@kevlns/art-workshop 0.4.2 → 0.5.0
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 +4 -0
- package/art-workshop.mjs +4 -3
- package/docs/data-formats.md +6 -0
- package/lib/asset-profile.mjs +21 -0
- package/lib/edit.mjs +7 -5
- package/lib/generate.mjs +14 -16
- package/lib/presentation.mjs +18 -2
- package/lib/prompt-structure.mjs +7 -3
- package/lib/task-contract.mjs +38 -6
- package/lib/templates.mjs +4 -0
- package/package.json +1 -1
- package/skills/art-workshop/SKILL.md +4 -0
package/AGENTS.md
CHANGED
|
@@ -79,6 +79,10 @@ candidate delete 先确认影响,拒绝运行中或被计划/底图引用的
|
|
|
79
79
|
|
|
80
80
|
任务草稿允许内容尚未完成,但拒绝编译器不支持的字段。生成任务的字段正本为 lib/task-contract.mjs;effect 使用 id/kind/target/color/relation/count,不支持 description。先读当前对象,完整保留未修改字段,按当前 revision 保存;保存成功后仍需编译预案,不能声称已生成图片。任务编译错误依据执行回执修正,不猜测风格或尺寸问题。
|
|
81
81
|
|
|
82
|
+
任务 mustRead 是必须看清的视觉特征,保持字符串数组;画面文字使用独立 textSpecs 数组,每项 content(准确文字)、hierarchy(层级)、zone(位置或载体)必填,fontHint(字形)可选。所有描述完整保存,不设字数上限;草稿允许未填完,预案要求完整。生成任务仅在资产规格允许文字时接受非空 textSpecs,编辑任务按底图及 changes/preserve 执行;不把视觉特征转成文字,不自动开启文字权限。entity.material 是可选物理材质描述。composition.lightDirection/lightQuality 由资产规格成对声明词表及默认值,任务和 variant 可以单项覆盖,未开放能力时携带字段会报错。
|
|
83
|
+
|
|
84
|
+
job read 返回的 resolvedAsset 是只读有效资产规格,assetError 表示解析失败;更新只提交原 config,不回填投影或默认值。任务对象 schemaVersion=2、风格核心 schemaVersion=3 与计划 compilerVersion=4 相互独立。新编译预案记录编译版本;读取或执行原计划不补字段,不迁移任务或冻结风格。
|
|
85
|
+
|
|
82
86
|
任务参考可通过 reference import --item-id <对象标识> 绑定单个出图对象;未绑定的参考为任务共用。生成与编辑只采纳共用参考和当前对象参考的观察。reference update 的 itemId 可改绑对象,null 表示任务共用。
|
|
83
87
|
|
|
84
88
|
`v-cli capability coverage --json` 核对结构化调用覆盖。参考导入的 `--item-id` 指定当前任务出图对象,省略表示任务共用;工具校验对象身份。
|
package/art-workshop.mjs
CHANGED
|
@@ -7,6 +7,7 @@ const args=process.argv.slice(2),pos=[],options={};
|
|
|
7
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
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/init | 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
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');
|
|
10
11
|
const {loadJob,loadProject}=await import('./lib/project.mjs');
|
|
11
12
|
const {referenceRoot,referenceGuide}=await import('./lib/refs.mjs');
|
|
12
13
|
const {loadSettings,initSettings,externalPath}=await import('./lib/settings.mjs');
|
|
@@ -85,10 +86,10 @@ try {
|
|
|
85
86
|
const projectId=required('project'),kind=module==='job'?'task':'style';
|
|
86
87
|
if(action==='template'&&kind==='task')print(jobTemplate(ROOT,projectId,{kind:options.kind,core:options.core}));
|
|
87
88
|
else if(action==='from-candidate'&&kind==='task')print(await editFromCandidate(settings,projectId,required('id'),{runId:required('run'),candidateId:required('candidate')}));
|
|
88
|
-
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'?{...record,display:taskDisplayState(record,runs,record.finalizations??[])}:styleView(ROOT,record)));}
|
|
89
|
+
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)));}
|
|
89
90
|
else if(action==='create')print(await createObject(settings,projectId,kind,readJson(path(required('input')))));
|
|
90
|
-
else if(action==='read'){const record=readObject(ROOT,projectId,kind,required('id'));print(kind==='style'?styleView(ROOT,record):record);}
|
|
91
|
-
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):record);}
|
|
91
|
+
else if(action==='read'){const record=readObject(ROOT,projectId,kind,required('id'));print(kind==='style'?styleView(ROOT,record):taskObjectView(ROOT,record));}
|
|
92
|
+
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));}
|
|
92
93
|
else if(action==='analyze'&&kind==='task')print(await startAnalysis(settings,projectId,required('id'),Number(required('revision')),{dry:options.dry,kind:'task',operationId:options.operation}));
|
|
93
94
|
else if(action==='derive')print(await deriveObject(settings,projectId,kind,required('id'),Number(required('revision'))));
|
|
94
95
|
else if(action==='restore'&&kind==='task')print(await restoreTask(settings,projectId,required('id'),Number(required('revision'))));
|
package/docs/data-formats.md
CHANGED
|
@@ -28,6 +28,12 @@ projects/<projectId>/styles/<styleId>/style.json 与 tasks/<taskId>/task.json
|
|
|
28
28
|
|
|
29
29
|
生成 config 包括 project、kind、core、execution、analysis、generation、items,以及互斥的 profile 或内联 asset 规格;实体及效果有稳定 id、数量、颜色、角色与关系。具体主体、构图、动作不冻结进风格。规格定义资产约束、设计基准与检查要点,内联规格属于当前任务,编译时形成同一不可变快照。编辑 config 的 items 明确 source、changes、preserve、mustRead、seed。
|
|
30
30
|
|
|
31
|
+
生成实体可选 material 描述物理材质,按原文进入主体行。composition 的 lightDirection/lightQuality 由资产规格 allowedOverrides 成对提供非空词表,defaults 成对提供词表内默认值。有效值按规格、任务、variant 顺序覆盖,允许单项覆盖;未开放时携带光照键报错。新 custom 模板开放光照,既有规格不自动改写。
|
|
32
|
+
|
|
33
|
+
mustRead 保持视觉特征字符串数组。生成和编辑 item 均可选 textSpecs 数组,每项为 {content,hierarchy,zone,fontHint?}:准确文字、层级、位置或载体为必填描述,字形可选,均不限制字数。草稿允许暂缺或留空,编译检查完整性。相同文字的不同位置、层级、字形保留,完全相同项仅在编译输出去重。生成禁文字规格仅拒绝非空 textSpecs,不拒绝视觉特征;编辑任务按底图和修改/保留集处理。文字要求独立编译为画面文字规格段,有文字规格时追加文字保真负向;候选 checks.content 保持字符串数组,accepted 只代表技术完整性。
|
|
34
|
+
|
|
35
|
+
job read/list 的 resolvedAsset 是当前有效规格只读投影,assetError 是解析失败说明;两者不属于 config,不能保存为需求。新编译计划带 compilerVersion=4 并参与 planHash;版本不作为执行准入门槛,已有计划缺字段时保留缺席,后端重绑定不补版本。
|
|
36
|
+
|
|
31
37
|
plan 包括 schema=art-workshop/plan、module/project/job、sources、snapshots、refs、execution、items、planHash。sources 绑定 taskRevision、taskConfigHash 和 coreHash;项目/核心/profile/任务形成快照。项含 inputHash、实际尺寸和 seed。透明背景为 {type:"transparent"};生成配置位于 composition.background,编辑配置位于 changes 中 target=background 的 value。预案项 output 固定 PNG、透明背景及处理版本并参与哈希;含完全透明区域的原生 alpha 保留,否则从边缘核实洋红底色,容许模型色偏,处理与外边界连通的底色及混合边缘。接近不透明的 alpha 噪声不视为透明背景。记录 outputProcessing,保留原图和透明 PNG。任何来源或哈希变化拒绝运行。
|
|
32
38
|
|
|
33
39
|
analysis 为 {provider,model},风格和任务分别保存视觉分析实例。generation 为 {backend,remote?,options?},remote 为 {provider,model};选中后端的模型进入执行与请求快照,旧 execution.model 不覆盖所选后端。options 为当前任务的本地采样覆盖 {steps?,cfg?,sampler?,scheduler?},合并到冻结方案 backend.options,进入实际 ComfyUI 请求;远程后端拒绝这些字段。新任务本地推荐默认值为 steps=25、cfg=3、sampler=euler、scheduler=simple,内置工作流相同。显式值及历史计划保留。省略字段沿用后端或工作流默认值,数值 0 不视为省略。任务切换模型、后端或采样参数会改变配置哈希,必须重新编译。凭据由宿主按实例注入,不保存在配置。
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {readJson,keys,descriptions} from './shared.mjs';
|
|
2
|
+
import {projectPath} from './project.mjs';
|
|
3
|
+
import {validateLightProfile} from './presentation.mjs';
|
|
4
|
+
|
|
5
|
+
/** 编译与只读投影共用规格解析,不把默认值写回任务。 */
|
|
6
|
+
export function resolveAssetProfile(root,projectId,job){
|
|
7
|
+
if(Boolean(job.asset)===Boolean(job.profile))throw new Error('任务必须指定一份内联资产规格或一个资产规格模板');
|
|
8
|
+
const profile=job.asset??readJson(projectPath(root,projectId,'profiles',job.profile));
|
|
9
|
+
keys(profile,['project','id','name','constraints','defaults','allowedOverrides','presets','checks','design'],'profile');
|
|
10
|
+
if(profile.project!==projectId||job.profile&&profile.id!==job.profile)throw new Error('资产配置工程身份不匹配');
|
|
11
|
+
keys(profile.constraints,['text','frame','scene','crop','shadow'],'constraints');
|
|
12
|
+
for(const v of Object.values(profile.constraints))if(typeof v!=='boolean')throw new Error('资产约束必须为布尔值');
|
|
13
|
+
descriptions(profile.checks,'profile.checks');
|
|
14
|
+
validateLightProfile(profile);
|
|
15
|
+
return profile;
|
|
16
|
+
}
|
|
17
|
+
export function taskObjectView(root,record){
|
|
18
|
+
if(record.config.kind!=='generate')return record;
|
|
19
|
+
try{return {...record,resolvedAsset:resolveAssetProfile(root,record.project,record.config)};}
|
|
20
|
+
catch(error){return {...record,assetError:error.message};}
|
|
21
|
+
}
|
package/lib/edit.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import {EDIT_FIELDS,textSpecs,textSpecLine,textFidelityNegative} from './task-contract.mjs';
|
|
1
2
|
import {description,descriptions} from './shared.mjs';
|
|
2
|
-
import {editingPrompt} from './prompt-structure.mjs';
|
|
3
|
+
import {editingPrompt,COMPILER_VERSION} from './prompt-structure.mjs';
|
|
3
4
|
import {TRANSPARENT_OUTPUT} from './transparent-output.mjs';
|
|
4
5
|
import {taskReferencePrompt} from './task-references.mjs';
|
|
5
6
|
import {readObject,verifyReferences} from './workspace.mjs';
|
|
@@ -17,8 +18,9 @@ export function compileEdit({projectId,jobId,coreId,root=ROOT,localExecution={}}
|
|
|
17
18
|
if(coreId&&job.core&&coreId!==job.core) throw new Error('核心与编辑任务绑定冲突');
|
|
18
19
|
const selected=coreId??job.core,core=selected?loadCore(projectId,selected,root):null,refs=dynamicRefs.map(r=>({path:r.path,hash:r.hash})),items=[],ids=new Set();
|
|
19
20
|
if(!Array.isArray(job.items)||!job.items.length) throw new Error('编辑 items 必须非空');
|
|
20
|
-
for(const source of job.items) {
|
|
21
|
-
keys(source,
|
|
21
|
+
for(const [sourceIndex,source] of job.items.entries()) {
|
|
22
|
+
keys(source,EDIT_FIELDS,'edit item');
|
|
23
|
+
const readable=textSpecs(source.textSpecs,`items[${sourceIndex}].textSpecs`);id(source.id);
|
|
22
24
|
if(ids.has(source.id)) throw new Error('编辑 item ID 重复');ids.add(source.id);
|
|
23
25
|
const path=sourcePath(root,source.source),fileHash=sha256File(path);refs.push({path,hash:fileHash});
|
|
24
26
|
if(!source.changes?.length||!Array.isArray(source.preserve)) throw new Error('编辑必须明确 changes 和 preserve');
|
|
@@ -32,7 +34,7 @@ export function compileEdit({projectId,jobId,coreId,root=ROOT,localExecution={}}
|
|
|
32
34
|
if(source.changes.filter(x=>x.target==='background').length>1) throw new Error(`编辑对象 ${source.id} 只能设置一个最终背景,请合并 changes 中的 background`);
|
|
33
35
|
if(core&&(changed.has('style')||preserved.has('style'))) throw new Error('绑定核心时,风格由核心负责,不能再声明修改或保留原风格');
|
|
34
36
|
descriptions(source.mustRead,'mustRead');const seed=source.seed??parseInt(hash([projectId,jobId,source.id]).slice(0,7),16);integer(seed,'seed');
|
|
35
|
-
items.push({...(source.changes.some(x=>x.target==='background'&&x.value?.type==='transparent')?{output:TRANSPARENT_OUTPUT}:{}),itemId:source.id,variantId:'base',seed,brief:source,prompt:editingPrompt({changes,preserve,frozen:core?corePrompt(core):'',references:taskReferencePrompt(taskRecord,source.id),mustRead:source.mustRead}),negativeBlock:core?coreNegative(core):'',imageArgs:[path],checks:{content:source.mustRead,style:core?[corePrompt(core)]:['原图风格保持一致'],asset:changes.concat(preserve)}});
|
|
37
|
+
items.push({...(source.changes.some(x=>x.target==='background'&&x.value?.type==='transparent')?{output:TRANSPARENT_OUTPUT}:{}),itemId:source.id,variantId:'base',seed,brief:source,prompt:editingPrompt({changes,preserve,frozen:core?corePrompt(core):'',references:taskReferencePrompt(taskRecord,source.id),mustRead:source.mustRead,textSpecs:readable}),negativeBlock:textFidelityNegative(core?coreNegative(core):'',readable),imageArgs:[path],checks:{content:readable.length?[...source.mustRead,...readable.map(textSpecLine)]:source.mustRead,style:core?[corePrompt(core)]:['原图风格保持一致'],asset:changes.concat(preserve)}});
|
|
36
38
|
}
|
|
37
|
-
return finishPlan({module:'edit',project:projectId,job:jobId,execution:execution(project,job.execution,localExecution),sources:{taskRevision:taskRecord.revision,taskConfigHash:hash(taskRecord.config),core:core?.id??null,coreHash:core?.coreHash??null,selection:selected?'编辑显式绑定':'保留原图'},snapshots:{project,core,job},refs,items});
|
|
39
|
+
return finishPlan({compilerVersion:COMPILER_VERSION,module:'edit',project:projectId,job:jobId,execution:execution(project,job.execution,localExecution),sources:{taskRevision:taskRecord.revision,taskConfigHash:hash(taskRecord.config),core:core?.id??null,coreHash:core?.coreHash??null,selection:selected?'编辑显式绑定':'保留原图'},snapshots:{project,core,job},refs,items});
|
|
38
40
|
}
|
package/lib/generate.mjs
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import {description,descriptions} from './shared.mjs';
|
|
2
|
-
import {generationPrompt} from './prompt-structure.mjs';
|
|
2
|
+
import {generationPrompt,COMPILER_VERSION} from './prompt-structure.mjs';
|
|
3
3
|
import {TRANSPARENT_OUTPUT} from './transparent-output.mjs';
|
|
4
|
-
import {GENERATION_FIELDS} from './task-contract.mjs';
|
|
4
|
+
import {GENERATION_FIELDS,textSpecs,textSpecLine,textFidelityNegative} from './task-contract.mjs';
|
|
5
5
|
import {taskReferencePrompt} from './task-references.mjs';
|
|
6
6
|
import {readObject,verifyReferences} from './workspace.mjs';
|
|
7
|
-
import {
|
|
8
|
-
import { ROOT,loadProject,loadJob
|
|
7
|
+
import { keys, id, integer, hash } from './shared.mjs';
|
|
8
|
+
import { ROOT,loadProject,loadJob } from './project.mjs';
|
|
9
9
|
import {selectCore,corePrompt,coreNegative} from './core.mjs';
|
|
10
10
|
import {execution,finishPlan} from './plan.mjs';
|
|
11
11
|
import {presentation,assetPrompt} from './presentation.mjs';
|
|
12
|
+
import {resolveAssetProfile} from './asset-profile.mjs';
|
|
12
13
|
import {design,designPrompt} from './design.mjs';
|
|
13
14
|
export function compileGenerate({projectId,jobId,coreId,root=ROOT,localExecution={}}) {
|
|
14
15
|
const taskRecord=readObject(root,projectId,'task',jobId);const dynamicRefs=verifyReferences(root,taskRecord);
|
|
@@ -16,28 +17,25 @@ export function compileGenerate({projectId,jobId,coreId,root=ROOT,localExecution
|
|
|
16
17
|
keys(job,['project','kind','core','profile','asset','execution','analysis','generation','items'],'job');
|
|
17
18
|
if(job.generation&&localExecution.model)job.execution={...job.execution,model:localExecution.model};
|
|
18
19
|
const selected=selectCore(project,job,coreId,root),core=selected.core;
|
|
19
|
-
|
|
20
|
-
const profile=job.asset??readJson(projectPath(root,projectId,'profiles',job.profile));
|
|
21
|
-
keys(profile,['project','id','name','constraints','defaults','allowedOverrides','presets','checks','design'],'profile');
|
|
22
|
-
if(profile.project!==projectId||job.profile&&profile.id!==job.profile) throw new Error('资产配置工程身份不匹配');
|
|
23
|
-
keys(profile.constraints,['text','frame','scene','crop','shadow'],'constraints');
|
|
24
|
-
for(const v of Object.values(profile.constraints)) if(typeof v!=='boolean') throw new Error('资产约束必须为布尔值');
|
|
25
|
-
descriptions(profile.checks,'profile.checks');
|
|
20
|
+
const profile=resolveAssetProfile(root,projectId,job);
|
|
26
21
|
const items=[],ids=new Set();
|
|
27
22
|
if(!Array.isArray(job.items)||!job.items.length) throw new Error('任务 items 必须非空');
|
|
28
|
-
for(const source of job.items) {
|
|
23
|
+
for(const [sourceIndex,source] of job.items.entries()) {
|
|
29
24
|
keys(source,GENERATION_FIELDS.item,'item');
|
|
25
|
+
const readable=textSpecs(source.textSpecs,`items[${sourceIndex}].textSpecs`);
|
|
26
|
+
if(readable.length&&profile.constraints.text!==true)throw new Error(`items[${sourceIndex}].textSpecs:资产规格禁用文字`);
|
|
30
27
|
const d=design(profile,source.design,job.execution);
|
|
31
28
|
id(source.id); if(ids.has(source.id)) throw new Error('item ID 重复'); ids.add(source.id);
|
|
32
29
|
description(source.intent,'intent'); descriptions(source.mustRead,'mustRead');
|
|
33
30
|
if(!Array.isArray(source.entities)||!source.entities.length) throw new Error('entities 必须非空');
|
|
34
31
|
const objectIds=new Set(), lines=[];
|
|
35
|
-
for(const e of source.entities) {
|
|
32
|
+
for(const [entityIndex,e] of source.entities.entries()) {
|
|
36
33
|
keys(e,GENERATION_FIELDS.entity,'entity'); id(e.id); id(e.kind);
|
|
37
34
|
if(objectIds.has(e.id)) throw new Error('实体 ID 重复'); objectIds.add(e.id);
|
|
38
35
|
if(!['primary','support'].includes(e.role)) throw new Error('实体角色不合法');
|
|
39
36
|
integer(e.count,'count',1,100); description(e.appearance,'appearance');description(e.color,'color'); if(e.action) description(e.action,'action');
|
|
40
|
-
|
|
37
|
+
if(e.material!==undefined)description(e.material,`items[${sourceIndex}].entities[${entityIndex}].material`);
|
|
38
|
+
lines.push(`${e.id}:${e.count} 个${e.appearance}${e.material!==undefined?',材质 '+e.material:''},${e.color},${e.role==='primary'?'主要':'辅助'}实体${e.action?','+e.action:''}。`);
|
|
41
39
|
}
|
|
42
40
|
for(const e of source.effects??[]) {
|
|
43
41
|
keys(e,GENERATION_FIELDS.effect,'effect');id(e.id);
|
|
@@ -52,8 +50,8 @@ export function compileGenerate({projectId,jobId,coreId,root=ROOT,localExecution
|
|
|
52
50
|
const p=presentation(profile,{...source.composition,...variant.composition},d);
|
|
53
51
|
if(!objectIds.has(p.value.focalTarget)) throw new Error('视觉焦点不存在');
|
|
54
52
|
const seed=variant.seed??source.seed??parseInt(hash([projectId,jobId,source.id]).slice(0,7),16); integer(seed,'seed');
|
|
55
|
-
items.push({...(p.value.background.type==='transparent'?{output:TRANSPARENT_OUTPUT}:{}),...(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:generationPrompt({intent:source.intent,frozen:corePrompt(core),details:lines,composition:`视觉焦点:${p.value.focalTarget}。\n${p.prompt}`,delivery:d?designPrompt(d):'',asset:assetPrompt(profile),references:taskReferencePrompt(taskRecord,source.id),mustRead:source.mustRead}),negativeBlock:[coreNegative(core),profile.constraints.text?'':'文字, 字母, 水印',profile.constraints.frame?'':'装饰外框'].filter(Boolean).join(', '),imageArgs:[],checks:{content:source.mustRead,style:[corePrompt(core)],asset:[...profile.checks,p.background]}});
|
|
53
|
+
items.push({...(p.value.background.type==='transparent'?{output:TRANSPARENT_OUTPUT}:{}),...(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:generationPrompt({intent:source.intent,frozen:corePrompt(core),details:lines,composition:`视觉焦点:${p.value.focalTarget}。\n${p.prompt}`,delivery:d?designPrompt(d):'',asset:assetPrompt(profile),references:taskReferencePrompt(taskRecord,source.id),mustRead:source.mustRead,textSpecs:readable}),negativeBlock:textFidelityNegative([coreNegative(core),profile.constraints.text?'':'文字, 字母, 水印',profile.constraints.frame?'':'装饰外框'].filter(Boolean).join(', '),readable),imageArgs:[],checks:{content:readable.length?[...source.mustRead,...readable.map(textSpecLine)]:source.mustRead,style:[corePrompt(core)],asset:[...profile.checks,p.background]}});
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
|
-
return finishPlan({module:'generate',project:projectId,job:jobId,execution:execution(project,job.execution,localExecution),sources:{taskRevision:taskRecord.revision,taskConfigHash:hash(taskRecord.config),core:core.id,coreHash:core.coreHash,selection:selected.source},snapshots:{project,core,profile,job},refs:dynamicRefs.map(r=>({path:r.path,hash:r.hash})),items});
|
|
56
|
+
return finishPlan({compilerVersion:COMPILER_VERSION,module:'generate',project:projectId,job:jobId,execution:execution(project,job.execution,localExecution),sources:{taskRevision:taskRecord.revision,taskConfigHash:hash(taskRecord.config),core:core.id,coreHash:core.coreHash,selection:selected.source},snapshots:{project,core,profile,job},refs:dynamicRefs.map(r=>({path:r.path,hash:r.hash})),items});
|
|
59
57
|
}
|
package/lib/presentation.mjs
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import {description} from './shared.mjs';
|
|
2
2
|
import { keys, choice, text, hex } from './shared.mjs';
|
|
3
|
+
export function validateLightProfile(profile){
|
|
4
|
+
const fields=['lightDirection','lightQuality'];
|
|
5
|
+
const declared=fields.some(k=>profile.allowedOverrides?.[k]!==undefined||profile.defaults?.[k]!==undefined);
|
|
6
|
+
if(!declared)return false;
|
|
7
|
+
for(const k of fields){
|
|
8
|
+
const allowed=profile.allowedOverrides?.[k];
|
|
9
|
+
if(!Array.isArray(allowed)||!allowed.length||allowed.some(v=>typeof v!=='string'||!v.trim()))throw new Error('光照方向与质感必须成对声明非空词表:'+k);
|
|
10
|
+
choice(profile.defaults?.[k],allowed,'defaults.'+k);
|
|
11
|
+
}
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
3
14
|
export function background(value,allowScene=false) {
|
|
4
15
|
keys(value,['type','color','from','to','description'],'background');
|
|
5
16
|
if(value.type==='transparent') { keys(value,['type'],'transparent background'); return '最终交付透明 PNG。中间图使用均匀纯洋红 #FF00FF 背景供自动去背景;主体不得含洋红背景色、背景投影、渐变或棋盘格;保留完整主体和边缘。'; }
|
|
@@ -9,13 +20,18 @@ export function background(value,allowScene=false) {
|
|
|
9
20
|
throw new Error('背景类型不支持或资产不允许场景');
|
|
10
21
|
}
|
|
11
22
|
export function presentation(profile,overrides={},design=null) {
|
|
12
|
-
keys(overrides,['preset','view','direction','occupancy','effectIntensity','background','focalTarget'],'composition');
|
|
23
|
+
keys(overrides,['preset','view','direction','occupancy','effectIntensity','background','focalTarget','lightDirection','lightQuality'],'composition');
|
|
24
|
+
const light=validateLightProfile(profile);
|
|
25
|
+
for(const k of ['lightDirection','lightQuality']){
|
|
26
|
+
if(!light&&Object.hasOwn(overrides,k))throw new Error('当前资产规格未开放光照词汇:'+k);
|
|
27
|
+
}
|
|
13
28
|
const c={...profile.defaults,...overrides};
|
|
29
|
+
if(light)for(const k of ['lightDirection','lightQuality'])choice(c[k],profile.allowedOverrides[k],k);
|
|
14
30
|
for(const k of ['preset','view','direction','effectIntensity']) choice(c[k],profile.allowedOverrides[k],k);
|
|
15
31
|
const range=profile.allowedOverrides.occupancy;
|
|
16
32
|
if(!Number.isFinite(c.occupancy)||c.occupancy<range.min||c.occupancy>range.max) throw new Error('主体占比越界');
|
|
17
33
|
const bg=background(c.background,profile.constraints.scene);
|
|
18
|
-
return {value:c,prompt:`${profile.presets[c.preset]}。视角:${c.view};方向:${c.direction};${design?'保持设计宽高比与四周安全留白':'整体占画幅约 '+c.occupancy*100+'%'};效果强度:${c.effectIntensity}。\n${bg}`,background:bg};
|
|
34
|
+
return {value:c,prompt:`${profile.presets[c.preset]}。视角:${c.view};方向:${c.direction};${design?'保持设计宽高比与四周安全留白':'整体占画幅约 '+c.occupancy*100+'%'};效果强度:${c.effectIntensity}${light?';光照:'+c.lightDirection+','+c.lightQuality:''}。\n${bg}`,background:bg};
|
|
19
35
|
}
|
|
20
36
|
export function assetPrompt(profile) {
|
|
21
37
|
const c=profile.constraints;
|
package/lib/prompt-structure.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
import {textSpecLine} from './task-contract.mjs';
|
|
2
|
+
export const COMPILER_VERSION = 4;
|
|
3
|
+
const textSection=entries=>entries?.length?`【画面文字规格】\n仅将「」内的内容作为画面文字,其余为布局要求。\n${entries.map(entry=>'- '+textSpecLine(entry)).join('\n')}`:'';
|
|
4
|
+
export function generationPrompt({intent,frozen,details,composition,delivery,asset,references,mustRead,textSpecs}){
|
|
3
5
|
return [
|
|
4
6
|
`【本次用途与主体】\n${intent}。`,
|
|
5
7
|
`【静态冻结风格】\n${frozen}`,
|
|
@@ -7,16 +9,18 @@ export function generationPrompt({intent,frozen,details,composition,delivery,ass
|
|
|
7
9
|
`【动态构图与背景】\n${composition}`,
|
|
8
10
|
`【交付规格与约束】\n${[delivery,asset].filter(Boolean).join('\n')}`,
|
|
9
11
|
mustRead?.length?`【必须可读的特征】\n${[...new Set(mustRead)].map(x=>'- '+x).join('\n')}`:'',
|
|
12
|
+
textSection(textSpecs),
|
|
10
13
|
references,
|
|
11
14
|
].filter(Boolean).join('\n');
|
|
12
15
|
}
|
|
13
|
-
export function editingPrompt({changes,preserve,frozen,references,mustRead}){
|
|
16
|
+
export function editingPrompt({changes,preserve,frozen,references,mustRead,textSpecs}){
|
|
14
17
|
return [
|
|
15
18
|
'【本次任务】\n基于输入原图编辑。未声明修改的部分保持原样。',
|
|
16
19
|
`【动态修改要求】\n${changes.join('\n')}`,
|
|
17
20
|
`【动态保留要求】\n${preserve.join('\n')}`,
|
|
18
21
|
frozen?`【静态冻结风格】\n${frozen}`:'',
|
|
19
22
|
mustRead?.length?`【必须可读的特征】\n${[...new Set(mustRead)].map(x=>'- '+x).join('\n')}`:'',
|
|
23
|
+
textSection(textSpecs),
|
|
20
24
|
references,
|
|
21
25
|
].filter(Boolean).join('\n');
|
|
22
26
|
}
|
package/lib/task-contract.mjs
CHANGED
|
@@ -1,13 +1,38 @@
|
|
|
1
|
-
import {keys,text,integer} from './shared.mjs';
|
|
1
|
+
import {keys,text,integer,description} from './shared.mjs';
|
|
2
2
|
import {background} from './presentation.mjs';
|
|
3
3
|
|
|
4
4
|
export const GENERATION_FIELDS = Object.freeze({
|
|
5
|
-
item:['id','seed','intent','entities','effects','relations','composition','mustRead','variants','design'],
|
|
6
|
-
entity:['id','kind','appearance','color','role','count','action'],
|
|
5
|
+
item:['id','seed','intent','entities','effects','relations','composition','mustRead','textSpecs','variants','design'],
|
|
6
|
+
entity:['id','kind','appearance','color','role','count','action','material'],
|
|
7
7
|
effect:['id','kind','target','color','relation','count'],
|
|
8
8
|
relation:['from','to','action'],
|
|
9
9
|
variant:['id','composition','seed'],
|
|
10
10
|
});
|
|
11
|
+
export const EDIT_FIELDS = Object.freeze(['id','source','changes','preserve','mustRead','textSpecs','seed']);
|
|
12
|
+
export const TEXT_SPEC_FIELDS = Object.freeze(['content','hierarchy','zone','fontHint']);
|
|
13
|
+
export const TEXT_SPEC_EXAMPLE = Object.freeze({content:'开始游戏',hierarchy:'主标题',zone:'底部居中',fontHint:'粗体无衬线'});
|
|
14
|
+
const TEXT_SPEC_RULE = 'mustRead 是必须看清的视觉特征,不是画面文字;画面文字单独使用 textSpecs 数组,每项 content/hierarchy/zone 必填、fontHint 可选,均为不限制字数的描述。草稿允许未填完,预案要求完整;不自动转换旧条目或开启文字权限。';
|
|
15
|
+
export function textSpecs(value,path='textSpecs',{draft=false}={}){
|
|
16
|
+
if(value===undefined)return [];
|
|
17
|
+
if(!Array.isArray(value))throw new Error(path+' 必须是数组');
|
|
18
|
+
for(const [index,entry] of value.entries()){
|
|
19
|
+
const at=`${path}[${index}]`;
|
|
20
|
+
keys(entry,TEXT_SPEC_FIELDS,at);
|
|
21
|
+
for(const field of TEXT_SPEC_FIELDS){
|
|
22
|
+
if(draft){if(entry[field]!==undefined&&typeof entry[field]!=='string')throw new Error(at+'.'+field+' 必须是字符串');}
|
|
23
|
+
else if(field!=='fontHint'||entry[field]!==undefined)description(entry[field],at+'.'+field);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const seen=new Set();
|
|
27
|
+
return value.filter(entry=>{const key=JSON.stringify(TEXT_SPEC_FIELDS.map(field=>entry[field]));if(seen.has(key))return false;seen.add(key);return true;});
|
|
28
|
+
}
|
|
29
|
+
export function textSpecLine(entry){return `文字:「${entry.content}」|层级:${entry.hierarchy}|位置:${entry.zone}${entry.fontHint!==undefined?'|字形:'+entry.fontHint:''}`;}
|
|
30
|
+
export function textFidelityNegative(original,entries){return entries.length?[original,'文字扭曲, 笔画错乱, 模糊小字'].filter(Boolean).join(', '):original;}
|
|
31
|
+
function draftComposition(value,path){
|
|
32
|
+
if(value===undefined)return;
|
|
33
|
+
keys(value,['preset','view','direction','occupancy','effectIntensity','background','focalTarget','lightDirection','lightQuality'],path);
|
|
34
|
+
for(const field of ['lightDirection','lightQuality'])if(value[field]!==undefined&&typeof value[field]!=='string')throw new Error(path+'.'+field+' 必须是字符串');
|
|
35
|
+
}
|
|
11
36
|
export const TASK_MODEL_FIELDS = Object.freeze({analysis:['provider','model'],generation:['backend','remote','options'],remote:['provider','model'],options:['steps','cfg','sampler','scheduler']});
|
|
12
37
|
export const LOCAL_SAMPLING_DEFAULTS = Object.freeze({steps:25,cfg:3,sampler:'euler',scheduler:'simple'});
|
|
13
38
|
export function taskSamplingOptions(value){
|
|
@@ -21,10 +46,12 @@ export function taskContract(kind){
|
|
|
21
46
|
return kind==='generate'?{
|
|
22
47
|
models:TASK_MODEL_FIELDS,
|
|
23
48
|
fields:GENERATION_FIELDS,
|
|
49
|
+
textSpecs:{fields:TEXT_SPEC_FIELDS,required:['content','hierarchy','zone'],example:TEXT_SPEC_EXAMPLE},
|
|
50
|
+
composition:{lightDirection:'可选,须由资产规格开放词表;可单项覆盖默认值',lightQuality:'可选,须由资产规格开放词表;可单项覆盖默认值'},
|
|
24
51
|
backgrounds:{transparent:{type:'transparent'},solid:{type:'solid',color:'#FFFFFF'},gradient:{type:'gradient',from:'#FFFFFF',to:'#000000'},scene:{type:'scene',description:'场景说明'}},
|
|
25
52
|
effectExample:{id:'glow',kind:'放射光束',target:'subject',color:'橙黄',relation:'从主体裂纹向外辐射',count:1},
|
|
26
|
-
rules:['动态需求描述不设字数上限,不截断或为通过校验删减内容;必填项仍须为非空文本。','effects 不支持 description;用 kind 描述效果类型,relation 描述位置和作用方式。','target、from、to 和 focalTarget 必须引用当前资产内的实体ID。','资产规格由 asset 配置;主体、身份色、材质、光效和构图属于任务需求。','草稿允许尚未填完;预案要求内容完整,不会发起生图。'],
|
|
27
|
-
}:{models:TASK_MODEL_FIELDS,
|
|
53
|
+
rules:[TEXT_SPEC_RULE,'material 可选,使用具体名词说明主体物理材质,不设字数上限。','光照词表和默认值由资产规格成对声明;未开放能力时携带光照字段会报错。','动态需求描述不设字数上限,不截断或为通过校验删减内容;必填项仍须为非空文本。','effects 不支持 description;用 kind 描述效果类型,relation 描述位置和作用方式。','target、from、to 和 focalTarget 必须引用当前资产内的实体ID。','资产规格由 asset 配置;主体、身份色、材质、光效和构图属于任务需求。','草稿允许尚未填完;预案要求内容完整,不会发起生图。'],
|
|
54
|
+
}:{models:TASK_MODEL_FIELDS,textSpecs:{fields:TEXT_SPEC_FIELDS,required:['content','hierarchy','zone'],example:TEXT_SPEC_EXAMPLE},fields:{item:EDIT_FIELDS,instruction:['target','instruction'],backgroundChange:['target','value']},examples:{changes:[{target:'detail',instruction:'减少内部切面'},{target:'outline',instruction:'加粗外轮廓'},{target:'light',instruction:'光源改为右上方暖光'}],preserve:[{target:'shape',instruction:'保持整体外形'}]},rules:[TEXT_SPEC_RULE,'动态需求描述不设字数上限,不截断或为通过校验删减内容;必填项仍须为非空文本。','编辑任务使用 source、changes、preserve、mustRead;保留未修改范围。','target 是具体修改或保留的范围名称,例如 shape、outline、color、detail;同一范围可以修改局部并保留其他特征,不按名称机械判定矛盾。','修改背景使用 {target:background,value:{type:transparent}} 或 solid/color、gradient/from/to、scene/description。透明输出自动处理为带实际透明像素的 PNG。','绑定风格核心时由核心决定风格,不再声明 style 范围。']};
|
|
28
55
|
}
|
|
29
56
|
/** Drafts may be incomplete, but never accept fields the compiler will discard. */
|
|
30
57
|
export function validateTaskDraft(config){
|
|
@@ -33,7 +60,8 @@ export function validateTaskDraft(config){
|
|
|
33
60
|
if(config.kind==='edit'){
|
|
34
61
|
if(config.items!==undefined&&!Array.isArray(config.items))throw new Error('items 必须是数组');
|
|
35
62
|
for(const [i,item] of (config.items??[]).entries()){
|
|
36
|
-
keys(item,
|
|
63
|
+
keys(item,EDIT_FIELDS,`items[${i}]`);
|
|
64
|
+
textSpecs(item.textSpecs,`items[${i}].textSpecs`,{draft:true});
|
|
37
65
|
for(const scope of ['changes','preserve']){
|
|
38
66
|
if(item[scope]!==undefined&&!Array.isArray(item[scope]))throw new Error(`items[${i}].${scope} 必须是数组`);
|
|
39
67
|
for(const [j,row] of (item[scope]??[]).entries()){
|
|
@@ -50,10 +78,14 @@ export function validateTaskDraft(config){
|
|
|
50
78
|
if(config.items!==undefined&&!Array.isArray(config.items))throw new Error('items 必须是数组');
|
|
51
79
|
for(const [index,item] of (config.items??[]).entries()){
|
|
52
80
|
keys(item,GENERATION_FIELDS.item,`items[${index}]`);
|
|
81
|
+
textSpecs(item.textSpecs,`items[${index}].textSpecs`,{draft:true});
|
|
82
|
+
draftComposition(item.composition,`items[${index}].composition`);
|
|
53
83
|
for(const [field,shape] of [['entities','entity'],['effects','effect'],['relations','relation'],['variants','variant']]){
|
|
54
84
|
if(item[field]!==undefined&&!Array.isArray(item[field]))throw new Error(`items[${index}].${field} 必须是数组`);
|
|
55
85
|
for(const [row,value] of (item[field]??[]).entries())keys(value,GENERATION_FIELDS[shape],`items[${index}].${field}[${row}]`);
|
|
56
86
|
}
|
|
87
|
+
for(const [row,entity] of (item.entities??[]).entries())if(entity.material!==undefined&&typeof entity.material!=='string')throw new Error(`items[${index}].entities[${row}].material 必须是字符串`);
|
|
88
|
+
for(const [row,variant] of (item.variants??[]).entries())draftComposition(variant.composition,`items[${index}].variants[${row}].composition`);
|
|
57
89
|
}
|
|
58
90
|
return config;
|
|
59
91
|
}
|
package/lib/templates.mjs
CHANGED
|
@@ -23,6 +23,8 @@ function generateTemplate(projectId,core,kind) {
|
|
|
23
23
|
direction: "无方向",
|
|
24
24
|
occupancy: 0.7,
|
|
25
25
|
effectIntensity: "中",
|
|
26
|
+
lightDirection: "左上方",
|
|
27
|
+
lightQuality: "柔和",
|
|
26
28
|
background: { type: "solid", color: "#FFFFFF" },
|
|
27
29
|
},
|
|
28
30
|
allowedOverrides: {
|
|
@@ -31,6 +33,8 @@ function generateTemplate(projectId,core,kind) {
|
|
|
31
33
|
direction: ["无方向"],
|
|
32
34
|
occupancy: { min: 0.1, max: 0.95 },
|
|
33
35
|
effectIntensity: ["弱", "中", "强"],
|
|
36
|
+
lightDirection: ["左上方", "右上方", "正面", "顶部", "背面"],
|
|
37
|
+
lightQuality: ["柔和", "硬朗", "均匀棚光", "戏剧性对比"],
|
|
34
38
|
},
|
|
35
39
|
presets: { centered: "主体居中,完整展示,四周保留安全空间" },
|
|
36
40
|
checks: ["主体完整", "需求明确"],
|
package/package.json
CHANGED
|
@@ -86,6 +86,10 @@ candidate delete 先确认影响,拒绝运行中或被计划/底图引用的
|
|
|
86
86
|
|
|
87
87
|
任务草稿允许内容尚未完成,但拒绝编译器不支持的字段。生成任务的字段正本为 lib/task-contract.mjs;effect 使用 id/kind/target/color/relation/count,不支持 description。先读当前对象,完整保留未修改字段,按当前 revision 保存;保存成功后仍需编译预案,不能声称已生成图片。任务编译错误依据执行回执修正,不猜测风格或尺寸问题。
|
|
88
88
|
|
|
89
|
+
任务 mustRead 是必须看清的视觉特征,保持字符串数组;画面文字使用独立 textSpecs 数组,每项 content(准确文字)、hierarchy(层级)、zone(位置或载体)必填,fontHint(字形)可选。所有描述完整保存,不设字数上限;草稿允许未填完,预案要求完整。生成任务仅在资产规格允许文字时接受非空 textSpecs,编辑任务按底图及 changes/preserve 执行;不把视觉特征转成文字,不自动开启文字权限。entity.material 是可选物理材质描述。composition.lightDirection/lightQuality 由资产规格成对声明词表及默认值,任务和 variant 可以单项覆盖,未开放能力时携带字段会报错。
|
|
90
|
+
|
|
91
|
+
job read 返回的 resolvedAsset 是只读有效资产规格,assetError 表示解析失败;更新只提交原 config,不回填投影或默认值。任务对象 schemaVersion=2、风格核心 schemaVersion=3 与计划 compilerVersion=4 相互独立。新编译预案记录编译版本;读取或执行原计划不补字段,不迁移任务或冻结风格。
|
|
92
|
+
|
|
89
93
|
任务参考可通过 reference import --item-id <对象标识> 绑定单个出图对象;未绑定的参考为任务共用。生成与编辑只采纳共用参考和当前对象参考的观察。reference update 的 itemId 可改绑对象,null 表示任务共用。
|
|
90
94
|
|
|
91
95
|
`v-cli capability coverage --json` 核对结构化调用覆盖。参考导入的 `--item-id` 指定当前任务出图对象,省略表示任务共用;工具校验对象身份。
|