Repository navigation
fix(app-shell): the Studio hook editor grants a sandboxed-JS body its capabilities - #26936
Merged
Merged
Conversation
… 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>
… 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>
Contributor
Author
席位核对ACCEPT · seat 席位意见:钩子编辑器现在给沙箱 JS 函数体一组能力勾选框,选项取自 spec 枚举,按 spec 顺序写入
Generated by Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Warren · project thread
Fixes #26726
Clause-②: no
Metadata-protocol: none
维护者速读
HookBodyCapability,勾选即写body.capabilities。ctx.api等的钩子必须声明能力,否则运行时抛错;之前 Studio 没有任何入口能写这个列表,只能走 API 修。这是本卡的 ui 半张,服务端 500 的半张另有子卡。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, thenorigin/main57820085merged in at5e04bdcd(no conflict; it moved rows into the samestudioi18n namespace but none of theengine.inspector.hook.*rows).HookDefaultInspector.tsx, Function section. For alanguage: 'js'body, a "Capabilities" checkbox list, one box perHookBodyCapabilitytoken read from the spec enum (HookBodyCapability.options), each with thectxcall it unlocks underneath (ctx.api.object(…).find / findOne / count / aggregate, and so on). Ticking writesbody.capabilitiesin the spec's token order; unticking the last writes[], the spec default.jsdropscapabilities,timeoutMsandmemoryMbfrom the written body (the keys ofScriptBodySchema.shapethatExpressionBodySchema.shapelacks, read off the spec), becauseExpressionBodySchemais strict and refuses each by name (its L2-only guidance).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.bodywas already a curated key as a whole (CURATED_FIELDS), which is exactly why nothing reachedbody.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 wholebody, so the host needs nothing new.engine.inspector.hook.capabilities,engine.inspector.hook.capabilitiesHint,engine.inspector.hook.capabilityUnknownin the lazystudionamespace,enandzh. Patch changeset for@object-ui/i18n;@object-ui/app-shellisprivate: true.Why
Triage first grade on the card, verbatim: "p2, two halves: the Studio hook editor has no
capabilitiescontrol (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 throughHookSchema.parse, and every written body is parsed back throughHookSchema:HookBodyCapability.options, with thectxcall hint;api.readwritesbody.capabilities: ['api.read']and the saved hook parses;sourceuntouched;[], which parses to the same body as no grant;capabilities;timeoutMs,memoryMb) to an expression drops every L2-only key and the saved hook parses;body.capabilities, draws no second control for it (positive control: it does draw the uncuratedtimeout);await loadStudioCatalogue('zh')).Runs
cef362e9and again on5e04bdcd.HookDefaultInspector.*.test.tsx,inspectorStrings.hookAction.i18n-10586, everyObjectHooksPanel*.test.tsx, pluspackages/i18n/: 101 files, 1432 passed / 13 skipped, exit 0, oncef362e9and again on5e04bdcd.pnpm --filter @object-ui/app-shell run type-check && pnpm --filter @object-ui/i18n run type-check: exit 0 on both heads (tsconfig.test.jsoncompiles the new test).eslinton the two touched app-shell files: 0 errors (one pre-existingreact-refresh/only-export-componentswarning onHookTargetScopeContext).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)
patchBody({ capabilities: … })replaced by a no-op): 4 of 9 red, exactly the pick, round-trip, clear and unlisted-token cases.delete next.capabilitiesline removed): 1 of 9 red, the language-switch case.c042e7be), the L2-only delete loop removed: 2 of 10 red, both switch cases; restored.Acceptance notes
import { HookBodyCapability } from '@objectstack/spec/data'), not copied. The inspector already imports runtime values from that same entry throughConditionBuilder, 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 UIweighs that closure in CI.body.timeoutMsandbody.memoryMbstill 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.Verification
Patch round 1 at
c042e7be: the same 34 families, all exit 0 (--ran34/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 bynode scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstackon5e04bdcd(the same 34 families as oncef362e9): 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
packages/specholds no runtime logic.pnpm lintpasses. (No formatter ran; the repo-widepnpm lintis CI's run, read fromLint UI/Lint & Repo Gates.)main, one pull request.packages/spectouched: its generated artifacts are regenerated and committed. (Not touched.)content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.Generated by Claude Code