agent-threader 2.0.5

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.
Files changed (172) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +126 -0
  3. package/compiled/claude/agent-threader/SKILL.md +361 -0
  4. package/compiled/codex/agent-threader/SKILL.md +361 -0
  5. package/compiled/cursor/rules/agent-threader.mdc +367 -0
  6. package/compiled/cursor/skills/agent-threader/SKILL.md +361 -0
  7. package/compiled/opencode/agent-threader.md +361 -0
  8. package/compiled/windsurf/rules/agent-threader.md +361 -0
  9. package/compiled/windsurf/skills/agent-threader/SKILL.md +361 -0
  10. package/dist/cli/commands/doctor.d.ts +6 -0
  11. package/dist/cli/commands/doctor.d.ts.map +1 -0
  12. package/dist/cli/commands/doctor.js +7 -0
  13. package/dist/cli/commands/doctor.js.map +1 -0
  14. package/dist/cli/commands/explain-error.d.ts +12 -0
  15. package/dist/cli/commands/explain-error.d.ts.map +1 -0
  16. package/dist/cli/commands/explain-error.js +23 -0
  17. package/dist/cli/commands/explain-error.js.map +1 -0
  18. package/dist/cli/commands/init-state.d.ts +6 -0
  19. package/dist/cli/commands/init-state.d.ts.map +1 -0
  20. package/dist/cli/commands/init-state.js +10 -0
  21. package/dist/cli/commands/init-state.js.map +1 -0
  22. package/dist/cli/commands/logs.d.ts +6 -0
  23. package/dist/cli/commands/logs.d.ts.map +1 -0
  24. package/dist/cli/commands/logs.js +9 -0
  25. package/dist/cli/commands/logs.js.map +1 -0
  26. package/dist/cli/commands/parse-heal.d.ts +6 -0
  27. package/dist/cli/commands/parse-heal.d.ts.map +1 -0
  28. package/dist/cli/commands/parse-heal.js +5 -0
  29. package/dist/cli/commands/parse-heal.js.map +1 -0
  30. package/dist/cli/commands/parse-result.d.ts +6 -0
  31. package/dist/cli/commands/parse-result.d.ts.map +1 -0
  32. package/dist/cli/commands/parse-result.js +5 -0
  33. package/dist/cli/commands/parse-result.js.map +1 -0
  34. package/dist/cli/commands/status.d.ts +6 -0
  35. package/dist/cli/commands/status.d.ts.map +1 -0
  36. package/dist/cli/commands/status.js +5 -0
  37. package/dist/cli/commands/status.js.map +1 -0
  38. package/dist/cli/commands/validate-manifest.d.ts +6 -0
  39. package/dist/cli/commands/validate-manifest.d.ts.map +1 -0
  40. package/dist/cli/commands/validate-manifest.js +5 -0
  41. package/dist/cli/commands/validate-manifest.js.map +1 -0
  42. package/dist/cli/index.d.ts +6 -0
  43. package/dist/cli/index.d.ts.map +1 -0
  44. package/dist/cli/index.js +360 -0
  45. package/dist/cli/index.js.map +1 -0
  46. package/dist/cli/output-formatter.d.ts +6 -0
  47. package/dist/cli/output-formatter.d.ts.map +1 -0
  48. package/dist/cli/output-formatter.js +19 -0
  49. package/dist/cli/output-formatter.js.map +1 -0
  50. package/dist/index.d.ts +3 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +5 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/lib/adapters/types.d.ts +40 -0
  55. package/dist/lib/adapters/types.d.ts.map +1 -0
  56. package/dist/lib/adapters/types.js +3 -0
  57. package/dist/lib/adapters/types.js.map +1 -0
  58. package/dist/lib/contracts/schema-validator.d.ts +15 -0
  59. package/dist/lib/contracts/schema-validator.d.ts.map +1 -0
  60. package/dist/lib/contracts/schema-validator.js +63 -0
  61. package/dist/lib/contracts/schema-validator.js.map +1 -0
  62. package/dist/lib/contracts/types.d.ts +91 -0
  63. package/dist/lib/contracts/types.d.ts.map +1 -0
  64. package/dist/lib/contracts/types.js +15 -0
  65. package/dist/lib/contracts/types.js.map +1 -0
  66. package/dist/lib/contracts/validate-manifest.d.ts +16 -0
  67. package/dist/lib/contracts/validate-manifest.d.ts.map +1 -0
  68. package/dist/lib/contracts/validate-manifest.js +123 -0
  69. package/dist/lib/contracts/validate-manifest.js.map +1 -0
  70. package/dist/lib/diagnostics/doctor.d.ts +17 -0
  71. package/dist/lib/diagnostics/doctor.d.ts.map +1 -0
  72. package/dist/lib/diagnostics/doctor.js +131 -0
  73. package/dist/lib/diagnostics/doctor.js.map +1 -0
  74. package/dist/lib/errors/explain-error.d.ts +10 -0
  75. package/dist/lib/errors/explain-error.d.ts.map +1 -0
  76. package/dist/lib/errors/explain-error.js +73 -0
  77. package/dist/lib/errors/explain-error.js.map +1 -0
  78. package/dist/lib/errors/types.d.ts +16 -0
  79. package/dist/lib/errors/types.d.ts.map +1 -0
  80. package/dist/lib/errors/types.js +50 -0
  81. package/dist/lib/errors/types.js.map +1 -0
  82. package/dist/lib/index.d.ts +29 -0
  83. package/dist/lib/index.d.ts.map +1 -0
  84. package/dist/lib/index.js +25 -0
  85. package/dist/lib/index.js.map +1 -0
  86. package/dist/lib/orchestrator/batch-strategy.d.ts +9 -0
  87. package/dist/lib/orchestrator/batch-strategy.d.ts.map +1 -0
  88. package/dist/lib/orchestrator/batch-strategy.js +34 -0
  89. package/dist/lib/orchestrator/batch-strategy.js.map +1 -0
  90. package/dist/lib/orchestrator/healing-policy.d.ts +47 -0
  91. package/dist/lib/orchestrator/healing-policy.d.ts.map +1 -0
  92. package/dist/lib/orchestrator/healing-policy.js +104 -0
  93. package/dist/lib/orchestrator/healing-policy.js.map +1 -0
  94. package/dist/lib/orchestrator/index.d.ts +11 -0
  95. package/dist/lib/orchestrator/index.d.ts.map +1 -0
  96. package/dist/lib/orchestrator/index.js +11 -0
  97. package/dist/lib/orchestrator/index.js.map +1 -0
  98. package/dist/lib/orchestrator/patch-validation.d.ts +9 -0
  99. package/dist/lib/orchestrator/patch-validation.d.ts.map +1 -0
  100. package/dist/lib/orchestrator/patch-validation.js +58 -0
  101. package/dist/lib/orchestrator/patch-validation.js.map +1 -0
  102. package/dist/lib/orchestrator/scheduling.d.ts +12 -0
  103. package/dist/lib/orchestrator/scheduling.d.ts.map +1 -0
  104. package/dist/lib/orchestrator/scheduling.js +74 -0
  105. package/dist/lib/orchestrator/scheduling.js.map +1 -0
  106. package/dist/lib/orchestrator/write-safety.d.ts +14 -0
  107. package/dist/lib/orchestrator/write-safety.d.ts.map +1 -0
  108. package/dist/lib/orchestrator/write-safety.js +44 -0
  109. package/dist/lib/orchestrator/write-safety.js.map +1 -0
  110. package/dist/lib/parser/parse-heal.d.ts +12 -0
  111. package/dist/lib/parser/parse-heal.d.ts.map +1 -0
  112. package/dist/lib/parser/parse-heal.js +9 -0
  113. package/dist/lib/parser/parse-heal.js.map +1 -0
  114. package/dist/lib/parser/parse-result.d.ts +12 -0
  115. package/dist/lib/parser/parse-result.d.ts.map +1 -0
  116. package/dist/lib/parser/parse-result.js +9 -0
  117. package/dist/lib/parser/parse-result.js.map +1 -0
  118. package/dist/lib/parser/parser.d.ts +8 -0
  119. package/dist/lib/parser/parser.d.ts.map +1 -0
  120. package/dist/lib/parser/parser.js +167 -0
  121. package/dist/lib/parser/parser.js.map +1 -0
  122. package/dist/lib/state/init-state.d.ts +15 -0
  123. package/dist/lib/state/init-state.d.ts.map +1 -0
  124. package/dist/lib/state/init-state.js +50 -0
  125. package/dist/lib/state/init-state.js.map +1 -0
  126. package/dist/lib/state/logs.d.ts +19 -0
  127. package/dist/lib/state/logs.d.ts.map +1 -0
  128. package/dist/lib/state/logs.js +25 -0
  129. package/dist/lib/state/logs.js.map +1 -0
  130. package/dist/lib/state/state.d.ts +7 -0
  131. package/dist/lib/state/state.d.ts.map +1 -0
  132. package/dist/lib/state/state.js +72 -0
  133. package/dist/lib/state/state.js.map +1 -0
  134. package/dist/lib/state/status.d.ts +22 -0
  135. package/dist/lib/state/status.d.ts.map +1 -0
  136. package/dist/lib/state/status.js +34 -0
  137. package/dist/lib/state/status.js.map +1 -0
  138. package/dist/lib/state/types.d.ts +55 -0
  139. package/dist/lib/state/types.d.ts.map +1 -0
  140. package/dist/lib/state/types.js +14 -0
  141. package/dist/lib/state/types.js.map +1 -0
  142. package/install-local.sh +239 -0
  143. package/install.sh +36 -0
  144. package/package.json +55 -0
  145. package/site/CNAME +1 -0
  146. package/site/index.html +141 -0
  147. package/site/install.sh +36 -0
  148. package/site/style.css +319 -0
  149. package/skill/SKILL.md +127 -0
  150. package/skill/SPEC.md +1189 -0
  151. package/skill/build/compile.mjs +237 -0
  152. package/skill/build/manifest.json +21 -0
  153. package/skill/fragments/common/model-selection.md +11 -0
  154. package/skill/fragments/common/portability-rules.md +16 -0
  155. package/skill/fragments/common/workflow.md +12 -0
  156. package/skill/fragments/domain/adapter-model.md +42 -0
  157. package/skill/fragments/domain/architecture-overview.md +36 -0
  158. package/skill/fragments/domain/contracts.md +31 -0
  159. package/skill/fragments/domain/pbh-healing.md +47 -0
  160. package/skill/fragments/domain/state-resume.md +34 -0
  161. package/skill/fragments/domain/verification-safety.md +33 -0
  162. package/skill/fragments/meta/schemas-reference.md +13 -0
  163. package/skill/fragments/meta/templates-reference.md +11 -0
  164. package/skill/schemas/heal_decision.v2.json +100 -0
  165. package/skill/schemas/manifest.v2.json +91 -0
  166. package/skill/schemas/state.v2.json +183 -0
  167. package/skill/schemas/task_result.v2.json +104 -0
  168. package/skill/schemas/verify_profile.v2.json +61 -0
  169. package/skill/skills/agent-threader/agent-threader.md +85 -0
  170. package/skill/templates/orchestrator.ts +38 -0
  171. package/skill/templates/parser.ts +384 -0
  172. package/skill/templates/types.ts +282 -0
@@ -0,0 +1,367 @@
1
+ ---
2
+ description: "agent-threader skill"
3
+ globs: []
4
+ alwaysApply: false
5
+ ---
6
+
7
+ <!-- managed_by: agent-threader -->
8
+ ---
9
+ name: agent-threader
10
+ version: "2.0"
11
+ description: "AgentThreader -- build or review manifest-driven agentic CLI orchestration with structured JSON contracts, schema-validated parsing, resumable state, dependency-aware scheduling, bounded self-healing, and orchestrator-owned verification."
12
+ ---
13
+
14
+ # AgentThreader
15
+
16
+ ## When To Use This Skill
17
+
18
+ Use this skill when manual chat execution no longer scales and the right answer is a repeatable runner around an agentic CLI.
19
+
20
+ Matching requests include:
21
+
22
+ - batch prompt runners over tasks, manifests, components, stories, or tickets
23
+ - looping an agentic CLI (`agent`, `opencode`, `claude`) across many items
24
+ - resumable or checkpointed agent loops with per-task logs
25
+ - self-healing outer loops that diagnose failures and patch prompts
26
+ - overnight or unattended batch runs with verification gates
27
+ - stage-based workflows where items pass through multiple prompt phases
28
+ - log triage followed by targeted recheck runs
29
+
30
+ ## Architecture
31
+
32
+ ### Architecture Overview
33
+
34
+ The v2 system has five moving parts:
35
+
36
+ 1. **Manifest** -- declares work items, dependencies, timeouts, and verification profiles.
37
+ 2. **Orchestrator** -- owns scheduling, parsing, verification, checkpointing, healing, and retry policy. The orchestrator is the single source of truth for task status.
38
+ 3. **Adapters** -- CLI-specific execution layers (`agent`, `opencode`, `claude`) that the orchestrator calls through a uniform `CliAdapter` interface.
39
+ 4. **Worker** -- the model invocation that performs task work and emits a `task_result.v2` JSON contract fenced by `<<<TASK_RESULT_V2>>>` sentinels.
40
+ 5. **Healer** -- the model invocation that diagnoses fixable failures and emits a `heal_decision.v2` JSON contract fenced by `<<<HEAL_DECISION_V2>>>` sentinels.
41
+
42
+ ### Control Flow
43
+
44
+ ```text
45
+ Manifest
46
+ -> Orchestrator
47
+ -> Adapter -> Worker
48
+ -> Parser and Schema Validator
49
+ -> Verification Gates
50
+ -> State Checkpoint
51
+ -> Healer (at batch checkpoints when policy requires)
52
+ -> Patch Validation and Application
53
+ -> Resume or Escalate
54
+ ```
55
+
56
+ Worker and healer outputs are candidate data until the orchestrator validates and commits them to state. Exit code alone is never treated as task success.
57
+
58
+ ### Canonical Source Tree
59
+
60
+ ```text
61
+ agent-threader/
62
+ SKILL.md -- skill entrypoint
63
+ SPEC.md -- normative architecture specification
64
+ schemas/ -- JSON schemas for all contracts
65
+ templates/ -- TypeScript scaffolding (types, parser, orchestrator utilities)
66
+ platforms/ -- thin wrappers for Codex, Cursor, Claude, Windsurf
67
+ ```
68
+
69
+ ---
70
+
71
+ ## Contracts
72
+
73
+ ### Contracts
74
+
75
+ All public contracts are JSON, versioned (`"2.0"`), and schema-validated. Machine-readable schemas live in `schemas/`.
76
+
77
+ ### manifest.v2
78
+
79
+ Declares tasks with required fields: `id`, `prompt_ref`, `depends_on`, `timeout_sec`, `verify_profile`. Optional: `context_refs`, `priority`, `retry_policy`, `metadata`.
80
+
81
+ Tasks are topologically sorted by `depends_on`. Lower `priority` values run first. A task cannot start until all dependencies are `DONE`.
82
+
83
+ ### task_result.v2
84
+
85
+ Emitted by the worker inside `<<<TASK_RESULT_V2>>>` / `<<<END_TASK_RESULT_V2>>>` sentinels.
86
+
87
+ Required fields: `contract_version`, `task_id`, `status` (DONE | BLOCKED | FAILED | CONTRACT_ERROR), `summary`.
88
+
89
+ Optional: `changed_files`, `writes[]` (with `path`, `op`, `encoding`, `content` or `content_ref`), `evidence` (commands, log_refs, notes), `failure_class`.
90
+
91
+ ### heal_decision.v2
92
+
93
+ Emitted by the healer inside `<<<HEAL_DECISION_V2>>>` / `<<<END_HEAL_DECISION_V2>>>` sentinels.
94
+
95
+ Required fields: `contract_version`, `scope` (task | batch | epoch), `decision` (RETRY | ESCALATE | NOT_FIXABLE), `failure_class`, `root_cause`, `patches[]`.
96
+
97
+ Patch targets: `shared_context`, `task_prompt`, `runtime_patch`, `contract_hint`. Each patch has `target`, `operation` (replace | append | merge), and `content`.
98
+
99
+ Optional: `learned_rule`, `escalations[]`, `retry_policy` (`reset_tasks`, `retry_window`).
100
+
101
+ ### state.v2
102
+
103
+ Persistent run state with: `run_id`, `run_status` (RUNNING | COMPLETED | ABORTED), `policy`, per-task state (status, attempts, failure signatures, history), and `healing_rounds[]`. Written atomically via temp file + rename.
104
+
105
+ ---
106
+
107
+ ## Healing Model
108
+
109
+ ### Progressive Batch Healing (PBH)
110
+
111
+ PBH is the default healing strategy. It starts with a small healing window, grows when stable, shrinks when unstable, and stops when automation is no longer justified.
112
+
113
+ ### Scheduling Modes
114
+
115
+ | Mode | Meaning |
116
+ | --- | --- |
117
+ | `auto` | PBH with adaptive growth and shrink. **Default.** |
118
+ | `off` | Healing disabled. |
119
+ | `task` | Heal only the single failed task. Window size is always 1. |
120
+ | `batch` | Heal at fixed batch checkpoints. Default fixed size is 5. |
121
+ | `epoch` | Attempt all pending tasks before healing. |
122
+
123
+ ### PBH Defaults
124
+
125
+ - `heal.schedule = auto`
126
+ - `batch.strategy = fibonacci` (sequence: 1, 2, 3, 5, 8, 13, ...)
127
+ - `failure_threshold = 0.2`
128
+ - `max_worker_attempts_per_task = 2`
129
+ - `max_heal_rounds_per_window = 2`
130
+ - `max_total_heal_rounds = 8`
131
+ - `signature_repeat_limit = 2`
132
+
133
+ ### PBH Behavior
134
+
135
+ - Zero failures in a window: advance to the next larger batch size.
136
+ - Failure rate > 0 but <= threshold: run healer once, retry the same window.
137
+ - Failure rate > threshold: shrink one batch level, isolate repeated signatures.
138
+ - Same signature repeats after healing: escalate that task.
139
+ - No convergence (failing set unchanged across rounds): abort the run.
140
+
141
+ ### Healable vs Non-Healable
142
+
143
+ Healable: `prompt_gap`, `missing_paths`, `weak_contract`, `contract_error`, `output_format`, `timeout`, `transient_infra`.
144
+
145
+ Non-healable: `blocked_external`, `real_bug`.
146
+
147
+ `build_error`, `test_error`, `smoke_error` may be healable when evidence points to prompt or configuration rather than a genuine product defect.
148
+
149
+ ### Convergence
150
+
151
+ Healing converges when at least one of: total failing count drops, repeated signature count drops, or a broad failure class narrows to a local issue. Healing is non-convergent when the same set persists, same signatures repeat, or budget is exhausted.
152
+
153
+ ### Healer Authority
154
+
155
+ The healer may emit bounded runtime patches (`timeout_sec`, `concurrency`, `current_batch_size`) validated by the orchestrator against operator limits. The healer must not modify `heal.schedule`, `batch.strategy`, verification commands, protected-file rules, parser behavior, or model identity.
156
+
157
+ ---
158
+
159
+ ## Verification and Safety
160
+
161
+ ### Verification and Safety Model
162
+
163
+ ### Verification Ownership
164
+
165
+ Verification always belongs to the orchestrator. It runs after successful parse and before final task success. The worker may report evidence, but does not own pass/fail classification.
166
+
167
+ ### Verification Layers
168
+
169
+ | Layer | Timing | Purpose |
170
+ | --- | --- | --- |
171
+ | Post-parse validation | After parsing worker output | Contract integrity, candidate writes, path safety |
172
+ | Post-write build/test | After writes are applied | Build, test, lint, or type failures caused by the change |
173
+ | Final smoke/browser | After build and test pass | Runtime behavior, UI behavior, custom project checks |
174
+
175
+ ### Allowed Write Path
176
+
177
+ 1. Worker emits `writes[]` in `task_result.v2`.
178
+ 2. Orchestrator validates those writes.
179
+ 3. Orchestrator applies those writes.
180
+ 4. Orchestrator verifies the result.
181
+
182
+ ### Required Write Safeguards
183
+
184
+ - Path normalization (writes cannot escape workspace root).
185
+ - Protected-file denylist.
186
+ - Shrinkage detection: reject replacement when original > 100 bytes and replacement < 50% of original size (unless explicitly allowed).
187
+ - Optional `sha256_before` precondition validation.
188
+ - Backup before write.
189
+ - Rollback on verification failure.
190
+
191
+ ### Healer Patch Safety
192
+
193
+ Healer patches follow the same validation model. The healer is forbidden from editing product source files directly, disabling verification, bypassing protected-file rules, or changing healing schedule mid-run.
194
+
195
+ ---
196
+
197
+ ## Adapter Model
198
+
199
+ ### Adapter Model
200
+
201
+ Adapters are the only place where CLI-specific behavior lives. The orchestrator core never calls CLIs directly -- it goes through `CliAdapter.execute`.
202
+
203
+ ### Adapter Responsibilities
204
+
205
+ - Construct the concrete CLI invocation (command, flags, working directory).
206
+ - Decide whether prompt delivery uses stdin, argv, or PTY interaction.
207
+ - Manage PTY or expect requirements for interactive CLIs.
208
+ - Capture combined stdout and stderr to the execution log.
209
+ - Return execution artifacts to the orchestrator.
210
+ - Delegate contract parsing and schema validation to the shared parser utilities.
211
+
212
+ ### Orchestrator Boundary
213
+
214
+ The orchestrator must:
215
+
216
+ - Never call CLIs directly except through `CliAdapter.execute`.
217
+ - Never parse raw logs without going through parser and validator modules.
218
+ - Never assume exit code alone means success.
219
+ - Remain CLI-agnostic outside the adapter boundary.
220
+
221
+ ### Reference Adapters
222
+
223
+ Initial adapters: `agent`, `opencode`, `claude`. All share one orchestrator contract model.
224
+
225
+ ### Interactive CLI Handling
226
+
227
+ For interactive CLIs, prompt rescue logic and TTY heuristics are adapter-local. Interactive adapters should implement ANSI stripping, bounded idle detection, finite rescue attempts, and explicit completion detection.
228
+
229
+ ### CliAdapter Interface
230
+
231
+ ```typescript
232
+ interface CliAdapter {
233
+ id: string;
234
+ capabilities: { stdinPrompt: boolean; argPrompt: boolean; pty: boolean; interactive: boolean };
235
+ prepare(task, ctx): PreparedInvocation;
236
+ execute(invocation, ctx): Promise<ExecutionArtifact>;
237
+ extractResult(artifact, ctx): Promise<TaskResultV2 | ParserFailure>;
238
+ healthcheck(ctx): Promise<AdapterHealth>;
239
+ }
240
+ ```
241
+
242
+ ---
243
+
244
+ ## State and Resume
245
+
246
+ ### State, Resume, and Convergence
247
+
248
+ ### Atomic State Writes
249
+
250
+ Mandatory. The orchestrator writes state via a temporary file followed by atomic rename on the same filesystem. State is checkpointed after every task attempt and every healing round.
251
+
252
+ ### Resume Semantics
253
+
254
+ - `DONE` tasks are skipped on resume if `manifest_digest` still matches.
255
+ - If `manifest_digest` changes, the orchestrator warns or forces reconciliation.
256
+ - `ESCALATED` tasks are not retried automatically.
257
+ - `FAILED` and `BLOCKED` tasks are eligible only if retry policy allows.
258
+
259
+ Reconciliation handles: tasks removed since last run, tasks added, tasks whose `prompt_ref`, `depends_on`, or `verify_profile` changed.
260
+
261
+ ### Failure Signature Generation
262
+
263
+ Stable failure signatures follow this algorithm:
264
+
265
+ 1. Start with the normalized failure class.
266
+ 2. Extract the primary stable signal from parser output, verification logs, or error codes.
267
+ 3. Remove timestamps, absolute paths, task IDs, and unstable numbers.
268
+ 4. Lowercase and collapse whitespace.
269
+ 5. Truncate to a stable maximum length.
270
+
271
+ Format: `<failure_class>:<normalized_signal>` (e.g., `build_error:missing_cn_import`).
272
+
273
+ ### Escalation Rules
274
+
275
+ Per-task: escalate when a task repeats the same signature `signature_repeat_limit` times after healing, or when a non-healable failure exhausts retry policy.
276
+
277
+ Per-run: escalate when `max_total_heal_rounds` is exhausted without convergence, or continuing would only repeat the same failure set.
278
+
279
+ Escalated tasks remain in state for reporting. Aborted runs record `run_status: ABORTED` with a non-empty `abort_reason`.
280
+
281
+ ---
282
+
283
+ ## Normative Specification
284
+
285
+ The full architecture, contracts, schemas, and behavioral rules are defined in `SPEC.md`. That document is the single source of truth. Read it when you need the end-to-end control flow, complete schema field definitions, or edge-case behavioral rules.
286
+
287
+ ## Canonical Source Of Truth
288
+
289
+ ### Schemas
290
+
291
+ Machine-readable JSON schemas (JSON Schema 2020-12) live in `schemas/`:
292
+
293
+ | Schema | Contract |
294
+ | --- | --- |
295
+ | `manifest.v2.json` | Task manifest: tasks with deps, timeouts, verify profiles |
296
+ | `verify_profile.v2.json` | Operator-defined verification profiles with steps and rollback flag |
297
+ | `task_result.v2.json` | Worker output: task_id, status, summary, optional writes and evidence |
298
+ | `heal_decision.v2.json` | Healer output: decision, patches, learned_rule |
299
+ | `state.v2.json` | Persistent run state: run_status, policy, per-task state, healing_rounds |
300
+
301
+ These schemas are the machine-readable authority. The orchestrator validates all contracts against them before state mutation.
302
+
303
+ ### Templates
304
+
305
+ Reference implementation skeletons live in `templates/`:
306
+
307
+ | File | Contents |
308
+ | --- | --- |
309
+ | `types.ts` | TypeScript type definitions for all v2 contracts: `ManifestV2`, `TaskResultV2`, `HealDecisionV2`, `StateV2`, `CliAdapter` interface, failure classes, PBH fibonacci sequence, default policy |
310
+ | `parser.ts` | Shared parser and validator: sentinel extraction (last block wins), JSON repair (strip markdown fences, trailing commas, JS comments), task result and heal decision validation, failure signature generation |
311
+ | `orchestrator.ts` | Shared runtime utilities: `writeAtomicJson` (temp file + rename) and `stableFailureSignature` (normalizes failure fingerprints) |
312
+
313
+ These templates are starting points for downstream runner implementations. Copy them into your project and extend as needed.
314
+
315
+ ---
316
+
317
+ ## Model Selection
318
+
319
+ ### Self-Healing: Model Selection Rule
320
+
321
+ When the user requests a self-healing runner, ask which models to use before generating code:
322
+
323
+ - **Worker CLI and model** -- runs the inner loop (can be fast/cheap)
324
+ - **Healer CLI and model** -- runs the outer diagnosis loop (should be more capable)
325
+
326
+ If the user does not specify, state the defaults explicitly before proceeding:
327
+
328
+ - Worker: the CLI the user is already using, default model
329
+ - Healer: same CLI family, stronger model tier
330
+
331
+ ---
332
+
333
+ ## Portability
334
+
335
+ ### Portability Rules
336
+
337
+ Platform wrappers may adapt:
338
+
339
+ - invocation command and flags
340
+ - prompt transport (`stdin`, argument, or PTY)
341
+ - approval handling and setup notes
342
+
343
+ Platform wrappers MUST preserve:
344
+
345
+ - contract field names and sentinel strings
346
+ - parser behavior
347
+ - PBH defaults and convergence rules
348
+ - state transitions and resume semantics
349
+
350
+ Platform wrappers MUST NOT redefine architecture, contracts, or healing policy.
351
+
352
+ ---
353
+
354
+ ## Workflow
355
+
356
+ ### Workflow
357
+
358
+ 1. Define the unit of work (component, story, work package, ticket, file).
359
+ 2. Create the manifest (`manifest.v2` JSON).
360
+ 3. Write shared context and per-task prompts.
361
+ 4. Define the completion contract in the prompt (instruct the worker to emit `<<<TASK_RESULT_V2>>>`).
362
+ 5. Choose the CLI adapter (`agent`, `opencode`, `claude`).
363
+ 6. Build the orchestrator (use `templates/` as starting point).
364
+ 7. Run sequential first, add concurrency after contracts and parsing are stable.
365
+ 8. Add verification gates (build, test, lint, smoke).
366
+ 9. Add healing only after the base loop works (`--heal auto`).
367
+ 10. Resume with `--resume` after interruptions.