/** * AI-PIP Audit utilities - Pure functions for ordered, human-readable audit output * * @remarks * These functions format layer results and signals so that the **data** exposed * is self-explanatory for an external auditor: each block includes a short * explanation of what it represents, human-readable labels (e.g. TC/STC/UC, * ALLOW/WARN/BLOCK), and origin/traceability. Visual styling is not part of core; * scripts or SDK can consume this text for richer presentation. * * Supports: * - Text report (formatPipelineAudit, formatPipelineAuditFull) * - JSON report for logs/machine consumption (buildFullAuditPayload, formatPipelineAuditAsJson) * - Run identifier (createAuditRunId) and generatedAt for correlation * - Compact log entry (buildAuditLogEntry) for one-line logging */ /** Lineage entry shape used across layers */ export interface LineageEntryLike { readonly step: string; readonly timestamp: number; } /** CSL result shape for audit formatting */ export interface CSLResultLike { readonly segments: ReadonlyArray<{ readonly id: string; readonly content: string; readonly trust: { readonly value: string; }; readonly lineage?: readonly LineageEntryLike[]; }>; readonly lineage: readonly LineageEntryLike[]; readonly processingTimeMs?: number; } /** Detection-like shape for audit (pattern_type for grouping) */ export interface DetectionLike { readonly pattern_type?: string; } /** ISL result shape for audit formatting */ export interface ISLResultLike { readonly segments: ReadonlyArray<{ readonly id: string; readonly originalContent: string; readonly sanitizedContent: string; readonly trust: { readonly value: string; }; readonly sanitizationLevel: string; readonly lineage?: readonly LineageEntryLike[]; /** Optional: per-segment detections (enables "detections: N" and types in audit) */ readonly piDetection?: { readonly detections: ReadonlyArray; readonly detected?: boolean; }; }>; readonly lineage: readonly LineageEntryLike[]; readonly metadata: { readonly totalSegments: number; readonly sanitizedSegments: number; readonly processingTimeMs?: number; }; } /** ISL signal shape for audit formatting */ export interface ISLSignalLike { readonly riskScore: number; readonly hasThreats: boolean; readonly timestamp: number; readonly piDetection: { readonly detected: boolean; readonly score: number; readonly detections: ReadonlyArray; readonly patterns?: readonly string[]; }; /** Optional: strategy used (e.g. MAX_CONFIDENCE) for reproducibility */ readonly metadata?: { readonly strategy?: string; }; } /** AAL decision reason shape for audit formatting */ export interface DecisionReasonLike { readonly action: string; readonly reason: string; readonly riskScore: number; readonly threshold: number; readonly hasThreats: boolean; readonly detectionCount: number; } /** AAL remediation plan shape for audit formatting */ export interface RemediationPlanLike { readonly strategy: string; readonly goals: readonly string[]; readonly constraints: readonly string[]; readonly targetSegments: readonly string[]; readonly needsRemediation: boolean; } /** CPE result shape for audit formatting */ export interface CPEResultLike { readonly envelope: { readonly metadata: { readonly timestamp: number; readonly nonce: string; readonly protocolVersion?: string; }; readonly signature: { readonly algorithm: string; readonly value?: string; }; readonly lineage: readonly LineageEntryLike[]; }; readonly processingTimeMs?: number; } /** Run identifier and timestamp for audit correlation */ export interface AuditRunInfo { readonly runId: string; readonly generatedAt: number; readonly generatedAtIso: string; } /** Compact summary for one-line logs (action, risk, detection count) */ export interface AuditLogSummary { readonly runId: string; readonly generatedAt: number; readonly generatedAtIso: string; readonly action: string; readonly riskScore: number; readonly hasThreats: boolean; readonly detectionCount: number; } /** Options for full pipeline audit (text or JSON) */ export interface FullPipelineAuditOptions { readonly runId?: string; readonly generatedAt?: number; readonly includeCpe?: boolean; readonly title?: string; readonly sectionSeparator?: string; } /** Options for JSON audit output */ export interface PipelineAuditJsonOptions extends FullPipelineAuditOptions { readonly compact?: boolean; } /** * Creates a unique run identifier for audit correlation (e.g. logs, multiple reports). * Uses crypto.randomUUID() when available, otherwise a time-based id. */ export declare function createAuditRunId(): string; /** * Builds a compact audit entry for one-line logging (e.g. logger.info(JSON.stringify(entry))). * Lineage is not included; use buildFullAuditPayload for full traceability. */ export declare function buildAuditLogEntry(signal: ISLSignalLike, reason: DecisionReasonLike, options?: { runId?: string; generatedAt?: number; }): AuditLogSummary; /** * Builds the full pipeline audit payload (JSON-serializable) with run id, timestamp, summary for logs, and section data. * Preserves lineage in each section for traceability. Use formatPipelineAuditAsJson to get a JSON string. */ export declare function buildFullAuditPayload(csl: CSLResultLike, isl: ISLResultLike, signal: ISLSignalLike, reason: DecisionReasonLike, options?: FullPipelineAuditOptions & { remediationPlan?: RemediationPlanLike | null; cpe?: CPEResultLike | null; }): Record; /** * Formats lineage entries for audit - chronological traceability * * @param lineage - Array of lineage entries (any layer) * @returns Formatted string with short legend and chronological steps */ export declare function formatLineageForAudit(lineage: readonly LineageEntryLike[]): string; /** * Formats CSL result for audit - data self-explanatory for external auditor * * @param result - CSL result (or compatible shape) * @returns Formatted string: what this block is, data origin, trust legend, per-segment data */ export declare function formatCSLForAudit(result: CSLResultLike): string; /** * Formats ISL result for audit - data self-explanatory; per-segment detections when present * * @param result - ISL result (or compatible shape) * @returns Formatted string: what this block is, data origin, per-segment trust/level/length/detections */ export declare function formatISLForAudit(result: ISLResultLike): string; /** * Formats ISL signal for audit - data self-explanatory; risk score and detection types * * @param signal - ISL signal (or compatible shape) * @returns Formatted string: what this block is, data origin, risk score (0-1), hasThreats, detection types */ export declare function formatISLSignalForAudit(signal: ISLSignalLike): string; /** * Formats AAL decision reason and optional remediation plan for audit * * @param reason - Decision reason (or compatible shape) * @param remediationPlan - Optional remediation plan (or compatible shape) * @returns Formatted string: action (ALLOW/WARN/BLOCK), reason, thresholds, remediation plan */ export declare function formatAALForAudit(reason: DecisionReasonLike, remediationPlan?: RemediationPlanLike | null): string; /** * Formats CPE result for audit - data self-explanatory * * @param result - CPE result (or compatible shape) * @returns Formatted string: what this block is, data origin, nonce, timestamp, signature */ export declare function formatCPEForAudit(result: CPEResultLike): string; /** * Builds a full pipeline audit report (CSL → ISL → CPE) from layer results. * Accepts minimal shapes for flexibility. * Use formatPipelineAuditFull when you need ISL Signal and AAL included. * * @param csl - CSL result (or compatible shape) * @param isl - ISL result (or compatible shape) * @param cpe - CPE result (or compatible shape) * @param options - Optional title and separator; use includeSignalAndAAL to add Signal + AAL sections * @returns Single formatted string for full audit */ export declare function formatPipelineAudit(csl: CSLResultLike, isl: ISLResultLike, cpe: CPEResultLike, options?: { title?: string; sectionSeparator?: string; includeSignalAndAAL?: boolean; signal?: ISLSignalLike; aalReason?: DecisionReasonLike; remediationPlan?: RemediationPlanLike | null; }): string; /** * Full pipeline audit report (CSL → ISL → ISL Signal → AAL → optional CPE) with run id and timestamp. * Unites all layers for a single audit view. Lineage is included in each section. * * @param csl - CSL result * @param isl - ISL result * @param signal - ISL signal (for AAL) * @param aalReason - AAL decision reason * @param remediationPlan - Optional remediation plan * @param cpe - Optional CPE result (included when includeCpe is true) * @param options - runId, generatedAt, includeCpe, title, sectionSeparator * @returns Formatted string with header (runId, generatedAt) and all sections */ export declare function formatPipelineAuditFull(csl: CSLResultLike, isl: ISLResultLike, signal: ISLSignalLike, aalReason: DecisionReasonLike, remediationPlan?: RemediationPlanLike | null, cpe?: CPEResultLike | null, options?: FullPipelineAuditOptions): string; /** * Full pipeline audit as JSON string (for logs, SIEM, machine consumption). * Preserves lineage in each section. Use buildFullAuditPayload for the raw object. * * @param options.compact - If true, single-line JSON; otherwise pretty-printed * @returns JSON string of the full audit payload */ export declare function formatPipelineAuditAsJson(csl: CSLResultLike, isl: ISLResultLike, signal: ISLSignalLike, reason: DecisionReasonLike, options?: PipelineAuditJsonOptions & { remediationPlan?: RemediationPlanLike | null; cpe?: CPEResultLike | null; }): string; //# sourceMappingURL=audit.d.ts.map