kin: KIN-DOCS-001-backend_dev
This commit is contained in:
parent
266acd0f62
commit
7edc66201c
3 changed files with 245 additions and 4 deletions
|
|
@ -1966,6 +1966,73 @@ def run_pipeline(
|
|||
}
|
||||
# status == 'confirmed': smoke test passed, continue pipeline
|
||||
|
||||
# Constitutional validator: gate before implementation (KIN-DOCS-001)
|
||||
if role == "constitutional_validator" and result["success"] and not dry_run:
|
||||
cv_output = result.get("output") or result.get("raw_output") or ""
|
||||
cv_parsed = None
|
||||
try:
|
||||
if isinstance(cv_output, dict):
|
||||
cv_parsed = cv_output
|
||||
elif isinstance(cv_output, str):
|
||||
cv_parsed = _try_parse_json(cv_output)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if isinstance(cv_parsed, dict):
|
||||
cv_verdict = cv_parsed.get("verdict", "")
|
||||
if cv_verdict in ("changes_required", "escalated"):
|
||||
if cv_verdict == "escalated":
|
||||
reason = cv_parsed.get("escalation_reason") or "constitutional_validator: принципы конфликтуют — требуется решение директора"
|
||||
blocked_reason = f"constitutional_validator: escalated — {reason}"
|
||||
else:
|
||||
violations = cv_parsed.get("violations") or []
|
||||
if violations:
|
||||
violations_summary = "; ".join(
|
||||
f"{v.get('principle', '?')} ({v.get('severity', '?')}): {v.get('description', '')}"
|
||||
for v in violations[:3]
|
||||
)
|
||||
else:
|
||||
violations_summary = cv_parsed.get("summary") or "changes required"
|
||||
blocked_reason = f"constitutional_validator: changes_required — {violations_summary}"
|
||||
|
||||
models.update_task(
|
||||
conn, task_id,
|
||||
status="blocked",
|
||||
blocked_reason=blocked_reason,
|
||||
blocked_agent_role="constitutional_validator",
|
||||
blocked_pipeline_step=str(i + 1),
|
||||
)
|
||||
if pipeline:
|
||||
models.update_pipeline(
|
||||
conn, pipeline["id"],
|
||||
status="failed",
|
||||
total_cost_usd=total_cost,
|
||||
total_tokens=total_tokens,
|
||||
total_duration_seconds=total_duration,
|
||||
)
|
||||
try:
|
||||
models.write_log(
|
||||
conn, pipeline["id"],
|
||||
f"Constitutional validator blocked pipeline: {blocked_reason}",
|
||||
level="WARN",
|
||||
extra={"role": "constitutional_validator", "verdict": cv_verdict, "reason": blocked_reason},
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return {
|
||||
"success": False,
|
||||
"error": blocked_reason,
|
||||
"blocked_by": "constitutional_validator",
|
||||
"blocked_reason": blocked_reason,
|
||||
"steps_completed": i + 1,
|
||||
"results": results,
|
||||
"total_cost_usd": total_cost,
|
||||
"total_tokens": total_tokens,
|
||||
"total_duration_seconds": total_duration,
|
||||
"pipeline_id": pipeline["id"] if pipeline else None,
|
||||
}
|
||||
# verdict == 'approved': constitutional check passed, continue pipeline
|
||||
|
||||
# Tech debt: create followup child task from dev agent output (KIN-128)
|
||||
if role in _TECH_DEBT_ROLES and result["success"] and not dry_run:
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue