import { dirname, join, resolve } from "node:path"; import type { AgentToolResult, ExtensionContext } from "@earendil-works/pi-coding-agent"; import type { HostContext } from "./host-contracts.ts"; import { roleRunArtifactsDirectory } from "./role-run-placement.ts"; import { Type } from "typebox"; export const AUDITOR_DOSSIER_TOOL_NAME = "ak_get_run_dossier" as const; export type AuditorDossierLocation = { readonly runDirectory: string; readonly admittedRequest: string; readonly parentSessionCandidate: string; readonly attachments: string; readonly artifacts: string; }; /** Resolve the exact run binding already carried by the parent record session. */ export function auditorRunDirectory(context: ExtensionContext | HostContext): string | undefined { const sessionFile = context.sessionManager?.getSessionFile?.(); if (sessionFile === undefined) return undefined; // Sole layout: /session/session.jsonl → climb two levels to the run directory. return resolve(dirname(dirname(sessionFile))); } /** The one shared, run-bound dossier locator exposed to every auditor seat. */ export function createAuditorDossierTool( runDirectory: string | undefined, ) { return { name: AUDITOR_DOSSIER_TOOL_NAME, description: "定位本审计席绑定的 run 卷宗及其证据入口。", // #836 r16 class 3: execute() ignores `_params` entirely — a closed root // only rejects the role for saying more. parameters: Type.Object({}, { additionalProperties: true }), async execute(_id: string, _params: unknown): Promise> { if (runDirectory === undefined) { return { content: [{ type: "text", text: "本审计席无绑定 run 卷宗记录。" }], details: undefined, }; } // #836: whole run directory pointer — officer finds materials; no leaf preference (A7.2). const details: AuditorDossierLocation = { runDirectory, admittedRequest: join(runDirectory, "admitted-request.json"), parentSessionCandidate: join(runDirectory, "session", "session.jsonl"), attachments: join(runDirectory, "attachments"), artifacts: roleRunArtifactsDirectory(runDirectory), }; return { content: [{ type: "text", text: JSON.stringify(details) }], details, }; }, }; }