Commit graph

1326 commits

Author SHA1 Message Date
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
Mario Zechner
26e1c9d91c Fix nested background issue in HookMessageComponent
When custom renderer returns a component with its own background,
don't wrap it in another background box. The nested bg resets
were causing padding to lose its background color.
2025-12-30 22:42:22 +01:00
Mario Zechner
41af99cccf Support multiple messages in agent.prompt() and agentLoop
- agentLoop now accepts AgentMessage[] instead of single message
- agent.prompt() accepts AgentMessage | AgentMessage[]
- Emits message_start/end for each message in the array
- AgentSession.prompt() builds array with hook message + user message
- TUI now receives events for before_agent_start injected messages
2025-12-30 22:42:22 +01:00
Mario Zechner
575c875475 Remove allowDuringStreaming flag - commands always run immediately
Hook commands now always execute immediately, even during streaming.
If a command needs to interact with the LLM, it uses pi.sendMessage()
which handles queueing automatically.

This simplifies the API and eliminates the issue of queued slash
commands being sent to the LLM instead of executing.
2025-12-30 22:42:22 +01:00
Mario Zechner
f8352bb7d7 Rename immediate -> allowDuringStreaming for hook commands 2025-12-30 22:42:22 +01:00
Mario Zechner
454dd919be Fix test hook: add triggerTurn to start agent run 2025-12-30 22:42:22 +01:00
Mario Zechner
0d558813e4 Fix test hook: use valid theme colors, proper type import 2025-12-30 22:42:22 +01:00
Mario Zechner
f43969b31a Update plan: mark before_agent_start as complete 2025-12-30 22:42:22 +01:00
Mario Zechner
57146de202 Implement before_agent_start hook event
- Add BeforeAgentStartEvent and BeforeAgentStartEventResult types
- Add emitBeforeAgentStart to HookRunner
- Call in AgentSession.prompt() before agent.prompt()
- Hook can return a message to inject into context (persisted + visible)
- Add test hook demonstrating custom message rendering and before_agent_start
2025-12-30 22:42:22 +01:00
Mario Zechner
bbdc350394 Add reference to #330 (Dynamic Context Pruning) in plan
Documents why context event was added and notes the type
inconsistency between ContextEvent (AgentMessage[]) and
ContextEventResult (Message[])
2025-12-30 22:42:22 +01:00
Mario Zechner
ae614f93e3 Add investigation item for context event vs before_agent_start
Reference: #324

Documents:
- Current context event behavior (AgentMessage[], transient)
- Proposed before_agent_start event (persistent, TUI visible)
- Key differences table
- Open design questions
- Need to verify AgentMessage vs Message abstraction level
2025-12-30 22:42:22 +01:00
Mario Zechner
1721bb8398 Mark Hook API Changes as complete in plan 2025-12-30 22:42:21 +01:00
Mario Zechner
4ff5f61ffc Add BranchSummaryMessageComponent, unify styling with hook messages
- CompactionSummaryMessageComponent now extends Box, uses customMessageBg
- New BranchSummaryMessageComponent for branch summaries
- Both use same background color as HookMessageComponent for consistency
- Added Spacer before compaction/branch components in chat
2025-12-30 22:42:21 +01:00