@manhquy/flow-skill 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ # 05 — Contract
2
+
3
+ ## Interfaces
4
+
5
+ We will expose some APIs as needed. Endpoints are flexible and will evolve.
6
+ Auth might be optional depending on context. Errors should be helpful.
7
+
8
+ ## Gate
9
+ - [x] Interfaces sketched
10
+ - [x] Auth considered
11
+ - [x] Errors mentioned
@@ -6,3 +6,5 @@ f02b 02-scope flow/02-scope.md FLAG
6
6
  fcda card cards/C-001.md PASS
7
7
  fcdb card cards/C-001.md FLAG
8
8
  fcdc card cards/C-001.md FLAG
9
+ f05a 05-contract flow/05-contract.md PASS
10
+ f05b 05-contract flow/05-contract.md FLAG
@@ -0,0 +1,307 @@
1
+ # Attestations — risk, receipts, and auto trust (v0.28)
2
+
3
+ Canonical owner for **card risk**, **attestation receipts**, **subject
4
+ fingerprints**, and **auto-active policy state**. Other docs link here; do not
5
+ duplicate full schemas.
6
+
7
+ Fingerprints detect **staleness** of a reviewed/verified subject. They do **not**
8
+ authenticate a human or model. Actor/engine labels and unsigned receipt files
9
+ are forgeable by a filesystem/repository owner. This layer is workflow integrity,
10
+ not a hostile-host or cryptographic identity boundary.
11
+
12
+ ## Risk fields (card markdown)
13
+
14
+ ```text
15
+ risk: standard|security-class|unknown
16
+ risk-reason: <single line, 1..256 bytes once classified>
17
+ risk-ack: none|git:<full repository object id>
18
+ ```
19
+
20
+ Rules:
21
+
22
+ - Missing legacy fields normalize to `unknown`, empty reason, `none` (compat).
23
+ - Duplicate anchored fields are **invalid** (not last-wins).
24
+ - `standard` requires a non-placeholder reason and `risk-ack: none`.
25
+ - `security-class` requires a non-placeholder reason; auto validates `risk-ack`.
26
+ - `unknown` requires `risk-ack: none`.
27
+ - New cards scaffold `risk: unknown` / empty reason / `risk-ack: none`.
28
+
29
+ ### Security acknowledgement (auto only)
30
+
31
+ `risk-ack: git:<full-oid>` is accepted only when:
32
+
33
+ 1. OID shape matches repository object format (`sha1` or `sha256`).
34
+ 2. Commit exists and is an ancestor of current integration `HEAD`.
35
+ 3. `git show <oid>:<project-prefix>DEBT.md` succeeds.
36
+ 4. The blob contains exactly one open line beginning
37
+ `- [ ] DEBT: security-class <card-id> --`.
38
+ 5. `git blame --line-porcelain` at that commit yields `author-mail` **distinct**
39
+ (normalized lowercase, no angle brackets) from `git var GIT_AUTHOR_IDENT`.
40
+ 6. Missing / ambiguous / same identity → fail closed for auto.
41
+
42
+ Residual: Git identity is forgeable by a repository/config owner.
43
+
44
+ ### Semantic override (auto, semantic_gate only)
45
+
46
+ `verdict: override` requires an ancestor DEBT open line:
47
+
48
+ ```text
49
+ - [ ] DEBT: semantic-override <00-idea|01-research|02-scope|03-prd|04-adr|05-contract|C-NNN> -- <reason> -- close before: <condition>
50
+ ```
51
+
52
+ Same author-distinct rule as security-class. Auto never accepts
53
+ `live_verify: override`.
54
+
55
+ ## Committed producer manifests
56
+
57
+ Pass cannot be minted from caller-supplied verdict/argv alone. Subjects reference
58
+ a committed, repo-relative owner:
59
+
60
+ ```text
61
+ schema: flow-attestation-owner/v1
62
+ kind: semantic_gate|live_verify
63
+ subject_id: <closed stage name or C-NNN>
64
+ target_id: none|<lowercase [a-z0-9._-], 1..64 bytes>
65
+ command: repo:<repo-relative executable>
66
+ revision_oracle: none|repo:<repo-relative executable>
67
+ ```
68
+
69
+ - `semantic_gate`: `target_id: none`, `revision_oracle: none`.
70
+ - `live_verify`: non-`none` target and revision oracle.
71
+ - Executables must be tracked regular files at `subject_revision`, inside the
72
+ project, stable object/mode, invoked directly (no shell re-parse).
73
+
74
+ Runner-constructed argv only:
75
+
76
+ ```text
77
+ <command> --subject-id <id> --subject-revision <oid> --subject-fingerprint <fp>
78
+ <revision_oracle> --subject-id <id> --subject-revision <oid> --target-id <target>
79
+ ```
80
+
81
+ Semantic producer stdout (strict):
82
+
83
+ ```text
84
+ schema: flow-semantic-result/v1
85
+ subject_fingerprint: <exact requested fingerprint>
86
+ verdict: pass|fail
87
+ critical_count: <0..999>
88
+ high_count: <0..999>
89
+ evidence_ref: none|repo:<relative-path>
90
+ ```
91
+
92
+ `pass` requires both counts zero. `override` is never producer output.
93
+
94
+ Live revision oracle stdout: exactly one full repository-format OID equal to the
95
+ requested deployed revision.
96
+
97
+ ## Receipt schema (`flow-attestation/v1`)
98
+
99
+ Path layout under main state root:
100
+
101
+ ```text
102
+ <main-state-root>/.flow/attestations/
103
+ semantic_gate/stage-05-contract.receipt
104
+ semantic_gate/card-C-001.receipt
105
+ live_verify/card-C-001.receipt
106
+ live_verify/card-C-001.attempt
107
+ ```
108
+
109
+ Required keys, **canonical order**, single-line `key: value`:
110
+
111
+ ```text
112
+ schema: flow-attestation/v1
113
+ kind: semantic_gate|live_verify
114
+ subject_type: stage|card
115
+ subject_id: <closed stage name or C-NNN>
116
+ subject_fingerprint: git-<sha1|sha256>:<object-id>
117
+ verdict: pass|fail|override
118
+ actor: <sanitized, <=128 bytes>
119
+ engine: <sanitized, <=128 bytes>
120
+ evidence_ref: none|repo:<relative-path>
121
+ timestamp: <UTC YYYY-MM-DDTHH:MM:SSZ>
122
+ override_ref: none|git:<full-object-id>
123
+ owner_ref: repo:<repo-relative owner manifest>
124
+ owner_fingerprint: git-<sha1|sha256>:<object-id>
125
+ ```
126
+
127
+ Kind-specific (also required when present):
128
+
129
+ - stage `semantic_gate`: `subject_revision`
130
+ - card `semantic_gate`: `subject_base`, `subject_revision`, `subject_tree`
131
+ - `live_verify`: `subject_revision`, `command_fingerprint`, `result_code`,
132
+ `result_fingerprint`, `duration_ms`, `target_id`, `revision_oracle_ref`,
133
+ `revision_oracle_fingerprint`
134
+
135
+ `result_code` closed set:
136
+ `exit:<0..255>|timeout|output-cap|signal:<1..64>|spawn-error`.
137
+
138
+ `result_fingerprint` hashes outcome metadata (status, byte counts, argv digest,
139
+ duration bucket) — **never** stdout/stderr bytes.
140
+
141
+ Parser rules:
142
+
143
+ - Reject blank/unknown keys, duplicates, missing required keys, multiline
144
+ values, NUL/control chars, oversized values, path traversal.
145
+ - Never source/eval receipt content.
146
+ - CRLF normalized on read.
147
+ - Invalid CLI/schema input does **not** overwrite an existing receipt.
148
+
149
+ Atomic write: temp in destination dir → `chmod 600` best-effort → rename.
150
+ Latest assessment wins: valid semantic `fail` and terminal live red replace
151
+ older `pass`. Pre-spawn live attempt marker is fail-closed until dead-owner
152
+ recovery or Must-ask `flow attest recover C-NNN --mark-failed`.
153
+
154
+ ### Scalar grammar
155
+
156
+ - `actor` / `engine` / `activated_by`:
157
+ `[A-Za-z0-9][A-Za-z0-9._@/-]{0,127}`
158
+ - `evidence_ref`: `none` or `repo:<normalized relative path>`, ≤256 UTF-8 bytes,
159
+ no `.` / `..` / empty segment / symlink escape
160
+ - `target_id`: `[a-z0-9][a-z0-9._-]{0,63}`
161
+ - Absent optional refs use literal `none`
162
+ - Integers: no signs, spaces, leading plus, or overflow
163
+ - Subject IDs: six stage names
164
+ (`00-idea`…`05-contract`) or normalized `C-NNN`
165
+
166
+ ## Subject projections and fingerprints
167
+
168
+ | Subject | Canonical projection |
169
+ |---|---|
170
+ | Stage semantic | Exact committed Git blob bytes for the stage path |
171
+ | Card semantic | `deps`, `implements`, risk fields, Scope, Allowed files, Verify, Done-evidence + base/head/tree OIDs |
172
+ | Card live | Verify + Done-evidence + owner manifest + target + deployed revision + argv digest |
173
+
174
+ Mutable `status` and `Evidence` are **excluded** from card semantic projection
175
+ so CLI-owned completion updates do not invalidate a still-current review.
176
+
177
+ Cleanliness for mint/consume (auto):
178
+
179
+ - Fail closed on dirty tracked, index, or untracked files **except** skill-owned
180
+ `.flow/` run-state and CLI-owned card `status`/`Evidence` projection fields.
181
+ - Do **not** mutate `.gitignore` to achieve cleanliness.
182
+
183
+ ### Stage fingerprint
184
+
185
+ 1. Validate stage name against closed set.
186
+ 2. Resolve revision to full commit; require clean tracked artifact.
187
+ 3. Blob OID for stage path at that commit; prefix `git-<format>:`.
188
+
189
+ ### Card semantic fingerprint
190
+
191
+ 1. Git repo + explicit base + head.
192
+ 2. Clean worktree including untracked (with `.flow` / status-Evidence exclusions).
193
+ 3. Canonical card-contract projection + base/head/tree OIDs + sorted
194
+ changed-path manifest (`base..head`, excluding card markdown path).
195
+ 4. Hash via `git hash-object --stdin`.
196
+
197
+ Currentness after ancestry-preserving merge: reviewed revision is ancestor of
198
+ integration HEAD; projection still matches; every reviewed changed path
199
+ (except card md) has same object/mode at HEAD. Squash/rebase or code-path edit
200
+ → stale.
201
+
202
+ ### Live fingerprint
203
+
204
+ Deployed revision + Verify/Done-evidence projection + owner/oracle object/mode
205
+ + target + argv digest. Oracle must return exact deployed OID before probe may
206
+ pass.
207
+
208
+ ## Auto-active state
209
+
210
+ ```text
211
+ <main-state-root>/.flow/auto-state
212
+ ```
213
+
214
+ ```text
215
+ schema: flow-auto/v1
216
+ status: active
217
+ activated_at: <UTC RFC3339>
218
+ activated_by: <sanitized <=128>
219
+ integration_branch: <validated branch name>
220
+ risk_fingerprint: git-<sha1|sha256>:<object-id>
221
+ contract_fingerprint: git-<sha1|sha256>:<object-id>
222
+ ```
223
+
224
+ Activation (`flow auto`) requires, atomically after full preflight:
225
+
226
+ - Git repo; main worktree on attached integration branch (linked/detached refuse)
227
+ - Reliable process-group supervisor capability (else refuse live auto)
228
+ - Planning complete + ≥1 card
229
+ - Full risk set valid (no `unknown`, valid security ack)
230
+ - Current accepted Stage 05 `semantic_gate` receipt
231
+
232
+ Card/live receipts are later transition gates, not activation prerequisites.
233
+ `flow auto stop` clears state. Status/resume show `INACTIVE|ACTIVE|STALE|INVALID`.
234
+
235
+ ### Enforcement matrix
236
+
237
+ | Boundary | Auto inactive | Auto active/current | Auto stale/invalid |
238
+ |---|---|---|---|
239
+ | `next` | Warn on stage receipt | Warn only | Warn only |
240
+ | `check` todo | Warn | Require card semantic pass/override | Block |
241
+ | `check` done | Warn | Semantic + live pass | Block |
242
+ | `card done` | Existing + warn | Same hard checks; validate before status mutation | Block |
243
+ | `ready` | Existing + advisory | Done deps need both receipts | No BUILDABLE; non-zero |
244
+ | merged `workspace remove` | Warn | Both receipts | Block |
245
+ | unmerged remove | Existing abandon | Allow without receipts | Allow |
246
+
247
+ No hidden bypass flag. Manual continuation: `flow auto stop`.
248
+
249
+ ## Main state-root resolution
250
+
251
+ Bash must match Python `_db.default_db_path` intent:
252
+
253
+ 1. Explicit `FLOW_PROJECT_ROOT` is project root.
254
+ 2. Resolve Git worktree top + first/main worktree.
255
+ 3. Linked worktree subpath → equivalent main-worktree subpath.
256
+ 4. Submodule / `--separate-git-dir` ambiguity → current root + local receipts
257
+ warning; never place `.flow` inside Git internals.
258
+ 5. Receipts readable without Python.
259
+
260
+ ## CLI surface
261
+
262
+ ```text
263
+ flow attest semantic --stage <stage> --revision <rev> --owner <manifest>
264
+ flow attest semantic --card <id> --base <rev> --revision <rev> --owner <manifest>
265
+ flow attest live-verify <id> --revision <rev> --owner <manifest>
266
+ flow attest status [<stage|card>]
267
+ flow attest recover <C-NNN> --mark-failed
268
+ flow auto
269
+ flow auto stop
270
+ ```
271
+
272
+ Exit codes:
273
+
274
+ - `0` — valid / pass / current accepted
275
+ - `1` — missing / stale / red policy result
276
+ - `2` — invalid usage / schema
277
+ - Timeout / cap / signal → non-zero; never pass
278
+
279
+ ## Process supervisor (attestation only)
280
+
281
+ Argv-safe: fixed cwd = logical checkout root, process group ownership,
282
+ streaming stdout/stderr independent + combined caps, TERM → grace → KILL → wait.
283
+ Capability probe: if reliable process-group supervisor unavailable, live
284
+ verification and auto activation fail closed (never unbounded fallback).
285
+
286
+ Usage/event logs for attestation record only subcommand, subject ID, result
287
+ class, duration bucket — never argv after `--`, raw output, or secrets.
288
+
289
+ ## Locks
290
+
291
+ Order: shared auto-policy mutex → subject locks sorted by `(subject_id, kind)`
292
+ → existing runner/workspace mutation lock.
293
+
294
+ Hard consumers hold locks from validation through irreversible side effects
295
+ (graph/harness/removal).
296
+
297
+ ## Backward compatibility
298
+
299
+ - Manual/teach/work without auto state: warnings only; pre-v0.28 exit codes.
300
+ - Planning `next` never hard-enforced in v0.28.
301
+ - Bash + Git floor; Python/SQLite optional and never required to parse receipts.
302
+ - Harness `risk_lane` remains separate advisory taxonomy (no silent sync).
303
+
304
+ ## Rollback
305
+
306
+ `flow auto stop`, then revert enforcement. Receipt files under `.flow/` are
307
+ run-state; remove for audit loss only — does not corrupt cards/DB.
@@ -1,8 +1,13 @@
1
1
  # /flow auto — autonomous build run
2
2
 
3
3
  `/flow auto` drives the card-building phase autonomously. Preflight via
4
- `flow.sh auto` (planning complete + cards exist), then YOU (Claude) orchestrate per the
5
- principles below. Operator chose: **Tier-A auto-merge green cards; halt at security-class.**
4
+ `flow.sh auto` requires planning complete, classified card **risk** (no `unknown`),
5
+ valid security-class DEBT acknowledgement when needed, a reliable live supervisor, and a
6
+ current Stage 05 `semantic_gate` receipt — then writes shared `.flow/auto-state`. Full
7
+ contract: `references/attestations.md`. Then YOU (Claude) orchestrate per the principles
8
+ below. Operator chose: **Tier-A auto-merge green cards; halt at security-class.**
9
+ While auto is active, mechanical transitions require current card semantic/live receipts;
10
+ there is no hidden bypass — use `flow auto stop` for deliberate manual continuation.
6
11
 
7
12
  ## Tiers (decide per card before acting)
8
13
 
@@ -34,7 +34,9 @@ install dir; run from the project root so `flow/` and `cards/` resolve.
34
34
  | `/flow mode work` | `bash <skill>/runner/flow.sh mode work` | Interview once, draft 00-05, pause for scope sign-off, deliver card set; still pass every gate. |
35
35
  | `/flow ready` | `bash <skill>/runner/flow.sh ready` | Relay buildable cards; confirm allowed-files truly don't overlap before suggesting parallel. Operator dispatches. |
36
36
  | `/flow workspace <verb>` | `bash <skill>/runner/flow.sh workspace add\|list\|enter\|remove\|check\|doctor [...]` | Multi-agent worktree isolation (human-driven, cross-vendor). Relay the runner output faithfully: on `add`, hand the operator the printed cd/env block (one worktree per agent — Claude `--worktree`/`-w`, Codex CLI manual + `CODEX_HOME`, Antigravity = open the dir as a workspace); on `check`/`doctor` exit 1, surface the collision/drift, don't auto-`--force` a `remove`. git is the source of truth; the `.flow/workspaces.jsonl` side-file only adds vendor/card/port/task. Advisory — not a `next` gate. |
37
- | `/flow auto` | `bash <skill>/runner/flow.sh auto` | On preflight PASS, drive the autonomous run per SKILL.md AUTO principles (subagent/card, planner review, worktree, Tier-C halt on security debt). |
37
+ | `/flow auto` | `bash <skill>/runner/flow.sh auto` | On preflight PASS (risk + Stage 05 receipt), shared auto-state is active — drive the autonomous run per SKILL.md AUTO principles + `attestations.md`. |
38
+ | `/flow auto stop` | `bash <skill>/runner/flow.sh auto stop` | Clear auto policy; return to warning-only manual path. |
39
+ | `/flow attest …` | `bash <skill>/runner/flow.sh attest semantic\|live-verify\|status\|recover …` | Mint/inspect receipts. Must-ask before mint/recover; `attest status` is read-only. |
38
40
  | `/flow recall` | `bash <skill>/runner/flow.sh recall` | Read back prior knowledge (open debt, recent retro, previous-card scope, harness friction/backlog, playbooks). Run at the START of a stage/card; apply it, don't re-learn known pain. |
39
41
  | `/flow unlock` | `bash <skill>/runner/flow.sh unlock` | Clear this project's concurrency lock after a crashed/abandoned session. Confirm the other session is really gone first. |
40
42
  | `/flow retro` | `bash <skill>/runner/flow.sh retro` | Ask the 3 questions; the operator writes the RETRO.md line — never you. |
@@ -63,6 +63,7 @@ operator-authority-only):
63
63
  - promote
64
64
  - mode
65
65
  - auto
66
+ - attest
66
67
  - workspace
67
68
  - unlock
68
69
  - retro
@@ -39,3 +39,5 @@ A run HALTS and reports — never silently continues — on any of:
39
39
 
40
40
  On halt: state what stopped it, what's done so far, the open debt/blocker, and the 2-4
41
41
  concrete options for the operator. Let them decide — don't patch around a regression.
42
+
43
+ See also: `references/attestations.md` for security-class **risk-ack** auto contract (v0.28).
@@ -16,6 +16,9 @@ and used only to add color, never to pass a gate.
16
16
  | Card DONE | deploy ran + **live URL verified as a user** (world-state evidence pasted) | "merged" / "deploy succeeded" / "tests pass" |
17
17
  | Card DONE (mechanical floor) | `flow.sh check` / `card done`: `## Evidence` multi-signal score ≥2 (URL + curl/command/test-log/path/DB/skill categories; denylist example.com etc.) | process-only prose (PR approvals, CI green, release notes alone); empty/placeholder |
18
18
  | Dep ready / parallel | `ready` + graph deps-met: dep `status=done` **and** same Evidence multi-signal floor | hand-edit `status: done` with hollow Evidence |
19
+ | Auto activation | risk set valid + current Stage 05 `semantic_gate` receipt (`attestations.md`) | prose “planning looks done” |
20
+ | Auto `check` / `card done` | current fingerprint-bound `semantic_gate` (+ `live_verify` when done) | self-assessed review / Evidence text alone |
21
+ | Merged worktree remove (auto) | both card receipts current for mapped card | `--force` without receipts |
19
22
  | Contract not drifted | contract-test card asserts every endpoint exists in live `/openapi.json` with matching shape | "backend and UI agree" (they don't, silently) |
20
23
 
21
24
  ## Rules