Repository navigation
Description
Motivation
There is no way to see how much agent work actually ran: "in the last 7 days Agent Code ran agents for N hours with M agents, and in project X it was N hours and M agents". Nothing durable records working time today — the only live "working" clock is renderer state that counts wall-clock time, and it is wrong across laptop sleep (#963). Building analytics on that signal would report stuck or slept-through turns as hours of work, so this depends on #963.
Intended behavior
A palette command opens an Agent Analytics window:
- Ranges: 24 hours, 7 days, 30 days, all time.
- Figures, in total and per project:
- Agent-hours — three agents working for one hour count as 3 h.
- Wall-clock hours — the same hour counts once.
- Agents — distinct agents that did work in the range, with agents the user started and orchestration workers shown separately. Terminals and native provider subagents are not counted. Reloads, provider switches and rewinds of the same agent count once.
- Projects are tabs, at the root level. Each tab lists the repository and its worktree directories underneath, with the same figures.
- Working time runs from a turn starting until it ends, including tool execution. It excludes time the machine was asleep and time blocked on a permission prompt or question. Unclean shutdowns and stuck phases never count.
- History starts when the recorder ships (no backfill from provider transcripts, which include CLI use outside Agent Code and cannot subtract sleep).
- Retention is forever, stored compactly: raw working intervals for recent days, then per-day rollups, so years of use stay small. No prompt text is ever stored.
- Numbers are computed in the main process, so every window shows the same values, and they survive restarts.
Acceptance criteria
- A single main-owned suspension signal (power monitor plus a timer-gap fallback) is shared by the turn clock and the recorder.
- Working state is derived by one pure reducer shared by the in-feed counter and the recorder.
- The recorder captures tab, repository, worktree, provider, agent identity and role at the time of work; intervals open at a crash close at the previous run's last heartbeat.
- Tests built from real on-disk recordings: a turn across a confirmed sleep excludes the sleep; an idle sleep adds nothing; an unclean shutdown adds seconds, not hours; a reload counts one agent; a permission wait splits working time.
- Compaction preserves each day's agent-hours and wall-clock hours exactly.
- The window shows both hour figures and agent counts for every range, tabs at the root with repositories and worktrees beneath.
- Command, surface, catalog and feature-reference registrations follow the existing conventions.
Open question
A tab closed and later reopened for the same folder, or merged into another: working default is to group root rows by tab title so they stay one project; to be confirmed before the aggregation stage.
Plan: docs/decomposition/agent-working-time.md on branch feat/agent-working-time. Depends on #963.
Activity