@kevlns/art-workshop 0.1.2 → 0.1.3
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 +2 -0
- package/README.md +20 -1
- package/lib/design.mjs +29 -0
- package/lib/executor.mjs +10 -6
- package/lib/generate.mjs +6 -4
- package/lib/plan.mjs +6 -3
- package/lib/presentation.mjs +2 -2
- package/package.json +1 -1
- package/skills/art-workshop/SKILL.md +19 -0
package/AGENTS.md
CHANGED
|
@@ -15,3 +15,5 @@
|
|
|
15
15
|
本地配置位于用户配置目录,可用 config path/show/init 发现;冻结核心在 workspace/projects/工程/cores。工程、参考、报告、计划、缓存、原图和产物都在安装目录之外,不纳入工具 Git 或 npm 包。相对资源按 workspace 解析,参考图按 refs 解析,RUN 按 output 解析。每次配置生效会补齐 refs 分类目录,包括 dry,不覆盖素材。
|
|
16
16
|
|
|
17
17
|
随包 skills/art-workshop 是使用规范源,agent init --directory DIR 同步到已有 Agent 技能目录,保留扩展文件;自动同步也可用 npm run skill:sync。v-cli 负责路由、清单与本指导发现,美术工坊负责实际任务、核心选择与模型请求。安装 v-cli 会安装此官方依赖。
|
|
18
|
+
|
|
19
|
+
UI 尺寸:文生图 profile.design 声明 resolution 与 outputScale,item.design 声明控件 width/height 与可选 outputScale。单体实际出图尺寸为设计尺寸乘倍率;不能同时指定任务 execution.size。换算越界报错,不自动改变比例;完整约束见 agent docs。
|
package/README.md
CHANGED
|
@@ -124,8 +124,27 @@ node art-workshop.mjs compare .cache/plan-a.json .cache/plan-b.json
|
|
|
124
124
|
node --test tests/art-workshop.test.mjs
|
|
125
125
|
```
|
|
126
126
|
|
|
127
|
-
依赖 Node.js 与已配置的 bailian-cli。历史图片保留供对照,旧配置和旧计划接口不再支持。真实模型效果需另行实测。
|
|
127
|
+
依赖 Node.js 与已配置的 bailian-cli。历史图片保留供对照,旧配置和旧计划接口不再支持。真实模型效果需另行实测。
|
|
128
128
|
|
|
129
129
|
## v-cli 接入
|
|
130
130
|
|
|
131
131
|
美术工坊是 v-cli 的随包官方插件,入口为 `v-cli art`。先运行 `v-cli agent docs art` 和 `v-cli agent describe art --json`,再运行 `v-cli art config show`、`v-cli art agent index` 选择正确工程。本文所有 `art-workshop` 命令都可将前缀替换为 `v-cli art`;参数、外部本地配置和冻结核心保持一致。`v-cli art --help` 查看入口,`v-cli art agent docs` 查看完整使用规范。
|
|
132
|
+
## UI 设计分辨率与单体出图尺寸
|
|
133
|
+
|
|
134
|
+
UI 设计基准属于资产规格,不写进冻结风格核心。文生图 profile 可声明:
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
"design": { "resolution": { "width": 1920, "height": 1080 }, "outputScale": 2 }
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
任务 item 可声明独立控件尺寸与可选倍率:
|
|
141
|
+
|
|
142
|
+
```json
|
|
143
|
+
"design": { "width": 240, "height": 80, "outputScale": 4 }
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
该按钮实际请求 size 为 960*320。同一任务的其他控件可使用不同设计尺寸;单体没有 design 时按 profile 的整幅设计分辨率出图。未覆盖倍率时继承 profile.outputScale。倍率为 1~4 的整数,设计尺寸为正整数且不得超过基准分辨率;换算后的每条边必须在工具支持的 256~4096 像素范围内,越界报错,不自动拉伸、补边或更改倍率。模型可能有额外尺寸与比例限制,工具的通用范围不等于模型能力保证。
|
|
147
|
+
|
|
148
|
+
启用设计尺寸时禁止同时设置任务 execution.size;工程和本地 execution.size 默认值被单体换算尺寸替代,模型等其他执行参数保留既有优先级。旧任务不声明 design 时保持原有行为。设计模式的提示词不再附加整体占画幅 75% 等比例要求,而声明设计宽高比和安全留白。
|
|
149
|
+
|
|
150
|
+
编译计划的每项包含 design(resolution、size、outputScale、outputSize)与实际 execution。预演、真实请求、输入哈希与执行验收使用同一份单体参数。修改设计尺寸后必须重新 plan。此配置控制请求画布,不保证模型精确绘制控件边界、描边或圆角像素,也不自动生成九宫切片、裁切或透明底资源。
|
package/lib/design.mjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { keys, integer } from './shared.mjs';
|
|
2
|
+
|
|
3
|
+
// 设计基准归资产规格,单体尺寸与倍率归任务;出图尺寸由它们确定。
|
|
4
|
+
export function design(profile, override, explicitExecution = {}) {
|
|
5
|
+
if (profile.design === undefined) {
|
|
6
|
+
if (override !== undefined) throw new Error('单体 design 需要资产规格声明 design');
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const base = profile.design;
|
|
10
|
+
keys(base, ['resolution', 'outputScale'], 'profile.design');
|
|
11
|
+
keys(base.resolution, ['width', 'height'], 'design.resolution');
|
|
12
|
+
integer(base.resolution.width, 'design.resolution.width', 1, 16384);
|
|
13
|
+
integer(base.resolution.height, 'design.resolution.height', 1, 16384);
|
|
14
|
+
integer(base.outputScale, 'design.outputScale', 1, 4);
|
|
15
|
+
if (override !== undefined) keys(override, ['width', 'height', 'outputScale'], 'item.design');
|
|
16
|
+
const size = override === undefined ? base.resolution : override;
|
|
17
|
+
integer(size.width, 'design.width', 1, base.resolution.width);
|
|
18
|
+
integer(size.height, 'design.height', 1, base.resolution.height);
|
|
19
|
+
const outputScale = override?.outputScale ?? base.outputScale;
|
|
20
|
+
integer(outputScale, 'design.outputScale', 1, 4);
|
|
21
|
+
if (explicitExecution.size !== undefined) throw new Error('设计尺寸与任务 execution.size 不能同时指定');
|
|
22
|
+
const outputSize = { width: size.width * outputScale, height: size.height * outputScale };
|
|
23
|
+
for (const axis of ['width', 'height']) integer(outputSize[axis], `设计换算出图 ${axis}`, 256, 4096);
|
|
24
|
+
return { resolution: { ...base.resolution }, size: { width: size.width, height: size.height }, outputScale, outputSize };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function designPrompt(value) {
|
|
28
|
+
return `UI 设计基准 ${value.resolution.width}×${value.resolution.height};本单体设计尺寸 ${value.size.width}×${value.size.height};出图倍率 ${value.outputScale},画布 ${value.outputSize.width}×${value.outputSize.height} 像素。保持设计宽高比,完整展示并在画布内居中;描边、圆角与细节随同一倍率缩放。`;
|
|
29
|
+
}
|
package/lib/executor.mjs
CHANGED
|
@@ -15,11 +15,14 @@ function runtimeVersion() {
|
|
|
15
15
|
export function executePlan(plan, items, { outputRoot=loadSettings().paths.output, dry = false, runner = runBl, log = console.log } = {}) {
|
|
16
16
|
validatePlan(plan);
|
|
17
17
|
if (!items.length) throw new Error('没有选中任何计划项');
|
|
18
|
-
for (const item of items)
|
|
18
|
+
for (const item of items) {
|
|
19
|
+
const expected = plan.items.find(x => x.inputHash === item.inputHash);
|
|
20
|
+
if (!expected || hash(item) !== hash(expected)) throw new Error('执行项不属于该计划或内容已改变');
|
|
21
|
+
}
|
|
19
22
|
for (const ref of plan.refs) { externalPath(ref.path,'原图/参考图'); if (!existsSync(ref.path) || sha256File(ref.path) !== ref.hash) throw new Error(`参考图已变化:${ref.path}`); }
|
|
20
23
|
externalPath(outputRoot,'输出目录');
|
|
21
24
|
if (dry) {
|
|
22
|
-
const requests = items.map(item => ({ itemId: item.itemId, variantId: item.variantId, seed: item.seed,
|
|
25
|
+
const requests = items.map(item => ({ ...(item.design?{design:item.design,execution:item.execution}:{}),itemId: item.itemId, variantId: item.variantId, seed: item.seed,
|
|
23
26
|
inputHash: item.inputHash, args: buildArgs(plan, item, join(outputRoot,'<runId>'), `${item.itemId}--${item.variantId}`) }));
|
|
24
27
|
log(JSON.stringify({ dry: true, remoteCalls: 0, planHash: plan.planHash, requests }, null, 2));
|
|
25
28
|
return { dry: true, requests };
|
|
@@ -39,7 +42,7 @@ export function executePlan(plan, items, { outputRoot=loadSettings().paths.outpu
|
|
|
39
42
|
for (const item of items) {
|
|
40
43
|
const prefix = `${item.itemId}--${item.variantId}`;
|
|
41
44
|
const args = buildArgs(plan, item, runDir, prefix);
|
|
42
|
-
const record = { ...item, args, ok: false, status: 'running', files: [], urls: [], outputHashes: {} };
|
|
45
|
+
const record = { ...structuredClone(item), args, ok: false, status: 'running', files: [], urls: [], outputHashes: {} };
|
|
43
46
|
manifest.items.push(record); persist();
|
|
44
47
|
const before = new Set(readdirSync(runDir));
|
|
45
48
|
try {
|
|
@@ -54,7 +57,8 @@ export function executePlan(plan, items, { outputRoot=loadSettings().paths.outpu
|
|
|
54
57
|
record.files.push(target); record.outputHashes[target] = sha256File(join(runDir, target));
|
|
55
58
|
});
|
|
56
59
|
record.urls = response.urls ?? [];
|
|
57
|
-
|
|
60
|
+
const expectedCount = (item.execution??plan.execution).perValue;
|
|
61
|
+
if (record.files.length !== expectedCount) throw new Error(`期望 ${expectedCount} 张,实际 ${record.files.length} 张`);
|
|
58
62
|
record.ok = true; record.status = 'generated';
|
|
59
63
|
log(`✔ ${item.itemId}/${item.variantId} seed=${item.seed} → ${record.files.join(', ')}`);
|
|
60
64
|
} catch (e) {
|
|
@@ -81,8 +85,8 @@ export function checkRun(manifest, manifestPath, review = manifest.review ?? [])
|
|
|
81
85
|
for (const item of manifest.items) {
|
|
82
86
|
const expected = manifest.plan.items.find(x => x.itemId === item.itemId && x.variantId === item.variantId);
|
|
83
87
|
if (!expected || expected.inputHash !== item.inputHash) throw new Error('执行记录不属于原始计划');
|
|
84
|
-
for (const key of ['prompt', 'seed', 'checks', 'negativeBlock', 'imageArgs']) {
|
|
85
|
-
if (hash(item[key]) !== hash(expected[key])) throw new Error(`执行记录已改变:${item.itemId}.${key}`);
|
|
88
|
+
for (const key of ['prompt', 'seed', 'checks', 'negativeBlock', 'imageArgs', 'execution', 'design']) {
|
|
89
|
+
if (hash({value:item[key]}) !== hash({value:expected[key]})) throw new Error(`执行记录已改变:${item.itemId}.${key}`);
|
|
86
90
|
}
|
|
87
91
|
}
|
|
88
92
|
if (!Array.isArray(review)) throw new Error('review 必须为数组');
|
package/lib/generate.mjs
CHANGED
|
@@ -3,12 +3,13 @@ import { ROOT,loadProject,loadJob,projectPath } from './project.mjs';
|
|
|
3
3
|
import {selectCore,corePrompt,coreNegative} from './core.mjs';
|
|
4
4
|
import {execution,finishPlan} from './plan.mjs';
|
|
5
5
|
import {presentation,assetPrompt} from './presentation.mjs';
|
|
6
|
+
import {design,designPrompt} from './design.mjs';
|
|
6
7
|
export function compileGenerate({projectId,jobId,coreId,root=ROOT,localExecution={}}) {
|
|
7
8
|
const project=loadProject(projectId,root),job=loadJob(projectId,jobId,'generate',root);
|
|
8
9
|
keys(job,['project','kind','core','profile','execution','items'],'job');
|
|
9
10
|
const selected=selectCore(project,job,coreId,root),core=selected.core;
|
|
10
11
|
const profile=readJson(projectPath(root,projectId,'profiles',job.profile));
|
|
11
|
-
keys(profile,['project','id','name','constraints','defaults','allowedOverrides','presets','checks'],'profile');
|
|
12
|
+
keys(profile,['project','id','name','constraints','defaults','allowedOverrides','presets','checks','design'],'profile');
|
|
12
13
|
if(profile.project!==projectId||profile.id!==job.profile) throw new Error('资产配置工程身份不匹配');
|
|
13
14
|
keys(profile.constraints,['text','frame','scene','crop','shadow'],'constraints');
|
|
14
15
|
for(const v of Object.values(profile.constraints)) if(typeof v!=='boolean') throw new Error('资产约束必须为布尔值');
|
|
@@ -16,7 +17,8 @@ export function compileGenerate({projectId,jobId,coreId,root=ROOT,localExecution
|
|
|
16
17
|
const items=[],ids=new Set();
|
|
17
18
|
if(!Array.isArray(job.items)||!job.items.length) throw new Error('任务 items 必须非空');
|
|
18
19
|
for(const source of job.items) {
|
|
19
|
-
keys(source,['id','seed','intent','entities','effects','relations','composition','mustRead','variants'],'item');
|
|
20
|
+
keys(source,['id','seed','intent','entities','effects','relations','composition','mustRead','variants','design'],'item');
|
|
21
|
+
const d=design(profile,source.design,job.execution);
|
|
20
22
|
id(source.id); if(ids.has(source.id)) throw new Error('item ID 重复'); ids.add(source.id);
|
|
21
23
|
text(source.intent,'intent'); texts(source.mustRead,'mustRead');
|
|
22
24
|
if(!Array.isArray(source.entities)||!source.entities.length) throw new Error('entities 必须非空');
|
|
@@ -39,10 +41,10 @@ export function compileGenerate({projectId,jobId,coreId,root=ROOT,localExecution
|
|
|
39
41
|
const variants=source.variants?.length?source.variants:[{id:'base'}],variantIds=new Set();
|
|
40
42
|
for(const variant of variants) {
|
|
41
43
|
keys(variant,['id','composition','seed'],'variant');id(variant.id); if(variantIds.has(variant.id)) throw new Error('variant ID 重复');variantIds.add(variant.id);
|
|
42
|
-
const p=presentation(profile,{...source.composition,...variant.composition});
|
|
44
|
+
const p=presentation(profile,{...source.composition,...variant.composition},d);
|
|
43
45
|
if(!objectIds.has(p.value.focalTarget)) throw new Error('视觉焦点不存在');
|
|
44
46
|
const seed=variant.seed??source.seed??parseInt(hash([projectId,jobId,source.id]).slice(0,7),16); integer(seed,'seed');
|
|
45
|
-
items.push({itemId:source.id,variantId:variant.id,seed,brief:{...source,composition:p.value},prompt:`【风格核心】\n${corePrompt(core,source.entities.map(e=>e.kind))}\n【真实需求】\n${source.intent}。\n${lines.join('\n')}\n视觉焦点:${p.value.focalTarget}。\n【构图与资产】\n${p.prompt}\n${assetPrompt(profile)}`,negativeBlock:[coreNegative(core),profile.constraints.text?'':'文字, 字母, 水印',profile.constraints.frame?'':'装饰外框'].filter(Boolean).join(', '),imageArgs:[],checks:{content:source.mustRead,style:[corePrompt(core,source.entities.map(e=>e.kind))],asset:[...profile.checks,p.background]}});
|
|
47
|
+
items.push({...(d?{design:d,execution:execution(project,{...job.execution,size:`${d.outputSize.width}*${d.outputSize.height}`},localExecution)}:{}),itemId:source.id,variantId:variant.id,seed,brief:{...source,composition:p.value},prompt:`【风格核心】\n${corePrompt(core,source.entities.map(e=>e.kind))}\n【真实需求】\n${source.intent}。\n${lines.join('\n')}\n视觉焦点:${p.value.focalTarget}。\n【构图与资产】\n${p.prompt}\n${d ? designPrompt(d) : ""}\n${assetPrompt(profile)}`,negativeBlock:[coreNegative(core),profile.constraints.text?'':'文字, 字母, 水印',profile.constraints.frame?'':'装饰外框'].filter(Boolean).join(', '),imageArgs:[],checks:{content:source.mustRead,style:[corePrompt(core,source.entities.map(e=>e.kind))],asset:[...profile.checks,p.background]}});
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
return finishPlan({module:'generate',project:projectId,job:jobId,execution:execution(project,job.execution,localExecution),sources:{core:core.id,coreHash:core.coreHash,selection:selected.source},snapshots:{project,core,profile,job},refs:[],items});
|
package/lib/plan.mjs
CHANGED
|
@@ -10,13 +10,16 @@ export function execution(project, overrides = {},local = {}) {
|
|
|
10
10
|
return e;
|
|
11
11
|
}
|
|
12
12
|
export function finishPlan(body) {
|
|
13
|
-
const items = body.items.map(x => ({...x,inputHash:hash({...x,execution:body.execution})}));
|
|
13
|
+
const items = body.items.map(x => ({...x,inputHash:hash({...x,execution:x.execution??body.execution})}));
|
|
14
14
|
const plan = {schema:'art-workshop/plan',...body,items}; return {...plan,planHash:hash(plan)};
|
|
15
15
|
}
|
|
16
16
|
export function validatePlan(plan) {
|
|
17
17
|
if(plan.schema !== 'art-workshop/plan' || !['generate','edit'].includes(plan.module) || !plan.items?.length) throw new Error('不是有效的当前计划');
|
|
18
18
|
const {planHash,...body} = plan; if(hash(body)!==planHash) throw new Error('计划已改变;请修改任务后重新预演');
|
|
19
|
-
for(const {inputHash,...item} of plan.items)
|
|
19
|
+
for(const {inputHash,...item} of plan.items) {
|
|
20
|
+
execution({},item.execution??plan.execution);
|
|
21
|
+
if(hash({...item,execution:item.execution??plan.execution})!==inputHash) throw new Error('计划项校验失败');
|
|
22
|
+
}
|
|
20
23
|
}
|
|
21
24
|
export function selectItems(plan,{item,variant,offset=0,limit}={}) {
|
|
22
25
|
integer(offset,'offset'); if(limit!==undefined) integer(limit,'limit',1);
|
|
@@ -26,7 +29,7 @@ export function selectItems(plan,{item,variant,offset=0,limit}={}) {
|
|
|
26
29
|
return result.filter(x=>ids.includes(x.itemId));
|
|
27
30
|
}
|
|
28
31
|
export function buildArgs(plan,item,outDir,prefix) {
|
|
29
|
-
const e=plan.execution, args=['image',plan.module==='edit'?'edit':'generate'];
|
|
32
|
+
const e=item.execution??plan.execution, args=['image',plan.module==='edit'?'edit':'generate'];
|
|
30
33
|
for(const path of item.imageArgs) args.push('--image',path);
|
|
31
34
|
args.push('--prompt',item.prompt,'--model',e.model,'--size',e.size,'--n',String(e.perValue));
|
|
32
35
|
if(item.negativeBlock) args.push('--negative-prompt',item.negativeBlock);
|
package/lib/presentation.mjs
CHANGED
|
@@ -6,14 +6,14 @@ export function background(value,allowScene=false) {
|
|
|
6
6
|
if(value.type==='scene'&&allowScene) { keys(value,['type','description'],'background'); return `场景背景:${text(value.description,'scene')}。`; }
|
|
7
7
|
throw new Error('背景类型不支持或资产不允许场景');
|
|
8
8
|
}
|
|
9
|
-
export function presentation(profile,overrides={}) {
|
|
9
|
+
export function presentation(profile,overrides={},design=null) {
|
|
10
10
|
keys(overrides,['preset','view','direction','occupancy','effectIntensity','background','focalTarget'],'composition');
|
|
11
11
|
const c={...profile.defaults,...overrides};
|
|
12
12
|
for(const k of ['preset','view','direction','effectIntensity']) choice(c[k],profile.allowedOverrides[k],k);
|
|
13
13
|
const range=profile.allowedOverrides.occupancy;
|
|
14
14
|
if(!Number.isFinite(c.occupancy)||c.occupancy<range.min||c.occupancy>range.max) throw new Error('主体占比越界');
|
|
15
15
|
const bg=background(c.background,profile.constraints.scene);
|
|
16
|
-
return {value:c,prompt:`${profile.presets[c.preset]}。视角:${c.view};方向:${c.direction}
|
|
16
|
+
return {value:c,prompt:`${profile.presets[c.preset]}。视角:${c.view};方向:${c.direction};${design?'保持设计宽高比与四周安全留白':'整体占画幅约 '+c.occupancy*100+'%'};效果强度:${c.effectIntensity}。\n${bg}`,background:bg};
|
|
17
17
|
}
|
|
18
18
|
export function assetPrompt(profile) {
|
|
19
19
|
const c=profile.constraints;
|
package/package.json
CHANGED
|
@@ -26,3 +26,22 @@ plan 和 `--dry` 不产生图片、没有远程生图调用;真实分析或 ru
|
|
|
26
26
|
随包 skill 是权威来源,`agent init --directory DIR` 同步到 DIR 下已有的 Agent 技能目录;保留项目扩展文件。修改随包源后重新同步,不直接改已同步的 SKILL.md。
|
|
27
27
|
|
|
28
28
|
资源路径:工程、报告、计划、参考图、缓存、编辑原图与输出均放在工具目录之外。默认输出为系统下载目录/image.g。参考目录可用 --refs-dir 指定;其他路径用 --workspace、--output-dir、--cache-dir 覆盖。相对资源文件按 workspace 解析,参考图按 refs 目录解析;不要在安装目录创建工程或产物。本地配置位于用户配置目录,通过 config path/show/init 发现;不纳入 Git。
|
|
29
|
+
## UI 设计分辨率与单体出图尺寸
|
|
30
|
+
|
|
31
|
+
UI 设计基准属于资产规格,不写进冻结风格核心。文生图 profile 可声明:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
"design": { "resolution": { "width": 1920, "height": 1080 }, "outputScale": 2 }
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
任务 item 可声明独立控件尺寸与可选倍率:
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
"design": { "width": 240, "height": 80, "outputScale": 4 }
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
该按钮实际请求 size 为 960*320。同一任务的其他控件可使用不同设计尺寸;单体没有 design 时按 profile 的整幅设计分辨率出图。未覆盖倍率时继承 profile.outputScale。倍率为 1~4 的整数,设计尺寸为正整数且不得超过基准分辨率;换算后的每条边必须在工具支持的 256~4096 像素范围内,越界报错,不自动拉伸、补边或更改倍率。模型可能有额外尺寸与比例限制,工具的通用范围不等于模型能力保证。
|
|
44
|
+
|
|
45
|
+
启用设计尺寸时禁止同时设置任务 execution.size;工程和本地 execution.size 默认值被单体换算尺寸替代,模型等其他执行参数保留既有优先级。旧任务不声明 design 时保持原有行为。设计模式的提示词不再附加整体占画幅 75% 等比例要求,而声明设计宽高比和安全留白。
|
|
46
|
+
|
|
47
|
+
编译计划的每项包含 design(resolution、size、outputScale、outputSize)与实际 execution。预演、真实请求、输入哈希与执行验收使用同一份单体参数。修改设计尺寸后必须重新 plan。此配置控制请求画布,不保证模型精确绘制控件边界、描边或圆角像素,也不自动生成九宫切片、裁切或透明底资源。
|