Commit Graph

92 Commits

Author SHA1 Message Date
Mario Zechner 504d0253f6 Rename /clear to /new, update hook events to before_new/new
Closes #305 - took direct rename approach instead of alias system

Thanks @mitsuhiko for the nudge!
2025-12-25 04:15:10 +01:00
Mario Zechner aa8f7029e1 Refactor OAuth/API key handling: AuthStorage and ModelRegistry
- Add AuthStorage class for credential storage (auth.json)
- Add ModelRegistry class for model management with API key resolution
- Add discoverAuthStorage() and discoverModels() discovery functions
- Add migration from legacy oauth.json and settings.json apiKeys to auth.json
- Remove configureOAuthStorage, defaultGetApiKey, findModel, discoverAvailableModels
- Remove apiKeys from Settings type and SettingsManager methods
- Rename getOAuthPath to getAuthPath
- Update SDK, examples, docs, tests, and mom package

Fixes #296
2025-12-25 03:48:36 +01:00
Mario Zechner b244b6d41b Fix model selector not showing models with settings.json API keys
Fixes #295
2025-12-24 21:23:44 +01:00
Mario Zechner 910c8cbee1 Release v0.27.8 - OAuth takes priority over settings.json API keys 2025-12-24 20:52:22 +01:00
Mario Zechner 18340a6910 Remove duplicate Custom Compaction example, reference main docs 2025-12-24 13:56:00 +01:00
Mario Zechner 54abb5d7ff Improve compaction hooks: add signal, no timeout, SessionManager cleanup, docs 2025-12-24 13:54:05 +01:00
Mario Zechner 74a8318698 Use clearer abbreviations in compaction diagrams 2025-12-24 12:59:45 +01:00
Mario Zechner 3ecf1fe0cc Improve compaction diagrams with legend and realistic message types 2025-12-24 12:58:00 +01:00
Mario Zechner c0022c0afd Add reference to compaction.ts source file 2025-12-24 12:55:47 +01:00
Mario Zechner c44fc0cba7 Clarify that cut point is always user/assistant/bash, never tool result 2025-12-24 12:55:15 +01:00
Mario Zechner 0f11a0ff58 Add split turn diagram to compaction docs 2025-12-24 12:53:23 +01:00
Mario Zechner fafe89cc58 Clarify keepRecentTokens is configurable 2025-12-24 12:51:41 +01:00
Mario Zechner 3a5d0d49f1 Add LLM context diagram to compaction docs 2025-12-24 12:49:45 +01:00
Mario Zechner bd24b5d6ad Fix compaction ASCII diagram to show append-only behavior 2025-12-24 12:49:09 +01:00
Mario Zechner ee660923ea Add ASCII diagram to compaction docs 2025-12-24 12:48:16 +01:00
Mario Zechner e9c20357e7 Add previousSummary to before_compact hook event 2025-12-24 12:47:12 +01:00
Mario Zechner db758095fc Clarify messagesToSummarize starts after last compaction 2025-12-24 12:44:05 +01:00
Mario Zechner 8f7f41186c Improve custom compaction docs in hooks.md 2025-12-24 12:43:04 +01:00
Mario Zechner 277fd22d5f Improve before_compact hook: add messagesToKeep, replace apiKey with resolveApiKey 2025-12-24 12:41:22 +01:00
Mario Zechner c5ffdc14e9 Add resolveApiKey to before_compact hook event 2025-12-24 12:28:51 +01:00
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