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
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
"""Quality Plan schema and defaults for the orchestrator quality plane.
|
|
2
|
+
|
|
3
|
+
A QualityPlan defines *how* a task's output should be reviewed — including
|
|
4
|
+
lens, reviewers, component slicing, synthesis, arbitration, and budget.
|
|
5
|
+
|
|
6
|
+
This module is pure schema + logic. Zero model calls. Zero side effects.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import copy
|
|
12
|
+
from typing import Any, Dict, List, Optional
|
|
13
|
+
|
|
14
|
+
# ── Mode constants ──────────────────────────────────────────────────────────
|
|
15
|
+
|
|
16
|
+
MODE_SINGLE = "single"
|
|
17
|
+
MODE_PANEL = "panel"
|
|
18
|
+
MODE_COMPONENT_PANEL = "component_panel"
|
|
19
|
+
MODE_ARBITRATION_ONLY = "arbitration_only" # reserved; unsupported (see validate_quality_plan)
|
|
20
|
+
VALID_MODES = {MODE_SINGLE, MODE_PANEL, MODE_COMPONENT_PANEL}
|
|
21
|
+
|
|
22
|
+
# ── Lens constants ─────────────────────────────────────────────────────────
|
|
23
|
+
|
|
24
|
+
LENS_CODE_CORRECTNESS = "code_correctness"
|
|
25
|
+
LENS_PLAN_CORRECTNESS = "plan_correctness"
|
|
26
|
+
LENS_CONFIG_SAFETY = "config_safety"
|
|
27
|
+
LENS_CONTENT_QUALITY = "content_quality"
|
|
28
|
+
LENS_DOCUMENT_QUALITY = "document_quality"
|
|
29
|
+
LENS_ARCHITECTURE_AUDIT = "architecture_audit"
|
|
30
|
+
LENS_RESEARCH_QUALITY = "research_quality"
|
|
31
|
+
LENS_STRATEGIC_REVIEW = "strategic_review"
|
|
32
|
+
LENS_MIGRATION_SAFETY = "migration_safety"
|
|
33
|
+
VALID_LENSES = {
|
|
34
|
+
LENS_CODE_CORRECTNESS,
|
|
35
|
+
LENS_PLAN_CORRECTNESS,
|
|
36
|
+
LENS_CONFIG_SAFETY,
|
|
37
|
+
LENS_CONTENT_QUALITY,
|
|
38
|
+
LENS_DOCUMENT_QUALITY,
|
|
39
|
+
LENS_ARCHITECTURE_AUDIT,
|
|
40
|
+
LENS_RESEARCH_QUALITY,
|
|
41
|
+
LENS_STRATEGIC_REVIEW,
|
|
42
|
+
LENS_MIGRATION_SAFETY,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
# ── Default personas by lens ───────────────────────────────────────────────
|
|
46
|
+
|
|
47
|
+
LENS_DEFAULT_PERSONAS: Dict[str, List[str]] = {
|
|
48
|
+
LENS_CODE_CORRECTNESS: ["maintainer", "test_strategist"],
|
|
49
|
+
LENS_CONFIG_SAFETY: ["security_safety", "operator_sre"],
|
|
50
|
+
LENS_ARCHITECTURE_AUDIT: ["systems_architect", "minimalist", "product_owner"],
|
|
51
|
+
LENS_PLAN_CORRECTNESS: ["systems_architect", "operator_sre"],
|
|
52
|
+
LENS_RESEARCH_QUALITY: ["research_skeptic", "product_owner"],
|
|
53
|
+
LENS_MIGRATION_SAFETY: ["migration_reviewer", "operator_sre", "maintainer"],
|
|
54
|
+
LENS_STRATEGIC_REVIEW: ["product_owner", "minimalist", "systems_architect"],
|
|
55
|
+
LENS_CONTENT_QUALITY: ["maintainer"],
|
|
56
|
+
LENS_DOCUMENT_QUALITY: ["maintainer"],
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
PERSONA_DESCRIPTIONS: Dict[str, str] = {
|
|
60
|
+
"systems_architect": "contradictions, overengineering, failure modes",
|
|
61
|
+
"maintainer": "complexity, testability, local implementation risk",
|
|
62
|
+
"security_safety": "destructive actions, secrets, permissions, unsafe commands",
|
|
63
|
+
"product_owner": "whether the work solves the actual problem",
|
|
64
|
+
"operator_sre": "runtime, recovery, observability, rollback",
|
|
65
|
+
"minimalist": "simpler design alternatives",
|
|
66
|
+
"adversarial_user": "how can this fail in real usage",
|
|
67
|
+
"research_skeptic": "citation quality, source fidelity, unsupported claims",
|
|
68
|
+
"migration_reviewer": "backward compatibility, sequencing, rollback",
|
|
69
|
+
"test_strategist": "coverage holes and falsifiability",
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
# ── Default mode by lens and risk tier ─────────────────────────────────────
|
|
73
|
+
|
|
74
|
+
RISK_TIER_AUTO = "auto"
|
|
75
|
+
RISK_TIER_QC_REQUIRED = "qc_required"
|
|
76
|
+
RISK_TIER_HUMAN_REQUIRED = "human_required"
|
|
77
|
+
|
|
78
|
+
DEFAULT_MODE_BY_RISK_AND_LENS: Dict[str, Dict[str, str]] = {
|
|
79
|
+
RISK_TIER_AUTO: {
|
|
80
|
+
"__default__": MODE_SINGLE,
|
|
81
|
+
LENS_ARCHITECTURE_AUDIT: MODE_PANEL,
|
|
82
|
+
LENS_STRATEGIC_REVIEW: MODE_PANEL,
|
|
83
|
+
LENS_MIGRATION_SAFETY: MODE_PANEL,
|
|
84
|
+
},
|
|
85
|
+
RISK_TIER_QC_REQUIRED: {
|
|
86
|
+
"__default__": MODE_SINGLE,
|
|
87
|
+
},
|
|
88
|
+
RISK_TIER_HUMAN_REQUIRED: {
|
|
89
|
+
"__default__": MODE_PANEL,
|
|
90
|
+
},
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
REVIEWER_MODEL_POLICY: Dict[str, str] = {
|
|
94
|
+
"systems_architect": "default",
|
|
95
|
+
"maintainer": "default",
|
|
96
|
+
"security_safety": "default",
|
|
97
|
+
"product_owner": "default",
|
|
98
|
+
"operator_sre": "default",
|
|
99
|
+
"minimalist": "cheap_cross_family",
|
|
100
|
+
"adversarial_user": "default",
|
|
101
|
+
"research_skeptic": "default",
|
|
102
|
+
"migration_reviewer": "default",
|
|
103
|
+
"test_strategist": "cheap_cross_family",
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class ReviewerRole:
|
|
108
|
+
def __init__(self, role: str, model_policy: str = "", focus: Optional[List[str]] = None):
|
|
109
|
+
self.role = role
|
|
110
|
+
self.model_policy = model_policy or REVIEWER_MODEL_POLICY.get(role, "default")
|
|
111
|
+
self.focus = focus or []
|
|
112
|
+
|
|
113
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
114
|
+
return {
|
|
115
|
+
"role": self.role,
|
|
116
|
+
"model_policy": self.model_policy,
|
|
117
|
+
"focus": list(self.focus),
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@classmethod
|
|
121
|
+
def from_dict(cls, d: Dict[str, Any]) -> ReviewerRole:
|
|
122
|
+
if not isinstance(d, dict):
|
|
123
|
+
d = {}
|
|
124
|
+
role = d.get("role", "reviewer")
|
|
125
|
+
if not isinstance(role, str) or not role:
|
|
126
|
+
role = "reviewer"
|
|
127
|
+
model_policy = d.get("model_policy", "")
|
|
128
|
+
if not isinstance(model_policy, str):
|
|
129
|
+
model_policy = ""
|
|
130
|
+
focus = d.get("focus", [])
|
|
131
|
+
if not isinstance(focus, list):
|
|
132
|
+
focus = []
|
|
133
|
+
focus = [f for f in focus if isinstance(f, str)]
|
|
134
|
+
return cls(
|
|
135
|
+
role=role,
|
|
136
|
+
model_policy=model_policy,
|
|
137
|
+
focus=focus,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class SynthesisPolicy:
|
|
142
|
+
def __init__(
|
|
143
|
+
self,
|
|
144
|
+
required: bool = True,
|
|
145
|
+
preserve_dissent: bool = True,
|
|
146
|
+
reject_on_p0: bool = True,
|
|
147
|
+
):
|
|
148
|
+
self.required = required
|
|
149
|
+
self.preserve_dissent = preserve_dissent
|
|
150
|
+
self.reject_on_p0 = reject_on_p0
|
|
151
|
+
|
|
152
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
153
|
+
return {
|
|
154
|
+
"required": self.required,
|
|
155
|
+
"preserve_dissent": self.preserve_dissent,
|
|
156
|
+
"reject_on_p0": self.reject_on_p0,
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@classmethod
|
|
160
|
+
def from_dict(cls, d: dict) -> SynthesisPolicy:
|
|
161
|
+
if not isinstance(d, dict):
|
|
162
|
+
d = {}
|
|
163
|
+
return cls(
|
|
164
|
+
required=d.get("required", True),
|
|
165
|
+
preserve_dissent=d.get("preserve_dissent", True),
|
|
166
|
+
reject_on_p0=d.get("reject_on_p0", True),
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
class ArbitrationPolicy:
|
|
171
|
+
def __init__(
|
|
172
|
+
self,
|
|
173
|
+
enabled: bool = False,
|
|
174
|
+
trigger: Optional[List[str]] = None,
|
|
175
|
+
model_policy: str = "default",
|
|
176
|
+
):
|
|
177
|
+
self.enabled = enabled
|
|
178
|
+
self.trigger = trigger or ["p0_disagreement", "low_confidence"]
|
|
179
|
+
self.model_policy = model_policy
|
|
180
|
+
|
|
181
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
182
|
+
return {
|
|
183
|
+
"enabled": self.enabled,
|
|
184
|
+
"trigger": list(self.trigger),
|
|
185
|
+
"model_policy": self.model_policy,
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
@classmethod
|
|
189
|
+
def from_dict(cls, d: dict) -> ArbitrationPolicy:
|
|
190
|
+
if not isinstance(d, dict):
|
|
191
|
+
d = {}
|
|
192
|
+
return cls(
|
|
193
|
+
enabled=d.get("enabled", False),
|
|
194
|
+
trigger=d.get("trigger"),
|
|
195
|
+
model_policy=d.get("model_policy", "default"),
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
class QualityBudget:
|
|
200
|
+
def __init__(
|
|
201
|
+
self,
|
|
202
|
+
max_llm_calls: int = 8,
|
|
203
|
+
max_wall_clock_sec: int = 900,
|
|
204
|
+
max_reviewers_per_component: int = 3,
|
|
205
|
+
max_components: int = 5,
|
|
206
|
+
degrade_strategy: str = "single_reviewer_then_synthesis",
|
|
207
|
+
):
|
|
208
|
+
self.max_llm_calls = max_llm_calls
|
|
209
|
+
self.max_wall_clock_sec = max_wall_clock_sec
|
|
210
|
+
self.max_reviewers_per_component = max_reviewers_per_component
|
|
211
|
+
self.max_components = max_components
|
|
212
|
+
self.degrade_strategy = degrade_strategy
|
|
213
|
+
|
|
214
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
215
|
+
return {
|
|
216
|
+
"max_llm_calls": self.max_llm_calls,
|
|
217
|
+
"max_wall_clock_sec": self.max_wall_clock_sec,
|
|
218
|
+
"max_reviewers_per_component": self.max_reviewers_per_component,
|
|
219
|
+
"max_components": self.max_components,
|
|
220
|
+
"degrade_strategy": self.degrade_strategy,
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
@classmethod
|
|
224
|
+
def from_dict(cls, d: dict) -> QualityBudget:
|
|
225
|
+
if not isinstance(d, dict):
|
|
226
|
+
d = {}
|
|
227
|
+
return cls(
|
|
228
|
+
max_llm_calls=d.get("max_llm_calls", 8),
|
|
229
|
+
max_wall_clock_sec=d.get("max_wall_clock_sec", 900),
|
|
230
|
+
max_reviewers_per_component=d.get("max_reviewers_per_component", 3),
|
|
231
|
+
max_components=d.get("max_components", 5),
|
|
232
|
+
degrade_strategy=d.get("degrade_strategy", "single_reviewer_then_synthesis"),
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
class QualityPlan:
|
|
237
|
+
"""Defines how output quality is evaluated for a task contract.
|
|
238
|
+
|
|
239
|
+
A QualityPlan is optional. If absent, the orchestrator uses the legacy
|
|
240
|
+
single-reviewer QC path with no behavioral change.
|
|
241
|
+
"""
|
|
242
|
+
|
|
243
|
+
def __init__(
|
|
244
|
+
self,
|
|
245
|
+
mode: str = MODE_SINGLE,
|
|
246
|
+
lens: str = LENS_CODE_CORRECTNESS,
|
|
247
|
+
components: str = "auto",
|
|
248
|
+
reviewers: Optional[List[ReviewerRole]] = None,
|
|
249
|
+
synthesis: Optional[SynthesisPolicy] = None,
|
|
250
|
+
arbitration: Optional[ArbitrationPolicy] = None,
|
|
251
|
+
budget: Optional[QualityBudget] = None,
|
|
252
|
+
):
|
|
253
|
+
self.mode = mode
|
|
254
|
+
self.lens = lens
|
|
255
|
+
self.components = components
|
|
256
|
+
self.reviewers = reviewers or []
|
|
257
|
+
self.synthesis = synthesis or SynthesisPolicy()
|
|
258
|
+
self.arbitration = arbitration or ArbitrationPolicy()
|
|
259
|
+
self.budget = budget or QualityBudget()
|
|
260
|
+
self.degraded = False
|
|
261
|
+
self.degrade_reason = ""
|
|
262
|
+
self.original_mode = mode
|
|
263
|
+
|
|
264
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
265
|
+
return {
|
|
266
|
+
"mode": self.mode,
|
|
267
|
+
"lens": self.lens,
|
|
268
|
+
"components": self.components,
|
|
269
|
+
"reviewers": [r.to_dict() for r in self.reviewers],
|
|
270
|
+
"synthesis": self.synthesis.to_dict(),
|
|
271
|
+
"arbitration": self.arbitration.to_dict(),
|
|
272
|
+
"budget": self.budget.to_dict(),
|
|
273
|
+
"degraded": self.degraded,
|
|
274
|
+
"degrade_reason": self.degrade_reason,
|
|
275
|
+
"original_mode": self.original_mode,
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
@classmethod
|
|
279
|
+
def from_dict(cls, d: dict) -> QualityPlan:
|
|
280
|
+
if not isinstance(d, dict):
|
|
281
|
+
d = {}
|
|
282
|
+
reviewers_raw = d.get("reviewers", [])
|
|
283
|
+
if not isinstance(reviewers_raw, list):
|
|
284
|
+
reviewers_raw = []
|
|
285
|
+
reviewers = [ReviewerRole.from_dict(r) for r in reviewers_raw if isinstance(r, dict)]
|
|
286
|
+
qp = cls(
|
|
287
|
+
mode=d.get("mode", MODE_SINGLE),
|
|
288
|
+
lens=d.get("lens", LENS_CODE_CORRECTNESS),
|
|
289
|
+
components=d.get("components", "auto"),
|
|
290
|
+
reviewers=reviewers,
|
|
291
|
+
synthesis=SynthesisPolicy.from_dict(d.get("synthesis", {})),
|
|
292
|
+
arbitration=ArbitrationPolicy.from_dict(d.get("arbitration", {})),
|
|
293
|
+
budget=QualityBudget.from_dict(d.get("budget", {})),
|
|
294
|
+
)
|
|
295
|
+
qp.degraded = bool(d.get("degraded", False))
|
|
296
|
+
qp.degrade_reason = d.get("degrade_reason", "") if isinstance(d.get("degrade_reason", ""), str) else ""
|
|
297
|
+
qp.original_mode = d.get("original_mode", qp.mode)
|
|
298
|
+
return qp
|
|
299
|
+
|
|
300
|
+
def estimate_calls(self) -> int:
|
|
301
|
+
"""Estimate worst-case LLM calls before dispatch.
|
|
302
|
+
|
|
303
|
+
Counts only actual model invocations: reviewer calls plus one
|
|
304
|
+
optional arbitration call. Local synthesis is NOT an LLM call.
|
|
305
|
+
Used by budget enforcement to decide whether to degrade.
|
|
306
|
+
"""
|
|
307
|
+
if self.mode == MODE_SINGLE:
|
|
308
|
+
return 1 # legacy run_qc_review executes exactly one LLM call
|
|
309
|
+
|
|
310
|
+
n_reviewers = max(len(self.reviewers), 1)
|
|
311
|
+
n_components = 1
|
|
312
|
+
if self.mode == MODE_COMPONENT_PANEL:
|
|
313
|
+
n_components = min(
|
|
314
|
+
self.budget.max_components,
|
|
315
|
+
5,
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
calls = n_components * n_reviewers
|
|
319
|
+
if self.arbitration.enabled:
|
|
320
|
+
calls += 1
|
|
321
|
+
return calls
|
|
322
|
+
|
|
323
|
+
def degraded_copy(self) -> QualityPlan:
|
|
324
|
+
"""Return a degraded version that respects budget caps.
|
|
325
|
+
|
|
326
|
+
Least-destructive ladder (perpetual-loop r2): drop arbitration first,
|
|
327
|
+
then component_panel -> panel -> single, then trim reviewers. Records
|
|
328
|
+
original_mode and degrade_reason for traceability.
|
|
329
|
+
"""
|
|
330
|
+
qp = copy.deepcopy(self)
|
|
331
|
+
qp.original_mode = qp.mode
|
|
332
|
+
reasons = []
|
|
333
|
+
|
|
334
|
+
while True:
|
|
335
|
+
estimated = qp.estimate_calls()
|
|
336
|
+
max_calls = qp.budget.max_llm_calls
|
|
337
|
+
if max_calls is None or estimated <= max_calls:
|
|
338
|
+
break
|
|
339
|
+
if qp.arbitration.enabled:
|
|
340
|
+
qp.arbitration.enabled = False
|
|
341
|
+
reasons.append("dropped_arbitration")
|
|
342
|
+
continue
|
|
343
|
+
if qp.reviewers and len(qp.reviewers) > 1:
|
|
344
|
+
qp.reviewers = qp.reviewers[:-1]
|
|
345
|
+
reasons.append("trimmed_reviewer")
|
|
346
|
+
continue
|
|
347
|
+
if qp.mode == MODE_COMPONENT_PANEL:
|
|
348
|
+
qp.mode = MODE_PANEL
|
|
349
|
+
reasons.append("component_panel→panel")
|
|
350
|
+
continue
|
|
351
|
+
if qp.mode == MODE_PANEL:
|
|
352
|
+
qp.mode = MODE_SINGLE
|
|
353
|
+
qp.reviewers = qp.reviewers[:1] if qp.reviewers else []
|
|
354
|
+
reasons.append("panel→single")
|
|
355
|
+
continue
|
|
356
|
+
break
|
|
357
|
+
|
|
358
|
+
if reasons:
|
|
359
|
+
qp.degraded = True
|
|
360
|
+
qp.degrade_reason = "; ".join(reasons)
|
|
361
|
+
return qp
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
# ── Convenience factory ────────────────────────────────────────────────────
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def quality_plan_for_contract(
|
|
368
|
+
risk_tier: str,
|
|
369
|
+
qc_lens: str,
|
|
370
|
+
quality_spec: Optional[Dict[str, Any]] = None,
|
|
371
|
+
) -> QualityPlan:
|
|
372
|
+
"""Build a default QualityPlan from contract-level fields.
|
|
373
|
+
|
|
374
|
+
Mirrors the existing logic: code_correctness lenses get single QC,
|
|
375
|
+
architecture_audit gets panel mode. Respects risk_tier escalation.
|
|
376
|
+
"""
|
|
377
|
+
tier_map = DEFAULT_MODE_BY_RISK_AND_LENS.get(risk_tier, DEFAULT_MODE_BY_RISK_AND_LENS[RISK_TIER_AUTO])
|
|
378
|
+
mode = tier_map.get(qc_lens, tier_map.get("__default__", MODE_SINGLE))
|
|
379
|
+
|
|
380
|
+
# If quality_spec has minimum_counts (adversarial audit), assume panel
|
|
381
|
+
qs = quality_spec or {}
|
|
382
|
+
if qs.get("minimum_counts") and mode == MODE_SINGLE:
|
|
383
|
+
mode = MODE_PANEL
|
|
384
|
+
|
|
385
|
+
reviewers = []
|
|
386
|
+
default_personas = LENS_DEFAULT_PERSONAS.get(qc_lens, [])
|
|
387
|
+
for persona in default_personas:
|
|
388
|
+
reviewers.append(ReviewerRole(role=persona))
|
|
389
|
+
|
|
390
|
+
# Arbitration only for human_required or strategic lenses
|
|
391
|
+
arbitration_enabled = risk_tier == RISK_TIER_HUMAN_REQUIRED or qc_lens in (
|
|
392
|
+
LENS_STRATEGIC_REVIEW,
|
|
393
|
+
LENS_ARCHITECTURE_AUDIT,
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
return QualityPlan(
|
|
397
|
+
mode=mode,
|
|
398
|
+
lens=qc_lens,
|
|
399
|
+
components="auto",
|
|
400
|
+
reviewers=reviewers,
|
|
401
|
+
synthesis=SynthesisPolicy(
|
|
402
|
+
required=mode in (MODE_PANEL, MODE_COMPONENT_PANEL),
|
|
403
|
+
),
|
|
404
|
+
arbitration=ArbitrationPolicy(enabled=arbitration_enabled),
|
|
405
|
+
budget=QualityBudget(),
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
def validate_quality_plan(qp: QualityPlan) -> List[str]:
|
|
410
|
+
"""Validate a QualityPlan, returning error messages."""
|
|
411
|
+
errors = []
|
|
412
|
+
if qp.mode == MODE_ARBITRATION_ONLY:
|
|
413
|
+
errors.append("mode arbitration_only is no longer supported")
|
|
414
|
+
elif qp.mode not in VALID_MODES:
|
|
415
|
+
errors.append(f"mode must be one of {sorted(VALID_MODES)}, got {qp.mode!r}")
|
|
416
|
+
if qp.lens not in VALID_LENSES:
|
|
417
|
+
errors.append(f"lens must be one of {sorted(VALID_LENSES)}, got {qp.lens!r}")
|
|
418
|
+
if qp.components not in ("auto", "explicit"):
|
|
419
|
+
errors.append(f"components must be 'auto' or 'explicit', got {qp.components!r}")
|
|
420
|
+
if (
|
|
421
|
+
not isinstance(qp.budget.max_components, int)
|
|
422
|
+
or isinstance(qp.budget.max_components, bool)
|
|
423
|
+
or qp.budget.max_components < 1
|
|
424
|
+
):
|
|
425
|
+
errors.append("budget.max_components must be an integer >= 1")
|
|
426
|
+
if (
|
|
427
|
+
not isinstance(qp.budget.max_llm_calls, int)
|
|
428
|
+
or isinstance(qp.budget.max_llm_calls, bool)
|
|
429
|
+
or qp.budget.max_llm_calls < 1
|
|
430
|
+
):
|
|
431
|
+
errors.append("budget.max_llm_calls must be an integer >= 1")
|
|
432
|
+
if (
|
|
433
|
+
not isinstance(qp.budget.max_reviewers_per_component, int)
|
|
434
|
+
or isinstance(qp.budget.max_reviewers_per_component, bool)
|
|
435
|
+
or qp.budget.max_reviewers_per_component < 1
|
|
436
|
+
):
|
|
437
|
+
errors.append("budget.max_reviewers_per_component must be an integer >= 1")
|
|
438
|
+
if (
|
|
439
|
+
not isinstance(qp.budget.max_wall_clock_sec, int)
|
|
440
|
+
or isinstance(qp.budget.max_wall_clock_sec, bool)
|
|
441
|
+
or qp.budget.max_wall_clock_sec < 0
|
|
442
|
+
):
|
|
443
|
+
errors.append("budget.max_wall_clock_sec must be an integer >= 0")
|
|
444
|
+
if qp.mode in (MODE_PANEL, MODE_COMPONENT_PANEL) and not qp.reviewers:
|
|
445
|
+
errors.append(f"reviewers list must not be empty when mode is {qp.mode}")
|
|
446
|
+
for r in qp.reviewers:
|
|
447
|
+
if r.role not in PERSONA_DESCRIPTIONS:
|
|
448
|
+
errors.append(f"unknown persona role: {r.role!r} (valid: {sorted(PERSONA_DESCRIPTIONS)})")
|
|
449
|
+
return errors
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""Quality plane — backward-compat facade over the ``orchestrator.qc`` package.
|
|
2
|
+
|
|
3
|
+
Phased evolution:
|
|
4
|
+
Phase 1: thin wrapper over legacy run_qc_review(), no behavioral change.
|
|
5
|
+
Phase 4: component slicing dispatch with per-component reviewers.
|
|
6
|
+
Phase 5+: multi-agent panels, arbitration, provider scheduling.
|
|
7
|
+
Refactor: this flat module was split into the orchestrator.qc package
|
|
8
|
+
(personas / parsing / aggregator / runner) with an identical public
|
|
9
|
+
surface; QualityPlane there is the facade over the runner entrypoints.
|
|
10
|
+
|
|
11
|
+
Every symbol that was previously importable from
|
|
12
|
+
``orchestrator.quality_plane`` still resolves here, and monkeypatching
|
|
13
|
+
names on THIS module remains effective because the qc submodules resolve
|
|
14
|
+
their shared collaborators through this namespace at call time. New code
|
|
15
|
+
should import from ``orchestrator.qc`` directly.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import concurrent.futures # noqa: F401 (historical attribute surface)
|
|
21
|
+
import json # noqa: F401
|
|
22
|
+
import math # noqa: F401
|
|
23
|
+
import os # noqa: F401
|
|
24
|
+
import re # noqa: F401
|
|
25
|
+
import time # noqa: F401
|
|
26
|
+
from typing import Any, Callable, Dict, List, Optional # noqa: F401
|
|
27
|
+
|
|
28
|
+
_HOME = {
|
|
29
|
+
"MIN_REVIEWER_TIMEOUT_SEC": "orchestrator.qc.personas",
|
|
30
|
+
"_PAID_MODEL_MARKERS": "orchestrator.qc.personas",
|
|
31
|
+
"_REVIEWER_HOOK": "orchestrator.qc.personas",
|
|
32
|
+
"_build_persona_prompt": "orchestrator.qc.personas",
|
|
33
|
+
"_error_artifact": "orchestrator.qc.personas",
|
|
34
|
+
"_extract_prompt_paths": "orchestrator.qc.personas",
|
|
35
|
+
"_fake_raw_response": "orchestrator.qc.personas",
|
|
36
|
+
"_invoke_reviewer": "orchestrator.qc.personas",
|
|
37
|
+
"_resolve_arbitration_model": "orchestrator.qc.personas",
|
|
38
|
+
"_resolve_reviewer_model": "orchestrator.qc.personas",
|
|
39
|
+
"_deadline_for": "orchestrator.qc.parsing",
|
|
40
|
+
"_norm_path": "orchestrator.qc.parsing",
|
|
41
|
+
"_normalize_issue_evidence": "orchestrator.qc.parsing",
|
|
42
|
+
"_parse_reviewer_response": "orchestrator.qc.parsing",
|
|
43
|
+
"_raw_to_arbitration_verdict": "orchestrator.qc.parsing",
|
|
44
|
+
"_raw_to_artifact": "orchestrator.qc.parsing",
|
|
45
|
+
"_build_arbitration_prompt": "orchestrator.qc.aggregator",
|
|
46
|
+
"_component_verdict_to_qp_verdict": "orchestrator.qc.aggregator",
|
|
47
|
+
"_run_arbitration": "orchestrator.qc.aggregator",
|
|
48
|
+
"_should_arbitrate": "orchestrator.qc.aggregator",
|
|
49
|
+
"_synthesis_reason": "orchestrator.qc.aggregator",
|
|
50
|
+
"_MAX_COMPONENT_WORKERS": "orchestrator.qc.runner",
|
|
51
|
+
"_apply_quality_spec_gates": "orchestrator.qc.runner",
|
|
52
|
+
"_run_component_quality_plane": "orchestrator.qc.runner",
|
|
53
|
+
"_run_component_reviews": "orchestrator.qc.runner",
|
|
54
|
+
"_run_panel_quality_plane": "orchestrator.qc.runner",
|
|
55
|
+
"_validate_explicit_components": "orchestrator.qc.runner",
|
|
56
|
+
"run_quality_plane": "orchestrator.qc.runner",
|
|
57
|
+
"QualityPlane": "orchestrator.qc",
|
|
58
|
+
"ComponentSlice": "orchestrator.component_slicer",
|
|
59
|
+
"slice_components": "orchestrator.component_slicer",
|
|
60
|
+
"LLMError": "orchestrator.llm",
|
|
61
|
+
"call_llm": "orchestrator.llm",
|
|
62
|
+
"ModelRegistry": "orchestrator.models",
|
|
63
|
+
"CallSpec": "orchestrator.provider_scheduler",
|
|
64
|
+
"ProviderScheduler": "orchestrator.provider_scheduler",
|
|
65
|
+
"_build_qc_prompt": "orchestrator.qc_review",
|
|
66
|
+
"_redact_secrets": "orchestrator.qc_review",
|
|
67
|
+
"_select_qc_model": "orchestrator.qc_review",
|
|
68
|
+
"run_qc_review": "orchestrator.qc_review",
|
|
69
|
+
"MODE_COMPONENT_PANEL": "orchestrator.quality_plan",
|
|
70
|
+
"MODE_PANEL": "orchestrator.quality_plan",
|
|
71
|
+
"MODE_SINGLE": "orchestrator.quality_plan",
|
|
72
|
+
"PERSONA_DESCRIPTIONS": "orchestrator.quality_plan",
|
|
73
|
+
"QualityPlan": "orchestrator.quality_plan",
|
|
74
|
+
"ReviewerRole": "orchestrator.quality_plan",
|
|
75
|
+
"validate_quality_plan": "orchestrator.quality_plan",
|
|
76
|
+
"ArbitrationVerdict": "orchestrator.review_artifact",
|
|
77
|
+
"EvidenceRead": "orchestrator.review_artifact",
|
|
78
|
+
"QualityPlaneVerdict": "orchestrator.review_artifact",
|
|
79
|
+
"ReviewArtifact": "orchestrator.review_artifact",
|
|
80
|
+
"ReviewIssue": "orchestrator.review_artifact",
|
|
81
|
+
"VERDICT_CONDITIONAL_PASS": "orchestrator.review_artifact",
|
|
82
|
+
"VERDICT_ERROR": "orchestrator.review_artifact",
|
|
83
|
+
"VERDICT_INSUFFICIENT_EVIDENCE": "orchestrator.review_artifact",
|
|
84
|
+
"VERDICT_PASS": "orchestrator.review_artifact",
|
|
85
|
+
"VERDICT_REJECT": "orchestrator.review_artifact",
|
|
86
|
+
"synthesize_artifacts": "orchestrator.review_artifact",
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def __getattr__(name):
|
|
91
|
+
try:
|
|
92
|
+
home = _HOME[name]
|
|
93
|
+
except KeyError:
|
|
94
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}") from None
|
|
95
|
+
import importlib
|
|
96
|
+
|
|
97
|
+
value = getattr(importlib.import_module(home), name)
|
|
98
|
+
globals()[name] = value
|
|
99
|
+
return value
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def __dir__():
|
|
103
|
+
return sorted(set(globals()) | set(_HOME))
|