feat(FN-1257): add runContext audit trail for task mutations
- Add RunMutationContext type to track which agent run caused a mutation - Thread runContext through TaskStore.logEntry, addComment, addSteeringComment, and pauseTask - Propagate runContext from HeartbeatMonitor.executeHeartbeat to task store operations - Propagate runContext from TaskExecutor.execute to task store operations - Add GET /api/agents/:id/runs/:runId/mutations endpoint to query mutations by runId - Add createTaskLogToolWithContext for heartbeat tools with run context support - Add comprehensive tests for RunMutationContext across store and heartbeat modules - Update memory.md with RunMutationContext usage convention
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* The parameter schemas are canonical here — executor.ts imports and reuses them.
|
||||
*/
|
||||
|
||||
import type { TaskDocument, TaskDocumentCreateInput, TaskStore } from "@fusion/core";
|
||||
import type { TaskDocument, TaskDocumentCreateInput, TaskStore, RunMutationContext } from "@fusion/core";
|
||||
import type { ToolDefinition } from "@mariozechner/pi-coding-agent";
|
||||
import { Type, type Static } from "@mariozechner/pi-ai";
|
||||
import type { AgentReflectionService } from "./agent-reflection.js";
|
||||
@@ -107,6 +107,32 @@ export function createTaskLogTool(store: TaskStore, taskId: string): ToolDefinit
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a `task_log` tool with run context for mutation correlation.
|
||||
*
|
||||
* @param store - TaskStore for task persistence
|
||||
* @param taskId - The task ID to log entries against
|
||||
* @param runContext - Optional run context for mutation correlation
|
||||
* @returns ToolDefinition for the `task_log` tool
|
||||
*/
|
||||
export function createTaskLogToolWithContext(store: TaskStore, taskId: string, runContext?: RunMutationContext): ToolDefinition {
|
||||
return {
|
||||
name: "task_log",
|
||||
label: "Log Entry",
|
||||
description:
|
||||
"Log an important action, decision, or issue for this task. " +
|
||||
"Use for significant events — not every small step.",
|
||||
parameters: taskLogParams,
|
||||
execute: async (_id: string, params: Static<typeof taskLogParams>) => {
|
||||
await store.logEntry(taskId, params.message, params.outcome, runContext);
|
||||
return {
|
||||
content: [{ type: "text" as const, text: `Logged: ${params.message}` }],
|
||||
details: {},
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a `task_document_write` tool that stores a named task document.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user