/** * History Types * * Defines types for tracking certification and scan history over time. * * @module history/types */ import { z } from "zod"; import type { Severity, CertificationLevel, AgentType } from "../certification/types.js"; import type { ComplianceFramework } from "../compliance/types.js"; /** * History entry type */ export type HistoryEntryType = "certification_started" | "certification_completed" | "scan_completed" | "finding_submitted" | "finding_fixed" | "compliance_report" | "model_run" | "decision_record"; /** * Actor identity for audit trail */ export interface ActorIdentity { /** Actor type */ type: "user" | "service" | "system"; /** Unique identifier (user ID, service account name, or "system") */ id: string; /** Email address if available */ email?: string; /** Display name */ name?: string; /** IP address or hostname (for audit purposes) */ source?: string; } /** * Integrity proof for tamper-evident audit trail */ export interface IntegrityProof { /** SHA-256 hash of this entry (excluding the integrity field itself) */ hash: string; /** SHA-256 hash of the previous entry (forms hash chain) */ previousHash: string; /** Sigstore signature if signing is enabled */ signature?: string; /** Rekor transparency log index if published */ rekorLogIndex?: number; /** Rekor log ID */ rekorLogId?: string; } /** * Base history entry */ export interface BaseHistoryEntry { id: string; timestamp: string; type: HistoryEntryType; projectPath: string; certificationId?: string; /** Actor who performed this action (for audit trail) */ actor?: ActorIdentity; /** Integrity proof for tamper-evident audit trail */ integrity?: IntegrityProof; } /** * Certification started entry */ export interface CertificationStartedEntry extends BaseHistoryEntry { type: "certification_started"; agents: AgentType[]; } /** * Certification completed entry */ export interface CertificationCompletedEntry extends BaseHistoryEntry { type: "certification_completed"; certificationId: string; level: CertificationLevel; score: number; findingsCount: number; bySeverity: Record; durationMs: number; } /** * Scan completed entry */ export interface ScanCompletedEntry extends BaseHistoryEntry { type: "scan_completed"; scanners: string[]; findingsCount: number; bySeverity: Record; durationMs: number; } /** * Finding submitted entry */ export interface FindingSubmittedEntry extends BaseHistoryEntry { type: "finding_submitted"; certificationId: string; agent: AgentType; findingId: string; severity: Severity; category: string; file: string; } /** * Finding fixed entry */ export interface FindingFixedEntry extends BaseHistoryEntry { type: "finding_fixed"; findingId: string; severity: Severity; fixMethod: "autofix" | "manual"; pattern?: string; } /** * Compliance report entry */ export interface ComplianceReportEntry extends BaseHistoryEntry { type: "compliance_report"; certificationId: string; framework: ComplianceFramework; complianceScore: number; controlsTotal: number; controlsCompliant: number; controlsAtRisk: number; controlsNonCompliant: number; } /** * Model run entry (for multi-model tracking) */ export interface ModelRunEntry extends BaseHistoryEntry { type: "model_run"; certificationId: string; model: string; agent: AgentType; findingsCount: number; inputTokens: number; outputTokens: number; durationMs: number; cost?: number; } /** * Decision record entry — a tamper-evident record of an AI decision for * explainability/traceability. Large or sensitive content (prompts, * inputs, outputs) is stored as a sha256 digest plus a short summary, so * the chain proves *what was decided* without retaining raw secrets. */ export interface DecisionRecordEntry extends BaseHistoryEntry { type: "decision_record"; /** Kind of decision (e.g. tool_call, classification, generation, refusal) */ decisionType: string; /** Model that produced the decision */ model: string; /** Model version/build, if known */ modelVersion?: string; /** sha256 of the input/context that led to the decision */ inputDigest: string; /** sha256 of the prompt (if applicable) */ promptDigest?: string; /** Tools/functions invoked as part of the decision */ toolsInvoked?: string[]; /** sha256 of the output/decision */ outputDigest: string; /** Short human-readable summary of the decision */ summary?: string; /** Rationale / explanation, if captured */ rationale?: string; /** Model confidence 0-100, if available */ confidence?: number; } /** * Union of all history entry types */ export type HistoryEntry = CertificationStartedEntry | CertificationCompletedEntry | ScanCompletedEntry | FindingSubmittedEntry | FindingFixedEntry | ComplianceReportEntry | ModelRunEntry | DecisionRecordEntry; /** * History query options */ export interface HistoryQueryOptions { /** Filter by entry type */ type?: HistoryEntryType | HistoryEntryType[]; /** Filter by project path */ projectPath?: string; /** Filter by certification ID */ certificationId?: string; /** Start date (ISO string) */ startDate?: string; /** End date (ISO string) */ endDate?: string; /** Maximum number of entries to return */ limit?: number; /** Offset for pagination */ offset?: number; /** Sort order */ order?: "asc" | "desc"; } /** * History query result */ export interface HistoryQueryResult { entries: HistoryEntry[]; total: number; hasMore: boolean; } /** * Time period for trends */ export type TrendPeriod = "day" | "week" | "month" | "quarter" | "year"; /** * Trend data point */ export interface TrendDataPoint { period: string; startDate: string; endDate: string; certificationCount: number; scanCount: number; findingsTotal: number; findingsFixed: number; avgScore: number; bySeverity: Record; } /** * Trend analysis result */ export interface TrendAnalysis { projectPath: string; period: TrendPeriod; dataPoints: TrendDataPoint[]; summary: { totalCertifications: number; totalScans: number; totalFindings: number; totalFixed: number; avgScore: number; scoreChange: number; findingsChange: number; }; } /** * Zod schemas for validation */ export declare const HistoryQueryOptionsSchema: z.ZodObject<{ type: z.ZodOptional, z.ZodArray, "many">]>>; projectPath: z.ZodOptional; certificationId: z.ZodOptional; startDate: z.ZodOptional; endDate: z.ZodOptional; limit: z.ZodDefault; offset: z.ZodDefault; order: z.ZodDefault>; }, "strip", z.ZodTypeAny, { limit: number; offset: number; order: "asc" | "desc"; projectPath?: string | undefined; certificationId?: string | undefined; type?: "compliance_report" | "certification_started" | "certification_completed" | "scan_completed" | "finding_submitted" | "finding_fixed" | "model_run" | "decision_record" | ("compliance_report" | "certification_started" | "certification_completed" | "scan_completed" | "finding_submitted" | "finding_fixed" | "model_run" | "decision_record")[] | undefined; startDate?: string | undefined; endDate?: string | undefined; }, { projectPath?: string | undefined; certificationId?: string | undefined; type?: "compliance_report" | "certification_started" | "certification_completed" | "scan_completed" | "finding_submitted" | "finding_fixed" | "model_run" | "decision_record" | ("compliance_report" | "certification_started" | "certification_completed" | "scan_completed" | "finding_submitted" | "finding_fixed" | "model_run" | "decision_record")[] | undefined; limit?: number | undefined; offset?: number | undefined; order?: "asc" | "desc" | undefined; startDate?: string | undefined; endDate?: string | undefined; }>; /** * Integrity verification result for a single entry */ export interface EntryVerificationResult { /** Entry ID */ entryId: string; /** Entry timestamp */ timestamp: string; /** Whether the entry hash is valid */ hashValid: boolean; /** Whether the chain link to previous entry is valid */ chainValid: boolean; /** Whether the signature is valid (if present) */ signatureValid?: boolean; /** Rekor transparency log index (if signed) */ rekorLogIndex?: number; /** Rekor log ID (if signed) */ rekorLogId?: string; /** Failure reason if any check failed */ failureReason?: string; } /** * Full history integrity verification result */ export interface IntegrityVerificationResult { /** Project path verified */ projectPath: string; /** When verification was performed */ verifiedAt: string; /** Overall verification status */ verified: boolean; /** Total entries in history */ totalEntries: number; /** Number of entries verified */ entriesVerified: number; /** Number of entries that passed all checks */ entriesPassed: number; /** Number of entries that failed verification */ entriesFailed: number; /** Chain integrity (no gaps, all links valid) */ chainIntegrity: boolean; /** First failure found (if any) */ firstFailure?: EntryVerificationResult; /** All failures (for detailed report) */ failures: EntryVerificationResult[]; /** Genesis entry hash (first entry in chain) */ genesisHash?: string; /** Latest entry hash (head of chain) */ headHash?: string; } //# sourceMappingURL=types.d.ts.map