/** * Hook Types for AgentKits Memory * * Lightweight hook system for auto-capturing Claude Code sessions. * Project-scoped storage. * * @module @agentkits/memory/hooks/types */ /** * Raw input from Claude Code hooks (via stdin JSON) */ export interface ClaudeCodeHookInput { /** Claude's session ID */ session_id?: string; /** Current working directory */ cwd?: string; /** User's prompt (UserPromptSubmit) */ prompt?: string; /** Tool name (PostToolUse) */ tool_name?: string; /** Tool input parameters (PostToolUse) */ tool_input?: unknown; /** Tool response/output (PostToolUse) */ tool_result?: unknown; /** Path to conversation transcript (Stop) */ transcript_path?: string; /** Stop reason (Stop) */ stop_reason?: string; } /** * Normalized hook input for handlers */ export interface NormalizedHookInput { /** Session ID */ sessionId: string; /** Project directory */ cwd: string; /** Project name (derived from cwd) */ project: string; /** User's prompt */ prompt?: string; /** Tool name */ toolName?: string; /** Tool input */ toolInput?: unknown; /** Tool response */ toolResponse?: unknown; /** Transcript path */ transcriptPath?: string; /** Stop reason */ stopReason?: string; /** Timestamp */ timestamp: number; } /** * Hook execution result */ export interface HookResult { /** Continue processing (always true for us) */ continue: boolean; /** Suppress output to Claude */ suppressOutput: boolean; /** Additional context to inject (SessionStart only) */ additionalContext?: string; /** Error message if failed */ error?: string; } /** * Hook-specific output for Claude Code */ export interface HookSpecificOutput { hookEventName: string; additionalContext?: string; } /** * Full hook response for Claude Code */ export interface ClaudeCodeHookResponse { continue?: boolean; suppressOutput?: boolean; hookSpecificOutput?: HookSpecificOutput; } /** * Hook event types */ export type HookEventType = 'context' | 'session-init' | 'observation' | 'summarize'; /** * Event handler interface */ export interface EventHandler { /** Execute the hook handler */ execute(input: NormalizedHookInput): Promise; } /** * Captured observation from tool usage */ export interface Observation { /** Unique ID */ id: string; /** Session ID */ sessionId: string; /** Project name */ project: string; /** Tool name */ toolName: string; /** Tool input (JSON) */ toolInput: string; /** Tool response (JSON, truncated) */ toolResponse: string; /** Working directory */ cwd: string; /** Timestamp */ timestamp: number; /** Observation type */ type: ObservationType; /** Brief title (auto-generated) */ title?: string; /** Which prompt number this observation belongs to */ promptNumber?: number; /** Files read in this observation (auto-extracted) */ filesRead?: string[]; /** Files modified in this observation (auto-extracted) */ filesModified?: string[]; /** Brief subtitle describing the action context */ subtitle?: string; /** Narrative explanation of what happened */ narrative?: string; /** Extracted facts from the observation */ facts?: string[]; /** Extracted concepts/topics */ concepts?: string[]; /** Content hash for deduplication */ contentHash?: string; /** Compressed single-sentence summary (AI-generated) */ compressedSummary?: string; /** Whether raw data has been replaced by compressed summary */ isCompressed?: boolean; } /** * Observation types based on tool usage */ export type ObservationType = 'read' | 'write' | 'execute' | 'search' | 'other'; /** * Observation intent — what the developer is trying to accomplish. * Stored as `intent:` prefixed tags in the concepts array (no schema change). */ export type ObservationIntent = 'bugfix' | 'feature' | 'refactor' | 'investigation' | 'testing' | 'documentation' | 'configuration' | 'optimization'; /** * Detect the developer's intent from tool usage context. * Pattern-matches on prompt text, tool name, and tool input. * Returns one or more intents (usually 1-2). */ export declare function detectIntent(toolName: string, toolInput: unknown, _toolResponse: unknown, prompt?: string): ObservationIntent[]; /** * Extract intent tags from a concepts array. * Filters concepts starting with 'intent:' and strips the prefix. */ export declare function extractIntents(concepts: string[]): ObservationIntent[]; /** * Structured code diff from Edit/MultiEdit operations. * Captures before/after snippets for understanding what changed. */ /** * Change type classification for code diffs */ export type DiffChangeType = 'addition' | 'deletion' | 'modification' | 'replacement'; export interface CodeDiff { /** File path that was edited */ file: string; /** Code before the change (truncated) */ before: string; /** Code after the change (truncated) */ after: string; /** Net line count change (positive=added, negative=removed) */ changeLines: number; /** Classified change type */ changeType: DiffChangeType; } /** * Classify the type of change in a diff */ export declare function classifyChangeType(before: string, after: string): DiffChangeType; /** * Extract structured code diffs from Edit/MultiEdit tool input. * Returns compact before/after snippets (truncated to 200 chars each). * For MultiEdit, captures up to 5 edits. */ export declare function extractCodeDiffs(toolName: string, toolInput: unknown): CodeDiff[]; /** * Format a code diff as a compact fact string. * Example: `DIFF src/auth.ts: "function auth(user)" → "function auth(user, opts)"` */ export declare function formatDiffFact(diff: CodeDiff): string; /** * Session record for tracking */ export interface SessionRecord { /** Database ID */ id: number; /** Claude's session ID */ sessionId: string; /** Project name */ project: string; /** First user prompt */ prompt: string; /** Session start time */ startedAt: number; /** Session end time */ endedAt?: number; /** Number of observations */ observationCount: number; /** Auto-generated summary */ summary?: string; /** Status */ status: 'active' | 'completed' | 'abandoned'; /** Parent session ID for session resume/continuation tracking */ parentSessionId?: string; } /** * User prompt record - tracks ALL prompts in a session */ export interface UserPrompt { /** Database ID */ id: number; /** Claude's session ID */ sessionId: string; /** Prompt number within session (1, 2, 3...) */ promptNumber: number; /** User's prompt text */ promptText: string; /** Timestamp */ createdAt: number; /** Content hash for deduplication */ contentHash?: string; } /** * Structured session summary */ export interface SessionSummary { /** Database ID */ id: number; /** Claude's session ID */ sessionId: string; /** Project name */ project: string; /** What user requested */ request: string; /** What was completed */ completed: string; /** Files read during session */ filesRead: string[]; /** Files modified during session */ filesModified: string[]; /** Remaining work / next steps */ nextSteps: string; /** Additional notes */ notes: string; /** Decision rationale — why key changes were made */ decisions: string[]; /** Errors encountered during session */ errors: string[]; /** Which prompt triggered this summary */ promptNumber: number; /** Timestamp */ createdAt: number; } /** * Context to inject on session start */ export interface MemoryContext { /** Recent observations */ recentObservations: Observation[]; /** Previous sessions */ previousSessions: SessionRecord[]; /** User prompts from recent sessions */ userPrompts: UserPrompt[]; /** Structured session summaries */ sessionSummaries: SessionSummary[]; /** Project-specific patterns */ patterns?: string[]; /** Recent decisions */ decisions?: string[]; /** Formatted markdown */ markdown: string; } /** * Export data format */ export interface ExportData { version: string; exportedAt: number; project: string; sessions: ExportSession[]; } /** * Exported session with all related data */ export interface ExportSession { sessionId: string; project: string; prompt: string; startedAt: number; endedAt?: number; status: string; parentSessionId?: string; observations: ExportObservation[]; prompts: ExportPrompt[]; summary?: ExportSummary; } /** * Exported observation */ export interface ExportObservation { id: string; toolName: string; timestamp: number; type: string; title?: string; subtitle?: string; narrative?: string; facts: string[]; concepts: string[]; contentHash?: string; compressedSummary?: string; isCompressed: boolean; } /** * Exported user prompt */ export interface ExportPrompt { promptNumber: number; promptText: string; createdAt: number; contentHash?: string; } /** * Exported session summary */ export interface ExportSummary { request: string; completed: string; filesRead: string[]; filesModified: string[]; nextSteps: string; notes: string; decisions: string[]; errors: string[]; } /** * Import result */ export interface ImportResult { imported: { sessions: number; observations: number; prompts: number; }; skipped: { observations: number; prompts: number; }; } /** * Context configuration for controlling what gets injected */ export interface ContextConfig { showSummaries: boolean; showPrompts: boolean; showObservations: boolean; showToolGuidance: boolean; maxSummaries: number; maxPrompts: number; maxObservations: number; } /** * Lifecycle configuration for memory decay/archival */ export interface LifecycleConfig { /** Auto-compress old observations */ autoCompress: boolean; /** Days after which to compress observations */ compressAfterDays: number; /** Auto-archive old sessions */ autoArchive: boolean; /** Days after which to archive sessions */ archiveAfterDays: number; /** Auto-delete archived sessions (opt-in, disabled by default) */ autoDelete: boolean; /** Days after which to delete archived sessions */ deleteAfterDays: number; /** Auto-vacuum after deletes */ autoVacuum: boolean; } /** Default lifecycle configuration */ export declare const DEFAULT_LIFECYCLE_CONFIG: LifecycleConfig; /** * Lifecycle task results */ export interface LifecycleResult { compressed: number; archived: number; deleted: number; vacuumed: boolean; } /** * Lifecycle statistics */ export interface LifecycleStats { totalSessions: number; activeSessions: number; completedSessions: number; archivedSessions: number; totalObservations: number; compressedObservations: number; uncompressedObservations: number; totalPrompts: number; dbSizeBytes: number; } /** Default context configuration */ export declare const DEFAULT_CONTEXT_CONFIG: ContextConfig; /** * Persistent memory settings stored in .claude/memory/settings.json */ export interface MemorySettings { /** Context injection configuration */ context: ContextConfig; /** AI provider configuration (for enrichment/compression) */ aiProvider?: import('./ai-provider.js').AIProviderConfig; } /** Default memory settings */ export declare const DEFAULT_MEMORY_SETTINGS: MemorySettings; /** * Generate observation ID */ export declare function generateObservationId(): string; /** * Compute content hash for deduplication. * Uses SHA-256 truncated to 16 hex chars (64 bits) — sufficient for dedup. * Computation: ~0.01ms. */ export declare function computeContentHash(...parts: string[]): string; /** * Get project name from cwd */ export declare function getProjectName(cwd: string): string; /** * Determine observation type from tool name */ export declare function getObservationType(toolName: string): ObservationType; /** * Extract file paths from tool input, classified as read or modified */ export declare function extractFilePaths(toolName: string, toolInput: unknown): { filesRead: string[]; filesModified: string[]; }; /** * Generate observation title from tool usage */ export declare function generateObservationTitle(toolName: string, toolInput: unknown): string; /** * Generate observation subtitle from tool usage context */ export declare function generateObservationSubtitle(toolName: string, toolInput: unknown, _toolResponse?: unknown): string; /** * Generate observation narrative from tool usage */ export declare function generateObservationNarrative(toolName: string, toolInput: unknown, _toolResponse?: unknown): string; /** * Extract facts from tool input/response */ export declare function extractFacts(toolName: string, toolInput: unknown, toolResponse: unknown): string[]; /** * Extract concepts/topics from tool usage */ export declare function extractConcepts(toolName: string, toolInput: unknown, _toolResponse?: unknown): string[]; /** * Truncate string to max length */ export declare function truncate(str: string, maxLength?: number): string; /** * Standard hook response (continue, no output) */ export declare const STANDARD_RESPONSE: ClaudeCodeHookResponse; /** * Format hook response for stdout */ export declare function formatResponse(result: HookResult): string; /** * Parse stdin input from Claude Code */ export declare function parseHookInput(stdin: string): NormalizedHookInput; //# sourceMappingURL=types.d.ts.map