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.
- letitloop-0.2.0.dist-info/METADATA +232 -0
- letitloop-0.2.0.dist-info/RECORD +175 -0
- letitloop-0.2.0.dist-info/WHEEL +5 -0
- letitloop-0.2.0.dist-info/entry_points.txt +4 -0
- letitloop-0.2.0.dist-info/licenses/LICENSE +21 -0
- letitloop-0.2.0.dist-info/top_level.txt +1 -0
- orchestrator/SKILL.md +292 -0
- orchestrator/__init__.py +151 -0
- orchestrator/anti_ouroboros.py +78 -0
- orchestrator/approval.py +139 -0
- orchestrator/ast_node_splicer.py +130 -0
- orchestrator/ast_splicer.py +94 -0
- orchestrator/audit.py +88 -0
- orchestrator/budget.py +195 -0
- orchestrator/checkpoint.py +248 -0
- orchestrator/cli.py +1971 -0
- orchestrator/codebase_introspector.py +66 -0
- orchestrator/component_slicer.py +185 -0
- orchestrator/config.py +152 -0
- orchestrator/contract.py +404 -0
- orchestrator/dag_validator.py +172 -0
- orchestrator/elasticity_governor.py +80 -0
- orchestrator/env_doctor.py +166 -0
- orchestrator/errors.py +211 -0
- orchestrator/events.py +120 -0
- orchestrator/evidence.py +203 -0
- orchestrator/exceptions.py +37 -0
- orchestrator/experimental/arena_arbiter.py +260 -0
- orchestrator/experimental/fuzz_engine.py +206 -0
- orchestrator/experimental/mutation_tester.py +382 -0
- orchestrator/failure.py +226 -0
- orchestrator/fast_sandbox.py +126 -0
- orchestrator/feasibility_gate.py +115 -0
- orchestrator/feedback.py +302 -0
- orchestrator/fixtures/__init__.py +0 -0
- orchestrator/fixtures/example_contract.json +50 -0
- orchestrator/fixtures/generated/evidence-cli-run-test-step-1.json +47 -0
- orchestrator/fixtures/generated/evidence-cli-run-test-step-2.json +47 -0
- orchestrator/fixtures/generated/evidence-inject-test-a.json +47 -0
- orchestrator/fixtures/generated/evidence-inject-test-b.json +47 -0
- orchestrator/fixtures/generated/evidence-inject-test-c.json +47 -0
- orchestrator/fixtures/generated/evidence-json-test-a.json +47 -0
- orchestrator/fixtures/generated/evidence-json-test-b.json +47 -0
- orchestrator/fixtures/generated/fail-report-fail-task-1.json +47 -0
- orchestrator/fixtures/generated/fail-report-json-task-1.json +47 -0
- orchestrator/fixtures/generated/fail-report-success-task-1.json +47 -0
- orchestrator/fixtures/generated/fuzz-engine-design.json +63 -0
- orchestrator/fixtures/generated/fuzz-engine-impl.json +62 -0
- orchestrator/fixtures/generated/fuzz-engine-tests.json +62 -0
- orchestrator/fixtures/generated/fuzz-engine-verify.json +62 -0
- orchestrator/fixtures/generated/goal-orch-step-1.json +63 -0
- orchestrator/fixtures/generated/goal-orch-step-2.json +62 -0
- orchestrator/fixtures/generated/goal-orch-step-3.json +62 -0
- orchestrator/fixtures/generated/goal-orch-step-4.json +62 -0
- orchestrator/fixtures/generated/goal-orch-step-5.json +62 -0
- orchestrator/fixtures/generated/goal-orch-step-6.json +63 -0
- orchestrator/fixtures/generated/implement-a-thread-safe-token-bucket-rat-task-1.json +53 -0
- orchestrator/fixtures/generated/orchestrator-checkpoint-rollback-3.json +63 -0
- orchestrator/fixtures/generated/orchestrator-checkpoint-rollback.json +62 -0
- orchestrator/fixtures/generated/orchestrator-live-telemetry-2.json +62 -0
- orchestrator/fixtures/generated/orchestrator-live-telemetry.json +62 -0
- orchestrator/fixtures/generated/orchestrator-spec-synthesis-1.json +62 -0
- orchestrator/fixtures/generated/orchestrator-spec-synthesis.json +62 -0
- orchestrator/fixtures/generated/orchestrator-test-verification-4.json +62 -0
- orchestrator/fixtures/generated/orchestrator-test-verification.json +62 -0
- orchestrator/fixtures/generated/perf-step-1.json +61 -0
- orchestrator/fixtures/generated/perf-step-2.json +62 -0
- orchestrator/fixtures/generated/perf-step-3.json +62 -0
- orchestrator/fixtures/generated/perf-step-4.json +62 -0
- orchestrator/fixtures/generated/perf-step-5.json +63 -0
- orchestrator/fixtures/generated/phase2-proof-two-step-step-1.json +47 -0
- orchestrator/fixtures/generated/phase2-proof-two-step-step-2.json +47 -0
- orchestrator/fixtures/generated/planner-spec-synthesis-impl.json +59 -0
- orchestrator/fixtures/generated/self-evolution-ast-formatter.json +69 -0
- orchestrator/fixtures/generated/self-evolution-checkpoint-rollback.json +70 -0
- orchestrator/fixtures/generated/self-evolution-spec-synthesis.json +70 -0
- orchestrator/fixtures/generated/self-evolution-step-1.json +70 -0
- orchestrator/fixtures/generated/self-evolution-step-2.json +70 -0
- orchestrator/fixtures/generated/self-evolution-step-3.json +70 -0
- orchestrator/fixtures/generated/self-evolution-step-4.json +70 -0
- orchestrator/fixtures/generated/self-evolution-step-5.json +65 -0
- orchestrator/fixtures/generated/self-evolution-telemetry.json +70 -0
- orchestrator/fixtures/generated/self-evolution-tests.json +71 -0
- orchestrator/fixtures/generated/spec-telemetry-research-design.json +64 -0
- orchestrator/fixtures/generated/spec-telemetry-step-1.json +62 -0
- orchestrator/fixtures/generated/spec-telemetry-step-2.json +62 -0
- orchestrator/fixtures/generated/spec-telemetry-step-3.json +62 -0
- orchestrator/fixtures/generated/spec-telemetry-step-4.json +62 -0
- orchestrator/fixtures/generated/spec-telemetry-step-5.json +62 -0
- orchestrator/fixtures/generated/spec-telemetry-verification.json +58 -0
- orchestrator/fixtures/generated/token-bucket-impl.json +69 -0
- orchestrator/fixtures/generated/token-bucket-step-1.json +70 -0
- orchestrator/fixtures/generated/token-bucket-step-2.json +70 -0
- orchestrator/fixtures/generated/token-bucket-step-3.json +60 -0
- orchestrator/fixtures/generated/token-bucket-tests.json +70 -0
- orchestrator/fixtures/generated/token-bucket-verify.json +61 -0
- orchestrator/fixtures/generated/trace-ux-tests-step-1.json +64 -0
- orchestrator/fixtures/generated/trace-ux-tests-step-2.json +64 -0
- orchestrator/fixtures/generated/trace-ux-tests-step-3.json +62 -0
- orchestrator/fixtures/generated/tui-live-telemetry-impl.json +59 -0
- orchestrator/fixtures/phase1_proof_escalation_contract.json +41 -0
- orchestrator/fixtures/phase1_proof_happy_path_contract.json +83 -0
- orchestrator/fixtures/phase1_proof_qc_contract.json +41 -0
- orchestrator/fixtures/phase1_proof_repair_contract.json +41 -0
- orchestrator/fixtures/phase2_proof_two_step_goal.json +15 -0
- orchestrator/fixtures/run_proofs.py +299 -0
- orchestrator/fixtures/test_normalizer.py +16 -0
- orchestrator/generator.py +239 -0
- orchestrator/goal.py +245 -0
- orchestrator/handoff.py +86 -0
- orchestrator/hybrid_worker.py +840 -0
- orchestrator/impossibility.py +162 -0
- orchestrator/limits.py +60 -0
- orchestrator/live_evolution_engine.py +247 -0
- orchestrator/llm.py +291 -0
- orchestrator/local_tool_calling.py +285 -0
- orchestrator/lock.py +404 -0
- orchestrator/mcp_client.py +571 -0
- orchestrator/mcp_server.py +344 -0
- orchestrator/memory_bridge.py +182 -0
- orchestrator/metrics.py +159 -0
- orchestrator/micro_epoch.py +42 -0
- orchestrator/models.py +350 -0
- orchestrator/parsing.py +237 -0
- orchestrator/patch_applier.py +154 -0
- orchestrator/plan_preview.py +138 -0
- orchestrator/plan_quality.py +357 -0
- orchestrator/planner.py +532 -0
- orchestrator/preferences.py +115 -0
- orchestrator/preflight.py +141 -0
- orchestrator/process_guard.py +357 -0
- orchestrator/prometheus_exporter.py +207 -0
- orchestrator/prompts.py +275 -0
- orchestrator/proposal_ledger.py +194 -0
- orchestrator/provenance.py +263 -0
- orchestrator/provider_scheduler.py +394 -0
- orchestrator/qc/__init__.py +153 -0
- orchestrator/qc/aggregator.py +330 -0
- orchestrator/qc/parsing.py +287 -0
- orchestrator/qc/personas.py +242 -0
- orchestrator/qc/runner.py +569 -0
- orchestrator/qc_overrule.py +87 -0
- orchestrator/qc_review.py +282 -0
- orchestrator/quality_lenses.py +314 -0
- orchestrator/quality_plan.py +449 -0
- orchestrator/quality_plane.py +103 -0
- orchestrator/reconcile.py +191 -0
- orchestrator/replanner.py +433 -0
- orchestrator/research.py +176 -0
- orchestrator/review_artifact.py +672 -0
- orchestrator/safety.py +271 -0
- orchestrator/schemas.py +230 -0
- orchestrator/scope.py +466 -0
- orchestrator/sensory_radar.py +79 -0
- orchestrator/skill_installer.py +140 -0
- orchestrator/sse_server.py +160 -0
- orchestrator/state.py +871 -0
- orchestrator/subprocess_helper.py +131 -0
- orchestrator/supervisor/__init__.py +184 -0
- orchestrator/supervisor/_shared.py +164 -0
- orchestrator/supervisor/cleanup.py +185 -0
- orchestrator/supervisor/core.py +1680 -0
- orchestrator/supervisor/recovery.py +367 -0
- orchestrator/supervisor/reporting.py +251 -0
- orchestrator/surgical_extractor.py +119 -0
- orchestrator/telemetry.py +61 -0
- orchestrator/templates.py +268 -0
- orchestrator/token_gate.py +245 -0
- orchestrator/tui.py +649 -0
- orchestrator/verifier.py +1103 -0
- orchestrator/webhooks.py +168 -0
- orchestrator/worker.py +469 -0
- orchestrator/worker_adapters.py +815 -0
- orchestrator/worker_pool.py +121 -0
- orchestrator/worktree.py +364 -0
orchestrator/safety.py
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"""Pre-execution safety checks and failsafe mechanisms."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
from typing import Any, Dict, List, Optional, Set
|
|
6
|
+
|
|
7
|
+
from .failure import MAX_SAME_CLASS_STRIKES, count_consecutive_same_class
|
|
8
|
+
from .goal import Plan
|
|
9
|
+
from .limits import ResourceLimits
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class SafetyIssue:
|
|
14
|
+
issue_type: str
|
|
15
|
+
severity: str
|
|
16
|
+
message: str
|
|
17
|
+
task_id: str = ""
|
|
18
|
+
details: Dict[str, Any] = field(default_factory=dict)
|
|
19
|
+
|
|
20
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
21
|
+
return {
|
|
22
|
+
"issue_type": self.issue_type,
|
|
23
|
+
"severity": self.severity,
|
|
24
|
+
"message": self.message,
|
|
25
|
+
"task_id": self.task_id,
|
|
26
|
+
"details": self.details,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass
|
|
31
|
+
class SafetyReport:
|
|
32
|
+
passed: bool
|
|
33
|
+
issues: List[SafetyIssue] = field(default_factory=list)
|
|
34
|
+
total_checks: int = 0
|
|
35
|
+
failed_checks: int = 0
|
|
36
|
+
|
|
37
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
38
|
+
return {
|
|
39
|
+
"passed": self.passed,
|
|
40
|
+
"issues": [i.to_dict() for i in self.issues],
|
|
41
|
+
"total_checks": self.total_checks,
|
|
42
|
+
"failed_checks": self.failed_checks,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def check_contract_validity(plan: Plan) -> List[SafetyIssue]:
|
|
47
|
+
"""Check that all contracts have required fields."""
|
|
48
|
+
issues = []
|
|
49
|
+
required_fields = {"task_id", "status", "contract"}
|
|
50
|
+
contract_required = {"title", "objective", "worker", "outputs", "acceptance_checks"}
|
|
51
|
+
|
|
52
|
+
def _as_dict(c):
|
|
53
|
+
return c if isinstance(c, dict) else c._raw if hasattr(c, "_raw") else {}
|
|
54
|
+
|
|
55
|
+
for c in plan.contracts:
|
|
56
|
+
c = _as_dict(c)
|
|
57
|
+
tid = c.get("task_id", "?")
|
|
58
|
+
missing = required_fields - set(c.keys())
|
|
59
|
+
if missing:
|
|
60
|
+
issues.append(
|
|
61
|
+
SafetyIssue(
|
|
62
|
+
issue_type="missing_contract_field",
|
|
63
|
+
severity="error",
|
|
64
|
+
message=f"contract {tid} missing fields: {missing}",
|
|
65
|
+
task_id=tid,
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
contract = c.get("contract", {})
|
|
70
|
+
if contract:
|
|
71
|
+
missing_contract = contract_required - set(contract.keys())
|
|
72
|
+
if missing_contract:
|
|
73
|
+
issues.append(
|
|
74
|
+
SafetyIssue(
|
|
75
|
+
issue_type="missing_contract_detail",
|
|
76
|
+
severity="error",
|
|
77
|
+
message=f"contract {tid} missing contract detail fields: {missing_contract}",
|
|
78
|
+
task_id=tid,
|
|
79
|
+
)
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
return issues
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def check_dependency_cycles(plan: Plan) -> List[SafetyIssue]:
|
|
86
|
+
"""Detect cycles in task dependency graph."""
|
|
87
|
+
issues = []
|
|
88
|
+
adj: Dict[str, List[str]] = {}
|
|
89
|
+
|
|
90
|
+
def _as_dict(c):
|
|
91
|
+
return c if isinstance(c, dict) else c._raw if hasattr(c, "_raw") else {}
|
|
92
|
+
|
|
93
|
+
for c in plan.contracts:
|
|
94
|
+
c = _as_dict(c)
|
|
95
|
+
tid = c.get("task_id", "?")
|
|
96
|
+
deps = c.get("depends_on", [])
|
|
97
|
+
adj[tid] = deps
|
|
98
|
+
|
|
99
|
+
visited: Set[str] = set()
|
|
100
|
+
rec_stack: Set[str] = set()
|
|
101
|
+
|
|
102
|
+
def _dfs(node: str) -> bool:
|
|
103
|
+
visited.add(node)
|
|
104
|
+
rec_stack.add(node)
|
|
105
|
+
for dep in adj.get(node, []):
|
|
106
|
+
if dep not in visited:
|
|
107
|
+
if _dfs(dep):
|
|
108
|
+
return True
|
|
109
|
+
elif dep in rec_stack:
|
|
110
|
+
issues.append(
|
|
111
|
+
SafetyIssue(
|
|
112
|
+
issue_type="dependency_cycle",
|
|
113
|
+
severity="error",
|
|
114
|
+
message=f"dependency cycle detected involving {node} -> {dep}",
|
|
115
|
+
task_id=node,
|
|
116
|
+
details={"cycle_node": dep},
|
|
117
|
+
)
|
|
118
|
+
)
|
|
119
|
+
return True
|
|
120
|
+
rec_stack.discard(node)
|
|
121
|
+
return False
|
|
122
|
+
|
|
123
|
+
for tid in adj:
|
|
124
|
+
if tid not in visited:
|
|
125
|
+
_dfs(tid)
|
|
126
|
+
|
|
127
|
+
return issues
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def check_resource_adequacy(plan: Plan, limits: ResourceLimits) -> List[SafetyIssue]:
|
|
131
|
+
"""Check that plan-level resource demands don't exceed limits."""
|
|
132
|
+
issues = []
|
|
133
|
+
|
|
134
|
+
def _as_dict(c):
|
|
135
|
+
return c if isinstance(c, dict) else c._raw if hasattr(c, "_raw") else {}
|
|
136
|
+
|
|
137
|
+
total_attempts = sum(
|
|
138
|
+
cc.get("contract", {}).get("worker", {}).get("max_attempts", 1) if isinstance(cc.get("contract"), dict) else 1
|
|
139
|
+
for cc in (_as_dict(c) for c in plan.contracts)
|
|
140
|
+
)
|
|
141
|
+
len(plan.contracts)
|
|
142
|
+
|
|
143
|
+
if total_attempts > limits.max_attempts_global:
|
|
144
|
+
issues.append(
|
|
145
|
+
SafetyIssue(
|
|
146
|
+
issue_type="resource_exceeded",
|
|
147
|
+
severity="warning",
|
|
148
|
+
message=f"total max attempts ({total_attempts}) exceed global limit ({limits.max_attempts_global})",
|
|
149
|
+
details={"total_attempts": total_attempts, "limit": limits.max_attempts_global},
|
|
150
|
+
)
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
return issues
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def check_workspace_health(workspace_root: str) -> List[SafetyIssue]:
|
|
157
|
+
"""Verify workspace directories exist and are writable."""
|
|
158
|
+
issues = []
|
|
159
|
+
if not os.path.isdir(workspace_root):
|
|
160
|
+
issues.append(
|
|
161
|
+
SafetyIssue(
|
|
162
|
+
issue_type="workspace_missing",
|
|
163
|
+
severity="error",
|
|
164
|
+
message=f"workspace root does not exist: {workspace_root}",
|
|
165
|
+
)
|
|
166
|
+
)
|
|
167
|
+
return issues
|
|
168
|
+
|
|
169
|
+
test_path = os.path.join(workspace_root, ".safety_test")
|
|
170
|
+
try:
|
|
171
|
+
with open(test_path, "w", encoding="utf-8") as f:
|
|
172
|
+
f.write("ok")
|
|
173
|
+
os.remove(test_path)
|
|
174
|
+
except OSError as e:
|
|
175
|
+
issues.append(
|
|
176
|
+
SafetyIssue(
|
|
177
|
+
issue_type="workspace_not_writable",
|
|
178
|
+
severity="error",
|
|
179
|
+
message=f"workspace root not writable: {e}",
|
|
180
|
+
details={"error": str(e)},
|
|
181
|
+
)
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
return issues
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def check_failsafe(state, contract, goal_id: str) -> Optional[SafetyIssue]:
|
|
188
|
+
"""Check if a task should be failsafe-triggered based on failure patterns."""
|
|
189
|
+
from .failure import classify_failure
|
|
190
|
+
|
|
191
|
+
fclass = classify_failure(state, contract)
|
|
192
|
+
strikes = count_consecutive_same_class(state, fclass)
|
|
193
|
+
|
|
194
|
+
if strikes >= MAX_SAME_CLASS_STRIKES:
|
|
195
|
+
if state.attempt >= contract.worker.get("max_attempts", 3):
|
|
196
|
+
return SafetyIssue(
|
|
197
|
+
issue_type="failsafe_triggered",
|
|
198
|
+
severity="error",
|
|
199
|
+
message=f"task {state.task_id}: {strikes} consecutive '{fclass}' failures, max attempts reached",
|
|
200
|
+
task_id=state.task_id,
|
|
201
|
+
details={
|
|
202
|
+
"failure_class": fclass,
|
|
203
|
+
"consecutive_strikes": strikes,
|
|
204
|
+
"max_attempts": contract.worker.get("max_attempts", 3),
|
|
205
|
+
"goal_id": goal_id,
|
|
206
|
+
},
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
return None
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def run_safety_checks(
|
|
213
|
+
plan: Plan,
|
|
214
|
+
workspace_root: str,
|
|
215
|
+
limits: Optional[ResourceLimits] = None,
|
|
216
|
+
) -> SafetyReport:
|
|
217
|
+
"""Run all pre-execution safety checks. Returns a SafetyReport."""
|
|
218
|
+
issues: List[SafetyIssue] = []
|
|
219
|
+
total = 0
|
|
220
|
+
failed = 0
|
|
221
|
+
|
|
222
|
+
checkers = [
|
|
223
|
+
("contract_validity", lambda: check_contract_validity(plan)),
|
|
224
|
+
("dependency_cycles", lambda: check_dependency_cycles(plan)),
|
|
225
|
+
("workspace_health", lambda: check_workspace_health(workspace_root)),
|
|
226
|
+
]
|
|
227
|
+
|
|
228
|
+
if limits:
|
|
229
|
+
checkers.append(("resource_adequacy", lambda: check_resource_adequacy(plan, limits)))
|
|
230
|
+
|
|
231
|
+
for name, checker in checkers:
|
|
232
|
+
total += 1
|
|
233
|
+
try:
|
|
234
|
+
result = checker()
|
|
235
|
+
issues.extend(result)
|
|
236
|
+
if result:
|
|
237
|
+
failed += 1
|
|
238
|
+
except Exception as e:
|
|
239
|
+
issues.append(
|
|
240
|
+
SafetyIssue(
|
|
241
|
+
issue_type="check_crashed",
|
|
242
|
+
severity="error",
|
|
243
|
+
message=f"safety check '{name}' crashed: {type(e).__name__}: {e}",
|
|
244
|
+
)
|
|
245
|
+
)
|
|
246
|
+
failed += 1
|
|
247
|
+
|
|
248
|
+
critical = any(i.severity == "error" for i in issues)
|
|
249
|
+
return SafetyReport(
|
|
250
|
+
passed=not critical,
|
|
251
|
+
issues=issues,
|
|
252
|
+
total_checks=total,
|
|
253
|
+
failed_checks=failed,
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def format_safety_report(report: SafetyReport) -> str:
|
|
258
|
+
"""Return a human-readable safety report string."""
|
|
259
|
+
if not report.issues:
|
|
260
|
+
return f"Safety: PASSED ({report.total_checks} checks, 0 issues)"
|
|
261
|
+
|
|
262
|
+
lines = [
|
|
263
|
+
f"Safety: {'FAILED' if not report.passed else 'PASSED (with warnings)'}",
|
|
264
|
+
f"Checks: {report.total_checks} total, {report.failed_checks} with issues",
|
|
265
|
+
f"Issues: {len(report.issues)}",
|
|
266
|
+
]
|
|
267
|
+
for iss in report.issues:
|
|
268
|
+
icon = "ERROR" if iss.severity == "error" else "WARN"
|
|
269
|
+
tid = f" [{iss.task_id}]" if iss.task_id else ""
|
|
270
|
+
lines.append(f" [{icon}]{tid} {iss.issue_type}: {iss.message}")
|
|
271
|
+
return "\n".join(lines)
|
orchestrator/schemas.py
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"""JSON Schema documents for letitloop public JSON interfaces."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import copy
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from .contract import VALID_CHECK_KINDS, VALID_QC_LENSES, VALID_RISK_TIERS, VALID_STATUSES
|
|
9
|
+
from .goal import VALID_GOAL_STATUSES
|
|
10
|
+
|
|
11
|
+
SCHEMA_DIALECT = "https://json-schema.org/draft/2020-12/schema"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def contract_schema() -> dict[str, Any]:
|
|
15
|
+
string_array = {"type": "array", "items": {"type": "string"}}
|
|
16
|
+
path_entry = {
|
|
17
|
+
"type": "object",
|
|
18
|
+
"properties": {"path": {"type": "string", "minLength": 1}},
|
|
19
|
+
"required": ["path"],
|
|
20
|
+
"additionalProperties": True,
|
|
21
|
+
}
|
|
22
|
+
check = {
|
|
23
|
+
"type": "object",
|
|
24
|
+
"properties": {
|
|
25
|
+
"id": {"type": "string", "minLength": 1},
|
|
26
|
+
"kind": {"type": "string", "enum": sorted(VALID_CHECK_KINDS)},
|
|
27
|
+
"path": {"type": "string"},
|
|
28
|
+
"command": {"type": "string"},
|
|
29
|
+
"expected": {},
|
|
30
|
+
"schema": {},
|
|
31
|
+
},
|
|
32
|
+
"required": ["id", "kind"],
|
|
33
|
+
"allOf": [
|
|
34
|
+
{
|
|
35
|
+
"if": {
|
|
36
|
+
"properties": {"kind": {"enum": ["command", "content_exact", "content_regex", "min_size"]}},
|
|
37
|
+
"required": ["kind"],
|
|
38
|
+
},
|
|
39
|
+
"then": {"required": ["expected"]},
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
"additionalProperties": True,
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
"$schema": SCHEMA_DIALECT,
|
|
46
|
+
"$id": "https://github.com/sdageltc/letitloop/raw/main/schemas/contract.schema.json",
|
|
47
|
+
"title": "letitloop task contract",
|
|
48
|
+
"type": "object",
|
|
49
|
+
"properties": {
|
|
50
|
+
"task_id": {"type": "string", "minLength": 1},
|
|
51
|
+
"title": {"type": "string"},
|
|
52
|
+
"status": {"type": "string", "enum": sorted(VALID_STATUSES)},
|
|
53
|
+
"risk_tier": {"type": "string", "enum": sorted(VALID_RISK_TIERS)},
|
|
54
|
+
"workspace_scope": {
|
|
55
|
+
"type": "object",
|
|
56
|
+
"properties": {
|
|
57
|
+
"allow": string_array,
|
|
58
|
+
"deny": string_array,
|
|
59
|
+
"scratch_dir": {"type": "string"},
|
|
60
|
+
},
|
|
61
|
+
"required": ["allow", "deny"],
|
|
62
|
+
"additionalProperties": False,
|
|
63
|
+
},
|
|
64
|
+
"objective": {"type": "string"},
|
|
65
|
+
"worker": {
|
|
66
|
+
"type": "object",
|
|
67
|
+
"properties": {
|
|
68
|
+
"model": {"type": "string"},
|
|
69
|
+
"max_attempts": {"type": "integer", "minimum": 1},
|
|
70
|
+
},
|
|
71
|
+
"required": ["model", "max_attempts"],
|
|
72
|
+
"additionalProperties": True,
|
|
73
|
+
},
|
|
74
|
+
"inputs": {"type": "array", "items": path_entry},
|
|
75
|
+
"outputs": {"type": "array", "items": path_entry},
|
|
76
|
+
"acceptance_checks": {"type": "array", "items": check},
|
|
77
|
+
"qc": {
|
|
78
|
+
"type": "object",
|
|
79
|
+
"properties": {
|
|
80
|
+
"required": {"type": "boolean"},
|
|
81
|
+
"lens": {"type": "string", "enum": sorted(VALID_QC_LENSES)},
|
|
82
|
+
},
|
|
83
|
+
"required": ["required", "lens"],
|
|
84
|
+
"additionalProperties": True,
|
|
85
|
+
},
|
|
86
|
+
"quality_spec": {
|
|
87
|
+
"type": "object",
|
|
88
|
+
"properties": {
|
|
89
|
+
"required_sections": string_array,
|
|
90
|
+
"quality_dimensions": {"type": "object"},
|
|
91
|
+
"hard_failures": string_array,
|
|
92
|
+
"minimum_counts": {"type": "object"},
|
|
93
|
+
"minimum_score": {"type": "number", "minimum": 0, "maximum": 1},
|
|
94
|
+
},
|
|
95
|
+
"additionalProperties": True,
|
|
96
|
+
},
|
|
97
|
+
"quality_plan": {"type": "object"},
|
|
98
|
+
"components": {
|
|
99
|
+
"type": "array",
|
|
100
|
+
"items": {
|
|
101
|
+
"type": "object",
|
|
102
|
+
"properties": {
|
|
103
|
+
"id": {"type": "string", "minLength": 1},
|
|
104
|
+
"files": {
|
|
105
|
+
"type": "array",
|
|
106
|
+
"items": {"type": "string", "minLength": 1},
|
|
107
|
+
"minItems": 1,
|
|
108
|
+
},
|
|
109
|
+
"description": {"type": "string"},
|
|
110
|
+
},
|
|
111
|
+
"required": ["id", "files"],
|
|
112
|
+
"additionalProperties": True,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
"required_mcp_servers": {
|
|
116
|
+
"type": "array",
|
|
117
|
+
"items": {"type": "string", "minLength": 1},
|
|
118
|
+
"uniqueItems": True,
|
|
119
|
+
},
|
|
120
|
+
"next_action": {"type": "string"},
|
|
121
|
+
},
|
|
122
|
+
"required": [
|
|
123
|
+
"task_id",
|
|
124
|
+
"title",
|
|
125
|
+
"status",
|
|
126
|
+
"risk_tier",
|
|
127
|
+
"workspace_scope",
|
|
128
|
+
"objective",
|
|
129
|
+
"worker",
|
|
130
|
+
"outputs",
|
|
131
|
+
"acceptance_checks",
|
|
132
|
+
"qc",
|
|
133
|
+
],
|
|
134
|
+
"additionalProperties": False,
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def goal_schema() -> dict[str, Any]:
|
|
139
|
+
statuses = sorted(VALID_GOAL_STATUSES | {status.lower() for status in VALID_GOAL_STATUSES})
|
|
140
|
+
return {
|
|
141
|
+
"$schema": SCHEMA_DIALECT,
|
|
142
|
+
"$id": "https://github.com/sdageltc/letitloop/raw/main/schemas/goal.schema.json",
|
|
143
|
+
"title": "letitloop goal",
|
|
144
|
+
"type": "object",
|
|
145
|
+
"properties": {
|
|
146
|
+
"goal_id": {"type": "string", "minLength": 1},
|
|
147
|
+
"title": {"type": "string"},
|
|
148
|
+
"description": {"type": "string"},
|
|
149
|
+
"constraints": {"type": "object"},
|
|
150
|
+
"dependencies": {
|
|
151
|
+
"type": "array",
|
|
152
|
+
"items": {"type": "string", "minLength": 1},
|
|
153
|
+
"uniqueItems": True,
|
|
154
|
+
},
|
|
155
|
+
"status": {"type": "string", "enum": statuses},
|
|
156
|
+
},
|
|
157
|
+
"required": ["goal_id", "title", "description"],
|
|
158
|
+
"additionalProperties": False,
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def mcp_schema() -> dict[str, Any]:
|
|
163
|
+
from .mcp_server import LetItLoopMCPServer
|
|
164
|
+
|
|
165
|
+
calls = []
|
|
166
|
+
for tool in LetItLoopMCPServer.get_tool_definitions():
|
|
167
|
+
calls.append(
|
|
168
|
+
{
|
|
169
|
+
"properties": {
|
|
170
|
+
"name": {"const": tool["name"]},
|
|
171
|
+
"arguments": tool["inputSchema"],
|
|
172
|
+
},
|
|
173
|
+
"required": ["name", "arguments"],
|
|
174
|
+
"additionalProperties": False,
|
|
175
|
+
}
|
|
176
|
+
)
|
|
177
|
+
request_id = {"type": ["string", "integer", "null"]}
|
|
178
|
+
base = {"jsonrpc": {"const": "2.0"}, "id": request_id}
|
|
179
|
+
return {
|
|
180
|
+
"$schema": SCHEMA_DIALECT,
|
|
181
|
+
"$id": "https://github.com/sdageltc/letitloop/raw/main/schemas/mcp.schema.json",
|
|
182
|
+
"title": "letitloop MCP stdio request",
|
|
183
|
+
"oneOf": [
|
|
184
|
+
{
|
|
185
|
+
"type": "object",
|
|
186
|
+
"properties": {
|
|
187
|
+
**base,
|
|
188
|
+
"method": {"const": "initialize"},
|
|
189
|
+
"params": {"type": "object"},
|
|
190
|
+
},
|
|
191
|
+
"required": ["jsonrpc", "id", "method"],
|
|
192
|
+
"additionalProperties": False,
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"type": "object",
|
|
196
|
+
"properties": {
|
|
197
|
+
**base,
|
|
198
|
+
"method": {"const": "tools/list"},
|
|
199
|
+
"params": {
|
|
200
|
+
"type": "object",
|
|
201
|
+
"properties": {"cursor": {"type": "string"}},
|
|
202
|
+
"additionalProperties": False,
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
"required": ["jsonrpc", "id", "method"],
|
|
206
|
+
"additionalProperties": False,
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"type": "object",
|
|
210
|
+
"properties": {
|
|
211
|
+
**base,
|
|
212
|
+
"method": {"const": "tools/call"},
|
|
213
|
+
"params": {"oneOf": calls},
|
|
214
|
+
},
|
|
215
|
+
"required": ["jsonrpc", "id", "method", "params"],
|
|
216
|
+
"additionalProperties": False,
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
SCHEMA_BUILDERS = {"contract": contract_schema, "goal": goal_schema, "mcp": mcp_schema}
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def get_schema(kind: str) -> dict[str, Any]:
|
|
226
|
+
try:
|
|
227
|
+
schema = SCHEMA_BUILDERS[kind]()
|
|
228
|
+
except KeyError as exc:
|
|
229
|
+
raise ValueError(f"unknown schema kind: {kind}") from exc
|
|
230
|
+
return copy.deepcopy(schema)
|