Official Codebase of 3DCodeVerse
Python
Fix three small bugs: articulated motion checks run once, brief cache key without track/language, placement constants pinned to the probe's; comments and names
gaoypengceee1043c1fd
diff --git a/harness/codeverse3d/config.py b/harness/codeverse3d/config.pyindex aa217e75..973f3bed 100644--- a/harness/codeverse3d/config.py+++ b/harness/codeverse3d/config.py@@ -30,6 +30,7 @@ from pydantic import (ValidationInfo,ValidatorFunctionWrapHandler,WrapValidator,+ field_validator,model_validator,)from pydantic_core import PydanticUseDefault@@ -178,8 +179,8 @@ class Judge(BaseModel):class Placement(BaseModel):"""The scene_placement gate's thresholds (spatial/scene_placement.py), metres / fractions.- The JS measurement (host_placement.mjs) keeps its own CONTACT / FLOATING / SUNK constants:- these decide severities only."""+ The JS measurement (host_placement.mjs) keeps its own CONTACT / FLOATING / SUNK constants: Settings refuses a+ placement whose contact_m / floating_outdoor_m / sunk_m differ from them; the rest decide severities only."""contact_m: float = Field(default=0.02, ge=0, description="foot within this of a surface = seated")floating_outdoor_m: float = Field(default=0.05, ge=0, description="gap above which an outdoor asset floats")@@ -222,6 +223,16 @@ class Settings(BaseSettings):data[section] = {**(sub.model_dump() if isinstance(sub, BaseModel) else sub), name: raw}return data+ @field_validator("placement")+ @classmethod+ def _placement_matches_the_probe(cls, v: Placement) -> Placement:+ """The probe (host_placement.mjs) measures `seated` / `floating` / `sunk` at its own constants: the gate must grade the same numbers."""+ d = Placement()+ if (v.contact_m, v.floating_outdoor_m, v.sunk_m) != (d.contact_m, d.floating_outdoor_m, d.sunk_m):+ raise ValueError("placement.contact_m / floating_outdoor_m / sunk_m are pinned to host_placement.mjs "+ "(CONTACT_TOL_M / FLOATING_M / SUNK_M); change both together")+ return v+runs_dir: Path = Field(default=Path("runs"))cache_dir: Path = Field(default=Path.home() / ".cache" / "codeverse3d")binaries: Binaries = Field(default_factory=Binaries)diff --git a/harness/codeverse3d/languages/cadquery/__init__.py b/harness/codeverse3d/languages/cadquery/__init__.pyindex ca1d9a4e..f1d0b097 100644--- a/harness/codeverse3d/languages/cadquery/__init__.py+++ b/harness/codeverse3d/languages/cadquery/__init__.py@@ -89,7 +89,7 @@ def _f(sev: Severity, msg: str, line: int | None = None, hint: str = "", target:return GateFinding(gate=GATE, severity=sev, target=target, message=msg, fix_hint=hint, data={"line": line} if line else {})-class BpyCollector(ImportCollector):+class CqCollector(ImportCollector):def __init__(self) -> None:super().__init__()self.calls: list[tuple[str, ast.Call]] = []@@ -134,7 +134,7 @@ def _top_level_assigned(tree: ast.Module) -> tuple[set[str], set[str]]:return top, guarded-def _rules(c: BpyCollector, tree: ast.Module, source: str) -> list[GateFinding]:+def _rules(c: CqCollector, tree: ast.Module, source: str) -> list[GateFinding]:E, W, I = Severity.ERROR, Severity.WARN, Severity.INFO # noqa: E741out: list[GateFinding] = []if "cadquery" not in c.imports:@@ -190,7 +190,7 @@ def lint_cadquery_source(source: str, *, target: str = "src/model.py") -> GateRemsg, hint, line = describe_parse_failure(exc) # type: ignore[arg-type]f = _f(Severity.ERROR, msg, line, hint, target)return GateReport.of(GATE, [f], duration_ms=int((time.monotonic() - t0) * 1000))- c = BpyCollector()+ c = CqCollector()c.visit(tree)findings = _rules(c, tree, source)for f in findings:diff --git a/harness/codeverse3d/languages/urdf/__init__.py b/harness/codeverse3d/languages/urdf/__init__.pyindex 590ab8fb..d280ae27 100644--- a/harness/codeverse3d/languages/urdf/__init__.py+++ b/harness/codeverse3d/languages/urdf/__init__.py@@ -687,7 +687,7 @@ class UrdfBlenderRuntime(RuntimeLayout):return fail("LintError", f"{len(errs)} lint error(s):\n{msg}", file=str(errs[0].target or "src/robot.urdf"),line=errs[0].data.get("line"), census=census)- # 2. Blender wrapper (writes build.json / census.json / meshes/ into the staging dir),+ # 1. Blender wrapper (writes build.json / census.json / meshes/ into the staging dir),# read like every other wrapper's reportblender = settings.resolve_blender()if not blender:@@ -716,7 +716,7 @@ class UrdfBlenderRuntime(RuntimeLayout):msg = "\n".join(f"- {f.as_line()}" for f in fk_findings)return fail("FkInconsistent", f"URDF frames do not reproduce the authored geometry:\n{msg}", census=census)- # 5. the rest pose decides the build; other poses are the joint_sweep gate+ # 2. the rest pose decides the build; other poses are the joint_sweep gatereport = sweep_collisions(robot, [{}])findings = sweep_findings(report, rest_max_m=REST_PENETRATION_MAX_M)@@ -743,7 +743,7 @@ def _run_blender(blender: str, ws: Workspace, art: Path, timeout_s: int, rlimit_"--script", str(ws.root / "src" / "model.py"), "--urdf", str(ws.root / "src" / "robot.urdf"),"--out", str(art), "--rlimit-gb", str(rlimit_gb)]# whitelist env (no inherited PYTHONPATH, user config pinned into artifacts) — deliberately- # stricter than blender.runtime.blender_env(); keep it that way+ # stricter than languages.blender.blender_env(); keep it that wayenv = {"PATH": os.environ.get("PATH", "/usr/bin:/bin"), "HOME": os.environ.get("HOME", str(ws.root)),"PYTHONDONTWRITEBYTECODE": "1", "PYTHONNOUSERSITE": "1", "BLENDER_USER_CONFIG": str(art / ".blender_config")}return run_subprocess(cmd, cwd=ws.root, env=env, timeout_s=timeout_s)diff --git a/harness/codeverse3d/tracks/articulated_object.py b/harness/codeverse3d/tracks/articulated_object.pyindex 24cc58f9..2c15d809 100644--- a/harness/codeverse3d/tracks/articulated_object.py+++ b/harness/codeverse3d/tracks/articulated_object.py@@ -34,12 +34,12 @@ class ArticulatedPipeline(ObjectPipeline):def gates(self, ctx: RunContext, round_index: int, build: BuildResult, measurement: Measurement | None) -> list[GateReport]:out = super().gates(ctx, round_index, build, measurement)- repaired = self._axis_repair(ctx)+ repaired, pre = self._axis_repair(ctx)out_dir = ctx.ws.renders_dir(round_index) / "poses"report, views = ctx.services.joint_sweep(ctx.ws, ctx.plan, out_dir)ctx.extra["pose_views"] = viewsout.append(report)- motion = self._motion_gate(ctx)+ motion = pre if pre is not None and not repaired else self._motion_gate(ctx) # the file changed only if repairedif motion is not None:if repaired:motion.findings.append(GateFinding(@@ -50,18 +50,19 @@ class ArticulatedPipeline(ObjectPipeline):return out@staticmethod- def _axis_repair(ctx: RunContext) -> list[str]:+ def _axis_repair(ctx: RunContext) -> tuple[list[str], GateReport | None]:+ """(joints repaired, the motion report measured before the repair); ``(…, None)`` when it did not run."""if not get_settings().axis_repair:- return []+ return [], Nonetry:pre = ctx.services.motion_checks(ctx.ws, ctx.plan)repaired = repair_motion_axes(ctx.ws, pre)except Exception as e: # noqa: BLE001 — advisory repair; the gate still reports truthlog.warning("axis repair skipped: %s", e)- return []+ return [], Noneif repaired:ctx.events.emit("gate.axis_repaired", joints=repaired)- return repaired+ return repaired, pre@staticmethoddef _motion_gate(ctx: RunContext) -> GateReport | None:diff --git a/harness/codeverse3d/tracks/planner.py b/harness/codeverse3d/tracks/planner.pyindex 2493a079..2b679946 100644--- a/harness/codeverse3d/tracks/planner.py+++ b/harness/codeverse3d/tracks/planner.py@@ -64,10 +64,10 @@ def _reference_digest(spec: Spec) -> list[dict[str, str]]:def brief_cache_key(spec: Spec, model_id: str) -> str:- """Every input to the call must be in the key."""+ """Every input to the call must be in the key (the call is the same for every track and language)."""c = spec.constraintspayload = json.dumps({- "prompt": spec.prompt.strip(), "track": spec.track.value, "language": spec.language.value,+ "prompt": spec.prompt.strip(),"must_have": list(c.must_have), "must_not": list(c.must_not), "style": c.style,"dimensions_m": c.dimensions_m or {}, "model": model_id,"references": _reference_digest(spec),@@ -96,7 +96,7 @@ def expand_brief(spec: Spec, model_id: str, *, model: Any | None = None, events:log.warning("brief cache %s unusable (%s); regenerating", path, e)if model is None:model = get_chat_model(model_id)- system = render(BRIEF_TEMPLATE, track=spec.track.value, language=spec.language.value)+ system = render(BRIEF_TEMPLATE)images = [ImagePart(path=r.path, label=f"{r.role}: {r.note}".strip(": ")) for r in spec.references]user = f"REQUEST: {spec.prompt.strip()}"if spec.constraints.must_have: