Commit graph

122 commits

Author SHA1 Message Date
cursive
d97a96493c
fix(tui): Strip OSC 8 hyperlink sequences in visibleWidth (#396) 2026-01-02 10:32:36 +01:00
nathyong
6e4270a286 tui: only check for emojis in visibleWidth when necessary
The initial render of a session, and any re-draws caused by terminal
resizing are noticeably slow, especially on conversations with 20+
turns and many tool calls.

From profiling with `bun --cpu-prof` (available since bun 1.3.2), the
majority of the rendering (90%) is spent on detection of emojis in the
string-width library, running the expensive `/\p{RGI_Emoji}$/v`
regular expression on every individual grapheme cluster in the entire
scrollback. I believe it essentially expands to a fixed search against
every possible emoji sequence, hence the amount of CPU time spent in it.

This change replaces the `stringWidth` from string-width with a
`graphemeWidth` function that performs a similar check, but avoids
running the `/\p{RGI_Emoji}$/v` regex for emoji detection unless it
contains codepoints that could be emojis.

The `visibleWidth` function also has two more optimisations:
- Short-circuits string length detection for strings that are entirely
  printable ASCII characters
- Adds a cache for non-ASCII segments to avoid recomputing string length
  when resizing
2026-01-02 01:56:11 +01:00
Mario Zechner
1d9fa13d58 Fix crash on Unicode format characters in visibleWidth
Strip all Unicode format characters (category Cf) before passing to
string-width. These are invisible control characters that crash
string-width but have no visible width anyway.

Closes #390
2026-01-01 22:33:09 +01:00
Mr. Rc
bbf23bd5f1
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
2026-01-01 02:16:29 +01:00
Mario Zechner
6f7c10e323 Add setEditorText/getEditorText to hook UI context, improve custom() API
- Add setEditorText() and getEditorText() to HookUIContext for prompt generator pattern
- custom() now accepts async factories for fire-and-forget work
- Add CancellableLoader component to tui package
- Add BorderedLoader component for hooks with cancel UI
- Export HookAPI, HookContext, HookFactory from main package
- Update all examples to import from packages instead of relative paths
- Update hooks.md and custom-tools.md documentation

fixes #350
2026-01-01 00:04:56 +01:00
Mario Zechner
71cbae6371 Export wrapTextWithAnsi utility and add handleInput docs
- Export wrapTextWithAnsi from tui package
- Add 'Handling Input' section to README with key detection example
- Document wrapTextWithAnsi in utilities section
2025-12-30 23:28:38 +01:00
Mario Zechner
e4df5d14b5 Tree selector improvements: active line highlight and tool filter
- Add inverse background highlight for selected/active line
- Add 'no-tools' filter mode to hide tool results
- Add isShiftCtrlO to cycle filters backwards
- Filter order: default → no-tools → user-only → labeled-only → all
2025-12-30 22:42:25 +01:00
Mario Zechner
9427211f99 fix(tui): render HTML tags as plain text in Markdown component
Handles both block-level and inline HTML tags that were previously
silently dropped.

fixes #359
2025-12-30 22:42:24 +01:00
Mario Zechner
544814875e Add global debug key (Shift+Ctrl+D), iterative tree sorting to avoid stack overflow 2025-12-30 22:42:22 +01:00
Mario Zechner
4edfff41a7
Merge pull request #315 from mitsuhiko/model-switcher
Reverse model switching and binding for dialog
2025-12-25 18:33:42 +01:00
Armin Ronacher
b576a527c7 Reverse model switching and binding for dialog 2025-12-25 18:07:36 +01:00
Mario Zechner
b4f7a957c4
Add /settings command with unified settings menu (#312)
* Add /settings command with unified settings menu

- Add SettingsList component to tui package with support for:
  - Inline value cycling (Enter/Space toggles)
  - Submenus for complex selections
  - Selection preservation when returning from submenu

- Add /settings slash command consolidating:
  - Auto-compact (toggle)
  - Show images (toggle)
  - Queue mode (cycle)
  - Hide thinking (toggle)
  - Collapse changelog (toggle)
  - Thinking level (submenu)
  - Theme (submenu with preview)

- Update AGENTS.md to clarify no inline imports rule

Fixes #310

* Add /settings to README slash commands table

* Remove old settings slash commands, consolidate into /settings

- Remove /thinking, /queue, /theme, /autocompact, /show-images commands
- Remove unused selector methods and imports
- Update README references to use /settings
2025-12-25 15:39:42 +01:00
Ahmed Kamal
0427445242
Fix Ctrl+W to use standard readline word deletion behavior (#306)
- Skip trailing whitespace before deleting word (readline behavior)
- Make word navigation grapheme-aware using Intl.Segmenter
- Add Ctrl+Left/Right and Alt+Left/Right word navigation to Input
- Accept full Unicode input while rejecting control characters (C0/C1/DEL)
- Extract shared utilities to utils.ts (getSegmenter, isWhitespaceChar, isPunctuationChar)
- Fix unsafe cast in Editor.forceFileAutocomplete with runtime type check
- Add comprehensive tests for word deletion and navigation
2025-12-25 04:09:47 +01:00
Armin Ronacher
65cbc22d7c
Add safety-space before pasting (#307)
* Add safety space when dropping in paths

* Add safety space when dropping in paths
2025-12-25 04:05:53 +01:00
Nico Bailon
e904b11e7b
Fix Ghostty detection inside tmux for inline images (#299) 2025-12-24 12:04:41 +01:00
Mario Zechner
31f4a588fd TUI: Improve file completion display (fixes #280) 2025-12-22 16:36:42 +01:00
Mario Zechner
d5fd685901 Enable more biome lints and fix things 2025-12-21 22:56:20 +01:00
Aliou Diallo
8868d623fc
feat(coding-agent): add Ctrl+Z to suspend process (#267)
* feat(tui): add isCtrlZ key detection and resetRenderState method

* feat(coding-agent): add Ctrl+Z handler to suspend process

* docs(coding-agent): add Ctrl+Z to keyboard shortcuts documentation

* feat(tui): add force parameter to requestRender
2025-12-21 20:19:32 +01:00
Aliou Diallo
afedf1707a feat(tui): add isCtrlG key detection 2025-12-21 12:06:57 +01:00
Mario Zechner
918750eb9e Fix tab completion for absolute paths
- Fix //tmp issue: distinguish slash commands from file paths by checking if anything precedes the /
- Fix symlinks to directories (like /tmp) not getting trailing slash
2025-12-21 02:41:38 +01:00
Mario Zechner
36e17933d5 feat(ai): add Google Cloud Code Assist provider
- Add new API type 'google-cloud-code-assist' for Gemini CLI / Antigravity auth
- Extract shared Google utilities to google-shared.ts
- Implement streaming provider for Cloud Code Assist endpoint
- Add 7 models: gemini-3-pro-high/low, gemini-3-flash, claude-sonnet/opus, gpt-oss

Models use OAuth authentication and have sh cost (uses Google account quota).
OAuth flow will be implemented in coding-agent in a follow-up.
2025-12-20 10:20:30 +01:00
Mario Zechner
d2276ab654 fix(tui): fix input buffering in iTerm2 causing delayed keypresses
The cell size query response parser was incorrectly holding back Kitty
keyboard protocol sequences, thinking they might be incomplete cell size
responses. This caused Ctrl+C/Ctrl+D to require multiple presses in iTerm2.

Fixed by only waiting for more data if the buffer doesn't end with a
terminal escape sequence terminator character.
2025-12-19 22:08:36 +01:00
Mario Zechner
84eaad8029 fix(tui): use isBackspace and isEnter helpers in Editor
Fixes Backspace and Enter not working with Caps Lock enabled.
The Kitty protocol sends lock key bits in modifiers which broke
the raw byte detection.
2025-12-19 21:08:24 +01:00
Mario Zechner
cbd20b58a6 fix(tui): add isHome, isEnd, isDelete helpers for Kitty protocol
Extended the Kitty protocol parser to handle functional keys with
~ terminator (Delete, Insert, PageUp, PageDown) and Home/End keys.
Updated editor.ts and input.ts to use the new helpers.
2025-12-19 21:00:20 +01:00
Mario Zechner
716516d61e fix(tui): use isEnter and isBackspace helpers in Input component
Fixes Kitty protocol handling for Enter and Backspace in the Input
component, matching the Editor component fix.
2025-12-19 20:57:03 +01:00
Mario Zechner
b8dd9be3d0 fix(tui): handle emoji deletion and cursor movement correctly
Backspace, Delete, and arrow keys now use Intl.Segmenter to operate
on grapheme clusters instead of individual UTF-16 code units. This
fixes deletion of emojis and other multi-codepoint characters.

fixes #240
2025-12-19 20:39:45 +01:00
Mario Zechner
28c3ffb914 fix(tui): handle Kitty protocol lock key modifiers
Fixes keyboard input in Ghostty on Linux when Num Lock is enabled.
The Kitty protocol includes Caps Lock (64) and Num Lock (128) bits
in modifier values. Now masks out lock bits when matching shortcuts.

Added helper functions: isArrowUp/Down/Left/Right, isEnter, isTab,
isBackspace, isShiftEnter, isAltEnter, isAltLeft/Right, isCtrlLeft/Right

fixes #243
2025-12-19 20:34:20 +01:00
Mario Zechner
f8b6164ecd Fix Escape key handling for Kitty keyboard protocol
Add isEscape() helper that handles both raw (\x1b) and Kitty protocol
(\x1b[27u) Escape sequences. Update all components that check for
Escape key to use the new helper.
2025-12-19 04:54:02 +01:00
Mario Zechner
139af12b37 Merge kitty-protocol-support into main 2025-12-19 01:21:47 +01:00
Mario Zechner
b2f29613e8 Add /hotkeys command, Ctrl+D exit, markdown table borders 2025-12-19 01:19:21 +01:00
Ahmed Kamal
d569f0353e Remove isKittyCtrl and isKittyKey from public exports
These generic helpers aren't used externally and would require
exporting MODIFIERS constants to be ergonomic. The specific
isCtrl* helpers cover all practical use cases.
2025-12-18 19:51:04 +02:00
Ahmed Kamal
727a7ab018 Add Ctrl+D to exit when editor is empty
- Add isCtrlD helper to keys.ts
- CustomEditor intercepts Ctrl+D and only triggers callback when editor is empty
- Single Ctrl+D with empty input exits immediately
- Update CHANGELOG to frame as feature (Kitty protocol support) not fix
2025-12-18 19:39:41 +02:00
Ahmed Kamal
c3c2bffc68 Add helper functions for key detection and update usage
- Add isCtrlA/C/E/K/O/P/T/U/W helper functions that check both raw and Kitty formats
- Add isAltBackspace helper function
- Refactor editor.ts, input.ts, select-list.ts to use helper functions
- Refactor custom-editor.ts, session-selector.ts, user-message-selector.ts
- Add CHANGELOG entry for the Shift+Enter fix
2025-12-18 19:29:40 +02:00
Ahmed Kamal
4a4531f887 Add Kitty keyboard protocol support for Shift+Enter and other modifier keys
Enable the Kitty keyboard protocol on terminal start to receive enhanced
key sequences that include modifier information. This fixes Shift+Enter
not working in Ghostty, Kitty, WezTerm, and other modern terminals.

Changes:
- Enable Kitty protocol on start (\x1b[>1u), disable on stop (\x1b[<u)
- Add centralized key definitions in packages/tui/src/keys.ts
- Support both legacy and Kitty sequences for all modifier+key combos:
  - Shift+Enter, Alt+Enter for newlines
  - Shift+Tab for thinking level cycling
  - Ctrl+C, Ctrl+A, Ctrl+E, Ctrl+K, Ctrl+U, Ctrl+W, Ctrl+O, Ctrl+P, Ctrl+T
  - Alt+Backspace for word deletion
- Export Keys constants and helper functions from @mariozechner/pi-tui
2025-12-18 19:20:30 +02:00
Sergii Kozak
f8e6d62db7 Add syntax highlighting to markdown code blocks 2025-12-17 20:15:44 -08:00
Ahmed Kamal
c1113deea9
Fix markdown tables overflowing/wrapping in TUI (width-aware rendering) (#206)
Fix markdown tables overflowing/wrapping in TUI
2025-12-17 17:13:27 +01:00
Mario Zechner
909989066a Fix TUI performance regression: add caching to Box, use Text directly for built-in tools 2025-12-17 16:39:23 +01:00
Mario Zechner
e7097d911a 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
2025-12-17 16:03:23 +01:00
Markus Ylisiurunen
4b04c87b3d
add new getCursor and getLines methods to editor (#201) 2025-12-16 20:13:43 +01:00
Markus Ylisiurunen
92577316e0
Fix double new line issues in markdown rendering (#199)
* prevent double blank lines after markdown elements

* prevent double blank lines after markdown elements
2025-12-16 00:25:06 +01:00
Mario Zechner
ce9ffaff91 Fix ANSI styles not preserved across newlines in text wrapping
wrapTextWithAnsi() was processing each line independently after splitting
on newlines, losing ANSI state. When styled text contained embedded newlines
(e.g. from markdown paragraphs), subsequent lines would lose their styling.

Fixed by tracking ANSI state across lines and prepending active codes to
lines after the first.

Fixes #197
2025-12-15 23:00:25 +01:00
Mario Zechner
e4e234ecff 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
2025-12-13 23:53:28 +01:00
Mario Zechner
b8a0465e30 Update docs for inline images, remove PI_NO_IMAGES env var
- Add CHANGELOG entry for inline image rendering feature
- Add /show-images to slash commands table in README
- Expand Image Support section with inline rendering info
- Add terminal.showImages to settings documentation
- Remove PI_NO_IMAGES environment variable feature
2025-12-13 23:21:18 +01:00
Mario Zechner
d4b2b4be04 Only query cell size if terminal supports images 2025-12-13 23:15:15 +01:00
Mario Zechner
215c10664a Fix image aspect ratio by querying terminal cell size
- Add getCellDimensions/setCellDimensions to terminal-image.ts
- TUI queries cell size on startup via CSI 16 t
- Parse response and filter it from user input
- Invalidate and re-render when cell dimensions received
- Pass rows parameter to Kitty protocol for correct aspect ratio
2025-12-13 23:09:05 +01:00
Nico Bailon
f603a377ae add PI_NO_IMAGES env var to disable inline image rendering 2025-12-12 19:35:54 -08:00
Nico Bailon
9e9d5c94ed add inline image rendering for terminals with graphics support 2025-12-12 19:30:50 -08:00
Markus Ylisiurunen
db886746b4
prevent double blank lines after markdown code blocks (#173) 2025-12-13 02:04:49 +01:00
Mario Zechner
d7f84469a7 Fix editor crash with wide characters (emojis, CJK)
Editor text wrapping now uses grapheme-aware width calculation instead
of string length. Fixes crash when pasting text containing emojis like
 or CJK characters that are 2 terminal columns wide.
2025-12-06 21:24:26 +01:00
Mario Zechner
30dd31d787 Merge feat/scroll-previous-prompts with history load on resume 2025-12-05 22:02:16 +01:00