kin: auto-commit after pipeline

This commit is contained in:
Gros Frumos 2026-03-17 14:03:53 +02:00
parent 04cbbc563b
commit b6f40a6ace
9 changed files with 1690 additions and 16 deletions

View file

@ -65,9 +65,11 @@ def build_context(
specs = _load_specialists()
ctx["available_specialists"] = list(specs.get("specialists", {}).keys())
ctx["routes"] = specs.get("routes", {})
ctx["departments"] = specs.get("departments", {})
except Exception:
ctx["available_specialists"] = []
ctx["routes"] = {}
ctx["departments"] = {}
elif role == "architect":
ctx["modules"] = models.get_modules(conn, project_id)
@ -111,6 +113,41 @@ def build_context(
conn, project_id, category="security",
)
elif role.endswith("_head"):
# Department head: load department config and previous handoff
ctx["decisions"] = models.get_decisions(conn, project_id)
ctx["modules"] = models.get_modules(conn, project_id)
try:
specs = _load_specialists()
all_specs = specs.get("specialists", {})
departments = specs.get("departments", {})
spec = all_specs.get(role, {})
dept_name = spec.get("department", "")
dept_info = departments.get(dept_name, {})
ctx["department"] = dept_name
ctx["department_workers"] = dept_info.get("workers", [])
ctx["department_description"] = dept_info.get("description", "")
except Exception:
ctx["department"] = ""
ctx["department_workers"] = []
ctx["department_description"] = ""
# Previous handoff from another department (if any)
try:
dept = ctx.get("department")
last_handoff = models.get_last_handoff(conn, task_id, to_department=dept)
# Fallback: get latest handoff NOT from our own department
# (avoids picking up our own outgoing handoff)
if not last_handoff and dept:
all_handoffs = models.get_handoffs_for_task(conn, task_id)
for h in reversed(all_handoffs):
if h.get("from_department") != dept:
last_handoff = h
break
if last_handoff:
ctx["incoming_handoff"] = last_handoff
except Exception:
pass
else:
# Unknown role — give decisions as fallback
ctx["decisions"] = models.get_decisions(conn, project_id, limit=20)
@ -175,6 +212,13 @@ def format_prompt(context: dict, role: str, prompt_template: str | None = None)
prompt_path = PROMPTS_DIR / f"{role}.md"
if prompt_path.exists():
prompt_template = prompt_path.read_text()
elif role.endswith("_head"):
# Fallback: all department heads share the base department_head.md prompt
dept_head_path = PROMPTS_DIR / "department_head.md"
if dept_head_path.exists():
prompt_template = dept_head_path.read_text()
else:
prompt_template = f"You are a {role}. Complete the task described below."
else:
prompt_template = f"You are a {role}. Complete the task described below."
@ -265,6 +309,22 @@ def format_prompt(context: dict, role: str, prompt_template: str | None = None)
sections.append(f"- {name}: {steps}")
sections.append("")
# Department context (department heads)
dept = context.get("department")
if dept:
dept_desc = context.get("department_description", "")
sections.append(f"## Department: {dept}" + (f"{dept_desc}" if dept_desc else ""))
sections.append("")
dept_workers = context.get("department_workers")
if dept_workers:
sections.append(f"## Department workers: {', '.join(dept_workers)}")
sections.append("")
incoming_handoff = context.get("incoming_handoff")
if incoming_handoff:
sections.append("## Incoming handoff from previous department:")
sections.append(json.dumps(incoming_handoff, ensure_ascii=False))
sections.append("")
# Module hint (debugger)
hint = context.get("module_hint")
if hint: