k0ntext 3.7.0 → 3.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +287 -383
  2. package/dist/agent-system/timestamp-tracker.d.ts +159 -0
  3. package/dist/agent-system/timestamp-tracker.d.ts.map +1 -0
  4. package/dist/agent-system/timestamp-tracker.js +405 -0
  5. package/dist/agent-system/timestamp-tracker.js.map +1 -0
  6. package/dist/agent-system/todolist-manager.d.ts +244 -0
  7. package/dist/agent-system/todolist-manager.d.ts.map +1 -0
  8. package/dist/agent-system/todolist-manager.js +580 -0
  9. package/dist/agent-system/todolist-manager.js.map +1 -0
  10. package/dist/cli/commands/snapshot.d.ts +28 -0
  11. package/dist/cli/commands/snapshot.d.ts.map +1 -0
  12. package/dist/cli/commands/snapshot.js +408 -0
  13. package/dist/cli/commands/snapshot.js.map +1 -0
  14. package/dist/cli/version/comparator.d.ts +1 -0
  15. package/dist/cli/version/comparator.d.ts.map +1 -1
  16. package/dist/cli/version/comparator.js +1 -0
  17. package/dist/cli/version/comparator.js.map +1 -1
  18. package/dist/db/client.d.ts +5 -0
  19. package/dist/db/client.d.ts.map +1 -1
  20. package/dist/db/client.js +7 -0
  21. package/dist/db/client.js.map +1 -1
  22. package/dist/db/schema.d.ts +1 -1
  23. package/dist/db/schema.js +1 -1
  24. package/dist/services/snapshot-manager.d.ts +251 -0
  25. package/dist/services/snapshot-manager.d.ts.map +1 -0
  26. package/dist/services/snapshot-manager.js +541 -0
  27. package/dist/services/snapshot-manager.js.map +1 -0
  28. package/docs/QUICKSTART.md +1 -1
  29. package/docs/TROUBLESHOOTING.md +51 -76
  30. package/docs/plans/2026-02-11-context-engineering-enhancement.md +1402 -0
  31. package/package.json +9 -2
  32. package/src/agent-system/timestamp-tracker.ts +520 -0
  33. package/src/agent-system/todolist-manager.ts +753 -0
  34. package/src/cli/commands/snapshot.ts +471 -0
  35. package/src/cli/version/comparator.ts +1 -0
  36. package/src/db/client.ts +8 -0
  37. package/src/db/migrations/0016_add_context_system_tables.sql +38 -0
  38. package/src/db/schema.ts +1 -1
  39. package/src/services/snapshot-manager.ts +719 -0
@@ -0,0 +1,1402 @@
1
+ # Context Engineering System Enhancement Implementation Plan
2
+
3
+ > **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
4
+
5
+ **Goal:** Build a unified `.claude/` context engineering system with commands, agents, sync, and TodoList tracking for AI coding sessions.
6
+
7
+ **Architecture:** Agent-Dispatcher pattern with TodoList tracking, timestamp-aware sync, and RPI workflow orchestration.
8
+
9
+ **Tech Stack:** Node.js, TypeScript, SQLite, Handlebars, Commander.js, Inquirer, Vitest
10
+
11
+ ---
12
+
13
+ ## Executive Summary
14
+
15
+ This enhancement transforms k0ntext's **AI session interface** (`.claude/` folder) into a cohesive context engineering platform. The system will:
16
+
17
+ 1. **Add `.claude/commands/`** - Slash commands for AI to invoke during coding sessions
18
+ 2. **Enhance `.claude/agents/`** - New agents for cleanup, sync, optimization
19
+ 3. **Synchronize context files** - claude.md ↔ ai_context.md stay in sync automatically
20
+ 4. **TodoList tracking** - Session tasks survive compactions
21
+ 5. **Index-aware operations** - All agents/commands aware of indexes folder
22
+ 6. **Timestamp-aware cleanup** - Interactive file management with snapshots
23
+
24
+ ---
25
+
26
+ ## Architecture Diagram
27
+
28
+ ```
29
+ ┌─────────────────────────────────────────────────────────────────────────────┐
30
+ │ AI Coding Session Interface (.claude/) │
31
+ ├─────────────────────────────────────────────────────────────────────────────┤
32
+ │ │
33
+ │ ┌─────────────────────────────────────────────────────────────────────┐ │
34
+ │ │ Commands Layer (/command-name) │ │
35
+ │ │ /context-opt /context-sync /snapshot:create │ │
36
+ │ │ /cleanup:scan /cleanup:interactive /todo:create │ │
37
+ │ │ /dispatch-rpi /context:status /workflow:route │ │
38
+ │ └─────────────────────────────────────────────────────────────────────┘ │
39
+ │ │ │
40
+ │ ┌─────────────────────────────────────────────────────────────────────┐ │
41
+ │ │ Agents Layer (@agent-name) │ │
42
+ │ │ @context-optimizer @cleanup-agent @sync-agent │ │
43
+ │ │ @todo-manager @snapshot-manager @workflow-router │ │
44
+ │ └─────────────────────────────────────────────────────────────────────┘ │
45
+ │ │ │
46
+ │ ┌─────────────────────────────────────────────────────────────────────┐ │
47
+ │ │ Core Services Layer │ │
48
+ │ │ TodoList Manager Timestamp Tracker Context Generator │ │
49
+ │ └─────────────────────────────────────────────────────────────────────┘ │
50
+ │ │ │
51
+ │ ┌─────────────────────────────────────────────────────────────────────┐ │
52
+ │ │ Data & Context Layer │ │
53
+ │ │ .claude/context/ .claude/indexes/ .claude/plans/ │ │
54
+ │ │ claude.md ai_context.md CLAUDE.md │ │
55
+ │ │ SQLite DB File System Git History │ │
56
+ │ └─────────────────────────────────────────────────────────────────────┘ │
57
+ │ │
58
+ └─────────────────────────────────────────────────────────────────────────────┘
59
+ ```
60
+
61
+ ---
62
+
63
+ ## Phase 1: Foundation (TodoList & Timestamp Tracking)
64
+
65
+ **Objective:** Build core services that agents and commands will depend on
66
+
67
+ ### New Files to Create
68
+
69
+ **1.1 `.claude/commands/todo-create.md`**
70
+ ```yaml
71
+ ---
72
+ name: todo-create
73
+ version: "1.0.0"
74
+ displayName: "Todo Create"
75
+ description: "Create a new todo list for current session with optional tasks"
76
+ category: "session-management"
77
+ arguments:
78
+ - name: "tasks"
79
+ description: "Optional comma-separated task descriptions"
80
+ required: false
81
+ - name: "--session <name>"
82
+ description: "Session name for grouping"
83
+ required: false
84
+ examples:
85
+ - invocation: '/todo-create "Review PR #123"'
86
+ description: "Create todo list for PR review"
87
+ - invocation: '/todo-create "Refactor context system" --session v3.8.0'
88
+ description: "Create named session todo list"
89
+ ---
90
+ ```
91
+
92
+ **1.2 `.claude/commands/todo-status.md`**
93
+ ```yaml
94
+ ---
95
+ name: todo-status
96
+ version: "1.0.0"
97
+ displayName: "Todo Status"
98
+ description: "Show current session todo list with task statuses"
99
+ category: "session-management"
100
+ arguments:
101
+ - name: "--session <name>"
102
+ description: "Show specific session todo"
103
+ required: false
104
+ - name: "--format <type>"
105
+ description: "Output format (table|json|markdown)"
106
+ required: false
107
+ examples:
108
+ - invocation: '/todo-status'
109
+ description: "Show current session todos"
110
+ ---
111
+ ```
112
+
113
+ **1.3 `.claude/agents/todo-manager.md`**
114
+ ```markdown
115
+ ---
116
+ name: todo-manager
117
+ version: "1.0.0"
118
+ displayName: "Todo Manager"
119
+ description: "Agent for managing session todo lists that survive compactions"
120
+ category: "session-management"
121
+ complexity: "low"
122
+ context_budget: "~5K tokens"
123
+ capabilities:
124
+ - "todo-list-creation"
125
+ - "task-tracking"
126
+ - "session-persistence"
127
+ - "compaction-survival"
128
+ workflows:
129
+ - "session-management"
130
+ commands: ["/todo-create", "/todo-status", "/todo-update"]
131
+ examples:
132
+ - invocation: '@todo-manager "Create todo list for implementing snapshot system"'
133
+ description: "Generate structured todo list"
134
+ - invocation: '@todo-manager "Update todo: mark task 3 as complete"'
135
+ description: "Update specific task status"
136
+ ---
137
+ ```
138
+
139
+ **1.4 `src/agent-system/todolist-manager.ts`**
140
+ ```typescript
141
+ // Backend service for todo lists
142
+ export class TodoListManager {
143
+ private db: DatabaseClient;
144
+
145
+ async createList(sessionId: string, tasks: Task[]): Promise<TodoList>;
146
+ async updateTask(sessionId: string, taskId: string, status: TaskStatus): Promise<void>;
147
+ async getList(sessionId: string): Promise<TodoList>;
148
+ async exportMarkdown(sessionId: string): Promise<string>;
149
+ async importFromMarkdown(content: string): Promise<TodoList>;
150
+ async archiveSession(sessionId: string): Promise<void>;
151
+ }
152
+ ```
153
+
154
+ **1.5 `src/agent-system/timestamp-tracker.ts`**
155
+ ```typescript
156
+ // Track file timestamps for sync operations
157
+ export class TimestampTracker {
158
+ async recordSnapshot(path: string): Promise<FileTimestamp>;
159
+ async getChangedFiles(since: Date): Promise<ChangedFile[]>;
160
+ async compareTimestamps(file1: string, file2: string): Promise<TimestampDiff>;
161
+ async syncTimestampsFromGit(): Promise<void>;
162
+ }
163
+ ```
164
+
165
+ ### Files to Modify
166
+
167
+ **1.6 `src/db/schema.ts`** - Add new tables (after line 200)
168
+
169
+ ```sql
170
+ -- Schema version update
171
+ SCHEMA_VERSION = '1.6.0'
172
+
173
+ -- Add to existing schema:
174
+ CREATE TABLE IF NOT EXISTS todo_sessions (
175
+ id TEXT PRIMARY KEY,
176
+ name TEXT NOT NULL,
177
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
178
+ updated_at TEXT NOT NULL DEFAULT (datetime('now')),
179
+ parent_session TEXT, -- For linking related sessions
180
+ metadata JSON
181
+ );
182
+
183
+ CREATE TABLE IF NOT EXISTS todo_tasks (
184
+ id TEXT PRIMARY KEY,
185
+ session_id TEXT NOT NULL,
186
+ subject TEXT NOT NULL,
187
+ description TEXT,
188
+ status TEXT NOT NULL DEFAULT 'pending',
189
+ dependencies TEXT, -- JSON array of task IDs
190
+ assigned_to TEXT,
191
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
192
+ updated_at TEXT NOT NULL DEFAULT (datetime('now')),
193
+ completed_at TEXT,
194
+ FOREIGN KEY (session_id) REFERENCES todo_sessions(id) ON DELETE CASCADE
195
+ );
196
+
197
+ CREATE TABLE IF NOT EXISTS file_timestamps (
198
+ path TEXT PRIMARY KEY,
199
+ modified_time TEXT NOT NULL,
200
+ size INTEGER NOT NULL,
201
+ hash TEXT NOT NULL,
202
+ last_checked TEXT NOT NULL DEFAULT (datetime('now')),
203
+ git_commit TEXT
204
+ );
205
+
206
+ CREATE INDEX IF NOT EXISTS idx_todo_sessions_created ON todo_sessions(created_at);
207
+ CREATE INDEX IF NOT EXISTS idx_todo_tasks_session ON todo_tasks(session_id);
208
+ CREATE INDEX IF NOT EXISTS idx_todo_tasks_status ON todo_tasks(status);
209
+ CREATE INDEX IF NOT EXISTS idx_file_timestamps_checked ON file_timestamps(last_checked);
210
+ ```
211
+
212
+ **1.7 `src/db/client.ts`** - Add database methods (after line 700)
213
+
214
+ ```typescript
215
+ // TodoList operations
216
+ public createTodoSession(name: string, metadata?: Record<string, unknown>): Promise<string>;
217
+ public createTodoTask(sessionId: string, task: Task): Promise<string>;
218
+ public updateTodoTask(taskId: string, updates: Partial<Task>): Promise<void>;
219
+ public getTodoSession(sessionId: string): Promise<TodoSession>;
220
+ public getCurrentTodoSession(): Promise<TodoSession | null>;
221
+ public getTodoTasks(sessionId: string): Promise<Task[]>;
222
+ public getPendingTodos(sessionId: string): Promise<Task[]>;
223
+
224
+ // Timestamp operations
225
+ public recordTimestamp(path: string): Promise<void>;
226
+ public batchRecordTimestamps(paths: string[]): Promise<void>;
227
+ public getChangedFiles(since: Date): Promise<string[]>;
228
+ public getFileTimestamp(path: string): Promise<FileTimestamp | null>;
229
+ public syncTimestampsFromGit(): Promise<void>;
230
+ ```
231
+
232
+ **1.8 `tests/agent-system/todolist-manager.test.ts`** - Test file
233
+
234
+ **1.9 `tests/agent-system/timestamp-tracker.test.ts`** - Test file
235
+
236
+ ---
237
+
238
+ ## Phase 2: Context File Commands & Agents
239
+
240
+ **Objective:** Dedicated commands and agents for claude.md and ai_context.md with fixed structure and auto-sync
241
+
242
+ ### New Files to Create
243
+
244
+ **2.1 `.claude/commands/context-opt.md`**
245
+ ```yaml
246
+ ---
247
+ name: context-opt
248
+ version: "1.0.0"
249
+ displayName: "Context Optimize"
250
+ description: "Analyze and optimize context files (claude.md, ai_context.md)"
251
+ category: "context-management"
252
+ arguments:
253
+ - name: "--analyze"
254
+ description: "Analyze current context state without changes"
255
+ action: "store_true"
256
+ - name: "--generate"
257
+ description: "Regenerate context files from database"
258
+ action: "store_true"
259
+ - name: "--sync"
260
+ description: "Sync claude.md and ai_context.md"
261
+ action: "store_true"
262
+ - name: "--workflow <name>"
263
+ description: "Optimize for specific workflow"
264
+ required: false
265
+ examples:
266
+ - invocation: '/context-opt --analyze'
267
+ description: "Check context health"
268
+ - invocation: '/context-opt --generate --sync'
269
+ description: "Regenerate and sync both context files"
270
+ ---
271
+ ```
272
+
273
+ **2.2 `.claude/commands/context-sync.md`**
274
+ ```yaml
275
+ ---
276
+ name: context-sync
277
+ version: "1.0.0"
278
+ displayName: "Context Sync"
279
+ description: "Bidirectional sync between claude.md and ai_context.md"
280
+ category: "context-management"
281
+ arguments:
282
+ - name: "--to <target>"
283
+ description: "Sync target: claude|ai|both"
284
+ required: false
285
+ - name: "--force"
286
+ description: "Sync even with conflicts"
287
+ action: "store_true"
288
+ - name: "--resolve <strategy>"
289
+ description: "Conflict resolution: newer|older|merge"
290
+ required: false
291
+ examples:
292
+ - invocation: '/context-sync --to both'
293
+ description: "Sync both context files"
294
+ ---
295
+ ```
296
+
297
+ **2.3 `.claude/commands/context-status.md`**
298
+ ```yaml
299
+ ---
300
+ name: context-status
301
+ version: "1.0.0"
302
+ displayName: "Context Status"
303
+ description: "Check sync status between claude.md and ai_context.md"
304
+ category: "context-management"
305
+ arguments:
306
+ - name: "--detailed"
307
+ description: "Show detailed diff"
308
+ action: "store_true"
309
+ - name: "--json"
310
+ description: "Output as JSON"
311
+ action: "store_true"
312
+ examples:
313
+ - invocation: '/context-status'
314
+ description: "Check if context files are in sync"
315
+ ---
316
+ ```
317
+
318
+ **2.4 `.claude/commands/context-diff.md`**
319
+ ```yaml
320
+ ---
321
+ name: context-diff
322
+ version: "1.0.0"
323
+ displayName: "Context Diff"
324
+ description: "Show differences between context files"
325
+ category: "context-management"
326
+ arguments:
327
+ - name: "--json"
328
+ description: "Output as JSON"
329
+ action: "store_true"
330
+ examples:
331
+ - invocation: '/context-diff'
332
+ description: "Show unified diff of context files"
333
+ ---
334
+ ```
335
+
336
+ **2.5 `.claude/agents/context-optimizer.md`**
337
+ ```markdown
338
+ ---
339
+ name: context-optimizer
340
+ version: "1.0.0"
341
+ displayName: "Context Optimizer"
342
+ description: "Agent for analyzing and optimizing context files with index-awareness"
343
+ category: "context-management"
344
+ complexity: "medium"
345
+ context_budget: "~15K tokens"
346
+ capabilities:
347
+ - "context-analysis"
348
+ - "redundancy-detection"
349
+ - "index-awareness"
350
+ - "recent-changes-detection"
351
+ - "optimization-recommendations"
352
+ workflows:
353
+ - "context-management"
354
+ - "documentation-optimization"
355
+ commands: ["/context-opt", "/context-sync", "/context-status"]
356
+ examples:
357
+ - invocation: '@context-optimizer "Analyze and optimize current context"'
358
+ description: "Full context analysis and optimization"
359
+ - invocation: '@context-optimizer "Sync context files and resolve conflicts"'
360
+ description: "Bidirectional sync with conflict resolution"
361
+ ---
362
+ ```
363
+
364
+ **2.6 `.claude/agents/context-sync-agent.md`**
365
+ ```markdown
366
+ ---
367
+ name: context-sync-agent
368
+ version: "1.0.0"
369
+ displayName: "Context Sync Agent"
370
+ description: "Specialized agent for bidirectional sync between claude.md and ai_context.md"
371
+ category: "context-management"
372
+ complexity: "medium"
373
+ context_budget: "~10K tokens"
374
+ capabilities:
375
+ - "bidirectional-sync"
376
+ - "conflict-detection"
377
+ - "timestamp-awareness"
378
+ - "merge-resolution"
379
+ - "backup-creation"
380
+ workflows:
381
+ - "context-management"
382
+ - "synchronization"
383
+ commands: ["/context-sync", "/context-diff", "/context-status"]
384
+ examples:
385
+ - invocation: '@context-sync-agent "Sync all context files"'
386
+ description: "Full bidirectional sync"
387
+ - invocation: '@context-sync-agent "Resolve conflicts in context files"'
388
+ description: "Detect and merge divergent changes"
389
+ ---
390
+ ```
391
+
392
+ **2.7 `src/context/generator.ts`**
393
+ ```typescript
394
+ // Generate context files from database + indexes
395
+ export class ContextGenerator {
396
+ constructor(private db: DatabaseClient, private projectRoot: string) {}
397
+
398
+ async generateClaudeMD(): Promise<string>;
399
+ async generateAIContextMD(): Promise<string>;
400
+ async getIndexBasedContext(workflow?: string): Promise<ContextData>;
401
+ async getRecentChanges(since?: Date): Promise<RecentChanges>;
402
+ private generateQuickReference(data: ContextData): string;
403
+ private generateRecentChanges(since?: Date): Promise<string>;
404
+ private generateIndexBasedLookup(data: ContextData): Promise<string>;
405
+ }
406
+ ```
407
+
408
+ **2.8 `src/context/sync-manager.ts`**
409
+ ```typescript
410
+ // Bidirectional sync between claude.md and ai_context.md
411
+ export class ContextSyncManager {
412
+ constructor(
413
+ private db: DatabaseClient,
414
+ private projectRoot: string,
415
+ private timestampTracker: TimestampTracker
416
+ ) {}
417
+
418
+ async syncToAIContext(): Promise<SyncResult>;
419
+ async syncToClaudeMD(): Promise<SyncResult>;
420
+ async syncBoth(): Promise<SyncResult>;
421
+ async detectDivergence(): Promise<DivergenceReport>;
422
+ async resolveConflict(strategy: ConflictStrategy): Promise<void>;
423
+ async createBackup(): Promise<string>;
424
+ }
425
+ ```
426
+
427
+ **2.9 `src/context/types.ts`**
428
+ ```typescript
429
+ export interface ContextData {
430
+ project: ProjectInfo;
431
+ techStack: TechStackInfo;
432
+ architecture: ArchitectureInfo;
433
+ workflows: WorkflowInfo[];
434
+ commands: CommandInfo[];
435
+ recentChanges: RecentChanges;
436
+ indexes: IndexInfo;
437
+ }
438
+
439
+ export interface RecentChanges {
440
+ commits: CommitInfo[];
441
+ uncommitted: FileChange[];
442
+ lastSync: Date;
443
+ }
444
+
445
+ export interface SyncResult {
446
+ success: boolean;
447
+ filesChanged: string[];
448
+ conflicts: Conflict[];
449
+ backupCreated?: string;
450
+ }
451
+ ```
452
+
453
+ **2.10 `src/context/template.ts`** - Handlebars template for context files
454
+
455
+ **2.11 `tests/context/generator.test.ts`** - Test file
456
+
457
+ **2.12 `tests/context/sync-manager.test.ts`** - Test file
458
+
459
+ ---
460
+
461
+ ## Phase 3: Snapshots & Cleanup Commands
462
+
463
+ **Objective:** Timestamp-aware snapshot system with interactive cleanup agent
464
+
465
+ ### New Files to Create
466
+
467
+ **3.1 `.claude/commands/snapshot-create.md`**
468
+ ```yaml
469
+ ---
470
+ name: snapshot-create
471
+ version: "1.0.0"
472
+ displayName: "Snapshot Create"
473
+ description: "Create a timestamped snapshot of context files and directories"
474
+ category: "snapshot-management"
475
+ arguments:
476
+ - name: "<name>"
477
+ description: "Snapshot name/description"
478
+ required: true
479
+ - name: "--paths <paths>"
480
+ description: "Paths to include (comma-separated, defaults: .claude/ context/)"
481
+ required: false
482
+ - name: "--tag <tags>"
483
+ description: "Tags to add (comma-separated)"
484
+ required: false
485
+ examples:
486
+ - invocation: '/snapshot-create "Before refactoring"'
487
+ description: "Create snapshot before major work"
488
+ - invocation: '/snapshot-create "Weekly backup" --tag weekly,manual'
489
+ description: "Create tagged snapshot"
490
+ ---
491
+ ```
492
+
493
+ **3.2 `.claude/commands/snapshot-restore.md`**
494
+ ```yaml
495
+ ---
496
+ name: snapshot-restore
497
+ version: "1.0.0"
498
+ displayName: "Snapshot Restore"
499
+ description: "Restore context files and directories from a snapshot"
500
+ category: "snapshot-management"
501
+ arguments:
502
+ - name: "<id>"
503
+ description: "Snapshot ID, name, or partial match"
504
+ required: true
505
+ - name: "--dry-run"
506
+ description: "Show what would be restored"
507
+ action: "store_true"
508
+ - name: "--paths <paths>"
509
+ description: "Only restore specific paths"
510
+ required: false
511
+ examples:
512
+ - invocation: '/snapshot-restore "Before refactoring"'
513
+ description: "Restore by name"
514
+ - invocation: '/snapshot-restore snap-abc123 --dry-run'
515
+ description: "Preview restoration"
516
+ ---
517
+ ```
518
+
519
+ **3.3 `.claude/commands/snapshot-list.md`**
520
+ ```yaml
521
+ ---
522
+ name: snapshot-list
523
+ version: "1.0.0"
524
+ displayName: "Snapshot List"
525
+ description: "List all available snapshots with filtering options"
526
+ category: "snapshot-management"
527
+ arguments:
528
+ - name: "--tag <tag>"
529
+ description: "Filter by tag"
530
+ required: false
531
+ - name: "--since <date>"
532
+ description: "Filter snapshots created after date"
533
+ required: false
534
+ - name: "--limit <n>"
535
+ description: "Limit results"
536
+ required: false
537
+ - name: "--json"
538
+ description: "Output as JSON"
539
+ action: "store_true"
540
+ examples:
541
+ - invocation: '/snapshot-list --tag weekly --limit 5'
542
+ description: "List recent weekly snapshots"
543
+ ---
544
+ ```
545
+
546
+ **3.4 `.claude/commands/snapshot-diff.md`**
547
+ ```yaml
548
+ ---
549
+ name: snapshot-diff
550
+ version: "1.0.0"
551
+ displayName: "Snapshot Diff"
552
+ description: "Compare two snapshots to see changes"
553
+ category: "snapshot-management"
554
+ arguments:
555
+ - name: "<id1>"
556
+ description: "First snapshot"
557
+ required: true
558
+ - name: "<id2>"
559
+ description: "Second snapshot"
560
+ required: true
561
+ examples:
562
+ - invocation: '/snapshot-diff "Before" "After"'
563
+ description: "Compare by name match"
564
+ ---
565
+ ```
566
+
567
+ **3.5 `.claude/commands/cleanup-scan.md`**
568
+ ```yaml
569
+ ---
570
+ name: cleanup-scan
571
+ version: "1.0.0"
572
+ displayName: "Cleanup Scan"
573
+ description: "Scan for files that can be cleaned up (snapshots, docs, contexts)"
574
+ category: "maintenance"
575
+ arguments:
576
+ - name: "--area <name>"
577
+ description: "Focus on: snapshots|docs|contexts|all"
578
+ required: false
579
+ - name: "--older-than <days>"
580
+ description: "Only show items older than N days"
581
+ required: false
582
+ - name: "--larger-than <mb>"
583
+ description: "Only show items larger than N MB"
584
+ required: false
585
+ examples:
586
+ - invocation: '/cleanup-scan --area snapshots --older-than 30'
587
+ description: "Find old snapshots to clean"
588
+ ---
589
+ ```
590
+
591
+ **3.6 `.claude/commands/cleanup-interactive.md`**
592
+ ```yaml
593
+ ---
594
+ name: cleanup-interactive
595
+ version: "1.0.0"
596
+ displayName: "Cleanup Interactive"
597
+ description: "Interactive cleanup with prompts and snapshot backup"
598
+ category: "maintenance"
599
+ arguments:
600
+ - name: "--snapshot-before"
601
+ description: "Create snapshot before cleanup"
602
+ action: "store_true"
603
+ - name: "--yes"
604
+ description: "Auto-confirm all prompts"
605
+ action: "store_true"
606
+ examples:
607
+ - invocation: '/cleanup-interactive --snapshot-before'
608
+ description: "Interactive cleanup with backup"
609
+ ---
610
+ ```
611
+
612
+ **3.7 `.claude/agents/snapshot-manager.md`**
613
+ ```markdown
614
+ ---
615
+ name: snapshot-manager
616
+ version: "1.0.0"
617
+ displayName: "Snapshot Manager"
618
+ description: "Agent for managing context file snapshots with timestamp awareness"
619
+ category: "snapshot-management"
620
+ complexity: "medium"
621
+ context_budget: "~10K tokens"
622
+ capabilities:
623
+ - "snapshot-creation"
624
+ - "snapshot-restoration"
625
+ - "snapshot-comparison"
626
+ - "retention-policy"
627
+ - "diff-generation"
628
+ workflows:
629
+ - "snapshot-management"
630
+ - "backup-restore"
631
+ commands: ["/snapshot-create", "/snapshot-restore", "/snapshot-list", "/snapshot-diff"]
632
+ examples:
633
+ - invocation: '@snapshot-manager "Create snapshot before major refactoring"'
634
+ description: "Snapshot current state"
635
+ - invocation: '@snapshot-manager "Compare current state with last week"'
636
+ description: "Diff snapshots for change analysis"
637
+ ---
638
+ ```
639
+
640
+ **3.8 `.claude/agents/cleanup-agent.md`**
641
+ ```markdown
642
+ ---
643
+ name: cleanup-agent
644
+ version: "1.0.0"
645
+ displayName: "Cleanup Agent"
646
+ description: "Interactive cleanup agent for snapshots, docs, and contexts with timestamp awareness"
647
+ category: "maintenance"
648
+ complexity: "medium"
649
+ context_budget: "~15K tokens"
650
+ capabilities:
651
+ - "timestamp-aware-scanning"
652
+ - "interactive-prompts"
653
+ - "snapshot-backup"
654
+ - "retention-policy"
655
+ - "size-analysis"
656
+ - "orphaned-file-detection"
657
+ workflows:
658
+ - "maintenance"
659
+ - "cleanup"
660
+ commands: ["/cleanup-scan", "/cleanup-interactive"]
661
+ examples:
662
+ - invocation: '@cleanup-agent "Scan and clean old snapshots"'
663
+ description: "Find and remove old snapshots"
664
+ - invocation: '@cleanup-agent "Clean up orphaned docs with backup"'
665
+ description: "Interactive docs cleanup with safety"
666
+ ---
667
+ ```
668
+
669
+ **3.9 `src/snapshots/manager.ts`**
670
+ ```typescript
671
+ export class SnapshotManager {
672
+ constructor(private db: DatabaseClient, private projectRoot: string) {}
673
+
674
+ async createSnapshot(name: string, options: SnapshotOptions): Promise<Snapshot>;
675
+ async restoreSnapshot(id: string, options: RestoreOptions): Promise<RestoreResult>;
676
+ async listSnapshots(filter?: SnapshotFilter): Promise<Snapshot[]>;
677
+ async diffSnapshots(id1: string, id2: string): Promise<SnapshotDiff>;
678
+ async deleteSnapshot(id: string): Promise<void>;
679
+ async autoCleanup(policy: RetentionPolicy): Promise<CleanupResult>;
680
+ async getSnapshotSize(id: string): Promise<number>;
681
+ }
682
+ ```
683
+
684
+ **3.10 `tests/snapshots/manager.test.ts`** - Test file
685
+
686
+ **3.11 `tests/cleanup/agent.test.ts`** - Test file
687
+
688
+ ---
689
+
690
+ ## Phase 4: Cross-Tool Sync Agent
691
+
692
+ **Objective:** Sync context to all AI tools with conflict resolution
693
+
694
+ ### New Files to Create
695
+
696
+ **4.1 `.claude/commands/cross-tool-sync.md`**
697
+ ```yaml
698
+ ---
699
+ name: cross-tool-sync
700
+ version: "1.0.0"
701
+ displayName: "Cross-Tool Sync"
702
+ description: "Synchronize context changes to all AI tool configs (Copilot, Cursor, Cline, etc.)"
703
+ category: "synchronization"
704
+ arguments:
705
+ - name: "--to <tools>"
706
+ description: "Target tools: copilot,cursor,cline,windsurf,aider,continue,gemini"
707
+ required: false
708
+ - name: "--from <source>"
709
+ description: "Source: claude|ai|both"
710
+ required: false
711
+ - name: "--check"
712
+ description: "Only check for conflicts, don't sync"
713
+ action: "store_true"
714
+ examples:
715
+ - invocation: '/cross-tool-sync --to copilot,cursor'
716
+ description: "Sync to specific tools"
717
+ ---
718
+ ```
719
+
720
+ **4.2 `.claude/agents/cross-tool-sync-agent.md`**
721
+ ```markdown
722
+ ---
723
+ name: cross-tool-sync-agent
724
+ version: "1.0.0"
725
+ displayName: "Cross-Tool Sync Agent"
726
+ description: "Propagate context changes to all AI tool configurations with conflict resolution"
727
+ category: "synchronization"
728
+ complexity: "high"
729
+ context_budget: "~20K tokens"
730
+ capabilities:
731
+ - "multi-tool-sync"
732
+ - "adapter-management"
733
+ - "conflict-resolution"
734
+ - "tool-config-detection"
735
+ - "backup-creation"
736
+ workflows:
737
+ - "synchronization"
738
+ - "cross-tool-management"
739
+ commands: ["/cross-tool-sync"]
740
+ examples:
741
+ - invocation: '@cross-tool-sync-agent "Sync latest context to all tools"'
742
+ description: "Full cross-tool synchronization"
743
+ - invocation: '@cross-tool-sync-agent "Check and resolve cross-tool conflicts"'
744
+ description: "Conflict detection and resolution"
745
+ ---
746
+ ```
747
+
748
+ **4.3 `src/sync/cross-tool-engine.ts`**
749
+ ```typescript
750
+ // Bidirectional sync across all AI tools
751
+ export class CrossToolSyncEngine {
752
+ private adapters: Map<string, ContextAdapter>;
753
+
754
+ registerAdapter(tool: string, adapter: ContextAdapter): void;
755
+ async syncTo(targets: string[]): Promise<SyncResult[]>;
756
+ async detectConflicts(): Promise<ConflictInfo[]>;
757
+ async resolveConflicts(resolutions: ConflictResolution[]): Promise<void>;
758
+ }
759
+
760
+ export interface ContextAdapter {
761
+ toolName: string;
762
+ configPaths: string[];
763
+ readContext(): Promise<string>;
764
+ writeContext(content: string): Promise<void>;
765
+ detectCustomChanges(): Promise<Change[]>;
766
+ }
767
+ ```
768
+
769
+ **4.4 `src/sync/adapters/claude-code.ts`** - Claude Code adapter
770
+
771
+ **4.5 `src/sync/adapters/copilot.ts`** - GitHub Copilot adapter
772
+
773
+ **4.6 `src/sync/adapters/cursor.ts`** - Cursor adapter
774
+
775
+ **4.7 `src/sync/adapters/cline.ts`** - Cline adapter
776
+
777
+ **4.8 `src/sync/adapters/windsurf.ts`** - Windsurf adapter
778
+
779
+ **4.9 `src/sync/adapters/aider.ts`** - Aider adapter
780
+
781
+ **4.10 `src/sync/adapters/gemini.ts`** - Gemini adapter
782
+
783
+ **4.11 `src/sync/conflict-resolver.ts`**
784
+ ```typescript
785
+ export class ConflictResolver {
786
+ async resolve(conflict: ConflictInfo, strategy: ResolveStrategy): Promise<ResolvedContent>;
787
+ async merge(contents: string[], strategies: MergeStrategy[]): Promise<string>;
788
+ }
789
+ ```
790
+
791
+ **4.12 `tests/sync/cross-tool-engine.test.ts`** - Test file
792
+
793
+ ---
794
+
795
+ ## Phase 5: Integration & RPI Dispatch
796
+
797
+ **Objective:** Auto-invocation hooks and parallel RPI agent dispatcher
798
+
799
+ ### New Files to Create
800
+
801
+ **5.1 `.claude/commands/dispatch-rpi.md`**
802
+ ```yaml
803
+ ---
804
+ name: dispatch-rpi
805
+ version: "1.0.0"
806
+ displayName: "Dispatch RPI"
807
+ description: "Dispatch up to 6 parallel RPI workflow agents (research/plan/implement)"
808
+ category: "agent-orchestration"
809
+ arguments:
810
+ - name: "--workflow <name>"
811
+ description: "RPI workflow to execute"
812
+ required: true
813
+ - name: "--parallel <n>"
814
+ description: "Number of parallel agents (1-6, default: 6)"
815
+ required: false
816
+ - name: "--tasks <tasks>"
817
+ description: "Comma-separated task descriptions"
818
+ required: false
819
+ examples:
820
+ - invocation: '/dispatch-rpi --workflow context-engineering --parallel 6'
821
+ description: "Full parallel RPI workflow"
822
+ - invocation: '/dispatch-rpi --workflow cleanup --parallel 3'
823
+ description: "Focused parallel dispatch"
824
+ ---
825
+ ```
826
+
827
+ **5.2 `.claude/commands/workflow-route.md`**
828
+ ```yaml
829
+ ---
830
+ name: workflow-route
831
+ version: "1.0.0"
832
+ displayName: "Workflow Route"
833
+ description: "Route commands based on workflow context with automatic file detection"
834
+ category: "navigation"
835
+ arguments:
836
+ - name: "<file>"
837
+ description: "File path to detect workflow for"
838
+ required: true
839
+ - name: "--list"
840
+ description: "List all workflow mappings"
841
+ action: "store_true"
842
+ examples:
843
+ - invocation: '/workflow-route src/db/schema.ts'
844
+ description: "Detect workflow and show relevant commands"
845
+ - invocation: '/workflow-route --list'
846
+ description: "Show all workflow-to-command mappings"
847
+ ---
848
+ ```
849
+
850
+ **5.3 `.claude/agents/rpi-dispatcher.md`**
851
+ ```markdown
852
+ ---
853
+ name: rpi-dispatcher
854
+ version: "1.0.0"
855
+ displayName: "RPI Dispatcher"
856
+ description: "Dispatch up to 6 parallel RPI workflow agents with consolidated results"
857
+ category: "agent-orchestration"
858
+ complexity: "high"
859
+ context_budget: "~25K tokens"
860
+ capabilities:
861
+ - "parallel-execution"
862
+ - "result-consolidation"
863
+ - "todolist-integration"
864
+ - "workflow-routing"
865
+ - "session-management"
866
+ workflows:
867
+ - "rpi-workflow"
868
+ - "parallel-execution"
869
+ commands: ["/dispatch-rpi", "/workflow-route"]
870
+ examples:
871
+ - invocation: '@rpi-dispatcher "Research and plan context sync system"'
872
+ description: "Parallel research and planning"
873
+ - invocation: '@rpi-dispatcher "Full RPI cycle: research→plan→implement"'
874
+ description: "Complete RPI workflow with 6 parallel agents"
875
+ ---
876
+ ```
877
+
878
+ **5.4 `.claude/agents/workflow-router.md`**
879
+ ```markdown
880
+ ---
881
+ name: workflow-router
882
+ version: "1.0.0"
883
+ displayName: "Workflow Router"
884
+ description: "Route commands based on workflow context and index awareness"
885
+ category: "navigation"
886
+ complexity: "medium"
887
+ context_budget: "~8K tokens"
888
+ capabilities:
889
+ - "workflow-detection"
890
+ - "index-awareness"
891
+ - "command-routing"
892
+ - "file-categorization"
893
+ workflows:
894
+ - "navigation"
895
+ - "context-lookup"
896
+ commands: ["/workflow-route"]
897
+ examples:
898
+ - invocation: '@workflow-router "What workflow handles database schema?"'
899
+ description: "Route question to correct workflow"
900
+ - invocation: '@workflow-router "Show me all workflow commands"'
901
+ description: "Display workflow-command mappings"
902
+ ---
903
+ ```
904
+
905
+ **5.5 `src/agent-system/dispatcher.ts`**
906
+ ```typescript
907
+ // Parallel agent dispatcher (up to 6 concurrent)
908
+ export class AgentDispatcher {
909
+ private maxConcurrent: number = 6;
910
+ private activeAgents: Map<string, Agent>;
911
+
912
+ async dispatch(agents: AgentConfig[]): Promise<AgentResult[]>;
913
+ async dispatchRPI(workflow: string, options: RPIOptions): Promise<RPIResult>;
914
+ private createTodoList(workflow: string, tasks: string[]): Promise<string>;
915
+ private consolidateResults(results: AgentResult[]): Promise<ConsolidatedResult>;
916
+ }
917
+ ```
918
+
919
+ **5.6 `src/integration/workflow-router.ts`**
920
+ ```typescript
921
+ // Route commands based on workflow context
922
+ export class WorkflowRouter {
923
+ async detectWorkflow(filePath: string): Promise<string>;
924
+ async routeCommand(command: string, context: WorkflowContext): Promise<RouteResult>;
925
+ async getWorkflowCommands(workflow: string): Promise<string[]>;
926
+ async listAllWorkflows(): Promise<WorkflowMapping[]>;
927
+ }
928
+ ```
929
+
930
+ **5.7 `tests/agent-system/dispatcher.test.ts`** - Test file
931
+
932
+ **5.8 `tests/integration/workflow-router.test.ts`** - Test file
933
+
934
+ ---
935
+
936
+ ## Database Migration
937
+
938
+ **File:** `src/db/migrations/0016_add_context_system_tables.sql`
939
+
940
+ ```sql
941
+ -- Migration 0016: Context System and TodoList Support
942
+ -- From: 1.5.0
943
+ -- To: 1.6.0
944
+
945
+ -- Todo sessions (for tracking across compactions)
946
+ CREATE TABLE IF NOT EXISTS todo_sessions (
947
+ id TEXT PRIMARY KEY,
948
+ name TEXT NOT NULL,
949
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
950
+ updated_at TEXT NOT NULL DEFAULT (datetime('now')),
951
+ parent_session TEXT,
952
+ metadata JSON
953
+ );
954
+
955
+ -- Todo tasks
956
+ CREATE TABLE IF NOT EXISTS todo_tasks (
957
+ id TEXT PRIMARY KEY,
958
+ session_id TEXT NOT NULL,
959
+ subject TEXT NOT NULL,
960
+ description TEXT,
961
+ status TEXT NOT NULL DEFAULT 'pending',
962
+ dependencies TEXT,
963
+ assigned_to TEXT,
964
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
965
+ updated_at TEXT NOT NULL DEFAULT (datetime('now')),
966
+ completed_at TEXT,
967
+ FOREIGN KEY (session_id) REFERENCES todo_sessions(id) ON DELETE CASCADE
968
+ );
969
+
970
+ -- Snapshots for context files
971
+ CREATE TABLE IF NOT EXISTS snapshots (
972
+ id TEXT PRIMARY KEY,
973
+ name TEXT NOT NULL,
974
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
975
+ file_hashes TEXT NOT NULL,
976
+ metadata JSON,
977
+ tags TEXT
978
+ );
979
+
980
+ -- File timestamps for sync tracking
981
+ CREATE TABLE IF NOT EXISTS file_timestamps (
982
+ path TEXT PRIMARY KEY,
983
+ modified_time TEXT NOT NULL,
984
+ size INTEGER NOT NULL,
985
+ hash TEXT NOT NULL,
986
+ last_checked TEXT NOT NULL DEFAULT (datetime('now')),
987
+ git_commit TEXT
988
+ );
989
+
990
+ -- Cross-tool sync state
991
+ CREATE TABLE IF NOT EXISTS cross_tool_sync_state (
992
+ tool TEXT PRIMARY KEY,
993
+ context_path TEXT NOT NULL,
994
+ last_synced TEXT,
995
+ last_hash TEXT,
996
+ last_sync_status TEXT,
997
+ sync_count INTEGER DEFAULT 0,
998
+ conflict_count INTEGER DEFAULT 0
999
+ );
1000
+
1001
+ -- Indexes
1002
+ CREATE INDEX IF NOT EXISTS idx_snapshots_created ON snapshots(created_at);
1003
+ CREATE INDEX IF NOT EXISTS idx_snapshots_tags ON snapshots(tags);
1004
+ CREATE INDEX IF NOT EXISTS idx_todo_sessions_created ON todo_sessions(created_at);
1005
+ CREATE INDEX IF NOT EXISTS idx_todo_tasks_session ON todo_tasks(session_id);
1006
+ CREATE INDEX IF NOT EXISTS idx_todo_tasks_status ON todo_tasks(status);
1007
+ CREATE INDEX IF NOT EXISTS idx_file_timestamps_checked ON file_timestamps(last_checked);
1008
+ ```
1009
+
1010
+ ---
1011
+
1012
+ ## Fixed Structure for claude.md / ai_context.md
1013
+
1014
+ Both files will follow this template structure:
1015
+
1016
+ ```markdown
1017
+ # {Project Name} - AI Context
1018
+
1019
+ > **Generated by k0ntext v{version}**
1020
+ > **Last Updated:** {timestamp}
1021
+ > **Sync Status:** {sync_status}
1022
+
1023
+ ---
1024
+
1025
+ ## Quick Reference
1026
+
1027
+ **Platform:** {platform_description}
1028
+ **Tech Stack:** {primary_technologies}
1029
+ **Repository:** {repo_url}
1030
+ **Status:** {status}
1031
+
1032
+ ---
1033
+
1034
+ ## Essential Commands
1035
+
1036
+ {commands_table}
1037
+
1038
+ ---
1039
+
1040
+ ## Project Identity
1041
+
1042
+ {project_details}
1043
+
1044
+ ---
1045
+
1046
+ ## Recent Changes
1047
+
1048
+ > **Auto-generated from git commits and uncommitted changes**
1049
+
1050
+ ### Latest Commits (Last 7)
1051
+
1052
+ {recent_commits}
1053
+
1054
+ ### Uncommitted Changes
1055
+
1056
+ {uncommitted_changes}
1057
+
1058
+ ---
1059
+
1060
+ ## Architecture
1061
+
1062
+ {architecture_overview}
1063
+
1064
+ ---
1065
+
1066
+ ## Index-Based Context Lookup
1067
+
1068
+ ### Workflows ({workflow_count})
1069
+
1070
+ {workflow_index}
1071
+
1072
+ ### Code Domains ({code_domain_count})
1073
+
1074
+ {code_index}
1075
+
1076
+ ### Agents ({agent_count})
1077
+
1078
+ {agent_index}
1079
+
1080
+ ### Commands ({command_count})
1081
+
1082
+ {command_index}
1083
+
1084
+ ---
1085
+
1086
+ ## Key Files by Workflow
1087
+
1088
+ {workflow_file_mapping}
1089
+
1090
+ ---
1091
+
1092
+ ## Gotchas & Patterns
1093
+
1094
+ {gotchas}
1095
+
1096
+ ---
1097
+
1098
+ ## Sync Metadata
1099
+
1100
+ ```json
1101
+ {
1102
+ "generated_at": "{timestamp}",
1103
+ "k0ntext_version": "{version}",
1104
+ "claude_hash": "{hash}",
1105
+ "ai_context_hash": "{hash}",
1106
+ "last_commit": "{commit_sha}",
1107
+ "synced_tools": ["claude", "copilot", "cursor"]
1108
+ }
1109
+ ```
1110
+ ```
1111
+
1112
+ ---
1113
+
1114
+ ## User Interaction Flows
1115
+
1116
+ ### Flow 1: Context Optimization
1117
+
1118
+ ```
1119
+ User: /context-opt --analyze
1120
+ |
1121
+ v
1122
+ [Scanning context files...]
1123
+ |
1124
+ v
1125
+ [Context Analysis Report]
1126
+ ┌─────────────────────────────────────┐
1127
+ │ Current Size: 85,234 tokens (42%) │
1128
+ │ Status: ⚠ Needs optimization │
1129
+ │ │
1130
+ │ Issues Found: │
1131
+ │ • Redundant sections (3) │
1132
+ │ • Outdated workflows (2) │
1133
+ │ • Missing recent changes (12) │
1134
+ └─────────────────────────────────────┘
1135
+ |
1136
+ v
1137
+ ? Apply optimizations? (Y/n)
1138
+ |
1139
+ +--Yes--> [Generating and syncing...]
1140
+ ```
1141
+
1142
+ ### Flow 2: TodoList During Session
1143
+
1144
+ ```
1145
+ User: /todo-create "Implement snapshot system"
1146
+ |
1147
+ v
1148
+ [✓ Todo session created: sess-abc123]
1149
+ [ ] Research snapshot requirements
1150
+ [ ] Design snapshot schema
1151
+ [ ] Implement snapshot manager
1152
+ [ ] Create snapshot commands
1153
+ [ ] Write tests
1154
+ |
1155
+ v
1156
+ [Session continues...]
1157
+ [User completes tasks, compaction happens]
1158
+ |
1159
+ v
1160
+ User: /todo-status
1161
+ |
1162
+ v
1163
+ [Current Todo Session: sess-abc123]
1164
+ [X] Research snapshot requirements ✓
1165
+ [X] Design snapshot schema ✓
1166
+ [ ] Implement snapshot manager
1167
+ [ ] Create snapshot commands
1168
+ [ ] Write tests
1169
+ |
1170
+ v
1171
+ [Session continues from where it left off]
1172
+ ```
1173
+
1174
+ ### Flow 3: Parallel RPI Dispatch
1175
+
1176
+ ```
1177
+ User: /dispatch-rpi --workflow context-engineering --parallel 6
1178
+ |
1179
+ v
1180
+ [Initializing RPI workflow: context-engineering]
1181
+ |
1182
+ v
1183
+ [Dispatching 6 parallel agents...]
1184
+
1185
+ Agent 1: @researcher (exploring/.claude/indexes)
1186
+ Agent 2: @architect (analyzing workflows)
1187
+ Agent 3: @database-ops (checking schema)
1188
+ Agent 4: @integration-hub (examining MCP)
1189
+ Agent 5: @context-optimizer (auditing context files)
1190
+ Agent 6: @workflow-router (mapping commands)
1191
+
1192
+ |
1193
+ v
1194
+ [Creating TodoList for session: rpi-xyz]
1195
+ ┌────────────────────────────────────────────┐
1196
+ │ [ ] Research current architecture │
1197
+ │ [ ] Design enhanced system │
1198
+ │ [ ] Plan database changes │
1199
+ │ [ ] Implement agent dispatcher │
1200
+ │ [ ] Test snapshot system │
1201
+ │ [ ] Update context sync │
1202
+ │ [ ] Verify cross-tool integration │
1203
+ └────────────────────────────────────────────┘
1204
+ |
1205
+ v
1206
+ [All agents running in parallel...]
1207
+ |
1208
+ v
1209
+ Agent 1: ✓ Found 15 workflow files
1210
+ Agent 2: ✓ Identified 3 integration points
1211
+ Agent 3: ✓ Schema v1.6.0 ready
1212
+ Agent 4: ✓ 5 MCP tools to add
1213
+ Agent 5: ✓ 2 context files diverged
1214
+ Agent 6: ✓ 23 workflow-command mappings
1215
+ |
1216
+ v
1217
+ [Consolidating results...]
1218
+ |
1219
+ v
1220
+ [TodoList updated: 6/8 tasks completed]
1221
+ ```
1222
+
1223
+ ---
1224
+
1225
+ ## Verification Steps
1226
+
1227
+ ### Manual Testing
1228
+
1229
+ 1. **TodoList System:**
1230
+ ```bash
1231
+ # In AI session, invoke command
1232
+ /todo-create "Test session"
1233
+
1234
+ # Check status
1235
+ /todo-status
1236
+
1237
+ # Verify compaction survival
1238
+ # (Trigger compaction, then run /todo-status again)
1239
+ ```
1240
+
1241
+ 2. **Context Files:**
1242
+ ```bash
1243
+ # In AI session
1244
+ /context-opt --analyze
1245
+ /context-sync --to both
1246
+ /context-status --detailed
1247
+ ```
1248
+
1249
+ 3. **Snapshots:**
1250
+ ```bash
1251
+ /snapshot-create "Test snapshot"
1252
+ /snapshot-list
1253
+ /snapshot-restore <id>
1254
+ ```
1255
+
1256
+ 4. **Cross-Tool Sync:**
1257
+ ```bash
1258
+ /cross-tool-sync --to copilot,cursor
1259
+ ```
1260
+
1261
+ 5. **Parallel Dispatch:**
1262
+ ```bash
1263
+ /dispatch-rpi --workflow test --parallel 3
1264
+ ```
1265
+
1266
+ ### Automated Tests
1267
+
1268
+ ```bash
1269
+ npm test # Run all tests
1270
+ npm test -- agent-system # Test agent system
1271
+ npm test -- context # Test context management
1272
+ npm test -- snapshots # Test snapshot system
1273
+ npm test -- sync # Test cross-tool sync
1274
+ ```
1275
+
1276
+ ---
1277
+
1278
+ ## Rollback Plan
1279
+
1280
+ If issues arise:
1281
+
1282
+ 1. **Per-phase rollback:** Git revert specific commits
1283
+ 2. **Database fallback:** Migration can be reversed
1284
+ 3. **Feature flags:** Add `K0NTEXT_EXPERIMENTAL_*` env vars
1285
+
1286
+ ---
1287
+
1288
+ ## Implementation Order
1289
+
1290
+ ### Week 1: Foundation
1291
+ - Day 1-2: TodoList manager, timestamp tracker
1292
+ - Day 3-4: Database schema v1.6.0 and migration
1293
+ - Day 5: Core service tests
1294
+
1295
+ ### Week 2: Context System
1296
+ - Day 1-2: Context generator, sync manager, types
1297
+ - Day 3-4: Commands and agents (context:opt, sync, status, diff)
1298
+ - Day 5: Testing and integration
1299
+
1300
+ ### Week 3: Snapshots & Cleanup
1301
+ - Day 1-2: Snapshot manager service
1302
+ - Day 3-4: Commands and agents (snapshot:*, cleanup:*)
1303
+ - Day 5: Testing and documentation
1304
+
1305
+ ### Week 4: Cross-Tool Sync
1306
+ - Day 1-3: Sync engine, adapters, conflict resolver
1307
+ - Day 4-5: Commands, agents, and testing
1308
+
1309
+ ### Week 5: Integration
1310
+ - Day 1-2: Agent dispatcher, workflow router
1311
+ - Day 3-4: Commands and agents (dispatch-rpi, workflow-route)
1312
+ - Day 5: Final testing, MCP tools, documentation
1313
+
1314
+ ---
1315
+
1316
+ ## Estimation
1317
+
1318
+ - **Phase 1 (Foundation):** 4-6 hours
1319
+ - **Phase 2 (Context System):** 6-8 hours
1320
+ - **Phase 3 (Snapshots & Cleanup):** 5-7 hours
1321
+ - **Phase 4 (Cross-Tool Sync):** 6-8 hours
1322
+ - **Phase 5 (Integration):** 5-7 hours
1323
+
1324
+ **Total: 26-36 hours** for all five phases
1325
+
1326
+ ---
1327
+
1328
+ ## Files Summary by Phase
1329
+
1330
+ ### Phase 1: Foundation
1331
+ | Type | Files |
1332
+ |-------|--------|
1333
+ | Commands | `.claude/commands/todo-create.md`, `.claude/commands/todo-status.md` |
1334
+ | Agents | `.claude/agents/todo-manager.md` |
1335
+ | Services | `src/agent-system/todolist-manager.ts`, `src/agent-system/timestamp-tracker.ts` |
1336
+ | Tests | `tests/agent-system/todolist-manager.test.ts`, `tests/agent-system/timestamp-tracker.test.ts` |
1337
+
1338
+ ### Phase 2: Context System
1339
+ | Type | Files |
1340
+ |-------|--------|
1341
+ | Commands | `.claude/commands/context-opt.md`, `.claude/commands/context-sync.md`, `.claude/commands/context-status.md`, `.claude/commands/context-diff.md` |
1342
+ | Agents | `.claude/agents/context-optimizer.md`, `.claude/agents/context-sync-agent.md` |
1343
+ | Services | `src/context/generator.ts`, `src/context/sync-manager.ts`, `src/context/types.ts`, `src/context/template.ts` |
1344
+ | Tests | `tests/context/generator.test.ts`, `tests/context/sync-manager.test.ts` |
1345
+
1346
+ ### Phase 3: Snapshots & Cleanup
1347
+ | Type | Files |
1348
+ |-------|--------|
1349
+ | Commands | `.claude/commands/snapshot-create.md`, `.claude/commands/snapshot-restore.md`, `.claude/commands/snapshot-list.md`, `.claude/commands/snapshot-diff.md`, `.claude/commands/cleanup-scan.md`, `.claude/commands/cleanup-interactive.md` |
1350
+ | Agents | `.claude/agents/snapshot-manager.md`, `.claude/agents/cleanup-agent.md` |
1351
+ | Services | `src/snapshots/manager.ts` |
1352
+ | Tests | `tests/snapshots/manager.test.ts`, `tests/cleanup/agent.test.ts` |
1353
+
1354
+ ### Phase 4: Cross-Tool Sync
1355
+ | Type | Files |
1356
+ |-------|--------|
1357
+ | Commands | `.claude/commands/cross-tool-sync.md` |
1358
+ | Agents | `.claude/agents/cross-tool-sync-agent.md` |
1359
+ | Services | `src/sync/cross-tool-engine.ts`, `src/sync/adapters/*.ts` (7 adapters), `src/sync/conflict-resolver.ts` |
1360
+ | Tests | `tests/sync/cross-tool-engine.test.ts` |
1361
+
1362
+ ### Phase 5: Integration
1363
+ | Type | Files |
1364
+ |-------|--------|
1365
+ | Commands | `.claude/commands/dispatch-rpi.md`, `.claude/commands/workflow-route.md` |
1366
+ | Agents | `.claude/agents/rpi-dispatcher.md`, `.claude/agents/workflow-router.md` |
1367
+ | Services | `src/agent-system/dispatcher.ts`, `src/integration/workflow-router.ts` |
1368
+ | Tests | `tests/agent-system/dispatcher.test.ts`, `tests/integration/workflow-router.test.ts` |
1369
+
1370
+ ---
1371
+
1372
+ ## Index & Context Folder Integration
1373
+
1374
+ All agents and commands will be **index-aware**, meaning they:
1375
+
1376
+ 1. **Read from `.claude/indexes/`** to understand project structure
1377
+ 2. **Reference `.claude/context/`** for project context data
1378
+ 3. **Update indexes** when new workflows/agents/commands are added
1379
+ 4. **Maintain cross-references** between related files
1380
+ 5. **Use semantic RAG** when database is available for context lookup
1381
+
1382
+ ---
1383
+
1384
+ ## Sync Strategy: claude.md ↔ ai_context.md
1385
+
1386
+ ### Bidirectional Sync Rules:
1387
+
1388
+ 1. **Timestamp Awareness:** Track modification time and git commit for each file
1389
+ 2. **Conflict Detection:** Compare hashes to detect divergence
1390
+ 3. **Merge Strategy:** Offer options: newer, older, manual merge, both
1391
+ 4. **Backup Before Sync:** Always create timestamped backup before overwriting
1392
+ 5. **Sync Metadata:** JSON footer with sync status for verification
1393
+
1394
+ ### Git Hook Integration:
1395
+
1396
+ - **pre-commit:** Check if claude.md or ai_context.md is staged → trigger sync
1397
+ - **post-commit:** Record sync state in database
1398
+ - **post-merge:** Run conflict resolution and auto-sync
1399
+
1400
+ ---
1401
+
1402
+ **Next Steps:** User reviews plan, asks questions, requests approval → ExitPlanMode