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,273 @@
1
+ // The reference loop's process values (REFERENCE_LOOP.md 2.1, 2.5, 2.6, 3):
2
+ // the three speed levels the kickoff card offers, each a time floor, a time
3
+ // cap, a round cap and the judge's bar; the default list of things a space
4
+ // avoids (the slop list); the judge's rubric; the frame-time line for each
5
+ // tier; and what each level is estimated to cost, from the same token
6
+ // profiles as the studio context's typical costs (ledger.mjs), so the card
7
+ // and the running total are priced alike.
8
+ //
9
+ // None of these is a look. The bar, the speed levels and the slop list are
10
+ // how hard and how long the agent works and what it never puts in a space;
11
+ // a space's colour, light and materials come only from its request and its
12
+ // target pictures (the no-presets rule).
13
+
14
+ import { IMAGE_PROVIDERS } from '../assets/images/index.mjs'
15
+ import { PRICES } from '../assets/providers/index.mjs'
16
+ import { priceOf, pricingOf, profileUsd, TYPICAL } from '../ledger.mjs'
17
+ import { MODELS, PRICING } from '../shared.mjs'
18
+
19
+ /** The speed levels, in the order the card shows them. Times in minutes. */
20
+ export const LEVELS = Object.freeze({
21
+ quick: Object.freeze({ id: 'quick', timeFloorMin: 0, timeCapMin: 30, roundCap: 2, bar: 8.0 }),
22
+ standard: Object.freeze({ id: 'standard', timeFloorMin: 60, timeCapMin: 180, roundCap: 8, bar: 9.0 }),
23
+ deep: Object.freeze({ id: 'deep', timeFloorMin: 240, timeCapMin: 720, roundCap: 24, bar: 9.2 }),
24
+ })
25
+ export const LEVEL_IDS = Object.freeze(Object.keys(LEVELS))
26
+ /** What an unanswered kickoff card goes with (never Marble: the environment
27
+ * stays unanswered, and the agent builds in 3D). */
28
+ export const DEFAULT_LEVEL = 'standard'
29
+ /** The one quality gauge the composer and `oda make --quality` set (1 to 5):
30
+ * the model, the effort a build runs at (a ceiling for any other request),
31
+ * the bar and how many rounds and minutes a
32
+ * request may take. A step has no time floor: it ends at the bar once it
33
+ * has judged minRounds rounds, or at its round or time cap. */
34
+ export const QUALITY = Object.freeze({
35
+ 1: Object.freeze({ step: 1, name: 'Quick', model: 'claude-sonnet-5-5', effort: 'medium', bar: 8.0, roundCap: 2, minRounds: 1, timeCapMin: 30 }),
36
+ 2: Object.freeze({ step: 2, name: 'Standard', model: 'claude-sonnet-5-5', effort: 'xhigh', bar: 8.5, roundCap: 5, minRounds: 2, timeCapMin: 90 }),
37
+ 3: Object.freeze({ step: 3, name: 'Careful', model: 'claude-opus-5-5', effort: 'xhigh', bar: 9.0, roundCap: 10, minRounds: 3, timeCapMin: 240 }),
38
+ 4: Object.freeze({ step: 4, name: 'High', model: 'claude-opus-5-5', effort: 'max', bar: 9.1, roundCap: 16, minRounds: 5, timeCapMin: 360 }),
39
+ 5: Object.freeze({ step: 5, name: 'Max', model: 'claude-fable-5-2', effort: 'max', bar: 9.2, roundCap: 24, minRounds: 8, timeCapMin: 720 }),
40
+ })
41
+ export const QUALITY_STEPS = Object.freeze([1, 2, 3, 4, 5])
42
+ export const DEFAULT_QUALITY = 3
43
+ /** The judge runs on one model at every step, so a score means the same at each. */
44
+ export const JUDGE_MODEL = 'claude-opus-5-5'
45
+
46
+ /** A quality step from a message or a flag: an integer 1 to 5, else null. */
47
+ export function qualityOf(value) {
48
+ const n = typeof value === 'string' && value.trim() !== '' ? Number(value) : value
49
+ return Number.isInteger(n) && QUALITY[n] ? n : null
50
+ }
51
+
52
+ /** A quality step's model on Claude, held under a ceiling (a Claude model
53
+ * id, oda make --ceiling) by output price, as the director's router holds
54
+ * its models. */
55
+ export function qualityModel(step, ceiling = null) {
56
+ const q = QUALITY[qualityOf(step)]
57
+ if (!q) throw new Error(`There is no quality step ${step}: it is 1 to 5.`)
58
+ const claude = MODELS.providers.find((p) => p.runtime === 'claude-agent-sdk')?.models ?? []
59
+ const out = (id) => Number(claude.find((m) => m.id === id)?.price?.[1] ?? Infinity)
60
+ return claude.some((m) => m.id === ceiling) && out(q.model) > out(ceiling) ? ceiling : q.model
61
+ }
62
+
63
+ /** A quality step as a loop level: no time floor, its own rounds and bar. */
64
+ export function qualityLevel(step) {
65
+ const q = QUALITY[qualityOf(step)]
66
+ if (!q) throw new Error(`There is no quality step ${step}: it is 1 to 5.`)
67
+ return { id: `quality-${q.step}`, quality: q.step, timeFloorMin: 0, timeCapMin: q.timeCapMin, roundCap: q.roundCap, minRounds: q.minRounds, bar: q.bar }
68
+ }
69
+
70
+ /** A level by its id (quick, standard, deep) or a quality step; an unknown
71
+ * one is an error, never a quiet fall back to standard. */
72
+ export function levelFor({ level = null, quality = null } = {}) {
73
+ if (quality !== null && quality !== undefined) return qualityLevel(quality)
74
+ const l = LEVELS[level]
75
+ if (!l) throw new Error(`There is no level "${level}": it is ${LEVEL_IDS.join(', ')}, or a quality step.`)
76
+ return l
77
+ }
78
+
79
+ /** What look_compare should say at the hero views, beside the judge's score. */
80
+ export const COMPARE_BAR = 'close'
81
+
82
+ /** The target pictures a space is judged against, and how often the creator
83
+ * may send them back to be drawn again. */
84
+ export const MIN_TARGETS = 4
85
+ export const MAX_TARGETS = 6
86
+ export const MAX_REDRAWS = 3
87
+
88
+ /** The frame time each tier is held to when the measurement does not carry
89
+ * its own line (WS3's perf T.budgetMs): the high tier headless on the
90
+ * studio's machine, the low tier at the phone's pixel count. */
91
+ export const FRAME_MS = Object.freeze({ high: 16.7, medium: 25, low: 33 })
92
+
93
+ /** The subscription's five-hour window: the share of it a run paces to. */
94
+ export const WINDOW_SHARE = 0.99
95
+
96
+ /** What every space avoids unless its brief says otherwise (brief.slop adds
97
+ * to it). Process, not look: none of it says what colour or light to use. */
98
+ export const SLOP = Object.freeze([
99
+ // The judge reads this list and never the request, so the exception is
100
+ // said without it: a game's own signs, drawn in the world, are not slop.
101
+ 'decorative lettering: eyebrow labels, monospace capitals, a stray serif, 01/02/03 counters used as ornament (a game\'s own score, timer and rule signs, drawn inside the world in the space\'s style, are not slop)',
102
+ 'decoration for its own sake: glowing orbs, shockwave rings bursting outward, an all-beige wash',
103
+ 'colour gone grey, or oversaturated',
104
+ 'the same thing copy-pasted in a visible repeat',
105
+ 'bare single-colour surfaces with no texture, where the style gives its surfaces some',
106
+ 'an empty sky',
107
+ 'mush in the distance: far shapes that smear instead of reading',
108
+ 'em dashes in any text',
109
+ ])
110
+
111
+ /** What the judge scores, each 0 to 10, against the target at the same view. */
112
+ export const RUBRIC = Object.freeze([
113
+ ['drawing', 'the way it is drawn: the target\'s medium, line, shading, shape language and surface (a photograph, a painting, an ink drawing, a cartoon, a print, pixels), and not another one'],
114
+ ['composition', 'composition and scale: the same framing, the masses where the target has them, things at their real size'],
115
+ ['materials', 'materials: each surface reads as what the target shows, drawn as the target draws it (its grain, roughness and wear, or its flat colour, strokes or dots)'],
116
+ ['colour', 'colour: the target\'s palette and values, neither greyed out nor oversaturated'],
117
+ ['light', 'light and shadow: the sun\'s direction and colour, the shade\'s value and hue, contact shadows'],
118
+ ['distance', 'far detail: the distance reads, with no mush and no cut-off edge'],
119
+ ['repetition', 'repetition: no visible tiling or copy-pasted repeats'],
120
+ ['realtime', 'real-time artefacts: no stair-stepped edges, flicker, holes or empty sky'],
121
+ ['slop', 'the slop list: none of it in the picture'],
122
+ ])
123
+
124
+ // ---------------------------------------------------------------- the estimate
125
+
126
+ /** One round on the main agent: look, plan, change, check, look again,
127
+ * with a helper now and then. The low end is a round that changes one
128
+ * thing, the high end one that rebuilds an area. */
129
+ export const ROUND = Object.freeze([
130
+ { calls: 10, prompt: 110_000, fresh: 4_000, output: 2_000 },
131
+ { calls: 20, prompt: 150_000, fresh: 5_000, output: 3_000 },
132
+ ])
133
+ /** The long edge, in pixels, of the pictures the judge sees and of the
134
+ * round's stills. */
135
+ export const JUDGE_PX = 1568
136
+ /** One judge's call: the targets and the stills at 1568 px (about 3,300
137
+ * tokens a picture), the rubric, and a JSON answer after thinking at xhigh. */
138
+ export const JUDGE_CALL = Object.freeze({ calls: 1, prompt: 40_000, fresh: 40_000, output: 4_000 })
139
+
140
+ /** How much more a call writes at a quality step's effort than the
141
+ * profiles (measured at high) say. */
142
+ export const EFFORT_OUTPUT = Object.freeze({ low: 1, medium: 1, high: 1, xhigh: 2, max: 3 })
143
+ const scaled = (profile, k) => (k === 1 ? profile : { ...profile, output: profile.output * k })
144
+
145
+ const cents = (n) => Math.round(n * 100) / 100
146
+
147
+ /** The rounds a level takes at least: its floor's worth, about one round in
148
+ * twenty minutes, and a third of its cap at least; a quality step's
149
+ * minRounds when that is more. */
150
+ export const roundsLo = (level) => Math.max(level.minRounds ?? 1, Math.min(level.roundCap, Math.ceil(level.roundCap / 3), Math.max(1, Math.round(level.timeFloorMin / 20))))
151
+
152
+ /** One new space at a level, in US dollars: the first rough build, the
153
+ * rounds (the fewest it takes up to its cap) with a judge's call each (and
154
+ * the second judge's, when there is one), and the target pictures (MIN to
155
+ * MAX_TARGETS, up to MAX_REDRAWS times more at the high end). Null with no
156
+ * price for the builder or the judge. */
157
+ function estimateRun(level, { card, judgeCard = card, second = null, picture = 0, outputScale = 1 }) {
158
+ if (!card || !judgeCard) return null
159
+ const k = outputScale
160
+ const judgeUsd = profileUsd(JUDGE_CALL, judgeCard) + (second ? profileUsd(JUDGE_CALL, second) : 0)
161
+ const lo = profileUsd(scaled(TYPICAL.build[0], k), card) + roundsLo(level) * (profileUsd(scaled(ROUND[0], k), card) + judgeUsd) + MIN_TARGETS * picture
162
+ const hi = profileUsd(scaled(TYPICAL.build[1], k), card) + level.roundCap * (profileUsd(scaled(ROUND[1], k), card) + judgeUsd) + MAX_TARGETS * (1 + MAX_REDRAWS) * picture
163
+ return { lo: cents(lo), hi: cents(Math.max(hi, lo)) }
164
+ }
165
+
166
+ /** One target picture's upper price on a generator (default openai), for an estimate. */
167
+ export function targetPrice(providerId = 'openai') {
168
+ const provider = IMAGE_PROVIDERS[providerId]
169
+ if (!provider || !provider.paid) return 0
170
+ try {
171
+ const model = provider.defaultModel({ inputs: 0 })
172
+ return provider.price(model, { quality: 'medium', inputs: 0 }, PRICES)?.high ?? 0
173
+ } catch {
174
+ return 0
175
+ }
176
+ }
177
+
178
+ /**
179
+ * Each level as the kickoff card shows it, with its cost in US dollars on
180
+ * this model: the first rough build, the rounds (the fewest a level takes
181
+ * up to its cap), a judge's call a round (two with an OpenAI key), and the
182
+ * target pictures (MIN_TARGETS to MAX_TARGETS, up to MAX_REDRAWS times more
183
+ * at the high end). Null usd when the model has no price.
184
+ *
185
+ * @param {{ pricing: object | [number, number] | null, judge?: object | [number, number] | null, targetUsd?: number }} input
186
+ * judge: the second judge's price card (OpenAI's), when there is one;
187
+ * targetUsd: one target picture's price at the generator's upper rate.
188
+ */
189
+ export function estimateLevels({ pricing, judge = null, targetUsd = 0 } = {}) {
190
+ const card = pricingOf(pricing)
191
+ const second = pricingOf(judge)
192
+ const picture = Number.isFinite(targetUsd) && targetUsd > 0 ? targetUsd : 0
193
+ return LEVEL_IDS.map((id) => {
194
+ const level = LEVELS[id]
195
+ const usd = estimateRun(level, { card, second, picture })
196
+ return { id, timeFloorMin: level.timeFloorMin, timeCapMin: level.timeCapMin, roundCap: level.roundCap, bar: level.bar, usd }
197
+ })
198
+ }
199
+
200
+ /**
201
+ * One new space at a quality step, priced on that step's model with the
202
+ * judge on JUDGE_MODEL, by the same arithmetic as estimateLevels, with the
203
+ * build's and the rounds' output per call scaled by the step's effort
204
+ * (EFFORT_OUTPUT), so the amount approved covers what that effort writes.
205
+ *
206
+ * @param {number} step 1 to 5
207
+ * @param {{ judge?: object | [number, number] | null, targetUsd?: number, pricing?: object | null }} input
208
+ * judge: the second judge's price card (OpenAI's), when there is one;
209
+ * pricing: the builder's card when it is not the step's model (another
210
+ * vendor chosen in Settings, which the step leaves in place).
211
+ */
212
+ export function estimateQuality(step, { judge = null, targetUsd = 0, pricing } = {}) {
213
+ const q = QUALITY[qualityOf(step)]
214
+ if (!q) throw new Error(`There is no quality step ${step}: it is 1 to 5.`)
215
+ const level = qualityLevel(q.step)
216
+ const card = pricingOf(pricing === undefined ? PRICING[q.model] : pricing)
217
+ const picture = Number.isFinite(targetUsd) && targetUsd > 0 ? targetUsd : 0
218
+ const usd = estimateRun(level, { card, judgeCard: pricingOf(PRICING[JUDGE_MODEL]), second: pricingOf(judge), picture, outputScale: EFFORT_OUTPUT[q.effort] ?? 1 })
219
+ return { ...q, level: level.id, usd }
220
+ }
221
+
222
+ /** What one judge's call costs on a card, for the spend after a round. */
223
+ export const judgeCallUsd = (pricing, usage = null) => {
224
+ const card = pricingOf(pricing)
225
+ if (!card) return 0
226
+ if (usage) return priceOf(usage, card)
227
+ return profileUsd(JUDGE_CALL, card)
228
+ }
229
+
230
+ // ---------------------------------------------------------------- the card's words
231
+
232
+ /** The level and environment names in the seven languages the cards speak
233
+ * (cards/labels.ts): the card's own label tables may draw them again. */
234
+ const LEVEL_WORDS = {
235
+ en: { quick: ['Quick', 'up to 30 min'], standard: ['Standard', '1 to 3 hours'], deep: ['Deep', '4 to 12 hours'] },
236
+ ko: { quick: ['빠르게', '30분 이내'], standard: ['보통', '1~3시간'], deep: ['깊게', '4~12시간'] },
237
+ ja: { quick: ['速く', '30分以内'], standard: ['標準', '1〜3時間'], deep: ['じっくり', '4〜12時間'] },
238
+ zh: { quick: ['快速', '30分钟以内'], standard: ['标准', '1至3小时'], deep: ['深入', '4至12小时'] },
239
+ es: { quick: ['Rápido', 'hasta 30 min'], standard: ['Normal', 'de 1 a 3 horas'], deep: ['A fondo', 'de 4 a 12 horas'] },
240
+ fr: { quick: ['Rapide', "jusqu'à 30 min"], standard: ['Normal', '1 à 3 heures'], deep: ['Approfondi', '4 à 12 heures'] },
241
+ de: { quick: ['Schnell', 'bis 30 Min.'], standard: ['Normal', '1 bis 3 Stunden'], deep: ['Gründlich', '4 bis 12 Stunden'] },
242
+ }
243
+ const ENVIRONMENT_WORDS = {
244
+ en: { mesh: ['Build it in 3D', 'Meshes and materials made for this space'], upload: ['Upload a file', 'A model or a splat of your own, with a collider'], marble: ['Generate with Marble', 'Paid, after its own cost card'] },
245
+ ko: { mesh: ['3D로 짓기', '이 공간을 위해 만든 메시와 재질'], upload: ['파일 올리기', '내 모델이나 스플랫, 콜라이더 선택'], marble: ['Marble로 생성', '유료, 비용 카드 먼저'] },
246
+ ja: { mesh: ['3Dで作る', 'この空間のためのメッシュと素材'], upload: ['ファイルを使う', '自分のモデルかスプラット、コライダー付き'], marble: ['Marbleで生成', '有料、先に費用カード'] },
247
+ zh: { mesh: ['用3D搭建', '为这个空间制作的网格和材质'], upload: ['上传文件', '自己的模型或点云,可选碰撞体'], marble: ['用Marble生成', '付费,先看费用卡'] },
248
+ es: { mesh: ['Construirlo en 3D', 'Mallas y materiales hechos para este espacio'], upload: ['Subir un archivo', 'Un modelo o un splat tuyo, con colisionador'], marble: ['Generar con Marble', 'De pago, tras su tarjeta de coste'] },
249
+ fr: { mesh: ['Le construire en 3D', 'Des maillages et matériaux faits pour cet espace'], upload: ['Envoyer un fichier', 'Un modèle ou un splat à vous, avec collisionneur'], marble: ['Générer avec Marble', 'Payant, après sa carte de coût'] },
250
+ de: { mesh: ['In 3D bauen', 'Meshes und Materialien für diesen Raum'], upload: ['Datei hochladen', 'Ein eigenes Modell oder Splat, mit Kollider'], marble: ['Mit Marble erzeugen', 'Kostenpflichtig, nach eigener Kostenkarte'] },
251
+ }
252
+ const LABEL_LOCALES = Object.keys(LEVEL_WORDS)
253
+ /** The card table a locale reads from: its language, else English. The
254
+ * locale is the screen language (locale.cjs screenLocale), never the one
255
+ * the creator writes in. */
256
+ export const labelLocale = (locale) => {
257
+ const lang = String(locale ?? '').slice(0, 2).toLowerCase()
258
+ return LABEL_LOCALES.includes(lang) ? lang : 'en'
259
+ }
260
+ export const ENVIRONMENTS = Object.freeze(['mesh', 'upload', 'marble'])
261
+
262
+ /** The levels for the card, labelled in the screen language. A model with
263
+ * no price has usd null, which the card shows as no price, never as free. */
264
+ export function levelsFor(locale, estimates) {
265
+ const words = LEVEL_WORDS[labelLocale(locale)]
266
+ return estimates.map((e) => ({ id: e.id, label: words[e.id][0], timeFloorMin: e.timeFloorMin, timeCapMin: e.timeCapMin, roundCap: e.roundCap, bar: e.bar, usd: e.usd ?? null }))
267
+ }
268
+
269
+ /** The three ways to make the environment, labelled in the screen language. */
270
+ export function environmentsFor(locale) {
271
+ const words = ENVIRONMENT_WORDS[labelLocale(locale)]
272
+ return ENVIRONMENTS.map((id) => ({ id, label: words[id][0], detail: words[id][1] }))
273
+ }
@@ -0,0 +1,358 @@
1
+ // Where one space's reference loop stands (REFERENCE_LOOP.md 2): the
2
+ // kickoff's answer (its speed level, the questions' answers, how the
3
+ // environment is made), the target pictures and the hero view each stands
4
+ // for, the rounds with the judge's scores, and the approval card's answer.
5
+ // The host makes one for each request (host.mjs); the loop's tools change
6
+ // it (tools/loop.mjs), the stop gate and the pace read it (loop/gate.mjs,
7
+ // pace.mjs), and brief.json carries its budget, bar and score history.
8
+ //
9
+ // It is kept in .nowhere/rounds/loop.json beside the round folders, so a
10
+ // "continue" goes on with the same level, targets and clock (the minutes
11
+ // spent in earlier requests count toward the floor and the cap). A new
12
+ // space request starts over at its own kickoff: what an earlier space left
13
+ // there numbers the rounds and nothing else until then. Only a loop that
14
+ // holds its request writes the file, so a request in between (a question,
15
+ // the "explain what you made" chip) never leaves a blank record over it.
16
+ //
17
+ // The clock starts when the kickoff is answered, and the minutes the
18
+ // creator takes over a card are left out (noteWait): a level's floor and
19
+ // cap are minutes of work, and two unanswered cards would otherwise use
20
+ // twenty of quick's thirty before anything was built.
21
+
22
+ import fs from 'node:fs'
23
+ import fsp from 'node:fs/promises'
24
+ import path from 'node:path'
25
+ import { COMPARE_BAR, LEVELS, MAX_REDRAWS, levelFor, qualityLevel } from './levels.mjs'
26
+
27
+ export const ROUNDS_DIR = path.join('.nowhere', 'rounds')
28
+ export const LOOP_FILE = path.join(ROUNDS_DIR, 'loop.json')
29
+ const SCHEMA = 'nowhere/loop@1'
30
+
31
+ /** The round folders already in the project: their numbers, ascending. */
32
+ export function roundNumbers(projectRoot) {
33
+ try {
34
+ return fs
35
+ .readdirSync(path.join(projectRoot, ROUNDS_DIR), { withFileTypes: true })
36
+ .filter((e) => e.isDirectory() && /^\d{1,4}$/.test(e.name))
37
+ .map((e) => Number(e.name))
38
+ .sort((a, b) => a - b)
39
+ } catch {
40
+ return []
41
+ }
42
+ }
43
+
44
+ function readSaved(projectRoot) {
45
+ try {
46
+ const raw = JSON.parse(fs.readFileSync(path.join(projectRoot, LOOP_FILE), 'utf8'))
47
+ return raw?.schema === SCHEMA ? raw : null
48
+ } catch {
49
+ return null
50
+ }
51
+ }
52
+
53
+ /** A fresh loop record. targets.delegated: the creator left the targets to
54
+ * the agent (the card's "you choose", or no answer), so nw_ask_targets may
55
+ * record a set with no card. */
56
+ const blank = () => ({ schema: SCHEMA, kickoff: null, budget: null, bar: null, targets: { round: 0, settled: false, none: null, delegated: false, images: [] }, rounds: [], approval: null, spentMs: 0, notes: [] })
57
+
58
+ /** The notes as kept: a plain string (the approval card's "one more round"
59
+ * note, or a loop.json from before notes kept the creator's words apart)
60
+ * is its own words; anything else unreadable is left out. */
61
+ function keptNotes(notes) {
62
+ return (Array.isArray(notes) ? notes : [])
63
+ .map((n) => (typeof n === 'string' ? { gap: n, said: n } : n && typeof n.gap === 'string' ? { gap: n.gap, said: typeof n.said === 'string' ? n.said : n.gap, hero: typeof n.hero === 'string' ? n.hero : null } : null))
64
+ .filter(Boolean)
65
+ }
66
+
67
+ /** A saved loop that is over: the creator pressed Publish after its last round. */
68
+ function finished(saved) {
69
+ const last = Array.isArray(saved?.rounds) ? saved.rounds.at(-1) : null
70
+ return saved?.approval?.answer === 'publish' && (!last || saved.approval.afterRound === last.n)
71
+ }
72
+
73
+ /**
74
+ * Whether a round counts toward the bar: every settled target's hero view
75
+ * was scored in it. A round on some of the views (nw_round heroes, or a
76
+ * view still loading) helps plan the next one but cannot end the loop, or
77
+ * the run could choose which views get judged.
78
+ */
79
+ export function judgedAll(targets, round) {
80
+ const heroes = (targets?.images ?? []).map((t) => t.hero)
81
+ if (!round || heroes.length === 0) return false
82
+ return heroes.every((h) => Number.isFinite(round.views?.[h]))
83
+ }
84
+
85
+ /**
86
+ * @param {{ projectRoot: string, space?: boolean, continued?: boolean, now?: () => number }} options
87
+ * space: the request builds a space (host.mjs depth.space): the stop gate
88
+ * holds it to the loop once a kickoff stands, and asks for the kickoff
89
+ * when it built without one. continued: it only says to go on, so a saved
90
+ * loop that is not over (no Publish after its last round) is this
91
+ * request's too, whatever request came in between.
92
+ */
93
+ export function createLoop({ projectRoot, space = false, continued = false, now = () => Date.now() }) {
94
+ const saved = readSaved(projectRoot)
95
+ const inherited = continued && !!saved?.kickoff && !finished(saved)
96
+ // A continuation picks up where the saved loop stood; anything else starts
97
+ // clean and only numbers its rounds after what is on disk.
98
+ const state = inherited ? { ...blank(), ...saved, targets: { ...blank().targets, ...(saved.targets ?? {}) } } : blank()
99
+ let kickedHere = false
100
+ // This request's part of the clock: from its start (a continuation) or
101
+ // from the kickoff's answer, less the creator's time over cards.
102
+ let clockStart = now()
103
+ let waitedMs = 0
104
+ /** The cost cards approved since the kickoff (tools/cards.mjs): a paid
105
+ * environment needs one of its own (tools/environment.mjs). */
106
+ let costCards = []
107
+ let costUnanswered = false
108
+ let writing = Promise.resolve()
109
+ const thisRequestMs = () => Math.max(0, now() - clockStart - waitedMs)
110
+
111
+ const loop = {
112
+ get space() {
113
+ return space
114
+ },
115
+ /** The loop holds this request: its own kickoff, or the one a
116
+ * "continue" goes on with. */
117
+ get active() {
118
+ return !!state.kickoff && (kickedHere || inherited)
119
+ },
120
+ /** The kickoff was answered in this request (not inherited). */
121
+ get kickedHere() {
122
+ return kickedHere
123
+ },
124
+ get kickoff() {
125
+ return state.kickoff
126
+ },
127
+ get budget() {
128
+ return state.budget
129
+ },
130
+ get bar() {
131
+ return state.bar
132
+ },
133
+ get targets() {
134
+ return state.targets
135
+ },
136
+ get rounds() {
137
+ return state.rounds
138
+ },
139
+ get approval() {
140
+ return state.approval
141
+ },
142
+ get level() {
143
+ if (state.budget?.quality) return qualityLevel(state.budget.quality)
144
+ return state.budget?.level ? LEVELS[state.budget.level] ?? null : null
145
+ },
146
+ /** The quality step the loop was started at (1 to 5), or null for a
147
+ * speed level: a "continue" keeps it, whatever the composer says now. */
148
+ get quality() {
149
+ return state.budget?.quality ?? null
150
+ },
151
+ /** The rounds a quality step judges before its bar may end it (0 for a speed level). */
152
+ minRounds() {
153
+ return Number(state.budget?.minRounds) || 0
154
+ },
155
+ /** The rounds that count toward those: the ones that scored every hero
156
+ * view with a target, on a space that had changed since the round
157
+ * counted before it. A round on some of the views, one no judge scored
158
+ * and one taken again on the same space are not counted. With no
159
+ * targets nothing is judged at all, and every round taken counts. */
160
+ judgedRounds() {
161
+ if (state.targets.none) return state.rounds.length
162
+ let count = 0
163
+ let before = null
164
+ for (const round of state.rounds) {
165
+ if (!judgedAll(state.targets, round) || !Number.isFinite(round.score)) continue
166
+ if (round.fingerprint && round.fingerprint === before) continue
167
+ before = round.fingerprint ?? null
168
+ count++
169
+ }
170
+ return count
171
+ },
172
+ /** Minutes spent on this loop: earlier requests' and this one's. */
173
+ elapsedMin() {
174
+ return (Number(state.spentMs || 0) + thisRequestMs()) / 60_000
175
+ },
176
+ /** The creator took `ms` over a card: not the loop's working time. */
177
+ noteWait(ms) {
178
+ const n = Number(ms)
179
+ if (Number.isFinite(n) && n > 0) waitedMs += n
180
+ },
181
+ /** A cost card was approved (nw_ask kind cost), for what. */
182
+ noteCostCard(usd) {
183
+ const n = Number(usd)
184
+ if (state.kickoff && Number.isFinite(n) && n > 0) costCards.push({ usd: n, at: now() })
185
+ },
186
+ /** Whether a cost card approved since the kickoff covers `usd` on its own. */
187
+ costCardCovers(usd) {
188
+ return costCards.some((c) => c.usd >= Number(usd) - 1e-9)
189
+ },
190
+ /** A cost card went unanswered (or there was no studio to ask): with no
191
+ * approval, nothing can be built until the creator answers one. */
192
+ noteCostUnanswered() {
193
+ costUnanswered = true
194
+ },
195
+ get costUnanswered() {
196
+ return costUnanswered
197
+ },
198
+ /** Minutes left before the time cap, or null with no level yet. */
199
+ remainingMin() {
200
+ return state.budget ? Math.max(0, state.budget.timeCapMin - loop.elapsedMin()) : null
201
+ },
202
+ /** The rounds' numbers continue from the folders on disk. */
203
+ nextRound() {
204
+ return Math.max(0, ...roundNumbers(projectRoot), ...state.rounds.map((r) => r.n)) + 1
205
+ },
206
+ /** What stops the loop early, whatever the score: the round cap or the time cap. */
207
+ capped() {
208
+ if (!state.budget) return { time: false, rounds: false, any: false }
209
+ const time = loop.elapsedMin() >= state.budget.timeCapMin
210
+ const rounds = state.rounds.length >= state.budget.roundCap
211
+ return { time, rounds, any: time || rounds }
212
+ },
213
+ /** The last round, or null. */
214
+ last() {
215
+ return state.rounds.at(-1) ?? null
216
+ },
217
+ scoreHistory() {
218
+ return state.rounds.map((r) => r.score).filter((s) => Number.isFinite(s))
219
+ },
220
+ /** Whether `round` (default the last) scored every target's hero view. */
221
+ judgedAll(round = loop.last()) {
222
+ return judgedAll(state.targets, round)
223
+ },
224
+ /** Whether the last round is at the bar on every hero view with a target. */
225
+ reached() {
226
+ const last = loop.last()
227
+ return !!last && !state.targets.none && judgedAll(state.targets, last) && Number.isFinite(last.score) && last.score >= (state.bar?.judge ?? 10)
228
+ },
229
+
230
+ /** The kickoff card was answered (or went unanswered): a new loop at
231
+ * that level, or at the request's quality step, its clock starting now.
232
+ * Once per loop: tools/loop.mjs refuses a second kickoff before it gets
233
+ * here. An unknown level throws (levelFor). */
234
+ kick({ level = null, quality = null, answers = {}, environment = null, timedOut = false, unavailable = false, usd = null, approvedUsd = null }) {
235
+ const l = levelFor({ level, quality })
236
+ Object.assign(state, blank())
237
+ state.kickoff = { level: l.id, ...(l.quality ? { quality: l.quality } : {}), answers, environment, timedOut, unavailable, approvedUsd, at: new Date(now()).toISOString() }
238
+ state.budget = {
239
+ level: l.id,
240
+ ...(l.quality ? { quality: l.quality, minRounds: l.minRounds } : {}),
241
+ timeFloorMin: l.timeFloorMin,
242
+ timeCapMin: l.timeCapMin,
243
+ roundCap: l.roundCap,
244
+ ...(usd ? { usdEstimate: { lo: usd.lo, hi: usd.hi } } : {}),
245
+ }
246
+ state.bar = { judge: l.bar, compare: COMPARE_BAR }
247
+ kickedHere = true
248
+ clockStart = now()
249
+ waitedMs = 0
250
+ costCards = []
251
+ return loop.save()
252
+ },
253
+ /** A targets card went out: the redraw count it showed. */
254
+ targetsShown(round) {
255
+ state.targets.round = Math.max(state.targets.round, round)
256
+ return loop.save()
257
+ },
258
+ /** The redraws left for the targets card. */
259
+ redrawsLeft() {
260
+ return Math.max(0, MAX_REDRAWS - state.targets.round)
261
+ },
262
+ /** The targets are settled: the pictures each hero view is judged
263
+ * against, or none, and why. */
264
+ settleTargets({ images = [], none = null }) {
265
+ state.targets = { ...state.targets, settled: true, none: none ? String(none).slice(0, 400) : null, images }
266
+ return loop.save()
267
+ },
268
+ /** The creator left the targets to the agent ("you choose", or no answer). */
269
+ delegateTargets() {
270
+ state.targets.delegated = true
271
+ return loop.save()
272
+ },
273
+ /** A round was judged. */
274
+ addRound(round) {
275
+ state.rounds.push(round)
276
+ // A creator's note for "one more round" is the first gap of the round
277
+ // it asked for, and is spent there.
278
+ state.notes = []
279
+ return loop.save()
280
+ },
281
+ /** The approval card's answer. */
282
+ setApproval(answer) {
283
+ state.approval = { ...answer, afterRound: loop.last()?.n ?? 0, at: new Date(now()).toISOString() }
284
+ // Beside any note the creator sent mid-run that no round has taken yet.
285
+ if (answer.answer === 'another' && answer.note) state.notes = [String(answer.note).slice(0, 500), ...(state.notes ?? [])].slice(0, 6)
286
+ return loop.save()
287
+ },
288
+ /** The creator's notes the next round starts from, as the agent reads
289
+ * them (the words, the picture kept and where its marks are). */
290
+ notes() {
291
+ return keptNotes(state.notes).map((n) => n.gap)
292
+ },
293
+ /** The same notes with the creator's own words beside each (said) and
294
+ * the hero view they marked: what the chat shows back, never the file
295
+ * the picture was kept in or the marks' pixels. */
296
+ creatorNotes() {
297
+ return keptNotes(state.notes).map((n) => ({ gap: n.gap, said: n.said, ...(n.hero ? { hero: n.hero } : {}) }))
298
+ },
299
+ /** A note the creator sent while the run worked (host.mjs inbox): the
300
+ * first gap of the next round, as the approval card's is. gap is what
301
+ * the agent reads; said and hero what the chat shows back. */
302
+ addNote(gap, { said, hero } = {}) {
303
+ const t = String(gap ?? '').trim().slice(0, 500)
304
+ if (!t) return Promise.resolve()
305
+ const words = typeof said === 'string' ? said.trim().slice(0, 500) : t
306
+ const view = typeof hero === 'string' && /^H[1-6]$/.test(hero) ? hero : null
307
+ state.notes = [...(state.notes ?? []), { gap: t, said: words, ...(view ? { hero: view } : {}) }].slice(-6)
308
+ return loop.save()
309
+ },
310
+ /** Writes loop.json, the minutes so far included. Never throws. Only a
311
+ * loop that holds this request writes: anything else would put a blank
312
+ * record over the one a later "continue" goes on with. */
313
+ save() {
314
+ if (!loop.active) return writing
315
+ const doc = { ...state, spentMs: Number(state.spentMs || 0) + thisRequestMs(), savedAt: new Date(now()).toISOString() }
316
+ const file = path.join(projectRoot, LOOP_FILE)
317
+ writing = writing.then(async () => {
318
+ try {
319
+ await fsp.mkdir(path.dirname(file), { recursive: true })
320
+ const temp = `${file}.${process.pid}.part`
321
+ await fsp.writeFile(temp, `${JSON.stringify(doc, null, 2)}\n`)
322
+ await fsp.rename(temp, file)
323
+ } catch {
324
+ // the loop goes on in memory; a continuation starts over
325
+ }
326
+ })
327
+ return writing
328
+ },
329
+ /** What the done event says about the loop, or null when it did not
330
+ * hold. beforeFloor and belowBar are what the chat says plainly when the
331
+ * run ended without its bar (a cap, or the gate letting go). */
332
+ summary() {
333
+ if (!state.kickoff) return null
334
+ const last = loop.last()
335
+ const reached = loop.reached()
336
+ const elapsed = loop.elapsedMin()
337
+ return {
338
+ level: state.budget?.level ?? null,
339
+ ...(state.budget?.quality ? { quality: state.budget.quality, minRounds: state.budget.minRounds } : {}),
340
+ rounds: state.rounds.length,
341
+ score: last?.score ?? null,
342
+ bar: state.bar?.judge ?? null,
343
+ reached,
344
+ judgedAll: !!last && judgedAll(state.targets, last),
345
+ capped: loop.capped().any,
346
+ elapsedMin: Math.round(elapsed),
347
+ beforeFloor: elapsed < (state.budget?.timeFloorMin ?? 0),
348
+ beforeMinRounds: loop.judgedRounds() < loop.minRounds(),
349
+ belowBar: !reached,
350
+ approval: state.approval?.answer ?? null,
351
+ targets: state.targets.none ? 'none' : state.targets.images.length,
352
+ }
353
+ },
354
+ /** The record as it is, for the checks. */
355
+ snapshot: () => JSON.parse(JSON.stringify(state)),
356
+ }
357
+ return loop
358
+ }