mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 16:04:03 +00:00
- Add TreeNode base type with id, parentId, timestamp - Add *Content types for clean input/output separation - Entry types are now TreeNode & *Content intersections - SessionManager assigns id/parentId on save, tracks leafId - Add migrateSessionEntries() for v1 to v2 conversion - Migration runs on load, rewrites file - buildSessionContext() uses tree traversal from leaf - Compaction returns CompactionResult (content only) - Hooks return compaction content, not full entries - Add firstKeptEntryId to before_compact hook event - Update mom package for tree fields - Better error messages for compaction failures
3.2 KiB
3.2 KiB
Session Tree Implementation Plan
Reference: session-tree.md
Phase 1: SessionManager Core
- Update entry types with
id,parentIdfields (using TreeNode intersection) - Add
versionfield toSessionHeader - Change
CompactionEntry.firstKeptEntryIndex→firstKeptEntryId - Add
BranchSummaryEntrytype - Add
byId: Map<string, ConversationEntry>index - Add
leafId: stringtracking - Implement
getPath(fromId?)tree traversal - Implement
getEntry(id)lookup - Implement
getLeafId()helper - Update
_buildIndex()to populatebyIdmap - Update
saveMessage()to include id/parentId (returns id) - Update
saveCompaction()signature and fields (returns id) - Update
saveThinkingLevelChange()to include id/parentId (returns id) - Update
saveModelChange()to include id/parentId (returns id) - Update
buildSessionContext()to usegetPath()traversal
Type Hierarchy
// Tree fields (added by SessionManager)
interface TreeNode { id, parentId, timestamp }
// Content types (for input)
interface MessageContent { type: "message"; message: AppMessage }
interface CompactionContent { type: "compaction"; summary; firstKeptEntryId; tokensBefore }
// etc...
// Full entry types (TreeNode & Content)
type SessionMessageEntry = TreeNode & MessageContent;
type CompactionEntry = TreeNode & CompactionContent;
// etc...
Phase 2: Migration
- Add
CURRENT_SESSION_VERSION = 2constant - Implement
_migrateToV2()for v1→v2 - Update
setSessionFile()to detect version and migrate - Implement
_rewriteFile()for post-migration persistence - Handle
firstKeptEntryIndex→firstKeptEntryIdconversion in migration
Phase 3: Branching
- Implement
branchInPlace(id)- switch leaf pointer - Implement
branchWithSummary(id, summary)- create summary entry - Update
branchToNewFile()to use IDs (no remapping) - Update
AgentSession.branch()to use new API
Phase 4: Compaction Integration
- Update
compaction.tsto work with IDs - Update
prepareCompaction()to returnfirstKeptEntryId - Update
compact()to returnCompactionResultwithfirstKeptEntryId - Update
AgentSessioncompaction methods - Add
firstKeptEntryIdtobefore_compacthook event
Phase 5: Testing
- Add test fixtures from existing sessions
- Test migration of v1 sessions
- Test context building with tree structure
- Test branching operations
- Test compaction with IDs
- Update existing tests for new types
Phase 6: UI Integration
- Update
/branchcommand for new API - Add
/branch-herecommand for in-place branching - Add
/branchescommand to list branches (future) - Update session display to show tree info (future)
Notes
- All save methods return the new entry's ID
- Migration rewrites file on first load if version < CURRENT_VERSION
- Existing sessions become linear chains after migration (parentId = previous entry)
- Tree features available immediately after migration
- SessionHeader does NOT have id/parentId (it's metadata, not part of tree)
- Content types allow clean input/output separation