@kevlns/art-workshop 0.3.1 → 0.3.2

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/AGENTS.md CHANGED
@@ -23,7 +23,7 @@ style create/read/update/derive/discard 管理草稿。style analyze --dry 只
23
23
  ## 取消、异常和关闭
24
24
 
25
25
  任务状态与停止证据分开。queued/running/cancelling 仍占用资源;unknown 或 stopConfirmed=false 保留资源。failed/cancelled 也不能单凭状态释放资源;dispatching/accepted 远程回执尚未结清时继续占用。工作进程丢失标记 unknown,不推测停止。
26
- task cancel 只取消指定运行,保留服务。远程取消只停止本地客户端,上游停止未知如实报告,不允许清理。shutdown 阻止提交、停止关联任务、核验共享队列和进程身份后关闭本地服务,不清空共享队列;有其他任务或停止未确认时保留服务。不得广泛杀所有 Python。
26
+ task cancel 只取消指定运行,保留服务。生成任务远程取消只停止本地客户端,上游停止未知如实报告,不允许清理。只读分析有 finishedAt、已知终态且工作进程已退出,无生成计划与回执时释放本地占用;云端计算与计费停止未知独立保留,不自动重发。没有完成证据的进程丢失仍保持 unknown。shutdown 阻止提交、停止关联任务、核验共享队列和进程身份后关闭本地服务,不清空共享队列;有其他任务或停止未确认时保留服务。不得广泛杀所有 Python。
27
27
 
28
28
  ## 生成与定版
29
29
 
package/docs/modes.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  创建风格草稿,按 style、palette、rendering 分类导入私有参考。style analyze --dry 只编译;实际 analyze 创建 taskId 和独立证据。报告绑定配置版本、图片哈希、分析模型和规则指纹;更新配置或参考后必须重新分析。冲突与未知项未处理时不能采用。
6
6
 
7
+ 讨论负责澄清分类观察焦点和编辑草稿,不等同于正式分析。正式分析按分类逐图观察,再生成包含 summary、observations、recommendation、conflicts、uncertainties 和 provenance 的结构化报告;只在报告通过职责与格式校验且源草稿未变化时回填。报告是待采用建议,不能声称已冻结风格或已生成图片。错误保留原草稿与证据,本地执行结束后允许编辑;云端计算不确定性单独提示,见 [状态与恢复](troubleshooting.md)。
8
+
7
9
  style adopt 冻结当前已审阅报告;style recover 只恢复原已授权采用事务。正式风格只读,修改使用 derive,不能复制文件改身份。任务动态参考用 job analyze,只转写指定内容用途,不替代静态风格。
8
10
 
9
11
  ## 远程文生图
@@ -8,10 +8,14 @@
8
8
 
9
9
  ## 状态与占用
10
10
 
11
- task status 返回原运行阶段、心跳、工作进程、后端身份、manifestPath、错误和停止证据。queued/running/cancelling 仍占用对象。释放必须是已知终态、stopConfirmed=true,且无 unsettled、promptId、remoteCancellation 或 dispatching/accepted 远程回执;unknown 一律保留占用。
11
+ task status 返回原运行阶段、心跳、工作进程、后端身份、manifestPath、错误和停止证据。queued/running/cancelling 仍占用对象。生成任务释放必须是已知终态、stopConfirmed=true,且无 unsettled、promptId、remoteCancellation 或 dispatching/accepted 远程回执;unknown 一律保留占用。
12
+
13
+ 只读风格分析与任务参考分析区分本地停止和云端计算状态:只有记录了 finishedAt、已知终态且工作进程已退出,且不存在生成计划、promptId 或远程生成回执时,才释放草稿占用并允许退出。上游超时或取消事实仍保留,task status 的 upstreamExecutionUnknown=true 表示云端计算及计费停止不可确认,不代表分析成功;没有完成记录的进程丢失继续保持 unknown。同步视觉接口没有可查询的任务身份,不提示查询不存在的云端任务,不自动重发。
12
14
 
13
15
  分析阶段记录 reference-analysis(当前图片与已完成数量)、synthesis(汇总)、report-repair(一次格式修正)和 report-validation(校验回填),不会用心跳推测完成比例。模型响应文字按调用保存在对象 reports/<taskId>/responses/,不保存凭据或请求图片编码。格式校验失败最多基于已有结果修正一次,不重复读取已完成的图片;仍失败则保留原响应和草稿,明确显示错误。
14
16
 
17
+ 多图风格分析将完整成功的分类观察缓存到配置的缓存目录 references/。缓存身份包含图片内容哈希、分类、说明、排除项、观察提示、规则及模型连接配置,不依赖每次运行变化的证据副本路径。明确重新发起分析时只重读未命中观察;汇总失败不会自动发起下一次分析。旧运行没有这种缓存时,原响应仍保留,不把缺少缓存身份的文字猜作可复用观察。
18
+
15
19
  工作进程丢失且心跳过期标记 unknown,不能推测上游停止。task wait 超时不取消;切面板不取消;本地客户端退出不代表云端取消或费用撤销。
16
20
 
17
21
  ## 查询、恢复和重试
package/lib/analyze.mjs CHANGED
@@ -29,8 +29,16 @@ export async function analyzeStyle({projectId,input,out,root=ROOT,refsDir,defaul
29
29
  else {
30
30
  const observations=[];
31
31
  for(const [index,args] of requests.slice(0,-1).entries()){
32
- onProgress({stage:'reference-analysis',index:index+1,completed:index,total:refs.length,referenceName:refs[index].note});
33
- observations.push(extractText(await runner(args)).join('\n'));
32
+ // Each run snapshots images under a new taskId. Cache by content and
33
+ // observation contract, never by that temporary evidence path.
34
+ const referenceKey=hash({model,provider:provenance.provider,guidanceHash:provenance.guidanceHash,reference:{hash:refs[index].hash,scope:refs[index].scope,note:refs[index].note,ignore:refs[index].ignore},prompt:args.at(-1)}),referenceCache=join(cacheDir,'references');
35
+ const saved=cacheRead(referenceCache,referenceKey);
36
+ const reused=saved?.schema==='art-workshop/reference-observation'&&typeof saved.text==='string'&&saved.text.trim().length>0;
37
+ onProgress({stage:'reference-analysis',index:index+1,completed:index,total:refs.length,referenceName:refs[index].note,reused});
38
+ const observation=reused?saved.text:extractText(await runner(args)).join('\n');
39
+ if(!observation.trim())throw new Error('参考图未返回有效观察,未汇总或回填');
40
+ if(!reused)writeJson(join(referenceCache,referenceKey+'.json'),{schema:'art-workshop/reference-observation',text:observation});
41
+ observations.push(observation);
34
42
  }
35
43
  onProgress({stage:'synthesis',completed:refs.length,total:refs.length});
36
44
  const args=[...requests.at(-1)];args[args.length-1]+='\n参考观察:'+JSON.stringify(observations);response=await runner(args);
package/lib/lifecycle.mjs CHANGED
@@ -10,7 +10,21 @@ export const RUN_STATES = Object.freeze([
10
10
  ]);
11
11
  export const terminal = (status) =>
12
12
  ["succeeded", "failed", "cancelled", "unknown"].includes(status);
13
+ /** Analysis only observes remote input. Its finalized, exited worker cannot mutate
14
+ * the draft again; an unqueryable upstream request may still consume credits.
15
+ * Generation receipts never qualify for this local-only completion proof. */
16
+ export function analysisLocallyStopped(task) {
17
+ if (!['style-analysis', 'task-reference-analysis'].includes(task.kind) ||
18
+ !['succeeded', 'failed', 'cancelled'].includes(task.status) ||
19
+ !Number.isFinite(Date.parse(task.finishedAt)) ||
20
+ !Number.isSafeInteger(task.workerPid) || task.workerPid <= 0 ||
21
+ task.plan || task.promptId || Object.keys(task.remoteExecutions ?? {}).length) return false;
22
+ try { process.kill(task.workerPid, 0); return false; } catch (error) {
23
+ return error.code === 'ESRCH';
24
+ }
25
+ }
13
26
  export function executionSettled(task) {
27
+ if (analysisLocallyStopped(task)) return true;
14
28
  return (
15
29
  terminal(task.status) &&
16
30
  task.status !== "unknown" &&
package/lib/tasks.mjs CHANGED
@@ -19,7 +19,7 @@ import { closeService, healthy } from "./service.mjs";
19
19
  import { cancelPrompt } from "./comfyui.mjs";
20
20
  import { validatePlan } from "./plan.mjs";
21
21
  import {assertExecutableStyle} from './style-contract.mjs';
22
- import { executionSettled, executionLifecycle } from "./lifecycle.mjs";
22
+ import { executionSettled, executionLifecycle, analysisLocallyStopped } from "./lifecycle.mjs";
23
23
  import { bindBackend } from "./backends.mjs";
24
24
  import { assertPlanCurrent } from "./workspace.mjs";
25
25
  import {
@@ -64,6 +64,7 @@ export function taskView(task) {
64
64
  styleId: task.styleId ?? null,
65
65
  lifecycle: executionLifecycle(task),
66
66
  stopConfirmed: executionSettled(task),
67
+ upstreamExecutionUnknown: analysisLocallyStopped(task) && !!task.remoteCancellation,
67
68
  schema,
68
69
  taskId,
69
70
  status,
@@ -103,7 +104,7 @@ export function taskStatus(root, taskId) {
103
104
  "工作进程退出;后端任务可能仍在运行,请 task cancel 或 shutdown 清理";
104
105
  writeJson(file, task);
105
106
  }
106
- return task;
107
+ return analysisLocallyStopped(task) ? { ...task, stopConfirmed: true } : task;
107
108
  }
108
109
  export function failedItems(root, runId, plan) {
109
110
  const original = taskStatus(root, runId);
@@ -263,6 +264,12 @@ export async function cancelTask(root, taskId, { wait = true } = {}) {
263
264
  // parent read-modify-write would race its heartbeat and lose prompt identities.
264
265
  writeJson(file + ".cancel", { requestedAt: new Date().toISOString() });
265
266
  if (terminal(task.status)) {
267
+ if (['style-analysis', 'task-reference-analysis'].includes(task.kind) && task.finishedAt) {
268
+ const deadline = Date.now() + 5000;
269
+ while (alive(task.workerPid) && Date.now() < deadline) await sleep(50);
270
+ const latest = taskStatus(root, taskId);
271
+ if (executionSettled(latest)) return latest;
272
+ }
266
273
  if (alive(task.workerPid))
267
274
  throw new Error("工作进程尚未退出,停止结果待确认");
268
275
  if (!task.endpoint || !task.promptId)
package/lib/vision.mjs CHANGED
@@ -40,7 +40,7 @@ export async function callVision(args,{cancelled=()=>false,onRemoteCancel,transp
40
40
  if(!texts.length||texts.some(t=>typeof t!=='string'))throw new Error('视觉模型未返回文字报告');
41
41
  return {text:texts.join('\n')};
42
42
  }catch(error){
43
- if(sent&&(controller.signal.aborted||error instanceof TypeError)){onRemoteCancel?.();throw new Error('视觉请求未确认停止,请查询原运行;不要重新提交');}
43
+ if(sent&&(controller.signal.aborted||error instanceof TypeError)){onRemoteCancel?.();throw new Error(cancelled()?'分析请求已取消;云端计算与计费是否停止无法确认,不会自动重发':'分析请求超时或连接中断;云端计算与计费是否停止无法确认,未回填报告,不会自动重发');}
44
44
  throw new Error(/^视觉/.test(error.message)?error.message:'视觉模型响应解析失败');
45
45
  }finally{clearInterval(timer);clearTimeout(timeout);}
46
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevlns/art-workshop",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "private": false,
5
5
  "description": "美术工坊:统一风格的多工程图片生成与编辑工具",
6
6
  "type": "module",
@@ -28,7 +28,7 @@ style create/read/update/derive/discard 管理草稿。style analyze --dry 只
28
28
  ## 取消、异常和关闭
29
29
 
30
30
  任务状态与停止证据分开。queued/running/cancelling 仍占用资源;unknown 或 stopConfirmed=false 保留资源。failed/cancelled 也不能单凭状态释放资源;dispatching/accepted 远程回执尚未结清时继续占用。工作进程丢失标记 unknown,不推测停止。
31
- task cancel 只取消指定运行,保留服务。远程取消只停止本地客户端,上游停止未知如实报告,不允许清理。shutdown 阻止提交、停止关联任务、核验共享队列和进程身份后关闭本地服务,不清空共享队列;有其他任务或停止未确认时保留服务。不得广泛杀所有 Python。
31
+ task cancel 只取消指定运行,保留服务。生成任务远程取消只停止本地客户端,上游停止未知如实报告,不允许清理。只读分析有 finishedAt、已知终态且工作进程已退出,无生成计划与回执时释放本地占用;云端计算与计费停止未知独立保留,不自动重发。没有完成证据的进程丢失仍保持 unknown。shutdown 阻止提交、停止关联任务、核验共享队列和进程身份后关闭本地服务,不清空共享队列;有其他任务或停止未确认时保留服务。不得广泛杀所有 Python。
32
32
 
33
33
  ## 生成与定版
34
34