@kevlns/art-workshop 0.3.7 → 0.3.9

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
@@ -63,6 +63,12 @@ candidate delete 先确认影响,拒绝运行中或被计划/底图引用的
63
63
 
64
64
  任务参考可通过 reference import --item-id <对象标识> 绑定单个出图对象;未绑定的参考为任务共用。生成与编辑只采纳共用参考和当前对象参考的观察。reference update 的 itemId 可改绑对象,null 表示任务共用。
65
65
 
66
+ `v-cli capability coverage --json` 核对结构化调用覆盖。参考导入的 `--item-id` 指定当前任务出图对象,省略表示任务共用;工具校验对象身份。
67
+
68
+ ### 本地环境部署
69
+
70
+ 使用 environment guide 获取部署指南与契约,environment inspect 读取机器环境。Pi 通过基础工具和动态工作流完成安装、下载、修正与采样;environment verify 独立校验文件、服务和节点,environment register 验收后登记。任务授权、进程、互斥与恢复交由 Harness。不得把模型回复或服务连通当作真实出图。unregister 仅解除登记,不删除模型或停止外部服务。按 --guide 选择随包方案,模型事实和启动参数只由 art 维护。
71
+
66
72
  ## 结果验证
67
73
 
68
74
  核对原始错误、任务身份、停止状态及实际产物。只报告已经完成的验证,模拟测试与真实执行分别说明。
package/art-workshop.mjs CHANGED
@@ -4,7 +4,7 @@ import {join,resolve} from 'node:path';
4
4
  import {readJson,writeJson} from './lib/shared.mjs';
5
5
  const args=process.argv.slice(2),pos=[],options={};
6
6
  if(args.length===1&&['--version','-V'].includes(args[0])){console.log(readJson(new URL('./package.json',import.meta.url)).version);process.exit(0);}
7
- const help='art-workshop: config path/show/init/validate | doctor [--backend ID] [--start] | workflow list | deployment plan/start/status/cancel/recover | refs guide | agent index/docs/init | list | style create/list/read/update/derive/discard/analyze/resolve/adopt/recover/validate/show | generate show/plan/run | edit show/plan/run | task list/status/wait/cancel/recover/resume | shutdown | check RUN | project init/upgrade | job template/from-candidate/create/list/read/update/derive/discard/analyze | reference import/list/update/remove | candidate list/finalize/delete/finalizations | compare PLAN PLAN\nrun --background 返回任务 ID;--backend 选择后端。shutdown 停止当前工作区关联任务,核验共享队列和进程身份后关闭本地服务。\n也可用 v-cli art 调用;先 v-cli agent docs art,再 v-cli agent describe art --json 查看完整参数。';
7
+ const help='art-workshop: config path/show/init/validate | doctor [--backend ID] [--start] | workflow list | environment guide/list/inspect/verify/register/unregister | refs guide | agent index/docs/init | list | style create/list/read/update/derive/discard/analyze/resolve/adopt/recover/validate/show | generate show/plan/run | edit show/plan/run | task list/status/wait/cancel/recover/resume | shutdown | check RUN | project init/upgrade | job template/from-candidate/create/list/read/update/derive/discard/analyze | reference import/list/update/remove | candidate list/finalize/delete/finalizations | compare PLAN PLAN\nrun --background 返回任务 ID;--backend 选择后端。shutdown 停止当前工作区关联任务,核验共享队列和进程身份后关闭本地服务。\n也可用 v-cli art 调用;先 v-cli agent docs art,再 v-cli agent describe art --json 查看完整参数。';
8
8
  if(!args.length||args.length===1&&['--help','-h','help'].includes(args[0])){console.log(help);process.exit(0);}
9
9
  const {loadJob,loadProject}=await import('./lib/project.mjs');
10
10
  const {referenceRoot,referenceGuide}=await import('./lib/refs.mjs');
@@ -25,9 +25,11 @@ const {candidates,finalize,deleteCandidate,finalizations,editFromCandidate}=awai
25
25
  const {upgradeProject}=await import('./lib/migration.mjs');
26
26
  const {workflowList}=await import('./lib/workflows.mjs');
27
27
  const {jobTemplate}=await import('./lib/templates.mjs');
28
- const {deploymentPlan,startDeployment,deploymentStatus,cancelDeployment,recoverDeployment}=await import('./lib/deployment.mjs');
28
+ const {deploymentGuide}=await import('./lib/deployment-guide.mjs');
29
+ const {inspectInstallation,discoverInstallations}=await import('./lib/environments.mjs');
30
+ const {verifyInstallation,registerInstallation,unregisterInstallation}=await import('./lib/environment-operations.mjs');
29
31
  const flags=new Set(['dry','explore','background','start','replace','confirm','all-variants']);
30
- const allowed=new Set(['config','workspace','output-dir','refs-dir','cache-dir','directory','endpoint','project','input','out','report','note','core','job','plan','item','variant','offset','limit','file','backend','timeout','kind','id','revision','source','category','purposes','mapping','run','candidate','actor','operation','retry-run',...flags]);
32
+ const allowed=new Set(['config','workspace','output-dir','refs-dir','cache-dir','directory','endpoint','guide','project','input','out','report','note','core','job','plan','item','variant','offset','limit','file','backend','timeout','kind','id','revision','source','category','purposes','mapping','run','candidate','actor','operation','retry-run','item-id',...flags]);
31
33
  for(let i=0;i<args.length;i++){if(args[i].startsWith('--')){const k=args[i].slice(2);if(!allowed.has(k)||k in options) throw new Error('未知或重复参数 '+k);options[k]=flags.has(k)?true:args[++i];if(options[k]===undefined) throw new Error('参数缺少值 '+k);}else pos.push(args[i]);}
32
34
  const print=x=>console.log(JSON.stringify(x?.schema==='art-workshop/style'?styleView(settings.paths.workspace,x):x,null,2));
33
35
  if(pos[0]==='workflow'&&pos[1]==='list'){print(workflowList());process.exit(0);}
@@ -48,13 +50,14 @@ try {
48
50
 
49
51
  const effectiveRefs=referenceRoot({defaultRefsDir:settings.paths.refs});
50
52
  if(settings.autoSyncSkills&&!options.dry&&['style','generate','edit'].includes(module)&&['analyze','adopt','run'].includes(action)){try{autoSync();}catch(error){console.error('skill 自动同步失败:'+error.message+';可用 agent init 重试。');}}
51
- if(module==='deployment'){
52
- if(action==='plan'){const plan=deploymentPlan(settings,{directory:required('directory'),endpoint:options.endpoint});if(options.out)writeJson(path(options.out),plan);print(plan);}
53
- else if(action==='start')print(await startDeployment(settings,readJson(path(required('plan'))),{operationId:required('operation')}));
54
- else if(action==='status')print(deploymentStatus(settings,required('id')));
55
- else if(action==='cancel')print(cancelDeployment(settings,required('id')));
56
- else if(action==='recover')print(await recoverDeployment(settings,required('operation')));
57
- else throw new Error('未知 deployment 操作');
53
+ if(module==='environment'){
54
+ if(action==='guide')print(deploymentGuide(options.guide));
55
+ else if(action==='list')print({environments:discoverInstallations()});
56
+ else if(action==='inspect')print(await inspectInstallation(required('directory'),required('endpoint'),options.guide));
57
+ else if(action==='verify'){const result=await verifyInstallation(required('directory'),required('endpoint'),{guideId:options.guide});print(result);if(!result.ok)process.exitCode=1;}
58
+ else if(action==='register')print(await registerInstallation(required('directory'),required('endpoint'),{guideId:options.guide}));
59
+ else if(action==='unregister')print(await unregisterInstallation(required('directory')));
60
+ else throw new Error('未知 environment 操作');
58
61
  }
59
62
  else if(module==='config'){
60
63
  if(action==='path') console.log(settings.file);
package/docs/commands.md CHANGED
@@ -830,111 +830,125 @@ v-cli art reference update --project P --kind style --id ID --revision N --item
830
830
 
831
831
  - 冻结风格只读;任务不允许静态分类;不修改用户原图;旧证据保留
832
832
 
833
- ### deployment plan
833
+ ### job template
834
834
 
835
- 固定 Qwen 2.1 部署 plan
835
+ 只读返回工具权威的任务配置模板;生成任务使用已冻结核心的题材
836
836
 
837
837
  ```sh
838
- v-cli art deployment plan
838
+ v-cli art job template --project <id> --kind <generate|edit> [--core <id>]
839
839
  ```
840
840
 
841
- - `--directory <dir>`:本机部署根目录
842
- - `--endpoint <url>`:本机 ComfyUI 地址
843
- - `--out <file>`:保存不可变预案
841
+ - `--project <id>`:工程身份
842
+ - `--kind <generate|edit>`:任务类型
843
+ - `--core <id>`:生成任务的冻结核心身份
844
844
 
845
- - 只读检测与预案;不下载、不启动、不采样
845
+ - 只读返回模板;不创建任务或文件
846
846
 
847
- ### deployment start
847
+ ### job from-candidate
848
848
 
849
- 固定 Qwen 2.1 部署 start
849
+ 将完整候选导入私有底图,创建独立编辑草稿,不运行
850
850
 
851
851
  ```sh
852
- v-cli art deployment start
852
+ v-cli art job from-candidate --project <id> --id <task> --run <id> --candidate <id>
853
853
  ```
854
854
 
855
- - `--plan <file>`:实际冻结部署预案
856
- - `--operation <id>`:稳定操作身份
855
+ - `--project <id>`:工程身份
856
+ - `--id <task>`:源任务身份
857
+ - `--run <id>`:真实批次
858
+ - `--candidate <id>`:完整候选身份
857
859
 
858
- - 下载、源码安装、独立环境、模型哈希验证、生成及编辑采样;不覆写既有不匹配文件
860
+ - 写入新的编辑草稿和私有底图;保留候选来源;不启动生成
859
861
 
860
- ### deployment status
862
+ ### task resume
861
863
 
862
- 固定 Qwen 2.1 部署 status
864
+ 仅恢复原上游任务的查询和下载,绝不重新提交
863
865
 
864
866
  ```sh
865
- v-cli art deployment status
867
+ v-cli art task resume TASK
866
868
  ```
867
869
 
868
- - `--id <id>`:原部署身份
870
+ - 位置参数 `TASK`:art 任务 ID(必填)
869
871
 
870
- - 只查询原部署,不重复启动
872
+ - 写入原任务状态
873
+ - 查询原上游任务并下载已有产物
874
+ - 提交结果未知时拒绝恢复
871
875
 
872
- ### deployment cancel
876
+ ### environment guide
873
877
 
874
- 固定 Qwen 2.1 部署 cancel
878
+ 本地环境部署指南
875
879
 
876
880
  ```sh
877
- v-cli art deployment cancel
881
+ v-cli art environment guide
878
882
  ```
879
883
 
880
- - `--id <id>`:原部署身份
884
+ - `--guide <id>`:部署指南标识;省略使用环境登记或推荐方案
881
885
 
882
- - 请求取消;仅停止已核验子进程与本部署采样,确认后释放安装占用
886
+ - 不执行安装、下载或采样;register 重新验收后登记,unregister 不删除安装文件或停止服务
883
887
 
884
- ### deployment recover
888
+ ### environment list
885
889
 
886
- 查询唯一原部署回执,不重新执行
890
+ 本地环境目录发现
887
891
 
888
892
  ```sh
889
- v-cli art deployment recover
893
+ v-cli art environment list
890
894
  ```
891
895
 
892
- - `--operation <id>`:启动前登记的稳定身份
893
896
 
894
- - 只读;无法唯一核验时停止未知
897
+ - 不执行安装、下载或采样;register 重新验收后登记,unregister 不删除安装文件或停止服务
895
898
 
896
- ### job template
899
+ ### environment inspect
897
900
 
898
- 只读返回工具权威的任务配置模板;生成任务使用已冻结核心的题材
901
+ 本地环境只读检测
899
902
 
900
903
  ```sh
901
- v-cli art job template --project <id> --kind <generate|edit> [--core <id>]
904
+ v-cli art environment inspect
902
905
  ```
903
906
 
904
- - `--project <id>`:工程身份
905
- - `--kind <generate|edit>`:任务类型
906
- - `--core <id>`:生成任务的冻结核心身份
907
+ - `--directory <value>`:本机环境根目录
908
+ - `--endpoint <value>`:本机 HTTP 服务根地址
909
+ - `--guide <id>`:部署指南标识;省略使用环境登记或推荐方案
907
910
 
908
- - 只读返回模板;不创建任务或文件
911
+ - 不执行安装、下载或采样;register 重新验收后登记,unregister 不删除安装文件或停止服务
909
912
 
910
- ### job from-candidate
913
+ ### environment verify
911
914
 
912
- 将完整候选导入私有底图,创建独立编辑草稿,不运行
915
+ 本地环境确定性验收
913
916
 
914
917
  ```sh
915
- v-cli art job from-candidate --project <id> --id <task> --run <id> --candidate <id>
918
+ v-cli art environment verify
916
919
  ```
917
920
 
918
- - `--project <id>`:工程身份
919
- - `--id <task>`:源任务身份
920
- - `--run <id>`:真实批次
921
- - `--candidate <id>`:完整候选身份
921
+ - `--directory <value>`:本机环境根目录
922
+ - `--endpoint <value>`:本机 HTTP 服务根地址
923
+ - `--guide <id>`:部署指南标识;省略使用环境登记或推荐方案
922
924
 
923
- - 写入新的编辑草稿和私有底图;保留候选来源;不启动生成
925
+ - 不执行安装、下载或采样;register 重新验收后登记,unregister 不删除安装文件或停止服务
924
926
 
925
- ### task resume
927
+ ### environment register
926
928
 
927
- 仅恢复原上游任务的查询和下载,绝不重新提交
929
+ 本地环境验收并登记
928
930
 
929
931
  ```sh
930
- v-cli art task resume TASK
932
+ v-cli art environment register
931
933
  ```
932
934
 
933
- - 位置参数 `TASK`:art 任务 ID(必填)
935
+ - `--directory <value>`:本机环境根目录
936
+ - `--endpoint <value>`:本机 HTTP 服务根地址
937
+ - `--guide <id>`:部署指南标识;省略使用环境登记或推荐方案
934
938
 
935
- - 写入原任务状态
936
- - 查询原上游任务并下载已有产物
937
- - 提交结果未知时拒绝恢复
939
+ - 不执行安装、下载或采样;register 重新验收后登记,unregister 不删除安装文件或停止服务
940
+
941
+ ### environment unregister
942
+
943
+ 本地环境解除登记
944
+
945
+ ```sh
946
+ v-cli art environment unregister
947
+ ```
948
+
949
+ - `--directory <value>`:本机环境根目录
950
+
951
+ - 不执行安装、下载或采样;register 重新验收后登记,unregister 不删除安装文件或停止服务
938
952
 
939
953
  ## 结果验证
940
954
 
@@ -1,60 +1,32 @@
1
- # Vant 本地环境检测与部署
1
+ # Vant 本地模型部署
2
2
 
3
3
  ## 定位
4
4
 
5
- 本地环境检测与部署,适用于当前随包实现。
5
+ 部署指南由 art 维护;Pi 根据机器环境规划并执行安装,Harness 管理授权、进程、停止与恢复。工具负责环境检测、模型校验和登记。
6
6
 
7
7
  ## 前置条件
8
8
 
9
- 先按包的环境要求准备工程与工具,使用实际配置和命令帮助核对目标。
9
+ 配置可用聊天模型,选择项目和本机安装目录、回环服务地址。任务授权覆盖目录内安装、下载及验证采样;已有文件冲突时保留原文件。推荐方案、依赖版本和模型校验值由 environment guide 返回。
10
10
 
11
11
  ## 操作流程
12
12
 
13
- 固定自动安装方案由 lib/deployment.mjs 的 LOCAL_RECIPE 维护:ComfyUI、GGUF 节点、Python/Torch 依赖以及三个模型的准确版本和 SHA256。自动部署当前只适配 Windows NVIDIA 环境;已有便携 Python 可复用,新建 venv 需要可用的 Python >=3.12。
13
+ 1. `v-cli art environment guide` 读取指南与模型契约。
14
+ 2. `v-cli art environment list` 发现已有环境;`environment inspect --directory DIR --endpoint URL` 检测指定环境。
15
+ 3. Pi 使用基础工具与动态工作流完成运行时、节点、依赖、模型和服务配置。网络或命令失败根据实际错误修正,保留成功节点。
16
+ 4. `environment verify --directory DIR --endpoint URL` 校验文件 SHA256、服务身份和工作流能力;本命令不下载、启动服务或采样。
17
+ 5. 通过标准计划与任务命令验证生成、编辑;保留原 taskId,不重发未知请求。
18
+ 6. `environment register --directory DIR --endpoint URL` 重新验收后登记。Vant 部署会话通过 art_operation 调用 environment-register,回填系统目录与地址。
14
19
 
15
- ### 目录与端口
20
+ 服务需长期运行时使用配置 launch 的 `doctor --start`,由 art 保存归属并在 Vant 退出时清理;普通下载与安装命令使用 Harness 受管进程。
16
21
 
17
- Vant 检测窗口默认安装目录为 `<VANT_HOME 或 ~/.vant>/art-env`,允许选择其他目录及本机可用端口。已有便携安装应选择包含 ComfyUI 和 python_embeded 的根目录,而不是 models、ComfyUI 子目录或旧 .vant-art。
18
-
19
- 空目录输入时,组织层可用 discoverInstallations 读取环境索引,并在默认目录、用户 AI 目录及 Windows C:/AI、D:/AI、E:/AI 有界扫描环境标记和 ComfyUI。扫描有深度和数量预算,不是全盘检索。独立 CLI deployment plan 必须明确 --directory,不会自行执行界面的自动选择逻辑。
20
-
21
- 端口自动选择只证明检测时可绑定,不预约端口。目录或端口变更后重新检测,确认的地址随环境保存;实际启动仍可能因端口被其他程序占用而失败。不能把其他进程监听同一端口视为此目录的环境。
22
-
23
- ### 已有环境复用
24
-
25
- 1. 检查 Python、ComfyUI、GGUF 节点、固定模型文件及大小,检查生成与编辑工作流的实际节点能力和端口归属。
26
- 2. 对可复用但未登记环境,adoptInstallation 流式验证模型 SHA256,连接或启动对应服务,核验能力后写入标记及用户环境索引。保留原模型;不因未登记而再次下载整套环境。
27
- 3. 接入检测的 verification=capabilities 只代表环境和工作流能力验证。新部署产生的真实生成、编辑验证图是另一等级证据,不能混称。
28
- 4. 缺文件或版本不符时展示具体差异。固定部署不自动覆写不匹配源码、模型或用户安装;先明确处理差异,再生成新预案。
29
-
30
- ### 独立 CLI 流程
31
-
32
- 以下示例使用已核对的安装目录与端口;启动前必须有部署、下载及验证采样的任务授权。
33
-
34
- ```sh
35
- v-cli art deployment plan --directory C:/AI/ComfyUI_windows_portable --endpoint http://127.0.0.1:8188/ --out deployment.json
36
- v-cli art deployment start --plan deployment.json --operation local-deploy-001
37
- v-cli art deployment status --id DEPLOYMENT
38
- v-cli art deployment cancel --id DEPLOYMENT
39
- v-cli art deployment recover --operation local-deploy-001
40
- ```
41
-
42
- plan 检测 Git、GPU、Python、文件与磁盘;需要下载模型时同时检测 curl.exe。不下载、不启动服务、不采样;现有文件存在不等于哈希已验证。Git 需能在 Vant 的 PATH 中直接执行,安装 Git for Windows 或修改 PATH 后须完全退出并重新启动 Vant。start 和工作进程执行前再次复核依赖与冻结预案;源码克隆前创建临时工作目录,完成固定提交检出后才提交源码。缺少命令与工作目录不可用分别报告,不再统一显示 ENOENT。
43
-
44
- start 创建后台 deploymentId,逐阶段记录实际进度,按固定方案安装、校验、生成与编辑采样;完成后才提交配置。下载或校验失败不覆写既有冲突文件。
45
-
46
- status 查询原部署。cancel 只停止已核验的本部署进程与采样,不删除用户素材或原模型,不关闭用户先前启动的服务。recover 只找回唯一原登记,不重复安装。工作进程丢失或停止未确认时保留 unknown 与安装占用。
47
-
48
- ### 存储与关闭
49
-
50
- 安装根保存程序、模型和 vant.art.config.json;环境索引、受管服务身份、日志和验证证据归 ~/.vant/state。项目生图归工程绑定的 .vant/art,不能写入共享模型环境。
51
-
52
- Vant 退出使用其应用生命周期清理关联后台任务,并关闭可核验为 Vant 启动的 ComfyUI,确认本机端口释放。单独关闭部署窗口不取消部署。CLI shutdown 的工作区与共享服务边界见 [任务控制](troubleshooting.md)。
22
+ `environment unregister --directory DIR` 仅解除登记,不删除安装文件和模型,也不停止外部服务。
53
23
 
54
24
  ## 结果验证
55
25
 
56
- 结合原始错误、结构化结果和实际产物核验;测试与真实平台执行分别记录。
26
+ 文件、服务、节点能力与真实采样分别记录。登记的 verification=capabilities 和 sampleVerified=false 表示未以此次登记证明真实出图。模型回复不能替代工具验收。
27
+
28
+ 取消由工作流停止入口处理;普通插话和关闭设置页不终止部署。恢复先核对任务记录、原进程及实际文件,保留有效下载,不重新执行成功节点。未知副作用继续占用,不能当作已停止。
57
29
 
58
30
  ## 参考资料
59
31
 
60
- [使用说明](../README.md)
32
+ [部署指南](local-models/qwen-image-2.1.md) · [使用说明](../README.md)
@@ -0,0 +1,55 @@
1
+ {
2
+ "id": "qwen-image-2.1-Q4-cpu-text-v1",
3
+ "comfy": {
4
+ "repository": "https://github.com/Comfy-Org/ComfyUI",
5
+ "commit": "b0b743566f65daafc423b4fea8a2fbda94b3384a"
6
+ },
7
+ "plugin": {
8
+ "repository": "https://github.com/leejet/ComfyUI-GGUF",
9
+ "commit": "373048b8403a7820620065210a691263d4da0a61"
10
+ },
11
+ "models": [
12
+ {
13
+ "path": "diffusion_models/qwen-image-2.1-UC-Q4_K_M.gguf",
14
+ "bytes": 4604558112,
15
+ "url": "https://huggingface.co/abenzerps/Qwen-Image-2.1-Uncensored-GGUF/resolve/main/qwen-image-2.1-UC-Q4_K_M.gguf",
16
+ "sha256": "e79c8a009f2ecbdb6c70fd663d9aea9ee304a0d91f347e4169a756b8ad141b41"
17
+ },
18
+ {
19
+ "path": "text_encoders/qwen3vl_8b_int8_convrot.safetensors",
20
+ "bytes": 9350798360,
21
+ "url": "https://huggingface.co/Comfy-Org/Qwen-Image-2.1/resolve/main/text_encoders/qwen3vl_8b_int8_convrot.safetensors",
22
+ "sha256": "8bfd0f6e12abf2d2d697ecc888e5e90b0d6741d6708f05799f53afa560452e8f"
23
+ },
24
+ {
25
+ "path": "vae/qwen_image_2.1_vae_bf16.safetensors",
26
+ "bytes": 675509688,
27
+ "url": "https://huggingface.co/Comfy-Org/Qwen-Image-2.1/resolve/main/vae/qwen_image_2.1_vae_bf16.safetensors",
28
+ "sha256": "bb21f7473051e1ac368515dd3f2e15cd44d7a11748ee8823e1ddca3e4876b7c9"
29
+ }
30
+ ],
31
+ "torch": "2.14.0",
32
+ "torchvision": "0.29.0",
33
+ "torchIndex": "https://download.pytorch.org/whl/cu130",
34
+ "gguf": "0.19.0",
35
+ "backend": {
36
+ "provider": "comfyui",
37
+ "model": "qwen-image-2.1-UC-Q4_K_M.gguf",
38
+ "workflow": "vant-builtin-qwen-image-2.1-Q4-8GB"
39
+ },
40
+ "pythonCandidates": [
41
+ "python_embeded/python.exe",
42
+ ".venv/Scripts/python.exe"
43
+ ],
44
+ "launchArgs": [
45
+ "-s",
46
+ "ComfyUI/main.py",
47
+ "--disable-dynamic-vram",
48
+ "--lowvram",
49
+ "--disable-auto-launch"
50
+ ],
51
+ "requiredPaths": [
52
+ "ComfyUI/main.py",
53
+ "ComfyUI/custom_nodes/ComfyUI-GGUF"
54
+ ]
55
+ }
@@ -0,0 +1,31 @@
1
+ # Vant 本地图片模型部署指南
2
+
3
+ ## 目标
4
+
5
+ 在用户指定目录部署或复用 ComfyUI 环境,接入 Qwen Image 2.1 Q4 图片生成及编辑。模型文件、固定版本与校验值读取同目录 JSON 契约,不猜测版本。根据实际系统、显卡、磁盘和网络制定命令;执行前明确任务范围。
6
+
7
+ ## 检测
8
+
9
+ 先读取 art environment guide,检测系统、GPU/显存、驱动、内存、磁盘、Git、Python、下载工具、端口以及已有环境。优先复用用户指定目录或 art 环境索引;不全盘扫描。没有 Git 可选择发行包下载,不重复执行失败命令。用户已有源码、虚拟环境和模型不直接覆盖。
10
+
11
+ ## 执行
12
+
13
+ 使用 Pi 基础工具与 Harness 受管进程执行。创建动态工作流,节点为检查环境、准备运行时、安装依赖、下载模型、配置服务、验证能力、登记环境。命令、错误和产物保存到任务记录。按实际反馈修正当前节点,成功节点不重复执行。
14
+
15
+ 在目标目录创建独立 Python 环境,或复用经过检测的便携 Python。源码检出契约指定提交,依赖安装在该 Python 环境。按模型契约将文件下载到 ComfyUI/models 下,先写临时文件,校验 SHA256 后改为最终文件;保留有效文件并支持续传。网络失败时检查已有代理,仅在当前命令使用,不修改系统代理。不自行安装或更新全局 npm 工具。
16
+
17
+ 低显存方案将文本编码器放在 CPU,服务使用 --disable-dynamic-vram --lowvram --disable-auto-launch。不要承诺显存一定充足。服务仅监听回环地址。端口占用时核对服务身份,不能将另一套环境误登记为当前目录。
18
+
19
+ ## 验收
20
+
21
+ 分别记录文件校验、服务连通、节点/工作流能力和真实采样。使用 art environment verify 对当前目录和端口验收;验收失败按原始错误修正。真实生成和编辑通过 art 的计划及任务机制执行,保存原 taskId,不重复提交未知请求。只有实际图像及完成回执能够证明采样成功。
22
+
23
+ 使用 art environment register 重新核验并登记已通过能力检查的环境。能力验收不等于采样验证;缺少真实采样时明确展示。登记完成再更新 Vant 的本地环境设置。
24
+
25
+ ## 取消与恢复
26
+
27
+ 用户普通插话不终止工作流。工作流停止时等待本任务进程实际退出,保留已校验模型、已有用户文件与执行证据。只停止能够核验身份的本任务服务,不能杀全部 Python 或关闭用户原有服务。恢复时先读任务记录、检查原进程与文件;未知副作用先核实,不重跑整个安装。关闭部署窗口不取消任务。
28
+
29
+ ## 版权
30
+
31
+ Copyright © 2026 Vant。
package/lib/agent.mjs CHANGED
@@ -39,7 +39,7 @@ export function autoSync({root=ROOT,cwd=process.cwd(),home=homedir(),env=process
39
39
  return syncSkill({root,skillDirs:dirs});
40
40
  }
41
41
  export function agentIndex(root=ROOT,workspace=loadSettings().paths.workspace) {
42
- return {tool:'art-workshop',displayName:'美术工坊',root,workspace,config:loadSettings().file,entry:join(root,'art-workshop.mjs'),skill:{name:'art-workshop',source:join(root,'skills','art-workshop','SKILL.md'),automaticDiscovery:true},modules:[{name:'style',actions:['create','list','read','update','derive','discard','analyze','resolve','adopt','recover','validate','show']},{name:'generate',actions:['show','plan','run']},{name:'edit',actions:['show','plan','run']},{name:'refs',actions:['guide']},{name:'agent',actions:['index','docs','init']}],utilities:['project','job','reference','candidate','list','check','compare','task','shutdown','doctor','workflow','config'],projects:(directory(join(workspace,'projects'))?readdirSync(join(workspace,'projects')):[]).filter(id=>directory(join(workspace,'projects',id))).map(id=>{const p=loadProject(id,workspace);return {id:p.id,cores:p.cores,defaultCore:p.defaultCore,jobs:readdirSync(join(workspace,'projects',id,'tasks')).filter(x=>existsSync(join(workspace,'projects',id,'tasks',x,'task.json')))};})};
42
+ return {tool:'art-workshop',displayName:'美术工坊',root,workspace,config:loadSettings().file,entry:join(root,'art-workshop.mjs'),skill:{name:'art-workshop',source:join(root,'skills','art-workshop','SKILL.md'),automaticDiscovery:true},modules:[{name:'style',actions:['create','list','read','update','derive','discard','analyze','resolve','adopt','recover','validate','show']},{name:'generate',actions:['show','plan','run']},{name:'edit',actions:['show','plan','run']},{name:'refs',actions:['guide']},{name:'agent',actions:['index','docs','init']}],utilities:['environment','project','job','reference','candidate','list','check','compare','task','shutdown','doctor','workflow','config'],projects:(directory(join(workspace,'projects'))?readdirSync(join(workspace,'projects')):[]).filter(id=>directory(join(workspace,'projects',id))).map(id=>{const p=loadProject(id,workspace);return {id:p.id,cores:p.cores,defaultCore:p.defaultCore,jobs:readdirSync(join(workspace,'projects',id,'tasks')).filter(x=>existsSync(join(workspace,'projects',id,'tasks',x,'task.json')))};})};
43
43
  }
44
44
  export const GUIDE_FILES=['README.md','docs/modes.md','docs/configuration.md','docs/data-formats.md','docs/commands.md','docs/deployment.md','docs/troubleshooting.md','docs/remote-models.md','docs/model-architecture.md','docs/core-guidance.md'];
45
45
  export function agentDocs(root=ROOT) {return GUIDE_FILES.map(file=>readFileSync(join(root,file),'utf8')).join('\n\n');}
@@ -0,0 +1,12 @@
1
+ import {readFileSync,readdirSync} from 'node:fs';
2
+ import {fileURLToPath} from 'node:url';
3
+ const root=new URL('../docs/local-models/',import.meta.url);
4
+ export function deploymentGuide(id){
5
+ const entries=readdirSync(root).filter(name=>name.endsWith('.json')).map(name=>({name,contract:JSON.parse(readFileSync(new URL(name,root),'utf8'))}));
6
+ const selected=id?entries.find(entry=>entry.contract.id===id):entries.find(entry=>entry.name==='qwen-image-2.1.json');
7
+ if(!selected)throw new Error('未知部署指南 '+id);
8
+ if(selected.contract.backend.workflow && !selected.contract.backend.workflow.startsWith('vant-builtin-'))selected.contract.backend.workflow=fileURLToPath(new URL(selected.contract.backend.workflow,root));
9
+ return {schema:'art-workshop/deployment-guide',id:selected.contract.id,contract:selected.contract,
10
+ available:entries.map(entry=>({id:entry.contract.id,model:entry.contract.backend.model})),
11
+ instructions:readFileSync(new URL(selected.name.replace(/\.json$/,'.md'),root),'utf8'),directory:fileURLToPath(root)};
12
+ }
@@ -0,0 +1,49 @@
1
+ import {createHash} from 'node:crypto';
2
+ import {createReadStream,realpathSync,existsSync,readFileSync,rmSync} from 'node:fs';
3
+ import {join} from 'node:path';
4
+ import {deploymentGuide} from './deployment-guide.mjs';
5
+ import {inspectInstallation,writeMarker,environmentRoot,MARKER} from './environments.mjs';
6
+ import {locked} from './runtime.mjs';
7
+
8
+ export async function verifyInstallation(directory,endpoint,{cancelled=()=>false,guideId}={}){
9
+ const report=await inspectInstallation(directory,endpoint,guideId);
10
+ const issues=[...report.missing,...(report.conflict?[report.conflict]:[])];
11
+ if(report.markerError)issues.push(report.markerError);
12
+ if(!report.live)issues.push('服务与工作流能力尚未通过');
13
+ for(const model of deploymentGuide(report.guideId).contract.models){
14
+ const file=join(report.root,'ComfyUI/models',model.path);
15
+ if(!existsSync(file))continue;
16
+ const digest=createHash('sha256');
17
+ for await(const chunk of createReadStream(file)){
18
+ if(cancelled())throw new Error('环境验收已取消');
19
+ digest.update(chunk);
20
+ }
21
+ if(digest.digest('hex')!==model.sha256)issues.push('SHA256 不匹配:'+model.path);
22
+ }
23
+ return {...report,ok:issues.length===0,issues,verification:'capabilities',sampleVerified:false,checkedAt:new Date().toISOString()};
24
+ }
25
+
26
+ export async function registerInstallation(directory,endpoint,{guideId}={}){
27
+ const root=realpathSync(directory);
28
+ return locked(environmentRoot(root),'registration',async()=>{
29
+ const report=await verifyInstallation(root,endpoint,{guideId});
30
+ if(!report.ok)throw new Error('环境验收未通过:'+report.issues.join(';'));
31
+ const record=writeMarker(root,{python:report.python,endpoint,recipe:report.guideId,verification:'capabilities'});
32
+ return {ok:true,root,...record,sampleVerified:false};
33
+ });
34
+ }
35
+
36
+ export async function unregisterInstallation(directory){
37
+ const root=realpathSync(directory);
38
+ return locked(environmentRoot(root),'registration',async()=>{
39
+ const file=join(environmentRoot(root),'environment.json');
40
+ if(!existsSync(file))throw new Error('环境未登记');
41
+ const record=JSON.parse(readFileSync(file,'utf8'));
42
+ if(record.root!==root)throw new Error('环境登记身份不匹配');
43
+ // Only registry records are removed; installation and service remain untouched.
44
+ rmSync(file);
45
+ const marker=join(root,MARKER);
46
+ if(existsSync(marker)&&JSON.parse(readFileSync(marker,'utf8')).environmentId===record.environmentId)rmSync(marker);
47
+ return {ok:true,root};
48
+ });
49
+ }
@@ -1,12 +1,11 @@
1
- import {createHash} from 'node:crypto';
2
- import {existsSync,readFileSync,readdirSync,realpathSync,statSync,createReadStream} from 'node:fs';
1
+ import {existsSync,readFileSync,readdirSync,realpathSync,statSync} from 'node:fs';
3
2
  import {homedir} from 'node:os';
4
- import {join,resolve,dirname} from 'node:path';
3
+ import {join,resolve} from 'node:path';
5
4
  import {hash,writeJson} from './shared.mjs';
6
- import {loadBackend,BUILTIN_WORKFLOW} from './workflows.mjs';
5
+ import {loadBackend} from './workflows.mjs';
7
6
  import {inspectEnvironment} from './diagnostics.mjs';
8
- import {LOCAL_RECIPE} from './deployment.mjs';
9
- import {ensureService,externalIdentity} from './service.mjs';
7
+ import {deploymentGuide} from './deployment-guide.mjs';
8
+ import {externalIdentity} from './service.mjs';
10
9
  export const MARKER='vant.art.config.json';
11
10
  export const globalHome=()=>resolve(process.env.VANT_HOME??join(homedir(),'.vant'));
12
11
  export const defaultInstallRoot=()=>join(globalHome(),'art-env');
@@ -16,31 +15,32 @@ export function readMarker(root){
16
15
  const value=JSON.parse(readFileSync(file,'utf8'));
17
16
  let endpoint;try{endpoint=new URL(value.endpoint);}catch{throw new Error('环境标记缺少合法服务地址');}
18
17
  if(endpoint.protocol!=='http:'||!['127.0.0.1','localhost'].includes(endpoint.hostname)||endpoint.pathname!=='/'||endpoint.search||endpoint.hash||endpoint.username||endpoint.password)throw new Error('环境标记只允许本机 HTTP 根地址');
19
- if(value.schema!=='vant/art-environment-v1'||value.comfy!=='ComfyUI'||!['python_embeded/python.exe','.venv/Scripts/python.exe'].includes(value.python))throw new Error('美术环境标记无效:'+file);
18
+ if(value.schema!=='vant/art-environment-v1'||value.comfy!=='ComfyUI'||!deploymentGuide(value.recipe).contract.pythonCandidates.includes(value.python))throw new Error('美术环境标记无效:'+file);
20
19
  return value;
21
20
  }
22
- export function writeMarker(root,{python,endpoint,recipe,verification='capabilities'}){
23
- const value={schema:'vant/art-environment-v1',environmentId:hash(realpathSync(root).toLowerCase()),comfy:'ComfyUI',python,endpoint,workflow:BUILTIN_WORKFLOW,recipe,verification,verifiedAt:new Date().toISOString()};
21
+ export function writeMarker(root,{python,endpoint,recipe=deploymentGuide().id,verification='capabilities'}){
22
+ const value={schema:'vant/art-environment-v1',environmentId:hash(realpathSync(root).toLowerCase()),comfy:'ComfyUI',python,endpoint,workflow:deploymentGuide(recipe).contract.backend.workflow,recipe,verification,verifiedAt:new Date().toISOString()};
24
23
  writeJson(join(root,MARKER),value);
25
24
  writeJson(join(environmentRoot(root),'environment.json'),{root:realpathSync(root),...value});return value;
26
25
  }
27
- export function backendFor(root,endpoint){
28
- const python=existsSync(join(root,'python_embeded/python.exe'))?'python_embeded/python.exe':'.venv/Scripts/python.exe';
29
- return {python,backend:loadBackend({file:join(root,'vant.art.config.json'),generation:{backends:{local:{provider:'comfyui',model:'qwen-image-2.1-UC-Q4_K_M.gguf',endpoints:[endpoint],launch:{executable:join(root,python),cwd:root,args:['-s','ComfyUI/main.py','--disable-dynamic-vram','--lowvram','--disable-auto-launch','--port',new URL(endpoint).port||'80']}}}}},'local')};
26
+ export function backendFor(root,endpoint,guideId){
27
+ const profile=deploymentGuide(guideId??readMarker(root)?.recipe).contract;
28
+ const python=profile.pythonCandidates.find(candidate=>existsSync(join(root,candidate)))??profile.pythonCandidates[0];
29
+ return {python,backend:loadBackend({file:join(root,MARKER),generation:{backends:{local:{...profile.backend,endpoints:[endpoint],launch:{executable:join(root,python),cwd:root,args:[...profile.launchArgs,'--port',new URL(endpoint).port||'80']}}}}},'local')};
30
30
  }
31
- export async function inspectInstallation(root,endpoint){
31
+ export async function inspectInstallation(root,endpoint,guideId){
32
32
  root=resolve(root);let marker=null,markerError;try{marker=readMarker(root);}catch(e){markerError=e.message;}
33
- const {python,backend}=backendFor(root,endpoint),missing=[];
33
+ const PROFILE=deploymentGuide(guideId??marker?.recipe).contract;
34
+ const {python,backend}=backendFor(root,endpoint,PROFILE.id),missing=[];
34
35
  if(!existsSync(join(root,python)))missing.push('Python 环境');
35
- if(!existsSync(join(root,'ComfyUI/main.py')))missing.push('ComfyUI');
36
- if(!existsSync(join(root,'ComfyUI/custom_nodes/ComfyUI-GGUF')))missing.push('ComfyUI-GGUF 节点');
37
- for(const model of LOCAL_RECIPE.models){const file=join(root,'ComfyUI/models',model.path);if(!existsSync(file)||statSync(file).size!==model.bytes)missing.push(model.path+'(缺失或大小不符)');}
38
- let service;try{service=await inspectEnvironment(endpoint,backend);if(service.ok){const edited=loadBackend({file:join(root,MARKER),generation:{backends:{local:{provider:'comfyui',model:backend.model,endpoints:[endpoint]}}}},'local','edit');const editReport=await inspectEnvironment(endpoint,edited);if(!editReport.ok)service=editReport;}}catch{}
36
+ for(const path of PROFILE.requiredPaths)if(!existsSync(join(root,path)))missing.push(path);
37
+ for(const model of PROFILE.models){const file=join(root,'ComfyUI/models',model.path);if(!existsSync(file)||statSync(file).size!==model.bytes)missing.push(model.path+'(缺失或大小不符)');}
38
+ let service;try{service=await inspectEnvironment(endpoint,backend);if(service.ok){const edited=loadBackend({file:join(root,MARKER),generation:{backends:{local:{...PROFILE.backend,endpoints:[endpoint]}}}},'local','edit');const editReport=await inspectEnvironment(endpoint,edited);if(!editReport.ok)service=editReport;}}catch{}
39
39
  let conflict;
40
40
  if(service?.ok===true&&process.platform==='win32'&&!externalIdentity(endpoint,backend.launch))conflict='指定端口属于另一套环境';
41
41
  if(marker?.endpoint&&marker.endpoint!==endpoint){try{const previous=await inspectEnvironment(marker.endpoint,backend);if(previous.ok)conflict='此环境已在 '+marker.endpoint+' 运行,请使用原端口或先关闭原服务';}catch{}}
42
- const models=LOCAL_RECIPE.models.map(model=>({path:model.path,bytes:model.bytes,present:existsSync(join(root,'ComfyUI/models',model.path))&&statSync(join(root,'ComfyUI/models',model.path)).size===model.bytes}));
43
- return {models,conflict,root,endpoint,managed:!!marker,markerError,python,missing,service,reusable:!markerError&&!missing.length,live:service?.ok===true};
42
+ const models=PROFILE.models.map(model=>({path:model.path,bytes:model.bytes,present:existsSync(join(root,'ComfyUI/models',model.path))&&statSync(join(root,'ComfyUI/models',model.path)).size===model.bytes}));
43
+ return {guideId:PROFILE.id,models,conflict,root,endpoint,managed:!!marker,markerError,python,missing,service,reusable:!markerError&&!missing.length,live:service?.ok===true};
44
44
  }
45
45
  export function discoverInstallations(){
46
46
  const found=new Set(),index=join(globalHome(),'state','art-environments');
@@ -50,18 +50,3 @@ export function discoverInstallations(){
50
50
  for(const root of [join(globalHome(),'art-env'),join(homedir(),'AI'),...(process.platform==='win32'?['C:/AI','D:/AI','E:/AI']:[])])scan(root,3);
51
51
  return [...found];
52
52
  }
53
- export async function adoptInstallation(root,endpoint,{cancelled=()=>false,onStage=()=>{}}={}){
54
- const report=await inspectInstallation(root,endpoint);if(!report.reusable)throw new Error('现有环境需要补齐:'+report.missing.join('、'));
55
- for(const model of LOCAL_RECIPE.models){
56
- onStage('校验已有模型 '+model.path);const digest=createHash('sha256');
57
- for await(const chunk of createReadStream(join(report.root,'ComfyUI/models',model.path))){if(cancelled())throw new Error('接入已取消');digest.update(chunk);}
58
- if(digest.digest('hex')!==model.sha256)throw new Error('模型校验失败,保留原文件:'+model.path);
59
- }
60
- onStage('核验服务与工作流能力');
61
- const {backend,python}=backendFor(report.root,endpoint);
62
- if(report.live&&process.platform==='win32'&&!externalIdentity(endpoint,backend.launch))throw new Error('端口由其他环境占用,不能将其登记到指定目录');
63
- await ensureService(backend,join(environmentRoot(report.root),'runtime'),{cancelled});
64
- const current=await inspectInstallation(report.root,endpoint);if(!current.live)throw new Error('现有环境工作流能力检测未通过');
65
- if(cancelled())throw new Error('接入已取消');
66
- writeMarker(report.root,{python,endpoint,verification:'capabilities'});return current;
67
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevlns/art-workshop",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "private": false,
5
5
  "description": "管理项目风格、参考图、图片生成、编辑和定版。支持本地 ComfyUI 与远程图片模型。",
6
6
  "type": "module",
@@ -68,13 +68,19 @@ candidate delete 先确认影响,拒绝运行中或被计划/底图引用的
68
68
 
69
69
  任务参考可通过 reference import --item-id <对象标识> 绑定单个出图对象;未绑定的参考为任务共用。生成与编辑只采纳共用参考和当前对象参考的观察。reference update 的 itemId 可改绑对象,null 表示任务共用。
70
70
 
71
+ `v-cli capability coverage --json` 核对结构化调用覆盖。参考导入的 `--item-id` 指定当前任务出图对象,省略表示任务共用;工具校验对象身份。
72
+
73
+ ### 本地环境部署
74
+
75
+ 使用 environment guide 获取部署指南与契约,environment inspect 读取机器环境。Pi 通过基础工具和动态工作流完成安装、下载、修正与采样;environment verify 独立校验文件、服务和节点,environment register 验收后登记。任务授权、进程、互斥与恢复交由 Harness。不得把模型回复或服务连通当作真实出图。unregister 仅解除登记,不删除模型或停止外部服务。按 --guide 选择随包方案,模型事实和启动参数只由 art 维护。
76
+
71
77
  ## 结果验证
72
78
 
73
79
  核对原始错误、任务身份、停止状态及实际产物。只报告已经完成的验证,模拟测试与真实执行分别说明。
74
80
 
75
81
  ## 参考资料
76
82
 
77
- 通过 `v-cli agent docs art` 读取当前随包规范。 · v-cli.plugin.json
83
+ 通过 `art-workshop --help` 和 `art-workshop agent docs` 查阅使用规范。 · v-cli.plugin.json
78
84
 
79
85
  ## 许可与版权
80
86
 
package/v-cli.plugin.json CHANGED
@@ -1944,246 +1944,279 @@
1944
1944
  },
1945
1945
  {
1946
1946
  "path": [
1947
- "deployment",
1948
- "plan"
1947
+ "job",
1948
+ "template"
1949
1949
  ],
1950
- "description": "固定 Qwen 2.1 部署 plan",
1950
+ "usage": "v-cli art job template --project <id> --kind <generate|edit> [--core <id>]",
1951
+ "description": "只读返回工具权威的任务配置模板;生成任务使用已冻结核心的题材",
1952
+ "arguments": [],
1951
1953
  "options": [
1952
1954
  {
1953
- "flags": "--directory <dir>",
1954
- "description": "本机部署根目录"
1955
+ "flags": "--project <id>",
1956
+ "description": "工程身份"
1955
1957
  },
1956
1958
  {
1957
- "flags": "--endpoint <url>",
1958
- "description": "本机 ComfyUI 地址"
1959
+ "flags": "--kind <generate|edit>",
1960
+ "description": "任务类型"
1959
1961
  },
1960
1962
  {
1961
- "flags": "--out <file>",
1962
- "description": "保存不可变预案"
1963
+ "flags": "--core <id>",
1964
+ "description": "生成任务的冻结核心身份"
1963
1965
  }
1964
1966
  ],
1965
1967
  "output": {
1966
1968
  "format": "json",
1967
- "description": "固定 Qwen 2.1 部署 plan"
1969
+ "description": "只读返回工具权威的任务配置模板;生成任务使用已冻结核心的题材"
1968
1970
  },
1969
- "safety": [
1970
- "只读检测与预案;不下载、不启动、不采样"
1971
- ],
1972
- "usage": "art-workshop deployment plan",
1973
- "arguments": [],
1974
1971
  "exitCodes": {
1975
1972
  "0": "成功",
1976
- "1": "校验、占用或执行失败;未确认停止不释放资源"
1977
- }
1973
+ "1": "校验、版本冲突或执行失败"
1974
+ },
1975
+ "safety": [
1976
+ "只读返回模板;不创建任务或文件"
1977
+ ]
1978
1978
  },
1979
1979
  {
1980
1980
  "path": [
1981
- "deployment",
1982
- "start"
1981
+ "job",
1982
+ "from-candidate"
1983
1983
  ],
1984
- "description": "固定 Qwen 2.1 部署 start",
1984
+ "usage": "v-cli art job from-candidate --project <id> --id <task> --run <id> --candidate <id>",
1985
+ "description": "将完整候选导入私有底图,创建独立编辑草稿,不运行",
1986
+ "arguments": [],
1985
1987
  "options": [
1986
1988
  {
1987
- "flags": "--plan <file>",
1988
- "description": "实际冻结部署预案"
1989
+ "flags": "--project <id>",
1990
+ "description": "工程身份"
1989
1991
  },
1990
1992
  {
1991
- "flags": "--operation <id>",
1992
- "description": "稳定操作身份"
1993
+ "flags": "--id <task>",
1994
+ "description": "源任务身份"
1995
+ },
1996
+ {
1997
+ "flags": "--run <id>",
1998
+ "description": "真实批次"
1999
+ },
2000
+ {
2001
+ "flags": "--candidate <id>",
2002
+ "description": "完整候选身份"
1993
2003
  }
1994
2004
  ],
1995
2005
  "output": {
1996
2006
  "format": "json",
1997
- "description": "固定 Qwen 2.1 部署 start"
2007
+ "description": "将完整候选导入私有底图,创建独立编辑草稿,不运行"
2008
+ },
2009
+ "exitCodes": {
2010
+ "0": "成功",
2011
+ "1": "校验、版本冲突或执行失败"
1998
2012
  },
1999
2013
  "safety": [
2000
- "下载、源码安装、独立环境、模型哈希验证、生成及编辑采样;不覆写既有不匹配文件"
2014
+ "写入新的编辑草稿和私有底图;保留候选来源;不启动生成"
2015
+ ]
2016
+ },
2017
+ {
2018
+ "path": [
2019
+ "task",
2020
+ "resume"
2001
2021
  ],
2002
- "usage": "art-workshop deployment start",
2003
- "arguments": [],
2022
+ "usage": "art-workshop task resume TASK",
2023
+ "description": "仅恢复原上游任务的查询和下载,绝不重新提交",
2024
+ "arguments": [
2025
+ {
2026
+ "name": "TASK",
2027
+ "required": true,
2028
+ "description": "art 任务 ID"
2029
+ }
2030
+ ],
2031
+ "options": [],
2032
+ "output": {
2033
+ "format": "json",
2034
+ "description": "仅恢复原上游任务的查询和下载,绝不重新提交"
2035
+ },
2004
2036
  "exitCodes": {
2005
2037
  "0": "成功",
2006
- "1": "校验、占用或执行失败;未确认停止不释放资源"
2007
- }
2038
+ "1": "失败;未确认停止时保留服务并报告"
2039
+ },
2040
+ "safety": [
2041
+ "写入原任务状态",
2042
+ "查询原上游任务并下载已有产物",
2043
+ "提交结果未知时拒绝恢复"
2044
+ ]
2008
2045
  },
2009
2046
  {
2010
2047
  "path": [
2011
- "deployment",
2012
- "status"
2048
+ "environment",
2049
+ "guide"
2013
2050
  ],
2014
- "description": "固定 Qwen 2.1 部署 status",
2051
+ "description": "本地环境部署指南",
2052
+ "usage": "art-workshop environment guide",
2053
+ "arguments": [],
2015
2054
  "options": [
2016
2055
  {
2017
- "flags": "--id <id>",
2018
- "description": "原部署身份"
2056
+ "flags": "--guide <id>",
2057
+ "description": "部署指南标识;省略使用环境登记或推荐方案"
2019
2058
  }
2020
2059
  ],
2021
2060
  "output": {
2022
2061
  "format": "json",
2023
- "description": "固定 Qwen 2.1 部署 status"
2062
+ "description": "环境事实与验收结果"
2024
2063
  },
2025
2064
  "safety": [
2026
- "只查询原部署,不重复启动"
2065
+ "不执行安装、下载或采样;register 重新验收后登记,unregister 不删除安装文件或停止服务"
2027
2066
  ],
2028
- "usage": "art-workshop deployment status",
2029
- "arguments": [],
2030
2067
  "exitCodes": {
2031
2068
  "0": "成功",
2032
- "1": "校验、占用或执行失败;未确认停止不释放资源"
2069
+ "1": "验收或执行失败"
2033
2070
  }
2034
2071
  },
2035
2072
  {
2036
2073
  "path": [
2037
- "deployment",
2038
- "cancel"
2039
- ],
2040
- "description": "固定 Qwen 2.1 部署 cancel",
2041
- "options": [
2042
- {
2043
- "flags": "--id <id>",
2044
- "description": "原部署身份"
2045
- }
2074
+ "environment",
2075
+ "list"
2046
2076
  ],
2077
+ "description": "本地环境目录发现",
2078
+ "usage": "art-workshop environment list",
2079
+ "arguments": [],
2080
+ "options": [],
2047
2081
  "output": {
2048
2082
  "format": "json",
2049
- "description": "固定 Qwen 2.1 部署 cancel"
2083
+ "description": "环境事实与验收结果"
2050
2084
  },
2051
2085
  "safety": [
2052
- "请求取消;仅停止已核验子进程与本部署采样,确认后释放安装占用"
2086
+ "不执行安装、下载或采样;register 重新验收后登记,unregister 不删除安装文件或停止服务"
2053
2087
  ],
2054
- "usage": "art-workshop deployment cancel",
2055
- "arguments": [],
2056
2088
  "exitCodes": {
2057
2089
  "0": "成功",
2058
- "1": "校验、占用或执行失败;未确认停止不释放资源"
2090
+ "1": "验收或执行失败"
2059
2091
  }
2060
2092
  },
2061
2093
  {
2062
2094
  "path": [
2063
- "deployment",
2064
- "recover"
2095
+ "environment",
2096
+ "inspect"
2065
2097
  ],
2066
- "description": "查询唯一原部署回执,不重新执行",
2098
+ "description": "本地环境只读检测",
2099
+ "usage": "art-workshop environment inspect",
2100
+ "arguments": [],
2067
2101
  "options": [
2068
2102
  {
2069
- "flags": "--operation <id>",
2070
- "description": "启动前登记的稳定身份"
2103
+ "flags": "--directory <value>",
2104
+ "description": "本机环境根目录"
2105
+ },
2106
+ {
2107
+ "flags": "--endpoint <value>",
2108
+ "description": "本机 HTTP 服务根地址"
2109
+ },
2110
+ {
2111
+ "flags": "--guide <id>",
2112
+ "description": "部署指南标识;省略使用环境登记或推荐方案"
2071
2113
  }
2072
2114
  ],
2073
2115
  "output": {
2074
2116
  "format": "json",
2075
- "description": "查询唯一原部署回执,不重新执行"
2117
+ "description": "环境事实与验收结果"
2076
2118
  },
2077
2119
  "safety": [
2078
- "只读;无法唯一核验时停止未知"
2120
+ "不执行安装、下载或采样;register 重新验收后登记,unregister 不删除安装文件或停止服务"
2079
2121
  ],
2080
- "usage": "art-workshop deployment recover",
2081
- "arguments": [],
2082
2122
  "exitCodes": {
2083
2123
  "0": "成功",
2084
- "1": "校验、占用或执行失败;未确认停止不释放资源"
2124
+ "1": "验收或执行失败"
2085
2125
  }
2086
2126
  },
2087
2127
  {
2088
2128
  "path": [
2089
- "job",
2090
- "template"
2129
+ "environment",
2130
+ "verify"
2091
2131
  ],
2092
- "usage": "v-cli art job template --project <id> --kind <generate|edit> [--core <id>]",
2093
- "description": "只读返回工具权威的任务配置模板;生成任务使用已冻结核心的题材",
2132
+ "description": "本地环境确定性验收",
2133
+ "usage": "art-workshop environment verify",
2094
2134
  "arguments": [],
2095
2135
  "options": [
2096
2136
  {
2097
- "flags": "--project <id>",
2098
- "description": "工程身份"
2137
+ "flags": "--directory <value>",
2138
+ "description": "本机环境根目录"
2099
2139
  },
2100
2140
  {
2101
- "flags": "--kind <generate|edit>",
2102
- "description": "任务类型"
2141
+ "flags": "--endpoint <value>",
2142
+ "description": "本机 HTTP 服务根地址"
2103
2143
  },
2104
2144
  {
2105
- "flags": "--core <id>",
2106
- "description": "生成任务的冻结核心身份"
2145
+ "flags": "--guide <id>",
2146
+ "description": "部署指南标识;省略使用环境登记或推荐方案"
2107
2147
  }
2108
2148
  ],
2109
2149
  "output": {
2110
2150
  "format": "json",
2111
- "description": "只读返回工具权威的任务配置模板;生成任务使用已冻结核心的题材"
2151
+ "description": "环境事实与验收结果"
2112
2152
  },
2153
+ "safety": [
2154
+ "不执行安装、下载或采样;register 重新验收后登记,unregister 不删除安装文件或停止服务"
2155
+ ],
2113
2156
  "exitCodes": {
2114
2157
  "0": "成功",
2115
- "1": "校验、版本冲突或执行失败"
2116
- },
2117
- "safety": [
2118
- "只读返回模板;不创建任务或文件"
2119
- ]
2158
+ "1": "验收或执行失败"
2159
+ }
2120
2160
  },
2121
2161
  {
2122
2162
  "path": [
2123
- "job",
2124
- "from-candidate"
2163
+ "environment",
2164
+ "register"
2125
2165
  ],
2126
- "usage": "v-cli art job from-candidate --project <id> --id <task> --run <id> --candidate <id>",
2127
- "description": "将完整候选导入私有底图,创建独立编辑草稿,不运行",
2166
+ "description": "本地环境验收并登记",
2167
+ "usage": "art-workshop environment register",
2128
2168
  "arguments": [],
2129
2169
  "options": [
2130
2170
  {
2131
- "flags": "--project <id>",
2132
- "description": "工程身份"
2171
+ "flags": "--directory <value>",
2172
+ "description": "本机环境根目录"
2133
2173
  },
2134
2174
  {
2135
- "flags": "--id <task>",
2136
- "description": "源任务身份"
2175
+ "flags": "--endpoint <value>",
2176
+ "description": "本机 HTTP 服务根地址"
2137
2177
  },
2138
2178
  {
2139
- "flags": "--run <id>",
2140
- "description": "真实批次"
2141
- },
2142
- {
2143
- "flags": "--candidate <id>",
2144
- "description": "完整候选身份"
2179
+ "flags": "--guide <id>",
2180
+ "description": "部署指南标识;省略使用环境登记或推荐方案"
2145
2181
  }
2146
2182
  ],
2147
2183
  "output": {
2148
2184
  "format": "json",
2149
- "description": "将完整候选导入私有底图,创建独立编辑草稿,不运行"
2185
+ "description": "环境事实与验收结果"
2150
2186
  },
2187
+ "safety": [
2188
+ "不执行安装、下载或采样;register 重新验收后登记,unregister 不删除安装文件或停止服务"
2189
+ ],
2151
2190
  "exitCodes": {
2152
2191
  "0": "成功",
2153
- "1": "校验、版本冲突或执行失败"
2154
- },
2155
- "safety": [
2156
- "写入新的编辑草稿和私有底图;保留候选来源;不启动生成"
2157
- ]
2192
+ "1": "验收或执行失败"
2193
+ }
2158
2194
  },
2159
2195
  {
2160
2196
  "path": [
2161
- "task",
2162
- "resume"
2197
+ "environment",
2198
+ "unregister"
2163
2199
  ],
2164
- "usage": "art-workshop task resume TASK",
2165
- "description": "仅恢复原上游任务的查询和下载,绝不重新提交",
2166
- "arguments": [
2200
+ "description": "本地环境解除登记",
2201
+ "usage": "art-workshop environment unregister",
2202
+ "arguments": [],
2203
+ "options": [
2167
2204
  {
2168
- "name": "TASK",
2169
- "required": true,
2170
- "description": "art 任务 ID"
2205
+ "flags": "--directory <value>",
2206
+ "description": "本机环境根目录"
2171
2207
  }
2172
2208
  ],
2173
- "options": [],
2174
2209
  "output": {
2175
2210
  "format": "json",
2176
- "description": "仅恢复原上游任务的查询和下载,绝不重新提交"
2211
+ "description": "环境事实与验收结果"
2177
2212
  },
2213
+ "safety": [
2214
+ "不执行安装、下载或采样;register 重新验收后登记,unregister 不删除安装文件或停止服务"
2215
+ ],
2178
2216
  "exitCodes": {
2179
2217
  "0": "成功",
2180
- "1": "失败;未确认停止时保留服务并报告"
2181
- },
2182
- "safety": [
2183
- "写入原任务状态",
2184
- "查询原上游任务并下载已有产物",
2185
- "提交结果未知时拒绝恢复"
2186
- ]
2218
+ "1": "验收或执行失败"
2219
+ }
2187
2220
  }
2188
2221
  ]
2189
2222
  }
@@ -1,19 +0,0 @@
1
- import {statSync} from 'node:fs';
2
- import {spawn,execFileSync} from 'node:child_process';
3
-
4
- export function deploymentCommandError(executable,error){
5
- const missing=error.code==='ENOENT';
6
- const detail=missing
7
- ? `找不到部署命令 ${executable}。${executable==='git'?'请安装 Git for Windows 并加入 PATH,然后完全退出并重新启动 Vant。':'请确认该命令已安装并在 Vant 的 PATH 中可用。'}`
8
- : `部署命令 ${executable} 无法执行(${error.code??error.status??'未知错误'}),请查看部署日志。`;
9
- return new Error(detail,{cause:error});
10
- }
11
- export function checkDeploymentCommand(executable){
12
- try{execFileSync(executable,['--version'],{windowsHide:true,timeout:10000,stdio:'pipe'});}
13
- catch(error){throw deploymentCommandError(executable,error);}
14
- }
15
- export function spawnDeploymentCommand(executable,args,cwd){
16
- try{if(!statSync(cwd).isDirectory())throw new Error('不是目录');}
17
- catch(error){throw new Error(`部署工作目录不可用:${cwd}。请重新检测安装目录。`,{cause:error});}
18
- return spawn(executable,args,{cwd,windowsHide:true,stdio:['ignore','inherit','inherit']});
19
- }
@@ -1,24 +0,0 @@
1
- import {existsSync,mkdirSync,renameSync,rmSync} from 'node:fs';
2
- import {dirname} from 'node:path';
3
- import {execFileSync} from 'node:child_process';
4
- import {ownedPath} from './workspace.mjs';
5
- import {hash} from './shared.mjs';
6
- import {deploymentCommandError} from './deployment-process.mjs';
7
-
8
- export async function ensureDeploymentSource(path,source,{control,command,check}){
9
- check();
10
- if(existsSync(path)){
11
- const git=args=>{try{return execFileSync('git',['-C',path,...args],{encoding:'utf8',windowsHide:true,timeout:10000}).trim();}catch(error){throw deploymentCommandError('git',error);}};
12
- const current=git(['rev-parse','HEAD']),remote=git(['remote','get-url','origin']).replace(/\.git$/,''),dirty=git(['status','--porcelain','--untracked-files=no']);
13
- if(current!==source.commit||remote!==source.repository||dirty)throw new Error('现有源码不是干净的固定部署版本,保留用户环境;请另选空目录');return;
14
- }
15
- mkdirSync(dirname(path),{recursive:true});
16
- const staging=ownedPath(control,'staging','source-'+hash(source).slice(0,16));
17
- // spawn requires its working directory to exist even when Git is installed.
18
- mkdirSync(dirname(staging),{recursive:true});
19
- if(existsSync(staging))rmSync(staging,{recursive:true,force:true});
20
- const network=['-c','http.lowSpeedLimit=1024','-c','http.lowSpeedTime=60'];
21
- await command('git',[...network,'clone','--filter=blob:none','--no-checkout',source.repository,staging],dirname(staging));
22
- await command('git',[...network,'-C',staging,'checkout','--detach',source.commit],dirname(staging));
23
- check();if(existsSync(path))throw new Error('源码目标被其他操作创建,禁止覆盖');renameSync(staging,path);
24
- }
@@ -1,86 +0,0 @@
1
- import {environmentRoot,writeMarker} from './environments.mjs';
2
- import {existsSync,mkdirSync,createReadStream,renameSync,rmSync,readFileSync} from 'node:fs';
3
- import {join,dirname} from 'node:path';
4
- import {spawnDeploymentCommand,deploymentCommandError} from './deployment-process.mjs';
5
- import {ensureDeploymentSource} from './deployment-source.mjs';
6
- import {createHash} from 'node:crypto';
7
- import {readJson,writeJson,hash} from './shared.mjs';
8
- import {loadSettings} from './settings.mjs';
9
- import {ownedPath} from './workspace.mjs';
10
- import {locked,sleep,stateRead} from './runtime.mjs';
11
- import {processIdentity,stopIdentity,ensureService} from './service.mjs';
12
- import {LOCAL_RECIPE,validateDeploymentPlan} from './deployment.mjs';
13
- import {loadBackend,BUILTIN_WORKFLOW} from './workflows.mjs';
14
- import {inspectEnvironment} from './diagnostics.mjs';
15
- import {generate} from './providers.mjs';
16
- import {cancelPrompt} from './comfyui.mjs';
17
- import {finishPlan} from './plan.mjs';
18
- import {bindBackend} from './backends.mjs';
19
- import {validateImage} from './images.mjs';
20
-
21
- const file=process.argv[2],state=readJson(file),plan=state.plan,settings=loadSettings({file:plan.settingsFile});
22
- const persist=()=>{state.heartbeat=new Date().toISOString();writeJson(file,state);};
23
- const cancelled=()=>existsSync(file+'.cancel');
24
- const check=()=>{if(cancelled())throw new Error('部署已取消');};
25
- const stage=value=>{state.stage=value;persist();check();};
26
- state.workerPid=process.pid;state.status='running';persist();const heartbeat=setInterval(persist,1000);
27
- let childIdentity,unsettled=false;
28
- async function command(executable,args,cwd){
29
- check();const child=spawnDeploymentCommand(executable,args,cwd);
30
- const completion=new Promise((resolve,reject)=>{child.once('error',error=>reject(deploymentCommandError(executable,error)));child.once('exit',(code)=>code===0?resolve():reject(new Error('部署命令 '+executable+' 失败,退出码 '+code)));});
31
- // Attach rejection immediately while awaiting the process identity.
32
- completion.catch(()=>{});await sleep(100);childIdentity=child.pid?processIdentity(child.pid):null;
33
- let stopping;
34
- const timer=setInterval(()=>{if(cancelled()&&childIdentity){clearInterval(timer);stopping=stopIdentity(childIdentity).catch(()=>{unsettled=true;});}},100);
35
- try{await completion;check();}finally{clearInterval(timer);if(stopping)await stopping;if(childIdentity&&processIdentity(childIdentity.pid)){try{await stopIdentity(childIdentity);}catch{unsettled=true;}}childIdentity=null;}
36
- }
37
- async function sha256(path){const digest=createHash('sha256');let bytes=0;for await(const chunk of createReadStream(path)){check();digest.update(chunk);bytes+=chunk.length;state.processedBytes=bytes;}return digest.digest('hex');}
38
- const repository=(path,source)=>ensureDeploymentSource(path,source,{control:environmentRoot(plan.installRoot),command,check});
39
-
40
- try{
41
- validateDeploymentPlan(plan,settings);
42
- const control=environmentRoot(plan.installRoot),claim=ownedPath(control,'deployment.json');
43
- await locked(control,'install',async()=>{
44
- const old=stateRead(claim);if(old&&old.deploymentId!==state.deploymentId&&old.stopConfirmed!==true)throw new Error('该安装目录已有运行或停止未知的部署,禁止重复操作');
45
- writeJson(claim,{deploymentId:state.deploymentId,workspace:plan.workspace,status:'running',stopConfirmed:false});
46
- try{
47
- stage('校验固定源码与节点');await repository(ownedPath(plan.installRoot,'ComfyUI'),LOCAL_RECIPE.comfy);
48
- await repository(ownedPath(plan.installRoot,'ComfyUI/custom_nodes/ComfyUI-GGUF'),LOCAL_RECIPE.plugin);
49
- const venvOwner=ownedPath(control,'venv-owned.json'),ownedVenv=stateRead(venvOwner);
50
- const installPython=!plan.portable&&(!existsSync(plan.python)||ownedVenv?.recipeHash===hash(LOCAL_RECIPE));
51
- if(installPython){
52
- if(!existsSync(plan.python)){writeJson(venvOwner,{recipeHash:hash(LOCAL_RECIPE),python:plan.python});stage('创建独立 Python 环境');await command(plan.basePython,['-m','venv',ownedPath(plan.installRoot,'.venv')],plan.installRoot);}
53
- stage('安装 CUDA 运行依赖');await command(plan.python,['-m','pip','install','torch=='+LOCAL_RECIPE.torch,'torchvision=='+LOCAL_RECIPE.torchvision,'--index-url',LOCAL_RECIPE.torchIndex],plan.installRoot);
54
- await command(plan.python,['-m','pip','install','-r',ownedPath(plan.installRoot,'ComfyUI/requirements.txt'),'gguf=='+LOCAL_RECIPE.gguf,'sentencepiece','protobuf'],plan.installRoot);
55
- }
56
- stage('核验 Python 与 CUDA');await command(plan.python,['-c',`import torch,gguf; import importlib.metadata as m; assert torch.cuda.is_available(), 'NVIDIA CUDA unavailable'; assert torch.__version__.split('+')[0]=='${LOCAL_RECIPE.torch}', 'Torch version differs'; assert m.version('gguf')=='${LOCAL_RECIPE.gguf}', 'GGUF version differs'`],plan.installRoot);
57
- for(const model of LOCAL_RECIPE.models){
58
- const destination=ownedPath(plan.installRoot,'ComfyUI/models',model.path);stage('校验模型 '+model.path);state.processedBytes=0;
59
- if(existsSync(destination)){if(await sha256(destination)!==model.sha256)throw new Error('现有模型哈希不匹配,保留原文件:'+model.path);continue;}
60
- stage('下载模型 '+model.path);mkdirSync(dirname(destination),{recursive:true});const temporary=ownedPath(control,hash(model.path)+'.part');
61
- try{await command('curl.exe',['--fail','--location','--retry','2','--connect-timeout','20','--max-time','7200','--output',temporary,model.url],plan.installRoot);if(await sha256(temporary)!==model.sha256)throw new Error('下载模型哈希校验失败');check();if(existsSync(destination))throw new Error('模型目标被其他操作创建,禁止覆盖');renameSync(temporary,destination);}finally{rmSync(temporary,{force:true});}
62
- }
63
- const configured={...settings,generation:{defaultBackend:'local-qwen',defaults:{},backends:{'local-qwen':{provider:'comfyui',model:LOCAL_RECIPE.models[0].path.split('/').at(-1),endpoints:[plan.endpoint],launch:{executable:plan.python,cwd:plan.installRoot,args:['-s','ComfyUI/main.py','--disable-dynamic-vram','--lowvram','--disable-auto-launch',...(new URL(plan.endpoint).port?['--port',new URL(plan.endpoint).port]:[])]}}}}};
64
- stage('检测固定工作流与环境');const backend=loadBackend(configured,'local-qwen'),endpoint=await ensureService(backend,join(control,'runtime'),{cancelled});
65
- const report=await inspectEnvironment(endpoint,backend);if(!report.ok)throw new Error('部署环境检查未通过');state.environment=report;
66
- // Readiness is proved by generation and editing, rather than a listening port.
67
- const {queue_running=[],queue_pending=[]}=await(await fetch(new URL('/queue',endpoint))).json();if(queue_running.length||queue_pending.length)throw new Error('现有服务正在执行其他任务,本次不插入验收采样;任务结束后重试部署验证');
68
- const output=ownedPath(control,'verification',state.deploymentId);mkdirSync(output,{recursive:true});
69
- let source;
70
- for(const mode of ['generate','edit']){
71
- stage(mode==='generate'?'单图生成验证':'底图编辑验证');
72
- const base=finishPlan({module:mode,project:'deployment',job:'verification',execution:{model:LOCAL_RECIPE.models[0].path.split('/').at(-1),size:'512*512',perValue:1,promptExtend:false,watermark:false},sources:{recipe:LOCAL_RECIPE.id},snapshots:{},refs:[],items:[{itemId:'verification',variantId:'base',seed:7619,prompt:mode==='generate'?'一个圆润的青绿色科幻能量球,简洁轮廓,柔和高光,纯白背景。':'保持原图轮廓和构图,将主体颜色改成金黄色。',negativeBlock:'文字,水印',imageArgs:mode==='edit'?[source]:[],checks:{content:[],style:[],asset:[]}}]});
73
- const modeOutput=ownedPath(output,mode);mkdirSync(modeOutput,{recursive:true});
74
- const bound=bindBackend(base,configured,'local-qwen'),result=await generate(bound,bound.items[0],{endpoint,root:join(control,'runtime'),outputDir:modeOutput,prefix:mode,cancelled,onPrompt:promptId=>{state.promptId=promptId;persist();}});
75
- state.promptId=null;const path=ownedPath(modeOutput,result.files[0]),info=await validateImage(readFileSync(path));if(info.width!==512||info.height!==512)throw new Error('部署验证图片尺寸不符');source=path;state.verification??=[];state.verification.push({mode,path,hash:await sha256(path),planHash:bound.planHash});persist();
76
- }
77
- stage('保存已验证部署配置');for(const evidence of state.verification)if(await sha256(evidence.path)!==evidence.hash)throw new Error('部署采样证据发生变化,不保存完成状态');const raw=readJson(settings.file);raw.generation={...raw.generation,defaultBackend:'local-qwen',backends:{...raw.generation?.backends,'local-qwen':configured.generation.backends['local-qwen']}};writeJson(settings.file,raw);
78
- writeMarker(plan.installRoot,{python:plan.portable?'python_embeded/python.exe':'.venv/Scripts/python.exe',endpoint:plan.endpoint,recipe:LOCAL_RECIPE.id,verification:'generate-and-edit'});state.status='succeeded';state.stopConfirmed=true;state.workflow=BUILTIN_WORKFLOW;
79
- }catch(error){
80
- if(error.unsettled&&!state.promptId)unsettled=true;
81
- if(state.promptId){try{await cancelPrompt(plan.endpoint,state.promptId);state.promptId=null;}catch{unsettled=true;}}
82
- state.status=unsettled?'unknown':cancelled()?'cancelled':'failed';state.stopConfirmed=!unsettled;state.error=error.message;
83
- }finally{writeJson(claim,{deploymentId:state.deploymentId,workspace:plan.workspace,status:state.status,stopConfirmed:state.stopConfirmed});}
84
- });
85
- }catch(error){if(error.unsettled)unsettled=true;state.status=unsettled?'unknown':cancelled()?'cancelled':'failed';state.stopConfirmed=!unsettled;state.error=error.message;}
86
- finally{clearInterval(heartbeat);state.finishedAt=new Date().toISOString();persist();}
@@ -1,75 +0,0 @@
1
- import {existsSync,openSync,closeSync,statfsSync} from 'node:fs';
2
- import {join,resolve} from 'node:path';
3
- import {spawn,execFileSync} from 'node:child_process';
4
- import {fileURLToPath} from 'node:url';
5
- import {randomUUID} from 'node:crypto';
6
- import {hash,readJson,writeJson,keys,id} from './shared.mjs';
7
- import {externalPath} from './settings.mjs';
8
- import {ownedPath} from './workspace.mjs';
9
- import {runtimeRoot,locked,alive} from './runtime.mjs';
10
- import {checkDeploymentCommand} from './deployment-process.mjs';
11
-
12
- // This recipe is the tested local installation, not a user-editable workflow.
13
- export const LOCAL_RECIPE={
14
- id:'qwen-image-2.1-Q4-cpu-text-v1',
15
- comfy:{repository:'https://github.com/Comfy-Org/ComfyUI',commit:'b0b743566f65daafc423b4fea8a2fbda94b3384a'},
16
- plugin:{repository:'https://github.com/leejet/ComfyUI-GGUF',commit:'373048b8403a7820620065210a691263d4da0a61'},
17
- models:[
18
- {path:'diffusion_models/qwen-image-2.1-UC-Q4_K_M.gguf',bytes:4_604_558_112,url:'https://huggingface.co/abenzerps/Qwen-Image-2.1-Uncensored-GGUF/resolve/main/qwen-image-2.1-UC-Q4_K_M.gguf',sha256:'e79c8a009f2ecbdb6c70fd663d9aea9ee304a0d91f347e4169a756b8ad141b41'},
19
- {path:'text_encoders/qwen3vl_8b_int8_convrot.safetensors',bytes:9_350_798_360,url:'https://huggingface.co/Comfy-Org/Qwen-Image-2.1/resolve/main/text_encoders/qwen3vl_8b_int8_convrot.safetensors',sha256:'8bfd0f6e12abf2d2d697ecc888e5e90b0d6741d6708f05799f53afa560452e8f'},
20
- {path:'vae/qwen_image_2.1_vae_bf16.safetensors',bytes:675_509_688,url:'https://huggingface.co/Comfy-Org/Qwen-Image-2.1/resolve/main/vae/qwen_image_2.1_vae_bf16.safetensors',sha256:'bb21f7473051e1ac368515dd3f2e15cd44d7a11748ee8823e1ddca3e4876b7c9'},
21
- ],
22
- torch:'2.14.0',torchvision:'0.29.0',torchIndex:'https://download.pytorch.org/whl/cu130',gguf:'0.19.0',
23
- };
24
- export function deploymentPlan(settings,{directory,endpoint='http://127.0.0.1:8188/'}={}){
25
- if(process.platform!=='win32')throw new Error('固定自动部署方案目前仅适配 Windows NVIDIA 环境');
26
- const target=ownedPath(externalPath(directory,'部署目录')),url=new URL(endpoint);
27
- if(url.protocol!=='http:'||!['127.0.0.1','localhost'].includes(url.hostname)||url.pathname!=='/'||url.search||url.hash||url.username||url.password)throw new Error('部署服务地址必须为本机 HTTP 根地址');
28
- checkDeploymentCommand('git');
29
- let gpu;
30
- try{gpu=execFileSync('nvidia-smi',['--query-gpu=name,memory.total,driver_version','--format=csv,noheader,nounits'],{encoding:'utf8',windowsHide:true,timeout:10000}).trim().split('\n').filter(Boolean).map(line=>{const [name,memoryMiB,driver]=line.split(',').map(value=>value.trim());return {name,memoryMiB:Number(memoryMiB),driver};});if(!gpu.length||gpu.some(device=>!device.name||!Number.isFinite(device.memoryMiB)))throw new Error('GPU 信息无效');}
31
- catch{throw new Error('固定自动部署需要可检测的 NVIDIA GPU 与驱动,请先安装驱动');}
32
- const portable=existsSync(ownedPath(target,'python_embeded/python.exe')),venv=ownedPath(target,'.venv/Scripts/python.exe');
33
- let python=portable?ownedPath(target,'python_embeded/python.exe'):existsSync(venv)?venv:null,basePython=null;
34
- if(!python){try{basePython=execFileSync('python',['-c','import sys; assert sys.version_info >= (3,12); print(sys.executable)'],{encoding:'utf8',windowsHide:true,timeout:10000}).trim();}catch{throw new Error('自动部署需要已安装的 Python 3.12 或以上;现有便携版可直接复用');}python=venv;}
35
- const present=LOCAL_RECIPE.models.map(model=>({...model,present:existsSync(ownedPath(target,'ComfyUI/models',model.path))}));
36
- if(present.some(model=>!model.present))checkDeploymentCommand('curl.exe');
37
- let ancestor=target;while(!existsSync(ancestor)){const parent=resolve(ancestor,'..');if(parent===ancestor)break;ancestor=parent;}
38
- const storage=statfsSync(ancestor),available=Number(storage.bavail)*Number(storage.bsize),required=present.filter(model=>!model.present).reduce((sum,model)=>sum+model.bytes,0)+(!portable&&!existsSync(venv)?8_000_000_000:1_000_000_000);
39
- if(available<required)throw new Error('部署磁盘空间不足,需要至少 '+Math.ceil(required/1e9)+' GB');
40
- const plan={schema:'art-workshop/deployment-plan',recipe:LOCAL_RECIPE,gpu,installRoot:target,endpoint:url.href,python,basePython,portable,models:present,requiredBytes:required,availableBytes:available,settingsFile:settings.file,workspace:settings.paths.workspace};
41
- return {...plan,planHash:hash(plan)};
42
- }
43
- export function validateDeploymentPlan(plan,settings){
44
- keys(plan,['schema','recipe','gpu','installRoot','endpoint','python','basePython','portable','models','requiredBytes','availableBytes','settingsFile','workspace','planHash'],'部署预案');
45
- const {planHash,...body}=plan;if(plan.schema!=='art-workshop/deployment-plan'||hash(body)!==planHash||hash(plan.recipe)!==hash(LOCAL_RECIPE))throw new Error('部署预案或固定方案已变化');
46
- if(plan.settingsFile!==settings.file||resolve(plan.workspace)!==resolve(settings.paths.workspace))throw new Error('部署预案不属于当前配置与工程');
47
- const expected=deploymentPlan(settings,{directory:plan.installRoot,endpoint:plan.endpoint});
48
- for(const key of ['gpu','python','basePython','portable','models'])if(hash(expected[key])!==hash(plan[key]))throw new Error('部署环境已变化,请重新预演');
49
- return plan;
50
- }
51
- export function deploymentStatus(settings,deploymentId){
52
- const state=readJson(ownedPath(runtimeRoot(settings),'deployments',id(deploymentId)+'.json'));
53
- if(state.schema!=='art-workshop/deployment'||state.deploymentId!==deploymentId)throw new Error('部署身份不匹配');
54
- if(!['succeeded','failed','cancelled','unknown'].includes(state.status)&&Date.now()-Date.parse(state.heartbeat??state.createdAt)>10000&&!alive(state.workerPid)){state.status='unknown';state.stopConfirmed=false;state.error='部署工作进程退出;禁止重复启动或清理,先核验原操作';writeJson(ownedPath(runtimeRoot(settings),'deployments',deploymentId+'.json'),state);}
55
- return state;
56
- }
57
- export async function startDeployment(settings,plan,{operationId}={}){
58
- if(typeof operationId!=='string'||!/^[a-z0-9-]{1,128}$/.test(operationId))throw new Error('部署需要稳定操作身份');
59
- return locked(runtimeRoot(settings),'deployment',async()=>{
60
- const {readdirSync}=await import('node:fs'),directory=ownedPath(runtimeRoot(settings),'deployments');
61
- const previous=existsSync(directory)?readdirSync(directory).filter(file=>file.endsWith('.json')).map(file=>deploymentStatus(settings,file.slice(0,-5))):[];
62
- const same=previous.find(state=>state.operationId===operationId);if(same){if(same.plan.planHash!==plan.planHash)throw new Error('部署操作身份已用于其他预案');return same;}
63
- const deploymentId='deploy-'+randomUUID(),file=ownedPath(directory,deploymentId+'.json'),logPath=ownedPath(directory,deploymentId+'.log');
64
- const state={schema:'art-workshop/deployment',deploymentId,operationId,status:'queued',stopConfirmed:false,createdAt:new Date().toISOString(),plan,logPath};writeJson(file,state);
65
- // Record rejected requests too: a caller losing an error receipt can recover
66
- // proof that this operation never started, without repeating the deployment.
67
- try{validateDeploymentPlan(plan,settings);if(previous.some(state=>state.stopConfirmed!==true))throw new Error('已有部署运行或停止未知,先处理原操作');}
68
- catch(error){state.status='failed';state.stopConfirmed=true;state.finishedAt=new Date().toISOString();state.error=error.message;writeJson(file,state);throw error;}
69
- const fd=openSync(logPath,'a'),child=spawn(process.execPath,[fileURLToPath(new URL('./deployment-worker.mjs',import.meta.url)),file],{detached:true,windowsHide:true,stdio:['ignore',fd,fd],env:{...process.env,ART_VISION_KEY:'',DASHSCOPE_API_KEY:''}});closeSync(fd);
70
- try{await new Promise((resolve,reject)=>{child.once('spawn',resolve);child.once('error',reject);});}catch(error){state.status='failed';state.stopConfirmed=true;state.error='部署进程启动失败';writeJson(file,state);throw error;}
71
- child.unref();return {deploymentId,status:'queued',stopConfirmed:false};
72
- });
73
- }
74
- export function cancelDeployment(settings,deploymentId){const state=deploymentStatus(settings,deploymentId);if(state.stopConfirmed===true)return state;writeJson(ownedPath(runtimeRoot(settings),'deployments',deploymentId+'.json.cancel'),{requestedAt:new Date().toISOString()});return {deploymentId,status:'cancelling',stopConfirmed:false};}
75
- export async function recoverDeployment(settings,operationId){const {readdirSync}=await import('node:fs');const directory=ownedPath(runtimeRoot(settings),'deployments');const records=existsSync(directory)?readdirSync(directory).filter(file=>file.endsWith('.json')).map(file=>deploymentStatus(settings,file.slice(0,-5))).filter(state=>state.operationId===operationId):[];if(records.length!==1)throw new Error('没有唯一原部署记录,停止状态未知;禁止重新提交');return records[0];}