Skip to content

Commit f2ca884

Browse files
docs(skills): teach the grouping fields a grid refuses, the ungranted hook body call and updateById under api.write (#39031)
Part of #38655 Clause-②: no Metadata-protocol: none This PR lands the two pages that fit their token ceilings and the first `actions.md` item. Two `actions.md` items stay open on the card, because that file has no restatement left to pay for them: `action-body-capability-undeclared`, and the identity-assignment write an action body is refused. Their text is written and pushed on the backup branch `claude/issue-38655-skills-save-refusals-wip` (`8b30ebeb`, no PR); see Acceptance notes. ## 维护者速读 - 用户能看到什么变化:照技能包让 AI 写应用的人,在列表分组、数据钩子和动作按钮三处,会先读到哪些写法在保存时被拒、该怎么改;此前技能包没写,要到保存被拒才知道。 - 为什么做:平台新增了三条保存期拒绝,技能包教的比平台拒的少;这是替照技能包写配置的 AI 作者补上。 - 出错会怎样:最坏是某句教学写错,AI 作者照着写出仍被拒的配置;只改文字,可直接撤回。 - 要你做什么:审阅这三页的文字改动。 ## What changes Text only, in three published skill pages. Each sentence follows the merged rule explanation in `packages/lint/src/rule-explanations/` (`list-view-field-refs.ts`, `record-writes.ts`), read at `444dce61`. - `skills/objectstack-ui/rules/list-views.md`, Grouping: on a grid (the default `type`) a grouping level's `field` is a stored single-valued field of the object. A multi-valued, JSON-stored or `formula` field is refused at validate and publish as `list-view-group-field-ungroupable` (show it as a column). Dotted grouping is on main, so the same sentence covers it: a dotted path is refused as `list-view-field-dotted` (group by the lookup itself). - `skills/objectstack-data/references/data-hooks.md`, Capabilities: a hook body call whose token is missing is refused at save as `hook-body-capability-undeclared` (an error from `os validate`, `os build`, `os lint` and a runtime save, `422 INVALID_METADATA`); add the token the message names, or remove the call. The paragraph names the spellings the rule reads, and the token table under it is the list the rule judges. Its `api.write` row now lists every write leaf the sandbox gates, `updateById(id, patch)` included. - `skills/objectstack-ui/rules/actions.md`, opening paragraph: a body writes through `ctx.api.object(X).update(...)` or `.updateById(id, patch)` under `api.write`; without the grant the write is refused at save (`action-body-write-capability-undeclared`, which the page already named). - `.changeset/38655-skills-save-refusals.md`: `@objectstack/skills` patch, with the list of what was deleted to pay for each addition. Skills size, both readings (tokens are the ratchet's own count): | File | Lines before | Lines after | Bytes before | Bytes after | Tokens before | Tokens after | |:--|--:|--:|--:|--:|--:|--:| | `rules/list-views.md` | 407 | 409 | 18035 | 18035 | 4509 | 4509 | | `rules/actions.md` | 271 | 270 | 15669 | 15669 | 3918 | 3918 | | `references/data-hooks.md` | 851 | 847 | 40480 | 40477 | 10120 | 10120 | | Every `SKILL.md`, summed | 2144 | 2144 | | | | | | Every `.md` under `skills/` | 17093 | 17090 | | | | | | Ratcheted bundle | | | | | 182270 | 182270 | No ceiling row moves. Each addition is paid for by deletion in its own file; the changeset lists every cut. Read first, by risk: 1. `skills/objectstack-data/references/data-hooks.md`, the Capabilities hunk: the reworded paragraph is the one place an existing sentence changed meaning order (the save refusal now comes before the sandbox throw). The cuts in this file are the "What Are Hooks?" heading with its one sentence, and the Status row of the `body` / `handler` table. 2. `skills/objectstack-ui/rules/list-views.md`, the Grouping hunk, then the `userFilters` hunk: it drops "and the `validate` list-view-mode lint reports it" after the parse rejection. 3. `skills/objectstack-ui/rules/actions.md`, the new-tab warning: it no longer names the `ActionParam[]` type. Two-minute verification: `node scripts/check-skills-token-ratchet.mjs` prints the three files at `4509`, `10120` and `3918` tokens with headroom 0 and ends on its `✓` line. ## Tests No package source changes, so no package test or typecheck is owed. No behaviour a test pins changed, so no ablation. ## Acceptance notes - Held, not in this PR: the two remaining `actions.md` items. With them the file measures 16206 bytes, 4052 tokens, against a ceiling of 3918 (+134), after the one cut the file offers. The ratchet's earlier notes on this row say the same ("Nothing else in the file restates another passage"). Moving the row is outside this card's claimed file surface, so the text waits on the backup branch named above. - `data-hooks.md`: the method table under "the cross-object repo" still lists `update` and not `updateById`; the `api.write` token row now names it. Not widened here. - `check:closed-ceremony-text` crashes locally in its self-test with `spawnSync git ENOBUFS` (the tracked-file listing overflows the default buffer in this container). Not measured locally; CI reads it. ## Verification Local run at `e284151c`, the derived list of `node scripts/pm/dispatch-gates.mjs --commands` (51 commands). <details><summary>Gate readings</summary> - Exit 0 (46 of 51): `check-skills-token-ratchet` and its self-test, `check:skill-refs`, `check:skill-served-sections`, `check:skill-links`, `check:skill-identifier-liveness`, `check:skill-compatibility`, `check:skill-frame-sync`, `check:doc-authoring`, `check:doc-formula-expressions` (after building its closure), `check:pm-skill-id-lint`, `check:role-word`, `check:nul-bytes`, `check:published-files`, `check-empty-changeset`, `check-changeset-no-major`, `check-adr-0087-registration`, `check:changeset-gate-self-tests`, `check-comment-mask-corpus` (24733 files, 0 disagree; a second run with a longer limit after the first timed out), and the remaining whole-tree and self-test commands on the list. - NOT MEASURED, prerequisite not met (exit 3, no full build in this worktree): `check:dts-closure`, `check:dual-build-cjs-loads`, `check:lean-entry-closure`, `check:sourcemap-no-sources-content`. Reason: they read built output of every package; this diff touches no package. CI runs them. - NOT MEASURED: `check:closed-ceremony-text` (the crash above), and `check:skill-examples` (outside the derived list; needs the client SDK built; no checked example block changed). </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzhKEbEnW8pwZRgK2gJ)_ <!-- signed: repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhKEbEnW8pwZRgK2gJ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4a3b532 commit f2ca884

4 files changed

Lines changed: 60 additions & 41 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
'@objectstack/skills': patch
3+
---
4+
5+
docs(skills): the published skills teach three refusals the save door makes: a grid grouping field the engine does not group by, a hook body call without its capability token, and `updateById` under `api.write`
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Text only: no schema, rule or runtime behaviour changes here. Each sentence follows the rule's own explanation (`os explain RULE`).
11+
12+
`skills/objectstack-ui/rules/list-views.md`, Grouping: on a grid (the default `type`) a grouping level's `field` is a stored single-valued field of the object. A multi-valued field (`multiselect`, `checkboxes`, `tags`, `multiple: true`), a JSON-stored one (`json`, `address` and the like) or a `formula` field is refused at validate and publish as `list-view-group-field-ungroupable`; the fix is to show the field as a column. A dotted path (`account.name`) is refused as `list-view-field-dotted`; the fix is to group by the lookup itself.
13+
14+
`skills/objectstack-data/references/data-hooks.md`, Capabilities: a hook body call whose token is missing from `body.capabilities` is refused at save as `hook-body-capability-undeclared`, an error from `os validate`, `os build`, `os lint` and a runtime save (`422 INVALID_METADATA`); the fix is to add the token the message names, or remove the call. The paragraph says which spellings the rule reads (a call on `ctx`, on a local bound once to it, on a handle bound once to `.object(…)`) and that a call spelled another way still throws in the sandbox. The `api.write` row lists every write leaf the sandbox gates: `insert`, `update`, `updateById(id, patch)`, `delete`, `updateMany`, `deleteMany`, `upsert`.
15+
16+
`skills/objectstack-ui/rules/actions.md`, opening paragraph: an action body writes through `ctx.api.object(X).update(...)` or `.updateById(id, patch)`, both under `api.write`, and without that grant the write is refused at save (`action-body-write-capability-undeclared`).
17+
18+
No file grows: each addition is paid for by deletion in its own file, so the three token counts stay 4509, 10120 and 3918.
19+
20+
- `list-views.md`: the view-switcher consequence of a bare flat view object; the lead-in sentence of Data Source; two words of each Columns comment; "still ANDed with the elements beside it" (the paragraph opens with "elements must all match"); the `userFilters` lead-in's list of elements (the block under it names them); the comment over `appearance`; that the list-view-mode lint also reports a `tabs` element the parse rejects; the second pointer to objectstack-data Search Fields and to Inline Editing (each is named a few lines above); "you almost never need a custom page" (item 2 says when a page is used).
21+
- `data-hooks.md`: the "Reference companion" line under the contents list; the "What Are Hooks?" heading and its one sentence (the two tables under it say when a hook runs); the Status row of the `body` / `handler` table (its header marks `handler` deprecated); a comment in the `input` example; "the layout both real hook modules in the repo use".
22+
- `actions.md`: the new-tab warning no longer names the `ActionParam[]` type, and keeps "user input only".

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,13 @@
66
- [Hook Context API](#hook-context-api) · [Common Patterns](#common-patterns) · [Registration Methods](#registration-methods)
77
- [Best Practices](#best-practices) · [Error Handling](#error-handling) · [References](#references)
88

9-
Reference companion to `objectstack-data/SKILL.md`, and the catalog's anchor for
10-
data hooks.
119
`check:skill-examples` skips the unmarked blocks: fragments, shapes, and pattern 4's bare `any`.
1210

1311

1412
---
1513

1614
## Core Concepts
1715

18-
### What Are Hooks?
19-
20-
Hooks are **event handlers** in the ObjectQL data access lifecycle, run before or
21-
after an operation — see [Before vs After](#before-vs-after-hooks).
22-
2316
### Hook Lifecycle Events
2417

2518
| Event | When It Fires | Use Cases |
@@ -188,7 +181,6 @@ CEL has no overload for does **not** degrade to "the hook did not fire" — it
188181
|:--|:--|:--|
189182
| Shape | `body: { language, source, capabilities }` (pure metadata) | `handler: async (ctx) => { … }` |
190183
| Runs in | An isolated **QuickJS VM** (edge-safe, capability-gated) | The host process (**full Node**) |
191-
| Status | **Preferred for new code** | **Deprecated** (`HookSchema`: *"prefer `body`"*) |
192184
| Both present? | Runtime uses **`body`** and ignores `handler` | — |
193185

194186
### The `body` shape
@@ -287,15 +279,21 @@ An unpredicated `find` / `count` is fine: every row is an honest answer.
287279

288280
### Capabilities — the complete list
289281

290-
A body may only touch a `ctx` API it declared in `capabilities`. Calling an
291-
undeclared one **throws inside the VM** — `capability '<token>' not granted to
292-
hook '<name>' …` — which surfaces as a hook error (see Troubleshooting). The legal
293-
tokens (`HookBodyCapability`) are exactly seven:
282+
A body may only touch a `ctx` API it declared in `capabilities`. A call in the
283+
table below whose token is missing is refused at save
284+
(`hook-body-capability-undeclared`: an **error** from `os validate`,
285+
`os build`, `os lint` and a runtime save, `422 INVALID_METADATA`): add the
286+
token the message names, or remove the call. The rule reads a call on `ctx`,
287+
on a local bound once to it (`const log = ctx.log`) or on a handle bound once
288+
to `.object(…)`; one spelled another way **throws inside the VM** —
289+
`capability '<token>' not granted to hook '<name>' …` — which surfaces as a
290+
hook error (see Troubleshooting). The legal tokens (`HookBodyCapability`) are
291+
exactly seven:
294292

295293
| Token | Unlocks |
296294
|:--|:--|
297295
| `api.read` | `ctx.api.object(n).find` / `findOne` / `count` / `aggregate`; also `ctx.title('<lookup field>')`. |
298-
| `api.write` | `ctx.api.object(n).insert` / `update` / `delete` |
296+
| `api.write` | `ctx.api.object(n).insert` / `update` / `updateById(id, patch)` / `delete` / `updateMany` / `deleteMany` / `upsert` |
299297
| `api.transaction` | `ctx.api.transaction(async () => { … })` — runs the callback's `ctx.api` ops in **one transaction on the default datasource**: commit on return, rollback on throw. A write in it to an object on another datasource is refused before it runs (`400 ERR_CROSS_DATASOURCE_TRANSACTION_WRITE`), except an append-only ledger (`lifecycle.class` `audit` / `telemetry` / `event`), written outside the unit and surviving its rollback. Inside a unit already open (the hook's write's, a caller's, or one an action body opened with `ctx.api.transaction`) it **joins** that unit: its return is no commit and its throw no rollback; the outer unit commits or rolls back all of it, so a throw the body catches keeps the callback's writes. Hooks of a write made inside a body's transaction run in that unit, and their `ctx.api` writes and own `ctx.api.transaction` join it. One level per body: a nested call is refused ("nested ctx.api.transaction is not supported"). On PostgreSQL and a MongoDB replica set a failed statement aborts the whole unit, even when caught. A driver with no transactions runs the callback with none and no warning: each write is stored as made, and a throw undoes none. Pair it with `api.write`. |
300298
| `crypto.uuid` | `ctx.crypto.randomUUID()` |
301299
| `log` | `ctx.log.debug` / `info` / `warn` / `error(msg, data?)` |
@@ -479,7 +477,6 @@ const org = ctx.user?.organizationId ?? ctx.session?.organizationId;
479477
```typescript
480478
// beforeInsert, afterInsert
481479
{
482-
// All field values being inserted
483480
name: 'Acme Corp',
484481
industry: 'Technology',
485482
...
@@ -729,8 +726,7 @@ ctx.ql.registerHook('beforeInsert', async (hookCtx) => { /* ... */ },
729726
```
730727

731728
**3. Hook files — `src/objects/{object}.hook.ts`.** One `defineHook({ ... })` per
732-
file, default-exported, then listed in the stack's `hooks` array (method 1). This is
733-
the layout both real hook modules in the repo use.
729+
file, default-exported, then listed in the stack's `hooks` array (method 1).
734730

735731
---
736732

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ is refused at validate and publish (`action-no-object-binding`; set it, or
99
`locations: []` if headless). With neither `locations` nor a view naming it in
1010
`rowActions` / `bulkActionDefs` it renders nowhere (`action-no-placement`). A body
1111
that returns or assigns values writes nothing
12-
(`action-record-write-discarded`): it calls `ctx.api.object(...).update(...)`
13-
in `language: 'js'` (an `expression` body has no I/O) with
14-
`capabilities: ['api.write']`; without that grant, a write is refused too
15-
(`action-body-write-capability-undeclared`).
12+
(`action-record-write-discarded`): it calls `ctx.api.object(X).update(...)`
13+
or `.updateById(id, patch)` in `language: 'js'` (an `expression` body has no
14+
I/O) with `capabilities: ['api.write']`; without it, a write is refused at
15+
save (`action-body-write-capability-undeclared`).
1616

1717
## Where Actions Appear (`locations`)
1818

@@ -213,9 +213,8 @@ export const OpenInvoicePdfAction = defineAction({
213213

214214
> A printable document (an invoice) is a page that declares `print` — [Print pages](./pages.md#print-pages).
215215
216-
> ⚠️ **Never express new-tab behavior via `params`** — it is `ActionParam[]` for
217-
> **user input** only: `params: [{ name: 'newTab', type: 'checkbox' }]` draws a
218-
> checkbox.
216+
> ⚠️ **Never express new-tab behavior via `params`**, which is **user input**
217+
> only: `params: [{ name: 'newTab', type: 'checkbox' }]` draws a checkbox.
219218
220219
## Action Parameter Patterns
221220

‎skills/objectstack-ui/rules/list-views.md‎

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ export const CaseViews = defineView({
3131
```
3232

3333
> **Never export a bare flat view object** (`{ name, label, type, columns }`
34-
> at top level): nothing registers and no view appears in the switcher.
34+
> at top level): nothing registers.
3535
3636
### Data Source (`data`)
3737

38-
Every view connects to data via one of two providers:
38+
Two providers:
3939

4040
```typescript
4141
data: { provider: 'object', object: 'support_case' }
@@ -48,10 +48,10 @@ data: { provider: 'value', items: [...] }
4848
### Columns
4949

5050
```typescript
51-
// Simple — field names only
51+
// Field names only
5252
columns: ['subject', 'status', 'priority', 'owner_id', 'due_date']
5353

54-
// Enhanced — full control
54+
// Per-column settings
5555
columns: [
5656
{ field: 'subject', link: true, width: 300 },
5757
{ field: 'status', width: 120, align: 'center' },
@@ -92,7 +92,7 @@ by nature — a log, an audit trail, a history, a report roll-up — declares
9292

9393
`filter` is a list whose elements must **all** match. An element is a rule
9494
`{ field, operator, value }` or an any-of group `{ or: [rule, ...] }` that
95-
matches when **any** of its rules does — still ANDed with the elements beside it:
95+
matches when **any** of its rules does:
9696

9797
```typescript
9898
filter: [
@@ -117,9 +117,8 @@ it read-only.
117117

118118
### End-User Quick Filters (`userFilters`, ADR-0047)
119119

120-
`filter` is the always-on base criteria. For the *end-user-facing* filter bar
121-
use `userFilters` — dropdowns, filter tabs, or
122-
toggles the user combines at runtime:
120+
`filter` is the always-on base criteria; `userFilters` is the filter bar the
121+
user combines at runtime:
123122

124123
```typescript
125124
userFilters: {
@@ -130,7 +129,6 @@ userFilters: {
130129
],
131130
},
132131

133-
// Runtime visualization whitelist:
134132
appearance: { allowedVisualizations: ['grid', 'kanban', 'gallery'] }, // one entry = locked, no switcher
135133
```
136134

@@ -142,9 +140,8 @@ Rules:
142140
entry, rendered as a tab in the object's saved-view switcher.
143141
- **On an object list view (`*.view.ts` `list` / `listViews`), only
144142
`element: 'dropdown'` (value chips) is allowed — `tabs` is page-only**
145-
(ADR-0047 amendment): the saved-view switcher already owns the tab bar, so
146-
`ObjectUserFiltersSchema` **rejects** `tabs` at parse (not dropped) and the
147-
`validate` list-view-mode lint reports it.
143+
(ADR-0047 amendment): the saved-view switcher owns the tab bar, so
144+
`ObjectUserFiltersSchema` **rejects** `tabs` at parse (not dropped).
148145
- **Omit `userFilters` when unsure — omission means a clean toolbar.** Nothing
149146
is auto-derived.
150147
- `userFilters: { element: 'dropdown' }` (no `fields`) is valid shorthand:
@@ -198,12 +195,12 @@ ingress gate refuses any entry outside the allowed set before the engine runs.
198195
| a renamed / mistyped column, or a dotted path (`account_id.name`) | `searchable-field-unknown` | `400 INVALID_FIELD` |
199196
| a real column outside the allowed set, or a virtual `formula` column | `searchable-field-unsearchable` | `400 INVALID_FIELD` |
200197

201-
Both diagnostics are **errors**: `os validate` fails the build.
198+
Both are **errors**: `os validate` fails.
202199

203200
To remove the search box instead: `userActions: { search: false }` on the list.
204201

205202
**Searching by a related record's title:** mirror it into a **stored** field
206-
and narrow to that (objectstack-data → Search Fields).
203+
and narrow to that.
207204

208205
### Sorting
209206

@@ -221,7 +218,13 @@ sort: [
221218
option order (declare stages in pipeline order); others sort by label.
222219
`orderBy` orders a level's groups by a number, date or boolean field of the
223220
same object instead — text or a select is refused
224-
(`list-view-group-order-unorderable`):
221+
(`list-view-group-order-unorderable`). On a grid (the default `type`) a
222+
level's `field` is a stored single-valued field of the object: a
223+
multi-valued (`multiselect`, `checkboxes`, `tags`, `multiple: true`),
224+
JSON-stored (`json`, `address`, …) or `formula` field is refused at validate and
225+
publish (`list-view-group-field-ungroupable`; show it as a column),
226+
and so is a dotted path (`account.name`: `list-view-field-dotted`; group by
227+
the lookup `account` itself):
225228

226229
```typescript
227230
grouping: { fields: [
@@ -380,8 +383,7 @@ export const WebToLead = defineForm({
380383
## Master-Detail Forms (parent + child line items)
381384

382385
To let users enter a record **together with its child line items** (invoice +
383-
lines, project + tasks) and save them **atomically**, you almost never need a
384-
custom page. Prefer, in order:
386+
lines, project + tasks) and save them **atomically**, prefer, in order:
385387

386388
1. **A parent field group naming the child (zero view config).** In the DATA
387389
MODEL, the parent declares `fieldGroups: [{ key: 'lines', label: 'Lines',
@@ -399,7 +401,7 @@ custom page. Prefer, in order:
399401
**Line-item grid behaviors (`grid` mode).** Every behaviour of the editable
400402
grid is derived from the DATA MODEL — computed columns, catalog
401403
typeahead auto-fill, persisted drag-reorder, and the live Subtotal → Tax → Total
402-
stack: **objectstack-data → Relationships → Inline Editing**. Three things are
404+
stack (Inline Editing, above). Three things are
403405
authored on this side: a trailing **ghost** row always exists, so never add an
404406
"Add line" button to the grid (typing in the ghost materialises a row; an
405407
untouched one is never persisted; a record-header action that inserts a priced

0 commit comments

Comments
 (0)