Commit Graph

32 Commits

  • fix(coding-agent): truncate bash hint line to terminal width
    Fixes TUI crash on narrow terminals (< 40 chars) when displaying
    collapsed bash output with 'earlier lines' hint.
    
    fixes #941
  • refactor: use configurable keybindings for all UI hints (#724)
    Follow-up to #717. Replaces all remaining hardcoded keybinding hints with configurable ones.
    
    - Add pasteImage to AppAction so it can be configured in keybindings.json
    - Create keybinding-hints.ts with reusable helper functions:
      - editorKey(action) / appKey(keybindings, action) - get key display string
      - keyHint(action, desc) / appKeyHint(kb, action, desc) / rawKeyHint(key, desc) - styled hints
    - Export helpers from components/index.ts for extensions
    - Update all components to use configured keybindings
    - Remove now-unused getDisplayString() from KeybindingsManager and EditorKeybindingsManager
    - Use keybindings.matches() instead of matchesKey() for pasteImage in custom-editor.ts
  • fix: use configurable expandTools keybinding instead of hardcoded ctrl+o (#717)
    - Add expandTools to EditorAction in pi-tui so components can access it
    - Update bash-execution, compaction-summary-message, branch-summary-message,
      and tool-execution to use getEditorKeybindings().getKeys('expandTools')
    - Pass expandTools config to setEditorKeybindings in KeybindingsManager.create()
    - Style keybinding with 'dim' color, description with 'muted' (matches startup hints)
  • feat(tui): add overlay compositing for ctx.ui.custom() (#558)
    Adds overlay rendering capability to the TUI, enabling floating modal
    components that render on top of existing content without clearing the screen.
    
    - Add showOverlay(), hideOverlay(), hasOverlay() methods to TUI
    - Implement ANSI-aware line compositing via extractSegments()
    - Support overlay stack (multiple overlays, later on top)
    - Add { overlay: true } option to ctx.ui.custom()
    - Add overlay-test.ts example extension
    
    Also fixes pre-existing bug where bash tool output cached visual lines
    at fixed terminal width, causing crashes on terminal resize.
    
    Co-authored-by: Nico Bailon <nico.bailon@gmail.com>
  • 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.).
  • 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 non-PNG images not displaying in Kitty protocol terminals
    JPEG/GIF/WebP images were not rendering in terminals using the Kitty
    graphics protocol (Kitty, Ghostty, WezTerm) because it requires PNG
    format (f=100). Non-PNG images are now converted to PNG using sharp
    before being sent to the terminal.
  • Fix edit tool diff not showing in TUI
    The async diff preview computation could race with tool execution,
    causing editDiffPreview to contain an error (file already modified)
    while the actual tool result had the correct diff in details.diff.
    
    Fix: prioritize result.details.diff over editDiffPreview when the
    tool has executed successfully. The preview is only used before
    tool execution completes.
  • fix(coding-agent): prevent full re-renders during write tool streaming
    Move line count from header to footer to avoid changing the first line
    during streaming, which was triggering full screen re-renders in the
    TUI's differential rendering logic.
  • Show edit diff before tool execution (fixes #393)
    - Extract diff computation from edit.ts into shared edit-diff.ts
    - ToolExecutionComponent computes and caches diff when args are complete
    - Diff is visible while permission hooks block, before tool executes
  • Fix characters (#372)
    * Fix cat command
    
    * Fix text rendering crash from undefined code points in bash output
    
    * Revert unintentional model parameter changes from fix cat command commit
  • Rework custom tools API with CustomToolContext
    - CustomAgentTool renamed to CustomTool
    - ToolAPI renamed to CustomToolAPI
    - ToolContext renamed to CustomToolContext
    - ToolSessionEvent renamed to CustomToolSessionEvent
    - Added CustomToolContext parameter to execute() and onSession()
    - CustomToolFactory now returns CustomTool<any, any> for type compatibility
    - dispose() replaced with onSession({ reason: 'shutdown' })
    - Added wrapCustomTool() to convert CustomTool to AgentTool
    - Session exposes setToolUIContext() instead of leaking internals
    - Fix ToolExecutionComponent to sync with toolOutputExpanded state
    - Update all custom tool examples for new API
  • Fix tree selector gutter alignment, add page navigation, improve styling
    - Fix gutter/connector alignment by tracking gutter positions with GutterInfo
    - Convert recursive markContains to iterative to avoid stack overflow
    - Add left/right arrow keys for page up/down navigation
    - Consistent assistant message styling (green prefix, appropriate status colors)
    - Remove leaf marker (*), active path bullets are sufficient
    - Add Expandable interface for toggle expansion
    - Fix BranchSummaryMessageComponent expansion toggle
  • Fix bash tool visual line truncation
    Use visual line counting (accounting for line wrapping) instead of logical
    line counting for bash tool output in collapsed mode. Now consistent with
    bash-execution.ts behavior.
    
    - Add shared truncateToVisualLines utility
    - Update tool-execution.ts to use Box for bash with visual truncation
    - Update bash-execution.ts to use shared utility
    - Pass TUI to ToolExecutionComponent for terminal width access
    
    Fixes #275
  • Add intra-line diff highlighting for edit tool
    - Extract diff rendering to dedicated diff.ts component
    - Show word-level changes with inverse highlighting when a single line is modified
    - Use diffWords for cleaner token grouping (includes adjacent whitespace)
    - Only apply intra-line diff when exactly 1 removed and 1 added line (true modification)
    - Multi-line changes show all removed then all added without incorrect pairing
    - Add theme.inverse() method for inverse text styling
  • Syntax highlighting improvements
    - Fix cli-highlight import (use static import instead of dynamic require)
    - Add syntax highlighting to read/write tool output
    - Update dark/light themes with VS Code default syntax colors
    - Add highlightCode and getLanguageFromPath exports
    - Upgrade @google/genai to 1.34.0 for IMAGE_RECITATION/IMAGE_OTHER FinishReason
    - Add AGENTS.md rule: never downgrade code to fix type errors from outdated deps
  • 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 image limits test to use realistic payload sizes
    Previous test used compressed 8k images (0.01MB) which was meaningless.
    Now tests with actual large noise images that don't compress.
    
    Realistic payload limits discovered:
    - Anthropic: 6 x 3MB = ~18MB total (not 32MB as documented)
    - OpenAI: 2 x 15MB = ~30MB total
    - Gemini: 10 x 20MB = ~200MB total (very permissive)
    - Mistral: 4 x 10MB = ~40MB total
    - xAI: 1 x 20MB (strict request size limit)
    - Groq: 5 x 5760px images (5 image + pixel limit)
    - zAI: 2 x 15MB = ~30MB (50MB request limit)
    - OpenRouter: 2 x 5MB = ~10MB total
    
    Also fixed GEMINI_API_KEY env var (was GOOGLE_API_KEY).
    
    Related to #120
  • 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
  • Fix image rendering artifacts and improve show-images selector
    - Image component returns correct number of lines (rows) for TUI accounting
    - Empty lines rendered first, then cursor moves up and image is drawn
    - This clears the space the image occupies before rendering
    - Add spacer before inline images in tool output
    - Create ShowImagesSelectorComponent with borders like other selectors
    - Use showSelector pattern for /show-images command
  • Add /show-images command to toggle inline image display
    - Add terminal.showImages setting to settings-manager.ts
    - Add /show-images slash command (only visible if terminal supports images)
    - ToolExecutionComponent checks both terminal support and user setting
    - Shows text fallback when inline images are disabled
  • Fix hardcoded truncation limits in tool output display
    - Add maxLines and maxBytes fields to TruncationResult to track actual limits used
    - Update tool-execution.ts to use actual limits from truncation result
    - Add fallbacks to DEFAULT_MAX_* for backward compatibility with old sessions
    - Fix outdated comments that said 30KB when default is 50KB