Skip to content

fix(desktop): clean ANSI escapes from agent log tail + drop dead AppHandle plumbing#756

Merged
wesbillman merged 2 commits into
mainfrom
rick/agent-log-display
May 27, 2026
Merged

fix(desktop): clean ANSI escapes from agent log tail + drop dead AppHandle plumbing#756
wesbillman merged 2 commits into
mainfrom
rick/agent-log-display

Conversation

@wesbillman
Copy link
Copy Markdown
Collaborator

What

Two related fixes for the desktop agent log viewer:

  1. Strip ANSI escapes from the agent log tail. The harness (sprout-acp) emits colorized tracing output. When its stdout/stderr is redirected to a log file by the desktop spawn path, the escape codes get baked into the file and render as ESC[2m-style gunk in the desktop log viewer's <pre>.
  2. Drop unused AppHandle plumbing in command discovery. While in the area, removed a dead app: Option<&AppHandle> parameter that was threaded through five functions in managed_agents/discovery.rs and never read at any layer. The unused-variable warning that surfaced this is now silenced.

How

  • read_log_tail in desktop/src-tauri/src/managed_agents/storage.rs pipes the buffer through strip-ansi-escapes::strip_str before returning. The crate delegates to vte — the same terminal parser Alacritty uses — so it correctly handles CSI, OSC, DCS, and C1 codes that a hand-rolled scrubber would silently mangle.
  • sprout-acp itself is not changed. Terminals, tail -f, CI logs, etc. still get the colors.
  • app: Option<&AppHandle> is removed from command_search_dirs, resolve_workspace_command, resolve_command, resolve_command_uncached, and command_availability. All six call sites (agent_discovery, agent_models, media, runtime) updated. The discover_managed_agent_prereqs Tauri command no longer needs the injected AppHandle either. Frontend invoke contract unchanged.

Why

  • ANSI parsing is deceptively non-trivial — a 50-line hand-rolled stripper plus tests would still miss DCS/C1 cases. strip-ansi-escapes is one line, well-maintained, and the standard Rust answer (~70M downloads). Net new transitive dep is just vte.
  • The dead AppHandle parameter was carrying ghost intent across the public API. If a future change needs AppHandle (e.g. resolve_resource for bundled sidecars), threading it back in will be a self-documenting diff rather than dead plumbing.

Tests

  • New unit test in storage.rs covers a typical colorized tracing line.
  • cargo check --no-default-features clean with no warnings.
  • Lefthook pre-push (rust-fmt, rust-clippy, rust-tests, web-check, desktop-check, desktop-tauri-fmt, desktop-tauri-check, desktop-build, mobile-check, mobile-test) all green.

The agent harness (sprout-acp) emits colorized tracing output. When
its stdout/stderr is redirected to a log file by the desktop spawn
path, the ANSI escape codes get baked into the file and render as
`ESC[2m`-style gunk in the log viewer's <pre>.

Strip the escapes in `read_log_tail` (desktop-only) using the
`strip-ansi-escapes` crate, which delegates to `vte` — the same
terminal parser Alacritty uses. Handles CSI, OSC, DCS, and C1 codes
correctly, where a hand-rolled scrubber would silently mangle them.

Leaves sprout-acp's logging untouched so terminals, `tail -f`, and
CI remain colorized.

Signed-off-by: Wes <wesbillman@users.noreply.github.com>
The `app: Option<&AppHandle>` parameter was threaded through five
functions in `managed_agents/discovery.rs` (`command_search_dirs`,
`resolve_workspace_command`, `resolve_command`, `resolve_command_uncached`,
`command_availability`) and never read by any of them. This produced an
unused-variable warning and carried ghost intent across the public API.

Remove the parameter at every layer, drop the now-unused `AppHandle`
imports, and update the six call sites in `agent_discovery`,
`agent_models`, `media`, and `runtime`. The `discover_managed_agent_prereqs`
Tauri command no longer needs the injected `AppHandle` either.

If a future change needs `AppHandle` (e.g. for `resolve_resource` to
locate bundled sidecars), threading it back in will be a self-documenting
diff rather than dead plumbing.

No behavior change.

Signed-off-by: Wes <wesbillman@users.noreply.github.com>
@wesbillman wesbillman requested a review from a team as a code owner May 27, 2026 16:01
@wesbillman
Copy link
Copy Markdown
Collaborator Author

BEFORE:

�[2m2026-05-27T00:22:29.381046Z�[0m �[32m INFO�[0m �[2msprout_acp�[0m�[2m:�[0m sprout-acp stopped

AFTER:

2026-05-27T15:37:15.552965Z  INFO sprout_acp: relay observer enabled

@wesbillman wesbillman merged commit 9823ff5 into main May 27, 2026
15 checks passed
@wesbillman wesbillman deleted the rick/agent-log-display branch May 27, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant