Skip to content
This repository was archived by the owner on Nov 25, 2026. It is now read-only.

(TML-2397) M1 — Contract spaces: framework mechanism - #434

Merged
wmadden merged 36 commits into
mainfrom
tml-2397-contract-spaces-first-class-schema-contributions-from
May 9, 2026
Merged

wmadden merged 36 commits into
mainfrom
tml-2397-contract-spaces-first-class-schema-contributions-from

Conversation

@wmadden

@wmadden wmadden commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Milestone 1 of TML-2397 — Contract spaces: first-class schema contributions from extensions and monorepo packages. Establishes the framework primitives for contract spaces — disjoint (contract.json, migration-graph, head-ref) units owned by extensions or monorepo packages — so extensions become first-class schema contributors using the same planner / runner / verifier / migration shape as application authoring.

This PR is the foundation. M2-M5 (later PRs in this stack) consume this surface to ship per-space db init/db update, the cipherstash and pgvector migrations to the new mechanism, and removal of the legacy databaseDependencies.init escape hatch.

What lands

Project shaping (4 commits)

  • Project spec (projects/extension-contract-spaces/spec.md) refined through design discussion.
  • Pinned-on-disk extension contract.json + head-ref decision (extensions are WYSIWYG-readable in the user's repo, not just in node_modules).
  • Two sub-specs scaffolded — framework-mechanism.spec.md (drives M1+M2) and cipherstash-migration.spec.md (drives M3).
  • Plan finalised: drop arktype-json from scope (no databaseDependencies); 5 milestones.

Framework mechanism (10 implementation commits + 6 doc / fix commits)

Task What Where
T1.1 Per-space marker schema prisma_contract.marker gains a space column; one-shot framework-internal migration promotes existing single-row marker to (space='app', …) packages/2-sql/4-framework/
T1.2 contractSpace descriptor field SqlControlExtensionDescriptor.contractSpace?: { contractJson, migrations, headRef } packages/2-sql/9-family/src/core/migrations/types.ts
T1.3 Per-space planner planAllSpaces({ spaces }) — target-agnostic primitive in @prisma-next/migration-tools/exports/spaces migration-tools
T1.4 Per-space runner ordering concatenateSpaceApplyInputs — extensions alphabetical, then app-space; single transaction migration-tools
T1.5 Per-space verifier verifyContractSpaces — strict matching of loaded extension contract spaces vs marker rows + on-disk pinned dirs migration-tools
T1.6 / T1.7 / T1.8 Pinned per-space artefacts Layout convention migrations/<space-id>/{contract.json, contract.d.ts, refs/head.json, <migration-name>/...}; emitPinnedSpaceArtefacts + writeExtensionMigrationPackage migration-tools
T1.9 Drift detection detectSpaceContractDrift, readPinnedHeadRef, gatherDiskContractSpaceState migration-tools
T1.10 Synthetic test extension packages/3-extensions/test-contract-space/ — private workspace package exercising the contract-space machinery end-to-end at the helper layer new package

Plus: 3 fixes from review rounds (F1 brand-helper conversion, F2 stale mock SQL, F3 spy-not-called assertion).

Architecture

Two architectural principles are enforced throughout:

  1. WYSIWYG-on-disk for all schema artefacts. Extension contracts and migrations are pinned in the user's repo (under migrations/<space-id>/), not just referenced via node_modules. The verifier and runner read on-disk pinned artefacts at apply time — descriptor imports are authoring-time only.
  2. Cross-space ordering via convention. All extension-space migrations apply first (alphabetically by space-id), then app-space migrations, all in a single transaction. Multi-space rollback is a property of the runner (M2).

All M1 helpers are framework-neutral primitives in 1-framework/ packages; per-target composition lives in the SQL family's consumption sites (M2).

Project artefacts

  • Spec: projects/extension-contract-spaces/spec.md
  • Sub-spec for M1+M2: projects/extension-contract-spaces/specs/framework-mechanism.spec.md
  • Sub-spec for M3: projects/extension-contract-spaces/specs/cipherstash-migration.spec.md
  • Plan + task statuses: projects/extension-contract-spaces/plan.md

(The project artefacts under projects/ are transient and will be migrated to docs/architecture docs/ in M5 close-out.)

Stacked PR series

This is the first of a stack:

  1. (this PR — M1) Framework mechanism — primitives in 1-framework/ packages.
  2. M2 — Codec lifecycle hooks + per-space db init/db update (CLI consumer wiring; SQL-family runner restructure for multi-space outer-tx).
  3. M3 — cipherstash extension authored as a contract space (greenfield in this repo; merges with TML-2373 separately).
  4. M4 (TBD) — pgvector migration to a contract space + monorepo example.
  5. M5 (TBD) — databaseDependencies removal + ADRs + close-out.

Verification

  • pnpm lint:deps green (no layering violations).
  • pnpm test:packages green for all M1-touched packages.
  • M1 acceptance criteria: all helper-side ACs at PASS; consumer-side ACs (AM4-rollback, AM8, AM9, AM10, AM11-migrate-fails-informatively) explicitly M2/M3 territory.
  • M1 SATISFIED at HEAD 3fe5a7637; close-out doc-pass at 612153654.

Test plan

  • CI green on this branch.
  • No regressions in pnpm test:packages.
  • No regressions in pnpm test:integration beyond the documented baseline (parallel resource contention with mongodb-memory-server).

Refs: TML-2397.

Summary by CodeRabbit

  • New Features

    • Per-space migrations: tooling, CLI and public API now surface and operate with explicit space identifiers and per-space pinned artifacts.
  • Breaking Changes

    • Migration marker storage is now space-keyed; databases using the legacy marker shape may require initialization or migration.
  • Error Handling

    • Detects legacy marker shape and provides actionable remediation guidance.
  • Tests

    • Expanded unit, integration and e2e test coverage for spaces, I/O and verifier behaviors.

@coderabbitai

coderabbitai Bot commented May 7, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds APP_SPACE_ID and contract-space types; implements per-space migration APIs/IO; migrates marker persistence to a space primary key with legacy-shape detection; threads spaceId through planners, runners, adapters, targets, and CLI; updates IO/types/tests/fixtures/examples; and adds an APP_SPACE_ID lint.

Changes

Spaces APIs, marker-by-space migration

Layer / File(s) Summary
Data / Core Types
packages/1-framework/1-core/framework-components/src/control/*
Introduce APP_SPACE_ID, MigrationHints, MigrationMetadata, ContractSpace, ContractSpaceHeadRef, MigrationPackage; update MigrationPlanner/readMarker signatures to include spaceId/space.
Migration Tooling & IO
packages/1-framework/3-tooling/migration/src/*, .../exports/spaces.ts, .../package.json
Add planAllSpaces, concatenateSpaceApplyInputs, detectSpaceContractDrift, emitPinnedSpaceArtefacts, readPinnedContractHash, space layout/validation, listPinnedSpaceDirectories, verifyContractSpaces, error helpers, OnDiskMigrationPackage, materialiseMigrationPackage, and a spaces barrel export plus package export mapping.
Space layout & validation
packages/1-framework/3-tooling/migration/src/space-layout.ts, errors.ts
Filesystem-friendly SPACE_ID_PATTERN, ValidSpaceId branded type, isValidSpaceId/assertValidSpaceId, and MigrationToolsError helpers for invalid/duplicate/app-space misuse.
IO: on-disk packages
packages/1-framework/3-tooling/migration/src/io.ts, package.ts
Expose MANIFEST_FILE, implement materialiseMigrationPackage, normalize dirPath to absolute, and switch read APIs to OnDiskMigrationPackage.
SQL runtime: marker keyed by space
packages/2-sql/5-runtime/src/*
Switch marker DDL/queries to space PK, re-export APP_SPACE_ID, require space in write/read inputs, update SQL generation and tests.
Targets: Postgres & SQLite
packages/3-targets/*/src/core/migrations/*
Statement builders now use space primary key; runners detect legacy marker shape and return LEGACY_MARKER_SHAPE failures; upsert/read flows thread spaceId.
Adapters & Families
packages/2-sql/9-family/*, packages/3-targets/6-adapters/*, packages/2-mongo-family/*
Control adapters/readMarker updated to accept space; Mongo adapter enforces app-only marker reads; family instances thread APP_SPACE_ID for app marker operations.
Planners & Migration Instances
packages/3-targets/*/planner*.ts, packages/2-sql/9-family/*
Planners accept spaceId and stamp produced migrations; TypeScriptRenderable*Migration carry spaceId; createMigrationPlan includes spaceId.
CLI wiring & types
packages/1-framework/3-tooling/cli/*
CLI commands pass APP_SPACE_ID to planner/runner and familyInstance.readMarker; CLI types updated to use OnDiskMigrationPackage; migration-new calls emptyMigration with spaceId.
Tests, fixtures, examples
test/**, packages/*/test/**, examples/**
Update marker DDL and SQL to use space PK; thread APP_SPACE_ID through planner calls; add contract-space fixture and extensive per-space/tooling tests and test helpers.
Repo lint and scripts
scripts/lint-app-space-id.mjs, package.json
Add lint script enforcing canonical APP_SPACE_ID and forbidding raw 'app' literals; integrate into lint:deps.

Estimated code review effort
🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant Planner
  participant Runner
  participant DB
  CLI->>Planner: request plan(spaceId=APP_SPACE_ID)
  Planner->>Runner: execute(plan with spaceId)
  Runner->>DB: ensure control tables, detect legacy marker shape
  Runner->>DB: read/write marker WHERE space = $1
Loading

"I hop through spaces, tidy and aware,
From id to space, the markers now compare.
I pin my artefacts, invariant lines,
And sniff out legacy, with gentle signs. 🥕
One hop, two hops—schemas all align!"

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2397-contract-spaces-first-class-schema-contributions-from

@pkg-pr-new

pkg-pr-new Bot commented May 7, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/mongo-runtime

npm i https://pkg.pr.new/@prisma-next/mongo-runtime@434

@prisma-next/family-mongo

npm i https://pkg.pr.new/@prisma-next/family-mongo@434

@prisma-next/sql-runtime

npm i https://pkg.pr.new/@prisma-next/sql-runtime@434

@prisma-next/family-sql

npm i https://pkg.pr.new/@prisma-next/family-sql@434

@prisma-next/extension-arktype-json

npm i https://pkg.pr.new/@prisma-next/extension-arktype-json@434

@prisma-next/middleware-telemetry

npm i https://pkg.pr.new/@prisma-next/middleware-telemetry@434

@prisma-next/mongo

npm i https://pkg.pr.new/@prisma-next/mongo@434

@prisma-next/extension-paradedb

npm i https://pkg.pr.new/@prisma-next/extension-paradedb@434

@prisma-next/extension-pgvector

npm i https://pkg.pr.new/@prisma-next/extension-pgvector@434

@prisma-next/postgres

npm i https://pkg.pr.new/@prisma-next/postgres@434

@prisma-next/sql-orm-client

npm i https://pkg.pr.new/@prisma-next/sql-orm-client@434

@prisma-next/sqlite

npm i https://pkg.pr.new/@prisma-next/sqlite@434

@prisma-next/target-mongo

npm i https://pkg.pr.new/@prisma-next/target-mongo@434

@prisma-next/adapter-mongo

npm i https://pkg.pr.new/@prisma-next/adapter-mongo@434

@prisma-next/driver-mongo

npm i https://pkg.pr.new/@prisma-next/driver-mongo@434

@prisma-next/contract

npm i https://pkg.pr.new/@prisma-next/contract@434

@prisma-next/utils

npm i https://pkg.pr.new/@prisma-next/utils@434

@prisma-next/config

npm i https://pkg.pr.new/@prisma-next/config@434

@prisma-next/errors

npm i https://pkg.pr.new/@prisma-next/errors@434

@prisma-next/framework-components

npm i https://pkg.pr.new/@prisma-next/framework-components@434

@prisma-next/operations

npm i https://pkg.pr.new/@prisma-next/operations@434

@prisma-next/ts-render

npm i https://pkg.pr.new/@prisma-next/ts-render@434

@prisma-next/contract-authoring

npm i https://pkg.pr.new/@prisma-next/contract-authoring@434

@prisma-next/ids

npm i https://pkg.pr.new/@prisma-next/ids@434

@prisma-next/psl-parser

npm i https://pkg.pr.new/@prisma-next/psl-parser@434

@prisma-next/psl-printer

npm i https://pkg.pr.new/@prisma-next/psl-printer@434

@prisma-next/cli

npm i https://pkg.pr.new/@prisma-next/cli@434

@prisma-next/emitter

npm i https://pkg.pr.new/@prisma-next/emitter@434

@prisma-next/migration-tools

npm i https://pkg.pr.new/@prisma-next/migration-tools@434

prisma-next

npm i https://pkg.pr.new/prisma-next@434

@prisma-next/vite-plugin-contract-emit

npm i https://pkg.pr.new/@prisma-next/vite-plugin-contract-emit@434

@prisma-next/mongo-codec

npm i https://pkg.pr.new/@prisma-next/mongo-codec@434

@prisma-next/mongo-contract

npm i https://pkg.pr.new/@prisma-next/mongo-contract@434

@prisma-next/mongo-value

npm i https://pkg.pr.new/@prisma-next/mongo-value@434

@prisma-next/mongo-contract-psl

npm i https://pkg.pr.new/@prisma-next/mongo-contract-psl@434

@prisma-next/mongo-contract-ts

npm i https://pkg.pr.new/@prisma-next/mongo-contract-ts@434

@prisma-next/mongo-emitter

npm i https://pkg.pr.new/@prisma-next/mongo-emitter@434

@prisma-next/mongo-schema-ir

npm i https://pkg.pr.new/@prisma-next/mongo-schema-ir@434

@prisma-next/mongo-query-ast

npm i https://pkg.pr.new/@prisma-next/mongo-query-ast@434

@prisma-next/mongo-orm

npm i https://pkg.pr.new/@prisma-next/mongo-orm@434

@prisma-next/mongo-query-builder

npm i https://pkg.pr.new/@prisma-next/mongo-query-builder@434

@prisma-next/mongo-lowering

npm i https://pkg.pr.new/@prisma-next/mongo-lowering@434

@prisma-next/mongo-wire

npm i https://pkg.pr.new/@prisma-next/mongo-wire@434

@prisma-next/sql-contract

npm i https://pkg.pr.new/@prisma-next/sql-contract@434

@prisma-next/sql-errors

npm i https://pkg.pr.new/@prisma-next/sql-errors@434

@prisma-next/sql-operations

npm i https://pkg.pr.new/@prisma-next/sql-operations@434

@prisma-next/sql-schema-ir

npm i https://pkg.pr.new/@prisma-next/sql-schema-ir@434

@prisma-next/sql-contract-psl

npm i https://pkg.pr.new/@prisma-next/sql-contract-psl@434

@prisma-next/sql-contract-ts

npm i https://pkg.pr.new/@prisma-next/sql-contract-ts@434

@prisma-next/sql-contract-emitter

npm i https://pkg.pr.new/@prisma-next/sql-contract-emitter@434

@prisma-next/sql-lane-query-builder

npm i https://pkg.pr.new/@prisma-next/sql-lane-query-builder@434

@prisma-next/sql-relational-core

npm i https://pkg.pr.new/@prisma-next/sql-relational-core@434

@prisma-next/sql-builder

npm i https://pkg.pr.new/@prisma-next/sql-builder@434

@prisma-next/target-postgres

npm i https://pkg.pr.new/@prisma-next/target-postgres@434

@prisma-next/target-sqlite

npm i https://pkg.pr.new/@prisma-next/target-sqlite@434

@prisma-next/adapter-postgres

npm i https://pkg.pr.new/@prisma-next/adapter-postgres@434

@prisma-next/adapter-sqlite

npm i https://pkg.pr.new/@prisma-next/adapter-sqlite@434

@prisma-next/driver-postgres

npm i https://pkg.pr.new/@prisma-next/driver-postgres@434

@prisma-next/driver-sqlite

npm i https://pkg.pr.new/@prisma-next/driver-sqlite@434

commit: 3e85bcb

@wmadden wmadden changed the title Extension contract spaces project plan (TML-2397) M1 — Contract spaces: framework mechanism May 8, 2026
@wmadden
wmadden marked this pull request as ready for review May 8, 2026 07:50

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/1-framework/3-tooling/migration/src/space-layout.ts (1)

28-32: 💤 Low value

Consider a branded type for stronger type safety.

The assertion asserts spaceId is string is semantically a no-op since the parameter is already string. If you want the type system to track validated space IDs, consider a branded type:

type ValidSpaceId = string & { readonly __brand: 'ValidSpaceId' };

export function assertValidSpaceId(spaceId: string): asserts spaceId is ValidSpaceId {
  if (!isValidSpaceId(spaceId)) {
    throw errorInvalidSpaceId(spaceId);
  }
}

However, if the current assertion is purely for runtime validation and the branding isn't needed downstream, the current form is acceptable.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/1-framework/3-tooling/migration/src/space-layout.ts` around lines 28
- 32, The current runtime assertion assertValidSpaceId(spaceId: string): asserts
spaceId is string is a no-op at the type level; introduce a branded type (e.g.
type ValidSpaceId = string & { readonly __brand: 'ValidSpaceId' }) and change
the assertion signature to assertValidSpaceId(spaceId: string): asserts spaceId
is ValidSpaceId so the compiler can track validated IDs; add the ValidSpaceId
type near the top of the file, update assertValidSpaceId to use it, and adjust
any call sites that need the branded type (or explicitly narrow/cast after
calling the assertion) so consumers can rely on the stronger type guarantee.
packages/3-targets/3-targets/postgres/test/migrations/statement-builders.test.ts (1)

28-80: Follow-up: retire the known coverage debt before warning expiry.

Given the CI warning about operation-resolver.ts and runner.ts gaps expiring on July 14, 2026, consider adding a focused integration path that exercises descriptor-pipeline resolution through runner execution to close that debt proactively.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/3-targets/3-targets/postgres/test/migrations/statement-builders.test.ts`
around lines 28 - 80, Add an integration test that exercises descriptor-pipeline
resolution end-to-end by invoking the Runner (class Runner or
runner.run/runner.execute) with a request that hits operation-resolver (the
resolver function in operation-resolver.ts) so the pipeline paths are exercised;
specifically, create a new test that bootstraps a minimal runner instance, feeds
it a descriptor that requires full pipeline resolution, and asserts the resolved
descriptor/outcome (this will exercise operation-resolver and runner logic and
close the coverage gap). Ensure the new test references the Runner API
(Runner.run or Runner.execute) and the operation-resolver entrypoint so CI
measures coverage against those files.
packages/1-framework/3-tooling/migration/test/emit-pinned-space-artefacts.test.ts (1)

210-214: 💤 Low value

Redundant dynamic import of mkdir.

mkdir is already imported at line 1 from node:fs/promises. The dynamic import here is unnecessary.

🧹 Remove redundant import
     await writeFile(`${dir}-marker`, 'noop'); // ensure mkdir creates dir
     // Pre-create a user-authored migration package directory with a stub manifest.
-    const { mkdir } = await import('node:fs/promises');
     await mkdir(userMigration, { recursive: true });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/1-framework/3-tooling/migration/test/emit-pinned-space-artefacts.test.ts`
around lines 210 - 214, The dynamic import that re-imports mkdir is redundant;
remove the `const { mkdir } = await import('node:fs/promises');` line and use
the already-imported `mkdir` symbol (used alongside `writeFile`) to create
`userMigration` (e.g., `await mkdir(userMigration, { recursive: true });`),
leaving the surrounding stub manifest creation code unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/3-extensions/test-contract-space/README.md`:
- Around line 3-5: The README links to a transient projects path
[`projects/extension-contract-spaces`] which will break; update the README.md
for the package `test-contract-space` so the "contract-space mechanism" link
points to a durable reference (for example the published package, a stable docs
page, or an internal package path), or remove the `projects/` link and replace
it with a permanent anchor or explanatory text; specifically edit the link text
that currently references `projects/extension-contract-spaces` so it targets a
stable resource (or plain text) to satisfy package/docs durability requirements.

---

Nitpick comments:
In `@packages/1-framework/3-tooling/migration/src/space-layout.ts`:
- Around line 28-32: The current runtime assertion assertValidSpaceId(spaceId:
string): asserts spaceId is string is a no-op at the type level; introduce a
branded type (e.g. type ValidSpaceId = string & { readonly __brand:
'ValidSpaceId' }) and change the assertion signature to
assertValidSpaceId(spaceId: string): asserts spaceId is ValidSpaceId so the
compiler can track validated IDs; add the ValidSpaceId type near the top of the
file, update assertValidSpaceId to use it, and adjust any call sites that need
the branded type (or explicitly narrow/cast after calling the assertion) so
consumers can rely on the stronger type guarantee.

In
`@packages/1-framework/3-tooling/migration/test/emit-pinned-space-artefacts.test.ts`:
- Around line 210-214: The dynamic import that re-imports mkdir is redundant;
remove the `const { mkdir } = await import('node:fs/promises');` line and use
the already-imported `mkdir` symbol (used alongside `writeFile`) to create
`userMigration` (e.g., `await mkdir(userMigration, { recursive: true });`),
leaving the surrounding stub manifest creation code unchanged.

In
`@packages/3-targets/3-targets/postgres/test/migrations/statement-builders.test.ts`:
- Around line 28-80: Add an integration test that exercises descriptor-pipeline
resolution end-to-end by invoking the Runner (class Runner or
runner.run/runner.execute) with a request that hits operation-resolver (the
resolver function in operation-resolver.ts) so the pipeline paths are exercised;
specifically, create a new test that bootstraps a minimal runner instance, feeds
it a descriptor that requires full pipeline resolution, and asserts the resolved
descriptor/outcome (this will exercise operation-resolver and runner logic and
close the coverage gap). Ensure the new test references the Runner API
(Runner.run or Runner.execute) and the operation-resolver entrypoint so CI
measures coverage against those files.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: b85a0de2-ec74-4bd8-9119-6bea6e223208

📥 Commits

Reviewing files that changed from the base of the PR and between 91a1853 and 6121536.

⛔ Files ignored due to path filters (5)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • projects/extension-contract-spaces/plan.md is excluded by !projects/**
  • projects/extension-contract-spaces/spec.md is excluded by !projects/**
  • projects/extension-contract-spaces/specs/cipherstash-migration.spec.md is excluded by !projects/**
  • projects/extension-contract-spaces/specs/framework-mechanism.spec.md is excluded by !projects/**
📒 Files selected for processing (77)
  • examples/react-router-demo/test/react-router.smoke.e2e.test.ts
  • packages/1-framework/3-tooling/migration/package.json
  • packages/1-framework/3-tooling/migration/src/concatenate-space-apply-inputs.ts
  • packages/1-framework/3-tooling/migration/src/detect-space-contract-drift.ts
  • packages/1-framework/3-tooling/migration/src/emit-pinned-space-artefacts.ts
  • packages/1-framework/3-tooling/migration/src/errors.ts
  • packages/1-framework/3-tooling/migration/src/exports/io.ts
  • packages/1-framework/3-tooling/migration/src/exports/spaces.ts
  • packages/1-framework/3-tooling/migration/src/io.ts
  • packages/1-framework/3-tooling/migration/src/plan-all-spaces.ts
  • packages/1-framework/3-tooling/migration/src/read-pinned-contract-hash.ts
  • packages/1-framework/3-tooling/migration/src/space-layout.ts
  • packages/1-framework/3-tooling/migration/src/verify-contract-spaces.ts
  • packages/1-framework/3-tooling/migration/test/concatenate-space-apply-inputs.test.ts
  • packages/1-framework/3-tooling/migration/test/deletable-node-modules.test.ts
  • packages/1-framework/3-tooling/migration/test/detect-space-contract-drift.test.ts
  • packages/1-framework/3-tooling/migration/test/emit-pinned-space-artefacts.test.ts
  • packages/1-framework/3-tooling/migration/test/plan-all-spaces.test.ts
  • packages/1-framework/3-tooling/migration/test/read-pinned-contract-hash.test.ts
  • packages/1-framework/3-tooling/migration/test/space-layout.test.ts
  • packages/1-framework/3-tooling/migration/test/verify-contract-spaces.test.ts
  • packages/1-framework/3-tooling/migration/test/write-extension-migration-package.test.ts
  • packages/1-framework/3-tooling/migration/tsdown.config.ts
  • packages/2-sql/5-runtime/src/exports/index.ts
  • packages/2-sql/5-runtime/src/sql-marker.ts
  • packages/2-sql/5-runtime/test/intercept-decoding.test.ts
  • packages/2-sql/5-runtime/test/marker-vs-intercept-ordering.test.ts
  • packages/2-sql/5-runtime/test/sql-family-adapter.test.ts
  • packages/2-sql/5-runtime/test/sql-marker.test.ts
  • packages/2-sql/5-runtime/test/sql-runtime.test.ts
  • packages/2-sql/5-runtime/test/utils.ts
  • packages/2-sql/9-family/src/core/migrations/types.ts
  • packages/2-sql/9-family/src/exports/control.ts
  • packages/2-sql/9-family/test/migrations.types.test-d.ts
  • packages/3-extensions/sql-orm-client/test/integration/runtime-helpers.ts
  • packages/3-extensions/test-contract-space/README.md
  • packages/3-extensions/test-contract-space/biome.jsonc
  • packages/3-extensions/test-contract-space/package.json
  • packages/3-extensions/test-contract-space/src/core/constants.ts
  • packages/3-extensions/test-contract-space/src/core/contract.ts
  • packages/3-extensions/test-contract-space/src/core/migrations.ts
  • packages/3-extensions/test-contract-space/src/exports/control.ts
  • packages/3-extensions/test-contract-space/test/descriptor.test.ts
  • packages/3-extensions/test-contract-space/tsconfig.json
  • packages/3-extensions/test-contract-space/tsconfig.prod.json
  • packages/3-extensions/test-contract-space/tsdown.config.ts
  • packages/3-extensions/test-contract-space/vitest.config.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/runner.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/statement-builders.ts
  • packages/3-targets/3-targets/postgres/src/exports/statement-builders.ts
  • packages/3-targets/3-targets/postgres/test/migrations/statement-builders.test.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/runner.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/statement-builders.ts
  • packages/3-targets/3-targets/sqlite/src/exports/statement-builders.ts
  • packages/3-targets/6-adapters/postgres/src/core/adapter.ts
  • packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/postgres/test/adapter.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/marker-schema-migration.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.basic.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.errors.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.idempotency.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/src/core/adapter.ts
  • packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/marker-schema-migration.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.basic.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.errors.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.idempotency.test.ts
  • test/e2e/framework/test/sqlite/utils.ts
  • test/integration/test/cli-journeys/drift-marker.e2e.test.ts
  • test/integration/test/cli-journeys/greenfield-setup.e2e.test.ts
  • test/integration/test/cli-journeys/invariant-routing.e2e.test.ts
  • test/integration/test/cli-journeys/migration-apply-edge-cases.e2e.test.ts
  • test/integration/test/cli.db-init.e2e.errors.test.ts
  • test/integration/test/cli.db-init.e2e.test.ts
  • test/integration/test/cli.db-sign.e2e.test.ts
  • test/integration/test/cli.migration-apply.e2e.test.ts
  • test/integration/test/family.sign-database.test.ts

@wmadden
wmadden force-pushed the tml-2397-contract-spaces-first-class-schema-contributions-from branch from 6eeed25 to a210c79 Compare May 8, 2026 11:30

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/3-targets/3-targets/postgres/src/core/migrations/runner.ts (1)

47-68: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

cloneAndFreezeRecord still shares objects nested inside arrays.

Object.freeze([...val]) only protects the array shell. If operation.meta contains something like [{ ... }], the later onOperationComplete() callback can still mutate those nested objects through the original operation after the skip record has been pushed, and that mutated metadata is what will be written to executedOperations/the ledger. Recurse through array members before freezing, or use a true deep clone/freeze helper here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/3-targets/3-targets/postgres/src/core/migrations/runner.ts` around
lines 47 - 68, cloneAndFreezeRecord currently only shallow-freezes arrays with
Object.freeze([...val]) which leaves object elements inside arrays mutable;
change the array branch in cloneAndFreezeRecord to deep-clone and freeze each
array element (recursively call cloneAndFreezeRecord for object/array elements,
copy primitives as-is), then freeze the resulting array before assigning, so
nested objects inside arrays (e.g., operation.meta entries) are fully immutable
when used by onOperationComplete()/executedOperations.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/3-extensions/test-contract-space/tsdown.config.ts`:
- Around line 3-5: The tsdown config's defineConfig currently only lists
'src/exports/control.ts'; update the entry array in defineConfig to include all
required entry points: 'src/exports/adapter.ts', 'src/exports/types.ts',
'src/exports/codec-types.ts', 'src/exports/control.ts', and
'src/exports/runtime.ts' so the single tsdown configuration block contains every
adapter/types/codec-types/control/runtime entry required by the rule.

---

Outside diff comments:
In `@packages/3-targets/3-targets/postgres/src/core/migrations/runner.ts`:
- Around line 47-68: cloneAndFreezeRecord currently only shallow-freezes arrays
with Object.freeze([...val]) which leaves object elements inside arrays mutable;
change the array branch in cloneAndFreezeRecord to deep-clone and freeze each
array element (recursively call cloneAndFreezeRecord for object/array elements,
copy primitives as-is), then freeze the resulting array before assigning, so
nested objects inside arrays (e.g., operation.meta entries) are fully immutable
when used by onOperationComplete()/executedOperations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 76689088-09fe-4bab-ad2e-26648f68faff

📥 Commits

Reviewing files that changed from the base of the PR and between 6eeed25 and a210c79.

⛔ Files ignored due to path filters (5)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • projects/extension-contract-spaces/plan.md is excluded by !projects/**
  • projects/extension-contract-spaces/spec.md is excluded by !projects/**
  • projects/extension-contract-spaces/specs/cipherstash-migration.spec.md is excluded by !projects/**
  • projects/extension-contract-spaces/specs/framework-mechanism.spec.md is excluded by !projects/**
📒 Files selected for processing (77)
  • examples/react-router-demo/test/react-router.smoke.e2e.test.ts
  • packages/1-framework/3-tooling/migration/package.json
  • packages/1-framework/3-tooling/migration/src/concatenate-space-apply-inputs.ts
  • packages/1-framework/3-tooling/migration/src/detect-space-contract-drift.ts
  • packages/1-framework/3-tooling/migration/src/emit-pinned-space-artefacts.ts
  • packages/1-framework/3-tooling/migration/src/errors.ts
  • packages/1-framework/3-tooling/migration/src/exports/io.ts
  • packages/1-framework/3-tooling/migration/src/exports/spaces.ts
  • packages/1-framework/3-tooling/migration/src/io.ts
  • packages/1-framework/3-tooling/migration/src/plan-all-spaces.ts
  • packages/1-framework/3-tooling/migration/src/read-pinned-contract-hash.ts
  • packages/1-framework/3-tooling/migration/src/space-layout.ts
  • packages/1-framework/3-tooling/migration/src/verify-contract-spaces.ts
  • packages/1-framework/3-tooling/migration/test/concatenate-space-apply-inputs.test.ts
  • packages/1-framework/3-tooling/migration/test/deletable-node-modules.test.ts
  • packages/1-framework/3-tooling/migration/test/detect-space-contract-drift.test.ts
  • packages/1-framework/3-tooling/migration/test/emit-pinned-space-artefacts.test.ts
  • packages/1-framework/3-tooling/migration/test/plan-all-spaces.test.ts
  • packages/1-framework/3-tooling/migration/test/read-pinned-contract-hash.test.ts
  • packages/1-framework/3-tooling/migration/test/space-layout.test.ts
  • packages/1-framework/3-tooling/migration/test/verify-contract-spaces.test.ts
  • packages/1-framework/3-tooling/migration/test/write-extension-migration-package.test.ts
  • packages/1-framework/3-tooling/migration/tsdown.config.ts
  • packages/2-sql/5-runtime/src/exports/index.ts
  • packages/2-sql/5-runtime/src/sql-marker.ts
  • packages/2-sql/5-runtime/test/intercept-decoding.test.ts
  • packages/2-sql/5-runtime/test/marker-vs-intercept-ordering.test.ts
  • packages/2-sql/5-runtime/test/sql-family-adapter.test.ts
  • packages/2-sql/5-runtime/test/sql-marker.test.ts
  • packages/2-sql/5-runtime/test/sql-runtime.test.ts
  • packages/2-sql/5-runtime/test/utils.ts
  • packages/2-sql/9-family/src/core/migrations/types.ts
  • packages/2-sql/9-family/src/exports/control.ts
  • packages/2-sql/9-family/test/migrations.types.test-d.ts
  • packages/3-extensions/sql-orm-client/test/integration/runtime-helpers.ts
  • packages/3-extensions/test-contract-space/README.md
  • packages/3-extensions/test-contract-space/biome.jsonc
  • packages/3-extensions/test-contract-space/package.json
  • packages/3-extensions/test-contract-space/src/core/constants.ts
  • packages/3-extensions/test-contract-space/src/core/contract.ts
  • packages/3-extensions/test-contract-space/src/core/migrations.ts
  • packages/3-extensions/test-contract-space/src/exports/control.ts
  • packages/3-extensions/test-contract-space/test/descriptor.test.ts
  • packages/3-extensions/test-contract-space/tsconfig.json
  • packages/3-extensions/test-contract-space/tsconfig.prod.json
  • packages/3-extensions/test-contract-space/tsdown.config.ts
  • packages/3-extensions/test-contract-space/vitest.config.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/runner.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/statement-builders.ts
  • packages/3-targets/3-targets/postgres/src/exports/statement-builders.ts
  • packages/3-targets/3-targets/postgres/test/migrations/statement-builders.test.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/runner.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/statement-builders.ts
  • packages/3-targets/3-targets/sqlite/src/exports/statement-builders.ts
  • packages/3-targets/6-adapters/postgres/src/core/adapter.ts
  • packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/postgres/test/adapter.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/marker-schema-migration.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.basic.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.errors.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.idempotency.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/src/core/adapter.ts
  • packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/marker-schema-migration.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.basic.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.errors.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.idempotency.test.ts
  • test/e2e/framework/test/sqlite/utils.ts
  • test/integration/test/cli-journeys/drift-marker.e2e.test.ts
  • test/integration/test/cli-journeys/greenfield-setup.e2e.test.ts
  • test/integration/test/cli-journeys/invariant-routing.e2e.test.ts
  • test/integration/test/cli-journeys/migration-apply-edge-cases.e2e.test.ts
  • test/integration/test/cli.db-init.e2e.errors.test.ts
  • test/integration/test/cli.db-init.e2e.test.ts
  • test/integration/test/cli.db-sign.e2e.test.ts
  • test/integration/test/cli.migration-apply.e2e.test.ts
  • test/integration/test/family.sign-database.test.ts
✅ Files skipped from review due to trivial changes (19)
  • packages/3-targets/3-targets/postgres/src/exports/statement-builders.ts
  • packages/2-sql/5-runtime/test/sql-family-adapter.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.errors.integration.test.ts
  • packages/3-extensions/test-contract-space/biome.jsonc
  • packages/3-extensions/test-contract-space/tsconfig.prod.json
  • packages/1-framework/3-tooling/migration/src/exports/spaces.ts
  • packages/2-sql/5-runtime/src/exports/index.ts
  • packages/3-extensions/test-contract-space/test/descriptor.test.ts
  • packages/3-extensions/test-contract-space/tsconfig.json
  • packages/1-framework/3-tooling/migration/test/write-extension-migration-package.test.ts
  • packages/1-framework/3-tooling/migration/src/exports/io.ts
  • packages/2-sql/9-family/test/migrations.types.test-d.ts
  • packages/3-extensions/test-contract-space/README.md
  • packages/1-framework/3-tooling/migration/test/space-layout.test.ts
  • packages/1-framework/3-tooling/migration/tsdown.config.ts
  • packages/3-extensions/test-contract-space/vitest.config.ts
  • test/integration/test/cli.db-init.e2e.errors.test.ts
  • packages/3-extensions/test-contract-space/src/core/constants.ts
  • packages/1-framework/3-tooling/migration/test/concatenate-space-apply-inputs.test.ts
🚧 Files skipped from review as they are similar to previous changes (47)
  • packages/3-targets/3-targets/sqlite/src/exports/statement-builders.ts
  • test/integration/test/family.sign-database.test.ts
  • packages/3-targets/6-adapters/postgres/src/core/adapter.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.idempotency.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.idempotency.integration.test.ts
  • test/integration/test/cli-journeys/drift-marker.e2e.test.ts
  • packages/3-targets/6-adapters/sqlite/src/core/adapter.ts
  • packages/3-extensions/test-contract-space/src/core/contract.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.errors.test.ts
  • test/integration/test/cli.db-sign.e2e.test.ts
  • packages/1-framework/3-tooling/migration/src/concatenate-space-apply-inputs.ts
  • test/integration/test/cli.migration-apply.e2e.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.basic.integration.test.ts
  • packages/1-framework/3-tooling/migration/src/io.ts
  • packages/2-sql/5-runtime/test/sql-marker.test.ts
  • packages/2-sql/5-runtime/test/marker-vs-intercept-ordering.test.ts
  • packages/1-framework/3-tooling/migration/src/errors.ts
  • packages/2-sql/5-runtime/test/utils.ts
  • test/integration/test/cli-journeys/greenfield-setup.e2e.test.ts
  • packages/1-framework/3-tooling/migration/test/emit-pinned-space-artefacts.test.ts
  • packages/1-framework/3-tooling/migration/package.json
  • packages/2-sql/5-runtime/test/intercept-decoding.test.ts
  • packages/3-extensions/test-contract-space/src/core/migrations.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.basic.test.ts
  • packages/1-framework/3-tooling/migration/src/emit-pinned-space-artefacts.ts
  • packages/1-framework/3-tooling/migration/src/plan-all-spaces.ts
  • packages/1-framework/3-tooling/migration/src/space-layout.ts
  • packages/1-framework/3-tooling/migration/test/read-pinned-contract-hash.test.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/statement-builders.ts
  • packages/3-extensions/test-contract-space/package.json
  • packages/1-framework/3-tooling/migration/src/detect-space-contract-drift.ts
  • packages/2-sql/5-runtime/test/sql-runtime.test.ts
  • packages/1-framework/3-tooling/migration/test/verify-contract-spaces.test.ts
  • packages/3-targets/6-adapters/postgres/test/adapter.test.ts
  • test/e2e/framework/test/sqlite/utils.ts
  • test/integration/test/cli.db-init.e2e.test.ts
  • packages/2-sql/5-runtime/src/sql-marker.ts
  • packages/1-framework/3-tooling/migration/test/deletable-node-modules.test.ts
  • test/integration/test/cli-journeys/invariant-routing.e2e.test.ts
  • packages/3-targets/3-targets/postgres/test/migrations/statement-builders.test.ts
  • packages/1-framework/3-tooling/migration/test/plan-all-spaces.test.ts
  • packages/3-extensions/test-contract-space/src/exports/control.ts
  • test/integration/test/cli-journeys/migration-apply-edge-cases.e2e.test.ts
  • packages/2-sql/9-family/src/core/migrations/types.ts
  • packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/marker-schema-migration.test.ts
  • packages/1-framework/3-tooling/migration/src/verify-contract-spaces.ts

wmadden added a commit that referenced this pull request May 8, 2026
…, not name shape

listPinnedSpaceDirectories distinguished user-authored migration
directories from pinned per-space subdirectories with a regex on the
directory name (^\d{8}T\d{4}_), encoding the formatMigrationDirName
convention as if it were a contract. Directory names belong to users
and are informative, not structural.

Switch to the same discriminator readMigrationsDir already uses:
presence of migration.json at the directory root. A subdirectory is a
migration directory iff it contains the manifest; otherwise it is a
candidate pinned per-space subdirectory. ENOENT means "no manifest";
other stat errors propagate. Sorted, deterministic output is
preserved.

This frees users to name their migration directories however they
like and removes a brittleness flagged in PR #434 review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts (1)

98-128: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Guard legacy marker tables before selecting on space.

Lines 98-127 only check that _prisma_marker exists, then immediately query WHERE space = ?. On pre-cleanup databases that still have the legacy single-row marker shape, this path now throws SQLite's raw no such column: space error instead of surfacing the structured LEGACY_MARKER_SHAPE remediation you added in the runner. That leaves standalone marker reads in verify/drift paths with an untyped failure mode.

At minimum, mirror the runner’s shape probe here before the select, or translate the missing-column case into the same structured remediation flow.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts` around
lines 98 - 128, Before running the filtered select on _prisma_marker,
probe/guard for the legacy single-row marker shape and map missing-column errors
to the same remediation used in the runner: use driver.query to inspect the
table schema or a single-row probe (e.g. PRAGMA table_info/_prisma_marker or
SELECT * FROM _prisma_marker LIMIT 1) and verify the presence of the space
column; if the space column is absent, return/throw the existing
LEGACY_MARKER_SHAPE remediation (or call the same remediation helper used by the
runner) instead of performing the `SELECT ... WHERE space = ?` with
APP_SPACE_ID, and additionally catch a runtime sqlite "no such column: space"
error from the driver.query call and translate it into that same structured
remediation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@packages/1-framework/3-tooling/migration/test/write-authored-migration-package.test.ts`:
- Around line 44-65: The test currently verifies deterministic serialization by
writing the package to two different roots (dirA and dirB) but misses overwrite
idempotency; change the test in write-authored-migration-package.test.ts so both
writes target the same output directory (call writeAuthoredMigrationPackage
twice to the same dir, e.g., dirA) to assert a second write over an existing
<targetDir>/<pkg.dirName> produces byte-identical migration.json, ops.json and
contract.json and does not leave stale files; keep existing readFile+expect
comparisons but use the files from the same directory before-and-after the
second write to validate overwrite idempotency for
writeAuthoredMigrationPackage.

In `@packages/2-sql/5-runtime/src/sql-marker.ts`:
- Around line 12-18: Change the optional `space?: string` property on the SQL
marker type to a required `space: string` (remove the defaulting behavior tied
to APP_SPACE_ID) and then update every call site that relied on implicit
defaults (referenced around the other occurrences you flagged) to pass
APP_SPACE_ID explicitly from app-only callers; specifically edit the declaration
for the `space` field in sql-marker.ts and audit references that construct or
read marker objects so they provide a concrete space value instead of omitting
it.

In `@scripts/lint-app-space-id.mjs`:
- Line 67: The global regex LITERAL_RE (const LITERAL_RE = /(['"])app\1/g) is
reused across file tests so its lastIndex carries over and skips matches; before
each file-level test where LITERAL_RE is used (e.g., the check around the code
that runs per-file at line ~110), reset the regex by setting
LITERAL_RE.lastIndex = 0 so each file starts matching from position 0; update
the loop or function that invokes LITERAL_RE to reset lastIndex immediately
before calling test/exec to ensure no matches are missed.

---

Outside diff comments:
In `@packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts`:
- Around line 98-128: Before running the filtered select on _prisma_marker,
probe/guard for the legacy single-row marker shape and map missing-column errors
to the same remediation used in the runner: use driver.query to inspect the
table schema or a single-row probe (e.g. PRAGMA table_info/_prisma_marker or
SELECT * FROM _prisma_marker LIMIT 1) and verify the presence of the space
column; if the space column is absent, return/throw the existing
LEGACY_MARKER_SHAPE remediation (or call the same remediation helper used by the
runner) instead of performing the `SELECT ... WHERE space = ?` with
APP_SPACE_ID, and additionally catch a runtime sqlite "no such column: space"
error from the driver.query call and translate it into that same structured
remediation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 7636fac7-0e33-4c19-9f2b-bafdb0a88733

📥 Commits

Reviewing files that changed from the base of the PR and between 1a7cb82 and 789f7c4.

⛔ Files ignored due to path filters (2)
  • projects/extension-contract-spaces/plan.md is excluded by !projects/**
  • projects/extension-contract-spaces/specs/framework-mechanism.spec.md is excluded by !projects/**
📒 Files selected for processing (28)
  • package.json
  • packages/1-framework/1-core/framework-components/src/control/control-migration-types.ts
  • packages/1-framework/1-core/framework-components/src/control/control-spaces.ts
  • packages/1-framework/1-core/framework-components/src/exports/control.ts
  • packages/1-framework/3-tooling/migration/src/exports/io.ts
  • packages/1-framework/3-tooling/migration/src/io.ts
  • packages/1-framework/3-tooling/migration/src/metadata.ts
  • packages/1-framework/3-tooling/migration/src/space-layout.ts
  • packages/1-framework/3-tooling/migration/test/write-authored-migration-package.test.ts
  • packages/2-sql/5-runtime/src/sql-marker.ts
  • packages/2-sql/9-family/src/core/migrations/types.ts
  • packages/2-sql/9-family/test/migrations.types.test-d.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/runner.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/statement-builders.ts
  • packages/3-targets/3-targets/postgres/src/exports/statement-builders.ts
  • packages/3-targets/3-targets/postgres/test/migrations/statement-builders.test.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/runner.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/statement-builders.ts
  • packages/3-targets/3-targets/sqlite/src/exports/statement-builders.ts
  • packages/3-targets/6-adapters/postgres/src/core/adapter.ts
  • packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.errors.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/src/core/adapter.ts
  • packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.errors.test.ts
  • scripts/lint-app-space-id.mjs
  • test/integration/test/contract-space-fixture/control.ts
  • test/integration/test/contract-space-fixture/migrations.ts
✅ Files skipped from review due to trivial changes (3)
  • packages/1-framework/3-tooling/migration/src/exports/io.ts
  • packages/1-framework/1-core/framework-components/src/exports/control.ts
  • test/integration/test/contract-space-fixture/migrations.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/3-targets/3-targets/postgres/src/exports/statement-builders.ts
  • packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.errors.test.ts
  • test/integration/test/contract-space-fixture/control.ts
  • packages/1-framework/3-tooling/migration/src/space-layout.ts

Comment thread scripts/lint-app-space-id.mjs Resolved
wmadden added a commit that referenced this pull request May 9, 2026
…, not name shape

listPinnedSpaceDirectories distinguished user-authored migration
directories from pinned per-space subdirectories with a regex on the
directory name (^\d{8}T\d{4}_), encoding the formatMigrationDirName
convention as if it were a contract. Directory names belong to users
and are informative, not structural.

Switch to the same discriminator readMigrationsDir already uses:
presence of migration.json at the directory root. A subdirectory is a
migration directory iff it contains the manifest; otherwise it is a
candidate pinned per-space subdirectory. ENOENT means "no manifest";
other stat errors propagate. Sorted, deterministic output is
preserved.

This frees users to name their migration directories however they
like and removes a brittleness flagged in PR #434 review.
@wmadden
wmadden force-pushed the tml-2397-contract-spaces-first-class-schema-contributions-from branch from ee05b2b to b245d27 Compare May 9, 2026 11:27

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/1-framework/3-tooling/migration/src/io.ts`:
- Around line 208-210: The creation of the OnDiskMigrationPackage in
readMigrationPackage sets dirPath to the incoming dir which may be relative;
change it to an absolute path (e.g. use path.resolve(dir) or
path.resolve(process.cwd(), dir)) when constructing pkg so dirPath always
matches the documented absolute contract; update the assignment for dirPath in
the pkg object (the variable pkg constructed with basename(dir) and dirPath) to
use the resolved absolute path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 3d9b1dfe-a02d-4239-8771-8251d876dd4b

📥 Commits

Reviewing files that changed from the base of the PR and between 1a7cb82 and b245d27.

⛔ Files ignored due to path filters (5)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • projects/extension-contract-spaces/plan.md is excluded by !projects/**
  • projects/extension-contract-spaces/spec.md is excluded by !projects/**
  • projects/extension-contract-spaces/specs/cipherstash-migration.spec.md is excluded by !projects/**
  • projects/extension-contract-spaces/specs/framework-mechanism.spec.md is excluded by !projects/**
📒 Files selected for processing (86)
  • examples/react-router-demo/test/react-router.smoke.e2e.test.ts
  • package.json
  • packages/1-framework/1-core/framework-components/src/control/control-migration-types.ts
  • packages/1-framework/1-core/framework-components/src/control/control-spaces.ts
  • packages/1-framework/1-core/framework-components/src/exports/control.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-apply.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-show.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-status.ts
  • packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-show.test.ts
  • packages/1-framework/3-tooling/migration/package.json
  • packages/1-framework/3-tooling/migration/src/concatenate-space-apply-inputs.ts
  • packages/1-framework/3-tooling/migration/src/detect-space-contract-drift.ts
  • packages/1-framework/3-tooling/migration/src/emit-pinned-space-artefacts.ts
  • packages/1-framework/3-tooling/migration/src/errors.ts
  • packages/1-framework/3-tooling/migration/src/exports/io.ts
  • packages/1-framework/3-tooling/migration/src/exports/package.ts
  • packages/1-framework/3-tooling/migration/src/exports/spaces.ts
  • packages/1-framework/3-tooling/migration/src/hash.ts
  • packages/1-framework/3-tooling/migration/src/io.ts
  • packages/1-framework/3-tooling/migration/src/metadata.ts
  • packages/1-framework/3-tooling/migration/src/migration-graph.ts
  • packages/1-framework/3-tooling/migration/src/package.ts
  • packages/1-framework/3-tooling/migration/src/plan-all-spaces.ts
  • packages/1-framework/3-tooling/migration/src/read-pinned-contract-hash.ts
  • packages/1-framework/3-tooling/migration/src/space-layout.ts
  • packages/1-framework/3-tooling/migration/src/verify-contract-spaces.ts
  • packages/1-framework/3-tooling/migration/test/concatenate-space-apply-inputs.test.ts
  • packages/1-framework/3-tooling/migration/test/deletable-node-modules.test.ts
  • packages/1-framework/3-tooling/migration/test/detect-space-contract-drift.test.ts
  • packages/1-framework/3-tooling/migration/test/emit-pinned-space-artefacts.test.ts
  • packages/1-framework/3-tooling/migration/test/find-path-with-invariants.test.ts
  • packages/1-framework/3-tooling/migration/test/fixtures.ts
  • packages/1-framework/3-tooling/migration/test/materialise-migration-package.test.ts
  • packages/1-framework/3-tooling/migration/test/migration-graph.test.ts
  • packages/1-framework/3-tooling/migration/test/plan-all-spaces.test.ts
  • packages/1-framework/3-tooling/migration/test/read-pinned-contract-hash.test.ts
  • packages/1-framework/3-tooling/migration/test/space-layout.test.ts
  • packages/1-framework/3-tooling/migration/test/verify-contract-spaces.test.ts
  • packages/1-framework/3-tooling/migration/tsdown.config.ts
  • packages/2-sql/5-runtime/src/exports/index.ts
  • packages/2-sql/5-runtime/src/sql-marker.ts
  • packages/2-sql/5-runtime/test/intercept-decoding.test.ts
  • packages/2-sql/5-runtime/test/marker-vs-intercept-ordering.test.ts
  • packages/2-sql/5-runtime/test/sql-family-adapter.test.ts
  • packages/2-sql/5-runtime/test/sql-marker.test.ts
  • packages/2-sql/5-runtime/test/sql-runtime.test.ts
  • packages/2-sql/5-runtime/test/utils.ts
  • packages/2-sql/9-family/src/core/migrations/types.ts
  • packages/2-sql/9-family/test/migrations.types.test-d.ts
  • packages/3-extensions/sql-orm-client/test/integration/runtime-helpers.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/runner.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/statement-builders.ts
  • packages/3-targets/3-targets/postgres/src/exports/statement-builders.ts
  • packages/3-targets/3-targets/postgres/test/migrations/statement-builders.test.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/runner.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/statement-builders.ts
  • packages/3-targets/3-targets/sqlite/src/exports/statement-builders.ts
  • packages/3-targets/6-adapters/postgres/src/core/adapter.ts
  • packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/postgres/test/adapter.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.basic.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.errors.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.idempotency.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/src/core/adapter.ts
  • packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.basic.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.errors.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.idempotency.test.ts
  • scripts/lint-app-space-id.mjs
  • test/e2e/framework/test/sqlite/utils.ts
  • test/integration/test/cli-journeys/drift-marker.e2e.test.ts
  • test/integration/test/cli-journeys/greenfield-setup.e2e.test.ts
  • test/integration/test/cli-journeys/invariant-routing.e2e.test.ts
  • test/integration/test/cli-journeys/migration-apply-edge-cases.e2e.test.ts
  • test/integration/test/cli.db-init.e2e.errors.test.ts
  • test/integration/test/cli.db-init.e2e.test.ts
  • test/integration/test/cli.db-sign.e2e.test.ts
  • test/integration/test/cli.migration-apply.e2e.test.ts
  • test/integration/test/contract-space-fixture/README.md
  • test/integration/test/contract-space-fixture/constants.ts
  • test/integration/test/contract-space-fixture/contract.ts
  • test/integration/test/contract-space-fixture/control.ts
  • test/integration/test/contract-space-fixture/descriptor.test.ts
  • test/integration/test/contract-space-fixture/migrations.ts
  • test/integration/test/family.sign-database.test.ts
✅ Files skipped from review due to trivial changes (26)
  • test/integration/test/cli-journeys/drift-marker.e2e.test.ts
  • packages/2-sql/5-runtime/test/sql-family-adapter.test.ts
  • packages/1-framework/3-tooling/migration/src/exports/package.ts
  • test/integration/test/family.sign-database.test.ts
  • packages/3-targets/3-targets/sqlite/src/exports/statement-builders.ts
  • test/integration/test/contract-space-fixture/control.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-apply.ts
  • packages/1-framework/3-tooling/migration/test/detect-space-contract-drift.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.basic.test.ts
  • packages/2-sql/5-runtime/src/exports/index.ts
  • packages/1-framework/3-tooling/migration/src/migration-graph.ts
  • test/integration/test/contract-space-fixture/README.md
  • packages/1-framework/3-tooling/migration/src/detect-space-contract-drift.ts
  • packages/1-framework/1-core/framework-components/src/control/control-migration-types.ts
  • packages/1-framework/3-tooling/migration/src/concatenate-space-apply-inputs.ts
  • test/integration/test/contract-space-fixture/constants.ts
  • packages/1-framework/3-tooling/migration/test/space-layout.test.ts
  • packages/2-sql/5-runtime/test/marker-vs-intercept-ordering.test.ts
  • packages/1-framework/3-tooling/migration/package.json
  • packages/1-framework/3-tooling/migration/src/exports/spaces.ts
  • packages/1-framework/1-core/framework-components/src/control/control-spaces.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.idempotency.integration.test.ts
  • packages/1-framework/3-tooling/migration/test/concatenate-space-apply-inputs.test.ts
  • packages/3-targets/6-adapters/postgres/test/adapter.test.ts
  • test/integration/test/contract-space-fixture/contract.ts
  • packages/2-sql/5-runtime/test/sql-marker.test.ts
🚧 Files skipped from review as they are similar to previous changes (46)
  • packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts
  • packages/1-framework/3-tooling/migration/src/exports/io.ts
  • package.json
  • packages/1-framework/3-tooling/migration/tsdown.config.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.basic.integration.test.ts
  • packages/2-sql/5-runtime/test/utils.ts
  • packages/3-extensions/sql-orm-client/test/integration/runtime-helpers.ts
  • test/integration/test/cli.db-init.e2e.errors.test.ts
  • packages/3-targets/6-adapters/postgres/src/core/adapter.ts
  • test/integration/test/cli.migration-apply.e2e.test.ts
  • packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts
  • packages/2-sql/5-runtime/test/sql-runtime.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.idempotency.test.ts
  • test/e2e/framework/test/sqlite/utils.ts
  • packages/3-targets/6-adapters/sqlite/src/core/adapter.ts
  • test/integration/test/cli-journeys/migration-apply-edge-cases.e2e.test.ts
  • packages/1-framework/3-tooling/migration/test/read-pinned-contract-hash.test.ts
  • test/integration/test/cli-journeys/greenfield-setup.e2e.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.errors.integration.test.ts
  • packages/1-framework/3-tooling/migration/src/read-pinned-contract-hash.ts
  • packages/1-framework/3-tooling/migration/src/plan-all-spaces.ts
  • packages/1-framework/3-tooling/migration/test/emit-pinned-space-artefacts.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.errors.test.ts
  • packages/2-sql/5-runtime/test/intercept-decoding.test.ts
  • packages/2-sql/9-family/test/migrations.types.test-d.ts
  • packages/3-targets/3-targets/postgres/src/exports/statement-builders.ts
  • packages/1-framework/3-tooling/migration/src/errors.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/runner.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/runner.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/statement-builders.ts
  • test/integration/test/cli.db-init.e2e.test.ts
  • examples/react-router-demo/test/react-router.smoke.e2e.test.ts
  • test/integration/test/cli.db-sign.e2e.test.ts
  • packages/1-framework/3-tooling/migration/src/emit-pinned-space-artefacts.ts
  • test/integration/test/contract-space-fixture/descriptor.test.ts
  • packages/2-sql/9-family/src/core/migrations/types.ts
  • test/integration/test/cli-journeys/invariant-routing.e2e.test.ts
  • scripts/lint-app-space-id.mjs
  • packages/1-framework/3-tooling/migration/src/metadata.ts
  • packages/2-sql/5-runtime/src/sql-marker.ts
  • packages/1-framework/3-tooling/migration/test/plan-all-spaces.test.ts
  • packages/1-framework/3-tooling/migration/test/deletable-node-modules.test.ts
  • packages/1-framework/3-tooling/migration/test/verify-contract-spaces.test.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/statement-builders.ts
  • packages/1-framework/3-tooling/migration/src/verify-contract-spaces.ts
  • packages/3-targets/3-targets/postgres/test/migrations/statement-builders.test.ts

wmadden added a commit that referenced this pull request May 9, 2026
New project: a shared agent-persona library at .agents/skills/drive-agent-personas/
that lets skills declare which executor identity should run them, shifting
execution-time defaults toward a deliberately-chosen bias-set instead of the
agent default. Plugs the F0-F6-class vocabulary-and-typology leak that
M1-cleanup of extension-contract-spaces made visible.

Spec pins:
- v1 ships seven personas (PM, principal-engineer, architect, tech-lead,
  developer-default, devrel, oss-specialist).
- Skills name personas by ID only via an in-body load instruction; the
  drive-agent-personas SKILL.md is the indirection layer that resolves
  IDs to personas/<id>.md.
- Atomic skill = one persona (SRP analogue); composite skills are
  first-class with an orchestrator persona (typically tech-lead).
- Conventions are skill-author discipline, not runtime contracts.

Plan: 3 milestones, 16 tasks. M1 is a kill-the-project gate that runs an
A/B test of the architect persona against the same artefact the original
reviewer signed off on at PR #434 R2 commit 68ebbeb (when AuthoredContractSpace
was committed and the typology-prefix concerns were missed). Project halts at
M1 if the construction is theatre. M2 populates the library; M3 retrofits
existing skills and decomposes /drive-pr-local-review.
wmadden added a commit that referenced this pull request May 9, 2026
…oc admits Probes as optional (M1 T1.5)

User-driven replan from m1 R1: the persona currently encodes the
*value* (be suspicious of qualifier prefixes) without the *cognitive
move* (ask: what does this distinguish it from?). Suspicion-as-value
produces "I noticed naming concerns" output; suspicion-as-trigger-
plus-question produces "this prefix performs a non-existent
partition" output. The five probes operationalise the architect's
naming/typology cognitive habits as concrete questions with concrete
triggers and (where applicable) criteria for a good answer.

architect.md changes:

  * Insert ## Probes between ## Responsibilities and ## Vocabulary
    cues (orchestrator-pinned location). All other sections (stance,
    priorities, responsibilities, vocabulary cues, out of scope) are
    byte-identical.
  * Five probes pasted verbatim from the orchestrator-notes record
    in projects/agent-personas/reviews/code-review.md § Orchestrator
    notes § m1 R1 → m1 R2 § Probe set:
      1. Discriminator-completeness probe (concrete / singular /
         structural / stable answer required for any qualifier-
         style prefix)
      2. Consumer-vs-essence probe (does the name describe what the
         type IS, or who happens to use it?)
      3. Concept-vs-mechanism probe (domain concept vs implementation
         mechanism)
      4. Symmetry probe (sibling types should be structurally
         symmetric)
      5. 'Reads cold' probe (cold-expectation vs actual responsibility)

_shape.md changes:

  * Promote singular "Optional section" header to plural "Optional
    sections" so the new probes entry doesn't look like a peer of the
    Out-of-scope section.
  * Add ## Probes as optional section #7. Body explains:
      - Probes are concrete *questions* the persona asks in specific
        situations, distinct from Priorities (what to watch for first)
        and Vocabulary cues (language patterns to use/avoid).
      - Each probe pairs (a) trigger with (b) question and ideally
        (c) criteria for a good answer.
      - Section exists because suspicion-as-value produces vague
        output; suspicion-as-trigger-plus-question produces specific
        output.
      - Not every persona needs probes. Review-class personas
        (architect, principal-engineer, devrel) typically benefit;
        implementation-class personas (developer, modes that produce
        more than evaluate) should omit rather than invent thin
        probes.
      - architect.md ## Probes is the v1 reference example.
  * Append a sixth review-checklist item that asks the author to
    confirm the optional Probes section is present-if-applicable
    (review-class personas with cognitive habits that decompose into
    trigger-plus-question pairs) or omitted-if-thin.

No A/B re-test this round per the orchestrator's plan.md amendment;
verification of probe effectiveness is deferred to M3 / Task 3.5
(E2E /drive-pr-local-review against PR #434, the natural test bed).

AC-5 stays PASS — the new probes section is verified by cold-read in
the m1 R2 validation gate, not by re-running the A/B test (the
construction's verdict-shifting effect was already demonstrated at
m1 R1; the probes are a refinement of effectiveness, not a re-test
of the construction).

Refs: TML-2397, projects/agent-personas/spec.md AC1 (persona content
quality); plan.md Task 1.5; reviews/code-review.md § Orchestrator
notes § m1 R1 → m1 R2.
wmadden added a commit that referenced this pull request May 9, 2026
…arity + probe-effectiveness (T3.5)

Per plan T3.5 + AC4 verification + the m1 R2 deferral of probe-
effectiveness verification: ran the post-decomposition drive-pr-
local-review composite against PR #434 at commit ee05b2b
(PR head ref at the time of this E2E; source-pinned per the m1 R1
contamination-prevention learning). One sub-subagent invocation
ran the composite end-to-end (composite's § 1 / § 2 scope-and-
spec, then § 3.1 / § 3.2 / § 3.3 sub-skill delegations, then § 4
synthesis).

Sub-subagent ID: 52f5750e-69cb-4eb0-861b-5df1d3211b50 (one-shot;
not resumed).

Artefacts captured at projects/agent-personas/assets/m3-e2e/:

  * system-design-review.md (architect lens; ~29 KB; 251 lines).
    Verdict CONCERNS. 7 substantive findings (A01-A07). Headline:
    A01 - five-of-everything for {hash, invariants} (5 consumer-
    named structurally-identical types); A02 - flat
    ContractSpace<TContract> with runtime discriminators (six
    branches re-encoding a partition the type system says doesn't
    exist).

  * code-review.md (principal-engineer lens; ~31 KB; 204 lines).
    AC verification: 4 PASS / 1 FAIL / 3 WEAK / 3 NOT VERIFIED on
    sub-spec AM1-AM11. Headline F01 - AM2 sub-spec text
    contradicts shipped fail-loud LEGACY_MARKER_SHAPE behaviour
    (spec drift, not code drift). F02 - LEGACY_MARKER_SHAPE
    remediation hint destructively under-specified.

  * walkthrough.md (tech-lead lens; ~24 KB; 178 lines). Reads as
    narrative; references sibling reviews at the right altitude;
    surfaces the LEGACY_MARKER_SHAPE typology-vs-operability
    cross-lens conflict as a decision for the human (not merged).

  * score.md - PASS verdict on both criteria; detailed scoring;
    honest framing per learnings.md.

Verdict: PASS on both criteria.

  * TC-13 parity: PASS. All three artefacts side-by-side; format
    unchanged (system-design-review follows pre-decomposition § 3
    minimum-coverage; code-review follows § 4.2 required-sections
    + § 4.5 verdict-table-and-summary; walkthrough follows § 5 /
    drive-pr-walkthrough template). Quality at parity.

  * Probe-effectiveness verification (deferred from m1 R2): PASS,
    with nuanced reading. The architect persona's discriminator-
    completeness probe specifically did its load-bearing job - F4
    / F6 prefixes were checked for and confirmed eliminated at
    ee05b2b (no residue beyond a stale fixture-comment surfaced
    as docs-follow-up). Probes additionally surfaced new typology
    defects A01 / A02 / A03 - direct intellectual descendants of
    the F4 / F6 cognitive moves applied to the current surface.
    The sub-subagent's honesty check confirms it would have
    demoted A01 to "minor naming cleanup" without the probes
    loaded.

Honest framing per learnings.md (the m1 R1 "personas raise the
floor" entry):

  * The strongest forms of A01 / A02 (e.g. "introduce
    ContractStateRef as the canonical type") are iteration-with-
    the-user material. The persona raised the floor; it did not
    eliminate the post-implementation interactive-review pass.
    Consistent with the m1 R2 caveat.

  * The persona correctly REFERRED the buildability-vs-typology
    trade-off (consolidating would change the migration-tools
    import graph) to the principal-engineer rather than
    adjudicating from the architect's seat. The persona discipline
    held.

Methodology notes:

  * Source-pinning to ee05b2b via git show <sha>:<path> was
    enforced and confirmed by the sub-subagent's methodology-
    notes section in each artefact. Workspace-tree versions of
    projects/extension-contract-spaces/** were NOT consulted.

  * Artefact directory was overridden from the composite's default
    (<spec-dir>/reviews/pr-434/) to projects/agent-personas/
    assets/m3-e2e/ - deliberate because the artefacts are
    auditable evidence for M3 / Task 3.5 score, not the canonical
    PR review.

  * Did not write a new spec.md - the canonical exists at
    ee05b2b; per composite § 2.3 no inferred review-spec needed.

What this does NOT verify (deferred to T3.6):

  * Behaviour smoke on the Shape-A retrofits (T3.2 / T3.3) -
    confirming loop / response shape / probing style are observably
    unchanged from pre-retrofit.

  * Cross-pollination preservation on the Shape-B
    drive-design-discussion retrofit - confirming an architect-
    raised concern can be referenced from PE-mode without re-
    adjudication.

Refs: TML-2397, projects/agent-personas/spec.md AC3 + AC4 + AC5
(probe-effectiveness deferred from m1 R2 per learnings.md);
plan.md Task 3.5; reviews/code-review.md AC scoreboard.
wmadden added a commit that referenced this pull request May 9, 2026
New project: a shared agent-persona library at .agents/skills/drive-agent-personas/
that lets skills declare which executor identity should run them, shifting
execution-time defaults toward a deliberately-chosen bias-set instead of the
agent default. Plugs the F0-F6-class vocabulary-and-typology leak that
M1-cleanup of extension-contract-spaces made visible.

Spec pins:
- v1 ships seven personas (PM, principal-engineer, architect, tech-lead,
  developer-default, devrel, oss-specialist).
- Skills name personas by ID only via an in-body load instruction; the
  drive-agent-personas SKILL.md is the indirection layer that resolves
  IDs to personas/<id>.md.
- Atomic skill = one persona (SRP analogue); composite skills are
  first-class with an orchestrator persona (typically tech-lead).
- Conventions are skill-author discipline, not runtime contracts.

Plan: 3 milestones, 16 tasks. M1 is a kill-the-project gate that runs an
A/B test of the architect persona against the same artefact the original
reviewer signed off on at PR #434 R2 commit 68ebbeb (when AuthoredContractSpace
was committed and the typology-prefix concerns were missed). Project halts at
M1 if the construction is theatre. M2 populates the library; M3 retrofits
existing skills and decomposes /drive-pr-local-review.
wmadden added a commit that referenced this pull request May 9, 2026
…oc admits Probes as optional (M1 T1.5)

User-driven replan from m1 R1: the persona currently encodes the
*value* (be suspicious of qualifier prefixes) without the *cognitive
move* (ask: what does this distinguish it from?). Suspicion-as-value
produces "I noticed naming concerns" output; suspicion-as-trigger-
plus-question produces "this prefix performs a non-existent
partition" output. The five probes operationalise the architect's
naming/typology cognitive habits as concrete questions with concrete
triggers and (where applicable) criteria for a good answer.

architect.md changes:

  * Insert ## Probes between ## Responsibilities and ## Vocabulary
    cues (orchestrator-pinned location). All other sections (stance,
    priorities, responsibilities, vocabulary cues, out of scope) are
    byte-identical.
  * Five probes pasted verbatim from the orchestrator-notes record
    in projects/agent-personas/reviews/code-review.md § Orchestrator
    notes § m1 R1 → m1 R2 § Probe set:
      1. Discriminator-completeness probe (concrete / singular /
         structural / stable answer required for any qualifier-
         style prefix)
      2. Consumer-vs-essence probe (does the name describe what the
         type IS, or who happens to use it?)
      3. Concept-vs-mechanism probe (domain concept vs implementation
         mechanism)
      4. Symmetry probe (sibling types should be structurally
         symmetric)
      5. 'Reads cold' probe (cold-expectation vs actual responsibility)

_shape.md changes:

  * Promote singular "Optional section" header to plural "Optional
    sections" so the new probes entry doesn't look like a peer of the
    Out-of-scope section.
  * Add ## Probes as optional section #7. Body explains:
      - Probes are concrete *questions* the persona asks in specific
        situations, distinct from Priorities (what to watch for first)
        and Vocabulary cues (language patterns to use/avoid).
      - Each probe pairs (a) trigger with (b) question and ideally
        (c) criteria for a good answer.
      - Section exists because suspicion-as-value produces vague
        output; suspicion-as-trigger-plus-question produces specific
        output.
      - Not every persona needs probes. Review-class personas
        (architect, principal-engineer, devrel) typically benefit;
        implementation-class personas (developer, modes that produce
        more than evaluate) should omit rather than invent thin
        probes.
      - architect.md ## Probes is the v1 reference example.
  * Append a sixth review-checklist item that asks the author to
    confirm the optional Probes section is present-if-applicable
    (review-class personas with cognitive habits that decompose into
    trigger-plus-question pairs) or omitted-if-thin.

No A/B re-test this round per the orchestrator's plan.md amendment;
verification of probe effectiveness is deferred to M3 / Task 3.5
(E2E /drive-pr-local-review against PR #434, the natural test bed).

AC-5 stays PASS — the new probes section is verified by cold-read in
the m1 R2 validation gate, not by re-running the A/B test (the
construction's verdict-shifting effect was already demonstrated at
m1 R1; the probes are a refinement of effectiveness, not a re-test
of the construction).

Refs: TML-2397, projects/agent-personas/spec.md AC1 (persona content
quality); plan.md Task 1.5; reviews/code-review.md § Orchestrator
notes § m1 R1 → m1 R2.
wmadden added a commit that referenced this pull request May 9, 2026
…arity + probe-effectiveness (T3.5)

Per plan T3.5 + AC4 verification + the m1 R2 deferral of probe-
effectiveness verification: ran the post-decomposition drive-pr-
local-review composite against PR #434 at commit ee05b2b
(PR head ref at the time of this E2E; source-pinned per the m1 R1
contamination-prevention learning). One sub-subagent invocation
ran the composite end-to-end (composite's § 1 / § 2 scope-and-
spec, then § 3.1 / § 3.2 / § 3.3 sub-skill delegations, then § 4
synthesis).

Sub-subagent ID: 52f5750e-69cb-4eb0-861b-5df1d3211b50 (one-shot;
not resumed).

Artefacts captured at projects/agent-personas/assets/m3-e2e/:

  * system-design-review.md (architect lens; ~29 KB; 251 lines).
    Verdict CONCERNS. 7 substantive findings (A01-A07). Headline:
    A01 - five-of-everything for {hash, invariants} (5 consumer-
    named structurally-identical types); A02 - flat
    ContractSpace<TContract> with runtime discriminators (six
    branches re-encoding a partition the type system says doesn't
    exist).

  * code-review.md (principal-engineer lens; ~31 KB; 204 lines).
    AC verification: 4 PASS / 1 FAIL / 3 WEAK / 3 NOT VERIFIED on
    sub-spec AM1-AM11. Headline F01 - AM2 sub-spec text
    contradicts shipped fail-loud LEGACY_MARKER_SHAPE behaviour
    (spec drift, not code drift). F02 - LEGACY_MARKER_SHAPE
    remediation hint destructively under-specified.

  * walkthrough.md (tech-lead lens; ~24 KB; 178 lines). Reads as
    narrative; references sibling reviews at the right altitude;
    surfaces the LEGACY_MARKER_SHAPE typology-vs-operability
    cross-lens conflict as a decision for the human (not merged).

  * score.md - PASS verdict on both criteria; detailed scoring;
    honest framing per learnings.md.

Verdict: PASS on both criteria.

  * TC-13 parity: PASS. All three artefacts side-by-side; format
    unchanged (system-design-review follows pre-decomposition § 3
    minimum-coverage; code-review follows § 4.2 required-sections
    + § 4.5 verdict-table-and-summary; walkthrough follows § 5 /
    drive-pr-walkthrough template). Quality at parity.

  * Probe-effectiveness verification (deferred from m1 R2): PASS,
    with nuanced reading. The architect persona's discriminator-
    completeness probe specifically did its load-bearing job - F4
    / F6 prefixes were checked for and confirmed eliminated at
    ee05b2b (no residue beyond a stale fixture-comment surfaced
    as docs-follow-up). Probes additionally surfaced new typology
    defects A01 / A02 / A03 - direct intellectual descendants of
    the F4 / F6 cognitive moves applied to the current surface.
    The sub-subagent's honesty check confirms it would have
    demoted A01 to "minor naming cleanup" without the probes
    loaded.

Honest framing per learnings.md (the m1 R1 "personas raise the
floor" entry):

  * The strongest forms of A01 / A02 (e.g. "introduce
    ContractStateRef as the canonical type") are iteration-with-
    the-user material. The persona raised the floor; it did not
    eliminate the post-implementation interactive-review pass.
    Consistent with the m1 R2 caveat.

  * The persona correctly REFERRED the buildability-vs-typology
    trade-off (consolidating would change the migration-tools
    import graph) to the principal-engineer rather than
    adjudicating from the architect's seat. The persona discipline
    held.

Methodology notes:

  * Source-pinning to ee05b2b via git show <sha>:<path> was
    enforced and confirmed by the sub-subagent's methodology-
    notes section in each artefact. Workspace-tree versions of
    projects/extension-contract-spaces/** were NOT consulted.

  * Artefact directory was overridden from the composite's default
    (<spec-dir>/reviews/pr-434/) to projects/agent-personas/
    assets/m3-e2e/ - deliberate because the artefacts are
    auditable evidence for M3 / Task 3.5 score, not the canonical
    PR review.

  * Did not write a new spec.md - the canonical exists at
    ee05b2b; per composite § 2.3 no inferred review-spec needed.

What this does NOT verify (deferred to T3.6):

  * Behaviour smoke on the Shape-A retrofits (T3.2 / T3.3) -
    confirming loop / response shape / probing style are observably
    unchanged from pre-retrofit.

  * Cross-pollination preservation on the Shape-B
    drive-design-discussion retrofit - confirming an architect-
    raised concern can be referenced from PE-mode without re-
    adjudication.

Refs: TML-2397, projects/agent-personas/spec.md AC3 + AC4 + AC5
(probe-effectiveness deferred from m1 R2 per learnings.md);
plan.md Task 3.5; reviews/code-review.md AC scoreboard.
wmadden added a commit that referenced this pull request May 9, 2026
…plans

Tighten SqlMigrationPlan, WriteMarkerInput, MergeMarkerInput, and the
ControlFamilyInstance/SqlControlAdapter readMarker signatures so the
contract space is required at every call site rather than silently
defaulting to APP_SPACE_ID. Thread spaceId through Postgres and SQLite
planners, planner-produced renderable migrations, and migration runners
so per-extension plans key their prisma_contract.marker rows by their
own space instead of collapsing onto the app row.

App-level CLI callsites (db init/update, migration plan/new/apply,
control-api client) explicitly pass APP_SPACE_ID. Mongo readMarker
accepts the parameter and rejects non-app spaces until per-space
support lands. Test fixtures and inline plan/marker constructions are
updated accordingly.

Closes the sql-marker.ts CR thread on PR #434 by removing the optional
space?: string fallback that masked missing spaceId plumbing.
wmadden added a commit that referenced this pull request May 9, 2026
Re-emitting the same package against an existing per-package
directory now clears the directory first and rewrites byte-identical
contents, so re-running migrate against an unchanged descriptor is a
no-op on disk and never leaves stale files behind. The lower-level
writeMigrationPackage stays strict so the CLI authoring path
(migration plan / migration new) still refuses to clobber an existing
authored migration.

Adds a same-dir overwrite-idempotency test that seeds a stale.json,
re-materialises, and asserts the directory contents converge on the
canonical three-file shape with byte-identical migration.json,
ops.json, and contract.json.

Closes the materialise-migration-package CR thread on PR #434.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
test/e2e/framework/test/sqlite/migrations/harness.ts (1)

1-3: ⚡ Quick win

Use pathe instead of node:path in this TypeScript harness.

While touching this file, please switch join to pathe to match the repo rule for cross-platform path behavior.

Proposed patch
-import { join } from 'node:path';
+import { join } from 'pathe';

Per coding guidelines: "**/*.{ts,tsx,mts,cts}: Use pathe instead of node:path for path manipulation in TypeScript files."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/e2e/framework/test/sqlite/migrations/harness.ts` around lines 1 - 3,
Replace the node:path import and usage with pathe to follow repo cross-platform
rules: change the import that currently pulls join from 'node:path' to import
join (or the appropriate function) from 'pathe' and update any references in
this harness (harness.ts) that call join so they use the pathe join; keep
mkdtempSync, rmSync, tmpdir imports unchanged and ensure TypeScript imports stay
consistent with the project's style.
packages/3-targets/6-adapters/sqlite/test/migrations/runner.idempotency.test.ts (1)

86-88: ⚡ Quick win

Use APP_SPACE_ID in marker query params instead of hardcoded 'app'.

Line [87], Line [135], and Line [168] hardcode the space string even though APP_SPACE_ID is already imported and used for plan creation. Reusing the constant keeps test intent aligned with the framework source of truth.

♻️ Suggested patch
-      ['app'],
+      [APP_SPACE_ID],
...
-      ['app'],
+      [APP_SPACE_ID],
...
-      ['app'],
+      [APP_SPACE_ID],

Also applies to: 134-136, 167-169

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/3-targets/6-adapters/sqlite/test/migrations/runner.idempotency.test.ts`
around lines 86 - 88, Replace the hardcoded 'app' space string in the marker SQL
query parameters with the imported APP_SPACE_ID constant so the tests use the
same source-of-truth as plan creation; update occurrences where the query
'SELECT COUNT(*) as cnt FROM _prisma_marker WHERE space = ?' (and similar
COUNT/SELECTs against _prisma_marker) pass ['app'] to instead pass
[APP_SPACE_ID], ensuring all assertions in runner.idempotency.test.ts reference
APP_SPACE_ID rather than the literal 'app'.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@packages/3-targets/6-adapters/sqlite/test/migrations/runner.idempotency.test.ts`:
- Around line 86-88: Replace the hardcoded 'app' space string in the marker SQL
query parameters with the imported APP_SPACE_ID constant so the tests use the
same source-of-truth as plan creation; update occurrences where the query
'SELECT COUNT(*) as cnt FROM _prisma_marker WHERE space = ?' (and similar
COUNT/SELECTs against _prisma_marker) pass ['app'] to instead pass
[APP_SPACE_ID], ensuring all assertions in runner.idempotency.test.ts reference
APP_SPACE_ID rather than the literal 'app'.

In `@test/e2e/framework/test/sqlite/migrations/harness.ts`:
- Around line 1-3: Replace the node:path import and usage with pathe to follow
repo cross-platform rules: change the import that currently pulls join from
'node:path' to import join (or the appropriate function) from 'pathe' and update
any references in this harness (harness.ts) that call join so they use the pathe
join; keep mkdtempSync, rmSync, tmpdir imports unchanged and ensure TypeScript
imports stay consistent with the project's style.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: fc897738-51d0-40e8-b381-16e45a2f86c5

📥 Commits

Reviewing files that changed from the base of the PR and between b245d27 and e2e5c6c.

📒 Files selected for processing (66)
  • packages/1-framework/1-core/framework-components/src/control/control-instances.ts
  • packages/1-framework/1-core/framework-components/src/control/control-migration-types.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-new.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts
  • packages/1-framework/3-tooling/cli/src/control-api/client.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/db-init.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/db-update.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/migration-apply.ts
  • packages/1-framework/3-tooling/migration/src/io.ts
  • packages/1-framework/3-tooling/migration/test/materialise-migration-package.test.ts
  • packages/2-mongo-family/9-family/src/core/control-instance.ts
  • packages/2-sql/5-runtime/src/sql-marker.ts
  • packages/2-sql/5-runtime/test/sql-marker.test.ts
  • packages/2-sql/5-runtime/test/utils.ts
  • packages/2-sql/9-family/src/core/control-adapter.ts
  • packages/2-sql/9-family/src/core/control-instance.ts
  • packages/2-sql/9-family/src/core/migrations/plan-helpers.ts
  • packages/2-sql/9-family/src/core/migrations/types.ts
  • packages/2-sql/9-family/test/migrations.types.test.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/planner-produced-postgres-migration.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/planner.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/runner.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/statement-builders.ts
  • packages/3-targets/3-targets/postgres/test/migrations/statement-builders.test.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/planner-produced-sqlite-migration.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/planner.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/runner.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/statement-builders.ts
  • packages/3-targets/3-targets/sqlite/test/migrations/nullability-backfill.test.ts
  • packages/3-targets/3-targets/sqlite/test/migrations/planner.authoring-surface.test.ts
  • packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/fixtures/runner-fixtures.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/op-factory-call.lowering.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.authoring-surface.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.behavior.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.case1.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.contract-to-schema-ir.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.fk-config.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.referential-actions.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.semantic-satisfaction.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.storage-types.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.storage-types.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/render-typescript.roundtrip.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.basic.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.errors.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.execution-checks.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.idempotency.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.policy.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/schema-verify.after-runner.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/fixtures/runner-fixtures.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner-introspection.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/render-typescript.roundtrip.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.basic.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.errors.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.idempotency.test.ts
  • test/e2e/framework/test/sqlite/migrations/harness.ts
  • test/integration/test/cli.db-verify.e2e.test.ts
  • test/integration/test/family.sign-database.test.ts
  • test/integration/test/family.verify-database.basic.test.ts
  • test/integration/test/family.verify-database.errors.test.ts
  • test/integration/test/referential-actions.integration.test.ts
✅ Files skipped from review due to trivial changes (3)
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.referential-actions.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/schema-verify.after-runner.integration.test.ts
  • test/integration/test/cli.db-verify.e2e.test.ts
🚧 Files skipped from review as they are similar to previous changes (8)
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.basic.integration.test.ts
  • packages/1-framework/3-tooling/migration/test/materialise-migration-package.test.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/runner.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.idempotency.integration.test.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/runner.ts
  • packages/1-framework/3-tooling/migration/src/io.ts
  • packages/2-sql/5-runtime/test/sql-marker.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.errors.test.ts

wmadden added a commit that referenced this pull request May 9, 2026
readMigrationPackage now resolves the incoming dir to an absolute path
before constructing the OnDiskMigrationPackage and before formatting
ENOENT / hash-mismatch error paths, so the documented absolute-path
contract on dirPath holds even when callers pass a relative path.
Diagnostics now consistently point at the resolved absolute directory.

Closes the readMigrationPackage CR thread on PR #434.
wmadden added a commit that referenced this pull request May 9, 2026
…, not name shape

listPinnedSpaceDirectories distinguished user-authored migration
directories from pinned per-space subdirectories with a regex on the
directory name (^\d{8}T\d{4}_), encoding the formatMigrationDirName
convention as if it were a contract. Directory names belong to users
and are informative, not structural.

Switch to the same discriminator readMigrationsDir already uses:
presence of migration.json at the directory root. A subdirectory is a
migration directory iff it contains the manifest; otherwise it is a
candidate pinned per-space subdirectory. ENOENT means "no manifest";
other stat errors propagate. Sorted, deterministic output is
preserved.

This frees users to name their migration directories however they
like and removes a brittleness flagged in PR #434 review.
wmadden added a commit that referenced this pull request May 9, 2026
…plans

Tighten SqlMigrationPlan, WriteMarkerInput, MergeMarkerInput, and the
ControlFamilyInstance/SqlControlAdapter readMarker signatures so the
contract space is required at every call site rather than silently
defaulting to APP_SPACE_ID. Thread spaceId through Postgres and SQLite
planners, planner-produced renderable migrations, and migration runners
so per-extension plans key their prisma_contract.marker rows by their
own space instead of collapsing onto the app row.

App-level CLI callsites (db init/update, migration plan/new/apply,
control-api client) explicitly pass APP_SPACE_ID. Mongo readMarker
accepts the parameter and rejects non-app spaces until per-space
support lands. Test fixtures and inline plan/marker constructions are
updated accordingly.

Closes the sql-marker.ts CR thread on PR #434 by removing the optional
space?: string fallback that masked missing spaceId plumbing.
wmadden added a commit that referenced this pull request May 9, 2026
Re-emitting the same package against an existing per-package
directory now clears the directory first and rewrites byte-identical
contents, so re-running migrate against an unchanged descriptor is a
no-op on disk and never leaves stale files behind. The lower-level
writeMigrationPackage stays strict so the CLI authoring path
(migration plan / migration new) still refuses to clobber an existing
authored migration.

Adds a same-dir overwrite-idempotency test that seeds a stale.json,
re-materialises, and asserts the directory contents converge on the
canonical three-file shape with byte-identical migration.json,
ops.json, and contract.json.

Closes the materialise-migration-package CR thread on PR #434.
wmadden added a commit that referenced this pull request May 9, 2026
readMigrationPackage now resolves the incoming dir to an absolute path
before constructing the OnDiskMigrationPackage and before formatting
ENOENT / hash-mismatch error paths, so the documented absolute-path
contract on dirPath holds even when callers pass a relative path.
Diagnostics now consistently point at the resolved absolute directory.

Closes the readMigrationPackage CR thread on PR #434.
wmadden added 18 commits May 9, 2026 19:31
assertValidSpaceId previously asserted the input was string, which is a no-op
since it already is. Introduce a branded ValidSpaceId type, narrow isValidSpaceId
to a type predicate, and update the assertion signature so the compiler can
track validated space ids through downstream filesystem helpers. No runtime
behavior change.
Reuse the top-level node:fs/promises import instead of dynamically re-importing
mkdir mid-test.
Promote the manifest filename literal from a module-private const to an
exported one so other helpers in the package can discriminate migration
directories by manifest presence (the same rule readMigrationsDir uses)
without re-declaring the literal.
…, not name shape

listPinnedSpaceDirectories distinguished user-authored migration
directories from pinned per-space subdirectories with a regex on the
directory name (^\d{8}T\d{4}_), encoding the formatMigrationDirName
convention as if it were a contract. Directory names belong to users
and are informative, not structural.

Switch to the same discriminator readMigrationsDir already uses:
presence of migration.json at the directory root. A subdirectory is a
migration directory iff it contains the manifest; otherwise it is a
candidate pinned per-space subdirectory. ENOENT means "no manifest";
other stat errors propagate. Sorted, deterministic output is
preserved.

This frees users to name their migration directories however they
like and removes a brittleness flagged in PR #434 review.
…ture to integration-tests workspace (M1-cleanup T-cleanup.1)

Drops the workspace package `@prisma-next/extension-test-contract-space` at
packages/3-extensions/test-contract-space/. The fixture existed only as
self-test scaffolding; no other workspace consumes it. Hosting it under
packages/3-extensions/ alongside production extensions (pgvector,
cipherstash, arktype-json) gave it a misleading "real extension" shape
(F1).

Relocates the descriptor + contract + migrations + descriptor sniff-test
to test/integration/test/contract-space-fixture/, where the
@prisma-next/integration-tests workspace already provides the
@prisma-next/family-sql, @prisma-next/sql-contract, and
@prisma-next/contract dependencies the fixture needs. M2 T2.5 (codec
hook + per-space db init/update tests) will extend this fixture from its
new home.

Also updates packages/1-framework/3-tooling/migration/test/deletable-node-modules.test.ts:
its node_modules stand-in directory name no longer references the dead
package; the comment block points at the new fixture location.

Refs: TML-2397
Closes-thread: PRRT_kwDOQM0QJc6AnF1X
…cleanup.0/1/2 closure

M1s functional acceptance was met but post-implementation review surfaced
six design-quality findings (F0–F5 in reviews/code-review.md). Codify the
remediation as Milestone 1-cleanup with explicit task breakdown and
validation gates so subsequent rounds have a clean contract.

R1 closed F0 / F1 / F5: F0 (manifest-presence migration-dir detection)
implemented in c19086d90; F1 (test-contract-space fixture relocation)
implemented in db33795e3; F5 (CodeRabbit tsdown nitpick) made moot by F1.
Mark T-cleanup.0/1/2 done with their resolution notes.

Update spec § 7 + § AM11 + References and the resolved-during-finalisation
note to point at the fixtures new home (test/integration/test/
contract-space-fixture/) rather than the dropped packages/3-extensions/
test-contract-space/ — kept the design framing while truing up the
canonical path.

F2 / F3 / F4 (T-cleanup.3 / T-cleanup.4) remain open; they are the next
remediation rounds.
…ol-spaces (M1-cleanup F3)

Hoist APP_SPACE_ID into `@prisma-next/framework-components/control` as
the single source of truth (`packages/1-framework/1-core/framework-components/src/control/control-spaces.ts`).
Drop the four duplicate declarations that previously coexisted —

  * packages/1-framework/3-tooling/migration/src/space-layout.ts
  * packages/2-sql/5-runtime/src/sql-marker.ts
  * packages/3-targets/3-targets/postgres/src/core/migrations/statement-builders.ts
  * packages/3-targets/3-targets/sqlite/src/core/migrations/statement-builders.ts

— and replace each with an `import { APP_SPACE_ID } from
"@prisma-next/framework-components/control"` plus a re-export so existing
barrel surfaces (sql-runtime, postgres / sqlite statement-builders,
migration-tools/spaces) keep their public shape.

Eliminate raw `"app"` literals in target / runtime / adapter source code
in favour of `APP_SPACE_ID` (or `${APP_SPACE_ID}` inside SQL templates):

  * postgres + sqlite ensureMarkerTableStatement (DEFAULT clause)
  * postgres migrateMarkerSchemaStatements (UPDATE / ALTER DEFAULT) —
    minimal in-place substitution, structure preserved; the array as a
    whole is owned by F2 (M1-cleanup T-cleanup.4) and will be deleted
    there.
  * sqlite migrateMarkerSchemaSqlite (rebuild-table dance)
  * postgres + sqlite adapter.readMarkerStatement (params)
  * postgres + sqlite control-adapter readMarker (params)

Add a regression guardrail at `scripts/lint-app-space-id.mjs` and wire
it into `pnpm lint:deps`. Two policed invariants:

  1. Exactly one `export const APP_SPACE_ID` declaration under
     `packages/`, located at the canonical file.
  2. No raw `"app"` / `app` literals in `packages/2-sql/**/src` or
     `packages/3-targets/**/src` (test files and JSDoc lines are
     excluded — the literal is often the test data or prose).

JSDoc lines that document the literal value of APP_SPACE_ID (e.g.
`{@link APP_SPACE_ID} (`app`)`) are intentionally preserved as prose;
they are not runtime values.

Refs: TML-2397, projects/extension-contract-spaces/reviews/code-review.md F3.
…o control plane (M1-cleanup F4)

Move and rename the contract-space identity / authoring types from the
SQL family up into `@prisma-next/framework-components/control`. Contract
spaces are a framework concept (the project spec is family-agnostic per
FRs 3-6), not a SQL one — a Mongo descriptor will eventually consume the
same types specialised to its own contract.

Renames + new home (`control-spaces.ts`):

  * ExtensionContractRef       -> ContractSpaceHeadRef
  * ExtensionMigrationPackage  -> AuthoredMigrationPackage
  * ExtensionContractSpace     -> AuthoredContractSpace<TContract = Contract>

`AuthoredContractSpace` is now generic over its contract value so the
SQL family pins `AuthoredContractSpace<Contract<SqlStorage>>` on
`SqlControlExtensionDescriptor.contractSpace?:` while the framework
shape stays family-neutral.

Also hoists the migration-package metadata types so
`AuthoredMigrationPackage` can reference them from the framework layer
without an upward import to `migration-tools`:

  * MigrationHints / MigrationMetadata move to
    `framework-components/control/control-migration-types.ts`.
  * `migration-tools/src/metadata.ts` becomes a re-export from
    `framework-components/control` so existing
    `@prisma-next/migration-tools/metadata` consumers (12 files in CLI
    + tests) continue to work unchanged. The arktype runtime schema
    that validates `migration.json` stays in `migration-tools/io.ts`
    (it is a write-time concern, not a type definition).

Producer-side rename in `migration-tools`:

  * writeExtensionMigrationPackage -> writeAuthoredMigrationPackage
    (and its test file renamed alongside).
  * Drops the lampshaded `MigrationPackageContents` duplicate in
    `migration-tools/src/io.ts` and imports the canonical
    `AuthoredMigrationPackage` instead.

Consumer-side updates:

  * `2-sql/9-family/src/core/migrations/types.ts` drops the three local
    interface declarations and uses `AuthoredContractSpace` from
    framework-components.
  * `2-sql/9-family/src/exports/control.ts` drops the three Extension*
    re-exports (no backward-compat shims per repo convention).
  * `2-sql/9-family/test/migrations.types.test-d.ts` updates names.
  * `test/integration/test/contract-space-fixture/{control,migrations}.ts`
    update imports / type names; the fixture continues to specialise
    `AuthoredContractSpace<Contract<SqlStorage>>` for its descriptor.

Spec § 1 of `framework-mechanism.spec.md` updated to reflect the new
type names and locations. § 3 / § 6 / § 7 still mention the old names
in narrative prose; surfacing those for orchestrator review (out of
the spec-edit authorisation for this round).

Refs: TML-2397, projects/extension-contract-spaces/reviews/code-review.md F4.
R2 landed F3 + F4 in 9e39382 + 68ebbeb but the spec/plan referenced
old type and helper names in narrative prose outside § 1 of the sub-spec
(the implementer was scoped to § 1 only). Update spec § 3 (helper-location
note + emission-helper paragraph) and § 6 (SpacePathInput.targetRef type
annotation) to use the renamed names; ditto plan T1.2 + T1.7 landed-
annotations. Mark T-cleanup.3 done with closure narrative covering both
findings, including the MigrationMetadata/MigrationHints hoist that R2
needed to make the layering work cleanly.

R3 (T-cleanup.4 / F2) remains, gating M1-cleanup SATISFIED.
…shape migration with structured detection (M1-cleanup F2)

The marker table moved from a single-row `id` PK to a per-space-row `space`
PK during contract-spaces work. Both targets carried a transitional
auto-migration helper that promoted legacy databases on every framework
boot — appropriate while the schema change was in flight, but a permanent
operational surface for a one-time concern past zero-range.

Delete the helpers (`migrateMarkerSchemaStatements` on Postgres,
`migrateMarkerSchemaSqlite` on SQLite) and replace them with a runtime
detection step at runner boot:

- `ensureControlTables` now returns `Result<void, SqlMigrationRunnerFailure>`
  and runs `detectLegacyMarkerShape` before creating the marker table.
- New `LEGACY_MARKER_SHAPE` `SqlMigrationRunnerErrorCode` carries a
  structured failure with the table name in `meta` and a summary that
  points the operator at the explicit remediation: drop the marker table
  and re-run `dbInit` from a clean baseline.
- Detection inspects `INFORMATION_SCHEMA.COLUMNS` (Postgres) or
  `PRAGMA table_info` (SQLite) for the absence of the `space` column on
  an existing marker table; fresh databases (table absent) and
  already-migrated databases (table present with `space`) both no-op.
- The detection step does not mutate the legacy table — operator
  intervention is the explicit remediation.

The `marker-schema-migration` test files (one per target) that exercised
the legacy → per-space promotion are deleted; coverage of the detection
step lands in each target adapter`s `runner.errors` test file alongside
existing `runnerFailure` scenarios.

Audit for analogous in-zero-range transitional migrations in the
postgres/sqlite control-plane DDL surfaces turned up no other
candidates: the ledger table is created with `IF NOT EXISTS` and has no
in-place upgrade helper, and no other `migrate*Schema` / promote-shape
paths exist in target sources.

References: PRRT_kwDOQM0QJc6AnH2D

M1-cleanup T-cleanup.4
…ED at 15e0534

3 implementer rounds + 3 reviewer rounds closed all 6 design-quality
findings (F0-F5) surfaced in the post-M1 design review. Final commit
SHAs: c19086d90 (F0 manifest-presence detection, pre-cleanup-milestone),
db33795e3 (F1 test-fixture relocation), 9e39382 (F3 APP_SPACE_ID
canonicalisation + lint guard), 68ebbeb (F4 contract-space type hoist
+ rename), 15e0534 (F2 transitional marker-migration deletion +
structured detection).

Mark T-cleanup.4 done with closure narrative (audit for analogous
in-zero-range transitional migrations across 2-sql + 3-targets came
back empty); promote the milestone heading to SATISFIED with the round
sequence and AC scoreboard summary preserved for the audit trail.

Project plan now stands at M1 + M1-cleanup SATISFIED; M2-M5 remain.
…prefix removal)

R3 reached SATISFIED at 15e0534 but interactive design-review of R2s
output surfaced F6: the Authored* prefix on the relocated types implies
a structural distinction between contract spaces that doesnt exist
(all spaces are equal at the type level — the app/extension designation
lives only in the orchestrator), and AuthoredMigrationPackage forks the
type hierarchy from the pre-existing on-disk MigrationPackage rather than
extending it.

Add T-cleanup.5 with the rename plan: ContractSpace<TContract>
(canonical, no prefix); MigrationPackage (canonical structural shape,
in framework-components/control); OnDiskMigrationPackage extends
MigrationPackage (in migration-tools/src/package.ts; adds dirPath);
materialiseMigrationPackage (renamed from writeAuthoredMigrationPackage,
not deleted — M3 consumes it). Add AC-D6. Flip milestone heading
SATISFIED → REOPENED for R4.

R4 is the rename pass; M3 (cipherstash) absorbs the import renames on
its next rebase.
…e typology (M1-cleanup F6)

Drop the `Authored` prefix from the contract-space types so the
canonical structural shape is `ContractSpace<TContract>` /
`MigrationPackage` (in `framework-components/control`). The on-disk
augmented form lives in `migration-tools/src/package.ts` as
`OnDiskMigrationPackage extends MigrationPackage` (adds `dirPath`).

Whether a value is the application's space or an extension's space
is a control-plane concern — the type carries no such distinction, and
the prior `Authored*` prefix wrongly implied a structural one. After
this rename, app-space and extension-space pipelines consume the same
shape; readers (`readMigrationPackage`, `readMigrationsDir`) return
`OnDiskMigrationPackage`; the framework's pinned-artefact emitter
takes the canonical `MigrationPackage`.

`writeAuthoredMigrationPackage` is renamed to
`materialiseMigrationPackage` — distinct verb from the lower-level
constituent-taking `writeMigrationPackage(dir, metadata, ops)` so the
struct-vs-constituents semantic difference stays visible at the call
site. The helper is renamed (not deleted) because the M3 cipherstash
branch consumes it; M3 absorbs the rename on its next rebase.

Hash and graph helpers (`verifyMigrationHash`, `reconstructGraph`)
take `OnDiskMigrationPackage` — `reconstructGraph` reads `dirPath` for
diagnostics and the readers'-side callers always have the augmented
form already.

The barrel `migration-tools/src/exports/package.ts` re-exports both
`MigrationPackage` (from framework-components) and
`OnDiskMigrationPackage` for ergonomic access at consumption sites.

Spec § 1 updated to track the renames; § 3 / § 7 references to
`writeAuthoredMigrationPackage` left for the orchestrator (mirroring
the R2 split). No GH thread to close — F6 surfaced in interactive
review.

AC-D6: `rg "Authored(ContractSpace|MigrationPackage)|writeAuthoredMigrationPackage" packages/ test/` returns no matches.
…ps (M1-cleanup R4 SATISFIED-candidate)

Implementer R4 landed F6 cleanly at f8649ba. Orchestrator close-ups:

- plan.md: T-cleanup.5 marked done with commit SHA + rename map preserved
  as audit trail; milestone heading flipped REOPENED -> SATISFIED-candidate;
  R4 outcome added; AC scoreboard candidate 7/7 pending reviewer.
- spec.md S 3 helper-location prose: writeAuthoredMigrationPackage ->
  materialiseMigrationPackage with full rename audit trail.
- spec.md S 7 (line 167) emission-helper detail: same rename + sentence
  on the verb-distinction from writeMigrationPackage(dir, metadata, ops)
  to keep the snapshot-vs-no-snapshot semantic visible at the call site.

S 1 was updated by the implementer in the prior commit per the round split.
Reviewer R4 still to verify before flipping milestone to SATISFIED.
…osed)

Reviewer R4 verdict SATISFIED. The contract-space typology flatten
(F6) closes cleanly: canonical ContractSpace<TContract> and
MigrationPackage in framework-components/control; OnDiskMigrationPackage
extends MigrationPackage in migration-tools for the deserialised-from-disk
variant; materialiseMigrationPackage replaces writeAuthoredMigrationPackage
(renamed, not deleted — M3 cipherstash branch consumes it on its next
rebase).

Trajectory: SATISFIED at 15e0534 post-R3 -> reopened at a9697ba for F6
-> re-SATISFIED at ac2157d post-R4. 7/7 ACs PASS, 15/15 GH PR threads
closed, validation gates green.

Reviewer surfaced one observational item (recorded in code-review.md, not
a finding): design-quality vocabulary findings have systematically surfaced
post-implementation in this milestone (F0–F6 cycle pattern). A
pre-implementation surface-vocabulary pass on M2/M3/M4/M5 would catch this
class earlier. Out of scope for R4; carried forward to next-milestone intake.
…plans

Tighten SqlMigrationPlan, WriteMarkerInput, MergeMarkerInput, and the
ControlFamilyInstance/SqlControlAdapter readMarker signatures so the
contract space is required at every call site rather than silently
defaulting to APP_SPACE_ID. Thread spaceId through Postgres and SQLite
planners, planner-produced renderable migrations, and migration runners
so per-extension plans key their prisma_contract.marker rows by their
own space instead of collapsing onto the app row.

App-level CLI callsites (db init/update, migration plan/new/apply,
control-api client) explicitly pass APP_SPACE_ID. Mongo readMarker
accepts the parameter and rejects non-app spaces until per-space
support lands. Test fixtures and inline plan/marker constructions are
updated accordingly.

Closes the sql-marker.ts CR thread on PR #434 by removing the optional
space?: string fallback that masked missing spaceId plumbing.
Re-emitting the same package against an existing per-package
directory now clears the directory first and rewrites byte-identical
contents, so re-running migrate against an unchanged descriptor is a
no-op on disk and never leaves stale files behind. The lower-level
writeMigrationPackage stays strict so the CLI authoring path
(migration plan / migration new) still refuses to clobber an existing
authored migration.

Adds a same-dir overwrite-idempotency test that seeds a stale.json,
re-materialises, and asserts the directory contents converge on the
canonical three-file shape with byte-identical migration.json,
ops.json, and contract.json.

Closes the materialise-migration-package CR thread on PR #434.
readMigrationPackage now resolves the incoming dir to an absolute path
before constructing the OnDiskMigrationPackage and before formatting
ENOENT / hash-mismatch error paths, so the documented absolute-path
contract on dirPath holds even when callers pass a relative path.
Diagnostics now consistently point at the resolved absolute directory.

Closes the readMigrationPackage CR thread on PR #434.
@wmadden
wmadden force-pushed the tml-2397-contract-spaces-first-class-schema-contributions-from branch from 7adb376 to 3e85bcb Compare May 9, 2026 17:31

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
scripts/lint-app-space-id.mjs (1)

107-116: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Reset LITERAL_RE.lastIndex before each file-level test.

Line 110 uses a global regex (/g) without resetting state first. If the previous iteration leaves lastIndex > 0, this can skip top-of-file 'app' literals in the next file and produce false negatives.

Suggested fix
 const literalViolations = [];
 for (const root of SCAN_ROOTS_FOR_LITERALS) {
   for (const file of walk(root)) {
     const contents = readFileSync(file, 'utf8');
+    LITERAL_RE.lastIndex = 0;
     if (!LITERAL_RE.test(contents)) continue;
     const lines = contents.split('\n');
     LITERAL_RE.lastIndex = 0;
#!/bin/bash
set -euo pipefail

# Reproduce stateful /g behavior that can affect per-file tests.
node --input-type=module <<'EOF'
const LITERAL_RE = /(['"])app\1/g;

const file1 = `const a = 1;\nconst s = 'app'`; // literal on final line
const file2 = `'app' at beginning`;

console.log('file1 precheck:', LITERAL_RE.test(file1), 'lastIndex:', LITERAL_RE.lastIndex);

// emulate line-by-line loop behavior in script
for (const line of file1.split('\n')) {
  LITERAL_RE.lastIndex = 0;
  LITERAL_RE.test(line);
}
console.log('after file1 line loop lastIndex:', LITERAL_RE.lastIndex);

// no reset before next file precheck (current pattern at Line 110)
console.log('file2 precheck without reset:', LITERAL_RE.test(file2), 'lastIndex:', LITERAL_RE.lastIndex);

// with reset
LITERAL_RE.lastIndex = 0;
console.log('file2 precheck with reset:', LITERAL_RE.test(file2), 'lastIndex:', LITERAL_RE.lastIndex);
EOF

nl -ba scripts/lint-app-space-id.mjs | sed -n '106,117p'
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/lint-app-space-id.mjs` around lines 107 - 116, The global regex
LITERAL_RE (used with /g) keeps state between tests causing false negatives when
checking entire file contents; before calling LITERAL_RE.test(contents) in the
file-level check inside the loop over SCAN_ROOTS_FOR_LITERALS and walk, reset
its state by setting LITERAL_RE.lastIndex = 0 so each file is tested from the
start (leave the per-line resets in the inner loop intact).
🧹 Nitpick comments (1)
scripts/lint-app-space-id.mjs (1)

118-124: ⚡ Quick win

Make comment-skip rules declarative instead of chained conditionals.

The hardcoded startsWith chain is harder to maintain as exceptions evolve. Move prefixes to a constant list and check with .some(...) for clearer rule ownership.

Refactor sketch
+const COMMENT_PREFIXES = ['//', '/**', '/*', '*/', '*'];
+
 ...
-      if (
-        trimmed.startsWith('//') ||
-        trimmed.startsWith('/**') ||
-        trimmed.startsWith('/*') ||
-        trimmed.startsWith('*/') ||
-        trimmed.startsWith('*')
-      ) {
+      if (COMMENT_PREFIXES.some((prefix) => trimmed.startsWith(prefix))) {
         continue;
       }

As per coding guidelines, "Use declarative configuration instead of hardcoded logic when rules change frequently, have exceptions, or need to be documented."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/lint-app-space-id.mjs` around lines 118 - 124, Replace the chained
startsWith calls with a declarative prefix list: define a constant array (e.g.,
SKIP_PREFIXES = ['//','/**','/*','*/','*']) near the top of
scripts/lint-app-space-id.mjs and replace the existing conditional that checks
trimmed.startsWith(...) with SKIP_PREFIXES.some(prefix =>
trimmed.startsWith(prefix)); update the if(...) that currently references
trimmed to use this .some(...) check so the skip rules are centralized and
easier to maintain.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@scripts/lint-app-space-id.mjs`:
- Around line 107-116: The global regex LITERAL_RE (used with /g) keeps state
between tests causing false negatives when checking entire file contents; before
calling LITERAL_RE.test(contents) in the file-level check inside the loop over
SCAN_ROOTS_FOR_LITERALS and walk, reset its state by setting
LITERAL_RE.lastIndex = 0 so each file is tested from the start (leave the
per-line resets in the inner loop intact).

---

Nitpick comments:
In `@scripts/lint-app-space-id.mjs`:
- Around line 118-124: Replace the chained startsWith calls with a declarative
prefix list: define a constant array (e.g., SKIP_PREFIXES =
['//','/**','/*','*/','*']) near the top of scripts/lint-app-space-id.mjs and
replace the existing conditional that checks trimmed.startsWith(...) with
SKIP_PREFIXES.some(prefix => trimmed.startsWith(prefix)); update the if(...)
that currently references trimmed to use this .some(...) check so the skip rules
are centralized and easier to maintain.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 46e68d89-c4c3-4cec-9f49-b5438fe3ed45

📥 Commits

Reviewing files that changed from the base of the PR and between 7adb376 and 3e85bcb.

⛔ Files ignored due to path filters (5)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • projects/extension-contract-spaces/plan.md is excluded by !projects/**
  • projects/extension-contract-spaces/spec.md is excluded by !projects/**
  • projects/extension-contract-spaces/specs/cipherstash-migration.spec.md is excluded by !projects/**
  • projects/extension-contract-spaces/specs/framework-mechanism.spec.md is excluded by !projects/**
📒 Files selected for processing (132)
  • examples/react-router-demo/test/react-router.smoke.e2e.test.ts
  • package.json
  • packages/1-framework/1-core/framework-components/src/control/control-instances.ts
  • packages/1-framework/1-core/framework-components/src/control/control-migration-types.ts
  • packages/1-framework/1-core/framework-components/src/control/control-spaces.ts
  • packages/1-framework/1-core/framework-components/src/exports/control.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-apply.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-new.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-show.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-status.ts
  • packages/1-framework/3-tooling/cli/src/control-api/client.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/db-init.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/db-update.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/migration-apply.ts
  • packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-show.test.ts
  • packages/1-framework/3-tooling/migration/package.json
  • packages/1-framework/3-tooling/migration/src/concatenate-space-apply-inputs.ts
  • packages/1-framework/3-tooling/migration/src/detect-space-contract-drift.ts
  • packages/1-framework/3-tooling/migration/src/emit-pinned-space-artefacts.ts
  • packages/1-framework/3-tooling/migration/src/errors.ts
  • packages/1-framework/3-tooling/migration/src/exports/io.ts
  • packages/1-framework/3-tooling/migration/src/exports/package.ts
  • packages/1-framework/3-tooling/migration/src/exports/spaces.ts
  • packages/1-framework/3-tooling/migration/src/hash.ts
  • packages/1-framework/3-tooling/migration/src/io.ts
  • packages/1-framework/3-tooling/migration/src/metadata.ts
  • packages/1-framework/3-tooling/migration/src/migration-graph.ts
  • packages/1-framework/3-tooling/migration/src/package.ts
  • packages/1-framework/3-tooling/migration/src/plan-all-spaces.ts
  • packages/1-framework/3-tooling/migration/src/read-pinned-contract-hash.ts
  • packages/1-framework/3-tooling/migration/src/space-layout.ts
  • packages/1-framework/3-tooling/migration/src/verify-contract-spaces.ts
  • packages/1-framework/3-tooling/migration/test/concatenate-space-apply-inputs.test.ts
  • packages/1-framework/3-tooling/migration/test/deletable-node-modules.test.ts
  • packages/1-framework/3-tooling/migration/test/detect-space-contract-drift.test.ts
  • packages/1-framework/3-tooling/migration/test/emit-pinned-space-artefacts.test.ts
  • packages/1-framework/3-tooling/migration/test/find-path-with-invariants.test.ts
  • packages/1-framework/3-tooling/migration/test/fixtures.ts
  • packages/1-framework/3-tooling/migration/test/io.test.ts
  • packages/1-framework/3-tooling/migration/test/materialise-migration-package.test.ts
  • packages/1-framework/3-tooling/migration/test/migration-graph.test.ts
  • packages/1-framework/3-tooling/migration/test/plan-all-spaces.test.ts
  • packages/1-framework/3-tooling/migration/test/read-pinned-contract-hash.test.ts
  • packages/1-framework/3-tooling/migration/test/space-layout.test.ts
  • packages/1-framework/3-tooling/migration/test/verify-contract-spaces.test.ts
  • packages/1-framework/3-tooling/migration/tsdown.config.ts
  • packages/2-mongo-family/9-family/src/core/control-instance.ts
  • packages/2-sql/5-runtime/src/exports/index.ts
  • packages/2-sql/5-runtime/src/sql-marker.ts
  • packages/2-sql/5-runtime/test/intercept-decoding.test.ts
  • packages/2-sql/5-runtime/test/marker-vs-intercept-ordering.test.ts
  • packages/2-sql/5-runtime/test/sql-family-adapter.test.ts
  • packages/2-sql/5-runtime/test/sql-marker.test.ts
  • packages/2-sql/5-runtime/test/sql-runtime.test.ts
  • packages/2-sql/5-runtime/test/utils.ts
  • packages/2-sql/9-family/src/core/control-adapter.ts
  • packages/2-sql/9-family/src/core/control-instance.ts
  • packages/2-sql/9-family/src/core/migrations/plan-helpers.ts
  • packages/2-sql/9-family/src/core/migrations/types.ts
  • packages/2-sql/9-family/test/migrations.types.test-d.ts
  • packages/2-sql/9-family/test/migrations.types.test.ts
  • packages/3-extensions/sql-orm-client/test/integration/runtime-helpers.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/planner-produced-postgres-migration.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/planner.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/runner.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/statement-builders.ts
  • packages/3-targets/3-targets/postgres/src/exports/statement-builders.ts
  • packages/3-targets/3-targets/postgres/test/migrations/statement-builders.test.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/planner-produced-sqlite-migration.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/planner.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/runner.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/statement-builders.ts
  • packages/3-targets/3-targets/sqlite/src/exports/statement-builders.ts
  • packages/3-targets/3-targets/sqlite/test/migrations/nullability-backfill.test.ts
  • packages/3-targets/3-targets/sqlite/test/migrations/planner.authoring-surface.test.ts
  • packages/3-targets/6-adapters/postgres/src/core/adapter.ts
  • packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/postgres/test/adapter.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/fixtures/runner-fixtures.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/op-factory-call.lowering.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.authoring-surface.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.behavior.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.case1.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.contract-to-schema-ir.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.fk-config.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.referential-actions.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.semantic-satisfaction.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.storage-types.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.storage-types.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/render-typescript.roundtrip.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.basic.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.errors.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.execution-checks.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.idempotency.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.policy.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/schema-verify.after-runner.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/src/core/adapter.ts
  • packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/fixtures/runner-fixtures.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner-introspection.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/render-typescript.roundtrip.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.basic.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.errors.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.idempotency.test.ts
  • scripts/lint-app-space-id.mjs
  • test/e2e/framework/test/sqlite/migrations/harness.ts
  • test/e2e/framework/test/sqlite/utils.ts
  • test/integration/test/cli-journeys/drift-marker.e2e.test.ts
  • test/integration/test/cli-journeys/greenfield-setup.e2e.test.ts
  • test/integration/test/cli-journeys/invariant-routing.e2e.test.ts
  • test/integration/test/cli-journeys/migration-apply-edge-cases.e2e.test.ts
  • test/integration/test/cli.db-init.e2e.errors.test.ts
  • test/integration/test/cli.db-init.e2e.test.ts
  • test/integration/test/cli.db-sign.e2e.test.ts
  • test/integration/test/cli.db-verify.e2e.test.ts
  • test/integration/test/cli.migration-apply.e2e.test.ts
  • test/integration/test/contract-space-fixture/README.md
  • test/integration/test/contract-space-fixture/constants.ts
  • test/integration/test/contract-space-fixture/contract.ts
  • test/integration/test/contract-space-fixture/control.ts
  • test/integration/test/contract-space-fixture/descriptor.test.ts
  • test/integration/test/contract-space-fixture/migrations.ts
  • test/integration/test/family.sign-database.test.ts
  • test/integration/test/family.verify-database.basic.test.ts
  • test/integration/test/family.verify-database.errors.test.ts
  • test/integration/test/referential-actions.integration.test.ts
✅ Files skipped from review due to trivial changes (35)
  • packages/3-extensions/sql-orm-client/test/integration/runtime-helpers.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/db-update.ts
  • package.json
  • packages/1-framework/3-tooling/migration/src/exports/io.ts
  • test/integration/test/contract-space-fixture/contract.ts
  • packages/1-framework/3-tooling/migration/tsdown.config.ts
  • test/integration/test/contract-space-fixture/README.md
  • packages/1-framework/3-tooling/migration/test/space-layout.test.ts
  • packages/1-framework/3-tooling/migration/package.json
  • packages/2-sql/5-runtime/test/marker-vs-intercept-ordering.test.ts
  • test/integration/test/contract-space-fixture/control.ts
  • packages/1-framework/1-core/framework-components/src/control/control-instances.ts
  • packages/1-framework/3-tooling/migration/test/detect-space-contract-drift.test.ts
  • packages/1-framework/3-tooling/migration/test/io.test.ts
  • test/integration/test/family.verify-database.errors.test.ts
  • packages/2-sql/5-runtime/src/exports/index.ts
  • test/integration/test/cli-journeys/migration-apply-edge-cases.e2e.test.ts
  • packages/2-sql/9-family/src/core/migrations/plan-helpers.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/render-typescript.roundtrip.test.ts
  • packages/1-framework/3-tooling/migration/src/emit-pinned-space-artefacts.ts
  • packages/1-framework/1-core/framework-components/src/control/control-spaces.ts
  • packages/2-sql/5-runtime/test/sql-runtime.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.storage-types.test.ts
  • packages/2-sql/5-runtime/test/sql-family-adapter.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.policy.integration.test.ts
  • packages/1-framework/3-tooling/migration/test/materialise-migration-package.test.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-apply.ts
  • test/integration/test/contract-space-fixture/constants.ts
  • packages/3-targets/6-adapters/postgres/test/adapter.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.execution-checks.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.behavior.test.ts
  • packages/1-framework/3-tooling/migration/test/migration-graph.test.ts
  • packages/1-framework/3-tooling/migration/test/find-path-with-invariants.test.ts
  • packages/1-framework/3-tooling/migration/test/verify-contract-spaces.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.semantic-satisfaction.test.ts
🚧 Files skipped from review as they are similar to previous changes (92)
  • packages/3-targets/3-targets/postgres/src/exports/statement-builders.ts
  • packages/3-targets/3-targets/sqlite/src/exports/statement-builders.ts
  • packages/2-sql/5-runtime/test/intercept-decoding.test.ts
  • test/e2e/framework/test/sqlite/migrations/harness.ts
  • test/integration/test/cli-journeys/greenfield-setup.e2e.test.ts
  • test/integration/test/referential-actions.integration.test.ts
  • packages/1-framework/3-tooling/migration/test/fixtures.ts
  • packages/3-targets/6-adapters/postgres/src/core/adapter.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/fixtures/runner-fixtures.ts
  • packages/1-framework/3-tooling/cli/src/control-api/client.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/schema-verify.after-runner.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/src/core/adapter.ts
  • packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.authoring-surface.test.ts
  • packages/1-framework/3-tooling/migration/src/hash.ts
  • packages/1-framework/3-tooling/migration/src/read-pinned-contract-hash.ts
  • test/integration/test/cli.db-verify.e2e.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner-introspection.integration.test.ts
  • packages/1-framework/3-tooling/migration/src/concatenate-space-apply-inputs.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner.test.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/migration-apply.ts
  • packages/1-framework/3-tooling/migration/src/exports/package.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.basic.integration.test.ts
  • packages/1-framework/1-core/framework-components/src/control/control-migration-types.ts
  • packages/2-mongo-family/9-family/src/core/control-instance.ts
  • packages/1-framework/3-tooling/migration/src/metadata.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/planner-produced-sqlite-migration.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.fk-config.test.ts
  • packages/3-targets/3-targets/sqlite/test/migrations/nullability-backfill.test.ts
  • packages/1-framework/1-core/framework-components/src/exports/control.ts
  • test/integration/test/cli.db-init.e2e.test.ts
  • examples/react-router-demo/test/react-router.smoke.e2e.test.ts
  • packages/1-framework/3-tooling/migration/src/plan-all-spaces.ts
  • test/integration/test/cli.db-init.e2e.errors.test.ts
  • packages/3-targets/3-targets/postgres/test/migrations/statement-builders.test.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-show.ts
  • test/integration/test/cli-journeys/drift-marker.e2e.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-show.test.ts
  • packages/1-framework/3-tooling/migration/test/plan-all-spaces.test.ts
  • packages/1-framework/3-tooling/migration/src/detect-space-contract-drift.ts
  • test/integration/test/cli.migration-apply.e2e.test.ts
  • test/integration/test/cli.db-sign.e2e.test.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-status.ts
  • packages/2-sql/9-family/test/migrations.types.test-d.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.idempotency.test.ts
  • packages/1-framework/3-tooling/migration/src/exports/spaces.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-new.ts
  • packages/2-sql/5-runtime/test/utils.ts
  • packages/1-framework/3-tooling/migration/src/migration-graph.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.storage-types.integration.test.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/planner.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts
  • packages/2-sql/9-family/src/core/control-adapter.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/db-init.ts
  • packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts
  • packages/2-sql/9-family/src/core/control-instance.ts
  • test/integration/test/family.verify-database.basic.test.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/runner.ts
  • test/integration/test/contract-space-fixture/descriptor.test.ts
  • test/integration/test/cli-journeys/invariant-routing.e2e.test.ts
  • packages/2-sql/9-family/src/core/migrations/types.ts
  • packages/2-sql/9-family/test/migrations.types.test.ts
  • packages/1-framework/3-tooling/migration/src/space-layout.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/runner.ts
  • test/integration/test/family.sign-database.test.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/statement-builders.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.contract-to-schema-ir.test.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/planner.ts
  • packages/1-framework/3-tooling/migration/test/read-pinned-contract-hash.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.case1.test.ts
  • packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/planner-produced-postgres-migration.ts
  • packages/1-framework/3-tooling/migration/test/deletable-node-modules.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.test.ts
  • packages/1-framework/3-tooling/migration/src/errors.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.idempotency.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.basic.test.ts
  • packages/1-framework/3-tooling/migration/src/package.ts
  • packages/1-framework/3-tooling/migration/test/concatenate-space-apply-inputs.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.integration.test.ts
  • packages/1-framework/3-tooling/migration/src/verify-contract-spaces.ts
  • packages/3-targets/3-targets/sqlite/test/migrations/planner.authoring-surface.test.ts
  • packages/2-sql/5-runtime/test/sql-marker.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.referential-actions.test.ts
  • packages/2-sql/5-runtime/src/sql-marker.ts
  • packages/3-targets/3-targets/sqlite/src/core/migrations/statement-builders.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.errors.integration.test.ts
  • packages/1-framework/3-tooling/migration/src/io.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.errors.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/op-factory-call.lowering.test.ts
  • packages/1-framework/3-tooling/migration/test/emit-pinned-space-artefacts.test.ts

@wmadden
wmadden merged commit a5fb511 into main May 9, 2026
15 checks passed
wmadden added a commit that referenced this pull request May 9, 2026
…, not name shape

listPinnedSpaceDirectories distinguished user-authored migration
directories from pinned per-space subdirectories with a regex on the
directory name (^\d{8}T\d{4}_), encoding the formatMigrationDirName
convention as if it were a contract. Directory names belong to users
and are informative, not structural.

Switch to the same discriminator readMigrationsDir already uses:
presence of migration.json at the directory root. A subdirectory is a
migration directory iff it contains the manifest; otherwise it is a
candidate pinned per-space subdirectory. ENOENT means "no manifest";
other stat errors propagate. Sorted, deterministic output is
preserved.

This frees users to name their migration directories however they
like and removes a brittleness flagged in PR #434 review.
wmadden added a commit that referenced this pull request May 9, 2026
…plans

Tighten SqlMigrationPlan, WriteMarkerInput, MergeMarkerInput, and the
ControlFamilyInstance/SqlControlAdapter readMarker signatures so the
contract space is required at every call site rather than silently
defaulting to APP_SPACE_ID. Thread spaceId through Postgres and SQLite
planners, planner-produced renderable migrations, and migration runners
so per-extension plans key their prisma_contract.marker rows by their
own space instead of collapsing onto the app row.

App-level CLI callsites (db init/update, migration plan/new/apply,
control-api client) explicitly pass APP_SPACE_ID. Mongo readMarker
accepts the parameter and rejects non-app spaces until per-space
support lands. Test fixtures and inline plan/marker constructions are
updated accordingly.

Closes the sql-marker.ts CR thread on PR #434 by removing the optional
space?: string fallback that masked missing spaceId plumbing.
wmadden added a commit that referenced this pull request May 9, 2026
Re-emitting the same package against an existing per-package
directory now clears the directory first and rewrites byte-identical
contents, so re-running migrate against an unchanged descriptor is a
no-op on disk and never leaves stale files behind. The lower-level
writeMigrationPackage stays strict so the CLI authoring path
(migration plan / migration new) still refuses to clobber an existing
authored migration.

Adds a same-dir overwrite-idempotency test that seeds a stale.json,
re-materialises, and asserts the directory contents converge on the
canonical three-file shape with byte-identical migration.json,
ops.json, and contract.json.

Closes the materialise-migration-package CR thread on PR #434.
@wmadden
wmadden deleted the tml-2397-contract-spaces-first-class-schema-contributions-from branch May 9, 2026 17:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant