Skip to content

A skill to stop your coding agent from burying the answer. ADHD-friendly output.

fix: grade the prompt that ships, in a context that isn't this repo

Lonnie Zane0a82e608c632
diff --git a/scripts/run_evals.py b/scripts/run_evals.py
index 1fae566..9a35462 100644
--- a/scripts/run_evals.py
+++ b/scripts/run_evals.py
@@ -8,6 +8,7 @@ import json
import shlex
import subprocess
import sys
+import tempfile
import time
from collections import Counter, defaultdict
from pathlib import Path
@@ -26,6 +27,27 @@ WEIGHTS = {
CONDITIONS = {"baseline", "candidate", "comparator"}
+_NEUTRAL_CWD: str | None = None
+
+
+def _neutral_cwd() -> str:
+ """An empty scratch directory to run a runner in.
+
+ Agent CLIs adopt their working directory as project context: run one inside
+ this checkout and it answers prompts by inspecting the harness instead of
+ the task. That contamination is not symmetric across conditions -- a
+ response style that discourages exploration wanders less -- so it shows up
+ as a score difference that has nothing to do with the skill under test.
+ Isolation is the same reason the runners pass `--setting-sources ""`; the
+ working directory is simply another channel the operator's world leaks in
+ through.
+ """
+ global _NEUTRAL_CWD
+ if _NEUTRAL_CWD is None:
+ _NEUTRAL_CWD = tempfile.mkdtemp(prefix="eval-neutral-cwd-")
+ return _NEUTRAL_CWD
+
+
def read_jsonl(path: Path) -> list[dict[str, Any]]:
rows: list[dict[str, Any]] = []
for number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), start=1):
@@ -168,12 +190,28 @@ def summarize_scores(scores: list[dict[str, Any]]) -> dict[str, Any]:
}
+def _strip_frontmatter(text: str) -> str:
+ """Drop a leading YAML frontmatter block, mirroring hooks/always-on.sh.
+
+ The hook injects the ruleset without frontmatter, so the eval has to grade
+ the same text. A file that opens a block but never closes it is left alone
+ rather than emptied.
+ """
+ lines = text.splitlines()
+ if not lines or lines[0].strip() != "---":
+ return text
+ for index in range(1, len(lines)):
+ if lines[index].strip() == "---":
+ return "\n".join(lines[index + 1 :]).lstrip("\n")
+ return text
+
+
def _condition_prompt(task: str, condition: str, skill_path: Path | None) -> str:
if condition == "baseline":
return task
if skill_path is None:
raise ValueError(f"--condition-skill is required for the {condition} condition")
- instructions = skill_path.read_text(encoding="utf-8")
+ instructions = _strip_frontmatter(skill_path.read_text(encoding="utf-8"))
return (
"Follow the response-style skill below while completing the task. "
"Do not discuss or quote the skill.\n\n"
@@ -261,7 +299,7 @@ def run_evaluations(args: argparse.Namespace) -> int:
check=False,
capture_output=True,
text=True,
- cwd=ROOT,
+ cwd=_neutral_cwd(),
)
if completed.returncode == 0:
break
diff --git a/tests/test_run_evals.py b/tests/test_run_evals.py
index e8a4380..d76973a 100644
--- a/tests/test_run_evals.py
+++ b/tests/test_run_evals.py
@@ -121,6 +121,41 @@ class EvaluationHarnessTest(unittest.TestCase):
with self.assertRaisesRegex(ValueError, "line 2"):
run_evals.read_jsonl(path)
+ def test_condition_prompt_injects_the_skill_body_without_frontmatter(self):
+ # hooks/always-on.sh strips the YAML frontmatter before injecting the
+ # ruleset, so the eval must grade the same text that actually ships.
+ with tempfile.TemporaryDirectory() as tmp:
+ skill = Path(tmp) / "SKILL.md"
+ skill.write_text(
+ "---\n"
+ "name: i-have-adhd\n"
+ "disable-model-invocation: true\n"
+ "metadata:\n"
+ " hermes:\n"
+ " tags: [ADHD]\n"
+ "---\n"
+ "\n"
+ "# i-have-adhd\n"
+ "\n"
+ "Lead with the next action.\n"
+ )
+
+ prompt = run_evals._condition_prompt("Fix the bug.", "candidate", skill)
+
+ self.assertIn("Lead with the next action.", prompt)
+ self.assertIn("Fix the bug.", prompt)
+ self.assertNotIn("disable-model-invocation", prompt)
+ self.assertNotIn("hermes", prompt)
+
+ def test_condition_prompt_keeps_a_skill_body_that_has_no_frontmatter(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ skill = Path(tmp) / "SKILL.md"
+ skill.write_text("# No frontmatter here\n\nLead with the next action.\n")
+
+ prompt = run_evals._condition_prompt("Fix the bug.", "candidate", skill)
+
+ self.assertIn("# No frontmatter here", prompt)
+
def test_unmetered_runner_is_rejected_before_any_call(self):
with tempfile.TemporaryDirectory() as tmp:
tmp_path = Path(tmp)
@@ -160,6 +195,37 @@ class EvaluationHarnessTest(unittest.TestCase):
self.assertEqual(0, run_evals.run_evaluations(args))
self.assertTrue(marker.exists())
+ def test_generation_runs_outside_the_repository(self):
+ # An agent CLI adopts its working directory as project context. Run it
+ # in this checkout and it answers prompts by inspecting the harness,
+ # which contaminates the responses being compared.
+ with tempfile.TemporaryDirectory() as tmp:
+ tmp_path = Path(tmp)
+ runner_config = tmp_path / "runners.json"
+ runner_config.write_text(
+ json.dumps({"pwd": {"command": ["sh", "-c", "pwd"], "response_format": "text"}})
+ )
+ output = tmp_path / "out.jsonl"
+ args = argparse.Namespace(
+ cases=ROOT / "evals" / "cases.jsonl",
+ runner_config=runner_config,
+ runner="pwd",
+ condition="baseline",
+ condition_skill=None,
+ case=["direct-answer"],
+ trials=1,
+ retries=0,
+ budget_usd=1.0,
+ allow_unmetered=True,
+ output=output,
+ )
+
+ self.assertEqual(0, run_evals.run_evaluations(args))
+
+ where = Path(run_evals.read_jsonl(output)[0]["response"].strip()).resolve()
+ self.assertNotEqual(ROOT.resolve(), where)
+ self.assertFalse(str(where).startswith(str(ROOT.resolve())))
+
def test_completed_keys_support_resuming_partial_runs(self):
rows = [
{