Skip to content

Commit 475ae46

Browse files
docs(skills): a gated action guards its door only; lock the field an irreversible transition changes (#35310)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wg1XdbbGasMNVx41tq3hZKV4)_ Fixes #35068 Fixes #35041 Fixes #34237 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:objectstack-ai 技能新增一条常见陷阱「只给动作加了闸,没锁状态字段」,教作者把不可逆状态迁移写成「需确认的 script 动作 + 状态字段锁(`readonly: true` 约束所有非系统写;字段权限不给 `editable` 不约束 Modify All 持有者),并在动作上声明 `requiredPermissions`」;工具名解析阶梯补上第四个来源 `MCP_FILE_TOOL_NAMES`(docs 的 tools.mdx 同步);MCP prompts 段落写明 `mcpPrompt: false` 及 stdio 例外。 - 为什么改:`ai.requiresConfirmation` 只守动作这一扇门,场景卡上代理被 428 拒后改用 `update_record` 直接把工单关了;按「三个问题 同意」不扩大闸门,改为教作者锁字段。另两张 p3 卡是同文件的过期文字。 - 风险与回滚:纯技能文字与一行文档,不动任何代码与契约;回滚即 revert 本 PR。 - 先看:`skills/objectstack-ai/SKILL.md` 的 Common Pitfalls 第 2 条(锁选项是否与实测一致);其次同文件 MCP prompts 段落;`state-machines-and-approvals.md` 只多一行指针。 - 两分钟验证:`node scripts/check-skills-token-ratchet.mjs`,预期 objectstack-ai/SKILL.md 6693 / 6801、state-machines-and-approvals.md 5936 / 5936,全绿。 - 需要你做的:审阅后合并(`skills/**` 为 Tier H 受管面)。 ## What changes **#35068 — gated action plus a field lock.** Scope 1 was measured before any text was written (below). `skills/objectstack-ai/SKILL.md` Common Pitfalls gains item 2, "Gating the action, not the state": `ai.requiresConfirmation` guards the action's own door only; an irreversible transition is a gated `script` action over a field a non-system write cannot set: `readonly: true` binds every non-system caller, while a field permission without `editable` binds only a caller no held set grants it (Modify All grants it); the body skips the caller's edit right, so the action declares `requiredPermissions`; a declarative `operation: 'update'` action and a `flow` action under `runAs: 'user'` write as the caller, so the lock stops them too; `readonlyWhen` and a `state_machine` rule bind the elevated body as well, so neither is the door, while a `state_machine` dead-end still makes the reached state final. Pitfall 1 now says the confirmation gate guards its door only. `skills/objectstack-automation/references/state-machines-and-approvals.md` carries one pointer line to it (taught once, in objectstack-ai, where the gate is taught; no restatement). **#35041 — the ladder's fourth source.** The resolution ladder names four sources; item 4 is `MCP_FILE_TOOL_NAMES` (the pinned export in the same constants file, so the list cannot drift), resolved only for a skill MCP can offer (`mcpPrompt` not `false`). `content/docs/ai/tools.mdx` (the one ladder sentence, scope addition 6964629901) says the same. **#34237 — `mcpPrompt` in the MCP prompts paragraph.** The paragraph names the optional key (`false` = in-product only, never offered over MCP on any connection, whatever the binding; absent or `true` = the binding rule), and the stdio sentence states the exception. ### Scope 1 measurement (tree 3fb7025 + this branch, no code changed) | Writer | static `readonly: true` | `readonlyWhen` (TRUE) | field permission without `editable` | `state_machine` | |:--|:--|:--|:--|:--| | `script` action body (`ctx.api`, elevated) | LANDS | STRIPPED | bypassed | enforced | | raw data write as the caller (MCP `update_record`, REST, form) | STRIPPED | STRIPPED | refused 403 unless a held set grants `editable` (Modify All does) | enforced | | declarative `operation: 'update'` action | STRIPPED (writes as the caller) | STRIPPED | refused 403 | enforced | Anchors: - The body runs elevated: `packages/runtime/src/action-execution.ts:3901` (`buildActionExecutionContext` returns `{ ...ec, isSystem: true }` with the `'action'` mark). - The static strip is gated on the context: `packages/objectql/src/engine-update.ts:1411` (`staticReadonlyStripRuns = !opCtx.context?.isSystem`) and `:1494`. - The conditional strip runs for every caller, `isSystem` included: `packages/objectql/src/engine-update.ts:1476`; the comment at `:1460-1467` says `isSystem` "is still NOT an exemption here". - Field-permission writes: the bypass is `packages/plugins/plugin-security/src/security-plugin-authz-middleware.ts:695` and the 403 is `:1662`. - The declarative update writes as the caller: `packages/runtime/src/action-execution.ts:4883` (`callData('update', …, ec)`, the comment above it reads "⛔ `ec`, never `buildActionExecutionContext(ec)`"). - The state machine is skipped only on seed replay or an explicit flag: `packages/objectql/src/engine-top-level.ts:4274-4275` (`shouldSkipStateMachine`). - The same table is already measured in the header of `packages/lint/src/validate-readonly-action-writes.ts`. Result: the action body's own write to a `readonly: true` field is KEPT and its write to a `readonlyWhen`-locked field is STRIPPED. So the lock that binds every non-system caller is `readonly: true`; a field permission without `editable` does not bind a Modify All holder; `readonlyWhen` is not the door. A `state_machine` rule binds every writer: it makes the state final, and it cannot be the door. ## Tests Text-only change; no committed test (the measurement used existing pins, run here). <details><summary>Scope 1 pins — objectql, 3 files, 25 tests passed</summary> `pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2 src/engine-readonly-update-strip-system-gate.test.ts src/engine-readonly-when-derived-writes.test.ts src/engine-repo-execute-elevation.test.ts`, after building the objectql dependency closure. Output: `Test Files 3 passed (3)`, `Tests 25 passed (25)`, `os-verify-lock: VERDICT command-exit 0`. - `engine-readonly-update-strip-system-gate.test.ts`: a caller-supplied `readonly` value lands exactly when `isSystem` is set. - `engine-readonly-when-derived-writes.test.ts`, "LOCK 2 — isSystem does NOT exempt a caller-supplied value". - `engine-repo-execute-elevation.test.ts`, "a readonly-field write through ctx.api LANDS, matching REST/MCP". </details> ## Acceptance notes - Line budget, PAID DOWN FIRST in the same files. `skills/objectstack-ai/SKILL.md`: the "Default for metadata apps" paragraph is cut, because it restated the App AI Blueprint table above it. The ladder item 1's ADR-0109 sentence is cut, because it restated *Tool metadata*. `state-machines-and-approvals.md`: three restatements are cut. The `[]` dead-end sentence restated the code comment `final — no outgoing transitions`; ", one per field" restated **One rule per field**; and "Do not carry the `record.x` habit…" restated the sentence before it. Fix round (af46d3b, review 6999708959 S1/S2): +42 tokens, paid first by cutting pitfall 1's retired-tool sentence (taught under Tool metadata) and folding the agents-are-internal lead into the skills-entry sentence; net 6680 -> 6693 / 6801. - Neither ratchet row moves, so no ceiling is raised and the standing ruling 「A:先削重复,余额按实测提高」 (ruling record 6513306068, letter B) is not invoked for a raise. The remainder fits under the existing ceilings. - Scope 3 items (the 428 refusal text; the scenario build prompt) are other cards and are not touched here. - `pnpm check:dual-build-cjs-loads` NOT MEASURED locally (exit 3, PREREQUISITE NOT MET: reads every package's `dist/`); CI runs it. ## Verification Readings at head 7611288 (tree objectstack-ai/objectstack). <details><summary>Skills size, before (origin/main 3fb7025) and after</summary> | File | lines | tokens / ceiling | |:--|:--|:--| | `skills/objectstack-ai/SKILL.md` | 443 → 462 | 6365 → 6693 / 6801 | | `skills/objectstack-automation/references/state-machines-and-approvals.md` | 392 → 392 | 5936 → 5936 / 5936 (23744 → 23743 bytes) | | all `skills/*/SKILL.md` (lines) | 4835 → 4854 | | | bundle total (whole shipped tree, tokens) | | 270968 → 271283 | </details> <details><summary>Local gate subset — 74 derived families, 73 exit 0, 1 NOT MEASURED</summary> The list was derived with `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` against merge base 3fb7025, which gave 74 families. Every family ran, and the exit code was captured before any pipe. - 73 families exit 0. Among them: `check:skills-token-ratchet`, `check:skill-links`, `check:skill-refs`, `check:skill-docs`, `check:skill-served-sections`, `check:skill-examples` (345 prose examples type-check), `check:doc-authoring`, `check:nul-bytes`, `check:pm-skill-id-lint`, `check:skill-identifier-liveness`, `check:docs` and `check:docs-spec-enumerations`. - `check:skill-examples` and `check:lean-entry-closure` exited 3 on the first pass, because their built inputs were missing. Both exited 0 after `client-react` and `objectql` were built. - `check:dual-build-cjs-loads` exited 3, PREREQUISITE NOT MET. - The reconciliation `dispatch-gates --ran` printed: `74 derived famil(ies) accounted for — 73 run, 1 NOT-MEASURED (1 DERIVED from a recorded exit 3)`. - `node scripts/pm/overlap-check.mjs --branch=HEAD` printed `VERDICT clean exit 0`. It merges cleanly with origin/main, with #35129 (which shares the ai SKILL.md) and with #35002 (which shares the state-machines file). </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Utp6CazXu8zyYD5PC6J2u7 <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6CazXu8zyYD5PC6J2u7 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f1bf850 commit 475ae46

4 files changed

Lines changed: 60 additions & 25 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/skills': patch
3+
---
4+
5+
docs(skills): objectstack-ai teaches that an AI-gated action guards its own door only, and pairs an irreversible transition with a lock on the field it changes; the tool-name ladder names its fourth source and the MCP prompts paragraph names `mcpPrompt`
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
objectstack-ai's Common Pitfalls gains "Gating the action, not the state". `ai.requiresConfirmation` guards the action's door, and an agent can still write the same field with `update_record` or any data write. An irreversible transition is a gated `script` action, whose body writes elevated, over a field a non-system write cannot set. `readonly: true` binds every non-system caller (the value is stripped); a field permission without `editable` (refused `403`) binds only a caller no held set grants it, and Modify All grants it. The body skips the caller's edit right, so the action declares who may run it in `requiredPermissions`. A declarative `operation: 'update'` action and a `flow` action under `runAs: 'user'` write as the caller, so the lock stops them too. `readonlyWhen` and a `state_machine` rule bind the elevated body as well, so neither is the door; a `state_machine` dead-end still makes the reached state final for every writer. objectstack-automation's `references/state-machines-and-approvals.md` points to it.
11+
12+
The resolution ladder for `skill.tools[]` names four sources: the fourth is `MCP_FILE_TOOL_NAMES`, the MCP door's file tools, resolved only for a skill MCP can offer (`mcpPrompt` not `false`).
13+
14+
The paragraph on which skills MCP offers as prompts names `mcpPrompt`: `false` keeps a skill for the in-product agents only, never offered over MCP on any connection whatever its binding, and the stdio transport withholds it too; absent or `true` keeps the binding rule.

‎content/docs/ai/tools.mdx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ export const CaseHandoverSkill = defineSkill({
190190

191191
## How the name is resolved
192192

193-
A `skill.tools[]` entry resolves against three sources, in order:
193+
A `skill.tools[]` entry resolves against three sources, in order, and a skill
194+
MCP can offer (`mcpPrompt` not `false`) against a fourth, the MCP door's file
195+
tools (`MCP_FILE_TOOL_NAMES` in `@objectstack/spec/system`):
194196

195197
1. the stack's own `tools[]` names — the refinement records on this page;
196198
2. the curated registry of tools the platform runtime registers at boot;

‎skills/objectstack-ai/SKILL.md‎

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ Agent → Skill → Tool
3636
└─ Autonomous actor with role, instructions, and guardrails
3737
```
3838

39-
Agents are platform-internal (☁️ `ask` / `build`; reference section at the
40-
bottom). **Skills are your entry point** — you extend the platform by authoring
41-
skills, and a skill reaches tools by naming them.
39+
**Skills are your entry point** — agents are platform-internal (reference
40+
section at the bottom), so you extend the platform by authoring skills, and a
41+
skill reaches tools by naming them.
4242

4343
---
4444

@@ -67,11 +67,11 @@ conditions.
6767
6868
### Naming the tools: the resolution ladder
6969

70-
A `skill.tools[]` entry resolves against the union of three sources
71-
(`collectToolUniverse` in `packages/lint/src/validate-ai-tool-references.ts`):
70+
A `skill.tools[]` entry resolves against the union of four sources
71+
(`packages/lint/src/validate-ai-tool-references.ts`):
7272

73-
1. **`stack.tools[].name`** — records your own stack declares. ADR-0109: the
74-
default third-party path declares **none** (see *Tool metadata* below).
73+
1. **`stack.tools[].name`** — records your own stack declares (none by
74+
default: *Tool metadata* below).
7575
2. **`PLATFORM_PROVIDED_TOOL_NAMES`** — the statically-registered platform
7676
tools, flattened from `PLATFORM_TOOLS_BY_PACKAGE` in
7777
`packages/spec/src/system/constants/platform-tool-names.ts`: data /
@@ -81,8 +81,11 @@ A `skill.tools[]` entry resolves against the union of three sources
8181
3. **`action_<name>`** — one tool per AI-exposed Action of your own stack
8282
(`PLATFORM_TOOL_FAMILY_PREFIXES`). **The default path** for anything your app
8383
does.
84+
4. **`MCP_FILE_TOOL_NAMES`** (same file) — the MCP door's file tools, resolved
85+
only for a skill MCP can offer (`mcpPrompt` not `false`): no in-product turn
86+
registers them.
8487

85-
A name in none of the three raises **`ai-skill-tool-unresolved`** (warning,
88+
A name none of them resolves raises **`ai-skill-tool-unresolved`** (warning,
8689
ADR-0078 advisory-first). The rule exists because one audited app shipped 10
8790
fictional tools across 6 skills through `validate` / `lint` clean, and became a
8891
copilot claiming abilities it did not have.
@@ -332,11 +335,27 @@ there is **no top-level `temperature` / `maxTokens`** on an agent
332335
there is no storage backend to choose — and neither is a gate. For a gate
333336
that is **enforced**, use
334337
`enableActionApproval: true` (approval queue ☁️), `ai.requiresConfirmation` on
335-
the **action**, or `approval: 'always'` on an MCP tool binding. AI metadata
336-
edits are already gated: they land as drafts a human must publish (ADR-0033).
337-
⚠️ `requiresConfirmation` on the **tool** was REMOVED (ADR-0033 §2; retired
338-
above). There is no `requireApprovalFor` field.
339-
2. **Indexing everything.** A knowledge source without a `where` filter and
338+
the **action** (its door only, pitfall 2), or `approval: 'always'` on an MCP
339+
tool binding. AI metadata edits are already gated: they land as drafts a
340+
human must publish (ADR-0033). There is no `requireApprovalFor` field.
341+
2. **Gating the action, not the state.** `ai.requiresConfirmation` guards the
342+
action's own door only: an agent can still write the field it changes with
343+
`update_record` or any data write, and the write lands. An irreversible
344+
transition is a gated action **plus a lock on that field**: a `script`
345+
action, whose body writes elevated (`isSystem`), over a field a non-system
346+
write cannot set. `readonly: true` binds every non-system caller (the value
347+
is stripped, **objectstack-data** → `readonly`); a field permission without
348+
`editable` (refused `403`) binds only a caller no held set grants it, and
349+
Modify All grants it, so an admin's agent still writes the field. The body
350+
skips the caller's edit right: declare who may run the action in its
351+
`requiredPermissions` (ADR-0066). A declarative
352+
`operation: 'update'` action, and a `flow` action under `runAs: 'user'`,
353+
write as the caller, so the lock stops them too. `readonlyWhen` and a
354+
`state_machine` rule bind the elevated body as well, so neither is the
355+
door; a `state_machine` dead-end (`closed: []`) still makes the reached
356+
state final for every writer (**objectstack-automation**
357+
`references/state-machines-and-approvals.md`).
358+
3. **Indexing everything.** A knowledge source without a `where` filter and
340359
curated `contentFields` fills the index with drafts and boilerplate that
341360
pollute retrieval. Source hygiene is the metadata's job; relevance tuning
342361
belongs to the adapter.
@@ -351,10 +370,6 @@ there is **no top-level `temperature` / `maxTokens`** on an agent
351370
| Knowledge source | `src/knowledge/sales-kb.ts` | `KnowledgeSourceSchema` metadata, registered at boot via `KnowledgeServicePlugin({ sources })` |
352371
| Central registration | `defineStack({ skills: [...] })` | `agents` / `tools` / `skills` are the only AI stack collections — knowledge sources have none, agents are platform-supplied, and `tools` is not the default path |
353372

354-
Default for metadata apps: push business capability into **skills**, expose
355-
business logic as **AI-exposed Actions**, wire domain knowledge through
356-
**knowledge sources**.
357-
358373
---
359374

360375
## Platform agents — reference only ☁️
@@ -400,8 +415,12 @@ there but is read: `registerSkillPrompts` offers a skill on `prompts/list` /
400415
`prompts/get` only when its server lists every tool the skill binds — a plain
401416
name by that tool, a wildcard by any match, an `action_*` entry also by
402417
`run_action`. That covers the HTTP door and any host server that calls it; the
403-
plugin's own stdio transport lists every skill. Bind a tool no MCP family
404-
serves (the MCP table above) and no filtering server offers the skill.
418+
plugin's own stdio transport lists every skill except one with
419+
`mcpPrompt: false`. That optional key is the owner's opt-out: `false` = written
420+
for the in-product agents only, never offered over MCP on any connection,
421+
whatever the binding; absent or `true` = the binding rule above. Bind a tool no
422+
MCP family serves (the MCP table above) and no filtering server offers the
423+
skill.
405424
`visualize_data` is the only built-in that draws a chart (an inline `data-chart`
406425
part), auto-registered **only** when an analytics service (`IAnalyticsService`)
407426
is wired — `query_data` / `aggregate_data` return numbers, not charts.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ Since **ADR-0020** there is **no `workflow` metadata type** and no
1111
validation rule** in the object's `validations` array: a flat `field` +
1212
`{ from: [allowedTo] }` transition table. It is **enforced on the write path** —
1313
an update whose `field` moves to a state not listed for the current state is
14-
rejected with the rule's `message`. A `from` state mapped to `[]` is a declared
15-
dead-end.
14+
rejected with the rule's `message`.
1615

1716
<!-- os:check -->
1817
```typescript
@@ -36,7 +35,7 @@ const rule: StateMachineValidation = {
3635

3736
Notes:
3837
- **One rule per field.** Parallel lifecycles (e.g. `status` + `payment_status`)
39-
are N separate `state_machine` rules, one per field.
38+
are N separate `state_machine` rules.
4039
- **`initialStates`** (optional) gates INSERT: a record created with its
4140
state field outside this list is rejected. `transitions` only governs
4241
updates, so without it a record can be born mid-flow (e.g. created already
@@ -55,6 +54,8 @@ Notes:
5554
you want guarded rather than relying on an implicit "any → any".
5655
- Predicate conditions in sibling rules evaluate against the merged record in
5756
the **`record.<field>`** CEL scope (bare field names do not resolve).
57+
- **An AI-gated irreversible transition** pairs this rule with a lock on
58+
`field`: **objectstack-ai** → Common Pitfalls.
5859

5960
### Approvals (Flow Nodes)
6061

@@ -260,8 +261,7 @@ entered. Its CEL source sees exactly **three roots** — nothing else:
260261
**`record` and bare field names are NOT available and fail the node loudly.**
261262
Everywhere else on this platform `record` means "the record at event time" — at an
262263
approval node that phrase is ambiguous between two different times, so you must
263-
say which one: `current.x` or `trigger.x`. Do not carry the `record.x` habit
264-
over from conditions.
264+
say which one: `current.x` or `trigger.x`.
265265

266266
Result contract: a user-id string, a CSV string, or an array of ids. An **empty**
267267
result (present-but-empty field/variable) triggers `onEmptyApprovers`. A

0 commit comments

Comments
 (0)