# okstra-inspect facet — time

Loaded lazily by the dispatch table in `SKILL.md` (core). Shared rules — Step 0 preflight, the standard task-key resolution rule (0/1/N), the no-task fallback, and Output Rules — live in the core file and still apply here.

## time

Trigger phrases: "work time", "elapsed time", "time summary", "duration", "elapsed", "how long did it take", "time analysis".

Aggregate elapsed work time for a task, grouped by **task type** and broken down by **worker** (lead + each worker). The `time-report` CLI reads both data sources (`history/timeline.json` runs + each run's `team-state-*.json` usage blocks) and does **all** aggregation — cross-run sums, CPU-sum vs wall-clock, timestamp parsing, unavailable detection. You only resolve the task-key, call it, and render. **Never recompute durations by hand.**

### time.1 — Resolve the task-key

Apply the standard task-key resolution rule from `SKILL.md` (core): full task-key → use directly; bare token → the resolver CLI and the 0/1/N branch. If no okstra history exists, say `No okstra history found. Run /okstra-run first.`

### time.2 — Fetch aggregated data

```bash
okstra time-report <task-key> --project-root <projectRoot> --text
```

Returns fixed labeled text (all durations are **raw milliseconds**):
- Repeated `Task type` blocks — task type, runs, lead ms, workers ms, and CPU sum ms, plus total labels
- `perWorker` — `{<taskType>: [{workerId, agents[], runs, totalMs, avgMs}]}`; only workers with a nonzero run appear, and `agents[]` lists agent labels that differ from `workerId`
- `perRunWallClock[]` — `{runTimestamp, taskType, wallClockMs}` (max `endedAt` − min `startedAt` per run)
- `phaseTimelines[]` — `{runTimestamp, taskType, phases:[{phase, firstAt, wallMsToNext}]}`
- `unavailable[]` — `{runTimestamp, taskType, reason}` for runs with no Phase-7 durations (never summed into totals)

### time.3 — Render

Convert every `*Ms` to `HH:MM:SS` (zero-pad; never show raw ms). Task types in `byTaskType` are already in chronological (first-appearance) order.

- **By task type** — `| Task type | Runs | CPU sum | Lead | Workers |` from `byTaskType`, plus a `grandTotal` row. `CPU sum` (= Lead + Workers) overlaps because workers run inside the lead's window — it is *not* wall-clock. Surface wall-clock only when the user explicitly asks, from `perRunWallClock`.
- **Per worker** (per task type) — `| Worker | Runs | Total | Avg/run |` from `perWorker`. Render the worker as bare `workerId` when `agents` is empty, else `workerId (agent1, agent2)`.
- **Phase breakdown** — "by stage"/"per stage"/"which stage took longest" in okstra most often means the **lifecycle stage (task-type)** view, which the *By task type* table above already answers — lead with that table, do not treat the request as unanswerable. Render the intra-run phase timeline only when the user clearly means within-a-run phases ("which phase", "Phase 1~7", "phase timeline"): one table per run from `phaseTimelines`: `| Phase | Start | Wall to next |` using `firstAt`/`wallMsToNext` (`null` → `--`). When `phaseTimelines` is empty, do **not** headline "not measurable" — the By-task-type table is the stage answer; mention the missing intra-run markers only as a trailing footnote.
- If `unavailable[]` is non-empty, append a trailing note listing each run with its reason. Never fold them into totals.
- Show the resolved `<task-key>` in the heading.

```markdown
## Time summary — <task-key>

### By task type

| Task type              | Runs | CPU sum   | Lead     | Workers  |
|------------------------|------|-----------|----------|----------|
| requirements-discovery | 2    | 00:33:12  | 00:12:08 | 00:21:04 |
| **Grand total**        | 6    | **03:03:06** | 01:05:49 | 01:57:17 |

### Per worker — requirements-discovery

| Worker               | Runs | Total    | Avg/run  |
|----------------------|------|----------|----------|
| lead                 | 2    | 00:12:08 | 00:06:04 |
| claude (sonnet-eval) | 2    | 00:09:12 | 00:04:36 |

> Unavailable: 1 run (implementation / 2026-04-30_03-03-48) — Phase 7 not reached
```
