Commit graph

350 commits

Author SHA1 Message Date
Mario Zechner
c58d5f20a4 Session tree structure with id/parentId linking
- Add TreeNode base type with id, parentId, timestamp
- Add *Content types for clean input/output separation
- Entry types are now TreeNode & *Content intersections
- SessionManager assigns id/parentId on save, tracks leafId
- Add migrateSessionEntries() for v1 to v2 conversion
- Migration runs on load, rewrites file
- buildSessionContext() uses tree traversal from leaf
- Compaction returns CompactionResult (content only)
- Hooks return compaction content, not full entries
- Add firstKeptEntryId to before_compact hook event
- Update mom package for tree fields
- Better error messages for compaction failures
2025-12-30 22:42:17 +01:00
Mario Zechner
ad10e2308e Update extension-loading.md with install/remove/update commands
- pi install <type> <source> (global default, -p for project)
- pi remove <type> <name>
- pi update [types...]
- Install adds to settings.json + installs to disk
- Global is default, -p/--project for project-local
2025-12-26 20:51:15 +01:00
Mario Zechner
31294e4749 Add extension loading design doc
Unified system for loading hooks, tools, skills, and themes from:
- Local files and directories
- npm packages (npm:pkg@version)
- Git repositories (git:url@tag or git:url#branch)

Includes filtering, atomic installation, and settings hierarchy.
2025-12-26 20:35:04 +01:00
Mario Zechner
3239a4a11a Add session version field and migrate-on-load strategy 2025-12-25 22:52:04 +01:00
Mario Zechner
013b6814e4 Clarify compaction in tree format: marker in chain, not a branch 2025-12-25 22:49:26 +01:00
Mario Zechner
64e7c80c7e Update session tree design to use UUIDs instead of indices 2025-12-25 21:19:02 +01:00
Mario Zechner
351faef604 Add session tree format design doc 2025-12-25 21:06:44 +01:00
Mario Zechner
911963e777 feat(coding-agent): Add --session-dir flag for custom session directory
- Add --session-dir CLI flag to specify custom session directory
- SessionManager API: second param of create(), continueRecent(), list(), open()
  changed from agentDir to sessionDir (direct directory, no cwd encoding)
- When omitted, uses default (~/.pi/agent/sessions/<encoded-cwd>/)
- --session now derives sessionDir from file's parent if --session-dir not provided
- list() validates session header before processing files
- Closes #313

Co-authored-by: scutifer <scutifer@users.noreply.github.com>
2025-12-25 20:27:41 +01:00
Mario Zechner
454ea1d36a 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
54018b6cc0 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
ac5f4a77cc Fix model selector not showing models with settings.json API keys
Fixes #295
2025-12-24 21:23:44 +01:00
Mario Zechner
a965b6f160 Release v0.27.8 - OAuth takes priority over settings.json API keys 2025-12-24 20:52:22 +01:00
Mario Zechner
43add86ebf Remove duplicate Custom Compaction example, reference main docs 2025-12-24 13:56:00 +01:00
Mario Zechner
705ba5d4f2 Improve compaction hooks: add signal, no timeout, SessionManager cleanup, docs 2025-12-24 13:54:05 +01:00
Mario Zechner
a2664ba38a Use clearer abbreviations in compaction diagrams 2025-12-24 12:59:45 +01:00
Mario Zechner
3c5f4920c0 Improve compaction diagrams with legend and realistic message types 2025-12-24 12:58:00 +01:00
Mario Zechner
27250c860b Add reference to compaction.ts source file 2025-12-24 12:55:47 +01:00
Mario Zechner
35a40b2197 Clarify that cut point is always user/assistant/bash, never tool result 2025-12-24 12:55:15 +01:00
Mario Zechner
5f41a384cc Add split turn diagram to compaction docs 2025-12-24 12:53:23 +01:00
Mario Zechner
699702e366 Clarify keepRecentTokens is configurable 2025-12-24 12:51:41 +01:00
Mario Zechner
51aa1339ef Add LLM context diagram to compaction docs 2025-12-24 12:49:45 +01:00
Mario Zechner
ea3ab718ea Fix compaction ASCII diagram to show append-only behavior 2025-12-24 12:49:09 +01:00
Mario Zechner
ea16af8b72 Add ASCII diagram to compaction docs 2025-12-24 12:48:16 +01:00
Mario Zechner
403faafdbe Add previousSummary to before_compact hook event 2025-12-24 12:47:12 +01:00
Mario Zechner
97bbd7a642 Clarify messagesToSummarize starts after last compaction 2025-12-24 12:44:05 +01:00
Mario Zechner
ee0befdfe1 Improve custom compaction docs in hooks.md 2025-12-24 12:43:04 +01:00
Mario Zechner
d9a542763a Improve before_compact hook: add messagesToKeep, replace apiKey with resolveApiKey 2025-12-24 12:41:22 +01:00
Mario Zechner
43a5447a80 Add resolveApiKey to before_compact hook event 2025-12-24 12:28:51 +01:00
Nico Bailon
1e1a92ea47
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
bb1da1ec51 Add API keys in settings.json, fixes #295 2025-12-24 02:11:17 +01:00
Aliou Diallo
7470dde1e9
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
2953a9d8d4
Add skipConversationRestore for before_branch hooks (#286) 2025-12-23 03:26:08 +01:00
Mario Zechner
42d7d9d9b6 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
face745f3d 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
f835f031eb SDK docs: add links to specific examples in each section 2025-12-22 12:44:41 +01:00
Mario Zechner
5d290f048e Fix SDK docs: AgentSession interface, findModel usage, settings example 2025-12-22 12:32:25 +01:00
Mario Zechner
1e6a23ab3d Update SDK docs for SettingsManager changes 2025-12-22 12:24:58 +01:00
Mario Zechner
05e1f31feb 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
d95a5c4186 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
70440f7591
feat(coding-agent): add configurable skills directories (#269) 2025-12-21 20:48:40 +01:00
Nico Bailon
74f7e6c9d5
Wrap custom tools with hooks (#248) 2025-12-19 19:05:20 +01:00
Mario Zechner
4fb3af93fb 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
e5e7b2a6a0 Improve hooks.md custom tool example with full type guard pattern 2025-12-19 00:51:21 +01:00
Mario Zechner
d353e5e219 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
3d9bad8fb6 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
05b7b81338 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
3424550d21 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
5e5bdadbf9 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
ed8ee03e22 Add available imports section to custom tools docs 2025-12-17 16:41:55 +01:00
Mario Zechner
909989066a Fix TUI performance regression: add caching to Box, use Text directly for built-in tools 2025-12-17 16:39:23 +01:00