create-ailk 0.43.0 → 0.44.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.
@@ -12,16 +12,16 @@
12
12
  * origin and the workspace, which is all the topology would decide.
13
13
  *
14
14
  * A dry run is the default (D3): the importer runs over `readOnlyFetch`, which
15
- * passes each `GET` through and answers a `POST`, `PATCH` or `PUT` locally
16
- * without sending it, so the plan — create · update · unchanged · skipped · failed — is
15
+ * passes each `GET` through and answers a `PUT` or `POST` locally without
16
+ * sending it, so the plan — create · update · unchanged · skipped · failed — is
17
17
  * decided by the importer itself against the live workspace, and no write can
18
18
  * leave the process. `--apply` writes; a second `--apply` reports every page
19
19
  * `unchanged`.
20
20
  *
21
- * Every page carries the hub's live-source mark (#10898 D5): its words already
22
- * ship on a live site, so the template's missing headings are advisory, not a
23
- * reason publish refuses it. The dry run prints, per planned page, whether
24
- * publish will take it and which headings the hub will list (D6).
21
+ * No page carries the hub's live-source mark (#11843 D7): `save_page` never
22
+ * keeps it, so a template's missing heading is blocking, as on any page. The
23
+ * dry run prints, per planned page, whether publish will take it and what the
24
+ * hub will list (#10898 D6), computed as publish will compute it.
25
25
  *
26
26
  * Credentials follow `seed-workspace` (#10204 D2): the origin from
27
27
  * `--api-url`, else `AILK_API_URL`; the workspace id from `--workspace`, else
@@ -34,7 +34,7 @@
34
34
  */
35
35
  import { readFileSync } from "node:fs";
36
36
  import { join, resolve } from "node:path";
37
- import { isDeepStrictEqual, parseArgs } from "node:util";
37
+ import { parseArgs } from "node:util";
38
38
  import { languageLines, languageOffLine, seedTopics, seedTopicsOf, topicSeedLines, withLanguage, } from "./language-import.js";
39
39
  import { formatImportMdxReport, importMdx, isDirectory, loadSiteMdxAdapter, outcomePath, } from "./lib/import-mdx.js";
40
40
  import { ParseError } from "./parse-args.js";
@@ -60,69 +60,33 @@ function given(value) {
60
60
  }
61
61
  // ── The dry run's transport (D3) ────────────────────────────────────────────
62
62
  /**
63
- * A fetch that sends `GET`s through `inner` and never sends a write: a `POST`
64
- * is answered `201` and a `PATCH` `200` locally, with the one member of a
65
- * write's answer `importMdx` reads (`data.locale`), and the structure write's
66
- * `PUT` (#10534) `200`. Any other method throws.
67
- *
68
- * The `PUT` answers `data.written` from the layout the hub's draft read
69
- * returned (#11749 D4): each 200 `GET`'s `data.structure` is kept per page
70
- * address, and a `PUT` to that address's `/structure` URL answers
71
- * `written: true` when its body's `structure` is not `isDeepStrictEqual` to
72
- * it — the hub's own comparison. Any other `PUT` (an equal layout, an address
73
- * never read, a read with no `structure` member, no string body, a `Request`
74
- * input) answers `written: false`. It never answers 409: a live tip with a
75
- * changed layout is planned `update`, what `--apply` reports after its
76
- * re-draft. The memory lasts one run, as the transport does.
63
+ * A fetch that sends `GET`s through `inner` and never sends a write (#11843
64
+ * D9): a `PUT` or `POST` is answered locally — `201` when its JSON body's
65
+ * `version` is `null`, else `200` — with the members of a save's answer the
66
+ * importer reads (`data.address.locale`, and `data.locale` for the Language
67
+ * pass). A `PATCH`, or any other method, throws, so a stray call on a retired
68
+ * route is visible in a dry run too. The importer decides `created`,
69
+ * `updated` and `unchanged` from its read alone, before it writes.
77
70
  */
78
71
  export function readOnlyFetch(inner, locale) {
79
- const layouts = new Map();
80
- /** Whether the hub would write a dry run's layout `PUT` (#11749 D4). */
81
- function layoutWritten(input, init) {
82
- if (input instanceof Request || typeof init?.body !== "string")
83
- return false;
84
- const url = String(input);
85
- const address = url.replace(/\/structure(?=\?|$)/, "");
86
- if (address === url || !layouts.has(address))
87
- return false;
88
- let sent;
89
- try {
90
- sent = JSON.parse(init.body)?.structure;
91
- }
92
- catch {
93
- return false;
94
- }
95
- return !isDeepStrictEqual(sent, layouts.get(address));
96
- }
97
72
  return (async (input, init) => {
98
73
  const method = (init?.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase();
99
- if (method === "GET") {
100
- const response = await inner(input, init);
101
- if (response.status === 200) {
102
- const url = input instanceof Request ? input.url : String(input);
103
- try {
104
- // Parsed here, never by `Response.json()`, so both sides of the
105
- // comparison are this module's plain objects.
106
- const data = JSON.parse(await response.clone().text())?.data;
107
- if (data !== null && typeof data === "object" && "structure" in data) {
108
- layouts.set(url, data.structure);
109
- }
110
- else {
111
- layouts.delete(url);
112
- }
113
- }
114
- catch {
115
- // Not JSON: nothing is recorded; the response goes back as it came.
116
- }
117
- }
118
- return response;
119
- }
120
- if (method !== "POST" && method !== "PATCH" && method !== "PUT") {
74
+ if (method === "GET")
75
+ return inner(input, init);
76
+ if (method !== "POST" && method !== "PUT") {
121
77
  throw new Error(`a dry run sends no ${method} request`);
122
78
  }
123
- const data = method === "PUT" ? { locale, written: layoutWritten(input, init) } : { locale };
124
- return new Response(JSON.stringify({ ok: true, data }), {
125
- status: method === "POST" ? 201 : 200,
79
+ let created = false;
80
+ try {
81
+ created =
82
+ typeof init?.body === "string" &&
83
+ JSON.parse(init.body)?.version === null;
84
+ }
85
+ catch {
86
+ // Not JSON: answered as an edit.
87
+ }
88
+ return new Response(JSON.stringify({ ok: true, data: { locale, address: { locale } } }), {
89
+ status: created ? 201 : 200,
126
90
  headers: { "content-type": "application/json" },
127
91
  });
128
92
  });
@@ -166,7 +130,7 @@ function verdictText(verdict) {
166
130
  : `publishable · advisory: ${verdict.advisory.map((issue) => issueText(issue, true)).join(", ")}`;
167
131
  }
168
132
  /** What a dry run prints when the site's contract cannot give a verdict. */
169
- export const PUBLISH_NOT_CHECKED = "publish: not checked — the site's @working-theory/validation has no live-source report; update the site's dependencies and re-run";
133
+ export const PUBLISH_NOT_CHECKED = "publish: not checked — the site's @working-theory/validation has no content check; update the site's dependencies and re-run";
170
134
  // ── The command (D1–D4) ─────────────────────────────────────────────────────
171
135
  export async function migrateContent(opts) {
172
136
  const targetDir = resolve(opts.targetDir);
@@ -227,7 +191,6 @@ export async function migrateContent(opts) {
227
191
  defaultLocale: LOCALE,
228
192
  fetch: transport,
229
193
  ...(opts.sleep !== undefined && { sleep: opts.sleep }),
230
- liveSource: true,
231
194
  // A dry run's importer lines say `created`/`updated`, which nothing was.
232
195
  ...(apply && { onLine }),
233
196
  });
@@ -371,24 +334,23 @@ skips is listed with the rule it failed. Their lines are prefixed
371
334
  editorial: — each outcome's root is content or editorial.
372
335
 
373
336
  A dry run prints create, update, unchanged, skipped or failed per page. It
374
- cannot see a write the API would refuse at --apply (a conflict or a server
375
- error), and a page whose content fails its page type is planned and saved
376
- with errors the editor shows, not failed. An update whose words already
377
- match the workspace prints "update — layout only". A layout change to a page
378
- whose draft is its live version is saved as a new draft with the same words,
379
- so the live site does not change until the page is published. --apply prints created, updated,
337
+ cannot see a write the API would refuse at --apply (a conflict, a server
338
+ error, or a page whose content fails its page type, which the save refuses
339
+ 422 invalid and stores nothing; fix its file and re-run). An update whose
340
+ words already match the workspace prints "update — layout only". A change to
341
+ a page that is live is saved as a new draft, so the live site does not
342
+ change until the page is published. --apply prints created, updated,
380
343
  unchanged, skipped or failed per page, so a re-run is safe. Exit 0 when no
381
344
  page failed, 1 when any did, 2 on a refusal (nothing is sent).
382
345
 
383
- Every page is written with a live-source mark: its words already ship on the
384
- live site, so the hub lists a heading the page type's template asks for and
385
- the page lacks as advisory, and publish takes the page. Editing the page's
386
- words in the hub drops the mark. A dry run prints a publish line after each
387
- page: publishable, the advisory headings the hub will list, or the status and
388
- findings that will stop the publish. The verdict is the site's installed
389
- @working-theory/validation's, not the hub's; it sees no library-file finding
390
- and no layout the hub repairs differently. A site whose validation predates
391
- the live-source report prints one "publish: not checked" line instead.
346
+ No page is written with a live-source mark, so a heading the page type's
347
+ template asks for and the page lacks stops its publish, as on any page. A
348
+ dry run prints a publish line after each page: publishable, the advisory
349
+ findings the hub will list, or the status and findings that will stop the
350
+ publish. The verdict is the site's installed @working-theory/validation's,
351
+ not the hub's; it sees no library-file finding and no layout the hub repairs
352
+ differently. A site whose validation has no content check prints one
353
+ "publish: not checked" line instead.
392
354
  `;
393
355
  export function parseMigrateContentArgs(argv) {
394
356
  let parsed;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ailk",
3
- "version": "0.43.0",
3
+ "version": "0.44.0",
4
4
  "description": "Scaffolder for AI Launch Kit — `pnpm create ailk@latest <dir>` produces a starter repo consuming @working-theory/* from npm (per ADR 0007).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,8 +28,8 @@
28
28
  "tar": "^7.5.21"
29
29
  },
30
30
  "devDependencies": {
31
- "@working-theory/schema": "0.71.0",
32
- "@working-theory/templates": "0.71.0"
31
+ "@working-theory/schema": "0.72.0",
32
+ "@working-theory/templates": "0.72.0"
33
33
  },
34
34
  "repository": {
35
35
  "type": "git",
@@ -89,7 +89,8 @@ Routes are versioned under `/v1/*`:
89
89
  - `/v1/member/purchases`, `/v1/member/appointments`, `/v1/member/artifacts`, `/v1/member/artifacts/:pieceId/versions/:version/file`, `/v1/member/meeting-types`, `/v1/member/availability`, `/v1/member/request-form`, `/v1/member/billing` (all GET) — the Phase 1 member reads (#8169, `src/routes/member/{purchases,appointments,artifacts,meeting-types,availability,request-form,billing}.ts`; spec `docs/specs/8169-member-reads-spec.md`). Same caller seam, refusals and registration as the bullet above, each read through one `src/lib/member-store.ts` function, each success body re-parsed against its `@working-theory/validation` `member.ts` schema. All eight are in `HUB_SESSION_ROUTES` (#8220). Appointments, artifacts and the file read are scoped by the resolved workspace AND Person (≤ 50, never an attendee's name, email or time zone; never a version or asset id; the file read is one `404 not_found` for every miss, a version above the 32-bit column included, and sends `messages.ts`'s five headers). **Purchases and billing read at workspace grain** (#9966 D4, replacing #8140's organization grain): only Persons in the calling workspace whose `userId` is ALREADY the caller (`lib/member-store.ts`'s `linkedPersonsInWorkspace`, pinned by `src/__tests__/member-isolation.test.ts`) — they link nothing, and a spoke's credential never reads a sibling workspace of its organization. A purchase is a completed hub `FlowCheckout` whose lead carries the caller's VERIFIED `User.email` (case-insensitive; never the Person's email, which is whatever a buyer typed at intake — #8241), or (#8185) a `Lead` the hub marked `spokeCheckout` when it was written — a registered spoke's unrelayed (`x-ailk-relayed` absent), LIVE paid checkout, the #7877 plan rule's own predicate evaluated in `services/lead-routing.ts` before the create and never updated, or (#8932) the per-Organization Stripe webhook's live, recorded, paid Offerings session, marked by that predicate's Offerings twin — served with the same Person-workspace and verified-email rules, its offering kept only if it is a plan-offering key (SEC-8169-6); an anonymous, relayed, test-mode or pre-#8185 lead is never marked and never served (no backfill), and `tests/architecture/idempotency-key-producers.test.ts` fails if any spoke-side file, MCP tool or client wrapper starts sending an `Idempotency-Key`. **Billing answers a hub credential only**: any other caller gets `404 not_found` before `resolveMember` and before any read, and no log line ever names a `cus_` id; a hub credential reads it at the workspace grain. Meeting types and availability join the workspace's `customerSlugs` that are also in `enabledSlugs` (#11122 D6: an Authenticated type that is Off is bookable nowhere, the account included) to the scheduling provider — a provider failure is its `SCHEDULING_ERROR_STATUS`, never an empty list; a slug outside `customerSlugs` is `404 meeting_type_not_offered` with no provider call — and register under `scheduling && (workspace || multi-tenant)`, because only the `scheduling` module delivers `services/scheduling/`. The request form is the `request-quote` contact row while `who` is `user`, whatever its status, else `{ form: null }`. **`GET /v1/member/onboarding` (#8515 D7)** serves the standard onboarding magnet — the `diagnostic` row at slug `onboarding` while `who` is `user`, whatever its status — reduced to display keys (a field's name, input type, `required`, select options and label/help/placeholder; a choice question's name, options, `multi` and `exclusiveValues`; never a `showIf`, `mapsTo`, `purposes`, field rule, `segments`, `whenHidden` or `resultsReveal`), else `{ form: null }`. `GET /v1/member/messages` items carry `action: "onboarding" | null` (#8515 D6). No MCP twin, by decision — the same reason, recorded in `tests/parity/README.md`.
90
90
  - `/v1/member/requests` (POST), `/v1/member/messages` (POST), `/v1/member/bookings` (POST), `/v1/member/artifacts/:pieceId/review` (POST), `/v1/member/profile` (PATCH), `/v1/member/profile/contact` (GET, PATCH), `/v1/member/deletion-request` (POST) — the Phase 1 member writes (#8170, the contact pair #8435, `src/routes/member/{requests,messages,bookings,artifact-review,profile,deletion-request}.ts`; spec `docs/specs/8170-member-writes-spec.md`). Same caller seam and refusals as the reads, and a cookie write must carry a trusted `Origin` (the preHandler's 401). Nothing in a body, path or query names a person, user or workspace; every body parses its `@working-theory/validation` `member.ts` schema (`400 invalid_input`, or `400 link_not_https` when a link is why) and every success body is re-parsed before it is sent. **Requests, messages and reviews are each ONE inbound `Interaction` on the caller's own Person** — channel `member`, direction `inbound`, `createdBy` the caller — and never a `Lead`: a request is checked against the `request-quote` magnet's CURRENT field steps (`400 answers_invalid` for a key the form does not ask, a missing required answer, an array answer or a failed field rule; `409 request_form_off` when the form is off or the caller has no Person) and stores `{ flowSlug, items }` with each label as the form shows it; a message stores `{ link }` when one is sent (`404 not_found` with no Person). **The cap:** every inbound write runs in one transaction whose first statement is the Person's advisory lock (`ailk:member-inbound:<personId>`), then counts the Person's inbound rows of the last hour — 30 or more is `429 too_many_requests` with nothing written. **The review** lands only on the piece's LATEST version (`409 version_not_latest`), only once per version and never after `Piece.approvedAt` is set (`409 review_closed`); a missing, foreign or approved piece is refused from one read before any lock, otherwise the Person lock then the workspace's piece lock (`lib/tenant-db.ts`'s `pieceStagesLockKey`, the key the operator's piece writes take), and it writes the version's `review`, `reviewComment`, `reviewedAt`, the piece's `approvedAt` on an approval and the `review` Interaction in that one transaction — never a title, stage, link, asset or note; asking for changes stays open on every new latest version (#8140 disposition 3). **The booking** books an offered `customerSlugs` meeting type at `<handle>/<slug>` as the caller (verified email, own name), refuses a Person holding 10 upcoming non-cancelled appointments `429` before any provider call, answers a provider failure through `SCHEDULING_ERROR_STATUS`, and binds a spoke caller's booking to its workspace as `/v1/schedule/book` does; it registers under `scheduling && (workspace || multi-tenant)`. **The profile** writes only the caller's own `User.name` / `User.image` (https only) and answers `{ name, image }`. **The contact** (`profile/contact`, #8435) is the caller's contact details on THIS site, never on the hub `User` and never synced to another site: the GET serves the contact of the caller's linked Person only once a human saved it (`contactConfirmedAt` set — a value only an anonymous capture wrote is `{ contact: null }`, SEC-8435-B); the PATCH takes all six keys, each nullable and required, and REPLACES the whole contact (so no value the client never saw survives), stamping `contactConfirmedBy: "client"`. With no Person yet it finds or creates the Person for the caller's VERIFIED email and links it through `stampPersonUser`'s rule; any outcome but linked is `409 contact_unavailable`, nothing written. Only the caller's own linked Person (`{ id, workspaceId, userId }`) is ever written; `400 invalid_input` or `400 telephone_invalid` for a refused body, an 8 KiB body bound, and `{ event: "member-contact", outcome }` as its one log line. **The deletion request** is filed through `routeLead` as a `web` message lead (kind `deletion`, the caller's verified email, no idempotency key) into `resolveSiteWorkspaceId()` — the deployment's own site workspace, so a spoke caller's request reaches the hub operator (`sentTo: "hub-operator"`), never the spoke's. Every data write goes through `src/lib/member-store.ts`; every write logs only `{ event, outcome }` and a `ref` of at most 8 characters (`services/member-area.ts`'s `memberWriteLog`), never a subject, body, answer, link, note, name, email or full id. All six (and the two contact routes) are in `HUB_SESSION_ROUTES` (#8220): a spoke's deletion request reaches the hub operator, and a spoke's profile write changes the name and photo the hub's `me` answers. **The onboarding submission (#8515 D8–D10):** `POST /v1/member/onboarding` takes the request body's `{ answers }` (`plainText`, ≤ 64), checks them against the served onboarding form (every key a served field or question; a required field non-blank; `email`, https `url`, `select` options and `minLength` as the request checker applies them; a single choice one option value; a `multi` choice 1…options distinct option values, an exclusive value only alone — `400 answers_invalid` / `link_not_https`; `409 onboarding_off` with no Person or no form) and writes ONE `flow:onboarding` `Lead` — never an `Interaction` — on the caller's own Person with the Person's email, the answers, `flowSlug`, `locale` and the server-written `submittedBy` (the caller's user id, a server-owned key the Inbox never shows as an answer), so it is an Inbox submission and a `lead` Activity entry with no reader change. Under the Person's inbound lock, at most five of the caller's OWN submissions an hour (`429 too_many_requests`) — only leads carrying the caller's `submittedBy` count, so an anonymous `POST /v1/leads/submit` with that source and the client's email never fills the allowance. Both onboarding routes are in `HUB_SESSION_ROUTES`. **A proposal (#8516):** the artifacts read and the review answer carry `kind`, `price` and `payment` (`{ status: "due" }` for an approved, priced, unpaid proposal where payment runs; `{ status: "paid", paidAt }` once paid; else `null`), and a proposal's review — the same write, which is how a proposal is accepted or sent back — also writes one `people.proposal.client_review` audit row as the client (`recordWorkspaceAuditAction`). **`POST /v1/member/artifacts/:pieceId/payment`** opens the client's Stripe Checkout page for their own approved, priced, unpaid proposal and answers `{ url }` — a `checkout.stripe.com` URL only (`isStripeCheckoutUrl`, checked before anything is stored), `Cache-Control: private, no-store`. It sits behind the commerce claim (`requireCommerceClaim`, the module-disabled 404 before any read) and its own strict per-IP limiter (`proposalpay`); it is NOT on `HUB_SESSION_ROUTES`. **Same site, sandbox only:** `services/proposal-payments.ts`'s `proposalPaymentsFor` is `on-approval` only with the claim, on a one-workspace deployment whose workspace is the proposal's (the deployment's one Stripe account is provably that seller's), with a key `assertSandboxKey` admits and `FRONTEND_URL` set — and never for a call carrying a spoke key or a hub credential; anywhere else approval records acceptance only and the pay route is `404 not_found`. The session is card only, expires in an hour, carries a fixed product name and the stored amount (never a request value), and is reused while it has more than five minutes left; a concurrent second session is expired. `409 proposal_not_approved` / `409 proposal_paid` / `502 payment_unavailable`; each opened session writes one `people.proposal.checkout` audit row. No MCP twin, by decision — identity-bound client writes, recorded in `tests/parity/README.md`.
91
91
  - `/v1/consent/cookie` (POST), `/v1/consent/unsubscribe` (POST), `/v1/consent/sign-up` (GET), `/v1/consent/account` (GET, POST), `/v1/consent/platform` (GET, POST), `/v1/member/consents` (GET, POST), `/v1/workspaces/:workspaceId/people/:personId/consents` (GET) — the consent ledger's routes (#8438, spec `docs/specs/8438-consent-registry-and-ledger-step-spec.md`; #8765, spec `docs/specs/8765-sign-up-refuses-without-the-spec.md`). `consent_grants` is THE ledger: append-only (the database refuses any change to a stored row, and any truncation, on it and on `consent_visitor_links`), every row naming its `source`, its `policyVersion` and, when known, its Person; it has two writers — `src/services/consent.ts` (`recordConsent`, `recordPersonConsent`, `recordCookieChoice`, `linkConsentVisitor`, `recordCheckoutConsent`; every source) and the web's sign-up hook `apps/web/lib/sign-up-agreements.ts` (#8765 D4), which writes only `sign_up` rows (subject `user`) of a user it creates in the same Better Auth transaction, from the evidence `GET /v1/consent/sign-up` built with `consent.ts`'s own functions — and every reader is `src/lib/consent-store.ts` (`DISTINCT ON` current-state reads, never a window). **Two readings of a Person's rows:** the OWN reading (`sign_up`, `account_settings`, `email_unsubscribe` — a verified caller or a signed link) is what the member's screens and any send read; the ANY-SOURCE reading (adds `magnet`, `api`, `cookie_banner`, `checkout`, and linked visitors' cookie rows) is the operator's, marked `unverified` — an anonymous form's row never changes a member's own answer. **The checkout grant (#8765 D13, D14):** `checkout` is the eighth source (the `consent_grants_source_known` CHECK names all eight). The hub webhook's `checkout.session.completed` arm, after the flow-checkout Person step, writes one `account_terms` row (subject `person`, source `checkout`, `sourceRef` the Checkout Session id, locale `en`, the current statement and version) through `recordCheckoutConsent` — one transaction under the `ailk:consent:<workspaceId>:checkout:<sessionId>` lock, nothing written when that Person already holds that session's row — only when `consent.terms_of_service` is `accepted` and `metadata.ailk_terms` is `account_terms@<current version>`; the Person is `services/checkout-buyer.ts`'s `checkoutBuyerPerson` (a proposal session → the piece's Person in its `ailk_workspace` through `lib/proposal-paid-store.ts`'s `proposalPersonId`; a flow checkout → the Person the Person step's `resolveCheckoutPerson` found or created, never created here; a signed-in buyer's `ailk_user_id` → the Person of that user's verified email in the site workspace, test mode included; else, for a paid live-mode session only, `customer_details.email`'s Person). **A spoke purchase records the same grant (#8778):** a spoke's checkout runs on the spoke's own Stripe account, so the hub webhook never sees it; instead the first write of a `spokeCheckout` lead with a Person (`services/lead-routing.ts`) whose `payload.termsAccepted` equals the current `account_terms@<version>` stamp (`currentAccountTermsStamp`) calls `recordCheckoutConsent` for the lead's Person, `sourceRef` the lead's `Idempotency-Key` (the Checkout Session id) — a `null` or absent value writes nothing (`consent_absent`), any other value nothing (`terms_unstamped`), a replay never reaches it (and `termsAccepted` is left out of the replay comparison, so a redelivery across a spoke's update still replays), and the store's per-session guard keeps it to one row; it logs `{ event: "checkout-consent", outcome, siteId }` only and never changes the lead's answer. A `checkout` row is unverified: the payer is not a signed-in user, so it never satisfies the account interstitial. It logs `{ event: "checkout-consent", outcome, eventIdPrefix }` only (`consent_absent`, `terms_unstamped`, `person_unresolved`, `recorded`, `unchanged`, `version_changed` — the site registry has moved past the stamped version, so nothing is written — and `failed`, which adds the error's `errName`) and never changes the 200. A write appends only when the answer changes the reading it is checked against, under an advisory lock on the (subject, purpose) pair. `POST /v1/consent/cookie` takes `{ visitorId, choice, locale }` and never a workspace (it comes from `resolvePublicWorkspace`); `POST /v1/consent/unsubscribe` takes a token signed with `AILK_CONSENT_LINK_SECRET` (≥ 32 bytes, optional; unset ⇒ `503 link_secret_not_configured`) and answers every defect as one `400 invalid_link`. Both are top-level, outside every module gate, in their own rate-limit scopes (`consent`, `unsubscribe`) and on `FORWARDED_VISITOR_ROUTES`. **A sign-up agreement is the account's (#8765 C3, D5, D6):** a `signUp` purpose (`account_terms`) is recorded once per `User`, subject `user` / the user id in the deployment's own site workspace (`resolveSiteWorkspaceId()`, the owner platform consents' footing, read by `userPlatformRows`), never per Person, so the hub and every spoke signed in through it read one row. `GET /v1/consent/sign-up` is anonymous: `{ workspaceId, agreements: [{ purposeId, policyVersion, locale, statement, statementHash }] }` for the site workspace (`locale` default `en`, `null` workspace `503 tenant_unresolved`, `Cache-Control: no-store`), top level beside the cookie route in its own rate-limit scope `signupevidence`, outside every module gate. **Its budget is per site key (#8805):** a request presenting a valid `x-ailk-spoke-key` (`resolveCallerSite` → a registered, unrevoked spoke) is counted against that key's `site,<spokeId>` bucket at `DEFAULT_SIGNUPEVIDENCE_PER_KEY_PER_MINUTE` (120; `AILK_RATE_LIMIT_SIGNUPEVIDENCE_PER_KEY_PER_MINUTE` overrides) and let through the server-wide per-IP ceiling, so a spoofed `X-Forwarded-For` cannot spend it; an invalid or absent key, or a failed lookup, keeps `DEFAULT_PER_IP_PER_MINUTE_STRICT` per IP. The key picks the bucket only — the workspace stays `resolveSiteWorkspaceId()` (`middleware/rate-limit.ts`'s `siteKeyReader`, `SITE_KEYED_ROUTES`). `GET /v1/consent/account` answers `{ agreements: [{ id, statement, policyVersion, acceptedVersion, acceptedAt, current }], complete }` for the caller (`memberCaller` — a cookie session or a hub credential; a personal token `401`); `POST` takes `{ purposeIds, locale? }`, refuses any id that is not a `signUp` agreement `404 purpose_unknown` before writing anything, writes each through `recordPersonConsent` (source `account_settings`, `sourceRef: spoke:<id>` for a hub credential) and answers the GET body; both register in `authScope` unconditionally and log `{ event: "account-agreements", outcome }` only. The member pair reads and writes that same row for a `signUp` purpose (no Person is created) and is unchanged for every other purpose; a `null` site workspace keeps the old per-Person reading; a hub credential's `via: "sign_up"` is `400 sign_up_window_closed` with nothing written (SEC-8765-B). The member pair and the account pair are in `HUB_SESSION_ROUTES` (26 entries since #8765); the anonymous `GET /v1/consent/sign-up` is not, and neither is `/v1/consent/platform` — it is the deployment owner's own consent to Working Theory, a cookie session holding `platform-consents`, under `multi-tenant`. The banner's visitor id travels in `x-ailk-consent-visitor` (only a v4 UUID counts) on the lead and flow routes and the member write, linking the visitor to the Person; the header is never echoed or logged. A `consent` flow field now stores `{ [purposeId]: boolean }` and writes the ledger at completion (source `magnet`, `sourceRef` the flow slug). The operator's `…/consents` answers `{ own, anySource, history, nextCursor }` (history 500 a page, `Cache-Control: private, no-store`, never a subject id). No MCP twin for any of them, recorded in `tests/parity/README.md`.
92
- - `/v1/workspaces/:workspaceId/requests` (GET, `?limit=`), `/v1/workspaces/:workspaceId/requests/:requestId` (GET), `/v1/workspaces/:workspaceId/people/:personId/pieces/:pieceId/versions` (POST) — the provider routes (#8171, `src/routes/workspaces/{requests,pieces}.ts` over `tenantDb(tenant).memberArea`; spec `docs/specs/8171-provider-routes-the-workspace-requests-spec.md`). **The Requests read** lists the workspace's inbound member rows (#8170's messages, quote requests and reviews), newest first, `limit` 1–50 (default 50, no cursor), behind `inbox-read` (every role) checked with `can(tenant.role, …)`. It is tiered: a role holding `people-read` (owner, admin) gets the full row — the subject, body and the kind's own fields (a message's `link`, a quote's `items`, a review's `pieceId`, `version`, `review`); every other caller, every agent key included, gets `{ id, kind, person, createdAt }` and the content is never selected. A row whose payload fails its kind's schema, or whose Person is gone, is left out and counted in one `warn`. **Deliver a version** numbers version n+1 under the piece lock (`withPieceStagesLock`), behind `member-pieces-manage` through `allows` (an agent granted it delivers); the body is exactly one of an `https` link (`isHttpsLink`, else `400 link_not_https`) and a private attachable asset of this workspace (`400 asset_not_found` / `asset_not_attachable`), plus an optional note; `version`, `deliveredBy` and `deliveredAt` are the server's (a body naming one is `400 validation_failed`); a piece with `approvedAt` set is `409 piece_approved`; a malformed, absent or foreign Person or piece is `404 not_found`. There is no round count, limit or remaining count (#8140 disposition 3). It answers `201 { version: { id, pieceId, version, file, link, note, deliveredAt } }` — the file's download name, never an asset id or `deliveredBy` — and every call that reaches the store writes one `people.version.create` audit row. **The single Requests read (#9847, spec `docs/specs/9847-agent-reads-member-request-spec.md`):** `GET /v1/workspaces/:workspaceId/requests/:requestId` answers one inbound member row of the caller's workspace in the list's full shape (`workspaceRequestSchema`, `{ ok: true, data: <row> }`) through `tenantDb(tenant).memberArea.getRequest`. Gate: `inboxAllowed(tenant, "people-read")` before any read — a person whose role holds `people-read`, an agent holding BOTH the `people-read` and `inbox-act` grants (the reply grant, #9714 D5; `member-pieces-manage` is not an alternative); a refusal is `403`. A malformed, absent, outbound, other workspace's or unservable id (payload failing its kind's schema, Person gone — logged `dropped: 1` at `warn`) is one `404 not_found`. The subject, body and each quote answer pass `inbox-messages.ts`'s `stripHiddenText` (zero-width, bidi, BOM and tag characters, SEC-9847-1); the stored row is untouched. Every agent call writes exactly one `people.request.read` audit row — `refused`/`failed` against the workspace, `succeeded` against the interaction with summary `{ kind }` and thread `hub:<personId>` — carrying its session; a person's call writes none. The list's agent view stays the summary row. The thread's `request` entry carries `requestId`, the row's `intx_` id, so an agent can find it. Same registration, scope and tenant guard as the routes above (`workspace || multi-tenant`). No MCP twin, by decision — member-area MCP tools are a later phase of the CRM nucleus, recorded in `tests/parity/README.md`.
92
+ - `/v1/workspaces/:workspaceId/requests` (GET, `?limit=`), `/v1/workspaces/:workspaceId/requests/:requestId` (GET), `/v1/workspaces/:workspaceId/people/:personId/pieces/:pieceId/versions` (POST) — the provider routes (#8171, `src/routes/workspaces/{requests,pieces}.ts` over `tenantDb(tenant).memberArea`; spec `docs/specs/8171-provider-routes-the-workspace-requests-spec.md`). **The Requests read** lists the workspace's inbound member rows (#8170's messages, quote requests and reviews), newest first, `limit` 1–50 (default 50, no cursor), behind `inbox-read` (every role) checked with `can(tenant.role, …)`. It is tiered: a role holding `people-read` (owner, admin) gets the full row — the subject, body and the kind's own fields (a message's `link`, a quote's `items`, a review's `pieceId`, `version`, `review`); every other caller, every agent key included, gets `{ id, kind, person, createdAt }` and the content is never selected. A row whose payload fails its kind's schema, or whose Person is gone, is left out and counted in one `warn`. **Deliver a version** numbers version n+1 under the piece lock (`withPieceStagesLock`), behind `member-pieces-manage` through `allows` (an agent granted it delivers); the body is an `https` link (`isHttpsLink`, else `400 link_not_https`), a private attachable asset of this workspace (`400 asset_not_found` / `asset_not_attachable`), or both (#11881 — the link says where the original lives, the file is the copy as sent; the `piece_versions_has_target` CHECK refuses neither), plus an optional note; `version`, `deliveredBy` and `deliveredAt` are the server's (a body naming one is `400 validation_failed`); a piece with `approvedAt` set is `409 piece_approved`; a malformed, absent or foreign Person or piece is `404 not_found`. There is no round count, limit or remaining count (#8140 disposition 3). It answers `201 { version: { id, pieceId, version, file, link, note, deliveredAt } }` — the file's download name, never an asset id or `deliveredBy` — and every call that reaches the store writes one `people.version.create` audit row. **The single Requests read (#9847, spec `docs/specs/9847-agent-reads-member-request-spec.md`):** `GET /v1/workspaces/:workspaceId/requests/:requestId` answers one inbound member row of the caller's workspace in the list's full shape (`workspaceRequestSchema`, `{ ok: true, data: <row> }`) through `tenantDb(tenant).memberArea.getRequest`. Gate: `inboxAllowed(tenant, "people-read")` before any read — a person whose role holds `people-read`, an agent holding BOTH the `people-read` and `inbox-act` grants (the reply grant, #9714 D5; `member-pieces-manage` is not an alternative); a refusal is `403`. A malformed, absent, outbound, other workspace's or unservable id (payload failing its kind's schema, Person gone — logged `dropped: 1` at `warn`) is one `404 not_found`. The subject, body and each quote answer pass `inbox-messages.ts`'s `stripHiddenText` (zero-width, bidi, BOM and tag characters, SEC-9847-1); the stored row is untouched. Every agent call writes exactly one `people.request.read` audit row — `refused`/`failed` against the workspace, `succeeded` against the interaction with summary `{ kind }` and thread `hub:<personId>` — carrying its session; a person's call writes none. The list's agent view stays the summary row. The thread's `request` entry carries `requestId`, the row's `intx_` id, so an agent can find it. Same registration, scope and tenant guard as the routes above (`workspace || multi-tenant`). No MCP twin, by decision — member-area MCP tools are a later phase of the CRM nucleus, recorded in `tests/parity/README.md`.
93
+ - `/v1/workspaces/:workspaceId/people/:personId/piece-versions` (GET) — a Person's delivered versions for the Admin's person page (#11881, `src/routes/workspaces/pieces.ts` over `tenantDb(tenant).memberArea.listPersonVersions`; spec `docs/specs/11881-an-entry-on-a-person-spec.md` D6): `{ items }`, at most 50, newest first, each `pieceVersionSchema` — its file's download name and type and its link, never an asset id or who delivered. A version whose file is gone, or that carries neither, is left out, as the member's artifacts read leaves it out. `people-read` checked by role (`roleAllows`), so no agent grant reaches it and the person timeline an agent may read stays content-free (#8171 D4); a malformed, absent or foreign Person is `404 not_found`; no audit row. No MCP twin, by decision (`tests/parity/README.md`).
93
94
  - `/v1/workspaces/:workspaceId/callbacks` (GET, `?limit=`) — the Inbox callbacks read (#9254, `src/routes/workspaces/callbacks.ts` over `tenantDb(tenant).callbacks`; spec `docs/specs/9254-callback-rows-inbox-spec.md`): the workspace's request-and-confirm `Callback` rows (#5970), newest first, `limit` 1–50 (default 50, the Requests read's own query; any other key `400 validation_failed`), behind `inbox-read` (every role, a member and an agent key included) through `permitted`, checked before any read. Same registration, scope and tenant guard as the Requests read (`workspace || multi-tenant`); the scope is always `request.tenant.workspaceId`. The row is `id`, `name`, `phone`, `preferredTime` (the window asked for, as typed), `personId` (`null` for a callback captured with no email), `confirmedAt`, `confirmedTime`, `paidAt` and `createdAt` — read through the fixed `CALLBACK_ROW_SELECT`, so never `payload`, the confirm digest or expiry, `buyerEmail`, `amountMinor`, `currency` or a Stripe id. The confirm state is the reader's to derive (`paidAt` → paid, else `confirmedAt` → confirmed, else awaiting). No item read, no cursor, no stamp, no audit row; the body is re-parsed against its own `.strict()` schema. The Admin Inbox lists each row under Interested. No MCP twin, recorded in `tests/parity/README.md`.
94
95
  - `/v1/workspaces/:workspaceId/work-requests` (GET, POST), `/v1/workspaces/:workspaceId/work-requests/:requestId` (GET), `/v1/workspaces/:workspaceId/work-requests/:requestId/issue` (PATCH) — custom-work requests (#11756, `src/routes/workspaces/work-requests.ts` over `tenantDb(tenant).workRequests`; spec `docs/specs/11756-a-custom-work-request-can-spec.md`): an Inbox item an agent files that points to one `Document` of its workspace, and the GitHub issue a person links to it. Same registration, scope and tenant guard as the callbacks read (one `TENANCY` row in `tenant:settings`); the scope is always `request.tenant.workspaceId`, and the routes never set `mcpPinSwitch`, so an all-workspaces token writes only in its session's pinned workspace — the pin is an accident fence, and the authorization is the live per-workspace `inbox-act` check. **The create** takes a strict `{ documentSlug, summary }` (the content slug grammar; the summary trimmed, 1–280 visible characters, a hidden code point or line break refused) behind `inboxAllowed(tenant, "inbox-act")` — an agent needs the grant; no permission was added — then charges `chargeWriteBudget` scope `workrequest`, the person in this workspace first (`by,<workspaceId>:<userId>`, 5 an hour, shared by all of that person's agents and connected apps — an OAuth agent id is a client registration many people share), then the workspace (`ws,`, 10 an hour) only when the person passed (`429 rate_limited` with `Retry-After`), before the body is parsed. It stores the request only when the slug resolves to a `Document` of the workspace at the default locale that the caller may read (`docs-read` and the Audience/Disabled rule; any miss `404 document_not_found`) and answers `201`. **The reads** (`inbox-read`) serve `{ items, total }` — at most 200, newest first, no query — and one row; a malformed, absent or foreign id is one `404 not_found`. A row is `{ id, summary, document: { slug, title } | null, githubIssue: { owner, repo, number } | null, byAgent, createdAt, updatedAt }`: the document is resolved live, in one query scoped to the workspace and the `Document` type, and is `null` when deleted, archived, retyped or not readable by the caller, or when the caller lacks `docs-read`; the title is stripped of hidden characters and cut at 200. **The link** is a person's act — every agent is `403` — behind `inbox-act`: `{ issueUrl }` is a `https://github.com/<owner>/<repo>/issues/<n>` URL or `null` (`400 issue_url_invalid` for anything else), stored only as `<owner>/<repo>#<n>` (CHECKed in the database); nothing calls GitHub and no GitHub credential is read. An agent's create that passed the gate and the budget writes one `inbox.create_work_request` audit row (`succeeded`, or `failed` with `validation_failed` / `document_not_found`); a link change writes one `inbox.set_work_request_issue` row; a 401, 403 or 429 writes none. No row or log line carries the summary, slug, title, URL or ref. MCP parity: the create's twin is `create_work_request` on `/mcp/workspace`; the list, the item and the link have no tool, by decision (recorded in `tests/parity/README.md`).
95
96
  - `/v1/workspaces/:workspaceId/submissions/:leadId/trial` (POST), `/v1/workspaces/:workspaceId/people/:personId/trial` (GET), `/v1/workspaces/:workspaceId/people/:personId/trial/extend` (POST) — the operator's Start, Get and Extend trial (#9287 C3, `src/routes/workspaces/trial.ts` over `src/services/trial.ts`; spec `docs/specs/9287-operator-started-trials-spec.md` DD2–DD7; Start trial since #9342, spec `docs/specs/9342-start-trial-needs-customers-and-spec.md` DD1–DD7). Same registration, scope and tenant guard as the callbacks read (`workspace || multi-tenant`); the scope is always `request.tenant`. All three need `billing-manage` by role — the owner alone; an admin, a member and every agent key are `403` before any read or Stripe call — and the two POSTs charge a write budget of 30 an hour per person (`chargeWriteBudget` scope `trial`, `429 rate_limited` with `Retry-After`) before their strict body (`bodyLimit` 4 KiB, `400 validation_failed`). The Stripe client is the tenant's own Organization's, `stripeClientForOrganization` only, never the env key (`409 stripe_not_connected`; unusable, or any thrown Stripe error, a fixed `502 stripe_unavailable`, logged by class name only). **Start trial** is a hosted Checkout trial (#9342): it accepts a lead only when it is a `flow:trial` submission of this workspace whose `trial` magnet is a `diagnostic` and names a Person (else one `404 not_found`); the `{ lookupKey }` must be a `plan` `listPlanOfferings` lists (`400 plan_unknown`; a failed read `503 offerings_unavailable`); with no usable `FRONTEND_URL` it is `503 checkout_not_configured` before any Stripe call. It then makes exactly three Stripe calls, all within the Offerings key contract (#8879 §3.3, unchanged): `prices.list` for exactly one active recurring Price under the key (`409 plan_unavailable`); `checkout.sessions.list` of the Person's email's completed sessions, where one tagged `ailk_origin: ailk-trial` is `409 trial_exists` with nothing created; and one session through `lib/stripe.ts`'s `createTrialCheckoutSession` (`@working-theory/stripe-client`) — subscription mode, `trial_period_days: 14`, `payment_method_collection: "if_required"`, `trial_settings.end_behavior.missing_payment_method: "pause"`, the terms box required (`409 terms_not_configured` when the account has no Terms of service URL), `customer_email` the Person's, `subscription_data.metadata` `{ ailk_origin: "ailk-trial", ailk_workspace, ailk_person, site }` with `site` the workspace id (`TRIAL_ORIGIN_TAG`), returning to `<FRONTEND_URL origin>/trial`, keyed `trial-checkout:<leadId>:<lookupKey>`. It calls no Customers or Subscriptions endpoint and writes nothing to the Person: Stripe creates the customer and the trialing subscription when the person completes Checkout, and the hub's licensing module (`@working-theory/api-hub`'s `src/licensing/`, #9383 DD3) mints from `customer.subscription.created` only for a subscription traced to the session Start trial recorded. A session URL `isStripeCheckoutUrl` refuses is `502 stripe_unavailable` with nothing sent. Before anyone is sent the link the session is recorded (`recordCheckoutSession`, #9383) with the workspace, the Organization, the Price and key it read and the connection's mode; a failed record expires the session on the same client and is `502 stripe_unavailable` with nothing sent, and a `conflict` whose stored record is equal in every field is the idempotent replay and succeeds. The person is then emailed the link (`@working-theory/email`'s `sendTrialCheckoutEmail`, from `deliverableSenderAddress()` named "<workspace> via <organization>"); a failed send is one `warn` with its kind and still a success. The answer is `201 { checkout: { url, emailed } }` with `Cache-Control: private, no-store`, re-parsed against `startTrialResponseSchema`. **Get trial** reads the Person's newest RECORDED Start-trial session (#8047 DD5): of the Person's email's ten newest complete sessions, those tagged `ailk-trial`, this workspace and this Person, the newest whose session record names this Organization, workspace and mode — never a customer found by email or stored on the Person — and serves its subscription as `{ subscriptionId, status, trialEnd, lookupKey }`, or `null`. **Extend trial** moves that trial's `trial_end` with `proration_behavior: "none"` only while it is `trialing` (`409 trial_not_active`), to a `trialEnd` strictly later than the current one and no later than 90 days after the request (`400 trial_end_invalid`), nothing written on a refusal. **Get and Extend trial need Subscriptions access, which a key that keeps §3.3 lacks** (#9342 DD7): on such a key Stripe refuses, the route answers `502 stripe_unavailable` and the Person page hides its Trial box; they work on a key that grants that access. Each success writes one `recordAuditAction` row naming the actor and the Person — `people.trial.start` (summary `{ emailed }`, `"true"` or `"false"`) and `people.trial.extend`; a refusal writes none, and Start trial does not mark the lead handled. No log line or audit summary carries the Checkout URL, and no response, log line or audit summary carries an email, a key or a `cus_`/`price_` id (the one `cs_` id served is inside Start trial's URL); Get and Extend's bodies are re-parsed against `trialResponseSchema` (`@working-theory/validation`'s `trial.ts`). No MCP twin — owner-only, recorded in `tests/parity/README.md`. **The managed-service licence** (#9402, spec `docs/specs/9402-managed-service-trials-deliver-the-spec.md` DD5): `/v1/workspaces/:workspaceId/people/:personId/trial/licence` (GET) and `…/trial/licence/reveal` (POST) sit in the same plugin and, like the trial routes, need `billing-manage` by role (#9841, narrowing #9402 DD5's staff audience) — the owner alone; an admin, a member and every agent key are `403` before any read. They read a managed-service trial's licence through the fulfilment seam's optional `readManagedLicence` (`services/offerings/fulfilment-hooks.ts`, built with `fulfilmentContextFor` from the tenant's own client): the GET answers `{ licence }` — `null`, `{ live: false }` or `{ live: true, tier, expiresAt }`, never a key — and the POST charges its own write budget (scope `licencereveal`, 30 an hour per person), takes a strict empty body, and answers `{ key }` only after one `people.trial.licence_reveal` audit row is written (`503 audit_unavailable` and no key when it is not). A licence the issuer recorded for the customer at mint reads as `none` (#9402 AC 5, entitlements#19), whatever the Product is today. `none`/`not_live` on the reveal, and an Organization whose hook has no staff read, are `404 licence_not_found`; a read that cannot be made is `502 licence_unavailable`. Both answer `Cache-Control: private, no-store`; no log line or audit row carries the key. No MCP twin, recorded in `tests/parity/README.md`.
@@ -98,14 +99,14 @@ Routes are versioned under `/v1/*`:
98
99
  - `/v1/workspaces/:workspaceId/agents` (GET `?userId=`, POST), `/v1/workspaces/:workspaceId/agents/:agentId/key` (POST), `/v1/workspaces/:workspaceId/agents/:agentId` (PATCH `{ enabled }`), `PUT /v1/workspaces/:workspaceId/agents/:agentId/grants` (`{ grants }`, #7864), and `/v1/agent/context` (GET) — the agent seat (#3591, `src/routes/workspaces/agents.ts` over `src/lib/agent-store.ts`, `// oss: false`). An agent is a stored delegate of one person, bound to one workspace. The five management routes refuse an agent caller outright (403), check `agents-manage` (owner, admin) before any read, and scope every read and write to `tenant.organizationId`, never a body or query value; an agent of another organization is the same 404 as a missing one. Create returns 201 with the key shown once; re-key returns the new key once. Each successful create, re-key, switch and grant change writes an `agents.*` audit record. **Grants (#7864, `docs/specs/7864-agent-key-grants-spec.md`).** An agent acts at `member`, plus any of nine permissions an owner or admin granted it one by one — `content-edit`, `content-publish`, `assets-write`, `magnets-manage`, `meeting-types-manage`, `people-read` since #852, `member-pieces-manage` since #7878, and `people-memory-propose` and `inbox-act` since #9679 (`@working-theory/validation`'s `AGENT_GRANTABLE_PERMISSIONS`, held to that set by the `agents_grants_allowed` CHECK). The grant PUT replaces the whole set (an empty list removes every grant) and refuses a grant the agent's person's own role does not hold, `409 grant_exceeds_person`. The clamp is one function both tenant guards call (`services/default-tenant.ts`'s `agentTenant`): an agent holds a stored grant only while its person's role holds it, so a demoted person's agent keeps the row but not the permission. The routes for the nine check `allows(tenant, "<permission>")`, which reads the grants — except that the six existing inbox `inbox-act` checks still read `can(tenant.role, …)` until #9686 moves them, and `people-memory-propose` is read today only by the workspace knowledge read (#9683, beside `people-read`); every other check keeps `can(tenant.role, …)`, so no other owner or admin permission is reachable. Every agent write on content, assets and meeting types writes one `recordAgentWrite` row naming the agent and its person (magnets already did); a person's writes there stay unaudited. The member-area writes audit every caller through `recordAuditAction`, whose actor names an agent as the agent. No grant raises the ceiling. `/v1/agent/context` is the agent's own read, unchanged by grants, and needs no permission beyond the workspace guard. Same registration scope as the routes above (`workspace || multi-tenant`).
99
100
  - `GET /v1/workspaces/:workspaceId/clients` and `DELETE /v1/workspaces/:workspaceId/clients/:clientId[?userId=]` — the workspace's Connected clients (#10393, `src/routes/workspaces/clients.ts` over `src/lib/connected-clients-store.ts`, `// oss: false`). The GET lists, as one table, the workspace's live OAuth authorizations (one row per client and person, from the token rows bound to this workspace; `lastUsedAt` is the newest sign-in or refresh) and its enabled agent keys, each row `kind`, `id`, `client.name`, `person`, `scopes`, `lastUsedAt` and never a token or key. A person holding `agents-manage` (owner, admin) sees every row; anyone else, an agent principal included, sees only their own person's. The DELETE refuses every agent caller (403), ends an OAuth authorization by deleting its token rows for this workspace only (a caller without `agents-manage` may name only themselves — another person's row is the same 404 as a missing one) and an agent key by switching it off (`agents-manage`), touches no session, and writes one audit row and one `connected-client-revoked` log line. The GET's MCP twin is `list_connected_clients`; the DELETE has no tool, by decision. Same registration scope as the routes above (`workspace || multi-tenant`).
100
101
  - `GET /v1/workspaces/:workspaceId/discovery` and `PUT /v1/workspaces/:workspaceId/discovery` — the owner's discovery switch, whether AI and search tools can find the workspace's site (#10510, `src/routes/workspaces/discovery.ts`, `// oss: false`, over `packages/api/src/services/site-discovery.ts`). Both parse `:workspaceId` with `inboxWorkspaceParamsSchema` (`400 validation_failed`) and act on `request.tenant.workspaceId` only. The GET needs any tenant, an agent included, and answers `{ ok: true, data: { discoverable } }`; the PUT needs `workspace-settings` (owner, admin — an agent is refused, `403`), checked before the strict `{ discoverable: boolean }` body (`400 validation_failed` on anything else), and answers the stored value. The GET's MCP twin is `get_site_discovery`; the PUT has no tool, by decision. Same registration scope as the routes above (`workspace || multi-tenant`, one `tenant:settings` row).
101
- - `/v1/workspaces/:workspaceId/content` (GET, POST), `/v1/workspaces/:workspaceId/content/:type/:slug` (GET, PATCH), `/v1/workspaces/:workspaceId/content/:type/:slug/{publish,unpublish}` (POST) — the tenant-guarded content editor's write surface (#5853, `src/routes/workspaces/content.ts`): list, create, read/save the draft tip (under `X-Draft-Version`; `If-Match` still accepted for one release, #10264), and publish/unpublish, all over `Artifact`/`ArtifactVersion`. `:type` is validated against the page-type registry (`z.enum(SCHEMA_ORG_TYPES)`) rather than accepted as a free string on every addressed operation — an unregistered type is a 400 before any lookup, since it is echoed back and passed to `notifyRevalidate` as the site's cache tag. Role floors from `@working-theory/validation`'s permission table (#7636 D2): publish and unpublish need `content-publish`, and create, read and save need `content-edit` (both owner, admin — an admin builds, a member operates). The list serves `content-edit` the editor's full view and a caller holding only `docs-read` (a member) a published-only projection (D4): draft rows dropped, every row `status: "published"`, `version: null`, `valid: true`, and a `published_with_draft` page's `type`/`tags` read from its PUBLISHED version — applied before every filter, so a member's `?status=draft` or a draft tip's `?tag=` matches nothing. **The GET list is a UNION of page artifacts and DOCUMENT assets** (#6093, D1/D9 — "one store, two views"): every row carries `tags: string[]` (never null, read from the draft tip's stored content for a page, from `Asset.tags` for a file) and a DERIVED `kind: "page" | "post" | "file"` (`BlogPosting` alone maps to `"post"`; an asset row is always `"file"`) — an optional `?tag=<slug>` filters the union AFTER it is built, so a file is returned under either its own tag or a shared one. The asset half of the union (`DOCUMENT_CONTENT_TYPES`, i.e. `application/pdf`) is skipped entirely when `locale`/`type` is supplied or `status` names anything but `"published"`, since a file row can never satisfy those. A foreign `:workspaceId` costs zero artifact **and** zero asset queries. MCP parity: on `/mcp/workspace`, the create's twin is `create_page` (#10956), the draft read and save are `read_report` and `save_draft` (#10336), and the publish is `publish_draft` (#10661); the list and unpublish have none, as `tests/parity/README.md` and the registry record. `POST /v1/workspaces/:workspaceId/documents/save` (#11811) saves a `Document` — agent context or a plugin-owned document — in the common shape, its address in the body as `POST …/assets/save`'s is: `content-edit` is checked before the body (an agent without it `403 agent_refused`, audited), `version: null` creates and a version edits under a compare-and-swap on the tip, a moved tip or a `null` on an existing document is `409 stale` with `currentVersion`, and a wrong field or word — a plugin contract's misfit included — is `422 invalid` with each issue's path; it never publishes. Its twin is `save_document`; the page save (`PUT …/content/:type/:slug`, `save_page`) also takes an editorial page, whose words are `{ body }`, carrying its stored layout forward. While both ways live, `create_page`, `save_draft` and `save_structure` say they are deprecated. `GET /v1/workspaces/:workspaceId/content/:type/:slug/open?locale=&form=` (#11808) opens a page laid out in sections as the page envelope: `content-edit` is checked before the query or any read, `form` is `record` (the default: its `fields` and its `words`, the stored layout with the body's words applied) or `working-copy` (a `workingCopy`, `{ document, settings }`, in their place), a type not laid out in sections is `422 invalid` at `address.type` (a `Document` naming `open_document`), a missing page — or one the caller may not read — a blank built in memory and never stored (#11809): `version` and `structureToken` `null`, `state: "draft"`, `report: null`, `fields: {}` and its template's starting sections headed by the slug, in the form asked for, a page not in the section form, or whose body's words do not apply cleanly to its layout, `409 not_outlined`, and a page whose working copy would lose a value or exceed the working copy's bounds `409 not_representable` with each issue's path; it never writes or audits, and is limited to 60 calls a minute per workspace. Its twin is `open_page`.
102
+ - `/v1/workspaces/:workspaceId/content` (GET, POST), `/v1/workspaces/:workspaceId/content/:type/:slug` (GET, PATCH), `/v1/workspaces/:workspaceId/content/:type/:slug/{publish,unpublish}` (POST) — the tenant-guarded content editor's write surface (#5853, `src/routes/workspaces/content.ts`): list, create, read/save the draft tip (under `X-Draft-Version`; `If-Match` still accepted for one release, #10264), and publish/unpublish, all over `Artifact`/`ArtifactVersion`. `:type` is validated against the page-type registry (`z.enum(SCHEMA_ORG_TYPES)`) rather than accepted as a free string on every addressed operation — an unregistered type is a 400 before any lookup, since it is echoed back and passed to `notifyRevalidate` as the site's cache tag. Role floors from `@working-theory/validation`'s permission table (#7636 D2): publish and unpublish need `content-publish`, and create, read and save need `content-edit` (both owner, admin — an admin builds, a member operates). The list serves `content-edit` the editor's full view and a caller holding only `docs-read` (a member) a published-only projection (D4): draft rows dropped, every row `status: "published"`, `version: null`, `valid: true`, and a `published_with_draft` page's `type`/`tags` read from its PUBLISHED version — applied before every filter, so a member's `?status=draft` or a draft tip's `?tag=` matches nothing. **The GET list is a UNION of page artifacts and DOCUMENT assets** (#6093, D1/D9 — "one store, two views"): every row carries `tags: string[]` (never null, read from the draft tip's stored content for a page, from `Asset.tags` for a file) and a DERIVED `kind: "page" | "post" | "file"` (`BlogPosting` alone maps to `"post"`; an asset row is always `"file"`) — an optional `?tag=<slug>` filters the union AFTER it is built, so a file is returned under either its own tag or a shared one. The asset half of the union (`DOCUMENT_CONTENT_TYPES`, i.e. `application/pdf`) is skipped entirely when `locale`/`type` is supplied or `status` names anything but `"published"`, since a file row can never satisfy those. A foreign `:workspaceId` costs zero artifact **and** zero asset queries. MCP parity: on `/mcp/workspace`, the create's twin is `create_page` (#10956), the draft read and save are `read_report` and `save_draft` (#10336), and the publish is `publish_draft` (#10661); the list and unpublish have none, as `tests/parity/README.md` and the registry record. `POST /v1/workspaces/:workspaceId/documents/save` (#11811) saves a `Document` — agent context or a plugin-owned document — in the common shape, its address in the body as `POST …/assets/save`'s is: `content-edit` is checked before the body (an agent without it `403 agent_refused`, audited), `version: null` creates and a version edits under a compare-and-swap on the tip, a moved tip or a `null` on an existing document is `409 stale` with `currentVersion`, and a wrong field or word — a plugin contract's misfit included — is `422 invalid` with each issue's path; it never publishes. Its twin is `save_document`; the page save (`PUT …/content/:type/:slug`, `save_page`) also takes an editorial page, whose words are `{ body }`, carrying its stored layout forward. While both ways live, `create_page`, `save_draft` and `save_structure` say they are deprecated. `GET /v1/workspaces/:workspaceId/content/:type/:slug/open?locale=&as=` (#11808, #11882) opens a page laid out in sections as the page envelope: `content-edit` is checked before the query or any read, `as` is `record` (the default: its `fields` and its `words`, the stored layout with the body's words applied) or `working-copy` (a `workingCopy`, `{ document, settings }`, in their place) — `form` is its old name, answered until the release after #11882, and the two sent with different values are `422 invalid` at `as` — a type not laid out in sections is `422 invalid` at `address.type` (a `Document` naming `open_document`), a missing page — or one the caller may not read — a blank built in memory and never stored (#11809): `version` and `structureToken` `null`, `state: "draft"`, `report: null`, `fields: {}` and its template's starting sections headed by the slug, in the shape asked for, a page not in the section form, or whose body's words do not apply cleanly to its layout, `409 not_outlined`, and a page whose working copy would lose a value or exceed the working copy's bounds `409 not_representable` with each issue's path; it never writes or audits, and is limited to 60 calls a minute per workspace. Its twin is `open_page`.
102
103
  - `/v1/workspaces/:workspaceId/library/pages` (GET, `?type=&status=&limit=&page=`) and `/v1/workspaces/:workspaceId/library/assets` (GET, `?tag=&type=&limit=&page=`) — the library reads, each answering `{ workspace: { id, name }, items, total, page, nextPage }` newest first (`limit` 1–200, default 50; `page` from 1; `libraryPageListQuerySchema` / `libraryAssetListQuerySchema` in `@working-theory/validation`). The page list (`packages-paid/api-content-write/src/routes/workspaces/library-pages.ts`, in the content-write tenant scope) serves every page, drafts included, as `{ id, type, slug, locale, title, status, updatedAt }`; `status` is the Docs list's rule — `disabled` when switched off, else `live` when a version is published (a newer draft included), else `draft` — and the route needs `content-edit` (`allows`, so an agent needs the grant). A disabled page is asked for only on a person's behalf: `tenantDb` keeps every disabled row from an agent. The asset list (`packages-paid/api-workspace/src/routes/assets/manage.ts`, beside the manage list, `assets-read`) serves each file's whole record (#11801), `{ id, key, filename, title, description, version, type, size, dimensions, audience, tags, url, updatedAt }` — `title` and `description` with hidden code points removed (`null` when none is written, never left out), `version` the file's record version (`r<n>`, #11803), `type` the content type, `size` its bytes, `dimensions` a raster image's `{ width, height }` as the Admin's Details panel shows it — read from the head of the file — the few bytes a PNG, GIF or WebP needs, at most 64 KiB for a JPEG or AVIF (`tenantDb.assets.fileHeads`, which never reads a private, Knowledge or disabled file) for the answered page's images alone, a JPEG's Exif and an AVIF's `irot` quarter-turn swapping the two (`routes/assets/dimensions.ts`) — and `null` for an SVG, any other file, or a header that does not say, `audience` who may read it, `url` the public read's path, `updatedAt` when the current file was uploaded — the `createdAt` of the version `currentVersion` names (`tenantDb.assets.currentVersionTimes`), so a replace moves it, a restore takes the restored version's upload time, and a metadata edit does not move it; the list is ordered by it, newest first — narrowed by an exact `tag` and a `type` that is a whole content type (`image/png`) or its top-level part (`image`); a file tagged `private` never lists, `?tag=private` included. MCP parity: `list_workspace_pages` and `list_assets` on `/mcp/workspace`.
103
- - `/v1/workspaces/:workspaceId/assets/save` (POST, #11803) — save a file's title and description: the body is `assetSaveBodySchema` (`{ address: { key }, version: "r<n>" | null, words: { title?, description? }, fields?: {} }`, strict at every level), and the answer `{ kind: "asset", address, version, fields: {}, words, state: "live" }` with the new record version. `assets-write` (`allows`, so an agent may hold it by grant) before the body is read; a wrong body is `422 invalid` with `details.issues` (`{ path, message }`, at most 20); a file the caller may not reach — for an agent also a disabled, private or Knowledge one — the plugin's one `404 not_found`; a save based on another record version, or on `null`, `409 stale` with `details.currentVersion`. One conditional UPDATE (`tenantDb.assets.saveRecord`) writes only `title`, `description` and `record_version`, whose `where` carries the version and the reach. Every agent call that reaches the body is audited (`assets.save`). An agent's `PATCH …/assets/:assetId` is refused `403 agent_refused`; a person's PATCH of a title or description moves the record version. MCP parity: `save_asset` on `/mcp/workspace`.
104
+ - `/v1/workspaces/:workspaceId/assets/save` (POST, #11803) — save a file's title, description and type: the body is `assetSaveBodySchema` (`{ address: { key }, version: "r<n>" | null, words: { title?, description? }, fields?: { type? } }`, strict at every level; `fields.type` (#11879) is one of the ten asset types and replaces the one the file held, every other tag kept; a type-only save sends `words: {}`), and the answer `{ kind: "asset", address, version, fields: { type }, words, state: "live" }` with the new record version. `assets-write` (`allows`, so an agent may hold it by grant) before the body is read; a wrong body is `422 invalid` with `details.issues` (`{ path, message }`, at most 20); a file the caller may not reach — for an agent also a disabled, private or Knowledge one — the plugin's one `404 not_found`; a save based on another record version, or on `null`, `409 stale` with `details.currentVersion`. One conditional UPDATE (`tenantDb.assets.saveRecord`) writes only `title`, `description`, the type tag and `record_version`, whose `where` carries the version and the reach — and, with a type, the tags it read, so a concurrent tags write reruns it. Every agent call that reaches the body is audited (`assets.save`). An agent's `PATCH …/assets/:assetId` is refused `403 agent_refused`; a person's PATCH of a title or description moves the record version. MCP parity: `save_asset` on `/mcp/workspace`.
104
105
  - `/v1/workspaces/:workspaceId/overview` (GET) — the workspace overview (#11806; `packages-paid/api-content-write/src/routes/workspaces/workspace-overview.ts`, in the content-write tenant scope beside the knowledge-base reads), any tenant of the workspace; any query key is 400 `validation_failed` (`Invalid query`, the key never echoed). It answers `{ site: { name, description, defaultLocale }, knowledge: { documents, complete }, language: { term, faq, topic, proof }, magnets: { draft, live }, withheld: [{ part, reason }] }`, each part by the code and under the gate of the read it replaces: the identity and SEO blobs (any tenant), `addressLocale(undefined)`, the knowledge list's own rows for `context: "knowledge"` (`docs-read`, at the list's reading role) with `version` — the draft tip's id — only where `content-edit` holds and the caller's own role reads the doc's audience, the Language count per kind (`docs-read`, at the caller's own role, one `groupBy`, no cap), and the magnet count per state through `magnetListView` (`draft` only for `magnets-manage`; the part needs `multi-tenant` or `signal-collectors`). A part the caller may not read is `null` (or, for `version` and `draft`, absent) and named in `withheld` with reason `grant` or `module` — never a refusal of the read. At most six queries in one `Promise.all`; the answer is re-parsed against `workspaceOverviewSchemaFor` (a version or draft count the caller may not see is a 500, never a leak); `Cache-Control: private, no-store`; an agent read logs one `agent_read` line, and the knowledge or Language part withheld for its grant one `denied_read` line each, naming the `part`, none naming a document. MCP parity: `get_workspace_overview` on `/mcp/workspace`.
105
- - `/v1/workspaces/:workspaceId/documents/open` (`?type=Document&slug=&locale=&form=`, #11808 #11853 — `form` is `record` or, at a plugin-owned address only, `working-copy`), `/v1/workspaces/:workspaceId/language/:kind/:slug/open` (`?locale=`) and `/v1/workspaces/:workspaceId/assets/open` (`?key=`) (all GET; the latter two #11809) — open a document, a Language item or a file's record under the common names, beside `open_page`'s route (#11808): each sits beside the read it parallels and takes that read's gate (`content-edit`, `docs-read`, `assets-read`) before any store read, and answers the thing in the common envelope with the `version` its save takes. Nothing at the address — or a thing the caller's read could not see — answers a blank built in memory and never stored: `version: null`, `state: "draft"` and the kind's starting layout (a contract document's `contract`/`contract_version` and required headings, an item's empty words); a file is never blank (`404 not_found`, under the reach `save_asset` gives an agent, for every caller). No open writes or audits. MCP parity: `open_document`, `open_language_item` and `open_asset` on `/mcp/workspace`.
106
+ - `/v1/workspaces/:workspaceId/documents/open` (`?type=Document&slug=&locale=&as=`, #11808 #11853 #11882 — `as` is `record` or, at a plugin-owned address only, `working-copy`, else `422 invalid` at the key sent; `form` is its old name, as the page open's), `/v1/workspaces/:workspaceId/language/:kind/:slug/open` (`?locale=`) and `/v1/workspaces/:workspaceId/assets/open` (`?key=`) (all GET; the latter two #11809) — open a document, a Language item or a file's record under the common names, beside `open_page`'s route (#11808): each sits beside the read it parallels and takes that read's gate (`content-edit`, `docs-read`, `assets-read`) before any store read, and answers the thing in the common envelope with the `version` its save takes. Nothing at the address — or a thing the caller's read could not see — answers a blank built in memory and never stored: `version: null`, `state: "draft"` and the kind's starting layout (a contract document's `contract`/`contract_version` and required headings, an item's empty words); a file is never blank (`404 not_found`, under the reach `save_asset` gives an agent, for every caller). No open writes or audits. MCP parity: `open_document`, `open_language_item` and `open_asset` on `/mcp/workspace`.
106
107
  - `/v1/workspaces/:workspaceId/page-types` (GET) and `/v1/workspaces/:workspaceId/tag-vocabulary` (GET) — the site-vocabulary reads (#11680; `packages-paid/api-content-write/src/routes/workspaces/site-vocabulary.ts`, in the content-write tenant scope), any tenant of the workspace, no query, no row read. `page-types` answers `{ types: [{ type, route, fixed, template, headings }] }`: every page-type registry entry that is a page, in registry order, with its template's headings as `PAGE_TEMPLATES` states them (`key`, `text`, `required`, `section`, `hint`), filtered per request by the module map `pageTypeModule` in `@working-theory/validation` (the one create-ailk's page-types reference generator reads): `marketing` types always, `scheduling` and `signal-collectors` types when `isModuleEnabled`, and `docs-blog` types when `AILK_ENABLED_MODULES` names `docs-blog` — a site that carries the blog and docs sets that key, since `docs-blog` has no API module. `tag-vocabulary` answers `tagVocabulary()`: `{ classes, topics, status }`, each a list of `{ tag, means, setBy }`. MCP parity: `list_page_types` and `get_tag_vocabulary` on `/mcp/workspace`.
107
108
  - `/v1/workspaces/:workspaceId/section-types` (GET, optional `?type=`) — the section-types read (#11790; the same file and scope), any tenant of the workspace, no row read. It answers `sectionTypes()` from `@working-theory/validation`: `{ sections: [{ type, dataSection, pins, fields, lists, rules }] }`, every member of `PageSectionSchema` in the union's order — or the one `type` names — with every leaf of its `data` (`path`, words or data, the Markdown `form`, `required` and `within`, value types, `values`, `bounds`), derived from the section schemas and `SECTION_WORDS`. An unknown `type`, or any other query key, is 400 `validation_failed` with the fixed message `Invalid section type filter`. MCP parity: `list_section_types` on `/mcp/workspace`.
108
- - `/v1/workspaces/:workspaceId/kinds` (GET) — the kinds read (#11805; the same file and scope), any tenant of the workspace, no query, no row read. It answers `listKinds(request.tenant, isModuleEnabled)` from `@working-theory/metadata`: `{ kinds: [{ kind, address, fields, moreFields, sectionTypes, states, moves }] }`, one entry per kind of `ADMIN_KIND_REGISTRY` (`@working-theory/validation`) — page, document, language_item, magnet, asset — whose address, fields and states are read off that kind's own schemas, and whose `moves` are the catalog rows tagged with the kind, kept only when the row's gate holds for the CLAMPED tenant the guard built (never an agent's stored grants or a token's raw scopes) and one of its modules runs on this hub; a page's `sectionTypes` names `list_section_types` rather than repeating it. Advice, never an entitlement: no write path may gate on it. MCP parity: `list_kinds` on `/mcp/workspace`.
109
+ - `/v1/workspaces/:workspaceId/kinds` (GET) — the kinds read (#11805; the same file and scope), any tenant of the workspace, no query, no row read. It answers `listKinds(request.tenant, isModuleEnabled)` from `@working-theory/metadata`: `{ kinds: [{ kind, address, fields, moreFields, sectionTypes, states, moves }] }`, one entry per kind of `ADMIN_KIND_REGISTRY` (`@working-theory/validation`) — page, document, language_item, magnet, asset — whose address, fields and states are read off that kind's own schemas, and whose `moves` are the catalog rows tagged with the kind, kept only when the row's gate holds for the CLAMPED tenant the guard built (never an agent's stored grants or a token's raw scopes) and one of its modules runs on this hub; a page's `sectionTypes` names `list_section_types` rather than repeating it. Beside `kinds` (#11878) it answers `forms` (`[{ kind, field, values }]` — each kind's form field and its values, read off that field's own schema through `KIND_FORMS`, then an offering's `ailkGroup` and an appointment with no form), `offSiteForms` (`[{ form, formats }]`), `formats` and `origins`, all from `adminKinds()` and the same for every caller and hub. Advice, never an entitlement: no write path may gate on it. MCP parity: `list_kinds` on `/mcp/workspace`.
109
110
  - `/v1/workspaces/:workspaceId/assets` (GET, POST), `/v1/workspaces/:workspaceId/assets/:assetId` (PATCH, DELETE), `/v1/assets/:assetId` (GET, public/anonymous) — the workspace asset store (#5854 upload/read; #6093 list/PATCH/DELETE, `src/routes/assets/{index,upload,read,manage}.ts`). Upload accepts an allowlisted union of three named classes (`src/routes/assets/index.ts`): five RASTER images (`image/png`, `image/jpeg`, `image/gif`, `image/webp`, `image/avif`), one VECTOR image (`image/svg+xml`, admitted under the operator's 2026-09-18 `allow-svg-assets` ruling — issue #6093 comment `5731573595` — superseding #5854's original SVG exclusion) and one DOCUMENT type (`application/pdf`), all under the existing 20 MB cap; `?tags=<slug>[,<slug>…]` stores tags on the row. The public read serves a RASTER type `inline` exactly as before; every OTHER admitted type (SVG, PDF) is served `attachment`, with the filename's extension pinned to the stored content type (closing extension spoofing) and a five-directive `Content-Security-Policy` (`default-src 'none'; sandbox; frame-ancestors 'none'; form-action 'none'; base-uri 'none'`) that makes the bytes never a document on this origin — this is what makes admitting SVG safe with NO server-side sanitizer. `GET …/assets` (`assets-read` — every role, a member included) lists a workspace's assets, metadata only, never `bytes`, with an optional `?tag=<slug>` filter; this is what narrows the store's prior "nothing lists assets" premise to its precise form — no ANONYMOUS and no CROSS-TENANT enumeration, both still true. `PATCH …/assets/:assetId` updates `title`/`description`/`tags` (`assets-write`, owner and admin, the upload's permission too; `null` clears a text field to SQL `NULL`, `""` stores empty; the asset's `id` and public URL are untouched). `DELETE …/assets/:assetId` (`assets-write`) removes the row and the bytes at the ORIGIN only — already-cached copies elsewhere are not recallable under the year-long `immutable` promise, and no reference check protects a page that still embeds the URL; absent and foreign ids both take the same 404. Every tenant route here is identity-bound; no MCP twin (#3591 exception). The public read has no MCP twin either — it serves bytes to an `<img>`/download, the same boundary `upload.ts` records for its own sibling. **A client's file is never in the library's public life (#7877 D18):** the default `GET …/assets` listing leaves out every asset tagged `private` — only `?tag=private` lists them (the Admin's Compose) — and the public read answers its uniform 404 for an asset tagged `private`, attached to any member-area message, or (#8171 D3) named by a delivered piece version (one `pieceVersion.count`, since the tag can be removed after delivery), so such a file's bytes are served only by its owner's member reads.
110
111
  - `/v1/subscription/me` (GET) — `?include=billing` (#8171 D7), from a cookie session only, adds the optional `planName` and `paymentMethod` (brand, last four, expiry) read from Stripe through `lib/stripe.ts`'s `readCustomerBillingSummary` for the caller's own resolved customer: cached per customer for 60 s (a failure too), one read in flight per customer, bounded at 3 s; a failure leaves both keys absent, a value outside the schema's bounds is `null`, and no id is served or logged. A bearer token, another value or none answers exactly as before.
111
112
  - `/v1/billing` (GET), `/v1/billing/portal-session` (POST) — org-scoped billing read + Stripe customer-portal session creation. The read stays open to every member (the Admin's plan gate reads it); the portal needs `billing-manage` — the owner alone (`@working-theory/validation`'s permission table (#7636 D2); an admin is refused before any Stripe call). `/v1/billing/usage` (GET) needs `billing-read` (owner, admin). **The read's `commerce` field (#8907 D14)** is the deployment's commerce claim, `claimed | unclaimed | undetermined` (`resolveCommerceClaim()`; a rejected read is `undetermined` and the answer stays `200`) — what the Admin's Billing card reads (#8908 D10). **`?include=billing` (#9067 D1)** — exactly that string, never an array — adds `details` only for a caller holding `billing-manage` (the owner; an agent never qualifies): `licenseExpiresAt` (`checkLicense().expiresAt`, `null` on a failed read) always, and for an Organization with a Stripe customer `renewsAt` (the current subscription's first item's `current_period_end`, only while it will renew), `sites` (its quantity) and `paymentMethod` (brand, last four, expiry), read through `lib/stripe.ts`'s `readCustomerBillingSummary` by `services/entitlements.ts`'s `readOrgBillingSummary` — cached per customer for 60 s (a failure too), one read in flight per customer, bounded at 3 s; a failure answers `details: { licenseExpiresAt }` and still `200`, a value outside `orgBillingDetailsSchema`'s bounds is `null`, no id is served or logged, and the reply carries `Cache-Control: private, no-store`. Every other request is answered exactly as before, with no Stripe or licence read. **`POST /v1/billing/plan-checkout` (#9067 D3, `routes/billing/plan-checkout.ts`)** is the Billing tab's Purchase plan: a subscription Checkout for the caller's own Organization's plan (`planPurchaseLookupKey` — `ailk-pro_monthly` / `ailk-pro-plus_monthly`, `PLAN_PURCHASE_LOOKUP_KEYS` built by the Offerings lookup-key grammar, #9338 DD1), on the admitted key like the portal (#8463). **It sells only an Offerings plan (#9338 DD4):** `createCheckoutSession` gets a `refuseProduct` that refuses every Product whose `metadata.ailk_group` is not exactly `plan` (`isOfferingsPlanProduct`, `services/offerings/catalog.ts`), checked on the same expanded Price it sells; a refused or unexpanded Product answers `500 plan_price_missing`. Check order: tenant → `billing-manage` (403 before any lookup) → write budget (`chargeWriteBudget` scope `plancheckout`, 10 an hour per Organization and per person, `429` with `Retry-After`) → the commerce claim (`409 purchase_unavailable`, `503 license_undetermined`) → a strict `{ returnUrl }` (`bodyLimit` 4 KiB, `400 validation_failed`) → the return URL (canonical, no userinfo, query, fragment or `//` path, `https:` or a local `http:`, on `config.TRUSTED_ORIGINS`; `400 return_url_refused`, `500 config-error` when none is trusted) → no customer yet (`409 billing_customer_exists`) and a purchasable tier (`409 plan_not_purchasable`) → `STRIPE_SECRET_KEY` and `assertAdmittedStripeKey` → one payable session (an open earlier one is expired first, a completed one is `409 purchase_pending`) → `createCheckoutSession` with `mode: "subscription"`, 1–50 sites, `metadata` and `subscriptionMetadata` `{ organizationId, ...siteStamp() }` and `PLATFORM_TERMS_OF_SERVICE`, never a `buyer` → a Checkout URL only → the session id recorded on `Organization.planCheckoutSessionId` by compare-and-set (a lost race or a failed write expires the new session). It answers `{ url }` with `Cache-Control: private, no-store`; no body or log line carries the return URL, an id or a Stripe message. **The webhook's Organization arm binds only that recorded session (#9067 D13):** a `checkout.session.completed` with `metadata.organizationId` links `session.customer` through one guarded `updateMany` on `{ id, planCheckoutSessionId: session.id, billingCustomerId: null }` (clearing the session); anything else — an unrecorded session, a bound customer, every `customer.created` — writes nothing and logs `org_bind_unproven`. No MCP twin for the purchase — owner-only, recorded in `tests/parity/README.md`.
@@ -244,7 +245,11 @@ sweep's own DB constraint (never a caller-side lock).
244
245
  - Don't bundle `apps/api` (esbuild, rollup, webpack). Slice specifiers cannot survive it — see `## Deploy path`.
245
246
  - Don't construct Fastify with `logger: true` or any `logger:` option. Pass `loggerInstance` built from `createLogger` in `@working-theory/observability` (see `packages/api/src/server.ts`). Fastify's own pino carries none of the redaction.
246
247
 
247
- Last updated: 2026-11-17 — #11809: the Language-item and file open routes (`…/language/:kind/:slug/open`, `…/assets/open`) and their twins, and the blank `open_page` and `open_document` (#11808) answer where they answered 404 — verified against `packages-paid/api-content-write/src/routes/workspaces/content.ts`, `packages-paid/api-workspace/src/routes/workspaces/language.ts`, `packages-paid/api-workspace/src/routes/assets/manage.ts` and `packages/metadata/src/mcp-tool-catalog.ts`.
248
+ Last updated: 2026-11-17 — #11882: both open routes take the query key `as` in place of `form`, which stays their old name for one release; `as` and `form` sent with different values are `422 invalid` at `as` — verified against `packages/validation/src/schemas/content-draft.ts` and `packages-paid/api-content-write/src/routes/workspaces/content.ts`.
249
+
250
+ Prior: 2026-11-17 — #11878: the kinds bullet names the four lists beside `kinds` — `forms`, `offSiteForms`, `formats`, `origins` — and their source — verified against `packages/validation/src/contract/admin-kinds.ts`, `packages/validation/src/schemas/page-types.ts` and `packages/metadata/src/mcp-tool-catalog.ts`.
251
+
252
+ Prior: 2026-11-17 — #11809: the Language-item and file open routes (`…/language/:kind/:slug/open`, `…/assets/open`) and their twins, and the blank `open_page` and `open_document` (#11808) answer where they answered 404 — verified against `packages-paid/api-content-write/src/routes/workspaces/content.ts`, `packages-paid/api-workspace/src/routes/workspaces/language.ts`, `packages-paid/api-workspace/src/routes/assets/manage.ts` and `packages/metadata/src/mcp-tool-catalog.ts`.
248
253
 
249
254
  Prior: 2026-11-17 — #11810: the magnets bullet names `POST …/magnets/save` as `save_magnet`'s twin (an `id` saves, none and `version: null` creates a draft), the PATCH and the create as having no tool, and the create's `403 agent_refused` for an agent — verified against `packages-paid/api-signal-collectors/src/routes/magnets/index.ts`, `packages/metadata/src/mcp-tool-catalog.ts` and `tests/parity/api-parity/kinds/site.ts`.
250
255
 
@@ -209,7 +209,7 @@ here. Spec: `docs/specs/3591-tenant-scoped-agent-auth-secure-spec.md` D13–D16.
209
209
  tools, `list_proposals` and `create_proposal`, twinning `GET`/`POST
210
210
  /v1/workspaces/:workspaceId/people/:personId/proposals` with the same grant: a proposal is
211
211
  private to one client, `payments` says whether approval leads to a Stripe page, and an agent's
212
- price is refused `proposal_needs_person` (a person prices) — and (#10957) `send_person_message`, twinning `POST …/people/:personId/messages`: one message on a client's member feed, saved then emailed (an agent's only to a proved address), needing `inbox-act` with `people-read` or `member-pieces-manage`, and `assets-write` for a file; the operator's message list has no tool, by decision — and (#9681) the four person-thread tools, `get_person_thread`, `set_person_thread_state`, `list_external_threads` and `add_external_thread`, twinning `GET`/`PATCH …/people/:personId/thread` and `GET`/`POST …/people/:personId/external-threads`: a client's whole thread page by page with its read/archived/resolved state, and pointers to email and Slack threads (never message text); reading needs the `people-read` grant, writing also `inbox-act`, and the client erasure route has no tool, by decision — and (#9682) the three person-memory tools, `list_person_memories`, `get_person_memory` and `propose_person_memory`, twinning `GET …/people/:personId/memories`, `GET …/memories/:path` and `POST …/memories`: an agent reads only live, unexpired memories (confirmed by a person, read within 180 days) and its proposal is never live — a new path is a draft, a confirmed one gets a pending version — needing the `people-read` or `people-memory-propose` grant to read and `people-memory-propose` to propose; the six person-only memory routes (edit, delete, confirm, redact, the versions list, restore) have no tool, by decision — and (#9749) `get_slack_connection_status`, twin of `GET /v1/workspaces/:workspaceId/slack-connection` (registered with `workspace`/`multi-tenant`, its route's `TENANCY` row: whether the Organization's Slack is connected, its team name and the date, never a credential; connect and disconnect are a person's act and have no tool, by decision), and `get_prospect_channel_settings` / `set_prospect_channel_settings`, twins of `GET`/`PUT …/prospect-channel` (registered with `scheduling`, their routes' module): the update replaces every field, needs the `meeting-types-manage` grant, is refused `slack_not_connected` while the Organization has no Slack connection, and an agent may change only `enabled`, `channelPrefix` and `archiveDays` — a change to `memberIds` or `welcomeTemplate` is refused `prospect_channel_needs_person` — and (#10950) the three meeting tools, `list_meeting_types`, `save_meeting_types` and `list_appointments`, twinning `GET`/`PUT …/meetings` and `GET /v1/schedule/appointments` (registered with `scheduling`): the meeting types from the connected calendar, each with whether it is Live (`enabled`) and who can book it (`visibility`: `public`, `private` or `authenticated`), the provider's `providerEventTypeId` and `createdAt` when it serves them, and, with the `meeting-types-manage` grant, `providerEditUrl` — the read takes no `include` (#11122 D4); the save needs that grant and its required `enabledSlugs` replaces the Live list, while `customerSlugs` (Authenticated) and `privateSlugs` (Private) are exclusive — a slug in both is refused — and an omitted one keeps the stored list less the sent list's slugs, and no price is set there; the appointments read is every role's, and an agent's only with the `people-read` grant (#10986), takes `eventTypeId` for one type's bookings (#11122 D12) and `workspaceId` when the connection reaches several workspaces (#11753), and its attendee names and emails are public-written text; the three scheduling-connection routes have no tool, by decision — and (#10218) the content-suggestion pair, `draft_page_suggestions` and `decide_page_suggestion` — and (#10336) the draft pair, `save_draft` and `read_report`, twinning `PATCH`/`GET …/content/:type/:slug` with the `content-edit` grant: `save_draft` takes the page's `content` whole as the PATCH body and its `version` as `X-Draft-Version`, writes a draft version that never goes live, and answers 409 `conflict` with `currentVersion` when the draft moved; `read_report` returns the draft tip, the version a save must send, the page's stored layout (`structure`, #10962) and the token `save_structure` must send, its open suggestions and the route's check report (`ready`, `needs repair` or `needs your words`), computed by the route and never by the tool — and (#10956) `create_page`, twinning `POST …/content` with the `content-edit` grant: it creates a page and its first draft from `content` sent whole (its `type` and `slug` are the address) — a page type laid out in sections sent no words (no body, an empty one, or only its template's headings) starts from its template (#11793): the hub lays out the template's sections, each headed by its default headline with an empty field to write under, and stores the words and the layout together, refusing a title or description the words rules refuse, or a `sections` key, 422 `invalid` — never publishes, and answers 409 `conflict` when the page exists and 409 `slug_taken` when another page holds the link — and (#11791) `save_page`, twinning `PUT …/content/:type/:slug` with the `content-edit` grant, under the common names of `docs/internal/decisions/one-way-common-names.md`: it saves a page laid out in sections — its `fields` and its `words` (its sections in order, each `{ id, type, data }`) — in one draft version that holds the body the hub builds from the words and the layout together; `address` (type, slug, locale) rides the URL, and `version` with `structureToken` is what the save was based on, both `null` for a new page; a save whose basis is no longer the tip, or `null` for a page that exists, answers 409 `stale` with `currentVersion` and `currentStructureToken`, and a wrong field or word 422 `invalid` with `issues` (`path`, `message`), the one refusal pair whose details reach the tool; it never publishes; since #11811 it also saves an editorial page, whose `words` are `{ body }`, its Markdown, carrying the stored layout forward; since #11808 (#11852) a page laid out in sections may send `workingCopy`, `{ document, settings }` — the two tabs of a working copy as exported — in place of `fields` and `words`: the hub converts it against the tip it was based on (409 `stale` before converting), keeps the stored fields a Settings table cannot carry, refuses a wrong copy 422 `invalid` at `workingCopy.settings`, `workingCopy.document` or the envelope path, and answers the page as a working copy — and (#11811) `save_document`, twinning `POST …/documents/save` with the `content-edit` grant: it saves a `Document` (Instructions, Knowledge or a plugin-owned document) in the same common shape — `address` (`type` always `Document`, slug, locale) rides the body, as `save_asset`'s does, `version` is `null` for a new document, `fields` are the page save's, and `words` is `{ body }`; a moved tip or a `null` on an existing document answers 409 `stale` with `currentVersion` alone, and a wrong field or word — a plugin contract's misfit included, each issue at its path (`fields.contract_version`, `words.body`) — 422 `invalid`, both details rebuilt in `workspace-server.ts`; a document never goes live; since #11808 it takes, at a plugin-owned contract address only, `workingCopy` (`{ document, settings }`, the two tabs of a working copy as exported) in place of `fields` and `words`, which the hub converts against the tip it was based on and answers in the same form (the record form when the copy would outgrow its bounds) — and (#11808) `open_document`, twinning `GET …/documents/open` with the `content-edit` grant: the read twin of `save_document`, its `address` in the query, answering the envelope in the record form or, with `form: "working-copy"` and only at a plugin-owned address (else 422 `invalid` at `form`), the working copy (409 `not_representable` when it would outgrow its bounds); it never writes, and its `invalid` keeps `issues` (`path`, `message`, each cut to 200 characters). — and (#11809) `open_language_item` and `open_asset` (`mcp-workspace`'s `language.ts` and `library.ts`), twinning `GET …/language/:kind/:slug/open` and `GET …/assets/open` under the gate of the read each parallels (`docs-read`, `assets-read`): each takes `{ workspaceId, address }` (plus `locale` for an item) and answers the thing in the common envelope with the `version` its save takes, or — nothing at the address, or nothing the caller may read there — an item's blank, `version: null` and its kind's empty words, which the save with `version: null` starts; a file is never blank (`404 not_found`); and `open_page` and `open_document` answer the same kind of blank where they answered 404 — a page its template's starting sections, headed by the slug, and a document at a plugin-owned contract address its contract's constant fields and required headings, else nothing; no open writes, and the section map lists `open_` tools as reads. While both ways live, `create_page`, `save_draft` and `save_structure` open their descriptions with a deprecation naming `save_page` or `save_document`; nothing else about them changes until the removal (#11811 D2, D6) — and (#10661) `publish_draft`, twinning `POST …/content/:type/:slug/publish` with the `content-publish` grant: it publishes the draft tip (or a named version) exactly as a person holding that permission does, an agent without the grant is refused 403 `agent_refused` before anything is read, and it never widens Audience or re-enables a doc — and (#10345) the knowledge-base pair, `read_knowledge` and `read_knowledge_doc`, twinning `GET …/knowledge-base` and `GET …/knowledge-base/:type/:slug` with no grant (`docs-read` is every role's): the docs a named member may read (`userId`, by default the agent's own person), at the lower of the agent's person's role and that member's, so naming someone only narrows; Live does not gate them and a disabled doc never appears; `filter: "workspace-memory"` answers the always-loaded set with its `totalTokens` and an 8000-token `warning` — and (#10951) `get_workspace_settings`, twin of `GET /v1/workspaces/:workspaceId/general` (`mcp-workspace`'s `workspace_settings.ts`, no grant): the workspace's name, its own logo (`null` when the organization's applies) and the deployment's deliverable sender (`null` when none is configured, so a magnet's results and completion emails do not go out); the PUT, which renames the workspace and sets its logo, has no tool, by decision — it needs `workspace-settings`, which is never agent-grantable — and (#11806) `get_workspace_overview`, twin of `GET /v1/workspaces/:workspaceId/overview` (`mcp-workspace`'s `workspace_overview.ts`, registered with `workspace` or `multi-tenant`, `gate: "tenant"`, no query): a command's starting picture in one call — the site identity's name and SEO description, the default locale, the Knowledge docs `read_knowledge` lists for the caller with each one's draft `version` where `read_report` would answer it (`content-edit`, and the caller's own role reads the doc), and the Language items by kind and the magnets by state (`draft` only with `magnets-manage`); a part the caller's grants or the site's modules do not allow is `null` or left out and named in `withheld` (`grant` or `module`), never a refusal of the read — and the six site-profile tools, `get_site_identity`, `set_site_identity`, `get_site_seo`, `set_site_seo`, `get_welcome_email` and `set_welcome_email` (`mcp-workspace`'s `site_profile.ts`), twinning `GET`/`PUT …/identity`, `…/seo` and `…/welcome-email`: any member reads; each write needs the `site-profile` grant (`ailk:site-profile`), under which every logo and every SEO field but the description — robots and indexing above all — must be sent as read, else `site_profile_field_locked`; the theme pair has no tool, by decision — and (#10733, issue 10905, #10952) the six Language tools, `list_language_items`, `get_language_item`, `save_language_item`, `set_language_item_live`, `list_language_item_pages` and `get_topic_brief`, twinning `GET …/language`, `GET`/`PUT …/language/:kind/:slug`, `POST …/language/:kind/:slug/live`, `GET …/language/:kind/:slug/appears-on` and `GET …/language/topic/:slug/brief` (`mcp-workspace`'s `language.ts`): a workspace's glossary terms, FAQs and topics; reading needs no grant, saving the `content-edit` grant (`version: null` creates, a tip id updates, 409 `slug_taken` / `stale` otherwise), the Live switch `content-publish` with the `version` the person reviewed — `live: false` is how an agent takes an item off the site; the `DELETE` has no tool, by decision (#11802): it is permanent (nothing restores the item and its slug stays taken), so a person deletes in the Admin and the route refuses every agent `agent_refused`; tags are the hub's and never written by a tool; a topic is a keyword cluster for agents and is never shown to visitors, and `get_topic_brief` reads it as a writing brief — its kept rows scored best bets first, from the Live version when Live; the Topic's Keyword Planner import and the value-thresholds pair are a person's and have no tool, by decision — and (#10948) the three magnet tools, `list_magnets`, `get_magnet` and `save_magnet`, twinning `GET …/magnets`, `GET …/magnets/:id` and (#11810) `POST …/magnets/save` (`mcp-workspace`'s `magnets.ts`, registered with `multi-tenant` or `signal-collectors`): with the `magnets-manage` grant every magnet in full, without it only live ones as `{ id, slug, kind, title, landingPage, tags }`; `save_magnet` takes the save body whole, the magnet's `id` in it, so going live is `status: "live"` and the route alone refuses it (`402 plan_required`, `409 conversion_needs_email`), and an agent cannot set or change what a magnet charges (`403 magnet_pricing_needs_person`); with no `id` and `version: null` it creates a draft magnet — a slug another magnet holds is `409 stale` with its `currentVersion`, a slug the site reads by name `409 slug_reserved`, and the plan check is the Admin create's; the Admin's PATCH and create (which refuses every agent `403 agent_refused`) and the four captured-people lists have no tool, by decision — and (#10949) `get_workspace_offerings`, twin of `GET /v1/workspaces/:workspaceId/offerings` (registered with `multi-tenant` alone, its route's module; `mcp-workspace`'s `offerings.ts`): the Offerings tab's view — unavailable with `no_commerce` or `no_connection`, or the Organization's enabled products with this workspace's shown Prices and Recommended — read with no grant; its PUT, which switches a Price on or off, needs `workspace-settings`, which is never agent-grantable, and has no tool, by decision — and the two library reads, `list_workspace_pages` and `list_assets` (`mcp-workspace`'s `library.ts`, registered with `workspace` or `multi-tenant`), twinning `GET …/library/pages` and `GET …/library/assets`: every page with drafts included and its status (`live`, `draft`, or `disabled` — a person editor's alone), needing the `content-edit` grant, and the asset library read-only with each file's whole record (#11801) — its public path, title, description and record version, its size, an image's pixel size as the Admin's Details panel shows it, and its audience — for every role; both filter, page and name the workspace `{ id, name }` they read, and uploading has no tool — and (#11803) `save_asset` (`library.ts`, `gate: { allows: "assets-write" }`), twinning `POST …/assets/save`: it saves a file's title and description by its key, based on the record version `list_assets` returned; a stale save is `409 stale` and its tool error carries `details.currentVersion`, a wrong argument `422 invalid` with `details.issues` (`{ path, message }`, at most twenty, each cut to 200 characters, rebuilt in `workspace-server.ts`); it never replaces, renames, re-privacies or deletes a file, and never reaches a private, Knowledge or disabled one — and (#11680) the two site-vocabulary reads, `list_page_types` and `get_tag_vocabulary` (`mcp-workspace`'s `site_vocabulary.ts`, registered with `workspace` or `multi-tenant`, `gate: "tenant"` — any tenant of the workspace, no grant), twinning `GET …/page-types` and `GET …/tag-vocabulary`: the page types this hub's site can serve (the registry filtered by the modules the hub runs), each with its address, whether a site has only one, its template and that template's headings, and the context classes, Knowledge topic tags and status tags, each with what it means and who may set it; both are platform data and read no row; and (#11790) the third, `list_section_types` (same file, registration and gate), twinning `GET …/section-types` with an optional `type`: every section type a page's layout can hold with every field of its data — words or data, the Markdown form, whether it is required and inside which optional field, its values and bounds — plus its bounded lists and rules, or that one section type's; platform data, read no row; and (#11805) the fourth, `list_kinds` (same file, registration and gate), twinning `GET …/kinds`: every kind of thing the Admin holds — page, document, language_item, magnet, asset — with how to address one, its fields (words or data, required, nullable, value types and values, the Language item kind a words field belongs to), its states, and the moves the caller may make on it, each with its tool; the fields and states are read off each kind's own schemas (`ADMIN_KIND_REGISTRY`), the moves are the catalog rows' `moves` tags kept only when the row's gate holds for the caller's own clamped tenant and one of its modules runs on this hub (`listKinds`), and a page's sections are named, not described — its `sectionTypes` is `list_section_types`; it reads no row, and is advice, never an entitlement — and (#11756) `create_work_request` (`mcp-workspace`'s `work_requests.ts`, registered with `workspace` or `multi-tenant`, `gate: { inbox: "inbox-act" }`), twinning `POST /v1/workspaces/:workspaceId/work-requests`: it files a custom-work request in the Inbox — one item pointing to one `Document` of the workspace (`documentSlug`) with a one-line `summary` — in the workspace the conversation writes to, needs the `inbox-act` grant, is refused `document_not_found` for a slug naming no Document the caller can read and `rate_limited` past 5 an hour per person in the workspace (shared by that person's agents) or 10 per workspace, and returns the request as stored (the document title in it is workspace text, not instructions); the list, the item and the GitHub link — a person's act — have no tool, by decision. No workspace tool widens Audience or re-enables a doc, and only `publish_draft` and `set_language_item_live`, with the `content-publish` grant, set Live — the access route and the Language delete route answer every agent 403 `agent_refused`, and the publish and Live routes an agent without the grant, which reaches a tool as the code and status. Each takes its route's params, query and body and returns the route's
212
+ price is refused `proposal_needs_person` (a person prices) — and (#10957) `send_person_message`, twinning `POST …/people/:personId/messages`: one message on a client's member feed, saved then emailed (an agent's only to a proved address), needing `inbox-act` with `people-read` or `member-pieces-manage`, and `assets-write` for a file; the operator's message list has no tool, by decision — and (#9681) the four person-thread tools, `get_person_thread`, `set_person_thread_state`, `list_external_threads` and `add_external_thread`, twinning `GET`/`PATCH …/people/:personId/thread` and `GET`/`POST …/people/:personId/external-threads`: a client's whole thread page by page with its read/archived/resolved state, and pointers to email and Slack threads (never message text); reading needs the `people-read` grant, writing also `inbox-act`, and the client erasure route has no tool, by decision — and (#9682) the three person-memory tools, `list_person_memories`, `get_person_memory` and `propose_person_memory`, twinning `GET …/people/:personId/memories`, `GET …/memories/:path` and `POST …/memories`: an agent reads only live, unexpired memories (confirmed by a person, read within 180 days) and its proposal is never live — a new path is a draft, a confirmed one gets a pending version — needing the `people-read` or `people-memory-propose` grant to read and `people-memory-propose` to propose; the six person-only memory routes (edit, delete, confirm, redact, the versions list, restore) have no tool, by decision — and (#9749) `get_slack_connection_status`, twin of `GET /v1/workspaces/:workspaceId/slack-connection` (registered with `workspace`/`multi-tenant`, its route's `TENANCY` row: whether the Organization's Slack is connected, its team name and the date, never a credential; connect and disconnect are a person's act and have no tool, by decision), and `get_prospect_channel_settings` / `set_prospect_channel_settings`, twins of `GET`/`PUT …/prospect-channel` (registered with `scheduling`, their routes' module): the update replaces every field, needs the `meeting-types-manage` grant, is refused `slack_not_connected` while the Organization has no Slack connection, and an agent may change only `enabled`, `channelPrefix` and `archiveDays` — a change to `memberIds` or `welcomeTemplate` is refused `prospect_channel_needs_person` — and (#10950) the three meeting tools, `list_meeting_types`, `save_meeting_types` and `list_appointments`, twinning `GET`/`PUT …/meetings` and `GET /v1/schedule/appointments` (registered with `scheduling`): the meeting types from the connected calendar, each with whether it is Live (`enabled`) and who can book it (`visibility`: `public`, `private` or `authenticated`), the provider's `providerEventTypeId` and `createdAt` when it serves them, and, with the `meeting-types-manage` grant, `providerEditUrl` — the read takes no `include` (#11122 D4); the save needs that grant and its required `enabledSlugs` replaces the Live list, while `customerSlugs` (Authenticated) and `privateSlugs` (Private) are exclusive — a slug in both is refused — and an omitted one keeps the stored list less the sent list's slugs, and no price is set there; the appointments read is every role's, and an agent's only with the `people-read` grant (#10986), takes `eventTypeId` for one type's bookings (#11122 D12) and `workspaceId` when the connection reaches several workspaces (#11753), and its attendee names and emails are public-written text; the three scheduling-connection routes have no tool, by decision — and (#10218) the content-suggestion pair, `draft_page_suggestions` and `decide_page_suggestion` — and (#10336) the draft pair, `save_draft` and `read_report`, twinning `PATCH`/`GET …/content/:type/:slug` with the `content-edit` grant: `save_draft` takes the page's `content` whole as the PATCH body and its `version` as `X-Draft-Version`, writes a draft version that never goes live, and answers 409 `conflict` with `currentVersion` when the draft moved; `read_report` returns the draft tip, the version a save must send, the page's stored layout (`structure`, #10962) and the token `save_structure` must send, its open suggestions and the route's check report (`ready`, `needs repair` or `needs your words`), computed by the route and never by the tool — and (#10956) `create_page`, twinning `POST …/content` with the `content-edit` grant: it creates a page and its first draft from `content` sent whole (its `type` and `slug` are the address) — a page type laid out in sections sent no words (no body, an empty one, or only its template's headings) starts from its template (#11793): the hub lays out the template's sections, each headed by its default headline with an empty field to write under, and stores the words and the layout together, refusing a title or description the words rules refuse, or a `sections` key, 422 `invalid` — never publishes, and answers 409 `conflict` when the page exists and 409 `slug_taken` when another page holds the link — and (#11791) `save_page`, twinning `PUT …/content/:type/:slug` with the `content-edit` grant, under the common names of `docs/internal/decisions/one-way-common-names.md`: it saves a page laid out in sections — its `fields` and its `words` (its sections in order, each `{ id, type, data }`) — in one draft version that holds the body the hub builds from the words and the layout together; `address` (type, slug, locale) rides the URL, and `version` with `structureToken` is what the save was based on, both `null` for a new page; a save whose basis is no longer the tip, or `null` for a page that exists, answers 409 `stale` with `currentVersion` and `currentStructureToken`, and a wrong field or word 422 `invalid` with `issues` (`path`, `message`), the one refusal pair whose details reach the tool; it never publishes; since #11811 it also saves an editorial page, whose `words` are `{ body }`, its Markdown, carrying the stored layout forward; since #11808 (#11852) a page laid out in sections may send `workingCopy`, `{ document, settings }` — the two tabs of a working copy as exported — in place of `fields` and `words`: the hub converts it against the tip it was based on (409 `stale` before converting), keeps the stored fields a Settings table cannot carry, refuses a wrong copy 422 `invalid` at `workingCopy.settings`, `workingCopy.document` or the envelope path, and answers the page as a working copy — and (#11811) `save_document`, twinning `POST …/documents/save` with the `content-edit` grant: it saves a `Document` (Instructions, Knowledge or a plugin-owned document) in the same common shape — `address` (`type` always `Document`, slug, locale) rides the body, as `save_asset`'s does, `version` is `null` for a new document, `fields` are the page save's, and `words` is `{ body }`; a moved tip or a `null` on an existing document answers 409 `stale` with `currentVersion` alone, and a wrong field or word — a plugin contract's misfit included, each issue at its path (`fields.contract_version`, `words.body`) — 422 `invalid`, both details rebuilt in `workspace-server.ts`; a document never goes live; since #11808 it takes, at a plugin-owned contract address only, `workingCopy` (`{ document, settings }`, the two tabs of a working copy as exported) in place of `fields` and `words`, which the hub converts against the tip it was based on and answers in the same form (the record form when the copy would outgrow its bounds) — and (#11808) `open_document`, twinning `GET …/documents/open` with the `content-edit` grant: the read twin of `save_document`, its `address` in the query, answering the envelope as the record or, with `as: "working-copy"` and only at a plugin-owned address (else 422 `invalid` at the key sent), the working copy (409 `not_representable` when it would outgrow its bounds); since #11882 `open_page` and `open_document` take `as` where they took `form`, which stays the old name for one release (the catalog keeps it, so the SDK never strips it), and the route refuses the two sent with different values 422 `invalid` at `as`; it never writes, and its `invalid` keeps `issues` (`path`, `message`, each cut to 200 characters). — and (#11809) `open_language_item` and `open_asset` (`mcp-workspace`'s `language.ts` and `library.ts`), twinning `GET …/language/:kind/:slug/open` and `GET …/assets/open` under the gate of the read each parallels (`docs-read`, `assets-read`): each takes `{ workspaceId, address }` (plus `locale` for an item) and answers the thing in the common envelope with the `version` its save takes, or — nothing at the address, or nothing the caller may read there — an item's blank, `version: null` and its kind's empty words, which the save with `version: null` starts; a file is never blank (`404 not_found`); and `open_page` and `open_document` answer the same kind of blank where they answered 404 — a page its template's starting sections, headed by the slug, and a document at a plugin-owned contract address its contract's constant fields and required headings, else nothing; no open writes, and the section map lists `open_` tools as reads. While both ways live, `create_page`, `save_draft` and `save_structure` open their descriptions with a deprecation naming `save_page` or `save_document`; nothing else about them changes until the removal (#11811 D2, D6) — and (#10661) `publish_draft`, twinning `POST …/content/:type/:slug/publish` with the `content-publish` grant: it publishes the draft tip (or a named version) exactly as a person holding that permission does, an agent without the grant is refused 403 `agent_refused` before anything is read, and it never widens Audience or re-enables a doc — and (#10345) the knowledge-base pair, `read_knowledge` and `read_knowledge_doc`, twinning `GET …/knowledge-base` and `GET …/knowledge-base/:type/:slug` with no grant (`docs-read` is every role's): the docs a named member may read (`userId`, by default the agent's own person), at the lower of the agent's person's role and that member's, so naming someone only narrows; Live does not gate them and a disabled doc never appears; `filter: "workspace-memory"` answers the always-loaded set with its `totalTokens` and an 8000-token `warning` — and (#10951) `get_workspace_settings`, twin of `GET /v1/workspaces/:workspaceId/general` (`mcp-workspace`'s `workspace_settings.ts`, no grant): the workspace's name, its own logo (`null` when the organization's applies) and the deployment's deliverable sender (`null` when none is configured, so a magnet's results and completion emails do not go out); the PUT, which renames the workspace and sets its logo, has no tool, by decision — it needs `workspace-settings`, which is never agent-grantable — and (#11806) `get_workspace_overview`, twin of `GET /v1/workspaces/:workspaceId/overview` (`mcp-workspace`'s `workspace_overview.ts`, registered with `workspace` or `multi-tenant`, `gate: "tenant"`, no query): a command's starting picture in one call — the site identity's name and SEO description, the default locale, the Knowledge docs `read_knowledge` lists for the caller with each one's draft `version` where `read_report` would answer it (`content-edit`, and the caller's own role reads the doc), and the Language items by kind and the magnets by state (`draft` only with `magnets-manage`); a part the caller's grants or the site's modules do not allow is `null` or left out and named in `withheld` (`grant` or `module`), never a refusal of the read — and the six site-profile tools, `get_site_identity`, `set_site_identity`, `get_site_seo`, `set_site_seo`, `get_welcome_email` and `set_welcome_email` (`mcp-workspace`'s `site_profile.ts`), twinning `GET`/`PUT …/identity`, `…/seo` and `…/welcome-email`: any member reads; each write needs the `site-profile` grant (`ailk:site-profile`), under which every logo and every SEO field but the description — robots and indexing above all — must be sent as read, else `site_profile_field_locked`; the theme pair has no tool, by decision — and (#10733, issue 10905, #10952) the six Language tools, `list_language_items`, `get_language_item`, `save_language_item`, `set_language_item_live`, `list_language_item_pages` and `get_topic_brief`, twinning `GET …/language`, `GET`/`PUT …/language/:kind/:slug`, `POST …/language/:kind/:slug/live`, `GET …/language/:kind/:slug/appears-on` and `GET …/language/topic/:slug/brief` (`mcp-workspace`'s `language.ts`): a workspace's glossary terms, FAQs and topics; reading needs no grant, saving the `content-edit` grant (`version: null` creates, a tip id updates, 409 `slug_taken` / `stale` otherwise), the Live switch `content-publish` with the `version` the person reviewed — `live: false` is how an agent takes an item off the site; the `DELETE` has no tool, by decision (#11802): it is permanent (nothing restores the item and its slug stays taken), so a person deletes in the Admin and the route refuses every agent `agent_refused`; tags are the hub's and never written by a tool; a topic is a keyword cluster for agents and is never shown to visitors, and `get_topic_brief` reads it as a writing brief — its kept rows scored best bets first, from the Live version when Live; the Topic's Keyword Planner import and the value-thresholds pair are a person's and have no tool, by decision — and (#10948) the three magnet tools, `list_magnets`, `get_magnet` and `save_magnet`, twinning `GET …/magnets`, `GET …/magnets/:id` and (#11810) `POST …/magnets/save` (`mcp-workspace`'s `magnets.ts`, registered with `multi-tenant` or `signal-collectors`): with the `magnets-manage` grant every magnet in full, without it only live ones as `{ id, slug, kind, title, landingPage, tags }`; `save_magnet` takes the save body whole, the magnet's `id` in it, so going live is `status: "live"` and the route alone refuses it (`402 plan_required`, `409 conversion_needs_email`), and an agent cannot set or change what a magnet charges (`403 magnet_pricing_needs_person`); with no `id` and `version: null` it creates a draft magnet — a slug another magnet holds is `409 stale` with its `currentVersion`, a slug the site reads by name `409 slug_reserved`, and the plan check is the Admin create's; the Admin's PATCH and create (which refuses every agent `403 agent_refused`) and the four captured-people lists have no tool, by decision — and (#10949) `get_workspace_offerings`, twin of `GET /v1/workspaces/:workspaceId/offerings` (registered with `multi-tenant` alone, its route's module; `mcp-workspace`'s `offerings.ts`): the Offerings tab's view — unavailable with `no_commerce` or `no_connection`, or the Organization's enabled products with this workspace's shown Prices and Recommended — read with no grant; its PUT, which switches a Price on or off, needs `workspace-settings`, which is never agent-grantable, and has no tool, by decision — and the two library reads, `list_workspace_pages` and `list_assets` (`mcp-workspace`'s `library.ts`, registered with `workspace` or `multi-tenant`), twinning `GET …/library/pages` and `GET …/library/assets`: every page with drafts included and its status (`live`, `draft`, or `disabled` — a person editor's alone), needing the `content-edit` grant, and the asset library read-only with each file's whole record (#11801) — its public path, title, description and record version, its size, an image's pixel size as the Admin's Details panel shows it, and its audience — for every role; both filter, page and name the workspace `{ id, name }` they read, and uploading has no tool — and (#11803) `save_asset` (`library.ts`, `gate: { allows: "assets-write" }`), twinning `POST …/assets/save`: it saves a file's title and description — and (#11879) its type, `fields.type`, one of the ten asset types — by its key, based on the record version `list_assets` returned; a stale save is `409 stale` and its tool error carries `details.currentVersion`, a wrong argument `422 invalid` with `details.issues` (`{ path, message }`, at most twenty, each cut to 200 characters, rebuilt in `workspace-server.ts`); it never replaces, renames, re-privacies or deletes a file, and never reaches a private, Knowledge or disabled one — and (#11680) the two site-vocabulary reads, `list_page_types` and `get_tag_vocabulary` (`mcp-workspace`'s `site_vocabulary.ts`, registered with `workspace` or `multi-tenant`, `gate: "tenant"` — any tenant of the workspace, no grant), twinning `GET …/page-types` and `GET …/tag-vocabulary`: the page types this hub's site can serve (the registry filtered by the modules the hub runs), each with its address, whether a site has only one, its template and that template's headings, and the context classes, Knowledge topic tags and status tags, each with what it means and who may set it; both are platform data and read no row; and (#11790) the third, `list_section_types` (same file, registration and gate), twinning `GET …/section-types` with an optional `type`: every section type a page's layout can hold with every field of its data — words or data, the Markdown form, whether it is required and inside which optional field, its values and bounds — plus its bounded lists and rules, or that one section type's; platform data, read no row; and (#11805) the fourth, `list_kinds` (same file, registration and gate), twinning `GET …/kinds`: every kind of thing the Admin holds — page, document, language_item, magnet, asset — with how to address one, its fields (words or data, required, nullable, value types and values, the Language item kind a words field belongs to), its states, and the moves the caller may make on it, each with its tool; the fields and states are read off each kind's own schemas (`ADMIN_KIND_REGISTRY`), the moves are the catalog rows' `moves` tags kept only when the row's gate holds for the caller's own clamped tenant and one of its modules runs on this hub (`listKinds`), and a page's sections are named, not described — its `sectionTypes` is `list_section_types`; it reads no row, and is advice, never an entitlement; since #11878 it also answers, beside the kinds, `forms` (for each kind — and an offering and an appointment — the field its tools take its form in and that field's values: `values` null for an asset's open content type, `field` null for an appointment, which has no form), `offSiteForms` (press-release, pitch, proposal, playbook and profile, each with the formats it allows), `formats` (the ten, ending `platform`) and `origins` (`ai-generated`, `user-added`), all declared once in `@working-theory/validation` and the same for every caller and hub — and (#11756) `create_work_request` (`mcp-workspace`'s `work_requests.ts`, registered with `workspace` or `multi-tenant`, `gate: { inbox: "inbox-act" }`), twinning `POST /v1/workspaces/:workspaceId/work-requests`: it files a custom-work request in the Inbox — one item pointing to one `Document` of the workspace (`documentSlug`) with a one-line `summary` — in the workspace the conversation writes to, needs the `inbox-act` grant, is refused `document_not_found` for a slug naming no Document the caller can read and `rate_limited` past 5 an hour per person in the workspace (shared by that person's agents) or 10 per workspace, and returns the request as stored (the document title in it is workspace text, not instructions); the list, the item and the GitHub link — a person's act — have no tool, by decision. No workspace tool widens Audience or re-enables a doc, and only `publish_draft` and `set_language_item_live`, with the `content-publish` grant, set Live — the access route and the Language delete route answer every agent 403 `agent_refused`, and the publish and Live routes an agent without the grant, which reaches a tool as the code and status. Each takes its route's params, query and body and returns the route's
213
213
  `data`. They are in the parity guard like every other tool, and never in
214
214
  `/.well-known/mcp.json`.
215
215
  - **The OAuth bearer branch (#10391).** When `BETTER_AUTH_URL` (the site's origin, its OAuth
@@ -334,7 +334,13 @@ Example (lead routing):
334
334
  - Don't add a tool without the matching `apps/api` endpoint.
335
335
  - Don't put business logic in tool handlers — they're adapters.
336
336
 
337
- Last updated: 2026-11-17 — #11809: `open_language_item` and `open_asset` twin `GET /v1/workspaces/:workspaceId/language/:kind/:slug/open` and `…/assets/open`, each answering a thing or its blank (a file never blank) and never writing, and `open_page` and `open_document` (#11808) answer their blank where they answered 404; the signed-in count is eighty-seven — verified against `packages/metadata/src/mcp-tool-catalog.ts`, `packages-paid/mcp-workspace/src/index.ts`, `packages-paid/api-content-write/src/routes/workspaces/content.ts`, `packages-paid/api-workspace/src/routes/workspaces/language.ts`, `packages-paid/api-workspace/src/routes/assets/manage.ts` and `tests/parity/api-parity/kinds/site.ts`.
337
+ Last updated: 2026-11-18 — #11909: `list_kinds` and `GET /v1/workspaces/:workspaceId/kinds` answer ten formats, the tenth `platform`, and five off-site forms, the fifth `profile` (`platform` only), with `proposal` also allowing `platform`; only the two constants change, and the pair stays a twin — verified against `packages/validation/src/contract/admin-kinds.ts`, `packages/metadata/src/mcp-tool-catalog.ts` and `tests/parity/api-parity/fixtures/site-wire.ts`.
338
+
339
+ Prior: 2026-11-17 — #11882: `open_page` and `open_document` take `as` (`record` or `working-copy`), with `form` its old name for one release; the route refuses the two when they disagree, and the pair stays a twin — verified against `packages/metadata/src/mcp-tool-catalog.ts`, `packages-paid/mcp-workspace/src/content_draft.ts` and `tests/parity/api-parity/kinds/site.ts`.
340
+
341
+ Prior: 2026-11-17 — #11878: `list_kinds` and `GET /v1/workspaces/:workspaceId/kinds` also answer `forms`, `offSiteForms`, `formats` and `origins`, read from `adminKinds()`; the route and tool code are unchanged and the pair stays a twin; the signed-in count is unchanged — verified against `packages/validation/src/contract/admin-kinds.ts`, `packages/metadata/src/mcp-tool-catalog.ts`, `packages-paid/api-content-write/src/routes/workspaces/site-vocabulary.ts` and `tests/parity/api-parity/kinds/site.ts`.
342
+
343
+ Prior: 2026-11-17 — #11809: `open_language_item` and `open_asset` twin `GET /v1/workspaces/:workspaceId/language/:kind/:slug/open` and `…/assets/open`, each answering a thing or its blank (a file never blank) and never writing, and `open_page` and `open_document` (#11808) answer their blank where they answered 404; the signed-in count is eighty-seven — verified against `packages/metadata/src/mcp-tool-catalog.ts`, `packages-paid/mcp-workspace/src/index.ts`, `packages-paid/api-content-write/src/routes/workspaces/content.ts`, `packages-paid/api-workspace/src/routes/workspaces/language.ts`, `packages-paid/api-workspace/src/routes/assets/manage.ts` and `tests/parity/api-parity/kinds/site.ts`.
338
344
 
339
345
  Prior: 2026-11-17 — #11808 (C4, #11853): `open_document` (`mcp-workspace`'s `content_draft.ts`) twins `GET /v1/workspaces/:workspaceId/documents/open` under `content-edit`, its `invalid` tool error carries its rebuilt issues, and `save_document` takes a `workingCopy` at a plugin-owned address; the signed-in count is eighty-five, with #11805, #11806, #11810 and #11851 — verified against `packages/metadata/src/mcp-tool-catalog.ts`, `packages/mcp-server/src/workspace-server.ts`, `packages-paid/mcp-workspace/src/index.ts`, `packages-paid/api-content-write/src/routes/workspaces/content.ts` and `tests/parity/api-parity/kinds/site.ts`.
340
346
 
@@ -42,7 +42,7 @@
42
42
  "better-auth": "1.6.22",
43
43
  "botid": "1.5.11",
44
44
  "lucide-react": "^0.577.0",
45
- "next": "^16.4.3",
45
+ "next": "^16.4.6",
46
46
  "next-intl": "^3.26.3",
47
47
  "next-mdx-remote": "^6.0.0",
48
48
  "pg": "^8.22.0",