Commit graph

55 commits

Author SHA1 Message Date
Mario Zechner
3018b01460 Fix slash command autocomplete Enter behavior
When pressing Enter on a highlighted slash command suggestion (e.g., typing
`/mod` with `/model` highlighted), the completion is now applied before
submitting. Previously, the partial text was submitted instead of the
selected command.

Fixes #49
2025-11-21 21:50:19 +01:00
Mario Zechner
59af0fd53a fix: markdown link rendering for links with identical text and href 2025-11-21 20:14:32 +01:00
Mario Zechner
1d8bc9d6eb Fix path completion hanging and autocomplete arrow key behavior
- Fixed catastrophic regex backtracking in extractPathPrefix that caused
  terminal to hang when text contained many / characters (e.g., URLs).
  Replaced complex regex with simple lastIndexOf approach. (#18)
- Fixed arrow keys moving both autocomplete selection and editor cursor
  by adding missing return statement after handling arrow keys in
  autocomplete mode.

Closes #18
2025-11-21 12:47:23 +01:00
Mario Zechner
85adcf22bf Release v0.8.0 2025-11-21 03:12:42 +01:00
Mario Zechner
cc88095140 WIP: Add theming system with /theme command
- Consolidated theme system into single src/theme/ directory
- Created Theme class with fg(), bg(), bold(), italic(), underline()
- Added dark and light built-in themes with 36 color tokens
- Support for custom themes in ~/.pi/agent/themes/*.json
- JSON schema for theme validation
- Theme selector UI with /theme command
- Save theme preference to settings
- Uses chalk for text formatting to preserve colors

TODO:
- Replace hardcoded colors throughout TUI components
- Apply markdown theming to Markdown components
- Add theme support to all TUI elements
2025-11-20 23:16:59 +01:00
Mario Zechner
93a60b7969 Downgrade Biome to 2.3.5 to fix false positive noUnusedPrivateClassMembers warnings 2025-11-20 22:32:45 +01:00
Mario Zechner
d44073b140 Release v0.7.28
- Add message queuing with configurable modes (one-at-a-time/all) (#15)
- Add /queue command to select queue mode
- Add TruncatedText component for proper viewport-aware text truncation
- Queue mode setting persists in ~/.pi/agent/settings.json
- Visual feedback for queued messages with proper ANSI handling
- Press Escape to abort and restore queued messages to editor
2025-11-20 20:39:43 +01:00
Mario Zechner
e694d435fd Release v0.7.27
- Fix slash command submission requiring two Enter presses (#30)
- Fix slash command autocomplete not re-triggering after typos (#29)
2025-11-20 18:56:27 +01:00
Mario Zechner
973a129407 Merge PR #36: Add Shift+Tab thinking level cycling with visual border feedback 2025-11-20 12:34:12 +01:00
Mario Zechner
b3d4478b61 Release v0.7.23 2025-11-20 11:59:17 +01:00
Tino Ehrich
0df48f6b33 feat: add visual thinking level indicator via border colors
The horizontal borders around the input editor now change color based on
the current thinking level, providing immediate visual feedback:

- off: gray (default)
- minimal: dim blue
- low: blue
- medium: cyan
- high: magenta

The more thinking, the brighter/more vibrant the color.

Changes:
- Add public borderColor property to Editor component (packages/tui)
- Use borderColor instead of hardcoded chalk.gray for borders
- Add getThinkingBorderColor() helper in TuiRenderer
- Add updateEditorBorderColor() to apply color changes
- Update border color when:
  - Cycling with Tab key
  - Selecting via /thinking command
  - Restoring session with thinking level set
2025-11-19 12:12:10 +01:00
Mario Zechner
1f68d6eb40 Release v0.7.22 2025-11-19 01:50:45 +01:00
Mario Zechner
1b28780155 Release v0.7.21 2025-11-19 00:56:16 +01:00
Mario Zechner
38ac29acfb Add ANSI-aware word wrapping to TUI components
- Created shared wrapTextWithAnsi() function in utils.ts
- Handles word-based wrapping while preserving ANSI escape codes
- Properly tracks active ANSI codes across wrapped lines
- Supports multi-byte characters (emoji, surrogate pairs)
- Updated Markdown and Text components to use shared wrapping
- Removed duplicate wrapping logic (158 lines total)
2025-11-18 22:26:24 +01:00
Mario Zechner
22d8a0ae4a Release v0.7.18 2025-11-18 22:08:44 +01:00
Mario Zechner
587d7c39a4 feat(coding-agent): add OAuth authentication for Claude Pro/Max
- Add /login and /logout commands for OAuth flow
- OAuth tokens stored in ~/.pi/agent/oauth.json with 0600 permissions
- Auto-refresh tokens when expired (5min buffer)
- Priority: OAuth > ANTHROPIC_OAUTH_TOKEN env > ANTHROPIC_API_KEY env
- Fix model selector async loading and re-render
- Add bracketed paste support to Input component for long codes
- Update README.md with OAuth documentation
- Add implementation docs and testing checklist
2025-11-18 17:33:33 +01:00
Mario Zechner
3b6ef6cf57 refactor(tui): Use explicit charCode check for unicode filtering
- Use 'charCodeAt(0) >= 32' instead of open 'else' in handleInput()
- Use same filter in handlePaste() for consistency
- Prevents control characters while allowing all unicode
- More explicit and safer than accepting everything
2025-11-16 23:05:19 +01:00
Mario Rodler
ce0c42f539 test(editor): Add tests for handling extended characters, emojis, and special key inputs 2025-11-16 18:15:21 +01:00
Mario Rodler
c8dcf1cdae feat(tui): Editor now handles extended character input (e.g., umlauts) and updates key binding documentation 2025-11-16 18:09:17 +01:00
Mario Zechner
a686f61c1d feat(tui): improve editor Ctrl/Alt word and line deletion shortcuts
- Add Ctrl+W for word deletion (stops at whitespace/punctuation)
- Add Ctrl+U for delete to start of line (merges with previous line at col 0)
- Change Ctrl+K from delete entire line to delete to end of line (merges with next line at EOL)
- Add Option+Backspace support in Ghostty (maps to Ctrl+W via ESC+DEL sequence)
- Cmd+Backspace in Ghostty works as Ctrl+U (terminal sends same control code)
- Update README and CHANGELOG with new keyboard shortcuts

Fixes #2, Fixes #3
2025-11-14 23:19:24 +01:00
Mario Zechner
c23f1576dc Fix markdown component nested list rendering. 2025-11-13 21:43:18 +01:00
Mario Zechner
97ac82312f fix: update footer state when rendering initial messages on resume/continue 2025-11-13 00:58:20 +01:00
Mario Zechner
60e4fcf012 docs: simplify MCP section with clear stance and minimal example
- State upfront: pi does not support MCP
- Provide minimal working example (README + bash script)
- Show simple usage pattern
- Remove verbose explanations

fix(tui): don't show duplicate URL when link text equals href
2025-11-12 23:00:27 +01:00
Mario Zechner
c75f53f6f2 Improve edit tool diff display with context-aware rendering
- Add generateDiffString() function in edit tool to create unified diffs with line numbers and 4 lines of context
- Store only the formatted diff string in tool result details instead of full file contents
- Update tool-execution renderer to parse and colorize the diff string
- Filter out message_update events from session saving to prevent verbose session files
- Add markdown nested list and table rendering tests
2025-11-12 20:09:11 +01:00
Mario Zechner
a6e300693d Redesign session selector with multi-line layout
- Custom SessionList component with 2 lines per item
- First line: message text (bold when selected)
- Second line: metadata (time · message count) in dim
- Blue › cursor for selected item
- Added "Resume Session" header
- Handle Ctrl+C (‹x03›) in SelectList for consistency
- Improved date formatting (38 minutes ago, 8 hours ago, etc.)
2025-11-12 09:25:40 +01:00
Mario Zechner
c531304d5d Fix emoji and multi-byte character handling in markdown wrapping 2025-11-12 09:07:48 +01:00
Mario Zechner
02a21dd936 Fix viewport width issues in thinking selector and text rendering
Thinking selector fix:
- Replace hardcoded 50-character borders with DynamicBorder component
  that adjusts to viewport width
- Prevents crash when terminal is resized narrow

Text/Markdown rendering fixes:
- Fix Markdown wrapSingleLine to check if adding next character would
  exceed width BEFORE adding it (was checking AFTER, causing lines to
  be 1 character too long)
- Add word truncation in Text component for words longer than
  contentWidth (prevents long unbreakable words from exceeding width)

These fixes prevent "Rendered line exceeds terminal width" errors.
2025-11-11 23:52:18 +01:00
Mario Zechner
a3b3849188 Fix SelectList crash on narrow terminal and thinking level restoration
SelectList fixes:
- Use hardcoded visual width for arrow prefix instead of string length
  which includes ANSI codes
- Truncate scroll indicator text to prevent exceeding terminal width
- Fixes crash when terminal is resized narrow and arrow keys are pressed

Thinking level fix:
- Restore thinking level even if it's "off" (removed !== "off" check)
- This ensures the thinking level selector shows the correct state on continue
2025-11-11 23:47:59 +01:00
Mario Zechner
001beff394 Fix tab rendering in TUI components
Replace tabs with 3 spaces for consistent rendering and width calculation:
- Updated visibleWidth() to normalize tabs before measuring
- Updated Text and Markdown components to replace tabs when rendering
- Updated tool-execution display for read/write tools to replace tabs

This fixes background color rendering issues when displaying files with tab indentation.
2025-11-11 23:24:48 +01:00
Mario Zechner
159075cad7 Improve tool execution rendering and error handling
- Show tool execution components immediately when tool calls appear in streaming
- Update components with streaming arguments as they come in
- Handle incomplete/partial arguments gracefully with optional chaining
- Fix error handling: tools now throw exceptions instead of returning error messages
- Fix bash abort handling to properly reject on abort/timeout
- Clean up error display
2025-11-11 23:05:58 +01:00
Mario Zechner
741add4411 Refactor TUI into proper components
- Create UserMessageComponent - handles user messages with spacing
- Create AssistantMessageComponent - handles complete assistant messages
- Create ThinkingSelectorComponent - wraps selector with borders
- Add setSelectedIndex to SelectList for preselecting current level
- Simplify tui-renderer by using dedicated components
- Much cleaner architecture - each message type is now a component
2025-11-11 21:55:29 +01:00
Mario Zechner
e2649341f0 Simplify assistant message spacing - just add spacer to components 2025-11-11 21:51:12 +01:00
Mario Zechner
5d7bc60cff Replace Markdown with Text component for tool execution
- Add background color support to Text component
- Replace Markdown component with Text in ToolExecutionComponent
- Use chalk.bold for formatting instead of markdown syntax
- Remove unnecessary markdown parsing overhead
2025-11-11 21:27:23 +01:00
Mario Zechner
fb4893d8d4 Clear scrollback buffer on full TUI re-renders 2025-11-11 20:42:40 +01:00
Mario Zechner
97e00fc45d Fix Escape key to cancel autocomplete before interrupting agent 2025-11-11 20:29:38 +01:00
Mario Zechner
dc1e2f928b Add /thinking command and improve TUI UX
- Add /thinking slash command with autocomplete for setting reasoning levels (off, minimal, low, medium, high)
- Fix Ctrl+C behavior: remove hardcoded exit in TUI, let focused component handle it
- Add empty lines before and after tool execution components for better visual separation
- Fix stats rendering: display stats AFTER tool executions complete (matches web-ui behavior)
- Remove "Press Ctrl+C again to exit" message, show "(esc to interrupt)" in loader instead
- Add bash tool abort signal support with immediate SIGKILL on interrupt
- Make Text and Markdown components return empty arrays when no actual text content
- Add setCustomBgRgb() method to Markdown for dynamic background colors
2025-11-11 20:28:10 +01:00
Mario Zechner
c5083bb7cb Fix markdown streaming duplication by splitting newlines first
- Added string-width library for proper terminal column width calculation
- Fixed wrapLine() to split by newlines before wrapping (like Text component)
- Fixed Loader interval leak by stopping before container removal
- Changed loader message from 'Loading...' to 'Working...'
2025-11-11 19:27:58 +01:00
Mario Zechner
985f955ea0 Clean up TUI package and refactor component structure
- Remove old TUI implementation and components (LoadingAnimation, MarkdownComponent, TextComponent, TextEditor, WhitespaceComponent)
- Rename components-new to components with new API (Loader, Markdown, Text, Editor, Spacer)
- Move Text and Input components to separate files in src/components/
- Add render caching to Text component (similar to Markdown)
- Add proper ANSI code handling in Text component using stripVTControlCharacters
- Update coding-agent to use new TUI API (requires ProcessTerminal, uses custom Editor subclass for key handling)
- Remove old test files, keep only chat-simple.ts and virtual-terminal.ts
- Update README.md with new minimal API documentation
- Switch from tsc to tsgo for type checking
- Update package dependencies across monorepo
2025-11-11 10:32:18 +01:00
Mario Zechner
1caa3cc1a7 Add line count to paste markers
- Paste markers now show line count: [paste #1 +50 lines]
- Update replacement logic to handle both old and new marker formats
- Provides better visibility into paste size
2025-11-11 00:24:40 +01:00
Mario Zechner
9dab1192ad Add padding to Text component and fix padding calculation
- Add paddingX and paddingY support to Text component (default 1, 1)
- Fix padding calculation bug in both Text and Markdown
- Right padding now correctly fills to terminal width
- Remove unused Spacer import from chat-simple
2025-11-11 00:22:31 +01:00
Mario Zechner
5f19dd62c7 Fix terminal rendering and add improvements
- Enable bracketed paste mode for handling large pastes
- Fix editor duplicate line rendering bug at terminal width
- Add padding support to Markdown component (paddingX/Y)
- Add Spacer component for vertical spacing
- Update chat-simple with spacers between messages
2025-11-11 00:13:46 +01:00
Mario Zechner
97c730c874 Add minimal TUI rewrite with differential rendering
- New TUI implementation with 3-strategy differential rendering
- Synchronized output (CSI 2026) for flicker-free updates
- New components: Editor, Markdown, Loader, SelectList, Spacer
- Editor: file autocomplete, slash commands, large paste markers
- Markdown: RGB background colors, caching
- Terminal: cursor movement, visibility, clear operations
- Chat demo with color-coded messages
2025-11-10 23:55:21 +01: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
5bbaaa0773 Formatting 2025-08-11 21:22:11 +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
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
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
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