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,663 @@
1
+ // The shapes every part of a production agrees on: what the reference tools
2
+ // measure, what the decision sessions answer (the interpretation, the vision,
3
+ // the board), what each role reports, what the critic and QA return, what a
4
+ // gate decides, and what the chat is sent. zod is the authority; the
5
+ // TypeScript in the orchestrator spec (section 3) is only their outline.
6
+ //
7
+ // The structured-output schemas the sessions are given come from these with
8
+ // jsonSchemaOf, kept to a plain subset of JSON Schema (type, properties,
9
+ // required, enum, items, minItems, maxItems, additionalProperties): which
10
+ // keywords the CLI's structured output takes is not known, so every bound
11
+ // that is left out there (lengths, ranges, hex patterns) is held again here
12
+ // when code parses the answer; lengths and list sizes are cut to fit first
13
+ // (fitTo), since no prompt states them.
14
+ //
15
+ // Strings the creator reads are bounded: labels 80 characters, lines 200,
16
+ // bodies 600 (the cards' own limits, cards.cjs).
17
+
18
+ import { z } from 'zod'
19
+ import { IMAGE_PROVIDER_IDS } from '../assets/images/index.mjs'
20
+ import { PROVIDERS } from '../assets/providers/index.mjs'
21
+
22
+ export const ROLE_IDS = ['builder', 'artist', 'modeller', 'sound', 'qa']
23
+ export const LANES = ['preview', 'blender', 'free']
24
+ /** kept: below the critic's bar, but the best attempt there was, and in the game. */
25
+ export const TASK_STATUS = ['waiting', 'ready', 'running', 'checking', 'passed', 'kept', 'failed', 'blocked', 'stopped', 'skipped']
26
+ export const CHECK_KINDS = ['build', 'runtime', 'markers', 'ownership', 'ledger', 'seams', 'coverage', 'view', 'cameras', 'placements', 'compare', 'play', 'eval', 'perf', 'asset', 'module', 'palette', 'audio']
27
+ export const PHASES = ['triage', 'interpret', 'vision', 'plan', 'estimate', 'build', 'check', 'final', 'deliver', 'done', 'stopped']
28
+ export const PROGRESS = ['first', 'better', 'same', 'worse', 'stagnant']
29
+
30
+ const label = z.string().min(1).max(80)
31
+ const line = z.string().max(200)
32
+ const body = z.string().max(600)
33
+ /** Longer prose for the model's own use (a brief's paragraph), never on a card. */
34
+ const prose = z.string().max(2000)
35
+ const lines = (max = 12) => z.array(line).max(max)
36
+ const num = z.number()
37
+ const unit = z.number().min(0).max(1)
38
+ const score = z.number().min(1).max(5)
39
+ export const HEX = /^#[0-9a-fA-F]{6}$/
40
+ const hex = z.string().regex(HEX, 'a colour as #rrggbb')
41
+ /** An object whose fields the schema does not name (an nw_play step, a shot). */
42
+ const anyObject = z.looseObject({})
43
+ export const RoleId = z.enum(ROLE_IDS)
44
+
45
+ // ---------------------------------------------------------------- 3.1 ReferenceFacts (ROLES computes)
46
+
47
+ const Lab = z.union([z.object({ L: num, a: num, b: num }), z.array(num).length(3)])
48
+ const Fractions4 = z.tuple([num, num, num, num])
49
+ const Band = z.enum(['top', 'upper', 'middle', 'lower', 'bottom'])
50
+ export const SHAPES = ['tall', 'square', 'wide']
51
+ const Where = z.object({ at: z.tuple([num, num]), box: Fractions4 })
52
+
53
+ export const ReferenceFacts = z.object({
54
+ source: z.string(),
55
+ crop: Fractions4.nullable(),
56
+ size: z.object({ width: num, height: num, aspect: num, shape: z.enum(SHAPES) }),
57
+ /** The lettering found and masked out before anything else was measured. */
58
+ text: z.object({
59
+ boxes: z.array(z.object({ box: Fractions4, height: num, kind: z.enum(['title', 'small']), ink: z.enum(['light', 'dark']), letters: num })),
60
+ share: unit,
61
+ }),
62
+ palette: z.array(z.object({ hex, share: unit, lab: Lab, oklab: z.array(num).length(3), where: Where.optional() })).max(8),
63
+ accents: z.array(z.object({ hex, share: unit })).max(8),
64
+ value: z.object({ key: z.enum(['low', 'mid', 'high']), meanL: num, p5: num, p50: num, p95: num, histogram: z.array(num), clipHigh: num, clipLow: num }),
65
+ contrast: z.object({ stdL: num, local: num }),
66
+ saturation: z.object({ meanChroma: num, p90Chroma: num, colourfulness: num }),
67
+ temperature: z.object({ warmth: num, tint: num, warmShare: num, coolShare: num }),
68
+ haze: z.object({
69
+ bands: z.array(z.object({ band: Band, meanL: num, contrast: num, chroma: num })),
70
+ score: num,
71
+ direction: z.enum(['toward-top', 'toward-bottom', 'none']),
72
+ }),
73
+ composition: z.object({
74
+ thirds: z.array(z.array(num)),
75
+ centroid: z.tuple([num, num]),
76
+ focal: z.array(z.object({ id: z.string(), x: num, y: num, share: num, box: Fractions4, mass: z.string().nullable(), where: z.string() })),
77
+ symmetry: num,
78
+ negativeSpace: num,
79
+ edgeGrid: z.array(z.array(num)),
80
+ }),
81
+ /** The big dark, mid and light shapes, as a value study reads them. */
82
+ masses: z.array(
83
+ z.object({ id: z.string(), value: z.enum(['dark', 'mid', 'light']), box: Fractions4, share: unit, hex, tall: num, fill: num, at: z.tuple([num, num]), band: Band, above: z.array(z.string()), below: z.array(z.string()) }),
84
+ ).max(8),
85
+ horizon: z.object({ y: num.nullable(), tiltDeg: num, confidence: unit }),
86
+ camera: z.object({ guess: z.enum(['eye-level', 'low', 'high', 'aerial', 'top-down']), pitchDeg: num, confidence: unit, why: z.string() }),
87
+ frame: z.object({
88
+ border: z.object({ top: num, bottom: num, left: num, right: num }),
89
+ textLikely: z.boolean(),
90
+ suggestedCrop: Fractions4.nullable(),
91
+ }),
92
+ })
93
+
94
+ // ---------------------------------------------------------------- 3.2 Interpretation and ArtBrief
95
+
96
+ const CameraPurpose = z.enum(['reference', 'player', 'closeup', 'overview', 'moment'])
97
+ export const BriefCamera = z.object({
98
+ id: z.string().min(1).max(40),
99
+ purpose: CameraPurpose,
100
+ subject: line.optional(),
101
+ heightM: num.optional(),
102
+ pitchDeg: num.optional(),
103
+ fovDeg: num.optional(),
104
+ horizonY: num.optional(),
105
+ /** nw_view's frame shape; code sets the reference camera's from the picture. */
106
+ aspect: z.enum(SHAPES).optional(),
107
+ })
108
+
109
+ /** A box of a picture in fractions [x0, y0, x1, y1], as the structured
110
+ * output takes it (a plain list; parseWith holds its length and range). */
111
+ const Box = z.array(unit).length(4)
112
+ export const SUBJECT_KINDS = ['mass', 'ground', 'landmark', 'figure', 'atmosphere', 'scale-cue']
113
+ /**
114
+ * A thing the reference clearly shows (post-mortem gap 2): its box in the
115
+ * picture as the facts measure it, its kind (atmosphere, and ground that
116
+ * runs across the frame, are seen in depth, the rest whole), and its role
117
+ * in the game: keep
118
+ * (the game has it, in its place and proportion) or transform (a specific
119
+ * character, logo or likeness the game must not copy: an original thing of
120
+ * the same role, frame position and relative size takes its place, named in
121
+ * replacement). form is the forms.scale element it is sized by; masses the
122
+ * facts' masses it covers.
123
+ */
124
+ export const Subject = z.object({
125
+ id: z.string().min(1).max(40),
126
+ what: line,
127
+ box: Box,
128
+ kind: z.enum(SUBJECT_KINDS),
129
+ role: z.enum(['keep', 'transform']),
130
+ form: line.optional(),
131
+ masses: z.array(z.string().max(10)).max(8).optional(),
132
+ replacement: line.optional(),
133
+ })
134
+
135
+ export const ArtBrief = z.object({
136
+ subject: prose,
137
+ play: z.object({ verbs: lines(12), goal: line, loop: body }),
138
+ /** An element from the reference names the subject it shows or the fact it reads. */
139
+ requestElements: z.array(z.object({ id: z.string().min(1).max(40), text: line, from: z.enum(['request', 'reference']), subject: z.string().max(40).optional(), fact: z.string().max(40).optional() })).min(1).max(24),
140
+ subjects: z.array(Subject).max(16),
141
+ palette: z.array(z.object({ hex, share: unit, role: line, fact: line })).min(1).max(10),
142
+ values: z.object({ key: z.enum(['low', 'mid', 'high']), range: z.array(num).length(2), contrast: z.enum(['soft', 'medium', 'hard']), fact: line }),
143
+ light: z.object({ sunElevationDeg: num, sunAzimuthDeg: num, colourTempK: num, ambient: line, shadowSoftness: num, fact: line }),
144
+ // Fog only when the request or the reference has it: clear air, space or a
145
+ // room is fog null, and haze layers only where the reference stages them.
146
+ atmosphere: z.object({ fog: z.object({ colour: hex, nearM: num, farM: num, height: z.boolean() }).nullable(), hazeLayers: z.number().int().min(0).max(8).optional(), fact: line }),
147
+ forms: z.object({
148
+ language: body,
149
+ scale: z.array(z.object({ element: line, sizeM: z.object({ h: num.optional(), w: num.optional(), d: num.optional() }), count: z.number().int().optional() })).max(24),
150
+ silhouettes: lines(12),
151
+ }),
152
+ materials: z.array(z.object({ surface: line, colours: z.array(hex).max(6), roughness: z.array(num).length(2), metal: z.boolean(), detail: line })).max(16),
153
+ detail: z.object({ near: line, mid: line, far: line }),
154
+ cameras: z.array(BriefCamera).min(1).max(12),
155
+ sound: z.object({ mood: line, sources: lines(12), events: z.array(z.object({ id: z.string().min(1).max(40), when: line, loop: z.boolean() })).max(16) }),
156
+ performance: z.object({ tier: z.enum(['low', 'mid', 'high']), drawCalls: z.number().int().min(1), triangles: z.number().int().min(1) }),
157
+ exclusions: lines(16),
158
+ assumptions: z.array(z.object({ what: line, why: line, confidence: z.enum(['low', 'medium', 'high']) })).max(16),
159
+ })
160
+
161
+ export const Interpretation = z.object({
162
+ readings: z.array(z.object({ id: z.string().min(1).max(40), summary: body })).min(2).max(3),
163
+ chosen: z.string().min(1).max(40),
164
+ why: body,
165
+ brief: ArtBrief,
166
+ })
167
+
168
+ /** The default performance tier for an inexpensive laptop (engine-direction 2.11). */
169
+ export const PERFORMANCE_DEFAULT = { tier: 'low', drawCalls: 150, triangles: 500_000 }
170
+
171
+ // ---------------------------------------------------------------- 3.3 Vision
172
+
173
+ export const Moment = z.object({ id: z.string().min(1).max(40), label, camera: z.string().min(1).max(40), sees: line, does: line, acceptance: line })
174
+ export const Vision = z.object({
175
+ concepts: z.array(z.object({ id: z.string().min(1).max(30), title: label, pitch: line, differs: line })).min(2).max(3),
176
+ chosen: z.string().min(1).max(30),
177
+ reasons: body,
178
+ pillars: z.array(line).min(3).max(5),
179
+ moments: z.array(Moment).min(2).max(4),
180
+ additions: z.array(z.object({ what: line, why: line, withinIntent: line })).min(1).max(5),
181
+ scope: z.object({ in: lines(6), out: lines(6) }),
182
+ card: z.object({ title: label, body }),
183
+ })
184
+
185
+ // ---------------------------------------------------------------- 3.4 Board, Task, Check, Criterion, Interface
186
+
187
+ export const Expect = z.object({
188
+ code: z.string().min(1).max(2000),
189
+ op: z.enum(['==', '>=', '<=', 'between', 'truthy']),
190
+ value: z.unknown().optional(),
191
+ })
192
+
193
+ // One flat object for every kind, so the structured output needs no anyOf;
194
+ // what each kind needs is held by the refinement. eval's expect is a list of
195
+ // one there; normalizeCheck turns the object form of 3.4 into it.
196
+ const CheckBase = z.object({
197
+ id: z.string().min(1).max(40),
198
+ kind: z.enum(CHECK_KINDS),
199
+ cameras: z.array(z.string().max(40)).max(12).optional(),
200
+ camera: z.string().max(40).optional(),
201
+ steps: z.array(anyObject).max(40).optional(),
202
+ expect: z.array(Expect).max(12).optional(),
203
+ code: z.string().max(4000).optional(),
204
+ path: z.string().max(200).optional(),
205
+ class: z.string().max(20).optional(),
206
+ size: z.object({ height: num.optional(), width: num.optional(), depth: num.optional() }).optional(),
207
+ hero: z.boolean().optional(),
208
+ exports: z.array(z.string().max(80)).max(24).optional(),
209
+ files: z.array(z.string().max(200)).max(24).optional(),
210
+ events: z.array(z.string().max(40)).max(24).optional(),
211
+ })
212
+ const NEEDS = {
213
+ view: ['cameras'],
214
+ cameras: [],
215
+ compare: ['camera'],
216
+ play: ['steps', 'expect'],
217
+ eval: ['code', 'expect'],
218
+ asset: ['path', 'class'],
219
+ module: ['path', 'exports'],
220
+ palette: ['files'],
221
+ audio: ['events'],
222
+ }
223
+ export const Check = CheckBase.superRefine((c, ctx) => {
224
+ for (const field of NEEDS[c.kind] ?? []) {
225
+ if (c[field] === undefined) ctx.addIssue({ code: 'custom', path: [field], message: `a ${c.kind} check needs ${field}` })
226
+ }
227
+ if (c.kind === 'eval' && Array.isArray(c.expect) && c.expect.length !== 1) ctx.addIssue({ code: 'custom', path: ['expect'], message: 'an eval check has exactly one expect' })
228
+ })
229
+
230
+ /** A check as 3.4 writes it (eval's expect an object, asset's expect the
231
+ * size) in the flat shape above. */
232
+ export function normalizeCheck(check) {
233
+ if (!check || typeof check !== 'object') return check
234
+ const c = { ...check }
235
+ if (c.kind === 'eval' && c.expect && !Array.isArray(c.expect)) c.expect = [c.expect]
236
+ if (c.kind === 'asset' && c.expect && !Array.isArray(c.expect) && typeof c.expect === 'object') {
237
+ c.size = c.size ?? c.expect
238
+ delete c.expect
239
+ }
240
+ return c
241
+ }
242
+
243
+ /** subject: the brief subject it judges, against that subject's crop of the reference. */
244
+ export const Criterion = z.object({ id: z.string().min(1).max(40), text: line, camera: z.string().max(40).optional(), subject: z.string().max(40).optional() })
245
+ export const Interface = z.object({
246
+ id: z.string().min(1).max(40),
247
+ kind: z.enum(['materials', 'audio']),
248
+ module: z.string().min(1).max(200),
249
+ names: z.array(z.string().min(1).max(60)).min(1).max(32),
250
+ producer: z.string().min(1).max(10),
251
+ consumers: z.array(z.string().max(10)).max(12),
252
+ })
253
+
254
+ export const RoleReport = z.object({
255
+ summary: body,
256
+ done: lines(24),
257
+ notDone: lines(24),
258
+ assumptions: lines(24),
259
+ changesNeeded: z.array(z.object({ path: z.string().max(200), owner: z.enum([...ROLE_IDS, 'director']), what: line, why: line })).max(12),
260
+ cameras: z.array(z.object({ id: z.string().min(1).max(40), shot: anyObject })).max(12).optional(),
261
+ assets: z.array(z.object({ path: z.string().max(200), class: z.string().max(20), sizeM: z.object({ h: num, w: num, d: num }), triangles: z.number().int() })).max(12).optional(),
262
+ events: z.array(z.string().max(40)).max(24).optional(),
263
+ })
264
+
265
+ export const CompareMetrics = z.object({
266
+ camera: z.string(),
267
+ colour: z.looseObject({}),
268
+ structure: z.object({ correlation: num, horizonDelta: num.nullable(), centroidDelta: num, edgeRatio: num, detailRatio: num }),
269
+ distance: unit,
270
+ flags: z.array(z.enum(['palette-far', 'value-far', 'structure-far', 'detail-far'])),
271
+ })
272
+ /** The flags that stop a pass on their own (6.2). */
273
+ export const GROSS_FLAGS = ['palette-far', 'value-far', 'structure-far', 'detail-far']
274
+
275
+ export const CriticReport = z.object({
276
+ scores: z.object({ form: score, detail: score, composition: score, colour: score, light: score }),
277
+ overall: score,
278
+ criteria: z.array(z.object({ id: z.string().max(40), met: z.boolean(), note: line })).max(12),
279
+ pairwise: z.enum(['better', 'same', 'worse', 'first']),
280
+ // owner director: the brief itself contradicts the reference.
281
+ changes: z.array(z.object({ rank: z.number().int().min(1).max(8), what: line, where: line, why: line, fix: line, owner: z.enum([...ROLE_IDS, 'director']) })).max(8),
282
+ copied: z.boolean(),
283
+ verdict: z.enum(['pass', 'revise']),
284
+ confidence: unit,
285
+ })
286
+
287
+ export const QAReport = z.object({
288
+ scripts: z.array(z.object({ id: z.string().min(1).max(40), covers: z.array(z.string().max(40)).max(12), steps: z.array(anyObject).max(40), expect: z.array(Expect).max(12) })).max(16),
289
+ results: z.array(z.object({ script: z.string().max(40), ok: z.boolean(), observed: line })).max(16),
290
+ bugs: z
291
+ .array(
292
+ z.object({
293
+ id: z.string().min(1).max(40),
294
+ severity: z.enum(['blocker', 'major', 'minor']),
295
+ title: line,
296
+ repro: body,
297
+ expected: line,
298
+ actual: line,
299
+ owner: RoleId,
300
+ files: z.array(z.string().max(200)).max(12).optional(),
301
+ /** The id of the script that shows it, which the fix task replays. */
302
+ script: z.string().max(40).optional(),
303
+ }),
304
+ )
305
+ .max(16),
306
+ })
307
+
308
+ export const GateResult = z.object({
309
+ task: z.string(),
310
+ round: z.number().int(),
311
+ checks: z.array(
312
+ z.object({
313
+ id: z.string(),
314
+ kind: z.string(),
315
+ ok: z.boolean(),
316
+ text: z.string(),
317
+ evidence: z.object({ images: z.array(z.string()).optional(), numbers: z.record(z.string(), z.unknown()).optional() }),
318
+ }),
319
+ ),
320
+ metrics: CompareMetrics.nullable(),
321
+ critic: CriticReport.nullable(),
322
+ flags: z.array(z.string()),
323
+ pass: z.boolean(),
324
+ progress: z.enum(PROGRESS),
325
+ best: z.boolean(),
326
+ usd: num,
327
+ ms: num,
328
+ })
329
+
330
+ export const Attempt = z.looseObject({
331
+ round: z.number().int(),
332
+ rung: z.number().int().nullable(),
333
+ model: z.string(),
334
+ effort: z.string(),
335
+ sessionId: z.string().nullable(),
336
+ resumed: z.boolean(),
337
+ startedAt: num,
338
+ endedAt: num,
339
+ usd: num,
340
+ turns: num,
341
+ report: z.unknown().nullable(),
342
+ gate: z.unknown().nullable(),
343
+ restored: z.boolean(),
344
+ })
345
+
346
+ /** A placement id: the id the blockout's code adds a stand-in under. */
347
+ export const PLACEMENT_ID = /^[A-Za-z][\w-]*$/
348
+ /**
349
+ * One of the blockout's placements: where a made model will stand, held by
350
+ * a stand-in until it is ready. anchor is the part of the model that meets
351
+ * the stand-in's place: its base (it stands where the stand-in stood, the
352
+ * default) or its top (things stand on it, as on a platform the player
353
+ * walks).
354
+ */
355
+ export const Placement = z.object({ id: z.string().min(1).max(40), what: line, anchor: z.enum(['base', 'top']).optional() })
356
+
357
+ /**
358
+ * How a modelled asset is made, as PLAN chooses it from the capability list
359
+ * code builds (director/methods.mjs): a model the project has (file), a CC0
360
+ * library's, a Blender model scripted for it, image-to-3D from the
361
+ * reference's crop of a subject (crop-3d: subject, mesh), or a picture
362
+ * generated for it first and image-to-3D from that (image-3d: image,
363
+ * views, mesh, and the subject whose crop it starts from when it may). why
364
+ * is the reason in a line; code checks it can run and prices what it spends.
365
+ */
366
+ export const METHOD_IDS = ['project', 'library', 'blender', 'crop-3d', 'image-3d']
367
+ export const MESH_PROVIDER_IDS = Object.keys(PROVIDERS)
368
+ export const Method = z.object({
369
+ how: z.enum(METHOD_IDS),
370
+ why: line,
371
+ subject: z.string().max(40).optional(),
372
+ image: z.enum(IMAGE_PROVIDER_IDS).optional(),
373
+ views: z.number().int().min(1).max(4).optional(),
374
+ mesh: z.enum(MESH_PROVIDER_IDS).optional(),
375
+ file: z.string().max(200).optional(),
376
+ })
377
+
378
+ const TaskFields = {
379
+ id: z.string().regex(/^t[1-9][0-9]*$/, 'task ids are t1, t2, ...'),
380
+ role: RoleId,
381
+ title: line,
382
+ label,
383
+ goal: body,
384
+ covers: z.array(z.string().max(40)).max(24),
385
+ reads: z.array(z.string().max(200)).max(24),
386
+ owns: z.array(z.string().max(200)).max(24),
387
+ deps: z.array(z.string().max(10)).max(12),
388
+ interface: z.string().max(40).optional(),
389
+ makesCameras: z.boolean().optional(),
390
+ /** The blockout's: every placement a made model will take over. */
391
+ placements: z.array(Placement).max(16).optional(),
392
+ /** A modeller task's: the placement its model stands at. */
393
+ placement: z.string().max(40).optional(),
394
+ /** A modeller task's: how its asset is made, and the way it falls back to
395
+ * when the creator refuses what that needs (a key, a consent, a cost). */
396
+ method: Method.optional(),
397
+ fallback: Method.optional(),
398
+ accept: z.object({ checks: z.array(Check).max(16), critic: z.array(Criterion).max(12) }),
399
+ tier: z.enum(['small', 'mid', 'top']),
400
+ roundLimit: z.number().int().min(1).max(12),
401
+ examples: z.array(z.string().max(1000)).max(8).optional(),
402
+ }
403
+ export const PlanTask = z.object(TaskFields)
404
+ /** A task as the board keeps it: the plan's fields and what code adds. */
405
+ export const Task = z.looseObject({ ...TaskFields, status: z.enum(TASK_STATUS).optional(), attempts: z.array(Attempt).optional() })
406
+
407
+ const RoleWords = z.object(Object.fromEntries(ROLE_IDS.map((r) => [r, label])))
408
+ const BoardFields = {
409
+ interfaces: z.array(Interface).max(8),
410
+ paid: z.array(z.object({ tool: z.literal('asset_generate'), provider: z.enum(['meshy', 'fal']), request: anyObject, for: z.string().max(10) })).max(6),
411
+ card: z.object({ title: label, body, note: line.optional() }),
412
+ roleWords: RoleWords,
413
+ costWords: z.object({ direction: label, critique: label, report: label, reserve: label }),
414
+ }
415
+ /** PLAN's answer: the board, the cost card's words and the role names, all
416
+ * but the code-set task fields. */
417
+ export const PlanOutput = z.object({ tasks: z.array(PlanTask).min(1).max(16), ...BoardFields })
418
+ export const Board = z.looseObject({ tasks: z.array(Task), ...BoardFields })
419
+
420
+ // ---------------------------------------------------------------- the small decisions
421
+
422
+ export const TriageOutput = z.object({ route: z.enum(['fast', 'production']), why: line })
423
+ /** The read-back after INTERPRET: what the picture clearly shows that the
424
+ * brief's subjects, forms and cameras lack or contradict, each with its box. */
425
+ export const ReadBack = z.object({
426
+ traits: z.array(z.object({ what: line, kind: z.enum(['missing', 'contradicts']), box: Box, subject: z.string().max(40).optional(), why: line })).max(8),
427
+ })
428
+ /** The director's word on its open notes between rounds: change the brief
429
+ * (a subject as it should be, a form's size), hand a note to a role, or
430
+ * leave it for the report. */
431
+ export const NotesReview = z.object({
432
+ notes: z
433
+ .array(
434
+ z.object({
435
+ note: z.number().int().min(1).max(24),
436
+ action: z.enum(['amend', 'route', 'report']),
437
+ owner: RoleId.optional(),
438
+ subject: Subject.optional(),
439
+ form: z.object({ element: line, sizeM: z.object({ h: num.optional(), w: num.optional(), d: num.optional() }) }).optional(),
440
+ why: line,
441
+ }),
442
+ )
443
+ .max(24),
444
+ })
445
+ /** The director's word, between two rounds of a modeller task that did
446
+ * not pass, on how its asset is made: keep the method, or switch to
447
+ * another from the capability list, with why. */
448
+ export const MethodReview = z.object({ action: z.enum(['keep', 'switch']), method: Method.optional(), why: line })
449
+ export const ReportOutput = z.object({ text: z.string().min(1).max(3000), verified: lines(24), assumed: lines(24), notDone: lines(24) })
450
+
451
+ // ---------------------------------------------------------------- 3.7 SessionSpec, RoleDef, SessionInput
452
+
453
+ const Image = z.object({ mime: z.string(), data: z.string() })
454
+ const fn = z.custom((v) => typeof v === 'function', 'a function')
455
+
456
+ export const SessionSpec = z.object({
457
+ kind: z.enum(['role', 'decision']),
458
+ key: z.string().min(1),
459
+ systemPrompt: z.string().min(1),
460
+ userText: z.string(),
461
+ images: z.array(Image),
462
+ builtIns: z.array(z.string()),
463
+ nwTools: z.array(z.string()),
464
+ skills: z.array(z.string()),
465
+ schema: z.record(z.string(), z.unknown()),
466
+ maxTurns: z.number().int().min(1),
467
+ })
468
+
469
+ export const RoleDef = z.looseObject({
470
+ id: RoleId,
471
+ lane: z.enum(LANES),
472
+ prompt: z.string(),
473
+ builtIns: z.array(z.string()),
474
+ nwTools: z.array(z.string()),
475
+ skills: z.array(z.string()),
476
+ mayOwn: z.array(z.string()),
477
+ configKeys: z.array(z.string()).optional(),
478
+ defaultChecks: fn,
479
+ rubric: z.unknown(),
480
+ maxTurns: z.number().int(),
481
+ session: fn,
482
+ catalogue: z.object({ does: z.string(), size: z.string(), checks: z.array(z.string()) }),
483
+ })
484
+
485
+ export const SessionInput = z.object({
486
+ brief: ArtBrief,
487
+ vision: Vision,
488
+ facts: z.unknown().nullable(),
489
+ cameras: z.array(anyObject).nullable(),
490
+ ready: z.array(z.object({ path: z.string(), kind: z.string() })),
491
+ round: z.number().int(),
492
+ roundLimit: z.number().int(),
493
+ previous: z.object({ reports: z.array(z.unknown()), gate: z.unknown().nullable(), restored: z.boolean(), diffStat: z.string() }).nullable(),
494
+ references: z.array(z.string()),
495
+ refImages: z.array(Image),
496
+ declinePaid: z.boolean(),
497
+ locale: z.string(),
498
+ })
499
+
500
+ /**
501
+ * What the gate hands the critic's criticSpec (ROLES, roles/critic.mjs), in
502
+ * the order the critic sees it: the reference, the crops of it for the
503
+ * subjects the criteria name, the shots at the task's cameras, nw_compare's
504
+ * side-by-side and the best attempt so far at the same camera; then the
505
+ * words. `scope` is 'task' for one task's gate and
506
+ * 'final' for the whole-scene critic of the final gate; for a modeller task
507
+ * the shots are its latest contact sheets and `best` the best round's
508
+ * colour sheet, with no metrics.
509
+ */
510
+ export const CriticInput = z.object({
511
+ scope: z.enum(['task', 'final']),
512
+ key: z.string(),
513
+ task: z.object({ id: z.string(), role: z.string(), title: z.string(), goal: z.string(), covers: z.array(z.string()) }),
514
+ round: z.number().int(),
515
+ reference: Image.nullable(),
516
+ shots: z.array(z.object({ camera: z.string(), image: Image })).max(8),
517
+ sideBySide: Image.nullable(),
518
+ best: Image.nullable(),
519
+ brief: z.string(),
520
+ pillars: z.array(z.string()),
521
+ moments: z.array(Moment),
522
+ criteria: z.array(Criterion),
523
+ metrics: CompareMetrics.nullable(),
524
+ flags: z.array(z.string()),
525
+ locale: z.string(),
526
+ /** The reference's crops of the subjects the criteria name, to judge form against. */
527
+ subjects: z.array(z.object({ id: z.string(), what: z.string(), role: z.string(), image: Image })).max(4).optional(),
528
+ /** A modeller task's: the pictures its model was made from (the
529
+ * reference's crop, the views generated for it). */
530
+ inputs: z.array(z.object({ what: z.string(), image: Image })).max(2).optional(),
531
+ /** What the director changed in the brief since the plan wrote the criteria. */
532
+ briefChanges: z.array(z.string()).max(8).optional(),
533
+ })
534
+
535
+ // ---------------------------------------------------------------- 3.9 what the chat is sent
536
+
537
+ const Scores = z.object({ form: num, detail: num, composition: num, colour: num, light: num, overall: num })
538
+ const ModelLine = z.object({ id: z.string(), name: z.string(), usd: num })
539
+ export const BoardView = z.object({
540
+ productionId: z.string(),
541
+ phase: z.enum(PHASES),
542
+ roleWords: z.record(z.string(), z.string()),
543
+ tasks: z.array(
544
+ z.object({
545
+ id: z.string(),
546
+ role: z.string(),
547
+ label: z.string(),
548
+ status: z.string(),
549
+ round: z.number().int(),
550
+ roundLimit: z.number().int(),
551
+ model: z.object({ id: z.string(), name: z.string() }).nullable(),
552
+ effort: z.string().nullable(),
553
+ escalated: z.boolean(),
554
+ image: z.string().nullable(),
555
+ scores: Scores.nullable(),
556
+ pass: z.boolean().nullable(),
557
+ usd: num,
558
+ }),
559
+ ),
560
+ cost: z.object({ usd: num, approvedUsd: num.nullable(), byModel: z.array(ModelLine) }),
561
+ /** The creator's "never above this model", when it is on (4.4). */
562
+ ceiling: z.object({ id: z.string(), name: z.string() }).nullable().optional(),
563
+ /** The director looking at the game itself, outside a task's gate: for a
564
+ * model it puts in at its placement, or for the game without a task's
565
+ * work; tag is the name its pictures are saved under. */
566
+ looking: z.object({ task: z.string(), why: z.enum(['placement', 'without']), placement: z.string().optional(), tag: z.string() }).nullable().optional(),
567
+ at: num,
568
+ })
569
+
570
+ /** The vision card's payload (cards.cjs validates it, the chat draws it). */
571
+ export const VisionCard = z.object({
572
+ concepts: z.array(z.object({ id: z.string(), title: label, pitch: line })).min(2).max(3),
573
+ chosen: z.string(),
574
+ reasons: body,
575
+ pillars: z.array(line).max(6),
576
+ moments: z.array(z.object({ id: z.string(), label, sees: line })).max(6),
577
+ additions: z.array(z.object({ what: line, why: line })).max(6),
578
+ scopeIn: z.array(line).max(6),
579
+ scopeOut: z.array(line).max(6),
580
+ })
581
+ export const VisionAnswer = z.union([
582
+ z.object({ answer: z.literal('approve') }),
583
+ z.object({ answer: z.literal('skip') }),
584
+ z.object({ answer: z.literal('pick'), concept: z.string() }),
585
+ z.object({ answer: z.literal('edit'), text: z.string().min(1).max(500) }),
586
+ ])
587
+
588
+ // ---------------------------------------------------------------- helpers
589
+
590
+ const DROP = new Set(['$schema', 'minLength', 'maxLength', 'minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'pattern', 'format', 'propertyNames', 'default'])
591
+
592
+ /** A zod schema as the structured output's JSON Schema, in the plain subset. */
593
+ export function jsonSchemaOf(schema) {
594
+ const plain = (node) => {
595
+ if (Array.isArray(node)) return node.map(plain)
596
+ if (!node || typeof node !== 'object') return node
597
+ const out = {}
598
+ for (const [key, value] of Object.entries(node)) {
599
+ if (DROP.has(key)) continue
600
+ if (key === 'const') {
601
+ out.enum = [value]
602
+ continue
603
+ }
604
+ out[key] = key === 'properties' ? Object.fromEntries(Object.entries(value).map(([k, v]) => [k, plain(v)])) : plain(value)
605
+ }
606
+ return out
607
+ }
608
+ return plain(z.toJSONSchema(schema))
609
+ }
610
+
611
+ /** The first problems of a failed parse, as one line each. */
612
+ export function issuesOf(error, max = 12) {
613
+ return (error?.issues ?? []).slice(0, max).map((i) => `${i.path.join('.') || 'the answer'}: ${i.message}`)
614
+ }
615
+
616
+ /** A parse that answers { ok, value } or { ok: false, errors }. */
617
+ export function parseWith(schema, value) {
618
+ const r = schema.safeParse(value)
619
+ return r.success ? { ok: true, value: r.data } : { ok: false, errors: issuesOf(r.error) }
620
+ }
621
+
622
+ const fullSchemas = new WeakMap()
623
+ const kindOf = (v) => (v === null ? 'null' : Array.isArray(v) ? 'array' : typeof v === 'number' ? 'number' : typeof v)
624
+
625
+ /**
626
+ * An answer cut to the bounds jsonSchemaOf leaves out of the structured
627
+ * output: every string to its maxLength, every list to its maxItems. A
628
+ * model is never told those lengths, so one long summary or one long fix
629
+ * would otherwise fail a whole attempt that did its work. Nothing else is
630
+ * changed; parseWith still holds every other rule.
631
+ */
632
+ export function fitTo(schema, value) {
633
+ let root = fullSchemas.get(schema)
634
+ if (!root) {
635
+ root = z.toJSONSchema(schema)
636
+ fullSchemas.set(schema, root)
637
+ }
638
+ const fit = (node, v) => {
639
+ if (!node || typeof node !== 'object' || v === undefined) return v
640
+ const options = node.anyOf ?? node.oneOf
641
+ if (options) {
642
+ const kind = kindOf(v)
643
+ const branch = options.find((o) => o.type === kind || (kind === 'number' && o.type === 'integer') || (kind === 'object' && !o.type && o.properties))
644
+ return branch ? fit(branch, v) : v
645
+ }
646
+ if (typeof v === 'string' && Number.isInteger(node.maxLength) && v.length > node.maxLength) {
647
+ const cut = v.slice(0, node.maxLength)
648
+ // Never half a surrogate pair at the end.
649
+ return /[\uD800-\uDBFF]$/.test(cut) ? cut.slice(0, -1) : cut
650
+ }
651
+ if (Array.isArray(v)) {
652
+ const kept = Number.isInteger(node.maxItems) ? v.slice(0, node.maxItems) : v
653
+ return kept.map((x, i) => fit(node.prefixItems?.[i] ?? node.items, x))
654
+ }
655
+ if (kindOf(v) === 'object' && node.properties) {
656
+ const out = { ...v }
657
+ for (const [k, child] of Object.entries(node.properties)) if (k in out) out[k] = fit(child, out[k])
658
+ return out
659
+ }
660
+ return v
661
+ }
662
+ return fit(root, value)
663
+ }