oda-engine 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/README.md +151 -2
  2. package/bin/nowhere.mjs +352 -0
  3. package/lib/account.mjs +57 -0
  4. package/lib/agentModules.mjs +57 -0
  5. package/lib/devServer.mjs +351 -0
  6. package/lib/headless.mjs +231 -0
  7. package/lib/headlessPreview.mjs +212 -0
  8. package/lib/keys.mjs +517 -0
  9. package/lib/make.mjs +855 -0
  10. package/lib/mcp.mjs +537 -0
  11. package/lib/open.mjs +22 -0
  12. package/lib/preview.mjs +87 -0
  13. package/lib/previewRpc.mjs +134 -0
  14. package/lib/project.mjs +359 -0
  15. package/lib/publishFlow.mjs +131 -0
  16. package/lib/resources.mjs +50 -0
  17. package/lib/rules.mjs +60 -0
  18. package/lib/scaffold.mjs +42 -0
  19. package/lib/setup.mjs +59 -0
  20. package/lib/tools.mjs +668 -0
  21. package/package.json +51 -4
  22. package/template/game.config.json +9 -0
  23. package/template/scene.json +4 -0
  24. package/template/src/main.ts +11 -0
  25. package/vendor/DOCS.md +447 -0
  26. package/vendor/agent/appRun.mjs +520 -0
  27. package/vendor/agent/assets/brief.mjs +242 -0
  28. package/vendor/agent/assets/collider.mjs +531 -0
  29. package/vendor/agent/assets/environments/index.mjs +12 -0
  30. package/vendor/agent/assets/environments/worldlabs.mjs +161 -0
  31. package/vendor/agent/assets/fetch.mjs +168 -0
  32. package/vendor/agent/assets/footprint.mjs +13 -0
  33. package/vendor/agent/assets/gltf.mjs +547 -0
  34. package/vendor/agent/assets/hdr.mjs +269 -0
  35. package/vendor/agent/assets/imageOps.mjs +171 -0
  36. package/vendor/agent/assets/images/codex.mjs +307 -0
  37. package/vendor/agent/assets/images/fal.mjs +75 -0
  38. package/vendor/agent/assets/images/gemini.mjs +84 -0
  39. package/vendor/agent/assets/images/index.mjs +25 -0
  40. package/vendor/agent/assets/images/openai.mjs +75 -0
  41. package/vendor/agent/assets/images/stability.mjs +71 -0
  42. package/vendor/agent/assets/images/views.mjs +31 -0
  43. package/vendor/agent/assets/import.mjs +1352 -0
  44. package/vendor/agent/assets/inspect.mjs +465 -0
  45. package/vendor/agent/assets/jobs.mjs +196 -0
  46. package/vendor/agent/assets/ktx2.mjs +290 -0
  47. package/vendor/agent/assets/ledger.mjs +466 -0
  48. package/vendor/agent/assets/net.mjs +254 -0
  49. package/vendor/agent/assets/prices.json +39 -0
  50. package/vendor/agent/assets/providers/fal.mjs +115 -0
  51. package/vendor/agent/assets/providers/index.mjs +22 -0
  52. package/vendor/agent/assets/providers/meshy.mjs +119 -0
  53. package/vendor/agent/assets/providers/tripo.mjs +188 -0
  54. package/vendor/agent/assets/sources/ambientcg.mjs +129 -0
  55. package/vendor/agent/assets/sources/index.mjs +23 -0
  56. package/vendor/agent/assets/sources/polyhaven.mjs +237 -0
  57. package/vendor/agent/assets/sources/polypizza.mjs +121 -0
  58. package/vendor/agent/assets/splat.mjs +631 -0
  59. package/vendor/agent/assets/targets.mjs +122 -0
  60. package/vendor/agent/assets/tile.mjs +261 -0
  61. package/vendor/agent/assets/unzip.mjs +180 -0
  62. package/vendor/agent/blender/cleanup.py +360 -0
  63. package/vendor/agent/blender/convert.py +167 -0
  64. package/vendor/agent/blender/find.mjs +192 -0
  65. package/vendor/agent/blender/nw_export.py +104 -0
  66. package/vendor/agent/blender/nw_rubric.py +426 -0
  67. package/vendor/agent/blender/run.mjs +193 -0
  68. package/vendor/agent/blender/runner.py +252 -0
  69. package/vendor/agent/blender/sheet.py +743 -0
  70. package/vendor/agent/depth.mjs +134 -0
  71. package/vendor/agent/director/board.mjs +451 -0
  72. package/vendor/agent/director/contracts.mjs +663 -0
  73. package/vendor/agent/director/director.mjs +2365 -0
  74. package/vendor/agent/director/estimate.mjs +200 -0
  75. package/vendor/agent/director/gate.mjs +802 -0
  76. package/vendor/agent/director/limits.json +16 -0
  77. package/vendor/agent/director/methods.mjs +457 -0
  78. package/vendor/agent/director/policy.json +33 -0
  79. package/vendor/agent/director/prompts.mjs +244 -0
  80. package/vendor/agent/director/reading.mjs +341 -0
  81. package/vendor/agent/director/router.mjs +184 -0
  82. package/vendor/agent/director/seams.mjs +243 -0
  83. package/vendor/agent/director/session.mjs +643 -0
  84. package/vendor/agent/director/store.mjs +119 -0
  85. package/vendor/agent/director/taskGate.mjs +110 -0
  86. package/vendor/agent/director/teamLedger.mjs +118 -0
  87. package/vendor/agent/director/triage.mjs +63 -0
  88. package/vendor/agent/downloads.cjs +363 -0
  89. package/vendor/agent/flow.mjs +78 -0
  90. package/vendor/agent/guard.mjs +613 -0
  91. package/vendor/agent/host.mjs +1736 -0
  92. package/vendor/agent/language.mjs +58 -0
  93. package/vendor/agent/ledger.mjs +360 -0
  94. package/vendor/agent/locale.cjs +186 -0
  95. package/vendor/agent/loop/capacity.mjs +74 -0
  96. package/vendor/agent/loop/compose.mjs +127 -0
  97. package/vendor/agent/loop/gate.mjs +205 -0
  98. package/vendor/agent/loop/judge.mjs +189 -0
  99. package/vendor/agent/loop/levels.mjs +273 -0
  100. package/vendor/agent/loop/state.mjs +358 -0
  101. package/vendor/agent/notes.cjs +278 -0
  102. package/vendor/agent/pace.mjs +258 -0
  103. package/vendor/agent/panels.mjs +431 -0
  104. package/vendor/agent/prompt.mjs +342 -0
  105. package/vendor/agent/reference/board.mjs +410 -0
  106. package/vendor/agent/reference/compose.mjs +364 -0
  107. package/vendor/agent/reference/decode.mjs +56 -0
  108. package/vendor/agent/reference/facts.mjs +1874 -0
  109. package/vendor/agent/reference/png.mjs +107 -0
  110. package/vendor/agent/reference/records.mjs +63 -0
  111. package/vendor/agent/reference/web.mjs +252 -0
  112. package/vendor/agent/roles/artist.mjs +69 -0
  113. package/vendor/agent/roles/builder.mjs +79 -0
  114. package/vendor/agent/roles/checks.mjs +223 -0
  115. package/vendor/agent/roles/common.mjs +188 -0
  116. package/vendor/agent/roles/critic.mjs +171 -0
  117. package/vendor/agent/roles/index.mjs +39 -0
  118. package/vendor/agent/roles/modeller.mjs +142 -0
  119. package/vendor/agent/roles/qa.mjs +58 -0
  120. package/vendor/agent/roles/rubrics.mjs +79 -0
  121. package/vendor/agent/roles/sound.mjs +69 -0
  122. package/vendor/agent/rounds.cjs +333 -0
  123. package/vendor/agent/shared.mjs +284 -0
  124. package/vendor/agent/stopGate.mjs +574 -0
  125. package/vendor/agent/subagents.mjs +129 -0
  126. package/vendor/agent/tools/assets.mjs +499 -0
  127. package/vendor/agent/tools/blender.mjs +754 -0
  128. package/vendor/agent/tools/cards.mjs +479 -0
  129. package/vendor/agent/tools/choices.mjs +479 -0
  130. package/vendor/agent/tools/compose.mjs +74 -0
  131. package/vendor/agent/tools/environment.mjs +488 -0
  132. package/vendor/agent/tools/eyes.mjs +733 -0
  133. package/vendor/agent/tools/generate.mjs +338 -0
  134. package/vendor/agent/tools/guide.mjs +46 -0
  135. package/vendor/agent/tools/harness.mjs +193 -0
  136. package/vendor/agent/tools/image.mjs +643 -0
  137. package/vendor/agent/tools/index.mjs +162 -0
  138. package/vendor/agent/tools/look.mjs +578 -0
  139. package/vendor/agent/tools/loop.mjs +858 -0
  140. package/vendor/agent/tools/others.mjs +123 -0
  141. package/vendor/agent/tools/pictures.mjs +535 -0
  142. package/vendor/agent/tools/reference.mjs +366 -0
  143. package/vendor/agent/transcripts.mjs +118 -0
  144. package/vendor/agent-loop.mjs +602 -0
  145. package/vendor/agent-plugin/.claude-plugin/plugin.json +5 -0
  146. package/vendor/agent-plugin/skills/art-direction/SKILL.md +82 -0
  147. package/vendor/agent-plugin/skills/asset-legality/SKILL.md +101 -0
  148. package/vendor/agent-plugin/skills/asset-sources/SKILL.md +111 -0
  149. package/vendor/agent-plugin/skills/blender-modeling/SKILL.md +97 -0
  150. package/vendor/agent-plugin/skills/look-dev/SKILL.md +104 -0
  151. package/vendor/agent-plugin/skills/playtesting/SKILL.md +74 -0
  152. package/vendor/agent-plugin/skills/reference-loop/SKILL.md +102 -0
  153. package/vendor/agent-plugin/skills/sound-design/SKILL.md +60 -0
  154. package/vendor/agent-plugin/skills/style/SKILL.md +35 -0
  155. package/vendor/agent-plugin/skills/tsl-r185/SKILL.md +107 -0
  156. package/vendor/auth.cjs +570 -0
  157. package/vendor/build.cjs +953 -0
  158. package/vendor/catalog.json +455 -0
  159. package/vendor/connectors.cjs +688 -0
  160. package/vendor/eyes.mjs +733 -0
  161. package/vendor/gameExports.json +1390 -0
  162. package/vendor/git.cjs +222 -0
  163. package/vendor/models.json +57 -0
  164. package/vendor/publish.cjs +1018 -0
  165. package/vendor/refBoard.cjs +301 -0
  166. package/vendor/schema/dist/assets.d.ts +335 -0
  167. package/vendor/schema/dist/assets.js +439 -0
  168. package/vendor/schema/dist/brief.d.ts +357 -0
  169. package/vendor/schema/dist/brief.js +302 -0
  170. package/vendor/schema/dist/common.d.ts +9 -0
  171. package/vendor/schema/dist/common.js +13 -0
  172. package/vendor/schema/dist/config.d.ts +406 -0
  173. package/vendor/schema/dist/config.js +355 -0
  174. package/vendor/schema/dist/contract.d.ts +599 -0
  175. package/vendor/schema/dist/contract.js +1146 -0
  176. package/vendor/schema/dist/index.d.ts +14 -0
  177. package/vendor/schema/dist/index.js +21 -0
  178. package/vendor/schema/dist/look.d.ts +463 -0
  179. package/vendor/schema/dist/look.js +681 -0
  180. package/vendor/schema/dist/lookStats.d.ts +230 -0
  181. package/vendor/schema/dist/lookStats.js +768 -0
  182. package/vendor/schema/dist/pilot.d.ts +32 -0
  183. package/vendor/schema/dist/pilot.js +44 -0
  184. package/vendor/schema/dist/publish.d.ts +214 -0
  185. package/vendor/schema/dist/publish.js +291 -0
  186. package/vendor/schema/dist/scene.d.ts +75 -0
  187. package/vendor/schema/dist/scene.js +120 -0
  188. package/vendor/schema/dist/skyLight.d.ts +141 -0
  189. package/vendor/schema/dist/skyLight.js +436 -0
  190. package/vendor/schema/dist/style.d.ts +131 -0
  191. package/vendor/schema/dist/style.js +155 -0
  192. package/vendor/schema/package.json +1 -0
  193. package/vendor/selectionPrompt.mjs +51 -0
  194. package/vendor/useTools.mjs +195 -0
  195. package/vendor/userMessage.mjs +26 -0
  196. package/web-dist/assets/GaussianSplatUtils-CptQkDVX.js +1 -0
  197. package/web-dist/assets/KTX2Loader-C53LJqss.js +2 -0
  198. package/web-dist/assets/SPZLoader-BQ3tjaTv.js +1 -0
  199. package/web-dist/assets/gaussianSplat-_9tcWegB.js +1 -0
  200. package/web-dist/assets/index-Baka-ZO7.js +693 -0
  201. package/web-dist/assets/index-CcjyyQco.css +1 -0
  202. package/web-dist/assets/meshopt_decoder.module-BvwdjiD3.js +1 -0
  203. package/web-dist/assets/zstddec.module-CfFeQW7d.js +1 -0
  204. package/web-dist/index.html +34 -0
@@ -0,0 +1,223 @@
1
+ // The two checks only the roles' work needs (orchestrator spec 5.8), run by
2
+ // the director's gate and by each session's task_check:
3
+ //
4
+ // palette every colour literal in the task's files is one of the brief's
5
+ // (its palette and its material colours), within deltaE2000 12;
6
+ // greys pass, and two strays are let through
7
+ // audio the sound module bundled alone and run in the preview: every
8
+ // event renders offline within bounds (length, peak, level, onset,
9
+ // a loop's seam)
10
+ //
11
+ // Each answers { id, kind, ok, text, evidence: { numbers } } like every
12
+ // check of the gate, and a check that cannot run fails with the reason.
13
+ // Every bound is a proposal, for the real-model experiments to tune.
14
+
15
+ import fs from 'node:fs'
16
+ import fsp from 'node:fs/promises'
17
+ import path from 'node:path'
18
+ import { deltaE2000, hexToLab } from '../../schema/dist/index.js'
19
+ import { matches } from '../director/board.mjs'
20
+ import { SOUND_MODULE } from './sound.mjs'
21
+
22
+ /** deltaE2000 from the nearest brief colour above which a literal is a stray. */
23
+ export const PALETTE_DELTA = 12
24
+ /** Chroma under which a colour is a grey, and passes. */
25
+ export const GREY_CHROMA = 4
26
+ /** Strays let through before the check fails. */
27
+ export const PALETTE_STRAYS = 2
28
+
29
+ export const AUDIO_BOUNDS = { minSeconds: 0.03, maxSeconds: 8, loopSeconds: 1, peak: 0.89, rms: 0.003, onsetMs: 10, seam: 0.02 }
30
+
31
+ const SKIP_DIRS = new Set(['node_modules', '.git', '.nowhere', 'dist', 'release', 'vendor'])
32
+ const TEXT_FILES = /\.(m?[jt]sx?|cjs|py|json|css|html|glsl|wgsl|md)$/i
33
+ const MAX_FILE = 1024 * 1024
34
+
35
+ const result = (check, ok, text, numbers = {}) => ({ id: check.id, kind: check.kind, ok, text, evidence: { numbers } })
36
+
37
+ /** Every project file a list of globs names (literal paths and patterns alike). */
38
+ async function filesFor(root, globs) {
39
+ const out = []
40
+ const walk = async (dir, rel) => {
41
+ let entries = []
42
+ try {
43
+ entries = await fsp.readdir(dir, { withFileTypes: true })
44
+ } catch {
45
+ return
46
+ }
47
+ for (const e of entries) {
48
+ if (out.length >= 2000) return
49
+ const r = rel ? `${rel}/${e.name}` : e.name
50
+ if (e.isDirectory()) {
51
+ if (!SKIP_DIRS.has(e.name)) await walk(path.join(dir, e.name), r)
52
+ } else if (e.isFile() && globs.some((g) => matches(g, r))) out.push(r)
53
+ }
54
+ }
55
+ await walk(root, '')
56
+ return out.sort()
57
+ }
58
+
59
+ /** The colour literals of a text: #rgb (in quotes), #rrggbb and 0xrrggbb, with their lines. */
60
+ export function colourLiterals(text) {
61
+ const found = []
62
+ const lines = text.split('\n')
63
+ lines.forEach((line, i) => {
64
+ for (const m of line.matchAll(/#([0-9a-fA-F]{6})(?![0-9a-zA-Z_])/g)) found.push({ hex: `#${m[1].toLowerCase()}`, line: i + 1, text: m[0] })
65
+ for (const m of line.matchAll(/(['"`])#([0-9a-fA-F]{3})\1/g)) {
66
+ const [r, g, b] = m[2].toLowerCase()
67
+ found.push({ hex: `#${r}${r}${g}${g}${b}${b}`, line: i + 1, text: `#${m[2]}` })
68
+ }
69
+ for (const m of line.matchAll(/\b0x([0-9a-fA-F]{6})\b/g)) found.push({ hex: `#${m[1].toLowerCase()}`, line: i + 1, text: m[0] })
70
+ })
71
+ return found
72
+ }
73
+
74
+ /** The brief's colours a file may use: its palette and its materials' colours. */
75
+ export function briefColours(brief) {
76
+ const out = []
77
+ for (const p of brief?.palette ?? []) if (typeof p?.hex === 'string') out.push(p.hex.toLowerCase())
78
+ for (const m of brief?.materials ?? []) for (const c of m?.colours ?? []) if (typeof c === 'string') out.push(c.toLowerCase())
79
+ return [...new Set(out.filter((h) => /^#[0-9a-f]{6}$/.test(h)))]
80
+ }
81
+
82
+ const briefOf = (ctx) => ctx?.production?.brief ?? ctx?.brief ?? null
83
+
84
+ async function palette(check, ctx) {
85
+ const root = ctx?.projectRoot
86
+ if (!root) return result(check, false, 'palette: there is no project open.')
87
+ const brief = briefOf(ctx)
88
+ const allowed = briefColours(brief)
89
+ if (allowed.length === 0) return result(check, false, 'palette: there is no brief palette to hold the files to, so the check cannot run.')
90
+ const files = await filesFor(root, check.files ?? [])
91
+ const labs = allowed.map((h) => ({ hex: h, lab: hexToLab(h) }))
92
+ const strays = []
93
+ let literals = 0
94
+ for (const rel of files) {
95
+ if (!TEXT_FILES.test(rel)) continue
96
+ let text = ''
97
+ try {
98
+ const abs = path.join(root, rel)
99
+ if (fs.statSync(abs).size > MAX_FILE) continue
100
+ text = await fsp.readFile(abs, 'utf8')
101
+ } catch {
102
+ continue
103
+ }
104
+ for (const lit of colourLiterals(text)) {
105
+ literals++
106
+ const lab = hexToLab(lit.hex)
107
+ if (Math.hypot(lab[1], lab[2]) < GREY_CHROMA) continue
108
+ let best = null
109
+ for (const a of labs) {
110
+ const d = deltaE2000(lab, a.lab)
111
+ if (!best || d < best.d) best = { d, hex: a.hex }
112
+ }
113
+ if (best.d > PALETTE_DELTA) strays.push({ file: rel, line: lit.line, hex: lit.hex, nearest: best.hex, deltaE: Math.round(best.d * 10) / 10 })
114
+ }
115
+ }
116
+ const numbers = { files: files.length, literals, strays: strays.length }
117
+ const listed = strays.map((s) => `${s.file}:${s.line} ${s.hex} (nearest brief colour ${s.nearest}, deltaE ${s.deltaE})`)
118
+ if (strays.length > PALETTE_STRAYS) {
119
+ return result(check, false, `palette: ${strays.length} colour literals are not the brief's (at most ${PALETTE_STRAYS} may be): ${listed.join('; ')}. Use the brief's colours (${allowed.join(', ')}).`, numbers)
120
+ }
121
+ return result(
122
+ check,
123
+ true,
124
+ `palette: ${literals} colour literals in ${files.length} file${files.length === 1 ? '' : 's'}, ${strays.length ? `${strays.length} off the brief (${listed.join('; ')}), within the ${PALETTE_STRAYS} allowed` : "all the brief's or greys"}.`,
125
+ numbers,
126
+ )
127
+ }
128
+
129
+ /** The page-side measure of one event, run through the preview's eval. It
130
+ * imports the bundled module from a blob URL, renders the event offline and
131
+ * answers only numbers (the samples stay in the page). */
132
+ export function audioProbe(bundle, event) {
133
+ return `const src = ${JSON.stringify(bundle)}
134
+ const url = URL.createObjectURL(new Blob([src], { type: 'text/javascript' }))
135
+ try {
136
+ const mod = await import(url)
137
+ if (typeof mod.renderOffline !== 'function') return { ok: false, error: 'the module exports no renderOffline' }
138
+ const sampleRate = 48000
139
+ const x = await mod.renderOffline(${JSON.stringify(event)}, sampleRate)
140
+ if (!x || typeof x.length !== 'number') return { ok: false, error: 'renderOffline did not return samples' }
141
+ const n = x.length
142
+ let peak = 0
143
+ let sum = 0
144
+ let finite = true
145
+ for (let i = 0; i < n; i++) {
146
+ const v = x[i]
147
+ if (!Number.isFinite(v)) { finite = false; continue }
148
+ const a = Math.abs(v)
149
+ if (a > peak) peak = a
150
+ sum += v * v
151
+ }
152
+ const floor = Math.max(0.001, 0.05 * peak)
153
+ let onset = -1
154
+ for (let i = 0; i < n; i++) if (Math.abs(x[i]) >= floor) { onset = i; break }
155
+ return { ok: true, sampleRate, seconds: n / sampleRate, peak, rms: n ? Math.sqrt(sum / n) : 0, finite, onsetMs: onset < 0 ? null : (onset / sampleRate) * 1000, seam: n > 1 ? Math.abs(x[n - 1] - x[0]) : 0 }
156
+ } finally {
157
+ URL.revokeObjectURL(url)
158
+ }`
159
+ }
160
+
161
+ /** What is wrong with one event's numbers, one sentence each. */
162
+ export function audioProblems(event, m, loop) {
163
+ const b = AUDIO_BOUNDS
164
+ const out = []
165
+ const r = (v, d = 3) => Math.round(v * 10 ** d) / 10 ** d
166
+ if (!m?.finite) out.push(`${event}: some samples are not numbers (NaN or infinite): a node is fed a bad value.`)
167
+ if (!(m?.seconds >= b.minSeconds) || m.seconds > b.maxSeconds) out.push(`${event}: it lasts ${r(m?.seconds ?? 0)} s; an event lasts ${b.minSeconds} to ${b.maxSeconds} s.`)
168
+ if (loop && m?.seconds < b.loopSeconds) out.push(`${event}: a loop of ${r(m.seconds)} s repeats too fast to read as ambience; make it at least ${b.loopSeconds} s.`)
169
+ if (m?.peak > b.peak) out.push(`${event}: it peaks at ${r(m.peak)}, over ${b.peak} (-1 dBFS), so it will clip; bring its gain down.`)
170
+ if (!(m?.rms >= b.rms)) out.push(`${event}: its level (RMS ${r(m?.rms ?? 0, 4)}) is under ${b.rms}: it is silent.`)
171
+ if (m?.onsetMs === null || m?.onsetMs > b.onsetMs) out.push(`${event}: it starts ${m?.onsetMs === null ? 'never' : `${r(m.onsetMs, 1)} ms late`}; the sound should begin within ${b.onsetMs} ms of play().`)
172
+ if (loop && m?.seam > b.seam) out.push(`${event}: the loop's seam jumps ${r(m.seam)} (at most ${b.seam}), so it clicks every time it repeats; end it where it starts.`)
173
+ return out
174
+ }
175
+
176
+ async function bundleSound(root) {
177
+ const entry = path.join(root, SOUND_MODULE)
178
+ if (!fs.existsSync(entry)) return { error: `${SOUND_MODULE} does not exist yet.` }
179
+ try {
180
+ const esbuild = await import('esbuild')
181
+ const r = await esbuild.build({
182
+ entryPoints: [entry],
183
+ bundle: true,
184
+ write: false,
185
+ format: 'esm',
186
+ platform: 'browser',
187
+ target: 'es2022',
188
+ external: ['three', 'three/*', '@nowhere/sdk'],
189
+ logLevel: 'silent',
190
+ })
191
+ return { code: r.outputFiles[0].text }
192
+ } catch (err) {
193
+ const first = err?.errors?.[0]
194
+ return { error: `${SOUND_MODULE} does not bundle on its own: ${first ? `${first.location ? `${first.location.file}:${first.location.line}: ` : ''}${first.text}` : (err?.message ?? err)}` }
195
+ }
196
+ }
197
+
198
+ async function audio(check, ctx) {
199
+ const root = ctx?.projectRoot
200
+ if (!root) return result(check, false, 'audio: there is no project open.')
201
+ if (typeof ctx?.rpc !== 'function') return result(check, false, 'audio: the preview is not connected, so nothing can be rendered.')
202
+ const built = await bundleSound(root)
203
+ if (built.error) return result(check, false, `audio: ${built.error}`)
204
+ const loops = new Map((briefOf(ctx)?.sound?.events ?? []).map((e) => [e.id, e.loop === true]))
205
+ const problems = []
206
+ const measured = {}
207
+ for (const event of check.events ?? []) {
208
+ const r = await ctx.rpc('eval', { code: audioProbe(built.code, event), timeoutMs: 5000 }, 12_000)
209
+ const m = r?.ok ? r.value : null
210
+ if (!m?.ok) {
211
+ problems.push(`${event}: it did not render: ${m?.error ?? r?.error ?? 'the preview did not answer'}.`)
212
+ continue
213
+ }
214
+ measured[event] = { seconds: m.seconds, peak: m.peak, rms: m.rms, onsetMs: m.onsetMs, seam: m.seam }
215
+ problems.push(...audioProblems(event, m, loops.get(event) === true))
216
+ }
217
+ const numbers = { events: (check.events ?? []).length, measured }
218
+ if (problems.length) return result(check, false, `audio: ${problems.join(' ')}`, numbers)
219
+ return result(check, true, `audio: all ${(check.events ?? []).length} events render within bounds (${Object.entries(measured).map(([e, m]) => `${e} ${Math.round(m.seconds * 100) / 100} s, peak ${Math.round(m.peak * 100) / 100}`).join('; ')}).`, numbers)
220
+ }
221
+
222
+ /** By check kind, as the gate looks them up. */
223
+ export const ROLE_CHECKS = { palette, audio }
@@ -0,0 +1,188 @@
1
+ // What every role shares: the paragraphs each role prompt carries (the
2
+ // pinned phrases the checks hold them to), the task message a session opens
3
+ // with, and the checks said in words. The message is built in one order for
4
+ // every role (orchestrator spec 5.0): the goal, the round, the parts of the
5
+ // brief the role needs, the cameras, what the task owns and reads, what is
6
+ // ready, the checks with exact example inputs. What the last attempt left to
7
+ // fix (the failed checks, the critic's changes, the handoff to a new model)
8
+ // is the director's own text (ATTEMPT_PROMPT and handoffText), which
9
+ // session.mjs adds after this message, so it is never said twice.
10
+ //
11
+ // The prompts are static English texts, so they cache; everything that
12
+ // changes per task goes in the message.
13
+
14
+ import { jsonSchemaOf } from '../director/contracts.mjs'
15
+
16
+ /** Ownership, the brief and checking, in every role prompt. */
17
+ export const SHARED_RULES = `## How a team task works
18
+
19
+ You own only the files your task lists. Everything else is read-only: if it must change, say so in changesNeeded (the path, whose it is, what and why), and the director hands it to its owner. A write outside your files is refused with the owner's name.
20
+
21
+ Every value comes from the brief, which comes from the request and the reference. There are no defaults to keep: a colour, size, light or sound that is not in the brief is a question you answer from the brief's facts, never a stock choice. A tool's default value is a placeholder until you pass the brief's. There is no library of ready-made materials, shaders, models or sounds to combine either: judge what this task needs from the brief and make it for it.
22
+
23
+ The platform rules hold in every file you write: src/main.ts exports createGame(ctx) returning { root, update(dt), dispose() }; no requestAnimationFrame of your own, all motion in update(dt); everything you create lives under root and dispose() frees it; input only through ctx.input.pressed(code) and ctx.input.look(); the visitor's HP changes only through the SDK's pilot (world.damage, world.heal), never a health of your own. One unit is one metre; the player is 1.75 m tall and sees from about 1.6 m.
24
+
25
+ Never put probes, throws, teleports or debug logs in the source to find something out: read the running game with nw_eval and nw_logs. Mark any line you change only to investigate with a trailing "// DBG" and put it back before you finish.
26
+
27
+ Run task_check before you finish; your task is judged by the same checks. It answers PASS or FAIL for each one with the evidence: fix what fails and run it again. Then finish with your report (the structured output): what you did, what is not done, what you assumed, and changesNeeded. Never claim something task_check or a picture did not show.`
28
+
29
+ const json = (v) => JSON.stringify(v)
30
+ const list = (items) => items.filter(Boolean).join(', ')
31
+
32
+ /** A brief camera or a concretised one, in a line. */
33
+ function cameraLine(c, shots) {
34
+ const shot = shots?.find((s) => s?.id === c.id)?.shot
35
+ const bits = [c.purpose, c.subject, c.heightM !== undefined ? `${c.heightM} m up` : '', c.pitchDeg !== undefined ? `pitch ${c.pitchDeg}` : '', c.fovDeg !== undefined ? `fov ${c.fovDeg}` : '', c.horizonY !== undefined ? `horizon at ${c.horizonY} of the height` : '', c.aspect ? `${c.aspect} frame` : '']
36
+ return `- ${c.id} (${list(bits)})${shot ? `: ${json(shot)}` : ''}`
37
+ }
38
+
39
+ /** A goto that is always an input nw_play takes: the map's centre. */
40
+ export const POINT = [0, 0, 0]
41
+
42
+ /** What an example's act step holds when the task's own play checks press
43
+ * no key: how a game is played is this game's design, decided per request,
44
+ * so the example never fixes one (a model copies an example as it is). */
45
+ export const KEY_PLACEHOLDER = '<the KeyboardEvent.code this game reads>'
46
+
47
+ /** The keys the task's own play checks press, the first step that holds any. */
48
+ export function playKeys(task) {
49
+ const keys = (task?.accept?.checks ?? []).flatMap((c) => (c.kind === 'play' ? c.steps ?? [] : [])).find((s) => Array.isArray(s?.keys) && s.keys.length)?.keys
50
+ return keys ?? null
51
+ }
52
+
53
+ /** The example nw_play input every role that plays is given: the keys from
54
+ * the task's own play checks, else a placeholder for the game's own key. */
55
+ export function playExample(target, keys = null) {
56
+ // watch names a thing to follow; a point is not one.
57
+ return json({ steps: [{ goto: target, seconds: 12 }, { keys: keys?.length ? keys : [KEY_PLACEHOLDER], seconds: 1 }], frames: 4, ...(typeof target === 'string' ? { watch: [target] } : {}) })
58
+ }
59
+
60
+ /** One check in words, with its exact input where it has one. */
61
+ export function checkWords(c, { brief, reference } = {}) {
62
+ const perf = brief?.performance
63
+ switch (c.kind) {
64
+ case 'build':
65
+ return 'build: nw_check passes and the game runs.'
66
+ case 'runtime':
67
+ return 'runtime: nw_status twice, a second apart, shows no runtime error, no material error, no failed file, and the frame counter moves.'
68
+ case 'markers':
69
+ return 'markers: no DBG or DEBUG marker is left in your files.'
70
+ case 'ownership':
71
+ return 'ownership: every file you wrote is one your task owns.'
72
+ case 'ledger':
73
+ return 'ledger: asset_ledger shows no problem for your files (every file in assets/ came through asset_import or nw_blender).'
74
+ case 'seams':
75
+ return 'seams: no file still starts with the seam stub marker.'
76
+ case 'coverage':
77
+ return 'coverage: every request element and moment is covered by a passed task.'
78
+ case 'view':
79
+ return `view: nw_view at the cameras ${list(c.cameras ?? [])} brings back every picture, none frozen.`
80
+ case 'cameras':
81
+ return `cameras: your report gives every brief camera as an nw_view shot (cameras: [{ "id", "shot" }]), each shot comes back, and the reference camera's horizon sits within 0.08 of the reference's.`
82
+ case 'placements':
83
+ return 'placements: every placement in your task message stands in the running game through place() of src/placements/index.ts (nw_eval reads the tag place() puts on what it adds).'
84
+ case 'compare':
85
+ return `compare: nw_compare ${json({ reference: reference ?? '<the reference>', camera: c.camera })} raises no gross flag of your role's own work (palette-far and value-far are the look's, structure-far and detail-far the forms' and the framing's) that your task raised or made worse; a flag of another role's work goes to the critic as evidence and to its owner. The critic then judges the side by side.`
86
+ case 'play':
87
+ return `play: nw_play ${json({ steps: c.steps ?? [] })}, then each of these holds through nw_eval: ${(c.expect ?? []).map((e) => `${e.code} ${e.op}${e.value !== undefined ? ` ${json(e.value)}` : ''}`).join('; ')}.`
88
+ case 'eval':
89
+ return `eval: nw_eval ${json({ code: c.code })} gives ${(c.expect ?? []).map((e) => `${e.op}${e.value !== undefined ? ` ${json(e.value)}` : ''}`).join('; ')}.`
90
+ case 'perf':
91
+ return `perf: a 10 s walk keeps draw calls at most ${perf?.drawCalls ?? 150} and triangles at most ${perf?.triangles ?? 500000} (the brief's ${perf?.tier ?? 'low'} tier, read with nw_eval renderer.info.render), and on this machine fps averages 55 or more with no frame over 50 ms.`
92
+ case 'asset':
93
+ return `asset: assets.lock.json records ${c.path} (class ${c.class})${c.size ? `, its size within 5% of ${json(c.size)} m` : ''}, its triangles within the class, measured by nw_blender when made, glTF dropped nothing${c.hero ? ', and it took at least 3 rounds (a hero)' : ''}.`
94
+ case 'module':
95
+ return `module: ${c.path} bundles on its own (three, three/webgpu, three/tsl and @nowhere/sdk outside it) and exports ${c.exports?.length ? list(c.exports) : 'every name of its interface'}.`
96
+ case 'palette':
97
+ return `palette: the colour literals in ${list(c.files ?? [])} are the brief's: at most 2 of them more than deltaE 12 from a brief palette or material colour (greys pass).`
98
+ case 'audio':
99
+ return `audio: renderOffline renders every event (${list(c.events ?? [])}): 0.03 to 8 s long (a loop at least 1 s), peak at most 0.89 (-1 dBFS), RMS at least 0.003, every sample finite, the onset within 10 ms, a loop's seam step at most 0.02.`
100
+ default:
101
+ return `${c.kind}: ${json(c)}`
102
+ }
103
+ }
104
+
105
+ /** The parts of the brief a role reads, by name. */
106
+ export function briefParts(brief, names) {
107
+ const out = {}
108
+ for (const n of names) if (brief?.[n] !== undefined) out[n] = brief[n]
109
+ return out
110
+ }
111
+
112
+ /** The pillars, and the moments this task covers, quoted as the vision wrote them. */
113
+ function visionLines(task, vision) {
114
+ if (!vision) return ''
115
+ const moments = (vision.moments ?? []).filter((m) => (task.covers ?? []).includes(m.id))
116
+ const elements = []
117
+ if (vision.pillars?.length) elements.push(`Pillars (the whole team decides by these):\n${vision.pillars.map((p) => `- ${p}`).join('\n')}`)
118
+ if (moments.length) elements.push(`The signature moments this task covers:\n${moments.map((m) => `- ${m.id} (camera ${m.camera}). Sees: ${m.sees}. Does: ${m.does}. Accepted when: ${m.acceptance}`).join('\n')}`)
119
+ return elements.join('\n\n')
120
+ }
121
+
122
+ /**
123
+ * The session a role runs for one attempt at a task: its static prompt, the
124
+ * task message, its tools and skills, and the structured output's schema.
125
+ * Model and effort are never here: the router picks them.
126
+ */
127
+ export function buildSession(role, task, input, { parts, schema, extra = [], images = [] }) {
128
+ const brief = input.brief
129
+ const checks = role.checksFor(task, brief)
130
+ const cameras = brief?.cameras ?? []
131
+ const shots = Array.isArray(input.cameras) ? input.cameras : null
132
+ const examples = [...(task.examples ?? [])]
133
+ const sections = [
134
+ `Your task (${task.id}, ${task.title}): ${task.goal}`,
135
+ `Round ${input.round} of ${input.roundLimit}.`,
136
+ `What the brief says that you need (the whole brief is brief.md in the project):\n${JSON.stringify(briefParts(brief, parts), null, 2)}`,
137
+ visionLines(task, input.vision),
138
+ cameras.length ? `The cameras${shots ? ' (as the blockout made them, ready for nw_view)' : ' (the brief\'s; the blockout makes each one a shot)'}:\n${cameras.map((c) => cameraLine(c, shots)).join('\n')}` : '',
139
+ `You own: ${list(task.owns ?? []) || 'nothing (you only read)'}.${task.reads?.length ? ` You read: ${list(task.reads)}.` : ''}`,
140
+ input.ready?.length ? `Ready to use (made by tasks whose work is in the game):\n${input.ready.map((r) => `- ${r.path} (${r.kind}${r.placement ? `; in the game already at the placement ${r.placement}, through the placements seam: never add it again` : ''})`).join('\n')}` : 'Nothing from other tasks is ready yet: use only what exists in the project and what you make.',
141
+ input.references?.length ? `The reference: ${input.references.join(', ')} (open it with Read; never reproduce a specific character, logo or text from it).` : 'There is no reference picture: the brief comes from the request alone.',
142
+ ...extra,
143
+ `Your checks (task_check runs them all; the director's gate runs them again):\n${checks.map((c) => `- ${checkWords(c, { brief, reference: input.references?.[0] })}`).join('\n')}`,
144
+ task.placement ? `Your model takes over the blockout's placement ${task.placement}: the director puts it in the game there when your task ends.` : '',
145
+ task.accept?.critic?.length ? `The critic then judges your result against the reference and the brief on:\n${task.accept.critic.map((c) => `- ${c.id}: ${c.text}${c.camera || c.subject ? ` (${[c.camera ? `camera ${c.camera}` : '', c.subject ? `against the reference's subject ${c.subject}, the box the brief gives it` : ''].filter(Boolean).join('; ')})` : ''}`).join('\n')}` : '',
146
+ examples.length ? `Start from these exact tool inputs:\n${examples.map((e) => `- ${e}`).join('\n')}` : '',
147
+ ]
148
+ return {
149
+ kind: 'role',
150
+ key: `task:${task.id}:r${input.round}`,
151
+ systemPrompt: role.prompt,
152
+ userText: sections.filter(Boolean).join('\n\n'),
153
+ images: [...images],
154
+ builtIns: [...role.builtIns],
155
+ nwTools: [...role.nwTools],
156
+ skills: [...role.skills],
157
+ schema: jsonSchemaOf(schema),
158
+ maxTurns: role.maxTurns,
159
+ }
160
+ }
161
+
162
+ /**
163
+ * A role's default checks with any kind the board already gave left out, so
164
+ * the board's own check (with its exact camera, steps or path) always wins
165
+ * and a default is never run twice. The director's withDefaults does the
166
+ * same when it merges them.
167
+ */
168
+ export function withoutGiven(task, defaults) {
169
+ const given = new Set((task.accept?.checks ?? []).map((c) => c.kind))
170
+ return defaults.filter((c) => !given.has(c.kind))
171
+ }
172
+
173
+ /** The board's checks, the role's defaults and the two every task has
174
+ * (markers, ownership), for the task message: what the gate will run. */
175
+ export function checksOf(task, defaults) {
176
+ const out = [...(task.accept?.checks ?? []), ...withoutGiven(task, defaults)]
177
+ for (const kind of ['markers', 'ownership']) if (!out.some((c) => c.kind === kind)) out.push({ id: kind, kind })
178
+ return out
179
+ }
180
+
181
+ /** The brief's camera for a purpose, the player's when it has none. */
182
+ export function cameraFor(brief, purpose) {
183
+ const cameras = brief?.cameras ?? []
184
+ return (cameras.find((c) => c.purpose === purpose) ?? cameras.find((c) => c.purpose === 'player') ?? cameras[0])?.id ?? 'player'
185
+ }
186
+
187
+ /** The literal paths among a task's globs. */
188
+ export const literalOwned = (task) => (task.owns ?? []).filter((g) => !/[*?[{]/.test(g))
@@ -0,0 +1,171 @@
1
+ // The critic: the primary judge of how an attempt looks. A decision session
2
+ // on a top-tier model (the router picks it), with no tools: it gets the
3
+ // reference, its crops of the brief subjects the criteria name, the gate's
4
+ // shots at the task's cameras (for a model, its contact sheets and the
5
+ // pictures it was made from), nw_compare's side by side and the best
6
+ // attempt so far, and answers a CriticReport: rubric scores, each criterion
7
+ // met or not, a pairwise call against the best so far, and ranked changes,
8
+ // each concrete enough to check from the next picture, the director's when
9
+ // the brief itself contradicts the reference. Pixel metrics never pass an
10
+ // attempt on their own: they only stop a pass when something is grossly
11
+ // off (passes below) and help tell progress from stagnation.
12
+
13
+ import { CriticReport, GROSS_FLAGS, jsonSchemaOf } from '../director/contracts.mjs'
14
+ import { ANCHORS, DIMENSIONS, RUBRICS } from './rubrics.mjs'
15
+
16
+ /** The pass rule's thresholds [proposal, orchestrator spec 2.8]. */
17
+ export const MIN_SCORE = 3
18
+ export const PASS_MEAN = 3.5
19
+ /** The dimensions whose mean decides a pass of the whole game (the final
20
+ * gate); light is held only by MIN_SCORE there. */
21
+ export const MEAN_OF = ['form', 'detail', 'composition', 'colour']
22
+ export const MAX_SHOTS = 4
23
+
24
+ /**
25
+ * What each role's work is judged on: its own dimensions, never another
26
+ * role's. An artist task waits only on the blockout, so its shots hold the
27
+ * builder's stand-in forms in the artist's look; a modeller's contact sheet
28
+ * has no composition or light to judge. The critic scores all five either
29
+ * way, and its changes for the rest go to their owners. The final gate, and
30
+ * a task of a role not named here, are judged on all five.
31
+ */
32
+ export const JUDGED = {
33
+ builder: ['form', 'composition'],
34
+ artist: ['colour', 'light', 'detail'],
35
+ modeller: ['form', 'detail', 'colour'],
36
+ }
37
+ /** What detail means in an artist's gate: its materials, not the forms'. */
38
+ const JUDGED_NOTE = { artist: 'detail here is surface breakup and material variety, not the detail of the forms themselves' }
39
+
40
+ /** The dimensions a gate holds to MIN_SCORE and the ones whose mean must
41
+ * reach PASS_MEAN. */
42
+ export function judgedOf(task) {
43
+ const own = task?.id !== 'final' ? JUDGED[task?.role] : null
44
+ return own ? { held: own, mean: own } : { held: DIMENSIONS.map((d) => d.id), mean: MEAN_OF }
45
+ }
46
+
47
+ export const CRITIC_SCHEMA = jsonSchemaOf(CriticReport)
48
+
49
+ export const CRITIC_PROMPT = `You are the art critic of an Oda game team. You judge; you never praise, never edit anything and never talk to the creator. Your judgement decides whether an attempt passes, and your changes are what the next attempt does, so be exact.
50
+
51
+ Judge against this request: its brief, its reference, the vision's moments and the criteria the plan wrote for this task. You bring no style, palette, size or light of your own and no standard checklist: what good form, detail, colour or light is here comes from them, at the reference's quality bar, never against "good for a game an agent made". Compare in this order, because each one hides the next:
52
+ 1. Form: the shapes, silhouettes and proportions the brief names and the reference's subjects show (a crop of a subject is what its form should read as), and scale against the 1.75 m player.
53
+ 2. Detail: how much detail there is near, mid and far, against what the brief and the reference have. A stub grey material, or a box where the brief names a form, is a 1 for detail.
54
+ 3. Composition: what each of the brief's cameras frames, and what reads first.
55
+ 4. Colour: the brief's palette and values, as the reference has them.
56
+ 5. Light and atmosphere: the brief's light and atmosphere, as the reference has them.
57
+
58
+ Scores, 1 to 5, for every dimension:
59
+ ${Object.entries(ANCHORS)
60
+ .map(([n, words]) => `${n}: ${words}`)
61
+ .join('\n')}
62
+
63
+ - criteria: answer every criterion you are given, by its id, met or not, with a one-line note of what you saw.
64
+ - pairwise: compare this attempt with the best one so far at the same camera (the last picture, when there is one): better, same or worse. With no earlier attempt, first.
65
+ - copied: true when the attempt reproduces a specific character, logo or text from the reference. Drawing its mood, light, palette and forms is the point; copying a particular figure, mark or lettering is not allowed.
66
+ - changes: at most 8, most important first (rank 1 is the first to do). Each says what is wrong, where (which camera and which part of the picture), why it matters against the reference or the brief, the concrete fix, and the owner role (builder, artist, modeller, sound). Concrete and checkable, with numbers against the brief or the reference where you can: "the brief makes <a thing> <n> player heights; it is <m>"; "the reference's far band is <n> L* lighter than its near one; here it is <m>". When the brief itself contradicts the reference (a size, a proportion or a form it asks for that the reference or a subject's crop clearly shows otherwise), the change is the director's (owner director): say what the brief asks, what the reference shows and the brief as it should be; the director decides whether the brief changes.
67
+ - verdict: pass only when every criterion is met, no score of the dimensions this gate judges (the message names them) is below ${MIN_SCORE}, their mean is at least ${PASS_MEAN}, nothing is copied and no gross pixel flag of this task's own is raised (a flag the message names as another role's work, or as there before this task, never decides it); otherwise revise. Score all five dimensions either way: the ones this gate does not judge are another role's work, so they never decide the verdict, and a change for them names that role as its owner.
68
+ - confidence: 0 to 1, how sure you are of this judgement from these pictures.
69
+
70
+ The pixel metrics you are given are a floor, not the judgement: they catch a view that is grossly off (a palette or value far from the reference's, a layout that does not correlate) and cannot see quality. Answer only with the structured output.`
71
+
72
+ const MIME = /^image\/(png|jpeg|webp)$/
73
+
74
+ /**
75
+ * The critic's session for one gate (orchestrator spec 2.8). `input` is the
76
+ * director's CriticInput (contracts.mjs): the pictures go in the order the
77
+ * prompt names them (the reference, the shots at the task's cameras, at
78
+ * most four, the side by side, the best so far), and the words say which
79
+ * picture is which.
80
+ */
81
+ export function criticSpec(input) {
82
+ const images = []
83
+ const said = []
84
+ const add = (image, words) => {
85
+ if (!image?.data || !MIME.test(image.mime ?? '')) return
86
+ images.push({ mime: image.mime, data: image.data })
87
+ said.push(`Picture ${images.length}: ${words}.`)
88
+ }
89
+ const modeller = input.task?.role === 'modeller'
90
+ add(input.reference, 'the reference')
91
+ for (const s of input.subjects ?? []) add(s.image, `the reference's subject ${s.id} (${s.what}), cut from it: what its form should read as${s.role === 'transform' ? ' (a subject to transform: its role, place and size, never its likeness)' : ''}`)
92
+ for (const s of (input.shots ?? []).slice(0, MAX_SHOTS)) add(s.image, modeller ? `this attempt's contact sheet (${s.camera})` : `this attempt at the camera ${s.camera}`)
93
+ for (const s of input.inputs ?? []) add(s.image, `what this model was made from: ${s.what} (judge the model against the reference and the brief; this shows where a difference came from)`)
94
+ add(input.sideBySide, 'the reference (left) beside this attempt (right) at the reference camera, from nw_compare')
95
+ add(input.best, modeller ? "the best round so far, its colour sheet: make the pairwise call against it" : 'the best attempt so far at the same camera: make the pairwise call against it')
96
+ const role = input.task?.role
97
+ // The role's axes the critic can see in a picture (play is the play checks').
98
+ const rubric = (RUBRICS[role]?.dimensions ?? []).filter((d) => DIMENSIONS.some((x) => x.id === d.id))
99
+ const criteria = input.criteria ?? []
100
+ const metrics = input.metrics
101
+ const sections = [
102
+ input.scope === 'final'
103
+ ? 'This is the final gate: judge the whole game, every camera, against the reference and the brief.'
104
+ : `This is round ${input.round} of task ${input.task?.id} (${input.task?.role}: ${input.task?.title}). Its goal: ${input.task?.goal}`,
105
+ said.join('\n') || 'No picture came with this gate: judge nothing you cannot see, score what you cannot see 1, and say so in a change.',
106
+ input.best ? '' : 'There is no earlier attempt to compare with: pairwise is first.',
107
+ `The brief:\n${input.brief}`,
108
+ input.pillars?.length ? `The pillars:\n${input.pillars.map((p) => `- ${p}`).join('\n')}` : '',
109
+ input.moments?.length ? `The signature moments this covers:\n${input.moments.map((m) => `- ${m.id} (camera ${m.camera}). Sees: ${m.sees}. Does: ${m.does}. Accepted when: ${m.acceptance}`).join('\n')}` : '',
110
+ criteria.length ? `The criteria, each to answer by its id:\n${criteria.map((c) => `- ${c.id}: ${c.text}${c.camera || c.subject ? ` (${[c.camera ? `camera ${c.camera}` : '', c.subject ? `subject ${c.subject}` : ''].filter(Boolean).join('; ')})` : ''}`).join('\n')}` : 'There are no task criteria: criteria is empty.',
111
+ input.briefChanges?.length ? `The director changed the brief since these criteria were written:\n${input.briefChanges.map((c) => `- ${c}`).join('\n')}\nWhere a criterion's number differs from the brief now, the brief wins.` : '',
112
+ rubric.length ? `For ${role} work, look first at:\n${rubric.map((d) => `- ${d.id}: ${d.what}`).join('\n')}` : '',
113
+ `Your five scores are ${DIMENSIONS.map((d) => `${d.id} (${d.what})`).join('; ')}.`,
114
+ judgedText(input),
115
+ metrics
116
+ ? `The pixel metrics at ${metrics.camera} (a floor, not the judgement): palette deltaE ${metrics.colour?.paletteDeltaE}, mean L* ${metrics.colour?.deltaMeanL} against the reference, contrast x${metrics.colour?.contrastRatio}, chroma x${metrics.colour?.chromaRatio}, L* layout correlation ${metrics.structure?.correlation}, edges x${metrics.structure?.edgeRatio}, distance ${metrics.distance}. Flags: ${(input.flags ?? metrics.flags ?? []).join(', ') || 'none'}.`
117
+ : modeller
118
+ ? 'There are no pixel metrics for an asset: judge the sheets against the reference and the brief\'s forms.'
119
+ : '',
120
+ ]
121
+ return {
122
+ kind: 'decision',
123
+ key: input.key ?? `critic:${input.task?.id ?? 'final'}:r${input.round ?? 0}`,
124
+ systemPrompt: CRITIC_PROMPT,
125
+ userText: sections.filter(Boolean).join('\n\n'),
126
+ images,
127
+ builtIns: [],
128
+ nwTools: [],
129
+ skills: [],
130
+ schema: CRITIC_SCHEMA,
131
+ maxTurns: 4,
132
+ }
133
+ }
134
+
135
+ /** Which dimensions decide this gate, in words. */
136
+ function judgedText(input) {
137
+ const task = input.scope === 'final' ? { id: 'final' } : input.task
138
+ const { held, mean } = judgedOf(task)
139
+ if (held.length === DIMENSIONS.length) return `This gate judges all five: none below ${MIN_SCORE}, and the mean of ${mean.join(', ')} at least ${PASS_MEAN}.`
140
+ const note = JUDGED_NOTE[task?.role]
141
+ return `This gate judges ${task.role} work on ${held.join(', ')} only${note ? ` (${note})` : ''}: none of them below ${MIN_SCORE} and their mean at least ${PASS_MEAN}. The other dimensions belong to other roles' work: score them, but they do not decide the verdict.`
142
+ }
143
+
144
+ /** Why a critic's report does not pass, one sentence a reason; empty when it passes. */
145
+ export function whyNot(report, metrics, task) {
146
+ if (!report || typeof report !== 'object' || !report.scores) return ['The critic sent no report.']
147
+ const out = []
148
+ if (report.verdict !== 'pass') out.push('The critic says revise.')
149
+ const met = new Map((report.criteria ?? []).map((c) => [c.id, c.met === true]))
150
+ for (const c of task?.accept?.critic ?? []) if (met.get(c.id) !== true) out.push(`The criterion ${c.id} is not met.`)
151
+ for (const c of report.criteria ?? []) if (c.met !== true && !(task?.accept?.critic ?? []).some((t) => t.id === c.id)) out.push(`The criterion ${c.id} is not met.`)
152
+ const { held, mean: of } = judgedOf(task)
153
+ const low = held.map((k) => [k, report.scores[k]]).filter(([, v]) => !(v >= MIN_SCORE))
154
+ if (low.length) out.push(`Scores below ${MIN_SCORE}: ${low.map(([k, v]) => `${k} ${v}`).join(', ')}.`)
155
+ const mean = of.reduce((s, k) => s + (Number(report.scores[k]) || 0), 0) / of.length
156
+ if (!(mean >= PASS_MEAN)) out.push(`The mean of ${of.join(', ')} is ${Math.round(mean * 100) / 100}, under ${PASS_MEAN}.`)
157
+ if (report.copied === true) out.push('It copies a specific character, logo or text from the reference.')
158
+ const gross = (metrics?.flags ?? []).filter((f) => GROSS_FLAGS.includes(f))
159
+ if (gross.length) out.push(`The pixel metrics raise ${gross.join(', ')}.`)
160
+ return out
161
+ }
162
+
163
+ /** The pass rule (orchestrator spec 2.8): the critic's verdict, every
164
+ * criterion, the scores of the dimensions the task's role is judged on,
165
+ * nothing copied, and no gross pixel flag. */
166
+ export function passes(report, metrics, task) {
167
+ return whyNot(report, metrics, task).length === 0
168
+ }
169
+
170
+ /** What the director's gate takes as its critic. */
171
+ export const critic = { criticSpec, passes, whyNot, CRITIC_SCHEMA }
@@ -0,0 +1,39 @@
1
+ // The team: five specialist roles the director dispatches tasks to, and the
2
+ // critic that judges their pictures. Each role is a RoleDef (orchestrator
3
+ // spec 3.7): its lane, its static prompt, its tools and skills, the files it
4
+ // may own, its default checks, its rubric and the session it runs for one
5
+ // attempt at a task. Model and effort are never a role's: the router picks
6
+ // them for every attempt.
7
+ //
8
+ // Few roles, with files that do not overlap, so parallel sessions in one
9
+ // working tree never write the same file: the builder owns the game's
10
+ // composition, the artist the look module, the modeller blender/ and
11
+ // assets/, the sound designer src/audio/, and the playtester nothing. The
12
+ // seams (src/look/index.ts, src/audio/index.ts), brief.md and .nowhere/ are
13
+ // the director's alone.
14
+
15
+ import { inside } from '../director/board.mjs'
16
+ import { artist } from './artist.mjs'
17
+ import { builder } from './builder.mjs'
18
+ import { modeller } from './modeller.mjs'
19
+ import { qa } from './qa.mjs'
20
+ import { sound } from './sound.mjs'
21
+
22
+ export { critic, criticSpec, passes, whyNot, CRITIC_SCHEMA, CRITIC_PROMPT } from './critic.mjs'
23
+ export { ROLE_CHECKS } from './checks.mjs'
24
+
25
+ /** RoleId to RoleDef, in the order the board groups them. */
26
+ export const ROLES = Object.freeze({ builder, artist, modeller, sound, qa })
27
+
28
+ /** Whether a role may own a project-relative path or glob (its mayOwn, with
29
+ * the `!` parts carved out). */
30
+ export const ownable = (role, glob) => (ROLES[role]?.mayOwn?.length ? inside(glob, ROLES[role].mayOwn) : false)
31
+
32
+ /** The roles as PLAN reads them: what each does, how big a task is, which
33
+ * files it may own, its lane and the checks it brings. */
34
+ export const ROLE_CATALOGUE = Object.values(ROLES)
35
+ .map((r) => {
36
+ const owns = r.mayOwn.length ? r.mayOwn.map((g) => (g.startsWith('!') ? `not ${g.slice(1)}` : g)).join(', ') : 'nothing (read-only)'
37
+ return `- ${r.id} (lane ${r.lane}; may own ${owns}): ${r.catalogue.does} Task size: ${r.catalogue.size} Checks for its work: ${r.catalogue.checks.join(', ') || 'none (its gate is its report)'}.`
38
+ })
39
+ .join('\n')