Repository navigation
fix(cli): the hook-body extractor infers member tokens through a body-local alias of ctx.MEMBER - #38731
Conversation
…-local alias of ctx.MEMBER Claude-Session: https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 1 package(s): 6 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
What this run could not see
Coarse fallback — 40 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 caa840a74280f86957d609f3bc78279207f34b72 && git checkout caa840a74280f86957d609f3bc78279207f34b72
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 0d68ce2db33a4328362b2695174b47277f377daa 2ed55579aa1ab62f2c6c276a6ccc7b2a5e0e7552 && git checkout -B drift-repro 0d68ce2db33a4328362b2695174b47277f377daa && git merge --no-ff 2ed55579aa1ab62f2c6c276a6ccc7b2a5e0e7552
node scripts/docs-audit/affected-docs.mjs --json 0d68ce2db33a4328362b2695174b47277f377daa
|
… alias shapes and the email and activity rows Claude-Session: https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#3 · os-steve · session_01ADHkmSwS4mQyXWrddL4r6B Final green head · 2026-11-30T09:19Z · zone o3-B ·
|
|
repo:objectstack#3 · os-steve · session_01ADHkmT9HTWLMN33WUVxVWB 席位核对ACCEPT @ 2ed5557 (card #38690, step 1; draft; 4 files, +261/−7)
Checks at this head (read before writing, latest per name): 44 success, 19 skipped, 0 failure, 0 in progress. Two of the skips are the opt-in |
|
repo:objectstack#3 · os-steve · session_01ADHkmSwS4mQyXWrddL4r6B Landing · 2026-11-30T09:27Z · zone o3-B · head
State: ready for review and auto-merge in this stroke. |
…an authored one (objectstack-ai#38755) <!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi92EfsyzCyjwc8X5TRpmNj6z)_ Fixes objectstack-ai#38690 Clause-②: no (narrowing) Metadata-protocol: narrowed Skills-docs: none — no `skills/**` text taught the lowered exemption; the one docs page that did (`content/docs/deployment/validating-metadata.mdx`, the two capability rows) is corrected here ## 维护者速读 - 用户能看到什么变化:挂在字符串 handler / target 旁的钩子和脚本动作函数体(构建产物,或手写的)现在也会被校验权限声明,缺权限时在发布和 os validate 时就报错,而不是上线后每次运行被沙箱拒掉;同时构建能认出 `ctx.log?.info(…)` 这类可选链、空白、注释写法,自动补上权限。 - 为什么做:这是「钩子与动作函数体权限校验」这张卡的第二步;取消当时为构建产物留的豁免,并把构建的推断补到与校验规则逐个写法一致。 - 出错会怎样:手写在字符串 handler / target 旁、漏声明权限的函数体,以及构建后丢了权限的产物,发布会被拒并点名缺的权限;首方示例与连接器应用实测零新增拒绝,可整 PR 撤回。 - 要你做什么:无。 ## What changes `validate-action-body-capabilities` (`@objectstack/lint`) skipped a body it took for one the build lowered: a hook body `os build` / `os verify` lowered from an inline `handler`, and at the runtime publish doors any hook body beside a string `handler` (`isLoweredHandlerBody`); and any action body beside a string `target`, judged for `api.write` alone (`isLoweredTargetBody`). The skip covered a body written by hand beside a string ref as well, since the rule cannot tell the two apart. The reason was that the build's capability inference did not read every gated call the rule reads. Step 1 of this card (PR objectstack-ai#38731) and objectstack-ai#38653 (PR objectstack-ai#38686) closed that gate by gate; this PR closes it spelling by spelling. So this PR: - drops both skips and the three helpers that only served them (`isLoweredHandlerBody`, `isLoweredTargetBody`, `loweredActionBodyPaths`). `validateActionBodyCapabilities` no longer takes the `loweredHookRefs` context, and its registry entry passes the stack alone. Neither function was on the package's barrel. - makes the CLI extractor (`packages/cli/src/utils/extract-hook-body.ts`) infer each gated call in each spelling the rule reads. Its `ctx`-anchored member patterns, and their rebound siblings for a renamed or destructured hook context, were literal `ctx.log.info`: `ctx.log?.info(…)`, `ctx?.crypto.randomUUID()`, `ctx.activity?.append(…)`, `ctx.email?.send(…)`, `ctx . log . info(…)` and `ctx.title?.(field)` lowered without their token, and the rule read each as the gated call. Each step now takes `?.` and whitespace, `title` takes the optional call, and inference also reads a comment-blanked copy of the source (the rule's own walk, strings kept), so a comment between steps no longer hides a call. Every change widens: what inferred a token before still does. A hook handler that calls `ctx.email.send` in any of these spellings now lowers with the grant and is refused at build by the hook parse, as `ctx.email.send(…)` already was. - exports `SANDBOX_CAPABILITY_GATES` and `type SandboxCapabilityGate` from the lint barrel, and moves the step-1 CLI enumeration pin off its hand-kept mirror onto that table. - adds a PARITY pin in the CLI. Every gate, leaf, receiver shape and face, in each spelling the rule reads (plain, `?.` before the member, before the leaf and before the call, whitespace, a block or line comment between steps), is lowered through `extractLoweredBody` and judged by `runAuthoringRules('build', …)` twice: ungranted it must draw the gate's finding (so the rule reads that spelling and the pin is not vacuous), lowered it must draw none. A REBOUND block does the same through a hook handler's renamed and destructured context parameter. The one exclusion is a hook body's `email.send`, pinned instead as a build refusal in every spelling. - corrects the text that described the exemption: the two `os explain` entries, the docs rule table, the rule's docblock and the comment over the `lowerCallables` target-shape pin. - registers the narrowing as ADR-0087 semantic entry `lowered-hook-and-action-bodies-capabilities-judged`, with a BREAKING changeset carrying FROM → TO for both authors (a body lowered by the build or written by hand beside a string ref) and the remedy for each: rebuild, or declare the token. - corrects the pending objectstack-ai#37815 changeset and its semantic entry, whose sentences this PR makes false (see Deliberate correction). The limit, stated: the build's reading covers the rule's by the pin's enumeration (census × receivers × spellings × faces), not by proof. Where the two differ outside it, the build reads more (a renamed context root, a spelling inside a string), and the over-inferred grant is one the sandbox never checks, except `email.send` on a hook, which is refused at build as before. Measured cost before the change, on `origin/main` at `f782a12033` (scratch script, not committed): every first-party stack (`examples/app-crm`, `app-multi-package` with its two packages, `app-showcase`, `app-starter`, `app-todo`, `packages/apps/connector-docusign`, `connector-github`, `connector-stripe`) loaded, normalized, lowered and parsed as `judgeAuthorTimeRules` does, then judged by the shipped rule and by the rule with both skips emulated away. 70 hook and action bodies, 1 of them lowered (app-crm's opportunity hook): 0 findings shipped, 0 without the skips, **0 newly refused**. The population holds one lowered body, so it bounds authored bodies; the lowered side is bounded by the PARITY pin. ## Tests - New `packages/lint/src/validate-action-body-capabilities.lowered-38690.test.ts` (26 tests). Per removed skip, a lowered body calling each gate ungranted, spelled directly and through an alias: refused (hook: `os validate` / `build` / `lint` and the hook save door; action: top level, object-inline, `os validate` / `build` / `lint`, the action and object doors). Controls: the same lowered body granted is not refused. A lowered body's write keeps its own id beside the other tokens. - `packages/cli/test/extract-hook-body-local-alias-38690.test.ts` (284 tests): the mirror table is deleted; ENUMERATION reads `SANDBOX_CAPABILITY_GATES` and spells every leaf in every spelling through seven receivers; PARITY and REBOUND as above; a hook handler calling `ctx.email.send` in seven spellings plus a renamed context is refused by `HookSchema` after `lowerCallables`. Red first, each fix: - PARITY harness: the earlier PARITY judged the extracted record without `language: 'js'`, which the rule skips, so it could not go red. With the body record the build writes and the widened spellings, against the old extractor: 51 failed. - Extractor `?.` / whitespace / optional call / rebound: the pins against the extractor at `a68c0a41cc`: 76 failed of 247 (ENUMERATION 27, PARITY 24, REBOUND 25). Hook mail in the new spellings: 4 failed of 8 (they built clean before). - Comment between steps: against the extractor at `2aec12e986`: 210 failed of 284, every one a comment spelling. Ablations at the head (`scripts/ablation-replace.mjs`, restore proven blob == HEAD): `MEMBER_STEP` back to a plain `\.`: 84 failed (ENUMERATION 32, PARITY 28, REBOUND 20, mail 4). `title` without the optional call: 11 failed. Inference over the raw source only: 210 failed. The skips re-inserted in the rule, per removed skip: hook 14 failed / 12 passed, non-write action 12 failed / 14 passed of the lint file. Forced test edits, named: - `packages/lint/src/validate-action-body-capabilities.hook-and-tokens-37815.test.ts`: two describe blocks deleted, `authored hook bodies only: a body lowered from a handler is not judged (objectstack-ai#37815 route C)` and `authored action bodies only past the writes: a body lowered from a target is judged for api.write alone (objectstack-ai#37815 M1)`. They pinned the two skips this PR removes; the new file pins the opposite. Their authored-body halves stay covered by the same file's arm (a)/(b) cases. The two predicate imports go with them. - `packages/cli/test/lower-callables.test.ts`: comment only, over the `[objectstack-ai#38653]` target-shape pin, which named `isLoweredTargetBody`. The pin itself is unchanged. ## Acceptance notes - The lowered hook finding's path stays `hooks[N].body.capabilities` on the seat's answer (claim amendment 5). Its premise, that a fresh build never draws the finding, holds again at this head for every spelling the PARITY pin enumerates; for an artifact that lost a grant, or a hand-written body, that key is the right one. ## Deliberate correction `Check Changeset` (`check-empty-changeset`) is red on purpose: this PR edits a pending release note it did not add. DELIBERATE CORRECTION, not a collision; ⛔ do not restore the base text. Both files below are unreleased (merged after 19.0.0-next.2) and ship in the same release as this PR, and this PR makes their sentences about lowered bodies false. Text only: no code, no entry id, no level or disposition line changes. Scope per claim amendment 5 (7276409399); rewrites 2 and 4 of the changeset and 3 and 4 of the entry re-trued per L2 7278772654. **`.changeset/37815-body-capabilities-every-gate.md`** 1. BREAKING paragraph. Before: "whose authored L2 body calls a member". After: "whose L2 body calls a member". 2. `hook-body-capability-undeclared` bullet. Before: "an authored L2 hook body that calls any of those gates" … "Only a body the author wrote is judged: a hook body `os build` / `os verify` lowered from an inline `handler` is not, since its grant is the build's inference (the lowered reading is objectstack-ai#38653)." After: "an L2 hook body that calls any of those gates" … "A hook body `os build` / `os verify` lowered from an inline `handler` is judged the same way: its grant is the one the build inferred from its calls, and the build reads each gated call in each spelling the rule reads." 3. `action-body-capability-undeclared` bullet. Before: "an authored L2 action body that calls a gate other than the writes without its token. An action body `os build` / `os verify` lowered from an inline `target` function is not judged for these tokens, since its grant is the build's inference (the lowered reading is objectstack-ai#38653); its writes are still judged under `action-body-write-capability-undeclared`." After: "an L2 action body that calls a gate other than the writes without its token. An action body `os build` / `os verify` lowered from an inline `target` function is judged the same way, against the grant the build inferred from its calls." 4. Paragraph after FROM → TO. Before: "A hook whose body was lowered from an inline `handler` is unchanged: FROM and TO alike, it is not judged by this rule. So is an action whose body was lowered from an inline `target` function, for every token but `api.write`: … TO, it still builds clean, and its writes are judged as before." After: "A hook written as an inline `handler`, and an action written as an inline `target` function, need no change: the build infers the grant from each gated call in each spelling the rule reads (`?.`, whitespace or a comment between steps, the optional call), so the body it lowers carries the token. … TO, it still builds clean, its lowered body granted `api.transaction`." **`packages/spec/src/migrations/entries/semantic/19.hook-and-action-bodies-calling-an-ungranted-gate-refused.ts`** (entry `hook-and-action-bodies-calling-an-ungranted-gate-refused`, id unchanged) 1. Header comment. Before: "an authored L2 hook body that calls". After: "an L2 hook body that calls". 2. `surface`. Before: "only a body the author wrote (a hook body lowered from an inline handler is not judged, and an action body lowered from an inline target function is judged for its writes alone, as before)". After: "whether the author wrote the body or os build lowered it from an inline handler or target function". 3. `replacement`, last sentence. Before: "needs no change for the other tokens: its lowered body is not judged for them (a later change carries the lowered reading)." After: "needs no change: os build infers the grant from each gated call in each spelling the rule reads (?., whitespace or a comment between steps, the optional call), so the body it lowers carries the token, and that lowered body is judged like an authored one." 4. `reason`. Before: "A hook body os build lowered from an inline handler is not judged, and an action body it lowered from an inline target function is judged only for api.write, as before: such a grant is the build's inference, not the author's, and the inference does not yet read every gated shape, so a hook written as a handler and an action written as a target function are unchanged." After: "A hook body os build lowered from an inline handler, and an action body it lowered from an inline target function, are judged the same way: their grant is the build's inference, which reads each gated call in each spelling the rule reads, pinned spelling by spelling against the rule, so a hook written as a handler and an action written as a target function build clean." ## Verification Two-minute check: `pnpm --filter @objectstack/cli exec vitest run test/extract-hook-body-local-alias-38690.test.ts`. Expect 1 file, 284 tests passed. With `MEMBER_STEP` in `extract-hook-body.ts` set back to a plain `\.`, 84 of them fail. Read first: the `MEMBER_STEP` / `memberLeafRx` / `blankComments` block and the inference loop in `packages/cli/src/utils/extract-hook-body.ts`, then the PARITY block in the test above, then the two removed skips in `packages/lint/src/validate-action-body-capabilities.ts`. <details><summary>Local gates at 3ca3538 (head)</summary> - Derived round: `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` listed 122 commands (the 119 of the last round plus `check:i18n`, `check:i18n-coverage`, `check:i18n-walk-parity`); each ran with stdin closed and its exit recorded before any pipe: 121 :: exit 0, and `node scripts/check-empty-changeset.mjs --base origin/main` :: exit 1, the DELIBERATE CORRECTION refusal above, by design. `dispatch-gates --ran`: 122 derived, 122 run, 0 NOT-MEASURED, 0 UNRUN. - Packages: `pnpm --filter @objectstack/lint test` 252 files / 10106 tests passed; cli `vitest run --project unit` 451 files / 6737 tests passed; `pnpm --filter @objectstack/lint typecheck` and `pnpm --filter @objectstack/cli typecheck` exit 0; spec rebuilt, `src/migrations` 5 files / 209 tests passed. - `node scripts/check-changeset-no-major.mjs --base origin/main --event` over this body: exit 0 (level axis: `@objectstack/lint` minor carries `Metadata-protocol: narrowed`; ADR-0087 `registered lowered-hook-and-action-bodies-capabilities-judged`). - `node scripts/pm/overlap-check.mjs` at this head: clean against origin/main (f576dee), objectstack-ai#38497 and objectstack-ai#38192. - Not run locally: the cli `integration` layer and `test:repo` (CI's Test Core); the dogfood battery is CI's on this head (`!` title, narrowing arm). </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmSa9QNE6qXdrFAvnUr)_ <!-- signed: repo:objectstack#3 · os-steve · session_01ADHkmSa9QNE6qXdrFAvnUr --> --------- Co-authored-by: Claude <noreply@anthropic.com>
Requested by Steve · project thread
Refs #38690 (step 1)
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
os buildlowers an inline hookhandler/ actiontargetto ajsbody and infersbody.capabilitiesfrom its source. The member patterns spelledctx.(ctx.log.info,ctx.crypto.randomUUID,ctx.email.send,ctx.activity.append), and the rebind followed only the handler's own parameter, so a body-local alias inferred nothing and the sandbox refused the call at run time, while the publish check (validate-action-body-capabilities,memberReceivers) reads the same alias as a receiver ofctx.MEMBER.bodyMemberAliases(new,packages/cli/src/utils/extract-hook-body.ts) reads the handler's parse for exactly the two alias shapes the lint rule credits:const l = ctx.MEMBER(notctx?.MEMBER, not a chain) and a plain element destructured offctx(const { log } = ctx,const { log: l } = ctx; no default, rest or nesting). A name counts only when declared once and never assigned or stepped again (the rule'sboundOnce).titleis collected on the hook face only (the host buildsctx.titleonly for hook bodies).reboundCapabilitiestakes those aliases as a third argument and reads them the way the rule reads its receivers: a CALL of a gated leaf (?.allowed on either side), and fortitlea call with an argument. A field read infers nothing.ExtractedBody.capabilitiesunion is unchanged (seven tokens). No spec, nopackages/lintedit.content/docs/automation/hook-bodies.mdx### Capability inference(claim amendment 1): thecrypto.uuidandlogrows name the alias shapes, newemail.sendandactivity.appendrows (which the table never had) name theirs, the*.title(…)row names the hook-face alias form, one sentence defines the two alias shapes and what infers nothing, and the over-inclusive paragraph now namesemail.sendas its exception (a hook body is never granted it, so a hook that spells or alias-calls it is refused at build).Read first (by risk):
bodyMemberAliases(the shape set must equal the rule's), the call-shaped alias loop at the top ofreboundCapabilities, then the docs table hunk (every sentence there must hold for the extractor as built).Tests
New
packages/cli/test/extract-hook-body-local-alias-38690.test.ts(93 cases):log(local, destructure, renamed destructure),crypto.uuid,email.send(measured here; the card had it unmeasured),activity.append(local, destructure), and a hook'stitle(FIELD)givingapi.read. At based2caaec40dthis file ran 49 failed / 44 passed.ctx.input.log, a reassignedlet, a local bound toctx.log.child, field reads (not calls) off each member alias, a title alias read or called with no argument, an alias spelled inside a string, a destructure with a default.ctx.MEMBERreceiver (all eight rows of lint'sSANDBOX_CAPABILITY_GATES,apiincluded), throughctx.MEMBER, a bound local, a destructure and a renamed destructure.SANDBOX_CAPABILITY_GATESis exported by none of@objectstack/lint's three entries (.,./runtime,./rule-explanations), and a relative import intopackages/lint/srcwould need across-package-test-inputsdeclaration outside this card's file surface, so the table is mirrored in the test and pinned to the cli's own published union (satisfies RecordoverExtractedBody['capabilities'], plus a coverage assertion).Ablations (one per member family, scripts/ablation-replace.mjs)
Each removes one member from
ALIASABLE_MEMBERS, runs the new file, restores; every restore printedblob == HEADandgit diff HEAD is empty.logremoved: 13 failed of 93 (the sixlogalias cases, sixlogenumeration rows, the optional-call case).cryptoremoved: 10 failed (four alias cases, six enumeration rows).emailremoved: 10 failed.activityremoved: 10 failed.titleremoved: 5 failed (two alias cases, three enumeration rows).Local readings at head (cli unit layer, typecheck, gates)
pnpm --filter '@objectstack/cli^...' buildunder the verify lock:VERDICT command-exit 0.pnpm --filter @objectstack/cli exec vitest run --project unit --maxWorkers=2: Test Files 451 passed (451), Tests 6544 passed (6544),VERDICT command-exit 0. Theintegrationlayer is CI's.pnpm --filter @objectstack/cli typecheck:VERDICT command-exit 0(test layer OK undertsconfig.test.json).extract-hook-body, the new file,hook-body-parameter-rebind,hook-body-mail-grant,lower-callables,published-subpath-hook-body.pin): 259 passed. No existing expected capability list changed.bcd5926dbc),dispatch-gates --commands: 69 families; 68 exit 0;check:dual-build-cjs-loadsexit 3 PREREQUISITE NOT MET, NOT MEASURED there.2ed55579aa, docs page added),dispatch-gates --commands: 100 families, all exit 0 (nine first exited 3 on a fresh tree's missing builds and were re-run after building their closures,check:dual-build-cjs-loadsamong them). Docs families includecheck:doc-anchors,check:docs-section-name,check:doc-frontmatter,check:docs-single-h1,check:docs-spec-enumerations,check:docs-transcript-drift,check:doc-route-spelling --advisory,check:section-landing-index,spec check:docs.--ranreconciliation: 100 derived, 100 run, 0 NOT-MEASURED, 0 UNRUN.Acceptance notes
examples/app-crm,app-multi-package,app-showcase,app-starter,app-todo,packages/apps/connector-docusign,connector-github,connector-stripe, loaded, normalized and lowered): 134 body rows, inferred lists byte-identical. No first-party body uses an alias shape.async (c) => { const l = c.log; l.info('x') },const { log } = c, orconst c = ctx; const l = c.log) still infers nothing here, and the rule does not read it either. Reported to the seat as a finding, not fixed here.send(...)through anemailalias now carriesemail.send, so the hook's parse refuses it at build, exactly asctx.email.send(...)spelled directly already is. Before, it shipped and failed at the call.reboundCapabilitiesalready uses), so a string containing such a call next to a real alias over-infers; foremail.sendon a hook that is a build refusal, the same edge the direct pattern documents.Verification
Two-minute check:
pnpm --filter @objectstack/cli exec vitest run --maxWorkers=2 test/extract-hook-body-local-alias-38690.test.ts. Expect 1 file, 93 tests passed. Docs: the### Capability inferencetable on the hook-bodies page has five member rows (crypto.uuid,log,email.send,activity.append,title), each naming its alias shapes.Generated by Claude Code