import { appendToolCall } from "../features/observability/index.js";
import { createRunStore, getActiveRun } from "../features/run-state/index.js";
import { nowIso, sanitizeJson, sanitizeText } from "../shared/index.js";
export function createToolExecuteAfterHandler(ctx) {
    const store = createRunStore(ctx.input.directory, ctx.config);
    return async function toolExecuteAfter(input, output) {
        const active = await getActiveRun(store);
        if (!active)
            return;
        await appendToolCall(store, active.run_id, {
            tool_call_id: input.callID,
            timestamp_start: nowIso(),
            timestamp_end: nowIso(),
            run_id: active.run_id,
            session_id: input.sessionID,
            tool_name: input.tool,
            args_summary: JSON.stringify(sanitizeJson(input.args)).slice(0, 500),
            status: "completed",
            output_summary: summarizeToolHookOutput(input.tool, output),
            evidence_refs: [],
            args_ref: typeof output.metadata === "object" ? undefined : undefined,
        });
    };
}
export function summarizeToolHookOutput(toolName, output) {
    const title = sanitizeText(String(output.title ?? "").trim());
    if (!toolName.startsWith("seed_")) {
        return title ? `${title} [output redacted]` : "[REDACTED_HOST_TOOL_OUTPUT]";
    }
    return sanitizeText(String(output.output ?? output.title ?? "")).slice(0, 1000);
}
//# sourceMappingURL=tool-execute-after.js.map