Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- **`hermes` backend**: `"sdk": "hermes"` engineers a saved capture through the local [`hermes` CLI](https://hermes-agent.nousresearch.com/docs) (`hermes chat --oneshot --format stream-json`), so a run needs no API key in rae — the model, the provider and the authentication are the user's own Hermes configuration. `hermes chat` reads the prompt on stdin, so nothing the model reads is shell-parsed; `hermes_max_turns` overrides the turn cap from the user's Hermes config; runs start with `--ignore-rules` so an `AGENTS.md`/`CLAUDE.md` cannot steer them, and estimate cost from the CLI's token counts, leaving it at 0 for a model with no known price. The backend covers `engineer` only: with `"sdk": "hermes"` the `agent` command stops before browser setup, so capture with another SDK (claude, opencode, copilot or cursor) and engineer that run with hermes; `agent --dry-run` reports the same error. The CLI is found on `PATH` or through `RAE_HERMES_BIN`, and `agent --dry-run` reports it as a check.
- **Copy text from the session**: the session takes the mouse for the wheel and for clicking files and links, so the terminal could not select its text. Dragging over the conversation now selects it and copies it to the clipboard when you let go, with `pbcopy`, `wl-copy`, `xclip` or `xsel`, or through the terminal (OSC 52) otherwise and over SSH. A click without a drag still opens a link.

### Fixed
- **Option+Delete in the session's input bar**: it deleted a single character, and on an empty bar it stopped the run, because the terminal sends it as Esc then Delete and the session acted on Esc at once. Esc now waits 50 ms for what follows, so Option+Delete deletes the word before the cursor and Option+arrows sent as Esc b / Esc f jump by word, while a lone Esc still stops the run or closes a menu.
- **Engineer mode names the run it works on**: the line above the input shows its id and prompt, by default your latest run with a HAR, and an engineer run's first line names the run it changes. `/engineer [run_id]` picks another one among the runs that have a HAR. A choice holds until another run is engineered or a new agent run captures one.

### Removed
- **Collector mode**: the `collector` command, the session's collector mode, the `collector_model` setting and the `collector` install extra. rae stays on turning a site's traffic into an API client. Existing configs and histories still load: an old `collector_model` is ignored, past collector runs stay in `/history`, and `./collected/` folders are left as they are.

### Fixed
- **Option+Delete in the session's input bar**: it deleted a single character, and on an empty bar it stopped the run, because the terminal sends it as Esc then Delete and the session acted on Esc at once. Esc now waits 50 ms for what follows, so Option+Delete deletes the word before the cursor and Option+arrows sent as Esc b / Esc f jump by word, while a lone Esc still stops the run or closes a menu.
- **A re-engineered run keeps its cost**: its tokens and cost in `/history`, `list` and `show` add up every re-engineer instead of keeping only the last, so a run's cost still counts its capture.
- The client card shows what its own run cost, not the session's spend so far; the chip under the input still shows the session's.
- `/history` opened while a run wraps up waits for it, instead of listing that run's cost from before.

## [0.15.0] - 2026-11-08

### Changed
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Cycle modes with **Shift+Tab**:
|------|--------------|
| `manual` | You drive the browser; AI generates the client from captured traffic. |
| `agent` | An AI agent drives capture autonomously (Playwright or Chrome MCP, or Vercel agent-browser CLI). |
| `engineer` | Re-run generation on a previous capture (`engineer <run_id>`). Needs a HAR, so it works on `auto`, `agent-browser` and manual runs, not chrome-mcp runs. |
| `engineer` | Re-run generation on a previous capture (`engineer <run_id>`). In the session it works on your latest run with a HAR, named above the input; `/engineer` picks another. Needs a HAR, so it works on `auto`, `agent-browser` and manual runs, not chrome-mcp runs. |

Agent mode providers:
- **chrome-mcp** (default for new configs; an existing `config.json` keeps its provider): drives your real Chrome so you keep existing sessions/cookies. Needs Node.js 20.19+; headed runs also need Chrome 146+ open with auto-connect enabled at `chrome://inspect/#remote-debugging`, and someone at the machine to accept Chrome's connection prompt when the run starts. For headed runs, rae checks before launching that Chrome's remote debugging port is reachable (not the Chrome or Node version) and stops with setup steps if it isn't; `agent --dry-run` shows the same check. Headless runs skip it. `--headless` starts a separate headless Chrome without your sessions. No HAR file is saved, so `engineer <run_id>` cannot regenerate these runs; run `agent` again instead.
Expand Down Expand Up @@ -132,6 +132,7 @@ Settings live in `~/.reverse-api/config.json` and can be edited via `/settings`

`reverse-api-engineer` opens a full-screen session; `agent` and `engineer` open it too when run in a terminal, and stay plain with `--json` or `--no-interactive`. Type `/` for the commands:
- `/model`, `/effort`, `/mode`: switch the model, how hard it thinks, and the mode (also Shift+Tab, ctrl+e).
- `/engineer [run_id]`: the run engineer mode works on, by default the latest with a HAR.
- `/settings`: SDK, agent provider, models, output and sync, changed in place in the session.
- `/history`: past runs with their details, to resume or re-engineer.
- `/resume [run_id]`: show a past run's conversation as it was and continue it where it stopped, on any SDK. Works for agent and engineer runs from this version on, which save their SDK session.
Expand Down
45 changes: 34 additions & 11 deletions src/reverse_api/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,16 +714,18 @@ def open_session(
model: str | None = None,
prompt: str | None = None,
run: Callable[[], Any] | None = None,
runner: Callable[[str, str | None], Any] | None = None,
runner: Callable[..., Any] | None = None,
target: str | None = None,
) -> None:
"""The interactive CLI: the full-screen session, in ``mode``.

A subcommand hands over ``run``, its ``prompt`` with every option bound, and ``runner(prompt, model)``,
which starts later prompts in that mode with the options that still apply, such as --headless.
In engineer mode, ``target`` is the run it works on, and the runner also takes it.
"""
from .repl.app import run_session

run_session(mode=mode, model=model, first=(prompt, run) if prompt and run else None, runner=runner)
run_session(mode=mode, model=model, first=(prompt, run) if prompt and run else None, runner=runner, target=target)


@main.command(
Expand Down Expand Up @@ -1443,7 +1445,8 @@ def engineer(
lambda: run_engineer(
run_id, prompt=main_prompt, additional_instructions=additional, model=model, output_dir=output_dir, is_fresh=fresh
),
lambda p, m: engineer_from_prompt(p, m or model, output_dir),
lambda p, m, target=None: engineer_from_prompt(p, m or model, output_dir, target),
target=run_id,
)
return
if not machine_output:
Expand Down Expand Up @@ -1497,15 +1500,33 @@ def engineer(
sys.exit(0 if payload["status"] == "ok" else 1)


def engineer_from_prompt(text: str, model: str | None = None, output_dir: str | None = None) -> dict[str, Any] | None:
"""A prompt in engineer mode: a known run id re-engineers that run; anything else is an instruction for the latest run."""
NO_CAPTURE = "no run has a HAR to engineer yet · manual mode records one, as does agent mode with agent_provider auto"


def has_capture(run: dict[str, Any]) -> bool:
"""Whether engineer can work on a run: its HAR is still on disk."""
try:
har_dir = Path((run.get("paths") or {}).get("har_dir") or get_har_dir(str(run["run_id"]), None))
except (KeyError, TypeError, ValueError):
return False
return (har_dir / "recording.har").exists()


def latest_capture() -> dict[str, Any] | None:
return next((r for r in session_manager.get_history(limit=len(session_manager.history)) if has_capture(r)), None)


def engineer_from_prompt(
text: str, model: str | None = None, output_dir: str | None = None, run_id: str | None = None
) -> dict[str, Any] | None:
"""A prompt in engineer mode: a known run id re-engineers that run; anything else is an instruction for
``run_id``, else for the latest run with a HAR."""
if session_manager.get_run(text):
return run_engineer(text, model=model, output_dir=output_dir)
# Histories can still hold collector runs, which captured no traffic; run_engineer explains any other run that has none.
latest = next((r for r in session_manager.get_history(limit=50) if r.get("mode") != "collector"), None)
if latest is None:
raise RuntimeError("no captured runs yet · start one in agent or manual mode")
return run_engineer(latest["run_id"], model=model, output_dir=output_dir, additional_instructions=text)
target = run_id or (latest_capture() or {}).get("run_id")
if target is None:
raise RuntimeError(NO_CAPTURE)
return run_engineer(target, model=model, output_dir=output_dir, additional_instructions=text)


def run_engineer(
Expand Down Expand Up @@ -1556,6 +1577,8 @@ def run_engineer(
enable_sync = config_manager.get("real_time_sync", True)
output_language = config_manager.get("output_language", "python")
resume_session, cost_before = _resume_point(resume) if resume else (None, 0.0)
# The run keeps what it spent before, its capture included: a re-engineer adds to it.
spent_before = dict((resume or session_manager.get_run(run_id) or {}).get("usage") or {})
# OpenCode and Copilot take their model from settings, except when reopening a session made with another.
resume_model = (resume or {}).get("sdk_session", {}).get("model")
session_model = {
Expand Down Expand Up @@ -1734,7 +1757,7 @@ def run_engineer(
run_id=run_id,
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.

paths={"script_path": result.get("script_path")},
)
_keep_session_cost(run_id, cost_before, usage)
Expand Down
Loading
Loading