Skip to content

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

Closed

Description

@admarble

Context

#540 shipped the experimental multi-issue TUI dashboard (M1). The now line in IssueBox is phase-coarse — running <phase> — because the existing onProgress event is the only available signal.

Spec Open Question #1 for #540 enumerated three options; M1 shipped (a). This issue tracks (b) and/or (c).

Options

(b) Log-tail enrichment

Tail .sequant/logs/<issue>-<phase>.log at the polling cadence (10 Hz). Update currentPhase.nowLine to the last log line; update currentPhase.lastActivityAt to the log file mtime. Bounded by a short head-truncation to keep reads cheap.

(c) Structured activity hook

Instrument the Claude CLI / agent driver to emit structured activity events (file edits, tool calls). Route through RunOrchestrator.wrapProgress to populate currentPhase directly.

Acceptance Criteria

  • currentPhase.nowLine surfaces sub-phase activity (option b or c)
  • currentPhase.lastActivityAt advances when the underlying signal changes (so the "last activity Xs ago" stamp actually ticks)
  • Polling overhead stays within the existing 10 Hz budget
  • When no activity is observed for ≥5s, the line falls back to the coarse running <phase> rather than going blank

Dependencies

Labels

enhancement, cli, backlog

Activity

  1. added
    enhancement
    cli
    on Apr 20, 2026
  2. added 2 commits that reference this issue on Apr 20, 2026
  3. admarble commented on Apr 23, 2026

    @admarble
    ContributorAuthor

    → PARK — Author-intended backlog per body (label not yet applied). Follow-on to experimental M1 TUI from #540/#542.
    Resume after: M1 TUI graduates from experimental, or user decides to advance.

    Consider: `gh issue edit 543 --add-label backlog` to match the stated intent.

  4. admarble commented on Apr 26, 2026

    @admarble
    ContributorAuthor

    → PARK — Author-intended backlog per body; follow-on to experimental M1 TUI from #540/#542
    Resume after: M1 TUI graduates from experimental, or user decides to advance

    Cleanup: gh issue edit 543 --add-label backlog to match stated intent.

  5. admarble commented on May 11, 2026

    @admarble
    ContributorAuthor

    Heads-up: #624 (run renderer follow-ups) overlaps with this issue.

    #624 item 1 imposes a height cap on the live zone (max(8, process.stdout.rows - 5)), and #624 item 3 adds loop N/M · last fail: <reason> to the live-zone status cell. Both touch the same data model that this issue's nowLine enrichment would extend.

    Whoever picks up either issue should read the other first to avoid reshaping the live-zone layout twice. Easiest path may be to fold this into #624's scope as a coherent live-zone redesign — worth a design discussion before either is assigned.

  6. admarble commented on May 11, 2026

    @admarble
    ContributorAuthor

    Supersedes 2 prior assessments (most recent: 2026-04-26)

    → PARK — Author-intended backlog; M1 TUI from #540 still experimental. New signal: #624 (run renderer follow-ups, opened today) touches the same live-zone data model — item 3 of #624 adds `loop N/M · last fail: ` to the status cell, which is exactly the nowLine enrichment surface.

    Resume after: M1 TUI graduates from experimental, OR #624 lands and a coherent live-zone redesign can be planned on top of the new shape.

    Cleanup: `gh issue edit 543 --add-label backlog` to match stated intent.

  7. admarble commented on May 11, 2026

    @admarble
    ContributorAuthor

    /exec Progress Update

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

    AC Coverage

    AC Description Status Evidence
    AC-1 currentPhase.nowLine surfaces sub-phase activity (option b or c) ✅ Implemented run-orchestrator.ts activity event handler (applyProgressEvent); phase-executor.ts wires the agent driver's onOutput stream through ExecutionConfig.onActivity
    AC-2 lastActivityAt advances when the underlying signal changes ✅ Implemented lastActivityAt = new Date() on every accepted activity event
    AC-3 Polling overhead stays within the existing 10 Hz budget ✅ Implemented ACTIVITY_THROTTLE_MS = 100 in phase-executor coalesces driver pings before re-emit; getSnapshot still returns freshly-allocated plain objects
    AC-4 Coarse running <phase> fallback after ≥5s of no activity ✅ Implemented nowLineWithStaleFallback() runs on every cloneIssueState call, so the threshold is enforced declaratively per snapshot read

    Implementation Notes (vs the issue body)

    • The issue describes option (b) as "tail .sequant/logs/<issue>-<phase>.log", but those files don't exist in this codebase — .sequant/logs/ only holds aggregate run JSON (run-*.json). Per-issue stdout transcripts live at /tmp/claude-issue-<N>.log (hook-managed). I implemented option (b)'s intent using the already-existing in-process onOutput stream from ClaudeCodeDriver, which is functionally equivalent but cheaper and avoids re-tailing what we already have in memory.
    • Option (c) (instrument the driver for structured events) was not needed — the existing stream is sufficient for nowLine. If finer signals (file edits, tool calls) are ever wanted, a derived AC for arch: typed workflow event system for decoupled progress, logging, and MCP streaming #504 would extend onActivity payloads without changing the orchestrator side.

    Heads-up on overlap with #624

    #624 landed before this PR and shaped the RunRenderer live-zone status cell, but this work touches a different layer: the multi-issue TUI (src/ui/tui/) consumes currentPhase.nowLine from RunOrchestrator.getSnapshot(), while #624's renderer reads the same ProgressCallback stream directly. Activity events are filtered out of the non-TUI line renderer (run-progress.ts) so #624's display is unaffected.

    Files Changed

    • src/lib/workflow/types.ts — extend ProgressCallback event union + add ExecutionConfig.onActivity
    • src/lib/workflow/run-orchestrator.ts — activity event handler, stale fallback, ANSI strip + last-line extraction
    • src/lib/workflow/phase-executor.ts — wire onOutput → config.onActivity with 100ms throttle
    • src/lib/workflow/batch-executor.ts — withActivityHook() adapter; applied at 3 phase call sites
    • src/commands/run-progress.ts — filter activity events out of the non-TUI renderer/heartbeat
    • src/lib/workflow/run-state.test.ts — 6 new test cases (activity flow, ANSI strip, multi-line, stale fallback, etc.)
    • src/lib/workflow/batch-executor.test.ts — 3 new test cases for withActivityHook
    • CHANGELOG.md — [Unreleased] entry

    Quality Gates

    • npm run build: ✅ pass
    • npm run lint: ✅ pass (0 warnings)
    • npx vitest run src/: ✅ 2655/2655 passing across 103 files

    Quality Plan Alignment

    N/A — no /spec was run for this issue (the implementation followed the issue's own AC list directly). Worth noting if a future review wants /spec-driven derived ACs.

    Known Gaps / Follow-ups

    • The phase-executor.ts plumbing (config.onActivity wired to onOutput) is exercised end-to-end through the orchestrator unit tests and a manual smoke test, but lacks a dedicated unit test that mocks AgentDriver. Reasoning: the wiring is ~5 lines around an existing callback path; a direct test would be heavy on mocks for marginal regression value, and the withActivityHook adapter + applyProgressEvent activity branch are both covered.
  8. admarble commented on May 12, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #543

    PR: #629 — feat(#543): enrich TUI nowLine with sub-phase activity from agent stream
    Commit reviewed: ee994bb
    Branch: 0 commits behind origin/main ✅

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original currentPhase.nowLine surfaces sub-phase activity (option b or c) ✅ MET applyProgressEvent handles new "activity" event variant; phase-executor taps the existing onOutput stream and re-emits through ExecutionConfig.onActivity. Implements option (b)'s intent over the in-process agent stream — the issue body assumes .sequant/logs/<issue>-<phase>.log files exist but they don't (only aggregate run-*.json); the in-memory stream is functionally equivalent and cheaper. Documented clearly in the PR description.
    AC-2 Original lastActivityAt advances when the underlying signal changes ✅ MET state.currentPhase.lastActivityAt = new Date() set on every accepted activity event (run-orchestrator.ts:276). Verified by run-state.test.ts "updates nowLine and lastActivityAt on activity events".
    AC-3 Original Polling overhead stays within the existing 10 Hz budget ✅ MET ACTIVITY_THROTTLE_MS = 100 (phase-executor.ts:623) coalesces driver pings to ≤10 Hz before re-emit. getSnapshot() still returns freshly-allocated plain objects; no extra work per poll on the read side.
    AC-4 Original When no activity is observed for ≥5s, fall back to coarse running <phase> rather than going blank ✅ MET nowLineWithStaleFallback() runs on every cloneIssueState (run-orchestrator.ts:1056); when ageMs ≥ ACTIVITY_STALE_MS (5000) it returns formatCoarseNowLine(phase). Declarative per snapshot read — no timer churn. lastActivityAt preserved so the "Xs ago" stamp continues to tick.

    Coverage: 4/4 AC items fully met
    Original ACs: 4/4 met
    Derived ACs: N/A — no /spec was run for this issue.


    Quality Plan Verification

    N/A — No quality plan found in issue comments.


    CI Status

    Check State Bucket Impact
    build (20.x) SUCCESS pass ✅ MET
    build (22.x) SUCCESS pass ✅ MET
    typecheck SUCCESS pass ✅ MET
    validate-skills SUCCESS pass ✅ MET
    validate-plugin SUCCESS pass ✅ MET

    CI Summary: 5 passed, 0 pending, 0 failed


    Stale Branch Check

    Check Value
    Commits behind origin/main 0
    Threshold 5
    Status ✅ OK

    Quality Metrics

    Metric Value Status
    Type issues (new any / as any) 0 OK
    Deleted tests 0 OK
    Files changed 8 OK
    Lines added +290 -
    Lines deleted -17 -

    Build Verification

    N/A — Build passes locally and in CI.


    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    src/lib/workflow/types.ts Optional (types-only) N/A (no runtime logic) -
    src/lib/workflow/run-orchestrator.ts Standard ✅ Yes src/lib/workflow/run-state.test.ts (+7 new cases)
    src/lib/workflow/phase-executor.ts Standard ⚠️ Transitive Wiring (~5 lines around existing onOutput callback); covered by integration through orchestrator tests. Author flagged this gap in PR body with clear cost-benefit reasoning.
    src/lib/workflow/batch-executor.ts Standard ✅ Yes src/lib/workflow/batch-executor.test.ts (+3 new cases for withActivityHook)
    src/commands/run-progress.ts Standard ⚠️ Two-line filter (if (event === "activity") return); behavior is "don't break non-TUI renderer" — trivially verified by existing tests not failing.
    CHANGELOG.md Optional N/A -

    Coverage: Core behavior (4/4 ACs) fully covered by 9 new tests. Thin wiring layers (phase-executor onActivity throttle + run-progress filter) covered transitively; explicit cost-benefit waiver documented in PR body is reasonable per feedback_evaluate_gaps_before_fixing.md.
    Critical paths without tests: None.

    Targeted test run: 51/51 passing in run-state.test.ts + batch-executor.test.ts (3.41s).
    Full suite (per PR body): 2655/2655 across 103 files.


    Code Review

    Strengths:

    • Clean separation of concerns. Activity event is a new ProgressCallback variant — orchestrator updates state; non-TUI renderers filter it out at the boundary (run-progress.ts). No layering violation.
    • Throttle implemented at the right layer. ACTIVITY_THROTTLE_MS = 100 lives in phase-executor (per-phase scope, not global), matching the 10 Hz TUI poll budget exactly. Errors in the activity callback are swallowed so the run is never disrupted.
    • Stale fallback is declarative, not timer-driven. nowLineWithStaleFallback is computed at snapshot-read time — no setInterval, no race risk. Preserves lastActivityAt so the "Xs ago" stamp still ticks even in coarse mode.
    • Race guard. applyProgressEvent ignores activity events for stale phase names (test "ignores activity events for stale phase names"), correctly handling the race between completion and a final flushed chunk.
    • Zero overhead when off. withActivityHook returns the input config unchanged when onProgress is undefined — non-TUI runs pay nothing.
    • Honest divergence note. PR description explicitly explains why option (b)'s "tail .sequant/logs/-.log" was implemented over the in-process stream instead (those log files don't exist in this codebase).
    • CHANGELOG entry is detailed and accurate.

    Issues: None blocking.

    Suggestions (non-blocking):

    • Trailing-edge throttle drop. The 100ms throttle is leading-edge — if a final useful output chunk arrives within 100ms of the previous emit and activity then stops, that line is lost and the cell falls back to coarse after 5s. Minor UX wart; the 5s fallback masks it. Not worth fixing.
    • extractActivityLine only strips SGR escapes (\x1b\[[0-9;]*m). Cursor-movement / clear-screen sequences would pass through. Almost certainly fine for typical agent output, but a follow-up could broaden the regex if real output proves noisy.

    Test Quality Review

    Category Status Notes
    Behavior vs Implementation ✅ OK Tests assert on observable snapshot state (getSnapshot().issues[0].currentPhase.nowLine), not internals.
    Coverage Depth ✅ OK Happy path, multi-line chunk, ANSI strip, stale-phase race, empty text, fresh-vs-stale fallback boundary — all covered.
    Mock Hygiene ✅ OK No mocks needed in run-state.test.ts — drives via the public onProgress callback. batch-executor.test.ts uses minimal vi.fn() for callback assertion.
    Test Reliability ✅ OK One 5ms setTimeout to ensure Date.now() advances ≥1ms — narrow and necessary. Forced clock manipulation (new Date(Date.now() - 6_000)) used for the stale-fallback test, avoiding real sleep.

    Anti-Pattern Detection

    Dependency Audit

    N/A — No package.json changes.

    Code Patterns

    No new anti-patterns introduced. No any / as any additions in source files. No empty catch blocks for control flow — the two try { onActivity(text) } catch {} swallows are intentional and documented (activity reporting must never disrupt the run). No N+1, no hardcoded secrets, no SQL.


    Call-Site Review

    New exported functions detected: 1

    Function Call Sites Loop? Conditions AC Match
    withActivityHook(config, issue, phase, onProgress) batch-executor.ts:509 (spec), batch-executor.ts:761 (main phase loop), batch-executor.ts:914 (quality-loop) Phase loop site is inside the per-phase for loop All three executePhaseWithRetry invocations wrapped consistently ✅ Covers all phases (spec, main, loop) — matches AC-1's "sub-phase activity" requirement across the full phase set

    Findings: All executePhaseWithRetry call sites are wrapped. No phase emits agent output without the activity hook attached.


    CLI Registration Verification

    N/A — No RunOptions changes. The new onActivity?: (text: string) => void lives on ExecutionConfig (internal config), not RunOptions. No user-facing CLI flag needed.


    Execution Evidence

    N/A — No scripts/ or CLI command changes. This is a library-internal wiring change consumed transitively by the experimental TUI (--experimental-tui already exists).


    Skill Command Verification

    N/A — No .claude/skills/**/*.md files changed.


    Smoke Test

    N/A — No workflow-affecting changes (skills, scripts, CLI). The behavior change is internal to the multi-issue TUI rendering path; the existing --experimental-tui flag exercises it.


    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists ✅ Found
    User-facing changes ✅ Yes (feat)
    [Unreleased] entry ✅ Present (detailed)
    Entry format ✅ Valid (under Added; references #543)

    Result: CHANGELOG requirements met.


    Documentation Check

    docs/features/experimental-tui-dashboard.md already documents the target behavior — the example at line 51 shows now ⠙ writing src/blog/pagination.tsx followed by last activity 00:02s ago. Before this PR, that example was aspirational (the M1 TUI only rendered the coarse running <phase> form per the issue body). This PR makes the example accurate without docs changes. No update needed.


    Self-Evaluation

    • Verified working: Yes — ran the targeted test files (51/51 passing in 3.41s) and traced the full activity event path inline: agent driver onOutput → phase-executor 100ms throttle → config.onActivity → withActivityHook → ProgressCallback("activity") → RunOrchestrator.applyProgressEvent → state.currentPhase → cloneIssueState snapshot with nowLineWithStaleFallback.
    • Test efficacy: High — the 9 new tests assert on the AC space directly (nowLine updates, lastActivityAt advances, 5s stale fallback, plus 4 edge cases) and exercise the public ProgressCallback surface.
    • Likely failure mode: Trailing-edge throttle drop — if a final useful output chunk arrives within 100ms of the previous emit and the agent then goes silent, that line is lost. The 5s coarse-fallback masks it gracefully. Not a correctness bug.
    • Verdict confidence: High. Small, focused change (8 files, +290/-17), all 4 ACs literally met, all 5 CI checks green, no new any types, lint clean, branch in sync with main.

    Verdict: READY_FOR_MERGE

    A+ implementation. All four acceptance criteria are literally met, the change is well-scoped (8 files, +290/-17), tests cover the AC space with 9 new cases, CI is fully green, and the PR description honestly documents one design deviation from the issue body (option b implemented over the in-process agent stream instead of tailing nonexistent .sequant/logs/<issue>-<phase>.log files) with sound reasoning.

    Documentation

    Before merging, run /docs 543 to refresh docs/features/experimental-tui-dashboard.md if you want to document the new fall-back-to-coarse-after-5s behavior beyond the existing example (optional — current docs are not misleading).

    Next Steps

    1. Merge PR feat(#543): enrich TUI nowLine with sub-phase activity from agent stream #629.
    2. Optional: /docs 543 to add a short note on the 5s stale-fallback in experimental-tui-dashboard.md.
    3. Consider a follow-up if you want trailing-edge throttle (very minor UX polish; not regression-blocking).
  9. added
    ready-for-review
    on May 12, 2026
  10. added a commit that references this issue on May 13, 2026
  11. admarble commented on May 13, 2026

    @admarble
    ContributorAuthor

    QA Gap-Fix Follow-up

    Commit d051c92 (on top of ee994bb) closes the four non-blocking gaps from the prior QA review.

    What changed

    Gap Fix
    Throttle in phase-executor.ts had no direct test Extracted createThrottledReporter(fn, intervalMs) as a pure, exported helper with leading + trailing throttle (was leading-only). Replaces the inline closure.
    Trailing-edge throttle drop Same helper — the latest payload during a window is now stashed and fires ~100ms after the burst ends, so the cell no longer goes stale until the 5s coarse fallback.
    extractActivityLine only stripped SGR escapes Broadened regex from \x1b\[[0-9;]*m to \x1b\[[0-9;?]*[a-zA-Z] — now strips all CSI sequences (cursor moves, line clears, DEC private-mode toggles).
    run-progress.ts activity filter had no test New src/commands/run-progress.test.ts with two tests covering the filter for both the renderer and -q heartbeat branches.

    Test delta

    • +9 tests, all passing (was 2655 → 2664 in src/):
      • 6 cases 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.
      • 1 case in run-state.test.ts asserting non-SGR CSI escapes (\x1b[2K\x1b[G\x1b[?25l…) are stripped.
      • 2 cases in src/commands/run-progress.test.ts for the activity-event filter.
    • Lint: clean.
    • Build (tsc): clean.
    • CI: all 5 checks green on d051c92 (build 20.x / 22.x, typecheck, validate-skills, validate-plugin).

    Behavior shift

    User-visible: the experimental TUI's now line will reflect one final activity ping ~100ms after a burst of agent output ends, instead of going stale until the 5s coarse fallback. AC-3 (≤10 Hz poll budget) preserved — the throttle still emits at most 2 fires per 100ms window.

    Updated verdict

    READY_FOR_MERGE — no known gaps remaining. CHANGELOG entry refreshed in the same commit to reflect the new throttle and ANSI behavior.

  12. added a commit that references this issue on May 13, 2026
  13. added 2 commits that reference this issue on Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    clienhancementready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions