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,333 @@
1
+ // The rounds of the reference loop as the chat shows them (REFERENCE_LOOP.md
2
+ // 2.4): after each round the agent posts a round message (rpc 'round'): not
3
+ // a card, nothing waits on it, only what this round looks like next to its
4
+ // targets, its score and what is still apart. main checks it here
5
+ // (roundFor) and the chat draws it (RoundMessage.tsx). The round's record
6
+ // stays in the project, one folder a round, which the mood board lists
7
+ // (listRounds):
8
+ //
9
+ // .nowhere/rounds/<n>/still-H#.png the view as the space looks now
10
+ // .nowhere/rounds/<n>/composite-H#.png target | now, side by side
11
+ // .nowhere/rounds/<n>/scores.json { round, views: { H#: score },
12
+ // overall, judge: { model, notes }, gaps }
13
+ // .nowhere/rounds/<n>/notes.md the judge's words
14
+ //
15
+ // A picture any card or round names is a file in the open project: a
16
+ // project-relative path to a PNG, JPEG or WebP that is there (imagePath).
17
+ //
18
+ // A round folder is named by its number (3, or 03, or round-3: the judge's
19
+ // round tool may pad or prefix it). A composite may say how it is laid out,
20
+ // so a mark the creator draws on it can be told in the hero still's own
21
+ // pixels (REFERENCE_LOOP.md 2.7, view and screen coordinates): compose()'s
22
+ // answer (reference/compose.mjs: width, height, panels { target, now } as
23
+ // { x, y, w, h } in the composite's pixels, cut { x, y, w, h } of the still
24
+ // or null) kept next to it as composite-H#.json, or under the hero in
25
+ // scores.json layout { H#: ... }. Without one, a mark is told in the
26
+ // composite's pixels only (compositeLayout).
27
+ //
28
+ // Electron-free, so the checks drive it in plain Node.
29
+
30
+ const fs = require('node:fs')
31
+ const path = require('node:path')
32
+
33
+ const ROUNDS_DIR = path.join('.nowhere', 'rounds')
34
+ const IMAGE = /\.(png|jpe?g|webp)$/i
35
+ /** A picture the chat shows is at most this: a composite of two 2k views is far under it. */
36
+ const IMAGE_MAX = 40 * 1024 * 1024
37
+ const HERO = /^H[1-6]$/
38
+ const SEVERITIES = new Set(['low', 'medium', 'high'])
39
+ /** A judge's own words for how far apart, said on the chat's three steps. */
40
+ const SEVERITY_WORDS = { minor: 'low', small: 'low', slight: 'low', moderate: 'medium', major: 'high', large: 'high', severe: 'high', critical: 'high', big: 'high' }
41
+ const MAX_VIEWS = 6
42
+ const MAX_GAPS = 6
43
+ const MAX_HISTORY = 60
44
+ const GAP_WHERE = 80
45
+ const GAP_WHAT = 200
46
+ /** A round folder: its number, padded or prefixed as the round tool may write it. */
47
+ const ROUND_DIR = /^(?:round[-_]?)?0*(\d{1,3})$/i
48
+
49
+ const isRecord = (v) => !!v && typeof v === 'object' && !Array.isArray(v)
50
+ const isNum = (v, min = -Infinity, max = Infinity) => typeof v === 'number' && Number.isFinite(v) && v >= min && v <= max
51
+ const isText = (v, min, max) => typeof v === 'string' && v.trim().length >= min && v.length <= max
52
+ const oneLine = (s) => String(s).replace(/\s+/g, ' ').trim()
53
+ const score = (v) => isNum(v, 0, 10)
54
+ const r2 = (v) => Math.round(v * 100) / 100
55
+ const clip = (v, max) => {
56
+ const line = oneLine(v)
57
+ return line.length > max ? `${line.slice(0, max - 3).trimEnd()}...` : line
58
+ }
59
+
60
+ /** A gap's severity on the chat's steps: low, medium or high, or a number
61
+ * 0 to 10 kept as it is. Anything else the judge wrote (major, minor, a
62
+ * number past 10) is read for what it says, else medium, rather than
63
+ * refusing the round over one word. */
64
+ function severityOf(v) {
65
+ if (typeof v === 'number' && Number.isFinite(v)) return r2(Math.max(0, Math.min(10, v)))
66
+ const word = String(v ?? '').trim().toLowerCase()
67
+ if (SEVERITIES.has(word)) return word
68
+ return Object.hasOwn(SEVERITY_WORDS, word) ? SEVERITY_WORDS[word] : 'medium'
69
+ }
70
+
71
+ /** A project-relative picture path as it is written ('.nowhere/rounds/3/composite-H1.png'),
72
+ * normalised, or null when it is not one: absolute, climbing out, or not a picture. */
73
+ function relImage(rel) {
74
+ if (typeof rel !== 'string' || rel.length < 5 || rel.length > 400) return null
75
+ const r = rel.replace(/\\/g, '/').replace(/^\.\//, '')
76
+ if (r.startsWith('/') || /^[A-Za-z]:/.test(r) || r.split('/').some((p) => p === '..' || p === '')) return null
77
+ return IMAGE.test(r) ? r : null
78
+ }
79
+
80
+ /** The file a project-relative path names, inside the project once its
81
+ * links are followed, a file of at most `max` bytes; or null. */
82
+ function projectFile(root, rel, max = IMAGE_MAX) {
83
+ if (!root || typeof rel !== 'string' || !rel || rel.length > 400) return null
84
+ const r = rel.replace(/\\/g, '/').replace(/^\.\//, '')
85
+ if (r.startsWith('/') || /^[A-Za-z]:/.test(r) || r.split('/').some((p) => p === '..' || p === '')) return null
86
+ try {
87
+ const base = fs.realpathSync(root)
88
+ const file = fs.realpathSync(path.join(base, ...r.split('/')))
89
+ if (!file.startsWith(base + path.sep)) return null
90
+ const st = fs.statSync(file)
91
+ return st.isFile() && st.size <= max ? file : null
92
+ } catch {
93
+ return null
94
+ }
95
+ }
96
+
97
+ /** The file a project-relative picture path names, inside the project once
98
+ * its links are followed, a file of at most IMAGE_MAX; or null. Without a
99
+ * project, the path's shape alone (rel) is checked and null comes back. */
100
+ function imagePath(root, rel) {
101
+ const r = relImage(rel)
102
+ return r ? projectFile(root, r) : null
103
+ }
104
+
105
+ /** A picture's width and height from its first bytes (PNG, JPEG or WebP),
106
+ * or null: no decoder, only the header. */
107
+ function imageSize(file) {
108
+ let head
109
+ try {
110
+ const fd = fs.openSync(file, 'r')
111
+ try {
112
+ head = Buffer.alloc(65_536)
113
+ head = head.subarray(0, fs.readSync(fd, head, 0, head.length, 0))
114
+ } finally {
115
+ fs.closeSync(fd)
116
+ }
117
+ } catch {
118
+ return null
119
+ }
120
+ const ok = (width, height) => (width > 0 && height > 0 ? { width, height } : null)
121
+ if (head.length >= 24 && head.readUInt32BE(0) === 0x89504e47) return ok(head.readUInt32BE(16), head.readUInt32BE(20))
122
+ if (head.length >= 30 && head.toString('latin1', 0, 4) === 'RIFF' && head.toString('latin1', 8, 12) === 'WEBP') {
123
+ const chunk = head.toString('latin1', 12, 16)
124
+ if (chunk === 'VP8X') return ok(1 + head.readUIntLE(24, 3), 1 + head.readUIntLE(27, 3))
125
+ if (chunk === 'VP8 ') return ok(head.readUInt16LE(26) & 0x3fff, head.readUInt16LE(28) & 0x3fff)
126
+ if (chunk === 'VP8L') {
127
+ const b = head.readUInt32LE(21)
128
+ return ok((b & 0x3fff) + 1, ((b >> 14) & 0x3fff) + 1)
129
+ }
130
+ return null
131
+ }
132
+ if (head.length >= 4 && head[0] === 0xff && head[1] === 0xd8) {
133
+ let i = 2
134
+ while (i + 9 < head.length) {
135
+ if (head[i] !== 0xff) return null
136
+ const marker = head[i + 1]
137
+ if (marker === 0xd8 || (marker >= 0xd0 && marker <= 0xd7) || marker === 0x01 || marker === 0xff) {
138
+ i += marker === 0xff ? 1 : 2
139
+ continue
140
+ }
141
+ // A start of frame (not the huffman, arithmetic or other tables) holds the size.
142
+ if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) return ok(head.readUInt16BE(i + 7), head.readUInt16BE(i + 5))
143
+ i += 2 + head.readUInt16BE(i + 2)
144
+ }
145
+ }
146
+ return null
147
+ }
148
+
149
+ const boxOf = (b) => (isRecord(b) && isNum(b.x, 0, 1e5) && isNum(b.y, 0, 1e5) && isNum(b.w, 1, 1e5) && isNum(b.h, 1, 1e5) ? { x: b.x, y: b.y, w: b.w, h: b.h } : null)
150
+ const sizeOf = (s) => (isRecord(s) && isNum(s.width, 1, 1e5) && isNum(s.height, 1, 1e5) ? { width: s.width, height: s.height } : null)
151
+
152
+ /**
153
+ * How a picture the creator marked is laid out, so a mark on it can be told
154
+ * as a place in the view (REFERENCE_LOOP.md 2.7): for a round's still, its
155
+ * hero and its own size (its pixels are the screen's, as the hero camera
156
+ * framed it); for a composite, its two halves (compose()'s panels, kept
157
+ * beside it as composite-H#.json or in scores.json layout[H#]) and the
158
+ * still the now half shows (its cut and size); null for any other picture.
159
+ * size: the marked picture's own size, which the panels are scaled to when
160
+ * the composite was resized after it was laid out.
161
+ */
162
+ function compositeLayout(root, rel, size = null) {
163
+ const r = relImage(rel)
164
+ const m = r ? /^(.*\/)?(composite|still)-(H[1-6])\.(png|jpe?g|webp)$/i.exec(r) : null
165
+ if (!m || !root) return null
166
+ const dir = m[1] ?? ''
167
+ const hero = m[3].toUpperCase()
168
+ const stillFile = ['png', 'jpg', 'jpeg', 'webp'].map((ext) => imagePath(root, `${dir}still-${hero}.${ext}`)).find(Boolean)
169
+ if (m[2].toLowerCase() === 'still') {
170
+ const own = imagePath(root, r)
171
+ const still = sizeOf(size) ?? (own ? imageSize(own) : null)
172
+ return still ? { kind: 'still', hero, still } : null
173
+ }
174
+ const json = (p) => {
175
+ const file = projectFile(root, p, 1024 * 1024)
176
+ return file ? readJson(file) : null
177
+ }
178
+ const side = json(r.replace(/\.(png|jpe?g|webp)$/i, '.json'))
179
+ const scores = json(`${dir}scores.json`)
180
+ const spec = [side, isRecord(scores?.layout) ? scores.layout[hero] : null].find((x) => isRecord(x) && boxOf(x.panels?.target) && boxOf(x.panels?.now))
181
+ if (!spec) return { kind: 'composite', hero, panels: null }
182
+ let target = boxOf(spec.panels.target)
183
+ let now = boxOf(spec.panels.now)
184
+ // Panels in the pixels the composite was written at; the picture marked may be a resized copy.
185
+ const own = sizeOf(size)
186
+ const written = sizeOf(spec)
187
+ if (own && written && Math.abs(own.width - written.width) > 1) {
188
+ const k = own.width / written.width
189
+ const scale = (b) => ({ x: b.x * k, y: b.y * k, w: b.w * k, h: b.h * k })
190
+ target = scale(target)
191
+ now = scale(now)
192
+ }
193
+ const cut = boxOf(spec.cut)
194
+ const still = sizeOf(spec.still) ?? (stillFile ? imageSize(stillFile) : null)
195
+ return { kind: 'composite', hero, panels: { target, now }, cut, still }
196
+ }
197
+
198
+ /** A picture a card or round names, or why not: there when there is a project to look in. */
199
+ function pictureOf(root, rel, what) {
200
+ const r = relImage(rel)
201
+ if (!r) return { error: `${what} must be a project-relative path to a PNG, JPEG or WebP file.` }
202
+ if (root && !imagePath(root, r)) return { error: `${what} ${r} is not a picture in the project.` }
203
+ return { path: r }
204
+ }
205
+
206
+ /** The round message as the chat shows it, or why not (the contract's shape:
207
+ * { round, elapsedMin, remainingMin, views: [{ hero, composite, score }],
208
+ * score, history, gaps: [{ where, what, severity, from?, hero? }], changed };
209
+ * from 'creator' marks the creator's own note, hero the view they marked). */
210
+ function roundFor(input, root) {
211
+ const needs = (what) => ({ error: `A round message needs ${what}.` })
212
+ if (!isRecord(input)) return needs('round, elapsedMin, remainingMin, views, score, history, gaps and changed')
213
+ if (!Number.isInteger(input.round) || input.round < 0 || input.round > 999) return needs('round: its number')
214
+ if (!isNum(input.elapsedMin, 0, 100_000) || !isNum(input.remainingMin, 0, 100_000)) return needs('elapsedMin and remainingMin in minutes')
215
+ const views = input.views
216
+ if (!Array.isArray(views) || views.length < 1 || views.length > MAX_VIEWS) return needs(`1 to ${MAX_VIEWS} views`)
217
+ const shown = []
218
+ for (const v of views) {
219
+ if (!isRecord(v) || !HERO.test(String(v.hero)) || !(v.score === undefined || v.score === null || score(v.score))) return needs('views each with a hero (H1 to H6), its composite and a score of 0 to 10')
220
+ const pic = pictureOf(root, v.composite, `The composite of ${v.hero}`)
221
+ if (pic.error) return { error: pic.error }
222
+ shown.push({ hero: v.hero, composite: pic.path, ...(score(v.score) ? { score: r2(v.score) } : {}) })
223
+ }
224
+ // null: the round was not judged (no targets, no judge), which the chat
225
+ // says rather than showing a number.
226
+ if (!(input.score === null || score(input.score))) return needs('score: the overall score, 0 to 10, or null when not judged')
227
+ const history = input.history ?? []
228
+ if (!Array.isArray(history) || history.length > MAX_HISTORY || !history.every(score)) return needs(`history: at most ${MAX_HISTORY} scores of 0 to 10, the first round's first`)
229
+ // The judge's gaps are its words: one too long is cut, one with a
230
+ // severity of its own wording is read for it, one with nothing to say is
231
+ // left out, and past MAX_GAPS the rest wait for the next round. None of
232
+ // it keeps the round from the chat.
233
+ const gaps = input.gaps ?? []
234
+ if (!Array.isArray(gaps)) return needs('gaps: a list of { where, what, severity }')
235
+ // A creator's note (from: 'creator') is their own words, shown under the
236
+ // chat's own label with the view they marked; one that was only marks on
237
+ // a picture has no words, and the chat says it was marked.
238
+ const fromCreator = (g) => g.from === 'creator'
239
+ const shownGaps = gaps
240
+ .filter((g) => isRecord(g) && isText(g.where, 1, 2000) && (isText(g.what, 1, 4000) || (fromCreator(g) && g.what === '')))
241
+ .slice(0, MAX_GAPS)
242
+ .map((g) => ({ where: clip(g.where, GAP_WHERE), what: clip(g.what, GAP_WHAT), severity: severityOf(g.severity), ...(fromCreator(g) ? { from: 'creator', ...(HERO.test(String(g.hero)) ? { hero: g.hero } : {}) } : {}) }))
243
+ if (input.changed !== undefined && input.changed !== null && typeof input.changed !== 'string') return needs('changed: one line')
244
+ return {
245
+ round: {
246
+ round: input.round,
247
+ elapsedMin: Math.round(input.elapsedMin),
248
+ remainingMin: Math.round(input.remainingMin),
249
+ views: shown,
250
+ score: input.score === null ? null : r2(input.score),
251
+ history: history.map(r2),
252
+ gaps: shownGaps,
253
+ changed: typeof input.changed === 'string' ? clip(input.changed, 300) : '',
254
+ },
255
+ }
256
+ }
257
+
258
+ const readJson = (file) => {
259
+ try {
260
+ return JSON.parse(fs.readFileSync(file, 'utf8'))
261
+ } catch {
262
+ return null
263
+ }
264
+ }
265
+
266
+ /** The round folders of a project, the first round first: each one's
267
+ * composites and stills by hero view, its scores and the judge's words. A
268
+ * folder whose scores.json cannot be read still shows its pictures. */
269
+ function listRounds(root) {
270
+ if (!root) return []
271
+ const dir = path.join(root, ROUNDS_DIR)
272
+ let names = []
273
+ try {
274
+ names = fs.readdirSync(dir, { withFileTypes: true }).filter((d) => d.isDirectory() && ROUND_DIR.test(d.name)).map((d) => d.name)
275
+ } catch {
276
+ return []
277
+ }
278
+ const numberOf = (name) => Number(ROUND_DIR.exec(name)[1])
279
+ const out = []
280
+ const seen = new Set()
281
+ for (const name of names.sort((a, b) => numberOf(a) - numberOf(b) || a.localeCompare(b))) {
282
+ // Two folders for one round (3 and round-3): the first named is listed.
283
+ if (seen.has(numberOf(name))) continue
284
+ seen.add(numberOf(name))
285
+ const at = path.join(dir, name)
286
+ let files = []
287
+ try {
288
+ files = fs.readdirSync(at)
289
+ } catch {
290
+ continue
291
+ }
292
+ const byHero = (prefix) =>
293
+ files
294
+ .map((f) => new RegExp(`^${prefix}-(H[1-6])\\.(png|jpe?g|webp)$`, 'i').exec(f))
295
+ .filter(Boolean)
296
+ .map((m) => ({ hero: m[1].toUpperCase(), path: `.nowhere/rounds/${name}/${m[0]}` }))
297
+ .sort((a, b) => a.hero.localeCompare(b.hero))
298
+ const s = readJson(path.join(at, 'scores.json'))
299
+ const views = isRecord(s?.views) ? Object.fromEntries(Object.entries(s.views).filter(([h, v]) => HERO.test(h) && score(v)).map(([h, v]) => [h, r2(v)])) : {}
300
+ const gaps = Array.isArray(s?.gaps)
301
+ ? s.gaps
302
+ .filter((g) => isRecord(g) && isText(g.where, 1, 200) && (g.from === 'creator' ? typeof g.said === 'string' : isText(g.what, 1, 400)))
303
+ .slice(0, MAX_GAPS)
304
+ // A creator's note shows their own words (said), not the agent's record of it.
305
+ .map((g) =>
306
+ g.from === 'creator'
307
+ ? { where: oneLine(g.where), what: clip(g.said, 400), from: 'creator', ...(HERO.test(String(g.hero)) ? { hero: g.hero } : {}), ...(g.severity !== undefined && g.severity !== null ? { severity: severityOf(g.severity) } : {}) }
308
+ : { where: oneLine(g.where), what: oneLine(g.what), ...(g.severity !== undefined && g.severity !== null ? { severity: severityOf(g.severity) } : {}) },
309
+ )
310
+ : []
311
+ let notes = null
312
+ try {
313
+ notes = fs.readFileSync(path.join(at, 'notes.md'), 'utf8').trim().slice(0, 1200) || null
314
+ } catch {
315
+ // no notes this round
316
+ }
317
+ out.push({
318
+ round: numberOf(name),
319
+ composites: byHero('composite'),
320
+ stills: byHero('still'),
321
+ views,
322
+ overall: score(s?.overall) ? r2(s.overall) : null,
323
+ judge: isRecord(s?.judge) ? { model: isText(s.judge.model, 1, 80) ? s.judge.model : null, notes: isText(s.judge.notes, 1, 2000) ? s.judge.notes.trim() : null } : null,
324
+ // Two judges: each one's model and overall (the lower stands).
325
+ judges: Array.isArray(s?.judges) ? s.judges.filter((j) => isRecord(j) && isText(j.model, 1, 80)).slice(0, 4).map((j) => ({ model: j.model, overall: score(j.overall) ? r2(j.overall) : null })) : [],
326
+ gaps,
327
+ notes,
328
+ })
329
+ }
330
+ return out
331
+ }
332
+
333
+ module.exports = { roundFor, listRounds, imagePath, projectFile, imageSize, compositeLayout, severityOf, relImage, pictureOf, ROUNDS_DIR, IMAGE_MAX }
@@ -0,0 +1,284 @@
1
+ // What the agent host's modules share: where the studio's own files are, the
2
+ // containment check every path goes through, the conversation helpers and the
3
+ // model table. Kept apart from host.mjs so the guard, the tools and the check
4
+ // scripts can import it without starting anything.
5
+
6
+ import { existsSync, readFileSync, realpathSync } from 'node:fs'
7
+ import { createRequire } from 'node:module'
8
+ import os from 'node:os'
9
+ import path from 'node:path'
10
+ import { fileURLToPath } from 'node:url'
11
+
12
+ /** electron/agent, in the repo and in a packaged app alike. */
13
+ export const AGENT_DIR = path.dirname(fileURLToPath(import.meta.url))
14
+ /** apps/studio in the repo; the staged app's root when packaged (stage-app.mjs
15
+ * copies electron, examples, templates and agent-plugin side by side); the
16
+ * CLI package's folder when `nowhere make` runs the agent its build vendored
17
+ * (packages/cli/vendor/agent). */
18
+ export const STUDIO_DIR = path.resolve(AGENT_DIR, '..', '..')
19
+ /** The first of the places that exists, else the first: the studio's layout,
20
+ * then the CLI's, whose build puts the plugin in vendor/
21
+ * beside the agent and keeps the starter project as the package's template/. */
22
+ const firstThere = (...dirs) => dirs.find((dir) => existsSync(dir)) ?? dirs[0]
23
+ export const PLUGIN_DIR = firstThere(path.join(STUDIO_DIR, 'agent-plugin'), path.join(STUDIO_DIR, 'vendor', 'agent-plugin'))
24
+ const TEMPLATE_DIR = firstThere(path.join(STUDIO_DIR, 'templates', 'blank'), path.join(STUDIO_DIR, 'template'))
25
+ export const TEMPLATE_MAIN = path.join(TEMPLATE_DIR, 'src', 'main.ts')
26
+ /** The blank template's scene.json: the starter placeholder every new project begins with. */
27
+ export const TEMPLATE_SCENE = path.join(TEMPLATE_DIR, 'scene.json')
28
+
29
+ /** The SDK's and the schema's own sources and guide, read-only for the agent:
30
+ * a run looked for them to learn what the SDK really exports and was refused
31
+ * (2026-10-20). In a packaged app the guide (sdk/) and the schema
32
+ * (vendor/schema/) sit beside electron/ (stage-app.mjs); in the repo the
33
+ * packages themselves. Only the folders that exist. */
34
+ export const SDK_SOURCES = [
35
+ path.join(STUDIO_DIR, 'sdk'),
36
+ path.join(STUDIO_DIR, 'vendor', 'schema'),
37
+ path.join(STUDIO_DIR, '..', '..', 'packages', 'sdk'),
38
+ path.join(STUDIO_DIR, '..', '..', 'packages', 'schema'),
39
+ ].filter((dir) => existsSync(dir))
40
+
41
+ /** The plugin the skills come in, and the skills the agent may load. */
42
+ export const PLUGIN_NAME = 'nowhere'
43
+ export const SKILL_NAMES = [
44
+ 'nowhere:look-dev',
45
+ 'nowhere:asset-sources',
46
+ 'nowhere:blender-modeling',
47
+ 'nowhere:tsl-r185',
48
+ 'nowhere:art-direction',
49
+ 'nowhere:asset-legality',
50
+ 'nowhere:sound-design',
51
+ 'nowhere:playtesting',
52
+ 'nowhere:reference-loop',
53
+ 'nowhere:style',
54
+ ]
55
+
56
+ /** Whether the skills folder shipped with this build. */
57
+ export const pluginReady = (dir = PLUGIN_DIR) => existsSync(path.join(dir, '.claude-plugin', 'plugin.json'))
58
+
59
+ // ArtStation, Pinterest and Behance, with any subdomain: their terms forbid
60
+ // feeding their images to AI tools, so the studio never fetches from them.
61
+ export const BLOCKED_HOSTS = /(^|[^a-z0-9-])((?:[a-z0-9-]+\.)*(?:artstation\.com|pinterest\.[a-z.]+|pinimg\.com|behance\.net))(?![a-z0-9-])/i
62
+
63
+ // The SDK's guide: beside the main process in a packaged app (stage-app.mjs
64
+ // copies it to sdk/DOCS.md), in the repo otherwise, and in the CLI's vendor/
65
+ // (its build copies it there). Until 0.1.2 a packaged app had only the repo
66
+ // path, found nothing, and its agent built games blind.
67
+ export const DOCS_AT = [path.join(STUDIO_DIR, 'sdk', 'DOCS.md'), path.join(STUDIO_DIR, '..', '..', 'packages', 'sdk', 'DOCS.md'), path.join(STUDIO_DIR, 'vendor', 'DOCS.md')]
68
+
69
+ export function sdkDocs() {
70
+ for (const file of DOCS_AT) {
71
+ try {
72
+ return readFileSync(file, 'utf8')
73
+ } catch {
74
+ // the next place
75
+ }
76
+ }
77
+ return 'SDK docs not found; rely on reading node types via the import shim names: World, createGame contract { root, update(dt), dispose() }.'
78
+ }
79
+
80
+ // ---------------------------------------------------------------- paths
81
+ // Both sides of a containment check have to be real paths. On macOS the
82
+ // temp and home trees are symlinked (/var -> /private/var), so comparing the
83
+ // raw strings refuses writes to files that are genuinely inside the project.
84
+
85
+ export function realOrSelf(p) {
86
+ // The nearest part of the path that exists, as a real path, with the rest
87
+ // (folders a write is about to create) put back on it.
88
+ let head = path.resolve(p)
89
+ const rest = []
90
+ for (;;) {
91
+ try {
92
+ return path.join(realpathSync(head), ...rest)
93
+ } catch {
94
+ const up = path.dirname(head)
95
+ if (up === head) return path.resolve(p)
96
+ rest.unshift(path.basename(head))
97
+ head = up
98
+ }
99
+ }
100
+ }
101
+
102
+ /** True when `target` resolves to something at or under `root`. */
103
+ export function isInside(root, target) {
104
+ const fold = (s) => (process.platform === 'win32' ? s.toLowerCase() : s)
105
+ const r = fold(realOrSelf(root))
106
+ const t = fold(realOrSelf(path.resolve(realOrSelf(root), target)))
107
+ if (t === r) return true
108
+ return t.startsWith(r.endsWith(path.sep) ? r : r + path.sep)
109
+ }
110
+
111
+ // ---------------------------------------------------------------- services with a key
112
+ // The connector catalog's services that take an API key, for the host's rules
113
+ // about keys in Bash: never printed, and a paid one never called before a
114
+ // cost was approved. Read through connectors.cjs (Electron-free); none when
115
+ // the catalog cannot be read.
116
+
117
+ /** Catalog categories whose calls cost money per job. Sketchfab's downloads
118
+ * ('assets') are not generation. */
119
+ export const PAID_CATEGORIES = new Set(['3d', 'world', 'image', 'audio', 'models'])
120
+
121
+ let keyed = null
122
+ /** @returns {{ id: string, category: string, envVar: string, apiHost: string | null }[]} */
123
+ export function keyedServices() {
124
+ if (keyed) return keyed
125
+ try {
126
+ const catalog = createRequire(import.meta.url)('../connectors.cjs').loadCatalog()
127
+ keyed = catalog
128
+ .filter((e) => e?.auth?.type === 'apiKey' && /^[A-Z_][A-Z0-9_]*$/.test(e.auth.envVar ?? ''))
129
+ .map((e) => {
130
+ let apiHost = null
131
+ try {
132
+ apiHost = new URL(e.testEndpoint?.url).hostname.toLowerCase()
133
+ } catch {
134
+ // no test endpoint
135
+ }
136
+ return { id: e.id, category: e.category, envVar: e.auth.envVar, apiHost }
137
+ })
138
+ } catch {
139
+ keyed = []
140
+ }
141
+ return keyed
142
+ }
143
+
144
+ // ---------------------------------------------------------------- the conversation so far
145
+ // A project's conversation goes on across messages and across restarts
146
+ // (main keeps it with the project, chatHistory.cjs). Claude resumes its own
147
+ // session, which the SDK keeps on disk; any other model, or Claude when that
148
+ // session is not on this machine, is given the recent messages as words.
149
+
150
+ const configDir = () => process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude')
151
+
152
+ /** Where the SDK keeps a project's sessions: <config>/projects/<cwd, every
153
+ * other character a dash>. Large tool outputs it saves for the model to read
154
+ * back land there too. */
155
+ export const sessionDir = (cwd) => path.join(configDir(), 'projects', realOrSelf(cwd).replace(/[^a-zA-Z0-9]/g, '-'))
156
+
157
+ /** Whether the SDK still has the session `id` for a project at `cwd`. */
158
+ export function sessionKept(id, cwd) {
159
+ if (!id) return false
160
+ return existsSync(path.join(sessionDir(cwd), `${id}.jsonl`))
161
+ }
162
+
163
+ /** The recent messages, for a model that has no memory of them. */
164
+ export function historyPreamble(history) {
165
+ if (!Array.isArray(history) || history.length === 0) return ''
166
+ const lines = history.map((m) => {
167
+ const pictures = m.images ? ` (with ${m.images} picture${m.images > 1 ? 's' : ''})` : ''
168
+ return `${m.role === 'user' ? 'Creator' : 'You'}${pictures}: ${m.text}`
169
+ })
170
+ return `Earlier in this project's conversation (oldest first; it has already happened, so do not redo it unless asked):\n${lines.join('\n')}\n\nThe creator's new message:\n`
171
+ }
172
+
173
+ /** The creator's last message in the history that has words of their own in
174
+ * it, for telling their language when the new one is too short to tell
175
+ * ("ok", "?", a picture alone) or is the studio's words. A message the
176
+ * studio wrote for them (studioWords: Continue, the Describe chip, a
177
+ * marking with no note) is in the screen language, not theirs, and is
178
+ * passed over. */
179
+ export function lastUserText(history) {
180
+ if (!Array.isArray(history)) return ''
181
+ for (let i = history.length - 1; i >= 0; i--) {
182
+ const m = history[i]
183
+ if (m?.role === 'user' && m.studioWords !== true && typeof m.text === 'string' && (m.text.match(/\p{L}/gu) ?? []).length >= 3) return m.text
184
+ }
185
+ return ''
186
+ }
187
+
188
+ /** The agent's last reply in the history with words in it, for the
189
+ * creator's language once none of their own words are left in it: the
190
+ * agent replies in their language, and the history is only the last 24
191
+ * messages, so a reference loop the creator kept going with Continue (its
192
+ * replies split around every card and round) pushes their own message out
193
+ * of it. A message on the agent's side that is the studio's words (an
194
+ * approval card's notice, studioWords) is in the screen language and is
195
+ * passed over. */
196
+ export function lastReplyText(history) {
197
+ if (!Array.isArray(history)) return ''
198
+ for (let i = history.length - 1; i >= 0; i--) {
199
+ const m = history[i]
200
+ if (m?.role === 'agent' && m.studioWords !== true && typeof m.text === 'string' && (m.text.match(/\p{L}/gu) ?? []).length >= 3) return m.text
201
+ }
202
+ return ''
203
+ }
204
+
205
+ // ---------------------------------------------------------------- failures
206
+
207
+ const failureText = (msg) => String(msg?.result ?? (Array.isArray(msg?.errors) ? msg.errors.join(' ') : '') ?? '')
208
+
209
+ /** What kind of failure a result is: the account, the key and a busy API are
210
+ * the creator's to fix, so nothing is cleaned up after them. */
211
+ export function failureKind(msg) {
212
+ const text = failureText(msg)
213
+ // Claude Code's own words when the sign-in it runs on no longer works.
214
+ if (/not logged in|please run \/login/i.test(text)) return 'login'
215
+ if (/credit balance/i.test(text)) return 'credit'
216
+ if (/invalid.{0,20}(api.?key|x-api-key)|authentication|401/i.test(text)) return 'key'
217
+ if (/rate.?limit|overloaded|529|429/i.test(text)) return 'busy'
218
+ if (msg?.subtype === 'error_max_turns' || /maximum number of turns/i.test(text)) return 'turns'
219
+ return 'other'
220
+ }
221
+
222
+ /** Why a run failed, as one sentence the creator can act on. */
223
+ export function readableFailure(msg) {
224
+ switch (failureKind(msg)) {
225
+ case 'credit':
226
+ return 'Your Anthropic account is out of credit. Add credit at console.anthropic.com, or use another key in Settings.'
227
+ case 'key':
228
+ return 'Anthropic refused the API key. Check it in Settings.'
229
+ case 'login':
230
+ return 'Claude on this Mac is signed out. Sign in again in Settings, under Agent apps.'
231
+ case 'busy':
232
+ return 'Anthropic is busy right now. Try again in a minute.'
233
+ case 'turns':
234
+ return 'The agent ran out of steps before it finished. Ask it to continue.'
235
+ default:
236
+ return failureText(msg).replace(/^Claude Code returned an error result:\s*/i, '') || 'The agent stopped with an error.'
237
+ }
238
+ }
239
+
240
+ // ---------------------------------------------------------------- models
241
+
242
+ export const MODELS = JSON.parse(readFileSync(path.join(AGENT_DIR, '..', 'models.json'), 'utf8'))
243
+
244
+ /** The provider and model for a model id; the default for one this build
245
+ * does not know (a settings file from a newer studio). */
246
+ export function modelFor(modelId) {
247
+ for (const provider of MODELS.providers) {
248
+ const model = provider.models.find((m) => m.id === modelId)
249
+ if (model) return { provider, model }
250
+ }
251
+ const provider = MODELS.providers.find((p) => p.models.some((m) => m.id === MODELS.default))
252
+ return { provider, model: provider.models.find((m) => m.id === MODELS.default) }
253
+ }
254
+
255
+ /** Every model's price, for pricing a helper that runs on another model. */
256
+ export const PRICES = Object.fromEntries(MODELS.providers.flatMap((p) => p.models.filter((m) => Array.isArray(m.price)).map((m) => [m.id, m.price])))
257
+
258
+ /** A model's whole price card from models.json (ledger.mjs pricingOf reads
259
+ * it): its price, the long-prompt tier where the vendor has one, and what a
260
+ * cached token costs. Null when the vendor's page gave no price. */
261
+ export function pricingFor(model) {
262
+ if (!model || !Array.isArray(model.price)) return null
263
+ return {
264
+ price: model.price,
265
+ ...(model.longPrompt && Array.isArray(model.longPrompt.price) && Number(model.longPrompt.over) > 0
266
+ ? { longPrompt: { over: Number(model.longPrompt.over), price: model.longPrompt.price } }
267
+ : {}),
268
+ ...(typeof model.cacheRead === 'number' ? { cacheRead: model.cacheRead } : {}),
269
+ ...(typeof model.cacheWrite === 'number' ? { cacheWrite: model.cacheWrite } : {}),
270
+ }
271
+ }
272
+
273
+ /** Every model's price card by id: the one price source for the estimate,
274
+ * the running total and the final line, a helper on another model included. */
275
+ export const PRICING = Object.fromEntries(MODELS.providers.flatMap((p) => p.models.filter((m) => Array.isArray(m.price)).map((m) => [m.id, pricingFor(m)])))
276
+
277
+ /** This build's version, for the SDK's client header. */
278
+ export const STUDIO_VERSION = (() => {
279
+ try {
280
+ return JSON.parse(readFileSync(path.join(STUDIO_DIR, 'package.json'), 'utf8')).version ?? '0'
281
+ } catch {
282
+ return '0'
283
+ }
284
+ })()