create-ailk 0.9.0 → 0.11.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 (104) hide show
  1. package/README.md +10 -5
  2. package/dist/cli.js +17 -2
  3. package/dist/content-payloads.d.ts +37 -0
  4. package/dist/content-payloads.js +64 -0
  5. package/dist/lib/fetch-module.d.ts +3 -3
  6. package/dist/lib/fetch-module.js +11 -5
  7. package/dist/lib/fetch-template.d.ts +1 -1
  8. package/dist/lib/fetch-template.js +7 -4
  9. package/dist/lib/module-license-gate.d.ts +29 -23
  10. package/dist/lib/module-license-gate.js +98 -0
  11. package/dist/module-architecture.d.ts +9 -0
  12. package/dist/module-architecture.js +46 -14
  13. package/dist/parse-args.d.ts +2 -0
  14. package/dist/parse-args.js +7 -0
  15. package/dist/programmatic.js +12 -4
  16. package/dist/starter-grid.d.ts +4 -67
  17. package/dist/starter-grid.js +6 -84
  18. package/dist/surfaces.js +2 -3
  19. package/dist/template-manifest.d.ts +1 -1
  20. package/dist/template-manifest.js +5 -5
  21. package/package.json +6 -4
  22. package/release-scope.json +25 -0
  23. package/site-templates/designs/minimalism/sample/README.md +2 -2
  24. package/site-templates/designs/minimalism/sample/content/en/HomePage/home.mdx +1 -1
  25. package/site-templates/marketing-site-free/TEMPLATE-MANIFEST.md +4 -3
  26. package/templates/.claude/agents/web.md +10 -8
  27. package/templates/.claude/rules/architecture.md +10 -7
  28. package/templates/.claude/settings.json +12 -0
  29. package/templates/.env.example +24 -3
  30. package/templates/CLAUDE.md +38 -22
  31. package/templates/README.md +12 -12
  32. package/templates/apps/api/jest.config.cjs +1 -0
  33. package/templates/apps/api/package.json +1 -0
  34. package/templates/apps/mcp/CLAUDE.md +23 -10
  35. package/templates/apps/mcp/__tests__/catalog-drift.test.ts +160 -17
  36. package/templates/apps/mcp/__tests__/index.test.ts +118 -1
  37. package/templates/apps/mcp/__tests__/lib/commerce-claim.test.ts +425 -5
  38. package/templates/apps/mcp/__tests__/module-exclusion.test.ts +67 -3
  39. package/templates/apps/mcp/__tests__/server.test.ts +162 -1
  40. package/templates/apps/mcp/src/index.ts +35 -3
  41. package/templates/apps/mcp/src/lib/commerce-claim.ts +193 -24
  42. package/templates/apps/mcp/src/server.ts +77 -5
  43. package/templates/apps/mcp/src/tools/purchase.ts +1 -1
  44. package/templates/apps/web/app/.well-known/mcp.json/build-manifest.ts +15 -0
  45. package/templates/apps/web/app/.well-known/mcp.json/route.ts +10 -3
  46. package/templates/apps/web/src/lib/commerce-claim.ts +15 -6
  47. package/templates/content/_site.mdx +23 -4
  48. package/templates/database/CHANGELOG.md +7 -0
  49. package/templates/database/package.json +1 -1
  50. package/templates/package.json +2 -0
  51. package/versions.json +34 -33
  52. package/dist/modules/commerce/0.6.0.tar.gz +0 -0
  53. package/dist/modules/commerce/0.6.1.tar.gz +0 -0
  54. package/dist/modules/docs-blog/0.6.0.tar.gz +0 -0
  55. package/dist/modules/docs-blog/0.6.1.tar.gz +0 -0
  56. package/dist/modules/marketing-site/0.6.1.tar.gz +0 -0
  57. package/dist/modules/minimalism-site/0.6.1.tar.gz +0 -0
  58. package/dist/modules/multi-tenant/0.6.0.tar.gz +0 -0
  59. package/dist/modules/multi-tenant/0.6.1.tar.gz +0 -0
  60. package/dist/modules/saas-product/0.6.1.tar.gz +0 -0
  61. package/dist/modules/scheduling/0.6.0.tar.gz +0 -0
  62. package/dist/modules/scheduling/0.6.1.tar.gz +0 -0
  63. package/dist/modules/signal-collectors/0.6.0.tar.gz +0 -0
  64. package/dist/modules/signal-collectors/0.6.1.tar.gz +0 -0
  65. package/dist/modules/simple-service/0.6.1.tar.gz +0 -0
  66. package/dist/modules/workspace/0.6.0.tar.gz +0 -0
  67. package/dist/modules/workspace/0.6.1.tar.gz +0 -0
  68. package/site-templates/aliases/minimalism-site.TEMPLATE-MANIFEST.json +0 -538
  69. package/templates/.claude/skills/README.md +0 -37
  70. package/templates/.claude/skills/add-auth/SKILL.md +0 -261
  71. package/templates/.claude/skills/add-auth/references/env-vars.md +0 -98
  72. package/templates/.claude/skills/add-auth/references/oauth-app-setup.md +0 -172
  73. package/templates/.claude/skills/add-page/SKILL.md +0 -260
  74. package/templates/.claude/skills/add-page/references/page-types.md +0 -124
  75. package/templates/.claude/skills/add-page/scripts/site-pages.mjs +0 -87
  76. package/templates/.claude/skills/add-page/templates/comparison-page.mdx.tmpl +0 -99
  77. package/templates/.claude/skills/add-page/templates/content.mdx.tmpl +0 -18
  78. package/templates/.claude/skills/add-page/templates/flow-landing-page.mdx.tmpl +0 -43
  79. package/templates/.claude/skills/add-page/templates/report-page.mdx.tmpl +0 -52
  80. package/templates/.claude/skills/add-page/templates/reports-list.mdx.tmpl +0 -38
  81. package/templates/.claude/skills/check-site/SKILL.md +0 -235
  82. package/templates/.claude/skills/check-site/references/common-errors.md +0 -113
  83. package/templates/.claude/skills/check-site/references/findings-glossary.md +0 -140
  84. package/templates/.claude/skills/check-site/references/severity-levels.md +0 -114
  85. package/templates/.claude/skills/fill-page/SKILL.md +0 -199
  86. package/templates/.claude/skills/fill-page/profiles/plumbing.yaml +0 -80
  87. package/templates/.claude/skills/fill-page/references/section-sources.md +0 -41
  88. package/templates/.claude/skills/setup-database/SKILL.md +0 -156
  89. package/templates/.claude/skills/setup-database/scripts/verify-inbox.ts +0 -154
  90. package/templates/.claude/skills/setup-deploy/SKILL.md +0 -275
  91. package/templates/.claude/skills/setup-deploy/references/env-vars-template.md +0 -192
  92. package/templates/.claude/skills/setup-deploy/references/runbook-template.md +0 -204
  93. package/templates/.claude/skills/setup-deploy/references/vercel-json-template.md +0 -98
  94. package/templates/.claude/skills/update-page/SKILL.md +0 -117
  95. package/templates/.claude/skills/update-page/scripts/update-page.ts +0 -640
  96. package/templates/.claude/skills/update-page/templates/redirects.mjs.tmpl +0 -31
  97. package/templates/.claude/skills/upgrade-plan/SKILL.md +0 -121
  98. package/templates/.claude/skills/upgrade-plan/references/options.md +0 -24
  99. package/templates/.claude/skills/upgrade-plan/scripts/upgrade-plan.ts +0 -527
  100. package/templates/apps/api/.ailk/inbox/2026-09-20T14-57-31.552Z-fallback-1789916251590-037e9005.json +0 -8
  101. package/templates/apps/api/.ailk/inbox/2026-09-20T14-57-33.840Z-fallback-1789916253842-b52659e9.json +0 -12
  102. package/templates/apps/api/.ailk/inbox/2026-09-20T14-57-33.844Z-fallback-1789916253845-6b266f8c.json +0 -12
  103. package/templates/apps/mcp/__tests__/lib/require-paid-tier.test.ts +0 -75
  104. package/templates/apps/mcp/src/lib/require-paid-tier.ts +0 -44
@@ -1,199 +0,0 @@
1
- ---
2
- name: fill-page
3
- description: Fill one existing page's section content from a category profile. Tier 1 writes realistic, labelled sample content for the category (a plumber's home page, say). Tier 2 asks the owner the profile's questions and writes the company's own first draft from their answers and `_site.mdx`. Use when the user says "fill this page", "fill the home page for a plumber", "write sample content for my services page", or "write my real copy from what I tell you". It never creates a page, never changes a page's section stack, and never edits `_site.mdx`.
4
- ---
5
-
6
- # fill-page
7
-
8
- Replace one page's `{brace}` instructions with content, reading the
9
- content from a **category profile** (`profiles/<slug>.yaml` beside this
10
- file). A profile is the data for one business type: the schema.org
11
- subtype, the typical offerings, the proof buyers expect, the buyer's own
12
- words, and the questions to ask the owner.
13
-
14
- Two tiers:
15
-
16
- | Tier | Source | Result | `placeholder` |
17
- | ---- | -------------------------------------------------------- | ------------------------------------------ | ------------- |
18
- | 1 | the profile | realistic sample content for the category | `true` |
19
- | 2 | `_site.mdx` + the owner's answers (`content/_intake.yaml`) | the company's own first draft | by the rule in Step 2.4 |
20
-
21
- `placeholder: true` in a page's frontmatter makes the site render a
22
- **PLACEHOLDER — REPLACE BEFORE LAUNCH** label at the top of the page.
23
- The label is for people. Structured data reaches agents without it, so
24
- tier-1 content must be safe to publish by itself (see the never-invent
25
- list).
26
-
27
- ## Inputs
28
-
29
- - **The page file** — `content/<locale>/<Type>/<slug>.mdx`. It must
30
- already exist; `add-page` creates pages.
31
- - **The page type** — the frontmatter `type`.
32
- - **The profile slug** — a file under `profiles/` (e.g. `plumbing`).
33
- Ask if the user did not name one. If there is no profile for their
34
- category, say so and stop.
35
- - **The tier** — 1 unless the user asks for their own copy.
36
-
37
- ## What never changes
38
-
39
- - The page's **section stack**: every section's `id` and `type`, in
40
- order. Never add, remove or reorder a section. The starter's manifest
41
- records each page's sections, and a changed stack fails its check.
42
- - Each section's **layout options** that are already present:
43
- `variant`, `columns`, `layout`, `initialOpen`, `size` and the like.
44
- They are the site's locked look.
45
- - Link targets (`href`) that are already present, except a link to a
46
- Service page, which follows that page's slug (Step 1.3).
47
- - `{/* … */}` comments in the MDX body.
48
- - `_site.mdx`. Identity strings (the company name) are read from it,
49
- never written to it.
50
-
51
- ## Never invent (tier 1)
52
-
53
- At tier 1, write none of these. Remove any you find in the page:
54
-
55
- - `price`, `priceCurrency`, `availability` or `stripe` — each feeds the
56
- schema.org `Offer` an agent quotes as the company's price.
57
- - A person's name or another company's name.
58
- - A phone number, a street address, or a licence or registration number.
59
- - A town, a county, or a distance: the service area is a company fact.
60
- - Testimonials: `author` is the literal `Sample customer`; no `company`,
61
- `rating` or `avatar`.
62
- - Statistics a reader would take as measured (a count of jobs, a years
63
- figure). Use the profile's `proof[]` labels as words, not numbers.
64
-
65
- The company name is the one identity string tier 1 may write, and it
66
- comes from `_site.mdx` `siteIdentity.name`.
67
-
68
- ## Step 0 — Read
69
-
70
- 1. Read `.ailk-site-manifest.json` at the site root, the site's roster
71
- of record: `modules` (the modules this site has) and `rows` (every
72
- route it carries). Add any module the `# Modules:` line of
73
- `architecture.yaml` names that `modules` does not — `create-ailk
74
- add-module` records a module it adds there; with no manifest, or none
75
- carrying `modules`, that line is the set. `level`, when present, never
76
- decides anything here.
77
-
78
- The page's `type` must render on this site: its **Module** in
79
- `../add-page/references/page-types.md` is in that set, or a row
80
- already renders it (`rows[].pageType` — a Free starter's `/meet/<slug>`
81
- `BookCall` placeholders). When it does not,
82
- say which module renders the type and which level carries it, point at
83
- the `upgrade-plan` skill, and stop. Never fill a page this site cannot
84
- render.
85
- 2. Read the profile: `profiles/<slug>.yaml`.
86
- 3. Read `content/_site.mdx` for `siteIdentity.name`.
87
- 4. Read the page file. Note its stack (`sections[].type` in order).
88
- 5. For each section type in the stack, read its data schema: the
89
- `<Type>SectionDataSchema` (or `<Type>DataSchema`) export in the
90
- installed `@working-theory/validation`'s `schemas/page-sections`. Fill
91
- only fields the schema declares. Every field a section renders from
92
- copy gets content; a field the source page did not use stays unused.
93
- 6. Find the route that renders this page type under `apps/web/app/[locale]/`
94
- and read its `bodyMode`. When it is `"mdx-body"`, the MDX body is
95
- rendered and must be filled too. Otherwise the body is a short note,
96
- and you rewrite it as one plain sentence that names no braces.
97
-
98
- `references/section-sources.md` maps each section type to the profile
99
- fields and intake answers that fill it.
100
-
101
- ## Step 1 — Tier 1: sample content
102
-
103
- 1. **Sections.** For each section, in place, write every copy field from
104
- the profile using `references/section-sources.md`:
105
- - offerings → `items` entries (`title` = the offering `name`,
106
- `description` = its `job`, `link.href` = `/services/<kebab name>`
107
- only when the manifest's `rows` carry `/services/[slug]`; otherwise
108
- no `link`, so no entry points at a page the site does not have);
109
- - vocabulary → headlines, eyebrows and FAQ questions (the buyer's own
110
- words: the `problem` list for what went wrong, `outcome` for what
111
- they get);
112
- - proof → `stats` labels and `testimonials` quotes, under the
113
- never-invent list.
114
- Keep `id`, `type` and every layout option.
115
- 2. **Frontmatter.** Rewrite `title` and `description` without braces.
116
- Use the company name from `_site.mdx` where the page names the
117
- company. On a page that carries `provider.name`, set it to the company
118
- name. Drop `schema.areaServed`; set `schema.serviceType` to the
119
- offering name. Remove every key the never-invent list names.
120
- 3. **Service pages.** A `Service` page is one offering. The user names
121
- the offering, or you take the first profile offering that no other
122
- Service page carries yet. Set `title` and `schema.serviceType` to the
123
- offering `name`, and `slug` and the file name to its name in kebab
124
- case (`Drain clearing` → `drain-clearing`): rename the file, never
125
- copy it. To give every offering a page, the user first adds one
126
- Service page per offering (`add-page`, or a copy of an existing one),
127
- then runs this skill on each.
128
- 4. **Body.** When the route renders `mdx-body`, rewrite each paragraph
129
- and list item under the page's existing headings in the category's
130
- words. Keep the headings, keep the order, keep the comments. Drop
131
- every `\{…\}` instruction. Under a price heading, say how the job is
132
- priced (the offering's `pricing`: `quote`, `fixed`, `hourly`,
133
- `subscription`) in words, with no figure.
134
- 5. **Label.** Set `placeholder: true` in the frontmatter.
135
- 6. **Check** (below).
136
-
137
- ## Step 2 — Tier 2: the company's own draft
138
-
139
- 1. **Ask.** Ask each `intake[]` question from the profile, in order, one
140
- at a time. Record the answers in `content/_intake.yaml`:
141
-
142
- ```yaml
143
- answers:
144
- offerings: [Drain clearing, Emergency call-out]
145
- service_area: "…"
146
- faq: null # unanswered
147
- ```
148
-
149
- A list answer stays a list. An unanswered or skipped question is
150
- `null`. Offerings are named exactly as the profile names them.
151
- 2. **Fill.** Fill the page as in Step 1, but from `_site.mdx` and the
152
- answers first; the profile fills only what the answers leave open.
153
- - A profile offering the owner does not offer appears on no page:
154
- remove its `items` entries, and ask before deleting its Service
155
- page (the one file this skill may delete).
156
- - A price appears only when the owner gave one, with `priceCurrency`.
157
- - The company name appears in each page's frontmatter (`title` or
158
- `description`), and the service area in the home hero when given.
159
- - A section whose sources have no answer keeps its tier-1 sample
160
- content.
161
- 3. **Never invent** still holds for everything the owner did not give.
162
- Testimonials stay `Sample customer` unless the owner supplies a
163
- customer's name with permission to publish it.
164
- 4. **Label.** Set `placeholder: false` only when every section is filled
165
- from company facts:
166
- - every section type in the stack appears in the `fills` of at least
167
- one intake item whose answer is not empty, and
168
- - when the stack has a `hero` or `cta`, `_site.mdx` has
169
- `siteIdentity.name`.
170
-
171
- A page with no sections is judged on its body: a `Service` page is
172
- cleared only when the `offerings` answer names its offering; any
173
- other page with no sections keeps `placeholder: true`. In every other
174
- case, keep `placeholder: true`.
175
- 5. **Check** (below).
176
-
177
- ## The check
178
-
179
- Run the site's own structured-data check. It reads every content page
180
- through the same frontmatter and section schemas the site renders with,
181
- and validates each page's JSON-LD:
182
-
183
- ```bash
184
- pnpm --filter web test -- lib/__tests__/structured-data.test.tsx
185
- ```
186
-
187
- Then search the filled file for a `{` or `}` in any frontmatter string or
188
- in the body outside `{/* … */}` comments. Fix everything either reports
189
- and run both again. Stop only when both are clean.
190
-
191
- ## What this skill does not do
192
-
193
- - Tier 3 (the Messaging Canvas through the content pipeline).
194
- - Create a page — use `add-page`.
195
- - Edit `_site.mdx`, the nav or the page roster. A profile's `roster` and
196
- `nav` entries are declared for a later step and are not applied here,
197
- and a profile page type this site cannot render (Step 0) is never
198
- suggested.
199
- - Write a price, a name or an address the owner did not give.
@@ -1,80 +0,0 @@
1
- # Category profile — Local Plumbing (#6640; starter-template contract § D).
2
- # Read by the `fill-page` skill: tier 1 fills a page with labelled sample
3
- # content from this file; tier 2 asks `intake[]` and fills from the answers.
4
- # Twin: templates/.claude/skills/fill-page/profiles/plumbing.yaml (byte-identical).
5
- slug: plumbing
6
- shape: local-business-service
7
- subtype: Plumber
8
- secondary: Person
9
- offerings:
10
- - name: Drain clearing
11
- job: Clears blocked sinks, showers, toilets and main drains, and says what caused the blockage.
12
- pricing: quote
13
- - name: Water heater installation
14
- job: Removes the old tank or boiler and fits, tests and registers a new water heater.
15
- pricing: fixed
16
- - name: Emergency call-out
17
- job: A plumber at the door the same day for a burst pipe, a flood or no water at all.
18
- pricing: hourly
19
- - name: Leak detection and repair
20
- job: Finds the hidden leak behind a wall or under a floor and fixes it with the least damage.
21
- pricing: quote
22
- proof:
23
- - kind: credential
24
- label: Licensed and insured
25
- - kind: reviews
26
- label: Reviews from local customers
27
- - kind: response-time
28
- label: Same-day response on emergency calls
29
- - kind: guarantee
30
- label: Workmanship guaranteed
31
- vocabulary:
32
- problem:
33
- - burst pipe
34
- - blocked drain
35
- - no hot water
36
- - leaking tap
37
- - low water pressure
38
- - water stain on the ceiling
39
- service:
40
- - drain clearing
41
- - water heater install
42
- - emergency call-out
43
- - leak repair
44
- - pipe replacement
45
- outcome:
46
- - same-day fix
47
- - hot water back on
48
- - no water damage
49
- - upfront quote
50
- - tidy job, nothing left behind
51
- roster:
52
- - op: add
53
- route: /meet/emergency
54
- pageType: BookCall
55
- reason: Emergency jobs book a call, not a form.
56
- - op: drop
57
- route: /pricing
58
- reason: Most plumbing work is quote-priced, so a price table misleads.
59
- nav:
60
- Services: Plumbing services
61
- content_posture: sample
62
- intake:
63
- - id: offerings
64
- ask: Which of these jobs do you take on, and is there one you do not list? (Drain clearing, water heater installation, emergency call-out, leak detection and repair.)
65
- fills: [hero, items]
66
- - id: service_area
67
- ask: Which towns, postcodes or radius do you cover?
68
- fills: [hero, cta]
69
- - id: about
70
- ask: How did the business start, who does the work, and what will you not take on?
71
- fills: [content-block]
72
- - id: proof
73
- ask: What can a customer check — your licence, your insurance, your reviews, your response time, your guarantee?
74
- fills: [stats, testimonials, social-proof]
75
- - id: faq
76
- ask: What do customers ask before they book, and what do you tell them?
77
- fills: [faq]
78
- - id: contact
79
- ask: How should a customer reach you — phone, form or booking — and how fast do you reply?
80
- fills: [cta]
@@ -1,41 +0,0 @@
1
- # Section sources
2
-
3
- Where each section's copy comes from. **Profile** is tier 1's source;
4
- **Intake** lists the `intake[]` answers that fill the section at tier 2
5
- (the same ids appear in each question's `fills`). Fields not named here
6
- are layout options: keep them as they are.
7
-
8
- | Section type | Copy fields | Profile (tier 1) | Intake (tier 2) |
9
- | --------------- | --------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | ---------------------------------------- |
10
- | `hero` | `eyebrow`, `headline`, `subheadline`, `primaryCta.label`, `secondaryCta.label` | `vocabulary.problem` + `vocabulary.outcome` for the headline; the category name for the eyebrow | `offerings`, `service_area` |
11
- | `items` | `headline`, `description`, `items[].title`, `items[].description`, `items[].link` | one item per `offerings[]` entry: `title` = `name`, `description` = `job`, `link.href` = `/services/<kebab name>` | `offerings` |
12
- | `cta` | `headline`, `description`, `primaryCta.label`, `secondaryCta.label` | `vocabulary.outcome` | `service_area`, `contact` |
13
- | `content-block` | `eyebrow`, `headline`, `body` | `proof[].label` and `vocabulary.service`, with no names, places or numbers | `about` |
14
- | `faq` | `headline`, `items[].question`, `items[].answer` | questions in `vocabulary.problem` words; answers from `offerings[].pricing` and `proof[]` | `faq` |
15
- | `stats` | `headline`, `items[].label`, `items[].value` | `proof[].label` as the label; a value only when it is not a measurement (e.g. `Same day`) | `proof` |
16
- | `testimonials` | `headline`, `items[].quote`, `items[].author` | quotes in `vocabulary.outcome` words; `author: Sample customer`; no `company`, `rating` or `avatar` | `proof` |
17
- | `social-proof` | `headline`, labels | `proof[].label` | `proof` |
18
-
19
- A section type not in this table: fill its copy fields from the profile's
20
- `vocabulary` and leave its data otherwise as it was. At tier 2 no intake
21
- answer fills it, so a page carrying it keeps `placeholder: true`.
22
-
23
- ## Frontmatter
24
-
25
- | Key | Tier 1 | Tier 2 |
26
- | ---------------------- | -------------------------------------------------- | ------------------------------------------- |
27
- | `title`, `description` | the category's words; the company name from `_site.mdx` where the page names the company | the company name and the owner's answers |
28
- | `provider.name` | `siteIdentity.name` | `siteIdentity.name` |
29
- | `schema.serviceType` | the offering `name` | the offering `name` |
30
- | `schema.areaServed` | removed | the `service_area` answer |
31
- | `price`, `priceCurrency`, `availability`, `stripe` | removed | only a price the owner gave, with its currency |
32
- | `placeholder` | `true` | by the rule in `SKILL.md` Step 2.4 |
33
-
34
- ## Pricing words (Service bodies, FAQ answers)
35
-
36
- | `pricing` | Say |
37
- | -------------- | ------------------------------------------------------------------- |
38
- | `quote` | priced after a look at the job; the quote is given before work starts |
39
- | `fixed` | one fixed price for the job, agreed before work starts |
40
- | `hourly` | charged by the hour on site, with the call-out rate stated up front |
41
- | `subscription` | a regular plan, billed on a schedule |
@@ -1,156 +0,0 @@
1
- ---
2
- name: setup-database
3
- description: Take this site from no database to a working lead inbox — provision Postgres, set the connection variables, create the tables, pin the owner, and prove it with one test message that must appear in the inbox. Use when the user asks "set up the database", "I want a lead inbox", "keep my leads", "collect newsletter signups", "connect Postgres", or when setup-deploy points here. Confirms before every write and never prints a connection string.
4
- ---
5
-
6
- # setup-database
7
-
8
- A new site needs no database: contact-form messages are emailed to the
9
- owner (when the email key is set). A database turns on the **lead inbox**
10
- — every message kept at `/leads`, reviewed signed in — and newsletter
11
- signups. This skill takes the site from no database to that inbox, and
12
- does not call it done until one test message is in it.
13
-
14
- ## When to use
15
-
16
- - "set up the database" / "connect Postgres"
17
- - "I want a lead inbox" / "keep every message"
18
- - "collect newsletter signups"
19
- - `setup-deploy` pointed here from its lead-delivery step
20
-
21
- Skip it when the site only needs messages by email — that is
22
- `setup-deploy`'s email key, no database required.
23
-
24
- ## Rules for every step
25
-
26
- - **Confirm before every write.** Say what file or command is next and
27
- wait for a yes.
28
- - **Never echo a connection string.** A database URL contains a
29
- password. Refer to it as "your `DATABASE_URL`", never print it, never
30
- commit it. It goes in `.env.local` (gitignored) and the hosting
31
- dashboards only.
32
- - **Stop on the first failure** and say which step failed and why
33
- (see "When a step fails"). Never skip ahead.
34
-
35
- ## The mechanic
36
-
37
- ### Step 1 — Detect
38
-
39
- Look for `DATABASE_URL` in `.env.local`, then `.env`. If it is already
40
- set, say so (without printing it) and go to Step 4.
41
-
42
- ### Step 2 — Provision Postgres
43
-
44
- Ask which Postgres the owner wants. Any provider that gives a **pooled**
45
- and a **direct** connection URL works (Neon, Supabase, Railway, RDS, …).
46
- For local work, the one command in `README.md` § "When you need a
47
- database":
48
-
49
- ```bash
50
- docker run --name ailk-postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres:17
51
- ```
52
-
53
- The owner pastes the two URLs. Write them to `.env.local` only:
54
-
55
- ```bash
56
- DATABASE_URL=<pooled URL>
57
- DATABASE_URL_NON_POOLED=<direct URL>
58
- ```
59
-
60
- (Local Docker: the same URL for both.) Then tell the owner to add the
61
- same two variables to **both** hosting projects — the API's (it stores
62
- the leads) and the web app's (sign-in reads the database). Placeholders
63
- only in any file you show; the real values go in each dashboard.
64
-
65
- ### Step 3 — Create the tables, then the default workspace
66
-
67
- ```bash
68
- pnpm db:migrate:deploy
69
- ```
70
-
71
- ```bash
72
- pnpm db:seed
73
- ```
74
-
75
- The seed creates the default Organization and Workspace every lead is
76
- filed under. Without it the API answers `503 tenant_unresolved` to every
77
- submission.
78
-
79
- ### Step 4 — Pin the owner, and make sure they can sign in
80
-
81
- The inbox shows leads only to the site's pinned owner. Ask for the
82
- email address the owner signs in with and set it — in `.env.local`, and
83
- on the API project's dashboard:
84
-
85
- ```bash
86
- AILK_OPERATOR_EMAIL=you@your-domain.com
87
- ```
88
-
89
- The owner must sign in with that address, and it must be verified by
90
- the sign-in provider. If no sign-in provider is configured yet, hand off
91
- to the `add-auth` skill now — the inbox is behind sign-in — and come
92
- back to Step 5 when it is done.
93
-
94
- ### Step 5 — Send one test message
95
-
96
- Make a nonce (for example `setup-database 3f9c2a`, a few random
97
- characters) and submit a lead to the running API (`pnpm dev` locally,
98
- or the deployed API's URL):
99
-
100
- ```bash
101
- curl -sS -X POST <api>/v1/leads/submit \
102
- -H 'content-type: application/json' \
103
- -d '{"source":"web","email":"<owner email>","payload":{"name":"setup-database test","message":"<nonce>"}}'
104
- ```
105
-
106
- It must answer **`201`** with `"persisted": "db"`. Anything else is a
107
- failed step (see below).
108
-
109
- ### Step 6 — Verify it is in the inbox
110
-
111
- Build the database package once (its `./tenancy` export resolves to
112
- `dist/`), then read the inbox with the inbox's own rule — the default
113
- workspace, newest first, the first page of 50:
114
-
115
- ```bash
116
- pnpm --filter @working-theory/database build
117
- pnpm --filter @working-theory/database exec tsx ../.claude/skills/setup-database/scripts/verify-inbox.ts "<nonce>"
118
- ```
119
-
120
- It prints `found in inbox` and exits 0 only when the test lead is on
121
- that page. Then ask the owner to open `/leads`, signed in as the pinned
122
- email, and confirm they see the "setup-database test" row.
123
-
124
- Do not report the database as set up until verify-inbox.ts exits 0.
125
-
126
- ## When a step fails
127
-
128
- Say which step failed and the likely cause — never "done":
129
-
130
- | Symptom | Likely cause |
131
- | ------------------------------------------- | ---------------------------------------------------------------------------------------------- |
132
- | `db:migrate:deploy` cannot connect | wrong `DATABASE_URL_NON_POOLED`, or the database is not reachable from here |
133
- | submit answers `503 tenant_unresolved` (or, with `CONTENT_ADAPTER=database`, the API refuses to start) | Step 3's `pnpm db:seed` did not run |
134
- | submit answers `201` with `persisted` ≠ `db` | the API process does not see `DATABASE_URL` — restart it, or set it on the API project |
135
- | verify-inbox exits 1 | the lead landed under another workspace, or 50 newer leads push it off the first page |
136
- | `/leads` is empty but verify passed | `AILK_OPERATOR_EMAIL` unset, a different or unverified sign-in email, or more than one workspace |
137
-
138
- ## What this skill does not do
139
-
140
- - Call a database vendor's API. The owner provisions; the skill walks
141
- them through it.
142
- - Print, log or commit a connection string.
143
- - Change application code. The API switches to the inbox by itself once
144
- `DATABASE_URL` is set.
145
-
146
- ## Coordination
147
-
148
- - **`setup-deploy`** — its lead-delivery step points here, and its
149
- `RUNBOOK.md` names this skill as the **Lead inbox** path.
150
- - **`add-auth`** — the inbox is behind sign-in; Step 4 hands off to it
151
- when no provider is configured.
152
-
153
- ## Files
154
-
155
- - `scripts/verify-inbox.ts` — Step 6's read. Exports `findInInbox`
156
- (pure, takes an injected Prisma-shaped client) and a thin `main()`.
@@ -1,154 +0,0 @@
1
- /**
2
- * verify-inbox — the last step of the `setup-database` skill.
3
- *
4
- * Proves the test lead the skill just submitted is in the lead inbox, by
5
- * reading with the inbox's own predicate: `Lead.siteId` = the default
6
- * workspace id, newest first, the first page of 50 — exactly what `/leads`
7
- * shows. A lead that exists somewhere else in the table does not count.
8
- *
9
- * Run inside the scaffold's `database` workspace, which owns the Prisma client
10
- * and its driver adapter. The script's own imports resolve from the WORKING
11
- * directory (`resolveFromWorkspace`), not from where this file sits — the
12
- * scaffold root depends on neither package. Build it first — the `./tenancy`
13
- * export resolves to `dist/`:
14
- *
15
- * pnpm --filter @working-theory/database build
16
- * pnpm --filter @working-theory/database exec tsx ../.claude/skills/setup-database/scripts/verify-inbox.ts <nonce>
17
- *
18
- * Exit 0, printing `found in inbox`, only when the nonce's lead is on that
19
- * page. Exit 1 when it is not; exit 2 on a usage error. Reads only — writes
20
- * nothing, and prints no lead field but the match.
21
- */
22
-
23
- import { createRequire } from "node:module";
24
- import { join } from "node:path";
25
- import { pathToFileURL } from "node:url";
26
-
27
- /**
28
- * Import `specifier` as the package at `cwd` sees it. A bare `import()` here
29
- * would resolve from this file's own directory (`.claude/skills/…`), where
30
- * the scaffold installs neither `@working-theory/database` nor its adapter;
31
- * resolving against `<cwd>/package.json` finds the `database` workspace's own
32
- * dependencies and its self-reference.
33
- */
34
- export function resolveFromWorkspace(specifier: string, cwd: string = process.cwd()): string {
35
- return createRequire(join(cwd, "package.json")).resolve(specifier);
36
- }
37
-
38
- async function importFromWorkspace<T>(specifier: string): Promise<T> {
39
- return (await import(pathToFileURL(resolveFromWorkspace(specifier)).href)) as T;
40
- }
41
-
42
- /** The inbox's first page (`GET /v1/leads`'s default `limit`). */
43
- export const INBOX_PAGE_SIZE = 50;
44
-
45
- interface LeadRow {
46
- id: string;
47
- payload: unknown;
48
- }
49
-
50
- /** The one Prisma call this script makes — injected, so it is testable without a database. */
51
- export interface InboxReader {
52
- lead: {
53
- findMany(args: {
54
- where: { siteId: string };
55
- orderBy: Array<Record<string, "desc">>;
56
- take: number;
57
- select: { id: true; payload: true };
58
- }): Promise<LeadRow[]>;
59
- };
60
- }
61
-
62
- function carriesNonce(payload: unknown, nonce: string): boolean {
63
- if (typeof payload !== "object" || payload === null) return false;
64
- const message = (payload as Record<string, unknown>)["message"];
65
- return typeof message === "string" && message.includes(nonce);
66
- }
67
-
68
- /** Whether the lead whose message carries `nonce` is on the inbox's first page. */
69
- export async function findInInbox(
70
- db: InboxReader,
71
- { workspaceId, nonce }: { workspaceId: string; nonce: string },
72
- ): Promise<boolean> {
73
- const page = await db.lead.findMany({
74
- where: { siteId: workspaceId },
75
- orderBy: [{ createdAt: "desc" }, { id: "desc" }],
76
- take: INBOX_PAGE_SIZE,
77
- select: { id: true, payload: true },
78
- });
79
- return page.some((row) => carriesNonce(row.payload, nonce));
80
- }
81
-
82
- /** `findInInbox` as a process result: 0 + `found in inbox`, or 1 + the reason. */
83
- export async function verifyInbox(
84
- db: InboxReader,
85
- args: { workspaceId: string; nonce: string },
86
- out: (line: string) => void = (line) => process.stdout.write(`${line}\n`),
87
- ): Promise<0 | 1> {
88
- if (await findInInbox(db, args)) {
89
- out("found in inbox");
90
- return 0;
91
- }
92
- out(
93
- "not in inbox: no lead carrying this nonce is on the default workspace's first page. " +
94
- "Check that `pnpm db:seed` ran (else the API answers tenant_unresolved) and that " +
95
- "the test submission returned 201 with persisted \"db\".",
96
- );
97
- return 1;
98
- }
99
-
100
- async function main(argv: string[]): Promise<number> {
101
- const nonce = argv[0];
102
- if (!nonce) {
103
- process.stderr.write("usage: verify-inbox.ts <nonce>\n");
104
- return 2;
105
- }
106
- // DATABASE_URL lives in the scaffold root's `.env.local` (setup-database
107
- // writes it there); this runs from `database/`, one level down.
108
- for (const file of ["../.env.local", "../.env"]) {
109
- if (process.env.DATABASE_URL) break;
110
- try {
111
- process.loadEnvFile(file);
112
- } catch {
113
- // absent — try the next one
114
- }
115
- }
116
- if (!process.env.DATABASE_URL) {
117
- process.stderr.write("verify-inbox: DATABASE_URL is not set (.env.local)\n");
118
- return 1;
119
- }
120
- // Resolved inside the scaffold's `database` workspace (see the header).
121
- // Prisma 7 needs an explicit driver adapter, as `database/seed.ts` does.
122
- const [{ PrismaClient }, { PrismaPg }, { DEFAULT_WORKSPACE_ID }] = await Promise.all([
123
- importFromWorkspace<{
124
- PrismaClient: new (opts: { adapter: unknown }) => InboxReader & {
125
- $disconnect(): Promise<void>;
126
- };
127
- }>("@working-theory/database"),
128
- importFromWorkspace<{ PrismaPg: new (opts: { connectionString: string }) => unknown }>(
129
- "@prisma/adapter-pg",
130
- ),
131
- importFromWorkspace<{ DEFAULT_WORKSPACE_ID: string }>("@working-theory/database/tenancy"),
132
- ]);
133
- const prisma = new PrismaClient({
134
- adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL }),
135
- });
136
- try {
137
- return await verifyInbox(prisma, {
138
- workspaceId: DEFAULT_WORKSPACE_ID,
139
- nonce,
140
- });
141
- } finally {
142
- await prisma.$disconnect();
143
- }
144
- }
145
-
146
- if (/verify-inbox\.ts$/.test(process.argv[1] ?? "")) {
147
- main(process.argv.slice(2)).then(
148
- (code) => process.exit(code),
149
- (err: unknown) => {
150
- process.stderr.write(`verify-inbox: ${err instanceof Error ? err.message : String(err)}\n`);
151
- process.exit(1);
152
- },
153
- );
154
- }