From 0933178412a89d313daff61c82eba8ce53ab560a Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 23:57:36 +0000 Subject: [PATCH 1/3] docs(adr): ADR-0163 records the two-tier field write lock model and the ui-prefix admission rule Claude-Session: https://claude.ai/code/session_01L6bhgTpyo8gQyqf9Tj9mfz Co-authored-by: Claude --- ...wo-forms-two-levels-ui-prefix-admission.md | 141 ++++++++++++++++++ docs/adr/README.md | 7 +- 2 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 docs/adr/0163-field-write-locks-two-tiers-two-forms-two-levels-ui-prefix-admission.md diff --git a/docs/adr/0163-field-write-locks-two-tiers-two-forms-two-levels-ui-prefix-admission.md b/docs/adr/0163-field-write-locks-two-tiers-two-forms-two-levels-ui-prefix-admission.md new file mode 100644 index 00000000000..4530857cb94 --- /dev/null +++ b/docs/adr/0163-field-write-locks-two-tiers-two-forms-two-levels-ui-prefix-admission.md @@ -0,0 +1,141 @@ +# ADR-0163: A field's write lock has two tiers, two forms and two levels — `readonly` / `readonlyWhen` keep every client write out, `uiReadonly` / `uiReadonlyWhen` keep a person's hand out at the console, a field's own declaration wins over its object's default, and a `ui`-prefixed key is admitted only where the console's answer and the server's legitimately differ + +**Status**: Accepted (2026-11-26) — maintainer ruling on [#36806](https://github.com/objectstack-ai/objectstack/issues/36806), ruling record [`7180466652`](https://github.com/objectstack-ai/objectstack/issues/36806#issuecomment-7180466652), verbatim 「按长远模型」, and the maintainer's ruling of 2026-11-28 on the object level, ruling record [`7235326611`](https://github.com/objectstack-ai/objectstack/issues/37402#issuecomment-7235326611), verbatim 「B 不算放开 (Recommended)」. `docs/adr/**` is Tier H (Prime Directive #14): this record lands by the maintainer's merge or enqueue, or by an authorised approval. **This record declares.** The keys it describes are on `main` already, landed by [#37436](https://github.com/objectstack-ai/objectstack/pull/37436), [#37888](https://github.com/objectstack-ai/objectstack/pull/37888) and [#38169](https://github.com/objectstack-ai/objectstack/pull/38169); the PR that carries this record changes one refusal message so that it names this record ([D6](#d6--contradictions)). Three things the rulings decide are held by no code yet, each with its card: [Ruled and not yet held](#ruled-and-not-yet-held). + +- **Date**: 2026-11-28 +- **Card**: [#37405](https://github.com/objectstack-ai/objectstack/issues/37405) (p2, `area:data`), a sub-issue of #36806, filed by the ruling record so that the model and the naming rule have a record to cite and do not live only in the keys' describe texts. +- **Decided by**: the maintainer, 2026-11-26, in the decision thread 「裁决 #36806 只读字段命名」: option A 「新增 uiReadonly 布尔键」 on the decision card, then 「按长远模型」, after 「我说的合理的方案是从元数据应用实际可能发生的业务需求角度出发,不等卡」 and 「考虑长远合理的方案」. Ruling record `7180466652` states the model, its phases and the naming rule. The ruling's own text is the authority this record writes down; where the two differ in words, the ruling wins and this record is corrected. +- **Ruled since**: the maintainer, 2026-11-28, on two questions the object level raised, both on [#37402](https://github.com/objectstack-ai/objectstack/issues/37402). Ruling record `7235326611`: 「B 不算放开 (Recommended)」, a field's explicit `uiReadonly: false` does not open it inside a locked record ([D3](#d3--two-levels-the-field-and-the-object-and-the-fields-own-declaration-wins)). Ruling record [`7237772411`](https://github.com/objectstack-ai/objectstack/issues/37402#issuecomment-7237772411): 「本 PR 按字面落地+立跟进卡 (Recommended)」, the inline line rows of a hand-locked parent are a follow-up card ([Ruled and not yet held](#ruled-and-not-yet-held)). +- **Builds on**: [ADR-0049](./0049-no-unenforced-security-properties.md) (a declared key is enforced on every surface it names). [ADR-0085](./0085-object-semantic-roles-over-surface-hint-blocks.md) §2 (the admission test for future keys: a key binds the object across surfaces, and fails if its honest name contains a page name). [ADR-0092](./0092-sys-user-profile-field-delegation.md) (history: it recorded field-level `readonly` as a UI hint and not a server boundary; the write-path strip has since made it one, which is why the hand lock needs a name of its own). [ADR-0124](./0124-server-enforces-client-is-courtesy.md) (the server is the enforcement point; a client gate stricter than the server is a presentation choice, D4). [ADR-0137](./0137-predicate-fault-semantics-are-contract.md) D2 (what a field-rule predicate that faults does). [ADR-0020](./0020-state-machine-converge-and-enforce.md) (the `state_machine` rule that judges the writes the hand lock lets through). +- **Leaves unchanged**: `readonly` and `readonlyWhen`, in every respect; every permission grant; the closed-state lock of [ADR-0162](./0162-an-object-declares-its-closed-states-the-record-and-its-lines-are-closed-to-change.md), which is a record lock that refuses and not a field lock. +- **Inputs**: code and docs text read on `objectstack-ai/objectstack` `main` at `c610020e`. Positions are in [As built](#as-built-read-at-c610020e). + +--- + +## Provenance + +Two kinds of statement appear below, and they are kept apart. + +1. **Ruled.** [Decision](#decision) carries only what the rulings say: ruling record `7180466652` (the model, the naming rule, what counts as by hand, the contradiction handling), and ruling records `7235326611` and `7237772411` (the object level). Where a D-item quotes, the words are the ruling record's. +2. **Readings.** [As built](#as-built-read-at-c610020e) says what the code on `main` does at `c610020e`, cited by symbol anchor (`path#symbol`). A behaviour that appears only there was settled by the PR that landed it and its contract review. It is not a decision of this record. + +## TL;DR + +| | Server lock: no client may write | Hand lock: no person edits by hand; API, import, actions and flows write, judged by validations | +|:--|:--|:--| +| Always | `readonly` | `uiReadonly` | +| Conditional (CEL over `record`) | `readonlyWhen` | `uiReadonlyWhen` | + +- Two **tiers**. The engine reads the server lock and never the hand lock. The console reads both. +- Two **forms**. A boolean, and a predicate over the record's own columns. `readonlyWhen: P\`true\`` is "set once on create"; there is no key for it. +- Two **levels**. An object's `uiReadonlyWhen` hand-locks the whole record, and a field's own hand-lock declaration replaces it for that field. +- **One naming rule.** A `ui`-prefixed twin of a key exists only where the console and the server legitimately answer the same question differently. Read-only is the only such concept today: `uiVisibleWhen` and `uiRequiredWhen` are refused. +- The hand lock is **not a security boundary**. Who may write a field is a permission. + +## Context + +A document's status usually moves only through its actions: an order is confirmed by Confirm, not by picking "Confirmed" in a form. Until this ruling the platform had one word for a field nobody edits, `readonly`, and that word is a server boundary: a non-system write that carries a `readonly` field has the field dropped and the rest lands. Measured on the hotcrm sales order (the body of #36806, for objectstack-ai/hotcrm#2716): with `status` declared `readonly`, a declarative update action answered success while the status stayed `draft`, a `PATCH` answered 200 with `X-ObjectStack-Dropped-Fields: status;reason=readonly`, and an import update reported the field dropped. The state machine saw none of them. So an author could keep people out of the field only by keeping the action, the import and the API out with them. + +The ruling adds the second fact a field can carry, under its own name, and settles the whole model at once so that later cards do not each invent a spelling: which keys exist, at which levels, what "by hand" means, and when a `ui`-prefixed key may be added at all. + +## Decision + +### D1 — Two tiers: the server lock and the hand lock + +A field carries two independent write facts. + +- **The server lock** (`readonly`, `readonlyWhen`): no client may write the field. It is enforced on the write path, for every door. +- **The hand lock** (`uiReadonly`, `uiReadonlyWhen`): no person edits the field by hand. Writes through the API, import, actions and flows keep the field, and the object's validations judge each of them exactly as they judge an ordinary field, a `state_machine` rule included. + +The engine never reads the hand-lock keys. A write to a hand-locked field is not dropped and is not reported as dropped. The console reads both tiers through one verdict: a field is read-only by hand now when `readonly` is true, or `readonlyWhen` is TRUE, or `uiReadonly` is true, or `uiReadonlyWhen` is TRUE. + +The hand lock answers a different question from a permission, and it is not one. It says by which route a person changes the field, not who may change it: a caller who may edit the record can write a hand-locked field through the API. Deleting the console's check would let no caller land a write the server refuses, so under ADR-0124 the check is a presentation rule and not an enforcement point in the wrong place. Who may write a field is the permission set's `editable` grant. An object whose fields carry only hand locks is no more protected than one with none, which is the boundary ADR-0092 refused to draw in the interface and this record does not draw there either. + +### D2 — Two forms: always and conditional + +Each tier has a boolean and a predicate. The predicate is CEL over `record`, the bound record's own columns, and both tiers' predicates have the same scope. + +"Set on create, fixed afterwards" is `readonlyWhen: P\`true\``, in the ruling record's words "the RAP `readonly:update` / OData `Core.Immutable` shape; no new key". + +A create from the console leaves a `uiReadonly` field out, and the server applies the field's `defaultValue`. An insert through the API, an import or an action may set the field, judged by the validations (a state machine's initial states). + +### D3 — Two levels: the field and the object, and the field's own declaration wins + +The object level of the hand lock is `uiReadonlyWhen` on the object: while TRUE the whole record is locked by hand. It is a default for each field. A field that declares a hand lock of its own, `uiReadonly: true` or a `uiReadonlyWhen`, is judged by that declaration instead, in both directions: a field whose own `uiReadonlyWhen` is `P\`false\`` stays editable inside a locked record, and a field's own predicate can lock it where the object does not. + +An explicit `uiReadonly: false` is not such a declaration (ruling record `7235326611`). It is that key's default, and a Studio switch turned on and then off stores it; read as an opt-out, it would silently open the field on every locked record. The one opt-out spelling is `uiReadonlyWhen: P\`false\``. + +A field's server lock is not a hand-lock declaration. It keeps locking on its own, whatever the object declares. + +The ruling record names an object-level `readonlyWhen` as "the symmetric completion the model allows later; not filed". This record files nothing for it either. The object level has one key today. + +### D4 — What "by hand" is + +Quoted from the ruling record: + +> "By hand" = create/edit dialogs (and the submitted payload), record-page inline edit, highlight-strip chip, grid inline edit and multi-row save, kanban drag, calendar drag, duplicating a record from the console, and an in-app assistant acting for a person. Not by hand = REST create/update, import (including the console import wizard's mapping), declarative and script actions, flows. + +ADR-0049 holds the key to every surface it names. A console surface through which a person changes a field's stored value reads the one verdict of D1, and a surface added later joins that read in the PR that adds it. + +### D5 — The `ui` prefix has an admission rule + +Quoted from the ruling record, which asks to be cited for it: + +> a `ui`-prefixed twin of a key is admitted only where the console's and the server's answers to the same question legitimately differ. Read-only is the only such concept today: visibility has one tier (the server side is permission masking, `requiredPermissions` / FLS `readable`, a different key) and required-ness has one tier (the server; the console mirrors `requiredWhen` for feedback). `uiVisibleWhen` and `uiRequiredWhen` are refused by this rule. + +`ui` names the console as a channel and not a page, which is how the two keys pass ADR-0085 §2. A later card that wants a `ui`-prefixed key cites this rule and shows the two answers that legitimately differ. One that cannot show them does not add the key. + +### D6 — Contradictions + +- `uiReadonly: true` beside `readonly: true` is refused at validate, at `['uiReadonly']`, at every door that parses a field. The server lock already keeps every client out, so the pair says two things at once. The refusal's text names this record. +- `uiReadonlyWhen` beside `readonlyWhen` is allowed. The two predicates can differ, and where `readonlyWhen` is TRUE the server lock is the stricter one. + +### D7 — The server lock stays a strip + +This record changes nothing on the write path. A client write that carries a server-locked field has the field dropped and the rest lands, and the answer names the dropped field (`X-ObjectStack-Dropped-Fields`, `droppedFields`). A mode in which the server lock refuses the write instead is out of this record's scope. The option a caller can already pass to have such a write refused whole is unchanged. + +## Ruled and not yet held + +Three things the rulings decide have no code holding them at `c610020e`. Each is a card, and none is re-opened here. + +| Ruled | Today | Card | +|:--|:--|:--| +| An in-app assistant acting for a person is a hand surface (D4). | Its writes run in the AI service, outside this repository, which does not read the hand lock. The keys' describe texts say so. | [#37898](https://github.com/objectstack-ai/objectstack/issues/37898) | +| Duplicating a record from the console is by hand (D4): the copy takes each hand-locked field's `defaultValue`. | The console has no person-triggered duplicate. The REST clone door is an API write, which the ruling keeps. | [#38202](https://github.com/objectstack-ai/objectstack/issues/38202) | +| The inline line rows of a hand-locked parent come under its lock (ruling record `7237772411`). | A line-item column follows the child object's own lock. | [#38249](https://github.com/objectstack-ai/objectstack/issues/38249) | + +## As built, read at `c610020e` + +- **The four field keys and the object key**: `packages/spec/src/data/field.zod.ts#FieldSchema` (`readonly`, `readonlyWhen`, `uiReadonly`, `uiReadonlyWhen`, and the refusal of D6 in its refinement); `packages/spec/src/data/object.zod.ts#ObjectSchemaBase` (`uiReadonlyWhen`). `uiReadonly` is optional with no default materialised: absent reads as false. +- **The server lock**: `packages/objectql/src/validation/rule-validator.ts#stripReadonlyFields` and `#stripReadonlyWhenFields`. Neither reads a hand-lock key. A conditional lock is not judged on a create, which is what makes `readonlyWhen: P\`true\`` set-once. The dropped fields reach the caller through `packages/rest/src/error-response.ts#applyDroppedFieldsHeader`; the refusal a caller can opt into is `packages/objectql/src/readonly-strict-errors.ts#ReadonlyFieldRejectedError`. +- **The one hand-lock verdict**: `ui/packages/core/src/evaluator/handLock.ts#fieldReadOnlyByHand`, with the object level folded in by `#effectiveUiReadonlyWhen`. Beyond the surfaces the ruling lists, the same verdict is read by the stage path, the line-item grid, the calendar quick-create, the Gantt (drag, resize, progress handle, dependency link, in-place edit), the timesheet cell and the command palette's create-as prefill. The import wizard's target mapping and the Studio authoring reads stay on the raw `readonly`. +- **A conditional hand lock is judged on an existing record only.** The create dialog does not read `uiReadonlyWhen`. +- **A hand-lock predicate that cannot be evaluated locks the field**, since no server judges it, and the edit dialog refuses to submit until it is fixed. `os validate` checks a field's and an object's `uiReadonlyWhen` as it checks `readonlyWhen` (`packages/lint/src/validate-expressions.ts`). +- **A caller denied a field the predicate reads** is served the lock closed instead of the predicate: `uiReadonly: true` on the field, a constant TRUE for the object's (`packages/metadata-core/src/object-schema-fls-references.ts`). +- **MCP `describe_object`** reports the hand-lock keys as their own keys, never folded into `readonly`, which tells an agent to leave a field out of a write (`packages/runtime/src/domains/mcp.ts#describeServedObject`). +- **Proof that every write keeps a hand-locked field**: `packages/qa/dogfood/test/ui-readonly-hand-lock-36806.dogfood.test.ts`. Over HTTP, a `PATCH`, an import and a declarative action write a `uiReadonly` field with no dropped-fields header, the `state_machine` rule refuses an illegal move with its own message on each door, and a `readonly` sibling is stripped as the control. The verdict's pins are `ui/packages/core/src/evaluator/__tests__/handLock-36806.test.ts`; the refusal's is `packages/spec/src/data/field-ui-readonly.test.ts`. + +## Consequences + +- An author has an honest declaration for "people do not type this; the buttons, the imports and the API set it": `uiReadonly`. `readonly` keeps its strong meaning, and nothing about it moves. +- The console can be stricter than the server by declaration. A person who may edit the record can still write a hand-locked field through the API. Where that must not happen, the answer is a permission, or the server lock. +- The hand lock has no server judge. It holds only as far as every console surface reads the one verdict, and a surface that forgets it opens the field with no refusal anywhere. The three rows of [Ruled and not yet held](#ruled-and-not-yet-held) are that cost today. +- A card that wants another `ui`-prefixed key has a rule to meet (D5) before it has a name to pick. + +## Alternatives considered + +The decision analysis the maintainer read is comment [`7179210173`](https://github.com/objectstack-ai/objectstack/issues/36806#issuecomment-7179210173) on #36806. In short: + +| Alternative | Why not | +|:--|:--| +| `editable: 'actions'` on the field | `editable` is the permission set's write grant. The word would mean "may write" on a grant and "the console may not write" on a field, and the value misdescribes API, import and flow writes. | +| Widen `readonly` to `boolean \| 'ui'` | The engine strips on a truthy `readonly`, so `'ui'` would be stripped on every write, the opposite of the ask, on a shipped server-enforced key. | +| No key: `readonly` plus a script action, which runs in a system context | The button works, and API and import writes to the field are still dropped silently. | +| A key for "editable on create, locked afterwards" | `readonlyWhen: P\`true\`` already says it (D2). | +| `uiVisibleWhen`, `uiRequiredWhen` | Refused by D5: each of those questions has one tier. | + +## Refs + +- Card [#37405](https://github.com/objectstack-ai/objectstack/issues/37405); parent [#36806](https://github.com/objectstack-ai/objectstack/issues/36806), ruling record [`7180466652`](https://github.com/objectstack-ai/objectstack/issues/36806#issuecomment-7180466652); object level [#37402](https://github.com/objectstack-ai/objectstack/issues/37402), ruling records [`7235326611`](https://github.com/objectstack-ai/objectstack/issues/37402#issuecomment-7235326611) and [`7237772411`](https://github.com/objectstack-ai/objectstack/issues/37402#issuecomment-7237772411). +- Landed by [#37436](https://github.com/objectstack-ai/objectstack/pull/37436) (the field keys and the console surfaces), [#37888](https://github.com/objectstack-ai/objectstack/pull/37888) (the Gantt, the timesheet, the calendar quick-create and the palette prefill) and [#38169](https://github.com/objectstack-ai/objectstack/pull/38169) (the object level). +- Open: [#37898](https://github.com/objectstack-ai/objectstack/issues/37898), [#38202](https://github.com/objectstack-ai/objectstack/issues/38202), [#38249](https://github.com/objectstack-ai/objectstack/issues/38249). diff --git a/docs/adr/README.md b/docs/adr/README.md index ef063606780..30d5db78151 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -13,11 +13,11 @@ ## Summary -163 records under `docs/adr/` (158 numbers), 11 under `ui/docs/adr/` (listed separately below). +164 records under `docs/adr/` (159 numbers), 11 under `ui/docs/adr/` (listed separately below). | Status | Records | |---|---| -| Accepted | 139 | +| Accepted | 140 | | Proposed | 10 | | Superseded | 4 | | Draft | 3 | @@ -26,7 +26,7 @@ | Amended | 1 | | Partially implemented | 1 | | Revised | 1 | -| **Total** | **163** | +| **Total** | **164** | ## Shared numbers @@ -230,6 +230,7 @@ A bare `ADR-0006` names the decision; its current text is [0006-project-environm | [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 | — | — | | [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 | — | — | | [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 | — | — | +| [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 | — | — | ## ObjectUI registry — `ui/docs/adr/` (`ui-` prefix) From 0922ab3aace05c52d7f13b3104eed7004912a410 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 29 Nov 2026 00:38:06 +0000 Subject: [PATCH 2/3] docs(skills,spec): teach the four field locks in objectstack-data and point the uiReadonly + readonly refusal at ADR-0163 skills/objectstack-data/rules/validation.md gains "Locking a Field": the two-by-two of readonly / readonlyWhen / uiReadonly / uiReadonlyWhen, one checked sales-order example and what each column does at run time. The two readonly bullets of Conditional Field Rules become a pointer at it, and the claim that an import is a system-context write is corrected there. SKILL.md routes to the section; evals gain case 30, a uiReadonly status field. The token ratchet rows follow: SKILL.md 2239 -> 2223 (lowered to the measurement), rules/validation.md 3466 -> 3862 (restatement cut first, the measured remainder raised under ruling record 6513306068; the section is ordered by ruling record 7180466652). packages/spec: the parse refusal for uiReadonly: true beside readonly: true ends with "ADR-0163 (D1, D6)", pinned in field-ui-readonly.test.ts. Claude-Session: https://claude.ai/code/session_01L6bhgTpyo8gQyqf9Tj9mfz Co-authored-by: Claude --- .../37405-field-write-lock-adr-skill.md | 15 ++++ .../spec/src/data/field-ui-readonly.test.ts | 3 + packages/spec/src/data/field.zod.ts | 6 +- scripts/check-skills-token-ratchet.mjs | 22 ++++- skills/objectstack-data/SKILL.md | 6 +- skills/objectstack-data/evals/README.md | 3 +- .../evals/objects-fields-relationships.json | 13 +++ skills/objectstack-data/rules/validation.md | 81 +++++++++++++------ 8 files changed, 115 insertions(+), 34 deletions(-) create mode 100644 .changeset/37405-field-write-lock-adr-skill.md diff --git a/.changeset/37405-field-write-lock-adr-skill.md b/.changeset/37405-field-write-lock-adr-skill.md new file mode 100644 index 00000000000..1b3d09a18fe --- /dev/null +++ b/.changeset/37405-field-write-lock-adr-skill.md @@ -0,0 +1,15 @@ +--- +'@objectstack/spec': patch +'@objectstack/skills': patch +--- + +docs(skills,spec): the `objectstack-data` skill teaches which of the four field locks to use, and the `uiReadonly` + `readonly` refusal names ADR-0163 + +Clause-②: no +Metadata-protocol: none + +`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` the 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. + +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. + +`@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. diff --git a/packages/spec/src/data/field-ui-readonly.test.ts b/packages/spec/src/data/field-ui-readonly.test.ts index 15ef6161bd4..60e5f2d99c4 100644 --- a/packages/spec/src/data/field-ui-readonly.test.ts +++ b/packages/spec/src/data/field-ui-readonly.test.ts @@ -48,6 +48,9 @@ describe('Field.uiReadonly / Field.uiReadonlyWhen', () => { expect(issues).toHaveLength(1); expect(issues[0].code).toBe('custom'); expect(issues[0].message).toMatch(/^`uiReadonly: true` locks the field against editing by hand at the console/); + // [#37405] The refusal names the record of the model, so the author who + // meets it can read why there are two locks and which one to keep. + expect(issues[0].message).toMatch(/ADR-0163 \(D1, D6\)\.$/); }); it('refuses the pair through the object door too', () => { diff --git a/packages/spec/src/data/field.zod.ts b/packages/spec/src/data/field.zod.ts index 0d3ab0d986d..f9a7d525065 100644 --- a/packages/spec/src/data/field.zod.ts +++ b/packages/spec/src/data/field.zod.ts @@ -3430,7 +3430,8 @@ export const FieldSchema = lazySchema(() => { }); } } - // The hand lock beside the server lock (ruling record 7180466652): a + // The hand lock beside the server lock (ruling record 7180466652, recorded + // as ADR-0163 D6, which the message names so the reader can find the model): a // `readonly: true` field already keeps every client out, so `uiReadonly` // beside it says two things at once — refused at every door that parses a // field (`defineStack`, `os validate`, the metadata save). The conditional @@ -3444,7 +3445,8 @@ export const FieldSchema = lazySchema(() => { '`uiReadonly: true` locks the field against editing by hand at the console while API, import, action and ' + 'flow writes keep it, and this field is also `readonly: true`, which keeps every client write out. Keep ' + 'one: `readonly` when no client may write the field, `uiReadonly` when people at the console may not but ' - + 'actions, imports and the API may (each write judged by the object\'s validations).', + + 'actions, imports and the API may (each write judged by the object\'s validations). The two locks and ' + + 'which one to choose: ADR-0163 (D1, D6).', }); } diff --git a/scripts/check-skills-token-ratchet.mjs b/scripts/check-skills-token-ratchet.mjs index 5f9bb5b3cda..da0131089e0 100644 --- a/scripts/check-skills-token-ratchet.mjs +++ b/scripts/check-skills-token-ratchet.mjs @@ -914,7 +914,14 @@ export const CEILINGS = new Map([ // `references/examples-objects.md` § Object Extension Model; the rule list `main` trimmed is // the routing table here). 8983 bytes on this tree, whose stamp line is 27 bytes: 8956 priced. // ceil(($(wc -c < skills/objectstack-data/SKILL.md) - 27) / 4) == ceil(8956 / 4) - ['skills/objectstack-data/SKILL.md', 2239], + // 2239 -> 2223 (#37405, ADR-0163): LOWERED to the measurement. The first bullet of + // `## Conditional Field Rules` keeps its trap (the value is dropped, the write is not + // refused) and routes the choice of lock to `rules/validation.md` § Locking a Field in + // place of the clause on which writers `readonly: true` binds, which that section now + // carries. 8983 -> 8918 bytes (8956 -> 8891 priced), -65, -> 2223 tokens, pinned AT the + // measurement. + // ceil(($(wc -c < skills/objectstack-data/SKILL.md) - 27) / 4) == ceil(8891 / 4) + ['skills/objectstack-data/SKILL.md', 2223], // 5997 -> 6008 (the formula skills follow-ups of PRs #34443 and #34447): the // `label(record.f)` row teaches a multi-select (`multiple: true`) reading each // selected label in stored order, joined with `, `, and the built-ins line @@ -1731,7 +1738,18 @@ export const CEILINGS = new Map([ // headroom absorbed, ceiling +705, pinned AT the measurement. Authority as the // `references/examples-objects.md` row. // ceil($(wc -c < skills/objectstack-data/rules/validation.md) / 4) == ceil(13861 / 4) - ['skills/objectstack-data/rules/validation.md', 3466], + // 3466 -> 3862 (#37405, ADR-0163): GAINS `## Locking a Field`, the section the ruling of + // record on #36806 orders into this skill (ruling record 7180466652: the four spellings, + // which one to use, the sales-order status example), with one checked example. PAID DOWN + // FIRST inside the file: the two `readonly` / `readonlyWhen` bullets of § Conditional Field + // Rules become one pointer at the new section, which says the same once (and corrects their + // claim that an import is a system-context write); § Conditional Validation loses its first + // example and the lead-in of the second, whose `when` / `then` / `otherwise` rule shows + // everything the first did. -1035 bytes cut, +2621 added: 13861 -> 15447 bytes (+1586) -> + // 3862 tokens, no headroom to absorb any of it, ceiling +396, the measured remainder, pinned + // AT the measurement. Raise path 「A:先削重复,余额按实测提高」 (ruling record 6513306068). + // ceil($(wc -c < skills/objectstack-data/rules/validation.md) / 4) == ceil(15447 / 4) + ['skills/objectstack-data/rules/validation.md', 3862], // objectstack-platform ['skills/objectstack-platform/references/plugin-hooks.md', 2413], // -215 to the measurement (was 2628) diff --git a/skills/objectstack-data/SKILL.md b/skills/objectstack-data/SKILL.md index e1e6f822b25..94378cf3d2b 100644 --- a/skills/objectstack-data/SKILL.md +++ b/skills/objectstack-data/SKILL.md @@ -82,9 +82,9 @@ over `record.*` (`P\`record.status == 'paid'\``), so every form and API write honours them. - **`readonlyWhen` and `readonly: true` drop the value; they do not refuse the - write.** `readonly: true` binds non-system writes only; a `runAs:'system'` - flow, system hook or seed does write it - ([objectstack-automation → Failure routing & `runAs`](../objectstack-automation/SKILL.md#failure-routing--runas)). + write**, a button's action included. A field that only actions, imports and + the API change is `uiReadonly` + ([Locking a Field](./rules/validation.md#locking-a-field)). - **`requiredWhen` is a transition gate, not an invariant**: it judges the write, not the stored row. A fact true of every stored record is a `validations[]` `script` rule. diff --git a/skills/objectstack-data/evals/README.md b/skills/objectstack-data/evals/README.md index 41ef4dd78b2..26cfeba52df 100644 --- a/skills/objectstack-data/evals/README.md +++ b/skills/objectstack-data/evals/README.md @@ -6,7 +6,8 @@ JSON fixtures in the objectui shape (`skill_name`, `evals[]`: `prompt`, - `objects-fields-relationships.json` — naming, field types (`secret` vs `password`), relationships (junction vs multi-value lookup, `deleteBehavior`, on a `user` field too), validation (`state_machine`, unique **index**), - conditional field rules, the record owner (负责人 is `owner_id`), an + conditional field rules, the hand lock (a `uiReadonly` status field), the + record owner (负责人 is `owner_id`), an object extension placing what it brings (`place`), the `.custom` pair's whole arrangement (`relatedLists`, `{ list, hidden: true }`). - `hooks-security-seeds-datasources.json` — search mirrors via hooks, diff --git a/skills/objectstack-data/evals/objects-fields-relationships.json b/skills/objectstack-data/evals/objects-fields-relationships.json index 4e27cd38d68..d658205ce7e 100644 --- a/skills/objectstack-data/evals/objects-fields-relationships.json +++ b/skills/objectstack-data/evals/objects-fields-relationships.json @@ -515,6 +515,19 @@ ], "must_not_contain": [] } + }, + { + "id": 30, + "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?", + "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.", + "files": [], + "assertions": { + "must_contain": [ + "uiReadonly: true", + "state_machine" + ], + "must_not_contain": [] + } } ] } diff --git a/skills/objectstack-data/rules/validation.md b/skills/objectstack-data/rules/validation.md index b4b1fda4da0..a3eceb5c580 100644 --- a/skills/objectstack-data/rules/validation.md +++ b/skills/objectstack-data/rules/validation.md @@ -198,25 +198,6 @@ is a **single** nested rule applied when it holds, `otherwise` (optional) a single rule applied when it doesn't. There is no `validations: []` array — compose multiple checks as multiple top-level rules or nested conditionals. -```typescript -validations: [ - { - name: 'enterprise_requires_manager', - type: 'conditional', - when: P`record.type == 'enterprise'`, - message: 'Enterprise account validation', - then: { - name: 'manager_required', - type: 'script', - condition: P`isBlank(record.account_manager)`, - message: 'Enterprise accounts must have an account manager', - }, - }, -] -``` - -With an `otherwise` branch: - ```typescript { name: 'payment_validation', @@ -364,13 +345,8 @@ export const Invoice = ObjectSchema.create({ - `showOnCreate: false` keeps a field off every create surface; edit, the record page and lists keep it. Refused beside `required: true`. -- Use `readonlyWhen` for state-locked fields; the ObjectQL write path ignores - incoming changes when the predicate is `TRUE` (for everyone; per permission - set → field permission `when`, rules/security.md). -- **`readonly: true` governs the end-user surface, not trusted system writers.** - A stripped write (REST/UI, and any `runAs:'user'` flow) reports success. - Imports and migrations are system-context writes too. Keep the field `readonly` when automation maintains it; the flow - side: [objectstack-automation → Failure routing & `runAs`](../../objectstack-automation/SKILL.md#failure-routing--runas). +- `readonly`, `readonlyWhen` and the console-only lock: + [Locking a Field](#locking-a-field). - Use `requiredWhen` for conditional requiredness; the ObjectQL validator enforces it on submit. The removed `conditionalRequired` alias is a parse error. @@ -390,3 +366,56 @@ or `requiredWhen` refuses the write naming it, an option `visibleWhen` only a write picking the option (forms still offer it); a `readonlyWhen` field stays editable and the save succeeds without its change (logged); a formula reads `null` (logged). + +## Locking a Field + +Two questions pick the key: who is kept out, and when. + +| | Every non-system write | Only a person editing at the console | +|:--|:--|:--| +| Always | `readonly: true` | `uiReadonly: true` | +| While a `record.*` predicate is TRUE | `readonlyWhen` | `uiReadonlyWhen` | + + +```typescript +import { P } from '@objectstack/spec'; +import { ObjectSchema, Field } from '@objectstack/spec/data'; + +export const SalesOrder = ObjectSchema.create({ + name: 'sales_order', + sharingModel: 'public_read_write', + uiReadonlyWhen: P`record.status != 'draft'`, // once confirmed, only actions change the order + fields: { + status: Field.select({ // moved by the Confirm action, never typed + options: [{ label: 'Draft', value: 'draft' }, { label: 'Confirmed', value: 'confirmed' }], + defaultValue: 'draft', + uiReadonly: true, + }), + order_number: Field.text({ readonlyWhen: P`true` }), // set on create, then fixed + notes: Field.textarea({ uiReadonlyWhen: P`false` }), // editable on a confirmed order too + }, +}); +``` + +- **Left column, the server lock: the value is dropped, the write is not + refused.** REST, the UI, an import, a declarative action and a + `runAs:'user'` flow answer success without the change + (`X-ObjectStack-Dropped-Fields` names the field). `readonly: true` lets a + system writer through (a seed, a migration, a system hook, a + `runAs:'system'` flow: + [objectstack-automation → Failure routing & `runAs`](../../objectstack-automation/SKILL.md#failure-routing--runas)), + so keep it on a field automation maintains. `readonlyWhen` holds for + everyone (per permission set: a field permission `when`, + [Security](./security.md)) and is not judged on a create. +- **Right column, the hand lock: forms, inline edit, grid cells and board or + calendar drags do not offer the field, and every write still lands**, + judged by the validations (a `state_machine` on `status`). Under `readonly` + the Confirm action's own write would be dropped. Not security: whoever may + edit the record can write the field through the API. +- A console create leaves a `uiReadonly` field out: the record takes its + `defaultValue`, and a `required` field without one fails the create. +- On the **object**, `uiReadonlyWhen` locks every field of an existing record. + A field's own `uiReadonly: true` or `uiReadonlyWhen` replaces it; + `uiReadonly: false` does not. +- `uiReadonly` beside `readonly: true` is refused. Only read-only has a `ui` + twin: there is no `uiVisibleWhen`. From 6e397de7845d8b00a51a7c57dc7c97ac00a70788 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 29 Nov 2026 01:00:06 +0000 Subject: [PATCH 3/3] docs(skills): the readonly trap names a declarative action, and the lock table says which row a system write passes Contract review of the previous head, one should-fix and one nit: - skills/objectstack-data/SKILL.md: "a button's action included" was true of a declarative action only; a script action's body runs in a system context and its write to a readonly: true field lands. The clause now reads "a declarative action's included". The ratchet row follows to the measurement, 2224. - skills/objectstack-data/rules/validation.md: the lock table's left column was headed "Every non-system write" over readonlyWhen too, which binds system writes as well. The header is "Every write" and the readonly: true cell carries "(system writes pass)"; the Confirm sentence names a declarative Confirm. 15448 bytes, the row stays 3862. Claude-Session: https://claude.ai/code/session_01L6bhgTpyo8gQyqf9Tj9mfz Co-authored-by: Claude --- .changeset/37405-field-write-lock-adr-skill.md | 2 +- scripts/check-skills-token-ratchet.mjs | 18 +++++++++--------- skills/objectstack-data/SKILL.md | 4 ++-- skills/objectstack-data/rules/validation.md | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.changeset/37405-field-write-lock-adr-skill.md b/.changeset/37405-field-write-lock-adr-skill.md index 1b3d09a18fe..38872b90a95 100644 --- a/.changeset/37405-field-write-lock-adr-skill.md +++ b/.changeset/37405-field-write-lock-adr-skill.md @@ -8,7 +8,7 @@ docs(skills,spec): the `objectstack-data` skill teaches which of the four field Clause-②: no Metadata-protocol: none -`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` the 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. +`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. 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. diff --git a/scripts/check-skills-token-ratchet.mjs b/scripts/check-skills-token-ratchet.mjs index da0131089e0..20083a325da 100644 --- a/scripts/check-skills-token-ratchet.mjs +++ b/scripts/check-skills-token-ratchet.mjs @@ -914,14 +914,14 @@ export const CEILINGS = new Map([ // `references/examples-objects.md` § Object Extension Model; the rule list `main` trimmed is // the routing table here). 8983 bytes on this tree, whose stamp line is 27 bytes: 8956 priced. // ceil(($(wc -c < skills/objectstack-data/SKILL.md) - 27) / 4) == ceil(8956 / 4) - // 2239 -> 2223 (#37405, ADR-0163): LOWERED to the measurement. The first bullet of + // 2239 -> 2224 (#37405, ADR-0163): LOWERED to the measurement. The first bullet of // `## Conditional Field Rules` keeps its trap (the value is dropped, the write is not - // refused) and routes the choice of lock to `rules/validation.md` § Locking a Field in - // place of the clause on which writers `readonly: true` binds, which that section now - // carries. 8983 -> 8918 bytes (8956 -> 8891 priced), -65, -> 2223 tokens, pinned AT the - // measurement. - // ceil(($(wc -c < skills/objectstack-data/SKILL.md) - 27) / 4) == ceil(8891 / 4) - ['skills/objectstack-data/SKILL.md', 2223], + // refused, a declarative action's included) and routes the choice of lock to + // `rules/validation.md` § Locking a Field in place of the clause on which writers + // `readonly: true` binds, which that section now carries. 8983 -> 8923 bytes (8956 -> + // 8896 priced), -60, -> 2224 tokens, pinned AT the measurement. + // ceil(($(wc -c < skills/objectstack-data/SKILL.md) - 27) / 4) == ceil(8896 / 4) + ['skills/objectstack-data/SKILL.md', 2224], // 5997 -> 6008 (the formula skills follow-ups of PRs #34443 and #34447): the // `label(record.f)` row teaches a multi-select (`multiple: true`) reading each // selected label in stored order, joined with `, `, and the built-ins line @@ -1745,10 +1745,10 @@ export const CEILINGS = new Map([ // Rules become one pointer at the new section, which says the same once (and corrects their // claim that an import is a system-context write); § Conditional Validation loses its first // example and the lead-in of the second, whose `when` / `then` / `otherwise` rule shows - // everything the first did. -1035 bytes cut, +2621 added: 13861 -> 15447 bytes (+1586) -> + // everything the first did. -1035 bytes cut, +2622 added: 13861 -> 15448 bytes (+1587) -> // 3862 tokens, no headroom to absorb any of it, ceiling +396, the measured remainder, pinned // AT the measurement. Raise path 「A:先削重复,余额按实测提高」 (ruling record 6513306068). - // ceil($(wc -c < skills/objectstack-data/rules/validation.md) / 4) == ceil(15447 / 4) + // ceil($(wc -c < skills/objectstack-data/rules/validation.md) / 4) == ceil(15448 / 4) ['skills/objectstack-data/rules/validation.md', 3862], // objectstack-platform diff --git a/skills/objectstack-data/SKILL.md b/skills/objectstack-data/SKILL.md index 94378cf3d2b..12fa061fe6a 100644 --- a/skills/objectstack-data/SKILL.md +++ b/skills/objectstack-data/SKILL.md @@ -82,8 +82,8 @@ over `record.*` (`P\`record.status == 'paid'\``), so every form and API write honours them. - **`readonlyWhen` and `readonly: true` drop the value; they do not refuse the - write**, a button's action included. A field that only actions, imports and - the API change is `uiReadonly` + write**, a declarative action's included. A field that only actions, imports + and the API change is `uiReadonly` ([Locking a Field](./rules/validation.md#locking-a-field)). - **`requiredWhen` is a transition gate, not an invariant**: it judges the write, not the stored row. A fact true of every stored record is a diff --git a/skills/objectstack-data/rules/validation.md b/skills/objectstack-data/rules/validation.md index a3eceb5c580..e4cf5bbae77 100644 --- a/skills/objectstack-data/rules/validation.md +++ b/skills/objectstack-data/rules/validation.md @@ -371,9 +371,9 @@ editable and the save succeeds without its change (logged); a formula reads Two questions pick the key: who is kept out, and when. -| | Every non-system write | Only a person editing at the console | +| | Every write | Only a person at the console | |:--|:--|:--| -| Always | `readonly: true` | `uiReadonly: true` | +| Always | `readonly: true` (system writes pass) | `uiReadonly: true` | | While a `record.*` predicate is TRUE | `readonlyWhen` | `uiReadonlyWhen` | @@ -410,7 +410,7 @@ export const SalesOrder = ObjectSchema.create({ - **Right column, the hand lock: forms, inline edit, grid cells and board or calendar drags do not offer the field, and every write still lands**, judged by the validations (a `state_machine` on `status`). Under `readonly` - the Confirm action's own write would be dropped. Not security: whoever may + a declarative Confirm's write would be dropped. Not security: whoever may edit the record can write the field through the API. - A console create leaves a `uiReadonly` field out: the record takes its `defaultValue`, and a `required` field without one fails the create.