Commit Graph

218 Commits

  • feat(coding-agent): add interactive-shell.ts extension example
    Demonstrates running interactive commands (vim, git rebase, htop, etc.)
    with full terminal access using user_bash event and ctx.ui.custom().
    
    - Auto-detects interactive commands from built-in list
    - !i prefix to force interactive mode
    - Configurable via INTERACTIVE_COMMANDS/INTERACTIVE_EXCLUDE env vars
    
    closes #532
  • Fix --no-skills flag not preventing skills from loading
    The --no-skills flag set options.skills = [] in main.ts, but the
    interactive mode UI would rediscover skills anyway because it called
    loadSkills() directly instead of using the already-loaded skills.
    
    Changes:
    - Add AgentSession.skills and AgentSession.skillWarnings properties
    - discoverSkills() now returns { skills, warnings } instead of Skill[]
    - Interactive mode uses session.skills instead of calling loadSkills()
    - Update SDK docs and examples for new return type
    
    Fixes #577
  • feat(coding-agent): add user_bash event and theme API extensions
    - user_bash event for intercepting ! and !! commands (#528)
    - Extensions can return { operations } or { result } to redirect/replace
    - executeBashWithOperations() for custom BashOperations execution
    - session.recordBashResult() for extensions handling bash themselves
    - Theme API: getAllThemes(), getTheme(), setTheme() on ctx.ui
    - mac-system-theme.ts example: sync with macOS dark/light mode
    - Updated ssh.ts to use user_bash event
  • Allow extensions to modify system prompt in before_agent_start
    - Add systemPrompt to BeforeAgentStartEvent so extensions can see current prompt
    - Change systemPromptAppend to systemPrompt in BeforeAgentStartEventResult for full replacement
    - Extensions can now chain modifications (each sees the result of previous)
    - Update ssh.ts to replace local cwd with remote cwd in system prompt
    - Update pirate.ts, claude-rules.ts, preset.ts to use new API
    
    fixes #575
  • feat(coding-agent): add pluggable operations for remote tool execution
    Adds optional operations parameter to create*Tool functions enabling
    delegation to remote systems (SSH, containers, etc.):
    
    - ReadOperations: readFile, access, detectImageMimeType
    - WriteOperations: writeFile, mkdir
    - EditOperations: readFile, writeFile, access
    - BashOperations: exec (with streaming, signal, timeout)
    
    Add ssh.ts example demonstrating --ssh flag for remote execution.
    Built-in renderers used automatically for overrides without custom renderers.
    
    fixes #564
  • feat(coding-agent): use built-in renderers for tool overrides without custom renderers
    When overriding a built-in tool (read, bash, edit, write, grep, find, ls)
    without providing renderCall/renderResult, the built-in renderer is now
    used automatically. This allows wrapping built-in tools for logging or
    access control without reimplementing the UI (syntax highlighting, diffs, etc.).
  • feat(coding-agent): add tool override support via extensions
    - Add setActiveTools() to ExtensionAPI for dynamic tool management
    - Extensions can now override, wrap, or disable built-in tools
    - Add tool-override.ts example demonstrating the pattern
    - Update documentation for tool override capabilities
  • feat(coding-agent): export run mode utilities with options interfaces
    - Add PrintModeOptions interface, update runPrintMode signature
    - Export InteractiveMode, InteractiveModeOptions, runPrintMode, PrintModeOptions, runRpcMode from main package
    - Document run modes in docs/sdk.md with usage examples
    - Update CHANGELOG
  • refactor(coding-agent): simplify extension runtime architecture
    - Replace per-extension closures with shared ExtensionRuntime
    - Split context actions: ExtensionContextActions (required) + ExtensionCommandContextActions (optional)
    - Rename LoadedExtension to Extension, remove setter methods
    - Change runner.initialize() from options object to positional params
    - Derive hasUI from uiContext presence (no separate param)
    - Add warning when extensions override built-in tools
    - RPC and print modes now provide full command context actions
    
    BREAKING CHANGE: Extension system types and initialization API changed.
    See CHANGELOG.md for migration details.
  • feat(coding-agent): add ctx.ui.setEditorComponent() extension API
    - Add setEditorComponent() to ctx.ui for custom editor components
    - Add CustomEditor base class for extensions (handles app keybindings)
    - Add keybindings parameter to ctx.ui.custom() factory (breaking change)
    - Add modal-editor.ts example (vim-like modes)
    - Add rainbow-editor.ts example (animated text highlighting)
    - Update docs: extensions.md, tui.md Pattern 7
    - Clean up terminal on TUI render errors
  • feat(coding-agent): add timeout option to extension dialogs with live countdown
    Extension UI dialogs (select, confirm, input) now support a timeout option
    that auto-dismisses with a live countdown display. Simpler alternative to
    manually managing AbortSignal for timed dialogs.
    
    Also adds ExtensionUIDialogOptions type export and updates RPC mode to
    forward timeout to clients.
  • Add ExtensionAPI methods, preset example, and TUI documentation improvements
    - ExtensionAPI: setModel(), getThinkingLevel(), setThinkingLevel() methods
    - New preset.ts example with plan/implement presets for model/thinking/tools switching
    - Export all UI components from pi-coding-agent for extension use
    - docs/tui.md: Common Patterns section with copy-paste code for SelectList, BorderedLoader, SettingsList, setStatus, setWidget, setFooter
    - docs/tui.md: Key Rules section for extension UI development
    - docs/extensions.md: Exhaustive example links for all ExtensionAPI methods and events
    - System prompt now references docs/tui.md for TUI development
    
    Fixes #509, relates to #347
  • Export truncation utilities for custom tools, add truncated-tool example
    - Export truncateHead, truncateTail, truncateLine, formatSize, DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES from package
    - Add examples/extensions/truncated-tool.ts showing proper output truncation with custom rendering
    - Document output truncation best practices in docs/extensions.md
  • Extensions: add pi.sendUserMessage() for sending user messages
    Adds sendUserMessage() to the extension API, allowing extensions to send
    actual user messages (role: user) rather than custom messages. Unlike
    sendMessage(), this always triggers a turn and behaves as if the user
    typed the message.
    
    - Add SendUserMessageHandler type and sendUserMessage() to ExtensionAPI
    - Wire handler through loader, runner, and all modes
    - Implement via prompt() with expandPromptTemplates: false
    - Add send-user-message.ts example with /ask, /steer, /followup commands
    - Document in extensions.md
    
    fixes #483
  • Add ctx.ui.setFooter() for extensions to replace footer component
    Extensions can now replace the built-in footer with a custom component:
    - setFooter(factory) replaces with custom component
    - setFooter(undefined) restores built-in footer
    
    Includes example extension demonstrating context usage display.
    
    Closes #481
  • Add extensions option to createAgentSession SDK
    - Accept ExtensionFactory[] for inline extensions (merged with discovery)
    - Mark preloadedExtensions as @internal (CLI implementation detail)
    - Update sdk.md with inline extension example
    - Update CHANGELOG
  • Add customTools option back to createAgentSession SDK
    - Accepts ToolDefinition[] directly (simplified from old { path?, tool } format)
    - Tools are combined with extension-registered tools
    - Updated sdk.md documentation
    - Updated CHANGELOG
  • Add Custom UI section, update CHANGELOG migration docs
    - Add ## Custom UI section consolidating dialogs, widgets, custom components, message rendering, theme colors
    - Simplify ctx.ui and pi.registerMessageRenderer in other sections to reference Custom UI
    - Update CHANGELOG to reflect auto-migration of commands/ to prompts/
  • Restructure extensions.md: add Custom Tools section, improve sendMessage docs
    - Add ## Custom Tools section with Tool Definition, Multiple Tools, Custom Rendering
    - Expand pi.sendMessage docs with deliverAs mode explanations
    - Add Extension Styles subsection (single file, dir, package.json)
    - Expand ExtensionCommandContext with waitForIdle, newSession, branch, navigateTree
    - Replace lodash with zod in examples
    - Various fixes and reorganization
  • Add migration for commands->prompts, warn about deprecated hooks/tools dirs
    - Auto-migrate commands/ to prompts/ on startup
    - Warn if hooks/ or tools/ directories contain custom extensions
    - Show deprecation warnings in interactive mode with keypress to continue
    - Update CHANGELOG and docs with full migration guide
  • Merge hooks and custom-tools into unified extensions system (#454)
    Breaking changes:
    - Settings: 'hooks' and 'customTools' arrays replaced with 'extensions'
    - CLI: '--hook' and '--tool' flags replaced with '--extension' / '-e'
    - API: HookMessage renamed to CustomMessage, role 'hookMessage' to 'custom'
    - API: FileSlashCommand renamed to PromptTemplate
    - API: discoverSlashCommands() renamed to discoverPromptTemplates()
    - Directories: commands/ renamed to prompts/ for prompt templates
    
    Migration:
    - Session version bumped to 3 (auto-migrates v2 sessions)
    - Old 'hookMessage' role entries converted to 'custom'
    
    Structural changes:
    - src/core/hooks/ and src/core/custom-tools/ merged into src/core/extensions/
    - src/core/slash-commands.ts renamed to src/core/prompt-templates.ts
    - examples/hooks/ and examples/custom-tools/ merged into examples/extensions/
    - docs/hooks.md and docs/custom-tools.md merged into docs/extensions.md
    
    New test coverage:
    - test/extensions-runner.test.ts (10 tests)
    - test/extensions-discovery.test.ts (26 tests)
    - test/prompt-templates.test.ts
  • Fix event bus async error handling, clear pending messages on session switch, improve SDK docs
    - event-bus.ts: await async handlers to catch errors properly
    - agent-session.ts: clear _pendingNextTurnMessages on newSession/switchSession/branch
    - sdk.ts: make eventBus first (required) param for discoverHooks/discoverCustomTools
    - docs/sdk.md: document eventBus sharing pattern for hook/tool communication
  • feat(coding-agent): add event bus for tool/hook communication (#431)
    * feat(coding-agent): add event bus for tool/hook communication
    
    Adds pi.events API enabling custom tools and hooks to communicate via
    pub/sub. Tools can emit events, hooks can listen. Shared EventBus instance
    created per session in createAgentSession().
    
    - EventBus interface with emit() and on() methods
    - on() returns unsubscribe function
    - Threaded through hook and tool loaders
    - Documented in hooks.md and custom-tools.md
    
    * fix(coding-agent): wrap event handlers to catch errors
    
    * docs: note async handler error handling for event bus
    
    * feat(coding-agent): add sendMessage to tools, nextTurn delivery mode
    
    - Custom tools now have pi.sendMessage() for direct agent notifications
    - New deliverAs: 'nextTurn' queues messages for next user prompt
    - Fix: hooks and tools now share the same eventBus (was isolated before)
    
    * fix(coding-agent): nextTurn delivery should always queue, even when streaming
  • docs: update CHANGELOG and hooks.md with missing items
    - tools.ts example hook
    - Multiple messages from before_agent_start
    - getSettingsListTheme/getSelectListTheme optional theme param
    - Hook error stack traces
  • feat(hooks): add systemPromptAppend to before_agent_start, full tool registry
    - before_agent_start handlers can return systemPromptAppend to dynamically
      append text to the system prompt for that turn
    - Multiple hooks' systemPromptAppend strings are concatenated
    - Multiple hooks' messages are now all injected (not just first)
    - Tool registry now contains ALL built-in tools (read, bash, edit, write,
      grep, find, ls) regardless of --tools flag
    - --tools only sets initially active tools, hooks can enable any via
      setActiveTools()
    - System prompt automatically rebuilds when tools change, updating tool
      descriptions and guidelines
    - Add pirate.ts example hook demonstrating systemPromptAppend
    - Update hooks.md with systemPromptAppend documentation
  • refactor: address PR feedback - merge setWidget, use KeyId for shortcuts
    1. Merge setWidget and setWidgetComponent into single overloaded method
       - Accepts either string[] or component factory function
       - Uses single Map<string, Component> internally
       - String arrays wrapped in Container with Text components
    
    2. Use KeyId type for registerShortcut instead of plain string
       - Import Key from @mariozechner/pi-tui
       - Update plan-mode example to use Key.shift('p')
       - Type-safe shortcut registration
    
    3. Fix tool API docs
       - Both built-in and custom tools can be enabled/disabled
       - Removed incorrect 'custom tools always active' statement
    
    4. Use matchesKey instead of matchShortcut (already done in rebase)
  • feat(hooks): add setWidgetComponent for custom TUI components
    - New ctx.ui.setWidgetComponent(key, factory) method
    - Allows custom Component to render as widget without taking focus
    - Unlike custom(), widget components render inline above editor
    - Components are disposed when cleared or replaced
    - Falls back to no-op in RPC/print modes
  • fix(widgets): add max line limit and document multi-hook behavior
    - Limit total widget lines to 10 to prevent viewport overflow/flicker
    - Show '... (widget truncated)' when limit exceeded
    - Document that multiple hooks stack widgets vertically
    - Add caution about keeping widgets small
  • refactor(hooks): address PR feedback
    - Rename getTools/setTools to getActiveTools/setActiveTools
    - Add getAllTools to enumerate all configured tools
    - Remove text_delta event (use turn_end/agent_end instead)
    - Add shortcut conflict detection:
      - Skip shortcuts that conflict with built-in shortcuts (with warning)
      - Log warnings when hooks register same shortcut (last wins)
    - Add note about prompt cache invalidation in setActiveTools
    - Update plan-mode hook to use agent_end for [DONE:id] parsing
  • feat(hooks): add text_delta event for streaming text monitoring
    - New text_delta hook event fires for each chunk of streaming text
    - Enables real-time monitoring of agent output
    - Plan-mode hook now updates todo progress as [DONE:id] tags stream in
    - Each todo item has unique ID for reliable tracking
  • feat(hooks): add setWidget API for multi-line status displays
    - ctx.ui.setWidget(key, lines) for multi-line displays above editor
    - Widgets appear below 'Working...' indicator, above editor
    - Supports ANSI styling including strikethrough
    - Added theme.strikethrough() method
    - Plan-mode hook now shows todo list with checkboxes
    - Completed items show checked box and strikethrough text
  • feat(coding-agent): add hook API for CLI flags, shortcuts, and tool control
    Hook API additions:
    - pi.getTools() / pi.setTools(toolNames) - dynamically enable/disable tools
    - pi.registerFlag(name, options) / pi.getFlag(name) - register custom CLI flags
    - pi.registerShortcut(shortcut, options) - register keyboard shortcuts
    
    Plan mode hook (examples/hooks/plan-mode.ts):
    - /plan command or Shift+P shortcut to toggle
    - --plan CLI flag to start in plan mode
    - Read-only tools: read, bash, grep, find, ls
    - Bash restricted to non-destructive commands (blocks rm, mv, git commit, etc.)
    - Interactive prompt after each response: execute, stay, or refine
    - Shows plan indicator in footer when active
    - State persists across sessions
  • WIP: Add hook API for dynamic tool control with plan-mode hook example
    - Add pi.getTools() and pi.setTools(toolNames) to HookAPI
    - Hooks can now enable/disable tools dynamically
    - Changes take effect on next agent turn
    
    New example hook: plan-mode.ts
    - Claude Code-style read-only exploration mode
    - /plan command toggles plan mode on/off
    - Plan mode tools: read, bash, grep, find, ls
    - Edit/write tools disabled in plan mode
    - Injects context telling agent about restrictions
    - After each response, prompts to execute/stay/refine
    - State persists across sessions