blun-king-cli 9.1.647 → 9.1.648
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/CHANGELOG.md +15 -0
- package/COMPACTION-STEER.md +15 -0
- package/GOAL-REPLY-TOOLS.md +25 -0
- package/LIESMICH.txt +49 -11
- package/ORIGINAL-HISTORY-BINDING.md +13 -0
- package/ORIGINAL-TOOL-OUTPUT.md +15 -0
- package/README.md +49 -11
- package/RELEASE-9.1.648.md +64 -0
- package/REQUEST-BODY-OBSERVATIONS.md +17 -0
- package/RETIRED-WORKER-DATA.md +25 -0
- package/RETIREMENT-COMPATIBILITY.md +11 -0
- package/bin/launcher-mode.js +1 -1
- package/bin/launcher-runtime.js +14 -1
- package/bin/plugin-bootstrap.js +1 -1
- package/bin/retired-bundled-plugins.cjs +2 -1
- package/bin/retired-installation.cjs +103 -0
- package/bin/retired-owned-tree.cjs +94 -0
- package/bin/retired-settings.cjs +108 -0
- package/bin/retired-worker-residues.cjs +29 -0
- package/blun.mjs +1246 -123
- package/package.json +12 -3
- package/telegram-plugin/dist/bridge.mjs +3 -2
- package/telegram-plugin/dist/mcp-server.mjs +25 -24
- package/worker-host.mjs +192 -95
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
|
|
6
|
+
const samePath = (a, b) => process.platform === 'win32' ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
7
|
+
const identity = (a, b) => a.dev === b.dev && a.ino === b.ino && a.birthtimeMs === b.birthtimeMs;
|
|
8
|
+
|
|
9
|
+
function optionalStat(filename) {
|
|
10
|
+
try { return fs.lstatSync(filename); }
|
|
11
|
+
catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function canonicalDirectory(directory) {
|
|
15
|
+
const absolute = path.resolve(directory);
|
|
16
|
+
const stat = fs.lstatSync(absolute);
|
|
17
|
+
if (!stat.isDirectory() || stat.isSymbolicLink() || !samePath(fs.realpathSync(absolute), absolute)) {
|
|
18
|
+
throw new Error('RETIRED_INSTALLATION_LINK');
|
|
19
|
+
}
|
|
20
|
+
return stat;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// No file content, keys, session history or symlink target is read.
|
|
24
|
+
// Every absolute deletion target is proved to be under its explicit parent.
|
|
25
|
+
function planRetiredTree(parent, name, { allowFile = false } = {}) {
|
|
26
|
+
if (!path.isAbsolute(parent) || path.basename(name) !== name || name === '.' || name === '..') {
|
|
27
|
+
throw new Error('RETIRED_INSTALLATION_SCOPE');
|
|
28
|
+
}
|
|
29
|
+
parent = path.resolve(parent);
|
|
30
|
+
if (!optionalStat(parent)) return null;
|
|
31
|
+
const parentIdentity = canonicalDirectory(parent);
|
|
32
|
+
const root = path.resolve(parent, name);
|
|
33
|
+
if (!samePath(path.dirname(root), parent)) throw new Error('RETIRED_INSTALLATION_SCOPE');
|
|
34
|
+
if (!optionalStat(root)) return null;
|
|
35
|
+
const entries = [];
|
|
36
|
+
function visit(filename, depth) {
|
|
37
|
+
if (depth > 64 || entries.length >= 200_000) throw new Error('RETIRED_INSTALLATION_LIMIT');
|
|
38
|
+
const stat = fs.lstatSync(filename);
|
|
39
|
+
if (stat.isSymbolicLink() || (stat.isDirectory() && !samePath(fs.realpathSync(filename), filename))) {
|
|
40
|
+
throw new Error('RETIRED_INSTALLATION_LINK');
|
|
41
|
+
}
|
|
42
|
+
if (!stat.isDirectory() && (!stat.isFile() || stat.nlink !== 1)) {
|
|
43
|
+
throw new Error('RETIRED_INSTALLATION_FILE');
|
|
44
|
+
}
|
|
45
|
+
entries.push({ filename, stat });
|
|
46
|
+
if (stat.isDirectory()) {
|
|
47
|
+
for (const child of fs.readdirSync(filename).toSorted()) visit(path.join(filename, child), depth + 1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
visit(root, 0);
|
|
51
|
+
if (!entries[0].stat.isDirectory() && !allowFile) throw new Error('RETIRED_INSTALLATION_DIRECTORY');
|
|
52
|
+
return { root, parent, parentIdentity, entries, byPath: new Map(entries.map(entry => [entry.filename, entry])) };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function checkEntry(entry) {
|
|
56
|
+
const current = fs.lstatSync(entry.filename);
|
|
57
|
+
const previous = entry.stat;
|
|
58
|
+
if (current.isSymbolicLink() || !identity(previous, current)
|
|
59
|
+
|| current.isDirectory() !== previous.isDirectory()
|
|
60
|
+
|| (!current.isDirectory() && (!current.isFile() || current.nlink !== 1
|
|
61
|
+
|| current.size !== previous.size || current.mtimeMs !== previous.mtimeMs))) {
|
|
62
|
+
throw new Error('RETIRED_INSTALLATION_CHANGED');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function removeRetiredTree(plan) {
|
|
67
|
+
if (!identity(canonicalDirectory(plan.parent), plan.parentIdentity)) {
|
|
68
|
+
throw new Error('RETIRED_INSTALLATION_CHANGED');
|
|
69
|
+
}
|
|
70
|
+
for (const entry of plan.entries) checkEntry(entry);
|
|
71
|
+
let files = 0;
|
|
72
|
+
for (const entry of plan.entries.toReversed()) {
|
|
73
|
+
// Repeat realpath and identity checks immediately before each synchronous
|
|
74
|
+
// mutation; never use recursive rm or follow a replaced parent junction.
|
|
75
|
+
const parent = fs.lstatSync(plan.parent);
|
|
76
|
+
if (parent.isSymbolicLink() || !parent.isDirectory() || !identity(parent, plan.parentIdentity)) {
|
|
77
|
+
throw new Error('RETIRED_INSTALLATION_CHANGED');
|
|
78
|
+
}
|
|
79
|
+
const cursor = path.dirname(entry.filename);
|
|
80
|
+
canonicalDirectory(cursor);
|
|
81
|
+
if (!samePath(cursor, plan.parent)) {
|
|
82
|
+
const ancestor = plan.byPath.get(cursor);
|
|
83
|
+
if (!ancestor) throw new Error('RETIRED_INSTALLATION_SCOPE');
|
|
84
|
+
checkEntry(ancestor);
|
|
85
|
+
}
|
|
86
|
+
checkEntry(entry);
|
|
87
|
+
if (entry.stat.isDirectory()) fs.rmdirSync(entry.filename);
|
|
88
|
+
else { fs.unlinkSync(entry.filename); files++; }
|
|
89
|
+
}
|
|
90
|
+
if (optionalStat(plan.root)) throw new Error('RETIRED_INSTALLATION_CHANGED');
|
|
91
|
+
return files;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
module.exports = { samePath, canonicalDirectory, optionalStat, planRetiredTree, removeRetiredTree };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const { createHash, randomUUID } = require('node:crypto');
|
|
6
|
+
const toml = require('smol-toml');
|
|
7
|
+
const { canonicalDirectory, optionalStat } = require('./retired-owned-tree.cjs');
|
|
8
|
+
const MAX_BYTES = 1024 * 1024;
|
|
9
|
+
const hash = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
10
|
+
|
|
11
|
+
function readPrivate(filename, inspectLinks = false) {
|
|
12
|
+
const requested = path.resolve(filename);
|
|
13
|
+
const requestedStat = fs.lstatSync(requested);
|
|
14
|
+
const linked = requestedStat.isSymbolicLink() === true || requestedStat.nlink !== 1;
|
|
15
|
+
if (linked && !inspectLinks) throw new Error('RETIRED_SETTINGS_FILE');
|
|
16
|
+
filename = linked ? fs.realpathSync(requested) : requested;
|
|
17
|
+
canonicalDirectory(path.dirname(filename));
|
|
18
|
+
const before = fs.lstatSync(filename);
|
|
19
|
+
if (!before.isFile() || before.isSymbolicLink() || (!inspectLinks && before.nlink !== 1) || before.size > MAX_BYTES) {
|
|
20
|
+
throw new Error('RETIRED_SETTINGS_FILE');
|
|
21
|
+
}
|
|
22
|
+
const fd = fs.openSync(filename, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0));
|
|
23
|
+
let bytes;
|
|
24
|
+
try {
|
|
25
|
+
const opened = fs.fstatSync(fd);
|
|
26
|
+
if (!opened.isFile() || opened.dev !== before.dev || opened.ino !== before.ino || opened.nlink !== before.nlink) {
|
|
27
|
+
throw new Error('RETIRED_SETTINGS_CHANGED');
|
|
28
|
+
}
|
|
29
|
+
const buffer = Buffer.alloc(MAX_BYTES + 1);
|
|
30
|
+
let length = 0;
|
|
31
|
+
while (length < buffer.length) {
|
|
32
|
+
const count = fs.readSync(fd, buffer, length, buffer.length - length, null);
|
|
33
|
+
if (!count) break;
|
|
34
|
+
length += count;
|
|
35
|
+
}
|
|
36
|
+
if (length > MAX_BYTES) throw new Error('RETIRED_SETTINGS_FILE');
|
|
37
|
+
bytes = buffer.subarray(0, length);
|
|
38
|
+
const after = fs.fstatSync(fd);
|
|
39
|
+
const current = fs.lstatSync(filename);
|
|
40
|
+
if (after.dev !== before.dev || after.ino !== before.ino || after.size !== before.size
|
|
41
|
+
|| after.mtimeMs !== before.mtimeMs || after.nlink !== before.nlink || current.isSymbolicLink()
|
|
42
|
+
|| current.dev !== before.dev || current.ino !== before.ino) throw new Error('RETIRED_SETTINGS_CHANGED');
|
|
43
|
+
} finally { fs.closeSync(fd); }
|
|
44
|
+
const currentRequested = fs.lstatSync(requested);
|
|
45
|
+
if (currentRequested.dev !== requestedStat.dev || currentRequested.ino !== requestedStat.ino
|
|
46
|
+
|| currentRequested.isSymbolicLink() !== requestedStat.isSymbolicLink()
|
|
47
|
+
|| (linked && fs.realpathSync(requested) !== filename)) throw new Error('RETIRED_SETTINGS_CHANGED');
|
|
48
|
+
return { bytes, identity: before, hash: hash(bytes), linked };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function stripRetiredToml(text) {
|
|
52
|
+
const document = toml.parse(text.codePointAt(0) === 0xFEFF ? text.slice(1) : text);
|
|
53
|
+
const servers = document.mcp_servers;
|
|
54
|
+
if (servers === undefined) return text;
|
|
55
|
+
if (!servers || typeof servers !== 'object' || Array.isArray(servers)) throw new Error('RETIRED_SETTINGS_TOML');
|
|
56
|
+
let changed = false;
|
|
57
|
+
for (const name of ['agent-spine', 'plugin-agent-spine:agent-spine']) {
|
|
58
|
+
if (Object.hasOwn(servers, name)) { delete servers[name]; changed = true; }
|
|
59
|
+
}
|
|
60
|
+
// The maintained parser handles all valid TOML spellings, including dotted
|
|
61
|
+
// keys and inline tables. Re-serialization preserves values, not comments.
|
|
62
|
+
return changed ? toml.stringify(document) : text;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function stripRetiredMcp(text) {
|
|
66
|
+
const document = JSON.parse(text.codePointAt(0) === 0xFEFF ? text.slice(1) : text);
|
|
67
|
+
if (!document || typeof document !== 'object' || Array.isArray(document)) throw new Error('RETIRED_SETTINGS_JSON');
|
|
68
|
+
if (document.mcpServers === undefined) return text;
|
|
69
|
+
if (!document.mcpServers || typeof document.mcpServers !== 'object' || Array.isArray(document.mcpServers)) {
|
|
70
|
+
throw new Error('RETIRED_SETTINGS_JSON');
|
|
71
|
+
}
|
|
72
|
+
let changed = false;
|
|
73
|
+
for (const name of ['agent-spine', 'plugin-agent-spine:agent-spine']) {
|
|
74
|
+
if (Object.hasOwn(document.mcpServers, name)) { delete document.mcpServers[name]; changed = true; }
|
|
75
|
+
}
|
|
76
|
+
return changed ? JSON.stringify(document, null, 2) + '\n' : text;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function retireSettings({ blunDir, io }) {
|
|
80
|
+
let changed = 0;
|
|
81
|
+
for (const [name, transform] of [['mcp.json', stripRetiredMcp], ['config.toml', stripRetiredToml]]) {
|
|
82
|
+
const filename = path.join(blunDir, name);
|
|
83
|
+
if (!optionalStat(filename)) continue;
|
|
84
|
+
const original = readPrivate(filename, true);
|
|
85
|
+
const text = original.bytes.toString('utf8');
|
|
86
|
+
if (!Buffer.from(text).equals(original.bytes)) throw new Error('RETIRED_SETTINGS_ENCODING');
|
|
87
|
+
const updated = transform(text);
|
|
88
|
+
if (updated === text) continue;
|
|
89
|
+
if (original.linked) throw new Error('RETIRED_SETTINGS_LINK');
|
|
90
|
+
if (Buffer.byteLength(updated) > MAX_BYTES) throw new Error('RETIRED_SETTINGS_FILE');
|
|
91
|
+
const temporary = path.join(blunDir, `.retired-settings-${randomUUID()}.tmp`);
|
|
92
|
+
try {
|
|
93
|
+
await io.writePrivateFile(temporary, updated);
|
|
94
|
+
const current = readPrivate(filename);
|
|
95
|
+
if (current.hash !== original.hash || current.identity.dev !== original.identity.dev
|
|
96
|
+
|| current.identity.ino !== original.identity.ino) throw new Error('RETIRED_SETTINGS_CHANGED');
|
|
97
|
+
const written = readPrivate(temporary);
|
|
98
|
+
if (!written.bytes.equals(Buffer.from(updated))) throw new Error('RETIRED_SETTINGS_CHANGED');
|
|
99
|
+
fs.renameSync(temporary, filename);
|
|
100
|
+
changed++;
|
|
101
|
+
} finally {
|
|
102
|
+
if (optionalStat(temporary)) fs.unlinkSync(temporary);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return changed;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
module.exports = { retireSettings, stripRetiredMcp, stripRetiredToml };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const { canonicalDirectory, optionalStat } = require('./retired-owned-tree.cjs');
|
|
5
|
+
|
|
6
|
+
// These paths may contain acceptance/delivery deduplication state used by a
|
|
7
|
+
// separately started old worker. Absence or age of a lock is not quiescence.
|
|
8
|
+
// Inspect names only: never open file contents, follow links, delete, or signal.
|
|
9
|
+
function inspectRetiredWorkerResidues(blunDir) {
|
|
10
|
+
canonicalDirectory(blunDir);
|
|
11
|
+
const deferred = [];
|
|
12
|
+
for (const { directory, names } of [
|
|
13
|
+
{ directory: 'worker', names: ['goal-status-v2.json', 'goal-status-v2.json.lock', 'goal-queue-checkpoint.json', 'worker.log'] },
|
|
14
|
+
{ directory: 'skills', names: ['.agent-spine-install.lock'] },
|
|
15
|
+
]) {
|
|
16
|
+
const parent = path.join(blunDir, directory);
|
|
17
|
+
try {
|
|
18
|
+
if (!optionalStat(parent)) continue;
|
|
19
|
+
canonicalDirectory(parent);
|
|
20
|
+
for (const name of names) if (optionalStat(path.join(parent, name))) deferred.push(directory + '/' + name);
|
|
21
|
+
} catch {
|
|
22
|
+
// A redirected/unreadable parent is not evidence of an empty footprint.
|
|
23
|
+
deferred.push(directory + '/');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return deferred;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = { inspectRetiredWorkerResidues };
|