diff --git a/app/api/routes_instructions.py b/app/api/routes_instructions.py index 145f254..1937a24 100644 --- a/app/api/routes_instructions.py +++ b/app/api/routes_instructions.py @@ -57,6 +57,14 @@ def update_instruction(instruction_id: str, body: UpdateInstructionRequest): return InstructionCreateResponse(item=item) +@router.delete("/consumed", status_code=200) +def clear_consumed_instructions(): + """Delete all consumed instructions. Pending instructions are never affected.""" + count = instruction_service.clear_consumed() + event_service.broadcast("history.cleared", {"count": count}) + return {"cleared": count} + + @router.delete("/{instruction_id}", status_code=204) def delete_instruction(instruction_id: str): try: diff --git a/app/services/instruction_service.py b/app/services/instruction_service.py index 95d2b1f..830d70f 100644 --- a/app/services/instruction_service.py +++ b/app/services/instruction_service.py @@ -168,6 +168,19 @@ def delete_instruction(instruction_id: str) -> None: logger.info("Instruction deleted id=%s", instruction_id) +def clear_consumed() -> int: + """Delete all consumed instructions. Returns the number of rows deleted.""" + with get_write_conn() as conn: + row = conn.execute( + "SELECT COUNT(*) FROM instructions WHERE status = 'consumed'" + ).fetchone() + count = row[0] if row else 0 + conn.execute("DELETE FROM instructions WHERE status = 'consumed'") + + logger.info("Consumed instructions cleared count=%d", count) + return count + + def consume_next(agent_id: str = "unknown") -> Optional[InstructionItem]: """ Atomically claim and return the next pending instruction. diff --git a/static/index.html b/static/index.html index aa468bb..f1c95f0 100644 --- a/static/index.html +++ b/static/index.html @@ -111,7 +111,13 @@ Consumed - 0 +