Skip to content

Commit f7e984e

Browse files
committed
feat: Smart Context Preservation for Task Resumption
- Add ContextSnapshot interfaces for rich context data structures - Implement ContextSnapshotManager for persistent storage and retrieval - Create ContextTracker for active context capture during task execution - Integrate context tracking into Task class for automatic context preservation - Add context restoration logic to resumeTaskFromHistory method - Include comprehensive test suite for context tracking functionality This feature enables much more intelligent task resumption by capturing and storing rich contextual information including analyzed files, architectural insights, task decisions, and codebase knowledge, rather than relying solely on conversation history reconstruction.
1 parent 38d8edf commit f7e984e

File tree

5 files changed

+1014
-0
lines changed

5 files changed

+1014
-0
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import type { TodoItem } from "@roo-code/types"
2+
3+
/**
4+
* Represents a file that was analyzed during task execution
5+
*/
6+
export interface AnalyzedFile {
7+
/** File path relative to workspace */
8+
path: string
9+
/** Content hash to detect changes */
10+
contentHash: string
11+
/** When this file was last analyzed */
12+
lastAnalyzed: number
13+
/** Key insights discovered about this file */
14+
insights: string[]
15+
/** File size at time of analysis */
16+
size: number
17+
/** File modification time at analysis */
18+
lastModified: number
19+
}
20+
21+
/**
22+
* Represents discovered patterns or architectural insights
23+
*/
24+
export interface ArchitecturalInsight {
25+
/** Unique identifier for this insight */
26+
id: string
27+
/** Type of insight (e.g., 'pattern', 'dependency', 'structure') */
28+
type: 'pattern' | 'dependency' | 'structure' | 'convention' | 'issue'
29+
/** Human-readable description */
30+
description: string
31+
/** Files related to this insight */
32+
relatedFiles: string[]
33+
/** Confidence level (0-1) */
34+
confidence: number
35+
/** When this insight was discovered */
36+
discoveredAt: number
37+
}
38+
39+
/**
40+
* Represents the working context of a task
41+
*/
42+
export interface WorkingContext {
43+
/** Current working directory */
44+
cwd: string
45+
/** Files that have been analyzed */
46+
analyzedFiles: Map<string, AnalyzedFile>
47+
/** Architectural insights discovered */
48+
insights: ArchitecturalInsight[]
49+
/** Current todo list state */
50+
todoList?: TodoItem[]
51+
/** Key decisions made during the task */
52+
decisions: TaskDecision[]
53+
/** Important discoveries about the codebase */
54+
codebaseKnowledge: CodebaseKnowledge
55+
}
56+
57+
/**
58+
* Represents a decision made during task execution
59+
*/
60+
export interface TaskDecision {
61+
/** Unique identifier */
62+
id: string
63+
/** What decision was made */
64+
decision: string
65+
/** Why this decision was made */
66+
reasoning: string
67+
/** When the decision was made */
68+
timestamp: number
69+
/** Files affected by this decision */
70+
affectedFiles: string[]
71+
}
72+
73+
/**
74+
* Represents knowledge about the codebase structure and patterns
75+
*/
76+
export interface CodebaseKnowledge {
77+
/** Main technology stack detected */
78+
techStack: string[]
79+
/** Project structure patterns */
80+
projectStructure: {
81+
type: 'monorepo' | 'single-package' | 'multi-package'
82+
mainDirectories: string[]
83+
configFiles: string[]
84+
}
85+
/** Coding conventions discovered */
86+
conventions: {
87+
naming: string[]
88+
fileOrganization: string[]
89+
patterns: string[]
90+
}
91+
/** Dependencies and their purposes */
92+
dependencies: {
93+
name: string
94+
purpose: string
95+
files: string[]
96+
}[]
97+
}
98+
99+
/**
100+
* Complete context snapshot for a task
101+
*/
102+
export interface ContextSnapshot {
103+
/** Snapshot version for compatibility */
104+
version: string
105+
/** Task ID this snapshot belongs to */
106+
taskId: string
107+
/** When this snapshot was created */
108+
createdAt: number
109+
/** Working context at time of snapshot */
110+
context: WorkingContext
111+
/** Hash of the snapshot for integrity */
112+
hash: string
113+
}
114+
115+
/**
116+
* Options for creating context snapshots
117+
*/
118+
export interface ContextSnapshotOptions {
119+
/** Whether to include file content hashes */
120+
includeContentHashes?: boolean
121+
/** Maximum number of insights to store */
122+
maxInsights?: number
123+
/** Whether to compress the snapshot */
124+
compress?: boolean
125+
}
126+
127+
/**
128+
* Result of context snapshot operations
129+
*/
130+
export interface ContextSnapshotResult {
131+
/** Whether the operation was successful */
132+
success: boolean
133+
/** Error message if operation failed */
134+
error?: string
135+
/** Size of the snapshot in bytes */
136+
size?: number
137+
/** Number of files included */
138+
fileCount?: number
139+
/** Number of insights included */
140+
insightCount?: number
141+
}

0 commit comments

Comments
 (0)