@adhdev/daemon-standalone 1.0.42 → 1.0.43-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +806 -722
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/public/assets/{index-B0peupbj.js → index-Bb-LJxkh.js} +37 -37
- package/public/index.html +1 -1
- package/vendor/mcp-server/index.js +3 -2
- package/vendor/mcp-server/index.js.map +1 -1
- package/vendor/mcp-server/package.json +3 -44
- package/vendor/session-host-daemon/index.js +21 -8
- package/vendor/session-host-daemon/index.js.map +1 -1
- package/vendor/session-host-daemon/index.mjs +21 -8
- package/vendor/session-host-daemon/index.mjs.map +1 -1
package/dist/index.js
CHANGED
|
@@ -31423,9 +31423,9 @@ var require_streamx = __commonJS({
|
|
|
31423
31423
|
}
|
|
31424
31424
|
});
|
|
31425
31425
|
|
|
31426
|
-
//
|
|
31426
|
+
// ../../node_modules/tar-stream/node_modules/b4a/index.js
|
|
31427
31427
|
var require_b4a2 = __commonJS({
|
|
31428
|
-
"
|
|
31428
|
+
"../../node_modules/tar-stream/node_modules/b4a/index.js"(exports2, module2) {
|
|
31429
31429
|
"use strict";
|
|
31430
31430
|
function isBuffer(value) {
|
|
31431
31431
|
return Buffer.isBuffer(value) || value instanceof Uint8Array;
|
|
@@ -31581,9 +31581,9 @@ var require_b4a2 = __commonJS({
|
|
|
31581
31581
|
}
|
|
31582
31582
|
});
|
|
31583
31583
|
|
|
31584
|
-
//
|
|
31584
|
+
// ../../node_modules/tar-stream/headers.js
|
|
31585
31585
|
var require_headers = __commonJS({
|
|
31586
|
-
"
|
|
31586
|
+
"../../node_modules/tar-stream/headers.js"(exports2) {
|
|
31587
31587
|
"use strict";
|
|
31588
31588
|
var b4a = require_b4a2();
|
|
31589
31589
|
var ZEROS = "0000000000000000000";
|
|
@@ -31844,9 +31844,9 @@ var require_headers = __commonJS({
|
|
|
31844
31844
|
}
|
|
31845
31845
|
});
|
|
31846
31846
|
|
|
31847
|
-
//
|
|
31847
|
+
// ../../node_modules/tar-stream/extract.js
|
|
31848
31848
|
var require_extract = __commonJS({
|
|
31849
|
-
"
|
|
31849
|
+
"../../node_modules/tar-stream/extract.js"(exports2, module2) {
|
|
31850
31850
|
"use strict";
|
|
31851
31851
|
var { Writable, Readable, getStreamError } = require_streamx();
|
|
31852
31852
|
var FIFO = require_fast_fifo();
|
|
@@ -32189,9 +32189,9 @@ var require_extract = __commonJS({
|
|
|
32189
32189
|
}
|
|
32190
32190
|
});
|
|
32191
32191
|
|
|
32192
|
-
//
|
|
32192
|
+
// ../../node_modules/tar-stream/constants.js
|
|
32193
32193
|
var require_constants = __commonJS({
|
|
32194
|
-
"
|
|
32194
|
+
"../../node_modules/tar-stream/constants.js"(exports2, module2) {
|
|
32195
32195
|
"use strict";
|
|
32196
32196
|
var constants = {
|
|
32197
32197
|
// just for envs without fs
|
|
@@ -32210,9 +32210,9 @@ var require_constants = __commonJS({
|
|
|
32210
32210
|
}
|
|
32211
32211
|
});
|
|
32212
32212
|
|
|
32213
|
-
//
|
|
32213
|
+
// ../../node_modules/tar-stream/pack.js
|
|
32214
32214
|
var require_pack = __commonJS({
|
|
32215
|
-
"
|
|
32215
|
+
"../../node_modules/tar-stream/pack.js"(exports2, module2) {
|
|
32216
32216
|
"use strict";
|
|
32217
32217
|
var { Readable, Writable, getStreamError } = require_streamx();
|
|
32218
32218
|
var b4a = require_b4a2();
|
|
@@ -32445,9 +32445,9 @@ var require_pack = __commonJS({
|
|
|
32445
32445
|
}
|
|
32446
32446
|
});
|
|
32447
32447
|
|
|
32448
|
-
//
|
|
32448
|
+
// ../../node_modules/tar-stream/index.js
|
|
32449
32449
|
var require_tar_stream = __commonJS({
|
|
32450
|
-
"
|
|
32450
|
+
"../../node_modules/tar-stream/index.js"(exports2) {
|
|
32451
32451
|
"use strict";
|
|
32452
32452
|
exports2.extract = require_extract();
|
|
32453
32453
|
exports2.pack = require_pack();
|
|
@@ -32690,9 +32690,9 @@ var require_pump = __commonJS({
|
|
|
32690
32690
|
}
|
|
32691
32691
|
});
|
|
32692
32692
|
|
|
32693
|
-
//
|
|
32693
|
+
// ../../node_modules/tar-fs/index.js
|
|
32694
32694
|
var require_tar_fs = __commonJS({
|
|
32695
|
-
"
|
|
32695
|
+
"../../node_modules/tar-fs/index.js"(exports2) {
|
|
32696
32696
|
"use strict";
|
|
32697
32697
|
var tar = require_tar_stream();
|
|
32698
32698
|
var pump = require_pump();
|
|
@@ -36556,10 +36556,10 @@ var require_dist3 = __commonJS({
|
|
|
36556
36556
|
}
|
|
36557
36557
|
function getDaemonBuildInfo() {
|
|
36558
36558
|
if (cached2) return cached2;
|
|
36559
|
-
const commit = readInjected(true ? "
|
|
36560
|
-
const commitShort = readInjected(true ? "
|
|
36561
|
-
const version2 = readInjected(true ? "1.0.
|
|
36562
|
-
const builtAt = readInjected(true ? "2026-08-
|
|
36559
|
+
const commit = readInjected(true ? "4c0b4f5134ad0c5994f030f228fa8d270fd75b6e" : void 0) ?? "unknown";
|
|
36560
|
+
const commitShort = readInjected(true ? "4c0b4f51" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
|
|
36561
|
+
const version2 = readInjected(true ? "1.0.43-rc.1" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
|
|
36562
|
+
const builtAt = readInjected(true ? "2026-08-11T02:05:06.448Z" : void 0);
|
|
36563
36563
|
cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
|
|
36564
36564
|
return cached2;
|
|
36565
36565
|
}
|
|
@@ -37817,7 +37817,7 @@ var require_dist3 = __commonJS({
|
|
|
37817
37817
|
}
|
|
37818
37818
|
});
|
|
37819
37819
|
function resolveBuildTrack(env2 = process.env) {
|
|
37820
|
-
const injected = true ? "" : void 0;
|
|
37820
|
+
const injected = true ? "preview" : void 0;
|
|
37821
37821
|
const stamped = typeof injected === "string" ? injected.trim() : "";
|
|
37822
37822
|
const raw = (stamped || (env2[BUILD_CHANNEL_ENV_VAR] ?? "").trim()).toLowerCase();
|
|
37823
37823
|
return raw === "preview" || raw === "next" ? "preview" : "stable";
|
|
@@ -45595,9 +45595,13 @@ Next step: ${nextStep}`;
|
|
|
45595
45595
|
if (!REFINE_TERMINAL_EVENTS.has(event.event)) return false;
|
|
45596
45596
|
const jobId = readRefineJobId2(event);
|
|
45597
45597
|
if (!jobId) return false;
|
|
45598
|
-
|
|
45599
|
-
(
|
|
45600
|
-
|
|
45598
|
+
try {
|
|
45599
|
+
return MeshRuntimeStore.getInstance().peekPendingEvents(event.meshId).some(
|
|
45600
|
+
(row) => row.event === event.event && readRefineJobId2(row.payload) === jobId
|
|
45601
|
+
);
|
|
45602
|
+
} catch {
|
|
45603
|
+
return false;
|
|
45604
|
+
}
|
|
45601
45605
|
}
|
|
45602
45606
|
function buildPendingEventFingerprint(event) {
|
|
45603
45607
|
const metadata = readRecord2(event.metadataEvent) || {};
|
|
@@ -45640,42 +45644,10 @@ Next step: ${nextStep}`;
|
|
|
45640
45644
|
const fingerprint = buildPendingEventFingerprint(event);
|
|
45641
45645
|
if (!fingerprint.trim()) return false;
|
|
45642
45646
|
try {
|
|
45643
|
-
|
|
45647
|
+
return MeshRuntimeStore.getInstance().hasPendingEventFingerprint(event.meshId, fingerprint);
|
|
45644
45648
|
} catch {
|
|
45649
|
+
return false;
|
|
45645
45650
|
}
|
|
45646
|
-
return readPendingMeshCoordinatorEventsFromDisk(event.meshId).some((pending) => buildPendingEventFingerprint(pending) === fingerprint);
|
|
45647
|
-
}
|
|
45648
|
-
function getPendingEventsPath(meshId, coordinatorDaemonId) {
|
|
45649
|
-
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
45650
|
-
if (coordinatorDaemonId) {
|
|
45651
|
-
const safeDaemon = coordinatorDaemonId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
45652
|
-
return (0, import_path6.join)(getLedgerDir(), `${safe}-${safeDaemon}.pending-events.jsonl`);
|
|
45653
|
-
}
|
|
45654
|
-
return (0, import_path6.join)(getLedgerDir(), `${safe}.pending-events.jsonl`);
|
|
45655
|
-
}
|
|
45656
|
-
function readPendingMeshCoordinatorEventsFromDisk(meshId, coordinatorDaemonId) {
|
|
45657
|
-
if (!meshId) return [];
|
|
45658
|
-
const daemonIds = normalizeCoordinatorDaemonIds(coordinatorDaemonId);
|
|
45659
|
-
const primaryDaemonId = daemonIds[0];
|
|
45660
|
-
const paths = primaryDaemonId ? [getPendingEventsPath(meshId, primaryDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
|
|
45661
|
-
const events = [];
|
|
45662
|
-
for (const path54 of paths) {
|
|
45663
|
-
if (!(0, import_fs6.existsSync)(path54)) continue;
|
|
45664
|
-
try {
|
|
45665
|
-
const raw = (0, import_fs6.readFileSync)(path54, "utf-8");
|
|
45666
|
-
const parsed = raw.split("\n").filter(Boolean).flatMap((line) => {
|
|
45667
|
-
try {
|
|
45668
|
-
return [JSON.parse(line)];
|
|
45669
|
-
} catch {
|
|
45670
|
-
return [];
|
|
45671
|
-
}
|
|
45672
|
-
});
|
|
45673
|
-
const filtered = primaryDaemonId && path54 === getPendingEventsPath(meshId) ? parsed.filter((e) => !e.targetCoordinatorDaemonId || daemonIds.includes(e.targetCoordinatorDaemonId)) : parsed;
|
|
45674
|
-
events.push(...filtered);
|
|
45675
|
-
} catch {
|
|
45676
|
-
}
|
|
45677
|
-
}
|
|
45678
|
-
return events;
|
|
45679
45651
|
}
|
|
45680
45652
|
function refineTerminalEventFromLedger(meshId, pending) {
|
|
45681
45653
|
const acceptedJobIds = new Set(
|
|
@@ -45750,50 +45722,6 @@ Next step: ${nextStep}`;
|
|
|
45750
45722
|
return 0;
|
|
45751
45723
|
}
|
|
45752
45724
|
}
|
|
45753
|
-
function trimPendingEventsIfNeeded(path54) {
|
|
45754
|
-
try {
|
|
45755
|
-
if (!(0, import_fs6.existsSync)(path54)) return;
|
|
45756
|
-
if ((0, import_fs6.statSync)(path54).size <= MAX_PENDING_EVENTS_BYTES) return;
|
|
45757
|
-
const lines = (0, import_fs6.readFileSync)(path54, "utf-8").split("\n").filter(Boolean);
|
|
45758
|
-
if (lines.length <= MAX_PENDING_EVENTS_KEEP) return;
|
|
45759
|
-
const dropped = lines.slice(0, lines.length - MAX_PENDING_EVENTS_KEEP);
|
|
45760
|
-
for (const line of dropped) {
|
|
45761
|
-
let event;
|
|
45762
|
-
try {
|
|
45763
|
-
event = JSON.parse(line);
|
|
45764
|
-
} catch {
|
|
45765
|
-
continue;
|
|
45766
|
-
}
|
|
45767
|
-
if (!event || !event.meshId) continue;
|
|
45768
|
-
const finalSummary = readMeshCompletionSummary(event.metadataEvent || {});
|
|
45769
|
-
if (!readNonEmptyString(event.coordinatorMessage) && !finalSummary) continue;
|
|
45770
|
-
try {
|
|
45771
|
-
appendLedgerEntry(event.meshId, {
|
|
45772
|
-
kind: "event_held",
|
|
45773
|
-
...event.nodeId ? { nodeId: event.nodeId } : {},
|
|
45774
|
-
payload: {
|
|
45775
|
-
event: event.event,
|
|
45776
|
-
reason: "pending_trim_dropped",
|
|
45777
|
-
recoverable: true,
|
|
45778
|
-
nodeLabel: event.nodeLabel,
|
|
45779
|
-
...event.workspace ? { workspace: event.workspace } : {},
|
|
45780
|
-
targetCoordinatorDaemonId: event.targetCoordinatorDaemonId ?? null,
|
|
45781
|
-
...readNonEmptyString(event.eventId) ? { eventId: event.eventId } : {},
|
|
45782
|
-
queuedAt: event.queuedAt,
|
|
45783
|
-
...finalSummary ? { finalSummary } : {},
|
|
45784
|
-
// Full original event for lossless mesh_requeue_held_events restore.
|
|
45785
|
-
heldEvent: event
|
|
45786
|
-
}
|
|
45787
|
-
});
|
|
45788
|
-
LOG2.warn("MeshEvents", `Pending-events trim dropping undelivered ${event.event} for mesh ${event.meshId} \u2014 recorded to ledger (recoverable)`);
|
|
45789
|
-
} catch (e) {
|
|
45790
|
-
LOG2.warn("MeshEvents", `Failed to ledger-record trim-dropped ${event.event} for mesh ${event.meshId}: ${e?.message || e}`);
|
|
45791
|
-
}
|
|
45792
|
-
}
|
|
45793
|
-
(0, import_fs6.writeFileSync)(path54, lines.slice(-MAX_PENDING_EVENTS_KEEP).join("\n") + "\n", "utf-8");
|
|
45794
|
-
} catch {
|
|
45795
|
-
}
|
|
45796
|
-
}
|
|
45797
45725
|
function stampPendingEventV2(event, hint) {
|
|
45798
45726
|
if (event.protocolVersion === MESH_PROTOCOL_VERSION_V2 && readNonEmptyString(event.eventId)) {
|
|
45799
45727
|
return event;
|
|
@@ -45876,40 +45804,30 @@ Next step: ${nextStep}`;
|
|
|
45876
45804
|
return true;
|
|
45877
45805
|
}
|
|
45878
45806
|
const fingerprint = buildPendingEventFingerprint(event);
|
|
45879
|
-
|
|
45880
|
-
|
|
45881
|
-
|
|
45882
|
-
|
|
45883
|
-
|
|
45884
|
-
|
|
45885
|
-
|
|
45886
|
-
|
|
45887
|
-
|
|
45888
|
-
|
|
45889
|
-
|
|
45890
|
-
|
|
45891
|
-
|
|
45892
|
-
|
|
45893
|
-
|
|
45894
|
-
|
|
45895
|
-
|
|
45896
|
-
|
|
45897
|
-
intendedFor: event.intendedFor ? JSON.stringify(event.intendedFor) : null
|
|
45898
|
-
});
|
|
45899
|
-
sqliteOk = true;
|
|
45900
|
-
} catch {
|
|
45901
|
-
}
|
|
45902
|
-
try {
|
|
45903
|
-
const path54 = getPendingEventsPath(event.meshId, event.targetCoordinatorDaemonId);
|
|
45904
|
-
trimPendingEventsIfNeeded(path54);
|
|
45905
|
-
(0, import_fs6.appendFileSync)(path54, JSON.stringify(event) + "\n", "utf-8");
|
|
45906
|
-
} catch (e) {
|
|
45907
|
-
if (!sqliteOk) throw e;
|
|
45908
|
-
LOG2.warn("MeshEvents", `JSONL append failed for mesh ${event.meshId}; SQLite holds the event: ${e?.message || e}`);
|
|
45909
|
-
}
|
|
45807
|
+
MeshRuntimeStore.getInstance().insertPendingEvent({
|
|
45808
|
+
id: (0, import_crypto6.randomUUID)(),
|
|
45809
|
+
meshId: event.meshId,
|
|
45810
|
+
coordinatorDaemonId: event.targetCoordinatorDaemonId ?? null,
|
|
45811
|
+
event: event.event,
|
|
45812
|
+
payload: event,
|
|
45813
|
+
fingerprint: fingerprint || null,
|
|
45814
|
+
queuedAt: event.queuedAt,
|
|
45815
|
+
// v2 envelope columns (B2a) — all nullable so v1 rows coexist. The
|
|
45816
|
+
// authoritative copy still rides inside `payload`; these columns exist
|
|
45817
|
+
// for queryable idempotency (event_id) and scope-based drain filtering
|
|
45818
|
+
// (scope / intended_for) without JSON-parsing every row.
|
|
45819
|
+
protocolVersion: event.protocolVersion ?? null,
|
|
45820
|
+
eventId: event.eventId ?? null,
|
|
45821
|
+
scope: event.scope ?? null,
|
|
45822
|
+
dispatchedBy: event.dispatchedBy ? JSON.stringify(event.dispatchedBy) : null,
|
|
45823
|
+
intendedFor: event.intendedFor ? JSON.stringify(event.intendedFor) : null
|
|
45824
|
+
});
|
|
45910
45825
|
return true;
|
|
45911
45826
|
} catch (e) {
|
|
45912
|
-
LOG2.
|
|
45827
|
+
LOG2.error(
|
|
45828
|
+
"MeshEvents",
|
|
45829
|
+
`PENDING-EVENT PERSIST FAILED \u2014 ${event.event} for mesh ${event.meshId} is NOT queued and will NOT be delivered (SQLite is the only store; there is no fallback): ${e?.message || e}`
|
|
45830
|
+
);
|
|
45913
45831
|
return false;
|
|
45914
45832
|
}
|
|
45915
45833
|
}
|
|
@@ -45920,98 +45838,17 @@ Next step: ${nextStep}`;
|
|
|
45920
45838
|
try {
|
|
45921
45839
|
requeued = MeshRuntimeStore.getInstance().requeueDrainedPendingEventByFingerprint(event.meshId, fingerprint);
|
|
45922
45840
|
} catch (e) {
|
|
45923
|
-
LOG2.
|
|
45924
|
-
|
|
45925
|
-
|
|
45926
|
-
|
|
45927
|
-
|
|
45928
|
-
if (!alreadyOnDisk) {
|
|
45929
|
-
trimPendingEventsIfNeeded(path54);
|
|
45930
|
-
(0, import_fs6.appendFileSync)(path54, JSON.stringify(event) + "\n", "utf-8");
|
|
45931
|
-
requeued = true;
|
|
45932
|
-
}
|
|
45933
|
-
} catch (e) {
|
|
45934
|
-
if (!requeued) {
|
|
45935
|
-
LOG2.warn("MeshEvents", `Failed to durably re-queue held ${event.event} for mesh ${event.meshId}: ${e?.message || e}`);
|
|
45936
|
-
return false;
|
|
45937
|
-
}
|
|
45938
|
-
LOG2.warn("MeshEvents", `JSONL re-queue append failed for mesh ${event.meshId}; SQLite holds the event: ${e?.message || e}`);
|
|
45841
|
+
LOG2.error(
|
|
45842
|
+
"MeshEvents",
|
|
45843
|
+
`HELD-EVENT RE-QUEUE FAILED \u2014 ${event.event} for mesh ${event.meshId} was NOT durably returned to the queue (SQLite is the only store): ${e?.message || e}`
|
|
45844
|
+
);
|
|
45845
|
+
return false;
|
|
45939
45846
|
}
|
|
45940
45847
|
return requeued;
|
|
45941
45848
|
}
|
|
45942
|
-
function atomicDrainFile(path54) {
|
|
45943
|
-
const tmpPath = `${path54}.draining`;
|
|
45944
|
-
try {
|
|
45945
|
-
(0, import_fs6.renameSync)(path54, tmpPath);
|
|
45946
|
-
} catch {
|
|
45947
|
-
return null;
|
|
45948
|
-
}
|
|
45949
|
-
try {
|
|
45950
|
-
const content = (0, import_fs6.readFileSync)(tmpPath, "utf-8");
|
|
45951
|
-
try {
|
|
45952
|
-
(0, import_fs6.unlinkSync)(tmpPath);
|
|
45953
|
-
} catch {
|
|
45954
|
-
}
|
|
45955
|
-
return content;
|
|
45956
|
-
} catch {
|
|
45957
|
-
try {
|
|
45958
|
-
(0, import_fs6.unlinkSync)(tmpPath);
|
|
45959
|
-
} catch {
|
|
45960
|
-
}
|
|
45961
|
-
return null;
|
|
45962
|
-
}
|
|
45963
|
-
}
|
|
45964
|
-
function selectiveDrainFile(path54, predicate) {
|
|
45965
|
-
const tmpPath = `${path54}.draining`;
|
|
45966
|
-
try {
|
|
45967
|
-
(0, import_fs6.renameSync)(path54, tmpPath);
|
|
45968
|
-
} catch {
|
|
45969
|
-
return [];
|
|
45970
|
-
}
|
|
45971
|
-
let content;
|
|
45972
|
-
try {
|
|
45973
|
-
content = (0, import_fs6.readFileSync)(tmpPath, "utf-8");
|
|
45974
|
-
} catch {
|
|
45975
|
-
try {
|
|
45976
|
-
(0, import_fs6.unlinkSync)(tmpPath);
|
|
45977
|
-
} catch {
|
|
45978
|
-
}
|
|
45979
|
-
return [];
|
|
45980
|
-
}
|
|
45981
|
-
const consumed = [];
|
|
45982
|
-
const keptLines = [];
|
|
45983
|
-
for (const line of content.split("\n")) {
|
|
45984
|
-
if (!line) continue;
|
|
45985
|
-
let parsed;
|
|
45986
|
-
try {
|
|
45987
|
-
parsed = JSON.parse(line);
|
|
45988
|
-
} catch {
|
|
45989
|
-
parsed = void 0;
|
|
45990
|
-
}
|
|
45991
|
-
if (parsed && predicate(parsed)) {
|
|
45992
|
-
consumed.push(parsed);
|
|
45993
|
-
} else {
|
|
45994
|
-
keptLines.push(line);
|
|
45995
|
-
}
|
|
45996
|
-
}
|
|
45997
|
-
try {
|
|
45998
|
-
if (keptLines.length > 0) {
|
|
45999
|
-
(0, import_fs6.writeFileSync)(path54, keptLines.join("\n") + "\n", "utf-8");
|
|
46000
|
-
}
|
|
46001
|
-
(0, import_fs6.unlinkSync)(tmpPath);
|
|
46002
|
-
} catch {
|
|
46003
|
-
try {
|
|
46004
|
-
if ((0, import_fs6.existsSync)(tmpPath) && !(0, import_fs6.existsSync)(path54)) (0, import_fs6.renameSync)(tmpPath, path54);
|
|
46005
|
-
} catch {
|
|
46006
|
-
}
|
|
46007
|
-
return [];
|
|
46008
|
-
}
|
|
46009
|
-
return consumed;
|
|
46010
|
-
}
|
|
46011
45849
|
function drainPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId, opts) {
|
|
46012
45850
|
if (!meshId) return [];
|
|
46013
45851
|
const daemonIds = normalizeCoordinatorDaemonIds(coordinatorDaemonId);
|
|
46014
|
-
const primaryDaemonId = daemonIds[0];
|
|
46015
45852
|
const drainer = resolveDrainerIdentity(daemonIds, opts?.drainerIdentity);
|
|
46016
45853
|
let priorDrainedEventIds = /* @__PURE__ */ new Set();
|
|
46017
45854
|
try {
|
|
@@ -46019,17 +45856,7 @@ Next step: ${nextStep}`;
|
|
|
46019
45856
|
} catch {
|
|
46020
45857
|
}
|
|
46021
45858
|
const onlyEvents = opts?.onlyEvents;
|
|
46022
|
-
const matchesFilter = (eventName) => !onlyEvents || onlyEvents.has(eventName);
|
|
46023
45859
|
const merged = [];
|
|
46024
|
-
const seenFingerprints = /* @__PURE__ */ new Set();
|
|
46025
|
-
const pushUnique = (event) => {
|
|
46026
|
-
const fingerprint = buildPendingEventFingerprint(event);
|
|
46027
|
-
if (fingerprint.trim()) {
|
|
46028
|
-
if (seenFingerprints.has(fingerprint)) return;
|
|
46029
|
-
seenFingerprints.add(fingerprint);
|
|
46030
|
-
}
|
|
46031
|
-
merged.push(event);
|
|
46032
|
-
};
|
|
46033
45860
|
try {
|
|
46034
45861
|
const store = MeshRuntimeStore.getInstance();
|
|
46035
45862
|
if (store.pendingEventCount(meshId) > 0) {
|
|
@@ -46040,39 +45867,17 @@ Next step: ${nextStep}`;
|
|
|
46040
45867
|
{ ...onlyEvents ? { onlyEvents } : {}, drainedBy }
|
|
46041
45868
|
)) {
|
|
46042
45869
|
const event = row.payload;
|
|
46043
|
-
if (event)
|
|
45870
|
+
if (event) merged.push(event);
|
|
46044
45871
|
}
|
|
46045
45872
|
}
|
|
46046
45873
|
} catch (e) {
|
|
46047
45874
|
if (!loggedSqlitePendingDrainFailure) {
|
|
46048
45875
|
loggedSqlitePendingDrainFailure = true;
|
|
46049
|
-
LOG2.warn("MeshEvents", `SQLite pending-event drain failed for mesh ${meshId}
|
|
45876
|
+
LOG2.warn("MeshEvents", `SQLite pending-event drain failed for mesh ${meshId} \u2014 NO events can be delivered while the store is unavailable (there is no fallback store; further occurrences at debug): ${e?.message || e}`);
|
|
46050
45877
|
} else {
|
|
46051
|
-
LOG2.debug("MeshEvents", `SQLite pending-event drain failed for mesh ${meshId};
|
|
45878
|
+
LOG2.debug("MeshEvents", `SQLite pending-event drain failed for mesh ${meshId}; no events delivered this cycle: ${e?.message || e}`);
|
|
46052
45879
|
}
|
|
46053
45880
|
}
|
|
46054
|
-
const paths = primaryDaemonId ? [getPendingEventsPath(meshId, primaryDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
|
|
46055
|
-
for (const path54 of paths) {
|
|
46056
|
-
const isSharedFile = !!primaryDaemonId && path54 === getPendingEventsPath(meshId);
|
|
46057
|
-
const targets = (e) => !isSharedFile || !e.targetCoordinatorDaemonId || daemonIds.includes(e.targetCoordinatorDaemonId);
|
|
46058
|
-
if (onlyEvents) {
|
|
46059
|
-
for (const event of selectiveDrainFile(path54, (e) => targets(e) && matchesFilter(e.event))) {
|
|
46060
|
-
pushUnique(event);
|
|
46061
|
-
}
|
|
46062
|
-
continue;
|
|
46063
|
-
}
|
|
46064
|
-
const content = atomicDrainFile(path54);
|
|
46065
|
-
if (!content) continue;
|
|
46066
|
-
const parsed = content.split("\n").filter(Boolean).flatMap((line) => {
|
|
46067
|
-
try {
|
|
46068
|
-
return [JSON.parse(line)];
|
|
46069
|
-
} catch {
|
|
46070
|
-
return [];
|
|
46071
|
-
}
|
|
46072
|
-
});
|
|
46073
|
-
const filtered = isSharedFile ? parsed.filter(targets) : parsed;
|
|
46074
|
-
for (const event of filtered) pushUnique(event);
|
|
46075
|
-
}
|
|
46076
45881
|
if (merged.length === 0) return [];
|
|
46077
45882
|
const routed = routeV2EventsForDrainer(merged, drainer, {
|
|
46078
45883
|
alreadyDrained: (eventId) => priorDrainedEventIds.has(eventId),
|
|
@@ -46098,16 +45903,8 @@ Next step: ${nextStep}`;
|
|
|
46098
45903
|
if (matchesTask(row.payload)) ids.push(row.id);
|
|
46099
45904
|
}
|
|
46100
45905
|
if (ids.length) removed += store.deletePendingEventsById(ids);
|
|
46101
|
-
} catch {
|
|
46102
|
-
|
|
46103
|
-
const daemonIds = normalizeCoordinatorDaemonIds(coordinatorDaemonId);
|
|
46104
|
-
const primaryDaemonId = daemonIds[0];
|
|
46105
|
-
const paths = primaryDaemonId ? [getPendingEventsPath(meshId, primaryDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
|
|
46106
|
-
for (const path54 of paths) {
|
|
46107
|
-
try {
|
|
46108
|
-
removed += selectiveDrainFile(path54, matchesTask).length;
|
|
46109
|
-
} catch {
|
|
46110
|
-
}
|
|
45906
|
+
} catch (e) {
|
|
45907
|
+
LOG2.warn("MeshEvents", `Failed to retract dispatch_blocked for task ${taskId} on mesh ${meshId}: ${e?.message || e}`);
|
|
46111
45908
|
}
|
|
46112
45909
|
return removed;
|
|
46113
45910
|
}
|
|
@@ -46121,28 +45918,16 @@ Next step: ${nextStep}`;
|
|
|
46121
45918
|
} catch {
|
|
46122
45919
|
}
|
|
46123
45920
|
const merged = [];
|
|
46124
|
-
const seenFingerprints = /* @__PURE__ */ new Set();
|
|
46125
|
-
const pushUnique = (event) => {
|
|
46126
|
-
const fingerprint = buildPendingEventFingerprint(event);
|
|
46127
|
-
if (fingerprint.trim()) {
|
|
46128
|
-
if (seenFingerprints.has(fingerprint)) return;
|
|
46129
|
-
seenFingerprints.add(fingerprint);
|
|
46130
|
-
}
|
|
46131
|
-
merged.push(event);
|
|
46132
|
-
};
|
|
46133
45921
|
try {
|
|
46134
45922
|
const store = MeshRuntimeStore.getInstance();
|
|
46135
45923
|
if (store.pendingEventCount(meshId) > 0) {
|
|
46136
45924
|
for (const row of store.peekPendingEvents(meshId, daemonIds.length > 0 ? daemonIds : void 0)) {
|
|
46137
45925
|
const event = row.payload;
|
|
46138
|
-
if (event)
|
|
45926
|
+
if (event) merged.push(event);
|
|
46139
45927
|
}
|
|
46140
45928
|
}
|
|
46141
45929
|
} catch {
|
|
46142
45930
|
}
|
|
46143
|
-
for (const event of readPendingMeshCoordinatorEventsFromDisk(meshId, daemonIds)) {
|
|
46144
|
-
pushUnique(event);
|
|
46145
|
-
}
|
|
46146
45931
|
const routed = routeV2EventsForDrainer(merged, drainer, {
|
|
46147
45932
|
alreadyDrained: (eventId) => priorDrainedEventIds.has(eventId),
|
|
46148
45933
|
batchSeen: /* @__PURE__ */ new Set(),
|
|
@@ -46243,37 +46028,24 @@ Next step: ${nextStep}`;
|
|
|
46243
46028
|
}
|
|
46244
46029
|
return result;
|
|
46245
46030
|
}
|
|
46246
|
-
function clearPendingMeshCoordinatorEvents(meshId,
|
|
46031
|
+
function clearPendingMeshCoordinatorEvents(meshId, _coordinatorDaemonId) {
|
|
46247
46032
|
if (!meshId) return;
|
|
46248
46033
|
try {
|
|
46249
46034
|
MeshRuntimeStore.getInstance().clearPendingEventsForMesh(meshId);
|
|
46250
46035
|
} catch {
|
|
46251
46036
|
}
|
|
46252
|
-
const paths = coordinatorDaemonId ? [getPendingEventsPath(meshId, coordinatorDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
|
|
46253
|
-
for (const path54 of paths) {
|
|
46254
|
-
if ((0, import_fs6.existsSync)(path54)) try {
|
|
46255
|
-
(0, import_fs6.unlinkSync)(path54);
|
|
46256
|
-
} catch {
|
|
46257
|
-
}
|
|
46258
|
-
}
|
|
46259
46037
|
}
|
|
46260
|
-
var import_fs6;
|
|
46261
|
-
var import_path6;
|
|
46262
46038
|
var import_crypto6;
|
|
46263
46039
|
var REFINE_TERMINAL_EVENTS;
|
|
46264
46040
|
var meshV2DrainCounters;
|
|
46265
46041
|
var warnedV2Violations;
|
|
46266
46042
|
var loggedSqlitePendingDrainFailure;
|
|
46267
46043
|
var TERMINAL_COMPLETION_EVENTS;
|
|
46268
|
-
var MAX_PENDING_EVENTS_BYTES;
|
|
46269
|
-
var MAX_PENDING_EVENTS_KEEP;
|
|
46270
46044
|
var PENDING_EVENTS_DRAINED_RETENTION_MS;
|
|
46271
46045
|
var PENDING_EVENTS_UNDRAINED_RETENTION_MS;
|
|
46272
46046
|
var init_mesh_events_pending = __esm2({
|
|
46273
46047
|
"src/mesh/mesh-events-pending.ts"() {
|
|
46274
46048
|
"use strict";
|
|
46275
|
-
import_fs6 = require("fs");
|
|
46276
|
-
import_path6 = require("path");
|
|
46277
46049
|
import_crypto6 = require("crypto");
|
|
46278
46050
|
init_logger();
|
|
46279
46051
|
init_config();
|
|
@@ -46317,8 +46089,6 @@ Next step: ${nextStep}`;
|
|
|
46317
46089
|
warnedV2Violations = /* @__PURE__ */ new Set();
|
|
46318
46090
|
loggedSqlitePendingDrainFailure = false;
|
|
46319
46091
|
TERMINAL_COMPLETION_EVENTS = /* @__PURE__ */ new Set(["agent:generating_completed", "agent:stopped"]);
|
|
46320
|
-
MAX_PENDING_EVENTS_BYTES = 100 * 1024;
|
|
46321
|
-
MAX_PENDING_EVENTS_KEEP = 50;
|
|
46322
46092
|
PENDING_EVENTS_DRAINED_RETENTION_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
46323
46093
|
PENDING_EVENTS_UNDRAINED_RETENTION_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
46324
46094
|
}
|
|
@@ -47855,15 +47625,15 @@ Next step: ${nextStep}`;
|
|
|
47855
47625
|
return meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
47856
47626
|
}
|
|
47857
47627
|
function legacyQueuePath(meshId) {
|
|
47858
|
-
return (0,
|
|
47628
|
+
return (0, import_path6.join)(getLedgerDir2(), `${safeMeshId(meshId)}.queue.json`);
|
|
47859
47629
|
}
|
|
47860
47630
|
function cleanupStrayRootRuntimeDb(canonicalPath2) {
|
|
47861
47631
|
try {
|
|
47862
|
-
const strayPath = (0,
|
|
47632
|
+
const strayPath = (0, import_path6.join)(getConfigDir2(), "mesh-runtime.db");
|
|
47863
47633
|
if (strayPath === canonicalPath2) return;
|
|
47864
|
-
if (!(0,
|
|
47865
|
-
if ((0,
|
|
47866
|
-
(0,
|
|
47634
|
+
if (!(0, import_fs6.existsSync)(strayPath)) return;
|
|
47635
|
+
if ((0, import_fs6.statSync)(strayPath).size !== 0) return;
|
|
47636
|
+
(0, import_fs6.unlinkSync)(strayPath);
|
|
47867
47637
|
if (!loggedStrayCleanup) {
|
|
47868
47638
|
loggedStrayCleanup = true;
|
|
47869
47639
|
LOG2.info("MeshRuntimeStore", `Removed stray 0-byte root mesh-runtime.db at ${strayPath}`);
|
|
@@ -47876,18 +47646,18 @@ Next step: ${nextStep}`;
|
|
|
47876
47646
|
}
|
|
47877
47647
|
}
|
|
47878
47648
|
function meshRuntimeStorePath() {
|
|
47879
|
-
const dir =
|
|
47880
|
-
const nextPath = (0,
|
|
47649
|
+
const dir = getLedgerDir2();
|
|
47650
|
+
const nextPath = (0, import_path6.join)(dir, "mesh-runtime.db");
|
|
47881
47651
|
cleanupStrayRootRuntimeDb(nextPath);
|
|
47882
|
-
if ((0,
|
|
47883
|
-
const legacyPath = (0,
|
|
47884
|
-
if (!(0,
|
|
47652
|
+
if ((0, import_fs6.existsSync)(nextPath)) return nextPath;
|
|
47653
|
+
const legacyPath = (0, import_path6.join)(dir, "beads.db");
|
|
47654
|
+
if (!(0, import_fs6.existsSync)(legacyPath)) return nextPath;
|
|
47885
47655
|
try {
|
|
47886
|
-
(0,
|
|
47656
|
+
(0, import_fs6.renameSync)(legacyPath, nextPath);
|
|
47887
47657
|
for (const suffix of ["-wal", "-shm"]) {
|
|
47888
47658
|
const legacyCompanion = `${legacyPath}${suffix}`;
|
|
47889
|
-
if ((0,
|
|
47890
|
-
(0,
|
|
47659
|
+
if ((0, import_fs6.existsSync)(legacyCompanion)) {
|
|
47660
|
+
(0, import_fs6.renameSync)(legacyCompanion, `${nextPath}${suffix}`);
|
|
47891
47661
|
}
|
|
47892
47662
|
}
|
|
47893
47663
|
} catch (err) {
|
|
@@ -47898,7 +47668,7 @@ Next step: ${nextStep}`;
|
|
|
47898
47668
|
`Legacy beads.db\u2192mesh-runtime.db migration failed; using existing DB in-place to avoid data loss: ${err?.message || err}`
|
|
47899
47669
|
);
|
|
47900
47670
|
}
|
|
47901
|
-
return (0,
|
|
47671
|
+
return (0, import_fs6.existsSync)(nextPath) ? nextPath : legacyPath;
|
|
47902
47672
|
}
|
|
47903
47673
|
return nextPath;
|
|
47904
47674
|
}
|
|
@@ -47959,8 +47729,8 @@ Next step: ${nextStep}`;
|
|
|
47959
47729
|
return { ledger: 0, toolCalls: 0, terminalQueue: 0, sessionDelivery: 0 };
|
|
47960
47730
|
}
|
|
47961
47731
|
}
|
|
47962
|
-
var
|
|
47963
|
-
var
|
|
47732
|
+
var import_fs6;
|
|
47733
|
+
var import_path6;
|
|
47964
47734
|
var DatabaseCtor;
|
|
47965
47735
|
var loggedMigrationFailure;
|
|
47966
47736
|
var loggedStrayCleanup;
|
|
@@ -47971,8 +47741,8 @@ Next step: ${nextStep}`;
|
|
|
47971
47741
|
var init_mesh_runtime_store = __esm2({
|
|
47972
47742
|
"src/mesh/mesh-runtime-store.ts"() {
|
|
47973
47743
|
"use strict";
|
|
47974
|
-
|
|
47975
|
-
|
|
47744
|
+
import_fs6 = require("fs");
|
|
47745
|
+
import_path6 = require("path");
|
|
47976
47746
|
init_logger();
|
|
47977
47747
|
init_load_better_sqlite3();
|
|
47978
47748
|
init_config();
|
|
@@ -48005,8 +47775,8 @@ Next step: ${nextStep}`;
|
|
|
48005
47775
|
static WAL_MAX_BYTES = 50 * 1024 * 1024;
|
|
48006
47776
|
// 50 MB
|
|
48007
47777
|
constructor(dbPath) {
|
|
48008
|
-
const dir = (0,
|
|
48009
|
-
if (!(0,
|
|
47778
|
+
const dir = (0, import_path6.dirname)(dbPath);
|
|
47779
|
+
if (!(0, import_fs6.existsSync)(dir)) (0, import_fs6.mkdirSync)(dir, { recursive: true });
|
|
48010
47780
|
this.dbPath = dbPath;
|
|
48011
47781
|
this.db = new (loadDatabaseCtor())(dbPath);
|
|
48012
47782
|
this.db.pragma("journal_mode = WAL");
|
|
@@ -48525,8 +48295,8 @@ Next step: ${nextStep}`;
|
|
|
48525
48295
|
this.walWriteCounter = 0;
|
|
48526
48296
|
try {
|
|
48527
48297
|
const walPath = `${this.dbPath}-wal`;
|
|
48528
|
-
if (!(0,
|
|
48529
|
-
const size = (0,
|
|
48298
|
+
if (!(0, import_fs6.existsSync)(walPath)) return;
|
|
48299
|
+
const size = (0, import_fs6.statSync)(walPath).size;
|
|
48530
48300
|
if (size < _MeshRuntimeStore.WAL_MAX_BYTES) return;
|
|
48531
48301
|
process.stderr.write(
|
|
48532
48302
|
`[adhdev-mesh] WAL file ${Math.round(size / 1024 / 1024)}MB exceeds threshold; forcing checkpoint
|
|
@@ -48542,9 +48312,9 @@ Next step: ${nextStep}`;
|
|
|
48542
48312
|
const count = this.db.prepare("SELECT COUNT(*) AS count FROM mesh_queue WHERE mesh_id = ?").get(meshId);
|
|
48543
48313
|
if (count.count > 0) return;
|
|
48544
48314
|
const path54 = legacyQueuePath(meshId);
|
|
48545
|
-
if (!(0,
|
|
48315
|
+
if (!(0, import_fs6.existsSync)(path54)) return;
|
|
48546
48316
|
try {
|
|
48547
|
-
const entries = JSON.parse((0,
|
|
48317
|
+
const entries = JSON.parse((0, import_fs6.readFileSync)(path54, "utf-8"));
|
|
48548
48318
|
if (!Array.isArray(entries)) return;
|
|
48549
48319
|
const insert = this.db.prepare(`
|
|
48550
48320
|
INSERT OR REPLACE INTO mesh_queue (
|
|
@@ -50558,7 +50328,7 @@ Next step: ${nextStep}`;
|
|
|
50558
50328
|
compactLedger: () => compactLedger,
|
|
50559
50329
|
enforceAllLedgerRotationCaps: () => enforceAllLedgerRotationCaps,
|
|
50560
50330
|
enforceLedgerRotationCap: () => enforceLedgerRotationCap,
|
|
50561
|
-
getLedgerDir: () =>
|
|
50331
|
+
getLedgerDir: () => getLedgerDir2,
|
|
50562
50332
|
getLedgerSummary: () => getLedgerSummary,
|
|
50563
50333
|
getSessionRecoveryContext: () => getSessionRecoveryContext,
|
|
50564
50334
|
isIntentionalCleanupStopEntry: () => isIntentionalCleanupStopEntry,
|
|
@@ -50599,42 +50369,42 @@ Next step: ${nextStep}`;
|
|
|
50599
50369
|
if (Number.isNaN(created)) return false;
|
|
50600
50370
|
return now - created >= ttlDays * MS_PER_DAY;
|
|
50601
50371
|
}
|
|
50602
|
-
function
|
|
50603
|
-
const dir = (0,
|
|
50604
|
-
if (!(0,
|
|
50605
|
-
(0,
|
|
50372
|
+
function getLedgerDir2() {
|
|
50373
|
+
const dir = (0, import_path7.join)(getConfigDir2(), LEDGER_DIR_NAME);
|
|
50374
|
+
if (!(0, import_fs7.existsSync)(dir)) {
|
|
50375
|
+
(0, import_fs7.mkdirSync)(dir, { recursive: true, mode: 448 });
|
|
50606
50376
|
}
|
|
50607
50377
|
return dir;
|
|
50608
50378
|
}
|
|
50609
50379
|
function getLedgerPath(meshId) {
|
|
50610
50380
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
50611
|
-
return (0,
|
|
50381
|
+
return (0, import_path7.join)(getLedgerDir2(), `${safe}.jsonl`);
|
|
50612
50382
|
}
|
|
50613
50383
|
function getRotatedPath(meshId, index) {
|
|
50614
50384
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
50615
|
-
return (0,
|
|
50385
|
+
return (0, import_path7.join)(getLedgerDir2(), `${safe}.${index}.jsonl`);
|
|
50616
50386
|
}
|
|
50617
50387
|
function getArchivePath(meshId) {
|
|
50618
50388
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
50619
|
-
return (0,
|
|
50389
|
+
return (0, import_path7.join)(getLedgerDir2(), `${safe}.archive.jsonl`);
|
|
50620
50390
|
}
|
|
50621
50391
|
function getRotatedArchivePath(meshId, index) {
|
|
50622
50392
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
50623
|
-
return (0,
|
|
50393
|
+
return (0, import_path7.join)(getLedgerDir2(), `${safe}.archive.${index}.jsonl`);
|
|
50624
50394
|
}
|
|
50625
50395
|
function getArchivedCountsPath(meshId) {
|
|
50626
50396
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
50627
|
-
return (0,
|
|
50397
|
+
return (0, import_path7.join)(getLedgerDir2(), `${safe}.archived-counts.json`);
|
|
50628
50398
|
}
|
|
50629
50399
|
function rotateArchiveFile(meshId, archivePath) {
|
|
50630
50400
|
let index = 1;
|
|
50631
|
-
while ((0,
|
|
50401
|
+
while ((0, import_fs7.existsSync)(getRotatedArchivePath(meshId, index))) {
|
|
50632
50402
|
index++;
|
|
50633
50403
|
if (index > 5) break;
|
|
50634
50404
|
}
|
|
50635
50405
|
if (index > 5) index = 5;
|
|
50636
50406
|
try {
|
|
50637
|
-
(0,
|
|
50407
|
+
(0, import_fs7.renameSync)(archivePath, getRotatedArchivePath(meshId, index));
|
|
50638
50408
|
} catch (e) {
|
|
50639
50409
|
process.stderr.write(`[adhdev-mesh] Archive rotation failed for mesh ${meshId}: ${e?.message || e}
|
|
50640
50410
|
`);
|
|
@@ -50642,15 +50412,15 @@ Next step: ${nextStep}`;
|
|
|
50642
50412
|
}
|
|
50643
50413
|
function readArchivedCounts(meshId) {
|
|
50644
50414
|
const path54 = getArchivedCountsPath(meshId);
|
|
50645
|
-
if (!(0,
|
|
50415
|
+
if (!(0, import_fs7.existsSync)(path54)) return { taskCompleted: 0, taskFailed: 0, taskStalled: 0, recoveryAttempted: 0, totalArchived: 0, lastArchivedAt: "" };
|
|
50646
50416
|
try {
|
|
50647
|
-
return JSON.parse((0,
|
|
50417
|
+
return JSON.parse((0, import_fs7.readFileSync)(path54, "utf-8"));
|
|
50648
50418
|
} catch {
|
|
50649
50419
|
return { taskCompleted: 0, taskFailed: 0, taskStalled: 0, recoveryAttempted: 0, totalArchived: 0, lastArchivedAt: "" };
|
|
50650
50420
|
}
|
|
50651
50421
|
}
|
|
50652
50422
|
function writeArchivedCounts(meshId, counts) {
|
|
50653
|
-
(0,
|
|
50423
|
+
(0, import_fs7.writeFileSync)(getArchivedCountsPath(meshId), JSON.stringify(counts), { encoding: "utf-8", mode: 384 });
|
|
50654
50424
|
}
|
|
50655
50425
|
function updateArchivedCounts(meshId, archived) {
|
|
50656
50426
|
const counts = readArchivedCounts(meshId);
|
|
@@ -50686,7 +50456,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
50686
50456
|
}
|
|
50687
50457
|
function compactLedger(meshId) {
|
|
50688
50458
|
const filePath = getLedgerPath(meshId);
|
|
50689
|
-
if (!(0,
|
|
50459
|
+
if (!(0, import_fs7.existsSync)(filePath)) return { archivedCount: 0, retainedCount: 0 };
|
|
50690
50460
|
const cutoff = Date.now() - ARCHIVE_TERMINAL_OLDER_THAN_MS;
|
|
50691
50461
|
const entries = readLedgerEntries(meshId);
|
|
50692
50462
|
const keep = [];
|
|
@@ -50701,11 +50471,11 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
50701
50471
|
if (archive.length === 0) return { archivedCount: 0, retainedCount: keep.length };
|
|
50702
50472
|
const archivePath = getArchivePath(meshId);
|
|
50703
50473
|
try {
|
|
50704
|
-
if ((0,
|
|
50474
|
+
if ((0, import_fs7.existsSync)(archivePath) && (0, import_fs7.statSync)(archivePath).size > 50 * 1024 * 1024) {
|
|
50705
50475
|
rotateArchiveFile(meshId, archivePath);
|
|
50706
50476
|
}
|
|
50707
50477
|
const archiveLines = archive.map((e) => JSON.stringify(e)).join("\n") + "\n";
|
|
50708
|
-
(0,
|
|
50478
|
+
(0, import_fs7.appendFileSync)(archivePath, archiveLines, { encoding: "utf-8", mode: 384 });
|
|
50709
50479
|
updateArchivedCounts(meshId, archive);
|
|
50710
50480
|
} catch (e) {
|
|
50711
50481
|
process.stderr.write(`[adhdev-mesh] Ledger archive write failed for mesh ${meshId}: ${e?.message || e}
|
|
@@ -50714,7 +50484,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
50714
50484
|
}
|
|
50715
50485
|
try {
|
|
50716
50486
|
const keepLines = keep.length ? keep.map((e) => JSON.stringify(e)).join("\n") + "\n" : "";
|
|
50717
|
-
(0,
|
|
50487
|
+
(0, import_fs7.writeFileSync)(filePath, keepLines, { encoding: "utf-8", mode: 384 });
|
|
50718
50488
|
invalidateLedgerCache(meshId);
|
|
50719
50489
|
} catch (e) {
|
|
50720
50490
|
process.stderr.write(`[adhdev-mesh] Ledger compaction rewrite failed for mesh ${meshId}: ${e?.message || e}
|
|
@@ -50896,9 +50666,9 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
50896
50666
|
if (derived) entry.taskId = derived;
|
|
50897
50667
|
}
|
|
50898
50668
|
const filePath = getLedgerPath(meshId);
|
|
50899
|
-
if ((0,
|
|
50669
|
+
if ((0, import_fs7.existsSync)(filePath)) {
|
|
50900
50670
|
try {
|
|
50901
|
-
const stat2 = (0,
|
|
50671
|
+
const stat2 = (0, import_fs7.statSync)(filePath);
|
|
50902
50672
|
if (stat2.size >= MAX_FILE_SIZE_BYTES) {
|
|
50903
50673
|
rotateLedgerFile(meshId, filePath);
|
|
50904
50674
|
} else if (stat2.size >= COMPACT_THRESHOLD_BYTES) {
|
|
@@ -50924,7 +50694,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
50924
50694
|
}
|
|
50925
50695
|
try {
|
|
50926
50696
|
const line = JSON.stringify(entry) + "\n";
|
|
50927
|
-
(0,
|
|
50697
|
+
(0, import_fs7.appendFileSync)(filePath, line, { encoding: "utf-8", mode: 384 });
|
|
50928
50698
|
invalidateLedgerCache(meshId);
|
|
50929
50699
|
meshLedgerEvents.emit("append", meshId, entry);
|
|
50930
50700
|
if (entry.kind === OPERATING_NOTE_KIND || entry.kind === OPERATING_NOTE_TOMBSTONE_KIND) {
|
|
@@ -51016,7 +50786,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
51016
50786
|
const remaining = readLedgerFile(meshId).filter((e) => !removeIds.includes(e.id));
|
|
51017
50787
|
const filePath = getLedgerPath(meshId);
|
|
51018
50788
|
const lines = remaining.length ? remaining.map((e) => JSON.stringify(e)).join("\n") + "\n" : "";
|
|
51019
|
-
(0,
|
|
50789
|
+
(0, import_fs7.writeFileSync)(filePath, lines, { encoding: "utf-8", mode: 384 });
|
|
51020
50790
|
} catch {
|
|
51021
50791
|
}
|
|
51022
50792
|
invalidateLedgerCache(meshId);
|
|
@@ -51073,7 +50843,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
51073
50843
|
}
|
|
51074
50844
|
try {
|
|
51075
50845
|
const lines = validEntries.map((e) => JSON.stringify(e)).join("\n") + "\n";
|
|
51076
|
-
(0,
|
|
50846
|
+
(0, import_fs7.appendFileSync)(ledgerPath, lines, { encoding: "utf-8", mode: 384 });
|
|
51077
50847
|
invalidateLedgerCache(meshId);
|
|
51078
50848
|
for (const entry of validEntries) {
|
|
51079
50849
|
meshLedgerEvents.emit("append", meshId, entry);
|
|
@@ -51085,10 +50855,10 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
51085
50855
|
}
|
|
51086
50856
|
function readLedgerFile(meshId) {
|
|
51087
50857
|
const filePath = getLedgerPath(meshId);
|
|
51088
|
-
if (!(0,
|
|
50858
|
+
if (!(0, import_fs7.existsSync)(filePath)) return [];
|
|
51089
50859
|
let content;
|
|
51090
50860
|
try {
|
|
51091
|
-
content = (0,
|
|
50861
|
+
content = (0, import_fs7.readFileSync)(filePath, "utf-8");
|
|
51092
50862
|
} catch {
|
|
51093
50863
|
return [];
|
|
51094
50864
|
}
|
|
@@ -51365,13 +51135,13 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
51365
51135
|
}
|
|
51366
51136
|
function rotateLedgerFile(meshId, currentPath) {
|
|
51367
51137
|
let index = 1;
|
|
51368
|
-
while ((0,
|
|
51138
|
+
while ((0, import_fs7.existsSync)(getRotatedPath(meshId, index))) {
|
|
51369
51139
|
index++;
|
|
51370
51140
|
if (index > 10) break;
|
|
51371
51141
|
}
|
|
51372
51142
|
if (index > 10) index = 10;
|
|
51373
51143
|
try {
|
|
51374
|
-
(0,
|
|
51144
|
+
(0, import_fs7.renameSync)(currentPath, getRotatedPath(meshId, index));
|
|
51375
51145
|
} catch (e) {
|
|
51376
51146
|
process.stderr.write(`[adhdev-mesh] Ledger rotation failed for mesh ${meshId}: ${e?.message || e}. File will continue to grow.
|
|
51377
51147
|
`);
|
|
@@ -51407,7 +51177,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
51407
51177
|
function readRotationEntriesTolerant(filePath) {
|
|
51408
51178
|
let text;
|
|
51409
51179
|
try {
|
|
51410
|
-
text = (0,
|
|
51180
|
+
text = (0, import_fs7.readFileSync)(filePath, "utf-8");
|
|
51411
51181
|
} catch {
|
|
51412
51182
|
return [];
|
|
51413
51183
|
}
|
|
@@ -51426,14 +51196,14 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
51426
51196
|
return out;
|
|
51427
51197
|
}
|
|
51428
51198
|
function evictClosedRotationFile(safe, dir, entry) {
|
|
51429
|
-
const filePath = (0,
|
|
51199
|
+
const filePath = (0, import_path7.join)(dir, entry.name);
|
|
51430
51200
|
const counts = readArchivedCounts(safe);
|
|
51431
51201
|
const alreadyFolded = new Set(counts.evictedRotations ?? []);
|
|
51432
51202
|
if (alreadyFolded.has(entry.name)) {
|
|
51433
|
-
if ((0,
|
|
51203
|
+
if ((0, import_fs7.existsSync)(filePath)) (0, import_fs7.unlinkSync)(filePath);
|
|
51434
51204
|
return;
|
|
51435
51205
|
}
|
|
51436
|
-
if (closedRotationKind(safe, entry.name) === "active" && (0,
|
|
51206
|
+
if (closedRotationKind(safe, entry.name) === "active" && (0, import_fs7.existsSync)(filePath)) {
|
|
51437
51207
|
const entries = readRotationEntriesTolerant(filePath);
|
|
51438
51208
|
for (const e of entries) {
|
|
51439
51209
|
if (e.kind === "task_completed") counts.taskCompleted++;
|
|
@@ -51446,25 +51216,25 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
51446
51216
|
counts.evictedRotations = [...alreadyFolded, entry.name];
|
|
51447
51217
|
counts.lastArchivedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
51448
51218
|
writeArchivedCounts(safe, counts);
|
|
51449
|
-
if ((0,
|
|
51219
|
+
if ((0, import_fs7.existsSync)(filePath)) (0, import_fs7.unlinkSync)(filePath);
|
|
51450
51220
|
}
|
|
51451
51221
|
function enforceLedgerRotationCap(meshId, opts) {
|
|
51452
51222
|
const maxFiles = opts?.maxFiles ?? resolveLedgerRotationMaxFiles();
|
|
51453
51223
|
const maxBytes = opts?.maxBytes ?? resolveLedgerRotationMaxBytes();
|
|
51454
51224
|
const dryRun = opts?.dryRun === true;
|
|
51455
51225
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
51456
|
-
const dir =
|
|
51226
|
+
const dir = getLedgerDir2();
|
|
51457
51227
|
const stats = [];
|
|
51458
51228
|
let names = [];
|
|
51459
51229
|
try {
|
|
51460
|
-
names = (0,
|
|
51230
|
+
names = (0, import_fs7.readdirSync)(dir);
|
|
51461
51231
|
} catch {
|
|
51462
51232
|
names = [];
|
|
51463
51233
|
}
|
|
51464
51234
|
for (const name of names) {
|
|
51465
51235
|
if (!closedRotationKind(safe, name)) continue;
|
|
51466
51236
|
try {
|
|
51467
|
-
const st = (0,
|
|
51237
|
+
const st = (0, import_fs7.statSync)((0, import_path7.join)(dir, name));
|
|
51468
51238
|
if (st.isFile()) stats.push({ name, sizeBytes: st.size, mtimeMs: st.mtimeMs });
|
|
51469
51239
|
} catch {
|
|
51470
51240
|
}
|
|
@@ -51494,10 +51264,10 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
51494
51264
|
evictedBytes: 0,
|
|
51495
51265
|
byReason: { rotation_cap_count: 0, rotation_cap_bytes: 0 }
|
|
51496
51266
|
};
|
|
51497
|
-
const dir =
|
|
51267
|
+
const dir = getLedgerDir2();
|
|
51498
51268
|
let names = [];
|
|
51499
51269
|
try {
|
|
51500
|
-
names = (0,
|
|
51270
|
+
names = (0, import_fs7.readdirSync)(dir);
|
|
51501
51271
|
} catch {
|
|
51502
51272
|
return result;
|
|
51503
51273
|
}
|
|
@@ -51523,8 +51293,8 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
51523
51293
|
}
|
|
51524
51294
|
return result;
|
|
51525
51295
|
}
|
|
51526
|
-
var
|
|
51527
|
-
var
|
|
51296
|
+
var import_fs7;
|
|
51297
|
+
var import_path7;
|
|
51528
51298
|
var import_crypto9;
|
|
51529
51299
|
var import_events;
|
|
51530
51300
|
var TASK_LIFECYCLE_LEDGER_KINDS;
|
|
@@ -51550,8 +51320,8 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
51550
51320
|
var init_mesh_ledger = __esm2({
|
|
51551
51321
|
"src/mesh/mesh-ledger.ts"() {
|
|
51552
51322
|
"use strict";
|
|
51553
|
-
|
|
51554
|
-
|
|
51323
|
+
import_fs7 = require("fs");
|
|
51324
|
+
import_path7 = require("path");
|
|
51555
51325
|
import_crypto9 = require("crypto");
|
|
51556
51326
|
init_config();
|
|
51557
51327
|
init_mesh_retention_config();
|
|
@@ -52705,10 +52475,10 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
52705
52475
|
return { config: inline, source: "mesh.policy.refineConfig", sourceType: "mesh_policy" };
|
|
52706
52476
|
}
|
|
52707
52477
|
for (const relative8 of MESH_REFINE_CONFIG_LOCATIONS) {
|
|
52708
|
-
const configPath = (0,
|
|
52709
|
-
if (!(0,
|
|
52478
|
+
const configPath = (0, import_path8.join)(workspace, relative8);
|
|
52479
|
+
if (!(0, import_fs8.existsSync)(configPath)) continue;
|
|
52710
52480
|
try {
|
|
52711
|
-
const parsed = parseConfigText3(configPath, (0,
|
|
52481
|
+
const parsed = parseConfigText3(configPath, (0, import_fs8.readFileSync)(configPath, "utf-8"));
|
|
52712
52482
|
const validation = validateMeshRefineConfig(parsed, relative8);
|
|
52713
52483
|
if (!validation.valid) return { source: relative8, sourceType: "invalid", path: configPath, error: String(validation.rejectedCommands[0]?.reason || validation.errors.join("; ")) };
|
|
52714
52484
|
return { config: parsed, source: relative8, sourceType: "repo_file", path: configPath };
|
|
@@ -52724,7 +52494,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
52724
52494
|
}
|
|
52725
52495
|
function readPackageScripts(workspace) {
|
|
52726
52496
|
try {
|
|
52727
|
-
const parsed = JSON.parse((0,
|
|
52497
|
+
const parsed = JSON.parse((0, import_fs8.readFileSync)((0, import_path8.join)(workspace, "package.json"), "utf-8"));
|
|
52728
52498
|
return isRecord3(parsed?.scripts) ? parsed.scripts : {};
|
|
52729
52499
|
} catch {
|
|
52730
52500
|
return {};
|
|
@@ -52799,8 +52569,8 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
52799
52569
|
unavailableReason: validation.commands.length ? void 0 : "validation_unavailable: repo mesh/refine config has no validation.commands"
|
|
52800
52570
|
};
|
|
52801
52571
|
}
|
|
52802
|
-
var
|
|
52803
|
-
var
|
|
52572
|
+
var import_fs8;
|
|
52573
|
+
var import_path8;
|
|
52804
52574
|
var yaml3;
|
|
52805
52575
|
var MESH_REFINE_VALIDATION_CATEGORIES;
|
|
52806
52576
|
var MESH_REFINE_VALIDATION_SCOPES;
|
|
@@ -52813,8 +52583,8 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
52813
52583
|
var init_refine_config = __esm2({
|
|
52814
52584
|
"src/mesh/refine-config.ts"() {
|
|
52815
52585
|
"use strict";
|
|
52816
|
-
|
|
52817
|
-
|
|
52586
|
+
import_fs8 = require("fs");
|
|
52587
|
+
import_path8 = require("path");
|
|
52818
52588
|
yaml3 = __toESM2(require_js_yaml());
|
|
52819
52589
|
MESH_REFINE_VALIDATION_CATEGORIES = ["typecheck", "test", "lint", "build"];
|
|
52820
52590
|
MESH_REFINE_VALIDATION_SCOPES = ["none", "web", "daemon"];
|
|
@@ -52921,7 +52691,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
52921
52691
|
if (!dir) continue;
|
|
52922
52692
|
for (const ext of WIN_EXEC_EXT) {
|
|
52923
52693
|
const full = path17.join(dir, trimmed + ext);
|
|
52924
|
-
if ((0,
|
|
52694
|
+
if ((0, import_fs9.existsSync)(full)) return full;
|
|
52925
52695
|
}
|
|
52926
52696
|
}
|
|
52927
52697
|
return null;
|
|
@@ -52938,7 +52708,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
52938
52708
|
if (process.platform !== "win32") return command;
|
|
52939
52709
|
const trimmed = (command || "").trim();
|
|
52940
52710
|
if (!trimmed) return command;
|
|
52941
|
-
if (path17.isAbsolute(trimmed) && (0,
|
|
52711
|
+
if (path17.isAbsolute(trimmed) && (0, import_fs9.existsSync)(trimmed)) return trimmed;
|
|
52942
52712
|
try {
|
|
52943
52713
|
const out = (0, import_child_process3.execFileSync)("where", [trimmed], {
|
|
52944
52714
|
encoding: "utf8",
|
|
@@ -52987,7 +52757,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
52987
52757
|
};
|
|
52988
52758
|
}
|
|
52989
52759
|
var import_child_process3;
|
|
52990
|
-
var
|
|
52760
|
+
var import_fs9;
|
|
52991
52761
|
var path17;
|
|
52992
52762
|
var DIRECT_EXEC_EXT;
|
|
52993
52763
|
var SHIM_EXEC_EXT;
|
|
@@ -52996,7 +52766,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
52996
52766
|
"src/cli-adapters/resolve-executable.ts"() {
|
|
52997
52767
|
"use strict";
|
|
52998
52768
|
import_child_process3 = require("child_process");
|
|
52999
|
-
|
|
52769
|
+
import_fs9 = require("fs");
|
|
53000
52770
|
path17 = __toESM2(require("path"));
|
|
53001
52771
|
DIRECT_EXEC_EXT = /* @__PURE__ */ new Set([".exe", ".com"]);
|
|
53002
52772
|
SHIM_EXEC_EXT = /* @__PURE__ */ new Set([".cmd", ".bat"]);
|
|
@@ -53134,7 +52904,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
53134
52904
|
if (!Number.isFinite(startedMs)) return false;
|
|
53135
52905
|
if (nowMs - startedMs <= WORKTREE_BOOTSTRAP_STALE_RUNNING_MS) return false;
|
|
53136
52906
|
const workspace = typeof node?.workspace === "string" ? node.workspace.trim() : "";
|
|
53137
|
-
if (!workspace || !(0,
|
|
52907
|
+
if (!workspace || !(0, import_fs10.existsSync)(workspace)) return false;
|
|
53138
52908
|
try {
|
|
53139
52909
|
const out = (0, import_node_child_process4.execFileSync)(resolveWin32Executable("git"), ["status", "--porcelain"], {
|
|
53140
52910
|
cwd: workspace,
|
|
@@ -53197,10 +52967,10 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
53197
52967
|
return { config: inline, source: "mesh.policy.worktreeBootstrapConfig", sourceType: "mesh_policy" };
|
|
53198
52968
|
}
|
|
53199
52969
|
for (const relative8 of MESH_WORKTREE_BOOTSTRAP_CONFIG_LOCATIONS) {
|
|
53200
|
-
const configPath = (0,
|
|
53201
|
-
if (!(0,
|
|
52970
|
+
const configPath = (0, import_path9.join)(workspace, relative8);
|
|
52971
|
+
if (!(0, import_fs10.existsSync)(configPath)) continue;
|
|
53202
52972
|
try {
|
|
53203
|
-
const parsed = parseConfigText4(configPath, (0,
|
|
52973
|
+
const parsed = parseConfigText4(configPath, (0, import_fs10.readFileSync)(configPath, "utf-8"));
|
|
53204
52974
|
const validation = validateMeshWorktreeBootstrapConfig(parsed, relative8);
|
|
53205
52975
|
if (!validation.valid) return { source: relative8, sourceType: "invalid", path: configPath, error: String(validation.rejectedCommands[0]?.reason || validation.errors.join("; ")) };
|
|
53206
52976
|
return { config: parsed, source: relative8, sourceType: "repo_file", path: configPath };
|
|
@@ -53213,9 +52983,9 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
53213
52983
|
function computeStaleInputsDigest(workspace, staleInputs) {
|
|
53214
52984
|
const digest = {};
|
|
53215
52985
|
for (const relative8 of staleInputs ?? []) {
|
|
53216
|
-
const filePath = (0,
|
|
52986
|
+
const filePath = (0, import_path9.join)(workspace, relative8);
|
|
53217
52987
|
try {
|
|
53218
|
-
digest[relative8] = (0, import_node_crypto2.createHash)("sha256").update((0,
|
|
52988
|
+
digest[relative8] = (0, import_node_crypto2.createHash)("sha256").update((0, import_fs10.readFileSync)(filePath)).digest("hex");
|
|
53219
52989
|
} catch {
|
|
53220
52990
|
digest[relative8] = "absent";
|
|
53221
52991
|
}
|
|
@@ -53286,10 +53056,10 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
53286
53056
|
staleInputs: loaded.config.staleInputs
|
|
53287
53057
|
};
|
|
53288
53058
|
const staleInputPaths = loaded.config.staleInputs ?? [];
|
|
53289
|
-
const initiallyAbsent = staleInputPaths.filter((p) => !(0,
|
|
53059
|
+
const initiallyAbsent = staleInputPaths.filter((p) => !(0, import_fs10.existsSync)((0, import_path9.join)(workspace, p)));
|
|
53290
53060
|
for (const command of validation.commands) {
|
|
53291
53061
|
if (initiallyAbsent.length > 0) {
|
|
53292
|
-
const appearedNow = initiallyAbsent.filter((p) => (0,
|
|
53062
|
+
const appearedNow = initiallyAbsent.filter((p) => (0, import_fs10.existsSync)((0, import_path9.join)(workspace, p)));
|
|
53293
53063
|
if (appearedNow.length > 0) {
|
|
53294
53064
|
state.status = "stale";
|
|
53295
53065
|
state.completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -53297,7 +53067,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
53297
53067
|
return state;
|
|
53298
53068
|
}
|
|
53299
53069
|
}
|
|
53300
|
-
const cwd = command.cwd ? (0,
|
|
53070
|
+
const cwd = command.cwd ? (0, import_path9.resolve)(workspace, command.cwd) : workspace;
|
|
53301
53071
|
const startedAt = Date.now();
|
|
53302
53072
|
state.lastCommand = command.displayCommand;
|
|
53303
53073
|
const resolvedCommand = resolveWin32Executable(command.command);
|
|
@@ -53357,8 +53127,8 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
53357
53127
|
}
|
|
53358
53128
|
return state;
|
|
53359
53129
|
}
|
|
53360
|
-
var
|
|
53361
|
-
var
|
|
53130
|
+
var import_fs10;
|
|
53131
|
+
var import_path9;
|
|
53362
53132
|
var import_node_child_process4;
|
|
53363
53133
|
var import_node_crypto2;
|
|
53364
53134
|
var import_node_util3;
|
|
@@ -53373,8 +53143,8 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
53373
53143
|
var init_worktree_bootstrap_config = __esm2({
|
|
53374
53144
|
"src/mesh/worktree-bootstrap-config.ts"() {
|
|
53375
53145
|
"use strict";
|
|
53376
|
-
|
|
53377
|
-
|
|
53146
|
+
import_fs10 = require("fs");
|
|
53147
|
+
import_path9 = require("path");
|
|
53378
53148
|
import_node_child_process4 = require("child_process");
|
|
53379
53149
|
import_node_crypto2 = require("crypto");
|
|
53380
53150
|
import_node_util3 = require("util");
|
|
@@ -53839,13 +53609,13 @@ ${rendered}`, "utf-8");
|
|
|
53839
53609
|
}
|
|
53840
53610
|
});
|
|
53841
53611
|
function getRegistryPath() {
|
|
53842
|
-
return (0,
|
|
53612
|
+
return (0, import_path11.join)(getDaemonDataDir(), "mesh-coordinators.json");
|
|
53843
53613
|
}
|
|
53844
53614
|
function loadMeshCoordinatorRegistry() {
|
|
53845
53615
|
const path54 = getRegistryPath();
|
|
53846
|
-
if (!(0,
|
|
53616
|
+
if (!(0, import_fs12.existsSync)(path54)) return;
|
|
53847
53617
|
try {
|
|
53848
|
-
const raw = JSON.parse((0,
|
|
53618
|
+
const raw = JSON.parse((0, import_fs12.readFileSync)(path54, "utf-8"));
|
|
53849
53619
|
if (!Array.isArray(raw)) return;
|
|
53850
53620
|
_registry.clear();
|
|
53851
53621
|
for (const entry of raw) {
|
|
@@ -53858,7 +53628,7 @@ ${rendered}`, "utf-8");
|
|
|
53858
53628
|
}
|
|
53859
53629
|
function saveRegistry() {
|
|
53860
53630
|
try {
|
|
53861
|
-
(0,
|
|
53631
|
+
(0, import_fs12.writeFileSync)(
|
|
53862
53632
|
getRegistryPath(),
|
|
53863
53633
|
JSON.stringify([..._registry.values()], null, 2),
|
|
53864
53634
|
{ encoding: "utf-8", mode: 384 }
|
|
@@ -53891,14 +53661,14 @@ ${rendered}`, "utf-8");
|
|
|
53891
53661
|
function listCoordinatorsForWorkspace(workspace) {
|
|
53892
53662
|
return [..._registry.values()].filter((e) => e.workspace === workspace);
|
|
53893
53663
|
}
|
|
53894
|
-
var
|
|
53895
|
-
var
|
|
53664
|
+
var import_path11;
|
|
53665
|
+
var import_fs12;
|
|
53896
53666
|
var _registry;
|
|
53897
53667
|
var init_coordinator_registry = __esm2({
|
|
53898
53668
|
"src/mesh/coordinator-registry.ts"() {
|
|
53899
53669
|
"use strict";
|
|
53900
|
-
|
|
53901
|
-
|
|
53670
|
+
import_path11 = require("path");
|
|
53671
|
+
import_fs12 = require("fs");
|
|
53902
53672
|
init_config();
|
|
53903
53673
|
_registry = /* @__PURE__ */ new Map();
|
|
53904
53674
|
}
|
|
@@ -62048,7 +61818,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
|
|
|
62048
61818
|
if (now - lastAttempt < IDLE_AUTO_FAST_FORWARD_THROTTLE_MS) return;
|
|
62049
61819
|
idleAutoFastForwardLastAttempt.set(throttleKey, now);
|
|
62050
61820
|
if (isLocalAutoLaunchNode(node)) {
|
|
62051
|
-
if (!(0,
|
|
61821
|
+
if (!(0, import_fs14.existsSync)(workspace)) return;
|
|
62052
61822
|
await executeLocalAutoFastForward({ meshId: args.meshId, nodeId: args.nodeId, node, workspace, policy, trigger: "idle_auto" });
|
|
62053
61823
|
return;
|
|
62054
61824
|
}
|
|
@@ -62145,7 +61915,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
|
|
|
62145
61915
|
});
|
|
62146
61916
|
});
|
|
62147
61917
|
}
|
|
62148
|
-
var
|
|
61918
|
+
var import_fs14;
|
|
62149
61919
|
var IDLE_AUTO_FAST_FORWARD_THROTTLE_MS;
|
|
62150
61920
|
var idleAutoFastForwardLastAttempt;
|
|
62151
61921
|
var CONTINUOUS_AUTO_FAST_FORWARD_SCAN_COOLDOWN_MS;
|
|
@@ -62174,7 +61944,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
|
|
|
62174
61944
|
var init_mesh_queue_assignment = __esm2({
|
|
62175
61945
|
"src/mesh/mesh-queue-assignment.ts"() {
|
|
62176
61946
|
"use strict";
|
|
62177
|
-
|
|
61947
|
+
import_fs14 = require("fs");
|
|
62178
61948
|
init_runtime_defaults();
|
|
62179
61949
|
init_config();
|
|
62180
61950
|
init_mesh_config();
|
|
@@ -62522,7 +62292,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
|
|
|
62522
62292
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
62523
62293
|
}
|
|
62524
62294
|
function getStatePath() {
|
|
62525
|
-
return (0,
|
|
62295
|
+
return (0, import_path13.join)(getConfigDir2(), "state.json");
|
|
62526
62296
|
}
|
|
62527
62297
|
function normalizeState(raw) {
|
|
62528
62298
|
const parsed = isPlainObject22(raw) ? raw : {};
|
|
@@ -62573,11 +62343,11 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
|
|
|
62573
62343
|
}
|
|
62574
62344
|
function loadState() {
|
|
62575
62345
|
const statePath = getStatePath();
|
|
62576
|
-
if (!(0,
|
|
62346
|
+
if (!(0, import_fs15.existsSync)(statePath)) {
|
|
62577
62347
|
return { ...DEFAULT_STATE };
|
|
62578
62348
|
}
|
|
62579
62349
|
try {
|
|
62580
|
-
const raw = (0,
|
|
62350
|
+
const raw = (0, import_fs15.readFileSync)(statePath, "utf-8");
|
|
62581
62351
|
return normalizeState(JSON.parse(raw));
|
|
62582
62352
|
} catch {
|
|
62583
62353
|
return { ...DEFAULT_STATE };
|
|
@@ -62586,7 +62356,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
|
|
|
62586
62356
|
function saveState(state) {
|
|
62587
62357
|
const statePath = getStatePath();
|
|
62588
62358
|
const normalized = normalizeState(state);
|
|
62589
|
-
(0,
|
|
62359
|
+
(0, import_fs15.writeFileSync)(statePath, JSON.stringify(normalized, null, 2), { encoding: "utf-8", mode: 384 });
|
|
62590
62360
|
}
|
|
62591
62361
|
function resetState() {
|
|
62592
62362
|
saveState({ ...DEFAULT_STATE });
|
|
@@ -62626,14 +62396,14 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
|
|
|
62626
62396
|
delete next[key2];
|
|
62627
62397
|
saveState({ ...state, deferredRestartSchedules: next });
|
|
62628
62398
|
}
|
|
62629
|
-
var
|
|
62630
|
-
var
|
|
62399
|
+
var import_fs15;
|
|
62400
|
+
var import_path13;
|
|
62631
62401
|
var DEFAULT_STATE;
|
|
62632
62402
|
var init_state_store = __esm2({
|
|
62633
62403
|
"src/config/state-store.ts"() {
|
|
62634
62404
|
"use strict";
|
|
62635
|
-
|
|
62636
|
-
|
|
62405
|
+
import_fs15 = require("fs");
|
|
62406
|
+
import_path13 = require("path");
|
|
62637
62407
|
init_config();
|
|
62638
62408
|
DEFAULT_STATE = {
|
|
62639
62409
|
recentActivity: [],
|
|
@@ -65787,7 +65557,7 @@ ${cleanBody}`;
|
|
|
65787
65557
|
const targets = wantSession ? idleCoordinators.filter((c) => sessionIdsEquivalent(c.sessionId, wantSession)) : idleCoordinators;
|
|
65788
65558
|
if (targets.length === 0 || !pending.coordinatorMessage) {
|
|
65789
65559
|
try {
|
|
65790
|
-
|
|
65560
|
+
requeueDrainedPendingMeshCoordinatorEvent(pending);
|
|
65791
65561
|
} catch {
|
|
65792
65562
|
}
|
|
65793
65563
|
continue;
|
|
@@ -66384,7 +66154,7 @@ ${cleanBody}`;
|
|
|
66384
66154
|
}
|
|
66385
66155
|
function safeUnlink(path54) {
|
|
66386
66156
|
try {
|
|
66387
|
-
(0,
|
|
66157
|
+
(0, import_fs16.unlinkSync)(path54);
|
|
66388
66158
|
return true;
|
|
66389
66159
|
} catch (e) {
|
|
66390
66160
|
LOG2.warn("DiskRetention", `Failed to delete ${path54}: ${e?.message || e}`);
|
|
@@ -66392,18 +66162,18 @@ ${cleanBody}`;
|
|
|
66392
66162
|
}
|
|
66393
66163
|
}
|
|
66394
66164
|
function listDirFiles(dir) {
|
|
66395
|
-
if (!(0,
|
|
66165
|
+
if (!(0, import_fs16.existsSync)(dir)) return [];
|
|
66396
66166
|
const out = [];
|
|
66397
66167
|
let names;
|
|
66398
66168
|
try {
|
|
66399
|
-
names = (0,
|
|
66169
|
+
names = (0, import_fs16.readdirSync)(dir);
|
|
66400
66170
|
} catch {
|
|
66401
66171
|
return [];
|
|
66402
66172
|
}
|
|
66403
66173
|
for (const name of names) {
|
|
66404
|
-
const path54 = (0,
|
|
66174
|
+
const path54 = (0, import_path14.join)(dir, name);
|
|
66405
66175
|
try {
|
|
66406
|
-
const st = (0,
|
|
66176
|
+
const st = (0, import_fs16.statSync)(path54);
|
|
66407
66177
|
if (st.isFile()) out.push({ path: path54, mtimeMs: st.mtimeMs });
|
|
66408
66178
|
} catch {
|
|
66409
66179
|
}
|
|
@@ -66411,7 +66181,7 @@ ${cleanBody}`;
|
|
|
66411
66181
|
return out;
|
|
66412
66182
|
}
|
|
66413
66183
|
function pruneExpiredLedgerJsonl(now = Date.now()) {
|
|
66414
|
-
const dir =
|
|
66184
|
+
const dir = getLedgerDir2();
|
|
66415
66185
|
const jsonl = listDirFiles(dir).filter((f) => f.path.endsWith(".jsonl"));
|
|
66416
66186
|
const expired = selectExpiredLedgerJsonl(jsonl, now);
|
|
66417
66187
|
let deleted = 0;
|
|
@@ -66420,7 +66190,7 @@ ${cleanBody}`;
|
|
|
66420
66190
|
return deleted;
|
|
66421
66191
|
}
|
|
66422
66192
|
function pruneExpiredDbBackups(now = Date.now()) {
|
|
66423
|
-
const dir =
|
|
66193
|
+
const dir = getLedgerDir2();
|
|
66424
66194
|
const baks = listDirFiles(dir).filter((f) => isDbBackupFileName(f.path.split(/[/\\]/).pop() || ""));
|
|
66425
66195
|
const expired = selectExpiredDbBackups(baks, now);
|
|
66426
66196
|
let deleted = 0;
|
|
@@ -66429,23 +66199,23 @@ ${cleanBody}`;
|
|
|
66429
66199
|
return deleted;
|
|
66430
66200
|
}
|
|
66431
66201
|
function pruneExpiredSessionHostRuntimes(now = Date.now()) {
|
|
66432
|
-
const root = (0,
|
|
66433
|
-
if (!(0,
|
|
66202
|
+
const root = (0, import_path14.join)(getConfigDir2(), "session-host");
|
|
66203
|
+
if (!(0, import_fs16.existsSync)(root)) return 0;
|
|
66434
66204
|
let apps;
|
|
66435
66205
|
try {
|
|
66436
|
-
apps = (0,
|
|
66206
|
+
apps = (0, import_fs16.readdirSync)(root);
|
|
66437
66207
|
} catch {
|
|
66438
66208
|
return 0;
|
|
66439
66209
|
}
|
|
66440
66210
|
const candidates = [];
|
|
66441
66211
|
for (const app of apps) {
|
|
66442
|
-
const runtimesDir = (0,
|
|
66443
|
-
if (!(0,
|
|
66212
|
+
const runtimesDir = (0, import_path14.join)(root, app, "runtimes");
|
|
66213
|
+
if (!(0, import_fs16.existsSync)(runtimesDir)) continue;
|
|
66444
66214
|
for (const f of listDirFiles(runtimesDir)) {
|
|
66445
66215
|
if (!f.path.endsWith(".json")) continue;
|
|
66446
66216
|
let record2 = null;
|
|
66447
66217
|
try {
|
|
66448
|
-
const parsed = JSON.parse((0,
|
|
66218
|
+
const parsed = JSON.parse((0, import_fs16.readFileSync)(f.path, "utf-8"));
|
|
66449
66219
|
const rec = parsed && typeof parsed === "object" ? parsed.record : null;
|
|
66450
66220
|
record2 = rec && typeof rec === "object" ? rec : null;
|
|
66451
66221
|
} catch {
|
|
@@ -66542,8 +66312,8 @@ ${cleanBody}`;
|
|
|
66542
66312
|
}
|
|
66543
66313
|
return signalled;
|
|
66544
66314
|
}
|
|
66545
|
-
var
|
|
66546
|
-
var
|
|
66315
|
+
var import_fs16;
|
|
66316
|
+
var import_path14;
|
|
66547
66317
|
var DAY_MS2;
|
|
66548
66318
|
var LEDGER_JSONL_MAX_AGE_MS;
|
|
66549
66319
|
var SESSION_HOST_RUNTIME_MAX_AGE_MS;
|
|
@@ -66552,8 +66322,8 @@ ${cleanBody}`;
|
|
|
66552
66322
|
var init_mesh_disk_retention = __esm2({
|
|
66553
66323
|
"src/mesh/mesh-disk-retention.ts"() {
|
|
66554
66324
|
"use strict";
|
|
66555
|
-
|
|
66556
|
-
|
|
66325
|
+
import_fs16 = require("fs");
|
|
66326
|
+
import_path14 = require("path");
|
|
66557
66327
|
init_config();
|
|
66558
66328
|
init_mesh_ledger();
|
|
66559
66329
|
init_runtime_surface();
|
|
@@ -66567,7 +66337,7 @@ ${cleanBody}`;
|
|
|
66567
66337
|
}
|
|
66568
66338
|
});
|
|
66569
66339
|
function retentionStatePath() {
|
|
66570
|
-
return (0,
|
|
66340
|
+
return (0, import_path15.join)(getLedgerDir2(), "worktree-node-retention-state.json");
|
|
66571
66341
|
}
|
|
66572
66342
|
function stateKey(meshId, nodeId) {
|
|
66573
66343
|
return `${meshId}::${nodeId}`;
|
|
@@ -66632,7 +66402,7 @@ ${cleanBody}`;
|
|
|
66632
66402
|
return String(stdout || "");
|
|
66633
66403
|
}
|
|
66634
66404
|
function normalizePathForCompare(value) {
|
|
66635
|
-
const resolved = (0,
|
|
66405
|
+
const resolved = (0, import_path15.resolve)(value);
|
|
66636
66406
|
try {
|
|
66637
66407
|
return fs11.realpathSync(resolved);
|
|
66638
66408
|
} catch {
|
|
@@ -66685,7 +66455,7 @@ ${cleanBody}`;
|
|
|
66685
66455
|
if (workspace && ctx.processCwd) {
|
|
66686
66456
|
const normalizedWorkspace = normalizePathForCompare(workspace);
|
|
66687
66457
|
const normalizedCwd = normalizePathForCompare(ctx.processCwd);
|
|
66688
|
-
if (normalizedCwd === normalizedWorkspace || normalizedCwd.startsWith(normalizedWorkspace +
|
|
66458
|
+
if (normalizedCwd === normalizedWorkspace || normalizedCwd.startsWith(normalizedWorkspace + import_path15.sep)) {
|
|
66689
66459
|
return skip("process_cwd_reference", "Worktree path is (or contains) the current process working directory; an open-runtime/cwd reference blocks removal.");
|
|
66690
66460
|
}
|
|
66691
66461
|
}
|
|
@@ -67049,7 +66819,7 @@ ${cleanBody}`;
|
|
|
67049
66819
|
}
|
|
67050
66820
|
var fs11;
|
|
67051
66821
|
var import_os22;
|
|
67052
|
-
var
|
|
66822
|
+
var import_path15;
|
|
67053
66823
|
var LOG_CATEGORY;
|
|
67054
66824
|
var metrics2;
|
|
67055
66825
|
var init_mesh_worktree_retention = __esm2({
|
|
@@ -67057,7 +66827,7 @@ ${cleanBody}`;
|
|
|
67057
66827
|
"use strict";
|
|
67058
66828
|
fs11 = __toESM2(require("fs"));
|
|
67059
66829
|
import_os22 = require("os");
|
|
67060
|
-
|
|
66830
|
+
import_path15 = require("path");
|
|
67061
66831
|
init_dist();
|
|
67062
66832
|
init_logger();
|
|
67063
66833
|
init_config();
|
|
@@ -67746,6 +67516,75 @@ ${cleanBody}`;
|
|
|
67746
67516
|
}
|
|
67747
67517
|
return delivered;
|
|
67748
67518
|
}
|
|
67519
|
+
function holdOrExpireStrictUnmatchedEvent(pending, wantSession, meshId) {
|
|
67520
|
+
const queuedAt = typeof pending.queuedAt === "number" ? pending.queuedAt : Date.now();
|
|
67521
|
+
if (Date.now() - queuedAt <= STRICT_SESSION_MATCH_TTL_MS) {
|
|
67522
|
+
try {
|
|
67523
|
+
const requeued = requeueDrainedPendingMeshCoordinatorEvent(pending);
|
|
67524
|
+
LOG2.info("MeshReconcile", `Strict route hold: coordinator session ${wantSession} not live on mesh ${meshId} \u2014 re-queued (${pending.event})${requeued ? "" : " [WARN: not durably re-queued]"}`);
|
|
67525
|
+
traceMeshEventDrop("strict_route_hold", {
|
|
67526
|
+
taskId: pending.metadataEvent?.taskId,
|
|
67527
|
+
sessionId: pending.metadataEvent?.targetSessionId ?? wantSession,
|
|
67528
|
+
nodeId: pending.nodeId,
|
|
67529
|
+
meshId,
|
|
67530
|
+
event: pending.event
|
|
67531
|
+
}, `coordinatorSession=${wantSession} not live durable=${requeued}`);
|
|
67532
|
+
} catch (e) {
|
|
67533
|
+
LOG2.warn("MeshReconcile", `Strict route re-queue failed for ${pending.event} on mesh ${meshId}: ${e?.message || e}`);
|
|
67534
|
+
}
|
|
67535
|
+
return;
|
|
67536
|
+
}
|
|
67537
|
+
const finalSummary = readMeshCompletionSummary(pending.metadataEvent || {});
|
|
67538
|
+
try {
|
|
67539
|
+
appendLedgerEntry(meshId, {
|
|
67540
|
+
kind: "event_held",
|
|
67541
|
+
...pending.nodeId ? { nodeId: pending.nodeId } : {},
|
|
67542
|
+
payload: {
|
|
67543
|
+
event: pending.event,
|
|
67544
|
+
reason: "strict_route_expired",
|
|
67545
|
+
recoverable: true,
|
|
67546
|
+
targetCoordinatorSessionId: wantSession,
|
|
67547
|
+
targetCoordinatorDaemonId: pending.targetCoordinatorDaemonId ?? null,
|
|
67548
|
+
nodeLabel: pending.nodeLabel,
|
|
67549
|
+
...pending.workspace ? { workspace: pending.workspace } : {},
|
|
67550
|
+
queuedAt,
|
|
67551
|
+
...finalSummary ? { finalSummary } : {}
|
|
67552
|
+
}
|
|
67553
|
+
});
|
|
67554
|
+
LOG2.warn("MeshReconcile", `Strict route expire: coordinator session ${wantSession} never returned for mesh ${meshId} \u2014 recorded to ledger (recoverable), dropped (${pending.event})`);
|
|
67555
|
+
traceMeshEventDrop("strict_route_expired", {
|
|
67556
|
+
taskId: pending.metadataEvent?.taskId,
|
|
67557
|
+
sessionId: pending.metadataEvent?.targetSessionId ?? wantSession,
|
|
67558
|
+
nodeId: pending.nodeId,
|
|
67559
|
+
meshId,
|
|
67560
|
+
event: pending.event
|
|
67561
|
+
}, `coordinatorSession=${wantSession} never returned`);
|
|
67562
|
+
} catch (e) {
|
|
67563
|
+
LOG2.warn("MeshReconcile", `Failed to ledger-expire strict-unmatched ${pending.event} for mesh ${meshId}: ${e?.message || e}`);
|
|
67564
|
+
}
|
|
67565
|
+
}
|
|
67566
|
+
var coordinatorModalParkState;
|
|
67567
|
+
var DISK_RETENTION_INTERVAL_MS;
|
|
67568
|
+
var heldEventLedgerRecorded;
|
|
67569
|
+
var STRICT_SESSION_MATCH_TTL_MS;
|
|
67570
|
+
var init_mesh_reconcile_coordinator_drain = __esm2({
|
|
67571
|
+
"src/mesh/mesh-reconcile-coordinator-drain.ts"() {
|
|
67572
|
+
"use strict";
|
|
67573
|
+
init_config();
|
|
67574
|
+
init_logger();
|
|
67575
|
+
init_mesh_events_pending();
|
|
67576
|
+
init_mesh_ledger();
|
|
67577
|
+
init_mesh_events_coordinator();
|
|
67578
|
+
init_mesh_event_classify();
|
|
67579
|
+
init_mesh_events_utils();
|
|
67580
|
+
init_mesh_event_trace();
|
|
67581
|
+
init_dist();
|
|
67582
|
+
coordinatorModalParkState = /* @__PURE__ */ new Map();
|
|
67583
|
+
DISK_RETENTION_INTERVAL_MS = 60 * 60 * 1e3;
|
|
67584
|
+
heldEventLedgerRecorded = /* @__PURE__ */ new Set();
|
|
67585
|
+
STRICT_SESSION_MATCH_TTL_MS = 6e4;
|
|
67586
|
+
}
|
|
67587
|
+
});
|
|
67749
67588
|
function assignedRowLiveStatusIsAwaitingApproval(mesh, nodeId, sessionId) {
|
|
67750
67589
|
if (!nodeId || !sessionId) return false;
|
|
67751
67590
|
try {
|
|
@@ -68548,6 +68387,165 @@ ${cleanBody}`;
|
|
|
68548
68387
|
}, `${reason} stale=${Math.round((nowMs - anchorMs) / 6e4)}m`);
|
|
68549
68388
|
}
|
|
68550
68389
|
}
|
|
68390
|
+
var ASSIGNED_STRANDED_DEADLINE_MS;
|
|
68391
|
+
var DELIVERED_NO_TURN_DEADLINE_MS;
|
|
68392
|
+
var NATIVE_SOURCE_ACTIVITY_STALE_MS;
|
|
68393
|
+
var ASSIGNED_DELIVERED_UNCONSUMED_REDRIVE_MS;
|
|
68394
|
+
var RECLAIM_UNKNOWN_GRACE_TICKS;
|
|
68395
|
+
var QUEUE_HOLD_HARD_DEADLINE_MS;
|
|
68396
|
+
var queueHoldHardDeadlineAudited;
|
|
68397
|
+
var deliveredNoTurnUnknownStreak;
|
|
68398
|
+
var deliveredUnconsumedUnknownStreak;
|
|
68399
|
+
var ASSIGNED_IDLE_TRANSCRIPT_COMPLETE_MS;
|
|
68400
|
+
var assignedIdleFinalAssistantSince;
|
|
68401
|
+
var ZOMBIE_ASSIGNED_MIN_AGE_MS;
|
|
68402
|
+
var init_mesh_reconcile_stranded_dispatch = __esm2({
|
|
68403
|
+
"src/mesh/mesh-reconcile-stranded-dispatch.ts"() {
|
|
68404
|
+
"use strict";
|
|
68405
|
+
init_logger();
|
|
68406
|
+
init_mesh_ledger();
|
|
68407
|
+
init_mesh_runtime_store();
|
|
68408
|
+
init_mesh_events_utils();
|
|
68409
|
+
init_mesh_event_trace();
|
|
68410
|
+
init_dist();
|
|
68411
|
+
init_mesh_work_queue();
|
|
68412
|
+
init_mesh_queue_assignment();
|
|
68413
|
+
init_mesh_events_stale();
|
|
68414
|
+
init_mesh_reconcile_identity();
|
|
68415
|
+
init_mesh_remote_event_pull();
|
|
68416
|
+
init_transcript_evidence();
|
|
68417
|
+
init_mesh_completion_synthesis();
|
|
68418
|
+
init_mesh_active_work();
|
|
68419
|
+
init_mesh_event_forwarding();
|
|
68420
|
+
init_mesh_turn_ledger();
|
|
68421
|
+
init_mesh_turn_presentation();
|
|
68422
|
+
ASSIGNED_STRANDED_DEADLINE_MS = 5 * 6e4;
|
|
68423
|
+
DELIVERED_NO_TURN_DEADLINE_MS = 15 * 6e4;
|
|
68424
|
+
NATIVE_SOURCE_ACTIVITY_STALE_MS = 10 * 6e4;
|
|
68425
|
+
ASSIGNED_DELIVERED_UNCONSUMED_REDRIVE_MS = 25e3;
|
|
68426
|
+
RECLAIM_UNKNOWN_GRACE_TICKS = 3;
|
|
68427
|
+
QUEUE_HOLD_HARD_DEADLINE_MS = 90 * 6e4;
|
|
68428
|
+
queueHoldHardDeadlineAudited = /* @__PURE__ */ new Set();
|
|
68429
|
+
deliveredNoTurnUnknownStreak = /* @__PURE__ */ new Map();
|
|
68430
|
+
deliveredUnconsumedUnknownStreak = /* @__PURE__ */ new Map();
|
|
68431
|
+
ASSIGNED_IDLE_TRANSCRIPT_COMPLETE_MS = 8e3;
|
|
68432
|
+
assignedIdleFinalAssistantSince = /* @__PURE__ */ new Map();
|
|
68433
|
+
ZOMBIE_ASSIGNED_MIN_AGE_MS = 30 * 60 * 1e3;
|
|
68434
|
+
}
|
|
68435
|
+
});
|
|
68436
|
+
function scheduleUnresolvedForwardNudge(components) {
|
|
68437
|
+
if (!components.dispatchMeshCommand) return;
|
|
68438
|
+
if (unresolvedForwardNudgeTimer) return;
|
|
68439
|
+
unresolvedForwardNudgeTimer = setTimeout(() => {
|
|
68440
|
+
unresolvedForwardNudgeTimer = void 0;
|
|
68441
|
+
if (unresolvedForwardNudgeRunning) return;
|
|
68442
|
+
unresolvedForwardNudgeRunning = true;
|
|
68443
|
+
void retryUnresolvedDelegateForwards(components).catch((e) => LOG2.warn("MeshReconcile", `Nudged unresolved-forward retry failed: ${e?.message || e}`)).finally(() => {
|
|
68444
|
+
unresolvedForwardNudgeRunning = false;
|
|
68445
|
+
});
|
|
68446
|
+
}, UNRESOLVED_FORWARD_NUDGE_DELAY_MS);
|
|
68447
|
+
if (typeof unresolvedForwardNudgeTimer.unref === "function") unresolvedForwardNudgeTimer.unref();
|
|
68448
|
+
}
|
|
68449
|
+
function clearUnresolvedForwardNudge() {
|
|
68450
|
+
if (unresolvedForwardNudgeTimer) {
|
|
68451
|
+
clearTimeout(unresolvedForwardNudgeTimer);
|
|
68452
|
+
unresolvedForwardNudgeTimer = void 0;
|
|
68453
|
+
}
|
|
68454
|
+
}
|
|
68455
|
+
async function retryUnresolvedDelegateForwards(components) {
|
|
68456
|
+
const dispatchMeshCommand = components.dispatchMeshCommand;
|
|
68457
|
+
if (!dispatchMeshCommand) return;
|
|
68458
|
+
expireStaleUnresolvedDelegateForwards();
|
|
68459
|
+
const entries = peekUnresolvedDelegateForwards();
|
|
68460
|
+
if (entries.length === 0) {
|
|
68461
|
+
if (unresolvedForwardRejectionCounts.size > 0) unresolvedForwardRejectionCounts.clear();
|
|
68462
|
+
return;
|
|
68463
|
+
}
|
|
68464
|
+
const selfIds = resolveCoordinatorDaemonIds(components);
|
|
68465
|
+
const isSelfCoordinatorId = (id) => selfIds.some((self) => daemonIdsEquivalent(self, id));
|
|
68466
|
+
for (const entry of entries) {
|
|
68467
|
+
const entryTraceCtx = {
|
|
68468
|
+
taskId: entry.payload.taskId,
|
|
68469
|
+
sessionId: readNonEmptyString(entry.payload.targetSessionId) || readNonEmptyString(entry.payload.sessionId),
|
|
68470
|
+
nodeId: readNonEmptyString(entry.payload.nodeId),
|
|
68471
|
+
event: readNonEmptyString(entry.payload.event)
|
|
68472
|
+
};
|
|
68473
|
+
if (isSelfCoordinatorId(entry.coordinatorDaemonId)) {
|
|
68474
|
+
let localResult;
|
|
68475
|
+
try {
|
|
68476
|
+
traceMeshEventStage("forward_send", entryTraceCtx, `self \u2192 local router (${entry.coordinatorDaemonId})`);
|
|
68477
|
+
localResult = handleMeshForwardEvent(components, entry.payload);
|
|
68478
|
+
} catch (e) {
|
|
68479
|
+
LOG2.warn("MeshReconcile", `Local route of self-addressed forward to ${entry.coordinatorDaemonId} threw: ${e?.message || e} \u2014 draining anyway to break the retry loop`);
|
|
68480
|
+
}
|
|
68481
|
+
ackUnresolvedDelegateForward(entry.id);
|
|
68482
|
+
unresolvedForwardRejectionCounts.delete(entry.id);
|
|
68483
|
+
if (localResult && localResult.success === false) {
|
|
68484
|
+
LOG2.warn("MeshReconcile", `Self-addressed unresolved-delegate ${readNonEmptyString(entry.payload.event)} rejected by local router (${readNonEmptyString(localResult.error) || "no reason"}) \u2014 drained to break the self-forward retry loop`);
|
|
68485
|
+
traceMeshEventDrop("self_forward_local_rejected", entryTraceCtx, readNonEmptyString(localResult.error) || "no reason");
|
|
68486
|
+
} else {
|
|
68487
|
+
LOG2.info("MeshReconcile", `Self-addressed unresolved-delegate ${readNonEmptyString(entry.payload.event)} routed via local router (coordinator ${entry.coordinatorDaemonId} is self) \u2014 drained`);
|
|
68488
|
+
}
|
|
68489
|
+
continue;
|
|
68490
|
+
}
|
|
68491
|
+
let pushPayload = entry.payload;
|
|
68492
|
+
if (!readNonEmptyString(pushPayload.meshId)) {
|
|
68493
|
+
const recoveredMeshId = resolveForwardEventMeshId(components, pushPayload);
|
|
68494
|
+
if (recoveredMeshId) {
|
|
68495
|
+
pushPayload = { ...pushPayload, meshId: recoveredMeshId };
|
|
68496
|
+
traceMeshEventStage("forward_meshid_recovered", entryTraceCtx, `meshId=${recoveredMeshId}`);
|
|
68497
|
+
}
|
|
68498
|
+
}
|
|
68499
|
+
let result;
|
|
68500
|
+
try {
|
|
68501
|
+
traceMeshEventStage("forward_send", entryTraceCtx, `retry \u2192 ${entry.coordinatorDaemonId}`);
|
|
68502
|
+
result = await dispatchMeshCommand(entry.coordinatorDaemonId, "mesh_forward_event", withStatusProbeMarker(pushPayload));
|
|
68503
|
+
} catch (e) {
|
|
68504
|
+
LOG2.warn("MeshReconcile", `Retry forward to coordinator ${entry.coordinatorDaemonId} failed: ${e?.message || e} \u2014 left queued`);
|
|
68505
|
+
traceMeshEventDrop("retry_forward_failed", entryTraceCtx, e?.message || String(e));
|
|
68506
|
+
continue;
|
|
68507
|
+
}
|
|
68508
|
+
if (result && result.success === false) {
|
|
68509
|
+
const rejections = (unresolvedForwardRejectionCounts.get(entry.id) || 0) + 1;
|
|
68510
|
+
unresolvedForwardRejectionCounts.set(entry.id, rejections);
|
|
68511
|
+
const reason = readNonEmptyString(result.error) || "no reason";
|
|
68512
|
+
if (rejections >= MAX_FORWARD_REJECTIONS) {
|
|
68513
|
+
ackUnresolvedDelegateForward(entry.id);
|
|
68514
|
+
unresolvedForwardRejectionCounts.delete(entry.id);
|
|
68515
|
+
LOG2.warn("MeshReconcile", `Retry forward to coordinator ${entry.coordinatorDaemonId} rejected ${rejections}x (${reason}) \u2014 dropping unresolved-delegate ${readNonEmptyString(entry.payload.event)} (sess=${readNonEmptyString(entry.payload.targetSessionId) || readNonEmptyString(entry.payload.sessionId) || "-"}) to stop the retry loop`);
|
|
68516
|
+
traceMeshEventDrop("retry_forward_exhausted", entryTraceCtx, `${reason} (${rejections} rejections)`);
|
|
68517
|
+
} else {
|
|
68518
|
+
LOG2.warn("MeshReconcile", `Retry forward to coordinator ${entry.coordinatorDaemonId} rejected (${reason}) \u2014 left queued (attempt ${rejections}/${MAX_FORWARD_REJECTIONS})`);
|
|
68519
|
+
traceMeshEventDrop("retry_forward_rejected", entryTraceCtx, reason);
|
|
68520
|
+
}
|
|
68521
|
+
continue;
|
|
68522
|
+
}
|
|
68523
|
+
ackUnresolvedDelegateForward(entry.id);
|
|
68524
|
+
unresolvedForwardRejectionCounts.delete(entry.id);
|
|
68525
|
+
LOG2.info("MeshReconcile", `Retried+delivered unresolved-delegate ${readNonEmptyString(entry.payload.event)} to coordinator ${entry.coordinatorDaemonId}`);
|
|
68526
|
+
}
|
|
68527
|
+
}
|
|
68528
|
+
var unresolvedForwardRejectionCounts;
|
|
68529
|
+
var MAX_FORWARD_REJECTIONS;
|
|
68530
|
+
var UNRESOLVED_FORWARD_NUDGE_DELAY_MS;
|
|
68531
|
+
var unresolvedForwardNudgeTimer;
|
|
68532
|
+
var unresolvedForwardNudgeRunning;
|
|
68533
|
+
var init_mesh_reconcile_unresolved_forward = __esm2({
|
|
68534
|
+
"src/mesh/mesh-reconcile-unresolved-forward.ts"() {
|
|
68535
|
+
"use strict";
|
|
68536
|
+
init_logger();
|
|
68537
|
+
init_mesh_unresolved_forward_outbox();
|
|
68538
|
+
init_mesh_events_coordinator();
|
|
68539
|
+
init_mesh_events_utils();
|
|
68540
|
+
init_mesh_event_trace();
|
|
68541
|
+
init_dist();
|
|
68542
|
+
init_mesh_reconcile_identity();
|
|
68543
|
+
unresolvedForwardRejectionCounts = /* @__PURE__ */ new Map();
|
|
68544
|
+
MAX_FORWARD_REJECTIONS = 5;
|
|
68545
|
+
UNRESOLVED_FORWARD_NUDGE_DELAY_MS = 250;
|
|
68546
|
+
unresolvedForwardNudgeRunning = false;
|
|
68547
|
+
}
|
|
68548
|
+
});
|
|
68551
68549
|
async function runMeshReconcileTick(components) {
|
|
68552
68550
|
const localDaemonId = readNonEmptyString(loadConfig2().machineId) || void 0;
|
|
68553
68551
|
const drainDaemonIds = resolveCoordinatorDaemonIds(components);
|
|
@@ -68667,7 +68665,7 @@ ${cleanBody}`;
|
|
|
68667
68665
|
}
|
|
68668
68666
|
{
|
|
68669
68667
|
const nowMs = Date.now();
|
|
68670
|
-
const due = lastDiskRetentionRunAt === void 0 || nowMs - lastDiskRetentionRunAt >=
|
|
68668
|
+
const due = lastDiskRetentionRunAt === void 0 || nowMs - lastDiskRetentionRunAt >= DISK_RETENTION_INTERVAL_MS2;
|
|
68671
68669
|
if (due) {
|
|
68672
68670
|
lastDiskRetentionRunAt = nowMs;
|
|
68673
68671
|
try {
|
|
@@ -68861,145 +68859,6 @@ ${cleanBody}`;
|
|
|
68861
68859
|
drainAndInjectIntoTargets(meshId, drainDaemonIds, localDaemonId, targetCoordinators, "idle");
|
|
68862
68860
|
}
|
|
68863
68861
|
}
|
|
68864
|
-
function holdOrExpireStrictUnmatchedEvent(pending, wantSession, meshId) {
|
|
68865
|
-
const queuedAt = typeof pending.queuedAt === "number" ? pending.queuedAt : Date.now();
|
|
68866
|
-
if (Date.now() - queuedAt <= STRICT_SESSION_MATCH_TTL_MS) {
|
|
68867
|
-
try {
|
|
68868
|
-
const requeued = requeueDrainedPendingMeshCoordinatorEvent(pending);
|
|
68869
|
-
LOG2.info("MeshReconcile", `Strict route hold: coordinator session ${wantSession} not live on mesh ${meshId} \u2014 re-queued (${pending.event})${requeued ? "" : " [WARN: not durably re-queued]"}`);
|
|
68870
|
-
traceMeshEventDrop("strict_route_hold", {
|
|
68871
|
-
taskId: pending.metadataEvent?.taskId,
|
|
68872
|
-
sessionId: pending.metadataEvent?.targetSessionId ?? wantSession,
|
|
68873
|
-
nodeId: pending.nodeId,
|
|
68874
|
-
meshId,
|
|
68875
|
-
event: pending.event
|
|
68876
|
-
}, `coordinatorSession=${wantSession} not live durable=${requeued}`);
|
|
68877
|
-
} catch (e) {
|
|
68878
|
-
LOG2.warn("MeshReconcile", `Strict route re-queue failed for ${pending.event} on mesh ${meshId}: ${e?.message || e}`);
|
|
68879
|
-
}
|
|
68880
|
-
return;
|
|
68881
|
-
}
|
|
68882
|
-
const finalSummary = readMeshCompletionSummary(pending.metadataEvent || {});
|
|
68883
|
-
try {
|
|
68884
|
-
appendLedgerEntry(meshId, {
|
|
68885
|
-
kind: "event_held",
|
|
68886
|
-
...pending.nodeId ? { nodeId: pending.nodeId } : {},
|
|
68887
|
-
payload: {
|
|
68888
|
-
event: pending.event,
|
|
68889
|
-
reason: "strict_route_expired",
|
|
68890
|
-
recoverable: true,
|
|
68891
|
-
targetCoordinatorSessionId: wantSession,
|
|
68892
|
-
targetCoordinatorDaemonId: pending.targetCoordinatorDaemonId ?? null,
|
|
68893
|
-
nodeLabel: pending.nodeLabel,
|
|
68894
|
-
...pending.workspace ? { workspace: pending.workspace } : {},
|
|
68895
|
-
queuedAt,
|
|
68896
|
-
...finalSummary ? { finalSummary } : {}
|
|
68897
|
-
}
|
|
68898
|
-
});
|
|
68899
|
-
LOG2.warn("MeshReconcile", `Strict route expire: coordinator session ${wantSession} never returned for mesh ${meshId} \u2014 recorded to ledger (recoverable), dropped (${pending.event})`);
|
|
68900
|
-
traceMeshEventDrop("strict_route_expired", {
|
|
68901
|
-
taskId: pending.metadataEvent?.taskId,
|
|
68902
|
-
sessionId: pending.metadataEvent?.targetSessionId ?? wantSession,
|
|
68903
|
-
nodeId: pending.nodeId,
|
|
68904
|
-
meshId,
|
|
68905
|
-
event: pending.event
|
|
68906
|
-
}, `coordinatorSession=${wantSession} never returned`);
|
|
68907
|
-
} catch (e) {
|
|
68908
|
-
LOG2.warn("MeshReconcile", `Failed to ledger-expire strict-unmatched ${pending.event} for mesh ${meshId}: ${e?.message || e}`);
|
|
68909
|
-
}
|
|
68910
|
-
}
|
|
68911
|
-
function scheduleUnresolvedForwardNudge(components) {
|
|
68912
|
-
if (!components.dispatchMeshCommand) return;
|
|
68913
|
-
if (unresolvedForwardNudgeTimer) return;
|
|
68914
|
-
unresolvedForwardNudgeTimer = setTimeout(() => {
|
|
68915
|
-
unresolvedForwardNudgeTimer = void 0;
|
|
68916
|
-
if (unresolvedForwardNudgeRunning) return;
|
|
68917
|
-
unresolvedForwardNudgeRunning = true;
|
|
68918
|
-
void retryUnresolvedDelegateForwards(components).catch((e) => LOG2.warn("MeshReconcile", `Nudged unresolved-forward retry failed: ${e?.message || e}`)).finally(() => {
|
|
68919
|
-
unresolvedForwardNudgeRunning = false;
|
|
68920
|
-
});
|
|
68921
|
-
}, UNRESOLVED_FORWARD_NUDGE_DELAY_MS);
|
|
68922
|
-
if (typeof unresolvedForwardNudgeTimer.unref === "function") unresolvedForwardNudgeTimer.unref();
|
|
68923
|
-
}
|
|
68924
|
-
function clearUnresolvedForwardNudge() {
|
|
68925
|
-
if (unresolvedForwardNudgeTimer) {
|
|
68926
|
-
clearTimeout(unresolvedForwardNudgeTimer);
|
|
68927
|
-
unresolvedForwardNudgeTimer = void 0;
|
|
68928
|
-
}
|
|
68929
|
-
}
|
|
68930
|
-
async function retryUnresolvedDelegateForwards(components) {
|
|
68931
|
-
const dispatchMeshCommand = components.dispatchMeshCommand;
|
|
68932
|
-
if (!dispatchMeshCommand) return;
|
|
68933
|
-
expireStaleUnresolvedDelegateForwards();
|
|
68934
|
-
const entries = peekUnresolvedDelegateForwards();
|
|
68935
|
-
if (entries.length === 0) {
|
|
68936
|
-
if (unresolvedForwardRejectionCounts.size > 0) unresolvedForwardRejectionCounts.clear();
|
|
68937
|
-
return;
|
|
68938
|
-
}
|
|
68939
|
-
const selfIds = resolveCoordinatorDaemonIds(components);
|
|
68940
|
-
const isSelfCoordinatorId = (id) => selfIds.some((self) => daemonIdsEquivalent(self, id));
|
|
68941
|
-
for (const entry of entries) {
|
|
68942
|
-
const entryTraceCtx = {
|
|
68943
|
-
taskId: entry.payload.taskId,
|
|
68944
|
-
sessionId: readNonEmptyString(entry.payload.targetSessionId) || readNonEmptyString(entry.payload.sessionId),
|
|
68945
|
-
nodeId: readNonEmptyString(entry.payload.nodeId),
|
|
68946
|
-
event: readNonEmptyString(entry.payload.event)
|
|
68947
|
-
};
|
|
68948
|
-
if (isSelfCoordinatorId(entry.coordinatorDaemonId)) {
|
|
68949
|
-
let localResult;
|
|
68950
|
-
try {
|
|
68951
|
-
traceMeshEventStage("forward_send", entryTraceCtx, `self \u2192 local router (${entry.coordinatorDaemonId})`);
|
|
68952
|
-
localResult = handleMeshForwardEvent(components, entry.payload);
|
|
68953
|
-
} catch (e) {
|
|
68954
|
-
LOG2.warn("MeshReconcile", `Local route of self-addressed forward to ${entry.coordinatorDaemonId} threw: ${e?.message || e} \u2014 draining anyway to break the retry loop`);
|
|
68955
|
-
}
|
|
68956
|
-
ackUnresolvedDelegateForward(entry.id);
|
|
68957
|
-
unresolvedForwardRejectionCounts.delete(entry.id);
|
|
68958
|
-
if (localResult && localResult.success === false) {
|
|
68959
|
-
LOG2.warn("MeshReconcile", `Self-addressed unresolved-delegate ${readNonEmptyString(entry.payload.event)} rejected by local router (${readNonEmptyString(localResult.error) || "no reason"}) \u2014 drained to break the self-forward retry loop`);
|
|
68960
|
-
traceMeshEventDrop("self_forward_local_rejected", entryTraceCtx, readNonEmptyString(localResult.error) || "no reason");
|
|
68961
|
-
} else {
|
|
68962
|
-
LOG2.info("MeshReconcile", `Self-addressed unresolved-delegate ${readNonEmptyString(entry.payload.event)} routed via local router (coordinator ${entry.coordinatorDaemonId} is self) \u2014 drained`);
|
|
68963
|
-
}
|
|
68964
|
-
continue;
|
|
68965
|
-
}
|
|
68966
|
-
let pushPayload = entry.payload;
|
|
68967
|
-
if (!readNonEmptyString(pushPayload.meshId)) {
|
|
68968
|
-
const recoveredMeshId = resolveForwardEventMeshId(components, pushPayload);
|
|
68969
|
-
if (recoveredMeshId) {
|
|
68970
|
-
pushPayload = { ...pushPayload, meshId: recoveredMeshId };
|
|
68971
|
-
traceMeshEventStage("forward_meshid_recovered", entryTraceCtx, `meshId=${recoveredMeshId}`);
|
|
68972
|
-
}
|
|
68973
|
-
}
|
|
68974
|
-
let result;
|
|
68975
|
-
try {
|
|
68976
|
-
traceMeshEventStage("forward_send", entryTraceCtx, `retry \u2192 ${entry.coordinatorDaemonId}`);
|
|
68977
|
-
result = await dispatchMeshCommand(entry.coordinatorDaemonId, "mesh_forward_event", withStatusProbeMarker(pushPayload));
|
|
68978
|
-
} catch (e) {
|
|
68979
|
-
LOG2.warn("MeshReconcile", `Retry forward to coordinator ${entry.coordinatorDaemonId} failed: ${e?.message || e} \u2014 left queued`);
|
|
68980
|
-
traceMeshEventDrop("retry_forward_failed", entryTraceCtx, e?.message || String(e));
|
|
68981
|
-
continue;
|
|
68982
|
-
}
|
|
68983
|
-
if (result && result.success === false) {
|
|
68984
|
-
const rejections = (unresolvedForwardRejectionCounts.get(entry.id) || 0) + 1;
|
|
68985
|
-
unresolvedForwardRejectionCounts.set(entry.id, rejections);
|
|
68986
|
-
const reason = readNonEmptyString(result.error) || "no reason";
|
|
68987
|
-
if (rejections >= MAX_FORWARD_REJECTIONS) {
|
|
68988
|
-
ackUnresolvedDelegateForward(entry.id);
|
|
68989
|
-
unresolvedForwardRejectionCounts.delete(entry.id);
|
|
68990
|
-
LOG2.warn("MeshReconcile", `Retry forward to coordinator ${entry.coordinatorDaemonId} rejected ${rejections}x (${reason}) \u2014 dropping unresolved-delegate ${readNonEmptyString(entry.payload.event)} (sess=${readNonEmptyString(entry.payload.targetSessionId) || readNonEmptyString(entry.payload.sessionId) || "-"}) to stop the retry loop`);
|
|
68991
|
-
traceMeshEventDrop("retry_forward_exhausted", entryTraceCtx, `${reason} (${rejections} rejections)`);
|
|
68992
|
-
} else {
|
|
68993
|
-
LOG2.warn("MeshReconcile", `Retry forward to coordinator ${entry.coordinatorDaemonId} rejected (${reason}) \u2014 left queued (attempt ${rejections}/${MAX_FORWARD_REJECTIONS})`);
|
|
68994
|
-
traceMeshEventDrop("retry_forward_rejected", entryTraceCtx, reason);
|
|
68995
|
-
}
|
|
68996
|
-
continue;
|
|
68997
|
-
}
|
|
68998
|
-
ackUnresolvedDelegateForward(entry.id);
|
|
68999
|
-
unresolvedForwardRejectionCounts.delete(entry.id);
|
|
69000
|
-
LOG2.info("MeshReconcile", `Retried+delivered unresolved-delegate ${readNonEmptyString(entry.payload.event)} to coordinator ${entry.coordinatorDaemonId}`);
|
|
69001
|
-
}
|
|
69002
|
-
}
|
|
69003
68862
|
function setupMeshReconcileLoop(components) {
|
|
69004
68863
|
const intervalMs = resolveReconcileIntervalMs();
|
|
69005
68864
|
let running = false;
|
|
@@ -69053,28 +68912,8 @@ ${cleanBody}`;
|
|
|
69053
68912
|
}
|
|
69054
68913
|
};
|
|
69055
68914
|
}
|
|
69056
|
-
var
|
|
69057
|
-
var DISK_RETENTION_INTERVAL_MS;
|
|
68915
|
+
var DISK_RETENTION_INTERVAL_MS2;
|
|
69058
68916
|
var lastDiskRetentionRunAt;
|
|
69059
|
-
var heldEventLedgerRecorded;
|
|
69060
|
-
var ASSIGNED_STRANDED_DEADLINE_MS;
|
|
69061
|
-
var DELIVERED_NO_TURN_DEADLINE_MS;
|
|
69062
|
-
var NATIVE_SOURCE_ACTIVITY_STALE_MS;
|
|
69063
|
-
var ASSIGNED_DELIVERED_UNCONSUMED_REDRIVE_MS;
|
|
69064
|
-
var RECLAIM_UNKNOWN_GRACE_TICKS;
|
|
69065
|
-
var QUEUE_HOLD_HARD_DEADLINE_MS;
|
|
69066
|
-
var queueHoldHardDeadlineAudited;
|
|
69067
|
-
var deliveredNoTurnUnknownStreak;
|
|
69068
|
-
var deliveredUnconsumedUnknownStreak;
|
|
69069
|
-
var ASSIGNED_IDLE_TRANSCRIPT_COMPLETE_MS;
|
|
69070
|
-
var assignedIdleFinalAssistantSince;
|
|
69071
|
-
var ZOMBIE_ASSIGNED_MIN_AGE_MS;
|
|
69072
|
-
var STRICT_SESSION_MATCH_TTL_MS;
|
|
69073
|
-
var unresolvedForwardRejectionCounts;
|
|
69074
|
-
var MAX_FORWARD_REJECTIONS;
|
|
69075
|
-
var UNRESOLVED_FORWARD_NUDGE_DELAY_MS;
|
|
69076
|
-
var unresolvedForwardNudgeTimer;
|
|
69077
|
-
var unresolvedForwardNudgeRunning;
|
|
69078
68917
|
var init_mesh_reconcile_loop = __esm2({
|
|
69079
68918
|
"src/mesh/mesh-reconcile-loop.ts"() {
|
|
69080
68919
|
"use strict";
|
|
@@ -69083,52 +68922,29 @@ ${cleanBody}`;
|
|
|
69083
68922
|
init_mesh_idle_reminder();
|
|
69084
68923
|
init_logger();
|
|
69085
68924
|
init_mesh_events_pending();
|
|
69086
|
-
init_mesh_ledger();
|
|
69087
68925
|
init_mesh_runtime_store();
|
|
69088
68926
|
init_mesh_events_coordinator();
|
|
69089
|
-
init_mesh_event_classify();
|
|
69090
|
-
init_mesh_unresolved_forward_outbox();
|
|
69091
68927
|
init_mesh_events_utils();
|
|
69092
|
-
|
|
69093
|
-
init_dist();
|
|
69094
|
-
init_mesh_work_queue();
|
|
69095
|
-
init_mesh_queue_assignment();
|
|
69096
|
-
init_mesh_ledger();
|
|
69097
|
-
init_mesh_events_stale();
|
|
68928
|
+
init_mesh_unresolved_forward_outbox();
|
|
69098
68929
|
init_mesh_reconcile_identity();
|
|
69099
68930
|
init_mesh_reconcile_config();
|
|
69100
68931
|
init_mesh_remote_event_pull();
|
|
69101
|
-
init_transcript_evidence();
|
|
69102
68932
|
init_mesh_disk_retention();
|
|
69103
68933
|
init_mesh_worktree_retention();
|
|
69104
68934
|
init_mesh_retention_config();
|
|
69105
68935
|
init_mesh_completion_synthesis();
|
|
69106
|
-
init_mesh_active_work();
|
|
69107
68936
|
init_mesh_event_forwarding();
|
|
68937
|
+
init_mesh_queue_assignment();
|
|
69108
68938
|
init_mesh_turn_ledger();
|
|
69109
|
-
|
|
68939
|
+
init_mesh_reconcile_coordinator_drain();
|
|
68940
|
+
init_mesh_reconcile_stranded_dispatch();
|
|
68941
|
+
init_mesh_reconcile_unresolved_forward();
|
|
69110
68942
|
init_mesh_reconcile_v2_backstop();
|
|
69111
68943
|
init_mesh_reconcile_acked_hold();
|
|
69112
|
-
|
|
69113
|
-
|
|
69114
|
-
|
|
69115
|
-
|
|
69116
|
-
DELIVERED_NO_TURN_DEADLINE_MS = 15 * 6e4;
|
|
69117
|
-
NATIVE_SOURCE_ACTIVITY_STALE_MS = 10 * 6e4;
|
|
69118
|
-
ASSIGNED_DELIVERED_UNCONSUMED_REDRIVE_MS = 25e3;
|
|
69119
|
-
RECLAIM_UNKNOWN_GRACE_TICKS = 3;
|
|
69120
|
-
QUEUE_HOLD_HARD_DEADLINE_MS = 90 * 6e4;
|
|
69121
|
-
queueHoldHardDeadlineAudited = /* @__PURE__ */ new Set();
|
|
69122
|
-
deliveredNoTurnUnknownStreak = /* @__PURE__ */ new Map();
|
|
69123
|
-
deliveredUnconsumedUnknownStreak = /* @__PURE__ */ new Map();
|
|
69124
|
-
ASSIGNED_IDLE_TRANSCRIPT_COMPLETE_MS = 8e3;
|
|
69125
|
-
assignedIdleFinalAssistantSince = /* @__PURE__ */ new Map();
|
|
69126
|
-
ZOMBIE_ASSIGNED_MIN_AGE_MS = 30 * 60 * 1e3;
|
|
69127
|
-
STRICT_SESSION_MATCH_TTL_MS = 6e4;
|
|
69128
|
-
unresolvedForwardRejectionCounts = /* @__PURE__ */ new Map();
|
|
69129
|
-
MAX_FORWARD_REJECTIONS = 5;
|
|
69130
|
-
UNRESOLVED_FORWARD_NUDGE_DELAY_MS = 250;
|
|
69131
|
-
unresolvedForwardNudgeRunning = false;
|
|
68944
|
+
init_mesh_reconcile_coordinator_drain();
|
|
68945
|
+
init_mesh_reconcile_stranded_dispatch();
|
|
68946
|
+
init_mesh_reconcile_unresolved_forward();
|
|
68947
|
+
DISK_RETENTION_INTERVAL_MS2 = 60 * 60 * 1e3;
|
|
69132
68948
|
}
|
|
69133
68949
|
});
|
|
69134
68950
|
var mesh_events_exports = {};
|
|
@@ -78031,7 +77847,7 @@ ${lastSnapshot}`;
|
|
|
78031
77847
|
getHostMemorySnapshot: () => getHostMemorySnapshot,
|
|
78032
77848
|
getInstallOrigin: () => getInstallOrigin,
|
|
78033
77849
|
getLastDisplayMessage: () => getLastDisplayMessage,
|
|
78034
|
-
getLedgerDir: () =>
|
|
77850
|
+
getLedgerDir: () => getLedgerDir2,
|
|
78035
77851
|
getLedgerSummary: () => getLedgerSummary,
|
|
78036
77852
|
getLogInstanceTag: () => getLogInstanceTag,
|
|
78037
77853
|
getLogLevel: () => getLogLevel,
|
|
@@ -79728,8 +79544,8 @@ ${lastSnapshot}`;
|
|
|
79728
79544
|
var import_node_util4 = require("util");
|
|
79729
79545
|
init_repo_mesh_types();
|
|
79730
79546
|
init_mesh_config();
|
|
79731
|
-
var
|
|
79732
|
-
var
|
|
79547
|
+
var import_fs11 = require("fs");
|
|
79548
|
+
var import_path10 = require("path");
|
|
79733
79549
|
init_refine_config();
|
|
79734
79550
|
init_worktree_bootstrap_config();
|
|
79735
79551
|
init_change_impact_config();
|
|
@@ -79748,22 +79564,22 @@ ${lastSnapshot}`;
|
|
|
79748
79564
|
"requirements.txt"
|
|
79749
79565
|
];
|
|
79750
79566
|
function writeConfigFile(workspace, relativePath, config2) {
|
|
79751
|
-
const target = (0,
|
|
79752
|
-
(0,
|
|
79753
|
-
(0,
|
|
79567
|
+
const target = (0, import_path10.join)(workspace, relativePath);
|
|
79568
|
+
(0, import_fs11.mkdirSync)((0, import_path10.dirname)(target), { recursive: true });
|
|
79569
|
+
(0, import_fs11.writeFileSync)(target, `${JSON.stringify(config2, null, 2)}
|
|
79754
79570
|
`, "utf-8");
|
|
79755
79571
|
return target;
|
|
79756
79572
|
}
|
|
79757
79573
|
function suggestMeshWorktreeBootstrapConfig(workspace) {
|
|
79758
79574
|
const commands = [];
|
|
79759
|
-
const hasPackageJson = (0,
|
|
79760
|
-
const hasNpmLock = (0,
|
|
79575
|
+
const hasPackageJson = (0, import_fs11.existsSync)((0, import_path10.join)(workspace, "package.json"));
|
|
79576
|
+
const hasNpmLock = (0, import_fs11.existsSync)((0, import_path10.join)(workspace, "package-lock.json"));
|
|
79761
79577
|
if (hasPackageJson) {
|
|
79762
79578
|
commands.push(
|
|
79763
79579
|
hasNpmLock ? { command: "npm", args: ["ci"] } : { command: "npm", args: ["install"] }
|
|
79764
79580
|
);
|
|
79765
79581
|
}
|
|
79766
|
-
const staleInputs = CANDIDATE_STALE_INPUTS.filter((relative8) => (0,
|
|
79582
|
+
const staleInputs = CANDIDATE_STALE_INPUTS.filter((relative8) => (0, import_fs11.existsSync)((0, import_path10.join)(workspace, relative8)));
|
|
79767
79583
|
if (!commands.length) {
|
|
79768
79584
|
return { commands, staleInputs };
|
|
79769
79585
|
}
|
|
@@ -79862,7 +79678,7 @@ ${lastSnapshot}`;
|
|
|
79862
79678
|
}
|
|
79863
79679
|
function applyConfigSuggestion(input) {
|
|
79864
79680
|
const { workspace, relativePath, existing, suggestedConfig, validate, write, overwrite } = input;
|
|
79865
|
-
const absolute = (0,
|
|
79681
|
+
const absolute = (0, import_path10.join)(workspace, relativePath);
|
|
79866
79682
|
if (existing !== void 0 && !overwrite) {
|
|
79867
79683
|
return { path: absolute, relativePath, written: false, skippedReason: "already_exists", config: existing };
|
|
79868
79684
|
}
|
|
@@ -80389,8 +80205,8 @@ ${lastSnapshot}`;
|
|
|
80389
80205
|
};
|
|
80390
80206
|
}
|
|
80391
80207
|
init_mesh_ledger();
|
|
80392
|
-
var
|
|
80393
|
-
var
|
|
80208
|
+
var import_fs13 = require("fs");
|
|
80209
|
+
var import_path12 = require("path");
|
|
80394
80210
|
init_config();
|
|
80395
80211
|
init_usage_normalize();
|
|
80396
80212
|
var USAGE_DIR_NAME = "mesh-usage";
|
|
@@ -80405,13 +80221,13 @@ ${lastSnapshot}`;
|
|
|
80405
80221
|
lastEvictedAt: 0
|
|
80406
80222
|
};
|
|
80407
80223
|
function getUsageDir() {
|
|
80408
|
-
const dir = (0,
|
|
80409
|
-
if (!(0,
|
|
80224
|
+
const dir = (0, import_path12.join)(getConfigDir2(), USAGE_DIR_NAME);
|
|
80225
|
+
if (!(0, import_fs13.existsSync)(dir)) (0, import_fs13.mkdirSync)(dir, { recursive: true, mode: 448 });
|
|
80410
80226
|
return dir;
|
|
80411
80227
|
}
|
|
80412
80228
|
function getUsagePath(meshId) {
|
|
80413
80229
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
80414
|
-
return (0,
|
|
80230
|
+
return (0, import_path12.join)(getUsageDir(), `${safe}.json`);
|
|
80415
80231
|
}
|
|
80416
80232
|
function emptyFile(meshId) {
|
|
80417
80233
|
return { version: 1, meshId, sessions: {} };
|
|
@@ -80421,7 +80237,7 @@ ${lastSnapshot}`;
|
|
|
80421
80237
|
const path54 = getUsagePath(meshId);
|
|
80422
80238
|
let stat2;
|
|
80423
80239
|
try {
|
|
80424
|
-
const s2 = (0,
|
|
80240
|
+
const s2 = (0, import_fs13.statSync)(path54);
|
|
80425
80241
|
stat2 = { mtimeMs: s2.mtimeMs, size: s2.size };
|
|
80426
80242
|
} catch {
|
|
80427
80243
|
usageFileCache.delete(path54);
|
|
@@ -80432,7 +80248,7 @@ ${lastSnapshot}`;
|
|
|
80432
80248
|
return cached5.file;
|
|
80433
80249
|
}
|
|
80434
80250
|
try {
|
|
80435
|
-
const parsed = JSON.parse((0,
|
|
80251
|
+
const parsed = JSON.parse((0, import_fs13.readFileSync)(path54, "utf-8"));
|
|
80436
80252
|
if (!parsed || typeof parsed !== "object" || !parsed.sessions) {
|
|
80437
80253
|
usageFileCache.delete(path54);
|
|
80438
80254
|
return emptyFile(meshId);
|
|
@@ -80447,19 +80263,19 @@ ${lastSnapshot}`;
|
|
|
80447
80263
|
function writeUsageFile(meshId, file2) {
|
|
80448
80264
|
const path54 = getUsagePath(meshId);
|
|
80449
80265
|
const tmp = `${path54}.tmp`;
|
|
80450
|
-
(0,
|
|
80266
|
+
(0, import_fs13.writeFileSync)(tmp, JSON.stringify(file2), { encoding: "utf-8", mode: 384 });
|
|
80451
80267
|
try {
|
|
80452
|
-
(0,
|
|
80268
|
+
(0, import_fs13.renameSync)(tmp, path54);
|
|
80453
80269
|
} catch (e) {
|
|
80454
80270
|
try {
|
|
80455
|
-
(0,
|
|
80271
|
+
(0, import_fs13.unlinkSync)(tmp);
|
|
80456
80272
|
} catch {
|
|
80457
80273
|
}
|
|
80458
80274
|
usageFileCache.delete(path54);
|
|
80459
80275
|
throw e;
|
|
80460
80276
|
}
|
|
80461
80277
|
try {
|
|
80462
|
-
const s2 = (0,
|
|
80278
|
+
const s2 = (0, import_fs13.statSync)(path54);
|
|
80463
80279
|
usageFileCache.set(path54, { file: file2, mtimeMs: s2.mtimeMs, size: s2.size });
|
|
80464
80280
|
} catch {
|
|
80465
80281
|
usageFileCache.delete(path54);
|
|
@@ -80840,7 +80656,7 @@ ${lastSnapshot}`;
|
|
|
80840
80656
|
init_state_store();
|
|
80841
80657
|
var import_child_process5 = require("child_process");
|
|
80842
80658
|
var import_util22 = require("util");
|
|
80843
|
-
var
|
|
80659
|
+
var import_fs17 = require("fs");
|
|
80844
80660
|
var import_os3 = require("os");
|
|
80845
80661
|
var path20 = __toESM2(require("path"));
|
|
80846
80662
|
var fs12 = __toESM2(require("fs"));
|
|
@@ -80917,7 +80733,7 @@ ${lastSnapshot}`;
|
|
|
80917
80733
|
if (path20.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~")) {
|
|
80918
80734
|
const candidate = trimmed.startsWith("~") ? path20.join((0, import_os3.homedir)(), trimmed.slice(1)) : trimmed;
|
|
80919
80735
|
const resolved = path20.isAbsolute(candidate) ? candidate : path20.resolve(candidate);
|
|
80920
|
-
return (0,
|
|
80736
|
+
return (0, import_fs17.existsSync)(resolved) ? resolved : null;
|
|
80921
80737
|
}
|
|
80922
80738
|
const isWin = (0, import_os3.platform)() === "win32";
|
|
80923
80739
|
const paths = (process.env.PATH || "").split(isWin ? ";" : ":");
|
|
@@ -80927,8 +80743,8 @@ ${lastSnapshot}`;
|
|
|
80927
80743
|
for (const ext of exes) {
|
|
80928
80744
|
const fullPath = path20.join(p, trimmed + ext);
|
|
80929
80745
|
try {
|
|
80930
|
-
if ((0,
|
|
80931
|
-
const stat2 = (0,
|
|
80746
|
+
if ((0, import_fs17.existsSync)(fullPath)) {
|
|
80747
|
+
const stat2 = (0, import_fs17.statSync)(fullPath);
|
|
80932
80748
|
if (stat2.isFile() && (isWin || stat2.mode & 73)) {
|
|
80933
80749
|
return fullPath;
|
|
80934
80750
|
}
|
|
@@ -80946,9 +80762,9 @@ ${lastSnapshot}`;
|
|
|
80946
80762
|
if (normalized.includes("*")) {
|
|
80947
80763
|
const username = home.split(/[\\/]/).pop() || "";
|
|
80948
80764
|
const resolved = normalized.replace("*", username);
|
|
80949
|
-
if ((0,
|
|
80765
|
+
if ((0, import_fs17.existsSync)(resolved)) return resolved;
|
|
80950
80766
|
} else {
|
|
80951
|
-
if ((0,
|
|
80767
|
+
if ((0, import_fs17.existsSync)(normalized)) return normalized;
|
|
80952
80768
|
}
|
|
80953
80769
|
}
|
|
80954
80770
|
return null;
|
|
@@ -80962,7 +80778,7 @@ ${lastSnapshot}`;
|
|
|
80962
80778
|
let resolvedCli = cliPath;
|
|
80963
80779
|
if (!resolvedCli && appPath && os28 === "darwin") {
|
|
80964
80780
|
const bundledCli = `${appPath}/Contents/Resources/app/bin/${def.cli}`;
|
|
80965
|
-
if ((0,
|
|
80781
|
+
if ((0, import_fs17.existsSync)(bundledCli)) resolvedCli = bundledCli;
|
|
80966
80782
|
}
|
|
80967
80783
|
if (!resolvedCli && appPath && os28 === "win32") {
|
|
80968
80784
|
const { dirname: dirname22 } = await import("path");
|
|
@@ -80975,7 +80791,7 @@ ${lastSnapshot}`;
|
|
|
80975
80791
|
`${appDir}\\\\resources\\\\app\\\\bin\\\\${def.cli}.cmd`
|
|
80976
80792
|
];
|
|
80977
80793
|
for (const c of candidates) {
|
|
80978
|
-
if ((0,
|
|
80794
|
+
if ((0, import_fs17.existsSync)(c)) {
|
|
80979
80795
|
resolvedCli = c;
|
|
80980
80796
|
break;
|
|
80981
80797
|
}
|
|
@@ -90470,9 +90286,9 @@ ${effect.notification.body || ""}`.trim();
|
|
|
90470
90286
|
}
|
|
90471
90287
|
return false;
|
|
90472
90288
|
}
|
|
90473
|
-
function
|
|
90289
|
+
function inspectOwnedNodeProcesses(options) {
|
|
90474
90290
|
const platform10 = options.platform ?? process.platform;
|
|
90475
|
-
if (platform10 !== "win32") return [];
|
|
90291
|
+
if (platform10 !== "win32") return { processes: [], probeFailed: false, probeFailureReason: null };
|
|
90476
90292
|
const exec7 = options.execFileSync ?? defaultExecFileSync();
|
|
90477
90293
|
const prefixes = options.prefixes.map((p) => normalizeWindowsPath(p));
|
|
90478
90294
|
const exclude = new Set((options.excludePids ?? []).filter((n) => Number.isFinite(n) && n > 0));
|
|
@@ -90491,21 +90307,33 @@ ${effect.notification.body || ""}`.trim();
|
|
|
90491
90307
|
const parsed = JSON.parse(out);
|
|
90492
90308
|
pids = Array.isArray(parsed) ? parsed : [parsed];
|
|
90493
90309
|
}
|
|
90494
|
-
} catch {
|
|
90495
|
-
return
|
|
90310
|
+
} catch (error48) {
|
|
90311
|
+
return {
|
|
90312
|
+
processes: [],
|
|
90313
|
+
probeFailed: true,
|
|
90314
|
+
probeFailureReason: `node process enumeration failed: ${errorText(error48)}`
|
|
90315
|
+
};
|
|
90496
90316
|
}
|
|
90497
90317
|
const results = [];
|
|
90318
|
+
let unreadable = 0;
|
|
90498
90319
|
for (const pid of pids) {
|
|
90499
90320
|
if (!Number.isFinite(pid) || pid <= 0 || exclude.has(pid)) continue;
|
|
90500
90321
|
const commandLine = getProcessCommandLine(pid, { platform: platform10, execFileSync: exec7 });
|
|
90501
|
-
if (!commandLine)
|
|
90322
|
+
if (!commandLine) {
|
|
90323
|
+
unreadable += 1;
|
|
90324
|
+
continue;
|
|
90325
|
+
}
|
|
90502
90326
|
const lower = commandLine.toLowerCase();
|
|
90503
90327
|
const underPrefix = prefixes.some((prefix) => lower.includes(prefix));
|
|
90504
90328
|
if (!underPrefix) continue;
|
|
90505
90329
|
if (markers.length > 0 && !markers.some((marker) => lower.includes(marker))) continue;
|
|
90506
90330
|
results.push({ pid, commandLine });
|
|
90507
90331
|
}
|
|
90508
|
-
return
|
|
90332
|
+
return {
|
|
90333
|
+
processes: results,
|
|
90334
|
+
probeFailed: unreadable > 0,
|
|
90335
|
+
probeFailureReason: unreadable > 0 ? `${unreadable} node process(es) had an unreadable command line; their prefix could not be determined` : null
|
|
90336
|
+
};
|
|
90509
90337
|
}
|
|
90510
90338
|
async function stopOwnedProcesses(options) {
|
|
90511
90339
|
const waitMs = options.waitMs ?? 15e3;
|
|
@@ -90525,11 +90353,18 @@ ${effect.notification.body || ""}`.trim();
|
|
|
90525
90353
|
return { stopped: options.processes.length - survivors.length, survivors };
|
|
90526
90354
|
}
|
|
90527
90355
|
async function stopOwnedProcessesForPrefixes(options) {
|
|
90528
|
-
const
|
|
90529
|
-
if (
|
|
90530
|
-
|
|
90356
|
+
const sweep = inspectOwnedNodeProcesses(options);
|
|
90357
|
+
if (sweep.probeFailed) {
|
|
90358
|
+
options.log?.(
|
|
90359
|
+
`Process-inspection probe could not verify prefixes ${options.prefixes.join(", ")}: ${sweep.probeFailureReason}. Treating the result as UNVERIFIED rather than clean.`
|
|
90360
|
+
);
|
|
90361
|
+
}
|
|
90362
|
+
if (sweep.processes.length === 0) {
|
|
90363
|
+
return { stopped: 0, survivors: [], probeFailed: sweep.probeFailed, probeFailureReason: sweep.probeFailureReason };
|
|
90364
|
+
}
|
|
90365
|
+
options.log?.(`Stopping ${sweep.processes.length} owned process(es) under prefixes: ${options.prefixes.join(", ")}`);
|
|
90531
90366
|
const result = await stopOwnedProcesses({
|
|
90532
|
-
processes,
|
|
90367
|
+
processes: sweep.processes,
|
|
90533
90368
|
waitMs: options.waitMs,
|
|
90534
90369
|
platform: options.platform,
|
|
90535
90370
|
execFileSync: options.execFileSync
|
|
@@ -90537,10 +90372,11 @@ ${effect.notification.body || ""}`.trim();
|
|
|
90537
90372
|
if (result.survivors.length > 0) {
|
|
90538
90373
|
options.log?.(`Could not stop ${result.survivors.length} owned process(es): ${result.survivors.map((s2) => s2.pid).join(", ")}`);
|
|
90539
90374
|
}
|
|
90540
|
-
return result;
|
|
90375
|
+
return { ...result, probeFailed: sweep.probeFailed, probeFailureReason: sweep.probeFailureReason };
|
|
90541
90376
|
}
|
|
90542
90377
|
var POINTER_NAME = ".adhdev-current";
|
|
90543
90378
|
var STABLE_FILES = [POINTER_NAME, "adhdev.cmd", "adhdev.ps1", "adhdev"];
|
|
90379
|
+
var REAL_PLATFORM = process.platform;
|
|
90544
90380
|
function resolveDefaultHealthPort(env2 = process.env) {
|
|
90545
90381
|
return getTrackIdentity(resolveBuildTrack(env2)).defaultPort;
|
|
90546
90382
|
}
|
|
@@ -90798,7 +90634,7 @@ exec "${portableNode}" "${cliEntry}" "$@"
|
|
|
90798
90634
|
function restoreStableFiles(snapshots, layout) {
|
|
90799
90635
|
const shims = stableShimContents();
|
|
90800
90636
|
for (const [target, snapshot] of snapshots) {
|
|
90801
|
-
if (snapshot.exists && snapshot.data) {
|
|
90637
|
+
if (snapshot.exists && snapshot.data && snapshot.data.length > 0) {
|
|
90802
90638
|
atomicWrite(target, snapshot.data.toString("binary"), "binary");
|
|
90803
90639
|
continue;
|
|
90804
90640
|
}
|
|
@@ -90806,7 +90642,7 @@ exec "${portableNode}" "${cliEntry}" "$@"
|
|
|
90806
90642
|
if (name === "adhdev.cmd" || name === "adhdev.ps1" || name === "adhdev") {
|
|
90807
90643
|
atomicWrite(target, shims[name].content, shims[name].encoding);
|
|
90808
90644
|
} else if (name === POINTER_NAME) {
|
|
90809
|
-
if (layout.activeVersionName)
|
|
90645
|
+
if (layout.activeVersionName) writePointerVerified(target, layout.activeVersionName);
|
|
90810
90646
|
else try {
|
|
90811
90647
|
fs19.unlinkSync(target);
|
|
90812
90648
|
} catch {
|
|
@@ -90819,12 +90655,30 @@ exec "${portableNode}" "${cliEntry}" "$@"
|
|
|
90819
90655
|
}
|
|
90820
90656
|
}
|
|
90821
90657
|
}
|
|
90658
|
+
function writePointerVerified(pointerPath, versionName) {
|
|
90659
|
+
if (!versionName || !versionName.trim()) {
|
|
90660
|
+
throw new Error(`refusing to write an empty version pointer to ${pointerPath}`);
|
|
90661
|
+
}
|
|
90662
|
+
atomicWrite(pointerPath, versionName, "ascii");
|
|
90663
|
+
if (REAL_PLATFORM !== "win32") return;
|
|
90664
|
+
let readback = "";
|
|
90665
|
+
try {
|
|
90666
|
+
readback = fs19.readFileSync(pointerPath, "utf8").trim();
|
|
90667
|
+
} catch (error48) {
|
|
90668
|
+
throw new Error(`version pointer readback failed for ${pointerPath}: ${error48?.message || String(error48)}`);
|
|
90669
|
+
}
|
|
90670
|
+
if (readback !== versionName.trim()) {
|
|
90671
|
+
throw new Error(
|
|
90672
|
+
`version pointer verification failed for ${pointerPath}: expected "${versionName.trim()}", read "${readback}"`
|
|
90673
|
+
);
|
|
90674
|
+
}
|
|
90675
|
+
}
|
|
90822
90676
|
function publishStableShimsAndPointer(layout, versionName) {
|
|
90823
90677
|
const shims = stableShimContents();
|
|
90824
90678
|
for (const name of ["adhdev.cmd", "adhdev.ps1", "adhdev"]) {
|
|
90825
90679
|
atomicWrite(path25.join(layout.stablePrefix, name), shims[name].content, shims[name].encoding);
|
|
90826
90680
|
}
|
|
90827
|
-
|
|
90681
|
+
writePointerVerified(layout.pointerPath, versionName);
|
|
90828
90682
|
}
|
|
90829
90683
|
function removeFailedStagedPrefix(stagedPrefix, layout, log) {
|
|
90830
90684
|
try {
|
|
@@ -91042,6 +90896,12 @@ exec "${portableNode}" "${cliEntry}" "$@"
|
|
|
91042
90896
|
log?.(`Skipping cleanup of ${candidate}: ${stopResult.survivors.length} owned process(es) could not be stopped`);
|
|
91043
90897
|
continue;
|
|
91044
90898
|
}
|
|
90899
|
+
if (stopResult.probeFailed) {
|
|
90900
|
+
log?.(
|
|
90901
|
+
`Skipping cleanup of ${candidate}: could not verify that no process is running from it (${stopResult.probeFailureReason}). Refusing to delete an install directory on an unverified sweep.`
|
|
90902
|
+
);
|
|
90903
|
+
continue;
|
|
90904
|
+
}
|
|
91045
90905
|
removeInactivePrefix(candidate, log);
|
|
91046
90906
|
}
|
|
91047
90907
|
}
|
|
@@ -91240,29 +91100,73 @@ exec "${portableNode}" "${cliEntry}" "$@"
|
|
|
91240
91100
|
}
|
|
91241
91101
|
return String(execNpmCommandSync(args, execOptions, surface)).trim();
|
|
91242
91102
|
}
|
|
91243
|
-
function
|
|
91103
|
+
function classifySessionHostPid(pid) {
|
|
91244
91104
|
const commandLine = getProcessCommandLine(pid);
|
|
91245
|
-
|
|
91105
|
+
if (!commandLine) return "unknown";
|
|
91106
|
+
return /session-host-daemon/i.test(commandLine) ? "managed" : "unrelated";
|
|
91246
91107
|
}
|
|
91247
91108
|
async function stopSessionHostProcesses(appName, configDir = getConfigDir2()) {
|
|
91248
91109
|
const pidFile = path26.join(configDir, `${appName}-session-host.pid`);
|
|
91110
|
+
const outcome = { pid: null, identity: null, stopped: false, survived: false };
|
|
91249
91111
|
let killedPid = null;
|
|
91112
|
+
let keepPidFile = false;
|
|
91250
91113
|
try {
|
|
91251
91114
|
if (fs20.existsSync(pidFile)) {
|
|
91252
91115
|
const pid = Number.parseInt(fs20.readFileSync(pidFile, "utf8").trim(), 10);
|
|
91253
|
-
if (Number.isFinite(pid) && pid !== process.pid
|
|
91254
|
-
|
|
91116
|
+
if (Number.isFinite(pid) && pid !== process.pid) {
|
|
91117
|
+
outcome.pid = pid;
|
|
91118
|
+
const identity = classifySessionHostPid(pid);
|
|
91119
|
+
outcome.identity = identity;
|
|
91120
|
+
if (identity === "unrelated") {
|
|
91121
|
+
appendUpgradeLog(
|
|
91122
|
+
`Session-host pidfile names pid ${pid}, which is positively identified as an unrelated process; treating the pidfile as stale and not killing it.`,
|
|
91123
|
+
configDir
|
|
91124
|
+
);
|
|
91125
|
+
} else {
|
|
91126
|
+
if (identity === "unknown") {
|
|
91127
|
+
appendUpgradeLog(
|
|
91128
|
+
`Could not read the command line of session-host pid ${pid} (process-inspection unavailable). The pidfile is this daemon's own record, so the pid is treated as ours and stopped \u2014 a stale host surviving an upgrade breaks every create_session with a conpty.node load failure.`,
|
|
91129
|
+
configDir
|
|
91130
|
+
);
|
|
91131
|
+
}
|
|
91132
|
+
if (killProcess(pid)) killedPid = pid;
|
|
91133
|
+
}
|
|
91255
91134
|
}
|
|
91256
91135
|
}
|
|
91257
91136
|
} catch {
|
|
91258
|
-
}
|
|
91137
|
+
}
|
|
91138
|
+
if (killedPid !== null) {
|
|
91139
|
+
outcome.stopped = await waitForPidExit(killedPid, 15e3);
|
|
91140
|
+
if (!outcome.stopped) {
|
|
91141
|
+
outcome.survived = true;
|
|
91142
|
+
appendUpgradeLog(
|
|
91143
|
+
`Session-host pid ${killedPid} did not exit within 15000ms of the stop request.`,
|
|
91144
|
+
configDir
|
|
91145
|
+
);
|
|
91146
|
+
}
|
|
91147
|
+
} else if (outcome.pid !== null && outcome.identity !== "unrelated") {
|
|
91148
|
+
outcome.survived = isPidAlive(outcome.pid);
|
|
91149
|
+
}
|
|
91150
|
+
keepPidFile = outcome.survived;
|
|
91151
|
+
if (!keepPidFile) {
|
|
91259
91152
|
try {
|
|
91260
91153
|
fs20.unlinkSync(pidFile);
|
|
91261
91154
|
} catch {
|
|
91262
91155
|
}
|
|
91156
|
+
} else {
|
|
91157
|
+
appendUpgradeLog(
|
|
91158
|
+
`Keeping ${pidFile} so the remaining upgrade guards can still see the surviving host.`,
|
|
91159
|
+
configDir
|
|
91160
|
+
);
|
|
91263
91161
|
}
|
|
91264
|
-
|
|
91265
|
-
|
|
91162
|
+
return outcome;
|
|
91163
|
+
}
|
|
91164
|
+
function isPidAlive(pid) {
|
|
91165
|
+
try {
|
|
91166
|
+
process.kill(pid, 0);
|
|
91167
|
+
return true;
|
|
91168
|
+
} catch (error48) {
|
|
91169
|
+
return error48?.code === "EPERM";
|
|
91266
91170
|
}
|
|
91267
91171
|
}
|
|
91268
91172
|
var LOCKED_NATIVE_ADDON_BASENAMES = ["conpty.node", "ghostty-vt.dll"];
|
|
@@ -91506,7 +91410,17 @@ ${marker}`,
|
|
|
91506
91410
|
await waitForPidExit(payload.parentPid, 15e3);
|
|
91507
91411
|
}
|
|
91508
91412
|
if (process.platform === "win32" || payload.killSessionHost === true) {
|
|
91509
|
-
await stopSessionHostProcesses(sessionHostAppName);
|
|
91413
|
+
const hostStop = await stopSessionHostProcesses(sessionHostAppName);
|
|
91414
|
+
if (process.platform === "win32" && hostStop.survived && hostStop.pid !== null) {
|
|
91415
|
+
const message = `Cannot upgrade: the session-host process (pid ${hostStop.pid}) is still running and could not be stopped. Upgrading now would delete the install it is running from and break every new session.`;
|
|
91416
|
+
emitUpgradeFailureNotice([
|
|
91417
|
+
message,
|
|
91418
|
+
"To recover, stop it and retry the update:",
|
|
91419
|
+
` Stop-Process -Id ${hostStop.pid} -Force`,
|
|
91420
|
+
` ${IDENTITY.binaryName} update`
|
|
91421
|
+
], getConfigDir2(), { targetVersion: payload.targetVersion });
|
|
91422
|
+
throw new Error(message);
|
|
91423
|
+
}
|
|
91510
91424
|
} else {
|
|
91511
91425
|
appendUpgradeLog("POSIX \u2014 session-host left running (survives upgrade; sessions rebind on next boot)");
|
|
91512
91426
|
}
|
|
@@ -92664,7 +92578,7 @@ ${marker}`,
|
|
|
92664
92578
|
var os20 = __toESM2(require("os"));
|
|
92665
92579
|
var path35 = __toESM2(require("path"));
|
|
92666
92580
|
var crypto6 = __toESM2(require("crypto"));
|
|
92667
|
-
var
|
|
92581
|
+
var import_fs18 = require("fs");
|
|
92668
92582
|
var import_child_process11 = require("child_process");
|
|
92669
92583
|
var import_chalk = __toESM2((init_source(), __toCommonJS(source_exports)));
|
|
92670
92584
|
init_provider_cli_adapter();
|
|
@@ -101411,7 +101325,7 @@ ${rawInput}` : rawInput;
|
|
|
101411
101325
|
const trimmed = command.trim();
|
|
101412
101326
|
if (!trimmed) return false;
|
|
101413
101327
|
if (isExplicitCommand(trimmed)) {
|
|
101414
|
-
return (0,
|
|
101328
|
+
return (0, import_fs18.existsSync)(expandExecutable(trimmed));
|
|
101415
101329
|
}
|
|
101416
101330
|
try {
|
|
101417
101331
|
(0, import_child_process11.execFileSync)(process.platform === "win32" ? "where" : "which", [trimmed], {
|
|
@@ -101556,10 +101470,10 @@ ${rawInput}` : rawInput;
|
|
|
101556
101470
|
}
|
|
101557
101471
|
function ensureEmptyDelegatedMcpConfig(workspace) {
|
|
101558
101472
|
const baseDir = path35.join(os20.tmpdir(), "adhdev-delegated-agent-empty-mcp");
|
|
101559
|
-
(0,
|
|
101473
|
+
(0, import_fs18.mkdirSync)(baseDir, { recursive: true });
|
|
101560
101474
|
const workspaceHash = shortHash(path35.resolve(workspace || os20.tmpdir()));
|
|
101561
101475
|
const filePath = path35.join(baseDir, `${workspaceHash}.json`);
|
|
101562
|
-
(0,
|
|
101476
|
+
(0, import_fs18.writeFileSync)(filePath, JSON.stringify({ mcpServers: {} }, null, 2), "utf-8");
|
|
101563
101477
|
return filePath;
|
|
101564
101478
|
}
|
|
101565
101479
|
function buildCoordinatorDelegatedCliLaunchOptions(input) {
|
|
@@ -108884,7 +108798,7 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
108884
108798
|
normalizeRepoMeshDeclarativeConfig: normalizeRepoMeshDeclarativeConfig2,
|
|
108885
108799
|
MESH_JSON_CONFIG_LOCATIONS: MESH_JSON_CONFIG_LOCATIONS2
|
|
108886
108800
|
} = await Promise.resolve().then(() => (init_mesh_json_config(), mesh_json_config_exports));
|
|
108887
|
-
const { mkdirSync: mkdirSync29, writeFileSync:
|
|
108801
|
+
const { mkdirSync: mkdirSync29, writeFileSync: writeFileSync30 } = await import("fs");
|
|
108888
108802
|
const { dirname: dirname22, join: join62 } = await import("path");
|
|
108889
108803
|
const scaffold = buildMeshJsonConfigScaffold2(mesh);
|
|
108890
108804
|
const scaffoldJson = serializeMeshJsonConfigScaffold2(scaffold);
|
|
@@ -108926,7 +108840,7 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
108926
108840
|
};
|
|
108927
108841
|
}
|
|
108928
108842
|
mkdirSync29(dirname22(absolutePath), { recursive: true });
|
|
108929
|
-
|
|
108843
|
+
writeFileSync30(absolutePath, `${scaffoldJson}
|
|
108930
108844
|
`, "utf-8");
|
|
108931
108845
|
return {
|
|
108932
108846
|
success: true,
|
|
@@ -108995,7 +108909,7 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
108995
108909
|
normalizeRepoMeshDeclarativeConfig: normalizeRepoMeshDeclarativeConfig2,
|
|
108996
108910
|
MESH_JSON_CONFIG_LOCATIONS: MESH_JSON_CONFIG_LOCATIONS2
|
|
108997
108911
|
} = await Promise.resolve().then(() => (init_mesh_json_config(), mesh_json_config_exports));
|
|
108998
|
-
const { existsSync: existsSync62, readFileSync: readFileSync53, mkdirSync: mkdirSync29, writeFileSync:
|
|
108912
|
+
const { existsSync: existsSync62, readFileSync: readFileSync53, mkdirSync: mkdirSync29, writeFileSync: writeFileSync30 } = await import("fs");
|
|
108999
108913
|
const { dirname: dirname22, join: join62 } = await import("path");
|
|
109000
108914
|
const yaml6 = await Promise.resolve().then(() => (init_js_yaml(), js_yaml_exports));
|
|
109001
108915
|
const relativePath = MESH_JSON_CONFIG_LOCATIONS2[0];
|
|
@@ -109061,7 +108975,7 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
109061
108975
|
};
|
|
109062
108976
|
}
|
|
109063
108977
|
mkdirSync29(dirname22(absolutePath), { recursive: true });
|
|
109064
|
-
|
|
108978
|
+
writeFileSync30(absolutePath, serialized, "utf-8");
|
|
109065
108979
|
return {
|
|
109066
108980
|
success: true,
|
|
109067
108981
|
written: true,
|
|
@@ -109550,11 +109464,11 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
109550
109464
|
let node;
|
|
109551
109465
|
const { migrateProviderRolesToSlots: migrateProviderRolesToSlots2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
109552
109466
|
if (meshRecord.inline) {
|
|
109553
|
-
const { randomUUID:
|
|
109467
|
+
const { randomUUID: randomUUID17 } = await import("crypto");
|
|
109554
109468
|
const clonedPolicy = { ...sourceNode.policy || {} };
|
|
109555
109469
|
migrateProviderRolesToSlots2(clonedPolicy);
|
|
109556
109470
|
node = {
|
|
109557
|
-
id: `node_${
|
|
109471
|
+
id: `node_${randomUUID17().replace(/-/g, "")}`,
|
|
109558
109472
|
workspace: result.worktreePath,
|
|
109559
109473
|
repoRoot: result.worktreePath,
|
|
109560
109474
|
daemonId: sourceNode.daemonId,
|
|
@@ -110760,7 +110674,7 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
110760
110674
|
return { success: true };
|
|
110761
110675
|
}
|
|
110762
110676
|
};
|
|
110763
|
-
var
|
|
110677
|
+
var import_path16 = require("path");
|
|
110764
110678
|
var fs422 = __toESM2(require("fs"));
|
|
110765
110679
|
init_logger();
|
|
110766
110680
|
init_mesh_host_ownership();
|
|
@@ -111041,7 +110955,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
111041
110955
|
};
|
|
111042
110956
|
}
|
|
111043
110957
|
if (cliType === "codex-cli") {
|
|
111044
|
-
const repoMcpConfigPath = (0,
|
|
110958
|
+
const repoMcpConfigPath = (0, import_path16.join)(workspace, ".mcp.json");
|
|
111045
110959
|
if (fs422.existsSync(repoMcpConfigPath)) {
|
|
111046
110960
|
try {
|
|
111047
110961
|
const repoMcpConfig = parseMeshCoordinatorMcpConfig(
|
|
@@ -111194,7 +111108,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
111194
111108
|
workspace
|
|
111195
111109
|
};
|
|
111196
111110
|
}
|
|
111197
|
-
const { existsSync: existsSync62, readFileSync: readFileSync53, writeFileSync:
|
|
111111
|
+
const { existsSync: existsSync62, readFileSync: readFileSync53, writeFileSync: writeFileSync30, copyFileSync: copyFileSync3, mkdirSync: mkdirSync29 } = await import("fs");
|
|
111198
111112
|
const { dirname: dirname22 } = await import("path");
|
|
111199
111113
|
const mcpConfigPath = coordinatorSetup.configPath;
|
|
111200
111114
|
const hermesManualFallback = cliType === "hermes-cli" && configFormat === "hermes_config_yaml" ? createHermesManualMeshCoordinatorSetup(meshId, workspace) : null;
|
|
@@ -111269,7 +111183,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
111269
111183
|
}
|
|
111270
111184
|
};
|
|
111271
111185
|
try {
|
|
111272
|
-
|
|
111186
|
+
writeFileSync30(mcpConfigPath, serializeMeshCoordinatorMcpConfig(mcpConfig, configFormat), "utf-8");
|
|
111273
111187
|
} catch (error48) {
|
|
111274
111188
|
const message = `Could not write MCP config for automatic setup: ${error48?.message || error48}`;
|
|
111275
111189
|
LOG2.error("MeshCoordinator", message);
|
|
@@ -112448,7 +112362,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
112448
112362
|
init_git_status();
|
|
112449
112363
|
init_refine_config();
|
|
112450
112364
|
init_worktree_bootstrap_config();
|
|
112451
|
-
var
|
|
112365
|
+
var import_path17 = require("path");
|
|
112452
112366
|
var fs45 = __toESM2(require("fs"));
|
|
112453
112367
|
var import_node_child_process9 = require("child_process");
|
|
112454
112368
|
init_resolve_executable();
|
|
@@ -112474,13 +112388,13 @@ ${tail}`;
|
|
|
112474
112388
|
const missingDependencyFailure = !spawnResolutionFailed && !outputLimitExceeded && /Cannot find module|MODULE_NOT_FOUND|node_modules|command not found|not found/i.test(stderr);
|
|
112475
112389
|
return { outputLimitExceeded, missingDependencyFailure };
|
|
112476
112390
|
}
|
|
112477
|
-
var REFINE_VALIDATION_LOG_DIR = (0,
|
|
112391
|
+
var REFINE_VALIDATION_LOG_DIR = (0, import_path17.join)(".adhdev", "logs");
|
|
112478
112392
|
function writeValidationFailureLog(workspace, index, candidate, streams, now = () => /* @__PURE__ */ new Date()) {
|
|
112479
112393
|
try {
|
|
112480
|
-
const dir = (0,
|
|
112394
|
+
const dir = (0, import_path17.join)(workspace, REFINE_VALIDATION_LOG_DIR);
|
|
112481
112395
|
fs45.mkdirSync(dir, { recursive: true });
|
|
112482
112396
|
const stamp = now().toISOString().replace(/[:.]/g, "-");
|
|
112483
|
-
const file2 = (0,
|
|
112397
|
+
const file2 = (0, import_path17.join)(dir, `refine-${stamp}-${index}.log`);
|
|
112484
112398
|
const asText = (v) => typeof v === "string" ? v : v == null ? "" : String(v);
|
|
112485
112399
|
const shown = candidate.displayCommand || [candidate.command, ...candidate.args || []].join(" ");
|
|
112486
112400
|
fs45.writeFileSync(
|
|
@@ -112724,7 +112638,7 @@ ${e?.stderr || ""}`
|
|
|
112724
112638
|
} catch {
|
|
112725
112639
|
continue;
|
|
112726
112640
|
}
|
|
112727
|
-
const submoduleRepo = (0,
|
|
112641
|
+
const submoduleRepo = (0, import_path17.join)(repoRoot, p);
|
|
112728
112642
|
let fastForward;
|
|
112729
112643
|
let reachableFromOriginMain;
|
|
112730
112644
|
if (branchCommit) {
|
|
@@ -113031,7 +112945,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
113031
112945
|
const baseCommit = readTreeObject(repoRoot, baseHead, path54);
|
|
113032
112946
|
const branchCommit = readTreeObject(repoRoot, branchHead, path54);
|
|
113033
112947
|
if (!baseCommit || !branchCommit) return false;
|
|
113034
|
-
return isSubmoduleFastForward((0,
|
|
112948
|
+
return isSubmoduleFastForward((0, import_path17.resolve)(repoRoot, path54), baseCommit, branchCommit);
|
|
113035
112949
|
});
|
|
113036
112950
|
}
|
|
113037
112951
|
function collectTrivialFastForwardGitlinkResolutions(worktreeRoot, baseRepoRoot, baseHead, branchHead) {
|
|
@@ -113040,8 +112954,8 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
113040
112954
|
const baseCommit = readTreeObject(baseRepoRoot, baseHead, path54);
|
|
113041
112955
|
const branchCommit = readTreeObject(worktreeRoot, branchHead, path54);
|
|
113042
112956
|
if (!baseCommit || !branchCommit) continue;
|
|
113043
|
-
const submoduleRepoPath = (0,
|
|
113044
|
-
ensureSubmoduleCommitLocal(submoduleRepoPath, (0,
|
|
112957
|
+
const submoduleRepoPath = (0, import_path17.resolve)(worktreeRoot, path54);
|
|
112958
|
+
ensureSubmoduleCommitLocal(submoduleRepoPath, (0, import_path17.resolve)(baseRepoRoot, path54), baseCommit);
|
|
113045
112959
|
if (baseCommit === branchCommit) {
|
|
113046
112960
|
continue;
|
|
113047
112961
|
}
|
|
@@ -113106,9 +113020,9 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
113106
113020
|
for (const path54 of changed) {
|
|
113107
113021
|
const baseCommit = readTreeObject(baseRepoRoot, baseHead, path54);
|
|
113108
113022
|
const branchCommit = readTreeObject(worktreeRoot, branchHead, path54);
|
|
113109
|
-
const submoduleRepoPath = (0,
|
|
113023
|
+
const submoduleRepoPath = (0, import_path17.resolve)(worktreeRoot, path54);
|
|
113110
113024
|
if (baseCommit) {
|
|
113111
|
-
ensureSubmoduleCommitLocal(submoduleRepoPath, (0,
|
|
113025
|
+
ensureSubmoduleCommitLocal(submoduleRepoPath, (0, import_path17.resolve)(baseRepoRoot, path54), baseCommit);
|
|
113112
113026
|
}
|
|
113113
113027
|
if (!baseCommit || !branchCommit || !isSubmoduleDivergedSibling(submoduleRepoPath, baseCommit, branchCommit)) {
|
|
113114
113028
|
gitlinks.push({ path: path54, baseCommit, branchCommit, action: "skipped_not_diverged" });
|
|
@@ -113222,7 +113136,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
113222
113136
|
for (const p of conflicts) {
|
|
113223
113137
|
const commit = resolveByPath.get(p);
|
|
113224
113138
|
try {
|
|
113225
|
-
(0, import_node_child_process9.execFileSync)(GIT3, ["checkout", "-q", "--detach", commit], { cwd: (0,
|
|
113139
|
+
(0, import_node_child_process9.execFileSync)(GIT3, ["checkout", "-q", "--detach", commit], { cwd: (0, import_path17.resolve)(worktreeRoot, p), stdio: "ignore" });
|
|
113226
113140
|
} catch {
|
|
113227
113141
|
}
|
|
113228
113142
|
try {
|
|
@@ -113244,7 +113158,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
113244
113158
|
const changedGitlinks = readChangedGitlinkPaths(repoRoot, baseHead, branchHead).map((path54) => {
|
|
113245
113159
|
const baseCommit = readTreeObject(repoRoot, baseHead, path54);
|
|
113246
113160
|
const branchCommit = readTreeObject(repoRoot, branchHead, path54);
|
|
113247
|
-
const submoduleRepoPath = (0,
|
|
113161
|
+
const submoduleRepoPath = (0, import_path17.resolve)(repoRoot, path54);
|
|
113248
113162
|
const fastForward = !!baseCommit && !!branchCommit && isSubmoduleFastForward(submoduleRepoPath, baseCommit, branchCommit);
|
|
113249
113163
|
return { path: path54, baseCommit, branchCommit, fastForward };
|
|
113250
113164
|
});
|
|
@@ -113299,7 +113213,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
113299
113213
|
if (!tree) return void 0;
|
|
113300
113214
|
const updates = paths.map((path54) => `160000 commit ${placeholderCommit} ${path54}`).join("\n");
|
|
113301
113215
|
if (!updates) return tree;
|
|
113302
|
-
const tmpIndex = (0,
|
|
113216
|
+
const tmpIndex = (0, import_path17.join)(resolveGitDir(repoRoot), `adhdev-refine-eq-${commitish.slice(0, 12)}.index`);
|
|
113303
113217
|
const env2 = { ...process.env, GIT_INDEX_FILE: tmpIndex };
|
|
113304
113218
|
try {
|
|
113305
113219
|
(0, import_node_child_process9.execFileSync)(GIT3, ["read-tree", tree], { cwd: repoRoot, env: env2, stdio: "ignore" });
|
|
@@ -113374,7 +113288,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
113374
113288
|
if (!contentTree) return void 0;
|
|
113375
113289
|
const updates = branchGitlinks.map((entry) => `160000 commit ${entry.branchCommit} ${entry.path}`).join("\n");
|
|
113376
113290
|
if (!updates) return contentTree;
|
|
113377
|
-
const tmpIndex = (0,
|
|
113291
|
+
const tmpIndex = (0, import_path17.join)(resolveGitDir(repoRoot), `adhdev-refine-ff-${baseHead.slice(0, 12)}-${branchHead.slice(0, 12)}.index`);
|
|
113378
113292
|
const env2 = { ...process.env, GIT_INDEX_FILE: tmpIndex };
|
|
113379
113293
|
try {
|
|
113380
113294
|
(0, import_node_child_process9.execFileSync)(GIT3, ["read-tree", contentTree], { cwd: repoRoot, env: env2, stdio: "ignore" });
|
|
@@ -113518,7 +113432,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
113518
113432
|
return match ? { commit: match[1], path: match[2] } : null;
|
|
113519
113433
|
}).filter((entry) => !!entry);
|
|
113520
113434
|
for (const gitlink of gitlinks) {
|
|
113521
|
-
const submodulePath = (0,
|
|
113435
|
+
const submodulePath = (0, import_path17.resolve)(repoRoot, gitlink.path);
|
|
113522
113436
|
const entry = {
|
|
113523
113437
|
path: gitlink.path,
|
|
113524
113438
|
commit: gitlink.commit,
|
|
@@ -113547,7 +113461,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
113547
113461
|
try {
|
|
113548
113462
|
const imported = await importCommitFromWorktreeSubmodule(
|
|
113549
113463
|
submodulePath,
|
|
113550
|
-
(0,
|
|
113464
|
+
(0, import_path17.resolve)(options.worktreeRoot, gitlink.path),
|
|
113551
113465
|
gitlink.commit
|
|
113552
113466
|
);
|
|
113553
113467
|
if (imported) {
|
|
@@ -113767,13 +113681,13 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
113767
113681
|
...extras
|
|
113768
113682
|
});
|
|
113769
113683
|
const isPackageManagerValidation = (candidate) => {
|
|
113770
|
-
const command = (0,
|
|
113684
|
+
const command = (0, import_path17.basename)(candidate.command).replace(/\.(?:cmd|exe)$/i, "");
|
|
113771
113685
|
return ["npm", "pnpm", "yarn", "bun"].includes(command) && candidate.args.some((arg) => arg === "run" || arg === "test" || arg === "exec");
|
|
113772
113686
|
};
|
|
113773
113687
|
const dependenciesLikelyMissing = (cwd) => {
|
|
113774
|
-
if (!fs45.existsSync((0,
|
|
113775
|
-
if (fs45.existsSync((0,
|
|
113776
|
-
return ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lockb", "bun.lock"].some((lock) => fs45.existsSync((0,
|
|
113688
|
+
if (!fs45.existsSync((0, import_path17.join)(cwd, "package.json"))) return false;
|
|
113689
|
+
if (fs45.existsSync((0, import_path17.join)(cwd, "node_modules"))) return false;
|
|
113690
|
+
return ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lockb", "bun.lock"].some((lock) => fs45.existsSync((0, import_path17.join)(cwd, lock)));
|
|
113777
113691
|
};
|
|
113778
113692
|
const needsNodeModules = (candidate, cwd) => isPackageManagerValidation(candidate) && dependenciesLikelyMissing(cwd);
|
|
113779
113693
|
const isDaemonScopedCommand = (candidate) => {
|
|
@@ -113840,7 +113754,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
113840
113754
|
summary.bootstrap = { stage: "legacy" };
|
|
113841
113755
|
for (const candidate of selection.bootstrapCommands) {
|
|
113842
113756
|
const startedAt = Date.now();
|
|
113843
|
-
const cwd = candidate.cwd ? (0,
|
|
113757
|
+
const cwd = candidate.cwd ? (0, import_path17.resolve)(workspace, candidate.cwd) : workspace;
|
|
113844
113758
|
const timeout = candidate.timeoutMs || REFINE_VALIDATION_TIMEOUT_MS;
|
|
113845
113759
|
const resolvedCommand = resolveWin32Executable(candidate.command);
|
|
113846
113760
|
const spawn7 = buildWin32ExecFileSpawn(resolvedCommand, candidate.args);
|
|
@@ -113873,7 +113787,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
113873
113787
|
let missingDepsBlocked = false;
|
|
113874
113788
|
for (const candidate of commandsToRun) {
|
|
113875
113789
|
const startedAt = Date.now();
|
|
113876
|
-
const cwd = candidate.cwd ? (0,
|
|
113790
|
+
const cwd = candidate.cwd ? (0, import_path17.resolve)(workspace, candidate.cwd) : workspace;
|
|
113877
113791
|
const timeout = candidate.timeoutMs || REFINE_VALIDATION_TIMEOUT_MS;
|
|
113878
113792
|
const bootstrapProvidedDependencies = summary.bootstrap?.stage === "cached" || summary.bootstrap?.stage === "ran" || summary.bootstrap?.stage === "legacy";
|
|
113879
113793
|
if (!bootstrapProvidedDependencies && needsNodeModules(candidate, cwd)) {
|
|
@@ -115878,7 +115792,7 @@ ${e?.stderr || ""}`;
|
|
|
115878
115792
|
}
|
|
115879
115793
|
var fs46 = __toESM2(require("fs"));
|
|
115880
115794
|
var import_node_os2 = require("os");
|
|
115881
|
-
var
|
|
115795
|
+
var import_path18 = require("path");
|
|
115882
115796
|
init_logger();
|
|
115883
115797
|
init_dist();
|
|
115884
115798
|
init_mesh_node_identity();
|
|
@@ -115888,7 +115802,7 @@ ${e?.stderr || ""}`;
|
|
|
115888
115802
|
function acceptableManagedWorktreePaths(resolveWorktreePath2, normalizePath2, repoRoot, meshName, branch, worktreeBaseDir) {
|
|
115889
115803
|
const safeBranch = branch.replace(/[/\\:*?"<>|]/g, "-").replace(/^\.+|\.+$/g, "");
|
|
115890
115804
|
const safeMeshName = meshName.replace(/[/\\:*?"<>|]/g, "-").replace(/^\.+|\.+$/g, "");
|
|
115891
|
-
const legacyPath = (0,
|
|
115805
|
+
const legacyPath = (0, import_path18.join)((0, import_path18.dirname)(repoRoot), LEGACY_WORKTREE_DIR_NAME, safeMeshName, safeBranch);
|
|
115892
115806
|
const candidates = [
|
|
115893
115807
|
resolveWorktreePath2(repoRoot, meshName, branch, worktreeBaseDir),
|
|
115894
115808
|
legacyPath
|
|
@@ -115912,8 +115826,8 @@ ${e?.stderr || ""}`;
|
|
|
115912
115826
|
function looksLikeCrossTrackWorktreePath(actualPath, normalizePath2) {
|
|
115913
115827
|
const home = normalizePath2((0, import_node_os2.homedir)());
|
|
115914
115828
|
return TRACK_CONFIG_DIR_NAMES.some((trackDirName) => {
|
|
115915
|
-
const trackWorktreesDir = (0,
|
|
115916
|
-
return actualPath === normalizePath2(trackWorktreesDir) || actualPath.startsWith(normalizePath2(trackWorktreesDir) +
|
|
115829
|
+
const trackWorktreesDir = (0, import_path18.join)(home, trackDirName, "worktrees");
|
|
115830
|
+
return actualPath === normalizePath2(trackWorktreesDir) || actualPath.startsWith(normalizePath2(trackWorktreesDir) + import_path18.sep);
|
|
115917
115831
|
});
|
|
115918
115832
|
}
|
|
115919
115833
|
function unexpectedPathRecoveryHint(actualPath, normalizePath2, suffix) {
|
|
@@ -115983,7 +115897,7 @@ ${e?.stderr || ""}`;
|
|
|
115983
115897
|
}
|
|
115984
115898
|
const { resolveWorktreePath: resolveWorktreePath2, listWorktrees: listWorktrees2 } = await Promise.resolve().then(() => (init_git_worktree(), git_worktree_exports));
|
|
115985
115899
|
const normalizePath2 = (value) => {
|
|
115986
|
-
const resolved = (0,
|
|
115900
|
+
const resolved = (0, import_path18.resolve)(value);
|
|
115987
115901
|
try {
|
|
115988
115902
|
return fs46.realpathSync(resolved);
|
|
115989
115903
|
} catch {
|
|
@@ -116079,7 +115993,7 @@ ${e?.stderr || ""}`;
|
|
|
116079
115993
|
}
|
|
116080
115994
|
const { resolveWorktreePath: resolveWorktreePath2, listWorktrees: listWorktrees2, removeWorktree: removeWorktree2 } = await Promise.resolve().then(() => (init_git_worktree(), git_worktree_exports));
|
|
116081
115995
|
const normalizePath2 = (value) => {
|
|
116082
|
-
const resolved = (0,
|
|
115996
|
+
const resolved = (0, import_path18.resolve)(value);
|
|
116083
115997
|
try {
|
|
116084
115998
|
return fs46.realpathSync(resolved);
|
|
116085
115999
|
} catch {
|
|
@@ -116719,7 +116633,7 @@ ${e?.stderr || ""}`;
|
|
|
116719
116633
|
init_logger();
|
|
116720
116634
|
var yaml5 = __toESM2(require_js_yaml());
|
|
116721
116635
|
var import_os5 = require("os");
|
|
116722
|
-
var
|
|
116636
|
+
var import_path19 = require("path");
|
|
116723
116637
|
var fs47 = __toESM2(require("fs"));
|
|
116724
116638
|
var MESH_COORDINATOR_AUTO_IMPORT_FORMATS = ["claude_mcp_json", "hermes_config_yaml", "opencode_json"];
|
|
116725
116639
|
function isSupportedMeshCoordinatorConfigFormat(format) {
|
|
@@ -116760,13 +116674,13 @@ ${e?.stderr || ""}`;
|
|
|
116760
116674
|
}
|
|
116761
116675
|
function resolveHermesUserHome() {
|
|
116762
116676
|
const explicitHome = process.env.HERMES_HOME?.trim();
|
|
116763
|
-
return explicitHome || (0,
|
|
116677
|
+
return explicitHome || (0, import_path19.join)((0, import_os5.homedir)(), ".hermes");
|
|
116764
116678
|
}
|
|
116765
116679
|
function loadHermesCoordinatorBaseConfig(targetConfigPath) {
|
|
116766
116680
|
const sourceHome = resolveHermesUserHome();
|
|
116767
|
-
const sourceConfigPath = (0,
|
|
116681
|
+
const sourceConfigPath = (0, import_path19.join)(sourceHome, "config.yaml");
|
|
116768
116682
|
if (!fs47.existsSync(sourceConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
116769
|
-
if ((0,
|
|
116683
|
+
if ((0, import_path19.resolve)(sourceConfigPath) === (0, import_path19.resolve)(targetConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
116770
116684
|
const parsed = parseMeshCoordinatorMcpConfig(fs47.readFileSync(sourceConfigPath, "utf-8"), "hermes_config_yaml");
|
|
116771
116685
|
const { mcp_servers: _mcpServers, ...baseConfig } = parsed;
|
|
116772
116686
|
return { config: baseConfig, sourceHome, sourceConfigPath };
|
|
@@ -116800,10 +116714,10 @@ ${e?.stderr || ""}`;
|
|
|
116800
116714
|
return sanitized;
|
|
116801
116715
|
}
|
|
116802
116716
|
function copyHermesCoordinatorCredentialFiles(sourceHome, targetHome) {
|
|
116803
|
-
if ((0,
|
|
116717
|
+
if ((0, import_path19.resolve)(sourceHome) === (0, import_path19.resolve)(targetHome)) return;
|
|
116804
116718
|
for (const fileName of [".env", "auth.json"]) {
|
|
116805
|
-
const sourcePath = (0,
|
|
116806
|
-
const targetPath = (0,
|
|
116719
|
+
const sourcePath = (0, import_path19.join)(sourceHome, fileName);
|
|
116720
|
+
const targetPath = (0, import_path19.join)(targetHome, fileName);
|
|
116807
116721
|
if (!fs47.existsSync(sourcePath)) continue;
|
|
116808
116722
|
try {
|
|
116809
116723
|
fs47.copyFileSync(sourcePath, targetPath);
|
|
@@ -121811,7 +121725,7 @@ async (params) => {
|
|
|
121811
121725
|
const pid = ctx.autoImplProcess?.pid;
|
|
121812
121726
|
return typeof pid === "number" && pid > 0 ? pid : null;
|
|
121813
121727
|
}
|
|
121814
|
-
function
|
|
121728
|
+
function isPidAlive2(pid) {
|
|
121815
121729
|
try {
|
|
121816
121730
|
process.kill(pid, 0);
|
|
121817
121731
|
return true;
|
|
@@ -121822,7 +121736,7 @@ async (params) => {
|
|
|
121822
121736
|
function clearStaleAutoImplState(ctx, reason) {
|
|
121823
121737
|
if (!ctx.autoImplStatus.running && !ctx.autoImplProcess) return;
|
|
121824
121738
|
const pid = getAutoImplPid(ctx);
|
|
121825
|
-
if (pid &&
|
|
121739
|
+
if (pid && isPidAlive2(pid)) return;
|
|
121826
121740
|
ctx.log(`Clearing stale auto-implement state: ${reason}${pid ? ` (pid ${pid})` : ""}`);
|
|
121827
121741
|
ctx.autoImplProcess = null;
|
|
121828
121742
|
ctx.autoImplStatus.running = false;
|
|
@@ -124986,7 +124900,7 @@ data: ${JSON.stringify(msg.data)}
|
|
|
124986
124900
|
}
|
|
124987
124901
|
}
|
|
124988
124902
|
}
|
|
124989
|
-
function
|
|
124903
|
+
function isPidAlive3(pid) {
|
|
124990
124904
|
try {
|
|
124991
124905
|
process.kill(pid, 0);
|
|
124992
124906
|
return true;
|
|
@@ -125007,7 +124921,7 @@ data: ${JSON.stringify(msg.data)}
|
|
|
125007
124921
|
stopped = killPid(pid) || stopped;
|
|
125008
124922
|
}
|
|
125009
124923
|
const provenUnrelated = !managed && options.identifiesPid?.(pid) === true;
|
|
125010
|
-
keepPidFile = !provenUnrelated &&
|
|
124924
|
+
keepPidFile = !provenUnrelated && isPidAlive3(pid);
|
|
125011
124925
|
if (keepPidFile) {
|
|
125012
124926
|
LOG2.warn(
|
|
125013
124927
|
"SessionHost",
|
|
@@ -125030,6 +124944,39 @@ data: ${JSON.stringify(msg.data)}
|
|
|
125030
124944
|
}
|
|
125031
124945
|
return stopped;
|
|
125032
124946
|
}
|
|
124947
|
+
async function stopHostRunningFromForeignEntry() {
|
|
124948
|
+
let currentEntry;
|
|
124949
|
+
try {
|
|
124950
|
+
currentEntry = resolveEntry();
|
|
124951
|
+
} catch {
|
|
124952
|
+
return;
|
|
124953
|
+
}
|
|
124954
|
+
const client = new import_session_host_core15.SessionHostClient({ endpoint: getEndpoint() });
|
|
124955
|
+
let reported;
|
|
124956
|
+
try {
|
|
124957
|
+
await client.connect();
|
|
124958
|
+
const response = await client.request({
|
|
124959
|
+
type: "get_host_diagnostics",
|
|
124960
|
+
payload: { includeSessions: false }
|
|
124961
|
+
});
|
|
124962
|
+
if (!response.success || !response.result) return;
|
|
124963
|
+
const value = response.result.hostEntryPath;
|
|
124964
|
+
reported = typeof value === "string" && value.trim() ? value : void 0;
|
|
124965
|
+
} catch {
|
|
124966
|
+
return;
|
|
124967
|
+
} finally {
|
|
124968
|
+
await client.close().catch(() => {
|
|
124969
|
+
});
|
|
124970
|
+
}
|
|
124971
|
+
if (!reported) return;
|
|
124972
|
+
if (pathsEquivalent(reported, currentEntry)) return;
|
|
124973
|
+
const reportedExists = fs54.existsSync(reported);
|
|
124974
|
+
LOG2.warn(
|
|
124975
|
+
"SessionHost",
|
|
124976
|
+
`Reachable session-host reports it is running from ${reported}${reportedExists ? "" : " (which no longer exists)"}, but this install runs from ${currentEntry}. That host would fail every create_session loading node-pty from its own prefix; stopping it so a current one is spawned in its place.`
|
|
124977
|
+
);
|
|
124978
|
+
stopManagedSessionHostProcess();
|
|
124979
|
+
}
|
|
125033
124980
|
async function ensureReady() {
|
|
125034
124981
|
options.beforeEnsureReady?.();
|
|
125035
124982
|
if (process.platform === "win32") {
|
|
@@ -125060,6 +125007,9 @@ data: ${JSON.stringify(msg.data)}
|
|
|
125060
125007
|
}
|
|
125061
125008
|
}
|
|
125062
125009
|
}
|
|
125010
|
+
if (process.platform === "win32") {
|
|
125011
|
+
await stopHostRunningFromForeignEntry();
|
|
125012
|
+
}
|
|
125063
125013
|
if (process.platform === "win32") {
|
|
125064
125014
|
try {
|
|
125065
125015
|
verifyConptyPrebuildBeforeSpawn(resolveEntry());
|
|
@@ -125393,6 +125343,136 @@ data: ${JSON.stringify(msg.data)}
|
|
|
125393
125343
|
init_config();
|
|
125394
125344
|
init_mesh_events();
|
|
125395
125345
|
init_mesh_reconcile_loop();
|
|
125346
|
+
var import_fs19 = require("fs");
|
|
125347
|
+
var import_path20 = require("path");
|
|
125348
|
+
var import_crypto14 = require("crypto");
|
|
125349
|
+
init_logger();
|
|
125350
|
+
init_mesh_ledger();
|
|
125351
|
+
init_mesh_runtime_store();
|
|
125352
|
+
init_mesh_events_pending();
|
|
125353
|
+
var PENDING_EVENTS_SUFFIX = ".pending-events.jsonl";
|
|
125354
|
+
function isPendingEventsFile(name) {
|
|
125355
|
+
return name.endsWith(PENDING_EVENTS_SUFFIX) && name.length > PENDING_EVENTS_SUFFIX.length;
|
|
125356
|
+
}
|
|
125357
|
+
function parsePendingEventsFile(content) {
|
|
125358
|
+
const events = [];
|
|
125359
|
+
let skipped = 0;
|
|
125360
|
+
for (const line of content.split("\n")) {
|
|
125361
|
+
if (!line.trim()) continue;
|
|
125362
|
+
let parsed;
|
|
125363
|
+
try {
|
|
125364
|
+
parsed = JSON.parse(line);
|
|
125365
|
+
} catch {
|
|
125366
|
+
skipped++;
|
|
125367
|
+
continue;
|
|
125368
|
+
}
|
|
125369
|
+
const event = parsed;
|
|
125370
|
+
if (!event || typeof event !== "object" || typeof event.meshId !== "string" || !event.meshId || typeof event.event !== "string" || !event.event) {
|
|
125371
|
+
skipped++;
|
|
125372
|
+
continue;
|
|
125373
|
+
}
|
|
125374
|
+
events.push(event);
|
|
125375
|
+
}
|
|
125376
|
+
return { events, skipped };
|
|
125377
|
+
}
|
|
125378
|
+
function importOneEvent(event) {
|
|
125379
|
+
try {
|
|
125380
|
+
const fingerprint = buildPendingEventFingerprint(event);
|
|
125381
|
+
MeshRuntimeStore.getInstance().insertPendingEvent({
|
|
125382
|
+
id: (0, import_crypto14.randomUUID)(),
|
|
125383
|
+
meshId: event.meshId,
|
|
125384
|
+
coordinatorDaemonId: event.targetCoordinatorDaemonId ?? null,
|
|
125385
|
+
event: event.event,
|
|
125386
|
+
payload: event,
|
|
125387
|
+
fingerprint: fingerprint || null,
|
|
125388
|
+
queuedAt: typeof event.queuedAt === "number" ? event.queuedAt : Date.now(),
|
|
125389
|
+
protocolVersion: event.protocolVersion ?? null,
|
|
125390
|
+
eventId: event.eventId ?? null,
|
|
125391
|
+
scope: event.scope ?? null,
|
|
125392
|
+
dispatchedBy: event.dispatchedBy ? JSON.stringify(event.dispatchedBy) : null,
|
|
125393
|
+
intendedFor: event.intendedFor ? JSON.stringify(event.intendedFor) : null
|
|
125394
|
+
});
|
|
125395
|
+
return true;
|
|
125396
|
+
} catch (e) {
|
|
125397
|
+
LOG2.warn("MeshEvents", `Pending-events migration: failed to import ${event.event} for mesh ${event.meshId}: ${e?.message || e}`);
|
|
125398
|
+
return false;
|
|
125399
|
+
}
|
|
125400
|
+
}
|
|
125401
|
+
function migratePendingEventsJsonlToSqlite() {
|
|
125402
|
+
const result = {
|
|
125403
|
+
filesScanned: 0,
|
|
125404
|
+
eventsImported: 0,
|
|
125405
|
+
linesSkipped: 0,
|
|
125406
|
+
filesRemoved: 0,
|
|
125407
|
+
filesRetained: 0
|
|
125408
|
+
};
|
|
125409
|
+
let dir;
|
|
125410
|
+
try {
|
|
125411
|
+
dir = getLedgerDir2();
|
|
125412
|
+
} catch {
|
|
125413
|
+
return result;
|
|
125414
|
+
}
|
|
125415
|
+
if (!(0, import_fs19.existsSync)(dir)) return result;
|
|
125416
|
+
let names;
|
|
125417
|
+
try {
|
|
125418
|
+
names = (0, import_fs19.readdirSync)(dir);
|
|
125419
|
+
} catch (e) {
|
|
125420
|
+
LOG2.warn("MeshEvents", `Pending-events migration: cannot read ledger dir: ${e?.message || e}`);
|
|
125421
|
+
return result;
|
|
125422
|
+
}
|
|
125423
|
+
for (const name of names) {
|
|
125424
|
+
if (!isPendingEventsFile(name)) continue;
|
|
125425
|
+
const path54 = (0, import_path20.join)(dir, name);
|
|
125426
|
+
result.filesScanned++;
|
|
125427
|
+
const claimed = `${path54}.migrating`;
|
|
125428
|
+
try {
|
|
125429
|
+
(0, import_fs19.renameSync)(path54, claimed);
|
|
125430
|
+
} catch {
|
|
125431
|
+
continue;
|
|
125432
|
+
}
|
|
125433
|
+
let content;
|
|
125434
|
+
try {
|
|
125435
|
+
content = (0, import_fs19.readFileSync)(claimed, "utf-8");
|
|
125436
|
+
} catch (e) {
|
|
125437
|
+
LOG2.warn("MeshEvents", `Pending-events migration: cannot read ${name}; leaving it for the next boot: ${e?.message || e}`);
|
|
125438
|
+
try {
|
|
125439
|
+
(0, import_fs19.renameSync)(claimed, path54);
|
|
125440
|
+
} catch {
|
|
125441
|
+
}
|
|
125442
|
+
result.filesRetained++;
|
|
125443
|
+
continue;
|
|
125444
|
+
}
|
|
125445
|
+
const { events, skipped } = parsePendingEventsFile(content);
|
|
125446
|
+
result.linesSkipped += skipped;
|
|
125447
|
+
let allImported = true;
|
|
125448
|
+
for (const event of events) {
|
|
125449
|
+
if (importOneEvent(event)) result.eventsImported++;
|
|
125450
|
+
else allImported = false;
|
|
125451
|
+
}
|
|
125452
|
+
if (!allImported) {
|
|
125453
|
+
try {
|
|
125454
|
+
(0, import_fs19.renameSync)(claimed, path54);
|
|
125455
|
+
} catch {
|
|
125456
|
+
}
|
|
125457
|
+
result.filesRetained++;
|
|
125458
|
+
continue;
|
|
125459
|
+
}
|
|
125460
|
+
try {
|
|
125461
|
+
(0, import_fs19.unlinkSync)(claimed);
|
|
125462
|
+
result.filesRemoved++;
|
|
125463
|
+
} catch (e) {
|
|
125464
|
+
LOG2.warn("MeshEvents", `Pending-events migration: imported ${name} but could not unlink it: ${e?.message || e}`);
|
|
125465
|
+
result.filesRemoved++;
|
|
125466
|
+
}
|
|
125467
|
+
}
|
|
125468
|
+
if (result.filesScanned > 0) {
|
|
125469
|
+
LOG2.info(
|
|
125470
|
+
"MeshEvents",
|
|
125471
|
+
`Pending-events JSONL migration: imported ${result.eventsImported} event(s) from ${result.filesScanned} legacy file(s) (removed ${result.filesRemoved}, retained ${result.filesRetained}, skipped ${result.linesSkipped} unreadable line(s))`
|
|
125472
|
+
);
|
|
125473
|
+
}
|
|
125474
|
+
return result;
|
|
125475
|
+
}
|
|
125396
125476
|
init_refresh();
|
|
125397
125477
|
init_mesh_runtime_store();
|
|
125398
125478
|
init_coordinator_registry();
|
|
@@ -125694,6 +125774,10 @@ ${upgradeFailureNotice.notice}${supersededHint}`);
|
|
|
125694
125774
|
statusInstanceId: config2.statusInstanceId
|
|
125695
125775
|
};
|
|
125696
125776
|
setupMeshEventForwarding(components);
|
|
125777
|
+
try {
|
|
125778
|
+
migratePendingEventsJsonlToSqlite();
|
|
125779
|
+
} catch {
|
|
125780
|
+
}
|
|
125697
125781
|
components.meshReconcileLoop = setupMeshReconcileLoop(components);
|
|
125698
125782
|
components.quotaRefreshLoop = setupQuotaRefreshLoop(components);
|
|
125699
125783
|
components.quotaEventRefresh = setupQuotaEventRefresh(components);
|