letitloop 0.2.0__py3-none-any.whl

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 (175) hide show
  1. letitloop-0.2.0.dist-info/METADATA +232 -0
  2. letitloop-0.2.0.dist-info/RECORD +175 -0
  3. letitloop-0.2.0.dist-info/WHEEL +5 -0
  4. letitloop-0.2.0.dist-info/entry_points.txt +4 -0
  5. letitloop-0.2.0.dist-info/licenses/LICENSE +21 -0
  6. letitloop-0.2.0.dist-info/top_level.txt +1 -0
  7. orchestrator/SKILL.md +292 -0
  8. orchestrator/__init__.py +151 -0
  9. orchestrator/anti_ouroboros.py +78 -0
  10. orchestrator/approval.py +139 -0
  11. orchestrator/ast_node_splicer.py +130 -0
  12. orchestrator/ast_splicer.py +94 -0
  13. orchestrator/audit.py +88 -0
  14. orchestrator/budget.py +195 -0
  15. orchestrator/checkpoint.py +248 -0
  16. orchestrator/cli.py +1971 -0
  17. orchestrator/codebase_introspector.py +66 -0
  18. orchestrator/component_slicer.py +185 -0
  19. orchestrator/config.py +152 -0
  20. orchestrator/contract.py +404 -0
  21. orchestrator/dag_validator.py +172 -0
  22. orchestrator/elasticity_governor.py +80 -0
  23. orchestrator/env_doctor.py +166 -0
  24. orchestrator/errors.py +211 -0
  25. orchestrator/events.py +120 -0
  26. orchestrator/evidence.py +203 -0
  27. orchestrator/exceptions.py +37 -0
  28. orchestrator/experimental/arena_arbiter.py +260 -0
  29. orchestrator/experimental/fuzz_engine.py +206 -0
  30. orchestrator/experimental/mutation_tester.py +382 -0
  31. orchestrator/failure.py +226 -0
  32. orchestrator/fast_sandbox.py +126 -0
  33. orchestrator/feasibility_gate.py +115 -0
  34. orchestrator/feedback.py +302 -0
  35. orchestrator/fixtures/__init__.py +0 -0
  36. orchestrator/fixtures/example_contract.json +50 -0
  37. orchestrator/fixtures/generated/evidence-cli-run-test-step-1.json +47 -0
  38. orchestrator/fixtures/generated/evidence-cli-run-test-step-2.json +47 -0
  39. orchestrator/fixtures/generated/evidence-inject-test-a.json +47 -0
  40. orchestrator/fixtures/generated/evidence-inject-test-b.json +47 -0
  41. orchestrator/fixtures/generated/evidence-inject-test-c.json +47 -0
  42. orchestrator/fixtures/generated/evidence-json-test-a.json +47 -0
  43. orchestrator/fixtures/generated/evidence-json-test-b.json +47 -0
  44. orchestrator/fixtures/generated/fail-report-fail-task-1.json +47 -0
  45. orchestrator/fixtures/generated/fail-report-json-task-1.json +47 -0
  46. orchestrator/fixtures/generated/fail-report-success-task-1.json +47 -0
  47. orchestrator/fixtures/generated/fuzz-engine-design.json +63 -0
  48. orchestrator/fixtures/generated/fuzz-engine-impl.json +62 -0
  49. orchestrator/fixtures/generated/fuzz-engine-tests.json +62 -0
  50. orchestrator/fixtures/generated/fuzz-engine-verify.json +62 -0
  51. orchestrator/fixtures/generated/goal-orch-step-1.json +63 -0
  52. orchestrator/fixtures/generated/goal-orch-step-2.json +62 -0
  53. orchestrator/fixtures/generated/goal-orch-step-3.json +62 -0
  54. orchestrator/fixtures/generated/goal-orch-step-4.json +62 -0
  55. orchestrator/fixtures/generated/goal-orch-step-5.json +62 -0
  56. orchestrator/fixtures/generated/goal-orch-step-6.json +63 -0
  57. orchestrator/fixtures/generated/implement-a-thread-safe-token-bucket-rat-task-1.json +53 -0
  58. orchestrator/fixtures/generated/orchestrator-checkpoint-rollback-3.json +63 -0
  59. orchestrator/fixtures/generated/orchestrator-checkpoint-rollback.json +62 -0
  60. orchestrator/fixtures/generated/orchestrator-live-telemetry-2.json +62 -0
  61. orchestrator/fixtures/generated/orchestrator-live-telemetry.json +62 -0
  62. orchestrator/fixtures/generated/orchestrator-spec-synthesis-1.json +62 -0
  63. orchestrator/fixtures/generated/orchestrator-spec-synthesis.json +62 -0
  64. orchestrator/fixtures/generated/orchestrator-test-verification-4.json +62 -0
  65. orchestrator/fixtures/generated/orchestrator-test-verification.json +62 -0
  66. orchestrator/fixtures/generated/perf-step-1.json +61 -0
  67. orchestrator/fixtures/generated/perf-step-2.json +62 -0
  68. orchestrator/fixtures/generated/perf-step-3.json +62 -0
  69. orchestrator/fixtures/generated/perf-step-4.json +62 -0
  70. orchestrator/fixtures/generated/perf-step-5.json +63 -0
  71. orchestrator/fixtures/generated/phase2-proof-two-step-step-1.json +47 -0
  72. orchestrator/fixtures/generated/phase2-proof-two-step-step-2.json +47 -0
  73. orchestrator/fixtures/generated/planner-spec-synthesis-impl.json +59 -0
  74. orchestrator/fixtures/generated/self-evolution-ast-formatter.json +69 -0
  75. orchestrator/fixtures/generated/self-evolution-checkpoint-rollback.json +70 -0
  76. orchestrator/fixtures/generated/self-evolution-spec-synthesis.json +70 -0
  77. orchestrator/fixtures/generated/self-evolution-step-1.json +70 -0
  78. orchestrator/fixtures/generated/self-evolution-step-2.json +70 -0
  79. orchestrator/fixtures/generated/self-evolution-step-3.json +70 -0
  80. orchestrator/fixtures/generated/self-evolution-step-4.json +70 -0
  81. orchestrator/fixtures/generated/self-evolution-step-5.json +65 -0
  82. orchestrator/fixtures/generated/self-evolution-telemetry.json +70 -0
  83. orchestrator/fixtures/generated/self-evolution-tests.json +71 -0
  84. orchestrator/fixtures/generated/spec-telemetry-research-design.json +64 -0
  85. orchestrator/fixtures/generated/spec-telemetry-step-1.json +62 -0
  86. orchestrator/fixtures/generated/spec-telemetry-step-2.json +62 -0
  87. orchestrator/fixtures/generated/spec-telemetry-step-3.json +62 -0
  88. orchestrator/fixtures/generated/spec-telemetry-step-4.json +62 -0
  89. orchestrator/fixtures/generated/spec-telemetry-step-5.json +62 -0
  90. orchestrator/fixtures/generated/spec-telemetry-verification.json +58 -0
  91. orchestrator/fixtures/generated/token-bucket-impl.json +69 -0
  92. orchestrator/fixtures/generated/token-bucket-step-1.json +70 -0
  93. orchestrator/fixtures/generated/token-bucket-step-2.json +70 -0
  94. orchestrator/fixtures/generated/token-bucket-step-3.json +60 -0
  95. orchestrator/fixtures/generated/token-bucket-tests.json +70 -0
  96. orchestrator/fixtures/generated/token-bucket-verify.json +61 -0
  97. orchestrator/fixtures/generated/trace-ux-tests-step-1.json +64 -0
  98. orchestrator/fixtures/generated/trace-ux-tests-step-2.json +64 -0
  99. orchestrator/fixtures/generated/trace-ux-tests-step-3.json +62 -0
  100. orchestrator/fixtures/generated/tui-live-telemetry-impl.json +59 -0
  101. orchestrator/fixtures/phase1_proof_escalation_contract.json +41 -0
  102. orchestrator/fixtures/phase1_proof_happy_path_contract.json +83 -0
  103. orchestrator/fixtures/phase1_proof_qc_contract.json +41 -0
  104. orchestrator/fixtures/phase1_proof_repair_contract.json +41 -0
  105. orchestrator/fixtures/phase2_proof_two_step_goal.json +15 -0
  106. orchestrator/fixtures/run_proofs.py +299 -0
  107. orchestrator/fixtures/test_normalizer.py +16 -0
  108. orchestrator/generator.py +239 -0
  109. orchestrator/goal.py +245 -0
  110. orchestrator/handoff.py +86 -0
  111. orchestrator/hybrid_worker.py +840 -0
  112. orchestrator/impossibility.py +162 -0
  113. orchestrator/limits.py +60 -0
  114. orchestrator/live_evolution_engine.py +247 -0
  115. orchestrator/llm.py +291 -0
  116. orchestrator/local_tool_calling.py +285 -0
  117. orchestrator/lock.py +404 -0
  118. orchestrator/mcp_client.py +571 -0
  119. orchestrator/mcp_server.py +344 -0
  120. orchestrator/memory_bridge.py +182 -0
  121. orchestrator/metrics.py +159 -0
  122. orchestrator/micro_epoch.py +42 -0
  123. orchestrator/models.py +350 -0
  124. orchestrator/parsing.py +237 -0
  125. orchestrator/patch_applier.py +154 -0
  126. orchestrator/plan_preview.py +138 -0
  127. orchestrator/plan_quality.py +357 -0
  128. orchestrator/planner.py +532 -0
  129. orchestrator/preferences.py +115 -0
  130. orchestrator/preflight.py +141 -0
  131. orchestrator/process_guard.py +357 -0
  132. orchestrator/prometheus_exporter.py +207 -0
  133. orchestrator/prompts.py +275 -0
  134. orchestrator/proposal_ledger.py +194 -0
  135. orchestrator/provenance.py +263 -0
  136. orchestrator/provider_scheduler.py +394 -0
  137. orchestrator/qc/__init__.py +153 -0
  138. orchestrator/qc/aggregator.py +330 -0
  139. orchestrator/qc/parsing.py +287 -0
  140. orchestrator/qc/personas.py +242 -0
  141. orchestrator/qc/runner.py +569 -0
  142. orchestrator/qc_overrule.py +87 -0
  143. orchestrator/qc_review.py +282 -0
  144. orchestrator/quality_lenses.py +314 -0
  145. orchestrator/quality_plan.py +449 -0
  146. orchestrator/quality_plane.py +103 -0
  147. orchestrator/reconcile.py +191 -0
  148. orchestrator/replanner.py +433 -0
  149. orchestrator/research.py +176 -0
  150. orchestrator/review_artifact.py +672 -0
  151. orchestrator/safety.py +271 -0
  152. orchestrator/schemas.py +230 -0
  153. orchestrator/scope.py +466 -0
  154. orchestrator/sensory_radar.py +79 -0
  155. orchestrator/skill_installer.py +140 -0
  156. orchestrator/sse_server.py +160 -0
  157. orchestrator/state.py +871 -0
  158. orchestrator/subprocess_helper.py +131 -0
  159. orchestrator/supervisor/__init__.py +184 -0
  160. orchestrator/supervisor/_shared.py +164 -0
  161. orchestrator/supervisor/cleanup.py +185 -0
  162. orchestrator/supervisor/core.py +1680 -0
  163. orchestrator/supervisor/recovery.py +367 -0
  164. orchestrator/supervisor/reporting.py +251 -0
  165. orchestrator/surgical_extractor.py +119 -0
  166. orchestrator/telemetry.py +61 -0
  167. orchestrator/templates.py +268 -0
  168. orchestrator/token_gate.py +245 -0
  169. orchestrator/tui.py +649 -0
  170. orchestrator/verifier.py +1103 -0
  171. orchestrator/webhooks.py +168 -0
  172. orchestrator/worker.py +469 -0
  173. orchestrator/worker_adapters.py +815 -0
  174. orchestrator/worker_pool.py +121 -0
  175. orchestrator/worktree.py +364 -0
@@ -0,0 +1,367 @@
1
+ """RecoveryMixin - extracted verbatim from the former monolithic supervisor.py."""
2
+
3
+ from orchestrator.dag_validator import DagValidationError, raise_if_invalid
4
+ from orchestrator.supervisor._shared import (
5
+ DEFAULT_RUN_DIR as DEFAULT_RUN_DIR,
6
+ )
7
+ from orchestrator.supervisor._shared import (
8
+ FAILURE_CLASS_TASK_CRASHED as FAILURE_CLASS_TASK_CRASHED,
9
+ )
10
+ from orchestrator.supervisor._shared import (
11
+ MAX_SAME_CLASS_STRIKES as MAX_SAME_CLASS_STRIKES,
12
+ )
13
+ from orchestrator.supervisor._shared import (
14
+ WORKSPACE_ROOT as WORKSPACE_ROOT,
15
+ )
16
+ from orchestrator.supervisor._shared import (
17
+ Any as Any,
18
+ )
19
+ from orchestrator.supervisor._shared import (
20
+ ContractGraph as ContractGraph,
21
+ )
22
+ from orchestrator.supervisor._shared import (
23
+ Dict as Dict,
24
+ )
25
+ from orchestrator.supervisor._shared import (
26
+ Goal as Goal,
27
+ )
28
+ from orchestrator.supervisor._shared import (
29
+ IllegalTransitionError as IllegalTransitionError,
30
+ )
31
+ from orchestrator.supervisor._shared import (
32
+ List as List,
33
+ )
34
+ from orchestrator.supervisor._shared import (
35
+ Optional as Optional,
36
+ )
37
+ from orchestrator.supervisor._shared import (
38
+ Plan as Plan,
39
+ )
40
+ from orchestrator.supervisor._shared import (
41
+ StateError as StateError,
42
+ )
43
+ from orchestrator.supervisor._shared import (
44
+ _pid_alive as _pid_alive,
45
+ )
46
+ from orchestrator.supervisor._shared import (
47
+ _retry_fingerprints as _retry_fingerprints,
48
+ )
49
+ from orchestrator.supervisor._shared import (
50
+ annotate_worker_result as annotate_worker_result,
51
+ )
52
+ from orchestrator.supervisor._shared import (
53
+ audit_mod as audit_mod,
54
+ )
55
+ from orchestrator.supervisor._shared import (
56
+ budget_mod as budget_mod,
57
+ )
58
+ from orchestrator.supervisor._shared import (
59
+ classify_failure as classify_failure,
60
+ )
61
+ from orchestrator.supervisor._shared import (
62
+ count_consecutive_same_class as count_consecutive_same_class,
63
+ )
64
+ from orchestrator.supervisor._shared import (
65
+ cp as cp,
66
+ )
67
+ from orchestrator.supervisor._shared import (
68
+ create_initial_state as create_initial_state,
69
+ )
70
+ from orchestrator.supervisor._shared import (
71
+ ev as ev,
72
+ )
73
+ from orchestrator.supervisor._shared import (
74
+ fb as fb,
75
+ )
76
+ from orchestrator.supervisor._shared import (
77
+ hashlib as hashlib,
78
+ )
79
+ from orchestrator.supervisor._shared import (
80
+ hmac as hmac,
81
+ )
82
+ from orchestrator.supervisor._shared import (
83
+ imp as imp,
84
+ )
85
+ from orchestrator.supervisor._shared import (
86
+ json as json,
87
+ )
88
+ from orchestrator.supervisor._shared import (
89
+ lk as lk,
90
+ )
91
+ from orchestrator.supervisor._shared import (
92
+ lm as lm,
93
+ )
94
+ from orchestrator.supervisor._shared import (
95
+ load_contract as load_contract,
96
+ )
97
+ from orchestrator.supervisor._shared import (
98
+ load_state as load_state,
99
+ )
100
+ from orchestrator.supervisor._shared import (
101
+ mb_mod as mb_mod,
102
+ )
103
+ from orchestrator.supervisor._shared import (
104
+ metrics_mod as metrics_mod,
105
+ )
106
+ from orchestrator.supervisor._shared import (
107
+ os as os,
108
+ )
109
+ from orchestrator.supervisor._shared import (
110
+ re as re,
111
+ )
112
+ from orchestrator.supervisor._shared import (
113
+ rec as rec,
114
+ )
115
+ from orchestrator.supervisor._shared import (
116
+ require_divergent_retry as require_divergent_retry,
117
+ )
118
+ from orchestrator.supervisor._shared import (
119
+ run_preflight as run_preflight,
120
+ )
121
+ from orchestrator.supervisor._shared import (
122
+ run_verification as run_verification,
123
+ )
124
+ from orchestrator.supervisor._shared import (
125
+ run_worker as run_worker,
126
+ )
127
+ from orchestrator.supervisor._shared import (
128
+ save_state as save_state,
129
+ )
130
+ from orchestrator.supervisor._shared import (
131
+ sc as sc,
132
+ )
133
+ from orchestrator.supervisor._shared import (
134
+ sys as sys,
135
+ )
136
+ from orchestrator.supervisor._shared import (
137
+ threading as threading,
138
+ )
139
+ from orchestrator.supervisor._shared import (
140
+ time as time,
141
+ )
142
+ from orchestrator.supervisor._shared import (
143
+ validate_contract_against_plan as validate_contract_against_plan,
144
+ )
145
+ from orchestrator.supervisor._shared import (
146
+ wp as wp,
147
+ )
148
+
149
+
150
+ class RecoveryMixin:
151
+ """Recovery responsibilities of Supervisor (moved verbatim)."""
152
+
153
+ def _save_plan(self):
154
+ """Persist plan.json to disk so graph statuses survive restarts."""
155
+ plan_path = os.path.join(self.run_dir, "plan.json")
156
+ try:
157
+ with open(plan_path, "w", encoding="utf-8") as f:
158
+ json.dump(self.plan.to_dict(), f, indent=2, ensure_ascii=False)
159
+ except OSError:
160
+ pass
161
+
162
+ def _recover_graph_from_state_files(self):
163
+ """Recover task statuses from state files for resumption after interruption.
164
+
165
+ On fresh start, all plan contracts are DRAFTED. After interruption, state files
166
+ contain actual statuses. This method syncs graph nodes from state files so the
167
+ supervisor can resume correctly (skips completed tasks, retries failed ones).
168
+ """
169
+ for task_id in self.graph.nodes:
170
+ state_path = self._state_path(task_id)
171
+ if os.path.isfile(state_path):
172
+ try:
173
+ state = load_state(state_path, journal_dir=self._task_run_dir(task_id))
174
+ actual_status = state.status
175
+ # Orphan sweep (autonomy fix 2026-07-31): a WORKING task
176
+ # whose lease owner is a different, now-dead supervisor pid
177
+ # means the previous run crashed mid-work. Crash + requeue it
178
+ # here so it becomes ready again (fix 3's execution-time
179
+ # check would never fire — WORKING tasks aren't "ready").
180
+ if actual_status == "WORKING":
181
+ lease = state.data.get("worker_lease")
182
+ lease_dead = (
183
+ isinstance(lease, dict)
184
+ and isinstance(lease.get("pid"), int)
185
+ and lease["pid"] != os.getpid()
186
+ and not _pid_alive(lease["pid"])
187
+ )
188
+ if lease_dead:
189
+ state.transition("CRASHED", reason="recovered: orphaned WORKING (lease owner dead)")
190
+ state.patch_data({"crash_reason": "recovered: orphaned WORKING (lease owner dead)"})
191
+ self._safe_save(state, state_path)
192
+ actual_status = "CRASHED"
193
+ self.graph.update_status(task_id, actual_status)
194
+ self.results[task_id] = {"status": actual_status}
195
+ except (
196
+ OSError,
197
+ json.JSONDecodeError,
198
+ ValueError,
199
+ KeyError,
200
+ StateError,
201
+ AttributeError,
202
+ RuntimeError,
203
+ ) as e:
204
+ print(f"[supervisor] State load failed during graph recovery for {task_id}: {e}", file=sys.stderr)
205
+ self.graph.update_status(task_id, "CRASHED")
206
+ self.results[task_id] = {"status": "CRASHED"}
207
+
208
+ def _get_contract_for_task(self, task_id: str) -> Optional[Any]:
209
+ """Retrieve the Contract object for a task_id."""
210
+ c_info = next((c for c in self.plan.contracts if c.get("task_id") == task_id), None)
211
+ if not c_info:
212
+ return None
213
+ contract_path, _ = self._get_contract_path_and_dict(c_info)
214
+ if not contract_path or not os.path.isfile(contract_path):
215
+ c_dict = c_info.get("contract") or c_info
216
+ from orchestrator.contract import Contract
217
+
218
+ try:
219
+ return Contract.from_dict(c_dict, workspace_root=self.workspace_root)
220
+ except (KeyError, ValueError, TypeError, AttributeError) as e:
221
+ print(f"[supervisor] Contract parsing error for {task_id}: {e}", file=sys.stderr)
222
+ return None
223
+ contract, _ = load_contract(contract_path, workspace_root=self.workspace_root)
224
+ return contract
225
+
226
+ def _escalate_stalled_nodes(self):
227
+ """ESCALATE non-terminal nodes after a no-progress iteration and write
228
+ impossibility artifacts — an unattended run must always end in a
229
+ terminal, auditable state (autonomy fix 2026-07-31)."""
230
+ from orchestrator.state import load_state
231
+
232
+ terminal = (
233
+ "COMPLETE",
234
+ "complete",
235
+ "DEGRADED_PASS",
236
+ "FORCE_COMPLETE",
237
+ "ESCALATED",
238
+ "BLOCKED",
239
+ "CANCELLED",
240
+ "FAILED",
241
+ "failed",
242
+ )
243
+ for task_id, node in list(self.graph.nodes.items()):
244
+ if node.get("status", "") in terminal:
245
+ continue
246
+ state_file = self._state_path(task_id)
247
+ if not os.path.isfile(state_file):
248
+ continue
249
+ try:
250
+ state = load_state(state_file, journal_dir=self._task_run_dir(task_id))
251
+ except (OSError, json.JSONDecodeError, ValueError, KeyError):
252
+ continue
253
+ reason = "stall: no progress in supervision loop"
254
+ try:
255
+ state.transition("ESCALATED", reason=reason)
256
+ except IllegalTransitionError:
257
+ try:
258
+ state.transition("CRASHED", reason=reason)
259
+ except IllegalTransitionError:
260
+ # Legal-transition dead end (e.g. READY/DRAFTED) — privileged
261
+ # escalation so the run still ends in a terminal, auditable state.
262
+ state.force_escalate(reason=reason)
263
+ contract = self._get_contract_for_task(task_id)
264
+ if contract is not None:
265
+ try:
266
+ imp.write_impossibility(
267
+ contract=contract,
268
+ state=state,
269
+ goal_id=self.goal.goal_id,
270
+ workspace_root=self.workspace_root,
271
+ )
272
+ except (OSError, ValueError, KeyError, AttributeError):
273
+ pass
274
+ self._safe_save(state, state_file)
275
+ self.graph.update_status(task_id, "ESCALATED")
276
+ with self._shared_lock:
277
+ self.results[task_id] = {"status": "ESCALATED"}
278
+
279
+ def resume_plan(self) -> Dict[str, str]:
280
+ """Resume a partially executed plan from persistent state.
281
+
282
+ Loads existing state from disk, reconstructs graph statuses,
283
+ rehydrates evidence store, then continues execution of remaining
284
+ tasks. Idempotent — safe to call on fully-complete plans.
285
+ """
286
+ try:
287
+ lk.acquire_lock(self.goal.goal_id, self.run_dir)
288
+ except lk.LockHeldError as e:
289
+ print(f"[supervisor] LOCK HELD: {e}", file=sys.stderr)
290
+ self.goal.status = "FAILED"
291
+ return {}
292
+ print(f"[supervisor] lock acquired for {self.goal.goal_id}", file=sys.stderr)
293
+
294
+ try:
295
+ print(f"[supervisor] resuming plan for goal {self.goal.goal_id}", file=sys.stderr)
296
+
297
+ # Issue #17: structural DAG gate before rebuilding execution.
298
+ # Statuses live separately from structure, so full validation of the
299
+ # persisted contract graph is safe (terminal nodes don't alter it).
300
+ try:
301
+ raise_if_invalid(self.plan.contracts)
302
+ except DagValidationError as e:
303
+ print(f"[supervisor] INVALID DAG on resume: {e}", file=sys.stderr)
304
+ raise
305
+
306
+ # Reconstruct graph statuses and evidence_store from disk
307
+ for c_info in self.plan.contracts:
308
+ task_id = c_info["task_id"]
309
+ state_file = self._state_path(task_id)
310
+ if os.path.isfile(state_file):
311
+ state = load_state(state_file)
312
+ if state.status in ("PAUSED", "paused"):
313
+ state.transition("READY", reason="resuming paused task")
314
+ self._safe_save(state, state_file)
315
+ self.graph.update_status(task_id, state.status)
316
+ self.results[task_id] = {"status": state.status}
317
+
318
+ # Rehydrate evidence_store from completed contracts
319
+ if state.status in ("COMPLETE", "complete", "DEGRADED_PASS", "FORCE_COMPLETE"):
320
+ contract_path, contract_dict = self._get_contract_path_and_dict(c_info)
321
+ contract, _ = load_contract(contract_path, workspace_root=self.workspace_root)
322
+ if contract:
323
+ self.evidence_store[task_id] = [
324
+ os.path.join(self.workspace_root, out["path"])
325
+ if not os.path.isabs(out["path"])
326
+ else out["path"]
327
+ for out in contract.outputs
328
+ ]
329
+
330
+ # Try ledger first, fall back to contract inspection
331
+ ledger = ev.load_ledger(self.run_dir)
332
+ if ledger:
333
+ self.evidence_store = ev.rebuild_evidence_store(ledger)
334
+
335
+ # Reconciliation gate — detect tampering / missing outputs before resume
336
+ report = rec.run_reconciliation(
337
+ self.goal.goal_id,
338
+ self.plan,
339
+ self.workspace_root,
340
+ self.run_dir,
341
+ )
342
+ if not report.passed:
343
+ print(
344
+ f"[supervisor] RECONCILIATION ISSUES detected — {report.failed_tasks} problem(s)", file=sys.stderr
345
+ )
346
+ # Reset failed/tampered tasks to RETRY_PENDING or DRAFTED
347
+ for issue in report.issues:
348
+ if issue.task_id in self.graph.nodes:
349
+ self.graph.update_status(issue.task_id, "RETRY_PENDING")
350
+ state_file = self._state_path(issue.task_id)
351
+ if os.path.isfile(state_file):
352
+ st = load_state(state_file)
353
+ st.transition("RETRY_PENDING", reason=f"reconciliation failure: {issue.issue_type}")
354
+ self._safe_save(st, state_file)
355
+ for iss in report.issues:
356
+ print(f" [{iss.issue_type}] {iss.task_id}: {iss.path or '(no path)'}", file=sys.stderr)
357
+ else:
358
+ print(
359
+ f"[supervisor] reconciliation OK — {report.checked_tasks}/{report.total_tasks} tasks clean",
360
+ file=sys.stderr,
361
+ )
362
+
363
+ self.goal.status = "EXECUTING"
364
+ return self._execute_plan()
365
+ finally:
366
+ lk.release_lock(self.run_dir)
367
+ print(f"[supervisor] lock released for {self.goal.goal_id}", file=sys.stderr)
@@ -0,0 +1,251 @@
1
+ """ReportingMixin - extracted verbatim from the former monolithic supervisor.py."""
2
+
3
+ from orchestrator.supervisor._shared import (
4
+ DEFAULT_RUN_DIR as DEFAULT_RUN_DIR,
5
+ )
6
+ from orchestrator.supervisor._shared import (
7
+ FAILURE_CLASS_TASK_CRASHED as FAILURE_CLASS_TASK_CRASHED,
8
+ )
9
+ from orchestrator.supervisor._shared import (
10
+ MAX_SAME_CLASS_STRIKES as MAX_SAME_CLASS_STRIKES,
11
+ )
12
+ from orchestrator.supervisor._shared import (
13
+ WORKSPACE_ROOT as WORKSPACE_ROOT,
14
+ )
15
+ from orchestrator.supervisor._shared import (
16
+ Any as Any,
17
+ )
18
+ from orchestrator.supervisor._shared import (
19
+ ContractGraph as ContractGraph,
20
+ )
21
+ from orchestrator.supervisor._shared import (
22
+ Dict as Dict,
23
+ )
24
+ from orchestrator.supervisor._shared import (
25
+ Goal as Goal,
26
+ )
27
+ from orchestrator.supervisor._shared import (
28
+ IllegalTransitionError as IllegalTransitionError,
29
+ )
30
+ from orchestrator.supervisor._shared import (
31
+ List as List,
32
+ )
33
+ from orchestrator.supervisor._shared import (
34
+ Optional as Optional,
35
+ )
36
+ from orchestrator.supervisor._shared import (
37
+ Plan as Plan,
38
+ )
39
+ from orchestrator.supervisor._shared import (
40
+ StateError as StateError,
41
+ )
42
+ from orchestrator.supervisor._shared import (
43
+ _pid_alive as _pid_alive,
44
+ )
45
+ from orchestrator.supervisor._shared import (
46
+ _retry_fingerprints as _retry_fingerprints,
47
+ )
48
+ from orchestrator.supervisor._shared import (
49
+ annotate_worker_result as annotate_worker_result,
50
+ )
51
+ from orchestrator.supervisor._shared import (
52
+ audit_mod as audit_mod,
53
+ )
54
+ from orchestrator.supervisor._shared import (
55
+ budget_mod as budget_mod,
56
+ )
57
+ from orchestrator.supervisor._shared import (
58
+ classify_failure as classify_failure,
59
+ )
60
+ from orchestrator.supervisor._shared import (
61
+ count_consecutive_same_class as count_consecutive_same_class,
62
+ )
63
+ from orchestrator.supervisor._shared import (
64
+ cp as cp,
65
+ )
66
+ from orchestrator.supervisor._shared import (
67
+ create_initial_state as create_initial_state,
68
+ )
69
+ from orchestrator.supervisor._shared import (
70
+ ev as ev,
71
+ )
72
+ from orchestrator.supervisor._shared import (
73
+ fb as fb,
74
+ )
75
+ from orchestrator.supervisor._shared import (
76
+ hashlib as hashlib,
77
+ )
78
+ from orchestrator.supervisor._shared import (
79
+ hmac as hmac,
80
+ )
81
+ from orchestrator.supervisor._shared import (
82
+ imp as imp,
83
+ )
84
+ from orchestrator.supervisor._shared import (
85
+ json as json,
86
+ )
87
+ from orchestrator.supervisor._shared import (
88
+ lk as lk,
89
+ )
90
+ from orchestrator.supervisor._shared import (
91
+ lm as lm,
92
+ )
93
+ from orchestrator.supervisor._shared import (
94
+ load_contract as load_contract,
95
+ )
96
+ from orchestrator.supervisor._shared import (
97
+ load_state as load_state,
98
+ )
99
+ from orchestrator.supervisor._shared import (
100
+ mb_mod as mb_mod,
101
+ )
102
+ from orchestrator.supervisor._shared import (
103
+ metrics_mod as metrics_mod,
104
+ )
105
+ from orchestrator.supervisor._shared import (
106
+ os as os,
107
+ )
108
+ from orchestrator.supervisor._shared import (
109
+ re as re,
110
+ )
111
+ from orchestrator.supervisor._shared import (
112
+ rec as rec,
113
+ )
114
+ from orchestrator.supervisor._shared import (
115
+ require_divergent_retry as require_divergent_retry,
116
+ )
117
+ from orchestrator.supervisor._shared import (
118
+ run_preflight as run_preflight,
119
+ )
120
+ from orchestrator.supervisor._shared import (
121
+ run_verification as run_verification,
122
+ )
123
+ from orchestrator.supervisor._shared import (
124
+ run_worker as run_worker,
125
+ )
126
+ from orchestrator.supervisor._shared import (
127
+ save_state as save_state,
128
+ )
129
+ from orchestrator.supervisor._shared import (
130
+ sc as sc,
131
+ )
132
+ from orchestrator.supervisor._shared import (
133
+ sys as sys,
134
+ )
135
+ from orchestrator.supervisor._shared import (
136
+ threading as threading,
137
+ )
138
+ from orchestrator.supervisor._shared import (
139
+ time as time,
140
+ )
141
+ from orchestrator.supervisor._shared import (
142
+ validate_contract_against_plan as validate_contract_against_plan,
143
+ )
144
+ from orchestrator.supervisor._shared import (
145
+ wp as wp,
146
+ )
147
+
148
+
149
+ class ReportingMixin:
150
+ """Reporting responsibilities of Supervisor (moved verbatim)."""
151
+
152
+ def _print_run_summary(self) -> None:
153
+ """Print a clear run summary with QC status per task."""
154
+ completed = sum(
155
+ 1
156
+ for r in self.results.values()
157
+ if r.get("status") in ("COMPLETE", "complete", "DEGRADED_PASS", "FORCE_COMPLETE")
158
+ )
159
+ failed = sum(
160
+ 1
161
+ for r in self.results.values()
162
+ if r.get("status") in ("FAILED", "failed", "BLOCKED", "CRASHED", "ESCALATED")
163
+ )
164
+ total = len(self.results)
165
+ print(f"\n{'=' * 60}", file=sys.stderr)
166
+ print(f" GOAL: {self.goal.goal_id}", file=sys.stderr)
167
+ print(f" STATUS: {self.goal.status}", file=sys.stderr)
168
+ print(f" CONTRACTS: {completed}/{total} completed, {failed}/{total} failed", file=sys.stderr)
169
+ print(f"{'=' * 60}", file=sys.stderr)
170
+ for tid, res in sorted(self.results.items()):
171
+ icon = "OK" if res.get("status") in ("COMPLETE", "complete", "DEGRADED_PASS") else "FAIL"
172
+ qc_requested = "no"
173
+ qc_executed = "no"
174
+ qc_verdict = "MISSING"
175
+ state_file = self._state_path(tid)
176
+ if os.path.isfile(state_file):
177
+ try:
178
+ s = load_state(state_file)
179
+ if s.qc_was_executed:
180
+ qc_executed = "yes"
181
+ if any("QC" in e.get("to", "") for e in s.events):
182
+ qc_requested = "yes"
183
+ if "qc_verdict" in s.evidence:
184
+ vp = s.evidence["qc_verdict"]
185
+ if os.path.isfile(vp):
186
+ with open(vp, "r", encoding="utf-8") as _f:
187
+ vd = json.load(_f)
188
+ qc_verdict = vd.get("status", "MISSING")
189
+ except (OSError, json.JSONDecodeError, KeyError, AttributeError, ValueError, RuntimeError):
190
+ pass
191
+ print(
192
+ f" [{icon}] {tid}: {res.get('status', '?'):20s} QC(req={qc_requested} exec={qc_executed} v={qc_verdict})",
193
+ file=sys.stderr,
194
+ )
195
+ print(f"{'=' * 60}\n", file=sys.stderr)
196
+
197
+ def aggregate_results(self) -> Dict[str, Any]:
198
+ """Collect all contract outputs, statuses, and evidence paths into a single dict."""
199
+ contract_summaries = {}
200
+ for c_info in self.plan.contracts:
201
+ task_id = c_info["task_id"]
202
+ state_file = self._state_path(task_id)
203
+ if os.path.isfile(state_file):
204
+ state = load_state(state_file)
205
+ contract_path, _ = self._get_contract_path_and_dict(c_info)
206
+ contract, _ = load_contract(contract_path, workspace_root=self.workspace_root)
207
+ outputs = [out["path"] for out in contract.outputs] if contract else []
208
+ contract_summaries[task_id] = {
209
+ "status": state.status,
210
+ "attempt": state.attempt,
211
+ "evidence": state.evidence,
212
+ "worker_results": state.worker_results,
213
+ "outputs": outputs,
214
+ }
215
+ if (
216
+ state.status in ("COMPLETE", "complete", "DEGRADED_PASS", "FORCE_COMPLETE")
217
+ and task_id not in self.evidence_store
218
+ and contract
219
+ ):
220
+ self.evidence_store[task_id] = [
221
+ os.path.join(self.workspace_root, out["path"])
222
+ if not os.path.isabs(out["path"])
223
+ else out["path"]
224
+ for out in contract.outputs
225
+ ]
226
+ else:
227
+ contract_summaries[task_id] = {
228
+ "status": c_info.get("status", "DRAFTED"),
229
+ "attempt": 0,
230
+ "evidence": {},
231
+ "worker_results": [],
232
+ "outputs": [],
233
+ }
234
+
235
+ completed_count = sum(
236
+ 1
237
+ for s in contract_summaries.values()
238
+ if s["status"] in ("COMPLETE", "complete", "DEGRADED_PASS", "FORCE_COMPLETE")
239
+ )
240
+ return {
241
+ "goal_id": self.goal.goal_id,
242
+ "goal_title": self.goal.title,
243
+ "goal_status": self.goal.status,
244
+ "contracts": contract_summaries,
245
+ "evidence_store": {tid: paths for tid, paths in self.evidence_store.items()},
246
+ "summary": {
247
+ "total": len(self.plan.contracts),
248
+ "completed": completed_count,
249
+ "failed": len(self.plan.contracts) - completed_count,
250
+ },
251
+ }