The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): record ad-hoc verify evidence run through a versioned or absolute interpreter
Uttkarsh Tiwari35accdbc30f2
diff --git a/agent/verification_evidence.py b/agent/verification_evidence.pyindex b376c290170..ee1c6ab3c99 100644--- a/agent/verification_evidence.py+++ b/agent/verification_evidence.py@@ -27,6 +27,13 @@ _AD_HOC_SCRIPT_NAME_PREFIXES = ("hermes-verify-", "hermes-ad-hoc-")_VERIFY_SCHEMA_VERSION = 1_INTERPRETERS = {"python", "python3", "node", "bash", "sh", "ruby", "perl"}+# The same interpreter is reached as `python3`, `python3.12`, `/usr/bin/python3.12`, or+# `env python3`. Matching only the bare token recorded no evidence for the invocation shapes+# the verify-on-stop nudge itself hands the agent, so a passing run left the workspace+# "unverified" and the nudge returned every turn.+_INTERPRETER_NAME_RE = re.compile(+ r"^(?:" + "|".join(sorted(_INTERPRETERS, key=len, reverse=True)) + r")(?:[0-9]+(?:\.[0-9]+)*)?$"+)_TARGET_EXTENSIONS = (".py", ".js", ".jsx", ".ts", ".tsx", ".rs", ".go", ".java")_TARGET_PREFIXES = ("test_", "tests", "spec", "__tests__")# Ordered: first matching keyword group wins; "check" only counts when the@@ -302,6 +309,16 @@ def _is_temp_script_path(token: str, root: str | Path | None) -> bool:return name.startswith(_AD_HOC_SCRIPT_NAME_PREFIXES) and _is_under(token, tempfile.gettempdir()) and not _is_under(token, root)+def _is_interpreter_token(token: str) -> bool:+ """Whether a command word names a shell interpreter.++ ``python3``, ``python3.12`` and ``/usr/bin/python3.12`` are the same interpreter; matching+ only the bare token left the ad-hoc branch blind to the invocation shapes the nudge hands+ the agent, so a passing run recorded no evidence and the workspace stayed ``unverified``.+ """+ return bool(_INTERPRETER_NAME_RE.match(Path(token).name))++def _ad_hoc_script_args(tokens: list[str], root: str | Path | None) -> Optional[list[str]]:candidate_tokens = _strip_command_prefix(tokens)if not candidate_tokens:@@ -309,7 +326,10 @@ def _ad_hoc_script_args(tokens: list[str], root: str | Path | None) -> Optional[command = candidate_tokens[0]if _is_temp_script_path(command, root):return candidate_tokens[1:]- if command in _INTERPRETERS:+ if Path(command).name == "env" and len(candidate_tokens) > 1 and _is_interpreter_token(candidate_tokens[1]):+ # `/usr/bin/env python3 script` names the same interpreter as `python3 script`.+ candidate_tokens, command = candidate_tokens[1:], candidate_tokens[1]+ if _is_interpreter_token(command):# Skip interpreter flags; the first positional must be the script.for idx, token in enumerate(candidate_tokens[1:], start=1):if _is_temp_script_path(token, root):diff --git a/tests/agent/test_verification_evidence.py b/tests/agent/test_verification_evidence.pyindex 566e63890f4..c62ad493bc2 100644--- a/tests/agent/test_verification_evidence.py+++ b/tests/agent/test_verification_evidence.py@@ -253,6 +253,55 @@ def test_temp_script_records_ad_hoc_evidence_without_canonical_suite(tmp_path, massert evidence.status == "passed"+ "invocation",+ [+ "python3.12 {script}",+ "/usr/bin/python3 {script}",+ "/usr/bin/python3.12 {script}",+ "python3 -u {script}",+ "/usr/bin/env python3 {script}",+ ],+)+def test_versioned_or_absolute_interpreter_records_ad_hoc_evidence(tmp_path, monkeypatch, invocation):+ """A versioned, absolute or `env`-prefixed interpreter names the same interpreter as a bare+ `python3`. Matching only the bare token left the ad-hoc branch blind to the invocation shapes+ the verify-on-stop nudge itself hands the agent, so a passing run recorded no evidence and+ every later turn re-nudged the same workspace as unverified.+ """+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))+ (tmp_path / "package.json").write_text("{}", encoding="utf-8")+ script = Path(tempfile.gettempdir()) / f"hermes-verify-{tmp_path.name}.py"+ script.write_text("print('ok')\n", encoding="utf-8")+ try:+ evidence = classify_verification_command(+ invocation.format(script=script),+ cwd=tmp_path,+ session_id="s1",+ exit_code=0,+ output="ok",+ )+ finally:+ script.unlink(missing_ok=True)++ assert evidence is not None+ assert evidence.kind == "ad_hoc"+ assert evidence.status == "passed"+++def test_non_interpreter_command_touching_the_temp_script_is_not_evidence(tmp_path, monkeypatch):+ """The nudge also tells the agent to clean the temp script up. A command that merely names+ the script — `rm`, `chmod`, `cat` — runs no verification and must not satisfy the gate.+ """+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))+ (tmp_path / "package.json").write_text("{}", encoding="utf-8")+ script = Path(tempfile.gettempdir()) / f"hermes-verify-{tmp_path.name}.py"++ for command in (f"rm -f {script}", f"/usr/bin/chmod +x {script}", f"/usr/bin/cat {script}"):+ evidence = classify_verification_command(command, cwd=tmp_path, session_id="s1", exit_code=0)+ assert evidence is None, f"{command!r} must not be recorded as verification evidence"++