@genart-dev/mcp-server 0.3.0 → 0.4.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/dist/index.cjs +2045 -227
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2051 -227
- package/dist/index.js.map +1 -1
- package/dist/lib.cjs +2074 -256
- package/dist/lib.cjs.map +1 -1
- package/dist/lib.js +2076 -252
- package/dist/lib.js.map +1 -1
- package/package.json +19 -4
package/dist/index.cjs
CHANGED
|
@@ -268,9 +268,40 @@ var EditorState = class extends import_events.EventEmitter {
|
|
|
268
268
|
canvasHeight: def.canvas.height,
|
|
269
269
|
rendererId: def.renderer.type
|
|
270
270
|
};
|
|
271
|
+
const sketch = {
|
|
272
|
+
getSymbols() {
|
|
273
|
+
return loaded.definition.symbols ?? {};
|
|
274
|
+
},
|
|
275
|
+
setSymbols(symbols) {
|
|
276
|
+
loaded.definition = { ...loaded.definition, symbols };
|
|
277
|
+
},
|
|
278
|
+
getComponents() {
|
|
279
|
+
return loaded.definition.components ?? {};
|
|
280
|
+
},
|
|
281
|
+
setComponents(components) {
|
|
282
|
+
loaded.definition = { ...loaded.definition, components };
|
|
283
|
+
},
|
|
284
|
+
getThirdParty() {
|
|
285
|
+
const def2 = loaded.definition;
|
|
286
|
+
return def2["thirdParty"] ?? [];
|
|
287
|
+
},
|
|
288
|
+
setThirdParty(notices) {
|
|
289
|
+
loaded.definition["thirdParty"] = notices;
|
|
290
|
+
},
|
|
291
|
+
getRenderer() {
|
|
292
|
+
return loaded.definition.renderer.type;
|
|
293
|
+
},
|
|
294
|
+
getGenartVersion() {
|
|
295
|
+
return loaded.definition.genart;
|
|
296
|
+
},
|
|
297
|
+
setGenartVersion(version) {
|
|
298
|
+
loaded.definition = { ...loaded.definition, genart: version };
|
|
299
|
+
}
|
|
300
|
+
};
|
|
271
301
|
return {
|
|
272
302
|
layers: layerStack,
|
|
273
303
|
sketchState,
|
|
304
|
+
sketch,
|
|
274
305
|
canvasWidth: def.canvas.width,
|
|
275
306
|
canvasHeight: def.canvas.height,
|
|
276
307
|
async resolveAsset(_assetId) {
|
|
@@ -306,11 +337,25 @@ var EditorState = class extends import_events.EventEmitter {
|
|
|
306
337
|
// src/server.ts
|
|
307
338
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
308
339
|
var import_zod2 = require("zod");
|
|
309
|
-
var
|
|
340
|
+
var import_core15 = require("@genart-dev/core");
|
|
310
341
|
var import_plugin_typography = __toESM(require("@genart-dev/plugin-typography"), 1);
|
|
311
342
|
var import_plugin_filters = __toESM(require("@genart-dev/plugin-filters"), 1);
|
|
312
343
|
var import_plugin_shapes = __toESM(require("@genart-dev/plugin-shapes"), 1);
|
|
313
344
|
var import_plugin_layout_guides = __toESM(require("@genart-dev/plugin-layout-guides"), 1);
|
|
345
|
+
var import_plugin_painting = __toESM(require("@genart-dev/plugin-painting"), 1);
|
|
346
|
+
var import_plugin_textures = __toESM(require("@genart-dev/plugin-textures"), 1);
|
|
347
|
+
var import_plugin_animation = __toESM(require("@genart-dev/plugin-animation"), 1);
|
|
348
|
+
var import_plugin_color_adjust = __toESM(require("@genart-dev/plugin-color-adjust"), 1);
|
|
349
|
+
var import_plugin_compositing = __toESM(require("@genart-dev/plugin-compositing"), 1);
|
|
350
|
+
var import_plugin_construction = __toESM(require("@genart-dev/plugin-construction"), 1);
|
|
351
|
+
var import_plugin_distribution = __toESM(require("@genart-dev/plugin-distribution"), 1);
|
|
352
|
+
var import_plugin_figure = __toESM(require("@genart-dev/plugin-figure"), 1);
|
|
353
|
+
var import_plugin_layout_composition = __toESM(require("@genart-dev/plugin-layout-composition"), 1);
|
|
354
|
+
var import_plugin_perspective = __toESM(require("@genart-dev/plugin-perspective"), 1);
|
|
355
|
+
var import_plugin_poses = __toESM(require("@genart-dev/plugin-poses"), 1);
|
|
356
|
+
var import_plugin_styles = __toESM(require("@genart-dev/plugin-styles"), 1);
|
|
357
|
+
var import_plugin_symbols = __toESM(require("@genart-dev/plugin-symbols"), 1);
|
|
358
|
+
var import_plugin_trace = __toESM(require("@genart-dev/plugin-trace"), 1);
|
|
314
359
|
|
|
315
360
|
// src/tools/workspace.ts
|
|
316
361
|
var import_promises3 = require("fs/promises");
|
|
@@ -739,8 +784,8 @@ async function createSketch(state, input) {
|
|
|
739
784
|
}
|
|
740
785
|
let algorithm = input.algorithm;
|
|
741
786
|
if (!algorithm) {
|
|
742
|
-
const
|
|
743
|
-
const adapter =
|
|
787
|
+
const registry5 = (0, import_core3.createDefaultRegistry)();
|
|
788
|
+
const adapter = registry5.resolve(rendererType);
|
|
744
789
|
algorithm = adapter.getAlgorithmTemplate();
|
|
745
790
|
}
|
|
746
791
|
let resolvedComponents;
|
|
@@ -965,8 +1010,8 @@ async function updateAlgorithm(state, input) {
|
|
|
965
1010
|
const shouldValidate = input.validate !== false;
|
|
966
1011
|
let validationPassed = true;
|
|
967
1012
|
if (shouldValidate) {
|
|
968
|
-
const
|
|
969
|
-
const adapter =
|
|
1013
|
+
const registry5 = (0, import_core3.createDefaultRegistry)();
|
|
1014
|
+
const adapter = registry5.resolve(def.renderer.type);
|
|
970
1015
|
const result = adapter.validate(input.algorithm);
|
|
971
1016
|
if (!result.valid) {
|
|
972
1017
|
throw new Error(
|
|
@@ -1089,6 +1134,12 @@ async function forkSketch(state, input) {
|
|
|
1089
1134
|
const seed = generateNewSeed ? Math.floor(Math.random() * 1e5) : sourceDef.state.seed;
|
|
1090
1135
|
const title = input.title ?? `${sourceDef.title} (fork)`;
|
|
1091
1136
|
const ts = now2();
|
|
1137
|
+
const sourceGeneration = sourceDef.lineage?.generation ?? 1;
|
|
1138
|
+
const lineage = {
|
|
1139
|
+
parentId: input.sourceId,
|
|
1140
|
+
parentTitle: sourceDef.title,
|
|
1141
|
+
generation: sourceGeneration + 1
|
|
1142
|
+
};
|
|
1092
1143
|
const forkedDef = {
|
|
1093
1144
|
genart: "1.1",
|
|
1094
1145
|
id: input.newId,
|
|
@@ -1101,6 +1152,8 @@ async function forkSketch(state, input) {
|
|
|
1101
1152
|
colors,
|
|
1102
1153
|
state: buildState(parameters, colors, seed),
|
|
1103
1154
|
algorithm,
|
|
1155
|
+
...sourceDef.compositionLevel ? { compositionLevel: sourceDef.compositionLevel } : {},
|
|
1156
|
+
lineage,
|
|
1104
1157
|
...philosophy ? { philosophy } : {},
|
|
1105
1158
|
...sourceDef.themes ? { themes: [...sourceDef.themes] } : {},
|
|
1106
1159
|
...sourceDef.skills ? { skills: [...sourceDef.skills] } : {},
|
|
@@ -2062,6 +2115,13 @@ ${s.philosophy}`);
|
|
|
2062
2115
|
params[p.key] = p.default;
|
|
2063
2116
|
}
|
|
2064
2117
|
const colorPalette = colors.map((c) => c.default);
|
|
2118
|
+
const maxGeneration = Math.max(
|
|
2119
|
+
...sources.map((s) => s.lineage?.generation ?? 1)
|
|
2120
|
+
);
|
|
2121
|
+
const lineage = {
|
|
2122
|
+
blendSources: input.sourceIds,
|
|
2123
|
+
generation: maxGeneration + 1
|
|
2124
|
+
};
|
|
2065
2125
|
const timestamp = now5();
|
|
2066
2126
|
const newDef = {
|
|
2067
2127
|
genart: "1.1",
|
|
@@ -2070,6 +2130,7 @@ ${s.philosophy}`);
|
|
|
2070
2130
|
created: timestamp,
|
|
2071
2131
|
modified: timestamp,
|
|
2072
2132
|
...skills.length > 0 ? { skills } : {},
|
|
2133
|
+
lineage,
|
|
2073
2134
|
renderer: { type: renderer, version: sources[0].renderer.version },
|
|
2074
2135
|
canvas: { width: canvasWidth, height: canvasHeight },
|
|
2075
2136
|
...philosophy ? { philosophy } : {},
|
|
@@ -2296,14 +2357,25 @@ async function getGuidelines(input) {
|
|
|
2296
2357
|
color: "color",
|
|
2297
2358
|
colours: "color",
|
|
2298
2359
|
layout: "composition",
|
|
2299
|
-
palette: "color"
|
|
2360
|
+
palette: "color",
|
|
2361
|
+
painting: "painting",
|
|
2362
|
+
watercolor: "painting",
|
|
2363
|
+
ink: "illustration",
|
|
2364
|
+
illustration: "illustration",
|
|
2365
|
+
"mixed-media": "illustration",
|
|
2366
|
+
"mixed media": "illustration",
|
|
2367
|
+
process: "process",
|
|
2368
|
+
layering: "process",
|
|
2369
|
+
"mark-making": "process",
|
|
2370
|
+
refinement: "process",
|
|
2371
|
+
constraints: "process"
|
|
2300
2372
|
};
|
|
2301
2373
|
const category = categoryMap[topic];
|
|
2302
2374
|
if (!category) {
|
|
2303
2375
|
return {
|
|
2304
2376
|
success: false,
|
|
2305
2377
|
topic,
|
|
2306
|
-
error: `No guidelines found for topic: '${topic}'. Available topics: composition, color, parameters, animation, performance`,
|
|
2378
|
+
error: `No guidelines found for topic: '${topic}'. Available topics: composition, color, painting, illustration, process, parameters, animation, performance`,
|
|
2307
2379
|
guidelines: null,
|
|
2308
2380
|
relatedSkills: []
|
|
2309
2381
|
};
|
|
@@ -2330,6 +2402,138 @@ ${guidelines}`,
|
|
|
2330
2402
|
}))
|
|
2331
2403
|
};
|
|
2332
2404
|
}
|
|
2405
|
+
var CONTEXT_KEYWORDS = {
|
|
2406
|
+
// Composition keywords
|
|
2407
|
+
layout: ["golden-ratio", "rule-of-thirds", "visual-weight", "gestalt-grouping"],
|
|
2408
|
+
balance: ["visual-weight", "golden-ratio", "rule-of-thirds"],
|
|
2409
|
+
grid: ["rule-of-thirds", "gestalt-grouping", "rhythm-movement"],
|
|
2410
|
+
flow: ["rhythm-movement", "gestalt-grouping"],
|
|
2411
|
+
movement: ["rhythm-movement", "mark-making"],
|
|
2412
|
+
rhythm: ["rhythm-movement", "mark-making"],
|
|
2413
|
+
focal: ["rule-of-thirds", "visual-weight", "figure-ground"],
|
|
2414
|
+
negative: ["figure-ground", "visual-weight"],
|
|
2415
|
+
space: ["figure-ground", "visual-weight", "atmospheric-depth"],
|
|
2416
|
+
// Color keywords
|
|
2417
|
+
palette: ["color-harmony", "palette-generation", "color-mixing-strategy"],
|
|
2418
|
+
color: ["color-harmony", "color-temperature", "itten-contrasts", "color-mixing-strategy"],
|
|
2419
|
+
warm: ["color-temperature", "atmospheric-depth"],
|
|
2420
|
+
cool: ["color-temperature", "atmospheric-depth"],
|
|
2421
|
+
contrast: ["simultaneous-contrast", "itten-contrasts", "value-structure"],
|
|
2422
|
+
value: ["value-structure", "itten-contrasts", "layering-strategy"],
|
|
2423
|
+
gray: ["color-mixing-strategy", "value-structure"],
|
|
2424
|
+
// Painting keywords
|
|
2425
|
+
watercolor: ["watercolor-techniques", "layering-strategy", "material-behavior"],
|
|
2426
|
+
ink: ["ink-illustration", "mark-making", "material-behavior"],
|
|
2427
|
+
oil: ["painting-foundations", "layering-strategy", "material-behavior"],
|
|
2428
|
+
charcoal: ["material-behavior", "mark-making"],
|
|
2429
|
+
brush: ["mark-making", "material-behavior"],
|
|
2430
|
+
layer: ["layering-strategy", "mixed-media-workflow", "iterative-refinement"],
|
|
2431
|
+
texture: ["material-behavior", "mark-making"],
|
|
2432
|
+
// Process keywords
|
|
2433
|
+
study: ["thumbnail-studies", "creative-constraints", "iterative-refinement"],
|
|
2434
|
+
thumbnail: ["thumbnail-studies", "creative-constraints"],
|
|
2435
|
+
refine: ["iterative-refinement", "layering-strategy"],
|
|
2436
|
+
iterate: ["iterative-refinement", "thumbnail-studies"],
|
|
2437
|
+
depth: ["atmospheric-depth", "color-temperature", "value-structure"],
|
|
2438
|
+
atmosphere: ["atmospheric-depth", "color-temperature"],
|
|
2439
|
+
perspective: ["atmospheric-depth"],
|
|
2440
|
+
constraint: ["creative-constraints"],
|
|
2441
|
+
limit: ["creative-constraints", "color-mixing-strategy"],
|
|
2442
|
+
hatch: ["mark-making", "ink-illustration"],
|
|
2443
|
+
stipple: ["mark-making"],
|
|
2444
|
+
gestural: ["mark-making", "iterative-refinement"],
|
|
2445
|
+
mix: ["color-mixing-strategy", "mixed-media-workflow"],
|
|
2446
|
+
glaze: ["layering-strategy", "material-behavior"]
|
|
2447
|
+
};
|
|
2448
|
+
async function suggestSkills(state, input) {
|
|
2449
|
+
const allSkills = registry.list();
|
|
2450
|
+
const scored = /* @__PURE__ */ new Map();
|
|
2451
|
+
for (const skill of allSkills) {
|
|
2452
|
+
scored.set(skill.id, { score: 0, reasons: [] });
|
|
2453
|
+
}
|
|
2454
|
+
if (input.sketchId) {
|
|
2455
|
+
const loaded = state.getSketch(input.sketchId);
|
|
2456
|
+
if (loaded) {
|
|
2457
|
+
const sketch = loaded.definition;
|
|
2458
|
+
const usedSkills = new Set(sketch.skills ?? []);
|
|
2459
|
+
for (const skill of allSkills) {
|
|
2460
|
+
if (!usedSkills.has(skill.id)) {
|
|
2461
|
+
const entry = scored.get(skill.id);
|
|
2462
|
+
entry.score += 1;
|
|
2463
|
+
entry.reasons.push("not yet used in this sketch");
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
const level = sketch.compositionLevel;
|
|
2467
|
+
if (level) {
|
|
2468
|
+
const levelSkills = {
|
|
2469
|
+
study: ["thumbnail-studies", "creative-constraints", "iterative-refinement"],
|
|
2470
|
+
sketch: ["iterative-refinement", "mark-making", "layering-strategy", "color-mixing-strategy"],
|
|
2471
|
+
developed: ["layering-strategy", "material-behavior", "atmospheric-depth", "color-mixing-strategy"],
|
|
2472
|
+
exhibition: ["layering-strategy", "material-behavior", "atmospheric-depth", "iterative-refinement", "mark-making"]
|
|
2473
|
+
};
|
|
2474
|
+
for (const id of levelSkills[level] ?? []) {
|
|
2475
|
+
const entry = scored.get(id);
|
|
2476
|
+
if (entry) {
|
|
2477
|
+
entry.score += 3;
|
|
2478
|
+
entry.reasons.push(`recommended for ${level}-level work`);
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
if (sketch.layers && sketch.layers.length > 0) {
|
|
2483
|
+
const layerTypes = sketch.layers.map((l) => l.type);
|
|
2484
|
+
if (layerTypes.some((t) => t.startsWith("painting:"))) {
|
|
2485
|
+
for (const id of ["layering-strategy", "material-behavior", "iterative-refinement"]) {
|
|
2486
|
+
const entry = scored.get(id);
|
|
2487
|
+
if (entry) {
|
|
2488
|
+
entry.score += 2;
|
|
2489
|
+
entry.reasons.push("sketch uses painting layers");
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
if (input.context) {
|
|
2497
|
+
const words = input.context.toLowerCase().split(/\W+/);
|
|
2498
|
+
for (const word of words) {
|
|
2499
|
+
const matched = CONTEXT_KEYWORDS[word];
|
|
2500
|
+
if (matched) {
|
|
2501
|
+
for (const skillId of matched) {
|
|
2502
|
+
const entry = scored.get(skillId);
|
|
2503
|
+
if (entry) {
|
|
2504
|
+
entry.score += 2;
|
|
2505
|
+
if (!entry.reasons.includes(`matches context keyword "${word}"`)) {
|
|
2506
|
+
entry.reasons.push(`matches context keyword "${word}"`);
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
if (!input.sketchId && !input.context) {
|
|
2514
|
+
for (const skill of allSkills) {
|
|
2515
|
+
if (skill.category === "process") {
|
|
2516
|
+
const entry = scored.get(skill.id);
|
|
2517
|
+
entry.score += 2;
|
|
2518
|
+
entry.reasons.push("process knowledge is broadly applicable");
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
const ranked = allSkills.map((skill) => ({
|
|
2523
|
+
id: skill.id,
|
|
2524
|
+
name: skill.name,
|
|
2525
|
+
category: skill.category,
|
|
2526
|
+
complexity: skill.complexity,
|
|
2527
|
+
description: skill.description,
|
|
2528
|
+
relevanceScore: scored.get(skill.id).score,
|
|
2529
|
+
rationale: scored.get(skill.id).reasons
|
|
2530
|
+
})).filter((s) => s.relevanceScore > 0).sort((a, b) => b.relevanceScore - a.relevanceScore).slice(0, 5);
|
|
2531
|
+
return {
|
|
2532
|
+
success: true,
|
|
2533
|
+
suggestions: ranked,
|
|
2534
|
+
total: ranked.length
|
|
2535
|
+
};
|
|
2536
|
+
}
|
|
2333
2537
|
|
|
2334
2538
|
// src/tools/components.ts
|
|
2335
2539
|
var import_promises7 = require("fs/promises");
|
|
@@ -2583,7 +2787,7 @@ async function captureHtml(options) {
|
|
|
2583
2787
|
try {
|
|
2584
2788
|
await page.setViewport({ width, height, deviceScaleFactor: 1 });
|
|
2585
2789
|
await page.setContent(html, { waitUntil: "domcontentloaded", timeout: 3e4 });
|
|
2586
|
-
await new Promise((
|
|
2790
|
+
await new Promise((resolve5) => setTimeout(resolve5, waitMs));
|
|
2587
2791
|
const buffer = await page.screenshot({
|
|
2588
2792
|
type: imageType,
|
|
2589
2793
|
clip: { x: 0, y: 0, width, height },
|
|
@@ -2603,7 +2807,7 @@ async function captureHtmlMulti(options) {
|
|
|
2603
2807
|
try {
|
|
2604
2808
|
await page.setViewport({ width, height, deviceScaleFactor: 1 });
|
|
2605
2809
|
await page.setContent(html, { waitUntil: "domcontentloaded", timeout: 3e4 });
|
|
2606
|
-
await new Promise((
|
|
2810
|
+
await new Promise((resolve5) => setTimeout(resolve5, waitMs));
|
|
2607
2811
|
const pngBuffer = await page.screenshot({
|
|
2608
2812
|
type: "png",
|
|
2609
2813
|
clip: { x: 0, y: 0, width, height }
|
|
@@ -2613,7 +2817,7 @@ async function captureHtmlMulti(options) {
|
|
|
2613
2817
|
const inlineWidth = Math.round(width * scale);
|
|
2614
2818
|
const inlineHeight = Math.round(height * scale);
|
|
2615
2819
|
await page.setViewport({ width: inlineWidth, height: inlineHeight, deviceScaleFactor: 1 });
|
|
2616
|
-
await new Promise((
|
|
2820
|
+
await new Promise((resolve5) => setTimeout(resolve5, 100));
|
|
2617
2821
|
const jpegBuffer = await page.screenshot({
|
|
2618
2822
|
type: "jpeg",
|
|
2619
2823
|
quality: jpegQuality,
|
|
@@ -2774,205 +2978,1264 @@ async function captureBatch(state, input) {
|
|
|
2774
2978
|
};
|
|
2775
2979
|
}
|
|
2776
2980
|
|
|
2777
|
-
// src/tools/
|
|
2778
|
-
var import_fs = require("fs");
|
|
2779
|
-
var import_promises9 = require("fs/promises");
|
|
2780
|
-
var import_path9 = require("path");
|
|
2781
|
-
var import_archiver = __toESM(require("archiver"), 1);
|
|
2981
|
+
// src/tools/critique.ts
|
|
2782
2982
|
var import_core10 = require("@genart-dev/core");
|
|
2783
|
-
var registry3 = (0, import_core10.
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2983
|
+
var registry3 = (0, import_core10.createDefaultSkillRegistry)();
|
|
2984
|
+
var ALL_ASPECTS = [
|
|
2985
|
+
"composition",
|
|
2986
|
+
"color",
|
|
2987
|
+
"rhythm",
|
|
2988
|
+
"unity",
|
|
2989
|
+
"expression"
|
|
2990
|
+
];
|
|
2991
|
+
var SEVERITY = {
|
|
2992
|
+
study: {
|
|
2993
|
+
level: "study",
|
|
2994
|
+
description: "Fast, exploratory \u2014 value the energy of discovery over polish",
|
|
2995
|
+
focus: "Is the core idea visible? Does the sketch capture a single insight?",
|
|
2996
|
+
tolerance: "High tolerance for roughness, imbalance, and incomplete resolution. Studies should feel alive, not finished."
|
|
2997
|
+
},
|
|
2998
|
+
sketch: {
|
|
2999
|
+
level: "sketch",
|
|
3000
|
+
description: "Intentional but rough \u2014 the idea should read clearly",
|
|
3001
|
+
focus: "Do composition and color serve the concept? Are parameters well-chosen?",
|
|
3002
|
+
tolerance: "Moderate tolerance. Unresolved edges and raw marks are fine, but the structure should be deliberate."
|
|
3003
|
+
},
|
|
3004
|
+
developed: {
|
|
3005
|
+
level: "developed",
|
|
3006
|
+
description: "Refined \u2014 every major decision should be justified",
|
|
3007
|
+
focus: "Do all elements work together? Is there a clear visual hierarchy? Does the palette feel cohesive?",
|
|
3008
|
+
tolerance: "Low tolerance for accidental imbalance. Rough areas should be intentional, not neglected."
|
|
3009
|
+
},
|
|
3010
|
+
exhibition: {
|
|
3011
|
+
level: "exhibition",
|
|
3012
|
+
description: "Polished \u2014 every element earns its place",
|
|
3013
|
+
focus: "Could you defend every choice? Does the piece hold up under sustained viewing? Is the concept fully realized?",
|
|
3014
|
+
tolerance: "Minimal tolerance. Each mark, color, and spatial relationship should feel inevitable."
|
|
2802
3015
|
}
|
|
3016
|
+
};
|
|
3017
|
+
function buildCompositionFramework() {
|
|
3018
|
+
return {
|
|
3019
|
+
aspect: "composition",
|
|
3020
|
+
questions: [
|
|
3021
|
+
"Where does the eye land first? Is that the intended focal point?",
|
|
3022
|
+
"Is there a clear visual hierarchy (primary, secondary, tertiary)?",
|
|
3023
|
+
"How does the composition use the edges and corners of the canvas?",
|
|
3024
|
+
"Is negative space working actively or is it leftover?",
|
|
3025
|
+
"Does the arrangement feel balanced or intentionally unbalanced?"
|
|
3026
|
+
],
|
|
3027
|
+
principles: [
|
|
3028
|
+
"Visual weight distribution \u2014 dense, dark, saturated, or detailed areas carry more weight",
|
|
3029
|
+
"Entry points and eye paths \u2014 the viewer needs a way in and a journey through the piece",
|
|
3030
|
+
"Edge tension \u2014 elements near canvas edges create tension; use this deliberately",
|
|
3031
|
+
"Rule of thirds / golden ratio \u2014 useful starting points, not rigid rules",
|
|
3032
|
+
"Figure-ground clarity \u2014 the relationship between positive and negative space"
|
|
3033
|
+
],
|
|
3034
|
+
pitfalls: [
|
|
3035
|
+
"Centering everything \u2014 creates static compositions unless intentionally symmetrical",
|
|
3036
|
+
"Filling the canvas uniformly \u2014 denies the viewer rest areas and focal emphasis",
|
|
3037
|
+
"Tangent lines \u2014 elements barely touching edges or each other create visual discomfort",
|
|
3038
|
+
"Competing focal points \u2014 multiple areas of equal emphasis confuse the eye",
|
|
3039
|
+
"Ignoring the canvas aspect ratio \u2014 composition should respond to the format"
|
|
3040
|
+
]
|
|
3041
|
+
};
|
|
2803
3042
|
}
|
|
2804
|
-
function
|
|
2805
|
-
return
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
3043
|
+
function buildColorFramework() {
|
|
3044
|
+
return {
|
|
3045
|
+
aspect: "color",
|
|
3046
|
+
questions: [
|
|
3047
|
+
"Does the palette feel intentional or arbitrary?",
|
|
3048
|
+
"Is there a dominant color temperature (warm/cool) or a deliberate tension between them?",
|
|
3049
|
+
"How many distinct hues are active? Is that number serving the concept?",
|
|
3050
|
+
"Are value contrasts (light/dark) creating readable structure?",
|
|
3051
|
+
"Do any colors feel out of place \u2014 or is dissonance intentional?"
|
|
3052
|
+
],
|
|
3053
|
+
principles: [
|
|
3054
|
+
"Color harmony \u2014 analogous, complementary, triadic, or split-complementary relationships",
|
|
3055
|
+
"Value structure \u2014 squint at the piece; the composition should read in grayscale",
|
|
3056
|
+
"Temperature as depth \u2014 warm advances, cool recedes (atmospheric perspective)",
|
|
3057
|
+
"Saturation as emphasis \u2014 high saturation draws the eye; use it sparingly for focus",
|
|
3058
|
+
"Color proportion \u2014 unequal amounts create interest (e.g., 60-30-10 ratio)"
|
|
3059
|
+
],
|
|
3060
|
+
pitfalls: [
|
|
3061
|
+
"Too many fully saturated colors competing for attention",
|
|
3062
|
+
"No value range \u2014 all mid-tones flatten the piece",
|
|
3063
|
+
"Random color assignment \u2014 palette should derive from concept, not just randomness",
|
|
3064
|
+
"Ignoring simultaneous contrast \u2014 adjacent colors alter each other's appearance",
|
|
3065
|
+
"Uniform opacity everywhere \u2014 varying transparency adds depth and atmosphere"
|
|
3066
|
+
]
|
|
2815
3067
|
};
|
|
2816
|
-
return { ...sketch, state: newState };
|
|
2817
3068
|
}
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
default:
|
|
2844
|
-
throw new Error(`Unsupported export format: '${input.format}'`);
|
|
2845
|
-
}
|
|
3069
|
+
function buildRhythmFramework() {
|
|
3070
|
+
return {
|
|
3071
|
+
aspect: "rhythm",
|
|
3072
|
+
questions: [
|
|
3073
|
+
"Is there a repeating visual motif or interval?",
|
|
3074
|
+
"Does the rhythm accelerate, decelerate, or remain steady?",
|
|
3075
|
+
"Are there moments of syncopation \u2014 unexpected breaks in the pattern?",
|
|
3076
|
+
"Does the rhythm contribute to or fight against the composition?",
|
|
3077
|
+
"Is there scale variation \u2014 does the motif appear at multiple sizes?"
|
|
3078
|
+
],
|
|
3079
|
+
principles: [
|
|
3080
|
+
"Regular rhythm creates calm and order; irregular rhythm creates energy",
|
|
3081
|
+
"Progressive rhythm (gradual change) creates movement and depth",
|
|
3082
|
+
"Alternating rhythm adds complexity without chaos",
|
|
3083
|
+
"Rhythm at multiple scales (fractal repetition) creates richness",
|
|
3084
|
+
"Silence (empty intervals) is as important as sound (marked intervals)"
|
|
3085
|
+
],
|
|
3086
|
+
pitfalls: [
|
|
3087
|
+
"Perfectly regular grids without variation feel mechanical, not generative",
|
|
3088
|
+
"Random distribution reads as noise, not rhythm",
|
|
3089
|
+
"Single-scale repetition feels monotonous \u2014 vary size, spacing, or density",
|
|
3090
|
+
"Rhythm that ignores the composition's focal structure",
|
|
3091
|
+
"Over-complexity \u2014 too many overlapping rhythms create visual noise"
|
|
3092
|
+
]
|
|
3093
|
+
};
|
|
2846
3094
|
}
|
|
2847
|
-
|
|
2848
|
-
const adapter = registry3.resolve(sketch.renderer.type);
|
|
2849
|
-
const html = adapter.generateStandaloneHTML(sketch);
|
|
2850
|
-
const content = Buffer.from(html, "utf-8");
|
|
2851
|
-
await (0, import_promises9.writeFile)(outputPath, content);
|
|
3095
|
+
function buildUnityFramework() {
|
|
2852
3096
|
return {
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
3097
|
+
aspect: "unity",
|
|
3098
|
+
questions: [
|
|
3099
|
+
"Does the piece feel like one cohesive work or disconnected parts?",
|
|
3100
|
+
"Is there a unifying visual language (consistent mark quality, shape vocabulary)?",
|
|
3101
|
+
"Do the parameters work together or do some feel bolted on?",
|
|
3102
|
+
"Would removing any element weaken the whole?",
|
|
3103
|
+
"Does the algorithm express a single clear idea?"
|
|
3104
|
+
],
|
|
3105
|
+
principles: [
|
|
3106
|
+
"Unity through repetition \u2014 shared elements tie the composition together",
|
|
3107
|
+
"Unity through proximity \u2014 grouped elements feel related",
|
|
3108
|
+
"Unity through continuation \u2014 aligned elements create visual connections",
|
|
3109
|
+
"Variety within unity \u2014 enough variation to hold interest, enough consistency to cohere",
|
|
3110
|
+
"Conceptual unity \u2014 all visual decisions serve the stated philosophy"
|
|
3111
|
+
],
|
|
3112
|
+
pitfalls: [
|
|
3113
|
+
"Feature accumulation \u2014 adding elements that don't serve the core concept",
|
|
3114
|
+
"Inconsistent mark quality \u2014 mixing precise geometry with organic marks without intention",
|
|
3115
|
+
"Disconnected color and form \u2014 palette that doesn't relate to the spatial structure",
|
|
3116
|
+
"Parameter sprawl \u2014 too many controls that don't interact meaningfully",
|
|
3117
|
+
"Style mixing without integration \u2014 combining techniques that don't speak to each other"
|
|
3118
|
+
]
|
|
2859
3119
|
};
|
|
2860
3120
|
}
|
|
2861
|
-
|
|
2862
|
-
const adapter = registry3.resolve(sketch.renderer.type);
|
|
2863
|
-
const html = adapter.generateStandaloneHTML(sketch);
|
|
2864
|
-
const width = input.width ?? sketch.canvas.width;
|
|
2865
|
-
const height = input.height ?? sketch.canvas.height;
|
|
2866
|
-
const result = await captureHtml({ html, width, height });
|
|
2867
|
-
await (0, import_promises9.writeFile)(input.outputPath, result.bytes);
|
|
3121
|
+
function buildExpressionFramework() {
|
|
2868
3122
|
return {
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
3123
|
+
aspect: "expression",
|
|
3124
|
+
questions: [
|
|
3125
|
+
"What mood or feeling does this piece evoke?",
|
|
3126
|
+
"Is the generative process visible in the output? Should it be?",
|
|
3127
|
+
"Does the algorithm's logic contribute to the emotional quality?",
|
|
3128
|
+
"Is there a sense of the unexpected \u2014 does the piece surprise even its creator?",
|
|
3129
|
+
"Does the philosophy statement match the visual experience?"
|
|
3130
|
+
],
|
|
3131
|
+
principles: [
|
|
3132
|
+
"Generative art is a conversation between intention and emergence",
|
|
3133
|
+
"The algorithm is a medium \u2014 its constraints and affordances shape expression",
|
|
3134
|
+
"Controlled randomness creates life; pure randomness creates noise",
|
|
3135
|
+
"The seed is a collaborator \u2014 different seeds should produce meaningfully different moods",
|
|
3136
|
+
"Process and result are both the artwork \u2014 the code embodies artistic decisions"
|
|
3137
|
+
],
|
|
3138
|
+
pitfalls: [
|
|
3139
|
+
"Over-control \u2014 leaving no room for generative surprise",
|
|
3140
|
+
"Under-control \u2014 no discernible artistic intention behind the randomness",
|
|
3141
|
+
"Technique as end \u2014 impressive code that produces emotionally flat output",
|
|
3142
|
+
"Derivative work \u2014 reproducing established generative art tropes without adding perspective",
|
|
3143
|
+
"Mismatched intent \u2014 the philosophy says one thing but the visual says another"
|
|
3144
|
+
]
|
|
2875
3145
|
};
|
|
2876
3146
|
}
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
3147
|
+
var ASPECT_BUILDERS = {
|
|
3148
|
+
composition: buildCompositionFramework,
|
|
3149
|
+
color: buildColorFramework,
|
|
3150
|
+
rhythm: buildRhythmFramework,
|
|
3151
|
+
unity: buildUnityFramework,
|
|
3152
|
+
expression: buildExpressionFramework
|
|
3153
|
+
};
|
|
3154
|
+
async function critiqueSketch(state, input) {
|
|
3155
|
+
state.requireWorkspace();
|
|
3156
|
+
let sketchId;
|
|
3157
|
+
if (input.sketchId) {
|
|
3158
|
+
sketchId = input.sketchId;
|
|
3159
|
+
} else if (state.selection.size > 0) {
|
|
3160
|
+
sketchId = [...state.selection][0];
|
|
3161
|
+
} else {
|
|
3162
|
+
throw new Error("No sketch specified and nothing selected");
|
|
2892
3163
|
}
|
|
2893
|
-
const
|
|
2894
|
-
const
|
|
2895
|
-
const
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
const
|
|
2904
|
-
|
|
2905
|
-
|
|
3164
|
+
const loaded = state.requireSketch(sketchId);
|
|
3165
|
+
const sketch = loaded.definition;
|
|
3166
|
+
const capture = await captureScreenshot(state, {
|
|
3167
|
+
target: "sketch",
|
|
3168
|
+
sketchId,
|
|
3169
|
+
previewSize: input.previewSize ?? 400
|
|
3170
|
+
});
|
|
3171
|
+
const aspects = input.aspects ?? [...ALL_ASPECTS];
|
|
3172
|
+
const frameworks = aspects.map((a) => ASPECT_BUILDERS[a]());
|
|
3173
|
+
const level = sketch.compositionLevel ?? "sketch";
|
|
3174
|
+
const severity = SEVERITY[level] ?? SEVERITY["sketch"];
|
|
3175
|
+
const relevantSkills = gatherRelevantSkills(aspects);
|
|
3176
|
+
const metadata = {
|
|
2906
3177
|
success: true,
|
|
2907
|
-
sketchId
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
3178
|
+
sketchId,
|
|
3179
|
+
title: sketch.title,
|
|
3180
|
+
compositionLevel: level,
|
|
3181
|
+
philosophy: sketch.philosophy ?? null,
|
|
3182
|
+
severity: {
|
|
3183
|
+
level: severity.level,
|
|
3184
|
+
description: severity.description,
|
|
3185
|
+
focus: severity.focus,
|
|
3186
|
+
tolerance: severity.tolerance
|
|
3187
|
+
},
|
|
3188
|
+
frameworks,
|
|
3189
|
+
relevantSkills,
|
|
3190
|
+
instructions: [
|
|
3191
|
+
"Use the image above and the frameworks below to perform a structured self-critique.",
|
|
3192
|
+
`Calibrate your critique to the ${severity.level} level: ${severity.description}`,
|
|
3193
|
+
"For each aspect, answer the questions, check the principles, and watch for the pitfalls.",
|
|
3194
|
+
"Be honest but constructive \u2014 identify what works as well as what could improve.",
|
|
3195
|
+
"End with 2-3 specific, actionable improvements ranked by impact."
|
|
3196
|
+
]
|
|
2913
3197
|
};
|
|
2914
|
-
}
|
|
2915
|
-
async function exportAlgorithm(sketch, outputPath) {
|
|
2916
|
-
const content = Buffer.from(sketch.algorithm, "utf-8");
|
|
2917
|
-
await (0, import_promises9.writeFile)(outputPath, content);
|
|
2918
3198
|
return {
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
format: "algorithm",
|
|
2922
|
-
outputPath,
|
|
2923
|
-
fileSize: content.byteLength,
|
|
2924
|
-
renderer: sketch.renderer.type
|
|
3199
|
+
metadata,
|
|
3200
|
+
previewJpegBase64: capture.previewJpegBase64
|
|
2925
3201
|
};
|
|
2926
3202
|
}
|
|
2927
|
-
async function
|
|
2928
|
-
|
|
2929
|
-
const
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
const
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
3203
|
+
async function compareSketches(state, input) {
|
|
3204
|
+
state.requireWorkspace();
|
|
3205
|
+
const ids = input.sketchIds;
|
|
3206
|
+
if (ids.length < 2) {
|
|
3207
|
+
throw new Error("compare_sketches requires at least 2 sketch IDs");
|
|
3208
|
+
}
|
|
3209
|
+
if (ids.length > 4) {
|
|
3210
|
+
throw new Error("compare_sketches supports a maximum of 4 sketches");
|
|
3211
|
+
}
|
|
3212
|
+
const sketchInfos = ids.map((id) => {
|
|
3213
|
+
const loaded = state.requireSketch(id);
|
|
3214
|
+
return {
|
|
3215
|
+
id,
|
|
3216
|
+
title: loaded.definition.title,
|
|
3217
|
+
compositionLevel: loaded.definition.compositionLevel ?? "sketch",
|
|
3218
|
+
philosophy: loaded.definition.philosophy ?? null,
|
|
3219
|
+
renderer: loaded.definition.renderer.type,
|
|
3220
|
+
seed: loaded.definition.state.seed
|
|
3221
|
+
};
|
|
2941
3222
|
});
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
3223
|
+
const batchResult = await captureBatch(state, {
|
|
3224
|
+
sketchIds: ids,
|
|
3225
|
+
previewSize: input.previewSize ?? 300
|
|
3226
|
+
});
|
|
3227
|
+
const previews = batchResult.items.map((item) => ({
|
|
3228
|
+
sketchId: item.metadata["sketchId"],
|
|
3229
|
+
inlineJpegBase64: item.inlineJpegBase64
|
|
3230
|
+
}));
|
|
3231
|
+
const aspects = input.aspects ?? [...ALL_ASPECTS];
|
|
3232
|
+
const frameworks = aspects.map((a) => ASPECT_BUILDERS[a]());
|
|
3233
|
+
const comparisonQuestions = aspects.map((aspect) => ({
|
|
3234
|
+
aspect,
|
|
3235
|
+
questions: buildComparisonQuestions(aspect, sketchInfos.length)
|
|
3236
|
+
}));
|
|
3237
|
+
const metadata = {
|
|
2951
3238
|
success: true,
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
3239
|
+
sketches: sketchInfos,
|
|
3240
|
+
aspects,
|
|
3241
|
+
frameworks,
|
|
3242
|
+
comparisonQuestions,
|
|
3243
|
+
instructions: [
|
|
3244
|
+
`Compare the ${ids.length} sketches shown above across the specified aspects.`,
|
|
3245
|
+
"For each aspect, use the framework questions and comparison questions to analyze differences.",
|
|
3246
|
+
"Identify which sketch handles each aspect most effectively and why.",
|
|
3247
|
+
"Note where sketches complement each other \u2014 techniques from one could improve another.",
|
|
3248
|
+
"End with a ranking per aspect and overall, with specific observations justifying each placement."
|
|
3249
|
+
]
|
|
3250
|
+
};
|
|
3251
|
+
return { metadata, previews };
|
|
3252
|
+
}
|
|
3253
|
+
function buildComparisonQuestions(aspect, count) {
|
|
3254
|
+
const base = {
|
|
3255
|
+
composition: [
|
|
3256
|
+
"Which sketch has the strongest focal point?",
|
|
3257
|
+
"How do the compositions differ in their use of space?",
|
|
3258
|
+
"Which creates the most effective visual hierarchy?"
|
|
3259
|
+
],
|
|
3260
|
+
color: [
|
|
3261
|
+
"Which palette feels most intentional?",
|
|
3262
|
+
"How do the value ranges compare \u2014 which has the strongest lights and darks?",
|
|
3263
|
+
"Which color temperature creates the most effective mood?"
|
|
3264
|
+
],
|
|
3265
|
+
rhythm: [
|
|
3266
|
+
"Which sketch has the most engaging visual rhythm?",
|
|
3267
|
+
"How do the rhythmic structures differ \u2014 regular vs progressive vs irregular?",
|
|
3268
|
+
"Which achieves the best balance of repetition and variation?"
|
|
3269
|
+
],
|
|
3270
|
+
unity: [
|
|
3271
|
+
"Which sketch feels most cohesive as a single work?",
|
|
3272
|
+
"Where does unity break down in each \u2014 what elements feel disconnected?",
|
|
3273
|
+
"Which has the tightest relationship between concept and execution?"
|
|
3274
|
+
],
|
|
3275
|
+
expression: [
|
|
3276
|
+
"Which sketch evokes the strongest emotional response?",
|
|
3277
|
+
"How does each sketch's generative process contribute to its expression?",
|
|
3278
|
+
"Which most successfully balances intention with emergence?"
|
|
2962
3279
|
]
|
|
2963
3280
|
};
|
|
3281
|
+
const questions = [...base[aspect]];
|
|
3282
|
+
if (count > 2) {
|
|
3283
|
+
questions.push(
|
|
3284
|
+
`Could elements from different sketches be combined to create something stronger?`
|
|
3285
|
+
);
|
|
3286
|
+
}
|
|
3287
|
+
return questions;
|
|
3288
|
+
}
|
|
3289
|
+
function gatherRelevantSkills(aspects) {
|
|
3290
|
+
const aspectToCategory = {
|
|
3291
|
+
composition: ["composition"],
|
|
3292
|
+
color: ["color"],
|
|
3293
|
+
rhythm: ["composition"],
|
|
3294
|
+
unity: ["composition", "color"],
|
|
3295
|
+
expression: ["process"]
|
|
3296
|
+
};
|
|
3297
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3298
|
+
const result = [];
|
|
3299
|
+
for (const aspect of aspects) {
|
|
3300
|
+
const categories = aspectToCategory[aspect];
|
|
3301
|
+
for (const cat of categories) {
|
|
3302
|
+
const skills = registry3.list(cat);
|
|
3303
|
+
for (const skill of skills) {
|
|
3304
|
+
if (!seen.has(skill.id)) {
|
|
3305
|
+
seen.add(skill.id);
|
|
3306
|
+
result.push({ id: skill.id, name: skill.name, relevantTo: aspect });
|
|
3307
|
+
}
|
|
3308
|
+
}
|
|
3309
|
+
}
|
|
3310
|
+
}
|
|
3311
|
+
return result;
|
|
2964
3312
|
}
|
|
2965
3313
|
|
|
2966
|
-
// src/tools/
|
|
2967
|
-
|
|
2968
|
-
|
|
3314
|
+
// src/tools/series.ts
|
|
3315
|
+
var import_promises9 = require("fs/promises");
|
|
3316
|
+
var import_path9 = require("path");
|
|
3317
|
+
var import_core11 = require("@genart-dev/core");
|
|
3318
|
+
function now6() {
|
|
3319
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
2969
3320
|
}
|
|
2970
|
-
var
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
3321
|
+
var KEBAB_RE2 = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
3322
|
+
function validateKebabId2(id) {
|
|
3323
|
+
if (!KEBAB_RE2.test(id)) {
|
|
3324
|
+
throw new Error(
|
|
3325
|
+
"ID must be kebab-case: lowercase letters, numbers, hyphens"
|
|
3326
|
+
);
|
|
3327
|
+
}
|
|
3328
|
+
}
|
|
3329
|
+
var VALID_STAGES = [
|
|
3330
|
+
"studies",
|
|
3331
|
+
"drafts",
|
|
3332
|
+
"refinements",
|
|
3333
|
+
"finals"
|
|
3334
|
+
];
|
|
3335
|
+
var STAGE_TO_LEVEL = {
|
|
3336
|
+
studies: "study",
|
|
3337
|
+
drafts: "sketch",
|
|
3338
|
+
refinements: "developed",
|
|
3339
|
+
finals: "exhibition"
|
|
3340
|
+
};
|
|
3341
|
+
var LEVEL_SCALE = {
|
|
3342
|
+
study: 1,
|
|
3343
|
+
sketch: 1,
|
|
3344
|
+
developed: 1.5,
|
|
3345
|
+
exhibition: 2
|
|
3346
|
+
};
|
|
3347
|
+
async function createSeries(state, input) {
|
|
3348
|
+
const ws = state.requireWorkspace();
|
|
3349
|
+
const id = input.label.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
3350
|
+
if (!id) {
|
|
3351
|
+
throw new Error("Could not derive a valid ID from the label");
|
|
3352
|
+
}
|
|
3353
|
+
if (ws.series?.some((s) => s.id === id)) {
|
|
3354
|
+
throw new Error(`Series with ID '${id}' already exists in workspace`);
|
|
3355
|
+
}
|
|
3356
|
+
const stages = input.stages ?? [...VALID_STAGES];
|
|
3357
|
+
for (const stage of stages) {
|
|
3358
|
+
if (!VALID_STAGES.includes(stage)) {
|
|
3359
|
+
throw new Error(
|
|
3360
|
+
`Invalid stage: '${stage}'. Valid stages: ${VALID_STAGES.join(", ")}`
|
|
3361
|
+
);
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
const sketchFiles = input.sketchFiles ?? [];
|
|
3365
|
+
for (const file of sketchFiles) {
|
|
3366
|
+
const found = ws.sketches.some((s) => s.file === file);
|
|
3367
|
+
if (!found) {
|
|
3368
|
+
throw new Error(
|
|
3369
|
+
`Sketch file '${file}' not found in workspace`
|
|
3370
|
+
);
|
|
3371
|
+
}
|
|
3372
|
+
}
|
|
3373
|
+
const series = {
|
|
3374
|
+
id,
|
|
3375
|
+
label: input.label,
|
|
3376
|
+
narrative: input.narrative,
|
|
3377
|
+
intent: input.intent,
|
|
3378
|
+
...input.progression ? { progression: input.progression } : {},
|
|
3379
|
+
stages,
|
|
3380
|
+
sketchFiles
|
|
3381
|
+
};
|
|
3382
|
+
state.workspace = {
|
|
3383
|
+
...ws,
|
|
3384
|
+
modified: now6(),
|
|
3385
|
+
series: [...ws.series ?? [], series]
|
|
3386
|
+
};
|
|
3387
|
+
const workspaceJson = (0, import_core11.serializeWorkspace)(state.workspace);
|
|
3388
|
+
if (!state.remoteMode) {
|
|
3389
|
+
await (0, import_promises9.writeFile)(state.workspacePath, workspaceJson, "utf-8");
|
|
3390
|
+
}
|
|
3391
|
+
state.emitMutation("workspace:updated", { seriesAdded: id });
|
|
3392
|
+
return {
|
|
3393
|
+
success: true,
|
|
3394
|
+
series: {
|
|
3395
|
+
id,
|
|
3396
|
+
label: input.label,
|
|
3397
|
+
narrative: input.narrative,
|
|
3398
|
+
intent: input.intent,
|
|
3399
|
+
stages,
|
|
3400
|
+
sketchCount: sketchFiles.length
|
|
3401
|
+
},
|
|
3402
|
+
workspaceContent: workspaceJson
|
|
3403
|
+
};
|
|
3404
|
+
}
|
|
3405
|
+
async function developConcept(_state, input) {
|
|
3406
|
+
const medium = input.medium ?? "p5";
|
|
3407
|
+
return {
|
|
3408
|
+
success: true,
|
|
3409
|
+
conceptPlan: {
|
|
3410
|
+
concept: input.concept,
|
|
3411
|
+
medium,
|
|
3412
|
+
mood: {
|
|
3413
|
+
instruction: "Define the emotional quality this concept should evoke.",
|
|
3414
|
+
prompts: [
|
|
3415
|
+
"What feeling should the viewer experience?",
|
|
3416
|
+
"Is this contemplative, energetic, unsettling, serene?",
|
|
3417
|
+
"What time of day, season, or environment does this concept suggest?"
|
|
3418
|
+
]
|
|
3419
|
+
},
|
|
3420
|
+
palette: {
|
|
3421
|
+
instruction: "Design a color strategy that serves the mood.",
|
|
3422
|
+
prompts: [
|
|
3423
|
+
"What color temperature dominates (warm/cool)?",
|
|
3424
|
+
"How many distinct hues are needed?",
|
|
3425
|
+
"Should saturation be high (bold, graphic) or low (subtle, atmospheric)?",
|
|
3426
|
+
"What value range (light-to-dark contrast) supports the concept?"
|
|
3427
|
+
]
|
|
3428
|
+
},
|
|
3429
|
+
composition: {
|
|
3430
|
+
instruction: "Plan the spatial structure.",
|
|
3431
|
+
prompts: [
|
|
3432
|
+
"Where should the viewer's eye land first?",
|
|
3433
|
+
"Is the composition centered, asymmetric, or edge-driven?",
|
|
3434
|
+
"How does negative space contribute to the concept?",
|
|
3435
|
+
"What rhythm (regular, progressive, chaotic) serves the idea?"
|
|
3436
|
+
]
|
|
3437
|
+
},
|
|
3438
|
+
skills: {
|
|
3439
|
+
instruction: "Identify design skills to load for this concept.",
|
|
3440
|
+
prompts: [
|
|
3441
|
+
"Which composition skill applies (rule-of-thirds, golden-ratio, gestalt)?",
|
|
3442
|
+
"Which color skill applies (color-harmony, color-temperature, simultaneous-contrast)?",
|
|
3443
|
+
"Are there process skills needed (layering-strategy, iterative-refinement, thumbnail-studies)?",
|
|
3444
|
+
"Consider using `suggest_skills` with the concept as context."
|
|
3445
|
+
]
|
|
3446
|
+
},
|
|
3447
|
+
seriesStructure: {
|
|
3448
|
+
instruction: "Plan the body of work.",
|
|
3449
|
+
prompts: [
|
|
3450
|
+
"How many studies should explore the core idea (3-6 recommended)?",
|
|
3451
|
+
"What aspect varies between studies (color, density, rhythm, scale)?",
|
|
3452
|
+
"Which studies should be developed further into drafts?",
|
|
3453
|
+
"What progression tells the most compelling story?"
|
|
3454
|
+
],
|
|
3455
|
+
recommendedStages: ["studies", "drafts", "refinements", "finals"]
|
|
3456
|
+
}
|
|
3457
|
+
},
|
|
3458
|
+
nextSteps: [
|
|
3459
|
+
"1. Use `create_series` with a label, narrative, and intent derived from this plan.",
|
|
3460
|
+
"2. Create 3-6 study-level sketches using `create_sketch` with compositionLevel: 'study'.",
|
|
3461
|
+
"3. Use `critique_sketch` on each study to evaluate against the concept.",
|
|
3462
|
+
"4. Use `promote_sketch` to advance the best studies to drafts.",
|
|
3463
|
+
"5. Iterate: critique \u2192 refine \u2192 promote through stages.",
|
|
3464
|
+
"6. Use `series_summary` to capture the full progression."
|
|
3465
|
+
]
|
|
3466
|
+
};
|
|
3467
|
+
}
|
|
3468
|
+
async function seriesSummary(state, input) {
|
|
3469
|
+
const ws = state.requireWorkspace();
|
|
3470
|
+
const series = ws.series?.find((s) => s.id === input.seriesId);
|
|
3471
|
+
if (!series) {
|
|
3472
|
+
throw new Error(`Series '${input.seriesId}' not found in workspace`);
|
|
3473
|
+
}
|
|
3474
|
+
const sketchInfos = [];
|
|
3475
|
+
const loadedIds = [];
|
|
3476
|
+
for (const file of series.sketchFiles) {
|
|
3477
|
+
let found = false;
|
|
3478
|
+
for (const [id, loaded] of state.sketches) {
|
|
3479
|
+
if ((0, import_path9.basename)(loaded.path) === file) {
|
|
3480
|
+
const def = loaded.definition;
|
|
3481
|
+
sketchInfos.push({
|
|
3482
|
+
id,
|
|
3483
|
+
title: def.title,
|
|
3484
|
+
file,
|
|
3485
|
+
compositionLevel: def.compositionLevel ?? "sketch",
|
|
3486
|
+
lineage: def.lineage ?? null,
|
|
3487
|
+
renderer: def.renderer.type,
|
|
3488
|
+
canvas: `${def.canvas.width}x${def.canvas.height}`,
|
|
3489
|
+
seed: def.state.seed,
|
|
3490
|
+
parameterCount: def.parameters.length,
|
|
3491
|
+
colorCount: def.colors.length,
|
|
3492
|
+
philosophy: def.philosophy ?? null
|
|
3493
|
+
});
|
|
3494
|
+
loadedIds.push(id);
|
|
3495
|
+
found = true;
|
|
3496
|
+
break;
|
|
3497
|
+
}
|
|
3498
|
+
}
|
|
3499
|
+
if (!found) {
|
|
3500
|
+
sketchInfos.push({ file, status: "not loaded" });
|
|
3501
|
+
}
|
|
3502
|
+
}
|
|
3503
|
+
let previews;
|
|
3504
|
+
if (input.captureScreenshots !== false && loadedIds.length > 0) {
|
|
3505
|
+
const batchResult = await captureBatch(state, {
|
|
3506
|
+
sketchIds: loadedIds,
|
|
3507
|
+
previewSize: input.previewSize ?? 300
|
|
3508
|
+
});
|
|
3509
|
+
previews = batchResult.items.map((item) => ({
|
|
3510
|
+
sketchId: item.metadata["sketchId"],
|
|
3511
|
+
inlineJpegBase64: item.inlineJpegBase64
|
|
3512
|
+
}));
|
|
3513
|
+
}
|
|
3514
|
+
const metadata = {
|
|
3515
|
+
success: true,
|
|
3516
|
+
series: {
|
|
3517
|
+
id: series.id,
|
|
3518
|
+
label: series.label,
|
|
3519
|
+
narrative: series.narrative,
|
|
3520
|
+
intent: series.intent,
|
|
3521
|
+
progression: series.progression ?? null,
|
|
3522
|
+
stages: series.stages ?? null
|
|
3523
|
+
},
|
|
3524
|
+
sketches: sketchInfos,
|
|
3525
|
+
summary: {
|
|
3526
|
+
totalSketches: series.sketchFiles.length,
|
|
3527
|
+
loadedSketches: loadedIds.length,
|
|
3528
|
+
compositionLevels: countBy(
|
|
3529
|
+
sketchInfos.filter((s) => s["compositionLevel"]).map((s) => s["compositionLevel"])
|
|
3530
|
+
)
|
|
3531
|
+
},
|
|
3532
|
+
instructions: [
|
|
3533
|
+
"Review the series progression from studies through finals.",
|
|
3534
|
+
"Evaluate whether the narrative and intent are reflected in the body of work.",
|
|
3535
|
+
"Consider: does each sketch build on its predecessors? Is there a clear evolution?",
|
|
3536
|
+
"Identify the strongest and weakest pieces. What makes them succeed or fail?",
|
|
3537
|
+
"Document insights and decisions in the series narrative."
|
|
3538
|
+
]
|
|
3539
|
+
};
|
|
3540
|
+
return { metadata, previews };
|
|
3541
|
+
}
|
|
3542
|
+
async function promoteSketch(state, input) {
|
|
3543
|
+
const ws = state.requireWorkspace();
|
|
3544
|
+
const source = state.requireSketch(input.sketchId);
|
|
3545
|
+
const sourceDef = source.definition;
|
|
3546
|
+
if (!VALID_STAGES.includes(input.toStage)) {
|
|
3547
|
+
throw new Error(
|
|
3548
|
+
`Invalid stage: '${input.toStage}'. Valid stages: ${VALID_STAGES.join(", ")}`
|
|
3549
|
+
);
|
|
3550
|
+
}
|
|
3551
|
+
const targetLevel = STAGE_TO_LEVEL[input.toStage];
|
|
3552
|
+
const scale = LEVEL_SCALE[targetLevel];
|
|
3553
|
+
const newId = input.newId ?? `${input.sketchId}-${input.toStage.replace(/s$/, "")}`;
|
|
3554
|
+
validateKebabId2(newId);
|
|
3555
|
+
if (state.getSketch(newId)) {
|
|
3556
|
+
throw new Error(`Sketch with ID '${newId}' already exists`);
|
|
3557
|
+
}
|
|
3558
|
+
const newWidth = Math.round(sourceDef.canvas.width * scale);
|
|
3559
|
+
const newHeight = Math.round(sourceDef.canvas.height * scale);
|
|
3560
|
+
const sourceGeneration = sourceDef.lineage?.generation ?? 1;
|
|
3561
|
+
const title = input.title ?? `${sourceDef.title} (${input.toStage.replace(/s$/, "")})`;
|
|
3562
|
+
const ts = now6();
|
|
3563
|
+
const promotedDef = {
|
|
3564
|
+
genart: "1.1",
|
|
3565
|
+
id: newId,
|
|
3566
|
+
title,
|
|
3567
|
+
created: ts,
|
|
3568
|
+
modified: ts,
|
|
3569
|
+
renderer: sourceDef.renderer,
|
|
3570
|
+
canvas: { width: newWidth, height: newHeight },
|
|
3571
|
+
parameters: [...sourceDef.parameters],
|
|
3572
|
+
colors: [...sourceDef.colors],
|
|
3573
|
+
state: {
|
|
3574
|
+
seed: sourceDef.state.seed,
|
|
3575
|
+
params: { ...sourceDef.state.params },
|
|
3576
|
+
colorPalette: [...sourceDef.state.colorPalette]
|
|
3577
|
+
},
|
|
3578
|
+
algorithm: sourceDef.algorithm,
|
|
3579
|
+
compositionLevel: targetLevel,
|
|
3580
|
+
lineage: {
|
|
3581
|
+
parentId: input.sketchId,
|
|
3582
|
+
parentTitle: sourceDef.title,
|
|
3583
|
+
generation: sourceGeneration + 1
|
|
3584
|
+
},
|
|
3585
|
+
...sourceDef.philosophy ? { philosophy: sourceDef.philosophy } : {},
|
|
3586
|
+
...sourceDef.themes ? { themes: [...sourceDef.themes] } : {},
|
|
3587
|
+
...sourceDef.skills ? { skills: [...sourceDef.skills] } : {},
|
|
3588
|
+
...sourceDef.components ? { components: sourceDef.components } : {},
|
|
3589
|
+
...sourceDef.symbols ? { symbols: sourceDef.symbols } : {},
|
|
3590
|
+
...input.agent ? { agent: input.agent } : {},
|
|
3591
|
+
...input.model ? { model: input.model } : {}
|
|
3592
|
+
};
|
|
3593
|
+
const sourceDir = (0, import_path9.dirname)(source.path);
|
|
3594
|
+
const newPath = (0, import_path9.resolve)(sourceDir, `${newId}.genart`);
|
|
3595
|
+
const json = (0, import_core11.serializeGenart)(promotedDef);
|
|
3596
|
+
if (!state.remoteMode) {
|
|
3597
|
+
await (0, import_promises9.writeFile)(newPath, json, "utf-8");
|
|
3598
|
+
}
|
|
3599
|
+
state.sketches.set(newId, { definition: promotedDef, path: newPath });
|
|
3600
|
+
const sourceRef = ws.sketches.find(
|
|
3601
|
+
(s) => s.file === (0, import_path9.basename)(source.path)
|
|
3602
|
+
);
|
|
3603
|
+
const position = sourceRef ? { x: sourceRef.position.x, y: sourceRef.position.y + sourceDef.canvas.height + 200 } : { x: 0, y: 0 };
|
|
3604
|
+
const file = (0, import_path9.basename)(newPath);
|
|
3605
|
+
state.workspace = {
|
|
3606
|
+
...ws,
|
|
3607
|
+
modified: ts,
|
|
3608
|
+
sketches: [...ws.sketches, { file, position }]
|
|
3609
|
+
};
|
|
3610
|
+
if (input.seriesId) {
|
|
3611
|
+
const seriesIndex = state.workspace.series?.findIndex(
|
|
3612
|
+
(s) => s.id === input.seriesId
|
|
3613
|
+
);
|
|
3614
|
+
if (seriesIndex !== void 0 && seriesIndex >= 0 && state.workspace.series) {
|
|
3615
|
+
const series = state.workspace.series[seriesIndex];
|
|
3616
|
+
const updatedSeries = {
|
|
3617
|
+
...series,
|
|
3618
|
+
sketchFiles: [...series.sketchFiles, file]
|
|
3619
|
+
};
|
|
3620
|
+
state.workspace = {
|
|
3621
|
+
...state.workspace,
|
|
3622
|
+
series: state.workspace.series.map(
|
|
3623
|
+
(s, i) => i === seriesIndex ? updatedSeries : s
|
|
3624
|
+
)
|
|
3625
|
+
};
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
3628
|
+
const workspaceJson = (0, import_core11.serializeWorkspace)(state.workspace);
|
|
3629
|
+
if (!state.remoteMode) {
|
|
3630
|
+
await (0, import_promises9.writeFile)(state.workspacePath, workspaceJson, "utf-8");
|
|
3631
|
+
}
|
|
3632
|
+
state.emitMutation("sketch:created", { id: newId, path: newPath });
|
|
3633
|
+
state.emitMutation("workspace:updated", { added: file });
|
|
3634
|
+
return {
|
|
3635
|
+
success: true,
|
|
3636
|
+
sourceId: input.sketchId,
|
|
3637
|
+
promotedSketch: {
|
|
3638
|
+
id: newId,
|
|
3639
|
+
title,
|
|
3640
|
+
path: newPath,
|
|
3641
|
+
compositionLevel: targetLevel,
|
|
3642
|
+
stage: input.toStage,
|
|
3643
|
+
canvas: { width: newWidth, height: newHeight },
|
|
3644
|
+
position,
|
|
3645
|
+
lineage: promotedDef.lineage
|
|
3646
|
+
},
|
|
3647
|
+
...scale > 1 ? {
|
|
3648
|
+
canvasUpscaled: `Canvas scaled ${scale}x: ${sourceDef.canvas.width}x${sourceDef.canvas.height} \u2192 ${newWidth}x${newHeight}`
|
|
3649
|
+
} : {},
|
|
3650
|
+
fileContent: json,
|
|
3651
|
+
workspaceContent: workspaceJson
|
|
3652
|
+
};
|
|
3653
|
+
}
|
|
3654
|
+
function countBy(items) {
|
|
3655
|
+
const counts = {};
|
|
3656
|
+
for (const item of items) {
|
|
3657
|
+
counts[item] = (counts[item] ?? 0) + 1;
|
|
3658
|
+
}
|
|
3659
|
+
return counts;
|
|
3660
|
+
}
|
|
3661
|
+
|
|
3662
|
+
// src/tools/reference.ts
|
|
3663
|
+
var import_promises10 = require("fs/promises");
|
|
3664
|
+
var import_path10 = require("path");
|
|
3665
|
+
var import_core12 = require("@genart-dev/core");
|
|
3666
|
+
var import_promises11 = require("fs/promises");
|
|
3667
|
+
function now7() {
|
|
3668
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
3669
|
+
}
|
|
3670
|
+
var KEBAB_RE3 = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
3671
|
+
function validateKebabId3(id) {
|
|
3672
|
+
if (!KEBAB_RE3.test(id)) {
|
|
3673
|
+
throw new Error(
|
|
3674
|
+
"ID must be kebab-case: lowercase letters, numbers, hyphens"
|
|
3675
|
+
);
|
|
3676
|
+
}
|
|
3677
|
+
}
|
|
3678
|
+
var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
3679
|
+
".png",
|
|
3680
|
+
".jpg",
|
|
3681
|
+
".jpeg",
|
|
3682
|
+
".gif",
|
|
3683
|
+
".webp",
|
|
3684
|
+
".bmp",
|
|
3685
|
+
".tiff",
|
|
3686
|
+
".svg"
|
|
3687
|
+
]);
|
|
3688
|
+
function isImageFile(path) {
|
|
3689
|
+
return IMAGE_EXTENSIONS.has((0, import_path10.extname)(path).toLowerCase());
|
|
3690
|
+
}
|
|
3691
|
+
var VALID_REFERENCE_TYPES = [
|
|
3692
|
+
"image",
|
|
3693
|
+
"artwork",
|
|
3694
|
+
"photograph",
|
|
3695
|
+
"texture",
|
|
3696
|
+
"palette"
|
|
3697
|
+
];
|
|
3698
|
+
async function addReference(state, input) {
|
|
3699
|
+
const ws = state.requireWorkspace();
|
|
3700
|
+
if (!isImageFile(input.image)) {
|
|
3701
|
+
throw new Error(
|
|
3702
|
+
`Not a recognized image file: ${input.image}. Supported: ${[...IMAGE_EXTENSIONS].join(", ")}`
|
|
3703
|
+
);
|
|
3704
|
+
}
|
|
3705
|
+
const id = input.id ?? (0, import_path10.basename)(input.image, (0, import_path10.extname)(input.image)).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
3706
|
+
if (!id) {
|
|
3707
|
+
throw new Error("Could not derive a valid ID from the image filename");
|
|
3708
|
+
}
|
|
3709
|
+
validateKebabId3(id);
|
|
3710
|
+
const refType = input.type ?? "image";
|
|
3711
|
+
if (!VALID_REFERENCE_TYPES.includes(refType)) {
|
|
3712
|
+
throw new Error(
|
|
3713
|
+
`Invalid reference type: '${refType}'. Valid types: ${VALID_REFERENCE_TYPES.join(", ")}`
|
|
3714
|
+
);
|
|
3715
|
+
}
|
|
3716
|
+
const workspaceDir = (0, import_path10.dirname)(state.workspacePath);
|
|
3717
|
+
const refsDir = (0, import_path10.resolve)(workspaceDir, "references");
|
|
3718
|
+
await (0, import_promises10.mkdir)(refsDir, { recursive: true });
|
|
3719
|
+
const ext = (0, import_path10.extname)(input.image);
|
|
3720
|
+
const destFilename = `${id}${ext}`;
|
|
3721
|
+
const destPath = (0, import_path10.resolve)(refsDir, destFilename);
|
|
3722
|
+
const relativePath = `references/${destFilename}`;
|
|
3723
|
+
if (!state.remoteMode) {
|
|
3724
|
+
await (0, import_promises10.copyFile)((0, import_path10.resolve)(input.image), destPath);
|
|
3725
|
+
}
|
|
3726
|
+
const ref = {
|
|
3727
|
+
id,
|
|
3728
|
+
type: refType,
|
|
3729
|
+
path: relativePath,
|
|
3730
|
+
...input.source ? { source: input.source } : {}
|
|
3731
|
+
};
|
|
3732
|
+
let attachedTo;
|
|
3733
|
+
let workspaceJson;
|
|
3734
|
+
let sketchJson;
|
|
3735
|
+
if (input.sketchId) {
|
|
3736
|
+
const loaded = state.requireSketch(input.sketchId);
|
|
3737
|
+
const existingRefs = loaded.definition.references ?? [];
|
|
3738
|
+
if (existingRefs.some((r) => r.id === id)) {
|
|
3739
|
+
throw new Error(
|
|
3740
|
+
`Reference with ID '${id}' already exists on sketch '${input.sketchId}'`
|
|
3741
|
+
);
|
|
3742
|
+
}
|
|
3743
|
+
const updatedDef = {
|
|
3744
|
+
...loaded.definition,
|
|
3745
|
+
modified: now7(),
|
|
3746
|
+
references: [...existingRefs, ref]
|
|
3747
|
+
};
|
|
3748
|
+
state.sketches.set(input.sketchId, {
|
|
3749
|
+
definition: updatedDef,
|
|
3750
|
+
path: loaded.path
|
|
3751
|
+
});
|
|
3752
|
+
sketchJson = (0, import_core12.serializeGenart)(updatedDef);
|
|
3753
|
+
if (!state.remoteMode) {
|
|
3754
|
+
await (0, import_promises11.writeFile)(loaded.path, sketchJson, "utf-8");
|
|
3755
|
+
}
|
|
3756
|
+
attachedTo = `sketch:${input.sketchId}`;
|
|
3757
|
+
state.emitMutation("sketch:updated", { id: input.sketchId });
|
|
3758
|
+
} else if (input.seriesId) {
|
|
3759
|
+
const seriesIndex = ws.series?.findIndex((s) => s.id === input.seriesId);
|
|
3760
|
+
if (seriesIndex === void 0 || seriesIndex < 0 || !ws.series) {
|
|
3761
|
+
throw new Error(`Series '${input.seriesId}' not found in workspace`);
|
|
3762
|
+
}
|
|
3763
|
+
const series = ws.series[seriesIndex];
|
|
3764
|
+
const existingRefs = series.references ?? [];
|
|
3765
|
+
if (existingRefs.some((r) => r.id === id)) {
|
|
3766
|
+
throw new Error(
|
|
3767
|
+
`Reference with ID '${id}' already exists on series '${input.seriesId}'`
|
|
3768
|
+
);
|
|
3769
|
+
}
|
|
3770
|
+
const updatedSeries = {
|
|
3771
|
+
...series,
|
|
3772
|
+
references: [...existingRefs, ref]
|
|
3773
|
+
};
|
|
3774
|
+
state.workspace = {
|
|
3775
|
+
...ws,
|
|
3776
|
+
modified: now7(),
|
|
3777
|
+
series: ws.series.map(
|
|
3778
|
+
(s, i) => i === seriesIndex ? updatedSeries : s
|
|
3779
|
+
)
|
|
3780
|
+
};
|
|
3781
|
+
workspaceJson = (0, import_core12.serializeWorkspace)(state.workspace);
|
|
3782
|
+
if (!state.remoteMode) {
|
|
3783
|
+
await (0, import_promises11.writeFile)(state.workspacePath, workspaceJson, "utf-8");
|
|
3784
|
+
}
|
|
3785
|
+
attachedTo = `series:${input.seriesId}`;
|
|
3786
|
+
state.emitMutation("workspace:updated", { referenceAdded: id });
|
|
3787
|
+
} else {
|
|
3788
|
+
throw new Error("Either seriesId or sketchId must be specified");
|
|
3789
|
+
}
|
|
3790
|
+
return {
|
|
3791
|
+
success: true,
|
|
3792
|
+
reference: {
|
|
3793
|
+
id,
|
|
3794
|
+
type: refType,
|
|
3795
|
+
path: relativePath,
|
|
3796
|
+
source: input.source ?? null
|
|
3797
|
+
},
|
|
3798
|
+
attachedTo,
|
|
3799
|
+
...sketchJson ? { fileContent: sketchJson } : {},
|
|
3800
|
+
...workspaceJson ? { workspaceContent: workspaceJson } : {}
|
|
3801
|
+
};
|
|
3802
|
+
}
|
|
3803
|
+
async function analyzeReference(state, input) {
|
|
3804
|
+
state.requireWorkspace();
|
|
3805
|
+
const { ref, location } = findReference(state, input.referenceId, input.seriesId, input.sketchId);
|
|
3806
|
+
const workspaceDir = (0, import_path10.dirname)(state.workspacePath);
|
|
3807
|
+
const imagePath = (0, import_path10.resolve)(workspaceDir, ref.path);
|
|
3808
|
+
let previewJpegBase64;
|
|
3809
|
+
try {
|
|
3810
|
+
const imageBuffer = await (0, import_promises10.readFile)(imagePath);
|
|
3811
|
+
const ext = (0, import_path10.extname)(ref.path).toLowerCase();
|
|
3812
|
+
const mimeMap = {
|
|
3813
|
+
".png": "image/png",
|
|
3814
|
+
".jpg": "image/jpeg",
|
|
3815
|
+
".jpeg": "image/jpeg",
|
|
3816
|
+
".gif": "image/gif",
|
|
3817
|
+
".webp": "image/webp",
|
|
3818
|
+
".svg": "image/svg+xml"
|
|
3819
|
+
};
|
|
3820
|
+
previewJpegBase64 = imageBuffer.toString("base64");
|
|
3821
|
+
} catch {
|
|
3822
|
+
}
|
|
3823
|
+
const metadata = {
|
|
3824
|
+
success: true,
|
|
3825
|
+
referenceId: ref.id,
|
|
3826
|
+
type: ref.type,
|
|
3827
|
+
path: ref.path,
|
|
3828
|
+
source: ref.source ?? null,
|
|
3829
|
+
location,
|
|
3830
|
+
existingAnalysis: ref.analysis ?? null,
|
|
3831
|
+
analysisFramework: {
|
|
3832
|
+
composition: {
|
|
3833
|
+
instruction: "Analyze the compositional structure of this reference.",
|
|
3834
|
+
prompts: [
|
|
3835
|
+
"What is the primary compositional structure (centered, asymmetric, diagonal, radial)?",
|
|
3836
|
+
"Where does the eye land first? What creates the focal point?",
|
|
3837
|
+
"How is negative space used \u2014 actively or passively?",
|
|
3838
|
+
"What is the relationship between foreground, middle ground, and background?",
|
|
3839
|
+
"How do the edges and corners of the frame interact with the subject?"
|
|
3840
|
+
]
|
|
3841
|
+
},
|
|
3842
|
+
palette: {
|
|
3843
|
+
instruction: "Identify the color strategy.",
|
|
3844
|
+
prompts: [
|
|
3845
|
+
"What are the dominant colors (3-5 hex values)?",
|
|
3846
|
+
"What color temperature dominates \u2014 warm, cool, or neutral?",
|
|
3847
|
+
"What is the value range \u2014 high contrast or compressed?",
|
|
3848
|
+
"Is the palette analogous, complementary, triadic, or something else?",
|
|
3849
|
+
"How does saturation vary across the composition?"
|
|
3850
|
+
]
|
|
3851
|
+
},
|
|
3852
|
+
rhythm: {
|
|
3853
|
+
instruction: "Identify rhythmic and pattern qualities.",
|
|
3854
|
+
prompts: [
|
|
3855
|
+
"Is there a repeating motif or interval?",
|
|
3856
|
+
"Is the rhythm regular, progressive, alternating, or irregular?",
|
|
3857
|
+
"At how many scales does pattern appear (fractal quality)?",
|
|
3858
|
+
"How do density variations create movement?",
|
|
3859
|
+
"Where are the moments of rest vs. activity?"
|
|
3860
|
+
]
|
|
3861
|
+
},
|
|
3862
|
+
mood: {
|
|
3863
|
+
instruction: "Identify the emotional and atmospheric qualities.",
|
|
3864
|
+
prompts: [
|
|
3865
|
+
"What is the overall mood \u2014 contemplative, energetic, serene, unsettling?",
|
|
3866
|
+
"How do color, light, and space contribute to that mood?",
|
|
3867
|
+
"Is there a sense of time \u2014 moment, duration, timelessness?",
|
|
3868
|
+
"What emotional response does the work invite?"
|
|
3869
|
+
]
|
|
3870
|
+
},
|
|
3871
|
+
technique: {
|
|
3872
|
+
instruction: "Identify technical and material qualities worth studying.",
|
|
3873
|
+
prompts: [
|
|
3874
|
+
"What medium or technique is used?",
|
|
3875
|
+
"How is mark-making contributing to expression?",
|
|
3876
|
+
"Are there layering or transparency effects?",
|
|
3877
|
+
"What level of control vs. chance is visible?",
|
|
3878
|
+
"What technical approach could be translated to generative art?"
|
|
3879
|
+
]
|
|
3880
|
+
}
|
|
3881
|
+
},
|
|
3882
|
+
instructions: [
|
|
3883
|
+
"Study the reference image carefully using the framework above.",
|
|
3884
|
+
"For each category, answer the prompts and synthesize your observations.",
|
|
3885
|
+
"After analysis, use update_reference_analysis to save the structured analysis.",
|
|
3886
|
+
"The analysis should inform how you create study sketches inspired by this reference.",
|
|
3887
|
+
"Focus on qualities that can be translated to generative art \u2014 don't try to replicate literally."
|
|
3888
|
+
]
|
|
3889
|
+
};
|
|
3890
|
+
return { metadata, previewJpegBase64 };
|
|
3891
|
+
}
|
|
3892
|
+
async function updateReferenceAnalysis(state, input) {
|
|
3893
|
+
const ws = state.requireWorkspace();
|
|
3894
|
+
const { ref, location } = findReference(
|
|
3895
|
+
state,
|
|
3896
|
+
input.referenceId,
|
|
3897
|
+
input.seriesId,
|
|
3898
|
+
input.sketchId
|
|
3899
|
+
);
|
|
3900
|
+
const updatedRef = {
|
|
3901
|
+
...ref,
|
|
3902
|
+
analysis: input.analysis
|
|
3903
|
+
};
|
|
3904
|
+
let workspaceJson;
|
|
3905
|
+
let sketchJson;
|
|
3906
|
+
if (location.startsWith("sketch:")) {
|
|
3907
|
+
const sketchId = location.replace("sketch:", "");
|
|
3908
|
+
const loaded = state.requireSketch(sketchId);
|
|
3909
|
+
const updatedDef = {
|
|
3910
|
+
...loaded.definition,
|
|
3911
|
+
modified: now7(),
|
|
3912
|
+
references: (loaded.definition.references ?? []).map(
|
|
3913
|
+
(r) => r.id === input.referenceId ? updatedRef : r
|
|
3914
|
+
)
|
|
3915
|
+
};
|
|
3916
|
+
state.sketches.set(sketchId, {
|
|
3917
|
+
definition: updatedDef,
|
|
3918
|
+
path: loaded.path
|
|
3919
|
+
});
|
|
3920
|
+
sketchJson = (0, import_core12.serializeGenart)(updatedDef);
|
|
3921
|
+
if (!state.remoteMode) {
|
|
3922
|
+
await (0, import_promises11.writeFile)(loaded.path, sketchJson, "utf-8");
|
|
3923
|
+
}
|
|
3924
|
+
state.emitMutation("sketch:updated", { id: sketchId });
|
|
3925
|
+
} else {
|
|
3926
|
+
const seriesId = location.replace("series:", "");
|
|
3927
|
+
const seriesIndex = ws.series.findIndex((s) => s.id === seriesId);
|
|
3928
|
+
const series = ws.series[seriesIndex];
|
|
3929
|
+
const updatedSeries = {
|
|
3930
|
+
...series,
|
|
3931
|
+
references: (series.references ?? []).map(
|
|
3932
|
+
(r) => r.id === input.referenceId ? updatedRef : r
|
|
3933
|
+
)
|
|
3934
|
+
};
|
|
3935
|
+
state.workspace = {
|
|
3936
|
+
...ws,
|
|
3937
|
+
modified: now7(),
|
|
3938
|
+
series: ws.series.map(
|
|
3939
|
+
(s, i) => i === seriesIndex ? updatedSeries : s
|
|
3940
|
+
)
|
|
3941
|
+
};
|
|
3942
|
+
workspaceJson = (0, import_core12.serializeWorkspace)(state.workspace);
|
|
3943
|
+
if (!state.remoteMode) {
|
|
3944
|
+
await (0, import_promises11.writeFile)(state.workspacePath, workspaceJson, "utf-8");
|
|
3945
|
+
}
|
|
3946
|
+
state.emitMutation("workspace:updated", { referenceAnalyzed: input.referenceId });
|
|
3947
|
+
}
|
|
3948
|
+
return {
|
|
3949
|
+
success: true,
|
|
3950
|
+
referenceId: input.referenceId,
|
|
3951
|
+
location,
|
|
3952
|
+
analysis: input.analysis,
|
|
3953
|
+
...sketchJson ? { fileContent: sketchJson } : {},
|
|
3954
|
+
...workspaceJson ? { workspaceContent: workspaceJson } : {}
|
|
3955
|
+
};
|
|
3956
|
+
}
|
|
3957
|
+
async function extractPalette(state, input) {
|
|
3958
|
+
state.requireWorkspace();
|
|
3959
|
+
const { ref, location } = findReference(
|
|
3960
|
+
state,
|
|
3961
|
+
input.referenceId,
|
|
3962
|
+
input.seriesId,
|
|
3963
|
+
input.sketchId
|
|
3964
|
+
);
|
|
3965
|
+
const count = input.count ?? 6;
|
|
3966
|
+
const workspaceDir = (0, import_path10.dirname)(state.workspacePath);
|
|
3967
|
+
const imagePath = (0, import_path10.resolve)(workspaceDir, ref.path);
|
|
3968
|
+
let previewJpegBase64;
|
|
3969
|
+
try {
|
|
3970
|
+
const imageBuffer = await (0, import_promises10.readFile)(imagePath);
|
|
3971
|
+
previewJpegBase64 = imageBuffer.toString("base64");
|
|
3972
|
+
} catch {
|
|
3973
|
+
}
|
|
3974
|
+
const metadata = {
|
|
3975
|
+
success: true,
|
|
3976
|
+
referenceId: ref.id,
|
|
3977
|
+
type: ref.type,
|
|
3978
|
+
path: ref.path,
|
|
3979
|
+
location,
|
|
3980
|
+
requestedColors: count,
|
|
3981
|
+
existingPalette: ref.analysis?.palette ?? null,
|
|
3982
|
+
instructions: [
|
|
3983
|
+
`Extract ${count} dominant colors from the reference image as hex values.`,
|
|
3984
|
+
"Order them from most dominant to least dominant.",
|
|
3985
|
+
"Include both saturated and neutral colors if present in the image.",
|
|
3986
|
+
"Consider the role of each color \u2014 is it a background, accent, or primary element?",
|
|
3987
|
+
"After extraction, use update_reference_analysis to save the palette.",
|
|
3988
|
+
"You can also apply the extracted palette to a sketch using set_colors or create a new theme."
|
|
3989
|
+
],
|
|
3990
|
+
extractionGuidelines: {
|
|
3991
|
+
dominance: "Prioritize colors by the area they occupy, not just their saturation.",
|
|
3992
|
+
variety: "Include the full value range (lights, midtones, darks) if present.",
|
|
3993
|
+
harmony: `Look for ${count <= 4 ? "core harmony" : "extended palette including transitional colors"}.`,
|
|
3994
|
+
neutrals: "Don't ignore grays, blacks, and whites \u2014 they often define the character of a palette."
|
|
3995
|
+
}
|
|
3996
|
+
};
|
|
3997
|
+
return { metadata, previewJpegBase64 };
|
|
3998
|
+
}
|
|
3999
|
+
function findReference(state, referenceId, seriesId, sketchId) {
|
|
4000
|
+
if (sketchId) {
|
|
4001
|
+
const loaded = state.requireSketch(sketchId);
|
|
4002
|
+
const ref = (loaded.definition.references ?? []).find(
|
|
4003
|
+
(r) => r.id === referenceId
|
|
4004
|
+
);
|
|
4005
|
+
if (ref) return { ref, location: `sketch:${sketchId}` };
|
|
4006
|
+
throw new Error(
|
|
4007
|
+
`Reference '${referenceId}' not found on sketch '${sketchId}'`
|
|
4008
|
+
);
|
|
4009
|
+
}
|
|
4010
|
+
if (seriesId) {
|
|
4011
|
+
const ws2 = state.requireWorkspace();
|
|
4012
|
+
const series = ws2.series?.find((s) => s.id === seriesId);
|
|
4013
|
+
if (!series) {
|
|
4014
|
+
throw new Error(`Series '${seriesId}' not found in workspace`);
|
|
4015
|
+
}
|
|
4016
|
+
const ref = (series.references ?? []).find((r) => r.id === referenceId);
|
|
4017
|
+
if (ref) return { ref, location: `series:${seriesId}` };
|
|
4018
|
+
throw new Error(
|
|
4019
|
+
`Reference '${referenceId}' not found on series '${seriesId}'`
|
|
4020
|
+
);
|
|
4021
|
+
}
|
|
4022
|
+
const ws = state.requireWorkspace();
|
|
4023
|
+
if (ws.series) {
|
|
4024
|
+
for (const series of ws.series) {
|
|
4025
|
+
const ref = (series.references ?? []).find((r) => r.id === referenceId);
|
|
4026
|
+
if (ref) return { ref, location: `series:${series.id}` };
|
|
4027
|
+
}
|
|
4028
|
+
}
|
|
4029
|
+
for (const [id, loaded] of state.sketches) {
|
|
4030
|
+
const ref = (loaded.definition.references ?? []).find(
|
|
4031
|
+
(r) => r.id === referenceId
|
|
4032
|
+
);
|
|
4033
|
+
if (ref) return { ref, location: `sketch:${id}` };
|
|
4034
|
+
}
|
|
4035
|
+
throw new Error(
|
|
4036
|
+
`Reference '${referenceId}' not found in any series or sketch`
|
|
4037
|
+
);
|
|
4038
|
+
}
|
|
4039
|
+
|
|
4040
|
+
// src/tools/export.ts
|
|
4041
|
+
var import_fs = require("fs");
|
|
4042
|
+
var import_promises12 = require("fs/promises");
|
|
4043
|
+
var import_path11 = require("path");
|
|
4044
|
+
var import_archiver = __toESM(require("archiver"), 1);
|
|
4045
|
+
var import_core13 = require("@genart-dev/core");
|
|
4046
|
+
var registry4 = (0, import_core13.createDefaultRegistry)();
|
|
4047
|
+
async function validateOutputPath(outputPath) {
|
|
4048
|
+
const parentDir = (0, import_path11.dirname)(outputPath);
|
|
4049
|
+
try {
|
|
4050
|
+
const s = await (0, import_promises12.stat)(parentDir);
|
|
4051
|
+
if (!s.isDirectory()) {
|
|
4052
|
+
throw new Error(`Parent directory does not exist: ${parentDir}`);
|
|
4053
|
+
}
|
|
4054
|
+
} catch (e) {
|
|
4055
|
+
if (e instanceof Error && e.message.startsWith("Parent directory")) throw e;
|
|
4056
|
+
throw new Error(`Parent directory does not exist: ${parentDir}`);
|
|
4057
|
+
}
|
|
4058
|
+
try {
|
|
4059
|
+
await (0, import_promises12.stat)(outputPath);
|
|
4060
|
+
throw new Error(
|
|
4061
|
+
`File already exists at ${outputPath}. Delete it first or use a different path.`
|
|
4062
|
+
);
|
|
4063
|
+
} catch (e) {
|
|
4064
|
+
if (e instanceof Error && e.message.startsWith("File already exists")) throw e;
|
|
4065
|
+
}
|
|
4066
|
+
}
|
|
4067
|
+
function algorithmExtension(rendererType) {
|
|
4068
|
+
return rendererType === "glsl" ? ".glsl" : ".js";
|
|
4069
|
+
}
|
|
4070
|
+
function applyOverrides2(sketch, overrides) {
|
|
4071
|
+
if (overrides.seed === void 0 && overrides.params === void 0) {
|
|
4072
|
+
return sketch;
|
|
4073
|
+
}
|
|
4074
|
+
const newState = {
|
|
4075
|
+
seed: overrides.seed ?? sketch.state.seed,
|
|
4076
|
+
params: overrides.params ? { ...sketch.state.params, ...overrides.params } : sketch.state.params,
|
|
4077
|
+
colorPalette: sketch.state.colorPalette
|
|
4078
|
+
};
|
|
4079
|
+
return { ...sketch, state: newState };
|
|
4080
|
+
}
|
|
4081
|
+
async function exportSketch(state, input) {
|
|
4082
|
+
state.requireWorkspace();
|
|
4083
|
+
const loaded = state.requireSketch(input.sketchId);
|
|
4084
|
+
const sketch = applyOverrides2(loaded.definition, {
|
|
4085
|
+
seed: input.seed,
|
|
4086
|
+
params: input.params
|
|
4087
|
+
});
|
|
4088
|
+
await validateOutputPath(input.outputPath);
|
|
4089
|
+
const adapter = registry4.resolve(sketch.renderer.type);
|
|
4090
|
+
if (!adapter) {
|
|
4091
|
+
throw new Error(
|
|
4092
|
+
`Unsupported renderer type: '${sketch.renderer.type}'`
|
|
4093
|
+
);
|
|
4094
|
+
}
|
|
4095
|
+
switch (input.format) {
|
|
4096
|
+
case "html":
|
|
4097
|
+
return await exportHtml(sketch, input.outputPath);
|
|
4098
|
+
case "png":
|
|
4099
|
+
return await exportPng(sketch, input);
|
|
4100
|
+
case "svg":
|
|
4101
|
+
return await exportSvg(sketch, input);
|
|
4102
|
+
case "algorithm":
|
|
4103
|
+
return await exportAlgorithm(sketch, input.outputPath);
|
|
4104
|
+
case "zip":
|
|
4105
|
+
return await exportZip(sketch, input);
|
|
4106
|
+
default:
|
|
4107
|
+
throw new Error(`Unsupported export format: '${input.format}'`);
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4110
|
+
async function exportHtml(sketch, outputPath) {
|
|
4111
|
+
const adapter = registry4.resolve(sketch.renderer.type);
|
|
4112
|
+
const html = adapter.generateStandaloneHTML(sketch);
|
|
4113
|
+
const content = Buffer.from(html, "utf-8");
|
|
4114
|
+
await (0, import_promises12.writeFile)(outputPath, content);
|
|
4115
|
+
return {
|
|
4116
|
+
success: true,
|
|
4117
|
+
sketchId: sketch.id,
|
|
4118
|
+
format: "html",
|
|
4119
|
+
outputPath,
|
|
4120
|
+
fileSize: content.byteLength,
|
|
4121
|
+
renderer: sketch.renderer.type
|
|
4122
|
+
};
|
|
4123
|
+
}
|
|
4124
|
+
async function exportPng(sketch, input) {
|
|
4125
|
+
const adapter = registry4.resolve(sketch.renderer.type);
|
|
4126
|
+
const html = adapter.generateStandaloneHTML(sketch);
|
|
4127
|
+
const width = input.width ?? sketch.canvas.width;
|
|
4128
|
+
const height = input.height ?? sketch.canvas.height;
|
|
4129
|
+
const result = await captureHtml({ html, width, height });
|
|
4130
|
+
await (0, import_promises12.writeFile)(input.outputPath, result.bytes);
|
|
4131
|
+
return {
|
|
4132
|
+
success: true,
|
|
4133
|
+
sketchId: sketch.id,
|
|
4134
|
+
format: "png",
|
|
4135
|
+
outputPath: input.outputPath,
|
|
4136
|
+
fileSize: result.bytes.byteLength,
|
|
4137
|
+
renderer: sketch.renderer.type
|
|
4138
|
+
};
|
|
4139
|
+
}
|
|
4140
|
+
async function exportSvg(sketch, input) {
|
|
4141
|
+
const width = input.width ?? sketch.canvas.width;
|
|
4142
|
+
const height = input.height ?? sketch.canvas.height;
|
|
4143
|
+
if (sketch.renderer.type === "svg") {
|
|
4144
|
+
const content2 = Buffer.from(sketch.algorithm, "utf-8");
|
|
4145
|
+
await (0, import_promises12.writeFile)(input.outputPath, content2);
|
|
4146
|
+
return {
|
|
4147
|
+
success: true,
|
|
4148
|
+
sketchId: sketch.id,
|
|
4149
|
+
format: "svg",
|
|
4150
|
+
outputPath: input.outputPath,
|
|
4151
|
+
fileSize: content2.byteLength,
|
|
4152
|
+
renderer: sketch.renderer.type,
|
|
4153
|
+
notice: null
|
|
4154
|
+
};
|
|
4155
|
+
}
|
|
4156
|
+
const adapter = registry4.resolve(sketch.renderer.type);
|
|
4157
|
+
const html = adapter.generateStandaloneHTML(sketch);
|
|
4158
|
+
const result = await captureHtml({ html, width, height });
|
|
4159
|
+
const b64 = Buffer.from(result.bytes).toString("base64");
|
|
4160
|
+
const svg = `<?xml version="1.0" encoding="UTF-8"?>
|
|
4161
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
4162
|
+
width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
|
|
4163
|
+
<image width="${width}" height="${height}"
|
|
4164
|
+
href="data:image/png;base64,${b64}"/>
|
|
4165
|
+
</svg>`;
|
|
4166
|
+
const content = Buffer.from(svg, "utf-8");
|
|
4167
|
+
await (0, import_promises12.writeFile)(input.outputPath, content);
|
|
4168
|
+
return {
|
|
4169
|
+
success: true,
|
|
4170
|
+
sketchId: sketch.id,
|
|
4171
|
+
format: "svg",
|
|
4172
|
+
outputPath: input.outputPath,
|
|
4173
|
+
fileSize: content.byteLength,
|
|
4174
|
+
renderer: sketch.renderer.type,
|
|
4175
|
+
notice: "Non-SVG renderer \u2014 rasterized PNG embedded in SVG container"
|
|
4176
|
+
};
|
|
4177
|
+
}
|
|
4178
|
+
async function exportAlgorithm(sketch, outputPath) {
|
|
4179
|
+
const content = Buffer.from(sketch.algorithm, "utf-8");
|
|
4180
|
+
await (0, import_promises12.writeFile)(outputPath, content);
|
|
4181
|
+
return {
|
|
4182
|
+
success: true,
|
|
4183
|
+
sketchId: sketch.id,
|
|
4184
|
+
format: "algorithm",
|
|
4185
|
+
outputPath,
|
|
4186
|
+
fileSize: content.byteLength,
|
|
4187
|
+
renderer: sketch.renderer.type
|
|
4188
|
+
};
|
|
4189
|
+
}
|
|
4190
|
+
async function exportZip(sketch, input) {
|
|
4191
|
+
const adapter = registry4.resolve(sketch.renderer.type);
|
|
4192
|
+
const width = input.width ?? sketch.canvas.width;
|
|
4193
|
+
const height = input.height ?? sketch.canvas.height;
|
|
4194
|
+
const html = adapter.generateStandaloneHTML(sketch);
|
|
4195
|
+
const genartJson = (0, import_core13.serializeGenart)(sketch);
|
|
4196
|
+
const algorithm = sketch.algorithm;
|
|
4197
|
+
const algExt = algorithmExtension(sketch.renderer.type);
|
|
4198
|
+
const captureResult = await captureHtml({ html, width, height });
|
|
4199
|
+
const output = (0, import_fs.createWriteStream)(input.outputPath);
|
|
4200
|
+
const archive = (0, import_archiver.default)("zip", { zlib: { level: 9 } });
|
|
4201
|
+
const finished = new Promise((resolve5, reject) => {
|
|
4202
|
+
output.on("close", resolve5);
|
|
4203
|
+
archive.on("error", reject);
|
|
4204
|
+
});
|
|
4205
|
+
archive.pipe(output);
|
|
4206
|
+
archive.append(html, { name: `${sketch.id}.html` });
|
|
4207
|
+
archive.append(Buffer.from(captureResult.bytes), { name: `${sketch.id}.png` });
|
|
4208
|
+
archive.append(algorithm, { name: `${sketch.id}${algExt}` });
|
|
4209
|
+
archive.append(genartJson, { name: `${sketch.id}.genart` });
|
|
4210
|
+
await archive.finalize();
|
|
4211
|
+
await finished;
|
|
4212
|
+
const s = await (0, import_promises12.stat)(input.outputPath);
|
|
4213
|
+
return {
|
|
4214
|
+
success: true,
|
|
4215
|
+
sketchId: sketch.id,
|
|
4216
|
+
format: "zip",
|
|
4217
|
+
outputPath: input.outputPath,
|
|
4218
|
+
fileSize: s.size,
|
|
4219
|
+
renderer: sketch.renderer.type,
|
|
4220
|
+
contents: [
|
|
4221
|
+
`${sketch.id}.html`,
|
|
4222
|
+
`${sketch.id}.png`,
|
|
4223
|
+
`${sketch.id}${algExt}`,
|
|
4224
|
+
`${sketch.id}.genart`
|
|
4225
|
+
]
|
|
4226
|
+
};
|
|
4227
|
+
}
|
|
4228
|
+
|
|
4229
|
+
// src/tools/design.ts
|
|
4230
|
+
function requireSketchId(state, args) {
|
|
4231
|
+
return args.sketchId ?? state.requireSelectedSketchId();
|
|
4232
|
+
}
|
|
4233
|
+
var BLEND_MODES = [
|
|
4234
|
+
"normal",
|
|
4235
|
+
"multiply",
|
|
4236
|
+
"screen",
|
|
4237
|
+
"overlay",
|
|
4238
|
+
"darken",
|
|
2976
4239
|
"lighten",
|
|
2977
4240
|
"color-dodge",
|
|
2978
4241
|
"color-burn",
|
|
@@ -2992,8 +4255,8 @@ async function designAddLayer(state, args) {
|
|
|
2992
4255
|
const sketchId = requireSketchId(state, args);
|
|
2993
4256
|
const loaded = state.requireSketch(sketchId);
|
|
2994
4257
|
const stack = state.getLayerStack(sketchId);
|
|
2995
|
-
const
|
|
2996
|
-
const layerTypeDef =
|
|
4258
|
+
const registry5 = state.pluginRegistry;
|
|
4259
|
+
const layerTypeDef = registry5?.resolveLayerType(args.type);
|
|
2997
4260
|
if (!layerTypeDef) {
|
|
2998
4261
|
throw new Error(
|
|
2999
4262
|
`Unknown layer type: '${args.type}'. Use design_list_layers types from registered plugins.`
|
|
@@ -3100,10 +4363,7 @@ async function designUpdateLayer(state, args) {
|
|
|
3100
4363
|
stack.updateProperties(args.layerId, updates);
|
|
3101
4364
|
}
|
|
3102
4365
|
if (args.name !== void 0) {
|
|
3103
|
-
|
|
3104
|
-
stack.updateProperties(args.layerId, { ...current.properties });
|
|
3105
|
-
const mutableLayer = stack.get(args.layerId);
|
|
3106
|
-
mutableLayer.name = args.name;
|
|
4366
|
+
stack.updateMeta(args.layerId, { name: args.name });
|
|
3107
4367
|
}
|
|
3108
4368
|
await state.saveSketch(sketchId);
|
|
3109
4369
|
return { updated: true, layerId: args.layerId, sketchId };
|
|
@@ -3201,9 +4461,7 @@ async function designToggleVisibility(state, args) {
|
|
|
3201
4461
|
throw new Error(`Layer '${args.layerId}' not found in sketch '${sketchId}'.`);
|
|
3202
4462
|
}
|
|
3203
4463
|
const newVisible = args.visible ?? !layer.visible;
|
|
3204
|
-
|
|
3205
|
-
mutableLayer.visible = newVisible;
|
|
3206
|
-
stack.updateProperties(args.layerId, { ...layer.properties });
|
|
4464
|
+
stack.updateMeta(args.layerId, { visible: newVisible });
|
|
3207
4465
|
await state.saveSketch(sketchId);
|
|
3208
4466
|
return {
|
|
3209
4467
|
layerId: args.layerId,
|
|
@@ -3219,9 +4477,7 @@ async function designLockLayer(state, args) {
|
|
|
3219
4477
|
throw new Error(`Layer '${args.layerId}' not found in sketch '${sketchId}'.`);
|
|
3220
4478
|
}
|
|
3221
4479
|
const newLocked = args.locked ?? !layer.locked;
|
|
3222
|
-
|
|
3223
|
-
mutableLayer.locked = newLocked;
|
|
3224
|
-
stack.updateProperties(args.layerId, { ...layer.properties });
|
|
4480
|
+
stack.updateMeta(args.layerId, { locked: newLocked });
|
|
3225
4481
|
await state.saveSketch(sketchId);
|
|
3226
4482
|
return {
|
|
3227
4483
|
layerId: args.layerId,
|
|
@@ -3242,8 +4498,8 @@ async function designCaptureComposite(state, args) {
|
|
|
3242
4498
|
}
|
|
3243
4499
|
|
|
3244
4500
|
// src/tools/design-plugins.ts
|
|
3245
|
-
function registerPluginMcpTools(server,
|
|
3246
|
-
for (const tool of
|
|
4501
|
+
function registerPluginMcpTools(server, registry5, state) {
|
|
4502
|
+
for (const tool of registry5.getMcpTools()) {
|
|
3247
4503
|
const inputSchema = tool.definition.inputSchema;
|
|
3248
4504
|
server.tool(
|
|
3249
4505
|
tool.name,
|
|
@@ -3288,7 +4544,7 @@ function registerPluginMcpTools(server, registry4, state) {
|
|
|
3288
4544
|
}
|
|
3289
4545
|
|
|
3290
4546
|
// src/resources/index.ts
|
|
3291
|
-
var
|
|
4547
|
+
var import_core14 = require("@genart-dev/core");
|
|
3292
4548
|
function registerResources(server, state) {
|
|
3293
4549
|
registerSkillsResource(server);
|
|
3294
4550
|
registerCanvasPresetsResource(server);
|
|
@@ -3296,7 +4552,7 @@ function registerResources(server, state) {
|
|
|
3296
4552
|
registerRenderersResource(server);
|
|
3297
4553
|
}
|
|
3298
4554
|
function registerSkillsResource(server) {
|
|
3299
|
-
const skillRegistry = (0,
|
|
4555
|
+
const skillRegistry = (0, import_core14.createDefaultSkillRegistry)();
|
|
3300
4556
|
server.resource(
|
|
3301
4557
|
"skills",
|
|
3302
4558
|
"genart://skills",
|
|
@@ -3347,7 +4603,7 @@ function registerCanvasPresetsResource(server) {
|
|
|
3347
4603
|
mimeType: "application/json",
|
|
3348
4604
|
text: JSON.stringify(
|
|
3349
4605
|
{
|
|
3350
|
-
presets:
|
|
4606
|
+
presets: import_core14.CANVAS_PRESETS.map((p) => ({
|
|
3351
4607
|
id: p.id,
|
|
3352
4608
|
label: p.label,
|
|
3353
4609
|
category: p.category,
|
|
@@ -3404,7 +4660,7 @@ function registerGalleryResource(server, state) {
|
|
|
3404
4660
|
);
|
|
3405
4661
|
}
|
|
3406
4662
|
function registerRenderersResource(server) {
|
|
3407
|
-
const
|
|
4663
|
+
const registry5 = (0, import_core14.createDefaultRegistry)();
|
|
3408
4664
|
server.resource(
|
|
3409
4665
|
"renderers",
|
|
3410
4666
|
"genart://renderers",
|
|
@@ -3413,9 +4669,9 @@ function registerRenderersResource(server) {
|
|
|
3413
4669
|
mimeType: "application/json"
|
|
3414
4670
|
},
|
|
3415
4671
|
async () => {
|
|
3416
|
-
const types =
|
|
4672
|
+
const types = registry5.list();
|
|
3417
4673
|
const renderers = types.map((type) => {
|
|
3418
|
-
const adapter =
|
|
4674
|
+
const adapter = registry5.resolve(type);
|
|
3419
4675
|
return {
|
|
3420
4676
|
type: adapter.type,
|
|
3421
4677
|
displayName: adapter.displayName,
|
|
@@ -3427,7 +4683,7 @@ function registerRenderersResource(server) {
|
|
|
3427
4683
|
}))
|
|
3428
4684
|
};
|
|
3429
4685
|
});
|
|
3430
|
-
const defaultAdapter =
|
|
4686
|
+
const defaultAdapter = registry5.getDefault();
|
|
3431
4687
|
return {
|
|
3432
4688
|
contents: [
|
|
3433
4689
|
{
|
|
@@ -3454,6 +4710,9 @@ function registerPrompts(server, state) {
|
|
|
3454
4710
|
registerCreateGenerativeArt(server);
|
|
3455
4711
|
registerExploreVariations(server, state);
|
|
3456
4712
|
registerApplyDesignTheory(server, state);
|
|
4713
|
+
registerCritiqueAndIterate(server, state);
|
|
4714
|
+
registerDevelopArtisticConcept(server, state);
|
|
4715
|
+
registerStudyReference(server, state);
|
|
3457
4716
|
}
|
|
3458
4717
|
function registerCreateGenerativeArt(server) {
|
|
3459
4718
|
server.prompt(
|
|
@@ -3734,21 +4993,200 @@ function registerApplyDesignTheory(server, state) {
|
|
|
3734
4993
|
content: {
|
|
3735
4994
|
type: "text",
|
|
3736
4995
|
text: [
|
|
3737
|
-
`Apply design theory to improve a generative art sketch.`,
|
|
4996
|
+
`Apply design theory to improve a generative art sketch.`,
|
|
4997
|
+
``,
|
|
4998
|
+
sketchContext,
|
|
4999
|
+
``,
|
|
5000
|
+
theoryGuides[args.theory],
|
|
5001
|
+
``,
|
|
5002
|
+
`## Workflow`,
|
|
5003
|
+
`1. Use \`get_selection\` or \`open_sketch\` to examine the current sketch`,
|
|
5004
|
+
`2. Analyze how the theory applies to the existing algorithm`,
|
|
5005
|
+
`3. Use \`fork_sketch\` to create a theory-applied variant`,
|
|
5006
|
+
`4. Modify the fork's algorithm and parameters using the theory principles above`,
|
|
5007
|
+
`5. Use \`capture_screenshot\` to compare before and after`,
|
|
5008
|
+
`6. Update the philosophy field to document the design rationale`,
|
|
5009
|
+
``,
|
|
5010
|
+
`**Attribution:** Always pass your \`agent\` name and \`model\` identifier when calling tools that create or modify sketches.`
|
|
5011
|
+
].join("\n")
|
|
5012
|
+
}
|
|
5013
|
+
}
|
|
5014
|
+
]
|
|
5015
|
+
};
|
|
5016
|
+
}
|
|
5017
|
+
);
|
|
5018
|
+
}
|
|
5019
|
+
function registerCritiqueAndIterate(server, state) {
|
|
5020
|
+
server.prompt(
|
|
5021
|
+
"critique-and-iterate",
|
|
5022
|
+
"Capture a sketch, self-critique it, identify improvements, fork, apply changes, compare, and document the iteration",
|
|
5023
|
+
{
|
|
5024
|
+
sketchId: import_zod.z.string().describe("ID of the sketch to critique and iterate on"),
|
|
5025
|
+
aspects: import_zod.z.string().optional().describe("Comma-separated aspects to focus on (composition, color, rhythm, unity, expression). Default: all"),
|
|
5026
|
+
iterations: import_zod.z.string().optional().describe("Number of improvement iterations (default: 1)")
|
|
5027
|
+
},
|
|
5028
|
+
async (args) => {
|
|
5029
|
+
const sketch = state.getSketch(args.sketchId);
|
|
5030
|
+
const iterations = args.iterations ? parseInt(args.iterations, 10) : 1;
|
|
5031
|
+
const aspectList = args.aspects ? args.aspects.split(",").map((a) => a.trim()) : ["composition", "color", "rhythm", "unity", "expression"];
|
|
5032
|
+
let sketchContext = "";
|
|
5033
|
+
if (sketch) {
|
|
5034
|
+
const def = sketch.definition;
|
|
5035
|
+
sketchContext = [
|
|
5036
|
+
`## Current Sketch: "${def.title}"`,
|
|
5037
|
+
`- **ID:** ${def.id}`,
|
|
5038
|
+
`- **Renderer:** ${def.renderer.type}`,
|
|
5039
|
+
`- **Canvas:** ${def.canvas.width}\xD7${def.canvas.height}`,
|
|
5040
|
+
`- **Composition Level:** ${def.compositionLevel ?? "sketch"}`,
|
|
5041
|
+
def.philosophy ? `- **Philosophy:** ${def.philosophy}` : `- **Philosophy:** not set`,
|
|
5042
|
+
`- **Parameters:** ${def.parameters?.length ?? 0} defined`,
|
|
5043
|
+
`- **Colors:** ${def.colors?.length ?? 0} defined`
|
|
5044
|
+
].join("\n");
|
|
5045
|
+
} else {
|
|
5046
|
+
sketchContext = `## Sketch: ${args.sketchId}
|
|
5047
|
+
*(Not currently loaded \u2014 use open_sketch first)*`;
|
|
5048
|
+
}
|
|
5049
|
+
return {
|
|
5050
|
+
messages: [
|
|
5051
|
+
{
|
|
5052
|
+
role: "user",
|
|
5053
|
+
content: {
|
|
5054
|
+
type: "text",
|
|
5055
|
+
text: [
|
|
5056
|
+
`Perform a structured critique-and-iterate cycle on a generative art sketch.`,
|
|
3738
5057
|
``,
|
|
3739
5058
|
sketchContext,
|
|
3740
5059
|
``,
|
|
3741
|
-
|
|
5060
|
+
`## Focus Aspects`,
|
|
5061
|
+
aspectList.map((a) => `- ${a}`).join("\n"),
|
|
3742
5062
|
``,
|
|
3743
|
-
`##
|
|
3744
|
-
`1. Use \`get_selection\` or \`open_sketch\` to examine the current sketch`,
|
|
3745
|
-
`2. Analyze how the theory applies to the existing algorithm`,
|
|
3746
|
-
`3. Use \`fork_sketch\` to create a theory-applied variant`,
|
|
3747
|
-
`4. Modify the fork's algorithm and parameters using the theory principles above`,
|
|
3748
|
-
`5. Use \`capture_screenshot\` to compare before and after`,
|
|
3749
|
-
`6. Update the philosophy field to document the design rationale`,
|
|
5063
|
+
`## Iterations: ${iterations}`,
|
|
3750
5064
|
``,
|
|
3751
|
-
|
|
5065
|
+
`## Process`,
|
|
5066
|
+
``,
|
|
5067
|
+
`For each iteration:`,
|
|
5068
|
+
``,
|
|
5069
|
+
`### Step 1: Capture & Critique`,
|
|
5070
|
+
`1. Use \`critique_sketch\` with sketchId="${args.sketchId}" and aspects=[${aspectList.map((a) => `"${a}"`).join(", ")}]`,
|
|
5071
|
+
`2. Study the returned screenshot carefully`,
|
|
5072
|
+
`3. Answer each framework question honestly \u2014 what works and what doesn't`,
|
|
5073
|
+
`4. Note the severity calibration for this composition level`,
|
|
5074
|
+
``,
|
|
5075
|
+
`### Step 2: Identify Improvements`,
|
|
5076
|
+
`Based on the critique, identify 2-3 specific, actionable improvements:`,
|
|
5077
|
+
`- Rank them by expected visual impact`,
|
|
5078
|
+
`- Be precise: "shift the focal cluster from center to upper-left third" not "improve composition"`,
|
|
5079
|
+
`- Consider which improvements can be achieved via parameter changes vs algorithm changes`,
|
|
5080
|
+
``,
|
|
5081
|
+
`### Step 3: Fork & Apply`,
|
|
5082
|
+
`1. Use \`fork_sketch\` to create a new version (preserve the original for comparison)`,
|
|
5083
|
+
`2. Apply the identified improvements:`,
|
|
5084
|
+
` - Use \`set_parameters\` or \`set_colors\` for parameter-level changes`,
|
|
5085
|
+
` - Use \`update_algorithm\` for algorithmic changes`,
|
|
5086
|
+
`3. Use \`capture_screenshot\` to verify each change visually`,
|
|
5087
|
+
``,
|
|
5088
|
+
`### Step 4: Compare`,
|
|
5089
|
+
`1. Use \`compare_sketches\` with the original and improved sketch IDs`,
|
|
5090
|
+
`2. Evaluate: did each intended improvement actually improve the piece?`,
|
|
5091
|
+
`3. Note any unintended consequences \u2014 improvements in one aspect sometimes degrade another`,
|
|
5092
|
+
``,
|
|
5093
|
+
`### Step 5: Document`,
|
|
5094
|
+
`After all iterations:`,
|
|
5095
|
+
`1. Update the improved sketch's philosophy field to document what changed and why`,
|
|
5096
|
+
`2. Summarize the iteration journey: what was tried, what worked, what was learned`,
|
|
5097
|
+
`3. If the original was better in some aspects, note what to preserve in future iterations`,
|
|
5098
|
+
``,
|
|
5099
|
+
`## Guidelines`,
|
|
5100
|
+
`- Be your own harshest (but fairest) critic \u2014 the goal is genuine improvement`,
|
|
5101
|
+
`- Small, focused changes are better than sweeping rewrites`,
|
|
5102
|
+
`- If a change doesn't work, revert it before trying the next improvement`,
|
|
5103
|
+
`- The final piece should feel like a natural evolution, not a different sketch`,
|
|
5104
|
+
`- Always pass your \`agent\` name and \`model\` identifier when calling tools that create or modify sketches`
|
|
5105
|
+
].join("\n")
|
|
5106
|
+
}
|
|
5107
|
+
}
|
|
5108
|
+
]
|
|
5109
|
+
};
|
|
5110
|
+
}
|
|
5111
|
+
);
|
|
5112
|
+
}
|
|
5113
|
+
function registerDevelopArtisticConcept(server, _state) {
|
|
5114
|
+
server.prompt(
|
|
5115
|
+
"develop-artistic-concept",
|
|
5116
|
+
"Develop an artistic concept through a full studio workflow: concept planning, studies, development, critique, iteration, and documentation",
|
|
5117
|
+
{
|
|
5118
|
+
concept: import_zod.z.string().describe("The artistic concept or theme to explore"),
|
|
5119
|
+
medium: import_zod.z.enum(["p5", "three", "glsl", "canvas2d", "svg"]).optional().describe("Preferred renderer/medium (default: p5)"),
|
|
5120
|
+
depth: import_zod.z.enum(["quick", "standard", "deep"]).optional().describe("How deeply to explore: quick (3 studies), standard (6 studies), deep (9+ studies). Default: standard")
|
|
5121
|
+
},
|
|
5122
|
+
async (args) => {
|
|
5123
|
+
const medium = args.medium ?? "p5";
|
|
5124
|
+
const depth = args.depth ?? "standard";
|
|
5125
|
+
const studyCount = depth === "quick" ? 3 : depth === "deep" ? 9 : 6;
|
|
5126
|
+
return {
|
|
5127
|
+
messages: [
|
|
5128
|
+
{
|
|
5129
|
+
role: "user",
|
|
5130
|
+
content: {
|
|
5131
|
+
type: "text",
|
|
5132
|
+
text: [
|
|
5133
|
+
`Develop the following artistic concept through a full studio workflow.`,
|
|
5134
|
+
``,
|
|
5135
|
+
`## Concept`,
|
|
5136
|
+
`${args.concept}`,
|
|
5137
|
+
``,
|
|
5138
|
+
`## Medium: ${medium}`,
|
|
5139
|
+
`## Depth: ${depth} (${studyCount} studies)`,
|
|
5140
|
+
``,
|
|
5141
|
+
`## Phase 1: Conceptual Planning`,
|
|
5142
|
+
`1. Use \`develop_concept\` with your concept and medium to get a structured plan`,
|
|
5143
|
+
`2. Define: mood, color strategy, compositional approach, and relevant skills`,
|
|
5144
|
+
`3. Create a series with \`create_series\` \u2014 write a narrative and intent statement`,
|
|
5145
|
+
``,
|
|
5146
|
+
`## Phase 2: Thumbnail Studies`,
|
|
5147
|
+
`1. Create ${studyCount} quick study-level sketches with \`create_sketch\` (compositionLevel: "study")`,
|
|
5148
|
+
`2. Each study should explore a different aspect of the concept:`,
|
|
5149
|
+
` - Vary composition (centered vs asymmetric vs edge-driven)`,
|
|
5150
|
+
` - Vary color (warm vs cool, saturated vs muted)`,
|
|
5151
|
+
` - Vary rhythm (regular vs progressive vs chaotic)`,
|
|
5152
|
+
` - Vary density (sparse vs dense vs gradient)`,
|
|
5153
|
+
`3. Use small canvases (600x600 or similar) \u2014 studies are fast explorations`,
|
|
5154
|
+
`4. Use \`capture_batch\` to see all studies at once`,
|
|
5155
|
+
``,
|
|
5156
|
+
`## Phase 3: Selection & Critique`,
|
|
5157
|
+
`1. Use \`series_summary\` to see the full set of studies with screenshots`,
|
|
5158
|
+
`2. Use \`critique_sketch\` on the 2-3 most promising studies`,
|
|
5159
|
+
`3. Identify which studies best capture the concept's intent`,
|
|
5160
|
+
`4. Note what works in each \u2014 composition choices, color relationships, rhythmic qualities`,
|
|
5161
|
+
``,
|
|
5162
|
+
`## Phase 4: Development`,
|
|
5163
|
+
`1. Use \`promote_sketch\` to advance the best 1-2 studies to "drafts" stage`,
|
|
5164
|
+
`2. Refine the promoted sketches:`,
|
|
5165
|
+
` - Add more parameters for fine control`,
|
|
5166
|
+
` - Develop the color palette with more nuance`,
|
|
5167
|
+
` - Strengthen compositional structure`,
|
|
5168
|
+
` - Load relevant skills with \`load_skill\` for guidance`,
|
|
5169
|
+
`3. Use \`critique_sketch\` after each round of changes`,
|
|
5170
|
+
``,
|
|
5171
|
+
`## Phase 5: Critique & Iteration`,
|
|
5172
|
+
`1. Use \`compare_sketches\` to evaluate drafts against each other`,
|
|
5173
|
+
`2. For the strongest draft, use the critique-and-iterate workflow:`,
|
|
5174
|
+
` - Critique \u2192 identify improvements \u2192 fork \u2192 apply \u2192 compare`,
|
|
5175
|
+
`3. Promote the best iteration to "refinements" stage`,
|
|
5176
|
+
`4. Continue refining until the piece feels resolved`,
|
|
5177
|
+
``,
|
|
5178
|
+
`## Phase 6: Final & Documentation`,
|
|
5179
|
+
`1. Promote the best refinement to "finals" stage (canvas will upscale)`,
|
|
5180
|
+
`2. Update the philosophy field with the full artistic statement`,
|
|
5181
|
+
`3. Use \`series_summary\` to capture the complete progression`,
|
|
5182
|
+
`4. Document: what was the concept? How did it evolve? What was discovered?`,
|
|
5183
|
+
``,
|
|
5184
|
+
`## Guidelines`,
|
|
5185
|
+
`- Each phase should feel like a natural progression, not a checklist`,
|
|
5186
|
+
`- Trust the studies \u2014 let unexpected results redirect the exploration`,
|
|
5187
|
+
`- The final piece should feel inevitable, like it couldn't have been any other way`,
|
|
5188
|
+
`- Always pass your \`agent\` name and \`model\` identifier when calling tools`,
|
|
5189
|
+
`- Use \`auto_arrange\` periodically to keep the workspace organized`
|
|
3752
5190
|
].join("\n")
|
|
3753
5191
|
}
|
|
3754
5192
|
}
|
|
@@ -3757,6 +5195,83 @@ function registerApplyDesignTheory(server, state) {
|
|
|
3757
5195
|
}
|
|
3758
5196
|
);
|
|
3759
5197
|
}
|
|
5198
|
+
function registerStudyReference(server, _state) {
|
|
5199
|
+
server.prompt(
|
|
5200
|
+
"study-reference",
|
|
5201
|
+
"Study a reference image: analyze it, identify key qualities, create a generative study sketch inspired by it, and document learnings",
|
|
5202
|
+
{
|
|
5203
|
+
referenceId: import_zod.z.string().describe("ID of the reference to study"),
|
|
5204
|
+
seriesId: import_zod.z.string().optional().describe("Series the reference belongs to (also where the study sketch will be added)"),
|
|
5205
|
+
sketchId: import_zod.z.string().optional().describe("Sketch the reference belongs to"),
|
|
5206
|
+
medium: import_zod.z.enum(["p5", "three", "glsl", "canvas2d", "svg"]).optional().describe("Renderer for the study sketch (default: p5)"),
|
|
5207
|
+
focus: import_zod.z.string().optional().describe("Specific quality to focus on: composition, palette, rhythm, mood, technique, or a custom focus")
|
|
5208
|
+
},
|
|
5209
|
+
async (args) => {
|
|
5210
|
+
const medium = args.medium ?? "p5";
|
|
5211
|
+
const focus = args.focus ?? "all key qualities";
|
|
5212
|
+
return {
|
|
5213
|
+
messages: [
|
|
5214
|
+
{
|
|
5215
|
+
role: "user",
|
|
5216
|
+
content: {
|
|
5217
|
+
type: "text",
|
|
5218
|
+
text: [
|
|
5219
|
+
`Study a reference image and create a generative art sketch inspired by it.`,
|
|
5220
|
+
``,
|
|
5221
|
+
`## Reference: ${args.referenceId}`,
|
|
5222
|
+
args.seriesId ? `## Series: ${args.seriesId}` : "",
|
|
5223
|
+
`## Medium: ${medium}`,
|
|
5224
|
+
`## Focus: ${focus}`,
|
|
5225
|
+
``,
|
|
5226
|
+
`## Phase 1: Analyze the Reference`,
|
|
5227
|
+
`1. Use \`analyze_reference\` with referenceId="${args.referenceId}"${args.seriesId ? ` seriesId="${args.seriesId}"` : ""}${args.sketchId ? ` sketchId="${args.sketchId}"` : ""} to get the analysis framework and image`,
|
|
5228
|
+
`2. Study the image carefully using the framework prompts`,
|
|
5229
|
+
`3. Answer each category: composition, palette, rhythm, mood, technique`,
|
|
5230
|
+
`4. Use \`update_reference_analysis\` to save your structured analysis`,
|
|
5231
|
+
``,
|
|
5232
|
+
`## Phase 2: Extract Key Qualities`,
|
|
5233
|
+
`From your analysis, identify 2-4 key qualities that are most interesting for generative art:`,
|
|
5234
|
+
`- These could be: a specific compositional structure, a color relationship, a rhythmic pattern, a mood quality`,
|
|
5235
|
+
`- Focus on qualities that can be *translated* into code, not literally replicated`,
|
|
5236
|
+
`- Consider what makes this reference compelling \u2014 what would be lost if you removed each quality?`,
|
|
5237
|
+
``,
|
|
5238
|
+
`## Phase 3: Extract Palette`,
|
|
5239
|
+
`1. Use \`extract_palette\` to study the reference's color strategy`,
|
|
5240
|
+
`2. Extract 5-8 hex colors that capture the essential palette`,
|
|
5241
|
+
`3. Save the palette in the reference analysis`,
|
|
5242
|
+
``,
|
|
5243
|
+
`## Phase 4: Create Study Sketch`,
|
|
5244
|
+
`1. Use \`create_sketch\` with compositionLevel: "study" to create a quick exploration`,
|
|
5245
|
+
`2. Translate the key qualities into generative parameters and algorithm choices:`,
|
|
5246
|
+
` - Composition \u2192 element placement, density distribution, negative space`,
|
|
5247
|
+
` - Palette \u2192 color definitions, themes derived from the reference palette`,
|
|
5248
|
+
` - Rhythm \u2192 repetition patterns, interval variations, scale relationships`,
|
|
5249
|
+
` - Mood \u2192 overall tone, animation speed, mark quality`,
|
|
5250
|
+
` - Technique \u2192 rendering approach, layering, transparency`,
|
|
5251
|
+
`3. Add the reference to the sketch with \`add_reference\``,
|
|
5252
|
+
`4. Document in the philosophy field how the reference influenced the study`,
|
|
5253
|
+
`5. Use \`capture_screenshot\` to verify the result`,
|
|
5254
|
+
``,
|
|
5255
|
+
`## Phase 5: Compare & Document`,
|
|
5256
|
+
`1. Use \`analyze_reference\` again to see the reference alongside your study`,
|
|
5257
|
+
`2. Evaluate: which qualities translated well? Which were lost or transformed?`,
|
|
5258
|
+
`3. Note what you learned \u2014 what worked, what surprised you, what to try next`,
|
|
5259
|
+
`4. Update the study sketch's philosophy with these insights`,
|
|
5260
|
+
``,
|
|
5261
|
+
`## Guidelines`,
|
|
5262
|
+
`- The goal is *inspiration*, not replication \u2014 a study should be recognizably generative`,
|
|
5263
|
+
`- A good study captures the *spirit* of the reference while being authentically algorithmic`,
|
|
5264
|
+
`- Use small canvases (600x600) \u2014 studies are explorations, not finished pieces`,
|
|
5265
|
+
`- If the reference suggests multiple interesting directions, create multiple studies`,
|
|
5266
|
+
`- Always pass your \`agent\` name and \`model\` identifier when calling tools`
|
|
5267
|
+
].filter(Boolean).join("\n")
|
|
5268
|
+
}
|
|
5269
|
+
}
|
|
5270
|
+
]
|
|
5271
|
+
};
|
|
5272
|
+
}
|
|
5273
|
+
);
|
|
5274
|
+
}
|
|
3760
5275
|
|
|
3761
5276
|
// src/server.ts
|
|
3762
5277
|
function jsonResult(data) {
|
|
@@ -3771,22 +5286,36 @@ function toolError(message) {
|
|
|
3771
5286
|
};
|
|
3772
5287
|
}
|
|
3773
5288
|
async function initializePluginRegistry() {
|
|
3774
|
-
const
|
|
5289
|
+
const registry5 = (0, import_core15.createPluginRegistry)({
|
|
3775
5290
|
surface: "mcp",
|
|
3776
5291
|
supportsInteractiveTools: false,
|
|
3777
5292
|
supportsRendering: false
|
|
3778
5293
|
});
|
|
3779
|
-
await
|
|
3780
|
-
await
|
|
3781
|
-
await
|
|
3782
|
-
await
|
|
3783
|
-
|
|
5294
|
+
await registry5.register(import_plugin_typography.default);
|
|
5295
|
+
await registry5.register(import_plugin_filters.default);
|
|
5296
|
+
await registry5.register(import_plugin_shapes.default);
|
|
5297
|
+
await registry5.register(import_plugin_layout_guides.default);
|
|
5298
|
+
await registry5.register(import_plugin_painting.default);
|
|
5299
|
+
await registry5.register(import_plugin_textures.default);
|
|
5300
|
+
await registry5.register(import_plugin_animation.default);
|
|
5301
|
+
await registry5.register(import_plugin_color_adjust.default);
|
|
5302
|
+
await registry5.register(import_plugin_compositing.default);
|
|
5303
|
+
await registry5.register(import_plugin_construction.default);
|
|
5304
|
+
await registry5.register(import_plugin_distribution.default);
|
|
5305
|
+
await registry5.register(import_plugin_figure.default);
|
|
5306
|
+
await registry5.register(import_plugin_layout_composition.default);
|
|
5307
|
+
await registry5.register(import_plugin_perspective.default);
|
|
5308
|
+
await registry5.register(import_plugin_poses.default);
|
|
5309
|
+
await registry5.register(import_plugin_styles.default);
|
|
5310
|
+
await registry5.register(import_plugin_symbols.default);
|
|
5311
|
+
await registry5.register(import_plugin_trace.default);
|
|
5312
|
+
return registry5;
|
|
3784
5313
|
}
|
|
3785
5314
|
function createServer(state) {
|
|
3786
5315
|
const server = new import_mcp.McpServer(
|
|
3787
5316
|
{
|
|
3788
5317
|
name: "@genart/mcp-server",
|
|
3789
|
-
version: "0.
|
|
5318
|
+
version: "0.4.0"
|
|
3790
5319
|
},
|
|
3791
5320
|
{
|
|
3792
5321
|
capabilities: {
|
|
@@ -3796,9 +5325,9 @@ function createServer(state) {
|
|
|
3796
5325
|
}
|
|
3797
5326
|
}
|
|
3798
5327
|
);
|
|
3799
|
-
const registryReady = initializePluginRegistry().then((
|
|
3800
|
-
state.pluginRegistry =
|
|
3801
|
-
registerPluginMcpTools(server,
|
|
5328
|
+
const registryReady = initializePluginRegistry().then((registry5) => {
|
|
5329
|
+
state.pluginRegistry = registry5;
|
|
5330
|
+
registerPluginMcpTools(server, registry5, state);
|
|
3802
5331
|
});
|
|
3803
5332
|
server._pluginsReady = registryReady;
|
|
3804
5333
|
registerWorkspaceTools(server, state);
|
|
@@ -3813,6 +5342,9 @@ function createServer(state) {
|
|
|
3813
5342
|
registerKnowledgeTools(server, state);
|
|
3814
5343
|
registerDesignTools(server, state);
|
|
3815
5344
|
registerCaptureTools(server, state);
|
|
5345
|
+
registerCritiqueTools(server, state);
|
|
5346
|
+
registerSeriesTools(server, state);
|
|
5347
|
+
registerReferenceTools(server, state);
|
|
3816
5348
|
registerExportTools(server, state);
|
|
3817
5349
|
registerResources(server, state);
|
|
3818
5350
|
registerPrompts(server, state);
|
|
@@ -4577,6 +6109,276 @@ function registerCaptureTools(server, state) {
|
|
|
4577
6109
|
}
|
|
4578
6110
|
);
|
|
4579
6111
|
}
|
|
6112
|
+
function registerCritiqueTools(server, state) {
|
|
6113
|
+
server.tool(
|
|
6114
|
+
"critique_sketch",
|
|
6115
|
+
"Capture a sketch screenshot and return a structured self-critique framework (questions, principles, pitfalls) per aspect. Severity calibrates to compositionLevel.",
|
|
6116
|
+
{
|
|
6117
|
+
sketchId: import_zod2.z.string().optional().describe("Sketch to critique (default: selected sketch)"),
|
|
6118
|
+
aspects: import_zod2.z.array(import_zod2.z.enum(["composition", "color", "rhythm", "unity", "expression"])).optional().describe("Aspects to critique (default: all five)"),
|
|
6119
|
+
previewSize: import_zod2.z.number().optional().describe("Max dimension for inline preview JPEG (default: 400)")
|
|
6120
|
+
},
|
|
6121
|
+
async (args) => {
|
|
6122
|
+
try {
|
|
6123
|
+
const result = await critiqueSketch(state, args);
|
|
6124
|
+
return {
|
|
6125
|
+
content: [
|
|
6126
|
+
{ type: "text", text: JSON.stringify(result.metadata, null, 2) },
|
|
6127
|
+
{ type: "image", data: result.previewJpegBase64, mimeType: "image/jpeg" }
|
|
6128
|
+
]
|
|
6129
|
+
};
|
|
6130
|
+
} catch (e) {
|
|
6131
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
6132
|
+
}
|
|
6133
|
+
}
|
|
6134
|
+
);
|
|
6135
|
+
server.tool(
|
|
6136
|
+
"compare_sketches",
|
|
6137
|
+
"Side-by-side capture of 2-4 sketches with a structured comparison framework across specified aspects.",
|
|
6138
|
+
{
|
|
6139
|
+
sketchIds: import_zod2.z.array(import_zod2.z.string()).describe("IDs of 2-4 sketches to compare"),
|
|
6140
|
+
aspects: import_zod2.z.array(import_zod2.z.enum(["composition", "color", "rhythm", "unity", "expression"])).optional().describe("Aspects to compare (default: all five)"),
|
|
6141
|
+
previewSize: import_zod2.z.number().optional().describe("Max dimension for inline preview JPEGs (default: 300)")
|
|
6142
|
+
},
|
|
6143
|
+
async (args) => {
|
|
6144
|
+
try {
|
|
6145
|
+
const result = await compareSketches(state, args);
|
|
6146
|
+
const content = [
|
|
6147
|
+
{ type: "text", text: JSON.stringify(result.metadata, null, 2) }
|
|
6148
|
+
];
|
|
6149
|
+
for (const preview of result.previews) {
|
|
6150
|
+
content.push({
|
|
6151
|
+
type: "text",
|
|
6152
|
+
text: `--- Sketch: ${preview.sketchId} ---`
|
|
6153
|
+
});
|
|
6154
|
+
content.push({
|
|
6155
|
+
type: "image",
|
|
6156
|
+
data: preview.inlineJpegBase64,
|
|
6157
|
+
mimeType: "image/jpeg"
|
|
6158
|
+
});
|
|
6159
|
+
}
|
|
6160
|
+
return { content };
|
|
6161
|
+
} catch (e) {
|
|
6162
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
6163
|
+
}
|
|
6164
|
+
}
|
|
6165
|
+
);
|
|
6166
|
+
}
|
|
6167
|
+
function registerSeriesTools(server, state) {
|
|
6168
|
+
server.tool(
|
|
6169
|
+
"create_series",
|
|
6170
|
+
"Create a new curated series of sketches with narrative, intent, and studio workflow stages",
|
|
6171
|
+
{
|
|
6172
|
+
label: import_zod2.z.string().describe("Display label for the series"),
|
|
6173
|
+
narrative: import_zod2.z.string().describe("Prose narrative describing the artistic exploration"),
|
|
6174
|
+
intent: import_zod2.z.string().describe("Short statement of artistic intent"),
|
|
6175
|
+
progression: import_zod2.z.string().optional().describe(
|
|
6176
|
+
"Series progression type (e.g. 'linear', 'branching', 'iterative')"
|
|
6177
|
+
),
|
|
6178
|
+
stages: import_zod2.z.array(import_zod2.z.enum(["studies", "drafts", "refinements", "finals"])).optional().describe(
|
|
6179
|
+
"Ordered stages in the studio workflow (default: all four)"
|
|
6180
|
+
),
|
|
6181
|
+
sketchFiles: import_zod2.z.array(import_zod2.z.string()).optional().describe("File names of existing sketches to include")
|
|
6182
|
+
},
|
|
6183
|
+
async (args) => {
|
|
6184
|
+
try {
|
|
6185
|
+
const result = await createSeries(state, args);
|
|
6186
|
+
return jsonResult(result);
|
|
6187
|
+
} catch (e) {
|
|
6188
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
6189
|
+
}
|
|
6190
|
+
}
|
|
6191
|
+
);
|
|
6192
|
+
server.tool(
|
|
6193
|
+
"develop_concept",
|
|
6194
|
+
"Generate a structured concept development plan with mood, palette, composition, skills, and series structure recommendations",
|
|
6195
|
+
{
|
|
6196
|
+
concept: import_zod2.z.string().describe("The artistic concept or theme to develop"),
|
|
6197
|
+
medium: import_zod2.z.enum(["p5", "three", "glsl", "canvas2d", "svg"]).optional().describe("Preferred renderer/medium (default: p5)")
|
|
6198
|
+
},
|
|
6199
|
+
async (args) => {
|
|
6200
|
+
try {
|
|
6201
|
+
const result = await developConcept(state, args);
|
|
6202
|
+
return jsonResult(result);
|
|
6203
|
+
} catch (e) {
|
|
6204
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
6205
|
+
}
|
|
6206
|
+
}
|
|
6207
|
+
);
|
|
6208
|
+
server.tool(
|
|
6209
|
+
"series_summary",
|
|
6210
|
+
"Capture all sketches in a series with narrative context for holistic evaluation",
|
|
6211
|
+
{
|
|
6212
|
+
seriesId: import_zod2.z.string().describe("ID of the series to summarize"),
|
|
6213
|
+
captureScreenshots: import_zod2.z.boolean().optional().describe("Capture screenshots of each sketch (default: true)"),
|
|
6214
|
+
previewSize: import_zod2.z.number().optional().describe("Preview image size in pixels (default: 300)")
|
|
6215
|
+
},
|
|
6216
|
+
async (args) => {
|
|
6217
|
+
try {
|
|
6218
|
+
const result = await seriesSummary(state, args);
|
|
6219
|
+
const content = [
|
|
6220
|
+
{ type: "text", text: JSON.stringify(result.metadata, null, 2) }
|
|
6221
|
+
];
|
|
6222
|
+
if (result.previews) {
|
|
6223
|
+
for (const preview of result.previews) {
|
|
6224
|
+
content.push({
|
|
6225
|
+
type: "image",
|
|
6226
|
+
data: preview.inlineJpegBase64,
|
|
6227
|
+
mimeType: "image/jpeg"
|
|
6228
|
+
});
|
|
6229
|
+
}
|
|
6230
|
+
}
|
|
6231
|
+
return { content };
|
|
6232
|
+
} catch (e) {
|
|
6233
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
6234
|
+
}
|
|
6235
|
+
}
|
|
6236
|
+
);
|
|
6237
|
+
server.tool(
|
|
6238
|
+
"promote_sketch",
|
|
6239
|
+
"Promote a sketch to the next studio workflow stage \u2014 fork, upscale canvas, update compositionLevel, and add to series",
|
|
6240
|
+
{
|
|
6241
|
+
sketchId: import_zod2.z.string().describe("ID of the sketch to promote"),
|
|
6242
|
+
toStage: import_zod2.z.enum(["studies", "drafts", "refinements", "finals"]).describe("Target stage to promote to"),
|
|
6243
|
+
seriesId: import_zod2.z.string().optional().describe("Series to add the promoted sketch to"),
|
|
6244
|
+
newId: import_zod2.z.string().optional().describe(
|
|
6245
|
+
"URL-safe kebab-case ID for the promoted sketch (default: auto-generated)"
|
|
6246
|
+
),
|
|
6247
|
+
title: import_zod2.z.string().optional().describe("Title for the promoted sketch (default: auto-generated)"),
|
|
6248
|
+
agent: import_zod2.z.string().optional().describe("CLI agent name"),
|
|
6249
|
+
model: import_zod2.z.string().optional().describe("AI model identifier")
|
|
6250
|
+
},
|
|
6251
|
+
async (args) => {
|
|
6252
|
+
try {
|
|
6253
|
+
const result = await promoteSketch(state, args);
|
|
6254
|
+
return jsonResult(result);
|
|
6255
|
+
} catch (e) {
|
|
6256
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
6257
|
+
}
|
|
6258
|
+
}
|
|
6259
|
+
);
|
|
6260
|
+
}
|
|
6261
|
+
function registerReferenceTools(server, state) {
|
|
6262
|
+
server.tool(
|
|
6263
|
+
"add_reference",
|
|
6264
|
+
"Import an image as a reference for inspiration. Copies the image to the workspace references/ directory and attaches it to a series or sketch.",
|
|
6265
|
+
{
|
|
6266
|
+
image: import_zod2.z.string().describe("Path to the reference image file"),
|
|
6267
|
+
type: import_zod2.z.enum(["image", "artwork", "photograph", "texture", "palette"]).optional().describe("Reference type (default: image)"),
|
|
6268
|
+
source: import_zod2.z.string().optional().describe("Source attribution (artist, URL, collection)"),
|
|
6269
|
+
seriesId: import_zod2.z.string().optional().describe("Series to attach the reference to"),
|
|
6270
|
+
sketchId: import_zod2.z.string().optional().describe("Sketch to attach the reference to"),
|
|
6271
|
+
id: import_zod2.z.string().optional().describe("Custom reference ID (default: derived from filename)")
|
|
6272
|
+
},
|
|
6273
|
+
async (args) => {
|
|
6274
|
+
try {
|
|
6275
|
+
const result = await addReference(state, args);
|
|
6276
|
+
return jsonResult(result);
|
|
6277
|
+
} catch (e) {
|
|
6278
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
6279
|
+
}
|
|
6280
|
+
}
|
|
6281
|
+
);
|
|
6282
|
+
server.tool(
|
|
6283
|
+
"analyze_reference",
|
|
6284
|
+
"Return a structured analysis framework for a reference image, with the image for visual inspection. The agent fills in the analysis using the framework prompts.",
|
|
6285
|
+
{
|
|
6286
|
+
referenceId: import_zod2.z.string().describe("ID of the reference to analyze"),
|
|
6287
|
+
seriesId: import_zod2.z.string().optional().describe("Series the reference belongs to (speeds up lookup)"),
|
|
6288
|
+
sketchId: import_zod2.z.string().optional().describe("Sketch the reference belongs to (speeds up lookup)"),
|
|
6289
|
+
previewSize: import_zod2.z.number().optional().describe("Max dimension for preview image (default: native)")
|
|
6290
|
+
},
|
|
6291
|
+
async (args) => {
|
|
6292
|
+
try {
|
|
6293
|
+
const result = await analyzeReference(state, args);
|
|
6294
|
+
const content = [
|
|
6295
|
+
{ type: "text", text: JSON.stringify(result.metadata, null, 2) }
|
|
6296
|
+
];
|
|
6297
|
+
if (result.previewJpegBase64) {
|
|
6298
|
+
const ext = (result.metadata["path"] ?? ".png").split(".").pop() ?? "png";
|
|
6299
|
+
const mimeMap = {
|
|
6300
|
+
png: "image/png",
|
|
6301
|
+
jpg: "image/jpeg",
|
|
6302
|
+
jpeg: "image/jpeg",
|
|
6303
|
+
gif: "image/gif",
|
|
6304
|
+
webp: "image/webp",
|
|
6305
|
+
svg: "image/svg+xml"
|
|
6306
|
+
};
|
|
6307
|
+
content.push({
|
|
6308
|
+
type: "image",
|
|
6309
|
+
data: result.previewJpegBase64,
|
|
6310
|
+
mimeType: mimeMap[ext] ?? "image/png"
|
|
6311
|
+
});
|
|
6312
|
+
}
|
|
6313
|
+
return { content };
|
|
6314
|
+
} catch (e) {
|
|
6315
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
6316
|
+
}
|
|
6317
|
+
}
|
|
6318
|
+
);
|
|
6319
|
+
server.tool(
|
|
6320
|
+
"update_reference_analysis",
|
|
6321
|
+
"Save a structured analysis (composition, palette, rhythm, mood, technique) back to a reference after studying it with analyze_reference.",
|
|
6322
|
+
{
|
|
6323
|
+
referenceId: import_zod2.z.string().describe("ID of the reference to update"),
|
|
6324
|
+
seriesId: import_zod2.z.string().optional().describe("Series the reference belongs to"),
|
|
6325
|
+
sketchId: import_zod2.z.string().optional().describe("Sketch the reference belongs to"),
|
|
6326
|
+
analysis: import_zod2.z.object({
|
|
6327
|
+
composition: import_zod2.z.string().optional().describe("Compositional structure observations"),
|
|
6328
|
+
palette: import_zod2.z.array(import_zod2.z.string()).optional().describe("Dominant colors as hex values"),
|
|
6329
|
+
rhythm: import_zod2.z.string().optional().describe("Visual rhythm and pattern observations"),
|
|
6330
|
+
mood: import_zod2.z.string().optional().describe("Mood and emotional qualities"),
|
|
6331
|
+
technique: import_zod2.z.string().optional().describe("Technique and medium observations"),
|
|
6332
|
+
keyQualities: import_zod2.z.array(import_zod2.z.string()).optional().describe("Key qualities worth studying")
|
|
6333
|
+
}).describe("Structured analysis to save")
|
|
6334
|
+
},
|
|
6335
|
+
async (args) => {
|
|
6336
|
+
try {
|
|
6337
|
+
const result = await updateReferenceAnalysis(state, args);
|
|
6338
|
+
return jsonResult(result);
|
|
6339
|
+
} catch (e) {
|
|
6340
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
6341
|
+
}
|
|
6342
|
+
}
|
|
6343
|
+
);
|
|
6344
|
+
server.tool(
|
|
6345
|
+
"extract_palette",
|
|
6346
|
+
"Return a reference image for color palette extraction, with guidelines for identifying dominant colors. The agent extracts hex colors visually.",
|
|
6347
|
+
{
|
|
6348
|
+
referenceId: import_zod2.z.string().describe("ID of the reference to extract palette from"),
|
|
6349
|
+
seriesId: import_zod2.z.string().optional().describe("Series the reference belongs to"),
|
|
6350
|
+
sketchId: import_zod2.z.string().optional().describe("Sketch the reference belongs to"),
|
|
6351
|
+
count: import_zod2.z.number().optional().describe("Number of colors to extract (default: 6)")
|
|
6352
|
+
},
|
|
6353
|
+
async (args) => {
|
|
6354
|
+
try {
|
|
6355
|
+
const result = await extractPalette(state, args);
|
|
6356
|
+
const content = [
|
|
6357
|
+
{ type: "text", text: JSON.stringify(result.metadata, null, 2) }
|
|
6358
|
+
];
|
|
6359
|
+
if (result.previewJpegBase64) {
|
|
6360
|
+
const ext = (result.metadata["path"] ?? ".png").split(".").pop() ?? "png";
|
|
6361
|
+
const mimeMap = {
|
|
6362
|
+
png: "image/png",
|
|
6363
|
+
jpg: "image/jpeg",
|
|
6364
|
+
jpeg: "image/jpeg",
|
|
6365
|
+
gif: "image/gif",
|
|
6366
|
+
webp: "image/webp",
|
|
6367
|
+
svg: "image/svg+xml"
|
|
6368
|
+
};
|
|
6369
|
+
content.push({
|
|
6370
|
+
type: "image",
|
|
6371
|
+
data: result.previewJpegBase64,
|
|
6372
|
+
mimeType: mimeMap[ext] ?? "image/png"
|
|
6373
|
+
});
|
|
6374
|
+
}
|
|
6375
|
+
return { content };
|
|
6376
|
+
} catch (e) {
|
|
6377
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
6378
|
+
}
|
|
6379
|
+
}
|
|
6380
|
+
);
|
|
6381
|
+
}
|
|
4580
6382
|
function registerExportTools(server, state) {
|
|
4581
6383
|
server.tool(
|
|
4582
6384
|
"export_sketch",
|
|
@@ -4841,7 +6643,7 @@ function registerDesignTools(server, state) {
|
|
|
4841
6643
|
}
|
|
4842
6644
|
);
|
|
4843
6645
|
}
|
|
4844
|
-
function registerKnowledgeTools(server,
|
|
6646
|
+
function registerKnowledgeTools(server, state) {
|
|
4845
6647
|
server.tool(
|
|
4846
6648
|
"list_skills",
|
|
4847
6649
|
"List all available design knowledge skills (Phase 5)",
|
|
@@ -4877,7 +6679,7 @@ function registerKnowledgeTools(server, _state) {
|
|
|
4877
6679
|
"get_guidelines",
|
|
4878
6680
|
"Return design guidelines and best practices for a topic (Phase 5)",
|
|
4879
6681
|
{
|
|
4880
|
-
topic: import_zod2.z.enum(["composition", "color", "parameters", "animation", "performance"]).describe("Guideline topic"),
|
|
6682
|
+
topic: import_zod2.z.enum(["composition", "color", "process", "painting", "illustration", "parameters", "animation", "performance"]).describe("Guideline topic"),
|
|
4881
6683
|
renderer: import_zod2.z.enum(["p5", "three", "glsl", "canvas2d", "svg"]).optional().describe("Renderer-specific guidance")
|
|
4882
6684
|
},
|
|
4883
6685
|
async (args) => {
|
|
@@ -4889,6 +6691,22 @@ function registerKnowledgeTools(server, _state) {
|
|
|
4889
6691
|
}
|
|
4890
6692
|
}
|
|
4891
6693
|
);
|
|
6694
|
+
server.tool(
|
|
6695
|
+
"suggest_skills",
|
|
6696
|
+
"Recommend relevant design skills based on sketch context and/or free-text description",
|
|
6697
|
+
{
|
|
6698
|
+
sketchId: import_zod2.z.string().optional().describe("ID of a loaded sketch to analyze for skill recommendations"),
|
|
6699
|
+
context: import_zod2.z.string().optional().describe("Free-text description of what you're working on (e.g., 'atmospheric landscape with watercolor')")
|
|
6700
|
+
},
|
|
6701
|
+
async (args) => {
|
|
6702
|
+
try {
|
|
6703
|
+
const result = await suggestSkills(state, args);
|
|
6704
|
+
return jsonResult(result);
|
|
6705
|
+
} catch (e) {
|
|
6706
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
6707
|
+
}
|
|
6708
|
+
}
|
|
6709
|
+
);
|
|
4892
6710
|
}
|
|
4893
6711
|
|
|
4894
6712
|
// src/index.ts
|