Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/37405-field-write-lock-adr-skill.md
Original file line number Diff line number Diff line change
@@ -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` 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.

`@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.

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions docs/adr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -26,7 +26,7 @@
| Amended | 1 |
| Partially implemented | 1 |
| Revised | 1 |
| **Total** | **163** |
| **Total** | **164** |

## Shared numbers

Expand Down Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions packages/spec/src/data/field-ui-readonly.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/spec/src/data/field.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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).',
});
}

Expand Down
22 changes: 20 additions & 2 deletions scripts/check-skills-token-ratchet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> 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, 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
Expand Down Expand Up @@ -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, +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(15448 / 4)
['skills/objectstack-data/rules/validation.md', 3862],

// objectstack-platform
['skills/objectstack-platform/references/plugin-hooks.md', 2413], // -215 to the measurement (was 2628)
Expand Down
6 changes: 3 additions & 3 deletions skills/objectstack-data/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
`validations[]` `script` rule.
Expand Down
3 changes: 2 additions & 1 deletion skills/objectstack-data/evals/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions skills/objectstack-data/evals/objects-fields-relationships.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
}
]
}
81 changes: 55 additions & 26 deletions skills/objectstack-data/rules/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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.
Expand All @@ -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 write | Only a person at the console |
|:--|:--|:--|
| Always | `readonly: true` (system writes pass) | `uiReadonly: true` |
| While a `record.*` predicate is TRUE | `readonlyWhen` | `uiReadonlyWhen` |

<!-- os:check -->
```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`
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.
- 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`.
Loading