Commit Graph

12 Commits

  • 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
  • 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
  • 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
  • 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[]
  • 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
  • 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
  • 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
  • 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