@koda-sl/baker-cli 0.533.0 → 0.534.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.
- package/README.md +1 -1
- package/dist/{canvas-G4QXNPPE.js → canvas-U7MZXZKR.js} +11 -11
- package/dist/{catalog-PTVQSATT.js → catalog-FLWVVX2U.js} +3 -2
- package/dist/{catalog-PTVQSATT.js.map → catalog-FLWVVX2U.js.map} +1 -1
- package/dist/{chunk-PE4ZP7MX.js → chunk-I3LRC33M.js} +520 -3963
- package/dist/chunk-I3LRC33M.js.map +1 -0
- package/dist/chunk-MIRPLAFD.js +1902 -0
- package/dist/chunk-MIRPLAFD.js.map +1 -0
- package/dist/chunk-NZUMNTAT.js +3510 -0
- package/dist/chunk-NZUMNTAT.js.map +1 -0
- package/dist/{chunk-JARRF5VX.js → chunk-PV2JVXFM.js} +2 -2
- package/dist/{chunk-N6WHUUFH.js → chunk-R6WEPF63.js} +2 -2
- package/dist/{chunk-NA5Q473J.js → chunk-RQB4XLSF.js} +90 -1749
- package/dist/chunk-RQB4XLSF.js.map +1 -0
- package/dist/{chunk-DJTWY7GL.js → chunk-T33M3PK7.js} +6 -18
- package/dist/chunk-T33M3PK7.js.map +1 -0
- package/dist/{chunk-VV6FDIP5.js → chunk-TNKKK7XD.js} +2 -2
- package/dist/{chunk-7GGLZOQN.js → chunk-TNOOWNN7.js} +2 -2
- package/dist/{chunk-SEYCF446.js → chunk-UAB4CYBH.js} +3 -3
- package/dist/cli.js +2 -2
- package/dist/{creatives-ADH6HCCA.js → creatives-NTAKM5TG.js} +5 -5
- package/dist/engine/index.js +2 -1
- package/dist/{feedback-MORAVN52.js → feedback-I5FZZAJR.js} +8 -4
- package/dist/{feedback-MORAVN52.js.map → feedback-I5FZZAJR.js.map} +1 -1
- package/dist/{feedback-record-M3RB7H2C.js → feedback-record-U2O24ITU.js} +8 -4
- package/dist/{feedback-record-M3RB7H2C.js.map → feedback-record-U2O24ITU.js.map} +1 -1
- package/dist/{make-7CIVNW77.js → make-JPXGF44U.js} +6 -5
- package/dist/{make-7CIVNW77.js.map → make-JPXGF44U.js.map} +1 -1
- package/dist/{rerun-ON6YCJAL.js → rerun-HCGLAUYW.js} +8 -7
- package/dist/{rerun-ON6YCJAL.js.map → rerun-HCGLAUYW.js.map} +1 -1
- package/dist/{run-YORKHK6S.js → run-2CSG6NIY.js} +8 -7
- package/dist/{scaffold-ad-RHSHBCVV.js → scaffold-ad-AQK4PX7C.js} +4 -3
- package/dist/{scaffold-ad-RHSHBCVV.js.map → scaffold-ad-AQK4PX7C.js.map} +1 -1
- package/dist/{scaffold-static-ad-XNOGCMPF.js → scaffold-static-ad-ORMMKUWY.js} +9 -8
- package/dist/{scaffold-static-ad-XNOGCMPF.js.map → scaffold-static-ad-ORMMKUWY.js.map} +1 -1
- package/dist/{scaffold-video-XEVJQ7QZ.js → scaffold-video-525OYZYI.js} +4 -3
- package/dist/{scaffold-video-XEVJQ7QZ.js.map → scaffold-video-525OYZYI.js.map} +1 -1
- package/dist/{select-BXBNFGVL.js → select-XAC7G4ZT.js} +7 -3
- package/dist/{select-BXBNFGVL.js.map → select-XAC7G4ZT.js.map} +1 -1
- package/dist/{set-prompt-JJWBB23C.js → set-prompt-H3UEDJWS.js} +3 -2
- package/dist/{set-prompt-JJWBB23C.js.map → set-prompt-H3UEDJWS.js.map} +1 -1
- package/dist/stale-TPLB2P4E.js +90 -0
- package/dist/stale-TPLB2P4E.js.map +1 -0
- package/dist/{sync-definition-7NBT6LTK.js → sync-definition-K5TJORL5.js} +4 -3
- package/dist/{translate-VMQHPX4B.js → translate-R2DXDXUY.js} +8 -5
- package/dist/{translate-VMQHPX4B.js.map → translate-R2DXDXUY.js.map} +1 -1
- package/dist/{validate-NB6PS5PF.js → validate-FGETFHYN.js} +7 -4
- package/dist/{validate-NB6PS5PF.js.map → validate-FGETFHYN.js.map} +1 -1
- package/package.json +1 -1
- package/dist/chunk-DJTWY7GL.js.map +0 -1
- package/dist/chunk-NA5Q473J.js.map +0 -1
- package/dist/chunk-OPUEQSKM.js +0 -122
- package/dist/chunk-OPUEQSKM.js.map +0 -1
- package/dist/chunk-PE4ZP7MX.js.map +0 -1
- package/dist/stale-SK2SDGOT.js +0 -76
- package/dist/stale-SK2SDGOT.js.map +0 -1
- /package/dist/{canvas-G4QXNPPE.js.map → canvas-U7MZXZKR.js.map} +0 -0
- /package/dist/{chunk-JARRF5VX.js.map → chunk-PV2JVXFM.js.map} +0 -0
- /package/dist/{chunk-N6WHUUFH.js.map → chunk-R6WEPF63.js.map} +0 -0
- /package/dist/{chunk-VV6FDIP5.js.map → chunk-TNKKK7XD.js.map} +0 -0
- /package/dist/{chunk-7GGLZOQN.js.map → chunk-TNOOWNN7.js.map} +0 -0
- /package/dist/{chunk-SEYCF446.js.map → chunk-UAB4CYBH.js.map} +0 -0
- /package/dist/{creatives-ADH6HCCA.js.map → creatives-NTAKM5TG.js.map} +0 -0
- /package/dist/{run-YORKHK6S.js.map → run-2CSG6NIY.js.map} +0 -0
- /package/dist/{sync-definition-7NBT6LTK.js.map → sync-definition-K5TJORL5.js.map} +0 -0
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
outputRatioWarningsFor,
|
|
6
6
|
shownBaseline,
|
|
7
7
|
shownVersion
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-UAB4CYBH.js";
|
|
9
9
|
import {
|
|
10
10
|
waitForSheet
|
|
11
11
|
} from "./chunk-WN4KX7GE.js";
|
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
correctedPicture,
|
|
20
20
|
growFromVersion,
|
|
21
21
|
ingestedNow,
|
|
22
|
-
isStaticAdCanvas,
|
|
23
22
|
keepsChosen,
|
|
24
23
|
madeThisRun,
|
|
25
24
|
makesSameVariants,
|
|
@@ -36,7 +35,45 @@ import {
|
|
|
36
35
|
variantImage,
|
|
37
36
|
versionRun,
|
|
38
37
|
writeSeriesMemberCanvas
|
|
39
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-T33M3PK7.js";
|
|
39
|
+
import {
|
|
40
|
+
AUTO_FIX_ROUNDS,
|
|
41
|
+
autoFixStep,
|
|
42
|
+
clearLegacyDirtyMarker,
|
|
43
|
+
correctFrom,
|
|
44
|
+
fixMemoryOf,
|
|
45
|
+
formatOfSizeNode,
|
|
46
|
+
frameChanges,
|
|
47
|
+
isStaticAdCanvas,
|
|
48
|
+
lostVital,
|
|
49
|
+
oneSizeFix,
|
|
50
|
+
paidFor,
|
|
51
|
+
peopleReader,
|
|
52
|
+
persistingDefects,
|
|
53
|
+
pictureEdit,
|
|
54
|
+
placedTooFar,
|
|
55
|
+
plainRunEdit,
|
|
56
|
+
prefilterSpend,
|
|
57
|
+
readRenderState,
|
|
58
|
+
recordRenderAttempt,
|
|
59
|
+
recordRendered,
|
|
60
|
+
recordReviewOutcome,
|
|
61
|
+
recordSeriesLeadRun,
|
|
62
|
+
recordSnapshot,
|
|
63
|
+
rendersNewPicture,
|
|
64
|
+
repeatsFailedFix,
|
|
65
|
+
reviewStaticRun,
|
|
66
|
+
runCostHint,
|
|
67
|
+
sizeShapeOf,
|
|
68
|
+
specEditInstruction,
|
|
69
|
+
staticReviewTargets,
|
|
70
|
+
stopsWithoutRepair,
|
|
71
|
+
withDeliveredSizes,
|
|
72
|
+
withExtendedSizes,
|
|
73
|
+
withRelayEdit,
|
|
74
|
+
withRelayNote,
|
|
75
|
+
withSizesFollowingFix
|
|
76
|
+
} from "./chunk-MIRPLAFD.js";
|
|
40
77
|
import {
|
|
41
78
|
buildFailedRunRecord,
|
|
42
79
|
buildInitialRunRecord,
|
|
@@ -48,20 +85,7 @@ import {
|
|
|
48
85
|
withFacts
|
|
49
86
|
} from "./chunk-YE4RCEEJ.js";
|
|
50
87
|
import {
|
|
51
|
-
clearLegacyDirtyMarker,
|
|
52
|
-
readRenderState,
|
|
53
|
-
recordRenderAttempt,
|
|
54
|
-
recordRendered,
|
|
55
|
-
recordReviewOutcome,
|
|
56
|
-
recordSeriesLeadRun,
|
|
57
|
-
recordSnapshot
|
|
58
|
-
} from "./chunk-OPUEQSKM.js";
|
|
59
|
-
import {
|
|
60
|
-
BRAND_LOGO_ROLE,
|
|
61
|
-
CLAIMS_MODEL,
|
|
62
|
-
CLAIMS_REQUEST,
|
|
63
88
|
CanvasPrepareError,
|
|
64
|
-
PEOPLE_PROMPT_VERSION,
|
|
65
89
|
REBUILD_FILE,
|
|
66
90
|
anchorLines,
|
|
67
91
|
castHandles,
|
|
@@ -71,35 +95,25 @@ import {
|
|
|
71
95
|
fixStaticAd,
|
|
72
96
|
formatOfAdaptId,
|
|
73
97
|
isNativeCanvas,
|
|
74
|
-
isWordsObject,
|
|
75
98
|
listSceneFiles,
|
|
76
|
-
peoplePrompt,
|
|
77
|
-
plannedPlacements,
|
|
78
99
|
prepareCanvas,
|
|
79
100
|
readIdeaAnchor,
|
|
80
|
-
readPeople,
|
|
81
101
|
readStaticBrandKit,
|
|
82
102
|
readStaticPromptJson,
|
|
83
103
|
rederiveFromVariant,
|
|
84
104
|
seriesOf,
|
|
85
|
-
uncastPeople,
|
|
86
105
|
wireNamedPeople,
|
|
87
106
|
wireProofBadges
|
|
88
107
|
} from "./chunk-3OSBCYKA.js";
|
|
89
108
|
import {
|
|
90
|
-
ViewerAnswerSchema,
|
|
91
|
-
describeViewer,
|
|
92
109
|
gatewayViewerModel,
|
|
93
110
|
jevReadJudge,
|
|
94
|
-
judgeViewerAnswer,
|
|
95
111
|
liveViewerLookups,
|
|
96
112
|
mayBeCorrection,
|
|
97
|
-
misreadings,
|
|
98
113
|
readTurnRenders,
|
|
99
114
|
recordTurnRender,
|
|
100
115
|
recordViewerFail,
|
|
101
116
|
roundFitsTurn,
|
|
102
|
-
sureEnough,
|
|
103
117
|
turnRenderRefusal,
|
|
104
118
|
updateTurnRenders,
|
|
105
119
|
viewerCheckBeforeRender,
|
|
@@ -114,11 +128,9 @@ import {
|
|
|
114
128
|
writeAvatars
|
|
115
129
|
} from "./chunk-ZOH672S6.js";
|
|
116
130
|
import {
|
|
117
|
-
readCaseFile
|
|
118
|
-
readCompanyReading
|
|
131
|
+
readCaseFile
|
|
119
132
|
} from "./chunk-UFUYTWEF.js";
|
|
120
133
|
import {
|
|
121
|
-
frontmatterOf,
|
|
122
134
|
ruleTells
|
|
123
135
|
} from "./chunk-DWW5QSUF.js";
|
|
124
136
|
import {
|
|
@@ -134,58 +146,22 @@ import {
|
|
|
134
146
|
localPathParam
|
|
135
147
|
} from "./chunk-R5LRBDEM.js";
|
|
136
148
|
import {
|
|
137
|
-
LogoFacts,
|
|
138
|
-
MISALIGNED,
|
|
139
149
|
ValidationError,
|
|
140
|
-
compareSizes,
|
|
141
150
|
createEngineFromEnv,
|
|
142
151
|
resolveConcurrency,
|
|
143
|
-
sizeDifferenceFinding,
|
|
144
152
|
ulid
|
|
145
|
-
} from "./chunk-
|
|
153
|
+
} from "./chunk-I3LRC33M.js";
|
|
146
154
|
import {
|
|
147
155
|
BackendClient,
|
|
148
|
-
LOGO_COMPOSITE_ROLE,
|
|
149
|
-
SERIES_LEAD_ROLE,
|
|
150
156
|
STATIC_ADAPT_FORMAT_ROLE,
|
|
151
|
-
STATIC_ADAPT_ROLE,
|
|
152
|
-
STATIC_FIX_ROLE,
|
|
153
|
-
STATIC_FORMAT_ROLE,
|
|
154
|
-
STATIC_LEAD_ROLE,
|
|
155
|
-
STATIC_MASTER_ROLE,
|
|
156
|
-
STATIC_PICK_ROLE,
|
|
157
|
-
STATIC_PLACE_ROLE,
|
|
158
|
-
STATIC_PLATE_ROLE,
|
|
159
|
-
STATIC_SAFE_FIT_ROLE,
|
|
160
|
-
STATIC_SIZE_ROLE,
|
|
161
|
-
STATIC_VARIANTS_ROLE,
|
|
162
|
-
STATIC_VARIANT_CALL_ROLE,
|
|
163
|
-
VARIANT_PREFILTER_ROLE,
|
|
164
|
-
adaptPlan,
|
|
165
157
|
castsNobody,
|
|
166
|
-
deliveredSize,
|
|
167
|
-
fitArtwork,
|
|
168
|
-
formatSlug,
|
|
169
158
|
isPlateCanvas,
|
|
170
|
-
logoArtwork,
|
|
171
|
-
logoCornerWords,
|
|
172
159
|
nodesWithRole,
|
|
173
|
-
placementProblems,
|
|
174
160
|
regenerateTargets,
|
|
175
|
-
rolesById
|
|
176
|
-
slotPosition,
|
|
177
|
-
staticMasterFormat,
|
|
178
|
-
textColourSource,
|
|
179
|
-
usesTextColour
|
|
161
|
+
rolesById
|
|
180
162
|
} from "./chunk-4Y7IJ2PU.js";
|
|
181
163
|
import {
|
|
182
|
-
bytesOf
|
|
183
|
-
judgeWinner,
|
|
184
|
-
nearIdenticalFindings,
|
|
185
|
-
parseJudgeScores,
|
|
186
|
-
reviewRenderedStatic,
|
|
187
|
-
samePictureSizes,
|
|
188
|
-
staticVerdict
|
|
164
|
+
bytesOf
|
|
189
165
|
} from "./chunk-3WTCMBDC.js";
|
|
190
166
|
import {
|
|
191
167
|
reviewAgainstRules
|
|
@@ -193,23 +169,17 @@ import {
|
|
|
193
169
|
import {
|
|
194
170
|
AdSpecSchema,
|
|
195
171
|
adSpecJsonSchema,
|
|
196
|
-
conceptSummary,
|
|
197
172
|
decisionOf,
|
|
198
173
|
isAdSpec,
|
|
199
174
|
isMemeTemplate,
|
|
200
175
|
isVital,
|
|
201
176
|
jevCitationJudge,
|
|
202
|
-
|
|
203
|
-
nativeCopy,
|
|
204
|
-
nativeSurfaceName,
|
|
205
|
-
readAdSpec,
|
|
206
|
-
readInterfaceWords
|
|
177
|
+
nativeCopy
|
|
207
178
|
} from "./chunk-RRC7F3QQ.js";
|
|
208
179
|
import {
|
|
209
180
|
RENDER_REVIEW_MODEL,
|
|
210
181
|
RENDER_REVIEW_UNAVAILABLE,
|
|
211
182
|
askAboutImages,
|
|
212
|
-
askAboutText,
|
|
213
183
|
reviewContextBeside,
|
|
214
184
|
reviewRenderedVideo,
|
|
215
185
|
rulesDigest,
|
|
@@ -217,13 +187,8 @@ import {
|
|
|
217
187
|
videoPathFromOutput
|
|
218
188
|
} from "./chunk-KITVYLEX.js";
|
|
219
189
|
import {
|
|
220
|
-
|
|
221
|
-
VIEWER_CHECK_MODEL,
|
|
222
|
-
nearestSupportedAspectRatio
|
|
190
|
+
VIEWER_CHECK_MODEL
|
|
223
191
|
} from "./chunk-MCJ5I5LR.js";
|
|
224
|
-
import {
|
|
225
|
-
describeMarket
|
|
226
|
-
} from "./chunk-2WZI36D3.js";
|
|
227
192
|
import {
|
|
228
193
|
LayerExecutionError,
|
|
229
194
|
RunAbortedError,
|
|
@@ -238,8 +203,8 @@ import {
|
|
|
238
203
|
} from "./chunk-VPF5A7CM.js";
|
|
239
204
|
|
|
240
205
|
// src/commands/canvas/run.ts
|
|
241
|
-
import { readFile as
|
|
242
|
-
import
|
|
206
|
+
import { readFile as readFile4 } from "fs/promises";
|
|
207
|
+
import path5 from "path";
|
|
243
208
|
import { defineCommand } from "citty";
|
|
244
209
|
|
|
245
210
|
// src/commands/canvas/run-progress.ts
|
|
@@ -822,33 +787,6 @@ async function restoreRunSnapshot(manifest, targetDir, opts = {}) {
|
|
|
822
787
|
return { canvasPath: path3.resolve(resolvedTarget, manifest.canvas.path), restored, upToDate };
|
|
823
788
|
}
|
|
824
789
|
|
|
825
|
-
// src/commands/canvas/named-people-read.ts
|
|
826
|
-
import { createHash } from "crypto";
|
|
827
|
-
import { mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
|
|
828
|
-
import path4 from "path";
|
|
829
|
-
var PEOPLE_TIMEOUT_MS = 3e4;
|
|
830
|
-
function peopleReader(cacheDir, spent) {
|
|
831
|
-
const dir = path4.join(cacheDir, "named-people");
|
|
832
|
-
return async (lines) => {
|
|
833
|
-
const said2 = lines.filter((l) => l.trim());
|
|
834
|
-
if (said2.length === 0) return [];
|
|
835
|
-
const key = createHash("sha256").update(JSON.stringify([PEOPLE_PROMPT_VERSION, CLAIMS_MODEL, said2])).digest("hex");
|
|
836
|
-
const file = path4.join(dir, `${key}.json`);
|
|
837
|
-
const cached = await readFile3(file, "utf8").then((text) => readPeople(JSON.parse(text), said2)).catch(() => null);
|
|
838
|
-
if (cached) return cached;
|
|
839
|
-
const answer = await askAboutText(CLAIMS_MODEL, peoplePrompt(said2), spent, {
|
|
840
|
-
timeoutMs: PEOPLE_TIMEOUT_MS,
|
|
841
|
-
request: CLAIMS_REQUEST
|
|
842
|
-
});
|
|
843
|
-
const people = readPeople(answer, said2);
|
|
844
|
-
if (people) {
|
|
845
|
-
await mkdir3(dir, { recursive: true });
|
|
846
|
-
await writeFile3(file, JSON.stringify(answer), "utf8");
|
|
847
|
-
}
|
|
848
|
-
return people;
|
|
849
|
-
};
|
|
850
|
-
}
|
|
851
|
-
|
|
852
790
|
// src/commands/avatars/namedPerson.ts
|
|
853
791
|
var RESEARCH_TIMEOUT_MS = 18e4;
|
|
854
792
|
async function avatarOfNamedPerson(who) {
|
|
@@ -866,7 +804,7 @@ async function avatarOfNamedPerson(who) {
|
|
|
866
804
|
|
|
867
805
|
// src/commands/canvas/slug-restore.ts
|
|
868
806
|
import { existsSync as existsSync2 } from "fs";
|
|
869
|
-
import
|
|
807
|
+
import path4 from "path";
|
|
870
808
|
var SLUG_PATTERN = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
|
|
871
809
|
var SlugRestoreError = class extends Error {
|
|
872
810
|
code;
|
|
@@ -882,8 +820,8 @@ async function canvasForSlug(slug, opts) {
|
|
|
882
820
|
if (!SLUG_PATTERN.test(slug)) {
|
|
883
821
|
throw new SlugRestoreError("invalid_slug", `"${slug}" is not a valid creative slug`);
|
|
884
822
|
}
|
|
885
|
-
const targetDir =
|
|
886
|
-
const local =
|
|
823
|
+
const targetDir = path4.join(opts.workspaceRoot, "src", "creatives", slug);
|
|
824
|
+
const local = path4.join(targetDir, `${slug}.canvas.json`);
|
|
887
825
|
if (!opts.forceRemote && existsSync2(local)) return { canvasPath: local };
|
|
888
826
|
const client = opts.client();
|
|
889
827
|
if (!client) {
|
|
@@ -991,620 +929,6 @@ function seriesEnvelope(lead, results) {
|
|
|
991
929
|
};
|
|
992
930
|
}
|
|
993
931
|
|
|
994
|
-
// src/commands/canvas/static-edit.ts
|
|
995
|
-
function specOf(raw) {
|
|
996
|
-
try {
|
|
997
|
-
return raw ? readAdSpec(raw) : null;
|
|
998
|
-
} catch {
|
|
999
|
-
return null;
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
function frame(spec) {
|
|
1003
|
-
const { copy: _copy, colors: _colors, brand, notes: _notes, source: _source, reference: _reference, ...rest } = spec;
|
|
1004
|
-
const concept = rest.concept ? { ...rest.concept, transfer_note: void 0 } : void 0;
|
|
1005
|
-
const brandShape = brand ? { ...brand, ground: void 0, ink: void 0, accent: void 0, cta: void 0, palette: [] } : void 0;
|
|
1006
|
-
return JSON.stringify({ ...rest, concept, brand: brandShape });
|
|
1007
|
-
}
|
|
1008
|
-
var ROLE_WORDS = {
|
|
1009
|
-
headline: "the headline",
|
|
1010
|
-
cta: "the button",
|
|
1011
|
-
button: "the button",
|
|
1012
|
-
price: "the price",
|
|
1013
|
-
body: "body text",
|
|
1014
|
-
caption: "a caption",
|
|
1015
|
-
label: "a label",
|
|
1016
|
-
fine_print: "the fine print"
|
|
1017
|
-
};
|
|
1018
|
-
function copyEdits(before, after) {
|
|
1019
|
-
const out = [];
|
|
1020
|
-
const shared = Math.min(before.length, after.length);
|
|
1021
|
-
for (let i = 0; i < shared; i++) {
|
|
1022
|
-
const a = before[i];
|
|
1023
|
-
const b = after[i];
|
|
1024
|
-
if (a.text !== b.text) out.push(`Change the words "${a.text}" to exactly "${b.text}".`);
|
|
1025
|
-
if ((a.position ?? "") !== (b.position ?? "") && b.position) out.push(`Move "${b.text}" to ${b.position}.`);
|
|
1026
|
-
if ((a.look ?? "") !== (b.look ?? "") && b.look) out.push(`Set "${b.text}" ${b.look}.`);
|
|
1027
|
-
if (a.lettering !== b.lettering || (a.role ?? "") !== (b.role ?? "") || (a.on ?? "") !== (b.on ?? "")) {
|
|
1028
|
-
out.push(`Set "${b.text}" as ${ROLE_WORDS[b.role ?? ""] ?? "it is described"}${b.on ? `, lettered on ${b.on}` : ""}.`);
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
for (const added of after.slice(shared)) {
|
|
1032
|
-
const role = ROLE_WORDS[added.role ?? ""];
|
|
1033
|
-
out.push(`Add the words "${added.text}"${role ? ` (${role})` : ""}${added.position ? `, ${added.position}` : ""}.`);
|
|
1034
|
-
}
|
|
1035
|
-
for (const removed of before.slice(shared)) out.push(`Remove the words "${removed.text}".`);
|
|
1036
|
-
return out;
|
|
1037
|
-
}
|
|
1038
|
-
function colourEdits(before, after) {
|
|
1039
|
-
const out = [];
|
|
1040
|
-
for (const use of after.colors) {
|
|
1041
|
-
const was = before.colors.find((c) => c.object === use.object);
|
|
1042
|
-
if (was && was.name === use.name && was.hex === use.hex) continue;
|
|
1043
|
-
out.push(`Make ${use.object} ${use.name}${use.hex ? ` (${use.hex})` : ""}.`);
|
|
1044
|
-
}
|
|
1045
|
-
const roles = [
|
|
1046
|
-
["cta", "the button"],
|
|
1047
|
-
["ground", "the background"],
|
|
1048
|
-
["ink", "the designed type"],
|
|
1049
|
-
["accent", "the accent colour"]
|
|
1050
|
-
];
|
|
1051
|
-
for (const [key, object] of roles) {
|
|
1052
|
-
const was = before.brand?.[key];
|
|
1053
|
-
const now = after.brand?.[key];
|
|
1054
|
-
if (typeof now === "string" && was !== now) out.push(`Make ${object} ${now}.`);
|
|
1055
|
-
}
|
|
1056
|
-
return out;
|
|
1057
|
-
}
|
|
1058
|
-
function specEditInstruction(previous, next) {
|
|
1059
|
-
const before = specOf(previous);
|
|
1060
|
-
const after = specOf(next);
|
|
1061
|
-
if (!before || !after || frame(before) !== frame(after)) return null;
|
|
1062
|
-
const edits = [...copyEdits(before.copy, after.copy), ...colourEdits(before, after)];
|
|
1063
|
-
return edits.length > 0 ? edits.join(" ") : null;
|
|
1064
|
-
}
|
|
1065
|
-
function frameChanges(previous, next) {
|
|
1066
|
-
const before = specOf(previous);
|
|
1067
|
-
const after = specOf(next);
|
|
1068
|
-
if (!before || !after) return [];
|
|
1069
|
-
const was = JSON.parse(frame(before));
|
|
1070
|
-
const now = JSON.parse(frame(after));
|
|
1071
|
-
return [.../* @__PURE__ */ new Set([...Object.keys(was), ...Object.keys(now)])].filter(
|
|
1072
|
-
(key) => JSON.stringify(was[key]) !== JSON.stringify(now[key])
|
|
1073
|
-
);
|
|
1074
|
-
}
|
|
1075
|
-
var normalized = (text) => text.trim().toLowerCase().replace(/\s+/g, " ");
|
|
1076
|
-
function repeatsFailedFix(last, instruction) {
|
|
1077
|
-
return Boolean(last && last.blocking.length > 0 && normalized(last.instruction) === normalized(instruction));
|
|
1078
|
-
}
|
|
1079
|
-
function fixMemoryOf(shown, from) {
|
|
1080
|
-
if (from !== void 0 && from !== shown.rendered?.runId) return { blocking: [] };
|
|
1081
|
-
return { ...shown.lastFix ? { lastFix: shown.lastFix } : {}, blocking: shown.blocking ?? [] };
|
|
1082
|
-
}
|
|
1083
|
-
function persistingDefects(before, after) {
|
|
1084
|
-
const now = new Set((after ?? []).filter((f) => f.severity === "blocking").map((f) => f.what));
|
|
1085
|
-
return before.filter((what) => now.has(what));
|
|
1086
|
-
}
|
|
1087
|
-
var onSurface = (line) => line.on ? ` on ${line.on}` : "";
|
|
1088
|
-
function inSceneEdits(before, after) {
|
|
1089
|
-
const was = before.filter((line) => line.lettering === "in_scene");
|
|
1090
|
-
const now = after.filter((line) => line.lettering === "in_scene");
|
|
1091
|
-
const out = [];
|
|
1092
|
-
for (let i = 0; i < Math.min(was.length, now.length); i++) {
|
|
1093
|
-
const a = was[i];
|
|
1094
|
-
const b = now[i];
|
|
1095
|
-
if (a.text !== b.text) out.push(`Change the words "${a.text}"${onSurface(a)} to exactly "${b.text}".`);
|
|
1096
|
-
if ((a.on ?? "") !== (b.on ?? "") && b.on)
|
|
1097
|
-
out.push(`Letter "${b.text}" on ${b.on}${a.on ? ` instead of ${a.on}` : ""}.`);
|
|
1098
|
-
}
|
|
1099
|
-
for (const added of now.slice(was.length)) out.push(`Letter the words "${added.text}"${onSurface(added)}.`);
|
|
1100
|
-
for (const removed of was.slice(now.length)) out.push(`Remove the words "${removed.text}" from the picture.`);
|
|
1101
|
-
return out;
|
|
1102
|
-
}
|
|
1103
|
-
function pictureEdit(previous, next) {
|
|
1104
|
-
const before = specOf(previous);
|
|
1105
|
-
const after = specOf(next);
|
|
1106
|
-
if (!before || !after || frame(before) !== frame(after)) return null;
|
|
1107
|
-
const changed = after.colors.filter((use) => {
|
|
1108
|
-
const was = before.colors.find((c) => c.object === use.object);
|
|
1109
|
-
return !isWordsObject(use.object) && !(was && was.name === use.name && was.hex === use.hex);
|
|
1110
|
-
});
|
|
1111
|
-
const ground = after.brand?.ground;
|
|
1112
|
-
const edits = [
|
|
1113
|
-
...inSceneEdits(before.copy, after.copy),
|
|
1114
|
-
...changed.map((use) => `Make ${use.object} ${use.name}${use.hex ? ` (${use.hex})` : ""}.`),
|
|
1115
|
-
...typeof ground === "string" && before.brand?.ground !== ground ? [`Make the background ${ground}.`] : []
|
|
1116
|
-
];
|
|
1117
|
-
return edits.length > 0 ? edits.join(" ") : null;
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
// src/commands/canvas/static-autofix.ts
|
|
1121
|
-
var AUTO_FIX_ROUNDS = 3;
|
|
1122
|
-
function wholePicture(f) {
|
|
1123
|
-
const kind = f.kind;
|
|
1124
|
-
if (!kind) return false;
|
|
1125
|
-
return kind.item === "subject" || kind.item === "one_idea" || kind.item === "concept" || (kind.item === "picture" || kind.item === "native" || kind.item === "rule") && kind.element === "picture";
|
|
1126
|
-
}
|
|
1127
|
-
var BRIEF_ITEMS = /* @__PURE__ */ new Set(["subject", "concept", "proof", "person"]);
|
|
1128
|
-
var fromBrief = (f) => f.kind !== void 0 && (BRIEF_ITEMS.has(f.kind.item) || f.kind.item === "rule" && f.kind.element === "picture");
|
|
1129
|
-
var wordsBreakRule = (f) => f.kind?.item === "rule" && f.kind.element === "copy";
|
|
1130
|
-
var lostVital = (f) => f.severity === "blocking" && f.kind?.item === "concept" && f.kind.job !== void 0;
|
|
1131
|
-
function keptLostHint(review, idea) {
|
|
1132
|
-
const lost = unique(review.filter(lostVital).map((f) => f.what.replace(/\.$/, "")));
|
|
1133
|
-
if (lost.length === 0) return null;
|
|
1134
|
-
return `Not done: what made the proven ad win is gone (${lost.join("; ")}). Never show this version as done: restore it as the plan decided it (its line under "What survives and what changes" and prompt.json's \`concept.load_bearing\`, carried in the scene, the references and the lines' \`look\`) and run again; if nothing of ours may carry it, build the idea on another proven ad (\`baker winning-ads fit <adId>\` on the next candidates, then \`baker creatives make ${idea ?? "<idea>"} --slug <new slug> --reference <adId>\`) and tell the person why, in one line.`;
|
|
1135
|
-
}
|
|
1136
|
-
function stopsWithoutRepair(review, brief, repaired) {
|
|
1137
|
-
return !repaired && review.some((f) => lostVital(f) && brief.includes(withoutSize(f.what)));
|
|
1138
|
-
}
|
|
1139
|
-
var comparesSizes = (f) => f.kind?.item === "sizes";
|
|
1140
|
-
var cutCopy = (f) => f.kind?.defect === "cut" && (f.kind.element === "logo" || f.kind.element === "button" || f.kind.element === "copy");
|
|
1141
|
-
function aboutWords(f) {
|
|
1142
|
-
const what = withoutSize(f.what);
|
|
1143
|
-
return PLACED.some((p) => p.test(what)) || MISREAD.test(what) || MISSING.test(what) || EXTRA_WORDS.test(what) || cutCopy(f) || f.kind !== void 0 && ["copy", "button", "logo"].includes(f.kind.element);
|
|
1144
|
-
}
|
|
1145
|
-
var PATCHED_WORDS = "the words came with a patch of redrawn picture around them";
|
|
1146
|
-
var UNREAD_WORDS = "where the words sit could not be read";
|
|
1147
|
-
var ARTIFACT = /\b(?:halos?|glow|seams?|smears?|smudges?|blotch(?:es)?|patch(?:es)?|box(?:es)?|rectangles?|scrims?|backings?|ghost(?:ed|ing|s)?)\b/i;
|
|
1148
|
-
var WORDS = /\b(?:words?|text|copy|headline|lines?|lettering|type|quote|caption|label|button|pill|cta|logo)\b/i;
|
|
1149
|
-
var wordsArtifact = (f) => {
|
|
1150
|
-
const what = withoutSize(f.what);
|
|
1151
|
-
return ARTIFACT.test(what) && WORDS.test(what);
|
|
1152
|
-
};
|
|
1153
|
-
var MANY_DEFECTS = 3;
|
|
1154
|
-
var withoutSize = (what) => what.replace(/^\d+(?:\.\d+)?:\d+(?:\.\d+)?(?:,\s*\d+(?:\.\d+)?:\d+(?:\.\d+)?)*:\s*/, "");
|
|
1155
|
-
var sizesOf = (what) => what.match(/^(\d+(?:\.\d+)?:\d+(?:\.\d+)?(?:,\s*\d+(?:\.\d+)?:\d+(?:\.\d+)?)*):\s/)?.[1]?.split(/,\s*/) ?? [];
|
|
1156
|
-
function carryUnchanged(now, prior, unchanged) {
|
|
1157
|
-
const settled = (f) => {
|
|
1158
|
-
const sizes = sizesOf(f.what);
|
|
1159
|
-
return sizes.length > 0 && sizes.every((s) => unchanged.includes(s)) && !comparesSizes(f);
|
|
1160
|
-
};
|
|
1161
|
-
return [...now.filter((f) => !settled(f)), ...prior.filter(settled)];
|
|
1162
|
-
}
|
|
1163
|
-
var pct = (share) => `${Math.round(share * 100)}%`;
|
|
1164
|
-
var PAST_BAND = /^(.+?) sits? (?:close to )?where (.+?) covers? (?:it|them) \((.+)\)\.?$/;
|
|
1165
|
-
var OFF_EDGE = /^(.+?) runs? off the edge of the picture \((.+)\)\.?$/;
|
|
1166
|
-
var OUTSIDE_SPACE = /^(.+?) sits? outside the space every size keeps clear \((.+)\)\.?$/;
|
|
1167
|
-
var EXTRA_WORDS = /^the picture adds words that aren't in the copy: (.+?)\. Remove them, or add them to the copy\.?$/;
|
|
1168
|
-
var SCENE_PRICES = /^the picture shows prices the copy does not hold: (.+?)\. Make them unreadable\.?$/;
|
|
1169
|
-
var PLACED = [PAST_BAND, OFF_EDGE, OUTSIDE_SPACE];
|
|
1170
|
-
var MISREAD = /^Text: (".+") reads (".*")\.?$/;
|
|
1171
|
-
var MISSING = /^Text: (".+") is missing\.?$/;
|
|
1172
|
-
var MAKE_ROOM = "Make the room by moving what is next to it with it and shortening the picture or the gaps, keeping every block in its order.";
|
|
1173
|
-
var OVERSHOOT = 0.06;
|
|
1174
|
-
function moveInto(what, edges, band) {
|
|
1175
|
-
const at = (edge) => edges.includes(edge);
|
|
1176
|
-
const top = band ? band.top + OVERSHOOT : 0;
|
|
1177
|
-
const bottom = band ? band.bottom + OVERSHOOT : 0;
|
|
1178
|
-
const vertical = at("bottom") && at("top") ? band ? `so all of it sits between ${pct(top)} and ${pct(1 - bottom)} of the height` : "into the middle of the frame, away from its top and bottom" : at("bottom") && band ? `up so all of it sits above ${pct(1 - bottom)} of the height, the bottom ${pct(bottom)} showing only the picture` : at("top") && band ? `down so all of it sits below ${pct(top)} of the height, the top ${pct(top)} showing only the picture` : at("bottom") ? "up, away from the bottom of the frame" : at("top") ? "down, away from the top of the frame" : "";
|
|
1179
|
-
const sides = ["right", "left"].filter((e) => at(e === "right" ? "right edge" : "left edge"));
|
|
1180
|
-
const side = sides.map((e) => band ? `at least ${pct(band[e])} in from the ${e} edge` : `away from the ${e} edge`).join(" and ");
|
|
1181
|
-
if (!vertical) return `Move ${what} ${side}`;
|
|
1182
|
-
return side ? `Move ${what} ${vertical}, and ${side}` : `Move ${what} ${vertical}`;
|
|
1183
|
-
}
|
|
1184
|
-
function correctionOf(finding, band, kind) {
|
|
1185
|
-
const what = withoutSize(finding).trim();
|
|
1186
|
-
if (/could not be read back/.test(what)) return null;
|
|
1187
|
-
const past = what.match(PAST_BAND);
|
|
1188
|
-
if (past) {
|
|
1189
|
-
const [, block = "", surface = "", edges = ""] = past;
|
|
1190
|
-
const covers = band && edges.includes("bottom") && edges.includes("top") ? `: ${surface} covers the top ${pct(band.top)} and the bottom ${pct(band.bottom)} of the frame` : band && edges.includes("bottom") ? `: ${surface} covers the bottom ${pct(band.bottom)} of the frame` : band && edges.includes("top") ? `: ${surface} covers the top ${pct(band.top)} of the frame` : "";
|
|
1191
|
-
return `${moveInto(block, edges, band)}${covers}. ${MAKE_ROOM}`;
|
|
1192
|
-
}
|
|
1193
|
-
const off = what.match(OFF_EDGE) ?? what.match(OUTSIDE_SPACE);
|
|
1194
|
-
if (off) {
|
|
1195
|
-
const [, block = "", edges = ""] = off;
|
|
1196
|
-
const named = edges.replace(/the (top|bottom) of the screen/g, "the $1 edge").replace(/ and /g, " and ");
|
|
1197
|
-
return `Move ${block} fully inside the frame, with clear space between it and ${named}, smaller if it needs to be.`;
|
|
1198
|
-
}
|
|
1199
|
-
const extra = what.match(EXTRA_WORDS);
|
|
1200
|
-
if (extra) {
|
|
1201
|
-
return `Erase these words wherever they appear, leaving the surface they are on blank or with plain lines: ${extra[1]}.`;
|
|
1202
|
-
}
|
|
1203
|
-
const prices = what.match(SCENE_PRICES);
|
|
1204
|
-
if (prices) {
|
|
1205
|
-
return `Blur these figures until no digit can be read, keeping the document or screen they are on as it is: ${prices[1]}.`;
|
|
1206
|
-
}
|
|
1207
|
-
const misread = what.match(MISREAD);
|
|
1208
|
-
if (misread) return `Re-letter ${misread[1]} exactly as written, letter for letter (it now reads ${misread[2]}).`;
|
|
1209
|
-
const missing = what.match(MISSING);
|
|
1210
|
-
if (missing) return `Add the line ${missing[1]}, spelled exactly, where it belongs in the layout.`;
|
|
1211
|
-
if (kind?.item === "sizes") return FOLLOW_PICTURE;
|
|
1212
|
-
const described = what.replace(/\.$/, "");
|
|
1213
|
-
return `Fix this: ${described.charAt(0).toLowerCase()}${described.slice(1)}.`;
|
|
1214
|
-
}
|
|
1215
|
-
function autoFixStep(canvas, review, opts = {}) {
|
|
1216
|
-
if ((opts.round ?? 0) >= AUTO_FIX_ROUNDS) return null;
|
|
1217
|
-
const flagged = (review ?? []).filter((f) => f.severity === "blocking" && !wordsBreakRule(f));
|
|
1218
|
-
if (flagged.length === 0) return null;
|
|
1219
|
-
if (isNativeCanvas(canvas)) return { kind: "respec", findings: unique(flagged.map((f) => f.what)) };
|
|
1220
|
-
const relaid = relaidSizes(canvas);
|
|
1221
|
-
const blocking = onDerivedSizes(flagged, relaid);
|
|
1222
|
-
const painted = paintedPlates(canvas);
|
|
1223
|
-
const onPainted = (f) => comparesSizes(f) && sizesOf(f.what).length > 0 && sizesOf(f.what).every((size) => painted.has(size));
|
|
1224
|
-
const cutSizes = new Map(relaid.filter((r) => r.words).map((r) => [r.format, r.id]));
|
|
1225
|
-
const patched = (f) => !lostVital(f) && ([PATCHED_WORDS, UNREAD_WORDS].some((said2) => withoutSize(f.what).startsWith(said2)) || wordsArtifact(f)) && sizesOf(f.what).length > 0 && sizesOf(f.what).every((size) => cutSizes.has(size));
|
|
1226
|
-
const wordsOnly = (f) => patched(f) || aboutWords(f) && sizesOf(f.what).length > 0 && sizesOf(f.what).every((size) => cutSizes.has(size));
|
|
1227
|
-
if (blocking.length > 0 && blocking.some(patched) && blocking.every(wordsOnly)) {
|
|
1228
|
-
return {
|
|
1229
|
-
kind: "regenerate",
|
|
1230
|
-
ids: unique(blocking.flatMap((f) => sizesOf(f.what).flatMap((size) => cutSizes.get(size) ?? []))),
|
|
1231
|
-
note: unique(blocking.map((f) => withoutSize(f.what))).join(" ")
|
|
1232
|
-
};
|
|
1233
|
-
}
|
|
1234
|
-
if (blocking.length > 0 && blocking.every(onPainted)) {
|
|
1235
|
-
return {
|
|
1236
|
-
kind: "regenerate",
|
|
1237
|
-
ids: unique(blocking.flatMap((f) => sizesOf(f.what).flatMap((size) => painted.get(size) ?? []))),
|
|
1238
|
-
note: `The last picture painted from the chosen one had this wrong, so avoid it: ${unique(blocking.map((f) => withoutSize(f.what))).join(" ")}`
|
|
1239
|
-
};
|
|
1240
|
-
}
|
|
1241
|
-
const worded = relaid.filter((r) => r.words).map((r) => r.format);
|
|
1242
|
-
const unplaceable = /* @__PURE__ */ new Set([
|
|
1243
|
-
...(opts.tooFar ?? []).filter((format) => relaid.some((r) => r.format === format)),
|
|
1244
|
-
...worded
|
|
1245
|
-
]);
|
|
1246
|
-
const misplaced = (f) => {
|
|
1247
|
-
const what = withoutSize(f.what);
|
|
1248
|
-
const sizes = sizesOf(f.what);
|
|
1249
|
-
return sizes.length > 0 && !sizes.every((size) => unplaceable.has(size)) && (PLACED.some((p) => p.test(what)) || cutCopy(f));
|
|
1250
|
-
};
|
|
1251
|
-
const extend = unique(blocking.filter(misplaced).flatMap((f) => sizesOf(f.what))).filter((size) => !unplaceable.has(size));
|
|
1252
|
-
const placing = extend.length > 0 ? { extend } : {};
|
|
1253
|
-
const rest = blocking.filter((f) => !misplaced(f));
|
|
1254
|
-
const at = (f) => relaid.find((r) => f.what.startsWith(`${r.format}:`) && (!r.words || aboutWords(f)));
|
|
1255
|
-
const keepRight = keptRules(opts.fixedBefore);
|
|
1256
|
-
const edits = {};
|
|
1257
|
-
for (const r of relaid) {
|
|
1258
|
-
const lines = unique(rest.filter((f) => at(f) === r).flatMap((f) => correctionOf(f.what, r.band, f.kind) ?? []));
|
|
1259
|
-
if (lines.length > 0) edits[r.id] = [...lines, ...keepRight ? [keepRight] : []].join(" ");
|
|
1260
|
-
}
|
|
1261
|
-
const sizesOnly = () => {
|
|
1262
|
-
const ids = Object.keys(edits);
|
|
1263
|
-
if (ids.length > 0) return { kind: "relayout", ids, edits, ...placing };
|
|
1264
|
-
return extend.length > 0 ? { kind: "extend", sizes: extend } : null;
|
|
1265
|
-
};
|
|
1266
|
-
const onSeveralSizes = (f) => {
|
|
1267
|
-
const what = withoutSize(f.what);
|
|
1268
|
-
return new Set(rest.filter((g) => withoutSize(g.what) === what).flatMap((g) => sizesOf(g.what))).size >= 2;
|
|
1269
|
-
};
|
|
1270
|
-
const settledPicture = opts.previous === "relayout" || opts.previous === "extend";
|
|
1271
|
-
const pictureFindings = rest.filter((f) => !at(f) && !patched(f) && (!settledPicture || onSeveralSizes(f)));
|
|
1272
|
-
const onPicture = unique(pictureFindings.map((f) => withoutSize(f.what)));
|
|
1273
|
-
if (onPicture.length === 0) return sizesOnly();
|
|
1274
|
-
const every = unique([...extend, ...deliveredSizes(canvas)]).filter((size) => !worded.includes(size));
|
|
1275
|
-
const afterNewPicture = every.length > 0 ? { extend: every } : {};
|
|
1276
|
-
const persisting = new Set((opts.lastFix?.blocking ?? []).map(withoutSize));
|
|
1277
|
-
const stillWrong = opts.previous === "fix" && onPicture.some((w) => persisting.has(w));
|
|
1278
|
-
const brief = unique(pictureFindings.filter(fromBrief).map((f) => withoutSize(f.what)));
|
|
1279
|
-
const rollAgain = stillWrong || brief.length > 0 || onPicture.length >= MANY_DEFECTS || pictureFindings.some(wholePicture);
|
|
1280
|
-
const last = (opts.round ?? 0) >= AUTO_FIX_ROUNDS - 1;
|
|
1281
|
-
if (rollAgain && (!last || brief.length > 0) && !opts.keepPicture && nodesWithRole(canvas, STATIC_VARIANTS_ROLE).length > 0) {
|
|
1282
|
-
return {
|
|
1283
|
-
kind: "regenerate",
|
|
1284
|
-
ids: [STATIC_VARIANTS_ROLE],
|
|
1285
|
-
note: [`The last picture made from this brief had this wrong, so avoid it: ${onPicture.join(" ")}`, ...keepRight ? [keepRight] : []].join(" "),
|
|
1286
|
-
...brief.length > 0 ? { brief } : {},
|
|
1287
|
-
...afterNewPicture
|
|
1288
|
-
};
|
|
1289
|
-
}
|
|
1290
|
-
const changes = unique(
|
|
1291
|
-
pictureFindings.filter((f) => !fromBrief(f)).flatMap((f) => correctionOf(f.what, void 0, f.kind) ?? [])
|
|
1292
|
-
);
|
|
1293
|
-
if (changes.length === 0) return sizesOnly();
|
|
1294
|
-
const named = new Set(blocking.flatMap((f) => sizesOf(f.what)));
|
|
1295
|
-
const keep = relaid.filter((r) => !r.words).map((r) => r.format).filter((format) => !named.has(format));
|
|
1296
|
-
const remade = every.filter((size) => !keep.includes(size));
|
|
1297
|
-
const kept = {
|
|
1298
|
-
...keep.length > 0 ? { keep } : {},
|
|
1299
|
-
...remade.length > 0 ? { extend: remade } : {}
|
|
1300
|
-
};
|
|
1301
|
-
const asked = `Change only this: ${changes.join(" ")}`;
|
|
1302
|
-
const again = onPicture.filter((w) => persisting.has(w)).map((w) => w.replace(/\.$/, ""));
|
|
1303
|
-
const instruction = [
|
|
1304
|
-
again.length > 0 ? `${asked} The last edit was already asked for this and Image 1 still shows it, so make it clearly: ${again.join("; ")}.` : asked,
|
|
1305
|
-
...keepRight ? [keepRight] : []
|
|
1306
|
-
].join(" ");
|
|
1307
|
-
if (repeatsFailedFix(opts.lastFix, asked) || repeatsFailedFix(opts.lastFix, instruction)) return null;
|
|
1308
|
-
const relay = Object.fromEntries(Object.entries(edits).filter(([id]) => relaid.some((r) => r.id === id && !r.words)));
|
|
1309
|
-
return { kind: "fix", instruction, ...Object.keys(relay).length > 0 ? { relay } : {}, ...kept };
|
|
1310
|
-
}
|
|
1311
|
-
var unique = (lines) => [...new Set(lines)];
|
|
1312
|
-
var blockingOf = (review) => unique(review.filter((f) => f.severity === "blocking").map((f) => f.what));
|
|
1313
|
-
function correctFrom(attempts) {
|
|
1314
|
-
const latest = attempts[attempts.length - 1];
|
|
1315
|
-
const fewest = Math.min(...attempts.map((a) => blockingOf(a.review).length));
|
|
1316
|
-
const base = blockingOf(latest.review).length > fewest ? attempts.find((a) => blockingOf(a.review).length === fewest) : latest;
|
|
1317
|
-
const now = new Set(blockingOf(base.review).map(withoutSize));
|
|
1318
|
-
const fixedBefore = unique(
|
|
1319
|
-
attempts.filter((a) => a !== base).flatMap((a) => blockingOf(a.review)).filter((what) => !now.has(withoutSize(what)))
|
|
1320
|
-
);
|
|
1321
|
-
return { ...base, fixedBefore };
|
|
1322
|
-
}
|
|
1323
|
-
function keptRules(fixedBefore) {
|
|
1324
|
-
const rules = unique((fixedBefore ?? []).map((f) => withoutSize(f).replace(/\.$/, "")));
|
|
1325
|
-
return rules.length > 0 ? `These were wrong in an earlier version and are right now, so keep them right: ${rules.join("; ")}.` : null;
|
|
1326
|
-
}
|
|
1327
|
-
var FOLLOW_PICTURE = "Show exactly what the finished ad (Image 2) shows: its people, products, panels and their order, and nothing it does not show.";
|
|
1328
|
-
function onDerivedSizes(findings, relaid) {
|
|
1329
|
-
if (relaid.length === 0) return [...findings];
|
|
1330
|
-
return findings.flatMap((f) => {
|
|
1331
|
-
const sizes = sizesOf(f.what);
|
|
1332
|
-
const onPicture = sizes.length > 0 && sizes.every((size) => !relaid.some((r) => r.format === size));
|
|
1333
|
-
if (!onPicture || !comparesSizes(f)) return [f];
|
|
1334
|
-
return relaid.map((r) => ({ ...f, what: `${r.format}: ${withoutSize(f.what)}` }));
|
|
1335
|
-
});
|
|
1336
|
-
}
|
|
1337
|
-
function deliveredSizes(canvas) {
|
|
1338
|
-
const nodes = canvas?.nodes;
|
|
1339
|
-
const labels = Array.isArray(nodes) ? nodes.find((n) => n.id === "final" && n.type === "collect")?.params?.labels : void 0;
|
|
1340
|
-
return Array.isArray(labels) ? labels.filter((l) => typeof l === "string") : [];
|
|
1341
|
-
}
|
|
1342
|
-
function relaidSizes(canvas) {
|
|
1343
|
-
const nodes = canvas?.nodes;
|
|
1344
|
-
const placements = Array.isArray(nodes) ? plannedPlacements(nodes) : void 0;
|
|
1345
|
-
const relaid = nodesWithRole(canvas, STATIC_ADAPT_FORMAT_ROLE).flatMap((n) => {
|
|
1346
|
-
const format = formatOfAdaptId(n.id);
|
|
1347
|
-
if (!format) return [];
|
|
1348
|
-
const model = String(n.params?.model ?? "");
|
|
1349
|
-
return [{ id: n.id, format, band: adaptPlan(model, format, placements).safe, words: false }];
|
|
1350
|
-
});
|
|
1351
|
-
const cut = nodesWithRole(canvas, STATIC_FORMAT_ROLE).flatMap((n) => {
|
|
1352
|
-
const format = n.params?.format;
|
|
1353
|
-
if (typeof format !== "string") return [];
|
|
1354
|
-
const model = String(n.params?.words?.model ?? "");
|
|
1355
|
-
const own = Array.isArray(n.params?.placements) ? n.params.placements : placements;
|
|
1356
|
-
return [{ id: n.id, format, band: adaptPlan(model, format, own).safe, words: true }];
|
|
1357
|
-
});
|
|
1358
|
-
return [...relaid, ...cut];
|
|
1359
|
-
}
|
|
1360
|
-
function paintedPlates(canvas) {
|
|
1361
|
-
const plates = new Set(nodesWithRole(canvas, STATIC_PLATE_ROLE).map((n) => n.id));
|
|
1362
|
-
return new Map(
|
|
1363
|
-
nodesWithRole(canvas, STATIC_FORMAT_ROLE).flatMap((n) => {
|
|
1364
|
-
const plate = String(n.inputs?.plate ?? "").match(/^\$ref:([a-z][a-z0-9_]*)\./)?.[1];
|
|
1365
|
-
const format = n.params?.format;
|
|
1366
|
-
return plate && plates.has(plate) && typeof format === "string" ? [[format, plate]] : [];
|
|
1367
|
-
})
|
|
1368
|
-
);
|
|
1369
|
-
}
|
|
1370
|
-
function placedTooFar(canvas, outputsByNode) {
|
|
1371
|
-
const placed = nodesWithRole(canvas, STATIC_PLACE_ROLE).flatMap((n) => {
|
|
1372
|
-
const format = n.params?.format;
|
|
1373
|
-
const unmoved = outputsByNode[n.id]?.reason;
|
|
1374
|
-
return (unmoved === "too_far" || unmoved === "inside_band") && typeof format === "string" ? [format] : [];
|
|
1375
|
-
});
|
|
1376
|
-
const cut = nodesWithRole(canvas, STATIC_FORMAT_ROLE).flatMap((n) => {
|
|
1377
|
-
const format = n.params?.format;
|
|
1378
|
-
const facts = outputsByNode[n.id]?.facts;
|
|
1379
|
-
return facts?.reason === "band_too_far" && typeof format === "string" ? [format] : [];
|
|
1380
|
-
});
|
|
1381
|
-
return [...placed, ...cut];
|
|
1382
|
-
}
|
|
1383
|
-
function formatOfSizeNode(canvas, id) {
|
|
1384
|
-
const relaid = formatOfAdaptId(id);
|
|
1385
|
-
if (relaid) return relaid;
|
|
1386
|
-
const node = nodesWithRole(canvas, STATIC_FORMAT_ROLE).find((n) => n.id === id);
|
|
1387
|
-
const format = node?.params?.format;
|
|
1388
|
-
return typeof format === "string" ? format : null;
|
|
1389
|
-
}
|
|
1390
|
-
function rendersNewPicture(run) {
|
|
1391
|
-
return !run.fix && !run.useVariant && !run.sizesOnly;
|
|
1392
|
-
}
|
|
1393
|
-
function paidFor(run) {
|
|
1394
|
-
if (run.fix) return "edit";
|
|
1395
|
-
return run.useVariant || run.sizesOnly ? "sizes" : "options";
|
|
1396
|
-
}
|
|
1397
|
-
function withRelayNote(canvas, ids, note) {
|
|
1398
|
-
const holder = canvas;
|
|
1399
|
-
if (!Array.isArray(holder.nodes)) return canvas;
|
|
1400
|
-
return {
|
|
1401
|
-
...holder,
|
|
1402
|
-
nodes: holder.nodes.map((n) => {
|
|
1403
|
-
if (typeof n.id !== "string" || !ids.includes(n.id)) return n;
|
|
1404
|
-
const paint = n.params?.paint;
|
|
1405
|
-
if (paint && typeof paint === "object") {
|
|
1406
|
-
const prompt = [typeof paint.prompt === "string" ? paint.prompt : "", note].filter(Boolean).join("\n\n");
|
|
1407
|
-
return { ...n, params: { ...n.params, paint: { ...paint, prompt } } };
|
|
1408
|
-
}
|
|
1409
|
-
if (typeof n.params?.prompt !== "string") return n;
|
|
1410
|
-
const [lead = "", ...rest] = n.params.prompt.split("\n\n");
|
|
1411
|
-
return { ...n, params: { ...n.params, prompt: [lead, note, ...rest].join("\n\n") } };
|
|
1412
|
-
})
|
|
1413
|
-
};
|
|
1414
|
-
}
|
|
1415
|
-
function withRelayEdit(canvas, id, opts) {
|
|
1416
|
-
const holder = canvas;
|
|
1417
|
-
if (!Array.isArray(holder.nodes)) return canvas;
|
|
1418
|
-
const target = holder.nodes.find((n) => n.id === id);
|
|
1419
|
-
if (target?.type === "static_format") return withWordsEdit({ nodes: holder.nodes, holder }, target, opts);
|
|
1420
|
-
const prompt = target?.params?.prompt;
|
|
1421
|
-
const refs = target?.inputs?.reference;
|
|
1422
|
-
if (!target || typeof prompt !== "string" || !Array.isArray(refs)) return canvas;
|
|
1423
|
-
const lastId = `last_${id}`;
|
|
1424
|
-
const remote = /^(?:https?|data):/.test(opts.previous);
|
|
1425
|
-
const last = {
|
|
1426
|
-
id: lastId,
|
|
1427
|
-
type: "ingest",
|
|
1428
|
-
params: remote ? { source: "url", url: opts.previous, expect: "image" } : { source: "path", path: opts.previous, expect: "image" }
|
|
1429
|
-
};
|
|
1430
|
-
const again = opts.asked?.includes(opts.instruction) ? "The last edit was asked for this and Image 1 still shows it wrong, so make the change clearly: " : "";
|
|
1431
|
-
const lead = `Edit: Image 1 is this ad as it was last laid out for this size. ${again}${opts.instruction} Keep the rest of Image 1 as it is: the picture, the colours, the lettering and every word, its layout changed only as much as this needs.`;
|
|
1432
|
-
const kept = prompt.split("\n\n").slice(1).filter((p) => !p.startsWith("Scale:")).map((p) => p.replace(/\bImage (\d+)\b/g, (_, n) => `Image ${Number(n) + 1}`)).map(
|
|
1433
|
-
(p) => p.startsWith("References:") ? p.replace("References:", "References:\nImage 1 (THIS SIZE): the last layout of this size, to edit.").replace(/^Image 2 \(AD\):.*$/m, "Image 2 (AD): the finished ad this size is made from: its words, logo and picture are the ones to keep.") : p
|
|
1434
|
-
);
|
|
1435
|
-
const leads = new Set(
|
|
1436
|
-
holder.nodes.flatMap((n) => n.tags?.role === SERIES_LEAD_ROLE ? [n.id] : [])
|
|
1437
|
-
);
|
|
1438
|
-
const own = refs.map((r) => typeof r === "string" && leads.has(r.match(/^\$ref:([a-z][a-z0-9_]*)\./)?.[1]) ? "$ref:master.image" : r);
|
|
1439
|
-
const edited = {
|
|
1440
|
-
...target,
|
|
1441
|
-
inputs: { ...target.inputs, reference: [`$ref:${lastId}.asset`, ...own] },
|
|
1442
|
-
params: { ...target.params, prompt: [lead, ...kept].join("\n\n") }
|
|
1443
|
-
};
|
|
1444
|
-
const at = holder.nodes.indexOf(target);
|
|
1445
|
-
return { ...holder, nodes: [...holder.nodes.slice(0, at), last, edited, ...holder.nodes.slice(at + 1)] };
|
|
1446
|
-
}
|
|
1447
|
-
function lastFile(id, file) {
|
|
1448
|
-
const remote = /^(?:https?|data):/.test(file);
|
|
1449
|
-
return {
|
|
1450
|
-
id,
|
|
1451
|
-
type: "ingest",
|
|
1452
|
-
params: remote ? { source: "url", url: file, expect: "image" } : { source: "path", path: file, expect: "image" }
|
|
1453
|
-
};
|
|
1454
|
-
}
|
|
1455
|
-
function withWordsEdit(at, target, opts) {
|
|
1456
|
-
const words = target.params?.words;
|
|
1457
|
-
if (typeof words?.prompt !== "string") return at.holder;
|
|
1458
|
-
const lastId = `last_${String(target.id)}`;
|
|
1459
|
-
const again = opts.asked?.includes(opts.instruction) ? "The last edit was asked for this and Image 1 still shows it wrong, so make the change clearly: " : "";
|
|
1460
|
-
const instruction = `Image 1 is this size as its words were last set. ${again}${opts.instruction} Keep the rest of Image 1's words as they are: the lines, the type, the colours and what carries them, moved only as much as this needs. The picture is Image 2's, unchanged.`;
|
|
1461
|
-
const prompt = words.prompt.replace(/\bImage (\d+)\b/g, (_, n) => `Image ${Number(n) + 1}`).replace("References:", "References:\nImage 1 (THIS SIZE): this size as its words were last set, to edit.");
|
|
1462
|
-
const edited = {
|
|
1463
|
-
...target,
|
|
1464
|
-
inputs: { ...target.inputs, previous: `$ref:${lastId}.asset` },
|
|
1465
|
-
params: { ...target.params, words: { ...words, prompt, edit: { instruction } } }
|
|
1466
|
-
};
|
|
1467
|
-
const index = at.nodes.indexOf(target);
|
|
1468
|
-
return {
|
|
1469
|
-
...at.holder,
|
|
1470
|
-
nodes: [...at.nodes.slice(0, index), lastFile(lastId, opts.previous), edited, ...at.nodes.slice(index + 1)]
|
|
1471
|
-
};
|
|
1472
|
-
}
|
|
1473
|
-
function withSizesFollowingFix(canvas, opts) {
|
|
1474
|
-
let out = canvas;
|
|
1475
|
-
for (const n of nodesWithRole(canvas, STATIC_ADAPT_FORMAT_ROLE)) {
|
|
1476
|
-
const also = opts.also?.[n.id];
|
|
1477
|
-
const previous = opts.last[n.id];
|
|
1478
|
-
if (previous) {
|
|
1479
|
-
const instruction = `Make the change the finished ad (Image 2) just had: ${opts.change}${also ? ` ${also}` : ""}`;
|
|
1480
|
-
out = withRelayEdit(out, n.id, { previous, instruction });
|
|
1481
|
-
} else if (also) out = withRelayNote(out, [n.id], `This size must also change this: ${also}`);
|
|
1482
|
-
}
|
|
1483
|
-
return out;
|
|
1484
|
-
}
|
|
1485
|
-
var EXTEND_PROMPT = [
|
|
1486
|
-
"Deliverable: Image 1 is a finished ad set inside a frame with flat grey margins around it. Paint only the grey: continue the picture outward into it so the whole frame reads as one picture, the scene going on (the wall, the floor, the sky, the room) or, where the ad has no scene, its own plain ground and colours.",
|
|
1487
|
-
"Keep everything that is not grey exactly where and as it is: every word, the logo, the button, the people, the products. Nothing in it moves, grows or is redrawn.",
|
|
1488
|
-
"Add nothing in the grey: no words, no letters, no logos, no buttons, no new people or objects, no frames, borders or shadows around the ad. Never repeat any part of the ad in it: no second logo, button, line of text, card or person; the grey is only more of the room, the table, the floor, the sky or the plain ground."
|
|
1489
|
-
].join("\n\n");
|
|
1490
|
-
function withExtendedSizes(canvas, formats) {
|
|
1491
|
-
const holder = canvas;
|
|
1492
|
-
if (!Array.isArray(holder.nodes)) return canvas;
|
|
1493
|
-
const nodes = holder.nodes;
|
|
1494
|
-
const final = nodes.find((n) => n.id === "final" && n.type === "collect");
|
|
1495
|
-
const labels = final?.params?.labels;
|
|
1496
|
-
const images = final?.inputs?.images;
|
|
1497
|
-
if (!final || !Array.isArray(labels) || !Array.isArray(images)) return canvas;
|
|
1498
|
-
const painter = nodesWithRole(canvas, STATIC_ADAPT_FORMAT_ROLE)[0] ?? nodesWithRole(canvas, STATIC_VARIANT_CALL_ROLE)[0];
|
|
1499
|
-
const params = painter?.params ?? {};
|
|
1500
|
-
const model = typeof params.model === "string" ? params.model : void 0;
|
|
1501
|
-
if (!model) return canvas;
|
|
1502
|
-
const placements = plannedPlacements(nodes) ?? nodes.find((n) => n.type === "static_safe_fit" && Array.isArray(n.params?.placements))?.params?.placements;
|
|
1503
|
-
const copy = placingCopy(nodes);
|
|
1504
|
-
const added = [];
|
|
1505
|
-
const delivered = [...images];
|
|
1506
|
-
const logoOn = /* @__PURE__ */ new Map();
|
|
1507
|
-
const cut = new Set(nodesWithRole(canvas, STATIC_FORMAT_ROLE).map((n) => `$ref:${n.id}.image`));
|
|
1508
|
-
for (const format of formats) {
|
|
1509
|
-
const at = labels.indexOf(format);
|
|
1510
|
-
const reads = images[at];
|
|
1511
|
-
const composite = nodes.find(
|
|
1512
|
-
(n) => typeof reads === "string" && reads === `$ref:${String(n.id)}.image` && n.tags?.role === LOGO_COMPOSITE_ROLE
|
|
1513
|
-
);
|
|
1514
|
-
const source = composite ? composite.inputs?.image : reads;
|
|
1515
|
-
if (at < 0 || typeof source !== "string" || cut.has(source)) continue;
|
|
1516
|
-
const slug = formatSlug(format);
|
|
1517
|
-
const ratio = nearestSupportedAspectRatio("image_generate", model, format);
|
|
1518
|
-
added.push(
|
|
1519
|
-
{
|
|
1520
|
-
id: `place_${slug}`,
|
|
1521
|
-
type: "static_place",
|
|
1522
|
-
inputs: { image: source },
|
|
1523
|
-
params: {
|
|
1524
|
-
format,
|
|
1525
|
-
render_ratio: ratio,
|
|
1526
|
-
...placements ? { placements: [...placements] } : {},
|
|
1527
|
-
...copy ? { copy } : {}
|
|
1528
|
-
},
|
|
1529
|
-
tags: { role: STATIC_PLACE_ROLE }
|
|
1530
|
-
},
|
|
1531
|
-
{
|
|
1532
|
-
id: `merge_${slug}`,
|
|
1533
|
-
type: "static_extend_merge",
|
|
1534
|
-
inputs: { placed: `$ref:place_${slug}.placed`, shown: `$ref:place_${slug}.shown`, keep: `$ref:place_${slug}.keep` },
|
|
1535
|
-
params: {
|
|
1536
|
-
render_ratio: ratio,
|
|
1537
|
-
paint: {
|
|
1538
|
-
model,
|
|
1539
|
-
aspect_ratio: ratio,
|
|
1540
|
-
...params.quality !== void 0 ? { quality: params.quality } : {},
|
|
1541
|
-
...params.image_size !== void 0 ? { image_size: params.image_size } : {},
|
|
1542
|
-
prompt: EXTEND_PROMPT
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
);
|
|
1547
|
-
if (composite) logoOn.set(String(composite.id), { ...composite, inputs: { ...composite.inputs, image: `$ref:merge_${slug}.image` } });
|
|
1548
|
-
else delivered[at] = `$ref:merge_${slug}.image`;
|
|
1549
|
-
}
|
|
1550
|
-
if (added.length === 0) return canvas;
|
|
1551
|
-
const kept = nodes.filter((n) => n !== final && !logoOn.has(String(n.id)));
|
|
1552
|
-
return {
|
|
1553
|
-
...holder,
|
|
1554
|
-
nodes: [...kept, ...added, ...logoOn.values(), { ...final, inputs: { ...final.inputs, images: delivered } }]
|
|
1555
|
-
};
|
|
1556
|
-
}
|
|
1557
|
-
function placingCopy(nodes) {
|
|
1558
|
-
const told = nodes.find(
|
|
1559
|
-
(n) => (n.type === "static_safe_fit" || n.type === "static_place") && Array.isArray(n.params?.copy)
|
|
1560
|
-
)?.params?.copy;
|
|
1561
|
-
if (Array.isArray(told)) return told;
|
|
1562
|
-
const kept = nodes.find((n) => n.type === "image_aspect_adapt" && Array.isArray(n.params?.copy))?.params?.copy;
|
|
1563
|
-
return Array.isArray(kept) ? kept.filter((t) => typeof t === "string").map((text) => ({ text })) : void 0;
|
|
1564
|
-
}
|
|
1565
|
-
function deliveredRole(ref, nodes, roles) {
|
|
1566
|
-
const idOf = (r) => typeof r === "string" ? /^\$ref:([^.]+)\./.exec(r)?.[1] : void 0;
|
|
1567
|
-
const read = idOf(ref);
|
|
1568
|
-
const composite = read && roles[read] === LOGO_COMPOSITE_ROLE ? nodes.find((n) => n.id === read) : void 0;
|
|
1569
|
-
const from = composite ? idOf(composite.inputs?.image) : read;
|
|
1570
|
-
return from ? roles[from] : void 0;
|
|
1571
|
-
}
|
|
1572
|
-
function withDeliveredSizes(canvas, last) {
|
|
1573
|
-
const holder = canvas;
|
|
1574
|
-
if (!Array.isArray(holder.nodes)) return canvas;
|
|
1575
|
-
const final = holder.nodes.find((n) => n.id === "final" && n.type === "collect");
|
|
1576
|
-
const labels = final?.params?.labels;
|
|
1577
|
-
const images = final?.inputs?.images;
|
|
1578
|
-
if (!final || !Array.isArray(labels) || !Array.isArray(images)) return canvas;
|
|
1579
|
-
const ingests = [];
|
|
1580
|
-
const roles = rolesById(canvas);
|
|
1581
|
-
const delivered = images.map((ref, i) => {
|
|
1582
|
-
const format = labels[i];
|
|
1583
|
-
const file = typeof format === "string" ? last[format] : void 0;
|
|
1584
|
-
if (!file || typeof format !== "string") return ref;
|
|
1585
|
-
const id = `last_${formatSlug(format)}`;
|
|
1586
|
-
const remote = /^(?:https?|data):/.test(file);
|
|
1587
|
-
const role = deliveredRole(ref, holder.nodes ?? [], roles);
|
|
1588
|
-
ingests.push({
|
|
1589
|
-
id,
|
|
1590
|
-
type: "ingest",
|
|
1591
|
-
params: remote ? { source: "url", url: file, expect: "image" } : { source: "path", path: file, expect: "image" },
|
|
1592
|
-
...role === STATIC_MASTER_ROLE ? { tags: { role } } : {}
|
|
1593
|
-
});
|
|
1594
|
-
return `$ref:${id}.asset`;
|
|
1595
|
-
});
|
|
1596
|
-
const at = holder.nodes.indexOf(final);
|
|
1597
|
-
return {
|
|
1598
|
-
...holder,
|
|
1599
|
-
nodes: [
|
|
1600
|
-
...holder.nodes.slice(0, at),
|
|
1601
|
-
...ingests,
|
|
1602
|
-
{ ...final, inputs: { ...final.inputs, images: delivered } },
|
|
1603
|
-
...holder.nodes.slice(at + 1)
|
|
1604
|
-
]
|
|
1605
|
-
};
|
|
1606
|
-
}
|
|
1607
|
-
|
|
1608
932
|
// src/commands/canvas/voice-retake.ts
|
|
1609
933
|
var nodesOf = (graph) => {
|
|
1610
934
|
const nodes = graph?.nodes;
|
|
@@ -1645,999 +969,16 @@ function retakenTalkingScenes(previous, canvas) {
|
|
|
1645
969
|
return keptVoiceClips(canvas).filter((clip) => before.has(clip.id) && promptOf(before.get(clip.id)) !== promptOf(clip)).map((clip) => String(clip.id));
|
|
1646
970
|
}
|
|
1647
971
|
|
|
1648
|
-
// src/commands/canvas/static-
|
|
1649
|
-
import { readFile as
|
|
1650
|
-
import path6 from "path";
|
|
1651
|
-
|
|
1652
|
-
// src/commands/canvas/glance-check.ts
|
|
972
|
+
// src/commands/canvas/static-spec-repair.ts
|
|
973
|
+
import { readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
|
|
1653
974
|
import sharp from "sharp";
|
|
1654
975
|
import { z } from "zod";
|
|
1655
|
-
var
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
next_step: "unclear"
|
|
1659
|
-
};
|
|
1660
|
-
var GLANCE_WIDTH = 400;
|
|
1661
|
-
var GlanceAnswerSchema = ViewerAnswerSchema.extend({
|
|
1662
|
-
/** What kind of product or service they take it for (D4). */
|
|
1663
|
-
category: z.object({ answer: z.string().default(""), clarity: z.enum(["clear", "guess", "unclear"]).default("unclear") }).default({ answer: "", clarity: "unclear" }),
|
|
1664
|
-
stopped: z.string().default(""),
|
|
1665
|
-
me: z.enum(["yes", "no", "unsure"]).default("unsure")
|
|
1666
|
-
});
|
|
1667
|
-
function wherePhrase(placements) {
|
|
1668
|
-
const fullScreen = placements.length === 0 || placements.some((p) => /automatic|stor|reel/i.test(p));
|
|
1669
|
-
return fullScreen ? "your Instagram or Facebook feed, Stories or Reels" : "your Instagram or Facebook feed";
|
|
1670
|
-
}
|
|
1671
|
-
function knowledge(viewer) {
|
|
1672
|
-
if (!viewer.knows.includes("brand")) return "You have never heard of the advertiser.";
|
|
1673
|
-
const offer = viewer.knows.includes("offer") ? " You know roughly what they sell." : "";
|
|
1674
|
-
return `You have come across the advertiser before.${offer}`;
|
|
1675
|
-
}
|
|
1676
|
-
function buildGlancePrompt(input) {
|
|
1677
|
-
const who = input.market ? `You are ${input.market}. ` : "";
|
|
1678
|
-
return [
|
|
1679
|
-
`${who}You are scrolling ${wherePhrase(input.viewer.placements)} on your phone. ${knowledge(input.viewer)}`,
|
|
1680
|
-
"This ad passes under your thumb and holds you for about three seconds: you take in the picture and read the biggest words, not the small print. The image is shown at the size your phone shows it.",
|
|
1681
|
-
"Answer as this person, from those three seconds alone. Do not fill gaps with what ads like this usually sell.",
|
|
1682
|
-
'For each question give your answer in English and how sure you are: "clear" when the ad says it outright or you already know it; "guess" when you are piecing it together; "unclear" when you cannot tell.',
|
|
1683
|
-
"offer: what is being sold or offered?",
|
|
1684
|
-
"for_whom: who is it for?",
|
|
1685
|
-
"next_step: what would you do next if you wanted it?",
|
|
1686
|
-
"category: what kind of product or service is this for (a payroll app, a trade course, a phone)?",
|
|
1687
|
-
'missing: in one short sentence, what you would need to be told to get it; "" when nothing.',
|
|
1688
|
-
"stopped: what made you stop on it, or what nearly made you scroll past, in a few words.",
|
|
1689
|
-
'me: is this for someone like you? "yes", "no" or "unsure".',
|
|
1690
|
-
"",
|
|
1691
|
-
'Reply with only this JSON: {"offer":{"answer":"","clarity":"clear|guess|unclear"},"for_whom":{"answer":"","clarity":"clear|guess|unclear"},"next_step":{"answer":"","clarity":"clear|guess|unclear"},"category":{"answer":"","clarity":"clear|guess|unclear"},"missing":"","stopped":"","me":"yes|no|unsure"}'
|
|
1692
|
-
].join("\n");
|
|
1693
|
-
}
|
|
1694
|
-
var QUESTION_WORDS = {
|
|
1695
|
-
offer: "what is offered",
|
|
1696
|
-
for_whom: "who it is for",
|
|
1697
|
-
next_step: "what to do next"
|
|
1698
|
-
};
|
|
1699
|
-
function missWords(miss) {
|
|
1700
|
-
if (miss.question === "presumes") return `it talks to them as a customer already ("${miss.viewerSaid}")`;
|
|
1701
|
-
const said2 = miss.viewerSaid.trim() ? `"${miss.viewerSaid.trim()}"` : "nothing";
|
|
1702
|
-
const what = QUESTION_WORDS[miss.question];
|
|
1703
|
-
return miss.reason === "misread" ? `${what} (they were sure it is ${said2})` : `${what} (they said ${said2})`;
|
|
1704
|
-
}
|
|
1705
|
-
function glanceFindings(answer, intended, format, viewer, misread = { offer: false, category: false }) {
|
|
1706
|
-
const verdict = judgeViewerAnswer({ ...answer, presumes: "" }, intended, GLANCE_REQUIRED, misread.offer);
|
|
1707
|
-
const category = answer.category.answer.trim();
|
|
1708
|
-
const kind = intended.recognition && category && misread.category ? [
|
|
1709
|
-
{
|
|
1710
|
-
severity: "warning",
|
|
1711
|
-
what: `${format}: At a glance, a stranger took it for "${category}"; it is meant as ${intended.recognition}.`
|
|
1712
|
-
}
|
|
1713
|
-
] : [];
|
|
1714
|
-
if (verdict.pass) return kind;
|
|
1715
|
-
const needed = answer.missing.trim() ? ` They needed: ${answer.missing.trim().replace(/[.!]+$/, "")}.` : "";
|
|
1716
|
-
const missed = verdict.missed.map(missWords).join("; ");
|
|
1717
|
-
return [
|
|
1718
|
-
{
|
|
1719
|
-
severity: "blocking",
|
|
1720
|
-
what: `${format}: At a glance, ${describeViewer(viewer).replace(/, on .* placements$/, "")} could not tell ${missed}.${needed}`
|
|
1721
|
-
},
|
|
1722
|
-
...kind
|
|
1723
|
-
];
|
|
1724
|
-
}
|
|
1725
|
-
async function glanceMisreads(answer, intended, judge) {
|
|
1726
|
-
const sure = sureEnough(answer.offer.clarity, GLANCE_REQUIRED.offer);
|
|
1727
|
-
const [offer = false, category = false] = await misreadings(
|
|
1728
|
-
[
|
|
1729
|
-
{ said: sure ? answer.offer.answer : "", meant: intended.offer, sells: intended.sells },
|
|
1730
|
-
{ said: answer.category.answer, meant: intended.recognition }
|
|
1731
|
-
],
|
|
1732
|
-
judge
|
|
1733
|
-
);
|
|
1734
|
-
return { offer, category };
|
|
1735
|
-
}
|
|
1736
|
-
function gatewayGlanceModel(onSpend) {
|
|
1737
|
-
return (jpeg, prompt) => askAboutImages(GLANCE_CHECK_MODEL, [jpeg], prompt, onSpend);
|
|
1738
|
-
}
|
|
1739
|
-
async function glanceCheck(opts) {
|
|
1740
|
-
let jpeg;
|
|
1741
|
-
try {
|
|
1742
|
-
const bytes = await bytesOf(opts.image);
|
|
1743
|
-
jpeg = (await sharp(bytes).resize({ width: GLANCE_WIDTH }).jpeg({ quality: 85 }).toBuffer()).toString("base64");
|
|
1744
|
-
} catch {
|
|
1745
|
-
return null;
|
|
1746
|
-
}
|
|
1747
|
-
const prompt = buildGlancePrompt({ viewer: opts.viewer, ...opts.market ? { market: opts.market } : {} });
|
|
1748
|
-
for (let attempt = 0; attempt < 2; attempt++) {
|
|
1749
|
-
const parsed = GlanceAnswerSchema.safeParse(await opts.ask(jpeg, prompt));
|
|
1750
|
-
if (parsed.success) {
|
|
1751
|
-
const misread = await glanceMisreads(parsed.data, opts.intended, opts.judge ?? jevReadJudge());
|
|
1752
|
-
return glanceFindings(parsed.data, opts.intended, opts.format, opts.viewer, misread);
|
|
1753
|
-
}
|
|
1754
|
-
}
|
|
1755
|
-
return null;
|
|
1756
|
-
}
|
|
1757
|
-
|
|
1758
|
-
// src/commands/canvas/logo-review.ts
|
|
1759
|
-
import sharp2 from "sharp";
|
|
1760
|
-
|
|
1761
|
-
// src/engine/nodes/local/lib/logo-match.ts
|
|
1762
|
-
var SOLID = 250;
|
|
1763
|
-
var SAME_COLOUR = 60;
|
|
1764
|
-
var LOGO_MATCH = 0.98;
|
|
1765
|
-
var DRAWN_LOGO_MATCH = 0.9;
|
|
1766
|
-
var COARSE_WIDTH = 180;
|
|
1767
|
-
var MIN_SHOWN = 0.4;
|
|
1768
|
-
var MAIN_COLOUR = 0.12;
|
|
1769
|
-
var INK_NEAR = 90;
|
|
1770
|
-
function inkColours(logo) {
|
|
1771
|
-
const bins = /* @__PURE__ */ new Map();
|
|
1772
|
-
let total = 0;
|
|
1773
|
-
for (let i = 0; i < logo.width * logo.height; i++) {
|
|
1774
|
-
if ((logo.data[i * 4 + 3] ?? 0) < SOLID) continue;
|
|
1775
|
-
const r = logo.data[i * 4] ?? 0;
|
|
1776
|
-
const g = logo.data[i * 4 + 1] ?? 0;
|
|
1777
|
-
const b = logo.data[i * 4 + 2] ?? 0;
|
|
1778
|
-
const key = r >> 5 << 6 | g >> 5 << 3 | b >> 5;
|
|
1779
|
-
const bin = bins.get(key) ?? { n: 0, r: 0, g: 0, b: 0 };
|
|
1780
|
-
bins.set(key, { n: bin.n + 1, r: bin.r + r, g: bin.g + g, b: bin.b + b });
|
|
1781
|
-
total++;
|
|
1782
|
-
}
|
|
1783
|
-
return [...bins.values()].filter((b) => b.n >= MAIN_COLOUR * total).map((b) => [b.r / b.n, b.g / b.n, b.b / b.n]);
|
|
1784
|
-
}
|
|
1785
|
-
function mapOf(img, f, test) {
|
|
1786
|
-
const width = Math.max(1, Math.floor(img.width / f));
|
|
1787
|
-
const height = Math.max(1, Math.floor(img.height / f));
|
|
1788
|
-
const map = new Uint8Array(width * height);
|
|
1789
|
-
for (let y = 0; y < height; y++) {
|
|
1790
|
-
for (let x = 0; x < width; x++) map[y * width + x] = cellOn(img.width, f, x * f, y * f, test) ? 1 : 0;
|
|
1791
|
-
}
|
|
1792
|
-
return { map, width, height };
|
|
1793
|
-
}
|
|
1794
|
-
function cellOn(width, f, x0, y0, test) {
|
|
1795
|
-
let on = 0;
|
|
1796
|
-
for (let j = 0; j < f; j++) {
|
|
1797
|
-
for (let i = 0; i < f; i++) on += test((y0 + j) * width + x0 + i) ? 1 : 0;
|
|
1798
|
-
}
|
|
1799
|
-
return on * 2 >= f * f;
|
|
1800
|
-
}
|
|
1801
|
-
function inkMapOf(image, colours, f) {
|
|
1802
|
-
return mapOf(image, f, (i) => colours.some((c) => distance(image.data, i * 4, c, 0) < INK_NEAR));
|
|
1803
|
-
}
|
|
1804
|
-
var maskOf = (logo, f) => mapOf(logo, f, (i) => (logo.data[i * 4 + 3] ?? 0) >= 128);
|
|
1805
|
-
function summed(m) {
|
|
1806
|
-
const w = m.width + 1;
|
|
1807
|
-
const sum = new Int32Array(w * (m.height + 1));
|
|
1808
|
-
for (let y = 0; y < m.height; y++) {
|
|
1809
|
-
let row = 0;
|
|
1810
|
-
for (let x = 0; x < m.width; x++) {
|
|
1811
|
-
row += m.map[y * m.width + x] ?? 0;
|
|
1812
|
-
sum[(y + 1) * w + x + 1] = (sum[y * w + x + 1] ?? 0) + row;
|
|
1813
|
-
}
|
|
1814
|
-
}
|
|
1815
|
-
return { ...m, sum };
|
|
1816
|
-
}
|
|
1817
|
-
function inkIn(m, x0, y0, x1, y1) {
|
|
1818
|
-
const w = m.width + 1;
|
|
1819
|
-
const [a, b] = [Math.max(0, x0), Math.min(m.width, x1)];
|
|
1820
|
-
const [c, d] = [Math.max(0, y0), Math.min(m.height, y1)];
|
|
1821
|
-
if (a >= b || c >= d) return 0;
|
|
1822
|
-
return (m.sum[d * w + b] ?? 0) - (m.sum[c * w + b] ?? 0) - (m.sum[d * w + a] ?? 0) + (m.sum[c * w + a] ?? 0);
|
|
1823
|
-
}
|
|
1824
|
-
function cellsOf(m) {
|
|
1825
|
-
const rows = [];
|
|
1826
|
-
const x0s = [];
|
|
1827
|
-
const x1s = [];
|
|
1828
|
-
for (let y = 0; y < m.height; y++) {
|
|
1829
|
-
for (let x = 0; x < m.width; x++) {
|
|
1830
|
-
if (!m.map[y * m.width + x]) continue;
|
|
1831
|
-
const start = x;
|
|
1832
|
-
while (x < m.width && m.map[y * m.width + x]) x++;
|
|
1833
|
-
rows.push(y);
|
|
1834
|
-
x0s.push(start);
|
|
1835
|
-
x1s.push(x);
|
|
1836
|
-
}
|
|
1837
|
-
}
|
|
1838
|
-
const mask = summed(m);
|
|
1839
|
-
return {
|
|
1840
|
-
rows: Int32Array.from(rows),
|
|
1841
|
-
x0s: Int32Array.from(x0s),
|
|
1842
|
-
x1s: Int32Array.from(x1s),
|
|
1843
|
-
mask,
|
|
1844
|
-
area: inkIn(mask, 0, 0, m.width, m.height),
|
|
1845
|
-
width: m.width,
|
|
1846
|
-
height: m.height
|
|
1847
|
-
};
|
|
1848
|
-
}
|
|
1849
|
-
var fitScore = (inter, inside, win, area) => inter / (inside + win - inter) * Math.sqrt(inside / area);
|
|
1850
|
-
function fitAt(ink, cells, x, y, floor = 0) {
|
|
1851
|
-
const inside = inkIn(cells.mask, -x, -y, ink.width - x, ink.height - y);
|
|
1852
|
-
if (inside < MIN_SHOWN * cells.area) return 0;
|
|
1853
|
-
const win = inkIn(ink, x, y, x + cells.width, y + cells.height);
|
|
1854
|
-
if (fitScore(Math.min(inside, win), inside, win, cells.area) <= floor) return 0;
|
|
1855
|
-
let inter = 0;
|
|
1856
|
-
for (let k = 0; k < cells.rows.length; k++) {
|
|
1857
|
-
const v = y + (cells.rows[k] ?? 0);
|
|
1858
|
-
inter += inkIn(ink, x + (cells.x0s[k] ?? 0), v, x + (cells.x1s[k] ?? 0), v + 1);
|
|
1859
|
-
}
|
|
1860
|
-
return fitScore(inter, inside, win, cells.area);
|
|
1861
|
-
}
|
|
1862
|
-
function bestFit(ink, cells, xs, ys, step = 1) {
|
|
1863
|
-
let best = { x: 0, y: 0, score: 0 };
|
|
1864
|
-
if (cells.area === 0) return best;
|
|
1865
|
-
for (let y = ys[0]; y <= ys[1]; y += step) {
|
|
1866
|
-
for (let x = xs[0]; x <= xs[1]; x += step) {
|
|
1867
|
-
const score = fitAt(ink, cells, x, y, best.score);
|
|
1868
|
-
if (score > best.score) best = { x, y, score };
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
return best;
|
|
1872
|
-
}
|
|
1873
|
-
function locateLogo(image, templates) {
|
|
1874
|
-
const first = templates[0];
|
|
1875
|
-
if (!first) return null;
|
|
1876
|
-
const colours = inkColours(templates[templates.length - 1] ?? first);
|
|
1877
|
-
if (colours.length === 0) return null;
|
|
1878
|
-
const f = Math.max(1, Math.round(image.width / COARSE_WIDTH));
|
|
1879
|
-
const found = coarseFind(summed(inkMapOf(image, colours, f)), templates, f);
|
|
1880
|
-
if (!found || found.score === 0) return null;
|
|
1881
|
-
if (f === 1) {
|
|
1882
|
-
const t = templates[found.template];
|
|
1883
|
-
return { x: found.x, y: found.y, width: t.width, height: t.height, template: found.template, score: found.score };
|
|
1884
|
-
}
|
|
1885
|
-
return fineFind(summed(inkMapOf(image, colours, 1)), templates, found, f);
|
|
1886
|
-
}
|
|
1887
|
-
function coarseFind(coarse, templates, f) {
|
|
1888
|
-
let found = null;
|
|
1889
|
-
templates.forEach((t, k) => {
|
|
1890
|
-
const cells = cellsOf(maskOf(t, f));
|
|
1891
|
-
const reachX = Math.round(cells.width * (1 - MIN_SHOWN));
|
|
1892
|
-
const reachY = Math.round(cells.height * (1 - MIN_SHOWN));
|
|
1893
|
-
const fit = bestFit(
|
|
1894
|
-
coarse,
|
|
1895
|
-
cells,
|
|
1896
|
-
[-reachX, coarse.width - cells.width + reachX],
|
|
1897
|
-
[-reachY, coarse.height - cells.height + reachY]
|
|
1898
|
-
);
|
|
1899
|
-
if (!found || fit.score > found.score) found = { template: k, ...fit };
|
|
1900
|
-
});
|
|
1901
|
-
return found;
|
|
1902
|
-
}
|
|
1903
|
-
function fineFind(full, templates, found, f) {
|
|
1904
|
-
let fine = null;
|
|
1905
|
-
const [cx, cy] = [found.x * f, found.y * f];
|
|
1906
|
-
for (const k of [-2, -1, 0, 1, 2].map((d) => found.template + d)) {
|
|
1907
|
-
const t = templates[k];
|
|
1908
|
-
if (!t) continue;
|
|
1909
|
-
const cells = cellsOf(maskOf(t, 1));
|
|
1910
|
-
const near = bestFit(full, cells, [cx - 2 * f, cx + 2 * f], [cy - 2 * f, cy + 2 * f], 3);
|
|
1911
|
-
const fit = bestFit(full, cells, [near.x - 2, near.x + 2], [near.y - 2, near.y + 2]);
|
|
1912
|
-
if (!fine || fit.score > fine.score)
|
|
1913
|
-
fine = { x: fit.x, y: fit.y, width: t.width, height: t.height, template: k, score: fit.score };
|
|
1914
|
-
}
|
|
1915
|
-
return fine;
|
|
1916
|
-
}
|
|
1917
|
-
var distance = (a, i, b, j) => Math.hypot((a[i] ?? 0) - (b[j] ?? 0), (a[i + 1] ?? 0) - (b[j + 1] ?? 0), (a[i + 2] ?? 0) - (b[j + 2] ?? 0));
|
|
1918
|
-
function logoAgreement(image, logo, at) {
|
|
1919
|
-
let solid = 0;
|
|
1920
|
-
let same = 0;
|
|
1921
|
-
for (let j = 0; j < logo.height; j++) {
|
|
1922
|
-
for (let i = 0; i < logo.width; i++) {
|
|
1923
|
-
const s = (j * logo.width + i) * 4;
|
|
1924
|
-
if ((logo.data[s + 3] ?? 0) < SOLID) continue;
|
|
1925
|
-
solid++;
|
|
1926
|
-
const u = at.x + i;
|
|
1927
|
-
const v = at.y + j;
|
|
1928
|
-
if (u < 0 || v < 0 || u >= image.width || v >= image.height) continue;
|
|
1929
|
-
if (distance(image.data, (v * image.width + u) * 4, logo.data, s) < SAME_COLOUR) same++;
|
|
1930
|
-
}
|
|
1931
|
-
}
|
|
1932
|
-
return solid === 0 ? 0 : same / solid;
|
|
1933
|
-
}
|
|
1934
|
-
|
|
1935
|
-
// src/commands/canvas/logo-review.ts
|
|
1936
|
-
var nodesOf2 = (parsed) => {
|
|
1937
|
-
const nodes = parsed?.nodes;
|
|
1938
|
-
return Array.isArray(nodes) ? nodes : [];
|
|
1939
|
-
};
|
|
1940
|
-
var refId = (ref) => typeof ref === "string" ? ref.match(/^\$ref:([a-z][a-z0-9_]*)\./)?.[1] ?? null : null;
|
|
1941
|
-
var edgesSaid = (edges) => edges.join(" and ") || "edge";
|
|
1942
|
-
var sizeId = formatSlug;
|
|
1943
|
-
function wordsNodeOf(nodes, composite, format) {
|
|
1944
|
-
let ref = composite?.inputs?.image;
|
|
1945
|
-
for (let hops = 0; hops < 12; hops++) {
|
|
1946
|
-
const n = nodes.find((m) => m.id === refId(ref));
|
|
1947
|
-
if (!n) break;
|
|
1948
|
-
if (n.type === "static_format" || n.type === "image_generate") return String(n.id);
|
|
1949
|
-
if (n.type === "static_prefilter") return null;
|
|
1950
|
-
ref = n.inputs?.image;
|
|
1951
|
-
}
|
|
1952
|
-
return `format_${sizeId(format)}`;
|
|
1953
|
-
}
|
|
1954
|
-
function saidOfRoom(format, defect, corner, words = `format_${sizeId(format)}`) {
|
|
1955
|
-
const kind = { item: "logo", element: "logo", defect: "other", edges: [] };
|
|
1956
|
-
const room = words === null ? `keep the ${corner} plain for the logo, with no word, button or card in it (a \`--fix\` of the chosen picture).` : `run \`baker canvas run \u2026 --regenerate ${words}\` and keep the ${corner} clear for the logo.`;
|
|
1957
|
-
const what = defect === "no_room" ? `${format}: there is no room for the logo, not even on a small plate; ${room}` : `${format}: the logo is lost on the picture under it; run \`--regenerate logo_${sizeId(format)}\` so it is set on a plate.`;
|
|
1958
|
-
return { severity: "blocking", what, kind };
|
|
1959
|
-
}
|
|
1960
|
-
function said(format, p, corner = logoCornerWords(void 0), words) {
|
|
1961
|
-
if (p.defect === "no_room" || p.defect === "illegible") return saidOfRoom(format, p.defect, corner, words);
|
|
1962
|
-
const kind = (item, element, defect) => ({
|
|
1963
|
-
item,
|
|
1964
|
-
element,
|
|
1965
|
-
defect,
|
|
1966
|
-
edges: p.defect === "cut" ? [...p.edges] : []
|
|
1967
|
-
});
|
|
1968
|
-
const blocking = (what, k) => ({
|
|
1969
|
-
severity: "blocking",
|
|
1970
|
-
what: `${format}: ${what}`,
|
|
1971
|
-
kind: k
|
|
1972
|
-
});
|
|
1973
|
-
if (p.element === "logo") {
|
|
1974
|
-
return p.defect === "cut" ? blocking(
|
|
1975
|
-
`the frame cuts the logo at its ${edgesSaid(p.edges)}; place it again inside the frame.`,
|
|
1976
|
-
kind("logo", "logo", "cut")
|
|
1977
|
-
) : blocking(
|
|
1978
|
-
`the logo reaches past the ${edgesSaid(p.edges)} of the part of the frame the app leaves clear; place it again inside it.`,
|
|
1979
|
-
kind("safe_zone", "logo", "other")
|
|
1980
|
-
);
|
|
1981
|
-
}
|
|
1982
|
-
if (p.defect === "under_logo") {
|
|
1983
|
-
const what = p.element === "headline" ? "the headline" : "a line of the copy";
|
|
1984
|
-
return blocking(
|
|
1985
|
-
`the logo covers ${what}; set the words again clear of the logo's corner.`,
|
|
1986
|
-
kind("layout", "copy", "other")
|
|
1987
|
-
);
|
|
1988
|
-
}
|
|
1989
|
-
return p.defect === "cut" ? blocking(
|
|
1990
|
-
`the frame cuts the headline at its ${edgesSaid(p.edges)}; set the words again inside the frame.`,
|
|
1991
|
-
kind("layout", "copy", "cut")
|
|
1992
|
-
) : blocking(
|
|
1993
|
-
`the headline reaches past the ${edgesSaid(p.edges)} of the part of the frame the app leaves clear; set the words again inside it.`,
|
|
1994
|
-
kind("safe_zone", "copy", "other")
|
|
1995
|
-
);
|
|
1996
|
-
}
|
|
1997
|
-
function logoPlacementFindings(parsed, outputsByNode) {
|
|
1998
|
-
return nodesWithRole(parsed, LOGO_COMPOSITE_ROLE).flatMap((n) => {
|
|
1999
|
-
const facts = LogoFacts.safeParse(outputsByNode[n.id]?.facts);
|
|
2000
|
-
if (!facts.success) return [];
|
|
2001
|
-
const { format, slot, problems } = facts.data;
|
|
2002
|
-
const kept = problems.some((p) => p.defect === "no_room") ? slotPosition(slot, deliveredSize(format)) : void 0;
|
|
2003
|
-
const corner = logoCornerWords(kept ?? n.params?.position);
|
|
2004
|
-
const words = wordsNodeOf(nodesOf2(parsed), n, facts.data.format);
|
|
2005
|
-
return facts.data.problems.map((p) => said(facts.data.format, p, corner, words));
|
|
2006
|
-
});
|
|
2007
|
-
}
|
|
2008
|
-
async function rgbaOf(bytes) {
|
|
2009
|
-
const { data, info } = await sharp2(bytes).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
2010
|
-
return { data, width: info.width, height: info.height };
|
|
2011
|
-
}
|
|
2012
|
-
async function ingestBytes(ref, outputsByNode) {
|
|
2013
|
-
const id = refId(ref);
|
|
2014
|
-
const asset = id ? outputsByNode[id]?.asset : void 0;
|
|
2015
|
-
const source = await textColourSource(asset?.metadata);
|
|
2016
|
-
if (source) return source;
|
|
2017
|
-
const at = typeof asset?.path === "string" ? asset.path : typeof asset?.url === "string" ? asset.url : null;
|
|
2018
|
-
return at ? await bytesOf(at).catch(() => null) : null;
|
|
2019
|
-
}
|
|
2020
|
-
var LOGO_FOUND = 0.6;
|
|
2021
|
-
var pct2 = (v) => `${Math.round(v * 100)}%`;
|
|
2022
|
-
function mismatch(format, agreement) {
|
|
2023
|
-
return {
|
|
2024
|
-
severity: "blocking",
|
|
2025
|
-
what: `${format}: the logo is not the brand's file as it is (redrawn or altered: ${pct2(agreement)} of it matches the file); run it again so the file itself is placed.`,
|
|
2026
|
-
kind: { item: "logo", element: "logo", defect: "other", edges: [] }
|
|
2027
|
-
};
|
|
2028
|
-
}
|
|
2029
|
-
function drawnMismatch(format, agreement) {
|
|
2030
|
-
return {
|
|
2031
|
-
severity: "blocking",
|
|
2032
|
-
what: `${format}: the logo drawn is not the brand's logo (only ${pct2(agreement)} of it matches the file); draw this size again with the brand's logo copied exactly from the logo file, letter for letter.`,
|
|
2033
|
-
kind: { item: "logo", element: "logo", defect: "other", edges: [] }
|
|
2034
|
-
};
|
|
2035
|
-
}
|
|
2036
|
-
function searchWidths(frameWidth) {
|
|
2037
|
-
const widths = [];
|
|
2038
|
-
for (let w = frameWidth * 0.08; w <= frameWidth * 0.45; w *= 1.04) widths.push(Math.round(w));
|
|
2039
|
-
return widths;
|
|
2040
|
-
}
|
|
2041
|
-
async function placedLogoFinding(n, outputsByNode, images) {
|
|
2042
|
-
const facts = LogoFacts.safeParse(outputsByNode[String(n.id)]?.facts);
|
|
2043
|
-
if (!facts.success || facts.data.problems.some((p) => p.defect === "no_room")) return [];
|
|
2044
|
-
const { format, box, variant, ink } = facts.data;
|
|
2045
|
-
const image = images.find((i) => i.format === format);
|
|
2046
|
-
const logos = Array.isArray(n.inputs?.logos) ? n.inputs.logos : [];
|
|
2047
|
-
const [ad, file] = await Promise.all([
|
|
2048
|
-
image ? bytesOf(image.path).catch(() => null) : null,
|
|
2049
|
-
ingestBytes(logos[variant], outputsByNode)
|
|
2050
|
-
]);
|
|
2051
|
-
if (!ad || !file) return [];
|
|
2052
|
-
const placed = await fitArtwork(await logoArtwork(file, ink ? { currentColor: ink } : {}), box);
|
|
2053
|
-
const agreement = logoAgreement(await rgbaOf(ad), placed, box);
|
|
2054
|
-
return agreement < LOGO_MATCH ? [mismatch(format, agreement)] : [];
|
|
2055
|
-
}
|
|
2056
|
-
async function drawnLogoOn(picture, arts) {
|
|
2057
|
-
let best = null;
|
|
2058
|
-
for (const art of arts) {
|
|
2059
|
-
if (!art) continue;
|
|
2060
|
-
const templates = await Promise.all(
|
|
2061
|
-
searchWidths(picture.width).map((w) => fitArtwork(art, { width: w, height: picture.height }))
|
|
2062
|
-
);
|
|
2063
|
-
const at = locateLogo(picture, templates);
|
|
2064
|
-
if (!at || at.score < LOGO_FOUND || best && best.score >= at.score) continue;
|
|
2065
|
-
best = { agreement: logoAgreement(picture, templates[at.template], at), box: at, score: at.score };
|
|
2066
|
-
}
|
|
2067
|
-
return best;
|
|
2068
|
-
}
|
|
2069
|
-
var NO_MARGIN = { top: 0, bottom: 0, left: 0, right: 0 };
|
|
2070
|
-
async function artworksOf(file, inks) {
|
|
2071
|
-
const colours = usesTextColour(file) ? inks : [void 0];
|
|
2072
|
-
return await Promise.all(colours.map((ink) => logoArtwork(file, ink ? { currentColor: ink } : {}).catch(() => null)));
|
|
2073
|
-
}
|
|
2074
|
-
async function drawnLogoFinding(image, arts) {
|
|
2075
|
-
const ad = await bytesOf(image.path).catch(() => null);
|
|
2076
|
-
if (!ad) return [];
|
|
2077
|
-
const picture = await rgbaOf(ad);
|
|
2078
|
-
const drawn = await drawnLogoOn(picture, arts);
|
|
2079
|
-
if (!drawn) return [];
|
|
2080
|
-
const frame2 = { width: picture.width, height: picture.height };
|
|
2081
|
-
const cut = placementProblems({ frame: frame2, safe: NO_MARGIN, logo: drawn.box });
|
|
2082
|
-
if (cut.length > 0) return cut.map((p) => said(image.format, p));
|
|
2083
|
-
return drawn.agreement < DRAWN_LOGO_MATCH ? [drawnMismatch(image.format, drawn.agreement)] : [];
|
|
2084
|
-
}
|
|
2085
|
-
async function deliveredLogoFindings(parsed, outputsByNode, images, inks = ["#000000", "#FFFFFF"]) {
|
|
2086
|
-
const nodes = nodesOf2(parsed);
|
|
2087
|
-
const composites = nodes.filter((n) => n.tags?.role === LOGO_COMPOSITE_ROLE && n.type === "static_logo");
|
|
2088
|
-
if (composites.length > 0) {
|
|
2089
|
-
return (await Promise.all(composites.map((n) => placedLogoFinding(n, outputsByNode, images)))).flat();
|
|
2090
|
-
}
|
|
2091
|
-
const logos = nodes.filter((n) => n.type === "ingest" && /^brand_logo/.test(String(n.tags?.role ?? "")));
|
|
2092
|
-
const files = await Promise.all(logos.map((n) => ingestBytes(`$ref:${String(n.id)}.asset`, outputsByNode)));
|
|
2093
|
-
const arts = (await Promise.all(files.map((f) => f ? artworksOf(f, inks) : []))).flat();
|
|
2094
|
-
if (!arts.some((a) => a !== null)) return [];
|
|
2095
|
-
const asIs = deliveredAsIs(nodes);
|
|
2096
|
-
const drawn = images.filter((i) => !asIs.has(i.format));
|
|
2097
|
-
return (await Promise.all(drawn.map((image) => drawnLogoFinding(image, arts)))).flat();
|
|
2098
|
-
}
|
|
2099
|
-
function deliveredAsIs(nodes) {
|
|
2100
|
-
const final = nodes.find((n) => n.id === "final" && n.type === "collect");
|
|
2101
|
-
const labels = final?.params?.labels;
|
|
2102
|
-
const images = final?.inputs?.images;
|
|
2103
|
-
if (!Array.isArray(labels) || !Array.isArray(images)) return /* @__PURE__ */ new Set();
|
|
2104
|
-
return new Set(
|
|
2105
|
-
labels.filter((label, i) => {
|
|
2106
|
-
const from = nodes.find((n) => n.id === refId(images[i]));
|
|
2107
|
-
return typeof label === "string" && from?.type === "ingest";
|
|
2108
|
-
})
|
|
2109
|
-
);
|
|
2110
|
-
}
|
|
2111
|
-
|
|
2112
|
-
// src/commands/canvas/static-run-review.ts
|
|
2113
|
-
function imagesOf(output) {
|
|
2114
|
-
const list = Array.isArray(output) ? output : [output];
|
|
2115
|
-
const images = list.filter((o) => Boolean(o) && typeof o === "object");
|
|
2116
|
-
return images.length > 0 && images.every((i) => i.kind === "image") ? images : null;
|
|
2117
|
-
}
|
|
2118
|
-
function promptPathOf(parsed) {
|
|
2119
|
-
const nodes = parsed?.nodes;
|
|
2120
|
-
if (!Array.isArray(nodes)) return null;
|
|
2121
|
-
const prompt = nodes.find((n) => n?.id === "prompt" && n?.type === "ingest");
|
|
2122
|
-
const p = prompt?.params;
|
|
2123
|
-
return p?.source === "path" && p.expect === "json" && typeof p.path === "string" ? p.path : null;
|
|
2124
|
-
}
|
|
2125
|
-
function staticReviewTargets(parsed, output) {
|
|
2126
|
-
const promptPath = promptPathOf(parsed);
|
|
2127
|
-
const images = imagesOf(output);
|
|
2128
|
-
if (!promptPath || !images) return null;
|
|
2129
|
-
const labels = finalOutputLabelsFromCanvas(parsed)?.labels ?? [];
|
|
2130
|
-
return {
|
|
2131
|
-
promptPath,
|
|
2132
|
-
// A local file when the run downloaded it, else its durable URL.
|
|
2133
|
-
images: images.flatMap((image, i) => {
|
|
2134
|
-
const source = typeof image.path === "string" ? image.path : typeof image.url === "string" ? image.url : null;
|
|
2135
|
-
return source ? [{ path: source, format: labels[i] ?? "" }] : [];
|
|
2136
|
-
})
|
|
2137
|
-
};
|
|
2138
|
-
}
|
|
2139
|
-
function nodesOf3(parsed) {
|
|
2140
|
-
const nodes = parsed?.nodes;
|
|
2141
|
-
return Array.isArray(nodes) ? nodes : [];
|
|
2142
|
-
}
|
|
2143
|
-
var refId2 = (ref) => typeof ref === "string" ? ref.match(/^\$ref:([a-z][a-z0-9_]*)\./)?.[1] ?? null : null;
|
|
2144
|
-
var hasRole = (n, role) => n.tags?.role === role;
|
|
2145
|
-
function variantCount(nodes) {
|
|
2146
|
-
const calls = nodes.filter((n) => hasRole(n, STATIC_VARIANT_CALL_ROLE)).length;
|
|
2147
|
-
if (calls > 0) return calls;
|
|
2148
|
-
const one = nodes.find((n) => hasRole(n, STATIC_VARIANTS_ROLE) && n.type === "image_generate");
|
|
2149
|
-
if (one) return typeof one.params?.n === "number" ? one.params.n : 1;
|
|
2150
|
-
if (nodes.some((n) => hasRole(n, STATIC_FIX_ROLE))) return 1;
|
|
2151
|
-
return nodes.filter((n) => n.type === "image_generate" && /^ad(_[a-z])?$/.test(String(n.id))).length;
|
|
2152
|
-
}
|
|
2153
|
-
function staticRunShape(parsed) {
|
|
2154
|
-
const nodes = nodesOf3(parsed);
|
|
2155
|
-
const renders = nodes.filter((n) => n.type === "image_generate" && typeof n.id === "string");
|
|
2156
|
-
const candidates = variantCount(nodes);
|
|
2157
|
-
const logoIds = new Set(nodes.filter((n) => hasRole(n, BRAND_LOGO_ROLE)).map((n) => String(n.id)));
|
|
2158
|
-
const logo = nodes.some((n) => hasRole(n, LOGO_COMPOSITE_ROLE)) || renders.some((n) => {
|
|
2159
|
-
const refs = n.inputs?.reference;
|
|
2160
|
-
return (Array.isArray(refs) ? refs : [refs]).some((r) => logoIds.has(refId2(r) ?? ""));
|
|
2161
|
-
}) || // On one picture each size's words call places the logo file.
|
|
2162
|
-
nodes.some((n) => n.type === "static_format" && logoIds.has(refId2(n.inputs?.logo) ?? ""));
|
|
2163
|
-
const masterId = nodes.find((n) => hasRole(n, STATIC_MASTER_ROLE))?.id;
|
|
2164
|
-
const adapt = nodes.find((n) => hasRole(n, STATIC_ADAPT_ROLE));
|
|
2165
|
-
return {
|
|
2166
|
-
candidates,
|
|
2167
|
-
judged: candidates > 1 && nodes.some(
|
|
2168
|
-
(n) => n.type === "image_select" && (hasRole(n, STATIC_PICK_ROLE) || n.id === "pick") || hasRole(n, VARIANT_PREFILTER_ROLE) && typeof n.params?.judge_model === "string"
|
|
2169
|
-
),
|
|
2170
|
-
relays: masterId !== void 0 ? 0 : Math.max(0, renders.length - candidates),
|
|
2171
|
-
cuts: nodes.filter((n) => {
|
|
2172
|
-
const from = refId2(n.inputs?.image);
|
|
2173
|
-
return hasRole(n, STATIC_SIZE_ROLE) && from !== null && from === masterId;
|
|
2174
|
-
}).length,
|
|
2175
|
-
relaid: nodes.filter((n) => hasRole(n, STATIC_ADAPT_FORMAT_ROLE)).length,
|
|
2176
|
-
adapted: Array.isArray(adapt?.params?.formats) ? adapt.params.formats.length : 0,
|
|
2177
|
-
plates: nodes.some((n) => hasRole(n, STATIC_LEAD_ROLE)) ? nodes.filter((n) => hasRole(n, STATIC_VARIANT_CALL_ROLE)).length : 0,
|
|
2178
|
-
// The lead the master delivers is the chosen option's own words, replayed: not a size set again.
|
|
2179
|
-
worded: nodes.filter((n) => hasRole(n, STATIC_FORMAT_ROLE) && n.id !== masterReads(nodes)).length,
|
|
2180
|
-
logo
|
|
2181
|
-
};
|
|
2182
|
-
}
|
|
2183
|
-
function masterReads(nodes) {
|
|
2184
|
-
return refId2(nodes.find((n) => hasRole(n, STATIC_MASTER_ROLE))?.inputs?.image);
|
|
2185
|
-
}
|
|
2186
|
-
function shapeHint(shape, copy) {
|
|
2187
|
-
const drawn = shape.plates > 0 ? " (a picture each without the ad's words, the lead size's words set on it)" : "";
|
|
2188
|
-
const variants = `${shape.candidates} variant${shape.candidates === 1 ? "" : "s"} rendered${drawn}${shape.judged ? ", ranked by the checks with a judge on a tie" : ", no judge"}`;
|
|
2189
|
-
const sizes = [
|
|
2190
|
-
...shape.worded > 0 ? [`${shape.worded} size${shape.worded === 1 ? "" : "s"} cut from the chosen picture with ${shape.worded === 1 ? "its" : "their"} words set for ${shape.worded === 1 ? "it" : "them"} (one request each)`] : [],
|
|
2191
|
-
...shape.relaid > 0 ? [`${shape.relaid} size${shape.relaid === 1 ? "" : "s"} re-laid out from the chosen picture (one request each)`] : [],
|
|
2192
|
-
...shape.cuts > 0 ? [`${shape.cuts} size${shape.cuts === 1 ? "" : "s"} cut from the chosen picture`] : [],
|
|
2193
|
-
...shape.adapted > 0 ? [`${shape.adapted} adapted from it`] : [],
|
|
2194
|
-
...shape.relays > 0 ? [`${shape.relays} other format${shape.relays === 1 ? "" : "s"} re-laid from the winner`] : []
|
|
2195
|
-
];
|
|
2196
|
-
const text = copy === 0 ? "no copy (the picture is the ad)" : "the copy set by the model and read back word for word";
|
|
2197
|
-
return `This run: ${variants}${sizes.length > 0 ? `; ${sizes.join("; ")}` : ""}; ${text}; ${shape.logo ? "the brand logo on the ad from its real file" : "no logo"}.`;
|
|
2198
|
-
}
|
|
2199
|
-
var PAID_FOR = {
|
|
2200
|
-
edit: "one edit of the version shown",
|
|
2201
|
-
sizes: "only the sizes asked for, laid out again",
|
|
2202
|
-
options: "new options from scratch, every size made from the one chosen"
|
|
2203
|
-
};
|
|
2204
|
-
function runCostHint(stats, kind) {
|
|
2205
|
-
if (!stats) return null;
|
|
2206
|
-
const cached = stats.cached_nodes > 0 ? ` (${stats.cached_nodes} of ${stats.total_nodes} steps came from the cache, free)` : "";
|
|
2207
|
-
return `This run cost ${Math.round(stats.total_credits)} credits: ${PAID_FOR[kind]}${cached}.`;
|
|
2208
|
-
}
|
|
2209
|
-
async function textOf(ref) {
|
|
2210
|
-
const r = ref;
|
|
2211
|
-
try {
|
|
2212
|
-
if (typeof r?.path === "string") return await readFile4(r.path, "utf8");
|
|
2213
|
-
if (typeof r?.url === "string") {
|
|
2214
|
-
const res = await fetch(r.url);
|
|
2215
|
-
return res.ok ? await res.text() : null;
|
|
2216
|
-
}
|
|
2217
|
-
} catch {
|
|
2218
|
-
return null;
|
|
2219
|
-
}
|
|
2220
|
-
return null;
|
|
2221
|
-
}
|
|
2222
|
-
function sizeShapeOf(canvas) {
|
|
2223
|
-
return isPlateCanvas(canvas) ? "plate" : "relayout";
|
|
2224
|
-
}
|
|
2225
|
-
function oneSizeFix(shape) {
|
|
2226
|
-
return shape === "plate" ? "`baker canvas run \u2026 --regenerate format_<size>` (for example `format_9x16`) sets that size's words again on the same picture (one request)" : "`baker canvas run \u2026 --regenerate adapt_<size>` (for example `adapt_9x16`) lays out that size again from the same picture (one request)";
|
|
2227
|
-
}
|
|
2228
|
-
function fixHint(shape) {
|
|
2229
|
-
return `One thing wrong in a version that is otherwise right: \`baker canvas run \u2026 --fix "<what to change>"\` edits that version and changes only that, keeping the picture, the layout and the other words (one render). Wrong or missing words: check the lines in prompt.json \`copy\` are exactly what should be printed, shorten a line the model keeps breaking, and re-run: a change only to copy, positions or colours is made as an edit of the version shown. Wrong picture, colour or subject: edit prompt.json's \`scene\`, \`colors\` or \`references\`. Layout or a logo drawn wrong: say in each line's \`position\` (and \`scene.layout\`) where it sits, by what is around it. A right prompt that rolled badly: \`baker canvas run \u2026 --regenerate static_variants\` renders new options (every size follows from the new pick). One size wrong while the chosen picture is right (words cut or too small, the button small, something drawn twice): ${oneSizeFix(shape)}.`;
|
|
2230
|
-
}
|
|
2231
|
-
function verdictHints(verdict, shape = "plate") {
|
|
2232
|
-
if (verdict === "needs_fixes") {
|
|
2233
|
-
const cost = shape === "plate" ? "each size's words take one request" : "each re-laid-out size takes one request; a cut is free";
|
|
2234
|
-
return [
|
|
2235
|
-
`NOT READY: the finished ad has blocking problems. Do not present it as done, and never ask the person whether to fix them: fix them now, inside this version. A defect in a version that is otherwise right is a \`--fix\`: it edits the chosen picture only, and every size is made from it again (${cost}). The same defect after a fix means the fix does not work: change the spec (prompt.json) or the approach, never the same retry. If it still cannot be fixed, show the person the best version and say in one plain sentence what is left, in their words ("the logo sits where Stories covers it"), without a question; never record your own checks as their feedback.`,
|
|
2236
|
-
fixHint(shape)
|
|
2237
|
-
];
|
|
2238
|
-
}
|
|
2239
|
-
if (verdict === "not_reviewed") {
|
|
2240
|
-
return [
|
|
2241
|
-
"The finished ad was NOT reviewed: no model gateway key here, or the review model did not answer twice. Look at every word of every format yourself before showing it, or re-run the same command (every node comes from the cache) to review it again."
|
|
2242
|
-
];
|
|
2243
|
-
}
|
|
2244
|
-
if (verdict === "ready") {
|
|
2245
|
-
return ["Reviewed every format of the finished ad: every word read back exactly, nothing to fix.", SHOW_IT];
|
|
2246
|
-
}
|
|
2247
|
-
return verdict === "ready_with_notes" ? [SHOW_IT] : [];
|
|
2248
|
-
}
|
|
2249
|
-
var SHOW_IT = `Show it as a Version ("Version 2"), never a run id or a file, in one line: the idea's message, who it is for, the customer quote it stands on (or that it is an explore bet), and the finding it answers. Name the versions you would run first; never ask which to keep or whether to publish: the person answers in their own time.`;
|
|
2250
|
-
function allowedSceneWords(spec) {
|
|
2251
|
-
return [.../* @__PURE__ */ new Set([...spec.scene_text, ...spec.third_party_brands.map((b) => b.name)])];
|
|
2252
|
-
}
|
|
2253
|
-
function brandPalette(brand) {
|
|
2254
|
-
if (!brand) return [];
|
|
2255
|
-
const named = [brand.ink, brand.accent, brand.cta, brand.ground, ...brand.palette];
|
|
2256
|
-
return [...new Set(named.filter((hex) => typeof hex === "string"))];
|
|
2257
|
-
}
|
|
2258
|
-
function safeAreaPlacements(viewer) {
|
|
2259
|
-
const named = (viewer?.placements ?? []).filter((p) => p !== "automatic");
|
|
2260
|
-
return named.length > 0 && named.length === viewer?.placements.length ? named : void 0;
|
|
2261
|
-
}
|
|
2262
|
-
function canvasPlacements(parsed) {
|
|
2263
|
-
const node = nodesWithRole(parsed, VARIANT_PREFILTER_ROLE)[0];
|
|
2264
|
-
const placements = node?.params?.placements;
|
|
2265
|
-
return Array.isArray(placements) && placements.length > 0 && placements.every((p) => typeof p === "string") ? placements : void 0;
|
|
2266
|
-
}
|
|
2267
|
-
async function reviewStaticRun(opts) {
|
|
2268
|
-
const targets = staticReviewTargets(opts.parsed, opts.output);
|
|
2269
|
-
if (!targets) return null;
|
|
2270
|
-
const prefilterId = nodesWithRole(opts.parsed, VARIANT_PREFILTER_ROLE)[0]?.id;
|
|
2271
|
-
const tieBreak = prefilterId ? opts.outputsByNode[prefilterId]?.reasoning : void 0;
|
|
2272
|
-
const pickId = nodesWithRole(opts.parsed, STATIC_PICK_ROLE)[0]?.id ?? "pick";
|
|
2273
|
-
const reasoning = typeof tieBreak === "string" ? tieBreak : await textOf(opts.outputsByNode[pickId]?.reasoning);
|
|
2274
|
-
const judge = reasoning ? parseJudgeScores(reasoning) : null;
|
|
2275
|
-
let copy = [];
|
|
2276
|
-
let mechanisms = [];
|
|
2277
|
-
let intended = {};
|
|
2278
|
-
let expectLogo = false;
|
|
2279
|
-
let concept = null;
|
|
2280
|
-
let uncast = [];
|
|
2281
|
-
let nobody = false;
|
|
2282
|
-
let brand = opts.brandName;
|
|
2283
|
-
let lockup = [...opts.lockup ?? []];
|
|
2284
|
-
let sceneText = [];
|
|
2285
|
-
let lines = [];
|
|
2286
|
-
let native;
|
|
2287
|
-
let palette = [];
|
|
2288
|
-
try {
|
|
2289
|
-
const spec = readAdSpec(JSON.parse(await readFile4(targets.promptPath, "utf8")));
|
|
2290
|
-
copy = spec.copy.map((l) => l.text);
|
|
2291
|
-
lines = spec.copy.map((l) => ({ text: l.text, lettering: l.lettering, ...l.role ? { role: l.role } : {} }));
|
|
2292
|
-
if (spec.native) {
|
|
2293
|
-
copy = nativeCopy(spec.native);
|
|
2294
|
-
lines = copy.map((text) => ({ text, lettering: "designed" }));
|
|
2295
|
-
native = nativeSurfaceName(spec.native);
|
|
2296
|
-
}
|
|
2297
|
-
palette = spec.native ? [] : brandPalette(spec.brand);
|
|
2298
|
-
mechanisms = spec.mechanism.map((m) => m.device);
|
|
2299
|
-
brand = spec.brand?.name ?? opts.brandName;
|
|
2300
|
-
const sells = (await readCompanyReading(path6.resolve(path6.dirname(targets.promptPath), "../../..")))?.sells;
|
|
2301
|
-
intended = {
|
|
2302
|
-
...spec.message?.trim() ? { offer: spec.message.trim() } : {},
|
|
2303
|
-
...spec.viewer?.who.trim() ? { persona: spec.viewer.who.trim() } : {},
|
|
2304
|
-
...spec.recognition?.trim() ? { recognition: spec.recognition.trim() } : {},
|
|
2305
|
-
...sells ? { sells } : {}
|
|
2306
|
-
};
|
|
2307
|
-
lockup = [.../* @__PURE__ */ new Set([...spec.brand?.lockup ?? [], ...lockup])];
|
|
2308
|
-
sceneText = [
|
|
2309
|
-
...allowedSceneWords(spec),
|
|
2310
|
-
...spec.native ? nativeChrome(spec.native, spec.viewer?.market?.language, interfaceWordsOf(opts.parsed)) : []
|
|
2311
|
-
];
|
|
2312
|
-
expectLogo = spec.logo && !spec.native && staticRunShape(opts.parsed).logo;
|
|
2313
|
-
concept = conceptSummary(spec);
|
|
2314
|
-
const cacheDir = path6.join(findWorkspaceRoot(path6.dirname(targets.promptPath)) ?? path6.dirname(targets.promptPath), "canvas", ".cache");
|
|
2315
|
-
const people = spec.native ? [] : await peopleReader(cacheDir, (u) => opts.onSpend?.(u))(copy) ?? [];
|
|
2316
|
-
uncast = uncastPeople(spec, people);
|
|
2317
|
-
nobody = !spec.native && castsNobody(spec);
|
|
2318
|
-
} catch {
|
|
2319
|
-
copy = [];
|
|
2320
|
-
}
|
|
2321
|
-
const shape = staticRunShape(opts.parsed);
|
|
2322
|
-
const placements = canvasPlacements(opts.parsed) ?? safeAreaPlacements(opts.viewer);
|
|
2323
|
-
const masterFormat = staticMasterFormat(opts.parsed) ?? void 0;
|
|
2324
|
-
const glancing = opts.glance === false ? Promise.resolve(null) : glanceAtFinished(
|
|
2325
|
-
targets.images,
|
|
2326
|
-
opts.viewer ?? STRANGER,
|
|
2327
|
-
intended,
|
|
2328
|
-
opts.glance ?? gatewayGlanceModel(opts.onSpend),
|
|
2329
|
-
opts.onSpend
|
|
2330
|
-
).catch(() => null);
|
|
2331
|
-
const comparing = opts.previous ? nearIdenticalFindings(targets.images, opts.previous).catch(() => []) : Promise.resolve([]);
|
|
2332
|
-
const leadFormat = masterFormat ?? targets.images[0]?.format ?? "";
|
|
2333
|
-
const lead = targets.images.find((i) => i.format === leadFormat);
|
|
2334
|
-
const drawn = native || !lead ? [] : drawnSizes(opts.parsed, targets.images.map((i) => i.format), leadFormat);
|
|
2335
|
-
const matching = lead && drawn.length > 0 ? compareSizes(
|
|
2336
|
-
lead,
|
|
2337
|
-
targets.images.filter((i) => drawn.includes(i.format)),
|
|
2338
|
-
{ ...opts.onSpend ? { onSpend: opts.onSpend } : {} }
|
|
2339
|
-
).catch(() => drawn.map((format) => ({ format, compared: false, differences: [] }))) : Promise.resolve([]);
|
|
2340
|
-
const untouched = opts.settled ? await samePictureSizes(targets.images, opts.settled.images) : [];
|
|
2341
|
-
const changed = targets.images.filter((i) => !untouched.includes(i.format));
|
|
2342
|
-
const held = await heldRules(path6.dirname(targets.promptPath)).catch(() => ({ rules: [] }));
|
|
2343
|
-
const review = await reviewRenderedStatic({
|
|
2344
|
-
images: changed.length > 0 ? changed : targets.images,
|
|
2345
|
-
rules: held.rules,
|
|
2346
|
-
copy,
|
|
2347
|
-
lines,
|
|
2348
|
-
palette,
|
|
2349
|
-
...placements ? { placements } : {},
|
|
2350
|
-
...brand ? { brand } : {},
|
|
2351
|
-
...lockup.length > 0 ? { lockup } : {},
|
|
2352
|
-
...sceneText.length > 0 ? { sceneText } : {},
|
|
2353
|
-
...masterFormat ? { masterFormat } : {},
|
|
2354
|
-
...expectLogo ? { expectLogo } : {},
|
|
2355
|
-
...concept && concept.mustKeep.length > 0 && referenceSource(opts.parsed) ? { concept: { ...concept, reference: referenceSource(opts.parsed) } } : {},
|
|
2356
|
-
logo: shape.logo,
|
|
2357
|
-
...native ? { native } : {},
|
|
2358
|
-
...uncast.length > 0 ? { uncastPeople: uncast } : {},
|
|
2359
|
-
...nobody ? { castsNobody: true } : {},
|
|
2360
|
-
...native ? { scrolled: scrolledLines(opts.parsed, opts.outputsByNode) } : {},
|
|
2361
|
-
mechanisms,
|
|
2362
|
-
...opts.viewer ? { viewer: describeViewer(opts.viewer) } : {},
|
|
2363
|
-
onSpend: opts.onSpend
|
|
2364
|
-
});
|
|
2365
|
-
const [glanced, compared, matched] = await Promise.all([glancing, comparing, matching]);
|
|
2366
|
-
const glance = review === null ? null : glanced;
|
|
2367
|
-
const unchanged = review === null ? [] : compared;
|
|
2368
|
-
const sized = sizeFactFindings(opts.parsed, opts.outputsByNode);
|
|
2369
|
-
const logoChecked = expectLogo && review !== null;
|
|
2370
|
-
const placedLogo = logoChecked ? logoPlacementFindings(opts.parsed, opts.outputsByNode) : [];
|
|
2371
|
-
const deliveredLogo = logoChecked ? await deliveredLogoFindings(opts.parsed, opts.outputsByNode, changed.length > 0 ? changed : targets.images, [
|
|
2372
|
-
.../* @__PURE__ */ new Set([...palette, "#FFFFFF", "#000000"])
|
|
2373
|
-
]).catch(() => []) : [];
|
|
2374
|
-
const differing = matched.flatMap((m) => m.differences.length > 0 ? [sizeDifferenceFinding(m.format, m.differences)] : []);
|
|
2375
|
-
const fresh = review === null ? null : [...review, ...glance ?? [], ...unchanged, ...sized, ...placedLogo, ...deliveredLogo, ...differing];
|
|
2376
|
-
const reviewed = fresh === null || !opts.settled ? fresh : carryUnchanged(fresh, opts.settled.review, untouched);
|
|
2377
|
-
const verdict = staticVerdict(reviewed);
|
|
2378
|
-
const hints = verdictHints(verdict, sizeShapeOf(opts.parsed));
|
|
2379
|
-
const lost = keptLostHint(reviewed ?? [], await ideaOf(targets.promptPath));
|
|
2380
|
-
if (lost) hints.push(lost);
|
|
2381
|
-
const sizeHints = verdict === "needs_fixes" ? sizeFixHints(opts.parsed, reviewed) : [];
|
|
2382
|
-
const sizesFirst = sizeHints[0]?.startsWith("Do this first") === true;
|
|
2383
|
-
if (sizesFirst) hints.push(...sizeHints);
|
|
2384
|
-
for (const f of reviewed ?? []) hints.push(`${f.severity === "blocking" ? "Must fix" : "Should fix"}: ${f.what}`);
|
|
2385
|
-
if ((reviewed ?? []).some((f) => f.severity === "blocking" && f.kind?.item === "rule" && f.kind.element === "copy")) {
|
|
2386
|
-
hints.push(
|
|
2387
|
-
'A company rule the words break is yours to rewrite in prompt.json\'s `copy` (no automatic round changes the words); only when the person asked for those words, keep them and add `"waive": [{"rule": "<id>", "why": "<their ask>"}]`.'
|
|
2388
|
-
);
|
|
2389
|
-
}
|
|
2390
|
-
if (review !== null && glance === null && opts.glance !== false) {
|
|
2391
|
-
hints.push("The finished ad was not shown to a stranger at a glance (the model did not answer): look at the 4:5 at phone size yourself and say what it sells in three seconds.");
|
|
2392
|
-
}
|
|
2393
|
-
const unmatched = review === null ? [] : matched.filter((m) => !m.compared).map((m) => m.format);
|
|
2394
|
-
if (unmatched.length > 0) {
|
|
2395
|
-
hints.push(
|
|
2396
|
-
`The ${unmatched.join(" and ")} could not be compared with the ${leadFormat} (the model did not answer): look at them side by side yourself, for the same people and product, shown once, unstretched.`
|
|
2397
|
-
);
|
|
2398
|
-
}
|
|
2399
|
-
if (!sizesFirst) hints.push(...sizeHints);
|
|
2400
|
-
hints.push(shapeHint(shape, copy.length));
|
|
2401
|
-
hints.push(...variantHints(judge, prefilterOutcome(opts.parsed, opts.outputsByNode)));
|
|
2402
|
-
return { review: reviewed, verdict, judge, hints };
|
|
2403
|
-
}
|
|
2404
|
-
function scrolledLines(parsed, outputsByNode) {
|
|
2405
|
-
return Object.fromEntries(
|
|
2406
|
-
nodesOf3(parsed).flatMap((n) => {
|
|
2407
|
-
const out = typeof n.id === "string" ? outputsByNode[n.id] : void 0;
|
|
2408
|
-
const format = n.params?.format;
|
|
2409
|
-
return n.type === "static_native" && typeof format === "string" && Array.isArray(out?.scrolled) ? [[format, out.scrolled.filter((t) => typeof t === "string")]] : [];
|
|
2410
|
-
})
|
|
2411
|
-
);
|
|
2412
|
-
}
|
|
2413
|
-
async function ideaOf(promptPath) {
|
|
2414
|
-
const definition = await readFile4(path6.join(path6.dirname(promptPath), "_definition.md"), "utf8").catch(() => "");
|
|
2415
|
-
const idea = frontmatterOf(definition)?.idea;
|
|
2416
|
-
return typeof idea === "string" && idea.trim() ? idea.trim() : void 0;
|
|
2417
|
-
}
|
|
2418
|
-
function referenceSource(parsed) {
|
|
2419
|
-
const original = nodesOf3(parsed).find((n) => n.id === "original" && n.type === "ingest");
|
|
2420
|
-
const source = original?.params?.url ?? original?.params?.path;
|
|
2421
|
-
return typeof source === "string" && !source.includes("[TODO") ? source : null;
|
|
2422
|
-
}
|
|
2423
|
-
function interfaceWordsOf(parsed) {
|
|
2424
|
-
const nodes = parsed?.nodes;
|
|
2425
|
-
const screen = Array.isArray(nodes) ? nodes.find((n) => n?.type === "static_native") : void 0;
|
|
2426
|
-
return readInterfaceWords(screen?.params?.interface_words) ?? void 0;
|
|
2427
|
-
}
|
|
2428
|
-
var STRANGER = { temperature: "cold", knows: [], placements: ["automatic"], source: "knowledge", reasons: [] };
|
|
2429
|
-
async function glanceAtFinished(images, viewer, intended, ask, onSpend) {
|
|
2430
|
-
const shown = images.find((i) => i.format === "4:5") ?? images[0];
|
|
2431
|
-
if (!shown) return null;
|
|
2432
|
-
return await glanceCheck({
|
|
2433
|
-
image: shown.path,
|
|
2434
|
-
format: shown.format,
|
|
2435
|
-
viewer,
|
|
2436
|
-
intended,
|
|
2437
|
-
ask,
|
|
2438
|
-
judge: jevReadJudge(onSpend),
|
|
2439
|
-
...viewer.market ? { market: describeMarket(viewer.market) } : {}
|
|
2440
|
-
});
|
|
2441
|
-
}
|
|
2442
|
-
function sizeFixHints(parsed, review) {
|
|
2443
|
-
const cut = new Set(nodesWithRole(parsed, STATIC_FORMAT_ROLE).map((n) => n.id));
|
|
2444
|
-
const relaid = [...nodesWithRole(parsed, STATIC_ADAPT_FORMAT_ROLE).map((n) => n.id), ...cut];
|
|
2445
|
-
const blocking = (review ?? []).filter((f) => f.severity === "blocking");
|
|
2446
|
-
const regenerate = relaid.flatMap((id) => {
|
|
2447
|
-
const format = formatOfSizeNode(parsed, id);
|
|
2448
|
-
if (!format || !blocking.some((f) => f.what.startsWith(`${format}:`))) return [];
|
|
2449
|
-
return [
|
|
2450
|
-
cut.has(id) ? `The ${format}'s words alone need fixing and the picture is right: \`baker canvas run \u2026 --regenerate ${id}\` sets the ${format}'s words again on the same picture (one request). If the picture itself is wrong, \`--fix\` it instead: every size's words are set again on the corrected picture.` : `The ${format} alone needs fixing and the chosen picture is right: \`baker canvas run \u2026 --regenerate ${id}\` lays out the ${format} again from the same picture (one request). If the chosen picture itself is wrong, \`--fix\` it instead: every size follows.`
|
|
2451
|
-
];
|
|
2452
|
-
});
|
|
2453
|
-
const relaidFormats = relaid.map((id) => formatOfSizeNode(parsed, id)).filter((f) => Boolean(f));
|
|
2454
|
-
const sizesOnly = regenerate.length > 0 && blocking.every((f) => relaidFormats.some((format) => f.what.startsWith(`${format}:`)));
|
|
2455
|
-
const lead = sizesOnly ? regenerate.map((h, i) => i === 0 ? `Do this first, not a --fix: ${h}` : h) : regenerate;
|
|
2456
|
-
return [...lead, ...safeFitHints(parsed, blocking)];
|
|
2457
|
-
}
|
|
2458
|
-
var COVERED = / sits? where .+? covers? (?:it|them) /;
|
|
2459
|
-
function safeFitHints(parsed, blocking) {
|
|
2460
|
-
return nodesWithRole(parsed, STATIC_SAFE_FIT_ROLE).flatMap((n) => {
|
|
2461
|
-
const format = typeof n.params?.format === "string" ? n.params.format : formatOfSlug(n.id.replace(/^safe_/, ""));
|
|
2462
|
-
if (!blocking.some((f) => f.what.startsWith(`${format}:`) && COVERED.test(f.what))) return [];
|
|
2463
|
-
return [
|
|
2464
|
-
`The ${format} was already shrunk and shifted automatically to clear what the app covers; small misses are corrected that way, so this one is too large for it. Change the layout itself (shorter copy, fewer lines, a smaller block of text) rather than a \`--fix\` asking to move it, which moves it only about 1%.`
|
|
2465
|
-
];
|
|
2466
|
-
});
|
|
2467
|
-
}
|
|
2468
|
-
var SIZE_FACT_FINDING = {
|
|
2469
|
-
band_too_far: {
|
|
2470
|
-
what: (format) => `${format}: the words reach too far past the part of the frame the app leaves clear to be moved inside it; set them inside it.`,
|
|
2471
|
-
kind: { item: "safe_zone", element: "copy", defect: "other", edges: [] }
|
|
2472
|
-
},
|
|
2473
|
-
words_over_face: {
|
|
2474
|
-
what: (format) => `${format}: the words were set over a face; set them where no face is.`,
|
|
2475
|
-
kind: { item: "layout", element: "copy", defect: "other", edges: [] }
|
|
2476
|
-
},
|
|
2477
|
-
words_misaligned: {
|
|
2478
|
-
what: (format) => `${format}: ${PATCHED_WORDS}, which shows as a box; set them again on the same picture.`,
|
|
2479
|
-
kind: { item: "layout", element: "copy", defect: "other", edges: [] }
|
|
2480
|
-
},
|
|
2481
|
-
words_not_read: {
|
|
2482
|
-
what: (format) => `${format}: ${UNREAD_WORDS}, so the picture around them may have been redrawn; set them again on the same picture.`,
|
|
2483
|
-
kind: { item: "layout", element: "copy", defect: "other", edges: [] }
|
|
2484
|
-
},
|
|
2485
|
-
subject_covered: {
|
|
2486
|
-
what: (format, facts) => `${format}: the words hide ${(facts.covered ?? ["the product"]).join(" and ")}, which the other sizes show; set them where it stays in view.`,
|
|
2487
|
-
kind: { item: "layout", element: "copy", defect: "other", edges: [] }
|
|
2488
|
-
},
|
|
2489
|
-
subject_cut: {
|
|
2490
|
-
what: (format) => `${format}: no cut of the picture keeps every person and product whole in this size.`,
|
|
2491
|
-
kind: { item: "picture", element: "picture", defect: "cut", edges: [] }
|
|
2492
|
-
}
|
|
2493
|
-
};
|
|
2494
|
-
function coveredIn(facts) {
|
|
2495
|
-
if (facts === void 0 || facts === null || typeof facts !== "object") return null;
|
|
2496
|
-
const covered = facts.covered;
|
|
2497
|
-
return Array.isArray(covered) ? covered.filter((c) => typeof c === "string") : [];
|
|
2498
|
-
}
|
|
2499
|
-
function hiddenEverywhere(sizes, outputsByNode) {
|
|
2500
|
-
const lists = sizes.map((s) => ({ ...s, covered: coveredIn(outputsByNode[s.id]?.facts) }));
|
|
2501
|
-
const labels = new Set(
|
|
2502
|
-
(lists[0]?.covered ?? []).filter((label) => lists.length > 1 && lists.every((s) => s.covered?.includes(label)))
|
|
2503
|
-
);
|
|
2504
|
-
const first = lists.find((s) => s.format && s.covered?.some((label) => labels.has(label)));
|
|
2505
|
-
const notes = first?.format && labels.size > 0 ? [
|
|
2506
|
-
{
|
|
2507
|
-
severity: "warning",
|
|
2508
|
-
what: `${first.format}: the words hide ${[...labels].join(" and ")} in every size; set them where it stays in view if it is what the ad sells.`,
|
|
2509
|
-
kind: { item: "layout", element: "copy", defect: "other", edges: [] }
|
|
2510
|
-
}
|
|
2511
|
-
] : [];
|
|
2512
|
-
return { labels, notes };
|
|
2513
|
-
}
|
|
2514
|
-
function sizeFactFindings(parsed, outputsByNode) {
|
|
2515
|
-
const added = paintedAdditions(parsed, outputsByNode);
|
|
2516
|
-
const sizes = nodesWithRole(parsed, STATIC_FORMAT_ROLE);
|
|
2517
|
-
const everywhere = hiddenEverywhere(
|
|
2518
|
-
sizes.map((n) => ({ id: n.id, format: formatOfSizeNode(parsed, n.id) })),
|
|
2519
|
-
outputsByNode
|
|
2520
|
-
);
|
|
2521
|
-
const found = sizes.flatMap((n) => {
|
|
2522
|
-
const format = formatOfSizeNode(parsed, n.id);
|
|
2523
|
-
const facts = outputsByNode[n.id]?.facts ?? {};
|
|
2524
|
-
const shownElsewhere = (coveredIn(facts) ?? []).some((label) => !everywhere.labels.has(label));
|
|
2525
|
-
const said2 = typeof facts.reason === "string" && (facts.reason !== "subject_covered" || shownElsewhere) ? SIZE_FACT_FINDING[facts.reason] : void 0;
|
|
2526
|
-
const patched = facts.reason !== "words_misaligned" && facts.words_mode !== "whole" && typeof facts.residual === "number" && facts.residual > MISALIGNED ? SIZE_FACT_FINDING.words_misaligned : void 0;
|
|
2527
|
-
const covered = (coveredIn(facts) ?? []).filter((label) => !everywhere.labels.has(label));
|
|
2528
|
-
const fromPlate = refId2(n.inputs?.plate);
|
|
2529
|
-
const extra = fromPlate ? added.get(fromPlate) : void 0;
|
|
2530
|
-
if (!format) return [];
|
|
2531
|
-
return [
|
|
2532
|
-
...[said2, patched].flatMap(
|
|
2533
|
-
(f) => f ? [{ severity: "blocking", what: f.what(format, covered.length > 0 ? { covered } : {}), kind: f.kind }] : []
|
|
2534
|
-
),
|
|
2535
|
-
...extra ? [
|
|
2536
|
-
{
|
|
2537
|
-
severity: "blocking",
|
|
2538
|
-
what: `${format}: the picture painted wider from the chosen one shows ${extra.join(", ")}, which the other sizes do not. It must show the main size's people and product, once each.`,
|
|
2539
|
-
kind: { item: "sizes", element: "picture", defect: "other", edges: [] }
|
|
2540
|
-
}
|
|
2541
|
-
] : []
|
|
2542
|
-
];
|
|
2543
|
-
});
|
|
2544
|
-
return [...found, ...everywhere.notes];
|
|
2545
|
-
}
|
|
2546
|
-
function paintedAdditions(parsed, outputsByNode) {
|
|
2547
|
-
return new Map(
|
|
2548
|
-
nodesWithRole(parsed, STATIC_PLATE_ROLE).flatMap((n) => {
|
|
2549
|
-
const facts = outputsByNode[n.id]?.facts;
|
|
2550
|
-
const added = Array.isArray(facts?.added) ? facts.added.filter((a) => typeof a === "string") : [];
|
|
2551
|
-
return facts?.reason === "subject_added" && added.length > 0 ? [[n.id, added]] : [];
|
|
2552
|
-
})
|
|
2553
|
-
);
|
|
2554
|
-
}
|
|
2555
|
-
function drawnSizes(parsed, delivered, masterFormat) {
|
|
2556
|
-
const others = delivered.filter((format) => format && format !== masterFormat);
|
|
2557
|
-
const cut = nodesWithRole(parsed, STATIC_FORMAT_ROLE);
|
|
2558
|
-
if (cut.length === 0) return others;
|
|
2559
|
-
const painted = new Set(nodesWithRole(parsed, STATIC_PLATE_ROLE).map((n) => n.id));
|
|
2560
|
-
const fromPainted = new Set(
|
|
2561
|
-
cut.flatMap((n) => {
|
|
2562
|
-
const plate = refId2(n.inputs?.plate);
|
|
2563
|
-
const format = formatOfSizeNode(parsed, n.id);
|
|
2564
|
-
return plate && painted.has(plate) && format ? [format] : [];
|
|
2565
|
-
})
|
|
2566
|
-
);
|
|
2567
|
-
return others.filter((format) => fromPainted.has(format));
|
|
2568
|
-
}
|
|
2569
|
-
function formatOfSlug(slug) {
|
|
2570
|
-
return slug.replace("x", ":").replace("_", ".");
|
|
2571
|
-
}
|
|
2572
|
-
function prefilterNodeId(parsed) {
|
|
2573
|
-
return nodesWithRole(parsed, VARIANT_PREFILTER_ROLE)[0]?.id ?? null;
|
|
2574
|
-
}
|
|
2575
|
-
function prefilterOutcome(parsed, outputsByNode) {
|
|
2576
|
-
const id = prefilterNodeId(parsed);
|
|
2577
|
-
const out = id ? outputsByNode[id] : void 0;
|
|
2578
|
-
return out && Array.isArray(out.dropped) ? out : null;
|
|
2579
|
-
}
|
|
2580
|
-
function prefilterSpend(parsed, outputsByNode, nodeRuns) {
|
|
2581
|
-
const cached = (id2) => nodeRuns.some((r) => r.node_id === id2 && r.cached);
|
|
2582
|
-
const id = prefilterNodeId(parsed);
|
|
2583
|
-
const checks = id && !cached(id) ? prefilterOutcome(parsed, outputsByNode)?.usage ?? [] : [];
|
|
2584
|
-
const fits = [
|
|
2585
|
-
...nodesWithRole(parsed, STATIC_SAFE_FIT_ROLE),
|
|
2586
|
-
...nodesWithRole(parsed, STATIC_PLACE_ROLE),
|
|
2587
|
-
// A size cut from one picture reads its subjects and its words; a widened picture its subjects.
|
|
2588
|
-
...nodesWithRole(parsed, STATIC_LEAD_ROLE),
|
|
2589
|
-
...nodesWithRole(parsed, STATIC_FORMAT_ROLE),
|
|
2590
|
-
...nodesWithRole(parsed, STATIC_PLATE_ROLE),
|
|
2591
|
-
// The logo's composite reads the size's words for its check.
|
|
2592
|
-
...nodesWithRole(parsed, LOGO_COMPOSITE_ROLE)
|
|
2593
|
-
].filter((n) => !cached(n.id)).flatMap((n) => {
|
|
2594
|
-
const usage = outputsByNode[n.id]?.usage;
|
|
2595
|
-
return Array.isArray(usage) ? usage : [];
|
|
2596
|
-
});
|
|
2597
|
-
return [...checks, ...fits];
|
|
2598
|
-
}
|
|
2599
|
-
function variantHints(judge, prefilter) {
|
|
2600
|
-
const hints = [];
|
|
2601
|
-
const dropped = prefilter?.dropped ?? [];
|
|
2602
|
-
const kept = Array.isArray(prefilter?.images) ? prefilter.images.length : judge?.length ?? 0;
|
|
2603
|
-
const total = dropped.length + kept;
|
|
2604
|
-
if (prefilter?.flagged) {
|
|
2605
|
-
hints.push(
|
|
2606
|
-
`Every variant failed the checks; variant ${prefilter.flagged.index + 1} had the fewest problems and was kept: ${prefilter.flagged.reasons.join(" ")}`
|
|
2607
|
-
);
|
|
2608
|
-
} else if (dropped.length > 0) {
|
|
2609
|
-
const list = dropped.map((d) => `variant ${d.index + 1} (${d.reasons.join(" ")})`).join("; ");
|
|
2610
|
-
hints.push(`${dropped.length} of ${total} variants set aside by the checks before the judge: ${list}.`);
|
|
2611
|
-
}
|
|
2612
|
-
const alone = prefilter?.order?.length === 1 && !prefilter.flagged ? prefilter.order[0] : void 0;
|
|
2613
|
-
if (alone !== void 0 && dropped.length > 0) {
|
|
2614
|
-
hints.push(
|
|
2615
|
-
`The checks ranked variant ${alone + 1} best, so no judge was needed; the others stay in this run as options the person can switch to (\`baker canvas run --use-variant\`).`
|
|
2616
|
-
);
|
|
2617
|
-
}
|
|
2618
|
-
const winner = judge ? judgeWinner(judge) : null;
|
|
2619
|
-
if (judge && winner) {
|
|
2620
|
-
const gone = new Set(dropped.map((d) => d.index));
|
|
2621
|
-
const shown = prefilter?.order ?? Array.from({ length: total }, (_, i) => i).filter((i) => !gone.has(i));
|
|
2622
|
-
const variant = (shown[winner.image - 1] ?? winner.image - 1) + 1;
|
|
2623
|
-
const why = winner.of === void 0 ? `${winner.total}/${Object.keys(winner.scores).length * 5}` : `first on ${Object.entries(winner.scores).filter(([, beaten]) => beaten === winner.of).map(([criterion]) => criterion.replace(/_/g, " ")).join(", ") || "none of the criteria alone"}`;
|
|
2624
|
-
hints.push(
|
|
2625
|
-
`The judge picked variant ${variant} of the ${judge.length} it compared (${why}); the others it compared stay in this run as options the person can switch to (\`baker canvas run --use-variant\`).`
|
|
2626
|
-
);
|
|
2627
|
-
}
|
|
2628
|
-
return hints;
|
|
2629
|
-
}
|
|
2630
|
-
|
|
2631
|
-
// src/commands/canvas/static-spec-repair.ts
|
|
2632
|
-
import { readFile as readFile5, writeFile as writeFile4 } from "fs/promises";
|
|
2633
|
-
import sharp3 from "sharp";
|
|
2634
|
-
import { z as z2 } from "zod";
|
|
2635
|
-
var Answer = z2.object({
|
|
2636
|
-
changed: z2.string().min(1),
|
|
2637
|
-
set: z2.array(z2.object({ path: z2.string().min(1), value: z2.unknown() }))
|
|
976
|
+
var Answer = z.object({
|
|
977
|
+
changed: z.string().min(1),
|
|
978
|
+
set: z.array(z.object({ path: z.string().min(1), value: z.unknown() }))
|
|
2638
979
|
});
|
|
2639
|
-
function withValueAt(root,
|
|
2640
|
-
const [key, ...rest] =
|
|
980
|
+
function withValueAt(root, path6, value) {
|
|
981
|
+
const [key, ...rest] = path6;
|
|
2641
982
|
if (key === void 0) return value;
|
|
2642
983
|
if (Array.isArray(root)) {
|
|
2643
984
|
const at = Number(key);
|
|
@@ -2680,7 +1021,7 @@ function printedWords(spec) {
|
|
|
2680
1021
|
function acceptRepair(before, answer, held = { rules: [] }) {
|
|
2681
1022
|
const parsed = Answer.safeParse(answer);
|
|
2682
1023
|
if (!parsed.success || !isAdSpec(before)) return null;
|
|
2683
|
-
const spec = parsed.data.set.reduce((at, { path:
|
|
1024
|
+
const spec = parsed.data.set.reduce((at, { path: path6, value }) => withValueAt(at, path6.split("."), value), before);
|
|
2684
1025
|
if (!isAdSpec(spec)) return null;
|
|
2685
1026
|
const was = AdSpecSchema.safeParse(before);
|
|
2686
1027
|
const now = AdSpecSchema.safeParse(spec);
|
|
@@ -2692,13 +1033,13 @@ function acceptRepair(before, answer, held = { rules: [] }) {
|
|
|
2692
1033
|
if (was.data.native && was.data.native.surface !== now.data.native?.surface) return null;
|
|
2693
1034
|
if (!keepsCast(was.data, now.data) || !keepsMemeTemplates(was.data, now.data)) return null;
|
|
2694
1035
|
const kept = printedWords(now.data);
|
|
2695
|
-
const
|
|
2696
|
-
if (!
|
|
1036
|
+
const said = printedWords(was.data);
|
|
1037
|
+
if (!said.every((text) => kept.includes(text))) return null;
|
|
2697
1038
|
if (was.data.native) {
|
|
2698
1039
|
const shown = now.data.native ? nativeCopy(now.data.native) : [];
|
|
2699
1040
|
if (!nativeCopy(was.data.native).every((text) => shown.includes(text))) return null;
|
|
2700
1041
|
}
|
|
2701
|
-
const added = kept.filter((text) => !
|
|
1042
|
+
const added = kept.filter((text) => !said.includes(text));
|
|
2702
1043
|
if (ruleTells(added, held.rules, held.language).some((t) => t.kind === "forbidden")) return null;
|
|
2703
1044
|
return { changed: parsed.data.changed, spec };
|
|
2704
1045
|
}
|
|
@@ -2759,7 +1100,7 @@ function restoreLines(spec, jobs) {
|
|
|
2759
1100
|
var REPAIR_TIMEOUT_MS = 15e4;
|
|
2760
1101
|
var SHOWN_WIDTH = 768;
|
|
2761
1102
|
async function repairSpec(opts) {
|
|
2762
|
-
const text = await
|
|
1103
|
+
const text = await readFile3(opts.promptPath, "utf8").catch(() => null);
|
|
2763
1104
|
if (text === null) return null;
|
|
2764
1105
|
let before;
|
|
2765
1106
|
try {
|
|
@@ -2767,7 +1108,7 @@ async function repairSpec(opts) {
|
|
|
2767
1108
|
} catch {
|
|
2768
1109
|
return null;
|
|
2769
1110
|
}
|
|
2770
|
-
const shown = opts.image ? await bytesOf(opts.image).then(async (bytes) => (await
|
|
1111
|
+
const shown = opts.image ? await bytesOf(opts.image).then(async (bytes) => (await sharp(bytes).resize({ width: SHOWN_WIDTH }).jpeg({ quality: 85 }).toBuffer()).toString("base64")).catch(() => null) : null;
|
|
2771
1112
|
const prompt = buildSpecRepairPrompt(
|
|
2772
1113
|
text,
|
|
2773
1114
|
opts.findings,
|
|
@@ -2781,7 +1122,7 @@ async function repairSpec(opts) {
|
|
|
2781
1122
|
opts.held
|
|
2782
1123
|
);
|
|
2783
1124
|
if (!repair) return null;
|
|
2784
|
-
await
|
|
1125
|
+
await writeFile3(opts.promptPath, `${JSON.stringify(repair.spec, null, 2)}
|
|
2785
1126
|
`, "utf8");
|
|
2786
1127
|
return repair.changed;
|
|
2787
1128
|
}
|
|
@@ -2922,7 +1263,7 @@ function failPreflight(code, message, fix) {
|
|
|
2922
1263
|
process.exit(2);
|
|
2923
1264
|
}
|
|
2924
1265
|
async function canvasFileFor(opts) {
|
|
2925
|
-
if (opts.file) return { canvasPath:
|
|
1266
|
+
if (opts.file) return { canvasPath: path5.resolve(opts.file) };
|
|
2926
1267
|
if (!opts.slug) failPreflight("missing_canvas", "Pass the canvas file, or --slug <slug> to run a creative by name.");
|
|
2927
1268
|
const cwd = process.cwd();
|
|
2928
1269
|
try {
|
|
@@ -2948,7 +1289,7 @@ async function executeSeriesRun(lead) {
|
|
|
2948
1289
|
`Make each other message as an ad of the series first (baker creatives make <idea> --series ${lead}), or each language (baker creatives translate --slug ${lead} --to es-MX,de).`
|
|
2949
1290
|
);
|
|
2950
1291
|
}
|
|
2951
|
-
const canvasRoot =
|
|
1292
|
+
const canvasRoot = path5.join(root, "canvas");
|
|
2952
1293
|
process.stdout.write(`[series] rendering ${members.length} ads of ${lead} at once: ${members.join(", ")}
|
|
2953
1294
|
`);
|
|
2954
1295
|
const results = await runSeries(members, {
|
|
@@ -2980,9 +1321,9 @@ async function executeSeriesRun(lead) {
|
|
|
2980
1321
|
`);
|
|
2981
1322
|
}
|
|
2982
1323
|
async function refreshSeriesAd(opts) {
|
|
2983
|
-
const slug = opts.slug ?? (opts.file ? creativeSlugFromCanvasPath(
|
|
1324
|
+
const slug = opts.slug ?? (opts.file ? creativeSlugFromCanvasPath(path5.resolve(opts.file)) : null);
|
|
2984
1325
|
if (!slug) return false;
|
|
2985
|
-
const root = findWorkspaceRoot(opts.file ?
|
|
1326
|
+
const root = findWorkspaceRoot(opts.file ? path5.dirname(path5.resolve(opts.file)) : process.cwd());
|
|
2986
1327
|
if (!root) return false;
|
|
2987
1328
|
const made = await writeSeriesMemberCanvas(root, slug);
|
|
2988
1329
|
if (made === null) return false;
|
|
@@ -3021,13 +1362,13 @@ async function executeCanvasRun(opts) {
|
|
|
3021
1362
|
const { canvasPath: filePath, adoptRunId } = await canvasFileFor(opts);
|
|
3022
1363
|
const canvasRoot = canvasOutputsRoot(filePath);
|
|
3023
1364
|
const creativeSlug = creativeSlugFromCanvasPath(filePath) ?? void 0;
|
|
3024
|
-
const held = creativeSlug ? await heldRules(
|
|
1365
|
+
const held = creativeSlug ? await heldRules(path5.dirname(filePath)) : { rules: [] };
|
|
3025
1366
|
if (creativeSlug) await clearLegacyDirtyMarker(canvasRoot, creativeSlug);
|
|
3026
1367
|
const turnId = optionalTurnId();
|
|
3027
|
-
const turnCache = opts.cacheDir ??
|
|
1368
|
+
const turnCache = opts.cacheDir ?? path5.join(canvasRoot, ".cache");
|
|
3028
1369
|
const refuseTurnRender = async (correction) => {
|
|
3029
1370
|
if (!creativeSlug || (opts.autoFixRound ?? 0) > 0) return;
|
|
3030
|
-
const onDisk = await
|
|
1371
|
+
const onDisk = await readFile4(filePath, "utf8").then((text) => JSON.parse(text)).catch(() => null);
|
|
3031
1372
|
const shape = sizeShapeOf(onDisk);
|
|
3032
1373
|
const refusal = turnRenderRefusal(await readTurnRenders(turnCache), turnId, creativeSlug, { correction, shape });
|
|
3033
1374
|
if (!refusal) return;
|
|
@@ -3038,19 +1379,19 @@ async function executeCanvasRun(opts) {
|
|
|
3038
1379
|
process.exit(2);
|
|
3039
1380
|
};
|
|
3040
1381
|
const shown = creativeSlug ? await shownVersion(canvasRoot, creativeSlug) : {};
|
|
3041
|
-
const promptOnDisk = await
|
|
1382
|
+
const promptOnDisk = await readFile4(path5.join(path5.dirname(filePath), "prompt.json"), "utf8").then((text) => JSON.parse(text)).catch(() => null);
|
|
3042
1383
|
await refuseTurnRender(mayBeCorrection(opts, shown.prompt, promptOnDisk));
|
|
3043
1384
|
const ideaHeld = creativeSlug && (opts.autoFixRound ?? 0) === 0 ? (await shownBaseline({
|
|
3044
1385
|
canvasRoot,
|
|
3045
1386
|
slug: creativeSlug,
|
|
3046
|
-
creativeDir:
|
|
1387
|
+
creativeDir: path5.dirname(filePath),
|
|
3047
1388
|
turnId,
|
|
3048
1389
|
shown,
|
|
3049
1390
|
record: true
|
|
3050
1391
|
})).baseline : void 0;
|
|
3051
1392
|
const citing = [];
|
|
3052
1393
|
await wireProofBadges(
|
|
3053
|
-
|
|
1394
|
+
path5.join(path5.dirname(filePath), "prompt.json"),
|
|
3054
1395
|
fetchBrandLogo,
|
|
3055
1396
|
(line) => process.stderr.write(`${line}
|
|
3056
1397
|
`),
|
|
@@ -3060,7 +1401,7 @@ async function executeCanvasRun(opts) {
|
|
|
3060
1401
|
if ((opts.autoFixRound ?? 0) === 0) {
|
|
3061
1402
|
const reading = [];
|
|
3062
1403
|
await wireNamedPeople(
|
|
3063
|
-
|
|
1404
|
+
path5.join(path5.dirname(filePath), "prompt.json"),
|
|
3064
1405
|
avatarOfNamedPerson,
|
|
3065
1406
|
(line) => process.stderr.write(`${line}
|
|
3066
1407
|
`),
|
|
@@ -3111,7 +1452,7 @@ ${describeRewrites(prepared.rewrites)}
|
|
|
3111
1452
|
);
|
|
3112
1453
|
process.exit(2);
|
|
3113
1454
|
}
|
|
3114
|
-
const asEdit =
|
|
1455
|
+
const asEdit = opts.fix === void 0 && opts.useVariant === void 0 && opts.regenerate === void 0 && opts.from === void 0 && shown.rendered ? plainRunEdit(parsed, shown.prompt, promptNow) : null;
|
|
3115
1456
|
const editOf = asEdit && shown.rendered ? await previousAdImage(canvasRoot, shown.rendered.runId, void 0, rolesById(parsed)) : null;
|
|
3116
1457
|
const editInstruction = editOf ? asEdit : null;
|
|
3117
1458
|
if (editInstruction) {
|
|
@@ -3181,8 +1522,8 @@ ${describeRewrites(prepared.rewrites)}
|
|
|
3181
1522
|
});
|
|
3182
1523
|
const last = Object.fromEntries(
|
|
3183
1524
|
nodesWithRole(parsed, STATIC_ADAPT_FORMAT_ROLE).flatMap((n) => {
|
|
3184
|
-
const
|
|
3185
|
-
return
|
|
1525
|
+
const path6 = delivered.find((d) => d.format === formatOfAdaptId(n.id))?.path;
|
|
1526
|
+
return path6 ? [[n.id, path6]] : [];
|
|
3186
1527
|
})
|
|
3187
1528
|
);
|
|
3188
1529
|
parsed = withSizesFollowingFix(parsed, {
|
|
@@ -3238,7 +1579,7 @@ ${describeRewrites(prepared.rewrites)}
|
|
|
3238
1579
|
const plain = fixInstruction === void 0 && opts.useVariant === void 0 && opts.regenerate === void 0 && (opts.extendSizes?.length ?? 0) === 0;
|
|
3239
1580
|
if (plain && fromRun && !native && isStaticAdCanvas(parsed) && !seriesOf(parsed)) {
|
|
3240
1581
|
const version = await versionRun(canvasRoot, fromRun);
|
|
3241
|
-
const same = version !== null && makesSameVariants(parsed, version, await ingestedNow(variantFiles(parsed),
|
|
1582
|
+
const same = version !== null && makesSameVariants(parsed, version, await ingestedNow(variantFiles(parsed), path5.dirname(filePath)));
|
|
3242
1583
|
const growth = version ? plainRunGrowth(parsed, version, {
|
|
3243
1584
|
sameVariants: same,
|
|
3244
1585
|
frameChanged: shown.prompt !== void 0 && frameChanges(shown.prompt, promptNow).length > 0,
|
|
@@ -3318,7 +1659,7 @@ ${describeRewrites(prepared.rewrites)}
|
|
|
3318
1659
|
process.stdout.write(`[extend] placing ${opts.extendSizes.join(", ")} clear of what covers or cuts it, its margins painted
|
|
3319
1660
|
`);
|
|
3320
1661
|
}
|
|
3321
|
-
const cacheDir = opts.cacheDir ??
|
|
1662
|
+
const cacheDir = opts.cacheDir ?? path5.join(canvasRoot, ".cache");
|
|
3322
1663
|
const engine = createEngineFromEnv({
|
|
3323
1664
|
cacheDir,
|
|
3324
1665
|
outputsDir: opts.outputsDir ?? canvasRoot,
|
|
@@ -3342,7 +1683,7 @@ ${describeRewrites(prepared.rewrites)}
|
|
|
3342
1683
|
const canvasSha = sha256Hex(Buffer.from(canvasText));
|
|
3343
1684
|
const sourceSha = prepared.sourceSha;
|
|
3344
1685
|
const client = opts.record === false ? null : buildBackendClient();
|
|
3345
|
-
const outputsDir = opts.outputsDir ?
|
|
1686
|
+
const outputsDir = opts.outputsDir ? path5.resolve(opts.outputsDir) : canvasRoot;
|
|
3346
1687
|
const { runId, resumed, source, sameSource, concurrentRunId, rendering } = await resolveRunId({
|
|
3347
1688
|
explicitRunId: opts.runId,
|
|
3348
1689
|
adoptedRunId: adoptRunId,
|
|
@@ -3373,7 +1714,7 @@ ${describeRewrites(prepared.rewrites)}
|
|
|
3373
1714
|
}
|
|
3374
1715
|
const viewerUsage = [];
|
|
3375
1716
|
const viewerCheck = creativeSlug && isStaticAdCanvas(parsed) ? await viewerCheckBeforeRender({
|
|
3376
|
-
creativeDir:
|
|
1717
|
+
creativeDir: path5.dirname(filePath),
|
|
3377
1718
|
cacheDir,
|
|
3378
1719
|
slug: creativeSlug,
|
|
3379
1720
|
skip: viewerCheckSkip({
|
|
@@ -3385,7 +1726,7 @@ ${describeRewrites(prepared.rewrites)}
|
|
|
3385
1726
|
asked: opts.skipViewerCheck === true
|
|
3386
1727
|
}),
|
|
3387
1728
|
spent: viewerChecksSpent(await readTurnRenders(turnCache), turnId, creativeSlug),
|
|
3388
|
-
lookups: liveViewerLookups(
|
|
1729
|
+
lookups: liveViewerLookups(path5.dirname(canvasRoot)),
|
|
3389
1730
|
model: VIEWER_CHECK_MODEL,
|
|
3390
1731
|
ask: gatewayViewerModel(VIEWER_CHECK_MODEL, (usage) => viewerUsage.push(usage)),
|
|
3391
1732
|
judge: jevReadJudge((usage) => viewerUsage.push(usage))
|
|
@@ -3444,7 +1785,7 @@ ${describeRewrites(prepared.rewrites)}
|
|
|
3444
1785
|
const graphUrl = client && creativeSlug && isStaticAdCanvas(parsed) ? await uploadRunGraph(client, parsed) : null;
|
|
3445
1786
|
const recordMeta = {
|
|
3446
1787
|
creativeSlug,
|
|
3447
|
-
canvasPath:
|
|
1788
|
+
canvasPath: path5.relative(path5.dirname(canvasRoot), filePath) || void 0,
|
|
3448
1789
|
canvasSha,
|
|
3449
1790
|
// The fingerprint the dashboard compares against the current source to flag
|
|
3450
1791
|
// "edited since last render": the same `computeSourceSha` the edit-sync posts,
|
|
@@ -3513,7 +1854,7 @@ ${describeRewrites(prepared.rewrites)}
|
|
|
3513
1854
|
await clearMarker();
|
|
3514
1855
|
const beforeRunId = shown.rendered?.runId;
|
|
3515
1856
|
if (creativeSlug) {
|
|
3516
|
-
const idea = await readIdeaAnchor(
|
|
1857
|
+
const idea = await readIdeaAnchor(path5.dirname(filePath));
|
|
3517
1858
|
await recordRendered(canvasRoot, creativeSlug, sourceSha, result.run_id, {
|
|
3518
1859
|
...promptNow ? { prompt: promptNow } : {},
|
|
3519
1860
|
...idea ? { anchor: idea.anchor, idea: anchorLines(idea.view) } : {},
|
|
@@ -3545,7 +1886,7 @@ ${describeRewrites(prepared.rewrites)}
|
|
|
3545
1886
|
brief: opts.brief?.trim() || void 0,
|
|
3546
1887
|
onSpend: (usage) => reviewUsage.push(usage)
|
|
3547
1888
|
}) : null;
|
|
3548
|
-
const brandKit = reviewable ? null : await readStaticBrandKit(await findBrandRoot(
|
|
1889
|
+
const brandKit = reviewable ? null : await readStaticBrandKit(await findBrandRoot(path5.dirname(filePath)) ?? process.cwd());
|
|
3549
1890
|
const runShape = {
|
|
3550
1891
|
fix: fixInstruction !== void 0,
|
|
3551
1892
|
useVariant: opts.useVariant !== void 0,
|
|
@@ -3580,7 +1921,7 @@ ${describeRewrites(prepared.rewrites)}
|
|
|
3580
1921
|
}
|
|
3581
1922
|
const costHint = staticReview ? runCostHint(result.stats, paidFor(runShape)) : null;
|
|
3582
1923
|
const corrected = opts.autoFixed ?? [];
|
|
3583
|
-
const seriesRoot = creativeSlug && staticReview ? findWorkspaceRoot(
|
|
1924
|
+
const seriesRoot = creativeSlug && staticReview ? findWorkspaceRoot(path5.dirname(filePath)) : null;
|
|
3584
1925
|
const seriesHints = seriesRoot && creativeSlug ? seriesRunHints(creativeSlug, {
|
|
3585
1926
|
leads: await seriesLeadsAbove(seriesRoot, creativeSlug),
|
|
3586
1927
|
members: await seriesMembers(seriesRoot, creativeSlug)
|
|
@@ -3605,7 +1946,7 @@ ${describeRewrites(prepared.rewrites)}
|
|
|
3605
1946
|
const hints = [...runNotes, ...reviewHints];
|
|
3606
1947
|
const findings = staticReview ? staticReview.review : review;
|
|
3607
1948
|
const ready = staticReview ? staticReview.verdict === "ready" || staticReview.verdict === "ready_with_notes" : review !== null && !review.some((f) => f.severity === "blocking");
|
|
3608
|
-
const definitionStatus = ready && creativeSlug ? await advanceDefinitionStatus(
|
|
1949
|
+
const definitionStatus = ready && creativeSlug ? await advanceDefinitionStatus(path5.join(path5.dirname(filePath), "_definition.md"), "rendered") : null;
|
|
3609
1950
|
if (poster) {
|
|
3610
1951
|
await flushBilled(
|
|
3611
1952
|
poster,
|
|
@@ -3865,4 +2206,4 @@ export {
|
|
|
3865
2206
|
executeCanvasRun,
|
|
3866
2207
|
buildBackendClient
|
|
3867
2208
|
};
|
|
3868
|
-
//# sourceMappingURL=chunk-
|
|
2209
|
+
//# sourceMappingURL=chunk-RQB4XLSF.js.map
|