Skip to content

feat(cli): the hook-body extractor infers api.transaction, and api.read through a bound object handle - #38686

Merged
objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/issue-38653-extractor-transaction-handle-read
Nov 30, 2026
Merged

objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/issue-38653-extractor-transaction-handle-read

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Steve · project thread
Fixes #38653
Clause-②: yes (widening)
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:应用作者把内联处理函数交给构建后,调用事务或通过对象句柄读数据的处理函数,构建时会自动获得对应权限,运行时不再被沙箱拒绝。
  • 为什么做:属于“处理函数能力推断准确”这一族工作,替所有用内联函数写钩子与动作的作者解决运行时莫名被拒的问题。
  • 出错会怎样:最坏是某个处理函数被多授予一个只开事务、不含读写的权限;改动只在构建期推断,撤回即可恢复原样。
  • 要你做什么:无。

What changes

os build lowers an inline hook handler / action target function to a js body and infers its capabilities (packages/cli/src/utils/extract-hook-body.ts). Two gated calls were never inferred, so a lowered handler making them was refused at the call by the sandbox:

  1. api.transaction — a new CAPABILITY_PATTERNS entry for a call of .transaction (?. allowed on either side) and for the member destructured off its receiver (const { transaction } = ctx.api, nested const { api: { transaction } } = ctx). Measured against the runner: installTxLeaf gates __txBegin / __txCommit / __txRollback behind api.transaction, and the VM sugar ctx.api.transaction closes over the context and reads no this, so every receiver that reaches ctx.api (the context itself, a root alias such as const api = ctx.api, a destructured api, or the destructured member called bare) hits the same gate. These are the shapes the hook-face refusal of ctx.transaction (the exemptCalls limb) already leaves standing as "the body's transaction route". Receiver-loose like the .object(...) patterns: api.transaction is no door and grants no data access, so an over-inferred grant opens nothing the body does not call.
  2. api.read through a bound handle — the bound-handle walk callsObjectWriteThroughHandle becomes callsObjectLeafThroughHandle(source, leaves), asked once for the write leaves (unchanged) and once for the read leaves (callsObjectReadThroughHandle, new). The read leaves are the direct api.read pattern's own (find|findOne|count|aggregate|get|list, now named once as OBJECT_READ_LEAVES); the runner's READ list (find, findOne, count, aggregate) adds none. The twin also covers the two other shapes the direct read regex missed: ?. before the leaf and an object argument holding a call.
  3. The published union — ExtractedBody.capabilities on @objectstack/cli/hook-body widens to seven tokens, 'api.transaction' added: exactly the HookBodyCapability set of @objectstack/spec. Contract face: this is a published type's accept set (a widening; nothing accepted before is refused), so the PR stays draft for its contract-review-tier review.
  4. Carrier note N4 — a CLI-side pin that lowerActionCallable still leaves a non-empty string target beside the minted body record (top-level and object-owned), the shape @objectstack/lint's isLoweredTargetBody keys on.
  5. Docs — the ### Capability inference table in content/docs/automation/hook-bodies.mdx gains two rows: *.transaction(…) (with the alias, ?. and destructured-member spellings the pattern reads) ⇒ api.transaction, and the read leaves on a bound handle ⇒ api.read. The sentences beside the table stay true as written.

Changeset: .changeset/38653-extractor-transaction-handle-read.md, @objectstack/cli patch, the level Metadata-protocol: none takes (a widened published type with no change to what a metadata author can write).

Read first (risk order)
  1. packages/cli/src/utils/extract-hook-body.ts — the api.transaction entry in CAPABILITY_PATTERNS (the receiver-loose regex and its destructure limb) and callsObjectLeafThroughHandle (the write walk is byte-identical apart from the leaves parameter).
  2. packages/cli/test/published-subpath-hook-body.pin.test.ts — the one line that widens the ratified union.
  3. packages/cli/test/extract-hook-body.test.ts — the new pins and their controls.

Tests

  • test/extract-hook-body.test.ts: the verify-delete-behaviors control hook's body verbatim infers ['api.read', 'api.write']; api.read through a bound handle, a handle off an alias of ctx.api, ?. before the leaf and an argument holding a call; a write-only bound handle stays ['api.write'] (control); api.transaction through ctx.api.transaction, a root alias, ?. on both sides, and the destructured member; a record field named transaction infers nothing (control).
  • test/lower-callables.test.ts: the N4 shape pin.
  • test/published-subpath-hook-body.pin.test.ts: the consumer compiled against the packed .d.ts asserts the seven-token union.
Ablations (one per new behaviour, each through `scripts/ablation-replace.mjs`, mutation proven on disk and restored to the HEAD blob)
  • Remove if (callsObjectReadThroughHandle(source)) inferred.add('api.read'); — 5 failed / 73 passed (the five api.read cases red, both controls green).
  • Turn the api.transaction entry's token into log — 4 failed / 74 passed (the four api.transaction cases red).
  • Delete action.target = ref; in lowerActionCallable — 2 failed / 31 passed (both N4 cases red).
  • Put the pin's union back to six tokens — 1 failed / 14 passed: conformance.ts(17,3): error TS2344: Type 'false' does not satisfy the constraint 'true'., so the pin reads the rebuilt, packed .d.ts.

Acceptance notes

  • Done-when 3: can validate-action-body-capabilities.ts now judge lowered bodies for the non-write tokens? Measured, no packages/lint change here. Population: every first-party config (examples/app-crm, app-multi-package, app-showcase, app-starter, app-todo, packages/apps/connector-docusign, connector-github, connector-stripe), each loaded, normalized and lowered, then read with the rule's own isLoweredHandlerBody / isLoweredTargetBody and bodyGatedCalls. packages/platform-objects and packages/apps/{account,setup,studio} carry no inline callable (their hooks are installed on the engine in-process). Result: 1 lowered hook body (crm_opportunity_stage_probability, no gated call), 0 lowered action bodies, 0 bodies newly refused with the lowered skips removed. The verify-delete-behaviors fixture (a test fixture, outside those trees) goes from one refusal (api.read) to none. So for api.read, api.write and api.transaction the extractor now reads every shape the rule reads. It does not yet for the member tokens: a body-local alias the rule reads (const l = ctx.log; l.info(…), const { log } = ctx, const { crypto } = ctx, const a = ctx.activity, a hook's const t = ctx.title; t(FIELD)) infers nothing, because the extractor's patterns for those members spell ctx. and its rebind covers only the handler's parameter. Dropping the skips now would refuse such a lowered body naming a grant the author never wrote. That is follow-up cli: the hook-body extractor infers nothing through a body-local alias of ctx.log, ctx.crypto, ctx.activity or ctx.title, so a lowered handler is refused at the call #38690: the extractor first reads those body-local aliases, then the rule drops its lowered skips.
  • The union could be typed as HookBodyCapability from @objectstack/spec (it is exactly the seven tokens), but this PR keeps it restated as ordered: typing it from spec would make the published .d.ts import spec types, and the conformance consumer in the pin, which installs only the packed CLI and typescript, would need @objectstack/spec linked too.
  • The destructured-leaf call transaction(fn) and a nested const { api: { transaction } } = ctx are inferred but not read by the lint rule (a missed finding there, never a false one).

Verification

Two-minute check: pnpm --filter @objectstack/cli exec vitest run --maxWorkers=2 test/extract-hook-body.test.ts test/lower-callables.test.ts test/published-subpath-hook-body.pin.test.ts. Expect 3 files and 126 tests passed.

Readings at head a6f711ac84 (the source is unchanged since 6c67329b6a; the later commits touch only the changeset, where ffbc961a01 moves its level to patch, and the docs page, c8373cd352):

Build, typecheck and tests (local)
  • pnpm --filter '@objectstack/cli^...' build then pnpm --filter @objectstack/cli build, under the verify lock: VERDICT command-exit 0.
  • pnpm --filter @objectstack/cli typecheck: VERDICT command-exit 0 (tsc --noEmit plus check:test-typecheck: OK).
  • The three touched files: Test Files 3 passed (3), Tests 126 passed (126).
  • The whole unit project, pnpm --filter @objectstack/cli exec vitest run --maxWorkers=2 --project unit: Test Files 450 passed (450), Tests 6451 passed (6451), VERDICT command-exit 0. The integration project is left to CI.
Derived gates (local subset)

node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack derived 69 families for the 5 changed paths; all 69 run, each exit code captured before any pipe. 68 exited 0. pnpm check:dual-build-cjs-loads exited 3 (PREREQUISITE NOT MET: it reads the dist of packages outside this build closure), so it is NOT MEASURED here and is CI's. Reconciliation: dispatch-gates --ran: 69 derived families accounted for, 68 run, 1 NOT-MEASURED (1 DERIVED from a recorded exit 3).

Docs gates for the page (local, at c8373cd)

Adding the page makes dispatch-gates --commands derive 31 more families (100 in all). All 31 ran at c8373cd352, each exit code captured before any pipe, and all 31 exited 0. pnpm --filter @objectstack/spec run check:skill-examples first exited 3 (PREREQUISITE NOT MET: no client-react dist); after the client-react closure was built it exited 0. Reconciliation over all 100: dispatch-gates --ran accounts for every family, 99 run and 1 NOT-MEASURED (check:dual-build-cjs-loads, exit 3 in the first round).


Generated by Claude Code

…d through a bound handle

Claude-Session: https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 30, 2026
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/cli, touching 12 documentable anchor(s).

7 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/automation/hook-bodies.mdx (via activity.append (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities), api.read (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities; a string literal in extractLoweredBody), api.transaction (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities), api.write (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities), crypto.uuid (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities), email.send (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities))
  • content/docs/automation/hooks.mdx (via api.read (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities; a string literal in extractLoweredBody), api.write (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities))
  • content/docs/automation/jobs.mdx (via api.read (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities; a string literal in extractLoweredBody), api.transaction (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities), api.write (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities))
  • content/docs/deployment/validating-metadata.mdx (via activity.append (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities), api.read (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities; a string literal in extractLoweredBody), api.transaction (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities), api.write (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities), crypto.uuid (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities), email.send (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities))
  • content/docs/kernel/runtime-services/email-service.mdx (via email.send (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities))
  • content/docs/protocol/kernel/plugin-spec.mdx (via email.send (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities))
  • content/docs/ui/actions.mdx (via api.write (literal, a string literal in CAPABILITY_PATTERNS; a string literal in capabilities))
What this run could not see
  • 1 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 69 of 252 client-bound route-ledger rows — the other 183 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 183: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 40 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 5ac1ee0bc8a79ab2238ded80123ba91623ad6081 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 18186bba910ad7f229a199f75ae718af692e6eb7 — the merge of head c8373cd352d15955a4ac0bcd60c28b90eddcc689 into base 5ac1ee0bc8a79ab2238ded80123ba91623ad6081, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 18186bba910ad7f229a199f75ae718af692e6eb7 && git checkout 18186bba910ad7f229a199f75ae718af692e6eb7
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 5ac1ee0bc8a79ab2238ded80123ba91623ad6081 c8373cd352d15955a4ac0bcd60c28b90eddcc689 && git checkout -B drift-repro 5ac1ee0bc8a79ab2238ded80123ba91623ad6081 && git merge --no-ff c8373cd352d15955a4ac0bcd60c28b90eddcc689

node scripts/docs-audit/affected-docs.mjs --json 5ac1ee0bc8a79ab2238ded80123ba91623ad6081

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 5ac1ee0bc8a79ab2238ded80123ba91623ad6081 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

…on and a read through a bound handle

Claude-Session: https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSwS4mQyXWrddL4r6B

Final green head · 2026-11-30T05:25Z · zone o3-B · c8373cd352 · check-runs: 44 success, 17 expected skips, 0 failed, 0 pending · mergeable_state clean · draft, Clause-②: yes (widening) and Metadata-protocol: none, +181 / -12 over 6 files against origin/main.
The dev's reports are 7268932786 (the build), 7268993636 (the changeset level) and 7269223662 (the docs rows).

  • What changes. The hook-body extractor infers api.transaction for a .transaction(…) call on ctx.api, on a root alias of it, with ?. on either side, or with the member destructured off it. It also infers api.read for the direct pattern's read leaves called through a bound object handle (callsObjectLeafThroughHandle, asked once for the write leaves and once for OBJECT_READ_LEAVES). The published @objectstack/cli/hook-body ExtractedBody.capabilities union widens to seven tokens, and the subpath pin follows. A CLI-side pin in lower-callables.test.ts holds the lowered-action shape that lint's isLoweredTargetBody keys on (carrier note 7267575290, N4 of feat(lint)!: refuse an action or hook body that calls a sandbox gate it was not granted #38650's contract record).
  • Tests. The three touched test files pass 126/126, the cli unit project 6451/6451, and cli typecheck is clean. Four ablations went red with controls green: (a) the handle-read call removed, 5 red; (b) the transaction token renamed, 4 red; (c) action.target = ref deleted, 2 red; (d) the pin union back to six tokens, 1 red plus TS2344.
  • Fix rounds since the first push:
    • ffbc961a01: the changeset level is now patch. The dispatch had ordered minor, and Metadata-protocol: none takes patch (ruling A, check-changeset-no-major). That was the PM's error.
    • c8373cd352: under claim amendment 1 (7269039655), two rows were added to the ### Capability inference table in content/docs/automation/hook-bodies.mdx. The docs drift check named that page.
    • The body is patched from the dev's drafts.
  • Done-when 3, measured. Across the first-party configs there is 1 lowered hook body and 0 lowered action bodies, and dropping lint's lowered skips newly refuses 0. The rule cannot drop them yet: the extractor still misses body-local aliases of ctx.log / ctx.crypto / ctx.activity / ctx.title. That is follow-up cli: the hook-body extractor infers nothing through a body-local alias of ctx.log, ctx.crypto, ctx.activity or ctx.title, so a lowered handler is refused at the call #38690, filed by the seat.
  • Gates. dispatch-gates --ran gives 100 families: 99 run with exit 0, and check:dual-build-cjs-loads is NOT MEASURED (exit 3, a dist outside the closure), which is CI's. overlap-check was clean before each push.
  • l1-face flags nothing. The owed sentence reads are the changeset and hook-bodies.mdx.
    Sent to L1-a for the first review. A contract-review-tier L2 is owed (a published type's accept set widens), and the seat does it. Fixes #38653.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmQm8PTU4AkVU5kdwEv
L1-a, the seat's L1 thread · 2026-11-30T05:35Z · first review

席位核对

ACCEPT @ c8373cd (card #38653, o3-B; 6 files, +181/−12)

What I checked

  • api.transaction inference. The new pattern \.\s*transaction\s*(?:\?\.\s*)?\( together with the destructure arm matches the route the sandbox gates. installTxLeaf (quickjs-runner.ts:784-792) refuses api.transaction with INSUFFICIENT_PRIVILEGES / 403 (:2255-2256), so the changeset's "refused at the call (403 INSUFFICIENT_PRIVILEGES)" is true. The token is a member of HookBodyCapability (hook-body.zod.ts:57-66), and that set has seven tokens, so "seven tokens" is true too. api.write stays a separate grant.
  • Read through a bound handle. callsObjectLeafThroughHandle is the old write walk with the leaf set passed in. The write path is byte-for-byte the same walk (callsObjectWriteThroughHandle = OBJECT_WRITE_LEAVES). The read twin uses OBJECT_READ_LEAVES, the same six leaves the direct api.read regex names.
  • Published type. ExtractedBody.capabilities gains 'api.transaction', and the packed-tarball pin (published-subpath-hook-body.pin.test.ts:286) moves in the same PR, as its header requires.
  • Changeset level. @objectstack/cli at patch with Clause-②: yes (widening) + Metadata-protocol: none is correct under ruling A (AGENTS.md:1035; check-changeset-no-major.mjs:3740 pins exactly this pair). The minor in the dispatch order was the slip.
  • Changeset and hook-bodies.mdx, read sentence by sentence. Every sentence matches the code. The two new table rows name exactly the shapes the probe below infers. "?. allowed on either side" holds for ctx.api?.transaction?.(…), and the nested destructure const { api: { transaction } } = ctx is read.
  • Done-when 3. The answer "not yet" with the measured population (0 bodies newly refused) and the follow-up cli: the hook-body extractor infers nothing through a body-local alias of ctx.log, ctx.crypto, ctx.activity or ctx.title, so a lowered handler is refused at the call #38690 is a fair reading of why validate-action-body-capabilities keeps its lowered skips. The open half is the member tokens' body-local aliases.

My runs (fresh worktree, cli dependencies built)

  • test/extract-hook-body.test.ts + test/lower-callables.test.ts: 111/111.
  • Ablations, each restored after the run:
    • (A) drop callsObjectReadThroughHandle → 5 red;
    • (B) drop the api.transaction pattern → 4 red;
    • (C) drop only the destructure arm → 1 red.
  • Probe of 10 shapes through extractLoweredBody(…, 'hook'):
    • direct, alias, ?./?.(, destructured and nested-destructured calls → ["api.transaction"];
    • return ctx.input.transaction → [];
    • a bound handle rows.find → ["api.read"];
    • r.findOne + r.update on one handle → ["api.read","api.write"].

Non-blocking

  • The destructure arm is receiver-loose. const { transaction } = ctx.input; return transaction; infers api.transaction, though the body never calls it (probed). The comment's "a read of a transaction FIELD … infers nothing" holds only for the member read ctx.input.transaction. By the file's own reasoning this is harmless: an over-granted token is one the sandbox never checks. A word in the comment ("a member read") would keep it exact.

Checks at this head (read before writing): 44 success, 17 skipped, 0 failure, 0 pending; mergeable clean.
Dogfood: not owed (not a narrowing). L2: the seat routes it (the published @objectstack/cli/hook-body type moves). The PR is a draft, and it lands after L2.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSwS4mQyXWrddL4r6B

Contract-review-claim: session_01ADHkmSwS4mQyXWrddL4r6B · head c8373cd · 2026-11-30T05:36Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSwS4mQyXWrddL4r6B

Contract review

Served-tier: TIER_DEFAULT
Head-sha: c8373cd352d15955a4ac0bcd60c28b90eddcc689
Local-runs: none
Scope: packages/cli/src/utils/extract-hook-body.ts, packages/cli/test/published-subpath-hook-body.pin.test.ts + packages/cli/test/extract-hook-body.test.ts, packages/cli/test/lower-callables.test.ts, .changeset/38653-extractor-transaction-handle-read.md
Security-touching: yes
Rule-change-verified: none

Face: the Clause-②: yes (widening) declaration alone. Zone o3-B writes this record at TIER_DEFAULT on the seat's word (seat thread, 2026-11-30T05:28Z). The diff touches no published schema under packages/spec/src, no governed path and no narrowing. I read the card #38653, claim 7268132415 and its amendment 7269039655, the three dev reports (7268932786, 7268993636, 7269223662), L1-a's ACCEPT 7269819170, the PR's net diff against origin/main (6 files, +181 / -12), and the 44 check-runs at this head (all success or expected skip, none pending).

① Derived judgments

  • api.transaction inference. A new CAPABILITY_PATTERNS row matches a .transaction call (?. allowed on either side) or the member destructured off a receiver. The sandbox gates exactly this route: installTxLeaf refuses without api.transaction, as L1-a read in quickjs-runner.ts. Before this PR, a lowered handler that called it was refused at every call. Now it is granted the token its source calls. Right.
  • Receiver-looseness. The row is receiver-loose, like the .object(…) rows above it. The destructure arm also infers the token for const { transaction } = ctx.input, which L1-a's probe showed. That is an over-grant of a token whose only effect is to unlock ctx.api.transaction. Writes inside it still need api.write, which is inferred separately. The over-grant opens no data access the body lacks, so it is accepted (see ③).
  • Read through a bound handle. callsObjectLeafThroughHandle is the old write walk with the leaf set as a parameter. The write call is byte-equivalent: OBJECT_WRITE_LEAVES is the same list, and the api.write path is unchanged. The read twin uses OBJECT_READ_LEAVES, the same six leaves the direct api.read row names. Right.
  • Public surface. ExtractedBody.capabilities on @objectstack/cli/hook-body gains 'api.transaction'. That is exactly the HookBodyCapability set of @objectstack/spec, seven tokens. The packed-subpath pin moves in the same PR, and ablation (d) shows it turning red with TS2344 when the union is put back. Nothing else is exported, and RATIFIED_SURFACE is unchanged. The only other importer on main is packages/cli/src/hook-body.ts, the re-export.
  • The N4 carrier pin in lower-callables.test.ts holds that lowerActionCallable leaves a string target beside the body. Ablation (c) shows it red when that line is deleted. Right.

② Semver level

  • @objectstack/cli takes patch, with Clause-②: yes (widening) and Metadata-protocol: none on the changeset and the PR body. Under ruling A the level follows the metadata-protocol line alone, so none takes patch, and Check Changeset is green at this head. The first push graded it minor on the PM's dispatch error; ffbc961a01 corrected it. There is no ! and no BREAKING banner: nothing previously accepted is refused. The changeset names the one consumer-visible effect, which is that an exhaustive switch over the union gains a case. Right.
  • Clause-②: one arm, a widening. Right.

③ Boundary flags

Implemented-by: claude/issue-38653-extractor-transaction-handle-read
Reviewed-by: session_01ADHkmSwS4mQyXWrddL4r6B

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSwS4mQyXWrddL4r6B

Landing · 2026-11-30T05:39Z · zone o3-B · head c8373cd352d15955a4ac0bcd60c28b90eddcc689 · ACCEPT → PR #38686 comment 7269819170 (L1-a) · Contract review → comment 7269859014 (TIER_DEFAULT, declaration face, PASS)

Reading Value
check-runs at head (pr-state) 44 success · 17 expected skip · 0 unexpected skip · 0 failed · 0 pending; mergeable_state clean
check-governed-merges --pr 38686 · K NOT governed, 193 changed lines (+181 / -12) · landing-k OK, K = 0 < 15, no shared book moved
check-owed-reviews DONE #38686 · face declaration · record current PASS (7269859014)

State: ready for review and auto-merge in this stroke. #38653 closes on merge (Fixes). The out-of-scope family is #38690, which the seat filed. L1-a's one nit (the destructure arm's comment wording) is accepted in the record with no push.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 30, 2026 05:40
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit 5a77a70 Nov 30, 2026
62 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-38653-extractor-transaction-handle-read branch November 30, 2026 06:07
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

2 participants