kin: KIN-021 Аудит-лог для --dangerously-skip-permissions в auto mode
This commit is contained in:
parent
67071c757d
commit
a0b0976d8d
16 changed files with 1477 additions and 14 deletions
51
web/api.py
51
web/api.py
|
|
@ -223,9 +223,16 @@ def create_task(body: TaskCreate):
|
|||
return t
|
||||
|
||||
|
||||
VALID_ROUTE_TYPES = {"debug", "feature", "refactor", "hotfix"}
|
||||
|
||||
|
||||
class TaskPatch(BaseModel):
|
||||
status: str | None = None
|
||||
execution_mode: str | None = None
|
||||
priority: int | None = None
|
||||
route_type: str | None = None
|
||||
title: str | None = None
|
||||
brief_text: str | None = None
|
||||
|
||||
|
||||
VALID_STATUSES = set(models.VALID_TASK_STATUSES)
|
||||
|
|
@ -238,8 +245,15 @@ def patch_task(task_id: str, body: TaskPatch):
|
|||
raise HTTPException(400, f"Invalid status '{body.status}'. Must be one of: {', '.join(VALID_STATUSES)}")
|
||||
if body.execution_mode is not None and body.execution_mode not in VALID_EXECUTION_MODES:
|
||||
raise HTTPException(400, f"Invalid execution_mode '{body.execution_mode}'. Must be one of: {', '.join(VALID_EXECUTION_MODES)}")
|
||||
if body.status is None and body.execution_mode is None:
|
||||
raise HTTPException(400, "Nothing to update. Provide status or execution_mode.")
|
||||
if body.priority is not None and not (1 <= body.priority <= 10):
|
||||
raise HTTPException(400, "priority must be between 1 and 10")
|
||||
if body.route_type is not None and body.route_type and body.route_type not in VALID_ROUTE_TYPES:
|
||||
raise HTTPException(400, f"Invalid route_type '{body.route_type}'. Must be one of: {', '.join(sorted(VALID_ROUTE_TYPES))} or empty string to clear")
|
||||
if body.title is not None and not body.title.strip():
|
||||
raise HTTPException(400, "title must not be empty")
|
||||
all_none = all(v is None for v in [body.status, body.execution_mode, body.priority, body.route_type, body.title, body.brief_text])
|
||||
if all_none:
|
||||
raise HTTPException(400, "Nothing to update.")
|
||||
conn = get_conn()
|
||||
t = models.get_task(conn, task_id)
|
||||
if not t:
|
||||
|
|
@ -250,6 +264,22 @@ def patch_task(task_id: str, body: TaskPatch):
|
|||
fields["status"] = body.status
|
||||
if body.execution_mode is not None:
|
||||
fields["execution_mode"] = body.execution_mode
|
||||
if body.priority is not None:
|
||||
fields["priority"] = body.priority
|
||||
if body.title is not None:
|
||||
fields["title"] = body.title.strip()
|
||||
if body.route_type is not None or body.brief_text is not None:
|
||||
current_brief = t.get("brief") or {}
|
||||
if isinstance(current_brief, str):
|
||||
current_brief = {"text": current_brief}
|
||||
if body.route_type is not None:
|
||||
if body.route_type:
|
||||
current_brief = {**current_brief, "route_type": body.route_type}
|
||||
else:
|
||||
current_brief = {k: v for k, v in current_brief.items() if k != "route_type"}
|
||||
if body.brief_text is not None:
|
||||
current_brief = {**current_brief, "text": body.brief_text}
|
||||
fields["brief"] = current_brief if current_brief else None
|
||||
models.update_task(conn, task_id, **fields)
|
||||
t = models.get_task(conn, task_id)
|
||||
conn.close()
|
||||
|
|
@ -384,6 +414,23 @@ def reject_task(task_id: str, body: TaskReject):
|
|||
return {"status": "pending", "reason": body.reason}
|
||||
|
||||
|
||||
class TaskRevise(BaseModel):
|
||||
comment: str
|
||||
|
||||
|
||||
@app.post("/api/tasks/{task_id}/revise")
|
||||
def revise_task(task_id: str, body: TaskRevise):
|
||||
"""Revise a task: return to in_progress with director's comment for the agent."""
|
||||
conn = get_conn()
|
||||
t = models.get_task(conn, task_id)
|
||||
if not t:
|
||||
conn.close()
|
||||
raise HTTPException(404, f"Task '{task_id}' not found")
|
||||
models.update_task(conn, task_id, status="in_progress", revise_comment=body.comment)
|
||||
conn.close()
|
||||
return {"status": "in_progress", "comment": body.comment}
|
||||
|
||||
|
||||
@app.get("/api/tasks/{task_id}/running")
|
||||
def is_task_running(task_id: str):
|
||||
"""Check if task has an active (running) pipeline."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue