feat. Review foot note, docker fix, pass message to reviewer , update tests
This commit is contained in:
@@ -48,6 +48,7 @@ def run_review_ephemeral(
|
||||
if completed.returncode != 0:
|
||||
raise RuntimeError(_format_runner_failure(completed))
|
||||
parsed = _parse_codex_exec_stdout(completed.stdout)
|
||||
parsed["_meta"] = _extract_result_meta_from_codex_stdout(completed.stdout, settings)
|
||||
return normalize_review_result(parsed)
|
||||
except Exception as exc:
|
||||
if settings.codex_auth_mode == "chatgpt":
|
||||
@@ -202,6 +203,67 @@ def _parse_codex_exec_stdout(stdout: str) -> dict[str, Any]:
|
||||
raise RuntimeError(f"codex exec output text did not contain review JSON; text_tail={_tail_text(last_text, 400)}")
|
||||
|
||||
|
||||
def _extract_result_meta_from_codex_stdout(stdout: str, settings: Settings) -> dict[str, Any]:
|
||||
model = settings.openai_review_model
|
||||
usage: dict[str, int] = {}
|
||||
for line in stdout.splitlines():
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
try:
|
||||
payload = json.loads(line)
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
discovered_model = _find_first_string_for_key(payload, "model")
|
||||
if discovered_model:
|
||||
model = discovered_model
|
||||
discovered_usage = _find_first_dict_for_key(payload, "usage")
|
||||
if isinstance(discovered_usage, dict):
|
||||
for output_key, source_key in (
|
||||
("input_tokens", "input_tokens"),
|
||||
("output_tokens", "output_tokens"),
|
||||
("total_tokens", "total_tokens"),
|
||||
):
|
||||
value = discovered_usage.get(source_key)
|
||||
if isinstance(value, int):
|
||||
usage[output_key] = value
|
||||
return {"source": "ephemeral_runner", "model": model, "usage": usage}
|
||||
|
||||
|
||||
def _find_first_string_for_key(payload: Any, key: str) -> str | None:
|
||||
if isinstance(payload, dict):
|
||||
value = payload.get(key)
|
||||
if isinstance(value, str) and value.strip():
|
||||
return value
|
||||
for nested in payload.values():
|
||||
found = _find_first_string_for_key(nested, key)
|
||||
if found:
|
||||
return found
|
||||
if isinstance(payload, list):
|
||||
for item in payload:
|
||||
found = _find_first_string_for_key(item, key)
|
||||
if found:
|
||||
return found
|
||||
return None
|
||||
|
||||
|
||||
def _find_first_dict_for_key(payload: Any, key: str) -> dict[str, Any] | None:
|
||||
if isinstance(payload, dict):
|
||||
value = payload.get(key)
|
||||
if isinstance(value, dict):
|
||||
return value
|
||||
for nested in payload.values():
|
||||
found = _find_first_dict_for_key(nested, key)
|
||||
if found:
|
||||
return found
|
||||
if isinstance(payload, list):
|
||||
for item in payload:
|
||||
found = _find_first_dict_for_key(item, key)
|
||||
if found:
|
||||
return found
|
||||
return None
|
||||
|
||||
|
||||
def _parse_review_json_from_text(text: str) -> dict[str, Any] | None:
|
||||
candidates: list[str] = [text.strip()]
|
||||
fenced = re.search(r"```(?:json)?\s*(\{.*\})\s*```", text, flags=re.DOTALL | re.IGNORECASE)
|
||||
|
||||
Reference in New Issue
Block a user