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

@ -473,12 +473,14 @@ def create_pipeline(
project_id: str,
route_type: str,
steps: list | dict,
parent_pipeline_id: int | None = None,
department: str | None = None,
) -> dict:
"""Create a new pipeline run."""
cur = conn.execute(
"""INSERT INTO pipelines (task_id, project_id, route_type, steps)
VALUES (?, ?, ?, ?)""",
(task_id, project_id, route_type, _json_encode(steps)),
"""INSERT INTO pipelines (task_id, project_id, route_type, steps, parent_pipeline_id, department)
VALUES (?, ?, ?, ?, ?, ?)""",
(task_id, project_id, route_type, _json_encode(steps), parent_pipeline_id, department),
)
conn.commit()
row = conn.execute(
@ -923,6 +925,68 @@ def delete_attachment(conn: sqlite3.Connection, attachment_id: int) -> bool:
return cur.rowcount > 0
# ---------------------------------------------------------------------------
# Department Handoffs (KIN-098)
# ---------------------------------------------------------------------------
def create_handoff(
conn: sqlite3.Connection,
pipeline_id: int,
task_id: str,
from_department: str,
to_department: str | None = None,
artifacts: dict | None = None,
decisions_made: list | None = None,
blockers: list | None = None,
status: str = "pending",
) -> dict:
"""Record a department handoff with artifacts for inter-department context."""
cur = conn.execute(
"""INSERT INTO department_handoffs
(pipeline_id, task_id, from_department, to_department, artifacts, decisions_made, blockers, status)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)""",
(pipeline_id, task_id, from_department, to_department,
_json_encode(artifacts), _json_encode(decisions_made), _json_encode(blockers), status),
)
conn.commit()
row = conn.execute(
"SELECT * FROM department_handoffs WHERE id = ?", (cur.lastrowid,)
).fetchone()
return _row_to_dict(row)
def get_handoffs_for_task(conn: sqlite3.Connection, task_id: str) -> list[dict]:
"""Get all handoffs for a task ordered by creation time."""
rows = conn.execute(
"SELECT * FROM department_handoffs WHERE task_id = ? ORDER BY created_at",
(task_id,),
).fetchall()
return _rows_to_list(rows)
def get_last_handoff(
conn: sqlite3.Connection,
task_id: str,
to_department: str | None = None,
) -> dict | None:
"""Get the most recent handoff for a task, optionally filtered by destination department."""
if to_department:
row = conn.execute(
"""SELECT * FROM department_handoffs
WHERE task_id = ? AND to_department = ?
ORDER BY created_at DESC LIMIT 1""",
(task_id, to_department),
).fetchone()
else:
row = conn.execute(
"""SELECT * FROM department_handoffs
WHERE task_id = ?
ORDER BY created_at DESC LIMIT 1""",
(task_id,),
).fetchone()
return _row_to_dict(row)
def get_chat_messages(
conn: sqlite3.Connection,
project_id: str,