Commit Graph

208 Commits

Author SHA1 Message Date
cc38e67d7c fix: Swank stderr leak, CSI detection with progn wrapper
- Swank: bind *error-output* to string stream to prevent 'Swank started
  at port: 4006.' from leaking to terminal on exit
- CSI detection: wrap inner dotimes in (progn ... t) so the and form
  doesn't short-circuit (dotimes returns nil, breaking the chain)
- Add debug add-msg for CSI detection results
2026-05-15 12:40:07 -04:00
df33e8d6db fix: main loop never closed, disconnect-daemon ran every iteration
The main loop's closing paren was missing — (sleep 0.1)) only closed
sleep and the minibuffer let, but NOT the loop itself. The next form
(progn (disconnect-daemon)) was INSIDE the loop body, called on every
iteration. On first call it added '* Disconnected *' and cleared the
daemon stream, making the TUI permanently disconnected.

Fix: add ) to close the loop. Also:
- Connect-daemon runs synchronously BEFORE with-terminal (3 ports, 6s
  max). If daemon is already running, the TUI starts connected.
- If sync connect fails, background thread retries every 5 seconds.
- start-daemon in background (no blocking wait for daemon startup),
  so TUI appears immediately.
2026-05-15 12:08:40 -04:00
9fb4393c9c fix: runtime crash (sb-ext:timeout undefined), replace with listen-based polling
- Remove handler-case + sb-ext:with-timeout 0.1 pattern entirely.
  sb-ext:timeout is a condition class, not a recognized type in the
  compilation environment, causing runtime 'undefined function' crash.
- Replace with dotimes 10 * (listen *standard-input*) + sleep 0.01
  polling loop. Same 0.1s timeout, no condition type dependencies.
- Also fix handler-bind → handler-case in tui-load.lisp so the stack
  unwinds properly (running with-terminal's shutdown-backend cleanup)
  before the crash handler runs, restoring terminal to normal state.
- Fix paren imbalance (off by 1) in the new listen-based reader code.
2026-05-15 11:36:46 -04:00
c1f4ad40d2 fix: disconnect-daemon missing close paren, compilation now succeeds
Major bug: defun disconnect-daemon in channel-tui-main.org was missing
its closing paren. Every form after disconnect-daemon (tui-main, tests,
etc.) was inside the unclosed defun, causing 'end of file' compile errors.
Adding the missing ) fixed all compilation errors.

Also revert handler-case change: keep sb-ext:timeout condition type.
2026-05-15 11:27:57 -04:00
d14ff3a316 fix: daemon port conflict handling, multi-port TUI connect
- start-daemon: handle ADDRESS-IN-USE-ERROR by trying ports 9105-9115
  instead of crashing. Logs which port is used.
- Add *daemon-port* defvar to track actual listening port
- main: wrap start-daemon in handler-case so the daemon doesn't
  crash if all ports are in use
- connect-daemon (TUI): try ports 9105-9115 with 2s timeout each
  instead of retrying the same port 3 times
- Add debug messages for connection success and disconnection timestamp
2026-05-15 10:56:09 -04:00
5924994202 fix: CSI escape detection for arrow keys, fix paren balance
- Add CSI escape sequence detection: when ESC (27) is received, poll
  for up to 20ms for the next bytes to detect arrow/home/end keys
- Use listen+read-char polling (not nested with-timeout) to reliably
  collect multi-byte sequences while keeping standalone ESC responsive
- Fix paren balance in main code block (2 extra opens from nested
  esc-seq forms needed matching closes)
2026-05-15 09:43:03 -04:00
53aa471a51 fix: revert to blocking connect-daemon, daemon connection now reliable
- Revert async connect-daemon thread (bt:make-thread unreliable — errors
  in the thread cause silent failure, no connection, no error message)
- Restore blocking connect-daemon before with-terminal (original pattern
  that was working)
- Revert /reconnect to synchronous call
- Remove stale async thread code and error messages
2026-05-15 09:21:54 -04:00
c148570d4c fix: multi-value backend-size, minibuffer border+width, pre-existing warnings
- backend-size: nested multiple-value-bind/values instead of or+mv-bind
  (or discards secondary values), remove stale env-var pre-check
- Minibuffer: full chat-w width (respects sidebar), horizontal rule
  border, clear filter prompt line to avoid text overlap
- Filter prompt: (or filter "") prevents "NIL" display
- Dirty-flag redraw: skip when dialog-stack is non-nil (minibuffer
  covers the area, prevents flicker)
- Remove 3 unused variables: FOCUS, SENSOR, C (pre-existing warnings)
2026-05-15 08:51:19 -04:00
f56ff4849f fix!: eliminate cat subprocess, use direct stdin reads, fix parens
Cat subprocess (uiop:launch-program '("cat") :input :interactive) was
unreliable — the process would exit immediately in some environments,
breaking ALL keyboard input. Root cause: uiop's :input :interactive mode
opened /dev/tty which failed under specific process-group configurations.

Replace with direct read-char-no-hang on *standard-input*. The bash script
sets stty -icanon -echo -ixon before launching sbcl, so SBCL's stdin is
already in raw mode. No subprocess needed.

Also fixed pre-existing paren imbalance in tui-main (2 extra opens).
2026-05-15 08:33:24 -04:00
3661d00138 fix: cat buffering, dialog filter int-chars, remove double render
- Wrap cat with stdbuf -o0 so keystrokes aren't stuck in cat's 4096-byte
  pipe buffer — text input was invisible until buffer filled
- Dialog filter: (characterp ch) rejects integer char codes from raw event
  dispatch. Accept integerp in range 32-126 and convert via code-char
- Remove initial render (backend-clear + view calls) before main loop.
  Dirty flags already trigger a full sync-wrapped redraw in the first
  iteration, eliminating the pre-loop clear flash
2026-05-14 20:29:50 -04:00
25da9ae685 fix: TUI flicker, bottom-anchored minibuffer, 13 color presets
Issue 1 — flickering during typing/updating:
- Wrap every frame render in DECICM sync (begin-sync/end-sync) so the
  terminal defers rendering until the entire frame is written
- Replace backend-clear (ESC[2J full clear) with draw-rect background
  fill — eliminates visible blank frame between redraws
- These two changes together eliminate all visible tearing/flicker

Issue 2 — bottom-anchored minibuffer (Emacs-style):
- Replace centered overlay dialog with bottom-anchored minibuffer
  that expands upward from the input line
- Unified command menu: Ctrl+P and / both open the same menu with
  all 35+ commands (slash + daemon), dispatch by value type
- Filter prompt at h-3 (same position as normal input),
  options listed above, grows up to 15 lines
- No full-screen dim backdrop — just clear the minibuffer area

Issue 3 — color schemes:
- Add 5 new presets: catppuccin, tokyonight, dracula, gemini, mono
- Total: 13 presets (up from 8)
- Update /theme completion list and help text

Also fixed: pre-existing unbalanced paren in tui-main (missing close)
2026-05-14 19:36:29 -04:00
6d7dd9e1ea fix: clean TUI exit, restore terminal, suppress compiler warnings
passepartout script:
- Add (uiop:quit 0) after tui-main so SBCL exits on Ctrl+Q
- Remove exec to allow stty restore after sbcl subprocess
- Restore icanon echo ixon after TUI exits (terminal stuck raw)

channel-tui-view.org:
- Remove unused fb/h vars from test-sidebar-not-shown-narrow
- Add (declare (ignore w)) to render-styled
- Qualify theme-color as passepartout.channel-tui:theme-color
  (render-styled is in :passepartout package)
- Remove dead :url clause from pick in parse-markdown-spans
  (URLs handled by dedicated branch, not via pick)
- Update literate prose for all changes
2026-05-14 16:25:36 -04:00
e453f9aad9 fix: use global vars for cat subprocess to avoid let* scope crash
Replaced (let* ((cat-proc ...) (tty-in ...)) ...) with global
special variables *cat-proc* and *tty-in* with defvar declarations.
The let* caused 'unbound variable' errors on Ctrl+Q because the
lexical scope didn't extend to terminate-process. Global vars have
indefinite scope and work reliably regardless of paren nesting.
2026-05-14 15:57:37 -04:00
74621cffd2 fix: disable flow control (-ixon) for Ctrl+Q, constrain prompt/hint to chat-w
- Added -ixon to stty so Ctrl+Q (XON byte) isn't swallowed by the
  terminal driver and reaches the TUI as :CTRL-Q
- view-input now truncates the prompt (> prefix + visible text) to
  chat-w - 2 characters, and the hint to chat-w characters, so
  neither extends into the sidebar area
2026-05-14 15:48:34 -04:00
2ce8d9d886 fix: constrain separator/input/status to chat area when sidebar visible
Added chat-w = w - sidebar_width calculation in view-status and
view-input, matching view-chat's existing approach. Also added
chat-w for the separator line drawing in tui-main. This prevents
the prompt, separator, hint, and status bar from extending into
the sidebar area when it's visible.
2026-05-14 15:44:17 -04:00
345f3f397d fix: set stty -icanon -echo in bash script before exec sbcl
uiop:run-program inside SBCL can't access the terminal, so stty
calls from within Lisp fail silently. By running 'stty -icanon -echo'
in the bash script before exec sbcl, the terminal is already in
character-at-a-time mode when the TUI starts, and Ctrl+P/B keys
arrive as individual bytes through the cat pipe.
2026-05-14 15:39:05 -04:00
84ef4c3443 fix: lower sidebar threshold to 60 cols, word-wrap agent messages
- Sidebar threshold lowered from 120 to 60 so it works on 83-col
  terminals
- Agent response text is now word-wrapped through cl-tty.box:word-wrap
  after markdown rendering, preventing text from bleeding past the
  terminal edge
2026-05-14 15:31:00 -04:00
ad5b9669a6 fix: revert w→chat-w replacement outside view-chat
view-status and view-sidebar don't have chat-w bound. Reverted
lines 78 and 236 to use w instead of chat-w.
2026-05-14 15:26:00 -04:00
187ec6e471 fix: constrain chat width when sidebar is visible, Ctrl+B sets all dirty
- Added chat-w = w - sidebar-width in view-chat for all width
  calculations (word-wrap, padding, borders) so text doesn't
  bleed into the sidebar area
- Changed Ctrl+B dirty flags from (list t t nil) to (list t t t)
  so input view also redraws, fixing the toggle-not-turning-off issue
2026-05-14 15:24:43 -04:00
48c2d57c14 fix: restore :key event handler with Ctrl+P/B/Q/L and dialog routing
The key event dispatch was lost during git restores, causing all
:key events (Ctrl+P, Ctrl+B, Enter, etc.) to fall through to
on-key which only handles :enter, :escape, and character insertion.
Added back the case ch with :CTRL-Q/:CTRL-P/:CTRL-B/:CTRL-L
branches and full dialog key routing.
2026-05-14 15:19:54 -04:00
b2f5f1cf1a fix: add stty -icanon for character-at-a-time input
Without -icanon, the terminal driver buffers all input until Enter,
so Ctrl+P/B never arrive as individual key events. With -icanon,
cat reads bytes immediately and pipes them to SBCL. SBCL reads from
the pipe, not fd 0, so there's no fd 0 read block issue.
2026-05-14 15:12:21 -04:00
4006a62e53 fix: remove stty -echo line, sync tangle 2026-05-14 14:42:22 -04:00
a609232589 fix: restructure let* closing so cat-proc stays in scope
sleep had 3 closers (sleep, loop, let*), closing the let* before
terminate-process. Reduced to 2 closers, added let* close after
terminate-process.
2026-05-14 14:35:23 -04:00
e0003a5f3c fix: move nil guard before backend info message
The backend info message showed NIL for height because the nil
guard ran after it. Swap order so the message shows guarded values.
2026-05-14 14:20:28 -04:00
14cdb6c7b4 fix: restore backend info message, remove Connected chat message
Backend dimensions needed to be readable. Connected v0.7.2
was accidentally restored by git checkout — removed again.
2026-05-14 14:18:12 -04:00
d71ccb95c6 fix: guards on resize handler and render loop, O_RDONLY for /dev/tty 2026-05-14 14:10:57 -04:00
55166fc9ff fix: add nil guards on w and h in tui-main before initial render
backend-size can return nil for height (especially when the /dev/tty
ioctl fallback hasn't been compiled in yet). view functions had nil
guards but the direct (- h 4) calls in tui-main's initial render
crashed before reaching them.
2026-05-14 14:04:27 -04:00
f5fdfe73d6 fix: move terminate-process inside let* scope
cat-proc and tty-in were defined by let* but the let* closed at
sleep's third ), putting them out of scope for terminate-process
and read-char. Restructured closing parens so the let* body wraps
the full loop + cleanup.
2026-05-14 14:02:59 -04:00
337b8cdd86 fix: nil guards on w and h in all view functions
Prevents crash when backend-size returns nil for height.
Defaults to 80x24 if dimensions are nil or invalid.
2026-05-14 13:41:15 -04:00
4bfb407094 fix: draw hint before prompt so cursor stays at input line
view-input drew prompt first (row h-3), then hint (row h-2),
leaving the cursor at end of the hint line after 'complete'.
Typed characters appeared there. Swapped order: hint first,
prompt last, so cursor ends at the > prompt.
2026-05-14 12:51:21 -04:00
d5b4c8c8f0 fix: draw input after separator so cursor stays at input line
The render order was: view-chat → view-input → draw-separator.
After the separator draw, the cursor ended up at row h-4 (the
separator line). Typed characters echoed by the terminal appeared
on the separator line, above the > prompt. Swapped so the input
line is drawn last: view-chat → draw-separator → view-input.
2026-05-14 12:48:01 -04:00
c0d0ddfeec fix: use stdbuf -o0 cat for unbuffered pipe input, remove debug
- Changed cat subprocess to stdbuf -o0 cat (unbuffered output)
  so characters arrive immediately through the pipe
- Added cat PID to startup messages for diagnostics
- Removed pipe debug logging (trace.log, pipe.log)
- Cat pipe input confirmed working: read-char returns #\a, #\b, #\Newline
- Remaining issue: frame-message format mismatch with daemon
  (pre-existing, not related to input changes)
2026-05-14 12:43:00 -04:00
b9a4318ef8 reorg: tangle to XDG, remove stale lisp files, fix tui input
- Changed all 50 org file :tangle targets from ../lisp/ to
  ~/.local/share/passepartout/lisp/ (XDG data dir)
- Removed 49 generated .lisp files from project lisp/ directory
- Removed tests/system-integration-tests.lisp (generated)
- Removed lisp/*.fasl (compiled, stale)
- Updated core-manifest.org to tangle .asd to XDG root
- Remapped quicklisp symlink: local-projects/passepartout → XDG

TUI fixes in channel-tui-main.org:
- Removed with-raw-terminal (stty raw breaks fd 0 reads in this SBCL)
- Use cat subprocess + pipe for keyboard input (via :input :interactive)
- Blocking read-char on pipe with with-timeout 0.1s for daemon processing
- Key events queued via drain-queue alongside daemon messages
- Full dialog key routing (Escape, Up/Down, Enter, filters, Backspace)
- SIGWINCH resize handling
- Post-handshake backend-size re-query
- Daemon version in status bar (was v0.5.0 hardcoded)
- Handshake version stored in state, no add-msg
- :daemon-version and :size-queried in state plist
- view-status uses draw-rect for background
- Test section gated with #+passepartout-tests
2026-05-14 12:34:06 -04:00
adca69d29c fix: remove hardcoded v0.5.0, show daemon version in status bar
- Removed connect-daemon's hardcoded "* Connected v0.5.0 *" message
  (fired before handshake arrived, was always stale)
- Added :daemon-version slot to state plist, filled by handshake handler
- view-status now shows version: "● passepartout v0.7.2 msgs:N Rules:N"
- passepartout script: force cl-tty recompile (:force t) to pick up
  CSI positioning, ioctl sizing, and detection fixes
2026-05-14 09:11:22 -04:00
1884372660 fix: use blocking read-char via listen for reliable input
read-char-no-hang on fd 0 streams never returns data because
sb-unix:unix-simple-poll on fd 0 returns NIL in this SBCL
environment. Switched to (listen tty) + (read-char tty) which
blocks until a key is pressed — correct interactive TUI behavior.
Also switched from (open "/dev/tty") to
(sb-sys:make-fd-stream 0 :input t :buffering :none) to directly
read from stdin.
2026-05-14 09:02:02 -04:00
11cb466d4f fix: add SIGWINCH resize handling for /dev/tty input path
Main loop now checks cl-tty.input::*terminal-resized-p* on every
iteration. When set (by SIGWINCH handler), re-queries backend-size
and marks all regions dirty for re-render.
2026-05-14 08:56:00 -04:00
226f979d38 fix: /dev/tty input, gate test code, fix code-char bug
- Replaced cl-tty read-event with direct read-char-no-hang from
  /dev/tty for reliable input (avoids unix-simple-poll fd 0 issue)
- Added (let ((tty ...)) wrapper to open /dev/tty once at startup
- Fixed (code-char raw-ch) bug: raw-ch is already a CHARACTER
- Fixed one extra close paren that closed (let ((ch ...)) early
- Gated fiveam test section behind #+passepartout-tests reader
  conditional to prevent crash on TUI startup when fiveam not loaded
2026-05-14 08:53:21 -04:00
a9705253a5 fix: restore read-event for reliable input, working TUI
- Replaced read-char-no-hang/stdin-input with cl-tty read-event
  (blocks until data, works regardless of --load stream)
- Added initial render before main loop via direct-to-backend
- Added read-event resize handling
- Removed stale fasl/crash/theme files
- Fixed paren balance in tui-main
- TUI starts, accepts input, daemon responds (msgs:3->4)
- 237 tests pass
2026-05-13 20:46:44 -04:00
ce3e8ed44c fix: use read-char-no-hang instead of cl-tty read-raw-byte
- Replaced read-event/read-raw-byte with read-char-no-hang from
  *standard-input* for reliable non-blocking terminal input
- Added escape sequence decoding (CSI sequences for arrows, PageUp/Dn,
  Home, End, F-keys)
- Added Ctrl+letter handling (0x01-0x1a mapped to :CTRL-X keywords)
- Added direct key dispatch for Ctrl+P (palette), Ctrl+B (sidebar),
  Ctrl+L (redraw), Ctrl+Q (quit), Ctrl+D/F/G, PageUp/Dn, Home/End
- Fixed cl-tty read-raw-byte to check poll result before reading
- Initial render before main loop so startup messages appear immediately
- All 237 tests pass
2026-05-13 20:23:51 -04:00
7d3dc479eb fix: initial render before loop, restore read-event timeout=0
- Added initial render (backend-clear + view-all) before main loop
  so startup messages appear immediately
- Restored read-event with :timeout 0 from git HEAD
- Removed dispatch-key-event from main loop (simplified to direct on-key)
- Removed :enter from :local keymap (handled directly in on-key)
- Retained direct-to-backend rendering (no framebuffer)
- Retained msgs count in status bar for debugging
- 237/237 tests pass
2026-05-13 20:09:40 -04:00
35fbf1d418 bump passepartout: v0.9.0 Warm TUI Redesign fixes 2026-05-13 19:49:45 -04:00
b17c501231 fix: replace draw-rect on framebuffer with draw-text
draw-rect has no method on raw arrays (only on framebuffer-backend,
simple-backend, modern-backend). Three calls in view-status, view-chat,
and view-sidebar passed the framebuffer array to draw-rect, causing
'no applicable method' crash on startup.

Replaced with (draw-text ... (make-string w #\Space) nil bg) which
fills the same area with background spaces.
2026-05-13 19:20:00 -04:00
15d16fd520 bump passepartout: v0.9.0 Warm TUI Redesign — blank slate
Complete rewrite of the TUI with warm amber/gold color palette and
clean three-zone layout (chat top, input bottom, status very bottom).

1. Layout restructure: input at y=h-3, hint at y=h-2, status at y=h-1
2. Warm palette: 20-key amber/gold theme, 8 warm presets
3. Readline keybindings: Ctrl+A/E/U/W/K/Y/L/D/F/G in :global keymap
4. Chat messages: user boxes (┌─└─), agent headers, collapsible tools
5. Command palette: Ctrl+P top-centered overlay, warm colors
6. Sidebar: Ctrl+B toggle, right panel with focus/rules/context/MCP
7. Keybindings: :ctrl+x, :?, mouse wheel support
8. Search: existing /search with match highlighting
9. Help overlay: ? shows keybinding and command reference
2026-05-13 19:13:20 -04:00
e27cffa4e0 fix: all 21 TUI test failures — KEY_ENTER, KEY_BACKSPACE, Escape handling
- KEY_ENTER (343) and KEY_BACKSPACE (263) were not handled in on-key
  causing Enter/Backspace to silently fail in tests using ncurses keycodes
- Escape (27) was not matched for streaming interrupt in on-key
- theme-color test expected keyword :white but function returns hex string
2026-05-13 18:08:29 -04:00
b5a07a5dcb bump passepartout: v0.8.0 TUI upgrade — all 6 items
Minibuffer (dialog stack), conversation view (ScrollBox+Markdown),
command palette (Ctrl+P), sidebar (6 panels, Ctrl+B), status bar
(degraded-mode signaling), keybinding layer (defkeymap).
2026-05-13 17:57:54 -04:00
60ce9c894c fix: backend-clear called with framebuffer instead of backend
Main loop was calling (backend-clear curr-fb) where curr-fb is a
framebuffer array. Changed to (backend-clear be) using the cl-tty
backend, which writes the terminal clear escape sequence.
2026-05-13 16:29:50 -04:00
36e7d51fce fix: add missing keyword clause in printable branch of on-key
The revert removed the (keyword ...) clause from the typecase in
on-key's printable branch. Keyword symbols from the main loop
(:a, :h, etc.) fell through to (t nil), making all character input
silently ignored. Typing and sending now works correctly.
2026-05-13 16:25:37 -04:00
af4d81ec9f fix: add word-wrap function, complete TUI migration
- Add missing word-wrap function (was declared in contract but never defined)
- TUI now renders correctly: draw-text on framebuffer arrays works
- Daemon connection verified
- All three view functions (status, chat, input) call draw-text correctly
2026-05-13 16:06:05 -04:00
79896c5ffd fix: bypass ASDF compile for TUI load, use direct compile-file+load 2026-05-13 14:53:27 -04:00
4b60e8c544 fix: stty graceful failure, backend-size TYPE-ERROR safety net
- cl-tty stty calls now use :ignore-error-status t (works in PTY/piped env)
- backend-size wraps in ignore-errors with 80x24 fallback in resize handler
- Both fixes enable TUI to run in environments without full terminal capabilities
2026-05-13 14:21:57 -04:00