Commit Graph
247 Commits
Author SHA1 Message Date
Mario Zechner d4bd429a35 Add hooks system with pi.send() for external message injection
- Hook discovery from ~/.pi/agent/hooks/, .pi/hooks/, --hook flag
- Events: session_start, session_switch, agent_start/end, turn_start/end, tool_call, tool_result, branch
- tool_call can block execution, tool_result can modify results
- pi.send(text, attachments?) to inject messages from external sources
- UI primitives: ctx.ui.select/confirm/input/notify
- Context: ctx.exec(), ctx.cwd, ctx.sessionFile, ctx.hasUI
- Docs shipped with npm package and binary builds
- System prompt references docs folder
2025-12-10 00:50:30 +01:00
Mario Zechner 1cea3c25f2 Fix queued messages. 2025-12-09 23:51:22 +01:00
Mario Zechner aba7f1e338 fix(coding-agent): skip hook init when no hooks configured 2025-12-09 22:24:17 +01:00
Mario Zechner feaefa303c feat(coding-agent): implement hooks system
- Add hooks infrastructure in core/hooks/ (loader, runner, types)
- HookUIContext interface with mode-specific implementations
- Interactive mode: TUI-based selector/input/confirm dialogs
- RPC mode: JSON protocol for hook UI requests/responses
- Print mode: no-op UI context (hooks run but can't prompt)
- AgentSession.branch() now async, returns { selectedText, skipped }
- Settings: hooks[] and hookTimeout configuration
- Export hook types from package for hook authors

Based on PR #147 proposal, adapted for new architecture.
2025-12-09 22:17:12 +01:00
Mario Zechner 62a606744c Simplify compaction: remove proactive abort, use Agent.continue() for retry
- Add agentLoopContinue() to pi-ai for resuming from existing context
- Add Agent.continue() method and transport.continue() interface
- Simplify AgentSession compaction to two cases: overflow (auto-retry) and threshold (no retry)
- Remove proactive mid-turn compaction abort
- Merge turn prefix summary into main summary
- Add isCompacting property to AgentSession and RPC state
- Block input during compaction in interactive mode
- Show compaction count on session resume
- Rename RPC.md to rpc.md for consistency

Related to #128
2025-12-09 21:43:49 +01:00
Mario Zechner 11566a1a58 Fix bash execution component to limit by visual lines instead of logical lines 2025-12-09 21:16:25 +01:00
Mario Zechner d324f9b567 feat(coding-agent): implement new compaction system with overflow recovery
Phase 1: Updated compaction.ts
- findCutPoint now returns CutPointResult with isSplitTurn and turnStartIndex
- Can cut at user, assistant, or bashExecution messages (never tool results)
- Added turnPrefixSummary support for split turns (parallel summarization)
- estimateTokens helper for context size estimation

Phase 2: Updated session-manager.ts
- CompactionEntry now has optional turnPrefixSummary field
- loadSessionFromEntries injects both summaries when turn was split

Phase 3: Updated agent-session.ts
- Overflow detection via isContextOverflow after agent_end
- Proactive compaction check on turn_end before next LLM call
- _abortingForCompaction flag to skip saving aborted messages
- Auto-retry after overflow recovery or proactive compaction
- New event fields: reason (overflow/threshold), willRetry

Phase 4: Updated interactive-mode.ts
- Shows reason in compaction status (Context overflow detected...)
- Shows retry status after compaction

Tests updated for new CutPointResult return type.
2025-12-09 17:18:53 +01:00
Mario Zechner 10befd135a Fix hardcoded truncation limits in tool output display
- Add maxLines and maxBytes fields to TruncationResult to track actual limits used
- Update tool-execution.ts to use actual limits from truncation result
- Add fallbacks to DEFAULT_MAX_* for backward compatibility with old sessions
- Fix outdated comments that said 30KB when default is 50KB
2025-12-09 17:06:29 +01:00
Mario Zechner cd677f4bd4 feat(coding-agent): maintain in-memory session entries for --no-session compaction support
SessionManager now tracks all entries in memory regardless of whether file
persistence is enabled. This allows compaction to work in --no-session mode
where no session file is created.

- Added inMemoryEntries array to store session entries
- All save methods now push to inMemoryEntries
- loadEntries() returns in-memory entries when file persistence is disabled
- File persistence only writes when enabled flag is true
- Session loading (constructor, setSessionFile) populates in-memory entries
2025-12-09 16:55:42 +01:00
Mario Zechner be9093ba59 Rewrite RPC documentation with accurate types 2025-12-09 15:19:19 +01:00
Mario Zechner 2c32c76f7f Add get_messages RPC command 2025-12-09 14:37:16 +01:00
Mario Zechner 84175650b7 Rewrite RPC mode with typed protocol and client
- Move RPC files to modes/rpc/ directory
- Add properly typed RpcCommand and RpcResponse types
- Expose full AgentSession API via RPC commands:
  - State: get_state
  - Model: set_model, cycle_model, get_available_models
  - Thinking: set_thinking_level, cycle_thinking_level
  - Queue: set_queue_mode
  - Compaction: compact, set_auto_compaction
  - Bash: bash, abort_bash
  - Session: get_session_stats, export_html, switch_session, branch, etc.
- Add RpcClient class for programmatic access
- Rewrite tests to use RpcClient instead of raw process spawning
- All commands support optional correlation ID for request/response matching
2025-12-09 14:13:28 +01:00
Mario Zechner 31f74e09c6 Fix auto-compaction TUI integration and cut point logic
- Trigger auto-compaction after agent_end instead of during message_end
- Show CompactionComponent after auto-compaction (same as manual /compact)
- Fix cut point to include bash executions before kept user message
- Stop backward scan at compaction, assistant, user, or toolResult boundaries
2025-12-09 02:45:24 +01:00
Mario Zechner fc3813c24d Fix --session flag to load session messages and restore model/thinking 2025-12-09 01:59:20 +01:00
Mario Zechner c0707bfc28 Add auto-compaction events to AgentSession
- Add AgentSessionEvent type extending AgentEvent with auto_compaction_start/end
- Emit events when auto-compaction starts and completes
- TUI shows loader during auto-compaction with escape to cancel
- Rebuilds chat UI when auto-compaction succeeds
2025-12-09 01:51:51 +01:00
Mario Zechner ba0b5304ae Show pending bash executions in pending area, move to chat on user submit 2025-12-09 01:39:40 +01:00
Mario Zechner 0ebd0db2cd Fix bash execution interleaving with tool calls: defer message insertion while streaming 2025-12-09 01:34:31 +01:00
Mario Zechner a63092e830 Move config.ts from utils/ to src/ 2025-12-09 01:28:06 +01:00
Mario Zechner 350196694d Remove old implementation files (main.ts, cli.ts, tui-renderer.ts), rename new files 2025-12-09 01:21:28 +01:00
Mario Zechner 4c7b7b5206 Split main-new.ts into modules: cli/args, cli/file-processor, cli/session-picker, core/system-prompt, core/model-resolver 2025-12-09 01:20:31 +01:00
Mario Zechner 9fc6dfb175 Deduplicate interactive-mode: consolidate message rendering, add showStatus helper 2025-12-09 01:12:19 +01:00
Mario Zechner 3b0bec8b90 Refactor selectors: replace show/hide pairs with single showSelector helper 2025-12-09 01:04:55 +01:00
Mario Zechner fd625dd07a Remove unused BashExecutionMessage import 2025-12-09 01:00:11 +01:00
Mario Zechner 790db64a72 Remove unnecessary type cast in interactive-mode.ts 2025-12-09 00:59:25 +01:00
Mario Zechner 94e30e5558 Fix path resolution in config.ts after file reorganization 2025-12-09 00:54:51 +01:00
Mario Zechner 58828adf76 Reorganize file structure: core/, utils/, modes/interactive/components/, modes/interactive/theme/ 2025-12-09 00:51:33 +01:00
Mario Zechner c84dd8379f WP16: Update main-new.ts to use InteractiveMode 2025-12-09 00:36:16 +01:00
Mario Zechner 6e7fd1765a WP15: Create InteractiveMode using AgentSession 2025-12-09 00:34:44 +01:00
Mario Zechner ab26f1a25d WP14: Create main-new.ts and cli-new.ts using AgentSession and new modes 2025-12-09 00:21:18 +01:00
Mario Zechner 5b82995085 WP13: Create modes/index.ts barrel export 2025-12-09 00:16:46 +01:00
Mario Zechner 60ff1508e4 WP12: Create rpc-mode.ts 2025-12-09 00:16:17 +01:00
Mario Zechner d53624b8a3 WP11: Create print-mode.ts 2025-12-09 00:15:37 +01:00
Mario Zechner 99402aed21 WP9+WP10: Add AgentSession session management and utility methods 2025-12-09 00:14:47 +01:00
Mario Zechner 3cdbb02dc8 WP8: Add AgentSession bash execution 2025-12-09 00:13:10 +01:00
Mario Zechner 4a5eeb99aa WP7: Add AgentSession compaction (manual + auto), fix listener preservation 2025-12-09 00:12:07 +01:00
Mario Zechner d11c257490 WP5+WP6: Add AgentSession model, thinking level, and queue mode management 2025-12-09 00:08:36 +01:00
Mario Zechner 7d305e1e00 WP4: Add AgentSession prompting methods (prompt, queue, abort, reset) 2025-12-09 00:07:24 +01:00
Mario Zechner 314f3ddb86 WP3: Add AgentSession event subscription with session persistence 2025-12-09 00:05:54 +01:00
Mario Zechner ce5e888778 WP2: Create AgentSession basic structure + update plan for keep-old-code strategy 2025-12-09 00:05:06 +01:00
Mario Zechner ed81d2ac56 WP1: Create bash-executor.ts with unified bash execution 2025-12-09 00:01:36 +01:00
Markus YlisiurunenandGitHub aaafc8627d use only model id for fuzzy filtering in model selector (#151) 2025-12-08 23:35:31 +01:00
Mario Zechner 5677715707 Fix crash when bash mode outputs binary data
Sanitize shell output by removing Unicode Format characters and lone
surrogates that crash string-width. This fixes crashes when running
commands like curl that download binary files.
2025-12-08 23:26:58 +01:00
Mario Zechner a4c6b47f85 Add green borders around bash execution component 2025-12-08 22:45:05 +01:00
Mario ZechnerandMarkus Ylisiurunen 570ebebbc3 Add bash mode for executing shell commands
- Add ! prefix in TUI editor to execute shell commands directly
- Output streams in real-time and is added to LLM context
- Supports multiline commands, cancellation (Escape), truncation
- Preview mode shows last 20 lines, Ctrl+O expands full output
- Commands persist in session history as bashExecution messages
- Add bash command to RPC mode via {type:'bash',command:'...'}
- Add RPC tests for bash command execution and context inclusion
- Update docs: rpc.md, session.md, README.md, CHANGELOG.md

Closes #112

Co-authored-by: Markus Ylisiurunen <markus.ylisiurunen@gmail.com>
2025-12-08 22:40:32 +01:00
Mario Zechner 69bce12613 Merge main into bash-mode 2025-12-08 21:39:01 +01:00
Mario Zechner 18df11d10e Add xhigh thinking level for OpenAI codex-max models
- Add 'xhigh' to ThinkingLevel type in ai and agent packages
- Map xhigh to reasoning_effort: 'max' for OpenAI providers
- Add thinkingXhigh color token to theme schema and built-in themes
- Show xhigh option only when using codex-max models
- Update CHANGELOG for both ai and coding-agent packages

closes #143
2025-12-08 21:12:54 +01:00
Mario Zechner ed22731d93 Add OpenAICompat for openai-completions provider quirks
Fixes #133
2025-12-08 19:02:03 +01:00
Mario Zechner 84878657af Add changelog entry for tool output truncation (#134) 2025-12-07 01:24:41 +01:00
Mario Zechner 8158b6fa0e Restore TUI warning notices for truncated tool output
Warnings now shown at bottom of tool execution (outside collapsed area)
so users can see truncation occurred even when content is collapsed.
2025-12-07 01:14:57 +01:00
Mario Zechner 62f1c815de Implement tool result truncation with actionable notices (#134)
- read: actionable notices with offset for continuation
  - First line > 30KB: return empty + bash command suggestion
  - Hit limit: '[Showing lines X-Y of Z. Use offset=N to continue]'

- bash: tail truncation with temp file
  - Notice includes line range + temp file path
  - Edge case: last line > 30KB shows partial

- grep: pre-truncate match lines to 500 chars
  - '[... truncated]' suffix on long lines
  - Notice for match limit and line truncation

- find/ls: result/entry limit notices
  - '[N results limit reached. Use limit=M for more]'

- All notices now in text content (LLM sees them)
- TUI simplified (notices render as part of output)
- Never return partial lines (except bash edge case)
2025-12-07 01:11:31 +01:00