Skip to content

feat(lint)!: refuse an action or hook body that calls a sandbox gate it was not granted - #38650

Merged
os-zhuang merged 13 commits into
mainfrom
claude/issue-37815-body-capabilities-ab
Nov 30, 2026
Merged

os-zhuang merged 13 commits into
mainfrom
claude/issue-37815-body-capabilities-ab

Conversation

@objectstack-fleet

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

Copy link
Copy Markdown
Contributor

Requested by Steve · project thread
Refs #37815 (items a, b)
Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: follow-up #38655

维护者速读

  • 用户能看到什么变化:应用作者保存或校验一个脚本动作或自己写的钩子脚本时,如果代码调用了沙箱需要授权的功能(写数据、事务、日志、发邮件、写活动记录等)却没有声明对应权限,现在会在保存和本地校验时直接被拒并说明要加哪个权限;以前能保存,但每次运行都报错。
  • 为什么做:属于脚本动作与钩子的权限检查跟进工作,把只覆盖动作写数据的检查扩展到钩子和沙箱的全部授权项。
  • 出错会怎样:误判会让一个本来能运行的动作或钩子保存不了;用函数写、由构建转换出来的钩子和动作这次不做新增检查;已存的元数据不受影响,可以直接撤回;现有示例应用实测无一被拒。
  • 要你做什么:无。

What changes

The QuickJS sandbox gates seven tokens, and before this PR lint judged one of them on one kind of body (ctx.api writes on action bodies, action-body-write-capability-undeclared). A hook body, and an action body calling any other gate, saved and published clean and then threw 403 INSUFFICIENT_PRIVILEGES at every call.

  • Runner census (measured first, read-only). Every capability gate in packages/runtime/src/sandbox/quickjs-runner.ts at 0ba5e06ae7: api.read on the READ leaves find / findOne / count / aggregate (installApiMethod, line 755) and on ctx.title(FIELD) with an argument (line 1035, hook bodies only: the action face builds no ctx.title); api.write on the WRITE leaves (line 756); api.transaction on ctx.api.transaction (installTxLeaf, line 783); log on ctx.log.debug|info|warn|error (line 881); crypto.uuid on ctx.crypto.randomUUID (line 907); email.send on ctx.email.send and activity.append on ctx.activity.append (installDoor, lines 941 to 994). That set is exactly HookBodyCapability in the spec. The rule judges exactly that set, as SANDBOX_CAPABILITY_GATES.
  • Arm (a), authored hook bodies. validateActionBodyCapabilities now walks stack.hooks too, with the same reading (blanked source; the member itself, a local bound once to it, or a handle bound once to .object(…)). New id hook-body-capability-undeclared, one finding per body and token, at hooks[i].body.capabilities. A hook body is never granted email.send (the hook's parse refuses the grant), so its ctx.email.send call is refused with the remedy that works: remove the call and send the mail from an action, a job or a flow. Scope (route C): authored hook bodies only. A hook body that os build / os verify lowered from an inline handler is not judged (isLoweredHandlerBody): under the CLI exactly when ctx.loweredHookRefs holds the hook's string handler, and at a door that hands no lowered refs (the runtime publish doors) whenever a string handler sits beside the body, the shape a build artifact carries. Its grant is the build's inference, and the extractor does not yet infer api.transaction or a read through a bound handle, so a finding there would name a grant the handler author cannot write. cli: the hook-body extractor infers no api.transaction and no api.read through a bound object handle, so a lowered handler's inferred capabilities miss calls it makes #38653 carries the lowered-handler reading and both extractor gaps. The registry entry keeps its name and gains hook in runtimeTypes (the validateHookAndJobBodyCompiles precedent: one entry, ids per kind), and now receives ctx.
  • Arm (b), the other tokens, authored action bodies. On action bodies, every gate other than the writes is judged under the new id action-body-capability-undeclared. A missing api.write keeps its own id and its exact words, so nothing that matches on it today changes. Scope (contract review M1, claim amendment 3): authored action bodies only, past the writes. An action body that os build / os verify lowered from an inline target function is judged for api.write only, as before (isLoweredTargetBody). Measured before the edit: the CLI hands no lowered-action ref set (LoweringResult carries loweredHookRefs only), and lowerActionCallable leaves a string target (the registered ref) beside the minted body. So on every door, the CLI included, a body is read as lowered when a string target sits beside it. No packages/cli edit was needed. A JS body runs only on a script action, where target is kept for legacy functions references alone; an authored body beside a string target is therefore not judged for the other tokens either, a missed finding, never a false one. In examples/app-showcase, none of the 296 JS-body actions (318 actions in all) carries a string target. cli: the hook-body extractor infers no api.transaction and no api.read through a bound object handle, so a lowered handler's inferred capabilities miss calls it makes #38653 carries the lowered reading.
  • Pin. The new test file reads the runner's source: the token set from caps.has('…'), the installApiMethod tokens and the installDoor calls must equal the census; the caps.has(NAME) calls with a variable must be exactly the two known ones, so a third parametrised gate turns it red; the READ list, the log levels and the door triples are pinned; and the census token set must equal HookBodyCapability.options.
  • L1-a's nit from fix(lint): the record-write-discarded hint prescribes a write the sandbox installs; app-dependencies lists the closure-judged bindings #38628. The action-body-write-unknown-field explanation now lists the installed field-carrying leaves: insert, update({ id, … }), updateById(id, { … }), upsert, updateMany. updateById landed with fix(runtime,cli,lint,spec)!: a sandboxed body's ctx.api.object(X).updateById(id, patch) writes the row #38643, which this branch merged from main; the census and the gate table read the runner's WRITE list and needed no edit.
  • os explain entries for both new ids, and two rows in content/docs/deployment/validating-metadata.mdx.
  • Upgrade guide and barrel. packages/lint/src/index.ts exports both new id constants. A new upgrade-guide entry, packages/spec/src/migrations/entries/semantic/19.hook-and-action-bodies-calling-an-ungranted-gate-refused.ts, follows the hook-job-body-does-not-compile-refused precedent and says the hook arm covers authored bodies only; the changeset marker is registered with that id, and the changeset carries an @objectstack/spec patch line. The os build extractor (packages/cli) is unchanged: byte-identical to main.

The rule file's header names hook as the third runtime door (review N2), and the upgrade-guide entry's acceptanceCriteria names the inline path objects[N].actions[M].body.capabilities (N2). S1 (updateById in the action-body-write-unknown-field leaf list) was met at a60a6de915.

This touches a contract face: the lint rule family's accept set at the save door and in os validate (a narrowing).

Tests

  • New file packages/lint/src/validate-action-body-capabilities.hook-and-tokens-37815.test.ts: per arm a refused case, a granted control that passes, and an ungated call that stays quiet; the hook case through the save door (runRuntimeAuthoringRules on type: 'hook') and through runAuthoringRules for validate / build / lint; the hook email.send remedy; ctx.title(FIELD) against ctx.title(); a shape table for bodyGatedCalls; the runner pin.
  • M1 pins, both sides, on one source (a write inside ctx.api.transaction, granted api.write only, as the extractor infers): the authored action body is refused; the same body beside a string target is not judged, through validateActionBodyCapabilities, through runAuthoringRules for validate / build / lint at the top level and inline on an object, and at the action and object doors (each with an authored positive control); a lowered body without api.write is still refused under the write id.
  • Route C pins, both sides, on one source (a read through a bound handle): the authored body is refused; the same body lowered from a handler is not judged, through validateActionBodyCapabilities, through runAuthoringRules for validate / build / lint with loweredHookRefs, and at the save door with a string handler beside the body; a string handler the build did not lower leaves the authored body judged.
  • One ablation per behaviour with scripts/ablation-replace.mjs, each restored to a clean tree.
Readings at 4c07e0d, 29d3b0f, a60a6de and c3319db
  • At 29d3b0f: pnpm --filter @objectstack/lint typecheck && pnpm --filter @objectstack/lint test: typecheck clean, check:test-typecheck OK; Test Files 248 passed, Tests 10035 passed. The new test file: 46 passed. Ablation of the M1 exemption (if (lowered) continue; deleted): Tests 3 failed / 43 passed, exactly the three lowered-target pins; restored, blob equal to HEAD. check-adr-0087-registration --base origin/main, check-changeset-no-major, check:spec-changes, check:upgrade-guide and check-nul-bytes exit 0; overlap-check clean.
  • Full dogfood battery on 29d3b0f (pnpm --filter @objectstack/dogfood test under the lock, after building the dogfood closure): Test Files 495 passed / 3 skipped (498), Tests 4187 passed / 68 skipped (4255), VERDICT command-exit 0. The head after it, 4c07e0d, changes only one sentence of the upgrade-guide entry's guidance text.
  • At 4c07e0d, after a cli build: pnpm --filter @objectstack/cli exec vitest run --maxWorkers=2 test/migrate-meta-engine-guidance.test.ts test/explain-rule-id.test.ts test/verify-delete-behaviors.test.ts: Test Files 3 passed, Tests 20 passed. The entry's printed guidance names no tracker, so the Test Core (2/12) red at 29d3b0f is fixed. check-adr-0087-registration, check-changeset-no-major, check:spec-changes, check:upgrade-guide, check:generated and check-nul-bytes exit 0; overlap-check clean.
  • At a60a6de (after merging main with fix(runtime,cli,lint,spec)!: a sandboxed body's ctx.api.object(X).updateById(id, patch) writes the row #38643): pnpm --filter @objectstack/lint typecheck && pnpm --filter @objectstack/lint test: typecheck clean, check:test-typecheck OK; Test Files 248 passed, Tests 10031 passed. The new test file, census pin included: 42 passed. check-adr-0087-registration --base origin/main exit 0; check-changeset-no-major exit 0.
  • At c3319db: lint suite Test Files 248 passed, Tests 10019 passed.
  • pnpm --filter @objectstack/cli exec vitest run --maxWorkers=2 test/verify-delete-behaviors.test.ts test/published-subpath-hook-body.pin.test.ts test/explain-rule-id.test.ts test/extract-hook-body.test.ts test/lint-hook-rules-reach-handler-hooks.test.ts (after a cli build): Test Files 5 passed, Tests 109 passed.
  • Ablation of the narrowing (the isLoweredHandlerBody early return deleted): Tests 2 failed / 40 passed, exactly the two not-judged pins; restored, blob equal to HEAD.
  • Round 1 ablations: the hook walk removed, 8 failed / 31 passed; the api.transaction gate entry removed, 8 failed / 31 passed; both restored.
  • After the build: check-adr-0087-registration exit 0 (1 migration entry added); check:spec-changes exit 0; check:upgrade-guide exit 0; check:generated all 14 artifacts current; check-nul-bytes OK. The upgrade guide was regenerated with gen:upgrade-guide only.
  • node scripts/pm/dispatch-gates.mjs --commands: 118 families derived; 116 exit 0, 2 NOT MEASURED (exit 3, PREREQUISITE NOT MET: check:skill-examples, check:dual-build-cjs-loads); --ran reconciliation: 118 accounted for. CI on c3319db: 72 check-runs, 62 success and 10 skipped, among them Lint & Repo Gates, Test Core, Check Changeset and Dogfood Regression Gate green.
  • Full dogfood battery on c3319db (pnpm --filter @objectstack/dogfood test under the lock, after building the dogfood closure): Test Files 495 passed / 3 skipped (498), Tests 4187 passed / 68 skipped (4255), VERDICT command-exit 0.
  • First-party measurement of example apps before any edit: 0 findings. A sweep of 50 handlers under packages/*/test/** and examples/** found one body refused under the lowered-handler reading (packages/cli/test/verify-delete-behaviors.test.ts); under route C it is not judged, and that test is green.

Acceptance notes

Verification

Read first: packages/lint/src/validate-action-body-capabilities.ts (SANDBOX_CAPABILITY_GATES, bodyGatedCalls, the hook walk), then isLoweredTargetBody and the action loop's lowered skip, then the new test file's runner-pin block, its M1 pins and its route C pins, then the authoring-rules.ts entry (runtimeTypes gains hook, run receives ctx).

Two-minute check: pnpm --filter @objectstack/lint exec vitest run src/validate-action-body-capabilities.hook-and-tokens-37815.test.ts shows 46 passed.


Generated by Claude Code

@github-actions github-actions Bot added size/l 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 29, 2026
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 2 package(s): @objectstack/lint, @objectstack/spec, touching 42 documentable anchor(s). ⚠️ 1 changed file(s) yielded no anchor (packages/lint/src/index.ts), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

26 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json d042837c104dcfef351fb7dc6952e83e90da1d00.

⛔ 7 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 1 changed file(s) yielded no anchor (packages/lint/src/index.ts) — pages documenting those are invisible to this run
  • 12 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 — 182 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 d042837c104dcfef351fb7dc6952e83e90da1d00 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from babfb592b3007985bbc43d535661f87e734eba50 — the merge of head 4c07e0d7084b91115d7af589082c509787b8cbc4 into base d042837c104dcfef351fb7dc6952e83e90da1d00, 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 babfb592b3007985bbc43d535661f87e734eba50 && git checkout babfb592b3007985bbc43d535661f87e734eba50
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin d042837c104dcfef351fb7dc6952e83e90da1d00 4c07e0d7084b91115d7af589082c509787b8cbc4 && git checkout -B drift-repro d042837c104dcfef351fb7dc6952e83e90da1d00 && git merge --no-ff 4c07e0d7084b91115d7af589082c509787b8cbc4

node scripts/docs-audit/affected-docs.mjs --json d042837c104dcfef351fb7dc6952e83e90da1d00

⚠️ 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 d042837c104dcfef351fb7dc6952e83e90da1d00 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSwS4mQyXWrddL4r6B

Known red · 2026-11-29T23:02Z · zone o3-B · head bac75a914f1a14ecca591bf443746b04b3754482. Test Core (9/12) fails on exactly the three barrel tests named in the dev's report: rule-id-barrel-exports.test.ts and two cases in rule-explanations.test.ts. The two new rule-id constants are not yet exported from packages/lint/src/index.ts. That file was outside the claim's surface. Claim amendment 7264010349 on #37815 adds it, together with the new semantic entry and the extractor api.transaction pattern, and the dev's patch round is running. This PR stays draft.

…ctor stays as on main

Route C (claim amendment 2): a hook body lowered from an inline handler by
os build / os verify is no longer judged by hook-body-capability-undeclared,
since its grant is the build's inference; the lowered reading waits on the
extractor. extract-hook-body.ts and its test are back to origin/main, and the
cli changeset line is dropped. The upgrade-guide entry, the changeset rows,
the explanation and the docs row say authored hook bodies only.

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-30T01:18Z · zone o3-B · c3319db255 · check-runs: 64 success, 12 expected skips, 0 failed, 0 pending · mergeable_state clean · not governed, +693 / -41 over 8 files.
Route C is per claim amendment 2 (7264779546). The dev's report is 7265907932.

  • Arm (a): hook-body-capability-undeclared judges authored hook bodies only. isLoweredHandlerBody skips a body that was lowered from a handler: in the CLI, one in loweredHookRefs; at the doors, a string handler beside the body. cli: the hook-body extractor infers no api.transaction and no api.read through a bound object handle, so a lowered handler's inferred capabilities miss calls it makes #38653 carries the lowered reading and the two extractor gaps.
  • Arm (b): action-body-capability-undeclared judges every other runner gate. action-body-write-capability-undeclared keeps its id and words.
  • SANDBOX_CAPABILITY_GATES is pinned to the runner census and to HookBodyCapability.options. packages/cli is byte-identical to main.
  • A new v19 entry hook-and-action-bodies-calling-an-ungranted-gate-refused is registered; the ADR-0087 gate exits 0.
    l1-face flags dogfood, which is met: the full battery ran on this head (495 files passed, 3 skipped; 4187 tests passed, 68 skipped). skills-docs reads follow-up #38655. The PR body was rewritten from the dev's draft (zone issue_patch, read back identical).
    Owed reads, sentence by sentence: .changeset/37815-body-capabilities-every-gate.md and content/docs/deployment/validating-metadata.mdx.
    Sent to L1-a. The narrowing owes one CONTRACT_REVIEW_TIER review, which the seat routes. The PR stays draft, Refs #37815 (items a, b). One leftover: the backup branch claude/issue-37815-body-capabilities-ab-wip (dd33652) was not deleted, because the relay has no branch delete; the seat hands it on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

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

席位核对

ACCEPT @ c3319db255fed5f856fd4eb12c759b70ae10501f (card #37815 a/b, route C per claim amendment 2 7264779546, zone o3-B). This is a narrowing and owes L2 at CONTRACT_REVIEW_TIER. The seat routes it and lands at Tier H.

Read at head:

  • The gate list. SANDBOX_CAPABILITY_GATES is one table, token by token, matching the runner's own checks (quickjs-runner.ts: api.transaction at :783, log at :881, crypto.uuid at :907, and the email.send / activity.append doors at :923).
    • ctx.title(FIELD) behind api.read applies to hooks only. calledWithArgument makes the bare ctx.title() free.
    • The new test file's census reads runtime/src/sandbox/quickjs-runner.ts itself and turns red on a gate it cannot read.
  • The action arm. bodyGatedCalls(source, 'action') gives one finding per ungranted token.
    • api.write keeps action-body-write-capability-undeclared with its message and hint byte for byte as at base.
    • Every other token reports action-body-capability-undeclared.
  • The hook arm. Over stack.hooks, an L2 js body with a non-blank source is judged, except a body isLoweredHandlerBody marks:
    • in the CLI, a hook whose string handler is in ctx.loweredHookRefs. compile.ts, lint.ts, validate.ts and item-lint.ts already hand it over, so packages/cli does not change;
    • at the gate, any string handler beside the body.
    • email.send on a hook gets its own message and remedy. That matches the runtime, which never grants it to a hook body (body-doors.ts:362, body-runner.ts:526).
  • Doors. The entry's runtimeTypes gains hook (['action', 'object', 'hook']), and run now passes ctx through.
  • My own runs, in a clean worktree at this head, after building the @objectstack/lint^... closure: validate-action-body-capabilities*, 2 passed, 71 passed (71).
  • My ablation. I removed the isLoweredHandlerBody skip. That gives 2 failed | 69 passed: "the same body lowered by os build / os validate / os verify is not judged" and "the save door, which hands no lowered refs, does not judge a build artifact's lowered body". Restored, tree clean.
  • Declarations. The title has !. Clause-②: no (narrowing) and Metadata-protocol: narrowed are declared, with a BREAKING banner and FROM → TO. lint is minor. spec is patch, for an upgrade-guide entry only, which matches the repo's precedent.
  • Changeset, read sentence by sentence. It is true against the code:
  • validating-metadata.mdx, read sentence by sentence. It adds two rows. The action row (✓ᵃᶜᵒ) lists exactly the non-write gates. The hook row (✓ʰ) lists the hook gates, the lowered-body exclusion and email.send. Both are true.
  • Dogfood. The full battery is recorded at this head (7265907932): c3319db255, under the verify lock, 495 passed | 3 skipped, 4187 passed | 68 skipped, no failures.
  • Mechanical face. The only flag is dogfood, covered above. Checks at this head: 64 success, 12 expected skip, 0 failed. mergeable_state is clean.

For the seat (landing order): #38643 adds updateById to runtime WRITE and to SANDBOX_API_WRITE_METHODS in this same file. This PR's census pin and its gate table read both lists. Whichever lands second needs a rebase on the other and a re-run of this file's census test. I expect a textual merge only.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSAjFEZHRpRq3WCj6z

Contract-review-claim: session_01ADHkmSAjFEZHRpRq3WCj6z · head c3319db · 2026-11-30T01:24Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSAjFEZHRpRq3WCj6z

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: c3319db255fed5f856fd4eb12c759b70ae10501f
Local-runs: none
Scope: packages/spec/src/migrations/entries/semantic/19.hook-and-action-bodies-calling-an-ungranted-gate-refused.ts + packages/lint/src/validate-action-body-capabilities.ts, packages/lint/src/authoring-rules.ts, packages/lint/src/index.ts, packages/lint/src/rule-explanations.ts, packages/lint/src/validate-action-body-capabilities.hook-and-tokens-37815.test.ts

PR #38650, card #37815 (Refs, items a and b), narrowing face plus published schema. Read: the card body and all 12 comments (claim 7263206599, amendment 7264010349, amendment 2 7264779546 with route C, the three dev reports), the PR body, the net diff against merge base f5da514b07bc, and the 76 check-runs on the head (64 success, 12 skipped, none failed, none pending; Check Changeset, Lint & Repo Gates, Test Core 12/12, Dogfood Regression Gate, Spec property liveness, Governed Surface Queue Guard green). Code read outside the diff, never reviewed: packages/runtime/src/sandbox/quickjs-runner.ts, packages/runtime/src/sandbox/body-runner.ts, packages/spec/src/data/hook-body.zod.ts, packages/spec/src/data/hook.zod.ts, packages/cli/src/utils/lower-callables.ts, packages/cli/src/utils/extract-hook-body.ts, packages/lint/src/validate-action-body-writes.ts, packages/lint/src/runtime-gate.ts. Prose faces (.changeset/37815-body-capabilities-every-gate.md, content/docs/deployment/validating-metadata.mdx) are read for ② only.

① Derived judgments

  • An authored L2 hook body calling a gated member without its token is refused as hook-body-capability-undeclared in os validate / build / lint and at the runtime hook door (runtimeTypes gains hook, run now passes ctx). Right. The gate table SANDBOX_CAPABILITY_GATES matches the runner token by token: api.read on READ (runner 755) and on ctx.title(FIELD) (1035, built for hook bodies only, body-runner.ts 552 to 557 against 682 to 691), api.write on WRITE (756), api.transaction (783), log on four levels (879 to 881), crypto.uuid (907), the two doors (945, 993 to 994). caps is new Set(args.capabilities) (303) with no implicit grant, and HookBodySchema.capabilities defaults to [], so reading an absent list as empty is right.
  • A hook body's ctx.email.send is refused with a remove-the-call remedy and no grant offered. Right: HookSchema refuses the grant at parse and hookBodyRunnerFactory refuses to bind a body that carries it (body-runner.ts 523), so no hook body ever holds the token.
  • A hook body lowered from an inline handler is not judged: under the CLI when loweredHookRefs holds the ref, at the doors whenever a string handler sits beside the body. Right as a missed finding, and disclosed (a hand-written hook with both keys is not judged at the doors; a body wins over a handler at bind, so that body does run). lowerCallables adds a ref to the set exactly when it minted the body, and every CLI caller of runAuthoringRules hands the set over (compile, validate, lint, item-lint, author-time-rules, scaffold-validate, the per-package pass).
  • An action body calling a gate other than the writes is refused as action-body-capability-undeclared on the CLI and at the action and object doors. Right for a body the author wrote. WRONG for a body the build lowered from an inline target function: see M1.
  • action-body-write-capability-undeclared keeps its id, message and hint. Right: the new code strips the ctx.api.object(…). prefix from each call and rebuilds the same sentence the base built from LEAF(…); byte-identical.
  • Public surface: @objectstack/lint barrel gains ACTION_BODY_CAPABILITY_UNDECLARED and HOOK_BODY_CAPABILITY_UNDECLARED; two os explain entries; one new upgrade-guide entry id. The rule function, the gate table and isLoweredHandlerBody are module exports only, not on the barrel. Right. packages/cli is not in the diff, so the published @objectstack/cli/hook-body type is untouched.
  • Job bodies run in the same sandbox behind api.*, log and crypto.uuid and are not judged. Outside items a and b; named in ④ as N3.

② Semver level

  • @objectstack/lint minor with a ! title and a BREAKING banner, @objectstack/spec patch for the entry alone. Matches the precedent on this 19.0.0-next line: .changeset/pre/34987-hook-job-body-does-not-compile.md (lint minor for a ! narrowing) and .changeset/pre/35143-seeds-actions-checks.md (spec patch for an entry-only change). Check Changeset is green on the head.
  • Clause-②: no (narrowing) on the PR body and on the changeset, with Metadata-protocol: narrowed. Right, and one arm only: nothing in the diff widens a published type. The ADR-0087 marker registered hook-and-action-bodies-calling-an-ungranted-gate-refused equals the entry's id.
  • The changeset's account of what breaks is incomplete by the amount of M1: it tells the author of a hook written as a handler that nothing changes, and says nothing to the author of an action written as a target function, whose build can now fail.

③ Boundary flags

④ Design judgment

M1 (must-fix) — the action arm judges bodies the build lowered from an inline target, with a remedy that author cannot write. lowerActionCallable (packages/cli/src/utils/lower-callables.ts 554 to 580) turns an action's target function into body: { language: 'js', source, capabilities } with the extractor's inferred grants, and collectActionBodies reads that body like any other. validateActionBodyCapabilities has no lowered exemption on the action walk. The extractor on main and on this head infers no api.transaction at all (CAPABILITY_PATTERNS, whose cap union does not even hold the token), reads api.read only on a direct .object(…).LEAF chain (not through a bound handle, ?. before the leaf, or an argument holding parentheses), and reads log, crypto.uuid, email.send and activity.append only on the literal ctx.MEMBER.LEAF spelling, while this rule also reads const { log } = ctx, const log = ctx.log, ctx?.log and ctx.log?.info. ctx.api.transaction is not a forbidden pattern, so such a target lowers (pinned for the shared extractor in packages/cli/test/hook-body-parameter-rebind.test.ts 330 to 338). So an app whose action is written as a function calling ctx.api.transaction(…) built clean before this PR and now fails os build / os validate / os lint with action-body-capability-undeclared at actions[N].body.capabilities, hint "Add 'api.transaction' to the action's body.capabilities", a key that author never wrote. This is the refusal the card ruled out twice: amendment 7264010349 calls it "a wrong refusal caused by this PR" for the hook face, and amendment 2 states "A handler lowered by os build / os verify is not judged by this PR". #37807 treated the same shape as a defect for writes and fixed it in the extractor (packages/cli/test/extract-hook-body.test.ts 75 to 77: "so os build lowered a handler and then refused it"). Three sentences in the diff are false while it stands: the rule file's header, lines 20 to 26 ("a handler the build lowers is not refused by the next step of the same build"), which the new title now extends to every gate; the hits entry's reason ("a hook written as a handler is unchanged", silent on an action written as a target) and replacement ("Add the token the finding names to the body's capabilities"); and the changeset's closing FROM and TO line. Read from the code, not run. Fix inside this PR's one narrowing arm: do not judge an action body the build lowered, for the tokens other than api.write (the hook arm's isLoweredHandlerBody reading, on a string target beside the body or a lowered-action ref set), say so in the entry, the header, the explanation and the changeset, pin both sides as the route C pins do for hooks, and leave the lowered reading to #38653.

S1 (should-fix) — packages/lint/src/rule-explanations.ts, ACTION_BODY_WRITE_UNKNOWN_FIELD_EXPLANATION: the new sentence lists insert, .update({ id, … }), .upsert(…) and .updateMany(…) as "the leaves the sandbox installs that carry fields". Against current main that is short by one: updateById(id, data) is installed behind api.write and carries fields. The PR body left the leaf to #38643, and #38643's merged diff does not touch this line, so on the merged tree os explain action-body-write-unknown-field states a closed list that omits a leaf the sandbox has. Add it on the rebase M1 needs.

Nits, no effect on the verdict:

  • N1: calledWithArgument reads any first argument as the related-record form, so ctx.title(undefined) and ctx.title(null) on a hook body are refused for api.read, while the runner gates only a field that is neither (quickjs-runner.ts 1034 to 1035). A literal nobody writes; accepted deviation or one line in the header.
  • N2: the rule file's header still says the rule gates "the runtime action and object publish doors" (line 30) though hook is now a third; and the entry's acceptanceCriteria names actions[N].body.capabilities only, while an inline action's finding sits at objects[N].actions[M].body.capabilities (the surface does name inline actions).
  • N3: a job body runs in the same sandbox behind the same tokens and is not judged. Outside items a and b of the card; a follow-up card if wanted.

Held, after trying to break it: the census pin fails on a new literal token, a new installApiMethod token, a new door and a third parametrised caps.has, and equals HookBodyCapability.options; the masking and bound-once reading are the base rule's, generalised by member with no new receiver shape (ctx.record.title, ctx.input.email, const { email } = ctx.record and a reassigned alias are not read); ctx.title is not judged on an action body, where the host builds no seam; the hook email message is true of the runtime; the entry's door list, 422 INVALID_METADATA and gate list agree with the gate and the runner.

Implemented-by: claude/issue-37815-body-capabilities-ab
Reviewed-by: session_01ADHkmSAjFEZHRpRq3WCj6z

VERDICT: FAIL

@objectstack-fleet objectstack-fleet Bot added the needs:contract-review Marker only — PR awaits its at-tier Contract review PASS; no check reads it, the record decides label Nov 30, 2026
…or api.write only

Contract review M1: action-body-capability-undeclared no longer judges an
action body os build / os verify lowered from an inline target function
(isLoweredTargetBody: a string target beside the body, the shape lowering
leaves), since its grant is the build's inference; its writes stay judged
under action-body-write-capability-undeclared. The rule header (the third
door, N2), the explanation, the upgrade-guide entry (the inline path, N2),
the changeset and the docs row say so; the lowered reading stays with the
extractor card.

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 (rework) · 2026-11-30T02:57Z · zone o3-B · 4c07e0d708 · check-runs: 64 success, 12 expected skips, 0 failed, 0 pending · mergeable_state clean · draft, a narrowing (!, Clause-②: no (narrowing)), +790 / -46 over 8 files against origin/main.
Since L1-a's ACCEPT 7266096396 at c3319db255 there are three commits, all fast-forward:

  • a60a6de915: a merge of origin/main with no conflict. The field-carrying leaves the action explanation lists now include updateById, so the seat's S1 is met.
  • 29d3b0fea1: M1 of the seat's contract review 7266230571, routed by claim amendment 3 (7266251484 on lint: action-body capability family follow-ups after #37807 (hook bodies, other capability tokens, updateById advice, ADR-0141 D1 binding list) #37815). The new exported isLoweredTargetBody(action) means a string target beside a body. Such a body is skipped for the non-write tokens, while action-body-write-capability-undeclared still judges its writes. The rule header, explanation, v19 entry, changeset and docs row are re-worded to match. The missed finding is disclosed: a body authored beside a target function is lowered and then not judged for the other tokens (the lowered reading is cli: the hook-body extractor infers no api.transaction and no api.read through a bound object handle, so a lowered handler's inferred capabilities miss calls it makes #38653).
  • 4c07e0d708: the v19 entry's printed replacement no longer cites a tracker id. That fixes the red Test Core (2/12) migrate-meta-engine-guidance.test.ts:420 at 29d3b0fea1.
    The dev's report is 7267018841:
  • The card test file passes 46/46 at 29d3b0fea1.
  • The ablation (delete if (lowered) continue;) turns exactly the 3 lowered-target pins red. After restore, git diff HEAD is empty.
  • @objectstack/lint passes 10035 tests, and the 3 cli guidance tests pass at 4c07e0d708.
  • The ADR-0087 gate, no-major, check:spec-changes, check:upgrade-guide, check:generated and the NUL-byte check all exit 0 at 4c07e0d708.
    l1-face flags dogfood. The full battery ran at 29d3b0fea1 and passed: 495 files passed and 3 skipped, 4187 tests passed and 68 skipped. 4c07e0d708 differs only by one sentence of the v19 entry's replacement text, and the battery was not re-run on it. The owed sentence reads are the changeset and content/docs/deployment/validating-metadata.mdx.
    Sent to L1-a for a delta. The seat's contract-review delta follows. Refs #37815 (items a, b), so the card stays open on merge.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSAjFEZHRpRq3WCj6z

Contract-review-claim: session_01ADHkmSAjFEZHRpRq3WCj6z · head 4c07e0d · 2026-11-30T02:58Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmQm8PTU4AkVU5kdwEv
L1-a, the seat's L1 thread · 2026-11-30T03:01Z · delta review

席位核对

ACCEPT @ 4c07e0d7084b91115d7af589082c509787b8cbc4 (card #37815 a/b, zone o3-B, narrowing). This is the delta c3319db2..4c07e0d7, and ACCEPT 7266096396 carries over to this head. L2 is still owed at CONTRACT_REVIEW_TIER: the seat's L2 delta, then landing at Tier H.

  • The merge of main is clean, and fix(runtime,cli,lint,spec)!: a sandboxed body's ctx.api.object(X).updateById(id, patch) writes the row #38643 is now in. 3a2111ab3f's tree, 7384cf0d91, is byte-identical to git merge-tree --write-tree c3319db2 4b577560. So the landing-order note in 7266096396 is settled: fix(runtime,cli,lint,spec)!: a sandboxed body's ctx.api.object(X).updateById(id, patch) writes the row #38643 landed first, and this branch carries it with no conflict resolution.
    • S1 (a60a6de9): the write-field explanation now lists .updateById(id, { … }) beside .update.
  • L2 M1 (29d3b0fe): a body lowered from a target function is judged for api.write only.
    • isLoweredTargetBody is true when a string target sits beside a body. That is the shape lowerCallables leaves: lower-callables.ts:568-578 takes a callable target, registers it, and writes the string ref back to target beside the body.
    • loweredActionBodyPaths walks actions[] and objects[].actions[] and produces the same …body.source paths that collectActionBodies reports. In the loop, if (lowered) continue; comes after the write arm, so a lowered body still gets action-body-write-capability-undeclared with its words unchanged.
    • The disclosed miss: an authored body beside a legacy string target is not judged either. That matches action.zod.ts:1527-1528, where target on a script action is kept for legacy functions references only. It is a missed finding, never a false one.
  • My own runs, in a clean worktree at this head, after building the @objectstack/lint^... closure.
    • validate-action-body-capabilities* gave 2 passed, 76 passed (76).
    • My ablation dropped if (lowered) continue;. That gave 3 failed | 73 passed, all three in the new M1 block: the os validate / build / lint case, the door case, and the writes case. I restored it and the tree is clean.
  • Read sentence by sentence; all true against the code above.
    • The changeset: the BREAKING banner now says "authored L2 body". The action-body-capability-undeclared bullet adds the lowered-target exclusion, with writes still judged. Arm (b) now says "Authored action body". The new closing sentence covers the lowered target case, FROM "built clean" TO "still builds clean".
    • validating-metadata.mdx: the action row adds "an authored L2 action body (one os build lowered from a target function is judged for its writes only)". The write row and the hook row are true as they stand.
    • The explanation adds the authored-only paragraph.
    • The v19 entry's surface, replacement, reason and acceptanceCriteria: the exclusion is stated in each, and the acceptance now names objects[N].actions[M].body.capabilities too.
    • 4c07e0d7 replaces "(the lowered reading is cli: the hook-body extractor infers no api.transaction and no api.read through a bound object handle, so a lowered handler's inferred capabilities miss calls it makes #38653)" with "(a later change carries the lowered reading)", so the printed guidance names no tracker. That fixes the Test Core red.
  • Dogfood: the battery at 29d3b0fea1 (495 / 4187, no failure; final-green 7267469416) covers this head, in my judgement. 4c07e0d7 changes one string of the v19 entry and nothing else. The seat makes the landing call.
  • Checks. The final-green comment reads 64 success and 0 failed at this head. mergeable_state is clean.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSAjFEZHRpRq3WCj6z

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 4c07e0d7084b91115d7af589082c509787b8cbc4
Local-runs: none
Scope: packages/spec/src/migrations/entries/semantic/19.hook-and-action-bodies-calling-an-ungranted-gate-refused.ts + packages/lint/src/validate-action-body-capabilities.ts, packages/lint/src/authoring-rules.ts, packages/lint/src/index.ts, packages/lint/src/rule-explanations.ts, packages/lint/src/validate-action-body-capabilities.hook-and-tokens-37815.test.ts

Delta round over record 7266230571 (FAIL at c3319db255fed5f856fd4eb12c759b70ae10501f). PR #38650, card #37815 (Refs, items a and b), narrowing face plus published schema. Read this round: the card's three comments since the first record (merge-round report 7266218175, claim amendment 3 7266251484, rework report 7267018841; 15 comments in all), the PR body as it now stands, the PR's net diff against merge base 4b57756092a1 (8 files, +790 / -46), the three own commits a60a6de915, 29d3b0fea1, 4c07e0d708, and the 76 check-runs on the new head: 64 success, 12 skipped, none failed, none pending. Between the two heads the branch merged main (3a2111ab3f); what came in with it is main's and is not reviewed. On the rule file the merge brought exactly #38643's two hunks (the header's leaf list and 'updateById' in SANDBOX_API_WRITE_METHODS) and nothing else; authoring-rules.ts and index.ts carry the same own hunks as at the first head. Code read outside the diff, never reviewed: packages/cli/src/utils/lower-callables.ts, packages/lint/src/validate-action-body-writes.ts, packages/spec/src/ui/action.zod.ts, packages/runtime/src/sandbox/quickjs-runner.ts on main.

Prior findings:

  • M1: closed
  • S1: closed
  • N1: unchanged, accepted deviation (PR body says so)
  • N2: fixed in 29d3b0fea1 (the header names hook as the third door; the entry's acceptanceCriteria names objects[N].actions[M].body.capabilities)
  • N3: unchanged, outside items a and b (PR body says so)

① Derived judgments

  • New since the first head: an action body beside a non-empty string target is not judged by action-body-capability-undeclared on any door (isLoweredTargetBody, the if (lowered) continue; after the write branch). Right: it removes the refusal M1 named and adds none. Against main such a body was judged for api.write only, and it still is, under the same id and words (pinned: "a lowered body still answers for its writes").
  • An action body with no string target is judged for every token as at the first head: the skip sits after the api.write branch and is keyed on the site's own path, and the six-token table, the per-token finding and both door cases still run on bodies without a target. Right.
  • The hook arm, the gate table, the census pin and the write id are as judged in the first record; the only change under them is main's updateById leaf, see ③.
  • Public surface: unchanged from the first head. isLoweredTargetBody is a module export, not on the @objectstack/lint barrel; the barrel still gains the two id constants only. packages/cli is not in the diff.

② Semver level

  • @objectstack/lint minor and @objectstack/spec patch, ! title, BREAKING banner, Clause-②: no (narrowing) and Metadata-protocol: narrowed on the PR body and the changeset, marker registered hook-and-action-bodies-calling-an-ungranted-gate-refused equal to the entry's id. Unchanged and right, on the precedents named in the first record. Check Changeset is green on the new head.
  • Clause-②: one arm. The M1 fix takes a refusal away from the narrowing and widens no published type; the cli type and its pin are untouched.
  • The changeset now says what breaks and what does not: BREAKING is for an authored body; the arm (b) bullet and the FROM and TO rows say an action body lowered from an inline target function is not judged for the other tokens and still answers for its writes. That agrees with the code. The gap the first record named under ② is closed.

③ Boundary flags

  • Rework report 7267018841: open_questions is empty. Carriers: cli: the hook-body extractor infers no api.transaction and no api.read through a bound object handle, so a lowered handler's inferred capabilities miss calls it makes #38653 for the lowered reading of both arms (not read, outside the inputs) and the seat for the leftover backup branch. Claim amendment 3 (7266251484) set the route for M1, S1 and N2 and told the dev to measure the marker before the edit and to stop on a fork that needs a packages/cli edit; the report states the measurement and no fork, and the diff holds no cli file.
  • Dogfood: the full battery is recorded at 29d3b0fea1 (495 files passed, 3 skipped; 4187 tests passed, 68 skipped). The final head differs from it by one sentence of the entry's replacement and was not re-run locally; Dogfood Regression Gate and Test Core are green on the final head, including the shard that was red at 29d3b0fea1 over that sentence.
  • Merge with fix(runtime,cli,lint,spec)!: a sandboxed body's ctx.api.object(X).updateById(id, patch) writes the row #38643, now in the branch: SANDBOX_API_WRITE_METHODS holds updateById, and the gate table reads that list by reference, so a hook body's or an action body's .updateById( call is judged behind api.write, which is what main's runner installs (WRITE, quickjs-runner.ts). No other verdict moved: the token set, the read leaves, the log levels, the doors and ctx.title(FIELD) are untouched by the merge, and the census test is green on the merged tree in CI (Test Core 12/12). The item is closed as text plus that one leaf.
  • SQL push-down: no query, id materialisation or in-app join in the diff.
  • No hits path is under skills/**, ui/skills/** or .claude/**, so no Security-touching: or Rule-change-verified: line is owed.

④ Design judgment

No must-fix, no should-fix.

M1: closed. How a lowered action body is recognised: isLoweredTargetBody(action) is true when action.target is a non-empty string and action.body is a record, on the CLI and at the doors alike. The marker is one the build stamps: lowerActionCallable (lower-callables.ts 554 to 580) lowers only a function target, always replaces it with the registered ref string (action.target = ref), and sets body beside it when extraction succeeds, so every lowered action body sits beside a string target; the stack the CLI rules read is that lowered stack, and an artifact item reaching the action or object door carries the same two keys. The CLI hands no lowered-action ref set (LoweringResult and AuthoringRuleContext carry loweredHookRefs only), so the shape is the only marker readable without a cli edit, as amendment 3 allowed. loweredActionBodyPaths builds its keys with the same prefixes and the same recordsOf indices as collectActionBodies, top level and inline, so the skip lands on the site it was computed for. Pins, both sides, on one source (a write inside ctx.api.transaction, granted api.write only, the grant the extractor infers): the authored body is refused; the same body beside a string target is not judged through the function, through runAuthoringRules for validate / build / lint at the top level and inline, and at the action and object doors, each door with an authored positive control; the lowered body without api.write is still refused under the write id. The reported ablation (the if (lowered) continue; line deleted: 3 failed, 43 passed, exactly the three lowered-target pins) matches what those tests assert; it was not re-run here.

S1: closed. ACTION_BODY_WRITE_UNKNOWN_FIELD_EXPLANATION now lists insert, .update({ id, … }) or .updateById(id, { … }), .upsert(…) and .updateMany(…), which is the set of field-carrying write leaves main's runner installs.

The narrowing, whole: one arm, no wider than its ground. What it refuses is an authored hook body calling any gate without its token, and an authored action body calling a gate other than the writes without its token; each such call is refused by the runner at the call site (the first record's census, unchanged but for the updateById leaf). What it leaves alone is every body whose grant the build inferred: a hook body by loweredHookRefs on the CLI and a string handler at the doors, an action body by a string target on every door. Both exemptions err toward a missed finding. The action one is the wider of the two: an authored JS body beside a legacy string target, and an authored body kept beside a target function, are skipped for the non-write tokens as well. That is disclosed in isLoweredTargetBody's own comment and in the PR body's acceptance notes, the spec keeps target on a script action only for legacy functions references (action.zod.ts, the target key's comment), and the dev reports no JS-body action with a string target in examples/app-showcase; a read of examples/** here found none either.

The hits entry, sentence by sentence against the code: surface says only a body the author wrote, a lowered hook body not judged and a lowered action body judged for its writes alone, as before: true. replacement says a hook written as a handler or an action written as a target function needs no change for the other tokens: true; it no longer names a tracker, which is what 4c07e0d708 changed and what turned Test Core green. reason gives the ground (the inference does not yet read every gated shape): true of the extractor on main. acceptanceCriteria names both action paths: true. The rule file's header (lines 20 to 31 and the last section), ACTION_BODY_CAPABILITY_UNDECLARED_EXPLANATION and the docs row say the same thing as the code.

Nits, no effect on the verdict:

Implemented-by: claude/issue-37815-body-capabilities-ab
Reviewed-by: session_01ADHkmSAjFEZHRpRq3WCj6z

VERDICT: PASS

@objectstack-fleet objectstack-fleet Bot removed the needs:contract-review Marker only — PR awaits its at-tier Contract review PASS; no check reads it, the record decides label Nov 30, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSAjFEZHRpRq3WCj6z

维护者速读

  • 用户能看到什么变化:作者保存或校验脚本动作、自己写的钩子脚本时,代码调用了沙箱要授权的功能(写数据、事务、日志、发邮件、写活动记录等)却没声明权限,会在保存和本地校验时被拒并说明要加哪个权限;以前能保存,但每次运行都报错。
  • 为什么做:把只覆盖「动作写数据」的权限检查扩展到钩子和沙箱的全部授权项。
  • 出错会怎样:误判会让本来能运行的脚本保存不了;由构建从函数转换出来的动作和钩子只查写权限、不做新增检查;已存元数据不受影响,示例应用实测无一被拒,可直接撤回。
  • 要你做什么:这是收紧保存检查的改动,需要你审批。契约复审 PASS 在评论 7267534418,Head-sha 4c07e0d7084b91115d7af589082c509787b8cbc4;批准后由席位落地。

Seat opinion: land as is. The first contract review failed because bodies the build lowers from an inline function were judged for grants their authors never write; that is fixed (lowered bodies are judged for api.write only), pinned on both the CLI and the save doors, and both review legs are on this head with nothing open above nit.

席位核对

ACCEPT at head 4c07e0d7084b91115d7af589082c509787b8cbc4 · Tier H (declared narrowing, maintainer-landed leg) · Refs #37815 (items a, b)

  1. Shape: items a and b of lint: action-body capability family follow-ups after #37807 (hook bodies, other capability tokens, updateById advice, ADR-0141 D1 binding list) #37815 in one Clause-② arm (narrowing), route C as ruled for this card; the existing write id keeps its message byte for byte.
  2. Premise measured: the card's reading that an ungranted sandbox gate saves and then throws at every run; the census pin equals HookBodyCapability.options and the runner's gate table.
  3. Gates: check-runs on this head 64 success, 12 expected skips, 0 failed, 0 pending; the dogfood battery ran green at 29d3b0fe, and this head differs from it by one entry sentence (L1 reading).
  4. Accepted deviations: N1 (ctx.title(undefined|null)), N3 (job bodies outside items a, b), N5 (entry wording for an authored body beside a string target).
  5. Out of scope and where it went: the lowered-body reading and a CLI-side pin of the lowered shape (N4) → cli: the hook-body extractor infers no api.transaction and no api.read through a bound object handle, so a lowered handler's inferred capabilities miss calls it makes #38653; skills docs → skills: teach three new save-time refusals — an ungroupable list-view grouping field, updateById in a body without api.write, and a hook or action body calling an ungranted capability #38655.
  6. Landing: L1 ACCEPT 7266096396, deltas through 7267533038 (this head); L2 FAIL 7266230571 (head c3319db2), delta PASS 7267534418 on this head with M1 and S1 closed. Lands after os-zhuang approves.

ACCEPT → PR #38650 comment 7267533038 · Contract review → comment 7267534418

@objectstack-fleet objectstack-fleet Bot added the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 30, 2026
@os-zhuang
os-zhuang marked this pull request as ready for review November 30, 2026 03:05
@os-zhuang
os-zhuang added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit 7870900 Nov 30, 2026
84 of 85 checks passed
@os-zhuang
os-zhuang deleted the claude/issue-37815-body-capabilities-ab branch November 30, 2026 03:31
@objectstack-fleet objectstack-fleet Bot removed the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 30, 2026
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
… whose documentBy is not a single-valued parent link (objectstack-ai#38662)

<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8Xj6YfMRKw8XnmTA1ohBr6K)_

Fixes objectstack-ai#38537

Clause-②: no
Metadata-protocol: none

**Lands after objectstack-ai#38594** (merged 2026-11-30T01:10Z; main merged into this
branch at `d1e1ba3f03`). Both PRs are seat 2's. The overlap is two files
(`packages/lint/src/index.ts`,
`packages/lint/src/rule-explanations.ts`), in hunks far apart;
`overlap-check` reads both clean against each other and main.

## 维护者速读

- 用户能看到什么变化:知识源的“文档单位”(`documentBy`)如果填的不是指向父记录的单值查找字段,`os validate` /
`os build` / `os lint` 和发布时都会报错并说明怎么改。之前只有在 Studio / 元数据 API 保存时才会拒绝。
- 为什么做:随包发布或代码注册的知识源不经过保存这道门,填错了没人拦,检索按父记录聚合会悄悄失效。这是 objectstack-ai#38537 的第二个也是最后一个
PR。
- 出错会怎样:只影响声明了 `documentBy` 的知识源;规则误判会让正确的知识源发布失败,删掉 `documentBy` 即可绕开。
- 要你做什么:无。

## What changes

- **New rule** `knowledge-source-document-by-not-parent-link` (`error`)
in `validate-knowledge-source.ts`. It refuses a `source.documentBy` that
`metadataFields` lists and that is not a single-valued parent link of
the indexed object. The checks run in the save door's order: declared by
the object, neither credential-class nor `internal`, a `lookup` /
`master_detail` type, a target `referenceTargetOf` can read, and not
`multiple: true`. Each reason gets its own message, worded like the save
door's `documentUnitRefusalText`, naming the field and the fix. Path:
`knowledgeSources[i].source.documentBy`.
- **Where it runs.** The rule rides the existing
`validateKnowledgeSource` registry entry, so it reaches `os validate` /
`build` / `lint` and the runtime publish gate (`knowledge_source`
writes) with no new wiring. This is what judges a source a package ships
or code registers; until now only the metadata API's save door did
(objectstack-ai#38564).
- **Not judged twice.** A `documentBy` that `metadataFields` does not
list is left to the parse, which already names that fix. A member the
object does not have is reported once, as
`knowledge-source-field-unknown`. An object with no readable field map
is not judged.
- **Published and explained.** The rule id is re-exported from the root
barrel (`index.ts`, one line in the knowledge block).
`rule-explanations.ts` gets its `os explain` entry and table row beside
the five sibling rules.
- **Census pin**
(`packages/core/src/security/second-object-read-exposure.pin.test.ts`):
the new `referenceTargetOf` import makes `validate-knowledge-source.ts`
a caller of the reference-target arbiter, so it is classified
`not-a-served-read` beside the other lint callers. It only asks whether
a target is declared, and reads and serves nothing of the target.
Admitted by the seat for this fix after CI's Test Core (8/12) flagged
the unclassified caller. Locally: 1 failed / 3 passed before the entry,
4/4 after.
- **Changeset** `patch` for `@objectstack/lint`.

## Route chosen for the parent-link rule (objectstack-ai#38564's PR 2 question)

objectstack-ai#38564 left PR 2 two ways to reach `parentLinkRule` / `documentUnitOf`
(`service-knowledge`'s `knowledge-search-scope.ts`). The seat accepted a
third:

- **A: lint imports `@objectstack/service-knowledge`.** Not taken.
`@objectstack/lint`'s package description says it "Depends on
@objectstack/spec; never on a runtime", and service-knowledge is a
runtime service. It would also need a new line on service-knowledge's
`exports` surface.
- **B: move the rule to "a package lint already reads, for example
`@objectstack/core`".** Not taken. Lint does not depend on
`@objectstack/core`; its workspace dependencies are `formula`,
`metadata-core`, `sdui-parser` and `spec`. Moving it to `spec` would put
runtime-shaped logic into the protocol package and widen this PR well
past its card.
- **C (taken): compose the verdict in lint from the spec predicates
`parentLinkRule` itself asks.** Withheld =
`isMaskedOnReadFieldType(type, managedBy)` or `internal === true`. That
is the reading this file already takes for
`knowledge-source-field-never-indexed`, and the one
`collectCredentialWriteResponseFields` /
`collectInternalWriteResponseFields` compute in core. Target =
`referenceTargetOf` (`@objectstack/spec/data`). The type pair `lookup` /
`master_detail` is spelled locally, as eight other lint rule files
already spell it. Cost: the four-part rule now lives in two places. No
test pins their agreement, because no package that depends on both can
import `documentUnitOf` without one more barrel line in
service-knowledge. The module header names the save door's function so a
change to one points at the other.

## Why

ADR-0161 K4: "a packaged item meets the gates that need no principal in
`os validate` and at publish". `documentBy` is such a gate: it reads
only the object definition. objectstack-ai#38564 left it judged at save only, and its
body says "PR 2's `os validate` rule covers packaged sources."

## Clause-② and Metadata-protocol, measured from the diff

`Clause-②: no` / `Metadata-protocol: none`, a judgement call stated here
for review. The rule refuses values of `source.documentBy`, a key objectstack-ai#38564
added in this same prerelease line. Its changeset
`.changeset/38537-knowledge-document-by.md` is still pending (not moved
to `.changeset/pre/`), so no published version carries the key and
nothing an author could write against a release is refused. The metadata
API's save door already refuses the same values. Read against `main`
instead, a packaged source with a non-parent-link `documentBy` passed
`os validate` before this PR and fails it after. If review prefers that
reading, the lines become `Clause-②: no (narrowing)` /
`Metadata-protocol: narrowed` (level `minor` and an ADR-0087
disposition).

## Verification

### Acceptance (the card's `os validate` half)

| Card line | Test (`validate-knowledge-source.document-by.test.ts`) |
|:--|:--|
| Refuse a text field, a `user` field, an `internal` lookup and a
`multiple` lookup, each naming the fix | "refuses a text field / a user
field / an internal lookup / a multiple lookup as the document unit,
naming the field and the fix" |
| (the save door's other reasons) | "… a credential-class field", "… a
lookup with no readable target", "… a system column the platform adds" |
| Positive controls | "CONTROL: a lookup and a master_detail to the
parent are admitted", "CONTROL: a source without documentBy is judged as
before" |
| Same verdict at publish | "refuses the publish with the words os
validate prints", "CONTROL: a single-valued parent link publishes with
nothing to report" |
| Published id + `os explain` | "the root barrel re-exports it", "os
explain answers it" |

### Ablation (`scripts/ablation-replace.mjs`, each mutation verified on
disk, each restore verified blob == HEAD `d9f63681062f` with an empty
`git diff HEAD`)

<details><summary>Call site disabled (<code>const refusal =
documentUnitRefusal(…)</code> → <code>undefined</code>): 9 red</summary>

`validate-knowledge-source.document-by.test.ts`: 9 failed / 8 passed.
All seven refusal tests, "a fields array is read like a field map", and
"refuses the publish with the words os validate prints". The controls
stay green.
</details>

<details><summary><code>multiple</code> arm deleted: 1 red</summary>

1 failed / 16 passed: "refuses a multiple lookup as the document unit…".
</details>

<details><summary><code>internal</code> half of the withheld arm
removed: 1 red</summary>

1 failed / 16 passed: "refuses an internal lookup as the document
unit…". (A first attempt was refused by the tool before running
anything, because its replacement text already occurred in the file; it
was re-run with a distinct replacement.)
</details>

### Package suite and typecheck

- `pnpm --filter @objectstack/lint test`: Test Files 248 passed (248),
Tests 9989 passed / 5 skipped. Exit 0.
- `pnpm --filter @objectstack/lint typecheck` (tsc + test layer): exit
0.
- `eslint` on the four changed source files: exit 0.
- `overlap-check`: VERDICT clean exit 0. origin/main merges cleanly, and
so do the 7 open PRs sharing a file (objectstack-ai#38651, objectstack-ai#38650, objectstack-ai#38643, objectstack-ai#38605,
objectstack-ai#38594, objectstack-ai#38550, objectstack-ai#38497).

### Derived gate families (`dispatch-gates.mjs --commands`, 70)

- First pass, captured per the tool's idiom: `--ran` reports "70 derived
famil(ies) accounted for — 66 run, 4 NOT-MEASURED (4 DERIVED from a
recorded exit 3)". All 66 that ran exited 0, including
`check-changeset-no-major --base origin/main`,
`check-adr-0087-registration --base origin/main`, `check:doc-authoring`,
`check:issue-citations` and `check:cross-package-test-inputs`.
- The four exit-3 families each had a prerequisite missing. Three were
re-run after fixing it, each exit 0: `check-plugin-teardown-shape
--self-test` (needed `git fetch --unshallow`),
`check:docs-transcript-drift` (needed the built lint) and
`check:lean-entry-closure` (needed the built objectql). These re-runs
were by hand, outside the `--ran` record.
- `check:dual-build-cjs-loads` was not measured locally: it reads every
package's `dist/`, which needs a full build. CI's `Build Core` job runs
it on this PR.

## Human Minimum

- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(spec untouched)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes (eslint on the changed
files).
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: n/a.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English (the 维护者速读 block is the
maintainer's Chinese brief).
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.

## Read first

1. `packages/lint/src/validate-knowledge-source.ts`:
`documentUnitRefusal` and the call site after
`judgeMembers('metadataFields')`.
2. `packages/services/service-knowledge/src/knowledge-search-scope.ts`:
`parentLinkRule` / `documentUnitOf`, the save door's rule this one
restates.

**Two-minute check:** `pnpm --filter @objectstack/lint exec vitest run
src/validate-knowledge-source.document-by.test.ts`. Expect 17 passed.

Dogfood: n/a (no `!` in the title, no `(narrowing)` arm).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01JQwxbWsSJprjGydwaCH1gD

<!-- signed: repo:objectstack#2 · os-warren ·
session_01JQwxbWsSJprjGydwaCH1gD -->

---------

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/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants