Commit graph

402 commits

Author SHA1 Message Date
Mario Zechner
7c553acd1e 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
942d8d3c95 Fix queued messages. 2025-12-09 23:51:22 +01:00
Mario Zechner
86c2a33df4 fix(coding-agent): skip hook init when no hooks configured 2025-12-09 22:24:17 +01:00
Mario Zechner
04d59f31ea 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
55032f1697 Add [Unreleased] section to changelogs 2025-12-09 21:51:01 +01:00
Mario Zechner
2d9ecd1750 Release v0.17.0 2025-12-09 21:47:39 +01:00
Mario Zechner
5a9d844f9a 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
d67c69c6e9 Fix bash execution component to limit by visual lines instead of logical lines 2025-12-09 21:16:25 +01:00
Mario Zechner
a38e619095 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
ee9acdb49d 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
8226975080 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
796112f40f Release v0.16.0 2025-12-09 15:43:29 +01:00
Mario Zechner
e275937982 Restructure coding-agent README for better readability
- Reorganize 30+ flat sections into 10 logical groups
- Convert verbose subsections to scannable tables (commands, shortcuts, options, tools)
- Consolidate philosophy sections (No MCP, No Sub-Agents, etc.) into single section
- Remove duplicate Development section
- Move installation/setup to top for quick onboarding
- Reduce from ~1860 lines to ~742 lines while preserving all information
2025-12-09 15:42:17 +01:00
Mario Zechner
1c55c2b5fe Add changelog entry for RPC mode breaking change (closes #91) 2025-12-09 15:34:13 +01:00
Mario Zechner
e3bbe475ae Add npm run dev instructions to DEVELOPMENT.md 2025-12-09 15:24:38 +01:00
Mario Zechner
045a24521d Update DEVELOPMENT.md with RPC mode structure 2025-12-09 15:24:09 +01:00
Mario Zechner
dc9a4b0fe4 Rewrite RPC documentation with accurate types 2025-12-09 15:19:19 +01:00
Mario Zechner
70b84532bb Update RPC example to use RpcClient 2025-12-09 14:44:13 +01:00
Mario Zechner
3c8ab0280e Add get_messages RPC command 2025-12-09 14:37:16 +01:00
Mario Zechner
2b0aa5ed8e Fix agent event ordering: update state before emitting events
Previously, Agent.emit() was called before state was updated (e.g., appendMessage).
This meant event handlers saw stale state - when message_end fired,
agent.state.messages didn't include the message yet.

Now state is updated first, then events are emitted, so handlers see
consistent state that matches the event.
2025-12-09 14:33:39 +01:00
Mario Zechner
3559a43ba0 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
b2e1054e5e Add [Unreleased] section for next development cycle 2025-12-09 13:44:59 +01:00
Mario Zechner
dbd6e5c500 Fix theme path for binary and npm builds after refactor 2025-12-09 13:43:59 +01:00
Mario Zechner
dcf81a6a1a Release v0.15.0
closes #153
2025-12-09 13:41:12 +01:00
Mario Zechner
f24ba6d7c7 Merge branch 'main' into refactor 2025-12-09 02:54:34 +01:00
DronNick
5be846802f
Added compat flags to model config example for ollama (#152) 2025-12-09 02:54:08 +01:00
Mario Zechner
66ba63050d Add test fixture for auto-compaction testing
Session at ~98% context usage, triggers auto-compaction with single prompt
2025-12-09 02:49:47 +01:00
Mario Zechner
4227fd5996 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
75c2eea151 Fix --session flag to load session messages and restore model/thinking 2025-12-09 01:59:20 +01:00
Mario Zechner
91b89578c1 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
803d4b65ee Show pending bash executions in pending area, move to chat on user submit 2025-12-09 01:39:40 +01:00
Mario Zechner
2c014c1b95 Fix bash execution interleaving with tool calls: defer message insertion while streaming 2025-12-09 01:34:31 +01:00
Mario Zechner
14d99b5f86 Move config.ts from utils/ to src/ 2025-12-09 01:28:06 +01:00
Mario Zechner
0c1a9c3091 Add code map to AGENTS.md, add DEVELOPMENT.md for coding-agent 2025-12-09 01:23:06 +01:00
Mario Zechner
6c9a264b63 Remove old implementation files (main.ts, cli.ts, tui-renderer.ts), rename new files 2025-12-09 01:21:28 +01:00
Mario Zechner
1a6a1a8acf 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
109a30b265 Deduplicate interactive-mode: consolidate message rendering, add showStatus helper 2025-12-09 01:12:19 +01:00
Mario Zechner
dbd5f5eb0b Refactor selectors: replace show/hide pairs with single showSelector helper 2025-12-09 01:04:55 +01:00
Mario Zechner
fd7f20f968 Remove unused BashExecutionMessage import 2025-12-09 01:00:11 +01:00
Mario Zechner
376b858d2b Remove unnecessary type cast in interactive-mode.ts 2025-12-09 00:59:25 +01:00
Mario Zechner
6adfb64279 Fix path resolution in config.ts after file reorganization 2025-12-09 00:54:51 +01:00
Mario Zechner
83a6c26969 Reorganize file structure: core/, utils/, modes/interactive/components/, modes/interactive/theme/ 2025-12-09 00:51:33 +01:00
Mario Zechner
00982705f2 WP16: Update main-new.ts to use InteractiveMode 2025-12-09 00:36:16 +01:00
Mario Zechner
0020de8518 WP15: Create InteractiveMode using AgentSession 2025-12-09 00:34:44 +01:00
Mario Zechner
e9f6de7cb8 WP14: Create main-new.ts and cli-new.ts using AgentSession and new modes 2025-12-09 00:21:18 +01:00
Mario Zechner
7890fb836a WP13: Create modes/index.ts barrel export 2025-12-09 00:16:46 +01:00
Mario Zechner
e7c71e7ee3 WP12: Create rpc-mode.ts 2025-12-09 00:16:17 +01:00
Mario Zechner
c0996a1078 WP11: Create print-mode.ts 2025-12-09 00:15:37 +01:00
Mario Zechner
934c2bc5d3 WP9+WP10: Add AgentSession session management and utility methods 2025-12-09 00:14:47 +01:00
Mario Zechner
94ff0b0962 WP8: Add AgentSession bash execution 2025-12-09 00:13:10 +01:00