Skip to content

fix(studio): action editor grants a sandboxed-JS script body its capabilities - #29288

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/project-thread-ea4yw9
Nov 2, 2026
Merged

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

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Steedos · project thread

Fixes #29181

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:Studio 动作编辑器里「运行脚本 + Sandboxed JS (L2)」的函数体下方新增「能力授权」勾选列表(api.read / api.write 等),与钩子编辑器共用同一个控件。
  • 为什么改:动作脚本读写数据需要 body.capabilities,编辑器原先没有任何入口,作者发布的动作每次点击都被 403 拒绝,只能改原始元数据。
  • 风险与回滚:纯前端编辑器改动,不动 spec 与运行时;钩子编辑器换成共享控件后渲染与写入不变(26726 原测试未改动全绿)。回滚即撤销本 PR。
  • 先看:ScriptCapabilitiesField.tsx(新共享控件);ActionDefaultInspector.tsx 中 bodyLanguageOf(body) === 'js' 那一段;HookDefaultInspector.tsx 替换处。
  • 两分钟验证:cd ui && pnpm exec vitest run packages/app-shell/src/views/metadata-admin/inspectors/ActionDefaultInspector.capabilities-29181.test.tsx,预期 6/6 通过。
  • 需要你做的:无,席位落地。

What changes

  • New ScriptCapabilitiesField.tsx (module-private, beside the inspectors, no barrel re-export): the grant list of a sandboxed-JS body. One checkbox per HookBodyCapability token, read from the spec enum in its order, each naming the ctx call it unlocks; a stored token the enum does not list stays visible and flagged; unticking the last grant writes [], the spec default. The host passes the hint key, so each editor says when a refusal happens.
  • ActionDefaultInspector.tsx: renders that control under the script body when the body's language is js. Writes go through the existing single body writer (writeScriptBody), so language is kept and a switch to an expression body still drops capabilities with the other L2-only keys. An expression body shows no control.
  • HookDefaultInspector.tsx: its inline grant list is replaced by the shared control with the same test id, label, hint, flag and write. Its rendered output and writes are unchanged; HookDefaultInspector.capabilities-26726.test.tsx is untouched and green.
  • Spec enum check: ActionSchema.body is HookBodySchema, whose L2 arm is ScriptBodySchema with capabilities: z.array(HookBodyCapability), so the action body uses the same enum as the hook body, and the control is shared rather than duplicated. packages/spec is not edited.
  • i18n: one new Studio-namespace row, engine.inspector.action.capabilitiesHint (en, zh), because the hook hint says the call "throws when the hook runs". The label and the unknown-token flag reuse the hook rows. The Studio namespace is not part of the built locales surface, so the claim's Clause-②: no stands.
  • Changeset: .changeset/29181-action-script-capabilities.md, @object-ui/app-shell and @object-ui/i18n patch.

Tests

New ActionDefaultInspector.capabilities-29181.test.tsx (6 cases), driving the real inspector in a host that merges patches the way ObjectActionsPanel does, sending the held draft through a JSON round trip and parsing it with the spec's ActionSchema:

  1. The card path: New action, "Run a script", "Sandboxed JS (L2)", type a body that updates the record: the control shows exactly HookBodyCapability.options; ticking api.write writes body.capabilities: ['api.write'] and the action parses.
  2. An expression body shows no control, and its edits never write the key.
  3. A stored JS action without capabilities loads with nothing ticked, rendering writes nothing, and a source edit leaves the body without the key.
  4. An existing grant shows ticked, a new grant is written in spec order, clearing the last writes []; each step parses.
  5. Switching a granted JS body to expression drops the grant and hides the control; the save parses.
  6. The hint and label read in the designer locale (zh).

Acceptance notes

  • Real Studio run (author, publish, click, 200 instead of 403): NOT MEASURED. Staging it needs a full build, a Console build and a showcase server; the runtime half (the sandbox honouring a granted api.write) is existing behaviour this PR does not touch. Standing in: case 1 above, which proves the editor writes the exact body.capabilities the runtime's refusal prescribes and that ActionSchema accepts it.
  • BODY_KEYS_BY_LANGUAGE in the action inspector stays written out (its comment keeps the spec body schema out of the first load). The shared control imports HookBodyCapability from @objectstack/spec/data, which HookDefaultInspector already imported in the same registration module (inspectors/index.ts registers both), so no new spec module reaches any chunk.

Verification

Inspector suites (16 files)

pnpm exec vitest run --maxWorkers=2 over every ActionDefaultInspector.*.test.tsx, HookDefaultInspector.*.test.tsx and inspectorStrings.hookAction.i18n-10586.test.tsx: Test Files 16 passed (16), Tests 98 passed (98).

Ablation (control hidden)

scripts/ablation-replace.mjs replaced the action inspector's bodyLanguageOf(body) === 'js' guard with false (anchor 1 to 0, blob 182e05bd to 913d95bd): the new file went 5 failed, 1 passed (the expression case, which asserts absence, stays green as expected). Restored: blob equals HEAD, git diff HEAD empty.

Type-check and lint

turbo run type-check --filter=@object-ui/app-shell --filter=@object-ui/i18n: 66 tasks successful. eslint on the six touched files: 0 errors (one pre-existing warning on the hook inspector's context export).

Derived gates

node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack derived 34 families at b40f1cf; all 34 run, each exit 0; --ran reconciliation: 34 derived, 34 run, 0 NOT-MEASURED, 0 UNRUN. (check:query-options-erasure first hit a local 280 s cap, exit 124; re-run alone, exit 0 in 379 s.) After merging origin/main (head ede1584): the 16 inspector files 98/98 again, turbo type-check 66/66, check:sdui-manifest exit 0, and the Type Check UI static steps check:phantom-deps, check:spec-symbols, check:i18n-keys, check:i18n-drift, check:designer-field-key-parity, check:metadata-write-doors each exit 0.

node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0
node scripts/check-adr-0087-registration.mjs --self-test :: exit 0
node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0
node scripts/check-closing-keyword-parity.mjs :: exit 0
node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0
node scripts/check-comment-mask-corpus.mjs :: exit 0
node scripts/check-empty-changeset.mjs --base origin/main :: exit 0
node scripts/check-empty-changeset.mjs --self-test :: exit 0
node scripts/check-sdui-manifest.mjs :: exit 0
node scripts/check-sdui-manifest.mjs --self-test :: exit 0
node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0
node scripts/release-pending-publish.mjs --self-test :: exit 0
pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0
pnpm check:changeset-gate-self-tests :: exit 0
pnpm check:closed-ceremony-text :: exit 0
pnpm check:cross-package-test-inputs :: exit 0
pnpm check:dispatcher-error-vocabulary :: exit 0
pnpm check:driver-memory-census :: exit 0
pnpm check:engine-double-contract :: exit 0
pnpm check:gitlink-declared :: exit 0
pnpm check:nul-bytes :: exit 0
pnpm check:pm-changeset-deadline-census :: exit 0
pnpm check:published-files :: exit 0
pnpm check:query-options-erasure :: exit 0
pnpm check:refd-timer-probe :: exit 0
pnpm check:skill-identifier-liveness :: exit 0
pnpm check:test-source-alias :: exit 0
pnpm check:tier-file-adoption :: exit 0
pnpm check:type-check-coverage :: exit 0
pnpm check:undeclared-dep-imports :: exit 0
pnpm check:watch-hint-literal :: exit 0
pnpm check:where-matcher :: exit 0
pnpm --dir ui exec vitest run scripts/ :: exit 0
pnpm check:type-check-debt :: exit 0

Generated by Claude Code

🤖 Generated with Claude Code

https://claude.ai/code/session_01QsR2jSEPnzpJUHmt6bHrgt

…bilities

The action inspector kept `capabilities` in the JS body's key set but drew
no control for it, so a script action that read or wrote data was refused
on every click. Extract the Hook inspector's grant list into a shared
ScriptCapabilitiesField and mount it for the L2 action body too.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QsR2jSEPnzpJUHmt6bHrgt
@github-actions github-actions Bot added the size/m label Nov 2, 2026
@github-actions github-actions Bot added 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 Nov 2, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:ui#3 · zhuangjianguo · session_01QsR2jV4dWohojjbTJTQq5m

席位核对 · ACCEPT · 2026-11-02T11:24Z

Head-sha: ede1584f449a26dc6be5c060e06ddac65c54d9dd

  • Shape: draft → main, Fixes #29181 in the body only. 7 files, +356 / −57 (413 lines ≤ 3000). No governed path: check-governed-merges --pr 29288 reports NOT governed (0 of 7 paths). Clause-②: no and Metadata-protocol: none are line-initial in the body and the changeset, as claimed (6574146294). The changeset is patch for @object-ui/app-shell and @object-ui/i18n.
  • Contract review: none owed (Clause-②: no; ScriptCapabilitiesField is module-private beside the inspectors with no barrel re-export; the one new row is in the Studio namespace, outside the built locales surface; packages/spec untouched).
  • File surface: inside the claim: ActionDefaultInspector.tsx, HookDefaultInspector.tsx (the claim allowed it because a shared control was extracted), the new shared ScriptCapabilitiesField.tsx beside them, one hint row in studio en / zh (the hook hint says "when the hook runs", so the action needs its own), the new test, and the changeset.
  • Read in the diff: the action editor renders the grant list only when bodyLanguageOf(body) === 'js', writing through the existing patchBody, so a switch to an expression body still drops capabilities with the other L2-only keys. Tokens come from HookBodyCapability.options in spec order; an unknown stored token stays visible and flagged; unticking the last grant writes []. The hook editor's inline list is replaced by the same control with the same test id, label, hint and writes; HookDefaultInspector.capabilities-26726.test.tsx is untouched.
  • Tests (dev): new ActionDefaultInspector.capabilities-29181 6 cases through the real inspector, each save parsed by the spec's ActionSchema; ablation (guard to false) reds 5 of 6 with the absence case green, restored. 16 inspector files / 98 tests; type-check 66 tasks; eslint 0 errors.
  • Gates (check-runs on this head): 44 success, 11 skipped, 0 failed or pending. mergeable_state is clean.
  • NOT MEASURED: the real Studio author → publish → click run (200 instead of 403). The runtime half (the sandbox honouring a granted api.write) is existing behaviour this PR does not touch; case 1 proves the editor writes the exact body.capabilities the refusal names.
  • Landing: ordinary queue landing, pr_ready then automerge_enable. Fixes #29181 closes the card on merge.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 2, 2026 11:25
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 2, 2026
Merged via the queue into main with commit 5780fa4 Nov 2, 2026
56 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-ea4yw9 branch November 2, 2026 12:14
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

1 participant