/** * peaks-perf-audit service — independent performance audit skill driver. * * Slice v2.12.0 (Group A, Tier 3). Symmetric to security-audit-service.ts: * - 5-state detection of the perf-audit runtime * - Loading + sha256 verification of the prd/handoff.md * - Loading the project-level perf-template.md * - Producing the audit envelope (verdict + violations) to write * to `.peaks/_runtime//audit/perf-.md` * * The actual LLM-in-loop audit step is NOT in this service — the * parent LLM (peaks-perf-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. * * Cross-references: * - PRD: `.peaks/_runtime//prd/handoff.md` (sha256-locked, schemaVersion: 2) * - Template: `.peaks/project-scan/perf-template.md` * - Output: `.peaks/_runtime//audit/perf-.md` * - Schema: `.peaks/project-scan/audit-output-schema.md` (schemaVersion: 1) * - Companion: `src/services/audit-independent/security-audit-service.ts` */ /** * 5-state detection result. Mirrors `SecurityAuditDetectState` and * the ecc-bridge `detectEcc` shape (slice 7 Group D). * * - `ready` — handoff + template + project all present * - `handoff-missing` — `.peaks/_runtime//prd/handoff.md` absent * - `template-missing` — `.peaks/project-scan/perf-template.md` absent * - `dispatch-failed` — parent LLM threw before returning the audit envelope * - `envelope-malformed` — parent LLM returned a value that fails `isPerfAuditEnvelope` */ export type PerfAuditDetectState = 'ready' | 'handoff-missing' | 'template-missing' | 'dispatch-failed' | 'envelope-malformed'; export interface PerfAuditDetectResult { readonly state: PerfAuditDetectState; readonly handoffPresent: boolean; readonly templatePresent: boolean; readonly warnings: readonly string[]; readonly nextActions: readonly string[]; } export type PerfAuditVerdict = 'pass' | 'warn' | 'block'; export interface PerfAuditViolation { readonly dimension: string; readonly severity: 'CRITICAL' | 'HIGH' | 'MED' | 'LOW'; readonly file: string; readonly line: number; readonly hint: string; } export interface PerfAuditEnvelope { readonly verdict: PerfAuditVerdict; readonly violations: ReadonlyArray; readonly summary: string; } /** * Validate a raw value as a PerfAuditEnvelope. Mirrors the * `isSecurityAuditEnvelope` strict-shape pattern. */ export declare function isPerfAuditEnvelope(value: unknown): value is PerfAuditEnvelope; /** * 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. * * Symmetric to `HandoffFrontmatter` in `security-audit-service.ts`. * We duplicate the type (rather than share) so the two services * can be independently type-evolved. */ 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 perf-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 readPerfTemplate(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) and * `detectSecurityAudit`: the CLI never throws; it returns a typed * detect result. */ export declare function detectPerfAudit(input: { readonly projectRoot: string; readonly sessionId: string; /** * The slice whose capsule this run audits. Slice * filename, so a caller that knows it must pass it or the probe resolves * `runPerfAudit` always did, and `peaks perf-audit detect` forwards its * long-standing `--rid` flag as of the post-verification repair round. */ readonly requestId?: string; readonly dispatchError?: unknown; readonly envelope?: unknown; }): PerfAuditDetectResult; /** * Render a PerfAuditEnvelope to the canonical audit artifact body * (markdown). Mirrors `renderSecurityAuditArtifact` in * `security-audit-service.ts` and `adaptEccEnvelopeToRdCodeReview` * in ecc-bridge.ts: produce a markdown body with all required * sections, ready to write to * `.peaks/_runtime//audit/perf-.md`. */ export declare function renderPerfAuditArtifact(env: PerfAuditEnvelope, opts: { rid: string; handoffHash: string; generatedAt: string; }): { body: string; violationsCount: number; verdict: PerfAuditVerdict; }; /** * Write the rendered audit artifact to * `.peaks/_runtime//audit/perf-.md`. * * Atomic write (tmp + rename) to avoid partial writes on crash. * Returns the absolute path on success. */ export declare function writePerfAuditArtifact(projectRoot: string, sessionId: string, rid: string, body: string): string; /** * Convenience: run `detectPerfAudit` + `renderPerfAuditArtifact` * + `writePerfAuditArtifact` in one call. * * Returns `{ detect, artifactPath, violationsCount, verdict }` or * `{ detect, artifactPath: null, ... }` when not ready. */ export declare function runPerfAudit(input: { readonly projectRoot: string; readonly sessionId: string; readonly rid: string; readonly generatedAt: string; readonly dispatchError?: unknown; readonly envelope?: unknown; }): { detect: PerfAuditDetectResult; artifactPath: string | null; violationsCount: number; verdict: PerfAuditVerdict | null; };