Skip to content

fix(app-shell): the Studio hook editor grants a sandboxed-JS body its capabilities - #26936

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/project-thread-7wuwlp
Oct 27, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/project-thread-7wuwlp

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Warren · project thread

Fixes #26726

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:Studio 钩子编辑器的「函数」区,在沙箱 JS 函数体下新增「能力授权」勾选列表(api.read / api.write / api.transaction / crypto.uuid / log),选项直接读 spec 的 HookBodyCapability,勾选即写 body.capabilities。
  • 为什么改:调用 ctx.api 等的钩子必须声明能力,否则运行时抛错;之前 Studio 没有任何入口能写这个列表,只能走 API 修。这是本卡的 ui 半张,服务端 500 的半张另有子卡。
  • 风险与回滚:只改编辑器写出的元数据,沙箱的能力校验原样不动;表达式函数体不显示该控件,切到表达式会去掉授权(表达式体本就拒收该键)。有问题直接 revert 本 PR。
  • 先看:HookDefaultInspector.tsx 里的 toggleCapability 与 setLanguage,然后 Function 区新增的 hook-body-capabilities 块,最后 HookDefaultInspector.capabilities-26726.test.tsx。
  • 两分钟验证:pnpm --dir ui exec vitest run packages/app-shell/src/views/metadata-admin/inspectors/HookDefaultInspector.capabilities-26726.test.tsx,预期 9 个测试全绿。
  • 需要你做的:无,席位落地。

What changes

Base c4a4aefc, then origin/main 57820085 merged in at 5e04bdcd (no conflict; it moved rows into the same studio i18n namespace but none of the engine.inspector.hook.* rows).

  • HookDefaultInspector.tsx, Function section. For a language: 'js' body, a "Capabilities" checkbox list, one box per HookBodyCapability token read from the spec enum (HookBodyCapability.options), each with the ctx call it unlocks underneath (ctx.api.object(…).find / findOne / count / aggregate, and so on). Ticking writes body.capabilities in the spec's token order; unticking the last writes [], the spec default.
  • Expression bodies. No control is drawn, and no edit of an expression body writes the key. Switching a body's language away from js drops capabilities, timeoutMs and memoryMb from the written body (the keys of ScriptBodySchema.shape that ExpressionBodySchema.shape lacks, read off the spec), because ExpressionBodySchema is strict and refuses each by name (its L2-only guidance).
  • A stored token the spec does not list (a typo, the retired crypto.hash) stays on screen as an extra, ticked, flagged box, and is kept on the next write until the author unticks it, so it never disappears unseen; the save's parse still names it.
  • Nothing is inferred from the body's source.
  • "More fields". No change needed: body was already a curated key as a whole (CURATED_FIELDS), which is exactly why nothing reached body.capabilities. The docblock claimed the js capabilities fell through to that form; it now says what is true.
  • ObjectHooksPanel.tsx. Unchanged: it merges each patch shallowly and the control's patch is a whole body, so the host needs nothing new.
  • i18n. engine.inspector.hook.capabilities, engine.inspector.hook.capabilitiesHint, engine.inspector.hook.capabilityUnknown in the lazy studio namespace, en and zh. Patch changeset for @object-ui/i18n; @object-ui/app-shell is private: true.

Why

Triage first grade on the card, verbatim: "p2, two halves: the Studio hook editor has no capabilities control (ui), and a hook refused for a missing capability answers the client 500, not a named refusal (domain:server, a child card filed on claim). ⛔ The capability check stays as strict as it is." This PR is the ui half; the server half is the child card #26903 and is not touched here.

Tests

HookDefaultInspector.capabilities-26726.test.tsx, ten cases. Every draft is the authored hook fed through HookSchema.parse, and every written body is parsed back through HookSchema:

  • one box per spec token, in enum order, read off HookBodyCapability.options, with the ctx call hint;
  • picking api.read writes body.capabilities: ['api.read'] and the saved hook parses;
  • an existing grant renders ticked, and a new grant is written in spec order beside it, source untouched;
  • clearing the last grant writes [], which parses to the same body as no grant;
  • an expression body shows no control, and its source edit writes no capabilities;
  • switching a granted js body to an expression drops the grant and the saved hook parses;
  • switching a js body with limits (timeoutMs, memoryMb) to an expression drops every L2-only key and the saved hook parses;
  • an unlisted stored token stays visible, flagged and kept, and unticking it removes it;
  • "More fields", fed a server schema that carries body.capabilities, draws no second control for it (positive control: it does draw the uncurated timeout);
  • the label and hint read in the designer locale (zh catalogue preloaded with await loadStudioCatalogue('zh')).
Runs
  • New file: 9/9 passed (lock VERDICT command-exit 0), on cef362e9 and again on 5e04bdcd.
  • Neighbours: every HookDefaultInspector.*.test.tsx, inspectorStrings.hookAction.i18n-10586, every ObjectHooksPanel*.test.tsx, plus packages/i18n/: 101 files, 1432 passed / 13 skipped, exit 0, on cef362e9 and again on 5e04bdcd.
  • pnpm --filter @object-ui/app-shell run type-check && pnpm --filter @object-ui/i18n run type-check: exit 0 on both heads (tsconfig.test.json compiles the new test).
  • eslint on the two touched app-shell files: 0 errors (one pre-existing react-refresh/only-export-components warning on HookTargetScopeContext).
  • pnpm check:new-line-citations (ui): 0 new citations.
Ablation (one-shot, through scripts/ablation-replace.mjs; each leg restored to the HEAD blob with an empty git diff HEAD)
  • Leg A, drop the write (patchBody({ capabilities: … }) replaced by a no-op): 4 of 9 red, exactly the pick, round-trip, clear and unlisted-token cases.
  • Leg B, keep the grant across a language switch (the delete next.capabilities line removed): 1 of 9 red, the language-switch case.
  • Leg C (patch round 1, head c042e7be), the L2-only delete loop removed: 2 of 10 red, both switch cases; restored.

Acceptance notes

  • The options are read from the spec at runtime (import { HookBodyCapability } from '@objectstack/spec/data'), not copied. The inspector already imports runtime values from that same entry through ConditionBuilder, and it loads behind the deferred designer loader (pageRouteLoadsNoStudioChunks-12187.test.tsx), so the read adds nothing to the console's eager closure; Build & E2E UI weighs that closure in CI.
  • Not changed, noted: body.timeoutMs and body.memoryMb still have no Studio control of their own (the language switch now drops them, patch round 1). Read from the code, not measured; left for a follow-up if wanted.
  • The sandbox's capability check and the server's refusal mapping are untouched (server: a hook refused for a missing capability answers the client 500 INTERNAL_ERROR instead of a coded refusal naming the hook and the capability #26903 carries the server half).

Verification

Patch round 1 at c042e7be: the same 34 families, all exit 0 (--ran 34/34); pnpm --dir ui exec vitest run scripts/ timed out two cases under shared-box load on the first pass, then exit 0 alone and on a full re-run. Gates derived by node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack on 5e04bdcd (the same 34 families as on cef362e9): 34 run, all exit 0, reconciled by --ran (34 derived, 34 run, 0 NOT-MEASURED, 0 UNRUN). Every family CI runs is read from this PR's check-runs, not re-run locally.

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic.
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; pnpm lint passes. (No formatter ran; the repo-wide pnpm lint is CI's run, read from Lint UI / Lint & Repo Gates.)
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec touched: its generated artifacts are regenerated and committed. (Not touched.)
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English.
  • The Before Submitting list in CONTRIBUTING.md is done.

Generated by Claude Code

… capabilities

A hook body that calls ctx.api, ctx.log or ctx.crypto needs the matching
token in body.capabilities, or the sandbox throws when the hook runs. The
hook inspector curates body as a whole, so the More fields form never drew
its members, and no control authored the grant list.

The Function section now shows a checkbox per HookBodyCapability token for a
js body, read from the spec enum, with the ctx call each unlocks. A switch to
an expression body drops the grant (an expression body refuses the key); an
unlisted stored token stays visible, flagged.

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

ExpressionBodySchema refuses capabilities, timeoutMs and memoryMb by name,
so the language switch now drops all three, read off the spec's two body
shapes. The api.write and log hints list every method the sandbox runner
gates on those tokens.

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

Copy link
Copy Markdown
Contributor Author

席位核对

ACCEPT · seat domain:ui#1 · session_01JQwxbZeBv2y91towxasSUT · head c042e7be · 2026-10-27T22:55Z

席位意见:钩子编辑器现在给沙箱 JS 函数体一组能力勾选框,选项取自 spec 枚举,按 spec 顺序写入 body.capabilities,全部取消写 [];表达式函数体不画也不写,切离 js 时清掉 spec 中全部 L2 专属键。

  1. Shape: Fixes #26726 (ui half; the server half is server: a hook refused for a missing capability answers the client 500 INTERNAL_ERROR instead of a coded refusal naming the hook and the capability #26903); 5 files, +331/−5. Source is HookDefaultInspector.tsx +86/−5, with one new test file (224 lines), 3 rows each in studio en/zh, and a patch changeset for @object-ui/i18n. ObjectHooksPanel.tsx is untouched: the host needed nothing.
  2. Premise measured: the seat read the source diff on both heads. CAPABILITY_TOKENS is HookBodyCapability.options, so the list cannot drift from the spec, and a grant is written in spec order. A stored token the spec does not list stays on screen, flagged, until it is unticked. The control renders only for language === 'js'. Patch round 1 (seat review): setLanguage now drops L2_ONLY_BODY_KEYS, the keys of ScriptBodySchema.shape missing from ExpressionBodySchema.shape (capabilities, timeoutMs, memoryMb), so a switch to an expression never carries a key the strict schema refuses. The ctx hints now match the runner's gates (quickjs-runner.ts: WRITE insert/update/delete/updateMany/deleteMany/upsert; log debug/info/warn/error). Dev: new file 10/10, each draft parsed through HookSchema; ablation legs A (4 of 9), B (1 of 9) and C (2 of 10) red, each restored.
  3. Gates / check-runs: PR check-runs on c042e7be: 43 success, 9 skipped, 0 failure. Dev's local run: 34 derived, 34 run, 0 NOT-MEASURED; app-shell and i18n type-check exit 0.
  4. Accepted deviations: vitest run scripts/ timed out two cases under shared-box load on the first local pass, then exited 0 alone and on a full re-run; CI is green. The seat applied the addendum's body_amendments (6455579985) to the PR body through the relay issue_patch, since a dev may not PATCH it.
  5. Out of scope: none filed. timeoutMs / memoryMb still have no Studio control of their own (noted by the dev, read from code). Skills-docs: none — UI editor only.
  6. Landing: not Tier H; the seat readies and arms auto-merge.

Generated by Claude Code

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

Projects

None yet

2 participants