@adhdev/daemon-core 0.9.70 → 0.9.72
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/cli-adapters/provider-cli-adapter.d.ts +1 -0
- package/dist/commands/cli-manager.d.ts +1 -0
- package/dist/commands/mesh-coordinator.d.ts +7 -0
- package/dist/index.js +315 -137
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +314 -136
- package/dist/index.mjs.map +1 -1
- package/dist/mesh/mesh-events.d.ts +2 -0
- package/dist/providers/cli-provider-instance.d.ts +1 -0
- package/dist/shared-types.d.ts +2 -0
- package/node_modules/@adhdev/session-host-core/package.json +1 -1
- package/package.json +1 -1
- package/src/boot/daemon-lifecycle.ts +7 -1
- package/src/cli-adapters/provider-cli-adapter.ts +24 -2
- package/src/commands/chat-commands.ts +37 -1
- package/src/commands/cli-manager.ts +3 -3
- package/src/commands/mesh-coordinator.ts +82 -1
- package/src/commands/router.ts +26 -6
- package/src/mesh/mesh-events.ts +61 -0
- package/src/providers/cli-provider-instance.ts +21 -16
- package/src/shared-types.ts +2 -0
- package/src/status/builders.ts +4 -0
- package/src/status/reporter.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -2226,7 +2226,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
2226
2226
|
`[${this.cliType}] Waiting for interactive prompt: status=${status} stableMs=${stableMs} recentOutputMs=${recentlyOutput} screen=${JSON.stringify(summarizeCliTraceText(screenText, 220)).slice(0, 260)}`
|
|
2227
2227
|
);
|
|
2228
2228
|
}
|
|
2229
|
-
await new Promise((
|
|
2229
|
+
await new Promise((resolve16) => setTimeout(resolve16, 50));
|
|
2230
2230
|
}
|
|
2231
2231
|
const finalScreenText = this.terminalScreen.getText() || "";
|
|
2232
2232
|
LOG.warn(
|
|
@@ -3136,7 +3136,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
3136
3136
|
const deadline = Date.now() + 1e4;
|
|
3137
3137
|
while (this.startupParseGate && Date.now() < deadline) {
|
|
3138
3138
|
this.resolveStartupState("send_wait");
|
|
3139
|
-
await new Promise((
|
|
3139
|
+
await new Promise((resolve16) => setTimeout(resolve16, 50));
|
|
3140
3140
|
}
|
|
3141
3141
|
}
|
|
3142
3142
|
if (!allowInterventionPrompt) {
|
|
@@ -3212,13 +3212,13 @@ var init_provider_cli_adapter = __esm({
|
|
|
3212
3212
|
}
|
|
3213
3213
|
this.responseEpoch += 1;
|
|
3214
3214
|
this.responseSettleIgnoreUntil = Date.now() + submitDelayMs + this.timeouts.outputSettle + 250;
|
|
3215
|
-
await new Promise((
|
|
3215
|
+
await new Promise((resolve16, reject) => {
|
|
3216
3216
|
let resolved = false;
|
|
3217
3217
|
const completion = {
|
|
3218
3218
|
resolveOnce: () => {
|
|
3219
3219
|
if (resolved) return;
|
|
3220
3220
|
resolved = true;
|
|
3221
|
-
|
|
3221
|
+
resolve16();
|
|
3222
3222
|
},
|
|
3223
3223
|
rejectOnce: (error) => {
|
|
3224
3224
|
if (resolved) return;
|
|
@@ -3376,17 +3376,17 @@ var init_provider_cli_adapter = __esm({
|
|
|
3376
3376
|
}
|
|
3377
3377
|
}
|
|
3378
3378
|
waitForStopped(timeoutMs) {
|
|
3379
|
-
return new Promise((
|
|
3379
|
+
return new Promise((resolve16) => {
|
|
3380
3380
|
const startedAt = Date.now();
|
|
3381
3381
|
const timer = setInterval(() => {
|
|
3382
3382
|
if (!this.ptyProcess || this.currentStatus === "stopped") {
|
|
3383
3383
|
clearInterval(timer);
|
|
3384
|
-
|
|
3384
|
+
resolve16(true);
|
|
3385
3385
|
return;
|
|
3386
3386
|
}
|
|
3387
3387
|
if (Date.now() - startedAt >= timeoutMs) {
|
|
3388
3388
|
clearInterval(timer);
|
|
3389
|
-
|
|
3389
|
+
resolve16(false);
|
|
3390
3390
|
}
|
|
3391
3391
|
}, 100);
|
|
3392
3392
|
});
|
|
@@ -3529,11 +3529,22 @@ var init_provider_cli_adapter = __esm({
|
|
|
3529
3529
|
}
|
|
3530
3530
|
}
|
|
3531
3531
|
}
|
|
3532
|
+
getParsedDebugState() {
|
|
3533
|
+
if (this.startupParseGate || typeof this.cliScripts?.parseSession !== "function") return null;
|
|
3534
|
+
try {
|
|
3535
|
+
const parsed = this.getScriptParsedStatus();
|
|
3536
|
+
return parsed && typeof parsed === "object" ? parsed : null;
|
|
3537
|
+
} catch {
|
|
3538
|
+
return null;
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3532
3541
|
getDebugState() {
|
|
3533
3542
|
const screenText = sanitizeTerminalText(this.terminalScreen.getText());
|
|
3534
3543
|
const startupModal = this.startupParseGate ? this.runParseApproval(this.recentOutputBuffer) : null;
|
|
3535
3544
|
const effectiveStatus = this.projectEffectiveStatus(startupModal);
|
|
3536
3545
|
const effectiveReady = this.ready || !!startupModal;
|
|
3546
|
+
const parsedDebugState = this.getParsedDebugState();
|
|
3547
|
+
const parsedMessages = Array.isArray(parsedDebugState?.messages) ? parsedDebugState.messages : [];
|
|
3537
3548
|
return {
|
|
3538
3549
|
type: this.cliType,
|
|
3539
3550
|
name: this.cliName,
|
|
@@ -3546,8 +3557,18 @@ var init_provider_cli_adapter = __esm({
|
|
|
3546
3557
|
startupParseGate: this.startupParseGate,
|
|
3547
3558
|
spawnAt: this.spawnAt,
|
|
3548
3559
|
workingDir: this.workingDir,
|
|
3549
|
-
messages:
|
|
3550
|
-
messageCount:
|
|
3560
|
+
messages: parsedMessages,
|
|
3561
|
+
messageCount: parsedMessages.length,
|
|
3562
|
+
parsedStatus: parsedDebugState ? {
|
|
3563
|
+
id: parsedDebugState.id,
|
|
3564
|
+
status: parsedDebugState.status,
|
|
3565
|
+
title: parsedDebugState.title,
|
|
3566
|
+
providerSessionId: parsedDebugState.providerSessionId,
|
|
3567
|
+
transcriptAuthority: parsedDebugState.transcriptAuthority,
|
|
3568
|
+
coverage: parsedDebugState.coverage,
|
|
3569
|
+
activeModal: parsedDebugState.activeModal,
|
|
3570
|
+
messageCount: parsedMessages.length
|
|
3571
|
+
} : null,
|
|
3551
3572
|
screenText: screenText.slice(-4e3),
|
|
3552
3573
|
currentTurnScope: this.currentTurnScope,
|
|
3553
3574
|
startupBuffer: this.startupBuffer.slice(-4e3),
|
|
@@ -5804,8 +5825,8 @@ async function detectIDEs(providerLoader) {
|
|
|
5804
5825
|
if ((0, import_fs4.existsSync)(bundledCli)) resolvedCli = bundledCli;
|
|
5805
5826
|
}
|
|
5806
5827
|
if (!resolvedCli && appPath && os21 === "win32") {
|
|
5807
|
-
const { dirname:
|
|
5808
|
-
const appDir =
|
|
5828
|
+
const { dirname: dirname8 } = await import("path");
|
|
5829
|
+
const appDir = dirname8(appPath);
|
|
5809
5830
|
const candidates = [
|
|
5810
5831
|
`${appDir}\\\\bin\\\\${def.cli}.cmd`,
|
|
5811
5832
|
`${appDir}\\\\bin\\\\${def.cli}`,
|
|
@@ -5869,19 +5890,19 @@ function resolveCommandPath(command) {
|
|
|
5869
5890
|
return null;
|
|
5870
5891
|
}
|
|
5871
5892
|
function execAsync(cmd, timeoutMs = 5e3) {
|
|
5872
|
-
return new Promise((
|
|
5893
|
+
return new Promise((resolve16) => {
|
|
5873
5894
|
const child = (0, import_child_process2.exec)(cmd, {
|
|
5874
5895
|
encoding: "utf-8",
|
|
5875
5896
|
timeout: timeoutMs,
|
|
5876
5897
|
...process.platform === "win32" ? { windowsHide: true } : {}
|
|
5877
5898
|
}, (err, stdout) => {
|
|
5878
5899
|
if (err || !stdout?.trim()) {
|
|
5879
|
-
|
|
5900
|
+
resolve16(null);
|
|
5880
5901
|
} else {
|
|
5881
|
-
|
|
5902
|
+
resolve16(stdout.trim());
|
|
5882
5903
|
}
|
|
5883
5904
|
});
|
|
5884
|
-
child.on("error", () =>
|
|
5905
|
+
child.on("error", () => resolve16(null));
|
|
5885
5906
|
});
|
|
5886
5907
|
}
|
|
5887
5908
|
async function detectCLIs(providerLoader, options) {
|
|
@@ -6246,7 +6267,7 @@ var DaemonCdpManager = class {
|
|
|
6246
6267
|
* Returns multiple entries if multiple IDE windows are open on same port
|
|
6247
6268
|
*/
|
|
6248
6269
|
static listAllTargets(port) {
|
|
6249
|
-
return new Promise((
|
|
6270
|
+
return new Promise((resolve16) => {
|
|
6250
6271
|
const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
|
|
6251
6272
|
let data = "";
|
|
6252
6273
|
res.on("data", (chunk) => data += chunk.toString());
|
|
@@ -6262,16 +6283,16 @@ var DaemonCdpManager = class {
|
|
|
6262
6283
|
(t) => !isNonMain(t.title || "") && t.url?.includes("workbench.html") && !t.url?.includes("agent")
|
|
6263
6284
|
);
|
|
6264
6285
|
const fallbackPages = pages.filter((t) => !isNonMain(t.title || ""));
|
|
6265
|
-
|
|
6286
|
+
resolve16(mainPages.length > 0 ? mainPages : fallbackPages);
|
|
6266
6287
|
} catch {
|
|
6267
|
-
|
|
6288
|
+
resolve16([]);
|
|
6268
6289
|
}
|
|
6269
6290
|
});
|
|
6270
6291
|
});
|
|
6271
|
-
req.on("error", () =>
|
|
6292
|
+
req.on("error", () => resolve16([]));
|
|
6272
6293
|
req.setTimeout(2e3, () => {
|
|
6273
6294
|
req.destroy();
|
|
6274
|
-
|
|
6295
|
+
resolve16([]);
|
|
6275
6296
|
});
|
|
6276
6297
|
});
|
|
6277
6298
|
}
|
|
@@ -6311,7 +6332,7 @@ var DaemonCdpManager = class {
|
|
|
6311
6332
|
}
|
|
6312
6333
|
}
|
|
6313
6334
|
findTargetOnPort(port) {
|
|
6314
|
-
return new Promise((
|
|
6335
|
+
return new Promise((resolve16) => {
|
|
6315
6336
|
const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
|
|
6316
6337
|
let data = "";
|
|
6317
6338
|
res.on("data", (chunk) => data += chunk.toString());
|
|
@@ -6322,7 +6343,7 @@ var DaemonCdpManager = class {
|
|
|
6322
6343
|
(t) => (t.type === "page" || t.type === "browser" || t.type === "Page") && t.webSocketDebuggerUrl
|
|
6323
6344
|
);
|
|
6324
6345
|
if (pages.length === 0) {
|
|
6325
|
-
|
|
6346
|
+
resolve16(targets.find((t) => t.webSocketDebuggerUrl) || null);
|
|
6326
6347
|
return;
|
|
6327
6348
|
}
|
|
6328
6349
|
const titleFilteredPages = pages.filter((t) => !this.isNonMainTitle(t.title || ""));
|
|
@@ -6341,25 +6362,25 @@ var DaemonCdpManager = class {
|
|
|
6341
6362
|
this._targetId = selected.target.id;
|
|
6342
6363
|
}
|
|
6343
6364
|
this._pageTitle = selected.target.title || "";
|
|
6344
|
-
|
|
6365
|
+
resolve16(selected.target);
|
|
6345
6366
|
return;
|
|
6346
6367
|
}
|
|
6347
6368
|
if (previousTargetId) {
|
|
6348
6369
|
this.log(`[CDP] Target ${previousTargetId} not found in page list`);
|
|
6349
|
-
|
|
6370
|
+
resolve16(null);
|
|
6350
6371
|
return;
|
|
6351
6372
|
}
|
|
6352
6373
|
this._pageTitle = list[0]?.title || "";
|
|
6353
|
-
|
|
6374
|
+
resolve16(list[0]);
|
|
6354
6375
|
} catch {
|
|
6355
|
-
|
|
6376
|
+
resolve16(null);
|
|
6356
6377
|
}
|
|
6357
6378
|
});
|
|
6358
6379
|
});
|
|
6359
|
-
req.on("error", () =>
|
|
6380
|
+
req.on("error", () => resolve16(null));
|
|
6360
6381
|
req.setTimeout(2e3, () => {
|
|
6361
6382
|
req.destroy();
|
|
6362
|
-
|
|
6383
|
+
resolve16(null);
|
|
6363
6384
|
});
|
|
6364
6385
|
});
|
|
6365
6386
|
}
|
|
@@ -6370,7 +6391,7 @@ var DaemonCdpManager = class {
|
|
|
6370
6391
|
this.extensionProviders = providers;
|
|
6371
6392
|
}
|
|
6372
6393
|
connectToTarget(wsUrl) {
|
|
6373
|
-
return new Promise((
|
|
6394
|
+
return new Promise((resolve16) => {
|
|
6374
6395
|
this.ws = new import_ws.default(wsUrl);
|
|
6375
6396
|
this.ws.on("open", async () => {
|
|
6376
6397
|
this._connected = true;
|
|
@@ -6380,17 +6401,17 @@ var DaemonCdpManager = class {
|
|
|
6380
6401
|
}
|
|
6381
6402
|
this.connectBrowserWs().catch(() => {
|
|
6382
6403
|
});
|
|
6383
|
-
|
|
6404
|
+
resolve16(true);
|
|
6384
6405
|
});
|
|
6385
6406
|
this.ws.on("message", (data) => {
|
|
6386
6407
|
try {
|
|
6387
6408
|
const msg = JSON.parse(data.toString());
|
|
6388
6409
|
if (msg.id && this.pending.has(msg.id)) {
|
|
6389
|
-
const { resolve:
|
|
6410
|
+
const { resolve: resolve17, reject } = this.pending.get(msg.id);
|
|
6390
6411
|
this.pending.delete(msg.id);
|
|
6391
6412
|
this.failureCount = 0;
|
|
6392
6413
|
if (msg.error) reject(new Error(msg.error.message));
|
|
6393
|
-
else
|
|
6414
|
+
else resolve17(msg.result);
|
|
6394
6415
|
} else if (msg.method === "Runtime.executionContextCreated") {
|
|
6395
6416
|
this.contexts.add(msg.params.context.id);
|
|
6396
6417
|
} else if (msg.method === "Runtime.executionContextDestroyed") {
|
|
@@ -6413,7 +6434,7 @@ var DaemonCdpManager = class {
|
|
|
6413
6434
|
this.ws.on("error", (err) => {
|
|
6414
6435
|
this.log(`[CDP] WebSocket error: ${err.message}`);
|
|
6415
6436
|
this._connected = false;
|
|
6416
|
-
|
|
6437
|
+
resolve16(false);
|
|
6417
6438
|
});
|
|
6418
6439
|
});
|
|
6419
6440
|
}
|
|
@@ -6427,7 +6448,7 @@ var DaemonCdpManager = class {
|
|
|
6427
6448
|
return;
|
|
6428
6449
|
}
|
|
6429
6450
|
this.log(`[CDP] Connecting browser WS for target discovery...`);
|
|
6430
|
-
await new Promise((
|
|
6451
|
+
await new Promise((resolve16, reject) => {
|
|
6431
6452
|
this.browserWs = new import_ws.default(browserWsUrl);
|
|
6432
6453
|
this.browserWs.on("open", async () => {
|
|
6433
6454
|
this._browserConnected = true;
|
|
@@ -6437,16 +6458,16 @@ var DaemonCdpManager = class {
|
|
|
6437
6458
|
} catch (e) {
|
|
6438
6459
|
this.log(`[CDP] setDiscoverTargets failed: ${e.message}`);
|
|
6439
6460
|
}
|
|
6440
|
-
|
|
6461
|
+
resolve16();
|
|
6441
6462
|
});
|
|
6442
6463
|
this.browserWs.on("message", (data) => {
|
|
6443
6464
|
try {
|
|
6444
6465
|
const msg = JSON.parse(data.toString());
|
|
6445
6466
|
if (msg.id && this.browserPending.has(msg.id)) {
|
|
6446
|
-
const { resolve:
|
|
6467
|
+
const { resolve: resolve17, reject: reject2 } = this.browserPending.get(msg.id);
|
|
6447
6468
|
this.browserPending.delete(msg.id);
|
|
6448
6469
|
if (msg.error) reject2(new Error(msg.error.message));
|
|
6449
|
-
else
|
|
6470
|
+
else resolve17(msg.result);
|
|
6450
6471
|
}
|
|
6451
6472
|
} catch {
|
|
6452
6473
|
}
|
|
@@ -6466,31 +6487,31 @@ var DaemonCdpManager = class {
|
|
|
6466
6487
|
}
|
|
6467
6488
|
}
|
|
6468
6489
|
getBrowserWsUrl() {
|
|
6469
|
-
return new Promise((
|
|
6490
|
+
return new Promise((resolve16) => {
|
|
6470
6491
|
const req = http.get(`http://127.0.0.1:${this.port}/json/version`, (res) => {
|
|
6471
6492
|
let data = "";
|
|
6472
6493
|
res.on("data", (chunk) => data += chunk.toString());
|
|
6473
6494
|
res.on("end", () => {
|
|
6474
6495
|
try {
|
|
6475
6496
|
const info = JSON.parse(data);
|
|
6476
|
-
|
|
6497
|
+
resolve16(info.webSocketDebuggerUrl || null);
|
|
6477
6498
|
} catch {
|
|
6478
|
-
|
|
6499
|
+
resolve16(null);
|
|
6479
6500
|
}
|
|
6480
6501
|
});
|
|
6481
6502
|
});
|
|
6482
|
-
req.on("error", () =>
|
|
6503
|
+
req.on("error", () => resolve16(null));
|
|
6483
6504
|
req.setTimeout(3e3, () => {
|
|
6484
6505
|
req.destroy();
|
|
6485
|
-
|
|
6506
|
+
resolve16(null);
|
|
6486
6507
|
});
|
|
6487
6508
|
});
|
|
6488
6509
|
}
|
|
6489
6510
|
sendBrowser(method, params = {}, timeoutMs = 15e3) {
|
|
6490
|
-
return new Promise((
|
|
6511
|
+
return new Promise((resolve16, reject) => {
|
|
6491
6512
|
if (!this.browserWs || !this._browserConnected) return reject(new Error("Browser WS not connected"));
|
|
6492
6513
|
const id = this.browserMsgId++;
|
|
6493
|
-
this.browserPending.set(id, { resolve:
|
|
6514
|
+
this.browserPending.set(id, { resolve: resolve16, reject });
|
|
6494
6515
|
this.browserWs.send(JSON.stringify({ id, method, params }));
|
|
6495
6516
|
setTimeout(() => {
|
|
6496
6517
|
if (this.browserPending.has(id)) {
|
|
@@ -6530,11 +6551,11 @@ var DaemonCdpManager = class {
|
|
|
6530
6551
|
}
|
|
6531
6552
|
// ─── CDP Protocol ────────────────────────────────────────
|
|
6532
6553
|
sendInternal(method, params = {}, timeoutMs = 15e3) {
|
|
6533
|
-
return new Promise((
|
|
6554
|
+
return new Promise((resolve16, reject) => {
|
|
6534
6555
|
if (!this.ws || !this._connected) return reject(new Error("CDP not connected"));
|
|
6535
6556
|
if (this.ws.readyState !== import_ws.default.OPEN) return reject(new Error("WebSocket not open"));
|
|
6536
6557
|
const id = this.msgId++;
|
|
6537
|
-
this.pending.set(id, { resolve:
|
|
6558
|
+
this.pending.set(id, { resolve: resolve16, reject });
|
|
6538
6559
|
this.ws.send(JSON.stringify({ id, method, params }));
|
|
6539
6560
|
setTimeout(() => {
|
|
6540
6561
|
if (this.pending.has(id)) {
|
|
@@ -6783,7 +6804,7 @@ var DaemonCdpManager = class {
|
|
|
6783
6804
|
const browserWs = this.browserWs;
|
|
6784
6805
|
let msgId = this.browserMsgId;
|
|
6785
6806
|
const sendWs = (method, params = {}, sessionId) => {
|
|
6786
|
-
return new Promise((
|
|
6807
|
+
return new Promise((resolve16, reject) => {
|
|
6787
6808
|
const mid = msgId++;
|
|
6788
6809
|
this.browserMsgId = msgId;
|
|
6789
6810
|
const handler = (raw) => {
|
|
@@ -6792,7 +6813,7 @@ var DaemonCdpManager = class {
|
|
|
6792
6813
|
if (msg.id === mid) {
|
|
6793
6814
|
browserWs.removeListener("message", handler);
|
|
6794
6815
|
if (msg.error) reject(new Error(msg.error.message || JSON.stringify(msg.error)));
|
|
6795
|
-
else
|
|
6816
|
+
else resolve16(msg.result);
|
|
6796
6817
|
}
|
|
6797
6818
|
} catch {
|
|
6798
6819
|
}
|
|
@@ -6993,14 +7014,14 @@ var DaemonCdpManager = class {
|
|
|
6993
7014
|
if (!ws || ws.readyState !== import_ws.default.OPEN) {
|
|
6994
7015
|
throw new Error("CDP not connected");
|
|
6995
7016
|
}
|
|
6996
|
-
return new Promise((
|
|
7017
|
+
return new Promise((resolve16, reject) => {
|
|
6997
7018
|
const id = getNextId();
|
|
6998
7019
|
pendingMap.set(id, {
|
|
6999
7020
|
resolve: (result) => {
|
|
7000
7021
|
if (result?.result?.subtype === "error") {
|
|
7001
7022
|
reject(new Error(result.result.description));
|
|
7002
7023
|
} else {
|
|
7003
|
-
|
|
7024
|
+
resolve16(result?.result?.value);
|
|
7004
7025
|
}
|
|
7005
7026
|
},
|
|
7006
7027
|
reject
|
|
@@ -7032,10 +7053,10 @@ var DaemonCdpManager = class {
|
|
|
7032
7053
|
throw new Error("CDP not connected");
|
|
7033
7054
|
}
|
|
7034
7055
|
const sendViaSession = (method, params = {}) => {
|
|
7035
|
-
return new Promise((
|
|
7056
|
+
return new Promise((resolve16, reject) => {
|
|
7036
7057
|
const pendingMap = this._browserConnected ? this.browserPending : this.pending;
|
|
7037
7058
|
const id = this._browserConnected ? this.browserMsgId++ : this.msgId++;
|
|
7038
|
-
pendingMap.set(id, { resolve:
|
|
7059
|
+
pendingMap.set(id, { resolve: resolve16, reject });
|
|
7039
7060
|
ws.send(JSON.stringify({ id, sessionId, method, params }));
|
|
7040
7061
|
setTimeout(() => {
|
|
7041
7062
|
if (pendingMap.has(id)) {
|
|
@@ -11247,7 +11268,8 @@ function buildIdeWorkspaceSession(state, cdpManagers, options) {
|
|
|
11247
11268
|
},
|
|
11248
11269
|
errorMessage: state.errorMessage,
|
|
11249
11270
|
errorReason: state.errorReason,
|
|
11250
|
-
lastUpdated: state.lastUpdated
|
|
11271
|
+
lastUpdated: state.lastUpdated,
|
|
11272
|
+
settings: state.settings
|
|
11251
11273
|
};
|
|
11252
11274
|
}
|
|
11253
11275
|
function buildExtensionAgentSession(parent, ext, options) {
|
|
@@ -11282,7 +11304,8 @@ function buildExtensionAgentSession(parent, ext, options) {
|
|
|
11282
11304
|
},
|
|
11283
11305
|
errorMessage: ext.errorMessage,
|
|
11284
11306
|
errorReason: ext.errorReason,
|
|
11285
|
-
lastUpdated: ext.lastUpdated
|
|
11307
|
+
lastUpdated: ext.lastUpdated,
|
|
11308
|
+
settings: ext.settings
|
|
11286
11309
|
};
|
|
11287
11310
|
}
|
|
11288
11311
|
function shouldIncludeExtensionSession(ext) {
|
|
@@ -11348,7 +11371,8 @@ function buildCliSession(state, options) {
|
|
|
11348
11371
|
},
|
|
11349
11372
|
errorMessage: state.errorMessage,
|
|
11350
11373
|
errorReason: state.errorReason,
|
|
11351
|
-
lastUpdated: state.lastUpdated
|
|
11374
|
+
lastUpdated: state.lastUpdated,
|
|
11375
|
+
settings: state.settings
|
|
11352
11376
|
};
|
|
11353
11377
|
}
|
|
11354
11378
|
function buildAcpSession(state, options) {
|
|
@@ -11382,7 +11406,8 @@ function buildAcpSession(state, options) {
|
|
|
11382
11406
|
},
|
|
11383
11407
|
errorMessage: state.errorMessage,
|
|
11384
11408
|
errorReason: state.errorReason,
|
|
11385
|
-
lastUpdated: state.lastUpdated
|
|
11409
|
+
lastUpdated: state.lastUpdated,
|
|
11410
|
+
settings: state.settings
|
|
11386
11411
|
};
|
|
11387
11412
|
}
|
|
11388
11413
|
function buildSessionEntries(allStates, cdpManagers, options = {}) {
|
|
@@ -11749,6 +11774,8 @@ function getSendChatInputEnvelope(args) {
|
|
|
11749
11774
|
function getHistorySessionId(h, args) {
|
|
11750
11775
|
const explicit = typeof args?.historySessionId === "string" ? args.historySessionId.trim() : "";
|
|
11751
11776
|
if (explicit) return explicit;
|
|
11777
|
+
const explicitProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : "";
|
|
11778
|
+
if (explicitProviderSessionId) return explicitProviderSessionId;
|
|
11752
11779
|
const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
|
|
11753
11780
|
if (!targetSessionId) return void 0;
|
|
11754
11781
|
const instance = h.ctx.instanceManager?.getInstance(targetSessionId);
|
|
@@ -12214,7 +12241,7 @@ function getCliVisibleTranscriptCount(adapter) {
|
|
|
12214
12241
|
async function getStableExtensionBaseline(h) {
|
|
12215
12242
|
const first = await readExtensionChatState(h);
|
|
12216
12243
|
if (getStateMessageCount(first) > 0 || getStateLastSignature(first)) return first;
|
|
12217
|
-
await new Promise((
|
|
12244
|
+
await new Promise((resolve16) => setTimeout(resolve16, 150));
|
|
12218
12245
|
const second = await readExtensionChatState(h);
|
|
12219
12246
|
return getStateMessageCount(second) >= getStateMessageCount(first) ? second : first;
|
|
12220
12247
|
}
|
|
@@ -12222,7 +12249,7 @@ async function verifyExtensionSendObserved(h, before) {
|
|
|
12222
12249
|
const beforeCount = getStateMessageCount(before);
|
|
12223
12250
|
const beforeSignature = getStateLastSignature(before);
|
|
12224
12251
|
for (let attempt = 0; attempt < 12; attempt += 1) {
|
|
12225
|
-
await new Promise((
|
|
12252
|
+
await new Promise((resolve16) => setTimeout(resolve16, 250));
|
|
12226
12253
|
const state = await readExtensionChatState(h);
|
|
12227
12254
|
if (state?.status === "waiting_approval") return true;
|
|
12228
12255
|
const afterCount = getStateMessageCount(state);
|
|
@@ -12312,7 +12339,32 @@ async function handleReadChat(h, args) {
|
|
|
12312
12339
|
...coverage ? { coverage } : {}
|
|
12313
12340
|
}, args);
|
|
12314
12341
|
}
|
|
12315
|
-
|
|
12342
|
+
const historyLimit = normalizeReadChatTailLimit(args);
|
|
12343
|
+
try {
|
|
12344
|
+
const agentStr = provider?.type || args?.agentType || getCurrentProviderType(h);
|
|
12345
|
+
const workspace = typeof args?.workspace === "string" ? args.workspace : typeof h.currentSession?.workspace === "string" ? h.currentSession.workspace : void 0;
|
|
12346
|
+
const history = readProviderChatHistory(agentStr, {
|
|
12347
|
+
canonicalHistory: provider?.canonicalHistory,
|
|
12348
|
+
historySessionId,
|
|
12349
|
+
workspace,
|
|
12350
|
+
offset: 0,
|
|
12351
|
+
limit: historyLimit,
|
|
12352
|
+
excludeRecentCount: 0,
|
|
12353
|
+
historyBehavior: provider?.historyBehavior,
|
|
12354
|
+
scripts: provider?.scripts
|
|
12355
|
+
});
|
|
12356
|
+
const historyProviderSessionId = typeof history?.providerSessionId === "string" ? history.providerSessionId : historySessionId;
|
|
12357
|
+
return buildReadChatCommandResult({
|
|
12358
|
+
messages: Array.isArray(history?.messages) ? history.messages : [],
|
|
12359
|
+
status: "idle",
|
|
12360
|
+
...typeof history?.title === "string" ? { title: history.title } : {},
|
|
12361
|
+
...historyProviderSessionId ? { providerSessionId: historyProviderSessionId } : {},
|
|
12362
|
+
...provider?.historyBehavior?.transcriptAuthority === "provider" || provider?.historyBehavior?.transcriptAuthority === "daemon" ? { transcriptAuthority: (provider?.historyBehavior).transcriptAuthority } : {},
|
|
12363
|
+
coverage: "tail"
|
|
12364
|
+
}, args);
|
|
12365
|
+
} catch (error) {
|
|
12366
|
+
return { success: false, error: error?.message || `${transport} adapter not found` };
|
|
12367
|
+
}
|
|
12316
12368
|
}
|
|
12317
12369
|
if (isExtensionTransport(transport)) {
|
|
12318
12370
|
let extensionReadChatError = "";
|
|
@@ -13830,7 +13882,7 @@ async function executeProviderScript(h, args, scriptName) {
|
|
|
13830
13882
|
const enterCount = cliCommand.enterCount || 1;
|
|
13831
13883
|
await adapter.writeRaw(cliCommand.text + "\r");
|
|
13832
13884
|
for (let i = 1; i < enterCount; i += 1) {
|
|
13833
|
-
await new Promise((
|
|
13885
|
+
await new Promise((resolve16) => setTimeout(resolve16, 50));
|
|
13834
13886
|
await adapter.writeRaw("\r");
|
|
13835
13887
|
}
|
|
13836
13888
|
}
|
|
@@ -14515,7 +14567,7 @@ var DaemonCommandHandler = class {
|
|
|
14515
14567
|
try {
|
|
14516
14568
|
const http3 = await import("http");
|
|
14517
14569
|
const postData = JSON.stringify(body);
|
|
14518
|
-
const result = await new Promise((
|
|
14570
|
+
const result = await new Promise((resolve16, reject) => {
|
|
14519
14571
|
const req = http3.request({
|
|
14520
14572
|
hostname: "127.0.0.1",
|
|
14521
14573
|
port: 19280,
|
|
@@ -14527,9 +14579,9 @@ var DaemonCommandHandler = class {
|
|
|
14527
14579
|
res.on("data", (chunk) => data += chunk);
|
|
14528
14580
|
res.on("end", () => {
|
|
14529
14581
|
try {
|
|
14530
|
-
|
|
14582
|
+
resolve16(JSON.parse(data));
|
|
14531
14583
|
} catch {
|
|
14532
|
-
|
|
14584
|
+
resolve16({ raw: data });
|
|
14533
14585
|
}
|
|
14534
14586
|
});
|
|
14535
14587
|
});
|
|
@@ -14547,15 +14599,15 @@ var DaemonCommandHandler = class {
|
|
|
14547
14599
|
if (!providerType) return { success: false, error: "providerType required" };
|
|
14548
14600
|
try {
|
|
14549
14601
|
const http3 = await import("http");
|
|
14550
|
-
const result = await new Promise((
|
|
14602
|
+
const result = await new Promise((resolve16, reject) => {
|
|
14551
14603
|
http3.get(`http://127.0.0.1:19280/api/providers/${providerType}/${endpoint}`, (res) => {
|
|
14552
14604
|
let data = "";
|
|
14553
14605
|
res.on("data", (chunk) => data += chunk);
|
|
14554
14606
|
res.on("end", () => {
|
|
14555
14607
|
try {
|
|
14556
|
-
|
|
14608
|
+
resolve16(JSON.parse(data));
|
|
14557
14609
|
} catch {
|
|
14558
|
-
|
|
14610
|
+
resolve16({ raw: data });
|
|
14559
14611
|
}
|
|
14560
14612
|
});
|
|
14561
14613
|
}).on("error", reject);
|
|
@@ -14569,7 +14621,7 @@ var DaemonCommandHandler = class {
|
|
|
14569
14621
|
try {
|
|
14570
14622
|
const http3 = await import("http");
|
|
14571
14623
|
const postData = JSON.stringify(args || {});
|
|
14572
|
-
const result = await new Promise((
|
|
14624
|
+
const result = await new Promise((resolve16, reject) => {
|
|
14573
14625
|
const req = http3.request({
|
|
14574
14626
|
hostname: "127.0.0.1",
|
|
14575
14627
|
port: 19280,
|
|
@@ -14581,9 +14633,9 @@ var DaemonCommandHandler = class {
|
|
|
14581
14633
|
res.on("data", (chunk) => data += chunk);
|
|
14582
14634
|
res.on("end", () => {
|
|
14583
14635
|
try {
|
|
14584
|
-
|
|
14636
|
+
resolve16(JSON.parse(data));
|
|
14585
14637
|
} catch {
|
|
14586
|
-
|
|
14638
|
+
resolve16({ raw: data });
|
|
14587
14639
|
}
|
|
14588
14640
|
});
|
|
14589
14641
|
});
|
|
@@ -14707,7 +14759,7 @@ async function waitForCliAdapterReady(adapter, options) {
|
|
|
14707
14759
|
if (status === "stopped") {
|
|
14708
14760
|
throw new Error("CLI runtime stopped before it became ready");
|
|
14709
14761
|
}
|
|
14710
|
-
await new Promise((
|
|
14762
|
+
await new Promise((resolve16) => setTimeout(resolve16, pollMs));
|
|
14711
14763
|
}
|
|
14712
14764
|
throw new Error(`CLI runtime did not become ready within ${timeoutMs}ms`);
|
|
14713
14765
|
}
|
|
@@ -14863,7 +14915,7 @@ var CliProviderInstance = class {
|
|
|
14863
14915
|
this.errorMessage = void 0;
|
|
14864
14916
|
this.errorReason = void 0;
|
|
14865
14917
|
}
|
|
14866
|
-
const autoApproveActive = adapterStatus
|
|
14918
|
+
const autoApproveActive = this.maybeAutoApproveStatus(adapterStatus, Date.now());
|
|
14867
14919
|
const visibleStatus = parseErrorMessage ? "error" : autoApproveActive ? "generating" : adapterStatus.status;
|
|
14868
14920
|
const parsedProviderSessionId = normalizeProviderSessionId(
|
|
14869
14921
|
this.provider,
|
|
@@ -15050,18 +15102,14 @@ var CliProviderInstance = class {
|
|
|
15050
15102
|
const enterCount = cliCommand.enterCount || 1;
|
|
15051
15103
|
await this.adapter.writeRaw(cliCommand.text + "\r");
|
|
15052
15104
|
for (let i = 1; i < enterCount; i += 1) {
|
|
15053
|
-
await new Promise((
|
|
15105
|
+
await new Promise((resolve16) => setTimeout(resolve16, 50));
|
|
15054
15106
|
await this.adapter.writeRaw("\r");
|
|
15055
15107
|
}
|
|
15056
15108
|
}
|
|
15057
15109
|
this.applyProviderResponse(parsed.payload, { phase: "immediate" });
|
|
15058
15110
|
}
|
|
15059
|
-
|
|
15060
|
-
const
|
|
15061
|
-
const adapterStatus = this.adapter.getStatus({ allowParse: false });
|
|
15062
|
-
const parsedStatus = null;
|
|
15063
|
-
const rawStatus = adapterStatus.status;
|
|
15064
|
-
const autoApproveActive = rawStatus === "waiting_approval" && this.shouldAutoApprove();
|
|
15111
|
+
maybeAutoApproveStatus(adapterStatus, now = Date.now()) {
|
|
15112
|
+
const autoApproveActive = adapterStatus?.status === "waiting_approval" && this.shouldAutoApprove();
|
|
15065
15113
|
if (autoApproveActive && !this.autoApproveBusy) {
|
|
15066
15114
|
this.autoApproveBusy = true;
|
|
15067
15115
|
if (this.autoApproveBusyTimer) clearTimeout(this.autoApproveBusyTimer);
|
|
@@ -15069,12 +15117,21 @@ var CliProviderInstance = class {
|
|
|
15069
15117
|
this.autoApproveBusy = false;
|
|
15070
15118
|
this.autoApproveBusyTimer = null;
|
|
15071
15119
|
}, 2e3);
|
|
15072
|
-
const
|
|
15073
|
-
|
|
15120
|
+
const modal = adapterStatus.activeModal;
|
|
15121
|
+
const { index: buttonIndex, label: buttonLabel } = pickApprovalButton(modal?.buttons, this.provider);
|
|
15122
|
+
this.recordAutoApproval(modal?.message, buttonLabel, now);
|
|
15074
15123
|
setTimeout(() => {
|
|
15075
15124
|
this.adapter.resolveModal(buttonIndex);
|
|
15076
15125
|
}, 0);
|
|
15077
15126
|
}
|
|
15127
|
+
return autoApproveActive;
|
|
15128
|
+
}
|
|
15129
|
+
detectStatusTransition() {
|
|
15130
|
+
const now = Date.now();
|
|
15131
|
+
const adapterStatus = this.adapter.getStatus({ allowParse: false });
|
|
15132
|
+
const parsedStatus = null;
|
|
15133
|
+
const rawStatus = adapterStatus.status;
|
|
15134
|
+
const autoApproveActive = this.maybeAutoApproveStatus(adapterStatus, now);
|
|
15078
15135
|
const newStatus = autoApproveActive ? "generating" : rawStatus;
|
|
15079
15136
|
const dirName = this.workingDir.split("/").filter(Boolean).pop() || "session";
|
|
15080
15137
|
const chatTitle = `${this.provider.name} \xB7 ${dirName}`;
|
|
@@ -16150,13 +16207,13 @@ var AcpProviderInstance = class {
|
|
|
16150
16207
|
}
|
|
16151
16208
|
this.currentStatus = "waiting_approval";
|
|
16152
16209
|
this.detectStatusTransition();
|
|
16153
|
-
const approved = await new Promise((
|
|
16154
|
-
this.permissionResolvers.push(
|
|
16210
|
+
const approved = await new Promise((resolve16) => {
|
|
16211
|
+
this.permissionResolvers.push(resolve16);
|
|
16155
16212
|
setTimeout(() => {
|
|
16156
|
-
const idx = this.permissionResolvers.indexOf(
|
|
16213
|
+
const idx = this.permissionResolvers.indexOf(resolve16);
|
|
16157
16214
|
if (idx >= 0) {
|
|
16158
16215
|
this.permissionResolvers.splice(idx, 1);
|
|
16159
|
-
|
|
16216
|
+
resolve16(false);
|
|
16160
16217
|
}
|
|
16161
16218
|
}, 3e5);
|
|
16162
16219
|
});
|
|
@@ -17140,7 +17197,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
17140
17197
|
resolvedDir,
|
|
17141
17198
|
resolvedCliArgs,
|
|
17142
17199
|
resolvedProvider,
|
|
17143
|
-
this.providerLoader.getSettings(normalizedType),
|
|
17200
|
+
{ ...this.providerLoader.getSettings(normalizedType), ...options?.settingsOverride || {} },
|
|
17144
17201
|
false,
|
|
17145
17202
|
{
|
|
17146
17203
|
providerSessionId: sessionBinding.providerSessionId,
|
|
@@ -17394,7 +17451,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
17394
17451
|
dir,
|
|
17395
17452
|
args?.cliArgs,
|
|
17396
17453
|
args?.initialModel,
|
|
17397
|
-
{ resumeSessionId: args?.resumeSessionId }
|
|
17454
|
+
{ resumeSessionId: args?.resumeSessionId, settingsOverride: args?.settings }
|
|
17398
17455
|
);
|
|
17399
17456
|
return {
|
|
17400
17457
|
success: true,
|
|
@@ -18742,7 +18799,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18742
18799
|
return { updated: false };
|
|
18743
18800
|
}
|
|
18744
18801
|
try {
|
|
18745
|
-
const etag = await new Promise((
|
|
18802
|
+
const etag = await new Promise((resolve16, reject) => {
|
|
18746
18803
|
const options = {
|
|
18747
18804
|
method: "HEAD",
|
|
18748
18805
|
hostname: "github.com",
|
|
@@ -18760,7 +18817,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18760
18817
|
headers: { "User-Agent": "adhdev-launcher" },
|
|
18761
18818
|
timeout: 1e4
|
|
18762
18819
|
}, (res2) => {
|
|
18763
|
-
|
|
18820
|
+
resolve16(res2.headers.etag || res2.headers["last-modified"] || "");
|
|
18764
18821
|
});
|
|
18765
18822
|
req2.on("error", reject);
|
|
18766
18823
|
req2.on("timeout", () => {
|
|
@@ -18769,7 +18826,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18769
18826
|
});
|
|
18770
18827
|
req2.end();
|
|
18771
18828
|
} else {
|
|
18772
|
-
|
|
18829
|
+
resolve16(res.headers.etag || res.headers["last-modified"] || "");
|
|
18773
18830
|
}
|
|
18774
18831
|
});
|
|
18775
18832
|
req.on("error", reject);
|
|
@@ -18833,7 +18890,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18833
18890
|
downloadFile(url, destPath) {
|
|
18834
18891
|
const https = require("https");
|
|
18835
18892
|
const http3 = require("http");
|
|
18836
|
-
return new Promise((
|
|
18893
|
+
return new Promise((resolve16, reject) => {
|
|
18837
18894
|
const doRequest = (reqUrl, redirectCount = 0) => {
|
|
18838
18895
|
if (redirectCount > 5) {
|
|
18839
18896
|
reject(new Error("Too many redirects"));
|
|
@@ -18853,7 +18910,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
18853
18910
|
res.pipe(ws);
|
|
18854
18911
|
ws.on("finish", () => {
|
|
18855
18912
|
ws.close();
|
|
18856
|
-
|
|
18913
|
+
resolve16();
|
|
18857
18914
|
});
|
|
18858
18915
|
ws.on("error", reject);
|
|
18859
18916
|
});
|
|
@@ -19432,17 +19489,17 @@ async function findFreePort(ports) {
|
|
|
19432
19489
|
throw new Error("No free port found");
|
|
19433
19490
|
}
|
|
19434
19491
|
function checkPortFree(port) {
|
|
19435
|
-
return new Promise((
|
|
19492
|
+
return new Promise((resolve16) => {
|
|
19436
19493
|
const server = net.createServer();
|
|
19437
19494
|
server.unref();
|
|
19438
|
-
server.on("error", () =>
|
|
19495
|
+
server.on("error", () => resolve16(false));
|
|
19439
19496
|
server.listen(port, "127.0.0.1", () => {
|
|
19440
|
-
server.close(() =>
|
|
19497
|
+
server.close(() => resolve16(true));
|
|
19441
19498
|
});
|
|
19442
19499
|
});
|
|
19443
19500
|
}
|
|
19444
19501
|
async function isCdpActive(port) {
|
|
19445
|
-
return new Promise((
|
|
19502
|
+
return new Promise((resolve16) => {
|
|
19446
19503
|
const req = require("http").get(`http://127.0.0.1:${port}/json/version`, {
|
|
19447
19504
|
timeout: 2e3
|
|
19448
19505
|
}, (res) => {
|
|
@@ -19451,16 +19508,16 @@ async function isCdpActive(port) {
|
|
|
19451
19508
|
res.on("end", () => {
|
|
19452
19509
|
try {
|
|
19453
19510
|
const info = JSON.parse(data);
|
|
19454
|
-
|
|
19511
|
+
resolve16(!!info["WebKit-Version"] || !!info["Browser"]);
|
|
19455
19512
|
} catch {
|
|
19456
|
-
|
|
19513
|
+
resolve16(false);
|
|
19457
19514
|
}
|
|
19458
19515
|
});
|
|
19459
19516
|
});
|
|
19460
|
-
req.on("error", () =>
|
|
19517
|
+
req.on("error", () => resolve16(false));
|
|
19461
19518
|
req.on("timeout", () => {
|
|
19462
19519
|
req.destroy();
|
|
19463
|
-
|
|
19520
|
+
resolve16(false);
|
|
19464
19521
|
});
|
|
19465
19522
|
});
|
|
19466
19523
|
}
|
|
@@ -19936,7 +19993,9 @@ cleanOldFiles();
|
|
|
19936
19993
|
init_logger();
|
|
19937
19994
|
|
|
19938
19995
|
// src/commands/mesh-coordinator.ts
|
|
19939
|
-
var
|
|
19996
|
+
var import_node_fs2 = require("fs");
|
|
19997
|
+
var import_node_module2 = require("module");
|
|
19998
|
+
var import_node_path = require("path");
|
|
19940
19999
|
var DEFAULT_SERVER_NAME = "adhdev-mesh";
|
|
19941
20000
|
var DEFAULT_ADHDEV_MCP_COMMAND = "adhdev-mcp";
|
|
19942
20001
|
function resolveMeshCoordinatorSetup(options) {
|
|
@@ -19961,11 +20020,23 @@ function resolveMeshCoordinatorSetup(options) {
|
|
|
19961
20020
|
if (!path26) {
|
|
19962
20021
|
return { kind: "unsupported", reason: "Provider auto-import MCP config is missing a config path" };
|
|
19963
20022
|
}
|
|
20023
|
+
const mcpServer = resolveAdhdevMcpServerLaunch({
|
|
20024
|
+
meshId,
|
|
20025
|
+
nodeExecutable: options.nodeExecutable,
|
|
20026
|
+
adhdevMcpEntryPath: options.adhdevMcpEntryPath
|
|
20027
|
+
});
|
|
20028
|
+
if (!mcpServer) {
|
|
20029
|
+
return {
|
|
20030
|
+
kind: "unsupported",
|
|
20031
|
+
reason: "Could not resolve the ADHDev MCP server entrypoint without relying on a PATH bin shim"
|
|
20032
|
+
};
|
|
20033
|
+
}
|
|
19964
20034
|
return {
|
|
19965
20035
|
kind: "auto_import",
|
|
19966
20036
|
serverName,
|
|
19967
|
-
configPath: (0,
|
|
19968
|
-
configFormat: mcpConfig.format
|
|
20037
|
+
configPath: (0, import_node_path.join)(workspace, path26),
|
|
20038
|
+
configFormat: mcpConfig.format,
|
|
20039
|
+
mcpServer
|
|
19969
20040
|
};
|
|
19970
20041
|
}
|
|
19971
20042
|
if (mcpConfig.mode === "manual") {
|
|
@@ -19997,6 +20068,53 @@ function resolveMeshCoordinatorSetup(options) {
|
|
|
19997
20068
|
function renderMeshCoordinatorTemplate(template, values) {
|
|
19998
20069
|
return template.replace(/\{\{\s*(meshId|workspace|serverName|adhdevMcpCommand)\s*\}\}/g, (_, key) => values[key] || "");
|
|
19999
20070
|
}
|
|
20071
|
+
function resolveAdhdevMcpServerLaunch(options) {
|
|
20072
|
+
const entryPath = resolveAdhdevMcpEntryPath(options.adhdevMcpEntryPath);
|
|
20073
|
+
if (!entryPath) return null;
|
|
20074
|
+
return {
|
|
20075
|
+
command: options.nodeExecutable?.trim() || process.execPath,
|
|
20076
|
+
args: [entryPath, "--repo-mesh", options.meshId]
|
|
20077
|
+
};
|
|
20078
|
+
}
|
|
20079
|
+
function resolveAdhdevMcpEntryPath(explicitPath) {
|
|
20080
|
+
const explicit = explicitPath?.trim();
|
|
20081
|
+
if (explicit) return normalizeExistingPath(explicit) || explicit;
|
|
20082
|
+
const envPath = process.env.ADHDEV_MCP_SERVER_PATH?.trim();
|
|
20083
|
+
if (envPath) return normalizeExistingPath(envPath) || envPath;
|
|
20084
|
+
const candidates = [];
|
|
20085
|
+
const addCandidate = (candidate) => {
|
|
20086
|
+
if (!candidates.includes(candidate)) candidates.push(candidate);
|
|
20087
|
+
};
|
|
20088
|
+
const addPackagedCandidates = (baseFile) => {
|
|
20089
|
+
if (!baseFile) return;
|
|
20090
|
+
const realBase = normalizeExistingPath(baseFile) || baseFile;
|
|
20091
|
+
const dir = (0, import_node_path.dirname)(realBase);
|
|
20092
|
+
addCandidate((0, import_node_path.resolve)(dir, "../vendor/mcp-server/index.js"));
|
|
20093
|
+
addCandidate((0, import_node_path.resolve)(dir, "../../vendor/mcp-server/index.js"));
|
|
20094
|
+
addCandidate((0, import_node_path.resolve)(dir, "../../../vendor/mcp-server/index.js"));
|
|
20095
|
+
};
|
|
20096
|
+
addPackagedCandidates(process.argv[1]);
|
|
20097
|
+
for (const candidate of candidates) {
|
|
20098
|
+
const normalized = normalizeExistingPath(candidate);
|
|
20099
|
+
if (normalized) return normalized;
|
|
20100
|
+
}
|
|
20101
|
+
try {
|
|
20102
|
+
const requireBase = process.argv[1] ? normalizeExistingPath(process.argv[1]) || process.argv[1] : (0, import_node_path.join)(process.cwd(), "adhdev-daemon.js");
|
|
20103
|
+
const req = (0, import_node_module2.createRequire)(requireBase);
|
|
20104
|
+
const resolvedModule = req.resolve("@adhdev/mcp-server");
|
|
20105
|
+
return normalizeExistingPath(resolvedModule) || resolvedModule;
|
|
20106
|
+
} catch {
|
|
20107
|
+
return null;
|
|
20108
|
+
}
|
|
20109
|
+
}
|
|
20110
|
+
function normalizeExistingPath(filePath) {
|
|
20111
|
+
try {
|
|
20112
|
+
if (!(0, import_node_fs2.existsSync)(filePath)) return null;
|
|
20113
|
+
return import_node_fs2.realpathSync.native(filePath);
|
|
20114
|
+
} catch {
|
|
20115
|
+
return null;
|
|
20116
|
+
}
|
|
20117
|
+
}
|
|
20000
20118
|
|
|
20001
20119
|
// src/status/snapshot.ts
|
|
20002
20120
|
var os17 = __toESM(require("os"));
|
|
@@ -20504,7 +20622,7 @@ async function waitForPidExit(pid, timeoutMs) {
|
|
|
20504
20622
|
while (Date.now() - start < timeoutMs) {
|
|
20505
20623
|
try {
|
|
20506
20624
|
process.kill(pid, 0);
|
|
20507
|
-
await new Promise((
|
|
20625
|
+
await new Promise((resolve16) => setTimeout(resolve16, 250));
|
|
20508
20626
|
} catch {
|
|
20509
20627
|
return;
|
|
20510
20628
|
}
|
|
@@ -20615,7 +20733,7 @@ async function runDaemonUpgradeHelper(payload) {
|
|
|
20615
20733
|
appendUpgradeLog(installOutput.trim());
|
|
20616
20734
|
}
|
|
20617
20735
|
if (process.platform === "win32") {
|
|
20618
|
-
await new Promise((
|
|
20736
|
+
await new Promise((resolve16) => setTimeout(resolve16, 500));
|
|
20619
20737
|
cleanupStaleGlobalInstallDirs(payload.packageName, installCommand.surface);
|
|
20620
20738
|
appendUpgradeLog("Post-install staging cleanup complete");
|
|
20621
20739
|
}
|
|
@@ -21453,11 +21571,16 @@ var DaemonCommandRouter = class {
|
|
|
21453
21571
|
const cliType = typeof args?.cliType === "string" ? args.cliType.trim() : "claude-cli";
|
|
21454
21572
|
if (!meshId) return { success: false, error: "meshId required" };
|
|
21455
21573
|
try {
|
|
21456
|
-
const { getMesh: getMesh3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
21457
21574
|
const { buildCoordinatorSystemPrompt: buildCoordinatorSystemPrompt2 } = await Promise.resolve().then(() => (init_coordinator_prompt(), coordinator_prompt_exports));
|
|
21458
|
-
|
|
21575
|
+
let mesh;
|
|
21576
|
+
if (args?.inlineMesh && typeof args.inlineMesh === "object") {
|
|
21577
|
+
mesh = args.inlineMesh;
|
|
21578
|
+
} else {
|
|
21579
|
+
const { getMesh: getMesh3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
21580
|
+
mesh = getMesh3(meshId);
|
|
21581
|
+
}
|
|
21459
21582
|
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
21460
|
-
if (mesh.nodes.length === 0) return { success: false, error: "No nodes in mesh" };
|
|
21583
|
+
if (!Array.isArray(mesh.nodes) || mesh.nodes.length === 0) return { success: false, error: "No nodes in mesh" };
|
|
21461
21584
|
const workspace = mesh.nodes[0].workspace;
|
|
21462
21585
|
const providerMeta = this.deps.providerLoader.resolve?.(cliType) || this.deps.providerLoader.getMeta(cliType);
|
|
21463
21586
|
const coordinatorSetup = resolveMeshCoordinatorSetup({
|
|
@@ -21496,9 +21619,9 @@ var DaemonCommandRouter = class {
|
|
|
21496
21619
|
workspace
|
|
21497
21620
|
};
|
|
21498
21621
|
}
|
|
21499
|
-
const { existsSync:
|
|
21622
|
+
const { existsSync: existsSync22, readFileSync: readFileSync15, writeFileSync: writeFileSync12, copyFileSync: copyFileSync3 } = await import("fs");
|
|
21500
21623
|
const mcpConfigPath = coordinatorSetup.configPath;
|
|
21501
|
-
const hadExistingMcpConfig =
|
|
21624
|
+
const hadExistingMcpConfig = existsSync22(mcpConfigPath);
|
|
21502
21625
|
let existingMcpConfig = {};
|
|
21503
21626
|
if (hadExistingMcpConfig) {
|
|
21504
21627
|
try {
|
|
@@ -21512,8 +21635,8 @@ var DaemonCommandRouter = class {
|
|
|
21512
21635
|
mcpServers: {
|
|
21513
21636
|
...existingMcpConfig.mcpServers || {},
|
|
21514
21637
|
[coordinatorSetup.serverName]: {
|
|
21515
|
-
command:
|
|
21516
|
-
args:
|
|
21638
|
+
command: coordinatorSetup.mcpServer.command,
|
|
21639
|
+
args: coordinatorSetup.mcpServer.args
|
|
21517
21640
|
}
|
|
21518
21641
|
}
|
|
21519
21642
|
};
|
|
@@ -21525,10 +21648,20 @@ var DaemonCommandRouter = class {
|
|
|
21525
21648
|
} catch {
|
|
21526
21649
|
systemPrompt = `You are a Repo Mesh Coordinator for "${mesh.name}". Use the adhdev-mesh MCP tools (mesh_status, mesh_list_nodes, mesh_send_task, mesh_read_chat, mesh_launch_session, etc.) to orchestrate work across ${mesh.nodes.length} node(s).`;
|
|
21527
21650
|
}
|
|
21651
|
+
const cliArgs = [];
|
|
21652
|
+
if (systemPrompt) {
|
|
21653
|
+
cliArgs.push("--append-system-prompt", systemPrompt);
|
|
21654
|
+
}
|
|
21655
|
+
if (cliType === "claude-cli") {
|
|
21656
|
+
cliArgs.push("--mcp-config", coordinatorSetup.configPath);
|
|
21657
|
+
}
|
|
21528
21658
|
const launchResult = await this.deps.cliManager.handleCliCommand("launch_cli", {
|
|
21529
21659
|
cliType,
|
|
21530
21660
|
dir: workspace,
|
|
21531
|
-
|
|
21661
|
+
cliArgs: cliArgs.length > 0 ? cliArgs : void 0,
|
|
21662
|
+
settings: {
|
|
21663
|
+
meshCoordinatorFor: meshId
|
|
21664
|
+
}
|
|
21532
21665
|
});
|
|
21533
21666
|
if (!launchResult?.success) {
|
|
21534
21667
|
return { success: false, error: launchResult?.error || "Failed to launch CLI session" };
|
|
@@ -21831,7 +21964,8 @@ var DaemonStatusReporter = class {
|
|
|
21831
21964
|
workspace: session.workspace ?? null,
|
|
21832
21965
|
title: session.title,
|
|
21833
21966
|
cdpConnected: session.cdpConnected,
|
|
21834
|
-
summaryMetadata: session.summaryMetadata
|
|
21967
|
+
summaryMetadata: session.summaryMetadata,
|
|
21968
|
+
settings: session.settings
|
|
21835
21969
|
})),
|
|
21836
21970
|
p2p: payload.p2p,
|
|
21837
21971
|
timestamp: now
|
|
@@ -22156,7 +22290,7 @@ var ProviderStreamAdapter = class {
|
|
|
22156
22290
|
const beforeCount = this.messageCount(before);
|
|
22157
22291
|
const beforeSignature = this.lastMessageSignature(before);
|
|
22158
22292
|
for (let attempt = 0; attempt < 12; attempt += 1) {
|
|
22159
|
-
await new Promise((
|
|
22293
|
+
await new Promise((resolve16) => setTimeout(resolve16, 250));
|
|
22160
22294
|
let state;
|
|
22161
22295
|
try {
|
|
22162
22296
|
state = await this.readChat(evaluate);
|
|
@@ -22178,7 +22312,7 @@ var ProviderStreamAdapter = class {
|
|
|
22178
22312
|
if (this.messageCount(first) > 0 || this.lastMessageSignature(first)) {
|
|
22179
22313
|
return first;
|
|
22180
22314
|
}
|
|
22181
|
-
await new Promise((
|
|
22315
|
+
await new Promise((resolve16) => setTimeout(resolve16, 150));
|
|
22182
22316
|
const second = await this.readChat(evaluate);
|
|
22183
22317
|
return this.messageCount(second) >= this.messageCount(first) ? second : first;
|
|
22184
22318
|
}
|
|
@@ -22329,7 +22463,7 @@ var ProviderStreamAdapter = class {
|
|
|
22329
22463
|
if (typeof data.error === "string" && data.error.trim()) return false;
|
|
22330
22464
|
}
|
|
22331
22465
|
for (let attempt = 0; attempt < 6; attempt += 1) {
|
|
22332
|
-
await new Promise((
|
|
22466
|
+
await new Promise((resolve16) => setTimeout(resolve16, 250));
|
|
22333
22467
|
const state = await this.readChat(evaluate);
|
|
22334
22468
|
const title = this.getStateTitle(state);
|
|
22335
22469
|
if (this.titlesMatch(title, sessionId)) return true;
|
|
@@ -24922,7 +25056,7 @@ function getCliTargetBundle(ctx, type, instanceId) {
|
|
|
24922
25056
|
return { target, instance, adapter };
|
|
24923
25057
|
}
|
|
24924
25058
|
function sleep(ms) {
|
|
24925
|
-
return new Promise((
|
|
25059
|
+
return new Promise((resolve16) => setTimeout(resolve16, ms));
|
|
24926
25060
|
}
|
|
24927
25061
|
async function waitForCliReady(ctx, type, instanceId, timeoutMs) {
|
|
24928
25062
|
const startedAt = Date.now();
|
|
@@ -27168,15 +27302,15 @@ var DevServer = class _DevServer {
|
|
|
27168
27302
|
this.json(res, 500, { error: e.message });
|
|
27169
27303
|
}
|
|
27170
27304
|
});
|
|
27171
|
-
return new Promise((
|
|
27305
|
+
return new Promise((resolve16, reject) => {
|
|
27172
27306
|
this.server.listen(port, "127.0.0.1", () => {
|
|
27173
27307
|
this.log(`Dev server listening on http://127.0.0.1:${port}`);
|
|
27174
|
-
|
|
27308
|
+
resolve16();
|
|
27175
27309
|
});
|
|
27176
27310
|
this.server.on("error", (e) => {
|
|
27177
27311
|
if (e.code === "EADDRINUSE") {
|
|
27178
27312
|
this.log(`Port ${port} in use, skipping dev server`);
|
|
27179
|
-
|
|
27313
|
+
resolve16();
|
|
27180
27314
|
} else {
|
|
27181
27315
|
reject(e);
|
|
27182
27316
|
}
|
|
@@ -27258,20 +27392,20 @@ var DevServer = class _DevServer {
|
|
|
27258
27392
|
child.stderr?.on("data", (d) => {
|
|
27259
27393
|
stderr += d.toString().slice(0, 2e3);
|
|
27260
27394
|
});
|
|
27261
|
-
await new Promise((
|
|
27395
|
+
await new Promise((resolve16) => {
|
|
27262
27396
|
const timer = setTimeout(() => {
|
|
27263
27397
|
child.kill();
|
|
27264
|
-
|
|
27398
|
+
resolve16();
|
|
27265
27399
|
}, 3e3);
|
|
27266
27400
|
child.on("exit", () => {
|
|
27267
27401
|
clearTimeout(timer);
|
|
27268
|
-
|
|
27402
|
+
resolve16();
|
|
27269
27403
|
});
|
|
27270
27404
|
child.stdout?.once("data", () => {
|
|
27271
27405
|
setTimeout(() => {
|
|
27272
27406
|
child.kill();
|
|
27273
27407
|
clearTimeout(timer);
|
|
27274
|
-
|
|
27408
|
+
resolve16();
|
|
27275
27409
|
}, 500);
|
|
27276
27410
|
});
|
|
27277
27411
|
});
|
|
@@ -27774,14 +27908,14 @@ var DevServer = class _DevServer {
|
|
|
27774
27908
|
child.stderr?.on("data", (d) => {
|
|
27775
27909
|
stderr += d.toString();
|
|
27776
27910
|
});
|
|
27777
|
-
await new Promise((
|
|
27911
|
+
await new Promise((resolve16) => {
|
|
27778
27912
|
const timer = setTimeout(() => {
|
|
27779
27913
|
child.kill();
|
|
27780
|
-
|
|
27914
|
+
resolve16();
|
|
27781
27915
|
}, timeout);
|
|
27782
27916
|
child.on("exit", () => {
|
|
27783
27917
|
clearTimeout(timer);
|
|
27784
|
-
|
|
27918
|
+
resolve16();
|
|
27785
27919
|
});
|
|
27786
27920
|
});
|
|
27787
27921
|
const elapsed = Date.now() - start;
|
|
@@ -28451,14 +28585,14 @@ data: ${JSON.stringify(msg.data)}
|
|
|
28451
28585
|
res.end(JSON.stringify(data, null, 2));
|
|
28452
28586
|
}
|
|
28453
28587
|
async readBody(req) {
|
|
28454
|
-
return new Promise((
|
|
28588
|
+
return new Promise((resolve16) => {
|
|
28455
28589
|
let body = "";
|
|
28456
28590
|
req.on("data", (chunk) => body += chunk);
|
|
28457
28591
|
req.on("end", () => {
|
|
28458
28592
|
try {
|
|
28459
|
-
|
|
28593
|
+
resolve16(JSON.parse(body));
|
|
28460
28594
|
} catch {
|
|
28461
|
-
|
|
28595
|
+
resolve16({});
|
|
28462
28596
|
}
|
|
28463
28597
|
});
|
|
28464
28598
|
});
|
|
@@ -28968,7 +29102,7 @@ async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS) {
|
|
|
28968
29102
|
const deadline = Date.now() + timeoutMs;
|
|
28969
29103
|
while (Date.now() < deadline) {
|
|
28970
29104
|
if (await canConnect(endpoint)) return;
|
|
28971
|
-
await new Promise((
|
|
29105
|
+
await new Promise((resolve16) => setTimeout(resolve16, STARTUP_POLL_MS));
|
|
28972
29106
|
}
|
|
28973
29107
|
throw new Error(`Session host did not become ready within ${timeoutMs}ms`);
|
|
28974
29108
|
}
|
|
@@ -29146,10 +29280,10 @@ async function installExtension(ide, extension) {
|
|
|
29146
29280
|
const buffer = Buffer.from(await res.arrayBuffer());
|
|
29147
29281
|
const fs16 = await import("fs");
|
|
29148
29282
|
fs16.writeFileSync(vsixPath, buffer);
|
|
29149
|
-
return new Promise((
|
|
29283
|
+
return new Promise((resolve16) => {
|
|
29150
29284
|
const cmd = `"${ide.cliCommand}" --install-extension "${vsixPath}" --force`;
|
|
29151
29285
|
(0, import_child_process11.exec)(cmd, { timeout: 6e4 }, (error, _stdout, stderr) => {
|
|
29152
|
-
|
|
29286
|
+
resolve16({
|
|
29153
29287
|
extensionId: extension.id,
|
|
29154
29288
|
marketplaceId: extension.marketplaceId,
|
|
29155
29289
|
success: !error,
|
|
@@ -29162,11 +29296,11 @@ async function installExtension(ide, extension) {
|
|
|
29162
29296
|
} catch (e) {
|
|
29163
29297
|
}
|
|
29164
29298
|
}
|
|
29165
|
-
return new Promise((
|
|
29299
|
+
return new Promise((resolve16) => {
|
|
29166
29300
|
const cmd = `"${ide.cliCommand}" --install-extension ${extension.marketplaceId} --force`;
|
|
29167
29301
|
(0, import_child_process11.exec)(cmd, { timeout: 6e4 }, (error, stdout, stderr) => {
|
|
29168
29302
|
if (error) {
|
|
29169
|
-
|
|
29303
|
+
resolve16({
|
|
29170
29304
|
extensionId: extension.id,
|
|
29171
29305
|
marketplaceId: extension.marketplaceId,
|
|
29172
29306
|
success: false,
|
|
@@ -29174,7 +29308,7 @@ async function installExtension(ide, extension) {
|
|
|
29174
29308
|
error: stderr || error.message
|
|
29175
29309
|
});
|
|
29176
29310
|
} else {
|
|
29177
|
-
|
|
29311
|
+
resolve16({
|
|
29178
29312
|
extensionId: extension.id,
|
|
29179
29313
|
marketplaceId: extension.marketplaceId,
|
|
29180
29314
|
success: true,
|
|
@@ -29268,6 +29402,48 @@ var SessionRegistry = class {
|
|
|
29268
29402
|
// src/boot/daemon-lifecycle.ts
|
|
29269
29403
|
init_logger();
|
|
29270
29404
|
init_config();
|
|
29405
|
+
|
|
29406
|
+
// src/mesh/mesh-events.ts
|
|
29407
|
+
init_mesh_config();
|
|
29408
|
+
init_logger();
|
|
29409
|
+
function setupMeshEventForwarding(components) {
|
|
29410
|
+
components.instanceManager.onEvent((event) => {
|
|
29411
|
+
if (event.event !== "agent:generating_completed" && event.event !== "agent:waiting_approval") return;
|
|
29412
|
+
const instanceId = event.instanceId;
|
|
29413
|
+
if (!instanceId) return;
|
|
29414
|
+
const sourceInstance = components.instanceManager.getInstance(instanceId);
|
|
29415
|
+
if (!sourceInstance || sourceInstance.category !== "cli") return;
|
|
29416
|
+
const state = sourceInstance.getState();
|
|
29417
|
+
const workspace = state.workspace;
|
|
29418
|
+
if (!workspace) return;
|
|
29419
|
+
const mesh = getMeshByRepo(workspace);
|
|
29420
|
+
if (!mesh) return;
|
|
29421
|
+
const allInstances = components.instanceManager.getByCategory("cli");
|
|
29422
|
+
const coordinatorInstances = allInstances.filter((inst) => {
|
|
29423
|
+
const instState = inst.getState();
|
|
29424
|
+
if (instState.settings?.meshCoordinatorFor !== mesh.id) return false;
|
|
29425
|
+
if (instState.instanceId === instanceId) return false;
|
|
29426
|
+
return true;
|
|
29427
|
+
});
|
|
29428
|
+
if (coordinatorInstances.length === 0) return;
|
|
29429
|
+
const targetNode = mesh.nodes.find((n) => n.workspace === workspace);
|
|
29430
|
+
const nodeLabel = targetNode ? `Node '${targetNode.id}'` : `Agent at ${workspace}`;
|
|
29431
|
+
let messageText = "";
|
|
29432
|
+
if (event.event === "agent:generating_completed") {
|
|
29433
|
+
messageText = `[System] ${nodeLabel} has completed its task and is now idle. You may use mesh_read_chat to review its progress.`;
|
|
29434
|
+
} else if (event.event === "agent:waiting_approval") {
|
|
29435
|
+
messageText = `[System] ${nodeLabel} is waiting for approval to proceed. You may use mesh_read_chat and mesh_approve to handle it.`;
|
|
29436
|
+
}
|
|
29437
|
+
if (!messageText) return;
|
|
29438
|
+
for (const coord of coordinatorInstances) {
|
|
29439
|
+
const coordState = coord.getState();
|
|
29440
|
+
LOG.info("MeshEvents", `Forwarding event from ${workspace} to coordinator ${coordState.instanceId}`);
|
|
29441
|
+
coord.onEvent("send_message", { input: { text: messageText, textFallback: messageText } });
|
|
29442
|
+
}
|
|
29443
|
+
});
|
|
29444
|
+
}
|
|
29445
|
+
|
|
29446
|
+
// src/boot/daemon-lifecycle.ts
|
|
29271
29447
|
async function initDaemonComponents(config) {
|
|
29272
29448
|
installGlobalInterceptor();
|
|
29273
29449
|
const appConfig = loadConfig();
|
|
@@ -29425,7 +29601,7 @@ async function initDaemonComponents(config) {
|
|
|
29425
29601
|
});
|
|
29426
29602
|
poller.start();
|
|
29427
29603
|
instanceManager.startTicking(config.tickIntervalMs ?? 5e3);
|
|
29428
|
-
|
|
29604
|
+
const components = {
|
|
29429
29605
|
providerLoader,
|
|
29430
29606
|
instanceManager,
|
|
29431
29607
|
cliManager,
|
|
@@ -29439,6 +29615,8 @@ async function initDaemonComponents(config) {
|
|
|
29439
29615
|
detectedIdes: detectedIdesRef,
|
|
29440
29616
|
refreshProviderAvailability
|
|
29441
29617
|
};
|
|
29618
|
+
setupMeshEventForwarding(components);
|
|
29619
|
+
return components;
|
|
29442
29620
|
}
|
|
29443
29621
|
async function startDaemonDevSupport(options) {
|
|
29444
29622
|
const devServer = new DevServer({
|