{
"meta": {
"agent": "planner",
"task_id": "496",
"title": "Restore agent-runner.log in agent-worker InvocationProcessor",
"created_at": "2026-04-14T12:00:00Z"
},
"inputs": [
{
"name": "issue-496",
"type": "context",
"ref": "https://github.com/AgentSDE/agent-core/issues/496",
"notes": "Restore agent-runner.log after fire-and-forget refactor"
},
{
"name": "invocation.processor.ts",
"type": "file",
"ref": "agent-worker/src/invocation/invocation.processor.ts",
"notes": "Target file — currently writes ai-output.jsonl but no agent-runner.log"
},
{
"name": "claude-invocation.service.ts",
"type": "file",
"ref": "src/invoke/claude-invocation.service.ts",
"notes": "Reference — original log-writing logic (now removed after BullMQ refactor)"
}
],
"outputs": [
{
"name": "plan",
"type": "plan",
"format": "md",
"content": "plan.md"
}
],
"files": [
{
"path": "agent-worker/src/invocation/invocation.processor.ts",
"action": "modify",
"reason": "Add agent-runner.log WriteStream, switch stdio to pipe, parse JSON lines for formatted log entries"
},
{
"path": "agent-worker/src/invocation/invocation.processor.spec.ts",
"action": "create",
"reason": "Unit tests for log creation, format, logEnded guard, error handling"
}
],
"steps": [
{
"id": "S1",
"summary": "Add cetTs() helper, create log WriteStream, write start header, switch stdio from fd to pipe, attach stdout/stderr handlers that write to both output files and formatted log",
"acceptance": [
"cetTs() returns CET/CEST timestamp in sv-SE locale format",
"agent-runner.log is created in append mode in {metaDir}",
"Start header line written: {ts} - {phase} - Starting Claude invocation",
"stdio uses pipe mode; stdout/stderr data written to both raw files and formatted log",
"stdout JSON lines parsed: tool_use → [tool:ToolName], text → [text] prefix",
"stderr lines written as: {ts} - {phase} - stderr: {chunk}"
],
"depends_on": []
},
{
"id": "S2",
"summary": "Add logEnded guard, write completion/error footers, close log stream in all exit paths, write unit tests",
"acceptance": [
"logEnded boolean flag prevents write-after-end errors",
"Completion footer: {ts} - {phase} - Completed with exit code {code}",
"Error path writes error entry and closes log stream",
"Unit tests cover: log creation, header/footer format, JSON line parsing, logEnded guard, missing taskDir"
],
"depends_on": [
"S1"
]
}
],
"risks": [
{
"risk": "Switching from fd to pipe stdio changes buffering behavior",
"mitigation": "WriteStream handles backpressure internally; keep log writes lightweight"
},
{
"risk": "Malformed JSON lines from Claude stdout",
"mitigation": "Wrap JSON.parse in try/catch, fall back to raw line logging"
}
],
"assumptions": [
"The viewer already reads from {taskDir}/meta/agent-runner.log — no viewer changes needed",
"Claude CLI stream-json output format has type field (tool_use, text) at the top level of each JSON line",
"agent-worker repo follows same lint/test conventions as agent-core"
],
"open_questions": []
}