@kevlns/art-workshop 0.5.1 → 0.5.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 +25 -25
- package/LICENSE +21 -21
- package/README.md +63 -63
- package/art-workshop.mjs +174 -174
- package/docs/configuration.md +82 -82
- package/docs/core-guidance.md +50 -50
- package/docs/data-formats.md +85 -85
- package/docs/deployment.md +32 -32
- package/docs/local-models/qwen-image-2.1.json +73 -73
- package/docs/local-models/qwen-image-2.1.md +33 -33
- package/docs/model-architecture.md +78 -78
- package/docs/modes.md +67 -67
- package/lib/agent.mjs +32 -32
- package/lib/analysis-worker.mjs +32 -32
- package/lib/analyze.mjs +85 -85
- package/lib/asset-profile.mjs +23 -23
- package/lib/candidates.mjs +103 -103
- package/lib/comfy-recovery.mjs +17 -17
- package/lib/conversation.mjs +77 -77
- package/lib/core.mjs +75 -75
- package/lib/deployment-guide.mjs +12 -12
- package/lib/design.mjs +29 -29
- package/lib/dimensions.mjs +22 -22
- package/lib/edit.mjs +41 -41
- package/lib/environment-operations.mjs +49 -49
- package/lib/environment-runtime.mjs +99 -99
- package/lib/environments.mjs +55 -55
- package/lib/executor.mjs +107 -107
- package/lib/generate.mjs +58 -58
- package/lib/heartbeat.mjs +16 -16
- package/lib/images.mjs +1 -1
- package/lib/lifecycle.mjs +53 -53
- package/lib/migration.mjs +154 -154
- package/lib/process-identity.mjs +22 -14
- package/lib/project.mjs +39 -39
- package/lib/refs.mjs +26 -26
- package/lib/runtime.mjs +25 -25
- package/lib/service.mjs +134 -126
- package/lib/settings.mjs +50 -50
- package/lib/shared.mjs +67 -67
- package/lib/style-bundle.mjs +85 -85
- package/lib/style-contract.mjs +74 -74
- package/lib/style-lifecycle.mjs +125 -125
- package/lib/style-review.mjs +14 -14
- package/lib/task-contract.mjs +93 -93
- package/lib/tasks.mjs +497 -497
- package/lib/templates.mjs +80 -80
- package/lib/vision.mjs +56 -56
- package/lib/worker-process.mjs +6 -6
- package/lib/workspace.mjs +292 -292
- package/package.json +1 -1
- package/rules/core-guidance.json +22 -22
- package/skills/art-workshop/SKILL.md +17 -17
- package/skills/art-workshop/references/conversation.md +11 -11
- package/skills/art-workshop/references/expression.md +27 -27
- package/skills/art-workshop/references/project.md +109 -109
- package/v-cli.plugin.json +2747 -2747
package/AGENTS.md
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
# Vant 美术工坊开发规范
|
|
2
|
-
|
|
3
|
-
## 定位
|
|
4
|
-
|
|
5
|
-
本文件仅指导维护 art-workshop 仓库。运行时技能正本为 skills/art-workshop/SKILL.md;命令机器契约为 v-cli.plugin.json。
|
|
6
|
-
|
|
7
|
-
## 调用流程
|
|
8
|
-
|
|
9
|
-
修改前读取相关源文件与 package.json 中的检查命令,保留已有工作区改动。
|
|
10
|
-
|
|
11
|
-
## 调用规范
|
|
12
|
-
|
|
13
|
-
技能正文与 references 独立维护,不从本文件生成运行规范。修改命令时同步机器清单及生成的命令文档。宿主配置和状态使用 VANT_HOME(默认 ~/.vant),项目数据保留在工程 .vant;安装不扫描其他 Agent 目录。外部宿主仅显式适配。
|
|
14
|
-
|
|
15
|
-
## 结果验证
|
|
16
|
-
|
|
17
|
-
运行 package.json 中与改动相关的检查;区分单测、真实后端、界面和安装验证。不得将模拟结果报告为真实生图或发布成功。
|
|
18
|
-
|
|
19
|
-
## 参考资料
|
|
20
|
-
|
|
21
|
-
[使用说明](README.md) · [运行技能](skills/art-workshop/SKILL.md)
|
|
22
|
-
|
|
23
|
-
## 许可与版权
|
|
24
|
-
|
|
25
|
-
MIT。Copyright © 2026 Vant。
|
|
1
|
+
# Vant 美术工坊开发规范
|
|
2
|
+
|
|
3
|
+
## 定位
|
|
4
|
+
|
|
5
|
+
本文件仅指导维护 art-workshop 仓库。运行时技能正本为 skills/art-workshop/SKILL.md;命令机器契约为 v-cli.plugin.json。
|
|
6
|
+
|
|
7
|
+
## 调用流程
|
|
8
|
+
|
|
9
|
+
修改前读取相关源文件与 package.json 中的检查命令,保留已有工作区改动。
|
|
10
|
+
|
|
11
|
+
## 调用规范
|
|
12
|
+
|
|
13
|
+
技能正文与 references 独立维护,不从本文件生成运行规范。修改命令时同步机器清单及生成的命令文档。宿主配置和状态使用 VANT_HOME(默认 ~/.vant),项目数据保留在工程 .vant;安装不扫描其他 Agent 目录。外部宿主仅显式适配。
|
|
14
|
+
|
|
15
|
+
## 结果验证
|
|
16
|
+
|
|
17
|
+
运行 package.json 中与改动相关的检查;区分单测、真实后端、界面和安装验证。不得将模拟结果报告为真实生图或发布成功。
|
|
18
|
+
|
|
19
|
+
## 参考资料
|
|
20
|
+
|
|
21
|
+
[使用说明](README.md) · [运行技能](skills/art-workshop/SKILL.md)
|
|
22
|
+
|
|
23
|
+
## 许可与版权
|
|
24
|
+
|
|
25
|
+
MIT。Copyright © 2026 Vant。
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright © 2026 Vant
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright © 2026 Vant
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
# Vant 美术工坊
|
|
2
|
-
|
|
3
|
-
`@kevlns/art-workshop`
|
|
4
|
-
|
|
5
|
-
## 功能
|
|
6
|
-
|
|
7
|
-
管理项目风格、参考图、图片生成、编辑和定版。支持本地 ComfyUI 与远程图片模型。
|
|
8
|
-
|
|
9
|
-
## 环境要求
|
|
10
|
-
|
|
11
|
-
Node.js 20 及以上;本地生成还需工具检测通过的 Python、显卡驱动与 ComfyUI 环境。
|
|
12
|
-
|
|
13
|
-
## 安装
|
|
14
|
-
|
|
15
|
-
```sh
|
|
16
|
-
npm install -g @kevlns/art-workshop
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## 快速开始
|
|
20
|
-
|
|
21
|
-
```sh
|
|
22
|
-
art-workshop config show
|
|
23
|
-
art-workshop config validate
|
|
24
|
-
art-workshop agent index
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## 使用说明
|
|
28
|
-
|
|
29
|
-
### 使用流程
|
|
30
|
-
|
|
31
|
-
1. 创建 schemaVersion 2 工程和风格草稿,导入对象专属参考;分析预演后按授权运行,审阅报告并采用为冻结核心。
|
|
32
|
-
2. 用 `job template` 获取任务模板,填写实际需求后创建任务。动态参考先 `job analyze`;编辑底图单独绑定。
|
|
33
|
-
3. 编译 `generate plan` 或 `edit plan`,保存并用 `run --plan ... --dry` 核对模型、尺寸、候选数、输入和参数转换。
|
|
34
|
-
4. 按任务授权执行,保存 taskId;前台和后台都登记运行。查询原身份,不因超时或重启重复提交。
|
|
35
|
-
5. `check` 核验产物,`candidate finalize` 定版。替换需 `--replace`,删除需 `--confirm`,均保留事实记录。
|
|
36
|
-
|
|
37
|
-
正式风格只读,修改需派生。任务空闲后可按原身份更新配置,历史批次不覆写。job discard 归档任务,job restore 按当前版本恢复;配置、收藏与历史图片保留。任务列表默认按执行中、待定版、草稿、已定版排序;运行状态与停止证据分别判断,不能只看终态释放占用。
|
|
38
|
-
|
|
39
|
-
### 后端与数据归属
|
|
40
|
-
|
|
41
|
-
本地为 ComfyUI 内置 Qwen Image 2.1 Q4、CPU 文本编码器方案,支持生成和显式底图编辑。自定义 API workflow 需要明确 bindings 与完整适配,不能把任意导入工作流视为可执行。
|
|
42
|
-
|
|
43
|
-
远程图片通过工具登记的协议适配器直接调用,目前登记 DashScope。模型、参数与支持状态由 art 内部登记表维护,Vant 读取同一目录,不复制型号判断。分析使用独立视觉模型连接;未注入视觉连接时使用百炼 CLI。Token Plan 是渠道,DashScope 是协议,不能据协议擅自替换实例地址和凭据。
|
|
44
|
-
|
|
45
|
-
应用数据根默认 `~/.vant`,可由 `VANT_HOME` 覆盖。工具配置为 `~/.vant/tools/art-workshop/config.json`;Vant 将工程美术数据绑定至工程 `.vant/art`。共享模型环境默认 `~/.vant/art-env`,控制状态与日志归用户数据根;安装根保存环境标记 `vant.art.config.json`。
|
|
46
|
-
|
|
47
|
-
## 开发与验证
|
|
48
|
-
|
|
49
|
-
```sh
|
|
50
|
-
npm ci
|
|
51
|
-
npm run check
|
|
52
|
-
npm run test:package
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
命令返回、结构校验、模拟测试与外部平台实际运行分别核验。发布版本和依赖以随包 `package.json` 为准。
|
|
56
|
-
|
|
57
|
-
## 文档
|
|
58
|
-
|
|
59
|
-
[Agent 调用规范](skills/art-workshop/SKILL.md) · [文档规范](docs/documentation.md) · [art 命令参考](docs/commands.md) · [配置与存储](docs/configuration.md) · [风格核心职责与问题决策](docs/core-guidance.md) · [art 工程与输入结构](docs/data-formats.md) · [本地环境检测与部署](docs/deployment.md) · [模型与执行架构](docs/model-architecture.md) · [模式与调用流程](docs/modes.md) · [远程图片适配与筛选](docs/remote-models.md) · [任务控制与诊断](docs/troubleshooting.md)
|
|
60
|
-
|
|
61
|
-
## 许可与版权
|
|
62
|
-
|
|
63
|
-
本工具采用 [MIT 许可](LICENSE)。Copyright © 2026 Vant。Vant 为工具集品牌;Figma、Unity、Steam、微信及其组件归各自权利人所有,第三方组件适用各自许可。
|
|
1
|
+
# Vant 美术工坊
|
|
2
|
+
|
|
3
|
+
`@kevlns/art-workshop`
|
|
4
|
+
|
|
5
|
+
## 功能
|
|
6
|
+
|
|
7
|
+
管理项目风格、参考图、图片生成、编辑和定版。支持本地 ComfyUI 与远程图片模型。
|
|
8
|
+
|
|
9
|
+
## 环境要求
|
|
10
|
+
|
|
11
|
+
Node.js 20 及以上;本地生成还需工具检测通过的 Python、显卡驱动与 ComfyUI 环境。
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install -g @kevlns/art-workshop
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 快速开始
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
art-workshop config show
|
|
23
|
+
art-workshop config validate
|
|
24
|
+
art-workshop agent index
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 使用说明
|
|
28
|
+
|
|
29
|
+
### 使用流程
|
|
30
|
+
|
|
31
|
+
1. 创建 schemaVersion 2 工程和风格草稿,导入对象专属参考;分析预演后按授权运行,审阅报告并采用为冻结核心。
|
|
32
|
+
2. 用 `job template` 获取任务模板,填写实际需求后创建任务。动态参考先 `job analyze`;编辑底图单独绑定。
|
|
33
|
+
3. 编译 `generate plan` 或 `edit plan`,保存并用 `run --plan ... --dry` 核对模型、尺寸、候选数、输入和参数转换。
|
|
34
|
+
4. 按任务授权执行,保存 taskId;前台和后台都登记运行。查询原身份,不因超时或重启重复提交。
|
|
35
|
+
5. `check` 核验产物,`candidate finalize` 定版。替换需 `--replace`,删除需 `--confirm`,均保留事实记录。
|
|
36
|
+
|
|
37
|
+
正式风格只读,修改需派生。任务空闲后可按原身份更新配置,历史批次不覆写。job discard 归档任务,job restore 按当前版本恢复;配置、收藏与历史图片保留。任务列表默认按执行中、待定版、草稿、已定版排序;运行状态与停止证据分别判断,不能只看终态释放占用。
|
|
38
|
+
|
|
39
|
+
### 后端与数据归属
|
|
40
|
+
|
|
41
|
+
本地为 ComfyUI 内置 Qwen Image 2.1 Q4、CPU 文本编码器方案,支持生成和显式底图编辑。自定义 API workflow 需要明确 bindings 与完整适配,不能把任意导入工作流视为可执行。
|
|
42
|
+
|
|
43
|
+
远程图片通过工具登记的协议适配器直接调用,目前登记 DashScope。模型、参数与支持状态由 art 内部登记表维护,Vant 读取同一目录,不复制型号判断。分析使用独立视觉模型连接;未注入视觉连接时使用百炼 CLI。Token Plan 是渠道,DashScope 是协议,不能据协议擅自替换实例地址和凭据。
|
|
44
|
+
|
|
45
|
+
应用数据根默认 `~/.vant`,可由 `VANT_HOME` 覆盖。工具配置为 `~/.vant/tools/art-workshop/config.json`;Vant 将工程美术数据绑定至工程 `.vant/art`。共享模型环境默认 `~/.vant/art-env`,控制状态与日志归用户数据根;安装根保存环境标记 `vant.art.config.json`。
|
|
46
|
+
|
|
47
|
+
## 开发与验证
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
npm ci
|
|
51
|
+
npm run check
|
|
52
|
+
npm run test:package
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
命令返回、结构校验、模拟测试与外部平台实际运行分别核验。发布版本和依赖以随包 `package.json` 为准。
|
|
56
|
+
|
|
57
|
+
## 文档
|
|
58
|
+
|
|
59
|
+
[Agent 调用规范](skills/art-workshop/SKILL.md) · [文档规范](docs/documentation.md) · [art 命令参考](docs/commands.md) · [配置与存储](docs/configuration.md) · [风格核心职责与问题决策](docs/core-guidance.md) · [art 工程与输入结构](docs/data-formats.md) · [本地环境检测与部署](docs/deployment.md) · [模型与执行架构](docs/model-architecture.md) · [模式与调用流程](docs/modes.md) · [远程图片适配与筛选](docs/remote-models.md) · [任务控制与诊断](docs/troubleshooting.md)
|
|
60
|
+
|
|
61
|
+
## 许可与版权
|
|
62
|
+
|
|
63
|
+
本工具采用 [MIT 许可](LICENSE)。Copyright © 2026 Vant。Vant 为工具集品牌;Figma、Unity、Steam、微信及其组件归各自权利人所有,第三方组件适用各自许可。
|
package/art-workshop.mjs
CHANGED
|
@@ -1,174 +1,174 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {prepareRuntime} from './lib/environment-runtime.mjs';
|
|
3
|
-
import {readdirSync,existsSync} from 'node:fs';
|
|
4
|
-
import {join,resolve} from 'node:path';
|
|
5
|
-
import {readJson,writeJson} from './lib/shared.mjs';
|
|
6
|
-
const args=process.argv.slice(2),pos=[],options={};
|
|
7
|
-
if(args.length===1&&['--version','-V'].includes(args[0])){console.log(readJson(new URL('./package.json',import.meta.url)).version);process.exit(0);}
|
|
8
|
-
const help='art-workshop: config path/show/init/validate | doctor [--backend ID] [--start] | workflow list | environment guide/list/prepare/inspect/verify/register/unregister | refs guide | agent index/docs/export | conversation start/status/cancel/resume | list | style export/import/sources/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/restore/analyze | reference import/list/update/remove | candidate list/favorites/favorite/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 查看完整参数。';
|
|
9
|
-
if(!args.length||args.length===1&&['--help','-h','help'].includes(args[0])){console.log(help);process.exit(0);}
|
|
10
|
-
const {taskObjectView}=await import('./lib/asset-profile.mjs');
|
|
11
|
-
const {loadJob,loadProject}=await import('./lib/project.mjs');
|
|
12
|
-
const {referenceRoot,referenceGuide}=await import('./lib/refs.mjs');
|
|
13
|
-
const {loadSettings,initSettings,externalPath}=await import('./lib/settings.mjs');
|
|
14
|
-
const {validateReport,loadCore}=await import('./lib/core.mjs');
|
|
15
|
-
const {compileGenerate}=await import('./lib/generate.mjs');
|
|
16
|
-
const {compileEdit}=await import('./lib/edit.mjs');
|
|
17
|
-
const {validatePlan,selectItems}=await import('./lib/plan.mjs');
|
|
18
|
-
const {executePlan,checkRun}=await import('./lib/executor.mjs');
|
|
19
|
-
const {agentIndex,agentDocs,exportSkill}=await import('./lib/agent.mjs');
|
|
20
|
-
const {backendDefaults,bindBackend,buildComfyRequest}=await import('./lib/backends.mjs');
|
|
21
|
-
const {startTask,taskStatus,taskView,recoverTask,resumeTask,waitTask,cancelTask,shutdown}=await import('./lib/tasks.mjs');
|
|
22
|
-
const {runtimeRoot,tasks}=await import('./lib/runtime.mjs');
|
|
23
|
-
const {validateConfiguration,doctor}=await import('./lib/diagnostics.mjs');
|
|
24
|
-
const {finishMigration,createProject,createObject,listObjects,readObject,styleView,updateObject,deriveObject,discardObject,restoreTask,importReference,removeReference,updateReference,taskDisplayState,STYLE_CATEGORIES,TASK_PURPOSES}=await import('./lib/workspace.mjs');
|
|
25
|
-
const {startAnalysis,adoptStyle,recoverStyleAdoption,resolveStyleIssue,reviseStyleRules}=await import('./lib/style-lifecycle.mjs');
|
|
26
|
-
const {candidates,finalize,deleteCandidate,finalizations,editFromCandidate}=await import('./lib/candidates.mjs');
|
|
27
|
-
const {favoriteList,setFavorite}=await import('./lib/favorites.mjs');
|
|
28
|
-
const {upgradeProject}=await import('./lib/migration.mjs');
|
|
29
|
-
const {workflowList}=await import('./lib/workflows.mjs');
|
|
30
|
-
const {jobTemplate}=await import('./lib/templates.mjs');
|
|
31
|
-
const {deploymentGuide}=await import('./lib/deployment-guide.mjs');
|
|
32
|
-
const {inspectInstallation,discoverInstallations}=await import('./lib/environments.mjs');
|
|
33
|
-
const {verifyInstallation,registerInstallation,unregisterInstallation}=await import('./lib/environment-operations.mjs');
|
|
34
|
-
const flags=new Set(['dry','explore','background','start','replace','confirm','all-variants']);
|
|
35
|
-
const allowed=new Set(['config','workspace','output-dir','refs-dir','cache-dir','directory','host','session','request','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','value','name',...flags]);
|
|
36
|
-
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]);}
|
|
37
|
-
const print=x=>console.log(JSON.stringify(x?.schema==='art-workshop/style'?styleView(settings.paths.workspace,x):x,null,2));
|
|
38
|
-
if(pos[0]==='workflow'&&pos[1]==='list'){print(workflowList());process.exit(0);}
|
|
39
|
-
let settings;
|
|
40
|
-
try{settings=loadSettings({file:options.config?resolve(options.config):undefined,workspace:options.workspace,output:options['output-dir'],refs:options['refs-dir'],cache:options['cache-dir']});}
|
|
41
|
-
catch(error){print({ok:false,stage:'configuration',issues:[{code:'configuration',message:error.message}]});process.exit(1);}
|
|
42
|
-
if(pos[0]==='config'&&pos[1]==='validate'||pos[0]==='doctor'){
|
|
43
|
-
if(pos[0]==='doctor'&&pos[1])throw new Error('doctor 不接受位置参数');
|
|
44
|
-
const report=pos[0]==='doctor'?await doctor(settings,{backend:options.backend,start:options.start}):validateConfiguration(settings,{backend:options.backend});print(report);process.exitCode=report.ok?0:1;
|
|
45
|
-
}else{
|
|
46
|
-
if(options.start)throw new Error('--start 仅用于 doctor');
|
|
47
|
-
const ROOT=settings.paths.workspace;
|
|
48
|
-
const path=x=>externalPath(resolve(ROOT,x),'资源文件');
|
|
49
|
-
function required(k){const value=options[k]??(k==='project'?settings.defaultProject:undefined);if(!value) throw new Error('需要 --'+k);return value;}
|
|
50
|
-
function manifestPath(value){const p=externalPath(resolve(settings.paths.output,value));return p.endsWith('.json')?p:join(p,'manifest.json');}
|
|
51
|
-
try {
|
|
52
|
-
const [module,action]=pos;
|
|
53
|
-
|
|
54
|
-
const effectiveRefs=referenceRoot({defaultRefsDir:settings.paths.refs});
|
|
55
|
-
if(module==='conversation'){
|
|
56
|
-
const {startConversation,conversationStatus,controlConversation}=await import('./lib/conversation.mjs');
|
|
57
|
-
if(action==='start')print(await startConversation(readJson(path(required('input'))),settings));
|
|
58
|
-
else if(action==='status')print(await conversationStatus(settings,required('session'),required('request')));
|
|
59
|
-
else if(['cancel','resume','close'].includes(action))print(await controlConversation(settings,required('session'),required('request'),action));
|
|
60
|
-
else throw new Error('未知 conversation 操作');
|
|
61
|
-
}else if(module==='environment'){
|
|
62
|
-
if(action==='guide')print(deploymentGuide(options.guide));
|
|
63
|
-
else if(action==='list')print({environments:discoverInstallations()});
|
|
64
|
-
else if(action==='prepare')print(await prepareRuntime(required('directory'),{guideId:options.guide}));
|
|
65
|
-
else if(action==='inspect')print(await inspectInstallation(required('directory'),required('endpoint'),options.guide));
|
|
66
|
-
else if(action==='verify'){const result=await verifyInstallation(required('directory'),required('endpoint'),{guideId:options.guide});print(result);if(!result.ok)process.exitCode=1;}
|
|
67
|
-
else if(action==='register')print(await registerInstallation(required('directory'),required('endpoint'),{guideId:options.guide}));
|
|
68
|
-
else if(action==='unregister')print(await unregisterInstallation(required('directory')));
|
|
69
|
-
else throw new Error('未知 environment 操作');
|
|
70
|
-
}
|
|
71
|
-
else if(module==='config'){
|
|
72
|
-
if(action==='path') console.log(settings.file);
|
|
73
|
-
else if(action==='show') print(settings);
|
|
74
|
-
else if(action==='init') print(initSettings(settings.file));
|
|
75
|
-
else throw new Error('未知 config 操作');
|
|
76
|
-
}
|
|
77
|
-
else if(module==='project'){
|
|
78
|
-
if(action==='upgrade')print(await upgradeProject(ROOT,required('project'),{dry:options.dry,settings,referenceAssignments:options.mapping?readJson(path(options.mapping)):undefined}));
|
|
79
|
-
else if(action==='init')print(await createProject(settings,required('project'),readJson(path(required('input')))));
|
|
80
|
-
else throw new Error('未知 project 操作');
|
|
81
|
-
}
|
|
82
|
-
else if(module==='reference'){
|
|
83
|
-
const projectId=required('project'),kind=required('kind'),objectId=required('id');
|
|
84
|
-
if(action==='list')print(readObject(ROOT,projectId,kind,objectId).references);
|
|
85
|
-
else if(action==='import')print(await importReference(settings,projectId,kind,objectId,Number(required('revision')),{source:required('source'),category:options.category,purposes:options.purposes?.split(','),itemId:options['item-id'],note:options.note??''}));
|
|
86
|
-
else if(action==='remove')print(await removeReference(settings,projectId,kind,objectId,Number(required('revision')),required('item')));
|
|
87
|
-
else if(action==='update')print(await updateReference(settings,projectId,kind,objectId,Number(required('revision')),required('item'),readJson(path(required('input')))));
|
|
88
|
-
else throw new Error('未知 reference 操作');
|
|
89
|
-
}
|
|
90
|
-
else if(module==='job'||module==='style'&&['create','list','update','derive','discard','read','migration-complete'].includes(action)){
|
|
91
|
-
const projectId=required('project'),kind=module==='job'?'task':'style';
|
|
92
|
-
if(action==='migration-complete')print(await finishMigration(settings,projectId,kind,required('id'),Number(required('revision')),readJson(path(required('input')))));
|
|
93
|
-
else if(action==='template'&&kind==='task')print(jobTemplate(ROOT,projectId,{kind:options.kind,core:options.core}));
|
|
94
|
-
else if(action==='from-candidate'&&kind==='task')print(await editFromCandidate(settings,projectId,required('id'),{runId:required('run'),candidateId:required('candidate')}));
|
|
95
|
-
else if(action==='list'){const records=listObjects(ROOT,projectId,kind),runs=kind==='task'?tasks(runtimeRoot(settings)).map(t=>taskStatus(runtimeRoot(settings),t.taskId)):[];print(records.map(record=>kind==='task'?{...taskObjectView(ROOT,record),display:taskDisplayState(record,runs,record.finalizations??[])}:styleView(ROOT,record)));}
|
|
96
|
-
else if(action==='create')print(await createObject(settings,projectId,kind,readJson(path(required('input')))));
|
|
97
|
-
else if(action==='read'){const record=readObject(ROOT,projectId,kind,required('id'));print(kind==='style'?styleView(ROOT,record):taskObjectView(ROOT,record));}
|
|
98
|
-
else if(action==='update'){const record=await updateObject(settings,projectId,kind,required('id'),Number(required('revision')),readJson(path(required('input'))));print(kind==='style'?styleView(ROOT,record):taskObjectView(ROOT,record));}
|
|
99
|
-
else if(action==='analyze'&&kind==='task')print(await startAnalysis(settings,projectId,required('id'),Number(required('revision')),{dry:options.dry,kind:'task',operationId:options.operation}));
|
|
100
|
-
else if(action==='derive')print(await deriveObject(settings,projectId,kind,required('id'),Number(required('revision'))));
|
|
101
|
-
else if(action==='restore'&&kind==='task')print(await restoreTask(settings,projectId,required('id'),Number(required('revision'))));
|
|
102
|
-
else if(action==='discard')print(await discardObject(settings,projectId,kind,required('id'),Number(required('revision'))));
|
|
103
|
-
else throw new Error('未知对象操作');
|
|
104
|
-
}
|
|
105
|
-
else if(module==='refs'){
|
|
106
|
-
if(action!=='guide') throw new Error('未知 refs 操作;使用 refs guide');
|
|
107
|
-
console.log(referenceGuide(effectiveRefs));
|
|
108
|
-
}
|
|
109
|
-
else if(module==='agent'){
|
|
110
|
-
if(action==='index') print({...agentIndex(undefined,ROOT),config:settings.file,paths:settings.paths});
|
|
111
|
-
else if(action==='docs') console.log(agentDocs());
|
|
112
|
-
else if(action==='export') print(exportSkill({directory:required('directory'),host:required('host'),dry:options.dry}));
|
|
113
|
-
else throw new Error('未知 agent 操作');
|
|
114
|
-
}
|
|
115
|
-
else if(module==='list'){print((existsSync(join(ROOT,'projects'))?readdirSync(join(ROOT,'projects')):[]).map(id=>readJson(join(ROOT,'projects',id,'project.json'))));}
|
|
116
|
-
else if(module==='style'&&['export','import','sources'].includes(action)){
|
|
117
|
-
const bundle=await import('./lib/style-bundle.mjs');
|
|
118
|
-
if(action==='export')print(bundle.exportStyleBundle(ROOT,required('project'),required('id'),path(required('out'))));
|
|
119
|
-
else if(action==='import')print(await bundle.importStyleBundle(settings,required('project'),path(required('file'))));
|
|
120
|
-
else print(bundle.listStyleSources(readJson(path(required('input')))));
|
|
121
|
-
}
|
|
122
|
-
else if(module==='style'){
|
|
123
|
-
const projectId=required('project');
|
|
124
|
-
if(action==='analyze')print(await startAnalysis(settings,projectId,required('id'),Number(required('revision')),{dry:options.dry,operationId:options.operation}));
|
|
125
|
-
else if(action==='recover')print(await recoverStyleAdoption(settings,projectId,required('id')));
|
|
126
|
-
else if(action==='revise')print(styleView(ROOT,await reviseStyleRules(settings,projectId,required('id'),Number(required('revision')),readJson(path(required('input'))))));
|
|
127
|
-
else if(action==='resolve')print(styleView(ROOT,await resolveStyleIssue(settings,projectId,required('id'),Number(required('revision')),readJson(path(required('input'))))));
|
|
128
|
-
else if(action==='adopt')print(await adoptStyle(settings,projectId,required('id'),Number(required('revision')),{note:options.note}));
|
|
129
|
-
else if(action==='validate') print(validateReport(readJson(path(required('report'))),projectId));
|
|
130
|
-
else if(action==='show') print(loadCore(projectId,required('core'),ROOT));
|
|
131
|
-
else throw new Error('未知 style 操作');
|
|
132
|
-
}else if(['generate','edit'].includes(module)){
|
|
133
|
-
if(action==='show') print(loadJob(required('project'),required('job'),module,ROOT));
|
|
134
|
-
else if(['plan','run'].includes(action)){
|
|
135
|
-
let plan;
|
|
136
|
-
if(options.plan){if(action!=='run'||['project','job','core','explore','backend'].some(k=>options[k]!==undefined)) throw new Error('冻结计划不能同时调整来源;修改任务后重新 plan');plan=readJson(path(options.plan));validatePlan(plan);if(plan.module!==module) throw new Error('计划模块不匹配');}
|
|
137
|
-
else {const job=loadJob(required('project'),required('job'),module,ROOT),backend=options.backend??job.generation?.backend;plan=bindBackend((module==='generate'?compileGenerate:compileEdit)({projectId:required('project'),jobId:required('job'),coreId:options.core,root:ROOT,localExecution:backendDefaults(settings,backend)}),settings,backend);}
|
|
138
|
-
if(action==='plan'){if(options.out) writeJson(path(options.out),plan);print(plan);}
|
|
139
|
-
else {
|
|
140
|
-
if(options['retry-run']&&(options.dry||options.variant||options.item||options.offset||options.limit))throw new Error('失败项重试不能混用预演或手动筛选');
|
|
141
|
-
if(options.variant&&options['all-variants'])throw new Error('不能同时选择单个候选与全部候选');
|
|
142
|
-
const variant=options.variant??(options.explore||options['all-variants']?undefined:'base');const items=selectItems(plan,{item:options.item,variant,offset:options.offset===undefined?0:Number(options.offset),limit:options.limit===undefined?undefined:Number(options.limit)});
|
|
143
|
-
if(options.dry){if(plan.backend?.provider==='comfyui')print({dry:true,remoteCalls:0,planHash:plan.planHash,requests:items.map(item=>({itemId:item.itemId,variantId:item.variantId,requests:Array.from({length:(item.execution??plan.execution).perValue},(_,index)=>buildComfyRequest(plan,item,{index}))}))});else executePlan(plan,items,{outputRoot:settings.paths.output,dry:true});}
|
|
144
|
-
else {const task=await startTask(plan,items,settings,{operationId:options.operation,retryRun:options['retry-run']??null});if(options.background)print(task);else {console.log('task → '+task.taskId);const result=await waitTask(runtimeRoot(settings),task.taskId);print(taskView(result));if(result.status!=='succeeded')process.exitCode=1;}}
|
|
145
|
-
}
|
|
146
|
-
}else throw new Error('未知模块操作');
|
|
147
|
-
}else if(module==='task'){
|
|
148
|
-
const root=runtimeRoot(settings),taskId=pos[2];
|
|
149
|
-
if(action==='list')print(tasks(root).filter(t=>!options.project||(t.plan?.project??t.project)===options.project).map(t=>taskView(taskStatus(root,t.taskId))));
|
|
150
|
-
else if(action==='recover')print(recoverTask(root,required('project'),required('operation')));
|
|
151
|
-
else if(action==='status')print(taskView(taskStatus(root,taskId)));
|
|
152
|
-
else if(action==='resume')print(await resumeTask(root,taskId));
|
|
153
|
-
else if(action==='cancel')print(taskView(await cancelTask(root,taskId)));
|
|
154
|
-
else if(action==='wait'){const timeoutSeconds=options.timeout===undefined?3600:Number(options.timeout);if(!Number.isFinite(timeoutSeconds)||timeoutSeconds<=0)throw new Error('timeout 必须为正秒数');const result=await waitTask(root,taskId,{timeoutSeconds});print(taskView(result));if(result.status!=='succeeded')process.exitCode=1;}
|
|
155
|
-
else throw new Error('未知 task 操作');
|
|
156
|
-
}else if(module==='shutdown'){if(action)throw new Error('shutdown 不接受位置参数');print(await shutdown(settings));}
|
|
157
|
-
else if(module==='candidate'){
|
|
158
|
-
const projectId=required('project');
|
|
159
|
-
if(action==='favorites')print(favoriteList(settings,projectId));
|
|
160
|
-
else if(action==='favorite'){
|
|
161
|
-
if(!['true','false'].includes(options.value))throw new Error('value 必须为 true 或 false');
|
|
162
|
-
print(await setFavorite(settings,projectId,required('job'),{runId:required('run'),candidateId:required('candidate'),value:options.value==='true'}));
|
|
163
|
-
}
|
|
164
|
-
else if(action==='list')print(candidates(settings,projectId,required('job'),required('run')));
|
|
165
|
-
else if(action==='finalize')print(await finalize(settings,projectId,required('job'),Number(required('revision')),{runId:required('run'),candidateId:required('candidate'),replace:options.replace,actor:required('actor'),name:options.name}));
|
|
166
|
-
else if(action==='delete')print(await deleteCandidate(settings,projectId,required('job'),Number(required('revision')),{runId:required('run'),candidateId:required('candidate'),confirm:options.confirm,actor:required('actor')}));
|
|
167
|
-
else if(action==='finalizations')print(finalizations(settings,projectId,required('job')));
|
|
168
|
-
else throw new Error('未知 candidate 操作');
|
|
169
|
-
}else if(module==='check'){print(checkRun(readJson(manifestPath(action??required('file'))),manifestPath(action??required('file'))));
|
|
170
|
-
}else if(module==='compare'){const read=value=>{const data=readJson(path(value));const plan=data.plan??data;validatePlan(plan);return plan;};const a=read(action),b=read(pos[2]);print({sameCore:a.sources.coreHash===b.sources.coreHash,execution:{before:a.execution,after:b.execution},items:b.items.map(x=>({itemId:x.itemId,variantId:x.variantId,changed:a.items.find(y=>y.itemId===x.itemId&&y.variantId===x.variantId)?.inputHash!==x.inputHash}))});}
|
|
171
|
-
else if(!module||module==='help') console.log(help);
|
|
172
|
-
else throw new Error('未知模块或旧入口:'+module);
|
|
173
|
-
}catch(e){print({ok:false,error:e.message,...(e.diagnostic?{diagnostic:e.diagnostic}:{})});process.exitCode=1;}
|
|
174
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {prepareRuntime} from './lib/environment-runtime.mjs';
|
|
3
|
+
import {readdirSync,existsSync} from 'node:fs';
|
|
4
|
+
import {join,resolve} from 'node:path';
|
|
5
|
+
import {readJson,writeJson} from './lib/shared.mjs';
|
|
6
|
+
const args=process.argv.slice(2),pos=[],options={};
|
|
7
|
+
if(args.length===1&&['--version','-V'].includes(args[0])){console.log(readJson(new URL('./package.json',import.meta.url)).version);process.exit(0);}
|
|
8
|
+
const help='art-workshop: config path/show/init/validate | doctor [--backend ID] [--start] | workflow list | environment guide/list/prepare/inspect/verify/register/unregister | refs guide | agent index/docs/export | conversation start/status/cancel/resume | list | style export/import/sources/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/restore/analyze | reference import/list/update/remove | candidate list/favorites/favorite/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 查看完整参数。';
|
|
9
|
+
if(!args.length||args.length===1&&['--help','-h','help'].includes(args[0])){console.log(help);process.exit(0);}
|
|
10
|
+
const {taskObjectView}=await import('./lib/asset-profile.mjs');
|
|
11
|
+
const {loadJob,loadProject}=await import('./lib/project.mjs');
|
|
12
|
+
const {referenceRoot,referenceGuide}=await import('./lib/refs.mjs');
|
|
13
|
+
const {loadSettings,initSettings,externalPath}=await import('./lib/settings.mjs');
|
|
14
|
+
const {validateReport,loadCore}=await import('./lib/core.mjs');
|
|
15
|
+
const {compileGenerate}=await import('./lib/generate.mjs');
|
|
16
|
+
const {compileEdit}=await import('./lib/edit.mjs');
|
|
17
|
+
const {validatePlan,selectItems}=await import('./lib/plan.mjs');
|
|
18
|
+
const {executePlan,checkRun}=await import('./lib/executor.mjs');
|
|
19
|
+
const {agentIndex,agentDocs,exportSkill}=await import('./lib/agent.mjs');
|
|
20
|
+
const {backendDefaults,bindBackend,buildComfyRequest}=await import('./lib/backends.mjs');
|
|
21
|
+
const {startTask,taskStatus,taskView,recoverTask,resumeTask,waitTask,cancelTask,shutdown}=await import('./lib/tasks.mjs');
|
|
22
|
+
const {runtimeRoot,tasks}=await import('./lib/runtime.mjs');
|
|
23
|
+
const {validateConfiguration,doctor}=await import('./lib/diagnostics.mjs');
|
|
24
|
+
const {finishMigration,createProject,createObject,listObjects,readObject,styleView,updateObject,deriveObject,discardObject,restoreTask,importReference,removeReference,updateReference,taskDisplayState,STYLE_CATEGORIES,TASK_PURPOSES}=await import('./lib/workspace.mjs');
|
|
25
|
+
const {startAnalysis,adoptStyle,recoverStyleAdoption,resolveStyleIssue,reviseStyleRules}=await import('./lib/style-lifecycle.mjs');
|
|
26
|
+
const {candidates,finalize,deleteCandidate,finalizations,editFromCandidate}=await import('./lib/candidates.mjs');
|
|
27
|
+
const {favoriteList,setFavorite}=await import('./lib/favorites.mjs');
|
|
28
|
+
const {upgradeProject}=await import('./lib/migration.mjs');
|
|
29
|
+
const {workflowList}=await import('./lib/workflows.mjs');
|
|
30
|
+
const {jobTemplate}=await import('./lib/templates.mjs');
|
|
31
|
+
const {deploymentGuide}=await import('./lib/deployment-guide.mjs');
|
|
32
|
+
const {inspectInstallation,discoverInstallations}=await import('./lib/environments.mjs');
|
|
33
|
+
const {verifyInstallation,registerInstallation,unregisterInstallation}=await import('./lib/environment-operations.mjs');
|
|
34
|
+
const flags=new Set(['dry','explore','background','start','replace','confirm','all-variants']);
|
|
35
|
+
const allowed=new Set(['config','workspace','output-dir','refs-dir','cache-dir','directory','host','session','request','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','value','name',...flags]);
|
|
36
|
+
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]);}
|
|
37
|
+
const print=x=>console.log(JSON.stringify(x?.schema==='art-workshop/style'?styleView(settings.paths.workspace,x):x,null,2));
|
|
38
|
+
if(pos[0]==='workflow'&&pos[1]==='list'){print(workflowList());process.exit(0);}
|
|
39
|
+
let settings;
|
|
40
|
+
try{settings=loadSettings({file:options.config?resolve(options.config):undefined,workspace:options.workspace,output:options['output-dir'],refs:options['refs-dir'],cache:options['cache-dir']});}
|
|
41
|
+
catch(error){print({ok:false,stage:'configuration',issues:[{code:'configuration',message:error.message}]});process.exit(1);}
|
|
42
|
+
if(pos[0]==='config'&&pos[1]==='validate'||pos[0]==='doctor'){
|
|
43
|
+
if(pos[0]==='doctor'&&pos[1])throw new Error('doctor 不接受位置参数');
|
|
44
|
+
const report=pos[0]==='doctor'?await doctor(settings,{backend:options.backend,start:options.start}):validateConfiguration(settings,{backend:options.backend});print(report);process.exitCode=report.ok?0:1;
|
|
45
|
+
}else{
|
|
46
|
+
if(options.start)throw new Error('--start 仅用于 doctor');
|
|
47
|
+
const ROOT=settings.paths.workspace;
|
|
48
|
+
const path=x=>externalPath(resolve(ROOT,x),'资源文件');
|
|
49
|
+
function required(k){const value=options[k]??(k==='project'?settings.defaultProject:undefined);if(!value) throw new Error('需要 --'+k);return value;}
|
|
50
|
+
function manifestPath(value){const p=externalPath(resolve(settings.paths.output,value));return p.endsWith('.json')?p:join(p,'manifest.json');}
|
|
51
|
+
try {
|
|
52
|
+
const [module,action]=pos;
|
|
53
|
+
|
|
54
|
+
const effectiveRefs=referenceRoot({defaultRefsDir:settings.paths.refs});
|
|
55
|
+
if(module==='conversation'){
|
|
56
|
+
const {startConversation,conversationStatus,controlConversation}=await import('./lib/conversation.mjs');
|
|
57
|
+
if(action==='start')print(await startConversation(readJson(path(required('input'))),settings));
|
|
58
|
+
else if(action==='status')print(await conversationStatus(settings,required('session'),required('request')));
|
|
59
|
+
else if(['cancel','resume','close'].includes(action))print(await controlConversation(settings,required('session'),required('request'),action));
|
|
60
|
+
else throw new Error('未知 conversation 操作');
|
|
61
|
+
}else if(module==='environment'){
|
|
62
|
+
if(action==='guide')print(deploymentGuide(options.guide));
|
|
63
|
+
else if(action==='list')print({environments:discoverInstallations()});
|
|
64
|
+
else if(action==='prepare')print(await prepareRuntime(required('directory'),{guideId:options.guide}));
|
|
65
|
+
else if(action==='inspect')print(await inspectInstallation(required('directory'),required('endpoint'),options.guide));
|
|
66
|
+
else if(action==='verify'){const result=await verifyInstallation(required('directory'),required('endpoint'),{guideId:options.guide});print(result);if(!result.ok)process.exitCode=1;}
|
|
67
|
+
else if(action==='register')print(await registerInstallation(required('directory'),required('endpoint'),{guideId:options.guide}));
|
|
68
|
+
else if(action==='unregister')print(await unregisterInstallation(required('directory')));
|
|
69
|
+
else throw new Error('未知 environment 操作');
|
|
70
|
+
}
|
|
71
|
+
else if(module==='config'){
|
|
72
|
+
if(action==='path') console.log(settings.file);
|
|
73
|
+
else if(action==='show') print(settings);
|
|
74
|
+
else if(action==='init') print(initSettings(settings.file));
|
|
75
|
+
else throw new Error('未知 config 操作');
|
|
76
|
+
}
|
|
77
|
+
else if(module==='project'){
|
|
78
|
+
if(action==='upgrade')print(await upgradeProject(ROOT,required('project'),{dry:options.dry,settings,referenceAssignments:options.mapping?readJson(path(options.mapping)):undefined}));
|
|
79
|
+
else if(action==='init')print(await createProject(settings,required('project'),readJson(path(required('input')))));
|
|
80
|
+
else throw new Error('未知 project 操作');
|
|
81
|
+
}
|
|
82
|
+
else if(module==='reference'){
|
|
83
|
+
const projectId=required('project'),kind=required('kind'),objectId=required('id');
|
|
84
|
+
if(action==='list')print(readObject(ROOT,projectId,kind,objectId).references);
|
|
85
|
+
else if(action==='import')print(await importReference(settings,projectId,kind,objectId,Number(required('revision')),{source:required('source'),category:options.category,purposes:options.purposes?.split(','),itemId:options['item-id'],note:options.note??''}));
|
|
86
|
+
else if(action==='remove')print(await removeReference(settings,projectId,kind,objectId,Number(required('revision')),required('item')));
|
|
87
|
+
else if(action==='update')print(await updateReference(settings,projectId,kind,objectId,Number(required('revision')),required('item'),readJson(path(required('input')))));
|
|
88
|
+
else throw new Error('未知 reference 操作');
|
|
89
|
+
}
|
|
90
|
+
else if(module==='job'||module==='style'&&['create','list','update','derive','discard','read','migration-complete'].includes(action)){
|
|
91
|
+
const projectId=required('project'),kind=module==='job'?'task':'style';
|
|
92
|
+
if(action==='migration-complete')print(await finishMigration(settings,projectId,kind,required('id'),Number(required('revision')),readJson(path(required('input')))));
|
|
93
|
+
else if(action==='template'&&kind==='task')print(jobTemplate(ROOT,projectId,{kind:options.kind,core:options.core}));
|
|
94
|
+
else if(action==='from-candidate'&&kind==='task')print(await editFromCandidate(settings,projectId,required('id'),{runId:required('run'),candidateId:required('candidate')}));
|
|
95
|
+
else if(action==='list'){const records=listObjects(ROOT,projectId,kind),runs=kind==='task'?tasks(runtimeRoot(settings)).map(t=>taskStatus(runtimeRoot(settings),t.taskId)):[];print(records.map(record=>kind==='task'?{...taskObjectView(ROOT,record),display:taskDisplayState(record,runs,record.finalizations??[])}:styleView(ROOT,record)));}
|
|
96
|
+
else if(action==='create')print(await createObject(settings,projectId,kind,readJson(path(required('input')))));
|
|
97
|
+
else if(action==='read'){const record=readObject(ROOT,projectId,kind,required('id'));print(kind==='style'?styleView(ROOT,record):taskObjectView(ROOT,record));}
|
|
98
|
+
else if(action==='update'){const record=await updateObject(settings,projectId,kind,required('id'),Number(required('revision')),readJson(path(required('input'))));print(kind==='style'?styleView(ROOT,record):taskObjectView(ROOT,record));}
|
|
99
|
+
else if(action==='analyze'&&kind==='task')print(await startAnalysis(settings,projectId,required('id'),Number(required('revision')),{dry:options.dry,kind:'task',operationId:options.operation}));
|
|
100
|
+
else if(action==='derive')print(await deriveObject(settings,projectId,kind,required('id'),Number(required('revision'))));
|
|
101
|
+
else if(action==='restore'&&kind==='task')print(await restoreTask(settings,projectId,required('id'),Number(required('revision'))));
|
|
102
|
+
else if(action==='discard')print(await discardObject(settings,projectId,kind,required('id'),Number(required('revision'))));
|
|
103
|
+
else throw new Error('未知对象操作');
|
|
104
|
+
}
|
|
105
|
+
else if(module==='refs'){
|
|
106
|
+
if(action!=='guide') throw new Error('未知 refs 操作;使用 refs guide');
|
|
107
|
+
console.log(referenceGuide(effectiveRefs));
|
|
108
|
+
}
|
|
109
|
+
else if(module==='agent'){
|
|
110
|
+
if(action==='index') print({...agentIndex(undefined,ROOT),config:settings.file,paths:settings.paths});
|
|
111
|
+
else if(action==='docs') console.log(agentDocs());
|
|
112
|
+
else if(action==='export') print(exportSkill({directory:required('directory'),host:required('host'),dry:options.dry}));
|
|
113
|
+
else throw new Error('未知 agent 操作');
|
|
114
|
+
}
|
|
115
|
+
else if(module==='list'){print((existsSync(join(ROOT,'projects'))?readdirSync(join(ROOT,'projects')):[]).map(id=>readJson(join(ROOT,'projects',id,'project.json'))));}
|
|
116
|
+
else if(module==='style'&&['export','import','sources'].includes(action)){
|
|
117
|
+
const bundle=await import('./lib/style-bundle.mjs');
|
|
118
|
+
if(action==='export')print(bundle.exportStyleBundle(ROOT,required('project'),required('id'),path(required('out'))));
|
|
119
|
+
else if(action==='import')print(await bundle.importStyleBundle(settings,required('project'),path(required('file'))));
|
|
120
|
+
else print(bundle.listStyleSources(readJson(path(required('input')))));
|
|
121
|
+
}
|
|
122
|
+
else if(module==='style'){
|
|
123
|
+
const projectId=required('project');
|
|
124
|
+
if(action==='analyze')print(await startAnalysis(settings,projectId,required('id'),Number(required('revision')),{dry:options.dry,operationId:options.operation}));
|
|
125
|
+
else if(action==='recover')print(await recoverStyleAdoption(settings,projectId,required('id')));
|
|
126
|
+
else if(action==='revise')print(styleView(ROOT,await reviseStyleRules(settings,projectId,required('id'),Number(required('revision')),readJson(path(required('input'))))));
|
|
127
|
+
else if(action==='resolve')print(styleView(ROOT,await resolveStyleIssue(settings,projectId,required('id'),Number(required('revision')),readJson(path(required('input'))))));
|
|
128
|
+
else if(action==='adopt')print(await adoptStyle(settings,projectId,required('id'),Number(required('revision')),{note:options.note}));
|
|
129
|
+
else if(action==='validate') print(validateReport(readJson(path(required('report'))),projectId));
|
|
130
|
+
else if(action==='show') print(loadCore(projectId,required('core'),ROOT));
|
|
131
|
+
else throw new Error('未知 style 操作');
|
|
132
|
+
}else if(['generate','edit'].includes(module)){
|
|
133
|
+
if(action==='show') print(loadJob(required('project'),required('job'),module,ROOT));
|
|
134
|
+
else if(['plan','run'].includes(action)){
|
|
135
|
+
let plan;
|
|
136
|
+
if(options.plan){if(action!=='run'||['project','job','core','explore','backend'].some(k=>options[k]!==undefined)) throw new Error('冻结计划不能同时调整来源;修改任务后重新 plan');plan=readJson(path(options.plan));validatePlan(plan);if(plan.module!==module) throw new Error('计划模块不匹配');}
|
|
137
|
+
else {const job=loadJob(required('project'),required('job'),module,ROOT),backend=options.backend??job.generation?.backend;plan=bindBackend((module==='generate'?compileGenerate:compileEdit)({projectId:required('project'),jobId:required('job'),coreId:options.core,root:ROOT,localExecution:backendDefaults(settings,backend)}),settings,backend);}
|
|
138
|
+
if(action==='plan'){if(options.out) writeJson(path(options.out),plan);print(plan);}
|
|
139
|
+
else {
|
|
140
|
+
if(options['retry-run']&&(options.dry||options.variant||options.item||options.offset||options.limit))throw new Error('失败项重试不能混用预演或手动筛选');
|
|
141
|
+
if(options.variant&&options['all-variants'])throw new Error('不能同时选择单个候选与全部候选');
|
|
142
|
+
const variant=options.variant??(options.explore||options['all-variants']?undefined:'base');const items=selectItems(plan,{item:options.item,variant,offset:options.offset===undefined?0:Number(options.offset),limit:options.limit===undefined?undefined:Number(options.limit)});
|
|
143
|
+
if(options.dry){if(plan.backend?.provider==='comfyui')print({dry:true,remoteCalls:0,planHash:plan.planHash,requests:items.map(item=>({itemId:item.itemId,variantId:item.variantId,requests:Array.from({length:(item.execution??plan.execution).perValue},(_,index)=>buildComfyRequest(plan,item,{index}))}))});else executePlan(plan,items,{outputRoot:settings.paths.output,dry:true});}
|
|
144
|
+
else {const task=await startTask(plan,items,settings,{operationId:options.operation,retryRun:options['retry-run']??null});if(options.background)print(task);else {console.log('task → '+task.taskId);const result=await waitTask(runtimeRoot(settings),task.taskId);print(taskView(result));if(result.status!=='succeeded')process.exitCode=1;}}
|
|
145
|
+
}
|
|
146
|
+
}else throw new Error('未知模块操作');
|
|
147
|
+
}else if(module==='task'){
|
|
148
|
+
const root=runtimeRoot(settings),taskId=pos[2];
|
|
149
|
+
if(action==='list')print(tasks(root).filter(t=>!options.project||(t.plan?.project??t.project)===options.project).map(t=>taskView(taskStatus(root,t.taskId))));
|
|
150
|
+
else if(action==='recover')print(recoverTask(root,required('project'),required('operation')));
|
|
151
|
+
else if(action==='status')print(taskView(taskStatus(root,taskId)));
|
|
152
|
+
else if(action==='resume')print(await resumeTask(root,taskId));
|
|
153
|
+
else if(action==='cancel')print(taskView(await cancelTask(root,taskId)));
|
|
154
|
+
else if(action==='wait'){const timeoutSeconds=options.timeout===undefined?3600:Number(options.timeout);if(!Number.isFinite(timeoutSeconds)||timeoutSeconds<=0)throw new Error('timeout 必须为正秒数');const result=await waitTask(root,taskId,{timeoutSeconds});print(taskView(result));if(result.status!=='succeeded')process.exitCode=1;}
|
|
155
|
+
else throw new Error('未知 task 操作');
|
|
156
|
+
}else if(module==='shutdown'){if(action)throw new Error('shutdown 不接受位置参数');print(await shutdown(settings));}
|
|
157
|
+
else if(module==='candidate'){
|
|
158
|
+
const projectId=required('project');
|
|
159
|
+
if(action==='favorites')print(favoriteList(settings,projectId));
|
|
160
|
+
else if(action==='favorite'){
|
|
161
|
+
if(!['true','false'].includes(options.value))throw new Error('value 必须为 true 或 false');
|
|
162
|
+
print(await setFavorite(settings,projectId,required('job'),{runId:required('run'),candidateId:required('candidate'),value:options.value==='true'}));
|
|
163
|
+
}
|
|
164
|
+
else if(action==='list')print(candidates(settings,projectId,required('job'),required('run')));
|
|
165
|
+
else if(action==='finalize')print(await finalize(settings,projectId,required('job'),Number(required('revision')),{runId:required('run'),candidateId:required('candidate'),replace:options.replace,actor:required('actor'),name:options.name}));
|
|
166
|
+
else if(action==='delete')print(await deleteCandidate(settings,projectId,required('job'),Number(required('revision')),{runId:required('run'),candidateId:required('candidate'),confirm:options.confirm,actor:required('actor')}));
|
|
167
|
+
else if(action==='finalizations')print(finalizations(settings,projectId,required('job')));
|
|
168
|
+
else throw new Error('未知 candidate 操作');
|
|
169
|
+
}else if(module==='check'){print(checkRun(readJson(manifestPath(action??required('file'))),manifestPath(action??required('file'))));
|
|
170
|
+
}else if(module==='compare'){const read=value=>{const data=readJson(path(value));const plan=data.plan??data;validatePlan(plan);return plan;};const a=read(action),b=read(pos[2]);print({sameCore:a.sources.coreHash===b.sources.coreHash,execution:{before:a.execution,after:b.execution},items:b.items.map(x=>({itemId:x.itemId,variantId:x.variantId,changed:a.items.find(y=>y.itemId===x.itemId&&y.variantId===x.variantId)?.inputHash!==x.inputHash}))});}
|
|
171
|
+
else if(!module||module==='help') console.log(help);
|
|
172
|
+
else throw new Error('未知模块或旧入口:'+module);
|
|
173
|
+
}catch(e){print({ok:false,error:e.message,...(e.diagnostic?{diagnostic:e.diagnostic}:{})});process.exitCode=1;}
|
|
174
|
+
}
|