Skip to content

The agent that turns websites into APIs!

feat: filter CLI stderr noise, add DEBUG=1 mode for full output

kalil0321aca566418afb
diff --git a/src/reverse_api/auto_engineer.py b/src/reverse_api/auto_engineer.py
index 43e1089..aa9b05e 100644
--- a/src/reverse_api/auto_engineer.py
+++ b/src/reverse_api/auto_engineer.py
@@ -274,6 +274,7 @@ Your final response should confirm the files were created and provide a brief su
cwd=str(self.scripts_dir.parent.parent), # Project root
model=self.model,
env={"CLAUDECODE": "", "CLAUDE_CODE_STREAM_CLOSE_TIMEOUT": "1800000"},
+ stderr=self._handle_cli_stderr,
)
final_result: dict[str, Any] | None = None
diff --git a/src/reverse_api/base_engineer.py b/src/reverse_api/base_engineer.py
index 0528feb..62d4880 100644
--- a/src/reverse_api/base_engineer.py
+++ b/src/reverse_api/base_engineer.py
@@ -1,5 +1,6 @@
"""Abstract base class for API reverse engineering."""
+import os
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Any
@@ -12,6 +13,8 @@ from .sync import FileSyncWatcher, get_available_directory
from .tui import THEME_PRIMARY, THEME_SECONDARY, ClaudeUI
from .utils import generate_folder_name, get_docs_dir, get_history_path, get_scripts_dir
+DEBUG = os.environ.get("DEBUG", "0") == "1"
+
class BaseEngineer(ABC):
"""Abstract base class for API reverse engineering implementations."""
@@ -60,6 +63,24 @@ class BaseEngineer(ABC):
self.existing_client_path = self._get_existing_client_path()
self.sync_watcher: FileSyncWatcher | None = None
self.local_scripts_dir: Path | None = None
+ self._stderr_error_shown = False
+
+ def _handle_cli_stderr(self, line: str) -> None:
+ """Filter CLI subprocess stderr. Shows full output in DEBUG mode, otherwise shows a single clean error."""
+ if DEBUG:
+ self.ui.console.print(f"[dim] stderr: {line.rstrip()}[/dim]")
+ return
+
+ # Known noisy errors from the CLI control protocol — show once
+ if "Error in hook callback" in line or "Stream closed" in line:
+ if not self._stderr_error_shown:
+ self._stderr_error_shown = True
+ self.ui.console.print(" [dim]![/dim] [dim]cli stream error (set DEBUG=1 for details)[/dim]")
+ return
+
+ # Suppress other common noise (stack traces, source maps)
+ if line.startswith(" at ") or "| " in line[:20]:
+ return
def start_sync(self):
"""Start real-time file sync if enabled."""
@@ -532,16 +553,20 @@ Your OpenAPI spec should be production-ready and suitable for:
mode_description = f"reverse engineer API calls and generate production-ready {language_name} code that replicates"
task_description = f"{language_name} API client"
- attempt_log_section = "" if self.output_mode == "docs" else (
- "If your first attempt doesn't work, analyze what went wrong and try again. "
- "Document each attempt and what you learned.\n\n"
- "<attempt_log>\n"
- "For each attempt (up to 5), document:\n"
- "- Attempt number\n"
- "- What approach you tried\n"
- "- What error or issue occurred (if any)\n"
- "- What you changed for the next attempt\n"
- "</attempt_log>\n\n"
+ attempt_log_section = (
+ ""
+ if self.output_mode == "docs"
+ else (
+ "If your first attempt doesn't work, analyze what went wrong and try again. "
+ "Document each attempt and what you learned.\n\n"
+ "<attempt_log>\n"
+ "For each attempt (up to 5), document:\n"
+ "- Attempt number\n"
+ "- What approach you tried\n"
+ "- What error or issue occurred (if any)\n"
+ "- What you changed for the next attempt\n"
+ "</attempt_log>\n\n"
+ )
)
after_verb = "documenting" if self.output_mode == "docs" else "testing"
output_type = "spec" if self.output_mode == "docs" else "code"
diff --git a/src/reverse_api/engineer.py b/src/reverse_api/engineer.py
index 309b54e..6a239d1 100644
--- a/src/reverse_api/engineer.py
+++ b/src/reverse_api/engineer.py
@@ -63,6 +63,7 @@ class ClaudeEngineer(BaseEngineer):
cwd=str(self.scripts_dir.parent.parent), # Project root
model=self.model,
env={"CLAUDECODE": "", "CLAUDE_CODE_STREAM_CLOSE_TIMEOUT": "1800000"},
+ stderr=self._handle_cli_stderr,
)
final_result: dict[str, Any] | None = None