Commit Graph

23 Commits

  • docs: Update project description with AI package information
    - Added @mariozechner/pi-ai package to the structure
    - Updated features to include unified LLM API
    - Expanded supported providers list
    - Updated tech stack with multiple SDKs
    - Added architecture details for AI package
    - Updated version numbers to current 0.5.12
    - Added testing information for AI package (Vitest)
    - Included all packages in build order example
  • chore: Mark AI package implementation task as complete
    - Moved completed AI package implementation task to done folder
    - Task successfully implemented the unified AI API (@mariozechner/pi-ai)
    - Package renamed, documentation improved, and published as v0.5.12
  • docs: Update file paths after moving AI docs to packages/ai/docs/
    - Update task.md to reference docs in new location
    - Update CLAUDE.md with project instructions
    - Update analysis.md with implementation progress
  • feat(ai): Implement unified AI API with Anthropic provider
    - Define clean API with complete() method and callbacks for streaming
    - Add comprehensive type system for messages, tools, and usage
    - Implement AnthropicAI provider with full feature support:
      - Thinking/reasoning with signatures
      - Tool calling with parallel execution
      - Streaming via callbacks (onText, onThinking)
      - Proper error handling and stop reasons
      - Cache tracking for input/output tokens
    - Add working test/example demonstrating tool execution flow
    - Support for system prompts, temperature, max tokens
    - Proper message role types: user, assistant, toolResult
  • feat(ai): Create unified AI package with OpenAI, Anthropic, and Gemini support
    - Set up @mariozechner/ai package structure following monorepo patterns
    - Install OpenAI, Anthropic, and Google Gemini SDK dependencies
    - Document comprehensive API investigation for all three providers
    - Design minimal unified API with streaming-first architecture
    - Add models.dev integration for pricing and capabilities
    - Implement automatic caching strategy for all providers
    - Update project documentation with package creation guide
  • feat(agent): Add /tokens command for cumulative token usage tracking
    Added /tokens slash command to TUI that displays session-wide token statistics.
    Key changes:
    - Fixed SessionManager to accumulate token usage instead of storing only last event
    - Added cumulative token tracking to TUI renderer alongside per-request totals
    - Implemented slash command infrastructure with /tokens autocomplete support
    - Fixed file autocompletion that was missing from Tab key handling
    - Clean minimal display format showing input/output/reasoning/cache/tool counts
    
    The /tokens command shows:
    Total usage
       input: 1,234
       output: 567
       reasoning: 89
       cache read: 100
       cache write: 50
       tool calls: 2
  • fix(tui): Fix garbled output when content exceeds viewport
    - Implemented new renderLineBased method that properly handles scrollback boundaries
    - Fixed ANSI code preservation in MarkdownComponent line wrapping
    - Added comprehensive test to reproduce and verify the fix
    - Root cause: PARTIAL rendering strategy couldn't position cursor in scrollback
    - Solution: Component-agnostic line comparison with proper viewport boundary handling
  • fix(agent): Properly handle ESC interrupt in TUI with centralized event emission
    Fixed the interrupt mechanism to show "[Interrupted by user]" message when ESC is pressed:
    - Removed duplicate UI cleanup from ESC key handler that interfered with event processing
    - Added centralized interrupted event emission in exception handler when abort signal is detected
    - Removed duplicate event emissions from API call methods to prevent multiple messages
    - Added abort signal support to preflight reasoning check for proper cancellation
    - Simplified abort detection to only check signal state, not error messages
  • fix(tui): Container change detection for proper differential rendering
    Fixed rendering artifact where duplicate bottom borders appeared when components
    dynamically shifted positions (e.g., Ctrl+C in agent clearing status container).
    
    Root cause: Container wasn't reporting as "changed" when cleared (0 children),
    causing differential renderer to skip re-rendering that area.
    
    Solution: Container now tracks previousChildCount and reports changed when
    child count changes, ensuring proper re-rendering when containers are cleared.
    
    - Added comprehensive test reproducing the layout shift artifact
    - Fixed Container to track and report child count changes
    - All tests pass including new layout shift artifact test
  • tui: Fix differential rendering to preserve scrollback buffer
    - renderDifferential now correctly handles content that exceeds viewport
    - When changes are above viewport, do full re-render with scrollback clear
    - When changes are in viewport, do partial re-render from change point
    - All tests pass, correctly preserves 100 items in scrollback
    - Issue: Still re-renders too much (entire tail from first change)
  • tui-double-buffer: Implement smart differential rendering with terminal abstraction
    - Create Terminal interface abstracting stdin/stdout operations for dependency injection
    - Implement ProcessTerminal for production use with process.stdin/stdout
    - Implement VirtualTerminal using @xterm/headless for accurate terminal emulation in tests
    - Fix TypeScript imports for @xterm/headless module
    - Move all component files to src/components/ directory for better organization
    - Add comprehensive test suite with async/await patterns for proper render timing
    - Fix critical TUI differential rendering bug when components grow in height
      - Issue: Old content wasn't properly cleared when component line count increased
      - Solution: Clear each old line individually before redrawing, ensure cursor at line start
    - Add test verifying terminal content preservation and text editor growth behavior
    - Update tsconfig.json to include test files in type checking
    - Add benchmark test comparing single vs double buffer performance
    
    The implementation successfully reduces flicker by only updating changed lines
    rather than clearing entire sections. Both TUI implementations maintain the
    same interface for backward compatibility.
  • missing-thinking-tokens: Complete task management for reasoning token support
    Moved completed task documentation to done folder after implementing reasoning token
    support for OpenAI models (o1, o3, gpt-5) across all renderers and APIs
  • docs: Add todo for automatic context length detection
    Document provider support for context length via models endpoint
    and caching strategy for model metadata
  • docs: Improve reasoning support table clarity
    - Remove redundant 'Reasoning Tokens' column (all models count them)
    - Group by provider for better readability
    - Clarify model limitations vs API limitations
    - Simplify check marks to focus on thinking content availability
  • feat(agent): Comprehensive reasoning token support across providers
    Added provider-specific reasoning/thinking token support for:
    - OpenAI (o1, o3, gpt-5): Full reasoning events via Responses API, token counts via Chat Completions
    - Groq: reasoning_format:"parsed" for Chat Completions, no summary support for Responses
    - Gemini 2.5: extra_body.google.thinking_config with <thought> tag extraction
    - OpenRouter: Unified reasoning parameter with message.reasoning field
    - Anthropic: Limited support via OpenAI compatibility layer
    
    Key improvements:
    - Centralized provider detection based on baseURL
    - parseReasoningFromMessage() extracts provider-specific reasoning content
    - adjustRequestForProvider() handles provider-specific request modifications
    - Smart reasoning support detection with caching per API type
    - Comprehensive README documentation with provider support matrix
    
    Fixes reasoning tokens not appearing for GPT-5 and other reasoning models.
  • agent: Add reasoning token support for OpenAI reasoning models
    - Extract and display reasoning tokens from both Chat Completions and Responses APIs
    - Add smart preflight detection to check reasoning support per model/API (cached per agent)
    - Support both reasoning_text (o1/o3) and summary_text (gpt-5) formats
    - Display reasoning tokens with  symbol in console and TUI renderers
    - Only send reasoning parameters to models that support them
    - Fix event type from "thinking" to "reasoning" for consistency
    
    Note: Chat Completions API only returns reasoning token counts, not content (by design).
    Only Responses API exposes actual thinking/reasoning events.
  • Display tool call metrics: Add ⚒ counter to token usage display
    - Show tool call count alongside token metrics in TUI and console renderers
    - TUI: Display at bottom with format "↑X ↓Y ⚒Z"
    - Console: Show metrics after assistant messages complete
    - Counter increments on each tool_call event
  • Initial monorepo setup with npm workspaces and dual TypeScript configuration
    - Set up npm workspaces for three packages: pi-tui, pi-agent, and pi (pods)
    - Implemented dual TypeScript configuration:
      - Root tsconfig.json with path mappings for development and type checking
      - Package-specific tsconfig.build.json for clean production builds
    - Configured lockstep versioning with sync script for inter-package dependencies
    - Added comprehensive documentation for development and publishing workflows
    - All packages at version 0.5.0 ready for npm publishing