Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/34824-action-refusals-skill.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@objectstack/skills': patch
'@objectstack/spec': patch
---

docs(skills, spec): the ui and i18n skills teach an action's `refusals` catalogue and its translation keys; `action.zod.ts` gains a module description

Clause-②: no — skill teaching text, evals and two comment-only edits in packages/spec; no schema, export or accept set moves
Metadata-protocol: none — no metadata key is touched

objectstack-ui's `rules/actions.md` gains a short section, "Refusing by code (`refusals`)": a `type: 'script'` action with a `js` body declares the refusals it may throw and throws the code instead of a sentence, the catalogue, the throws and the checks are the ones a hook has (taught in objectstack-data's `references/data-hooks.md` § Declared refusals), the sentence is answered as `userMessage` and translated at `objects.<object>._actions.<action>.refusals.<CODE>.message`, and an authored `errorMessage` replaces it in the console's failure toast. The file's Add Line example now declares `refusals: { PRODUCT_NOT_FOUND: … }` and throws `{ code: 'PRODUCT_NOT_FOUND' }` where it threw `new Error('Product not found.')`.

objectstack-i18n's SKILL.md lists the keys in the object key table — `_actions.{action_name}.refusals.{CODE}` holds `message` and `reasons.{reason}.message`, the same under `globalActions.{action_name}`, and a key for a code or reason the action does not declare is `translation-target-unknown` — and the server-composed text section names an action's refusal beside a hook's. Each skill's eval file gains one case that grades the rule.

`@objectstack/spec`: comments only. `src/ui/action.zod.ts` opens with a module doc block, so the generated reference page and the two skill reference indexes describe the module ("Action protocol schemas — `ActionSchema`, the `action` metadata type, and the parts it is built from.") where they listed its first five exports, and the jsdoc above `actionRefusalsWithoutSandboxedBody` names the third case as the function judges it: a `script` action with no `body`.
17 changes: 16 additions & 1 deletion content/docs/references/ui/action.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
---
title: Action schema — UI Protocol property reference
navTitle: Action
description: "Action schemas of the ObjectStack UI Protocol: Action, ActionAi, ActionLocation and 5 more — each property with its type, default and a TypeScript example."
description: "Action protocol schemas — ActionSchema, the action metadata type, and the parts it is built from."
---

{/* ⚠️ AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs live in the module folders under content/docs/. */}

Action protocol schemas — `ActionSchema`, the `action` metadata type, and the parts it is built from.

An action is a command a user or an AI agent runs: a button on a record
header, a list row or a list toolbar, or on a page. Its `type` names the
dispatch route — a `script` body or handler, a `url`, a `flow`, an `api`
endpoint, a `modal` or a `form` — and `locations` names the surfaces that
draw it. Declare one with `defineAction`.

Beside `ActionSchema`: `ActionParamSchema` (one input of the
param dialog), `ActionLocationSchema` (the surfaces),
`ActionAiSchema` (how an agent is offered the action),
`ActionRefusalSchema` (one entry of the `refusals` catalogue a
`script` body refuses through) and `InlineActionSchema` (an action
declared inline on a page element instead of registered by name).

<Callout type="info">
**Source:** `packages/spec/src/ui/action.zod.ts`
</Callout>
Expand Down
35 changes: 33 additions & 2 deletions packages/spec/scripts/file-description.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1796,28 +1796,59 @@ describe('corpus — no reference source donates a symbol comment to its page',
expect(openingOf('shared/mapping.zod.ts')).toBe('@module shared/mapping');
});

it('publishes no description for the eight modules whose opening was one schema\'s doc (#13334)', () => {
it('publishes no description for seven of the eight modules whose opening was one schema\'s doc (#13334)', () => {
// The corpus half of route ② — each of the eight had a symbol's comment
// wedged into its import list by the lazify codemod, published as the
// page's opening and as the module's skill-index pointer row. The comments
// moved back to the declarations they document (or to the family they
// head), so no block sits in the header zone documenting nothing: the page
// honestly prints no description. 宁可缺,不要错.
//
// The eighth, `ui/action.zod.ts`, has since been given a module header
// written on purpose (#34824 N4) — the case below pins it, so it leaves
// this list rather than being exempted from it.
const openingOf = (rel: string) =>
opening(findModuleDocBlock(fs.readFileSync(path.join(SRC_DIR, rel), 'utf-8')));
for (const rel of [
'ai/agent.zod.ts',
'data/datasource.zod.ts',
'data/hook.zod.ts',
'security/permission.zod.ts',
'ui/action.zod.ts',
'ui/app.zod.ts',
'ui/component.zod.ts',
'ui/page.zod.ts',
]) {
expect(openingOf(rel), rel).toBeNull();
}
});

it('opens `ui/action` with the module header written above its imports (#34824 N4)', () => {
// The one #13334 module that regained a description, and how: not a
// symbol's comment back in the import list, but a block in the header zone
// — after the licence line, before the first import — that describes the
// module. Pinned on three facts so neither a re-wedged symbol comment nor a
// header glued to a declaration can pass for it.
const rel = 'ui/action.zod.ts';
const source = fs.readFileSync(path.join(SRC_DIR, rel), 'utf-8');
const block = findModuleDocBlock(source);

// ① the opening, exactly — the page's first line and the skill-index row.
expect(opening(block)).toBe(
'Action protocol schemas — `ActionSchema`, the `action` metadata type, and the parts it is built from.',
);

// ② the selected block is the header zone's: nothing but the licence line
// and blanks precede it, and no import does.
const at = source.indexOf(`/**${block}*/`);
expect(at).toBeGreaterThan(-1);
const before = source.slice(0, at).split('\n').filter(l => l.trim() !== '');
expect(before).toEqual(['// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.']);

// ③ what follows it is the import list, not a declaration it could be
// documenting.
const after = source.slice(at + `/**${block}*/`.length).split('\n').find(l => l.trim() !== '');
expect(after).toMatch(/^import\b/);
});
});

/**
Expand Down
13 changes: 7 additions & 6 deletions packages/spec/src/data/hook-refusal-codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,13 @@ export function undeclaredActionRefusalReasonAtRun(
}

/**
* The save-time refusal for a catalogue on an action whose code cannot throw a
* code: a type other than `script` (its `target` is a URL, page, flow or
* endpoint — a refused flow answers through its own `end` refusal), an
* `expression` body, or a `script` action with neither a body nor an inline
* `target` function. `os i18n` would demand its translations and nothing would
* serve them.
* The save-time refusal for a catalogue on an action that runs no sandboxed
* `js` body, so nothing it runs can throw a declared code: a type other than
* `script` (its `target` is a URL, page, flow or endpoint — a refused flow
* answers through its own `end` refusal), an `expression` body, or a `script`
* action with no `body` — which is what a string `target` naming a host
* handler, or an inline `target` function `os build` could not lower, leaves.
* `os i18n` would demand its translations and nothing would serve them.
*/
export function actionRefusalsWithoutSandboxedBody(type: string, language: string | undefined): string {
const has = actionCodeCarrier(type, language);
Expand Down
17 changes: 17 additions & 0 deletions packages/spec/src/ui/action.zod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.

/**
* Action protocol schemas — `ActionSchema`, the `action` metadata type, and the parts it is built from.
*
* An action is a command a user or an AI agent runs: a button on a record
* header, a list row or a list toolbar, or on a page. Its `type` names the
* dispatch route — a `script` body or handler, a `url`, a `flow`, an `api`
* endpoint, a `modal` or a `form` — and `locations` names the surfaces that
* draw it. Declare one with `defineAction`.
*
* Beside {@link ActionSchema}: {@link ActionParamSchema} (one input of the
* param dialog), {@link ActionLocationSchema} (the surfaces),
* {@link ActionAiSchema} (how an agent is offered the action),
* {@link ActionRefusalSchema} (one entry of the `refusals` catalogue a
* `script` body refuses through) and {@link InlineActionSchema} (an action
* declared inline on a page element instead of registered by name).
*/

import { z } from 'zod';
import { retiredKey } from '../shared/retired-key';
import { FieldType } from '../data/field.zod';
Expand Down
26 changes: 25 additions & 1 deletion scripts/check-skills-token-ratchet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,31 @@ export const CEILINGS = new Map([
// 「A:先削重复,余额按实测提高」 (record 6513306068). The seven hand-authored
// objectstack-ui files net -149 bytes across the move (100990 -> 100841).
// ceil($(wc -c < skills/objectstack-ui/rules/actions.md) / 4) == ceil(12123 / 4)
['skills/objectstack-ui/rules/actions.md', 3031],
// 3031 -> 3180 (#34824): an action body refuses by code. One paragraph under the `ctx` section (which
// action may declare `refusals`; that the catalogue, the throws and the checks are a hook's,
// taught in objectstack-data and only pointed at here; the bundle key the sentence is translated
// at; that an authored `errorMessage` replaces the sentence in the console's toast), and the
// Add Line example declares one entry and throws its code where it threw a sentence. PAID DOWN
// FIRST by 124 bytes of true restatement in this file, five cuts: the label line
// "**Script-typed action**:" above the Add to Campaign example (26; the block's own
// `type: 'script'` says it, under the H2 "Examples"); the label "**Flow-typed action**" and the
// parentheses it held the `onSuccess` note in (19 net, the note now says "the flow run"; the
// block's own `type: 'flow'` says it); "`openIn: 'new-tab'` opens it in a new tab," (35 net,
// `'self'` now spelled `openIn: 'self'`; the H3 "`openIn: 'new-tab'`" under the H2 "Opening in
// a New Tab" and the example's `openIn: 'new-tab'` line say it); " on success / failure" on
// the `successMessage` / `errorMessage` bullet (21; the two key names, that bullet's
// "Action completed" half and the refusals paragraph's "failure toast … `errorMessage`" say
// it); "(`{ field: 'email' }`)" beside "field-backed params" (23; the `{ field: … }` params of
// the Reassign Lead, Add to Campaign and Add Line examples show the shape). The same ruling's
// second half carries the rest. Arithmetic: the text adds 721 bytes, the cuts remove 124, so
// the file is 12123 -> 12720 bytes -> 3180 tokens, zero headroom before, ceiling +149, the
// measured remainder only, pinned AT the measurement. RE-MEASURED on the merge with main after
// the #34770 row above landed first (this entry was written as 2808 -> 2957 over 11231 ->
// 11828 bytes; the delta is the same +597 bytes, +149 tokens, and none of the five cuts falls
// in the text that row moved in). Same ruling as the lines above (2026-10-27, tap A):
// 「A:先削重复,余额按实测提高」 (ruling record 6513306068).
// ceil($(wc -c < skills/objectstack-ui/rules/actions.md) / 4) == ceil(12720 / 4)
['skills/objectstack-ui/rules/actions.md', 3180],
// 6090 -> 6252 (#19715, card item 4): a 5-line table of contents at the top,
// anchors to the file's existing headings, nothing else changed. +162 tokens,
// zero headroom to absorb any of it, ceiling +162. Maintainer ruling
Expand Down
2 changes: 1 addition & 1 deletion skills/objectstack-data/references/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ from `node_modules` — there is no local copy in the skill bundle.
- `node_modules/@objectstack/spec/src/system/deploy-bundle.zod.ts` — Deploy Bundle Protocol
- `node_modules/@objectstack/spec/src/system/translation.zod.ts` — Exports: LocaleSchema, FieldTranslationSchema, ActionResultDialogTranslationSchema, ObjectTranslationDataSchema, TranslationDataSchema
- `node_modules/@objectstack/spec/src/ui/action-params.zod.ts` — The action DISPATCH contract: what the platform validates on the way in, and
- `node_modules/@objectstack/spec/src/ui/action.zod.ts` — Exports: ActionParamSchema, ActionType, ActionLocationSchema, ActionAiSchema, ActionRefusalSchema
- `node_modules/@objectstack/spec/src/ui/action.zod.ts` — Action protocol schemas — `ActionSchema`, the `action` metadata type, and the parts it is built from.
- `node_modules/@objectstack/spec/src/ui/bulk-action.zod.ts` — Bulk Action Schemas
- `node_modules/@objectstack/spec/src/ui/chart.zod.ts` — Unified Chart Type Taxonomy
- `node_modules/@objectstack/spec/src/ui/i18n.zod.ts` — Display-label and ARIA-label primitives shared by every `ui/` shape.
Expand Down
13 changes: 7 additions & 6 deletions skills/objectstack-i18n/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ All translatable content for a single object is aggregated under
| `_sections.{section_name}` | Form section `label`, `description`; `fields.{field_name}` — the `label`, `placeholder`, `helpText` an entry overrides for that form alone (`helpText` here, `help` under `fields.{field_name}` above: each spells what its source does) |
| `_tabs.{tab_name}` | Filter-preset tab `label` (`ViewTabSchema.name`) |
| `_validations.{rule_name}` | `message` only — the sentence a rejected write returns (replaces the retired `validationMessages`) |
| `_actions.{action_name}.refusals.{CODE}` | `message`, and `reasons.{reason}.message` per declared reason — the sentences of the action's `refusals` catalogue (**objectstack-ui** → Actions), for a code and reason it declares (any other is `translation-target-unknown`); the same under `globalActions.{action_name}` |

Top-level groups alongside `objects`: `apps` (label, description, navigation),
`messages`, `globalActions` (actions with no `objectName` — a key naming a bound action is
Expand Down Expand Up @@ -340,9 +341,8 @@ The spec models coverage results for tooling — the return shapes of the option
(totals, `coveragePercent`, per-group `breakdown`) and `TranslationDiffItem` —
`key` (dot path), `status` (`missing | redundant | stale`), `locale`, optional
`objectName`, optional `sourceHash` for stale detection, and AI-enrichment
fields (`aiSuggested`, `aiConfidence`). Full Zod shape:
`node_modules/@objectstack/spec/src/system/translation.zod.ts` —
`TranslationCoverageResultSchema`, `TranslationDiffItemSchema`.
fields (`aiSuggested`, `aiConfidence`). Full Zod shape: `TranslationCoverageResultSchema`,
`TranslationDiffItemSchema` (`translation.zod.ts`).

---

Expand Down Expand Up @@ -403,7 +403,8 @@ produced; a client renders it as received.
code is never handed Simplified text.
- **App-authored** refusal text is not on this ladder: a hook's catalogued refusal is served
through `hooks.<hook>.refusals.<CODE>.message` (a declared reason's through
`hooks.<hook>.refusals.<CODE>.reasons.<REASON>.message`) in the caller's locale, negotiated over
`….<CODE>.reasons.<REASON>.message`), an action's through its `_actions.{action_name}.refusals`
keys (table above), each in the caller's locale, negotiated over
whatever locales the app's translations hold, and otherwise as declared, in the app's own
source language. No `en` floor is supplied for it. Under an entry declaring `params`, a
translation keeps its `{{ name }}` holes; the runtime fills them after picking it.
Expand Down Expand Up @@ -474,8 +475,8 @@ every plugin contributes its own `objects.*` slice.

## Shipped examples

`examples/app-crm` — the bundled layout (one `crm.translation.ts`, `en` + `zh-CN`).
`examples/app-todo` — the per-locale layout (`{en,zh-CN,ja-JP}.ts` + `index.ts`).
`examples/app-crm` — the bundled layout (`en` + `zh-CN`).
`examples/app-todo` — the per-locale layout.

---

Expand Down
10 changes: 10 additions & 0 deletions skills/objectstack-i18n/evals/bundles-locales-coverage.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@
"must_not_contain": ["pages.crm_manual", "sections.getting_started"]
}
},
{
"id": 13,
"prompt": "The `submit_signoff` action on `crm_invoice` declares `refusals: { NOT_DRAFT: { message: 'Only a draft invoice can be signed off.', status: 409 }, STAGE_LOCKED: { message: 'This stage change is not allowed.', params: ['stage'], reasons: { closed: { message: 'A {{ stage }} invoice can no longer change.' } } } }`, and its body throws those codes. zh-CN users still read the English sentences. Which bundle keys translate them, and what does a caller get in a locale no bundle covers?",
"expected_output": "`objects.crm_invoice._actions.submit_signoff.refusals.NOT_DRAFT.message` and `….refusals.STAGE_LOCKED.message`, and the reason's sentence at `objects.crm_invoice._actions.submit_signoff.refusals.STAGE_LOCKED.reasons.closed.message`; an action with no `objectName` takes the same keys under `globalActions.submit_signoff`. The reason's translation keeps its `{{ stage }}` hole, which the server fills after picking the translation. The server answers the sentence in the caller's locale, negotiated over the locales the app's bundles hold, on the refusal's `userMessage`; a locale no bundle covers gets the declared sentence as written, with no `en` floor. A key for a code or reason the action does not declare is `translation-target-unknown`. Not a hook's refusal key, and not a `messages` entry the body looks up itself.",
"files": [],
"assertions": {
"must_contain": ["_actions", "submit_signoff", "refusals", "NOT_DRAFT", "reasons", "closed"],
"must_not_contain": ["hooks.submit_signoff"]
}
},
{
"id": 10,
"prompt": "In zh-CN the `crm_renew` action on `crm_opportunity` opens its param dialog with the rows of its pre-submit read still in English. Its `preflight.fields` declares the paths `amount` and `verdict.summary`.",
Expand Down
10 changes: 10 additions & 0 deletions skills/objectstack-ui/evals/views-apps-actions-pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@
"must_contain": ["type: 'simple'", "modalSize"],
"must_not_contain": ["type: 'tabbed'"]
}
},
{
"id": 20,
"prompt": "The `submit_signoff` script action on `crm_invoice` refuses a non-draft invoice with `throw new Error('Only a draft invoice can be signed off.')` in its `js` body, so zh-CN users read that English sentence in the failure toast. Make it refuse in the caller's language, with the code `NOT_DRAFT` and a 409.",
"expected_output": "The action declares `refusals: { NOT_DRAFT: { message: 'Only a draft invoice can be signed off.', status: 409 } }` and the body throws the code instead of the sentence: `throw { code: 'NOT_DRAFT' }`. The server answers the declared sentence on the refusal's `userMessage` with status 409, in the caller's locale once the zh-CN bundle carries `objects.crm_invoice._actions.submit_signoff.refusals.NOT_DRAFT.message`, else as declared, and the console's failure toast shows it. The action authors no failure copy of its own, which would replace that sentence in the toast. A code the body throws literally and `refusals` does not declare is refused at save. Not a locale branch in the body, and not a second sentence per language in the throw.",
"files": [],
"assertions": {
"must_contain": ["refusals", "NOT_DRAFT", "409", "_actions"],
"must_not_contain": ["hooks.submit_signoff"]
}
}
]
}
2 changes: 1 addition & 1 deletion skills/objectstack-ui/references/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ from `node_modules` — there is no local copy in the skill bundle.

## Core schemas

- `node_modules/@objectstack/spec/src/ui/action.zod.ts` — Exports: ActionParamSchema, ActionType, ActionLocationSchema, ActionAiSchema, ActionRefusalSchema
- `node_modules/@objectstack/spec/src/ui/action.zod.ts` — Action protocol schemas — `ActionSchema`, the `action` metadata type, and the parts it is built from.
- `node_modules/@objectstack/spec/src/ui/app.zod.ts` — Exports: ObjectNavItemSchema, DashboardNavItemSchema, PageNavItemSchema, UrlNavItemSchema, ReportNavItemSchema
- `node_modules/@objectstack/spec/src/ui/chart.zod.ts` — Unified Chart Type Taxonomy
- `node_modules/@objectstack/spec/src/ui/component.zod.ts` — Exports: PageContainerProps, PageHeaderProps, PageTabsProps, PageCardProps, RecordDetailsProps
Expand Down
Loading
Loading