Refresh agentd top: unified running view, fast startup, robust cursor restore, cheap LLM summaries

t-798·WorkTask·
·
·
Created4 days ago·Updated4 days ago·pipeline runs →

Description

Edit

agentd top needs a functional refresh. Current regressions:

1) It does not show running persistent agents (only scans oneshot run directories). 2) Startup is slow (scales with historical run count; currently performs one docker ps call per run directory). 3) On exit, terminal cursor can remain hidden.

Desired behavior:

  • Show running agents from both domains:
  • oneshot runs
  • persistent agents
  • Include a concise, cheap LLM-generated current-status line per agent.
  • Startup and refresh should be fast and non-blocking.
  • Cursor should always be restored on exit (normal exit, ESC/q, and exceptions).

Implementation should keep costs low (summary generation rate-limited and cached), and avoid polling patterns that scale with total historical runs.

Timeline (10)

🔄[human]Open → InProgress4 days ago
💬[human]4 days ago

Diagnosis from current code:

  • top only calls getRunningAgents over oneshot log directories and never loads persistent agents, so it misses currently running persistent sessions.
  • main dispatch ignores the top --workspace argument (pattern is Top _ showAll -> getLogRoot ...), so explicit workspace/log-root override has no effect.
  • runTop blocks before first render via initialAgents <- getRunningAgents ...
  • getRunningAgents does one docker ps -f name=<run> per run directory; with many historical runs this dominates startup/refresh time.
  • aiCurrentActivity is always Nothing, so there is no activity summary despite UI column.
  • top uses customMainWithDefaultVty + neverShowCursor with no explicit final cursor restore fallback.

Proposed implementation plan: 1) Replace top data loading with a unified snapshot that merges oneshot + persistent running agents. 2) Fix top argument wiring so top --workspace is honored. 3) Eliminate per-run docker calls: query running containers once per refresh and intersect with run IDs. 4) Make refresh non-blocking (background worker + BChan updates); render immediately with loading state. 5) Add activity summary pipeline:

  • deterministic fallback summary immediately from latest events/session lines,
  • cheap LLM summary async via Omni.Agents.Summarize (haiku model),
  • cache + fingerprint per agent so we only resummarize on new activity.

6) Add agent kind (oneshot/persistent) so Enter/l and k route correctly (logs and stop behavior). 7) Harden terminal teardown: explicit Vty lifecycle and finally block that always re-enables cursor. 8) Add tests for merge/filter logic + summary cache invalidation + mode-sensitive actions.

💬[human]4 days ago

Implemented refresh of agentd top in Omni/Agentd.hs.

What changed:

  • Removed top --workspace from CLI surface (per request). agentd top now only supports --all.
  • Reworked top data model to unify both domains:
  • oneshot container runs (from /var/log/agentd/<run>/events.jsonl)
  • persistent agents (from Daemon.listPersistentAgents)
  • Fixed the core visibility bug: running persistent sessions now appear in top.
  • Removed per-run docker polling:
  • old behavior did docker ps -f name=<run> per run directory
  • new behavior does one docker ps --format {{.Names}} per refresh and intersects with run IDs
  • Made startup responsive:
  • top starts with an empty/loading state
  • refreshes run via async snapshot jobs posted through BChan events
  • Added activity pipeline:
  • deterministic fallback activity from latest event/session lines
  • async cheap LLM summary refinement via Omni.Agents.Summarize (haiku model)
  • fingerprinted summary cache + in-flight dedupe to avoid redundant summarization
  • graceful fallback mode if provider init fails
  • Added kind-aware actions in top:
  • Enter/l shows logs via oneshot or persistent backend correctly
  • k stops oneshot containers or persistent sessions appropriately
  • Added terminal teardown hardening:
  • on top exit, always emit cursor-show escape in finally cleanup

Verification:

  • typecheck.sh Omni/Agentd.hs
  • lint Omni/Agentd.hs
  • bild --test Omni/Agentd.hs
  • agentd top --help now shows only [-a|--all].
  • Interactive tmux smoke check confirms running persistent agents are now listed in top.
🔄[human]InProgress → Review4 days ago
🔄[human]Review → InProgress4 days ago
💬[human]4 days ago

Adjusted top status footer to use fixed-width single-char refresh indicator to avoid horizontal jitter. Changed from 'refreshing/steady' to 'sync=R' (refreshing) and 'sync=.' (steady). Verified with typecheck.sh Omni/Agentd.hs.

🔄[human]InProgress → Review4 days ago