Official Codebase of 3DCodeVerse
Python
skills: the read probe was measuring git, not the agent — so it now carries a control that says when it is blind
gaoypengf44f8af0dd93
diff --git a/harness/codeverse/cli/skills_cmd.py b/harness/codeverse/cli/skills_cmd.pyindex 75f04e5e..cf23925d 100644--- a/harness/codeverse/cli/skills_cmd.py+++ b/harness/codeverse/cli/skills_cmd.py@@ -109,6 +109,10 @@ def report(Targets from the design: >= 60% for CLI backends, >= 80% for api-agent. A skillunder 20% over 20 sessions is merged or deleted.++ Sessions whose CONTROL bundle was also "read" are counted separately and excluded from+ the rate: git's own diff and every CLI's skill activation both bump atime, so in those+ sessions the probe saw nothing it can attribute to the agent (docs/SKILLS.md section 4)."""from rich.table import Table@@ -124,7 +128,11 @@ def report(raise typer.Exit(code=1)per: dict[tuple[str, str], list[int]] = {}+ blind = sum(1 for r in rows if r.get("control_read"))+ no_control = sum(1 for r in rows if not r.get("control_present"))for r in rows:+ if r.get("control_read"):+ continue # the probe was blind here; counting it would liebackend = str(r.get("agent", "?")).split(":", 1)[0]reads = {x["name"]: x for x in r.get("reads", [])}for name in r.get("listed", []):@@ -134,12 +142,16 @@ def report(cell[1] += 1 if got.get("surfaced") else 0cell[2] += 1 if got.get("deep") else 0if as_json:- console.print_json(json.dumps([- {"skill": k[0], "backend": k[1], "listed": v[0], "surfaced": v[1], "deep": v[2],- "deep_read_rate": round(v[2] / v[0], 3) if v[0] else None}- for k, v in sorted(per.items())]))+ console.print_json(json.dumps({+ "sessions": len(rows), "control_read_sessions": blind, "no_control_sessions": no_control,+ "skills": [+ {"skill": k[0], "backend": k[1], "listed": v[0], "surfaced": v[1], "deep": v[2],+ "deep_read_rate": round(v[2] / v[0], 3) if v[0] else None}+ for k, v in sorted(per.items())]}))return- t = Table(title=f"skill read rate ({len(rows)} sessions)")+ scored = len(rows) - blind+ t = Table(title=f"skill read rate ({scored} of {len(rows)} sessions; "+ f"{blind} blind — the control was read too)")for col in ("skill", "backend", "listed", "surfaced", "deep", "deep rate", "verdict"):t.add_column(col)for (name, backend), (listed, surfaced, deep) in sorted(per.items()):@@ -148,6 +160,15 @@ def report(verdict = "delete/merge" if (listed >= 20 and rate < 0.20) else ("ok" if rate >= target else "below target")t.add_row(name, backend, str(listed), str(surfaced), str(deep), f"{rate:.0%}", verdict)console.print(t)+ if blind:+ err_console.print(+ f"[yellow]{blind} of {len(rows)} sessions excluded[/]: the never-routed control bundle "+ f"was opened too, so nothing in them can be attributed to the agent.")+ if no_control:+ err_console.print(+ f"[yellow]{no_control} session(s) predate the control bundle[/]: their rates are an upper bound.")+ if not per:+ err_console.print("[red]every session was blind[/] — the read rate is unmeasured, not 0 and not 100%.")__all__ = ["skills_app"]diff --git a/harness/codeverse/contracts/skills.py b/harness/codeverse/contracts/skills.pyindex 4abf986a..5bc36b95 100644--- a/harness/codeverse/contracts/skills.py+++ b/harness/codeverse/contracts/skills.py@@ -33,6 +33,22 @@ class SkillsUsage(BaseModel):index_tokens: int = 0body_tokens_read: int = Field(default=0, description="tokens of the bodies the probe says were read deep")inlined: str = Field(default="", description="single-shot: the body inlined into the prompt, '' otherwise")+ control_read: bool = Field(+ default=False,+ description="the never-routed control bundle was 'read' too, so this session's atime "+ "evidence proves nothing and every rate below is an upper bound")+ control_present: bool = Field(default=False, description="a control bundle was materialised at all")++ @property+ def probe_trustworthy(self) -> bool:+ """False when the control fired — the only honest reading of the numbers below.++ A run computes ``files_changed`` through ``git add -A -N`` + ``git diff``, and git+ reads every untracked file to do it, which bumps atime on the whole bundle tree.+ CLI activation opens ``references/`` too. Either way the probe says "read" when+ nobody chose to read, and only the control can tell you which session you are in.+ """+ return self.control_present and not self.control_read@propertydef surfaced(self) -> list[str]:@@ -44,7 +60,10 @@ class SkillsUsage(BaseModel):@propertydef deep_read_rate(self) -> float | None:- return (len(self.deep) / len(self.listed)) if self.listed else None+ """None when there is nothing listed, or when the control says the probe is blind."""+ if not self.listed or (self.control_present and self.control_read):+ return None+ return len(self.deep) / len(self.listed)__all__ = ["SkillRead", "SkillsUsage"]diff --git a/harness/codeverse/skills/materialize.py b/harness/codeverse/skills/materialize.pyindex 67b1bc37..a10ae6b0 100644--- a/harness/codeverse/skills/materialize.py+++ b/harness/codeverse/skills/materialize.py@@ -11,6 +11,22 @@ in skills"). A 2-10 KB duplicate in a disposable workspace costs nothing.WHY ``os.utime`` at the end: the read probe in ``telemetry.py`` says a bundle was openedwhen ``atime > mtime``. That only means anything if the two start equal, somaterialisation stamps them equal instead of trusting whatever the copy left behind.++WHY a CONTROL bundle goes in beside them: because ``atime > mtime`` turned out to be a+much weaker signal than the design assumed, and measured on 2026-08-25 it fires with+nobody reading anything. Two independent causes, both verified:++* ``Workspace.changed_files`` runs ``git add -A -N`` then ``git diff --numstat`` after+ every agent session, and git reads each untracked file to compute the diff. On a real+ git workspace that alone flips all four files of a bundle to "read".+* all four CLIs (codex 0.149.0, claude-code 2.1.245, agy 1.1.20, gemini-cli 0.53.0) open+ ``references/*.md`` while activating a skill, including on a task whose description does+ not match and with the prompt telling them not to activate anything.++Neither can be argued away, so the probe carries its own falsification: one extra bundle+that is never routed, never indexed and never mentioned. If IT comes back "read", the+session's atime evidence proves nothing and ``deep_read_rate`` reports ``None`` instead of+a confident 100%."""from __future__ import annotations@@ -42,6 +58,43 @@ BODY_FILES = ("AGENTS.md", "GEMINI.md", "CLAUDE.md")MARK_BEGIN = "<!-- 3dcv:skills -->"MARK_END = "<!-- /3dcv:skills -->"+#: the never-routed bundle whose atime falsifies the probe. Named so it sorts away from+#: the real ones, and worded so an agent that does read it has been told it is a control.+CONTROL_NAME = "zz-cv3d-read-control"+CONTROL_SKILL_MD = f"""---+name: {CONTROL_NAME}+description: Measurement control for the harness read probe. Never applies to any task; do+ not use it. If you are reading this, note only that you opened it.+license: Apache-2.0+metadata:+ evidence: measured+ verified: "2026-08-25"+ evidence_note: "Not advice. A control file whose access time falsifies the read probe."+---++# Not a skill++This file exists so the harness can tell "the agent read a skill" apart from "something+touched the file". It contains no guidance. Nothing routes it and nothing lists it.+"""+CONTROL_REFERENCE_MD = ("Control reference. If this file's access time moved, the read probe "+ "cannot distinguish a real read this session.\n")+++def write_control(ws_root: Path) -> list[Path]:+ """Materialise the control bundle into both roots, stamped like the real ones."""+ written: list[Path] = []+ for rel in SKILL_ROOTS:+ d = Path(ws_root) / rel / CONTROL_NAME+ (d / "references").mkdir(parents=True, exist_ok=True)+ (d / "SKILL.md").write_text(CONTROL_SKILL_MD)+ (d / "references" / "control.md").write_text(CONTROL_REFERENCE_MD)+ written += [d / "SKILL.md", d / "references" / "control.md"]+ now = time.time()+ for p in written:+ os.utime(p, (now, now))+ return written+def _copy_bundle(skill: Skill, dest_root: Path) -> list[Path]:dest = dest_root / skill.name@@ -70,7 +123,7 @@ def materialize_skills(ws_root: Path, skills: Sequence[Skill]) -> list[Path]:a later round no longer attaches."""root = Path(ws_root)- wanted = {s.name for s in skills}+ wanted = {s.name for s in skills} | {CONTROL_NAME}written: list[Path] = []for rel in SKILL_ROOTS:base = root / rel@@ -80,6 +133,7 @@ def materialize_skills(ws_root: Path, skills: Sequence[Skill]) -> list[Path]:shutil.rmtree(old, ignore_errors=True)for s in skills:written += _copy_bundle(s, base)+ written += write_control(root)now = time.time()for p in written:os.utime(p, (now, now)) # atime == mtime: the read probe's zero point@@ -164,5 +218,5 @@ def attach_skills(return out-__all__ = ["BODY_FILES", "MARK_BEGIN", "MARK_END", "SKILL_ROOTS", "attach_skills",- "materialize_skills", "write_index"]+__all__ = ["BODY_FILES", "CONTROL_NAME", "MARK_BEGIN", "MARK_END", "SKILL_ROOTS",+ "attach_skills", "materialize_skills", "write_control", "write_index"]diff --git a/harness/codeverse/skills/telemetry.py b/harness/codeverse/skills/telemetry.pyindex 15505616..a5b5fc64 100644--- a/harness/codeverse/skills/telemetry.py+++ b/harness/codeverse/skills/telemetry.py@@ -11,16 +11,27 @@ Three signals, cheapest first:after a write bumps ``atime``. ``materialize_skills`` stamps ``atime == mtime`` onevery file it writes, so ``atime > mtime`` afterwards means the file was opened. Noparsing, and it works identically for all five backends.-2. **references/ depth probe** — signal 1 has one known false positive: a CLI's startup- scan opens SKILL.md to read the frontmatter. Nothing scans ``references/*.md``, so an- atime bump there means the agent read the body and followed it. Signal 1 = surfaced,- signal 2 = went deep. (This is the spec's own progressive disclosure, so the probe is- free — but a bundle that ships no ``references/`` cannot be probed for depth, and says- so via ``deep_measurable`` instead of quietly scoring 0.)+2. **references/ depth probe** — signal 1 has an obvious false positive: a CLI's startup+ scan opens SKILL.md to read the frontmatter. The design assumed nothing scans+ ``references/*.md``, so an atime bump there meant the agent read the body and followed+ it. **Measured 2026-08-25, that assumption is false**, for two independent reasons:+ ``Workspace.changed_files`` runs ``git add -A -N`` + ``git diff`` after every session+ and git reads every untracked file to diff it; and all four CLIs open ``references/``+ while activating a skill, even one whose description does not match the task. So the+ depth signal is kept — it is still the difference between "listed" and "opened" — but+ it is no longer trusted on its own, which is what signal 4 is for. (A bundle that+ ships no ``references/`` cannot be probed for depth and says so via+ ``deep_measurable`` instead of quietly scoring 0.)3. **exact reads for api-agent** — our own tool loop owns ``read_file``, so it logs everyread of a skill path with its turn into ``telemetry/skill_reads.jsonl``. api-agent istherefore the CALIBRATION arm: compare signals 1/2 against ground truth and report theprobe's false-positive / false-negative rate rather than assuming it is exact.+4. **the control bundle** — ``materialize.write_control`` puts one never-routed,+ never-indexed bundle beside the real ones. Nothing should ever open it. When it comes+ back opened, this session's atime evidence proves nothing, ``control_read`` is set and+ ``deep_read_rate`` returns ``None`` rather than a confident 100%. It costs two small+ files and turns a metric that could silently read 100% forever into one that says when+ it cannot see."""from __future__ import annotations@@ -105,6 +116,7 @@ def probe_reads(ws_root: Path, materialized: SkillsMaterialized) -> SkillsUsage:"""What the session did with the bundles we attached, per skill."""root = Path(ws_root)exact = _exact_reads(root)+ control_present, control_read = _control_state(root)reads: list[SkillRead] = []for sel in materialized.selections:name = sel.name@@ -129,9 +141,26 @@ def probe_reads(ws_root: Path, materialized: SkillsMaterialized) -> SkillsUsage:listed=list(materialized.listed), reads=reads, index_tokens=materialized.index_tokens,body_tokens_read=sum(r.body_tokens for r in reads if r.deep),inlined=materialized.inlined,+ control_present=control_present, control_read=control_read,)+def _control_state(root: Path) -> tuple[bool, bool]:+ """(a control was materialised, something opened it) — the probe's own falsification."""+ from codeverse.skills.materialize import CONTROL_NAME++ present = False+ opened = False+ for rel in (AGENTS_SKILL_ROOT, CLAUDE_SKILL_ROOT):+ d = root / rel / CONTROL_NAME+ if not d.is_dir():+ continue+ present = True+ for f in [d / "SKILL.md", *sorted((d / "references").glob("*.md"))]:+ opened = opened or _opened(f)+ return present, opened++def append_usage(ws_root: Path, usage: SkillsUsage, **context: Any) -> Path | None:"""One JSON line per (run, round, session) — the file ``3dcv skills report`` reads."""try:diff --git a/harness/docs/SKILLS.md b/harness/docs/SKILLS.mdindex 46e313eb..d32c58a6 100644--- a/harness/docs/SKILLS.md+++ b/harness/docs/SKILLS.md@@ -28,18 +28,37 @@ The spec's three tiers, and what each costs us per turn:The same three tiers are the read probe. `materialize_skills` writes every file with`atime == mtime`; the root filesystem is ext4 with `relatime`, so the first read afterwards-bumps `atime`. A CLI's discovery scan opens `SKILL.md` to read the frontmatter — verified,-§7 — and nothing scans `references/`. So:+bumps `atime`:-* `atime(SKILL.md) > mtime` → **surfaced**: the bundle reached the agent's index.-* `atime(references/*.md) > mtime` → **deep**: the agent read the body and followed it.+* `atime(SKILL.md) > mtime` → **surfaced**: something opened the bundle.+* `atime(references/*.md) > mtime` → **deep**: something opened the body's depth file.A bundle with no `references/` reports `deep_measurable: false` rather than quietly-scoring 0. `api-agent` owns its own `read_file`, so it logs exact reads with turn numbers-and is the **calibration arm** for the probe.+scoring 0. `api-agent` owns its own `read_file`, so it logs exact reads with turn numbers.-`references/` is therefore not optional decoration. It is the only honest evidence that a-skill was read rather than merely listed.+### The probe carries its own falsification, because it had to++The design read `deep` as "the agent chose to go deeper". **Measured 2026-08-25, it does+not mean that.** Two independent causes, both reproduced:++1. **`Workspace.changed_files` reads every file.** It runs `git add -A -N` then+ `git diff --numstat` after *every* agent session to compute `files_changed`, and git+ reads each untracked file to diff it. On a real git workspace that alone flips all four+ files of every bundle to "read", with no agent involved. Reproduced in+ `test_git_diff_alone_trips_the_control`.+2. **Every CLI opens `references/` while activating a skill.** Negative control: one+ bundle whose description does not match the task, prompt "do not read any files, do not+ activate any skill" — codex 0.149.0, claude-code 2.1.245, agy 1.1.20 and gemini-cli+ 0.53.0 *all* opened `SKILL.md` **and** `references/`. (Each touched only the root it+ owns, which is a nice independent confirmation of the root mapping in §7.)++So a fourth signal was added: `materialize.write_control` puts one **never-routed,+never-indexed** bundle beside the real ones. Nothing should ever open it. When it comes+back opened, `SkillsUsage.control_read` is set, `probe_trustworthy` is false and+`deep_read_rate` returns **`None`** — not 100%, not 0. `3dcv skills report` excludes those+sessions from the rate and prints how many it dropped.++This is the difference between a metric and a number that would have read 100% forever.---@@ -145,10 +164,14 @@ sitting in the workspace, nothing in the prompt about skills (2026-08-25):| claude-code 2.1.245 | 5 | 5 | 5 | **100%** | 8,041 | timed out on our 600 s cap after reading || agy 1.1.20 | 5 | 5 | 5 | **100%** | 8,041 | completed |-The mechanism works, and the advice lands: codex's `src/parts/common.py` came back with-`WELD_OVERLAP = 0.001` and the comment "1 mm weld overlap with the seat", which is-`cv3d-part-contact`'s recommendation and inside `PENETRATION_WARN_M`. Left to the prompt-corpus alone it would have read 2–5 mm (§9).+**Read those 100%s as an upper bound.** These runs predate the control bundle, and §1 says+why every one of them would report 100% whether or not the agent chose to read anything.++What is *not* ambiguous is the behavioural evidence underneath: codex's+`src/parts/common.py` came back with `WELD_OVERLAP = 0.001` and the comment+"1 mm weld overlap with the seat" — `cv3d-part-contact`'s recommendation, inside+`PENETRATION_WARN_M`. Left to the prompt corpus alone it would have read 2–5 mm (§9). The+content reached the model and changed the output; the atime number is what cannot prove it.Two things this also says, and neither is comfortable:@@ -292,7 +315,14 @@ its battery, its n and its date.tokens per env/zone session — and has not been A/B'd against a routed skill.* **api-agent read calibration is unmeasured.** Signal 3 (exact reads) exists and is unittested, but no real battery has yet produced a session where it can be compared against- the atime probe's answer.+ the atime probe's answer. That comparison is now the only route to a *quantified* read+ rate: the control (§1) can say when the atime probe is blind, but only api-agent's own+ `read_file` log can say what was actually read when it is.+* **The atime probe is blind in any git workspace.** `Workspace.changed_files` trips the+ control on every real run, so until either that call stops reading file contents (`git+ diff --numstat --no-index` on a copy, or `git status --porcelain` plus mtimes) or the+ probe is sampled *before* it, the reported rate for the CLI backends will be "blind" in+ every session. The control makes that visible instead of silent; it does not fix it.* **`cadquery` and `threejs` bundles are routed off.** They stay off until each languagereaches 20 graded runs.* **Router PRECISION is not reported.** The read rate says how often a listed skill wasdiff --git a/harness/tests/skills/test_materialize_prompting.py b/harness/tests/skills/test_materialize_prompting.pyindex c926d919..a7099d56 100644--- a/harness/tests/skills/test_materialize_prompting.py+++ b/harness/tests/skills/test_materialize_prompting.py@@ -58,7 +58,37 @@ def test_bundles_land_in_both_discovery_roots_as_real_files(ws, library):assert f.is_file() and not f.is_symlink()assert f.read_text() == s.path.read_text()assert (ws / root / s.name / "references" / "worked_example.md").is_file()- assert len(written) == 2 * 2 * 2 # 2 roots x 2 skills x (SKILL.md + one reference)+ # 2 roots x (2 skills + the read control) x (SKILL.md + one reference)+ assert len(written) == 2 * 3 * 2+++def test_a_never_routed_control_bundle_goes_in_beside_the_real_ones(ws, library):+ """Signal 4: the probe's own falsification.++ Nothing routes it, nothing indexes it, and if it comes back opened then whatever+ opened it was not the agent choosing to read a skill — git's own diff does it, and so+ does every CLI's activation. Without this the read rate would report 100% forever.+ """+ from codeverse.skills.materialize import CONTROL_NAME++ materialize_skills(ws, [library["cv3d-part-contact"]])+ for root in SKILL_ROOTS:+ d = ws / root / CONTROL_NAME+ assert (d / "SKILL.md").is_file() and (d / "references" / "control.md").is_file()+ assert CONTROL_NAME not in index_block([library["cv3d-part-contact"]], "api-agent")+ from codeverse.skills.registry import ROUTED_SKILLS++ assert CONTROL_NAME not in ROUTED_SKILLS+++def test_the_control_survives_a_reroute_and_never_counts_as_a_stale_bundle(ws, library):+ from codeverse.skills.materialize import CONTROL_NAME++ materialize_skills(ws, [library["cv3d-part-contact"], library["cv3d-bbox-contract"]])+ materialize_skills(ws, [library["cv3d-bbox-contract"]])+ for root in SKILL_ROOTS:+ assert (ws / root / CONTROL_NAME / "SKILL.md").is_file()+ assert not (ws / root / "cv3d-part-contact").exists()def test_nothing_in_a_materialised_tree_is_a_symlink_because_codex_refuses_them(ws, library):diff --git a/harness/tests/skills/test_telemetry.py b/harness/tests/skills/test_telemetry.pyindex f05e30f8..d52ae466 100644--- a/harness/tests/skills/test_telemetry.py+++ b/harness/tests/skills/test_telemetry.py@@ -149,3 +149,78 @@ def test_telemetry_never_raises_into_a_run(tmp_path):record_exact_read(tmp_path / "does" / "not" / "exist", ".agents/skills/x/SKILL.md", turn=1)assert append_usage(tmp_path / "nope" / "nope", probe_reads(tmp_path, SkillsMaterialized())) is None or True+++# --------------------------------------------------------------- signal 4: the control+def test_the_control_bundle_is_materialised_and_starts_unread(ws, library):+ from codeverse.skills.materialize import CONTROL_NAME, materialize_skills++ materialize_skills(ws, [library["cv3d-part-contact"]])+ usage = probe_reads(ws, _materialized(library, "cv3d-part-contact"))+ assert usage.control_present and not usage.control_read+ assert usage.probe_trustworthy+ assert CONTROL_NAME not in usage.listed+++def test_a_control_that_was_opened_makes_the_rate_unmeasurable(ws, library):+ """The whole point: a session where everything looks read is a session that measured+ nothing, and it must say so instead of reporting a confident 100%."""+ from codeverse.skills.materialize import CONTROL_NAME, materialize_skills+ from codeverse.skills.prompting import AGENTS_SKILL_ROOT++ materialize_skills(ws, [library["cv3d-part-contact"]])+ _touch(ws / AGENTS_SKILL_ROOT / "cv3d-part-contact" / "references" / "worked_example.md")+ _touch(ws / AGENTS_SKILL_ROOT / CONTROL_NAME / "references" / "control.md")+ usage = probe_reads(ws, _materialized(library, "cv3d-part-contact"))+ assert usage.deep == ["cv3d-part-contact"] # the raw signal is still reported+ assert usage.control_read and not usage.probe_trustworthy+ assert usage.deep_read_rate is None # but the RATE refuses to lie+++def test_git_diff_alone_trips_the_control(tmp_path, library): # noqa: PLR0915+ """The confound that invalidated the original design, reproduced.++ ``Workspace.changed_files`` runs `git add -A -N` then `git diff --numstat` after every+ agent session, and git reads each untracked file to diff it. That flips every bundle+ file to "read" with no agent involved at all.+ """+ import subprocess++ from codeverse.skills.materialize import materialize_skills++ ws = tmp_path / "ws"+ (ws / "src").mkdir(parents=True)+ subprocess.run(["git", "init", "-q"], cwd=ws, check=True)+ subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-q",+ "--allow-empty", "-m", "init"], cwd=ws, check=True)+ for f in materialize_skills(ws, [library["cv3d-part-contact"]]):+ # back-date by more than ATIME_EPSILON_S: a real session lasts minutes, and the+ # probe deliberately ignores an access within a second of the write+ st = os.stat(f)+ os.utime(f, (st.st_mtime - 10, st.st_mtime - 10))++ before = probe_reads(ws, _materialized(library, "cv3d-part-contact"))+ assert before.probe_trustworthy, "materialisation alone must leave the control unread"++ subprocess.run(["git", "add", "-A", "-N"], cwd=ws, check=True)+ subprocess.run(["git", "diff", "--numstat", "HEAD"], cwd=ws, check=True, capture_output=True)++ after = probe_reads(ws, _materialized(library, "cv3d-part-contact"))+ assert after.control_read, "git read every untracked file; the control must have caught it"+ assert after.deep_read_rate is None+++def _materialized(library, *names):+ from codeverse.skills.model import Selection, SkillsMaterialized++ sels = [Selection(skill=library[n], priority=50, rules=("R1",), reason="test") for n in names]+ return SkillsMaterialized(listed=list(names), selections=sels)+++def _touch(path):+ import os+ import time++ st = os.stat(path)+ os.utime(path, (st.st_mtime + 60, st.st_mtime))+ time.sleep(0)