/** * Episodic Memory Types * * Core types for tracking work history with effort estimation. * These types enable agents to understand what work has been done, * by whom, and how much effort was involved. */ /** * Effort level for a work episode. * Ordered from least to most significant. */ export type Effort = 'trivial' | 'low' | 'medium' | 'high' | 'significant'; /** * A single unit of tracked work. * Represents something an agent did — e.g., editing files, running tests, committing. */ export interface WorkEpisode { /** Unique episode ID (UUID) */ id: string; /** Agent ID that performed this work (e.g., 'default', 'backend', 'tester') */ agentId: string; /** Terminal session prefix (first 8 chars of session ID) */ terminalPrefix: string; /** High-level action label (e.g., 'edit', 'test', 'commit', 'refactor') */ action: string; /** Human-readable summary of what was done */ summary: string; /** Files affected by this episode */ files: string[]; /** Total lines changed (added + removed), if known */ linesChanged?: number; /** ISO timestamp when the episode was recorded */ timestamp: string; /** Session ID for grouping episodes within a session */ sessionId: string; /** Estimated effort level */ effort: Effort; /** Duration in milliseconds, if tracked */ durationMs?: number; /** Number of tool calls in this episode */ toolCalls?: number; /** Related work item ID (from workitem system) */ workItemId?: string; /** Related git commit hashes */ relatedCommits?: string[]; /** Parent episode ID (for sub-tasks) */ parentEpisode?: string; } /** * Raw signals used to estimate effort. * These are collected from tool calls and timing data. */ export interface EffortSignals { /** Number of unique files touched */ fileCount: number; /** Total lines changed (added + removed) */ linesChanged: number; /** Total number of tool calls */ toolCallCount: number; /** Duration in milliseconds */ durationMs: number; /** Number of edit/write iterations on same files */ iterationCount: number; /** Complexity indicators detected */ complexityIndicators: { /** New files were created (not just edited) */ newFiles?: boolean; /** Multiple languages involved */ multiLanguage?: boolean; /** Test files were created or modified */ tests?: boolean; /** Config files were modified */ configChanges?: boolean; }; } /** * Tunable weights for effort estimation. * All weights are multipliers or divisors applied to raw signals. */ export interface EffortWeights { /** Points per file (default: 2) */ fileCountMultiplier: number; /** Lines per point (default: 50) — higher means lines matter less */ linesPerPoint: number; /** Minutes per point (default: 1) */ minutesPerPoint: number; /** Points per tool call (default: 1) */ toolCallWeight: number; } /** * Summary of effort across multiple episodes. */ export interface EffortSummary { /** Number of episodes included */ episodeCount: number; /** Maximum effort level across episodes */ totalEffort: Effort; /** Total time spent in milliseconds */ timeSpentMs: number; /** Unique agent IDs involved */ agents: string[]; /** Human-readable description */ description: string; } /** * Project-level work summary with breakdown. */ export interface ProjectWorkSummary { /** Total number of episodes */ episodeCount: number; /** Maximum effort level */ totalEffort: Effort; /** Total time spent in milliseconds */ timeSpentMs: number; /** Effort breakdown by agent */ agentBreakdown: Array<{ agentId: string; episodeCount: number; maxEffort: Effort; timeSpentMs: number; }>; /** Most frequently touched files */ topFiles: Array<{ path: string; touchCount: number; }>; /** Episodes since the last git commit */ uncommittedWork: WorkEpisode[]; } /** * Summary of work that would be at risk from a destructive operation. * Used by guardrails and rehearsal to warn agents before they destroy work. */ export interface WorkAtRisk { /** Episodes involving the affected files */ episodes: WorkEpisode[]; /** Maximum effort across at-risk episodes */ totalEffort: Effort; /** Agents who did the work (e.g., ['default (abc123)', 'backend (xyz999)']) */ agentAttribution: string[]; /** Human-readable warning message */ warningMessage: string; } /** * Persistence interface for work episodes. * Write methods may be async (for file I/O), read methods are synchronous * (read from in-memory cache). */ export interface EpisodeStore { /** Save a single episode */ save(episode: WorkEpisode): void | Promise; /** Save multiple episodes at once */ saveBatch(episodes: WorkEpisode[]): void | Promise; /** Get all episodes */ getAll(): WorkEpisode[]; /** Get episodes for specific files */ getByFiles(files: string[]): WorkEpisode[]; /** Get episodes by agent ID */ getByAgent(agentId: string): WorkEpisode[]; /** Get episodes by session ID */ getBySession(sessionId: string): WorkEpisode[]; /** Get episodes within a time range (ISO timestamps) */ getByTimeRange(start: string, end: string): WorkEpisode[]; /** Get the N most recent episodes */ getRecent(count: number): WorkEpisode[]; /** Get project work summary */ getWorkSummary(): ProjectWorkSummary; /** Get the maximum effort level across all episodes (or a subset) */ getTotalEffort(episodes?: WorkEpisode[]): Effort; /** Remove episodes older than maxAge milliseconds. Returns count removed. */ cleanup(maxAgeMs: number): number | Promise; }