Repository navigation
feat(spec,runtime): hook refusals on handler hooks, with declared reasons and params - #33641
Conversation
Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
…lers (#33214) Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
…33214) Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
…and reference docs (#33214) Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
…ams; changeset (#33214) Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
…ndler-hook-refusals
… not a helper parameter (#33214) Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
…r header totals (#33214) Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
…ndler-hook-refusals # Conflicts: # content/docs/automation/hooks.mdx
…main (#33214) Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 3 package(s): 1 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 2 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 177 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 00b3c9f3abeab5d02f5cf1b23164c1e3c9f0c13b && git checkout 00b3c9f3abeab5d02f5cf1b23164c1e3c9f0c13b
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 48e695966ad76eee523d8a1321a88317ee4acfa6 da6c538b7643003b2de36ac47aea018c6aa39c87 && git checkout -B drift-repro 48e695966ad76eee523d8a1321a88317ee4acfa6 && git merge --no-ff da6c538b7643003b2de36ac47aea018c6aa39c87
node scripts/docs-audit/affected-docs.mjs --json 48e695966ad76eee523d8a1321a88317ee4acfa6
|
|
domain:spec#2 · sunhaolin · session_017xRBcSbLCxEmyHf9upz3pz Contract-review-handoff: review#2 — CONTRACT_REVIEW_TIER unavailable (the seat's isolated reviewer refused by its session classifier twice, 2026-11-14T17:2xZ) · head 7bb3498 Card #33214. Ruling 6879477573 (问一 A, 问二 S1, 问三 params) inside ruling 6431311681 (#26170 letter A). The dev reports are 6888595211 and 6888828706. The PR merged |
|
review#2 · os-project-manager · session_01FEkQ5nhu4dRbKVQKDB4CDB Contract-review-claim: session_01FEkQ5nhu4dRbKVQKDB4CDB · head 7bb3498 · 2026-11-15T04:40Z |
…declares reasons; compile hook refusal templates (#33214) Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
…pty-hole rule (#33214) Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
…ms compile refusals; skills follow-up #33658 (#33214) Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
…ite walk ledger (#33214) Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
|
review#2 · os-project-manager · session_01FEkQ5nhu4dRbKVQKDB4CDB Contract-review-claim: session_01FEkQ5nhu4dRbKVQKDB4CDB · head 1c9a1ec · 2026-11-15T06:08Z |
|
review#2 · os-project-manager · session_01FEkQ5nhu4dRbKVQKDB4CDB Contract reviewServed-tier: Delta review of the hop ① Derived judgments
② Semver level
Clause-②: yes — correct, unchanged.
③ Boundary flags
④ Design judgmentM1, closed. Option (a), at both places.
S1, closed for the doors that compile. Nits (no effect on correctness or the contract; accepted deviations or follow-up cards):
Held. No new export, no schema key and no wire field in this hop. The regenerated No must-fix and no should-fix remains. Nits only: this is the final round for this PR's contract face. Implemented-by: VERDICT: PASS |
…ndler-hook-refusals
…on reference after merging main (#33214) Claude-Session: https://claude.ai/code/session_017xRBcRivaGj55DhDi7sE8w Co-authored-by: Claude <noreply@anthropic.com>
|
domain:spec#2 · sunhaolin · session_017xRBcSbLCxEmyHf9upz3pz 维护者速读 · PR #33641 @
|
…arams (objectstack-ai#33775) <!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XGooifXpuUREdsVd5x9prTS)_ domain:skills#1 · os-project-manager · session_01FEkQ5o9NG21PoQGHjYvjzM Fixes objectstack-ai#33658 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:数据技能 `data-hooks.md` 的「声明式拒绝」一节改为教 objectstack-ai#33214 之后的真实规则:`handler` 钩子也能声明 `refusals`;同一个码下可以有多句 `reasons`(抛 `{ code, reason }`);声明 `params` 后句子里的双花括号占位符只能引用已声明的名字。i18n 技能在原有翻译键旁加上 reasons 的翻译键。 - 为什么改:PR objectstack-ai#33641 合并后,旧文档仍说「只有沙箱 JS 能声明拒绝、一码一句、不许占位符」,AI 照着写会继续抛英文句子或自造错误码。 - 风险与回滚:只改两份技能文档加一个 changeset,无代码;为付 token 棘轮删了同文件内四处重复说明。回滚即 revert。 - 先看:`skills/objectstack-data/references/data-hooks.md` 的 `### Declared refusals` 一节(示例与下方 5 条要点);其次 `skills/objectstack-i18n/SKILL.md` 的 App-authored 一条。 - 两分钟验证:`node scripts/check-skills-token-ratchet.mjs` 全绿,data-hooks.md 为 9990/10011。 - 需要你做的:无,席位落地(按低风险 skills 臂;臂若读出 Tier H 则需你批准合并)。 ## What changes Three files, no code. **`skills/objectstack-data/references/data-hooks.md` § Declared refusals (`refusals`)** - The example's `ASSET_NOT_IN_STOCK` entry now declares `params: ['due']` and a `reasons` entry `on_loan` whose sentence fills a `due` hole, and the body throws `Object.assign(new Error(), { code: 'ASSET_NOT_IN_STOCK', reason: 'on_loan', params: { due: asset.due_date } })` before the existing code-only throw. - "Only a `js` `body` can declare one: a `handler` hook, inline TS included, is refused at save" is replaced: a `js` body or a `handler` (inline or named) can declare one; an `expression` body, or neither, is refused at save. - New bullets: `reasons` are snake_case, thrown as `reason`, and keep the code's wire `code` and status; `params` names what a hole may fill, and a hole over any other name, or any hole with no `params`, is refused. - The translation bullet names both keys, `hooks.HOOK.refusals.CODE.message` and `hooks.HOOK.refusals.CODE.reasons.REASON.message`, and says the thrown text (not "the body's own text") is unused. - The refusal bullet adds "a reason missing from a code's `reasons`". - The intro says "the hook throws the code" instead of "its body throws the code". **`skills/objectstack-i18n/SKILL.md` § Server-Composed User Text**: the App-authored bullet names `hooks.HOOK.refusals.CODE.reasons.REASON.message` beside the code's key, and says a translation of a sentence whose entry declares `params` keeps its holes, filled by the runtime after it is picked. **`.changeset/33658-skills-hook-refusal-reasons-params.md`**: `'@objectstack/skills': patch` (the catalog ships in `@objectstack/skills`). **Token ratchet payment (same file, restatements only).** data-hooks.md was at 10004/10011; the new text cost about 150 tokens. Removed: | Removed | Its home in the same file | |:--|:--| | "The deprecated `handler` takes an inline function or a registered function's name (Registration Methods)." | the `body` vs `handler` table (inline) and Registration Methods 1 (string name via `functions`) | | "So spell keys against the object's declared fields, and on an insert event read `previous` only against `null` ..." | the paragraph above it (a typo'd key and a `previous` column on an insert fail the write) and the `previous is null on insert` bullet | | "(A declarative `condition` does not hit this wall ...)" under Gotcha 1 | § `condition`: "`record` here is the RECORD ... unlike `ctx.input` / `ctx.result` inside the body, which stay partial, see Gotcha 1" | | "Register it like any hook, add it to `defineStack({ hooks: [...] })` ..." after the copy-paste example | Registration Methods 1 (`defineStack({ hooks })`, `AppPlugin` auto-binds) | No ceiling moved. `i18n.sourceLocale` teaching is untouched (objectstack-ai#33635 holds it). ## Why PR objectstack-ai#33641 (objectstack-ai#33214, ruling 6879477573) made `HookSchema` and the runtime accept `refusals` on a handler hook, `reasons` under a code and declared `params`. The skills still taught the pre-objectstack-ai#33641 rule, so an agent would keep a hand-written body for every rule, one sentence per code and no params. ## Tests No test file is committed (skills text only). Two one-time checks of the new example, both against `main` @ `12a0f09f` built under the lock: <details><summary>HookSchema.parse on the published example and six mutants (packages/spec dist)</summary> ``` example parse: true hole over undeclared name: refused: refusals.ASSET_NOT_IN_STOCK.reasons.on_loan.message A hook refusal `message` binds only `due` ... hole with no params: refused: refusals.ASSET_NOT_IN_STOCK.reasons.on_loan.message A hook refusal `message` whose entry declares no `params` is plain text ... literal undeclared reason: refused: body.source `body.source` throws code 'ASSET_NOT_IN_STOCK' with reason 'lost' ... inline handler + refusals: ACCEPTED inline handler, undeclared reason: refused: handler `handler` throws code 'ASSET_NOT_IN_STOCK' with reason 'lost' ... string handler + refusals: ACCEPTED expression body + refusals: refused: refusals `refusals` is answered for a sandboxed `body` ... ``` The block was read out of the edited markdown file, not retyped. Each bullet's claim has a mutant above. </details> <details><summary>Real QuickJS run of the example's throw lines (scratch test beside hook-refusal-catalogue.test.ts, deleted after)</summary> The body was bound through `hookBodyRunnerFactory` + `QuickJSScriptRunner` with the hook passed through `HookSchema.parse`; the one `ctx.api` read was swapped for an input value, every throw line kept as published. `Tests 5 passed (5)`, exit 0. ``` ON_LOAN {"status":409,"body":{"error":"This asset is on loan until 2026-12-01.","code":"RESOURCE_CONFLICT","declaredCode":"ASSET_NOT_IN_STOCK","object":"asset_checkout","userMessage":"This asset is on loan until 2026-12-01."}} ZH {"status":409,"body":{"error":"该资产借出至 2026-12-01。","code":"RESOURCE_CONFLICT","declaredCode":"ASSET_NOT_IN_STOCK","object":"asset_checkout","userMessage":"该资产借出至 2026-12-01。"}} RETIRED {"status":409,"body":{"error":"Only an in-stock asset can be checked out.","code":"RESOURCE_CONFLICT","declaredCode":"ASSET_NOT_IN_STOCK","object":"asset_checkout","userMessage":"Only an in-stock asset can be checked out."}} ``` </details> ## Acceptance notes Each taught rule, read from `main` @ `12a0f09f`: | Taught | Read from | |:--|:--| | a `js` body or a `handler` (inline or string) may declare `refusals`; `expression` body or neither refused at `refusals` | `packages/spec/src/data/hook.zod.ts` `refuseUndeclaredLiteralRefusalCode` (`answered = body === undefined ? hasHandler : language === 'js'`) | | reasons snake_case, thrown as `reason`, keep the code's status and wire code | `HOOK_REFUSAL_REASON_PATTERN` (`hook-refusal-codes.ts`); `HookRefusalSchema` `reasons` describe; runtime `declaredAnswer` | | a hole only over a declared param; no `params` means no hole | `hookRefusalMessageRefusal` (`closedScopeTemplateRefusal` with `roots: params`) | | literal undeclared code or reason refused at save, else a 500 | `hookRefusalCodesThrownIn` / `hookRefusalReasonsThrownIn`; runtime `undeclaredHookRefusalReasonAtRun` | | reason key, and a translation keeps its holes | `hookRefusalMessageKey` (`system/i18n-resolver.ts`); `translation.zod.ts` `hooks` docblock | Out of scope, noted for the seat (not filed): the objectstack-data eval `hooks-security-seeds-datasources.json` id 7 `expected_output` still ends "a catalogue on a hook without a `js` body is refused at save", which objectstack-ai#33641 made false (a `handler` hook may declare one). Its assertions (`must_contain`, `must_not_contain`) are unaffected. carrier: the skills seat. ## Verification Readings on head `6072b2db`: - **Model tier** (`dispatch-gates --tier`): MANDATORY contract-review tier, `skills/**` clause ①, no one-line exit. This branch was written at the default tier; the seat's in-seat at-tier contract review pays the mandated tier. - **`check-governed-merges.mjs --branch claude/project-thread-3vm39u`**: GOVERNED, `skills/**` ×2, landing tier H on a path list; low-risk skills arm NOT MEASURED there ("no reading of the pull request was handed in"). The arm is read with `--pr` on this PR. - **Skills readings (lines; tokens = ceil(bytes/4)):** data-hooks.md 892 to 893 lines, 10004 to 9990 tokens (ceiling 10011); objectstack-i18n/SKILL.md 522 to 524 lines, 5918 to 5971 tokens (ceiling 6333). Bundle, all 11 `skills/*/SKILL.md`: 4588 to 4590 lines, 59049 to 59102 tokens. - **`check-skill-line-ratchet.mjs`**: exit 0. <details><summary>Derived gates: 48 derived, 47 exit 0, 1 NOT MEASURED, plus check:skill-examples</summary> `node scripts/pm/dispatch-gates.mjs --ran FILE`: "48 derived famil(ies) accounted for, 47 run, 1 NOT-MEASURED (1 DERIVED from a recorded exit 3)". - exit 0: check-adr-0087-registration (base, self-test), check-changeset-no-major, check-closing-keyword-parity (+ self-test), check-comment-mask-corpus, check-doc-route-spelling (advisory, self-test), check-dts-emitted self-test, check-empty-changeset (base, self-test), check-skills-token-ratchet (+ self-test), ci assert-turbo-remote-cache / plan-test-core-shards / prune-turbo-cache / snapshot-next self-tests, check-governed-queue-guard self-test, release-rehearsal-clone self-test, release-pending-publish self-test, lint check:doc-formula-expressions, spec check:skill-docs, spec check:skill-refs, check:agent-test-spelling, check:changeset-gate-self-tests, check:ci-filter-parity, check:closed-ceremony-text, check:corpus-claim-drift, check:cross-package-test-inputs, check:doc-authoring, check:driver-memory-census, check:dts-closure, check:gitlink-declared, check:lean-entry-closure, check:merge-driver, check:nul-bytes, check:pm-governed-merges, check:pm-skill-id-lint, check:published-files, check:refd-timer-probe, check:role-word, check:skill-compatibility, check:skill-frame-sync, check:skill-identifier-liveness, check:skill-links, check:sourcemap-no-sources-content, check:watch-hint-literal. - NOT MEASURED: `pnpm check:dual-build-cjs-loads` exit 3, reason: it reads every package's `dist` and asks for a full `pnpm build`; this diff touches no package, so CI's run is the reading. - Outside the derivation: `pnpm --filter @objectstack/spec run check:skill-examples` exit 0, "346 prose examples type-check across 3 surface(s)". </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01FEkQ5o9NG21PoQGHjYvjzM)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01FEkQ5o9NG21PoQGHjYvjzM <!-- signed: domain:skills#1 · os-project-manager · session_01FEkQ5o9NG21PoQGHjYvjzM --> Co-authored-by: Claude <noreply@anthropic.com>
objectstack-ai#33796) <!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XNgQVJVHQG8aPco5eaW7Vvs)_ Fixes objectstack-ai#33657 Clause-②: yes (widening) Metadata-protocol: none Seat `domain:ui#1` · os-project-manager · card thread `session_01FEkQ5oQHgtkqYPCqstiKir` · claim 6892138272 ## 维护者速读 - 改了什么:Studio 的钩子(hook)表单里,每条拒绝目录条目除了「提示语」和「状态码」,现在还能填「原因」(同一错误码下的多句提示,以 snake_case 原因名为键)和「参数」(提示语里 `{{ 名称 }}` 可以填的名字)。表单定义 `hookForm` 加两行;渲染器本来就能画「嵌套在键值记录里的键值记录」和名称列表。契约复审 S1 之后另有一处渲染器修正:可选的键值记录行删掉最后一条时,现在写成「不存在」,不再写成空对象 `{}`。 - 为什么改:objectstack-ai#33214 让拒绝目录支持 `reasons` 和 `params`,但 Studio 表单只给了两项,作者在 Studio 里没法声明这两项能力。 - 风险与回滚:元数据可写内容不变(这两个键本来就合法),只是表单多了两行。实测:在改动前,带 `reasons`/`params` 的目录经 Studio 编辑其他字段后已经能原样保存,本改动后依旧如此;只填提示语和状态码的条目保存结果与今天逐字节相同。回滚即还原本 PR。 - 契约复审 S1 修正(d3ff3bdb):之前加一条原因再删掉,Studio 会存下 `reasons: {}`;空对象和不写读法不同(空对象会拒绝主体抛出的每个原因,不写则不读原因),而界面上两者看起来一样。同样的问题在上一层:删掉最后一个错误码会存下 `refusals: {}`,它会拒绝主体抛出的每个错误码。现在两处都写成「不存在」;必填的键值记录行(对象的 `fields`)照旧保留 `{}`。 - 先看:`packages/spec/src/data/hook.form.ts`(新增的两行)、`ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.hookRefusalReasons-33657.test.tsx`(经真实 Studio 编辑页填写、保存、读回)、`packages/spec/src/system/metadata-form-zod-reconciliation.test.ts`(删掉两条 omit 台账行)。 - 两分钟验证:在 Studio 打开任一带 `refusals` 的钩子,点「编辑」,展开一条错误码:应看到 Key / Message / Status / Reasons / Params 五项;在 Reasons 里加 `plan_locked` 并填一句话,在 Params 里填 `state`,保存后重新打开仍在。 - 需要你做的:无,席位落地(`hook.form.ts` 随 `@objectstack/spec` 发布,席位先补契约复审记录)。 ## What changes - **The form** (`packages/spec/src/data/hook.form.ts`). The `refusals` row's entry gains two sub-rows after `message` and `status`: - `reasons`: `type: 'record'`, `widget: 'key-only-record'`, with one sub-row `message` (required textarea). A reason entry is `{ message }` and nothing else, with no member that echoes its key, so it takes the same key-only record control the catalogue itself takes. The key rule the control checks is the served schema's own `propertyNames.pattern` for `reasons`, which the spec derives from `HOOK_REFUSAL_REASON_PATTERN`; the form restates no rule. - `params`: `type: 'tags'`, the name list control. - The entry `message` help text said the sentence is "plain text, with no placeholders". Once `params` is on the same card that is false, so it now says a `{{ name }}` hole fills a declared param. The new rows' help texts recite `HookRefusalSchema`'s own `.describe()` text. - **The ledger** (`packages/spec/src/system/metadata-form-zod-reconciliation.test.ts`): the two `omit` rows for `hook` / `refusals` / `reasons` and `params` are gone. - **Drawing the rows needed no renderer change.** Measured on `origin/main` before any edit (below): the console's generic form renderer (`SchemaForm`'s `RecordField`) already draws a key-only record nested inside a key-only record entry, reads each level's key rule from the schema it is handed (`servedRecordKeyPattern`), and draws a `tags` row as the string-tags widget. - **Removing the last entry of an optional record row writes it absent** (`ui/packages/app-shell/src/views/metadata-admin/SchemaForm.tsx`, contract review S1, d3ff3bd). `RecordField.removeItem` emitted `{}` once the last entry went, and nothing on the save path dropped it. `RecordField` now takes `FieldControl`'s `offerUnset` (the key is optional and not a list element, the condition the enum select's "— None —" already uses) and, when that holds, emits an empty map as `undefined`, the form's clear convention. A required row keeps `{}`. See "S1: empty versus absent" below for the forms this reaches. - **Translations.** The three new rows and the changed help text are translated in the ten locales of `@objectstack/platform-objects`' metadata-form bundles (regenerated with `node scripts/check-i18n-bundles.mjs --write`, then the new leaves translated by hand, the same ten the `refusals` row is translated in; a second `--write` dropped the source-hash entries of the translated leaves). The French label "Message" stays a byte copy of the source, as the existing `refusals.message` label already is. The console's zh-CN form labels (`metadata-form-zh-cn.ts`, read by the Pending changes sheet) name the three rows. - **Census counts.** Three `@objectstack/platform-objects` translation pins count the hook form's enumerated children and the row labels authored in the three hand-translated locales; the three new rows move them from 9 to 12 and from 738 to 741, each with a comment naming the rows. - **Changeset** `.changeset/33657-hook-form-refusal-reasons-params.md`: `@objectstack/spec`, `@objectstack/platform-objects`, `@object-ui/app-shell`, `@object-ui/console` patch (a widening with `Metadata-protocol: none`; app-shell is private and console's `dist` ships it). ## Measured first (on `origin/main` bd96ec9, before any edit) A probe through the real Studio edit page (`MetadataResourceEditPage` for `hook`, the served form `hookForm`, the served schema from `HookSchema`), over a stored hook whose `refusals.CONTRACT_LOCKED` declares `message`, `status: 409`, `params: ['state']` and `reasons.plan_locked.message`: 1. **What the entry offers:** the open entry's labels read `Key*`, `Message*`, `Status`, nothing else. The deciding line is the `refusals` row's `fields` array in `hook.form.ts`, which lists `message` and `status` only; the renderer draws exactly the sub-rows a record row lists (`RecordField` maps its `specs`, the row's `fields`). 2. **Round trip:** a Label edit then Save sent the body with `refusals` byte-identical (`params` and `reasons` kept), and so did an edit of the entry's own `message`. The deciding lines: the page sends the whole draft, and `RecordField`'s `updateItem` writes `{ ...entry, ...patch }`, so members the form does not list are kept. So the card's "may lose them on a Studio edit" did not hold on main; the round-trip pin below now holds it. 3. **Can the renderer draw the shape?** The same probe with a form that adds a nested key-only `reasons` record and a `params` tags row drew `Key / Message / Status / Reasons / Params`, showed `plan_locked` as a nested entry, and no element id was duplicated. A nested `type: 'record'` sub-row goes through the same `FieldRow` → `resolveFieldFace` → `RecordField` path as a top-level one, with the sub-schema from `pickSubSchema`. ## S1: empty versus absent (contract review 6893396284) Measured through the real Studio edit page on 2238c90, before the fix (each new pin below red, received shown): - add `plan_locked` to `CONTRACT_LOCKED`, remove it, edit Label, Save: the entry was stored as `{ message, reasons: {}, status: 409 }`; - over a stored entry with one reason, remove it, Save: `reasons: {}`, `params` kept; - remove the only refusal code, Save: `refusals: {}`. `{}` and absent read differently at both levels. For `reasons`, `hook.zod.ts`'s save-time check refuses every literal reason thrown under a code whose `reasons` is `{}`, and the runtime catalogue faults a computed one; an absent `reasons` does not read the thrown reason. For `refusals`, `{}` is a declared catalogue with no codes, so every code the body throws is refused (and a non-js body is refused outright); an absent catalogue leaves the throws as they were. The screen draws the same empty list either way. The generic `RecordField` inline face is reached by exactly three form rows across the served forms (`type: 'record'` rows in `packages/spec/src/**/*.form.ts`; no other form declares one, and the other `type: 'record'` hits in the repo are pages): | Form row | Required? | Before | After | |---|---|---|---| | `object` → `fields` | `required: true` | `{}` | `{}` (unchanged, no absent state) | | `hook` → `refusals` | optional | `{}` (refuses every thrown code) | absent | | `hook` → `refusals.<CODE>.reasons` | optional | `{}` (refuses every thrown reason) | absent | So `{}` and absent are not equivalent for the second row either, and the generic fix changes it in the same direction as the finding. That is why the fix is generic and gated on the row being optional, rather than local to the hook form: the form has no per-row way to say "empty means absent", and the `refusals` row has the same defect. Add-then-remove with no other edit now returns the draft to the stored hook, so the page has nothing to save. ## Tests - `ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.hookRefusalReasons-33657.test.tsx` (new, the real Studio form): the real page with the production registrations, the type row built the way the server builds it (`hookForm` + `z.toJSONSchema(HookSchema, { io: 'input' })`), a stub metadata client as the stored row. - an opened refusal entry offers exactly `Key, Message, Status, Reasons, Params`; - author a reason (`plan_locked` + its message) and a param (`state`) through the rendered controls, Save: the PUT body's entry is `{ message, status, reasons: { plan_locked: { message } }, params: ['state'] }` and `HookSchema` parses it; then a fresh page over the stored row shows the reason and its message and the `state` chip; - a stored catalogue that uses `reasons` and `params` round-trips a Label edit: the body equals the stored hook with the new label; - CONTROL: a refusal with only `message` + `status` saves exactly as stored (keys `message`, `status`). - S1: add then remove the only reason (plus a Label edit, so there is something to save): the entry is stored as `{ message, status }`, keys exactly those two; - S1: remove the last stored reason: the entry is the stored one without `reasons` (`params` kept); - S1 CONTROL: add a second reason and remove the first: `reasons` holds the second, as before; - S1: remove the only refusal code: the stored hook has no `refusals` key. - `ui/packages/app-shell/src/views/metadata-admin/SchemaForm.keyOnlyRecord-26835.test.tsx` (the form definition test, new `describe`): `hookForm` declares `reasons` as a key-only record of `{ message }` and `params` as `tags`; the served schema's reason key rule is `HOOK_REFUSAL_REASON_PATTERN.source`; author a reason + param and the value parses as written; a reason key `PLAN_LOCKED` is refused with the served rule and the value does not move; a stored catalogue reloads into the same rows. The file's `addKey` helper now takes the last `Key` box: an open entry draws a second one for its `reasons`, and the catalogue's own box comes after every card. The existing CONTROL there ("a hook authored with two refusals saves a body HookSchema accepts as written") passes unchanged in substance. - `SchemaForm.keyOnlyRecord-26835.test.tsx`, S1 `describe`: removing the last entry of the optional `refusals` row leaves no `refusals` key and `HookSchema` parses the value; CONTROL: the same row declared `required: true` keeps `refusals: {}`. - `packages/spec/src/system/metadata-form-zod-reconciliation.test.ts`: green without the two `omit` rows (`hook.refusals` offers both keys). ### Ablations Through `scripts/ablation-replace.mjs --delete` on the form source, each leg running the reconciliation test (spec `src`), a spec rebuild, `scripts/ablation-dist-preflight.mjs @objectstack/spec MARKER --absent` (ui vitest reads spec from `dist`), and both ui pin files (17 tests). Each restored with blob == HEAD and `git diff HEAD` empty; then spec rebuilt and the preflight run without `--absent` found both markers back in `dist` (exit 0), and both pin files were 17/17 green. - `reasons` row deleted: reconciliation 1 failed / 75 (`hook.refusals: accepted by the Zod but unauthorable in the form … expected [ 'reasons' ] to deeply equal []`); ui 6 failed / 17 (the offer pin, the Studio author-save-reload pin, and all four SchemaForm `reasons`/`params` pins). - `params` row deleted: reconciliation 1 failed / 75 (`expected [ 'params' ]`); ui 5 failed / 17 (the offer pin, both author pins, the definition pin and the reload pin). - The round-trip and CONTROL pins stay green under both: they hold behaviour that already held on main, which is what they are for. - S1, the empty-to-absent arm reverted (`emit` writes the map as given): 4 failed / 23 across the two ui pin files (the SchemaForm optional-row pin and the three Studio S1 pins); the S1 CONTROLs stay green. - S1, the `offerUnset` gate dropped (every empty map written absent): 1 failed / 15 in `SchemaForm.keyOnlyRecord-26835.test.tsx`, the required-row CONTROL. Both restored by copying the fixed file back; 23/23 green. ## Acceptance notes - **The premise's second half did not hold on main.** A catalogue using `reasons` / `params` already kept them through a Studio edit (measured above). The new round-trip pin holds that, and nothing in this diff changes it. - **`params` is not checked in the form.** The tags control accepts any text; a non-identifier is refused at save by `HookSchema` (`A refusal param is an identifier (e.g. state)`), and a `{{ }}` hole over an undeclared name is refused there too. The form restates no rule, as the order asks. - **Not changed (order's ⛔):** `hook.zod.ts`, the runtime refusal catalogue, the lint rule, any server code. - **Noted, not filed:** the `refusals` row's help text still ends "JavaScript (L2) bodies only", while since objectstack-ai#33641 a `handler` hook may declare `refusals` too. The Studio form authors a `body` hook (the handler row is the collapsed "Legacy handler" text field), so the sentence still describes what this form authors; left as is to keep this diff to the two rows. carrier: none. ## Verification <details><summary>S1 round (head d3ff3bd)</summary> - `dispatch-gates --commands` derives the same 88 families on d3ff3bd; all 88 exit 0, run sequentially after a full workspace build. `--ran`: 88 derived, 88 run, 0 NOT-MEASURED. - From `ui/`: the two pin files, 23 passed; the 15 metadata-admin test files that touch a record row, `keyField` or `refusals` (`grep -l "type: 'record'\|keyField\|refusals\|RecordField"`), 179 passed. A run of the whole `metadata-admin/` folder (281 files) did not finish inside a 25-minute timeout and was stopped; CI runs it. - `pnpm --filter @object-ui/app-shell run type-check` exit 0. ESLint `--no-inline-config` on the three changed ui files: exit 0, 17 warnings, none on a changed line. - `origin/main` is 28 commits past the branch; `git merge-tree` against it is clean. </details> <details><summary>Local gates, suites, type-check and lint (head 2238c90)</summary> - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derives 88 families for this diff (tree 2238c90). All 88 exit 0 on 2238c90, run sequentially after a full workspace build (`turbo run build`, 119 tasks). `--ran` reconciliation: 88 derived, 88 run, 0 NOT-MEASURED, 0 UNRUN. - First round (heads 8daba63 to e764497, before the last commit): 86 exit 0; `check-plugin-teardown-shape --self-test` exit 3 (shallow clone; exit 0 after fetching its fixture commit) and `check:test-source-alias` exit 1 (the edited `SchemaForm.keyOnlyRecord-26835.test.tsx` reaches `import('@objectstack/lint')` through the condition widget; module-top `@objectstack/formula` / `@objectstack/lint` imports added in 2238c90). The second round above is the one on the final head. - `node scripts/check-i18n-bundles.mjs --write --filter=platform-objects` regenerated the 21 drifted bundle files (eleven metadata-form bundles and ten source-hash tables); the new leaves were then translated by hand and a second `--write` dropped their source-hash entries. `pnpm check:i18n`, `check:i18n-stale-fill` and `check:i18n-coverage` (423 baselined, none new) exit 0. - Suites under the lock: `pnpm --filter @objectstack/spec test` 842 files, 26942 passed, 1 todo. `pnpm --filter @objectstack/platform-objects test` 122 files, 1972 passed (first run: 3 failed, the hook form's enumerated-children census `9` and the zh-CN/ja-JP/es-ES row-label census `738`, which the three new rows move to `12` and `741`; updated in e764497 with their reason). From `ui/`: `SchemaForm.keyOnlyRecord-26835.test.tsx`, `ResourceEditPage.hookRefusalReasons-33657.test.tsx` and `metadata-form-i18n.test.ts`, 39 passed. The full app-shell suite and the rest of the farm are CI's. - `pnpm --filter @object-ui/app-shell run type-check`, `pnpm --filter @objectstack/spec typecheck`, `pnpm --filter @objectstack/platform-objects typecheck`: exit 0. ESLint `--no-inline-config` on every changed source and test file: exit 0, one warning on an unchanged line of the existing harness (`sink.value = next`). `pnpm check:new-line-citations` (from `ui/`): 0 new, exit 0. - `origin/main` moved 9 commits past base bd96ec9; none touches a file in this diff. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01FEkQ5oQHgtkqYPCqstiKir --- _Generated by [Claude Code](https://claude.ai/code/session_01FEkQ5oQHgtkqYPCqstiKir)_ <!-- signed: domain:ui#1 · os-project-manager · session_01FEkQ5oQHgtkqYPCqstiKir --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
Fixes #33214
Clause-②: yes
Metadata-protocol: added
Skills-docs: follow-up #33658 — skills/objectstack-data/references/data-hooks.md (the "Declared refusals (
refusals)" section teaches a sandboxedbodyonly, one sentence per code, no params), skills/objectstack-i18n/SKILL.md (thehooks.HOOK.refusals.CODE.messagerow has noreasonskey)维护者速读
handler写的 hook 现在也能声明refusals(拒绝目录)。一个错误码下可以登记多句话(reasons),每句话可以带参数(params)。中文用户看到中文,线上的错误码不变。jsbody 翻译拒绝提示,所以 zh-CN 用户读到的是英文。按裁决 6879477573(问一 A、问二 S1、问三 是)落地。refusals的 hook 两条路径都不受影响;声明了refusals、但没用新功能的 hook,线上信封与改动前逐字节相同(有对比测试钉住)。新增的进程内拦截只在声明了refusals的 handler 上启用。回滚 = revert 本 PR。packages/runtime/src/sandbox/hook-refusal-catalogue.ts(进程内应答与宿主错误标记)、packages/runtime/src/sandbox/body-runner.ts的withInProcessHookTitle、packages/spec/src/data/hook.zod.ts的refuseUndeclaredLiteralRefusalCode。pnpm --filter @objectstack/verify exec vitest run src/harness.hook-refusal-door.test.ts,预期 2 个测试通过:源码启动(handler 进程内运行)与产物启动(沙箱 body)在Accept-Language: zh-CN下返回逐字节相同的中文拒绝信封。What changes
Under maintainer ruling 6879477573 (问一 A · 问二 S1 · 问三 是, inside ruling 6431311681 letter A), a hook's refusal catalogue is answered on every path the hook runs on, and an entry can hold several declared sentences with parameters.
refusalson ahandlerhook (packages/spec/src/data/hook.zod.ts,hook-refusal-codes.ts). The schema acceptsrefusalson a hook whosehandleris an inline function or a string reference. It reads an inline handler's literal throws off its source, the same text the build's lowering peels, and refuses an undeclared code or reason there, athandler. Ajsbody still wins over a handler, as at bind. Still refused: anexpressionbody, or neither a body nor a handler.packages/runtime/src/sandbox/body-runner.tswithInProcessHookTitle, wired atpackages/runtime/src/app-artifact-handlers.tswithhookandoptions.i18n). For a hook that declaresrefusals, the seam hands the handlerctx.api,ctx.qlandctx.titleas host surfaces that mark every error a host call raises, and answers the handler's own throw throughresolveInProcessHookRefusal(hook-refusal-catalogue.ts), which builds the sameSandboxErrorthe body path builds. A marked host error, aSandboxErrorand a crash pass through unchanged. A callback the handler hands a host call (atransactionbody) stays the handler's: what it throws is the handler's refusal. A hook with no catalogue runs exactly as before; the seam's old call shape (a hook name) is unchanged.reasons(S1):refusals.CODE.reasons.REASON.message, with snake_case reasons. The hook throws{ code, reason }and is answered with the reason's sentence, the entry's status and the unchanged wire code. An undeclared reason is refused loudly: at save when literal, otherwise as a500naming the hook, the code and the reason. The translation key ishooks.HOOK.refusals.CODE.reasons.REASON.message(translation.zod.ts,hookRefusalMessageKey(hook, code, reason?)). The i18n walk counts each reason (packages/lint/src/i18n-walk.ts), andos validaterefuses a reason key the code does not declare (packages/lint/src/validate-translation-references.ts).params: the entry declares names, and its sentences may hold double-brace holes over those names only. A hole over an undeclared name is refused at save by the closed-scope judge the action copy slots use (closedScopeTemplateRefusal). An entry with noparamsstays plain text and every hole in it is refused, as before. The runtime fills the picked (translated or declared) sentence from the throw'sparamsthrough the formula template engine the flowendrefusal renders with, with only declared names in scope.paramsandreasoncross the QuickJS__errorInfochannel, kept offSandboxErrorInfoand the wire (sandboxRefusalAddressOf,quickjs-runner.ts).translation.zod.tshooks docblock's "no hole is filled" sentence is corrected. Docs:content/docs/automation/hooks.mdxgains a "Refusing in the user's language" section;content/docs/ui/translations.mdxandcontent/docs/protocol/kernel/i18n-standard.mdxgain the reasons key.Generated and ledger files moved with it:
api-surface,export-origins,authorable-surface, the reference docs, the strictness ledger counts, liveness rows (hook/refusals.reasons,hook/refusals.params,translation/hooks.refusals.reasons), anddropped-refinements.baseline.json(the hole rule is now a refinement, because it depends onparams, sodata/HookRefusalis declared there).Tests
packages/spec/src/data/hook-refusals.test.ts: handler accept/refuse, reasons accept/refuse, literal reason reading, params holes. 96 pass.packages/runtime/src/sandbox/hook-refusal-catalogue.test.ts: body-path reasons and params; a byte-identical envelope pin for a hook using none of the new parts, whose literal was measured on the base commit e540baf with the base's three runtime files checked out; the in-process seam's wire against the body path's, zh-CN, faults, crash and host-raised pass-through (ctx.api,ctx.ql, inside atransactioncallback), and the untouched no-catalogue hook. 36 pass.packages/verify/src/harness.hook-refusal-door.test.ts:bootStack(config)(in-process handler) against the artifact door (sandboxed body) underAccept-Language: zh-CN; the two envelopes are byte-identical. 2 pass.packages/cli/test/i18n-hook-refusal-coverage.test.ts(reasons harvested, demanded, scaffolded; 10 pass),packages/cli/test/lower-callables.test.ts(the build lowering keeps the catalogue and is judged on the lowered body; 31 pass),packages/lint/src/validate-translation-references.test.ts(reason translation targets; 241 pass).Acceptance notes
Studio hook form: filed Studio: the hook form offers a refusal as message + status only, so it cannot author the
refusals.CODE.reasonsandparamsthat #33214 adds #33657. The form offers a refusal asmessage+statusonly, so it cannot authorreasons/params(the dev's open question 2, answered A by record 6889389473).A hook that already declares
refusalsand also throws an unrelated stringreasonproperty is now judged on that reason: an undeclared one is a500fault. Before this change areasonfield was not read.On the in-process path, the host surfaces are proxies only for a hook that declares
refusals. A method is called on the object the proxy fronts, and anything the handler hands back to a host call is unwrapped first.The published JSON Schema no longer carries the hole pattern on a refusal
message(now a refinement; declared indropped-refinements.baseline.json).Verification
Measured at head
68aca57b(after one merge oforigin/main,9f736f2e), in this cloud container.Ablations, one per new pin (each mutation proven on disk by scripts/ablation-replace.mjs; each restore proven by blob == HEAD and an empty git diff HEAD)
ctx.api,ctx.ql, transaction). A5 the VM address channel removed: 6 red. A6 the reason sentence pick removed: 4 red. A7 one byte added touserMessage: the byte-identical pin and 15 more red.packages/lint/dist(preflight: marker present in 2 built files): the 3 CLI reason pins red; restore rebuilt, marker absent, tree clean.packages/runtime/dist(preflight: marker present in 2 built files; the mutate leg's declarations step refused the now-unused names after the JS was emitted): the source-door parity pin red, the artifact door green; restore rebuilt, marker absent, tree clean.Local gates and package suites
node scripts/pm/dispatch-gates.mjs --commands(no paths) derives 118 commands at this head;--ranreconciles 118 of 118. First run: 113 at exit 0, and five non-zero:check:dispatcher-error-vocabulary(exit 1, a finding): two new helpers passed acodeparameter into an object literal. Restructured so the code reaches the literal as a local, as before. Exit 0 at head.check:test-source-alias(exit 1, a finding): two new tests loaded modules inside a clocked window. The loads moved to module top. Exit 0 at head.check-plugin-teardown-shape.mjs --self-test(exit 3, prerequisite: the pinned commit was outside the shallow clone): fetched, exit 0.check:skill-examples(exit 3, prerequisite:client-reactnot built): built, exit 0.check:dual-build-cjs-loads(exit 3, prerequisite: needs every package'sdist/, a full monorepo build): NOT MEASURED locally; CI runs it.check:generated,check:api-surface,check:dual-source-exports,check:entry-nameability,check:exported-any,check:skill-examples,check:liveness, every other speccheck:*in the list,check:cross-package-test-inputs,check:i18n-walk-parity,check:doc-authoring,check:issue-citations,check:nul-bytes,check:spec-docblock-symbol-anchors, and the changeset gates.@objectstack/spec839 files pass, 1 skipped (26874 tests pass) at head;@objectstack/runtime599 files (10694) pass;@objectstack/lint208 files (8890) pass;@objectstack/cli --project unit417 files (5956) pass;@objectstack/verify52 files (439) pass. The CLI integration layer is declared to CI (no spawn entry touched).Generated by Claude Code