cclaw-cli 0.51.25 → 0.51.27

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.
@@ -22,6 +22,10 @@ export const ARTIFACT_TEMPLATES = {
22
22
 
23
23
  # Brainstorm Artifact
24
24
 
25
+ ## Mode Block
26
+ - **Mode:** STARTUP | BUILDER | ENGINEERING | OPS | RESEARCH (pick exactly one)
27
+ - **Why this mode:** (one line; cite a concrete signal — repo state, user prompt, ownership, risk window)
28
+
25
29
  ## Context
26
30
  - **Project state:**
27
31
  - **Relevant existing code/patterns:**
@@ -36,25 +40,15 @@ export const ARTIFACT_TEMPLATES = {
36
40
 
37
41
  ## Problem Decision Record
38
42
  - **Depth:** lite | standard | deep
39
- - **Frame type:** product | technical-maintenance
40
-
41
- ### Product framing (use when applicable)
42
- - **Persona / user:**
43
- - **Job to be done:**
44
- - **Pain / trigger:**
45
- - **Value hypothesis:**
46
- - **Evidence / signal:**
47
- - **Success metric:**
48
- - **Why now:**
49
- - **Do-nothing consequence:**
50
- - **Non-goals:**
51
-
52
- ### Technical-maintenance framing (use when product framing is not applicable)
53
- - **Affected operator/developer:**
54
- - **Current failure mode:**
55
- - **Expected operational improvement:**
56
- - **Verification signal:**
57
- - **Do-nothing cost:**
43
+ - **Frame type:** \`<free-form-label>\` (one short token that names how this work is framed; pick whatever fits — examples in commentary only: \`product\`, \`technical-maintenance\`, \`research-spike\`, \`ops-incident\`, \`infrastructure\`, \`library-extraction\`. Do NOT treat the examples as an enum.)
44
+
45
+ ### Framing fields (universal keep field names; fill in whatever is meaningful for this work)
46
+ - **Affected user / role / operator:** (who experiences the problem or carries the consequence)
47
+ - **Current state / failure mode / opportunity:** (what is happening today)
48
+ - **Desired outcome (observable):** (what changes when this work lands; phrase so a test or operator could verify)
49
+ - **Evidence / signal supporting this framing:** (citation, metric, ticket, prior artifact, repo path, or \`- None.\`)
50
+ - **Why now (urgency / cost of waiting):**
51
+ - **Do-nothing consequence:** (concrete — not "nothing happens")
58
52
  - **Non-goals:**
59
53
 
60
54
  ## Premise Check
@@ -62,6 +56,26 @@ export const ARTIFACT_TEMPLATES = {
62
56
  - **Direct path?** (yes/no + one-line justification)
63
57
  - **What if we do nothing?** (concrete consequence, not "nothing happens")
64
58
 
59
+ ## Forcing Questions
60
+ > Minimum 3 questions; each answer MUST contain at least one *specific* token: a concrete name, a role, a number, a repo-relative path, an external link, or a verbatim quote. Vague answers fail the linter.
61
+
62
+ | # | Forcing question | Specific answer | Decision impact | Q\\<n\\> decision |
63
+ |---|---|---|---|---|
64
+ | 1 | | | | decision: |
65
+ | 2 | | | | decision: |
66
+ | 3 | | | | decision: |
67
+
68
+ ## Premise List
69
+ > ≥2 premises. Each premise must be in the form \`P<n>: <statement> — agreed | disagreed | revised\`. \`revised\` rows must include the revised statement on the next line.
70
+
71
+ - P1: <statement> — agreed | disagreed | revised
72
+ - P2: <statement> — agreed | disagreed | revised
73
+
74
+ ## Anti-Sycophancy Stamp
75
+ - **Forbidden response openers acknowledged:** yes (no "you're absolutely right", "great point", "absolutely!", etc.)
76
+ - **Posture commitment:** push back with reasoning when premises feel weak; do not perform agreement.
77
+ - **Evidence-that-would-change-the-recommendation:** (one line per premise, or \`- None.\`)
78
+
65
79
  ## How Might We
66
80
  - *How might we …?* — one line naming the user, the desired outcome, and the binding constraint.
67
81
 
@@ -99,6 +113,33 @@ export const ARTIFACT_TEMPLATES = {
99
113
 
100
114
  > Role values: \`baseline\` | \`challenger\` | \`wild-card\`. Upside values: \`low\` | \`modest\` | \`high\` | \`higher\`. Exactly one row must be a \`challenger\` with \`high\` or \`higher\` upside.
101
115
 
116
+ ### Approach Detail Cards
117
+ > Required structural form per approach (≥2). One block per row above:
118
+
119
+ #### APPROACH A
120
+ - Summary:
121
+ - Effort:
122
+ - Risk:
123
+ - Pros:
124
+ - Cons:
125
+ - Reuses:
126
+
127
+ #### APPROACH B
128
+ - Summary:
129
+ - Effort:
130
+ - Risk:
131
+ - Pros:
132
+ - Cons:
133
+ - Reuses:
134
+
135
+ RECOMMENDATION: <approach letter — one-line rationale, traced to forcing-question answers and premise list>
136
+
137
+ ## Outside Voice (optional)
138
+ - source: <model id | critic agent | human reviewer> | (or \`- not used.\`)
139
+ - prompt:
140
+ - tension:
141
+ - resolution:
142
+
102
143
  ## Approach Reaction
103
144
  - Closest option:
104
145
  - Concerns:
@@ -184,6 +225,20 @@ ${SEED_SHELF_SECTION}
184
225
  | B (ideal architecture) | | | | | | |
185
226
  | C (optional) | | | | | | |
186
227
 
228
+ RECOMMENDATION: <option letter — one-line rationale tying back to premise challenge and existing-code leverage>
229
+
230
+ ## Failure Modes Registry
231
+ > Universal failure-mode shape — applies to CLI, library, infra, web, batch jobs.
232
+
233
+ | Codepath | Failure mode | Rescued? (yes/no) | Test? (unit/integration/e2e) | User sees? (message/silent/N/A) | Logged? (level/none) | Q\\<n\\> decision |
234
+ |---|---|---|---|---|---|---|
235
+ | | | | | | | decision: |
236
+
237
+ ## Reversibility Rating
238
+ - Score (1-5, 1 = one-way door / unrecoverable, 5 = trivially reversible):
239
+ - Justification (cite a specific artifact/file or migration step):
240
+ - Rollback plan reference:
241
+
187
242
  ## Temporal Interrogation
188
243
  - Deep/optional only; omit for compact scope.
189
244
  | Time slice | Likely decision pressure | Lock now or defer? | Reason |
@@ -343,7 +398,7 @@ ${SEED_SHELF_SECTION}
343
398
  | Topic | Finding | Evidence |
344
399
  |---|---|---|
345
400
  | Domain conventions | | |
346
- | UX/product patterns | | |
401
+ | User-facing or operator-facing patterns | | |
347
402
 
348
403
  ## Architecture Options
349
404
  | Option | Trade-offs | Recommendation | Evidence |
@@ -516,6 +571,32 @@ ${MARKDOWN_CODE_FENCE}
516
571
  |---|---|---|---|
517
572
  | | | | covered/gap |
518
573
 
574
+ ## ASCII Coverage Diagram
575
+
576
+ <!-- diagram: ascii-coverage -->
577
+
578
+ ${MARKDOWN_CODE_FENCE}
579
+ entry-point
580
+ ├── happy path [★★★]
581
+ ├── empty input [★★]
582
+ ├── error path [★]
583
+ ├── concurrency edge [GAP]
584
+ ├── slow-network edge [→E2E]
585
+ └── perf regression [→EVAL]
586
+ ${MARKDOWN_CODE_FENCE}
587
+
588
+ > Required marker tokens (at least one each present where applicable): \`[★★★]\` / \`[★★]\` / \`[★]\` / \`[GAP]\` / \`[→E2E]\` / \`[→EVAL]\`. The diagram is the single source of truth for coverage; gaps must be traced into Plan or Spec.
589
+
590
+ ## Regression Iron Rule
591
+ - Iron rule acknowledged: yes — any diff that changes existing behavior gets a regression test added to the plan, no exceptions.
592
+ - Detected behavior changes (or \`- None.\`):
593
+ - Regression test handoff (Plan task ID or \`- None.\`):
594
+
595
+ ## Calibrated Findings
596
+ > Format: \`[P1|P2|P3] (confidence: <n>/10) <repo-relative-path>[:<line>] — <one-line description>\`. Findings with confidence \`< 7\` are suppressed unless severity is \`P1\`.
597
+
598
+ - (or \`- None this stage.\`)
599
+
519
600
  ## Performance Budget
520
601
  | Critical path | Metric | Target | Measurement method |
521
602
  |---|---|---|---|
@@ -673,6 +754,50 @@ For meaningful design work, replace the Learnings sentinel with 1-3 JSON learnin
673
754
  |---|---|---|
674
755
  | | | |
675
756
 
757
+ ## Synthesis Sources
758
+ > Spec is synthesized from existing context (CLAUDE.md / AGENTS.md / TODOS.md / git history / brainstorm + scope + design artifacts) — interview only when something genuinely cannot be derived. List the artifacts/files actually read and what each supplied.
759
+
760
+ | Source | What it supplied | Confidence (1-10) |
761
+ |---|---|---|
762
+ | | | |
763
+
764
+ ## Behavior Contract
765
+ > List behaviors universally (works for CLI, library, infra, web, batch). Use either \`As a <role>, I can <action> so that <outcome>.\` or \`Given <state>, When <event>, Then <outcome>.\`. ≥3 behaviors required. The shape — not the topic — is what the linter checks.
766
+
767
+ - (or write \`- None.\` if a single-step spec)
768
+
769
+ ## Architecture Modules
770
+ > One line of responsibility per module — no file paths, no signatures, no method names. Modules must be derivable from the design artifact.
771
+
772
+ | Module | Responsibility (one sentence) | Maps to design ref (DD-#) |
773
+ |---|---|---|
774
+ | | | |
775
+
776
+ ## Testing Strategy
777
+ - Behaviors covered (not implementation):
778
+ - Integration vs. unit split (and why):
779
+ - Real services vs. doubles (and why):
780
+ - Coverage gaps with rationale (or \`- None.\`):
781
+
782
+ ## Spec Self-Review
783
+ > Inline pass; fix in place. If a check fails, do not move on without recording the fix.
784
+
785
+ - [ ] Placeholders scan (no \`TBD\`, \`TODO\`, \`FIXME\`, \`<placeholder>\`)
786
+ - [ ] Internal consistency (sections do not contradict each other)
787
+ - [ ] Scope check (focused enough for a single plan)
788
+ - [ ] Ambiguity check (no requirement readable two ways)
789
+ - Patches applied:
790
+ - None
791
+ - Remaining concerns:
792
+ - None
793
+
794
+ ## Reviewer Concerns (convergence guard)
795
+ > Populate ONLY if the spec review loop did not converge after 3 iterations. Each row links a concern to the unresolved review pass.
796
+
797
+ | ID | Concern | Reviewer / source | Disposition (open/accept/defer) | Rationale |
798
+ |---|---|---|---|---|
799
+ | | | | | |
800
+
676
801
  ## Approval
677
802
  - Approved by:
678
803
  - Date:
@@ -684,6 +809,11 @@ For meaningful design work, replace the Learnings sentinel with 1-3 JSON learnin
684
809
 
685
810
  # Plan Artifact
686
811
 
812
+ ## Plan Header
813
+ - **Goal:** (one sentence — what this plan delivers)
814
+ - **Architecture:** (2-3 sentences — approach + key boundaries)
815
+ - **Tech Stack:** (key languages/runtimes/frameworks/libraries that the executor must know)
816
+
687
817
  ## Upstream Handoff
688
818
  - Source artifacts: \`03-design-<slug>.md\`, \`04-spec.md\`
689
819
  - Decisions carried forward:
@@ -750,6 +880,56 @@ Execution rule: complete and verify each batch before starting the next batch.
750
880
  |---|---|---|
751
881
  | | | |
752
882
 
883
+ ## Implementation Units
884
+ > Required structural form per implementation unit. Use ≥1 unit; bite-sized 2-5 minute steps inside each. The linter validates shape, not topic.
885
+
886
+ ### Implementation Unit U-1
887
+ - **Goal:**
888
+ - **Requirements (from Spec):**
889
+ - **Dependencies (other units):**
890
+ - **Files (repo-relative; never absolute):**
891
+ - Create:
892
+ - Modify:
893
+ - Test:
894
+ - **Approach:** (1-3 sentences; cite design decision DD-# or LD#hash)
895
+ - **Patterns to follow:** (link existing files/modules to mirror, or \`- None applicable.\`)
896
+ - **Test scenarios:**
897
+ - Happy:
898
+ - Edge:
899
+ - Error:
900
+ - Integration:
901
+ - **Verification:** (outcome to observe — not a shell script; e.g., "command exits 0 and prints \`<artifact-anchor>\`").
902
+ - **Steps (each 2-5 min, checkbox):**
903
+ - [ ] Step 1: write failing test for <behavior>
904
+ - [ ] Step 2: run test, observe RED with reason
905
+ - [ ] Step 3: minimal implementation
906
+ - [ ] Step 4: run test, observe GREEN
907
+ - [ ] Step 5: refactor + commit
908
+
909
+ ## High-Level Technical Design
910
+ > "Directional guidance, not implementation specification." Choose the form that fits the work: pseudo-code grammar, mermaid sequence/state, data-flow ASCII, decision matrix. Skip if the plan is a pure rename/move.
911
+
912
+ \`\`\`
913
+ (pseudo-code, mermaid, ASCII data flow, or decision matrix)
914
+ \`\`\`
915
+
916
+ ## Plan Self-Review
917
+ - [ ] Spec coverage: every spec behavior maps to a unit/task
918
+ - [ ] Placeholder scan (regex on full artifact, not only Task List)
919
+ - [ ] Type/name consistency across units (signatures referenced match definitions)
920
+ - [ ] No silent scope reduction
921
+ - [ ] Confidence per unit recorded (1-10)
922
+ - Patches applied:
923
+ - None
924
+ - Remaining concerns:
925
+ - None
926
+
927
+ ## Execution Handoff
928
+ - **Posture chosen:** Subagent-Driven (recommended) | Inline executor
929
+ - **Why this posture:** (one line tying choice to plan size, parallelism, novelty)
930
+ - **Subagent recipe (if Subagent-Driven):** \`<harness>\` -> \`<dispatch surface>\` -> \`<agent-definition path>\` (substitute neutral placeholders; full recipes in \`docs/harnesses.md\`)
931
+ - **Inline recipe (if Inline executor):** TDD loop unit-by-unit with batch checkpoints
932
+
753
933
  ## No-Placeholder Scan
754
934
  - Scanned tokens: \`TODO\`, \`TBD\`, \`FIXME\`, \`<fill-in>\`, \`<your-*-here>\`, \`xxx\`, bare ellipsis in task rows.
755
935
  - Hits: 0 (required for WAIT_FOR_CONFIRM to resolve).
@@ -822,6 +1002,39 @@ Execution rule: complete and verify each batch before starting the next batch.
822
1002
  - Spec criterion IDs:
823
1003
 
824
1004
 
1005
+ ## Iron Law Acknowledgement
1006
+ - Iron Law: NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST.
1007
+ - Acknowledged: yes — code that landed before its test will be deleted and rewritten from the test.
1008
+ - Exceptions invoked (or \`- None.\`):
1009
+
1010
+ ## Watched-RED Proof
1011
+ > Required for every new test in this stage. Each row proves the test was *observed* failing before any production code was written.
1012
+
1013
+ | Slice | Test name | Observed at (ISO ts) | Failure reason snippet | Source command/log |
1014
+ |---|---|---|---|---|
1015
+ | S-1 | | | | |
1016
+
1017
+ ## Vertical Slice Cycle
1018
+ > Per slice: RED -> GREEN -> REFACTOR within the same cycle (refactor not deferred). The linter checks structural presence of all three phases.
1019
+
1020
+ | Slice | RED ts | GREEN ts | REFACTOR ts (or \`deferred because <reason>\`) |
1021
+ |---|---|---|---|
1022
+ | S-1 | | | |
1023
+
1024
+ ## Assertion Correctness Notes
1025
+ > For each new test assertion, name a *plausible subtle bug* that would still pass it (mental mutation test). If you cannot, the assertion is too coarse — strengthen it.
1026
+
1027
+ | Slice | Assertion (one line) | Bug that would still pass | Strengthening action (or \`- Sufficient.\`) |
1028
+ |---|---|---|---|
1029
+ | S-1 | | | |
1030
+
1031
+ ## Anti-Rationalization Checks
1032
+ - [ ] No "test passes immediately" — each new test was watched failing first
1033
+ - [ ] No "code before test" reuse from a prior session
1034
+ - [ ] No "tests after" backfill instead of RED-first
1035
+ - [ ] No "spirit not ritual" overrides
1036
+ - Notes (or \`- None this stage.\`):
1037
+
825
1038
  ## Verification Ladder
826
1039
  | Slice | Tier reached | Evidence |
827
1040
  |---|---|---|
@@ -863,6 +1076,44 @@ For meaningful TDD work, replace the Learnings sentinel with 1-3 JSON learning b
863
1076
  - Open questions:
864
1077
  - Drift from upstream (or \`None\`):
865
1078
 
1079
+ ## Self-Review First
1080
+ - [ ] Build/lint/type-check/tests passed locally
1081
+ - [ ] Diff matches spec/plan (no scope creep)
1082
+ - [ ] Leftover prints / commented code / unused imports removed
1083
+ - [ ] Deletion test: each new module justifies its existence
1084
+ - Evidence (commands + result):
1085
+ - Patches applied (or \`- None.\`):
1086
+
1087
+ ## Frame the Review Request
1088
+ - **Goal:**
1089
+ - **Approach:**
1090
+ - **Risk areas:**
1091
+ - **Verification done:**
1092
+ - **Open questions for the reviewer:**
1093
+
1094
+ ## Critic Subagent Dispatch
1095
+ > Dispatch a fresh-context critic (not the session history). Required even for self-driven review — the critic delegates back via \`delegation-record.mjs\` so the proof chain is preserved.
1096
+
1097
+ | Field | Value |
1098
+ |---|---|
1099
+ | Critic agent definition path | \`<repo-relative path under harness directory>\` |
1100
+ | Dispatch surface | One of the \`--dispatch-surface\` enum values listed in \`docs/harnesses.md\` (\`claude-task\`, \`cursor-task\`, \`opencode-agent\`, \`codex-agent\`, \`generic-task\`, \`role-switch\`, \`manual\`) |
1101
+ | Frame sent | WHAT_WAS_IMPLEMENTED + PLAN_OR_REQUIREMENTS + BASE_SHA + HEAD_SHA |
1102
+ | Critic returned | Strengths / Critical / Important / Minor |
1103
+ | Span id | \`<span-id>\` |
1104
+ | Acknowledgement ts | \`<iso ts>\` |
1105
+
1106
+ ## Receiving Posture
1107
+ - [ ] No performative agreement (forbidden openers acknowledged)
1108
+ - [ ] READ -> UNDERSTAND -> VERIFY -> EVALUATE -> RESPOND -> IMPLEMENT one-at-a-time discipline followed
1109
+ - [ ] Push-back recorded with reasoning when the critic was wrong
1110
+ - Notes (or \`- None.\`):
1111
+
1112
+ ## Critic Convergence
1113
+ - Iterations run: <n>/3
1114
+ - Convergence reached: yes / no — \`Reviewer Concerns\` populated when no
1115
+ - Stop reason:
1116
+
866
1117
  ## Review Evidence Scope
867
1118
  - Base/head:
868
1119
  - Files inspected:
@@ -992,6 +1243,12 @@ For meaningful review work, replace the Learnings sentinel with 1-3 JSON learnin
992
1243
  - Open questions:
993
1244
  - Drift from upstream (or \`None\`):
994
1245
 
1246
+ ## Verify Tests Gate
1247
+ - Discovered test command (cite repo config — package scripts / pyproject / go.mod / Cargo.toml / pom.xml / gradle):
1248
+ - Result: PASS | FAIL
1249
+ - Evidence (full output snippet or path):
1250
+ - Stop on FAIL: confirmed (no options surface unless PASS)
1251
+
995
1252
  ## Preflight Results
996
1253
  - Review verdict:
997
1254
  - Build:
@@ -1000,9 +1257,44 @@ For meaningful review work, replace the Learnings sentinel with 1-3 JSON learnin
1000
1257
  - Type-check:
1001
1258
  - Working tree clean:
1002
1259
 
1260
+ ## Base Branch Determination
1261
+ - Command run: \`git merge-base HEAD main || git merge-base HEAD master\`
1262
+ - Base branch:
1263
+ - User confirmation (if ambiguous):
1264
+
1265
+ ## Finalization Options
1266
+ > Exactly four options must be surfaced when tests pass. Selecting any option requires a recorded user decision.
1267
+
1268
+ 1. **Merge back to base locally** — \`MERGE_LOCAL\`
1269
+ 2. **Push and create PR** — \`OPEN_PR\`
1270
+ 3. **Keep branch as-is** — \`KEEP_BRANCH\`
1271
+ 4. **Discard this work** — \`DISCARD\` (typed-confirmation required)
1272
+
1273
+ - Selected option:
1274
+ - Typed confirmation (DISCARD only):
1275
+ - User decision recorded at:
1276
+
1003
1277
  ## Release Notes
1004
1278
  -
1005
1279
 
1280
+ ## Structured PR Body
1281
+ > Required when selected option is \`OPEN_PR\`. The structure is universal — replace placeholder bullets with concrete content, do not introduce domain-specific subsections.
1282
+
1283
+ ### ## Summary
1284
+ - (2-3 bullets describing what changed and why)
1285
+
1286
+ ### ## Test Plan
1287
+ - [ ] (verification step — repo-relative command + expected outcome)
1288
+ - [ ] (additional verification step or \`Manual: <action>\`)
1289
+
1290
+ ### ## Commits Included
1291
+ - (auto-generated commit list; one bullet per commit hash + subject)
1292
+
1293
+ ## Worktree Cleanup
1294
+ - Cleanup applies to options \`MERGE_LOCAL\` and \`DISCARD\`; preserved for \`OPEN_PR\` and \`KEEP_BRANCH\`.
1295
+ - Worktree path:
1296
+ - Cleanup result:
1297
+
1006
1298
  ## Rollback Plan
1007
1299
  - Trigger conditions:
1008
1300
  - Rollback steps:
@@ -5,6 +5,12 @@ function flowStatePath() {
5
5
  function delegationLogPath() {
6
6
  return `${RUNTIME_ROOT}/state/delegation-log.json`;
7
7
  }
8
+ function delegationEventsPath() {
9
+ return `${RUNTIME_ROOT}/state/delegation-events.jsonl`;
10
+ }
11
+ function subagentsPath() {
12
+ return `${RUNTIME_ROOT}/state/subagents.json`;
13
+ }
8
14
  function artifactsPath() {
9
15
  return `${RUNTIME_ROOT}/artifacts`;
10
16
  }
@@ -30,7 +36,7 @@ Do not modify state in this command. It is a pure read/render operation.
30
36
  - stage marker: passed/current/pending/skipped/stale,
31
37
  - gates summary,
32
38
  - artifact summary,
33
- - delegation branch for current stage with fulfillmentMode labels,
39
+ - delegation branch for current stage with fulfillmentMode, dispatchSurface, proof status, and active tracker labels,
34
40
  6. When \`closeout.shipSubstate !== "idle"\` or \`currentStage === "ship"\`, add
35
41
  a closeout sub-tree:
36
42
  - \`retro:\` line derived from \`closeout.retroDraftedAt\` /
@@ -1,7 +1,21 @@
1
1
  import { type SubagentFallback } from "./harness-adapters.js";
2
2
  import type { FlowStage } from "./types.js";
3
3
  export type DelegationMode = "mandatory" | "proactive";
4
- export type DelegationStatus = "scheduled" | "completed" | "failed" | "waived";
4
+ export type DelegationStatus = "scheduled" | "launched" | "acknowledged" | "completed" | "failed" | "waived" | "stale";
5
+ export declare const DELEGATION_DISPATCH_SURFACES: readonly ["claude-task", "cursor-task", "opencode-agent", "codex-agent", "generic-task", "role-switch", "manual"];
6
+ export type DelegationDispatchSurface = typeof DELEGATION_DISPATCH_SURFACES[number];
7
+ /**
8
+ * Per-surface allowed agent-definition path prefixes. Used by the generated
9
+ * `.cclaw/hooks/delegation-record.mjs` helper to reject mismatched
10
+ * `--agent-definition-path` values without inspecting any harness state.
11
+ *
12
+ * The list is intentionally structural: each surface maps to one or more
13
+ * repo-relative path prefixes that must be a parent of the supplied path.
14
+ * `role-switch` and `manual` accept any path because the agent-definition
15
+ * is intentionally not a generated artifact for those surfaces.
16
+ */
17
+ export declare const DELEGATION_DISPATCH_SURFACE_PATH_PREFIXES: Record<DelegationDispatchSurface, string[]>;
18
+ export type DelegationEventType = DelegationStatus;
5
19
  /**
6
20
  * How a delegation was actually fulfilled. Advisory — mirrors the harness
7
21
  * `subagentFallback` that was in effect when the entry was recorded.
@@ -10,8 +24,11 @@ export type DelegationStatus = "scheduled" | "completed" | "failed" | "waived";
10
24
  * - `generic-dispatch` — generic Task/Subagent dispatch mapped to a named role.
11
25
  * - `role-switch` — performed in-session with explicit role announce.
12
26
  * - `harness-waiver` — auto-waived due to missing dispatch capability.
27
+ * - `legacy-inferred` — pre-v3 entry: completed status without dispatch
28
+ * surface/proof. Read-only; stage-complete reports it as a warning until
29
+ * the entry is re-recorded via `delegation-record.mjs --rerecord`.
13
30
  */
14
- export type DelegationFulfillmentMode = "isolated" | "generic-dispatch" | "role-switch" | "harness-waiver";
31
+ export type DelegationFulfillmentMode = "isolated" | "generic-dispatch" | "role-switch" | "harness-waiver" | "legacy-inferred";
15
32
  export interface DelegationTokenUsage {
16
33
  input: number;
17
34
  output: number;
@@ -53,6 +70,20 @@ export type DelegationEntry = {
53
70
  retryCount?: number;
54
71
  /** Optional references to evidence anchors in artifacts. */
55
72
  evidenceRefs?: string[];
73
+ /** Dispatch proof id from the parent/controller side. */
74
+ dispatchId?: string;
75
+ /** Worker-reported run id or task id returned by the harness. */
76
+ workerRunId?: string;
77
+ /** Concrete runtime surface used to launch the worker. */
78
+ dispatchSurface?: DelegationDispatchSurface;
79
+ /** Path to the generated or canonical agent definition used for dispatch. */
80
+ agentDefinitionPath?: string;
81
+ /** ISO timestamp when the worker was acknowledged by the harness/worker. */
82
+ ackTs?: string;
83
+ /** ISO timestamp when the worker was launched. */
84
+ launchedTs?: string;
85
+ /** ISO timestamp when the worker completed. */
86
+ completedTs?: string;
56
87
  /** Optional skill marker used for role-specific mandatory checks. */
57
88
  skill?: string;
58
89
  /**
@@ -61,12 +92,29 @@ export type DelegationEntry = {
61
92
  * harness).
62
93
  */
63
94
  fulfillmentMode?: DelegationFulfillmentMode;
64
- /** Schema version marker for span-compatible delegation logs. */
65
- schemaVersion?: 1;
95
+ /**
96
+ * Schema version marker for span-compatible delegation rows.
97
+ *
98
+ * - `1` — legacy rows that predate the dispatch-surface lock
99
+ * - `2` — historical interim format that introduced ack/launched
100
+ * timestamps but did not require dispatch-surface or ack-ts on
101
+ * completed isolated/generic
102
+ * - `3` — current format: completed isolated/generic must carry
103
+ * `dispatchSurface`, `agentDefinitionPath`, and ACK timestamp
104
+ */
105
+ schemaVersion?: 1 | 2 | 3;
66
106
  };
107
+ export declare const DELEGATION_LEDGER_SCHEMA_VERSION: 3;
67
108
  export type DelegationLedger = {
68
109
  runId: string;
69
110
  entries: DelegationEntry[];
111
+ /** Schema version of the ledger envelope. Current: `3`. */
112
+ schemaVersion?: 1 | 2 | 3;
113
+ };
114
+ export type DelegationEvent = DelegationEntry & {
115
+ event: DelegationEventType;
116
+ eventTs: string;
117
+ schemaVersion: 1 | 2 | 3;
70
118
  };
71
119
  /**
72
120
  * Heuristic: does a changed file path strongly imply a trust-boundary
@@ -79,6 +127,10 @@ export type DelegationLedger = {
79
127
  */
80
128
  export declare function isTrustBoundaryPath(filePath: string): boolean;
81
129
  export declare function readDelegationLedger(projectRoot: string): Promise<DelegationLedger>;
130
+ export declare function readDelegationEvents(projectRoot: string): Promise<{
131
+ events: DelegationEvent[];
132
+ corruptLines: number[];
133
+ }>;
82
134
  export declare function appendDelegation(projectRoot: string, entry: DelegationEntry): Promise<void>;
83
135
  /**
84
136
  * Aggregate the fulfillment mode cclaw expects for the active harness set.
@@ -96,6 +148,12 @@ export declare function checkMandatoryDelegations(projectRoot: string, stage: Fl
96
148
  staleIgnored: string[];
97
149
  /** Delegation rows missing required evidence under a role-switch fallback. */
98
150
  missingEvidence: string[];
151
+ /** Native isolated completion rows that lack dispatch proof. */
152
+ missingDispatchProof: string[];
153
+ /** Legacy inferred isolated completions accepted only as migration warnings. */
154
+ legacyInferredCompletions: string[];
155
+ /** Current-run event log lines that could not be parsed. */
156
+ corruptEventLines: number[];
99
157
  /** Current-run scheduled rows with no terminal row sharing the same spanId. */
100
158
  staleWorkers: string[];
101
159
  /** Expected fulfillment mode for the active harness set. */