create-ailk 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/README.md +64 -7
  2. package/dist/add-module.js +7 -2
  3. package/dist/cli.js +35 -0
  4. package/dist/copy.d.ts +41 -0
  5. package/dist/copy.js +87 -21
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/lib/fetch-template-snapshot.d.ts +21 -0
  9. package/dist/lib/fetch-template-snapshot.js +205 -0
  10. package/dist/lib/merge-three-way.d.ts +31 -0
  11. package/dist/lib/merge-three-way.js +65 -0
  12. package/dist/lib/scaffold-render-sweep.d.ts +23 -0
  13. package/dist/lib/scaffold-render-sweep.js +52 -0
  14. package/dist/module-architecture.js +64 -5
  15. package/dist/programmatic.d.ts +7 -1
  16. package/dist/programmatic.js +40 -3
  17. package/dist/site-roster.js +21 -4
  18. package/dist/spoke-checkout.d.ts +7 -0
  19. package/dist/spoke-checkout.js +8 -1
  20. package/dist/surfaces.d.ts +14 -0
  21. package/dist/surfaces.js +98 -3
  22. package/dist/template-record.d.ts +59 -0
  23. package/dist/template-record.js +183 -0
  24. package/dist/topology.js +29 -1
  25. package/dist/update.d.ts +48 -0
  26. package/dist/update.js +504 -0
  27. package/package.json +3 -3
  28. package/templates/.claude/cloudparity-repo-hooks.json +9 -0
  29. package/templates/.claude/hooks/architecture-check.sh +8 -0
  30. package/templates/.claude/rules/loop-contract.md +129 -0
  31. package/templates/.claude/settings.json +3 -2
  32. package/templates/.env.example +13 -0
  33. package/templates/CLAUDE.md +1 -1
  34. package/templates/CONVENTIONS.md +3 -2
  35. package/templates/_gitignore +162 -0
  36. package/templates/apps/api/.env.example +17 -1
  37. package/templates/apps/api/CLAUDE.md +18 -8
  38. package/templates/apps/api/package.json +2 -1
  39. package/templates/apps/api/src/__tests__/factories/in-memory-prisma.ts +41 -2
  40. package/templates/apps/api/src/__tests__/setup.ts +7 -0
  41. package/templates/apps/api/src/__tests__/stripe-boot.test.ts +132 -0
  42. package/templates/apps/api/src/bin/__tests__/rate-limit-probe.test.ts +184 -0
  43. package/templates/apps/api/src/bin/rate-limit-probe.ts +53 -0
  44. package/templates/apps/api/src/lib/__mocks__/prisma.ts +8 -0
  45. package/templates/apps/api/src/lib/__tests__/consent-ledger-double.ts +237 -0
  46. package/templates/apps/api/src/lib/__tests__/consent-store.test.ts +334 -0
  47. package/templates/apps/api/src/lib/__tests__/stripe-admission.test.ts +217 -0
  48. package/templates/apps/api/src/lib/__tests__/stripe.test.ts +7 -0
  49. package/templates/apps/api/src/lib/consent-store.ts +335 -0
  50. package/templates/apps/api/src/lib/proposal-paid-store.ts +49 -0
  51. package/templates/apps/api/src/lib/rate-limit-probe.ts +165 -0
  52. package/templates/apps/api/src/lib/rate-limit-store.ts +142 -0
  53. package/templates/apps/api/src/lib/stripe.ts +97 -5
  54. package/templates/apps/api/src/middleware/__tests__/auth.hub-session-path.test.ts +13 -4
  55. package/templates/apps/api/src/middleware/__tests__/default-tenant.test.ts +2 -0
  56. package/templates/apps/api/src/middleware/__tests__/rate-limit-cross-isolate.db.test.ts +220 -0
  57. package/templates/apps/api/src/middleware/__tests__/rate-limit-store.test.ts +430 -0
  58. package/templates/apps/api/src/middleware/__tests__/rate-limit.test.ts +72 -14
  59. package/templates/apps/api/src/middleware/auth.ts +16 -4
  60. package/templates/apps/api/src/middleware/default-tenant.ts +9 -0
  61. package/templates/apps/api/src/middleware/rate-limit.ts +295 -82
  62. package/templates/apps/api/src/routes/checkout/__tests__/live-key.test.ts +167 -0
  63. package/templates/apps/api/src/routes/checkout/session.ts +3 -3
  64. package/templates/apps/api/src/routes/checkout/sessions.ts +6 -4
  65. package/templates/apps/api/src/routes/consent/cookie.ts +90 -0
  66. package/templates/apps/api/src/routes/consent/index.ts +18 -0
  67. package/templates/apps/api/src/routes/consent/unsubscribe.ts +127 -0
  68. package/templates/apps/api/src/routes/leads/index.ts +15 -0
  69. package/templates/apps/api/src/routes/project-listings/__tests__/drafts.test.ts +5 -0
  70. package/templates/apps/api/src/routes/webhooks/README.md +33 -5
  71. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-flow-checkout.test.ts +17 -4
  72. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-idempotency.test.ts +2 -0
  73. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-livemode-live.test.ts +159 -0
  74. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-livemode.test.ts +158 -0
  75. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-proposal-paid.test.ts +369 -0
  76. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-rate-limit.test.ts +2 -0
  77. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-site-filter.test.ts +442 -0
  78. package/templates/apps/api/src/routes/webhooks/stripe.ts +201 -6
  79. package/templates/apps/api/src/server.ts +125 -18
  80. package/templates/apps/api/src/services/__tests__/audit-log.test.ts +91 -0
  81. package/templates/apps/api/src/services/__tests__/consent-ledger.test.ts +503 -0
  82. package/templates/apps/api/src/services/__tests__/consent.test.ts +18 -3
  83. package/templates/apps/api/src/services/__tests__/lead-routing.test.ts +115 -4
  84. package/templates/apps/api/src/services/__tests__/person.test.ts +392 -0
  85. package/templates/apps/api/src/services/__tests__/request-confirm.test.ts +87 -0
  86. package/templates/apps/api/src/services/__tests__/revalidation.test.ts +57 -17
  87. package/templates/apps/api/src/services/audit-log.ts +72 -10
  88. package/templates/apps/api/src/services/consent.ts +488 -3
  89. package/templates/apps/api/src/services/default-tenant.ts +12 -3
  90. package/templates/apps/api/src/services/hub-sign-in.ts +2 -1
  91. package/templates/apps/api/src/services/lead-routing.ts +105 -12
  92. package/templates/apps/api/src/services/person.ts +501 -1
  93. package/templates/apps/api/src/services/project-listings.ts +7 -2
  94. package/templates/apps/api/src/services/public-site-resolver.ts +21 -2
  95. package/templates/apps/api/src/services/request-confirm.ts +52 -0
  96. package/templates/apps/api/src/services/revalidation.ts +11 -1
  97. package/templates/apps/api/vercel.json +1 -1
  98. package/templates/apps/mcp/CLAUDE.md +19 -7
  99. package/templates/apps/mcp/__tests__/catalog-drift.test.ts +95 -8
  100. package/templates/apps/mcp/src/tools/person_notes.ts +25 -0
  101. package/templates/apps/mcp/src/tools/proposals.ts +27 -0
  102. package/templates/apps/mcp/src/workspace-server.ts +16 -0
  103. package/templates/apps/web/_gitignore +6 -0
  104. package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/sign-up-card.test.tsx +165 -0
  105. package/templates/apps/web/app/[locale]/(auth)/sign-up/page.tsx +19 -0
  106. package/templates/apps/web/app/[locale]/(auth)/sign-up/sign-up-card.tsx +106 -23
  107. package/templates/apps/web/app/[locale]/(auth)/sign-up/sign-up.actions.ts +125 -0
  108. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/account-frame-sign-out.test.tsx +175 -0
  109. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/agreements-prompt.test.tsx +281 -0
  110. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +17 -3
  111. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +154 -53
  112. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +116 -27
  113. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +57 -2
  114. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +146 -0
  115. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +124 -18
  116. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +116 -18
  117. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/onboarding.test.tsx +323 -0
  118. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +365 -0
  119. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +290 -20
  120. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/settings.test.tsx +56 -0
  121. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +74 -4
  122. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +8 -0
  123. package/templates/apps/web/app/[locale]/(authed)/account/agreements-actions.ts +170 -0
  124. package/templates/apps/web/app/[locale]/(authed)/account/agreements-prompt.tsx +181 -0
  125. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +88 -3
  126. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/pay-form.tsx +65 -0
  127. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/review-form.tsx +27 -0
  128. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +176 -3
  129. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/pay.test.tsx +193 -0
  130. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/review.test.tsx +188 -0
  131. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-actions.ts +65 -4
  132. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +17 -0
  133. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +15 -9
  134. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +3 -3
  135. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +81 -0
  136. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +70 -27
  137. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +26 -3
  138. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +65 -19
  139. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/actions.ts +120 -0
  140. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/onboarding-form.tsx +322 -0
  141. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +126 -0
  142. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +43 -1
  143. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +65 -0
  144. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +226 -0
  145. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +89 -37
  146. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +102 -0
  147. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +62 -0
  148. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +44 -34
  149. package/templates/apps/web/app/[locale]/(authed)/account/sign-in-method.ts +1 -1
  150. package/templates/apps/web/app/[locale]/consent-banner.tsx +32 -0
  151. package/templates/apps/web/app/[locale]/consent.actions.ts +71 -0
  152. package/templates/apps/web/app/[locale]/contact/contact.actions.ts +13 -1
  153. package/templates/apps/web/app/[locale]/flows/[slug]/flow.actions.ts +25 -3
  154. package/templates/apps/web/app/[locale]/layout.tsx +23 -2
  155. package/templates/apps/web/app/[locale]/newsletter/newsletter.actions.ts +12 -1
  156. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe-rsc-boundary.test.tsx +209 -0
  157. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe.test.tsx +158 -0
  158. package/templates/apps/web/app/[locale]/unsubscribe/page.tsx +54 -0
  159. package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe-button.tsx +73 -0
  160. package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe.actions.ts +55 -0
  161. package/templates/apps/web/app/robots.txt/route.ts +13 -10
  162. package/templates/apps/web/auth.ts +20 -1
  163. package/templates/apps/web/jest.config.cjs +3 -0
  164. package/templates/apps/web/lib/__tests__/auth-email.test.ts +84 -0
  165. package/templates/apps/web/lib/__tests__/consent-visitor.test.ts +163 -0
  166. package/templates/apps/web/lib/__tests__/relay.test.ts +49 -0
  167. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +96 -7
  168. package/templates/apps/web/lib/account-config.ts +31 -16
  169. package/templates/apps/web/lib/auth-email.ts +45 -10
  170. package/templates/apps/web/lib/consent-visitor.ts +103 -0
  171. package/templates/apps/web/lib/relay.ts +20 -0
  172. package/templates/apps/web/lib/topology.generated.ts +9 -0
  173. package/templates/apps/web/messages/en.json +121 -18
  174. package/templates/apps/web/next.config.mjs +8 -2
  175. package/templates/database/CHANGELOG.md +55 -0
  176. package/templates/database/__tests__/consent-ledger.db.test.ts +345 -0
  177. package/templates/database/__tests__/fence-fan-out.db.test.ts +6 -2
  178. package/templates/database/__tests__/fixtures/person-contact-backfill.json +182 -0
  179. package/templates/database/__tests__/outbound-message-action.db.test.ts +80 -0
  180. package/templates/database/__tests__/person-contact.db.test.ts +563 -0
  181. package/templates/database/__tests__/person-notes.db.test.ts +249 -0
  182. package/templates/database/__tests__/person.db.test.ts +3 -1
  183. package/templates/database/__tests__/piece-kind-migration.test.ts +67 -0
  184. package/templates/database/__tests__/piece-kind.db.test.ts +208 -0
  185. package/templates/database/_gitignore +8 -0
  186. package/templates/database/inbox/schema.prisma +114 -22
  187. package/templates/database/migrations/20261014120000_consent_ledger/migration.sql +122 -0
  188. package/templates/database/migrations/20261014120000_person_contact/migration.sql +231 -0
  189. package/templates/database/migrations/20261015120000_person_notes/migration.sql +77 -0
  190. package/templates/database/migrations/20261015120000_rate_limit_counters/migration.sql +43 -0
  191. package/templates/database/migrations/20261016120000_piece_kind/migration.sql +95 -0
  192. package/templates/database/migrations/20261017120000_outbound_message_action/migration.sql +30 -0
  193. package/templates/database/ops/schema.prisma +16 -0
  194. package/templates/database/package.json +1 -1
  195. package/templates/project.yaml +6 -3
  196. package/versions.json +35 -35
  197. package/templates/.claude/rules/preserve-existing-style.md +0 -51
@@ -0,0 +1,43 @@
1
+ -- #5040 — the rate limiter's shared database store (spec
2
+ -- docs/specs/5040-the-api-s-rate-limiter-spec.md D2/D3). One row per bucket
3
+ -- key hash; the middleware's database store (`apps/api/src/lib/rate-limit-store.ts`)
4
+ -- is the only reader or writer. Belongs to the deployment, not a tenant: no
5
+ -- workspace_id, no tenancy fence. Rows are disposable — a lost counter only
6
+ -- resets a window.
7
+ --
8
+ -- Rollback (safe while no code selects the database store, i.e. deploy this
9
+ -- migration before the code that reads AILK_RATE_LIMIT_STORE=database or
10
+ -- defaults to it with DATABASE_URL set):
11
+ -- DROP TABLE "rate_limit_counters";
12
+
13
+ -- CreateTable
14
+ CREATE TABLE "rate_limit_counters" (
15
+ "id" TEXT NOT NULL DEFAULT ('rlc_'::text || (uuidv7())::text),
16
+ "key_hash" TEXT NOT NULL,
17
+ "window_start_ms" BIGINT NOT NULL,
18
+ "window_ms" INTEGER NOT NULL,
19
+ "count" INTEGER NOT NULL,
20
+ "created_at" TIMESTAMPTZ NOT NULL DEFAULT now(),
21
+
22
+ CONSTRAINT "rate_limit_counters_pkey" PRIMARY KEY ("id")
23
+ );
24
+
25
+ -- CreateIndex
26
+ CREATE UNIQUE INDEX "rate_limit_counters_key_hash_key" ON "rate_limit_counters"("key_hash");
27
+
28
+ -- CreateIndex
29
+ -- The sweep: DELETE WHERE window_start_ms + window_ms <= now.
30
+ CREATE INDEX "rate_limit_counters_window_start_ms_idx" ON "rate_limit_counters"("window_start_ms");
31
+
32
+ -- ADR-0031 rule 3 — rate_limit_counters: rlc_ (registered in
33
+ -- packages/ids/src/registry.ts; this migration's path is added to
34
+ -- migration-sync.test.ts's PK_CHECK_MIGRATIONS).
35
+ ALTER TABLE "rate_limit_counters" ALTER COLUMN "id" SET DEFAULT ('rlc_'::text || (uuidv7())::text);
36
+ ALTER TABLE "rate_limit_counters" ADD CONSTRAINT "rate_limit_counters_id_format" CHECK ("id" ~ '^rlc_[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$');
37
+
38
+ -- D2 — key_hash is always a sha256 hex digest, never the raw bucket key.
39
+ ALTER TABLE "rate_limit_counters" ADD CONSTRAINT "rate_limit_counters_key_hash_hex" CHECK ("key_hash" ~ '^[0-9a-f]{64}$');
40
+
41
+ -- D2 — window_ms > 0, count >= 1.
42
+ ALTER TABLE "rate_limit_counters" ADD CONSTRAINT "rate_limit_counters_window_ms_positive" CHECK ("window_ms" > 0);
43
+ ALTER TABLE "rate_limit_counters" ADD CONSTRAINT "rate_limit_counters_count_positive" CHECK ("count" >= 1);
@@ -0,0 +1,95 @@
1
+ -- #8516 — proposals as an artifact kind (spec
2
+ -- docs/specs/8516-proposals-as-an-artifact-kind-spec.md D1, D2).
3
+ --
4
+ -- pieces (8 columns) — what a piece is (`kind`: `deliverable` or
5
+ -- `proposal`), a proposal's optional price (minor units
6
+ -- of a two-decimal currency), the client's current Stripe
7
+ -- Checkout Session (id, URL, expiry) and when Stripe
8
+ -- reported the proposal paid, with the session that paid
9
+ -- it. Stripe objects are named by plain columns with a
10
+ -- format CHECK and no foreign key (ADR 0009).
11
+ --
12
+ -- DDL only. Every existing row reads `kind = 'deliverable'` from the constant
13
+ -- default — Postgres stores the default in the catalog and rewrites no row, so
14
+ -- `updated_at` and every other column of an existing piece are unchanged. The
15
+ -- seven other columns are nullable with no default. Each CHECK below is added
16
+ -- NOT VALID and then VALIDATEd; every existing row passes each one (a
17
+ -- deliverable with every new column NULL).
18
+ --
19
+ -- Rollout: deploy this migration BEFORE the API code that reads and writes the
20
+ -- columns; code without them fails every piece read.
21
+ --
22
+ -- Rollback: DROP INDEX "pieces_checkout_session_id_key"; ALTER TABLE "pieces"
23
+ -- DROP COLUMN "kind", DROP COLUMN "price_amount", DROP COLUMN
24
+ -- "price_currency", DROP COLUMN "checkout_session_id", DROP COLUMN
25
+ -- "checkout_url", DROP COLUMN "checkout_expires_at", DROP COLUMN "paid_at",
26
+ -- DROP COLUMN "paid_session_id"; (the CHECKs go with them).
27
+
28
+ -- AlterTable
29
+ ALTER TABLE "pieces" ADD COLUMN "kind" VARCHAR(16) NOT NULL DEFAULT 'deliverable',
30
+ ADD COLUMN "price_amount" INTEGER,
31
+ ADD COLUMN "price_currency" CHAR(3),
32
+ ADD COLUMN "checkout_session_id" TEXT,
33
+ ADD COLUMN "checkout_url" VARCHAR(2048),
34
+ ADD COLUMN "checkout_expires_at" TIMESTAMP(3),
35
+ ADD COLUMN "paid_at" TIMESTAMP(3),
36
+ ADD COLUMN "paid_session_id" TEXT;
37
+
38
+ -- CreateIndex
39
+ CREATE UNIQUE INDEX "pieces_checkout_session_id_key" ON "pieces"("checkout_session_id");
40
+
41
+ -- A piece is a deliverable or a proposal, nothing else.
42
+ ALTER TABLE "pieces" ADD CONSTRAINT "pieces_kind_allowed"
43
+ CHECK ("kind" IN ('deliverable', 'proposal')) NOT VALID;
44
+ ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_kind_allowed";
45
+
46
+ -- An amount and its currency are written together.
47
+ ALTER TABLE "pieces" ADD CONSTRAINT "pieces_price_pair"
48
+ CHECK (("price_amount" IS NULL) = ("price_currency" IS NULL)) NOT VALID;
49
+ ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_price_pair";
50
+
51
+ -- 1 to 100,000,000 minor units (PROPOSAL_PRICE_MAX_MINOR).
52
+ ALTER TABLE "pieces" ADD CONSTRAINT "pieces_price_range"
53
+ CHECK ("price_amount" IS NULL OR "price_amount" BETWEEN 1 AND 100000000) NOT VALID;
54
+ ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_price_range";
55
+
56
+ -- A lower-case ISO-4217 code.
57
+ ALTER TABLE "pieces" ADD CONSTRAINT "pieces_price_currency_format"
58
+ CHECK ("price_currency" IS NULL OR "price_currency" ~ '^[a-z]{3}$') NOT VALID;
59
+ ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_price_currency_format";
60
+
61
+ -- Only a proposal carries a price.
62
+ ALTER TABLE "pieces" ADD CONSTRAINT "pieces_price_proposal_only"
63
+ CHECK ("price_amount" IS NULL OR "kind" = 'proposal') NOT VALID;
64
+ ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_price_proposal_only";
65
+
66
+ -- A Checkout Session's id, URL and expiry are written together.
67
+ ALTER TABLE "pieces" ADD CONSTRAINT "pieces_checkout_triple"
68
+ CHECK (("checkout_session_id" IS NULL) = ("checkout_url" IS NULL)
69
+ AND ("checkout_session_id" IS NULL) = ("checkout_expires_at" IS NULL)) NOT VALID;
70
+ ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_checkout_triple";
71
+
72
+ -- A Stripe Checkout Session id.
73
+ ALTER TABLE "pieces" ADD CONSTRAINT "pieces_checkout_session_format"
74
+ CHECK ("checkout_session_id" IS NULL OR "checkout_session_id" ~ '^cs_(test|live)_[A-Za-z0-9]{1,250}$') NOT VALID;
75
+ ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_checkout_session_format";
76
+
77
+ -- A Checkout URL is https.
78
+ ALTER TABLE "pieces" ADD CONSTRAINT "pieces_checkout_url_https"
79
+ CHECK ("checkout_url" IS NULL OR "checkout_url" ~ '^https://') NOT VALID;
80
+ ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_checkout_url_https";
81
+
82
+ -- A Checkout Session opens only for an approved, priced proposal.
83
+ ALTER TABLE "pieces" ADD CONSTRAINT "pieces_checkout_needs_approved_price"
84
+ CHECK ("checkout_session_id" IS NULL OR ("price_amount" IS NOT NULL AND "approved_at" IS NOT NULL)) NOT VALID;
85
+ ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_checkout_needs_approved_price";
86
+
87
+ -- When paid and the session that paid are written together.
88
+ ALTER TABLE "pieces" ADD CONSTRAINT "pieces_paid_pair"
89
+ CHECK (("paid_at" IS NULL) = ("paid_session_id" IS NULL)) NOT VALID;
90
+ ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_paid_pair";
91
+
92
+ -- Only a priced proposal is paid.
93
+ ALTER TABLE "pieces" ADD CONSTRAINT "pieces_paid_needs_price"
94
+ CHECK ("paid_at" IS NULL OR "price_amount" IS NOT NULL) NOT VALID;
95
+ ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_paid_needs_price";
@@ -0,0 +1,30 @@
1
+ -- #8515 — an outbound message may carry the onboarding action (spec
2
+ -- docs/specs/8515-standard-client-onboarding-diagnostic-and-spec.md D6).
3
+ --
4
+ -- `interactions_outbound_shape` (20261012120000_member_contract) admitted an
5
+ -- outbound row only as a payload-free `message`. Start onboarding writes an
6
+ -- outbound `message` whose `payload` is exactly `{"action": "onboarding"}`,
7
+ -- which the client's own site renders as a link to its `/account/onboarding`.
8
+ -- The CHECK is replaced in place, under the same name, admitting that one
9
+ -- payload and nothing else; no other constraint changes and no row is
10
+ -- rewritten. The new CHECK is added NOT VALID and then VALIDATEd (the #8516
11
+ -- piece_kind shape). The DROP takes ACCESS EXCLUSIVE and, in the migration's
12
+ -- one transaction, holds it through the VALIDATE scan, so the table is locked
13
+ -- for that scan; in exchange there is no moment without the constraint. Every
14
+ -- existing outbound row is payload-free and passes.
15
+ --
16
+ -- Folder name: the spec named 20261016120000; #8516's 20261016120000_piece_kind
17
+ -- landed first at that timestamp, so this sorts after it (spec §5.3).
18
+ --
19
+ -- Rollback — only AFTER the code is rolled back (running code would write
20
+ -- rows the old CHECK refuses):
21
+ -- UPDATE "interactions" SET "payload" = NULL WHERE "direction" = 'outbound';
22
+ -- ALTER TABLE "interactions" DROP CONSTRAINT "interactions_outbound_shape";
23
+ -- ALTER TABLE "interactions" ADD CONSTRAINT "interactions_outbound_shape"
24
+ -- CHECK ("direction" <> 'outbound' OR ("kind" = 'message' AND "payload" IS NULL));
25
+ -- Clients then lose the Open onboarding link on those messages; the body stays.
26
+
27
+ ALTER TABLE "interactions" DROP CONSTRAINT "interactions_outbound_shape";
28
+ ALTER TABLE "interactions" ADD CONSTRAINT "interactions_outbound_shape"
29
+ CHECK ("direction" <> 'outbound' OR ("kind" = 'message' AND ("payload" IS NULL OR "payload" = '{"action": "onboarding"}'::jsonb))) NOT VALID;
30
+ ALTER TABLE "interactions" VALIDATE CONSTRAINT "interactions_outbound_shape";
@@ -25,3 +25,19 @@ model AuditLog {
25
25
  @@index([workspaceId, targetType, targetId])
26
26
  @@map("audit_logs")
27
27
  }
28
+
29
+ /// RateLimitCounter — the shared per-bucket counter for `rateLimitMiddleware`'s
30
+ /// database store (#5040 D2). Belongs to the deployment, not a tenant: no
31
+ /// workspaceId, no tenancy fence. Rows are disposable — a lost counter only
32
+ /// resets a window. `key_hash` is sha256(bucketKey) hex, never the raw key.
33
+ model RateLimitCounter {
34
+ id String @id @default(dbgenerated("('rlc_'::text || (uuidv7())::text)")) @db.Text
35
+ keyHash String @unique @map("key_hash") @db.Text // sha256(bucketKey) hex
36
+ windowStartMs BigInt @map("window_start_ms")
37
+ windowMs Int @map("window_ms")
38
+ count Int
39
+ createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
40
+
41
+ @@index([windowStartMs], map: "rate_limit_counters_window_start_ms_idx")
42
+ @@map("rate_limit_counters")
43
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@working-theory/database",
3
- "version": "0.39.0",
3
+ "version": "0.41.0",
4
4
  "license": "Apache-2.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,7 +1,8 @@
1
1
  schema_version: 1
2
2
 
3
3
  # project.yaml — per-repo configuration consumed by Claude Code skills and
4
- # global rules. Replace REPLACE_ME values with your repo's actual identity.
4
+ # global rules. Replace every REPLACE_ME value with your repo's own: its
5
+ # identity and its Slack channel.
5
6
  #
6
7
  # See https://github.com/working-theory-labs/ai-launch-kit/blob/main/project.yaml
7
8
  # for AI Launch Kit's own canonical example.
@@ -10,10 +11,13 @@ identity:
10
11
  name: REPLACE_ME # your repo slug, kebab-case
11
12
  github_repo: REPLACE_ME/REPLACE_ME # owner/repo on GitHub
12
13
  npm_scope: "@REPLACE_ME" # e.g. "@yourorg" — replace with your npm scope
13
- visibility: private # "oss" | "private"
14
+ visibility: private # "public" | "private" | "internal"
14
15
  default_branch: main
15
16
  branching_model: single_trunk
16
17
 
18
+ slack:
19
+ primary_channel: REPLACE_ME # channel name without "#", where this repo's CI and agent reports land
20
+
17
21
  product:
18
22
  identity_mode: organization # "organization" | "person" | null
19
23
  default_locale: en
@@ -27,7 +31,6 @@ labels:
27
31
  blocked: status/blocked
28
32
  done: status/done
29
33
  needs_spec: status/needs-spec
30
- auto_merge: auto-merge-eligible
31
34
 
32
35
  verification:
33
36
  preflight: pnpm preflight
package/versions.json CHANGED
@@ -1,53 +1,53 @@
1
1
  {
2
- "@working-theory/admin-ui": "0.39.0",
3
- "@working-theory/aeo": "0.39.0",
4
- "@working-theory/agent-context": "0.39.0",
2
+ "@working-theory/admin-ui": "0.41.0",
3
+ "@working-theory/aeo": "0.41.0",
4
+ "@working-theory/agent-context": "0.41.0",
5
5
  "@working-theory/agent-contract": "0.1.0",
6
6
  "@working-theory/agent-memory": "0.0.0",
7
7
  "@working-theory/ai": "0.1.0",
8
- "@working-theory/analytics": "0.39.0",
9
- "@working-theory/api-client": "0.39.0",
8
+ "@working-theory/analytics": "0.41.0",
9
+ "@working-theory/api-client": "0.41.0",
10
10
  "@working-theory/cda-filesystem": "0.0.0",
11
- "@working-theory/cli": "0.39.0",
12
- "@working-theory/common": "0.39.0",
11
+ "@working-theory/cli": "0.41.0",
12
+ "@working-theory/common": "0.41.0",
13
13
  "@working-theory/consent": "0.1.0",
14
- "@working-theory/content-adapters": "0.39.0",
15
- "@working-theory/content-projection": "0.39.0",
16
- "@working-theory/email": "0.39.0",
14
+ "@working-theory/content-adapters": "0.41.0",
15
+ "@working-theory/content-projection": "0.41.0",
16
+ "@working-theory/email": "0.41.0",
17
17
  "@working-theory/env": "0.0.0",
18
- "@working-theory/eslint-config": "0.39.0",
19
- "@working-theory/fumadocs-schema": "0.39.0",
20
- "@working-theory/ids": "0.12.0",
21
- "@working-theory/jsonld": "0.39.0",
22
- "@working-theory/license": "0.39.0",
23
- "@working-theory/metadata": "0.39.0",
24
- "@working-theory/observability": "0.39.0",
25
- "@working-theory/page-renderer": "0.39.0",
18
+ "@working-theory/eslint-config": "0.41.0",
19
+ "@working-theory/fumadocs-schema": "0.41.0",
20
+ "@working-theory/ids": "0.14.0",
21
+ "@working-theory/jsonld": "0.41.0",
22
+ "@working-theory/license": "0.41.0",
23
+ "@working-theory/metadata": "0.41.0",
24
+ "@working-theory/observability": "0.41.0",
25
+ "@working-theory/page-renderer": "0.41.0",
26
26
  "@working-theory/plugin-mcp": "0.1.3",
27
- "@working-theory/schema": "0.39.0",
28
- "@working-theory/schema-pack-registry": "0.39.0",
29
- "@working-theory/schema-validator": "0.39.0",
30
- "@working-theory/sections-registry": "0.39.0",
31
- "@working-theory/site-config": "0.39.0",
32
- "@working-theory/spoke-checkout": "0.5.0",
33
- "@working-theory/stripe-client": "0.39.0",
34
- "@working-theory/templates": "0.39.0",
35
- "@working-theory/theme": "0.39.0",
36
- "@working-theory/ui": "0.39.0",
37
- "@working-theory/validation": "0.39.0",
38
- "@working-theory/web-i18n": "0.39.0",
27
+ "@working-theory/schema": "0.41.0",
28
+ "@working-theory/schema-pack-registry": "0.41.0",
29
+ "@working-theory/schema-validator": "0.41.0",
30
+ "@working-theory/sections-registry": "0.41.0",
31
+ "@working-theory/site-config": "0.41.0",
32
+ "@working-theory/spoke-checkout": "0.5.2",
33
+ "@working-theory/stripe-client": "0.41.0",
34
+ "@working-theory/templates": "0.41.0",
35
+ "@working-theory/theme": "0.41.0",
36
+ "@working-theory/ui": "0.41.0",
37
+ "@working-theory/validation": "0.41.0",
38
+ "@working-theory/web-i18n": "0.41.0",
39
39
  "@working-theory/billing-client": "0.0.0",
40
40
  "@working-theory/branding": "0.0.0",
41
41
  "@working-theory/license-client": "0.0.0",
42
42
  "@working-theory/license-manifest": "0.0.0",
43
43
  "@working-theory/partner-session": "0.0.0",
44
44
  "@working-theory/preview-protocol": "0.0.0",
45
- "@working-theory/ui-commerce": "0.23.17",
46
- "@working-theory/ui-docs-blog": "0.23.17",
47
- "@working-theory/ui-scheduling": "0.23.17",
48
- "@working-theory/ui-signal-collectors": "0.25.6",
45
+ "@working-theory/ui-commerce": "0.23.19",
46
+ "@working-theory/ui-docs-blog": "0.23.19",
47
+ "@working-theory/ui-scheduling": "0.23.19",
48
+ "@working-theory/ui-signal-collectors": "0.25.8",
49
49
  "@working-theory/web": "0.0.0",
50
50
  "@working-theory/api": "1.0.0",
51
51
  "@working-theory/mcp": "0.0.0",
52
- "@working-theory/database": "0.39.0"
52
+ "@working-theory/database": "0.41.0"
53
53
  }
@@ -1,51 +0,0 @@
1
- # Preserve Existing Style
2
-
3
- When editing existing files, preserve their existing formatting. Do
4
- **not** reformat, reflow, reorganize imports, change quote style,
5
- change indentation, or rearrange whitespace on lines that aren't
6
- materially changing as part of your task.
7
-
8
- Your diff should contain only the lines you deliberately touched. A
9
- 20-line functional change should produce a ~20-line diff, not a
10
- 900-line diff with 880 lines of formatting churn.
11
-
12
- ## Why
13
-
14
- Formatting churn:
15
-
16
- - Obscures real changes during code review.
17
- - Creates noise in `git blame` / `git log`.
18
- - Triggers unnecessary merge conflicts.
19
- - Violates the spirit of "behavior must not change unless the
20
- acceptance criteria say so" — even if runtime behavior is identical,
21
- the meaning to a human reader has changed.
22
-
23
- ## How to apply
24
-
25
- - **Before committing:** run `git diff --stat`. If the delta is
26
- wildly larger than the work you did, investigate before pushing.
27
- - **If your editor runs a formatter on save:** disable it for the
28
- session, configure it to match the existing style, or revert
29
- formatting-only lines before committing.
30
- - **If quotes, semicolons, or import grouping differ from the
31
- existing file:** match the existing file, not your editor's
32
- defaults.
33
- - **The diff is the contract.** A reviewer should see only the lines
34
- you meant to change.
35
-
36
- ## Not covered by this rule
37
-
38
- - Deliberate cleanup (removing dead code, inlining single-use
39
- helpers, collapsing redundant abstraction) is fine when it's the
40
- point of the task and called out in the PR.
41
- - Net-new files set their own style, subject to the project's
42
- existing conventions.
43
- - A task whose acceptance criteria explicitly say "reformat file X"
44
- (rare).
45
-
46
- ## Escalation
47
-
48
- If you believe the existing style is genuinely wrong and want to
49
- change it: stop. Note it in the PR description and propose the
50
- reformat as a separate PR. Do not unilaterally reformat the codebase
51
- as a side effect of an unrelated task.