oda-engine 0.0.0-stage → 0.1.0

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 +90 -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-CB77cP9U.js +1 -0
  197. package/web-dist/assets/KTX2Loader-6OIWUF7s.js +2 -0
  198. package/web-dist/assets/SPZLoader-zYj0Alfv.js +1 -0
  199. package/web-dist/assets/gaussianSplat-CJTI1sEh.js +1 -0
  200. package/web-dist/assets/index-CcjyyQco.css +1 -0
  201. package/web-dist/assets/index-DMyJcoZJ.js +693 -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,107 @@
1
+ // Pictures the reference tools hand back: a PNG writer and the few drawing
2
+ // steps their sheets need (a panel copied in, a filled box, a line). RGBA in,
3
+ // PNG bytes out, with node's own zlib (deflate and crc32), so a side by side
4
+ // or a reference sheet needs no image library and comes out the same every
5
+ // time for the same input.
6
+
7
+ import { crc32, deflateSync } from 'node:zlib'
8
+ import { resample } from './facts.mjs'
9
+
10
+ const SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])
11
+
12
+ function chunk(type, body) {
13
+ const head = Buffer.alloc(8)
14
+ head.writeUInt32BE(body.length, 0)
15
+ head.write(type, 4, 'latin1')
16
+ const crc = Buffer.alloc(4)
17
+ crc.writeUInt32BE(crc32(Buffer.concat([head.subarray(4), body])) >>> 0, 0)
18
+ return Buffer.concat([head, body, crc])
19
+ }
20
+
21
+ /** A picture ({ data: RGBA, width, height }) as PNG bytes: 8-bit RGBA, each
22
+ * row with the Sub filter, which keeps flat panels and gradients small. */
23
+ export function encodePng({ data, width, height }) {
24
+ const ihdr = Buffer.alloc(13)
25
+ ihdr.writeUInt32BE(width, 0)
26
+ ihdr.writeUInt32BE(height, 4)
27
+ ihdr[8] = 8
28
+ ihdr[9] = 6
29
+ const stride = width * 4
30
+ const raw = Buffer.alloc((stride + 1) * height)
31
+ for (let y = 0; y < height; y++) {
32
+ const o = y * (stride + 1)
33
+ raw[o] = 1
34
+ for (let x = 0; x < stride; x++) {
35
+ const v = data[y * stride + x]
36
+ raw[o + 1 + x] = (v - (x >= 4 ? data[y * stride + x - 4] : 0)) & 255
37
+ }
38
+ }
39
+ return Buffer.concat([SIGNATURE, chunk('IHDR', ihdr), chunk('IDAT', deflateSync(raw, { level: 6 })), chunk('IEND', Buffer.alloc(0))])
40
+ }
41
+
42
+ /** A picture of one colour. */
43
+ export function canvas(width, height, rgb = [0, 0, 0]) {
44
+ const data = new Uint8Array(width * height * 4)
45
+ for (let i = 0; i < width * height; i++) {
46
+ data[i * 4] = rgb[0]
47
+ data[i * 4 + 1] = rgb[1]
48
+ data[i * 4 + 2] = rgb[2]
49
+ data[i * 4 + 3] = 255
50
+ }
51
+ return { data, width, height }
52
+ }
53
+
54
+ /** `src` drawn into `dst` at (x, y), resized to w x h first when given. */
55
+ export function blit(dst, src, x, y, w = src.width, h = src.height) {
56
+ const pic = w === src.width && h === src.height ? src : resample(src, w, h)
57
+ for (let row = 0; row < pic.height; row++) {
58
+ const ty = y + row
59
+ if (ty < 0 || ty >= dst.height) continue
60
+ for (let col = 0; col < pic.width; col++) {
61
+ const tx = x + col
62
+ if (tx < 0 || tx >= dst.width) continue
63
+ const s = (row * pic.width + col) * 4
64
+ const d = (ty * dst.width + tx) * 4
65
+ dst.data[d] = pic.data[s]
66
+ dst.data[d + 1] = pic.data[s + 1]
67
+ dst.data[d + 2] = pic.data[s + 2]
68
+ dst.data[d + 3] = 255
69
+ }
70
+ }
71
+ return dst
72
+ }
73
+
74
+ /** A filled box, clipped to the picture. */
75
+ export function fillRect(dst, x, y, w, h, rgb) {
76
+ const x0 = Math.max(0, Math.round(x))
77
+ const y0 = Math.max(0, Math.round(y))
78
+ const x1 = Math.min(dst.width, Math.round(x + w))
79
+ const y1 = Math.min(dst.height, Math.round(y + h))
80
+ for (let ty = y0; ty < y1; ty++) {
81
+ for (let tx = x0; tx < x1; tx++) {
82
+ const d = (ty * dst.width + tx) * 4
83
+ dst.data[d] = rgb[0]
84
+ dst.data[d + 1] = rgb[1]
85
+ dst.data[d + 2] = rgb[2]
86
+ dst.data[d + 3] = 255
87
+ }
88
+ }
89
+ return dst
90
+ }
91
+
92
+ /** A straight line `width` pixels thick, from (x0, y0) to (x1, y1). */
93
+ export function line(dst, x0, y0, x1, y1, rgb, width = 1) {
94
+ const steps = Math.max(1, Math.ceil(Math.hypot(x1 - x0, y1 - y0)))
95
+ const half = (width - 1) / 2
96
+ for (let i = 0; i <= steps; i++) {
97
+ const t = i / steps
98
+ fillRect(dst, x0 + (x1 - x0) * t - half, y0 + (y1 - y0) * t - half, width, width, rgb)
99
+ }
100
+ return dst
101
+ }
102
+
103
+ /** '#rrggbb' as [r, g, b]. */
104
+ export const rgbOf = (hex) => {
105
+ const n = parseInt(String(hex).replace('#', ''), 16)
106
+ return [(n >> 16) & 255, (n >> 8) & 255, n & 255]
107
+ }
@@ -0,0 +1,63 @@
1
+ // Which records of a manifest name a picture (refs/board.json, the
2
+ // quarantine's manifest, the asset ledger), and the grade they give it. One
3
+ // rule for the agent's tools (look.mjs reads it before a picture is measured
4
+ // or sent to a model) and the mood board (moodBoard.cjs says "Only to look
5
+ // at" from it), so what the agent refuses and what the board says it will
6
+ // not send never disagree.
7
+
8
+ import { BLOCKED_HOSTS } from '../shared.mjs'
9
+
10
+ /** A name as a manifest writes it, compared as a project path. */
11
+ const norm = (v) => v.replace(/\\/g, '/').replace(/^\.\//, '')
12
+
13
+ /** The names a record gives its file. */
14
+ export function namesOf(record) {
15
+ return [record?.path, record?.file, record?.name, record?.local, record?.ref, record?.reference].filter((x) => typeof x === 'string').map(norm)
16
+ }
17
+
18
+ /** Every object anywhere in a manifest that names the file: by its project
19
+ * path, its file name (alone or at the end of a path), or its hash. */
20
+ export function recordsFor(doc, { rel, name, sha }) {
21
+ const found = []
22
+ const walk = (v, depth) => {
23
+ if (depth > 8 || v === null || typeof v !== 'object') return
24
+ if (Array.isArray(v)) {
25
+ for (const x of v) walk(x, depth + 1)
26
+ return
27
+ }
28
+ const names = namesOf(v)
29
+ if ((typeof sha === 'string' && sha && v.sha256 === sha) || names.some((n) => n === rel || n === name || n.endsWith(`/${name}`))) found.push(v)
30
+ for (const x of Object.values(v)) walk(x, depth + 1)
31
+ }
32
+ walk(doc, 0)
33
+ return found
34
+ }
35
+
36
+ /** Graded C: for the creator's eyes only, never fed to a model. */
37
+ export const gradeC = (record) => String(record?.grade ?? '').trim().toUpperCase() === 'C'
38
+
39
+ const blocked = (v) => typeof v === 'string' && BLOCKED_HOSTS.test(v)
40
+
41
+ /** Whether a record says the file came from a site whose pictures may not
42
+ * be fed to a model (ArtStation, Pinterest, Behance). */
43
+ export function fromBlockedSite(record) {
44
+ const source = record?.source !== null && typeof record?.source === 'object' && !Array.isArray(record.source) ? record.source : {}
45
+ return [record?.host, record?.url, record?.referrer, source.host, source.url].some(blocked)
46
+ }
47
+
48
+ /** Only to look at: some record naming the picture grades it C or says it
49
+ * came from such a site. */
50
+ export const lookOnly = (records) => records.some((r) => gradeC(r) || fromBlockedSite(r))
51
+
52
+ /** A picture's grade from the records naming it: C when any of them says C,
53
+ * else the grade of the one naming its exact path, else of the first. */
54
+ export function gradeOf(records, rel) {
55
+ if (records.some(gradeC)) return 'C'
56
+ const exact = records.find((r) => namesOf(r).includes(rel))
57
+ const g = String((exact ?? records[0])?.grade ?? '').trim().toUpperCase()
58
+ return g === 'A' || g === 'B' ? g : null
59
+ }
60
+
61
+ /** The record that best says where a picture came from: the one naming its
62
+ * exact path, else the first naming it at all. */
63
+ export const bestRecord = (records, rel) => records.find((r) => namesOf(r).includes(rel)) ?? records[0] ?? null
@@ -0,0 +1,252 @@
1
+ // Web references: pictures the agent found on the web and kept with
2
+ // nw_keep_pictures (tools/pictures.mjs). Each one sits under refs/web/ with
3
+ // its record on refs/board.json: the page it came from, its site, its
4
+ // licence and its use. A web reference is for looking at: the agent, the
5
+ // reference tools and the judge see it, but it never becomes one of the
6
+ // space's files and is never sent to a generator, unless its licence is CC0
7
+ // or public domain (use "look and generate", generate true). Everything else
8
+ // is "look only". The rules here are read by the generators' input check
9
+ // (tools/generate.mjs), asset_import (assets/import.mjs),
10
+ // nw_take_download (tools/cards.mjs), nw_blender's ledger line
11
+ // (tools/blender.mjs), the ledger's backfill (assets/ledger.mjs) and the
12
+ // publish pre-flight (publish.cjs), so all of them refuse the same files.
13
+ //
14
+ // Electron-free, no network: the CLI vendors it with the tools.
15
+
16
+ import { createHash } from 'node:crypto'
17
+ import fsp from 'node:fs/promises'
18
+ import path from 'node:path'
19
+ import { decodeImage } from './decode.mjs'
20
+ import { recordsFor } from './records.mjs'
21
+
22
+ /** Where kept web references live, and the board that records them. */
23
+ export const WEB_DIR = 'refs/web'
24
+ export const BOARD_FILE = 'refs/board.json'
25
+ /** The licences under which a web picture may also be a generator's input. */
26
+ export const FREE_LICENSES = Object.freeze(['CC0-1.0', 'LicenseRef-PD'])
27
+ export const LOOK_ONLY = 'look only'
28
+ export const LOOK_AND_GENERATE = 'look and generate'
29
+
30
+ const slash = (p) => String(p).replace(/\\/g, '/').replace(/^\.\//, '')
31
+ const isObj = (v) => v !== null && typeof v === 'object' && !Array.isArray(v)
32
+
33
+ /** Whether a record is a kept web reference: written by nw_keep_pictures, or
34
+ * naming a file under refs/web/. */
35
+ export function isWebRecord(record) {
36
+ if (!isObj(record)) return false
37
+ return record.kind === 'web-reference' || [record.path, record.file].some((p) => typeof p === 'string' && slash(p).startsWith(`${WEB_DIR}/`))
38
+ }
39
+
40
+ /** A web record that may not be a generator's input or one of the space's files. */
41
+ export const webLookOnly = (record) => isWebRecord(record) && record.generate !== true
42
+
43
+ /** The board's document, or null when there is none or it does not parse. */
44
+ export async function readBoardDoc(projectRoot) {
45
+ try {
46
+ return JSON.parse(await fsp.readFile(path.join(projectRoot, BOARD_FILE), 'utf8'))
47
+ } catch {
48
+ return null
49
+ }
50
+ }
51
+
52
+ /** Why a look-only record is look only, in a few words. */
53
+ export function lookOnlyWhy(record) {
54
+ const name = record?.license?.name ?? record?.license?.spdx ?? null
55
+ return `${name ? `its licence is ${name}` : 'its licence is unknown'}, not CC0 or public domain`
56
+ }
57
+
58
+ /**
59
+ * The look-only web record of a project picture, or null. A picture under
60
+ * refs/web/ with no record saying it is free to use counts as look only.
61
+ */
62
+ export async function webLookOnlyOf(projectRoot, { rel, sha = null, doc = undefined }) {
63
+ const board = doc === undefined ? await readBoardDoc(projectRoot) : doc
64
+ const r = rel ? slash(rel) : null
65
+ const records = board ? recordsFor(board, { rel: r ?? '\u0000', name: r ? path.basename(r) : '\u0000', sha }) : []
66
+ const lookOnly = records.find(webLookOnly)
67
+ if (lookOnly) return lookOnly
68
+ if (r && r.startsWith(`${WEB_DIR}/`) && !records.some((x) => isWebRecord(x) && x.generate === true)) return { path: r, kind: 'web-reference', generate: false, license: null }
69
+ return null
70
+ }
71
+
72
+ const sha256Of = async (file) => createHash('sha256').update(await fsp.readFile(file)).digest('hex')
73
+
74
+ /** Every look-only web record on a board, whatever its shape. */
75
+ function lookOnlyRecords(doc) {
76
+ const found = []
77
+ const walk = (v, depth) => {
78
+ if (depth > 8 || v === null || typeof v !== 'object') return
79
+ if (Array.isArray(v)) {
80
+ for (const x of v) walk(x, depth + 1)
81
+ return
82
+ }
83
+ if (webLookOnly(v)) found.push(v)
84
+ for (const x of Object.values(v)) walk(x, depth + 1)
85
+ }
86
+ walk(doc, 0)
87
+ return found
88
+ }
89
+
90
+ /** The hashes of the look-only web pictures, each with its record: those
91
+ * the board records, and every file under refs/web/ that no record calls
92
+ * free, so a missing or rewritten board forgets nothing still on disk. */
93
+ async function lookOnlyHashes(projectRoot, board) {
94
+ const out = new Map()
95
+ for (const r of board ? lookOnlyRecords(board) : []) if (typeof r.sha256 === 'string') out.set(r.sha256, r)
96
+ let names = []
97
+ try {
98
+ names = await fsp.readdir(path.join(projectRoot, WEB_DIR))
99
+ } catch {
100
+ // no refs/web/
101
+ }
102
+ for (const name of names) {
103
+ const rel = `${WEB_DIR}/${name}`
104
+ let sha
105
+ try {
106
+ sha = await sha256Of(path.join(projectRoot, rel))
107
+ } catch {
108
+ continue
109
+ }
110
+ if (out.has(sha)) continue
111
+ const record = await webLookOnlyOf(projectRoot, { rel, sha, doc: board })
112
+ if (record) out.set(sha, record)
113
+ }
114
+ return out
115
+ }
116
+
117
+ /** Each of `files` (absolute paths) that is a look-only web reference, by
118
+ * its content (a name in quarantine says nothing about where it came
119
+ * from), or by sitting under refs/web/ with no record calling it free:
120
+ * [{ file, record, why }]. */
121
+ export async function webLookOnlyAll(projectRoot, files) {
122
+ const board = await readBoardDoc(projectRoot)
123
+ const hashes = await lookOnlyHashes(projectRoot, board)
124
+ const found = []
125
+ for (const file of files) {
126
+ const rel = slash(path.relative(projectRoot, file))
127
+ const inWeb = rel.startsWith(`${WEB_DIR}/`)
128
+ if (hashes.size === 0 && !inWeb) continue
129
+ let sha
130
+ try {
131
+ sha = await sha256Of(file)
132
+ } catch {
133
+ continue
134
+ }
135
+ const record = hashes.get(sha) ?? (inWeb ? await webLookOnlyOf(projectRoot, { rel, sha, doc: board }) : null)
136
+ if (record) found.push({ file, record, why: lookOnlyWhy(record) })
137
+ }
138
+ return found
139
+ }
140
+
141
+ /** The first of `files` that is a look-only web reference, or null. */
142
+ export async function webLookOnlyAmong(projectRoot, files) {
143
+ return (await webLookOnlyAll(projectRoot, files))[0] ?? null
144
+ }
145
+
146
+ // ---------------------------------------------------------------- near copies
147
+
148
+ /** How far apart two picture prints may be, on average over their 192
149
+ * values out of 255, for the pictures to be one re-encoded or resized. */
150
+ export const NEAR_PRINT = 6
151
+
152
+ /**
153
+ * A picture's print: its 8 x 8 colour thumbnail, each cell the average of
154
+ * its pixels, as 192 bytes in base64. Re-encoding or resizing moves it by a
155
+ * point or two; another picture, even of the same place, by far more. Null
156
+ * for a picture almost of one colour, which cannot be told from another.
157
+ * `pic` is decodeImage's answer.
158
+ */
159
+ export function printOf(pic) {
160
+ if (!pic?.ok || !(pic.width > 0) || !(pic.height > 0)) return null
161
+ const { data, width, height } = pic
162
+ const cells = Buffer.alloc(192)
163
+ const greys = []
164
+ for (let cy = 0; cy < 8; cy++) {
165
+ for (let cx = 0; cx < 8; cx++) {
166
+ const x0 = Math.floor((cx * width) / 8)
167
+ const x1 = Math.max(x0 + 1, Math.floor(((cx + 1) * width) / 8))
168
+ const y0 = Math.floor((cy * height) / 8)
169
+ const y1 = Math.max(y0 + 1, Math.floor(((cy + 1) * height) / 8))
170
+ const sum = [0, 0, 0]
171
+ let n = 0
172
+ for (let y = y0; y < y1; y++) {
173
+ for (let x = x0; x < x1; x++) {
174
+ const i = (y * width + x) * 4
175
+ sum[0] += data[i]
176
+ sum[1] += data[i + 1]
177
+ sum[2] += data[i + 2]
178
+ n++
179
+ }
180
+ }
181
+ const at = (cy * 8 + cx) * 3
182
+ for (let c = 0; c < 3; c++) cells[at + c] = Math.round(sum[c] / n)
183
+ greys.push((sum[0] + sum[1] + sum[2]) / (3 * n))
184
+ }
185
+ }
186
+ const mean = greys.reduce((a, b) => a + b, 0) / greys.length
187
+ const spread = Math.sqrt(greys.reduce((a, g) => a + (g - mean) ** 2, 0) / greys.length)
188
+ return spread < 4 ? null : cells.toString('base64')
189
+ }
190
+
191
+ /** How far apart two prints are: the mean difference of their values. */
192
+ export function printDistance(a, b) {
193
+ const x = Buffer.from(a, 'base64')
194
+ const y = Buffer.from(b, 'base64')
195
+ if (x.length !== 192 || y.length !== 192) return Infinity
196
+ let d = 0
197
+ for (let i = 0; i < 192; i++) d += Math.abs(x[i] - y[i])
198
+ return d / 192
199
+ }
200
+
201
+ /**
202
+ * The look-only web record whose picture `bytes` is, re-encoded or resized
203
+ * (a copy made with sips, python or ffmpeg has a hash of its own), or null.
204
+ * Decodes only when the board has a look-only record with a print. A crop
205
+ * is a new picture to this: it is not caught.
206
+ */
207
+ export async function webLookOnlyNear(projectRoot, bytes, { rpc = null, doc = undefined } = {}) {
208
+ const board = doc === undefined ? await readBoardDoc(projectRoot) : doc
209
+ const printed = board ? lookOnlyRecords(board).filter((r) => typeof r.print === 'string') : []
210
+ if (printed.length === 0) return null
211
+ const print = printOf(await decodeImage(bytes, { maxEdge: 256, rpc }).catch(() => null))
212
+ if (!print) return null
213
+ for (const record of printed) {
214
+ const distance = printDistance(print, record.print)
215
+ if (distance <= NEAR_PRINT) return { record, why: lookOnlyWhy(record), distance }
216
+ }
217
+ return null
218
+ }
219
+
220
+ /**
221
+ * Adds a web record to refs/board.json, in place of any record of the same
222
+ * picture, keeping everything else the board holds: a board that is a list
223
+ * gets it appended; any other board keeps its records under "web".
224
+ */
225
+ export async function writeWebRecord(projectRoot, record) {
226
+ const file = path.join(projectRoot, BOARD_FILE)
227
+ let doc = await readBoardDoc(projectRoot)
228
+ const same = (r) => isObj(r) && (r.sha256 === record.sha256 || slash(r.path ?? '') === record.path)
229
+ if (Array.isArray(doc)) doc = [...doc.filter((r) => !same(r)), record]
230
+ else {
231
+ doc = isObj(doc) ? doc : {}
232
+ doc.web = [...(Array.isArray(doc.web) ? doc.web.filter((r) => !same(r)) : []), record]
233
+ }
234
+ await fsp.mkdir(path.dirname(file), { recursive: true })
235
+ await fsp.writeFile(file, `${JSON.stringify(doc, null, 2)}\n`)
236
+ return doc
237
+ }
238
+
239
+ /** The web references brief.json cites, in its order, at most `max`: what
240
+ * the judge is shown beside the targets (tools/loop.mjs nw_round). Three,
241
+ * because each is sent again as image tokens to every judged round (to
242
+ * both judges when there are two), paid on the creator's key or plan. */
243
+ export function briefWebReferences(brief, max = 3) {
244
+ const refs = Array.isArray(brief?.references) ? brief.references : []
245
+ const out = []
246
+ for (const r of refs) {
247
+ const p = typeof r?.path === 'string' ? slash(r.path) : ''
248
+ if (p.startsWith(`${WEB_DIR}/`) && !out.includes(p)) out.push(p)
249
+ if (out.length >= max) break
250
+ }
251
+ return out
252
+ }
@@ -0,0 +1,69 @@
1
+ // The artist: the planet's look (sky, fog, light, tone curve, grade) through
2
+ // look_apply, and the materials and shaders of its interface module, both
3
+ // from the brief's numbers. Judged by the critic against the reference, with
4
+ // nw_compare's pixel flags as the floor.
5
+
6
+ import { RoleReport } from '../director/contracts.mjs'
7
+ import { SHARED_RULES, buildSession, cameraFor, checksOf, literalOwned } from './common.mjs'
8
+ import { RUBRICS } from './rubrics.mjs'
9
+
10
+ export const ARTIST_PROMPT = `You are the artist on an Oda game team: you set the planet's look and make its materials and shaders. You work from the brief and the reference through the tools; you never talk to the creator, and only the director reads your report.
11
+
12
+ ## Your work
13
+
14
+ - The look first, before any material: a wrong sun makes every material look wrong. Turn the brief into look_apply set values: the sun's direction from light.sunElevationDeg and sunAzimuthDeg and its colour from colourTempK; the fog's colour and distances from atmosphere.fog (colour, nearM, farM, height), or fog null when the brief has none; exposure and contrast from values (its key, range and contrast); the sky's colours, the grade's temperature and saturation from the palette and the facts the brief cites. look_apply is the only way you change game.config.json, and only its look keys (sky, fog, lighting, bloom, look).
15
+ - Then the materials of your interface: the module your task names (beside src/look/index.ts, which is the director's) exports every named material, each written for this brief in TSL (nowhere:tsl-r185 has the API; the SDK has no ready-made materials): decide from the brief's materials, palette, light and detail what each surface needs (its colours and roughness range, its pattern and how it varies, whether it moves or glows) and build that node graph. A material left at a mid grey is a stub, and the critic scores it as one.
16
+ - Look after every change: nw_view at your task's cameras, nw_compare at the reference camera (the reference beside the view, and the flags), look_compare for which knob to turn. Change one or two things a round, the biggest difference first, and say the numbers ("mean L* <view> against <reference>; exposure <from> to <to>").
17
+ - The skills: nowhere:look-dev (from the brief's numbers to look values), nowhere:art-direction (judging a view against a reference), nowhere:tsl-r185 before any material.
18
+ - nw_status names a material that failed to build (it is drawn black): fix it before anything else.
19
+
20
+ ${SHARED_RULES}`
21
+
22
+ const LOOK_PARTS = ['palette', 'values', 'light', 'atmosphere', 'materials', 'detail', 'performance', 'exclusions']
23
+
24
+ export const artist = {
25
+ id: 'artist',
26
+ lane: 'preview',
27
+ prompt: ARTIST_PROMPT,
28
+ builtIns: ['Read', 'Write', 'Edit', 'Glob', 'Grep', 'TodoWrite', 'Skill'],
29
+ nwTools: ['nw_docs', 'nw_schema', 'nw_guide', 'nw_check', 'nw_view', 'nw_status', 'nw_logs', 'nw_eval', 'look_apply', 'look_compare', 'nw_reference', 'nw_compare'],
30
+ skills: ['nowhere:look-dev', 'nowhere:tsl-r185', 'nowhere:art-direction'],
31
+ mayOwn: ['src/look/**', '!src/look/index.ts'],
32
+ configKeys: ['sky', 'fog', 'lighting', 'bloom', 'look'],
33
+ rubric: RUBRICS.artist,
34
+ maxTurns: 80,
35
+ catalogue: {
36
+ does: "The look (sky, fog, sun, tone curve, grade, bloom, AO) through look_apply from the brief's light, atmosphere and values, and the materials and shaders of one interface module under src/look/ from the brief's colours and roughness.",
37
+ size: 'One look pass, or one materials module of up to about 8 materials, per task.',
38
+ checks: ['build', 'runtime', 'compare', 'palette', 'module'],
39
+ },
40
+ /**
41
+ * build, runtime, compare at the reference camera (the player's without a
42
+ * reference camera), palette on its files and, with the board's
43
+ * interfaces, module for its interface.
44
+ */
45
+ defaultChecks(task, brief, { interfaces = [] } = {}) {
46
+ const out = [
47
+ { id: 'build', kind: 'build' },
48
+ { id: 'runtime', kind: 'runtime' },
49
+ { id: 'compare', kind: 'compare', camera: cameraFor(brief, 'reference') },
50
+ ]
51
+ const files = (task.owns ?? []).filter((g) => g.startsWith('src/look/'))
52
+ if (files.length) out.push({ id: 'palette', kind: 'palette', files })
53
+ const iface = interfaces.find((i) => i.id === task.interface)
54
+ const module = iface?.module ?? (task.interface ? literalOwned(task).find((p) => /^src\/look\/.+\.ts$/.test(p)) : undefined)
55
+ if (module) out.push({ id: 'module', kind: 'module', path: module, exports: iface?.names ?? [] })
56
+ return out
57
+ },
58
+ checksFor(task, brief) {
59
+ return checksOf(task, this.defaultChecks(task, brief))
60
+ },
61
+ session(task, input) {
62
+ return buildSession(this, task, input, {
63
+ parts: LOOK_PARTS,
64
+ schema: RoleReport,
65
+ images: input.refImages ?? [],
66
+ extra: ["When you set the look, cite in your report which fact each value came from (\"fog far <metres>: atmosphere.fog.farM\")."],
67
+ })
68
+ },
69
+ }
@@ -0,0 +1,79 @@
1
+ // The builder: the layout at the brief's scales, the generators (terrain,
2
+ // scatter, instancing), the gameplay and the integration of what the other
3
+ // roles make. The only role that owns src/main.ts, scene.json and the
4
+ // config's non-look keys. Its blockout makes the production's cameras.
5
+
6
+ import { RoleReport } from '../director/contracts.mjs'
7
+ import { POINT, SHARED_RULES, buildSession, checksOf, playExample, playKeys } from './common.mjs'
8
+ import { RUBRICS } from './rubrics.mjs'
9
+
10
+ export const BUILDER_PROMPT = `You are the builder on an Oda game team: you lay out the world, write its generators and its gameplay, and put together what the other roles make. You work from the brief and the vision; you never talk to the creator, and only the director reads your report.
11
+
12
+ ## Your work
13
+
14
+ - One module per concern under src/world/ (terrain, layout, scatter, landmarks) and src/game/ (rules, state, interactions); src/main.ts stays the composition that calls them. Read nw_docs before your first game code.
15
+ - Sizes are the brief's, in metres against the 1.75 m player (forms.scale), and the reference's subjects keep the proportions and the places the picture gives them (subjects: each a box of the picture). A size the brief does not give is one you decide from what the thing is for in this game, and list as an assumption. Keep placed models at their real size ("normalize": false in scene.json). The map is as large as the brief's map says (tiles in game.config.json).
16
+ - A blockout task (makesCameras) lays out the whole game roughly and early: the ground at the brief's scale, the spawn (config.player.spawn), the paths and the landmarks as stand-ins at their real sizes, every request element present. Then every brief camera becomes an nw_view shot that frames what the brief says: the reference camera like the reference (its height, pitch and lens, the aspect the brief gives it, and its horizon at the brief's horizonY when it gives one), the player camera at eye height. Look through each with nw_view and give them all in your report as cameras: [{ "id", "shot" }].
17
+ - Placements: your task message names the placements a made model will take over. Add the stand-in of each through place(ctx, world, "<placement id>", standIn, opts) from src/placements/index.ts (the placements seam, the director's) where you would call world.add(id, standIn, opts): it adds the stand-in now, and the model in its place once the model is made, at its real size where the stand-in stood (its base there, or its top for a placement whose anchor is top). Keep each stand-in at the size and place the brief gives the thing.
18
+ - Generators: terrain, scatter and repeated things are written for this game's forms and instanced (one draw call for many), so the game stays inside the brief's performance tier on an inexpensive laptop. Any shader they need is written for the brief in TSL (nowhere:tsl-r185); the SDK has none ready-made.
19
+ - Gameplay: rules and state in world.state, interactions with onTouch, the visitor's HP only through the pilot. Test each interaction with nw_play, walking there with goto, and compare world.state at the start and the end.
20
+ - Integration: import the materials from src/look/index.ts and the sound from src/audio/index.ts (the seams; the director keeps them building until their makers pass), and call the sound's play(event) where the brief's events happen. A model made for a placement is in the game through place() already: never add it again. Place any other asset the task message says is ready, and never reference an asset or a seam name that is not ready yet.
21
+ - Bash only reads here (git diff, ls); write files with Write and Edit.
22
+
23
+ ${SHARED_RULES}`
24
+
25
+ const BUILD_PARTS = ['subject', 'play', 'requestElements', 'subjects', 'forms', 'map', 'cameras', 'performance', 'sound', 'exclusions']
26
+
27
+ /** A builder task that puts other tasks' work together: it owns the
28
+ * composition and waits on someone (not the blockout, which waits on nobody). */
29
+ export const isIntegration = (task) => task.role === 'builder' && !task.makesCameras && (task.deps ?? []).length > 0 && (task.owns ?? []).includes('src/main.ts')
30
+
31
+ export const builder = {
32
+ id: 'builder',
33
+ lane: 'preview',
34
+ prompt: BUILDER_PROMPT,
35
+ builtIns: ['Read', 'Write', 'Edit', 'Glob', 'Grep', 'Bash', 'TodoWrite', 'Skill'],
36
+ nwTools: ['nw_docs', 'nw_schema', 'nw_guide', 'nw_check', 'nw_view', 'nw_play', 'nw_eval', 'nw_logs', 'nw_status', 'nw_compare'],
37
+ skills: ['nowhere:tsl-r185'],
38
+ mayOwn: ['src/main.ts', 'src/world/**', 'src/game/**', 'scene.json', 'game.config.json'],
39
+ rubric: RUBRICS.builder,
40
+ maxTurns: 120,
41
+ catalogue: {
42
+ does: 'The blockout (layout at the brief\'s scales, spawn, paths, landmarks, every brief camera as an nw_view shot, a stand-in through the placements seam at each placement a model takes over), generators (terrain, scatter, instancing), gameplay (world.state, onTouch, the HP contract) and integration (imports the seams and ready assets, wires the sound events). The only owner of src/main.ts, scene.json and game.config.json (not its look keys).',
43
+ size: 'One module or one integration pass per task; the blockout covers the whole layout roughly.',
44
+ checks: ['build', 'runtime', 'cameras', 'placements', 'play', 'perf'],
45
+ },
46
+ /** build and runtime always; cameras on the blockout, and placements when
47
+ * it declares any; perf on an integration task. */
48
+ defaultChecks(task, brief) {
49
+ const out = [
50
+ { id: 'build', kind: 'build' },
51
+ { id: 'runtime', kind: 'runtime' },
52
+ ]
53
+ if (task.makesCameras) out.push({ id: 'cameras', kind: 'cameras', cameras: (brief?.cameras ?? []).map((c) => c.id) })
54
+ if (task.makesCameras && (task.placements ?? []).length) out.push({ id: 'placements', kind: 'placements' })
55
+ if (isIntegration(task)) out.push({ id: 'perf', kind: 'perf' })
56
+ return out
57
+ },
58
+ checksFor(task, brief) {
59
+ return checksOf(task, this.defaultChecks(task, brief))
60
+ },
61
+ session(task, input) {
62
+ // An nw_play input that walks somewhere real: a goto from the board's own
63
+ // play checks, else a point, which is always one (a request element's id
64
+ // is not a thing in the game, and a model copies an example as it is).
65
+ const fromChecks = (task.accept?.checks ?? []).flatMap((c) => (c.kind === 'play' ? c.steps ?? [] : [])).find((s) => typeof s?.goto === 'string' || Array.isArray(s?.goto))?.goto
66
+ const extra = [
67
+ fromChecks !== undefined
68
+ ? `A valid nw_play input that walks the player to a thing and acts there, from your task's own play check (goto takes a placement id or kind, a world kind, an object name, or a point [x, y, z] in metres): ${playExample(fromChecks, playKeys(task))}`
69
+ : `An nw_play input that walks the player somewhere and acts there: ${playExample(POINT, playKeys(task))}. The act step holds the key your game reads for it, whatever this game's controls are. goto takes a point [x, y, z] in metres, as here, or the id or kind of a placement, a world kind or an object name that is in your game.`,
70
+ ]
71
+ if (task.makesCameras) extra.push('This is the blockout: your report must give every brief camera as cameras: [{ "id": "<brief camera id>", "shot": <an nw_view shot> }]. Give task_check the same list (task_check { "cameras": [...] }) so its cameras check shoots them before you report.')
72
+ if ((task.placements ?? []).length) {
73
+ extra.push(
74
+ `The placements (a model is made for each; add its stand-in with place(ctx, world, id, standIn, opts) from src/placements/index.ts, imported as './placements/index' from src/main.ts):\n${task.placements.map((p) => `- ${p.id}: ${p.what}${p.anchor === 'top' ? ' (anchor top: the top of the model meets the top of the stand-in, as things stand on it)' : ''}`).join('\n')}`,
75
+ )
76
+ }
77
+ return buildSession(this, task, input, { parts: BUILD_PARTS, schema: RoleReport, images: task.makesCameras ? input.refImages ?? [] : [], extra })
78
+ },
79
+ }