@adhdev/daemon-standalone 0.9.82-rc.66 → 0.9.82-rc.67
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/dist/index.js +1518 -592
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/vendor/mcp-server/index.js +25 -9
- package/vendor/mcp-server/index.js.map +1 -1
package/dist/index.js
CHANGED
|
@@ -34,6 +34,780 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
34
34
|
));
|
|
35
35
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
36
|
|
|
37
|
+
// ../../node_modules/better-sqlite3/lib/util.js
|
|
38
|
+
var require_util = __commonJS({
|
|
39
|
+
"../../node_modules/better-sqlite3/lib/util.js"(exports2) {
|
|
40
|
+
"use strict";
|
|
41
|
+
exports2.getBooleanOption = (options, key) => {
|
|
42
|
+
let value = false;
|
|
43
|
+
if (key in options && typeof (value = options[key]) !== "boolean") {
|
|
44
|
+
throw new TypeError(`Expected the "${key}" option to be a boolean`);
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
};
|
|
48
|
+
exports2.cppdb = /* @__PURE__ */ Symbol();
|
|
49
|
+
exports2.inspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// ../../node_modules/better-sqlite3/lib/sqlite-error.js
|
|
54
|
+
var require_sqlite_error = __commonJS({
|
|
55
|
+
"../../node_modules/better-sqlite3/lib/sqlite-error.js"(exports2, module2) {
|
|
56
|
+
"use strict";
|
|
57
|
+
var descriptor = { value: "SqliteError", writable: true, enumerable: false, configurable: true };
|
|
58
|
+
function SqliteError(message, code) {
|
|
59
|
+
if (new.target !== SqliteError) {
|
|
60
|
+
return new SqliteError(message, code);
|
|
61
|
+
}
|
|
62
|
+
if (typeof code !== "string") {
|
|
63
|
+
throw new TypeError("Expected second argument to be a string");
|
|
64
|
+
}
|
|
65
|
+
Error.call(this, message);
|
|
66
|
+
descriptor.value = "" + message;
|
|
67
|
+
Object.defineProperty(this, "message", descriptor);
|
|
68
|
+
Error.captureStackTrace(this, SqliteError);
|
|
69
|
+
this.code = code;
|
|
70
|
+
}
|
|
71
|
+
Object.setPrototypeOf(SqliteError, Error);
|
|
72
|
+
Object.setPrototypeOf(SqliteError.prototype, Error.prototype);
|
|
73
|
+
Object.defineProperty(SqliteError.prototype, "name", descriptor);
|
|
74
|
+
module2.exports = SqliteError;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// ../../node_modules/file-uri-to-path/index.js
|
|
79
|
+
var require_file_uri_to_path = __commonJS({
|
|
80
|
+
"../../node_modules/file-uri-to-path/index.js"(exports2, module2) {
|
|
81
|
+
"use strict";
|
|
82
|
+
var sep = require("path").sep || "/";
|
|
83
|
+
module2.exports = fileUriToPath;
|
|
84
|
+
function fileUriToPath(uri) {
|
|
85
|
+
if ("string" != typeof uri || uri.length <= 7 || "file://" != uri.substring(0, 7)) {
|
|
86
|
+
throw new TypeError("must pass in a file:// URI to convert to a file path");
|
|
87
|
+
}
|
|
88
|
+
var rest = decodeURI(uri.substring(7));
|
|
89
|
+
var firstSlash = rest.indexOf("/");
|
|
90
|
+
var host = rest.substring(0, firstSlash);
|
|
91
|
+
var path5 = rest.substring(firstSlash + 1);
|
|
92
|
+
if ("localhost" == host) host = "";
|
|
93
|
+
if (host) {
|
|
94
|
+
host = sep + sep + host;
|
|
95
|
+
}
|
|
96
|
+
path5 = path5.replace(/^(.+)\|/, "$1:");
|
|
97
|
+
if (sep == "\\") {
|
|
98
|
+
path5 = path5.replace(/\//g, "\\");
|
|
99
|
+
}
|
|
100
|
+
if (/^.+\:/.test(path5)) {
|
|
101
|
+
} else {
|
|
102
|
+
path5 = sep + path5;
|
|
103
|
+
}
|
|
104
|
+
return host + path5;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// ../../node_modules/bindings/bindings.js
|
|
110
|
+
var require_bindings = __commonJS({
|
|
111
|
+
"../../node_modules/bindings/bindings.js"(exports2, module2) {
|
|
112
|
+
"use strict";
|
|
113
|
+
var fs4 = require("fs");
|
|
114
|
+
var path5 = require("path");
|
|
115
|
+
var fileURLToPath = require_file_uri_to_path();
|
|
116
|
+
var join4 = path5.join;
|
|
117
|
+
var dirname3 = path5.dirname;
|
|
118
|
+
var exists = fs4.accessSync && function(path6) {
|
|
119
|
+
try {
|
|
120
|
+
fs4.accessSync(path6);
|
|
121
|
+
} catch (e) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
} || fs4.existsSync || path5.existsSync;
|
|
126
|
+
var defaults = {
|
|
127
|
+
arrow: process.env.NODE_BINDINGS_ARROW || " \u2192 ",
|
|
128
|
+
compiled: process.env.NODE_BINDINGS_COMPILED_DIR || "compiled",
|
|
129
|
+
platform: process.platform,
|
|
130
|
+
arch: process.arch,
|
|
131
|
+
nodePreGyp: "node-v" + process.versions.modules + "-" + process.platform + "-" + process.arch,
|
|
132
|
+
version: process.versions.node,
|
|
133
|
+
bindings: "bindings.node",
|
|
134
|
+
try: [
|
|
135
|
+
// node-gyp's linked version in the "build" dir
|
|
136
|
+
["module_root", "build", "bindings"],
|
|
137
|
+
// node-waf and gyp_addon (a.k.a node-gyp)
|
|
138
|
+
["module_root", "build", "Debug", "bindings"],
|
|
139
|
+
["module_root", "build", "Release", "bindings"],
|
|
140
|
+
// Debug files, for development (legacy behavior, remove for node v0.9)
|
|
141
|
+
["module_root", "out", "Debug", "bindings"],
|
|
142
|
+
["module_root", "Debug", "bindings"],
|
|
143
|
+
// Release files, but manually compiled (legacy behavior, remove for node v0.9)
|
|
144
|
+
["module_root", "out", "Release", "bindings"],
|
|
145
|
+
["module_root", "Release", "bindings"],
|
|
146
|
+
// Legacy from node-waf, node <= 0.4.x
|
|
147
|
+
["module_root", "build", "default", "bindings"],
|
|
148
|
+
// Production "Release" buildtype binary (meh...)
|
|
149
|
+
["module_root", "compiled", "version", "platform", "arch", "bindings"],
|
|
150
|
+
// node-qbs builds
|
|
151
|
+
["module_root", "addon-build", "release", "install-root", "bindings"],
|
|
152
|
+
["module_root", "addon-build", "debug", "install-root", "bindings"],
|
|
153
|
+
["module_root", "addon-build", "default", "install-root", "bindings"],
|
|
154
|
+
// node-pre-gyp path ./lib/binding/{node_abi}-{platform}-{arch}
|
|
155
|
+
["module_root", "lib", "binding", "nodePreGyp", "bindings"]
|
|
156
|
+
]
|
|
157
|
+
};
|
|
158
|
+
function bindings(opts) {
|
|
159
|
+
if (typeof opts == "string") {
|
|
160
|
+
opts = { bindings: opts };
|
|
161
|
+
} else if (!opts) {
|
|
162
|
+
opts = {};
|
|
163
|
+
}
|
|
164
|
+
Object.keys(defaults).map(function(i2) {
|
|
165
|
+
if (!(i2 in opts)) opts[i2] = defaults[i2];
|
|
166
|
+
});
|
|
167
|
+
if (!opts.module_root) {
|
|
168
|
+
opts.module_root = exports2.getRoot(exports2.getFileName());
|
|
169
|
+
}
|
|
170
|
+
if (path5.extname(opts.bindings) != ".node") {
|
|
171
|
+
opts.bindings += ".node";
|
|
172
|
+
}
|
|
173
|
+
var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
|
|
174
|
+
var tries = [], i = 0, l = opts.try.length, n, b, err;
|
|
175
|
+
for (; i < l; i++) {
|
|
176
|
+
n = join4.apply(
|
|
177
|
+
null,
|
|
178
|
+
opts.try[i].map(function(p) {
|
|
179
|
+
return opts[p] || p;
|
|
180
|
+
})
|
|
181
|
+
);
|
|
182
|
+
tries.push(n);
|
|
183
|
+
try {
|
|
184
|
+
b = opts.path ? requireFunc.resolve(n) : requireFunc(n);
|
|
185
|
+
if (!opts.path) {
|
|
186
|
+
b.path = n;
|
|
187
|
+
}
|
|
188
|
+
return b;
|
|
189
|
+
} catch (e) {
|
|
190
|
+
if (e.code !== "MODULE_NOT_FOUND" && e.code !== "QUALIFIED_PATH_RESOLUTION_FAILED" && !/not find/i.test(e.message)) {
|
|
191
|
+
throw e;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
err = new Error(
|
|
196
|
+
"Could not locate the bindings file. Tried:\n" + tries.map(function(a) {
|
|
197
|
+
return opts.arrow + a;
|
|
198
|
+
}).join("\n")
|
|
199
|
+
);
|
|
200
|
+
err.tries = tries;
|
|
201
|
+
throw err;
|
|
202
|
+
}
|
|
203
|
+
module2.exports = exports2 = bindings;
|
|
204
|
+
exports2.getFileName = function getFileName(calling_file) {
|
|
205
|
+
var origPST = Error.prepareStackTrace, origSTL = Error.stackTraceLimit, dummy = {}, fileName;
|
|
206
|
+
Error.stackTraceLimit = 10;
|
|
207
|
+
Error.prepareStackTrace = function(e, st) {
|
|
208
|
+
for (var i = 0, l = st.length; i < l; i++) {
|
|
209
|
+
fileName = st[i].getFileName();
|
|
210
|
+
if (fileName !== __filename) {
|
|
211
|
+
if (calling_file) {
|
|
212
|
+
if (fileName !== calling_file) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
} else {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
Error.captureStackTrace(dummy);
|
|
222
|
+
dummy.stack;
|
|
223
|
+
Error.prepareStackTrace = origPST;
|
|
224
|
+
Error.stackTraceLimit = origSTL;
|
|
225
|
+
var fileSchema = "file://";
|
|
226
|
+
if (fileName.indexOf(fileSchema) === 0) {
|
|
227
|
+
fileName = fileURLToPath(fileName);
|
|
228
|
+
}
|
|
229
|
+
return fileName;
|
|
230
|
+
};
|
|
231
|
+
exports2.getRoot = function getRoot(file2) {
|
|
232
|
+
var dir = dirname3(file2), prev;
|
|
233
|
+
while (true) {
|
|
234
|
+
if (dir === ".") {
|
|
235
|
+
dir = process.cwd();
|
|
236
|
+
}
|
|
237
|
+
if (exists(join4(dir, "package.json")) || exists(join4(dir, "node_modules"))) {
|
|
238
|
+
return dir;
|
|
239
|
+
}
|
|
240
|
+
if (prev === dir) {
|
|
241
|
+
throw new Error(
|
|
242
|
+
'Could not find module root given file: "' + file2 + '". Do you have a `package.json` file? '
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
prev = dir;
|
|
246
|
+
dir = join4(dir, "..");
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
// ../../node_modules/better-sqlite3/lib/methods/wrappers.js
|
|
253
|
+
var require_wrappers = __commonJS({
|
|
254
|
+
"../../node_modules/better-sqlite3/lib/methods/wrappers.js"(exports2) {
|
|
255
|
+
"use strict";
|
|
256
|
+
var { cppdb } = require_util();
|
|
257
|
+
exports2.prepare = function prepare(sql) {
|
|
258
|
+
return this[cppdb].prepare(sql, this, false);
|
|
259
|
+
};
|
|
260
|
+
exports2.exec = function exec(sql) {
|
|
261
|
+
this[cppdb].exec(sql);
|
|
262
|
+
return this;
|
|
263
|
+
};
|
|
264
|
+
exports2.close = function close() {
|
|
265
|
+
this[cppdb].close();
|
|
266
|
+
return this;
|
|
267
|
+
};
|
|
268
|
+
exports2.loadExtension = function loadExtension(...args) {
|
|
269
|
+
this[cppdb].loadExtension(...args);
|
|
270
|
+
return this;
|
|
271
|
+
};
|
|
272
|
+
exports2.defaultSafeIntegers = function defaultSafeIntegers(...args) {
|
|
273
|
+
this[cppdb].defaultSafeIntegers(...args);
|
|
274
|
+
return this;
|
|
275
|
+
};
|
|
276
|
+
exports2.unsafeMode = function unsafeMode(...args) {
|
|
277
|
+
this[cppdb].unsafeMode(...args);
|
|
278
|
+
return this;
|
|
279
|
+
};
|
|
280
|
+
exports2.getters = {
|
|
281
|
+
name: {
|
|
282
|
+
get: function name() {
|
|
283
|
+
return this[cppdb].name;
|
|
284
|
+
},
|
|
285
|
+
enumerable: true
|
|
286
|
+
},
|
|
287
|
+
open: {
|
|
288
|
+
get: function open() {
|
|
289
|
+
return this[cppdb].open;
|
|
290
|
+
},
|
|
291
|
+
enumerable: true
|
|
292
|
+
},
|
|
293
|
+
inTransaction: {
|
|
294
|
+
get: function inTransaction() {
|
|
295
|
+
return this[cppdb].inTransaction;
|
|
296
|
+
},
|
|
297
|
+
enumerable: true
|
|
298
|
+
},
|
|
299
|
+
readonly: {
|
|
300
|
+
get: function readonly2() {
|
|
301
|
+
return this[cppdb].readonly;
|
|
302
|
+
},
|
|
303
|
+
enumerable: true
|
|
304
|
+
},
|
|
305
|
+
memory: {
|
|
306
|
+
get: function memory() {
|
|
307
|
+
return this[cppdb].memory;
|
|
308
|
+
},
|
|
309
|
+
enumerable: true
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
// ../../node_modules/better-sqlite3/lib/methods/transaction.js
|
|
316
|
+
var require_transaction = __commonJS({
|
|
317
|
+
"../../node_modules/better-sqlite3/lib/methods/transaction.js"(exports2, module2) {
|
|
318
|
+
"use strict";
|
|
319
|
+
var { cppdb } = require_util();
|
|
320
|
+
var controllers = /* @__PURE__ */ new WeakMap();
|
|
321
|
+
module2.exports = function transaction(fn) {
|
|
322
|
+
if (typeof fn !== "function") throw new TypeError("Expected first argument to be a function");
|
|
323
|
+
const db = this[cppdb];
|
|
324
|
+
const controller = getController(db, this);
|
|
325
|
+
const { apply } = Function.prototype;
|
|
326
|
+
const properties = {
|
|
327
|
+
default: { value: wrapTransaction(apply, fn, db, controller.default) },
|
|
328
|
+
deferred: { value: wrapTransaction(apply, fn, db, controller.deferred) },
|
|
329
|
+
immediate: { value: wrapTransaction(apply, fn, db, controller.immediate) },
|
|
330
|
+
exclusive: { value: wrapTransaction(apply, fn, db, controller.exclusive) },
|
|
331
|
+
database: { value: this, enumerable: true }
|
|
332
|
+
};
|
|
333
|
+
Object.defineProperties(properties.default.value, properties);
|
|
334
|
+
Object.defineProperties(properties.deferred.value, properties);
|
|
335
|
+
Object.defineProperties(properties.immediate.value, properties);
|
|
336
|
+
Object.defineProperties(properties.exclusive.value, properties);
|
|
337
|
+
return properties.default.value;
|
|
338
|
+
};
|
|
339
|
+
var getController = (db, self) => {
|
|
340
|
+
let controller = controllers.get(db);
|
|
341
|
+
if (!controller) {
|
|
342
|
+
const shared = {
|
|
343
|
+
commit: db.prepare("COMMIT", self, false),
|
|
344
|
+
rollback: db.prepare("ROLLBACK", self, false),
|
|
345
|
+
savepoint: db.prepare("SAVEPOINT ` _bs3. `", self, false),
|
|
346
|
+
release: db.prepare("RELEASE ` _bs3. `", self, false),
|
|
347
|
+
rollbackTo: db.prepare("ROLLBACK TO ` _bs3. `", self, false)
|
|
348
|
+
};
|
|
349
|
+
controllers.set(db, controller = {
|
|
350
|
+
default: Object.assign({ begin: db.prepare("BEGIN", self, false) }, shared),
|
|
351
|
+
deferred: Object.assign({ begin: db.prepare("BEGIN DEFERRED", self, false) }, shared),
|
|
352
|
+
immediate: Object.assign({ begin: db.prepare("BEGIN IMMEDIATE", self, false) }, shared),
|
|
353
|
+
exclusive: Object.assign({ begin: db.prepare("BEGIN EXCLUSIVE", self, false) }, shared)
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
return controller;
|
|
357
|
+
};
|
|
358
|
+
var wrapTransaction = (apply, fn, db, { begin, commit, rollback, savepoint, release, rollbackTo }) => function sqliteTransaction() {
|
|
359
|
+
let before, after, undo;
|
|
360
|
+
if (db.inTransaction) {
|
|
361
|
+
before = savepoint;
|
|
362
|
+
after = release;
|
|
363
|
+
undo = rollbackTo;
|
|
364
|
+
} else {
|
|
365
|
+
before = begin;
|
|
366
|
+
after = commit;
|
|
367
|
+
undo = rollback;
|
|
368
|
+
}
|
|
369
|
+
before.run();
|
|
370
|
+
try {
|
|
371
|
+
const result = apply.call(fn, this, arguments);
|
|
372
|
+
if (result && typeof result.then === "function") {
|
|
373
|
+
throw new TypeError("Transaction function cannot return a promise");
|
|
374
|
+
}
|
|
375
|
+
after.run();
|
|
376
|
+
return result;
|
|
377
|
+
} catch (ex) {
|
|
378
|
+
if (db.inTransaction) {
|
|
379
|
+
undo.run();
|
|
380
|
+
if (undo !== rollback) after.run();
|
|
381
|
+
}
|
|
382
|
+
throw ex;
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
// ../../node_modules/better-sqlite3/lib/methods/pragma.js
|
|
389
|
+
var require_pragma = __commonJS({
|
|
390
|
+
"../../node_modules/better-sqlite3/lib/methods/pragma.js"(exports2, module2) {
|
|
391
|
+
"use strict";
|
|
392
|
+
var { getBooleanOption, cppdb } = require_util();
|
|
393
|
+
module2.exports = function pragma(source, options) {
|
|
394
|
+
if (options == null) options = {};
|
|
395
|
+
if (typeof source !== "string") throw new TypeError("Expected first argument to be a string");
|
|
396
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
397
|
+
const simple = getBooleanOption(options, "simple");
|
|
398
|
+
const stmt = this[cppdb].prepare(`PRAGMA ${source}`, this, true);
|
|
399
|
+
return simple ? stmt.pluck().get() : stmt.all();
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
// ../../node_modules/better-sqlite3/lib/methods/backup.js
|
|
405
|
+
var require_backup = __commonJS({
|
|
406
|
+
"../../node_modules/better-sqlite3/lib/methods/backup.js"(exports2, module2) {
|
|
407
|
+
"use strict";
|
|
408
|
+
var fs4 = require("fs");
|
|
409
|
+
var path5 = require("path");
|
|
410
|
+
var { promisify } = require("util");
|
|
411
|
+
var { cppdb } = require_util();
|
|
412
|
+
var fsAccess = promisify(fs4.access);
|
|
413
|
+
module2.exports = async function backup(filename, options) {
|
|
414
|
+
if (options == null) options = {};
|
|
415
|
+
if (typeof filename !== "string") throw new TypeError("Expected first argument to be a string");
|
|
416
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
417
|
+
filename = filename.trim();
|
|
418
|
+
const attachedName = "attached" in options ? options.attached : "main";
|
|
419
|
+
const handler = "progress" in options ? options.progress : null;
|
|
420
|
+
if (!filename) throw new TypeError("Backup filename cannot be an empty string");
|
|
421
|
+
if (filename === ":memory:") throw new TypeError('Invalid backup filename ":memory:"');
|
|
422
|
+
if (typeof attachedName !== "string") throw new TypeError('Expected the "attached" option to be a string');
|
|
423
|
+
if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
|
|
424
|
+
if (handler != null && typeof handler !== "function") throw new TypeError('Expected the "progress" option to be a function');
|
|
425
|
+
await fsAccess(path5.dirname(filename)).catch(() => {
|
|
426
|
+
throw new TypeError("Cannot save backup because the directory does not exist");
|
|
427
|
+
});
|
|
428
|
+
const isNewFile = await fsAccess(filename).then(() => false, () => true);
|
|
429
|
+
return runBackup(this[cppdb].backup(this, attachedName, filename, isNewFile), handler || null);
|
|
430
|
+
};
|
|
431
|
+
var runBackup = (backup, handler) => {
|
|
432
|
+
let rate = 0;
|
|
433
|
+
let useDefault = true;
|
|
434
|
+
return new Promise((resolve2, reject) => {
|
|
435
|
+
setImmediate(function step() {
|
|
436
|
+
try {
|
|
437
|
+
const progress = backup.transfer(rate);
|
|
438
|
+
if (!progress.remainingPages) {
|
|
439
|
+
backup.close();
|
|
440
|
+
resolve2(progress);
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (useDefault) {
|
|
444
|
+
useDefault = false;
|
|
445
|
+
rate = 100;
|
|
446
|
+
}
|
|
447
|
+
if (handler) {
|
|
448
|
+
const ret = handler(progress);
|
|
449
|
+
if (ret !== void 0) {
|
|
450
|
+
if (typeof ret === "number" && ret === ret) rate = Math.max(0, Math.min(2147483647, Math.round(ret)));
|
|
451
|
+
else throw new TypeError("Expected progress callback to return a number or undefined");
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
setImmediate(step);
|
|
455
|
+
} catch (err) {
|
|
456
|
+
backup.close();
|
|
457
|
+
reject(err);
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
// ../../node_modules/better-sqlite3/lib/methods/serialize.js
|
|
466
|
+
var require_serialize = __commonJS({
|
|
467
|
+
"../../node_modules/better-sqlite3/lib/methods/serialize.js"(exports2, module2) {
|
|
468
|
+
"use strict";
|
|
469
|
+
var { cppdb } = require_util();
|
|
470
|
+
module2.exports = function serialize(options) {
|
|
471
|
+
if (options == null) options = {};
|
|
472
|
+
if (typeof options !== "object") throw new TypeError("Expected first argument to be an options object");
|
|
473
|
+
const attachedName = "attached" in options ? options.attached : "main";
|
|
474
|
+
if (typeof attachedName !== "string") throw new TypeError('Expected the "attached" option to be a string');
|
|
475
|
+
if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
|
|
476
|
+
return this[cppdb].serialize(attachedName);
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
// ../../node_modules/better-sqlite3/lib/methods/function.js
|
|
482
|
+
var require_function = __commonJS({
|
|
483
|
+
"../../node_modules/better-sqlite3/lib/methods/function.js"(exports2, module2) {
|
|
484
|
+
"use strict";
|
|
485
|
+
var { getBooleanOption, cppdb } = require_util();
|
|
486
|
+
module2.exports = function defineFunction(name, options, fn) {
|
|
487
|
+
if (options == null) options = {};
|
|
488
|
+
if (typeof options === "function") {
|
|
489
|
+
fn = options;
|
|
490
|
+
options = {};
|
|
491
|
+
}
|
|
492
|
+
if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
|
|
493
|
+
if (typeof fn !== "function") throw new TypeError("Expected last argument to be a function");
|
|
494
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
495
|
+
if (!name) throw new TypeError("User-defined function name cannot be an empty string");
|
|
496
|
+
const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
|
|
497
|
+
const deterministic = getBooleanOption(options, "deterministic");
|
|
498
|
+
const directOnly = getBooleanOption(options, "directOnly");
|
|
499
|
+
const varargs = getBooleanOption(options, "varargs");
|
|
500
|
+
let argCount = -1;
|
|
501
|
+
if (!varargs) {
|
|
502
|
+
argCount = fn.length;
|
|
503
|
+
if (!Number.isInteger(argCount) || argCount < 0) throw new TypeError("Expected function.length to be a positive integer");
|
|
504
|
+
if (argCount > 100) throw new RangeError("User-defined functions cannot have more than 100 arguments");
|
|
505
|
+
}
|
|
506
|
+
this[cppdb].function(fn, name, argCount, safeIntegers, deterministic, directOnly);
|
|
507
|
+
return this;
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
// ../../node_modules/better-sqlite3/lib/methods/aggregate.js
|
|
513
|
+
var require_aggregate = __commonJS({
|
|
514
|
+
"../../node_modules/better-sqlite3/lib/methods/aggregate.js"(exports2, module2) {
|
|
515
|
+
"use strict";
|
|
516
|
+
var { getBooleanOption, cppdb } = require_util();
|
|
517
|
+
module2.exports = function defineAggregate(name, options) {
|
|
518
|
+
if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
|
|
519
|
+
if (typeof options !== "object" || options === null) throw new TypeError("Expected second argument to be an options object");
|
|
520
|
+
if (!name) throw new TypeError("User-defined function name cannot be an empty string");
|
|
521
|
+
const start = "start" in options ? options.start : null;
|
|
522
|
+
const step = getFunctionOption(options, "step", true);
|
|
523
|
+
const inverse = getFunctionOption(options, "inverse", false);
|
|
524
|
+
const result = getFunctionOption(options, "result", false);
|
|
525
|
+
const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
|
|
526
|
+
const deterministic = getBooleanOption(options, "deterministic");
|
|
527
|
+
const directOnly = getBooleanOption(options, "directOnly");
|
|
528
|
+
const varargs = getBooleanOption(options, "varargs");
|
|
529
|
+
let argCount = -1;
|
|
530
|
+
if (!varargs) {
|
|
531
|
+
argCount = Math.max(getLength(step), inverse ? getLength(inverse) : 0);
|
|
532
|
+
if (argCount > 0) argCount -= 1;
|
|
533
|
+
if (argCount > 100) throw new RangeError("User-defined functions cannot have more than 100 arguments");
|
|
534
|
+
}
|
|
535
|
+
this[cppdb].aggregate(start, step, inverse, result, name, argCount, safeIntegers, deterministic, directOnly);
|
|
536
|
+
return this;
|
|
537
|
+
};
|
|
538
|
+
var getFunctionOption = (options, key, required2) => {
|
|
539
|
+
const value = key in options ? options[key] : null;
|
|
540
|
+
if (typeof value === "function") return value;
|
|
541
|
+
if (value != null) throw new TypeError(`Expected the "${key}" option to be a function`);
|
|
542
|
+
if (required2) throw new TypeError(`Missing required option "${key}"`);
|
|
543
|
+
return null;
|
|
544
|
+
};
|
|
545
|
+
var getLength = ({ length }) => {
|
|
546
|
+
if (Number.isInteger(length) && length >= 0) return length;
|
|
547
|
+
throw new TypeError("Expected function.length to be a positive integer");
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
// ../../node_modules/better-sqlite3/lib/methods/table.js
|
|
553
|
+
var require_table = __commonJS({
|
|
554
|
+
"../../node_modules/better-sqlite3/lib/methods/table.js"(exports2, module2) {
|
|
555
|
+
"use strict";
|
|
556
|
+
var { cppdb } = require_util();
|
|
557
|
+
module2.exports = function defineTable(name, factory) {
|
|
558
|
+
if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
|
|
559
|
+
if (!name) throw new TypeError("Virtual table module name cannot be an empty string");
|
|
560
|
+
let eponymous = false;
|
|
561
|
+
if (typeof factory === "object" && factory !== null) {
|
|
562
|
+
eponymous = true;
|
|
563
|
+
factory = defer(parseTableDefinition(factory, "used", name));
|
|
564
|
+
} else {
|
|
565
|
+
if (typeof factory !== "function") throw new TypeError("Expected second argument to be a function or a table definition object");
|
|
566
|
+
factory = wrapFactory(factory);
|
|
567
|
+
}
|
|
568
|
+
this[cppdb].table(factory, name, eponymous);
|
|
569
|
+
return this;
|
|
570
|
+
};
|
|
571
|
+
function wrapFactory(factory) {
|
|
572
|
+
return function virtualTableFactory(moduleName, databaseName, tableName, ...args) {
|
|
573
|
+
const thisObject = {
|
|
574
|
+
module: moduleName,
|
|
575
|
+
database: databaseName,
|
|
576
|
+
table: tableName
|
|
577
|
+
};
|
|
578
|
+
const def = apply.call(factory, thisObject, args);
|
|
579
|
+
if (typeof def !== "object" || def === null) {
|
|
580
|
+
throw new TypeError(`Virtual table module "${moduleName}" did not return a table definition object`);
|
|
581
|
+
}
|
|
582
|
+
return parseTableDefinition(def, "returned", moduleName);
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
function parseTableDefinition(def, verb, moduleName) {
|
|
586
|
+
if (!hasOwnProperty.call(def, "rows")) {
|
|
587
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "rows" property`);
|
|
588
|
+
}
|
|
589
|
+
if (!hasOwnProperty.call(def, "columns")) {
|
|
590
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "columns" property`);
|
|
591
|
+
}
|
|
592
|
+
const rows = def.rows;
|
|
593
|
+
if (typeof rows !== "function" || Object.getPrototypeOf(rows) !== GeneratorFunctionPrototype) {
|
|
594
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "rows" property (should be a generator function)`);
|
|
595
|
+
}
|
|
596
|
+
let columns = def.columns;
|
|
597
|
+
if (!Array.isArray(columns) || !(columns = [...columns]).every((x) => typeof x === "string")) {
|
|
598
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "columns" property (should be an array of strings)`);
|
|
599
|
+
}
|
|
600
|
+
if (columns.length !== new Set(columns).size) {
|
|
601
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate column names`);
|
|
602
|
+
}
|
|
603
|
+
if (!columns.length) {
|
|
604
|
+
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with zero columns`);
|
|
605
|
+
}
|
|
606
|
+
let parameters;
|
|
607
|
+
if (hasOwnProperty.call(def, "parameters")) {
|
|
608
|
+
parameters = def.parameters;
|
|
609
|
+
if (!Array.isArray(parameters) || !(parameters = [...parameters]).every((x) => typeof x === "string")) {
|
|
610
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "parameters" property (should be an array of strings)`);
|
|
611
|
+
}
|
|
612
|
+
} else {
|
|
613
|
+
parameters = inferParameters(rows);
|
|
614
|
+
}
|
|
615
|
+
if (parameters.length !== new Set(parameters).size) {
|
|
616
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate parameter names`);
|
|
617
|
+
}
|
|
618
|
+
if (parameters.length > 32) {
|
|
619
|
+
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with more than the maximum number of 32 parameters`);
|
|
620
|
+
}
|
|
621
|
+
for (const parameter of parameters) {
|
|
622
|
+
if (columns.includes(parameter)) {
|
|
623
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with column "${parameter}" which was ambiguously defined as both a column and parameter`);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
let safeIntegers = 2;
|
|
627
|
+
if (hasOwnProperty.call(def, "safeIntegers")) {
|
|
628
|
+
const bool = def.safeIntegers;
|
|
629
|
+
if (typeof bool !== "boolean") {
|
|
630
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "safeIntegers" property (should be a boolean)`);
|
|
631
|
+
}
|
|
632
|
+
safeIntegers = +bool;
|
|
633
|
+
}
|
|
634
|
+
let directOnly = false;
|
|
635
|
+
if (hasOwnProperty.call(def, "directOnly")) {
|
|
636
|
+
directOnly = def.directOnly;
|
|
637
|
+
if (typeof directOnly !== "boolean") {
|
|
638
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "directOnly" property (should be a boolean)`);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
const columnDefinitions = [
|
|
642
|
+
...parameters.map(identifier).map((str) => `${str} HIDDEN`),
|
|
643
|
+
...columns.map(identifier)
|
|
644
|
+
];
|
|
645
|
+
return [
|
|
646
|
+
`CREATE TABLE x(${columnDefinitions.join(", ")});`,
|
|
647
|
+
wrapGenerator(rows, new Map(columns.map((x, i) => [x, parameters.length + i])), moduleName),
|
|
648
|
+
parameters,
|
|
649
|
+
safeIntegers,
|
|
650
|
+
directOnly
|
|
651
|
+
];
|
|
652
|
+
}
|
|
653
|
+
function wrapGenerator(generator, columnMap, moduleName) {
|
|
654
|
+
return function* virtualTable(...args) {
|
|
655
|
+
const output = args.map((x) => Buffer.isBuffer(x) ? Buffer.from(x) : x);
|
|
656
|
+
for (let i = 0; i < columnMap.size; ++i) {
|
|
657
|
+
output.push(null);
|
|
658
|
+
}
|
|
659
|
+
for (const row of generator(...args)) {
|
|
660
|
+
if (Array.isArray(row)) {
|
|
661
|
+
extractRowArray(row, output, columnMap.size, moduleName);
|
|
662
|
+
yield output;
|
|
663
|
+
} else if (typeof row === "object" && row !== null) {
|
|
664
|
+
extractRowObject(row, output, columnMap, moduleName);
|
|
665
|
+
yield output;
|
|
666
|
+
} else {
|
|
667
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded something that isn't a valid row object`);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
function extractRowArray(row, output, columnCount, moduleName) {
|
|
673
|
+
if (row.length !== columnCount) {
|
|
674
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an incorrect number of columns`);
|
|
675
|
+
}
|
|
676
|
+
const offset = output.length - columnCount;
|
|
677
|
+
for (let i = 0; i < columnCount; ++i) {
|
|
678
|
+
output[i + offset] = row[i];
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
function extractRowObject(row, output, columnMap, moduleName) {
|
|
682
|
+
let count = 0;
|
|
683
|
+
for (const key of Object.keys(row)) {
|
|
684
|
+
const index = columnMap.get(key);
|
|
685
|
+
if (index === void 0) {
|
|
686
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an undeclared column "${key}"`);
|
|
687
|
+
}
|
|
688
|
+
output[index] = row[key];
|
|
689
|
+
count += 1;
|
|
690
|
+
}
|
|
691
|
+
if (count !== columnMap.size) {
|
|
692
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with missing columns`);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
function inferParameters({ length }) {
|
|
696
|
+
if (!Number.isInteger(length) || length < 0) {
|
|
697
|
+
throw new TypeError("Expected function.length to be a positive integer");
|
|
698
|
+
}
|
|
699
|
+
const params = [];
|
|
700
|
+
for (let i = 0; i < length; ++i) {
|
|
701
|
+
params.push(`$${i + 1}`);
|
|
702
|
+
}
|
|
703
|
+
return params;
|
|
704
|
+
}
|
|
705
|
+
var { hasOwnProperty } = Object.prototype;
|
|
706
|
+
var { apply } = Function.prototype;
|
|
707
|
+
var GeneratorFunctionPrototype = Object.getPrototypeOf(function* () {
|
|
708
|
+
});
|
|
709
|
+
var identifier = (str) => `"${str.replace(/"/g, '""')}"`;
|
|
710
|
+
var defer = (x) => () => x;
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
// ../../node_modules/better-sqlite3/lib/methods/inspect.js
|
|
715
|
+
var require_inspect = __commonJS({
|
|
716
|
+
"../../node_modules/better-sqlite3/lib/methods/inspect.js"(exports2, module2) {
|
|
717
|
+
"use strict";
|
|
718
|
+
var DatabaseInspection = function Database() {
|
|
719
|
+
};
|
|
720
|
+
module2.exports = function inspect(depth, opts) {
|
|
721
|
+
return Object.assign(new DatabaseInspection(), this);
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
// ../../node_modules/better-sqlite3/lib/database.js
|
|
727
|
+
var require_database = __commonJS({
|
|
728
|
+
"../../node_modules/better-sqlite3/lib/database.js"(exports2, module2) {
|
|
729
|
+
"use strict";
|
|
730
|
+
var fs4 = require("fs");
|
|
731
|
+
var path5 = require("path");
|
|
732
|
+
var util = require_util();
|
|
733
|
+
var SqliteError = require_sqlite_error();
|
|
734
|
+
var DEFAULT_ADDON;
|
|
735
|
+
function Database(filenameGiven, options) {
|
|
736
|
+
if (new.target == null) {
|
|
737
|
+
return new Database(filenameGiven, options);
|
|
738
|
+
}
|
|
739
|
+
let buffer;
|
|
740
|
+
if (Buffer.isBuffer(filenameGiven)) {
|
|
741
|
+
buffer = filenameGiven;
|
|
742
|
+
filenameGiven = ":memory:";
|
|
743
|
+
}
|
|
744
|
+
if (filenameGiven == null) filenameGiven = "";
|
|
745
|
+
if (options == null) options = {};
|
|
746
|
+
if (typeof filenameGiven !== "string") throw new TypeError("Expected first argument to be a string");
|
|
747
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
748
|
+
if ("readOnly" in options) throw new TypeError('Misspelled option "readOnly" should be "readonly"');
|
|
749
|
+
if ("memory" in options) throw new TypeError('Option "memory" was removed in v7.0.0 (use ":memory:" filename instead)');
|
|
750
|
+
const filename = filenameGiven.trim();
|
|
751
|
+
const anonymous = filename === "" || filename === ":memory:";
|
|
752
|
+
const readonly2 = util.getBooleanOption(options, "readonly");
|
|
753
|
+
const fileMustExist = util.getBooleanOption(options, "fileMustExist");
|
|
754
|
+
const timeout = "timeout" in options ? options.timeout : 5e3;
|
|
755
|
+
const verbose = "verbose" in options ? options.verbose : null;
|
|
756
|
+
const nativeBinding = "nativeBinding" in options ? options.nativeBinding : null;
|
|
757
|
+
if (readonly2 && anonymous && !buffer) throw new TypeError("In-memory/temporary databases cannot be readonly");
|
|
758
|
+
if (!Number.isInteger(timeout) || timeout < 0) throw new TypeError('Expected the "timeout" option to be a positive integer');
|
|
759
|
+
if (timeout > 2147483647) throw new RangeError('Option "timeout" cannot be greater than 2147483647');
|
|
760
|
+
if (verbose != null && typeof verbose !== "function") throw new TypeError('Expected the "verbose" option to be a function');
|
|
761
|
+
if (nativeBinding != null && typeof nativeBinding !== "string" && typeof nativeBinding !== "object") throw new TypeError('Expected the "nativeBinding" option to be a string or addon object');
|
|
762
|
+
let addon;
|
|
763
|
+
if (nativeBinding == null) {
|
|
764
|
+
addon = DEFAULT_ADDON || (DEFAULT_ADDON = require_bindings()("better_sqlite3.node"));
|
|
765
|
+
} else if (typeof nativeBinding === "string") {
|
|
766
|
+
const requireFunc = typeof __non_webpack_require__ === "function" ? __non_webpack_require__ : require;
|
|
767
|
+
addon = requireFunc(path5.resolve(nativeBinding).replace(/(\.node)?$/, ".node"));
|
|
768
|
+
} else {
|
|
769
|
+
addon = nativeBinding;
|
|
770
|
+
}
|
|
771
|
+
if (!addon.isInitialized) {
|
|
772
|
+
addon.setErrorConstructor(SqliteError);
|
|
773
|
+
addon.isInitialized = true;
|
|
774
|
+
}
|
|
775
|
+
if (!anonymous && !filename.startsWith("file:") && !fs4.existsSync(path5.dirname(filename))) {
|
|
776
|
+
throw new TypeError("Cannot open database because the directory does not exist");
|
|
777
|
+
}
|
|
778
|
+
Object.defineProperties(this, {
|
|
779
|
+
[util.cppdb]: { value: new addon.Database(filename, filenameGiven, anonymous, readonly2, fileMustExist, timeout, verbose || null, buffer || null) },
|
|
780
|
+
...wrappers.getters
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
var wrappers = require_wrappers();
|
|
784
|
+
Database.prototype.prepare = wrappers.prepare;
|
|
785
|
+
Database.prototype.transaction = require_transaction();
|
|
786
|
+
Database.prototype.pragma = require_pragma();
|
|
787
|
+
Database.prototype.backup = require_backup();
|
|
788
|
+
Database.prototype.serialize = require_serialize();
|
|
789
|
+
Database.prototype.function = require_function();
|
|
790
|
+
Database.prototype.aggregate = require_aggregate();
|
|
791
|
+
Database.prototype.table = require_table();
|
|
792
|
+
Database.prototype.loadExtension = wrappers.loadExtension;
|
|
793
|
+
Database.prototype.exec = wrappers.exec;
|
|
794
|
+
Database.prototype.close = wrappers.close;
|
|
795
|
+
Database.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;
|
|
796
|
+
Database.prototype.unsafeMode = wrappers.unsafeMode;
|
|
797
|
+
Database.prototype[util.inspect] = require_inspect();
|
|
798
|
+
module2.exports = Database;
|
|
799
|
+
}
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
// ../../node_modules/better-sqlite3/lib/index.js
|
|
803
|
+
var require_lib = __commonJS({
|
|
804
|
+
"../../node_modules/better-sqlite3/lib/index.js"(exports2, module2) {
|
|
805
|
+
"use strict";
|
|
806
|
+
module2.exports = require_database();
|
|
807
|
+
module2.exports.SqliteError = require_sqlite_error();
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
|
|
37
811
|
// ../session-host-core/dist/index.js
|
|
38
812
|
var require_dist = __commonJS({
|
|
39
813
|
"../session-host-core/dist/index.js"(exports2, module2) {
|
|
@@ -23812,14 +24586,162 @@ Follow these recovery rules:
|
|
|
23812
24586
|
meshLedgerEvents = new import_events.EventEmitter();
|
|
23813
24587
|
}
|
|
23814
24588
|
});
|
|
24589
|
+
function safeMeshId(meshId) {
|
|
24590
|
+
return meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
24591
|
+
}
|
|
24592
|
+
function legacyQueuePath(meshId) {
|
|
24593
|
+
return (0, import_path5.join)(getLedgerDir(), `${safeMeshId(meshId)}.queue.json`);
|
|
24594
|
+
}
|
|
24595
|
+
var import_better_sqlite3;
|
|
24596
|
+
var import_fs5;
|
|
24597
|
+
var import_path5;
|
|
24598
|
+
var BeadsDB;
|
|
24599
|
+
var init_beads_db = __esm2({
|
|
24600
|
+
"src/mesh/beads-db.ts"() {
|
|
24601
|
+
"use strict";
|
|
24602
|
+
import_better_sqlite3 = __toESM2(require_lib());
|
|
24603
|
+
import_fs5 = require("fs");
|
|
24604
|
+
import_path5 = require("path");
|
|
24605
|
+
init_mesh_ledger();
|
|
24606
|
+
BeadsDB = class _BeadsDB {
|
|
24607
|
+
static instance;
|
|
24608
|
+
db;
|
|
24609
|
+
migratedMeshIds = /* @__PURE__ */ new Set();
|
|
24610
|
+
constructor(dbPath) {
|
|
24611
|
+
const dir = (0, import_path5.dirname)(dbPath);
|
|
24612
|
+
if (!(0, import_fs5.existsSync)(dir)) (0, import_fs5.mkdirSync)(dir, { recursive: true });
|
|
24613
|
+
this.db = new import_better_sqlite3.default(dbPath);
|
|
24614
|
+
this.db.pragma("journal_mode = WAL");
|
|
24615
|
+
this.db.pragma("synchronous = NORMAL");
|
|
24616
|
+
this.db.pragma("foreign_keys = ON");
|
|
24617
|
+
this.db.pragma("busy_timeout = 5000");
|
|
24618
|
+
this.migrate();
|
|
24619
|
+
}
|
|
24620
|
+
static getInstance() {
|
|
24621
|
+
if (!this.instance) {
|
|
24622
|
+
this.instance = new _BeadsDB((0, import_path5.join)(getLedgerDir(), "beads.db"));
|
|
24623
|
+
}
|
|
24624
|
+
return this.instance;
|
|
24625
|
+
}
|
|
24626
|
+
static resetForTests() {
|
|
24627
|
+
this.instance?.close();
|
|
24628
|
+
this.instance = void 0;
|
|
24629
|
+
}
|
|
24630
|
+
close() {
|
|
24631
|
+
this.db.close();
|
|
24632
|
+
}
|
|
24633
|
+
transaction(fn) {
|
|
24634
|
+
return this.db.transaction(fn).immediate();
|
|
24635
|
+
}
|
|
24636
|
+
migrate() {
|
|
24637
|
+
this.db.exec(`
|
|
24638
|
+
CREATE TABLE IF NOT EXISTS mesh_queue (
|
|
24639
|
+
id TEXT PRIMARY KEY,
|
|
24640
|
+
mesh_id TEXT NOT NULL,
|
|
24641
|
+
status TEXT NOT NULL,
|
|
24642
|
+
target_node_id TEXT,
|
|
24643
|
+
target_session_id TEXT,
|
|
24644
|
+
assigned_node_id TEXT,
|
|
24645
|
+
assigned_session_id TEXT,
|
|
24646
|
+
created_at TEXT NOT NULL,
|
|
24647
|
+
updated_at TEXT NOT NULL,
|
|
24648
|
+
payload TEXT NOT NULL
|
|
24649
|
+
);
|
|
24650
|
+
|
|
24651
|
+
CREATE INDEX IF NOT EXISTS idx_mesh_queue_mesh_status_created
|
|
24652
|
+
ON mesh_queue(mesh_id, status, created_at);
|
|
24653
|
+
CREATE INDEX IF NOT EXISTS idx_mesh_queue_assignment
|
|
24654
|
+
ON mesh_queue(mesh_id, assigned_node_id, assigned_session_id, status);
|
|
24655
|
+
`);
|
|
24656
|
+
}
|
|
24657
|
+
ensureLegacyQueueMigrated(meshId) {
|
|
24658
|
+
if (this.migratedMeshIds.has(meshId)) return;
|
|
24659
|
+
this.migratedMeshIds.add(meshId);
|
|
24660
|
+
const count = this.db.prepare("SELECT COUNT(*) AS count FROM mesh_queue WHERE mesh_id = ?").get(meshId);
|
|
24661
|
+
if (count.count > 0) return;
|
|
24662
|
+
const path28 = legacyQueuePath(meshId);
|
|
24663
|
+
if (!(0, import_fs5.existsSync)(path28)) return;
|
|
24664
|
+
try {
|
|
24665
|
+
const entries = JSON.parse((0, import_fs5.readFileSync)(path28, "utf-8"));
|
|
24666
|
+
if (!Array.isArray(entries)) return;
|
|
24667
|
+
const insert = this.db.prepare(`
|
|
24668
|
+
INSERT OR REPLACE INTO mesh_queue (
|
|
24669
|
+
id, mesh_id, status, target_node_id, target_session_id,
|
|
24670
|
+
assigned_node_id, assigned_session_id, created_at, updated_at, payload
|
|
24671
|
+
) VALUES (
|
|
24672
|
+
@id, @meshId, @status, @targetNodeId, @targetSessionId,
|
|
24673
|
+
@assignedNodeId, @assignedSessionId, @createdAt, @updatedAt, @payload
|
|
24674
|
+
)
|
|
24675
|
+
`);
|
|
24676
|
+
for (const entry of entries) {
|
|
24677
|
+
insert.run(this.toRow(entry));
|
|
24678
|
+
}
|
|
24679
|
+
} catch {
|
|
24680
|
+
return;
|
|
24681
|
+
}
|
|
24682
|
+
}
|
|
24683
|
+
getQueueEntries(meshId, statuses) {
|
|
24684
|
+
this.ensureLegacyQueueMigrated(meshId);
|
|
24685
|
+
if (statuses?.length) {
|
|
24686
|
+
const placeholders = statuses.map(() => "?").join(", ");
|
|
24687
|
+
const rows2 = this.db.prepare(`SELECT payload FROM mesh_queue WHERE mesh_id = ? AND status IN (${placeholders}) ORDER BY created_at ASC`).all(meshId, ...statuses);
|
|
24688
|
+
return rows2.map((row) => JSON.parse(row.payload));
|
|
24689
|
+
}
|
|
24690
|
+
const rows = this.db.prepare("SELECT payload FROM mesh_queue WHERE mesh_id = ? ORDER BY created_at ASC").all(meshId);
|
|
24691
|
+
return rows.map((row) => JSON.parse(row.payload));
|
|
24692
|
+
}
|
|
24693
|
+
getQueueRevision(meshId) {
|
|
24694
|
+
this.ensureLegacyQueueMigrated(meshId);
|
|
24695
|
+
const rows = this.db.prepare("SELECT id, status, updated_at FROM mesh_queue WHERE mesh_id = ? ORDER BY id ASC").all(meshId);
|
|
24696
|
+
return rows.map((row) => `${row.id}:${row.status}:${row.updated_at}`).join("|");
|
|
24697
|
+
}
|
|
24698
|
+
replaceQueue(meshId, queue) {
|
|
24699
|
+
const deleteStmt = this.db.prepare("DELETE FROM mesh_queue WHERE mesh_id = ?");
|
|
24700
|
+
const insert = this.db.prepare(`
|
|
24701
|
+
INSERT INTO mesh_queue (
|
|
24702
|
+
id, mesh_id, status, target_node_id, target_session_id,
|
|
24703
|
+
assigned_node_id, assigned_session_id, created_at, updated_at, payload
|
|
24704
|
+
) VALUES (
|
|
24705
|
+
@id, @meshId, @status, @targetNodeId, @targetSessionId,
|
|
24706
|
+
@assignedNodeId, @assignedSessionId, @createdAt, @updatedAt, @payload
|
|
24707
|
+
)
|
|
24708
|
+
`);
|
|
24709
|
+
deleteStmt.run(meshId);
|
|
24710
|
+
for (const entry of queue) insert.run(this.toRow(entry));
|
|
24711
|
+
}
|
|
24712
|
+
deleteQueue(meshId) {
|
|
24713
|
+
this.db.prepare("DELETE FROM mesh_queue WHERE mesh_id = ?").run(meshId);
|
|
24714
|
+
this.migratedMeshIds.delete(meshId);
|
|
24715
|
+
}
|
|
24716
|
+
toRow(entry) {
|
|
24717
|
+
return {
|
|
24718
|
+
id: entry.id,
|
|
24719
|
+
meshId: entry.meshId,
|
|
24720
|
+
status: entry.status,
|
|
24721
|
+
targetNodeId: entry.targetNodeId ?? null,
|
|
24722
|
+
targetSessionId: entry.targetSessionId ?? null,
|
|
24723
|
+
assignedNodeId: entry.assignedNodeId ?? null,
|
|
24724
|
+
assignedSessionId: entry.assignedSessionId ?? null,
|
|
24725
|
+
createdAt: entry.createdAt,
|
|
24726
|
+
updatedAt: entry.updatedAt,
|
|
24727
|
+
payload: JSON.stringify(entry)
|
|
24728
|
+
};
|
|
24729
|
+
}
|
|
24730
|
+
};
|
|
24731
|
+
}
|
|
24732
|
+
});
|
|
23815
24733
|
var mesh_work_queue_exports = {};
|
|
23816
24734
|
__export2(mesh_work_queue_exports, {
|
|
23817
24735
|
ACTIVE_MESH_QUEUE_STATUSES: () => ACTIVE_MESH_QUEUE_STATUSES,
|
|
23818
24736
|
HISTORICAL_MESH_QUEUE_STATUSES: () => HISTORICAL_MESH_QUEUE_STATUSES,
|
|
23819
24737
|
MESH_TASK_MODES: () => MESH_TASK_MODES,
|
|
24738
|
+
__clearMeshQueueForTests: () => __clearMeshQueueForTests,
|
|
24739
|
+
__replaceMeshQueueForTests: () => __replaceMeshQueueForTests,
|
|
24740
|
+
__resetBeadsDBForTests: () => __resetBeadsDBForTests,
|
|
23820
24741
|
cancelTask: () => cancelTask,
|
|
23821
24742
|
claimNextTask: () => claimNextTask,
|
|
23822
24743
|
enqueueTask: () => enqueueTask,
|
|
24744
|
+
getMeshQueueRevision: () => getMeshQueueRevision,
|
|
23823
24745
|
getMeshQueueStats: () => getMeshQueueStats,
|
|
23824
24746
|
getQueue: () => getQueue,
|
|
23825
24747
|
normalizeMeshTaskMode: () => normalizeMeshTaskMode,
|
|
@@ -23855,53 +24777,14 @@ Follow these recovery rules:
|
|
|
23855
24777
|
]
|
|
23856
24778
|
};
|
|
23857
24779
|
}
|
|
23858
|
-
function
|
|
23859
|
-
|
|
23860
|
-
return (0, import_path5.join)(getLedgerDir(), `${safe}.queue.json`);
|
|
23861
|
-
}
|
|
23862
|
-
function getLockPath(meshId) {
|
|
23863
|
-
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
23864
|
-
return (0, import_path5.join)(getLedgerDir(), `${safe}.queue.lock`);
|
|
23865
|
-
}
|
|
23866
|
-
function withQueueLock(meshId, fn) {
|
|
23867
|
-
const lockPath = getLockPath(meshId);
|
|
23868
|
-
let fd = -1;
|
|
23869
|
-
for (let i = 0; i < 10; i++) {
|
|
23870
|
-
try {
|
|
23871
|
-
fd = (0, import_fs5.openSync)(lockPath, "wx");
|
|
23872
|
-
break;
|
|
23873
|
-
} catch {
|
|
23874
|
-
const deadline = Date.now() + 30;
|
|
23875
|
-
while (Date.now() < deadline) {
|
|
23876
|
-
}
|
|
23877
|
-
}
|
|
23878
|
-
}
|
|
23879
|
-
try {
|
|
23880
|
-
return fn();
|
|
23881
|
-
} finally {
|
|
23882
|
-
if (fd !== -1) try {
|
|
23883
|
-
(0, import_fs5.closeSync)(fd);
|
|
23884
|
-
} catch {
|
|
23885
|
-
}
|
|
23886
|
-
try {
|
|
23887
|
-
(0, import_fs5.unlinkSync)(lockPath);
|
|
23888
|
-
} catch {
|
|
23889
|
-
}
|
|
23890
|
-
}
|
|
24780
|
+
function withQueueLock(_meshId, fn) {
|
|
24781
|
+
return BeadsDB.getInstance().transaction(fn);
|
|
23891
24782
|
}
|
|
23892
24783
|
function readQueue(meshId) {
|
|
23893
|
-
|
|
23894
|
-
if (!(0, import_fs5.existsSync)(path28)) return [];
|
|
23895
|
-
try {
|
|
23896
|
-
const content = (0, import_fs5.readFileSync)(path28, "utf-8");
|
|
23897
|
-
return JSON.parse(content);
|
|
23898
|
-
} catch {
|
|
23899
|
-
return [];
|
|
23900
|
-
}
|
|
24784
|
+
return BeadsDB.getInstance().getQueueEntries(meshId);
|
|
23901
24785
|
}
|
|
23902
24786
|
function writeQueue(meshId, queue) {
|
|
23903
|
-
|
|
23904
|
-
(0, import_fs5.writeFileSync)(path28, JSON.stringify(queue, null, 2), "utf-8");
|
|
24787
|
+
BeadsDB.getInstance().replaceQueue(meshId, queue);
|
|
23905
24788
|
}
|
|
23906
24789
|
function enqueueTask(meshId, message, opts) {
|
|
23907
24790
|
requireMeshHostQueueOwner(opts);
|
|
@@ -23935,6 +24818,9 @@ Follow these recovery rules:
|
|
|
23935
24818
|
}
|
|
23936
24819
|
return queue;
|
|
23937
24820
|
}
|
|
24821
|
+
function getMeshQueueRevision(meshId) {
|
|
24822
|
+
return BeadsDB.getInstance().getQueueRevision(meshId);
|
|
24823
|
+
}
|
|
23938
24824
|
function claimNextTask(meshId, nodeId, sessionId) {
|
|
23939
24825
|
return withQueueLock(meshId, () => {
|
|
23940
24826
|
const queue = readQueue(meshId);
|
|
@@ -24078,8 +24964,17 @@ Follow these recovery rules:
|
|
|
24078
24964
|
}))
|
|
24079
24965
|
};
|
|
24080
24966
|
}
|
|
24081
|
-
|
|
24082
|
-
|
|
24967
|
+
function __replaceMeshQueueForTests(meshId, queue) {
|
|
24968
|
+
BeadsDB.getInstance().transaction(() => {
|
|
24969
|
+
BeadsDB.getInstance().replaceQueue(meshId, queue);
|
|
24970
|
+
});
|
|
24971
|
+
}
|
|
24972
|
+
function __clearMeshQueueForTests(meshId) {
|
|
24973
|
+
BeadsDB.getInstance().deleteQueue(meshId);
|
|
24974
|
+
}
|
|
24975
|
+
function __resetBeadsDBForTests() {
|
|
24976
|
+
BeadsDB.resetForTests();
|
|
24977
|
+
}
|
|
24083
24978
|
var import_crypto5;
|
|
24084
24979
|
var ACTIVE_MESH_QUEUE_STATUSES;
|
|
24085
24980
|
var HISTORICAL_MESH_QUEUE_STATUSES;
|
|
@@ -24088,11 +24983,9 @@ Follow these recovery rules:
|
|
|
24088
24983
|
var init_mesh_work_queue = __esm2({
|
|
24089
24984
|
"src/mesh/mesh-work-queue.ts"() {
|
|
24090
24985
|
"use strict";
|
|
24091
|
-
import_fs5 = require("fs");
|
|
24092
|
-
import_path5 = require("path");
|
|
24093
24986
|
import_crypto5 = require("crypto");
|
|
24094
|
-
init_mesh_ledger();
|
|
24095
24987
|
init_mesh_host_ownership();
|
|
24988
|
+
init_beads_db();
|
|
24096
24989
|
ACTIVE_MESH_QUEUE_STATUSES = ["pending", "assigned"];
|
|
24097
24990
|
HISTORICAL_MESH_QUEUE_STATUSES = ["completed", "failed", "cancelled"];
|
|
24098
24991
|
MESH_TASK_MODES = ["code_change", "validation", "live_debug_readonly", "launch_app", "convergence"];
|
|
@@ -24241,6 +25134,59 @@ Follow these recovery rules:
|
|
|
24241
25134
|
import_fs6 = require("fs");
|
|
24242
25135
|
}
|
|
24243
25136
|
});
|
|
25137
|
+
var fs22;
|
|
25138
|
+
var AsyncBatchWriter;
|
|
25139
|
+
var init_async_batch_writer = __esm2({
|
|
25140
|
+
"src/logging/async-batch-writer.ts"() {
|
|
25141
|
+
"use strict";
|
|
25142
|
+
fs22 = __toESM2(require("fs"));
|
|
25143
|
+
AsyncBatchWriter = class {
|
|
25144
|
+
// Maps filePath -> string buffer
|
|
25145
|
+
static buffers = /* @__PURE__ */ new Map();
|
|
25146
|
+
static writePromises = /* @__PURE__ */ new Map();
|
|
25147
|
+
static flushTimer = null;
|
|
25148
|
+
/**
|
|
25149
|
+
* Queues data to be written to a file asynchronously in a batch.
|
|
25150
|
+
*/
|
|
25151
|
+
static write(filePath, data) {
|
|
25152
|
+
let buf = this.buffers.get(filePath);
|
|
25153
|
+
if (!buf) {
|
|
25154
|
+
buf = [];
|
|
25155
|
+
this.buffers.set(filePath, buf);
|
|
25156
|
+
}
|
|
25157
|
+
buf.push(data);
|
|
25158
|
+
if (!this.flushTimer) {
|
|
25159
|
+
this.flushTimer = setTimeout(() => {
|
|
25160
|
+
this.flushTimer = null;
|
|
25161
|
+
this.flushAll();
|
|
25162
|
+
}, 50);
|
|
25163
|
+
}
|
|
25164
|
+
}
|
|
25165
|
+
static async flushAll() {
|
|
25166
|
+
const entries = Array.from(this.buffers.entries());
|
|
25167
|
+
this.buffers.clear();
|
|
25168
|
+
for (const [filePath, buffer] of entries) {
|
|
25169
|
+
const dataToWrite = buffer.join("");
|
|
25170
|
+
const doWrite = async () => {
|
|
25171
|
+
try {
|
|
25172
|
+
const prevPromise = this.writePromises.get(filePath);
|
|
25173
|
+
if (prevPromise) await prevPromise;
|
|
25174
|
+
await fs22.promises.appendFile(filePath, dataToWrite, { encoding: "utf-8", mode: 384 });
|
|
25175
|
+
} catch {
|
|
25176
|
+
}
|
|
25177
|
+
};
|
|
25178
|
+
const writePromise = doWrite();
|
|
25179
|
+
this.writePromises.set(filePath, writePromise);
|
|
25180
|
+
writePromise.finally(() => {
|
|
25181
|
+
if (this.writePromises.get(filePath) === writePromise) {
|
|
25182
|
+
this.writePromises.delete(filePath);
|
|
25183
|
+
}
|
|
25184
|
+
});
|
|
25185
|
+
}
|
|
25186
|
+
}
|
|
25187
|
+
};
|
|
25188
|
+
}
|
|
25189
|
+
});
|
|
24244
25190
|
function setLogLevel(level) {
|
|
24245
25191
|
currentLevel = level;
|
|
24246
25192
|
daemonLog("Logger", `Log level set to: ${level}`, "info");
|
|
@@ -24267,7 +25213,7 @@ Follow these recovery rules:
|
|
|
24267
25213
|
}
|
|
24268
25214
|
function cleanOldLogs() {
|
|
24269
25215
|
try {
|
|
24270
|
-
const files =
|
|
25216
|
+
const files = fs32.readdirSync(LOG_DIR).filter((f) => f.startsWith("daemon-") && f.endsWith(".log"));
|
|
24271
25217
|
const cutoff = /* @__PURE__ */ new Date();
|
|
24272
25218
|
cutoff.setDate(cutoff.getDate() - MAX_LOG_DAYS);
|
|
24273
25219
|
const cutoffStr = cutoff.toISOString().slice(0, 10);
|
|
@@ -24275,7 +25221,7 @@ Follow these recovery rules:
|
|
|
24275
25221
|
const dateMatch = file2.match(/daemon-(\d{4}-\d{2}-\d{2})/);
|
|
24276
25222
|
if (dateMatch && dateMatch[1] < cutoffStr) {
|
|
24277
25223
|
try {
|
|
24278
|
-
|
|
25224
|
+
fs32.unlinkSync(path9.join(LOG_DIR, file2));
|
|
24279
25225
|
} catch {
|
|
24280
25226
|
}
|
|
24281
25227
|
}
|
|
@@ -24285,14 +25231,14 @@ Follow these recovery rules:
|
|
|
24285
25231
|
}
|
|
24286
25232
|
function rotateSizeIfNeeded() {
|
|
24287
25233
|
try {
|
|
24288
|
-
const stat2 =
|
|
25234
|
+
const stat2 = fs32.statSync(currentLogFile);
|
|
24289
25235
|
if (stat2.size > MAX_LOG_SIZE) {
|
|
24290
25236
|
const backup = currentLogFile.replace(".log", ".1.log");
|
|
24291
25237
|
try {
|
|
24292
|
-
|
|
25238
|
+
fs32.unlinkSync(backup);
|
|
24293
25239
|
} catch {
|
|
24294
25240
|
}
|
|
24295
|
-
|
|
25241
|
+
fs32.renameSync(currentLogFile, backup);
|
|
24296
25242
|
}
|
|
24297
25243
|
} catch {
|
|
24298
25244
|
}
|
|
@@ -24303,7 +25249,7 @@ Follow these recovery rules:
|
|
|
24303
25249
|
checkDateRotation();
|
|
24304
25250
|
rotateSizeIfNeeded();
|
|
24305
25251
|
}
|
|
24306
|
-
|
|
25252
|
+
AsyncBatchWriter.write(currentLogFile, line + "\n");
|
|
24307
25253
|
} catch {
|
|
24308
25254
|
}
|
|
24309
25255
|
}
|
|
@@ -24391,7 +25337,7 @@ Follow these recovery rules:
|
|
|
24391
25337
|
writeToFile(`Log file: ${currentLogFile}`);
|
|
24392
25338
|
writeToFile(`Log level: ${currentLevel}`);
|
|
24393
25339
|
}
|
|
24394
|
-
var
|
|
25340
|
+
var fs32;
|
|
24395
25341
|
var path9;
|
|
24396
25342
|
var os32;
|
|
24397
25343
|
var LEVEL_NUM;
|
|
@@ -24414,9 +25360,10 @@ Follow these recovery rules:
|
|
|
24414
25360
|
var init_logger = __esm2({
|
|
24415
25361
|
"src/logging/logger.ts"() {
|
|
24416
25362
|
"use strict";
|
|
24417
|
-
|
|
25363
|
+
fs32 = __toESM2(require("fs"));
|
|
24418
25364
|
path9 = __toESM2(require("path"));
|
|
24419
25365
|
os32 = __toESM2(require("os"));
|
|
25366
|
+
init_async_batch_writer();
|
|
24420
25367
|
LEVEL_NUM = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
24421
25368
|
LEVEL_LABEL = { debug: "DBG", info: "INF", warn: "WRN", error: "ERR" };
|
|
24422
25369
|
currentLevel = "info";
|
|
@@ -24424,7 +25371,7 @@ Follow these recovery rules:
|
|
|
24424
25371
|
MAX_LOG_SIZE = 5 * 1024 * 1024;
|
|
24425
25372
|
MAX_LOG_DAYS = 7;
|
|
24426
25373
|
try {
|
|
24427
|
-
|
|
25374
|
+
fs32.mkdirSync(LOG_DIR, { recursive: true });
|
|
24428
25375
|
} catch {
|
|
24429
25376
|
}
|
|
24430
25377
|
currentDate = getDateStr();
|
|
@@ -24432,14 +25379,14 @@ Follow these recovery rules:
|
|
|
24432
25379
|
cleanOldLogs();
|
|
24433
25380
|
try {
|
|
24434
25381
|
const oldLog = path9.join(LOG_DIR, "daemon.log");
|
|
24435
|
-
if (
|
|
24436
|
-
const stat2 =
|
|
25382
|
+
if (fs32.existsSync(oldLog)) {
|
|
25383
|
+
const stat2 = fs32.statSync(oldLog);
|
|
24437
25384
|
const oldDate = stat2.mtime.toISOString().slice(0, 10);
|
|
24438
|
-
|
|
25385
|
+
fs32.renameSync(oldLog, path9.join(LOG_DIR, `daemon-${oldDate}.log`));
|
|
24439
25386
|
}
|
|
24440
25387
|
const oldLogBackup = path9.join(LOG_DIR, "daemon.log.old");
|
|
24441
|
-
if (
|
|
24442
|
-
|
|
25388
|
+
if (fs32.existsSync(oldLogBackup)) {
|
|
25389
|
+
fs32.unlinkSync(oldLogBackup);
|
|
24443
25390
|
}
|
|
24444
25391
|
} catch {
|
|
24445
25392
|
}
|
|
@@ -25792,8 +26739,8 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
|
|
|
25792
26739
|
let cwd = options.cwd;
|
|
25793
26740
|
if (cwd) {
|
|
25794
26741
|
try {
|
|
25795
|
-
const
|
|
25796
|
-
const stat2 =
|
|
26742
|
+
const fs17 = require("fs");
|
|
26743
|
+
const stat2 = fs17.statSync(cwd);
|
|
25797
26744
|
if (!stat2.isDirectory()) cwd = os8.homedir();
|
|
25798
26745
|
} catch {
|
|
25799
26746
|
cwd = os8.homedir();
|
|
@@ -25891,27 +26838,35 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
|
|
|
25891
26838
|
return path14.isAbsolute(expanded) ? expanded : path14.resolve(expanded);
|
|
25892
26839
|
}
|
|
25893
26840
|
const isWin = os9.platform() === "win32";
|
|
25894
|
-
|
|
25895
|
-
|
|
25896
|
-
|
|
25897
|
-
|
|
25898
|
-
|
|
25899
|
-
|
|
25900
|
-
|
|
25901
|
-
|
|
25902
|
-
|
|
25903
|
-
|
|
26841
|
+
const paths = (process.env.PATH || "").split(path14.delimiter);
|
|
26842
|
+
const exes = isWin ? [".exe", ".cmd", ".bat", ""] : [""];
|
|
26843
|
+
for (const p of paths) {
|
|
26844
|
+
if (!p) continue;
|
|
26845
|
+
for (const ext of exes) {
|
|
26846
|
+
const fullPath = path14.join(p, trimmed + ext);
|
|
26847
|
+
try {
|
|
26848
|
+
const fs17 = require("fs");
|
|
26849
|
+
if (fs17.existsSync(fullPath)) {
|
|
26850
|
+
const stat2 = fs17.statSync(fullPath);
|
|
26851
|
+
if (stat2.isFile() && (isWin || stat2.mode & 73)) {
|
|
26852
|
+
return fullPath;
|
|
26853
|
+
}
|
|
26854
|
+
}
|
|
26855
|
+
} catch {
|
|
26856
|
+
}
|
|
26857
|
+
}
|
|
25904
26858
|
}
|
|
26859
|
+
return isWin ? `${trimmed}.cmd` : trimmed;
|
|
25905
26860
|
}
|
|
25906
26861
|
function isScriptBinary(binaryPath) {
|
|
25907
26862
|
if (!path14.isAbsolute(binaryPath)) return false;
|
|
25908
26863
|
try {
|
|
25909
|
-
const
|
|
25910
|
-
const resolved =
|
|
26864
|
+
const fs17 = require("fs");
|
|
26865
|
+
const resolved = fs17.realpathSync(binaryPath);
|
|
25911
26866
|
const head = Buffer.alloc(8);
|
|
25912
|
-
const fd =
|
|
25913
|
-
|
|
25914
|
-
|
|
26867
|
+
const fd = fs17.openSync(resolved, "r");
|
|
26868
|
+
fs17.readSync(fd, head, 0, 8, 0);
|
|
26869
|
+
fs17.closeSync(fd);
|
|
25915
26870
|
let i = 0;
|
|
25916
26871
|
if (head[0] === 239 && head[1] === 187 && head[2] === 191) i = 3;
|
|
25917
26872
|
return head[i] === 35 && head[i + 1] === 33;
|
|
@@ -25922,12 +26877,12 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
|
|
|
25922
26877
|
function looksLikeMachOOrElf(filePath) {
|
|
25923
26878
|
if (!path14.isAbsolute(filePath)) return false;
|
|
25924
26879
|
try {
|
|
25925
|
-
const
|
|
25926
|
-
const resolved =
|
|
26880
|
+
const fs17 = require("fs");
|
|
26881
|
+
const resolved = fs17.realpathSync(filePath);
|
|
25927
26882
|
const buf = Buffer.alloc(8);
|
|
25928
|
-
const fd =
|
|
25929
|
-
|
|
25930
|
-
|
|
26883
|
+
const fd = fs17.openSync(resolved, "r");
|
|
26884
|
+
fs17.readSync(fd, buf, 0, 8, 0);
|
|
26885
|
+
fs17.closeSync(fd);
|
|
25931
26886
|
let i = 0;
|
|
25932
26887
|
if (buf[0] === 239 && buf[1] === 187 && buf[2] === 191) i = 3;
|
|
25933
26888
|
const b = buf.subarray(i);
|
|
@@ -26011,7 +26966,6 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
|
|
|
26011
26966
|
}
|
|
26012
26967
|
var os9;
|
|
26013
26968
|
var path14;
|
|
26014
|
-
var import_child_process4;
|
|
26015
26969
|
var TerminalTranscriptAccumulator;
|
|
26016
26970
|
var buildCliSpawnEnv;
|
|
26017
26971
|
var init_provider_cli_shared = __esm2({
|
|
@@ -26019,7 +26973,6 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
|
|
|
26019
26973
|
"use strict";
|
|
26020
26974
|
os9 = __toESM2(require("os"));
|
|
26021
26975
|
path14 = __toESM2(require("path"));
|
|
26022
|
-
import_child_process4 = require("child_process");
|
|
26023
26976
|
init_spawn_env();
|
|
26024
26977
|
TerminalTranscriptAccumulator = class {
|
|
26025
26978
|
lines = [[]];
|
|
@@ -28616,6 +29569,7 @@ ${lastSnapshot}`;
|
|
|
28616
29569
|
getLogLevel: () => getLogLevel,
|
|
28617
29570
|
getMesh: () => getMesh,
|
|
28618
29571
|
getMeshByRepo: () => getMeshByRepo,
|
|
29572
|
+
getMeshQueueRevision: () => getMeshQueueRevision,
|
|
28619
29573
|
getMeshQueueStats: () => getMeshQueueStats,
|
|
28620
29574
|
getNpmExecOptions: () => getNpmExecOptions,
|
|
28621
29575
|
getPendingMeshCoordinatorEvents: () => getPendingMeshCoordinatorEvents,
|
|
@@ -31442,9 +32396,11 @@ ${lastSnapshot}`;
|
|
|
31442
32396
|
saveState({ ...DEFAULT_STATE });
|
|
31443
32397
|
}
|
|
31444
32398
|
var import_child_process2 = require("child_process");
|
|
32399
|
+
var import_util3 = require("util");
|
|
31445
32400
|
var import_fs9 = require("fs");
|
|
31446
32401
|
var import_os22 = require("os");
|
|
31447
32402
|
var path10 = __toESM2(require("path"));
|
|
32403
|
+
var execAsync2 = (0, import_util3.promisify)(import_child_process2.exec);
|
|
31448
32404
|
var BUILTIN_IDE_DEFINITIONS = [];
|
|
31449
32405
|
var registeredIDEs = /* @__PURE__ */ new Map();
|
|
31450
32406
|
function registerIDEDefinition(def) {
|
|
@@ -31468,24 +32424,33 @@ ${lastSnapshot}`;
|
|
|
31468
32424
|
const resolved = path10.isAbsolute(candidate) ? candidate : path10.resolve(candidate);
|
|
31469
32425
|
return (0, import_fs9.existsSync)(resolved) ? resolved : null;
|
|
31470
32426
|
}
|
|
31471
|
-
|
|
31472
|
-
|
|
31473
|
-
|
|
31474
|
-
|
|
31475
|
-
|
|
31476
|
-
|
|
31477
|
-
|
|
31478
|
-
|
|
32427
|
+
const isWin = (0, import_os22.platform)() === "win32";
|
|
32428
|
+
const paths = (process.env.PATH || "").split(isWin ? ";" : ":");
|
|
32429
|
+
const exes = isWin ? [".exe", ".cmd", ".bat", ""] : [""];
|
|
32430
|
+
for (const p of paths) {
|
|
32431
|
+
if (!p) continue;
|
|
32432
|
+
for (const ext of exes) {
|
|
32433
|
+
const fullPath = path10.join(p, trimmed + ext);
|
|
32434
|
+
try {
|
|
32435
|
+
if ((0, import_fs9.existsSync)(fullPath)) {
|
|
32436
|
+
const stat2 = (0, import_fs9.statSync)(fullPath);
|
|
32437
|
+
if (stat2.isFile() && (isWin || stat2.mode & 73)) {
|
|
32438
|
+
return fullPath;
|
|
32439
|
+
}
|
|
32440
|
+
}
|
|
32441
|
+
} catch {
|
|
32442
|
+
}
|
|
32443
|
+
}
|
|
31479
32444
|
}
|
|
32445
|
+
return null;
|
|
31480
32446
|
}
|
|
31481
|
-
function getIdeVersion(cliCommand) {
|
|
32447
|
+
async function getIdeVersion(cliCommand) {
|
|
31482
32448
|
try {
|
|
31483
|
-
const
|
|
32449
|
+
const { stdout } = await execAsync2(`"${cliCommand}" --version`, {
|
|
31484
32450
|
encoding: "utf-8",
|
|
31485
|
-
timeout: 1e4
|
|
31486
|
-
|
|
31487
|
-
|
|
31488
|
-
return result.split("\n")[0] || null;
|
|
32451
|
+
timeout: 1e4
|
|
32452
|
+
});
|
|
32453
|
+
return stdout.trim().split("\n")[0] || null;
|
|
31489
32454
|
} catch {
|
|
31490
32455
|
return null;
|
|
31491
32456
|
}
|
|
@@ -31533,7 +32498,7 @@ ${lastSnapshot}`;
|
|
|
31533
32498
|
}
|
|
31534
32499
|
}
|
|
31535
32500
|
const installed = os222 === "darwin" ? !!(resolvedCli || appPath) : !!resolvedCli;
|
|
31536
|
-
const version2 = resolvedCli ? getIdeVersion(resolvedCli) : null;
|
|
32501
|
+
const version2 = resolvedCli ? await getIdeVersion(resolvedCli) : null;
|
|
31537
32502
|
results.push({
|
|
31538
32503
|
id: def.id,
|
|
31539
32504
|
name: def.name,
|
|
@@ -31550,18 +32515,22 @@ ${lastSnapshot}`;
|
|
|
31550
32515
|
init_cli_detector();
|
|
31551
32516
|
var os42 = __toESM2(require("os"));
|
|
31552
32517
|
var import_child_process3 = require("child_process");
|
|
31553
|
-
|
|
31554
|
-
|
|
32518
|
+
var import_util22 = require("util");
|
|
32519
|
+
var execAsync3 = (0, import_util22.promisify)(import_child_process3.exec);
|
|
32520
|
+
var cachedDarwinAvail = null;
|
|
32521
|
+
var darwinMemoryInterval = null;
|
|
32522
|
+
async function updateDarwinMemoryCache() {
|
|
32523
|
+
if (os42.platform() !== "darwin") return;
|
|
31555
32524
|
try {
|
|
31556
|
-
const
|
|
32525
|
+
const { stdout } = await execAsync3("vm_stat", {
|
|
31557
32526
|
encoding: "utf-8",
|
|
31558
32527
|
timeout: 4e3,
|
|
31559
32528
|
maxBuffer: 256 * 1024
|
|
31560
32529
|
});
|
|
31561
|
-
const pageSizeMatch =
|
|
32530
|
+
const pageSizeMatch = stdout.match(/page size of (\d+)\s*bytes/i);
|
|
31562
32531
|
const pageSize = pageSizeMatch ? parseInt(pageSizeMatch[1], 10) : 4096;
|
|
31563
32532
|
const counts = {};
|
|
31564
|
-
for (const line of
|
|
32533
|
+
for (const line of stdout.split("\n")) {
|
|
31565
32534
|
const m = line.match(/^\s*Pages\s+([^:]+):\s+([\d,]+)\s*\.?/);
|
|
31566
32535
|
if (!m) continue;
|
|
31567
32536
|
const key = m[1].trim().toLowerCase().replace(/\s+/g, "_");
|
|
@@ -31575,18 +32544,24 @@ ${lastSnapshot}`;
|
|
|
31575
32544
|
const fileBacked = counts["file_backed"] ?? 0;
|
|
31576
32545
|
const availPages = free + inactive + speculative + purgeable + fileBacked;
|
|
31577
32546
|
const bytes = availPages * pageSize;
|
|
31578
|
-
|
|
31579
|
-
return Math.min(bytes, totalMem);
|
|
32547
|
+
cachedDarwinAvail = Number.isFinite(bytes) && bytes >= 0 ? Math.min(bytes, os42.totalmem()) : null;
|
|
31580
32548
|
} catch {
|
|
31581
|
-
return null;
|
|
31582
32549
|
}
|
|
31583
32550
|
}
|
|
31584
32551
|
function getHostMemorySnapshot() {
|
|
32552
|
+
if (os42.platform() === "darwin" && !darwinMemoryInterval) {
|
|
32553
|
+
updateDarwinMemoryCache();
|
|
32554
|
+
darwinMemoryInterval = setInterval(updateDarwinMemoryCache, 3e3);
|
|
32555
|
+
darwinMemoryInterval.unref();
|
|
32556
|
+
}
|
|
31585
32557
|
const totalMem = os42.totalmem();
|
|
31586
32558
|
const freeMem = os42.freemem();
|
|
31587
|
-
const
|
|
31588
|
-
|
|
31589
|
-
|
|
32559
|
+
const availableMem = os42.platform() === "darwin" ? cachedDarwinAvail ?? freeMem : freeMem;
|
|
32560
|
+
return {
|
|
32561
|
+
totalMem,
|
|
32562
|
+
freeMem,
|
|
32563
|
+
availableMem
|
|
32564
|
+
};
|
|
31590
32565
|
}
|
|
31591
32566
|
var LIVE_LIFECYCLES = /* @__PURE__ */ new Set(["starting", "running", "stopping", "interrupted"]);
|
|
31592
32567
|
function isSessionHostLiveRuntime(record2) {
|
|
@@ -33929,7 +34904,7 @@ ${lastSnapshot}`;
|
|
|
33929
34904
|
${cleanBody}`;
|
|
33930
34905
|
return cleanTitle || cleanBody;
|
|
33931
34906
|
}
|
|
33932
|
-
var
|
|
34907
|
+
var fs42 = __toESM2(require("fs"));
|
|
33933
34908
|
var path11 = __toESM2(require("path"));
|
|
33934
34909
|
var os52 = __toESM2(require("os"));
|
|
33935
34910
|
var HISTORY_DIR = path11.join(os52.homedir(), ".adhdev", "history");
|
|
@@ -34049,8 +35024,8 @@ ${cleanBody}`;
|
|
|
34049
35024
|
function readPersistedSavedHistorySessionSummaries(dir) {
|
|
34050
35025
|
try {
|
|
34051
35026
|
const filePath = getSavedHistoryIndexFilePath(dir);
|
|
34052
|
-
if (!
|
|
34053
|
-
const raw = JSON.parse(
|
|
35027
|
+
if (!fs42.existsSync(filePath)) return null;
|
|
35028
|
+
const raw = JSON.parse(fs42.readFileSync(filePath, "utf-8"));
|
|
34054
35029
|
if (!raw || raw.version !== SAVED_HISTORY_INDEX_VERSION || !raw.sessions || typeof raw.sessions !== "object") {
|
|
34055
35030
|
return null;
|
|
34056
35031
|
}
|
|
@@ -34077,7 +35052,7 @@ ${cleanBody}`;
|
|
|
34077
35052
|
}
|
|
34078
35053
|
function listHistoryFiles(dir, historySessionId) {
|
|
34079
35054
|
const sanitizedSessionId = historySessionId ? sanitizeHistoryFileSegment(historySessionId) : "";
|
|
34080
|
-
return
|
|
35055
|
+
return fs42.readdirSync(dir).filter((file2) => {
|
|
34081
35056
|
if (!file2.endsWith(".jsonl")) return false;
|
|
34082
35057
|
if (sanitizedSessionId) {
|
|
34083
35058
|
return file2.startsWith(`${sanitizedSessionId}_`);
|
|
@@ -34095,7 +35070,7 @@ ${cleanBody}`;
|
|
|
34095
35070
|
function buildSavedHistoryFileSignatureMap(dir, files) {
|
|
34096
35071
|
return new Map(files.map((file2) => {
|
|
34097
35072
|
try {
|
|
34098
|
-
const stat2 =
|
|
35073
|
+
const stat2 = fs42.statSync(path11.join(dir, file2));
|
|
34099
35074
|
return [file2, `${file2}:${stat2.size}:${Math.trunc(stat2.mtimeMs)}`];
|
|
34100
35075
|
} catch {
|
|
34101
35076
|
return [file2, `${file2}:missing`];
|
|
@@ -34118,8 +35093,8 @@ ${cleanBody}`;
|
|
|
34118
35093
|
function loadPersistedSavedHistoryIndexFromFile(dir) {
|
|
34119
35094
|
try {
|
|
34120
35095
|
const filePath = getSavedHistoryIndexFilePath(dir);
|
|
34121
|
-
if (!
|
|
34122
|
-
const raw = JSON.parse(
|
|
35096
|
+
if (!fs42.existsSync(filePath)) return /* @__PURE__ */ new Map();
|
|
35097
|
+
const raw = JSON.parse(fs42.readFileSync(filePath, "utf-8"));
|
|
34123
35098
|
if (!raw || raw.version !== SAVED_HISTORY_INDEX_VERSION || !raw.files || typeof raw.files !== "object") {
|
|
34124
35099
|
return /* @__PURE__ */ new Map();
|
|
34125
35100
|
}
|
|
@@ -34141,27 +35116,27 @@ ${cleanBody}`;
|
|
|
34141
35116
|
files: Object.fromEntries(entries.entries()),
|
|
34142
35117
|
sessions: buildSavedHistorySessionSummaryMapFromEntries(entries)
|
|
34143
35118
|
};
|
|
34144
|
-
|
|
34145
|
-
|
|
35119
|
+
fs42.writeFileSync(tempPath, JSON.stringify(payload), "utf-8");
|
|
35120
|
+
fs42.renameSync(tempPath, filePath);
|
|
34146
35121
|
}
|
|
34147
35122
|
function acquireSavedHistoryIndexLock(dir) {
|
|
34148
35123
|
const lockPath = getSavedHistoryIndexLockPath(dir);
|
|
34149
35124
|
const deadline = Date.now() + SAVED_HISTORY_INDEX_LOCK_WAIT_MS;
|
|
34150
35125
|
while (Date.now() <= deadline) {
|
|
34151
35126
|
try {
|
|
34152
|
-
|
|
35127
|
+
fs42.mkdirSync(lockPath);
|
|
34153
35128
|
return () => {
|
|
34154
35129
|
try {
|
|
34155
|
-
|
|
35130
|
+
fs42.rmSync(lockPath, { recursive: true, force: true });
|
|
34156
35131
|
} catch {
|
|
34157
35132
|
}
|
|
34158
35133
|
};
|
|
34159
35134
|
} catch (error48) {
|
|
34160
35135
|
if (error48?.code !== "EEXIST") return null;
|
|
34161
35136
|
try {
|
|
34162
|
-
const stat2 =
|
|
35137
|
+
const stat2 = fs42.statSync(lockPath);
|
|
34163
35138
|
if (Date.now() - stat2.mtimeMs > SAVED_HISTORY_INDEX_LOCK_STALE_MS) {
|
|
34164
|
-
|
|
35139
|
+
fs42.rmSync(lockPath, { recursive: true, force: true });
|
|
34165
35140
|
continue;
|
|
34166
35141
|
}
|
|
34167
35142
|
} catch {
|
|
@@ -34208,7 +35183,7 @@ ${cleanBody}`;
|
|
|
34208
35183
|
}
|
|
34209
35184
|
for (const file2 of Array.from(currentEntries.keys())) {
|
|
34210
35185
|
if (incomingFiles.has(file2)) continue;
|
|
34211
|
-
if (!
|
|
35186
|
+
if (!fs42.existsSync(path11.join(dir, file2))) {
|
|
34212
35187
|
currentEntries.delete(file2);
|
|
34213
35188
|
}
|
|
34214
35189
|
}
|
|
@@ -34216,14 +35191,14 @@ ${cleanBody}`;
|
|
|
34216
35191
|
}
|
|
34217
35192
|
function invalidatePersistedSavedHistoryIndex(agentType, dir) {
|
|
34218
35193
|
try {
|
|
34219
|
-
|
|
35194
|
+
fs42.rmSync(getSavedHistoryIndexFilePath(dir), { force: true });
|
|
34220
35195
|
} catch {
|
|
34221
35196
|
}
|
|
34222
35197
|
savedHistorySessionCache.delete(agentType.replace(/[^a-zA-Z0-9_-]/g, "_"));
|
|
34223
35198
|
}
|
|
34224
35199
|
function buildSavedHistoryIndexFileSignature(dir) {
|
|
34225
35200
|
try {
|
|
34226
|
-
const stat2 =
|
|
35201
|
+
const stat2 = fs42.statSync(getSavedHistoryIndexFilePath(dir));
|
|
34227
35202
|
return `index:${stat2.size}:${Math.trunc(stat2.mtimeMs)}`;
|
|
34228
35203
|
} catch {
|
|
34229
35204
|
return "index:missing";
|
|
@@ -34231,10 +35206,10 @@ ${cleanBody}`;
|
|
|
34231
35206
|
}
|
|
34232
35207
|
function historyDirectoryHasFilesNewerThanIndex(dir) {
|
|
34233
35208
|
try {
|
|
34234
|
-
const indexStat =
|
|
35209
|
+
const indexStat = fs42.statSync(getSavedHistoryIndexFilePath(dir));
|
|
34235
35210
|
const files = listHistoryFiles(dir);
|
|
34236
35211
|
for (const file2 of files) {
|
|
34237
|
-
const stat2 =
|
|
35212
|
+
const stat2 = fs42.statSync(path11.join(dir, file2));
|
|
34238
35213
|
if (stat2.mtimeMs > indexStat.mtimeMs) return true;
|
|
34239
35214
|
}
|
|
34240
35215
|
return false;
|
|
@@ -34244,7 +35219,7 @@ ${cleanBody}`;
|
|
|
34244
35219
|
}
|
|
34245
35220
|
function buildSavedHistoryFileSignature(dir, file2) {
|
|
34246
35221
|
try {
|
|
34247
|
-
const stat2 =
|
|
35222
|
+
const stat2 = fs42.statSync(path11.join(dir, file2));
|
|
34248
35223
|
return `${file2}:${stat2.size}:${Math.trunc(stat2.mtimeMs)}`;
|
|
34249
35224
|
} catch {
|
|
34250
35225
|
return `${file2}:missing`;
|
|
@@ -34325,7 +35300,7 @@ ${cleanBody}`;
|
|
|
34325
35300
|
const historySessionId = extractSavedHistorySessionIdFromFile(file2);
|
|
34326
35301
|
if (!historySessionId) return null;
|
|
34327
35302
|
const filePath = path11.join(dir, file2);
|
|
34328
|
-
const content =
|
|
35303
|
+
const content = fs42.readFileSync(filePath, "utf-8");
|
|
34329
35304
|
const lines = content.split("\n").filter(Boolean);
|
|
34330
35305
|
let messageCount = 0;
|
|
34331
35306
|
let firstMessageAt = 0;
|
|
@@ -34386,7 +35361,7 @@ ${cleanBody}`;
|
|
|
34386
35361
|
savedHistoryBackgroundRefresh.add(key);
|
|
34387
35362
|
setTimeout(() => {
|
|
34388
35363
|
try {
|
|
34389
|
-
if (!
|
|
35364
|
+
if (!fs42.existsSync(dir)) return;
|
|
34390
35365
|
const files = listHistoryFiles(dir);
|
|
34391
35366
|
const fileSignatures = buildSavedHistoryFileSignatureMap(dir, files);
|
|
34392
35367
|
const persistedEntries = loadPersistedSavedHistoryIndex(dir);
|
|
@@ -34532,13 +35507,13 @@ ${cleanBody}`;
|
|
|
34532
35507
|
}
|
|
34533
35508
|
if (newMessages.length === 0) return;
|
|
34534
35509
|
const dir = path11.join(HISTORY_DIR, this.sanitize(agentType));
|
|
34535
|
-
|
|
35510
|
+
fs42.mkdirSync(dir, { recursive: true });
|
|
34536
35511
|
const date5 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
34537
35512
|
const filePrefix = effectiveHistoryKey ? `${this.sanitize(effectiveHistoryKey)}_` : "";
|
|
34538
35513
|
const fileName = `${filePrefix}${date5}.jsonl`;
|
|
34539
35514
|
const filePath = path11.join(dir, fileName);
|
|
34540
35515
|
const lines = newMessages.map((m) => JSON.stringify(m)).join("\n") + "\n";
|
|
34541
|
-
|
|
35516
|
+
fs42.appendFileSync(filePath, lines, "utf-8");
|
|
34542
35517
|
updateSavedHistoryIndexForAppendedMessages(agentType, dir, fileName, effectiveHistoryKey, newMessages);
|
|
34543
35518
|
const prevCount = this.lastSeenCounts.get(dedupKey) || 0;
|
|
34544
35519
|
if (!historySessionId && messages.length < prevCount * 0.5 && prevCount > 3) {
|
|
@@ -34628,7 +35603,7 @@ ${cleanBody}`;
|
|
|
34628
35603
|
if (!id || !ws) return;
|
|
34629
35604
|
try {
|
|
34630
35605
|
const dir = path11.join(HISTORY_DIR, this.sanitize(agentType));
|
|
34631
|
-
|
|
35606
|
+
fs42.mkdirSync(dir, { recursive: true });
|
|
34632
35607
|
const date5 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
34633
35608
|
const fileName = `${this.sanitize(id)}_${date5}.jsonl`;
|
|
34634
35609
|
const filePath = path11.join(dir, fileName);
|
|
@@ -34643,7 +35618,7 @@ ${cleanBody}`;
|
|
|
34643
35618
|
historySessionId: id,
|
|
34644
35619
|
workspace: ws
|
|
34645
35620
|
};
|
|
34646
|
-
|
|
35621
|
+
fs42.appendFileSync(filePath, JSON.stringify(record2) + "\n", "utf-8");
|
|
34647
35622
|
updateSavedHistoryIndexForSessionStart(agentType, dir, fileName, id, ws);
|
|
34648
35623
|
} catch {
|
|
34649
35624
|
}
|
|
@@ -34678,14 +35653,14 @@ ${cleanBody}`;
|
|
|
34678
35653
|
this.lastSeenCounts.delete(fromDedupKey);
|
|
34679
35654
|
}
|
|
34680
35655
|
const dir = path11.join(HISTORY_DIR, this.sanitize(agentType));
|
|
34681
|
-
if (!
|
|
35656
|
+
if (!fs42.existsSync(dir)) return;
|
|
34682
35657
|
const fromPrefix = `${this.sanitize(fromId)}_`;
|
|
34683
35658
|
const toPrefix = `${this.sanitize(toId)}_`;
|
|
34684
|
-
const files =
|
|
35659
|
+
const files = fs42.readdirSync(dir).filter((file2) => file2.startsWith(fromPrefix) && file2.endsWith(".jsonl"));
|
|
34685
35660
|
for (const file2 of files) {
|
|
34686
35661
|
const sourcePath = path11.join(dir, file2);
|
|
34687
35662
|
const targetPath = path11.join(dir, `${toPrefix}${file2.slice(fromPrefix.length)}`);
|
|
34688
|
-
const sourceLines =
|
|
35663
|
+
const sourceLines = fs42.readFileSync(sourcePath, "utf-8").split("\n").filter(Boolean);
|
|
34689
35664
|
const rewritten = sourceLines.map((line) => {
|
|
34690
35665
|
try {
|
|
34691
35666
|
const parsed = JSON.parse(line);
|
|
@@ -34699,16 +35674,16 @@ ${cleanBody}`;
|
|
|
34699
35674
|
}
|
|
34700
35675
|
}).filter((line) => !!line);
|
|
34701
35676
|
if (rewritten.length === 0) {
|
|
34702
|
-
|
|
35677
|
+
fs42.unlinkSync(sourcePath);
|
|
34703
35678
|
continue;
|
|
34704
35679
|
}
|
|
34705
|
-
const existing =
|
|
35680
|
+
const existing = fs42.existsSync(targetPath) ? new Set(fs42.readFileSync(targetPath, "utf-8").split("\n").filter(Boolean)) : /* @__PURE__ */ new Set();
|
|
34706
35681
|
const nextLines = rewritten.filter((line) => !existing.has(line));
|
|
34707
35682
|
if (nextLines.length > 0) {
|
|
34708
|
-
|
|
35683
|
+
fs42.appendFileSync(targetPath, `${nextLines.join("\n")}
|
|
34709
35684
|
`, "utf-8");
|
|
34710
35685
|
}
|
|
34711
|
-
|
|
35686
|
+
fs42.unlinkSync(sourcePath);
|
|
34712
35687
|
}
|
|
34713
35688
|
invalidatePersistedSavedHistoryIndex(agentType, dir);
|
|
34714
35689
|
} catch {
|
|
@@ -34719,13 +35694,13 @@ ${cleanBody}`;
|
|
|
34719
35694
|
if (!sessionId) return;
|
|
34720
35695
|
try {
|
|
34721
35696
|
const dir = path11.join(HISTORY_DIR, this.sanitize(agentType));
|
|
34722
|
-
if (!
|
|
35697
|
+
if (!fs42.existsSync(dir)) return;
|
|
34723
35698
|
const prefix = `${this.sanitize(sessionId)}_`;
|
|
34724
|
-
const files =
|
|
35699
|
+
const files = fs42.readdirSync(dir).filter((file2) => file2.startsWith(prefix) && file2.endsWith(".jsonl")).sort();
|
|
34725
35700
|
const seen = /* @__PURE__ */ new Set();
|
|
34726
35701
|
for (const file2 of files) {
|
|
34727
35702
|
const filePath = path11.join(dir, file2);
|
|
34728
|
-
const lines =
|
|
35703
|
+
const lines = fs42.readFileSync(filePath, "utf-8").split("\n").filter(Boolean);
|
|
34729
35704
|
const next = [];
|
|
34730
35705
|
for (const line of lines) {
|
|
34731
35706
|
let parsed = null;
|
|
@@ -34754,10 +35729,10 @@ ${cleanBody}`;
|
|
|
34754
35729
|
}
|
|
34755
35730
|
const collapsed = collapseReplayAssistantTurns(dedupedAdjacent, historyBehavior);
|
|
34756
35731
|
if (collapsed.length === 0) {
|
|
34757
|
-
|
|
35732
|
+
fs42.unlinkSync(filePath);
|
|
34758
35733
|
continue;
|
|
34759
35734
|
}
|
|
34760
|
-
|
|
35735
|
+
fs42.writeFileSync(filePath, `${collapsed.map((entry) => JSON.stringify(entry)).join("\n")}
|
|
34761
35736
|
`, "utf-8");
|
|
34762
35737
|
}
|
|
34763
35738
|
invalidatePersistedSavedHistoryIndex(agentType, dir);
|
|
@@ -34774,18 +35749,18 @@ ${cleanBody}`;
|
|
|
34774
35749
|
/** Delete history files older than 30 days */
|
|
34775
35750
|
async rotateOldFiles() {
|
|
34776
35751
|
try {
|
|
34777
|
-
if (!
|
|
35752
|
+
if (!fs42.existsSync(HISTORY_DIR)) return;
|
|
34778
35753
|
const cutoff = Date.now() - RETAIN_DAYS * 24 * 60 * 60 * 1e3;
|
|
34779
|
-
const agentDirs =
|
|
35754
|
+
const agentDirs = fs42.readdirSync(HISTORY_DIR, { withFileTypes: true }).filter((d) => d.isDirectory());
|
|
34780
35755
|
for (const dir of agentDirs) {
|
|
34781
35756
|
const dirPath = path11.join(HISTORY_DIR, dir.name);
|
|
34782
|
-
const files =
|
|
35757
|
+
const files = fs42.readdirSync(dirPath).filter((f) => f.endsWith(".jsonl") || f.endsWith(".terminal.log"));
|
|
34783
35758
|
let removedAny = false;
|
|
34784
35759
|
for (const file2 of files) {
|
|
34785
35760
|
const filePath = path11.join(dirPath, file2);
|
|
34786
|
-
const stat2 =
|
|
35761
|
+
const stat2 = fs42.statSync(filePath);
|
|
34787
35762
|
if (stat2.mtimeMs < cutoff) {
|
|
34788
|
-
|
|
35763
|
+
fs42.unlinkSync(filePath);
|
|
34789
35764
|
removedAny = true;
|
|
34790
35765
|
}
|
|
34791
35766
|
}
|
|
@@ -34833,13 +35808,13 @@ ${cleanBody}`;
|
|
|
34833
35808
|
try {
|
|
34834
35809
|
const sanitized = agentType.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
34835
35810
|
const dir = path11.join(HISTORY_DIR, sanitized);
|
|
34836
|
-
if (!
|
|
35811
|
+
if (!fs42.existsSync(dir)) return { messages: [], hasMore: false };
|
|
34837
35812
|
const files = listHistoryFiles(dir, historySessionId);
|
|
34838
35813
|
const allMessages = [];
|
|
34839
35814
|
const seen = /* @__PURE__ */ new Set();
|
|
34840
35815
|
for (const file2 of files) {
|
|
34841
35816
|
const filePath = path11.join(dir, file2);
|
|
34842
|
-
const content =
|
|
35817
|
+
const content = fs42.readFileSync(filePath, "utf-8");
|
|
34843
35818
|
const lines = content.trim().split("\n").filter(Boolean);
|
|
34844
35819
|
for (let i = 0; i < lines.length; i++) {
|
|
34845
35820
|
try {
|
|
@@ -34863,7 +35838,7 @@ ${cleanBody}`;
|
|
|
34863
35838
|
try {
|
|
34864
35839
|
const sanitized = agentType.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
34865
35840
|
const dir = path11.join(HISTORY_DIR, sanitized);
|
|
34866
|
-
if (!
|
|
35841
|
+
if (!fs42.existsSync(dir)) {
|
|
34867
35842
|
savedHistorySessionCache.delete(sanitized);
|
|
34868
35843
|
return { sessions: [], hasMore: false };
|
|
34869
35844
|
}
|
|
@@ -34924,10 +35899,10 @@ ${cleanBody}`;
|
|
|
34924
35899
|
function readExistingSessionStartRecord(agentType, historySessionId) {
|
|
34925
35900
|
try {
|
|
34926
35901
|
const dir = path11.join(HISTORY_DIR, agentType);
|
|
34927
|
-
if (!
|
|
35902
|
+
if (!fs42.existsSync(dir)) return null;
|
|
34928
35903
|
const files = listHistoryFiles(dir, historySessionId).sort();
|
|
34929
35904
|
for (const file2 of files) {
|
|
34930
|
-
const lines =
|
|
35905
|
+
const lines = fs42.readFileSync(path11.join(dir, file2), "utf-8").split("\n").filter(Boolean);
|
|
34931
35906
|
for (const line of lines) {
|
|
34932
35907
|
try {
|
|
34933
35908
|
const parsed = JSON.parse(line);
|
|
@@ -34948,16 +35923,16 @@ ${cleanBody}`;
|
|
|
34948
35923
|
if (records.length === 0) return false;
|
|
34949
35924
|
try {
|
|
34950
35925
|
const dir = path11.join(HISTORY_DIR, agentType);
|
|
34951
|
-
|
|
35926
|
+
fs42.mkdirSync(dir, { recursive: true });
|
|
34952
35927
|
const prefix = `${historySessionId.replace(/[^a-zA-Z0-9_-]/g, "_")}_`;
|
|
34953
|
-
for (const file2 of
|
|
35928
|
+
for (const file2 of fs42.readdirSync(dir)) {
|
|
34954
35929
|
if (file2.startsWith(prefix) && file2.endsWith(".jsonl")) {
|
|
34955
|
-
|
|
35930
|
+
fs42.unlinkSync(path11.join(dir, file2));
|
|
34956
35931
|
}
|
|
34957
35932
|
}
|
|
34958
35933
|
const targetDate = new Date(records[records.length - 1].receivedAt || Date.now()).toISOString().slice(0, 10);
|
|
34959
35934
|
const filePath = path11.join(dir, `${prefix}${targetDate}.jsonl`);
|
|
34960
|
-
|
|
35935
|
+
fs42.writeFileSync(filePath, `${records.map((record2) => JSON.stringify(record2)).join("\n")}
|
|
34961
35936
|
`, "utf-8");
|
|
34962
35937
|
invalidatePersistedSavedHistoryIndex(agentType, dir);
|
|
34963
35938
|
savedHistorySessionCache.delete(agentType.replace(/[^a-zA-Z0-9_-]/g, "_"));
|
|
@@ -35065,7 +36040,7 @@ ${cleanBody}`;
|
|
|
35065
36040
|
if (visible.length === 0) return null;
|
|
35066
36041
|
let sourceMtimeMs = 0;
|
|
35067
36042
|
try {
|
|
35068
|
-
sourceMtimeMs =
|
|
36043
|
+
sourceMtimeMs = fs42.statSync(sourcePath).mtimeMs;
|
|
35069
36044
|
} catch {
|
|
35070
36045
|
}
|
|
35071
36046
|
const firstMessageAt = visible[0]?.receivedAt || sourceMtimeMs || Date.now();
|
|
@@ -35824,6 +36799,19 @@ ${effect.notification.body || ""}`.trim();
|
|
|
35824
36799
|
if (cleanMessage) lines.push(cleanMessage);
|
|
35825
36800
|
return lines.join("\n");
|
|
35826
36801
|
}
|
|
36802
|
+
async function withTimeout(promise2, timeoutMs, label) {
|
|
36803
|
+
let timer = null;
|
|
36804
|
+
try {
|
|
36805
|
+
return await Promise.race([
|
|
36806
|
+
promise2,
|
|
36807
|
+
new Promise((_, reject) => {
|
|
36808
|
+
timer = setTimeout(() => reject(new Error(`${label} timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
36809
|
+
})
|
|
36810
|
+
]);
|
|
36811
|
+
} finally {
|
|
36812
|
+
if (timer) clearTimeout(timer);
|
|
36813
|
+
}
|
|
36814
|
+
}
|
|
35827
36815
|
var IdeProviderInstance = class {
|
|
35828
36816
|
type;
|
|
35829
36817
|
category = "ide";
|
|
@@ -36048,7 +37036,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
36048
37036
|
if (webviewScript) {
|
|
36049
37037
|
const matchText = this.provider.webviewMatchText;
|
|
36050
37038
|
const matchFn = matchText ? (body) => body.includes(matchText) : void 0;
|
|
36051
|
-
const webviewRaw = await cdp.evaluateInWebviewFrame(webviewScript, matchFn);
|
|
37039
|
+
const webviewRaw = await withTimeout(cdp.evaluateInWebviewFrame(webviewScript, matchFn), 3e4, "evaluateInWebviewFrame");
|
|
36052
37040
|
if (webviewRaw) {
|
|
36053
37041
|
raw = typeof webviewRaw === "string" ? (() => {
|
|
36054
37042
|
try {
|
|
@@ -36063,7 +37051,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
36063
37051
|
if (!raw) {
|
|
36064
37052
|
const readChatScript = this.getReadChatScript();
|
|
36065
37053
|
if (!readChatScript) return;
|
|
36066
|
-
raw = await cdp.evaluate(readChatScript, 3e4);
|
|
37054
|
+
raw = await withTimeout(cdp.evaluate(readChatScript, 3e4), 3e4, "evaluate.readChatScript");
|
|
36067
37055
|
if (typeof raw === "string") {
|
|
36068
37056
|
try {
|
|
36069
37057
|
raw = JSON.parse(raw);
|
|
@@ -36374,7 +37362,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
36374
37362
|
now
|
|
36375
37363
|
);
|
|
36376
37364
|
LOG2.info("IdeInstance", `[IdeInstance:${this.type}] autoApprove: executing resolveAction for "${targetButton}"`);
|
|
36377
|
-
let rawResult = await cdp.evaluate(script, 1e4);
|
|
37365
|
+
let rawResult = await withTimeout(cdp.evaluate(script, 1e4), 1e4, "evaluate.autoApprove");
|
|
36378
37366
|
if (typeof rawResult === "string") {
|
|
36379
37367
|
try {
|
|
36380
37368
|
rawResult = JSON.parse(rawResult);
|
|
@@ -37417,7 +38405,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
37417
38405
|
}
|
|
37418
38406
|
return fn() || null;
|
|
37419
38407
|
}
|
|
37420
|
-
var
|
|
38408
|
+
var fs5 = __toESM2(require("fs"));
|
|
37421
38409
|
var os62 = __toESM2(require("os"));
|
|
37422
38410
|
var path12 = __toESM2(require("path"));
|
|
37423
38411
|
var import_node_crypto = require("crypto");
|
|
@@ -37984,11 +38972,11 @@ ${effect.notification.body || ""}`.trim();
|
|
|
37984
38972
|
function storeChatDebugBundleOnDaemon(bundle, targetSessionId) {
|
|
37985
38973
|
const bundleId = createChatDebugBundleId(targetSessionId);
|
|
37986
38974
|
const dir = getChatDebugBundleDir();
|
|
37987
|
-
|
|
38975
|
+
fs5.mkdirSync(dir, { recursive: true });
|
|
37988
38976
|
const savedPath = path12.join(dir, `${bundleId}.json`);
|
|
37989
38977
|
const json2 = `${JSON.stringify(bundle, null, 2)}
|
|
37990
38978
|
`;
|
|
37991
|
-
|
|
38979
|
+
fs5.writeFileSync(savedPath, json2, { encoding: "utf8", mode: 384 });
|
|
37992
38980
|
return { bundleId, savedPath, sizeBytes: Buffer.byteLength(json2, "utf8") };
|
|
37993
38981
|
}
|
|
37994
38982
|
function isDaemonFileDebugDelivery(args) {
|
|
@@ -39149,7 +40137,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
39149
40137
|
}
|
|
39150
40138
|
return { success: false, error: "resolveAction script not available for this provider" };
|
|
39151
40139
|
}
|
|
39152
|
-
var
|
|
40140
|
+
var fs6 = __toESM2(require("fs"));
|
|
39153
40141
|
var path13 = __toESM2(require("path"));
|
|
39154
40142
|
var os7 = __toESM2(require("os"));
|
|
39155
40143
|
var KEY_TO_VK = {
|
|
@@ -39422,7 +40410,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
39422
40410
|
return path13.resolve(inputPath);
|
|
39423
40411
|
}
|
|
39424
40412
|
function listDirectoryEntriesSafe(dirPath) {
|
|
39425
|
-
const entries =
|
|
40413
|
+
const entries = fs6.readdirSync(dirPath, { withFileTypes: true });
|
|
39426
40414
|
const files = [];
|
|
39427
40415
|
for (const entry of entries) {
|
|
39428
40416
|
const entryPath = path13.join(dirPath, entry.name);
|
|
@@ -39434,14 +40422,14 @@ ${effect.notification.body || ""}`.trim();
|
|
|
39434
40422
|
if (entry.isFile()) {
|
|
39435
40423
|
let size;
|
|
39436
40424
|
try {
|
|
39437
|
-
size =
|
|
40425
|
+
size = fs6.statSync(entryPath).size;
|
|
39438
40426
|
} catch {
|
|
39439
40427
|
size = void 0;
|
|
39440
40428
|
}
|
|
39441
40429
|
files.push({ name: entry.name, type: "file", size });
|
|
39442
40430
|
continue;
|
|
39443
40431
|
}
|
|
39444
|
-
const stat2 =
|
|
40432
|
+
const stat2 = fs6.statSync(entryPath);
|
|
39445
40433
|
files.push({
|
|
39446
40434
|
name: entry.name,
|
|
39447
40435
|
type: stat2.isDirectory() ? "directory" : "file",
|
|
@@ -39459,7 +40447,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
39459
40447
|
const letter = String.fromCharCode(code);
|
|
39460
40448
|
const root = `${letter}:\\`;
|
|
39461
40449
|
try {
|
|
39462
|
-
if (!
|
|
40450
|
+
if (!fs6.existsSync(root)) continue;
|
|
39463
40451
|
if (excluded && root.toLowerCase() === excluded) continue;
|
|
39464
40452
|
drives.push({ name: `${letter}:`, type: "directory", path: root });
|
|
39465
40453
|
} catch {
|
|
@@ -39470,7 +40458,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
39470
40458
|
async function handleFileRead(h, args) {
|
|
39471
40459
|
try {
|
|
39472
40460
|
const filePath = resolveSafePath(args?.path);
|
|
39473
|
-
const content =
|
|
40461
|
+
const content = fs6.readFileSync(filePath, "utf-8");
|
|
39474
40462
|
return { success: true, content, path: filePath };
|
|
39475
40463
|
} catch (e) {
|
|
39476
40464
|
return { success: false, error: e.message };
|
|
@@ -39479,8 +40467,8 @@ ${effect.notification.body || ""}`.trim();
|
|
|
39479
40467
|
async function handleFileWrite(h, args) {
|
|
39480
40468
|
try {
|
|
39481
40469
|
const filePath = resolveSafePath(args?.path);
|
|
39482
|
-
|
|
39483
|
-
|
|
40470
|
+
fs6.mkdirSync(path13.dirname(filePath), { recursive: true });
|
|
40471
|
+
fs6.writeFileSync(filePath, args?.content || "", "utf-8");
|
|
39484
40472
|
return { success: true, path: filePath };
|
|
39485
40473
|
} catch (e) {
|
|
39486
40474
|
return { success: false, error: e.message };
|
|
@@ -40592,7 +41580,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
40592
41580
|
var path18 = __toESM2(require("path"));
|
|
40593
41581
|
var crypto4 = __toESM2(require("crypto"));
|
|
40594
41582
|
var import_fs10 = require("fs");
|
|
40595
|
-
var
|
|
41583
|
+
var import_child_process5 = require("child_process");
|
|
40596
41584
|
var import_chalk = __toESM2((init_source(), __toCommonJS(source_exports)));
|
|
40597
41585
|
init_provider_cli_adapter();
|
|
40598
41586
|
init_cli_detector();
|
|
@@ -40600,7 +41588,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
40600
41588
|
var os12 = __toESM2(require("os"));
|
|
40601
41589
|
var path16 = __toESM2(require("path"));
|
|
40602
41590
|
var crypto3 = __toESM2(require("crypto"));
|
|
40603
|
-
var
|
|
41591
|
+
var fs7 = __toESM2(require("fs"));
|
|
40604
41592
|
var import_node_module = require("module");
|
|
40605
41593
|
init_provider_cli_adapter();
|
|
40606
41594
|
init_logger();
|
|
@@ -40655,9 +41643,9 @@ ${effect.notification.body || ""}`.trim();
|
|
|
40655
41643
|
if (!part.data) return null;
|
|
40656
41644
|
const rawData = part.data.includes(",") ? part.data.split(",").pop() || "" : part.data;
|
|
40657
41645
|
if (!rawData) return null;
|
|
40658
|
-
|
|
41646
|
+
fs7.mkdirSync(dir, { recursive: true });
|
|
40659
41647
|
const filePath = path16.join(dir, safeInputImageBasename(index, part.mimeType));
|
|
40660
|
-
|
|
41648
|
+
fs7.writeFileSync(filePath, Buffer.from(rawData, "base64"));
|
|
40661
41649
|
cleanupStaleMaterializedImages(dir);
|
|
40662
41650
|
return filePath;
|
|
40663
41651
|
}
|
|
@@ -40669,14 +41657,14 @@ ${effect.notification.body || ""}`.trim();
|
|
|
40669
41657
|
if (now - lastMaterializedImageCleanupAt < MATERIALIZED_IMAGE_CLEANUP_INTERVAL_MS) return;
|
|
40670
41658
|
lastMaterializedImageCleanupAt = now;
|
|
40671
41659
|
try {
|
|
40672
|
-
const entries =
|
|
41660
|
+
const entries = fs7.readdirSync(dir);
|
|
40673
41661
|
for (const entry of entries) {
|
|
40674
41662
|
if (!entry.startsWith("adhdev-input-image-")) continue;
|
|
40675
41663
|
const fullPath = path16.join(dir, entry);
|
|
40676
41664
|
try {
|
|
40677
|
-
const stat2 =
|
|
41665
|
+
const stat2 = fs7.statSync(fullPath);
|
|
40678
41666
|
if (now - stat2.mtimeMs > MATERIALIZED_IMAGE_MAX_AGE_MS) {
|
|
40679
|
-
|
|
41667
|
+
fs7.unlinkSync(fullPath);
|
|
40680
41668
|
}
|
|
40681
41669
|
} catch {
|
|
40682
41670
|
}
|
|
@@ -40915,7 +41903,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
40915
41903
|
const resolvedDbPath = probe.dbPath.replace(/^~/, os12.homedir());
|
|
40916
41904
|
const now = Date.now();
|
|
40917
41905
|
if (this.cachedSqliteDbMissingUntil > now) return null;
|
|
40918
|
-
if (!
|
|
41906
|
+
if (!fs7.existsSync(resolvedDbPath)) {
|
|
40919
41907
|
this.cachedSqliteDbMissingUntil = now + 1e4;
|
|
40920
41908
|
return null;
|
|
40921
41909
|
}
|
|
@@ -41831,7 +42819,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
41831
42819
|
};
|
|
41832
42820
|
addDir(this.workingDir);
|
|
41833
42821
|
try {
|
|
41834
|
-
addDir(
|
|
42822
|
+
addDir(fs7.realpathSync.native(this.workingDir));
|
|
41835
42823
|
} catch {
|
|
41836
42824
|
}
|
|
41837
42825
|
return Array.from(dirs);
|
|
@@ -41868,7 +42856,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
41868
42856
|
};
|
|
41869
42857
|
var path17 = __toESM2(require("path"));
|
|
41870
42858
|
var import_stream = require("stream");
|
|
41871
|
-
var
|
|
42859
|
+
var import_child_process4 = require("child_process");
|
|
41872
42860
|
var import_sdk = (init_acp(), __toCommonJS(acp_exports));
|
|
41873
42861
|
init_logger();
|
|
41874
42862
|
function getPromptCapabilityFlags(agentCapabilities) {
|
|
@@ -42385,7 +43373,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
42385
43373
|
this.errorMessage = null;
|
|
42386
43374
|
this.errorReason = null;
|
|
42387
43375
|
this.stderrBuffer = [];
|
|
42388
|
-
this.process = (0,
|
|
43376
|
+
this.process = (0, import_child_process4.spawn)(command, args, {
|
|
42389
43377
|
cwd: this.workingDir,
|
|
42390
43378
|
env: env2,
|
|
42391
43379
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -43106,7 +44094,7 @@ ${rawInput}` : rawInput;
|
|
|
43106
44094
|
return (0, import_fs10.existsSync)(expandExecutable(trimmed));
|
|
43107
44095
|
}
|
|
43108
44096
|
try {
|
|
43109
|
-
(0,
|
|
44097
|
+
(0, import_child_process5.execFileSync)(process.platform === "win32" ? "where" : "which", [trimmed], {
|
|
43110
44098
|
stdio: "ignore",
|
|
43111
44099
|
...process.platform === "win32" ? { windowsHide: true } : {}
|
|
43112
44100
|
});
|
|
@@ -43913,11 +44901,11 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
43913
44901
|
return null;
|
|
43914
44902
|
}
|
|
43915
44903
|
};
|
|
43916
|
-
var
|
|
44904
|
+
var import_child_process6 = require("child_process");
|
|
43917
44905
|
var net3 = __toESM2(require("net"));
|
|
43918
44906
|
var os15 = __toESM2(require("os"));
|
|
43919
44907
|
var path20 = __toESM2(require("path"));
|
|
43920
|
-
var
|
|
44908
|
+
var fs8 = __toESM2(require("fs"));
|
|
43921
44909
|
var path19 = __toESM2(require("path"));
|
|
43922
44910
|
var os14 = __toESM2(require("os"));
|
|
43923
44911
|
var chokidar = __toESM2(require_chokidar());
|
|
@@ -44266,9 +45254,9 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44266
45254
|
static siblingStderrLogged = /* @__PURE__ */ new Set();
|
|
44267
45255
|
static looksLikeProviderRoot(candidate) {
|
|
44268
45256
|
try {
|
|
44269
|
-
if (!
|
|
45257
|
+
if (!fs8.existsSync(candidate) || !fs8.statSync(candidate).isDirectory()) return false;
|
|
44270
45258
|
return ["ide", "extension", "cli", "acp"].some(
|
|
44271
|
-
(category) =>
|
|
45259
|
+
(category) => fs8.existsSync(path19.join(candidate, category))
|
|
44272
45260
|
);
|
|
44273
45261
|
} catch {
|
|
44274
45262
|
return false;
|
|
@@ -44276,7 +45264,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44276
45264
|
}
|
|
44277
45265
|
static hasProviderRootMarker(candidate) {
|
|
44278
45266
|
try {
|
|
44279
|
-
return
|
|
45267
|
+
return fs8.existsSync(path19.join(candidate, _ProviderLoader.SIBLING_MARKER_FILE));
|
|
44280
45268
|
} catch {
|
|
44281
45269
|
return false;
|
|
44282
45270
|
}
|
|
@@ -44438,7 +45426,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44438
45426
|
this.providers.clear();
|
|
44439
45427
|
this.providerAvailability.clear();
|
|
44440
45428
|
let upstreamCount = 0;
|
|
44441
|
-
if (!this.disableUpstream &&
|
|
45429
|
+
if (!this.disableUpstream && fs8.existsSync(this.upstreamDir)) {
|
|
44442
45430
|
upstreamCount = this.loadDir(this.upstreamDir);
|
|
44443
45431
|
if (upstreamCount > 0) {
|
|
44444
45432
|
this.log(`Loaded ${upstreamCount} upstream providers (auto-updated)`);
|
|
@@ -44446,7 +45434,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44446
45434
|
} else if (this.disableUpstream) {
|
|
44447
45435
|
this.log("Upstream loading disabled (sourceMode=no-upstream)");
|
|
44448
45436
|
}
|
|
44449
|
-
if (
|
|
45437
|
+
if (fs8.existsSync(this.userDir)) {
|
|
44450
45438
|
const userCount = this.loadDir(this.userDir, [".upstream"]);
|
|
44451
45439
|
if (userCount > 0) {
|
|
44452
45440
|
this.log(`Loaded ${userCount} user custom providers (never auto-updated)`);
|
|
@@ -44461,10 +45449,10 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44461
45449
|
* Check if upstream directory exists and has providers.
|
|
44462
45450
|
*/
|
|
44463
45451
|
hasUpstream() {
|
|
44464
|
-
if (!
|
|
45452
|
+
if (!fs8.existsSync(this.upstreamDir)) return false;
|
|
44465
45453
|
try {
|
|
44466
|
-
return
|
|
44467
|
-
(d) =>
|
|
45454
|
+
return fs8.readdirSync(this.upstreamDir).some(
|
|
45455
|
+
(d) => fs8.statSync(path19.join(this.upstreamDir, d)).isDirectory()
|
|
44468
45456
|
);
|
|
44469
45457
|
} catch {
|
|
44470
45458
|
return false;
|
|
@@ -44962,7 +45950,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44962
45950
|
resolved._resolvedScriptsSource = `compatibility:${entry.ideVersion}`;
|
|
44963
45951
|
if (providerDir) {
|
|
44964
45952
|
const fullDir = path19.join(providerDir, entry.scriptDir);
|
|
44965
|
-
resolved._resolvedScriptsPath =
|
|
45953
|
+
resolved._resolvedScriptsPath = fs8.existsSync(path19.join(fullDir, "scripts.js")) ? path19.join(fullDir, "scripts.js") : fullDir;
|
|
44966
45954
|
}
|
|
44967
45955
|
matched = true;
|
|
44968
45956
|
}
|
|
@@ -44978,7 +45966,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44978
45966
|
resolved._resolvedScriptsSource = "defaultScriptDir:version_miss";
|
|
44979
45967
|
if (providerDir) {
|
|
44980
45968
|
const fullDir = path19.join(providerDir, base.defaultScriptDir);
|
|
44981
|
-
resolved._resolvedScriptsPath =
|
|
45969
|
+
resolved._resolvedScriptsPath = fs8.existsSync(path19.join(fullDir, "scripts.js")) ? path19.join(fullDir, "scripts.js") : fullDir;
|
|
44982
45970
|
}
|
|
44983
45971
|
}
|
|
44984
45972
|
resolved._versionWarning = `Version ${currentVersion} not in compatibility matrix. Using default scripts.`;
|
|
@@ -44996,7 +45984,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
44996
45984
|
resolved._resolvedScriptsSource = `versions:${range}`;
|
|
44997
45985
|
if (providerDir) {
|
|
44998
45986
|
const fullDir = path19.join(providerDir, dirOverride);
|
|
44999
|
-
resolved._resolvedScriptsPath =
|
|
45987
|
+
resolved._resolvedScriptsPath = fs8.existsSync(path19.join(fullDir, "scripts.js")) ? path19.join(fullDir, "scripts.js") : fullDir;
|
|
45000
45988
|
}
|
|
45001
45989
|
}
|
|
45002
45990
|
} else if (override.scripts) {
|
|
@@ -45013,7 +46001,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45013
46001
|
resolved._resolvedScriptsSource = "defaultScriptDir:no_version";
|
|
45014
46002
|
if (providerDir) {
|
|
45015
46003
|
const fullDir = path19.join(providerDir, base.defaultScriptDir);
|
|
45016
|
-
resolved._resolvedScriptsPath =
|
|
46004
|
+
resolved._resolvedScriptsPath = fs8.existsSync(path19.join(fullDir, "scripts.js")) ? path19.join(fullDir, "scripts.js") : fullDir;
|
|
45017
46005
|
}
|
|
45018
46006
|
}
|
|
45019
46007
|
}
|
|
@@ -45046,14 +46034,14 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45046
46034
|
return null;
|
|
45047
46035
|
}
|
|
45048
46036
|
const dir = path19.join(providerDir, scriptDir);
|
|
45049
|
-
if (!
|
|
46037
|
+
if (!fs8.existsSync(dir)) {
|
|
45050
46038
|
this.log(` [loadScriptsFromDir] ${type}: dir not found: ${dir}`);
|
|
45051
46039
|
return null;
|
|
45052
46040
|
}
|
|
45053
46041
|
const cached2 = this.scriptsCache.get(dir);
|
|
45054
46042
|
if (cached2) return cached2;
|
|
45055
46043
|
const scriptsJs = path19.join(dir, "scripts.js");
|
|
45056
|
-
if (
|
|
46044
|
+
if (fs8.existsSync(scriptsJs)) {
|
|
45057
46045
|
try {
|
|
45058
46046
|
delete require.cache[require.resolve(scriptsJs)];
|
|
45059
46047
|
const loaded = require(scriptsJs);
|
|
@@ -45074,9 +46062,9 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45074
46062
|
watch() {
|
|
45075
46063
|
this.stopWatch();
|
|
45076
46064
|
const watchDir = (dir) => {
|
|
45077
|
-
if (!
|
|
46065
|
+
if (!fs8.existsSync(dir)) {
|
|
45078
46066
|
try {
|
|
45079
|
-
|
|
46067
|
+
fs8.mkdirSync(dir, { recursive: true });
|
|
45080
46068
|
} catch {
|
|
45081
46069
|
return;
|
|
45082
46070
|
}
|
|
@@ -45089,13 +46077,17 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45089
46077
|
ignoreInitial: true,
|
|
45090
46078
|
awaitWriteFinish: { stabilityThreshold: 200, pollInterval: 50 }
|
|
45091
46079
|
});
|
|
46080
|
+
let reloadTimer = null;
|
|
45092
46081
|
const handleChange = (filePath) => {
|
|
45093
46082
|
if (/[\/\\]fixtures[\/\\]/.test(filePath)) {
|
|
45094
46083
|
return;
|
|
45095
46084
|
}
|
|
45096
46085
|
if (filePath.endsWith(".js") || filePath.endsWith(".json")) {
|
|
45097
|
-
|
|
45098
|
-
|
|
46086
|
+
if (reloadTimer) clearTimeout(reloadTimer);
|
|
46087
|
+
reloadTimer = setTimeout(() => {
|
|
46088
|
+
this.log(`File changed: ${path19.basename(filePath)}, reloading...`);
|
|
46089
|
+
this.reload();
|
|
46090
|
+
}, 300);
|
|
45099
46091
|
}
|
|
45100
46092
|
};
|
|
45101
46093
|
watcher.on("add", handleChange).on("change", handleChange).on("unlink", handleChange);
|
|
@@ -45148,13 +46140,15 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45148
46140
|
return { updated: false };
|
|
45149
46141
|
}
|
|
45150
46142
|
const https = require("https");
|
|
45151
|
-
const {
|
|
46143
|
+
const { exec: exec7 } = require("child_process");
|
|
46144
|
+
const { promisify: promisify6 } = require("util");
|
|
46145
|
+
const execAsync5 = promisify6(exec7);
|
|
45152
46146
|
const metaPath = path19.join(this.upstreamDir, _ProviderLoader.META_FILE);
|
|
45153
46147
|
let prevEtag = "";
|
|
45154
46148
|
let prevTimestamp = 0;
|
|
45155
46149
|
try {
|
|
45156
|
-
if (
|
|
45157
|
-
const meta3 = JSON.parse(
|
|
46150
|
+
if (fs8.existsSync(metaPath)) {
|
|
46151
|
+
const meta3 = JSON.parse(fs8.readFileSync(metaPath, "utf-8"));
|
|
45158
46152
|
prevEtag = meta3.etag || "";
|
|
45159
46153
|
prevTimestamp = meta3.timestamp || 0;
|
|
45160
46154
|
}
|
|
@@ -45212,36 +46206,36 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45212
46206
|
const tmpTar = path19.join(os14.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
|
|
45213
46207
|
const tmpExtract = path19.join(os14.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
|
|
45214
46208
|
await this.downloadFile(_ProviderLoader.GITHUB_TARBALL_URL, tmpTar);
|
|
45215
|
-
|
|
45216
|
-
|
|
45217
|
-
const extracted =
|
|
46209
|
+
fs8.mkdirSync(tmpExtract, { recursive: true });
|
|
46210
|
+
await execAsync5(`tar -xzf "${tmpTar}" -C "${tmpExtract}"`, { timeout: 3e4 });
|
|
46211
|
+
const extracted = fs8.readdirSync(tmpExtract);
|
|
45218
46212
|
const rootDir = extracted.find(
|
|
45219
|
-
(d) =>
|
|
46213
|
+
(d) => fs8.statSync(path19.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
|
|
45220
46214
|
);
|
|
45221
46215
|
if (!rootDir) throw new Error("Unexpected tarball structure");
|
|
45222
46216
|
const sourceDir = path19.join(tmpExtract, rootDir);
|
|
45223
46217
|
const backupDir = this.upstreamDir + ".bak";
|
|
45224
|
-
if (
|
|
45225
|
-
if (
|
|
45226
|
-
|
|
46218
|
+
if (fs8.existsSync(this.upstreamDir)) {
|
|
46219
|
+
if (fs8.existsSync(backupDir)) fs8.rmSync(backupDir, { recursive: true, force: true });
|
|
46220
|
+
fs8.renameSync(this.upstreamDir, backupDir);
|
|
45227
46221
|
}
|
|
45228
46222
|
try {
|
|
45229
46223
|
this.copyDirRecursive(sourceDir, this.upstreamDir);
|
|
45230
46224
|
this.writeMeta(metaPath, etag || `ts-${Date.now()}`, Date.now());
|
|
45231
|
-
if (
|
|
46225
|
+
if (fs8.existsSync(backupDir)) fs8.rmSync(backupDir, { recursive: true, force: true });
|
|
45232
46226
|
} catch (e) {
|
|
45233
|
-
if (
|
|
45234
|
-
if (
|
|
45235
|
-
|
|
46227
|
+
if (fs8.existsSync(backupDir)) {
|
|
46228
|
+
if (fs8.existsSync(this.upstreamDir)) fs8.rmSync(this.upstreamDir, { recursive: true, force: true });
|
|
46229
|
+
fs8.renameSync(backupDir, this.upstreamDir);
|
|
45236
46230
|
}
|
|
45237
46231
|
throw e;
|
|
45238
46232
|
}
|
|
45239
46233
|
try {
|
|
45240
|
-
|
|
46234
|
+
fs8.rmSync(tmpTar, { force: true });
|
|
45241
46235
|
} catch {
|
|
45242
46236
|
}
|
|
45243
46237
|
try {
|
|
45244
|
-
|
|
46238
|
+
fs8.rmSync(tmpExtract, { recursive: true, force: true });
|
|
45245
46239
|
} catch {
|
|
45246
46240
|
}
|
|
45247
46241
|
const upstreamCount = this.countProviders(this.upstreamDir);
|
|
@@ -45273,7 +46267,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45273
46267
|
reject(new Error(`HTTP ${res.statusCode}`));
|
|
45274
46268
|
return;
|
|
45275
46269
|
}
|
|
45276
|
-
const ws =
|
|
46270
|
+
const ws = fs8.createWriteStream(destPath);
|
|
45277
46271
|
res.pipe(ws);
|
|
45278
46272
|
ws.on("finish", () => {
|
|
45279
46273
|
ws.close();
|
|
@@ -45292,22 +46286,22 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45292
46286
|
}
|
|
45293
46287
|
/** Recursive directory copy */
|
|
45294
46288
|
copyDirRecursive(src, dest) {
|
|
45295
|
-
|
|
45296
|
-
for (const entry of
|
|
46289
|
+
fs8.mkdirSync(dest, { recursive: true });
|
|
46290
|
+
for (const entry of fs8.readdirSync(src, { withFileTypes: true })) {
|
|
45297
46291
|
const srcPath = path19.join(src, entry.name);
|
|
45298
46292
|
const destPath = path19.join(dest, entry.name);
|
|
45299
46293
|
if (entry.isDirectory()) {
|
|
45300
46294
|
this.copyDirRecursive(srcPath, destPath);
|
|
45301
46295
|
} else {
|
|
45302
|
-
|
|
46296
|
+
fs8.copyFileSync(srcPath, destPath);
|
|
45303
46297
|
}
|
|
45304
46298
|
}
|
|
45305
46299
|
}
|
|
45306
46300
|
/** .meta.json save */
|
|
45307
46301
|
writeMeta(metaPath, etag, timestamp) {
|
|
45308
46302
|
try {
|
|
45309
|
-
|
|
45310
|
-
|
|
46303
|
+
fs8.mkdirSync(path19.dirname(metaPath), { recursive: true });
|
|
46304
|
+
fs8.writeFileSync(metaPath, JSON.stringify({
|
|
45311
46305
|
etag,
|
|
45312
46306
|
timestamp,
|
|
45313
46307
|
lastCheck: new Date(timestamp).toISOString(),
|
|
@@ -45318,11 +46312,11 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45318
46312
|
}
|
|
45319
46313
|
/** Count provider files (provider.js or provider.json) */
|
|
45320
46314
|
countProviders(dir) {
|
|
45321
|
-
if (!
|
|
46315
|
+
if (!fs8.existsSync(dir)) return 0;
|
|
45322
46316
|
let count = 0;
|
|
45323
46317
|
const scan = (d) => {
|
|
45324
46318
|
try {
|
|
45325
|
-
for (const entry of
|
|
46319
|
+
for (const entry of fs8.readdirSync(d, { withFileTypes: true })) {
|
|
45326
46320
|
if (entry.isDirectory()) scan(path19.join(d, entry.name));
|
|
45327
46321
|
else if (entry.name === "provider.json") count++;
|
|
45328
46322
|
}
|
|
@@ -45549,18 +46543,18 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45549
46543
|
const cat = provider.category;
|
|
45550
46544
|
const searchRoots = this.getProviderRoots();
|
|
45551
46545
|
for (const root of searchRoots) {
|
|
45552
|
-
if (!
|
|
46546
|
+
if (!fs8.existsSync(root)) continue;
|
|
45553
46547
|
const candidate = this.getProviderDir(root, cat, type);
|
|
45554
|
-
if (
|
|
46548
|
+
if (fs8.existsSync(path19.join(candidate, "provider.json"))) return candidate;
|
|
45555
46549
|
const catDir = path19.join(root, cat);
|
|
45556
|
-
if (
|
|
46550
|
+
if (fs8.existsSync(catDir)) {
|
|
45557
46551
|
try {
|
|
45558
|
-
for (const entry of
|
|
46552
|
+
for (const entry of fs8.readdirSync(catDir, { withFileTypes: true })) {
|
|
45559
46553
|
if (!entry.isDirectory()) continue;
|
|
45560
46554
|
const jsonPath = path19.join(catDir, entry.name, "provider.json");
|
|
45561
|
-
if (
|
|
46555
|
+
if (fs8.existsSync(jsonPath)) {
|
|
45562
46556
|
try {
|
|
45563
|
-
const data = JSON.parse(
|
|
46557
|
+
const data = JSON.parse(fs8.readFileSync(jsonPath, "utf-8"));
|
|
45564
46558
|
if (data.type === type) return path19.join(catDir, entry.name);
|
|
45565
46559
|
} catch {
|
|
45566
46560
|
}
|
|
@@ -45579,7 +46573,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45579
46573
|
*/
|
|
45580
46574
|
buildScriptWrappersFromDir(dir) {
|
|
45581
46575
|
const scriptsJs = path19.join(dir, "scripts.js");
|
|
45582
|
-
if (
|
|
46576
|
+
if (fs8.existsSync(scriptsJs)) {
|
|
45583
46577
|
try {
|
|
45584
46578
|
delete require.cache[require.resolve(scriptsJs)];
|
|
45585
46579
|
return require(scriptsJs);
|
|
@@ -45589,13 +46583,13 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45589
46583
|
const toCamel = (name) => name.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
45590
46584
|
const result = {};
|
|
45591
46585
|
try {
|
|
45592
|
-
for (const file2 of
|
|
46586
|
+
for (const file2 of fs8.readdirSync(dir)) {
|
|
45593
46587
|
if (!file2.endsWith(".js")) continue;
|
|
45594
46588
|
const scriptName = toCamel(file2.replace(".js", ""));
|
|
45595
46589
|
const filePath = path19.join(dir, file2);
|
|
45596
46590
|
result[scriptName] = (...args) => {
|
|
45597
46591
|
try {
|
|
45598
|
-
let content =
|
|
46592
|
+
let content = fs8.readFileSync(filePath, "utf-8");
|
|
45599
46593
|
if (args[0] && typeof args[0] === "object") {
|
|
45600
46594
|
for (const [key, val] of Object.entries(args[0])) {
|
|
45601
46595
|
let v = val;
|
|
@@ -45641,12 +46635,12 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45641
46635
|
* Structure: dir/category/agent-name/provider.{json,js}
|
|
45642
46636
|
*/
|
|
45643
46637
|
loadDir(dir, excludeDirs) {
|
|
45644
|
-
if (!
|
|
46638
|
+
if (!fs8.existsSync(dir)) return 0;
|
|
45645
46639
|
let count = 0;
|
|
45646
46640
|
const scan = (d) => {
|
|
45647
46641
|
let entries;
|
|
45648
46642
|
try {
|
|
45649
|
-
entries =
|
|
46643
|
+
entries = fs8.readdirSync(d, { withFileTypes: true });
|
|
45650
46644
|
} catch {
|
|
45651
46645
|
return;
|
|
45652
46646
|
}
|
|
@@ -45654,7 +46648,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45654
46648
|
if (hasJson) {
|
|
45655
46649
|
const jsonPath = path19.join(d, "provider.json");
|
|
45656
46650
|
try {
|
|
45657
|
-
const raw =
|
|
46651
|
+
const raw = fs8.readFileSync(jsonPath, "utf-8");
|
|
45658
46652
|
const mod = JSON.parse(raw);
|
|
45659
46653
|
if (typeof mod.extensionIdPattern === "string") {
|
|
45660
46654
|
const flags = mod.extensionIdPattern_flags || "";
|
|
@@ -45674,7 +46668,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45674
46668
|
} else {
|
|
45675
46669
|
const hasCompatibility = Array.isArray(normalizedProvider.compatibility);
|
|
45676
46670
|
const scriptsPath = path19.join(d, "scripts.js");
|
|
45677
|
-
if (!hasCompatibility &&
|
|
46671
|
+
if (!hasCompatibility && fs8.existsSync(scriptsPath)) {
|
|
45678
46672
|
try {
|
|
45679
46673
|
delete require.cache[require.resolve(scriptsPath)];
|
|
45680
46674
|
const scripts = require(scriptsPath);
|
|
@@ -45775,6 +46769,14 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45775
46769
|
}
|
|
45776
46770
|
return pids;
|
|
45777
46771
|
}
|
|
46772
|
+
async function execQuiet(command, options = {}) {
|
|
46773
|
+
return new Promise((resolve16) => {
|
|
46774
|
+
(0, import_child_process6.exec)(command, options, (error48, stdout) => {
|
|
46775
|
+
if (error48) return resolve16("");
|
|
46776
|
+
resolve16(stdout.toString());
|
|
46777
|
+
});
|
|
46778
|
+
});
|
|
46779
|
+
}
|
|
45778
46780
|
var _providerLoader = null;
|
|
45779
46781
|
function getProviderLoader() {
|
|
45780
46782
|
if (!_providerLoader) {
|
|
@@ -45813,11 +46815,11 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45813
46815
|
function getIdePathCandidates(ideId) {
|
|
45814
46816
|
return getProviderLoader().getIdePathCandidates(ideId);
|
|
45815
46817
|
}
|
|
45816
|
-
function getMacAppProcessPids(ideId) {
|
|
46818
|
+
async function getMacAppProcessPids(ideId) {
|
|
45817
46819
|
const appPaths = getIdePathCandidates(ideId);
|
|
45818
46820
|
if (appPaths.length === 0) return [];
|
|
45819
46821
|
try {
|
|
45820
|
-
const output =
|
|
46822
|
+
const output = await execQuiet("ps axww -o pid=,args=", {
|
|
45821
46823
|
encoding: "utf-8",
|
|
45822
46824
|
timeout: 3e3,
|
|
45823
46825
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -45827,8 +46829,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45827
46829
|
return [];
|
|
45828
46830
|
}
|
|
45829
46831
|
}
|
|
45830
|
-
function killMacAppPathProcesses(ideId, signal) {
|
|
45831
|
-
const pids = getMacAppProcessPids(ideId);
|
|
46832
|
+
async function killMacAppPathProcesses(ideId, signal) {
|
|
46833
|
+
const pids = await getMacAppProcessPids(ideId);
|
|
45832
46834
|
let signalled = false;
|
|
45833
46835
|
for (const pid of pids) {
|
|
45834
46836
|
try {
|
|
@@ -45891,68 +46893,68 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45891
46893
|
try {
|
|
45892
46894
|
if (plat === "darwin" && appName) {
|
|
45893
46895
|
try {
|
|
45894
|
-
|
|
46896
|
+
await execQuiet(`osascript -e 'tell application "${escapeForAppleScript(appName)}" to quit' 2>/dev/null`, {
|
|
45895
46897
|
timeout: 5e3
|
|
45896
46898
|
});
|
|
45897
46899
|
} catch {
|
|
45898
46900
|
try {
|
|
45899
|
-
|
|
46901
|
+
await execQuiet(`pkill -x "${appName}" 2>/dev/null`, { timeout: 5e3 });
|
|
45900
46902
|
} catch {
|
|
45901
46903
|
}
|
|
45902
46904
|
}
|
|
45903
|
-
killMacAppPathProcesses(ideId, "SIGTERM");
|
|
46905
|
+
await killMacAppPathProcesses(ideId, "SIGTERM");
|
|
45904
46906
|
} else if (plat === "win32" && winProcesses) {
|
|
45905
46907
|
for (const proc of winProcesses) {
|
|
45906
46908
|
try {
|
|
45907
|
-
|
|
46909
|
+
await execQuiet(`taskkill /IM "${proc}" /F 2>nul`, { timeout: 5e3 });
|
|
45908
46910
|
} catch {
|
|
45909
46911
|
}
|
|
45910
46912
|
}
|
|
45911
46913
|
try {
|
|
45912
46914
|
const exeName = winProcesses[0].replace(".exe", "");
|
|
45913
|
-
|
|
46915
|
+
await execQuiet(`powershell -Command "Get-Process -Name '${exeName}' -ErrorAction SilentlyContinue | Stop-Process -Force"`, {
|
|
45914
46916
|
timeout: 1e4
|
|
45915
46917
|
});
|
|
45916
46918
|
} catch {
|
|
45917
46919
|
}
|
|
45918
46920
|
} else {
|
|
45919
46921
|
try {
|
|
45920
|
-
|
|
46922
|
+
await execQuiet(`pkill -f "${ideId}" 2>/dev/null`);
|
|
45921
46923
|
} catch {
|
|
45922
46924
|
}
|
|
45923
46925
|
}
|
|
45924
46926
|
for (let i = 0; i < 30; i++) {
|
|
45925
46927
|
await new Promise((r) => setTimeout(r, 500));
|
|
45926
|
-
if (!isIdeRunning(ideId)) return true;
|
|
46928
|
+
if (!await isIdeRunning(ideId)) return true;
|
|
45927
46929
|
}
|
|
45928
46930
|
if (plat === "darwin" && appName) {
|
|
45929
46931
|
try {
|
|
45930
|
-
|
|
46932
|
+
await execQuiet(`pkill -9 -x "${appName}" 2>/dev/null`, { timeout: 5e3 });
|
|
45931
46933
|
} catch {
|
|
45932
46934
|
}
|
|
45933
|
-
killMacAppPathProcesses(ideId, "SIGKILL");
|
|
46935
|
+
await killMacAppPathProcesses(ideId, "SIGKILL");
|
|
45934
46936
|
} else if (plat === "win32" && winProcesses) {
|
|
45935
46937
|
for (const proc of winProcesses) {
|
|
45936
46938
|
try {
|
|
45937
|
-
|
|
46939
|
+
await execQuiet(`taskkill /IM "${proc}" /F 2>nul`);
|
|
45938
46940
|
} catch {
|
|
45939
46941
|
}
|
|
45940
46942
|
}
|
|
45941
46943
|
}
|
|
45942
46944
|
await new Promise((r) => setTimeout(r, 2e3));
|
|
45943
|
-
return !isIdeRunning(ideId);
|
|
46945
|
+
return !await isIdeRunning(ideId);
|
|
45944
46946
|
} catch {
|
|
45945
46947
|
return false;
|
|
45946
46948
|
}
|
|
45947
46949
|
}
|
|
45948
|
-
function isIdeRunning(ideId) {
|
|
46950
|
+
async function isIdeRunning(ideId) {
|
|
45949
46951
|
const plat = os15.platform();
|
|
45950
46952
|
try {
|
|
45951
46953
|
if (plat === "darwin") {
|
|
45952
46954
|
const appName = getMacAppIdentifiers()[ideId];
|
|
45953
|
-
if (!appName) return getMacAppProcessPids(ideId).length > 0;
|
|
46955
|
+
if (!appName) return (await getMacAppProcessPids(ideId)).length > 0;
|
|
45954
46956
|
try {
|
|
45955
|
-
const result =
|
|
46957
|
+
const result = await execQuiet(`pgrep -x "${appName}" 2>/dev/null`, {
|
|
45956
46958
|
encoding: "utf-8",
|
|
45957
46959
|
timeout: 3e3
|
|
45958
46960
|
});
|
|
@@ -45960,7 +46962,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45960
46962
|
} catch {
|
|
45961
46963
|
}
|
|
45962
46964
|
try {
|
|
45963
|
-
const result =
|
|
46965
|
+
const result = await execQuiet(
|
|
45964
46966
|
`osascript -e 'tell application "System Events" to count (every process whose name is "${escapeForAppleScript(appName)}")'`,
|
|
45965
46967
|
{
|
|
45966
46968
|
encoding: "utf-8",
|
|
@@ -45971,20 +46973,20 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45971
46973
|
if (Number.parseInt(result.trim() || "0", 10) > 0) return true;
|
|
45972
46974
|
} catch {
|
|
45973
46975
|
}
|
|
45974
|
-
return getMacAppProcessPids(ideId).length > 0;
|
|
46976
|
+
return (await getMacAppProcessPids(ideId)).length > 0;
|
|
45975
46977
|
} else if (plat === "win32") {
|
|
45976
46978
|
const winProcesses = getWinProcessNames()[ideId];
|
|
45977
46979
|
if (!winProcesses) return false;
|
|
45978
46980
|
for (const proc of winProcesses) {
|
|
45979
46981
|
try {
|
|
45980
|
-
const result =
|
|
46982
|
+
const result = await execQuiet(`tasklist /FI "IMAGENAME eq ${proc}" /NH 2>nul`, { encoding: "utf-8" });
|
|
45981
46983
|
if (result.includes(proc)) return true;
|
|
45982
46984
|
} catch {
|
|
45983
46985
|
}
|
|
45984
46986
|
}
|
|
45985
46987
|
try {
|
|
45986
46988
|
const exeName = winProcesses[0].replace(".exe", "");
|
|
45987
|
-
const result =
|
|
46989
|
+
const result = await execQuiet(
|
|
45988
46990
|
`powershell -Command "(Get-Process -Name '${exeName}' -ErrorAction SilentlyContinue).Count"`,
|
|
45989
46991
|
{ encoding: "utf-8", timeout: 5e3 }
|
|
45990
46992
|
);
|
|
@@ -45993,20 +46995,20 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
45993
46995
|
}
|
|
45994
46996
|
return false;
|
|
45995
46997
|
} else {
|
|
45996
|
-
const result =
|
|
46998
|
+
const result = await execQuiet(`pgrep -f "${ideId}" 2>/dev/null`, { encoding: "utf-8" });
|
|
45997
46999
|
return result.trim().length > 0;
|
|
45998
47000
|
}
|
|
45999
47001
|
} catch {
|
|
46000
47002
|
return false;
|
|
46001
47003
|
}
|
|
46002
47004
|
}
|
|
46003
|
-
function detectCurrentWorkspace(ideId) {
|
|
47005
|
+
async function detectCurrentWorkspace(ideId) {
|
|
46004
47006
|
const plat = os15.platform();
|
|
46005
47007
|
if (plat === "darwin") {
|
|
46006
47008
|
try {
|
|
46007
47009
|
const appName = getMacAppIdentifiers()[ideId];
|
|
46008
47010
|
if (!appName) return void 0;
|
|
46009
|
-
const result =
|
|
47011
|
+
const result = await execQuiet(
|
|
46010
47012
|
`lsof -c "${appName}" 2>/dev/null | grep cwd | head -1 | awk '{print $NF}'`,
|
|
46011
47013
|
{ encoding: "utf-8", timeout: 3e3 }
|
|
46012
47014
|
);
|
|
@@ -46016,7 +47018,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46016
47018
|
}
|
|
46017
47019
|
} else if (plat === "win32") {
|
|
46018
47020
|
try {
|
|
46019
|
-
const
|
|
47021
|
+
const fs17 = require("fs");
|
|
46020
47022
|
const appNameMap = getMacAppIdentifiers();
|
|
46021
47023
|
const appName = appNameMap[ideId];
|
|
46022
47024
|
if (appName) {
|
|
@@ -46025,8 +47027,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46025
47027
|
appName,
|
|
46026
47028
|
"storage.json"
|
|
46027
47029
|
);
|
|
46028
|
-
if (
|
|
46029
|
-
const data = JSON.parse(
|
|
47030
|
+
if (fs17.existsSync(storagePath)) {
|
|
47031
|
+
const data = JSON.parse(fs17.readFileSync(storagePath, "utf-8"));
|
|
46030
47032
|
const workspaces = data?.openedPathsList?.workspaces3 || data?.openedPathsList?.entries || [];
|
|
46031
47033
|
if (workspaces.length > 0) {
|
|
46032
47034
|
const recent = workspaces[0];
|
|
@@ -46093,8 +47095,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46093
47095
|
};
|
|
46094
47096
|
}
|
|
46095
47097
|
}
|
|
46096
|
-
const alreadyRunning = isIdeRunning(targetIde.id);
|
|
46097
|
-
const workspace = options.workspace || (alreadyRunning ? detectCurrentWorkspace(targetIde.id) : void 0);
|
|
47098
|
+
const alreadyRunning = await isIdeRunning(targetIde.id);
|
|
47099
|
+
const workspace = options.workspace || (alreadyRunning ? await detectCurrentWorkspace(targetIde.id) : void 0);
|
|
46098
47100
|
if (alreadyRunning) {
|
|
46099
47101
|
const killed = await killIdeProcess(targetIde.id);
|
|
46100
47102
|
if (!killed) {
|
|
@@ -46169,10 +47171,10 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46169
47171
|
const canUseAppLauncher = !!appName;
|
|
46170
47172
|
const useAppLauncher = preferredMethod === "app" ? canUseAppLauncher : preferredMethod === "cli" ? false : !canUseCli && canUseAppLauncher;
|
|
46171
47173
|
if (!useAppLauncher && ide.cliCommand) {
|
|
46172
|
-
(0,
|
|
47174
|
+
(0, import_child_process6.spawn)(ide.cliCommand, args, { detached: true, stdio: "ignore", windowsHide: true }).unref();
|
|
46173
47175
|
} else if (appName) {
|
|
46174
47176
|
const openArgs = ["-a", appName, "--args", ...args];
|
|
46175
|
-
(0,
|
|
47177
|
+
(0, import_child_process6.spawn)("open", openArgs, { detached: true, stdio: "ignore" }).unref();
|
|
46176
47178
|
} else {
|
|
46177
47179
|
throw new Error(`No app identifier or CLI for ${ide.displayName}`);
|
|
46178
47180
|
}
|
|
@@ -46198,7 +47200,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46198
47200
|
const args = ["--remote-debugging-port=" + port];
|
|
46199
47201
|
if (newWindow) args.push("--new-window");
|
|
46200
47202
|
if (workspace) args.push(workspace);
|
|
46201
|
-
(0,
|
|
47203
|
+
(0, import_child_process6.spawn)(cli, args, { detached: true, stdio: "ignore", windowsHide: true }).unref();
|
|
46202
47204
|
}
|
|
46203
47205
|
function getAvailableIdeIds() {
|
|
46204
47206
|
return getProviderLoader().getAvailableIdeTypes();
|
|
@@ -46206,14 +47208,14 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46206
47208
|
init_config();
|
|
46207
47209
|
init_cli_detector();
|
|
46208
47210
|
init_logger();
|
|
46209
|
-
var
|
|
47211
|
+
var fs9 = __toESM2(require("fs"));
|
|
46210
47212
|
var path21 = __toESM2(require("path"));
|
|
46211
47213
|
var os16 = __toESM2(require("os"));
|
|
46212
47214
|
var LOG_DIR2 = process.platform === "win32" ? path21.join(process.env.LOCALAPPDATA || process.env.APPDATA || path21.join(os16.homedir(), "AppData", "Local"), "adhdev", "logs") : process.platform === "darwin" ? path21.join(os16.homedir(), "Library", "Logs", "adhdev") : path21.join(os16.homedir(), ".local", "share", "adhdev", "logs");
|
|
46213
47215
|
var MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
46214
47216
|
var MAX_DAYS = 7;
|
|
46215
47217
|
try {
|
|
46216
|
-
|
|
47218
|
+
fs9.mkdirSync(LOG_DIR2, { recursive: true });
|
|
46217
47219
|
} catch {
|
|
46218
47220
|
}
|
|
46219
47221
|
var SENSITIVE_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -46259,7 +47261,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46259
47261
|
}
|
|
46260
47262
|
function cleanOldFiles() {
|
|
46261
47263
|
try {
|
|
46262
|
-
const files =
|
|
47264
|
+
const files = fs9.readdirSync(LOG_DIR2).filter((f) => f.startsWith("commands-") && f.endsWith(".jsonl"));
|
|
46263
47265
|
const cutoff = /* @__PURE__ */ new Date();
|
|
46264
47266
|
cutoff.setDate(cutoff.getDate() - MAX_DAYS);
|
|
46265
47267
|
const cutoffStr = cutoff.toISOString().slice(0, 10);
|
|
@@ -46267,7 +47269,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46267
47269
|
const dateMatch = file2.match(/commands-(\d{4}-\d{2}-\d{2})/);
|
|
46268
47270
|
if (dateMatch && dateMatch[1] < cutoffStr) {
|
|
46269
47271
|
try {
|
|
46270
|
-
|
|
47272
|
+
fs9.unlinkSync(path21.join(LOG_DIR2, file2));
|
|
46271
47273
|
} catch {
|
|
46272
47274
|
}
|
|
46273
47275
|
}
|
|
@@ -46277,14 +47279,14 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46277
47279
|
}
|
|
46278
47280
|
function checkSize() {
|
|
46279
47281
|
try {
|
|
46280
|
-
const stat2 =
|
|
47282
|
+
const stat2 = fs9.statSync(currentFile);
|
|
46281
47283
|
if (stat2.size > MAX_FILE_SIZE) {
|
|
46282
47284
|
const backup = currentFile.replace(".jsonl", ".1.jsonl");
|
|
46283
47285
|
try {
|
|
46284
|
-
|
|
47286
|
+
fs9.unlinkSync(backup);
|
|
46285
47287
|
} catch {
|
|
46286
47288
|
}
|
|
46287
|
-
|
|
47289
|
+
fs9.renameSync(currentFile, backup);
|
|
46288
47290
|
}
|
|
46289
47291
|
} catch {
|
|
46290
47292
|
}
|
|
@@ -46317,14 +47319,14 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46317
47319
|
...entry.error ? { err: entry.error } : {},
|
|
46318
47320
|
...entry.durationMs !== void 0 ? { ms: entry.durationMs } : {}
|
|
46319
47321
|
});
|
|
46320
|
-
|
|
47322
|
+
fs9.appendFileSync(currentFile, line + "\n");
|
|
46321
47323
|
} catch {
|
|
46322
47324
|
}
|
|
46323
47325
|
}
|
|
46324
47326
|
function getRecentCommands(count = 50) {
|
|
46325
47327
|
try {
|
|
46326
|
-
if (!
|
|
46327
|
-
const content =
|
|
47328
|
+
if (!fs9.existsSync(currentFile)) return [];
|
|
47329
|
+
const content = fs9.readFileSync(currentFile, "utf-8");
|
|
46328
47330
|
const lines = content.trim().split("\n").filter(Boolean);
|
|
46329
47331
|
return lines.slice(-count).map((line) => {
|
|
46330
47332
|
try {
|
|
@@ -46350,14 +47352,11 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46350
47352
|
cleanOldFiles();
|
|
46351
47353
|
var yaml2 = __toESM2(require_js_yaml());
|
|
46352
47354
|
init_logger();
|
|
46353
|
-
var import_node_child_process3 = require("child_process");
|
|
46354
47355
|
var import_node_crypto2 = require("crypto");
|
|
46355
|
-
var import_node_fs3 = require("fs");
|
|
46356
|
-
var import_node_module2 = require("module");
|
|
46357
47356
|
var os17 = __toESM2(require("os"));
|
|
46358
47357
|
var import_node_path = require("path");
|
|
46359
47358
|
var DEFAULT_SERVER_NAME = "adhdev-mesh";
|
|
46360
|
-
var DEFAULT_ADHDEV_MCP_COMMAND = "adhdev
|
|
47359
|
+
var DEFAULT_ADHDEV_MCP_COMMAND = "adhdev";
|
|
46361
47360
|
var HERMES_CLI_TYPE = "hermes-cli";
|
|
46362
47361
|
var HERMES_MCP_CONFIG_PATH = "~/.hermes/config.yaml";
|
|
46363
47362
|
function isHermesProvider(provider, cliType) {
|
|
@@ -46367,8 +47366,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46367
47366
|
function resolveHermesMeshCoordinatorSetup(options) {
|
|
46368
47367
|
const mcpServer = resolveAdhdevMcpServerLaunch({
|
|
46369
47368
|
meshId: options.meshId,
|
|
46370
|
-
|
|
46371
|
-
adhdevMcpEntryPath: options.adhdevMcpEntryPath,
|
|
47369
|
+
adhdevMcpCommand: options.adhdevMcpCommand,
|
|
46372
47370
|
adhdevMcpTransport: options.adhdevMcpTransport,
|
|
46373
47371
|
adhdevMcpPort: options.adhdevMcpPort
|
|
46374
47372
|
});
|
|
@@ -46399,7 +47397,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46399
47397
|
requiresRestart: true,
|
|
46400
47398
|
instructions: "Hermes CLI does not auto-import repo-local .mcp.json. Add this MCP server to Hermes config under mcp_servers, then start a fresh Hermes session.",
|
|
46401
47399
|
template: renderMeshCoordinatorTemplate(
|
|
46402
|
-
"mcp_servers:\n {{serverName}}:\n command: {{adhdevMcpCommand}}\n args:\n - --repo-mesh\n - {{meshId}}\n enabled: true\n",
|
|
47400
|
+
"mcp_servers:\n {{serverName}}:\n command: {{adhdevMcpCommand}}\n args:\n - mcp\n - --mode\n - ipc\n - --repo-mesh\n - {{meshId}}\n enabled: true\n",
|
|
46403
47401
|
{
|
|
46404
47402
|
meshId,
|
|
46405
47403
|
workspace,
|
|
@@ -46436,8 +47434,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
46436
47434
|
}
|
|
46437
47435
|
const mcpServer = resolveAdhdevMcpServerLaunch({
|
|
46438
47436
|
meshId,
|
|
46439
|
-
|
|
46440
|
-
adhdevMcpEntryPath: options.adhdevMcpEntryPath,
|
|
47437
|
+
adhdevMcpCommand: options.adhdevMcpCommand,
|
|
46441
47438
|
adhdevMcpTransport: options.adhdevMcpTransport,
|
|
46442
47439
|
adhdevMcpPort: options.adhdevMcpPort
|
|
46443
47440
|
});
|
|
@@ -46509,19 +47506,19 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
46509
47506
|
return (0, import_node_path.join)(workspace, trimmed);
|
|
46510
47507
|
}
|
|
46511
47508
|
function resolveAdhdevMcpServerLaunch(options) {
|
|
46512
|
-
const
|
|
46513
|
-
if (!entryPath) return null;
|
|
46514
|
-
const nodeExecutable = resolveMcpNodeExecutable(options.nodeExecutable);
|
|
46515
|
-
if (!nodeExecutable) return null;
|
|
47509
|
+
const command = resolveAdhdevCommand(options.adhdevMcpCommand);
|
|
46516
47510
|
const transport = resolveMcpTransport(options.adhdevMcpTransport);
|
|
46517
|
-
const args = [
|
|
47511
|
+
const args = ["mcp", "--mode", transport, "--repo-mesh", options.meshId];
|
|
46518
47512
|
const port = resolveMcpPort(options.adhdevMcpPort);
|
|
46519
47513
|
if (port !== void 0) args.push("--port", String(port));
|
|
46520
47514
|
return {
|
|
46521
|
-
command
|
|
47515
|
+
command,
|
|
46522
47516
|
args
|
|
46523
47517
|
};
|
|
46524
47518
|
}
|
|
47519
|
+
function resolveAdhdevCommand(explicitCommand) {
|
|
47520
|
+
return explicitCommand?.trim() || process.env.ADHDEV_COORDINATOR_MCP_COMMAND?.trim() || DEFAULT_ADHDEV_MCP_COMMAND;
|
|
47521
|
+
}
|
|
46525
47522
|
function resolveMcpTransport(explicitTransport) {
|
|
46526
47523
|
if (explicitTransport === "local" || explicitTransport === "ipc") return explicitTransport;
|
|
46527
47524
|
const envTransport = process.env.ADHDEV_COORDINATOR_MCP_TRANSPORT?.trim();
|
|
@@ -46534,109 +47531,6 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
46534
47531
|
const parsed = Number(raw);
|
|
46535
47532
|
return Number.isInteger(parsed) && parsed > 0 ? parsed : void 0;
|
|
46536
47533
|
}
|
|
46537
|
-
function resolveMcpNodeExecutable(explicitExecutable) {
|
|
46538
|
-
const explicit = explicitExecutable?.trim();
|
|
46539
|
-
if (explicit) return explicit;
|
|
46540
|
-
const candidates = [];
|
|
46541
|
-
const addCandidate = (candidate) => {
|
|
46542
|
-
const trimmed = candidate?.trim();
|
|
46543
|
-
if (!trimmed) return;
|
|
46544
|
-
const normalized = normalizeExistingPath(trimmed) || trimmed;
|
|
46545
|
-
if (!candidates.includes(normalized)) candidates.push(normalized);
|
|
46546
|
-
};
|
|
46547
|
-
addCandidate(process.env.ADHDEV_MCP_NODE_EXECUTABLE);
|
|
46548
|
-
addCandidate(process.env.ADHDEV_NODE_EXECUTABLE);
|
|
46549
|
-
addCandidate(process.env.npm_node_execpath);
|
|
46550
|
-
addNodeCandidatesFromPath(process.env.PATH, addCandidate);
|
|
46551
|
-
addNodeCandidatesFromNvm(os17.homedir(), addCandidate);
|
|
46552
|
-
addCandidate("/opt/homebrew/bin/node");
|
|
46553
|
-
addCandidate("/usr/local/bin/node");
|
|
46554
|
-
addCandidate("/usr/bin/node");
|
|
46555
|
-
addCandidate(process.execPath);
|
|
46556
|
-
for (const candidate of candidates) {
|
|
46557
|
-
if (nodeRuntimeSupportsWebSocket(candidate)) return candidate;
|
|
46558
|
-
}
|
|
46559
|
-
return null;
|
|
46560
|
-
}
|
|
46561
|
-
function addNodeCandidatesFromPath(pathValue, addCandidate) {
|
|
46562
|
-
for (const entry of (pathValue || "").split(":")) {
|
|
46563
|
-
const dir = entry.trim();
|
|
46564
|
-
if (!dir) continue;
|
|
46565
|
-
addCandidate((0, import_node_path.join)(dir, "node"));
|
|
46566
|
-
}
|
|
46567
|
-
}
|
|
46568
|
-
function addNodeCandidatesFromNvm(homeDir, addCandidate) {
|
|
46569
|
-
const versionsDir = (0, import_node_path.join)(homeDir, ".nvm", "versions", "node");
|
|
46570
|
-
try {
|
|
46571
|
-
const versionDirs = (0, import_node_fs3.readdirSync)(versionsDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort(compareNodeVersionNamesDescending);
|
|
46572
|
-
for (const versionDir of versionDirs) {
|
|
46573
|
-
addCandidate((0, import_node_path.join)(versionsDir, versionDir, "bin", "node"));
|
|
46574
|
-
}
|
|
46575
|
-
} catch {
|
|
46576
|
-
}
|
|
46577
|
-
}
|
|
46578
|
-
function compareNodeVersionNamesDescending(a, b) {
|
|
46579
|
-
const parse3 = (value) => value.replace(/^v/, "").split(".").map((part) => Number.parseInt(part, 10) || 0);
|
|
46580
|
-
const left = parse3(a);
|
|
46581
|
-
const right = parse3(b);
|
|
46582
|
-
for (let i = 0; i < Math.max(left.length, right.length); i++) {
|
|
46583
|
-
const diff = (right[i] || 0) - (left[i] || 0);
|
|
46584
|
-
if (diff !== 0) return diff;
|
|
46585
|
-
}
|
|
46586
|
-
return b.localeCompare(a);
|
|
46587
|
-
}
|
|
46588
|
-
function nodeRuntimeSupportsWebSocket(nodeExecutable) {
|
|
46589
|
-
try {
|
|
46590
|
-
(0, import_node_child_process3.execFileSync)(nodeExecutable, ["-e", "process.exit(typeof WebSocket === 'function' ? 0 : 42)"], {
|
|
46591
|
-
stdio: "ignore",
|
|
46592
|
-
timeout: 3e3
|
|
46593
|
-
});
|
|
46594
|
-
return true;
|
|
46595
|
-
} catch {
|
|
46596
|
-
return false;
|
|
46597
|
-
}
|
|
46598
|
-
}
|
|
46599
|
-
function resolveAdhdevMcpEntryPath(explicitPath) {
|
|
46600
|
-
const explicit = explicitPath?.trim();
|
|
46601
|
-
if (explicit) return normalizeExistingPath(explicit) || explicit;
|
|
46602
|
-
const envPath = process.env.ADHDEV_MCP_SERVER_PATH?.trim();
|
|
46603
|
-
if (envPath) return normalizeExistingPath(envPath) || envPath;
|
|
46604
|
-
const candidates = [];
|
|
46605
|
-
const addCandidate = (candidate) => {
|
|
46606
|
-
if (!candidates.includes(candidate)) candidates.push(candidate);
|
|
46607
|
-
};
|
|
46608
|
-
const addPackagedCandidates = (baseFile) => {
|
|
46609
|
-
if (!baseFile) return;
|
|
46610
|
-
const realBase = normalizeExistingPath(baseFile) || baseFile;
|
|
46611
|
-
const dir = (0, import_node_path.dirname)(realBase);
|
|
46612
|
-
addCandidate((0, import_node_path.resolve)(dir, "../vendor/mcp-server/index.js"));
|
|
46613
|
-
addCandidate((0, import_node_path.resolve)(dir, "../../vendor/mcp-server/index.js"));
|
|
46614
|
-
addCandidate((0, import_node_path.resolve)(dir, "../../../vendor/mcp-server/index.js"));
|
|
46615
|
-
addCandidate((0, import_node_path.resolve)(dir, "../../mcp-server/dist/index.js"));
|
|
46616
|
-
addCandidate((0, import_node_path.resolve)(dir, "../../../mcp-server/dist/index.js"));
|
|
46617
|
-
};
|
|
46618
|
-
addPackagedCandidates(process.argv[1]);
|
|
46619
|
-
for (const candidate of candidates) {
|
|
46620
|
-
const normalized = normalizeExistingPath(candidate);
|
|
46621
|
-
if (normalized) return normalized;
|
|
46622
|
-
}
|
|
46623
|
-
try {
|
|
46624
|
-
const requireBase = process.argv[1] ? normalizeExistingPath(process.argv[1]) || process.argv[1] : (0, import_node_path.join)(process.cwd(), "adhdev-daemon.js");
|
|
46625
|
-
const req = (0, import_node_module2.createRequire)(requireBase);
|
|
46626
|
-
const resolvedModule = req.resolve("@adhdev/mcp-server");
|
|
46627
|
-
return normalizeExistingPath(resolvedModule) || resolvedModule;
|
|
46628
|
-
} catch {
|
|
46629
|
-
return null;
|
|
46630
|
-
}
|
|
46631
|
-
}
|
|
46632
|
-
function normalizeExistingPath(filePath) {
|
|
46633
|
-
try {
|
|
46634
|
-
if (!(0, import_node_fs3.existsSync)(filePath)) return null;
|
|
46635
|
-
return import_node_fs3.realpathSync.native(filePath);
|
|
46636
|
-
} catch {
|
|
46637
|
-
return null;
|
|
46638
|
-
}
|
|
46639
|
-
}
|
|
46640
47534
|
init_mesh_events();
|
|
46641
47535
|
init_mesh_host_ownership();
|
|
46642
47536
|
var os18 = __toESM2(require("os"));
|
|
@@ -46950,23 +47844,23 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
46950
47844
|
}
|
|
46951
47845
|
};
|
|
46952
47846
|
}
|
|
47847
|
+
var import_child_process7 = require("child_process");
|
|
46953
47848
|
var import_child_process8 = require("child_process");
|
|
46954
|
-
var
|
|
46955
|
-
var fs9 = __toESM2(require("fs"));
|
|
47849
|
+
var fs10 = __toESM2(require("fs"));
|
|
46956
47850
|
var os19 = __toESM2(require("os"));
|
|
46957
47851
|
var path222 = __toESM2(require("path"));
|
|
46958
47852
|
var UPGRADE_HELPER_ENV = "ADHDEV_DAEMON_UPGRADE_HELPER";
|
|
46959
47853
|
function getUpgradeLogPath() {
|
|
46960
47854
|
const home = os19.homedir();
|
|
46961
47855
|
const dir = path222.join(home, ".adhdev");
|
|
46962
|
-
|
|
47856
|
+
fs10.mkdirSync(dir, { recursive: true });
|
|
46963
47857
|
return path222.join(dir, "daemon-upgrade.log");
|
|
46964
47858
|
}
|
|
46965
47859
|
function appendUpgradeLog(message) {
|
|
46966
47860
|
const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${message}
|
|
46967
47861
|
`;
|
|
46968
47862
|
try {
|
|
46969
|
-
|
|
47863
|
+
fs10.appendFileSync(getUpgradeLogPath(), line, "utf8");
|
|
46970
47864
|
} catch {
|
|
46971
47865
|
}
|
|
46972
47866
|
}
|
|
@@ -46974,12 +47868,12 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
46974
47868
|
const binDir = path222.dirname(nodeExecutable);
|
|
46975
47869
|
if (platform10 === "win32") {
|
|
46976
47870
|
const npmCliPath = path222.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
|
|
46977
|
-
if (
|
|
47871
|
+
if (fs10.existsSync(npmCliPath)) {
|
|
46978
47872
|
return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
|
|
46979
47873
|
}
|
|
46980
47874
|
for (const candidate of ["npm.exe", "npm"]) {
|
|
46981
47875
|
const candidatePath = path222.join(binDir, candidate);
|
|
46982
|
-
if (
|
|
47876
|
+
if (fs10.existsSync(candidatePath)) {
|
|
46983
47877
|
return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
|
|
46984
47878
|
}
|
|
46985
47879
|
}
|
|
@@ -46987,7 +47881,7 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
46987
47881
|
}
|
|
46988
47882
|
for (const candidate of ["npm"]) {
|
|
46989
47883
|
const candidatePath = path222.join(binDir, candidate);
|
|
46990
|
-
if (
|
|
47884
|
+
if (fs10.existsSync(candidatePath)) {
|
|
46991
47885
|
return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
|
|
46992
47886
|
}
|
|
46993
47887
|
}
|
|
@@ -46997,12 +47891,12 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
46997
47891
|
if (!currentCliPath) return null;
|
|
46998
47892
|
let resolvedPath = currentCliPath;
|
|
46999
47893
|
try {
|
|
47000
|
-
resolvedPath =
|
|
47894
|
+
resolvedPath = fs10.realpathSync.native(currentCliPath);
|
|
47001
47895
|
} catch {
|
|
47002
47896
|
}
|
|
47003
47897
|
let currentDir = resolvedPath;
|
|
47004
47898
|
try {
|
|
47005
|
-
if (
|
|
47899
|
+
if (fs10.statSync(resolvedPath).isFile()) {
|
|
47006
47900
|
currentDir = path222.dirname(resolvedPath);
|
|
47007
47901
|
}
|
|
47008
47902
|
} catch {
|
|
@@ -47011,8 +47905,8 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
47011
47905
|
while (true) {
|
|
47012
47906
|
const packageJsonPath = path222.join(currentDir, "package.json");
|
|
47013
47907
|
try {
|
|
47014
|
-
if (
|
|
47015
|
-
const parsed = JSON.parse(
|
|
47908
|
+
if (fs10.existsSync(packageJsonPath)) {
|
|
47909
|
+
const parsed = JSON.parse(fs10.readFileSync(packageJsonPath, "utf8"));
|
|
47016
47910
|
if (parsed?.name === packageName) {
|
|
47017
47911
|
const normalized = currentDir.replace(/\\/g, "/");
|
|
47018
47912
|
return normalized.includes("/node_modules/") ? currentDir : null;
|
|
@@ -47070,7 +47964,7 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
47070
47964
|
}
|
|
47071
47965
|
function execNpmCommandSync(args, options = {}, surface) {
|
|
47072
47966
|
const execOptions = surface?.execOptions || getNpmExecOptions();
|
|
47073
|
-
return (0,
|
|
47967
|
+
return (0, import_child_process7.execFileSync)(
|
|
47074
47968
|
surface?.npmExecutable || "npm",
|
|
47075
47969
|
[...surface?.npmArgsPrefix || [], ...args],
|
|
47076
47970
|
{
|
|
@@ -47083,7 +47977,7 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
47083
47977
|
function killPid2(pid) {
|
|
47084
47978
|
try {
|
|
47085
47979
|
if (process.platform === "win32") {
|
|
47086
|
-
(0,
|
|
47980
|
+
(0, import_child_process7.execFileSync)("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true });
|
|
47087
47981
|
} else {
|
|
47088
47982
|
process.kill(pid, "SIGTERM");
|
|
47089
47983
|
}
|
|
@@ -47095,7 +47989,7 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
47095
47989
|
function getWindowsProcessCommandLine(pid) {
|
|
47096
47990
|
const pidFilter = `ProcessId=${pid}`;
|
|
47097
47991
|
try {
|
|
47098
|
-
const psOut = (0,
|
|
47992
|
+
const psOut = (0, import_child_process7.execFileSync)("powershell.exe", [
|
|
47099
47993
|
"-NoProfile",
|
|
47100
47994
|
"-NonInteractive",
|
|
47101
47995
|
"-ExecutionPolicy",
|
|
@@ -47107,7 +48001,7 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
47107
48001
|
} catch {
|
|
47108
48002
|
}
|
|
47109
48003
|
try {
|
|
47110
|
-
const wmicOut = (0,
|
|
48004
|
+
const wmicOut = (0, import_child_process7.execFileSync)("wmic", [
|
|
47111
48005
|
"process",
|
|
47112
48006
|
"where",
|
|
47113
48007
|
pidFilter,
|
|
@@ -47123,7 +48017,7 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
47123
48017
|
if (!Number.isFinite(pid) || pid <= 0) return null;
|
|
47124
48018
|
if (process.platform === "win32") return getWindowsProcessCommandLine(pid);
|
|
47125
48019
|
try {
|
|
47126
|
-
const text = (0,
|
|
48020
|
+
const text = (0, import_child_process7.execFileSync)("ps", ["-o", "command=", "-p", String(pid)], {
|
|
47127
48021
|
encoding: "utf8",
|
|
47128
48022
|
timeout: 3e3,
|
|
47129
48023
|
stdio: ["ignore", "pipe", "ignore"]
|
|
@@ -47151,8 +48045,8 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
47151
48045
|
function stopSessionHostProcesses(appName) {
|
|
47152
48046
|
const pidFile = path222.join(os19.homedir(), ".adhdev", `${appName}-session-host.pid`);
|
|
47153
48047
|
try {
|
|
47154
|
-
if (
|
|
47155
|
-
const pid = Number.parseInt(
|
|
48048
|
+
if (fs10.existsSync(pidFile)) {
|
|
48049
|
+
const pid = Number.parseInt(fs10.readFileSync(pidFile, "utf8").trim(), 10);
|
|
47156
48050
|
if (Number.isFinite(pid) && pid !== process.pid && isManagedSessionHostPid(pid)) {
|
|
47157
48051
|
killPid2(pid);
|
|
47158
48052
|
}
|
|
@@ -47160,7 +48054,7 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
47160
48054
|
} catch {
|
|
47161
48055
|
} finally {
|
|
47162
48056
|
try {
|
|
47163
|
-
|
|
48057
|
+
fs10.unlinkSync(pidFile);
|
|
47164
48058
|
} catch {
|
|
47165
48059
|
}
|
|
47166
48060
|
}
|
|
@@ -47168,7 +48062,7 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
47168
48062
|
function removeDaemonPidFile() {
|
|
47169
48063
|
const pidFile = path222.join(os19.homedir(), ".adhdev", "daemon.pid");
|
|
47170
48064
|
try {
|
|
47171
|
-
|
|
48065
|
+
fs10.unlinkSync(pidFile);
|
|
47172
48066
|
} catch {
|
|
47173
48067
|
}
|
|
47174
48068
|
}
|
|
@@ -47186,30 +48080,30 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
47186
48080
|
if (pkgName.startsWith("@")) {
|
|
47187
48081
|
const [scope, name] = pkgName.split("/");
|
|
47188
48082
|
const scopeDir = path222.join(npmRoot, scope);
|
|
47189
|
-
if (!
|
|
47190
|
-
for (const entry of
|
|
48083
|
+
if (!fs10.existsSync(scopeDir)) return;
|
|
48084
|
+
for (const entry of fs10.readdirSync(scopeDir)) {
|
|
47191
48085
|
if (!entry.startsWith(`.${name}-`)) continue;
|
|
47192
|
-
|
|
48086
|
+
fs10.rmSync(path222.join(scopeDir, entry), { recursive: true, force: true });
|
|
47193
48087
|
appendUpgradeLog(`Removed stale scoped staging dir: ${path222.join(scopeDir, entry)}`);
|
|
47194
48088
|
}
|
|
47195
48089
|
} else {
|
|
47196
|
-
for (const entry of
|
|
48090
|
+
for (const entry of fs10.readdirSync(npmRoot)) {
|
|
47197
48091
|
if (!entry.startsWith(`.${pkgName}-`)) continue;
|
|
47198
|
-
|
|
48092
|
+
fs10.rmSync(path222.join(npmRoot, entry), { recursive: true, force: true });
|
|
47199
48093
|
appendUpgradeLog(`Removed stale staging dir: ${path222.join(npmRoot, entry)}`);
|
|
47200
48094
|
}
|
|
47201
48095
|
}
|
|
47202
|
-
if (
|
|
47203
|
-
for (const entry of
|
|
48096
|
+
if (fs10.existsSync(binDir)) {
|
|
48097
|
+
for (const entry of fs10.readdirSync(binDir)) {
|
|
47204
48098
|
if (!Array.from(binNames).some((name) => entry.startsWith(`.${name}-`))) continue;
|
|
47205
|
-
|
|
48099
|
+
fs10.rmSync(path222.join(binDir, entry), { recursive: true, force: true });
|
|
47206
48100
|
appendUpgradeLog(`Removed stale bin staging entry: ${path222.join(binDir, entry)}`);
|
|
47207
48101
|
}
|
|
47208
48102
|
}
|
|
47209
48103
|
}
|
|
47210
48104
|
function spawnDetachedDaemonUpgradeHelper(payload) {
|
|
47211
48105
|
const env2 = { ...process.env, [UPGRADE_HELPER_ENV]: JSON.stringify(payload) };
|
|
47212
|
-
const child = (0,
|
|
48106
|
+
const child = (0, import_child_process8.spawn)(process.execPath, process.argv.slice(1), {
|
|
47213
48107
|
detached: true,
|
|
47214
48108
|
stdio: "ignore",
|
|
47215
48109
|
windowsHide: true,
|
|
@@ -47239,7 +48133,7 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
47239
48133
|
cleanupStaleGlobalInstallDirs(payload.packageName, installCommand.surface);
|
|
47240
48134
|
const spec = `${payload.packageName}@${payload.targetVersion || "latest"}`;
|
|
47241
48135
|
appendUpgradeLog(`Installing ${spec}`);
|
|
47242
|
-
const installOutput = (0,
|
|
48136
|
+
const installOutput = (0, import_child_process7.execFileSync)(
|
|
47243
48137
|
installCommand.command,
|
|
47244
48138
|
installCommand.args,
|
|
47245
48139
|
{
|
|
@@ -47261,7 +48155,7 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
47261
48155
|
const env2 = { ...process.env };
|
|
47262
48156
|
delete env2[UPGRADE_HELPER_ENV];
|
|
47263
48157
|
appendUpgradeLog(`Restarting daemon with args: ${restartArgv.join(" ")}`);
|
|
47264
|
-
const child = (0,
|
|
48158
|
+
const child = (0, import_child_process8.spawn)(process.execPath, restartArgv, {
|
|
47265
48159
|
detached: true,
|
|
47266
48160
|
stdio: "ignore",
|
|
47267
48161
|
windowsHide: true,
|
|
@@ -47286,9 +48180,10 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
47286
48180
|
process.exit(1);
|
|
47287
48181
|
}
|
|
47288
48182
|
}
|
|
48183
|
+
init_mesh_work_queue();
|
|
47289
48184
|
var import_os3 = require("os");
|
|
47290
48185
|
var import_path8 = require("path");
|
|
47291
|
-
var
|
|
48186
|
+
var fs11 = __toESM2(require("fs"));
|
|
47292
48187
|
var CHANNEL_NPM_TAG = { stable: "latest", preview: "next" };
|
|
47293
48188
|
var CHANNEL_SERVER_URL = {
|
|
47294
48189
|
stable: "https://api.adhf.dev",
|
|
@@ -47932,7 +48827,7 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
47932
48827
|
if (!isSelfNode && daemonId) unavailableNodeIds.push(nodeId);
|
|
47933
48828
|
continue;
|
|
47934
48829
|
}
|
|
47935
|
-
if (
|
|
48830
|
+
if (fs11.existsSync(workspace)) {
|
|
47936
48831
|
try {
|
|
47937
48832
|
const localGit = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
|
|
47938
48833
|
if (localGit?.isGitRepo) {
|
|
@@ -48099,14 +48994,14 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
48099
48994
|
});
|
|
48100
48995
|
}
|
|
48101
48996
|
async function computeGitPatchId(cwd, fromRef, toRef) {
|
|
48102
|
-
const { execFileSync:
|
|
48103
|
-
const diff =
|
|
48997
|
+
const { execFileSync: execFileSync3 } = await import("child_process");
|
|
48998
|
+
const diff = execFileSync3("git", ["diff", "--patch", "--full-index", fromRef, toRef], {
|
|
48104
48999
|
cwd,
|
|
48105
49000
|
encoding: "utf8",
|
|
48106
49001
|
maxBuffer: REFINE_PATCH_EQUIVALENCE_OUTPUT_LIMIT_BYTES
|
|
48107
49002
|
});
|
|
48108
49003
|
if (!diff.trim()) return "";
|
|
48109
|
-
const patchId =
|
|
49004
|
+
const patchId = execFileSync3("git", ["patch-id", "--stable"], {
|
|
48110
49005
|
cwd,
|
|
48111
49006
|
input: diff,
|
|
48112
49007
|
encoding: "utf8",
|
|
@@ -48117,8 +49012,8 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
48117
49012
|
async function runMeshRefinePatchEquivalenceGate(repoRoot, baseHead, branchHead) {
|
|
48118
49013
|
const startedAt = Date.now();
|
|
48119
49014
|
try {
|
|
48120
|
-
const { execFileSync:
|
|
48121
|
-
const git = (args) =>
|
|
49015
|
+
const { execFileSync: execFileSync3 } = await import("child_process");
|
|
49016
|
+
const git = (args) => execFileSync3("git", args, {
|
|
48122
49017
|
cwd: repoRoot,
|
|
48123
49018
|
encoding: "utf8",
|
|
48124
49019
|
maxBuffer: REFINE_PATCH_EQUIVALENCE_OUTPUT_LIMIT_BYTES
|
|
@@ -48171,8 +49066,8 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
48171
49066
|
const entries = [];
|
|
48172
49067
|
try {
|
|
48173
49068
|
const { execFile: execFile3 } = await import("child_process");
|
|
48174
|
-
const { promisify:
|
|
48175
|
-
const execFileAsync3 =
|
|
49069
|
+
const { promisify: promisify6 } = await import("util");
|
|
49070
|
+
const execFileAsync3 = promisify6(execFile3);
|
|
48176
49071
|
const runGit2 = async (cwd, args) => {
|
|
48177
49072
|
const { stdout } = await execFileAsync3("git", args, {
|
|
48178
49073
|
cwd,
|
|
@@ -48196,7 +49091,7 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
48196
49091
|
reachable: false
|
|
48197
49092
|
};
|
|
48198
49093
|
try {
|
|
48199
|
-
if (!
|
|
49094
|
+
if (!fs11.existsSync(submodulePath)) {
|
|
48200
49095
|
entry.error = `Submodule checkout missing at ${gitlink.path}`;
|
|
48201
49096
|
entries.push(entry);
|
|
48202
49097
|
continue;
|
|
@@ -48262,8 +49157,8 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
48262
49157
|
}
|
|
48263
49158
|
async function runMeshRefineValidationGate(mesh, workspace) {
|
|
48264
49159
|
const { execFile: execFile3 } = await import("child_process");
|
|
48265
|
-
const { promisify:
|
|
48266
|
-
const execFileAsync3 =
|
|
49160
|
+
const { promisify: promisify6 } = await import("util");
|
|
49161
|
+
const execFileAsync3 = promisify6(execFile3);
|
|
48267
49162
|
const selection = resolveMeshRefineValidationPlan(mesh, workspace);
|
|
48268
49163
|
const summary = {
|
|
48269
49164
|
status: "skipped",
|
|
@@ -48353,9 +49248,9 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
48353
49248
|
function loadHermesCoordinatorBaseConfig(targetConfigPath) {
|
|
48354
49249
|
const sourceHome = resolveHermesUserHome();
|
|
48355
49250
|
const sourceConfigPath = (0, import_path8.join)(sourceHome, "config.yaml");
|
|
48356
|
-
if (!
|
|
49251
|
+
if (!fs11.existsSync(sourceConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
48357
49252
|
if ((0, import_path8.resolve)(sourceConfigPath) === (0, import_path8.resolve)(targetConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
48358
|
-
const parsed = parseMeshCoordinatorMcpConfig(
|
|
49253
|
+
const parsed = parseMeshCoordinatorMcpConfig(fs11.readFileSync(sourceConfigPath, "utf-8"), "hermes_config_yaml");
|
|
48359
49254
|
const { mcp_servers: _mcpServers, ...baseConfig } = parsed;
|
|
48360
49255
|
return { config: baseConfig, sourceHome, sourceConfigPath };
|
|
48361
49256
|
}
|
|
@@ -48392,9 +49287,9 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
48392
49287
|
for (const fileName of [".env", "auth.json"]) {
|
|
48393
49288
|
const sourcePath = (0, import_path8.join)(sourceHome, fileName);
|
|
48394
49289
|
const targetPath = (0, import_path8.join)(targetHome, fileName);
|
|
48395
|
-
if (!
|
|
49290
|
+
if (!fs11.existsSync(sourcePath)) continue;
|
|
48396
49291
|
try {
|
|
48397
|
-
|
|
49292
|
+
fs11.copyFileSync(sourcePath, targetPath);
|
|
48398
49293
|
} catch (error48) {
|
|
48399
49294
|
LOG2.warn("MeshCoordinator", `Could not copy Hermes ${fileName} into isolated coordinator home: ${error48?.message || error48}`);
|
|
48400
49295
|
}
|
|
@@ -48607,6 +49502,7 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
48607
49502
|
getCachedAggregateMeshStatus(meshId, mesh, options) {
|
|
48608
49503
|
const cached2 = this.aggregateMeshStatusCache.get(meshId);
|
|
48609
49504
|
if (!cached2?.snapshot || cached2.snapshot.success !== true || !Array.isArray(cached2.snapshot.nodes)) return null;
|
|
49505
|
+
if (cached2.queueRevision !== getMeshQueueRevision(meshId)) return null;
|
|
48610
49506
|
let snapshot = this.cloneJsonValue(cached2.snapshot);
|
|
48611
49507
|
snapshot = this.hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options);
|
|
48612
49508
|
if (shouldRefreshStalePendingAggregate(snapshot, options)) return null;
|
|
@@ -48644,7 +49540,7 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
48644
49540
|
returnedAt: new Date(builtAt).toISOString()
|
|
48645
49541
|
}
|
|
48646
49542
|
};
|
|
48647
|
-
this.aggregateMeshStatusCache.set(meshId, { builtAt, snapshot: this.cloneJsonValue(next) });
|
|
49543
|
+
this.aggregateMeshStatusCache.set(meshId, { builtAt, snapshot: this.cloneJsonValue(next), queueRevision: getMeshQueueRevision(meshId) });
|
|
48648
49544
|
return next;
|
|
48649
49545
|
}
|
|
48650
49546
|
getCachedInlineMesh(meshId, inlineMesh) {
|
|
@@ -48747,13 +49643,13 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
48747
49643
|
recoveryHint: "Inspect the mesh node record before removing it, or remove stale metadata manually only after confirming no managed worktree remains."
|
|
48748
49644
|
};
|
|
48749
49645
|
}
|
|
48750
|
-
const worktreeExists =
|
|
49646
|
+
const worktreeExists = fs11.existsSync(workspace);
|
|
48751
49647
|
const sourceNode = args.node?.clonedFromNodeId ? args.mesh?.nodes?.find((n) => n.id === args.node.clonedFromNodeId || n.nodeId === args.node.clonedFromNodeId) : args.mesh?.nodes?.find((n) => !n.isLocalWorktree);
|
|
48752
49648
|
const repoRoot = typeof sourceNode?.repoRoot === "string" && sourceNode.repoRoot.trim() ? sourceNode.repoRoot.trim() : typeof sourceNode?.workspace === "string" && sourceNode.workspace.trim() ? sourceNode.workspace.trim() : "";
|
|
48753
49649
|
if (!worktreeExists) {
|
|
48754
49650
|
return { success: true, skipped: true, removedPath: workspace, repoRoot: repoRoot || void 0, reason: "worktree_path_missing" };
|
|
48755
49651
|
}
|
|
48756
|
-
if (!repoRoot || !
|
|
49652
|
+
if (!repoRoot || !fs11.existsSync(repoRoot)) {
|
|
48757
49653
|
return {
|
|
48758
49654
|
success: false,
|
|
48759
49655
|
code: "mesh_worktree_cleanup_missing_source_repo",
|
|
@@ -48773,7 +49669,7 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
48773
49669
|
const normalizePath = (value) => {
|
|
48774
49670
|
const resolved = (0, import_path8.resolve)(value);
|
|
48775
49671
|
try {
|
|
48776
|
-
return
|
|
49672
|
+
return fs11.realpathSync(resolved);
|
|
48777
49673
|
} catch {
|
|
48778
49674
|
return resolved;
|
|
48779
49675
|
}
|
|
@@ -48846,8 +49742,8 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
48846
49742
|
return { allow: true, status: metadataStatus, source: "node_branch_convergence" };
|
|
48847
49743
|
}
|
|
48848
49744
|
const { execFile: execFile3 } = await import("child_process");
|
|
48849
|
-
const { promisify:
|
|
48850
|
-
const execFileAsync3 =
|
|
49745
|
+
const { promisify: promisify6 } = await import("util");
|
|
49746
|
+
const execFileAsync3 = promisify6(execFile3);
|
|
48851
49747
|
const runGit2 = async (gitArgs, cwd) => {
|
|
48852
49748
|
const { stdout } = await execFileAsync3("git", gitArgs, {
|
|
48853
49749
|
cwd,
|
|
@@ -49257,8 +50153,8 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
49257
50153
|
const repoRoot = sourceNode?.repoRoot || sourceNode?.workspace;
|
|
49258
50154
|
if (!repoRoot) return { success: false, error: "Source node repoRoot not found", refineStages };
|
|
49259
50155
|
const { execFile: execFile3 } = await import("child_process");
|
|
49260
|
-
const { promisify:
|
|
49261
|
-
const execFileAsync3 =
|
|
50156
|
+
const { promisify: promisify6 } = await import("util");
|
|
50157
|
+
const execFileAsync3 = promisify6(execFile3);
|
|
49262
50158
|
const resolveStarted = Date.now();
|
|
49263
50159
|
const { stdout: branchStdout } = await execFileAsync3("git", ["branch", "--show-current"], { cwd: node.workspace, encoding: "utf8" });
|
|
49264
50160
|
const branch = branchStdout.trim();
|
|
@@ -49567,8 +50463,8 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
49567
50463
|
if (sinceTs > 0) {
|
|
49568
50464
|
return { success: true, logs: [], totalBuffered: 0 };
|
|
49569
50465
|
}
|
|
49570
|
-
if (
|
|
49571
|
-
const content =
|
|
50466
|
+
if (fs11.existsSync(LOG_PATH)) {
|
|
50467
|
+
const content = fs11.readFileSync(LOG_PATH, "utf-8");
|
|
49572
50468
|
const allLines = content.split("\n");
|
|
49573
50469
|
const recent = allLines.slice(-count).join("\n");
|
|
49574
50470
|
return { success: true, logs: recent, totalLines: allLines.length };
|
|
@@ -50991,7 +51887,7 @@ ${block2}`);
|
|
|
50991
51887
|
workspace
|
|
50992
51888
|
};
|
|
50993
51889
|
}
|
|
50994
|
-
const { existsSync:
|
|
51890
|
+
const { existsSync: existsSync26, readFileSync: readFileSync19, writeFileSync: writeFileSync14, copyFileSync: copyFileSync4, mkdirSync: mkdirSync18 } = await import("fs");
|
|
50995
51891
|
const { dirname: dirname9 } = await import("path");
|
|
50996
51892
|
const mcpConfigPath = coordinatorSetup.configPath;
|
|
50997
51893
|
const hermesManualFallback = cliType === "hermes-cli" && configFormat === "hermes_config_yaml" ? createHermesManualMeshCoordinatorSetup(meshId, workspace) : null;
|
|
@@ -51027,14 +51923,14 @@ ${block2}`);
|
|
|
51027
51923
|
};
|
|
51028
51924
|
}
|
|
51029
51925
|
try {
|
|
51030
|
-
|
|
51926
|
+
mkdirSync18(dirname9(mcpConfigPath), { recursive: true });
|
|
51031
51927
|
} catch (error48) {
|
|
51032
51928
|
const message = `Could not prepare MCP config path for automatic setup: ${error48?.message || error48}`;
|
|
51033
51929
|
LOG2.error("MeshCoordinator", message);
|
|
51034
51930
|
if (hermesManualFallback) return returnManualFallback(message);
|
|
51035
51931
|
return { success: false, code: "mesh_coordinator_config_write_failed", error: message, meshId, cliType, workspace };
|
|
51036
51932
|
}
|
|
51037
|
-
const hadExistingMcpConfig =
|
|
51933
|
+
const hadExistingMcpConfig = existsSync26(mcpConfigPath);
|
|
51038
51934
|
let existingMcpConfig = hermesBaseConfig?.config || {};
|
|
51039
51935
|
if (hermesBaseConfig) {
|
|
51040
51936
|
copyHermesCoordinatorCredentialFiles(hermesBaseConfig.sourceHome, dirname9(mcpConfigPath));
|
|
@@ -51064,7 +51960,7 @@ ${block2}`);
|
|
|
51064
51960
|
}
|
|
51065
51961
|
};
|
|
51066
51962
|
try {
|
|
51067
|
-
|
|
51963
|
+
writeFileSync14(mcpConfigPath, serializeMeshCoordinatorMcpConfig(mcpConfig, configFormat), "utf-8");
|
|
51068
51964
|
} catch (error48) {
|
|
51069
51965
|
const message = `Could not write MCP config for automatic setup: ${error48?.message || error48}`;
|
|
51070
51966
|
LOG2.error("MeshCoordinator", message);
|
|
@@ -51292,7 +52188,7 @@ ${block2}`);
|
|
|
51292
52188
|
}
|
|
51293
52189
|
}
|
|
51294
52190
|
if (workspace) {
|
|
51295
|
-
if (!
|
|
52191
|
+
if (!fs11.existsSync(workspace)) {
|
|
51296
52192
|
const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
|
|
51297
52193
|
let remoteProbeApplied = false;
|
|
51298
52194
|
if (inlineTransitGit) {
|
|
@@ -51501,7 +52397,7 @@ ${block2}`);
|
|
|
51501
52397
|
}
|
|
51502
52398
|
}
|
|
51503
52399
|
if (killProcess) {
|
|
51504
|
-
const running = isIdeRunning(ideType);
|
|
52400
|
+
const running = await isIdeRunning(ideType);
|
|
51505
52401
|
if (running) {
|
|
51506
52402
|
LOG2.info("StopIDE", `Killing IDE process: ${ideType}`);
|
|
51507
52403
|
const killed = await killIdeProcess(ideType);
|
|
@@ -51525,6 +52421,8 @@ ${block2}`);
|
|
|
51525
52421
|
lastStatusSentAt = 0;
|
|
51526
52422
|
statusPendingThrottle = false;
|
|
51527
52423
|
lastP2PStatusHash = "";
|
|
52424
|
+
lastP2PStatusSentAt = 0;
|
|
52425
|
+
p2pDebounceTimer = null;
|
|
51528
52426
|
lastServerStatusHash = "";
|
|
51529
52427
|
lastStatusSummary = "";
|
|
51530
52428
|
statusTimer = null;
|
|
@@ -51776,7 +52674,18 @@ ${block2}`);
|
|
|
51776
52674
|
})() : { ...hashTarget, sessions };
|
|
51777
52675
|
const h = this.simpleHash(JSON.stringify(hashPayload));
|
|
51778
52676
|
if (h !== this.lastP2PStatusHash) {
|
|
52677
|
+
const now = Date.now();
|
|
52678
|
+
if (this.lastP2PStatusSentAt && now - this.lastP2PStatusSentAt < 500) {
|
|
52679
|
+
if (!this.p2pDebounceTimer) {
|
|
52680
|
+
this.p2pDebounceTimer = setTimeout(() => {
|
|
52681
|
+
this.p2pDebounceTimer = null;
|
|
52682
|
+
this.sendUnifiedStatusReport({ reason: "p2p_debounce" });
|
|
52683
|
+
}, 500);
|
|
52684
|
+
}
|
|
52685
|
+
return false;
|
|
52686
|
+
}
|
|
51779
52687
|
this.lastP2PStatusHash = h;
|
|
52688
|
+
this.lastP2PStatusSentAt = now;
|
|
51780
52689
|
this.deps.p2p?.sendStatus(payload);
|
|
51781
52690
|
return true;
|
|
51782
52691
|
}
|
|
@@ -53091,11 +54000,11 @@ ${block2}`);
|
|
|
53091
54000
|
this.eventListeners = [];
|
|
53092
54001
|
}
|
|
53093
54002
|
};
|
|
53094
|
-
var
|
|
54003
|
+
var fs12 = __toESM2(require("fs"));
|
|
53095
54004
|
var path232 = __toESM2(require("path"));
|
|
53096
54005
|
var os20 = __toESM2(require("os"));
|
|
53097
|
-
var import_child_process10 = require("child_process");
|
|
53098
54006
|
var import_os4 = require("os");
|
|
54007
|
+
var import_child_process9 = require("child_process");
|
|
53099
54008
|
var ARCHIVE_PATH = path232.join(os20.homedir(), ".adhdev", "version-history.json");
|
|
53100
54009
|
var MAX_ENTRIES_PER_PROVIDER = 20;
|
|
53101
54010
|
var VersionArchive = class {
|
|
@@ -53105,8 +54014,8 @@ ${block2}`);
|
|
|
53105
54014
|
}
|
|
53106
54015
|
load() {
|
|
53107
54016
|
try {
|
|
53108
|
-
if (
|
|
53109
|
-
this.history = JSON.parse(
|
|
54017
|
+
if (fs12.existsSync(ARCHIVE_PATH)) {
|
|
54018
|
+
this.history = JSON.parse(fs12.readFileSync(ARCHIVE_PATH, "utf-8"));
|
|
53110
54019
|
}
|
|
53111
54020
|
} catch {
|
|
53112
54021
|
this.history = {};
|
|
@@ -53143,27 +54052,43 @@ ${block2}`);
|
|
|
53143
54052
|
}
|
|
53144
54053
|
save() {
|
|
53145
54054
|
try {
|
|
53146
|
-
|
|
53147
|
-
|
|
54055
|
+
fs12.mkdirSync(path232.dirname(ARCHIVE_PATH), { recursive: true });
|
|
54056
|
+
fs12.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
|
|
53148
54057
|
} catch {
|
|
53149
54058
|
}
|
|
53150
54059
|
}
|
|
53151
54060
|
};
|
|
53152
|
-
function runCommand(cmd, timeout = 1e4) {
|
|
53153
|
-
|
|
53154
|
-
|
|
54061
|
+
async function runCommand(cmd, timeout = 1e4) {
|
|
54062
|
+
return new Promise((resolve16) => {
|
|
54063
|
+
(0, import_child_process9.exec)(cmd, {
|
|
53155
54064
|
encoding: "utf-8",
|
|
53156
|
-
timeout
|
|
53157
|
-
|
|
53158
|
-
|
|
53159
|
-
|
|
53160
|
-
|
|
53161
|
-
}
|
|
54065
|
+
timeout
|
|
54066
|
+
}, (error48, stdout) => {
|
|
54067
|
+
if (error48) return resolve16(null);
|
|
54068
|
+
resolve16(stdout.trim());
|
|
54069
|
+
});
|
|
54070
|
+
});
|
|
53162
54071
|
}
|
|
53163
54072
|
function findBinary2(name) {
|
|
53164
|
-
const
|
|
53165
|
-
const
|
|
53166
|
-
|
|
54073
|
+
const isWin = (0, import_os4.platform)() === "win32";
|
|
54074
|
+
const paths = (process.env.PATH || "").split(isWin ? ";" : ":");
|
|
54075
|
+
const exes = isWin ? [".exe", ".cmd", ".bat", ""] : [""];
|
|
54076
|
+
for (const p of paths) {
|
|
54077
|
+
if (!p) continue;
|
|
54078
|
+
for (const ext of exes) {
|
|
54079
|
+
const fullPath = path232.join(p, name + ext);
|
|
54080
|
+
try {
|
|
54081
|
+
if (fs12.existsSync(fullPath)) {
|
|
54082
|
+
const stat2 = fs12.statSync(fullPath);
|
|
54083
|
+
if (stat2.isFile() && (isWin || stat2.mode & 73)) {
|
|
54084
|
+
return fullPath;
|
|
54085
|
+
}
|
|
54086
|
+
}
|
|
54087
|
+
} catch {
|
|
54088
|
+
}
|
|
54089
|
+
}
|
|
54090
|
+
}
|
|
54091
|
+
return null;
|
|
53167
54092
|
}
|
|
53168
54093
|
function parseVersion2(raw) {
|
|
53169
54094
|
const match = raw.match(/v?(\d+\.\d+(?:\.\d+)?(?:-[a-zA-Z0-9.]+)?)/);
|
|
@@ -53185,13 +54110,13 @@ ${block2}`);
|
|
|
53185
54110
|
}
|
|
53186
54111
|
return void 0;
|
|
53187
54112
|
}
|
|
53188
|
-
function getVersion(binary, versionCommand) {
|
|
54113
|
+
async function getVersion(binary, versionCommand) {
|
|
53189
54114
|
if (versionCommand) {
|
|
53190
|
-
const raw = runCommand(versionCommand);
|
|
54115
|
+
const raw = await runCommand(versionCommand);
|
|
53191
54116
|
return raw ? parseVersion2(raw) : null;
|
|
53192
54117
|
}
|
|
53193
54118
|
for (const flag of ["--version", "-V", "-v"]) {
|
|
53194
|
-
const raw = runCommand(`"${binary}" ${flag}`);
|
|
54119
|
+
const raw = await runCommand(`"${binary}" ${flag}`);
|
|
53195
54120
|
if (raw && raw.length < 500) return parseVersion2(raw);
|
|
53196
54121
|
}
|
|
53197
54122
|
return null;
|
|
@@ -53201,18 +54126,18 @@ ${block2}`);
|
|
|
53201
54126
|
if (p.includes("*")) {
|
|
53202
54127
|
const home = os20.homedir();
|
|
53203
54128
|
const resolved = p.replace(/\*/g, home.split(path232.sep).pop() || "");
|
|
53204
|
-
if (
|
|
54129
|
+
if (fs12.existsSync(resolved)) return resolved;
|
|
53205
54130
|
} else {
|
|
53206
|
-
if (
|
|
54131
|
+
if (fs12.existsSync(p)) return p;
|
|
53207
54132
|
}
|
|
53208
54133
|
}
|
|
53209
54134
|
return null;
|
|
53210
54135
|
}
|
|
53211
|
-
function getMacAppVersion(appPath) {
|
|
54136
|
+
async function getMacAppVersion(appPath) {
|
|
53212
54137
|
if ((0, import_os4.platform)() !== "darwin" || !appPath.endsWith(".app")) return null;
|
|
53213
54138
|
const plistPath = path232.join(appPath, "Contents", "Info.plist");
|
|
53214
|
-
if (!
|
|
53215
|
-
const raw = runCommand(`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${plistPath}"`);
|
|
54139
|
+
if (!fs12.existsSync(plistPath)) return null;
|
|
54140
|
+
const raw = await runCommand(`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${plistPath}"`);
|
|
53216
54141
|
return raw || null;
|
|
53217
54142
|
}
|
|
53218
54143
|
async function detectAllVersions(loader, archive) {
|
|
@@ -53237,16 +54162,16 @@ ${block2}`);
|
|
|
53237
54162
|
let resolvedBin = cliBin;
|
|
53238
54163
|
if (!resolvedBin && appPath && currentOs === "darwin") {
|
|
53239
54164
|
const bundled = path232.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
|
|
53240
|
-
if (provider.cli &&
|
|
54165
|
+
if (provider.cli && fs12.existsSync(bundled)) resolvedBin = bundled;
|
|
53241
54166
|
}
|
|
53242
54167
|
info.installed = !!(appPath || resolvedBin);
|
|
53243
54168
|
info.path = appPath || null;
|
|
53244
54169
|
info.binary = resolvedBin || null;
|
|
53245
54170
|
if (resolvedBin) {
|
|
53246
|
-
info.version = getVersion(resolvedBin, versionCommand);
|
|
54171
|
+
info.version = await getVersion(resolvedBin, versionCommand);
|
|
53247
54172
|
}
|
|
53248
54173
|
if (!info.version && appPath) {
|
|
53249
|
-
info.version = getMacAppVersion(appPath);
|
|
54174
|
+
info.version = await getMacAppVersion(appPath);
|
|
53250
54175
|
}
|
|
53251
54176
|
} else if (provider.category === "cli" || provider.category === "acp") {
|
|
53252
54177
|
const bin = provider.binary || provider.spawn?.command || provider.cli || provider.type;
|
|
@@ -53254,7 +54179,7 @@ ${block2}`);
|
|
|
53254
54179
|
info.installed = !!binPath;
|
|
53255
54180
|
info.binary = binPath || null;
|
|
53256
54181
|
if (binPath) {
|
|
53257
|
-
info.version = getVersion(binPath, versionCommand);
|
|
54182
|
+
info.version = await getVersion(binPath, versionCommand);
|
|
53258
54183
|
}
|
|
53259
54184
|
} else if (provider.category === "extension") {
|
|
53260
54185
|
info.installed = false;
|
|
@@ -53274,7 +54199,7 @@ ${block2}`);
|
|
|
53274
54199
|
return results;
|
|
53275
54200
|
}
|
|
53276
54201
|
var http2 = __toESM2(require("http"));
|
|
53277
|
-
var
|
|
54202
|
+
var fs16 = __toESM2(require("fs"));
|
|
53278
54203
|
var path27 = __toESM2(require("path"));
|
|
53279
54204
|
init_config();
|
|
53280
54205
|
function generateFiles(type, name, category, opts = {}) {
|
|
@@ -53619,7 +54544,7 @@ async (params) => {
|
|
|
53619
54544
|
};
|
|
53620
54545
|
}
|
|
53621
54546
|
init_logger();
|
|
53622
|
-
var
|
|
54547
|
+
var fs13 = __toESM2(require("fs"));
|
|
53623
54548
|
var path24 = __toESM2(require("path"));
|
|
53624
54549
|
init_logger();
|
|
53625
54550
|
async function handleCdpEvaluate(ctx, req, res) {
|
|
@@ -53800,17 +54725,17 @@ async (params) => {
|
|
|
53800
54725
|
}
|
|
53801
54726
|
let scriptsPath = "";
|
|
53802
54727
|
const directScripts = path24.join(dir, "scripts.js");
|
|
53803
|
-
if (
|
|
54728
|
+
if (fs13.existsSync(directScripts)) {
|
|
53804
54729
|
scriptsPath = directScripts;
|
|
53805
54730
|
} else {
|
|
53806
54731
|
const scriptsDir = path24.join(dir, "scripts");
|
|
53807
|
-
if (
|
|
53808
|
-
const versions =
|
|
53809
|
-
return
|
|
54732
|
+
if (fs13.existsSync(scriptsDir)) {
|
|
54733
|
+
const versions = fs13.readdirSync(scriptsDir).filter((d) => {
|
|
54734
|
+
return fs13.statSync(path24.join(scriptsDir, d)).isDirectory();
|
|
53810
54735
|
}).sort().reverse();
|
|
53811
54736
|
for (const ver of versions) {
|
|
53812
54737
|
const p = path24.join(scriptsDir, ver, "scripts.js");
|
|
53813
|
-
if (
|
|
54738
|
+
if (fs13.existsSync(p)) {
|
|
53814
54739
|
scriptsPath = p;
|
|
53815
54740
|
break;
|
|
53816
54741
|
}
|
|
@@ -53822,7 +54747,7 @@ async (params) => {
|
|
|
53822
54747
|
return;
|
|
53823
54748
|
}
|
|
53824
54749
|
try {
|
|
53825
|
-
const source =
|
|
54750
|
+
const source = fs13.readFileSync(scriptsPath, "utf-8");
|
|
53826
54751
|
const hints = {};
|
|
53827
54752
|
const funcRegex = /module\.exports\.(\w+)\s*=\s*function\s+\w+\s*\(params\)/g;
|
|
53828
54753
|
let match;
|
|
@@ -54635,7 +55560,7 @@ async (params) => {
|
|
|
54635
55560
|
ctx.json(res, 500, { error: `DOM context collection failed: ${e.message}` });
|
|
54636
55561
|
}
|
|
54637
55562
|
}
|
|
54638
|
-
var
|
|
55563
|
+
var fs14 = __toESM2(require("fs"));
|
|
54639
55564
|
var path25 = __toESM2(require("path"));
|
|
54640
55565
|
function slugifyFixtureName(value) {
|
|
54641
55566
|
const normalized = String(value || "").trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
@@ -54651,10 +55576,10 @@ async (params) => {
|
|
|
54651
55576
|
function readCliFixture(ctx, type, name) {
|
|
54652
55577
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
54653
55578
|
const filePath = path25.join(fixtureDir, `${name}.json`);
|
|
54654
|
-
if (!
|
|
55579
|
+
if (!fs14.existsSync(filePath)) {
|
|
54655
55580
|
throw new Error(`Fixture not found: ${filePath}`);
|
|
54656
55581
|
}
|
|
54657
|
-
return JSON.parse(
|
|
55582
|
+
return JSON.parse(fs14.readFileSync(filePath, "utf-8"));
|
|
54658
55583
|
}
|
|
54659
55584
|
function getExerciseTranscriptText(result) {
|
|
54660
55585
|
const parts = [];
|
|
@@ -55390,7 +56315,7 @@ async (params) => {
|
|
|
55390
56315
|
return;
|
|
55391
56316
|
}
|
|
55392
56317
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
55393
|
-
|
|
56318
|
+
fs14.mkdirSync(fixtureDir, { recursive: true });
|
|
55394
56319
|
const name = slugifyFixtureName(String(body?.name || `${type}-${Date.now()}`));
|
|
55395
56320
|
const result = await runCliExerciseInternal(ctx, { ...request, type });
|
|
55396
56321
|
const fixture = {
|
|
@@ -55418,7 +56343,7 @@ async (params) => {
|
|
|
55418
56343
|
notes: typeof body?.notes === "string" ? body.notes : void 0
|
|
55419
56344
|
};
|
|
55420
56345
|
const filePath = path25.join(fixtureDir, `${name}.json`);
|
|
55421
|
-
|
|
56346
|
+
fs14.writeFileSync(filePath, JSON.stringify(fixture, null, 2));
|
|
55422
56347
|
ctx.json(res, 200, {
|
|
55423
56348
|
saved: true,
|
|
55424
56349
|
name,
|
|
@@ -55436,14 +56361,14 @@ async (params) => {
|
|
|
55436
56361
|
async function handleCliFixtureList(ctx, type, _req, res) {
|
|
55437
56362
|
try {
|
|
55438
56363
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
55439
|
-
if (!
|
|
56364
|
+
if (!fs14.existsSync(fixtureDir)) {
|
|
55440
56365
|
ctx.json(res, 200, { fixtures: [], count: 0 });
|
|
55441
56366
|
return;
|
|
55442
56367
|
}
|
|
55443
|
-
const fixtures =
|
|
56368
|
+
const fixtures = fs14.readdirSync(fixtureDir).filter((file2) => file2.endsWith(".json")).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" })).map((file2) => {
|
|
55444
56369
|
const fullPath = path25.join(fixtureDir, file2);
|
|
55445
56370
|
try {
|
|
55446
|
-
const raw = JSON.parse(
|
|
56371
|
+
const raw = JSON.parse(fs14.readFileSync(fullPath, "utf-8"));
|
|
55447
56372
|
return {
|
|
55448
56373
|
name: raw.name || file2.replace(/\.json$/i, ""),
|
|
55449
56374
|
path: fullPath,
|
|
@@ -55574,7 +56499,7 @@ async (params) => {
|
|
|
55574
56499
|
ctx.json(res, 500, { error: `Raw send failed: ${e.message}` });
|
|
55575
56500
|
}
|
|
55576
56501
|
}
|
|
55577
|
-
var
|
|
56502
|
+
var fs15 = __toESM2(require("fs"));
|
|
55578
56503
|
var path26 = __toESM2(require("path"));
|
|
55579
56504
|
var os21 = __toESM2(require("os"));
|
|
55580
56505
|
function getAutoImplPid(ctx) {
|
|
@@ -55622,10 +56547,10 @@ async (params) => {
|
|
|
55622
56547
|
return fallback?.type || null;
|
|
55623
56548
|
}
|
|
55624
56549
|
function getLatestScriptVersionDir(scriptsDir) {
|
|
55625
|
-
if (!
|
|
55626
|
-
const versions =
|
|
56550
|
+
if (!fs15.existsSync(scriptsDir)) return null;
|
|
56551
|
+
const versions = fs15.readdirSync(scriptsDir).filter((d) => {
|
|
55627
56552
|
try {
|
|
55628
|
-
return
|
|
56553
|
+
return fs15.statSync(path26.join(scriptsDir, d)).isDirectory();
|
|
55629
56554
|
} catch {
|
|
55630
56555
|
return false;
|
|
55631
56556
|
}
|
|
@@ -55647,13 +56572,13 @@ async (params) => {
|
|
|
55647
56572
|
if (!sourceDir) {
|
|
55648
56573
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
55649
56574
|
}
|
|
55650
|
-
if (!
|
|
55651
|
-
|
|
55652
|
-
|
|
56575
|
+
if (!fs15.existsSync(desiredDir)) {
|
|
56576
|
+
fs15.mkdirSync(path26.dirname(desiredDir), { recursive: true });
|
|
56577
|
+
fs15.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
55653
56578
|
ctx.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
55654
56579
|
}
|
|
55655
56580
|
const providerJson = path26.join(desiredDir, "provider.json");
|
|
55656
|
-
if (!
|
|
56581
|
+
if (!fs15.existsSync(providerJson)) {
|
|
55657
56582
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
55658
56583
|
}
|
|
55659
56584
|
return { dir: desiredDir };
|
|
@@ -55661,15 +56586,15 @@ async (params) => {
|
|
|
55661
56586
|
function loadAutoImplReferenceScripts(ctx, referenceType) {
|
|
55662
56587
|
if (!referenceType) return {};
|
|
55663
56588
|
const refDir = ctx.findProviderDir(referenceType);
|
|
55664
|
-
if (!refDir || !
|
|
56589
|
+
if (!refDir || !fs15.existsSync(refDir)) return {};
|
|
55665
56590
|
const referenceScripts = {};
|
|
55666
56591
|
const scriptsDir = path26.join(refDir, "scripts");
|
|
55667
56592
|
const latestDir = getLatestScriptVersionDir(scriptsDir);
|
|
55668
56593
|
if (!latestDir) return referenceScripts;
|
|
55669
|
-
for (const file2 of
|
|
56594
|
+
for (const file2 of fs15.readdirSync(latestDir)) {
|
|
55670
56595
|
if (!file2.endsWith(".js")) continue;
|
|
55671
56596
|
try {
|
|
55672
|
-
referenceScripts[file2] =
|
|
56597
|
+
referenceScripts[file2] = fs15.readFileSync(path26.join(latestDir, file2), "utf-8");
|
|
55673
56598
|
} catch {
|
|
55674
56599
|
}
|
|
55675
56600
|
}
|
|
@@ -55778,15 +56703,15 @@ async (params) => {
|
|
|
55778
56703
|
const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
|
|
55779
56704
|
const prompt = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference, verification);
|
|
55780
56705
|
const tmpDir = path26.join(os21.tmpdir(), "adhdev-autoimpl");
|
|
55781
|
-
if (!
|
|
56706
|
+
if (!fs15.existsSync(tmpDir)) fs15.mkdirSync(tmpDir, { recursive: true });
|
|
55782
56707
|
const promptFile = path26.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
|
|
55783
|
-
|
|
56708
|
+
fs15.writeFileSync(promptFile, prompt, "utf-8");
|
|
55784
56709
|
ctx.log(`Auto-implement prompt written to ${promptFile} (${prompt.length} chars)`);
|
|
55785
56710
|
const agentProvider = ctx.providerLoader.resolve(agent) || ctx.providerLoader.getMeta(agent);
|
|
55786
56711
|
const spawn4 = agentProvider?.spawn;
|
|
55787
56712
|
if (!spawn4?.command) {
|
|
55788
56713
|
try {
|
|
55789
|
-
|
|
56714
|
+
fs15.unlinkSync(promptFile);
|
|
55790
56715
|
} catch {
|
|
55791
56716
|
}
|
|
55792
56717
|
ctx.json(res, 400, { error: `Agent '${agent}' has no spawn config. Select a CLI provider with a spawn configuration.` });
|
|
@@ -55888,7 +56813,7 @@ async (params) => {
|
|
|
55888
56813
|
} catch {
|
|
55889
56814
|
}
|
|
55890
56815
|
try {
|
|
55891
|
-
|
|
56816
|
+
fs15.unlinkSync(promptFile);
|
|
55892
56817
|
} catch {
|
|
55893
56818
|
}
|
|
55894
56819
|
ctx.log(`Auto-implement (ACP) ${success2 ? "completed" : "failed"}: ${type} (exit: ${code})`);
|
|
@@ -56114,7 +57039,7 @@ async (params) => {
|
|
|
56114
57039
|
}
|
|
56115
57040
|
});
|
|
56116
57041
|
try {
|
|
56117
|
-
|
|
57042
|
+
fs15.unlinkSync(promptFile);
|
|
56118
57043
|
} catch {
|
|
56119
57044
|
}
|
|
56120
57045
|
ctx.log(`Auto-implement ${success2 ? "completed" : "failed"}: ${type} (exit: ${code})${verificationSummary ? ` verify=${verificationSummary.pass ? "pass" : "fail"}` : ""}`);
|
|
@@ -56219,10 +57144,10 @@ async (params) => {
|
|
|
56219
57144
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
56220
57145
|
lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
|
|
56221
57146
|
lines.push("");
|
|
56222
|
-
for (const file2 of
|
|
57147
|
+
for (const file2 of fs15.readdirSync(latestScriptsDir)) {
|
|
56223
57148
|
if (file2.endsWith(".js") && targetFileNames.has(file2)) {
|
|
56224
57149
|
try {
|
|
56225
|
-
const content =
|
|
57150
|
+
const content = fs15.readFileSync(path26.join(latestScriptsDir, file2), "utf-8");
|
|
56226
57151
|
lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
|
|
56227
57152
|
lines.push("```javascript");
|
|
56228
57153
|
lines.push(content);
|
|
@@ -56232,14 +57157,14 @@ async (params) => {
|
|
|
56232
57157
|
}
|
|
56233
57158
|
}
|
|
56234
57159
|
}
|
|
56235
|
-
const refFiles =
|
|
57160
|
+
const refFiles = fs15.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
56236
57161
|
if (refFiles.length > 0) {
|
|
56237
57162
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
56238
57163
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
56239
57164
|
lines.push("");
|
|
56240
57165
|
for (const file2 of refFiles) {
|
|
56241
57166
|
try {
|
|
56242
|
-
const content =
|
|
57167
|
+
const content = fs15.readFileSync(path26.join(latestScriptsDir, file2), "utf-8");
|
|
56243
57168
|
lines.push(`### \`${file2}\` \u{1F512}`);
|
|
56244
57169
|
lines.push("```javascript");
|
|
56245
57170
|
lines.push(content);
|
|
@@ -56284,7 +57209,7 @@ async (params) => {
|
|
|
56284
57209
|
const loadGuide = (name) => {
|
|
56285
57210
|
try {
|
|
56286
57211
|
const p = path26.join(docsDir, name);
|
|
56287
|
-
if (
|
|
57212
|
+
if (fs15.existsSync(p)) return fs15.readFileSync(p, "utf-8");
|
|
56288
57213
|
} catch {
|
|
56289
57214
|
}
|
|
56290
57215
|
return null;
|
|
@@ -56528,11 +57453,11 @@ async (params) => {
|
|
|
56528
57453
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
56529
57454
|
lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
|
|
56530
57455
|
lines.push("");
|
|
56531
|
-
for (const file2 of
|
|
57456
|
+
for (const file2 of fs15.readdirSync(latestScriptsDir)) {
|
|
56532
57457
|
if (!file2.endsWith(".js")) continue;
|
|
56533
57458
|
if (!targetFileNames.has(file2)) continue;
|
|
56534
57459
|
try {
|
|
56535
|
-
const content =
|
|
57460
|
+
const content = fs15.readFileSync(path26.join(latestScriptsDir, file2), "utf-8");
|
|
56536
57461
|
lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
|
|
56537
57462
|
lines.push("```javascript");
|
|
56538
57463
|
lines.push(content);
|
|
@@ -56541,14 +57466,14 @@ async (params) => {
|
|
|
56541
57466
|
} catch {
|
|
56542
57467
|
}
|
|
56543
57468
|
}
|
|
56544
|
-
const refFiles =
|
|
57469
|
+
const refFiles = fs15.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
56545
57470
|
if (refFiles.length > 0) {
|
|
56546
57471
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
56547
57472
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
56548
57473
|
lines.push("");
|
|
56549
57474
|
for (const file2 of refFiles) {
|
|
56550
57475
|
try {
|
|
56551
|
-
const content =
|
|
57476
|
+
const content = fs15.readFileSync(path26.join(latestScriptsDir, file2), "utf-8");
|
|
56552
57477
|
lines.push(`### \`${file2}\` \u{1F512}`);
|
|
56553
57478
|
lines.push("```javascript");
|
|
56554
57479
|
lines.push(content);
|
|
@@ -56585,7 +57510,7 @@ async (params) => {
|
|
|
56585
57510
|
const loadGuide = (name) => {
|
|
56586
57511
|
try {
|
|
56587
57512
|
const p = path26.join(docsDir, name);
|
|
56588
|
-
if (
|
|
57513
|
+
if (fs15.existsSync(p)) return fs15.readFileSync(p, "utf-8");
|
|
56589
57514
|
} catch {
|
|
56590
57515
|
}
|
|
56591
57516
|
return null;
|
|
@@ -57323,7 +58248,7 @@ data: ${JSON.stringify(msg.data)}
|
|
|
57323
58248
|
path27.join(process.cwd(), "packages/web-devconsole/dist")
|
|
57324
58249
|
];
|
|
57325
58250
|
for (const dir of candidates) {
|
|
57326
|
-
if (
|
|
58251
|
+
if (fs16.existsSync(path27.join(dir, "index.html"))) return dir;
|
|
57327
58252
|
}
|
|
57328
58253
|
return null;
|
|
57329
58254
|
}
|
|
@@ -57335,7 +58260,7 @@ data: ${JSON.stringify(msg.data)}
|
|
|
57335
58260
|
}
|
|
57336
58261
|
const htmlPath = path27.join(distDir, "index.html");
|
|
57337
58262
|
try {
|
|
57338
|
-
const html =
|
|
58263
|
+
const html = fs16.readFileSync(htmlPath, "utf-8");
|
|
57339
58264
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
57340
58265
|
res.end(html);
|
|
57341
58266
|
} catch (e) {
|
|
@@ -57365,7 +58290,7 @@ data: ${JSON.stringify(msg.data)}
|
|
|
57365
58290
|
return;
|
|
57366
58291
|
}
|
|
57367
58292
|
try {
|
|
57368
|
-
const content =
|
|
58293
|
+
const content = fs16.readFileSync(filePath);
|
|
57369
58294
|
const ext = path27.extname(filePath);
|
|
57370
58295
|
const contentType = _DevServer.MIME_MAP[ext] || "application/octet-stream";
|
|
57371
58296
|
res.writeHead(200, { "Content-Type": contentType, "Cache-Control": "public, max-age=31536000, immutable" });
|
|
@@ -57474,14 +58399,14 @@ data: ${JSON.stringify(msg.data)}
|
|
|
57474
58399
|
const files = [];
|
|
57475
58400
|
const scan = (d, prefix) => {
|
|
57476
58401
|
try {
|
|
57477
|
-
for (const entry of
|
|
58402
|
+
for (const entry of fs16.readdirSync(d, { withFileTypes: true })) {
|
|
57478
58403
|
if (entry.name.startsWith(".") || entry.name.endsWith(".bak")) continue;
|
|
57479
58404
|
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
57480
58405
|
if (entry.isDirectory()) {
|
|
57481
58406
|
files.push({ path: rel, size: 0, type: "dir" });
|
|
57482
58407
|
scan(path27.join(d, entry.name), rel);
|
|
57483
58408
|
} else {
|
|
57484
|
-
const stat2 =
|
|
58409
|
+
const stat2 = fs16.statSync(path27.join(d, entry.name));
|
|
57485
58410
|
files.push({ path: rel, size: stat2.size, type: "file" });
|
|
57486
58411
|
}
|
|
57487
58412
|
}
|
|
@@ -57509,11 +58434,11 @@ data: ${JSON.stringify(msg.data)}
|
|
|
57509
58434
|
this.json(res, 403, { error: "Forbidden" });
|
|
57510
58435
|
return;
|
|
57511
58436
|
}
|
|
57512
|
-
if (!
|
|
58437
|
+
if (!fs16.existsSync(fullPath) || fs16.statSync(fullPath).isDirectory()) {
|
|
57513
58438
|
this.json(res, 404, { error: `File not found: ${filePath}` });
|
|
57514
58439
|
return;
|
|
57515
58440
|
}
|
|
57516
|
-
const content =
|
|
58441
|
+
const content = fs16.readFileSync(fullPath, "utf-8");
|
|
57517
58442
|
this.json(res, 200, { type, path: filePath, content, lines: content.split("\n").length });
|
|
57518
58443
|
}
|
|
57519
58444
|
/** POST /api/providers/:type/file — write a file { path, content } */
|
|
@@ -57535,9 +58460,9 @@ data: ${JSON.stringify(msg.data)}
|
|
|
57535
58460
|
return;
|
|
57536
58461
|
}
|
|
57537
58462
|
try {
|
|
57538
|
-
if (
|
|
57539
|
-
|
|
57540
|
-
|
|
58463
|
+
if (fs16.existsSync(fullPath)) fs16.copyFileSync(fullPath, fullPath + ".bak");
|
|
58464
|
+
fs16.mkdirSync(path27.dirname(fullPath), { recursive: true });
|
|
58465
|
+
fs16.writeFileSync(fullPath, content, "utf-8");
|
|
57541
58466
|
this.log(`File saved: ${fullPath} (${content.length} chars)`);
|
|
57542
58467
|
this.providerLoader.reload();
|
|
57543
58468
|
this.json(res, 200, { saved: true, path: filePath, chars: content.length });
|
|
@@ -57554,8 +58479,8 @@ data: ${JSON.stringify(msg.data)}
|
|
|
57554
58479
|
}
|
|
57555
58480
|
for (const name of ["scripts.js", "provider.json"]) {
|
|
57556
58481
|
const p = path27.join(dir, name);
|
|
57557
|
-
if (
|
|
57558
|
-
const source =
|
|
58482
|
+
if (fs16.existsSync(p)) {
|
|
58483
|
+
const source = fs16.readFileSync(p, "utf-8");
|
|
57559
58484
|
this.json(res, 200, { type, path: p, source, lines: source.split("\n").length });
|
|
57560
58485
|
return;
|
|
57561
58486
|
}
|
|
@@ -57574,11 +58499,11 @@ data: ${JSON.stringify(msg.data)}
|
|
|
57574
58499
|
this.json(res, 404, { error: `Provider not found: ${type}` });
|
|
57575
58500
|
return;
|
|
57576
58501
|
}
|
|
57577
|
-
const target =
|
|
58502
|
+
const target = fs16.existsSync(path27.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
|
|
57578
58503
|
const targetPath = path27.join(dir, target);
|
|
57579
58504
|
try {
|
|
57580
|
-
if (
|
|
57581
|
-
|
|
58505
|
+
if (fs16.existsSync(targetPath)) fs16.copyFileSync(targetPath, targetPath + ".bak");
|
|
58506
|
+
fs16.writeFileSync(targetPath, source, "utf-8");
|
|
57582
58507
|
this.log(`Saved provider: ${targetPath} (${source.length} chars)`);
|
|
57583
58508
|
this.providerLoader.reload();
|
|
57584
58509
|
this.json(res, 200, { saved: true, path: targetPath, chars: source.length });
|
|
@@ -57723,20 +58648,20 @@ data: ${JSON.stringify(msg.data)}
|
|
|
57723
58648
|
let targetDir;
|
|
57724
58649
|
targetDir = this.providerLoader.getUserProviderDir(category, type);
|
|
57725
58650
|
const jsonPath = path27.join(targetDir, "provider.json");
|
|
57726
|
-
if (
|
|
58651
|
+
if (fs16.existsSync(jsonPath)) {
|
|
57727
58652
|
this.json(res, 409, { error: `Provider already exists at ${targetDir}`, path: targetDir });
|
|
57728
58653
|
return;
|
|
57729
58654
|
}
|
|
57730
58655
|
try {
|
|
57731
58656
|
const result = generateFiles(type, name, category, { cdpPorts, cli, processName, installPath, binary, extensionId, version: version2, osPaths, processNames });
|
|
57732
|
-
|
|
57733
|
-
|
|
58657
|
+
fs16.mkdirSync(targetDir, { recursive: true });
|
|
58658
|
+
fs16.writeFileSync(jsonPath, result["provider.json"], "utf-8");
|
|
57734
58659
|
const createdFiles = ["provider.json"];
|
|
57735
58660
|
if (result.files) {
|
|
57736
58661
|
for (const [relPath, content] of Object.entries(result.files)) {
|
|
57737
58662
|
const fullPath = path27.join(targetDir, relPath);
|
|
57738
|
-
|
|
57739
|
-
|
|
58663
|
+
fs16.mkdirSync(path27.dirname(fullPath), { recursive: true });
|
|
58664
|
+
fs16.writeFileSync(fullPath, content, "utf-8");
|
|
57740
58665
|
createdFiles.push(relPath);
|
|
57741
58666
|
}
|
|
57742
58667
|
}
|
|
@@ -57785,10 +58710,10 @@ data: ${JSON.stringify(msg.data)}
|
|
|
57785
58710
|
}
|
|
57786
58711
|
// ─── Phase 2: Auto-Implement Backend ───
|
|
57787
58712
|
getLatestScriptVersionDir(scriptsDir) {
|
|
57788
|
-
if (!
|
|
57789
|
-
const versions =
|
|
58713
|
+
if (!fs16.existsSync(scriptsDir)) return null;
|
|
58714
|
+
const versions = fs16.readdirSync(scriptsDir).filter((d) => {
|
|
57790
58715
|
try {
|
|
57791
|
-
return
|
|
58716
|
+
return fs16.statSync(path27.join(scriptsDir, d)).isDirectory();
|
|
57792
58717
|
} catch {
|
|
57793
58718
|
return false;
|
|
57794
58719
|
}
|
|
@@ -57810,13 +58735,13 @@ data: ${JSON.stringify(msg.data)}
|
|
|
57810
58735
|
if (!sourceDir) {
|
|
57811
58736
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
57812
58737
|
}
|
|
57813
|
-
if (!
|
|
57814
|
-
|
|
57815
|
-
|
|
58738
|
+
if (!fs16.existsSync(desiredDir)) {
|
|
58739
|
+
fs16.mkdirSync(path27.dirname(desiredDir), { recursive: true });
|
|
58740
|
+
fs16.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
57816
58741
|
this.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
57817
58742
|
}
|
|
57818
58743
|
const providerJson = path27.join(desiredDir, "provider.json");
|
|
57819
|
-
if (!
|
|
58744
|
+
if (!fs16.existsSync(providerJson)) {
|
|
57820
58745
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
57821
58746
|
}
|
|
57822
58747
|
return { dir: desiredDir };
|
|
@@ -57859,10 +58784,10 @@ data: ${JSON.stringify(msg.data)}
|
|
|
57859
58784
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
57860
58785
|
lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
|
|
57861
58786
|
lines.push("");
|
|
57862
|
-
for (const file2 of
|
|
58787
|
+
for (const file2 of fs16.readdirSync(latestScriptsDir)) {
|
|
57863
58788
|
if (file2.endsWith(".js") && targetFileNames.has(file2)) {
|
|
57864
58789
|
try {
|
|
57865
|
-
const content =
|
|
58790
|
+
const content = fs16.readFileSync(path27.join(latestScriptsDir, file2), "utf-8");
|
|
57866
58791
|
lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
|
|
57867
58792
|
lines.push("```javascript");
|
|
57868
58793
|
lines.push(content);
|
|
@@ -57872,14 +58797,14 @@ data: ${JSON.stringify(msg.data)}
|
|
|
57872
58797
|
}
|
|
57873
58798
|
}
|
|
57874
58799
|
}
|
|
57875
|
-
const refFiles =
|
|
58800
|
+
const refFiles = fs16.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
57876
58801
|
if (refFiles.length > 0) {
|
|
57877
58802
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
57878
58803
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
57879
58804
|
lines.push("");
|
|
57880
58805
|
for (const file2 of refFiles) {
|
|
57881
58806
|
try {
|
|
57882
|
-
const content =
|
|
58807
|
+
const content = fs16.readFileSync(path27.join(latestScriptsDir, file2), "utf-8");
|
|
57883
58808
|
lines.push(`### \`${file2}\` \u{1F512}`);
|
|
57884
58809
|
lines.push("```javascript");
|
|
57885
58810
|
lines.push(content);
|
|
@@ -57924,7 +58849,7 @@ data: ${JSON.stringify(msg.data)}
|
|
|
57924
58849
|
const loadGuide = (name) => {
|
|
57925
58850
|
try {
|
|
57926
58851
|
const p = path27.join(docsDir, name);
|
|
57927
|
-
if (
|
|
58852
|
+
if (fs16.existsSync(p)) return fs16.readFileSync(p, "utf-8");
|
|
57928
58853
|
} catch {
|
|
57929
58854
|
}
|
|
57930
58855
|
return null;
|
|
@@ -58105,11 +59030,11 @@ data: ${JSON.stringify(msg.data)}
|
|
|
58105
59030
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
58106
59031
|
lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
|
|
58107
59032
|
lines.push("");
|
|
58108
|
-
for (const file2 of
|
|
59033
|
+
for (const file2 of fs16.readdirSync(latestScriptsDir)) {
|
|
58109
59034
|
if (!file2.endsWith(".js")) continue;
|
|
58110
59035
|
if (!targetFileNames.has(file2)) continue;
|
|
58111
59036
|
try {
|
|
58112
|
-
const content =
|
|
59037
|
+
const content = fs16.readFileSync(path27.join(latestScriptsDir, file2), "utf-8");
|
|
58113
59038
|
lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
|
|
58114
59039
|
lines.push("```javascript");
|
|
58115
59040
|
lines.push(content);
|
|
@@ -58118,14 +59043,14 @@ data: ${JSON.stringify(msg.data)}
|
|
|
58118
59043
|
} catch {
|
|
58119
59044
|
}
|
|
58120
59045
|
}
|
|
58121
|
-
const refFiles =
|
|
59046
|
+
const refFiles = fs16.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
58122
59047
|
if (refFiles.length > 0) {
|
|
58123
59048
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
58124
59049
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
58125
59050
|
lines.push("");
|
|
58126
59051
|
for (const file2 of refFiles) {
|
|
58127
59052
|
try {
|
|
58128
|
-
const content =
|
|
59053
|
+
const content = fs16.readFileSync(path27.join(latestScriptsDir, file2), "utf-8");
|
|
58129
59054
|
lines.push(`### \`${file2}\` \u{1F512}`);
|
|
58130
59055
|
lines.push("```javascript");
|
|
58131
59056
|
lines.push(content);
|
|
@@ -58162,7 +59087,7 @@ data: ${JSON.stringify(msg.data)}
|
|
|
58162
59087
|
const loadGuide = (name) => {
|
|
58163
59088
|
try {
|
|
58164
59089
|
const p = path27.join(docsDir, name);
|
|
58165
|
-
if (
|
|
59090
|
+
if (fs16.existsSync(p)) return fs16.readFileSync(p, "utf-8");
|
|
58166
59091
|
} catch {
|
|
58167
59092
|
}
|
|
58168
59093
|
return null;
|
|
@@ -58927,7 +59852,8 @@ data: ${JSON.stringify(msg.data)}
|
|
|
58927
59852
|
if (raw === "0" || raw === "false" || raw === "no") return false;
|
|
58928
59853
|
return raw === "1" || raw === "true" || raw === "yes";
|
|
58929
59854
|
}
|
|
58930
|
-
var
|
|
59855
|
+
var import_child_process10 = require("child_process");
|
|
59856
|
+
var import_util32 = require("util");
|
|
58931
59857
|
var EXTENSION_CATALOG = [
|
|
58932
59858
|
// AI Agent extensions
|
|
58933
59859
|
{
|
|
@@ -59014,15 +59940,15 @@ data: ${JSON.stringify(msg.data)}
|
|
|
59014
59940
|
apiKeyName: "OpenAI/Anthropic API key"
|
|
59015
59941
|
}
|
|
59016
59942
|
];
|
|
59017
|
-
|
|
59943
|
+
var execAsync4 = (0, import_util32.promisify)(import_child_process10.exec);
|
|
59944
|
+
async function isExtensionInstalled(ide, marketplaceId) {
|
|
59018
59945
|
if (!ide.cliCommand) return false;
|
|
59019
59946
|
try {
|
|
59020
|
-
const
|
|
59947
|
+
const { stdout } = await execAsync4(`"${ide.cliCommand}" --list-extensions`, {
|
|
59021
59948
|
encoding: "utf-8",
|
|
59022
|
-
timeout: 15e3
|
|
59023
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
59949
|
+
timeout: 15e3
|
|
59024
59950
|
});
|
|
59025
|
-
const installed =
|
|
59951
|
+
const installed = stdout.trim().split("\n").map((e) => e.trim().toLowerCase());
|
|
59026
59952
|
return installed.includes(marketplaceId.toLowerCase());
|
|
59027
59953
|
} catch {
|
|
59028
59954
|
return false;
|
|
@@ -59038,7 +59964,7 @@ data: ${JSON.stringify(msg.data)}
|
|
|
59038
59964
|
error: `No CLI command found for ${ide.displayName}. Please install it manually.`
|
|
59039
59965
|
};
|
|
59040
59966
|
}
|
|
59041
|
-
const alreadyInstalled = isExtensionInstalled(ide, extension.marketplaceId);
|
|
59967
|
+
const alreadyInstalled = await isExtensionInstalled(ide, extension.marketplaceId);
|
|
59042
59968
|
if (alreadyInstalled) {
|
|
59043
59969
|
return {
|
|
59044
59970
|
extensionId: extension.id,
|
|
@@ -59054,11 +59980,11 @@ data: ${JSON.stringify(msg.data)}
|
|
|
59054
59980
|
const res = await fetch(extension.vsixUrl);
|
|
59055
59981
|
if (res.ok) {
|
|
59056
59982
|
const buffer = Buffer.from(await res.arrayBuffer());
|
|
59057
|
-
const
|
|
59058
|
-
|
|
59983
|
+
const fs17 = await import("fs");
|
|
59984
|
+
fs17.writeFileSync(vsixPath, buffer);
|
|
59059
59985
|
return new Promise((resolve16) => {
|
|
59060
59986
|
const cmd = `"${ide.cliCommand}" --install-extension "${vsixPath}" --force`;
|
|
59061
|
-
(0,
|
|
59987
|
+
(0, import_child_process10.exec)(cmd, { timeout: 6e4 }, (error48, _stdout, stderr) => {
|
|
59062
59988
|
resolve16({
|
|
59063
59989
|
extensionId: extension.id,
|
|
59064
59990
|
marketplaceId: extension.marketplaceId,
|
|
@@ -59074,7 +60000,7 @@ data: ${JSON.stringify(msg.data)}
|
|
|
59074
60000
|
}
|
|
59075
60001
|
return new Promise((resolve16) => {
|
|
59076
60002
|
const cmd = `"${ide.cliCommand}" --install-extension ${extension.marketplaceId} --force`;
|
|
59077
|
-
(0,
|
|
60003
|
+
(0, import_child_process10.exec)(cmd, { timeout: 6e4 }, (error48, stdout, stderr) => {
|
|
59078
60004
|
if (error48) {
|
|
59079
60005
|
resolve16({
|
|
59080
60006
|
extensionId: extension.id,
|
|
@@ -59111,7 +60037,7 @@ data: ${JSON.stringify(msg.data)}
|
|
|
59111
60037
|
if (!ide.cliCommand) return false;
|
|
59112
60038
|
try {
|
|
59113
60039
|
const args = workspacePath ? `"${workspacePath}"` : "";
|
|
59114
|
-
(0,
|
|
60040
|
+
(0, import_child_process10.exec)(`"${ide.cliCommand}" ${args}`, { timeout: 1e4 });
|
|
59115
60041
|
return true;
|
|
59116
60042
|
} catch {
|
|
59117
60043
|
return false;
|