create-ailk 0.15.0 → 0.17.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 (128) hide show
  1. package/README.md +124 -0
  2. package/dist/add-module.js +52 -7
  3. package/dist/add-route.js +8 -0
  4. package/dist/adopt.d.ts +74 -0
  5. package/dist/adopt.js +314 -0
  6. package/dist/cli.js +82 -2
  7. package/dist/derive-architecture.d.ts +22 -0
  8. package/dist/derive-architecture.js +58 -1
  9. package/dist/lib/declared-env.d.ts +142 -0
  10. package/dist/lib/declared-env.js +985 -0
  11. package/dist/lib/env-catalog.d.ts +17 -0
  12. package/dist/lib/env-catalog.js +234 -0
  13. package/dist/lib/extract-module-bundle.d.ts +9 -0
  14. package/dist/lib/extract-module-bundle.js +18 -1
  15. package/dist/lib/module-tier.d.ts +2 -0
  16. package/dist/lib/module-tier.js +4 -0
  17. package/dist/module-architecture.js +76 -0
  18. package/dist/parse-args.d.ts +5 -0
  19. package/dist/parse-args.js +17 -1
  20. package/dist/programmatic.d.ts +8 -0
  21. package/dist/programmatic.js +78 -9
  22. package/dist/seed-flows.d.ts +65 -0
  23. package/dist/seed-flows.js +350 -0
  24. package/dist/site-manifest.d.ts +43 -0
  25. package/dist/site-manifest.js +98 -3
  26. package/dist/site-roster.d.ts +13 -0
  27. package/dist/site-roster.js +22 -8
  28. package/dist/spoke-checkout.d.ts +67 -0
  29. package/dist/spoke-checkout.js +562 -0
  30. package/dist/surfaces.js +7 -0
  31. package/dist/sync-routes.js +23 -8
  32. package/dist/topology.d.ts +124 -9
  33. package/dist/topology.js +451 -40
  34. package/package.json +3 -3
  35. package/templates/.env.example +10 -0
  36. package/templates/apps/api/CLAUDE.md +19 -4
  37. package/templates/apps/api/src/__tests__/factories/in-memory-prisma.ts +95 -16
  38. package/templates/apps/api/src/__tests__/openapi-keyless-hub.test.ts +122 -0
  39. package/templates/apps/api/src/__tests__/support/hub-sign-in-fake-db.ts +362 -0
  40. package/templates/apps/api/src/bin/spokes.ts +62 -1
  41. package/templates/apps/api/src/config/__tests__/hub-require-spoke-key.test.ts +75 -0
  42. package/templates/apps/api/src/config/index.ts +35 -0
  43. package/templates/apps/api/src/lib/__mocks__/prisma.ts +89 -0
  44. package/templates/apps/api/src/lib/__tests__/deliverable-asset-store.test.ts +66 -5
  45. package/templates/apps/api/src/lib/__tests__/hub-sign-in-store.test.ts +209 -0
  46. package/templates/apps/api/src/lib/__tests__/spoke-store.test.ts +20 -0
  47. package/templates/apps/api/src/lib/deliverable-asset-store.ts +24 -5
  48. package/templates/apps/api/src/lib/hub-sign-in-store.ts +419 -0
  49. package/templates/apps/api/src/lib/spoke-store.ts +25 -3
  50. package/templates/apps/api/src/middleware/__tests__/auth.hub-session-path.test.ts +310 -0
  51. package/templates/apps/api/src/middleware/auth.ts +126 -0
  52. package/templates/apps/api/src/routes/auth/__tests__/hub-sign-in.test.ts +483 -0
  53. package/templates/apps/api/src/routes/auth/hub-sign-in.ts +201 -0
  54. package/templates/apps/api/src/routes/leads/__tests__/index.test.ts +7 -0
  55. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-flow-checkout.test.ts +105 -0
  56. package/templates/apps/api/src/routes/webhooks/stripe.ts +72 -1
  57. package/templates/apps/api/src/server.ts +105 -0
  58. package/templates/apps/api/src/services/__tests__/deliverable-fulfillment.test.ts +4 -4
  59. package/templates/apps/api/src/services/__tests__/hub-sign-in.test.ts +854 -0
  60. package/templates/apps/api/src/services/__tests__/lead-routing.test.ts +293 -0
  61. package/templates/apps/api/src/services/__tests__/person.test.ts +553 -0
  62. package/templates/apps/api/src/services/hub-sign-in.ts +471 -0
  63. package/templates/apps/api/src/services/lead-routing.ts +131 -2
  64. package/templates/apps/api/src/services/person.ts +541 -0
  65. package/templates/apps/web/.env.example +58 -5
  66. package/templates/apps/web/app/[locale]/(auth)/sign-in/next-path.ts +0 -0
  67. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +206 -0
  68. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +256 -3
  69. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +5 -8
  70. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/__tests__/route.test.ts +205 -0
  71. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +82 -0
  72. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +98 -29
  73. package/templates/apps/web/app/[locale]/(authed)/account/support-actions.ts +6 -3
  74. package/templates/apps/web/app/[locale]/(authed)/layout.tsx +19 -101
  75. package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +90 -0
  76. package/templates/apps/web/app/[locale]/layout.tsx +28 -15
  77. package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +295 -0
  78. package/templates/apps/web/app/api/auth/hub/authorize/route.ts +156 -0
  79. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +341 -0
  80. package/templates/apps/web/app/api/hub-session/callback/route.ts +168 -0
  81. package/templates/apps/web/app/api/hub-session/sign-in/route.ts +76 -0
  82. package/templates/apps/web/app/api/hub-session/sign-out/route.ts +63 -0
  83. package/templates/apps/web/app/openapi.json/__tests__/route.test.ts +57 -24
  84. package/templates/apps/web/app/openapi.json/route.ts +3 -6
  85. package/templates/apps/web/auth.ts +29 -2
  86. package/templates/apps/web/components/sign-out-trigger.tsx +20 -1
  87. package/templates/apps/web/components/signed-in-nav.tsx +17 -3
  88. package/templates/apps/web/lib/__tests__/account-config.test.ts +5 -2
  89. package/templates/apps/web/lib/__tests__/listings-config.test.ts +83 -0
  90. package/templates/apps/web/lib/__tests__/listings.test.tsx +49 -0
  91. package/templates/apps/web/lib/__tests__/meeting-slugs.test.ts +49 -1
  92. package/templates/apps/web/lib/__tests__/relay.test.ts +33 -0
  93. package/templates/apps/web/lib/__tests__/server-api.test.ts +37 -28
  94. package/templates/apps/web/lib/account-config.ts +130 -1
  95. package/templates/apps/web/lib/api-origin.generated.ts +11 -0
  96. package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +262 -0
  97. package/templates/apps/web/lib/hub-session/config.ts +104 -0
  98. package/templates/apps/web/lib/hub-session/index.ts +23 -0
  99. package/templates/apps/web/lib/hub-session/seal.ts +82 -0
  100. package/templates/apps/web/lib/hub-session/session.ts +180 -0
  101. package/templates/apps/web/lib/hub-session/sign-in-gate.tsx +79 -0
  102. package/templates/apps/web/lib/listings-config.ts +31 -0
  103. package/templates/apps/web/lib/listings.tsx +7 -3
  104. package/templates/apps/web/lib/meeting-slugs.ts +11 -1
  105. package/templates/apps/web/lib/next-path.ts +35 -0
  106. package/templates/apps/web/lib/relay.ts +3 -1
  107. package/templates/apps/web/lib/server-api.ts +11 -1
  108. package/templates/apps/web/lib/topology.generated.ts +15 -5
  109. package/templates/apps/web/messages/en.json +32 -3
  110. package/templates/database/CHANGELOG.md +26 -0
  111. package/templates/database/__tests__/agents.db.test.ts +25 -5
  112. package/templates/database/__tests__/fixtures/person-backfill.json +264 -0
  113. package/templates/database/__tests__/member-area.db.test.ts +245 -0
  114. package/templates/database/__tests__/person.db.test.ts +584 -0
  115. package/templates/database/auth/schema.prisma +3 -2
  116. package/templates/database/config/schema.prisma +13 -0
  117. package/templates/database/inbox/schema.prisma +98 -0
  118. package/templates/database/migrations/20261010120000_person/migration.sql +106 -0
  119. package/templates/database/migrations/20261010121000_person_backfill/migration.sql +132 -0
  120. package/templates/database/migrations/20261010130000_agent_grants_people_read/migration.sql +20 -0
  121. package/templates/database/migrations/20261011120000_member_area/migration.sql +158 -0
  122. package/templates/database/migrations/20261011130000_agent_grants_member_pieces_manage/migration.sql +21 -0
  123. package/templates/database/package.json +1 -1
  124. package/templates/database/scripts/person-backfill.sql +132 -0
  125. package/templates/database/tenancy.ts +53 -0
  126. package/templates/tools/check-declared-env.ts +37 -0
  127. package/templates/tools/declared-env.ts +1163 -0
  128. package/versions.json +35 -35
@@ -10,16 +10,48 @@ export declare class TopologyError extends Error {
10
10
  export declare const SPOKE_REMOVED_ROOTS: readonly string[];
11
11
  /** The root `--without-mcp` removes. */
12
12
  export declare const SPOKE_MCP_ROOT = "apps/mcp";
13
+ /** Commerce's apps/web files that reach the hub's own checkout (spoke-intake Rule 3, #7838). */
14
+ export declare const SPOKE_HUB_CHECKOUT_SEEDS: readonly string[];
13
15
  /**
14
- * The sign-in and database files a spoke does not carry — files and
15
- * directories, scaffold-relative. Every other file that imports one of them
16
- * goes with it (`spokeExclusions`).
16
+ * The files a spoke does not carry — files and directories, scaffold-relative:
17
+ * the sign-in and database seeds, then the commerce files that call the hub's
18
+ * own checkout (`SPOKE_HUB_CHECKOUT_SEEDS`; a spoke keeps its own, #7838).
19
+ * Every other file that imports one of them goes with it (`spokeExclusions`).
17
20
  */
18
21
  export declare const SPOKE_REMOVAL_SEEDS: readonly string[];
19
- /** The two generated seam files (D5). A seam is rewritten, never removed. */
22
+ /**
23
+ * Module paths a spoke drops even when it carries the module (#7876 D8,
24
+ * clarified 2026-10-09). `signal-collectors`' report reader links a
25
+ * grant-gated report's bytes on the hub from `NEXT_PUBLIC_AILK_API_URL`,
26
+ * which a spoke refuses (#7874: its hub origin is server-only), and a
27
+ * deliverable is hub-side anyway — so a spoke carries neither the
28
+ * `/reports` routes nor the report seeds that would have no route.
29
+ */
30
+ export declare const SPOKE_EXCLUDED_MODULE_PATHS: readonly string[];
31
+ /**
32
+ * The `(authed)` seeds of the sign-in-through-the-hub mode (#7894 D9): the
33
+ * whole `(authed)` group goes in the default mode; in the hub mode its account
34
+ * area, layout and gate seam stay, and only these go — the operator surfaces,
35
+ * the Better Auth gate and the suites that mock `auth.ts` by path.
36
+ */
37
+ export declare const HUB_MODE_AUTHED_SEEDS: readonly string[];
38
+ /** The generated seam files (D5; #7874 D12). A seam is rewritten, never removed. */
20
39
  export declare const WEB_SEAM_PATH = "apps/web/lib/topology.generated.ts";
21
40
  export declare const MCP_SEAM_PATH = "apps/mcp/src/lib/topology.generated.ts";
41
+ /** The browser API origin seam (#7874 D12): a spoke's render reads no env. */
42
+ export declare const API_ORIGIN_SEAM_PATH = "apps/web/lib/api-origin.generated.ts";
43
+ /**
44
+ * The `(authed)` layout's signed-out gate (#7894 D8). Under the `(authed)`
45
+ * seed, so a default-mode spoke drops it with its group and never renders it.
46
+ */
47
+ export declare const AUTHED_GATE_SEAM_PATH = "apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx";
22
48
  export declare const SPOKE_SEAM_FILES: readonly string[];
49
+ /**
50
+ * Template files only a spoke carries (#7874 D11): the declared-env check.
51
+ * `scaffoldSync` excludes them from a hub's copy (`copyTemplate`'s
52
+ * `excludePaths` matches an exact file path).
53
+ */
54
+ export declare const SPOKE_ONLY_FILES: readonly string[];
23
55
  /**
24
56
  * The closure's allow-list: a file `spokeExclusions` removes must sit under
25
57
  * one of these prefixes, or under a `__tests__/` directory. A member outside
@@ -27,14 +59,26 @@ export declare const SPOKE_SEAM_FILES: readonly string[];
27
59
  * file — and `spokeExclusions` throws naming it rather than cut it silently.
28
60
  */
29
61
  export declare const SPOKE_REMOVABLE_PREFIXES: readonly string[];
62
+ /**
63
+ * A spoke's sign-in modes (#7894 D1): `off` — the default, no sign-in — and
64
+ * `hub`, signing a visitor in through the hub (`--hub-sign-in <origin>`).
65
+ */
66
+ export type SignInMode = "off" | "hub";
30
67
  export interface SpokeShapeOptions {
31
68
  /** Whether the spoke keeps `apps/mcp` (the default; `--without-mcp` drops it). */
32
69
  mcp: boolean;
70
+ /** The sign-in mode (#7894 D1). Absent means `"off"`, so every existing caller is the default mode. */
71
+ signIn?: SignInMode;
33
72
  }
34
73
  /** The removed roots for these options. */
35
74
  export declare function spokeRemovedRoots(opts: SpokeShapeOptions): string[];
36
- /** Whether a closure member is one the registry allows a spoke to drop. */
37
- export declare function isRemovableClosureMember(path: string): boolean;
75
+ /**
76
+ * Whether a closure member is one the registry allows a spoke to drop: under
77
+ * a seed of THAT sign-in mode, or a test. In the hub mode a surviving account
78
+ * file that imports `auth.ts` is therefore not removable, and
79
+ * `spokeExclusions` throws naming it (#7894 D9).
80
+ */
81
+ export declare function isRemovableClosureMember(path: string, opts?: Pick<SpokeShapeOptions, "signIn">): boolean;
38
82
  /**
39
83
  * Every path a spoke does not carry, computed over the built `templates/`
40
84
  * tree: the removed roots, the seeds that apply, and every source file under
@@ -69,14 +113,56 @@ export interface IsSpokeExcludedOptions extends SpokeShapeOptions {
69
113
  * generator contract). Scaffold-relative, `/`- or `\`-separated.
70
114
  */
71
115
  export declare function isSpokeExcluded(path: string, opts: IsSpokeExcludedOptions): boolean;
72
- /** `apps/web/lib/topology.generated.ts` for `topology` (D5). */
73
- export declare function renderWebSeam(topology: Topology): string;
116
+ /**
117
+ * Where a module bundle's `installMap` destination lands on a spoke (#7876
118
+ * D10): `database/flows/<name>.flow.json` becomes `flows/<name>.json` — a
119
+ * declared flow `create-ailk seed-flows` sends to the hub — and every other
120
+ * destination is returned unchanged. Applied before the spoke filter, so a
121
+ * remapped flow survives it while the rest of `database/` is dropped. A hub
122
+ * install passes no remap.
123
+ */
124
+ export declare function spokeDestination(destination: string): string;
125
+ /**
126
+ * `apps/web/lib/topology.generated.ts` for `topology` (D5) and, on a spoke,
127
+ * its sign-in mode (#7894 D8). The hub render loads `auth.ts` only when a
128
+ * session is read, so a module that imports this seam for a constant never
129
+ * loads Better Auth.
130
+ */
131
+ export declare function renderWebSeam(topology: Topology, signIn?: SignInMode): string;
132
+ /**
133
+ * `apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx` (#7894 D8).
134
+ * The hub render is the `(authed)` layout's no-session branch, moved; the
135
+ * `signIn: "hub"` render imports only the hub-session gate. A default-mode
136
+ * spoke carries no `(authed)` group, so it has no render.
137
+ * @throws TopologyError for a spoke in the default mode.
138
+ */
139
+ export declare function renderAuthedGateSeam(topology: Topology, signIn?: SignInMode): string;
74
140
  /** `apps/mcp/src/lib/topology.generated.ts` for `topology` (D5). */
75
141
  export declare function renderMcpSeam(topology: Topology): string;
142
+ /** `apps/web/lib/api-origin.generated.ts` for `topology` (#7874 D12). */
143
+ export declare function renderApiOriginSeam(topology: Topology): string;
76
144
  /** `pnpm-workspace.yaml` without its `database` package entry. */
77
145
  export declare function transformWorkspaceYaml(text: string): string;
78
146
  /** The root `package.json` without its `db:*` scripts. */
79
147
  export declare function transformRootPackageJson(text: string): string;
148
+ /** The spoke's declared-env script (#7874 D11) — named apart from the monorepo's `env:check`. */
149
+ export declare const ENV_DECLARED_SCRIPT = "env:declared";
150
+ /**
151
+ * The spoke's root `package.json` with the declared-env check (#7874 D11):
152
+ * an `env:declared` script after `claude-md:check`, and `preflight` running
153
+ * it right after `claude-md:check`. Applied after `transformRootPackageJson`.
154
+ * @throws TopologyError when either anchor is missing.
155
+ */
156
+ export declare function addEnvCheckScripts(text: string): string;
157
+ /**
158
+ * The spoke's `.github/workflows/ci.yml` (#7874 D11): a `pnpm env:declared`
159
+ * step after `pnpm claude-md:check`, and no `pnpm db:generate` step — a
160
+ * spoke has no `database/` and no `db:*` script, so that step would fail
161
+ * first (#7962). The comment block directly above the dropped step goes with
162
+ * it.
163
+ * @throws TopologyError when either anchor is missing.
164
+ */
165
+ export declare function transformCiWorkflow(text: string): string;
80
166
  /** The root `tsconfig.json` without a reference under a removed root. */
81
167
  export declare function transformRootTsconfig(text: string, opts: SpokeShapeOptions): string;
82
168
  /**
@@ -87,7 +173,8 @@ export declare function transformAppPackageJson(text: string, label: string, req
87
173
  /**
88
174
  * Apply every D6 root-file transform to the spoke at `targetDir` (after the
89
175
  * base copy, before any module or template layer), and write the spoke
90
- * render of each seam it carries (D5).
176
+ * render of each seam it carries (D5). Also the declared-env check's root
177
+ * script and CI step (#7874 D11), and the browser API origin seam (D12).
91
178
  * @throws TopologyError naming the file whose anchor is missing.
92
179
  */
93
180
  export declare function applySpokeTransforms(targetDir: string, opts: SpokeShapeOptions): void;
@@ -101,10 +188,24 @@ export declare const HUB_ORIGIN_ENV_VAR = "AILK_API_URL";
101
188
  * the hub issues those.
102
189
  */
103
190
  export declare function writeHubOriginEnv(targetDir: string, origin: string): void;
191
+ /** The env var naming the hub's web origin a hub-mode spoke signs in at (#7894 D11). */
192
+ export declare const HUB_SIGN_IN_URL_ENV_VAR = "AILK_HUB_SIGN_IN_URL";
193
+ /** The env var holding a hub-mode spoke's own cookie key material (#7894 D7, D11). */
194
+ export declare const HUB_SESSION_SECRET_ENV_VAR = "AILK_HUB_SESSION_SECRET";
195
+ /**
196
+ * Write a hub-mode spoke's sign-in env (#7894 D11) to `apps/web/.env.local`,
197
+ * under `writeHubOriginEnv`'s never-clobber rule: the hub's web origin, and a
198
+ * fresh session secret (32 random bytes, 43 base64url characters). Never the
199
+ * client id or client secret — the hub issues those (`spokes sign-in-client`)
200
+ * — and never `BETTER_AUTH_SECRET` or a database URL.
201
+ */
202
+ export declare function writeHubSignInEnv(targetDir: string, origin: string): void;
104
203
  /** The `hard_floors:` block a spoke's `project.yaml` carries (D9). */
105
204
  export declare function renderSpokeHardFloors(opts: SpokeShapeOptions): string;
106
205
  /** `project.yaml` with its `hard_floors:` block replaced by the spoke's (D9). */
107
206
  export declare function transformProjectYaml(text: string, opts: SpokeShapeOptions): string;
207
+ /** Why a module is not admitted on a spoke, and where its admission lives. */
208
+ export declare const SPOKE_REFUSAL_REASONS: Partial<Record<ModuleName, string>>;
108
209
  /** The modules a spoke may carry — every slice declaring `spoke: true`. */
109
210
  export declare function spokeModules(): ModuleName[];
110
211
  /** The refusal for a module a spoke cannot carry, or undefined when admitted. */
@@ -115,6 +216,14 @@ export declare function spokeModuleRefusal(name: ModuleName): string | undefined
115
216
  * @throws TopologyError on an unreadable manifest or an unknown value.
116
217
  */
117
218
  export declare function readSiteTopology(targetDir: string): Topology;
219
+ /**
220
+ * The spoke options `<targetDir>` records (#7894 D1), for the later commands
221
+ * (`sync-routes`, `add-module`): `undefined` on a hub; on a spoke, `mcp` from
222
+ * whether it still carries `apps/mcp` and `signIn` from the manifest's
223
+ * `signIn` key — absent reads as `"off"`, every spoke before #7894.
224
+ * @throws TopologyError on an unreadable manifest or an unknown value.
225
+ */
226
+ export declare function readSpokeShape(targetDir: string): SpokeShapeOptions | undefined;
118
227
  /**
119
228
  * Hosts a spoke may reach over plain `http:` — the set
120
229
  * `packages/api-client/src/http.ts` sends the spoke key under. Named here
@@ -129,3 +238,9 @@ export declare const LOOPBACK_HOSTS: readonly string[];
129
238
  * is not such an origin. Never echoes a query or fragment.
130
239
  */
131
240
  export declare function normalizeHubUrl(raw: string | undefined): string;
241
+ /**
242
+ * The hub's WEB origin a hub-mode spoke signs in at (`--hub-sign-in`, #7894
243
+ * D1) — `normalizeHubUrl`'s rules, each refusal naming the flag.
244
+ * @throws TopologyError when `raw` is not such an origin.
245
+ */
246
+ export declare function normalizeHubSignInUrl(raw: string): string;