export interface StepRecord { name: string; ok: boolean; ms: number; /** Optional payload (e.g. lockVersionDrift info). Kept small — large * envelope payloads should not be embedded here. */ info?: unknown; } export interface ErrorRecord { /** Last step in flight when the error fired. May be undefined when the * failure happened outside any instrumented step. */ step?: string; message: string; /** Error.name when not the bare 'Error' (e.g. 'TypeError', 'SyntaxError'). */ name?: string; /** errno-style code from fs/network errors ('ENOENT', 'EACCES', ...). */ code?: string; /** File path on fs errors. */ path?: string; stack?: string; } export interface AuditEntry { ts: string; version: string; command: string; args: string[]; cwd: string; exitCode: number; durationMs: number; steps?: StepRecord[]; error?: ErrorRecord; stderrTail?: string; env?: { node: string; platform: string; arch: string; }; warnings?: string[]; } export interface AuditContext { /** Run `fn` as a named step. Records ok/ms on completion; if `fn` throws, * records `ok:false` and re-throws (caller decides what to do with the * error). Use `info` to attach a small payload — keep it light. */ runStep(name: string, fn: () => T | Promise, info?: unknown): Promise; /** Add diagnostic text to the failure stderr tail without printing it. Use * for child-process output captured with stdio:'pipe' in --json mode. */ captureStderr(chunk: unknown): void; /** Attach a free-form warning to the entry (audit only — does NOT write * to stderr). Use for "auto-forced because lock drift" style notices. */ warn(message: string): void; /** Flush the entry. Idempotent — only the first call writes. */ finish(opts: { exitCode: number; error?: unknown; }): void; } /** * Begin auditing the current command. Call once per `mswai ` * invocation, before the command runs. Returns a no-op context when * audit is disabled via `MSWAI_LOG=0`. */ export declare function startAudit(opts: { command: string; args: string[]; cwd: string; }): AuditContext; /** * Get the audit context for the in-flight command. Returns a no-op context * (never null) when no audit is active or `MSWAI_LOG=0` is set, so callers * can always write `await currentAudit().runStep(...)` without a null check. */ export declare function currentAudit(): AuditContext;