@punal_manalan/blender-project-harness 0.0.0-stage → 1.0.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/.kilo/agent/blender-grader.md +197 -0
- package/.kilo/agent/blender-worker.md +127 -0
- package/.kilo/blender-project-harness/config.example.json +71 -0
- package/.kilo/blender-project-harness/tools/harness/EXPECTED_FLOW.md +656 -0
- package/.kilo/blender-project-harness/tools/harness/blender-operations.mjs +882 -0
- package/.kilo/blender-project-harness/tools/harness/blender-operations.test.mjs +550 -0
- package/.kilo/blender-project-harness/tools/harness/blender.mjs +301 -0
- package/.kilo/blender-project-harness/tools/harness/blender.test.mjs +87 -0
- package/.kilo/blender-project-harness/tools/harness/cli.mjs +127 -0
- package/.kilo/blender-project-harness/tools/harness/documents.mjs +201 -0
- package/.kilo/blender-project-harness/tools/harness/download.mjs +94 -0
- package/.kilo/blender-project-harness/tools/harness/download.test.mjs +63 -0
- package/.kilo/blender-project-harness/tools/harness/engine.mjs +1866 -0
- package/.kilo/blender-project-harness/tools/harness/engine.test.mjs +2219 -0
- package/.kilo/blender-project-harness/tools/harness/intake.mjs +571 -0
- package/.kilo/blender-project-harness/tools/harness/intake.test.mjs +181 -0
- package/.kilo/blender-project-harness/tools/harness/package-lock.json +1227 -0
- package/.kilo/blender-project-harness/tools/harness/package.json +15 -0
- package/.kilo/blender-project-harness/tools/harness/plugin.mjs +550 -0
- package/.kilo/blender-project-harness/tools/harness/plugin.test.mjs +526 -0
- package/.kilo/blender-project-harness/tools/harness/proxy.mjs +222 -0
- package/.kilo/blender-project-harness/tools/harness/proxy.test.mjs +217 -0
- package/.kilo/blender-project-harness/tools/harness/scaffold.mjs +83 -0
- package/.kilo/blender-project-harness/tools/harness/scaffold.test.mjs +74 -0
- package/.kilo/blender-project-harness/tools/harness/server.mjs +24 -0
- package/.kilo/blender-project-harness/tools/harness/shell-policy.mjs +196 -0
- package/.kilo/blender-project-harness/tools/harness/shell-policy.test.mjs +68 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/Documents/ASSETS.md +29 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/Documents/DECISIONS.md +8 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/Documents/Goals/01-project-brief.md +71 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/Documents/Goals/README.md +17 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/Documents/INTAKE.md +8 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/Documents/README.md +57 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/Documents/REQUIREMENTS.md +64 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/Documents/REVIEW.md +29 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/Documents/References/README.md +18 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/Documents/Reviews/README.md +48 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/Documents/TASKSTRACKER.md +10 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/Documents/Tasks/README.md +4 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/Documents/WORKFLOW.md +36 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/README.md +130 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/assets/README.md +31 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/assets/audio/.gitkeep +0 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/assets/external/README.md +43 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/assets/external/SOURCE_TEMPLATE.md +18 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/assets/hdri/.gitkeep +0 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/assets/models/.gitkeep +0 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/assets/textures/.gitkeep +0 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/backups/.gitkeep +0 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/backups/README.md +5 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/exports/.gitkeep +0 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/exports/README.md +11 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/renders/README.md +7 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/renders/final/.gitkeep +0 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/renders/wip/.gitkeep +0 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/scenes/README.md +10 -0
- package/.kilo/blender-project-harness/tools/harness/templates/project/scripts/README.md +16 -0
- package/.kilo/blender-project-harness/tools/harness/test-fixture.mjs +91 -0
- package/.kilo/blender-project-harness/tools/harness/workspace.mjs +30 -0
- package/.kilo/blender-project-harness/tools/harness/workspace.test.mjs +31 -0
- package/.kilo/blender-project-harness/tools/test_blender_tools.py +427 -0
- package/.kilo/plugins/blender-workflow.js +3 -0
- package/.kilo/skills/blender-assets/SKILL.md +99 -0
- package/.kilo/skills/blender-mcp/SKILL.md +147 -0
- package/.kilo/skills/blender-mcp/references/README.md +22 -0
- package/.kilo/skills/blender-mcp/references/animation.md +83 -0
- package/.kilo/skills/blender-mcp/references/bpy.md +97 -0
- package/.kilo/skills/blender-mcp/references/level-design.md +53 -0
- package/.kilo/skills/blender-mcp/references/materials.md +80 -0
- package/.kilo/skills/blender-mcp/references/retopology.md +104 -0
- package/.kilo/skills/blender-mcp/references/rigging.md +123 -0
- package/.kilo/skills/blender-mcp/references/scene.md +72 -0
- package/.kilo/skills/blender-project-goal/SKILL.md +115 -0
- package/.kilo/skills/blender-project-grading/SKILL.md +184 -0
- package/.kilo/skills/blender-project-readme/SKILL.md +46 -0
- package/.kilo/skills/blender-project-requirements/SKILL.md +84 -0
- package/.kilo/skills/blender-project-scaffold/SKILL.md +59 -0
- package/.kilo/skills/blender-project-workflow/SKILL.md +96 -0
- package/.kilo/skills/blender-subagents/SKILL.md +204 -0
- package/.kilo/skills/blender-workflow-harness/SKILL.md +187 -0
- package/AGENTS.md +234 -0
- package/Blender/README.md +30 -0
- package/CHANGELOG.md +22 -0
- package/LICENSE +21 -0
- package/README.md +368 -2
- package/THIRD_PARTY_NOTICES.md +51 -0
- package/bin/blender-project-harness.mjs +4 -0
- package/installer/cli.mjs +116 -0
- package/installer/install.mjs +325 -0
- package/installer/install.test.mjs +134 -0
- package/package.json +58 -6
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { Harness, contained, digest, stable, deny, git } from './engine.mjs';
|
|
4
|
+
import { operationBatchCode, preflightCode, saveCode, renderCode, renderPreflightCode, sceneFactsCode } from './blender-operations.mjs';
|
|
5
|
+
|
|
6
|
+
export const READ_TOOLS = new Set(['get_addon_status', 'get_scene_info', 'look', 'search_assets', 'disable_telemetry', 'record_trajectory_feedback']);
|
|
7
|
+
export const SCENE_INFO_TOOL = {
|
|
8
|
+
name: 'blender_harness_scene_info',
|
|
9
|
+
description: 'Read-only scene facts for one scene or all scenes. No ticket, save, or mutation.',
|
|
10
|
+
inputSchema: { type: 'object', properties: { scene: { type: 'string' }, user_prompt: { type: 'string' } }, required: ['user_prompt'], additionalProperties: false },
|
|
11
|
+
};
|
|
12
|
+
export const EXECUTE_TOOL = {
|
|
13
|
+
name: 'harness_execute',
|
|
14
|
+
description: 'Execute one ticketed bounded Blender apply batch, save, WIP render, or seal. Obtain ticket from blender_workflow. Raw Python/imports/generation unavailable.',
|
|
15
|
+
inputSchema: { type: 'object', properties: { token: { type: 'string' }, operation: { type: 'string', enum: ['apply', 'save', 'seal', 'wip'] },
|
|
16
|
+
payload: { type: 'object' }, user_prompt: { type: 'string' } }, required: ['token', 'operation', 'payload', 'user_prompt'], additionalProperties: false },
|
|
17
|
+
};
|
|
18
|
+
export const textOf = (result) => (result.content ?? []).filter((c) => c.type === 'text').map((c) => c.text).join('\n');
|
|
19
|
+
export function firstJson(text) {
|
|
20
|
+
const start = text.indexOf('{');
|
|
21
|
+
let depth = 0, quote = false, escaped = false;
|
|
22
|
+
for (let i = start; i >= 0 && i < text.length; i++) {
|
|
23
|
+
const c = text[i];
|
|
24
|
+
if (quote) { if (escaped) escaped = false; else if (c === '\\') escaped = true; else if (c === '"') quote = false; }
|
|
25
|
+
else if (c === '"') quote = true;
|
|
26
|
+
else if (c === '{') depth++;
|
|
27
|
+
else if (c === '}' && --depth === 0) return JSON.parse(text.slice(start, i + 1));
|
|
28
|
+
}
|
|
29
|
+
deny('upstream response lacks JSON receipt');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function exportSignature(format, buffer) {
|
|
33
|
+
if (format === 'glb') return buffer.subarray(0, 4).toString('ascii') === 'glTF';
|
|
34
|
+
if (format === 'gltf') return buffer.toString('utf8', 0, Math.min(buffer.length, 4096)).trimStart().startsWith('{');
|
|
35
|
+
if (format === 'fbx') return buffer.toString('ascii', 0, Math.min(buffer.length, 32)).startsWith('Kaydara FBX Binary') || buffer.toString('utf8', 0, Math.min(buffer.length, 4096)).trimStart().startsWith('; FBX');
|
|
36
|
+
if (format === 'usd') return buffer.subarray(0, 8).toString('ascii') === 'PXR-USDC' || buffer.toString('utf8', 0, Math.min(buffer.length, 4096)).trimStart().startsWith('#usda');
|
|
37
|
+
if (format === 'obj') return !buffer.includes(0);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class BlenderProxy {
|
|
42
|
+
constructor(harness, upstream) { this.harness = harness; this.upstream = upstream; }
|
|
43
|
+
verifyExport(context, receipt) {
|
|
44
|
+
if (!receipt || typeof receipt.path !== 'string' || !receipt.path.startsWith('exports/')) deny('export receipt path is invalid');
|
|
45
|
+
const projectPath = `${context.project}/${receipt.path}`;
|
|
46
|
+
const full = contained(this.harness.root, projectPath);
|
|
47
|
+
if (!fs.existsSync(full)) deny('export file is missing');
|
|
48
|
+
const buffer = fs.readFileSync(full);
|
|
49
|
+
if (buffer.length === 0) deny('export file is empty');
|
|
50
|
+
if (buffer.length !== receipt.bytes || this.harness.hash(projectPath) !== receipt.sha256) deny('export receipt hash does not match the file');
|
|
51
|
+
if (!exportSignature(receipt.format, buffer)) deny('export file signature does not match the format');
|
|
52
|
+
return { ...receipt, path: projectPath };
|
|
53
|
+
}
|
|
54
|
+
async listTools() {
|
|
55
|
+
const tools = [], seen = new Set();
|
|
56
|
+
let cursor;
|
|
57
|
+
do {
|
|
58
|
+
if (cursor && seen.has(cursor)) deny('upstream tool pagination repeated');
|
|
59
|
+
seen.add(cursor);
|
|
60
|
+
const response = await this.upstream.listTools(cursor ? { cursor } : {});
|
|
61
|
+
tools.push(...response.tools.filter((t) => READ_TOOLS.has(t.name)));
|
|
62
|
+
cursor = response.nextCursor;
|
|
63
|
+
} while (cursor);
|
|
64
|
+
return { tools: [...tools, EXECUTE_TOOL, SCENE_INFO_TOOL] };
|
|
65
|
+
}
|
|
66
|
+
async call(name, args) {
|
|
67
|
+
if (name === SCENE_INFO_TOOL.name) {
|
|
68
|
+
if (!args || Object.keys(args).some((key) => !['scene', 'user_prompt'].includes(key)) || typeof args.user_prompt !== 'string' || !args.user_prompt.trim() || (args.scene !== undefined && (typeof args.scene !== 'string' || !args.scene.trim()))) deny('scene info requires user_prompt and optional scene name');
|
|
69
|
+
return this.result(await this.run(sceneFactsCode(args.scene ?? null), args.user_prompt));
|
|
70
|
+
}
|
|
71
|
+
if (READ_TOOLS.has(name)) return this.upstream.callTool({ name, arguments: args });
|
|
72
|
+
if (name !== 'harness_execute') deny('unregistered Blender operation');
|
|
73
|
+
if (!args || Object.keys(args).some((k) => !['token', 'operation', 'payload', 'user_prompt'].includes(k)) || typeof args.user_prompt !== 'string' || !args.user_prompt.trim()) deny('strict ticket arguments and verbatim user prompt required');
|
|
74
|
+
const context = this.harness.consume(args.token, args.operation, args.payload);
|
|
75
|
+
const scenePath = contained(this.harness.root, context.scene, true);
|
|
76
|
+
let round = null;
|
|
77
|
+
let roundRoot = null;
|
|
78
|
+
let renderPath = null;
|
|
79
|
+
let indexPath = null;
|
|
80
|
+
let indexLine = null;
|
|
81
|
+
let roundCreated = false;
|
|
82
|
+
let completed = 0;
|
|
83
|
+
const operationResults = [];
|
|
84
|
+
try {
|
|
85
|
+
const addon = await this.upstream.callTool({ name: 'get_addon_status', arguments: { user_prompt: args.user_prompt } });
|
|
86
|
+
if (addon.isError || firstJson(textOf(addon)).up_to_date !== true) deny('addon mismatch or unavailable');
|
|
87
|
+
const before = await this.run(preflightCode(scenePath), args.user_prompt);
|
|
88
|
+
if (before.missing?.length) deny('missing external scene dependencies');
|
|
89
|
+
if (context.change.sceneHash && this.harness.hash(context.scene) !== context.change.sceneHash) deny('scene file changed outside guarded operation');
|
|
90
|
+
if (args.operation === 'apply') {
|
|
91
|
+
if (before.is_dirty) deny('live scene has unsaved changes; save or recover before applying a guarded operation');
|
|
92
|
+
if (!before.filepath) deny('save initial scene before editing');
|
|
93
|
+
const operations = operationBatchCode(args.payload, context.change.objects);
|
|
94
|
+
const names = Array.isArray(args.payload?.operations) ? args.payload.operations.map((operation) => operation.operation) : [args.payload?.operation ?? 'apply'];
|
|
95
|
+
for (const [index, operation] of operations.entries()) {
|
|
96
|
+
let receipt;
|
|
97
|
+
try {
|
|
98
|
+
receipt = await this.run(operation, args.user_prompt);
|
|
99
|
+
if (names[index] === 'export_scene') receipt = this.verifyExport(context, receipt);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
operationResults.push({ index: index + 1, operation: names[index], ok: false, error: String(error.message) });
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
await this.run(saveCode(scenePath), args.user_prompt);
|
|
105
|
+
operationResults.push({ index: index + 1, operation: names[index], ok: true, ...(['export_scene', 'check_assets'].includes(names[index]) ? { receipt } : {}) });
|
|
106
|
+
completed += 1;
|
|
107
|
+
}
|
|
108
|
+
const result = this.harness.finish(args.token, { ok: true, completed, operationResults });
|
|
109
|
+
return this.result(result);
|
|
110
|
+
}
|
|
111
|
+
await this.run(saveCode(scenePath), args.user_prompt);
|
|
112
|
+
const saved = await this.run(preflightCode(scenePath), args.user_prompt);
|
|
113
|
+
if (saved.is_dirty || saved.filepath !== scenePath) deny('authoritative scene save not verified');
|
|
114
|
+
if (args.operation === 'save') return this.result(this.harness.finish(args.token, { ok: true }));
|
|
115
|
+
await this.run(renderPreflightCode(scenePath), args.user_prompt);
|
|
116
|
+
if (args.operation === 'wip') {
|
|
117
|
+
const relativeRender = `renders/wip/WIP-${Date.now()}.png`;
|
|
118
|
+
const wipPath = `${context.project}/${relativeRender}`;
|
|
119
|
+
contained(this.harness.root, wipPath, true);
|
|
120
|
+
fs.mkdirSync(path.dirname(path.join(this.harness.root, wipPath)), { recursive: true });
|
|
121
|
+
await this.run(renderCode(scenePath, `//${relativeRender}`), args.user_prompt);
|
|
122
|
+
const image = fs.readFileSync(contained(this.harness.root, wipPath));
|
|
123
|
+
if (!image.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))) deny('WIP render is not PNG');
|
|
124
|
+
return this.result(this.harness.finish(args.token, { ok: true, renderPath: wipPath }));
|
|
125
|
+
}
|
|
126
|
+
round = this.makeRound(context.project, context.change.failedRounds ?? []);
|
|
127
|
+
roundRoot = `${context.project}/Documents/Reviews/${round}`;
|
|
128
|
+
const evidenceRoot = contained(this.harness.root, `${roundRoot}/_evidence`, true);
|
|
129
|
+
fs.mkdirSync(evidenceRoot, { recursive: true });
|
|
130
|
+
roundCreated = true;
|
|
131
|
+
const roundRelative = `Documents/Reviews/${round}`;
|
|
132
|
+
const declaredScenes = (context.change.scenes ?? []).filter((name) => typeof name === 'string' && name.trim());
|
|
133
|
+
const primaryScene = context.change.primaryScene ?? declaredScenes[0] ?? null;
|
|
134
|
+
const sceneOrder = [...new Set([primaryScene, ...declaredScenes].filter(Boolean))];
|
|
135
|
+
if (!sceneOrder.length) sceneOrder.push(null);
|
|
136
|
+
const renders = {};
|
|
137
|
+
const scenes = [];
|
|
138
|
+
const evidenceNames = new Set();
|
|
139
|
+
let primary = primaryScene;
|
|
140
|
+
for (const [index, sceneName] of sceneOrder.entries()) {
|
|
141
|
+
const preflight = await this.run(renderPreflightCode(scenePath, sceneName), args.user_prompt);
|
|
142
|
+
const name = sceneName ?? preflight.scene ?? 'active';
|
|
143
|
+
if (primary === null) primary = name;
|
|
144
|
+
const safeName = String(name).replace(/[\\/:*?"<>|]+/g, '-').replace(/\s+/g, '-').slice(0, 80) || `scene-${index + 1}`;
|
|
145
|
+
const relativeRender = name === primary
|
|
146
|
+
? `renders/final/${round}.png`
|
|
147
|
+
: `${roundRelative}/_evidence/scenes/${safeName}/camera.png`;
|
|
148
|
+
const projectRender = `${context.project}/${relativeRender}`;
|
|
149
|
+
const absoluteRender = projectRender;
|
|
150
|
+
contained(this.harness.root, absoluteRender, true);
|
|
151
|
+
fs.mkdirSync(path.dirname(path.join(this.harness.root, absoluteRender)), { recursive: true });
|
|
152
|
+
await this.run(renderCode(scenePath, `//${relativeRender}`, sceneName), args.user_prompt);
|
|
153
|
+
const render = fs.readFileSync(contained(this.harness.root, absoluteRender));
|
|
154
|
+
if (!render.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))) deny('review render is not PNG');
|
|
155
|
+
if (name === primary) renderPath = projectRender;
|
|
156
|
+
const sceneDir = contained(this.harness.root, `${roundRoot}/_evidence/scenes/${safeName}`, true);
|
|
157
|
+
fs.mkdirSync(sceneDir, { recursive: true });
|
|
158
|
+
const cameraPath = `${roundRoot}/_evidence/scenes/${safeName}/camera.png`;
|
|
159
|
+
if (name === primary) fs.copyFileSync(path.join(this.harness.root, absoluteRender), path.join(this.harness.root, cameraPath));
|
|
160
|
+
const facts = await this.run(sceneFactsCode(name), args.user_prompt);
|
|
161
|
+
const factsPath = `${roundRoot}/_evidence/scenes/${safeName}/scene-facts.json`;
|
|
162
|
+
const textPath = `${roundRoot}/_evidence/scenes/${safeName}/scene.txt`;
|
|
163
|
+
fs.writeFileSync(path.join(this.harness.root, factsPath), JSON.stringify(facts.scenes?.[0] ?? facts, null, 2) + '\n');
|
|
164
|
+
fs.writeFileSync(path.join(this.harness.root, textPath), JSON.stringify(facts.scenes?.[0] ?? facts, null, 2) + '\n');
|
|
165
|
+
renders[name] = projectRender;
|
|
166
|
+
scenes.push({ name, render: projectRender, camera: preflight.camera, use_sequencer: preflight.use_sequencer, resolution: preflight.resolution, facts: factsPath });
|
|
167
|
+
for (const pathName of [projectRender, cameraPath, factsPath, textPath]) evidenceNames.add(pathName);
|
|
168
|
+
}
|
|
169
|
+
const evidence = Object.fromEntries([...evidenceNames].map((name) => [name, this.harness.hash(name)]));
|
|
170
|
+
const evidenceKey = digest(stable({ scene: this.harness.hash(context.scene), specs: context.records.specs, evidence }));
|
|
171
|
+
const manifest = { round, created: new Date().toISOString(), previous_round: context.previousRound, active_goal: `${context.project}/${context.goal}`,
|
|
172
|
+
base_commit: context.change.base, dirty: git(this.harness.root, ['status', '--porcelain', '--', context.project]).trim(),
|
|
173
|
+
scene: { path: context.scene, sha256: this.harness.hash(context.scene) }, primary_scene: primary, scenes,
|
|
174
|
+
scene_requirements: context.change.sceneRequirements ?? {}, specs: context.records.specs,
|
|
175
|
+
asset_check: context.change.assetCheckReceipt ?? null,
|
|
176
|
+
evidence, evidence_key: evidenceKey, graders: context.records.roster, tasks: {}, operation_tasks: context.operationTasks ?? [] };
|
|
177
|
+
fs.writeFileSync(contained(this.harness.root, `${roundRoot}/manifest.json`, true), JSON.stringify(manifest, null, 2) + '\n', { flag: 'wx' });
|
|
178
|
+
indexPath = `${context.project}/Documents/Reviews/README.md`;
|
|
179
|
+
indexLine = `\n- ${round}: ${context.change.outcome}; evidence ${evidenceKey}\n`;
|
|
180
|
+
fs.appendFileSync(contained(this.harness.root, indexPath), indexLine);
|
|
181
|
+
const result = this.harness.finish(args.token, { ok: true, round, renderPath, evidence, renders, primaryScene: primary, scenes: scenes.map((scene) => scene.name) });
|
|
182
|
+
return this.result({ ...result, render: path.join(this.harness.root, renderPath), manifest: `${roundRoot}/manifest.json` });
|
|
183
|
+
} catch (error) {
|
|
184
|
+
if (indexPath && indexLine) {
|
|
185
|
+
try {
|
|
186
|
+
const index = contained(this.harness.root, indexPath);
|
|
187
|
+
const text = fs.readFileSync(index, 'utf8');
|
|
188
|
+
const at = text.lastIndexOf(indexLine);
|
|
189
|
+
if (at >= 0) fs.writeFileSync(index, text.slice(0, at) + text.slice(at + indexLine.length));
|
|
190
|
+
} catch { /* Preserve fail-closed state when cleanup cannot restore the index. */ }
|
|
191
|
+
}
|
|
192
|
+
if (roundCreated && roundRoot) {
|
|
193
|
+
try { fs.rmSync(contained(this.harness.root, roundRoot), { recursive: true, force: true }); } catch { /* Preserve evidence for manual recovery. */ }
|
|
194
|
+
}
|
|
195
|
+
if (renderPath) {
|
|
196
|
+
try { fs.rmSync(contained(this.harness.root, renderPath), { force: true }); } catch { /* Preserve evidence for manual recovery. */ }
|
|
197
|
+
}
|
|
198
|
+
try { this.harness.finish(args.token, { ok: false, error: String(error.message), round, completed, operationResults }); } catch { /* A sealed state remains fail-closed if manifest publication failed. */ }
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
async run(code, prompt) {
|
|
203
|
+
const result = await this.upstream.callTool({ name: 'execute_blender_code', arguments: { code, user_prompt: prompt } });
|
|
204
|
+
const text = textOf(result);
|
|
205
|
+
const receipts = [...text.matchAll(/HARNESS_JSON:([^\r\n]+)/g)];
|
|
206
|
+
if (result.isError || receipts.length !== 1 || /Error executing code:/.test(text)) deny(`Blender execution failed: ${text.slice(0, 1500)}`);
|
|
207
|
+
const receipt = JSON.parse(receipts[0][1]);
|
|
208
|
+
if (receipt.ok !== true) deny('Blender operation receipt failed');
|
|
209
|
+
return receipt;
|
|
210
|
+
}
|
|
211
|
+
makeRound(project, reserved = []) {
|
|
212
|
+
const base = contained(this.harness.root, `${project}/Documents/Reviews`);
|
|
213
|
+
const index = fs.existsSync(path.join(base, 'README.md')) ? fs.readFileSync(path.join(base, 'README.md'), 'utf8') : '';
|
|
214
|
+
const names = [...fs.readdirSync(base), ...reserved, ...index.matchAll(/R(\d+)-\d{8}T\d{6}Z/g)].map((v) => typeof v === 'string' ? v : v[0]);
|
|
215
|
+
const next = Math.max(0, ...names.map((v) => Number(/^R(\d+)-/.exec(v)?.[1] ?? 0))) + 1;
|
|
216
|
+
const stamp = new Date().toISOString().replace(/[-:]/g, '').replace(/\.\d{3}Z$/, 'Z');
|
|
217
|
+
const round = `R${String(next).padStart(2, '0')}-${stamp}`;
|
|
218
|
+
fs.mkdirSync(contained(this.harness.root, `${project}/Documents/Reviews/${round}`, true));
|
|
219
|
+
return round;
|
|
220
|
+
}
|
|
221
|
+
result(value) { return { content: [{ type: 'text', text: JSON.stringify(value, null, 2) }] }; }
|
|
222
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import { BlenderProxy, firstJson } from './proxy.mjs';
|
|
6
|
+
import { fixture } from './test-fixture.mjs';
|
|
7
|
+
|
|
8
|
+
const result = (text) => ({ content: [{ type: 'text', text }] });
|
|
9
|
+
function upstream(f) {
|
|
10
|
+
const calls = [];
|
|
11
|
+
return {
|
|
12
|
+
calls,
|
|
13
|
+
async listTools() { return { tools: ['look', 'execute_blender_code', 'import_asset', 'get_scene_info'].map((name) => ({ name, inputSchema: { type: 'object' } })) }; },
|
|
14
|
+
async callTool(call) {
|
|
15
|
+
calls.push(call);
|
|
16
|
+
if (call.name === 'get_addon_status') return result(JSON.stringify({ up_to_date: true }));
|
|
17
|
+
if (call.name === 'get_scene_info') return result('Scene fixture\nCamera Fixture');
|
|
18
|
+
if (call.name !== 'execute_blender_code') return result('Read only');
|
|
19
|
+
const code = call.arguments.code;
|
|
20
|
+
if (code.includes('"operation": "check_assets"')) {
|
|
21
|
+
return result('HARNESS_JSON:' + JSON.stringify({ ok: true, operation: 'check_assets', strict: true, external: [], missing: [], packed: ['fixture.png'], libraries: [] }));
|
|
22
|
+
}
|
|
23
|
+
if (code.includes('external = bpy.utils.blend_paths')) {
|
|
24
|
+
return result('HARNESS_JSON:' + JSON.stringify({ ok: true, filepath: fs.existsSync(path.join(f.root, f.scene)) ? path.join(f.root, f.scene) : '', is_dirty: false, missing: [] }));
|
|
25
|
+
}
|
|
26
|
+
if (code.includes('bpy.ops.wm.save_as_mainfile')) {
|
|
27
|
+
f.write(f.scene, 'BLENDER fixture bytes');
|
|
28
|
+
return result('HARNESS_JSON:' + JSON.stringify({ ok: true, filepath: path.join(f.root, f.scene) }));
|
|
29
|
+
}
|
|
30
|
+
if (code.includes('bpy.ops.export_scene.gltf')) {
|
|
31
|
+
const exportPath = /"(exports\/[^"]+)"/.exec(code)?.[1];
|
|
32
|
+
assert.ok(exportPath, 'export output bound to generated path');
|
|
33
|
+
const bytes = Buffer.from('glTF' + '\u0002\u0000\u0000\u0000' + '\u0000'.repeat(8), 'binary');
|
|
34
|
+
f.write(`${f.project}/${exportPath}`, bytes);
|
|
35
|
+
return result('HARNESS_JSON:' + JSON.stringify({ ok: true, operation: 'export_scene', format: 'glb', path: exportPath, bytes: bytes.length, sha256: f.harness.hash(`${f.project}/${exportPath}`), scene: 'Scene' }));
|
|
36
|
+
}
|
|
37
|
+
if (code.includes('bpy.ops.render.render')) {
|
|
38
|
+
const render = /scene\.render\.filepath = "(\/\/[^"\n]+)"/.exec(code)?.[1];
|
|
39
|
+
assert.ok(render, 'render output bound to generated path');
|
|
40
|
+
f.write(`${f.project}/${render.slice(2)}`, Buffer.from([137, 80, 78, 71, 13, 10, 26, 10, 0]));
|
|
41
|
+
}
|
|
42
|
+
return result('HARNESS_JSON:' + JSON.stringify({ ok: true }));
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
async function execute(f, proxy, operation, payload = {}) {
|
|
47
|
+
const { token } = f.harness.issue(f.session, operation, payload);
|
|
48
|
+
f.harness.authorize(f.session, token, operation, payload);
|
|
49
|
+
return proxy.call('harness_execute', { token, operation, payload, user_prompt: 'Create fixture scene.' });
|
|
50
|
+
}
|
|
51
|
+
async function prepareSeal(f, proxy) {
|
|
52
|
+
f.harness.command(f.session, 'finalize');
|
|
53
|
+
const wip = JSON.parse((await execute(f, proxy, 'wip')).content[0].text);
|
|
54
|
+
f.harness.inspect(f.session, path.join(f.root, wip.change.wipRender.path), true);
|
|
55
|
+
}
|
|
56
|
+
const meshOperation = {
|
|
57
|
+
operation: 'create_mesh',
|
|
58
|
+
name: 'Cube',
|
|
59
|
+
primitive: 'cube',
|
|
60
|
+
location: [0, 0, 0],
|
|
61
|
+
scale: [1, 1, 1],
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
test('proxy hides raw mutation tools and rejects direct calls', async (t) => {
|
|
65
|
+
const f = fixture(t), p = new BlenderProxy(f.harness, upstream(f));
|
|
66
|
+
assert.deepEqual((await p.listTools()).tools.map((v) => v.name), ['look', 'get_scene_info', 'harness_execute', 'blender_harness_scene_info']);
|
|
67
|
+
await assert.rejects(p.call('execute_blender_code', { code: 'anything' }), /unregistered/);
|
|
68
|
+
await assert.rejects(p.call('harness_execute', { token: 'forged', operation: 'save', payload: {}, user_prompt: 'test' }), /authorization/);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('scene info is read-only and does not issue a ticket', async (t) => {
|
|
72
|
+
const f = fixture(t);
|
|
73
|
+
const mock = upstream(f);
|
|
74
|
+
const p = new BlenderProxy(f.harness, mock);
|
|
75
|
+
const response = await p.call('blender_harness_scene_info', { user_prompt: 'Inspect scenes.' });
|
|
76
|
+
assert.ok(response.content[0].text);
|
|
77
|
+
assert.equal(f.harness.command(f.session, 'status').change, null);
|
|
78
|
+
assert.ok(mock.calls.some((call) => call.name === 'execute_blender_code' && call.arguments.code.includes('payload = []')));
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('proxy needs hook receipt even when issued ticket exists', async (t) => {
|
|
82
|
+
const f = fixture(t); f.begin();
|
|
83
|
+
const p = new BlenderProxy(f.harness, upstream(f));
|
|
84
|
+
const { token } = f.harness.issue(f.session, 'save', {});
|
|
85
|
+
await assert.rejects(p.call('harness_execute', { token, operation: 'save', payload: {}, user_prompt: 'test' }), /authorization/);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('proxy seals immutable evidence, manifest and PNG, then checkpoint succeeds', async (t) => {
|
|
89
|
+
const f = fixture(t); f.begin();
|
|
90
|
+
const upstreamMock = upstream(f), p = new BlenderProxy(f.harness, upstreamMock);
|
|
91
|
+
await execute(f, p, 'apply', meshOperation);
|
|
92
|
+
await execute(f, p, 'save');
|
|
93
|
+
await prepareSeal(f, p);
|
|
94
|
+
const seal = JSON.parse((await execute(f, p, 'seal')).content[0].text);
|
|
95
|
+
assert.ok(fs.existsSync(seal.render));
|
|
96
|
+
assert.ok(seal.change.evidenceKey);
|
|
97
|
+
assert.throws(() => f.harness.command(f.session, 'self-review', { notes: 'not viewed' }), /inspect/);
|
|
98
|
+
f.harness.inspect(f.session, seal.render, true);
|
|
99
|
+
f.harness.command(f.session, 'self-review', { notes: 'Fixture image inspected, acceptance checks pass.' });
|
|
100
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(f.root, seal.manifest), 'utf8'));
|
|
101
|
+
assert.equal(manifest.active_goal, `${f.project}/${f.goal}`);
|
|
102
|
+
assert.equal(manifest.verdict, 'PASS');
|
|
103
|
+
assert.equal(manifest.operation_tasks.some((task) => Object.hasOwn(task, 'token')), false);
|
|
104
|
+
const { git } = await import('./engine.mjs');
|
|
105
|
+
git(f.root, ['add', '--', f.project]); f.commit();
|
|
106
|
+
assert.equal(f.harness.command(f.session, 'checkpoint').change, null);
|
|
107
|
+
assert.equal(f.harness.command(f.session, 'goal-complete').complete, true);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('strict check_assets receipt is embedded in the sealed manifest', async (t) => {
|
|
111
|
+
const f = fixture(t); f.begin();
|
|
112
|
+
f.write(`${f.project}/notes.txt`, 'asset check evidence\n');
|
|
113
|
+
const p = new BlenderProxy(f.harness, upstream(f));
|
|
114
|
+
await execute(f, p, 'apply', { operation: 'check_assets', strict: true });
|
|
115
|
+
await execute(f, p, 'save');
|
|
116
|
+
await prepareSeal(f, p);
|
|
117
|
+
const seal = JSON.parse((await execute(f, p, 'seal')).content[0].text);
|
|
118
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(f.root, seal.manifest), 'utf8'));
|
|
119
|
+
assert.equal(manifest.asset_check.strict, true);
|
|
120
|
+
assert.deepEqual(manifest.asset_check.packed, ['fixture.png']);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('proxy executes one batched apply ticket and saves each operation', async (t) => {
|
|
124
|
+
const f = fixture(t); f.begin();
|
|
125
|
+
const p = new BlenderProxy(f.harness, upstream(f));
|
|
126
|
+
const applied = JSON.parse((await execute(f, p, 'apply', { operations: [
|
|
127
|
+
meshOperation,
|
|
128
|
+
{ operation: 'transform', name: 'Cube', location: [0, 0, 1] },
|
|
129
|
+
] })).content[0].text);
|
|
130
|
+
assert.equal(applied.change.operations, 1);
|
|
131
|
+
const ledger = fs.readFileSync(path.join(f.root, f.project, 'Documents', 'TASKSTRACKER.md'), 'utf8');
|
|
132
|
+
assert.match(ledger, /apply x2/);
|
|
133
|
+
assert.match(ledger, /done/);
|
|
134
|
+
const taskDoc = fs.readFileSync(path.join(f.root, f.project, 'Documents', 'Tasks', 'T001', 'SUMMARY.md'), 'utf8');
|
|
135
|
+
assert.match(taskDoc, /create_mesh/);
|
|
136
|
+
assert.match(taskDoc, /Operation Results/);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('proxy verifies export receipts and records them on the project', async (t) => {
|
|
140
|
+
const f = fixture(t); f.begin();
|
|
141
|
+
const p = new BlenderProxy(f.harness, upstream(f));
|
|
142
|
+
await execute(f, p, 'apply', { operation: 'export_scene', format: 'glb', path: 'exports/room.glb' });
|
|
143
|
+
const status = f.harness.command(f.session, 'status');
|
|
144
|
+
assert.equal(status.change.operations, 1);
|
|
145
|
+
assert.equal(status.exports.length, 1);
|
|
146
|
+
assert.equal(status.exports[0].path, `${f.project}/exports/room.glb`);
|
|
147
|
+
assert.match(status.exports[0].sha256, /^[a-f0-9]{64}$/);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('proxy renders a WIP image without creating review evidence', async (t) => {
|
|
151
|
+
const f = fixture(t); f.begin();
|
|
152
|
+
const p = new BlenderProxy(f.harness, upstream(f));
|
|
153
|
+
await execute(f, p, 'apply', meshOperation);
|
|
154
|
+
const wip = JSON.parse((await execute(f, p, 'wip')).content[0].text);
|
|
155
|
+
assert.ok(wip.change.wipRender.path.startsWith(`${f.project}/renders/wip/`));
|
|
156
|
+
assert.ok(fs.existsSync(path.join(f.root, wip.change.wipRender.path)));
|
|
157
|
+
assert.equal(wip.change.evidence, undefined);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('proxy camera preflight fails before creating round artifacts and keeps recovery available', async (t) => {
|
|
161
|
+
const f = fixture(t); f.begin();
|
|
162
|
+
const noCamera = upstream(f);
|
|
163
|
+
const baseCall = noCamera.callTool.bind(noCamera);
|
|
164
|
+
noCamera.callTool = async (call) => {
|
|
165
|
+
if (call.name === 'execute_blender_code' && call.arguments.code.includes('scene camera is not set')) {
|
|
166
|
+
return { isError: true, content: [{ type: 'text', text: 'RuntimeError: scene camera is not set' }] };
|
|
167
|
+
}
|
|
168
|
+
return baseCall(call);
|
|
169
|
+
};
|
|
170
|
+
const p = new BlenderProxy(f.harness, noCamera);
|
|
171
|
+
await execute(f, p, 'apply', meshOperation);
|
|
172
|
+
f.harness.command(f.session, 'finalize');
|
|
173
|
+
await assert.rejects(execute(f, p, 'wip'), /camera/);
|
|
174
|
+
const status = f.harness.command(f.session, 'status');
|
|
175
|
+
assert.equal(status.change.sealed, false);
|
|
176
|
+
assert.equal(status.nextStep.phase, 'recover');
|
|
177
|
+
assert.equal(fs.existsSync(path.join(f.root, f.project, 'renders', 'final')), false);
|
|
178
|
+
const reopened = f.harness.recover(f.session, { reopen: true });
|
|
179
|
+
assert.equal(reopened.change.reopen, true);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('proxy fails closed on addon mismatch and preserves recovery', async (t) => {
|
|
183
|
+
const f = fixture(t); f.begin();
|
|
184
|
+
const bad = upstream(f);
|
|
185
|
+
bad.callTool = async () => result('{"up_to_date":false}');
|
|
186
|
+
const p = new BlenderProxy(f.harness, bad);
|
|
187
|
+
await assert.rejects(execute(f, p, 'save'), /addon mismatch/);
|
|
188
|
+
assert.equal(f.harness.command(f.session, 'status').change.sealed, false);
|
|
189
|
+
assert.ok(f.harness.issue(f.session, 'save', {}).token);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test('failed seal removes incomplete round artifacts and reserves its sequence', async (t) => {
|
|
193
|
+
const f = fixture(t); f.begin();
|
|
194
|
+
let failScene = false;
|
|
195
|
+
const bad = upstream(f);
|
|
196
|
+
bad.callTool = async (call) => {
|
|
197
|
+
if (call.name === 'get_addon_status') return result(JSON.stringify({ up_to_date: true }));
|
|
198
|
+
if (failScene && call.name === 'execute_blender_code' && call.arguments?.code?.includes('payload = []')) return { isError: true, content: [{ type: 'text', text: 'scene facts failed' }] };
|
|
199
|
+
return upstream(f).callTool(call);
|
|
200
|
+
};
|
|
201
|
+
const p = new BlenderProxy(f.harness, bad);
|
|
202
|
+
await execute(f, p, 'apply', meshOperation);
|
|
203
|
+
await execute(f, p, 'save');
|
|
204
|
+
await prepareSeal(f, p);
|
|
205
|
+
failScene = true;
|
|
206
|
+
await assert.rejects(execute(f, p, 'seal'), /Blender execution failed/);
|
|
207
|
+
const failed = f.harness.command(f.session, 'status').change;
|
|
208
|
+
assert.equal(failed.sealed, false);
|
|
209
|
+
assert.ok(fs.existsSync(path.join(f.root, f.project, 'Documents', 'Reviews')));
|
|
210
|
+
await assert.rejects(execute(f, p, 'seal'), /Blender execution failed/);
|
|
211
|
+
assert.equal(f.harness.command(f.session, 'status').change.sealed, false);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test('JSON extraction handles escaped strings and denies incomplete objects', () => {
|
|
215
|
+
assert.deepEqual(firstJson('prefix {"ok":true,"text":"} { \\""} suffix'), { ok: true, text: '} { "' });
|
|
216
|
+
assert.throws(() => firstJson('{"ok":'), /receipt/);
|
|
217
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
export const fail = (message) => { throw new Error(`Scaffold: ${message}`); };
|
|
7
|
+
export const DEFAULT_TEMPLATE_ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), 'templates', 'project');
|
|
8
|
+
|
|
9
|
+
const TEXT_EXTENSIONS = new Set(['.md', '.jsonc', '.json', '.txt', '.py', '.ps1', '.cmd', '.js', '.mjs']);
|
|
10
|
+
const TOKEN = /\{\{([A-Z_]+)\}\}/g;
|
|
11
|
+
|
|
12
|
+
function walk(directory, base = directory) {
|
|
13
|
+
const entries = fs.readdirSync(directory, { withFileTypes: true });
|
|
14
|
+
const files = [];
|
|
15
|
+
for (const entry of entries) {
|
|
16
|
+
const full = path.join(directory, entry.name);
|
|
17
|
+
if (entry.isDirectory()) files.push(...walk(full, base));
|
|
18
|
+
else if (entry.isFile()) files.push(full);
|
|
19
|
+
}
|
|
20
|
+
return files;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isText(file) {
|
|
24
|
+
return path.basename(file) === '.gitignore' || TEXT_EXTENSIONS.has(path.extname(file).toLowerCase());
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function render(text, replacements, name) {
|
|
28
|
+
return text.replace(TOKEN, (token, key) => {
|
|
29
|
+
if (!(key in replacements)) fail(`unknown template token ${token} in ${name}`);
|
|
30
|
+
return replacements[key];
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function scaffold(root, { name, description, goal, goalTitle, dryRun = false, date = new Date(), templateRoot = DEFAULT_TEMPLATE_ROOT }) {
|
|
35
|
+
if (typeof name !== 'string' || !/^[A-Za-z0-9](?:[A-Za-z0-9 _-]*[A-Za-z0-9_-])?$/.test(name) || /^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])$/i.test(name)) {
|
|
36
|
+
fail('invalid project name; use letters, numbers, internal spaces, hyphens, or underscores, and avoid Windows device names');
|
|
37
|
+
}
|
|
38
|
+
const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
|
|
39
|
+
if (!slug) fail('project name must contain at least one letter or number');
|
|
40
|
+
|
|
41
|
+
const projectsRoot = path.join(root, 'Blender');
|
|
42
|
+
const resolvedTemplateRoot = path.resolve(templateRoot);
|
|
43
|
+
if (!fs.existsSync(projectsRoot) || !fs.statSync(projectsRoot).isDirectory()) fail(`project collection not found: ${projectsRoot}`);
|
|
44
|
+
if (fs.existsSync(projectsRoot) && fs.lstatSync(projectsRoot).isSymbolicLink()) fail('project collection must not be a symbolic link or junction');
|
|
45
|
+
if (!fs.existsSync(resolvedTemplateRoot) || !fs.statSync(resolvedTemplateRoot).isDirectory()) fail(`project template not found: ${resolvedTemplateRoot}`);
|
|
46
|
+
const destination = path.join(projectsRoot, name);
|
|
47
|
+
if (fs.existsSync(destination)) fail(`project already exists: ${destination}`);
|
|
48
|
+
|
|
49
|
+
const replacements = {
|
|
50
|
+
PROJECT_NAME: name,
|
|
51
|
+
PROJECT_SLUG: slug,
|
|
52
|
+
DATE: `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`,
|
|
53
|
+
DESCRIPTION: description || 'TBD - replace with the project purpose.',
|
|
54
|
+
GOAL: goal || 'TBD - replace with the first design request.',
|
|
55
|
+
GOAL_TITLE: goalTitle || 'Project Brief',
|
|
56
|
+
};
|
|
57
|
+
const files = walk(resolvedTemplateRoot).map((file) => ({
|
|
58
|
+
source: file,
|
|
59
|
+
relative: path.relative(resolvedTemplateRoot, file),
|
|
60
|
+
text: isText(file) ? render(fs.readFileSync(file, 'utf8'), replacements, file) : null,
|
|
61
|
+
}));
|
|
62
|
+
|
|
63
|
+
if (dryRun) return { dryRun: true, destination, slug, files: files.map((file) => file.relative) };
|
|
64
|
+
|
|
65
|
+
const staging = path.join(projectsRoot, `.scaffold-${crypto.randomUUID().replaceAll('-', '')}`);
|
|
66
|
+
let owned = false;
|
|
67
|
+
try {
|
|
68
|
+
fs.mkdirSync(staging);
|
|
69
|
+
owned = true;
|
|
70
|
+
for (const file of files) {
|
|
71
|
+
const target = path.join(staging, file.relative);
|
|
72
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
73
|
+
if (file.text === null) fs.copyFileSync(file.source, target);
|
|
74
|
+
else fs.writeFileSync(target, file.text);
|
|
75
|
+
}
|
|
76
|
+
fs.renameSync(staging, destination);
|
|
77
|
+
owned = false;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (owned) fs.rmSync(staging, { recursive: true, force: true });
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
return { destination, slug };
|
|
83
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import test from 'node:test';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { DEFAULT_TEMPLATE_ROOT, scaffold } from './scaffold.mjs';
|
|
8
|
+
|
|
9
|
+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
|
|
10
|
+
const TEMPLATE = path.join(ROOT, 'tools', 'harness', 'templates', 'project');
|
|
11
|
+
const tempBase = path.join(os.tmpdir(), 'kilo');
|
|
12
|
+
fs.mkdirSync(tempBase, { recursive: true });
|
|
13
|
+
|
|
14
|
+
function workspace(t) {
|
|
15
|
+
const root = fs.mkdtempSync(path.join(tempBase, 'scaffold-'));
|
|
16
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
17
|
+
fs.mkdirSync(path.join(root, 'Blender'), { recursive: true });
|
|
18
|
+
return root;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function templateCopy(t) {
|
|
22
|
+
const root = fs.mkdtempSync(path.join(tempBase, 'scaffold-template-'));
|
|
23
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
24
|
+
const template = path.join(root, 'project');
|
|
25
|
+
fs.cpSync(TEMPLATE, template, { recursive: true });
|
|
26
|
+
return template;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test('scaffold template is owned by the harness', () => {
|
|
30
|
+
assert.equal(DEFAULT_TEMPLATE_ROOT, TEMPLATE);
|
|
31
|
+
assert.ok(fs.existsSync(path.join(TEMPLATE, 'README.md')));
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('scaffold renders tokens, hidden files, and binaries', (t) => {
|
|
35
|
+
const root = workspace(t);
|
|
36
|
+
const result = scaffold(root, { name: 'Cozy Room', description: 'A room.', goal: 'Build it.', goalTitle: 'Brief', date: new Date(2026, 9, 31) });
|
|
37
|
+
const project = path.join(root, 'Blender', 'Cozy Room');
|
|
38
|
+
assert.equal(result.destination, project);
|
|
39
|
+
assert.equal(result.slug, 'cozy-room');
|
|
40
|
+
const readme = fs.readFileSync(path.join(project, 'README.md'), 'utf8');
|
|
41
|
+
assert.match(readme, /Cozy Room/);
|
|
42
|
+
assert.match(readme, /2026-10-31/);
|
|
43
|
+
assert.doesNotMatch(readme, /\{\{/);
|
|
44
|
+
assert.ok(fs.existsSync(path.join(project, '.gitignore')));
|
|
45
|
+
assert.ok(fs.existsSync(path.join(project, 'Documents', 'TASKSTRACKER.md')));
|
|
46
|
+
assert.ok(fs.existsSync(path.join(project, 'Documents', 'Tasks', 'README.md')));
|
|
47
|
+
assert.ok(fs.existsSync(path.join(project, 'Documents', 'INTAKE.md')));
|
|
48
|
+
assert.match(fs.readFileSync(path.join(project, 'Documents', 'INTAKE.md'), 'utf8'), /Intake — Cozy Room/);
|
|
49
|
+
assert.equal(fs.existsSync(path.join(project, 'Documents', 'TASKS.md')), false);
|
|
50
|
+
assert.ok(fs.existsSync(path.join(project, 'exports', '.gitkeep')));
|
|
51
|
+
assert.equal(fs.readdirSync(path.join(root, 'Blender')).some((name) => name.startsWith('.scaffold-')), false);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('scaffold dry run writes nothing', (t) => {
|
|
55
|
+
const root = workspace(t);
|
|
56
|
+
const result = scaffold(root, { name: 'Dry Run', dryRun: true });
|
|
57
|
+
assert.equal(result.dryRun, true);
|
|
58
|
+
assert.equal(fs.existsSync(path.join(root, 'Blender', 'Dry Run')), false);
|
|
59
|
+
assert.ok(result.files.includes('README.md'));
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('scaffold rejects invalid names, duplicates, and unknown tokens', (t) => {
|
|
63
|
+
const root = workspace(t);
|
|
64
|
+
const template = templateCopy(t);
|
|
65
|
+
assert.throws(() => scaffold(root, { name: 'CON' }), /invalid project name/);
|
|
66
|
+
assert.throws(() => scaffold(root, { name: 'Trailing ' }), /invalid project name/);
|
|
67
|
+
scaffold(root, { name: 'Existing' });
|
|
68
|
+
assert.throws(() => scaffold(root, { name: 'Existing' }), /already exists/);
|
|
69
|
+
const templateFile = path.join(template, 'Documents', 'ASSETS.md');
|
|
70
|
+
fs.writeFileSync(templateFile, '{{UNKNOWN_TOKEN}}\n');
|
|
71
|
+
assert.throws(() => scaffold(root, { name: 'Broken', templateRoot: template }), /unknown template token/);
|
|
72
|
+
assert.equal(fs.existsSync(path.join(root, 'Blender', 'Broken')), false);
|
|
73
|
+
assert.equal(fs.readdirSync(path.join(root, 'Blender')).some((name) => name.startsWith('.scaffold-')), false);
|
|
74
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
4
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
5
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
6
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
7
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
8
|
+
import { Harness } from './engine.mjs';
|
|
9
|
+
import { BlenderProxy } from './proxy.mjs';
|
|
10
|
+
import { workspaceRoot } from './workspace.mjs';
|
|
11
|
+
|
|
12
|
+
const root = workspaceRoot(path.dirname(fileURLToPath(import.meta.url)));
|
|
13
|
+
const harness = new Harness(root);
|
|
14
|
+
const client = new Client({ name: 'blender-workflow-proxy', version: '1.0.0' });
|
|
15
|
+
const transport = new StdioClientTransport({ command: 'uvx', args: ['mcp-for-blender==2.2.6'], cwd: root,
|
|
16
|
+
env: Object.fromEntries(Object.entries(process.env).filter(([, v]) => v !== undefined)), stderr: 'inherit' });
|
|
17
|
+
await client.connect(transport);
|
|
18
|
+
const proxy = new BlenderProxy(harness, client);
|
|
19
|
+
const server = new Server({ name: 'guarded-blender', version: '1.0.0' }, { capabilities: { tools: {} }, instructions:
|
|
20
|
+
'Production writes require blender_workflow registration, bounded change and one-time operation ticket. Raw Python is unavailable. Seal, inspect with look, review, obtain required approval, commit and checkpoint before next change. Unsupported operations stop.' });
|
|
21
|
+
server.setRequestHandler(ListToolsRequestSchema, () => proxy.listTools());
|
|
22
|
+
server.setRequestHandler(CallToolRequestSchema, (request) => proxy.call(request.params.name, request.params.arguments));
|
|
23
|
+
server.onclose = () => { void client.close(); };
|
|
24
|
+
await server.connect(new StdioServerTransport());
|