@adhdev/daemon-standalone 1.0.58-rc.28 → 1.0.58-rc.29
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 +1016 -384
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -36885,10 +36885,10 @@ var require_dist3 = __commonJS({
|
|
|
36885
36885
|
}
|
|
36886
36886
|
function getDaemonBuildInfo() {
|
|
36887
36887
|
if (cached2) return cached2;
|
|
36888
|
-
const commit = readInjected(true ? "
|
|
36889
|
-
const commitShort = readInjected(true ? "
|
|
36890
|
-
const version2 = readInjected(true ? "1.0.58-rc.
|
|
36891
|
-
const builtAt = readInjected(true ? "2026-08-
|
|
36888
|
+
const commit = readInjected(true ? "e767bd9b61dce1fd657b98aae517e9c405bdcb92" : void 0) ?? "unknown";
|
|
36889
|
+
const commitShort = readInjected(true ? "e767bd9b" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
|
|
36890
|
+
const version2 = readInjected(true ? "1.0.58-rc.29" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
|
|
36891
|
+
const builtAt = readInjected(true ? "2026-08-27T16:04:41.136Z" : void 0);
|
|
36892
36892
|
cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
|
|
36893
36893
|
return cached2;
|
|
36894
36894
|
}
|
|
@@ -38287,11 +38287,11 @@ var require_dist3 = __commonJS({
|
|
|
38287
38287
|
const override = env2.ADHDEV_CONFIG_DIR;
|
|
38288
38288
|
if (!override || !override.trim()) return false;
|
|
38289
38289
|
const sibling = otherTrackConfigDir(env2, homeDir2);
|
|
38290
|
-
const
|
|
38290
|
+
const normalize7 = (p) => {
|
|
38291
38291
|
const unified = p.trim().replace(/[\\/]+$/, "").replace(/\\/g, "/");
|
|
38292
38292
|
return platform11 === "win32" ? unified.toLowerCase() : unified;
|
|
38293
38293
|
};
|
|
38294
|
-
return
|
|
38294
|
+
return normalize7(override) === normalize7(sibling);
|
|
38295
38295
|
}
|
|
38296
38296
|
function configDirChannelMismatch(resolvedConfigDir, resolvedChannel, hasExplicitChannelSignal) {
|
|
38297
38297
|
if (hasExplicitChannelSignal) return null;
|
|
@@ -40012,7 +40012,7 @@ child.on('exit', () => process.exit(0));
|
|
|
40012
40012
|
};
|
|
40013
40013
|
}
|
|
40014
40014
|
function buildWrapperCommand(wrapperFile) {
|
|
40015
|
-
return `node ${
|
|
40015
|
+
return `node "${wrapperFile}"`;
|
|
40016
40016
|
}
|
|
40017
40017
|
function readBackup(file2) {
|
|
40018
40018
|
const result = readJsonFile(file2);
|
|
@@ -51012,6 +51012,14 @@ The instruction it carried was never delivered to anyone. If it still matters, r
|
|
|
51012
51012
|
// 30 d
|
|
51013
51013
|
TOMBSTONE_RETAIN_MS: 3456e7,
|
|
51014
51014
|
// 400 d
|
|
51015
|
+
// sync_hot rate window (extension per proposals-v3.5 P24): served+applied
|
|
51016
|
+
// sync bytes reaching SYNC_HOT_BYTES within one SYNC_HOT_WINDOW_MS window
|
|
51017
|
+
// emits one informational sync_hot anomaly (at most one per window).
|
|
51018
|
+
// Observation only — never a throttle: the traffic it flags is normal bulk
|
|
51019
|
+
// catch-up, and suppressing it would only slow legitimate recovery.
|
|
51020
|
+
SYNC_HOT_WINDOW_MS: 6e4,
|
|
51021
|
+
SYNC_HOT_BYTES: 33554432,
|
|
51022
|
+
// 32 MiB per window ≈ 0.5 MiB/s sustained
|
|
51015
51023
|
durability: "normal"
|
|
51016
51024
|
};
|
|
51017
51025
|
}
|
|
@@ -56007,6 +56015,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56007
56015
|
});
|
|
56008
56016
|
var MAX_WANT_CONCURRENT;
|
|
56009
56017
|
var ENTRIES_BATCH_MAX;
|
|
56018
|
+
var SYNC_HOTSPOT_TOP_N;
|
|
56010
56019
|
var SyncEngine;
|
|
56011
56020
|
var init_sync = __esm2({
|
|
56012
56021
|
"../../vendor/seqscribe/dist/sync.js"() {
|
|
@@ -56017,6 +56026,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56017
56026
|
init_session();
|
|
56018
56027
|
MAX_WANT_CONCURRENT = 4;
|
|
56019
56028
|
ENTRIES_BATCH_MAX = 100;
|
|
56029
|
+
SYNC_HOTSPOT_TOP_N = 5;
|
|
56020
56030
|
SyncEngine = class {
|
|
56021
56031
|
o;
|
|
56022
56032
|
peers = /* @__PURE__ */ new Map();
|
|
@@ -56024,6 +56034,16 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56024
56034
|
// (rejected_finality, sealed, forked, dropped_overflow, error) — the spin
|
|
56025
56035
|
// was invisible precisely because rejects were silently discarded
|
|
56026
56036
|
rejects = /* @__PURE__ */ new Map();
|
|
56037
|
+
// P24 observability: interval throughput counters (drained by stats()) —
|
|
56038
|
+
// the "hot and busy" complement to P22's "hot and stuck" stall signal
|
|
56039
|
+
interval = /* @__PURE__ */ new Map();
|
|
56040
|
+
intervalPairBytes = /* @__PURE__ */ new Map();
|
|
56041
|
+
// `${topic}\u0000${peerId}` → served+applied bytes
|
|
56042
|
+
// sync_hot rate window — informational only, never a throttle (§16
|
|
56043
|
+
// SYNC_HOT_* constants; the traffic it flags is normal bulk catch-up)
|
|
56044
|
+
hotWindowStart = 0;
|
|
56045
|
+
hotWindowBytes = 0;
|
|
56046
|
+
hotEmitted = false;
|
|
56027
56047
|
finalityHub = null;
|
|
56028
56048
|
subHub = null;
|
|
56029
56049
|
directiveHub = null;
|
|
@@ -56162,6 +56182,56 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56162
56182
|
rejectStats(topic) {
|
|
56163
56183
|
return { ...this.rejects.get(topic) ?? {} };
|
|
56164
56184
|
}
|
|
56185
|
+
// P24 — drain-and-reset: each stats() read returns the counters accumulated
|
|
56186
|
+
// since the previous read, plus the bounded (topic, peer) byte leaderboard.
|
|
56187
|
+
drainIntervalStats() {
|
|
56188
|
+
const topics = new Map(this.interval);
|
|
56189
|
+
this.interval.clear();
|
|
56190
|
+
const hotspots = [...this.intervalPairBytes].map(([k, bytes]) => {
|
|
56191
|
+
const i = k.indexOf("\0");
|
|
56192
|
+
return { topic: k.slice(0, i), peerId: k.slice(i + 1), bytes };
|
|
56193
|
+
}).sort((a, b) => b.bytes - a.bytes || (a.topic < b.topic ? -1 : a.topic > b.topic ? 1 : a.peerId < b.peerId ? -1 : 1)).slice(0, SYNC_HOTSPOT_TOP_N);
|
|
56194
|
+
this.intervalPairBytes.clear();
|
|
56195
|
+
return { topics, hotspots };
|
|
56196
|
+
}
|
|
56197
|
+
counters(topic) {
|
|
56198
|
+
let c = this.interval.get(topic);
|
|
56199
|
+
if (!c) {
|
|
56200
|
+
c = {
|
|
56201
|
+
servedEntries: 0,
|
|
56202
|
+
servedBytes: 0,
|
|
56203
|
+
appliedEntries: 0,
|
|
56204
|
+
appliedBytes: 0,
|
|
56205
|
+
wantRoundsRequested: 0,
|
|
56206
|
+
wantRoundsServed: 0
|
|
56207
|
+
};
|
|
56208
|
+
this.interval.set(topic, c);
|
|
56209
|
+
}
|
|
56210
|
+
return c;
|
|
56211
|
+
}
|
|
56212
|
+
noteThroughput(topic, peerId, entries, bytes, dir) {
|
|
56213
|
+
const c = this.counters(topic);
|
|
56214
|
+
if (dir === "served") {
|
|
56215
|
+
c.servedEntries += entries;
|
|
56216
|
+
c.servedBytes += bytes;
|
|
56217
|
+
} else {
|
|
56218
|
+
c.appliedEntries += entries;
|
|
56219
|
+
c.appliedBytes += bytes;
|
|
56220
|
+
}
|
|
56221
|
+
const pk = `${topic}\0${peerId}`;
|
|
56222
|
+
this.intervalPairBytes.set(pk, (this.intervalPairBytes.get(pk) ?? 0) + bytes);
|
|
56223
|
+
const now = this.o.clock();
|
|
56224
|
+
if (now - this.hotWindowStart >= this.o.constants.SYNC_HOT_WINDOW_MS) {
|
|
56225
|
+
this.hotWindowStart = now;
|
|
56226
|
+
this.hotWindowBytes = 0;
|
|
56227
|
+
this.hotEmitted = false;
|
|
56228
|
+
}
|
|
56229
|
+
this.hotWindowBytes += bytes;
|
|
56230
|
+
if (!this.hotEmitted && this.hotWindowBytes >= this.o.constants.SYNC_HOT_BYTES) {
|
|
56231
|
+
this.hotEmitted = true;
|
|
56232
|
+
this.o.emitAnomaly({ kind: "sync_hot" });
|
|
56233
|
+
}
|
|
56234
|
+
}
|
|
56165
56235
|
// ---- lifecycle ----
|
|
56166
56236
|
onReady(s2) {
|
|
56167
56237
|
const ps = this.peers.get(s2);
|
|
@@ -56342,6 +56412,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56342
56412
|
}));
|
|
56343
56413
|
if (!accepted)
|
|
56344
56414
|
return;
|
|
56415
|
+
this.noteThroughput(d.topic, ps.session.peerId, batch.length, bytes, "served");
|
|
56345
56416
|
ps.known.set(key2, last.seq);
|
|
56346
56417
|
if (done)
|
|
56347
56418
|
ps.dirty.delete(key2);
|
|
@@ -56386,6 +56457,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56386
56457
|
fromSeq: recovery ? recoveryFrom : head.contigSeq + 1
|
|
56387
56458
|
};
|
|
56388
56459
|
ps.activeWants.set(req, want);
|
|
56460
|
+
this.counters(want.topic).wantRoundsRequested += 1;
|
|
56389
56461
|
ps.session.request(`WANT:${req}`, () => ({
|
|
56390
56462
|
t: "WANT",
|
|
56391
56463
|
req,
|
|
@@ -56508,6 +56580,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56508
56580
|
ps.session.sendControl({ t: "ERR", code: "ERR_ACL_DENIED", ref: m.topic });
|
|
56509
56581
|
return;
|
|
56510
56582
|
}
|
|
56583
|
+
this.counters(m.topic).wantRoundsServed += 1;
|
|
56511
56584
|
if (this.snapshotHub?.maybeOffer(ps.session, m.topic, m.writer, m.fromSeq)) {
|
|
56512
56585
|
const contig = this.o.core.getStream(m.topic, m.writer).contigSeq;
|
|
56513
56586
|
ps.session.sendData((mid) => ({
|
|
@@ -56572,6 +56645,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56572
56645
|
}));
|
|
56573
56646
|
if (!accepted)
|
|
56574
56647
|
return;
|
|
56648
|
+
this.noteThroughput(m.topic, ps.session.peerId, batch.length, bytes, "served");
|
|
56575
56649
|
from = last.seq + 1;
|
|
56576
56650
|
}
|
|
56577
56651
|
}
|
|
@@ -56597,6 +56671,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56597
56671
|
if ((ps.known.get(key2) ?? 0) < m.toSeq)
|
|
56598
56672
|
ps.known.set(key2, m.toSeq);
|
|
56599
56673
|
const applies = [];
|
|
56674
|
+
const costs = [];
|
|
56600
56675
|
for (const raw of m.entries) {
|
|
56601
56676
|
let entry;
|
|
56602
56677
|
try {
|
|
@@ -56608,16 +56683,25 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56608
56683
|
}
|
|
56609
56684
|
if (entry.topic !== m.topic || entry.writer !== m.writer)
|
|
56610
56685
|
continue;
|
|
56686
|
+
costs.push(utf8ByteLength(JSON.stringify(entry)));
|
|
56611
56687
|
applies.push(this.o.core.applyExternal(entry, ps.session.peerId).catch(() => "error"));
|
|
56612
56688
|
}
|
|
56613
56689
|
void Promise.all(applies).then((results) => {
|
|
56614
|
-
|
|
56615
|
-
|
|
56690
|
+
let appliedN = 0;
|
|
56691
|
+
let appliedB = 0;
|
|
56692
|
+
for (let i = 0; i < results.length; i++) {
|
|
56693
|
+
const r = results[i];
|
|
56694
|
+
if (r === "applied" || r === "duplicate" || r === "pending") {
|
|
56695
|
+
appliedN += 1;
|
|
56696
|
+
appliedB += costs[i];
|
|
56616
56697
|
continue;
|
|
56698
|
+
}
|
|
56617
56699
|
const rec = this.rejects.get(m.topic) ?? {};
|
|
56618
56700
|
rec[r] = (rec[r] ?? 0) + 1;
|
|
56619
56701
|
this.rejects.set(m.topic, rec);
|
|
56620
56702
|
}
|
|
56703
|
+
if (appliedN > 0)
|
|
56704
|
+
this.noteThroughput(m.topic, ps.session.peerId, appliedN, appliedB, "applied");
|
|
56621
56705
|
if (m.req !== void 0 && m.done) {
|
|
56622
56706
|
const want = ps.activeWants.get(m.req);
|
|
56623
56707
|
this.finishWant(ps, m.req);
|
|
@@ -57405,7 +57489,8 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57405
57489
|
return r;
|
|
57406
57490
|
};
|
|
57407
57491
|
const stats = () => {
|
|
57408
|
-
const
|
|
57492
|
+
const interval = sync.drainIntervalStats();
|
|
57493
|
+
const out = { topics: {}, peers: sync.peerStats(), syncHotspots: interval.hotspots };
|
|
57409
57494
|
const now = clock();
|
|
57410
57495
|
for (const topic of topics.list()) {
|
|
57411
57496
|
const cert = core2.getCert(topic);
|
|
@@ -57426,7 +57511,15 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57426
57511
|
finalityGeneration: cert?.generation ?? null,
|
|
57427
57512
|
certOrderAgeMs: cert ? Math.max(0, now - cert.order.l) : null,
|
|
57428
57513
|
consumers: consumers2,
|
|
57429
|
-
applyRejects: sync.rejectStats(topic)
|
|
57514
|
+
applyRejects: sync.rejectStats(topic),
|
|
57515
|
+
sync: interval.topics.get(topic) ?? {
|
|
57516
|
+
servedEntries: 0,
|
|
57517
|
+
servedBytes: 0,
|
|
57518
|
+
appliedEntries: 0,
|
|
57519
|
+
appliedBytes: 0,
|
|
57520
|
+
wantRoundsRequested: 0,
|
|
57521
|
+
wantRoundsServed: 0
|
|
57522
|
+
}
|
|
57430
57523
|
};
|
|
57431
57524
|
}
|
|
57432
57525
|
return out;
|
|
@@ -58497,6 +58590,9 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
58497
58590
|
fallbackCounts.set(reason, (fallbackCounts.get(reason) ?? 0) + 1);
|
|
58498
58591
|
readsServedFromLedger++;
|
|
58499
58592
|
}
|
|
58593
|
+
function configureMeshReadReadinessCollector(collector) {
|
|
58594
|
+
seqscribeCollectorRef = collector;
|
|
58595
|
+
}
|
|
58500
58596
|
function logTransition(meshId, state) {
|
|
58501
58597
|
if (loggedTransitions.get(meshId) === state) return;
|
|
58502
58598
|
loggedTransitions.set(meshId, state);
|
|
@@ -58518,18 +58614,22 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
58518
58614
|
if (!hasMeshReadModelIndex(meshId)) return { ready: false, reason: "index_missing" };
|
|
58519
58615
|
}
|
|
58520
58616
|
let topicStats;
|
|
58521
|
-
|
|
58522
|
-
const
|
|
58523
|
-
|
|
58524
|
-
|
|
58525
|
-
|
|
58526
|
-
|
|
58527
|
-
|
|
58528
|
-
|
|
58529
|
-
|
|
58530
|
-
|
|
58531
|
-
|
|
58617
|
+
if (seqscribeCollectorRef) {
|
|
58618
|
+
const snapshot = seqscribeCollectorRef.snapshot();
|
|
58619
|
+
if (!snapshot) return { ready: false, reason: "stats_error" };
|
|
58620
|
+
topicStats = snapshot.stats.topics[topic];
|
|
58621
|
+
} else {
|
|
58622
|
+
try {
|
|
58623
|
+
topicStats = node.node.stats().topics[topic];
|
|
58624
|
+
} catch (error48) {
|
|
58625
|
+
LOG2.warn(
|
|
58626
|
+
"Seqscribe",
|
|
58627
|
+
`read readiness stats failed mesh=${meshId}: ${error48 instanceof Error ? error48.message : String(error48)}`
|
|
58628
|
+
);
|
|
58629
|
+
return { ready: false, reason: "stats_error" };
|
|
58630
|
+
}
|
|
58532
58631
|
}
|
|
58632
|
+
if (!topicStats) return { ready: false, reason: "topic_undefined" };
|
|
58533
58633
|
if (topicStats.quarantined > 0) return { ready: false, reason: "quarantined" };
|
|
58534
58634
|
const consumerName = meshReadModelConsumerName(meshId);
|
|
58535
58635
|
if (!consumerName) return { ready: false, reason: "consumer_missing" };
|
|
@@ -58571,6 +58671,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
58571
58671
|
var readsServedFromReplica;
|
|
58572
58672
|
var readsServedFromLedger;
|
|
58573
58673
|
var loggedTransitions;
|
|
58674
|
+
var seqscribeCollectorRef;
|
|
58574
58675
|
var init_mesh_read_readiness = __esm2({
|
|
58575
58676
|
"src/seqscribe/mesh-read-readiness.ts"() {
|
|
58576
58677
|
"use strict";
|
|
@@ -58585,6 +58686,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
58585
58686
|
readsServedFromReplica = 0;
|
|
58586
58687
|
readsServedFromLedger = 0;
|
|
58587
58688
|
loggedTransitions = /* @__PURE__ */ new Map();
|
|
58689
|
+
seqscribeCollectorRef = null;
|
|
58588
58690
|
}
|
|
58589
58691
|
});
|
|
58590
58692
|
function fromLedger(entry) {
|
|
@@ -63011,10 +63113,20 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
63011
63113
|
resolvedAt: r.resolved_at
|
|
63012
63114
|
};
|
|
63013
63115
|
}
|
|
63116
|
+
function registerLedgerBulkChangeListener(fn) {
|
|
63117
|
+
onLedgerBulkChange = fn;
|
|
63118
|
+
}
|
|
63119
|
+
function notifyLedgerBulkChange() {
|
|
63120
|
+
try {
|
|
63121
|
+
onLedgerBulkChange?.();
|
|
63122
|
+
} catch {
|
|
63123
|
+
}
|
|
63124
|
+
}
|
|
63014
63125
|
function pruneMeshRuntimeRetention() {
|
|
63015
63126
|
try {
|
|
63016
63127
|
const store = MeshRuntimeStore.getInstance();
|
|
63017
63128
|
const ledger = store.pruneEventLedger(MESH_EVENT_LEDGER_RETENTION_MS);
|
|
63129
|
+
if (ledger > 0) notifyLedgerBulkChange();
|
|
63018
63130
|
const toolCalls = store.pruneToolCallLog(MESH_TOOL_CALL_LOG_RETENTION_MS);
|
|
63019
63131
|
const terminalQueue = store.pruneTerminalQueueEntries(MESH_TERMINAL_QUEUE_RETENTION_MS);
|
|
63020
63132
|
const sessionDelivery = store.pruneTerminalSessionDeliveries(resolveSessionDeliveryRetentionMs());
|
|
@@ -63027,6 +63139,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
63027
63139
|
return { ledger: 0, toolCalls: 0, terminalQueue: 0, sessionDelivery: 0 };
|
|
63028
63140
|
}
|
|
63029
63141
|
}
|
|
63142
|
+
var onLedgerBulkChange;
|
|
63030
63143
|
var MESH_EVENT_LEDGER_RETENTION_MS;
|
|
63031
63144
|
var MESH_TOOL_CALL_LOG_RETENTION_MS;
|
|
63032
63145
|
var MESH_TERMINAL_QUEUE_RETENTION_MS;
|
|
@@ -63177,6 +63290,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
63177
63290
|
static resetForTests() {
|
|
63178
63291
|
this.instance?.close();
|
|
63179
63292
|
this.instance = void 0;
|
|
63293
|
+
notifyLedgerBulkChange();
|
|
63180
63294
|
}
|
|
63181
63295
|
/**
|
|
63182
63296
|
* VACUUM the SQLite database to reclaim on-disk space. Retention prunes rows
|
|
@@ -65824,6 +65938,242 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
65824
65938
|
};
|
|
65825
65939
|
}
|
|
65826
65940
|
});
|
|
65941
|
+
function safeMeshId3(meshId) {
|
|
65942
|
+
return meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
65943
|
+
}
|
|
65944
|
+
function getLedgerDir2() {
|
|
65945
|
+
const dir = (0, import_path7.join)(getConfigDir2(), LEDGER_DIR_NAME);
|
|
65946
|
+
if (!(0, import_fs7.existsSync)(dir)) {
|
|
65947
|
+
(0, import_fs7.mkdirSync)(dir, { recursive: true, mode: 448 });
|
|
65948
|
+
}
|
|
65949
|
+
return dir;
|
|
65950
|
+
}
|
|
65951
|
+
function getLedgerPath(meshId) {
|
|
65952
|
+
return (0, import_path7.join)(getLedgerDir2(), `${safeMeshId3(meshId)}.jsonl`);
|
|
65953
|
+
}
|
|
65954
|
+
function getRotatedPath(meshId, index) {
|
|
65955
|
+
return (0, import_path7.join)(getLedgerDir2(), `${safeMeshId3(meshId)}.${index}.jsonl`);
|
|
65956
|
+
}
|
|
65957
|
+
function getArchivePath(meshId) {
|
|
65958
|
+
return (0, import_path7.join)(getLedgerDir2(), `${safeMeshId3(meshId)}.archive.jsonl`);
|
|
65959
|
+
}
|
|
65960
|
+
function getRotatedArchivePath(meshId, index) {
|
|
65961
|
+
return (0, import_path7.join)(getLedgerDir2(), `${safeMeshId3(meshId)}.archive.${index}.jsonl`);
|
|
65962
|
+
}
|
|
65963
|
+
function getArchivedTerminalKeysPath(meshId) {
|
|
65964
|
+
return (0, import_path7.join)(getLedgerDir2(), `${safeMeshId3(meshId)}.archived-terminal-keys.json`);
|
|
65965
|
+
}
|
|
65966
|
+
var import_fs7;
|
|
65967
|
+
var import_path7;
|
|
65968
|
+
var LEDGER_DIR_NAME;
|
|
65969
|
+
var init_mesh_ledger_paths = __esm2({
|
|
65970
|
+
"src/mesh/mesh-ledger-paths.ts"() {
|
|
65971
|
+
"use strict";
|
|
65972
|
+
import_fs7 = require("fs");
|
|
65973
|
+
import_path7 = require("path");
|
|
65974
|
+
init_config();
|
|
65975
|
+
LEDGER_DIR_NAME = "mesh-ledger";
|
|
65976
|
+
}
|
|
65977
|
+
});
|
|
65978
|
+
function ledgerEntryTaskId(entry) {
|
|
65979
|
+
if (typeof entry.taskId === "string" && entry.taskId.trim()) return entry.taskId.trim();
|
|
65980
|
+
const fromPayload = entry.payload && typeof entry.payload === "object" ? entry.payload.taskId : void 0;
|
|
65981
|
+
return typeof fromPayload === "string" && fromPayload.trim() ? fromPayload.trim() : void 0;
|
|
65982
|
+
}
|
|
65983
|
+
function readLedgerFile(meshId) {
|
|
65984
|
+
const filePath = getLedgerPath(meshId);
|
|
65985
|
+
if (!(0, import_fs8.existsSync)(filePath)) return [];
|
|
65986
|
+
let content;
|
|
65987
|
+
try {
|
|
65988
|
+
content = (0, import_fs8.readFileSync)(filePath, "utf-8");
|
|
65989
|
+
} catch {
|
|
65990
|
+
return [];
|
|
65991
|
+
}
|
|
65992
|
+
const entries = [];
|
|
65993
|
+
for (const line of content.split("\n")) {
|
|
65994
|
+
if (!line.trim()) continue;
|
|
65995
|
+
try {
|
|
65996
|
+
const entry = JSON.parse(line);
|
|
65997
|
+
if (entry.id && entry.kind) {
|
|
65998
|
+
if (!entry.taskId) {
|
|
65999
|
+
const derived = ledgerEntryTaskId(entry);
|
|
66000
|
+
if (derived) entry.taskId = derived;
|
|
66001
|
+
}
|
|
66002
|
+
entries.push(entry);
|
|
66003
|
+
}
|
|
66004
|
+
} catch {
|
|
66005
|
+
}
|
|
66006
|
+
}
|
|
66007
|
+
return entries;
|
|
66008
|
+
}
|
|
66009
|
+
function ensureLedgerImported(store, meshId) {
|
|
66010
|
+
if (ledgerImportStoreRef !== store) {
|
|
66011
|
+
ledgerImportDone.clear();
|
|
66012
|
+
ledgerImportStoreRef = store;
|
|
66013
|
+
}
|
|
66014
|
+
if (ledgerImportDone.has(meshId)) return;
|
|
66015
|
+
ledgerImportDone.add(meshId);
|
|
66016
|
+
const fileEntries = readLedgerFile(meshId);
|
|
66017
|
+
if (fileEntries.length === 0) return;
|
|
66018
|
+
try {
|
|
66019
|
+
store.importLedgerEntries(fileEntries.map((e) => ({
|
|
66020
|
+
id: e.id,
|
|
66021
|
+
meshId: e.meshId,
|
|
66022
|
+
timestamp: e.timestamp,
|
|
66023
|
+
kind: e.kind,
|
|
66024
|
+
nodeId: e.nodeId ?? null,
|
|
66025
|
+
sessionId: e.sessionId ?? null,
|
|
66026
|
+
providerType: e.providerType ?? null,
|
|
66027
|
+
taskId: ledgerEntryTaskId(e) ?? null,
|
|
66028
|
+
payload: e.payload ?? {}
|
|
66029
|
+
})));
|
|
66030
|
+
} catch {
|
|
66031
|
+
}
|
|
66032
|
+
}
|
|
66033
|
+
function readLedgerFromStore(meshId, opts) {
|
|
66034
|
+
const store = MeshRuntimeStore.getInstance();
|
|
66035
|
+
ensureLedgerImported(store, meshId);
|
|
66036
|
+
return store.readLedgerEntriesOrdered(meshId, opts).map((r) => {
|
|
66037
|
+
const payload = r.payload && typeof r.payload === "object" ? r.payload : {};
|
|
66038
|
+
const taskId = ledgerEntryTaskId({ taskId: r.taskId ?? void 0, payload });
|
|
66039
|
+
return {
|
|
66040
|
+
id: r.id,
|
|
66041
|
+
meshId: r.meshId,
|
|
66042
|
+
timestamp: r.timestamp,
|
|
66043
|
+
kind: r.kind,
|
|
66044
|
+
...r.nodeId ? { nodeId: r.nodeId } : {},
|
|
66045
|
+
...r.sessionId ? { sessionId: r.sessionId } : {},
|
|
66046
|
+
...r.providerType ? { providerType: r.providerType } : {},
|
|
66047
|
+
...taskId ? { taskId } : {},
|
|
66048
|
+
payload
|
|
66049
|
+
};
|
|
66050
|
+
});
|
|
66051
|
+
}
|
|
66052
|
+
function getLedgerScanStats() {
|
|
66053
|
+
return {
|
|
66054
|
+
fullScans: ledgerScanStats.fullScans,
|
|
66055
|
+
scannedRows: ledgerScanStats.scannedRows,
|
|
66056
|
+
pushdownScans: ledgerScanStats.pushdownScans,
|
|
66057
|
+
pushdownRows: ledgerScanStats.pushdownRows,
|
|
66058
|
+
windowMs: Date.now() - ledgerScanStats.windowStartedAt
|
|
66059
|
+
};
|
|
66060
|
+
}
|
|
66061
|
+
function __resetLedgerScanStatsForTests() {
|
|
66062
|
+
ledgerScanStats.fullScans = 0;
|
|
66063
|
+
ledgerScanStats.scannedRows = 0;
|
|
66064
|
+
ledgerScanStats.pushdownScans = 0;
|
|
66065
|
+
ledgerScanStats.pushdownRows = 0;
|
|
66066
|
+
ledgerScanStats.windowStartedAt = Date.now();
|
|
66067
|
+
ledgerScanStats.lastSummaryAt = Date.now();
|
|
66068
|
+
}
|
|
66069
|
+
function recordLedgerFullScan(rowCount) {
|
|
66070
|
+
ledgerScanStats.fullScans++;
|
|
66071
|
+
ledgerScanStats.scannedRows += rowCount;
|
|
66072
|
+
maybeSummarizeLedgerScans();
|
|
66073
|
+
}
|
|
66074
|
+
function recordLedgerPushdownScan(rowCount) {
|
|
66075
|
+
ledgerScanStats.pushdownScans++;
|
|
66076
|
+
ledgerScanStats.pushdownRows += rowCount;
|
|
66077
|
+
maybeSummarizeLedgerScans();
|
|
66078
|
+
}
|
|
66079
|
+
function maybeSummarizeLedgerScans() {
|
|
66080
|
+
const now = Date.now();
|
|
66081
|
+
if (now - ledgerScanStats.lastSummaryAt < LEDGER_SCAN_SUMMARY_INTERVAL_MS) return;
|
|
66082
|
+
const windowMs = now - ledgerScanStats.windowStartedAt;
|
|
66083
|
+
const { fullScans, scannedRows, pushdownScans, pushdownRows } = ledgerScanStats;
|
|
66084
|
+
if (fullScans > 0 || pushdownScans > 0) {
|
|
66085
|
+
LOG2.info(
|
|
66086
|
+
"MeshLedger",
|
|
66087
|
+
`Ledger scans in last ${Math.round(windowMs / 1e3)}s: ${fullScans} full (${scannedRows} rows parsed), ${pushdownScans} SQL-bounded (${pushdownRows} rows)`
|
|
66088
|
+
);
|
|
66089
|
+
}
|
|
66090
|
+
ledgerScanStats.fullScans = 0;
|
|
66091
|
+
ledgerScanStats.scannedRows = 0;
|
|
66092
|
+
ledgerScanStats.pushdownScans = 0;
|
|
66093
|
+
ledgerScanStats.pushdownRows = 0;
|
|
66094
|
+
ledgerScanStats.windowStartedAt = now;
|
|
66095
|
+
ledgerScanStats.lastSummaryAt = now;
|
|
66096
|
+
}
|
|
66097
|
+
function liveCacheEntry(meshId) {
|
|
66098
|
+
const cached5 = ledgerReadCache.get(meshId);
|
|
66099
|
+
if (!cached5) return void 0;
|
|
66100
|
+
if (Date.now() - cached5.cachedAt >= LEDGER_CACHE_TTL_MS) return void 0;
|
|
66101
|
+
return cached5;
|
|
66102
|
+
}
|
|
66103
|
+
function getCachedRawEntries(meshId) {
|
|
66104
|
+
const cached5 = liveCacheEntry(meshId);
|
|
66105
|
+
if (cached5) return cached5.entries;
|
|
66106
|
+
let entries;
|
|
66107
|
+
try {
|
|
66108
|
+
entries = readLedgerFromStore(meshId);
|
|
66109
|
+
} catch {
|
|
66110
|
+
entries = readLedgerFile(meshId);
|
|
66111
|
+
}
|
|
66112
|
+
recordLedgerFullScan(entries.length);
|
|
66113
|
+
ledgerReadCache.set(meshId, { entries, cachedAt: Date.now() });
|
|
66114
|
+
return entries;
|
|
66115
|
+
}
|
|
66116
|
+
function entryTimeValue(entry) {
|
|
66117
|
+
const t = new Date(entry.timestamp).getTime();
|
|
66118
|
+
return Number.isNaN(t) ? NaN : t;
|
|
66119
|
+
}
|
|
66120
|
+
function appendToLedgerCache(meshId, newEntries) {
|
|
66121
|
+
if (newEntries.length === 0) return true;
|
|
66122
|
+
const cached5 = liveCacheEntry(meshId);
|
|
66123
|
+
if (!cached5) return false;
|
|
66124
|
+
let tailTime = cached5.entries.length > 0 ? entryTimeValue(cached5.entries[cached5.entries.length - 1]) : -Infinity;
|
|
66125
|
+
if (Number.isNaN(tailTime)) return false;
|
|
66126
|
+
for (const entry of newEntries) {
|
|
66127
|
+
const t = entryTimeValue(entry);
|
|
66128
|
+
if (Number.isNaN(t) || t < tailTime) return false;
|
|
66129
|
+
tailTime = t;
|
|
66130
|
+
}
|
|
66131
|
+
cached5.entries.push(...newEntries);
|
|
66132
|
+
return true;
|
|
66133
|
+
}
|
|
66134
|
+
function recordLedgerAppend(meshId, newEntries) {
|
|
66135
|
+
if (!appendToLedgerCache(meshId, newEntries)) invalidateLedgerCache(meshId);
|
|
66136
|
+
}
|
|
66137
|
+
function invalidateLedgerCache(meshId) {
|
|
66138
|
+
ledgerReadCache.delete(meshId);
|
|
66139
|
+
}
|
|
66140
|
+
function clearLedgerImportFlag(meshId) {
|
|
66141
|
+
ledgerImportDone.delete(meshId);
|
|
66142
|
+
}
|
|
66143
|
+
function invalidateAllLedgerCaches() {
|
|
66144
|
+
ledgerReadCache.clear();
|
|
66145
|
+
}
|
|
66146
|
+
var import_fs8;
|
|
66147
|
+
var ledgerReadCache;
|
|
66148
|
+
var LEDGER_CACHE_TTL_MS;
|
|
66149
|
+
var ledgerImportStoreRef;
|
|
66150
|
+
var ledgerImportDone;
|
|
66151
|
+
var ledgerScanStats;
|
|
66152
|
+
var LEDGER_SCAN_SUMMARY_INTERVAL_MS;
|
|
66153
|
+
var init_mesh_ledger_read_cache = __esm2({
|
|
66154
|
+
"src/mesh/mesh-ledger-read-cache.ts"() {
|
|
66155
|
+
"use strict";
|
|
66156
|
+
import_fs8 = require("fs");
|
|
66157
|
+
init_mesh_runtime_store();
|
|
66158
|
+
init_mesh_runtime_store_turn_rows();
|
|
66159
|
+
init_logger();
|
|
66160
|
+
init_mesh_ledger_paths();
|
|
66161
|
+
ledgerReadCache = /* @__PURE__ */ new Map();
|
|
66162
|
+
LEDGER_CACHE_TTL_MS = 3e4;
|
|
66163
|
+
ledgerImportDone = /* @__PURE__ */ new Set();
|
|
66164
|
+
ledgerScanStats = {
|
|
66165
|
+
fullScans: 0,
|
|
66166
|
+
scannedRows: 0,
|
|
66167
|
+
/** Cold reads served by SQL pushdown (bounded) rather than a full scan. */
|
|
66168
|
+
pushdownScans: 0,
|
|
66169
|
+
pushdownRows: 0,
|
|
66170
|
+
windowStartedAt: Date.now(),
|
|
66171
|
+
lastSummaryAt: Date.now()
|
|
66172
|
+
};
|
|
66173
|
+
LEDGER_SCAN_SUMMARY_INTERVAL_MS = 6e4;
|
|
66174
|
+
registerLedgerBulkChangeListener(invalidateAllLedgerCaches);
|
|
66175
|
+
}
|
|
66176
|
+
});
|
|
65827
66177
|
var mesh_ledger_exports = {};
|
|
65828
66178
|
__export2(mesh_ledger_exports, {
|
|
65829
66179
|
MAX_LEDGER_SLICE_LIMIT: () => MAX_LEDGER_SLICE_LIMIT,
|
|
@@ -65833,6 +66183,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
65833
66183
|
OPERATING_NOTE_KIND: () => OPERATING_NOTE_KIND,
|
|
65834
66184
|
OPERATING_NOTE_TOMBSTONE_KIND: () => OPERATING_NOTE_TOMBSTONE_KIND,
|
|
65835
66185
|
__clearMeshLedgerForTests: () => __clearMeshLedgerForTests,
|
|
66186
|
+
__resetLedgerScanStatsForTests: () => __resetLedgerScanStatsForTests,
|
|
65836
66187
|
appendLedgerEntry: () => appendLedgerEntry,
|
|
65837
66188
|
appendRemoteLedgerEntries: () => appendRemoteLedgerEntries,
|
|
65838
66189
|
buildLedgerOriginatingCoordinatorStamp: () => buildLedgerOriginatingCoordinatorStamp,
|
|
@@ -65843,8 +66194,10 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
65843
66194
|
enforceLedgerRotationCap: () => enforceLedgerRotationCap,
|
|
65844
66195
|
extractJsonObjectFromSummary: () => extractJsonObjectFromSummary,
|
|
65845
66196
|
getLedgerDir: () => getLedgerDir2,
|
|
66197
|
+
getLedgerScanStats: () => getLedgerScanStats,
|
|
65846
66198
|
getLedgerSummary: () => getLedgerSummary,
|
|
65847
66199
|
getSessionRecoveryContext: () => getSessionRecoveryContext,
|
|
66200
|
+
invalidateAllLedgerCaches: () => invalidateAllLedgerCaches,
|
|
65848
66201
|
isIntentionalCleanupStopEntry: () => isIntentionalCleanupStopEntry,
|
|
65849
66202
|
isNoteExpired: () => isNoteExpired,
|
|
65850
66203
|
isOperatingNoteTombstoned: () => isOperatingNoteTombstoned,
|
|
@@ -65862,11 +66215,6 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
65862
66215
|
readOperatingNotes: () => readOperatingNotes,
|
|
65863
66216
|
tombstoneOperatingNote: () => tombstoneOperatingNote
|
|
65864
66217
|
});
|
|
65865
|
-
function ledgerEntryTaskId(entry) {
|
|
65866
|
-
if (typeof entry.taskId === "string" && entry.taskId.trim()) return entry.taskId.trim();
|
|
65867
|
-
const fromPayload = entry.payload && typeof entry.payload === "object" ? entry.payload.taskId : void 0;
|
|
65868
|
-
return typeof fromPayload === "string" && fromPayload.trim() ? fromPayload.trim() : void 0;
|
|
65869
|
-
}
|
|
65870
66218
|
function isIntentionalCleanupStopEntry(entry) {
|
|
65871
66219
|
if (entry.kind !== "session_stopped" && entry.kind !== "task_failed" && entry.kind !== "task_stalled") return false;
|
|
65872
66220
|
const payload = entry.payload && typeof entry.payload === "object" && !Array.isArray(entry.payload) ? entry.payload : {};
|
|
@@ -65894,38 +66242,11 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
65894
66242
|
if (Number.isNaN(created)) return false;
|
|
65895
66243
|
return now - created >= ttlDays * MS_PER_DAY;
|
|
65896
66244
|
}
|
|
65897
|
-
function getLedgerDir2() {
|
|
65898
|
-
const dir = (0, import_path7.join)(getConfigDir2(), LEDGER_DIR_NAME);
|
|
65899
|
-
if (!(0, import_fs7.existsSync)(dir)) {
|
|
65900
|
-
(0, import_fs7.mkdirSync)(dir, { recursive: true, mode: 448 });
|
|
65901
|
-
}
|
|
65902
|
-
return dir;
|
|
65903
|
-
}
|
|
65904
|
-
function getLedgerPath(meshId) {
|
|
65905
|
-
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
65906
|
-
return (0, import_path7.join)(getLedgerDir2(), `${safe}.jsonl`);
|
|
65907
|
-
}
|
|
65908
|
-
function getRotatedPath(meshId, index) {
|
|
65909
|
-
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
65910
|
-
return (0, import_path7.join)(getLedgerDir2(), `${safe}.${index}.jsonl`);
|
|
65911
|
-
}
|
|
65912
|
-
function getArchivePath(meshId) {
|
|
65913
|
-
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
65914
|
-
return (0, import_path7.join)(getLedgerDir2(), `${safe}.archive.jsonl`);
|
|
65915
|
-
}
|
|
65916
|
-
function getRotatedArchivePath(meshId, index) {
|
|
65917
|
-
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
65918
|
-
return (0, import_path7.join)(getLedgerDir2(), `${safe}.archive.${index}.jsonl`);
|
|
65919
|
-
}
|
|
65920
|
-
function getArchivedTerminalKeysPath(meshId) {
|
|
65921
|
-
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
65922
|
-
return (0, import_path7.join)(getLedgerDir2(), `${safe}.archived-terminal-keys.json`);
|
|
65923
|
-
}
|
|
65924
66245
|
function readArchivedTerminalKeys(meshId) {
|
|
65925
66246
|
const path63 = getArchivedTerminalKeysPath(meshId);
|
|
65926
|
-
if (!(0,
|
|
66247
|
+
if (!(0, import_fs9.existsSync)(path63)) return /* @__PURE__ */ new Set();
|
|
65927
66248
|
try {
|
|
65928
|
-
const parsed = JSON.parse((0,
|
|
66249
|
+
const parsed = JSON.parse((0, import_fs9.readFileSync)(path63, "utf-8"));
|
|
65929
66250
|
return new Set(Array.isArray(parsed?.keys) ? parsed.keys.filter((k) => typeof k === "string") : []);
|
|
65930
66251
|
} catch {
|
|
65931
66252
|
return /* @__PURE__ */ new Set();
|
|
@@ -65947,23 +66268,23 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
65947
66268
|
keys = keys.slice(keys.length - ARCHIVED_TERMINAL_KEYS_MAX);
|
|
65948
66269
|
}
|
|
65949
66270
|
const index = { keys, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
65950
|
-
(0,
|
|
66271
|
+
(0, import_fs9.writeFileSync)(getArchivedTerminalKeysPath(meshId), JSON.stringify(index), { encoding: "utf-8", mode: 384 });
|
|
65951
66272
|
} catch {
|
|
65952
66273
|
}
|
|
65953
66274
|
}
|
|
65954
66275
|
function getArchivedCountsPath(meshId) {
|
|
65955
66276
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
65956
|
-
return (0,
|
|
66277
|
+
return (0, import_path8.join)(getLedgerDir2(), `${safe}.archived-counts.json`);
|
|
65957
66278
|
}
|
|
65958
66279
|
function rotateArchiveFile(meshId, archivePath) {
|
|
65959
66280
|
let index = 1;
|
|
65960
|
-
while ((0,
|
|
66281
|
+
while ((0, import_fs9.existsSync)(getRotatedArchivePath(meshId, index))) {
|
|
65961
66282
|
index++;
|
|
65962
66283
|
if (index > 5) break;
|
|
65963
66284
|
}
|
|
65964
66285
|
if (index > 5) index = 5;
|
|
65965
66286
|
try {
|
|
65966
|
-
(0,
|
|
66287
|
+
(0, import_fs9.renameSync)(archivePath, getRotatedArchivePath(meshId, index));
|
|
65967
66288
|
} catch (e) {
|
|
65968
66289
|
process.stderr.write(`[adhdev-mesh] Archive rotation failed for mesh ${meshId}: ${e?.message || e}
|
|
65969
66290
|
`);
|
|
@@ -65971,15 +66292,15 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
65971
66292
|
}
|
|
65972
66293
|
function readArchivedCounts(meshId) {
|
|
65973
66294
|
const path63 = getArchivedCountsPath(meshId);
|
|
65974
|
-
if (!(0,
|
|
66295
|
+
if (!(0, import_fs9.existsSync)(path63)) return { taskCompleted: 0, taskFailed: 0, taskStalled: 0, recoveryAttempted: 0, totalArchived: 0, lastArchivedAt: "" };
|
|
65975
66296
|
try {
|
|
65976
|
-
return JSON.parse((0,
|
|
66297
|
+
return JSON.parse((0, import_fs9.readFileSync)(path63, "utf-8"));
|
|
65977
66298
|
} catch {
|
|
65978
66299
|
return { taskCompleted: 0, taskFailed: 0, taskStalled: 0, recoveryAttempted: 0, totalArchived: 0, lastArchivedAt: "" };
|
|
65979
66300
|
}
|
|
65980
66301
|
}
|
|
65981
66302
|
function writeArchivedCounts(meshId, counts) {
|
|
65982
|
-
(0,
|
|
66303
|
+
(0, import_fs9.writeFileSync)(getArchivedCountsPath(meshId), JSON.stringify(counts), { encoding: "utf-8", mode: 384 });
|
|
65983
66304
|
}
|
|
65984
66305
|
function updateArchivedCounts(meshId, archived) {
|
|
65985
66306
|
const counts = readArchivedCounts(meshId);
|
|
@@ -66015,7 +66336,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66015
66336
|
}
|
|
66016
66337
|
function compactLedger(meshId) {
|
|
66017
66338
|
const filePath = getLedgerPath(meshId);
|
|
66018
|
-
if (!(0,
|
|
66339
|
+
if (!(0, import_fs9.existsSync)(filePath)) return { archivedCount: 0, retainedCount: 0 };
|
|
66019
66340
|
const cutoff = Date.now() - ARCHIVE_TERMINAL_OLDER_THAN_MS;
|
|
66020
66341
|
const entries = readLedgerEntries(meshId);
|
|
66021
66342
|
const retainedDispatchKeys = /* @__PURE__ */ new Set();
|
|
@@ -66044,11 +66365,11 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66044
66365
|
if (archive.length === 0) return { archivedCount: 0, retainedCount: keep.length };
|
|
66045
66366
|
const archivePath = getArchivePath(meshId);
|
|
66046
66367
|
try {
|
|
66047
|
-
if ((0,
|
|
66368
|
+
if ((0, import_fs9.existsSync)(archivePath) && (0, import_fs9.statSync)(archivePath).size > 50 * 1024 * 1024) {
|
|
66048
66369
|
rotateArchiveFile(meshId, archivePath);
|
|
66049
66370
|
}
|
|
66050
66371
|
const archiveLines = archive.map((e) => JSON.stringify(e)).join("\n") + "\n";
|
|
66051
|
-
(0,
|
|
66372
|
+
(0, import_fs9.appendFileSync)(archivePath, archiveLines, { encoding: "utf-8", mode: 384 });
|
|
66052
66373
|
updateArchivedCounts(meshId, archive);
|
|
66053
66374
|
recordArchivedTerminalKeys(meshId, archive);
|
|
66054
66375
|
} catch (e) {
|
|
@@ -66058,7 +66379,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66058
66379
|
}
|
|
66059
66380
|
try {
|
|
66060
66381
|
const keepLines = keep.length ? keep.map((e) => JSON.stringify(e)).join("\n") + "\n" : "";
|
|
66061
|
-
(0,
|
|
66382
|
+
(0, import_fs9.writeFileSync)(filePath, keepLines, { encoding: "utf-8", mode: 384 });
|
|
66062
66383
|
invalidateLedgerCache(meshId);
|
|
66063
66384
|
} catch (e) {
|
|
66064
66385
|
process.stderr.write(`[adhdev-mesh] Ledger compaction rewrite failed for mesh ${meshId}: ${e?.message || e}
|
|
@@ -66240,9 +66561,9 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66240
66561
|
if (derived) entry.taskId = derived;
|
|
66241
66562
|
}
|
|
66242
66563
|
const filePath = getLedgerPath(meshId);
|
|
66243
|
-
if ((0,
|
|
66564
|
+
if ((0, import_fs9.existsSync)(filePath)) {
|
|
66244
66565
|
try {
|
|
66245
|
-
const stat2 = (0,
|
|
66566
|
+
const stat2 = (0, import_fs9.statSync)(filePath);
|
|
66246
66567
|
if (stat2.size >= MAX_FILE_SIZE_BYTES) {
|
|
66247
66568
|
rotateLedgerFile(meshId, filePath);
|
|
66248
66569
|
} else if (stat2.size >= COMPACT_THRESHOLD_BYTES) {
|
|
@@ -66264,12 +66585,12 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66264
66585
|
payload: entry.payload
|
|
66265
66586
|
});
|
|
66266
66587
|
} catch {
|
|
66267
|
-
|
|
66588
|
+
clearLedgerImportFlag(meshId);
|
|
66268
66589
|
}
|
|
66269
66590
|
try {
|
|
66270
66591
|
const line = JSON.stringify(entry) + "\n";
|
|
66271
|
-
(0,
|
|
66272
|
-
|
|
66592
|
+
(0, import_fs9.appendFileSync)(filePath, line, { encoding: "utf-8", mode: 384 });
|
|
66593
|
+
recordLedgerAppend(meshId, [entry]);
|
|
66273
66594
|
meshLedgerEvents.emit("append", meshId, entry);
|
|
66274
66595
|
try {
|
|
66275
66596
|
recordMeshEventShadow(meshId, entry);
|
|
@@ -66364,7 +66685,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66364
66685
|
const remaining = readLedgerFile(meshId).filter((e) => !removeIds.includes(e.id));
|
|
66365
66686
|
const filePath = getLedgerPath(meshId);
|
|
66366
66687
|
const lines = remaining.length ? remaining.map((e) => JSON.stringify(e)).join("\n") + "\n" : "";
|
|
66367
|
-
(0,
|
|
66688
|
+
(0, import_fs9.writeFileSync)(filePath, lines, { encoding: "utf-8", mode: 384 });
|
|
66368
66689
|
} catch {
|
|
66369
66690
|
}
|
|
66370
66691
|
invalidateLedgerCache(meshId);
|
|
@@ -66421,8 +66742,8 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66421
66742
|
}
|
|
66422
66743
|
try {
|
|
66423
66744
|
const lines = validEntries.map((e) => JSON.stringify(e)).join("\n") + "\n";
|
|
66424
|
-
(0,
|
|
66425
|
-
|
|
66745
|
+
(0, import_fs9.appendFileSync)(ledgerPath, lines, { encoding: "utf-8", mode: 384 });
|
|
66746
|
+
recordLedgerAppend(meshId, validEntries);
|
|
66426
66747
|
for (const entry of validEntries) {
|
|
66427
66748
|
meshLedgerEvents.emit("append", meshId, entry);
|
|
66428
66749
|
}
|
|
@@ -66431,101 +66752,33 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66431
66752
|
throw new Error(`Failed to append remote ledger entries for mesh ${meshId}: ${e.message}`);
|
|
66432
66753
|
}
|
|
66433
66754
|
}
|
|
66434
|
-
function
|
|
66435
|
-
const filePath = getLedgerPath(meshId);
|
|
66436
|
-
if (!(0, import_fs7.existsSync)(filePath)) return [];
|
|
66437
|
-
let content;
|
|
66438
|
-
try {
|
|
66439
|
-
content = (0, import_fs7.readFileSync)(filePath, "utf-8");
|
|
66440
|
-
} catch {
|
|
66441
|
-
return [];
|
|
66442
|
-
}
|
|
66443
|
-
const entries = [];
|
|
66444
|
-
for (const line of content.split("\n")) {
|
|
66445
|
-
if (!line.trim()) continue;
|
|
66446
|
-
try {
|
|
66447
|
-
const entry = JSON.parse(line);
|
|
66448
|
-
if (entry.id && entry.kind) {
|
|
66449
|
-
if (!entry.taskId) {
|
|
66450
|
-
const derived = ledgerEntryTaskId(entry);
|
|
66451
|
-
if (derived) entry.taskId = derived;
|
|
66452
|
-
}
|
|
66453
|
-
entries.push(entry);
|
|
66454
|
-
}
|
|
66455
|
-
} catch {
|
|
66456
|
-
}
|
|
66457
|
-
}
|
|
66458
|
-
return entries;
|
|
66459
|
-
}
|
|
66460
|
-
function ensureLedgerImported(store, meshId) {
|
|
66461
|
-
if (ledgerImportStoreRef !== store) {
|
|
66462
|
-
ledgerImportDone.clear();
|
|
66463
|
-
ledgerImportStoreRef = store;
|
|
66464
|
-
}
|
|
66465
|
-
if (ledgerImportDone.has(meshId)) return;
|
|
66466
|
-
ledgerImportDone.add(meshId);
|
|
66467
|
-
const fileEntries = readLedgerFile(meshId);
|
|
66468
|
-
if (fileEntries.length === 0) return;
|
|
66469
|
-
try {
|
|
66470
|
-
store.importLedgerEntries(fileEntries.map((e) => ({
|
|
66471
|
-
id: e.id,
|
|
66472
|
-
meshId: e.meshId,
|
|
66473
|
-
timestamp: e.timestamp,
|
|
66474
|
-
kind: e.kind,
|
|
66475
|
-
nodeId: e.nodeId ?? null,
|
|
66476
|
-
sessionId: e.sessionId ?? null,
|
|
66477
|
-
providerType: e.providerType ?? null,
|
|
66478
|
-
taskId: ledgerEntryTaskId(e) ?? null,
|
|
66479
|
-
payload: e.payload ?? {}
|
|
66480
|
-
})));
|
|
66481
|
-
} catch {
|
|
66482
|
-
}
|
|
66483
|
-
}
|
|
66484
|
-
function readLedgerFromStore(meshId) {
|
|
66485
|
-
const store = MeshRuntimeStore.getInstance();
|
|
66486
|
-
ensureLedgerImported(store, meshId);
|
|
66487
|
-
return store.readLedgerEntriesOrdered(meshId).map((r) => {
|
|
66488
|
-
const payload = r.payload && typeof r.payload === "object" ? r.payload : {};
|
|
66489
|
-
const taskId = ledgerEntryTaskId({ taskId: r.taskId ?? void 0, payload });
|
|
66490
|
-
return {
|
|
66491
|
-
id: r.id,
|
|
66492
|
-
meshId: r.meshId,
|
|
66493
|
-
timestamp: r.timestamp,
|
|
66494
|
-
kind: r.kind,
|
|
66495
|
-
...r.nodeId ? { nodeId: r.nodeId } : {},
|
|
66496
|
-
...r.sessionId ? { sessionId: r.sessionId } : {},
|
|
66497
|
-
...r.providerType ? { providerType: r.providerType } : {},
|
|
66498
|
-
...taskId ? { taskId } : {},
|
|
66499
|
-
payload
|
|
66500
|
-
};
|
|
66501
|
-
});
|
|
66502
|
-
}
|
|
66503
|
-
function getCachedRawEntries(meshId) {
|
|
66504
|
-
const now = Date.now();
|
|
66505
|
-
const cached5 = ledgerReadCache.get(meshId);
|
|
66506
|
-
if (cached5 && now - cached5.cachedAt < LEDGER_CACHE_TTL_MS) return cached5.entries;
|
|
66507
|
-
let entries;
|
|
66755
|
+
function __clearMeshLedgerForTests(meshId) {
|
|
66508
66756
|
try {
|
|
66509
|
-
|
|
66757
|
+
MeshRuntimeStore.getInstance().clearLedgerForMesh(meshId);
|
|
66510
66758
|
} catch {
|
|
66511
|
-
entries = readLedgerFile(meshId);
|
|
66512
66759
|
}
|
|
66513
|
-
|
|
66514
|
-
|
|
66515
|
-
}
|
|
66516
|
-
function invalidateLedgerCache(meshId) {
|
|
66517
|
-
ledgerReadCache.delete(meshId);
|
|
66760
|
+
invalidateLedgerCache(meshId);
|
|
66761
|
+
clearLedgerImportFlag(meshId);
|
|
66518
66762
|
}
|
|
66519
|
-
function
|
|
66763
|
+
function readRawEntriesForOpts(meshId, opts) {
|
|
66764
|
+
const cached5 = liveCacheEntry(meshId);
|
|
66765
|
+
if (cached5) return cached5.entries;
|
|
66766
|
+
const hasSince = typeof opts?.since === "string" && !Number.isNaN(new Date(opts.since).getTime());
|
|
66767
|
+
const kinds = opts?.kind?.length ? opts.kind : void 0;
|
|
66768
|
+
if (!hasSince && !kinds) return getCachedRawEntries(meshId);
|
|
66520
66769
|
try {
|
|
66521
|
-
|
|
66770
|
+
const entries = readLedgerFromStore(meshId, {
|
|
66771
|
+
...hasSince ? { since: opts.since } : {},
|
|
66772
|
+
...kinds ? { kinds } : {}
|
|
66773
|
+
});
|
|
66774
|
+
recordLedgerPushdownScan(entries.length);
|
|
66775
|
+
return entries;
|
|
66522
66776
|
} catch {
|
|
66777
|
+
return getCachedRawEntries(meshId);
|
|
66523
66778
|
}
|
|
66524
|
-
ledgerReadCache.delete(meshId);
|
|
66525
|
-
ledgerImportDone.delete(meshId);
|
|
66526
66779
|
}
|
|
66527
66780
|
function readLedgerEntries(meshId, opts) {
|
|
66528
|
-
let entries =
|
|
66781
|
+
let entries = readRawEntriesForOpts(meshId, opts);
|
|
66529
66782
|
if (opts?.since) {
|
|
66530
66783
|
const sinceDate = new Date(opts.since).getTime();
|
|
66531
66784
|
if (!isNaN(sinceDate)) entries = entries.filter((e) => new Date(e.timestamp).getTime() >= sinceDate);
|
|
@@ -66727,13 +66980,13 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66727
66980
|
}
|
|
66728
66981
|
function rotateLedgerFile(meshId, currentPath) {
|
|
66729
66982
|
let index = 1;
|
|
66730
|
-
while ((0,
|
|
66983
|
+
while ((0, import_fs9.existsSync)(getRotatedPath(meshId, index))) {
|
|
66731
66984
|
index++;
|
|
66732
66985
|
if (index > 10) break;
|
|
66733
66986
|
}
|
|
66734
66987
|
if (index > 10) index = 10;
|
|
66735
66988
|
try {
|
|
66736
|
-
(0,
|
|
66989
|
+
(0, import_fs9.renameSync)(currentPath, getRotatedPath(meshId, index));
|
|
66737
66990
|
} catch (e) {
|
|
66738
66991
|
process.stderr.write(`[adhdev-mesh] Ledger rotation failed for mesh ${meshId}: ${e?.message || e}. File will continue to grow.
|
|
66739
66992
|
`);
|
|
@@ -66769,7 +67022,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66769
67022
|
function readRotationEntriesTolerant(filePath) {
|
|
66770
67023
|
let text;
|
|
66771
67024
|
try {
|
|
66772
|
-
text = (0,
|
|
67025
|
+
text = (0, import_fs9.readFileSync)(filePath, "utf-8");
|
|
66773
67026
|
} catch {
|
|
66774
67027
|
return [];
|
|
66775
67028
|
}
|
|
@@ -66788,14 +67041,14 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66788
67041
|
return out;
|
|
66789
67042
|
}
|
|
66790
67043
|
function evictClosedRotationFile(safe, dir, entry) {
|
|
66791
|
-
const filePath = (0,
|
|
67044
|
+
const filePath = (0, import_path8.join)(dir, entry.name);
|
|
66792
67045
|
const counts = readArchivedCounts(safe);
|
|
66793
67046
|
const alreadyFolded = new Set(counts.evictedRotations ?? []);
|
|
66794
67047
|
if (alreadyFolded.has(entry.name)) {
|
|
66795
|
-
if ((0,
|
|
67048
|
+
if ((0, import_fs9.existsSync)(filePath)) (0, import_fs9.unlinkSync)(filePath);
|
|
66796
67049
|
return;
|
|
66797
67050
|
}
|
|
66798
|
-
if (closedRotationKind(safe, entry.name) === "active" && (0,
|
|
67051
|
+
if (closedRotationKind(safe, entry.name) === "active" && (0, import_fs9.existsSync)(filePath)) {
|
|
66799
67052
|
const entries = readRotationEntriesTolerant(filePath);
|
|
66800
67053
|
for (const e of entries) {
|
|
66801
67054
|
if (e.kind === "task_completed") counts.taskCompleted++;
|
|
@@ -66808,7 +67061,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66808
67061
|
counts.evictedRotations = [...alreadyFolded, entry.name];
|
|
66809
67062
|
counts.lastArchivedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
66810
67063
|
writeArchivedCounts(safe, counts);
|
|
66811
|
-
if ((0,
|
|
67064
|
+
if ((0, import_fs9.existsSync)(filePath)) (0, import_fs9.unlinkSync)(filePath);
|
|
66812
67065
|
}
|
|
66813
67066
|
function enforceLedgerRotationCap(meshId, opts) {
|
|
66814
67067
|
const maxFiles = opts?.maxFiles ?? resolveLedgerRotationMaxFiles();
|
|
@@ -66819,14 +67072,14 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66819
67072
|
const stats = [];
|
|
66820
67073
|
let names = [];
|
|
66821
67074
|
try {
|
|
66822
|
-
names = (0,
|
|
67075
|
+
names = (0, import_fs9.readdirSync)(dir);
|
|
66823
67076
|
} catch {
|
|
66824
67077
|
names = [];
|
|
66825
67078
|
}
|
|
66826
67079
|
for (const name of names) {
|
|
66827
67080
|
if (!closedRotationKind(safe, name)) continue;
|
|
66828
67081
|
try {
|
|
66829
|
-
const st = (0,
|
|
67082
|
+
const st = (0, import_fs9.statSync)((0, import_path8.join)(dir, name));
|
|
66830
67083
|
if (st.isFile()) stats.push({ name, sizeBytes: st.size, mtimeMs: st.mtimeMs });
|
|
66831
67084
|
} catch {
|
|
66832
67085
|
}
|
|
@@ -66859,7 +67112,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66859
67112
|
const dir = getLedgerDir2();
|
|
66860
67113
|
let names = [];
|
|
66861
67114
|
try {
|
|
66862
|
-
names = (0,
|
|
67115
|
+
names = (0, import_fs9.readdirSync)(dir);
|
|
66863
67116
|
} catch {
|
|
66864
67117
|
return result;
|
|
66865
67118
|
}
|
|
@@ -66885,12 +67138,11 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66885
67138
|
}
|
|
66886
67139
|
return result;
|
|
66887
67140
|
}
|
|
66888
|
-
var
|
|
66889
|
-
var
|
|
67141
|
+
var import_fs9;
|
|
67142
|
+
var import_path8;
|
|
66890
67143
|
var import_crypto11;
|
|
66891
67144
|
var import_events;
|
|
66892
67145
|
var TASK_LIFECYCLE_LEDGER_KINDS;
|
|
66893
|
-
var LEDGER_DIR_NAME;
|
|
66894
67146
|
var MAX_FILE_SIZE_BYTES;
|
|
66895
67147
|
var COMPACT_THRESHOLD_BYTES;
|
|
66896
67148
|
var ARCHIVE_TERMINAL_OLDER_THAN_MS;
|
|
@@ -66907,23 +67159,22 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66907
67159
|
var MS_PER_DAY;
|
|
66908
67160
|
var ARCHIVED_TERMINAL_KEYS_MAX;
|
|
66909
67161
|
var meshLedgerEvents;
|
|
66910
|
-
var ledgerReadCache;
|
|
66911
|
-
var LEDGER_CACHE_TTL_MS;
|
|
66912
|
-
var ledgerImportStoreRef;
|
|
66913
|
-
var ledgerImportDone;
|
|
66914
67162
|
var init_mesh_ledger = __esm2({
|
|
66915
67163
|
"src/mesh/mesh-ledger.ts"() {
|
|
66916
67164
|
"use strict";
|
|
66917
|
-
|
|
66918
|
-
|
|
67165
|
+
import_fs9 = require("fs");
|
|
67166
|
+
import_path8 = require("path");
|
|
66919
67167
|
import_crypto11 = require("crypto");
|
|
66920
|
-
init_config();
|
|
66921
67168
|
init_mesh_retention_config();
|
|
66922
67169
|
init_dist();
|
|
66923
67170
|
import_events = require("events");
|
|
66924
67171
|
init_mesh_runtime_store();
|
|
67172
|
+
init_mesh_ledger_paths();
|
|
67173
|
+
init_mesh_ledger_read_cache();
|
|
66925
67174
|
init_mesh_dual_write();
|
|
66926
67175
|
init_contracts();
|
|
67176
|
+
init_mesh_ledger_paths();
|
|
67177
|
+
init_mesh_ledger_read_cache();
|
|
66927
67178
|
TASK_LIFECYCLE_LEDGER_KINDS = /* @__PURE__ */ new Set([
|
|
66928
67179
|
"task_dispatched",
|
|
66929
67180
|
"task_claimed",
|
|
@@ -66942,7 +67193,6 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66942
67193
|
// redrive history without an O(n) payload scan.
|
|
66943
67194
|
"redrive_provider_changed"
|
|
66944
67195
|
]);
|
|
66945
|
-
LEDGER_DIR_NAME = "mesh-ledger";
|
|
66946
67196
|
MAX_FILE_SIZE_BYTES = 10 * 1024 * 1024;
|
|
66947
67197
|
COMPACT_THRESHOLD_BYTES = 2 * 1024 * 1024;
|
|
66948
67198
|
ARCHIVE_TERMINAL_OLDER_THAN_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
@@ -66972,9 +67222,6 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66972
67222
|
MS_PER_DAY = 24 * 60 * 60 * 1e3;
|
|
66973
67223
|
ARCHIVED_TERMINAL_KEYS_MAX = 5e3;
|
|
66974
67224
|
meshLedgerEvents = new import_events.EventEmitter();
|
|
66975
|
-
ledgerReadCache = /* @__PURE__ */ new Map();
|
|
66976
|
-
LEDGER_CACHE_TTL_MS = 100;
|
|
66977
|
-
ledgerImportDone = /* @__PURE__ */ new Set();
|
|
66978
67225
|
}
|
|
66979
67226
|
});
|
|
66980
67227
|
var coordinator_prompt_exports = {};
|
|
@@ -68055,10 +68302,10 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68055
68302
|
return { config: inline, source: "mesh.policy.refineConfig", sourceType: "mesh_policy" };
|
|
68056
68303
|
}
|
|
68057
68304
|
for (const relative8 of MESH_REFINE_CONFIG_LOCATIONS) {
|
|
68058
|
-
const configPath = (0,
|
|
68059
|
-
if (!(0,
|
|
68305
|
+
const configPath = (0, import_path9.join)(workspace, relative8);
|
|
68306
|
+
if (!(0, import_fs10.existsSync)(configPath)) continue;
|
|
68060
68307
|
try {
|
|
68061
|
-
const parsed = parseConfigText3(configPath, (0,
|
|
68308
|
+
const parsed = parseConfigText3(configPath, (0, import_fs10.readFileSync)(configPath, "utf-8"));
|
|
68062
68309
|
const validation = validateMeshRefineConfig(parsed, relative8);
|
|
68063
68310
|
if (!validation.valid) return { source: relative8, sourceType: "invalid", path: configPath, error: String(validation.rejectedCommands[0]?.reason || validation.errors.join("; ")) };
|
|
68064
68311
|
return { config: parsed, source: relative8, sourceType: "repo_file", path: configPath };
|
|
@@ -68074,7 +68321,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68074
68321
|
}
|
|
68075
68322
|
function readPackageScripts(workspace) {
|
|
68076
68323
|
try {
|
|
68077
|
-
const parsed = JSON.parse((0,
|
|
68324
|
+
const parsed = JSON.parse((0, import_fs10.readFileSync)((0, import_path9.join)(workspace, "package.json"), "utf-8"));
|
|
68078
68325
|
return isRecord3(parsed?.scripts) ? parsed.scripts : {};
|
|
68079
68326
|
} catch {
|
|
68080
68327
|
return {};
|
|
@@ -68149,8 +68396,8 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68149
68396
|
unavailableReason: validation.commands.length ? void 0 : "validation_unavailable: repo mesh/refine config has no validation.commands"
|
|
68150
68397
|
};
|
|
68151
68398
|
}
|
|
68152
|
-
var
|
|
68153
|
-
var
|
|
68399
|
+
var import_fs10;
|
|
68400
|
+
var import_path9;
|
|
68154
68401
|
var yaml3;
|
|
68155
68402
|
var MESH_REFINE_VALIDATION_CATEGORIES;
|
|
68156
68403
|
var MESH_REFINE_VALIDATION_SCOPES;
|
|
@@ -68163,8 +68410,8 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68163
68410
|
var init_refine_config = __esm2({
|
|
68164
68411
|
"src/mesh/refine-config.ts"() {
|
|
68165
68412
|
"use strict";
|
|
68166
|
-
|
|
68167
|
-
|
|
68413
|
+
import_fs10 = require("fs");
|
|
68414
|
+
import_path9 = require("path");
|
|
68168
68415
|
yaml3 = __toESM2(require_js_yaml());
|
|
68169
68416
|
MESH_REFINE_VALIDATION_CATEGORIES = ["typecheck", "test", "lint", "build"];
|
|
68170
68417
|
MESH_REFINE_VALIDATION_SCOPES = ["none", "web", "daemon"];
|
|
@@ -68271,7 +68518,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68271
68518
|
if (!dir) continue;
|
|
68272
68519
|
for (const ext of WIN_EXEC_EXT) {
|
|
68273
68520
|
const full = path232.join(dir, trimmed + ext);
|
|
68274
|
-
if ((0,
|
|
68521
|
+
if ((0, import_fs11.existsSync)(full)) return full;
|
|
68275
68522
|
}
|
|
68276
68523
|
}
|
|
68277
68524
|
return null;
|
|
@@ -68288,7 +68535,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68288
68535
|
if (process.platform !== "win32") return command;
|
|
68289
68536
|
const trimmed = (command || "").trim();
|
|
68290
68537
|
if (!trimmed) return command;
|
|
68291
|
-
if (path232.isAbsolute(trimmed) && (0,
|
|
68538
|
+
if (path232.isAbsolute(trimmed) && (0, import_fs11.existsSync)(trimmed)) return trimmed;
|
|
68292
68539
|
try {
|
|
68293
68540
|
const out = (0, import_child_process3.execFileSync)("where", [trimmed], {
|
|
68294
68541
|
encoding: "utf8",
|
|
@@ -68337,7 +68584,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68337
68584
|
};
|
|
68338
68585
|
}
|
|
68339
68586
|
var import_child_process3;
|
|
68340
|
-
var
|
|
68587
|
+
var import_fs11;
|
|
68341
68588
|
var path232;
|
|
68342
68589
|
var DIRECT_EXEC_EXT;
|
|
68343
68590
|
var SHIM_EXEC_EXT;
|
|
@@ -68346,7 +68593,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68346
68593
|
"src/cli-adapters/resolve-executable.ts"() {
|
|
68347
68594
|
"use strict";
|
|
68348
68595
|
import_child_process3 = require("child_process");
|
|
68349
|
-
|
|
68596
|
+
import_fs11 = require("fs");
|
|
68350
68597
|
path232 = __toESM2(require("path"));
|
|
68351
68598
|
DIRECT_EXEC_EXT = /* @__PURE__ */ new Set([".exe", ".com"]);
|
|
68352
68599
|
SHIM_EXEC_EXT = /* @__PURE__ */ new Set([".cmd", ".bat"]);
|
|
@@ -68484,7 +68731,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68484
68731
|
if (!Number.isFinite(startedMs)) return false;
|
|
68485
68732
|
if (nowMs - startedMs <= WORKTREE_BOOTSTRAP_STALE_RUNNING_MS) return false;
|
|
68486
68733
|
const workspace = typeof node?.workspace === "string" ? node.workspace.trim() : "";
|
|
68487
|
-
if (!workspace || !(0,
|
|
68734
|
+
if (!workspace || !(0, import_fs12.existsSync)(workspace)) return false;
|
|
68488
68735
|
try {
|
|
68489
68736
|
const out = (0, import_node_child_process4.execFileSync)(resolveWin32Executable("git"), ["status", "--porcelain"], {
|
|
68490
68737
|
cwd: workspace,
|
|
@@ -68547,10 +68794,10 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68547
68794
|
return { config: inline, source: "mesh.policy.worktreeBootstrapConfig", sourceType: "mesh_policy" };
|
|
68548
68795
|
}
|
|
68549
68796
|
for (const relative8 of MESH_WORKTREE_BOOTSTRAP_CONFIG_LOCATIONS) {
|
|
68550
|
-
const configPath = (0,
|
|
68551
|
-
if (!(0,
|
|
68797
|
+
const configPath = (0, import_path10.join)(workspace, relative8);
|
|
68798
|
+
if (!(0, import_fs12.existsSync)(configPath)) continue;
|
|
68552
68799
|
try {
|
|
68553
|
-
const parsed = parseConfigText4(configPath, (0,
|
|
68800
|
+
const parsed = parseConfigText4(configPath, (0, import_fs12.readFileSync)(configPath, "utf-8"));
|
|
68554
68801
|
const validation = validateMeshWorktreeBootstrapConfig(parsed, relative8);
|
|
68555
68802
|
if (!validation.valid) return { source: relative8, sourceType: "invalid", path: configPath, error: String(validation.rejectedCommands[0]?.reason || validation.errors.join("; ")) };
|
|
68556
68803
|
return { config: parsed, source: relative8, sourceType: "repo_file", path: configPath };
|
|
@@ -68563,9 +68810,9 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68563
68810
|
function computeStaleInputsDigest(workspace, staleInputs) {
|
|
68564
68811
|
const digest = {};
|
|
68565
68812
|
for (const relative8 of staleInputs ?? []) {
|
|
68566
|
-
const filePath = (0,
|
|
68813
|
+
const filePath = (0, import_path10.join)(workspace, relative8);
|
|
68567
68814
|
try {
|
|
68568
|
-
digest[relative8] = (0, import_node_crypto2.createHash)("sha256").update((0,
|
|
68815
|
+
digest[relative8] = (0, import_node_crypto2.createHash)("sha256").update((0, import_fs12.readFileSync)(filePath)).digest("hex");
|
|
68569
68816
|
} catch {
|
|
68570
68817
|
digest[relative8] = "absent";
|
|
68571
68818
|
}
|
|
@@ -68636,10 +68883,10 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68636
68883
|
staleInputs: loaded.config.staleInputs
|
|
68637
68884
|
};
|
|
68638
68885
|
const staleInputPaths = loaded.config.staleInputs ?? [];
|
|
68639
|
-
const initiallyAbsent = staleInputPaths.filter((p) => !(0,
|
|
68886
|
+
const initiallyAbsent = staleInputPaths.filter((p) => !(0, import_fs12.existsSync)((0, import_path10.join)(workspace, p)));
|
|
68640
68887
|
for (const command of validation.commands) {
|
|
68641
68888
|
if (initiallyAbsent.length > 0) {
|
|
68642
|
-
const appearedNow = initiallyAbsent.filter((p) => (0,
|
|
68889
|
+
const appearedNow = initiallyAbsent.filter((p) => (0, import_fs12.existsSync)((0, import_path10.join)(workspace, p)));
|
|
68643
68890
|
if (appearedNow.length > 0) {
|
|
68644
68891
|
state.status = "stale";
|
|
68645
68892
|
state.completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -68647,7 +68894,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68647
68894
|
return state;
|
|
68648
68895
|
}
|
|
68649
68896
|
}
|
|
68650
|
-
const cwd = command.cwd ? (0,
|
|
68897
|
+
const cwd = command.cwd ? (0, import_path10.resolve)(workspace, command.cwd) : workspace;
|
|
68651
68898
|
const startedAt = Date.now();
|
|
68652
68899
|
state.lastCommand = command.displayCommand;
|
|
68653
68900
|
const resolvedCommand = resolveWin32Executable(command.command);
|
|
@@ -68707,8 +68954,8 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68707
68954
|
}
|
|
68708
68955
|
return state;
|
|
68709
68956
|
}
|
|
68710
|
-
var
|
|
68711
|
-
var
|
|
68957
|
+
var import_fs12;
|
|
68958
|
+
var import_path10;
|
|
68712
68959
|
var import_node_child_process4;
|
|
68713
68960
|
var import_node_crypto2;
|
|
68714
68961
|
var import_node_util3;
|
|
@@ -68723,8 +68970,8 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68723
68970
|
var init_worktree_bootstrap_config = __esm2({
|
|
68724
68971
|
"src/mesh/worktree-bootstrap-config.ts"() {
|
|
68725
68972
|
"use strict";
|
|
68726
|
-
|
|
68727
|
-
|
|
68973
|
+
import_fs12 = require("fs");
|
|
68974
|
+
import_path10 = require("path");
|
|
68728
68975
|
import_node_child_process4 = require("child_process");
|
|
68729
68976
|
import_node_crypto2 = require("crypto");
|
|
68730
68977
|
import_node_util3 = require("util");
|
|
@@ -69259,13 +69506,13 @@ ${rendered}`, "utf-8");
|
|
|
69259
69506
|
}
|
|
69260
69507
|
});
|
|
69261
69508
|
function getRegistryPath() {
|
|
69262
|
-
return (0,
|
|
69509
|
+
return (0, import_path12.join)(getDaemonDataDir(), "mesh-coordinators.json");
|
|
69263
69510
|
}
|
|
69264
69511
|
function loadMeshCoordinatorRegistry() {
|
|
69265
69512
|
const path63 = getRegistryPath();
|
|
69266
|
-
if (!(0,
|
|
69513
|
+
if (!(0, import_fs14.existsSync)(path63)) return;
|
|
69267
69514
|
try {
|
|
69268
|
-
const raw = JSON.parse((0,
|
|
69515
|
+
const raw = JSON.parse((0, import_fs14.readFileSync)(path63, "utf-8"));
|
|
69269
69516
|
if (!Array.isArray(raw)) return;
|
|
69270
69517
|
_registry.clear();
|
|
69271
69518
|
for (const entry of raw) {
|
|
@@ -69278,7 +69525,7 @@ ${rendered}`, "utf-8");
|
|
|
69278
69525
|
}
|
|
69279
69526
|
function saveRegistry() {
|
|
69280
69527
|
try {
|
|
69281
|
-
(0,
|
|
69528
|
+
(0, import_fs14.writeFileSync)(
|
|
69282
69529
|
getRegistryPath(),
|
|
69283
69530
|
JSON.stringify([..._registry.values()], null, 2),
|
|
69284
69531
|
{ encoding: "utf-8", mode: 384 }
|
|
@@ -69315,14 +69562,14 @@ ${rendered}`, "utf-8");
|
|
|
69315
69562
|
function listCoordinatorsForMesh(meshId) {
|
|
69316
69563
|
return [..._registry.values()].filter((e) => e.meshId === meshId).sort((a, b) => (b.startedAt ?? 0) - (a.startedAt ?? 0));
|
|
69317
69564
|
}
|
|
69318
|
-
var
|
|
69319
|
-
var
|
|
69565
|
+
var import_path12;
|
|
69566
|
+
var import_fs14;
|
|
69320
69567
|
var _registry;
|
|
69321
69568
|
var init_coordinator_registry = __esm2({
|
|
69322
69569
|
"src/mesh/coordinator-registry.ts"() {
|
|
69323
69570
|
"use strict";
|
|
69324
|
-
|
|
69325
|
-
|
|
69571
|
+
import_path12 = require("path");
|
|
69572
|
+
import_fs14 = require("fs");
|
|
69326
69573
|
init_config();
|
|
69327
69574
|
_registry = /* @__PURE__ */ new Map();
|
|
69328
69575
|
}
|
|
@@ -76985,7 +77232,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
|
|
|
76985
77232
|
if (now - lastAttempt < IDLE_AUTO_FAST_FORWARD_THROTTLE_MS) return;
|
|
76986
77233
|
idleAutoFastForwardLastAttempt.set(throttleKey, now);
|
|
76987
77234
|
if (isLocalAutoLaunchNode(node)) {
|
|
76988
|
-
if (!(0,
|
|
77235
|
+
if (!(0, import_fs16.existsSync)(workspace)) return;
|
|
76989
77236
|
await executeLocalAutoFastForward({ meshId: args.meshId, nodeId: args.nodeId, node, workspace, policy, trigger: "idle_auto" });
|
|
76990
77237
|
return;
|
|
76991
77238
|
}
|
|
@@ -77075,7 +77322,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
|
|
|
77075
77322
|
}
|
|
77076
77323
|
}
|
|
77077
77324
|
}
|
|
77078
|
-
var
|
|
77325
|
+
var import_fs16;
|
|
77079
77326
|
var IDLE_AUTO_FAST_FORWARD_THROTTLE_MS;
|
|
77080
77327
|
var idleAutoFastForwardLastAttempt;
|
|
77081
77328
|
var CONTINUOUS_AUTO_FAST_FORWARD_SCAN_COOLDOWN_MS;
|
|
@@ -77084,7 +77331,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
|
|
|
77084
77331
|
var init_mesh_auto_fast_forward = __esm2({
|
|
77085
77332
|
"src/mesh/mesh-auto-fast-forward.ts"() {
|
|
77086
77333
|
"use strict";
|
|
77087
|
-
|
|
77334
|
+
import_fs16 = require("fs");
|
|
77088
77335
|
init_logger();
|
|
77089
77336
|
init_config();
|
|
77090
77337
|
init_mesh_fast_forward();
|
|
@@ -79936,7 +80183,7 @@ Re-target now if the pin is stale: mesh_queue_requeue(task_id='${taskId}', targe
|
|
|
79936
80183
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
79937
80184
|
}
|
|
79938
80185
|
function getStatePath() {
|
|
79939
|
-
return (0,
|
|
80186
|
+
return (0, import_path14.join)(getConfigDir2(), "state.json");
|
|
79940
80187
|
}
|
|
79941
80188
|
function normalizeState(raw) {
|
|
79942
80189
|
const parsed = isPlainObject22(raw) ? raw : {};
|
|
@@ -79987,11 +80234,11 @@ Re-target now if the pin is stale: mesh_queue_requeue(task_id='${taskId}', targe
|
|
|
79987
80234
|
}
|
|
79988
80235
|
function loadState() {
|
|
79989
80236
|
const statePath = getStatePath();
|
|
79990
|
-
if (!(0,
|
|
80237
|
+
if (!(0, import_fs17.existsSync)(statePath)) {
|
|
79991
80238
|
return { ...DEFAULT_STATE };
|
|
79992
80239
|
}
|
|
79993
80240
|
try {
|
|
79994
|
-
const raw = (0,
|
|
80241
|
+
const raw = (0, import_fs17.readFileSync)(statePath, "utf-8");
|
|
79995
80242
|
return normalizeState(JSON.parse(raw));
|
|
79996
80243
|
} catch {
|
|
79997
80244
|
return { ...DEFAULT_STATE };
|
|
@@ -80000,7 +80247,7 @@ Re-target now if the pin is stale: mesh_queue_requeue(task_id='${taskId}', targe
|
|
|
80000
80247
|
function saveState(state) {
|
|
80001
80248
|
const statePath = getStatePath();
|
|
80002
80249
|
const normalized = normalizeState(state);
|
|
80003
|
-
(0,
|
|
80250
|
+
(0, import_fs17.writeFileSync)(statePath, JSON.stringify(normalized, null, 2), { encoding: "utf-8", mode: 384 });
|
|
80004
80251
|
}
|
|
80005
80252
|
function resetState() {
|
|
80006
80253
|
saveState({ ...DEFAULT_STATE });
|
|
@@ -80040,14 +80287,14 @@ Re-target now if the pin is stale: mesh_queue_requeue(task_id='${taskId}', targe
|
|
|
80040
80287
|
delete next[key2];
|
|
80041
80288
|
saveState({ ...state, deferredRestartSchedules: next });
|
|
80042
80289
|
}
|
|
80043
|
-
var
|
|
80044
|
-
var
|
|
80290
|
+
var import_fs17;
|
|
80291
|
+
var import_path14;
|
|
80045
80292
|
var DEFAULT_STATE;
|
|
80046
80293
|
var init_state_store = __esm2({
|
|
80047
80294
|
"src/config/state-store.ts"() {
|
|
80048
80295
|
"use strict";
|
|
80049
|
-
|
|
80050
|
-
|
|
80296
|
+
import_fs17 = require("fs");
|
|
80297
|
+
import_path14 = require("path");
|
|
80051
80298
|
init_config();
|
|
80052
80299
|
DEFAULT_STATE = {
|
|
80053
80300
|
recentActivity: [],
|
|
@@ -84343,7 +84590,7 @@ ${cleanBody}`;
|
|
|
84343
84590
|
}
|
|
84344
84591
|
function readDiskSpace(path63) {
|
|
84345
84592
|
try {
|
|
84346
|
-
const stats = (0,
|
|
84593
|
+
const stats = (0, import_fs18.statfsSync)(path63);
|
|
84347
84594
|
const blockSize = Number(stats.bsize);
|
|
84348
84595
|
const freeBytes = Number(stats.bavail) * blockSize;
|
|
84349
84596
|
const totalBytes = Number(stats.blocks) * blockSize;
|
|
@@ -84390,7 +84637,7 @@ ${cleanBody}`;
|
|
|
84390
84637
|
}
|
|
84391
84638
|
return status;
|
|
84392
84639
|
}
|
|
84393
|
-
var
|
|
84640
|
+
var import_fs18;
|
|
84394
84641
|
var DISK_CRITICAL_PERCENT_FREE;
|
|
84395
84642
|
var DISK_CRITICAL_FREE_BYTES;
|
|
84396
84643
|
var DISK_WARNING_PERCENT_FREE;
|
|
@@ -84399,7 +84646,7 @@ ${cleanBody}`;
|
|
|
84399
84646
|
var init_disk_space_preflight = __esm2({
|
|
84400
84647
|
"src/diagnostics/disk-space-preflight.ts"() {
|
|
84401
84648
|
"use strict";
|
|
84402
|
-
|
|
84649
|
+
import_fs18 = require("fs");
|
|
84403
84650
|
init_logger();
|
|
84404
84651
|
DISK_CRITICAL_PERCENT_FREE = 2;
|
|
84405
84652
|
DISK_CRITICAL_FREE_BYTES = 1 * 1024 * 1024 * 1024;
|
|
@@ -84451,7 +84698,7 @@ ${cleanBody}`;
|
|
|
84451
84698
|
}
|
|
84452
84699
|
function safeUnlink(path63) {
|
|
84453
84700
|
try {
|
|
84454
|
-
(0,
|
|
84701
|
+
(0, import_fs19.unlinkSync)(path63);
|
|
84455
84702
|
return true;
|
|
84456
84703
|
} catch (e) {
|
|
84457
84704
|
LOG2.warn("DiskRetention", `Failed to delete ${path63}: ${e?.message || e}`);
|
|
@@ -84459,18 +84706,18 @@ ${cleanBody}`;
|
|
|
84459
84706
|
}
|
|
84460
84707
|
}
|
|
84461
84708
|
function listDirFiles(dir) {
|
|
84462
|
-
if (!(0,
|
|
84709
|
+
if (!(0, import_fs19.existsSync)(dir)) return [];
|
|
84463
84710
|
const out = [];
|
|
84464
84711
|
let names;
|
|
84465
84712
|
try {
|
|
84466
|
-
names = (0,
|
|
84713
|
+
names = (0, import_fs19.readdirSync)(dir);
|
|
84467
84714
|
} catch {
|
|
84468
84715
|
return [];
|
|
84469
84716
|
}
|
|
84470
84717
|
for (const name of names) {
|
|
84471
|
-
const path63 = (0,
|
|
84718
|
+
const path63 = (0, import_path15.join)(dir, name);
|
|
84472
84719
|
try {
|
|
84473
|
-
const st = (0,
|
|
84720
|
+
const st = (0, import_fs19.statSync)(path63);
|
|
84474
84721
|
if (st.isFile()) out.push({ path: path63, mtimeMs: st.mtimeMs });
|
|
84475
84722
|
} catch {
|
|
84476
84723
|
}
|
|
@@ -84496,23 +84743,23 @@ ${cleanBody}`;
|
|
|
84496
84743
|
return deleted;
|
|
84497
84744
|
}
|
|
84498
84745
|
function pruneExpiredSessionHostRuntimes(now = Date.now()) {
|
|
84499
|
-
const root = (0,
|
|
84500
|
-
if (!(0,
|
|
84746
|
+
const root = (0, import_path15.join)(getConfigDir2(), "session-host");
|
|
84747
|
+
if (!(0, import_fs19.existsSync)(root)) return 0;
|
|
84501
84748
|
let apps;
|
|
84502
84749
|
try {
|
|
84503
|
-
apps = (0,
|
|
84750
|
+
apps = (0, import_fs19.readdirSync)(root);
|
|
84504
84751
|
} catch {
|
|
84505
84752
|
return 0;
|
|
84506
84753
|
}
|
|
84507
84754
|
const candidates = [];
|
|
84508
84755
|
for (const app of apps) {
|
|
84509
|
-
const runtimesDir = (0,
|
|
84510
|
-
if (!(0,
|
|
84756
|
+
const runtimesDir = (0, import_path15.join)(root, app, "runtimes");
|
|
84757
|
+
if (!(0, import_fs19.existsSync)(runtimesDir)) continue;
|
|
84511
84758
|
for (const f of listDirFiles(runtimesDir)) {
|
|
84512
84759
|
if (!f.path.endsWith(".json")) continue;
|
|
84513
84760
|
let record2 = null;
|
|
84514
84761
|
try {
|
|
84515
|
-
const parsed = JSON.parse((0,
|
|
84762
|
+
const parsed = JSON.parse((0, import_fs19.readFileSync)(f.path, "utf-8"));
|
|
84516
84763
|
const rec = parsed && typeof parsed === "object" ? parsed.record : null;
|
|
84517
84764
|
record2 = rec && typeof rec === "object" ? rec : null;
|
|
84518
84765
|
} catch {
|
|
@@ -84617,8 +84864,8 @@ ${cleanBody}`;
|
|
|
84617
84864
|
}
|
|
84618
84865
|
return signalled;
|
|
84619
84866
|
}
|
|
84620
|
-
var
|
|
84621
|
-
var
|
|
84867
|
+
var import_fs19;
|
|
84868
|
+
var import_path15;
|
|
84622
84869
|
var DAY_MS2;
|
|
84623
84870
|
var LEDGER_JSONL_MAX_AGE_MS;
|
|
84624
84871
|
var SESSION_HOST_RUNTIME_MAX_AGE_MS;
|
|
@@ -84627,8 +84874,8 @@ ${cleanBody}`;
|
|
|
84627
84874
|
var init_mesh_disk_retention = __esm2({
|
|
84628
84875
|
"src/mesh/mesh-disk-retention.ts"() {
|
|
84629
84876
|
"use strict";
|
|
84630
|
-
|
|
84631
|
-
|
|
84877
|
+
import_fs19 = require("fs");
|
|
84878
|
+
import_path15 = require("path");
|
|
84632
84879
|
init_config();
|
|
84633
84880
|
init_mesh_ledger();
|
|
84634
84881
|
init_runtime_surface();
|
|
@@ -84643,7 +84890,7 @@ ${cleanBody}`;
|
|
|
84643
84890
|
}
|
|
84644
84891
|
});
|
|
84645
84892
|
function retentionStatePath() {
|
|
84646
|
-
return (0,
|
|
84893
|
+
return (0, import_path16.join)(getLedgerDir2(), "worktree-node-retention-state.json");
|
|
84647
84894
|
}
|
|
84648
84895
|
function stateKey(meshId, nodeId) {
|
|
84649
84896
|
return `${meshId}::${nodeId}`;
|
|
@@ -84708,7 +84955,7 @@ ${cleanBody}`;
|
|
|
84708
84955
|
return String(stdout || "");
|
|
84709
84956
|
}
|
|
84710
84957
|
function normalizePathForCompare(value) {
|
|
84711
|
-
const resolved = (0,
|
|
84958
|
+
const resolved = (0, import_path16.resolve)(value);
|
|
84712
84959
|
try {
|
|
84713
84960
|
return fs17.realpathSync(resolved);
|
|
84714
84961
|
} catch {
|
|
@@ -84761,7 +85008,7 @@ ${cleanBody}`;
|
|
|
84761
85008
|
if (workspace && ctx.processCwd) {
|
|
84762
85009
|
const normalizedWorkspace = normalizePathForCompare(workspace);
|
|
84763
85010
|
const normalizedCwd = normalizePathForCompare(ctx.processCwd);
|
|
84764
|
-
if (normalizedCwd === normalizedWorkspace || normalizedCwd.startsWith(normalizedWorkspace +
|
|
85011
|
+
if (normalizedCwd === normalizedWorkspace || normalizedCwd.startsWith(normalizedWorkspace + import_path16.sep)) {
|
|
84765
85012
|
return skip("process_cwd_reference", "Worktree path is (or contains) the current process working directory; an open-runtime/cwd reference blocks removal.");
|
|
84766
85013
|
}
|
|
84767
85014
|
}
|
|
@@ -85142,7 +85389,7 @@ ${cleanBody}`;
|
|
|
85142
85389
|
}
|
|
85143
85390
|
var fs17;
|
|
85144
85391
|
var import_os22;
|
|
85145
|
-
var
|
|
85392
|
+
var import_path16;
|
|
85146
85393
|
var LOG_CATEGORY;
|
|
85147
85394
|
var metrics2;
|
|
85148
85395
|
var init_mesh_worktree_retention = __esm2({
|
|
@@ -85150,7 +85397,7 @@ ${cleanBody}`;
|
|
|
85150
85397
|
"use strict";
|
|
85151
85398
|
fs17 = __toESM2(require("fs"));
|
|
85152
85399
|
import_os22 = require("os");
|
|
85153
|
-
|
|
85400
|
+
import_path16 = require("path");
|
|
85154
85401
|
init_dist();
|
|
85155
85402
|
init_logger();
|
|
85156
85403
|
init_config();
|
|
@@ -91530,8 +91777,8 @@ ${cleanBody}`;
|
|
|
91530
91777
|
}
|
|
91531
91778
|
function probeSubmoduleGitlinkReachability(input) {
|
|
91532
91779
|
const { path: path63, baseCommit, branchCommit, probeRoot, baseRepoRoot } = input;
|
|
91533
|
-
const submoduleRepo = (0,
|
|
91534
|
-
const baseSubmoduleRepo = (0,
|
|
91780
|
+
const submoduleRepo = (0, import_path17.resolve)(probeRoot, path63);
|
|
91781
|
+
const baseSubmoduleRepo = (0, import_path17.resolve)(baseRepoRoot, path63);
|
|
91535
91782
|
if (baseCommit) ensureSubmoduleCommitLocal(submoduleRepo, baseSubmoduleRepo, baseCommit);
|
|
91536
91783
|
if (branchCommit) ensureSubmoduleCommitLocal(submoduleRepo, baseSubmoduleRepo, branchCommit);
|
|
91537
91784
|
let fastForward;
|
|
@@ -91701,7 +91948,7 @@ ${cleanBody}`;
|
|
|
91701
91948
|
}
|
|
91702
91949
|
var fs50;
|
|
91703
91950
|
var import_node_child_process9;
|
|
91704
|
-
var
|
|
91951
|
+
var import_path17;
|
|
91705
91952
|
var GIT2;
|
|
91706
91953
|
var REFINE_PATCH_EQUIVALENCE_OUTPUT_LIMIT_BYTES;
|
|
91707
91954
|
var init_mesh_refine_gitlink_utils = __esm2({
|
|
@@ -91709,7 +91956,7 @@ ${cleanBody}`;
|
|
|
91709
91956
|
"use strict";
|
|
91710
91957
|
fs50 = __toESM2(require("fs"));
|
|
91711
91958
|
import_node_child_process9 = require("child_process");
|
|
91712
|
-
|
|
91959
|
+
import_path17 = require("path");
|
|
91713
91960
|
init_logger();
|
|
91714
91961
|
init_resolve_executable();
|
|
91715
91962
|
GIT2 = process.platform === "win32" ? resolveWin32Executable("git") : "git";
|
|
@@ -91835,9 +92082,9 @@ ${cleanBody}`;
|
|
|
91835
92082
|
for (const path63 of changed) {
|
|
91836
92083
|
const baseCommit = readTreeObject(baseRepoRoot, baseHead, path63);
|
|
91837
92084
|
const branchCommit = readTreeObject(worktreeRoot, branchHead, path63);
|
|
91838
|
-
const submoduleRepoPath = (0,
|
|
92085
|
+
const submoduleRepoPath = (0, import_path18.resolve)(worktreeRoot, path63);
|
|
91839
92086
|
if (baseCommit) {
|
|
91840
|
-
ensureSubmoduleCommitLocal(submoduleRepoPath, (0,
|
|
92087
|
+
ensureSubmoduleCommitLocal(submoduleRepoPath, (0, import_path18.resolve)(baseRepoRoot, path63), baseCommit);
|
|
91841
92088
|
}
|
|
91842
92089
|
const markUndeterminable = () => {
|
|
91843
92090
|
const unavailable = [];
|
|
@@ -92060,7 +92307,7 @@ ${cleanBody}`;
|
|
|
92060
92307
|
for (const p of conflicts) {
|
|
92061
92308
|
const commit = resolveByPath.get(p);
|
|
92062
92309
|
try {
|
|
92063
|
-
(0, import_node_child_process10.execFileSync)(GIT2, ["checkout", "-q", "--detach", commit], { cwd: (0,
|
|
92310
|
+
(0, import_node_child_process10.execFileSync)(GIT2, ["checkout", "-q", "--detach", commit], { cwd: (0, import_path18.resolve)(worktreeRoot, p), stdio: "ignore" });
|
|
92064
92311
|
} catch {
|
|
92065
92312
|
}
|
|
92066
92313
|
try {
|
|
@@ -92079,7 +92326,7 @@ ${cleanBody}`;
|
|
|
92079
92326
|
return { ok: true, branchHead };
|
|
92080
92327
|
}
|
|
92081
92328
|
var fs51;
|
|
92082
|
-
var
|
|
92329
|
+
var import_path18;
|
|
92083
92330
|
var import_node_child_process10;
|
|
92084
92331
|
var SUBMODULE_PUBLISH_REQUIRED_RECOMMENDED_ACTION;
|
|
92085
92332
|
var SUBMODULE_PUBLICATION_UNDETERMINABLE_RECOMMENDED_ACTION;
|
|
@@ -92087,7 +92334,7 @@ ${cleanBody}`;
|
|
|
92087
92334
|
"src/mesh/mesh-refine-submodule-converge.ts"() {
|
|
92088
92335
|
"use strict";
|
|
92089
92336
|
fs51 = __toESM2(require("fs"));
|
|
92090
|
-
|
|
92337
|
+
import_path18 = require("path");
|
|
92091
92338
|
import_node_child_process10 = require("child_process");
|
|
92092
92339
|
init_mesh_refine_gitlink_utils();
|
|
92093
92340
|
SUBMODULE_PUBLISH_REQUIRED_RECOMMENDED_ACTION = "Publish the branch-side submodule commit(s) to submodule origin main, then rerun mesh_refine_node. Do NOT retry the rebase: the branch was intentionally left unrewritten because a rebase here would mint a submodule commit the reachability gate must reject.";
|
|
@@ -92111,10 +92358,10 @@ ${tail}`;
|
|
|
92111
92358
|
}
|
|
92112
92359
|
function writeValidationFailureLog(workspace, index, candidate, streams, now = () => /* @__PURE__ */ new Date()) {
|
|
92113
92360
|
try {
|
|
92114
|
-
const dir = (0,
|
|
92361
|
+
const dir = (0, import_path19.join)(workspace, REFINE_VALIDATION_LOG_DIR);
|
|
92115
92362
|
fs52.mkdirSync(dir, { recursive: true });
|
|
92116
92363
|
const stamp2 = now().toISOString().replace(/[:.]/g, "-");
|
|
92117
|
-
const file2 = (0,
|
|
92364
|
+
const file2 = (0, import_path19.join)(dir, `refine-${stamp2}-${index}.log`);
|
|
92118
92365
|
const asText = (v) => typeof v === "string" ? v : v == null ? "" : String(v);
|
|
92119
92366
|
const shown = candidate.displayCommand || [candidate.command, ...candidate.args || []].join(" ");
|
|
92120
92367
|
fs52.writeFileSync(
|
|
@@ -92599,7 +92846,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
92599
92846
|
const baseCommit = readTreeObject(repoRoot, baseHead, path63);
|
|
92600
92847
|
const branchCommit = readTreeObject(repoRoot, branchHead, path63);
|
|
92601
92848
|
if (!baseCommit || !branchCommit) return false;
|
|
92602
|
-
return isSubmoduleFastForward((0,
|
|
92849
|
+
return isSubmoduleFastForward((0, import_path19.resolve)(repoRoot, path63), baseCommit, branchCommit);
|
|
92603
92850
|
});
|
|
92604
92851
|
}
|
|
92605
92852
|
function collectTrivialFastForwardGitlinkResolutions(worktreeRoot, baseRepoRoot, baseHead, branchHead) {
|
|
@@ -92608,8 +92855,8 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
92608
92855
|
const baseCommit = readTreeObject(baseRepoRoot, baseHead, path63);
|
|
92609
92856
|
const branchCommit = readTreeObject(worktreeRoot, branchHead, path63);
|
|
92610
92857
|
if (!baseCommit || !branchCommit) continue;
|
|
92611
|
-
const submoduleRepoPath = (0,
|
|
92612
|
-
ensureSubmoduleCommitLocal(submoduleRepoPath, (0,
|
|
92858
|
+
const submoduleRepoPath = (0, import_path19.resolve)(worktreeRoot, path63);
|
|
92859
|
+
ensureSubmoduleCommitLocal(submoduleRepoPath, (0, import_path19.resolve)(baseRepoRoot, path63), baseCommit);
|
|
92613
92860
|
if (baseCommit === branchCommit) {
|
|
92614
92861
|
continue;
|
|
92615
92862
|
}
|
|
@@ -92625,7 +92872,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
92625
92872
|
const changedGitlinks = readChangedGitlinkPaths(repoRoot, baseHead, branchHead).map((path63) => {
|
|
92626
92873
|
const baseCommit = readTreeObject(repoRoot, baseHead, path63);
|
|
92627
92874
|
const branchCommit = readTreeObject(repoRoot, branchHead, path63);
|
|
92628
|
-
const submoduleRepoPath = (0,
|
|
92875
|
+
const submoduleRepoPath = (0, import_path19.resolve)(repoRoot, path63);
|
|
92629
92876
|
const probe = !!baseCommit && !!branchCommit ? probeSubmoduleFastForward(submoduleRepoPath, baseCommit, branchCommit) : "undeterminable";
|
|
92630
92877
|
return {
|
|
92631
92878
|
path: path63,
|
|
@@ -92688,7 +92935,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
92688
92935
|
if (!tree) return void 0;
|
|
92689
92936
|
const updates = paths.map((path63) => `160000 commit ${placeholderCommit} ${path63}`).join("\n");
|
|
92690
92937
|
if (!updates) return tree;
|
|
92691
|
-
const tmpIndex = (0,
|
|
92938
|
+
const tmpIndex = (0, import_path19.join)(resolveGitDir(repoRoot), `adhdev-refine-eq-${commitish.slice(0, 12)}.index`);
|
|
92692
92939
|
const env2 = { ...process.env, GIT_INDEX_FILE: tmpIndex };
|
|
92693
92940
|
try {
|
|
92694
92941
|
(0, import_node_child_process11.execFileSync)(GIT2, ["read-tree", tree], { cwd: repoRoot, env: env2, stdio: "ignore" });
|
|
@@ -92763,7 +93010,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
92763
93010
|
if (!contentTree) return void 0;
|
|
92764
93011
|
const updates = branchGitlinks.map((entry) => `160000 commit ${entry.branchCommit} ${entry.path}`).join("\n");
|
|
92765
93012
|
if (!updates) return contentTree;
|
|
92766
|
-
const tmpIndex = (0,
|
|
93013
|
+
const tmpIndex = (0, import_path19.join)(resolveGitDir(repoRoot), `adhdev-refine-ff-${baseHead.slice(0, 12)}-${branchHead.slice(0, 12)}.index`);
|
|
92767
93014
|
const env2 = { ...process.env, GIT_INDEX_FILE: tmpIndex };
|
|
92768
93015
|
try {
|
|
92769
93016
|
(0, import_node_child_process11.execFileSync)(GIT2, ["read-tree", contentTree], { cwd: repoRoot, env: env2, stdio: "ignore" });
|
|
@@ -92922,7 +93169,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
92922
93169
|
return match ? { commit: match[1], path: match[2] } : null;
|
|
92923
93170
|
}).filter((entry) => !!entry);
|
|
92924
93171
|
for (const gitlink of gitlinks) {
|
|
92925
|
-
const submodulePath = (0,
|
|
93172
|
+
const submodulePath = (0, import_path19.resolve)(repoRoot, gitlink.path);
|
|
92926
93173
|
const entry = {
|
|
92927
93174
|
path: gitlink.path,
|
|
92928
93175
|
commit: gitlink.commit,
|
|
@@ -92949,7 +93196,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
92949
93196
|
entry.localReachable = false;
|
|
92950
93197
|
if (options.allowAutoPublishSubmoduleMainCommits === true && options.worktreeRoot) {
|
|
92951
93198
|
try {
|
|
92952
|
-
const imported = await importCommitFromWorktreeSubmodule(submodulePath, (0,
|
|
93199
|
+
const imported = await importCommitFromWorktreeSubmodule(submodulePath, (0, import_path19.resolve)(options.worktreeRoot, gitlink.path), gitlink.commit);
|
|
92953
93200
|
if (imported) {
|
|
92954
93201
|
entry.localReachable = true;
|
|
92955
93202
|
entry.importedFromWorktree = true;
|
|
@@ -93201,13 +93448,13 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
93201
93448
|
...extras
|
|
93202
93449
|
});
|
|
93203
93450
|
const isPackageManagerValidation = (candidate) => {
|
|
93204
|
-
const command = (0,
|
|
93451
|
+
const command = (0, import_path19.basename)(candidate.command).replace(/\.(?:cmd|exe)$/i, "");
|
|
93205
93452
|
return ["npm", "pnpm", "yarn", "bun"].includes(command) && candidate.args.some((arg) => arg === "run" || arg === "test" || arg === "exec");
|
|
93206
93453
|
};
|
|
93207
93454
|
const dependenciesLikelyMissing = (cwd) => {
|
|
93208
|
-
if (!fs52.existsSync((0,
|
|
93209
|
-
if (fs52.existsSync((0,
|
|
93210
|
-
return ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lockb", "bun.lock"].some((lock) => fs52.existsSync((0,
|
|
93455
|
+
if (!fs52.existsSync((0, import_path19.join)(cwd, "package.json"))) return false;
|
|
93456
|
+
if (fs52.existsSync((0, import_path19.join)(cwd, "node_modules"))) return false;
|
|
93457
|
+
return ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lockb", "bun.lock"].some((lock) => fs52.existsSync((0, import_path19.join)(cwd, lock)));
|
|
93211
93458
|
};
|
|
93212
93459
|
const needsNodeModules = (candidate, cwd) => isPackageManagerValidation(candidate) && dependenciesLikelyMissing(cwd);
|
|
93213
93460
|
const isDaemonScopedCommand = (candidate) => {
|
|
@@ -93274,7 +93521,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
93274
93521
|
summary.bootstrap = { stage: "legacy" };
|
|
93275
93522
|
for (const candidate of selection.bootstrapCommands) {
|
|
93276
93523
|
const startedAt = Date.now();
|
|
93277
|
-
const cwd = candidate.cwd ? (0,
|
|
93524
|
+
const cwd = candidate.cwd ? (0, import_path19.resolve)(workspace, candidate.cwd) : workspace;
|
|
93278
93525
|
const timeout = candidate.timeoutMs || REFINE_VALIDATION_TIMEOUT_MS;
|
|
93279
93526
|
const resolvedCommand = resolveWin32Executable(candidate.command);
|
|
93280
93527
|
const spawn7 = buildWin32ExecFileSpawn(resolvedCommand, candidate.args);
|
|
@@ -93307,7 +93554,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
93307
93554
|
let missingDepsBlocked = false;
|
|
93308
93555
|
for (const candidate of commandsToRun) {
|
|
93309
93556
|
const startedAt = Date.now();
|
|
93310
|
-
const cwd = candidate.cwd ? (0,
|
|
93557
|
+
const cwd = candidate.cwd ? (0, import_path19.resolve)(workspace, candidate.cwd) : workspace;
|
|
93311
93558
|
const timeout = candidate.timeoutMs || REFINE_VALIDATION_TIMEOUT_MS;
|
|
93312
93559
|
const bootstrapProvidedDependencies = summary.bootstrap?.stage === "cached" || summary.bootstrap?.stage === "ran" || summary.bootstrap?.stage === "legacy";
|
|
93313
93560
|
if (!bootstrapProvidedDependencies && needsNodeModules(candidate, cwd)) {
|
|
@@ -93374,7 +93621,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
93374
93621
|
summary.status = "passed";
|
|
93375
93622
|
return summary;
|
|
93376
93623
|
}
|
|
93377
|
-
var
|
|
93624
|
+
var import_path19;
|
|
93378
93625
|
var fs52;
|
|
93379
93626
|
var import_node_child_process11;
|
|
93380
93627
|
var REFINE_VALIDATION_TIMEOUT_MS;
|
|
@@ -93389,7 +93636,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
93389
93636
|
init_git_status();
|
|
93390
93637
|
init_refine_config();
|
|
93391
93638
|
init_worktree_bootstrap_config();
|
|
93392
|
-
|
|
93639
|
+
import_path19 = require("path");
|
|
93393
93640
|
fs52 = __toESM2(require("fs"));
|
|
93394
93641
|
import_node_child_process11 = require("child_process");
|
|
93395
93642
|
init_resolve_executable();
|
|
@@ -93402,7 +93649,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
93402
93649
|
REFINE_VALIDATION_SUMMARY_HEAD_CHARS = 2e3;
|
|
93403
93650
|
REFINE_VALIDATION_SUMMARY_TAIL_CHARS = 6e3;
|
|
93404
93651
|
REFINE_VALIDATION_SUMMARY_CHARS = REFINE_VALIDATION_SUMMARY_HEAD_CHARS + REFINE_VALIDATION_SUMMARY_TAIL_CHARS;
|
|
93405
|
-
REFINE_VALIDATION_LOG_DIR = (0,
|
|
93652
|
+
REFINE_VALIDATION_LOG_DIR = (0, import_path19.join)(".adhdev", "logs");
|
|
93406
93653
|
}
|
|
93407
93654
|
});
|
|
93408
93655
|
async function runMeshRefineSubmoduleReachabilityPreflight(args) {
|
|
@@ -93411,7 +93658,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
93411
93658
|
if (touched.length === 0) return void 0;
|
|
93412
93659
|
const entries = [];
|
|
93413
93660
|
for (const path63 of touched) {
|
|
93414
|
-
const probedRepo = (0,
|
|
93661
|
+
const probedRepo = (0, import_path20.resolve)(args.worktreeRoot, path63);
|
|
93415
93662
|
const commit = readTreeObject(args.worktreeRoot, args.branchRef, path63);
|
|
93416
93663
|
if (!commit) {
|
|
93417
93664
|
entries.push({
|
|
@@ -93566,7 +93813,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
93566
93813
|
}
|
|
93567
93814
|
var import_node_child_process12;
|
|
93568
93815
|
var import_node_util6;
|
|
93569
|
-
var
|
|
93816
|
+
var import_path20;
|
|
93570
93817
|
var execFileAsync5;
|
|
93571
93818
|
var runGit2;
|
|
93572
93819
|
var init_mesh_refine_submodule_preflight = __esm2({
|
|
@@ -93574,7 +93821,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
93574
93821
|
"use strict";
|
|
93575
93822
|
import_node_child_process12 = require("child_process");
|
|
93576
93823
|
import_node_util6 = require("util");
|
|
93577
|
-
|
|
93824
|
+
import_path20 = require("path");
|
|
93578
93825
|
init_dist();
|
|
93579
93826
|
init_mesh_refine_gitlink_utils();
|
|
93580
93827
|
init_mesh_refine_gates();
|
|
@@ -98862,8 +99109,8 @@ ${e?.stderr || ""}`;
|
|
|
98862
99109
|
init_git_locale();
|
|
98863
99110
|
init_repo_mesh_types();
|
|
98864
99111
|
init_mesh_config();
|
|
98865
|
-
var
|
|
98866
|
-
var
|
|
99112
|
+
var import_fs13 = require("fs");
|
|
99113
|
+
var import_path11 = require("path");
|
|
98867
99114
|
init_refine_config();
|
|
98868
99115
|
init_worktree_bootstrap_config();
|
|
98869
99116
|
init_change_impact_config();
|
|
@@ -98882,22 +99129,22 @@ ${e?.stderr || ""}`;
|
|
|
98882
99129
|
"requirements.txt"
|
|
98883
99130
|
];
|
|
98884
99131
|
function writeConfigFile(workspace, relativePath, config2) {
|
|
98885
|
-
const target = (0,
|
|
98886
|
-
(0,
|
|
98887
|
-
(0,
|
|
99132
|
+
const target = (0, import_path11.join)(workspace, relativePath);
|
|
99133
|
+
(0, import_fs13.mkdirSync)((0, import_path11.dirname)(target), { recursive: true });
|
|
99134
|
+
(0, import_fs13.writeFileSync)(target, `${JSON.stringify(config2, null, 2)}
|
|
98888
99135
|
`, "utf-8");
|
|
98889
99136
|
return target;
|
|
98890
99137
|
}
|
|
98891
99138
|
function suggestMeshWorktreeBootstrapConfig(workspace) {
|
|
98892
99139
|
const commands = [];
|
|
98893
|
-
const hasPackageJson = (0,
|
|
98894
|
-
const hasNpmLock = (0,
|
|
99140
|
+
const hasPackageJson = (0, import_fs13.existsSync)((0, import_path11.join)(workspace, "package.json"));
|
|
99141
|
+
const hasNpmLock = (0, import_fs13.existsSync)((0, import_path11.join)(workspace, "package-lock.json"));
|
|
98895
99142
|
if (hasPackageJson) {
|
|
98896
99143
|
commands.push(
|
|
98897
99144
|
hasNpmLock ? { command: "npm", args: ["ci"] } : { command: "npm", args: ["install"] }
|
|
98898
99145
|
);
|
|
98899
99146
|
}
|
|
98900
|
-
const staleInputs = CANDIDATE_STALE_INPUTS.filter((relative8) => (0,
|
|
99147
|
+
const staleInputs = CANDIDATE_STALE_INPUTS.filter((relative8) => (0, import_fs13.existsSync)((0, import_path11.join)(workspace, relative8)));
|
|
98901
99148
|
if (!commands.length) {
|
|
98902
99149
|
return { commands, staleInputs };
|
|
98903
99150
|
}
|
|
@@ -98996,7 +99243,7 @@ ${e?.stderr || ""}`;
|
|
|
98996
99243
|
}
|
|
98997
99244
|
function applyConfigSuggestion(input) {
|
|
98998
99245
|
const { workspace, relativePath, existing, suggestedConfig, validate, write, overwrite } = input;
|
|
98999
|
-
const absolute = (0,
|
|
99246
|
+
const absolute = (0, import_path11.join)(workspace, relativePath);
|
|
99000
99247
|
if (existing !== void 0 && !overwrite) {
|
|
99001
99248
|
return { path: absolute, relativePath, written: false, skippedReason: "already_exists", config: existing };
|
|
99002
99249
|
}
|
|
@@ -99537,8 +99784,8 @@ ${e?.stderr || ""}`;
|
|
|
99537
99784
|
function isMeshTestPollution(args) {
|
|
99538
99785
|
return isSyntheticTestMeshId(args.meshId) || isSyntheticTestCoordinatorSession(args.coordinatorSessionId);
|
|
99539
99786
|
}
|
|
99540
|
-
var
|
|
99541
|
-
var
|
|
99787
|
+
var import_fs15 = require("fs");
|
|
99788
|
+
var import_path13 = require("path");
|
|
99542
99789
|
init_config();
|
|
99543
99790
|
var ZERO = {
|
|
99544
99791
|
inputTokens: 0,
|
|
@@ -99655,13 +99902,13 @@ ${e?.stderr || ""}`;
|
|
|
99655
99902
|
lastEvictedAt: 0
|
|
99656
99903
|
};
|
|
99657
99904
|
function getUsageDir() {
|
|
99658
|
-
const dir = (0,
|
|
99659
|
-
if (!(0,
|
|
99905
|
+
const dir = (0, import_path13.join)(getConfigDir2(), USAGE_DIR_NAME);
|
|
99906
|
+
if (!(0, import_fs15.existsSync)(dir)) (0, import_fs15.mkdirSync)(dir, { recursive: true, mode: 448 });
|
|
99660
99907
|
return dir;
|
|
99661
99908
|
}
|
|
99662
99909
|
function getUsagePath(meshId) {
|
|
99663
99910
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
99664
|
-
return (0,
|
|
99911
|
+
return (0, import_path13.join)(getUsageDir(), `${safe}.json`);
|
|
99665
99912
|
}
|
|
99666
99913
|
function emptyFile(meshId) {
|
|
99667
99914
|
return { version: 1, meshId, sessions: {} };
|
|
@@ -99671,7 +99918,7 @@ ${e?.stderr || ""}`;
|
|
|
99671
99918
|
const path63 = getUsagePath(meshId);
|
|
99672
99919
|
let stat2;
|
|
99673
99920
|
try {
|
|
99674
|
-
const s2 = (0,
|
|
99921
|
+
const s2 = (0, import_fs15.statSync)(path63);
|
|
99675
99922
|
stat2 = { mtimeMs: s2.mtimeMs, size: s2.size };
|
|
99676
99923
|
} catch {
|
|
99677
99924
|
usageFileCache.delete(path63);
|
|
@@ -99682,7 +99929,7 @@ ${e?.stderr || ""}`;
|
|
|
99682
99929
|
return cached5.file;
|
|
99683
99930
|
}
|
|
99684
99931
|
try {
|
|
99685
|
-
const parsed = JSON.parse((0,
|
|
99932
|
+
const parsed = JSON.parse((0, import_fs15.readFileSync)(path63, "utf-8"));
|
|
99686
99933
|
if (!parsed || typeof parsed !== "object" || !parsed.sessions) {
|
|
99687
99934
|
usageFileCache.delete(path63);
|
|
99688
99935
|
return emptyFile(meshId);
|
|
@@ -99697,19 +99944,19 @@ ${e?.stderr || ""}`;
|
|
|
99697
99944
|
function writeUsageFile(meshId, file2) {
|
|
99698
99945
|
const path63 = getUsagePath(meshId);
|
|
99699
99946
|
const tmp = `${path63}.tmp`;
|
|
99700
|
-
(0,
|
|
99947
|
+
(0, import_fs15.writeFileSync)(tmp, JSON.stringify(file2), { encoding: "utf-8", mode: 384 });
|
|
99701
99948
|
try {
|
|
99702
|
-
(0,
|
|
99949
|
+
(0, import_fs15.renameSync)(tmp, path63);
|
|
99703
99950
|
} catch (e) {
|
|
99704
99951
|
try {
|
|
99705
|
-
(0,
|
|
99952
|
+
(0, import_fs15.unlinkSync)(tmp);
|
|
99706
99953
|
} catch {
|
|
99707
99954
|
}
|
|
99708
99955
|
usageFileCache.delete(path63);
|
|
99709
99956
|
throw e;
|
|
99710
99957
|
}
|
|
99711
99958
|
try {
|
|
99712
|
-
const s2 = (0,
|
|
99959
|
+
const s2 = (0, import_fs15.statSync)(path63);
|
|
99713
99960
|
usageFileCache.set(path63, { file: file2, mtimeMs: s2.mtimeMs, size: s2.size });
|
|
99714
99961
|
} catch {
|
|
99715
99962
|
usageFileCache.delete(path63);
|
|
@@ -101225,7 +101472,7 @@ The pin is NOT cleared automatically: a pin often encodes required context conti
|
|
|
101225
101472
|
init_state_store();
|
|
101226
101473
|
var import_child_process5 = require("child_process");
|
|
101227
101474
|
var import_util22 = require("util");
|
|
101228
|
-
var
|
|
101475
|
+
var import_fs20 = require("fs");
|
|
101229
101476
|
var import_os3 = require("os");
|
|
101230
101477
|
var path27 = __toESM2(require("path"));
|
|
101231
101478
|
var fs18 = __toESM2(require("fs"));
|
|
@@ -101302,7 +101549,7 @@ The pin is NOT cleared automatically: a pin often encodes required context conti
|
|
|
101302
101549
|
if (path27.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~")) {
|
|
101303
101550
|
const candidate = trimmed.startsWith("~") ? path27.join((0, import_os3.homedir)(), trimmed.slice(1)) : trimmed;
|
|
101304
101551
|
const resolved = path27.isAbsolute(candidate) ? candidate : path27.resolve(candidate);
|
|
101305
|
-
return (0,
|
|
101552
|
+
return (0, import_fs20.existsSync)(resolved) ? resolved : null;
|
|
101306
101553
|
}
|
|
101307
101554
|
const isWin = (0, import_os3.platform)() === "win32";
|
|
101308
101555
|
const paths = (process.env.PATH || "").split(isWin ? ";" : ":");
|
|
@@ -101312,8 +101559,8 @@ The pin is NOT cleared automatically: a pin often encodes required context conti
|
|
|
101312
101559
|
for (const ext of exes) {
|
|
101313
101560
|
const fullPath = path27.join(p, trimmed + ext);
|
|
101314
101561
|
try {
|
|
101315
|
-
if ((0,
|
|
101316
|
-
const stat2 = (0,
|
|
101562
|
+
if ((0, import_fs20.existsSync)(fullPath)) {
|
|
101563
|
+
const stat2 = (0, import_fs20.statSync)(fullPath);
|
|
101317
101564
|
if (stat2.isFile() && (isWin || stat2.mode & 73)) {
|
|
101318
101565
|
return fullPath;
|
|
101319
101566
|
}
|
|
@@ -101331,9 +101578,9 @@ The pin is NOT cleared automatically: a pin often encodes required context conti
|
|
|
101331
101578
|
if (normalized.includes("*")) {
|
|
101332
101579
|
const username = home.split(/[\\/]/).pop() || "";
|
|
101333
101580
|
const resolved = normalized.replace("*", username);
|
|
101334
|
-
if ((0,
|
|
101581
|
+
if ((0, import_fs20.existsSync)(resolved)) return resolved;
|
|
101335
101582
|
} else {
|
|
101336
|
-
if ((0,
|
|
101583
|
+
if ((0, import_fs20.existsSync)(normalized)) return normalized;
|
|
101337
101584
|
}
|
|
101338
101585
|
}
|
|
101339
101586
|
return null;
|
|
@@ -101347,7 +101594,7 @@ The pin is NOT cleared automatically: a pin often encodes required context conti
|
|
|
101347
101594
|
let resolvedCli = cliPath;
|
|
101348
101595
|
if (!resolvedCli && appPath && os35 === "darwin") {
|
|
101349
101596
|
const bundledCli = `${appPath}/Contents/Resources/app/bin/${def.cli}`;
|
|
101350
|
-
if ((0,
|
|
101597
|
+
if ((0, import_fs20.existsSync)(bundledCli)) resolvedCli = bundledCli;
|
|
101351
101598
|
}
|
|
101352
101599
|
if (!resolvedCli && appPath && os35 === "win32") {
|
|
101353
101600
|
const { dirname: dirname25 } = await import("path");
|
|
@@ -101360,7 +101607,7 @@ The pin is NOT cleared automatically: a pin often encodes required context conti
|
|
|
101360
101607
|
`${appDir}\\\\resources\\\\app\\\\bin\\\\${def.cli}.cmd`
|
|
101361
101608
|
];
|
|
101362
101609
|
for (const c of candidates) {
|
|
101363
|
-
if ((0,
|
|
101610
|
+
if ((0, import_fs20.existsSync)(c)) {
|
|
101364
101611
|
resolvedCli = c;
|
|
101365
101612
|
break;
|
|
101366
101613
|
}
|
|
@@ -113289,7 +113536,7 @@ ${marker}`,
|
|
|
113289
113536
|
var os26 = __toESM2(require("os"));
|
|
113290
113537
|
var path43 = __toESM2(require("path"));
|
|
113291
113538
|
var crypto6 = __toESM2(require("crypto"));
|
|
113292
|
-
var
|
|
113539
|
+
var import_fs21 = require("fs");
|
|
113293
113540
|
var import_child_process11 = require("child_process");
|
|
113294
113541
|
var import_chalk = __toESM2((init_source(), __toCommonJS(source_exports)));
|
|
113295
113542
|
var fs34 = __toESM2(require("fs"));
|
|
@@ -115934,7 +116181,7 @@ ${marker}`,
|
|
|
115934
116181
|
return v;
|
|
115935
116182
|
});
|
|
115936
116183
|
if (missing) return null;
|
|
115937
|
-
return out;
|
|
116184
|
+
return out.includes("*") ? out : path38.normalize(out);
|
|
115938
116185
|
}
|
|
115939
116186
|
function claudeProjectDirName(workspace) {
|
|
115940
116187
|
return workspace.replace(/[^A-Za-z0-9_-]/g, "-");
|
|
@@ -118248,8 +118495,8 @@ ${marker}`,
|
|
|
118248
118495
|
const landedQuestion = readFocusedClaudeTuiQuestion(landed.screenText);
|
|
118249
118496
|
const rereadQuestion = readFocusedClaudeTuiQuestion(reread);
|
|
118250
118497
|
if (!landedQuestion || !rereadQuestion) return true;
|
|
118251
|
-
const
|
|
118252
|
-
return
|
|
118498
|
+
const normalize7 = (text) => text.replace(/\s+/g, " ").trim();
|
|
118499
|
+
return normalize7(landedQuestion.question) === normalize7(rereadQuestion.question);
|
|
118253
118500
|
}
|
|
118254
118501
|
async captureClaudeTuiPrompt(firstScreen, headers) {
|
|
118255
118502
|
if (this.claudeTuiCaptureSuppressed) return;
|
|
@@ -118466,8 +118713,8 @@ ${marker}`,
|
|
|
118466
118713
|
};
|
|
118467
118714
|
}
|
|
118468
118715
|
function isPathInsideWorkspace(configPath, workspace) {
|
|
118469
|
-
const
|
|
118470
|
-
const ws =
|
|
118716
|
+
const normalize7 = (value) => value.replace(/[\\/]+$/, "");
|
|
118717
|
+
const ws = normalize7(workspace);
|
|
118471
118718
|
if (!ws) return false;
|
|
118472
118719
|
const separatorAgnostic = (value) => value.replace(/\\/g, "/");
|
|
118473
118720
|
const normalizedPath = separatorAgnostic(configPath);
|
|
@@ -124847,7 +125094,7 @@ ${rawInput}` : rawInput;
|
|
|
124847
125094
|
const trimmed = command.trim();
|
|
124848
125095
|
if (!trimmed) return false;
|
|
124849
125096
|
if (isExplicitCommand(trimmed)) {
|
|
124850
|
-
return (0,
|
|
125097
|
+
return (0, import_fs21.existsSync)(expandExecutable(trimmed));
|
|
124851
125098
|
}
|
|
124852
125099
|
try {
|
|
124853
125100
|
(0, import_child_process11.execFileSync)(process.platform === "win32" ? "where" : "which", [trimmed], {
|
|
@@ -124993,10 +125240,10 @@ ${rawInput}` : rawInput;
|
|
|
124993
125240
|
}
|
|
124994
125241
|
function ensureEmptyDelegatedMcpConfig(workspace) {
|
|
124995
125242
|
const baseDir = path43.join(os26.tmpdir(), "adhdev-delegated-agent-empty-mcp");
|
|
124996
|
-
(0,
|
|
125243
|
+
(0, import_fs21.mkdirSync)(baseDir, { recursive: true });
|
|
124997
125244
|
const workspaceHash = shortHash(path43.resolve(workspace || os26.tmpdir()));
|
|
124998
125245
|
const filePath = path43.join(baseDir, `${workspaceHash}.json`);
|
|
124999
|
-
(0,
|
|
125246
|
+
(0, import_fs21.writeFileSync)(filePath, JSON.stringify({ mcpServers: {} }, null, 2), "utf-8");
|
|
125000
125247
|
return filePath;
|
|
125001
125248
|
}
|
|
125002
125249
|
function buildCoordinatorDelegatedCliLaunchOptions(input) {
|
|
@@ -131834,9 +132081,9 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
131834
132081
|
}
|
|
131835
132082
|
}
|
|
131836
132083
|
compareVersions(a, b) {
|
|
131837
|
-
const
|
|
131838
|
-
const pa =
|
|
131839
|
-
const pb =
|
|
132084
|
+
const normalize7 = (v) => v.split(/[-_+]/)[0].split(".").map((x) => parseInt(x, 10) || 0);
|
|
132085
|
+
const pa = normalize7(a);
|
|
132086
|
+
const pb = normalize7(b);
|
|
131840
132087
|
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
131841
132088
|
const va = pa[i] || 0;
|
|
131842
132089
|
const vb = pb[i] || 0;
|
|
@@ -132720,11 +132967,11 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
132720
132967
|
MESH_JSON_CONFIG_LOCATIONS: MESH_JSON_CONFIG_LOCATIONS2
|
|
132721
132968
|
} = await Promise.resolve().then(() => (init_mesh_json_config(), mesh_json_config_exports));
|
|
132722
132969
|
const { mkdirSync: mkdirSync34, writeFileSync: writeFileSync32 } = await import("fs");
|
|
132723
|
-
const { dirname: dirname25, join:
|
|
132970
|
+
const { dirname: dirname25, join: join74 } = await import("path");
|
|
132724
132971
|
const scaffold = buildMeshJsonConfigScaffold2(mesh);
|
|
132725
132972
|
const scaffoldJson = serializeMeshJsonConfigScaffold2(scaffold);
|
|
132726
132973
|
const relativePath = MESH_JSON_CONFIG_LOCATIONS2[0];
|
|
132727
|
-
const absolutePath =
|
|
132974
|
+
const absolutePath = join74(workspace, relativePath);
|
|
132728
132975
|
const validation = normalizeRepoMeshDeclarativeConfig2(scaffold);
|
|
132729
132976
|
if (!validation.valid) {
|
|
132730
132977
|
return { success: false, meshId, error: `invalid mesh.json scaffold: ${validation.errors.join("; ")}` };
|
|
@@ -132830,18 +133077,18 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
132830
133077
|
normalizeRepoMeshDeclarativeConfig: normalizeRepoMeshDeclarativeConfig2,
|
|
132831
133078
|
MESH_JSON_CONFIG_LOCATIONS: MESH_JSON_CONFIG_LOCATIONS2
|
|
132832
133079
|
} = await Promise.resolve().then(() => (init_mesh_json_config(), mesh_json_config_exports));
|
|
132833
|
-
const { existsSync:
|
|
132834
|
-
const { dirname: dirname25, join:
|
|
133080
|
+
const { existsSync: existsSync74, readFileSync: readFileSync59, mkdirSync: mkdirSync34, writeFileSync: writeFileSync32 } = await import("fs");
|
|
133081
|
+
const { dirname: dirname25, join: join74 } = await import("path");
|
|
132835
133082
|
const yaml6 = await Promise.resolve().then(() => (init_js_yaml(), js_yaml_exports));
|
|
132836
133083
|
const relativePath = MESH_JSON_CONFIG_LOCATIONS2[0];
|
|
132837
133084
|
let baseDoc = { version: 1 };
|
|
132838
|
-
let existingPath =
|
|
133085
|
+
let existingPath = join74(workspace, relativePath);
|
|
132839
133086
|
let existedAsYaml = false;
|
|
132840
133087
|
for (const relative8 of MESH_JSON_CONFIG_LOCATIONS2) {
|
|
132841
|
-
const candidate =
|
|
132842
|
-
if (!
|
|
133088
|
+
const candidate = join74(workspace, relative8);
|
|
133089
|
+
if (!existsSync74(candidate)) continue;
|
|
132843
133090
|
try {
|
|
132844
|
-
const text =
|
|
133091
|
+
const text = readFileSync59(candidate, "utf-8");
|
|
132845
133092
|
const parsed = /\.json$/i.test(candidate) ? JSON.parse(text) : yaml6.load(text);
|
|
132846
133093
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
132847
133094
|
baseDoc = parsed;
|
|
@@ -134888,7 +135135,7 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
134888
135135
|
}
|
|
134889
135136
|
}
|
|
134890
135137
|
};
|
|
134891
|
-
var
|
|
135138
|
+
var import_path21 = require("path");
|
|
134892
135139
|
var fs53 = __toESM2(require("fs"));
|
|
134893
135140
|
init_logger();
|
|
134894
135141
|
init_mesh_host_ownership();
|
|
@@ -134929,9 +135176,9 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
134929
135176
|
}
|
|
134930
135177
|
}
|
|
134931
135178
|
function isWorkspaceLocalPath(configPath, workspace) {
|
|
134932
|
-
const resolvedConfig = (0,
|
|
134933
|
-
const resolvedWorkspace = (0,
|
|
134934
|
-
return resolvedConfig === resolvedWorkspace || resolvedConfig.startsWith(resolvedWorkspace +
|
|
135179
|
+
const resolvedConfig = (0, import_path21.resolve)(configPath);
|
|
135180
|
+
const resolvedWorkspace = (0, import_path21.resolve)(workspace);
|
|
135181
|
+
return resolvedConfig === resolvedWorkspace || resolvedConfig.startsWith(resolvedWorkspace + import_path21.sep);
|
|
134935
135182
|
}
|
|
134936
135183
|
var meshCoordinatorLaunchHandlers = {
|
|
134937
135184
|
launch_mesh_coordinator: async (ctx, args) => {
|
|
@@ -135193,7 +135440,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
135193
135440
|
};
|
|
135194
135441
|
}
|
|
135195
135442
|
if (cliType === "codex-cli") {
|
|
135196
|
-
const repoMcpConfigPath = (0,
|
|
135443
|
+
const repoMcpConfigPath = (0, import_path21.join)(workspace, ".mcp.json");
|
|
135197
135444
|
if (fs53.existsSync(repoMcpConfigPath)) {
|
|
135198
135445
|
try {
|
|
135199
135446
|
const repoMcpConfig = parseMeshCoordinatorMcpConfig(
|
|
@@ -135366,7 +135613,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
135366
135613
|
workspace
|
|
135367
135614
|
};
|
|
135368
135615
|
}
|
|
135369
|
-
const { existsSync:
|
|
135616
|
+
const { existsSync: existsSync74, readFileSync: readFileSync59, writeFileSync: writeFileSync32, copyFileSync: copyFileSync3, mkdirSync: mkdirSync34 } = await import("fs");
|
|
135370
135617
|
const { dirname: dirname25 } = await import("path");
|
|
135371
135618
|
const mcpConfigPath = coordinatorSetup.configPath;
|
|
135372
135619
|
const hermesManualFallback = cliType === "hermes-cli" && configFormat === "hermes_config_yaml" ? createHermesManualMeshCoordinatorSetup(meshId, workspace) : null;
|
|
@@ -135411,14 +135658,14 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
135411
135658
|
if (hermesManualFallback) return returnManualFallback(message);
|
|
135412
135659
|
return { success: false, code: "mesh_coordinator_config_write_failed", error: message, meshId, cliType, workspace };
|
|
135413
135660
|
}
|
|
135414
|
-
const hadExistingMcpConfig =
|
|
135661
|
+
const hadExistingMcpConfig = existsSync74(mcpConfigPath);
|
|
135415
135662
|
let existingMcpConfig = hermesBaseConfig?.config || {};
|
|
135416
135663
|
if (hermesBaseConfig) {
|
|
135417
135664
|
copyHermesCoordinatorCredentialFiles(hermesBaseConfig.sourceHome, dirname25(mcpConfigPath));
|
|
135418
135665
|
}
|
|
135419
135666
|
if (hadExistingMcpConfig) {
|
|
135420
135667
|
try {
|
|
135421
|
-
const parsedExistingMcpConfig = parseMeshCoordinatorMcpConfig(
|
|
135668
|
+
const parsedExistingMcpConfig = parseMeshCoordinatorMcpConfig(readFileSync59(mcpConfigPath, "utf-8"), configFormat);
|
|
135422
135669
|
const existingCoordinatorConfig = hermesManualFallback ? stripHermesCoordinatorTempModelProviderOverrides(parsedExistingMcpConfig) : parsedExistingMcpConfig;
|
|
135423
135670
|
existingMcpConfig = { ...existingMcpConfig, ...existingCoordinatorConfig };
|
|
135424
135671
|
copyFileSync3(mcpConfigPath, mcpConfigPath + ".backup");
|
|
@@ -136229,7 +136476,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
136229
136476
|
const { deriveMeshReviewInboxItems: deriveMeshReviewInboxItems2 } = await Promise.resolve().then(() => (init_mesh_review_inbox(), mesh_review_inbox_exports));
|
|
136230
136477
|
const { readLedgerEntries: readLedgerEntries2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
|
|
136231
136478
|
const { getGitDiffSummary: getGitDiffSummary2 } = await Promise.resolve().then(() => (init_git_diff(), git_diff_exports));
|
|
136232
|
-
const { existsSync:
|
|
136479
|
+
const { existsSync: existsSync74 } = await import("fs");
|
|
136233
136480
|
const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
136234
136481
|
const mesh = meshRecord?.mesh;
|
|
136235
136482
|
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
@@ -136248,7 +136495,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
136248
136495
|
const derivation = deriveMeshReviewInboxItems2({ nodes: nodeStatuses, ledgerEntries });
|
|
136249
136496
|
for (const item of derivation.items) {
|
|
136250
136497
|
const workspace = item.workspace;
|
|
136251
|
-
if (!workspace || !
|
|
136498
|
+
if (!workspace || !existsSync74(workspace)) continue;
|
|
136252
136499
|
const baseRef = item.defaultBranch ? `origin/${item.defaultBranch}` : "origin/main";
|
|
136253
136500
|
try {
|
|
136254
136501
|
const diffResult = await getGitDiffSummary2(workspace, { baseRef, maxFiles: 100 });
|
|
@@ -136450,7 +136697,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
136450
136697
|
init_router_refine();
|
|
136451
136698
|
var fs56 = __toESM2(require("fs"));
|
|
136452
136699
|
var import_node_os22 = require("os");
|
|
136453
|
-
var
|
|
136700
|
+
var import_path222 = require("path");
|
|
136454
136701
|
init_logger();
|
|
136455
136702
|
init_git_locale();
|
|
136456
136703
|
init_dist();
|
|
@@ -136462,7 +136709,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
136462
136709
|
function acceptableManagedWorktreePaths(resolveWorktreePath2, normalizePath2, repoRoot, meshName, branch, worktreeBaseDir) {
|
|
136463
136710
|
const safeBranch = branch.replace(/[/\\:*?"<>|]/g, "-").replace(/^\.+|\.+$/g, "");
|
|
136464
136711
|
const safeMeshName = meshName.replace(/[/\\:*?"<>|]/g, "-").replace(/^\.+|\.+$/g, "");
|
|
136465
|
-
const legacyPath = (0,
|
|
136712
|
+
const legacyPath = (0, import_path222.join)((0, import_path222.dirname)(repoRoot), LEGACY_WORKTREE_DIR_NAME, safeMeshName, safeBranch);
|
|
136466
136713
|
const candidates = [
|
|
136467
136714
|
resolveWorktreePath2(repoRoot, meshName, branch, worktreeBaseDir),
|
|
136468
136715
|
legacyPath
|
|
@@ -136489,8 +136736,8 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
136489
136736
|
function looksLikeCrossTrackWorktreePath(actualPath, normalizePath2) {
|
|
136490
136737
|
const home = normalizePath2((0, import_node_os22.homedir)());
|
|
136491
136738
|
return TRACK_CONFIG_DIR_NAMES.some((trackDirName) => {
|
|
136492
|
-
const trackWorktreesDir = (0,
|
|
136493
|
-
return actualPath === normalizePath2(trackWorktreesDir) || actualPath.startsWith(normalizePath2(trackWorktreesDir) +
|
|
136739
|
+
const trackWorktreesDir = (0, import_path222.join)(home, trackDirName, "worktrees");
|
|
136740
|
+
return actualPath === normalizePath2(trackWorktreesDir) || actualPath.startsWith(normalizePath2(trackWorktreesDir) + import_path222.sep);
|
|
136494
136741
|
});
|
|
136495
136742
|
}
|
|
136496
136743
|
function unexpectedPathRecoveryHint(actualPath, normalizePath2, suffix) {
|
|
@@ -136600,7 +136847,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
136600
136847
|
}
|
|
136601
136848
|
const { resolveWorktreePath: resolveWorktreePath2, listWorktrees: listWorktrees2 } = await Promise.resolve().then(() => (init_git_worktree(), git_worktree_exports));
|
|
136602
136849
|
const normalizePath2 = (value) => {
|
|
136603
|
-
const resolved = (0,
|
|
136850
|
+
const resolved = (0, import_path222.resolve)(value);
|
|
136604
136851
|
try {
|
|
136605
136852
|
return fs56.realpathSync(resolved);
|
|
136606
136853
|
} catch {
|
|
@@ -136727,7 +136974,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
136727
136974
|
}
|
|
136728
136975
|
const { resolveWorktreePath: resolveWorktreePath2, listWorktrees: listWorktrees2, removeWorktree: removeWorktree2 } = await Promise.resolve().then(() => (init_git_worktree(), git_worktree_exports));
|
|
136729
136976
|
const normalizePath2 = (value) => {
|
|
136730
|
-
const resolved = (0,
|
|
136977
|
+
const resolved = (0, import_path222.resolve)(value);
|
|
136731
136978
|
try {
|
|
136732
136979
|
return fs56.realpathSync(resolved);
|
|
136733
136980
|
} catch {
|
|
@@ -137395,7 +137642,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
137395
137642
|
init_logger();
|
|
137396
137643
|
var yaml5 = __toESM2(require_js_yaml());
|
|
137397
137644
|
var import_os5 = require("os");
|
|
137398
|
-
var
|
|
137645
|
+
var import_path23 = require("path");
|
|
137399
137646
|
var fs57 = __toESM2(require("fs"));
|
|
137400
137647
|
var MESH_COORDINATOR_AUTO_IMPORT_FORMATS = ["claude_mcp_json", "hermes_config_yaml", "opencode_json"];
|
|
137401
137648
|
function isSupportedMeshCoordinatorConfigFormat(format) {
|
|
@@ -137436,13 +137683,13 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
137436
137683
|
}
|
|
137437
137684
|
function resolveHermesUserHome() {
|
|
137438
137685
|
const explicitHome = process.env.HERMES_HOME?.trim();
|
|
137439
|
-
return explicitHome || (0,
|
|
137686
|
+
return explicitHome || (0, import_path23.join)((0, import_os5.homedir)(), ".hermes");
|
|
137440
137687
|
}
|
|
137441
137688
|
function loadHermesCoordinatorBaseConfig(targetConfigPath) {
|
|
137442
137689
|
const sourceHome = resolveHermesUserHome();
|
|
137443
|
-
const sourceConfigPath = (0,
|
|
137690
|
+
const sourceConfigPath = (0, import_path23.join)(sourceHome, "config.yaml");
|
|
137444
137691
|
if (!fs57.existsSync(sourceConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
137445
|
-
if ((0,
|
|
137692
|
+
if ((0, import_path23.resolve)(sourceConfigPath) === (0, import_path23.resolve)(targetConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
137446
137693
|
const parsed = parseMeshCoordinatorMcpConfig(fs57.readFileSync(sourceConfigPath, "utf-8"), "hermes_config_yaml");
|
|
137447
137694
|
const { mcp_servers: _mcpServers, ...baseConfig } = parsed;
|
|
137448
137695
|
return { config: baseConfig, sourceHome, sourceConfigPath };
|
|
@@ -137476,10 +137723,10 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
137476
137723
|
return sanitized;
|
|
137477
137724
|
}
|
|
137478
137725
|
function copyHermesCoordinatorCredentialFiles(sourceHome, targetHome) {
|
|
137479
|
-
if ((0,
|
|
137726
|
+
if ((0, import_path23.resolve)(sourceHome) === (0, import_path23.resolve)(targetHome)) return;
|
|
137480
137727
|
for (const fileName of [".env", "auth.json"]) {
|
|
137481
|
-
const sourcePath = (0,
|
|
137482
|
-
const targetPath = (0,
|
|
137728
|
+
const sourcePath = (0, import_path23.join)(sourceHome, fileName);
|
|
137729
|
+
const targetPath = (0, import_path23.join)(targetHome, fileName);
|
|
137483
137730
|
if (!fs57.existsSync(sourcePath)) continue;
|
|
137484
137731
|
try {
|
|
137485
137732
|
fs57.copyFileSync(sourcePath, targetPath);
|
|
@@ -139007,6 +139254,108 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
139007
139254
|
init_runtime_defaults();
|
|
139008
139255
|
init_snapshot3();
|
|
139009
139256
|
init_builders();
|
|
139257
|
+
init_dist2();
|
|
139258
|
+
init_logger();
|
|
139259
|
+
init_topics2();
|
|
139260
|
+
var FLEET_STATUS_ENV = "ADHDEV_SEQSCRIBE_FLEET_STATUS";
|
|
139261
|
+
var FLEET_STATUS_ENTRY_KIND = "adhdev.fleet.status";
|
|
139262
|
+
var MAX_INFLIGHT2 = 32;
|
|
139263
|
+
function resolveFleetStatusMode(env2 = process.env) {
|
|
139264
|
+
const raw = env2[FLEET_STATUS_ENV]?.trim().toLowerCase();
|
|
139265
|
+
if (!raw) return "off";
|
|
139266
|
+
if (raw === "off") return "off";
|
|
139267
|
+
if (raw === "shadow") return "shadow";
|
|
139268
|
+
warnOnce3(
|
|
139269
|
+
`unrecognized ${FLEET_STATUS_ENV}=${raw}; treating as 'off'. Valid values are 'shadow' and 'off' (default).`
|
|
139270
|
+
);
|
|
139271
|
+
return "off";
|
|
139272
|
+
}
|
|
139273
|
+
var counters3 = {
|
|
139274
|
+
written: 0,
|
|
139275
|
+
failed: 0,
|
|
139276
|
+
dropped: 0,
|
|
139277
|
+
oversized: 0
|
|
139278
|
+
};
|
|
139279
|
+
var activeNode3 = null;
|
|
139280
|
+
var activeMode2 = "off";
|
|
139281
|
+
var inflight2 = 0;
|
|
139282
|
+
var topicUsable = null;
|
|
139283
|
+
var warnedOnce3 = /* @__PURE__ */ new Set();
|
|
139284
|
+
function warnOnce3(message) {
|
|
139285
|
+
if (warnedOnce3.has(message)) return;
|
|
139286
|
+
warnedOnce3.add(message);
|
|
139287
|
+
LOG2.warn("Seqscribe", message);
|
|
139288
|
+
}
|
|
139289
|
+
function configureFleetStatusShadow(node, env2 = process.env) {
|
|
139290
|
+
activeNode3 = node;
|
|
139291
|
+
activeMode2 = resolveFleetStatusMode(env2);
|
|
139292
|
+
topicUsable = null;
|
|
139293
|
+
inflight2 = 0;
|
|
139294
|
+
if (node && activeMode2 === "shadow") {
|
|
139295
|
+
LOG2.info("Seqscribe", `fleet.status shadow armed writer=${node.writerId}`);
|
|
139296
|
+
}
|
|
139297
|
+
}
|
|
139298
|
+
function ensureTopic2(node) {
|
|
139299
|
+
if (topicUsable !== null) return topicUsable;
|
|
139300
|
+
const present = node.topics.some((d) => d.topic === FLEET_STATUS_TOPIC);
|
|
139301
|
+
topicUsable = present;
|
|
139302
|
+
if (!present) {
|
|
139303
|
+
LOG2.warn(
|
|
139304
|
+
"Seqscribe",
|
|
139305
|
+
`fleet.status shadow disabled \u2014 topic ${FLEET_STATUS_TOPIC} is not defined on this node`
|
|
139306
|
+
);
|
|
139307
|
+
}
|
|
139308
|
+
return present;
|
|
139309
|
+
}
|
|
139310
|
+
function recordFleetStatusShadow(entry) {
|
|
139311
|
+
try {
|
|
139312
|
+
const node = activeNode3;
|
|
139313
|
+
if (!node || activeMode2 === "off") return false;
|
|
139314
|
+
if (!ensureTopic2(node)) return false;
|
|
139315
|
+
if (inflight2 >= MAX_INFLIGHT2) {
|
|
139316
|
+
counters3.dropped++;
|
|
139317
|
+
warnOnce3(
|
|
139318
|
+
`fleet.status shadow shedding load \u2014 ${MAX_INFLIGHT2} appends in flight; status records are being dropped from the RING only (the WS status_report is unaffected)`
|
|
139319
|
+
);
|
|
139320
|
+
return false;
|
|
139321
|
+
}
|
|
139322
|
+
const payload = sanitizeJson(entry);
|
|
139323
|
+
const estimated = estimateEntryBytes({
|
|
139324
|
+
topic: FLEET_STATUS_TOPIC,
|
|
139325
|
+
kind: FLEET_STATUS_ENTRY_KIND,
|
|
139326
|
+
payload
|
|
139327
|
+
});
|
|
139328
|
+
const ceiling = resolveConstants().MAX_ENTRY_BYTES;
|
|
139329
|
+
if (estimated > ceiling) {
|
|
139330
|
+
counters3.oversized++;
|
|
139331
|
+
warnOnce3(
|
|
139332
|
+
`fleet.status shadow skipped an oversized record (further occurrences logged once): estimated=${estimated}B ceiling=${ceiling}B. The entry is a fixed set of scalars \u2014 this is a producer-shape bug, not a transport one.`
|
|
139333
|
+
);
|
|
139334
|
+
return false;
|
|
139335
|
+
}
|
|
139336
|
+
inflight2++;
|
|
139337
|
+
void node.node.log(FLEET_STATUS_TOPIC).append(FLEET_STATUS_ENTRY_KIND, payload).then(
|
|
139338
|
+
() => {
|
|
139339
|
+
inflight2--;
|
|
139340
|
+
counters3.written++;
|
|
139341
|
+
},
|
|
139342
|
+
(error48) => {
|
|
139343
|
+
inflight2--;
|
|
139344
|
+
counters3.failed++;
|
|
139345
|
+
warnOnce3(
|
|
139346
|
+
`fleet.status shadow append failed (further failures logged once): ${error48 instanceof Error ? error48.message : String(error48)}`
|
|
139347
|
+
);
|
|
139348
|
+
}
|
|
139349
|
+
);
|
|
139350
|
+
return true;
|
|
139351
|
+
} catch (error48) {
|
|
139352
|
+
counters3.failed++;
|
|
139353
|
+
warnOnce3(
|
|
139354
|
+
`fleet.status shadow threw synchronously (further throws logged once): ${error48 instanceof Error ? error48.message : String(error48)}`
|
|
139355
|
+
);
|
|
139356
|
+
return false;
|
|
139357
|
+
}
|
|
139358
|
+
}
|
|
139010
139359
|
function buildCloudP2PSummary(p2p) {
|
|
139011
139360
|
if (!p2p) return void 0;
|
|
139012
139361
|
const counter = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
@@ -139080,6 +139429,59 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
139080
139429
|
timestamp: timestamp2
|
|
139081
139430
|
};
|
|
139082
139431
|
}
|
|
139432
|
+
function countFleetSessions(sessions) {
|
|
139433
|
+
const list = Array.isArray(sessions) ? sessions : [];
|
|
139434
|
+
const counts = {
|
|
139435
|
+
ideCount: 0,
|
|
139436
|
+
cliCount: 0,
|
|
139437
|
+
acpCount: 0,
|
|
139438
|
+
idleCount: 0,
|
|
139439
|
+
generatingCount: 0,
|
|
139440
|
+
waitingApprovalCount: 0,
|
|
139441
|
+
erroredCount: 0
|
|
139442
|
+
};
|
|
139443
|
+
for (const raw of list) {
|
|
139444
|
+
const session = raw || {};
|
|
139445
|
+
if (!session.parentId) {
|
|
139446
|
+
if (session.kind === "workspace" && session.transport === "cdp-page") counts.ideCount++;
|
|
139447
|
+
else if (session.kind === "agent" && session.transport === "pty") counts.cliCount++;
|
|
139448
|
+
else if (session.kind === "agent" && session.transport === "acp") counts.acpCount++;
|
|
139449
|
+
}
|
|
139450
|
+
switch (session.status) {
|
|
139451
|
+
case "idle":
|
|
139452
|
+
counts.idleCount++;
|
|
139453
|
+
break;
|
|
139454
|
+
case "generating":
|
|
139455
|
+
counts.generatingCount++;
|
|
139456
|
+
break;
|
|
139457
|
+
// Both approval-shaped states land in one bucket: from a fleet tail's
|
|
139458
|
+
// point of view "a human must answer something" is the signal, and
|
|
139459
|
+
// splitting it would invite a consumer to watch only one of the two.
|
|
139460
|
+
case "waiting_approval":
|
|
139461
|
+
case "waiting_choice":
|
|
139462
|
+
counts.waitingApprovalCount++;
|
|
139463
|
+
break;
|
|
139464
|
+
case "error":
|
|
139465
|
+
counts.erroredCount++;
|
|
139466
|
+
break;
|
|
139467
|
+
default:
|
|
139468
|
+
break;
|
|
139469
|
+
}
|
|
139470
|
+
}
|
|
139471
|
+
return counts;
|
|
139472
|
+
}
|
|
139473
|
+
function fleetStatusEntry(input) {
|
|
139474
|
+
const seqscribeSummary = buildCloudSeqscribeSummary(input.seqscribe);
|
|
139475
|
+
const at = Number.isFinite(input.timestamp) ? new Date(input.timestamp).toISOString() : (/* @__PURE__ */ new Date()).toISOString();
|
|
139476
|
+
return {
|
|
139477
|
+
daemonId: input.daemonId,
|
|
139478
|
+
at,
|
|
139479
|
+
onlineState: input.onlineState,
|
|
139480
|
+
p2pActive: input.p2pActive === true,
|
|
139481
|
+
sessionCounts: countFleetSessions(input.sessions),
|
|
139482
|
+
...seqscribeSummary ? { seqscribe: seqscribeSummary } : {}
|
|
139483
|
+
};
|
|
139484
|
+
}
|
|
139083
139485
|
var SERVER_DEDUP_KEEPALIVE_REPORTS = 10;
|
|
139084
139486
|
var DaemonStatusReporter = class {
|
|
139085
139487
|
deps;
|
|
@@ -139343,6 +139745,20 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
139343
139745
|
);
|
|
139344
139746
|
}
|
|
139345
139747
|
}
|
|
139748
|
+
recordFleetStatusShadow(fleetStatusEntry({
|
|
139749
|
+
daemonId: this.deps.instanceId,
|
|
139750
|
+
sessions: payload.sessions,
|
|
139751
|
+
// Derived from what this process can actually observe: a live server
|
|
139752
|
+
// socket is `online`; no socket while P2P still carries traffic is a
|
|
139753
|
+
// daemon mid-reconnect rather than a dead one. `offline` is
|
|
139754
|
+
// effectively unreachable from here — `sendUnifiedStatusReport`
|
|
139755
|
+
// returns early when neither transport is up — and is kept in the
|
|
139756
|
+
// enum for a consumer that infers it from a stale `at`.
|
|
139757
|
+
onlineState: serverConnected ? "online" : p2pConnected ? "reconnecting" : "offline",
|
|
139758
|
+
p2pActive: p2pConnected,
|
|
139759
|
+
timestamp: now,
|
|
139760
|
+
seqscribe: this.deps.getSeqscribeStats?.() || void 0
|
|
139761
|
+
}));
|
|
139346
139762
|
if (opts?.p2pOnly) return;
|
|
139347
139763
|
if (!serverConnected || !serverConn) return;
|
|
139348
139764
|
const wsPayload = buildCloudStatusReportPayload(
|
|
@@ -146890,8 +147306,8 @@ data: ${JSON.stringify(msg.data)}
|
|
|
146890
147306
|
init_contract();
|
|
146891
147307
|
init_mesh_events();
|
|
146892
147308
|
init_mesh_reconcile_loop();
|
|
146893
|
-
var
|
|
146894
|
-
var
|
|
147309
|
+
var import_fs22 = require("fs");
|
|
147310
|
+
var import_path24 = require("path");
|
|
146895
147311
|
var import_crypto18 = require("crypto");
|
|
146896
147312
|
init_logger();
|
|
146897
147313
|
init_mesh_ledger();
|
|
@@ -146959,31 +147375,31 @@ data: ${JSON.stringify(msg.data)}
|
|
|
146959
147375
|
} catch {
|
|
146960
147376
|
return result;
|
|
146961
147377
|
}
|
|
146962
|
-
if (!(0,
|
|
147378
|
+
if (!(0, import_fs22.existsSync)(dir)) return result;
|
|
146963
147379
|
let names;
|
|
146964
147380
|
try {
|
|
146965
|
-
names = (0,
|
|
147381
|
+
names = (0, import_fs22.readdirSync)(dir);
|
|
146966
147382
|
} catch (e) {
|
|
146967
147383
|
LOG2.warn("MeshEvents", `Pending-events migration: cannot read ledger dir: ${e?.message || e}`);
|
|
146968
147384
|
return result;
|
|
146969
147385
|
}
|
|
146970
147386
|
for (const name of names) {
|
|
146971
147387
|
if (!isPendingEventsFile(name)) continue;
|
|
146972
|
-
const path63 = (0,
|
|
147388
|
+
const path63 = (0, import_path24.join)(dir, name);
|
|
146973
147389
|
result.filesScanned++;
|
|
146974
147390
|
const claimed = `${path63}.migrating`;
|
|
146975
147391
|
try {
|
|
146976
|
-
(0,
|
|
147392
|
+
(0, import_fs22.renameSync)(path63, claimed);
|
|
146977
147393
|
} catch {
|
|
146978
147394
|
continue;
|
|
146979
147395
|
}
|
|
146980
147396
|
let content;
|
|
146981
147397
|
try {
|
|
146982
|
-
content = (0,
|
|
147398
|
+
content = (0, import_fs22.readFileSync)(claimed, "utf-8");
|
|
146983
147399
|
} catch (e) {
|
|
146984
147400
|
LOG2.warn("MeshEvents", `Pending-events migration: cannot read ${name}; leaving it for the next boot: ${e?.message || e}`);
|
|
146985
147401
|
try {
|
|
146986
|
-
(0,
|
|
147402
|
+
(0, import_fs22.renameSync)(claimed, path63);
|
|
146987
147403
|
} catch {
|
|
146988
147404
|
}
|
|
146989
147405
|
result.filesRetained++;
|
|
@@ -146998,14 +147414,14 @@ data: ${JSON.stringify(msg.data)}
|
|
|
146998
147414
|
}
|
|
146999
147415
|
if (!allImported) {
|
|
147000
147416
|
try {
|
|
147001
|
-
(0,
|
|
147417
|
+
(0, import_fs22.renameSync)(claimed, path63);
|
|
147002
147418
|
} catch {
|
|
147003
147419
|
}
|
|
147004
147420
|
result.filesRetained++;
|
|
147005
147421
|
continue;
|
|
147006
147422
|
}
|
|
147007
147423
|
try {
|
|
147008
|
-
(0,
|
|
147424
|
+
(0, import_fs22.unlinkSync)(claimed);
|
|
147009
147425
|
result.filesRemoved++;
|
|
147010
147426
|
} catch (e) {
|
|
147011
147427
|
LOG2.warn("MeshEvents", `Pending-events migration: imported ${name} but could not unlink it: ${e?.message || e}`);
|
|
@@ -147163,20 +147579,20 @@ data: ${JSON.stringify(msg.data)}
|
|
|
147163
147579
|
};
|
|
147164
147580
|
}
|
|
147165
147581
|
init_require_whitelist();
|
|
147166
|
-
var
|
|
147167
|
-
var
|
|
147582
|
+
var import_fs23 = require("fs");
|
|
147583
|
+
var import_path25 = require("path");
|
|
147168
147584
|
init_config();
|
|
147169
147585
|
init_logger();
|
|
147170
147586
|
var FLEET_SECRET_FILE = "seqscribe-fleet-secret.json";
|
|
147171
147587
|
function fleetSecretPath(env2) {
|
|
147172
|
-
return (0,
|
|
147588
|
+
return (0, import_path25.join)(getConfigDir2(env2), FLEET_SECRET_FILE);
|
|
147173
147589
|
}
|
|
147174
147590
|
function loadStoredFleetSecret(env2) {
|
|
147175
147591
|
const path63 = fleetSecretPath(env2);
|
|
147176
|
-
if (!(0,
|
|
147592
|
+
if (!(0, import_fs23.existsSync)(path63)) return null;
|
|
147177
147593
|
let raw;
|
|
147178
147594
|
try {
|
|
147179
|
-
raw = (0,
|
|
147595
|
+
raw = (0, import_fs23.readFileSync)(path63, "utf-8");
|
|
147180
147596
|
} catch (err) {
|
|
147181
147597
|
LOG2.warn(
|
|
147182
147598
|
"Seqscribe",
|
|
@@ -147203,32 +147619,32 @@ data: ${JSON.stringify(msg.data)}
|
|
|
147203
147619
|
throw new Error("storeFleetSecret requires an integer version >= 1");
|
|
147204
147620
|
}
|
|
147205
147621
|
const dir = getConfigDir2(env2);
|
|
147206
|
-
if (!(0,
|
|
147207
|
-
(0,
|
|
147622
|
+
if (!(0, import_fs23.existsSync)(dir)) {
|
|
147623
|
+
(0, import_fs23.mkdirSync)(dir, { recursive: true, mode: 448 });
|
|
147208
147624
|
}
|
|
147209
|
-
const path63 = (0,
|
|
147625
|
+
const path63 = (0, import_path25.join)(dir, FLEET_SECRET_FILE);
|
|
147210
147626
|
const tmp = `${path63}.tmp-${process.pid}`;
|
|
147211
|
-
(0,
|
|
147627
|
+
(0, import_fs23.writeFileSync)(tmp, JSON.stringify({ secret, version: version2 }, null, 2), {
|
|
147212
147628
|
encoding: "utf-8",
|
|
147213
147629
|
mode: 384
|
|
147214
147630
|
});
|
|
147215
147631
|
try {
|
|
147216
|
-
(0,
|
|
147632
|
+
(0, import_fs23.renameSync)(tmp, path63);
|
|
147217
147633
|
} catch (err) {
|
|
147218
147634
|
try {
|
|
147219
|
-
(0,
|
|
147635
|
+
(0, import_fs23.unlinkSync)(tmp);
|
|
147220
147636
|
} catch {
|
|
147221
147637
|
}
|
|
147222
147638
|
throw err;
|
|
147223
147639
|
}
|
|
147224
147640
|
try {
|
|
147225
|
-
(0,
|
|
147641
|
+
(0, import_fs23.chmodSync)(path63, 384);
|
|
147226
147642
|
} catch {
|
|
147227
147643
|
}
|
|
147228
147644
|
LOG2.info("Seqscribe", `fleet secret stored (v${version2})`);
|
|
147229
147645
|
}
|
|
147230
|
-
var
|
|
147231
|
-
var
|
|
147646
|
+
var import_fs24 = require("fs");
|
|
147647
|
+
var import_path26 = require("path");
|
|
147232
147648
|
init_dist2();
|
|
147233
147649
|
init_config();
|
|
147234
147650
|
init_logger();
|
|
@@ -147238,12 +147654,12 @@ data: ${JSON.stringify(msg.data)}
|
|
|
147238
147654
|
var SEQSCRIBE_DB_NAME = "seqscribe.db";
|
|
147239
147655
|
var WRITER_ID_PREFIX = "adhdev";
|
|
147240
147656
|
function getSeqscribeDbPath() {
|
|
147241
|
-
return (0,
|
|
147657
|
+
return (0, import_path26.join)(getConfigDir2(), SEQSCRIBE_DB_NAME);
|
|
147242
147658
|
}
|
|
147243
147659
|
function openSeqscribeNode(opts = {}) {
|
|
147244
147660
|
const dbPath = opts.dbPath ?? getSeqscribeDbPath();
|
|
147245
|
-
const dir = (0,
|
|
147246
|
-
if (!(0,
|
|
147661
|
+
const dir = (0, import_path26.dirname)(dbPath);
|
|
147662
|
+
if (!(0, import_fs24.existsSync)(dir)) (0, import_fs24.mkdirSync)(dir, { recursive: true, mode: 448 });
|
|
147247
147663
|
const Database = loadBetterSqlite3();
|
|
147248
147664
|
const db = new Database(dbPath);
|
|
147249
147665
|
db.pragma("journal_mode = WAL");
|
|
@@ -147305,6 +147721,32 @@ data: ${JSON.stringify(msg.data)}
|
|
|
147305
147721
|
authority: authority.authority,
|
|
147306
147722
|
intervalMs: opts.finalityIntervalMs
|
|
147307
147723
|
}) : null;
|
|
147724
|
+
let unsubAnomaly = null;
|
|
147725
|
+
try {
|
|
147726
|
+
unsubAnomaly = node.onAnomaly((anomaly) => {
|
|
147727
|
+
try {
|
|
147728
|
+
if (anomaly.kind === "sync_stalled") {
|
|
147729
|
+
LOG2.warn(
|
|
147730
|
+
"Seqscribe",
|
|
147731
|
+
`sync stalled writer=${writerId} \u2014 WANT rounds toward a peer stopped progressing; check get_status_metadata seqscribe.stalledStreams / applyRejects`
|
|
147732
|
+
);
|
|
147733
|
+
} else if (anomaly.kind === "sync_hot") {
|
|
147734
|
+
LOG2.warn(
|
|
147735
|
+
"Seqscribe",
|
|
147736
|
+
`sync hot writer=${writerId} \u2014 bulk sync traffic crossed the rate window (informational, not throttled); see seqscribe.syncHotspots in get_status_metadata`
|
|
147737
|
+
);
|
|
147738
|
+
} else {
|
|
147739
|
+
LOG2.warn("Seqscribe", `anomaly kind=${anomaly.kind} writer=${writerId}`);
|
|
147740
|
+
}
|
|
147741
|
+
} catch {
|
|
147742
|
+
}
|
|
147743
|
+
});
|
|
147744
|
+
} catch (err) {
|
|
147745
|
+
LOG2.warn(
|
|
147746
|
+
"Seqscribe",
|
|
147747
|
+
`anomaly subscription failed: ${err instanceof Error ? err.message : String(err)}`
|
|
147748
|
+
);
|
|
147749
|
+
}
|
|
147308
147750
|
LOG2.info(
|
|
147309
147751
|
"Seqscribe",
|
|
147310
147752
|
`node open writer=${writerId} topics=${defs.length} authority=${authority ? "on" : "off"}${opts.isCoordinator ? " role=coordinator" : ""}`
|
|
@@ -147317,6 +147759,10 @@ data: ${JSON.stringify(msg.data)}
|
|
|
147317
147759
|
finalityLoop?.stop();
|
|
147318
147760
|
} catch {
|
|
147319
147761
|
}
|
|
147762
|
+
try {
|
|
147763
|
+
unsubAnomaly?.();
|
|
147764
|
+
} catch {
|
|
147765
|
+
}
|
|
147320
147766
|
try {
|
|
147321
147767
|
await node.close();
|
|
147322
147768
|
} catch (err) {
|
|
@@ -147474,6 +147920,41 @@ data: ${JSON.stringify(msg.data)}
|
|
|
147474
147920
|
if (peer.queuedData > maxQueued) maxQueued = peer.queuedData;
|
|
147475
147921
|
if (peer.state === "ready") peersReady++;
|
|
147476
147922
|
}
|
|
147923
|
+
let localDiagnostics = {};
|
|
147924
|
+
if (opts.includeLocalDiagnostics) {
|
|
147925
|
+
let applyRejects = 0;
|
|
147926
|
+
for (const topic of Object.values(stats.topics)) {
|
|
147927
|
+
for (const count of Object.values(topic.applyRejects ?? {})) {
|
|
147928
|
+
if (typeof count === "number" && Number.isFinite(count) && count > 0) {
|
|
147929
|
+
applyRejects += count;
|
|
147930
|
+
}
|
|
147931
|
+
}
|
|
147932
|
+
}
|
|
147933
|
+
let stalledStreams = 0;
|
|
147934
|
+
for (const peer of stats.peers) {
|
|
147935
|
+
const stalled = peer.stalledStreams;
|
|
147936
|
+
if (typeof stalled === "number" && Number.isFinite(stalled) && stalled > 0) {
|
|
147937
|
+
stalledStreams += stalled;
|
|
147938
|
+
}
|
|
147939
|
+
}
|
|
147940
|
+
const snap = opts.throughput;
|
|
147941
|
+
localDiagnostics = {
|
|
147942
|
+
applyRejects,
|
|
147943
|
+
stalledStreams,
|
|
147944
|
+
...snap ? {
|
|
147945
|
+
throughput: {
|
|
147946
|
+
intervalMs: snap.intervalMs,
|
|
147947
|
+
servedEntries: snap.totals.servedEntries,
|
|
147948
|
+
servedBytes: snap.totals.servedBytes,
|
|
147949
|
+
appliedEntries: snap.totals.appliedEntries,
|
|
147950
|
+
appliedBytes: snap.totals.appliedBytes,
|
|
147951
|
+
wantRoundsRequested: snap.totals.wantRoundsRequested,
|
|
147952
|
+
wantRoundsServed: snap.totals.wantRoundsServed
|
|
147953
|
+
},
|
|
147954
|
+
syncHotspots: snap.hotspots.map((h) => ({ ...h }))
|
|
147955
|
+
} : {}
|
|
147956
|
+
};
|
|
147957
|
+
}
|
|
147477
147958
|
return {
|
|
147478
147959
|
topics,
|
|
147479
147960
|
peers: stats.peers.length,
|
|
@@ -147492,9 +147973,119 @@ data: ${JSON.stringify(msg.data)}
|
|
|
147492
147973
|
parityRan: (opts.parity?.runs ?? 0) > 0,
|
|
147493
147974
|
parityMissingInShadowBucket: bucket(opts.parity?.missingInShadow ?? 0, BACKLOG_BUCKETS),
|
|
147494
147975
|
parityExtraInShadowBucket: bucket(opts.parity?.extraInShadow ?? 0, BACKLOG_BUCKETS),
|
|
147495
|
-
parityFieldMismatchBucket: bucket(opts.parity?.fieldMismatch ?? 0, BACKLOG_BUCKETS)
|
|
147976
|
+
parityFieldMismatchBucket: bucket(opts.parity?.fieldMismatch ?? 0, BACKLOG_BUCKETS),
|
|
147977
|
+
...localDiagnostics
|
|
147978
|
+
};
|
|
147979
|
+
}
|
|
147980
|
+
init_logger();
|
|
147981
|
+
var DEFAULT_COLLECT_INTERVAL_MS = 6e4;
|
|
147982
|
+
var SNAPSHOT_HOTSPOT_LIMIT = 5;
|
|
147983
|
+
var ZERO_TOTALS = {
|
|
147984
|
+
servedEntries: 0,
|
|
147985
|
+
servedBytes: 0,
|
|
147986
|
+
appliedEntries: 0,
|
|
147987
|
+
appliedBytes: 0,
|
|
147988
|
+
wantRoundsRequested: 0,
|
|
147989
|
+
wantRoundsServed: 0
|
|
147990
|
+
};
|
|
147991
|
+
function sumTotals(stats) {
|
|
147992
|
+
const totals = { ...ZERO_TOTALS };
|
|
147993
|
+
for (const topic of Object.values(stats.topics ?? {})) {
|
|
147994
|
+
const sync = topic?.sync;
|
|
147995
|
+
if (!sync) continue;
|
|
147996
|
+
totals.servedEntries += num(sync.servedEntries);
|
|
147997
|
+
totals.servedBytes += num(sync.servedBytes);
|
|
147998
|
+
totals.appliedEntries += num(sync.appliedEntries);
|
|
147999
|
+
totals.appliedBytes += num(sync.appliedBytes);
|
|
148000
|
+
totals.wantRoundsRequested += num(sync.wantRoundsRequested);
|
|
148001
|
+
totals.wantRoundsServed += num(sync.wantRoundsServed);
|
|
148002
|
+
}
|
|
148003
|
+
return totals;
|
|
148004
|
+
}
|
|
148005
|
+
function num(value) {
|
|
148006
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0;
|
|
148007
|
+
}
|
|
148008
|
+
function sumApplyRejects(stats) {
|
|
148009
|
+
let total = 0;
|
|
148010
|
+
for (const topic of Object.values(stats.topics ?? {})) {
|
|
148011
|
+
for (const count of Object.values(topic?.applyRejects ?? {})) {
|
|
148012
|
+
total += num(count);
|
|
148013
|
+
}
|
|
148014
|
+
}
|
|
148015
|
+
return total;
|
|
148016
|
+
}
|
|
148017
|
+
function sumStalledStreams(stats) {
|
|
148018
|
+
let total = 0;
|
|
148019
|
+
for (const peer of stats.peers ?? []) {
|
|
148020
|
+
total += num(peer?.stalledStreams);
|
|
148021
|
+
}
|
|
148022
|
+
return total;
|
|
148023
|
+
}
|
|
148024
|
+
function hasActivity(totals) {
|
|
148025
|
+
return totals.servedEntries > 0 || totals.appliedEntries > 0 || totals.servedBytes > 0 || totals.appliedBytes > 0 || totals.wantRoundsRequested > 0 || totals.wantRoundsServed > 0;
|
|
148026
|
+
}
|
|
148027
|
+
function fmtBytes(bytes) {
|
|
148028
|
+
if (bytes < 1024) return `${bytes}B`;
|
|
148029
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)}KiB`;
|
|
148030
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)}MiB`;
|
|
148031
|
+
}
|
|
148032
|
+
function startSeqscribeThroughputCollector(opts) {
|
|
148033
|
+
const intervalMs = opts.intervalMs ?? DEFAULT_COLLECT_INTERVAL_MS;
|
|
148034
|
+
const clock = opts.clock ?? (() => Date.now());
|
|
148035
|
+
const log = opts.log ?? ((level, message) => {
|
|
148036
|
+
if (level === "warn") LOG2.warn("Seqscribe", message);
|
|
148037
|
+
else LOG2.info("Seqscribe", message);
|
|
148038
|
+
});
|
|
148039
|
+
let current = null;
|
|
148040
|
+
let lastAt = null;
|
|
148041
|
+
let stopped = false;
|
|
148042
|
+
const collect = () => {
|
|
148043
|
+
if (stopped) return current;
|
|
148044
|
+
let stats;
|
|
148045
|
+
try {
|
|
148046
|
+
stats = opts.readStats();
|
|
148047
|
+
} catch (error48) {
|
|
148048
|
+
log(
|
|
148049
|
+
"warn",
|
|
148050
|
+
`throughput collect failed: ${error48 instanceof Error ? error48.message : String(error48)}`
|
|
148051
|
+
);
|
|
148052
|
+
return current;
|
|
148053
|
+
}
|
|
148054
|
+
const at = clock();
|
|
148055
|
+
const totals = sumTotals(stats);
|
|
148056
|
+
const snapshot = {
|
|
148057
|
+
at,
|
|
148058
|
+
intervalMs: lastAt === null ? intervalMs : Math.max(0, at - lastAt),
|
|
148059
|
+
totals,
|
|
148060
|
+
hotspots: (stats.syncHotspots ?? []).slice(0, SNAPSHOT_HOTSPOT_LIMIT).map((h) => ({ topic: h.topic, peerId: h.peerId, bytes: num(h.bytes) })),
|
|
148061
|
+
applyRejects: sumApplyRejects(stats),
|
|
148062
|
+
stalledStreams: sumStalledStreams(stats),
|
|
148063
|
+
stats
|
|
148064
|
+
};
|
|
148065
|
+
lastAt = at;
|
|
148066
|
+
current = snapshot;
|
|
148067
|
+
if (hasActivity(totals)) {
|
|
148068
|
+
const top = snapshot.hotspots[0];
|
|
148069
|
+
log(
|
|
148070
|
+
"info",
|
|
148071
|
+
`sync ${intervalMs / 1e3}s: served=${totals.servedEntries}e/${fmtBytes(totals.servedBytes)} applied=${totals.appliedEntries}e/${fmtBytes(totals.appliedBytes)} want=${totals.wantRoundsRequested}req/${totals.wantRoundsServed}served` + (top ? ` hot=${top.topic}@${top.peerId}/${fmtBytes(top.bytes)}` : "")
|
|
148072
|
+
);
|
|
148073
|
+
}
|
|
148074
|
+
return snapshot;
|
|
148075
|
+
};
|
|
148076
|
+
const timer = setInterval(collect, intervalMs);
|
|
148077
|
+
timer.unref?.();
|
|
148078
|
+
return {
|
|
148079
|
+
snapshot: () => current,
|
|
148080
|
+
collect,
|
|
148081
|
+
stop: () => {
|
|
148082
|
+
if (stopped) return;
|
|
148083
|
+
stopped = true;
|
|
148084
|
+
clearInterval(timer);
|
|
148085
|
+
}
|
|
147496
148086
|
};
|
|
147497
148087
|
}
|
|
148088
|
+
init_mesh_read_readiness();
|
|
147498
148089
|
init_mesh_dual_write();
|
|
147499
148090
|
init_mesh_parity();
|
|
147500
148091
|
init_mesh_config();
|
|
@@ -147865,6 +148456,7 @@ ${upgradeFailureNotice.notice}${supersededHint}`);
|
|
|
147865
148456
|
);
|
|
147866
148457
|
commandHandler.setAgentStreamManager(agentStreamManager);
|
|
147867
148458
|
let seqscribeNodeRef;
|
|
148459
|
+
let seqscribeCollector;
|
|
147868
148460
|
const router = new DaemonCommandRouter({
|
|
147869
148461
|
commandHandler,
|
|
147870
148462
|
cliManager,
|
|
@@ -147897,8 +148489,18 @@ ${upgradeFailureNotice.notice}${supersededHint}`);
|
|
|
147897
148489
|
try {
|
|
147898
148490
|
const dual = meshDualWriteCounters();
|
|
147899
148491
|
const parity = meshParityCounters();
|
|
147900
|
-
|
|
148492
|
+
const snapshot = seqscribeCollector?.snapshot() ?? null;
|
|
148493
|
+
if (!snapshot) return null;
|
|
148494
|
+
return summarizeSeqscribeStats(snapshot.stats, {
|
|
147901
148495
|
authorityEnabled: seqscribeNodeRef.authorityEnabled,
|
|
148496
|
+
// Local surface: `get_status_metadata` and the status
|
|
148497
|
+
// reporter share this closure, but the cloud projection
|
|
148498
|
+
// (buildCloudSeqscribeSummary) is a fixed-key allow-list
|
|
148499
|
+
// that drops every field below, so these never reach the
|
|
148500
|
+
// server. syncHotspots in particular carries topic names
|
|
148501
|
+
// and peer ids and is local-only by contract.
|
|
148502
|
+
includeLocalDiagnostics: true,
|
|
148503
|
+
throughput: snapshot,
|
|
147902
148504
|
dualWrite: {
|
|
147903
148505
|
active: isMeshDualWriteActive(),
|
|
147904
148506
|
failed: dual.failed,
|
|
@@ -147952,6 +148554,22 @@ ${upgradeFailureNotice.notice}${supersededHint}`);
|
|
|
147952
148554
|
};
|
|
147953
148555
|
components.seqscribeNode = tryOpenDaemonSeqscribeNode({ daemonId: config2.statusInstanceId });
|
|
147954
148556
|
seqscribeNodeRef = components.seqscribeNode;
|
|
148557
|
+
if (components.seqscribeNode) {
|
|
148558
|
+
try {
|
|
148559
|
+
const node = components.seqscribeNode;
|
|
148560
|
+
seqscribeCollector = startSeqscribeThroughputCollector({
|
|
148561
|
+
readStats: () => node.node.stats()
|
|
148562
|
+
});
|
|
148563
|
+
seqscribeCollector.collect();
|
|
148564
|
+
components.seqscribeCollector = seqscribeCollector;
|
|
148565
|
+
configureMeshReadReadinessCollector(seqscribeCollector);
|
|
148566
|
+
} catch (error48) {
|
|
148567
|
+
LOG2.warn(
|
|
148568
|
+
"Seqscribe",
|
|
148569
|
+
`throughput collector unavailable: ${error48 instanceof Error ? error48.message : String(error48)}`
|
|
148570
|
+
);
|
|
148571
|
+
}
|
|
148572
|
+
}
|
|
147955
148573
|
if (components.seqscribeNode) {
|
|
147956
148574
|
try {
|
|
147957
148575
|
components.seqscribeProbe = startConvergenceProbe(components.seqscribeNode, {
|
|
@@ -147968,6 +148586,7 @@ ${upgradeFailureNotice.notice}${supersededHint}`);
|
|
|
147968
148586
|
try {
|
|
147969
148587
|
configureMeshDualWrite(components.seqscribeNode ?? null);
|
|
147970
148588
|
configureMeshReadModel(components.seqscribeNode ?? null);
|
|
148589
|
+
configureFleetStatusShadow(components.seqscribeNode ?? null);
|
|
147971
148590
|
if (components.seqscribeNode) {
|
|
147972
148591
|
pruneStaleConsumersAtBoot();
|
|
147973
148592
|
components.seqscribeParityLoop = startMeshParityLoop(components.seqscribeNode);
|
|
@@ -148030,7 +148649,8 @@ ${upgradeFailureNotice.notice}${supersededHint}`);
|
|
|
148030
148649
|
eventLoopMonitor,
|
|
148031
148650
|
seqscribeNode,
|
|
148032
148651
|
seqscribeProbe,
|
|
148033
|
-
seqscribeParityLoop
|
|
148652
|
+
seqscribeParityLoop,
|
|
148653
|
+
seqscribeCollector
|
|
148034
148654
|
} = components;
|
|
148035
148655
|
poller.stop();
|
|
148036
148656
|
cdpInitializer.stop();
|
|
@@ -148058,6 +148678,14 @@ ${upgradeFailureNotice.notice}${supersededHint}`);
|
|
|
148058
148678
|
seqscribeProbe?.stop();
|
|
148059
148679
|
} catch {
|
|
148060
148680
|
}
|
|
148681
|
+
try {
|
|
148682
|
+
seqscribeCollector?.stop();
|
|
148683
|
+
} catch {
|
|
148684
|
+
}
|
|
148685
|
+
try {
|
|
148686
|
+
configureMeshReadReadinessCollector(null);
|
|
148687
|
+
} catch {
|
|
148688
|
+
}
|
|
148061
148689
|
try {
|
|
148062
148690
|
seqscribeParityLoop?.stop();
|
|
148063
148691
|
} catch {
|
|
@@ -148066,6 +148694,10 @@ ${upgradeFailureNotice.notice}${supersededHint}`);
|
|
|
148066
148694
|
configureMeshDualWrite(null);
|
|
148067
148695
|
} catch {
|
|
148068
148696
|
}
|
|
148697
|
+
try {
|
|
148698
|
+
configureFleetStatusShadow(null);
|
|
148699
|
+
} catch {
|
|
148700
|
+
}
|
|
148069
148701
|
try {
|
|
148070
148702
|
configureMeshReadModel(null);
|
|
148071
148703
|
} catch {
|