Official Codebase of 3DCodeVerse
Python
skills_hook: the round passes the previous round's gates in, and repair pointers use Route.matches_finding (E1)
gaoypeng48159036aee6
diff --git a/harness/codeverse3d/tracks/lifecycle.py b/harness/codeverse3d/tracks/lifecycle.pyindex 5b0780b6..e796daef 100644--- a/harness/codeverse3d/tracks/lifecycle.py+++ b/harness/codeverse3d/tracks/lifecycle.py@@ -506,7 +506,8 @@ class BaseTrack:rec = run_best_of_n(self, ctx, tasks, pipeline, files_hint=ctx.runtime.expected_files(ctx.plan))else:rec = run_round(ctx, index=index, kind=kind, tasks=tasks, pipeline=pipeline, instructions=instructions,- previous=previous, files_hint=ctx.runtime.expected_files(ctx.plan),+ previous=previous, findings=rounds[-1].gates if rounds else (),+ files_hint=ctx.runtime.expected_files(ctx.plan),extra_notes=self.round_extra_notes(ctx))except RoundFailed as e:if e.quota:diff --git a/harness/codeverse3d/tracks/skills_hook.py b/harness/codeverse3d/tracks/skills_hook.pyindex 514c299e..d9a02505 100644--- a/harness/codeverse3d/tracks/skills_hook.py+++ b/harness/codeverse3d/tracks/skills_hook.py@@ -15,14 +15,10 @@ from __future__ import annotationsimport loggingfrom collections.abc import Sequence-from pathlib import Pathfrom typing import Any-from pydantic import ValidationError-from codeverse3d.contracts.artifacts import GateReportfrom codeverse3d.contracts.run import SkillsUsage-from codeverse3d.proc import read_json_or_nonefrom codeverse3d.tracks.common import RunContextlog = logging.getLogger(__name__)@@ -30,33 +26,10 @@ log = logging.getLogger(__name__)CTX_KEY = "skills" # ctx.extra slot holding this round's SkillsMaterialized-def _previous_findings(ctx: RunContext, index: int) -> list[GateReport]:- """The gates of the last completed round — the input no CLI's own loader can see.-- Read straight off disk rather than through ``steps.load_round_journal`` so the hook- stays independent of the round loop (and so a half-written record from a killed run- costs this round its gate routing, not the round itself)."""- if index <= 0:- return []- d = Path(ctx.ws.root) / "rounds"- if not d.is_dir():- return []- for p in sorted(d.glob("r*.json"), reverse=True):- data = read_json_or_none(p)- if data is None or int(data.get("index", -1)) >= index: # unreadable, or not before this round- continue- gates = data.get("gates") or []- if gates:- try:- return [GateReport.model_validate(g) for g in gates]- except ValidationError as e:- log.debug("skills: round record %s has gates we cannot parse: %s", p, e)- return []- return []---def attach_for_round(ctx: RunContext, *, index: int, kind: str) -> Any | None:- """Route + materialise this round's skills. Returns the ``SkillsMaterialized``."""+def attach_for_round(ctx: RunContext, *, index: int, kind: str, findings: Sequence[GateReport] = ()) -> Any | None:+ """Route + materialise this round's skills. Returns the ``SkillsMaterialized``.++ ``findings``: the previous round's gates — the input no CLI's own loader can see."""from codeverse3d.config import get_settingsfrom codeverse3d.skills import attach_skills@@ -72,7 +45,7 @@ def attach_for_round(ctx: RunContext, *, index: int, kind: str) -> Any | None:language=ctx.language.value,kind=kind,plan=ctx.plan,- findings=_previous_findings(ctx, index),+ findings=list(findings),single_shot=ctx.single_shot,)except Exception as e: # noqa: BLE001 — never let the skill system break a round@@ -118,33 +91,16 @@ def repair_pointers(ctx: RunContext, lint: GateReport | None) -> str:if not got or not getattr(got, "selections", None):return ""from codeverse3d.skills.prompting import repair_pointers as _fmt- from codeverse3d.skills.registry import finding_kinds+ from codeverse3d.skills.registry import ROUTES, finding_kinds- kinds = set(finding_kinds([lint])) if lint is not None else set()- answering = [s.name for s in got.selections if kinds & _matched(s, kinds)]+ kinds = finding_kinds([lint]) if lint is not None else []+ # ANY route for the skill, not just the rules that fired at attach time: the build/lint failure a+ # repair session is looking at was discovered afterwards, and the sheet that answers it is+ # already sitting in the workspace+ answering = [s.name for s in got.selections if any(r.skill == s.name and r.matches_finding(kinds) for r in ROUTES)]return _fmt(got.selections, agent_kind=ctx.agent_kind, answering=answering)-def _matched(selection: Any, kinds: set[str]) -> set[str]:- """The current finding kinds this attached skill's routes answer (families included)."""- out: set[str] = set()- for pat in _kinds_of(selection):- family = pat[:-1] if pat.endswith("*") else ""- out |= {k for k in kinds if (family and k.startswith(family)) or k == pat}- return out---def _kinds_of(selection: Any) -> tuple[str, ...]:- """Every finding kind ANY route for this skill answers.-- Deliberately not just the rules that fired at attach time: the build/lint failure a- repair session is looking at was discovered afterwards, and the sheet that answers it- is already sitting in the workspace."""- from codeverse3d.skills.registry import ROUTES-- return tuple(k for r in ROUTES if r.skill == selection.name for k in r.findings)--def record_usage(ctx: RunContext, *, index: int, kind: str) -> SkillsUsage | None:"""After the round's sessions: what was read. Also appends ``telemetry/skills.jsonl``."""got = ctx.extra.get(CTX_KEY)diff --git a/harness/codeverse3d/tracks/steps.py b/harness/codeverse3d/tracks/steps.pyindex bd3fdfc5..4ffa9987 100644--- a/harness/codeverse3d/tracks/steps.py+++ b/harness/codeverse3d/tracks/steps.py@@ -191,11 +191,14 @@ def run_round(pipeline: RoundPipeline,instructions: Sequence[str] = (),previous: Judgment | None = None,+ findings: Sequence[GateReport] = (),files_hint: Sequence[str] = (),extra_usage: Usage | None = None,extra_notes: Sequence[str] = (),) -> RoundRecord:"""Execute one round and persist its record. Budget is charged as it goes.+ ``previous`` / ``findings``: the previous round's verdict and gates (the judge reads the one,+ the skill router the other).``tasks`` may be empty when the code is already in place (scene stages,best-of-N winner copied in): the round is then build → gates → render →@@ -209,7 +212,7 @@ def run_round(with tally() as spent:try:return _run_round(ctx, index=index, kind=kind, tasks=tasks, pipeline=pipeline, instructions=instructions,- previous=previous, files_hint=files_hint, extra_usage=extra_usage,+ previous=previous, findings=findings, files_hint=files_hint, extra_usage=extra_usage,extra_notes=extra_notes, steps=steps, spent=spent)except BaseException as e:# the round died half-way (budget stop, 503 storm, RoundFailed): what it burned@@ -228,6 +231,7 @@ def _run_round(pipeline: RoundPipeline,instructions: Sequence[str] = (),previous: Judgment | None = None,+ findings: Sequence[GateReport] = (),files_hint: Sequence[str] = (),extra_usage: Usage | None = None,extra_notes: Sequence[str] = (),@@ -249,7 +253,7 @@ def _run_round(# or every kind-gated bundle (the *-forms / *-joints routes) drops out and the winner is# generated with a strictly smaller library than a --candidates 1 baseline (review 2026-08-29)skill_kind = "baseline" if kind == "candidate" else kind- skills_hook.attach_for_round(ctx, index=index, kind=skill_kind)+ skills_hook.attach_for_round(ctx, index=index, kind=skill_kind, findings=findings)gens = run_generation_tasks(ctx, skills_hook.with_inlined_skill(ctx, tasks), steps=steps)notes += [f"{g.label}: {g.notes}" for g in gens if not g.ok]ctx.ws.commit(f"r{index:02d} {kind}: generated")diff --git a/harness/tests/skills/test_hook.py b/harness/tests/skills/test_hook.pyindex b8fbc536..fe1f6298 100644--- a/harness/tests/skills/test_hook.py+++ b/harness/tests/skills/test_hook.py@@ -60,17 +60,10 @@ def test_the_switch_on_attaches_records_and_measures(ctx, monkeypatch):def test_the_previous_rounds_findings_route_the_repair_sheet(ctx, monkeypatch):monkeypatch.setenv("C3D_SKILLS", "on")- rounds = ctx.ws.root / "rounds"- rounds.mkdir()- rec = {"index": 0, "kind": "baseline", "gates": [GateReport(- gate="connectivity", passed=False,- findings=[GateFinding(gate="connectivity", severity=Severity.ERROR,- message="part 'Leg' is floating: nearest supported part is 'Seat' at 4.0 mm")],- ).model_dump(mode="json")]}- import json-- (rounds / "r00.json").write_text(json.dumps(rec))- got = H.attach_for_round(ctx, index=1, kind="repair")+ gates = [GateReport(gate="connectivity", passed=False, findings=[GateFinding(+ gate="connectivity", severity=Severity.ERROR,+ message="part 'Leg' is floating: nearest supported part is 'Seat' at 4.0 mm")])]+ got = H.attach_for_round(ctx, index=1, kind="repair", findings=gates)assert "c3d-part-contact" in got.listedassert "connectivity/floating_part" in got.reasons["c3d-part-contact"]assert got.selections[0].gate_fired