@kevlns/art-workshop 0.5.1 → 0.6.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 +25 -25
- package/LICENSE +21 -21
- package/README.md +65 -63
- package/art-workshop.mjs +219 -174
- package/docs/channels.md +49 -0
- package/docs/commands.md +2259 -22
- package/docs/configuration.md +90 -82
- package/docs/core-guidance.md +58 -50
- package/docs/data-formats.md +89 -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 +73 -67
- package/docs/release-0.6.0.md +9 -0
- package/lib/agent.mjs +32 -32
- package/lib/analysis-worker.mjs +36 -32
- package/lib/analyze.mjs +85 -85
- package/lib/asset-profile.mjs +23 -23
- package/lib/backends.mjs +2 -0
- package/lib/candidates.mjs +104 -103
- package/lib/channel-operation.mjs +84 -0
- package/lib/comfy-recovery.mjs +17 -17
- package/lib/conversation.mjs +77 -77
- package/lib/core.mjs +104 -75
- package/lib/deployment-guide.mjs +12 -12
- package/lib/design.mjs +29 -29
- package/lib/dimensions.mjs +22 -22
- package/lib/edit.mjs +43 -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 +60 -58
- package/lib/generation-policy.mjs +1 -1
- 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/object-format.mjs +1 -1
- package/lib/process-identity.mjs +22 -14
- package/lib/project.mjs +39 -39
- package/lib/prompt-structure.mjs +3 -3
- package/lib/refs.mjs +26 -26
- package/lib/runtime.mjs +25 -25
- package/lib/service.mjs +155 -126
- package/lib/settings.mjs +50 -50
- package/lib/shared.mjs +67 -67
- package/lib/style-bundle.mjs +98 -85
- package/lib/style-contract.mjs +74 -74
- package/lib/style-lifecycle.mjs +124 -125
- package/lib/style-review.mjs +14 -14
- package/lib/style-samples.mjs +92 -0
- package/lib/task-contract.mjs +94 -93
- package/lib/tasks.mjs +497 -497
- package/lib/templates.mjs +80 -80
- package/lib/video/PROVENANCE.json +63 -0
- package/lib/video/atomic.mjs +32 -0
- package/lib/video/channel.mjs +70 -0
- package/lib/video/contract-local-media.mjs +42 -0
- package/lib/video/contract-story.mjs +213 -0
- package/lib/video/contract-video.mjs +117 -0
- package/lib/video/contracts.mjs +3 -0
- package/lib/video/h3.mjs +232 -0
- package/lib/video/local-runtime.mjs +20 -0
- package/lib/video/media.mjs +223 -0
- package/lib/video/models.mjs +336 -0
- package/lib/video/path.mjs +18 -0
- package/lib/video/process.mjs +15 -0
- package/lib/video/resource.mjs +15 -0
- package/lib/video/service.mjs +731 -0
- package/lib/video/workflow.mjs +571 -0
- package/lib/video.mjs +12 -0
- package/lib/vision.mjs +56 -56
- package/lib/worker-process.mjs +6 -6
- package/lib/workspace.mjs +305 -292
- package/package.json +8 -3
- package/rules/core-guidance.json +22 -22
- package/skills/art-workshop/SKILL.md +19 -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 +119 -109
- package/skills/art-workshop/references/style-discussion.md +7 -3
- package/skills/art-workshop/references/video.md +13 -0
- package/v-cli.plugin.json +7240 -2747
package/lib/style-bundle.mjs
CHANGED
|
@@ -1,85 +1,98 @@
|
|
|
1
|
-
import {readFileSync,writeFileSync,mkdirSync,existsSync,renameSync,rmSync,readdirSync} from 'node:fs';
|
|
2
|
-
import {join,resolve,relative,isAbsolute} from 'node:path';
|
|
3
|
-
import {randomUUID,createHash} from 'node:crypto';
|
|
4
|
-
import {readObject,objectDirectory,ownedPath,verifyReferences} from './workspace.mjs';
|
|
5
|
-
import {hash,id,readJson,writeJson} from './shared.mjs';
|
|
6
|
-
import {loadProject} from './project.mjs';
|
|
7
|
-
import {locked,runtimeRoot} from './runtime.mjs';
|
|
8
|
-
|
|
9
|
-
const bytesHash=b=>createHash('sha256').update(b).digest('hex');
|
|
10
|
-
const safe=(root,path)=>{if(typeof path!=='string'||!path||isAbsolute(path)||path.includes('\\')||path.split('/').some(x=>!x||x==='.'||x==='..'))throw new Error('风格包资源路径非法');return ownedPath(root,path);};
|
|
11
|
-
export function validateStyleBundle(bundle){
|
|
12
|
-
if(bundle?.schema!=='art-workshop/style-bundle'||bundle.schemaVersion!==1)throw new Error('风格包格式不支持');
|
|
13
|
-
const {bundleHash,...body}=bundle;if(hash(body)!==bundleHash)throw new Error('风格包完整性校验失败');
|
|
14
|
-
const {coreHash,...core}=bundle.core??{};
|
|
15
|
-
if(hash(core)!==coreHash||bundle.style?.status!=='frozen'||bundle.style.coreHash!==coreHash||bundle.style.id!==core.id||bundle.style.project!==core.project)throw new Error('冻结风格身份或核心校验失败');
|
|
16
|
-
id(core.id);id(core.project);
|
|
17
|
-
if(!Array.isArray(bundle.style.references)||!Array.isArray(bundle.files)||bundle.files.length>500)throw new Error('风格包参考非法');
|
|
18
|
-
const seen=new Set();let total=0;
|
|
19
|
-
for(const file of bundle.files){
|
|
20
|
-
safe('/bundle',file.path);if(seen.has(file.path))throw new Error('风格包路径重复');seen.add(file.path);
|
|
21
|
-
if(typeof file.data!=='string')throw new Error('风格包图片数据非法');
|
|
22
|
-
const bytes=Buffer.from(file.data,'base64');total+=bytes.length;
|
|
23
|
-
if(bytes.toString('base64')!==file.data||bytesHash(bytes)!==file.hash||total>100*1024*1024)throw new Error('风格包图片校验失败或超限');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
1
|
+
import {readFileSync,writeFileSync,mkdirSync,existsSync,renameSync,rmSync,readdirSync} from 'node:fs';
|
|
2
|
+
import {join,resolve,relative,isAbsolute} from 'node:path';
|
|
3
|
+
import {randomUUID,createHash} from 'node:crypto';
|
|
4
|
+
import {readObject,objectDirectory,ownedPath,verifyReferences} from './workspace.mjs';
|
|
5
|
+
import {hash,id,readJson,writeJson} from './shared.mjs';
|
|
6
|
+
import {loadProject} from './project.mjs';
|
|
7
|
+
import {locked,runtimeRoot} from './runtime.mjs';
|
|
8
|
+
|
|
9
|
+
const bytesHash=b=>createHash('sha256').update(b).digest('hex');
|
|
10
|
+
const safe=(root,path)=>{if(typeof path!=='string'||!path||isAbsolute(path)||path.includes('\\')||path.split('/').some(x=>!x||x==='.'||x==='..'))throw new Error('风格包资源路径非法');return ownedPath(root,path);};
|
|
11
|
+
export function validateStyleBundle(bundle){
|
|
12
|
+
if(bundle?.schema!=='art-workshop/style-bundle'||bundle.schemaVersion!==1)throw new Error('风格包格式不支持');
|
|
13
|
+
const {bundleHash,...body}=bundle;if(hash(body)!==bundleHash)throw new Error('风格包完整性校验失败');
|
|
14
|
+
const {coreHash,...core}=bundle.core??{};
|
|
15
|
+
if(hash(core)!==coreHash||bundle.style?.status!=='frozen'||bundle.style.coreHash!==coreHash||bundle.style.id!==core.id||bundle.style.project!==core.project)throw new Error('冻结风格身份或核心校验失败');
|
|
16
|
+
id(core.id);id(core.project);
|
|
17
|
+
if(!Array.isArray(bundle.style.references)||!Array.isArray(bundle.files)||bundle.files.length>500)throw new Error('风格包参考非法');
|
|
18
|
+
const seen=new Set();let total=0;
|
|
19
|
+
for(const file of bundle.files){
|
|
20
|
+
safe('/bundle',file.path);if(seen.has(file.path))throw new Error('风格包路径重复');seen.add(file.path);
|
|
21
|
+
if(typeof file.data!=='string')throw new Error('风格包图片数据非法');
|
|
22
|
+
const bytes=Buffer.from(file.data,'base64');total+=bytes.length;
|
|
23
|
+
if(bytes.toString('base64')!==file.data||bytesHash(bytes)!==file.hash||total>100*1024*1024)throw new Error('风格包图片校验失败或超限');
|
|
24
|
+
}
|
|
25
|
+
const samples=bundle.style.samples??[];
|
|
26
|
+
if(!Array.isArray(samples)||samples.length>12)throw new Error('风格包运行时参考非法');
|
|
27
|
+
const sampleIds=new Set();
|
|
28
|
+
for(const sample of samples){
|
|
29
|
+
id(sample.id,'sample');
|
|
30
|
+
if(sampleIds.has(sample.id)||!/^samples\//.test(sample.path??'')||!Array.isArray(core.config?.rules)||!/^[a-f0-9]{64}$/.test(sample.rulesHash??''))throw new Error('风格包运行时参考身份或版本非法');
|
|
31
|
+
sampleIds.add(sample.id);
|
|
32
|
+
}
|
|
33
|
+
const dependencies=[...bundle.style.references,...samples];
|
|
34
|
+
if(hash(bundle.style.samples??[])!==hash(bundle.core.approvedSamples??[]))throw new Error('风格包样张与核心快照不一致');
|
|
35
|
+
for(const ref of dependencies){safe('/bundle',ref.path);if(!bundle.files.some(file=>file.path===ref.path&&file.hash===ref.hash))throw new Error('风格包缺少参考依赖');}
|
|
36
|
+
if(bundle.files.some(file=>!dependencies.some(ref=>ref.path===file.path)))throw new Error('风格包包含未声明的参考资源');
|
|
37
|
+
return bundle;
|
|
38
|
+
}
|
|
39
|
+
export function exportStyleBundle(root,project,styleId,destination){
|
|
40
|
+
const style=readObject(root,project,'style',styleId);
|
|
41
|
+
if(style.status!=='frozen')throw new Error('只可导出已冻结风格');
|
|
42
|
+
const core=readJson(ownedPath(objectDirectory(root,project,'style',styleId),'core.json'));
|
|
43
|
+
const references=verifyReferences(root,style);
|
|
44
|
+
// Export only frozen evidence and explicitly owned reference bytes, never settings or runtime files.
|
|
45
|
+
const files=references.map(ref=>({path:style.references.find(item=>item.id===ref.id).path,hash:ref.hash,data:readFileSync(ref.path).toString('base64')}));
|
|
46
|
+
for(const sample of style.samples??[]){const bytes=readFileSync(ownedPath(objectDirectory(root,project,'style',styleId),sample.path));if(bytesHash(bytes)!==sample.hash)throw new Error('运行时参考已改变:'+sample.id);files.push({path:sample.path,hash:sample.hash,data:bytes.toString('base64')});}
|
|
47
|
+
const portable={schema:style.schema,schemaVersion:style.schemaVersion,project:style.project,id:style.id,name:style.name,revision:style.revision,status:style.status,coreHash:style.coreHash,createdAt:style.createdAt,updatedAt:style.updatedAt,config:style.config,references:style.references,samples:style.samples??[],report:core.report?{data:core.report,sourceRevision:style.revision,path:null,runId:null,sourceHash:null}:null,source:style.source??null};
|
|
48
|
+
const body={schema:'art-workshop/style-bundle',schemaVersion:1,style:portable,core,files};
|
|
49
|
+
const bundle=validateStyleBundle({...body,bundleHash:hash(body)});
|
|
50
|
+
if(existsSync(destination))throw new Error('导出目标已存在,不覆盖共享风格');
|
|
51
|
+
mkdirSync(resolve(destination,'..'),{recursive:true});writeFileSync(destination,JSON.stringify(bundle,null,2)+'\n',{flag:'wx'});
|
|
52
|
+
return {path:destination,id:style.id,revision:style.revision,bundleHash:bundle.bundleHash};
|
|
53
|
+
}
|
|
54
|
+
export function listStyleSources(directories){
|
|
55
|
+
const sources=directories.map(directory=>{
|
|
56
|
+
const items=[],errors=[];
|
|
57
|
+
try{for(const file of readdirSync(directory).filter(file=>file.endsWith('.style.json')).sort()){
|
|
58
|
+
try{const path=ownedPath(directory,file),raw=readFileSync(path);if(raw.length>150*1024*1024)throw new Error('风格包超限');const bundle=validateStyleBundle(JSON.parse(raw));items.push({path,id:bundle.style.id,name:bundle.style.name,revision:bundle.style.revision,coreHash:bundle.core.coreHash,bundleHash:bundle.bundleHash,project:bundle.style.project});}
|
|
59
|
+
catch(error){errors.push(file+':'+error.message);}
|
|
60
|
+
}}catch(error){errors.push(error.message);}
|
|
61
|
+
return {directory,items,...(errors.length?{error:errors.join(';')}:{})};
|
|
62
|
+
});
|
|
63
|
+
for(const source of sources)for(const item of source.items){
|
|
64
|
+
item.conflict=sources.flatMap(source=>source.items).some(other=>other.project===item.project&&other.id===item.id&&other.revision===item.revision&&other.coreHash!==item.coreHash);
|
|
65
|
+
}
|
|
66
|
+
return sources;
|
|
67
|
+
}
|
|
68
|
+
export async function importStyleBundle(settings,projectId,file,expectedHash){
|
|
69
|
+
const raw=readFileSync(file);if(raw.length>150*1024*1024)throw new Error('风格包超限');
|
|
70
|
+
const bundle=validateStyleBundle(JSON.parse(raw));
|
|
71
|
+
if(expectedHash && bundle.bundleHash!==expectedHash)throw new Error("来源风格已变化,请刷新后重新选择");
|
|
72
|
+
return locked(runtimeRoot(settings),'control',async()=>{
|
|
73
|
+
const root=settings.paths.workspace,project=loadProject(projectId,root);
|
|
74
|
+
const localId='shared-'+bundle.bundleHash.slice(0,32);
|
|
75
|
+
const directory=objectDirectory(root,projectId,'style',localId);
|
|
76
|
+
if(existsSync(directory)){
|
|
77
|
+
const existing=readObject(root,projectId,'style',localId);
|
|
78
|
+
if(existing.source?.bundleHash!==bundle.bundleHash)throw new Error('导入身份冲突');
|
|
79
|
+
verifyReferences(root,existing);
|
|
80
|
+
for(const sample of existing.samples??[]){const path=ownedPath(directory,sample.path);if(!existsSync(path)||bytesHash(readFileSync(path))!==sample.hash)throw new Error('已导入的运行时参考缺失或已改变:'+sample.id);}
|
|
81
|
+
return existing;
|
|
82
|
+
}
|
|
83
|
+
const origin={id:bundle.style.id,project:bundle.style.project,revision:bundle.style.revision,coreHash:bundle.core.coreHash,bundleHash:bundle.bundleHash};
|
|
84
|
+
const body={...bundle.core,project:projectId,id:localId,report:bundle.core.report?{...bundle.core.report,project:projectId,id:localId}:null,origin};delete body.coreHash;
|
|
85
|
+
const core={...body,coreHash:hash(body)};
|
|
86
|
+
const style={...bundle.style,project:projectId,id:localId,source:origin,coreHash:core.coreHash,report:core.report?{...bundle.style.report,data:core.report}:null};
|
|
87
|
+
const staging=objectDirectory(root,projectId,'style','import-'+randomUUID());
|
|
88
|
+
try{
|
|
89
|
+
mkdirSync(staging,{recursive:true});
|
|
90
|
+
for(const item of bundle.files){const target=safe(staging,item.path);mkdirSync(resolve(target,'..'),{recursive:true});writeFileSync(target,Buffer.from(item.data,'base64'),{flag:'wx'});}
|
|
91
|
+
writeJson(join(staging,'style.json'),style);writeJson(join(staging,'core.json'),core);
|
|
92
|
+
renameSync(staging,directory);
|
|
93
|
+
try{project.cores.push(localId);project.defaultCore??=localId;writeJson(ownedPath(root,'projects',projectId,'project.json'),project);}
|
|
94
|
+
catch(error){rmSync(directory,{recursive:true,force:true});throw error;}
|
|
95
|
+
return style;
|
|
96
|
+
}finally{rmSync(staging,{recursive:true,force:true});}
|
|
97
|
+
});
|
|
98
|
+
}
|
package/lib/style-contract.mjs
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
import {hash,keys,id,text,texts,choice} from './shared.mjs';
|
|
2
|
-
import {ContractError} from './errors.mjs';
|
|
3
|
-
/** Versioned drawing contract. Content and physical properties belong to each task. */
|
|
4
|
-
export const STYLE_SCHEMA_VERSION=3;
|
|
5
|
-
export const REFERENCE_CATEGORIES=[
|
|
6
|
-
{directory:'style',purpose:'媒介与整体绘制气质',recommended:'只提炼如何绘制,不继承主体轮廓、比例、结构或姿态',scope:'style'},
|
|
7
|
-
{directory:'palette',purpose:'可复用色彩关系',recommended:'色彩饱和度、色相对比与阴影偏色;不冻结主体身份色',scope:'palette'},
|
|
8
|
-
{directory:'rendering',purpose:'描绘、明暗、描边与笔触',recommended:'色阶、高光画法、描边、笔触与刻画密度;不固定材质或光源方向',scope:'rendering'}
|
|
9
|
-
];
|
|
10
|
-
export const STYLE_CATEGORIES=REFERENCE_CATEGORIES.map(category=>category.directory);
|
|
11
|
-
export const OBSERVATION_SCOPES=[...STYLE_CATEGORIES,'content','asset'];
|
|
12
|
-
export const RULE_SCOPES=['medium','shading','outline','highlights','brushwork','detail','palette'];
|
|
13
|
-
export const RULE_STRENGTHS=['required','default','avoid'];
|
|
14
|
-
export const RULE_TOPICS=[
|
|
15
|
-
{id:'medium',label:'媒介与整体语言'},
|
|
16
|
-
{id:'outline',label:'描边'},
|
|
17
|
-
{id:'shading',label:'明暗与形体表现'},
|
|
18
|
-
{id:'highlights',label:'高光'},
|
|
19
|
-
{id:'brushwork',label:'笔触'},
|
|
20
|
-
{id:'detail',label:'刻画密度'},
|
|
21
|
-
{id:'palette',label:'色彩关系'}
|
|
22
|
-
];
|
|
23
|
-
export const RULE_LABELS={required:'必须遵守',default:'默认倾向',avoid:'必须避免'};
|
|
24
|
-
export const RULE_GUIDE='每条规则只表达一个绘制主题。required 是必须遵守,avoid 是必须避免;只是少用、优先或通常避免时使用 default,并在 instruction 写清倾向。when 只记录适用条件,不猜测任务是否满足;条件规则不展开为全局禁止。各主题按需要填写,不要求填满;不重复同一要求,不增加主体、背景、尺寸或模型限制。';
|
|
25
|
-
export const STYLE_NEGATIVE_GUIDE='风格负向只排除跨主体复用的绘制语言,例如混杂渲染语言、照片级写实表现、杂乱的绘画笔触;不得排除具体主体、部件、身份色、物体纹理、材质、光源方向、构图或交付规格。不要把参考图中未出现的内容推断为禁止。avoid 规则可填写 negative 字符串数组,直接写被排除的抽象视觉特征,不加“避免、不要、禁止、no、without”等否定前缀,不混入正向要求或局部例外。instruction 是同一规则的阅读说明;适用条件和例外必须写入 when。只有无条件且明确填写的 negative 进入独立负向参数;有 when 的规则及 negative 表达完整保留在正向条件段,不猜测条件成立,不展开为全局禁止。未填写 negative 的文字排除条款仍完整保留,不机械转换。default 只是倾向,不进入负向参数。';
|
|
26
|
-
export const EXAMPLE_CONFIG={rules:[
|
|
27
|
-
{id:'medium',scope:'medium',strength:'required',instruction:'采用数字卡通插画表现',when:''},
|
|
28
|
-
{id:'outline',scope:'outline',strength:'default',instruction:'深色粗壮硬描边,具体颜色与粗细随画幅调整',when:''},
|
|
29
|
-
{id:'shading',scope:'shading',strength:'default',instruction:'以有限硬边色阶塑形,层次随体量调整',when:''},
|
|
30
|
-
{id:'crystal-highlights',scope:'highlights',strength:'default',instruction:'允许白色锐利高光和局部柔和发光',when:'任务指定透明或发光物体时'},
|
|
31
|
-
{id:'consistent-language',scope:'medium',strength:'avoid',instruction:'排除同一资产内混杂的绘制语言',negative:['混杂的绘制语言'],when:''}
|
|
32
|
-
]};
|
|
33
|
-
export const STYLE_BOUNDARY='风格只定义如何绘制:媒介、刻画密度、明暗方式、描边、高光画法、笔触和色彩关系。具体主体、轮廓、比例、结构、部件、姿态、身份色、物理材质、光源位置方向、构图、背景和资产规格属于任务,不能冻结到风格中。刻画密度不删减任务要求的结构或部件;笔触不是物体表面纹理,高光画法不是统一材质。';
|
|
34
|
-
export function assertExecutableStyle(plan){
|
|
35
|
-
if(plan.sources?.core&&plan.snapshots?.core?.schemaVersion!==STYLE_SCHEMA_VERSION)
|
|
36
|
-
throw new Error('旧风格计划需派生风格并重新分析采用、重新编译;历史证据仍可只读查看');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function validateStyleConfig(config){
|
|
40
|
-
keys(config,['rules'],'style rules');
|
|
41
|
-
if(!Array.isArray(config.rules)
|
|
42
|
-
const ids=new Set();
|
|
43
|
-
for(const rule of config.rules){
|
|
44
|
-
keys(rule,['id','scope','strength','instruction','when','negative'],'style rule');
|
|
45
|
-
id(rule.id,'rule.id');if(ids.has(rule.id))throw new ContractError('规则ID重复');ids.add(rule.id);
|
|
46
|
-
choice(rule.scope,RULE_SCOPES,'rule.scope');choice(rule.strength,RULE_STRENGTHS,'rule.strength');
|
|
47
|
-
text(rule.instruction,'rule.instruction',300);
|
|
48
|
-
if(/本轮|上一[轮版]|上次|本次调整|已[经]?修改|为解决.*冲突/.test(rule.instruction))throw new ContractError('风格规则必须为独立成稿,不包含迭代过程描述');
|
|
49
|
-
if(typeof rule.when!=='string'||rule.when.length>1000)throw new ContractError('规则适用条件非法');
|
|
50
|
-
if(rule.negative!==undefined){
|
|
51
|
-
if(rule.strength!=='avoid')throw new ContractError('仅 avoid 规则可配置 negative;默认倾向不能升级为负向禁止');
|
|
52
|
-
if(!Array.isArray(rule.negative)||rule.negative.length>20)throw new ContractError('规则 negative 必须为不超过20项的字符串数组');
|
|
53
|
-
for(const term of rule.negative){
|
|
54
|
-
text(term,'rule.negative',200);
|
|
55
|
-
if(/^(?:避免|不要|不得|禁止|不允许|不使用|排除|no\b|without\b|avoid\b)/i.test(term.trim()))throw new ContractError('negative 直接描述被排除的绘制特征,不加否定前缀;适用条件写入 when');
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return config;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function validateStyleDraft(config){
|
|
63
|
-
keys(config,['description','constraints','rules','analysis'],'style config');
|
|
64
|
-
if(config.rules!==undefined)validateStyleConfig({rules:config.rules});
|
|
65
|
-
if(config.description!==undefined&&(typeof config.description!=='string'||config.description.length>12000))throw new ContractError('风格描述必须是12000字以内文本');
|
|
66
|
-
if(config.constraints!==undefined)texts(config.constraints,'constraints',{empty:true});
|
|
67
|
-
if(config.analysis!==undefined){keys(config.analysis,['provider','model'],'analysis');text(config.analysis.provider,'analysis.provider');text(config.analysis.model,'analysis.model');}
|
|
68
|
-
return structuredClone(config);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export const REFERENCE_NOTE_LIMIT=8000;
|
|
72
|
-
export function validateReferenceNotes({note='',ignore=''}={}){for(const [field,value] of Object.entries({note,ignore}))if(typeof value!=='string'||value.length>REFERENCE_NOTE_LIMIT)throw new ContractError('参考说明必须为8000字以内文本',{fieldPath:field});}
|
|
73
|
-
export function styleAnalysisReadiness(input){const config=input.config??input,refs=input.references??input.refs??[];const ready=!!(config.description?.trim()||config.constraints?.some(x=>x.trim())||config.rules?.length||refs.length);return {ready,reason:ready?'':'请补充风格说明、规则或参考图后分析'};}
|
|
74
|
-
export function styleContract(){return {schemaVersion:STYLE_SCHEMA_VERSION,fields:['description','constraints','rules','analysis'],referenceNoteLimit:REFERENCE_NOTE_LIMIT,analysisContent:'description、constraints、rules 或参考图至少有一项有效内容',rules:{scopes:RULE_SCOPES,strengths:RULE_STRENGTHS},migration:true};}
|
|
1
|
+
import {hash,keys,id,text,texts,choice} from './shared.mjs';
|
|
2
|
+
import {ContractError} from './errors.mjs';
|
|
3
|
+
/** Versioned drawing contract. Content and physical properties belong to each task. */
|
|
4
|
+
export const STYLE_SCHEMA_VERSION=3;
|
|
5
|
+
export const REFERENCE_CATEGORIES=[
|
|
6
|
+
{directory:'style',purpose:'媒介与整体绘制气质',recommended:'只提炼如何绘制,不继承主体轮廓、比例、结构或姿态',scope:'style'},
|
|
7
|
+
{directory:'palette',purpose:'可复用色彩关系',recommended:'色彩饱和度、色相对比与阴影偏色;不冻结主体身份色',scope:'palette'},
|
|
8
|
+
{directory:'rendering',purpose:'描绘、明暗、描边与笔触',recommended:'色阶、高光画法、描边、笔触与刻画密度;不固定材质或光源方向',scope:'rendering'}
|
|
9
|
+
];
|
|
10
|
+
export const STYLE_CATEGORIES=REFERENCE_CATEGORIES.map(category=>category.directory);
|
|
11
|
+
export const OBSERVATION_SCOPES=[...STYLE_CATEGORIES,'content','asset'];
|
|
12
|
+
export const RULE_SCOPES=['medium','shading','outline','highlights','brushwork','detail','palette'];
|
|
13
|
+
export const RULE_STRENGTHS=['required','default','avoid'];
|
|
14
|
+
export const RULE_TOPICS=[
|
|
15
|
+
{id:'medium',label:'媒介与整体语言'},
|
|
16
|
+
{id:'outline',label:'描边'},
|
|
17
|
+
{id:'shading',label:'明暗与形体表现'},
|
|
18
|
+
{id:'highlights',label:'高光'},
|
|
19
|
+
{id:'brushwork',label:'笔触'},
|
|
20
|
+
{id:'detail',label:'刻画密度'},
|
|
21
|
+
{id:'palette',label:'色彩关系'}
|
|
22
|
+
];
|
|
23
|
+
export const RULE_LABELS={required:'必须遵守',default:'默认倾向',avoid:'必须避免'};
|
|
24
|
+
export const RULE_GUIDE='每条规则只表达一个绘制主题。required 是必须遵守,avoid 是必须避免;只是少用、优先或通常避免时使用 default,并在 instruction 写清倾向。when 只记录适用条件,不猜测任务是否满足;条件规则不展开为全局禁止。各主题按需要填写,不要求填满;不重复同一要求,不增加主体、背景、尺寸或模型限制。';
|
|
25
|
+
export const STYLE_NEGATIVE_GUIDE='风格负向只排除跨主体复用的绘制语言,例如混杂渲染语言、照片级写实表现、杂乱的绘画笔触;不得排除具体主体、部件、身份色、物体纹理、材质、光源方向、构图或交付规格。不要把参考图中未出现的内容推断为禁止。avoid 规则可填写 negative 字符串数组,直接写被排除的抽象视觉特征,不加“避免、不要、禁止、no、without”等否定前缀,不混入正向要求或局部例外。instruction 是同一规则的阅读说明;适用条件和例外必须写入 when。只有无条件且明确填写的 negative 进入独立负向参数;有 when 的规则及 negative 表达完整保留在正向条件段,不猜测条件成立,不展开为全局禁止。未填写 negative 的文字排除条款仍完整保留,不机械转换。default 只是倾向,不进入负向参数。';
|
|
26
|
+
export const EXAMPLE_CONFIG={rules:[
|
|
27
|
+
{id:'medium',scope:'medium',strength:'required',instruction:'采用数字卡通插画表现',when:''},
|
|
28
|
+
{id:'outline',scope:'outline',strength:'default',instruction:'深色粗壮硬描边,具体颜色与粗细随画幅调整',when:''},
|
|
29
|
+
{id:'shading',scope:'shading',strength:'default',instruction:'以有限硬边色阶塑形,层次随体量调整',when:''},
|
|
30
|
+
{id:'crystal-highlights',scope:'highlights',strength:'default',instruction:'允许白色锐利高光和局部柔和发光',when:'任务指定透明或发光物体时'},
|
|
31
|
+
{id:'consistent-language',scope:'medium',strength:'avoid',instruction:'排除同一资产内混杂的绘制语言',negative:['混杂的绘制语言'],when:''}
|
|
32
|
+
]};
|
|
33
|
+
export const STYLE_BOUNDARY='风格只定义如何绘制:媒介、刻画密度、明暗方式、描边、高光画法、笔触和色彩关系。具体主体、轮廓、比例、结构、部件、姿态、身份色、物理材质、光源位置方向、构图、背景和资产规格属于任务,不能冻结到风格中。刻画密度不删减任务要求的结构或部件;笔触不是物体表面纹理,高光画法不是统一材质。';
|
|
34
|
+
export function assertExecutableStyle(plan){
|
|
35
|
+
if(plan.sources?.core&&plan.snapshots?.core?.schemaVersion!==STYLE_SCHEMA_VERSION)
|
|
36
|
+
throw new Error('旧风格计划需派生风格并重新分析采用、重新编译;历史证据仍可只读查看');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function validateStyleConfig(config){
|
|
40
|
+
keys(config,['rules'],'style rules');
|
|
41
|
+
if(!Array.isArray(config.rules)||config.rules.length>60)throw new ContractError('风格规则必须为不超过60条的数组');
|
|
42
|
+
const ids=new Set();
|
|
43
|
+
for(const rule of config.rules){
|
|
44
|
+
keys(rule,['id','scope','strength','instruction','when','negative'],'style rule');
|
|
45
|
+
id(rule.id,'rule.id');if(ids.has(rule.id))throw new ContractError('规则ID重复');ids.add(rule.id);
|
|
46
|
+
choice(rule.scope,RULE_SCOPES,'rule.scope');choice(rule.strength,RULE_STRENGTHS,'rule.strength');
|
|
47
|
+
text(rule.instruction,'rule.instruction',300);
|
|
48
|
+
if(/本轮|上一[轮版]|上次|本次调整|已[经]?修改|为解决.*冲突/.test(rule.instruction))throw new ContractError('风格规则必须为独立成稿,不包含迭代过程描述');
|
|
49
|
+
if(typeof rule.when!=='string'||rule.when.length>1000)throw new ContractError('规则适用条件非法');
|
|
50
|
+
if(rule.negative!==undefined){
|
|
51
|
+
if(rule.strength!=='avoid')throw new ContractError('仅 avoid 规则可配置 negative;默认倾向不能升级为负向禁止');
|
|
52
|
+
if(!Array.isArray(rule.negative)||rule.negative.length>20)throw new ContractError('规则 negative 必须为不超过20项的字符串数组');
|
|
53
|
+
for(const term of rule.negative){
|
|
54
|
+
text(term,'rule.negative',200);
|
|
55
|
+
if(/^(?:避免|不要|不得|禁止|不允许|不使用|排除|no\b|without\b|avoid\b)/i.test(term.trim()))throw new ContractError('negative 直接描述被排除的绘制特征,不加否定前缀;适用条件写入 when');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return config;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function validateStyleDraft(config){
|
|
63
|
+
keys(config,['description','constraints','rules','analysis'],'style config');
|
|
64
|
+
if(config.rules!==undefined)validateStyleConfig({rules:config.rules});
|
|
65
|
+
if(config.description!==undefined&&(typeof config.description!=='string'||config.description.length>12000))throw new ContractError('风格描述必须是12000字以内文本');
|
|
66
|
+
if(config.constraints!==undefined)texts(config.constraints,'constraints',{empty:true});
|
|
67
|
+
if(config.analysis!==undefined){keys(config.analysis,['provider','model'],'analysis');text(config.analysis.provider,'analysis.provider');text(config.analysis.model,'analysis.model');}
|
|
68
|
+
return structuredClone(config);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const REFERENCE_NOTE_LIMIT=8000;
|
|
72
|
+
export function validateReferenceNotes({note='',ignore=''}={}){for(const [field,value] of Object.entries({note,ignore}))if(typeof value!=='string'||value.length>REFERENCE_NOTE_LIMIT)throw new ContractError('参考说明必须为8000字以内文本',{fieldPath:field});}
|
|
73
|
+
export function styleAnalysisReadiness(input){const config=input.config??input,refs=input.references??input.refs??[];const ready=!!(config.description?.trim()||config.constraints?.some(x=>x.trim())||config.rules?.length||refs.length);return {ready,reason:ready?'':'请补充风格说明、规则或参考图后分析'};}
|
|
74
|
+
export function styleContract(){return {schemaVersion:STYLE_SCHEMA_VERSION,fields:['description','constraints','rules','analysis'],referenceNoteLimit:REFERENCE_NOTE_LIMIT,analysisContent:'description、constraints、rules 或参考图至少有一项有效内容',rules:{scopes:RULE_SCOPES,strengths:RULE_STRENGTHS},migration:true};}
|