Skip to content

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

Merged
kalil0321 merged 2 commits into
mainfrom
kalil0321/engineer-mode
Nov 15, 2026
Merged

kalil0321 merged 2 commits into
mainfrom
kalil0321/engineer-mode

Conversation

@kalil0321

@kalil0321 kalil0321 commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

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.

Written for commit 151a6bf. Summary will update on new commits.

View guided diff Turn on auto-fix

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T11:08:29.679747Z 151a6bf New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e81a276a76

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +365 to +367
if st.mode == "engineer" and not st.engineer_chosen:
run = self.cli.latest_capture()
st.engineer_target = (run["run_id"], str(run.get("prompt") or "")) if run else None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Refresh the default engineer target when a capture finishes

If the user switches to engineer mode while an agent run is still capturing, find_target() selects the previous run because the new HAR does not exist yet. When the capture finishes, finish() never refreshes this selection, and start() explicitly passes the stale target to engineer_from_prompt(). Consequently, the next engineer prompt modifies the previous client's run rather than the latest capture, even though no target was explicitly chosen. Refresh the unchosen target after capture completion, before starting any queued engineer prompt.

Useful? React with 👍 / 👎.

Comment on lines +365 to +367
if st.mode == "engineer" and not st.engineer_chosen:
run = self.cli.latest_capture()
st.engineer_target = (run["run_id"], str(run.get("prompt") or "")) if run else None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Engineer targets the previous capture

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.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/reverse_api/repl/app.py
Line: 365-367

Comment:
**Engineer targets the previous capture**

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.

---

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

Comment thread src/reverse_api/cli.py
sdk=sdk,
output_mode=output_mode,
usage=_run_totals(resume.get("usage") or {}, usage) if resume else usage,
usage=_run_totals(spent_before, usage),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Older capture costs disappear

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.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/reverse_api/cli.py
Line: 1760

Comment:
**Older capture costs disappear**

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.

@kalil0321
kalil0321 changed the base branch from kalil0321/remove-collector to main November 15, 2026 11:05
@kalil0321
kalil0321 merged commit 1f491fa into main Nov 15, 2026
15 checks passed

This branch was successfully deployed

1 active deployment
preview — 151a6bf0 Deployed Nov 15, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant