diff --git a/.agents/skills/judge-panel/SKILL.md b/.agents/skills/judge-panel/SKILL.md index 735584e..e8e2855 100644 --- a/.agents/skills/judge-panel/SKILL.md +++ b/.agents/skills/judge-panel/SKILL.md @@ -46,6 +46,8 @@ PROMPT = """... {items} ...""" # demand EXACT one-line-per-answer output, no def items(manifest): return [{"key": "g12", "files": [...], "text": "(3 frames: A, B, C)"}] def parse(text): return {key: value} # tolerant regexes, see pitfalls # optional: jev_batches(manifest, votes), jev_collect(batch, answers), analyze(manifest, votes, jev, out_dir) +# optional: WORKDIR = "" claude/codex/agy run there (e.g. a scrubbed blind folder) +# optional: def batches(items, n): ... your own grouping (e.g. one call per pose) instead of chunks of n ``` ## 3. Run diff --git a/.agents/skills/judge-panel/scripts/panel.py b/.agents/skills/judge-panel/scripts/panel.py index 9c1ebb8..4b79db9 100644 --- a/.agents/skills/judge-panel/scripts/panel.py +++ b/.agents/skills/judge-panel/scripts/panel.py @@ -8,6 +8,8 @@ def items(manifest) -> list [{"key": str, "files": [path, ...], "text": str}] def parse(text) -> dict judge raw output -> {key: value}; missing keys = not answered # optional AGENT_HINT: dict extra line per agent (default: "view every image before answering") + WORKDIR: str working directory for the claude, codex and agy calls (default: inherited) + def batches(items, n) -> list group items into calls (default: consecutive chunks of n) def jev_batches(manifest, votes) -> list [{"keys": [...], "state": {...}, "questions": {...}}] def jev_collect(batch, answers) -> dict one Jev response -> {key: value} def analyze(manifest, votes, jev, out_dir) -> None @@ -28,6 +30,7 @@ def analyze(manifest, votes, jev, out_dir) -> None import importlib.util import json import os +import re import subprocess import sys from concurrent.futures import ThreadPoolExecutor @@ -64,8 +67,13 @@ def panel_dir(spec, manifest: Path) -> Path: def _cursor_cmd() -> list[str]: # agent.cmd goes through cmd.exe, which mangles | < > in the prompt; call node directly. - vers = Path(os.environ["LOCALAPPDATA"]) / "cursor-agent" / "versions" - d = max(vers.iterdir()) + local = os.environ.get("LOCALAPPDATA") + vers = Path(local) / "cursor-agent" / "versions" if local else None + runnable = [d for d in (vers.iterdir() if vers and vers.is_dir() else []) + if (d / "node.exe").is_file() and (d / "index.js").is_file()] + if not runnable: + raise SystemExit("cursor judge needs a cursor-agent install under %LOCALAPPDATA%; drop it with --agents") + d = max(runnable, key=lambda p: [int(n) for n in re.findall(r"\d+", p.name)]) # numeric, not string order return [str(d / "node.exe"), str(d / "index.js")] @@ -90,24 +98,25 @@ def render_items(batch, attached: bool) -> str: def call(spec, agent: str, batch) -> str: hint = getattr(spec, "AGENT_HINT", {}).get(agent, DEFAULT_HINT) + workdir = getattr(spec, "WORKDIR", None) dirs = sorted({str(Path(f).parent) for it in batch for f in it["files"]}) if agent == "codex": cmd = ["codex.cmd" if os.name == "nt" else "codex", "exec", "--skip-git-repo-check", "--sandbox", "read-only"] for it in batch: for f in it["files"]: cmd += ["-i", f] - return run_cmd(cmd + ["-"], spec.PROMPT.format(items=render_items(batch, True))) + return run_cmd(cmd + ["-"], spec.PROMPT.format(items=render_items(batch, True)), cwd=workdir) prompt = spec.PROMPT.format(items=render_items(batch, False)) + "\n" + hint if agent == "claude": cmd = ["claude", "-p", "--allowedTools", "Read"] for d in dirs: cmd += ["--add-dir", d] - return run_cmd(cmd, prompt + "\nUse the Read tool to view each image file.") + return run_cmd(cmd, prompt + "\nUse the Read tool to view each image file.", cwd=workdir) if agent == "agy": cmd = ["agy"] for d in dirs: cmd += ["--add-dir", d] - return run_cmd(cmd + ["-p", prompt]) + return run_cmd(cmd + ["-p", prompt], cwd=workdir) if agent == "cursor": return run_cmd([*_cursor_cmd(), "-p", "--trust", "--mode", "ask", "--output-format", "text", prompt], cwd=dirs[0]) @@ -151,7 +160,7 @@ def cmd_run(spec, manifest, a): got = spec.parse(txt) print(f"===== {ag}: parsed {len(got)}/{min(a.batch, len(items))}\n{txt[-1500:]}\n-> {json.dumps(got)[:800]}") return - bs = batches(items, a.batch) + bs = getattr(spec, "batches", batches)(items, a.batch) (pdir / "batches.json").write_text(json.dumps({"batch": a.batch, "keys": [[i["key"] for i in b] for b in bs]}), encoding="utf-8") with ThreadPoolExecutor(len(agents)) as pool: diff --git a/.claude/skills/judge-panel/SKILL.md b/.claude/skills/judge-panel/SKILL.md index 735584e..e8e2855 100644 --- a/.claude/skills/judge-panel/SKILL.md +++ b/.claude/skills/judge-panel/SKILL.md @@ -46,6 +46,8 @@ PROMPT = """... {items} ...""" # demand EXACT one-line-per-answer output, no def items(manifest): return [{"key": "g12", "files": [...], "text": "(3 frames: A, B, C)"}] def parse(text): return {key: value} # tolerant regexes, see pitfalls # optional: jev_batches(manifest, votes), jev_collect(batch, answers), analyze(manifest, votes, jev, out_dir) +# optional: WORKDIR = "" claude/codex/agy run there (e.g. a scrubbed blind folder) +# optional: def batches(items, n): ... your own grouping (e.g. one call per pose) instead of chunks of n ``` ## 3. Run diff --git a/.claude/skills/judge-panel/scripts/panel.py b/.claude/skills/judge-panel/scripts/panel.py index 9c1ebb8..4b79db9 100644 --- a/.claude/skills/judge-panel/scripts/panel.py +++ b/.claude/skills/judge-panel/scripts/panel.py @@ -8,6 +8,8 @@ def items(manifest) -> list [{"key": str, "files": [path, ...], "text": str}] def parse(text) -> dict judge raw output -> {key: value}; missing keys = not answered # optional AGENT_HINT: dict extra line per agent (default: "view every image before answering") + WORKDIR: str working directory for the claude, codex and agy calls (default: inherited) + def batches(items, n) -> list group items into calls (default: consecutive chunks of n) def jev_batches(manifest, votes) -> list [{"keys": [...], "state": {...}, "questions": {...}}] def jev_collect(batch, answers) -> dict one Jev response -> {key: value} def analyze(manifest, votes, jev, out_dir) -> None @@ -28,6 +30,7 @@ def analyze(manifest, votes, jev, out_dir) -> None import importlib.util import json import os +import re import subprocess import sys from concurrent.futures import ThreadPoolExecutor @@ -64,8 +67,13 @@ def panel_dir(spec, manifest: Path) -> Path: def _cursor_cmd() -> list[str]: # agent.cmd goes through cmd.exe, which mangles | < > in the prompt; call node directly. - vers = Path(os.environ["LOCALAPPDATA"]) / "cursor-agent" / "versions" - d = max(vers.iterdir()) + local = os.environ.get("LOCALAPPDATA") + vers = Path(local) / "cursor-agent" / "versions" if local else None + runnable = [d for d in (vers.iterdir() if vers and vers.is_dir() else []) + if (d / "node.exe").is_file() and (d / "index.js").is_file()] + if not runnable: + raise SystemExit("cursor judge needs a cursor-agent install under %LOCALAPPDATA%; drop it with --agents") + d = max(runnable, key=lambda p: [int(n) for n in re.findall(r"\d+", p.name)]) # numeric, not string order return [str(d / "node.exe"), str(d / "index.js")] @@ -90,24 +98,25 @@ def render_items(batch, attached: bool) -> str: def call(spec, agent: str, batch) -> str: hint = getattr(spec, "AGENT_HINT", {}).get(agent, DEFAULT_HINT) + workdir = getattr(spec, "WORKDIR", None) dirs = sorted({str(Path(f).parent) for it in batch for f in it["files"]}) if agent == "codex": cmd = ["codex.cmd" if os.name == "nt" else "codex", "exec", "--skip-git-repo-check", "--sandbox", "read-only"] for it in batch: for f in it["files"]: cmd += ["-i", f] - return run_cmd(cmd + ["-"], spec.PROMPT.format(items=render_items(batch, True))) + return run_cmd(cmd + ["-"], spec.PROMPT.format(items=render_items(batch, True)), cwd=workdir) prompt = spec.PROMPT.format(items=render_items(batch, False)) + "\n" + hint if agent == "claude": cmd = ["claude", "-p", "--allowedTools", "Read"] for d in dirs: cmd += ["--add-dir", d] - return run_cmd(cmd, prompt + "\nUse the Read tool to view each image file.") + return run_cmd(cmd, prompt + "\nUse the Read tool to view each image file.", cwd=workdir) if agent == "agy": cmd = ["agy"] for d in dirs: cmd += ["--add-dir", d] - return run_cmd(cmd + ["-p", prompt]) + return run_cmd(cmd + ["-p", prompt], cwd=workdir) if agent == "cursor": return run_cmd([*_cursor_cmd(), "-p", "--trust", "--mode", "ask", "--output-format", "text", prompt], cwd=dirs[0]) @@ -151,7 +160,7 @@ def cmd_run(spec, manifest, a): got = spec.parse(txt) print(f"===== {ag}: parsed {len(got)}/{min(a.batch, len(items))}\n{txt[-1500:]}\n-> {json.dumps(got)[:800]}") return - bs = batches(items, a.batch) + bs = getattr(spec, "batches", batches)(items, a.batch) (pdir / "batches.json").write_text(json.dumps({"batch": a.batch, "keys": [[i["key"] for i in b] for b in bs]}), encoding="utf-8") with ThreadPoolExecutor(len(agents)) as pool: diff --git a/.cursor/skills/judge-panel/SKILL.md b/.cursor/skills/judge-panel/SKILL.md index 735584e..e8e2855 100644 --- a/.cursor/skills/judge-panel/SKILL.md +++ b/.cursor/skills/judge-panel/SKILL.md @@ -46,6 +46,8 @@ PROMPT = """... {items} ...""" # demand EXACT one-line-per-answer output, no def items(manifest): return [{"key": "g12", "files": [...], "text": "(3 frames: A, B, C)"}] def parse(text): return {key: value} # tolerant regexes, see pitfalls # optional: jev_batches(manifest, votes), jev_collect(batch, answers), analyze(manifest, votes, jev, out_dir) +# optional: WORKDIR = "" claude/codex/agy run there (e.g. a scrubbed blind folder) +# optional: def batches(items, n): ... your own grouping (e.g. one call per pose) instead of chunks of n ``` ## 3. Run diff --git a/.cursor/skills/judge-panel/scripts/panel.py b/.cursor/skills/judge-panel/scripts/panel.py index 9c1ebb8..4b79db9 100644 --- a/.cursor/skills/judge-panel/scripts/panel.py +++ b/.cursor/skills/judge-panel/scripts/panel.py @@ -8,6 +8,8 @@ def items(manifest) -> list [{"key": str, "files": [path, ...], "text": str}] def parse(text) -> dict judge raw output -> {key: value}; missing keys = not answered # optional AGENT_HINT: dict extra line per agent (default: "view every image before answering") + WORKDIR: str working directory for the claude, codex and agy calls (default: inherited) + def batches(items, n) -> list group items into calls (default: consecutive chunks of n) def jev_batches(manifest, votes) -> list [{"keys": [...], "state": {...}, "questions": {...}}] def jev_collect(batch, answers) -> dict one Jev response -> {key: value} def analyze(manifest, votes, jev, out_dir) -> None @@ -28,6 +30,7 @@ def analyze(manifest, votes, jev, out_dir) -> None import importlib.util import json import os +import re import subprocess import sys from concurrent.futures import ThreadPoolExecutor @@ -64,8 +67,13 @@ def panel_dir(spec, manifest: Path) -> Path: def _cursor_cmd() -> list[str]: # agent.cmd goes through cmd.exe, which mangles | < > in the prompt; call node directly. - vers = Path(os.environ["LOCALAPPDATA"]) / "cursor-agent" / "versions" - d = max(vers.iterdir()) + local = os.environ.get("LOCALAPPDATA") + vers = Path(local) / "cursor-agent" / "versions" if local else None + runnable = [d for d in (vers.iterdir() if vers and vers.is_dir() else []) + if (d / "node.exe").is_file() and (d / "index.js").is_file()] + if not runnable: + raise SystemExit("cursor judge needs a cursor-agent install under %LOCALAPPDATA%; drop it with --agents") + d = max(runnable, key=lambda p: [int(n) for n in re.findall(r"\d+", p.name)]) # numeric, not string order return [str(d / "node.exe"), str(d / "index.js")] @@ -90,24 +98,25 @@ def render_items(batch, attached: bool) -> str: def call(spec, agent: str, batch) -> str: hint = getattr(spec, "AGENT_HINT", {}).get(agent, DEFAULT_HINT) + workdir = getattr(spec, "WORKDIR", None) dirs = sorted({str(Path(f).parent) for it in batch for f in it["files"]}) if agent == "codex": cmd = ["codex.cmd" if os.name == "nt" else "codex", "exec", "--skip-git-repo-check", "--sandbox", "read-only"] for it in batch: for f in it["files"]: cmd += ["-i", f] - return run_cmd(cmd + ["-"], spec.PROMPT.format(items=render_items(batch, True))) + return run_cmd(cmd + ["-"], spec.PROMPT.format(items=render_items(batch, True)), cwd=workdir) prompt = spec.PROMPT.format(items=render_items(batch, False)) + "\n" + hint if agent == "claude": cmd = ["claude", "-p", "--allowedTools", "Read"] for d in dirs: cmd += ["--add-dir", d] - return run_cmd(cmd, prompt + "\nUse the Read tool to view each image file.") + return run_cmd(cmd, prompt + "\nUse the Read tool to view each image file.", cwd=workdir) if agent == "agy": cmd = ["agy"] for d in dirs: cmd += ["--add-dir", d] - return run_cmd(cmd + ["-p", prompt]) + return run_cmd(cmd + ["-p", prompt], cwd=workdir) if agent == "cursor": return run_cmd([*_cursor_cmd(), "-p", "--trust", "--mode", "ask", "--output-format", "text", prompt], cwd=dirs[0]) @@ -151,7 +160,7 @@ def cmd_run(spec, manifest, a): got = spec.parse(txt) print(f"===== {ag}: parsed {len(got)}/{min(a.batch, len(items))}\n{txt[-1500:]}\n-> {json.dumps(got)[:800]}") return - bs = batches(items, a.batch) + bs = getattr(spec, "batches", batches)(items, a.batch) (pdir / "batches.json").write_text(json.dumps({"batch": a.batch, "keys": [[i["key"] for i in b] for b in bs]}), encoding="utf-8") with ThreadPoolExecutor(len(agents)) as pool: diff --git a/tests/test_judge_panel.py b/tests/test_judge_panel.py new file mode 100644 index 0000000..0474704 --- /dev/null +++ b/tests/test_judge_panel.py @@ -0,0 +1,84 @@ +"""judge-panel harness: optional spec hooks (WORKDIR, batches) and the cursor-agent lookup.""" +from __future__ import annotations + +import importlib.util +import sys +import types +from argparse import Namespace +from pathlib import Path + +import pytest + +PANEL = Path(__file__).resolve().parents[1] / ".claude" / "skills" / "judge-panel" / "scripts" / "panel.py" + + +@pytest.fixture +def panel(): + spec = importlib.util.spec_from_file_location("judge_panel_under_test", PANEL) + mod = importlib.util.module_from_spec(spec) + sys.modules["judge_panel_under_test"] = mod + spec.loader.exec_module(mod) + return mod + + +def _spec(**extra): + mod = types.SimpleNamespace(NAME="t", PROMPT="{items}", parse=lambda text: {}, **extra) + return mod + + +def _record(panel, monkeypatch): + calls = [] + monkeypatch.setattr(panel, "run_cmd", lambda cmd, prompt=None, timeout=1800, cwd=None: calls.append(cwd) or "") + return calls + + +BATCH = [{"key": "a", "files": ["/imgs/x/a.jpg"], "text": ""}] + + +@pytest.mark.parametrize("agent", ["claude", "codex", "agy"]) +def test_workdir_is_used_for_the_cli_judges(panel, monkeypatch, agent): + calls = _record(panel, monkeypatch) + panel.call(_spec(WORKDIR="/blind/judge-input"), agent, BATCH) + assert calls == ["/blind/judge-input"] + + +def test_without_workdir_the_cwd_is_inherited(panel, monkeypatch): + calls = _record(panel, monkeypatch) + panel.call(_spec(), "claude", BATCH) + assert calls == [None] + + +def test_a_spec_can_group_the_batches(panel, monkeypatch, tmp_path): + items = [{"key": k, "files": [], "text": pose} for k, pose in [("a", "left"), ("b", "right"), ("c", "left")]] + + def by_pose(items, n): + groups = {} + for it in items: + groups.setdefault(it["text"], []).append(it) + return [groups[k] for k in sorted(groups)] + + seen = {} + monkeypatch.setattr(panel, "worker", lambda spec, pdir, ag, bs, keep: seen.setdefault(ag, bs) and (ag, len(bs))) + spec = _spec(items=lambda manifest: items, batches=by_pose) + manifest = tmp_path / "manifest.json" + manifest.write_text("{}", encoding="utf-8") + panel.cmd_run(spec, {}, Namespace(manifest=manifest, agents="claude", test=False, batch=8, keep=0.8)) + assert [[i["key"] for i in b] for b in seen["claude"]] == [["a", "c"], ["b"]] + + +def test_cursor_picks_the_newest_runnable_version_numerically(panel, monkeypatch, tmp_path): + vers = tmp_path / "cursor-agent" / "versions" + for name, runnable in [("2025.9.10-abc", True), ("2025.10.2-def", True), ("2025.11.1-broken", False)]: + d = vers / name + d.mkdir(parents=True) + if runnable: + (d / "node.exe").write_text("") + (d / "index.js").write_text("") + monkeypatch.setenv("LOCALAPPDATA", str(tmp_path)) + assert panel._cursor_cmd()[0].endswith(str(Path("2025.10.2-def") / "node.exe")) + + +def test_cursor_without_an_install_explains_itself(panel, monkeypatch): + monkeypatch.delenv("LOCALAPPDATA", raising=False) + with pytest.raises(SystemExit, match="cursor-agent install"): + panel._cursor_cmd()