Skip to content

The agent that turns websites into APIs!

fix(engineer): preserve original capture prompt when --prompt is non-fresh

Kalil Bouziguesec9de623d0fd
diff --git a/src/reverse_api/cli.py b/src/reverse_api/cli.py
index beb62f5..0d97a3f 100644
--- a/src/reverse_api/cli.py
+++ b/src/reverse_api/cli.py
@@ -1207,7 +1207,15 @@ def run_auto_capture(prompt=None, url=None, model=None, output_dir=None, agent_p
@main.command()
@click.argument("run_id")
[email protected]("--prompt", "-p", default=None, help="Override the engineering prompt for this run.")
+ "--prompt",
+ "-p",
+ default=None,
+ help=(
+ "With --fresh: replace the captured run's original goal. "
+ "Without --fresh: layered as additional instructions on top of the original prompt."
+ ),
+)
@click.option(
"--fresh",
is_flag=True,
@@ -1222,7 +1230,18 @@ def run_auto_capture(prompt=None, url=None, model=None, output_dir=None, agent_p
@click.option("--output-dir", "-o", default=None, help="Custom output directory.")
def engineer(run_id, prompt, fresh, model, output_dir):
"""Run reverse engineering on a previous run."""
- run_engineer(run_id, prompt=prompt, model=model, output_dir=output_dir, is_fresh=fresh)
+ # --fresh treats --prompt as a full replacement of the original goal;
+ # without --fresh, --prompt is additive so the captured run's context is preserved.
+ main_prompt = prompt if fresh else None
+ additional = prompt if (prompt and not fresh) else None
+ run_engineer(
+ run_id,
+ prompt=main_prompt,
+ additional_instructions=additional,
+ model=model,
+ output_dir=output_dir,
+ is_fresh=fresh,
+ )
def run_engineer(
diff --git a/tests/test_cli_engineer_command.py b/tests/test_cli_engineer_command.py
new file mode 100644
index 0000000..fb2acf1
--- /dev/null
+++ b/tests/test_cli_engineer_command.py
@@ -0,0 +1,65 @@
+"""Tests for the `engineer` click command wiring.
+
+Specifically: --prompt and --fresh must combine the way the old `@id <run_id>
+[--fresh] <prompt>` REPL syntax did. Without --fresh, --prompt is layered as
+*additional instructions* so the captured run's original goal is preserved;
+with --fresh, --prompt fully replaces the original goal.
+
+Regression for chatgpt-codex-connector PR #63 review (P2).
+"""
+
+from unittest.mock import patch
+
+from click.testing import CliRunner
+
+from reverse_api.cli import engineer
+
+
+class TestEngineerCommandPromptWiring:
+ """`engineer <run_id> [--prompt] [--fresh]` flag combinations."""
+
+ def test_no_prompt_no_fresh(self):
+ runner = CliRunner()
+ with patch("reverse_api.cli.run_engineer") as mock_run:
+ result = runner.invoke(engineer, ["abc123"])
+ assert result.exit_code == 0, result.output
+ kwargs = mock_run.call_args.kwargs
+ assert kwargs["prompt"] is None
+ assert kwargs["additional_instructions"] is None
+ assert kwargs["is_fresh"] is False
+
+ def test_prompt_without_fresh_is_additive(self):
+ """Without --fresh, --prompt becomes additional_instructions so the
+ run's original prompt is still loaded by run_engineer.
+ """
+ runner = CliRunner()
+ with patch("reverse_api.cli.run_engineer") as mock_run:
+ result = runner.invoke(engineer, ["abc123", "--prompt", "add pagination"])
+ assert result.exit_code == 0, result.output
+ kwargs = mock_run.call_args.kwargs
+ assert kwargs["prompt"] is None, "must NOT pass user text as the main prompt without --fresh"
+ assert kwargs["additional_instructions"] == "add pagination"
+ assert kwargs["is_fresh"] is False
+
+ def test_fresh_without_prompt(self):
+ runner = CliRunner()
+ with patch("reverse_api.cli.run_engineer") as mock_run:
+ result = runner.invoke(engineer, ["abc123", "--fresh"])
+ assert result.exit_code == 0, result.output
+ kwargs = mock_run.call_args.kwargs
+ assert kwargs["prompt"] is None
+ assert kwargs["additional_instructions"] is None
+ assert kwargs["is_fresh"] is True
+
+ def test_fresh_with_prompt_replaces_main(self):
+ """With --fresh, --prompt fully replaces the run's original goal."""
+ runner = CliRunner()
+ with patch("reverse_api.cli.run_engineer") as mock_run:
+ result = runner.invoke(
+ engineer, ["abc123", "--fresh", "--prompt", "reverse engineer the auth flow only"]
+ )
+ assert result.exit_code == 0, result.output
+ kwargs = mock_run.call_args.kwargs
+ assert kwargs["prompt"] == "reverse engineer the auth flow only"
+ assert kwargs["additional_instructions"] is None
+ assert kwargs["is_fresh"] is True