/** * aidimag core types — mirrors the data model in DESIGN.md. */ export type MemoryKind = "DECISION" | "CONVENTION" | "GOTCHA" | "FAILED_APPROACH" | "ARCHITECTURE" | "INVARIANT" | "TODO_CONTEXT" | "GUARDRAIL" | "SKILL"; export type MemoryStatus = "VERIFIED" | "UNVERIFIED" | "STALE" | "REFUTED"; /** * Guardrail enforcement level (Karpathy's always/ask-first/never bucket). * Only meaningful when kind === "GUARDRAIL". */ export type GuardrailLevel = "always" | "ask-first" | "never"; export type EvidenceType = "COMMIT_REF" | "TEST_RESULT" | "EXEC_TRACE" | "STATIC_CHECK" | "HUMAN_ATTESTED" | "TICKET_REF"; export type EvidenceResult = "PASS" | "FAIL" | "UNKNOWN"; export interface Evidence { id: string; memoryId: string; type: EvidenceType; /** ref / script / assertion — interpretation depends on `type` */ payload: string; lastRun: string | null; result: EvidenceResult; /** cryptographic signature (Ed25519/SSH) over the evidence content — present when signed */ signature?: string | null; /** identity of the signer (e.g. key fingerprint or email) */ signedBy?: string | null; } export type LinkRelation = "supports" | "contradicts" | "refines"; export interface MemoryLink { fromId: string; toId: string; relation: LinkRelation; } export interface MemoryScope { /** glob-ish path patterns this memory applies to; empty = whole repo */ paths: string[]; /** optional symbol names (functions, classes) */ symbols: string[]; } export interface MemoryEntry { id: string; kind: MemoryKind; /** written as a falsifiable statement */ claim: string; scope: MemoryScope; confidence: number; status: MemoryStatus; /** * Pinned memories are exempt from time-based confidence decay (they never * demote to UNVERIFIED just from age) — but evidence failure still marks * them STALE. "Never decays" ≠ "never falsifiable". */ pinned: boolean; createdBy: string; createdAt: string; verifiedAt: string | null; supersededBy: string | null; /** last local mutation time (sync LWW anchor) */ updatedAt: string | null; grounding: Evidence[]; links: MemoryLink[]; /** enforcement level — present only when kind === "GUARDRAIL" */ guardrailLevel?: GuardrailLevel; /** * For FAILED_APPROACH memories: conditions under which the failure applies. * Prevents blocking a previously-failed solution after the underlying cause * has been resolved. Stored as opaque condition strings (e.g. feature flags, * dependency versions, architecture states). */ appliesWhen?: string[]; } export interface MemoryWriteInput { kind: MemoryKind; claim: string; paths?: string[]; symbols?: string[]; createdBy?: string; evidence?: Array<{ type: EvidenceType; payload: string; }>; /** create the memory pinned (exempt from time decay) */ pinned?: boolean; /** required when kind === "GUARDRAIL": always | ask-first | never */ guardrailLevel?: GuardrailLevel; /** * Conditions under which a FAILED_APPROACH memory applies. Lets the system warn * only when the same preconditions are present, not forever. */ appliesWhen?: string[]; /** * When true, executable evidence (STATIC_CHECK / TEST_RESULT / EXEC_TRACE) is * trusted for local verify. Default false — use for CLI human writes and * human-approved proposals only. */ trustExecutableEvidence?: boolean; } export interface MemorySearchOptions { query: string; kind?: MemoryKind; status?: MemoryStatus; /** restrict to memories scoped to (or overlapping) these paths */ paths?: string[]; /** restrict to memories scoped to (or overlapping) these symbols */ symbols?: string[]; limit?: number; includeRefuted?: boolean; } export interface MemoryStatusSummary { total: number; byStatus: Record; byKind: Partial>; /** memories exempt from time decay */ pinned?: number; dbPath: string; pendingProposals?: number; } export type ProposalStatus = "PENDING" | "APPROVED" | "REJECTED"; export interface ProposalInput { kind: MemoryKind; claim: string; paths?: string[]; symbols?: string[]; evidence?: Array<{ type: EvidenceType; payload: string; }>; /** where this proposal came from: 'commit-miner' | 'session:' | 'human' */ source: string; /** e.g. commit sha the proposal was mined from */ sourceRef?: string; /** why the source thinks this is worth remembering */ rationale?: string; /** ticket id (e.g. XXX-2100) extracted from branch/commit message */ ticketRef?: string; /** enforcement level for GUARDRAIL proposals */ guardrailLevel?: GuardrailLevel; /** conditions under which a FAILED_APPROACH proposal applies */ appliesWhen?: string[]; } export interface Proposal extends ProposalInput { id: string; createdAt: string; status: ProposalStatus; /** memory id, set when approved */ memoryId: string | null; /** last local mutation time (sync LWW anchor) */ updatedAt?: string | null; paths: string[]; symbols: string[]; evidence: Array<{ type: EvidenceType; payload: string; }>; appliesWhen?: string[]; }