Commit graph

43 commits

Author SHA1 Message Date
Mario Zechner
f0ab8db40f Expand pi.sendMessage and registerMessageRenderer docs in hooks.md
- sendMessage: document storage timing, LLM context, TUI display
- registerMessageRenderer: document renderer signature, return null for default
2025-12-31 14:34:30 +01:00
Mario Zechner
8e1e99ca05 Change branch() to use entryId instead of entryIndex
- AgentSession.branch(entryId: string) now takes entry ID
- SessionBeforeBranchEvent.entryId replaces entryIndex
- getUserMessagesForBranching() returns entryId
- Update RPC types and client
- Update UserMessageSelectorComponent
- Update hook examples and tests
- Update docs (hooks.md, sdk.md)
2025-12-31 13:47:34 +01:00
Mario Zechner
84b663276d Add creation hints to docs and update system prompt
- System prompt now instructs to read docs AND examples, follow cross-refs
- Each doc starts with 'pi can create X. Ask it to build one.'
2025-12-31 13:16:44 +01:00
Mario Zechner
20fbf40fac Add tui.md and improve TUI documentation
- New tui.md covers component system for hooks and custom tools
- Update hooks.md intro with 'Key capabilities' highlighting UI
- Update custom-tools.md intro with 'Key capabilities' highlighting UI
- Reference tui.md from both docs
2025-12-31 13:05:59 +01:00
Mario Zechner
29e0ed9cd1 Improve hooks.md UI documentation
- Add 'Key capabilities' section highlighting UI features
- Expand ctx.ui docs with custom component details
- Reference snake.ts example for custom UI
2025-12-31 13:02:28 +01:00
Mario Zechner
88e39471ea Remove hook execution timeouts
- Remove timeout logic from HookRunner
- Remove hookTimeout from Settings interface
- Remove getHookTimeout/setHookTimeout methods
- Update CHANGELOG.md and hooks.md

Timeouts were inconsistently applied and caused issues with
legitimate slow operations (LLM calls, user prompts). Users can
use Ctrl+C to abort hung hooks.
2025-12-31 12:57:54 +01:00
Mario Zechner
bab343b8bc Update hooks.md: clarify session_before_tree, document all sessionManager methods 2025-12-31 12:44:52 +01:00
Mario Zechner
679343de55 Add compaction.md and rewrite hooks.md
- New compaction.md covers auto-compaction and branch summarization
- Explains cut points, split turns, data model, file tracking
- Documents session_before_compact and session_before_tree hooks

- Rewritten hooks.md matches actual API (separate event names)
- Correct ctx.ui.custom() signature (returns handle, not callback)
- Documents all session events including tree events
- Adds sessionManager and modelRegistry usage
- Updates all examples to use correct API
2025-12-31 12:33:13 +01:00
Mario Zechner
450d77fb79 Update hooks.md and session.md for consolidated HookContext
- HookEventContext renamed to HookContext (used for events and commands)
- RegisteredCommand.handler: (ctx) -> (args, ctx)
- before_compact: previousCompactions -> branchEntries, model moved to ctx.model
- ctx.exec -> pi.exec in examples
- ctx.sessionFile -> ctx.sessionManager.getSessionFile()
- CompactionPreparation: document turnPrefixMessages, isSplitTurn, previousSummary
- session.md: clarify details field for compaction/branch summary
2025-12-31 02:40:31 +01:00
Mario Zechner
a9479458ee Update CHANGELOG.md and docs for session tree release
CHANGELOG.md:
- Add /tree command, context event, before_agent_start event
- Add ui.custom(), branch summarization, selectedBg theme color
- Add snake game example hook
- Add external contributions: CRLF fix, bash on Unix, clickable OAuth, error messages
- Update theme requirements (50 total colors)

session.md:
- Complete rewrite for v2 tree structure
- Document all entry types with examples
- Add SessionManager API reference

hooks.md:
- Replace pi.send() with pi.sendMessage()
- Add pi.appendEntry(), pi.registerCommand(), pi.registerMessageRenderer()
- Move exec() from ctx to pi.exec()
- Add ui.custom() for custom TUI components
- Add context and before_agent_start events
- Update before_compact event fields
- Add ctx.sessionManager and ctx.modelRegistry
2025-12-31 00:39:20 +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
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
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
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
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
e7097d911a 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
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
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
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