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
orchestrator/goal.py ADDED
@@ -0,0 +1,245 @@
1
+ """Data models and graph processing for goal-to-contract decomposition."""
2
+
3
+ from datetime import datetime, timezone
4
+ from typing import Any, Dict, List, Optional
5
+
6
+ VALID_GOAL_STATUSES = {"DRAFTED", "PLANNED", "EXECUTING", "COMPLETE", "FAILED", "PAUSED", "CANCELLED"}
7
+
8
+ # Task statuses that are considered final — no further processing needed
9
+ FINAL_TASK_STATUSES = frozenset(
10
+ {
11
+ "COMPLETE",
12
+ "complete",
13
+ "VERIFIED",
14
+ "DEGRADED_PASS",
15
+ "degraded_pass",
16
+ "FORCE_COMPLETE",
17
+ "force_complete",
18
+ "FAILED",
19
+ "failed",
20
+ "BLOCKED",
21
+ "ESCALATED",
22
+ "CRASHED",
23
+ }
24
+ )
25
+
26
+
27
+ class Goal:
28
+ """High-level goal representation."""
29
+
30
+ def __init__(
31
+ self,
32
+ goal_id: str,
33
+ title: str,
34
+ description: str,
35
+ constraints: Optional[Dict[str, Any]] = None,
36
+ dependencies: Optional[List[str]] = None,
37
+ status: str = "DRAFTED",
38
+ ):
39
+ self.goal_id = goal_id
40
+ self.title = title
41
+ self.description = description
42
+ self.constraints = constraints if constraints is not None else {}
43
+ self.dependencies = dependencies if dependencies is not None else []
44
+ self.status = status.upper() if status and status.upper() in VALID_GOAL_STATUSES else "DRAFTED"
45
+
46
+ def to_dict(self) -> Dict[str, Any]:
47
+ return {
48
+ "goal_id": self.goal_id,
49
+ "title": self.title,
50
+ "description": self.description,
51
+ "constraints": self.constraints,
52
+ "dependencies": self.dependencies,
53
+ "status": self.status,
54
+ }
55
+
56
+ @classmethod
57
+ def from_dict(cls, data: Dict[str, Any]) -> "Goal":
58
+ return cls(
59
+ goal_id=data["goal_id"],
60
+ title=data.get("title", ""),
61
+ description=data.get("description", ""),
62
+ constraints=data.get("constraints", {}),
63
+ dependencies=data.get("dependencies", []),
64
+ status=data.get("status", "DRAFTED"),
65
+ )
66
+
67
+ def __repr__(self) -> str:
68
+ return f"<Goal {self.goal_id} status={self.status}>"
69
+
70
+
71
+ class Plan:
72
+ """Execution plan containing structured contracts for a goal."""
73
+
74
+ def __init__(
75
+ self,
76
+ goal_id: str,
77
+ contracts: List[Dict[str, Any]],
78
+ created_at: Optional[str] = None,
79
+ ):
80
+ self.goal_id = goal_id
81
+ self.contracts = contracts
82
+ self.created_at = created_at if created_at is not None else datetime.now(timezone.utc).isoformat()
83
+
84
+ def to_dict(self) -> Dict[str, Any]:
85
+ return {
86
+ "goal_id": self.goal_id,
87
+ "contracts": self.contracts,
88
+ "created_at": self.created_at,
89
+ }
90
+
91
+ @classmethod
92
+ def from_dict(cls, data: Dict[str, Any]) -> "Plan":
93
+ return cls(
94
+ goal_id=data["goal_id"],
95
+ contracts=data.get("contracts", []),
96
+ created_at=data.get("created_at"),
97
+ )
98
+
99
+ def __repr__(self) -> str:
100
+ return f"<Plan goal={self.goal_id} contracts={len(self.contracts)}>"
101
+
102
+
103
+ class ContractGraph:
104
+ """Graph structure to analyze contract dependencies, ordering, and state."""
105
+
106
+ def __init__(self, plan: Plan):
107
+ self.plan = plan
108
+ self.nodes: Dict[str, Dict[str, Any]] = {}
109
+ for c in plan.contracts:
110
+ task_id = c["task_id"]
111
+ self.nodes[task_id] = {
112
+ "task_id": task_id,
113
+ "depends_on": list(c.get("depends_on", [])),
114
+ "status": c.get("status", "DRAFTED"),
115
+ "contract": c.get("contract"),
116
+ "contract_path": c.get("contract_path"),
117
+ }
118
+
119
+ def cycle_path(self, start: Optional[str] = None) -> List[str]:
120
+ """Return one concrete dependency cycle as [A, B, ..., A]; empty list if acyclic.
121
+
122
+ Iterative DFS with a color map (1=on stack, 2=done) and parent-chain
123
+ reconstruction once a back edge hits an on-stack node.
124
+ """
125
+ color: Dict[str, int] = {}
126
+ parent: Dict[str, str] = {}
127
+
128
+ roots = [start] if (start is not None and start in self.nodes) else list(self.nodes.keys())
129
+ for root in roots:
130
+ if color.get(root):
131
+ continue
132
+ color[root] = 1
133
+ stack = [(root, iter(self.nodes.get(root, {}).get("depends_on", [])))]
134
+ while stack:
135
+ node_id, dep_iter = stack[-1]
136
+ advanced = False
137
+ for dep in dep_iter:
138
+ if dep not in self.nodes:
139
+ continue
140
+ state = color.get(dep)
141
+ if state is None:
142
+ color[dep] = 1
143
+ parent[dep] = node_id
144
+ stack.append((dep, iter(self.nodes[dep].get("depends_on", []))))
145
+ advanced = True
146
+ break
147
+ if state == 1:
148
+ chain = []
149
+ cur = node_id
150
+ while True:
151
+ chain.append(cur)
152
+ if cur == dep:
153
+ break
154
+ cur = parent[cur]
155
+ chain.reverse()
156
+ chain.append(dep)
157
+ return chain
158
+ if not advanced:
159
+ color[node_id] = 2
160
+ stack.pop()
161
+ return []
162
+
163
+ def has_cycle(self) -> bool:
164
+ """Return True if a cycle exists in the graph."""
165
+ return bool(self.cycle_path())
166
+
167
+ def topological_sort(self) -> List[str]:
168
+ """Return task IDs in dependency order (dependencies first).
169
+
170
+ Raises ValueError if a cycle is detected.
171
+ """
172
+ if self.has_cycle():
173
+ raise ValueError("Cycle detected in contracts")
174
+
175
+ for node_id, node_data in self.nodes.items():
176
+ for dep in node_data.get("depends_on", []):
177
+ if dep not in self.nodes:
178
+ raise ValueError(f"Contract {node_id} depends on unknown task: {dep}")
179
+
180
+ visited = set()
181
+ order = []
182
+
183
+ def dfs(node_id: str):
184
+ visited.add(node_id)
185
+ for dep in self.nodes.get(node_id, {}).get("depends_on", []):
186
+ if dep in self.nodes and dep not in visited:
187
+ dfs(dep)
188
+ order.append(node_id)
189
+
190
+ for node_id in sorted(self.nodes.keys()):
191
+ if node_id not in visited:
192
+ dfs(node_id)
193
+
194
+ return order
195
+
196
+ def update_status(self, task_id: str, status: str):
197
+ """Update contract status in graph and underlying plan."""
198
+ if task_id in self.nodes:
199
+ self.nodes[task_id]["status"] = status
200
+ for c in self.plan.contracts:
201
+ if c["task_id"] == task_id:
202
+ c["status"] = status
203
+
204
+ def mark_complete(self, task_id: str):
205
+ """Mark task status as complete."""
206
+ self.update_status(task_id, "COMPLETE")
207
+
208
+ def get_ready_tasks(self) -> List[str]:
209
+ """Return task IDs whose dependencies are all complete and not in a final state."""
210
+ ready = []
211
+ try:
212
+ order = self.topological_sort()
213
+ except ValueError:
214
+ return []
215
+ for task_id in order:
216
+ node = self.nodes[task_id]
217
+ if node["status"] in FINAL_TASK_STATUSES:
218
+ continue
219
+ deps_complete = True
220
+ for dep in node["depends_on"]:
221
+ dep_status = self.nodes.get(dep, {}).get("status", "")
222
+ dep_status_upper = dep_status.upper()
223
+ if dep_status_upper not in ("COMPLETE", "VERIFIED"):
224
+ deps_complete = False
225
+ break
226
+ if deps_complete:
227
+ ready.append(task_id)
228
+ return ready
229
+
230
+ def get_blocked_tasks(self) -> List[str]:
231
+ """Return task IDs that have at least one incomplete dependency."""
232
+ blocked = []
233
+ for task_id, node in self.nodes.items():
234
+ if node["status"] in FINAL_TASK_STATUSES:
235
+ continue
236
+ has_incomplete_dep = False
237
+ for dep in node["depends_on"]:
238
+ dep_status = self.nodes.get(dep, {}).get("status", "")
239
+ dep_status_upper = dep_status.upper()
240
+ if dep_status_upper not in ("COMPLETE", "VERIFIED"):
241
+ has_incomplete_dep = True
242
+ break
243
+ if has_incomplete_dep:
244
+ blocked.append(task_id)
245
+ return blocked
@@ -0,0 +1,86 @@
1
+ """State-derived session handoff generation."""
2
+
3
+ import json
4
+ import os
5
+ from datetime import datetime, timezone
6
+
7
+ from .exceptions import HandoffError
8
+ from .state import LEGAL_TRANSITIONS
9
+
10
+
11
+ def _next_legal_actions(state):
12
+ """Return sorted list of legal next transitions from current state."""
13
+ return sorted(LEGAL_TRANSITIONS.get(state.status, set()))
14
+
15
+
16
+ def _outcome_classification(state):
17
+ """Classify outcome: no_change, observation, lesson_candidate, skill_candidate."""
18
+ if state.is_terminal():
19
+ if state.status == "COMPLETE":
20
+ return "lesson_candidate"
21
+ elif state.status == "ESCALATED":
22
+ return "skill_candidate"
23
+ elif state.status == "BLOCKED":
24
+ return "observation"
25
+ return "observation"
26
+
27
+
28
+ def build_handoff(state, run_dir):
29
+ """Build a handoff artifact strictly from state.
30
+
31
+ Returns a dict with keys:
32
+ handoff_id, generated_at, task_id, state, attempt,
33
+ completed_checks, evidence_paths, blocker, next_legal_actions,
34
+ outcome_classification, unresolved_human_decisions.
35
+
36
+ Also writes handoff JSON to run_dir if provided.
37
+ """
38
+ if not state.task_id:
39
+ raise HandoffError("state has no task_id")
40
+
41
+ evidence_paths = list(state.evidence.values()) if state.evidence else []
42
+
43
+ last_event = state.events[-1] if state.events else {}
44
+ blocker = None
45
+ if state.status == "BLOCKED":
46
+ blocker = last_event.get("reason", "blocked by preflight failure")
47
+ elif state.status == "ESCALATED":
48
+ blocker = last_event.get("reason", "impossibility: task escalated after max retries")
49
+
50
+ handoff = {
51
+ "handoff_id": f"handoff-{state.task_id}-{datetime.now(timezone.utc).strftime('%Y%m%d%H%M%S')}",
52
+ "generated_at": datetime.now(timezone.utc).isoformat(),
53
+ "task_id": state.task_id,
54
+ "status": state.status,
55
+ "attempt": state.attempt,
56
+ "completed_checks": [e["to"] for e in state.events],
57
+ "evidence_paths": evidence_paths,
58
+ "blocker": blocker,
59
+ "next_legal_actions": _next_legal_actions(state),
60
+ "outcome_classification": _outcome_classification(state),
61
+ "unresolved_human_decisions": _unresolved_decisions(state),
62
+ }
63
+
64
+ if run_dir:
65
+ os.makedirs(run_dir, exist_ok=True)
66
+ handoff_path = os.path.join(run_dir, "handoff.json")
67
+ with open(handoff_path, "w", encoding="utf-8") as f:
68
+ json.dump(handoff, f, indent=2, ensure_ascii=False)
69
+
70
+ return handoff
71
+
72
+
73
+ def _unresolved_decisions(state):
74
+ """Identify decisions requiring human input."""
75
+ decisions = []
76
+ if state.status == "BLOCKED":
77
+ decisions.append("resolve blocker and transition to PREFLIGHT_RUNNING to retry")
78
+ if state.status == "ESCALATED":
79
+ decisions.append("review impossibility log; decide manual intervention or abort")
80
+ if state.status == "RETRY_PENDING":
81
+ decisions.append("choose changed approach and transition to WORKING")
82
+ if state.status == "QC_REJECTED":
83
+ decisions.append("review QC findings and decide approach or abort")
84
+ if state.status == "QC_CONDITIONAL_PASS":
85
+ decisions.append("review conditional QC findings and fix required items or abort")
86
+ return decisions