Official Codebase of 3DCodeVerse
Python
record: _git.py is git_history.py — a module seven others import by a private-looking name
gaoypeng29b5190881d6
diff --git a/harness/codeverse3d/addons/dataset/captions.py b/harness/codeverse3d/addons/dataset/captions.pyindex 3676f3df..191e90a8 100644--- a/harness/codeverse3d/addons/dataset/captions.py+++ b/harness/codeverse3d/addons/dataset/captions.py@@ -31,7 +31,7 @@ from codeverse3d.contracts.run import RunRecordfrom codeverse3d.models import get_chat_modelfrom codeverse3d.proc import write_json_atomicfrom codeverse3d.prompts import prompt_hash-from codeverse3d.record import _git+from codeverse3d.record import git_historyfrom codeverse3d.workspace import WorkspaceMAX_CODE_CHARS = 12_000@@ -128,7 +128,7 @@ def _code_excerpt(ws: Workspace, record: RunRecord) -> str:files, _src = code_files_for_round(ws, rnd)entry = ENTRY_FILE[record.spec.language]ordered = {k: files[k] for k in sorted(files, key=lambda k: (k != entry, k))}- text, _skipped = _git.decode_text_files(ordered, max_total=MAX_CODE_CHARS)+ text, _skipped = git_history.decode_text_files(ordered, max_total=MAX_CODE_CHARS)return "\n\n".join(f"### {p}\n{t}" for p, t in text.items())diff --git a/harness/codeverse3d/addons/dataset/export.py b/harness/codeverse3d/addons/dataset/export.pyindex 5a86349c..a652ebf8 100644--- a/harness/codeverse3d/addons/dataset/export.py+++ b/harness/codeverse3d/addons/dataset/export.py@@ -40,7 +40,7 @@ from codeverse3d.addons.dataset.quality import DuplicateGroup, code_sha256, markfrom codeverse3d.contracts.common import ENTRY_FILE, Languagefrom codeverse3d.contracts.run import RunId, RunRecordfrom codeverse3d.proc import read_json_or_none, sha256_file, write_json_atomic, write_text_atomic-from codeverse3d.record._git import CODE_ROOTS+from codeverse3d.record.git_history import CODE_ROOTSfrom codeverse3d.record.record import FoundRun, iter_runsfrom codeverse3d.workspace import Workspacediff --git a/harness/codeverse3d/addons/dataset/pairs.py b/harness/codeverse3d/addons/dataset/pairs.pyindex 3844d469..39f4eac6 100644--- a/harness/codeverse3d/addons/dataset/pairs.py+++ b/harness/codeverse3d/addons/dataset/pairs.py@@ -34,7 +34,7 @@ from codeverse3d.addons import selectfrom codeverse3d.addons.dataset.quality import prompt_idfrom codeverse3d.contracts.run import RoundRecord, RunRecordfrom codeverse3d.proc import read_jsonl_lenient-from codeverse3d.record import _git+from codeverse3d.record import git_historyfrom codeverse3d.record.record import effective_judgment, iter_runs, skip_unreadablefrom codeverse3d.workspace import Workspace@@ -49,10 +49,10 @@ def _side(ws: Workspace, rnd: RoundRecord, *, cache: dict[str, dict[str, Any]])key = rnd.commit or f"wt:{rnd.index}"if key not in cache:try:- raw = _git.read_tree_at(ws, rnd.commit) if rnd.commit else _git.read_working_tree(ws)- except _git.GitReadError:+ raw = git_history.read_tree_at(ws, rnd.commit) if rnd.commit else git_history.read_working_tree(ws)+ except git_history.GitReadError:raw = {}- text, skipped = _git.decode_text_files(raw, max_total=MAX_INLINE_CODE)+ text, skipped = git_history.decode_text_files(raw, max_total=MAX_INLINE_CODE)cache[key] = {"files": text, "truncated_files": skipped}c = cache[key]j = effective_judgment(rnd)@@ -178,14 +178,14 @@ def in_round_repair_pairs(ws: Workspace, rec: RunRecord, *, slug: str | None = Ncontinueif "repair attempts:" not in rnd.notes or "(fixed)" not in rnd.notes:continue- generated = _git.commit_by_subject(ws, f"r{rnd.index:02d} {rnd.kind}: generated")+ generated = git_history.commit_by_subject(ws, f"r{rnd.index:02d} {rnd.kind}: generated")if not generated or generated == rnd.commit or not ws.has_commit(generated):continuetry:- raw = _git.read_tree_at(ws, generated)- except _git.GitReadError:+ raw = git_history.read_tree_at(ws, generated)+ except git_history.GitReadError:continue- rej_files, rej_skipped = _git.decode_text_files(raw, max_total=MAX_INLINE_CODE)+ rej_files, rej_skipped = git_history.decode_text_files(raw, max_total=MAX_INLINE_CODE)chosen = _side(ws, rnd, cache=cache)if rej_files == chosen["files"]:continue # the repair changed nothing under the code rootsdiff --git a/harness/codeverse3d/addons/dataset/refine.py b/harness/codeverse3d/addons/dataset/refine.pyindex dfcc8a00..e0194732 100644--- a/harness/codeverse3d/addons/dataset/refine.py+++ b/harness/codeverse3d/addons/dataset/refine.py@@ -30,7 +30,12 @@ from pydantic import BaseModel, Fieldfrom codeverse3d.addons.dataset.pairs import MIN_PREFERENCE_DELTAfrom codeverse3d.contracts.artifacts import Severityfrom codeverse3d.contracts.run import RoundRecord, RunRecord-from codeverse3d.record._git import GitReadError, changed_files_between, diff_between, read_tree_at+from codeverse3d.record.git_history import (+ GitReadError,+ changed_files_between,+ diff_between,+ read_tree_at,+)from codeverse3d.record.record import (BATTERY_MARKERS,effective_judgment,diff --git a/harness/codeverse3d/addons/dataset/sample.py b/harness/codeverse3d/addons/dataset/sample.pyindex 5f1c3cca..12cacff3 100644--- a/harness/codeverse3d/addons/dataset/sample.py+++ b/harness/codeverse3d/addons/dataset/sample.py@@ -37,7 +37,7 @@ from codeverse3d.contracts.common import (code_file,)from codeverse3d.contracts.run import RoundRecord, RunRecord-from codeverse3d.record import _git+from codeverse3d.record import git_historyfrom codeverse3d.record.deliverable import deliverable_path, round_outputs, texture_shipped_forfrom codeverse3d.record.record import (effective_judgment,@@ -153,18 +153,18 @@ def code_files_for_round(ws: Workspace, rnd: RoundRecord | None) -> tuple[dict[s"""Raw code tree for a round → ``(files, source)`` where source is ``commit``,``deliverable`` (the packaged snapshot of the handed-over round) or ``working_tree``."""if rnd is not None and rnd.commit and ws.has_commit(rnd.commit):- return _git.read_tree_at(ws, rnd.commit), "commit"+ return git_history.read_tree_at(ws, rnd.commit), "commit"packaged = _deliverable_code(ws)if packaged:return packaged, "deliverable"- return _git.read_working_tree(ws), "working_tree"+ return git_history.read_working_tree(ws), "working_tree"def _deliverable_code(ws: Workspace) -> dict[str, bytes]:"""``deliverable/src|public/**`` — the snapshot kept when git is unreadable(a run copied without its .git, an archived deliverable)."""files: dict[str, bytes] = {}- for root in _git.CODE_ROOTS:+ for root in git_history.CODE_ROOTS:base = ws.deliverable / rootif not base.is_dir():continuediff --git a/harness/codeverse3d/record/__init__.py b/harness/codeverse3d/record/__init__.pyindex 096bc600..ada61c95 100644--- a/harness/codeverse3d/record/__init__.py+++ b/harness/codeverse3d/record/__init__.py@@ -4,7 +4,7 @@``effective_judgment`` · ``unique_files``* ``deliverable`` every round's kept build (``artifacts/rNN/``) and ``deliverable/`` for one round* ``telemetry`` the settings / environment a record carries-* ``_git`` reading the workspace's own git history (files at a round's commit)+* ``git_history`` reading the workspace's own git history (files at a round's commit)Turning a tree of finished runs into a dataset, a gallery or a cost report is ``codeverse3d.addons``."""diff --git a/harness/codeverse3d/record/deliverable.py b/harness/codeverse3d/record/deliverable.pyindex 5081d290..77670c13 100644--- a/harness/codeverse3d/record/deliverable.py+++ b/harness/codeverse3d/record/deliverable.py@@ -33,7 +33,7 @@ from pathlib import Pathfrom codeverse3d.contracts.common import ENTRY_FILE, Language, Trackfrom codeverse3d.contracts.run import DeliverableFile, RoundRecord, RunDeliverable, RunRecordfrom codeverse3d.proc import read_json_or_none, sha256_file, write_json_atomic-from codeverse3d.record import _git+from codeverse3d.record import git_historyfrom codeverse3d.workspace import Workspacelog = logging.getLogger(__name__)@@ -131,11 +131,11 @@ def _code_tree(ws: Workspace, rnd: RoundRecord | None) -> tuple[dict[str, bytes]if rnd is not None and rnd.commit:try:if ws.has_commit(rnd.commit):- return _git.read_tree_at(ws, rnd.commit), "commit"- except _git.GitReadError as e:+ return git_history.read_tree_at(ws, rnd.commit), "commit"+ except git_history.GitReadError as e:log.warning("deliverable: git read failed in %s: %s", ws.root, e)try:- return _git.read_working_tree(ws), "working_tree"+ return git_history.read_working_tree(ws), "working_tree"except OSError as e: # pragma: no cover - defensivelog.warning("deliverable: working tree unreadable in %s: %s", ws.root, e)return {}, "working_tree"diff --git a/harness/codeverse3d/record/_git.py b/harness/codeverse3d/record/git_history.pysimilarity index 100%rename from harness/codeverse3d/record/_git.pyrename to harness/codeverse3d/record/git_history.pydiff --git a/harness/codeverse3d/workspace.py b/harness/codeverse3d/workspace.pyindex 60cf68b4..c86d5e7a 100644--- a/harness/codeverse3d/workspace.py+++ b/harness/codeverse3d/workspace.py@@ -70,7 +70,7 @@ GIT_SAFE_FLAGS = ("-c", "core.hooksPath=/dev/null", "-c", "core.fsmonitor=false"#: in .git/config, both agent-writable — is not reachable by ``-c``, and ``--no-ext-diff``#: alone does not disable textconv: without ``--no-textconv`` that driver EXECUTES.GIT_SAFE_DIFF_FLAGS = ("--no-ext-diff", "--no-textconv")-#: a has_commit probe that has not answered by then answers no (record/_git.py reads use 60 s too)+#: a has_commit probe that has not answered by then answers no (record/git_history.py reads use 60 s too)HAS_COMMIT_TIMEOUT_S = 60#: local (.git/config) config that makes git EXECUTE a program. ``-c`` cannot override a#: local ``filter.*`` / ``diff.*`` driver, so these are unset in place before every commit.diff --git a/harness/docs/ARCHITECTURE.md b/harness/docs/ARCHITECTURE.mdindex b901ba28..99898ab1 100644--- a/harness/docs/ARCHITECTURE.md+++ b/harness/docs/ARCHITECTURE.md@@ -211,7 +211,7 @@ codeverse3d/record/ what every run WRITES: record.py (finalize_record, load_record, iter_runs,effective_judgment), deliverable.py (every round's kept build underartifacts/rNN/, and deliverable/ for ONE round — built by addons/select),- telemetry.py, _git.py (files at a round's commit)+ telemetry.py, git_history.py (files at a round's commit)addons/ optional tools that READ finished runs; outside cli/ nothing imports them(tests/core/test_addons_boundary.py). dataset/ = export.py, pack.py, pairs.py,refine.py, captions.py, index.py, sample.py, quality.py (tiers + code fingerprints +diff --git a/harness/docs/INTERFACES.md b/harness/docs/INTERFACES.mdindex b6ba6fe4..58a60a7b 100644--- a/harness/docs/INTERFACES.md+++ b/harness/docs/INTERFACES.md@@ -650,7 +650,7 @@ from codeverse3d.addons.dataset.refine import build_refine, transitions, RefineT# one row per round i -> i+1 the harness asked to change; outcome improved|regressed|unchanged|unscored# (threshold: pairs.MIN_PREFERENCE_DELTA); dropped rows carry the reason (no_predecessor / no_commit /# predecessor_build_failed / predecessor_unjudged / git_read_failed)-from codeverse3d.record._git import read_tree_at, diff_between, changed_files_between, GitReadError+from codeverse3d.record.git_history import read_tree_at, diff_between, changed_files_between, GitReadError# read_tree_at(ws, commit, *, paths=None) -> {path: bytes} via ls-tree + cat-file --batch — NEVER# `git archive`, which renders content through a planted filter.<name>.smudge and has no --no-filters# (tests/flywheel_cli); symlinks (mode 120000) are skipped; `paths` reads only those filesdiff --git a/harness/tests/flywheel_cli/test_flywheel.py b/harness/tests/flywheel_cli/test_flywheel.pyindex e953b58e..6c63fcfa 100644--- a/harness/tests/flywheel_cli/test_flywheel.py+++ b/harness/tests/flywheel_cli/test_flywheel.py@@ -10,7 +10,7 @@ import pytestfrom codeverse3d.addons import selectfrom codeverse3d.addons.dataset.export import export_samplesfrom codeverse3d.addons.dataset.pairs import build_pairs-from codeverse3d.record import _git+from codeverse3d.record import git_historyfrom codeverse3d.record.record import (RecordError,finalize_record,@@ -70,13 +70,13 @@ def test_iter_runs_and_errors(runs_dir: Path):def test_git_tree_at_commit(fake_run):ws, rec = fake_runc0, c1 = rec.rounds[0].commit, rec.rounds[1].commit- t0 = _git.read_tree_at(ws, c0)- t1 = _git.read_tree_at(ws, c1)+ t0 = git_history.read_tree_at(ws, c0)+ t1 = git_history.read_tree_at(ws, c1)assert set(t0) == {"src/model.py"}assert set(t1) == {"src/model.py", "src/parts/leg.py"}assert b"round 0" in t0["src/model.py"] and b"round 1" in t1["src/model.py"]- with pytest.raises(_git.GitReadError):- _git.read_tree_at(ws, "deadbeef")+ with pytest.raises(git_history.GitReadError):+ git_history.read_tree_at(ws, "deadbeef")def test_a_planted_diff_driver_never_runs(fake_run, tmp_path):@@ -94,8 +94,8 @@ def test_a_planted_diff_driver_never_runs(fake_run, tmp_path):ws._git("config", "--local", f"diff.evil.{key}", payload)ws._git("config", "--local", "diff.external", payload)- text, _total, _truncated = _git.diff_between(ws, before, after)- files = _git.changed_files_between(ws, before, after)+ text, _total, _truncated = git_history.diff_between(ws, before, after)+ files = git_history.changed_files_between(ws, before, after)assert not fired.exists(), f"a planted diff driver ran: {fired.read_text()!r}"assert files == ["src/blob.bin"] and "src/blob.bin" in text@@ -103,7 +103,7 @@ def test_a_planted_diff_driver_never_runs(fake_run, tmp_path):def test_a_symlink_is_not_exported_as_a_file_of_its_target(fake_run) -> None:"""ls-tree lists a symlink as a blob holding its target — never a file of the sample."""- from codeverse3d.record._git import read_tree_at+ from codeverse3d.record.git_history import read_tree_atws, _rec = fake_run(ws.src / "model.py").write_text("import bpy\n")@@ -127,7 +127,7 @@ def test_a_planted_smudge_filter_never_runs(fake_run, tmp_path):ws._git("config", "--local", "filter.evil.smudge", f"sh -c 'echo pwned >> {fired}; cat'")ws._git("config", "--local", "filter.evil.required", "false")- files = _git.read_tree_at(ws, commit)+ files = git_history.read_tree_at(ws, commit)assert not fired.exists(), f"a planted smudge filter ran: {fired.read_text()!r}"assert files["src/model.py"] == b"# real content\n" # the raw blob, unfiltered@@ -137,12 +137,12 @@ def test_diff_between_refuses_a_sha_the_repo_does_not_have(fake_run):"""A sha the repository no longer holds raises rather than diffing against an empty tree."""ws, rec = fake_rungood = rec.rounds[1].commit- with pytest.raises(_git.GitReadError):- _git.diff_between(ws, "0" * 40, good)- with pytest.raises(_git.GitReadError):- _git.diff_between(ws, good, "0" * 40)- with pytest.raises(_git.GitReadError):- _git.changed_files_between(ws, good, "0" * 40)+ with pytest.raises(git_history.GitReadError):+ git_history.diff_between(ws, "0" * 40, good)+ with pytest.raises(git_history.GitReadError):+ git_history.diff_between(ws, good, "0" * 40)+ with pytest.raises(git_history.GitReadError):+ git_history.changed_files_between(ws, good, "0" * 40)# --------------------------------------------------------------------------- export + pack