Repository navigation
Commit 4ffe9d3
feat(spec, runtime, lint): an action writes the sentences it declares in the organization's language (ctx.text) (#35085)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBQ3DFv6XZAspQRYGQoEWhr8)_
Fixes #34374
Clause-②: yes (widening: a new optional authorable key
`ActionSchema.texts`, and new translation keys)
Metadata-protocol: added
Skills-docs: follow-up owed — skills/objectstack-ui/rules/actions.md,
skills/objectstack-i18n/SKILL.md
## 维护者速读
- **改了什么**:脚本动作(`type: 'script'` + `js` body)现在可以像钩子一样在 `texts`
里声明要写进记录的句子,body 里用 `ctx.text('key', params)` 取用。运行时按组织语言作答。
- **为什么改**:HotCRM 的 `send_email` 这类动作以前把 `'Email: ' + subject`
硬编码进记录,非英文组织只能读到英文。钩子已经有 `ctx.text`(#34545),动作这一半此前缺失。
- **风险与回滚**:只做加法。没有 `texts` 的动作行为不变,钩子的 schema
与文案字节不变(`references/data/hook.mdx` 未动)。回滚 = revert 本 PR。旧记录不会被改写。
- **先看**:① `packages/runtime/src/sandbox/hook-text.ts`(钩子/动作共用的
`buildDeclaredTextSurface`,组织语言与回退逻辑都在这里);②
`packages/spec/src/ui/action.zod.ts` 的
`refuseUndeclaredLiteralActionTextKey`(保存时拒收);③
`packages/runtime/src/sandbox/body-runner.ts` 的动作 handler 接线。
- **两分钟验证**:`pnpm --filter @objectstack/runtime exec vitest run
--maxWorkers=2 src/sandbox/action-text.integration.test.ts`,预期 8/8 通过。其中
ja-JP 用例写出日文句子,fr-FR 无译文时写出声明的原句。
- **需要你做的**:无,席位落地。
## What changes
This is PR2 of #34374, the action half, per split record 6931459308 and
ruling 6913660232 (option B, parameter 7). PR1, the hook half, landed as
#34545.
**spec**
- `ActionSchema.texts`: a record from snake_case keys to
`ActionTextSchema`. `ActionTextSchema` is
`declaredTextEntrySchema('action')`, the same shared factory and the
same entry shape (`message`, `params`) as `HookTextSchema`. Only the
words differ.
- `DeclaredTextSubject` is now `'hook' | 'action'`. The
`TEXT_WORDS.action` row's locale guidance names both translation
addresses: `objects.OBJ._actions.ACT.texts.KEY.message` and
`globalActions.ACT.texts.KEY.message`.
- `hook-refusal-codes.ts`: the text sentences are now built per subject
from private cores. The hook exports are byte-identical. New action
exports:
- `ACTION_TEXT_MESSAGE_HOLE_REFUSED` (the action-named hole refusal);
- `undeclaredActionTextKeyAtSave`;
- `undeclaredActionTextAtRun`;
- `actionTextsWithoutRunnableCode`.
- Two save-time refusals:
- `texts` on any action that runs no `js` body of its own (url, flow,
api, an expression body, or no body) is refused at `texts`;
- a literal `ctx.text('key')` over an undeclared key is refused at
`body.source`.
- `i18n-resolver.ts`: new `actionTextMessageKey(objectName, actionName,
key)`. It shares one node-key helper with `actionRefusalMessageKey`, so
a bound action and an object-less one resolve through the same ladder.
- `translation.zod.ts`: the action translation node accepts `texts`
through the new `textTranslationsSchema('action')`, which also builds
the hook translation node byte-identically. A loud `text` alias points
to `texts`.
**runtime**
- `hook-text.ts` is rebuilt around one `TextOwner` core,
`buildDeclaredTextSurface`, shared by `buildHookTextSurface` and the new
`buildActionTextSurface`. The organization's language comes from
`readOrganizationTextLocale`:
- the Localization setting when somebody set it;
- otherwise the app's `i18n.defaultLocale`;
- never the language of the person who ran the action.
- Fallback when no translation answers:
- a missing translation, or no language to pick, writes the declared
sentence filled with its params;
- a translation whose holes do not render is dropped for the declared
sentence, with a warning;
- a Localization setting that cannot be read rejects the call.
- `body-runner.ts`: the action handler passes `ctx.text` into the
sandbox, so both binding sites (`app-artifact-handlers.ts` and
`installDefaultActionBodyRunner`) receive it without change.
- The action's own object is read through `actionOwnObject`, which
`hook-refusal-catalogue.ts` now exports so the refusal and text surfaces
share one owner ladder.
**lint**
- `i18n-walk.ts`: `os i18n extract` and the coverage check now see
action texts, both inline object actions and top-level ones.
- `validate-translation-references.ts`: a translation over a key the
action does not declare under `texts` is refused, with
`TRANSLATION_TARGET_UNKNOWN`.
- `validate-hook-refusal-templates.ts`: action text templates are
compiled like refusal templates. `validate`, `compile` and the publish
gate refuse:
- logic in a hole;
- an unknown formatter;
- an empty hole;
- a `currency` formatter with no code.
**Ripples, docs, changeset**
- `@object-ui/core` `SPEC_ACTION_KEYS` gains `texts`.
- `liveness/action.json` gains a `texts` row.
- Counts and pins move:
- the type-alias pin: 859 to 860;
- the metadata-form reconciliation pin: a new omit row;
- the degenerate-derivation pin: 54 to 55;
- the dropped-refinements baseline: the build's corrected entries plus
`ui/ActionText`.
- Generated artifacts are regenerated by `check:generated --fix` and the
spec build. None is hand-edited.
- Docs:
- `ui/actions.mdx`: a new `texts` subsection;
- `ui/translations.mdx`: an "Action texts" row;
- `protocol/objectui/actions.mdx`: the field line;
- `automation/hook-bodies.mdx`: the `ctx.text` row said "hook bodies
only", which this change made false.
- Changeset: spec, runtime and lint `minor`; `@object-ui/core` `patch`.
## Tests
- `packages/spec/src/ui/action-texts.test.ts` (new) covers:
- parse;
- the closed entry;
- param identifiers and duplicates;
- a hole with no params, or over an undeclared param, in the action's
words;
- near-miss aliases;
- five non-script shapes refused;
- literal undeclared keys at save, with controls for a comment, a string
and a computed key;
- parity between the hook and action factories;
- the guidance naming both addresses, with no tracker number;
- translation addresses and a bundle at both layouts.
- `packages/runtime/src/sandbox/action-text.integration.test.ts` (new, 8
tests) uses a real ObjectQL, SqlDriver (better-sqlite3), QuickJS and
memory i18n, through `engine.registerAction` and `executeAction`. Cases:
- a bound action, with a `globalActions` control;
- an object-less action;
- ja-JP set in Localization, with a `source: 'default'` control;
- fr-FR with no translation, which falls back;
- an unrendered translation, which falls back with a warning, with a
control;
- an unregistered setting vs an unavailable store;
- an undeclared key;
- no texts declared.
- lint tests:
- `i18n-walk.test.ts`: 3 new tests;
- `validate-translation-references.test.ts`: a `texts` coverage row plus
3 new tests;
- `validate-hook-refusal-templates.test.ts`: about 11 new tests,
including the publish gate.
- HotCRM's `send_email` case, `ctx.text('email_subject', { subject })`,
is the pinned fixture throughout.
<details><summary>Red first on origin/main, then ablations (each
restored, blob == HEAD, `git diff HEAD` empty)</summary>
- **Red first:** with the runtime sandbox sources set back to BASE
`4443014630`, `action-text.integration.test.ts` reads `Tests 8 failed
(8)`.
- **Ablation 1** replaces body-runner's `buildActionTextSurface(...)`
with `undefined`: `Tests 8 failed (8)`.
- **Ablation 2** replaces hook-text's `actionOwnObject(...)` with
`undefined`: `Tests 4 failed | 4 passed (8)`. The 4 that pass are the
cases that do not read the action's object (fallback, undeclared key, no
texts, settings errors).
- **Ablation 3** makes i18n-walk's `pushActionTexts` return early:
`Tests 3 failed | 13 passed (16)`. The 3 new walk tests turn red and the
rest of the file stays green.
All three ablations went through `scripts/ablation-replace.mjs` with a
trap restore and a check that the anchor landed on disk.
</details>
<details><summary>Package suites and typecheck (head 7d7241a, after
merging origin/main)</summary>
- spec `pnpm test`: `Test Files 853 passed (853)` · `Tests 27290 passed
| 1 todo (27291)`
- lint `pnpm test`: `Test Files 218 passed (218)` · `Tests 9250 passed
(9250)`
- runtime `src/sandbox` + `src/app-artifact-handlers`: `Test Files 54
passed (54)` · `Tests 676 passed (676)`
- metadata-protocol degenerate-derivation pin: `Tests 18 passed (18)`
- `@object-ui/core` actionKeys pin: `Tests 19 passed (19)`
- `typecheck` for spec, runtime and lint: exit 0 each (`TC spec=0
runtime=0 lint=0`).
</details>
## Acceptance notes
- **Which actions run `ctx.text`.** Only `type: 'script'` actions with a
`js` body get it, because they are the only ones that run a body.
- An inline `target` function is lowered to such a body by `os build`.
- `flow` and `api` actions dispatch on `target` and have no body
context. A flow's record writes are the flow's own, translated under
`flows.FLOW.records` (#34062).
- **Studio.** The Studio action form shows no `texts` editor yet. The
key is authorable in source, and the metadata-form reconciliation pin
carries an explicit omit row for it. A form row is follow-up work.
- **Skills docs.** The skills teaching
(`skills/objectstack-ui/rules/actions.md`,
`skills/objectstack-i18n/SKILL.md`) is owed as a follow-up, per the
`Skills-docs:` line. This PR touches no `skills/**` file.
## Verification
The branch merged origin/main at eb7b09d. The one hand conflict was
the type-alias pin count: main's two `DatasetNextStep` pins (861) stack
with `ActionTextSchema` (862). The generated artifacts the merge left
stale were then regenerated with `scripts/pm/os-regen-merge.sh` and the
spec generators. No main-side line of the generated files was dropped;
only the schema counts moved.
The derived gate set has 122 commands, from `node
scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` at 7d7241a. All of them were run locally
at that head after a full package build. `dispatch-gates --ran` reads:
`122 derived, 122 run, 0 NOT-MEASURED, 0 UNRUN`. CI check-runs are cited
in the report.
<details><summary>Gate sweep at 7d7241a</summary>
- 121 of 122 gates exit 0 on the first run.
- `pnpm --dir ui exec vitest run scripts/` was SIGKILLed by the box's
memory limit while running beside the other gates. Rerun alone, it exits
0 (`Tests 5077 passed | 2 skipped`).
- `check:type-check-debt` ran under the verify lock: `0 raw tsc error(s)
total, none above its recorded number`.
- `check:dual-build-cjs-loads`: exit 0 (`124 published require entry
point(s) across 72 package(s) load`).
- `check:generated` (spec): `All 14 generated artifacts are up to date`.
- `check-platform-checklist --changed-from origin/main`: exit 0 (`20
anchor(s) judged, 0 lost`).
- `check-nul-bytes`: exit 0.
- `check-governed-merges --branch`: `NOT governed`, 44 paths, +1312 /
-92.
- An earlier full sweep at d3e6adf, before the merge, had seven
prerequisite refusals (shallow clone, missing dists, a lock
queue-timeout). All seven were fixed and rerun green before this sweep.
</details>
**Dogfood battery:** n/a. The title has no `!` and Clause-② is a
widening with no `(narrowing)` arm.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WGufzgNCAXyGfBQFZBwixH)_
<!-- signed: repo:objectstack#3 · os-support-ai ·
session_01WGufzgNCAXyGfBQFZBwixH -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent dfc6bbf commit 4ffe9d3
44 files changed
Lines changed: 1354 additions & 99 deletions
File tree
- .changeset
- content/docs
- automation
- protocol/objectui
- references
- data
- kernel
- system
- ui
- ui
- 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
- 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 | + | |
| 25 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| 233 | + | |
233 | 234 | | |
234 | 235 | | |
235 | 236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
502 | 502 | | |
503 | 503 | | |
504 | 504 | | |
| 505 | + | |
505 | 506 | | |
506 | 507 | | |
507 | 508 | | |
| |||
| 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 | |
|---|---|---|---|
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
| 335 | + | |
335 | 336 | | |
336 | 337 | | |
337 | 338 | | |
| |||
0 commit comments