@adhdev/daemon-core 0.9.82-rc.139 → 0.9.82-rc.140
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/cli-state-engine.d.ts +9 -0
- package/dist/config/config.d.ts +5 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +255 -140
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +218 -109
- package/dist/index.mjs.map +1 -1
- package/dist/mesh/coordinator-registry.d.ts +25 -0
- package/dist/shared-types.d.ts +5 -0
- package/package.json +1 -1
- package/src/boot/daemon-lifecycle.ts +2 -0
- package/src/cli-adapters/cli-state-engine.ts +41 -12
- package/src/cli-adapters/provider-cli-adapter.ts +15 -13
- package/src/commands/cli-manager.ts +4 -0
- package/src/commands/router.ts +13 -4
- package/src/config/config.ts +12 -0
- package/src/index.ts +3 -1
- package/src/mesh/coordinator-registry.ts +75 -0
- package/src/providers/cli-provider-instance.ts +19 -2
- package/src/shared-types.ts +2 -0
- package/src/status/builders.ts +23 -6
package/dist/index.js
CHANGED
|
@@ -434,6 +434,7 @@ var config_exports = {};
|
|
|
434
434
|
__export(config_exports, {
|
|
435
435
|
generateMachineId: () => generateMachineId,
|
|
436
436
|
getConfigDir: () => getConfigDir,
|
|
437
|
+
getDaemonDataDir: () => getDaemonDataDir,
|
|
437
438
|
isSetupComplete: () => isSetupComplete,
|
|
438
439
|
isStableMachineId: () => isStableMachineId,
|
|
439
440
|
loadConfig: () => loadConfig,
|
|
@@ -542,6 +543,13 @@ function getConfigDir() {
|
|
|
542
543
|
}
|
|
543
544
|
return dir;
|
|
544
545
|
}
|
|
546
|
+
function getDaemonDataDir() {
|
|
547
|
+
const dir = (0, import_path.join)(getConfigDir(), "daemon");
|
|
548
|
+
if (!(0, import_fs.existsSync)(dir)) {
|
|
549
|
+
(0, import_fs.mkdirSync)(dir, { recursive: true });
|
|
550
|
+
}
|
|
551
|
+
return dir;
|
|
552
|
+
}
|
|
545
553
|
function getConfigPath() {
|
|
546
554
|
return (0, import_path.join)(getConfigDir(), "config.json");
|
|
547
555
|
}
|
|
@@ -1308,41 +1316,41 @@ function isIntentionalCleanupStopEntry(entry) {
|
|
|
1308
1316
|
return payload.intentional === true && (payload.reason === "operator_cleanup" || payload.intentionalStopReason === "operator_cleanup" || payload.source === "mesh_cleanup_sessions" || payload.source === "mesh_remove_node");
|
|
1309
1317
|
}
|
|
1310
1318
|
function getLedgerDir() {
|
|
1311
|
-
const dir = (0,
|
|
1312
|
-
if (!(0,
|
|
1313
|
-
(0,
|
|
1319
|
+
const dir = (0, import_path6.join)(getConfigDir(), LEDGER_DIR_NAME);
|
|
1320
|
+
if (!(0, import_fs6.existsSync)(dir)) {
|
|
1321
|
+
(0, import_fs6.mkdirSync)(dir, { recursive: true, mode: 448 });
|
|
1314
1322
|
}
|
|
1315
1323
|
return dir;
|
|
1316
1324
|
}
|
|
1317
1325
|
function getLedgerPath(meshId) {
|
|
1318
1326
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1319
|
-
return (0,
|
|
1327
|
+
return (0, import_path6.join)(getLedgerDir(), `${safe}.jsonl`);
|
|
1320
1328
|
}
|
|
1321
1329
|
function getRotatedPath(meshId, index) {
|
|
1322
1330
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1323
|
-
return (0,
|
|
1331
|
+
return (0, import_path6.join)(getLedgerDir(), `${safe}.${index}.jsonl`);
|
|
1324
1332
|
}
|
|
1325
1333
|
function getArchivePath(meshId) {
|
|
1326
1334
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1327
|
-
return (0,
|
|
1335
|
+
return (0, import_path6.join)(getLedgerDir(), `${safe}.archive.jsonl`);
|
|
1328
1336
|
}
|
|
1329
1337
|
function getRotatedArchivePath(meshId, index) {
|
|
1330
1338
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1331
|
-
return (0,
|
|
1339
|
+
return (0, import_path6.join)(getLedgerDir(), `${safe}.archive.${index}.jsonl`);
|
|
1332
1340
|
}
|
|
1333
1341
|
function getArchivedCountsPath(meshId) {
|
|
1334
1342
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1335
|
-
return (0,
|
|
1343
|
+
return (0, import_path6.join)(getLedgerDir(), `${safe}.archived-counts.json`);
|
|
1336
1344
|
}
|
|
1337
1345
|
function rotateArchiveFile(meshId, archivePath) {
|
|
1338
1346
|
let index = 1;
|
|
1339
|
-
while ((0,
|
|
1347
|
+
while ((0, import_fs6.existsSync)(getRotatedArchivePath(meshId, index))) {
|
|
1340
1348
|
index++;
|
|
1341
1349
|
if (index > 5) break;
|
|
1342
1350
|
}
|
|
1343
1351
|
if (index > 5) index = 5;
|
|
1344
1352
|
try {
|
|
1345
|
-
(0,
|
|
1353
|
+
(0, import_fs6.renameSync)(archivePath, getRotatedArchivePath(meshId, index));
|
|
1346
1354
|
} catch (e) {
|
|
1347
1355
|
process.stderr.write(`[adhdev-mesh] Archive rotation failed for mesh ${meshId}: ${e?.message || e}
|
|
1348
1356
|
`);
|
|
@@ -1350,9 +1358,9 @@ function rotateArchiveFile(meshId, archivePath) {
|
|
|
1350
1358
|
}
|
|
1351
1359
|
function readArchivedCounts(meshId) {
|
|
1352
1360
|
const path28 = getArchivedCountsPath(meshId);
|
|
1353
|
-
if (!(0,
|
|
1361
|
+
if (!(0, import_fs6.existsSync)(path28)) return { taskCompleted: 0, taskFailed: 0, taskStalled: 0, recoveryAttempted: 0, totalArchived: 0, lastArchivedAt: "" };
|
|
1354
1362
|
try {
|
|
1355
|
-
return JSON.parse((0,
|
|
1363
|
+
return JSON.parse((0, import_fs6.readFileSync)(path28, "utf-8"));
|
|
1356
1364
|
} catch {
|
|
1357
1365
|
return { taskCompleted: 0, taskFailed: 0, taskStalled: 0, recoveryAttempted: 0, totalArchived: 0, lastArchivedAt: "" };
|
|
1358
1366
|
}
|
|
@@ -1368,7 +1376,7 @@ function updateArchivedCounts(meshId, archived) {
|
|
|
1368
1376
|
counts.totalArchived += archived.length;
|
|
1369
1377
|
counts.lastArchivedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1370
1378
|
try {
|
|
1371
|
-
(0,
|
|
1379
|
+
(0, import_fs6.writeFileSync)(getArchivedCountsPath(meshId), JSON.stringify(counts), { encoding: "utf-8", mode: 384 });
|
|
1372
1380
|
} catch {
|
|
1373
1381
|
}
|
|
1374
1382
|
}
|
|
@@ -1391,7 +1399,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
1391
1399
|
}
|
|
1392
1400
|
function compactLedger(meshId) {
|
|
1393
1401
|
const filePath = getLedgerPath(meshId);
|
|
1394
|
-
if (!(0,
|
|
1402
|
+
if (!(0, import_fs6.existsSync)(filePath)) return { archivedCount: 0, retainedCount: 0 };
|
|
1395
1403
|
const cutoff = Date.now() - ARCHIVE_TERMINAL_OLDER_THAN_MS;
|
|
1396
1404
|
const entries = readLedgerEntries(meshId);
|
|
1397
1405
|
const keep = [];
|
|
@@ -1406,11 +1414,11 @@ function compactLedger(meshId) {
|
|
|
1406
1414
|
if (archive.length === 0) return { archivedCount: 0, retainedCount: keep.length };
|
|
1407
1415
|
const archivePath = getArchivePath(meshId);
|
|
1408
1416
|
try {
|
|
1409
|
-
if ((0,
|
|
1417
|
+
if ((0, import_fs6.existsSync)(archivePath) && (0, import_fs6.statSync)(archivePath).size > 50 * 1024 * 1024) {
|
|
1410
1418
|
rotateArchiveFile(meshId, archivePath);
|
|
1411
1419
|
}
|
|
1412
1420
|
const archiveLines = archive.map((e) => JSON.stringify(e)).join("\n") + "\n";
|
|
1413
|
-
(0,
|
|
1421
|
+
(0, import_fs6.appendFileSync)(archivePath, archiveLines, { encoding: "utf-8", mode: 384 });
|
|
1414
1422
|
updateArchivedCounts(meshId, archive);
|
|
1415
1423
|
} catch (e) {
|
|
1416
1424
|
process.stderr.write(`[adhdev-mesh] Ledger archive write failed for mesh ${meshId}: ${e?.message || e}
|
|
@@ -1419,7 +1427,7 @@ function compactLedger(meshId) {
|
|
|
1419
1427
|
}
|
|
1420
1428
|
try {
|
|
1421
1429
|
const keepLines = keep.length ? keep.map((e) => JSON.stringify(e)).join("\n") + "\n" : "";
|
|
1422
|
-
(0,
|
|
1430
|
+
(0, import_fs6.writeFileSync)(filePath, keepLines, { encoding: "utf-8", mode: 384 });
|
|
1423
1431
|
invalidateLedgerCache(meshId);
|
|
1424
1432
|
} catch (e) {
|
|
1425
1433
|
process.stderr.write(`[adhdev-mesh] Ledger compaction rewrite failed for mesh ${meshId}: ${e?.message || e}
|
|
@@ -1551,9 +1559,9 @@ function appendLedgerEntry(meshId, partial) {
|
|
|
1551
1559
|
...partial
|
|
1552
1560
|
};
|
|
1553
1561
|
const filePath = getLedgerPath(meshId);
|
|
1554
|
-
if ((0,
|
|
1562
|
+
if ((0, import_fs6.existsSync)(filePath)) {
|
|
1555
1563
|
try {
|
|
1556
|
-
const stat2 = (0,
|
|
1564
|
+
const stat2 = (0, import_fs6.statSync)(filePath);
|
|
1557
1565
|
if (stat2.size >= MAX_FILE_SIZE_BYTES) {
|
|
1558
1566
|
rotateLedgerFile(meshId, filePath);
|
|
1559
1567
|
} else if (stat2.size >= COMPACT_THRESHOLD_BYTES) {
|
|
@@ -1564,7 +1572,7 @@ function appendLedgerEntry(meshId, partial) {
|
|
|
1564
1572
|
}
|
|
1565
1573
|
try {
|
|
1566
1574
|
const line = JSON.stringify(entry) + "\n";
|
|
1567
|
-
(0,
|
|
1575
|
+
(0, import_fs6.appendFileSync)(filePath, line, { encoding: "utf-8", mode: 384 });
|
|
1568
1576
|
invalidateLedgerCache(meshId);
|
|
1569
1577
|
meshLedgerEvents.emit("append", meshId, entry);
|
|
1570
1578
|
return entry;
|
|
@@ -1610,7 +1618,7 @@ function appendRemoteLedgerEntries(meshId, entries) {
|
|
|
1610
1618
|
}
|
|
1611
1619
|
try {
|
|
1612
1620
|
const lines = validEntries.map((e) => JSON.stringify(e)).join("\n") + "\n";
|
|
1613
|
-
(0,
|
|
1621
|
+
(0, import_fs6.appendFileSync)(ledgerPath, lines, { encoding: "utf-8", mode: 384 });
|
|
1614
1622
|
invalidateLedgerCache(meshId);
|
|
1615
1623
|
for (const entry of validEntries) {
|
|
1616
1624
|
meshLedgerEvents.emit("append", meshId, entry);
|
|
@@ -1622,10 +1630,10 @@ function appendRemoteLedgerEntries(meshId, entries) {
|
|
|
1622
1630
|
}
|
|
1623
1631
|
function readLedgerFile(meshId) {
|
|
1624
1632
|
const filePath = getLedgerPath(meshId);
|
|
1625
|
-
if (!(0,
|
|
1633
|
+
if (!(0, import_fs6.existsSync)(filePath)) return [];
|
|
1626
1634
|
let content;
|
|
1627
1635
|
try {
|
|
1628
|
-
content = (0,
|
|
1636
|
+
content = (0, import_fs6.readFileSync)(filePath, "utf-8");
|
|
1629
1637
|
} catch {
|
|
1630
1638
|
return [];
|
|
1631
1639
|
}
|
|
@@ -1826,24 +1834,24 @@ function getSessionRecoveryContext(meshId, opts) {
|
|
|
1826
1834
|
}
|
|
1827
1835
|
function rotateLedgerFile(meshId, currentPath) {
|
|
1828
1836
|
let index = 1;
|
|
1829
|
-
while ((0,
|
|
1837
|
+
while ((0, import_fs6.existsSync)(getRotatedPath(meshId, index))) {
|
|
1830
1838
|
index++;
|
|
1831
1839
|
if (index > 10) break;
|
|
1832
1840
|
}
|
|
1833
1841
|
if (index > 10) index = 10;
|
|
1834
1842
|
try {
|
|
1835
|
-
(0,
|
|
1843
|
+
(0, import_fs6.renameSync)(currentPath, getRotatedPath(meshId, index));
|
|
1836
1844
|
} catch (e) {
|
|
1837
1845
|
process.stderr.write(`[adhdev-mesh] Ledger rotation failed for mesh ${meshId}: ${e?.message || e}. File will continue to grow.
|
|
1838
1846
|
`);
|
|
1839
1847
|
}
|
|
1840
1848
|
}
|
|
1841
|
-
var
|
|
1849
|
+
var import_fs6, import_path6, import_crypto4, import_events, LEDGER_DIR_NAME, MAX_FILE_SIZE_BYTES, COMPACT_THRESHOLD_BYTES, ARCHIVE_TERMINAL_OLDER_THAN_MS, RECENT_FAILURE_WINDOW_MS, ARCHIVABLE_KINDS, DEFAULT_LEDGER_SLICE_LIMIT, MAX_LEDGER_SLICE_LIMIT, meshLedgerEvents, ledgerReadCache, LEDGER_CACHE_TTL_MS;
|
|
1842
1850
|
var init_mesh_ledger = __esm({
|
|
1843
1851
|
"src/mesh/mesh-ledger.ts"() {
|
|
1844
1852
|
"use strict";
|
|
1845
|
-
|
|
1846
|
-
|
|
1853
|
+
import_fs6 = require("fs");
|
|
1854
|
+
import_path6 = require("path");
|
|
1847
1855
|
import_crypto4 = require("crypto");
|
|
1848
1856
|
init_config();
|
|
1849
1857
|
import_events = require("events");
|
|
@@ -1877,14 +1885,14 @@ function safeMeshId(meshId) {
|
|
|
1877
1885
|
return meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1878
1886
|
}
|
|
1879
1887
|
function legacyQueuePath(meshId) {
|
|
1880
|
-
return (0,
|
|
1888
|
+
return (0, import_path7.join)(getLedgerDir(), `${safeMeshId(meshId)}.queue.json`);
|
|
1881
1889
|
}
|
|
1882
|
-
var
|
|
1890
|
+
var import_fs7, import_path7, import_module, import_meta, DatabaseCtor, BeadsDB;
|
|
1883
1891
|
var init_beads_db = __esm({
|
|
1884
1892
|
"src/mesh/beads-db.ts"() {
|
|
1885
1893
|
"use strict";
|
|
1886
|
-
|
|
1887
|
-
|
|
1894
|
+
import_fs7 = require("fs");
|
|
1895
|
+
import_path7 = require("path");
|
|
1888
1896
|
import_module = require("module");
|
|
1889
1897
|
init_mesh_ledger();
|
|
1890
1898
|
import_meta = {};
|
|
@@ -1899,8 +1907,8 @@ var init_beads_db = __esm({
|
|
|
1899
1907
|
static WAL_MAX_BYTES = 50 * 1024 * 1024;
|
|
1900
1908
|
// 50 MB
|
|
1901
1909
|
constructor(dbPath) {
|
|
1902
|
-
const dir = (0,
|
|
1903
|
-
if (!(0,
|
|
1910
|
+
const dir = (0, import_path7.dirname)(dbPath);
|
|
1911
|
+
if (!(0, import_fs7.existsSync)(dir)) (0, import_fs7.mkdirSync)(dir, { recursive: true });
|
|
1904
1912
|
this.dbPath = dbPath;
|
|
1905
1913
|
this.db = new (loadDatabaseCtor())(dbPath);
|
|
1906
1914
|
this.db.pragma("journal_mode = WAL");
|
|
@@ -1911,7 +1919,7 @@ var init_beads_db = __esm({
|
|
|
1911
1919
|
}
|
|
1912
1920
|
static getInstance() {
|
|
1913
1921
|
if (!this.instance) {
|
|
1914
|
-
this.instance = new _BeadsDB((0,
|
|
1922
|
+
this.instance = new _BeadsDB((0, import_path7.join)(getLedgerDir(), "beads.db"));
|
|
1915
1923
|
}
|
|
1916
1924
|
return this.instance;
|
|
1917
1925
|
}
|
|
@@ -1991,8 +1999,8 @@ var init_beads_db = __esm({
|
|
|
1991
1999
|
this.walWriteCounter = 0;
|
|
1992
2000
|
try {
|
|
1993
2001
|
const walPath = `${this.dbPath}-wal`;
|
|
1994
|
-
if (!(0,
|
|
1995
|
-
const size = (0,
|
|
2002
|
+
if (!(0, import_fs7.existsSync)(walPath)) return;
|
|
2003
|
+
const size = (0, import_fs7.statSync)(walPath).size;
|
|
1996
2004
|
if (size < _BeadsDB.WAL_MAX_BYTES) return;
|
|
1997
2005
|
process.stderr.write(
|
|
1998
2006
|
`[adhdev-mesh] WAL file ${Math.round(size / 1024 / 1024)}MB exceeds threshold; forcing checkpoint
|
|
@@ -2008,9 +2016,9 @@ var init_beads_db = __esm({
|
|
|
2008
2016
|
const count = this.db.prepare("SELECT COUNT(*) AS count FROM mesh_queue WHERE mesh_id = ?").get(meshId);
|
|
2009
2017
|
if (count.count > 0) return;
|
|
2010
2018
|
const path28 = legacyQueuePath(meshId);
|
|
2011
|
-
if (!(0,
|
|
2019
|
+
if (!(0, import_fs7.existsSync)(path28)) return;
|
|
2012
2020
|
try {
|
|
2013
|
-
const entries = JSON.parse((0,
|
|
2021
|
+
const entries = JSON.parse((0, import_fs7.readFileSync)(path28, "utf-8"));
|
|
2014
2022
|
if (!Array.isArray(entries)) return;
|
|
2015
2023
|
const insert = this.db.prepare(`
|
|
2016
2024
|
INSERT OR REPLACE INTO mesh_queue (
|
|
@@ -2527,7 +2535,7 @@ function resolveCommandPath(command) {
|
|
|
2527
2535
|
if (isExplicitCommandPath(trimmed)) {
|
|
2528
2536
|
const expanded = expandHome(trimmed);
|
|
2529
2537
|
const candidate = path8.isAbsolute(expanded) ? expanded : path8.resolve(expanded);
|
|
2530
|
-
return (0,
|
|
2538
|
+
return (0, import_fs8.existsSync)(candidate) ? candidate : null;
|
|
2531
2539
|
}
|
|
2532
2540
|
return null;
|
|
2533
2541
|
}
|
|
@@ -2627,14 +2635,14 @@ async function detectCLI(cliId, providerLoader, options) {
|
|
|
2627
2635
|
const all = await detectCLIs(providerLoader, options);
|
|
2628
2636
|
return all.find((c) => c.id === resolvedId && c.installed) || null;
|
|
2629
2637
|
}
|
|
2630
|
-
var import_child_process, os2, path8,
|
|
2638
|
+
var import_child_process, os2, path8, import_fs8;
|
|
2631
2639
|
var init_cli_detector = __esm({
|
|
2632
2640
|
"src/detection/cli-detector.ts"() {
|
|
2633
2641
|
"use strict";
|
|
2634
2642
|
import_child_process = require("child_process");
|
|
2635
2643
|
os2 = __toESM(require("os"));
|
|
2636
2644
|
path8 = __toESM(require("path"));
|
|
2637
|
-
|
|
2645
|
+
import_fs8 = require("fs");
|
|
2638
2646
|
}
|
|
2639
2647
|
});
|
|
2640
2648
|
|
|
@@ -2981,18 +2989,18 @@ function getPendingEventsPath(meshId, coordinatorDaemonId) {
|
|
|
2981
2989
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
2982
2990
|
if (coordinatorDaemonId) {
|
|
2983
2991
|
const safeDaemon = coordinatorDaemonId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
2984
|
-
return (0,
|
|
2992
|
+
return (0, import_path8.join)(getLedgerDir(), `${safe}-${safeDaemon}.pending-events.jsonl`);
|
|
2985
2993
|
}
|
|
2986
|
-
return (0,
|
|
2994
|
+
return (0, import_path8.join)(getLedgerDir(), `${safe}.pending-events.jsonl`);
|
|
2987
2995
|
}
|
|
2988
2996
|
function readPendingMeshCoordinatorEventsFromDisk(meshId, coordinatorDaemonId) {
|
|
2989
2997
|
if (!meshId) return [];
|
|
2990
2998
|
const paths = coordinatorDaemonId ? [getPendingEventsPath(meshId, coordinatorDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
|
|
2991
2999
|
const events = [];
|
|
2992
3000
|
for (const path28 of paths) {
|
|
2993
|
-
if (!(0,
|
|
3001
|
+
if (!(0, import_fs9.existsSync)(path28)) continue;
|
|
2994
3002
|
try {
|
|
2995
|
-
const raw = (0,
|
|
3003
|
+
const raw = (0, import_fs9.readFileSync)(path28, "utf-8");
|
|
2996
3004
|
const parsed = raw.split("\n").filter(Boolean).flatMap((line) => {
|
|
2997
3005
|
try {
|
|
2998
3006
|
return [JSON.parse(line)];
|
|
@@ -3071,11 +3079,11 @@ function reconcilePendingMeshCoordinatorEvents(meshId, events) {
|
|
|
3071
3079
|
}
|
|
3072
3080
|
function trimPendingEventsIfNeeded(path28) {
|
|
3073
3081
|
try {
|
|
3074
|
-
if (!(0,
|
|
3075
|
-
if ((0,
|
|
3076
|
-
const lines = (0,
|
|
3082
|
+
if (!(0, import_fs9.existsSync)(path28)) return;
|
|
3083
|
+
if ((0, import_fs9.statSync)(path28).size <= MAX_PENDING_EVENTS_BYTES) return;
|
|
3084
|
+
const lines = (0, import_fs9.readFileSync)(path28, "utf-8").split("\n").filter(Boolean);
|
|
3077
3085
|
if (lines.length <= MAX_PENDING_EVENTS_KEEP) return;
|
|
3078
|
-
(0,
|
|
3086
|
+
(0, import_fs9.writeFileSync)(path28, lines.slice(-MAX_PENDING_EVENTS_KEEP).join("\n") + "\n", "utf-8");
|
|
3079
3087
|
} catch {
|
|
3080
3088
|
}
|
|
3081
3089
|
}
|
|
@@ -3091,7 +3099,7 @@ function queuePendingMeshCoordinatorEvent(event) {
|
|
|
3091
3099
|
}
|
|
3092
3100
|
const path28 = getPendingEventsPath(event.meshId, event.targetCoordinatorDaemonId);
|
|
3093
3101
|
trimPendingEventsIfNeeded(path28);
|
|
3094
|
-
(0,
|
|
3102
|
+
(0, import_fs9.appendFileSync)(path28, JSON.stringify(event) + "\n", "utf-8");
|
|
3095
3103
|
return true;
|
|
3096
3104
|
} catch (e) {
|
|
3097
3105
|
LOG.warn("MeshEvents", `Failed to persist pending coordinator event: ${e?.message || e}`);
|
|
@@ -3101,20 +3109,20 @@ function queuePendingMeshCoordinatorEvent(event) {
|
|
|
3101
3109
|
function atomicDrainFile(path28) {
|
|
3102
3110
|
const tmpPath = `${path28}.draining`;
|
|
3103
3111
|
try {
|
|
3104
|
-
(0,
|
|
3112
|
+
(0, import_fs9.renameSync)(path28, tmpPath);
|
|
3105
3113
|
} catch {
|
|
3106
3114
|
return null;
|
|
3107
3115
|
}
|
|
3108
3116
|
try {
|
|
3109
|
-
const content = (0,
|
|
3117
|
+
const content = (0, import_fs9.readFileSync)(tmpPath, "utf-8");
|
|
3110
3118
|
try {
|
|
3111
|
-
(0,
|
|
3119
|
+
(0, import_fs9.unlinkSync)(tmpPath);
|
|
3112
3120
|
} catch {
|
|
3113
3121
|
}
|
|
3114
3122
|
return content;
|
|
3115
3123
|
} catch {
|
|
3116
3124
|
try {
|
|
3117
|
-
(0,
|
|
3125
|
+
(0, import_fs9.unlinkSync)(tmpPath);
|
|
3118
3126
|
} catch {
|
|
3119
3127
|
}
|
|
3120
3128
|
return null;
|
|
@@ -3148,8 +3156,8 @@ function clearPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
|
|
|
3148
3156
|
if (!meshId) return;
|
|
3149
3157
|
const paths = coordinatorDaemonId ? [getPendingEventsPath(meshId, coordinatorDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
|
|
3150
3158
|
for (const path28 of paths) {
|
|
3151
|
-
if ((0,
|
|
3152
|
-
(0,
|
|
3159
|
+
if ((0, import_fs9.existsSync)(path28)) try {
|
|
3160
|
+
(0, import_fs9.unlinkSync)(path28);
|
|
3153
3161
|
} catch {
|
|
3154
3162
|
}
|
|
3155
3163
|
}
|
|
@@ -4167,12 +4175,12 @@ function setupMeshEventForwarding(components) {
|
|
|
4167
4175
|
});
|
|
4168
4176
|
});
|
|
4169
4177
|
}
|
|
4170
|
-
var
|
|
4178
|
+
var import_fs9, import_path8, REMOTE_IDLE_SESSION_TTL_MS, remoteIdleSessions, meshByWorkspaceCache, MESH_WORKSPACE_CACHE_TTL_MS, REFINE_TERMINAL_EVENTS, MAX_PENDING_EVENTS_BYTES, MAX_PENDING_EVENTS_KEEP, MESH_COORDINATOR_EVENTS, EVENT_TO_LEDGER_KIND, INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS, RECENT_COMPLETION_FINGERPRINT_TTL_MS, autoLaunchInProgress, autoLaunchCooldownUntil, AUTO_LAUNCH_COOLDOWN_MS;
|
|
4171
4179
|
var init_mesh_events = __esm({
|
|
4172
4180
|
"src/mesh/mesh-events.ts"() {
|
|
4173
4181
|
"use strict";
|
|
4174
|
-
|
|
4175
|
-
|
|
4182
|
+
import_fs9 = require("fs");
|
|
4183
|
+
import_path8 = require("path");
|
|
4176
4184
|
init_config();
|
|
4177
4185
|
init_mesh_config();
|
|
4178
4186
|
init_cli_detector();
|
|
@@ -5192,6 +5200,15 @@ var init_cli_state_engine = __esm({
|
|
|
5192
5200
|
// ── Approval ─────────────────────────────────────
|
|
5193
5201
|
lastApprovalResolvedAt = 0;
|
|
5194
5202
|
lastResolvedModalMessage = "";
|
|
5203
|
+
/**
|
|
5204
|
+
* When the engine previously held a modal but the latest parse failed
|
|
5205
|
+
* to extract one, we record the timestamp here and only drop the modal
|
|
5206
|
+
* after the configured `approvalCooldown` to avoid flapping between
|
|
5207
|
+
* waiting_approval and generating on every Claude TUI redraw — that
|
|
5208
|
+
* flapping is what fed auto-approve a fresh modal signature on each
|
|
5209
|
+
* paint and made the engine type "1" repeatedly into the prompt.
|
|
5210
|
+
*/
|
|
5211
|
+
modalLostAt = 0;
|
|
5195
5212
|
approvalExitTimeout = null;
|
|
5196
5213
|
// ── Response tracking ────────────────────────────
|
|
5197
5214
|
responseEpoch = 0;
|
|
@@ -5296,7 +5313,9 @@ var init_cli_state_engine = __esm({
|
|
|
5296
5313
|
} catch {
|
|
5297
5314
|
}
|
|
5298
5315
|
}
|
|
5299
|
-
if (!this.transport.isAlive()
|
|
5316
|
+
if (!this.transport.isAlive()) return;
|
|
5317
|
+
const buttonsValid = Array.isArray(modal?.buttons) && modal.buttons.some((b) => typeof b === "string" && b.trim());
|
|
5318
|
+
if (!modal || !buttonsValid) return;
|
|
5300
5319
|
const currentModalMessage = typeof modal?.message === "string" ? modal.message.trim() : "";
|
|
5301
5320
|
const inCooldown = !!this.lastApprovalResolvedAt && Date.now() - this.lastApprovalResolvedAt < this.timeouts.approvalCooldown;
|
|
5302
5321
|
if (inCooldown && currentModalMessage === this.lastResolvedModalMessage) return;
|
|
@@ -5646,13 +5665,19 @@ var init_cli_state_engine = __esm({
|
|
|
5646
5665
|
if (!inCooldown) {
|
|
5647
5666
|
if (!modal) {
|
|
5648
5667
|
LOG.warn("CLI", `[${this.provider.type}] detectStatus=waiting_approval but parseApproval returned null; ignoring`);
|
|
5649
|
-
if (this.currentStatus === "waiting_approval") {
|
|
5650
|
-
this.
|
|
5651
|
-
this.
|
|
5652
|
-
this.
|
|
5668
|
+
if (this.currentStatus === "waiting_approval" && this.activeModal) {
|
|
5669
|
+
const lostAt = this.modalLostAt || Date.now();
|
|
5670
|
+
if (!this.modalLostAt) this.modalLostAt = lostAt;
|
|
5671
|
+
if (Date.now() - lostAt >= this.timeouts.approvalCooldown) {
|
|
5672
|
+
this.activeModal = null;
|
|
5673
|
+
this.modalLostAt = 0;
|
|
5674
|
+
this.setStatus("generating", "approval_lost_modal");
|
|
5675
|
+
this.callbacks.onStatusChange();
|
|
5676
|
+
}
|
|
5653
5677
|
}
|
|
5654
5678
|
return;
|
|
5655
5679
|
}
|
|
5680
|
+
this.modalLostAt = 0;
|
|
5656
5681
|
this.isWaitingForResponse = true;
|
|
5657
5682
|
this.setStatus("waiting_approval", "script_detect");
|
|
5658
5683
|
const prev = this.activeModal;
|
|
@@ -6780,19 +6805,12 @@ ${lastSnapshot}`;
|
|
|
6780
6805
|
const liveDetect = this.runDetectStatus(this.recentOutputBuffer || this.terminalScreen.getText());
|
|
6781
6806
|
if (liveDetect === "waiting_approval") {
|
|
6782
6807
|
const liveModal = this.runParseApproval(this.terminalScreen.getText()) || this.runParseApproval(this.recentOutputBuffer);
|
|
6783
|
-
|
|
6808
|
+
const buttonsOk = liveModal && Array.isArray(liveModal.buttons) && liveModal.buttons.some((b) => typeof b === "string" && b.trim());
|
|
6809
|
+
if (liveModal && buttonsOk) {
|
|
6784
6810
|
effectiveModal = liveModal;
|
|
6785
6811
|
if (!this.engine.activeModal) this.engine.activeModal = liveModal;
|
|
6786
|
-
} else {
|
|
6787
|
-
LOG.warn("CLI", `[${this.cliType}] getStatus live re-extract: detect=waiting_approval but parseApproval still null (recentLen=${this.recentOutputBuffer.length} screenLen=${this.terminalScreen.getText().length})`);
|
|
6788
6812
|
}
|
|
6789
|
-
} else if (liveDetect && liveDetect !== "generating" && liveDetect !== "idle") {
|
|
6790
|
-
LOG.warn("CLI", `[${this.cliType}] getStatus live re-extract: detect=${liveDetect} (not waiting_approval)`);
|
|
6791
|
-
} else if (this.engine.currentStatus === "waiting_approval" && liveDetect !== "waiting_approval") {
|
|
6792
|
-
LOG.warn("CLI", `[${this.cliType}] getStatus live re-extract: engine.status=waiting_approval but live detect=${liveDetect}`);
|
|
6793
6813
|
}
|
|
6794
|
-
} else if (!effectiveModal && this.engine.currentStatus === "waiting_approval") {
|
|
6795
|
-
LOG.warn("CLI", `[${this.cliType}] getStatus skipped live re-extract: allowParse=${allowParse} isWaitingForResponse=${this.engine.isWaitingForResponse}`);
|
|
6796
6814
|
}
|
|
6797
6815
|
if (startupDetectedStatus === "waiting_approval" && effectiveModal) {
|
|
6798
6816
|
effectiveStatus = "waiting_approval";
|
|
@@ -7705,7 +7723,8 @@ ${lastSnapshot}`;
|
|
|
7705
7723
|
if (parsedDebugState?.status === "error") {
|
|
7706
7724
|
effectiveStatus = "error";
|
|
7707
7725
|
}
|
|
7708
|
-
|
|
7726
|
+
const debugEffectiveModal = startupModal || this.engine.activeModal;
|
|
7727
|
+
if (startupDetectedStatus === "waiting_approval" && debugEffectiveModal) {
|
|
7709
7728
|
effectiveStatus = "waiting_approval";
|
|
7710
7729
|
}
|
|
7711
7730
|
if (effectiveStatus === "idle" && parsedDebugState?.status === "generating" && !hasFinalAssistant(parsedDebugState)) {
|
|
@@ -7936,7 +7955,9 @@ __export(index_exports, {
|
|
|
7936
7955
|
getAIExtensions: () => getAIExtensions,
|
|
7937
7956
|
getActiveDirectDispatches: () => getActiveDirectDispatches,
|
|
7938
7957
|
getAvailableIdeIds: () => getAvailableIdeIds,
|
|
7958
|
+
getCoordinatorForSession: () => getCoordinatorForSession,
|
|
7939
7959
|
getCurrentDaemonLogPath: () => getCurrentDaemonLogPath,
|
|
7960
|
+
getDaemonDataDir: () => getDaemonDataDir,
|
|
7940
7961
|
getDaemonLogDir: () => getDaemonLogDir,
|
|
7941
7962
|
getDebugRuntimeConfig: () => getDebugRuntimeConfig,
|
|
7942
7963
|
getGitDiffSummary: () => getGitDiffSummary,
|
|
@@ -7988,10 +8009,12 @@ __export(index_exports, {
|
|
|
7988
8009
|
killIdeProcess: () => killIdeProcess,
|
|
7989
8010
|
launchIDE: () => launchIDE,
|
|
7990
8011
|
launchWithCdp: () => launchWithCdp,
|
|
8012
|
+
listCoordinatorsForWorkspace: () => listCoordinatorsForWorkspace,
|
|
7991
8013
|
listHostedCliRuntimes: () => listHostedCliRuntimes,
|
|
7992
8014
|
listMeshes: () => listMeshes,
|
|
7993
8015
|
listWorktrees: () => listWorktrees,
|
|
7994
8016
|
loadConfig: () => loadConfig,
|
|
8017
|
+
loadMeshCoordinatorRegistry: () => loadMeshCoordinatorRegistry,
|
|
7995
8018
|
loadMeshRefineConfig: () => loadMeshRefineConfig,
|
|
7996
8019
|
loadMeshWorktreeBootstrapConfig: () => loadMeshWorktreeBootstrapConfig,
|
|
7997
8020
|
loadState: () => loadState,
|
|
@@ -8028,6 +8051,7 @@ __export(index_exports, {
|
|
|
8028
8051
|
readLedgerSlice: () => readLedgerSlice,
|
|
8029
8052
|
recordDebugTrace: () => recordDebugTrace,
|
|
8030
8053
|
registerExtensionProviders: () => registerExtensionProviders,
|
|
8054
|
+
registerMeshCoordinator: () => registerMeshCoordinator,
|
|
8031
8055
|
removeNode: () => removeNode,
|
|
8032
8056
|
removeWorktree: () => removeWorktree,
|
|
8033
8057
|
requeueTask: () => requeueTask,
|
|
@@ -8061,6 +8085,7 @@ __export(index_exports, {
|
|
|
8061
8085
|
summarizeGitStatus: () => summarizeGitStatus,
|
|
8062
8086
|
syncMeshes: () => syncMeshes,
|
|
8063
8087
|
triggerMeshQueue: () => triggerMeshQueue,
|
|
8088
|
+
unregisterMeshCoordinator: () => unregisterMeshCoordinator,
|
|
8064
8089
|
updateConfig: () => updateConfig,
|
|
8065
8090
|
updateDirectDispatchStatus: () => updateDirectDispatchStatus,
|
|
8066
8091
|
updateMesh: () => updateMesh,
|
|
@@ -9816,9 +9841,58 @@ function getSavedProviderSessions(state, filters) {
|
|
|
9816
9841
|
init_mesh_config();
|
|
9817
9842
|
init_coordinator_prompt();
|
|
9818
9843
|
|
|
9819
|
-
// src/mesh/
|
|
9820
|
-
var import_fs3 = require("fs");
|
|
9844
|
+
// src/mesh/coordinator-registry.ts
|
|
9821
9845
|
var import_path3 = require("path");
|
|
9846
|
+
var import_fs3 = require("fs");
|
|
9847
|
+
init_config();
|
|
9848
|
+
var _registry = /* @__PURE__ */ new Map();
|
|
9849
|
+
function getRegistryPath() {
|
|
9850
|
+
return (0, import_path3.join)(getDaemonDataDir(), "mesh-coordinators.json");
|
|
9851
|
+
}
|
|
9852
|
+
function loadMeshCoordinatorRegistry() {
|
|
9853
|
+
const path28 = getRegistryPath();
|
|
9854
|
+
if (!(0, import_fs3.existsSync)(path28)) return;
|
|
9855
|
+
try {
|
|
9856
|
+
const raw = JSON.parse((0, import_fs3.readFileSync)(path28, "utf-8"));
|
|
9857
|
+
if (!Array.isArray(raw)) return;
|
|
9858
|
+
_registry.clear();
|
|
9859
|
+
for (const entry of raw) {
|
|
9860
|
+
if (typeof entry?.sessionId === "string" && typeof entry?.meshId === "string") {
|
|
9861
|
+
_registry.set(entry.sessionId, entry);
|
|
9862
|
+
}
|
|
9863
|
+
}
|
|
9864
|
+
} catch {
|
|
9865
|
+
}
|
|
9866
|
+
}
|
|
9867
|
+
function saveRegistry() {
|
|
9868
|
+
try {
|
|
9869
|
+
(0, import_fs3.writeFileSync)(
|
|
9870
|
+
getRegistryPath(),
|
|
9871
|
+
JSON.stringify([..._registry.values()], null, 2),
|
|
9872
|
+
{ encoding: "utf-8", mode: 384 }
|
|
9873
|
+
);
|
|
9874
|
+
} catch {
|
|
9875
|
+
}
|
|
9876
|
+
}
|
|
9877
|
+
function registerMeshCoordinator(entry) {
|
|
9878
|
+
_registry.set(entry.sessionId, entry);
|
|
9879
|
+
saveRegistry();
|
|
9880
|
+
}
|
|
9881
|
+
function unregisterMeshCoordinator(sessionId) {
|
|
9882
|
+
if (_registry.delete(sessionId)) {
|
|
9883
|
+
saveRegistry();
|
|
9884
|
+
}
|
|
9885
|
+
}
|
|
9886
|
+
function getCoordinatorForSession(sessionId) {
|
|
9887
|
+
return _registry.get(sessionId);
|
|
9888
|
+
}
|
|
9889
|
+
function listCoordinatorsForWorkspace(workspace) {
|
|
9890
|
+
return [..._registry.values()].filter((e) => e.workspace === workspace);
|
|
9891
|
+
}
|
|
9892
|
+
|
|
9893
|
+
// src/mesh/refine-config.ts
|
|
9894
|
+
var import_fs4 = require("fs");
|
|
9895
|
+
var import_path4 = require("path");
|
|
9822
9896
|
var yaml = __toESM(require("js-yaml"));
|
|
9823
9897
|
var MESH_REFINE_VALIDATION_CATEGORIES = ["typecheck", "test", "lint", "build"];
|
|
9824
9898
|
var MESH_REFINE_CONFIG_LOCATIONS = [
|
|
@@ -10001,10 +10075,10 @@ function loadMeshRefineConfig(mesh, workspace) {
|
|
|
10001
10075
|
return { config: inline, source: "mesh.policy.refineConfig", sourceType: "mesh_policy" };
|
|
10002
10076
|
}
|
|
10003
10077
|
for (const relative3 of MESH_REFINE_CONFIG_LOCATIONS) {
|
|
10004
|
-
const configPath = (0,
|
|
10005
|
-
if (!(0,
|
|
10078
|
+
const configPath = (0, import_path4.join)(workspace, relative3);
|
|
10079
|
+
if (!(0, import_fs4.existsSync)(configPath)) continue;
|
|
10006
10080
|
try {
|
|
10007
|
-
const parsed = parseConfigText(configPath, (0,
|
|
10081
|
+
const parsed = parseConfigText(configPath, (0, import_fs4.readFileSync)(configPath, "utf-8"));
|
|
10008
10082
|
const validation = validateMeshRefineConfig(parsed, relative3);
|
|
10009
10083
|
if (!validation.valid) return { source: relative3, sourceType: "invalid", path: configPath, error: String(validation.rejectedCommands[0]?.reason || validation.errors.join("; ")) };
|
|
10010
10084
|
return { config: parsed, source: relative3, sourceType: "repo_file", path: configPath };
|
|
@@ -10020,7 +10094,7 @@ function loadMeshRefineConfig(mesh, workspace) {
|
|
|
10020
10094
|
}
|
|
10021
10095
|
function readPackageScripts(workspace) {
|
|
10022
10096
|
try {
|
|
10023
|
-
const parsed = JSON.parse((0,
|
|
10097
|
+
const parsed = JSON.parse((0, import_fs4.readFileSync)((0, import_path4.join)(workspace, "package.json"), "utf-8"));
|
|
10024
10098
|
return isRecord(parsed?.scripts) ? parsed.scripts : {};
|
|
10025
10099
|
} catch {
|
|
10026
10100
|
return {};
|
|
@@ -10093,8 +10167,8 @@ function resolveMeshRefineValidationPlan(mesh, workspace) {
|
|
|
10093
10167
|
}
|
|
10094
10168
|
|
|
10095
10169
|
// src/mesh/worktree-bootstrap-config.ts
|
|
10096
|
-
var
|
|
10097
|
-
var
|
|
10170
|
+
var import_fs5 = require("fs");
|
|
10171
|
+
var import_path5 = require("path");
|
|
10098
10172
|
var import_node_child_process3 = require("child_process");
|
|
10099
10173
|
var import_node_util3 = require("util");
|
|
10100
10174
|
var yaml2 = __toESM(require("js-yaml"));
|
|
@@ -10184,10 +10258,10 @@ function loadMeshWorktreeBootstrapConfig(mesh, workspace) {
|
|
|
10184
10258
|
return { config: inline, source: "mesh.policy.worktreeBootstrapConfig", sourceType: "mesh_policy" };
|
|
10185
10259
|
}
|
|
10186
10260
|
for (const relative3 of MESH_WORKTREE_BOOTSTRAP_CONFIG_LOCATIONS) {
|
|
10187
|
-
const configPath = (0,
|
|
10188
|
-
if (!(0,
|
|
10261
|
+
const configPath = (0, import_path5.join)(workspace, relative3);
|
|
10262
|
+
if (!(0, import_fs5.existsSync)(configPath)) continue;
|
|
10189
10263
|
try {
|
|
10190
|
-
const parsed = parseConfigText2(configPath, (0,
|
|
10264
|
+
const parsed = parseConfigText2(configPath, (0, import_fs5.readFileSync)(configPath, "utf-8"));
|
|
10191
10265
|
const validation = validateMeshWorktreeBootstrapConfig(parsed, relative3);
|
|
10192
10266
|
if (!validation.valid) return { source: relative3, sourceType: "invalid", path: configPath, error: String(validation.rejectedCommands[0]?.reason || validation.errors.join("; ")) };
|
|
10193
10267
|
return { config: parsed, source: relative3, sourceType: "repo_file", path: configPath };
|
|
@@ -10221,10 +10295,10 @@ async function runMeshWorktreeBootstrap(mesh, workspace) {
|
|
|
10221
10295
|
staleInputs: loaded.config.staleInputs
|
|
10222
10296
|
};
|
|
10223
10297
|
const staleInputPaths = loaded.config.staleInputs ?? [];
|
|
10224
|
-
const initiallyAbsent = staleInputPaths.filter((p) => !(0,
|
|
10298
|
+
const initiallyAbsent = staleInputPaths.filter((p) => !(0, import_fs5.existsSync)((0, import_path5.join)(workspace, p)));
|
|
10225
10299
|
for (const command of validation.commands) {
|
|
10226
10300
|
if (initiallyAbsent.length > 0) {
|
|
10227
|
-
const appearedNow = initiallyAbsent.filter((p) => (0,
|
|
10301
|
+
const appearedNow = initiallyAbsent.filter((p) => (0, import_fs5.existsSync)((0, import_path5.join)(workspace, p)));
|
|
10228
10302
|
if (appearedNow.length > 0) {
|
|
10229
10303
|
state.status = "stale";
|
|
10230
10304
|
state.completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -10232,7 +10306,7 @@ async function runMeshWorktreeBootstrap(mesh, workspace) {
|
|
|
10232
10306
|
return state;
|
|
10233
10307
|
}
|
|
10234
10308
|
}
|
|
10235
|
-
const cwd = command.cwd ? (0,
|
|
10309
|
+
const cwd = command.cwd ? (0, import_path5.resolve)(workspace, command.cwd) : workspace;
|
|
10236
10310
|
const startedAt = Date.now();
|
|
10237
10311
|
state.lastCommand = command.displayCommand;
|
|
10238
10312
|
try {
|
|
@@ -11287,8 +11361,8 @@ var P2pRelayFailureError = class extends Error {
|
|
|
11287
11361
|
};
|
|
11288
11362
|
|
|
11289
11363
|
// src/config/state-store.ts
|
|
11290
|
-
var
|
|
11291
|
-
var
|
|
11364
|
+
var import_fs10 = require("fs");
|
|
11365
|
+
var import_path9 = require("path");
|
|
11292
11366
|
init_config();
|
|
11293
11367
|
var DEFAULT_STATE = {
|
|
11294
11368
|
recentActivity: [],
|
|
@@ -11302,7 +11376,7 @@ function isPlainObject2(value) {
|
|
|
11302
11376
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
11303
11377
|
}
|
|
11304
11378
|
function getStatePath() {
|
|
11305
|
-
return (0,
|
|
11379
|
+
return (0, import_path9.join)(getConfigDir(), "state.json");
|
|
11306
11380
|
}
|
|
11307
11381
|
function normalizeState(raw) {
|
|
11308
11382
|
const parsed = isPlainObject2(raw) ? raw : {};
|
|
@@ -11338,11 +11412,11 @@ function normalizeState(raw) {
|
|
|
11338
11412
|
}
|
|
11339
11413
|
function loadState() {
|
|
11340
11414
|
const statePath = getStatePath();
|
|
11341
|
-
if (!(0,
|
|
11415
|
+
if (!(0, import_fs10.existsSync)(statePath)) {
|
|
11342
11416
|
return { ...DEFAULT_STATE };
|
|
11343
11417
|
}
|
|
11344
11418
|
try {
|
|
11345
|
-
const raw = (0,
|
|
11419
|
+
const raw = (0, import_fs10.readFileSync)(statePath, "utf-8");
|
|
11346
11420
|
return normalizeState(JSON.parse(raw));
|
|
11347
11421
|
} catch {
|
|
11348
11422
|
return { ...DEFAULT_STATE };
|
|
@@ -11351,7 +11425,7 @@ function loadState() {
|
|
|
11351
11425
|
function saveState(state) {
|
|
11352
11426
|
const statePath = getStatePath();
|
|
11353
11427
|
const normalized = normalizeState(state);
|
|
11354
|
-
(0,
|
|
11428
|
+
(0, import_fs10.writeFileSync)(statePath, JSON.stringify(normalized, null, 2), { encoding: "utf-8", mode: 384 });
|
|
11355
11429
|
}
|
|
11356
11430
|
function resetState() {
|
|
11357
11431
|
saveState({ ...DEFAULT_STATE });
|
|
@@ -11360,7 +11434,7 @@ function resetState() {
|
|
|
11360
11434
|
// src/detection/ide-detector.ts
|
|
11361
11435
|
var import_child_process2 = require("child_process");
|
|
11362
11436
|
var import_util = require("util");
|
|
11363
|
-
var
|
|
11437
|
+
var import_fs11 = require("fs");
|
|
11364
11438
|
var import_os2 = require("os");
|
|
11365
11439
|
var path10 = __toESM(require("path"));
|
|
11366
11440
|
var execAsync2 = (0, import_util.promisify)(import_child_process2.exec);
|
|
@@ -11385,7 +11459,7 @@ function findCliCommand(command) {
|
|
|
11385
11459
|
if (path10.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~")) {
|
|
11386
11460
|
const candidate = trimmed.startsWith("~") ? path10.join((0, import_os2.homedir)(), trimmed.slice(1)) : trimmed;
|
|
11387
11461
|
const resolved = path10.isAbsolute(candidate) ? candidate : path10.resolve(candidate);
|
|
11388
|
-
return (0,
|
|
11462
|
+
return (0, import_fs11.existsSync)(resolved) ? resolved : null;
|
|
11389
11463
|
}
|
|
11390
11464
|
const isWin = (0, import_os2.platform)() === "win32";
|
|
11391
11465
|
const paths = (process.env.PATH || "").split(isWin ? ";" : ":");
|
|
@@ -11395,8 +11469,8 @@ function findCliCommand(command) {
|
|
|
11395
11469
|
for (const ext of exes) {
|
|
11396
11470
|
const fullPath = path10.join(p, trimmed + ext);
|
|
11397
11471
|
try {
|
|
11398
|
-
if ((0,
|
|
11399
|
-
const stat2 = (0,
|
|
11472
|
+
if ((0, import_fs11.existsSync)(fullPath)) {
|
|
11473
|
+
const stat2 = (0, import_fs11.statSync)(fullPath);
|
|
11400
11474
|
if (stat2.isFile() && (isWin || stat2.mode & 73)) {
|
|
11401
11475
|
return fullPath;
|
|
11402
11476
|
}
|
|
@@ -11425,9 +11499,9 @@ function checkPathExists(paths) {
|
|
|
11425
11499
|
if (normalized.includes("*")) {
|
|
11426
11500
|
const username = home.split(/[\\/]/).pop() || "";
|
|
11427
11501
|
const resolved = normalized.replace("*", username);
|
|
11428
|
-
if ((0,
|
|
11502
|
+
if ((0, import_fs11.existsSync)(resolved)) return resolved;
|
|
11429
11503
|
} else {
|
|
11430
|
-
if ((0,
|
|
11504
|
+
if ((0, import_fs11.existsSync)(normalized)) return normalized;
|
|
11431
11505
|
}
|
|
11432
11506
|
}
|
|
11433
11507
|
return null;
|
|
@@ -11441,7 +11515,7 @@ async function detectIDEs(providerLoader) {
|
|
|
11441
11515
|
let resolvedCli = cliPath;
|
|
11442
11516
|
if (!resolvedCli && appPath && os22 === "darwin") {
|
|
11443
11517
|
const bundledCli = `${appPath}/Contents/Resources/app/bin/${def.cli}`;
|
|
11444
|
-
if ((0,
|
|
11518
|
+
if ((0, import_fs11.existsSync)(bundledCli)) resolvedCli = bundledCli;
|
|
11445
11519
|
}
|
|
11446
11520
|
if (!resolvedCli && appPath && os22 === "win32") {
|
|
11447
11521
|
const { dirname: dirname9 } = await import("path");
|
|
@@ -11454,7 +11528,7 @@ async function detectIDEs(providerLoader) {
|
|
|
11454
11528
|
`${appDir}\\\\resources\\\\app\\\\bin\\\\${def.cli}.cmd`
|
|
11455
11529
|
];
|
|
11456
11530
|
for (const c of candidates) {
|
|
11457
|
-
if ((0,
|
|
11531
|
+
if ((0, import_fs11.existsSync)(c)) {
|
|
11458
11532
|
resolvedCli = c;
|
|
11459
11533
|
break;
|
|
11460
11534
|
}
|
|
@@ -17191,7 +17265,7 @@ var ACP_SESSION_CAPABILITIES = [
|
|
|
17191
17265
|
"set_mode",
|
|
17192
17266
|
"set_thought_level"
|
|
17193
17267
|
];
|
|
17194
|
-
function
|
|
17268
|
+
function buildWorkspaceSession(state, cdpManagers, options) {
|
|
17195
17269
|
const profile = options.profile || "full";
|
|
17196
17270
|
const activeChat = normalizeActiveChatData(state.activeChat, getActiveChatOptions(profile));
|
|
17197
17271
|
const summaryMetadata = normalizeProviderSummaryMetadata(state.summaryMetadata);
|
|
@@ -17202,7 +17276,10 @@ function buildIdeWorkspaceSession(state, cdpManagers, options) {
|
|
|
17202
17276
|
const git = getGitSummaryForWorkspace(workspace, options);
|
|
17203
17277
|
const title = activeChat?.title || state.name;
|
|
17204
17278
|
const meshCoordinatorFor = state.settings?.meshCoordinatorFor;
|
|
17205
|
-
const
|
|
17279
|
+
const registryEntry = state.instanceId ? getCoordinatorForSession(state.instanceId) : void 0;
|
|
17280
|
+
const effectiveMeshId = meshCoordinatorFor || registryEntry?.meshId;
|
|
17281
|
+
const coordinator = effectiveMeshId ? { meshId: effectiveMeshId, role: "coordinator" } : void 0;
|
|
17282
|
+
const meshQueueStats = effectiveMeshId ? getMeshQueueStats(effectiveMeshId) : void 0;
|
|
17206
17283
|
return {
|
|
17207
17284
|
id: state.instanceId || state.type,
|
|
17208
17285
|
parentId: null,
|
|
@@ -17226,6 +17303,7 @@ function buildIdeWorkspaceSession(state, cdpManagers, options) {
|
|
|
17226
17303
|
errorReason: state.errorReason,
|
|
17227
17304
|
lastUpdated: state.lastUpdated,
|
|
17228
17305
|
settings: state.settings,
|
|
17306
|
+
...coordinator && { coordinator },
|
|
17229
17307
|
...meshQueueStats && { meshQueueStats }
|
|
17230
17308
|
};
|
|
17231
17309
|
}
|
|
@@ -17239,7 +17317,10 @@ function buildExtensionAgentSession(parent, ext, options) {
|
|
|
17239
17317
|
const workspace = parent.workspace || null;
|
|
17240
17318
|
const git = getGitSummaryForWorkspace(workspace, options);
|
|
17241
17319
|
const meshCoordinatorFor = ext.settings?.meshCoordinatorFor;
|
|
17242
|
-
const
|
|
17320
|
+
const registryEntry = ext.instanceId ? getCoordinatorForSession(ext.instanceId) : void 0;
|
|
17321
|
+
const effectiveMeshId = meshCoordinatorFor || registryEntry?.meshId;
|
|
17322
|
+
const coordinator = effectiveMeshId ? { meshId: effectiveMeshId, role: "coordinator" } : void 0;
|
|
17323
|
+
const meshQueueStats = effectiveMeshId ? getMeshQueueStats(effectiveMeshId) : void 0;
|
|
17243
17324
|
return {
|
|
17244
17325
|
id: ext.instanceId || `${parent.instanceId}:${ext.type}`,
|
|
17245
17326
|
parentId: parent.instanceId || parent.type,
|
|
@@ -17263,6 +17344,7 @@ function buildExtensionAgentSession(parent, ext, options) {
|
|
|
17263
17344
|
errorReason: ext.errorReason,
|
|
17264
17345
|
lastUpdated: ext.lastUpdated,
|
|
17265
17346
|
settings: ext.settings,
|
|
17347
|
+
...coordinator && { coordinator },
|
|
17266
17348
|
...meshQueueStats && { meshQueueStats }
|
|
17267
17349
|
};
|
|
17268
17350
|
}
|
|
@@ -17292,7 +17374,10 @@ function buildCliSession(state, options) {
|
|
|
17292
17374
|
const workspace = state.workspace || null;
|
|
17293
17375
|
const git = getGitSummaryForWorkspace(workspace, options);
|
|
17294
17376
|
const meshCoordinatorFor = state.settings?.meshCoordinatorFor;
|
|
17295
|
-
const
|
|
17377
|
+
const registryEntry = state.instanceId ? getCoordinatorForSession(state.instanceId) : void 0;
|
|
17378
|
+
const effectiveMeshId = meshCoordinatorFor || registryEntry?.meshId;
|
|
17379
|
+
const coordinator = effectiveMeshId ? { meshId: effectiveMeshId, role: "coordinator" } : void 0;
|
|
17380
|
+
const meshQueueStats = effectiveMeshId ? getMeshQueueStats(effectiveMeshId) : void 0;
|
|
17296
17381
|
return {
|
|
17297
17382
|
id: state.instanceId,
|
|
17298
17383
|
parentId: null,
|
|
@@ -17332,6 +17417,7 @@ function buildCliSession(state, options) {
|
|
|
17332
17417
|
errorReason: state.errorReason,
|
|
17333
17418
|
lastUpdated: state.lastUpdated,
|
|
17334
17419
|
settings: state.settings,
|
|
17420
|
+
...coordinator && { coordinator },
|
|
17335
17421
|
...meshQueueStats && { meshQueueStats }
|
|
17336
17422
|
};
|
|
17337
17423
|
}
|
|
@@ -17345,7 +17431,10 @@ function buildAcpSession(state, options) {
|
|
|
17345
17431
|
const workspace = state.workspace || null;
|
|
17346
17432
|
const git = getGitSummaryForWorkspace(workspace, options);
|
|
17347
17433
|
const meshCoordinatorFor = state.settings?.meshCoordinatorFor;
|
|
17348
|
-
const
|
|
17434
|
+
const registryEntry = state.instanceId ? getCoordinatorForSession(state.instanceId) : void 0;
|
|
17435
|
+
const effectiveMeshId = meshCoordinatorFor || registryEntry?.meshId;
|
|
17436
|
+
const coordinator = effectiveMeshId ? { meshId: effectiveMeshId, role: "coordinator" } : void 0;
|
|
17437
|
+
const meshQueueStats = effectiveMeshId ? getMeshQueueStats(effectiveMeshId) : void 0;
|
|
17349
17438
|
return {
|
|
17350
17439
|
id: state.instanceId,
|
|
17351
17440
|
parentId: null,
|
|
@@ -17368,6 +17457,7 @@ function buildAcpSession(state, options) {
|
|
|
17368
17457
|
errorReason: state.errorReason,
|
|
17369
17458
|
lastUpdated: state.lastUpdated,
|
|
17370
17459
|
settings: state.settings,
|
|
17460
|
+
...coordinator && { coordinator },
|
|
17371
17461
|
...meshQueueStats && { meshQueueStats }
|
|
17372
17462
|
};
|
|
17373
17463
|
}
|
|
@@ -17377,7 +17467,7 @@ function buildSessionEntries(allStates, cdpManagers, options = {}) {
|
|
|
17377
17467
|
const cliStates = allStates.filter((s) => s.category === "cli");
|
|
17378
17468
|
const acpStates = allStates.filter((s) => s.category === "acp");
|
|
17379
17469
|
for (const state of ideStates) {
|
|
17380
|
-
sessions.push(
|
|
17470
|
+
sessions.push(buildWorkspaceSession(state, cdpManagers, options));
|
|
17381
17471
|
for (const ext of state.extensions) {
|
|
17382
17472
|
if (!shouldIncludeExtensionSession(ext)) continue;
|
|
17383
17473
|
sessions.push(buildExtensionAgentSession(state, ext, options));
|
|
@@ -21894,7 +21984,7 @@ var DaemonCommandHandler = class {
|
|
|
21894
21984
|
var os13 = __toESM(require("os"));
|
|
21895
21985
|
var path18 = __toESM(require("path"));
|
|
21896
21986
|
var crypto4 = __toESM(require("crypto"));
|
|
21897
|
-
var
|
|
21987
|
+
var import_fs12 = require("fs");
|
|
21898
21988
|
var import_child_process5 = require("child_process");
|
|
21899
21989
|
var import_chalk = __toESM(require("chalk"));
|
|
21900
21990
|
init_provider_cli_adapter();
|
|
@@ -22705,10 +22795,17 @@ var CliProviderInstance = class {
|
|
|
22705
22795
|
return autoApproveActive;
|
|
22706
22796
|
}
|
|
22707
22797
|
const modal = adapterStatus.activeModal;
|
|
22708
|
-
const
|
|
22798
|
+
const buttons = Array.isArray(modal?.buttons) ? modal.buttons.map((b) => String(b || "").trim()).filter(Boolean) : [];
|
|
22799
|
+
if (!modal || buttons.length === 0) {
|
|
22800
|
+
return autoApproveActive;
|
|
22801
|
+
}
|
|
22802
|
+
const { index: buttonIndex, label: buttonLabel } = pickApprovalButton(buttons, this.provider);
|
|
22803
|
+
if (buttonIndex < 0) {
|
|
22804
|
+
return autoApproveActive;
|
|
22805
|
+
}
|
|
22709
22806
|
const signature = [
|
|
22710
22807
|
typeof modal?.message === "string" ? modal.message.trim() : "",
|
|
22711
|
-
|
|
22808
|
+
buttons.join("|"),
|
|
22712
22809
|
buttonIndex
|
|
22713
22810
|
].join("::");
|
|
22714
22811
|
if (!this.autoApproveBusy || signature !== this.lastAutoApprovalSignature) {
|
|
@@ -24606,7 +24703,7 @@ function commandExists(command) {
|
|
|
24606
24703
|
const trimmed = command.trim();
|
|
24607
24704
|
if (!trimmed) return false;
|
|
24608
24705
|
if (isExplicitCommand(trimmed)) {
|
|
24609
|
-
return (0,
|
|
24706
|
+
return (0, import_fs12.existsSync)(expandExecutable(trimmed));
|
|
24610
24707
|
}
|
|
24611
24708
|
try {
|
|
24612
24709
|
(0, import_child_process5.execFileSync)(process.platform === "win32" ? "where" : "which", [trimmed], {
|
|
@@ -24728,10 +24825,10 @@ function hasCliArg(args, flag) {
|
|
|
24728
24825
|
}
|
|
24729
24826
|
function ensureEmptyDelegatedMcpConfig(workspace) {
|
|
24730
24827
|
const baseDir = path18.join(os13.tmpdir(), "adhdev-delegated-agent-empty-mcp");
|
|
24731
|
-
(0,
|
|
24828
|
+
(0, import_fs12.mkdirSync)(baseDir, { recursive: true });
|
|
24732
24829
|
const workspaceHash = crypto4.createHash("sha256").update(path18.resolve(workspace || os13.tmpdir())).digest("hex").slice(0, 16);
|
|
24733
24830
|
const filePath = path18.join(baseDir, `${workspaceHash}.json`);
|
|
24734
|
-
(0,
|
|
24831
|
+
(0, import_fs12.writeFileSync)(filePath, JSON.stringify({ mcpServers: {} }, null, 2), "utf-8");
|
|
24735
24832
|
return filePath;
|
|
24736
24833
|
}
|
|
24737
24834
|
function buildCoordinatorDelegatedCliLaunchOptions(input) {
|
|
@@ -24962,6 +25059,7 @@ var DaemonCliManager = class {
|
|
|
24962
25059
|
this.deps.removeAgentTracking(key);
|
|
24963
25060
|
sessionRegistry?.unregisterByInstanceKey(key);
|
|
24964
25061
|
instanceManager?.removeInstance(key);
|
|
25062
|
+
unregisterMeshCoordinator(key);
|
|
24965
25063
|
LOG.info("CLI", `\u{1F9F9} Auto-cleaned ${status.status} CLI: ${cliType}`);
|
|
24966
25064
|
this.deps.onStatusChange();
|
|
24967
25065
|
}
|
|
@@ -25233,6 +25331,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
25233
25331
|
this.deps.removeAgentTracking(key);
|
|
25234
25332
|
this.deps.getSessionRegistry?.()?.unregisterByInstanceKey(key);
|
|
25235
25333
|
this.deps.getInstanceManager()?.removeInstance(key);
|
|
25334
|
+
unregisterMeshCoordinator(key);
|
|
25236
25335
|
LOG.info("CLI", `\u{1F6D1} Agent stopped: ${adapter.cliType} in ${adapter.workingDir}`);
|
|
25237
25336
|
this.deps.onStatusChange();
|
|
25238
25337
|
} else {
|
|
@@ -25241,6 +25340,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
25241
25340
|
this.deps.getSessionRegistry?.()?.unregisterByInstanceKey(key);
|
|
25242
25341
|
im.removeInstance(key);
|
|
25243
25342
|
this.deps.removeAgentTracking(key);
|
|
25343
|
+
unregisterMeshCoordinator(key);
|
|
25244
25344
|
LOG.warn("CLI", `\u{1F9F9} Force-removed orphan entry: ${key}`);
|
|
25245
25345
|
this.deps.onStatusChange();
|
|
25246
25346
|
}
|
|
@@ -28946,7 +29046,7 @@ async function maybeRunDaemonUpgradeHelperFromEnv() {
|
|
|
28946
29046
|
// src/commands/router.ts
|
|
28947
29047
|
init_mesh_work_queue();
|
|
28948
29048
|
var import_os3 = require("os");
|
|
28949
|
-
var
|
|
29049
|
+
var import_path10 = require("path");
|
|
28950
29050
|
var fs11 = __toESM(require("fs"));
|
|
28951
29051
|
var import_node_child_process5 = require("child_process");
|
|
28952
29052
|
var CHANNEL_NPM_TAG = { stable: "latest", preview: "next" };
|
|
@@ -29094,7 +29194,7 @@ function buildMeshNodeDisplayLabel(node, nodeId, providerPriority) {
|
|
|
29094
29194
|
const explicit = readStringValue(node.machineLabel, node.machine_label, node.machineNickname, node.machine_nickname, node.alias);
|
|
29095
29195
|
if (explicit) return explicit;
|
|
29096
29196
|
const workspace = readStringValue(node.workspace, node.repoRoot, node.repo_root);
|
|
29097
|
-
const workspaceName = workspace ? (0,
|
|
29197
|
+
const workspaceName = workspace ? (0, import_path10.basename)(workspace) : void 0;
|
|
29098
29198
|
const host = readStringValue(node.machineName, node.machine_name, node.hostname, node.host, node.daemonId, node.daemon_id, node.machineId, node.machine_id);
|
|
29099
29199
|
const provider = providerPriority[0] || (Array.isArray(node.providers) ? readStringValue(...node.providers) : void 0);
|
|
29100
29200
|
const parts = [workspaceName, host, provider].filter(Boolean);
|
|
@@ -30200,7 +30300,7 @@ async function runMeshRefineSubmoduleReachabilityGate(repoRoot, mergedTree, opti
|
|
|
30200
30300
|
return match ? { commit: match[1], path: match[2] } : null;
|
|
30201
30301
|
}).filter((entry) => !!entry);
|
|
30202
30302
|
for (const gitlink of gitlinks) {
|
|
30203
|
-
const submodulePath = (0,
|
|
30303
|
+
const submodulePath = (0, import_path10.resolve)(repoRoot, gitlink.path);
|
|
30204
30304
|
const entry = {
|
|
30205
30305
|
path: gitlink.path,
|
|
30206
30306
|
commit: gitlink.commit,
|
|
@@ -30228,7 +30328,7 @@ async function runMeshRefineSubmoduleReachabilityGate(repoRoot, mergedTree, opti
|
|
|
30228
30328
|
try {
|
|
30229
30329
|
const imported = await importCommitFromWorktreeSubmodule(
|
|
30230
30330
|
submodulePath,
|
|
30231
|
-
(0,
|
|
30331
|
+
(0, import_path10.resolve)(options.worktreeRoot, gitlink.path),
|
|
30232
30332
|
gitlink.commit
|
|
30233
30333
|
);
|
|
30234
30334
|
if (imported) {
|
|
@@ -30395,17 +30495,17 @@ async function runMeshRefineValidationGate(mesh, workspace) {
|
|
|
30395
30495
|
...extras
|
|
30396
30496
|
});
|
|
30397
30497
|
const isPackageManagerValidation = (candidate) => {
|
|
30398
|
-
const command = (0,
|
|
30498
|
+
const command = (0, import_path10.basename)(candidate.command).replace(/\.(?:cmd|exe)$/i, "");
|
|
30399
30499
|
return ["npm", "pnpm", "yarn", "bun"].includes(command) && candidate.args.some((arg) => arg === "run" || arg === "test" || arg === "exec");
|
|
30400
30500
|
};
|
|
30401
30501
|
const dependenciesLikelyMissing = (cwd) => {
|
|
30402
|
-
if (!fs11.existsSync((0,
|
|
30403
|
-
if (fs11.existsSync((0,
|
|
30404
|
-
return ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lockb", "bun.lock"].some((lock) => fs11.existsSync((0,
|
|
30502
|
+
if (!fs11.existsSync((0, import_path10.join)(cwd, "package.json"))) return false;
|
|
30503
|
+
if (fs11.existsSync((0, import_path10.join)(cwd, "node_modules"))) return false;
|
|
30504
|
+
return ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lockb", "bun.lock"].some((lock) => fs11.existsSync((0, import_path10.join)(cwd, lock)));
|
|
30405
30505
|
};
|
|
30406
30506
|
for (const candidate of selection.bootstrapCommands) {
|
|
30407
30507
|
const startedAt = Date.now();
|
|
30408
|
-
const cwd = candidate.cwd ? (0,
|
|
30508
|
+
const cwd = candidate.cwd ? (0, import_path10.resolve)(workspace, candidate.cwd) : workspace;
|
|
30409
30509
|
const timeout = candidate.timeoutMs || REFINE_VALIDATION_TIMEOUT_MS;
|
|
30410
30510
|
try {
|
|
30411
30511
|
const result = await execFileAsync3(candidate.command, candidate.args, {
|
|
@@ -30431,7 +30531,7 @@ async function runMeshRefineValidationGate(mesh, workspace) {
|
|
|
30431
30531
|
}
|
|
30432
30532
|
for (const candidate of selection.commands) {
|
|
30433
30533
|
const startedAt = Date.now();
|
|
30434
|
-
const cwd = candidate.cwd ? (0,
|
|
30534
|
+
const cwd = candidate.cwd ? (0, import_path10.resolve)(workspace, candidate.cwd) : workspace;
|
|
30435
30535
|
const timeout = candidate.timeoutMs || REFINE_VALIDATION_TIMEOUT_MS;
|
|
30436
30536
|
if (selection.bootstrapCommands.length === 0 && isPackageManagerValidation(candidate) && dependenciesLikelyMissing(cwd)) {
|
|
30437
30537
|
summary.commandsRun.push(commandRecord(candidate, cwd, startedAt, {
|
|
@@ -30493,13 +30593,13 @@ function serializeMeshCoordinatorMcpConfig(config, format) {
|
|
|
30493
30593
|
}
|
|
30494
30594
|
function resolveHermesUserHome() {
|
|
30495
30595
|
const explicitHome = process.env.HERMES_HOME?.trim();
|
|
30496
|
-
return explicitHome || (0,
|
|
30596
|
+
return explicitHome || (0, import_path10.join)((0, import_os3.homedir)(), ".hermes");
|
|
30497
30597
|
}
|
|
30498
30598
|
function loadHermesCoordinatorBaseConfig(targetConfigPath) {
|
|
30499
30599
|
const sourceHome = resolveHermesUserHome();
|
|
30500
|
-
const sourceConfigPath = (0,
|
|
30600
|
+
const sourceConfigPath = (0, import_path10.join)(sourceHome, "config.yaml");
|
|
30501
30601
|
if (!fs11.existsSync(sourceConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
30502
|
-
if ((0,
|
|
30602
|
+
if ((0, import_path10.resolve)(sourceConfigPath) === (0, import_path10.resolve)(targetConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
30503
30603
|
const parsed = parseMeshCoordinatorMcpConfig(fs11.readFileSync(sourceConfigPath, "utf-8"), "hermes_config_yaml");
|
|
30504
30604
|
const { mcp_servers: _mcpServers, ...baseConfig } = parsed;
|
|
30505
30605
|
return { config: baseConfig, sourceHome, sourceConfigPath };
|
|
@@ -30533,10 +30633,10 @@ function stripHermesCoordinatorTempModelProviderOverrides(config) {
|
|
|
30533
30633
|
return sanitized;
|
|
30534
30634
|
}
|
|
30535
30635
|
function copyHermesCoordinatorCredentialFiles(sourceHome, targetHome) {
|
|
30536
|
-
if ((0,
|
|
30636
|
+
if ((0, import_path10.resolve)(sourceHome) === (0, import_path10.resolve)(targetHome)) return;
|
|
30537
30637
|
for (const fileName of [".env", "auth.json"]) {
|
|
30538
|
-
const sourcePath = (0,
|
|
30539
|
-
const targetPath = (0,
|
|
30638
|
+
const sourcePath = (0, import_path10.join)(sourceHome, fileName);
|
|
30639
|
+
const targetPath = (0, import_path10.join)(targetHome, fileName);
|
|
30540
30640
|
if (!fs11.existsSync(sourcePath)) continue;
|
|
30541
30641
|
try {
|
|
30542
30642
|
fs11.copyFileSync(sourcePath, targetPath);
|
|
@@ -30918,7 +31018,7 @@ var DaemonCommandRouter = class {
|
|
|
30918
31018
|
}
|
|
30919
31019
|
const { resolveWorktreePath: resolveWorktreePath2, listWorktrees: listWorktrees2, removeWorktree: removeWorktree2 } = await Promise.resolve().then(() => (init_git_worktree(), git_worktree_exports));
|
|
30920
31020
|
const normalizePath = (value) => {
|
|
30921
|
-
const resolved = (0,
|
|
31021
|
+
const resolved = (0, import_path10.resolve)(value);
|
|
30922
31022
|
try {
|
|
30923
31023
|
return fs11.realpathSync(resolved);
|
|
30924
31024
|
} catch {
|
|
@@ -33334,11 +33434,15 @@ ${block2}`);
|
|
|
33334
33434
|
return { success: false, error: cliCmdLaunch?.error || "Failed to launch CLI session" };
|
|
33335
33435
|
}
|
|
33336
33436
|
LOG.info("MeshCoordinator", `Launched ${cliType} coordinator (cli_command) for mesh ${meshId}`);
|
|
33437
|
+
const cliCmdSessionId = cliCmdLaunch.sessionId || cliCmdLaunch.id;
|
|
33438
|
+
if (cliCmdSessionId) {
|
|
33439
|
+
registerMeshCoordinator({ meshId, sessionId: cliCmdSessionId, workspace, startedAt: Date.now() });
|
|
33440
|
+
}
|
|
33337
33441
|
try {
|
|
33338
33442
|
const { appendLedgerEntry: appendLedgerEntry2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
|
|
33339
33443
|
appendLedgerEntry2(meshId, {
|
|
33340
33444
|
kind: "coordinator_started",
|
|
33341
|
-
sessionId:
|
|
33445
|
+
sessionId: cliCmdSessionId,
|
|
33342
33446
|
providerType: cliType,
|
|
33343
33447
|
payload: { workspace }
|
|
33344
33448
|
});
|
|
@@ -33349,7 +33453,7 @@ ${block2}`);
|
|
|
33349
33453
|
meshId,
|
|
33350
33454
|
cliType,
|
|
33351
33455
|
workspace,
|
|
33352
|
-
sessionId:
|
|
33456
|
+
sessionId: cliCmdSessionId,
|
|
33353
33457
|
mcpRegistered: true
|
|
33354
33458
|
};
|
|
33355
33459
|
}
|
|
@@ -33379,7 +33483,7 @@ ${block2}`);
|
|
|
33379
33483
|
workspace
|
|
33380
33484
|
};
|
|
33381
33485
|
}
|
|
33382
|
-
const { existsSync:
|
|
33486
|
+
const { existsSync: existsSync29, readFileSync: readFileSync22, writeFileSync: writeFileSync17, copyFileSync: copyFileSync4, mkdirSync: mkdirSync18 } = await import("fs");
|
|
33383
33487
|
const { dirname: dirname9 } = await import("path");
|
|
33384
33488
|
const mcpConfigPath = coordinatorSetup.configPath;
|
|
33385
33489
|
const hermesManualFallback = cliType === "hermes-cli" && configFormat === "hermes_config_yaml" ? createHermesManualMeshCoordinatorSetup(meshId, workspace) : null;
|
|
@@ -33422,14 +33526,14 @@ ${block2}`);
|
|
|
33422
33526
|
if (hermesManualFallback) return returnManualFallback(message);
|
|
33423
33527
|
return { success: false, code: "mesh_coordinator_config_write_failed", error: message, meshId, cliType, workspace };
|
|
33424
33528
|
}
|
|
33425
|
-
const hadExistingMcpConfig =
|
|
33529
|
+
const hadExistingMcpConfig = existsSync29(mcpConfigPath);
|
|
33426
33530
|
let existingMcpConfig = hermesBaseConfig?.config || {};
|
|
33427
33531
|
if (hermesBaseConfig) {
|
|
33428
33532
|
copyHermesCoordinatorCredentialFiles(hermesBaseConfig.sourceHome, dirname9(mcpConfigPath));
|
|
33429
33533
|
}
|
|
33430
33534
|
if (hadExistingMcpConfig) {
|
|
33431
33535
|
try {
|
|
33432
|
-
const parsedExistingMcpConfig = parseMeshCoordinatorMcpConfig(
|
|
33536
|
+
const parsedExistingMcpConfig = parseMeshCoordinatorMcpConfig(readFileSync22(mcpConfigPath, "utf-8"), configFormat);
|
|
33433
33537
|
const existingCoordinatorConfig = hermesManualFallback ? stripHermesCoordinatorTempModelProviderOverrides(parsedExistingMcpConfig) : parsedExistingMcpConfig;
|
|
33434
33538
|
existingMcpConfig = { ...existingMcpConfig, ...existingCoordinatorConfig };
|
|
33435
33539
|
copyFileSync4(mcpConfigPath, mcpConfigPath + ".backup");
|
|
@@ -33452,7 +33556,7 @@ ${block2}`);
|
|
|
33452
33556
|
}
|
|
33453
33557
|
};
|
|
33454
33558
|
try {
|
|
33455
|
-
|
|
33559
|
+
writeFileSync17(mcpConfigPath, serializeMeshCoordinatorMcpConfig(mcpConfig, configFormat), "utf-8");
|
|
33456
33560
|
} catch (error) {
|
|
33457
33561
|
const message = `Could not write MCP config for automatic setup: ${error?.message || error}`;
|
|
33458
33562
|
LOG.error("MeshCoordinator", message);
|
|
@@ -33489,11 +33593,15 @@ ${block2}`);
|
|
|
33489
33593
|
return { success: false, error: launchResult?.error || "Failed to launch CLI session" };
|
|
33490
33594
|
}
|
|
33491
33595
|
LOG.info("MeshCoordinator", `Launched ${cliType} coordinator for mesh ${meshId} in ${workspace}`);
|
|
33596
|
+
const launchSessionId = launchResult.sessionId || launchResult.id;
|
|
33597
|
+
if (launchSessionId) {
|
|
33598
|
+
registerMeshCoordinator({ meshId, sessionId: launchSessionId, workspace, startedAt: Date.now() });
|
|
33599
|
+
}
|
|
33492
33600
|
try {
|
|
33493
33601
|
const { appendLedgerEntry: appendLedgerEntry2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
|
|
33494
33602
|
appendLedgerEntry2(meshId, {
|
|
33495
33603
|
kind: "coordinator_started",
|
|
33496
|
-
sessionId:
|
|
33604
|
+
sessionId: launchSessionId,
|
|
33497
33605
|
providerType: cliType,
|
|
33498
33606
|
payload: { workspace }
|
|
33499
33607
|
});
|
|
@@ -33504,7 +33612,7 @@ ${block2}`);
|
|
|
33504
33612
|
meshId,
|
|
33505
33613
|
cliType,
|
|
33506
33614
|
workspace,
|
|
33507
|
-
sessionId:
|
|
33615
|
+
sessionId: launchSessionId,
|
|
33508
33616
|
mcpConfigWritten: true
|
|
33509
33617
|
};
|
|
33510
33618
|
} catch (e) {
|
|
@@ -41704,6 +41812,7 @@ init_config();
|
|
|
41704
41812
|
init_mesh_events();
|
|
41705
41813
|
async function initDaemonComponents(config) {
|
|
41706
41814
|
installGlobalInterceptor();
|
|
41815
|
+
loadMeshCoordinatorRegistry();
|
|
41707
41816
|
const appConfig = loadConfig();
|
|
41708
41817
|
const providerSourceMode = appConfig.providerSourceMode || "normal";
|
|
41709
41818
|
const disableUpstream = providerSourceMode === "no-upstream";
|
|
@@ -42061,7 +42170,9 @@ async function shutdownDaemonComponents(components) {
|
|
|
42061
42170
|
getAIExtensions,
|
|
42062
42171
|
getActiveDirectDispatches,
|
|
42063
42172
|
getAvailableIdeIds,
|
|
42173
|
+
getCoordinatorForSession,
|
|
42064
42174
|
getCurrentDaemonLogPath,
|
|
42175
|
+
getDaemonDataDir,
|
|
42065
42176
|
getDaemonLogDir,
|
|
42066
42177
|
getDebugRuntimeConfig,
|
|
42067
42178
|
getGitDiffSummary,
|
|
@@ -42113,10 +42224,12 @@ async function shutdownDaemonComponents(components) {
|
|
|
42113
42224
|
killIdeProcess,
|
|
42114
42225
|
launchIDE,
|
|
42115
42226
|
launchWithCdp,
|
|
42227
|
+
listCoordinatorsForWorkspace,
|
|
42116
42228
|
listHostedCliRuntimes,
|
|
42117
42229
|
listMeshes,
|
|
42118
42230
|
listWorktrees,
|
|
42119
42231
|
loadConfig,
|
|
42232
|
+
loadMeshCoordinatorRegistry,
|
|
42120
42233
|
loadMeshRefineConfig,
|
|
42121
42234
|
loadMeshWorktreeBootstrapConfig,
|
|
42122
42235
|
loadState,
|
|
@@ -42153,6 +42266,7 @@ async function shutdownDaemonComponents(components) {
|
|
|
42153
42266
|
readLedgerSlice,
|
|
42154
42267
|
recordDebugTrace,
|
|
42155
42268
|
registerExtensionProviders,
|
|
42269
|
+
registerMeshCoordinator,
|
|
42156
42270
|
removeNode,
|
|
42157
42271
|
removeWorktree,
|
|
42158
42272
|
requeueTask,
|
|
@@ -42186,6 +42300,7 @@ async function shutdownDaemonComponents(components) {
|
|
|
42186
42300
|
summarizeGitStatus,
|
|
42187
42301
|
syncMeshes,
|
|
42188
42302
|
triggerMeshQueue,
|
|
42303
|
+
unregisterMeshCoordinator,
|
|
42189
42304
|
updateConfig,
|
|
42190
42305
|
updateDirectDispatchStatus,
|
|
42191
42306
|
updateMesh,
|