/** * peaks-security-audit service — independent security audit skill driver. * * Slice v2.12.0 (Group A, Tier 2). The skill is decoupled from the * peaks-rd 5-way fan-out (per PRD AC-2.x) and lives as a standalone * CLI surface: `peaks security-audit run --rid ...`. * * The service owns: * - 5-state detection of the security-audit runtime * (handoff-missing / template-missing / dispatch-failed / template-malformed / ready) * - Loading + sha256 verification of the prd/handoff.md * - Loading the project-level security-template.md * - Producing the audit envelope (verdict + violations) to write * to `.peaks/_runtime//audit/security-.md` * * The actual LLM-in-loop audit step is NOT in this service — the * parent LLM (peaks-security-audit skill prompt) reads the template, * runs the audit, and returns a structured envelope. This service * is the pure I/O + validation core; the LLM is the judgement core. * * Why a service (not inlined in the CLI): * - Unit-testable in isolation (6 case per PRD AC-2.8) * - The 5-state detector mirrors the ecc-bridge detectEcc pattern * (slice 7 Group D), keeping the surface uniform * - Future migration to peaks sub-agent dispatch (peaks-rd main * loop can opt to call this service directly without re-implementing * the handoff verification) * * Cross-references: * - PRD: `.peaks/_runtime//prd/handoff.md` (sha256-locked, schemaVersion: 2) * - Template: `.peaks/project-scan/security-template.md` * - Output: `.peaks/_runtime//audit/security-.md` * - Schema: `.peaks/project-scan/audit-output-schema.md` (schemaVersion: 1) */ /** * 5-state detection result. Mirrors `detectEcc` in `services/code-review/ecc-bridge.ts`. * * - `ready` — handoff + template + project all present * - `handoff-missing` — `.peaks/_runtime//prd/handoff.md` absent * - `template-missing` — `.peaks/project-scan/security-template.md` absent * - `dispatch-failed` — parent LLM threw before returning the audit envelope * - `envelope-malformed` — parent LLM returned a value that fails `isSecurityAuditEnvelope` */ export type SecurityAuditDetectState = 'ready' | 'handoff-missing' | 'template-missing' | 'dispatch-failed' | 'envelope-malformed'; export interface SecurityAuditDetectResult { readonly state: SecurityAuditDetectState; readonly handoffPresent: boolean; readonly templatePresent: boolean; readonly warnings: readonly string[]; readonly nextActions: readonly string[]; } export type SecurityAuditVerdict = 'pass' | 'warn' | 'block'; export interface SecurityAuditViolation { readonly dimension: string; readonly severity: 'CRITICAL' | 'HIGH' | 'MED' | 'LOW'; readonly file: string; readonly line: number; readonly hint: string; } export interface SecurityAuditEnvelope { readonly verdict: SecurityAuditVerdict; readonly violations: ReadonlyArray; readonly summary: string; } /** * Validate a raw value as a SecurityAuditEnvelope. Mirrors the * `isEccEnvelope` strict-shape pattern. */ export declare function isSecurityAuditEnvelope(value: unknown): value is SecurityAuditEnvelope; /** * Handoff frontmatter — minimal projection of peaks-prd v2.11.0 handoff * frontmatter. We only need sha256 for verification; the rest of the * handoff body is consumed by the parent LLM, not by this service. */ export interface HandoffFrontmatter { readonly sha256: string; readonly schemaVersion: number; } /** * Read the peaks-prd handoff frontmatter + body, verify sha256 matches * the body. Returns null on missing file or sha256 mismatch; otherwise * returns the parsed frontmatter + body string. * * Defensive: we read frontmatter via a 1-line regex match, not via * a YAML parser. The handoff service (`src/services/prd/handoff-service.ts`) * is the canonical writer; we only consume its output here. */ export declare function readAndVerifyHandoff(handoffPath: string, projectRoot: string): { frontmatter: HandoffFrontmatter; body: string; } | null; /** * Read the project-level security-template.md. Returns the body * string (with frontmatter stripped) or null if the file is absent. * Does NOT validate the template content; the parent LLM validates * by reading. */ export declare function readSecurityTemplate(projectRoot: string): string | null; /** * 5-state detector. The parent skill inspects the state and either * proceeds (when `ready`) or records a degradation note and falls * back (when any other state). * * Soft-fail policy mirrors `detectEcc` (slice 7 Group D): the CLI * never throws; it returns a typed detect result. */ export declare function detectSecurityAudit(input: { readonly projectRoot: string; readonly sessionId: string; readonly dispatchError?: unknown; readonly envelope?: unknown; }): SecurityAuditDetectResult; /** * Render a SecurityAuditEnvelope to the canonical audit artifact body * (markdown). Mirrors `adaptEccEnvelopeToRdCodeReview` in ecc-bridge.ts: * produce a markdown body with all required sections, ready to write * to `.peaks/_runtime//audit/security-.md`. */ export declare function renderSecurityAuditArtifact(env: SecurityAuditEnvelope, opts: { rid: string; handoffHash: string; generatedAt: string; }): { body: string; violationsCount: number; verdict: SecurityAuditVerdict; }; /** * Write the rendered audit artifact to * `.peaks/_runtime//audit/security-.md`. * * Atomic write (tmp + rename) to avoid partial writes on crash. * Returns the absolute path on success. */ export declare function writeSecurityAuditArtifact(projectRoot: string, sessionId: string, rid: string, body: string): string; /** * Convenience: run `detectSecurityAudit` + `renderSecurityAuditArtifact` * + `writeSecurityAuditArtifact` in one call. * * Returns `{ detect, artifactPath, violationsCount, verdict }` or * `{ detect, artifactPath: null, ... }` when not ready. */ export declare function runSecurityAudit(input: { readonly projectRoot: string; readonly sessionId: string; readonly rid: string; readonly generatedAt: string; readonly dispatchError?: unknown; readonly envelope?: unknown; }): { detect: SecurityAuditDetectResult; artifactPath: string | null; violationsCount: number; verdict: SecurityAuditVerdict | null; };