Commit Graph

72 Commits

Author SHA1 Message Date
Nico Bailon 4f36556cc8 Add before_compact hook event (closes #281) (#285)
* Add before_compact hook event (closes #281)

* Add compact hook event and documentation

- Add compact event that fires after compaction completes
- Update hooks.md with lifecycle diagram, field docs, and example
- Add CHANGELOG entry
- Add comprehensive test coverage (10 tests) for before_compact and compact events
- Tests cover: event emission, cancellation, custom entry, error handling, multiple hooks
2025-12-24 11:26:29 +01:00
Mario Zechner 26719278e2 Add API keys in settings.json, fixes #295 2025-12-24 02:11:17 +01:00
Aliou Diallo d3b8a702b9 docs: fix outdated custom tools paths and add missing header shortcut (#283)
* docs: fix custom tools example paths to use index.ts structure

* fix: add missing ctrl+g shortcut to startup header

* docs: fix /session -> /resume for session switching references
2025-12-23 03:29:31 +01:00
Nico Bailon 3fbad24af7 Add skipConversationRestore for before_branch hooks (#286) 2025-12-23 03:26:08 +01:00
Mario Zechner cc8cbf44a6 Add before/after session events with cancellation support
- Merge branch event into session with before_branch/branch reasons
- Add before_switch, before_clear, shutdown reasons
- before_* events can be cancelled with { cancel: true }
- Update RPC commands to return cancelled status
- Add shutdown event on process exit
- New example hooks: confirm-destructive, dirty-repo-guard, auto-commit-on-exit

fixes #278
2025-12-22 18:18:38 +01:00
Mario Zechner 3c93bc882f Fix SDK tools to respect cwd option
Core tools now properly use the cwd passed to createAgentSession().
Added tool factory functions for SDK users who specify custom cwd with explicit tools.

Fixes #279
2025-12-22 16:17:55 +01:00
Mario Zechner 0e7f5f6538 SDK docs: add links to specific examples in each section 2025-12-22 12:44:41 +01:00
Mario Zechner 7648a69852 Fix SDK docs: AgentSession interface, findModel usage, settings example 2025-12-22 12:32:25 +01:00
Mario Zechner 9eedaad8ae Update SDK docs for SettingsManager changes 2025-12-22 12:24:58 +01:00
Mario Zechner 59976daeb8 Add SDK documentation
- docs/sdk.md: comprehensive SDK reference
  - Core concepts (createAgentSession, AgentSession, Agent, events)
  - All options with examples
  - Discovery functions
  - Complete example

- README.md: add SDK section with brief overview and links
2025-12-22 03:20:09 +01:00
Mario Zechner 20702d2cd5 feat(coding-agent): add --skills CLI flag for filtering skills
Adds glob pattern support for skill filtering:
- --skills <patterns> CLI flag (comma-separated glob patterns)
- includeSkills setting in settings.json
- ignoredSkills now supports glob patterns
- ignoredSkills takes precedence over includeSkills and --skills

Closes #268
2025-12-21 20:58:54 +01:00
Nico Bailon bf9ecc46cd feat(coding-agent): add configurable skills directories (#269) 2025-12-21 20:48:40 +01:00
Nico Bailon 6115cd5518 Wrap custom tools with hooks (#248) 2025-12-19 19:05:20 +01:00
Mario Zechner d7d3a23857 Refactor subagent tool, fix custom tool discovery, fix JSON mode stdout flush
Breaking changes:
- Custom tools now require index.ts entry point in subdirectory
  (e.g., tools/mytool/index.ts instead of tools/mytool.ts)

Subagent tool improvements:
- Refactored to use Message[] from ai package instead of custom types
- Extracted agent discovery to separate agents.ts module
- Added parallel mode streaming (shows progress from all tasks)
- Added turn count to usage stats footer
- Removed redundant Query section from scout output

Fixes:
- JSON mode stdout flush: Fixed race condition where pi --mode json
  could exit before all output was written, causing consumers to
  miss final events

Also:
- Added signal/timeout support to pi.exec() for custom tools and hooks
- Renamed pi-pods bin to avoid conflict with pi
2025-12-19 04:54:02 +01:00
Mario Zechner 90e1dc6097 Improve hooks.md custom tool example with full type guard pattern 2025-12-19 00:51:21 +01:00
Mario Zechner 04e1d8e2fe Add type guards for tool_result event narrowing
- Export isBashToolResult, isReadToolResult, etc. type guards
- Update hooks.md with type guard usage examples
- Document custom tool handling in hooks.md
2025-12-19 00:48:03 +01:00
Mario Zechner 28db028c43 Expose full tool result content and details in hook tool_result event
Breaking change: ToolResultEvent now exposes content and typed details
instead of just a result string. Hook handlers returning { result: ... }
must change to { content: [...] }.

- ToolResultEvent is now a discriminated union based on toolName
- Each built-in tool has typed details (BashToolDetails, etc.)
- Export tool details types and TruncationResult
- Update hooks.md documentation

Closes #233
2025-12-19 00:42:08 +01:00
Mario Zechner 2ce98b36a9 Skills standard compliance
Implement Agent Skills standard (https://agentskills.io/specification):
- Validate name (must match parent dir, lowercase, max 64 chars)
- Validate description (required, max 1024 chars)
- Warn on unknown frontmatter fields
- Warn on name collisions (keep first)
- Change prompt format to XML structure
- Remove {baseDir} placeholder (use relative paths)
- Add tests and update documentation

fixes #231
2025-12-19 00:11:39 +01:00
Mario Zechner 05501329ff Improve documentation: README settings table, philosophy section, custom-tools intro, rpc hook_error event, hooks import aliases 2025-12-17 22:04:28 +01:00
Mario Zechner eea76250b8 Improve system prompt docs, clean up theme/skills/hooks docs, fix toolResults type
- System prompt: clearer pointers to specific doc files
- theme.md: added thinkingXhigh, bashMode tokens, fixed Theme class methods
- skills.md: rewrote with better framing, examples, and skill repositories
- hooks.md: fixed timeout/error handling docs, added custom tool interception note
- Breaking: turn_end event toolResults changed from AppMessage[] to ToolResultMessage[]
2025-12-17 21:27:28 +01:00
Mario Zechner cf073c23d8 Add available imports section to custom tools docs 2025-12-17 16:41:55 +01:00
Mario Zechner a63b6ab241 Fix TUI performance regression: add caching to Box, use Text directly for built-in tools 2025-12-17 16:39:23 +01:00
Mario Zechner 98685149f8 Re-export Type from typebox, update examples to import from pi-coding-agent 2025-12-17 16:10:01 +01:00
Mario Zechner 99877a8398 Custom tools with session lifecycle, examples for hooks and tools
- Custom tools: TypeScript modules that extend pi with new tools
  - Custom TUI rendering via renderCall/renderResult
  - User interaction via pi.ui (select, confirm, input, notify)
  - Session lifecycle via onSession callback for state reconstruction
  - Examples: todo.ts, question.ts, hello.ts

- Hook examples: permission-gate, git-checkpoint, protected-paths

- Session lifecycle centralized in AgentSession
  - Works across all modes (interactive, print, RPC)
  - Unified session event for hooks (replaces session_start/session_switch)

- Box component added to pi-tui

- Examples bundled in npm and binary releases

Fixes #190
2025-12-17 16:03:23 +01:00
Mario Zechner 75aaa9b4fa Add tool result streaming
- Add AgentToolUpdateCallback type and optional onUpdate callback to AgentTool.execute()
- Add tool_execution_update event with toolCallId, toolName, args, partialResult
- Normalize tool_execution_end to always use AgentToolResult (no more string fallback)
- Bash tool streams truncated rolling buffer output during execution
- ToolExecutionComponent shows last N lines when collapsed (not first N)
- Interactive mode handles tool_execution_update events
- Update RPC docs and ai/agent READMEs

fixes #44
2025-12-16 14:53:17 +01:00
Mario Zechner 64aac37812 coding-agent: change Pi skills to use SKILL.md convention
Breaking change: Pi skills must now be named SKILL.md inside a directory,
matching Codex CLI format. Previously any *.md file was treated as a skill.

Migrate by renaming ~/.pi/agent/skills/foo.md to ~/.pi/agent/skills/foo/SKILL.md
2025-12-12 23:23:17 +01:00
Nico Bailon 1de5118261 Add skills system with Claude Code compatibility (#171)
* Add skills system with Claude Code compatibility

* consolidate skills into single module, merge loaders, add <available_skills> XML tags

* add Codex CLI skills compatibility, skip hidden/symlinks
2025-12-12 18:24:52 +01:00
Mario Zechner 5509434528 mom: add coding-agent dependency, update compaction docs 2025-12-11 13:04:45 +01:00
Mario Zechner 278a37f1a8 mom: remove dynamic timestamp from system prompt for better cache hits 2025-12-11 12:26:59 +01:00
Mario Zechner 1a7a6a86f0 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 742398ae85 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 56ced9ae83 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
Mario Zechner f61b432209 Add ./hooks subpath export for cleaner imports 2025-12-10 00:56:02 +01:00
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 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 be9093ba59 Rewrite RPC documentation with accurate types 2025-12-09 15:19:19 +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 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