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.
- package/README.md +151 -2
- package/bin/nowhere.mjs +352 -0
- package/lib/account.mjs +57 -0
- package/lib/agentModules.mjs +57 -0
- package/lib/devServer.mjs +351 -0
- package/lib/headless.mjs +231 -0
- package/lib/headlessPreview.mjs +212 -0
- package/lib/keys.mjs +517 -0
- package/lib/make.mjs +855 -0
- package/lib/mcp.mjs +537 -0
- package/lib/open.mjs +22 -0
- package/lib/preview.mjs +87 -0
- package/lib/previewRpc.mjs +134 -0
- package/lib/project.mjs +359 -0
- package/lib/publishFlow.mjs +131 -0
- package/lib/resources.mjs +50 -0
- package/lib/rules.mjs +60 -0
- package/lib/scaffold.mjs +42 -0
- package/lib/setup.mjs +59 -0
- package/lib/tools.mjs +668 -0
- package/package.json +51 -4
- package/template/game.config.json +9 -0
- package/template/scene.json +4 -0
- package/template/src/main.ts +11 -0
- package/vendor/DOCS.md +447 -0
- package/vendor/agent/appRun.mjs +520 -0
- package/vendor/agent/assets/brief.mjs +242 -0
- package/vendor/agent/assets/collider.mjs +531 -0
- package/vendor/agent/assets/environments/index.mjs +12 -0
- package/vendor/agent/assets/environments/worldlabs.mjs +161 -0
- package/vendor/agent/assets/fetch.mjs +168 -0
- package/vendor/agent/assets/footprint.mjs +13 -0
- package/vendor/agent/assets/gltf.mjs +547 -0
- package/vendor/agent/assets/hdr.mjs +269 -0
- package/vendor/agent/assets/imageOps.mjs +171 -0
- package/vendor/agent/assets/images/codex.mjs +307 -0
- package/vendor/agent/assets/images/fal.mjs +75 -0
- package/vendor/agent/assets/images/gemini.mjs +84 -0
- package/vendor/agent/assets/images/index.mjs +25 -0
- package/vendor/agent/assets/images/openai.mjs +75 -0
- package/vendor/agent/assets/images/stability.mjs +71 -0
- package/vendor/agent/assets/images/views.mjs +31 -0
- package/vendor/agent/assets/import.mjs +1352 -0
- package/vendor/agent/assets/inspect.mjs +465 -0
- package/vendor/agent/assets/jobs.mjs +196 -0
- package/vendor/agent/assets/ktx2.mjs +290 -0
- package/vendor/agent/assets/ledger.mjs +466 -0
- package/vendor/agent/assets/net.mjs +254 -0
- package/vendor/agent/assets/prices.json +39 -0
- package/vendor/agent/assets/providers/fal.mjs +115 -0
- package/vendor/agent/assets/providers/index.mjs +22 -0
- package/vendor/agent/assets/providers/meshy.mjs +119 -0
- package/vendor/agent/assets/providers/tripo.mjs +188 -0
- package/vendor/agent/assets/sources/ambientcg.mjs +129 -0
- package/vendor/agent/assets/sources/index.mjs +23 -0
- package/vendor/agent/assets/sources/polyhaven.mjs +237 -0
- package/vendor/agent/assets/sources/polypizza.mjs +121 -0
- package/vendor/agent/assets/splat.mjs +631 -0
- package/vendor/agent/assets/targets.mjs +122 -0
- package/vendor/agent/assets/tile.mjs +261 -0
- package/vendor/agent/assets/unzip.mjs +180 -0
- package/vendor/agent/blender/cleanup.py +360 -0
- package/vendor/agent/blender/convert.py +167 -0
- package/vendor/agent/blender/find.mjs +192 -0
- package/vendor/agent/blender/nw_export.py +104 -0
- package/vendor/agent/blender/nw_rubric.py +426 -0
- package/vendor/agent/blender/run.mjs +193 -0
- package/vendor/agent/blender/runner.py +252 -0
- package/vendor/agent/blender/sheet.py +743 -0
- package/vendor/agent/depth.mjs +134 -0
- package/vendor/agent/director/board.mjs +451 -0
- package/vendor/agent/director/contracts.mjs +663 -0
- package/vendor/agent/director/director.mjs +2365 -0
- package/vendor/agent/director/estimate.mjs +200 -0
- package/vendor/agent/director/gate.mjs +802 -0
- package/vendor/agent/director/limits.json +16 -0
- package/vendor/agent/director/methods.mjs +457 -0
- package/vendor/agent/director/policy.json +33 -0
- package/vendor/agent/director/prompts.mjs +244 -0
- package/vendor/agent/director/reading.mjs +341 -0
- package/vendor/agent/director/router.mjs +184 -0
- package/vendor/agent/director/seams.mjs +243 -0
- package/vendor/agent/director/session.mjs +643 -0
- package/vendor/agent/director/store.mjs +119 -0
- package/vendor/agent/director/taskGate.mjs +110 -0
- package/vendor/agent/director/teamLedger.mjs +118 -0
- package/vendor/agent/director/triage.mjs +63 -0
- package/vendor/agent/downloads.cjs +363 -0
- package/vendor/agent/flow.mjs +78 -0
- package/vendor/agent/guard.mjs +613 -0
- package/vendor/agent/host.mjs +1736 -0
- package/vendor/agent/language.mjs +58 -0
- package/vendor/agent/ledger.mjs +360 -0
- package/vendor/agent/locale.cjs +186 -0
- package/vendor/agent/loop/capacity.mjs +74 -0
- package/vendor/agent/loop/compose.mjs +127 -0
- package/vendor/agent/loop/gate.mjs +205 -0
- package/vendor/agent/loop/judge.mjs +189 -0
- package/vendor/agent/loop/levels.mjs +273 -0
- package/vendor/agent/loop/state.mjs +358 -0
- package/vendor/agent/notes.cjs +278 -0
- package/vendor/agent/pace.mjs +258 -0
- package/vendor/agent/panels.mjs +431 -0
- package/vendor/agent/prompt.mjs +342 -0
- package/vendor/agent/reference/board.mjs +410 -0
- package/vendor/agent/reference/compose.mjs +364 -0
- package/vendor/agent/reference/decode.mjs +56 -0
- package/vendor/agent/reference/facts.mjs +1874 -0
- package/vendor/agent/reference/png.mjs +107 -0
- package/vendor/agent/reference/records.mjs +63 -0
- package/vendor/agent/reference/web.mjs +252 -0
- package/vendor/agent/roles/artist.mjs +69 -0
- package/vendor/agent/roles/builder.mjs +79 -0
- package/vendor/agent/roles/checks.mjs +223 -0
- package/vendor/agent/roles/common.mjs +188 -0
- package/vendor/agent/roles/critic.mjs +171 -0
- package/vendor/agent/roles/index.mjs +39 -0
- package/vendor/agent/roles/modeller.mjs +142 -0
- package/vendor/agent/roles/qa.mjs +58 -0
- package/vendor/agent/roles/rubrics.mjs +79 -0
- package/vendor/agent/roles/sound.mjs +69 -0
- package/vendor/agent/rounds.cjs +333 -0
- package/vendor/agent/shared.mjs +284 -0
- package/vendor/agent/stopGate.mjs +574 -0
- package/vendor/agent/subagents.mjs +129 -0
- package/vendor/agent/tools/assets.mjs +499 -0
- package/vendor/agent/tools/blender.mjs +754 -0
- package/vendor/agent/tools/cards.mjs +479 -0
- package/vendor/agent/tools/choices.mjs +479 -0
- package/vendor/agent/tools/compose.mjs +74 -0
- package/vendor/agent/tools/environment.mjs +488 -0
- package/vendor/agent/tools/eyes.mjs +733 -0
- package/vendor/agent/tools/generate.mjs +338 -0
- package/vendor/agent/tools/guide.mjs +46 -0
- package/vendor/agent/tools/harness.mjs +193 -0
- package/vendor/agent/tools/image.mjs +643 -0
- package/vendor/agent/tools/index.mjs +162 -0
- package/vendor/agent/tools/look.mjs +578 -0
- package/vendor/agent/tools/loop.mjs +858 -0
- package/vendor/agent/tools/others.mjs +123 -0
- package/vendor/agent/tools/pictures.mjs +535 -0
- package/vendor/agent/tools/reference.mjs +366 -0
- package/vendor/agent/transcripts.mjs +118 -0
- package/vendor/agent-loop.mjs +602 -0
- package/vendor/agent-plugin/.claude-plugin/plugin.json +5 -0
- package/vendor/agent-plugin/skills/art-direction/SKILL.md +82 -0
- package/vendor/agent-plugin/skills/asset-legality/SKILL.md +101 -0
- package/vendor/agent-plugin/skills/asset-sources/SKILL.md +111 -0
- package/vendor/agent-plugin/skills/blender-modeling/SKILL.md +97 -0
- package/vendor/agent-plugin/skills/look-dev/SKILL.md +104 -0
- package/vendor/agent-plugin/skills/playtesting/SKILL.md +74 -0
- package/vendor/agent-plugin/skills/reference-loop/SKILL.md +102 -0
- package/vendor/agent-plugin/skills/sound-design/SKILL.md +60 -0
- package/vendor/agent-plugin/skills/style/SKILL.md +35 -0
- package/vendor/agent-plugin/skills/tsl-r185/SKILL.md +107 -0
- package/vendor/auth.cjs +570 -0
- package/vendor/build.cjs +953 -0
- package/vendor/catalog.json +455 -0
- package/vendor/connectors.cjs +688 -0
- package/vendor/eyes.mjs +733 -0
- package/vendor/gameExports.json +1390 -0
- package/vendor/git.cjs +222 -0
- package/vendor/models.json +57 -0
- package/vendor/publish.cjs +1018 -0
- package/vendor/refBoard.cjs +301 -0
- package/vendor/schema/dist/assets.d.ts +335 -0
- package/vendor/schema/dist/assets.js +439 -0
- package/vendor/schema/dist/brief.d.ts +357 -0
- package/vendor/schema/dist/brief.js +302 -0
- package/vendor/schema/dist/common.d.ts +9 -0
- package/vendor/schema/dist/common.js +13 -0
- package/vendor/schema/dist/config.d.ts +406 -0
- package/vendor/schema/dist/config.js +355 -0
- package/vendor/schema/dist/contract.d.ts +599 -0
- package/vendor/schema/dist/contract.js +1146 -0
- package/vendor/schema/dist/index.d.ts +14 -0
- package/vendor/schema/dist/index.js +21 -0
- package/vendor/schema/dist/look.d.ts +463 -0
- package/vendor/schema/dist/look.js +681 -0
- package/vendor/schema/dist/lookStats.d.ts +230 -0
- package/vendor/schema/dist/lookStats.js +768 -0
- package/vendor/schema/dist/pilot.d.ts +32 -0
- package/vendor/schema/dist/pilot.js +44 -0
- package/vendor/schema/dist/publish.d.ts +214 -0
- package/vendor/schema/dist/publish.js +291 -0
- package/vendor/schema/dist/scene.d.ts +75 -0
- package/vendor/schema/dist/scene.js +120 -0
- package/vendor/schema/dist/skyLight.d.ts +141 -0
- package/vendor/schema/dist/skyLight.js +436 -0
- package/vendor/schema/dist/style.d.ts +131 -0
- package/vendor/schema/dist/style.js +155 -0
- package/vendor/schema/package.json +1 -0
- package/vendor/selectionPrompt.mjs +51 -0
- package/vendor/useTools.mjs +195 -0
- package/vendor/userMessage.mjs +26 -0
- package/web-dist/assets/GaussianSplatUtils-CptQkDVX.js +1 -0
- package/web-dist/assets/KTX2Loader-C53LJqss.js +2 -0
- package/web-dist/assets/SPZLoader-BQ3tjaTv.js +1 -0
- package/web-dist/assets/gaussianSplat-_9tcWegB.js +1 -0
- package/web-dist/assets/index-Baka-ZO7.js +693 -0
- package/web-dist/assets/index-CcjyyQco.css +1 -0
- package/web-dist/assets/meshopt_decoder.module-BvwdjiD3.js +1 -0
- package/web-dist/assets/zstddec.module-CfFeQW7d.js +1 -0
- package/web-dist/index.html +34 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$comment": "How far one production may go (orchestrator spec 2.11); proposals for the real-model experiments to tune. maxSessions null: 3 sessions at once on a machine with 16 GB of memory or more, else 2. attemptMinutes: a role session that runs longer is interrupted and the attempt fails. decisionMinutes: one structured answer (a Fable turn can be long). productionMinutes: past it nothing new starts and FINAL runs with what passed. noteReviews: how many times between rounds the director reviews the notes that came to it (a decision each). methodReviews: how many times per modeller task the director reviews how its asset is made, after a round that did not pass (a decision each).",
|
|
3
|
+
"roundsPerTask": 4,
|
|
4
|
+
"attempts": 30,
|
|
5
|
+
"maxSessions": null,
|
|
6
|
+
"attemptMinutes": 25,
|
|
7
|
+
"decisionMinutes": 15,
|
|
8
|
+
"productionMinutes": 120,
|
|
9
|
+
"polishCycles": 1,
|
|
10
|
+
"qaTasks": 3,
|
|
11
|
+
"followUps": 2,
|
|
12
|
+
"maxTasks": 12,
|
|
13
|
+
"criteriaPerTask": 6,
|
|
14
|
+
"noteReviews": 2,
|
|
15
|
+
"methodReviews": 1
|
|
16
|
+
}
|
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
// How each modelled asset is made, decided by the engine per asset (the
|
|
2
|
+
// creator's request after the Haiku post-mortem, and the "switch method"
|
|
3
|
+
// part of its gap 7). Code builds the capability list: what this machine and
|
|
4
|
+
// the creator's settings allow (Blender, the web, each image and
|
|
5
|
+
// image-to-3D provider with its key or consent and its price, paid or not)
|
|
6
|
+
// and how usable the reference's crop of each subject is (its pixels, the
|
|
7
|
+
// lettering and the other subjects over it, how busy its surround is, the
|
|
8
|
+
// frame's edges that cut it). PLAN chooses a method for every modeller task
|
|
9
|
+
// from it, with a reason and a fallback for when the creator refuses what it
|
|
10
|
+
// needs; between rounds of a task that did not pass, the director may switch
|
|
11
|
+
// it. No table here chooses: code only says what can run, prices it, writes
|
|
12
|
+
// the crops a method starts from and checks that the model shows the method
|
|
13
|
+
// it was made by.
|
|
14
|
+
//
|
|
15
|
+
// project a model the project already has (method.file)
|
|
16
|
+
// library a CC0 library's (asset_search, asset_fetch, asset_import)
|
|
17
|
+
// blender a Blender model scripted for it (nw_blender)
|
|
18
|
+
// crop-3d image-to-3D from the reference's crop of a subject
|
|
19
|
+
// image-3d a picture generated for it first (one clean view or several),
|
|
20
|
+
// from the brief and, when it may be sent, the subject's crop;
|
|
21
|
+
// then image-to-3D from that
|
|
22
|
+
//
|
|
23
|
+
// Every model from outside is cleaned up in Blender by asset_import before
|
|
24
|
+
// the gates (blender/cleanup.py).
|
|
25
|
+
|
|
26
|
+
import fs from 'node:fs'
|
|
27
|
+
import fsp from 'node:fs/promises'
|
|
28
|
+
import path from 'node:path'
|
|
29
|
+
import { imageSize } from '../assets/imageOps.mjs'
|
|
30
|
+
import { IMAGE_PROVIDERS } from '../assets/images/index.mjs'
|
|
31
|
+
import { readLedgerState, recordAsset } from '../assets/ledger.mjs'
|
|
32
|
+
import { PRICES, PROVIDERS } from '../assets/providers/index.mjs'
|
|
33
|
+
import { decodeImage } from '../reference/decode.mjs'
|
|
34
|
+
import { cropPicture, fitEdge } from '../reference/facts.mjs'
|
|
35
|
+
import { encodePng } from '../reference/png.mjs'
|
|
36
|
+
import { blockedSourceOf } from '../tools/generate.mjs'
|
|
37
|
+
import { METHOD_IDS } from './contracts.mjs'
|
|
38
|
+
import { inDepth, isBox, toWhole } from './reading.mjs'
|
|
39
|
+
|
|
40
|
+
/** What each method is, in a line, for PLAN and the review. */
|
|
41
|
+
export const METHOD_WORDS = {
|
|
42
|
+
project: 'a model the project already has (file: its path)',
|
|
43
|
+
library: 'a CC0 library model, searched, fetched and imported (Poly Haven, Kenney through Poly Pizza)',
|
|
44
|
+
blender: 'a Blender model scripted in bpy for this asset, rendered and measured every round',
|
|
45
|
+
'crop-3d': "image-to-3D from the reference's crop of the subject (subject, mesh): the model is what the crop shows of it",
|
|
46
|
+
'image-3d': "a picture generated for this asset first (image: the generator; views: 1 for one clean view, 2 to 4 for views of it, front first), from the brief and, when it may be sent, the subject's crop; then image-to-3D from it (mesh)",
|
|
47
|
+
}
|
|
48
|
+
/** What an image-to-3D service needs from a picture (a fact about the services, not a style). */
|
|
49
|
+
export const RECONSTRUCTION =
|
|
50
|
+
'Image-to-3D rebuilds one object from pictures of it: it needs the object whole and alone, nothing in front of it, no lettering, on a plain background, with enough pixels; a single picture shows one side, and the service invents the rest.'
|
|
51
|
+
/** The reference's crop is cut this much wider than the subject's box, each side. */
|
|
52
|
+
const MARGIN = 1 / 16
|
|
53
|
+
/** The longest side of a crop written for a method. */
|
|
54
|
+
const CROP_EDGE = 1024
|
|
55
|
+
/** The longest side the reference is read at to cut a crop from. */
|
|
56
|
+
const SOURCE_EDGE = 4096
|
|
57
|
+
/** A subject's crop under this many pixels on its long side is small for image-to-3D (a measure, said). */
|
|
58
|
+
export const SMALL_CROP = 256
|
|
59
|
+
/** The band round a box, as a share of its size, whose edges say how busy
|
|
60
|
+
* the subject's surround is; and the step in lightness that is an edge. */
|
|
61
|
+
const RING = 0.15
|
|
62
|
+
const EDGE_STEP = 8
|
|
63
|
+
/** Image-to-3D services that take several views. */
|
|
64
|
+
const SEVERAL = new Set(Object.entries(PROVIDERS).filter(([, p]) => p.tasks.includes('multi-image-to-3d')).map(([id]) => id))
|
|
65
|
+
|
|
66
|
+
/** A project-relative path as globs read it (board.mjs relPath, which imports this). */
|
|
67
|
+
const relPath = (p) =>
|
|
68
|
+
String(p ?? '')
|
|
69
|
+
.replace(/\\/g, '/')
|
|
70
|
+
.replace(/^(\.\/)+/, '')
|
|
71
|
+
.replace(/\/+$/, '')
|
|
72
|
+
const r2 = (n) => Math.round(n * 100) / 100
|
|
73
|
+
const r3 = (n) => Math.round(n * 1000) / 1000
|
|
74
|
+
const usd = (n) => `$${Number(n).toFixed(2)}`
|
|
75
|
+
const keyOf = (secret, envVar) => {
|
|
76
|
+
try {
|
|
77
|
+
const v = secret?.(envVar)
|
|
78
|
+
return typeof v === 'string' && v.trim() !== ''
|
|
79
|
+
} catch {
|
|
80
|
+
return false
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ---------------------------------------------------------------- the crops
|
|
85
|
+
|
|
86
|
+
/** How much of box `a` box `b` covers. */
|
|
87
|
+
function overlap(a, b) {
|
|
88
|
+
const w = Math.max(0, Math.min(a[2], b[2]) - Math.max(a[0], b[0]))
|
|
89
|
+
const h = Math.max(0, Math.min(a[3], b[3]) - Math.max(a[1], b[1]))
|
|
90
|
+
const area = (a[2] - a[0]) * (a[3] - a[1])
|
|
91
|
+
return area > 0 ? (w * h) / area : 0
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The part of the picture a subject's crop is cut from: its box (of the
|
|
95
|
+
* whole picture) a sixteenth wider each side, inside the frame. */
|
|
96
|
+
function cropBoxOf([x0, y0, x1, y1]) {
|
|
97
|
+
const mx = MARGIN * (x1 - x0)
|
|
98
|
+
const my = MARGIN * (y1 - y0)
|
|
99
|
+
return [Math.max(0, x0 - mx), Math.max(0, y0 - my), Math.min(1, x1 + mx), Math.min(1, y1 + my)]
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** How much of the band round a box (outside it, inside the frame) is
|
|
103
|
+
* edges, 0 to 1: about 0 for a subject on a plain surround (a horizon
|
|
104
|
+
* crossing it is a line), more among other things. */
|
|
105
|
+
function ringOf(pic, box) {
|
|
106
|
+
const lum = (x, y) => {
|
|
107
|
+
const i = (y * pic.width + x) * 4
|
|
108
|
+
return (0.2126 * pic.data[i] + 0.7152 * pic.data[i + 1] + 0.0722 * pic.data[i + 2]) / 2.55
|
|
109
|
+
}
|
|
110
|
+
const [x0, y0, x1, y1] = [box[0] * pic.width, box[1] * pic.height, box[2] * pic.width, box[3] * pic.height].map(Math.round)
|
|
111
|
+
const bw = Math.max(2, Math.round((x1 - x0) * RING))
|
|
112
|
+
const bh = Math.max(2, Math.round((y1 - y0) * RING))
|
|
113
|
+
let n = 0
|
|
114
|
+
let edges = 0
|
|
115
|
+
for (let y = Math.max(0, y0 - bh); y < Math.min(pic.height - 1, y1 + bh); y++) {
|
|
116
|
+
for (let x = Math.max(0, x0 - bw); x < Math.min(pic.width - 1, x1 + bw); x++) {
|
|
117
|
+
if (x >= x0 && x < x1 && y >= y0 && y < y1) continue
|
|
118
|
+
const l = lum(x, y)
|
|
119
|
+
n++
|
|
120
|
+
if (Math.abs(lum(x + 1, y) - l) + Math.abs(lum(x, y + 1) - l) > EDGE_STEP) edges++
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return n ? r2(edges / n) : null
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* How usable the reference's crop of each subject that stands in the game
|
|
128
|
+
* is, measured: [{ id, what, kind, role, px: [w, h], sent: [w, h], share,
|
|
129
|
+
* text, overlaps: [{ id, share }], cut: [edges], ring }]. px is in the
|
|
130
|
+
* reference's own pixels (`size`, its whole picture as its file has it; the
|
|
131
|
+
* facts' size, of the copy they were measured on, when that is not known);
|
|
132
|
+
* sent the subject's pixels in the crop writeCrop cuts of it, read at most
|
|
133
|
+
* 4096 px on the reference's long side and fitted to 1024; text the share
|
|
134
|
+
* of the box under lettering; overlaps the other subjects over it; cut the
|
|
135
|
+
* frame's edges it runs into; ring how much of what is round it is edges (0
|
|
136
|
+
* plain, higher busier). `pic` is the decoded reference, `crop` the facts'
|
|
137
|
+
* crop of it.
|
|
138
|
+
*/
|
|
139
|
+
export function subjectQuality({ brief, facts, pic = null, crop = null, size = null }) {
|
|
140
|
+
const subjects = (brief?.subjects ?? []).filter((s) => isBox(s.box) && !inDepth(s))
|
|
141
|
+
const letters = (facts?.text?.boxes ?? []).map((b) => b.box).filter(isBox)
|
|
142
|
+
const W = facts?.size?.width ?? pic?.width ?? 0
|
|
143
|
+
const H = facts?.size?.height ?? pic?.height ?? 0
|
|
144
|
+
// The picture a crop is cut from, as writeCrop reads it.
|
|
145
|
+
const source = size ? Math.min(1, SOURCE_EDGE / Math.max(size.width, size.height)) : 1
|
|
146
|
+
return subjects.map((s) => {
|
|
147
|
+
const whole = toWhole(s.box, crop)
|
|
148
|
+
const others = subjects.filter((o) => o.id !== s.id).map((o) => ({ id: o.id, share: r2(overlap(s.box, o.box)) })).filter((o) => o.share >= 0.05)
|
|
149
|
+
const text = letters.length ? r2(Math.min(1, letters.reduce((n, b) => n + overlap(s.box, b), 0))) : 0
|
|
150
|
+
const cut = [whole[0] <= 0.01 && 'left', whole[1] <= 0.01 && 'top', whole[2] >= 0.99 && 'right', whole[3] >= 0.99 && 'bottom'].filter(Boolean)
|
|
151
|
+
const px = size ? [(whole[2] - whole[0]) * size.width, (whole[3] - whole[1]) * size.height] : [(s.box[2] - s.box[0]) * W, (s.box[3] - s.box[1]) * H]
|
|
152
|
+
let fit = 1
|
|
153
|
+
if (size) {
|
|
154
|
+
const c = cropBoxOf(whole)
|
|
155
|
+
fit = source * Math.min(1, CROP_EDGE / (source * Math.max((c[2] - c[0]) * size.width, (c[3] - c[1]) * size.height)))
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
id: s.id,
|
|
159
|
+
what: s.what,
|
|
160
|
+
kind: s.kind,
|
|
161
|
+
role: s.role,
|
|
162
|
+
px: px.map(Math.round),
|
|
163
|
+
sent: px.map((n) => Math.round(n * fit)),
|
|
164
|
+
share: r3((s.box[2] - s.box[0]) * (s.box[3] - s.box[1])),
|
|
165
|
+
text,
|
|
166
|
+
overlaps: others,
|
|
167
|
+
cut,
|
|
168
|
+
ring: pic ? ringOf(pic, whole) : null,
|
|
169
|
+
}
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** A subject's crop quality in words, one line. */
|
|
174
|
+
export function qualityLine(q) {
|
|
175
|
+
const sent = q.sent ?? q.px
|
|
176
|
+
const fitted = sent[0] !== q.px[0] || sent[1] !== q.px[1] ? `, ${sent[0]} x ${sent[1]} in the crop that is sent` : ''
|
|
177
|
+
const bits = [`${q.px[0]} x ${q.px[1]} px of the reference${fitted}${Math.max(...sent) < SMALL_CROP ? ` (under ${SMALL_CROP} on its long side)` : ''}`]
|
|
178
|
+
bits.push(q.text > 0 ? `${Math.round(q.text * 100)}% of it under lettering` : 'no lettering over it')
|
|
179
|
+
bits.push(q.overlaps.length ? `overlapped by ${q.overlaps.map((o) => `${o.id} (${Math.round(o.share * 100)}%)`).join(', ')}` : 'no other subject over it')
|
|
180
|
+
if (q.cut.length) bits.push(`cut by the frame's ${q.cut.join(' and ')} edge${q.cut.length === 1 ? '' : 's'}`)
|
|
181
|
+
if (q.ring !== null) bits.push(`edges over ${Math.round(q.ring * 100)}% of what is round it (0 is a plain surround)`)
|
|
182
|
+
bits.push('seen from one side only')
|
|
183
|
+
return `- ${q.id} (${q.what}; ${q.kind}, ${q.role}${q.role === 'transform' ? ': its crop is never sent, its likeness is the reference\'s' : ''}): ${bits.join('; ')}`
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ---------------------------------------------------------------- what can run
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* The capability list: { methods, image, mesh, subjects, reference }, each
|
|
190
|
+
* method and provider with its state (ready: it runs now; ask: a card asks
|
|
191
|
+
* the creator first, a key or a consent; off: it cannot here) and why, the
|
|
192
|
+
* providers with their prices. Built by code from what is here; PLAN and the
|
|
193
|
+
* review choose from it. `made` says of a project path whether a task of
|
|
194
|
+
* this production makes it.
|
|
195
|
+
*
|
|
196
|
+
* @param {{ projectRoot: string, blender?: object | null, web?: string, declinePaid?: boolean, secret?: Function,
|
|
197
|
+
* codex?: { path?: string, login?: string | null, error?: string } | null, codexState?: string, brief?: object,
|
|
198
|
+
* facts?: object | null, reference?: { rel: string, crop?: number[] | null, image?: object | null } | null, prices?: object,
|
|
199
|
+
* made?: ((rel: string) => boolean) | null }} options
|
|
200
|
+
*/
|
|
201
|
+
export async function capabilitiesOf({ projectRoot, blender = null, web = 'ask', declinePaid = false, secret = null, codex = null, codexState = 'ask', brief = null, facts = null, reference = null, prices = PRICES, made = null }) {
|
|
202
|
+
// The models the project has; those this production's tasks make are not
|
|
203
|
+
// one of them (a task's own model, failing, is no other way to make it).
|
|
204
|
+
const files = []
|
|
205
|
+
const ours = []
|
|
206
|
+
const walk = async (rel) => {
|
|
207
|
+
for (const e of await fsp.readdir(path.join(projectRoot, rel), { withFileTypes: true }).catch(() => [])) {
|
|
208
|
+
const child = `${rel}/${e.name}`
|
|
209
|
+
if (e.isDirectory()) await walk(child)
|
|
210
|
+
else if (/\.(glb|gltf)$/i.test(e.name) && files.length < 40) (made?.(child) ? ours : files).push(child)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
await walk('assets')
|
|
214
|
+
|
|
215
|
+
const paid = (p, envVar, label) => (declinePaid ? { state: 'off', why: 'the creator declined paid generation' } : keyOf(secret, envVar) ? { state: 'ready', why: `${label}'s key is here` } : { state: 'ask', why: `${label}'s key is asked on a key card first` })
|
|
216
|
+
const image = {}
|
|
217
|
+
for (const [id, p] of Object.entries(IMAGE_PROVIDERS)) {
|
|
218
|
+
const model = p.defaultModel({ inputs: 1 })
|
|
219
|
+
const price = p.price(model, { inputs: 1, quality: 'medium' }, prices)
|
|
220
|
+
if (id === 'codex') {
|
|
221
|
+
const state =
|
|
222
|
+
codexState === 'deny'
|
|
223
|
+
? { state: 'off', why: 'the creator did not allow Codex' }
|
|
224
|
+
: !codex || codex.error
|
|
225
|
+
? { state: 'off', why: codex?.error ?? 'Codex was not looked for' }
|
|
226
|
+
: codex.login !== 'chatgpt'
|
|
227
|
+
? { state: 'off', why: codex.login ? 'Codex is logged in with an API key, not the ChatGPT plan' : 'Codex is not logged in' }
|
|
228
|
+
: codexState === 'allow'
|
|
229
|
+
? { state: 'ready', why: 'the creator allowed Codex' }
|
|
230
|
+
: { state: 'ask', why: "the creator's consent is asked on a card first" }
|
|
231
|
+
image[id] = { ...state, model, usd: 0, unit: "the creator's ChatGPT plan, nothing on the cost card" }
|
|
232
|
+
continue
|
|
233
|
+
}
|
|
234
|
+
image[id] = { ...paid(p, p.envVar, p.label), model, usd: price?.high ?? null, unit: price?.unit ?? 'no price' }
|
|
235
|
+
}
|
|
236
|
+
const mesh = {}
|
|
237
|
+
for (const [id, p] of Object.entries(PROVIDERS)) {
|
|
238
|
+
const price = p.price('image-to-3d', p.defaultModel('image-to-3d'), prices)
|
|
239
|
+
mesh[id] = { ...paid(p, p.envVar, p.label), model: p.defaultModel('image-to-3d'), usd: price?.high ?? null, unit: price?.unit ?? 'no price', several: SEVERAL.has(id) }
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// The reference may be cropped and sent only when nothing forbids it.
|
|
243
|
+
// Its own size is its file's (the facts were measured on a smaller copy),
|
|
244
|
+
// turned as the decoded picture is when its header says otherwise.
|
|
245
|
+
let ref = null
|
|
246
|
+
let size = null
|
|
247
|
+
if (reference?.rel) {
|
|
248
|
+
const abs = path.join(projectRoot, reference.rel)
|
|
249
|
+
ref = { rel: reference.rel, crop: reference.crop ?? null, blocked: await blockedSourceOf(projectRoot, reference.rel, abs).catch(() => null) }
|
|
250
|
+
size = imageSize(await fsp.readFile(abs).catch(() => null))
|
|
251
|
+
}
|
|
252
|
+
let pic = null
|
|
253
|
+
if (reference?.image?.data) {
|
|
254
|
+
const d = await decodeImage(Buffer.from(reference.image.data, 'base64'), { mime: reference.image.mime, maxEdge: 768 }).catch(() => null)
|
|
255
|
+
if (d?.ok) pic = d
|
|
256
|
+
}
|
|
257
|
+
const seen = pic ?? facts?.size ?? null
|
|
258
|
+
if (size && seen && size.width !== size.height && (size.width > size.height) !== (seen.width > seen.height)) size = { width: size.height, height: size.width }
|
|
259
|
+
const subjects = subjectQuality({ brief, facts, pic, crop: reference?.crop ?? null, size })
|
|
260
|
+
|
|
261
|
+
// The best of the providers of a kind, and of two things a method needs both of, the worse.
|
|
262
|
+
const best = (list) => (list.some((x) => x.state === 'ready') ? 'ready' : list.some((x) => x.state === 'ask') ? 'ask' : 'off')
|
|
263
|
+
const both = (a, b) => (a === 'off' || b === 'off' ? 'off' : a === 'ask' || b === 'ask' ? 'ask' : 'ready')
|
|
264
|
+
const meshState = best(Object.values(mesh))
|
|
265
|
+
const imageState = best(Object.values(image))
|
|
266
|
+
const cropWhy = !ref ? 'there is no reference picture' : ref.blocked ? `the reference came from ${ref.blocked}, which may never be fed to a model` : !subjects.some((s) => s.role === 'keep') ? 'no subject of the brief stands in the game as kept' : null
|
|
267
|
+
const methods = {
|
|
268
|
+
project: files.length
|
|
269
|
+
? { state: 'ready', why: `the project has ${files.length} model${files.length === 1 ? '' : 's'}${ours.length ? ' besides those this production makes' : ''}`, files, made: ours }
|
|
270
|
+
: { state: 'off', why: ours.length ? 'the project has no model under assets/ but those this production makes' : 'the project has no model under assets/', files, made: ours },
|
|
271
|
+
library: web === 'deny' ? { state: 'off', why: 'the creator has not allowed the web' } : { state: web === 'allow' ? 'ready' : 'ask', why: web === 'allow' ? 'the web is allowed' : 'the web is asked on a card first' },
|
|
272
|
+
blender: blender ? { state: 'ready', why: `Blender ${blender.version ?? ''} is installed`.replace(/ {2}/g, ' ') } : { state: 'ask', why: 'Blender is not installed: a card asks the creator to install it' },
|
|
273
|
+
'crop-3d': cropWhy ? { state: 'off', why: cropWhy } : meshState === 'off' ? { state: 'off', why: 'no image-to-3D provider can run' } : { state: meshState, why: 'image-to-3D from a subject\'s crop of the reference' },
|
|
274
|
+
'image-3d':
|
|
275
|
+
imageState === 'off' || meshState === 'off'
|
|
276
|
+
? { state: 'off', why: imageState === 'off' ? 'no image generator can run' : 'no image-to-3D provider can run' }
|
|
277
|
+
: { state: both(imageState, meshState), why: ref?.blocked ? `a picture generated first, from the brief's words alone (the reference came from ${ref.blocked}, so its crops are never sent), then image-to-3D` : 'a picture generated first, then image-to-3D' },
|
|
278
|
+
}
|
|
279
|
+
return { methods, image, mesh, subjects, reference: ref, declinePaid }
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** The capability list in words, for PLAN and the review. */
|
|
283
|
+
export function capabilityText(caps) {
|
|
284
|
+
const state = (x) => (x.state === 'ready' ? 'ready' : x.state === 'ask' ? 'ready after a card' : 'not here')
|
|
285
|
+
const lines = ['How a modelled asset can be made here (code checks the choice and prices it on the cost card):']
|
|
286
|
+
for (const id of METHOD_IDS) {
|
|
287
|
+
const m = caps.methods[id]
|
|
288
|
+
lines.push(`- ${id}: ${METHOD_WORDS[id]}. ${state(m)}: ${m.why}${id === 'project' && m.files?.length ? ` (${m.files.slice(0, 12).join(', ')})` : ''}.`)
|
|
289
|
+
}
|
|
290
|
+
lines.push('Image generators (image, for image-3d):')
|
|
291
|
+
for (const [id, p] of Object.entries(caps.image)) lines.push(`- ${id}: ${state(p)}: ${p.why}; ${p.model}, ${p.usd === null ? 'no price' : p.usd === 0 ? p.unit : `up to ${usd(p.usd)} a picture (${p.unit})`}.`)
|
|
292
|
+
lines.push('Image-to-3D (mesh, for crop-3d and image-3d):')
|
|
293
|
+
for (const [id, p] of Object.entries(caps.mesh)) lines.push(`- ${id}: ${state(p)}: ${p.why}; ${p.usd === null ? 'no price' : `up to ${usd(p.usd)} a model (${p.unit})`}${p.several ? '; takes 2 to 4 views' : '; one picture'}.`)
|
|
294
|
+
lines.push(RECONSTRUCTION)
|
|
295
|
+
if (caps.subjects.length) {
|
|
296
|
+
lines.push("The reference's crop of each subject that stands in the game, measured:")
|
|
297
|
+
for (const q of caps.subjects) lines.push(qualityLine(q))
|
|
298
|
+
}
|
|
299
|
+
return lines.join('\n')
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// ---------------------------------------------------------------- what is checked
|
|
303
|
+
|
|
304
|
+
/** The asset's GLB a modeller task makes: its literal path, else its asset check's. */
|
|
305
|
+
export function assetOf(task) {
|
|
306
|
+
const owned = (task?.owns ?? []).map(relPath).find((p) => /^assets\/.+\.(glb|gltf)$/i.test(p) && !/[*?[{]/.test(p))
|
|
307
|
+
return owned ?? (task?.accept?.checks ?? []).find((c) => c.kind === 'asset' && c.path)?.path ?? null
|
|
308
|
+
}
|
|
309
|
+
/** The folder under blender/ where a task's crops and pictures go. */
|
|
310
|
+
export const pictureDir = (task) => {
|
|
311
|
+
const glb = assetOf(task)
|
|
312
|
+
return glb ? `blender/${glb.replace(/^assets\//, '').replace(/\.(glb|gltf)$/i, '').replace(/[^A-Za-z0-9._/-]/g, '_')}` : null
|
|
313
|
+
}
|
|
314
|
+
/** Whether a method sends pictures to a service (and so writes some under blender/). */
|
|
315
|
+
export const usesPictures = (m) => m?.how === 'crop-3d' || m?.how === 'image-3d'
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* What stops a method from running for a task, one sentence each; empty
|
|
319
|
+
* when it can (a card it needs is asked before the cost card, and a refusal
|
|
320
|
+
* leaves the task's fallback). `fallback` names it so in the sentences.
|
|
321
|
+
* Without caps only its shape is checked.
|
|
322
|
+
*/
|
|
323
|
+
export function methodErrors(task, m, { caps = null, brief = null, fallback = false } = {}) {
|
|
324
|
+
const errors = []
|
|
325
|
+
const where = `${task.id}'s ${fallback ? 'fallback' : 'method'}`
|
|
326
|
+
if (!m) return errors
|
|
327
|
+
const subject = m.subject ? (brief?.subjects ?? []).find((s) => s.id === m.subject) : null
|
|
328
|
+
if (m.subject && !subject) errors.push(`${where} names the subject "${m.subject}", which the brief does not have.`)
|
|
329
|
+
if (m.how === 'crop-3d') {
|
|
330
|
+
if (!m.subject) errors.push(`${where} is crop-3d: give subject, the brief subject whose crop the model is made from.`)
|
|
331
|
+
if (subject?.role === 'transform') errors.push(`${where} is crop-3d from ${subject.id}, a subject the brief transforms: its crop would copy its likeness. Make it another way (image-3d from the brief's replacement in words, or Blender).`)
|
|
332
|
+
if (subject && inDepth(subject)) errors.push(`${where} is crop-3d from ${subject.id}, which the picture shows in depth (sky, haze, terrain across the frame): there is no one object in its crop to rebuild.`)
|
|
333
|
+
}
|
|
334
|
+
if (usesPictures(m) && !m.mesh) errors.push(`${where} is ${m.how}: give mesh, the image-to-3D provider (${Object.keys(PROVIDERS).join(', ')}).`)
|
|
335
|
+
if (m.how === 'image-3d') {
|
|
336
|
+
if (!m.image) errors.push(`${where} is image-3d: give image, the generator (${Object.keys(IMAGE_PROVIDERS).join(', ')}).`)
|
|
337
|
+
if ((m.views ?? 1) > 1 && m.mesh && !SEVERAL.has(m.mesh)) errors.push(`${where} asks for ${m.views} views, but ${m.mesh} makes a model from one picture (${[...SEVERAL].join(', ') || 'none here'} takes several).`)
|
|
338
|
+
}
|
|
339
|
+
if (m.how === 'project') {
|
|
340
|
+
if (!m.file) errors.push(`${where} is project: give file, the project's model it uses.`)
|
|
341
|
+
else if (caps && (caps.methods.project.made ?? []).includes(relPath(m.file))) errors.push(`${where} names ${m.file}, which this production makes (a task's own model), not a model the project had (${(caps.methods.project.files ?? []).join(', ') || 'it has none'}).`)
|
|
342
|
+
else if (caps && !(caps.methods.project.files ?? []).includes(relPath(m.file))) errors.push(`${where} names ${m.file}, which is not a model of the project (${(caps.methods.project.files ?? []).join(', ') || 'it has none'}).`)
|
|
343
|
+
}
|
|
344
|
+
if (!caps) return errors
|
|
345
|
+
if (usesPictures(m) && m.subject && caps.reference?.blocked) errors.push(`${where} starts from the crop of ${m.subject}, but the reference came from ${caps.reference.blocked}, whose pictures are never fed to a model: leave subject out (image-3d from the brief's words) or make it another way.`)
|
|
346
|
+
const at = caps.methods[m.how]
|
|
347
|
+
if (at?.state === 'off') errors.push(`${where} is ${m.how}, which cannot run here: ${at.why}.`)
|
|
348
|
+
if (m.image && caps.image[m.image]?.state === 'off') errors.push(`${where} makes its picture with ${m.image}, which cannot run here: ${caps.image[m.image].why}.`)
|
|
349
|
+
if (m.mesh && caps.mesh[m.mesh]?.state === 'off') errors.push(`${where} makes its model with ${m.mesh}, which cannot run here: ${caps.mesh[m.mesh].why}.`)
|
|
350
|
+
return errors
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/** What a method needs a card for, in order: [{ kind: 'key', provider } | { kind: 'codex' } | { kind: 'blender' } | { kind: 'web' }]. */
|
|
354
|
+
export function cardsFor(m, caps) {
|
|
355
|
+
if (!m || !caps) return []
|
|
356
|
+
const out = []
|
|
357
|
+
if (m.how === 'blender' && caps.methods.blender.state === 'ask') out.push({ kind: 'blender' })
|
|
358
|
+
if (m.how === 'library' && caps.methods.library.state === 'ask') out.push({ kind: 'web' })
|
|
359
|
+
if (m.image && caps.image[m.image]?.state === 'ask') out.push(m.image === 'codex' ? { kind: 'codex' } : { kind: 'key', provider: IMAGE_PROVIDERS[m.image] })
|
|
360
|
+
if (m.mesh && caps.mesh[m.mesh]?.state === 'ask') out.push({ kind: 'key', provider: PROVIDERS[m.mesh] })
|
|
361
|
+
return out
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* The estimate requests a method's spending is priced with, through the
|
|
366
|
+
* tools' own estimates (nothing is sent): [{ tool, provider, request }].
|
|
367
|
+
*/
|
|
368
|
+
export function methodRequests(task, m) {
|
|
369
|
+
if (!usesPictures(m)) return []
|
|
370
|
+
const out = []
|
|
371
|
+
const views = m.how === 'image-3d' ? (m.views ?? 1) : 1
|
|
372
|
+
if (m.how === 'image-3d') out.push({ tool: 'image_generate', provider: m.image, request: { action: 'estimate', provider: m.image, prompt: `${task.title}`.slice(0, 200), views, ...(m.subject ? { from: ['crop.png'] } : {}) } })
|
|
373
|
+
const several = views > 1
|
|
374
|
+
out.push({ tool: 'asset_generate', provider: m.mesh, request: { action: 'estimate', provider: m.mesh, task: several ? 'multi-image-to-3d' : 'image-to-3d', ...(several ? { images: Array.from({ length: views }, (_, k) => `view-${k + 1}.png`) } : { image: 'view.png' }) } })
|
|
375
|
+
return out
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** A method as one line. */
|
|
379
|
+
export function methodLine(m) {
|
|
380
|
+
if (!m) return 'none'
|
|
381
|
+
const bits = [m.how, m.subject && `from ${m.subject}`, m.image && `picture by ${m.image}${(m.views ?? 1) > 1 ? `, ${m.views} views` : ''}`, m.mesh && `model by ${m.mesh}`, m.file && m.file].filter(Boolean)
|
|
382
|
+
return `${bits.join(', ')} (${m.why})`
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// ---------------------------------------------------------------- the crops a method starts from
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* The reference's crop of a subject, written for a method at
|
|
389
|
+
* <dir>/<subject>-crop.png (a sixteenth wider than its box each side, at most
|
|
390
|
+
* 1024 px), and recorded in the ledger as the creator's picture cut down:
|
|
391
|
+
* its subject, box, role and the reference it is of. Answers { rel, width,
|
|
392
|
+
* height } or { error }. A crop already there for the same box is kept.
|
|
393
|
+
*/
|
|
394
|
+
export async function writeCrop({ projectRoot, reference, subject, dir }) {
|
|
395
|
+
if (!reference?.rel || !subject || !isBox(subject.box)) return { error: 'there is no reference or no subject box to cut' }
|
|
396
|
+
if (subject.role === 'transform') return { error: `${subject.id} is a subject to transform: its crop is never made` }
|
|
397
|
+
const rel = `${dir}/${subject.id}-crop.png`
|
|
398
|
+
const abs = path.join(projectRoot, ...rel.split('/'))
|
|
399
|
+
const { lock } = await readLedgerState(projectRoot)
|
|
400
|
+
const had = lock.files[rel]
|
|
401
|
+
if (had && fs.existsSync(abs) && JSON.stringify(had.meta?.box) === JSON.stringify(subject.box) && had.meta?.of === reference.rel) return { rel, width: had.meta.width, height: had.meta.height, kept: true }
|
|
402
|
+
let bytes
|
|
403
|
+
try {
|
|
404
|
+
bytes = await fsp.readFile(path.join(projectRoot, reference.rel))
|
|
405
|
+
} catch {
|
|
406
|
+
return { error: `the reference ${reference.rel} is not there` }
|
|
407
|
+
}
|
|
408
|
+
const pic = await decodeImage(bytes, { mime: /\.png$/i.test(reference.rel) ? 'image/png' : /\.webp$/i.test(reference.rel) ? 'image/webp' : 'image/jpeg', maxEdge: SOURCE_EDGE })
|
|
409
|
+
if (!pic.ok) return { error: pic.error }
|
|
410
|
+
const cut = fitEdge(cropPicture(pic, cropBoxOf(toWhole(subject.box, reference.crop ?? null))), CROP_EDGE)
|
|
411
|
+
await fsp.mkdir(path.dirname(abs), { recursive: true })
|
|
412
|
+
const temp = `${abs}.${process.pid}.part`
|
|
413
|
+
await fsp.writeFile(temp, encodePng(cut))
|
|
414
|
+
await fsp.rename(temp, abs)
|
|
415
|
+
const refEntry = lock.files[reference.rel] ?? null
|
|
416
|
+
const r = await recordAsset(projectRoot, rel, {
|
|
417
|
+
kind: 'image',
|
|
418
|
+
origin: 'creator',
|
|
419
|
+
license: refEntry?.license ? { ...refEntry.license } : { spdx: 'LicenseRef-Creator-Declared' },
|
|
420
|
+
source: { provider: 'reference', title: `${subject.what} (cut from ${reference.rel})`.slice(0, 200) },
|
|
421
|
+
steps: [{ op: 'crop', at: new Date().toISOString(), detail: `${subject.id}'s box ${JSON.stringify(subject.box)} of ${reference.rel}, a sixteenth wider each side, ${cut.width}x${cut.height}` }],
|
|
422
|
+
publish: false,
|
|
423
|
+
meta: { subject: subject.id, box: subject.box, role: subject.role, of: reference.rel, width: cut.width, height: cut.height },
|
|
424
|
+
})
|
|
425
|
+
return r.ok ? { rel, width: cut.width, height: cut.height } : { error: r.error }
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// ---------------------------------------------------------------- what the model shows
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Whether a model's ledger entry shows the method its task chose: made in
|
|
432
|
+
* Blender, fetched from a library, generated from the subject's crop or
|
|
433
|
+
* from pictures the named generator made, or the project's own file. A
|
|
434
|
+
* sentence when it does not, else null.
|
|
435
|
+
*/
|
|
436
|
+
export function methodProblem(m, rel, entry, lock) {
|
|
437
|
+
if (!m || !entry) return null
|
|
438
|
+
const inputs = Array.isArray(entry.meta?.provenance?.inputs) ? entry.meta.provenance.inputs : []
|
|
439
|
+
const origin = entry.origin
|
|
440
|
+
const was = origin === 'made' ? 'made in Blender' : origin === 'download' ? `fetched from ${entry.source?.provider ?? 'the web'}` : origin === 'generated' ? `generated by ${entry.generation?.vendor ?? 'a service'}${inputs.length ? ` from ${inputs.map((i) => i.path).join(', ')}` : ''}` : `the creator's (${origin})`
|
|
441
|
+
const off = (want) => `${rel} was ${was}, not ${want}, the way its task makes it (${m.how}): make it that way, or report why it cannot be`
|
|
442
|
+
if (m.how === 'blender' && origin !== 'made') return off('made in Blender with nw_blender')
|
|
443
|
+
if (m.how === 'library' && origin !== 'download') return off('fetched from a CC0 library with asset_fetch and asset_import')
|
|
444
|
+
if (m.how === 'project' && m.file && relPath(m.file) !== rel && !(entry.derivedFrom ?? []).includes(relPath(m.file))) return off(`${m.file}, the project's model`)
|
|
445
|
+
if (m.how === 'crop-3d') {
|
|
446
|
+
if (origin !== 'generated') return off(`generated by ${m.mesh ?? 'image-to-3D'} from the crop of ${m.subject}`)
|
|
447
|
+
if (m.mesh && entry.generation?.vendor !== m.mesh) return off(`generated by ${m.mesh}`)
|
|
448
|
+
if (!inputs.some((i) => i.subject === m.subject || lock?.files?.[i.path]?.meta?.subject === m.subject)) return off(`made from the reference's crop of ${m.subject}`)
|
|
449
|
+
}
|
|
450
|
+
if (m.how === 'image-3d') {
|
|
451
|
+
if (origin !== 'generated') return off(`generated by ${m.mesh ?? 'image-to-3D'} from pictures ${m.image ?? 'an image generator'} made for it`)
|
|
452
|
+
if (m.mesh && entry.generation?.vendor !== m.mesh) return off(`generated by ${m.mesh}`)
|
|
453
|
+
const made = inputs.filter((i) => (i.vendor ?? lock?.files?.[i.path]?.generation?.vendor) === m.image)
|
|
454
|
+
if (!made.length) return off(`made from pictures ${m.image} made for it with image_generate`)
|
|
455
|
+
}
|
|
456
|
+
return null
|
|
457
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$comment": "Which model and effort each part of a production runs on (director/router.mjs reads it; orchestrator spec 4). rungs: the ladder a build task climbs, cheapest first; a failed attempt without measured progress climbs one rung, effort before model. tiers: where a task the board marks small, mid or top starts. decisions: the phases that are one structured answer, with `max` for a request at max depth and `stuck` for a critic whose calls flip or stall; readback (the brief checked against its picture), notes (the director's notes between rounds) and method (how a modelled asset is made, reviewed after a round that did not pass) are narrow verifiers, so they run at medium effort. rules: the start and climb rules. Every number is a proposal for the real-model experiments to tune; every model id must be in models.json.",
|
|
3
|
+
"rungs": [
|
|
4
|
+
{ "model": "claude-haiku-5-5", "effort": "medium", "tier": "small" },
|
|
5
|
+
{ "model": "claude-haiku-5-5", "effort": "high", "tier": "small" },
|
|
6
|
+
{ "model": "claude-sonnet-5-5", "effort": "high", "tier": "mid" },
|
|
7
|
+
{ "model": "claude-opus-5-5", "effort": "high", "tier": "top" },
|
|
8
|
+
{ "model": "claude-opus-5-5", "effort": "xhigh", "tier": "top" },
|
|
9
|
+
{ "model": "claude-fable-5-2", "effort": "high", "tier": "top" }
|
|
10
|
+
],
|
|
11
|
+
"tiers": { "small": 0, "mid": 2, "top": 3 },
|
|
12
|
+
"decisions": {
|
|
13
|
+
"triage": { "model": "claude-haiku-5-5", "effort": "low" },
|
|
14
|
+
"interpret": { "model": "claude-opus-5-5", "effort": "high", "max": { "model": "claude-fable-5-2", "effort": "high" } },
|
|
15
|
+
"readback": { "model": "claude-opus-5-5", "effort": "medium" },
|
|
16
|
+
"vision": { "model": "claude-opus-5-5", "effort": "high", "max": { "model": "claude-fable-5-2", "effort": "high" } },
|
|
17
|
+
"plan": { "model": "claude-opus-5-5", "effort": "high", "max": { "model": "claude-fable-5-2", "effort": "high" } },
|
|
18
|
+
"critic": { "model": "claude-opus-5-5", "effort": "high", "stuck": { "model": "claude-fable-5-2", "effort": "high" } },
|
|
19
|
+
"notes": { "model": "claude-opus-5-5", "effort": "medium" },
|
|
20
|
+
"method": { "model": "claude-opus-5-5", "effort": "medium" },
|
|
21
|
+
"report": { "model": "claude-haiku-5-5", "effort": "low" }
|
|
22
|
+
},
|
|
23
|
+
"rules": {
|
|
24
|
+
"smallNeedsChecks": 2,
|
|
25
|
+
"goalKinds": ["view", "compare", "play", "eval", "asset", "audio", "module"],
|
|
26
|
+
"integrationAtLeast": "mid",
|
|
27
|
+
"qaAtLeast": "mid",
|
|
28
|
+
"sameRungWhileBetter": 2,
|
|
29
|
+
"resumeUnderTokens": 100000,
|
|
30
|
+
"stagnantDistance": 0.02,
|
|
31
|
+
"stuckDistance": 0.05
|
|
32
|
+
}
|
|
33
|
+
}
|