Skip to content

Commit b8456eb

Browse files
docs(skills): a line-add action sets the price; a self-tied create gets a current_user default (#34019)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9Ty2ru1KHBywrksCX6GQE13)_ Fixes #33978 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:两条搭建教学。① 界面技能 actions.md:「给父记录加明细行」的动作必须设置单价(从产品读价,或在角色可定价时设为必填参数),附一个可类型检查的示例;② 数据技能 security.md:插入策略的 `check` 绑定当前用户的字段时,给该字段设 `defaultValue: 'current_user'`,用户只说「加一个任务」也能建成。各配一条评测用例。 - 为什么改:评测里聊天写数据失败,6 次明细行金额写成空(加行动作没有价格),14 次建任务 403(策略要求用户没说的负责人)。维护者原话「聊天里改数据 出问题的关键还是我们的skills需要优化吧?」。 - 风险与回滚:仅技能文档、评测与 token 天花板,不改运行时;回滚即 revert。actions.md 天花板 2453→2808、security.md 3959→4041、objectstack-ui SKILL.md 3814→3833(先删重复,余额按实测提高)。 - 先看:`skills/objectstack-ui/rules/actions.md`(新段落与示例)→ `skills/objectstack-data/rules/security.md`(`own_tasks` 策略与四行说明)→ `scripts/check-skills-token-ratchet.mjs`(两行天花板与算式)。 - 两分钟验证:`node scripts/check-skills-token-ratchet.mjs`,预期 actions.md 显示 2808 / 2808、security.md 4041 / 4041,全部通过。 - 需要你做的:批准本 PR ## What changes - `skills/objectstack-ui/rules/actions.md` § Action Parameter Patterns: **An action that adds a child line sets its price.** `lookupAutofill` fills only the form and the grid, and a stored `expression` reads only its own row, so a body inserting `invoice`, `product` and `quantity` alone stores no `amount`. Read the price from the source the build declares, or take it as a `required` param where the persona sets prices. One `os:check` example (`crm_add_invoice_line`, `type: 'script'`, params `product` and `quantity` borrowed with `objectOverride: 'invoice_line'`, a body with `api.read` + `api.write` that reads `product.list_price`, throws when the product is not found, and inserts the line; `refreshAfter: true`, since the invoice's roll-up total moves). Lines also written past the action (API, an agent, an import — one with automations off skips hooks) get the price from a `beforeInsert` hook on the line, `runAs: 'system'` when the writer cannot read it. - `skills/objectstack-ui/SKILL.md` § line-item grid behaviors: one clause scoping its "never add an 'Add line' button" to the grid, pointing a record-header action that inserts a priced line to rules/actions.md, so the two do not read as contradicting each other. - `skills/objectstack-data/rules/security.md` § Row-Level Security: the example's second policy becomes the insert-only `own_tasks` (`check: 'assignee == current_user.id'`, field `task.assignee: { type: 'user', defaultValue: 'current_user' }`), followed by four lines: a `check` over a field the request never names refuses a plain create; `defaultValue: 'current_user'` fills an omitted `user` field before `check` is judged. - Homes, chosen by where a builder reads it: rule 1 where the add-line action and its params are written; rule 2 directly under the policy example, beside `check`. `relationships.md` and `field-types.md` untouched. - Paid down first (standing ruling 「A:先削重复,余额按实测提高」, record 6513306068), each cut keeping a home: - actions.md, 85 bytes: "`locations` is an array of surfaces:" (the H2 names `locations`, the table header says Surface); the `opensInNewTab` H3 tail "— async / computed redirect" (its paragraph opens "A redirect URL computed after a fetch"); ", holes in either" on the `helpText` bullet (the bullet above lists `description` and a param's `helpText` among the `{{ }}` copy holes). - security.md, 137 bytes: the `org_isolation` example policy. A select-only `using` policy is still shown twice in § Membership keys; `current_user.organization_id` keeps its placeholder-table row; the tenant predicate is the Layer 0 wall in § Platform-global objects. - Evals: `skills/objectstack-ui/evals/views-apps-actions-pages.json` case 18 (the add-line action); `skills/objectstack-data/evals/hooks-security-seeds-datasources.json` case 21 (the self-tied create; it follows case 20, which #33954 landed, byte-identical after the merge of main). Every `must_contain` appears verbatim in its `expected_output`; both `must_not_contain` lists are empty. - `scripts/check-skills-token-ratchet.mjs`: three rows moved to the measurement (actions.md, security.md, objectstack-ui SKILL.md), arithmetic in the row comments. The review-round additions (35 + 24 tokens) had no true duplicate to cut, so they rest on the ruling's second half. - `.changeset/33978-line-price-and-self-tied-create.md`: `'@objectstack/skills': patch`. - No forced test edits. ## Tests Measured on `origin/main` before writing (b8ac0e2): - `defaultValue: 'current_user'` is a runtime token on a `user` field (`packages/spec/src/data/field.zod.ts`, the `defaultValue` describe), resolved per request in `packages/objectql/src/engine-defaults-and-autonumbers.ts`. - On insert the engine applies field defaults, then `beforeInsert` hooks, and the RLS `check` judges that post-hook row (`postHookWriteImageCheck`; pinned by `packages/plugins/plugin-security/src/insert-check-post-image.test.ts`). - A CEL `defaultValue` envelope and a stored `expression` read only the row being written, so neither can read the product's price; `lookupAutofill` is client-side only. - Action bodies run elevated (`packages/runtime/src/action-execution.ts`, `isSystem: true`); hooks run as the operator unless `runAs: 'system'` (`packages/objectql/src/hook-run-as.ts`). <details><summary>Scratch proof (uncommitted vitest file on the insert-check-post-image harness, deleted after) — 5/5 passed</summary> ```text assignee: { type: 'user', defaultValue: 'current_user' } + insert check 'assignee == current_user.id' create naming no assignee -> admitted, stored assignee = the caller control: same field, no default -> PERMISSION_DENIED 403 "the insert would violate a row-level CHECK" with the default, naming another user -> still 403 the taught field parses through ObjectSchema.create invoice_line amount = record.quantity * record.unit_price quantity 3, no unit_price -> amount null (not 0) quantity 3, unit_price 20 -> amount 60 Lock VERDICT command-exit 0 · Test Files 1 passed · Tests 5 passed ``` </details> ## Acceptance notes - Not taught: the card's alternative for rule 2, "say in the field description that an agent sets it". On main the agent's object description (`describeServedObject`, `packages/runtime/src/domains/mcp.ts`) serves name, type, label, required, readonly, system, options and `defaultValue` per field, and no `description`, so that route has no measured agent consumer. It does serve `defaultValue` and tells the agent to omit the field to get it, which is the taught path. - The rule 1 example computes the price and takes no price param: the body runs elevated, so an optional override param would let a persona write a price their field grant denies. The param route stays prose ("a `required` param where the persona sets prices"). - NOT MEASURED: the example action run through the action runtime (it is type-checked; its mechanics follow the file's existing script example); a hook stamping `unit_price` for a persona whose field grant denies editing it (the text makes no claim about it). - `field-types.md`'s `lookupAutofill` paragraph still ends at "Client-side only" with no pointer to the new rule; left out to keep to two rule files. - Review round (seat at-tier review PASS at 31a2d6d, record 6897741755): N2, N3, N4 applied in one commit; N1 and N5 left as they are. - Authoring arrangement: this thread is served below the card's mandated tier, so the `skills/**` text was authored and committed by an at-tier (`CONTRACT_REVIEW_TIER`) subagent in the same worktree and branch; push, gates, relay writes and the report stay with the thread. ## Verification Token counts, `ceil(utf8 bytes / 4)`: | Scope | Before | After | |---|---|---| | `rules/actions.md` | 185 lines · 9807 B · 2452 tok (ceiling 2453) | 224 lines · 11231 B · 2808 tok (ceiling 2808, headroom 0) | | `rules/security.md` | 329 lines · 15834 B · 3959 tok (ceiling 3959) | 334 lines · 16164 B · 4041 tok (ceiling 4041, headroom 0) | | `objectstack-ui/SKILL.md` (priced bytes, stamp line excluded) | 15233 B · 3809 tok (ceiling 3814) | 15329 B · 3833 tok (ceiling 3833, headroom 0) | | all `skills/*/SKILL.md` (240e9ab vs head) | 4596 lines · 237075 B | 4597 lines · 237171 B (+1 line, +96 B) | | whole shipped `skills/` bundle (ratchet, 240e9ab vs head) | 246388 tok (authored 187806, eval 46787) | 247470 tok (authored 188268, eval 47407): +462 authored, +620 eval fixture | Local gate union at head `0d221b0` (`origin/main` 240e9ab merged in; `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`, every listed command run, exit captured before any pipe): - 65 derived · 64 exit 0 · 1 NOT MEASURED: `pnpm check:dual-build-cjs-loads` exit 3, PREREQUISITE NOT MET (reads every package's `dist/`; this worktree built only the spec, client, client-react and plugin-security closures). Declared narrowing; CI carries it. - `--ran` reconciliation: "65 derived famil(ies) accounted for — 64 run, 1 NOT-MEASURED (1 DERIVED from a recorded exit 3)". The union at the previous heads read the same (63 derived, 62 run, 1 NOT MEASURED at both `18e323b` and `31a2d6d`). - Acceptance gates at `0d221b0`, each exit 0: `pnpm --filter @objectstack/spec check:skill-docs` ("Skill docs in sync"), `check:skill-refs` ("9 generated files in sync with packages/spec"), `check:skill-examples` ("347 prose examples type-check across 3 surface(s)", after a spec rebuild), `node scripts/check-skills-token-ratchet.mjs` ("57 authored bundle file(s) within their ceilings") and `--self-test` ("104 cases pass"), `pnpm check:nul-bytes`, `git diff --check`. - Not run locally: `test:repo` (CI's `Test Core`); the diff touches no test. <!-- signed: domain:skills#2 · os-steve · session_01ADHkmQ2cXsNaBaNbjBDxsA --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 60fca0f commit b8456eb

7 files changed

Lines changed: 132 additions & 16 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/skills': patch
3+
---
4+
5+
docs(skills): an action that adds a child line sets the line's price, and a create policy tied to the caller gets a `current_user` default
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`objectstack-ui` `rules/actions.md` teaches that an action inserting a line item reads the price from the source the build declares (or takes it as a required param), because `lookupAutofill` and a stored `expression` do not fill it on a server-side insert. `objectstack-data` `rules/security.md` teaches that a `check` over a field the request never names refuses a plain create, and that `defaultValue: 'current_user'` on the tying `user` field fills it before `check` is judged. One eval case each.

‎scripts/check-skills-token-ratchet.mjs‎

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,16 @@ export const CEILINGS = new Map([
814814
// measurement, zero headroom. Authority: the ruling of record that orders this text into
815815
// the published skills, objectstack-ai/cloud#3659 letter A (ruling comment 6682024726), via
816816
// the standing 2026-10-27 ruling (record 6513306068), quoted verbatim in the PR body.
817-
// ceil(($(wc -c < skills/objectstack-ui/SKILL.md) - 20) / 4) == ceil(15256 / 4)
818-
['skills/objectstack-ui/SKILL.md', 3814],
817+
// 3814 -> 3833: one clause in the line-item grid paragraph — "never add an 'Add line'
818+
// button" is about the grid, and a record-header action that inserts a priced line is
819+
// `rules/actions.md` — so the paragraph does not read as forbidding the action that file
820+
// teaches. No passage of this file restates it or was found restating another, so nothing
821+
// is cut first; the standing ruling's second half carries the raise, verbatim and
822+
// untranslated: 「A:先削重复,余额按实测提高」 (record 6513306068). The file was 15253
823+
// bytes (15233 priced, 3809 tokens, headroom 5) -> 15349 (15329 priced) -> 3833 tokens,
824+
// the 5 absorbed, ceiling +19, pinned AT the measurement, zero headroom.
825+
// ceil(($(wc -c < skills/objectstack-ui/SKILL.md) - 20) / 4) == ceil(15329 / 4)
826+
['skills/objectstack-ui/SKILL.md', 3833],
819827
// 8333 -> 6193: RE-LOCK at the landed count after the #19715 split (decision
820828
// batch #213 item 1, maintainer 「1 2 4 同意」): the worked R1, the report
821829
// template and the v17-canonical shapes block moved VERBATIM into
@@ -1057,8 +1065,21 @@ export const CEILINGS = new Map([
10571065
// `origin/main` the file was 15056 bytes (3764 tokens, headroom 4); the
10581066
// LANDED file is 15834 bytes -> 3959 tokens, ceiling +191, pinned AT the
10591067
// measurement, zero headroom.
1060-
// ceil($(wc -c < skills/objectstack-data/rules/security.md) / 4) == ceil(15834 / 4)
1061-
['skills/objectstack-data/rules/security.md', 3959],
1068+
// 3959 -> 4041: a `check` over a field the request never names refuses a
1069+
// plain create, and the tying field's `defaultValue: 'current_user'` (a
1070+
// `user` field) fills it before `check` is judged — four lines of prose
1071+
// under the § Row-Level Security example, whose second policy becomes the
1072+
// insert-only `own_tasks` that shows it. Same standing ruling, verbatim and
1073+
// untranslated: 「A:先削重复,余额按实测提高」 (record 6513306068). PAID DOWN
1074+
// FIRST: that example's `org_isolation` policy (137 bytes) — a select-only
1075+
// policy carrying `using` alone stays shown twice in the § Membership keys
1076+
// block, `current_user.organization_id` keeps its row in the placeholder
1077+
// table, and the tenant predicate itself is the Layer 0 wall of
1078+
// § Platform-global objects. On `origin/main` the file was 15834 bytes
1079+
// (3959 tokens, headroom 0); the LANDED file is 16164 bytes -> 4041 tokens,
1080+
// ceiling +82, pinned AT the measurement, zero headroom.
1081+
// ceil($(wc -c < skills/objectstack-data/rules/security.md) / 4) == ceil(16164 / 4)
1082+
['skills/objectstack-data/rules/security.md', 4041],
10621083
// 3024 -> 3109 (2026-08-31 app-repo-principles raise, see the block above).
10631084
// Severity Levels listed the three values and left the CHOICE unstated: a
10641085
// block rests on a judgement a person made, so a machine-inferred signal — a
@@ -1142,8 +1163,28 @@ export const CEILINGS = new Map([
11421163
// URL on a `type: 'url'` action"). The file is 9028 -> 9810 bytes -> 2453 tokens, the row's 8
11431164
// bytes of headroom absorbed, ceiling +194, pinned AT the measurement. Same ruling as the lines
11441165
// above (2026-10-27, tap A): 「A:先削重复,余额按实测提高」.
1145-
// ceil($(wc -c < skills/objectstack-ui/rules/actions.md) / 4) == ceil(9810 / 4)
1146-
['skills/objectstack-ui/rules/actions.md', 2453],
1166+
// 2453 -> 2777: an action that adds a child line sets the line's price — why a
1167+
// body inserting the parent, the product and the quantity alone stores no `amount`
1168+
// (`lookupAutofill` fills only the form and the grid, a stored `expression` reads only
1169+
// its own row), one type-checked example whose body reads the product's price, the
1170+
// `required` param where the persona sets prices, and the `beforeInsert` hook for lines
1171+
// written past the action. PAID DOWN FIRST by 85 bytes of true restatement in this file:
1172+
// the sentence "`locations` is an array of surfaces:" (the H2 above it names `locations`,
1173+
// the table header right below says "Surface", every example writes the array); the
1174+
// `opensInNewTab` H3's tail "— async / computed redirect" (its paragraph opens "A redirect
1175+
// URL computed after a fetch"); ", holes in either" on the `helpText` bullet (the bullet
1176+
// above it lists `description` and a param's `helpText` among the `{{ }}` copy holes).
1177+
// The file is 9807 -> 11106 bytes -> 2777 tokens, the row's 1 token of headroom absorbed,
1178+
// ceiling +324, pinned AT the measurement. Same ruling as the lines above (2026-10-27,
1179+
// tap A): 「A:先削重复,余额按实测提高」.
1180+
// 2777 -> 2808: that example gains `refreshAfter: true` (the line moves the invoice's
1181+
// roll-up) and a guard for a product `findOne` does not return, and the closing sentence
1182+
// says an import with automations off skips the hook. Nothing further in the file restates
1183+
// another passage (the 85 bytes above were what there was), so the same ruling's second
1184+
// half carries it: the file is 11106 -> 11231 bytes -> 2808 tokens, zero headroom before,
1185+
// ceiling +31, pinned AT the measurement.
1186+
// ceil($(wc -c < skills/objectstack-ui/rules/actions.md) / 4) == ceil(11231 / 4)
1187+
['skills/objectstack-ui/rules/actions.md', 2808],
11471188
// 6090 -> 6252 (#19715, card item 4): a 5-line table of contents at the top,
11481189
// anchors to the file's existing headings, nothing else changed. +162 tokens,
11491190
// zero headroom to absorb any of it, ceiling +162. Maintainer ruling

‎skills/objectstack-data/evals/hooks-security-seeds-datasources.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@
200200
"must_contain": ["function: 'count'", "'project.task_count': { readable: false }"],
201201
"must_not_contain": ["task: { allowRead: true }"]
202202
}
203+
},
204+
{
205+
"id": 21,
206+
"prompt": "In our project tracker a contractor may create a `task` only when they are its `assignee` (a person field). A contractor asks the assistant \"Add a 'Launch checklist' task to the Website relaunch\" and the create answers 403, because the request names no assignee. Author the field and the contractor permission set's policy so the plain request succeeds, without widening whom a contractor may assign.",
207+
"expected_output": "`assignee: { type: 'user', defaultValue: 'current_user' }` on `task`, and on the contractor permission set a `rowLevelSecurity` policy with `object: 'task'`, `operation: 'insert'` and `check: 'assignee == current_user.id'`. The default fills an omitted `assignee` with the acting user before `check` is judged, so a create that names no assignee is admitted and one naming someone else is still refused. The `check` is kept as it is, not loosened or dropped.",
208+
"files": [],
209+
"assertions": {
210+
"must_contain": ["type: 'user'", "defaultValue: 'current_user'", "check: 'assignee == current_user.id'"],
211+
"must_not_contain": []
212+
}
203213
}
204214
]
205215
}

‎skills/objectstack-data/rules/security.md‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,19 @@ rowLevelSecurity: [
8585
check: 'owner_id == current_user.id',
8686
},
8787
{
88-
name: 'org_isolation',
89-
object: 'contact',
90-
operation: 'select',
91-
using: 'organization_id == current_user.organization_id',
88+
name: 'own_tasks', // task.assignee: { type: 'user', defaultValue: 'current_user' }
89+
object: 'task',
90+
operation: 'insert',
91+
check: 'assignee == current_user.id',
9292
},
9393
]
9494
```
9595

96+
A `check` over a field the request never names refuses a plain create ("add a
97+
task" answers 403). Give the tying field a default the check admits:
98+
`defaultValue: 'current_user'` fills an omitted `user` field before `check` is
99+
judged, so `own_tasks` admits a create that names no assignee.
100+
96101
Predicates are **canonical CEL** (ADR-0058): `field == current_user.<prop>`,
97102
`field == 'literal'`, `field in current_user.<array>`, comparisons (`>`/`<`/`>=`/`<=`),
98103
`&&`/`||`/`!`, and `== null` checks all lower to a pushdown filter. **No** cross-object

‎skills/objectstack-ui/SKILL.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ every behaviour is derived from the DATA MODEL — computed columns, catalog
101101
typeahead auto-fill, persisted drag-reorder, and the live Subtotal → Tax → Total
102102
stack: **objectstack-data → Relationships → Inline Editing**. Three things are
103103
authored on this side: a trailing **ghost** row always exists, so never add an
104-
"Add line" button (typing in the ghost materialises a row; an untouched one is
105-
never persisted); `autofill: false` opts one column out of the typeahead copy;
104+
"Add line" button to the grid (typing in the ghost materialises a row; an
105+
untouched one is never persisted; a record-header action that inserts a priced
106+
line is [Actions](./rules/actions.md)); `autofill: false` opts one column out of the typeahead copy;
106107
and the form's `taxRateField` overrides which parent field drives the totals.
107108

108109
**Read side — the record page.** Child relationships are related lists on the

‎skills/objectstack-ui/evals/views-apps-actions-pages.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@
170170
"must_contain": ["tabPermissions", "'hidden'", "requiredPermissions", "systemPermissions"],
171171
"must_not_contain": ["hidden: true,", "hidden: true }"]
172172
}
173+
},
174+
{
175+
"id": 18,
176+
"prompt": "Sales reps add lines to an invoice from a header button: they pick a `product` and a `quantity`. Reps can neither read nor edit a price. `invoice_line.amount` is a stored `expression` (`record.quantity * record.unit_price`), and the line's `product` lookup declares `lookupAutofill` from the product's `list_price`. Author the action.",
177+
"expected_output": "One `defineAction` (`type: 'script'`, `objectName: 'invoice'`) whose `params` are `product` and `quantity`, each borrowed with `objectOverride: 'invoice_line'`, and whose `body` (`capabilities: ['api.read', 'api.write']`) reads `ctx.api.object('product').findOne({ where: { id: input.product } })` and inserts the line with `invoice: ctx.recordId` and `unit_price: product.list_price`. `lookupAutofill` fills only the form and the grid, and the stored expression reads only its own row, so an insert that sends no `unit_price` stores no `amount`. The body runs trusted, so it reads the price the rep cannot. If lines are also written by the API, an import or an agent, a `beforeInsert` hook on `invoice_line` copies the price instead.",
178+
"files": [],
179+
"assertions": {
180+
"must_contain": ["defineAction", "ctx.api.object('product').findOne", "unit_price: product.list_price", "api.read"],
181+
"must_not_contain": []
182+
}
173183
}
174184
]
175185
}

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

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
## Where Actions Appear (`locations`)
44

5-
`locations` is an array of surfaces:
6-
75
| Value | Surface |
86
|:-----------------|:--------|
97
| `record_header` | Detail page header (single record) |
@@ -24,7 +22,7 @@
2422
- `preflight` — a read the param dialog shows above the params before submit: `{ read: { url }, path?, fields?, seed? }` sends one `GET` (no other `method`, no body or credentials) to a same-origin API path (one leading `/`) whose only holes are `${param.NAME}` (a declared param; re-read when it changes), `${ctx.recordId}` and `${ctx.record.FIELD}`. `path` selects the answer's sub-tree (`data`); `fields` rows are `resultDialog.fields`' `{ path, label?, format? }` (omitted: JSON). Each `seed: [{ param, path }]` entry fills a declared param, drawn read-only and submitted as shown: seeded once, no `defaultValue` / `defaultFromRow` / `carryOver`, read by no hole; mark it `required` so Confirm waits for the answer. Refused without a non-empty `params` and beside `execution: 'aggregate'`. UX, not authorization: the endpoint still checks a seeded value.
2523
- `successMessage` / `errorMessage` — toast copy on success / failure; without `successMessage` the UI shows a generic "Action completed" toast.
2624
- Copy holes are `{{ }}`: `confirmText`, `description` (`'Choose the new owner of {{ record.name }}.'`) and a param's `helpText` read `record`; `successMessage` and each `outcomeMessages` entry (`resent: 'Invitation resent to {{ result.email }}'`) read `result` (the handler's answer) 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`.
27-
- A param's `helpText`, like `description`, is a sentence or an inline locale map (`{ en: 'Why {{ record.name }} is paused', 'zh-CN': '暂停原因' }`), holes in either; the map is how a page button's inline `action` (no bundle reaches it) writes its hint per locale.
25+
- 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.
2826
- `undoable: true` — an **Undo** in the success toast (and `Ctrl+Z`). Snapshot: runtime on `operation: 'update'`, console on `type: 'api'`; else refused.
2927

3028
<!-- os:check -->
@@ -142,7 +140,7 @@ export const PrintA3Action = defineAction({
142140
});
143141
```
144142

145-
### `opensInNewTab` + `newTabUrl` — async / computed redirect (SSO)
143+
### `opensInNewTab` + `newTabUrl` (SSO)
146144

147145
A redirect URL **computed after a fetch**: `opensInNewTab:
148146
true` pre-opens the tab synchronously on click (no popup blocker), then navigates
@@ -182,4 +180,45 @@ that overrides `type` names its own `widget`);
182180
`objectOverride` borrows a field of another object, and `defaultFromRow: true`
183181
pre-fills from the selected row in `list_item` contexts.
184182

183+
**An action that adds a child line sets its price.** `lookupAutofill` fills only
184+
the form and the grid, and a stored `expression` reads only its own row, so a
185+
body inserting `invoice`, `product` and `quantity` alone stores no `amount`. Read
186+
the price from the source the build declares, or take it as a `required` param
187+
where the persona sets prices:
188+
189+
<!-- os:check -->
190+
```typescript
191+
import { defineAction } from '@objectstack/spec/ui';
192+
193+
export const AddInvoiceLineAction = defineAction({
194+
name: 'crm_add_invoice_line',
195+
label: 'Add Line',
196+
objectName: 'invoice',
197+
type: 'script',
198+
locations: ['record_header'],
199+
params: [
200+
{ field: 'product', objectOverride: 'invoice_line', required: true },
201+
{ field: 'quantity', objectOverride: 'invoice_line', required: true },
202+
],
203+
body: {
204+
language: 'js',
205+
source: `
206+
const product = await ctx.api.object('product').findOne({ where: { id: input.product } });
207+
if (!product) throw new Error('Product not found.');
208+
await ctx.api.object('invoice_line').insert({
209+
invoice: ctx.recordId, product: input.product, quantity: input.quantity,
210+
unit_price: product.list_price,
211+
});
212+
`,
213+
capabilities: ['api.read', 'api.write'],
214+
},
215+
refreshAfter: true,
216+
});
217+
```
218+
219+
Lines also written past the action (API, an agent, an import — one with
220+
automations off skips hooks) get the price from a `beforeInsert` hook on the
221+
line instead (objectstack-data → Lifecycle Hooks), `runAs: 'system'` when the
222+
writer cannot read it.
223+
185224
> Set `refreshAfter: true` whenever the action mutates the current record.

0 commit comments

Comments
 (0)