@kevlns/art-workshop 0.2.1 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/AGENTS.md +26 -49
  2. package/README.md +31 -93
  3. package/art-workshop.mjs +70 -26
  4. package/docs/commands.md +913 -80
  5. package/docs/configuration.md +33 -139
  6. package/docs/core-guidance.md +15 -76
  7. package/docs/data-formats.md +15 -151
  8. package/docs/deployment.md +42 -0
  9. package/docs/model-architecture.md +52 -0
  10. package/docs/modes.md +15 -116
  11. package/docs/remote-models.md +42 -0
  12. package/docs/troubleshooting.md +31 -67
  13. package/lib/adapters/dashscope.mjs +234 -0
  14. package/lib/adapters/index.mjs +28 -0
  15. package/lib/agent.mjs +2 -2
  16. package/lib/analysis-worker.mjs +27 -0
  17. package/lib/analyze.mjs +29 -13
  18. package/lib/backends.mjs +350 -74
  19. package/lib/bl.mjs +3 -18
  20. package/lib/candidates.mjs +82 -0
  21. package/lib/comfyui.mjs +10 -8
  22. package/lib/contracts.d.ts +67 -0
  23. package/lib/core.mjs +24 -45
  24. package/lib/deployment-process.mjs +19 -0
  25. package/lib/deployment-source.mjs +24 -0
  26. package/lib/deployment-worker.mjs +86 -0
  27. package/lib/deployment.mjs +75 -0
  28. package/lib/design.mjs +5 -5
  29. package/lib/dimensions.mjs +22 -0
  30. package/lib/edit.mjs +6 -3
  31. package/lib/environments.mjs +67 -0
  32. package/lib/execution/remote.mjs +156 -0
  33. package/lib/executor.mjs +12 -24
  34. package/lib/generate.mjs +9 -6
  35. package/lib/generation-policy.mjs +198 -0
  36. package/lib/images.mjs +10 -0
  37. package/lib/lifecycle.mjs +40 -0
  38. package/lib/migration.mjs +154 -0
  39. package/lib/model-catalog.mjs +288 -0
  40. package/lib/model-registry.mjs +234 -0
  41. package/lib/plan.mjs +98 -28
  42. package/lib/project.mjs +13 -4
  43. package/lib/providers.mjs +27 -22
  44. package/lib/refs.mjs +10 -18
  45. package/lib/runtime.mjs +6 -4
  46. package/lib/service.mjs +45 -4
  47. package/lib/settings.mjs +2 -4
  48. package/lib/shared.mjs +10 -7
  49. package/lib/style-contract.mjs +19 -0
  50. package/lib/style-lifecycle.mjs +73 -0
  51. package/lib/task-references.mjs +37 -0
  52. package/lib/task-worker.mjs +225 -50
  53. package/lib/tasks.mjs +442 -63
  54. package/lib/templates.mjs +68 -0
  55. package/lib/transport/cli.mjs +69 -0
  56. package/lib/transport/http.mjs +82 -0
  57. package/lib/vision.mjs +46 -0
  58. package/lib/workflows.mjs +10 -1
  59. package/lib/workspace.mjs +211 -0
  60. package/package.json +9 -3
  61. package/rules/core-guidance.json +14 -13
  62. package/skills/art-workshop/SKILL.md +28 -53
  63. package/v-cli.plugin.json +1257 -143
  64. package/docs//351/227/256/351/242/230/346/212/245/345/221/212-2026-10-08.md +0 -29
@@ -1,58 +1,233 @@
1
- import {existsSync,readdirSync,renameSync,writeFileSync} from 'node:fs';
2
- import {join} from 'node:path';
3
- import {readJson,writeJson,hash} from './shared.mjs';
4
- import {sha256File} from './bl.mjs';
5
- import {validatePlan} from './plan.mjs';
6
- import {externalPath} from './settings.mjs';
7
- import {ensureService} from './service.mjs';
8
- import {generate,generationRequest} from './providers.mjs';
9
- import {cancelPrompt} from './comfyui.mjs';
1
+ import { existsSync, readdirSync, renameSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { readJson, writeJson, hash } from "./shared.mjs";
4
+ import { sha256File } from "./bl.mjs";
5
+ import { validatePlan } from "./plan.mjs";
6
+ import { externalPath } from "./settings.mjs";
7
+ import { ensureService } from "./service.mjs";
8
+ import { generate, generationRequest } from "./providers.mjs";
9
+ import { cancelPrompt } from "./comfyui.mjs";
10
+ import { validateImage } from "./images.mjs";
10
11
 
11
- const file=process.argv[2],task=readJson(file);
12
- const cancelled=()=>existsSync(file+'.cancel')||existsSync(join(task.root,'shutdown.json'));
13
- const persist=()=>{task.heartbeat=new Date().toISOString();writeJson(file,task);};
14
- task.workerPid=process.pid;task.status='running';persist();
15
- const heartbeat=setInterval(persist,1000);
16
- let manifest,manifestPath;
17
- function saveManifest(){if(!manifest)return;manifest.summary={expected:task.items.length,completed:manifest.items.filter(x=>x.status!=='running').length,ok:manifest.items.filter(x=>x.ok).length,failed:manifest.items.filter(x=>x.status==='failed').length,cancelled:manifest.items.filter(x=>x.status==='cancelled').length};writeJson(manifestPath,manifest);}
12
+ const file = process.argv[2],
13
+ task = readJson(file);
14
+ const cancelled = () => {
15
+ const requested =
16
+ existsSync(file + ".cancel") ||
17
+ existsSync(join(task.root, "shutdown.json"));
18
+ if (
19
+ requested &&
20
+ !["succeeded", "failed", "cancelled", "unknown"].includes(task.status)
21
+ )
22
+ task.status = "cancelling";
23
+ return requested;
24
+ };
25
+ const persist = () => {
26
+ task.heartbeat = new Date().toISOString();
27
+ writeJson(file, task);
28
+ };
29
+ task.workerPid = process.pid;
30
+ task.status = "running";
31
+ persist();
32
+ const heartbeat = setInterval(persist, 1000);
33
+ let manifest, manifestPath;
34
+ function saveManifest() {
35
+ if (!manifest) return;
36
+ manifest.summary = {
37
+ expected: task.items.length,
38
+ completed: manifest.items.filter((x) => x.status !== "running").length,
39
+ ok: manifest.items.filter((x) => x.ok).length,
40
+ failed: manifest.items.filter((x) => x.status === "failed").length,
41
+ cancelled: manifest.items.filter((x) => x.status === "cancelled").length,
42
+ };
43
+ writeJson(manifestPath, manifest);
44
+ }
18
45
  try {
19
- validatePlan(task.plan);externalPath(task.outputRoot,'输出目录');
20
- for(const ref of task.plan.refs)if(sha256File(externalPath(ref.path))!==ref.hash)throw new Error('原图/参考图已变化:'+ref.path);
21
- const runDir=join(task.outputRoot,task.plan.job+'-'+task.taskId);
22
- manifestPath=join(runDir,'manifest.json');
23
- task.manifestPath=manifestPath;
24
- manifest={schema:'art-workshop/run',runId:task.taskId,taskId:task.taskId,plan:task.plan,planHash:task.plan.planHash,provider:task.plan.backend?.provider??'bailian',startedAt:new Date().toISOString(),items:[],review:[],selections:{}};saveManifest();persist();
25
- const backend=task.plan.backend;
26
- if(backend?.provider==='comfyui')task.endpoint=await ensureService(backend,task.root,{cancelled});
27
- for(const item of task.items) {
28
- if(cancelled())break;
29
- task.currentItem={itemId:item.itemId,variantId:item.variantId};persist();
30
- const record={...structuredClone(item),ok:false,status:'running',files:[],urls:[],outputHashes:{}};
31
- manifest.items.push(record);saveManifest();
46
+ validatePlan(task.plan);
47
+ externalPath(task.outputRoot, "输出目录");
48
+ for (const ref of task.resumeOnly ? [] : task.plan.refs)
49
+ if (sha256File(externalPath(ref.path)) !== ref.hash)
50
+ throw new Error("原图/参考图已变化:" + ref.path);
51
+ const runDir = join(task.outputRoot, task.plan.job + "-" + task.taskId);
52
+ manifestPath = join(runDir, "manifest.json");
53
+ task.manifestPath = manifestPath;
54
+ manifest = task.resumeOnly
55
+ ? readJson(manifestPath)
56
+ : {
57
+ schema: "art-workshop/run",
58
+ runId: task.taskId,
59
+ taskId: task.taskId,
60
+ plan: task.plan,
61
+ planHash: task.plan.planHash,
62
+ provider: task.plan.backend?.provider ?? "bailian",
63
+ startedAt: new Date().toISOString(),
64
+ items: [],
65
+ };
66
+ if (
67
+ manifest.taskId !== task.taskId ||
68
+ manifest.planHash !== task.plan.planHash
69
+ )
70
+ throw new Error("原批次结果身份不匹配");
71
+ if (task.resumeOnly) manifest.finishedAt = null;
72
+ saveManifest();
73
+ persist();
74
+ const backend = task.plan.backend;
75
+ if (backend?.provider === "comfyui")
76
+ task.endpoint = await ensureService(backend, task.root, { cancelled });
77
+ for (const item of task.items) {
78
+ if (cancelled()) break;
79
+ if (
80
+ task.resumeOnly &&
81
+ !["accepted", "completed"].includes(
82
+ task.remoteExecutions?.[item.inputHash]?.state,
83
+ )
84
+ )
85
+ continue;
86
+ if (
87
+ task.resumeOnly &&
88
+ manifest.items.some((row) => row.inputHash === item.inputHash && row.ok)
89
+ )
90
+ continue;
91
+ task.currentItem = { itemId: item.itemId, variantId: item.variantId };
92
+ persist();
93
+ const record = {
94
+ ...structuredClone(item),
95
+ ok: false,
96
+ status: "running",
97
+ files: [],
98
+ urls: [],
99
+ outputHashes: {},
100
+ };
101
+ const previousIndex = manifest.items.findIndex(
102
+ (row) => row.inputHash === item.inputHash,
103
+ );
104
+ if (previousIndex >= 0) manifest.items[previousIndex] = record;
105
+ else manifest.items.push(record);
106
+ saveManifest();
32
107
  try {
33
- const before=new Set(readdirSync(runDir));
34
- const request=generationRequest(task.plan,item);
35
- record.request=request;saveManifest();
36
- const result=await generate(task.plan,item,{endpoint:task.endpoint,root:task.root,outputDir:runDir,prefix:`${item.itemId}--${item.variantId}`,cancelled,onPrompt:promptId=>{task.promptId=promptId;persist();},onRemoteCancel:()=>{task.remoteCancellation='client-stopped; upstream execution cannot be confirmed';}});
37
- if(result.files)record.files=result.files;
108
+ const before = new Set(readdirSync(runDir));
109
+ const request = generationRequest(task.plan, item);
110
+ record.request = request;
111
+ saveManifest();
112
+ const result = await generate(task.plan, item, {
113
+ endpoint: task.endpoint,
114
+ root: task.root,
115
+ outputDir: runDir,
116
+ prefix: `${item.itemId}--${item.variantId}`,
117
+ cancelled,
118
+ receipt: task.remoteExecutions?.[item.inputHash],
119
+ onReceipt: (receipt) => {
120
+ task.remoteExecutions ??= {};
121
+ task.remoteExecutions[item.inputHash] = receipt;
122
+ record.remote = receipt;
123
+ const pending = Object.values(task.remoteExecutions).some((value) =>
124
+ ["dispatching", "accepted"].includes(value.state),
125
+ );
126
+ task.unsettled = pending;
127
+ if (!pending) task.remoteCancellation = null;
128
+ persist();
129
+ saveManifest();
130
+ },
131
+ onPrompt: (promptId) => {
132
+ task.promptId = promptId;
133
+ persist();
134
+ },
135
+ onRemoteCancel: () => {
136
+ task.remoteCancellation =
137
+ "client-stopped; upstream execution cannot be confirmed";
138
+ task.unsettled = true;
139
+ persist();
140
+ },
141
+ });
142
+ if (result.files) record.files = result.files;
38
143
  else {
39
- record.urls=result.urls??[];
40
- const fresh=readdirSync(runDir).filter(f=>!before.has(f)&&/\.(png|jpe?g|webp)$/i.test(f)).sort();
41
- for(const [index,source] of fresh.entries()){const target=`${item.itemId}--${item.variantId}${index?'--'+(index+1):''}${source.slice(source.lastIndexOf('.'))}`;if(source!==target){if(existsSync(join(runDir,target)))throw new Error('产物已存在');renameSync(join(runDir,source),join(runDir,target));}record.files.push(target);}
144
+ record.urls = result.urls ?? [];
145
+ const fresh = readdirSync(runDir)
146
+ .filter((f) => !before.has(f) && /\.(png|jpe?g|webp)$/i.test(f))
147
+ .sort();
148
+ for (const [index, source] of fresh.entries()) {
149
+ const target = `${item.itemId}--${item.variantId}${index ? "--" + (index + 1) : ""}${source.slice(source.lastIndexOf("."))}`;
150
+ if (source !== target) {
151
+ if (existsSync(join(runDir, target))) throw new Error("产物已存在");
152
+ renameSync(join(runDir, source), join(runDir, target));
153
+ }
154
+ record.files.push(target);
155
+ }
156
+ }
157
+ if (
158
+ record.files.length !== (item.execution ?? task.plan.execution).perValue
159
+ )
160
+ throw new Error("生成数量与计划不符");
161
+ const expected = (item.execution ?? task.plan.execution).size
162
+ .split("*")
163
+ .map(Number);
164
+ for (const image of record.files) {
165
+ const path = join(runDir, image),
166
+ info = await validateImage(readFileSync(path));
167
+ if (info.width !== expected[0] || info.height !== expected[1])
168
+ throw new Error("生成图片尺寸与冻结计划不符");
169
+ record.outputHashes[image] = sha256File(path);
170
+ }
171
+ record.ok = true;
172
+ record.status = "generated";
173
+ } catch (error) {
174
+ if (backend?.provider === "comfyui" && task.promptId)
175
+ try {
176
+ await cancelPrompt(task.endpoint, task.promptId);
177
+ task.promptId = null;
178
+ } catch (stopError) {
179
+ error.unsettled = true;
180
+ error.message += ";无法确认后端停止:" + stopError.message;
181
+ }
182
+ if (error.unsettled) task.unsettled = true;
183
+ record.status = cancelled() && !error.unsettled ? "cancelled" : "failed";
184
+ record.error = error.message;
185
+ if (record.status === "failed") {
186
+ task.error = error.message;
187
+ if (error.diagnostic) {
188
+ record.diagnostic = error.diagnostic;
189
+ task.diagnostic = error.diagnostic;
190
+ }
42
191
  }
43
- if(record.files.length!==(item.execution??task.plan.execution).perValue)throw new Error('生成数量与计划不符');
44
- for(const image of record.files)record.outputHashes[image]=sha256File(join(runDir,image));
45
- record.ok=true;record.status='generated';
46
- }catch(error){
47
- if(backend?.provider==='comfyui'&&task.promptId)try{await cancelPrompt(task.endpoint,task.promptId);task.promptId=null;}catch(stopError){error.unsettled=true;error.message+=';无法确认后端停止:'+stopError.message;}
48
- if(error.unsettled)task.unsettled=true;
49
- record.status=cancelled()&&!error.unsettled?'cancelled':'failed';record.error=error.message;
50
- if(record.status==='failed'){task.error=error.message;if(error.diagnostic){record.diagnostic=error.diagnostic;task.diagnostic=error.diagnostic;}}
51
192
  }
52
193
  saveManifest();
194
+ if (task.unsettled) break;
195
+ }
196
+ if (cancelled() || task.unsettled)
197
+ for (const item of task.items)
198
+ if (!manifest.items.some((x) => x.inputHash === item.inputHash))
199
+ manifest.items.push({
200
+ ...structuredClone(item),
201
+ ok: false,
202
+ status: "cancelled",
203
+ files: [],
204
+ urls: [],
205
+ outputHashes: {},
206
+ error: "任务已取消,未执行",
207
+ });
208
+ manifest.finishedAt = new Date().toISOString();
209
+ saveManifest();
210
+ task.status = cancelled()
211
+ ? "cancelled"
212
+ : manifest.summary.failed
213
+ ? "failed"
214
+ : manifest.summary.cancelled
215
+ ? "cancelled"
216
+ : "succeeded";
217
+ } catch (error) {
218
+ task.status = cancelled() ? "cancelled" : "failed";
219
+ task.error = error.message;
220
+ if (error.diagnostic) task.diagnostic = error.diagnostic;
221
+ if (manifest) {
222
+ manifest.error = error.message;
223
+ manifest.diagnostic = error.diagnostic;
224
+ manifest.finishedAt = new Date().toISOString();
225
+ saveManifest();
53
226
  }
54
- if(cancelled())for(const item of task.items)if(!manifest.items.some(x=>x.inputHash===item.inputHash))manifest.items.push({...structuredClone(item),ok:false,status:'cancelled',files:[],urls:[],outputHashes:{},error:'任务已取消,未执行'});
55
- manifest.finishedAt=new Date().toISOString();saveManifest();
56
- task.status=task.unsettled?'failed':cancelled()?'cancelled':manifest.summary.failed?'failed':'succeeded';
57
- }catch(error){task.status=cancelled()?'cancelled':'failed';task.error=error.message;if(error.diagnostic)task.diagnostic=error.diagnostic;if(manifest){manifest.error=error.message;manifest.diagnostic=error.diagnostic;manifest.finishedAt=new Date().toISOString();saveManifest();}}
58
- finally{clearInterval(heartbeat);task.finishedAt=new Date().toISOString();persist();}
227
+ } finally {
228
+ clearInterval(heartbeat);
229
+ task.stopConfirmed =
230
+ !task.unsettled && !task.promptId && !task.remoteCancellation;
231
+ task.finishedAt = new Date().toISOString();
232
+ persist();
233
+ }