fix(tui): v2+v3 bug fixes, pending input queue, ! shell magic, /resume#513
Merged
lsdefine merged 6 commits intoMay 28, 2026
Merged
Conversation
Added installation instructions for Windows and Linux, including one-click install options and manual clone instructions. Updated configuration examples and GUI launch commands.
v2 Ctrl+S freeze: defer reset() + cleanup via call_after_refresh so the keystroke handler returns immediately even when streaming has the reactive queue saturated. Added _skip_change_next flag to short-circuit on_input_area_changed during the deferred clear. v3 terminal title: route _set_term_title via os.write(1,...) — sys.stdout gets redirected to sb_agent.log during PTK app run, so OSC 0 escapes were silently ending up in the log file. Default _session_name = 'session' for v2 parity, and repaint title on running→idle transition. v3 input row bg fill: _tile() now pads explicit bg-active spaces to width — PTK's cell renderer doesn't honour \x1b[K (erase-to-EOL), so the user bubble's charcoal band used to stop at text length. v3 /emoji picker: arrow-key menu (mirrors /llm). Pet styles cleaned to bear (default) + cat + dot + unicode. Bear calm tier restored to ʕ•ᴥ•ʔ. • used for the calm tier, o for focused — matches user-requested mood progression. Pet frame rate decoupled from spinner via self._spin // 5. v3 ask_user "coderun freeze" fix: _tool_status no longer marks an in-flight ask_user chip as ✓ ok when the stream contains the "Waiting for your answer ..." marker. Bumped DoneEvent grace from 2 s to 10 s when the marker is in the stream so a slow ask_user_queue.put doesn't cause the picker to fall through to _finalize. v3 /scheduler picker: added pre_checked kwarg to _show_menu so the running set lands atomically. slash_cmds._match_service relaxed to path-only matching so directly-launched (`python reflect/foo.py`) reflect tasks are detected. Running rows highlighted in functional green. Confirm card accepts ← as cancel (parity with Esc) — same on v2 ChoiceList. v3 keybindings: Esc Esc (within 800 ms) → /rewind (handled in _handle_key so PTK's Esc interception path actually fires). v3 pending input queue: agent.task_dir wired so ga.turn_end_callback can consume `<task_dir>/_intervene`. New AgentBridge.inject_intervene appends to the file (atomic vs read-modify-write), and _drain_pending routes the combined message either through that hook (mid-turn) or via put_task (idle). Cooldown 5 s, resets per new pending. ↑ recalls the last queued message, Esc clears the queue. v2 has equivalent shape: AgentSession.pending + per-session agent.task_dir + _inject_intervene + _poll_pending timer. ! shell magic: prefix `!` enters shell mode — pink border, prompt mark swaps `❯` → `!`, body strips the leading `!` so the glyph appears once. Enter runs the rest as `subprocess.run(shell=True, timeout=30)`, echoes `! cmd` + `└ output` into scrollback, and appends to LLM history (via _intervene when agent is running, direct backend.history append when idle — sidesteps the iterator race). /resume: forwarded as a literal to the agent so GA's _handle_slash_cmd (agentmain.py:124) can expand it. Added to v3 _cmds() + v2 COMMANDS + slash_cmds.COMMANDS + i18n + /help + Tips. Turn marker regex fix: agent_loop.py:52 switches `**LLM Running (Turn N) ...**` to the short `**Turn N ...**` when task_dir is set. Extended all v3/v2 turn-marker regexes to match either form. Cherry-picked upstream fixes: - PR lsdefine#466 (8ae3645): _collapse_choice early-return when the on_select callback (e.g. /rewind) detaches the anchor widget. - PR lsdefine#461 (08f21e8): SelectableStatic.has_valid_selection_parent + app-level _is_stale_selectable_mouse_event filter that swallows mouse events on detached widgets.
Per user screenshot 040748, the committed `! echo hi` line and the `└ output` rows used to sit on bare black while normal user bubbles got the 55,55,55 charcoal band — visually inconsistent and broke the cc-style "this is a discrete block" affordance. New `_TILE_SHELL` (65,60,65 bg, light fg) wraps both halves via `_tile()`, so the pink `!` prompt and dim `└` glyph inherit the band across the full row width. Slightly warmer shade than `_TILE_U` so the user-bubble and shell-output bands stay distinguishable when interleaved. Black-terminal only — matches user spec.
Previous commit's _TILE_SHELL forced a light fg across both the `└` gutter and the command output, erasing the dim styling on the gutter and overwriting any ANSI the shell command emitted into stdout. Make the tile bg-only (`\x1b[48;2;65;60;65m`). Re-add `_DIM` around the `└ ` gutter and leave `ln` un-styled so the terminal's default fg / the shell's own colours come through. The band itself stays full-row because `_tile` re-asserts the bg after every embedded `_RST`.
Last commit wrapped both the `! cmd` echo AND the `└ output` rows in the charcoal tile. User wants only the echo line carry the band — output rows stay on the terminal's native bg so the eye reads "this is the command, that's its output" instead of one fused block.
shenhao-stu
added a commit
to shenhao-stu/GenericAgent
that referenced
this pull request
May 28, 2026
…lone `tuiapp_v2.py:27` imports `fmt_key`, `fmt_keys` from `keysym`, but the module file was never tracked. PR lsdefine#513 (tui v2/v3 fixes) is unusable on a fresh checkout without this. Adds the cross-platform shortcut formatter that turns binding strings into mac/Win-Linux key labels (e.g. `"ctrl+b"` → `"⌃B"` / `"Ctrl+B"`), honoring `GA_KEYSYM_STYLE`.
FeiNiaoBF
pushed a commit
to FeiNiaoBF/GenericAgent
that referenced
this pull request
May 28, 2026
…lone `tuiapp_v2.py:27` imports `fmt_key`, `fmt_keys` from `keysym`, but the module file was never tracked. PR lsdefine#513 (tui v2/v3 fixes) is unusable on a fresh checkout without this. Adds the cross-platform shortcut formatter that turns binding strings into mac/Win-Linux key labels (e.g. `"ctrl+b"` → `"⌃B"` / `"Ctrl+B"`), honoring `GA_KEYSYM_STYLE`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bundle of v2/v3 TUI bug fixes + two new features (pending-input queue,
!shell magic) +/resumewiring + cherry-picked upstream fixes (#466, #461).Bug fixes
reset()+ cleanup viacall_after_refresh._skip_change_nextshort-circuits the synchronous Changed event so the keystroke handler returns instantly even when streaming saturates the reactive queue._set_term_titleviaos.write(1, ...); PTK redirectssys.stdouttosb_agent.log, so the OSC 0 escape was landing in the log instead of the terminal. Default session name =\"session\"for v2 parity; repaint on running→idle._tile()now pads explicit bg-active spaces to width. PTK's cell renderer doesn't honour\x1b[K, so the charcoal user-bubble band used to stop at text length._tool_statusno longer marks an in-flightask_userchip as ✓ ok while the stream still containsWaiting for your answer .... BumpedDoneEventgrace to 10 s when that marker is in the stream so a slowask_user_queue.putdoesn't cause the picker to fall through to_finalize.pre_checkedkwarg to_show_menuso the running set lands atomically with the rest of the menu state (PTK could otherwise render the menu before the post-_show_menuoverride took effect).slash_cmds._match_servicerelaxed to path-only so directly-launched (python reflect/foo.py) services are detected. Running rows colored functional green in both v2 + v3.ChoiceListand v3_menu_cardnow treat←as cancel (parity with Esc) so the user can roll back to the picker one-handed.agent.task_dir(required for the_intervenehook below) flips agent_loop.py:52 to emit the short**Turn N ...**form. Extended all four v3 turn-marker regexes (_TURN_MARKER_RE,_TURN_SPLIT_FOLD_RE,_TURN_MK_RE, and the_safe_posinline patterns) plus the v2 split-pattern to match either form.New features
[queued #N]markers and live in a preview block above the input. 5 s cooldown that resets per new pending, then drains via<task_dir>/_intervene(mid-turn) — the agent picks up the combined text at the next turn boundary thanks toga.turn_end_callback. Falls back toput_taskwhen the agent is idle.↑recalls the most-recent queued entry for amendment;Escclears the queue.!shell magic command (v2 + v3) — Prefix!enters shell mode: pink border, prompt mark swaps to!, body strips the leading!so the glyph shows once. Enter runs the rest assubprocess.run(shell=True, timeout=30), echoes! cmd+└ outputinto scrollback, and appends to the LLM history so a follow-up like "what did I just run?" finds the context. The history append routes through_intervenewhile the agent is running to avoid racing the runner thread's iteration ofbackend.history./resumewiring — Forwarded as a literal to the agent so GA's_handle_slash_cmd(agentmain.py:124) can expand it. Added to the v3 palette, v2COMMANDS,slash_cmds.COMMANDS, i18n (en+zh),/help, and tip rotations.v3 emoji polish
_PETS_ASCII/_PETS_BUNNY/_PETS_BLOB.ʕ•ᴥ•ʔ(default).cat+dotcalm tiers use•; focused tier useso— mood progression matches user-requested aesthetic.self._spin // 5so the face cycles at ~0.5 s while the spinner stays snappy at 0.1 s.v3 keybindings
Esc Esc(within 800 ms) →/rewind. Handled inside_handle_keybecause PTK's Esc interception swallows it before_keysruns.Cherry-picked upstream fixes
_collapse_choiceearly-return when theon_selectcallback (e.g./rewind) detaches the anchor widget.SelectableStatic.has_valid_selection_parent+ app-level_is_stale_selectable_mouse_eventfilter that swallows mouse events on detached widgets.Test plan
⠋ <session> · GenericAgentduring run and<session> · GenericAgentat idle/emojiopens picker; bear default; pet visibly slower than spinner请你coderun以下→ ask_user chip stays· …until answered; ask card renders inline with input/schedulershows running services pre-checked (green) in both v2 + v3; ← on confirm card rolls backTurn 1 ...text in scrollback during normal runs[MASTER] ...in the next LLM call's prompt!echo hi→ scrollback shows! echo hi/└ hi; agent recalls the command on a follow-up question/resumein either TUI lists recent sessions