Skip to content

Commit 2c93001

Browse files
docs(skills): data-hooks says an action body's input and ctx are already bound and names the refused redeclaration (#36143)
Fixes #34988 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:让 AI 写「动作脚本」的客户,技能手册现在会先说明脚本里已有两个现成的参数,不能再声明同名变量;以前手册没提,AI 照常见写法写出的脚本在校验和保存时被拒。 - 为什么做:属于「教 AI 正确编写元数据的技能手册」这条线,补上平台已经拒收、手册却没教的一处。 - 出错会怎样:只改说明文字,不改平台行为;最坏是措辞误导作者,撤回这次合并即可恢复原文。 - 要你做什么:这是对外发布的技能手册,需要你审阅并合并。 ## What changes `skills/objectstack-data/references/data-hooks.md`, and its eval case 33: - **The action wrapper paragraph** (under the sandbox `ctx` table) now reads: the action params arrive as `input`; both names are already bound; `const input = ctx.input || {};` or `let ctx` is `action-body-does-not-compile`, refused like a hook body's, with a link to the hook compile paragraph in § Sandbox restrictions, which carries the commands (`os validate`, `os build`, `os lint`), the runtime save (`422 INVALID_METADATA`) and the fix. - **The hook compile paragraph** it links to: the suggested local is now `const data = ctx.input || {};` (was `const input = …`, the exact line an action body is refused for, now one click away from the action warning); `a runtime hook save` became `a runtime save`, so the sentence holds for the action and object saves too. - **Paid for inside the file.** The file sat 2 tokens under its shrink-only ceiling on `origin/main` (`check-skills-token-ratchet`: 10120 of 10122), so the new text is paid for by two deletions of restatement: the hook paragraph no longer re-prints the `(async (ctx) => { … })` wrapper that § The `body` shape shows, and the `condition` paragraph no longer repeats the `input.id` / single-record-context clause that the "Why so few?" note states with the same ADR-0058 citation. The rule id and the refusal are quoted from the code on `origin/main`: `ACTION_BODY_DOES_NOT_COMPILE = 'action-body-does-not-compile'` in `packages/lint/src/validate-action-body-compiles.ts`, and the ADR-0087 entry `action-body-does-not-compile-refused` ("Refused at error as `action-body-does-not-compile` (422 INVALID_METADATA at the doors)", loaded by `os validate` / `os build` / `os lint`). - **Eval case 33** (`skills/objectstack-data/evals/hooks-security-seeds-datasources.json`, rework round 1 on the L2 should-fix S1): `must_contain` is now `hook-body-does-not-compile` and `ctx.input` (a token both printed fixes carry; the old `input.status` failed the `const data = …` rename the paragraph now prints), and `expected_output` spells that rename. Changeset: `.changeset/34988-action-wrapper-redeclare.md`, `@objectstack/skills` patch (the catalog ships in that package). ## Tests Text only; no tested behaviour changes, so no ablation. Skills size readings (head `7613457f`; `data-hooks.md` unchanged since `54a18393`): | Reading | Before | After | |:--|:--|:--| | `data-hooks.md`, lines | 884 | 885 | | `data-hooks.md`, tokens (`ceil(utf8 bytes / 4)`) | 10120 | 10121 (ceiling 10122) | | All `skills/*/SKILL.md`, lines | 4945 | 4945 | | Whole shipped tree, tokens | 288733 | 288734 | ## Acceptance notes - Card Done-when, each clause: parameters named as already bound (yes); the refused redeclaration shown (`const input = ctx.input || {};`, `let ctx`); the lint rule linked (rule id `action-body-does-not-compile` plus the link to the paragraph listing the commands that report it). - The claim's file surface was the action wrapper paragraph only. Three more spots in the same file were touched, all forced by the token ceiling or by the link: the two restatement deletions and the hook paragraph's two wording changes above. No ceiling row was moved. - `os explain action-body-does-not-compile` (the rule carries an explanation in `packages/lint/src/rule-explanations.ts`) did not fit the ceiling and is not mentioned. ## Verification - First file to read: `skills/objectstack-data/references/data-hooks.md`, the hunk under the `ctx` table (the new teaching), then the `condition` hunk (the riskiest one: a deletion in text this card did not own). - Two-minute check: `node scripts/check-skills-token-ratchet.mjs` prints `skills/objectstack-data/references/data-hooks.md is 10121 tokens (ceiling 10122; headroom 1)` and exits 0. Local gates at `54a18393`: the 48 commands `dispatch-gates --commands` derives; 43 exited 0 (among them `check:skill-links`, `check:skill-refs`, `check:skill-identifier-liveness`, `check:doc-authoring`, `check:nul-bytes`, `check-skills-token-ratchet`, `check-empty-changeset`); 5 exited 3, NOT MEASURED, reason: they need a full workspace build this text change does not warrant, left to CI (`check:doc-formula-expressions` in `@objectstack/lint`, `check:dts-closure`, `check:dual-build-cjs-loads`, `check:lean-entry-closure`, `check:sourcemap-no-sources-content`). `overlap-check` against `origin/main` and open pulls 36089, 36087, 36067, 36104: merges cleanly. --- _Generated by [Claude Code](https://claude.ai/code/session_017xRBcSPM86QhYAcidhG5Bu)_ <!-- signed: repo:objectstack#6 · sunhaolin · session_017xRBcSPM86QhYAcidhG5Bu --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent a64c3b8 commit 2c93001

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@objectstack/skills': patch
3+
---
4+
5+
Clause-②: no
6+
Metadata-protocol: none
7+
8+
`objectstack-data`'s hook reference (`references/data-hooks.md`) now says that `input` and `ctx` are already bound in an action body's `(async (input, ctx) => { … })` wrapper, shows the refused redeclaration (`const input = ctx.input || {};`, `let ctx`) with its rule id `action-body-does-not-compile`, and links the hook-body compile paragraph for the commands, the `422 INVALID_METADATA` save and the fix. That paragraph's suggested local is now `const data = …`, a name no wrapper binds. The file stays inside its token ceiling by dropping two restatements.

‎skills/objectstack-data/evals/hooks-security-seeds-datasources.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,10 @@
350350
{
351351
"id": 33,
352352
"prompt": "`os validate` reports an error on this `beforeInsert` hook on `lead`, and I cannot see why: `body: { language: 'js', source: \"const ctx = ctx.input || {}; if (!ctx.status) ctx.status = 'new';\", capabilities: [] }`. What is wrong, and what should the source be?",
353-
"expected_output": "The `js` source is compiled inside the wrapper the runtime runs it in, `(async (ctx) => { … })`, where `ctx` is already the parameter: `const ctx = …` declares it a second time, a SyntaxError before any statement runs. The finding is `hook-body-does-not-compile`, an error from `os validate`, `os build` and `os lint`, and a runtime save of the hook is refused with `422 INVALID_METADATA`. Fix: use `ctx` as it is (`if (!ctx.input.status) ctx.input.status = 'new';`) or give the local another name (`const input = ctx.input || {}; if (!input.status) input.status = 'new';`). Does not suppress the rule, and does not move the logic to a deprecated `handler`.",
353+
"expected_output": "The `js` source is compiled inside the wrapper the runtime runs it in, `(async (ctx) => { … })`, where `ctx` is already the parameter: `const ctx = …` declares it a second time, a SyntaxError before any statement runs. The finding is `hook-body-does-not-compile`, an error from `os validate`, `os build` and `os lint`, and a runtime save of the hook is refused with `422 INVALID_METADATA`. Fix: use `ctx` as it is (`if (!ctx.input.status) ctx.input.status = 'new';`) or give the local another name (`const data = ctx.input || {}; if (!data.status) data.status = 'new';`). Does not suppress the rule, and does not move the logic to a deprecated `handler`.",
354354
"files": [],
355355
"assertions": {
356-
"must_contain": ["hook-body-does-not-compile", "input.status"],
356+
"must_contain": ["hook-body-does-not-compile", "ctx.input"],
357357
"must_not_contain": []
358358
}
359359
}

‎skills/objectstack-data/references/data-hooks.md‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ in neither). So:
164164
is not in hand, which fails closed rather than reading an update as an
165165
insert. The `before*` dispatch of a predicate (`multi: true`) write is
166166
**not** such a case: `beforeUpdate` / `beforeDelete` dispatch once per
167-
matched row, each on a single-record-shaped context whose `previous` is that
168-
row's pre-image and whose `input.id` (`handler`; a `body`: `ctx.previous.id`) names the row (ADR-0058 Addendum II,
167+
matched row, each with that row's pre-image as `previous` (ADR-0058 Addendum II,
169168
D1/D2), so a transition condition evaluates there exactly as on a
170169
single-record write, and `record` is that row's state, stored ⊕ payload. Only
171170
the *payload* stays batch-scoped (D3):
@@ -248,7 +247,9 @@ The sandbox is handed a **JSON snapshot** of these (built by
248247

249248
(Action bodies additionally receive `ctx.recordId` and `ctx.record`, and their
250249
wrap is `(async (input, ctx) => { … })(input, ctx)` — the action params arrive as
251-
the first arg.)
250+
`input`. Both are already bound: `const input = ctx.input || {};` or `let ctx`
251+
is `action-body-does-not-compile`, refused
252+
[like a hook body's](#sandbox-restrictions).)
252253

253254
### `ctx.api.object(name)` — the cross-object repo
254255

@@ -338,12 +339,12 @@ The body runs in an isolated QuickJS VM, **not** Node:
338339
the hook. A `body` must be **self-contained**: inline the helper, or keep that
339340
hook as a bundled (deprecated) `handler`.
340341
- **Refused when it does not compile:** a `js` source is compiled, unrun, inside
341-
its `(async (ctx) => { … })` wrapper, where `ctx` is already declared. So
342+
its wrapper, where `ctx` is already declared. So
342343
`const ctx = ctx.input || {};` (or `let ctx`, one name declared twice, any
343344
syntax error) is `hook-body-does-not-compile`: an **error** from `os validate`,
344-
`os build`, `os lint` and a runtime hook save (`422 INVALID_METADATA`), naming
345+
`os build`, `os lint` and a runtime save (`422 INVALID_METADATA`), naming
345346
the hook, the `SyntaxError` and its line. Fix: use `ctx` as it is, or rename
346-
the local (`const input = ctx.input || {};`). A job's `js` body runs in the
347+
the local (`const data = ctx.input || {};`). A job's `js` body runs in the
347348
same wrapper: `job-body-does-not-compile`, from the three commands. A regex
348349
pattern the checking engine refuses is a warning: the runtime may accept it.
349350

0 commit comments

Comments
 (0)