- Add sys.path.append for llmcore's own directory as fallback
- Remove dead variable _imp_err
- Distinguish missing mykey vs import failure with clear error messages
macOS Terminal.app quantises truecolor to its nearest 256 slot (so
#5e6ad2 lavender lands on slot 62 #5f5fd7, visibly more blue) and
renders \x1b[2m as a heavy multiply instead of a gentle blend, producing
the "blue border + heavy shadow" against iTerm's identical code.
Branch on TERM_PROGRAM: iTerm keeps its truecolor accent and \x1b[2m
dim; Apple_Terminal switches to pinned 256-slot accent (105) and an
explicit mid-gray (244) for dim. Box border (146) was already 256-slot
so it carries unchanged.
Replace _history_lines (pre-rendered) with _blocks (source + kind) so
_repaint_screen can re-render every chip, banner, user panel at the
current width. \x1b[3J wipes scrollback on resize/Ctrl+L so the entire
conversation reflows, not just the visible viewport.
SIGWINCH delivery via self-pipe + select() — PEP 475 auto-retry on
os.read makes signal-driven InterruptedError unreliable under iTerm
split panes, so a dedicated pipe wakes the loop deterministically.
Streaming tracks a single _streaming_block whose source grows monotonically
through safe-position commits; mid-stream resize re-renders both the
committed source and the volatile live_tail.
Eight independent fixes accumulated since the last batch, all landing in
tuiapp_v2.py:
1. Code-block selection offset: _align_md_renders's is_centered heuristic
tripped on any code line indented >=4 spaces (Python's default), stripping
the indent from the source string so the visible selection and the copied
text disagreed. Add wide_lead >= 2*nt0_lead guard — only Rich's H1 centering
(wide_lead ~ width/2) crosses it, code lines never do.
2. Blockquote-continuation selection offset: Rich re-emits `▌ ` on every
wrapped visual line of a quote, but the wide-render carries the marker
only once. Strip the marker as a decoration prefix (counts as indent, not
content) and switch the wrap-accumulator to account for the per-break
eaten space — both pre-existing code-block wraps and blockquotes now map
correctly.
3. Streaming ANSI garbage: while a turn is streaming, the tail text segment
was rendered with `Text(content, style=C_FG)` instead of `Text.from_ansi`.
SGR codes from the model/tool output would render as literal `[31m`
glyphs and only resolve after `m.done` flipped or a resize forced a
remount via the Markdown path. Switch the two streaming fast paths to
Text.from_ansi — O(n) scan, no Markdown parse, colors honored live.
4. continue picker LIMIT removed: tuiapp's own `LIMIT = 20` truncated the
/continue picker even though list_sessions() always builds the full list.
Show everything; header now reads "选择要恢复的会话 (N 条)".
5. Long-paste rescue + user echo elision: Windows Terminal yanks window
focus when its >=5KiB paste-warning dialog pops, leaving focused=None
after the user confirms; Textual then routes the Paste event to the App
bubble instead of InputArea, and the paste appears to do nothing. Add a
GenericAgentTUI._on_paste forwarder that refocuses #input and replays the
event into InputArea._on_paste. Separately, on submit, elide user-side
display of very long pastes (head 10 / tail 5 / `⋯ 省略 N 行 ⋯`); the
agent still receives the full content via expand_placeholders.
6. mykey.py hot reload: load_llm_sessions() already had mtime-gated reload
plumbing, but it only ran on Agent.__init__ / next_llm / list_llms — so
editing mykey.py mid-session required restart. Two triggers added:
on_input_area_submitted now calls load_llm_sessions() before sending
(cheap mtime check; rebuilds on change), and a new /reload-keys command
forces a sweep across every session (resetting llmcore._mykey_mtime
per-iteration so the cache doesn't short-circuit later sessions).
7. Resize / sidebar toggle no longer jumps to bottom: _remount_current_session
used to unconditionally scroll_end after rebuilding. Capture scroll_y +
"was at bottom?" first; stick to bottom only if the user was already there,
otherwise restore the prior scroll_y so resizes don't yank the user away
from what they were reading.
8. Markdown table cells wrap instead of ellipsizing: Rich's Markdown
TableElement passes no `overflow` to Table.add_column, so the default
"ellipsis" hides long cell content with `…` on narrow widths. Patch
TableElement.__rich_console__ on import to pass overflow="fold".
When a single LLM provider goes down mid-task (auth, network, quota,
etc.), the conductor falls completely silent: MixinSession yields
errors as text chunks (not Python exceptions), so the existing
try/except guard in conductor_loop never triggers, and the conductor's
only way to talk to the user (LLM-decided POST /chat tool call) is dead.
Add a tiny watchdog: monitor_conductor_queue now returns the conductor
agent's final done text, and conductor_loop scans the tail-1000-char
window for "!!!Error:" — the prefix llmcore uses for unrecoverable
errors. Tail window (not whole text) avoids false positives from
earlier turns; using a character window (not last-line) matches
ga.do_no_tool's content[-100:] style and tolerates the decoration
(fence + "[Info] Final response to user.") that do_no_tool appends
after the error chunk when its own short window check misses. When
detected, push the matched error line as a system chat message so the
user knows what happened. A dedup check prevents repeated warnings
if multiple events fail in succession.
+16 -4 lines. Only frontends/conductor.py touched. No agent_loop /
llmcore changes; other frontends unaffected.
When setup window starts the bridge, the main window was already created
with URL http://127.0.0.1:14168/ but failed to load (bridge not running yet).
After bridge becomes ready, we now navigate the main window to reload the
bridge URL before showing it, preventing the white screen issue.
- Plan card (📋): per-session message-scan with `plan_scan_baseline` so
`/continue` of a finished session doesn't auto-resurrect old plan cards;
prefers `<summary>当前步骤:` over the long plan-item echo; placeholder
while enter_plan_mode is armed but plan.md hasn't been written yet.
- Done annotation (⠿ {Verb} for Xm Ys · ↑ N · ↓ M): post-turn elapsed
+ per-call token deltas, frozen at done so the line stays put across
re-mounts. Spinner annotation gated on cumulative deltas past stream-start
baselines — fixes `↓ 16` showing immediately on prompt submit.
- fold_turns regex anchored to line-start (`^` + MULTILINE) so embedded
backticks in tool output (e.g. `N|\`\`\`\`` gutter from file_read) don't
pair with later real fences. ~100x faster on long /continue sessions.
- /cost: per-session card + `/cost all`; `Context window` line now reads
GA's actual char cap via `cost_tracker.context_window_chars(backend)` =
`backend.context_win * 3` (the `trim_messages_history` trigger threshold
in llmcore.py), so the percentage reflects real budget and respects
`mykey.py` overrides. Unit changes from token to character. Dropped the
model-theoretical `_CTX_LIMITS` table (never actually constrained anything).
Subagent log scan via `cost_tracker.scan_subagent_logs` aggregates
`temp/*/stdout.log` since TUI start.
- /review: standalone in-session reviewer; reuses `review_cmd.handle`
to render the inline prompt and submits as a normal user task.
- llmcore: emit `[Output] tokens=N` for chat_completions / responses modes
(already emitted for `messages` SSE) so cost_tracker scopes output
tokens uniformly across all three API modes.
- review_inline_prompt.{txt,en.txt}: filled out the in-session review
discipline — Three Iron Rules, Q1-Q4 framing, severity examples,
8 false-positive rules expanded, 8 wording rules expanded, 8-item
self-check. ZH/EN both grow ~80 lines.
- memory/review_sop.md: rewrite 52 → 191 lines, 11 sections covering
quick-start, entry files, Three Iron Rules, 5-step workflow, severity,
output protocol, relationship to plan_sop / verify_sop. Style mirrors
plan_sop.md + autonomous_operation_sop.md.
Files: frontends/{tuiapp_v2,tuiapp,cost_tracker,plan_state}.py, llmcore.py,
memory/review_sop.md, memory/review_sop/review_inline_prompt.{txt,en.txt},
.gitignore (allowlist new SOP).
Co-authored-by: Shen Hao <shenhao-stu@users.noreply.github.com>
`self.model` was pinned to `_sessions[0].model` at init; after failover the
topbar (and any other reader of `agent.get_llm_name(model=True)`) kept showing
the primary's model name even when `_cur_idx` had moved to a fallback session.
Convert to a property returning the current session's model. `_BROADCAST_ATTRS`
doesn't include `model`, and grep finds no external writes, so making it
read-only is safe.
Co-authored-by: d 🔹 <258577966+voidborne-d@users.noreply.github.com>
The earlier split-around-code-spans helper was incomplete (no ~~~ fences,
no indented blocks, no multi-line inline code) and over-engineered. The
underlying CommonMark hazard is only the start-of-line HTML block that
swallows the next line — mid-line tags are inline HTML Rich already
renders as text. Anchoring the regex to line start (^ + MULTILINE,
optional <=3 leading spaces) handles the original swallow case while
leaving every code-region variant intact. One known gap: a <summary>
tag on the first column inside a fenced block still matches.
_META_TAG_RE blindly stripped the tags so inline-code samples like
'`<summary>x</summary>`' became bare empty backticks. Split the
text on fenced/inline code regions and only strip in the gaps.
Non-ga-default themes fight Rich's frozen accent expectations — code spans
on sel_bg, link colors, heading hues end up either washed out or invisible
on themes like tokyo-night / textual-light. Until each is hand-tuned,
collapse heading / list / code styles to fg + muted so body text stays
readable; inline code also drops its sel_bg background under ga-default
(was hiding text in some terminals).
- watch_theme no longer remounts the whole transcript: just clears render
caches and repaints chrome. Long-history switches go from multi-second
Markdown reparse to ~150ms. Already-mounted message text stays in the
old palette until the next natural reflow (fold toggle, resize, new
turn, session switch).
- _markdown_rich_theme gains a colored flag. Non-ga-default themes render
Markdown in plain fg with only structural emphasis (bold/italic/code
backdrop) until per-theme accents are tuned — avoids text blending
into the background on themes whose accent slots collide with sel_bg.
- Sidebar Q/S preview used C_DIM (0.35 bg/fg blend); under the active row's
SEL_BG the contrast collapses on tokyo-night. Switch to C_MUTED (0.55).
- Drop the 'theme: X' system message — the picker provides the visual
feedback already, the extra row is noise on every preview tick.
- Replace cycle-theme with ThemePicker modal: OptionList live-previews on
highlight, Enter commits + saves, Esc reverts to the prior theme.
- Persist UI settings in temp/tui_settings.json; restored on startup.
- Theme Markdown list bullets and ordered-list numbers via markdown.list /
markdown.item.bullet / markdown.item.number — previously hard-cyan.