Skip to content

Commit 038ccf5

Browse files
docs(adr,skills): ADR-0163 records the two-tier field write lock; objectstack-data teaches the four locks (#38428)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4Uu8dhiDUf1jDKZiZnYduzapm)_ Fixes #37405 Clause-②: no (no accept set or export changes; governed rules text, so one contract-review-tier review before the queue; Tier H) Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:给应用建数据模型的人和 AI,现在能从技能里学到「锁定一个字段」的四种写法各在什么时候用(比如销售订单的状态只让「确认」按钮改、不让人手改);把两种锁同时配在一个字段上时,校验报错会指出该看哪份设计说明。平台行为不变。 - 为什么做:你对「字段只读分两级」那张决策卡已经定了长远模型,功能也已上线,但设计说明和技能里一直没有记下来,这一步是补上记录。 - 出错会怎样:最坏是说明里某句话和平台实际做法对不上,作者照着配错了锁;只改文字和一句报错提示,可以直接撤回。 - 要你做什么:设计说明和技能文件的改动需要你批准合并。 ## What changes No key, schema, accepted value, default or runtime behaviour changes. This records the ruling of record on #36806 (ruling record 7180466652, 「按长远模型」) and the two object-level rulings on #37402 (ruling records 7235326611 and 7237772411), whose code landed in #37436, #37888 and #38169. - `docs/adr/0163-field-write-locks-two-tiers-two-forms-two-levels-ui-prefix-admission.md` (new, `Accepted (2026-11-26)` on the ruling record; it reaches `main` only by the Tier H approval). D1 two tiers (server lock `readonly` / `readonlyWhen`, hand lock `uiReadonly` / `uiReadonlyWhen`), D2 two forms (`readonlyWhen: P\`true\`` is the set-once spelling), D3 two levels (the object's `uiReadonlyWhen`; a field's own declaration wins; `uiReadonly: false` is not a declaration), D4 what "by hand" is, D5 the admission rule of the `ui` prefix (`uiVisibleWhen` / `uiRequiredWhen` are not admitted), D6 contradictions, D7 the server lock stays a strip. The record keeps two kinds of statement apart: Decision carries only what the rulings say, quoted; "As built" says what `main` does at `c610020e`, by symbol anchor. A third section, "Ruled and not yet held", lists the three places the ruling covers and the code does not reach yet, each with its open carrier card. - `docs/adr/README.md`: regenerated by `node scripts/adr-index.mjs` (164 records). - `skills/objectstack-data/rules/validation.md`: new section `## Locking a Field`: a two-by-two table of the four keys (who is kept out, and when), one checked sales-order example (the hotcrm#2716 case: a `status` only the Confirm action moves), and five bullets on what each column does at run time. - `skills/objectstack-data/SKILL.md` § Conditional Field Rules: the first bullet keeps its trap (the value is dropped, the write is not refused, a declarative action's included) and routes to the new section. - `skills/objectstack-data/evals/objects-fields-relationships.json`: case 30, a `uiReadonly` status field (`must_contain`: `uiReadonly: true`, `state_machine`). `evals/README.md` names it. - `packages/spec/src/data/field.zod.ts`: the parse refusal for `uiReadonly: true` beside `readonly: true` keeps its wording and now ends `The two locks and which one to choose: ADR-0163 (D1, D6).` This is the text `objectstack validate` prints for the pair. Pinned in `field-ui-readonly.test.ts`. - `.changeset/37405-field-write-lock-adr-skill.md`: `@objectstack/spec` and `@objectstack/skills`, patch. **One sentence of the skill is corrected, not only moved.** `rules/validation.md` said "Imports and migrations are system-context writes too." An import is not a system-context write. The `readonly` describe in `FieldSchema` says so ("A normal (non-system) import is NOT system-context and still strips"), `importControlOptOutRefusal` in `packages/rest/src/import-prepare.ts` refuses the historical-import opt-out to every HTTP caller, and the #36806 measurement found the same. The new section lists an import among the writes `readonly: true` drops, and a migration among the system writers it lets through. **Token ratchet** (`scripts/check-skills-token-ratchet.mjs`), two rows: - `skills/objectstack-data/SKILL.md` 2239 → 2224: lowered to the measurement. - `skills/objectstack-data/rules/validation.md` 3466 → 3862 (+396). The section is ordered into this skill by the ruling of record on #36806 (ruling record 7180466652: the four spellings, which one to use, the sales-order status example), and the raise follows the standing ruling, verbatim: 「A:先削重复,余额按实测提高」 (ruling record 6513306068). Paid down first in the same file, 1035 bytes cut against 2622 added: - the two `readonly` / `readonlyWhen` bullets of § Conditional Field Rules are now one pointer at the new section, which says the same once; - § Conditional Validation loses its first example (`enterprise_requires_manager`) and the lead-in of the second, whose `when` / `then` / `otherwise` rule shows everything the first did. ### Skills readings (lines / bytes / tokens) | | before | after | |:-|:-|:-| | `skills/objectstack-data/rules/validation.md` | 392 / 13861 / 3466 | 421 / 15448 / 3862 | | `skills/objectstack-data/SKILL.md` | 167 / 8983 / 2239 | 167 / 8923 / 2224 | | `skills/objectstack-data/evals/objects-fields-relationships.json` (not ratcheted) | 520 / 37381 | 533 / 38751 | | `skills/objectstack-data/evals/README.md` (not ratcheted) | 17 / 969 | 18 / 1016 | | all of `skills/objectstack-data/**` | 4643 / 252853 | 4686 / 255797 | | all `skills/*/SKILL.md` | 4386 / 228159 | 4386 / 228099 | | all of `skills/**` | 23333 / 1230467 | 23376 / 1233411 | | ratcheted (authored) total, tokens | 200510 | 200891 | ### Round 2 (head 6e397de): the contract review of 0922ab3 The review (comment 7248470779, PASS) left one should-fix and one nit. Both are done in one commit. - S1, `SKILL.md`: "a button's action included" was true of a declarative action only. A script action's body runs in a system context, so its write to a `readonly: true` field lands (ADR-0163, Alternatives, row 3). The clause now reads "a declarative action's included". The ratchet row follows the file to its measurement, 2224 (2223 at the previous head). - N1, `rules/validation.md`: the table's left column was headed "Every non-system write" over `readonlyWhen` too, which binds system writes as well. The header is now "Every write" and the `readonly: true` cell carries "(system writes pass)". The right header lost one word to pay for it ("Only a person at the console"), and the Confirm sentence names "a declarative Confirm". The file is 15448 bytes and its row stays 3862. - The changeset's sentence on the Confirm action says "a declarative action's own write" to match. ## Tests - `packages/spec/src/data/field-ui-readonly.test.ts`: the existing refusal case also asserts the message ends with `ADR-0163 (D1, D6).` `vitest run src/data/field-ui-readonly.test.ts` in `packages/spec`: 5 of 5 pass. - The new skill example carries the `os:check` marker, so `check:skill-examples` type-checks it against the built `@objectstack/spec` declarations. Exit 0: 353 marked examples type-check, this one among them. The example was also parsed by `ObjectSchema` and read by `validateStackExpressions` in two scratch vitest files (not committed): it parses, and the expression lint reports no issue for `readonlyWhen: P`true`` or `uiReadonlyWhen: P`false``. - `check:skill-eval-tokens`: exit 0; both `must_contain` tokens of case 30 are taught by the bundle. - Not run: a model-driven round of the skill evals. Case 30 has a new hash and no recorded answer yet. ## Acceptance notes - Done-when, line by line. "ADR accepted on `main`": the record's status is `Accepted` on the ruling record and it lands by the Tier H approval of this PR. "Skill section in place and its eval exercises a `uiReadonly` status field": the section and case 30. "`objectstack validate`'s refusal text for `uiReadonly` + `readonly` points at the ADR": the message above. - The card's Asked lists what the ruling says. Three points of it are not held by code on `main` yet. The ADR says so in "Ruled and not yet held" and names the open carrier of each: #37898 (the assistant is among the hands the ruling names; cloud AI service), #38202 (console Duplicate carries a hand-locked value), #38249 (inline child lines of a hand-locked parent). The skill section teaches only what `main` does today. - "`uiVisibleWhen` / `uiRequiredWhen` refused" (card wording): the ruling's rule is that a key earns a `ui` twin only when an action must write what a person may not, and only read-only meets it. Neither key exists in the schema, so a strict parse answers each as an unknown key. No dedicated refusal is added here; the ADR records the rule (D5) and the skill says there is no `uiVisibleWhen`. - D3 records that an object-level server lock (`readonlyWhen` on the object) is not filed anywhere; it is named so a later reader does not infer it from the hand lock's object level. - The refusal message names the ADR by number, the form the spec's other messages use (`ADR-0158 U2`, `ADR-0049`). - Branch `claude/project-thread-bqsxpg` is assigned by the harness, not the repo's `claude/issue-N-…` convention. ## Verification Two-minute check: `node scripts/check-skills-token-ratchet.mjs`, expect exit 0 with `skills/objectstack-data/rules/validation.md` 3862 / 3862 and `skills/objectstack-data/SKILL.md` 2224 / 2224. Read first, by risk: 1. `skills/objectstack-data/rules/validation.md` § Locking a Field (it ships to third parties verbatim): the left-column bullet, where the writers `readonly: true` drops and lets through are listed, and the import correction. 2. `docs/adr/0163-…md` D3 and D4 against the ruling records, then "Ruled and not yet held". 3. `scripts/check-skills-token-ratchet.mjs`: the two rows and their arithmetic. <details><summary>Local gates at 6e397de (only what reads the two changed skill files)</summary> Not the whole list again: the second commit changes two skill files, the ratchet rows and one changeset sentence. Re-run, each exit 0: `check-skills-token-ratchet.mjs` (and `--self-test`), `ui` `check:skill-eval-tokens`, `check:skill-links`, `check:skill-frame-sync`, `check:skill-identifier-liveness`, spec `check:skill-examples` (353 examples), `check:skill-docs`, `check:skill-refs`, `check:skill-served-sections`, `check-nul-bytes.mjs`. </details> <details><summary>Local gates at 0922ab3</summary> `node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ran FILE`, each command recorded as `CMD :: exit N`: **124 derived, 120 run, 4 NOT-MEASURED, 0 UNRUN**. Every run family exit 0, among them `check-skills-token-ratchet.mjs` (and `--self-test`), `check:adr-index`, `check:adr-anchors`, `check:adr-symbol-anchors`, `check-adr-links.mjs`, `check:skill-links`, `check:skill-frame-sync`, `check:skill-identifier-liveness`, spec `check:docs` / `check:api-surface` / `check:authorable-surface` / `check:skill-docs` / `check:skill-refs` / `check:liveness`, `check-empty-changeset.mjs`, `check-adr-0087-registration.mjs --base origin/main`, `check:ratchet-remedy-authority`, `check:type-check-debt`. - The four recorded exit 3 (prerequisite not met), as the tool reads the record: - `check-plugin-teardown-shape.mjs --self-test`: NOT MEASURED. Its positive control is pinned to a commit this shallow clone cannot reach. The gate itself (without `--self-test`) ran, exit 0. - `check:doc-formula-expressions`, `check:dual-build-cjs-loads`, `check:lean-entry-closure`: exit 3 on the first pass (their build closures were missing). After the closures were built each was run again alone, exit 0. The record keeps both lines, and the tool reads a command with two codes as the worse one, so its count stays 4. - Outside the derived list, run by hand: spec `check:skill-examples` (exit 3 before the `@objectstack/client-react` closure was built, exit 0 after: 353 examples), `ui` `check:skill-eval-tokens` (exit 0), `ui` `check:skills-paths` (exit 0). - `scripts/pm/overlap-check.mjs`: clean against `origin/main` (3579cf1) and the one open PR that shares a file (#38192, `skills/objectstack-data/SKILL.md`). - Built at `c610020e` plus this diff; `main` moved three commits since (none under this diff's paths), not merged in. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgTpyo8gQyqf9Tj9mfz <!-- signed: repo:objectstack#2 · os-sales · session_01L6bhgTpyo8gQyqf9Tj9mfz --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4437c50 commit 038ccf5

10 files changed

Lines changed: 260 additions & 37 deletions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@objectstack/spec': patch
3+
'@objectstack/skills': patch
4+
---
5+
6+
docs(skills,spec): the `objectstack-data` skill teaches which of the four field locks to use, and the `uiReadonly` + `readonly` refusal names ADR-0163
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
`skills/objectstack-data/rules/validation.md` gains `## Locking a Field`: a two-by-two table of `readonly`, `readonlyWhen`, `uiReadonly` and `uiReadonlyWhen` (who is kept out, and when), one checked sales-order example, and what each column does at run time. The server lock (`readonly`, `readonlyWhen`) drops the value from every non-system write and answers success; the hand lock (`uiReadonly`, `uiReadonlyWhen`) stops the console offering the field while an action, an import and the API still write it, each write judged by the object's validations. A status field that only a Confirm action moves is `uiReadonly: true`; under `readonly: true` a declarative action's own write is dropped. The section also covers the object-level `uiReadonlyWhen` and how a field replaces it, what a console create does with a `uiReadonly` field, and the refused pair.
12+
13+
One sentence the skill carried is corrected on the way: an import is not a system-context write, so `readonly: true` drops an imported value like any other client write. The two bullets that said otherwise are now one pointer at the new section, and `SKILL.md` § Conditional Field Rules routes there. `evals/objects-fields-relationships.json` gains case 30, a `uiReadonly` status field.
14+
15+
`@objectstack/spec`: the parse refusal for `uiReadonly: true` beside `readonly: true` keeps its wording and now ends with where the model is recorded: `The two locks and which one to choose: ADR-0163 (D1, D6).` No schema, accepted value or default changes.

‎docs/adr/0163-field-write-locks-two-tiers-two-forms-two-levels-ui-prefix-admission.md‎

Lines changed: 141 additions & 0 deletions
Large diffs are not rendered by default.

‎docs/adr/README.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
## Summary
1515

16-
163 records under `docs/adr/` (158 numbers), 11 under `ui/docs/adr/` (listed separately below).
16+
164 records under `docs/adr/` (159 numbers), 11 under `ui/docs/adr/` (listed separately below).
1717

1818
| Status | Records |
1919
|---|---|
20-
| Accepted | 139 |
20+
| Accepted | 140 |
2121
| Proposed | 10 |
2222
| Superseded | 4 |
2323
| Draft | 3 |
@@ -26,7 +26,7 @@
2626
| Amended | 1 |
2727
| Partially implemented | 1 |
2828
| Revised | 1 |
29-
| **Total** | **163** |
29+
| **Total** | **164** |
3030

3131
## Shared numbers
3232

@@ -230,6 +230,7 @@ A bare `ADR-0006` names the decision; its current text is [0006-project-environm
230230
| [ADR-0160](./0160-record-scoped-ai-inquiry.md) | Record-scoped AI inquiry — a context pack is its own metadata type, read as the caller and served by one tool… | Accepted — merged 2026-11-24 (PR objectstack#37115); amended 2026-11-25, 2… | 2026-11-24 | — | — |
231231
| [ADR-0161](./0161-knowledge-platform-boundary-platform-owns-assembly-sync-split-record-return-knowledge-source-is-a-governed-type.md) | The knowledge platform boundary — the platform owns document assembly, sync and reconcile, structural split a… | Proposed — 2026-11-24, written for objectstack#37001 on the maintainer's r… | 2026-11-24 | — | — |
232232
| [ADR-0162](./0162-an-object-declares-its-closed-states-the-record-and-its-lines-are-closed-to-change.md) | An object declares its closed states — in them the record and its master-detail lines are closed to change fo… | Proposed — 2026-11-26, written for objectstack#36253 on the maintainer's r… | 2026-11-26 | — | — |
233+
| [ADR-0163](./0163-field-write-locks-two-tiers-two-forms-two-levels-ui-prefix-admission.md) | A field's write lock has two tiers, two forms and two levels — `readonly` / `readonlyWhen` keep every client… | Accepted — 2026-11-26 — maintainer ruling on #36806, ruling record `718046… | 2026-11-28 | — | — |
233234

234235
## ObjectUI registry — `ui/docs/adr/` (`ui-` prefix)
235236

‎packages/spec/src/data/field-ui-readonly.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ describe('Field.uiReadonly / Field.uiReadonlyWhen', () => {
4848
expect(issues).toHaveLength(1);
4949
expect(issues[0].code).toBe('custom');
5050
expect(issues[0].message).toMatch(/^`uiReadonly: true` locks the field against editing by hand at the console/);
51+
// [#37405] The refusal names the record of the model, so the author who
52+
// meets it can read why there are two locks and which one to keep.
53+
expect(issues[0].message).toMatch(/ADR-0163 \(D1, D6\)\.$/);
5154
});
5255

5356
it('refuses the pair through the object door too', () => {

‎packages/spec/src/data/field.zod.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,7 +3430,8 @@ export const FieldSchema = lazySchema(() => {
34303430
});
34313431
}
34323432
}
3433-
// The hand lock beside the server lock (ruling record 7180466652): a
3433+
// The hand lock beside the server lock (ruling record 7180466652, recorded
3434+
// as ADR-0163 D6, which the message names so the reader can find the model): a
34343435
// `readonly: true` field already keeps every client out, so `uiReadonly`
34353436
// beside it says two things at once — refused at every door that parses a
34363437
// field (`defineStack`, `os validate`, the metadata save). The conditional
@@ -3444,7 +3445,8 @@ export const FieldSchema = lazySchema(() => {
34443445
'`uiReadonly: true` locks the field against editing by hand at the console while API, import, action and '
34453446
+ 'flow writes keep it, and this field is also `readonly: true`, which keeps every client write out. Keep '
34463447
+ 'one: `readonly` when no client may write the field, `uiReadonly` when people at the console may not but '
3447-
+ 'actions, imports and the API may (each write judged by the object\'s validations).',
3448+
+ 'actions, imports and the API may (each write judged by the object\'s validations). The two locks and '
3449+
+ 'which one to choose: ADR-0163 (D1, D6).',
34483450
});
34493451
}
34503452

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,14 @@ export const CEILINGS = new Map([
914914
// `references/examples-objects.md` § Object Extension Model; the rule list `main` trimmed is
915915
// the routing table here). 8983 bytes on this tree, whose stamp line is 27 bytes: 8956 priced.
916916
// ceil(($(wc -c < skills/objectstack-data/SKILL.md) - 27) / 4) == ceil(8956 / 4)
917-
['skills/objectstack-data/SKILL.md', 2239],
917+
// 2239 -> 2224 (#37405, ADR-0163): LOWERED to the measurement. The first bullet of
918+
// `## Conditional Field Rules` keeps its trap (the value is dropped, the write is not
919+
// refused, a declarative action's included) and routes the choice of lock to
920+
// `rules/validation.md` § Locking a Field in place of the clause on which writers
921+
// `readonly: true` binds, which that section now carries. 8983 -> 8923 bytes (8956 ->
922+
// 8896 priced), -60, -> 2224 tokens, pinned AT the measurement.
923+
// ceil(($(wc -c < skills/objectstack-data/SKILL.md) - 27) / 4) == ceil(8896 / 4)
924+
['skills/objectstack-data/SKILL.md', 2224],
918925
// 5997 -> 6008 (the formula skills follow-ups of PRs #34443 and #34447): the
919926
// `label(record.f)` row teaches a multi-select (`multiple: true`) reading each
920927
// selected label in stored order, joined with `, `, and the built-ins line
@@ -1731,7 +1738,18 @@ export const CEILINGS = new Map([
17311738
// headroom absorbed, ceiling +705, pinned AT the measurement. Authority as the
17321739
// `references/examples-objects.md` row.
17331740
// ceil($(wc -c < skills/objectstack-data/rules/validation.md) / 4) == ceil(13861 / 4)
1734-
['skills/objectstack-data/rules/validation.md', 3466],
1741+
// 3466 -> 3862 (#37405, ADR-0163): GAINS `## Locking a Field`, the section the ruling of
1742+
// record on #36806 orders into this skill (ruling record 7180466652: the four spellings,
1743+
// which one to use, the sales-order status example), with one checked example. PAID DOWN
1744+
// FIRST inside the file: the two `readonly` / `readonlyWhen` bullets of § Conditional Field
1745+
// Rules become one pointer at the new section, which says the same once (and corrects their
1746+
// claim that an import is a system-context write); § Conditional Validation loses its first
1747+
// example and the lead-in of the second, whose `when` / `then` / `otherwise` rule shows
1748+
// everything the first did. -1035 bytes cut, +2622 added: 13861 -> 15448 bytes (+1587) ->
1749+
// 3862 tokens, no headroom to absorb any of it, ceiling +396, the measured remainder, pinned
1750+
// AT the measurement. Raise path 「A:先削重复,余额按实测提高」 (ruling record 6513306068).
1751+
// ceil($(wc -c < skills/objectstack-data/rules/validation.md) / 4) == ceil(15448 / 4)
1752+
['skills/objectstack-data/rules/validation.md', 3862],
17351753

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

‎skills/objectstack-data/SKILL.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ over `record.*` (`P\`record.status == 'paid'\``), so every form and
8282
API write honours them.
8383

8484
- **`readonlyWhen` and `readonly: true` drop the value; they do not refuse the
85-
write.** `readonly: true` binds non-system writes only; a `runAs:'system'`
86-
flow, system hook or seed does write it
87-
([objectstack-automation → Failure routing & `runAs`](../objectstack-automation/SKILL.md#failure-routing--runas)).
85+
write**, a declarative action's included. A field that only actions, imports
86+
and the API change is `uiReadonly`
87+
([Locking a Field](./rules/validation.md#locking-a-field)).
8888
- **`requiredWhen` is a transition gate, not an invariant**: it judges the
8989
write, not the stored row. A fact true of every stored record is a
9090
`validations[]` `script` rule.

‎skills/objectstack-data/evals/README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ JSON fixtures in the objectui shape (`skill_name`, `evals[]`: `prompt`,
66
- `objects-fields-relationships.json` — naming, field types (`secret` vs
77
`password`), relationships (junction vs multi-value lookup,
88
`deleteBehavior`, on a `user` field too), validation (`state_machine`, unique **index**),
9-
conditional field rules, the record owner (负责人 is `owner_id`), an
9+
conditional field rules, the hand lock (a `uiReadonly` status field), the
10+
record owner (负责人 is `owner_id`), an
1011
object extension placing what it brings (`place`), the `.custom` pair's
1112
whole arrangement (`relatedLists`, `{ list, hidden: true }`).
1213
- `hooks-security-seeds-datasources.json` — search mirrors via hooks,

‎skills/objectstack-data/evals/objects-fields-relationships.json‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,19 @@
515515
],
516516
"must_not_contain": []
517517
}
518+
},
519+
{
520+
"id": 30,
521+
"prompt": "On `sales_order`, `status` (`draft`, then `confirmed`) should change only through the Confirm button: nobody may pick another status in the form, in a grid cell or by dragging a card on the board. A colleague set `readonly: true` on `status`; now Confirm answers success and the order stays `draft`. Why, and how should the field be declared so that Confirm works and can only take a draft order to confirmed?",
522+
"expected_output": "`readonly: true` is the server lock: every non-system write to the field is dropped, not refused, and the Confirm action's own update is such a write, so it answers success without the change (`X-ObjectStack-Dropped-Fields` names the field). Declare the hand lock instead: `status: Field.select({ options: [...], defaultValue: 'draft', uiReadonly: true })`. Forms, inline edit, grid cells and board drags stop offering the field, while the action, an import and the API still write it, each write judged by the object's validations; so the legal move goes in a `state_machine` rule on `status` (`draft: ['confirmed']`). It is not security: whoever may edit the record can still write the field through the API.",
523+
"files": [],
524+
"assertions": {
525+
"must_contain": [
526+
"uiReadonly: true",
527+
"state_machine"
528+
],
529+
"must_not_contain": []
530+
}
518531
}
519532
]
520533
}

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

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -198,25 +198,6 @@ is a **single** nested rule applied when it holds, `otherwise` (optional) a
198198
single rule applied when it doesn't. There is no `validations: []` array —
199199
compose multiple checks as multiple top-level rules or nested conditionals.
200200

201-
```typescript
202-
validations: [
203-
{
204-
name: 'enterprise_requires_manager',
205-
type: 'conditional',
206-
when: P`record.type == 'enterprise'`,
207-
message: 'Enterprise account validation',
208-
then: {
209-
name: 'manager_required',
210-
type: 'script',
211-
condition: P`isBlank(record.account_manager)`,
212-
message: 'Enterprise accounts must have an account manager',
213-
},
214-
},
215-
]
216-
```
217-
218-
With an `otherwise` branch:
219-
220201
```typescript
221202
{
222203
name: 'payment_validation',
@@ -364,13 +345,8 @@ export const Invoice = ObjectSchema.create({
364345

365346
- `showOnCreate: false` keeps a field off every create surface; edit, the
366347
record page and lists keep it. Refused beside `required: true`.
367-
- Use `readonlyWhen` for state-locked fields; the ObjectQL write path ignores
368-
incoming changes when the predicate is `TRUE` (for everyone; per permission
369-
set → field permission `when`, rules/security.md).
370-
- **`readonly: true` governs the end-user surface, not trusted system writers.**
371-
A stripped write (REST/UI, and any `runAs:'user'` flow) reports success.
372-
Imports and migrations are system-context writes too. Keep the field `readonly` when automation maintains it; the flow
373-
side: [objectstack-automation → Failure routing & `runAs`](../../objectstack-automation/SKILL.md#failure-routing--runas).
348+
- `readonly`, `readonlyWhen` and the console-only lock:
349+
[Locking a Field](#locking-a-field).
374350
- Use `requiredWhen` for conditional requiredness; the ObjectQL validator
375351
enforces it on submit. The removed `conditionalRequired` alias is a parse
376352
error.
@@ -390,3 +366,56 @@ or `requiredWhen` refuses the write naming it, an option `visibleWhen` only a
390366
write picking the option (forms still offer it); a `readonlyWhen` field stays
391367
editable and the save succeeds without its change (logged); a formula reads
392368
`null` (logged).
369+
370+
## Locking a Field
371+
372+
Two questions pick the key: who is kept out, and when.
373+
374+
| | Every write | Only a person at the console |
375+
|:--|:--|:--|
376+
| Always | `readonly: true` (system writes pass) | `uiReadonly: true` |
377+
| While a `record.*` predicate is TRUE | `readonlyWhen` | `uiReadonlyWhen` |
378+
379+
<!-- os:check -->
380+
```typescript
381+
import { P } from '@objectstack/spec';
382+
import { ObjectSchema, Field } from '@objectstack/spec/data';
383+
384+
export const SalesOrder = ObjectSchema.create({
385+
name: 'sales_order',
386+
sharingModel: 'public_read_write',
387+
uiReadonlyWhen: P`record.status != 'draft'`, // once confirmed, only actions change the order
388+
fields: {
389+
status: Field.select({ // moved by the Confirm action, never typed
390+
options: [{ label: 'Draft', value: 'draft' }, { label: 'Confirmed', value: 'confirmed' }],
391+
defaultValue: 'draft',
392+
uiReadonly: true,
393+
}),
394+
order_number: Field.text({ readonlyWhen: P`true` }), // set on create, then fixed
395+
notes: Field.textarea({ uiReadonlyWhen: P`false` }), // editable on a confirmed order too
396+
},
397+
});
398+
```
399+
400+
- **Left column, the server lock: the value is dropped, the write is not
401+
refused.** REST, the UI, an import, a declarative action and a
402+
`runAs:'user'` flow answer success without the change
403+
(`X-ObjectStack-Dropped-Fields` names the field). `readonly: true` lets a
404+
system writer through (a seed, a migration, a system hook, a
405+
`runAs:'system'` flow:
406+
[objectstack-automation → Failure routing & `runAs`](../../objectstack-automation/SKILL.md#failure-routing--runas)),
407+
so keep it on a field automation maintains. `readonlyWhen` holds for
408+
everyone (per permission set: a field permission `when`,
409+
[Security](./security.md)) and is not judged on a create.
410+
- **Right column, the hand lock: forms, inline edit, grid cells and board or
411+
calendar drags do not offer the field, and every write still lands**,
412+
judged by the validations (a `state_machine` on `status`). Under `readonly`
413+
a declarative Confirm's write would be dropped. Not security: whoever may
414+
edit the record can write the field through the API.
415+
- A console create leaves a `uiReadonly` field out: the record takes its
416+
`defaultValue`, and a `required` field without one fails the create.
417+
- On the **object**, `uiReadonlyWhen` locks every field of an existing record.
418+
A field's own `uiReadonly: true` or `uiReadonlyWhen` replaces it;
419+
`uiReadonly: false` does not.
420+
- `uiReadonly` beside `readonly: true` is refused. Only read-only has a `ui`
421+
twin: there is no `uiVisibleWhen`.

0 commit comments

Comments
 (0)