Commit graph

38 commits

Author SHA1 Message Date
Mario Zechner
f064ea0e14 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
2025-08-17 20:18:45 +02:00
Mario Zechner
2c03724862 fix: Remove unused imports and add biome-ignore for false positive
- Remove unused SlashCommand import from tui-renderer.ts
- Add biome-ignore comment for previousRenderCommands which is actually used
2025-08-16 19:21:43 +02:00
Mario Zechner
3fe1f4c11e Update todos.md 2025-08-16 19:18:07 +02:00
Mario Zechner
5bbaaa0773 Formatting 2025-08-11 21:22:11 +02:00
Mario Zechner
42bf7b4ae0 Add husky pre-commit hook for formatting and type checking 2025-08-11 21:15:37 +02:00
Mario Zechner
e21a46e68f 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
2025-08-11 15:43:48 +02:00
Mario Zechner
7e3b94ade6 style(tui): Apply biome formatting fixes 2025-08-11 14:18:33 +02:00
Mario Zechner
6e40c5d761 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
2025-08-11 14:17:46 +02:00
Mario Zechner
1d9b77298c 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
2025-08-11 12:21:13 +02:00
Mario Zechner
1f9d10cab0 Fix file paths. 2025-08-11 02:32:52 +02:00
Mario Zechner
192d8d2600 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
2025-08-11 02:31:49 +02:00
Mario Zechner
2ec8a27222 feat(tui): Add instructional header and welcome message to chat demo
- Add header with slash command and file autocomplete instructions
- Add initial welcome message with detailed feature descriptions
- Import TextComponent for the header
- Make it clearer how to use all the demo features
2025-08-11 01:36:18 +02:00
Mario Zechner
5ceaa91c74 fix(tui): Trigger initial render when start() is called
The demos were not showing any output until user input because:
- Components were added before ui.start() was called
- addChild calls requestRender() but it returns early if \!isStarted
- So no initial render happened until user input triggered one

Now ui.start() triggers an initial render if components exist.
2025-08-11 01:34:32 +02:00
Mario Zechner
838fde47ba refactor(tui): Move examples from README to test directory
- Move chat application example to test/chat-app.ts
- Move multi-component layout example to test/multi-layout.ts
- Update README to reference example files instead of inline code
- Add proper exit handlers (Ctrl+C) to all examples
- Simplify README by reducing inline code examples
2025-08-11 01:29:43 +02:00
Mario Zechner
12dfcfad23 docs(tui): Update README with surgical differential rendering documentation
- Add surgical differential rendering as the main feature
- Document the three rendering strategies (surgical, partial, full)
- Add performance metrics documentation
- Simplify component examples to be more concise
- Add comprehensive testing section with VirtualTerminal API
- Include testing best practices and performance testing guidance
- Remove duplicate TextEditor documentation section
2025-08-11 01:22:45 +02:00
Mario Zechner
386f90fc36 tui: Implement surgical differential rendering for minimal redraws
- New renderDifferentialSurgical method with three strategies:
  - SURGICAL: Only update specific changed lines (1-2 lines per render)
  - PARTIAL: Clear and re-render from first change when line counts change
  - FULL: Clear scrollback and re-render all when changes above viewport
- Preserves all content in scrollback buffer correctly
- Reduces redraws from ~14 lines to ~1.3 lines for common updates
- All 24 tests pass including scrollback preservation tests
- Massive performance improvement: 90% reduction in unnecessary redraws
2025-08-11 01:13:42 +02:00
Mario Zechner
0131b29b2c 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)
2025-08-11 00:57:59 +02:00
Mario Zechner
afa807b200 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.
2025-08-10 22:33:03 +02:00
Mario Zechner
923a9e58ab 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
2025-08-10 14:38:25 +02:00
Mario Zechner
5d13a90077 docs: Add context window percentage to token usage display todo 2025-08-10 10:38:52 +02:00
Mario Zechner
f36299ad3a docs: Add todo for automatic context length detection
Document provider support for context length via models endpoint
and caching strategy for model metadata
2025-08-10 10:33:59 +02:00
Mario Zechner
8bee281010 Updated todos.md 2025-08-10 02:15:30 +02:00
Mario Zechner
f82e82da93 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
2025-08-10 02:13:13 +02:00
Mario Zechner
047d9af407 docs: Fix outdated Gemini thinking content notes
Gemini 2.5 thinking content IS fully supported - we handle extra_body automatically
2025-08-10 01:56:20 +02:00
Mario Zechner
99ce76d66e 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.
2025-08-10 01:46:15 +02:00
Mario Zechner
62d9eefc2a 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.
2025-08-10 00:32:30 +02:00
Mario Zechner
9157411034 Updated agent README.md with test advise 2025-08-09 21:17:46 +02:00
Mario Zechner
832b20b173 v0.5.7: Fix tool counter spacing in metrics display 2025-08-09 20:19:04 +02:00
Mario Zechner
9fee306075 v0.5.6: Fix CLI execution when installed globally 2025-08-09 20:16:59 +02:00
Mario Zechner
db86195dd9 v0.5.5: Add tool call metrics display 2025-08-09 20:11:06 +02:00
Mario Zechner
9544a8edf9 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
2025-08-09 20:10:15 +02:00
Mario Zechner
1887e33339 v0.5.4 - Fix CLI execution when imported and JSON import issues 2025-08-09 19:38:00 +02:00
Mario Zechner
f579a3f112 v0.5.4 - Fix lockstep versioning and update all packages 2025-08-09 19:37:12 +02:00
Mario Zechner
3a9c3a2ed6 v0.5.3 - Fix missing scripts directory in published package 2025-08-09 19:26:59 +02:00
Mario Zechner
42dc46a513 Fix process.cwd() error when running from deleted directory
- Defer process.cwd() call in logger to avoid initialization errors
- Resolve log file path only when actually writing logs
- Bump version to 0.5.2
2025-08-09 18:05:28 +02:00
Mario Zechner
d304f377d7 Fix pi-agent CLI execution issue when installed globally
- Remove isMainModule check that was preventing execution via npm symlink
- CLI now runs main function directly when executed
- Bump version to 0.5.1
2025-08-09 18:02:34 +02:00
Mario Zechner
c615f3f011 Fix npm publishing warnings and clean up package.json files
- Fixed repository URLs to use git+https:// format
- Removed tsconfig.tsbuildinfo from clean scripts
- Updated README with clearer build instructions and dependency order
- Fixed bin paths to reference dist/cli.js correctly
- Ready for npm publishing with no warnings
2025-08-09 17:27:16 +02:00
Mario Zechner
a74c5da112 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
2025-08-09 17:18:38 +02:00