Skip to content

Commit 19b5b42

Browse files
committed
docs(skills): show the reasons list shape on the actions page; narrow two hook-page claims
Contract review on #37407: actions.md now writes the list throw's shape and its closing line; data-hooks.md says the HTTP doors (not every door) answer details.refusals, and names a non-list reasons as a 500 too. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6bhgUpnvPnJ1hR74pUrVj
1 parent f0fd20d commit 19b5b42

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

‎.changeset/37407-skills-multi-reason-refusal.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ docs(skills): data hooks and actions teach the multi-reason refusal throw
77
Clause-②: no (published prose only; teaches the list throw already on main)
88
Metadata-protocol: none
99

10-
`skills/objectstack-data/references/data-hooks.md` (Declared refusals) now teaches the list form beside the single `reason`: throw `reasons: [{ reason, params? }, …]`; each line is translated and filled from its own `params`; `userMessage` joins the lines and closes with the entry's `message`, filled from the throw's top-level `params` (else its holes render empty); every door answers `details.refusals`. It says how an entry declares `reasons` (a snake_case reason to `{ message }` only; another status needs another code), that every listed reason must be declared (refused at save when literal, a `500` at run), and that `reason` beside `reasons`, an empty list or a malformed element is a `500`. `skills/objectstack-ui/rules/actions.md` (Refusing by code) points an action's body at the same list. Both files sat at zero token headroom, so the words are paid for by tightening prose in the same file; no fact is removed (one redundant `condition` example and a sample field go).
10+
`skills/objectstack-data/references/data-hooks.md` (Declared refusals) now teaches the list form beside the single `reason`: throw `reasons: [{ reason, params? }, …]`; each line is translated and filled from its own `params`; `userMessage` joins the lines and closes with the entry's `message`, filled from the throw's top-level `params` (else its holes render empty); the HTTP doors answer `details.refusals`. It says how an entry declares `reasons` (a snake_case reason to `{ message }` only; another status needs another code), that every listed reason must be declared (refused at save when literal, a `500` at run), and that a `reasons` that is not a non-empty list of `{ reason, params? }`, or one beside `reason`, is a `500`. `skills/objectstack-ui/rules/actions.md` (Refusing by code) shows an action's body the same list shape, `reasons: [{ reason, params? }, …]` instead of `reason`, closed by the code's `message`, and points at the hook section for the rules. Both files sat at zero token headroom, so the words are paid for by tightening prose in the same file; no fact is removed (one redundant `condition` example and a sample field go).

‎skills/objectstack-data/references/data-hooks.md‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,8 @@ A throw aborts the operation and rolls back its transaction; `onError: 'log'`
785785

786786
A hook that enforces a business rule declares a `refusals` catalogue, one
787787
SCREAMING_SNAKE code per rule, and throws the code. Without one, a `body`'s
788-
throw is answered `HOOK_ABORTED`, the platform's code: fine for a failure you did not
789-
plan, not for a rule the user can act on. A cross-object guard a validation rule
790-
cannot read:
788+
throw is answered `HOOK_ABORTED`, the platform's code: fine for an unplanned failure, not
789+
for a rule the user can act on. A cross-object guard a validation rule cannot read:
791790

792791
<!-- os:check -->
793792
```typescript
@@ -829,14 +828,14 @@ export default defineHook({
829828
- For several reasons throw `reasons: [{ reason: 'on_loan', params: { due } }, …]`, not
830829
`reason`: one translated line each, filled from its own `params`. `userMessage` joins
831830
them by newlines and ends with the entry's `message`, filled from the throw's
832-
top-level `params` (else its holes are empty); every door answers
831+
top-level `params` (else its holes are empty); the HTTP doors answer
833832
`details.refusals: [{ reason, message }]`, absent for a single `reason`.
834833
- Translated via `hooks.<hook>.refusals.<CODE>.message` (or
835834
`….<CODE>.reasons.<REASON>.message`); the thrown text and `status` are unused.
836835
- An undeclared code (or none), or a reason missing from a code's `reasons` (a listed
837836
one even when the code declares none), is refused: at save if thrown literally, else
838-
as a `500`. `reason` beside `reasons`, an empty list or an element not
839-
`{ reason, params? }` is a `500`. Unchanged `ctx.api` errors and crashes pass through.
837+
as a `500`. A `reasons` not a non-empty list of `{ reason, params? }`, or beside
838+
`reason`, is a `500`. Unchanged `ctx.api` errors and crashes pass through.
840839

841840
### Declared texts (`texts`)
842841

‎skills/objectstack-ui/rules/actions.md‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ in `language: 'js'` (an `expression` body has no I/O) with
2121
|:-----------------|:--------|
2222
| `record_header` | Detail page header |
2323
| `record_more` | Detail page overflow menu (⋯) |
24-
| `record_related` | Related-list section inside a record |
24+
| `record_related` | Related-list section in a record |
2525
| `record_section` | Body section/tab of a record |
2626
| `list_item` | Per-row action in list views |
2727
| `list_toolbar` | Toolbar button; one ticked row is its `recordId`, several are refused (no `_selectedIds`) |
@@ -42,8 +42,8 @@ there: a wrong name draws nothing.
4242

4343
## Visibility, Disable & Feedback
4444

45-
- `visible` — a bare CEL predicate over the current record (prefer the `P\`...\`` template; `record.<field>` resolves identically on every surface, never `${…}`- or `{…}`-wrapped — see `objectstack-formula`); when false the action is **hidden**.
46-
- `disabled` — `boolean` **or** a CEL predicate; when true the action **shows but greys out**. A bare field ref in either (`done` for `record.done`) fails `os validate`.
45+
- `visible` — a bare CEL predicate over the current record (prefer the `P\`...\`` template; `record.<field>` resolves identically on every surface, never `${…}`- or `{…}`-wrapped — see `objectstack-formula`); when false it is **hidden**.
46+
- `disabled` — `boolean` **or** a CEL predicate; when true it **shows but greys out**. A bare field ref in either (`done` for `record.done`) fails `os validate`.
4747
- `disabledReason` — an I18nLabel (a sentence or an inline locale map) a greyed action shows as its hover title and accessible description. Display-only: never a predicate or a gate (the hook or permission still refuses). Omit it to keep the console's default "Not available for this record"; a blank one is refused, and `disabledMessage` / `disabledTooltip` / `disabledHint` / `disabledText` are refused naming this key. The reason goes here, not in `description`.
4848
- `pressed` — a CEL predicate over the same scope as `visible` that marks the action as already done by this reader: while TRUE the record header draws it pressed (`aria-pressed`). Display-only, never a gate; a boolean literal is refused (a constant is a style, not a reader's state), and `active` / `activeWhen` / `pressedWhen` are refused naming this key. A per-reader fact (the reader's vote) is a block the object declares under `attachedOnRead`, filled per caller by a service or `afterFind` hook, read as `has(record.viewer) && record.viewer.vote == 'helpful'`.
4949
- `confirmText` — set for any destructive or irreversible operation; the confirm dialog of a param-less action. A registered action is refused it beside a non-empty `params` (put the question on `description`); a view's `bulkActionDefs` entry pairs the two by its own contract.
@@ -54,7 +54,7 @@ there: a wrong name draws nothing.
5454
- Copy holes are `{{ }}`: `confirmText`, `description` and a param's `helpText` read `record`; `successMessage` and each `outcomeMessages` entry (`resent: 'Invitation resent to {{ result.email }}'`) read `result` and `record`; `errorMessage` takes none. A `bulkActionDefs` entry's `confirmText` reads `{{ count }}` and its params by bare name (`{{ tier }}`). In all of them `${record.name}`, `{name}`, logic in a hole and a blank sentence fail `os validate`.
5555
- A param's `helpText`, like `description`, is a sentence or an inline locale map (`{ en: 'Why {{ record.name }} is paused', 'zh-CN': '暂停原因' }`); the map is how a page button's inline `action` (no bundle reaches it) writes its hint per locale.
5656
- `undoable: true` — an **Undo** in the success toast (and `Ctrl+Z`). Snapshot: runtime on `operation: 'update'`, console on `type: 'api'`; else refused.
57-
- A list view's `bulkActions: ['<name>']` runs the action once per ticked row. A body that writes each selected row takes that form: declare `execution: 'perRecord'` and write the row it is handed (`ctx.record`, `ctx.recordId`; `crm_create_campaign` below); a row whose run throws is listed with its message. A `bulkActionDefs` entry `{ name, operation: 'custom', execution: 'aggregate' }` runs it once for the selection. A script body or a flow receives the ids under the built-in key `params._selectedIds` (`input._selectedIds`), at most 5000 and only ids the caller can read: one the caller cannot read refuses the whole call (`404 RECORD_NOT_FOUND`) before it starts. A throw is one outcome for the selection; a return value's top-level `succeeded` or `failed` is read as a `BulkActionResult` (`@objectstack/spec/ui`), and in any other form (counts, one list) reported as unreadable.
57+
- A list view's `bulkActions: ['<name>']` runs it once per ticked row. A body that writes each selected row takes that form: declare `execution: 'perRecord'` and write the row it is handed (`ctx.record`, `ctx.recordId`; `crm_create_campaign` below); a row whose run throws is listed with its message. A `bulkActionDefs` entry `{ name, operation: 'custom', execution: 'aggregate' }` runs it once for the selection. A script body or a flow receives the ids under the built-in key `params._selectedIds` (`input._selectedIds`), at most 5000 and only ids the caller can read: one the caller cannot read refuses the whole call (`404 RECORD_NOT_FOUND`) before it starts. A throw is one outcome for the selection; a return value's top-level `succeeded` or `failed` is read as a `BulkActionResult` (`@objectstack/spec/ui`), and in any other form (counts, one list) reported as unreadable.
5858

5959
<!-- os:check -->
6060
```typescript
@@ -129,7 +129,7 @@ export const AddToCampaignAction = defineAction({
129129

130130
### Action body context (`ctx`)
131131

132-
A server-side `body` (or a registered `handler`) receives `ctx` with `input` (the dialog params), `record` (the target row, when a
132+
A server-side `body` or registered `handler` receives `ctx` with `input` (the dialog params), `record` (the target row when a
133133
`recordId` is in scope), `api` (scoped cross-object CRUD) and the caller. Read
134134
the active organization as `ctx.user?.organizationId ?? ctx.session?.organizationId`
135135
(as in hooks, objectstack-data).
@@ -141,12 +141,13 @@ Bodies execute **trusted** (`ctx.api` /
141141

142142
`throw new Error('…')` answers every caller in the author's language. A `type: 'script'` action
143143
with a `js` body (an inline `target` function is lowered to one; any other action is refused the
144-
key) declares `refusals` and throws the code, as `crm_add_invoice_line` below does: the catalogue,
144+
key) declares `refusals` and throws the code, as `crm_add_invoice_line` below: the catalogue,
145145
throws and checks are a hook's (objectstack-data → Lifecycle Hooks → Declared refusals). The
146146
sentence is answered as `userMessage`, translated at
147147
`objects.<object>._actions.<action>.refusals.<CODE>.message` (objectstack-i18n); the console's
148-
failure toast shows it unless the action authors `errorMessage`. A body may throw a hook's
149-
`reasons` list too (rules there): one line per reason.
148+
failure toast shows it unless the action sets `errorMessage`. For several reasons throw
149+
`reasons: [{ reason, params? }, …]`, not `reason`: `userMessage` is one line per reason, closed
150+
by the code's `message` (rules there).
150151

151152
### Writing in the organization's language (`texts`)
152153

@@ -164,7 +165,7 @@ rejects. An undeclared key is refused at save when named literally, else at run.
164165

165166
A **static** `target` URL on a `type: 'url'` action: `openIn: 'self'` forces
166167
in-place navigation; omitted, absolute URLs open in a new tab and relative ones
167-
navigate in place.
168+
in place.
168169

169170
<!-- os:check -->
170171
```typescript
@@ -187,7 +188,7 @@ A redirect URL **computed after a fetch**: `opensInNewTab:
187188
true` pre-opens the tab synchronously on click (no popup blocker), then navigates
188189
it to the handler's `redirectUrl`. `newTabUrl` skips the round-trip — a backend
189190
path starting with `/` (an external URL is refused, use
190-
`openIn`), valid only with `opensInNewTab: true`; the endpoint enforces its own
191+
`openIn`), only with `opensInNewTab: true`; the endpoint enforces its own
191192
auth (the tab carries no in-app session).
192193

193194
<!-- os:check -->
@@ -260,7 +261,7 @@ export const AddInvoiceLineAction = defineAction({
260261

261262
Lines also written past the action (API, an agent, an import — one with
262263
automations off skips hooks) get the price from a `beforeInsert` hook on the
263-
line instead (objectstack-data → Lifecycle Hooks), `runAs: 'system'` when the
264+
line (objectstack-data → Lifecycle Hooks), `runAs: 'system'` when the
264265
writer cannot read it.
265266

266-
> Set `refreshAfter: true` whenever the action mutates the current record.
267+
> Set `refreshAfter: true` when the action mutates the current record.

0 commit comments

Comments
 (0)