Official Codebase of 3DCodeVerse
Python
skills: CV3D_SKILLS_ONLY restricts the LIBRARY, so an effect A/B can name one bundle
gaoypeng489229167594
diff --git a/harness/codeverse/skills/config.py b/harness/codeverse/skills/config.pyindex ba76ac9a..fda4d1cf 100644--- a/harness/codeverse/skills/config.py+++ b/harness/codeverse/skills/config.py@@ -12,6 +12,15 @@ in ``plan_features.LIVE_SWITCHES``, and a test that greps the tree to prove it i* ``CV3D_SKILLS_MAX`` — attached bundles per session (default 5, design §5.2 law 1).* ``CV3D_SKILLS_UNVERIFIED`` — also route bundles labelled ``inherited-unverified``(cadquery / threejs today: zero graded runs, so their claims are carried, not measured).+* ``CV3D_SKILLS_ONLY`` — comma list; the router may consider ONLY these bundles.++WHY ``CV3D_SKILLS_ONLY`` exists. An effect A/B has to attribute its delta to ONE bundle,+and ``CV3D_SKILLS=1`` routes up to five. Restricting the LIBRARY (rather than filtering+the selection afterwards) is the semantics that keeps the arms honest: the named bundle+is routed exactly where its own table rows fire, and the cap never silently drops it in+favour of a higher-priority sheet that is not under test. An unknown name yields an+empty library — every session then attaches nothing, which shows up immediately as a+variant arm identical to its control, rather than quietly measuring the full set."""from __future__ import annotations@@ -24,6 +33,7 @@ log = logging.getLogger(__name__)SKILLS_ENV = "CV3D_SKILLS"SKILLS_MAX_ENV = "CV3D_SKILLS_MAX"SKILLS_UNVERIFIED_ENV = "CV3D_SKILLS_UNVERIFIED"+SKILLS_ONLY_ENV = "CV3D_SKILLS_ONLY"DEFAULT_SKILLS_MAX = 5_TRUE = frozenset({"1", "on", "true", "yes", "y"})@@ -50,6 +60,17 @@ def skills_unverified() -> bool:return _flag(SKILLS_UNVERIFIED_ENV)+def skills_only() -> frozenset[str]:+ """The bundles the router may consider, or empty for "all of them".++ Read at call time like the other three, for the same reason: an A/B arm sets it in+ the child's environment and a value frozen at import would hand the variant the+ control's library.+ """+ raw = os.environ.get(SKILLS_ONLY_ENV, "")+ return frozenset(n.strip() for n in raw.split(",") if n.strip())++def skills_max(default: int = DEFAULT_SKILLS_MAX) -> int:"""Cap on bundles attached to one session. A bad value falls back, never crashes a run."""raw = os.environ.get(SKILLS_MAX_ENV, "").strip()@@ -66,5 +87,5 @@ def skills_max(default: int = DEFAULT_SKILLS_MAX) -> int:return n-__all__ = ["DEFAULT_SKILLS_MAX", "SKILLS_ENV", "SKILLS_MAX_ENV", "SKILLS_UNVERIFIED_ENV",- "skills_enabled", "skills_max", "skills_unverified"]+__all__ = ["DEFAULT_SKILLS_MAX", "SKILLS_ENV", "SKILLS_MAX_ENV", "SKILLS_ONLY_ENV",+ "SKILLS_UNVERIFIED_ENV", "skills_enabled", "skills_max", "skills_only", "skills_unverified"]diff --git a/harness/codeverse/skills/materialize.py b/harness/codeverse/skills/materialize.pyindex a10ae6b0..70bd7418 100644--- a/harness/codeverse/skills/materialize.py+++ b/harness/codeverse/skills/materialize.py@@ -39,7 +39,7 @@ from collections.abc import Sequencefrom pathlib import Pathfrom typing import Any-from codeverse.skills.config import skills_max, skills_unverified+from codeverse.skills.config import SKILLS_ONLY_ENV, skills_max, skills_only, skills_unverifiedfrom codeverse.skills.model import Selection, Skill, SkillsMaterializedfrom codeverse.skills.prompting import (AGENTS_SKILL_ROOT,@@ -178,12 +178,28 @@ def attach_skills(library: dict[str, Skill] | None = None,max_skills: int | None = None,allow_unverified: bool | None = None,+ only: frozenset[str] | None = None,) -> SkillsMaterialized:"""Route → write → return what a session will see. The one entry point tracks call.The caller decides whether the feature is on (``config.skills_enabled``); thisfunction assumes it is, so a test can attach without setting the environment.++ ``only`` (env ``CV3D_SKILLS_ONLY``) restricts the LIBRARY before routing, which is+ what an effect A/B needs: the delta then belongs to one bundle instead of to whatever+ set of five the router happened to pick. Restricting the library — rather than+ filtering ``sel`` afterwards — also stops the cap from spending a slot on a bundle+ that is not under test and then dropping the one that is."""+ picked = skills_only() if only is None else only+ if picked:+ from codeverse.skills import all_skills++ lib = dict(all_skills() if library is None else library)+ library = {n: s for n, s in lib.items() if n in picked}+ if not library:+ log.warning("%s=%s matches no bundle in the library; this session attaches nothing",+ SKILLS_ONLY_ENV, ",".join(sorted(picked)))sel: list[Selection] = select(track, language, kind,signals=plan_signals(plan), findings=findings, library=library,diff --git a/harness/codeverse/tracks/plan_features.py b/harness/codeverse/tracks/plan_features.pyindex 29c4e64b..8e4eca91 100644--- a/harness/codeverse/tracks/plan_features.py+++ b/harness/codeverse/tracks/plan_features.py@@ -52,6 +52,7 @@ GENERATION_SIDE: frozenset[str] = frozenset({CONTACTS})#: env switches outside CV3D_PLAN_FEATURES, same rulePLAN_SIDE_ENV: frozenset[str] = frozenset({"CV3D_PLAN_BRIEF", "CV3D_SCOPED_PARTS"})GENERATION_SIDE_ENV: frozenset[str] = frozenset({"CV3D_SKILLS", "CV3D_SKILLS_MAX", "CV3D_SKILLS_UNVERIFIED",+ "CV3D_SKILLS_ONLY","CV3D_DETAIL_ROUNDS", "CV3D_REFERENCE_DIFF"})@@ -87,6 +88,7 @@ LIVE_SWITCHES: dict[str, str] = {"CV3D_SKILLS": "codeverse/skills/config.py","CV3D_SKILLS_MAX": "codeverse/skills/config.py","CV3D_SKILLS_UNVERIFIED": "codeverse/skills/config.py",+ "CV3D_SKILLS_ONLY": "codeverse/skills/config.py",}#: Switches that are DECLARED but read by no code path, with the reason. An A/B arm thatdiff --git a/harness/tests/skills/test_only_switch.py b/harness/tests/skills/test_only_switch.pynew file mode 100644index 00000000..953b9d3e--- /dev/null+++ b/harness/tests/skills/test_only_switch.py@@ -0,0 +1,88 @@+"""``CV3D_SKILLS_ONLY``: route exactly one bundle, so an effect A/B can attribute its delta.++``CV3D_SKILLS=1`` routes up to five bundles. A delta measured against that is a delta of+the SET, and the wave's question is per bundle. The switch restricts the LIBRARY rather+than filtering the selection afterwards, and the difference is testable: with a filter,+the cap could spend its slots on higher-priority sheets and drop the one under test.+"""++from __future__ import annotations++import pytest++from codeverse.skills.config import SKILLS_ONLY_ENV, skills_only+from codeverse.skills.materialize import attach_skills+++class _Part:+ def __init__(self, instances=1, symmetry="none"):+ self.instances, self.symmetry, self.children = instances, symmetry, None+++class _Plan:+ parts = (_Part(instances=4), _Part(symmetry="mirror_x"))+ joints = effects = passes = ()+ summary = style_notes = ""+++def ws(tmp_path):+ (tmp_path / "AGENTS.md").write_text("# agents\n")+ return tmp_path+++def _listed(ws, **kw):+ return attach_skills(ws, track="static_object", language="blender", kind="baseline",+ agent_kind="api-agent", plan=_Plan(), **kw).listed+++def test_unset_routes_the_whole_set(ws):+ listed = _listed(ws)+ assert len(listed) > 1+ assert "cv3d-bbox-contract" in listed++[email protected]("name", ["cv3d-bbox-contract", "cv3d-blender-forms", "cv3d-repeats-and-mirrors"])+def test_only_routes_exactly_that_bundle(ws, name):+ assert _listed(ws, only=frozenset({name})) == [name]+++def test_the_cap_cannot_drop_the_bundle_under_test(ws):+ """The reason it restricts the library and not the selection. bbox-contract ranks+ below blender-forms and part-contact in the default set, so a max of 1 applied to the+ FULL routing would hand back somebody else's bundle."""+ assert _listed(ws, max_skills=1)[0] != "cv3d-bbox-contract"+ assert _listed(ws, only=frozenset({"cv3d-bbox-contract"}), max_skills=1) == ["cv3d-bbox-contract"]+++def test_a_bundle_its_own_rules_do_not_fire_for_is_still_not_routed(ws):+ """`only` narrows what MAY be routed; it never forces an attachment. urdf-joints has+ no row that fires on a blender static_object, so the arm attaches nothing — and an A/B+ on it would correctly measure no difference rather than a fabricated one."""+ assert _listed(ws, only=frozenset({"cv3d-urdf-joints"})) == []+++def test_an_unknown_name_attaches_nothing_rather_than_everything(ws, caplog):+ """A typo must make the variant visibly identical to its control, not silently+ measure the full five-bundle set."""+ assert _listed(ws, only=frozenset({"cv3d-typo"})) == []+ assert SKILLS_ONLY_ENV in caplog.text+++def test_the_switch_is_read_at_call_time(ws, monkeypatch):+ """Frozen at import (the get_settings/lru_cache trap) the variant child would run the+ control's library — the failure mode that printed 'keep, +0.344' for identical arms."""+ monkeypatch.delenv(SKILLS_ONLY_ENV, raising=False)+ assert skills_only() == frozenset()+ monkeypatch.setenv(SKILLS_ONLY_ENV, " cv3d-bbox-contract , ")+ assert skills_only() == frozenset({"cv3d-bbox-contract"})+ assert _listed(ws) == ["cv3d-bbox-contract"], "attach_skills must consult the env when only= is omitted"+++def test_pinning_one_bundle_still_permits_a_pinned_plan():+ """The switch is generation-side, so bench/ab_plan.py --pin-plan stays available —+ which is the only reason this wave is measurable where the plan loop was not."""+ from codeverse.tracks.plan_features import LIVE_SWITCHES, pin_plan_blockers++ assert SKILLS_ONLY_ENV in LIVE_SWITCHES, "an unregistered switch is one ab_plan calls dead"+ assert pin_plan_blockers({"CV3D_SKILLS": "1", SKILLS_ONLY_ENV: "cv3d-bbox-contract"}) == []