Skip to content

feat(#543): enrich TUI nowLine with sub-phase activity from agent stream - #629

Merged
admarble merged 2 commits into
mainfrom
feature/543-feat-tui-enrich-nowline-with-per-file-log-tail-act
May 13, 2026
Merged

admarble merged 2 commits into
mainfrom
feature/543-feat-tui-enrich-nowline-with-per-file-log-tail-act

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

  • Wires the agent driver's existing onOutput stream to enrich the multi-issue TUI's now line with sub-phase activity, replacing the coarse running <phase> placeholder from Live multi-issue dashboard for sequant run — concurrent box rendering (read-only TUI) #540.
  • Adds an "activity" variant to ProgressCallback; RunOrchestrator strips ANSI, takes the last non-empty line, updates nowLine + lastActivityAt, and substitutes the coarse form when activity is ≥5s stale.
  • Implements option (b) from the issue body using the in-process stream rather than tailing a log file — .sequant/logs/<issue>-<phase>.log files were assumed by the issue but never existed (.sequant/logs/ holds aggregate run JSON only).

Implementation notes

  • Phase executor throttles activity to one emit per ~100ms so the TUI's 10 Hz poll budget is preserved (AC-3).
  • New withActivityHook(config, issue, phase, onProgress) helper in batch-executor wraps ExecutionConfig with an onActivity adapter at each executePhaseWithRetry call site; runs without a TUI pay no overhead because the helper short-circuits when onProgress is undefined.
  • Non-TUI line renderer and -q heartbeat in run-progress.ts filter "activity" events out — they only feed the TUI's nowLine.

Pre-PR AC Verification

AC Description Status Evidence
AC-1 currentPhase.nowLine surfaces sub-phase activity ✅ Implemented run-orchestrator.ts:262-273 (activity event handler); phase-executor.ts:617-637 (onActivity wiring)
AC-2 lastActivityAt advances when signal changes ✅ Implemented run-orchestrator.ts:270 — lastActivityAt = new Date() on every accepted activity event
AC-3 Polling overhead within 10 Hz budget ✅ Implemented phase-executor.ts:625-636 — ACTIVITY_THROTTLE_MS = 100 coalesces driver pings; getSnapshot still allocates plain objects per AC-3 expectations
AC-4 Fall back to coarse running <phase> after ≥5s of no activity ✅ Implemented run-orchestrator.ts:1052-1059 — nowLineWithStaleFallback() invoked from cloneIssueState so every snapshot read enforces the threshold

Test plan

  • npm run build — clean
  • npm run lint — clean (no warnings)
  • npx vitest run src/ — 2655/2655 passing across 103 files
  • 6 new cases in run-state.test.ts covering activity nowLine updates, multi-line chunk handling, ANSI stripping, stale-phase race ignore, empty-text no-op, and 5s coarse fallback
  • 3 new cases in batch-executor.test.ts covering withActivityHook (undefined passthrough, event forwarding, error swallowing)
  • Live smoke test confirmed end-to-end wiring (orchestrator activity event → nowLine update, fresh lastActivityAt)

Closes #543

Tap the existing agent-driver onOutput stream and re-emit each chunk as
a new "activity" ProgressCallback event, throttled to ~10 Hz to preserve
the TUI's poll budget. RunOrchestrator strips ANSI, picks the last
non-empty line, updates nowLine + lastActivityAt, and substitutes the
coarse 'running <phase>' form when activity goes stale for >=5s.

Implements option (b) from the issue — using the in-process stream
rather than tailing a non-existent log file.
…, filter test

QA on PR #629 surfaced four gap-fix opportunities. Bundled here:

1. Extract `createThrottledReporter(fn, intervalMs)` in phase-executor.ts:
   leading + trailing edge throttle replacing the inline leading-only
   closure. Latest payload during a throttle window is stashed and fires
   ~100ms after the burst ends, so the TUI cell no longer goes stale
   (until the 5s coarse fallback) just because the last useful chunk
   landed inside the 100ms window. Adds `cancel()` for cleanup after
   `driver.executePhase` returns.

2. Broaden the ANSI strip in `extractActivityLine` from SGR-only
   (\x1b\[[0-9;]*m) to all CSI sequences (\x1b\[[0-9;?]*[a-zA-Z]). Covers
   cursor moves (\x1b[G), line clears (\x1b[2K), and DEC private-mode
   toggles (\x1b[?25l) that can leak through chalk/ink in agent output.

3. Add 6 unit tests for `createThrottledReporter` (leading fires,
   within-window drop with latest-stash, trailing fire of latest, no
   trailing when idle, idle-window leading resume, cancel drops pending)
   using vitest fake timers. Makes the throttle behavior — which carries
   AC-3 — directly verifiable instead of relying on the public
   `applyProgressEvent` surface to exercise it transitively.

4. Add 2 tests in the new src/commands/run-progress.test.ts covering the
   activity-event filter on both the renderer and `-q` heartbeat
   branches. If the two-line `if (event === "activity") return` guards
   are ever removed, the non-TUI line renderer would spam ~10 lines/sec
   per active phase — these tests catch that regression.

5. Add 1 test in run-state.test.ts asserting non-SGR CSI escapes are
   stripped.

All 2664 tests pass (was 2655 — exactly 9 new). Lint clean. Build clean.

Verdict in the QA comment moves from READY_FOR_MERGE-with-non-blocking-
nits to READY_FOR_MERGE-with-no-known-gaps.
@admarble
admarble merged commit 3efeffd into main May 13, 2026
5 checks passed
admarble added a commit that referenced this pull request Sep 9, 2026
…, filter test

QA on PR #629 surfaced four gap-fix opportunities. Bundled here:

1. Extract `createThrottledReporter(fn, intervalMs)` in phase-executor.ts:
   leading + trailing edge throttle replacing the inline leading-only
   closure. Latest payload during a throttle window is stashed and fires
   ~100ms after the burst ends, so the TUI cell no longer goes stale
   (until the 5s coarse fallback) just because the last useful chunk
   landed inside the 100ms window. Adds `cancel()` for cleanup after
   `driver.executePhase` returns.

2. Broaden the ANSI strip in `extractActivityLine` from SGR-only
   (\x1b\[[0-9;]*m) to all CSI sequences (\x1b\[[0-9;?]*[a-zA-Z]). Covers
   cursor moves (\x1b[G), line clears (\x1b[2K), and DEC private-mode
   toggles (\x1b[?25l) that can leak through chalk/ink in agent output.

3. Add 6 unit tests for `createThrottledReporter` (leading fires,
   within-window drop with latest-stash, trailing fire of latest, no
   trailing when idle, idle-window leading resume, cancel drops pending)
   using vitest fake timers. Makes the throttle behavior — which carries
   AC-3 — directly verifiable instead of relying on the public
   `applyProgressEvent` surface to exercise it transitively.

4. Add 2 tests in the new src/commands/run-progress.test.ts covering the
   activity-event filter on both the renderer and `-q` heartbeat
   branches. If the two-line `if (event === "activity") return` guards
   are ever removed, the non-TUI line renderer would spam ~10 lines/sec
   per active phase — these tests catch that regression.

5. Add 1 test in run-state.test.ts asserting non-SGR CSI escapes are
   stripped.

All 2664 tests pass (was 2655 — exactly 9 new). Lint clean. Build clean.

Verdict in the QA comment moves from READY_FOR_MERGE-with-non-blocking-
nits to READY_FOR_MERGE-with-no-known-gaps.
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.

feat(tui): enrich nowLine with per-file / log-tail activity

1 participant