Skip to content

Commit fea0712

Browse files
docs(skills): teach a validation rule message's {{ }} holes (#38787)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9SNzk6FfxPPrxLwCB5BftuN)_ Part of #37909 — PR 3 of the ruling's sequencing (skills and docs), claim amendment 5 (7279412658). PR 1 (#38687, merged as 9cbb41b) is the doors; PR 2 (#38736, merged as 49c09ed) is the render. This PR teaches what the merged tree does. Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:没有运行时变化;技能 objectstack-data 与文档「Validation metadata」页开始教规则提示语里的 `{{ record.字段 }}` 占位、格式化器、币种规则(你选的 A)、看不到的字段留空、译文先填、提示语是纯文本。 - 为什么做:维护者已裁(P3);前两步已合入,这是第三步,让写元数据的 AI 和人知道怎么写、写了会显示什么。 - 出错会怎样:最坏是教错一句,AI 写出的提示语被发布校验拒(会点名正确写法)或某个占位显示为空;不影响任何保存是否被拒。 - 要你做什么:skills 是受管面,请 os-zhuang 审批;ratchet 行按「A:先削重复,余额按实测提高」抬了 235 个 token(先删了 699 字节重复)。 ## What changes Ruling P3 (card comment 7239726323), the currency ruling A (7277046538), and the items PR 1's and PR 2's contract records left to this PR. - **`skills/objectstack-data/rules/validation.md`** gains § Messages — Record Values in Holes: the `record` / `previous` roots (`previous` empty on insert), one segment, own fields; the formatter whitelist with `| currency:EUR`; what the doors refuse (a single brace, a read through a field, another root, logic); a bare `| currency` in the organization's default currency, and with none set that hole empty while the server log names the setting (ruling A); a field holding its own currency names the code or uses `| number:2` (PR 2 contract record, E2); a field the person whose write was refused cannot read, or sees masked, renders empty, `default:` included; the translation takes the same holes and is filled first; the sentence is plain text (PR 2 contract record: "PR 3's docs should say the sentence is text"). - **`content/docs/data-modeling/validation.mdx`** — the `message` row of Common Properties points at a new § Messages with a worked example, the two roots, the formatter table, currency, the field floor (including writes an automation makes on someone's behalf, and a person-less system write), translations and plain text. - **`content/docs/ui/translations.mdx`** — the one bullet that said a validation message is "substituted whole — there is no interpolation … `{variable}` placeholders in it are not filled", false since PR 2, now says a translation fills the same `{{ }}` holes, translation first, the fallback, and that a single brace is refused at publish. - **`packages/spec/src/migrations/entries/semantic/19.validation-rule-message-template-holes.ts`** — PR 1's contract record N3: the example renamed the field between FROM (`{received}`) and TO (`record.received_amount`); FROM now reads `{received_amount}`. One word; nothing else in the entry moves. ### Token ratchet (`scripts/check-skills-token-ratchet.mjs`) `skills/objectstack-data/rules/validation.md` had no headroom (3862 / 3862). Paid down first inside the file: § Incorrect vs Correct and its table-of-contents entry are deleted, since its one example (a rule with no `events` runs on insert and update; scope it with `events: ['update']`) restates § Events, which stays. -699 bytes cut, +1638 added: 15448 -> 16387 bytes (+939) -> `ceil(16387 / 4)` = 4097 tokens; the row moves 3862 -> 4097, the measured remainder, pinned at the measurement. Raise path: the standing maintainer ruling 2026-10-27 「A:先削重复,余额按实测提高」 (ruling record 6513306068). `SKILL.md` gains no byte. No other row moves. ### Outside the original claimed file surface The seat widened the surface by its relay of 2026-11-30T13:21Z: `content/docs/ui/translations.mdx` (that one bullet), the ratchet row, the `.changeset` note, and the one word in the semantic entry. ## Acceptance notes - Read before writing: the merged `rule-message-render.ts`, `engine-rule-message-rendering.ts`, the formula `templateEngine` formatters (`TEMPLATE_FORMATTERS`, `splitHoleFormatter`) and `ExecutionContext.timezone`. - Plain text: no console error or toast renderer in `ui/packages` puts a message through `dangerouslySetInnerHTML` (the files that use it are page HTML, rich text, charts, markdown and code blocks). `@object-ui/core`'s deprecated `ObjectValidationEngine` was not audited (PR 2 contract record, outside the diff). - Out of scope: PR 1's N4 (private copies of the hole grammar, a code dedupe) and PR 2's N3 (`packages/lint/src/seed-row-refusals.ts` prints blank holes), as the seat agreed; PR 2's N2 and N7 stand as recorded; N8 is #38759. - No eval case: the file surface holds no eval file. ## Verification Head `17319d01f6c6dfc2eb9b7c9ef0daebf764eed391`, on main `49c09ed902`. - Full build: `bash scripts/pm/os-verify-lock.sh -c 'pnpm build --concurrency=2'` → VERDICT command-exit 0 (123/123 tasks). - Derived gates (`node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`, re-derived after the last commit, same 133): each run with stdin closed, recorded `cmd :: exit N`. All 133 exit 0. - First round on `995a1318c6`: 132 green, `pnpm check:skill-links` red — the table-of-contents link `#messages--record-values-in-holes` did not match the heading, whose code span slugs to `messages--record-values-in---holes`. Root fix in `17319d01f6`: the heading drops the code span (its body shows the holes), the link now resolves, and the ratchet row is pinned at the new measurement (4097). The 15 skills / changeset / ratchet gates were re-run on the new head, all exit 0; no other file changed. - `node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ran=FILE` → 133 derived, 133 run, 0 NOT-MEASURED, 0 UNRUN. - `node scripts/check-skills-token-ratchet.mjs` and `--self-test` → exit 0; `node scripts/check-skill-links.mjs` → 290 links, 161 fragments resolve. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmQ6vV3YvhJWKF1gSDs <!-- signed: repo:objectstack@os-steve · os-steve · session_01ADHkmQ6vV3YvhJWKF1gSDs --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0346b57 commit fea0712

6 files changed

Lines changed: 109 additions & 37 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@objectstack/skills': patch
3+
'@objectstack/spec': patch
4+
---
5+
6+
docs(skills): the objectstack-data validation rules teach a rule message's `{{ }}` holes
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
`skills/objectstack-data/rules/validation.md` gains § Messages — Record Values in Holes, teaching what the refusal sentence does since validation rule messages were rendered at run time: a hole names one of the object's own fields under `record` (the judged record) or `previous` (the stored row before an update, empty on insert), with at most one whitelisted formatter; a bare `| currency` formats in the organization's default currency, and with none set that hole renders empty while the server log names the setting (Setup → Localization); a field holding its own currency names the code (`| currency:EUR`) or uses `| number:2`; a field the person whose write was refused cannot read, or sees masked, renders empty, `default:` included; a translation at `objects.<object>._validations.<rule>.message` takes the same holes and is filled first; the sentence is plain text.
12+
13+
§ Incorrect vs Correct is gone: its one example (a rule with no `events` runs on insert and update; scope it with `events: ['update']`) restated § Events.
14+
15+
The upgrade entry `validation-rule-message-template-holes` (`@objectstack/spec`) names the same field before and after in its example: `Total {total_price} is below {received_amount}` becomes `Total {{ record.total_price | currency }} is below {{ record.received_amount | currency }}`.

‎content/docs/data-modeling/validation.mdx‎

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ All validation types share these base properties:
7474
| `description` | `string` | optional | Developer documentation |
7575
| `active` | `boolean` | optional | Is the rule active (default: `true`) |
7676
| `severity` | `enum` | optional | `'error'` (blocks save), `'warning'`, `'info'` (default: `'error'`) |
77-
| `message` | `string` | ✅ | User-facing error message |
77+
| `message` | `string` | ✅ | The sentence a refused write returns to the person; may show the record's values in `{{ }}` holes ([Messages](#messages)) |
7878
| `events` | `enum[]` | optional | When to run: `'insert'`, `'update'` (default: `['insert', 'update']`). No `'delete'` — guard deletions with a `beforeDelete` lifecycle hook |
7979
| `priority` | `number` | optional | Execution order (0-9999, lower runs first, default: 100) |
8080
| `tags` | `string[]` | optional | Categorization tags |
@@ -300,6 +300,51 @@ Apply validation only when a condition is met:
300300

301301
The outer conditional evaluates the `when` CEL predicate, then recurses into `then` (when true) or `otherwise` (when false). The nested rule supplies the violation message; the conditional itself carries the required base `message`.
302302

303+
## Messages
304+
305+
A rule's `message` is the sentence the person who saved reads when the rule refuses the write. It is a `{{ }}` template, so it can say by how much a limit was crossed, not only that it was:
306+
307+
```typescript
308+
{
309+
name: 'payment_not_above_total',
310+
type: 'cross_field',
311+
condition: 'record.received_amount != null && record.total_price != null && record.received_amount > record.total_price',
312+
fields: ['received_amount', 'total_price'],
313+
message: 'Total {{ record.total_price | currency }} is below what was received ({{ record.received_amount | currency }}).',
314+
}
315+
```
316+
317+
A refused save then reads `Total $1,200.00 is below what was received ($1,500.00).`
318+
319+
**What a hole may name.** One of the object's own fields, one segment deep, under one of two roots:
320+
321+
| Root | Holds |
322+
| :--- | :--- |
323+
| `record` | The record the rule judged: the stored row with this write applied |
324+
| `previous` | The stored row before an update. On insert there is none, so a `previous` hole renders empty |
325+
326+
`objectstack validate`, `objectstack compile` and the publish gate refuse a single-brace token (`{total_price}`, `${total_price}`), a hole over any other root (`{{ user.name }}`), a hole that reads through a field (`{{ record.account.name }}`), a field the object does not declare, and logic in a hole. Each refusal names the spelling to use. A rule stored before these checks keeps loading and is judged at its next save.
327+
328+
**Formatters.** A hole takes at most one, after a `|`. Values are formatted in the language the refusal is negotiated in:
329+
330+
| Formatter | Renders |
331+
| :--- | :--- |
332+
| `number`, `number:2` | A grouped number, optionally with fixed decimals |
333+
| `currency`, `currency:EUR` | An amount in the organization's default currency, or in the ISO 4217 code written in capitals |
334+
| `percent`, `percent:1` | A 0–1 ratio as a percentage |
335+
| `date`, `date:long`, `date:iso` | A calendar date |
336+
| `datetime`, `datetime:long`, `datetime:iso` | An instant, in the organization's time zone, UTC when none is set (`iso` stays UTC) |
337+
| `upper`, `lower`, `trim`, `truncate:80` | Text, changed or cut with an ellipsis |
338+
| `default:'n/a'` | The text given, when the field is empty |
339+
340+
**Currency.** A bare `| currency` formats in the organization's default currency, set in Setup → Localization (`localization.currency`). When none is set, that hole renders empty, the rest of the sentence still fills, and the server log names the rule and the setting to fill. An amount is never shown in a currency nobody chose. A `currency` field that carries its own currency (a per-record or fixed currency) is still formatted in the organization's default by a bare `| currency`; name the code (`| currency:EUR`) or use `| number:2` for such a field.
341+
342+
**Fields the person cannot read stay empty.** A hole shows a value only when the person whose write was refused may read that field unmasked. A field they cannot read, a field masked for them, and a password, secret or internal field render empty, and `default:` does not fill them. The same holds when an automation writes on someone's behalf: a `runAs: 'system'` flow someone started, an action, an approval step. The sentence is worded for that person, so it shows what they may read. A system write that names no person (a schedule, a platform job) is read only in the server log, and shows every field but password, secret and internal ones. If the platform cannot tell what the person may read, every hole renders empty and the server log says why. Whether the write is refused never depends on the message.
343+
344+
**Translations.** A translated message at `objects.<object>._validations.<rule>.message` reads the same holes and is filled first. If it does not render, the authored message is filled instead and the server log names the translation.
345+
346+
**Plain text.** The filled sentence is text, never markup: a value shows exactly as stored, so a client must render it as text.
347+
303348
## Priority
304349

305350
When multiple validations exist, `priority` controls execution order:

‎content/docs/ui/translations.mdx‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,17 @@ Honest limits worth knowing before you plan around them:
490490
position in the component tree.** That is a settled refusal (maintainer
491491
ruling 2026-09-03, #14749) — not a gap awaiting a fix, and not something to
492492
plan around.
493-
- **Validation messages are translatable, but substituted whole — there is no
494-
interpolation.** Author the message on the rule
493+
- **Validation messages are translatable, and a translation fills the same
494+
`{{ }}` holes.** Author the message on the rule
495495
(`object.validations[].message`), which the engine returns on every rejected
496496
write, and translate it under `objects.<name>._validations.<rule>.message`
497-
(the row in the table above) — live since 17.3.0. The write path swaps the
498-
whole sentence for the bundle's, so only the language changes: an authored
499-
message has no parameter contract, so `{variable}` placeholders in it are not
500-
filled, and a key the bundle does not carry falls back to the authored
501-
literal.
497+
(the row in the table above) — live since 17.3.0. Both are templates over
498+
`record` and `previous`
499+
([Messages](/docs/data-modeling/validation#messages)): the write path picks
500+
the translation for the refusal's language and fills it first; one that does
501+
not render falls back to the authored message, filled the same way, and the
502+
server log names the translation. A key the bundle does not carry falls back
503+
to the authored message. A single-brace `{variable}` is refused at publish.
502504

503505
The retired top-level `validationMessages` group is **not** what came back.
504506
It was removed in 17.0.0 (#4667) because nothing read it — a translated rule

‎packages/spec/src/migrations/entries/semantic/19.validation-rule-message-template-holes.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const entry: SemanticMigration = {
1515
+ '— a sentence carrying a single-brace `{…}` or `${…}` token, or a `{{ }}` hole',
1616
replacement: 'a sentence with no braces, or a `{{ }}` hole naming one of the object\'s own fields under `record` '
1717
+ '(the merged record the rule judged) or `previous` (the stored row before an update), one segment deep, with '
18-
+ 'an optional whitelisted formatter: `Total {total_price} is below {received}` becomes `Total {{ '
18+
+ 'an optional whitelisted formatter: `Total {total_price} is below {received_amount}` becomes `Total {{ '
1919
+ 'record.total_price | currency }} is below {{ record.received_amount | currency }}`, and a brace that was '
2020
+ 'prose (`must be { tier: standard|premium }`) is reworded without it (`must name a tier: standard or '
2121
+ 'premium`).',

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,17 @@ export const CEILINGS = new Map([
18271827
// 3862 tokens, no headroom to absorb any of it, ceiling +396, the measured remainder, pinned
18281828
// AT the measurement. Raise path 「A:先削重复,余额按实测提高」 (ruling record 6513306068).
18291829
// ceil($(wc -c < skills/objectstack-data/rules/validation.md) / 4) == ceil(15448 / 4)
1830-
['skills/objectstack-data/rules/validation.md', 3862],
1830+
// 3862 -> 4097 (#37909, ruling P3 7239726323, currency ruling A 7277046538): GAINS
1831+
// § Messages — Record Values in Holes, what a refused write's sentence does since rule
1832+
// messages render (the two roots, the formatters, the tenant currency and its empty hole, the
1833+
// field floor, translation first, plain text). PAID DOWN FIRST inside the file: § Incorrect vs
1834+
// Correct and its table-of-contents entry are gone, since its one example (a rule with no
1835+
// `events` runs on insert and update; scope it with `events: ['update']`) restates § Events.
1836+
// -699 bytes cut, +1638 added: 15448 -> 16387 bytes (+939) -> 4097 tokens, no headroom to
1837+
// absorb any of it, ceiling +235, the measured remainder, pinned AT the measurement. Raise path
1838+
// 「A:先削重复,余额按实测提高」 (ruling record 6513306068).
1839+
// ceil($(wc -c < skills/objectstack-data/rules/validation.md) / 4) == ceil(16387 / 4)
1840+
['skills/objectstack-data/rules/validation.md', 4097],
18311841

18321842
// objectstack-platform
18331843
['skills/objectstack-platform/references/plugin-hooks.md', 2413], // -215 to the measurement (was 2628)

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
- [Available Rule Types](#available-rule-types) · [Expression Syntax](#expression-syntax) · [Script Validation](#script-validation)
44
- [Uniqueness — Use Unique Indexes](#uniqueness--use-unique-indexes) · [State Machine Validation](#state-machine-validation)
55
- [Format](#format-validation) · [Cross-Field](#cross-field-validation) · [JSON Schema](#json-schema-validation) · [Conditional](#conditional-validation)
6-
- [External / Custom Validation → Lifecycle Hooks](#external--custom-validation--lifecycle-hooks) · [Validation Properties](#validation-properties)
7-
- [Incorrect vs Correct](#incorrect-vs-correct)
6+
- [External / Custom Validation → Lifecycle Hooks](#external--custom-validation--lifecycle-hooks) · [Messages](#messages--record-values-in-holes) · [Validation Properties](#validation-properties)
87

98
Unmarked blocks are fragments; `check:skill-examples` skips them.
109

@@ -248,6 +247,32 @@ const taxIdCheck = defineHook({
248247
});
249248
```
250249

250+
## Messages — Record Values in Holes
251+
252+
`message` is a `{{ }}` template: a hole names one of the object's own fields,
253+
one segment deep, under `record` (the record the rule judged) or `previous`
254+
(the stored row before an update; empty on insert), with at most one formatter.
255+
256+
```typescript
257+
message: 'Total {{ record.total_price | currency }} is below what was received ({{ record.received_amount | currency }}).'
258+
```
259+
260+
- Formatters: `number` / `number:2`, `currency` / `currency:EUR`, `percent`,
261+
`date` / `date:long`, `datetime`, `upper`, `lower`, `trim`, `truncate:80`,
262+
`default:'n/a'`. A single-brace `{total}`, a hole through a field
263+
(`{{ record.account.name }}`) or over another root (`{{ user.name }}`) and
264+
logic in a hole are refused by `os validate` and at publish.
265+
- Bare `| currency` formats in the organization's default currency (Setup →
266+
Localization). With none set, that hole renders empty and the server log
267+
names the setting. A field holding its own currency names it:
268+
`| currency:EUR`, or `| number:2`.
269+
- A field the person whose write was refused cannot read, or sees masked,
270+
renders empty, `default:` included. The verdict never depends on the sentence.
271+
- The translation at `objects.<object>._validations.<rule>.message` takes the
272+
same holes and is filled first; if it does not render, the authored message is
273+
filled instead.
274+
- The sentence is plain text: a value shows as stored, never as markup.
275+
251276
## Validation Properties
252277

253278
### Severity Levels
@@ -284,31 +309,6 @@ priority: 100 // Application validations (default)
284309
priority: 1000 // User validations (run last)
285310
```
286311

287-
## Incorrect vs Correct
288-
289-
### ❌ Incorrect — Validation Fires Too Often
290-
291-
```typescript
292-
{
293-
type: 'script',
294-
condition: P`record.status == 'draft'`,
295-
message: 'Record is still in draft',
296-
// ❌ No events — runs on all operations
297-
}
298-
```
299-
300-
### ✅ Correct — Validation Scoped to Events
301-
302-
```typescript
303-
{
304-
name: 'no_draft_publish',
305-
type: 'script',
306-
condition: P`record.status == 'draft'`,
307-
message: 'Cannot publish draft records',
308-
events: ['update'], // ✅ Only validate on update
309-
}
310-
```
311-
312312
## Conditional Field Rules
313313

314314
A rule that belongs to the data model goes on the **field definition** and

0 commit comments

Comments
 (0)