Skip to content

Share platform-neutral code through an npm workspace package - #122

Merged
Programcode merged 4 commits into
mainfrom
native-ios/02-workspaces-core
Oct 8, 2026
Merged

Programcode merged 4 commits into
mainfrom
native-ios/02-workspaces-core

Conversation

@Programcode

Copy link
Copy Markdown
Owner

The repository is now an npm workspace with one shared package, packages/core, so the native iOS app planned in plans/2026-10-08-native-ios-app.md can reuse DebateLab's platform-neutral code. src/ did not move, and the website behaves the same.

What moved into @debatelab/core:

  • The import-closed leaf modules from src/lib: languages, URL and file validation, voice delivery and payload, the AI request and output schemas, the provider types, the crossfire schemas, reducer, prefill and draft storage, the sparring formats, and the Edge Function error helper. Each has zod as its only outside dependency.
  • contract/*, one-line re-exports of the four files the client already shares with the Edge Functions (debate-context, model-catalog, source-bounds, voice-tags). Those stay in supabase/functions/_shared, where Deno imports them.

How the web keeps working:

  • Every old src/lib path keeps a one-line export * shim, so no importer, vi.mock target or test changed. The one exception is ai/schemas/url.ts: only the moved schemas used it, and knip flags an unused shim.
  • Crossfire draft storage takes its storage as a parameter in the package. The src/lib wrapper keeps the localStorage default, so AuthProvider and the Crossfire page are untouched.
  • validation/file.ts accepts any object with name, size and type, which a browser File satisfies.

Guards that keep the package platform-neutral:

  • packages/core/tsconfig.json compiles with the ES2022 lib and no DOM types. As a side effect, the _shared contract files' "no Deno or DOM APIs" comments are now checked by the compiler. A small globals.d.ts declares URL and console.warn, which both browsers and Hermes provide.
  • ESLint gives packages/** no browser globals and errors on window, document, storage, import.meta, and imports of React, React Native, zustand, supabase-js and the web-only UI libraries. A probe file with each of those failed lint as expected. The type-aware no-floating-promises rule now covers the package too.
  • npm run typecheck includes the package; knip runs it as a workspace; check-docs skips any node_modules folder; the database, live-e2e, model-matrix and agentic-e2e workflow filters include packages/**.

Left in src/ on purpose: the stores, the AI client and streaming, the Supabase client, environment and auth wiring, src/i18n.ts and the locale catalogs. They depend on browser storage, import.meta.env or app singletons, and the catalogs are the most edited files in the repo. They become shareable in later native-app PRs through injected storage and runtime adapters.

GitHub Actions still starts no jobs on this account (billing), so these checks ran locally on Node 22.23.2:

  • npm run verify exit 0 at the final tree: 273 Vitest tests, 30 collaboration tests, 333 Deno Edge Function tests, the build with its boundary check, the service-worker offline test, and 30 Chromium smoke e2e tests.
  • npm ls zod react react-dom resolves exactly one copy of each.
  • A clean clone ran npm ci, linked node_modules/@debatelab/core, and passed typecheck and build.
  • verify-debatelab in fake mode: doctor all ok, including the probe that reads src/lib/supabase/env.ts from the dev server. The ai-tools recipe (sign-in, streaming Ask with citations and web search, Attack, Brainstorm, Factoids) passed 6/6 on desktop and mobile Chromium, and the practice recipe (Crossfire reducer, draft storage, Sparring formats) passed 3/3 on both.

Not run: the full browser suite, WebKit, the database gate (no migrations), staging, and npm ci on npm 10.

🤖 Generated with Claude Code

Programcode and others added 4 commits October 8, 2026 18:06
The root package lists packages/* as workspaces. packages/core is a
private TypeScript-source package whose only dependency is zod at the
root's range, with a tsconfig that has no DOM library. The lockfile
gains only the workspace entry and the package link.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Moves the import-closed leaf modules from src/lib into
packages/core/src under the same relative names: languages, URL and
file validation, voice delivery and payload, the AI request and output
schemas, the provider types, the crossfire schemas, reducer, prefill
and draft storage, the sparring formats and the Edge Function error
helper. Package files import each other relatively, and the four
contract files shared with the Edge Functions are re-exported from
supabase/functions/_shared, not moved.

Every old src/lib path except ai/schemas/url.ts (only the moved
schemas used it) keeps a one-line re-export, so importers, vi.mock
targets and tests are unchanged. Crossfire draft storage now takes its
storage as a parameter; the src/lib wrapper keeps the localStorage
default for the web.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
ESLint rejects browser globals, import.meta and web-only imports in
packages/**, and the type-aware promise rules now cover packages/core.
npm run typecheck checks packages/core against its no-DOM tsconfig. knip
reads the root and packages/core as workspaces. The database, live-e2e,
model-matrix and agentic-e2e path filters include packages/**, and the
docs check skips node_modules at any depth.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 8, 2026 18:31
@vercel

vercel Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
debate-navigator Ready Ready Preview Oct 8, 2026 6:33pm UTC
debatelab-staging Ready Ready Preview Oct 8, 2026 6:33pm UTC

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository YAML (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Free
  • Run ID: f8508085-1f41-43d4-85cb-d0aada25ae58
📥 Commits

Reviewing files that changed from the base of the PR and between 8c5da7f and a9a1ff6.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (60)
  • .github/workflows/agentic-e2e.yml
  • .github/workflows/database.yml
  • .github/workflows/live-e2e.yml
  • .github/workflows/model-matrix.yml
  • AGENTS.md
  • README.md
  • docs/architecture.md
  • docs/development.md
  • eslint.config.js
  • knip.json
  • package.json
  • packages/core/README.md
  • packages/core/package.json
  • packages/core/src/ai/providers/types.ts
  • packages/core/src/ai/schemas/ask.ts
  • packages/core/src/ai/schemas/attack.ts
  • packages/core/src/ai/schemas/brainstorm.ts
  • packages/core/src/ai/schemas/factoids.ts
  • packages/core/src/ai/schemas/generate.ts
  • packages/core/src/ai/schemas/source-import.ts
  • packages/core/src/ai/schemas/sparring.ts
  • packages/core/src/ai/schemas/url.ts
  • packages/core/src/contract/debate-context.ts
  • packages/core/src/contract/model-catalog.ts
  • packages/core/src/contract/source-bounds.ts
  • packages/core/src/contract/voice-tags.ts
  • packages/core/src/crossfire/prefill.ts
  • packages/core/src/crossfire/reducer.ts
  • packages/core/src/crossfire/schemas.ts
  • packages/core/src/crossfire/storage.ts
  • packages/core/src/globals.d.ts
  • packages/core/src/languages.ts
  • packages/core/src/sparring/formats.ts
  • packages/core/src/supabase/edge-function-error.ts
  • packages/core/src/validation/file.ts
  • packages/core/src/validation/url.ts
  • packages/core/src/voice/delivery.ts
  • packages/core/src/voice/payload.ts
  • packages/core/tsconfig.json
  • scripts/check-docs.mjs
  • scripts/staging/fixtures.mjs
  • src/lib/ai/providers/types.ts
  • src/lib/ai/schemas/ask.ts
  • src/lib/ai/schemas/attack.ts
  • src/lib/ai/schemas/brainstorm.ts
  • src/lib/ai/schemas/factoids.ts
  • src/lib/ai/schemas/generate.ts
  • src/lib/ai/schemas/source-import.ts
  • src/lib/ai/schemas/sparring.ts
  • src/lib/crossfire/prefill.ts
  • src/lib/crossfire/reducer.ts
  • src/lib/crossfire/schemas.ts
  • src/lib/crossfire/storage.ts
  • src/lib/languages.ts
  • src/lib/sparring/formats.ts
  • src/lib/supabase/edge-function-error.ts
  • src/lib/validation/file.ts
  • src/lib/validation/url.ts
  • src/lib/voice/delivery.ts
  • src/lib/voice/payload.ts
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Essentials by visiting https://app.coderabbit.ai/settings/billing.

Comment @coderabbitai help to get the list of available commands.

@Programcode

Copy link
Copy Markdown
Owner Author

Review record for a9a1ff6.

Codex (gpt-6.1-sol, high effort, detached snapshot at a9a1ff6): no findings. It compared all 20 moved files against 8c5da7f, the shims and exports, the crossfire storage defaults and the AuthProvider callers, FileLike against File at the call sites, the contract re-exports, workspace resolution, the lockfile, the lint and knip guards, the workflow filters and the PR claims. On a clean checkout it confirmed that 98 runtime exports and the four contract modules keep the same object through both import paths, and that typechecks, ESLint, knip, the docs check, 85 focused tests, the production build and the boundary check pass.

Hosted builds: both Vercel projects built a9a1ff6 with their default install, so Vercel's npm accepts the workspace lockfile. GitHub Actions started no jobs (billing), so the checks of record are the local run in the description. Copilot and CodeRabbit did not review (quota and rate limit).

@Programcode
Programcode merged commit 56a94d7 into main Oct 8, 2026
8 of 18 checks passed
@Programcode
Programcode deleted the native-ios/02-workspaces-core branch October 8, 2026 18:38
@Programcode

Copy link
Copy Markdown
Owner Author

Production follow-through for merge commit 56a94d7:

  • Vercel deployed 56a94d7 to production (debate-navigator, "Deployment has completed") and to the permanent staging site. https://debate.pi-stack.org/ answers 200.
  • Live production after the deploy, compared with the screenshots of production taken before PR Remove the Capacitor iOS shell #121: 0 differing pixels on /, /login and /terms at desktop and phone sizes.
  • The staging sync reports "In sync with 56a94d7". This PR changes no migrations or Edge Functions, so there was nothing to deploy to either backend.

This branch was successfully deployed

2 active deployments
Preview – debate-navigator — a9a1ff67 Deployed Oct 8, 2026 by vercel[bot]
Preview – debatelab-staging — a9a1ff67 Deployed Oct 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants