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

examples/supabase: cross-contract FK with cascade, end-to-end (TML-2500 M3b) - #765

Merged
wmadden merged 12 commits into
mainfrom
tml-2500-m3b-walking-skeleton
Jun 8, 2026
Merged

wmadden merged 12 commits into
mainfrom
tml-2500-m3b-walking-skeleton

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

After this PR, an app contract can declare a foreign key from a local model to a model owned by an extension's contract — and the framework turns it into a real Postgres FK constraint with the standard referential actions. The grounding example, from examples/supabase/src/contract.prisma:

types {
  Uuid = String @db.Uuid
}

namespace public {
  model Profile {
    id       String @id @default(uuid())
    username String
    userId   Uuid   @unique
    user     supabase:auth.AuthUser @relation(fields: [userId], references: [id], onDelete: Cascade)
    @@map("profile")
  }
}

The new bit is Profile.user. supabase:auth.AuthUser reads broad-to-narrow: model AuthUser in namespace auth of contract space supabase. The supabase space comes from @prisma-next/extension-supabase; the app declares its dependency via extensionPacks in prisma-next.config.ts. The colon-prefix is the only new PSL grammar — the @relation attribute is unchanged from local FKs.

The DDL the planner emits at migration time:

ALTER TABLE "public"."profile"
  ADD CONSTRAINT "profile_userId_fkey"
  FOREIGN KEY ("userId")
  REFERENCES "auth"."users"("id")
  ON DELETE CASCADE;

That's the deliverable: cross-contract foreign keys are first-class, complete with cascade-delete semantics realized through the live database constraint.

How the PR is structured

The substrate that makes this possible — the IR carrier with spaceId, the PSL grammar, the brand handles, the planner, the verifier, the aggregate resolution — already shipped in earlier slices of this project. This PR is the first consumer that drives it through the example app's normal prisma-next contract emit flow and proves it works against a live database.

Three things land:

1. The walking-skeleton wire-up. examples/supabase/src/contract.prisma declares the cross-contract FK shown above. The standard CLI emit flow (pnpm --filter @prisma-next/example-supabase emit) regenerates the example's contract.json + contract.d.ts cleanly.

2. A hermetic cascade-delete integration test. A new it block in examples/supabase/test/skeleton.integration.test.ts seeds an auth.users row via raw SQL (cross-space — no ORM access by design, see Decision below), inserts a public.profile row through the ORM that references the seeded user, asserts the row is present, deletes the auth.users row, and asserts public.profile is empty. This proves both that the FK constraint really exists in pg_constraint and that ON DELETE CASCADE actually fires through it.

3. Two cleanups the walking-skeleton surfaced.

Typed spaceId on the contract surface. The TS contract surface (BuiltStorageTables<Definition>) didn't expose spaceId on cross-space FK targets, even though the runtime carrier already had it. Before this PR, consumers had to cast through as Record<string, unknown> to read the field. After, it's a typed read.

typeParams empty-state canonicalization. The walking-skeleton was the first runtime consumer to drive a Supabase-extension-style named type (Uuid = String @db.Uuid) through the app's runtime client — and tripped on a representation inconsistency. The PSL emitter wrote typeParams: {} for empty named types; the runtime validator rejected typeParams: {} against non-parameterized codecs; the IR mixed required and optional shapes. The fix makes empty typeParams canonical at every boundary: the on-disk JSON omits it (canonicalizer strips); the in-memory IR always carries typeParams: {} (construction normalizes); codecs receive a consistent empty form. Extension contracts (supabase, pgvector, postgis) are re-emitted via pnpm fixtures:emit, which automatically re-pins their migration baselines.

Decision: cross-space relations are declared but non-navigable

The cross-space relation is a real relationship in the contract — it drives the FK constraint and appears in introspection — but ORM traversal across spaces is a compile-time error. Writing db.public.Profile.find({ include: { user: true } }) does not type-check.

The reason: this is the canonical Supabase usage pattern. Apps reference auth.users for the cascade-delete guarantee; they don't query auth.users directly from the app. Cross-space querying would need a runtime contract-space aggregate that merges loaded spaces into the queryable surface, which doesn't exist today. The injection seam (when we eventually design it) is ExecutionContext, not a merged Db<C> type.

This is why the cascade test uses raw SQL for auth.users operations (no ORM surface to use) but the ORM for public.profile operations (the app's own model, where the ORM is the right tool).

Validation

  • pnpm typecheck: 138/138
  • pnpm lint: 79/79
  • pnpm lint:deps: clean
  • pnpm fixtures:check: clean
  • pnpm test:packages: 9934 passed (4 expected-fail, 3 skipped)
  • pnpm --filter @prisma-next/example-supabase test: 2/2 (M1 walking-skeleton + new cascade test)

Test plan

  • CI runs the full repo gate end-to-end.
  • Spot-check the cascade locally: pnpm --filter @prisma-next/example-supabase test.
  • Confirm the existing M1 walking-skeleton it still proves what it originally claimed (zero DDL for auth.*/storage.*; db verify passes; auth.users reachable via raw client) — the M1 it is deliberately FK-agnostic so the cascade it is the sole FK assertion.

Alternatives considered

Field-level @db.Uuid instead of a types {} block. Early dispatch attempts wrote userId String @db.Uuid @unique directly on the field. The PSL grammar only accepts @db.X inside types { Name = T @db.X } declarations — field-level use is rejected. The named-type pattern is the canonical idiom and is the same shape the supabase extension itself uses internally.

Auto-propagating the target's native type via the brand. First instinct was that M2's ColumnRef<TSpaceId> brand would auto-match the source column to the target's storage type. The brand carries spaceId for resolution, not storage type. PSL authors are responsible for native-type matching on cross-space FK source columns — same rule as for local FKs whose target isn't the PSL default type.

Three options for the typeParams empty-state fix. We considered:

  • Loosen only the runtime validator — treat {} and missing as equivalent at the JS comparison boundary, leave the on-disk redundancy alone. Smallest blast radius. Rejected: leaves the on-disk inconsistency (extension contracts ship typeParams: {} indefinitely) and only papers over the misalignment.
  • Strip typeParams: {} via the canonicalizer; normalize the in-memory form to {}. What landed. The canonicalizer already had this exact pattern for other empty-defaults; the deferred work was small. Migration baselines re-pin automatically via the existing pnpm migrations:regen script.
  • Introduce a real pg/uuid codec descriptor. The architecturally cleanest answer — stops @db.Uuid from masquerading as pg/text@1 with nativeType: 'uuid'. Rejected for this PR: it's a project's worth of work touching every consumer of @db.Uuid. Reasonable follow-up.

Required typeParams: Record<string, unknown> vs optional typeParams?. An early version of the substrate fix flipped StorageTypeInstance.typeParams to optional, mirroring the on-disk form directly. Reverted: the in-memory contract is "empty = {}", not "empty = undefined". Codecs read a canonical empty form consistently. The validator schema stays permissive on input (the on-disk form genuinely omits); construction normalizes.

Splitting M3b into two PRs. The substrate fix could have shipped as its own PR with the walking-skeleton waiting. We chose to bundle: the substrate fix has its narrative anchor — the walking-skeleton is what tripped on it. A standalone substrate-fix PR would have read as "fix a thing nobody noticed was broken." This PR is wider than originally planned but coherent: one decision (cross-contract FKs as first-class), one walking-skeleton proof, plus the substrate cleanup the proof required.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Profile now links to auth users via a unique userId with ON DELETE CASCADE.
  • Tests

    • Added integration tests validating cross-schema referential integrity and cascade delete.
  • Chores

    • Contract output now omits empty typeParams for cleaner serialization.
    • Updated extension contracts and migration metadata/hashes to match the new canonicalization.

@wmadden-electric
wmadden-electric requested a review from a team as a code owner June 8, 2026 08:57
@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@wmadden-electric, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 56 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: f035420b-7527-4286-8395-c8d4a2ec2463

📥 Commits

Reviewing files that changed from the base of the PR and between 5ca6d89 and 355f1ff.

⛔ Files ignored due to path filters (3)
  • projects/cross-contract-refs/slices/M3b/plan.md is excluded by !projects/**
  • projects/cross-contract-refs/slices/M3b/spec.md is excluded by !projects/**
  • projects/cross-contract-refs/trace.jsonl is excluded by !projects/**
📒 Files selected for processing (41)
  • examples/supabase/src/contract.d.ts
  • examples/supabase/src/contract.json
  • examples/supabase/src/contract.prisma
  • examples/supabase/src/handlers.ts
  • examples/supabase/test/skeleton.integration.test.ts
  • packages/1-framework/0-foundation/contract/test/canonicalization-path-match.test.ts
  • packages/1-framework/0-foundation/contract/test/canonicalization.test.ts
  • packages/1-framework/3-tooling/emitter/test/canonicalization.test.ts
  • packages/1-framework/3-tooling/emitter/test/utils.ts
  • packages/2-sql/1-core/contract/src/canonicalization-hooks.ts
  • packages/2-sql/1-core/contract/src/ir/sql-storage.ts
  • packages/2-sql/1-core/contract/src/ir/storage-type-instance.ts
  • packages/2-sql/1-core/contract/src/validators.ts
  • packages/2-sql/1-core/contract/test/sql-storage.test.ts
  • packages/2-sql/2-authoring/contract-ts/src/contract-types.ts
  • packages/2-sql/2-authoring/contract-ts/test/contract.parameterized-types.test.ts
  • packages/2-sql/2-authoring/contract-ts/test/cross-space-relation.test.ts
  • packages/2-sql/4-lanes/relational-core/src/codec-ref-for-column.ts
  • packages/2-sql/5-runtime/src/sql-context.ts
  • packages/2-sql/5-runtime/test/codec-integrity.test.ts
  • packages/3-extensions/pgvector/migrations/20260601T0000_install_vector_extension/end-contract.d.ts
  • packages/3-extensions/pgvector/migrations/20260601T0000_install_vector_extension/end-contract.json
  • packages/3-extensions/pgvector/migrations/20260601T0000_install_vector_extension/migration.json
  • packages/3-extensions/pgvector/migrations/20260601T0000_install_vector_extension/migration.ts
  • packages/3-extensions/pgvector/migrations/refs/head.json
  • packages/3-extensions/pgvector/src/contract.d.ts
  • packages/3-extensions/pgvector/src/contract.json
  • packages/3-extensions/postgis/migrations/20260601T0000_install_postgis_extension/end-contract.d.ts
  • packages/3-extensions/postgis/migrations/20260601T0000_install_postgis_extension/end-contract.json
  • packages/3-extensions/postgis/migrations/20260601T0000_install_postgis_extension/migration.json
  • packages/3-extensions/postgis/migrations/20260601T0000_install_postgis_extension/migration.ts
  • packages/3-extensions/postgis/migrations/refs/head.json
  • packages/3-extensions/postgis/src/contract.d.ts
  • packages/3-extensions/postgis/src/contract.json
  • packages/3-extensions/supabase/src/contract/contract.d.ts
  • packages/3-extensions/supabase/src/contract/contract.json
  • packages/3-extensions/supabase/test/contract-handles.test.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/planner-ddl-builders.ts
  • skills/extension-author/prisma-next-extension-upgrade/upgrades/0.12-to-0.13/instructions.md
  • skills/upgrade/prisma-next-upgrade/upgrades/0.12-to-0.13/instructions.md
  • test/integration/test/authoring/parity/core-surface/expected.contract.json
📝 Walkthrough

Walkthrough

Refactor to accept omitted/empty codec typeParams, strip empty typeParams during canonicalization, normalize missing typeParams to {} at runtime, add cross-space FK support in the Supabase example (Profile.userId → auth.users.id), update runtime integrity/registry, tests, generated contracts, migrations, and upgrade docs.

Changes

Optional typeParams throughout SQL contract system

Layer / File(s) Summary
Type instance optionality and normalization
packages/2-sql/1-core/contract/src/ir/storage-type-instance.ts, packages/2-sql/1-core/contract/src/validators.ts, packages/2-sql/1-core/contract/src/ir/sql-storage.ts, packages/2-sql/1-core/contract/test/sql-storage.test.ts
StorageTypeInstanceInput.typeParams becomes optional; toStorageTypeInstance normalizes missing to {}; validator and SqlStorage normalization updated and tested.
Canonicalization patterns and tests
packages/2-sql/1-core/contract/src/canonicalization-hooks.ts, packages/1-framework/3-tooling/emitter/test/utils.ts, packages/1-framework/3-tooling/emitter/test/canonicalization.test.ts, packages/1-framework/0-foundation/contract/test/canonicalization-path-match.test.ts, packages/1-framework/0-foundation/contract/test/canonicalization.test.ts
Removed storage.types.*.typeParams preserve-empty pattern; canonicalizer now strips empty typeParams; tests updated/added to cover stripping and preservation when non-empty.
Runtime codec parameterization integrity and registry
packages/2-sql/5-runtime/src/sql-context.ts, packages/2-sql/5-runtime/test/codec-integrity.test.ts
Integrity checks now consider whether typeParams has keys (treat {} as missing); codec registry omits typeParams when empty; iterations simplified to Object.entries; tests added to verify acceptance of empty-object cases.
Reference canonicalization & cross-space FK types
packages/2-sql/4-lanes/relational-core/src/codec-ref-for-column.ts, packages/2-sql/2-authoring/contract-ts/src/contract-types.ts, packages/2-sql/2-authoring/contract-ts/test/*, packages/3-targets/3-targets/postgres/src/core/migrations/planner-ddl-builders.ts
Column codec refs canonicalize empty typeParams to omission; FK target type gains optional spaceId; migration/type expansion treats missing/empty typeParams as non-expandable; tests adapted accordingly.
Integration examples and cross-schema FK validation
examples/supabase/src/contract.d.ts, examples/supabase/src/contract.json, examples/supabase/src/contract.prisma, examples/supabase/test/skeleton.integration.test.ts, examples/supabase/src/handlers.ts
Supabase example adds userId: Uuid with unique + FK to auth.users.id, Prisma Uuid alias added, handler insertAndReadProfile removed, and an integration test verifies ON DELETE CASCADE across schemas.
Generated contracts, migrations & upgrade docs
packages/3-extensions/pgvector/..., packages/3-extensions/postgis/..., packages/3-extensions/supabase/..., test/integration/..., skills/extension-author/..., skills/upgrade/...
Regenerated StorageHash values and migration hashes; removed empty typeParams from generated codec entries; added upgrade instructions documenting stripping of empty typeParams and the cross-space PSL pattern.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • prisma/prisma-next#745: Related—updates Supabase contract to add cross-schema FK (public.profile.userId → auth.users.id).
  • prisma/prisma-next#534: Related—work on cross-namespace FK modeling and lowering that this PR exercises.

Suggested reviewers

  • aqrln
  • SevInf

Poem

🐰 Hopping through contracts with cheer,

Empty typeParams disappear —
Canonicalized, normalized true,
Cross-schema links now follow through.
Tests and hashes all renewed!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding cross-contract foreign key support with cascading deletes in the Supabase example, with reference to the tracking ticket.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2500-m3b-walking-skeleton

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@pkg-pr-new

pkg-pr-new Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

npm i https://pkg.pr.new/@prisma-next/extension-author-tools@765

@prisma-next/mongo-runtime

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

@prisma-next/family-mongo

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

@prisma-next/sql-runtime

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

@prisma-next/family-sql

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

@prisma-next/extension-arktype-json

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

@prisma-next/middleware-cache

npm i https://pkg.pr.new/@prisma-next/middleware-cache@765

@prisma-next/mongo

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

@prisma-next/extension-paradedb

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

@prisma-next/extension-pgvector

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

@prisma-next/extension-postgis

npm i https://pkg.pr.new/@prisma-next/extension-postgis@765

@prisma-next/postgres

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

@prisma-next/sql-orm-client

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

@prisma-next/sqlite

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

@prisma-next/extension-supabase

npm i https://pkg.pr.new/@prisma-next/extension-supabase@765

@prisma-next/target-mongo

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

@prisma-next/adapter-mongo

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

@prisma-next/driver-mongo

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

@prisma-next/contract

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

@prisma-next/utils

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

@prisma-next/config

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

@prisma-next/errors

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

@prisma-next/framework-components

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

@prisma-next/operations

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

@prisma-next/ts-render

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

@prisma-next/contract-authoring

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

@prisma-next/ids

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

@prisma-next/psl-parser

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

@prisma-next/psl-printer

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

@prisma-next/cli

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

@prisma-next/cli-telemetry

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

@prisma-next/emitter

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

@prisma-next/migration-tools

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

prisma-next

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

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

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

@prisma-next/mongo-codec

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

@prisma-next/mongo-contract

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

@prisma-next/mongo-value

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

@prisma-next/mongo-contract-psl

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

@prisma-next/mongo-contract-ts

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

@prisma-next/mongo-emitter

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

@prisma-next/mongo-schema-ir

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

@prisma-next/mongo-query-ast

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

@prisma-next/mongo-orm

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

@prisma-next/mongo-query-builder

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

@prisma-next/mongo-lowering

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

@prisma-next/mongo-wire

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

@prisma-next/sql-contract

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

@prisma-next/sql-errors

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

@prisma-next/sql-operations

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

@prisma-next/sql-schema-ir

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

@prisma-next/sql-contract-psl

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

@prisma-next/sql-contract-ts

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

@prisma-next/sql-contract-emitter

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

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

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

@prisma-next/sql-relational-core

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

@prisma-next/sql-builder

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

@prisma-next/target-postgres

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

@prisma-next/target-sqlite

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

@prisma-next/adapter-postgres

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

@prisma-next/adapter-sqlite

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

@prisma-next/driver-postgres

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

@prisma-next/driver-sqlite

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

commit: 355f1ff

@github-actions

github-actions Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 149.32 KB (+0.05% 🔺)
postgres / emit 118.4 KB (+0.09% 🔺)
mongo / no-emit 76.67 KB (0%)
mongo / emit 70.96 KB (0%)
cf-worker / no-emit 179.38 KB (+0.05% 🔺)
cf-worker / emit 145.16 KB (+0.09% 🔺)

@wmadden-electric
wmadden-electric force-pushed the tml-2500-m3b-walking-skeleton branch from 5df1be8 to 75ce231 Compare June 8, 2026 09:01
const rows = await insertAndReadProfile(runtime, 'alice', userId);
expect(rows).toHaveLength(1);
expect(rows[0]).toMatchObject({ username: 'alice' });
expect(rows[0]).toMatchObject({ username: 'alice', userId });

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.

What does this prove exactly? If the FK were not present, this would work identically.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 3935665: the cascade test was refactored to use raw SQL against auth.users (the foreign source) and the ORM for public.Profile (the FK owner). The test now exercises the FK constraint directly — deleting an auth.users row causes the cascade to delete the referencing Profile row, which is what proves the FK is in place.

Comment on lines +329 to +332
const afterDelete = await pg.query<{ count: string }>(
'SELECT COUNT(*)::text AS count FROM public.profile WHERE "userId" = $1',
[userId],
);

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.

You should be using the ORM for this and all the preceding queries that operate on the public.Profile model

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 3935665: all public.Profile operations now use the ORM client. Raw SQL is only used for auth.users operations, which don't have a contract in this space.

Comment on lines +23 to +24
readonly nativeType: string;
readonly typeParams: Record<string, unknown>;
readonly typeParams?: Record<string, unknown>;

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.

Why did you make this optional? I thought the whole idea in our strategy was that this would always be present, and that the canonicalizer and serializer would ensure an empty value is represented consistently as {}?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 3935665: typeParams is optional on the input interface (StorageTypeInstanceInput) so callers that omit it at construction don't need to pass {}. The output type (StorageTypeInstance) still requires typeParams: Record<string, unknown> — always present. The toStorageTypeInstance helper normalises a missing value to {} at construction time. The canonicalizer and serializer continue to handle the canonical form; this change only relaxes what callers must supply when building inputs.

@wmadden-electric wmadden-electric changed the title TML-2500(M3b): cross-contract FK walking skeleton + cascade test + typeParams canonicalization examples/supabase: cross-contract FK with cascade, end-to-end (TML-2500 M3b) Jun 8, 2026
@wmadden-electric
wmadden-electric force-pushed the tml-2500-m3b-walking-skeleton branch 2 times, most recently from 346e668 to 1d0056a Compare June 8, 2026 10:45

@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: 2

🤖 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/2-sql/4-lanes/relational-core/src/codec-ref-for-column.ts`:
- Around line 65-74: The code currently treats any value with zero Object.keys
(including arrays like []) as "no typeParams" and drops them; change the
presence check so arrays are treated as present even if empty. Update the
hasParamKeys logic in codec-ref-for-column.ts (the instanceParams/hasParamKeys
check used when building the CodecRef) to: hasParamKeys = instanceParams !==
undefined && (Array.isArray(instanceParams) ||
Object.keys(instanceParams).length > 0) (or use an equivalent plain-object
check), and apply the same change to the second occurrence around lines 78-79 so
empty arrays are preserved as explicit typeParams while only canonicalizing
truly empty plain objects.

In `@packages/2-sql/5-runtime/src/sql-context.ts`:
- Around line 476-491: The code currently treats any non-array object and
missing typeParams as equivalent; change the logic so only a plain empty object
({}) or undefined/null are treated as "missing" and everything else (arrays,
primitives, objects with prototypes, or objects with keys) counts as an explicit
payload. Replace the refHasTypeParamKeys computation with an explicit
isEmptyPlainObject check (e.g. typeof refTypeParams === 'object' &&
!Array.isArray(refTypeParams) && Object.getPrototypeOf(refTypeParams) ===
Object.prototype && Object.keys(refTypeParams).length === 0) and then treat
missing if refTypeParams is undefined/null or isEmptyPlainObject; keep the
runtime check that throws RUNTIME.CODEC_PARAMETERIZATION_MISMATCH when
descriptor.isParameterized is false but the ref is not missing (i.e. has an
explicit payload). Ensure you update references to refTypeParams,
refHasTypeParamKeys and the if that uses descriptor.isParameterized accordingly.
🪄 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: 8b957f72-95d3-4412-bd40-1ecc36490263

📥 Commits

Reviewing files that changed from the base of the PR and between 3496511 and 1d0056a.

⛔ Files ignored due to path filters (3)
  • projects/cross-contract-refs/slices/M3b/plan.md is excluded by !projects/**
  • projects/cross-contract-refs/slices/M3b/spec.md is excluded by !projects/**
  • projects/cross-contract-refs/trace.jsonl is excluded by !projects/**
📒 Files selected for processing (39)
  • examples/supabase/src/contract.d.ts
  • examples/supabase/src/contract.json
  • examples/supabase/src/contract.prisma
  • examples/supabase/src/handlers.ts
  • examples/supabase/test/skeleton.integration.test.ts
  • packages/1-framework/0-foundation/contract/test/canonicalization-path-match.test.ts
  • packages/1-framework/0-foundation/contract/test/canonicalization.test.ts
  • packages/1-framework/3-tooling/emitter/test/canonicalization.test.ts
  • packages/1-framework/3-tooling/emitter/test/utils.ts
  • packages/2-sql/1-core/contract/src/canonicalization-hooks.ts
  • packages/2-sql/1-core/contract/src/ir/sql-storage.ts
  • packages/2-sql/1-core/contract/src/ir/storage-type-instance.ts
  • packages/2-sql/1-core/contract/src/validators.ts
  • packages/2-sql/1-core/contract/test/sql-storage.test.ts
  • packages/2-sql/2-authoring/contract-ts/src/contract-types.ts
  • packages/2-sql/2-authoring/contract-ts/test/contract.parameterized-types.test.ts
  • packages/2-sql/2-authoring/contract-ts/test/cross-space-relation.test.ts
  • packages/2-sql/4-lanes/relational-core/src/codec-ref-for-column.ts
  • packages/2-sql/5-runtime/src/sql-context.ts
  • packages/2-sql/5-runtime/test/codec-integrity.test.ts
  • packages/3-extensions/pgvector/migrations/20260601T0000_install_vector_extension/end-contract.d.ts
  • packages/3-extensions/pgvector/migrations/20260601T0000_install_vector_extension/end-contract.json
  • packages/3-extensions/pgvector/migrations/20260601T0000_install_vector_extension/migration.json
  • packages/3-extensions/pgvector/migrations/20260601T0000_install_vector_extension/migration.ts
  • packages/3-extensions/pgvector/migrations/refs/head.json
  • packages/3-extensions/pgvector/src/contract.d.ts
  • packages/3-extensions/pgvector/src/contract.json
  • packages/3-extensions/postgis/migrations/20260601T0000_install_postgis_extension/end-contract.d.ts
  • packages/3-extensions/postgis/migrations/20260601T0000_install_postgis_extension/end-contract.json
  • packages/3-extensions/postgis/migrations/20260601T0000_install_postgis_extension/migration.json
  • packages/3-extensions/postgis/migrations/20260601T0000_install_postgis_extension/migration.ts
  • packages/3-extensions/postgis/migrations/refs/head.json
  • packages/3-extensions/postgis/src/contract.d.ts
  • packages/3-extensions/postgis/src/contract.json
  • packages/3-extensions/supabase/src/contract/contract.d.ts
  • packages/3-extensions/supabase/src/contract/contract.json
  • packages/3-extensions/supabase/test/contract-handles.test.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/planner-ddl-builders.ts
  • test/integration/test/authoring/parity/core-surface/expected.contract.json
💤 Files with no reviewable changes (3)
  • packages/1-framework/3-tooling/emitter/test/utils.ts
  • packages/2-sql/1-core/contract/src/canonicalization-hooks.ts
  • examples/supabase/src/handlers.ts

@wmadden
wmadden force-pushed the tml-2500-m3b-walking-skeleton branch from f86adb6 to 5ca6d89 Compare June 8, 2026 11:21
@wmadden
wmadden enabled auto-merge (rebase) June 8, 2026 11:21
@wmadden-electric
wmadden-electric force-pushed the tml-2500-m3b-walking-skeleton branch from 5ca6d89 to a063265 Compare June 8, 2026 13:22
wmadden and others added 12 commits June 8, 2026 15:29
… record cast in cross-space-relation test

Add `readonly spaceId?: string` to the FK target object literal inside
BuiltStorageTables<Definition>, so cross-space relation FKs surface the
already-emitted runtime spaceId through the typed contract surface. The
field is optional — local FKs continue to type-check unchanged.

Drop the `as unknown as Record<string, unknown>` cast at
cross-space-relation.test.ts:300; the test now reads `fks[0]!.target.spaceId`
directly against the typed surface.

Signed-off-by: Will Madden <[email protected]>
…1 follow-up)

Mirrors the R1 drop at cross-space-relation.test.ts:300. The
BuiltStorageTables FK target now exposes the optional spaceId field
(added in cf2cd49), so the `as Record<string, unknown>` cast and its
stale "narrow type which omits spaceId" justification are obsolete. The
test now reads `fk.target.spaceId` against the typed surface.

Signed-off-by: Will Madden <[email protected]>
…the runtime boundary

PSL emits `typeParams: {}` for `@db.X` named types whose body carries
no parameters (e.g. `types { Uuid = String @db.Uuid }` in the supabase
extension). The runtime validator previously rejected any column whose
codec ref carried `typeParams !== undefined` against a non-parameterized
codec descriptor, so any contract using such an alias died at
`createExecutionContext` with `CODEC_PARAMETERIZATION_MISMATCH`.

Reconcile the two views around the design principle: at every runtime
comparison boundary, `typeParams: {}` and missing `typeParams` mean the
same thing — "no parameters were supplied". The on-disk JSON shape and
the IR types are unchanged; only the JS-side comparison behavior is
canonicalized.

Three runtime surfaces canonicalize empty typeParams:

- `codecRefForStorageColumn` (codec-ref-for-column.ts): a typeRef-shaped
  column whose alias carries empty typeParams now produces a `CodecRef`
  with no `typeParams` field. Same for inline-typeParams columns whose
  `typeParams` value happens to be `{}`. This keeps content-keyed
  memoisation honest (`{codecId}` and `{codecId, typeParams: {}}` resolve
  to the same cache key) and stops a stray `{}` from tripping the
  validator downstream.

- `assertColumnCodecIntegrity` (sql-context.ts): non-parameterized
  codecs only conflict with typeParams that carry at least one key. An
  empty object is treated as equivalent to absent.

- `buildContractCodecRegistry` typeRef walk (sql-context.ts): codec-ref
  construction for `storage.types[name]` entries matches the
  codec-ref-for-column canonicalization, so the pre-population walk uses
  the same cache key as the column walk.

New focused unit tests cover both forms (inline column + typeRef-shaped
column) against a non-parameterized codec descriptor. Both tests fail
against the pre-change code and pass after.

Signed-off-by: Will Madden <[email protected]>
…validator)

R1 (7c76339) shipped runtime-side equivalence between empty and missing `typeParams` at every comparison boundary. R2 finishes the job at the on-disk boundary by dropping the SQL-side preserve-empty entry for `storage.types.*.typeParams` and re-emitting the affected extension contracts + migration baselines.

Three coordinated changes:

- `packages/2-sql/1-core/contract/src/canonicalization-hooks.ts`: remove the `[storage, types, *, typeParams]` preserve-empty path so `omitDefaults` strips `typeParams: {}` the same way it strips every other empty default. The Mongo-family hook file already had no equivalent entry.

- `packages/2-sql/1-core/contract/src/validators.ts` + `ir/storage-type-instance.ts`: make `typeParams` optional on the codec-instance schema and IR shape. The on-disk canonical form now omits `typeParams: {}`, so the validator must accept the absent form; the runtime already treats absent and `{}` as equivalent (R1).

Mechanical regeneration (via `pnpm fixtures:emit`):

- supabase/pgvector/postgis `src/contract.{json,d.ts}` re-emitted without the empty `typeParams` field, producing new storageHashes.

- pgvector/postgis migration baselines re-pinned via `pnpm migrations:regen` (head.json + migration.{ts,json} + ops.json + end-contract.{json,d.ts}). supabase has no on-disk migrations tree.

- `test/integration/test/authoring/parity/core-surface/expected.contract.json` regenerated through the parity fixtures pipeline.

Tests:

- New focused case in emitter `canonicalization.test.ts` asserting `{codecId, nativeType, typeParams: {}}` canonicalizes to `{codecId, nativeType}` under SQL hooks.

- Updated `canonicalization.test.ts` in the foundation package: empty `typeParams` is now stripped even with the SQL hook; new case covers non-empty `typeParams` preservation.

- Updated `canonicalization-path-match.test.ts` to assert the inverted predicate behavior.

- Renamed the previously-passing "rejects type instance missing typeParams" case in `contract.parameterized-types.test.ts` to "accepts type instance with omitted typeParams" — missing is now the canonical form for empty.

Validation: typecheck 138/138 clean; lint + lint:deps clean; all affected packages green (sql-contract 157/157, sql-contract-ts 326/326, sql-runtime 269/269, contract 169/169, emitter 166/166, sql-contract-psl 227/227, supabase 19/19, pgvector 140/140, postgis 87/87).
Signed-off-by: Will Madden <[email protected]>
…eParams optional flip

R2 flipped `StorageTypeInstance.typeParams` from required to optional on
the IR but missed downstream construction sites. Under
`exactOptionalPropertyTypes: true` an explicit `typeParams: x` where `x`
is `T | undefined` is not assignable to a target with `typeParams?: T`.

Fixes:
- planner-strategies.ts: read site uses optional chaining (`?.[`).
- 4 construction sites (postgres planner-type-resolution,
  postgres planner-ddl-builders, sqlite planner-ddl-builders,
  family-sql contract-to-schema-ir, family-sql verify-sql-schema):
  use `...ifDefined('typeParams', x)` to omit the property when
  the source is undefined.

The sqlite `planner-ddl-builders.ts:146` site is the same mechanical
pattern as the postgres/family-sql ones; it surfaced when the
family-sql cascade unblocked downstream package typechecks.

Full repo `pnpm typecheck`: 138/138 PASS.

Signed-off-by: Will Madden <[email protected]>
… handler + M1 test for the new NOT NULL userId

Signed-off-by: Will Madden <[email protected]>
Project workspace artifacts for slice M3b — cross-contract FK walking
skeleton + cascade-delete test + BuiltStorageTables.spaceId type-surface
cleanup + the typeParams empty-state equivalence substrate fix that
surfaced during execution.

projects/cross-contract-refs/slices/M3b/spec.md      — slice spec
projects/cross-contract-refs/slices/M3b/plan.md      — dispatch plan
projects/cross-contract-refs/trace.jsonl             — emit-as-you-go trace

reviews/code-review.md and learnings.md are intentionally gitignored
(transient working state per projects/.gitignore).

Signed-off-by: Will Madden <[email protected]>
… cascade test ORM)

F3: Make StorageTypeInstance.typeParams required in the in-memory IR. Revert
six ifDefined wrapper sites added in M3b.2 where the source is a
StorageTypeInstance. The SqlStorage constructor normalises on-disk objects
that omit typeParams (canonical compact form) to typeParams: {} via
normaliseTypeEntry, using a runtime 'in' check so it only allocates a new
object when the property is genuinely absent. StorageTypeInstanceInput keeps
typeParams optional; the arktype validator also keeps it optional for on-disk
compatibility. Added a test for the normalisation behaviour.

F4: Remove the userId seed and insertAndReadProfile round-trip from the M1 it
block — those steps don't prove the FK exists. Delete handlers.ts (dead code).
The M1 it retains only its original three claims: zero DDL for auth/storage,
db verify passes, raw auth.users read.

F5: Refactor the cascade it so that public.profile operations go through the
ORM runtime (db.connect + runtime.execute) and auth.users operations remain
raw SQL via withClient. Both clients are open simultaneously; the try/finally
block calls db.close() to clean up the ORM runtime.

Signed-off-by: Will Madden <[email protected]>

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
`SqlNamespace.entries.table` is already typed as
`Readonly<Record<string, StorageTable>>`, which is exactly what the
local `SqlNamespaceTables` alias expanded to. The five cast sites and
the alias itself were all no-ops; removing them drops the bare-cast
ratchet count by 4 (from 1274 to 1269 vs merge-base).

This unblocks the Lint CI check.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…+ extension regen

- examples/supabase: add cross-space-fk-psl-pattern entry documenting
  the types { Uuid } + supabase:auth.AuthUser @relation PSL authoring
  pattern (new opt-in feature; no action for existing consumers).
- packages/3-extensions/: add regen-extension-contracts-strip-empty-type-params
  entry covering the typeParams: {} canonicalization — extension authors
  with named-type aliases must re-emit + re-pin migration baselines.

Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@wmadden-electric
wmadden-electric force-pushed the tml-2500-m3b-walking-skeleton branch from a063265 to 355f1ff Compare June 8, 2026 13:31
@wmadden
wmadden merged commit c99fae0 into main Jun 8, 2026
28 of 29 checks passed
@wmadden
wmadden deleted the tml-2500-m3b-walking-skeleton branch June 8, 2026 13:50
wmadden-electric added a commit that referenced this pull request Jun 8, 2026
…orkspace (TML-2500 M4) (#770)

This is the documentation + close-out milestone (M4) for the
cross-contract-refs project. All four implementation milestones have
merged — M1 #745, M2 #752, M3a #756, M3b #765 — shipping
cross-contract-space foreign-key references end-to-end. This PR migrates
the project's durable knowledge into the canonical doc surfaces, records
the project as shipped in the umbrella tracker, lands the final-retro
lessons, and deletes the transient project workspace.

## What shipped (recap, for the reader without context)

An app contract can now declare a foreign key from a local model to a
model owned by an *extension's* contract space. The headline example,
live in `examples/supabase`:

```prisma
types {
  Uuid = String @db.Uuid
}

namespace public {
  model Profile {
    id     String @id @default(uuid())
    userId Uuid   @unique
    user   supabase:auth.AuthUser @relation(fields: [userId], references: [id], onDelete: Cascade)
    @@Map("profile")
  }
}
```

The planner lowers this to a real Postgres FK (`REFERENCES
"auth"."users"("id") ON DELETE CASCADE`), and a hermetic integration
test proves the cascade fires against a live database.

## Where the knowledge landed (M4.1)

The design knowledge that lived in the transient
`projects/cross-contract-refs/` workspace migrated to three canonical,
self-contained surfaces:

- **Subsystem doc** — a new "Cross-contract FK references" subsection in
`docs/architecture docs/subsystems/6. Ecosystem Extensions & Packs.md`
(the extension hub). Records the *current shape*: the presence-based
optional `spaceId` discriminator on `ForeignKeyReference`,
dependency-graph construction, namespace-ownership rules, the
aggregate-loader resolution rule, and the `__unbound__`
DDL-qualification consequence.
- **ADR 226** — `docs/architecture docs/adrs/ADR 226 - Cross-contract
foreign-key references.md`. Records the *decisions*: presence-based
discrimination (chosen so local-FK JSON stays byte-identical), implicit
`extensionPacks` resolution, the DAG + reverse-reference rejection,
namespace ownership, Option-B non-navigable relations, the colon-prefix
PSL grammar, and no-diagnostic cascade. Cross-links ADR 212 / 221 / 225.
- **Authoring rulecard** —
`.agents/rules/cross-contract-fk-authoring.mdc`. The actionable Do/Don't
for authoring a cross-contract FK, including the hard-won M3b lesson
that the FK source column must match the target's native type (`types {
Uuid = String @db.Uuid }`), and that `@db.X` is type-constructor syntax
(only valid inside a `types {}` block), not a field attribute.

## Bookkeeping (M4.2)

- The umbrella tracker (`projects/supabase-integration/README.md`)
status row flipped to ✅ **Done & closed** with the four PR links, and
its link repointed from the (now-deleted) project spec to the durable
subsystem doc.
- The one durable dangling link —
`packages/3-extensions/supabase/README.md` pointing into the project dir
— repointed to ADR 226 / the subsystem doc.

## Final retro (M4.3)

Per the mandatory-final-retro invariant, the process lessons from this
project's execution landed in durable `drive/` calibration surfaces:

- `drive/spec/README.md` — spec illustrative snippets (PSL grammar, IR
shapes) must be re-verified against shipped code before execution, not
copied as fact. (This project hit it four times.)
- `drive/calibration/model-tier.md` — a worked example confirming the
existing "pin the dispatch tier explicitly, don't inherit" rule.
- `drive/calibration/dod.md` — test-dispatch briefs need a "claims
preserved" acceptance criterion: state what the test proves, on the
right surface.

## Definition of Done — verified

| AC | Status | Evidence |
|----|--------|----------|
| AC1 (TS cross-contract ref, non-navigable) | ✅ | M2 #752 |
| AC2 (PSL cross-contract ref, round-trip) | ✅ | M2 #752 + M3a #756 |
| AC3 (`__unbound__` unqualified REFERENCES) | ✅ | M3a #756 |
| AC4 (cascade permitted, DDL has ON DELETE CASCADE) | ✅ | M2 #752 + M3b
#765 |
| AC5 (missing-pack diagnostic, both surfaces) | ✅ | M2 #752 |
| AC6 (primitive collision + cycle rejection) | ✅ | M1 #745 |
| AC7 (live FK in `pg_constraint`, verifier clean) | ✅ | M3a #756 + M3b
#765 |
| AC8 (round-trip property test) | ✅ | M1 #745 |
| AC9 (TML-2459 local FK tests unchanged) | ✅ | all milestones |
| AC10 (`pnpm lint:deps` clean) | ✅ | all milestones |

All slices merged; mandatory final retro complete; durable docs landed;
no open ADRs blocking.

## Deletion

`projects/cross-contract-refs/` is removed. Verified before deletion:
trace integrity passes (89 events, 9 dispatches, all round/dispatch
pairs matched); no durable file (`packages/`, `examples/`, `docs/`,
`.agents/`) references the deleted path; `pnpm build` + `pnpm typecheck`
unaffected (nothing imports from `projects/`). References to
cross-contract-refs that remain in *other* project workspaces
(`supabase-integration`, `postgres-rls`, etc.) are
transient-to-transient and get cleaned at those projects' own
close-outs.

## Validation

- `pnpm typecheck`: 138/138
- `pnpm lint`: 79/79
- `pnpm lint:rules:symlinks`: clean (the new rulecard wired)
- `pnpm build`: clean

Refs: TML-2500.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Documentation**
* Added comprehensive guidance for cross-contract foreign-key
references, including authoring conventions and architectural design
decisions.
* Updated ecosystem extensions documentation with cross-contract
reference patterns and resolution behavior.
* Enhanced calibration and code verification documentation with improved
guidance for test authoring and snippet validation.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Will Madden <[email protected]>
Co-authored-by: Will Madden <[email protected]>
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
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.

2 participants