Repository navigation
Commit 227ae36
feat(spec, runtime, lint): an action body refuses in the caller's language through a declared refusal catalogue (#34719)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBFyg5B2muWbKZjA9phXVWse)_
Fixes #34273
Clause-②: yes (widening) — an action may now declare `refusals`
(`ActionRefusalSchema`); translation bundles accept
`objects.<object>._actions.<action>.refusals.<CODE>.message` and
`globalActions.<action>.refusals.<CODE>.message` (with
`….reasons.<REASON>.message`); `@objectstack/spec` exports
`ActionRefusalSchema` and the `ActionRefusal` type (`ui`),
`actionRefusalMessageKey` (`system`), and
`ACTION_REFUSAL_MESSAGE_HOLE_REFUSED`,
`actionRefusalsWithoutSandboxedBody`,
`undeclaredActionRefusalCodeAtSave`,
`undeclaredActionRefusalReasonAtSave`, `undeclaredActionRefusalAtRun`
and `undeclaredActionRefusalReasonAtRun` (`data`);
`@objectstack/runtime` adds no export: the action body runner answers
through `resolveActionRefusal` internally. Nothing that was accepted
before is refused
Metadata-protocol: added
Skills-docs: follow-up #34824 — `skills/objectstack-i18n/SKILL.md` lists
the hook refusal key only and `skills/objectstack-ui/rules/actions.md`
teaches no action `refusals`; `content/docs/ui/actions.mdx` and
`content/docs/ui/translations.mdx` gain the section and the key row here
## 维护者速读
- 改了什么:动作(`type: 'script'` 的 `js` 体)可以像钩子一样声明拒绝语目录
`refusals`,体里只抛代码(`throw { code: 'NOT_DRAFT' }`),服务器按调用者语言回出声明的句子(放在
`userMessage`
上)和声明的状态码;译文和动作的其他文案放一处:`objects.<对象>._actions.<动作>.refusals.<CODE>.message`,无对象的动作在
`globalActions.<动作>.refusals.…`。
- 为什么改:动作体里 `throw new Error('英文句子')`
给中文、日文用户看到的永远是作者写的那句;钩子早有拒绝语目录(#26170 / #33214),动作没有。
- 风险与回滚:纯新增,没写 `refusals` 的动作行为完全不变(有对照测试);钩子的拒绝语与 texts 的已发布 schema
一字不变(共享工厂按主体出词)。回滚即 revert。
-
先看:`packages/spec/src/data/declared-entry.zod.ts`(共享的声明条目工厂,钩子拒绝、动作拒绝、钩子
texts 三种条目都由它造,#34374 动作半直接加一行),然后
`packages/runtime/src/sandbox/hook-refusal-catalogue.ts` 的
`resolveActionRefusal`。
- 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run
src/sandbox/action-refusal-catalogue.test.ts`,预期 16 条全过(含经真实 `/actions`
门回 409 + 中文 `userMessage`)。
- 需要你做的:无,席位落地;需契约复审(`Metadata-protocol: added`)。
## What changes
- **Spec — `ActionSchema.refusals`**
(`packages/spec/src/ui/action.zod.ts`): the hook catalogue's twin, keyed
by SCREAMING_SNAKE code: `{ message, status?, reasons?, params? }`.
Save-time checks: a catalogue on an action that runs no `js` body of its
own (another `type`, an `expression` body, no body) is refused at
`refusals`; a code, or a reason under a code that declares `reasons`,
that the body throws literally and the catalogue does not declare is
refused at `body.source` (comments and strings masked, a computed code
left to the run). `ActionRefusalSchema` is exported beside the action
schema.
- **Spec — one declared-entry factory**
(`packages/spec/src/data/declared-entry.zod.ts`, new, not on a barrel):
`declaredRefusalEntrySchema(subject)` builds `HookRefusalSchema` and
`ActionRefusalSchema`; `declaredTextEntrySchema(subject)` builds
`HookTextSchema` (#34374 PR1). One core (`message`, `params`, the
plain-text / closed-scope hole rule, the duplicate-param check); the
words per subject are table rows. Every hook sentence is byte-identical
to before, so the published hook JSON Schemas and reference pages do not
move. The action half of #34374 adds its `texts` row to the text table.
- **Spec — sentences and keys** (`hook-refusal-codes.ts`,
`i18n-resolver.ts`, `translation.zod.ts`): the save-time and run-time
refusal sentences are one subject-parameterised core with the hook
exports unchanged and action twins added;
`actionRefusalMessageKey(objectName, action, code, reason?)`; the action
translation node accepts `refusals` (alias `refusal`), one factory
shared with `hooks.<hook>.refusals`.
- **Runtime — `resolveActionRefusal`** (`hook-refusal-catalogue.ts`,
`body-runner.ts`, `app-plugin.ts`, `app-artifact-handlers.ts`): the
action body runner hands every body throw to it; one answer for a hook's
and an action's catalogue (`resolveSandboxedRefusal`): a declared code
is answered with the entry's sentence in the caller's
`executionContext.locale` (negotiated as a hook's is), its holes filled
through the same template renderer, its status and the code on the wire;
any other deliberate throw is a fault naming the action and the code.
The action's own object is read by the one owner-key ladder
(`standaloneActionOwnerKey` / `isObjectLessActionKey`,
`@objectstack/objectql`), so a bound action never reads `globalActions`
and an object-less one never reads an object's group. Both default
action-runner bindings now pass the `i18n` reader.
- **Lint**: `objectstack validate` refuses an action refusal translation
over a code or reason the action does not declare
(`checkActionRefusals`, nearest code offered); `os i18n extract`
scaffolds the keys (`pushActionRefusals`); the compile half of a
sentence with `params` judges action catalogues too
(`actionRefusalTemplateIssues`, on the collections the action copy pass
reads) — logic, an unknown formatter, an empty hole and `currency` with
no code are errors at `validate`, `compile` and the publish gate's
`action` write.
- **Docs**: `ui/actions.mdx` (new subsection under Path A),
`ui/translations.mdx` (key row).
- **Generated**: dropped-refinements baseline (`ui/ActionRefusal` and
the `….refusals.valueType` sites; header recomputed 270 / 1135),
liveness row `action.refusals` (drilled to its four keys) and the
`hook.refusals.params` producer re-anchored at the factory, a
strictness-ledger row for `declared-entry.zod.ts`, and the
`check:generated --fix` outputs (api-surface, export-origins,
declaration-map, reference docs, liveness counts, ledger counts, and the
two generator-owned `skills/*/references/_index.md` lines).
## Tests
- **`packages/runtime/src/sandbox/action-refusal-catalogue.test.ts`**
(new, 16): the real `actionBodyRunnerFactory` + `QuickJSScriptRunner`,
read off `mapDataError` and the real `/actions` door
(`HttpDispatcher.handleActions`): declared message/status/code with the
body's own text withheld; 400 default and the body's status not read;
zh-CN at the bound key; `zh` negotiated to `zh-CN`; an object-less
action at `globalActions`; CONTROL fallbacks (no translation, no locale,
no service); reason + params filled, reason translation filled after;
undeclared reason / code / no code → 500 fault naming the action;
CONTROL: no `refusals` answered as before, a crash stays a crash, a host
error passes through; the door answers 409 with the translated
`userMessage` (CONTROL: no catalogue keeps the body's 400 and no
`userMessage`).
- **`packages/spec/src/ui/action-refusals.test.ts`** (new, 29):
acceptance, code pattern, empty message, 5xx refused, refused on no body
/ expression body / `url` / `flow`, omitted `type` accepted,
`httpStatus` rename; literal undeclared code and reason at `body.source`
with CONTROLs (declared, computed, no catalogue); reasons/params hole
rules in the action's words; the hook and action entries accept and
refuse the same documents; each subject keeps its own sentences; the
text entry has no `status`/`reasons`; run-time sentences; both
translation addresses, bundle acceptance and the `refusal` rename.
- **Lint**: `validate-hook-refusal-templates.test.ts` (+12: CONTROLs,
three refusals, currency in the action's words, reasons at their own
path, one judgement for an action met twice, the stack pass, the publish
gate's `action` write with CONTROL);
`validate-translation-references.test.ts` (+4: CONTROL, undeclared code
with suggestion, a key on an action with no `refusals`, undeclared
reason and a reason under a code with none); `i18n-walk.test.ts` (+3:
bound key, reason key, `globalActions` key).
- **Forced test changes**:
`packages/spec/src/type-alias-convention.pin.test.ts` pins
`ActionRefusalSchema` as an isomorphic alias (857 → 858, with its
history line);
`packages/spec/src/system/metadata-form-zod-reconciliation.test.ts` (a
root omit row for `action.refusals` — the Studio form row is a
follow-up, as `hook.texts`'s was);
`packages/metadata-protocol/src/protocol.meta-types-degenerate-derivation.test.ts`
(`action` serves 54 top-level properties, was 53; the sample names
`refusals`); `packages/lint/src/validate-translation-references.test.ts`
(the action-translation coverage table gains a `refusals` row and the
real-instance leg a declared catalogue);
`packages/lint/src/authored-site-expression.test.ts` (the new walk pass
`actionRefusalTemplateIssues` classified). No other existing test was
changed.
## Acceptance notes
- **Contract fork** (recorded on the claim): the refusal sits on the
action like `HookSchema.refusals` (precedent named by the seat); final
public names are the seat's call: `refusals`, `ActionRefusalSchema`,
`actionRefusalMessageKey`, the runtime-internal `resolveActionRefusal`
(not a package export), and the factory module
`data/declared-entry.zod.ts` (`declaredRefusalEntrySchema`,
`declaredTextEntrySchema`).
- **Serial with #34374**: PR1 (#34545) is merged and this branch starts
from it; `HookTextSchema` now comes from the shared factory
(byte-identical published schema) so PR2 adds one text row for actions.
- **Not covered**: a string `target` with no body (an imperative host
handler) is not answered against the catalogue — `refusals` is refused
there at save, so nothing promises it. The Studio action form gets no
`refusals` row (it needs the eleven metadata-forms bundles); the
reconciliation ledger records the omission, owed to #34823, as the
skills teaching is to #34824 (`Skills-docs:` above).
- The `skills/objectstack-ui|data/references/_index.md` lines are pure
`gen:skill-refs` output (the generator lists a module's first exports;
`ActionRefusalSchema` now precedes `ActionSchema` in `action.zod.ts`
because it must be declared before the lazy `ActionSchema` evaluates it
under `OS_EAGER_SCHEMAS=1`).
- Needs a contract-tier review (`Metadata-protocol: added`).
## Verification
Every heavy run went under `os-verify-lock`.
- `@objectstack/spec`: 940 files, 28752 passed (the one red case on the
first run was the reconciliation row added in this PR, green on its
rerun with the pin test, 79/79). `check:generated` 14/14
(`check:test-typecheck` needs `NODE_OPTIONS=--max-old-space-size=8192`
on this box; the default heap OOMs in `tsc`, nothing measured).
- `@objectstack/lint`: 214 files, 9126 passed after the walk
classification; `tsc --noEmit` exit 0.
- `@objectstack/runtime` sandbox + app-artifact-handlers: 53 files, 665
passed; `tsc --noEmit` exit 0. `@objectstack/metadata-protocol`
derivation test 18/18.
- **Ablation** (`scripts/ablation-replace.mjs`, restored, blob == HEAD,
`git diff HEAD` empty): the action runner's `resolveActionRefusal(…)`
replaced by the raw throw ⇒ 12 of 16 runtime cases red; the 4 that stay
green are the pass-through CONTROLs (no catalogue, a crash, a host
error) and the door CONTROL.
- The spec test caught one wording slip during the work ("A action
refusal"), fixed with a per-subject article; the hook sentences are
unchanged.
- Gates: `dispatch-gates --commands` derived 128 families; all ran at
the merge of main (116 exit 0; 12 exit 3/1 on the first pass: a stale
spec `dist`, an unbuilt workspace, a shallow clone, and two findings
fixed in the head commit — `packages/spec/llms.txt` counts the new
module, and the new runtime test pays the `@objectstack/metadata` load
at collection). After a full `turbo run build` (119/119) and the fixes,
the 12 reran exit 0. The per-command ledger at head is on the card's
os-dev report.
Taken over by repo:objectstack#3 area o3-J (claim 6948521290 on #34273,
seat 2 hand-off 6948316290); L1 delta ACCEPT 6948575381 at `0169fc10`.
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01WGufzfr1xZSFZzCR8HnqXX
<!-- signed: repo:objectstack#3 · os-support-ai ·
session_01WGufzfr1xZSFZzCR8HnqXX -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 99bd220 commit 227ae36
51 files changed
Lines changed: 2037 additions & 316 deletions
File tree
- .changeset
- content/docs
- protocol/objectui
- references
- data
- kernel
- system
- ui
- ui
- docs/audits
- 2026-07-unknown-key-strictness-ledger.counts
- packages
- lint/src
- metadata-protocol/src
- runtime/src
- sandbox
- spec
- api-surface
- authorable-surface
- declaration-map
- export-origins
- json-schema.manifest
- liveness
- state-counts
- src
- data
- system
- ui
- skills
- objectstack-data/references
- objectstack-ui/references
- ui/packages/core/src/actions
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
| 232 | + | |
232 | 233 | | |
233 | 234 | | |
234 | 235 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
| 503 | + | |
503 | 504 | | |
504 | 505 | | |
505 | 506 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
| 36 | + | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
385 | 385 | | |
386 | 386 | | |
387 | 387 | | |
388 | | - | |
| 388 | + | |
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
394 | | - | |
| 394 | + | |
395 | 395 | | |
396 | 396 | | |
397 | 397 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
331 | 331 | | |
332 | 332 | | |
333 | 333 | | |
| 334 | + | |
334 | 335 | | |
335 | 336 | | |
336 | 337 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| 142 | + | |
142 | 143 | | |
143 | 144 | | |
144 | 145 | | |
| |||
244 | 245 | | |
245 | 246 | | |
246 | 247 | | |
| 248 | + | |
247 | 249 | | |
248 | 250 | | |
249 | 251 | | |
| |||
424 | 426 | | |
425 | 427 | | |
426 | 428 | | |
| 429 | + | |
427 | 430 | | |
428 | 431 | | |
429 | 432 | | |
| |||
667 | 670 | | |
668 | 671 | | |
669 | 672 | | |
| 673 | + | |
670 | 674 | | |
671 | 675 | | |
672 | 676 | | |
| |||
879 | 883 | | |
880 | 884 | | |
881 | 885 | | |
| 886 | + | |
882 | 887 | | |
883 | 888 | | |
884 | 889 | | |
| |||
0 commit comments