Official Codebase of 3DCodeVerse
Python
prompts: the CV3D_LEAN_PROMPT review — narrow the parts table only on all-part rounds
ziyao08e9d4085b3e
diff --git a/harness/codeverse/agents/materialize.py b/harness/codeverse/agents/materialize.pyindex bb97b21a..aa6b68cc 100644--- a/harness/codeverse/agents/materialize.py+++ b/harness/codeverse/agents/materialize.py@@ -44,6 +44,11 @@ log = logging.getLogger(__name__)CV3D_DIR = ".3dcv" # harness-owned read-only docs inside the workspaceMCP_SERVER_NAME = "3dcv"MCP_TOOL_TIMEOUT_MS = 600_000+#: backends that get NO MCP server, so the 3dcv tools never appear as declarations in the+#: session's own tool list — this file's ``_tool_section`` is their only tool documentation+#: and they call the tools from the shell. A prompt may point at "your tool list" only for+#: the kinds NOT in here (``tracks/prompting.tools_declared``).+MCPLESS_KINDS: frozenset[str] = frozenset({"agy"})#: ``.geminiignore`` / ``.aiexclude`` — gemini-cli's read_file/glob REFUSE ignored paths, so the#: agent-facing artefacts must stay readable: ``artifacts/*.json`` (the build tool advertises#: ``census.json`` etc.), ``artifacts/tool_renders/`` and ``trajectories/<label>_rNN/task_prompt.md``@@ -87,7 +92,7 @@ def _tool_section(agent_kind: str, spatial_tools: bool, mcp_command: list[str],prove = [n for n in ("measure", "check_contract", "scene_probe", "gl_probe") if n in names]if agent_kind == "claude-code":how = "Tools are exposed by the MCP server `3dcv`; their names appear as `mcp__c3v__<name>` (e.g. `mcp__c3v__build`)."- elif agent_kind == "agy":+ elif agent_kind in MCPLESS_KINDS:how = ("This session has no MCP server. Call a tool from the shell instead:\n""`python -m codeverse.cli.main tools <name> --json '{\"arg\": \"value\"}'` "diff --git a/harness/codeverse/config.py b/harness/codeverse/config.pyindex dbd5b61a..05e76947 100644--- a/harness/codeverse/config.py+++ b/harness/codeverse/config.py@@ -115,8 +115,9 @@ class Limits(BaseModel):"(7 150 chars) rides in the baseline prompt AND byte-for-byte in the materialised ""AGENTS.md/GEMINI.md; the tool list arrives three times (prompt 4 088 + GEMINI.md + ""the MCP declarations); the whole 24 k cookbook is inlined though a brief-driven "- "chapter selector exists; and a refine prompt carries all acceptance items and all "- "part rows for a median of 3 targets. OFF until the A/B reads out; "+ "chapter selector exists; and a refine prompt (median 18 604 chars over the 48 "+ "recorded there) carries all 20 acceptance items when 6 failed, and every part row "+ "for a median of 4 targets. OFF until the A/B reads out; ""`CV3D_LEAN_PROMPT=1` (read at call time by `lean_prompt_enabled`) is the variant arm.",)diff --git a/harness/codeverse/orchestrator.py b/harness/codeverse/orchestrator.pyindex 18b41ff6..6d6b4c01 100644--- a/harness/codeverse/orchestrator.py+++ b/harness/codeverse/orchestrator.py@@ -373,7 +373,7 @@ def compact_instructions(tasks: Sequence[RefineTask], max_lines: int = 6) -> lisreturn []groups: dict[str, list[RefineTask]] = {}for t in sorted(tasks, key=lambda t: t.priority):- groups.setdefault(_instance_base(t.target), []).append(t)+ groups.setdefault(instance_base(t.target), []).append(t)lines: list[str] = []for target, members in groups.items():if len(members) == 1:@@ -403,7 +403,12 @@ def _split_instance(target: str) -> tuple[str, str]:return target or "overall", ""-def _instance_base(target: str) -> str:+def instance_base(target: str) -> str:+ """The plan name behind a refine target: ``Leg_1`` → ``Leg``, anything else unchanged.++ ``_canon_target`` keeps the suffix, so every consumer that matches a target against+ plan part names has to strip it here rather than inventing its own rule+ (``tracks/prompting.parts_table_for_targets`` is the other one)."""return _split_instance(target)[0]diff --git a/harness/codeverse/prompts/tracks/generate_articulated.j2 b/harness/codeverse/prompts/tracks/generate_articulated.j2index 5479618a..6a74d94f 100644--- a/harness/codeverse/prompts/tracks/generate_articulated.j2+++ b/harness/codeverse/prompts/tracks/generate_articulated.j2@@ -17,8 +17,9 @@ Constraints:{{ frame_doc }}{% if lean %}The language contract is already in this workspace's agent instructions file (`AGENTS.md` =-`GEMINI.md` = `CLAUDE.md`, loaded for you), and your 3dcv tools are declared in your tool-list — read them there; neither is repeated below.+`GEMINI.md` = `CLAUDE.md`, loaded for you){% if tools_declared %}, and your 3dcv tools are declared in your+tool list{% else %}, which is also where your 3dcv tools are documented — this session has no MCP server,+so you call them from the shell as that file shows{% endif %} — read them there; neither is repeated below.{% else %}{{ contract }}{% endif %}diff --git a/harness/codeverse/prompts/tracks/refine_object.j2 b/harness/codeverse/prompts/tracks/refine_object.j2index 017e12e6..e5d2ad20 100644--- a/harness/codeverse/prompts/tracks/refine_object.j2+++ b/harness/codeverse/prompts/tracks/refine_object.j2@@ -33,8 +33,13 @@ Files in scope: {% for f in files %}`{{ f }}`{% if not loop.last %}, {% endif %}## Plan rows for the targets (bbox centre/extents in meters — the truth to converge to){{ parts_table }}-## Acceptance checklist (unchanged)+## Acceptance checklist{% if not lean %} (unchanged){% endif %}+{{ acceptance }}+{% if plan_pointer %}++{{ plan_pointer }}+{% endif %}## Detail budget{{ detail_budget }}diff --git a/harness/codeverse/tracks/prompting.py b/harness/codeverse/tracks/prompting.pyindex f8520272..a9d554d0 100644--- a/harness/codeverse/tracks/prompting.py+++ b/harness/codeverse/tracks/prompting.py@@ -19,6 +19,7 @@ from codeverse.contracts.common import HARNESS_OWNED_SRC, Language, Trackfrom codeverse.contracts.plan import Plan, StaticPlanfrom codeverse.contracts.run import RoundRecordfrom codeverse.conventions import LANGUAGE_FRAME, Frame, frame_doc, to_snake+from codeverse.orchestrator import instance_basefrom codeverse.prompts import renderfrom codeverse.prompts.catalog import prompt_dir_forfrom codeverse.tracks.common import RunContext@@ -291,6 +292,18 @@ def lean_prompt(ctx: RunContext) -> bool:and lean_prompt_enabled())+def tools_declared(ctx: RunContext) -> bool:+ """Does this session see the 3dcv tools as declarations of its own?++ True for every backend the harness gives an MCP server; false for the mcp-less ones+ (:data:`agents.materialize.MCPLESS_KINDS`), whose materialised instructions say the+ opposite — "This session has no MCP server", call them from the shell. A prompt that+ drops the tool cards has to point at whichever of the two the session actually got."""+ from codeverse.agents.materialize import MCPLESS_KINDS # local: tracks -> agents stays lazy++ return ctx.agent_kind not in MCPLESS_KINDS++def articulated_brief(ctx: RunContext) -> str:"""What ranks the cookbook's worked examples: the request plus the plan's own vocabulary.@@ -327,9 +340,11 @@ def acceptance_lines_focused(plan: Plan | None, failed: Sequence[Any]) -> str:"""Acceptance for a refine prompt: the FAILED items in full, the rest as their ids.A refine round is told to change exactly the listed targets, so the items that already- pass are there to be preserved, not re-read — one id line each says that in 4 % of the- chars. Empty ``failed`` (no judgment, or everything passed) keeps the full list: with- nothing to focus on, focusing would only remove information."""+ pass are there to be preserved, not re-read — one id line each says that in a third of+ the chars (median 2 625 -> 885 over the 48 recorded refine prompts of aa_articulated:+ 20 items, 6 of them failed on the round that precedes the prompt). Empty ``failed``+ (no judgment, or everything passed) keeps the full list: with nothing to focus on,+ focusing would only remove information."""items = getattr(plan, "acceptance", None) or []ids = {getattr(a, "id", "") for a in failed}if not items or not ids:@@ -342,24 +357,47 @@ def acceptance_lines_focused(plan: Plan | None, failed: Sequence[Any]) -> str:def parts_table_for_targets(plan: Plan | None, targets: Sequence[str]) -> str:- """The plan rows for the refine targets — the whole table when none of them is a part.+ """The plan rows for the refine targets — the whole table unless EVERY target is a part.The template's heading has always said "Plan rows for the targets"; the table under it- was every part in the plan (1 605 chars for a median of 3 targets, aa_articulated)."""- keys = {to_snake(t) for t in targets}- scoped = [p for p in (getattr(plan, "parts", None) or ()) if to_snake(p.name) in keys]- return parts_table_for(scoped) if scoped else parts_table(plan)+ was every part in the plan (median 1 532 chars over the 48 recorded refine prompts of+ aa_articulated). Narrowing is only honest when the round is ABOUT those parts: a group+ that also carries the whole-artifact target (``overall`` — where a gate error with no+ part of its own lands) is about the assembly, and an assembly is judged against rows+ this would have dropped. That is most rounds — 39 of those 48 prompts carry ``overall``+ and only 4 narrow — which is the price of not lying about what the table is. Instance+ suffixes come off first: ``_canon_target`` hands on the plan's spelling but keeps the+ ``Leg_1``, and the plan has no such row."""+ keys = {to_snake(instance_base(t)) for t in targets}+ parts = list(getattr(plan, "parts", None) or ())+ if not keys or not keys <= {to_snake(p.name) for p in parts}:+ return parts_table(plan)+ return parts_table_for([p for p in parts if to_snake(p.name) in keys])def refine_focus(ctx: RunContext, last: RoundRecord, targets: Sequence[str]) -> dict[str, Any]:"""Refine-prompt overrides under the lean switch: focused acceptance + targeted parts.- ``{}`` when the switch is off, so the control arm renders byte-identically."""+ ``{}`` when the switch is off, so the control arm renders byte-identically.++ Whatever is dropped gets a pointer to ``plan.json``, which is in the workspace and is+ neither git- nor agent-ignored. Measured precedent says the model will not fetch it+ (the ``read_cookbook`` tool went uncalled in all 20 sessions of the excerpt study), so+ the pointer buys nothing when nothing was dropped — hence it names only what actually+ went, and is empty when the two helpers returned the full text anyway."""if not lean_prompt(ctx):return {}from codeverse.tracks.steps import failed_acceptance # local: steps -> repair -> here- return {"acceptance": acceptance_lines_focused(ctx.plan, failed_acceptance(ctx, last.judgment)),- "parts_table": parts_table_for_targets(ctx.plan, targets)}+ acceptance = acceptance_lines_focused(ctx.plan, failed_acceptance(ctx, last.judgment))+ parts = parts_table_for_targets(ctx.plan, targets)+ dropped: list[str] = []+ if acceptance != acceptance_lines(ctx.plan):+ dropped.append("the text of the acceptance items listed by id only")+ if parts != parts_table(ctx.plan):+ dropped.append("the rows of the parts this round does not name")+ pointer = (f"Elided from this prompt and readable in `{ctx.ws.plan_path.name}` at the workspace "+ f"root: {'; '.join(dropped)}." if dropped else "")+ return {"acceptance": acceptance, "parts_table": parts, "plan_pointer": pointer}def language_system_prompt(language: Language, *, role: str = "", tools: bool = True, **vars: Any) -> str:@@ -407,8 +445,13 @@ def base_prompt_context(ctx: RunContext, **extra: Any) -> dict[str, Any]:"cookbook_excerpt": cookbook_excerpt(ctx, lean=lean),"tool_cards": ctx.tool_cards,"single_shot": ctx.single_shot,- # templates drop with it only what the workspace already carries (see lean_prompt)+ # templates drop with it only what the workspace already carries (see lean_prompt),+ # and say where it went: the tools in the session's own declarations or, for an+ # mcp-less backend, in the instructions file; the elided plan material in plan.json+ # (refine only, so "" here — refine_focus fills it when something was actually cut)"lean": lean,+ "tools_declared": tools_declared(ctx),+ "plan_pointer": "","output_format": SINGLE_SHOT_FORMAT if ctx.single_shot else AGENT_OUTPUT_RULES,"spec_prompt": ctx.spec.prompt,"constraints": constraints_text(ctx.spec),diff --git a/harness/codeverse/tracks/static_object.py b/harness/codeverse/tracks/static_object.pyindex 4e5c09d8..36d998eb 100644--- a/harness/codeverse/tracks/static_object.py+++ b/harness/codeverse/tracks/static_object.py@@ -349,8 +349,9 @@ class StaticObjectTrack(BaseTrack):# set is ≤ 3 files / ≤ 12 k chars — the first turn is then the editcurrent_files=refine_inline_files(ctx, files, scoped=scoped),# lean switch only, {} when off: the failed acceptance items in full with- # the rest as ids, and the plan rows the heading already promises — this- # group's targets, not every part in the plan+ # the rest as ids, the plan rows the heading already promises (this group's+ # targets, when every one of them IS a part), and a pointer to plan.json+ # for whatever that dropped**refine_focus(ctx, last, group.targets),),)diff --git a/harness/tests/orchestrator_tracks/test_cookbook_excerpt.py b/harness/tests/orchestrator_tracks/test_cookbook_excerpt.pyindex 1c4ae1fd..961bfe5c 100644--- a/harness/tests/orchestrator_tracks/test_cookbook_excerpt.py+++ b/harness/tests/orchestrator_tracks/test_cookbook_excerpt.py@@ -46,7 +46,7 @@ def test_every_track_sends_the_whole_cookbook(monkeypatch) -> None:dims={}, reference_images=[], reference_notes=""),track=Track.GRAPHICS, language=Language.GLSL_SHADER,contract_text="CONTRACT", cookbook_rel="glsl_shader/cookbook.md",- cookbook_text=big, tool_cards="", single_shot=True, extra={},+ cookbook_text=big, tool_cards="", single_shot=True, agent_kind="single-shot", extra={},runtime=SimpleNamespace(entry_globs=()))monkeypatch.setattr(graphics_steps, "constraints_text", lambda spec: "")monkeypatch.setattr(graphics_steps, "reference_note", lambda ctx: "")diff --git a/harness/tests/orchestrator_tracks/test_lean_prompt.py b/harness/tests/orchestrator_tracks/test_lean_prompt.pyindex 7248dfb9..be798dc9 100644--- a/harness/tests/orchestrator_tracks/test_lean_prompt.py+++ b/harness/tests/orchestrator_tracks/test_lean_prompt.py@@ -3,8 +3,9 @@Measured on aa_articulated (2026-09-02, prompts dated 2026-09-01): the baseline prompt is53 562 chars and the CLI additionally loads GEMINI.md (18 444 B) plus 6 618 chars of MCP tooldeclarations on EVERY turn — with prompts/urdf/contract.md in both GEMINI.md and the prompt,-the tool list in all three, the whole 24 k cookbook inlined, and a refine prompt carrying all-26 acceptance items and all 9 part rows for a median of 3 targets.+the tool list in all three, the whole 24 k cookbook inlined, and a refine prompt (median+18 604 chars over the 48 recorded there) carrying all 20 acceptance items when 6 had failed,+and every part row for a median of 4 targets.The switch is an A/B arm, so the control must be untouched: every test here renders the SAMEcontext twice and the OFF arm has to come out byte-identical to what a caller that never heard@@ -13,7 +14,11 @@ of ``lean`` produces.from __future__ import annotations+import subprocess+from pathlib import Path+import pytest+from jinja2 import ChoiceLoader, DictLoader, FileSystemLoaderfrom codeverse.config import LEAN_PROMPT_ENV, Settings, get_settings, lean_prompt_enabledfrom codeverse.contracts.artifacts import Judgment@@ -22,7 +27,8 @@ from codeverse.contracts.plan import ArticulatedPlanfrom codeverse.contracts.run import RoundRecordfrom codeverse.orchestrator import BudgetGuard, RefineTask, RoundPolicy, RunState, TaskGroupfrom codeverse.proc import EventLog-from codeverse.prompts import load_text, render+from codeverse.prompts import PROMPTS_DIR, _env, load_text, render+from codeverse.tracks.articulated_object import ArticulatedObjectTrackfrom codeverse.tracks.common import RunContext, Services, cookbook_rel_for, language_contractfrom codeverse.tracks.plan_features import GENERATION_SIDE_ENV, LIVE_SWITCHESfrom codeverse.tracks.planner import plan_example@@ -42,6 +48,12 @@ GENERATE = "tracks/generate_articulated.j2"REFINE = "tracks/refine_object.j2"DETAIL = "tracks/detail_object.j2"+#: the last commit before ``CV3D_LEAN_PROMPT`` existed. Pinned by sha on purpose: the value+#: of this reference is that it does NOT move with the branch — it is the literal template a+#: caller that never heard of ``lean`` rendered.+PRE_LEAN = "ee38e5d375fd4900f45ff8e1a20f5cdb464ddace"+HARNESS = Path(__file__).resolve().parents[2]+def _ctx(tmp_path, *, track=Track.ARTICULATED_OBJECT, language=Language.URDF_BLENDER,agent_id="gemini-cli:gemini-3.7-flash") -> RunContext:@@ -62,6 +74,37 @@ def _ctx(tmp_path, *, track=Track.ARTICULATED_OBJECT, language=Language.URDF_BLEreturn ctx+def _track_ctx(tmp_path, *, agent_id="gemini-cli:gemini-3.7-flash") -> tuple[ArticulatedObjectTrack, RunContext]:+ """The REAL track and the context it builds — the production path into ``_refine_task``."""+ ws = Workspace(tmp_path / "run").create()+ settings = Settings(runs_dir=tmp_path / "runs", cache_dir=tmp_path / "cache")+ track = ArticulatedObjectTrack(services=FakeServices(), settings=settings,+ runtime=FakeRuntime(Language.URDF_BLENDER))+ spec = make_spec(Track.ARTICULATED_OBJECT, Language.URDF_BLENDER, generator=agent_id,+ prompt="a desk drawer unit with one sliding drawer")+ ctx = track.build_context(spec, ws, EventLog(ws.events_path), RunState(slug="d"))+ ctx.plan = ArticulatedPlan.model_validate(plan_example(Track.ARTICULATED_OBJECT))+ return track, ctx+++def _pre_lean_templates():+ """The three templates as of :data:`PRE_LEAN`, in the STRICT prompt environment.++ ``prompts.render`` falls back to a lenient environment when a template wants a name its+ caller does not pass — under that fallback an unknown ``lean`` renders as empty, i.e. as+ the OFF arm, and a reversibility test would pass for the wrong reason. Overlaying the+ real environment keeps the settings that decide the bytes (trim_blocks, lstrip_blocks,+ keep_trailing_newline)."""+ srcs: dict[str, str] = {}+ for rel in (GENERATE, REFINE, DETAIL):+ out = subprocess.run(["git", "show", f"{PRE_LEAN}:./codeverse/prompts/{rel}"],+ cwd=HARNESS, capture_output=True, text=True, check=False)+ if out.returncode:+ pytest.skip(f"no git object {PRE_LEAN} here: {out.stderr.strip()}")+ srcs[rel] = out.stdout+ return _env.overlay(loader=ChoiceLoader([DictLoader(srcs), FileSystemLoader(str(PROMPTS_DIR))]))++def _last() -> RoundRecord:return RoundRecord(index=1, kind="baseline", judgment=Judgment(rubric="articulated_v1", overall=0.62, passed=False, summary="drawer face sits proud",@@ -74,6 +117,16 @@ def _group() -> TaskGroup:files=["src/model.py"])], files=["src/model.py"])+def _rows(table: str) -> list[str]:+ """The part names of a rendered parts table, header row and rule dropped."""+ rows = [r for r in table.splitlines() if r.startswith("| ") and "|---" not in r]+ return [r.split("|")[1].strip() for r in rows][1:]+++#: plan_example's DeskDrawerUnit has exactly these parts, in this order+ALL_ROWS = ["Cabinet", "Drawer"]++def _contexts(ctx: RunContext) -> dict[str, dict]:"""The three per-turn prompt contexts of an articulated round, as the track builds them."""last, group = _last(), _group()@@ -125,22 +178,30 @@ def test_only_an_articulated_agent_session_is_lean(tmp_path, monkeypatch):# --------------------------------------------------------------------------- reversibility+#: the names the switch added to every prompt context; the pre-lean templates use none of them+LEAN_VARS = ("lean", "tools_declared", "plan_pointer")++@pytest.mark.parametrize("rel", [GENERATE, REFINE, DETAIL])-def test_the_off_arm_is_byte_identical_to_the_prompt_without_the_switch(tmp_path, monkeypatch, rel):+def test_the_off_arm_is_byte_identical_to_the_prompt_before_the_switch(tmp_path, monkeypatch, rel):"""The control arm must be TODAY's prompt, not a re-flowed version of it.- The reference is the same context with ``lean`` removed — literally what every caller- passed before this switch existed, and what the templates then rendered."""+ The reference is the template FILE as of :data:`PRE_LEAN`, rendered strictly with the+ same context minus the names the switch introduced — what a caller that never heard of+ ``lean`` passed, and what the templates then rendered, byte for byte."""monkeypatch.delenv(LEAN_PROMPT_ENV, raising=False)ctx = _ctx(tmp_path)vars_ = _contexts(ctx)[rel]- assert vars_["lean"] is False- before = dict(vars_)- before.pop("lean")- assert render(rel, **vars_) == render(rel, **before)+ assert vars_["lean"] is False and vars_["plan_pointer"] == ""+ before = {k: v for k, v in vars_.items() if k not in LEAN_VARS}+ today = _env.get_template(rel).render(**vars_) # strict: no lenient fallback to hide a rename+ assert render(rel, **vars_) == today # ...and that is what production renders+ assert today == _pre_lean_templates().get_template(rel).render(**before)-#: measured with this fixture (plan_example's DeskDrawerUnit): 18 504 / 4 295 / 4 098 chars+#: measured with this fixture (plan_example's DeskDrawerUnit): 18 504 / 4 131 / 4 098 chars.+#: A fixture is not the corpus — what one refine prompt of the aa_articulated battery saves is+#: in the commit message, and it is smaller (its rounds mostly keep the whole parts table).@pytest.mark.parametrize(("rel", "floor"), [(GENERATE, 16_000), (REFINE, 3_800), (DETAIL, 3_600)])def test_the_lean_arm_is_smaller_and_keeps_the_unique_material(tmp_path, monkeypatch, rel, floor):monkeypatch.delenv(LEAN_PROMPT_ENV, raising=False)@@ -206,13 +267,90 @@ def test_refine_shows_the_failed_acceptance_in_full_and_only_the_targeted_parts(assert "[j1] (must, articulation) Drawer slides out" in focus["acceptance"]assert "already verified, keep them true: a1, a2" in focus["acceptance"]assert "Seat top at 0.45 m" not in focus["acceptance"]- rows = [r for r in focus["parts_table"].splitlines() if r.startswith("| ") and "|---" not in r]- assert [r.split("|")[1].strip() for r in rows] == ["part", "Drawer"]- # a target that is not a part (the judge's "overall") falls back to the whole table- whole = refine_focus(ctx, _last(), ["overall"])["parts_table"]- assert "| Cabinet | fixed carcass" in whole and "| Drawer |" in whole+ assert _rows(focus["parts_table"]) == ["Drawer"]# nothing failed → nothing to focus on, so the full checklist standspassed = RoundRecord(index=1, kind="baseline", judgment=Judgment(rubric="articulated_v1", overall=0.9, passed=True, summary="ok", scores={},acceptance_results={"a1": True, "j1": True}))assert "Seat top at 0.45 m" in refine_focus(ctx, passed, ["Drawer"])["acceptance"]++[email protected](("targets", "rows"), [+ (["Drawer"], ["Drawer"]),+ (["Drawer", "Cabinet"], ALL_ROWS), # narrowed to both, which happens to be all of them+ (["Drawer_1"], ["Drawer"]), # _canon_target keeps the instance suffix; the plan has no such row+ (["drawer"], ["Drawer"]), # the match is on to_snake, not on spelling+ (["overall"], ALL_ROWS), # the whole artifact+ (["Drawer", "overall"], ALL_ROWS), # ...even next to a part+ (["overall", "Drawer"], ALL_ROWS), # ...in either order+ (["Hinge"], ALL_ROWS), # a target the plan does not know+ ([], ALL_ROWS), # no targets at all is not "no rows"+])+def test_the_parts_table_narrows_only_when_every_target_is_a_part(tmp_path, monkeypatch, targets, rows):+ """A group carrying the whole-artifact target is about the assembly, and an assembly is+ judged against the rows narrowing would drop, so ONE non-part target keeps the table whole."""+ monkeypatch.setenv(LEAN_PROMPT_ENV, "1")+ assert _rows(refine_focus(_ctx(tmp_path), _last(), targets)["parts_table"]) == rows+++def test_what_was_elided_points_at_plan_json_and_the_heading_stops_saying_unchanged(tmp_path, monkeypatch):+ """Material the model must fetch is never fetched (the read_cookbook study), so the pointer+ is not a promise — but a checklist rewritten to ids while its heading says "(unchanged)"+ is a lie, and a prompt that drops rows without naming the file holding them is a dead end.+ The pointer names only what actually went: with nothing failed and no part target, nothing+ is dropped and there is no pointer."""+ monkeypatch.setenv(LEAN_PROMPT_ENV, "1")+ ctx = _ctx(tmp_path)+ both = refine_focus(ctx, _last(), ["Drawer"])["plan_pointer"]+ assert "`plan.json`" in both and ctx.ws.plan_path.name == "plan.json"+ assert "acceptance items listed by id" in both and "parts this round does not name" in both+ kept = refine_focus(ctx, _last(), ["overall"])["plan_pointer"]+ assert "acceptance items listed by id" in kept and "does not name" not in kept+ passed = RoundRecord(index=1, kind="baseline", judgment=Judgment(+ rubric="articulated_v1", overall=0.9, passed=True, summary="ok", scores={},+ acceptance_results={"a1": True, "j1": True}))+ assert refine_focus(ctx, passed, ["overall"])["plan_pointer"] == ""++ monkeypatch.delenv(LEAN_PROMPT_ENV)+ get_settings.cache_clear()+ off = _prompts(_ctx(tmp_path / "off"))[REFINE]+ monkeypatch.setenv(LEAN_PROMPT_ENV, "1")+ on = _prompts(_ctx(tmp_path / "on"))[REFINE]+ # ("plan.json" alone is no evidence: check_contract's tool card names it too)+ assert "## Acceptance checklist (unchanged)" in off and "Elided from this prompt" not in off+ assert "## Acceptance checklist\n" in on and "(unchanged)" not in on+ assert both in on+++def test_the_pointer_names_the_tool_channel_this_backend_actually_got(tmp_path, monkeypatch):+ """agy has no MCP server: `agents/materialize._tool_section` tells it the tools are shell+ calls documented in that same file, so "declared in your tool list" would be false."""+ monkeypatch.setenv(LEAN_PROMPT_ENV, "1")+ mcp = _prompts(_ctx(tmp_path / "gem"))[GENERATE]+ shell = _prompts(_ctx(tmp_path / "agy", agent_id="agy:gemini-3.7-flash"))[GENERATE]+ assert "declared in your\ntool list" in mcp and "no MCP server" not in mcp+ assert "this session has no MCP server" in shell and "declared in your" not in shell+ for p in (mcp, shell): # the contract half is the same either way+ assert "`AGENTS.md` =" in p+++# --------------------------------------------------------------------------- the production path+def test_the_track_s_own_refine_prompt_is_the_focused_one(tmp_path, monkeypatch):+ """Through ``ArticulatedObjectTrack._refine_task`` — the only caller of ``refine_focus``.++ A hand-built context proves the helpers; deleting the call from the track leaves those+ tests green and every real refine prompt fat."""+ monkeypatch.setenv(LEAN_PROMPT_ENV, "1")+ track, ctx = _track_ctx(tmp_path)+ prompt = track._refine_task(ctx, _group(), _last(), 2, parallel=True).prompt+ assert "already verified, keep them true: a1, a2" in prompt+ assert "Seat top at 0.45 m" not in prompt # the passing items, by id only+ assert _rows(prompt) == ["Drawer"] # not every part in the plan+ assert "Elided from this prompt" in prompt and "## Acceptance checklist\n" in prompt++ monkeypatch.delenv(LEAN_PROMPT_ENV)+ get_settings.cache_clear()+ track, ctx = _track_ctx(tmp_path / "off")+ off = track._refine_task(ctx, _group(), _last(), 2, parallel=True).prompt+ assert "Seat top at 0.45 m" in off and _rows(off) == ALL_ROWS+ assert "## Acceptance checklist (unchanged)" in off and "Elided from this prompt" not in off