Skip to content

Official Codebase of 3DCodeVerse

Python

graphics: a system prompt per language, built around the one lever with evidence

gaoypengd619e8fb1e76
diff --git a/harness/codeverse/prompts/__init__.py b/harness/codeverse/prompts/__init__.py
index e8fee67e..ebdae4bb 100644
--- a/harness/codeverse/prompts/__init__.py
+++ b/harness/codeverse/prompts/__init__.py
@@ -3,11 +3,15 @@
from __future__ import annotations
import hashlib
+import logging
from functools import lru_cache
from pathlib import Path
from typing import Any
-from jinja2 import Environment, FileSystemLoader, StrictUndefined
+from jinja2 import ChainableUndefined, Environment, FileSystemLoader, StrictUndefined
+from jinja2.exceptions import UndefinedError
+
+log = logging.getLogger(__name__)
PROMPTS_DIR = Path(__file__).resolve().parent
@@ -20,6 +24,17 @@ _env = Environment(
autoescape=False,
)
+#: same environment, but an unknown name renders empty instead of raising — used only
+#: as the fallback above, never as the default.
+_lenient_env = Environment(
+ loader=FileSystemLoader(str(PROMPTS_DIR)),
+ undefined=ChainableUndefined,
+ trim_blocks=True,
+ lstrip_blocks=True,
+ keep_trailing_newline=True,
+ autoescape=False,
+)
+
@lru_cache(maxsize=256)
def load_text(rel_path: str) -> str:
@@ -31,8 +46,22 @@ def load_text(rel_path: str) -> str:
def render(rel_path: str, **ctx: Any) -> str:
- """Render a jinja template under prompts/ with ``ctx``."""
- return _env.get_template(rel_path).render(**ctx)
+ """Render a jinja template under prompts/ with ``ctx``.
+
+ StrictUndefined is deliberate: a template that silently drops a section because a
+ caller renamed a variable is worse than a loud failure at development time. But a
+ template edited while a run is IN FLIGHT is a different matter — the run reloads the
+ file at its next round boundary and dies on a variable its caller has never heard of.
+ So a missing name degrades the prompt (that one section renders empty) instead of
+ killing the task, and says so in the log. Everything else still raises.
+ """
+ template = _env.get_template(rel_path)
+ try:
+ return template.render(**ctx)
+ except UndefinedError as e:
+ log.error("prompt %s wants a variable this caller does not pass (%s); rendering it "
+ "leniently — the prompt loses that section, the run continues", rel_path, e)
+ return _lenient_env.get_template(rel_path).render(**ctx)
def prompt_hash(text: str) -> str:
diff --git a/harness/codeverse/prompts/glsl_shader/system.md b/harness/codeverse/prompts/glsl_shader/system.md
index b031a4d8..6b7b9d25 100644
--- a/harness/codeverse/prompts/glsl_shader/system.md
+++ b/harness/codeverse/prompts/glsl_shader/system.md
@@ -1 +1,40 @@
-You are an expert GLSL fragment-shader artist (Shadertoy style) writing RAW code for a headless harness. Follow the contract exactly: no #version/uniform redeclarations (shader) · no window/context creation (program) · everything animates with time. Render and LOOK at your frames before finishing.
+You are a GLSL fragment-shader artist writing a raw Shadertoy-style body for a headless
+harness. You own every pixel of one image pass. There is no state between pixels and no
+state between frames: every frame is a pure function of the pixel and of absolute `u_time`.
+The harness owns the `#version` header, the uniform block and `common.glsl` — never
+redeclare them.
+
+The loop that decides whether your work ships:
+
+ write → `gl_probe` (compiles? one frame) → fix everything it reports → repeat
+ → `gl_frames` → LOOK at the sheet → only then finish.
+
+Do not finish while `gl_probe` reports anything. This is not advice. On a measured
+ten-rung ladder of shader briefs, the agent that ran this loop compiled 10 of 10 and the
+one given the same reference material WITHOUT the loop compiled 5 of 10 — and the loop's
+code came out shorter and cheaper, not longer. A single unreported compile error reads to
+you as "this idea does not work" when the truth is "you left out an include".
+
+What the judge will name if you skip it:
+
+* **Compiles but invisible** — the effect is there in source and contributes nothing to the
+ frame. Check the final `fragColor` write, the raymarch hit test, the ray direction, and
+ whether a term is multiplied to zero.
+* **One-scale noise** — a single octave at a single frequency both aliases and reads flat.
+ Real surfaces carry structure at two or three scales.
+* **Scrolled uv standing in for motion** — a still image with a sliding texture over it. Move
+ what is *in* the scene, at more than one rate.
+* **A radial blob standing in for directional light** — a light shaft has a direction and a
+ soft edge; a centred falloff has neither.
+
+Two rules that survive every brief:
+
+* Everything is a smooth function of absolute `u_time`. No frame counters, no per-frame
+ seeds, and never a hand-rolled `fract`/`mod` wrap of raw time — that is a visible cut
+ between two sampled frames.
+* **Light before colour.** Get the frame into a readable band first; hue and palette work
+ is invisible on dark, low-chroma pixels. A subject in daylight sits near half the
+ brightness of its own sky — a fifth is underlit, not moody.
+
+A clean simpler effect beats a richer one carrying a visible defect. Clear NaN, black,
+blown and static before you add the next layer; deleting a layer is a legitimate fix.
diff --git a/harness/codeverse/prompts/glsl_shader/system_v0.md b/harness/codeverse/prompts/glsl_shader/system_v0.md
new file mode 100644
index 00000000..b031a4d8
--- /dev/null
+++ b/harness/codeverse/prompts/glsl_shader/system_v0.md
@@ -0,0 +1 @@
+You are an expert GLSL fragment-shader artist (Shadertoy style) writing RAW code for a headless harness. Follow the contract exactly: no #version/uniform redeclarations (shader) · no window/context creation (program) · everything animates with time. Render and LOOK at your frames before finishing.
diff --git a/harness/codeverse/prompts/opengl_python/system.md b/harness/codeverse/prompts/opengl_python/system.md
index 372c8502..a882cbc5 100644
--- a/harness/codeverse/prompts/opengl_python/system.md
+++ b/harness/codeverse/prompts/opengl_python/system.md
@@ -1 +1,39 @@
-You are an expert raw OpenGL (moderngl) graphics programmer writing RAW code for a headless harness. Follow the contract exactly: no #version/uniform redeclarations (shader) · no window/context creation (program) · everything animates with time. Render and LOOK at your frames before finishing.
+You are a graphics programmer writing a raw moderngl program for a headless harness. You
+own a program with a lifetime: `setup(ctx, width, height)` runs **once** and returns your
+state; `render(ctx, state, t, frame, fbo)` is **sampled** at unequal times, out of order,
+and must draw the frame for that `t` into the framebuffer it is handed. There is no window,
+no context creation and no clock of your own.
+
+The loop that decides whether your work ships:
+
+ write → `gl_probe` (imports? one frame) → fix everything it reports → repeat
+ → `gl_frames` → LOOK at the sheet → only then finish.
+
+Do not finish while `gl_probe` reports anything. This is not advice. On a measured ladder
+of graphics briefs, the agent that ran this loop got every rung to compile and the one
+given the same reference material WITHOUT the loop got half — and the loop's code came out
+shorter and cheaper, not longer.
+
+What the judge will name if you skip it:
+
+* **The sampled-time trap** — you are called at t = 0, 1, 2.5, 4, 6 s, not at 60 fps. A
+ simulation that advances one step per call has taken five steps by the last frame. Pose
+ from `t`; if a state must integrate, integrate to `t` inside the call.
+* **The final pass not landing** — you rendered into your own FBO and the harness read the
+ one you were handed. The last thing `render` does is draw into `fbo`.
+* **A hard cut between samples** — motion that is fine at 60 fps but discontinuous at the
+ five sampled times. Check that your parameterisation is smooth across them.
+* **One-scale detail** — a single frequency in a texture, a displacement or a particle
+ field both aliases and reads flat.
+
+Two rules that survive every brief:
+
+* Everything is a smooth function of absolute `t`, and `render` is deterministic: called
+ twice with the same `t`, it must draw the same frame. No frame counters driving content,
+ no per-call RNG without a `t`-derived seed, no hand-rolled `fract`/`mod` wrap of raw time.
+* **Light before colour.** Get the frame into a readable band first; hue and palette work is
+ invisible on dark, low-chroma pixels. A subject in daylight sits near half the brightness
+ of its own sky — a fifth is underlit, not moody.
+
+A clean simpler program beats a richer one carrying a visible defect. Clear NaN, black,
+blown and static before you add the next pass; deleting a pass is a legitimate fix.
diff --git a/harness/codeverse/prompts/opengl_python/system_v0.md b/harness/codeverse/prompts/opengl_python/system_v0.md
new file mode 100644
index 00000000..372c8502
--- /dev/null
+++ b/harness/codeverse/prompts/opengl_python/system_v0.md
@@ -0,0 +1 @@
+You are an expert raw OpenGL (moderngl) graphics programmer writing RAW code for a headless harness. Follow the contract exactly: no #version/uniform redeclarations (shader) · no window/context creation (program) · everything animates with time. Render and LOOK at your frames before finishing.
diff --git a/harness/codeverse/spatial/frame_stats.py b/harness/codeverse/spatial/frame_stats.py
index df04aade..6f79b59a 100644
--- a/harness/codeverse/spatial/frame_stats.py
+++ b/harness/codeverse/spatial/frame_stats.py
@@ -133,7 +133,11 @@ def sequence_stats(frames: Sequence[tuple[float, str | Path]], *, nan_counts: Se
seq.mean_diff = float(np.mean(diffs))
seq.max_diff = float(np.max(diffs))
seq.n_duplicates = sum(1 for d in diffs if d < DUPLICATE_DIFF)
- seq.static = seq.mean_diff < STATIC_DIFF
+ # MAX, not mean: 'static' is a scoring cap (shader_v2.yaml static_frames), so it must
+ # require that NO sampled pair changed. With the mean, an effect whose motion is
+ # concentrated between two of the five sampled times (0/1/2.5/4/6 s) is averaged down
+ # by the three quiet pairs and convicted while animating.
+ seq.static = seq.max_diff < STATIC_DIFF
seq.flicker = seq.max_diff > FLICKER_DIFF and len(diffs) >= 2
return seq
@@ -163,7 +167,7 @@ def frame_gate(seq: SequenceStats, *, motion_expected: bool = True, gate: str =
add(Severity.ERROR, "blown", f"frames are blown out white (mean luminance {seq.mean_lum:.3f})",
"tone-map and clamp: col = col / (1.0 + col); keep accumulated glow sums bounded")
if seq.static and motion_expected:
- add(Severity.WARN, "static", f"frames do not change over time (mean |Δ| {seq.mean_diff:.4f}); the shader looks static",
+ add(Severity.WARN, "static", f"frames do not change over time (largest |Δ| between any two sampled frames {seq.max_diff:.4f}); the shader looks static",
"use u_time for motion: scroll uv, rotate, animate noise offsets, move lights — the judge compares frames at t=0..6s")
elif seq.n_duplicates and motion_expected:
add(Severity.INFO, "duplicate", f"{seq.n_duplicates} consecutive frame pair(s) are identical",
diff --git a/harness/codeverse/tracks/plan_features.py b/harness/codeverse/tracks/plan_features.py
index 9c553a8a..d9d1377b 100644
--- a/harness/codeverse/tracks/plan_features.py
+++ b/harness/codeverse/tracks/plan_features.py
@@ -84,6 +84,9 @@ LIVE_SWITCHES: dict[str, str] = {
#: while its prompts live in prompts/urdf/, so the articulated agent got NO
#: cookbook at all. On = the fixed mapping; A/B before making it unconditional.
"CV3D_URDF_COOKBOOK": "codeverse/tracks/common.py",
+ #: v0 = the pre-2026-08-28 two-sentence system prompt; unset = the per-language one.
+ #: Temporary, for the A/B; remove with the system_v0.md files once it has an answer.
+ "CV3D_SYSPROMPT": "codeverse/tracks/prompting.py",
"CV3D_IPV4": "codeverse/models/gemini.py",
}
diff --git a/harness/codeverse/tracks/prompting.py b/harness/codeverse/tracks/prompting.py
index 6829a29a..42d926f6 100644
--- a/harness/codeverse/tracks/prompting.py
+++ b/harness/codeverse/tracks/prompting.py
@@ -8,7 +8,9 @@ which maps a refine target (part / zone / asset) to the files that own it.
from __future__ import annotations
+import contextlib
import logging
+import os
from collections.abc import Sequence
from pathlib import Path
from typing import TYPE_CHECKING, Any
@@ -278,7 +280,13 @@ def language_system_prompt(language: Language, *, role: str = "", **vars: Any) -
"""
if role:
return render(f"system/role_{role}.j2", language=language.value, **vars).strip()
- return load_text(f"{prompt_dir_for(language)}/system.md").strip()
+ d = prompt_dir_for(language)
+ # CV3D_SYSPROMPT=v0 serves the pre-2026-08-28 two-sentence prompt, so an A/B can run
+ # both arms from one tree. Delete the v0 files and this branch once it has an answer.
+ if os.environ.get("CV3D_SYSPROMPT") == "v0":
+ with contextlib.suppress(FileNotFoundError):
+ return load_text(f"{d}/system_v0.md").strip()
+ return load_text(f"{d}/system.md").strip()
def base_prompt_context(ctx: RunContext, **extra: Any) -> dict[str, Any]: