# okstra-inspect facet — history

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.

## history

Trigger phrases: "okstra history", "past runs", "run history", "re-run", "list tasks", "run again", "resume", "continue".

**Re-run vs Resume — decide upfront.** Re-run = start a fresh run (new run-seq, new manifest, new report) reusing an old run's parameters → `history.3`. Resume = continue an interrupted Claude session for an existing run, no new run-seq → `history.4`. If the user is ambiguous, ask — defaulting to the wrong one either wastes a fresh run-seq or silently abandons a recoverable session.

### history.1 — Project task history

1. Run `okstra model-io history-input --project-root <projectRoot>`.
2. Apply filters from user input (all optional, AND-combined):
   - `--task-type <type>` → keep entries whose `taskType` matches.
   - `--latest-run-status <status>` → keep entries whose `latestRunStatus` matches (`completed`, `contract-violated`, `error`).
   - `--task-group <group>` → keep entries whose `taskGroup` matches.
3. Sort by `updatedAt` desc.
4. Page: default `--limit 20`. If truncated, add `... <N> more (pass --limit <N> to see all)`.
5. Use the task/status/time/report lines emitted by the fixed text projection.

```markdown
## okstra Task History — <project-id>

| # | Task Key | Type | currentStatus | latestRunStatus | Last Run | Report |
|---|----------|------|---------------|------------------|----------|--------|
| 1 | proj:group:id | error-analysis | completed | completed | 2026-04-05 22:59 | .project-docs/.../final-report-*.data.json |
| 2 | proj:group:id2 | final-verification | todo | error | 2026-04-04 15:30 | -- |
```

If stdout `taskCount` is zero, answer `There is no okstra execution history yet.`

### history.2 — Run history by task

When a user selects a specific task:

1. Run `okstra model-io history-input --project-root <projectRoot> --task-ref <task-key>`.
2. Use each numbered run block for chronological status, report, run-manifest, and resume paths.
   `Status` is the run's current status from its own run-manifest (the timeline entry itself only records the prepare-time value). `Report` is `-` for a run that never validated a report — a prepared run that was superseded before it ran — so two runs never share one report in this list.

```markdown
## Runs for <task-key>

| # | Timestamp | Type | Status | Report |
|---|-----------|------|--------|--------|
| 1 | 2026-04-05 22:59 | error-analysis | completed | .../final-report-*.data.json |
| 2 | 2026-04-04 15:30 | error-analysis | error | -- |
```

### history.3 — Re-run (NEW run from old parameters)

Builds a fresh run — new run-seq, new manifest, new report — using parameters from a previous `run-manifest-*.json`. Does NOT touch old artifacts; use `history.4` to continue an interrupted session.

1. Pick the source run-manifest: `runManifestPath` from `history.2`, or task's `latestRunManifestPath` from `history.1`. Note: `latestRunManifestPath` is projected from the timeline's latest run, so it is empty when the task has no recorded run yet (timeline absent) — in that case fall back to a `history.2` per-run `runManifestPath`, or ask the user.
2. Run `okstra model-io rerun-input --run-manifest <runManifestPath>` and use its required argument lines:
   - `projectId` → `--project-id`
   - `taskGroup` → `--task-group`
   - `taskId` → `--task-id`
   - `taskType` → `--task-type`
   - `taskBriefPath` → `--task-brief`
3. Optional arguments (include only when present in source):
   - `Workers` → `--workers` (comma-separated provider ids; the projection already folds roster slot ids like `codex-verifier` down to their provider, so pass the line verbatim and never hand-assemble it from a roster)
   - `relatedTasks` → `--related-tasks`
   - model overrides → `--claude-model`, `--codex-model`, `--antigravity-model`
   - for `taskType: implementation`: `teamContract.executor.provider` → `--executor <claude|codex|antigravity>` when different from `claude`.
4. **`taskType: implementation` only — resolve `--base-ref`:** do not inspect the worktree registry. Omit `--base-ref` to reuse an existing registration. If the launch reports that no worktree is registered and a base is required, ask the user before retrying.
5. Display the assembled command:
   ```bash
   ~/.okstra/bin/okstra.sh \
     --project-id <project-id> \
     --task-group <task-group> \
     --task-id <task-id> \
     --task-type <task-type> \
     --task-brief <brief-path> \
     --workers <worker-list>
   ```
6. Once the user confirms, execute it.

### history.4 — Resume (continue an interrupted run)

Continues an existing Claude session for an unfinished run. Does NOT create a new run-seq — for a fresh dispatch use `history.3`.

1. Use `Latest resume command` from status input or `Resume command` from a history run block.
2. Verify the file exists on disk.
3. If it exists: `bash <resume-command-path>`.
4. If the path is empty or the file is missing: `No resume script available for this run. Use 'history.3' to start a fresh run instead.`
