Engineer mode: name the run it works on, /engineer to pick it, keep each run's cost

Merged
KA
9d ago
+315-44

Stacked on #174.

Why

In engineer mode you could not tell which run your prompt would change, or how to pick another one: text silently went to the latest run. Costs were also off: re-engineering a run replaced its recorded cost with the last re-engineer's, and the client card showed the session's spend next to the run's own tokens.

What

  • The line above the input names the run engineer mode works on (id and prompt). By default it is your latest run with a HAR, and an engineer run's first line names it too.
  • /engineer [run_id] picks another run among those with a HAR. A choice holds until another run is engineered or a new agent run captures one.
  • Engineer mode has its own input hint, including when no run has a HAR yet.
  • A re-engineer adds its tokens and cost to the run's history entry.
  • The client card shows its own run's cost; the chip under the input stays the session's spend.
  • /history opened while a run wraps up waits for it, so it lists the new cost.

Verification

  • Tests cover the target, /engineer, the subcommand's run, the prompt routing, the cost sum on a real history file, the card cost and the wait. ruff and mypy are clean, and 1310 tests pass.
  • Live session in a pty with Haiku 5.5, two re-engineers of one run:
    • The seam, picker and run line named the run.
    • The card showed $0.01 per run.
    • The history went $0.11 → $0.12 → $0.13, matching history.json.

Out of scope

  • No release or version bump.

Summary by cubic

Engineer mode now names the run it works on, lets you pick a different one with /engineer, and a re-engineered run keeps the full cost of all its passes.

  • The line above the input shows the target run's id and prompt; by default it's your latest run with a HAR, and an engineer run's first line names it too.
  • /engineer [run_id] picks another run among those with a HAR; the choice holds until another run is engineered or a new agent run captures one.
  • Engineer mode has its own input hint, including when no run has a HAR yet.
  • A re-engineer adds its tokens and cost to the run's history entry instead of replacing them.
  • The client card shows its own run's cost; the chip under the input keeps showing the session's spend.
  • /history opened while a run wraps up waits for it, so it lists the new cost.

RetriggerView in GreptileConfidence Score: 4/5

Refresh the default engineer target after capture before merging so later prompts do not change an older run.

Findings

  1. P1 Engineer targets the previous capture ▶
  2. P2 Older capture costs disappear ▶
Fix with agent prompt
### Issue 1
src/reverse_api/repl/app.py:365-367
If the user switches to engineer mode while a new agent run is still capturing, `find_target()` selects the previous run because the new HAR does not exist yet. Nothing refreshes that choice when capture finishes. After `/new`, the next engineer prompt still changes the previous run's client instead of the latest capture's. Refresh the default target after capture finishes.

### Issue 2
src/reverse_api/cli.py:1760
Older history entries can store spending only in `cost` or `total_cost`. `_run_totals()` adds only matching keys, while `recorded_cost()` prefers `estimated_cost_usd`. An old `cost: 0.50` plus a new `estimated_cost_usd: 0.25` therefore displays $0.25 rather than $0.75. Normalize the old cost before adding the new cost so these saved runs retain their capture spending.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Engineer mode now names its target and adds /engineer to choose another saved capture.

  • Engineer mode shows and works on a named run with a HAR.
  • Re-engineered runs keep their total usage while cards show each run’s cost.
  • The history list waits for a wrapping run to save its cost.

Reviews (1) · Last reviewed commit: "feat(engineer): name the run engineer mo..." · Reviewed by Greptile