From e15331eedca86fd07a13a08621ef45da87a52abd Mon Sep 17 00:00:00 2001 From: Jack Herrington Date: Sun, 29 Nov 2026 12:01:22 -0800 Subject: [PATCH 1/3] feat(kody): seed the headless-api starter so a fresh store isn't empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds src/seed.ts (one published contentItem) wired into defineCms, for spec §8 ("seeded document readable"). Validated by local-smoke.mts against a fresh Postgres — the seeded doc is present on first registration. Granting public (no-auth) read on contentItem remains a go-day item. Co-Authored-By: Claude Opus 4.8 (1M context) --- kody/headless-api/GO-DAY.md | 7 ++++--- kody/headless-api/scripts/local-smoke.mts | 11 +++++++++++ kody/headless-api/src/cms.config.ts | 2 ++ kody/headless-api/src/seed.ts | 19 +++++++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 kody/headless-api/src/seed.ts diff --git a/kody/headless-api/GO-DAY.md b/kody/headless-api/GO-DAY.md index 7a56619d..ebe7b4a6 100644 --- a/kody/headless-api/GO-DAY.md +++ b/kody/headless-api/GO-DAY.md @@ -35,6 +35,7 @@ remains is only what requires the external blockers to clear. `x-cms-role` write succeeds and is attributed; MCP tool list answers; a second package importing `@tanstack/cms-client` reads the same document. -> Note: the §8 "seeded document readable with **no auth**" check needs a seed + -> public read access — not yet added here (the smoke uses authenticated writes). -> Add a small `seed` and confirm anonymous read on go-day. +> Note: the §8 "seeded document readable with **no auth**" check — the `seed` is +> now in place (`src/seed.ts`, validated by the smoke). What remains is granting +> **public (anonymous) read access** on `contentItem` so the seeded doc is +> readable over REST with no `x-cms-role` header; confirm on go-day. diff --git a/kody/headless-api/scripts/local-smoke.mts b/kody/headless-api/scripts/local-smoke.mts index 27e684af..795c6462 100644 --- a/kody/headless-api/scripts/local-smoke.mts +++ b/kody/headless-api/scripts/local-smoke.mts @@ -35,6 +35,17 @@ async function post(op: string, role: string, body: unknown) { ) } +// 0. Seed: a fresh store is seeded on first registration (spec §8). +await entry.fetch(new Request(`${ops}/noop`, { method: 'GET' })).catch(() => {}) +const seeded = + (await getAs(systemContext('smoke'), { + collection: 'contentItem', + id: 'welcome', + staged: false, + populate: false, + }))?.doc ?? null +check('seed document present on fresh store', seeded?.title === 'Welcome', seeded) + // 1. Editor stages a write over REST (header-role auth) through the fetch entry. const writeRes = await post('save_document', 'editor', { collection: 'contentItem', diff --git a/kody/headless-api/src/cms.config.ts b/kody/headless-api/src/cms.config.ts index fe8024ef..d941388a 100644 --- a/kody/headless-api/src/cms.config.ts +++ b/kody/headless-api/src/cms.config.ts @@ -3,6 +3,7 @@ import type { CmsConfig } from '@tanstack/cms-core' import { createPostgresStorage } from '@tanstack/cms-store-postgres' import { definition } from './cms.definition' import { getDatabaseUrl } from './secrets' +import { seed } from './seed' // Kody variant of starters/headless-api. Differences from the monorepo starter // (spec §3.1): no `dataDir`/embedded storage — external Postgres via the @@ -22,6 +23,7 @@ export function registerHeadlessCms() { return defineCms(definition, { blockTypes: [], auth, + seed, // `connectionString` accepts a resolver, so the secret stays out of the // build and is read at connect time (store-postgres types.ts:85). storage: createPostgresStorage({ diff --git a/kody/headless-api/src/seed.ts b/kody/headless-api/src/seed.ts new file mode 100644 index 00000000..d745e5a7 --- /dev/null +++ b/kody/headless-api/src/seed.ts @@ -0,0 +1,19 @@ +import type { SeedStore } from '@tanstack/cms-core' + +// Content written on first run against an empty store, so a freshly-published +// app isn't empty (spec §8). Published so it is live immediately. Public (no +// auth) read access is still a go-day item — see GO-DAY.md. +export const seed: SeedStore = { + documents: { + contentItem: { + welcome: { + title: 'Welcome', + slug: 'welcome', + channel: 'web', + priority: 1, + body: 'This headless CMS serves one schema over REST, a typed client, and MCP.', + published: true, + }, + }, + }, +} From df3460a377435fe67fe67d0a82c223071ec2ac89 Mon Sep 17 00:00:00 2001 From: Jack Herrington Date: Sun, 29 Nov 2026 16:31:49 -0800 Subject: [PATCH 2/3] fix(kody): correct kody.jobs schedule schema; record kody dev findings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Validated the headless-api package under `kody dev` (local workerd). Results: - The CMS graph bundles + boots under workerd; the `{ fetch }` entry serves (CMS 404 on `/`). Biggest unknown (workerd-compat) resolved. - kody dev validated the `kody.jobs` schema: schedule must be an object `{ type: "interval", every: "5m" }` (or cron), not a bare string. Fixed. - U2 confirmed locally: a DB request fails under workerd with `No such module "pg"` — the stock pg driver doesn't load; Neon's serverless driver behind the store's PgPoolLike interface is the (config-side) fix. - `kody dev` must run from a standalone checkout; nested in the monorepo it fails the snapshot with a misleading "bundle target(s) missing" error. GO-DAY.md and AGENTS.md updated with all of the above. Co-Authored-By: Claude Opus 4.8 (1M context) --- kody/headless-api/AGENTS.md | 17 ++++++--- kody/headless-api/GO-DAY.md | 69 +++++++++++++++++++++------------- kody/headless-api/package.json | 4 +- 3 files changed, 56 insertions(+), 34 deletions(-) diff --git a/kody/headless-api/AGENTS.md b/kody/headless-api/AGENTS.md index 157c246b..5c82718c 100644 --- a/kody/headless-api/AGENTS.md +++ b/kody/headless-api/AGENTS.md @@ -45,11 +45,16 @@ write; `GET` reads it back after approval; `POST /api/mcp` lists tools. `viewer` is denied (403). API-key/token issuance (`createApiKey`) is a separate path. - **Writes stage into governance** — they are invisible until `approve()`. -- **`kody.jobs` field schema is best-effort** (`entry` + cron `schedule`). - Confirm exact field names with `repoRunChecks` / the jobs guide on go-day; - the handlers themselves are verified. -- **`pg` over workerd TCP is unproven (U2).** If egress fails on Kody, swap the - pool for a Neon serverless driver — config-side only, because the store types - `PgPoolLike` as a structural interface (no package change). +- **`kody.jobs` schema is confirmed** (validated by `kody dev`): `entry: + "./src/jobs.ts#"`, `schedule: { "type": "interval", "every": "5m" }` (or + `{ "type": "cron", "expression": "<5-field>" }`). Bare cron strings and + `type: "once"` are rejected. +- **`pg` does NOT load under Kody workerd (U2, confirmed via `kody dev`):** + a DB request fails with `No such module "pg"`. Swap the pool for Neon's + serverless driver behind the store's `PgPoolLike` interface — config-side + only, no store-postgres change. Everything else bundles + runs under workerd. +- **Run `kody dev` from a standalone checkout, not nested in the monorepo** — + nesting fails the snapshot with a misleading `bundle target(s) missing` error. + See GO-DAY.md. - `node_modules/` here is local symlink scaffolding for the smoke only; the real deps resolve from the pkg-pr-new URLs in `package.json` on Kody. diff --git a/kody/headless-api/GO-DAY.md b/kody/headless-api/GO-DAY.md index ebe7b4a6..903d0a9f 100644 --- a/kody/headless-api/GO-DAY.md +++ b/kody/headless-api/GO-DAY.md @@ -1,41 +1,58 @@ # Go-day deltas — headless-api -Everything in this package is built and **locally validated** (real Postgres, -`scripts/local-smoke.mts` → SMOKE PASS) against the workspace packages. What -remains is only what requires the external blockers to clear. +Built and validated two ways: (1) node + real Postgres via +`scripts/local-smoke.mts` → SMOKE PASS (CMS logic, auth, governance, jobs); +(2) **`kody dev` (local workerd)** — see "What kody dev proved" below. + +## What `kody dev` already proved (local workerd, no publish) + +- ✅ **The CMS graph bundles and boots under workerd** (same esbuild path as + publish). The `{ fetch }` entry loads and the CMS API handler serves — `GET /` + returns the CMS's own `404 {"code":"NOT_FOUND"}`. +- ✅ **`kody.jobs` manifest schema confirmed** (kody dev validated it): + `"schedule": { "type": "interval", "every": "5m" }` (or + `{ "type": "cron", "expression": "<5-field>" }`), `entry: + "./src/jobs.ts#"`. A bare cron string and `schedule.type: "once"` are + rejected. +- ⚠️ **U2 answer (local):** the first DB-touching request fails under workerd + with **`Error: No such module "pg"`** during `migrateTo`. The stock `pg` + driver does not load under Kody workerd. Everything upstream of the DB works. + +## Must run `kody dev` from a STANDALONE checkout + +`kody dev` snapshots the package via its git repo. Run inside this monorepo it +fails with `Package bundle target(s) missing from the repo session snapshot: +src/jobs.ts#...` — a **nesting artifact, not a real error**. In a standalone +git repo (how the go-day git lane works) the same files build cleanly. For local +iteration, copy the package to its own dir + `git init` (see the scratch at +`/tmp/kody-standalone` used during the spike), with `node_modules/@tanstack/*` +symlinked to the workspace packages and `node_modules/pg` to the pnpm store. ## Blocked until the Preview builds land 1. **Pin dependency URLs.** Replace `@REF` in `package.json` for the four - `@tanstack/cms-*` deps with the pkg-pr-new refs the Preview CI job reports - (spec §7-1). `pg` stays an npm dep. + `@tanstack/cms-*` deps with the pkg-pr-new refs. `pg` stays declared. ## Blocked on Kody (App install + `package:write` in the tanstack org) -2. **Publish via the git lane** (D3): `packageGetGitRemote({ create: true, - name: '@tanstack/cms-starter-headless-api' })` → clone → copy this package in - → push → `packagePublishExternalPush`. If it returns `locked`, open the - `approval_url`. -3. **Set the `CMS_DATABASE_URL` package secret** to the prod Postgres string. -4. **Resolve U1 (secret accessor).** Fill `src/secrets.ts#getDatabaseUrl` with - the synchronous `kody:runtime` package-secret read. Confirm whether the value - is available synchronously at module scope; if only request-scoped, capture - it into the module cache on the first request (the resolver is sync by - design — store types.ts:85). -5. **Confirm `kody.jobs` field schema** via `repoRunChecks` (the manifest - validator). Current best-effort shape: `{ entry: "./src/jobs.ts#", - schedule: "*/5 * * * *" }`. -6. **Run U2 test** (spec §7-5): the first REST call on the published app is the - pg-over-workerd-TCP test. If egress fails, swap the pool for Neon's serverless - driver — config-side only (`PgPoolLike` is a structural interface). +2. **Resolve U2 — swap `pg` for a workerd-native driver.** Confirmed required + (above). Use Neon's serverless driver behind the store's `PgPoolLike` + interface — config-side only, no store-postgres change (the store types the + pool structurally). Then re-run `kody dev` against a reachable Postgres and + confirm a DB-backed request + a job succeed. +3. **Resolve U1 — secret accessor.** Fill `src/secrets.ts#getDatabaseUrl` with a + synchronous `kody:runtime` package-secret read. NB under `kody dev --target + mock` package secrets are **placeholders** by design, so a real DB URL can't + flow through them locally — test U1 against the published app or with a + `.kody/mocks.ts`-style stand-in. +4. **Publish via the git lane** (D3) and set the `CMS_DATABASE_URL` package + secret. +5. **Public read for §8.** Grant anonymous read on `contentItem` so the seeded + doc is readable over REST with no `x-cms-role` header (the `seed` itself is + in place and validated). ## Post-publish acceptance (spec §8) `appFetch` (`synthetic: true`): seeded doc readable over REST with no auth; `x-cms-role` write succeeds and is attributed; MCP tool list answers; a second package importing `@tanstack/cms-client` reads the same document. - -> Note: the §8 "seeded document readable with **no auth**" check — the `seed` is -> now in place (`src/seed.ts`, validated by the smoke). What remains is granting -> **public (anonymous) read access** on `contentItem` so the seeded doc is -> readable over REST with no `x-cms-role` header; confirm on go-day. diff --git a/kody/headless-api/package.json b/kody/headless-api/package.json index 0135b714..06776d39 100644 --- a/kody/headless-api/package.json +++ b/kody/headless-api/package.json @@ -29,11 +29,11 @@ "jobs": { "cms-outbox-drain": { "entry": "./src/jobs.ts#outboxDrain", - "schedule": "*/5 * * * *" + "schedule": { "type": "interval", "every": "5m" } }, "cms-scheduler-tick": { "entry": "./src/jobs.ts#schedulerTick", - "schedule": "*/5 * * * *" + "schedule": { "type": "interval", "every": "5m" } } } } From bae81d226e2262649afe83b0c2f2785cf909834d Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 3 Dec 2026 16:11:19 +0000 Subject: [PATCH 3/3] ci: apply automated fixes --- kody/headless-api/package.json | 10 ++++++++-- kody/headless-api/scripts/local-smoke.mts | 20 +++++++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/kody/headless-api/package.json b/kody/headless-api/package.json index 06776d39..a230aece 100644 --- a/kody/headless-api/package.json +++ b/kody/headless-api/package.json @@ -29,11 +29,17 @@ "jobs": { "cms-outbox-drain": { "entry": "./src/jobs.ts#outboxDrain", - "schedule": { "type": "interval", "every": "5m" } + "schedule": { + "type": "interval", + "every": "5m" + } }, "cms-scheduler-tick": { "entry": "./src/jobs.ts#schedulerTick", - "schedule": { "type": "interval", "every": "5m" } + "schedule": { + "type": "interval", + "every": "5m" + } } } } diff --git a/kody/headless-api/scripts/local-smoke.mts b/kody/headless-api/scripts/local-smoke.mts index 795c6462..8bd6288c 100644 --- a/kody/headless-api/scripts/local-smoke.mts +++ b/kody/headless-api/scripts/local-smoke.mts @@ -38,13 +38,19 @@ async function post(op: string, role: string, body: unknown) { // 0. Seed: a fresh store is seeded on first registration (spec §8). await entry.fetch(new Request(`${ops}/noop`, { method: 'GET' })).catch(() => {}) const seeded = - (await getAs(systemContext('smoke'), { - collection: 'contentItem', - id: 'welcome', - staged: false, - populate: false, - }))?.doc ?? null -check('seed document present on fresh store', seeded?.title === 'Welcome', seeded) + ( + await getAs(systemContext('smoke'), { + collection: 'contentItem', + id: 'welcome', + staged: false, + populate: false, + }) + )?.doc ?? null +check( + 'seed document present on fresh store', + seeded?.title === 'Welcome', + seeded, +) // 1. Editor stages a write over REST (header-role auth) through the fetch entry. const writeRes = await post('save_document', 'editor', {