Commit graph

1338 commits

Author SHA1 Message Date
Mario Zechner
09d6131bef Add file tracking and iterative summary merging to compaction
- CompactionDetails type with readFiles/modifiedFiles
- extractFileOperations collects from tool calls and previous compaction details
- UPDATE_SUMMARIZATION_PROMPT for merging with previous summary
- generateSummary now accepts previousSummary for iterative updates
- compact() extracts files, passes previousSummary, returns details
- Only merges from !fromHook compaction entries (backward compatible)
2025-12-30 22:42:24 +01:00
Mario Zechner
d4dc07ab20 Pass fromHook to appendCompaction for both manual and auto compaction 2025-12-30 22:42:24 +01:00
Mario Zechner
f118cdc67b Add fromHook field to CompactionEntry and BranchSummaryEntry
- fromHook: true = hook generated, skip file extraction
- fromHook: undefined/false = pi generated, extract files (backward compatible)
- branchWithSummary now accepts fromHook parameter
- File extraction only runs for !entry.fromHook entries
2025-12-30 22:42:24 +01:00
Mario Zechner
0445da666c Fix compaction message rendering to go through addMessageToChat
Both auto_compaction_end and executeCompaction were manually adding
CompactionSummaryMessageComponent instead of using addMessageToChat,
which caused missing spacers. Now both use addMessageToChat for
consistent spacing and expansion state handling.
2025-12-30 22:42:24 +01:00
Mario Zechner
8fe8fe9920 Add preamble to branch summary for context
Prepends: 'The user explored a different conversation branch before
returning here. Summary of that exploration:'

This helps the LLM understand the summary is background context from
a different path, not the current thread being continued.
2025-12-30 22:42:24 +01:00
Mario Zechner
2ba69878ed Fix branch summarization: use convertToLlm instead of messagesToText
The old messagesToText only extracted text content, losing all tool calls.
Now uses convertToLlm like compaction does, preserving the full conversation
including tool calls, which is essential for generating useful summaries.
2025-12-30 22:42:24 +01:00
Mario Zechner
0fe9f74b4e Return defensive copies from SettingsManager getters
getHookPaths(), getCustomToolPaths(), and getSkillsSettings() now return
copies of arrays instead of references to internal state. This prevents
callers from accidentally mutating settings without going through setters.

Fixes #361
2025-12-30 22:42:24 +01:00
Mario Zechner
92947a3dc4 Fix common ancestor finding: iterate backwards to find deepest ancestor
getPath returns root-first, so iterating forward found root as common
ancestor instead of the deepest shared node. Now iterates backwards.
2025-12-30 22:42:24 +01:00
Mario Zechner
a602e8aba8 Remove restrictive sentence limits from Goal section 2025-12-30 22:42:24 +01:00
Mario Zechner
ac71aac090 Use structured output format for compaction and branch summarization
Both now use consistent sections:
- Goal
- Constraints & Preferences
- Progress (Done/In Progress/Blocked)
- Key Decisions
- Next Steps
- Critical Context (compaction only)

Prompts instruct LLM to use EXACT format and preserve file paths/function names.
2025-12-30 22:42:24 +01:00
Mario Zechner
d1a49c45ff Append file lists to summary text for LLM context and TUI display
Files are included both:
- In summary text as <read-files>/<modified-files> tags (visible to LLM and TUI)
- In details for structured access by code
2025-12-30 22:42:24 +01:00
Mario Zechner
9427211f99 fix(tui): render HTML tags as plain text in Markdown component
Handles both block-level and inline HTML tags that were previously
silently dropped.

fixes #359
2025-12-30 22:42:24 +01:00
Mario Zechner
4ef3325cec Store file lists in BranchSummaryEntry.details for cumulative tracking
- BranchSummaryResult now returns readFiles and modifiedFiles separately
- BranchSummaryDetails type for details: { readFiles, modifiedFiles }
- branchWithSummary accepts optional details parameter
- Collect files from existing branch_summary.details when preparing entries
- Files accumulate across nested branch summaries
2025-12-30 22:42:24 +01:00
Mario Zechner
04f2fcf004 Use XML tags for file operations in branch summary
<read-files> and <modified-files> with one path per line
2025-12-30 22:42:24 +01:00
Mario Zechner
e7bfb5afe7 Fix file ops: Read (not modified) and Modified (edited or written)
- Read: files only read, not modified
- Modified: files that were edited OR written
- Avoids duplicate listings when same file is read then edited
2025-12-30 22:42:24 +01:00
Mario Zechner
dc5fc4fc40 Use reserveTokens for branch summary (tokens left for prompt + response)
- tokenBudget = contextWindow - reserveTokens
- Default 16384, same as compaction
- Consistent naming with CompactionSettings.reserveTokens
2025-12-30 22:42:24 +01:00
Mario Zechner
f5f39f08f1 Use token-based maxTokens instead of fraction-based reserveFraction
- BranchSummarySettings.maxTokens (default 100000) instead of reserveFraction
- More intuitive and consistent with CompactionSettings.keepRecentTokens
2025-12-30 22:42:24 +01:00
Mario Zechner
839a46e6fe Use AgentMessage in BranchPreparation and add BranchSummarySettings
- BranchPreparation now uses AgentMessage[] instead of custom type
- Reuse getMessageFromEntry pattern from compaction.ts
- Add BranchSummarySettings with reserveFraction to settings.json
- Add getBranchSummarySettings() to SettingsManager
- Use settings for reserveFraction instead of hardcoded value
2025-12-30 22:42:23 +01:00
Mario Zechner
08fab16e2d Add ReadonlySessionManager and refactor branch summarization
- Add ReadonlySessionManager interface to session-manager.ts
- Re-export from hooks/index.ts
- Add collectEntriesForBranchSummary() to extract entries for summarization
- Don't stop at compaction boundaries (include their summaries as context)
- Add token budget support to prepareBranchEntries()
- Walk entries newest-to-oldest to prioritize recent context
- Use options object for generateBranchSummary()
- Handle compaction entries as context summaries
- Export new types: CollectEntriesResult, GenerateBranchSummaryOptions
2025-12-30 22:42:23 +01:00
Mario Zechner
5cbaf2be88 Improve branch summarization with preparation and file ops extraction
- Add prepareBranchEntries() to extract messages and file operations
- Extract read/write/edit operations from tool calls
- Append static file operations section to summary
- Improve prompt for branch summarization
- Skip toolResult messages (context already in assistant message)
- Export new types: BranchPreparation, FileOperations
2025-12-30 22:42:23 +01:00
Mario Zechner
fd13b53b1c Refactor: move compaction code to src/core/compaction/
- Move compaction.ts to src/core/compaction/compaction.ts
- Extract branch summarization to src/core/compaction/branch-summarization.ts
- Add index.ts to re-export all compaction utilities
- Update all imports across the codebase
2025-12-30 22:42:23 +01:00
Mario Zechner
aee61b1a6b Fix test: getLeafId returns null for empty session, not empty string 2025-12-30 22:42:23 +01:00
Mario Zechner
31c5cd38d1 Add tree navigation tests and shared test utilities
- Add test/utilities.ts with shared helpers (API_KEY, userMsg, assistantMsg, createTestSession)
- Add agent-session-tree-navigation.test.ts with e2e tests for tree navigation
- Add getChildren() method to SessionManager
- Add summaryEntry to navigateTree return type
- Update existing tests to use shared utilities
2025-12-30 22:42:23 +01:00
Mario Zechner
01dae9ebcc Fix branch summarization abort handling and tree navigation
- Check response.stopReason instead of catching errors for abort detection
- Return result object from _generateBranchSummary instead of throwing
- Fix summary attachment: attach to navigation target position, not old branch
- Support root-level summaries (parentId=null) in branchWithSummary
- Remove setTimeout hack for re-showing tree selector on abort
2025-12-30 22:42:23 +01:00
Mario Zechner
9dac0a1423 WIP: Add branch summarization abort support with loader and escape handler 2025-12-30 22:42:23 +01:00
Mario Zechner
159e19a010 Fix tree selector gutter alignment, add page navigation, improve styling
- Fix gutter/connector alignment by tracking gutter positions with GutterInfo
- Convert recursive markContains to iterative to avoid stack overflow
- Add left/right arrow keys for page up/down navigation
- Consistent assistant message styling (green prefix, appropriate status colors)
- Remove leaf marker (*), active path bullets are sufficient
- Add Expandable interface for toggle expansion
- Fix BranchSummaryMessageComponent expansion toggle
2025-12-30 22:42:23 +01:00
Mario Zechner
975e90ea8c fix(coding-agent): prioritize active branch in sorting and fix gutters spacing 2025-12-30 22:42:23 +01:00
Mario Zechner
97e5e8c918 fix(coding-agent): use smaller bullet marker with space for active path 2025-12-30 22:42:23 +01:00
Mario Zechner
3493e47b4d fix(coding-agent): move active path marker to right before entry text 2025-12-30 22:42:23 +01:00
Mario Zechner
96c071b4c4 feat(coding-agent): highlight active path with ● marker in tree selector 2025-12-30 22:42:23 +01:00
Mario Zechner
8d3b4dd762 fix(coding-agent): keep gutters when rendering virtual root children 2025-12-30 22:42:23 +01:00
Mario Zechner
6465bc502f fix(coding-agent): show gutters without connectors on virtual root children 2025-12-30 22:42:23 +01:00
Mario Zechner
d568ebd659 feat(coding-agent): add gutters and connectors back to tree selector
- Show ├─ for non-last siblings, └─ for last sibling
- Show │ gutter for descendants of non-last siblings
- Properly handle multiple roots display shift
2025-12-30 22:42:23 +01:00
Mario Zechner
e50eae1054 fix(coding-agent): display multiple roots at indent 0, keep child logic intact 2025-12-30 22:42:23 +01:00
Mario Zechner
32ec1fa883 fix(coding-agent): treat multiple roots as children of virtual branching root 2025-12-30 22:42:23 +01:00
Mario Zechner
7c103ddc55 refactor(coding-agent): simplify tree indentation
- At indent 0: stay flat unless parent branches
- At indent 1: children go to indent 2 (visual grouping)
- At indent 2+: stay flat for single-child chains
- Remove gutter/connector complexity for now
2025-12-30 22:42:23 +01:00
Mario Zechner
6fbc3a01ef refactor(coding-agent): cleaner tree gutter/indent logic
- Only indent when parent has siblings (branch point)
- gutterLevels array tracks which levels need │ vs spaces
- connector: none/branch/last for ├─/└─ display
2025-12-30 22:42:23 +01:00
Mario Zechner
1d90592df1 fix(coding-agent): always show error/aborted assistant messages in tree 2025-12-30 22:42:23 +01:00
Mario Zechner
e8debe78c6 fix(coding-agent): use visible leaf for tree display, preserve metadata on branch 2025-12-30 22:42:23 +01:00
Mario Zechner
5726770d1f fix(coding-agent): always show current leaf in tree selector even if aborted/error 2025-12-30 22:42:22 +01:00
Mario Zechner
2922020382 feat(coding-agent): improve tree selector tool display
- Tool results show formatted call info like [read: path:1-10], [bash: cmd]
- Skip assistant messages with stopReason error/aborted
- Skip assistant messages with only tool calls (no text)
- Format built-in tools like tool-execution.ts (read, write, edit, bash, grep, find, ls)
- Custom tools show truncated JSON args
2025-12-30 22:42:22 +01:00
Mario Zechner
b153b528e8 feat(coding-agent): show tool name instead of result content in tree selector 2025-12-30 22:42:22 +01:00
Mario Zechner
6b7ad0ed4b feat(coding-agent): reimplement tree selector features
- Label editing with 'l' key
- Ctrl+O cycles through filters: default -> user-only -> labeled-only -> all
- Preserve cursor position when toggling filters
- Labels shown at front of node
- Normalize tabs/newlines in content
- extractContent limited to 200 chars for performance
- truncateToWidth on all rendered lines
- Iterative flattenTree to avoid stack overflow
- Linear chain optimization (no indent for single-child chains)
2025-12-30 22:42:22 +01:00
Mario Zechner
544814875e Add global debug key (Shift+Ctrl+D), iterative tree sorting to avoid stack overflow 2025-12-30 22:42:22 +01:00
Mario Zechner
1f4594598b feat(coding-agent): add search to /tree selector
- Type to filter nodes by matching tokens in content
- Search field always visible above tree
- Backspace removes chars, Escape clears search
- Restructured layout: title, border, help+search, border, tree, border
2025-12-30 22:42:22 +01:00
Mario Zechner
4958271dd3 feat(coding-agent): implement /tree command for session tree navigation
- Add TreeSelectorComponent with ASCII tree visualization
- Add AgentSession.navigateTree() for switching branches
- Add session_before_tree/session_tree hook events
- Add SessionManager.resetLeaf() for navigating to root
- Change leafId from string to string|null for consistency with parentId
- Support optional branch summarization when switching
- Update buildSessionContext() to handle null leafId
- Add /tree to slash commands in interactive mode
2025-12-30 22:42:22 +01:00
Mario Zechner
256761e410 Clean-up 2025-12-30 22:42:22 +01:00
Mario Zechner
59ce62bffc Tree spec 2025-12-30 22:42:22 +01:00
Mario Zechner
d6283f99dc refactor(hooks): split session events into individual typed events
Major changes:
- Replace monolithic SessionEvent with reason discriminator with individual
  event types: session_start, session_before_switch, session_switch,
  session_before_new, session_new, session_before_branch, session_branch,
  session_before_compact, session_compact, session_shutdown
- Each event has dedicated result type (SessionBeforeSwitchResult, etc.)
- HookHandler type now allows bare return statements (void in return type)
- HookAPI.on() has proper overloads for each event with correct typing

Additional fixes:
- AgentSession now always subscribes to agent in constructor (was only
  subscribing when external subscribe() called, breaking internal handlers)
- Standardize on undefined over null throughout codebase
- HookUIContext methods return undefined instead of null
- SessionManager methods return undefined instead of null
- Simplify hook exports to 'export type * from types.js'
- Add detailed JSDoc for skipConversationRestore vs cancel
- Fix createBranchedSession to rebuild index in persist mode
- newSession() now returns the session file path

Updated all example hooks, tests, and emission sites to use new event types.
2025-12-30 22:42:22 +01:00
Mario Zechner
38d65dfe59 Add ReadonlySessionManager type for hooks
Hooks now receive ReadonlySessionManager in contexts, which only
exposes read methods. Writes must go through pi.sendMessage() or
pi.appendEntry().
2025-12-30 22:42:22 +01:00