# okstra-inspect facet — cost

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.

## cost

Trigger phrases: "okstra context-cost", "context cost", "context-cost", "read cost", "artifact cost", "task bundle cost", "agent read cost".

Read-only estimate of how much file/context surface a prepared task bundle asks the lead, analysis workers, and report-writer to absorb. This sub-command does **not** mutate task artifacts.

### cost.1 — Resolve target

Accepted target forms:

1. Full task-key: `<project-id>:<task-group>:<task-id>`.
2. Bare token — a task-id (e.g. `DEV-9184`) **or** a task-group (e.g. `PROD`).
3. Task root path, e.g. `<projectRoot>/.okstra/tasks/<group>/<task-id>`.

If the user gives a task root path, run `okstra context-cost <absolute-or-user-provided-path>` directly.

If the user gives a full task-key, run:

```bash
okstra context-cost <task-key> --project-root <projectRoot>
```

If the user gives a bare token, resolve it via the standard task-key resolution rule in `SKILL.md` (core).

If the user asks generally ("show me the context cost") and does not name a task, apply the core no-task fallback to pick the task to measure.

### cost.2 — Run estimator

Use the CLI output as the source of truth:

```bash
okstra context-cost <resolved-target> --project-root <projectRoot>
```

Do not re-count files manually unless the CLI fails and the user explicitly asks for manual fallback.

### cost.3 — Render

Render the CLI JSON into the cost.4 template. Each row's Files / Size / ~Tokens come from the matching output block — `totals` (Task bundle, Current run, Legacy timestamp), `instructionSet`, `leadPhase1`, `analysisWorker`, `reportWriter`, `skillAssets`; their exact field names are in the CLI output (do not re-list them here). Format bytes as raw + rounded KB/MB.

Field-specific notes (these affect interpretation, not just display):
- Analysis worker uses per-worker fields (`bytesPerWorker`, `estimatedTokensPerWorker`). Use `analysisWorker.estimatedReductionPercent` directly for the worker-input reduction — do **not** recompute it from `bytesPerWorker` when `mode == "analysis-packet-primary"` (that value is already the packet-primary cost).
- `estimatedTokens*` are a static ranking heuristic (~4 ASCII chars/token, non-ASCII ≈ 1 token/char), never billing numbers — actual cost is the token-usage collector's domain.
- `skillAssets` = the per-run hot-path instruction assets loaded OUTSIDE the task bundle (skill bodies + agent specs), sorted by size — the prompt-diet target.

### cost.4 — Output template

```markdown
## okstra Context Cost — <task-key>

| Surface | Files | Size | ~Tokens |
|---|---:|---:|---:|
| Task bundle | <N> | <bytes> (<human>) | - |
| Current run | <N> | <bytes> (<human>) | - |
| Instruction set | <N> | <bytes> (<human>) | <estimatedTokens> |
| Lead Phase 1 (`<mode>`) | <N> | <bytes> (<human>) | <estimatedTokens> |
| Analysis worker / worker (`<mode>`) | <N> | <bytes> (<human>) | <estimatedTokensPerWorker> |
| Report writer synthesis | <N> | <bytes> (<human>) | <estimatedTokens> |
| Skill assets (hot path) | <N> | <bytes> (<human>) | <estimatedTokens> |

- Current run: `<currentRunPath-or-->`
- Legacy timestamp artifacts: `<N>`
- Legacy full worker contract: `<legacyFullContractBytesPerWorker>` bytes (`<human>`) per analysis worker
- Packet estimate: `<estimatedPacketModeBytesPerWorker>` bytes (`<human>`) per analysis worker
- Estimated worker-input reduction: `<percent>%`

### Reading

<One or two Korean sentences explaining the main bottleneck and the next likely optimization target.>
```

Interpretation rules:

- `leadPhase1.mode == "active-run-context"` means the compact lead intake file is present and should be treated as the primary lead read surface.
- `leadPhase1.mode == "legacy-five-file"` means this task was prepared before active-run-context, or the manifest does not reference it.
- `analysisWorker.mode == "analysis-packet-primary"` means new workers should read `analysis-packet.md` first and open full source inputs only for evidence checks or missing detail.
- If `analysisWorker.mode == "full-input-contract"` and `estimatedReductionPercent` is low, the next target is worker prompt/input contract slimming.
- If `reportWriter.bytes` dominates, the next target is a compact `synthesis-input` artifact.
- If `skillAssets.estimatedTokens` dominates the per-run fixed cost, the next target is slimming the largest `skillAssets.files[]` entries (prompt diet — perf plan v2 P2), e.g. thin-core + lazy-sidecar split.
- If `legacyTimestampFileCount` is high, recommend current-view/cold-artifact separation or retention cleanup, not destructive deletion by default.
