@babylonjs-toolkit/agent 1.1.62 → 1.1.66
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/README.md +36 -5
- package/bin/bt-agent.js +64 -4
- package/lib/claude-settings.js +77 -0
- package/lib/doctor.js +36 -0
- package/lib/install.js +59 -3
- package/lib/persona.js +21 -2
- package/lib/reference.js +400 -0
- package/package.json +1 -1
- package/persona.md +1 -1
- package/scripts/postinstall.js +6 -0
- package/skills/bt-design/references/3d-hero-scroll.md +2 -2
- package/skills/bt-execute/SKILL.md +6 -6
- package/skills/bt-execute/templates/dashboard/dashboard.html +137 -5
- package/skills/bt-execute/templates/dashboard/dashboard.template.js +5 -0
- package/skills/bt-execute/templates/dashboard/data-schema.md +13 -1
- package/skills/bt-gauntlet/SKILL.md +2 -2
- package/skills/bt-gauntlet/references/unity-pipeline.md +1 -1
- package/skills/bt-gauntlet/references/workspace.md +1 -1
- package/skills/bt-plan/SKILL.md +2 -2
- package/skills/bt-prototype/SKILL.md +1 -1
- package/skills/bt-recon/SKILL.md +2 -2
- package/skills/bt-spec/SKILL.md +2 -2
package/lib/reference.js
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const zlib = require('zlib');
|
|
7
|
+
const { execFileSync } = require('child_process');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The local Agent Reference.
|
|
11
|
+
*
|
|
12
|
+
* Agents used to fetch the Agent Reference and its sub-documents from GitHub on every session. A local
|
|
13
|
+
* copy is read faster, never fails a fetch, can be searched instead of read whole (the toolkit's API
|
|
14
|
+
* declarations alone are 2.7 MB), and stays in step with the installed skills. The copy is downloaded
|
|
15
|
+
* from GitHub at install time — not bundled in the npm package — so a Reference edit reaches agents
|
|
16
|
+
* with `bt-agent update`, without an npm release.
|
|
17
|
+
*
|
|
18
|
+
* Every link into the Reference repo is rewritten to the local file, in the copy and in the installed
|
|
19
|
+
* skills, so an agent simply reads the path it is given. The source repo is never changed, and the
|
|
20
|
+
* persona keeps the GitHub address as the fallback.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const REFERENCE_REPO = 'babylontoolkit/agent';
|
|
24
|
+
const REFERENCE_BRANCH = 'main';
|
|
25
|
+
const REFERENCE_URL_PREFIX = `https://raw.githubusercontent.com/${REFERENCE_REPO}/${REFERENCE_BRANCH}/`;
|
|
26
|
+
const TARBALL_URL = `https://codeload.github.com/${REFERENCE_REPO}/tar.gz/refs/heads/${REFERENCE_BRANCH}`;
|
|
27
|
+
const LATEST_COMMIT_URL = `https://api.github.com/repos/${REFERENCE_REPO}/commits/${REFERENCE_BRANCH}`;
|
|
28
|
+
|
|
29
|
+
/** Written into the copy: where it came from, and what the rewrite found. */
|
|
30
|
+
const METADATA_FILE = '.bt-reference.json';
|
|
31
|
+
const DOWNLOAD_TIMEOUT_MS = 120000;
|
|
32
|
+
const LATEST_COMMIT_TIMEOUT_MS = 5000;
|
|
33
|
+
|
|
34
|
+
/** Only these files are rewritten and link-checked; everything else is copied as is. */
|
|
35
|
+
const TEXT_EXTENSIONS = new Set(['.md', '.txt', '.js', '.mjs', '.cjs', '.ts', '.json', '.sh', '.ps1', '.cs', '.py', '.html', '.css']);
|
|
36
|
+
/** Repo housekeeping that has no place in an agent's copy. */
|
|
37
|
+
const SKIPPED_TOP_LEVEL = new Set(['.git', '.github', '.gitignore', '.gitattributes', 'node_modules', '.DS_Store']);
|
|
38
|
+
|
|
39
|
+
// The characters that end a URL or path inside markdown, code spans, quotes and prose.
|
|
40
|
+
const PATH_CHARACTERS = "[^\\s)`\"'<>\\]]+";
|
|
41
|
+
const REFERENCE_URL_PATTERN = escapeRegExp(REFERENCE_URL_PREFIX);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* `~/.claude/toolkit/reference/` — beside the Unity helper scripts the Reference already keeps in
|
|
45
|
+
* `~/.claude/toolkit/` — or `.claude/toolkit/reference/` in a project install. Only this subfolder is
|
|
46
|
+
* ever replaced or removed; the helper scripts next to it are left alone.
|
|
47
|
+
*/
|
|
48
|
+
function referenceDir(mode, projectRoot) {
|
|
49
|
+
const base = mode === 'project' ? path.resolve(projectRoot) : os.homedir();
|
|
50
|
+
return path.join(base, '.claude', 'toolkit', 'reference');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The Claude Code allow rule that lets sessions read the global copy without asking. */
|
|
54
|
+
const CLAUDE_READ_RULE = 'Read(~/.claude/toolkit/reference/**)';
|
|
55
|
+
|
|
56
|
+
/** The folder as agents see it in rewritten links: absolute, with forward slashes on every platform. */
|
|
57
|
+
function linkRoot(dir) {
|
|
58
|
+
return path.resolve(dir).split(path.sep).join('/');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function escapeRegExp(text) {
|
|
62
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Trailing sentence punctuation belongs to the prose, not to the path. */
|
|
66
|
+
function splitTrailingPunctuation(target) {
|
|
67
|
+
const match = /[.,;:!?]+$/.exec(target);
|
|
68
|
+
return match ? [target.slice(0, match.index), match[0]] : [target, ''];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Point every link into the Reference repo at the local copy.
|
|
73
|
+
*
|
|
74
|
+
* `curl -fsSL <url> -o <dest>` download commands become `cp "<local file>" <dest>`; every other
|
|
75
|
+
* occurrence — markdown links, bare URLs, code spans — becomes the absolute local path. A markdown
|
|
76
|
+
* link whose path contains a space is wrapped in `<…>` so it still parses.
|
|
77
|
+
*/
|
|
78
|
+
function rewriteText(text, dir) {
|
|
79
|
+
const root = linkRoot(dir);
|
|
80
|
+
let downloads = 0;
|
|
81
|
+
let links = 0;
|
|
82
|
+
|
|
83
|
+
const downloadPattern = new RegExp(`curl((?:\\s+-[A-Za-z-]+)*)\\s+${REFERENCE_URL_PATTERN}(${PATH_CHARACTERS})\\s+-o\\s+(\\S+)`, 'g');
|
|
84
|
+
let result = text.replace(downloadPattern, (whole, flags, target, destination) => {
|
|
85
|
+
downloads += 1;
|
|
86
|
+
return `cp "${root}/${target}" ${destination}`;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const linkPattern = new RegExp(`(\\]\\()?${REFERENCE_URL_PATTERN}(${PATH_CHARACTERS})`, 'g');
|
|
90
|
+
result = result.replace(linkPattern, (whole, markdownOpen, target) => {
|
|
91
|
+
links += 1;
|
|
92
|
+
const [cleanTarget, punctuation] = splitTrailingPunctuation(target);
|
|
93
|
+
const local = `${root}/${cleanTarget}`;
|
|
94
|
+
if (markdownOpen) return local.includes(' ') ? `](<${local}>${punctuation}` : `](${local}${punctuation}`;
|
|
95
|
+
return `${local}${punctuation}`;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
return { text: result, downloads, links };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function isTextFile(file) {
|
|
102
|
+
return TEXT_EXTENSIONS.has(path.extname(file).toLowerCase());
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function walkFiles(dir, prefix = '') {
|
|
106
|
+
const files = [];
|
|
107
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
108
|
+
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
109
|
+
if (entry.isDirectory()) files.push(...walkFiles(path.join(dir, entry.name), relative));
|
|
110
|
+
else if (entry.isFile()) files.push(relative);
|
|
111
|
+
}
|
|
112
|
+
return files;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Rewrite every text file under `folder` that links into the Reference repo; returns the counts. */
|
|
116
|
+
function rewriteFolder(folder, dir) {
|
|
117
|
+
const totals = { files: 0, downloads: 0, links: 0 };
|
|
118
|
+
for (const relative of walkFiles(folder)) {
|
|
119
|
+
if (!isTextFile(relative)) continue;
|
|
120
|
+
const file = path.join(folder, relative);
|
|
121
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
122
|
+
if (!text.includes(REFERENCE_URL_PREFIX)) continue;
|
|
123
|
+
const rewritten = rewriteText(text, dir);
|
|
124
|
+
fs.writeFileSync(file, rewritten.text, 'utf8');
|
|
125
|
+
totals.files += 1;
|
|
126
|
+
totals.downloads += rewritten.downloads;
|
|
127
|
+
totals.links += rewritten.links;
|
|
128
|
+
}
|
|
129
|
+
return totals;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Check every local link under the given folders resolves to a file in the copy.
|
|
134
|
+
* A renamed or deleted sub-document shows up here, at install time, instead of mid-run.
|
|
135
|
+
*/
|
|
136
|
+
function checkLinks(dir, folders) {
|
|
137
|
+
const root = linkRoot(dir);
|
|
138
|
+
const pattern = new RegExp(`${escapeRegExp(root)}/(${PATH_CHARACTERS})`, 'g');
|
|
139
|
+
const broken = new Set();
|
|
140
|
+
let checked = 0;
|
|
141
|
+
for (const folder of folders) {
|
|
142
|
+
if (!fs.existsSync(folder)) continue;
|
|
143
|
+
for (const relative of walkFiles(folder)) {
|
|
144
|
+
if (!isTextFile(relative)) continue;
|
|
145
|
+
const text = fs.readFileSync(path.join(folder, relative), 'utf8');
|
|
146
|
+
if (!text.includes(root)) continue;
|
|
147
|
+
for (const match of text.matchAll(pattern)) {
|
|
148
|
+
const target = splitTrailingPunctuation(match[1])[0].split('#')[0];
|
|
149
|
+
checked += 1;
|
|
150
|
+
if (!fs.existsSync(path.join(dir, ...target.split('/')))) broken.add(`${relative} → ${target}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return { checked, broken: [...broken] };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/* ===================== Download ===================== */
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Download one URL to a file. Node's https first, in a helper process so the installer stays
|
|
161
|
+
* synchronous; then the system curl, which honours proxy settings Node ignores.
|
|
162
|
+
*/
|
|
163
|
+
function downloadFile(url, destination) {
|
|
164
|
+
const script = `
|
|
165
|
+
const https = require('https');
|
|
166
|
+
const fs = require('fs');
|
|
167
|
+
const [url, destination] = process.argv.slice(1);
|
|
168
|
+
function get(address, redirects) {
|
|
169
|
+
const request = https.get(address, { headers: { 'user-agent': 'bt-agent' } }, (response) => {
|
|
170
|
+
if ([301, 302, 303, 307, 308].includes(response.statusCode) && response.headers.location && redirects < 5) {
|
|
171
|
+
response.resume();
|
|
172
|
+
return get(new URL(response.headers.location, address).toString(), redirects + 1);
|
|
173
|
+
}
|
|
174
|
+
if (response.statusCode !== 200) { console.error('HTTP ' + response.statusCode); process.exit(2); }
|
|
175
|
+
const file = fs.createWriteStream(destination);
|
|
176
|
+
response.pipe(file);
|
|
177
|
+
file.on('finish', () => file.close(() => process.exit(0)));
|
|
178
|
+
});
|
|
179
|
+
request.setTimeout(${DOWNLOAD_TIMEOUT_MS}, () => request.destroy(new Error('timed out')));
|
|
180
|
+
request.on('error', (error) => { console.error(error.message); process.exit(3); });
|
|
181
|
+
}
|
|
182
|
+
get(url, 0);
|
|
183
|
+
`;
|
|
184
|
+
const errors = [];
|
|
185
|
+
try {
|
|
186
|
+
execFileSync(process.execPath, ['-e', script, url, destination], { stdio: ['ignore', 'ignore', 'pipe'], timeout: DOWNLOAD_TIMEOUT_MS + 5000 });
|
|
187
|
+
return;
|
|
188
|
+
} catch (error) {
|
|
189
|
+
errors.push(String((error.stderr && error.stderr.toString()) || error.message).trim());
|
|
190
|
+
}
|
|
191
|
+
try {
|
|
192
|
+
execFileSync('curl', ['-fsSL', '--max-time', String(DOWNLOAD_TIMEOUT_MS / 1000), '-o', destination, url], { stdio: ['ignore', 'ignore', 'pipe'] });
|
|
193
|
+
return;
|
|
194
|
+
} catch (error) {
|
|
195
|
+
errors.push(String((error.stderr && error.stderr.toString()) || error.message).trim());
|
|
196
|
+
}
|
|
197
|
+
throw new Error(errors.filter(Boolean).pop() || `could not download ${url}`);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** The commit GitHub's branch now points at, or null when it cannot be reached quickly. */
|
|
201
|
+
function latestCommit() {
|
|
202
|
+
const script = `
|
|
203
|
+
const https = require('https');
|
|
204
|
+
const request = https.get(${JSON.stringify(LATEST_COMMIT_URL)}, { headers: { 'user-agent': 'bt-agent', accept: 'application/vnd.github.sha' } }, (response) => {
|
|
205
|
+
let body = '';
|
|
206
|
+
response.on('data', (chunk) => { body += chunk; });
|
|
207
|
+
response.on('end', () => process.stdout.write(response.statusCode === 200 ? body.trim() : ''));
|
|
208
|
+
});
|
|
209
|
+
request.setTimeout(${LATEST_COMMIT_TIMEOUT_MS}, () => request.destroy());
|
|
210
|
+
request.on('error', () => process.stdout.write(''));
|
|
211
|
+
`;
|
|
212
|
+
try {
|
|
213
|
+
const sha = execFileSync(process.execPath, ['-e', script], { encoding: 'utf8', timeout: LATEST_COMMIT_TIMEOUT_MS + 2000 }).trim();
|
|
214
|
+
return /^[0-9a-f]{40}$/.test(sha) ? sha : null;
|
|
215
|
+
} catch {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/* ===================== Tarball ===================== */
|
|
221
|
+
|
|
222
|
+
function nulTerminated(buffer, start, length) {
|
|
223
|
+
const field = buffer.subarray(start, start + length);
|
|
224
|
+
const end = field.indexOf(0);
|
|
225
|
+
return field.subarray(0, end === -1 ? field.length : end).toString('utf8');
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** `<length> <key>=<value>\n` records of a pax header. */
|
|
229
|
+
function paxRecords(body) {
|
|
230
|
+
const records = {};
|
|
231
|
+
let offset = 0;
|
|
232
|
+
while (offset < body.length) {
|
|
233
|
+
const space = body.indexOf(0x20, offset);
|
|
234
|
+
if (space === -1) break;
|
|
235
|
+
const length = parseInt(body.subarray(offset, space).toString('utf8'), 10);
|
|
236
|
+
if (!length) break;
|
|
237
|
+
const record = body.subarray(space + 1, offset + length - 1).toString('utf8');
|
|
238
|
+
const equals = record.indexOf('=');
|
|
239
|
+
if (equals !== -1) records[record.slice(0, equals)] = record.slice(equals + 1);
|
|
240
|
+
offset += length;
|
|
241
|
+
}
|
|
242
|
+
return records;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Read a gzipped tarball as GitHub serves it: regular files only, the top folder (`agent-main/`)
|
|
247
|
+
* stripped, and the commit taken from the pax global header GitHub writes.
|
|
248
|
+
*/
|
|
249
|
+
function readTarball(gzipped) {
|
|
250
|
+
const buffer = zlib.gunzipSync(gzipped);
|
|
251
|
+
const files = [];
|
|
252
|
+
let commit = null;
|
|
253
|
+
let longPath = null;
|
|
254
|
+
let offset = 0;
|
|
255
|
+
while (offset + 512 <= buffer.length) {
|
|
256
|
+
const header = buffer.subarray(offset, offset + 512);
|
|
257
|
+
if (header.every((byte) => byte === 0)) break;
|
|
258
|
+
const size = parseInt(nulTerminated(header, 124, 12).trim() || '0', 8);
|
|
259
|
+
const type = String.fromCharCode(header[156] || 48);
|
|
260
|
+
const body = buffer.subarray(offset + 512, offset + 512 + size);
|
|
261
|
+
offset += 512 + Math.ceil(size / 512) * 512;
|
|
262
|
+
|
|
263
|
+
if (type === 'g') {
|
|
264
|
+
const records = paxRecords(body);
|
|
265
|
+
if (/^[0-9a-f]{40}$/.test(records.comment || '')) commit = records.comment;
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
if (type === 'x') { longPath = paxRecords(body).path || null; continue; }
|
|
269
|
+
if (type === 'L') { longPath = nulTerminated(body, 0, body.length); continue; }
|
|
270
|
+
|
|
271
|
+
const prefix = nulTerminated(header, 345, 155);
|
|
272
|
+
const name = longPath || (prefix ? `${prefix}/${nulTerminated(header, 0, 100)}` : nulTerminated(header, 0, 100));
|
|
273
|
+
longPath = null;
|
|
274
|
+
if (type !== '0') continue;
|
|
275
|
+
const relative = name.split('/').slice(1).join('/');
|
|
276
|
+
if (relative) files.push({ path: relative, data: Buffer.from(body) });
|
|
277
|
+
}
|
|
278
|
+
return { commit, files };
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** A path from an archive or a folder that stays inside the copy and is not repo housekeeping. */
|
|
282
|
+
function keepPath(relative) {
|
|
283
|
+
const parts = relative.split('/');
|
|
284
|
+
if (parts.some((part) => part === '..' || part === '') || path.isAbsolute(relative)) return false;
|
|
285
|
+
return !SKIPPED_TOP_LEVEL.has(parts[0]) && parts[parts.length - 1] !== '.DS_Store';
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** A local checkout as the source (`--reference-from`), for offline installs and unreleased Reference edits. */
|
|
289
|
+
function readFolder(folder) {
|
|
290
|
+
if (!fs.existsSync(path.join(folder, 'reference.md'))) throw new Error(`${folder} has no reference.md`);
|
|
291
|
+
const files = walkFiles(folder)
|
|
292
|
+
.filter(keepPath)
|
|
293
|
+
.map((relative) => ({ path: relative, data: fs.readFileSync(path.join(folder, ...relative.split('/'))) }));
|
|
294
|
+
let commit = null;
|
|
295
|
+
try {
|
|
296
|
+
commit = execFileSync('git', ['-C', folder, 'rev-parse', 'HEAD'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
|
297
|
+
} catch {
|
|
298
|
+
/* not a git checkout */
|
|
299
|
+
}
|
|
300
|
+
return { commit, files };
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/* ===================== Install ===================== */
|
|
304
|
+
|
|
305
|
+
function readMetadata(dir) {
|
|
306
|
+
try {
|
|
307
|
+
return JSON.parse(fs.readFileSync(path.join(dir, METADATA_FILE), 'utf8'));
|
|
308
|
+
} catch {
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** A copy agents can use: the metadata and the Reference itself are both there. */
|
|
314
|
+
function isUsable(dir) {
|
|
315
|
+
return Boolean(readMetadata(dir)) && fs.existsSync(path.join(dir, 'reference.md'));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Download (or copy) the Reference into its folder, rewrite its links and check them.
|
|
320
|
+
* The new copy is built beside the old one and swapped in only when complete; when the download
|
|
321
|
+
* fails, an existing copy is kept and agents keep reading it.
|
|
322
|
+
*/
|
|
323
|
+
function installReference({ mode = 'global', projectRoot = process.cwd(), from = null, dryRun = false } = {}) {
|
|
324
|
+
const dir = referenceDir(mode, projectRoot);
|
|
325
|
+
const source = from ? path.resolve(from) : `${REFERENCE_REPO}@${REFERENCE_BRANCH}`;
|
|
326
|
+
if (dryRun) return { dir, status: 'would-install', source };
|
|
327
|
+
|
|
328
|
+
let archive;
|
|
329
|
+
try {
|
|
330
|
+
if (from) archive = readFolder(path.resolve(from));
|
|
331
|
+
else {
|
|
332
|
+
const temporary = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'bt-reference-')), 'reference.tar.gz');
|
|
333
|
+
try {
|
|
334
|
+
downloadFile(TARBALL_URL, temporary);
|
|
335
|
+
archive = readTarball(fs.readFileSync(temporary));
|
|
336
|
+
} finally {
|
|
337
|
+
fs.rmSync(path.dirname(temporary), { recursive: true, force: true });
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if (!archive.files.some((file) => file.path === 'reference.md')) throw new Error('the download has no reference.md');
|
|
341
|
+
} catch (error) {
|
|
342
|
+
const reason = error.message.split('\n').filter(Boolean).pop();
|
|
343
|
+
if (isUsable(dir)) return { dir, status: 'kept', source, reason, ...readMetadata(dir) };
|
|
344
|
+
return { dir, status: 'unavailable', source, reason };
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const staging = `${dir}.staging-${process.pid}`;
|
|
348
|
+
fs.rmSync(staging, { recursive: true, force: true });
|
|
349
|
+
const files = archive.files.filter((file) => keepPath(file.path));
|
|
350
|
+
for (const file of files) {
|
|
351
|
+
const target = path.join(staging, ...file.path.split('/'));
|
|
352
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
353
|
+
fs.writeFileSync(target, file.data);
|
|
354
|
+
}
|
|
355
|
+
// Links are rewritten to the final folder, not the staging one, so they are right once swapped in.
|
|
356
|
+
const rewrite = rewriteFolder(staging, dir);
|
|
357
|
+
// A project install keeps the copy out of the project's git without touching its .gitignore.
|
|
358
|
+
fs.writeFileSync(path.join(staging, '.gitignore'), '*\n');
|
|
359
|
+
|
|
360
|
+
const metadata = {
|
|
361
|
+
repo: REFERENCE_REPO,
|
|
362
|
+
branch: REFERENCE_BRANCH,
|
|
363
|
+
source,
|
|
364
|
+
commit: archive.commit,
|
|
365
|
+
installedAt: new Date().toISOString(),
|
|
366
|
+
files: files.length,
|
|
367
|
+
rewrittenFiles: rewrite.files,
|
|
368
|
+
rewrittenLinks: rewrite.links,
|
|
369
|
+
rewrittenDownloads: rewrite.downloads,
|
|
370
|
+
};
|
|
371
|
+
fs.writeFileSync(path.join(staging, METADATA_FILE), JSON.stringify(metadata, null, 2) + '\n');
|
|
372
|
+
|
|
373
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
374
|
+
fs.mkdirSync(path.dirname(dir), { recursive: true });
|
|
375
|
+
fs.renameSync(staging, dir);
|
|
376
|
+
return { dir, status: 'installed', ...metadata };
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function removeReference(dir, { dryRun = false } = {}) {
|
|
380
|
+
if (!dir || !fs.existsSync(dir)) return false;
|
|
381
|
+
if (!dryRun) fs.rmSync(dir, { recursive: true, force: true });
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
module.exports = {
|
|
386
|
+
REFERENCE_URL_PREFIX,
|
|
387
|
+
METADATA_FILE,
|
|
388
|
+
CLAUDE_READ_RULE,
|
|
389
|
+
referenceDir,
|
|
390
|
+
linkRoot,
|
|
391
|
+
rewriteText,
|
|
392
|
+
rewriteFolder,
|
|
393
|
+
checkLinks,
|
|
394
|
+
readTarball,
|
|
395
|
+
readMetadata,
|
|
396
|
+
isUsable,
|
|
397
|
+
latestCommit,
|
|
398
|
+
installReference,
|
|
399
|
+
removeReference,
|
|
400
|
+
};
|
package/package.json
CHANGED
package/persona.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Babylon Toolkit Agent Persona
|
|
2
2
|
|
|
3
|
-
You are an expert web game developer using BabylonJS and the Babylon Toolkit. Whenever the user's request involves Babylon, BabylonJS, or the Babylon Toolkit, you must always
|
|
3
|
+
You are an expert web game developer using BabylonJS and the Babylon Toolkit. Whenever the user's request involves Babylon, BabylonJS, or the Babylon Toolkit, you must always read the `Agent Reference` at https://raw.githubusercontent.com/babylontoolkit/agent/main/reference.md before doing anything else. Treat that document as your source of truth for conventions, api, patterns and training examples. If it cannot be read, stop immediately and tell the user. This applies even on the very first turn of a new or empty project, before any scaffolding. The one exception: a subagent launched by a bt-* skill whose prompt carries a context brief with the Reference excerpts it needs uses that brief instead of reading the Reference again — the orchestrator has already read it, and reading it again in every subagent adds time, not rigor.
|
|
4
4
|
|
|
5
5
|
You own the entire pipeline end to end — frontend and UI design, gameplay code, shaders, generated art and audio, 3D models in headless Blender, whole game levels and prefabs in a terminal-driven Unity Editor, the interactive glTF export, the web build, the dev server, and visual QA by screenshotting both Unity and the running browser. Drive every one of those yourself; never stop to ask permission for work the reference already documents. Make the best call, state your assumption, and finish the job. See `Agent Authority — The Entire Pipeline Is Yours` in the reference.
|
|
6
6
|
|
package/scripts/postinstall.js
CHANGED
|
@@ -35,6 +35,12 @@ function main() {
|
|
|
35
35
|
for (const p of report.persona) console.log(` persona ${p.file} — ${p.action}`);
|
|
36
36
|
|
|
37
37
|
for (const c of report.config) console.log(` config ${c.file} — ${c.action} (network_access = true)`);
|
|
38
|
+
if (report.reference) {
|
|
39
|
+
const ref = report.reference;
|
|
40
|
+
console.log(ref.status === 'installed' || ref.status === 'kept'
|
|
41
|
+
? ` reference ${ref.dir} — ${ref.status === 'kept' ? 'kept the existing copy' : `${ref.files} files`}`
|
|
42
|
+
: ` reference not installed (${ref.reason}) — agents read it from GitHub; run \`bt-agent update\` later`);
|
|
43
|
+
}
|
|
38
44
|
|
|
39
45
|
console.log(check.ok ? '\nINSTALL OK' : '\nINSTALL INCOMPLETE — run `bt-agent doctor` for details');
|
|
40
46
|
console.log('\nRestart your agent session so the skills, persona and Codex configuration are picked up.\n');
|
|
@@ -80,12 +80,12 @@ CLI** → the model's own built-in image/video generation → any other configur
|
|
|
80
80
|
image/video tool. The parameter names below (`reference_paths`, `image_paths`,
|
|
81
81
|
`out_path`) are KIE/Kling's; map them to your backend (Higgsfield mapping below).
|
|
82
82
|
|
|
83
|
-
> **If using the KIE MCP servers** (Babylon Toolkit projects):
|
|
83
|
+
> **If using the KIE MCP servers** (Babylon Toolkit projects): read the
|
|
84
84
|
> Babylon Toolkit Agent Reference and its `web-kie-servers.md` sub-document
|
|
85
85
|
> first (per CLAUDE.md). Those servers read the key from `.env` — a file named
|
|
86
86
|
> `env` is ignored.
|
|
87
87
|
|
|
88
|
-
> **If using the Higgsfield CLI** (`@higgsfield/cli`):
|
|
88
|
+
> **If using the Higgsfield CLI** (`@higgsfield/cli`): read the Agent
|
|
89
89
|
> Reference's `web-higgsfield-cli.md` sub-document first. Install the CLI
|
|
90
90
|
> locally (`npm i -D @higgsfield/cli`) and the reference's download wrapper as
|
|
91
91
|
> `scripts/hf-generate.mjs`. The CLI only returns CDN URLs; the wrapper saves
|
|
@@ -33,8 +33,8 @@ Run tasks from a plan: build each one with its tests, have an independent verifi
|
|
|
33
33
|
|
|
34
34
|
- **TIME MATTERS** — on by default; `--no-time-limit` turns it off. Treat the arguments as ending with `TIME MATTERS`: the user is waiting on this run, so finish quickly — follow the *Work fast* rules below to the letter, take the direct route to each task's Acceptance, and do not re-read what you already have. Begin every implementer and verifier prompt with `TIME MATTERS.` Print `⏱️ [bt-execute] TIME MATTERS` at the start (`--no-time-limit`: print `⏱️ [bt-execute] No time limit`, and do not add it). Speed never relaxes tests, the independent verifier, live checks, or "tick only on PASS".
|
|
35
35
|
- **Scope.** Implement only the selected task(s). No "while I'm here" work on other tasks. Ambiguous, or blocked by an unfinished task → stop and tell the user *(auto-pilot: decide and log it)*.
|
|
36
|
-
- **Open the run before anything else.** The first actions of every run — before
|
|
37
|
-
- **Read the docs once.** For Babylon work, if you have not read the Agent Reference this session,
|
|
36
|
+
- **Open the run before anything else.** The first actions of every run — before reading docs, reading code, checking the repo or any other pre-flight work — are, in order: take the clock; append the `⏱ Run <n> start` line to the run log; sync the dashboard with the plan and set `status: "in-progress"` (*Run start* under *Feature folder and dashboard*); write the live file (`role: "orchestrator"`, `title: "Starting run <n> — <what you are checking first>"`); and launch the watchdog in the background (*Never let the dashboard go stale*). From then on the pre-flight work is narrated in the live file like any other step. Until the run is opened the dashboard still shows the last run's end state — a user who restarts a run and refreshes must see it running within a minute, not after the pre-flight is over.
|
|
37
|
+
- **Read the docs once.** For Babylon work, if you have not read the Agent Reference this session, read it once — https://raw.githubusercontent.com/babylontoolkit/agent/main/reference.md — plus only the sub-documents the plan's tasks need, searching a large one for the part you need rather than reading it whole. It is the authority for conventions and API. Cannot be read → stop and tell the user *(auto-pilot: retry 3×, then continue on what you know and log it)*. Read the plan's checklist and the parts of `SPEC.md` the tasks touch; re-read after a context compaction.
|
|
38
38
|
- **SPEC.md** constrains how you build. If the code and SPEC.md disagree, stop and tell the user *(auto-pilot: decide which is right, fix SPEC.md in the same task, log it)*. When a task changes architecture, a system, a convention or a dependency, SPEC.md must end up matching — normally the plan's final `Update SPEC.md` task; if the plan has none, do it anyway; a new dependency is recorded in SPEC.md by the task that introduces it. Follow SPEC.md's "How to update this spec". **Write the product, never the procedure** — no capture protocols, tool lists, ledgers or gates: recorded there, they become a bar every later feature must clear.
|
|
39
39
|
- **Say what you are doing** — one short line at each task and phase boundary, and before anything slow.
|
|
40
40
|
- **Clock every run** — auto-pilot or not, so bt-plan's time estimates can be recalibrated from real runs. Take every time from the shell (`date '+%Y-%m-%d %H:%M %Z'`, local time), never from memory, the conversation or a tool result's UTC timestamp. Append to the run log `documents/<slug>_autopilot.md` beside the plan (a legacy plan keeps its existing `<plan-basename>_autopilot.md`; an interactive run writes only these lines and its task lines):
|
|
@@ -60,7 +60,7 @@ Work in **phases**: a `### Phase N` group in the plan, or — if the plan has no
|
|
|
60
60
|
|
|
61
61
|
For a task built on a sibling skill (e.g. bt-design's 3D-Hero-Scroll), give the verifier the relevant part of that skill *(where skills load through a tool: `load_skill` + `read_skill_resource`; where they are files: the skills directory this skill was loaded from, e.g. `~/.claude/skills/`, `~/.agents/skills/` or the project's equivalent)* — its documented options (e.g. `sweep: page` really reaches the document bottom) are part of Acceptance.
|
|
62
62
|
|
|
63
|
-
**Every subagent gets a brief, not homework:** the task block(s), the plan Decisions / Design Reference entries they cite, the SPEC.md parts touched, the Agent Reference excerpts needed (with
|
|
63
|
+
**Every subagent gets a brief, not homework:** the task block(s), the plan Decisions / Design Reference entries they cite, the SPEC.md parts touched, the Agent Reference excerpts needed (with their links) — **always including the full `Coding Practices — ENFORCED` section**, since implementers write to it and verifiers fail work that breaks it — the test command and the feature folder's `tests/` path, the `snapshots/` path and *Snapshots tell the story* (for any phase with visible output), the dashboard and live file paths with the per-task update rules from *Feature folder and dashboard* (with `--verbose`, the `details` fields that role writes), the project's agent instructions, the *Work fast* rules below, and: *"Do not read the Agent Reference or SPEC.md in full — the parts you need are here, and this overrides any standing instruction to read it first. Read one sub-document (search it for the API, never the whole file) only if you hit an API this brief does not cover, and say which."*
|
|
64
64
|
|
|
65
65
|
## Feature folder and dashboard
|
|
66
66
|
|
|
@@ -99,9 +99,9 @@ On top of the per-task updates:
|
|
|
99
99
|
- **Run start — the first thing the run does** (*Open the run before anything else*): **refresh `dashboard.html`** — copy it again from the template with `{{slug}}` replaced (it is never edited, so this is always safe, and it is how layout fixes reach dashboards created by older versions); then **sync the dashboard with the plan file** — re-read its checklist and add any phase or task (including sub-tasks like `T3.1`) the dashboard lacks, in plan order, as `pending`, with an `updates` note on it (`Added to the plan after <the plan was complete / phase 2 ran> — <why, if the plan says>`); a task the plan no longer has is removed with an `activity` line saying so. Then `status: "in-progress"`, `runs` + 1, the run-log document link, an `activity` line, the first live-file write, and the watchdog launched in the background. In a git repository, check `.gitignore` has `.agents/specs/*/documents/*_live.js` and append it once if not — the live file is never staged or committed; `<slug>_dashboard.js` and `snapshots/` are.
|
|
100
100
|
- **Each phase, after its ticks and before its commit:** the phase's status, times and minutes (from its `⏱` line), its verifier result and a two-or-three-sentence summary of what it delivered; the phase-level snapshots (a progression spanning several tasks — below); `decisions`; `activeTime`; an `activity` line; and a current "so far" `outcome` headline.
|
|
101
101
|
- **A deferral:** the task's `status: "deferred"` and `deferredReason`, an `activity` line.
|
|
102
|
-
- **Run end — the After Action Report.** **decide the status by re-reading the plan file's checkboxes, never from memory:** `complete` when every task in the plan is `- [x]`; `incomplete` when every task is either ticked or marked ⏭️ DEFERRED; otherwise `paused` (the run covered only a slice, or tasks were added). The page refuses a `complete` it can see is false — it shows the plan as paused with a warning — but the plan file is the authority; never leave `in-progress` behind, because the status picks the page's top slot: `in-progress` shows *Current run activity* (the live file and the milestones), any other run-ended status shows the After Action Report in its place. Write `followUps` for a human, and `afterAction` — the whole plan's execution, start to finish: a one-sentence headline of what the plan delivered; two to four paragraphs on what was built, how it was proven and what surprised; highlights; and **one before/after for the plan as a whole** (`comparison`) — the plan-wide "before" frame beside a final "after" taken now from the same camera or viewport (the end-to-end check's session supplies it). Add the plan's key progression to `afterAction.snapshots` if one tells the story better than any single phase. The figures (tasks, tests, retries, time) are computed by the page — never type them in. A run that ends before the plan is finished writes it too; the page marks it *Interim* while `paused`, and the next run revises it with an `updates` entry. **A reopened plan** (tasks added after it was complete) works the same way: the run that finishes the added tasks rewrites the After Action Report to cover them, notes the change in its `updates` (`Revised — T7 added after completion: <why>`), and retakes the plan-wide "after" from the same camera so the comparison shows the plan as it now stands.
|
|
102
|
+
- **Run end — the After Action Report.** **decide the status by re-reading the plan file's checkboxes, never from memory:** `complete` when every task in the plan is `- [x]`; `incomplete` when every task is either ticked or marked ⏭️ DEFERRED; otherwise `paused` (the run covered only a slice, or tasks were added). The page refuses a `complete` it can see is false — it shows the plan as paused with a warning — but the plan file is the authority; never leave `in-progress` behind, because the status picks the page's top slot: `in-progress` shows *Current run activity* (the live file and the milestones), any other run-ended status shows the After Action Report in its place. Write `followUps` for a human, and `afterAction` — the whole plan's execution, start to finish: a one-sentence headline of what the plan delivered; two to four paragraphs on what was built, how it was proven and what surprised; highlights; and **one before/after for the plan as a whole** (`comparison`) — the plan-wide "before" frame beside a final "after" taken now from the same camera or viewport (the end-to-end check's session supplies it). Add the plan's key progression to `afterAction.snapshots` if one tells the story better than any single phase. Write `afterAction.testing` on every run, not only `--verbose`: run every test suite the plan touched **once more, in full, at run end** and record each as a `suites` entry (name, command, passed, failed, how many tests this plan added, and a `note` for any failure that pre-dates the plan) — never add up the tasks' counts, which re-count the same suite once per task; a `summary` of how the plan was tested (unit tests, the verifier's re-runs, what was checked live and on what, the end-to-end check); and `gaps` — what no test or live check covers. The page builds the task-by-task table and the list of test cases from the tasks. The figures (tasks, tests, retries, time) are computed by the page — never type them in. A run that ends before the plan is finished writes it too; the page marks it *Interim* while `paused`, and the next run revises it with an `updates` entry. **A reopened plan** (tasks added after it was complete) works the same way: the run that finishes the added tasks rewrites the After Action Report to cover them, notes the change in its `updates` (`Revised — T7 added after completion: <why>`), and retakes the plan-wide "after" from the same camera so the comparison shows the plan as it now stands.
|
|
103
103
|
- **`--verbose` — the same work, written up in depth.** It changes what is written, never what is done: tests, the verifier, live checks and snapshot captures are exactly as without it, and TIME MATTERS still holds (the extra cost is writing, not checking). Set `detail: "verbose"` at run start. Each task gets a `details` write-up (fields in `data-schema.md`), filled in by whoever has the facts, at the same per-task moments as everything else:
|
|
104
|
-
- **the implementer, when the task is built:** `approach` (how it was built, how the pieces fit together, why this way and not the alternatives it weighed); `changes` — every file touched, with what changed in it and why; `testCases` — every named case with its expected and actual result; `problems` — each failed attempt or dead end, with what failed, the root cause and the fix; `notes` for a future maintainer; `timing.build`;
|
|
104
|
+
- **the implementer, when the task is built:** `approach` (how it was built, how the pieces fit together, why this way and not the alternatives it weighed); `changes` — every file touched, with what changed in it and why; `testCases` — every named case with its expected and actual result, the result leading with `PASS` or `FAIL` (`"PASS — 0→74 km/h on held W"`); `problems` — each failed attempt or dead end, with what failed, the root cause and the fix; `notes` for a future maintainer; `timing.build`;
|
|
105
105
|
- **the verifier, while it checks:** `acceptance` — every Acceptance item with its verdict and the evidence it rests on (command output, the screenshot, the line read); `liveCheck` — what it looked at, on which engine, at what resolution, and how it judged it; `timing.verify`;
|
|
106
106
|
- **you, at the tick and in the fix loop:** each fix round added to `problems`, `timing.fix`, and snapshot captions that say what to notice, not just what is shown.
|
|
107
107
|
|
|
@@ -148,7 +148,7 @@ An unattended run: **nobody is there to answer, and nothing waits for anyone's a
|
|
|
148
148
|
|
|
149
149
|
- **The run ends only when the work queue is empty** — every task in it `- [x]` or deferred. The queue is the range asked for (`T3-T7`, `T12-`, `NEXT:<n>`), or every remaining task for `ALL` or no task id. Before ending, re-read the plan: an unticked, undeferred task in the queue means you are not done.
|
|
150
150
|
- **Ending your turn is stopping.** A finished task or phase, a commit, a milestone worth reporting, a long session, many tasks done, a compaction, a tool error, an ambiguity, a hard external blocker — none of these ends the turn. Narrate the boundary in one console line and start the next phase in the same turn. The only mid-queue turn end is waiting on a background job or subagent that will notify you, and that message is one status line (`waiting on T9 verifier`), never a question or a summary inviting a reply.
|
|
151
|
-
- **The only early exits — exactly four:** the plan file is missing; a range endpoint does not exist or is reversed (a typo the user must fix — say so and end); the brief names a stop point (`stop after T5`, `stop before the Unity tasks`) — stop there; the user tells you to stop during the run. Nothing else.
|
|
151
|
+
- **The only early exits — exactly four:** the plan file is missing; a range endpoint does not exist or is reversed (a typo the user must fix — say so and end); the brief names a stop point (`stop after T5`, `stop before the Unity tasks`) — stop there; the user tells you to stop during the run. Nothing else. An Agent Reference that cannot be read → retry 3×, then continue on what you know and log it. A missing Pro license, an account, a credential or a sign-in only the user has → defer the tasks that need it and keep running every task that does not.
|
|
152
152
|
- After a compaction, re-read the plan and the run log and continue from the first unticked, undeferred task.
|
|
153
153
|
|
|
154
154
|
### Keep moving
|