Skip to content

Commit 934ac07

Browse files
docs(skills): objectstack-automation teaches that a clearable state lists '' among its targets (#36559)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8Uwe38nh7MLTBwLqZZeHCsq)_ Fixes #36161 Clause-②: no Metadata-protocol: none Ride-along: the `employee` lifecycle eval in `skills/objectstack-data/evals/objects-fields-relationships.json` now declares `initialStates` (declared by the seat; source: a finding in the thread of card 36534, the same state-machine teaching theme). ## 维护者速读 - 用户能看到什么变化:用 AI 搭应用的人,照自动化技能写状态机时,会被告知「想让某个状态可以清空,就要在它的去向里写上空值」;此前技能没提,照着写出来的应用会拒绝用户清空状态字段。 - 为什么做:平台已经把「清空状态」当成一次状态流转来判定,技能文字落后于已上线的规则,这是补上那句教学。 - 出错会怎样:只改教学文字,不改任何运行行为;写错了最多是 AI 少写或多写一个空值去向,撤回这个改动即可恢复原文。 - 要你做什么:无。 ## What changes `skills/objectstack-automation/references/state-machines-and-approvals.md`, state-machine notes, one new entry: > **Clearing the field is a transition to `''`.** An update to `null` or `''` is judged from the stored state: a clearable state lists `''` in its targets, e.g. `paused: ['open', '']`; from any other listed state it is refused (`invalid_transition`, `constraint.to: ''`). Quoted from the merged code, not from the card. `checkStateMachine` in `packages/objectql/src/validation/rule-validator.ts` (main d463c46) reads the stored state, maps an empty target (`undefined`, `null` or the empty string) to the key `''`, and answers `fallback('invalid_transition', { from: fromKey, to: toKey }, …)` when the stored state's list does not include it. Two points where the skill text is narrower than the card's sentence, both on purpose: - The card writes `to: ''`. In the code that pair is the refusal's `constraint` (`{ from, to: '' }`), so the skill says `constraint.to: ''`. - The card writes "a clear from any other state is refused". The code returns no error when the stored state is not a key of `transitions` (the existing "unlisted from state is not guarded" note), so the skill says "any other listed state". The new entry is paid for by shortening the section intro and six neighbouring notes in the same file; each keeps its fact. The token ceiling row is untouched. Ride-along, second commit: in `skills/objectstack-data/evals/objects-fields-relationships.json`, the `employee` lifecycle case's expected answer declared a `state_machine` with `transitions` only, which publish refuses for a machine that runs on insert (`state-machine-no-initial-states`). It now declares `initialStates: ['draft']` with the one-clause reason its sibling `order` case uses, and `must_contain` requires `initialStates`. The seeds eval in `hooks-security-seeds-datasources.json` that mentions `state_machine` only says seed rows skip that rule; it teaches no machine and is unchanged. ## Tests No code path changes, so there is no test to add or ablate. The one `os:check` block in the section is byte-identical. ## Acceptance notes - Scope-out, the ui lane's: the card notes that the Studio validations panel parses targets with a filter that drops empty strings, so it cannot write `''` and loses an existing one on edit. Not touched here; no file under `ui/` is in this diff. - Commit trailer: the commit carries the model-free trailer pair AGENTS.md prescribes. The dispatch order asked for a trailer naming a model; AGENTS.md outranks it. - Changeset: `skills/` ships as `@objectstack/skills`, so this takes a `patch` changeset (`.changeset/36161-automation-skill-clearable-state.md`), not `skip-changeset`. ## Verification Readings at head dd527b9 against main d463c46. | Reading | Before | After | |:--|--:|--:| | The edited file, lines | 385 | 386 | | The edited file, bytes | 23726 | 23734 | | The edited file, tokens (ceiling 5936) | 5932 | 5934 | | All `SKILL.md` files, lines | 4951 | 4951 | | Ratcheted authored catalog, tokens | 197573 | 197575 | | The eval file (measured, not ratcheted), tokens | 7984 | 8032 | | Whole shipped bundle, tokens | 293321 | 293371 | Net `skills/**` lines: +2 (25 added, 23 removed): +1 in the reference, +1 in the eval file. Read first: the "Notes" list of the state-machine section in the diff — the new entry, then the six shortened notes beside it (check that none lost a fact). Two-minute check: `node scripts/check-skills-token-ratchet.mjs` exits 0 and prints `state-machines-and-approvals.md is 5934 tokens (ceiling 5936; headroom 2)`; `git grep -n "''" -- skills/objectstack-automation/references/state-machines-and-approvals.md` shows the clearable-state entry. <details><summary>Local gate subset (derived by dispatch-gates, 49 families)</summary> 44 exited 0 at dd527b9, among them `check-skills-token-ratchet` (scan and self-test), `check:skill-refs`, `check:skill-served-sections`, `check:skill-links`, `check:skill-identifier-liveness`, `check:skill-compatibility`, `check:skill-frame-sync`, `check:role-word`, `check:doc-authoring`, `check:nul-bytes`, `check:published-files`, `check-empty-changeset`, `check-changeset-no-major`, `check-adr-0087-registration`, `check-closing-keyword-parity`. NOT MEASURED locally, left to CI: - `check:dts-closure`, `check:dual-build-cjs-loads`, `check:lean-entry-closure`, `check:sourcemap-no-sources-content`, `check:doc-formula-expressions` — each exited 3, prerequisite not met: they read built `dist/` and this diff touches no package, so no build closure was made. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxbZeHNsF3RWcWpj7rGj)_ <!-- signed: repo:objectstack#1 · os-warren · session_01JQwxbZeHNsF3RWcWpj7rGj --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 92e660d commit 934ac07

3 files changed

Lines changed: 41 additions & 23 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/skills': patch
3+
---
4+
5+
docs(skills): `objectstack-automation` teaches that clearing a state-machine field is a transition to `''`, and how to make a state clearable
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The state-machine notes in `references/state-machines-and-approvals.md` gain one entry: an update that sets the state field to `null` or `''` is judged from the stored state as a transition to `''`. A state meant to be clearable lists `''` in its targets, e.g. `paused: ['open', '']`; from any other state the machine lists, the clear is refused with `invalid_transition`, and the refusal's `constraint` carries `to: ''` beside `from`. A stored state that is not a key of `transitions` stays unguarded, as before.
11+
12+
This is the behaviour `@objectstack/objectql` already ships; the skill only teaches it.
13+
14+
Paid for by deletion in the same file, with the token ceiling unchanged (5936): the wording of the section's intro and of six neighbouring notes was shortened, each keeping its fact — one rule per field, `initialStates` gating insert, guards and reactions living outside the machine, the introspection route, the unguarded unlisted `from` state, and the `record.<field>` scope of sibling predicates.
15+
16+
Ride-along, same theme: in the `objectstack-data` eval `objects-fields-relationships.json`, the `employee` lifecycle case's expected answer declared a `state_machine` with `transitions` only, which publish refuses for a machine that runs on insert (`state-machine-no-initial-states`). It now declares `initialStates: ['draft']` with the reason, and the case's `must_contain` requires `initialStates`.

‎skills/objectstack-automation/references/state-machines-and-approvals.md‎

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
## State Machines & Approvals
22

3-
A record's **state machine** locks the legal transitions of its status field
4-
so that automation cannot drive a record into an illegal state. Unmarked
5-
blocks are fragments.
3+
A record's **state machine** locks its status field's legal transitions so
4+
automation cannot drive it into an illegal state. Unmarked blocks are
5+
fragments.
66

77
### State Machine — a `state_machine` validation rule (ADR-0020)
88

99
Since **ADR-0020** there is **no `workflow` metadata type** and no
1010
`object.stateMachines` map. A record state machine is **one `state_machine`
1111
validation rule** in the object's `validations` array: a flat `field` +
12-
`{ from: [allowedTo] }` transition table. It is **enforced on the write path** —
13-
an update whose `field` moves to a state not listed for the current state is
12+
`{ from: [allowedTo] }` transition table. It is **enforced on the write path**:
13+
an update moving `field` to a state not listed for the current one is
1414
rejected with the rule's `message`.
1515

1616
<!-- os:check -->
@@ -34,27 +34,28 @@ const rule: StateMachineValidation = {
3434
```
3535

3636
Notes:
37-
- **One rule per field.** Parallel lifecycles (e.g. `status` + `payment_status`)
38-
are N separate `state_machine` rules.
39-
- **`initialStates`** gates INSERT: a record created with its state field
40-
outside this list is rejected. `transitions` only governs updates, so a
41-
machine that runs on insert without it is refused at publish
37+
- **One rule per field.** Parallel lifecycles (`status` + `payment_status`)
38+
are separate `state_machine` rules.
39+
- **`initialStates`** gates INSERT: a record created in a state outside
40+
this list is rejected. `transitions` only governs updates, so a
41+
machine running on insert without it is refused at publish
4242
(`state-machine-no-initial-states`); an update-only machine
4343
(`events: ['update']`) needs none.
4444
- **Conditional transitions / side effects are NOT part of the machine.** A
45-
guard is expressed as a sibling `script` / `conditional` validation rule;
46-
"do something when the state changes" is a **record-triggered Flow**
47-
(ADR-0019) — a `record_change` flow whose start-node condition gates on the
48-
transition.
45+
guard is a sibling `script` / `conditional` rule; a reaction to
46+
a state change is a `record_change` flow (ADR-0019) whose start-node
47+
condition gates on the transition.
4948
- **Introspection:** `GET /api/v1/meta/object/:name/state/:field?from=:state`
50-
returns the legal next states so UIs/agents can read the transition table
51-
instead of hard-coding it (`next: null` = no FSM governs the field, **or**
52-
`?from=` was omitted — always pass `from`).
53-
- **An unlisted `from` state is NOT guarded.** An update whose current state is
54-
not a key of `transitions` is treated leniently (no lock) — list every state
55-
you want guarded rather than relying on an implicit "any → any".
56-
- Predicate conditions in sibling rules evaluate against the merged record in
57-
the **`record.<field>`** CEL scope (bare field names do not resolve).
49+
returns the legal next states for UIs/agents to read (`next: null` = no
50+
FSM governs the field, **or** `?from=` was omitted — always pass `from`).
51+
- **An unlisted `from` state is NOT guarded.** An update whose current state
52+
is not a key of `transitions` passes — list every state to guard.
53+
- **Clearing the field is a transition to `''`.** An update to `null` or `''`
54+
is judged from the stored state: a clearable state lists `''` in its
55+
targets, e.g. `paused: ['open', '']`; from any other listed state it is
56+
refused (`invalid_transition`, `constraint.to: ''`).
57+
- Sibling-rule predicates read the merged record in the **`record.<field>`**
58+
CEL scope (bare field names do not resolve).
5859
- **An AI-gated irreversible transition** pairs this rule with a lock on
5960
`field`: **objectstack-ai** → Common Pitfalls.
6061

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@
4545
{
4646
"id": 3,
4747
"prompt": "On `employee`: email must be unique within each organization, `status` may only move draft → active → terminated, and a `contract_end` earlier than `contract_start` must be rejected.",
48-
"expected_output": "Uniqueness is an index, not a validation type: `indexes: [{ fields: ['email'], unique: 'organization' }]` (the scope is stated; `type` / `partial` are retired). The lifecycle is one `state_machine` validation with `field: 'status'`, `transitions: { draft: ['active'], active: ['terminated'], terminated: [] }` and a `message`. The date rule is a `script` validation (inverted: fails when the expression is true) or `cross_field`, written as bare CEL over `record.` with explicit `!= null` guards.",
48+
"expected_output": "Uniqueness is an index, not a validation type: `indexes: [{ fields: ['email'], unique: 'organization' }]` (the scope is stated; `type` / `partial` are retired). The lifecycle is one `state_machine` validation with `field: 'status'`, `transitions: { draft: ['active'], active: ['terminated'], terminated: [] }`, `initialStates: ['draft']` and a `message` — `transitions` governs only UPDATE, so publish refuses a machine that runs on insert without it (`state-machine-no-initial-states`). The date rule is a `script` validation (inverted: fails when the expression is true) or `cross_field`, written as bare CEL over `record.` with explicit `!= null` guards.",
4949
"files": [],
5050
"assertions": {
5151
"must_contain": [
5252
"unique: 'organization'",
5353
"state_machine",
5454
"transitions",
55+
"initialStates",
5556
"record.",
5657
"!= null"
5758
],

0 commit comments

Comments
 (0)