Commit graph

738 commits

Author SHA1 Message Date
Mario Zechner
bb445d24f1 Auto-retry on transient provider errors (overloaded, rate limit, 5xx)
- Add retry logic with exponential backoff (2s, 4s, 8s) in AgentSession
- Disable Anthropic SDK built-in retries (maxRetries: 0) to allow app-level handling
- TUI shows retry status with Escape to cancel
- RPC mode: add set_auto_retry, abort_retry commands and auto_retry_start/end events
- Configurable via settings.json: retry.enabled, retry.maxRetries, retry.baseDelayMs
- Exclude context overflow errors from retry (handled by compaction)

fixes #157
2025-12-10 23:36:46 +01:00
Mario Zechner
79f5c6d22e Fix git branch indicator in subdirectories
Walk up directory hierarchy to find .git/HEAD instead of only checking cwd.

fixes #156
2025-12-10 22:52:19 +01:00
Mario Zechner
3d35e7c469 Fix branch selector for single message and --no-session mode
- Allow branch selector to open with single user message (changed <= 1 to === 0 check)
- Support in-memory branching for --no-session mode (no files created)
- Add isEnabled() getter to SessionManager
- Update sessionFile getter to return null when sessions disabled
- Update SessionSwitchEvent types to allow null session files
- Add branching tests for single message and --no-session scenarios

fixes #163
2025-12-10 22:41:32 +01:00
Mario Zechner
09a48fd1c3 feat: add line number display to HTML export for read tool calls
Implements line number display in HTML exports for read tool calls, matching the TUI format.
When offset/limit parameters are provided, displays path:startLine-endLine in yellow color.

Fixes #166
2025-12-10 22:05:14 +01:00
Mario Zechner
751e10e78b Add [Unreleased] section to changelogs 2025-12-10 21:41:50 +01:00
Mario Zechner
f931c57726 Release v0.18.1 2025-12-10 21:25:15 +01:00
Mario Zechner
1ce09681b1 Add issue links to changelog entries 2025-12-10 21:24:05 +01:00
Mario Zechner
c91afd76f1 Update changelogs for recent fixes 2025-12-10 21:23:08 +01:00
Mario Zechner
7323af1f69 fixes #161: stop theme watcher and exit cleanly in print mode
The theme file watcher was keeping the Node.js process alive indefinitely
even in print mode where hot-reload is unnecessary. This simple fix calls
stopThemeWatcher() and process.exit(0) after print mode completes.

- Added stopThemeWatcher() call after runPrintMode() completes
- Added process.exit(0) to ensure clean process termination
- Imported stopThemeWatcher from theme module

This is a minimal fix that addresses the symptom (process hanging) without
changing the theme initialization logic.
2025-12-10 21:16:47 +01:00
Mario Zechner
9516424cae fixes #161: disable theme watcher in print mode
The theme file watcher was keeping the Node.js process alive indefinitely
even in print mode where hot-reload is unnecessary. This fix adds an
enableWatcher parameter to initTheme() and setTheme() functions, and only
enables watchers in interactive mode.

- Modified initTheme() to accept enableWatcher parameter (default: false)
- Modified setTheme() to accept enableWatcher parameter (default: false)
- Updated main.ts to only enable watchers in interactive mode
- Updated InteractiveMode to enable watchers when changing themes
2025-12-10 21:16:47 +01:00
Mario Zechner
76312ea7e8 Fix Mistral 400 errors after aborted assistant messages
- Skip empty assistant messages (no content, no tool calls) to avoid
  Mistral's 'Assistant message must have either content or tool_calls'
  error
- Remove synthetic assistant bridge message after tool results (Mistral
  no longer requires this as of Dec 2024)
- Add test for empty assistant message handling

Follow-up to #165
2025-12-10 21:13:33 +01:00
Mario Zechner
99b4b1aca0 Add Mistral as AI provider
- Add Mistral to KnownProvider type and model generation
- Implement Mistral-specific compat handling in openai-completions:
  - requiresToolResultName: tool results need name field
  - requiresAssistantAfterToolResult: synthetic assistant message between tool/user
  - requiresThinkingAsText: thinking blocks as <thinking> text
  - requiresMistralToolIds: tool IDs must be exactly 9 alphanumeric chars
- Add MISTRAL_API_KEY environment variable support
- Add Mistral tests across all test files
- Update documentation (README, CHANGELOG) for both ai and coding-agent packages
- Remove client IDs from gemini.md, reference upstream source instead

Closes #165
2025-12-10 20:36:19 +01:00
Lukas Pitschl
a248e2547a
fix(ai): remove global process.env.ANTHROPIC_API_KEY deletion (#164)
* fix(ai): remove global process.env.ANTHROPIC_API_KEY deletion

The code was deleting process.env.ANTHROPIC_API_KEY to prevent the SDK
from using it when OAuth tokens were provided. However, this was a global
mutation that affected the entire Node.js process, causing the API key to
be unavailable after the first prompt.

The Anthropic SDK constructor already handles credential selection via
parameters (apiKey: null, authToken: token for OAuth vs apiKey: key for
regular keys), so the environment variable deletion was unnecessary.

* Update CHANGELOG.md for API key fix
2025-12-10 18:12:16 +01:00
Mario Zechner
7785b7c93f Release v0.18.0 2025-12-10 01:18:13 +01:00
Mario Zechner
7742f7b653 Credit nicobailon for hooks collaboration 2025-12-10 01:01:15 +01:00
Mario Zechner
c7afa35e1b Add hooks to changelog (closes #145, supersedes #158) 2025-12-10 01:00:32 +01:00
Mario Zechner
1abc635044 Add ./hooks subpath export for cleaner imports 2025-12-10 00:56:02 +01:00
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
02c7f9ea51 Port truncation logic from coding-agent to mom
- Add truncate.ts with 2000 lines / 50KB limits
- Update bash tool with tail truncation and temp file output
- Update read tool with head truncation and offset hints
- Remove redundant context history truncation (tools already provide actionable hints)

fixes #155
2025-12-09 16:05:08 +01:00
Mario Zechner
de3fd172a9 Update generated models 2025-12-09 15:44:45 +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