/** * Static audit service โ€” `peaks audit static`. * * Slice #6 L2.3 P2-a: soft-optional ECC AgentShield integration. * * Per spec ยง5.3, the audit framework integrates with ECC AgentShield * (102 lint rules) on a soft-optional basis. When ECC is installed * AND `agentShieldEnabled: true`, the audit subprocess spawns the * ECC scanner and merges its findings; when either is missing, the * audit completes with peaks-cli-only findings. * * The subprocess is **observability enhancement**, not a structural * gate โ€” every soft-fail path returns a well-formed audit report. */ import { type ProseRatioResult } from './prose-ratio-calculator.js'; import type { EnforcerFinding, RedLineAudit } from './types.js'; export interface StaticAuditInput { readonly projectRoot: string; /** Override the preference for a single call. Default: read from preferences. */ readonly enableAgentShield?: boolean | undefined; /** * Optional subprocess runner injection point. Used by tests * to mock `npx ecc-agentshield`. Production callers should * leave this undefined; the default uses `child_process.spawnSync`. */ readonly subprocessRunner?: SubprocessRunner | undefined; } export interface StaticAuditResult { readonly audit: RedLineAudit; readonly agentShield: AgentShieldState; readonly warnings: readonly string[]; /** v2.14.0 Slice C: prose-only ratio with informational exclusion (per A3.1). */ readonly proseRatio: ProseRatioResult; } export interface AgentShieldState { /** Whether the agent-shield subprocess was spawned. */ readonly spawned: boolean; /** Whether ECC AgentShield is installed (regardless of whether it was spawned). */ readonly installed: boolean; /** Why the subprocess was or was not spawned. */ readonly reason: 'enabled-and-installed' | 'disabled-by-preference' | 'flag-disabled' | 'flag-enabled-but-ecc-missing' | 'disabled-and-ecc-missing'; /** The merged ECC findings (empty if not spawned). */ readonly findings: readonly EnforcerFinding[]; } /** * Subprocess runner interface โ€” the only seam tests need to * mock the `npx ecc-agentshield` subprocess. Production callers * leave `subprocessRunner` undefined; the default delegates to * `child_process.spawnSync` (synchronous, captures stdout). */ export interface SubprocessRunner { run(command: string, args: readonly string[], timeoutMs: number): SubprocessResult; } export interface SubprocessResult { readonly status: number | null; readonly stdout: string; readonly stderr: string; readonly error?: Error; } export declare function runStaticAudit(input: StaticAuditInput): StaticAuditResult;