@kevlns/art-workshop 0.3.4 → 0.3.5
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/lib/generate.mjs +6 -5
- package/lib/task-contract.mjs +29 -0
- package/lib/workspace.mjs +3 -2
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -42,3 +42,5 @@ candidate delete 先确认影响,拒绝运行中或被计划/底图引用的
|
|
|
42
42
|
远端上游身份持久化后才能轮询。`task resume TASK` 只恢复原身份查询与取回,不重发生成;无回执或仍处于 dispatching 的提交保持未知。界面与保存共用 modelEligibility,展示字段不进入执行契约。
|
|
43
43
|
|
|
44
44
|
风格报告和核心职责版本 schemaVersion=3;不再包含 shape、lighting、domains,不限定主体题材。旧核心保留,只能派生后重新分析采用;旧分类参考必须明确重新分类,不能猜测搬到任务或渲染。低刻画密度不删任务结构,干净笔触不禁止物体纹理,高光画法不统一物理材质。
|
|
45
|
+
|
|
46
|
+
任务草稿允许内容尚未完成,但拒绝编译器不支持的字段。生成任务的字段正本为 lib/task-contract.mjs;effect 使用 id/kind/target/color/relation/count,不支持 description。先读当前对象,完整保留未修改字段,按当前 revision 保存;保存成功后仍需编译预案,不能声称已生成图片。任务编译错误依据执行回执修正,不猜测风格或尺寸问题。
|
package/lib/generate.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {GENERATION_FIELDS} from './task-contract.mjs';
|
|
1
2
|
import {taskReferencePrompt} from './task-references.mjs';
|
|
2
3
|
import {readObject,verifyReferences} from './workspace.mjs';
|
|
3
4
|
import { readJson, keys, id, text, texts, integer, hash } from './shared.mjs';
|
|
@@ -21,29 +22,29 @@ export function compileGenerate({projectId,jobId,coreId,root=ROOT,localExecution
|
|
|
21
22
|
const items=[],ids=new Set();
|
|
22
23
|
if(!Array.isArray(job.items)||!job.items.length) throw new Error('任务 items 必须非空');
|
|
23
24
|
for(const source of job.items) {
|
|
24
|
-
keys(source,
|
|
25
|
+
keys(source,GENERATION_FIELDS.item,'item');
|
|
25
26
|
const d=design(profile,source.design,job.execution);
|
|
26
27
|
id(source.id); if(ids.has(source.id)) throw new Error('item ID 重复'); ids.add(source.id);
|
|
27
28
|
text(source.intent,'intent'); texts(source.mustRead,'mustRead');
|
|
28
29
|
if(!Array.isArray(source.entities)||!source.entities.length) throw new Error('entities 必须非空');
|
|
29
30
|
const objectIds=new Set(), lines=[];
|
|
30
31
|
for(const e of source.entities) {
|
|
31
|
-
keys(e,
|
|
32
|
+
keys(e,GENERATION_FIELDS.entity,'entity'); id(e.id); id(e.kind);
|
|
32
33
|
if(objectIds.has(e.id)) throw new Error('实体 ID 重复'); objectIds.add(e.id);
|
|
33
34
|
if(!['primary','support'].includes(e.role)) throw new Error('实体角色不合法');
|
|
34
35
|
integer(e.count,'count',1,100); text(e.appearance,'appearance');text(e.color,'color'); if(e.action) text(e.action,'action');
|
|
35
36
|
lines.push(`${e.id}:${e.count} 个${e.appearance},${e.color},${e.role==='primary'?'主要':'辅助'}实体${e.action?','+e.action:''}。`);
|
|
36
37
|
}
|
|
37
38
|
for(const e of source.effects??[]) {
|
|
38
|
-
keys(e,
|
|
39
|
+
keys(e,GENERATION_FIELDS.effect,'effect');id(e.id);
|
|
39
40
|
if(objectIds.has(e.id)||!source.entities.some(x=>x.id===e.target)) throw new Error('效果 ID 重复或目标不存在'); objectIds.add(e.id);
|
|
40
41
|
for(const k of ['kind','color','relation']) text(e[k],k); integer(e.count,'count',1,100);
|
|
41
42
|
lines.push(`${e.id}:${e.count} 个${e.color}${e.kind},作用于 ${e.target};${e.relation}。`);
|
|
42
43
|
}
|
|
43
|
-
for(const r of source.relations??[]) {keys(r,
|
|
44
|
+
for(const r of source.relations??[]) {keys(r,GENERATION_FIELDS.relation,'relation'); if(!objectIds.has(r.from)||!objectIds.has(r.to)) throw new Error('关系目标不存在');lines.push(`${r.from} → ${r.to}:${text(r.action,'action')}。`);}
|
|
44
45
|
const variants=source.variants?.length?source.variants:[{id:'base'}],variantIds=new Set();
|
|
45
46
|
for(const variant of variants) {
|
|
46
|
-
keys(variant,
|
|
47
|
+
keys(variant,GENERATION_FIELDS.variant,'variant');id(variant.id); if(variantIds.has(variant.id)) throw new Error('variant ID 重复');variantIds.add(variant.id);
|
|
47
48
|
const p=presentation(profile,{...source.composition,...variant.composition},d);
|
|
48
49
|
if(!objectIds.has(p.value.focalTarget)) throw new Error('视觉焦点不存在');
|
|
49
50
|
const seed=variant.seed??source.seed??parseInt(hash([projectId,jobId,source.id]).slice(0,7),16); integer(seed,'seed');
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {keys} from './shared.mjs';
|
|
2
|
+
|
|
3
|
+
export const GENERATION_FIELDS = Object.freeze({
|
|
4
|
+
item:['id','seed','intent','entities','effects','relations','composition','mustRead','variants','design'],
|
|
5
|
+
entity:['id','kind','appearance','color','role','count','action'],
|
|
6
|
+
effect:['id','kind','target','color','relation','count'],
|
|
7
|
+
relation:['from','to','action'],
|
|
8
|
+
variant:['id','composition','seed'],
|
|
9
|
+
});
|
|
10
|
+
export function taskContract(kind){
|
|
11
|
+
return kind==='generate'?{
|
|
12
|
+
fields:GENERATION_FIELDS,
|
|
13
|
+
effectExample:{id:'glow',kind:'放射光束',target:'subject',color:'橙黄',relation:'从主体裂纹向外辐射',count:1},
|
|
14
|
+
rules:['effects 不支持 description;用 kind 描述效果类型,relation 描述位置和作用方式。','target、from、to 和 focalTarget 必须引用当前资产内的实体ID。','资产规格由 asset 配置;主体、身份色、材质、光效和构图属于任务需求。','草稿允许尚未填完;预案要求内容完整,不会发起生图。'],
|
|
15
|
+
}:{rules:['编辑任务使用 source、changes、preserve、mustRead;保留未修改范围。']};
|
|
16
|
+
}
|
|
17
|
+
/** Drafts may be incomplete, but never accept fields the compiler will discard. */
|
|
18
|
+
export function validateTaskDraft(config){
|
|
19
|
+
if(config.kind!=='generate')return config;
|
|
20
|
+
if(config.items!==undefined&&!Array.isArray(config.items))throw new Error('items 必须是数组');
|
|
21
|
+
for(const [index,item] of (config.items??[]).entries()){
|
|
22
|
+
keys(item,GENERATION_FIELDS.item,`items[${index}]`);
|
|
23
|
+
for(const [field,shape] of [['entities','entity'],['effects','effect'],['relations','relation'],['variants','variant']]){
|
|
24
|
+
if(item[field]!==undefined&&!Array.isArray(item[field]))throw new Error(`items[${index}].${field} 必须是数组`);
|
|
25
|
+
for(const [row,value] of (item[field]??[]).entries())keys(value,GENERATION_FIELDS[shape],`items[${index}].${field}[${row}]`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return config;
|
|
29
|
+
}
|
package/lib/workspace.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {validateTaskDraft} from './task-contract.mjs';
|
|
1
2
|
import {existsSync,mkdirSync,readdirSync,readFileSync,writeFileSync,lstatSync,rmSync,cpSync} from 'node:fs';
|
|
2
3
|
import {resolve,join,dirname,relative,isAbsolute} from 'node:path';
|
|
3
4
|
import {randomUUID,createHash} from 'node:crypto';
|
|
@@ -81,7 +82,7 @@ export async function createObject(settings,projectId,kind,{name,config={},sourc
|
|
|
81
82
|
if(project.schemaVersion!==2)throw new Error('工程需先显式升级');
|
|
82
83
|
if(typeof name!=='string'||!name.trim())throw new Error('对象名称不能为空');
|
|
83
84
|
const objectId=kind+'-'+randomUUID(),record={schema:'art-workshop/'+kind,schemaVersion:2,project:projectId,id:objectId,name:name.trim(),revision:1,status:'draft',createdAt:now(),updatedAt:now(),source,config:kind==='style'?styleConfig(config):structuredClone(config),references:[],report:null};
|
|
84
|
-
if(kind==='task'){if(!['generate','edit'].includes(config.kind))throw new Error('任务必须声明生成或编辑类型');record.config.project=projectId;}
|
|
85
|
+
if(kind==='task'){validateTaskDraft(config);if(!['generate','edit'].includes(config.kind))throw new Error('任务必须声明生成或编辑类型');record.config.project=projectId;}
|
|
85
86
|
const directory=objectDirectory(settings.paths.workspace,projectId,kind,objectId);
|
|
86
87
|
try{if(kind==='task')record.config=await importSources(settings,record,record.config);writeJson(objectFile(settings.paths.workspace,projectId,kind,objectId),record);return record;}
|
|
87
88
|
catch(error){if(existsSync(directory))rmSync(ownedPath(settings.paths.workspace,directory),{recursive:true,force:true});throw error;}
|
|
@@ -112,7 +113,7 @@ export async function importReference(settings,projectId,kind,objectId,revision,
|
|
|
112
113
|
});}catch(error){if(created)rmSync(created,{force:true});throw error;}
|
|
113
114
|
}
|
|
114
115
|
export async function updateObject(settings,projectId,kind,objectId,revision,{name,config}={}){
|
|
115
|
-
return mutateObject(settings,projectId,kind,objectId,revision,async record=>{const before=hash(record.config);if(name!==undefined){if(!name.trim())throw new Error('名称不能为空');record.name=name;}if(config!==undefined){if(kind==='task'&&(config.kind!==record.config.kind||config.project&&config.project!==projectId))throw new Error('任务类型/工程不可修改');record.config=kind==='task'?await importSources(settings,record,config):styleConfig(config);if(kind==='task')record.config.project=projectId;}if(hash(record.config)!==before)if(kind==='task')record.report=null;return record;});
|
|
116
|
+
return mutateObject(settings,projectId,kind,objectId,revision,async record=>{const before=hash(record.config);if(name!==undefined){if(!name.trim())throw new Error('名称不能为空');record.name=name;}if(config!==undefined){if(kind==='task'&&(config.kind!==record.config.kind||config.project&&config.project!==projectId))throw new Error('任务类型/工程不可修改');record.config=kind==='task'?await importSources(settings,record,validateTaskDraft(config)):styleConfig(config);if(kind==='task')record.config.project=projectId;}if(hash(record.config)!==before)if(kind==='task')record.report=null;return record;});
|
|
116
117
|
}
|
|
117
118
|
export async function removeReference(settings,projectId,kind,objectId,revision,referenceId){
|
|
118
119
|
// Keep immutable snapshot resources. A later explicit object cleanup owns deletion.
|