// The audit-logger's one tool — its standing: where the trail is, and what waits in the spool // (novox/hq issue 276). Launched as its own process beside the handler, so it reads the spool from // disk rather than asking the handler. import { stat } from "node:fs/promises"; import { registerModuleTools, type ToolDefinition } from "@novox/mesh-sdk/tools"; import { auditLogPath, auditSpoolPath } from "../audit.js"; import { Spool } from "../spool.js"; export function getAuditTools(env: NodeJS.ProcessEnv = process.env): ToolDefinition[] { return [ { name: "audit_status", description: "The audit trail's standing: its path and size, and the events that could not be written yet — how many wait in the spool, how many were taken from the bus and are held only there, the oldest, the last error, and whether the spool is over its bound (then the bus gives events up and max-deliveries is raised).", input: {}, run: async () => { const path = auditLogPath(env); const size = await stat(path).then((s) => s.size, () => null); const spool = await Spool.read(auditSpoolPath(env)); return { trail: { path, bytes: size }, spool: spool.standing() }; }, }, ]; } registerModuleTools("audit-logger", (env) => getAuditTools(env));