fix(terminal): answer color queries before attach and add UFO support
What & why
Launching UFO in a fresh pane could insert 11;rgb:1515/1111/1010 into its first message before the user typed. The agent starts before the renderer attaches; replaying its background-color query produces a valid but late response, after UFO's roughly 150 ms probe window.
Add UFO as a built-in terminal agent with icons, a launch wrapper, positional prompts, and explicit resume support. Answer terminal color queries in the persistent PTY daemon before retention and broadcast, so startup does not depend on a renderer. Preserve an inert OSC boundary after answering to keep xterm parser transitions intact when a query interrupts another control sequence. Pass configured colors at creation and on theme changes; preserve parser/color state through handoff and gate updates on daemon capability. Bump the daemon to 0.3.5 so existing installations can upgrade. Older running daemons retain the old behavior until upgraded.
The responder handles palette/foreground/background/cursor queries, fragmented BEL/ST and UTF-8 C1 controls, setters/resets, and bounded malformed input. Additional viewers do not generate duplicate replies. The first color-capable viewer supplies colors; disconnecting it promotes the next capable viewer. Explicit theme resets survive reconnect. Incomplete parser carry is discarded on process exit so an old session cannot contaminate a replacement. UFO native turn hooks, automatic conversation discovery, model presets, and unattended runs remain unintegrated.
Before/after screenshots, trace, verification, and limitations (organization-visible Superset page).
How I tested it
- Reproduced the prefix before typing in the desktop app. On the fixed daemon, the same UFO button opens an empty prompt; typed input survives renderer reload unchanged; the signed-in conversation returns
UFO_FIXED_FINAL_927exactly. No diagnostic suppression is installed. bun run lint,bun run typecheck(42 tasks), andbun run check:i18npass.- Parser simplification removes 38 lines, three unreachable states, redundant overflow state, and a duplicate setter loop without dropping coverage. Revalidation: 189 daemon unit tests, 76 xterm comparison probes, daemon typecheck, and root lint pass. The rebuilt real-PTY suite passed 54/57 with three lifecycle timeouts; all three passed a focused rerun.
- 189 daemon unit tests, 65 focused renderer/settings tests, 6 host authority/CI integration tests, and 2 real-PTY/capability tests pass. The PTY regression receives a reply within 150 ms without a subscriber, delays attachment by one second, and checks clean later input.
- All 57 daemon integration tests pass with
--test-concurrency=1, including byte fidelity, handoff, flow control, and recovery. The concurrent run had one handoff timeout; its isolated rerun also passes. - Independent Superset agent review: 97 focused tests and 76 bounded xterm differential probes pass. Tests compare visible text, cursor position, title events, query counts, and every split boundary for interrupted controls. Stale session IDs, exit carry, legacy snapshots, viewer promotion, selection-only theme changes, and resets while disconnected have regressions.
- Full
bun run testis not green: 34 desktop failures occurred in the broad run; 65 isolated desktop tests pass. A host session-folder test also collided with an existing localdupe-targetfolder. Full-suite causes are not fully resolved. Separately, the first GitHub Test job exposed two real PR regressions: fake PTYs omitted the newly accessed metadata. Those fixtures are corrected and both tests pass locally. The follow-up GitHub Test job ended in a Bun segmentation fault/SIGILL; Build, Lint, and Typecheck passed. CI will rerun on the cleanup commit.
Checklist
- PR title follows conventional commits
-
bun run lintandbun run typecheckpass - Allow edits from maintainers: same-repository branch, not a fork PR
Summary by cubic
Fixes terminal color queries so the PTY daemon answers them before the renderer attaches, preventing UFO's background-color probe from inserting 11;rgb:1515/1111/1010 into its first message. Adds UFO as a built-in terminal agent.
Behavior and integration
- The daemon now answers foreground/background/cursor/ANSI queries with a parser that preserves xterm boundaries, including UTF-8 C1 controls and fragmented BEL/ST terminators; multiple viewers don't generate duplicate replies and oversized or malformed controls are bounded.
- Colors are passed at session creation and on theme changes; identical theme syncs keep overrides while new assignments reset them, and state survives daemon handoff. Updates are gated on daemon capability.
- UFO launches run in the local workspace with a positional prompt; resume uses
ufo --resume <conversation-id>. UFO has no native turn hooks, session discovery, model presets, or unattended run support; those remain unintegrated.
Migration
- The daemon is bumped to 0.3.5; older running daemons keep the old behavior until upgraded.
Summary by CodeRabbit
- New Features
- Added UFO as a built-in terminal agent, with setup support, a Settings icon, and the ability to resume conversations.
- Terminal sessions now use your selected theme’s foreground, background, cursor, and ANSI colors. Color settings update when the theme changes and are applied to new sessions.
- Terminal color settings are preserved when sessions are handed off or restored.
- Documentation
- Added guidance for installing and using UFO, including supported launch and resume commands.