Skip to content

Commit 30ff9f4

Browse files
docs(skills): objectstack-data teaches the field permission when and when to pick it over a validation rule
`rules/security.md` gains a section on the row-conditioned edit lock: the choice rule (a lock for everyone is a validation rule; a lock that depends on who edits is `when` on that set's field entries, never both), the contract example, the four boundaries (edit vote only, same object, pre-image on update, locks and never grants) and the docs pointers. `SKILL.md`'s `readonlyWhen` line names the per-role alternative inside the file's headroom. One eval case pins the contract prompt. The two touched token-ratchet rows are raised by the measured remainder under the maintainer's ruling quoted beside them. Claude-Session: https://claude.ai/code/session_01JQwxbakp4nDuCkULsj7Fyr Co-authored-by: Claude <noreply@anthropic.com>
1 parent 756220c commit 30ff9f4

4 files changed

Lines changed: 60 additions & 3 deletions

File tree

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,16 @@ export const CEILINGS = new Map([
552552
// 2026-10-24 (project decision list item 9), verbatim and untranslated, the
553553
// line for item 8 of the same message elided:
554554
// 「9. 技能文档 security.md 的 token 上限 2543 → 2563 … 同意」.
555-
['skills/objectstack-data/rules/security.md', 2563],
555+
// 2563 -> 2957 (#26179): the field permission row condition `when` — the
556+
// choice rule (a lock for everyone is a validation; a lock that depends on
557+
// who edits is `when` on that set's field entries), one example and the
558+
// four boundaries — which the file did not teach, so an author locked the
559+
// fields for every user. +396 tokens on a landed 2561, 2 absorbed by
560+
// headroom, ceiling +394. The file carries no duplicated passage to cut
561+
// first (measured: no sentence repeats in the file). Maintainer ruling
562+
// 2026-10-27 on the decision card 「skills 修复卡的教学和 eval 都撞 token 天
563+
// 花板,怎么付?」, tap A, verbatim and untranslated: 「A:先削重复,余额按实测提高」.
564+
['skills/objectstack-data/rules/security.md', 2957],
556565
// 3024 -> 3109 (2026-08-31 app-repo-principles raise, see the block above).
557566
// Severity Levels listed the three values and left the CHOICE unstated: a
558567
// block rests on a judgement a person made, so a machine-inferred signal — a
@@ -651,7 +660,15 @@ export const CEILINGS = new Map([
651660
['skills/objectstack-ai/evals/skills-tools-knowledge.json', 1074],
652661
['skills/objectstack-api/evals/endpoints-auth-routes.json', 1042],
653662
['skills/objectstack-automation/evals/flows-triggers-approvals.json', 1255],
654-
['skills/objectstack-data/evals/hooks-security-seeds-datasources.json', 894],
663+
// 894 -> 1095 (#26179): one regression case for the field permission `when`
664+
// (the contract prompt: lock the legal terms for finance from approval on,
665+
// legal keeps the edit) — expected: `when` on the finance set's entries with
666+
// `readable: true`, and NO validation rule or `readonlyWhen` locking the
667+
// fields for every user. +201 tokens, zero headroom to absorb any of it,
668+
// ceiling +201; nothing duplicated in the file to cut first. Same ruling as
669+
// the `rules/security.md` row above (2026-10-27, tap A:
670+
// 「A:先削重复,余额按实测提高」).
671+
['skills/objectstack-data/evals/hooks-security-seeds-datasources.json', 1095],
655672
['skills/objectstack-data/evals/objects-fields-relationships.json', 946],
656673
['skills/objectstack-formula/evals/cel-predicates-formulas.json', 1046],
657674
['skills/objectstack-i18n/evals/bundles-locales-coverage.json', 1004],

‎skills/objectstack-data/SKILL.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ export const Invoice = ObjectSchema.create({
218218

219219
- Use `visibleWhen` to hide irrelevant fields in ObjectUI forms.
220220
- Use `readonlyWhen` for state-locked fields; the ObjectQL write path ignores
221-
incoming changes when the predicate is `TRUE`.
221+
incoming changes when the predicate is `TRUE` (for everyone; per role →
222+
field permission `when`, rules/security.md).
222223
- **`readonly: true` governs the end-user surface, not trusted system writers.**
223224
A non-system write (REST/UI, and any `runAs:'user'` flow — the default) has
224225
the field **stripped** from any non-system write; the write reports

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@
4040
"must_contain": ["defineSeed", "externalId", "upsert", "env:", "daysFromNow"],
4141
"must_not_contain": ["new Date(", "defineDataset", "externalId: 'id'"]
4242
}
43+
},
44+
{
45+
"id": 5,
46+
"prompt": "Finance may edit a contract's legal terms (`governing_law`, `liability_cap`) while it is a draft, but not once it is approved, signing or active. Legal still edits them.",
47+
"expected_output": "Field permission entries with a row condition on the finance set: `'clm_contract.governing_law': { readable: true, editable: false, when: \"status in ['approved', 'signing', 'active']\" }` and the same for `liability_cap`; the legal set keeps its edit grant. No validation rule and no `readonlyWhen`, which would lock the fields for every user.",
48+
"files": [],
49+
"assertions": {
50+
"must_contain": ["when:", "editable: false", "readable: true", "clm_contract.governing_law"],
51+
"must_not_contain": ["validations:", "readonlyWhen"]
52+
}
4353
}
4454
]
4555
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,35 @@ bridge (warns). The compiler resolves these
116116
`owner_only_deletes`) and the object's `sharingModel` (ADR-0056 D1) over
117117
hand-written policies for the common cases.
118118

119+
## Field permissions — a row-conditioned edit lock (`when`)
120+
121+
A set's `fields` entry (`'OBJECT.FIELD': { readable, editable }`) may carry
122+
`when`, a row condition in the same canonical CEL as `rowLevelSecurity[].using`.
123+
**Choose by who loses the edit — one mechanism per need, never both:**
124+
125+
- Locked for **everyone** at that stage → a [validation rule](./validation.md)
126+
on the object (`readonlyWhen` likewise strips the write for everyone).
127+
- Locked for **some roles** only → `when` on the field entries of each set
128+
that loses the edit; the other sets keep their grant.
129+
130+
```typescript
131+
// finance may not change the contract's legal terms after approval
132+
fields: {
133+
'clm_contract.governing_law': { readable: true, editable: false, when: "status in ['approved', 'signing', 'active']" },
134+
}
135+
```
136+
137+
- **Edit vote only.** Reads are row-blind; `readable: false` beside `when` is
138+
refused at parse time.
139+
- **Same object.** Fields of the entry's object vs a literal or `current_user.*`;
140+
no relation reach (refused at `os validate` / publish, never dropped).
141+
- **Pre-image.** An update is judged on the stored row, so a write cannot unlock
142+
itself by moving `status` back; an insert on the row as sent.
143+
- **Locks, never grants.** On unmatched rows the entry is absent; another held
144+
set's `editable: true` still wins (most-permissive merge).
145+
- Docs: https://objectstack.ai/docs/permissions/field-level-security#row-conditioned-edit-locks-when
146+
and the recipe https://objectstack.ai/docs/permissions/access-recipes#data-lock-fields-for-a-position-once-a-record-reaches-a-stage
147+
119148
## Sensitive fields — `secret` type + `requiredPermissions`
120149

121150
`maskingRule` is **live** (FieldMasker). Two more channels:

0 commit comments

Comments
 (0)