Official Codebase of 3DCodeVerse
Python
prompts: stop truncating, by byte offset, the material we wrote for the model
gaoypeng8c60f504d98e
diff --git a/harness/codeverse/tracks/graphics.py b/harness/codeverse/tracks/graphics.pyindex 122a17c5..0a533842 100644--- a/harness/codeverse/tracks/graphics.py+++ b/harness/codeverse/tracks/graphics.py@@ -51,7 +51,6 @@ from codeverse.tracks.prompting import (reference_images,reference_note,select_cookbook_chapters,- select_cookbook_excerpt,skeleton_files,)from codeverse.workspace import Workspace@@ -361,7 +360,7 @@ def graphics_prompt_context(ctx: RunContext, **extra: Any) -> dict[str, Any]:res = plan.resolution if plan else (1280, 720)d: dict[str, Any] = {"track": ctx.track.value, "language": ctx.language.value, "contract": ctx.contract_text,- "cookbook_rel": ctx.cookbook_rel, "cookbook_excerpt": select_cookbook_excerpt(ctx, graphics_brief(ctx)), "tool_cards": ctx.tool_cards,+ "cookbook_rel": ctx.cookbook_rel, "cookbook_excerpt": ctx.cookbook_text, "tool_cards": ctx.tool_cards,# the recipes tracks/graphics_recipes.py put in the harness-owned src/recipes.glsl before the session ([] = no block)"seeded_recipes": list((getattr(ctx, "extra", None) or {}).get(EXTRA_KEY) or []),"single_shot": ctx.single_shot, "output_format": SINGLE_SHOT_FORMAT if ctx.single_shot else AGENT_OUTPUT_RULES,diff --git a/harness/codeverse/tracks/planner.py b/harness/codeverse/tracks/planner.pyindex 475e77fa..c23814e8 100644--- a/harness/codeverse/tracks/planner.py+++ b/harness/codeverse/tracks/planner.py@@ -798,7 +798,7 @@ def build_system_prompt(spec: Spec, plan_model: type[BaseModel], *, runtime: Anytrack=spec.track.value,language=lang.value,frame_doc=frame_doc(LANGUAGE_FRAME[lang.value]),- contract=language_contract(lang, runtime)[:6000],+ contract=language_contract(lang, runtime),example_json=json.dumps(example if example is not None else plan_example(spec.track), indent=1),schema_fields=", ".join(plan_model.model_json_schema().get("properties", {}).keys()),target_parts=budget.target_parts,diff --git a/harness/codeverse/tracks/prompting.py b/harness/codeverse/tracks/prompting.pyindex 2075c8a7..5ab0f869 100644--- a/harness/codeverse/tracks/prompting.py+++ b/harness/codeverse/tracks/prompting.py@@ -275,7 +275,12 @@ def base_prompt_context(ctx: RunContext, **extra: Any) -> dict[str, Any]:"frame_doc": frame_doc(LANGUAGE_FRAME[ctx.language.value]),"contract": ctx.contract_text,"cookbook_rel": ctx.cookbook_rel,- "cookbook_excerpt": ctx.cookbook_text[:6000],+ # the whole cookbook. It used to be ctx.cookbook_text[:6000] — a blind byte+ # prefix that delivered 13 % of blender's and 10 % of scene_threejs's, cutting+ # mid-snippet, and the read_cookbook tool that was supposed to fetch the rest+ # went uncalled in all 20 measured sessions. Prompt material the harness wrote+ # for the model is not summarised by byte offset.+ "cookbook_excerpt": ctx.cookbook_text,"tool_cards": ctx.tool_cards,"single_shot": ctx.single_shot,"output_format": SINGLE_SHOT_FORMAT if ctx.single_shot else AGENT_OUTPUT_RULES,diff --git a/harness/codeverse/tracks/repair.py b/harness/codeverse/tracks/repair.pyindex 242acea5..a3a64118 100644--- a/harness/codeverse/tracks/repair.py+++ b/harness/codeverse/tracks/repair.py@@ -85,7 +85,7 @@ _HEADING = re.compile(r"^##+ .+$", re.M)_WORD = re.compile(r"[A-Za-z_][A-Za-z0-9_]{3,}")-def relevant_cookbook_section(cookbook: str, error_text: str, *, max_chars: int = 3000) -> str:+def relevant_cookbook_section(cookbook: str, error_text: str, *, max_chars: int = 12000) -> str:"""Pick the cookbook ``##`` section sharing the most identifiers with the error."""if not cookbook or not error_text:return ""@@ -201,4 +201,4 @@ def make_repair_task(ctx: RunContext, build: BuildResult, lint: GateReport, *, rdef _repair_system(ctx: RunContext) -> str:return (f"You repair {ctx.language.value} code that failed to build. Fix only the reported error(s) with the smallest "- f"correct change; keep every part, name and dimension. {ctx.contract_text[:4000]}")+ f"correct change; keep every part, name and dimension. {ctx.contract_text}")diff --git a/harness/tests/orchestrator_tracks/test_cookbook_excerpt.py b/harness/tests/orchestrator_tracks/test_cookbook_excerpt.pyindex ad7736dd..dc7391a0 100644--- a/harness/tests/orchestrator_tracks/test_cookbook_excerpt.py+++ b/harness/tests/orchestrator_tracks/test_cookbook_excerpt.py@@ -90,26 +90,37 @@ def test_budget_never_cuts_a_chapter() -> None:assert any(t.startswith("Gradient sky") for t in _titles(small)) # the 1.3 k chapter that does-def test_graphics_prompt_context_uses_the_selector(monkeypatch) -> None:+def test_every_track_sends_the_whole_cookbook(monkeypatch) -> None:+ """No track delivers the cookbook by byte offset any more.++ It used to be ``ctx.cookbook_text[:6000]`` in base_prompt_context and a 9 000-char+ chapter selection in graphics — 13 % of blender's 46 623 chars, 10 % of+ scene_threejs's 57 631, cut mid-snippet. The read_cookbook tool was the stated+ escape hatch and went uncalled in all 20 measured sessions, so what the prefix left+ out simply never reached the model. Chapter SELECTION is still right where the+ stage knows which chapters it needs (scene's env/zone recipes, graphics' recipe+ seeding); it is not right as a way to shrink the reference itself.+ """from codeverse.tracks import graphics as graphics_steps+ from codeverse.tracks.prompting import base_prompt_context- seen: dict[str, str] = {}-- def fake(ctx, brief, **kw):- seen["brief"] = brief- return "EXCERPT"-- monkeypatch.setattr(graphics_steps, "select_cookbook_excerpt", fake)- ctx = SimpleNamespace(plan=None, spec=SimpleNamespace(prompt="an aurora", constraints=None, must=[], must_not=[], dims={},- reference_images=[], reference_notes=""),+ big = "\n\n".join(f"## chapter {i}\n" + "x" * 4000 for i in range(20)) # ~80 000 chars+ ctx = SimpleNamespace(plan=None, spec=SimpleNamespace(prompt="an aurora", constraints=None, must=[], must_not=[],+ dims={}, reference_images=[], reference_notes=""),track=Track.GRAPHICS, language=Language.GLSL_SHADER,- contract_text="", cookbook_rel="", cookbook_text="", tool_cards="", single_shot=True,+ contract_text="CONTRACT", cookbook_rel="glsl_shader/cookbook.md",+ cookbook_text=big, tool_cards="", single_shot=True,runtime=SimpleNamespace(entry_globs=()))monkeypatch.setattr(graphics_steps, "constraints_text", lambda spec: "")monkeypatch.setattr(graphics_steps, "reference_note", lambda ctx: "")monkeypatch.setattr(graphics_steps, "acceptance_lines", lambda plan: "")- d = graphics_steps.graphics_prompt_context(ctx)- assert d["cookbook_excerpt"] == "EXCERPT" and seen["brief"].startswith("an aurora")+ assert graphics_steps.graphics_prompt_context(ctx)["cookbook_excerpt"] == big++ monkeypatch.setattr("codeverse.tracks.prompting.constraints_text", lambda spec: "")+ monkeypatch.setattr("codeverse.tracks.prompting.reference_note", lambda ctx: "")+ monkeypatch.setattr("codeverse.tracks.prompting.acceptance_lines", lambda plan: "")+ assert base_prompt_context(ctx)["cookbook_excerpt"] == big+ assert base_prompt_context(ctx)["contract"] == "CONTRACT"def test_aurora_example_ships_and_composes() -> None: