@adhdev/daemon-standalone 1.0.58-rc.27 → 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 +1564 -602
- 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,12 +51012,20 @@ 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
|
}
|
|
51018
51026
|
});
|
|
51019
51027
|
var require_canonicalize = __commonJS2({
|
|
51020
|
-
"../../node_modules/canonicalize/lib/canonicalize.js"(exports22, module22) {
|
|
51028
|
+
"../../vendor/seqscribe/node_modules/canonicalize/lib/canonicalize.js"(exports22, module22) {
|
|
51021
51029
|
"use strict";
|
|
51022
51030
|
module22.exports = function serialize(object2) {
|
|
51023
51031
|
if (typeof object2 === "number" && isNaN(object2)) {
|
|
@@ -51127,7 +51135,7 @@ The instruction it carried was never delivered to anyone. If it still matters, r
|
|
|
51127
51135
|
var hexes;
|
|
51128
51136
|
var Hash;
|
|
51129
51137
|
var init_utils = __esm2({
|
|
51130
|
-
"../../node_modules/@noble/hashes/esm/utils.js"() {
|
|
51138
|
+
"../../vendor/seqscribe/node_modules/@noble/hashes/esm/utils.js"() {
|
|
51131
51139
|
"use strict";
|
|
51132
51140
|
hasHexBuiltin = /* @__PURE__ */ (() => (
|
|
51133
51141
|
// @ts-ignore
|
|
@@ -51159,7 +51167,7 @@ The instruction it carried was never delivered to anyone. If it still matters, r
|
|
|
51159
51167
|
var HashMD;
|
|
51160
51168
|
var SHA256_IV;
|
|
51161
51169
|
var init_md = __esm2({
|
|
51162
|
-
"../../node_modules/@noble/hashes/esm/_md.js"() {
|
|
51170
|
+
"../../vendor/seqscribe/node_modules/@noble/hashes/esm/_md.js"() {
|
|
51163
51171
|
"use strict";
|
|
51164
51172
|
init_utils();
|
|
51165
51173
|
HashMD = class extends Hash {
|
|
@@ -51269,7 +51277,7 @@ The instruction it carried was never delivered to anyone. If it still matters, r
|
|
|
51269
51277
|
var SHA256;
|
|
51270
51278
|
var sha256;
|
|
51271
51279
|
var init_sha2 = __esm2({
|
|
51272
|
-
"../../node_modules/@noble/hashes/esm/sha2.js"() {
|
|
51280
|
+
"../../vendor/seqscribe/node_modules/@noble/hashes/esm/sha2.js"() {
|
|
51273
51281
|
"use strict";
|
|
51274
51282
|
init_md();
|
|
51275
51283
|
init_utils();
|
|
@@ -51415,7 +51423,7 @@ The instruction it carried was never delivered to anyone. If it still matters, r
|
|
|
51415
51423
|
});
|
|
51416
51424
|
var sha2562;
|
|
51417
51425
|
var init_sha256 = __esm2({
|
|
51418
|
-
"../../node_modules/@noble/hashes/esm/sha256.js"() {
|
|
51426
|
+
"../../vendor/seqscribe/node_modules/@noble/hashes/esm/sha256.js"() {
|
|
51419
51427
|
"use strict";
|
|
51420
51428
|
init_sha2();
|
|
51421
51429
|
sha2562 = sha256;
|
|
@@ -52009,9 +52017,20 @@ The instruction it carried was never delivered to anyone. If it still matters, r
|
|
|
52009
52017
|
});
|
|
52010
52018
|
function betterSqlite3Handle(db, lockDb) {
|
|
52011
52019
|
let owned = false;
|
|
52020
|
+
const stmts = /* @__PURE__ */ new Map();
|
|
52021
|
+
const prep = (sql) => {
|
|
52022
|
+
let s2 = stmts.get(sql);
|
|
52023
|
+
if (s2 === void 0) {
|
|
52024
|
+
if (stmts.size >= 512)
|
|
52025
|
+
stmts.clear();
|
|
52026
|
+
s2 = db.prepare(sql);
|
|
52027
|
+
stmts.set(sql, s2);
|
|
52028
|
+
}
|
|
52029
|
+
return s2;
|
|
52030
|
+
};
|
|
52012
52031
|
return {
|
|
52013
52032
|
run(sql, params = []) {
|
|
52014
|
-
const stmt =
|
|
52033
|
+
const stmt = prep(sql);
|
|
52015
52034
|
if (stmt.reader) {
|
|
52016
52035
|
stmt.all(...params);
|
|
52017
52036
|
return { changes: 0, lastInsertRowid: 0 };
|
|
@@ -52020,10 +52039,10 @@ The instruction it carried was never delivered to anyone. If it still matters, r
|
|
|
52020
52039
|
return { changes: r.changes, lastInsertRowid: r.lastInsertRowid };
|
|
52021
52040
|
},
|
|
52022
52041
|
get(sql, params = []) {
|
|
52023
|
-
return
|
|
52042
|
+
return prep(sql).get(...params);
|
|
52024
52043
|
},
|
|
52025
52044
|
all(sql, params = []) {
|
|
52026
|
-
return
|
|
52045
|
+
return prep(sql).all(...params);
|
|
52027
52046
|
},
|
|
52028
52047
|
transaction(fn) {
|
|
52029
52048
|
return db.transaction(fn)();
|
|
@@ -52063,7 +52082,7 @@ The instruction it carried was never delivered to anyone. If it still matters, r
|
|
|
52063
52082
|
var HMAC;
|
|
52064
52083
|
var hmac;
|
|
52065
52084
|
var init_hmac = __esm2({
|
|
52066
|
-
"../../node_modules/@noble/hashes/esm/hmac.js"() {
|
|
52085
|
+
"../../vendor/seqscribe/node_modules/@noble/hashes/esm/hmac.js"() {
|
|
52067
52086
|
"use strict";
|
|
52068
52087
|
init_utils();
|
|
52069
52088
|
HMAC = class extends Hash {
|
|
@@ -52285,9 +52304,15 @@ The instruction it carried was never delivered to anyone. If it still matters, r
|
|
|
52285
52304
|
this.deps.timers.clearTimeout(c.retryTimer);
|
|
52286
52305
|
c.retryTimer = null;
|
|
52287
52306
|
}
|
|
52307
|
+
this.rejectWaiters(c, misuse("node closed before catch-up"));
|
|
52288
52308
|
}
|
|
52289
52309
|
this.consumers.clear();
|
|
52290
52310
|
}
|
|
52311
|
+
rejectWaiters(c, err) {
|
|
52312
|
+
const ws = c.waiters.splice(0);
|
|
52313
|
+
for (const w of ws)
|
|
52314
|
+
w.reject(err);
|
|
52315
|
+
}
|
|
52291
52316
|
onEntry(topic, name, cb) {
|
|
52292
52317
|
if (this.closed)
|
|
52293
52318
|
throw misuse("node is closed");
|
|
@@ -52307,7 +52332,8 @@ The instruction it carried was never delivered to anyone. If it still matters, r
|
|
|
52307
52332
|
rerun: false,
|
|
52308
52333
|
failures: 0,
|
|
52309
52334
|
retryTimer: null,
|
|
52310
|
-
gone: false
|
|
52335
|
+
gone: false,
|
|
52336
|
+
waiters: []
|
|
52311
52337
|
};
|
|
52312
52338
|
this.consumers.set(key2, c);
|
|
52313
52339
|
this.pump(c);
|
|
@@ -52315,9 +52341,102 @@ The instruction it carried was never delivered to anyone. If it still matters, r
|
|
|
52315
52341
|
c.gone = true;
|
|
52316
52342
|
if (c.retryTimer !== null)
|
|
52317
52343
|
this.deps.timers.clearTimeout(c.retryTimer);
|
|
52344
|
+
this.rejectWaiters(c, misuse(`consumer unsubscribed before catch-up: ${key2}`));
|
|
52318
52345
|
this.consumers.delete(key2);
|
|
52319
52346
|
};
|
|
52320
52347
|
}
|
|
52348
|
+
// ---- durable-consumer lifecycle (proposals-v3.5 P17–P19) ----
|
|
52349
|
+
isActive(topic, name) {
|
|
52350
|
+
return this.consumers.has(`${topic} ${name}`);
|
|
52351
|
+
}
|
|
52352
|
+
assertInactive(topic, name, op) {
|
|
52353
|
+
if (this.closed)
|
|
52354
|
+
throw misuse("node is closed");
|
|
52355
|
+
this.deps.topics.get(topic);
|
|
52356
|
+
if (this.consumers.has(`${topic} ${name}`))
|
|
52357
|
+
throw misuse(`${op} on active consumer ${topic} ${name} \u2014 unsubscribe first`);
|
|
52358
|
+
}
|
|
52359
|
+
// P17: discard-derived-state rebuild for the SAME stable consumer name.
|
|
52360
|
+
// Inactive-only (registration would race the cursor write); the next
|
|
52361
|
+
// onEntry with this name resumes at the installed boundary. NOTE: the reset
|
|
52362
|
+
// materializes a cursor row, which gates §7.6 archiving from this moment —
|
|
52363
|
+
// re-register promptly, or the row ages into consumer_abandoned.
|
|
52364
|
+
resetConsumer(topic, name, o) {
|
|
52365
|
+
this.assertInactive(topic, name, "resetConsumer");
|
|
52366
|
+
const from = o?.from ?? "earliest-retained";
|
|
52367
|
+
const existed = this.deps.store.cursorsForTopic(topic).some((c) => c.consumer === name);
|
|
52368
|
+
const replayFromRowid = from === "head" ? this.deps.store.maxRowid(topic) : 0;
|
|
52369
|
+
this.deps.store.cursorSet(name, topic, replayFromRowid, new Date(this.deps.clock()).toISOString());
|
|
52370
|
+
return {
|
|
52371
|
+
existed,
|
|
52372
|
+
from,
|
|
52373
|
+
replayFromRowid,
|
|
52374
|
+
archivedRows: from === "earliest-retained" ? this.deps.store.archivedCount(topic) : 0
|
|
52375
|
+
};
|
|
52376
|
+
}
|
|
52377
|
+
// P18: explicit durable-cursor deletion — never implicit (forgetting a
|
|
52378
|
+
// cursor changes at-least-once restart semantics). Inactive-only; a deleted
|
|
52379
|
+
// cursor no longer gates archiving, so the archive floor re-evaluates.
|
|
52380
|
+
deleteConsumer(topic, name) {
|
|
52381
|
+
this.assertInactive(topic, name, "deleteConsumer");
|
|
52382
|
+
const existed = this.deps.store.cursorsForTopic(topic).some((c) => c.consumer === name);
|
|
52383
|
+
if (existed) {
|
|
52384
|
+
this.deps.store.cursorDelete(name, topic);
|
|
52385
|
+
this.onAdvance?.(topic);
|
|
52386
|
+
}
|
|
52387
|
+
return { existed };
|
|
52388
|
+
}
|
|
52389
|
+
listConsumers(topic) {
|
|
52390
|
+
if (this.closed)
|
|
52391
|
+
throw misuse("node is closed");
|
|
52392
|
+
this.deps.topics.get(topic);
|
|
52393
|
+
return this.deps.store.cursorsForTopic(topic).map((c) => ({ ...c, active: this.isActive(topic, c.consumer) }));
|
|
52394
|
+
}
|
|
52395
|
+
// P18 GC: deliberate cleanup of versioned/renamed consumers. Only inactive
|
|
52396
|
+
// cursors are eligible; filters compose (prefix AND inactiveBefore).
|
|
52397
|
+
pruneConsumers(topic, o) {
|
|
52398
|
+
if (this.closed)
|
|
52399
|
+
throw misuse("node is closed");
|
|
52400
|
+
this.deps.topics.get(topic);
|
|
52401
|
+
const pruned = [];
|
|
52402
|
+
for (const c of this.deps.store.cursorsForTopic(topic)) {
|
|
52403
|
+
if (this.isActive(topic, c.consumer))
|
|
52404
|
+
continue;
|
|
52405
|
+
if (o?.prefix !== void 0 && !c.consumer.startsWith(o.prefix))
|
|
52406
|
+
continue;
|
|
52407
|
+
if (o?.inactiveBefore !== void 0) {
|
|
52408
|
+
const at = Date.parse(c.updatedAt);
|
|
52409
|
+
if (!Number.isFinite(at) || at >= o.inactiveBefore)
|
|
52410
|
+
continue;
|
|
52411
|
+
}
|
|
52412
|
+
this.deps.store.cursorDelete(c.consumer, topic);
|
|
52413
|
+
pruned.push(c.consumer);
|
|
52414
|
+
}
|
|
52415
|
+
if (pruned.length > 0)
|
|
52416
|
+
this.onAdvance?.(topic);
|
|
52417
|
+
return pruned;
|
|
52418
|
+
}
|
|
52419
|
+
// P19: deterministic caught-up signal. Snapshots the topic head NOW and
|
|
52420
|
+
// resolves once the durable cursor reaches it (i.e. every entry through that
|
|
52421
|
+
// head has completed its callback); later appends start a new interval.
|
|
52422
|
+
// Callback failure/backoff delays resolution by construction (the cursor
|
|
52423
|
+
// does not advance); unsubscribe and node close reject.
|
|
52424
|
+
caughtUp(topic, name) {
|
|
52425
|
+
try {
|
|
52426
|
+
if (this.closed)
|
|
52427
|
+
throw misuse("node is closed");
|
|
52428
|
+
this.deps.topics.get(topic);
|
|
52429
|
+
const c = this.consumers.get(`${topic} ${name}`);
|
|
52430
|
+
if (!c)
|
|
52431
|
+
throw misuse(`caughtUp on unregistered consumer ${topic} ${name}`);
|
|
52432
|
+
const through = this.deps.store.maxRowid(topic);
|
|
52433
|
+
if (this.deps.store.cursorGet(name, topic) >= through)
|
|
52434
|
+
return Promise.resolve({ throughRowid: through });
|
|
52435
|
+
return new Promise((resolve31, reject) => c.waiters.push({ through, resolve: resolve31, reject }));
|
|
52436
|
+
} catch (e) {
|
|
52437
|
+
return Promise.reject(e);
|
|
52438
|
+
}
|
|
52439
|
+
}
|
|
52321
52440
|
notifyApplied(topic) {
|
|
52322
52441
|
for (const c of this.consumers.values()) {
|
|
52323
52442
|
if (c.topic === topic)
|
|
@@ -52379,6 +52498,14 @@ The instruction it carried was never delivered to anyone. If it still matters, r
|
|
|
52379
52498
|
c.failures = 0;
|
|
52380
52499
|
this.deps.store.cursorSet(c.name, c.topic, rowid, new Date(this.deps.clock()).toISOString());
|
|
52381
52500
|
onProgress();
|
|
52501
|
+
if (c.waiters.length > 0) {
|
|
52502
|
+
const done = c.waiters.filter((w) => rowid >= w.through);
|
|
52503
|
+
if (done.length > 0) {
|
|
52504
|
+
c.waiters = c.waiters.filter((w) => rowid < w.through);
|
|
52505
|
+
for (const w of done)
|
|
52506
|
+
w.resolve({ throughRowid: w.through });
|
|
52507
|
+
}
|
|
52508
|
+
}
|
|
52382
52509
|
}
|
|
52383
52510
|
}
|
|
52384
52511
|
}
|
|
@@ -55888,6 +56015,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
55888
56015
|
});
|
|
55889
56016
|
var MAX_WANT_CONCURRENT;
|
|
55890
56017
|
var ENTRIES_BATCH_MAX;
|
|
56018
|
+
var SYNC_HOTSPOT_TOP_N;
|
|
55891
56019
|
var SyncEngine;
|
|
55892
56020
|
var init_sync = __esm2({
|
|
55893
56021
|
"../../vendor/seqscribe/dist/sync.js"() {
|
|
@@ -55898,9 +56026,24 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
55898
56026
|
init_session();
|
|
55899
56027
|
MAX_WANT_CONCURRENT = 4;
|
|
55900
56028
|
ENTRIES_BATCH_MAX = 100;
|
|
56029
|
+
SYNC_HOTSPOT_TOP_N = 5;
|
|
55901
56030
|
SyncEngine = class {
|
|
55902
56031
|
o;
|
|
55903
56032
|
peers = /* @__PURE__ */ new Map();
|
|
56033
|
+
// P22 observability: cumulative non-applied wire-apply outcomes per topic
|
|
56034
|
+
// (rejected_finality, sealed, forked, dropped_overflow, error) — the spin
|
|
56035
|
+
// was invisible precisely because rejects were silently discarded
|
|
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;
|
|
55904
56047
|
finalityHub = null;
|
|
55905
56048
|
subHub = null;
|
|
55906
56049
|
directiveHub = null;
|
|
@@ -56004,6 +56147,8 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56004
56147
|
wantQueue: [],
|
|
56005
56148
|
wantedStreams: /* @__PURE__ */ new Set(),
|
|
56006
56149
|
recoveryProgress: /* @__PURE__ */ new Map(),
|
|
56150
|
+
syncProgress: /* @__PURE__ */ new Map(),
|
|
56151
|
+
stalled: /* @__PURE__ */ new Set(),
|
|
56007
56152
|
antiEntropyTimer: null,
|
|
56008
56153
|
probes: /* @__PURE__ */ new Map(),
|
|
56009
56154
|
known: /* @__PURE__ */ new Map(),
|
|
@@ -56030,9 +56175,63 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56030
56175
|
peerId: ps.session.peerId,
|
|
56031
56176
|
state: ps.session.state(),
|
|
56032
56177
|
dirtyStreams: ps.dirty.size,
|
|
56033
|
-
queuedData: ps.session.queuedData()
|
|
56178
|
+
queuedData: ps.session.queuedData(),
|
|
56179
|
+
stalledStreams: ps.stalled.size
|
|
56034
56180
|
}));
|
|
56035
56181
|
}
|
|
56182
|
+
rejectStats(topic) {
|
|
56183
|
+
return { ...this.rejects.get(topic) ?? {} };
|
|
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
|
+
}
|
|
56036
56235
|
// ---- lifecycle ----
|
|
56037
56236
|
onReady(s2) {
|
|
56038
56237
|
const ps = this.peers.get(s2);
|
|
@@ -56213,6 +56412,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56213
56412
|
}));
|
|
56214
56413
|
if (!accepted)
|
|
56215
56414
|
return;
|
|
56415
|
+
this.noteThroughput(d.topic, ps.session.peerId, batch.length, bytes, "served");
|
|
56216
56416
|
ps.known.set(key2, last.seq);
|
|
56217
56417
|
if (done)
|
|
56218
56418
|
ps.dirty.delete(key2);
|
|
@@ -56257,6 +56457,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56257
56457
|
fromSeq: recovery ? recoveryFrom : head.contigSeq + 1
|
|
56258
56458
|
};
|
|
56259
56459
|
ps.activeWants.set(req, want);
|
|
56460
|
+
this.counters(want.topic).wantRoundsRequested += 1;
|
|
56260
56461
|
ps.session.request(`WANT:${req}`, () => ({
|
|
56261
56462
|
t: "WANT",
|
|
56262
56463
|
req,
|
|
@@ -56379,6 +56580,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56379
56580
|
ps.session.sendControl({ t: "ERR", code: "ERR_ACL_DENIED", ref: m.topic });
|
|
56380
56581
|
return;
|
|
56381
56582
|
}
|
|
56583
|
+
this.counters(m.topic).wantRoundsServed += 1;
|
|
56382
56584
|
if (this.snapshotHub?.maybeOffer(ps.session, m.topic, m.writer, m.fromSeq)) {
|
|
56383
56585
|
const contig = this.o.core.getStream(m.topic, m.writer).contigSeq;
|
|
56384
56586
|
ps.session.sendData((mid) => ({
|
|
@@ -56443,6 +56645,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56443
56645
|
}));
|
|
56444
56646
|
if (!accepted)
|
|
56445
56647
|
return;
|
|
56648
|
+
this.noteThroughput(m.topic, ps.session.peerId, batch.length, bytes, "served");
|
|
56446
56649
|
from = last.seq + 1;
|
|
56447
56650
|
}
|
|
56448
56651
|
}
|
|
@@ -56468,6 +56671,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56468
56671
|
if ((ps.known.get(key2) ?? 0) < m.toSeq)
|
|
56469
56672
|
ps.known.set(key2, m.toSeq);
|
|
56470
56673
|
const applies = [];
|
|
56674
|
+
const costs = [];
|
|
56471
56675
|
for (const raw of m.entries) {
|
|
56472
56676
|
let entry;
|
|
56473
56677
|
try {
|
|
@@ -56479,19 +56683,35 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56479
56683
|
}
|
|
56480
56684
|
if (entry.topic !== m.topic || entry.writer !== m.writer)
|
|
56481
56685
|
continue;
|
|
56482
|
-
|
|
56483
|
-
|
|
56484
|
-
|
|
56686
|
+
costs.push(utf8ByteLength(JSON.stringify(entry)));
|
|
56687
|
+
applies.push(this.o.core.applyExternal(entry, ps.session.peerId).catch(() => "error"));
|
|
56688
|
+
}
|
|
56689
|
+
void Promise.all(applies).then((results) => {
|
|
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];
|
|
56697
|
+
continue;
|
|
56698
|
+
}
|
|
56699
|
+
const rec = this.rejects.get(m.topic) ?? {};
|
|
56700
|
+
rec[r] = (rec[r] ?? 0) + 1;
|
|
56701
|
+
this.rejects.set(m.topic, rec);
|
|
56702
|
+
}
|
|
56703
|
+
if (appliedN > 0)
|
|
56704
|
+
this.noteThroughput(m.topic, ps.session.peerId, appliedN, appliedB, "applied");
|
|
56485
56705
|
if (m.req !== void 0 && m.done) {
|
|
56486
56706
|
const want = ps.activeWants.get(m.req);
|
|
56487
56707
|
this.finishWant(ps, m.req);
|
|
56488
56708
|
if (want) {
|
|
56489
56709
|
const head = this.o.core.getStream(m.topic, m.writer);
|
|
56490
56710
|
const target = this.o.core.recoveryTarget(m.topic, m.writer);
|
|
56711
|
+
const skey = `${m.topic} ${m.writer}`;
|
|
56491
56712
|
if (target) {
|
|
56492
|
-
const
|
|
56493
|
-
|
|
56494
|
-
ps.recoveryProgress.set(key3, head.contigSeq);
|
|
56713
|
+
const before = ps.recoveryProgress.get(skey);
|
|
56714
|
+
ps.recoveryProgress.set(skey, head.contigSeq);
|
|
56495
56715
|
if (before !== void 0 && before >= head.contigSeq)
|
|
56496
56716
|
this.o.core.reportCanonicalUnavailable(m.topic, m.writer);
|
|
56497
56717
|
else
|
|
@@ -56499,8 +56719,22 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
56499
56719
|
} else if (head.sealReason === null && m.toSeq > head.contigSeq) {
|
|
56500
56720
|
const cert = this.o.core.getCert(m.topic);
|
|
56501
56721
|
const awaitingSnapshot = cert !== null && (cert.cut[m.writer]?.seq ?? 0) > head.contigSeq;
|
|
56502
|
-
if (!awaitingSnapshot)
|
|
56503
|
-
|
|
56722
|
+
if (!awaitingSnapshot) {
|
|
56723
|
+
const before = ps.syncProgress.get(skey);
|
|
56724
|
+
ps.syncProgress.set(skey, head.contigSeq);
|
|
56725
|
+
if (before !== void 0 && before >= head.contigSeq) {
|
|
56726
|
+
if (!ps.stalled.has(skey)) {
|
|
56727
|
+
ps.stalled.add(skey);
|
|
56728
|
+
this.o.emitAnomaly({ kind: "sync_stalled" });
|
|
56729
|
+
}
|
|
56730
|
+
} else {
|
|
56731
|
+
ps.stalled.delete(skey);
|
|
56732
|
+
this.queueWant(ps, m.topic, m.writer);
|
|
56733
|
+
}
|
|
56734
|
+
}
|
|
56735
|
+
} else {
|
|
56736
|
+
ps.syncProgress.delete(skey);
|
|
56737
|
+
ps.stalled.delete(skey);
|
|
56504
56738
|
}
|
|
56505
56739
|
}
|
|
56506
56740
|
}
|
|
@@ -57211,8 +57445,52 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57211
57445
|
store.close();
|
|
57212
57446
|
}
|
|
57213
57447
|
};
|
|
57448
|
+
const SCAN_DEFAULT_LIMIT = 500;
|
|
57449
|
+
const SCAN_MAX_LIMIT = 1e4;
|
|
57450
|
+
const scanEntries = (topic, o = {}) => {
|
|
57451
|
+
if (closed)
|
|
57452
|
+
throw misuse("node is closed");
|
|
57453
|
+
topics.get(topic);
|
|
57454
|
+
const limit = Math.min(Math.max(1, Math.floor(o.limit ?? SCAN_DEFAULT_LIMIT)), SCAN_MAX_LIMIT);
|
|
57455
|
+
if (o.writer !== void 0) {
|
|
57456
|
+
if (o.after !== void 0 || o.through !== void 0)
|
|
57457
|
+
throw misuse("scanEntries: writer form takes fromSeq/toSeq, not after/through");
|
|
57458
|
+
const head = core2.getStream(topic, o.writer);
|
|
57459
|
+
const fromSeq = o.fromSeq ?? 1;
|
|
57460
|
+
const toSeq = o.toSeq ?? head.contigSeq;
|
|
57461
|
+
if (toSeq < fromSeq)
|
|
57462
|
+
return { entries: [], complete: true, truncatedBelow: false };
|
|
57463
|
+
const windowEnd = Math.min(toSeq, fromSeq + limit - 1);
|
|
57464
|
+
const bySeq = /* @__PURE__ */ new Map();
|
|
57465
|
+
for (const e of store.archivedEntries(topic, o.writer, fromSeq, windowEnd))
|
|
57466
|
+
bySeq.set(e.seq, e);
|
|
57467
|
+
for (const { entry } of store.entriesRange(topic, o.writer, fromSeq, windowEnd))
|
|
57468
|
+
bySeq.set(entry.seq, entry);
|
|
57469
|
+
const entries2 = [...bySeq.values()].sort((a, b) => a.seq - b.seq);
|
|
57470
|
+
const complete2 = windowEnd >= toSeq;
|
|
57471
|
+
const firstAvail = entries2[0]?.seq;
|
|
57472
|
+
const truncatedBelow2 = firstAvail !== void 0 ? firstAvail > fromSeq : head.contigSeq >= fromSeq;
|
|
57473
|
+
const r2 = { entries: entries2, complete: complete2, truncatedBelow: truncatedBelow2 };
|
|
57474
|
+
if (!complete2)
|
|
57475
|
+
r2.nextFromSeq = windowEnd + 1;
|
|
57476
|
+
return r2;
|
|
57477
|
+
}
|
|
57478
|
+
if (o.fromSeq !== void 0 || o.toSeq !== void 0)
|
|
57479
|
+
throw misuse("scanEntries: fromSeq/toSeq require writer");
|
|
57480
|
+
const fetched = store.entriesAfterOrder(topic, o.after ?? null, limit + 1);
|
|
57481
|
+
const within = o.through ? fetched.filter((e) => orderCompare(orderOf(e), o.through) <= 0) : fetched;
|
|
57482
|
+
const entries = within.slice(0, limit);
|
|
57483
|
+
const complete = within.length <= limit && (within.length < fetched.length || fetched.length <= limit);
|
|
57484
|
+
const cert = core2.getCert(topic);
|
|
57485
|
+
const truncatedBelow = store.archivedCount(topic) > 0 && (o.after === void 0 || cert !== null && orderCompare(o.after, cert.order) < 0);
|
|
57486
|
+
const r = { entries, complete, truncatedBelow };
|
|
57487
|
+
if (!complete && entries.length > 0)
|
|
57488
|
+
r.nextAfter = orderOf(entries[entries.length - 1]);
|
|
57489
|
+
return r;
|
|
57490
|
+
};
|
|
57214
57491
|
const stats = () => {
|
|
57215
|
-
const
|
|
57492
|
+
const interval = sync.drainIntervalStats();
|
|
57493
|
+
const out = { topics: {}, peers: sync.peerStats(), syncHotspots: interval.hotspots };
|
|
57216
57494
|
const now = clock();
|
|
57217
57495
|
for (const topic of topics.list()) {
|
|
57218
57496
|
const cert = core2.getCert(topic);
|
|
@@ -57232,13 +57510,34 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57232
57510
|
archived: store.archivedCount(topic),
|
|
57233
57511
|
finalityGeneration: cert?.generation ?? null,
|
|
57234
57512
|
certOrderAgeMs: cert ? Math.max(0, now - cert.order.l) : null,
|
|
57235
|
-
consumers: consumers2
|
|
57513
|
+
consumers: consumers2,
|
|
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
|
+
}
|
|
57236
57523
|
};
|
|
57237
57524
|
}
|
|
57238
57525
|
return out;
|
|
57239
57526
|
};
|
|
57240
57527
|
return Object.assign(node, {
|
|
57241
57528
|
stats,
|
|
57529
|
+
resetConsumer: (topic, consumer, o) => consumers.resetConsumer(topic, consumer, o),
|
|
57530
|
+
deleteConsumer: (topic, consumer) => consumers.deleteConsumer(topic, consumer),
|
|
57531
|
+
listConsumers: (topic) => consumers.listConsumers(topic),
|
|
57532
|
+
pruneConsumers: (topic, o) => consumers.pruneConsumers(topic, o),
|
|
57533
|
+
consumerCaughtUp: (topic, consumer) => consumers.caughtUp(topic, consumer),
|
|
57534
|
+
scanEntries,
|
|
57535
|
+
headOrder: (topic) => {
|
|
57536
|
+
if (closed)
|
|
57537
|
+
throw misuse("node is closed");
|
|
57538
|
+
topics.get(topic);
|
|
57539
|
+
return store.maxOrderUpTo(topic, Number.MAX_SAFE_INTEGER);
|
|
57540
|
+
},
|
|
57242
57541
|
_core: core2,
|
|
57243
57542
|
_views: views,
|
|
57244
57543
|
_registers: registers,
|
|
@@ -57254,6 +57553,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57254
57553
|
init_beacon();
|
|
57255
57554
|
init_codec();
|
|
57256
57555
|
init_consume();
|
|
57556
|
+
init_hlc();
|
|
57257
57557
|
init_constants();
|
|
57258
57558
|
init_directives();
|
|
57259
57559
|
init_errors3();
|
|
@@ -57452,6 +57752,12 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57452
57752
|
function meshEventsTopic(meshId) {
|
|
57453
57753
|
return `mesh.${safeMeshId(meshId)}.events`;
|
|
57454
57754
|
}
|
|
57755
|
+
function meshIdFromEventsTopic(topic) {
|
|
57756
|
+
if (!topic.startsWith("mesh.") || !topic.endsWith(".events")) return null;
|
|
57757
|
+
const segment = topic.slice("mesh.".length, -".events".length);
|
|
57758
|
+
if (segment.length === 0 || segment.includes(".")) return null;
|
|
57759
|
+
return segment;
|
|
57760
|
+
}
|
|
57455
57761
|
function sessionTranscriptTopic(sessionId) {
|
|
57456
57762
|
return `session.${safeSessionId(sessionId)}.transcript`;
|
|
57457
57763
|
}
|
|
@@ -57544,6 +57850,193 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57544
57850
|
FLEET_STATUS_RING = 50;
|
|
57545
57851
|
}
|
|
57546
57852
|
});
|
|
57853
|
+
function diffProjected(expected, actual) {
|
|
57854
|
+
const fields = [];
|
|
57855
|
+
if (expected.ledgerKind !== actual.ledgerKind) fields.push("ledgerKind");
|
|
57856
|
+
if (expected.timestamp !== actual.timestamp) fields.push("timestamp");
|
|
57857
|
+
if (expected.nodeId !== actual.nodeId) fields.push("nodeId");
|
|
57858
|
+
if (expected.sessionId !== actual.sessionId) fields.push("sessionId");
|
|
57859
|
+
if (expected.providerType !== actual.providerType) fields.push("providerType");
|
|
57860
|
+
if (expected.taskId !== actual.taskId) fields.push("taskId");
|
|
57861
|
+
const keys = /* @__PURE__ */ new Set([
|
|
57862
|
+
...Object.keys(expected.payload ?? {}),
|
|
57863
|
+
...Object.keys(actual.payload ?? {})
|
|
57864
|
+
]);
|
|
57865
|
+
for (const key2 of keys) {
|
|
57866
|
+
if (expected.payload?.[key2] !== actual.payload?.[key2]) fields.push(`payload.${key2}`);
|
|
57867
|
+
}
|
|
57868
|
+
return fields;
|
|
57869
|
+
}
|
|
57870
|
+
function readProjected(payload) {
|
|
57871
|
+
if (!payload || typeof payload !== "object") return null;
|
|
57872
|
+
const record2 = payload;
|
|
57873
|
+
if (typeof record2.id !== "string" || record2.id.length === 0) return null;
|
|
57874
|
+
return {
|
|
57875
|
+
id: record2.id,
|
|
57876
|
+
timestamp: typeof record2.timestamp === "string" ? record2.timestamp : "",
|
|
57877
|
+
ledgerKind: typeof record2.ledgerKind === "string" ? record2.ledgerKind : "",
|
|
57878
|
+
nodeId: record2.nodeId ?? null,
|
|
57879
|
+
sessionId: record2.sessionId ?? null,
|
|
57880
|
+
providerType: record2.providerType ?? null,
|
|
57881
|
+
taskId: record2.taskId ?? null,
|
|
57882
|
+
payload: record2.payload ?? {}
|
|
57883
|
+
};
|
|
57884
|
+
}
|
|
57885
|
+
function collectOwnShadowRecords(handle, topic, through) {
|
|
57886
|
+
const records = /* @__PURE__ */ new Map();
|
|
57887
|
+
let truncatedBelow = false;
|
|
57888
|
+
let after;
|
|
57889
|
+
for (let page = 0; page < SHADOW_SCAN_MAX_PAGES; page++) {
|
|
57890
|
+
const result = handle.node.scanEntries(topic, {
|
|
57891
|
+
...after ? { after } : {},
|
|
57892
|
+
through,
|
|
57893
|
+
limit: SHADOW_SCAN_PAGE
|
|
57894
|
+
});
|
|
57895
|
+
if (result.truncatedBelow) truncatedBelow = true;
|
|
57896
|
+
for (const entry of result.entries) {
|
|
57897
|
+
if (entry.kind !== MESH_EVENT_ENTRY_KIND) continue;
|
|
57898
|
+
if (entry.writer !== handle.writerId) continue;
|
|
57899
|
+
const projected = readProjected(entry.payload);
|
|
57900
|
+
if (projected) records.set(projected.id, projected);
|
|
57901
|
+
}
|
|
57902
|
+
if (result.complete || !result.nextAfter) break;
|
|
57903
|
+
after = result.nextAfter;
|
|
57904
|
+
}
|
|
57905
|
+
return { records, through, truncatedBelow };
|
|
57906
|
+
}
|
|
57907
|
+
function shortId(id) {
|
|
57908
|
+
return id.length <= 12 ? id : `${id.slice(0, 12)}\u2026`;
|
|
57909
|
+
}
|
|
57910
|
+
async function runMeshParityCheck(handle, meshId, ledgerEntries, _opts = {}) {
|
|
57911
|
+
const topic = meshEventsTopic(meshId);
|
|
57912
|
+
const result = { meshId, compared: 0, mismatches: [] };
|
|
57913
|
+
if (!handle.topics.some((d) => d.topic === topic)) {
|
|
57914
|
+
return result;
|
|
57915
|
+
}
|
|
57916
|
+
let window;
|
|
57917
|
+
try {
|
|
57918
|
+
const through = handle.node.headOrder(topic);
|
|
57919
|
+
if (through === null) {
|
|
57920
|
+
window = { records: /* @__PURE__ */ new Map(), through: null, truncatedBelow: false };
|
|
57921
|
+
} else {
|
|
57922
|
+
window = collectOwnShadowRecords(handle, topic, through);
|
|
57923
|
+
}
|
|
57924
|
+
} catch (error48) {
|
|
57925
|
+
LOG2.warn(
|
|
57926
|
+
"Seqscribe",
|
|
57927
|
+
`parity read failed mesh=${meshId}: ${error48 instanceof Error ? error48.message : String(error48)}`
|
|
57928
|
+
);
|
|
57929
|
+
return result;
|
|
57930
|
+
}
|
|
57931
|
+
const shadow = window.records;
|
|
57932
|
+
const seen = /* @__PURE__ */ new Set();
|
|
57933
|
+
let oldestComparedMs = Infinity;
|
|
57934
|
+
for (const entry of ledgerEntries) {
|
|
57935
|
+
result.compared++;
|
|
57936
|
+
seen.add(entry.id);
|
|
57937
|
+
const entryMs = new Date(entry.timestamp).getTime();
|
|
57938
|
+
if (Number.isFinite(entryMs) && entryMs < oldestComparedMs) oldestComparedMs = entryMs;
|
|
57939
|
+
const actual = shadow.get(entry.id);
|
|
57940
|
+
if (!actual) {
|
|
57941
|
+
result.mismatches.push({
|
|
57942
|
+
kind: "missing_in_shadow",
|
|
57943
|
+
id: entry.id,
|
|
57944
|
+
ledgerKind: entry.kind
|
|
57945
|
+
});
|
|
57946
|
+
continue;
|
|
57947
|
+
}
|
|
57948
|
+
const fields = diffProjected(projectMeshLedgerEntry(entry), actual);
|
|
57949
|
+
if (fields.length > 0) {
|
|
57950
|
+
result.mismatches.push({
|
|
57951
|
+
kind: "field_mismatch",
|
|
57952
|
+
id: entry.id,
|
|
57953
|
+
ledgerKind: entry.kind,
|
|
57954
|
+
fields
|
|
57955
|
+
});
|
|
57956
|
+
}
|
|
57957
|
+
}
|
|
57958
|
+
for (const [id, record2] of shadow) {
|
|
57959
|
+
if (seen.has(id)) continue;
|
|
57960
|
+
const recordMs = new Date(record2.timestamp).getTime();
|
|
57961
|
+
if (Number.isFinite(recordMs) && recordMs < oldestComparedMs) continue;
|
|
57962
|
+
result.mismatches.push({
|
|
57963
|
+
kind: "extra_in_shadow",
|
|
57964
|
+
id,
|
|
57965
|
+
ledgerKind: record2.ledgerKind || null
|
|
57966
|
+
});
|
|
57967
|
+
}
|
|
57968
|
+
if (window.truncatedBelow) {
|
|
57969
|
+
LOG2.info(
|
|
57970
|
+
"Seqscribe",
|
|
57971
|
+
`parity window mesh=${meshId} reaches below the archive floor \u2014 shadow records under the cut are not visible to this sweep`
|
|
57972
|
+
);
|
|
57973
|
+
}
|
|
57974
|
+
counters.runs++;
|
|
57975
|
+
counters.compared = result.compared;
|
|
57976
|
+
let missing = 0;
|
|
57977
|
+
let extra = 0;
|
|
57978
|
+
let field2 = 0;
|
|
57979
|
+
for (const m of result.mismatches) {
|
|
57980
|
+
if (m.kind === "missing_in_shadow") missing++;
|
|
57981
|
+
else if (m.kind === "extra_in_shadow") extra++;
|
|
57982
|
+
else field2++;
|
|
57983
|
+
}
|
|
57984
|
+
counters.missingInShadow += missing;
|
|
57985
|
+
counters.extraInShadow += extra;
|
|
57986
|
+
counters.fieldMismatch += field2;
|
|
57987
|
+
counters.mismatches += result.mismatches.length;
|
|
57988
|
+
if (result.mismatches.length > 0) {
|
|
57989
|
+
for (const m of result.mismatches.slice(0, MISMATCH_LOG_CAP)) {
|
|
57990
|
+
LOG2.info(
|
|
57991
|
+
"Seqscribe",
|
|
57992
|
+
`parity mismatch kind=${m.kind} mesh=${meshId} entry=${shortId(m.id)} ledgerKind=${m.ledgerKind ?? "unknown"}` + (m.fields?.length ? ` fields=${m.fields.join(",")}` : "")
|
|
57993
|
+
);
|
|
57994
|
+
}
|
|
57995
|
+
if (result.mismatches.length > MISMATCH_LOG_CAP) {
|
|
57996
|
+
LOG2.info(
|
|
57997
|
+
"Seqscribe",
|
|
57998
|
+
`parity mismatch mesh=${meshId} \u2014 ${result.mismatches.length - MISMATCH_LOG_CAP} further mismatches not logged this run`
|
|
57999
|
+
);
|
|
58000
|
+
}
|
|
58001
|
+
}
|
|
58002
|
+
return result;
|
|
58003
|
+
}
|
|
58004
|
+
function meshParityCounters() {
|
|
58005
|
+
return { ...counters };
|
|
58006
|
+
}
|
|
58007
|
+
function __resetMeshParityForTests() {
|
|
58008
|
+
counters.compared = 0;
|
|
58009
|
+
counters.missingInShadow = 0;
|
|
58010
|
+
counters.extraInShadow = 0;
|
|
58011
|
+
counters.fieldMismatch = 0;
|
|
58012
|
+
counters.mismatches = 0;
|
|
58013
|
+
counters.runs = 0;
|
|
58014
|
+
}
|
|
58015
|
+
var PARITY_CONSUMER;
|
|
58016
|
+
var counters;
|
|
58017
|
+
var SHADOW_SCAN_PAGE;
|
|
58018
|
+
var SHADOW_SCAN_MAX_PAGES;
|
|
58019
|
+
var MISMATCH_LOG_CAP;
|
|
58020
|
+
var init_mesh_parity = __esm2({
|
|
58021
|
+
"src/seqscribe/mesh-parity.ts"() {
|
|
58022
|
+
"use strict";
|
|
58023
|
+
init_logger();
|
|
58024
|
+
init_mesh_event_projection();
|
|
58025
|
+
init_topics2();
|
|
58026
|
+
PARITY_CONSUMER = "stage3-mesh-parity";
|
|
58027
|
+
counters = {
|
|
58028
|
+
compared: 0,
|
|
58029
|
+
missingInShadow: 0,
|
|
58030
|
+
extraInShadow: 0,
|
|
58031
|
+
fieldMismatch: 0,
|
|
58032
|
+
mismatches: 0,
|
|
58033
|
+
runs: 0
|
|
58034
|
+
};
|
|
58035
|
+
SHADOW_SCAN_PAGE = 500;
|
|
58036
|
+
SHADOW_SCAN_MAX_PAGES = 200;
|
|
58037
|
+
MISMATCH_LOG_CAP = 20;
|
|
58038
|
+
}
|
|
58039
|
+
});
|
|
57547
58040
|
function warnOnce(message) {
|
|
57548
58041
|
if (warnedOnce.has(message)) return;
|
|
57549
58042
|
warnedOnce.add(message);
|
|
@@ -57564,9 +58057,8 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57564
58057
|
malformed: 0
|
|
57565
58058
|
};
|
|
57566
58059
|
}
|
|
57567
|
-
function
|
|
57568
|
-
|
|
57569
|
-
return generation === 0 ? READ_MODEL_CONSUMER : `${READ_MODEL_CONSUMER}#${generation + 1}`;
|
|
58060
|
+
function meshReadModelRebuildEpoch(meshId) {
|
|
58061
|
+
return rebuildEpoch.get(meshId) ?? 0;
|
|
57570
58062
|
}
|
|
57571
58063
|
function addToBucket(map3, key2, id) {
|
|
57572
58064
|
if (!key2) return;
|
|
@@ -57584,7 +58076,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57584
58076
|
bucket2.delete(id);
|
|
57585
58077
|
if (bucket2.size === 0) map3.delete(key2);
|
|
57586
58078
|
}
|
|
57587
|
-
function
|
|
58079
|
+
function readProjected2(payload) {
|
|
57588
58080
|
if (!payload || typeof payload !== "object") return null;
|
|
57589
58081
|
const record2 = payload;
|
|
57590
58082
|
if (typeof record2.id !== "string" || record2.id.length === 0) return null;
|
|
@@ -57602,7 +58094,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57602
58094
|
}
|
|
57603
58095
|
function ingest(index, entry) {
|
|
57604
58096
|
if (entry.kind !== MESH_EVENT_ENTRY_KIND) return;
|
|
57605
|
-
const event =
|
|
58097
|
+
const event = readProjected2(entry.payload);
|
|
57606
58098
|
if (!event) {
|
|
57607
58099
|
index.malformed++;
|
|
57608
58100
|
return;
|
|
@@ -57641,7 +58133,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57641
58133
|
if (existing) return existing;
|
|
57642
58134
|
const topic = meshEventsTopic(meshId);
|
|
57643
58135
|
if (!node.topics.some((d) => d.topic === topic)) return null;
|
|
57644
|
-
const index = emptyIndex(
|
|
58136
|
+
const index = emptyIndex(READ_MODEL_CONSUMER);
|
|
57645
58137
|
try {
|
|
57646
58138
|
index.unsub = node.node.onEntry(topic, index.consumerName, (entry) => {
|
|
57647
58139
|
ingest(index, entry);
|
|
@@ -57735,8 +58227,70 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57735
58227
|
}
|
|
57736
58228
|
indexes.delete(meshId);
|
|
57737
58229
|
}
|
|
57738
|
-
|
|
58230
|
+
const node = activeNode;
|
|
58231
|
+
if (!node) return null;
|
|
58232
|
+
const topic = meshEventsTopic(meshId);
|
|
58233
|
+
if (!node.topics.some((d) => d.topic === topic)) return null;
|
|
58234
|
+
rebuildEpoch.set(meshId, (rebuildEpoch.get(meshId) ?? 0) + 1);
|
|
58235
|
+
let coverage = null;
|
|
58236
|
+
try {
|
|
58237
|
+
const reset = node.node.resetConsumer(topic, READ_MODEL_CONSUMER, {
|
|
58238
|
+
from: "earliest-retained"
|
|
58239
|
+
});
|
|
58240
|
+
coverage = {
|
|
58241
|
+
consumerName: READ_MODEL_CONSUMER,
|
|
58242
|
+
existed: reset.existed,
|
|
58243
|
+
replayFromRowid: reset.replayFromRowid,
|
|
58244
|
+
archivedRows: reset.archivedRows
|
|
58245
|
+
};
|
|
58246
|
+
lastRebuildCoverage.set(meshId, {
|
|
58247
|
+
archivedRows: reset.archivedRows,
|
|
58248
|
+
replayFromRowid: reset.replayFromRowid
|
|
58249
|
+
});
|
|
58250
|
+
if (reset.archivedRows > 0) {
|
|
58251
|
+
LOG2.info(
|
|
58252
|
+
"Seqscribe",
|
|
58253
|
+
`read model rebuild mesh=${meshId} replays from the archive floor (rowid=${reset.replayFromRowid}, ${reset.archivedRows} archived rows not replayed)`
|
|
58254
|
+
);
|
|
58255
|
+
}
|
|
58256
|
+
} catch (error48) {
|
|
58257
|
+
warnOnce(
|
|
58258
|
+
`read model rebuild could not reset cursor topic=${topic}: ${error48 instanceof Error ? error48.message : String(error48)}`
|
|
58259
|
+
);
|
|
58260
|
+
return null;
|
|
58261
|
+
}
|
|
57739
58262
|
ensureIndex(meshId);
|
|
58263
|
+
return coverage;
|
|
58264
|
+
}
|
|
58265
|
+
function pruneStaleConsumersAtBoot() {
|
|
58266
|
+
const node = activeNode;
|
|
58267
|
+
if (!node) return 0;
|
|
58268
|
+
let total = 0;
|
|
58269
|
+
for (const definition of node.topics) {
|
|
58270
|
+
const meshId = meshIdFromEventsTopic(definition.topic);
|
|
58271
|
+
if (meshId === null) continue;
|
|
58272
|
+
total += pruneTopicConsumers(node, definition.topic, meshId).length;
|
|
58273
|
+
}
|
|
58274
|
+
return total;
|
|
58275
|
+
}
|
|
58276
|
+
function pruneTopicConsumers(node, topic, meshId) {
|
|
58277
|
+
const pruned = [];
|
|
58278
|
+
try {
|
|
58279
|
+
pruned.push(...node.node.pruneConsumers(topic, { prefix: `${READ_MODEL_CONSUMER}#` }));
|
|
58280
|
+
pruned.push(...node.node.pruneConsumers(topic, { prefix: `${PARITY_CONSUMER}:` }));
|
|
58281
|
+
} catch (error48) {
|
|
58282
|
+
warnOnce(
|
|
58283
|
+
`consumer prune failed topic=${topic}: ${error48 instanceof Error ? error48.message : String(error48)}`
|
|
58284
|
+
);
|
|
58285
|
+
return pruned;
|
|
58286
|
+
}
|
|
58287
|
+
if (pruned.length > 0) {
|
|
58288
|
+
LOG2.info(
|
|
58289
|
+
"Seqscribe",
|
|
58290
|
+
`pruned ${pruned.length} stale durable consumer(s) mesh=${meshId} \u2014 archive gate released`
|
|
58291
|
+
);
|
|
58292
|
+
}
|
|
58293
|
+
return pruned;
|
|
57740
58294
|
}
|
|
57741
58295
|
function meshReadModelConsumerName(meshId) {
|
|
57742
58296
|
return indexes.get(meshId)?.consumerName ?? null;
|
|
@@ -57749,7 +58303,8 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57749
58303
|
}
|
|
57750
58304
|
}
|
|
57751
58305
|
indexes.clear();
|
|
57752
|
-
|
|
58306
|
+
lastRebuildCoverage.clear();
|
|
58307
|
+
rebuildEpoch.clear();
|
|
57753
58308
|
activeNode = null;
|
|
57754
58309
|
warnedOnce.clear();
|
|
57755
58310
|
}
|
|
@@ -57763,7 +58318,8 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57763
58318
|
var indexes;
|
|
57764
58319
|
var activeNode;
|
|
57765
58320
|
var warnedOnce;
|
|
57766
|
-
var
|
|
58321
|
+
var lastRebuildCoverage;
|
|
58322
|
+
var rebuildEpoch;
|
|
57767
58323
|
var init_mesh_read_model = __esm2({
|
|
57768
58324
|
"src/seqscribe/mesh-read-model.ts"() {
|
|
57769
58325
|
"use strict";
|
|
@@ -57771,12 +58327,14 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57771
58327
|
init_dist();
|
|
57772
58328
|
init_logger();
|
|
57773
58329
|
init_mesh_event_projection();
|
|
58330
|
+
init_mesh_parity();
|
|
57774
58331
|
init_topics2();
|
|
57775
58332
|
READ_MODEL_CONSUMER = "stage4a-mesh-read-model";
|
|
57776
58333
|
indexes = /* @__PURE__ */ new Map();
|
|
57777
58334
|
activeNode = null;
|
|
57778
58335
|
warnedOnce = /* @__PURE__ */ new Set();
|
|
57779
|
-
|
|
58336
|
+
lastRebuildCoverage = /* @__PURE__ */ new Map();
|
|
58337
|
+
rebuildEpoch = /* @__PURE__ */ new Map();
|
|
57780
58338
|
}
|
|
57781
58339
|
});
|
|
57782
58340
|
function resolveMeshDualWriteMode(env2 = process.env) {
|
|
@@ -57861,7 +58419,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57861
58419
|
return topic;
|
|
57862
58420
|
} catch (error48) {
|
|
57863
58421
|
definedTopics.set(topic, false);
|
|
57864
|
-
|
|
58422
|
+
counters2.topicErrors++;
|
|
57865
58423
|
LOG2.warn(
|
|
57866
58424
|
"Seqscribe",
|
|
57867
58425
|
`mesh dual-write disabled for this mesh \u2014 defineTopic failed topic=${topic}: ${error48 instanceof Error ? error48.message : String(error48)}`
|
|
@@ -57882,7 +58440,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57882
58440
|
const topic = ensureTopic(node, meshId);
|
|
57883
58441
|
if (!topic) return false;
|
|
57884
58442
|
if (inflight >= MAX_INFLIGHT) {
|
|
57885
|
-
|
|
58443
|
+
counters2.dropped++;
|
|
57886
58444
|
warnOnce2(
|
|
57887
58445
|
`mesh dual-write shedding load \u2014 ${MAX_INFLIGHT} appends in flight; records are being dropped from the SHADOW leg only (the ledger is unaffected)`
|
|
57888
58446
|
);
|
|
@@ -57892,7 +58450,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57892
58450
|
const estimated = estimateProjectedEntryBytes(topic, projected);
|
|
57893
58451
|
const ceiling = maxEntryBytes();
|
|
57894
58452
|
if (estimated > ceiling) {
|
|
57895
|
-
|
|
58453
|
+
counters2.oversized++;
|
|
57896
58454
|
warnOnce2(
|
|
57897
58455
|
`mesh dual-write skipped an oversized record (further occurrences logged once): estimated=${estimated}B ceiling=${ceiling}B ledgerKind=${projected.ledgerKind}. The projection is supposed to bound every field \u2014 this is a projection bug, not a transport one.`
|
|
57898
58456
|
);
|
|
@@ -57902,13 +58460,13 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57902
58460
|
void node.node.log(topic).append(MESH_EVENT_ENTRY_KIND, toJsonValue(projected)).then(
|
|
57903
58461
|
() => {
|
|
57904
58462
|
inflight--;
|
|
57905
|
-
if (origin === "backfill")
|
|
57906
|
-
else
|
|
58463
|
+
if (origin === "backfill") counters2.backfilled++;
|
|
58464
|
+
else counters2.written++;
|
|
57907
58465
|
},
|
|
57908
58466
|
(error48) => {
|
|
57909
58467
|
inflight--;
|
|
57910
|
-
if (origin === "backfill")
|
|
57911
|
-
else
|
|
58468
|
+
if (origin === "backfill") counters2.backfillFailed++;
|
|
58469
|
+
else counters2.failed++;
|
|
57912
58470
|
warnOnce2(
|
|
57913
58471
|
`mesh dual-write append failed (further failures logged once): ${error48 instanceof Error ? error48.message : String(error48)}`
|
|
57914
58472
|
);
|
|
@@ -57916,8 +58474,8 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57916
58474
|
);
|
|
57917
58475
|
return true;
|
|
57918
58476
|
} catch (error48) {
|
|
57919
|
-
if (origin === "backfill")
|
|
57920
|
-
else
|
|
58477
|
+
if (origin === "backfill") counters2.backfillFailed++;
|
|
58478
|
+
else counters2.failed++;
|
|
57921
58479
|
warnOnce2(
|
|
57922
58480
|
`mesh dual-write threw synchronously (further throws logged once): ${error48 instanceof Error ? error48.message : String(error48)}`
|
|
57923
58481
|
);
|
|
@@ -57925,7 +58483,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57925
58483
|
}
|
|
57926
58484
|
}
|
|
57927
58485
|
function meshDualWriteCounters() {
|
|
57928
|
-
return { ...
|
|
58486
|
+
return { ...counters2 };
|
|
57929
58487
|
}
|
|
57930
58488
|
function isMeshDualWriteActive() {
|
|
57931
58489
|
return activeNode2 !== null && (activeMode === "shadow" || activeMode === "primary");
|
|
@@ -57945,17 +58503,17 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57945
58503
|
definedTopics.clear();
|
|
57946
58504
|
inflight = 0;
|
|
57947
58505
|
warnedOnce2.clear();
|
|
57948
|
-
|
|
57949
|
-
|
|
57950
|
-
|
|
57951
|
-
|
|
57952
|
-
|
|
57953
|
-
|
|
57954
|
-
|
|
58506
|
+
counters2.written = 0;
|
|
58507
|
+
counters2.failed = 0;
|
|
58508
|
+
counters2.dropped = 0;
|
|
58509
|
+
counters2.topicErrors = 0;
|
|
58510
|
+
counters2.backfilled = 0;
|
|
58511
|
+
counters2.backfillFailed = 0;
|
|
58512
|
+
counters2.oversized = 0;
|
|
57955
58513
|
}
|
|
57956
58514
|
var MESH_DUAL_WRITE_ENV;
|
|
57957
58515
|
var MAX_INFLIGHT;
|
|
57958
|
-
var
|
|
58516
|
+
var counters2;
|
|
57959
58517
|
var definedTopics;
|
|
57960
58518
|
var activeNode2;
|
|
57961
58519
|
var activeMode;
|
|
@@ -57970,7 +58528,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57970
58528
|
init_topics2();
|
|
57971
58529
|
MESH_DUAL_WRITE_ENV = "ADHDEV_SEQSCRIBE_MESH";
|
|
57972
58530
|
MAX_INFLIGHT = 512;
|
|
57973
|
-
|
|
58531
|
+
counters2 = {
|
|
57974
58532
|
written: 0,
|
|
57975
58533
|
failed: 0,
|
|
57976
58534
|
dropped: 0,
|
|
@@ -57987,190 +58545,54 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
57987
58545
|
TOPIC_LISTENERS = /* @__PURE__ */ Symbol.for("adhdev.seqscribe.topicActivatedListeners");
|
|
57988
58546
|
}
|
|
57989
58547
|
});
|
|
57990
|
-
function
|
|
57991
|
-
|
|
57992
|
-
if (expected.ledgerKind !== actual.ledgerKind) fields.push("ledgerKind");
|
|
57993
|
-
if (expected.timestamp !== actual.timestamp) fields.push("timestamp");
|
|
57994
|
-
if (expected.nodeId !== actual.nodeId) fields.push("nodeId");
|
|
57995
|
-
if (expected.sessionId !== actual.sessionId) fields.push("sessionId");
|
|
57996
|
-
if (expected.providerType !== actual.providerType) fields.push("providerType");
|
|
57997
|
-
if (expected.taskId !== actual.taskId) fields.push("taskId");
|
|
57998
|
-
const keys = /* @__PURE__ */ new Set([
|
|
57999
|
-
...Object.keys(expected.payload ?? {}),
|
|
58000
|
-
...Object.keys(actual.payload ?? {})
|
|
58001
|
-
]);
|
|
58002
|
-
for (const key2 of keys) {
|
|
58003
|
-
if (expected.payload?.[key2] !== actual.payload?.[key2]) fields.push(`payload.${key2}`);
|
|
58004
|
-
}
|
|
58005
|
-
return fields;
|
|
58548
|
+
function reportMeshTopicGrants(topics) {
|
|
58549
|
+
grantedTopics = topics ? new Set(topics) : null;
|
|
58006
58550
|
}
|
|
58007
|
-
function
|
|
58008
|
-
if (
|
|
58009
|
-
|
|
58010
|
-
if (typeof record2.id !== "string" || record2.id.length === 0) return null;
|
|
58011
|
-
return {
|
|
58012
|
-
id: record2.id,
|
|
58013
|
-
timestamp: typeof record2.timestamp === "string" ? record2.timestamp : "",
|
|
58014
|
-
ledgerKind: typeof record2.ledgerKind === "string" ? record2.ledgerKind : "",
|
|
58015
|
-
nodeId: record2.nodeId ?? null,
|
|
58016
|
-
sessionId: record2.sessionId ?? null,
|
|
58017
|
-
providerType: record2.providerType ?? null,
|
|
58018
|
-
taskId: record2.taskId ?? null,
|
|
58019
|
-
payload: record2.payload ?? {}
|
|
58020
|
-
};
|
|
58551
|
+
function isTopicGranted(topic) {
|
|
58552
|
+
if (grantedTopics === null) return true;
|
|
58553
|
+
return grantedTopics.has(topic);
|
|
58021
58554
|
}
|
|
58022
|
-
|
|
58023
|
-
const
|
|
58024
|
-
|
|
58025
|
-
|
|
58026
|
-
|
|
58027
|
-
if (entry.kind !== MESH_EVENT_ENTRY_KIND) return;
|
|
58028
|
-
if (entry.writer !== handle.writerId) return;
|
|
58029
|
-
const projected = readProjected2(entry.payload);
|
|
58030
|
-
if (projected) found.set(projected.id, projected);
|
|
58031
|
-
});
|
|
58032
|
-
await new Promise((resolve31) => setTimeout(resolve31, 0));
|
|
58033
|
-
await new Promise((resolve31) => setTimeout(resolve31, 0));
|
|
58034
|
-
} finally {
|
|
58035
|
-
try {
|
|
58036
|
-
unsub?.();
|
|
58037
|
-
} catch {
|
|
58038
|
-
}
|
|
58555
|
+
function isConsumerCaughtUp(node, topic, meshId, consumerName) {
|
|
58556
|
+
const epoch = meshReadModelRebuildEpoch(meshId);
|
|
58557
|
+
const existing = caughtUpLatches.get(meshId);
|
|
58558
|
+
if (existing && existing.node === node && existing.consumerName === consumerName && existing.epoch === epoch) {
|
|
58559
|
+
if (existing.caughtUp || existing.pending) return existing.caughtUp;
|
|
58039
58560
|
}
|
|
58040
|
-
|
|
58041
|
-
|
|
58042
|
-
function shortId(id) {
|
|
58043
|
-
return id.length <= 12 ? id : `${id.slice(0, 12)}\u2026`;
|
|
58044
|
-
}
|
|
58045
|
-
async function runMeshParityCheck(handle, meshId, ledgerEntries, opts = {}) {
|
|
58046
|
-
const topic = meshEventsTopic(meshId);
|
|
58047
|
-
const result = { meshId, compared: 0, mismatches: [] };
|
|
58048
|
-
if (!handle.topics.some((d) => d.topic === topic)) {
|
|
58049
|
-
return result;
|
|
58050
|
-
}
|
|
58051
|
-
let shadow;
|
|
58561
|
+
const latch = { node, consumerName, epoch, caughtUp: false, pending: true };
|
|
58562
|
+
caughtUpLatches.set(meshId, latch);
|
|
58052
58563
|
try {
|
|
58053
|
-
|
|
58054
|
-
|
|
58055
|
-
|
|
58056
|
-
|
|
58564
|
+
void node.node.consumerCaughtUp(topic, consumerName).then(
|
|
58565
|
+
() => {
|
|
58566
|
+
if (caughtUpLatches.get(meshId) !== latch) return;
|
|
58567
|
+
latch.pending = false;
|
|
58568
|
+
latch.caughtUp = true;
|
|
58569
|
+
},
|
|
58570
|
+
(error48) => {
|
|
58571
|
+
if (caughtUpLatches.get(meshId) !== latch) return;
|
|
58572
|
+
latch.pending = false;
|
|
58573
|
+
latch.caughtUp = false;
|
|
58574
|
+
LOG2.info(
|
|
58575
|
+
"Seqscribe",
|
|
58576
|
+
`read model catch-up watch ended mesh=${meshId}: ${error48 instanceof Error ? error48.message : String(error48)}`
|
|
58577
|
+
);
|
|
58578
|
+
}
|
|
58057
58579
|
);
|
|
58058
58580
|
} catch (error48) {
|
|
58581
|
+
latch.pending = false;
|
|
58059
58582
|
LOG2.warn(
|
|
58060
58583
|
"Seqscribe",
|
|
58061
|
-
`
|
|
58584
|
+
`read model catch-up unavailable mesh=${meshId}: ${error48 instanceof Error ? error48.message : String(error48)}`
|
|
58062
58585
|
);
|
|
58063
|
-
return result;
|
|
58064
|
-
}
|
|
58065
|
-
const seen = /* @__PURE__ */ new Set();
|
|
58066
|
-
let oldestComparedMs = Infinity;
|
|
58067
|
-
for (const entry of ledgerEntries) {
|
|
58068
|
-
result.compared++;
|
|
58069
|
-
seen.add(entry.id);
|
|
58070
|
-
const entryMs = new Date(entry.timestamp).getTime();
|
|
58071
|
-
if (Number.isFinite(entryMs) && entryMs < oldestComparedMs) oldestComparedMs = entryMs;
|
|
58072
|
-
const actual = shadow.get(entry.id);
|
|
58073
|
-
if (!actual) {
|
|
58074
|
-
result.mismatches.push({
|
|
58075
|
-
kind: "missing_in_shadow",
|
|
58076
|
-
id: entry.id,
|
|
58077
|
-
ledgerKind: entry.kind
|
|
58078
|
-
});
|
|
58079
|
-
continue;
|
|
58080
|
-
}
|
|
58081
|
-
const fields = diffProjected(projectMeshLedgerEntry(entry), actual);
|
|
58082
|
-
if (fields.length > 0) {
|
|
58083
|
-
result.mismatches.push({
|
|
58084
|
-
kind: "field_mismatch",
|
|
58085
|
-
id: entry.id,
|
|
58086
|
-
ledgerKind: entry.kind,
|
|
58087
|
-
fields
|
|
58088
|
-
});
|
|
58089
|
-
}
|
|
58090
|
-
}
|
|
58091
|
-
for (const [id, record2] of shadow) {
|
|
58092
|
-
if (seen.has(id)) continue;
|
|
58093
|
-
const recordMs = new Date(record2.timestamp).getTime();
|
|
58094
|
-
if (Number.isFinite(recordMs) && recordMs < oldestComparedMs) continue;
|
|
58095
|
-
result.mismatches.push({
|
|
58096
|
-
kind: "extra_in_shadow",
|
|
58097
|
-
id,
|
|
58098
|
-
ledgerKind: record2.ledgerKind || null
|
|
58099
|
-
});
|
|
58100
|
-
}
|
|
58101
|
-
counters2.runs++;
|
|
58102
|
-
counters2.compared = result.compared;
|
|
58103
|
-
let missing = 0;
|
|
58104
|
-
let extra = 0;
|
|
58105
|
-
let field2 = 0;
|
|
58106
|
-
for (const m of result.mismatches) {
|
|
58107
|
-
if (m.kind === "missing_in_shadow") missing++;
|
|
58108
|
-
else if (m.kind === "extra_in_shadow") extra++;
|
|
58109
|
-
else field2++;
|
|
58110
|
-
}
|
|
58111
|
-
counters2.missingInShadow += missing;
|
|
58112
|
-
counters2.extraInShadow += extra;
|
|
58113
|
-
counters2.fieldMismatch += field2;
|
|
58114
|
-
counters2.mismatches += result.mismatches.length;
|
|
58115
|
-
if (result.mismatches.length > 0) {
|
|
58116
|
-
for (const m of result.mismatches.slice(0, MISMATCH_LOG_CAP)) {
|
|
58117
|
-
LOG2.info(
|
|
58118
|
-
"Seqscribe",
|
|
58119
|
-
`parity mismatch kind=${m.kind} mesh=${meshId} entry=${shortId(m.id)} ledgerKind=${m.ledgerKind ?? "unknown"}` + (m.fields?.length ? ` fields=${m.fields.join(",")}` : "")
|
|
58120
|
-
);
|
|
58121
|
-
}
|
|
58122
|
-
if (result.mismatches.length > MISMATCH_LOG_CAP) {
|
|
58123
|
-
LOG2.info(
|
|
58124
|
-
"Seqscribe",
|
|
58125
|
-
`parity mismatch mesh=${meshId} \u2014 ${result.mismatches.length - MISMATCH_LOG_CAP} further mismatches not logged this run`
|
|
58126
|
-
);
|
|
58127
|
-
}
|
|
58128
|
-
}
|
|
58129
|
-
return result;
|
|
58130
|
-
}
|
|
58131
|
-
function meshParityCounters() {
|
|
58132
|
-
return { ...counters2 };
|
|
58133
|
-
}
|
|
58134
|
-
function __resetMeshParityForTests() {
|
|
58135
|
-
counters2.compared = 0;
|
|
58136
|
-
counters2.missingInShadow = 0;
|
|
58137
|
-
counters2.extraInShadow = 0;
|
|
58138
|
-
counters2.fieldMismatch = 0;
|
|
58139
|
-
counters2.mismatches = 0;
|
|
58140
|
-
counters2.runs = 0;
|
|
58141
|
-
}
|
|
58142
|
-
var PARITY_CONSUMER;
|
|
58143
|
-
var counters2;
|
|
58144
|
-
var MISMATCH_LOG_CAP;
|
|
58145
|
-
var init_mesh_parity = __esm2({
|
|
58146
|
-
"src/seqscribe/mesh-parity.ts"() {
|
|
58147
|
-
"use strict";
|
|
58148
|
-
init_logger();
|
|
58149
|
-
init_mesh_event_projection();
|
|
58150
|
-
init_topics2();
|
|
58151
|
-
PARITY_CONSUMER = "stage3-mesh-parity";
|
|
58152
|
-
counters2 = {
|
|
58153
|
-
compared: 0,
|
|
58154
|
-
missingInShadow: 0,
|
|
58155
|
-
extraInShadow: 0,
|
|
58156
|
-
fieldMismatch: 0,
|
|
58157
|
-
mismatches: 0,
|
|
58158
|
-
runs: 0
|
|
58159
|
-
};
|
|
58160
|
-
MISMATCH_LOG_CAP = 20;
|
|
58161
58586
|
}
|
|
58162
|
-
|
|
58163
|
-
function reportMeshTopicGrants(topics) {
|
|
58164
|
-
grantedTopics = topics ? new Set(topics) : null;
|
|
58165
|
-
}
|
|
58166
|
-
function isTopicGranted(topic) {
|
|
58167
|
-
if (grantedTopics === null) return true;
|
|
58168
|
-
return grantedTopics.has(topic);
|
|
58587
|
+
return latch.caughtUp;
|
|
58169
58588
|
}
|
|
58170
58589
|
function countFallback(reason) {
|
|
58171
58590
|
fallbackCounts.set(reason, (fallbackCounts.get(reason) ?? 0) + 1);
|
|
58172
58591
|
readsServedFromLedger++;
|
|
58173
58592
|
}
|
|
58593
|
+
function configureMeshReadReadinessCollector(collector) {
|
|
58594
|
+
seqscribeCollectorRef = collector;
|
|
58595
|
+
}
|
|
58174
58596
|
function logTransition(meshId, state) {
|
|
58175
58597
|
if (loggedTransitions.get(meshId) === state) return;
|
|
58176
58598
|
loggedTransitions.set(meshId, state);
|
|
@@ -58192,24 +58614,28 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
58192
58614
|
if (!hasMeshReadModelIndex(meshId)) return { ready: false, reason: "index_missing" };
|
|
58193
58615
|
}
|
|
58194
58616
|
let topicStats;
|
|
58195
|
-
|
|
58196
|
-
const
|
|
58197
|
-
|
|
58198
|
-
|
|
58199
|
-
|
|
58200
|
-
|
|
58201
|
-
|
|
58202
|
-
|
|
58203
|
-
|
|
58204
|
-
|
|
58205
|
-
|
|
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
|
+
}
|
|
58206
58631
|
}
|
|
58632
|
+
if (!topicStats) return { ready: false, reason: "topic_undefined" };
|
|
58207
58633
|
if (topicStats.quarantined > 0) return { ready: false, reason: "quarantined" };
|
|
58208
58634
|
const consumerName = meshReadModelConsumerName(meshId);
|
|
58209
58635
|
if (!consumerName) return { ready: false, reason: "consumer_missing" };
|
|
58210
|
-
|
|
58211
|
-
|
|
58212
|
-
|
|
58636
|
+
if (!isConsumerCaughtUp(node, topic, meshId, consumerName)) {
|
|
58637
|
+
return { ready: false, reason: "consumer_lag" };
|
|
58638
|
+
}
|
|
58213
58639
|
if (meshParityCounters().mismatches > 0) return { ready: false, reason: "parity_mismatch" };
|
|
58214
58640
|
return { ready: true, reason: null };
|
|
58215
58641
|
}
|
|
@@ -58237,12 +58663,15 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
58237
58663
|
readsServedFromReplica = 0;
|
|
58238
58664
|
readsServedFromLedger = 0;
|
|
58239
58665
|
loggedTransitions.clear();
|
|
58666
|
+
caughtUpLatches.clear();
|
|
58240
58667
|
}
|
|
58241
58668
|
var grantedTopics;
|
|
58669
|
+
var caughtUpLatches;
|
|
58242
58670
|
var fallbackCounts;
|
|
58243
58671
|
var readsServedFromReplica;
|
|
58244
58672
|
var readsServedFromLedger;
|
|
58245
58673
|
var loggedTransitions;
|
|
58674
|
+
var seqscribeCollectorRef;
|
|
58246
58675
|
var init_mesh_read_readiness = __esm2({
|
|
58247
58676
|
"src/seqscribe/mesh-read-readiness.ts"() {
|
|
58248
58677
|
"use strict";
|
|
@@ -58252,10 +58681,12 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
58252
58681
|
init_mesh_read_model();
|
|
58253
58682
|
init_topics2();
|
|
58254
58683
|
grantedTopics = null;
|
|
58684
|
+
caughtUpLatches = /* @__PURE__ */ new Map();
|
|
58255
58685
|
fallbackCounts = /* @__PURE__ */ new Map();
|
|
58256
58686
|
readsServedFromReplica = 0;
|
|
58257
58687
|
readsServedFromLedger = 0;
|
|
58258
58688
|
loggedTransitions = /* @__PURE__ */ new Map();
|
|
58689
|
+
seqscribeCollectorRef = null;
|
|
58259
58690
|
}
|
|
58260
58691
|
});
|
|
58261
58692
|
function fromLedger(entry) {
|
|
@@ -62682,10 +63113,20 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
62682
63113
|
resolvedAt: r.resolved_at
|
|
62683
63114
|
};
|
|
62684
63115
|
}
|
|
63116
|
+
function registerLedgerBulkChangeListener(fn) {
|
|
63117
|
+
onLedgerBulkChange = fn;
|
|
63118
|
+
}
|
|
63119
|
+
function notifyLedgerBulkChange() {
|
|
63120
|
+
try {
|
|
63121
|
+
onLedgerBulkChange?.();
|
|
63122
|
+
} catch {
|
|
63123
|
+
}
|
|
63124
|
+
}
|
|
62685
63125
|
function pruneMeshRuntimeRetention() {
|
|
62686
63126
|
try {
|
|
62687
63127
|
const store = MeshRuntimeStore.getInstance();
|
|
62688
63128
|
const ledger = store.pruneEventLedger(MESH_EVENT_LEDGER_RETENTION_MS);
|
|
63129
|
+
if (ledger > 0) notifyLedgerBulkChange();
|
|
62689
63130
|
const toolCalls = store.pruneToolCallLog(MESH_TOOL_CALL_LOG_RETENTION_MS);
|
|
62690
63131
|
const terminalQueue = store.pruneTerminalQueueEntries(MESH_TERMINAL_QUEUE_RETENTION_MS);
|
|
62691
63132
|
const sessionDelivery = store.pruneTerminalSessionDeliveries(resolveSessionDeliveryRetentionMs());
|
|
@@ -62698,6 +63139,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
62698
63139
|
return { ledger: 0, toolCalls: 0, terminalQueue: 0, sessionDelivery: 0 };
|
|
62699
63140
|
}
|
|
62700
63141
|
}
|
|
63142
|
+
var onLedgerBulkChange;
|
|
62701
63143
|
var MESH_EVENT_LEDGER_RETENTION_MS;
|
|
62702
63144
|
var MESH_TOOL_CALL_LOG_RETENTION_MS;
|
|
62703
63145
|
var MESH_TERMINAL_QUEUE_RETENTION_MS;
|
|
@@ -62848,6 +63290,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
62848
63290
|
static resetForTests() {
|
|
62849
63291
|
this.instance?.close();
|
|
62850
63292
|
this.instance = void 0;
|
|
63293
|
+
notifyLedgerBulkChange();
|
|
62851
63294
|
}
|
|
62852
63295
|
/**
|
|
62853
63296
|
* VACUUM the SQLite database to reclaim on-disk space. Retention prunes rows
|
|
@@ -65495,6 +65938,242 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
65495
65938
|
};
|
|
65496
65939
|
}
|
|
65497
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
|
+
});
|
|
65498
66177
|
var mesh_ledger_exports = {};
|
|
65499
66178
|
__export2(mesh_ledger_exports, {
|
|
65500
66179
|
MAX_LEDGER_SLICE_LIMIT: () => MAX_LEDGER_SLICE_LIMIT,
|
|
@@ -65504,6 +66183,7 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
65504
66183
|
OPERATING_NOTE_KIND: () => OPERATING_NOTE_KIND,
|
|
65505
66184
|
OPERATING_NOTE_TOMBSTONE_KIND: () => OPERATING_NOTE_TOMBSTONE_KIND,
|
|
65506
66185
|
__clearMeshLedgerForTests: () => __clearMeshLedgerForTests,
|
|
66186
|
+
__resetLedgerScanStatsForTests: () => __resetLedgerScanStatsForTests,
|
|
65507
66187
|
appendLedgerEntry: () => appendLedgerEntry,
|
|
65508
66188
|
appendRemoteLedgerEntries: () => appendRemoteLedgerEntries,
|
|
65509
66189
|
buildLedgerOriginatingCoordinatorStamp: () => buildLedgerOriginatingCoordinatorStamp,
|
|
@@ -65514,8 +66194,10 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
65514
66194
|
enforceLedgerRotationCap: () => enforceLedgerRotationCap,
|
|
65515
66195
|
extractJsonObjectFromSummary: () => extractJsonObjectFromSummary,
|
|
65516
66196
|
getLedgerDir: () => getLedgerDir2,
|
|
66197
|
+
getLedgerScanStats: () => getLedgerScanStats,
|
|
65517
66198
|
getLedgerSummary: () => getLedgerSummary,
|
|
65518
66199
|
getSessionRecoveryContext: () => getSessionRecoveryContext,
|
|
66200
|
+
invalidateAllLedgerCaches: () => invalidateAllLedgerCaches,
|
|
65519
66201
|
isIntentionalCleanupStopEntry: () => isIntentionalCleanupStopEntry,
|
|
65520
66202
|
isNoteExpired: () => isNoteExpired,
|
|
65521
66203
|
isOperatingNoteTombstoned: () => isOperatingNoteTombstoned,
|
|
@@ -65533,11 +66215,6 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
65533
66215
|
readOperatingNotes: () => readOperatingNotes,
|
|
65534
66216
|
tombstoneOperatingNote: () => tombstoneOperatingNote
|
|
65535
66217
|
});
|
|
65536
|
-
function ledgerEntryTaskId(entry) {
|
|
65537
|
-
if (typeof entry.taskId === "string" && entry.taskId.trim()) return entry.taskId.trim();
|
|
65538
|
-
const fromPayload = entry.payload && typeof entry.payload === "object" ? entry.payload.taskId : void 0;
|
|
65539
|
-
return typeof fromPayload === "string" && fromPayload.trim() ? fromPayload.trim() : void 0;
|
|
65540
|
-
}
|
|
65541
66218
|
function isIntentionalCleanupStopEntry(entry) {
|
|
65542
66219
|
if (entry.kind !== "session_stopped" && entry.kind !== "task_failed" && entry.kind !== "task_stalled") return false;
|
|
65543
66220
|
const payload = entry.payload && typeof entry.payload === "object" && !Array.isArray(entry.payload) ? entry.payload : {};
|
|
@@ -65565,38 +66242,11 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
65565
66242
|
if (Number.isNaN(created)) return false;
|
|
65566
66243
|
return now - created >= ttlDays * MS_PER_DAY;
|
|
65567
66244
|
}
|
|
65568
|
-
function getLedgerDir2() {
|
|
65569
|
-
const dir = (0, import_path7.join)(getConfigDir2(), LEDGER_DIR_NAME);
|
|
65570
|
-
if (!(0, import_fs7.existsSync)(dir)) {
|
|
65571
|
-
(0, import_fs7.mkdirSync)(dir, { recursive: true, mode: 448 });
|
|
65572
|
-
}
|
|
65573
|
-
return dir;
|
|
65574
|
-
}
|
|
65575
|
-
function getLedgerPath(meshId) {
|
|
65576
|
-
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
65577
|
-
return (0, import_path7.join)(getLedgerDir2(), `${safe}.jsonl`);
|
|
65578
|
-
}
|
|
65579
|
-
function getRotatedPath(meshId, index) {
|
|
65580
|
-
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
65581
|
-
return (0, import_path7.join)(getLedgerDir2(), `${safe}.${index}.jsonl`);
|
|
65582
|
-
}
|
|
65583
|
-
function getArchivePath(meshId) {
|
|
65584
|
-
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
65585
|
-
return (0, import_path7.join)(getLedgerDir2(), `${safe}.archive.jsonl`);
|
|
65586
|
-
}
|
|
65587
|
-
function getRotatedArchivePath(meshId, index) {
|
|
65588
|
-
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
65589
|
-
return (0, import_path7.join)(getLedgerDir2(), `${safe}.archive.${index}.jsonl`);
|
|
65590
|
-
}
|
|
65591
|
-
function getArchivedTerminalKeysPath(meshId) {
|
|
65592
|
-
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
65593
|
-
return (0, import_path7.join)(getLedgerDir2(), `${safe}.archived-terminal-keys.json`);
|
|
65594
|
-
}
|
|
65595
66245
|
function readArchivedTerminalKeys(meshId) {
|
|
65596
66246
|
const path63 = getArchivedTerminalKeysPath(meshId);
|
|
65597
|
-
if (!(0,
|
|
66247
|
+
if (!(0, import_fs9.existsSync)(path63)) return /* @__PURE__ */ new Set();
|
|
65598
66248
|
try {
|
|
65599
|
-
const parsed = JSON.parse((0,
|
|
66249
|
+
const parsed = JSON.parse((0, import_fs9.readFileSync)(path63, "utf-8"));
|
|
65600
66250
|
return new Set(Array.isArray(parsed?.keys) ? parsed.keys.filter((k) => typeof k === "string") : []);
|
|
65601
66251
|
} catch {
|
|
65602
66252
|
return /* @__PURE__ */ new Set();
|
|
@@ -65618,23 +66268,23 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
65618
66268
|
keys = keys.slice(keys.length - ARCHIVED_TERMINAL_KEYS_MAX);
|
|
65619
66269
|
}
|
|
65620
66270
|
const index = { keys, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
65621
|
-
(0,
|
|
66271
|
+
(0, import_fs9.writeFileSync)(getArchivedTerminalKeysPath(meshId), JSON.stringify(index), { encoding: "utf-8", mode: 384 });
|
|
65622
66272
|
} catch {
|
|
65623
66273
|
}
|
|
65624
66274
|
}
|
|
65625
66275
|
function getArchivedCountsPath(meshId) {
|
|
65626
66276
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
65627
|
-
return (0,
|
|
66277
|
+
return (0, import_path8.join)(getLedgerDir2(), `${safe}.archived-counts.json`);
|
|
65628
66278
|
}
|
|
65629
66279
|
function rotateArchiveFile(meshId, archivePath) {
|
|
65630
66280
|
let index = 1;
|
|
65631
|
-
while ((0,
|
|
66281
|
+
while ((0, import_fs9.existsSync)(getRotatedArchivePath(meshId, index))) {
|
|
65632
66282
|
index++;
|
|
65633
66283
|
if (index > 5) break;
|
|
65634
66284
|
}
|
|
65635
66285
|
if (index > 5) index = 5;
|
|
65636
66286
|
try {
|
|
65637
|
-
(0,
|
|
66287
|
+
(0, import_fs9.renameSync)(archivePath, getRotatedArchivePath(meshId, index));
|
|
65638
66288
|
} catch (e) {
|
|
65639
66289
|
process.stderr.write(`[adhdev-mesh] Archive rotation failed for mesh ${meshId}: ${e?.message || e}
|
|
65640
66290
|
`);
|
|
@@ -65642,15 +66292,15 @@ CREATE TABLE IF NOT EXISTS sq_archive (
|
|
|
65642
66292
|
}
|
|
65643
66293
|
function readArchivedCounts(meshId) {
|
|
65644
66294
|
const path63 = getArchivedCountsPath(meshId);
|
|
65645
|
-
if (!(0,
|
|
66295
|
+
if (!(0, import_fs9.existsSync)(path63)) return { taskCompleted: 0, taskFailed: 0, taskStalled: 0, recoveryAttempted: 0, totalArchived: 0, lastArchivedAt: "" };
|
|
65646
66296
|
try {
|
|
65647
|
-
return JSON.parse((0,
|
|
66297
|
+
return JSON.parse((0, import_fs9.readFileSync)(path63, "utf-8"));
|
|
65648
66298
|
} catch {
|
|
65649
66299
|
return { taskCompleted: 0, taskFailed: 0, taskStalled: 0, recoveryAttempted: 0, totalArchived: 0, lastArchivedAt: "" };
|
|
65650
66300
|
}
|
|
65651
66301
|
}
|
|
65652
66302
|
function writeArchivedCounts(meshId, counts) {
|
|
65653
|
-
(0,
|
|
66303
|
+
(0, import_fs9.writeFileSync)(getArchivedCountsPath(meshId), JSON.stringify(counts), { encoding: "utf-8", mode: 384 });
|
|
65654
66304
|
}
|
|
65655
66305
|
function updateArchivedCounts(meshId, archived) {
|
|
65656
66306
|
const counts = readArchivedCounts(meshId);
|
|
@@ -65686,7 +66336,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
65686
66336
|
}
|
|
65687
66337
|
function compactLedger(meshId) {
|
|
65688
66338
|
const filePath = getLedgerPath(meshId);
|
|
65689
|
-
if (!(0,
|
|
66339
|
+
if (!(0, import_fs9.existsSync)(filePath)) return { archivedCount: 0, retainedCount: 0 };
|
|
65690
66340
|
const cutoff = Date.now() - ARCHIVE_TERMINAL_OLDER_THAN_MS;
|
|
65691
66341
|
const entries = readLedgerEntries(meshId);
|
|
65692
66342
|
const retainedDispatchKeys = /* @__PURE__ */ new Set();
|
|
@@ -65715,11 +66365,11 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
65715
66365
|
if (archive.length === 0) return { archivedCount: 0, retainedCount: keep.length };
|
|
65716
66366
|
const archivePath = getArchivePath(meshId);
|
|
65717
66367
|
try {
|
|
65718
|
-
if ((0,
|
|
66368
|
+
if ((0, import_fs9.existsSync)(archivePath) && (0, import_fs9.statSync)(archivePath).size > 50 * 1024 * 1024) {
|
|
65719
66369
|
rotateArchiveFile(meshId, archivePath);
|
|
65720
66370
|
}
|
|
65721
66371
|
const archiveLines = archive.map((e) => JSON.stringify(e)).join("\n") + "\n";
|
|
65722
|
-
(0,
|
|
66372
|
+
(0, import_fs9.appendFileSync)(archivePath, archiveLines, { encoding: "utf-8", mode: 384 });
|
|
65723
66373
|
updateArchivedCounts(meshId, archive);
|
|
65724
66374
|
recordArchivedTerminalKeys(meshId, archive);
|
|
65725
66375
|
} catch (e) {
|
|
@@ -65729,7 +66379,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
65729
66379
|
}
|
|
65730
66380
|
try {
|
|
65731
66381
|
const keepLines = keep.length ? keep.map((e) => JSON.stringify(e)).join("\n") + "\n" : "";
|
|
65732
|
-
(0,
|
|
66382
|
+
(0, import_fs9.writeFileSync)(filePath, keepLines, { encoding: "utf-8", mode: 384 });
|
|
65733
66383
|
invalidateLedgerCache(meshId);
|
|
65734
66384
|
} catch (e) {
|
|
65735
66385
|
process.stderr.write(`[adhdev-mesh] Ledger compaction rewrite failed for mesh ${meshId}: ${e?.message || e}
|
|
@@ -65911,9 +66561,9 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
65911
66561
|
if (derived) entry.taskId = derived;
|
|
65912
66562
|
}
|
|
65913
66563
|
const filePath = getLedgerPath(meshId);
|
|
65914
|
-
if ((0,
|
|
66564
|
+
if ((0, import_fs9.existsSync)(filePath)) {
|
|
65915
66565
|
try {
|
|
65916
|
-
const stat2 = (0,
|
|
66566
|
+
const stat2 = (0, import_fs9.statSync)(filePath);
|
|
65917
66567
|
if (stat2.size >= MAX_FILE_SIZE_BYTES) {
|
|
65918
66568
|
rotateLedgerFile(meshId, filePath);
|
|
65919
66569
|
} else if (stat2.size >= COMPACT_THRESHOLD_BYTES) {
|
|
@@ -65935,12 +66585,12 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
65935
66585
|
payload: entry.payload
|
|
65936
66586
|
});
|
|
65937
66587
|
} catch {
|
|
65938
|
-
|
|
66588
|
+
clearLedgerImportFlag(meshId);
|
|
65939
66589
|
}
|
|
65940
66590
|
try {
|
|
65941
66591
|
const line = JSON.stringify(entry) + "\n";
|
|
65942
|
-
(0,
|
|
65943
|
-
|
|
66592
|
+
(0, import_fs9.appendFileSync)(filePath, line, { encoding: "utf-8", mode: 384 });
|
|
66593
|
+
recordLedgerAppend(meshId, [entry]);
|
|
65944
66594
|
meshLedgerEvents.emit("append", meshId, entry);
|
|
65945
66595
|
try {
|
|
65946
66596
|
recordMeshEventShadow(meshId, entry);
|
|
@@ -66035,7 +66685,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66035
66685
|
const remaining = readLedgerFile(meshId).filter((e) => !removeIds.includes(e.id));
|
|
66036
66686
|
const filePath = getLedgerPath(meshId);
|
|
66037
66687
|
const lines = remaining.length ? remaining.map((e) => JSON.stringify(e)).join("\n") + "\n" : "";
|
|
66038
|
-
(0,
|
|
66688
|
+
(0, import_fs9.writeFileSync)(filePath, lines, { encoding: "utf-8", mode: 384 });
|
|
66039
66689
|
} catch {
|
|
66040
66690
|
}
|
|
66041
66691
|
invalidateLedgerCache(meshId);
|
|
@@ -66092,8 +66742,8 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66092
66742
|
}
|
|
66093
66743
|
try {
|
|
66094
66744
|
const lines = validEntries.map((e) => JSON.stringify(e)).join("\n") + "\n";
|
|
66095
|
-
(0,
|
|
66096
|
-
|
|
66745
|
+
(0, import_fs9.appendFileSync)(ledgerPath, lines, { encoding: "utf-8", mode: 384 });
|
|
66746
|
+
recordLedgerAppend(meshId, validEntries);
|
|
66097
66747
|
for (const entry of validEntries) {
|
|
66098
66748
|
meshLedgerEvents.emit("append", meshId, entry);
|
|
66099
66749
|
}
|
|
@@ -66102,101 +66752,33 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66102
66752
|
throw new Error(`Failed to append remote ledger entries for mesh ${meshId}: ${e.message}`);
|
|
66103
66753
|
}
|
|
66104
66754
|
}
|
|
66105
|
-
function
|
|
66106
|
-
const filePath = getLedgerPath(meshId);
|
|
66107
|
-
if (!(0, import_fs7.existsSync)(filePath)) return [];
|
|
66108
|
-
let content;
|
|
66109
|
-
try {
|
|
66110
|
-
content = (0, import_fs7.readFileSync)(filePath, "utf-8");
|
|
66111
|
-
} catch {
|
|
66112
|
-
return [];
|
|
66113
|
-
}
|
|
66114
|
-
const entries = [];
|
|
66115
|
-
for (const line of content.split("\n")) {
|
|
66116
|
-
if (!line.trim()) continue;
|
|
66117
|
-
try {
|
|
66118
|
-
const entry = JSON.parse(line);
|
|
66119
|
-
if (entry.id && entry.kind) {
|
|
66120
|
-
if (!entry.taskId) {
|
|
66121
|
-
const derived = ledgerEntryTaskId(entry);
|
|
66122
|
-
if (derived) entry.taskId = derived;
|
|
66123
|
-
}
|
|
66124
|
-
entries.push(entry);
|
|
66125
|
-
}
|
|
66126
|
-
} catch {
|
|
66127
|
-
}
|
|
66128
|
-
}
|
|
66129
|
-
return entries;
|
|
66130
|
-
}
|
|
66131
|
-
function ensureLedgerImported(store, meshId) {
|
|
66132
|
-
if (ledgerImportStoreRef !== store) {
|
|
66133
|
-
ledgerImportDone.clear();
|
|
66134
|
-
ledgerImportStoreRef = store;
|
|
66135
|
-
}
|
|
66136
|
-
if (ledgerImportDone.has(meshId)) return;
|
|
66137
|
-
ledgerImportDone.add(meshId);
|
|
66138
|
-
const fileEntries = readLedgerFile(meshId);
|
|
66139
|
-
if (fileEntries.length === 0) return;
|
|
66140
|
-
try {
|
|
66141
|
-
store.importLedgerEntries(fileEntries.map((e) => ({
|
|
66142
|
-
id: e.id,
|
|
66143
|
-
meshId: e.meshId,
|
|
66144
|
-
timestamp: e.timestamp,
|
|
66145
|
-
kind: e.kind,
|
|
66146
|
-
nodeId: e.nodeId ?? null,
|
|
66147
|
-
sessionId: e.sessionId ?? null,
|
|
66148
|
-
providerType: e.providerType ?? null,
|
|
66149
|
-
taskId: ledgerEntryTaskId(e) ?? null,
|
|
66150
|
-
payload: e.payload ?? {}
|
|
66151
|
-
})));
|
|
66152
|
-
} catch {
|
|
66153
|
-
}
|
|
66154
|
-
}
|
|
66155
|
-
function readLedgerFromStore(meshId) {
|
|
66156
|
-
const store = MeshRuntimeStore.getInstance();
|
|
66157
|
-
ensureLedgerImported(store, meshId);
|
|
66158
|
-
return store.readLedgerEntriesOrdered(meshId).map((r) => {
|
|
66159
|
-
const payload = r.payload && typeof r.payload === "object" ? r.payload : {};
|
|
66160
|
-
const taskId = ledgerEntryTaskId({ taskId: r.taskId ?? void 0, payload });
|
|
66161
|
-
return {
|
|
66162
|
-
id: r.id,
|
|
66163
|
-
meshId: r.meshId,
|
|
66164
|
-
timestamp: r.timestamp,
|
|
66165
|
-
kind: r.kind,
|
|
66166
|
-
...r.nodeId ? { nodeId: r.nodeId } : {},
|
|
66167
|
-
...r.sessionId ? { sessionId: r.sessionId } : {},
|
|
66168
|
-
...r.providerType ? { providerType: r.providerType } : {},
|
|
66169
|
-
...taskId ? { taskId } : {},
|
|
66170
|
-
payload
|
|
66171
|
-
};
|
|
66172
|
-
});
|
|
66173
|
-
}
|
|
66174
|
-
function getCachedRawEntries(meshId) {
|
|
66175
|
-
const now = Date.now();
|
|
66176
|
-
const cached5 = ledgerReadCache.get(meshId);
|
|
66177
|
-
if (cached5 && now - cached5.cachedAt < LEDGER_CACHE_TTL_MS) return cached5.entries;
|
|
66178
|
-
let entries;
|
|
66755
|
+
function __clearMeshLedgerForTests(meshId) {
|
|
66179
66756
|
try {
|
|
66180
|
-
|
|
66757
|
+
MeshRuntimeStore.getInstance().clearLedgerForMesh(meshId);
|
|
66181
66758
|
} catch {
|
|
66182
|
-
entries = readLedgerFile(meshId);
|
|
66183
66759
|
}
|
|
66184
|
-
|
|
66185
|
-
|
|
66186
|
-
}
|
|
66187
|
-
function invalidateLedgerCache(meshId) {
|
|
66188
|
-
ledgerReadCache.delete(meshId);
|
|
66760
|
+
invalidateLedgerCache(meshId);
|
|
66761
|
+
clearLedgerImportFlag(meshId);
|
|
66189
66762
|
}
|
|
66190
|
-
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);
|
|
66191
66769
|
try {
|
|
66192
|
-
|
|
66770
|
+
const entries = readLedgerFromStore(meshId, {
|
|
66771
|
+
...hasSince ? { since: opts.since } : {},
|
|
66772
|
+
...kinds ? { kinds } : {}
|
|
66773
|
+
});
|
|
66774
|
+
recordLedgerPushdownScan(entries.length);
|
|
66775
|
+
return entries;
|
|
66193
66776
|
} catch {
|
|
66777
|
+
return getCachedRawEntries(meshId);
|
|
66194
66778
|
}
|
|
66195
|
-
ledgerReadCache.delete(meshId);
|
|
66196
|
-
ledgerImportDone.delete(meshId);
|
|
66197
66779
|
}
|
|
66198
66780
|
function readLedgerEntries(meshId, opts) {
|
|
66199
|
-
let entries =
|
|
66781
|
+
let entries = readRawEntriesForOpts(meshId, opts);
|
|
66200
66782
|
if (opts?.since) {
|
|
66201
66783
|
const sinceDate = new Date(opts.since).getTime();
|
|
66202
66784
|
if (!isNaN(sinceDate)) entries = entries.filter((e) => new Date(e.timestamp).getTime() >= sinceDate);
|
|
@@ -66398,13 +66980,13 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66398
66980
|
}
|
|
66399
66981
|
function rotateLedgerFile(meshId, currentPath) {
|
|
66400
66982
|
let index = 1;
|
|
66401
|
-
while ((0,
|
|
66983
|
+
while ((0, import_fs9.existsSync)(getRotatedPath(meshId, index))) {
|
|
66402
66984
|
index++;
|
|
66403
66985
|
if (index > 10) break;
|
|
66404
66986
|
}
|
|
66405
66987
|
if (index > 10) index = 10;
|
|
66406
66988
|
try {
|
|
66407
|
-
(0,
|
|
66989
|
+
(0, import_fs9.renameSync)(currentPath, getRotatedPath(meshId, index));
|
|
66408
66990
|
} catch (e) {
|
|
66409
66991
|
process.stderr.write(`[adhdev-mesh] Ledger rotation failed for mesh ${meshId}: ${e?.message || e}. File will continue to grow.
|
|
66410
66992
|
`);
|
|
@@ -66440,7 +67022,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66440
67022
|
function readRotationEntriesTolerant(filePath) {
|
|
66441
67023
|
let text;
|
|
66442
67024
|
try {
|
|
66443
|
-
text = (0,
|
|
67025
|
+
text = (0, import_fs9.readFileSync)(filePath, "utf-8");
|
|
66444
67026
|
} catch {
|
|
66445
67027
|
return [];
|
|
66446
67028
|
}
|
|
@@ -66459,14 +67041,14 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66459
67041
|
return out;
|
|
66460
67042
|
}
|
|
66461
67043
|
function evictClosedRotationFile(safe, dir, entry) {
|
|
66462
|
-
const filePath = (0,
|
|
67044
|
+
const filePath = (0, import_path8.join)(dir, entry.name);
|
|
66463
67045
|
const counts = readArchivedCounts(safe);
|
|
66464
67046
|
const alreadyFolded = new Set(counts.evictedRotations ?? []);
|
|
66465
67047
|
if (alreadyFolded.has(entry.name)) {
|
|
66466
|
-
if ((0,
|
|
67048
|
+
if ((0, import_fs9.existsSync)(filePath)) (0, import_fs9.unlinkSync)(filePath);
|
|
66467
67049
|
return;
|
|
66468
67050
|
}
|
|
66469
|
-
if (closedRotationKind(safe, entry.name) === "active" && (0,
|
|
67051
|
+
if (closedRotationKind(safe, entry.name) === "active" && (0, import_fs9.existsSync)(filePath)) {
|
|
66470
67052
|
const entries = readRotationEntriesTolerant(filePath);
|
|
66471
67053
|
for (const e of entries) {
|
|
66472
67054
|
if (e.kind === "task_completed") counts.taskCompleted++;
|
|
@@ -66479,7 +67061,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66479
67061
|
counts.evictedRotations = [...alreadyFolded, entry.name];
|
|
66480
67062
|
counts.lastArchivedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
66481
67063
|
writeArchivedCounts(safe, counts);
|
|
66482
|
-
if ((0,
|
|
67064
|
+
if ((0, import_fs9.existsSync)(filePath)) (0, import_fs9.unlinkSync)(filePath);
|
|
66483
67065
|
}
|
|
66484
67066
|
function enforceLedgerRotationCap(meshId, opts) {
|
|
66485
67067
|
const maxFiles = opts?.maxFiles ?? resolveLedgerRotationMaxFiles();
|
|
@@ -66490,14 +67072,14 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66490
67072
|
const stats = [];
|
|
66491
67073
|
let names = [];
|
|
66492
67074
|
try {
|
|
66493
|
-
names = (0,
|
|
67075
|
+
names = (0, import_fs9.readdirSync)(dir);
|
|
66494
67076
|
} catch {
|
|
66495
67077
|
names = [];
|
|
66496
67078
|
}
|
|
66497
67079
|
for (const name of names) {
|
|
66498
67080
|
if (!closedRotationKind(safe, name)) continue;
|
|
66499
67081
|
try {
|
|
66500
|
-
const st = (0,
|
|
67082
|
+
const st = (0, import_fs9.statSync)((0, import_path8.join)(dir, name));
|
|
66501
67083
|
if (st.isFile()) stats.push({ name, sizeBytes: st.size, mtimeMs: st.mtimeMs });
|
|
66502
67084
|
} catch {
|
|
66503
67085
|
}
|
|
@@ -66530,7 +67112,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66530
67112
|
const dir = getLedgerDir2();
|
|
66531
67113
|
let names = [];
|
|
66532
67114
|
try {
|
|
66533
|
-
names = (0,
|
|
67115
|
+
names = (0, import_fs9.readdirSync)(dir);
|
|
66534
67116
|
} catch {
|
|
66535
67117
|
return result;
|
|
66536
67118
|
}
|
|
@@ -66556,12 +67138,11 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66556
67138
|
}
|
|
66557
67139
|
return result;
|
|
66558
67140
|
}
|
|
66559
|
-
var
|
|
66560
|
-
var
|
|
67141
|
+
var import_fs9;
|
|
67142
|
+
var import_path8;
|
|
66561
67143
|
var import_crypto11;
|
|
66562
67144
|
var import_events;
|
|
66563
67145
|
var TASK_LIFECYCLE_LEDGER_KINDS;
|
|
66564
|
-
var LEDGER_DIR_NAME;
|
|
66565
67146
|
var MAX_FILE_SIZE_BYTES;
|
|
66566
67147
|
var COMPACT_THRESHOLD_BYTES;
|
|
66567
67148
|
var ARCHIVE_TERMINAL_OLDER_THAN_MS;
|
|
@@ -66578,23 +67159,22 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66578
67159
|
var MS_PER_DAY;
|
|
66579
67160
|
var ARCHIVED_TERMINAL_KEYS_MAX;
|
|
66580
67161
|
var meshLedgerEvents;
|
|
66581
|
-
var ledgerReadCache;
|
|
66582
|
-
var LEDGER_CACHE_TTL_MS;
|
|
66583
|
-
var ledgerImportStoreRef;
|
|
66584
|
-
var ledgerImportDone;
|
|
66585
67162
|
var init_mesh_ledger = __esm2({
|
|
66586
67163
|
"src/mesh/mesh-ledger.ts"() {
|
|
66587
67164
|
"use strict";
|
|
66588
|
-
|
|
66589
|
-
|
|
67165
|
+
import_fs9 = require("fs");
|
|
67166
|
+
import_path8 = require("path");
|
|
66590
67167
|
import_crypto11 = require("crypto");
|
|
66591
|
-
init_config();
|
|
66592
67168
|
init_mesh_retention_config();
|
|
66593
67169
|
init_dist();
|
|
66594
67170
|
import_events = require("events");
|
|
66595
67171
|
init_mesh_runtime_store();
|
|
67172
|
+
init_mesh_ledger_paths();
|
|
67173
|
+
init_mesh_ledger_read_cache();
|
|
66596
67174
|
init_mesh_dual_write();
|
|
66597
67175
|
init_contracts();
|
|
67176
|
+
init_mesh_ledger_paths();
|
|
67177
|
+
init_mesh_ledger_read_cache();
|
|
66598
67178
|
TASK_LIFECYCLE_LEDGER_KINDS = /* @__PURE__ */ new Set([
|
|
66599
67179
|
"task_dispatched",
|
|
66600
67180
|
"task_claimed",
|
|
@@ -66613,7 +67193,6 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66613
67193
|
// redrive history without an O(n) payload scan.
|
|
66614
67194
|
"redrive_provider_changed"
|
|
66615
67195
|
]);
|
|
66616
|
-
LEDGER_DIR_NAME = "mesh-ledger";
|
|
66617
67196
|
MAX_FILE_SIZE_BYTES = 10 * 1024 * 1024;
|
|
66618
67197
|
COMPACT_THRESHOLD_BYTES = 2 * 1024 * 1024;
|
|
66619
67198
|
ARCHIVE_TERMINAL_OLDER_THAN_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
@@ -66643,9 +67222,6 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
|
|
|
66643
67222
|
MS_PER_DAY = 24 * 60 * 60 * 1e3;
|
|
66644
67223
|
ARCHIVED_TERMINAL_KEYS_MAX = 5e3;
|
|
66645
67224
|
meshLedgerEvents = new import_events.EventEmitter();
|
|
66646
|
-
ledgerReadCache = /* @__PURE__ */ new Map();
|
|
66647
|
-
LEDGER_CACHE_TTL_MS = 100;
|
|
66648
|
-
ledgerImportDone = /* @__PURE__ */ new Set();
|
|
66649
67225
|
}
|
|
66650
67226
|
});
|
|
66651
67227
|
var coordinator_prompt_exports = {};
|
|
@@ -67726,10 +68302,10 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
67726
68302
|
return { config: inline, source: "mesh.policy.refineConfig", sourceType: "mesh_policy" };
|
|
67727
68303
|
}
|
|
67728
68304
|
for (const relative8 of MESH_REFINE_CONFIG_LOCATIONS) {
|
|
67729
|
-
const configPath = (0,
|
|
67730
|
-
if (!(0,
|
|
68305
|
+
const configPath = (0, import_path9.join)(workspace, relative8);
|
|
68306
|
+
if (!(0, import_fs10.existsSync)(configPath)) continue;
|
|
67731
68307
|
try {
|
|
67732
|
-
const parsed = parseConfigText3(configPath, (0,
|
|
68308
|
+
const parsed = parseConfigText3(configPath, (0, import_fs10.readFileSync)(configPath, "utf-8"));
|
|
67733
68309
|
const validation = validateMeshRefineConfig(parsed, relative8);
|
|
67734
68310
|
if (!validation.valid) return { source: relative8, sourceType: "invalid", path: configPath, error: String(validation.rejectedCommands[0]?.reason || validation.errors.join("; ")) };
|
|
67735
68311
|
return { config: parsed, source: relative8, sourceType: "repo_file", path: configPath };
|
|
@@ -67745,7 +68321,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
67745
68321
|
}
|
|
67746
68322
|
function readPackageScripts(workspace) {
|
|
67747
68323
|
try {
|
|
67748
|
-
const parsed = JSON.parse((0,
|
|
68324
|
+
const parsed = JSON.parse((0, import_fs10.readFileSync)((0, import_path9.join)(workspace, "package.json"), "utf-8"));
|
|
67749
68325
|
return isRecord3(parsed?.scripts) ? parsed.scripts : {};
|
|
67750
68326
|
} catch {
|
|
67751
68327
|
return {};
|
|
@@ -67820,8 +68396,8 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
67820
68396
|
unavailableReason: validation.commands.length ? void 0 : "validation_unavailable: repo mesh/refine config has no validation.commands"
|
|
67821
68397
|
};
|
|
67822
68398
|
}
|
|
67823
|
-
var
|
|
67824
|
-
var
|
|
68399
|
+
var import_fs10;
|
|
68400
|
+
var import_path9;
|
|
67825
68401
|
var yaml3;
|
|
67826
68402
|
var MESH_REFINE_VALIDATION_CATEGORIES;
|
|
67827
68403
|
var MESH_REFINE_VALIDATION_SCOPES;
|
|
@@ -67834,8 +68410,8 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
67834
68410
|
var init_refine_config = __esm2({
|
|
67835
68411
|
"src/mesh/refine-config.ts"() {
|
|
67836
68412
|
"use strict";
|
|
67837
|
-
|
|
67838
|
-
|
|
68413
|
+
import_fs10 = require("fs");
|
|
68414
|
+
import_path9 = require("path");
|
|
67839
68415
|
yaml3 = __toESM2(require_js_yaml());
|
|
67840
68416
|
MESH_REFINE_VALIDATION_CATEGORIES = ["typecheck", "test", "lint", "build"];
|
|
67841
68417
|
MESH_REFINE_VALIDATION_SCOPES = ["none", "web", "daemon"];
|
|
@@ -67942,7 +68518,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
67942
68518
|
if (!dir) continue;
|
|
67943
68519
|
for (const ext of WIN_EXEC_EXT) {
|
|
67944
68520
|
const full = path232.join(dir, trimmed + ext);
|
|
67945
|
-
if ((0,
|
|
68521
|
+
if ((0, import_fs11.existsSync)(full)) return full;
|
|
67946
68522
|
}
|
|
67947
68523
|
}
|
|
67948
68524
|
return null;
|
|
@@ -67959,7 +68535,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
67959
68535
|
if (process.platform !== "win32") return command;
|
|
67960
68536
|
const trimmed = (command || "").trim();
|
|
67961
68537
|
if (!trimmed) return command;
|
|
67962
|
-
if (path232.isAbsolute(trimmed) && (0,
|
|
68538
|
+
if (path232.isAbsolute(trimmed) && (0, import_fs11.existsSync)(trimmed)) return trimmed;
|
|
67963
68539
|
try {
|
|
67964
68540
|
const out = (0, import_child_process3.execFileSync)("where", [trimmed], {
|
|
67965
68541
|
encoding: "utf8",
|
|
@@ -68008,7 +68584,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68008
68584
|
};
|
|
68009
68585
|
}
|
|
68010
68586
|
var import_child_process3;
|
|
68011
|
-
var
|
|
68587
|
+
var import_fs11;
|
|
68012
68588
|
var path232;
|
|
68013
68589
|
var DIRECT_EXEC_EXT;
|
|
68014
68590
|
var SHIM_EXEC_EXT;
|
|
@@ -68017,7 +68593,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68017
68593
|
"src/cli-adapters/resolve-executable.ts"() {
|
|
68018
68594
|
"use strict";
|
|
68019
68595
|
import_child_process3 = require("child_process");
|
|
68020
|
-
|
|
68596
|
+
import_fs11 = require("fs");
|
|
68021
68597
|
path232 = __toESM2(require("path"));
|
|
68022
68598
|
DIRECT_EXEC_EXT = /* @__PURE__ */ new Set([".exe", ".com"]);
|
|
68023
68599
|
SHIM_EXEC_EXT = /* @__PURE__ */ new Set([".cmd", ".bat"]);
|
|
@@ -68155,7 +68731,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68155
68731
|
if (!Number.isFinite(startedMs)) return false;
|
|
68156
68732
|
if (nowMs - startedMs <= WORKTREE_BOOTSTRAP_STALE_RUNNING_MS) return false;
|
|
68157
68733
|
const workspace = typeof node?.workspace === "string" ? node.workspace.trim() : "";
|
|
68158
|
-
if (!workspace || !(0,
|
|
68734
|
+
if (!workspace || !(0, import_fs12.existsSync)(workspace)) return false;
|
|
68159
68735
|
try {
|
|
68160
68736
|
const out = (0, import_node_child_process4.execFileSync)(resolveWin32Executable("git"), ["status", "--porcelain"], {
|
|
68161
68737
|
cwd: workspace,
|
|
@@ -68218,10 +68794,10 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68218
68794
|
return { config: inline, source: "mesh.policy.worktreeBootstrapConfig", sourceType: "mesh_policy" };
|
|
68219
68795
|
}
|
|
68220
68796
|
for (const relative8 of MESH_WORKTREE_BOOTSTRAP_CONFIG_LOCATIONS) {
|
|
68221
|
-
const configPath = (0,
|
|
68222
|
-
if (!(0,
|
|
68797
|
+
const configPath = (0, import_path10.join)(workspace, relative8);
|
|
68798
|
+
if (!(0, import_fs12.existsSync)(configPath)) continue;
|
|
68223
68799
|
try {
|
|
68224
|
-
const parsed = parseConfigText4(configPath, (0,
|
|
68800
|
+
const parsed = parseConfigText4(configPath, (0, import_fs12.readFileSync)(configPath, "utf-8"));
|
|
68225
68801
|
const validation = validateMeshWorktreeBootstrapConfig(parsed, relative8);
|
|
68226
68802
|
if (!validation.valid) return { source: relative8, sourceType: "invalid", path: configPath, error: String(validation.rejectedCommands[0]?.reason || validation.errors.join("; ")) };
|
|
68227
68803
|
return { config: parsed, source: relative8, sourceType: "repo_file", path: configPath };
|
|
@@ -68234,9 +68810,9 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68234
68810
|
function computeStaleInputsDigest(workspace, staleInputs) {
|
|
68235
68811
|
const digest = {};
|
|
68236
68812
|
for (const relative8 of staleInputs ?? []) {
|
|
68237
|
-
const filePath = (0,
|
|
68813
|
+
const filePath = (0, import_path10.join)(workspace, relative8);
|
|
68238
68814
|
try {
|
|
68239
|
-
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");
|
|
68240
68816
|
} catch {
|
|
68241
68817
|
digest[relative8] = "absent";
|
|
68242
68818
|
}
|
|
@@ -68307,10 +68883,10 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68307
68883
|
staleInputs: loaded.config.staleInputs
|
|
68308
68884
|
};
|
|
68309
68885
|
const staleInputPaths = loaded.config.staleInputs ?? [];
|
|
68310
|
-
const initiallyAbsent = staleInputPaths.filter((p) => !(0,
|
|
68886
|
+
const initiallyAbsent = staleInputPaths.filter((p) => !(0, import_fs12.existsSync)((0, import_path10.join)(workspace, p)));
|
|
68311
68887
|
for (const command of validation.commands) {
|
|
68312
68888
|
if (initiallyAbsent.length > 0) {
|
|
68313
|
-
const appearedNow = initiallyAbsent.filter((p) => (0,
|
|
68889
|
+
const appearedNow = initiallyAbsent.filter((p) => (0, import_fs12.existsSync)((0, import_path10.join)(workspace, p)));
|
|
68314
68890
|
if (appearedNow.length > 0) {
|
|
68315
68891
|
state.status = "stale";
|
|
68316
68892
|
state.completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -68318,7 +68894,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68318
68894
|
return state;
|
|
68319
68895
|
}
|
|
68320
68896
|
}
|
|
68321
|
-
const cwd = command.cwd ? (0,
|
|
68897
|
+
const cwd = command.cwd ? (0, import_path10.resolve)(workspace, command.cwd) : workspace;
|
|
68322
68898
|
const startedAt = Date.now();
|
|
68323
68899
|
state.lastCommand = command.displayCommand;
|
|
68324
68900
|
const resolvedCommand = resolveWin32Executable(command.command);
|
|
@@ -68378,8 +68954,8 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68378
68954
|
}
|
|
68379
68955
|
return state;
|
|
68380
68956
|
}
|
|
68381
|
-
var
|
|
68382
|
-
var
|
|
68957
|
+
var import_fs12;
|
|
68958
|
+
var import_path10;
|
|
68383
68959
|
var import_node_child_process4;
|
|
68384
68960
|
var import_node_crypto2;
|
|
68385
68961
|
var import_node_util3;
|
|
@@ -68394,8 +68970,8 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
68394
68970
|
var init_worktree_bootstrap_config = __esm2({
|
|
68395
68971
|
"src/mesh/worktree-bootstrap-config.ts"() {
|
|
68396
68972
|
"use strict";
|
|
68397
|
-
|
|
68398
|
-
|
|
68973
|
+
import_fs12 = require("fs");
|
|
68974
|
+
import_path10 = require("path");
|
|
68399
68975
|
import_node_child_process4 = require("child_process");
|
|
68400
68976
|
import_node_crypto2 = require("crypto");
|
|
68401
68977
|
import_node_util3 = require("util");
|
|
@@ -68930,13 +69506,13 @@ ${rendered}`, "utf-8");
|
|
|
68930
69506
|
}
|
|
68931
69507
|
});
|
|
68932
69508
|
function getRegistryPath() {
|
|
68933
|
-
return (0,
|
|
69509
|
+
return (0, import_path12.join)(getDaemonDataDir(), "mesh-coordinators.json");
|
|
68934
69510
|
}
|
|
68935
69511
|
function loadMeshCoordinatorRegistry() {
|
|
68936
69512
|
const path63 = getRegistryPath();
|
|
68937
|
-
if (!(0,
|
|
69513
|
+
if (!(0, import_fs14.existsSync)(path63)) return;
|
|
68938
69514
|
try {
|
|
68939
|
-
const raw = JSON.parse((0,
|
|
69515
|
+
const raw = JSON.parse((0, import_fs14.readFileSync)(path63, "utf-8"));
|
|
68940
69516
|
if (!Array.isArray(raw)) return;
|
|
68941
69517
|
_registry.clear();
|
|
68942
69518
|
for (const entry of raw) {
|
|
@@ -68949,7 +69525,7 @@ ${rendered}`, "utf-8");
|
|
|
68949
69525
|
}
|
|
68950
69526
|
function saveRegistry() {
|
|
68951
69527
|
try {
|
|
68952
|
-
(0,
|
|
69528
|
+
(0, import_fs14.writeFileSync)(
|
|
68953
69529
|
getRegistryPath(),
|
|
68954
69530
|
JSON.stringify([..._registry.values()], null, 2),
|
|
68955
69531
|
{ encoding: "utf-8", mode: 384 }
|
|
@@ -68986,14 +69562,14 @@ ${rendered}`, "utf-8");
|
|
|
68986
69562
|
function listCoordinatorsForMesh(meshId) {
|
|
68987
69563
|
return [..._registry.values()].filter((e) => e.meshId === meshId).sort((a, b) => (b.startedAt ?? 0) - (a.startedAt ?? 0));
|
|
68988
69564
|
}
|
|
68989
|
-
var
|
|
68990
|
-
var
|
|
69565
|
+
var import_path12;
|
|
69566
|
+
var import_fs14;
|
|
68991
69567
|
var _registry;
|
|
68992
69568
|
var init_coordinator_registry = __esm2({
|
|
68993
69569
|
"src/mesh/coordinator-registry.ts"() {
|
|
68994
69570
|
"use strict";
|
|
68995
|
-
|
|
68996
|
-
|
|
69571
|
+
import_path12 = require("path");
|
|
69572
|
+
import_fs14 = require("fs");
|
|
68997
69573
|
init_config();
|
|
68998
69574
|
_registry = /* @__PURE__ */ new Map();
|
|
68999
69575
|
}
|
|
@@ -76656,7 +77232,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
|
|
|
76656
77232
|
if (now - lastAttempt < IDLE_AUTO_FAST_FORWARD_THROTTLE_MS) return;
|
|
76657
77233
|
idleAutoFastForwardLastAttempt.set(throttleKey, now);
|
|
76658
77234
|
if (isLocalAutoLaunchNode(node)) {
|
|
76659
|
-
if (!(0,
|
|
77235
|
+
if (!(0, import_fs16.existsSync)(workspace)) return;
|
|
76660
77236
|
await executeLocalAutoFastForward({ meshId: args.meshId, nodeId: args.nodeId, node, workspace, policy, trigger: "idle_auto" });
|
|
76661
77237
|
return;
|
|
76662
77238
|
}
|
|
@@ -76746,7 +77322,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
|
|
|
76746
77322
|
}
|
|
76747
77323
|
}
|
|
76748
77324
|
}
|
|
76749
|
-
var
|
|
77325
|
+
var import_fs16;
|
|
76750
77326
|
var IDLE_AUTO_FAST_FORWARD_THROTTLE_MS;
|
|
76751
77327
|
var idleAutoFastForwardLastAttempt;
|
|
76752
77328
|
var CONTINUOUS_AUTO_FAST_FORWARD_SCAN_COOLDOWN_MS;
|
|
@@ -76755,7 +77331,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
|
|
|
76755
77331
|
var init_mesh_auto_fast_forward = __esm2({
|
|
76756
77332
|
"src/mesh/mesh-auto-fast-forward.ts"() {
|
|
76757
77333
|
"use strict";
|
|
76758
|
-
|
|
77334
|
+
import_fs16 = require("fs");
|
|
76759
77335
|
init_logger();
|
|
76760
77336
|
init_config();
|
|
76761
77337
|
init_mesh_fast_forward();
|
|
@@ -79607,7 +80183,7 @@ Re-target now if the pin is stale: mesh_queue_requeue(task_id='${taskId}', targe
|
|
|
79607
80183
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
79608
80184
|
}
|
|
79609
80185
|
function getStatePath() {
|
|
79610
|
-
return (0,
|
|
80186
|
+
return (0, import_path14.join)(getConfigDir2(), "state.json");
|
|
79611
80187
|
}
|
|
79612
80188
|
function normalizeState(raw) {
|
|
79613
80189
|
const parsed = isPlainObject22(raw) ? raw : {};
|
|
@@ -79658,11 +80234,11 @@ Re-target now if the pin is stale: mesh_queue_requeue(task_id='${taskId}', targe
|
|
|
79658
80234
|
}
|
|
79659
80235
|
function loadState() {
|
|
79660
80236
|
const statePath = getStatePath();
|
|
79661
|
-
if (!(0,
|
|
80237
|
+
if (!(0, import_fs17.existsSync)(statePath)) {
|
|
79662
80238
|
return { ...DEFAULT_STATE };
|
|
79663
80239
|
}
|
|
79664
80240
|
try {
|
|
79665
|
-
const raw = (0,
|
|
80241
|
+
const raw = (0, import_fs17.readFileSync)(statePath, "utf-8");
|
|
79666
80242
|
return normalizeState(JSON.parse(raw));
|
|
79667
80243
|
} catch {
|
|
79668
80244
|
return { ...DEFAULT_STATE };
|
|
@@ -79671,7 +80247,7 @@ Re-target now if the pin is stale: mesh_queue_requeue(task_id='${taskId}', targe
|
|
|
79671
80247
|
function saveState(state) {
|
|
79672
80248
|
const statePath = getStatePath();
|
|
79673
80249
|
const normalized = normalizeState(state);
|
|
79674
|
-
(0,
|
|
80250
|
+
(0, import_fs17.writeFileSync)(statePath, JSON.stringify(normalized, null, 2), { encoding: "utf-8", mode: 384 });
|
|
79675
80251
|
}
|
|
79676
80252
|
function resetState() {
|
|
79677
80253
|
saveState({ ...DEFAULT_STATE });
|
|
@@ -79711,14 +80287,14 @@ Re-target now if the pin is stale: mesh_queue_requeue(task_id='${taskId}', targe
|
|
|
79711
80287
|
delete next[key2];
|
|
79712
80288
|
saveState({ ...state, deferredRestartSchedules: next });
|
|
79713
80289
|
}
|
|
79714
|
-
var
|
|
79715
|
-
var
|
|
80290
|
+
var import_fs17;
|
|
80291
|
+
var import_path14;
|
|
79716
80292
|
var DEFAULT_STATE;
|
|
79717
80293
|
var init_state_store = __esm2({
|
|
79718
80294
|
"src/config/state-store.ts"() {
|
|
79719
80295
|
"use strict";
|
|
79720
|
-
|
|
79721
|
-
|
|
80296
|
+
import_fs17 = require("fs");
|
|
80297
|
+
import_path14 = require("path");
|
|
79722
80298
|
init_config();
|
|
79723
80299
|
DEFAULT_STATE = {
|
|
79724
80300
|
recentActivity: [],
|
|
@@ -84014,7 +84590,7 @@ ${cleanBody}`;
|
|
|
84014
84590
|
}
|
|
84015
84591
|
function readDiskSpace(path63) {
|
|
84016
84592
|
try {
|
|
84017
|
-
const stats = (0,
|
|
84593
|
+
const stats = (0, import_fs18.statfsSync)(path63);
|
|
84018
84594
|
const blockSize = Number(stats.bsize);
|
|
84019
84595
|
const freeBytes = Number(stats.bavail) * blockSize;
|
|
84020
84596
|
const totalBytes = Number(stats.blocks) * blockSize;
|
|
@@ -84061,7 +84637,7 @@ ${cleanBody}`;
|
|
|
84061
84637
|
}
|
|
84062
84638
|
return status;
|
|
84063
84639
|
}
|
|
84064
|
-
var
|
|
84640
|
+
var import_fs18;
|
|
84065
84641
|
var DISK_CRITICAL_PERCENT_FREE;
|
|
84066
84642
|
var DISK_CRITICAL_FREE_BYTES;
|
|
84067
84643
|
var DISK_WARNING_PERCENT_FREE;
|
|
@@ -84070,7 +84646,7 @@ ${cleanBody}`;
|
|
|
84070
84646
|
var init_disk_space_preflight = __esm2({
|
|
84071
84647
|
"src/diagnostics/disk-space-preflight.ts"() {
|
|
84072
84648
|
"use strict";
|
|
84073
|
-
|
|
84649
|
+
import_fs18 = require("fs");
|
|
84074
84650
|
init_logger();
|
|
84075
84651
|
DISK_CRITICAL_PERCENT_FREE = 2;
|
|
84076
84652
|
DISK_CRITICAL_FREE_BYTES = 1 * 1024 * 1024 * 1024;
|
|
@@ -84122,7 +84698,7 @@ ${cleanBody}`;
|
|
|
84122
84698
|
}
|
|
84123
84699
|
function safeUnlink(path63) {
|
|
84124
84700
|
try {
|
|
84125
|
-
(0,
|
|
84701
|
+
(0, import_fs19.unlinkSync)(path63);
|
|
84126
84702
|
return true;
|
|
84127
84703
|
} catch (e) {
|
|
84128
84704
|
LOG2.warn("DiskRetention", `Failed to delete ${path63}: ${e?.message || e}`);
|
|
@@ -84130,18 +84706,18 @@ ${cleanBody}`;
|
|
|
84130
84706
|
}
|
|
84131
84707
|
}
|
|
84132
84708
|
function listDirFiles(dir) {
|
|
84133
|
-
if (!(0,
|
|
84709
|
+
if (!(0, import_fs19.existsSync)(dir)) return [];
|
|
84134
84710
|
const out = [];
|
|
84135
84711
|
let names;
|
|
84136
84712
|
try {
|
|
84137
|
-
names = (0,
|
|
84713
|
+
names = (0, import_fs19.readdirSync)(dir);
|
|
84138
84714
|
} catch {
|
|
84139
84715
|
return [];
|
|
84140
84716
|
}
|
|
84141
84717
|
for (const name of names) {
|
|
84142
|
-
const path63 = (0,
|
|
84718
|
+
const path63 = (0, import_path15.join)(dir, name);
|
|
84143
84719
|
try {
|
|
84144
|
-
const st = (0,
|
|
84720
|
+
const st = (0, import_fs19.statSync)(path63);
|
|
84145
84721
|
if (st.isFile()) out.push({ path: path63, mtimeMs: st.mtimeMs });
|
|
84146
84722
|
} catch {
|
|
84147
84723
|
}
|
|
@@ -84167,23 +84743,23 @@ ${cleanBody}`;
|
|
|
84167
84743
|
return deleted;
|
|
84168
84744
|
}
|
|
84169
84745
|
function pruneExpiredSessionHostRuntimes(now = Date.now()) {
|
|
84170
|
-
const root = (0,
|
|
84171
|
-
if (!(0,
|
|
84746
|
+
const root = (0, import_path15.join)(getConfigDir2(), "session-host");
|
|
84747
|
+
if (!(0, import_fs19.existsSync)(root)) return 0;
|
|
84172
84748
|
let apps;
|
|
84173
84749
|
try {
|
|
84174
|
-
apps = (0,
|
|
84750
|
+
apps = (0, import_fs19.readdirSync)(root);
|
|
84175
84751
|
} catch {
|
|
84176
84752
|
return 0;
|
|
84177
84753
|
}
|
|
84178
84754
|
const candidates = [];
|
|
84179
84755
|
for (const app of apps) {
|
|
84180
|
-
const runtimesDir = (0,
|
|
84181
|
-
if (!(0,
|
|
84756
|
+
const runtimesDir = (0, import_path15.join)(root, app, "runtimes");
|
|
84757
|
+
if (!(0, import_fs19.existsSync)(runtimesDir)) continue;
|
|
84182
84758
|
for (const f of listDirFiles(runtimesDir)) {
|
|
84183
84759
|
if (!f.path.endsWith(".json")) continue;
|
|
84184
84760
|
let record2 = null;
|
|
84185
84761
|
try {
|
|
84186
|
-
const parsed = JSON.parse((0,
|
|
84762
|
+
const parsed = JSON.parse((0, import_fs19.readFileSync)(f.path, "utf-8"));
|
|
84187
84763
|
const rec = parsed && typeof parsed === "object" ? parsed.record : null;
|
|
84188
84764
|
record2 = rec && typeof rec === "object" ? rec : null;
|
|
84189
84765
|
} catch {
|
|
@@ -84288,8 +84864,8 @@ ${cleanBody}`;
|
|
|
84288
84864
|
}
|
|
84289
84865
|
return signalled;
|
|
84290
84866
|
}
|
|
84291
|
-
var
|
|
84292
|
-
var
|
|
84867
|
+
var import_fs19;
|
|
84868
|
+
var import_path15;
|
|
84293
84869
|
var DAY_MS2;
|
|
84294
84870
|
var LEDGER_JSONL_MAX_AGE_MS;
|
|
84295
84871
|
var SESSION_HOST_RUNTIME_MAX_AGE_MS;
|
|
@@ -84298,8 +84874,8 @@ ${cleanBody}`;
|
|
|
84298
84874
|
var init_mesh_disk_retention = __esm2({
|
|
84299
84875
|
"src/mesh/mesh-disk-retention.ts"() {
|
|
84300
84876
|
"use strict";
|
|
84301
|
-
|
|
84302
|
-
|
|
84877
|
+
import_fs19 = require("fs");
|
|
84878
|
+
import_path15 = require("path");
|
|
84303
84879
|
init_config();
|
|
84304
84880
|
init_mesh_ledger();
|
|
84305
84881
|
init_runtime_surface();
|
|
@@ -84314,7 +84890,7 @@ ${cleanBody}`;
|
|
|
84314
84890
|
}
|
|
84315
84891
|
});
|
|
84316
84892
|
function retentionStatePath() {
|
|
84317
|
-
return (0,
|
|
84893
|
+
return (0, import_path16.join)(getLedgerDir2(), "worktree-node-retention-state.json");
|
|
84318
84894
|
}
|
|
84319
84895
|
function stateKey(meshId, nodeId) {
|
|
84320
84896
|
return `${meshId}::${nodeId}`;
|
|
@@ -84379,7 +84955,7 @@ ${cleanBody}`;
|
|
|
84379
84955
|
return String(stdout || "");
|
|
84380
84956
|
}
|
|
84381
84957
|
function normalizePathForCompare(value) {
|
|
84382
|
-
const resolved = (0,
|
|
84958
|
+
const resolved = (0, import_path16.resolve)(value);
|
|
84383
84959
|
try {
|
|
84384
84960
|
return fs17.realpathSync(resolved);
|
|
84385
84961
|
} catch {
|
|
@@ -84432,7 +85008,7 @@ ${cleanBody}`;
|
|
|
84432
85008
|
if (workspace && ctx.processCwd) {
|
|
84433
85009
|
const normalizedWorkspace = normalizePathForCompare(workspace);
|
|
84434
85010
|
const normalizedCwd = normalizePathForCompare(ctx.processCwd);
|
|
84435
|
-
if (normalizedCwd === normalizedWorkspace || normalizedCwd.startsWith(normalizedWorkspace +
|
|
85011
|
+
if (normalizedCwd === normalizedWorkspace || normalizedCwd.startsWith(normalizedWorkspace + import_path16.sep)) {
|
|
84436
85012
|
return skip("process_cwd_reference", "Worktree path is (or contains) the current process working directory; an open-runtime/cwd reference blocks removal.");
|
|
84437
85013
|
}
|
|
84438
85014
|
}
|
|
@@ -84813,7 +85389,7 @@ ${cleanBody}`;
|
|
|
84813
85389
|
}
|
|
84814
85390
|
var fs17;
|
|
84815
85391
|
var import_os22;
|
|
84816
|
-
var
|
|
85392
|
+
var import_path16;
|
|
84817
85393
|
var LOG_CATEGORY;
|
|
84818
85394
|
var metrics2;
|
|
84819
85395
|
var init_mesh_worktree_retention = __esm2({
|
|
@@ -84821,7 +85397,7 @@ ${cleanBody}`;
|
|
|
84821
85397
|
"use strict";
|
|
84822
85398
|
fs17 = __toESM2(require("fs"));
|
|
84823
85399
|
import_os22 = require("os");
|
|
84824
|
-
|
|
85400
|
+
import_path16 = require("path");
|
|
84825
85401
|
init_dist();
|
|
84826
85402
|
init_logger();
|
|
84827
85403
|
init_config();
|
|
@@ -91201,8 +91777,8 @@ ${cleanBody}`;
|
|
|
91201
91777
|
}
|
|
91202
91778
|
function probeSubmoduleGitlinkReachability(input) {
|
|
91203
91779
|
const { path: path63, baseCommit, branchCommit, probeRoot, baseRepoRoot } = input;
|
|
91204
|
-
const submoduleRepo = (0,
|
|
91205
|
-
const baseSubmoduleRepo = (0,
|
|
91780
|
+
const submoduleRepo = (0, import_path17.resolve)(probeRoot, path63);
|
|
91781
|
+
const baseSubmoduleRepo = (0, import_path17.resolve)(baseRepoRoot, path63);
|
|
91206
91782
|
if (baseCommit) ensureSubmoduleCommitLocal(submoduleRepo, baseSubmoduleRepo, baseCommit);
|
|
91207
91783
|
if (branchCommit) ensureSubmoduleCommitLocal(submoduleRepo, baseSubmoduleRepo, branchCommit);
|
|
91208
91784
|
let fastForward;
|
|
@@ -91372,7 +91948,7 @@ ${cleanBody}`;
|
|
|
91372
91948
|
}
|
|
91373
91949
|
var fs50;
|
|
91374
91950
|
var import_node_child_process9;
|
|
91375
|
-
var
|
|
91951
|
+
var import_path17;
|
|
91376
91952
|
var GIT2;
|
|
91377
91953
|
var REFINE_PATCH_EQUIVALENCE_OUTPUT_LIMIT_BYTES;
|
|
91378
91954
|
var init_mesh_refine_gitlink_utils = __esm2({
|
|
@@ -91380,7 +91956,7 @@ ${cleanBody}`;
|
|
|
91380
91956
|
"use strict";
|
|
91381
91957
|
fs50 = __toESM2(require("fs"));
|
|
91382
91958
|
import_node_child_process9 = require("child_process");
|
|
91383
|
-
|
|
91959
|
+
import_path17 = require("path");
|
|
91384
91960
|
init_logger();
|
|
91385
91961
|
init_resolve_executable();
|
|
91386
91962
|
GIT2 = process.platform === "win32" ? resolveWin32Executable("git") : "git";
|
|
@@ -91506,9 +92082,9 @@ ${cleanBody}`;
|
|
|
91506
92082
|
for (const path63 of changed) {
|
|
91507
92083
|
const baseCommit = readTreeObject(baseRepoRoot, baseHead, path63);
|
|
91508
92084
|
const branchCommit = readTreeObject(worktreeRoot, branchHead, path63);
|
|
91509
|
-
const submoduleRepoPath = (0,
|
|
92085
|
+
const submoduleRepoPath = (0, import_path18.resolve)(worktreeRoot, path63);
|
|
91510
92086
|
if (baseCommit) {
|
|
91511
|
-
ensureSubmoduleCommitLocal(submoduleRepoPath, (0,
|
|
92087
|
+
ensureSubmoduleCommitLocal(submoduleRepoPath, (0, import_path18.resolve)(baseRepoRoot, path63), baseCommit);
|
|
91512
92088
|
}
|
|
91513
92089
|
const markUndeterminable = () => {
|
|
91514
92090
|
const unavailable = [];
|
|
@@ -91731,7 +92307,7 @@ ${cleanBody}`;
|
|
|
91731
92307
|
for (const p of conflicts) {
|
|
91732
92308
|
const commit = resolveByPath.get(p);
|
|
91733
92309
|
try {
|
|
91734
|
-
(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" });
|
|
91735
92311
|
} catch {
|
|
91736
92312
|
}
|
|
91737
92313
|
try {
|
|
@@ -91750,7 +92326,7 @@ ${cleanBody}`;
|
|
|
91750
92326
|
return { ok: true, branchHead };
|
|
91751
92327
|
}
|
|
91752
92328
|
var fs51;
|
|
91753
|
-
var
|
|
92329
|
+
var import_path18;
|
|
91754
92330
|
var import_node_child_process10;
|
|
91755
92331
|
var SUBMODULE_PUBLISH_REQUIRED_RECOMMENDED_ACTION;
|
|
91756
92332
|
var SUBMODULE_PUBLICATION_UNDETERMINABLE_RECOMMENDED_ACTION;
|
|
@@ -91758,7 +92334,7 @@ ${cleanBody}`;
|
|
|
91758
92334
|
"src/mesh/mesh-refine-submodule-converge.ts"() {
|
|
91759
92335
|
"use strict";
|
|
91760
92336
|
fs51 = __toESM2(require("fs"));
|
|
91761
|
-
|
|
92337
|
+
import_path18 = require("path");
|
|
91762
92338
|
import_node_child_process10 = require("child_process");
|
|
91763
92339
|
init_mesh_refine_gitlink_utils();
|
|
91764
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.";
|
|
@@ -91782,10 +92358,10 @@ ${tail}`;
|
|
|
91782
92358
|
}
|
|
91783
92359
|
function writeValidationFailureLog(workspace, index, candidate, streams, now = () => /* @__PURE__ */ new Date()) {
|
|
91784
92360
|
try {
|
|
91785
|
-
const dir = (0,
|
|
92361
|
+
const dir = (0, import_path19.join)(workspace, REFINE_VALIDATION_LOG_DIR);
|
|
91786
92362
|
fs52.mkdirSync(dir, { recursive: true });
|
|
91787
92363
|
const stamp2 = now().toISOString().replace(/[:.]/g, "-");
|
|
91788
|
-
const file2 = (0,
|
|
92364
|
+
const file2 = (0, import_path19.join)(dir, `refine-${stamp2}-${index}.log`);
|
|
91789
92365
|
const asText = (v) => typeof v === "string" ? v : v == null ? "" : String(v);
|
|
91790
92366
|
const shown = candidate.displayCommand || [candidate.command, ...candidate.args || []].join(" ");
|
|
91791
92367
|
fs52.writeFileSync(
|
|
@@ -92270,7 +92846,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
92270
92846
|
const baseCommit = readTreeObject(repoRoot, baseHead, path63);
|
|
92271
92847
|
const branchCommit = readTreeObject(repoRoot, branchHead, path63);
|
|
92272
92848
|
if (!baseCommit || !branchCommit) return false;
|
|
92273
|
-
return isSubmoduleFastForward((0,
|
|
92849
|
+
return isSubmoduleFastForward((0, import_path19.resolve)(repoRoot, path63), baseCommit, branchCommit);
|
|
92274
92850
|
});
|
|
92275
92851
|
}
|
|
92276
92852
|
function collectTrivialFastForwardGitlinkResolutions(worktreeRoot, baseRepoRoot, baseHead, branchHead) {
|
|
@@ -92279,8 +92855,8 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
92279
92855
|
const baseCommit = readTreeObject(baseRepoRoot, baseHead, path63);
|
|
92280
92856
|
const branchCommit = readTreeObject(worktreeRoot, branchHead, path63);
|
|
92281
92857
|
if (!baseCommit || !branchCommit) continue;
|
|
92282
|
-
const submoduleRepoPath = (0,
|
|
92283
|
-
ensureSubmoduleCommitLocal(submoduleRepoPath, (0,
|
|
92858
|
+
const submoduleRepoPath = (0, import_path19.resolve)(worktreeRoot, path63);
|
|
92859
|
+
ensureSubmoduleCommitLocal(submoduleRepoPath, (0, import_path19.resolve)(baseRepoRoot, path63), baseCommit);
|
|
92284
92860
|
if (baseCommit === branchCommit) {
|
|
92285
92861
|
continue;
|
|
92286
92862
|
}
|
|
@@ -92296,7 +92872,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
92296
92872
|
const changedGitlinks = readChangedGitlinkPaths(repoRoot, baseHead, branchHead).map((path63) => {
|
|
92297
92873
|
const baseCommit = readTreeObject(repoRoot, baseHead, path63);
|
|
92298
92874
|
const branchCommit = readTreeObject(repoRoot, branchHead, path63);
|
|
92299
|
-
const submoduleRepoPath = (0,
|
|
92875
|
+
const submoduleRepoPath = (0, import_path19.resolve)(repoRoot, path63);
|
|
92300
92876
|
const probe = !!baseCommit && !!branchCommit ? probeSubmoduleFastForward(submoduleRepoPath, baseCommit, branchCommit) : "undeterminable";
|
|
92301
92877
|
return {
|
|
92302
92878
|
path: path63,
|
|
@@ -92359,7 +92935,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
92359
92935
|
if (!tree) return void 0;
|
|
92360
92936
|
const updates = paths.map((path63) => `160000 commit ${placeholderCommit} ${path63}`).join("\n");
|
|
92361
92937
|
if (!updates) return tree;
|
|
92362
|
-
const tmpIndex = (0,
|
|
92938
|
+
const tmpIndex = (0, import_path19.join)(resolveGitDir(repoRoot), `adhdev-refine-eq-${commitish.slice(0, 12)}.index`);
|
|
92363
92939
|
const env2 = { ...process.env, GIT_INDEX_FILE: tmpIndex };
|
|
92364
92940
|
try {
|
|
92365
92941
|
(0, import_node_child_process11.execFileSync)(GIT2, ["read-tree", tree], { cwd: repoRoot, env: env2, stdio: "ignore" });
|
|
@@ -92434,7 +93010,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
92434
93010
|
if (!contentTree) return void 0;
|
|
92435
93011
|
const updates = branchGitlinks.map((entry) => `160000 commit ${entry.branchCommit} ${entry.path}`).join("\n");
|
|
92436
93012
|
if (!updates) return contentTree;
|
|
92437
|
-
const tmpIndex = (0,
|
|
93013
|
+
const tmpIndex = (0, import_path19.join)(resolveGitDir(repoRoot), `adhdev-refine-ff-${baseHead.slice(0, 12)}-${branchHead.slice(0, 12)}.index`);
|
|
92438
93014
|
const env2 = { ...process.env, GIT_INDEX_FILE: tmpIndex };
|
|
92439
93015
|
try {
|
|
92440
93016
|
(0, import_node_child_process11.execFileSync)(GIT2, ["read-tree", contentTree], { cwd: repoRoot, env: env2, stdio: "ignore" });
|
|
@@ -92593,7 +93169,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
92593
93169
|
return match ? { commit: match[1], path: match[2] } : null;
|
|
92594
93170
|
}).filter((entry) => !!entry);
|
|
92595
93171
|
for (const gitlink of gitlinks) {
|
|
92596
|
-
const submodulePath = (0,
|
|
93172
|
+
const submodulePath = (0, import_path19.resolve)(repoRoot, gitlink.path);
|
|
92597
93173
|
const entry = {
|
|
92598
93174
|
path: gitlink.path,
|
|
92599
93175
|
commit: gitlink.commit,
|
|
@@ -92620,7 +93196,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
92620
93196
|
entry.localReachable = false;
|
|
92621
93197
|
if (options.allowAutoPublishSubmoduleMainCommits === true && options.worktreeRoot) {
|
|
92622
93198
|
try {
|
|
92623
|
-
const imported = await importCommitFromWorktreeSubmodule(submodulePath, (0,
|
|
93199
|
+
const imported = await importCommitFromWorktreeSubmodule(submodulePath, (0, import_path19.resolve)(options.worktreeRoot, gitlink.path), gitlink.commit);
|
|
92624
93200
|
if (imported) {
|
|
92625
93201
|
entry.localReachable = true;
|
|
92626
93202
|
entry.importedFromWorktree = true;
|
|
@@ -92872,13 +93448,13 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
92872
93448
|
...extras
|
|
92873
93449
|
});
|
|
92874
93450
|
const isPackageManagerValidation = (candidate) => {
|
|
92875
|
-
const command = (0,
|
|
93451
|
+
const command = (0, import_path19.basename)(candidate.command).replace(/\.(?:cmd|exe)$/i, "");
|
|
92876
93452
|
return ["npm", "pnpm", "yarn", "bun"].includes(command) && candidate.args.some((arg) => arg === "run" || arg === "test" || arg === "exec");
|
|
92877
93453
|
};
|
|
92878
93454
|
const dependenciesLikelyMissing = (cwd) => {
|
|
92879
|
-
if (!fs52.existsSync((0,
|
|
92880
|
-
if (fs52.existsSync((0,
|
|
92881
|
-
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)));
|
|
92882
93458
|
};
|
|
92883
93459
|
const needsNodeModules = (candidate, cwd) => isPackageManagerValidation(candidate) && dependenciesLikelyMissing(cwd);
|
|
92884
93460
|
const isDaemonScopedCommand = (candidate) => {
|
|
@@ -92945,7 +93521,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
92945
93521
|
summary.bootstrap = { stage: "legacy" };
|
|
92946
93522
|
for (const candidate of selection.bootstrapCommands) {
|
|
92947
93523
|
const startedAt = Date.now();
|
|
92948
|
-
const cwd = candidate.cwd ? (0,
|
|
93524
|
+
const cwd = candidate.cwd ? (0, import_path19.resolve)(workspace, candidate.cwd) : workspace;
|
|
92949
93525
|
const timeout = candidate.timeoutMs || REFINE_VALIDATION_TIMEOUT_MS;
|
|
92950
93526
|
const resolvedCommand = resolveWin32Executable(candidate.command);
|
|
92951
93527
|
const spawn7 = buildWin32ExecFileSpawn(resolvedCommand, candidate.args);
|
|
@@ -92978,7 +93554,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
92978
93554
|
let missingDepsBlocked = false;
|
|
92979
93555
|
for (const candidate of commandsToRun) {
|
|
92980
93556
|
const startedAt = Date.now();
|
|
92981
|
-
const cwd = candidate.cwd ? (0,
|
|
93557
|
+
const cwd = candidate.cwd ? (0, import_path19.resolve)(workspace, candidate.cwd) : workspace;
|
|
92982
93558
|
const timeout = candidate.timeoutMs || REFINE_VALIDATION_TIMEOUT_MS;
|
|
92983
93559
|
const bootstrapProvidedDependencies = summary.bootstrap?.stage === "cached" || summary.bootstrap?.stage === "ran" || summary.bootstrap?.stage === "legacy";
|
|
92984
93560
|
if (!bootstrapProvidedDependencies && needsNodeModules(candidate, cwd)) {
|
|
@@ -93045,7 +93621,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
93045
93621
|
summary.status = "passed";
|
|
93046
93622
|
return summary;
|
|
93047
93623
|
}
|
|
93048
|
-
var
|
|
93624
|
+
var import_path19;
|
|
93049
93625
|
var fs52;
|
|
93050
93626
|
var import_node_child_process11;
|
|
93051
93627
|
var REFINE_VALIDATION_TIMEOUT_MS;
|
|
@@ -93060,7 +93636,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
93060
93636
|
init_git_status();
|
|
93061
93637
|
init_refine_config();
|
|
93062
93638
|
init_worktree_bootstrap_config();
|
|
93063
|
-
|
|
93639
|
+
import_path19 = require("path");
|
|
93064
93640
|
fs52 = __toESM2(require("fs"));
|
|
93065
93641
|
import_node_child_process11 = require("child_process");
|
|
93066
93642
|
init_resolve_executable();
|
|
@@ -93073,7 +93649,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
93073
93649
|
REFINE_VALIDATION_SUMMARY_HEAD_CHARS = 2e3;
|
|
93074
93650
|
REFINE_VALIDATION_SUMMARY_TAIL_CHARS = 6e3;
|
|
93075
93651
|
REFINE_VALIDATION_SUMMARY_CHARS = REFINE_VALIDATION_SUMMARY_HEAD_CHARS + REFINE_VALIDATION_SUMMARY_TAIL_CHARS;
|
|
93076
|
-
REFINE_VALIDATION_LOG_DIR = (0,
|
|
93652
|
+
REFINE_VALIDATION_LOG_DIR = (0, import_path19.join)(".adhdev", "logs");
|
|
93077
93653
|
}
|
|
93078
93654
|
});
|
|
93079
93655
|
async function runMeshRefineSubmoduleReachabilityPreflight(args) {
|
|
@@ -93082,7 +93658,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
93082
93658
|
if (touched.length === 0) return void 0;
|
|
93083
93659
|
const entries = [];
|
|
93084
93660
|
for (const path63 of touched) {
|
|
93085
|
-
const probedRepo = (0,
|
|
93661
|
+
const probedRepo = (0, import_path20.resolve)(args.worktreeRoot, path63);
|
|
93086
93662
|
const commit = readTreeObject(args.worktreeRoot, args.branchRef, path63);
|
|
93087
93663
|
if (!commit) {
|
|
93088
93664
|
entries.push({
|
|
@@ -93237,7 +93813,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
93237
93813
|
}
|
|
93238
93814
|
var import_node_child_process12;
|
|
93239
93815
|
var import_node_util6;
|
|
93240
|
-
var
|
|
93816
|
+
var import_path20;
|
|
93241
93817
|
var execFileAsync5;
|
|
93242
93818
|
var runGit2;
|
|
93243
93819
|
var init_mesh_refine_submodule_preflight = __esm2({
|
|
@@ -93245,7 +93821,7 @@ ${mergeTreeErr?.stderr || ""}`;
|
|
|
93245
93821
|
"use strict";
|
|
93246
93822
|
import_node_child_process12 = require("child_process");
|
|
93247
93823
|
import_node_util6 = require("util");
|
|
93248
|
-
|
|
93824
|
+
import_path20 = require("path");
|
|
93249
93825
|
init_dist();
|
|
93250
93826
|
init_mesh_refine_gitlink_utils();
|
|
93251
93827
|
init_mesh_refine_gates();
|
|
@@ -98533,8 +99109,8 @@ ${e?.stderr || ""}`;
|
|
|
98533
99109
|
init_git_locale();
|
|
98534
99110
|
init_repo_mesh_types();
|
|
98535
99111
|
init_mesh_config();
|
|
98536
|
-
var
|
|
98537
|
-
var
|
|
99112
|
+
var import_fs13 = require("fs");
|
|
99113
|
+
var import_path11 = require("path");
|
|
98538
99114
|
init_refine_config();
|
|
98539
99115
|
init_worktree_bootstrap_config();
|
|
98540
99116
|
init_change_impact_config();
|
|
@@ -98553,22 +99129,22 @@ ${e?.stderr || ""}`;
|
|
|
98553
99129
|
"requirements.txt"
|
|
98554
99130
|
];
|
|
98555
99131
|
function writeConfigFile(workspace, relativePath, config2) {
|
|
98556
|
-
const target = (0,
|
|
98557
|
-
(0,
|
|
98558
|
-
(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)}
|
|
98559
99135
|
`, "utf-8");
|
|
98560
99136
|
return target;
|
|
98561
99137
|
}
|
|
98562
99138
|
function suggestMeshWorktreeBootstrapConfig(workspace) {
|
|
98563
99139
|
const commands = [];
|
|
98564
|
-
const hasPackageJson = (0,
|
|
98565
|
-
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"));
|
|
98566
99142
|
if (hasPackageJson) {
|
|
98567
99143
|
commands.push(
|
|
98568
99144
|
hasNpmLock ? { command: "npm", args: ["ci"] } : { command: "npm", args: ["install"] }
|
|
98569
99145
|
);
|
|
98570
99146
|
}
|
|
98571
|
-
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)));
|
|
98572
99148
|
if (!commands.length) {
|
|
98573
99149
|
return { commands, staleInputs };
|
|
98574
99150
|
}
|
|
@@ -98667,7 +99243,7 @@ ${e?.stderr || ""}`;
|
|
|
98667
99243
|
}
|
|
98668
99244
|
function applyConfigSuggestion(input) {
|
|
98669
99245
|
const { workspace, relativePath, existing, suggestedConfig, validate, write, overwrite } = input;
|
|
98670
|
-
const absolute = (0,
|
|
99246
|
+
const absolute = (0, import_path11.join)(workspace, relativePath);
|
|
98671
99247
|
if (existing !== void 0 && !overwrite) {
|
|
98672
99248
|
return { path: absolute, relativePath, written: false, skippedReason: "already_exists", config: existing };
|
|
98673
99249
|
}
|
|
@@ -99208,8 +99784,8 @@ ${e?.stderr || ""}`;
|
|
|
99208
99784
|
function isMeshTestPollution(args) {
|
|
99209
99785
|
return isSyntheticTestMeshId(args.meshId) || isSyntheticTestCoordinatorSession(args.coordinatorSessionId);
|
|
99210
99786
|
}
|
|
99211
|
-
var
|
|
99212
|
-
var
|
|
99787
|
+
var import_fs15 = require("fs");
|
|
99788
|
+
var import_path13 = require("path");
|
|
99213
99789
|
init_config();
|
|
99214
99790
|
var ZERO = {
|
|
99215
99791
|
inputTokens: 0,
|
|
@@ -99326,13 +99902,13 @@ ${e?.stderr || ""}`;
|
|
|
99326
99902
|
lastEvictedAt: 0
|
|
99327
99903
|
};
|
|
99328
99904
|
function getUsageDir() {
|
|
99329
|
-
const dir = (0,
|
|
99330
|
-
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 });
|
|
99331
99907
|
return dir;
|
|
99332
99908
|
}
|
|
99333
99909
|
function getUsagePath(meshId) {
|
|
99334
99910
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
99335
|
-
return (0,
|
|
99911
|
+
return (0, import_path13.join)(getUsageDir(), `${safe}.json`);
|
|
99336
99912
|
}
|
|
99337
99913
|
function emptyFile(meshId) {
|
|
99338
99914
|
return { version: 1, meshId, sessions: {} };
|
|
@@ -99342,7 +99918,7 @@ ${e?.stderr || ""}`;
|
|
|
99342
99918
|
const path63 = getUsagePath(meshId);
|
|
99343
99919
|
let stat2;
|
|
99344
99920
|
try {
|
|
99345
|
-
const s2 = (0,
|
|
99921
|
+
const s2 = (0, import_fs15.statSync)(path63);
|
|
99346
99922
|
stat2 = { mtimeMs: s2.mtimeMs, size: s2.size };
|
|
99347
99923
|
} catch {
|
|
99348
99924
|
usageFileCache.delete(path63);
|
|
@@ -99353,7 +99929,7 @@ ${e?.stderr || ""}`;
|
|
|
99353
99929
|
return cached5.file;
|
|
99354
99930
|
}
|
|
99355
99931
|
try {
|
|
99356
|
-
const parsed = JSON.parse((0,
|
|
99932
|
+
const parsed = JSON.parse((0, import_fs15.readFileSync)(path63, "utf-8"));
|
|
99357
99933
|
if (!parsed || typeof parsed !== "object" || !parsed.sessions) {
|
|
99358
99934
|
usageFileCache.delete(path63);
|
|
99359
99935
|
return emptyFile(meshId);
|
|
@@ -99368,19 +99944,19 @@ ${e?.stderr || ""}`;
|
|
|
99368
99944
|
function writeUsageFile(meshId, file2) {
|
|
99369
99945
|
const path63 = getUsagePath(meshId);
|
|
99370
99946
|
const tmp = `${path63}.tmp`;
|
|
99371
|
-
(0,
|
|
99947
|
+
(0, import_fs15.writeFileSync)(tmp, JSON.stringify(file2), { encoding: "utf-8", mode: 384 });
|
|
99372
99948
|
try {
|
|
99373
|
-
(0,
|
|
99949
|
+
(0, import_fs15.renameSync)(tmp, path63);
|
|
99374
99950
|
} catch (e) {
|
|
99375
99951
|
try {
|
|
99376
|
-
(0,
|
|
99952
|
+
(0, import_fs15.unlinkSync)(tmp);
|
|
99377
99953
|
} catch {
|
|
99378
99954
|
}
|
|
99379
99955
|
usageFileCache.delete(path63);
|
|
99380
99956
|
throw e;
|
|
99381
99957
|
}
|
|
99382
99958
|
try {
|
|
99383
|
-
const s2 = (0,
|
|
99959
|
+
const s2 = (0, import_fs15.statSync)(path63);
|
|
99384
99960
|
usageFileCache.set(path63, { file: file2, mtimeMs: s2.mtimeMs, size: s2.size });
|
|
99385
99961
|
} catch {
|
|
99386
99962
|
usageFileCache.delete(path63);
|
|
@@ -100896,7 +101472,7 @@ The pin is NOT cleared automatically: a pin often encodes required context conti
|
|
|
100896
101472
|
init_state_store();
|
|
100897
101473
|
var import_child_process5 = require("child_process");
|
|
100898
101474
|
var import_util22 = require("util");
|
|
100899
|
-
var
|
|
101475
|
+
var import_fs20 = require("fs");
|
|
100900
101476
|
var import_os3 = require("os");
|
|
100901
101477
|
var path27 = __toESM2(require("path"));
|
|
100902
101478
|
var fs18 = __toESM2(require("fs"));
|
|
@@ -100973,7 +101549,7 @@ The pin is NOT cleared automatically: a pin often encodes required context conti
|
|
|
100973
101549
|
if (path27.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~")) {
|
|
100974
101550
|
const candidate = trimmed.startsWith("~") ? path27.join((0, import_os3.homedir)(), trimmed.slice(1)) : trimmed;
|
|
100975
101551
|
const resolved = path27.isAbsolute(candidate) ? candidate : path27.resolve(candidate);
|
|
100976
|
-
return (0,
|
|
101552
|
+
return (0, import_fs20.existsSync)(resolved) ? resolved : null;
|
|
100977
101553
|
}
|
|
100978
101554
|
const isWin = (0, import_os3.platform)() === "win32";
|
|
100979
101555
|
const paths = (process.env.PATH || "").split(isWin ? ";" : ":");
|
|
@@ -100983,8 +101559,8 @@ The pin is NOT cleared automatically: a pin often encodes required context conti
|
|
|
100983
101559
|
for (const ext of exes) {
|
|
100984
101560
|
const fullPath = path27.join(p, trimmed + ext);
|
|
100985
101561
|
try {
|
|
100986
|
-
if ((0,
|
|
100987
|
-
const stat2 = (0,
|
|
101562
|
+
if ((0, import_fs20.existsSync)(fullPath)) {
|
|
101563
|
+
const stat2 = (0, import_fs20.statSync)(fullPath);
|
|
100988
101564
|
if (stat2.isFile() && (isWin || stat2.mode & 73)) {
|
|
100989
101565
|
return fullPath;
|
|
100990
101566
|
}
|
|
@@ -101002,9 +101578,9 @@ The pin is NOT cleared automatically: a pin often encodes required context conti
|
|
|
101002
101578
|
if (normalized.includes("*")) {
|
|
101003
101579
|
const username = home.split(/[\\/]/).pop() || "";
|
|
101004
101580
|
const resolved = normalized.replace("*", username);
|
|
101005
|
-
if ((0,
|
|
101581
|
+
if ((0, import_fs20.existsSync)(resolved)) return resolved;
|
|
101006
101582
|
} else {
|
|
101007
|
-
if ((0,
|
|
101583
|
+
if ((0, import_fs20.existsSync)(normalized)) return normalized;
|
|
101008
101584
|
}
|
|
101009
101585
|
}
|
|
101010
101586
|
return null;
|
|
@@ -101018,7 +101594,7 @@ The pin is NOT cleared automatically: a pin often encodes required context conti
|
|
|
101018
101594
|
let resolvedCli = cliPath;
|
|
101019
101595
|
if (!resolvedCli && appPath && os35 === "darwin") {
|
|
101020
101596
|
const bundledCli = `${appPath}/Contents/Resources/app/bin/${def.cli}`;
|
|
101021
|
-
if ((0,
|
|
101597
|
+
if ((0, import_fs20.existsSync)(bundledCli)) resolvedCli = bundledCli;
|
|
101022
101598
|
}
|
|
101023
101599
|
if (!resolvedCli && appPath && os35 === "win32") {
|
|
101024
101600
|
const { dirname: dirname25 } = await import("path");
|
|
@@ -101031,7 +101607,7 @@ The pin is NOT cleared automatically: a pin often encodes required context conti
|
|
|
101031
101607
|
`${appDir}\\\\resources\\\\app\\\\bin\\\\${def.cli}.cmd`
|
|
101032
101608
|
];
|
|
101033
101609
|
for (const c of candidates) {
|
|
101034
|
-
if ((0,
|
|
101610
|
+
if ((0, import_fs20.existsSync)(c)) {
|
|
101035
101611
|
resolvedCli = c;
|
|
101036
101612
|
break;
|
|
101037
101613
|
}
|
|
@@ -112960,7 +113536,7 @@ ${marker}`,
|
|
|
112960
113536
|
var os26 = __toESM2(require("os"));
|
|
112961
113537
|
var path43 = __toESM2(require("path"));
|
|
112962
113538
|
var crypto6 = __toESM2(require("crypto"));
|
|
112963
|
-
var
|
|
113539
|
+
var import_fs21 = require("fs");
|
|
112964
113540
|
var import_child_process11 = require("child_process");
|
|
112965
113541
|
var import_chalk = __toESM2((init_source(), __toCommonJS(source_exports)));
|
|
112966
113542
|
var fs34 = __toESM2(require("fs"));
|
|
@@ -115605,7 +116181,7 @@ ${marker}`,
|
|
|
115605
116181
|
return v;
|
|
115606
116182
|
});
|
|
115607
116183
|
if (missing) return null;
|
|
115608
|
-
return out;
|
|
116184
|
+
return out.includes("*") ? out : path38.normalize(out);
|
|
115609
116185
|
}
|
|
115610
116186
|
function claudeProjectDirName(workspace) {
|
|
115611
116187
|
return workspace.replace(/[^A-Za-z0-9_-]/g, "-");
|
|
@@ -117919,8 +118495,8 @@ ${marker}`,
|
|
|
117919
118495
|
const landedQuestion = readFocusedClaudeTuiQuestion(landed.screenText);
|
|
117920
118496
|
const rereadQuestion = readFocusedClaudeTuiQuestion(reread);
|
|
117921
118497
|
if (!landedQuestion || !rereadQuestion) return true;
|
|
117922
|
-
const
|
|
117923
|
-
return
|
|
118498
|
+
const normalize7 = (text) => text.replace(/\s+/g, " ").trim();
|
|
118499
|
+
return normalize7(landedQuestion.question) === normalize7(rereadQuestion.question);
|
|
117924
118500
|
}
|
|
117925
118501
|
async captureClaudeTuiPrompt(firstScreen, headers) {
|
|
117926
118502
|
if (this.claudeTuiCaptureSuppressed) return;
|
|
@@ -118137,8 +118713,8 @@ ${marker}`,
|
|
|
118137
118713
|
};
|
|
118138
118714
|
}
|
|
118139
118715
|
function isPathInsideWorkspace(configPath, workspace) {
|
|
118140
|
-
const
|
|
118141
|
-
const ws =
|
|
118716
|
+
const normalize7 = (value) => value.replace(/[\\/]+$/, "");
|
|
118717
|
+
const ws = normalize7(workspace);
|
|
118142
118718
|
if (!ws) return false;
|
|
118143
118719
|
const separatorAgnostic = (value) => value.replace(/\\/g, "/");
|
|
118144
118720
|
const normalizedPath = separatorAgnostic(configPath);
|
|
@@ -124518,7 +125094,7 @@ ${rawInput}` : rawInput;
|
|
|
124518
125094
|
const trimmed = command.trim();
|
|
124519
125095
|
if (!trimmed) return false;
|
|
124520
125096
|
if (isExplicitCommand(trimmed)) {
|
|
124521
|
-
return (0,
|
|
125097
|
+
return (0, import_fs21.existsSync)(expandExecutable(trimmed));
|
|
124522
125098
|
}
|
|
124523
125099
|
try {
|
|
124524
125100
|
(0, import_child_process11.execFileSync)(process.platform === "win32" ? "where" : "which", [trimmed], {
|
|
@@ -124664,10 +125240,10 @@ ${rawInput}` : rawInput;
|
|
|
124664
125240
|
}
|
|
124665
125241
|
function ensureEmptyDelegatedMcpConfig(workspace) {
|
|
124666
125242
|
const baseDir = path43.join(os26.tmpdir(), "adhdev-delegated-agent-empty-mcp");
|
|
124667
|
-
(0,
|
|
125243
|
+
(0, import_fs21.mkdirSync)(baseDir, { recursive: true });
|
|
124668
125244
|
const workspaceHash = shortHash(path43.resolve(workspace || os26.tmpdir()));
|
|
124669
125245
|
const filePath = path43.join(baseDir, `${workspaceHash}.json`);
|
|
124670
|
-
(0,
|
|
125246
|
+
(0, import_fs21.writeFileSync)(filePath, JSON.stringify({ mcpServers: {} }, null, 2), "utf-8");
|
|
124671
125247
|
return filePath;
|
|
124672
125248
|
}
|
|
124673
125249
|
function buildCoordinatorDelegatedCliLaunchOptions(input) {
|
|
@@ -131505,9 +132081,9 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
131505
132081
|
}
|
|
131506
132082
|
}
|
|
131507
132083
|
compareVersions(a, b) {
|
|
131508
|
-
const
|
|
131509
|
-
const pa =
|
|
131510
|
-
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);
|
|
131511
132087
|
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
131512
132088
|
const va = pa[i] || 0;
|
|
131513
132089
|
const vb = pb[i] || 0;
|
|
@@ -132391,11 +132967,11 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
132391
132967
|
MESH_JSON_CONFIG_LOCATIONS: MESH_JSON_CONFIG_LOCATIONS2
|
|
132392
132968
|
} = await Promise.resolve().then(() => (init_mesh_json_config(), mesh_json_config_exports));
|
|
132393
132969
|
const { mkdirSync: mkdirSync34, writeFileSync: writeFileSync32 } = await import("fs");
|
|
132394
|
-
const { dirname: dirname25, join:
|
|
132970
|
+
const { dirname: dirname25, join: join74 } = await import("path");
|
|
132395
132971
|
const scaffold = buildMeshJsonConfigScaffold2(mesh);
|
|
132396
132972
|
const scaffoldJson = serializeMeshJsonConfigScaffold2(scaffold);
|
|
132397
132973
|
const relativePath = MESH_JSON_CONFIG_LOCATIONS2[0];
|
|
132398
|
-
const absolutePath =
|
|
132974
|
+
const absolutePath = join74(workspace, relativePath);
|
|
132399
132975
|
const validation = normalizeRepoMeshDeclarativeConfig2(scaffold);
|
|
132400
132976
|
if (!validation.valid) {
|
|
132401
132977
|
return { success: false, meshId, error: `invalid mesh.json scaffold: ${validation.errors.join("; ")}` };
|
|
@@ -132501,18 +133077,18 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
132501
133077
|
normalizeRepoMeshDeclarativeConfig: normalizeRepoMeshDeclarativeConfig2,
|
|
132502
133078
|
MESH_JSON_CONFIG_LOCATIONS: MESH_JSON_CONFIG_LOCATIONS2
|
|
132503
133079
|
} = await Promise.resolve().then(() => (init_mesh_json_config(), mesh_json_config_exports));
|
|
132504
|
-
const { existsSync:
|
|
132505
|
-
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");
|
|
132506
133082
|
const yaml6 = await Promise.resolve().then(() => (init_js_yaml(), js_yaml_exports));
|
|
132507
133083
|
const relativePath = MESH_JSON_CONFIG_LOCATIONS2[0];
|
|
132508
133084
|
let baseDoc = { version: 1 };
|
|
132509
|
-
let existingPath =
|
|
133085
|
+
let existingPath = join74(workspace, relativePath);
|
|
132510
133086
|
let existedAsYaml = false;
|
|
132511
133087
|
for (const relative8 of MESH_JSON_CONFIG_LOCATIONS2) {
|
|
132512
|
-
const candidate =
|
|
132513
|
-
if (!
|
|
133088
|
+
const candidate = join74(workspace, relative8);
|
|
133089
|
+
if (!existsSync74(candidate)) continue;
|
|
132514
133090
|
try {
|
|
132515
|
-
const text =
|
|
133091
|
+
const text = readFileSync59(candidate, "utf-8");
|
|
132516
133092
|
const parsed = /\.json$/i.test(candidate) ? JSON.parse(text) : yaml6.load(text);
|
|
132517
133093
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
132518
133094
|
baseDoc = parsed;
|
|
@@ -134559,7 +135135,7 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
134559
135135
|
}
|
|
134560
135136
|
}
|
|
134561
135137
|
};
|
|
134562
|
-
var
|
|
135138
|
+
var import_path21 = require("path");
|
|
134563
135139
|
var fs53 = __toESM2(require("fs"));
|
|
134564
135140
|
init_logger();
|
|
134565
135141
|
init_mesh_host_ownership();
|
|
@@ -134600,9 +135176,9 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
134600
135176
|
}
|
|
134601
135177
|
}
|
|
134602
135178
|
function isWorkspaceLocalPath(configPath, workspace) {
|
|
134603
|
-
const resolvedConfig = (0,
|
|
134604
|
-
const resolvedWorkspace = (0,
|
|
134605
|
-
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);
|
|
134606
135182
|
}
|
|
134607
135183
|
var meshCoordinatorLaunchHandlers = {
|
|
134608
135184
|
launch_mesh_coordinator: async (ctx, args) => {
|
|
@@ -134864,7 +135440,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
134864
135440
|
};
|
|
134865
135441
|
}
|
|
134866
135442
|
if (cliType === "codex-cli") {
|
|
134867
|
-
const repoMcpConfigPath = (0,
|
|
135443
|
+
const repoMcpConfigPath = (0, import_path21.join)(workspace, ".mcp.json");
|
|
134868
135444
|
if (fs53.existsSync(repoMcpConfigPath)) {
|
|
134869
135445
|
try {
|
|
134870
135446
|
const repoMcpConfig = parseMeshCoordinatorMcpConfig(
|
|
@@ -135037,7 +135613,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
135037
135613
|
workspace
|
|
135038
135614
|
};
|
|
135039
135615
|
}
|
|
135040
|
-
const { existsSync:
|
|
135616
|
+
const { existsSync: existsSync74, readFileSync: readFileSync59, writeFileSync: writeFileSync32, copyFileSync: copyFileSync3, mkdirSync: mkdirSync34 } = await import("fs");
|
|
135041
135617
|
const { dirname: dirname25 } = await import("path");
|
|
135042
135618
|
const mcpConfigPath = coordinatorSetup.configPath;
|
|
135043
135619
|
const hermesManualFallback = cliType === "hermes-cli" && configFormat === "hermes_config_yaml" ? createHermesManualMeshCoordinatorSetup(meshId, workspace) : null;
|
|
@@ -135082,14 +135658,14 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
135082
135658
|
if (hermesManualFallback) return returnManualFallback(message);
|
|
135083
135659
|
return { success: false, code: "mesh_coordinator_config_write_failed", error: message, meshId, cliType, workspace };
|
|
135084
135660
|
}
|
|
135085
|
-
const hadExistingMcpConfig =
|
|
135661
|
+
const hadExistingMcpConfig = existsSync74(mcpConfigPath);
|
|
135086
135662
|
let existingMcpConfig = hermesBaseConfig?.config || {};
|
|
135087
135663
|
if (hermesBaseConfig) {
|
|
135088
135664
|
copyHermesCoordinatorCredentialFiles(hermesBaseConfig.sourceHome, dirname25(mcpConfigPath));
|
|
135089
135665
|
}
|
|
135090
135666
|
if (hadExistingMcpConfig) {
|
|
135091
135667
|
try {
|
|
135092
|
-
const parsedExistingMcpConfig = parseMeshCoordinatorMcpConfig(
|
|
135668
|
+
const parsedExistingMcpConfig = parseMeshCoordinatorMcpConfig(readFileSync59(mcpConfigPath, "utf-8"), configFormat);
|
|
135093
135669
|
const existingCoordinatorConfig = hermesManualFallback ? stripHermesCoordinatorTempModelProviderOverrides(parsedExistingMcpConfig) : parsedExistingMcpConfig;
|
|
135094
135670
|
existingMcpConfig = { ...existingMcpConfig, ...existingCoordinatorConfig };
|
|
135095
135671
|
copyFileSync3(mcpConfigPath, mcpConfigPath + ".backup");
|
|
@@ -135900,7 +136476,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
135900
136476
|
const { deriveMeshReviewInboxItems: deriveMeshReviewInboxItems2 } = await Promise.resolve().then(() => (init_mesh_review_inbox(), mesh_review_inbox_exports));
|
|
135901
136477
|
const { readLedgerEntries: readLedgerEntries2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
|
|
135902
136478
|
const { getGitDiffSummary: getGitDiffSummary2 } = await Promise.resolve().then(() => (init_git_diff(), git_diff_exports));
|
|
135903
|
-
const { existsSync:
|
|
136479
|
+
const { existsSync: existsSync74 } = await import("fs");
|
|
135904
136480
|
const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
135905
136481
|
const mesh = meshRecord?.mesh;
|
|
135906
136482
|
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
@@ -135919,7 +136495,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
135919
136495
|
const derivation = deriveMeshReviewInboxItems2({ nodes: nodeStatuses, ledgerEntries });
|
|
135920
136496
|
for (const item of derivation.items) {
|
|
135921
136497
|
const workspace = item.workspace;
|
|
135922
|
-
if (!workspace || !
|
|
136498
|
+
if (!workspace || !existsSync74(workspace)) continue;
|
|
135923
136499
|
const baseRef = item.defaultBranch ? `origin/${item.defaultBranch}` : "origin/main";
|
|
135924
136500
|
try {
|
|
135925
136501
|
const diffResult = await getGitDiffSummary2(workspace, { baseRef, maxFiles: 100 });
|
|
@@ -136121,7 +136697,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
136121
136697
|
init_router_refine();
|
|
136122
136698
|
var fs56 = __toESM2(require("fs"));
|
|
136123
136699
|
var import_node_os22 = require("os");
|
|
136124
|
-
var
|
|
136700
|
+
var import_path222 = require("path");
|
|
136125
136701
|
init_logger();
|
|
136126
136702
|
init_git_locale();
|
|
136127
136703
|
init_dist();
|
|
@@ -136133,7 +136709,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
136133
136709
|
function acceptableManagedWorktreePaths(resolveWorktreePath2, normalizePath2, repoRoot, meshName, branch, worktreeBaseDir) {
|
|
136134
136710
|
const safeBranch = branch.replace(/[/\\:*?"<>|]/g, "-").replace(/^\.+|\.+$/g, "");
|
|
136135
136711
|
const safeMeshName = meshName.replace(/[/\\:*?"<>|]/g, "-").replace(/^\.+|\.+$/g, "");
|
|
136136
|
-
const legacyPath = (0,
|
|
136712
|
+
const legacyPath = (0, import_path222.join)((0, import_path222.dirname)(repoRoot), LEGACY_WORKTREE_DIR_NAME, safeMeshName, safeBranch);
|
|
136137
136713
|
const candidates = [
|
|
136138
136714
|
resolveWorktreePath2(repoRoot, meshName, branch, worktreeBaseDir),
|
|
136139
136715
|
legacyPath
|
|
@@ -136160,8 +136736,8 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
136160
136736
|
function looksLikeCrossTrackWorktreePath(actualPath, normalizePath2) {
|
|
136161
136737
|
const home = normalizePath2((0, import_node_os22.homedir)());
|
|
136162
136738
|
return TRACK_CONFIG_DIR_NAMES.some((trackDirName) => {
|
|
136163
|
-
const trackWorktreesDir = (0,
|
|
136164
|
-
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);
|
|
136165
136741
|
});
|
|
136166
136742
|
}
|
|
136167
136743
|
function unexpectedPathRecoveryHint(actualPath, normalizePath2, suffix) {
|
|
@@ -136271,7 +136847,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
136271
136847
|
}
|
|
136272
136848
|
const { resolveWorktreePath: resolveWorktreePath2, listWorktrees: listWorktrees2 } = await Promise.resolve().then(() => (init_git_worktree(), git_worktree_exports));
|
|
136273
136849
|
const normalizePath2 = (value) => {
|
|
136274
|
-
const resolved = (0,
|
|
136850
|
+
const resolved = (0, import_path222.resolve)(value);
|
|
136275
136851
|
try {
|
|
136276
136852
|
return fs56.realpathSync(resolved);
|
|
136277
136853
|
} catch {
|
|
@@ -136398,7 +136974,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
136398
136974
|
}
|
|
136399
136975
|
const { resolveWorktreePath: resolveWorktreePath2, listWorktrees: listWorktrees2, removeWorktree: removeWorktree2 } = await Promise.resolve().then(() => (init_git_worktree(), git_worktree_exports));
|
|
136400
136976
|
const normalizePath2 = (value) => {
|
|
136401
|
-
const resolved = (0,
|
|
136977
|
+
const resolved = (0, import_path222.resolve)(value);
|
|
136402
136978
|
try {
|
|
136403
136979
|
return fs56.realpathSync(resolved);
|
|
136404
136980
|
} catch {
|
|
@@ -137066,7 +137642,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
137066
137642
|
init_logger();
|
|
137067
137643
|
var yaml5 = __toESM2(require_js_yaml());
|
|
137068
137644
|
var import_os5 = require("os");
|
|
137069
|
-
var
|
|
137645
|
+
var import_path23 = require("path");
|
|
137070
137646
|
var fs57 = __toESM2(require("fs"));
|
|
137071
137647
|
var MESH_COORDINATOR_AUTO_IMPORT_FORMATS = ["claude_mcp_json", "hermes_config_yaml", "opencode_json"];
|
|
137072
137648
|
function isSupportedMeshCoordinatorConfigFormat(format) {
|
|
@@ -137107,13 +137683,13 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
137107
137683
|
}
|
|
137108
137684
|
function resolveHermesUserHome() {
|
|
137109
137685
|
const explicitHome = process.env.HERMES_HOME?.trim();
|
|
137110
|
-
return explicitHome || (0,
|
|
137686
|
+
return explicitHome || (0, import_path23.join)((0, import_os5.homedir)(), ".hermes");
|
|
137111
137687
|
}
|
|
137112
137688
|
function loadHermesCoordinatorBaseConfig(targetConfigPath) {
|
|
137113
137689
|
const sourceHome = resolveHermesUserHome();
|
|
137114
|
-
const sourceConfigPath = (0,
|
|
137690
|
+
const sourceConfigPath = (0, import_path23.join)(sourceHome, "config.yaml");
|
|
137115
137691
|
if (!fs57.existsSync(sourceConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
137116
|
-
if ((0,
|
|
137692
|
+
if ((0, import_path23.resolve)(sourceConfigPath) === (0, import_path23.resolve)(targetConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
137117
137693
|
const parsed = parseMeshCoordinatorMcpConfig(fs57.readFileSync(sourceConfigPath, "utf-8"), "hermes_config_yaml");
|
|
137118
137694
|
const { mcp_servers: _mcpServers, ...baseConfig } = parsed;
|
|
137119
137695
|
return { config: baseConfig, sourceHome, sourceConfigPath };
|
|
@@ -137147,10 +137723,10 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
137147
137723
|
return sanitized;
|
|
137148
137724
|
}
|
|
137149
137725
|
function copyHermesCoordinatorCredentialFiles(sourceHome, targetHome) {
|
|
137150
|
-
if ((0,
|
|
137726
|
+
if ((0, import_path23.resolve)(sourceHome) === (0, import_path23.resolve)(targetHome)) return;
|
|
137151
137727
|
for (const fileName of [".env", "auth.json"]) {
|
|
137152
|
-
const sourcePath = (0,
|
|
137153
|
-
const targetPath = (0,
|
|
137728
|
+
const sourcePath = (0, import_path23.join)(sourceHome, fileName);
|
|
137729
|
+
const targetPath = (0, import_path23.join)(targetHome, fileName);
|
|
137154
137730
|
if (!fs57.existsSync(sourcePath)) continue;
|
|
137155
137731
|
try {
|
|
137156
137732
|
fs57.copyFileSync(sourcePath, targetPath);
|
|
@@ -138678,6 +139254,108 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
138678
139254
|
init_runtime_defaults();
|
|
138679
139255
|
init_snapshot3();
|
|
138680
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
|
+
}
|
|
138681
139359
|
function buildCloudP2PSummary(p2p) {
|
|
138682
139360
|
if (!p2p) return void 0;
|
|
138683
139361
|
const counter = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
@@ -138751,6 +139429,59 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
138751
139429
|
timestamp: timestamp2
|
|
138752
139430
|
};
|
|
138753
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
|
+
}
|
|
138754
139485
|
var SERVER_DEDUP_KEEPALIVE_REPORTS = 10;
|
|
138755
139486
|
var DaemonStatusReporter = class {
|
|
138756
139487
|
deps;
|
|
@@ -139014,6 +139745,20 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
139014
139745
|
);
|
|
139015
139746
|
}
|
|
139016
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
|
+
}));
|
|
139017
139762
|
if (opts?.p2pOnly) return;
|
|
139018
139763
|
if (!serverConnected || !serverConn) return;
|
|
139019
139764
|
const wsPayload = buildCloudStatusReportPayload(
|
|
@@ -146561,8 +147306,8 @@ data: ${JSON.stringify(msg.data)}
|
|
|
146561
147306
|
init_contract();
|
|
146562
147307
|
init_mesh_events();
|
|
146563
147308
|
init_mesh_reconcile_loop();
|
|
146564
|
-
var
|
|
146565
|
-
var
|
|
147309
|
+
var import_fs22 = require("fs");
|
|
147310
|
+
var import_path24 = require("path");
|
|
146566
147311
|
var import_crypto18 = require("crypto");
|
|
146567
147312
|
init_logger();
|
|
146568
147313
|
init_mesh_ledger();
|
|
@@ -146630,31 +147375,31 @@ data: ${JSON.stringify(msg.data)}
|
|
|
146630
147375
|
} catch {
|
|
146631
147376
|
return result;
|
|
146632
147377
|
}
|
|
146633
|
-
if (!(0,
|
|
147378
|
+
if (!(0, import_fs22.existsSync)(dir)) return result;
|
|
146634
147379
|
let names;
|
|
146635
147380
|
try {
|
|
146636
|
-
names = (0,
|
|
147381
|
+
names = (0, import_fs22.readdirSync)(dir);
|
|
146637
147382
|
} catch (e) {
|
|
146638
147383
|
LOG2.warn("MeshEvents", `Pending-events migration: cannot read ledger dir: ${e?.message || e}`);
|
|
146639
147384
|
return result;
|
|
146640
147385
|
}
|
|
146641
147386
|
for (const name of names) {
|
|
146642
147387
|
if (!isPendingEventsFile(name)) continue;
|
|
146643
|
-
const path63 = (0,
|
|
147388
|
+
const path63 = (0, import_path24.join)(dir, name);
|
|
146644
147389
|
result.filesScanned++;
|
|
146645
147390
|
const claimed = `${path63}.migrating`;
|
|
146646
147391
|
try {
|
|
146647
|
-
(0,
|
|
147392
|
+
(0, import_fs22.renameSync)(path63, claimed);
|
|
146648
147393
|
} catch {
|
|
146649
147394
|
continue;
|
|
146650
147395
|
}
|
|
146651
147396
|
let content;
|
|
146652
147397
|
try {
|
|
146653
|
-
content = (0,
|
|
147398
|
+
content = (0, import_fs22.readFileSync)(claimed, "utf-8");
|
|
146654
147399
|
} catch (e) {
|
|
146655
147400
|
LOG2.warn("MeshEvents", `Pending-events migration: cannot read ${name}; leaving it for the next boot: ${e?.message || e}`);
|
|
146656
147401
|
try {
|
|
146657
|
-
(0,
|
|
147402
|
+
(0, import_fs22.renameSync)(claimed, path63);
|
|
146658
147403
|
} catch {
|
|
146659
147404
|
}
|
|
146660
147405
|
result.filesRetained++;
|
|
@@ -146669,14 +147414,14 @@ data: ${JSON.stringify(msg.data)}
|
|
|
146669
147414
|
}
|
|
146670
147415
|
if (!allImported) {
|
|
146671
147416
|
try {
|
|
146672
|
-
(0,
|
|
147417
|
+
(0, import_fs22.renameSync)(claimed, path63);
|
|
146673
147418
|
} catch {
|
|
146674
147419
|
}
|
|
146675
147420
|
result.filesRetained++;
|
|
146676
147421
|
continue;
|
|
146677
147422
|
}
|
|
146678
147423
|
try {
|
|
146679
|
-
(0,
|
|
147424
|
+
(0, import_fs22.unlinkSync)(claimed);
|
|
146680
147425
|
result.filesRemoved++;
|
|
146681
147426
|
} catch (e) {
|
|
146682
147427
|
LOG2.warn("MeshEvents", `Pending-events migration: imported ${name} but could not unlink it: ${e?.message || e}`);
|
|
@@ -146834,20 +147579,20 @@ data: ${JSON.stringify(msg.data)}
|
|
|
146834
147579
|
};
|
|
146835
147580
|
}
|
|
146836
147581
|
init_require_whitelist();
|
|
146837
|
-
var
|
|
146838
|
-
var
|
|
147582
|
+
var import_fs23 = require("fs");
|
|
147583
|
+
var import_path25 = require("path");
|
|
146839
147584
|
init_config();
|
|
146840
147585
|
init_logger();
|
|
146841
147586
|
var FLEET_SECRET_FILE = "seqscribe-fleet-secret.json";
|
|
146842
147587
|
function fleetSecretPath(env2) {
|
|
146843
|
-
return (0,
|
|
147588
|
+
return (0, import_path25.join)(getConfigDir2(env2), FLEET_SECRET_FILE);
|
|
146844
147589
|
}
|
|
146845
147590
|
function loadStoredFleetSecret(env2) {
|
|
146846
147591
|
const path63 = fleetSecretPath(env2);
|
|
146847
|
-
if (!(0,
|
|
147592
|
+
if (!(0, import_fs23.existsSync)(path63)) return null;
|
|
146848
147593
|
let raw;
|
|
146849
147594
|
try {
|
|
146850
|
-
raw = (0,
|
|
147595
|
+
raw = (0, import_fs23.readFileSync)(path63, "utf-8");
|
|
146851
147596
|
} catch (err) {
|
|
146852
147597
|
LOG2.warn(
|
|
146853
147598
|
"Seqscribe",
|
|
@@ -146874,32 +147619,32 @@ data: ${JSON.stringify(msg.data)}
|
|
|
146874
147619
|
throw new Error("storeFleetSecret requires an integer version >= 1");
|
|
146875
147620
|
}
|
|
146876
147621
|
const dir = getConfigDir2(env2);
|
|
146877
|
-
if (!(0,
|
|
146878
|
-
(0,
|
|
147622
|
+
if (!(0, import_fs23.existsSync)(dir)) {
|
|
147623
|
+
(0, import_fs23.mkdirSync)(dir, { recursive: true, mode: 448 });
|
|
146879
147624
|
}
|
|
146880
|
-
const path63 = (0,
|
|
147625
|
+
const path63 = (0, import_path25.join)(dir, FLEET_SECRET_FILE);
|
|
146881
147626
|
const tmp = `${path63}.tmp-${process.pid}`;
|
|
146882
|
-
(0,
|
|
147627
|
+
(0, import_fs23.writeFileSync)(tmp, JSON.stringify({ secret, version: version2 }, null, 2), {
|
|
146883
147628
|
encoding: "utf-8",
|
|
146884
147629
|
mode: 384
|
|
146885
147630
|
});
|
|
146886
147631
|
try {
|
|
146887
|
-
(0,
|
|
147632
|
+
(0, import_fs23.renameSync)(tmp, path63);
|
|
146888
147633
|
} catch (err) {
|
|
146889
147634
|
try {
|
|
146890
|
-
(0,
|
|
147635
|
+
(0, import_fs23.unlinkSync)(tmp);
|
|
146891
147636
|
} catch {
|
|
146892
147637
|
}
|
|
146893
147638
|
throw err;
|
|
146894
147639
|
}
|
|
146895
147640
|
try {
|
|
146896
|
-
(0,
|
|
147641
|
+
(0, import_fs23.chmodSync)(path63, 384);
|
|
146897
147642
|
} catch {
|
|
146898
147643
|
}
|
|
146899
147644
|
LOG2.info("Seqscribe", `fleet secret stored (v${version2})`);
|
|
146900
147645
|
}
|
|
146901
|
-
var
|
|
146902
|
-
var
|
|
147646
|
+
var import_fs24 = require("fs");
|
|
147647
|
+
var import_path26 = require("path");
|
|
146903
147648
|
init_dist2();
|
|
146904
147649
|
init_config();
|
|
146905
147650
|
init_logger();
|
|
@@ -146909,12 +147654,12 @@ data: ${JSON.stringify(msg.data)}
|
|
|
146909
147654
|
var SEQSCRIBE_DB_NAME = "seqscribe.db";
|
|
146910
147655
|
var WRITER_ID_PREFIX = "adhdev";
|
|
146911
147656
|
function getSeqscribeDbPath() {
|
|
146912
|
-
return (0,
|
|
147657
|
+
return (0, import_path26.join)(getConfigDir2(), SEQSCRIBE_DB_NAME);
|
|
146913
147658
|
}
|
|
146914
147659
|
function openSeqscribeNode(opts = {}) {
|
|
146915
147660
|
const dbPath = opts.dbPath ?? getSeqscribeDbPath();
|
|
146916
|
-
const dir = (0,
|
|
146917
|
-
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 });
|
|
146918
147663
|
const Database = loadBetterSqlite3();
|
|
146919
147664
|
const db = new Database(dbPath);
|
|
146920
147665
|
db.pragma("journal_mode = WAL");
|
|
@@ -146976,6 +147721,32 @@ data: ${JSON.stringify(msg.data)}
|
|
|
146976
147721
|
authority: authority.authority,
|
|
146977
147722
|
intervalMs: opts.finalityIntervalMs
|
|
146978
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
|
+
}
|
|
146979
147750
|
LOG2.info(
|
|
146980
147751
|
"Seqscribe",
|
|
146981
147752
|
`node open writer=${writerId} topics=${defs.length} authority=${authority ? "on" : "off"}${opts.isCoordinator ? " role=coordinator" : ""}`
|
|
@@ -146988,6 +147759,10 @@ data: ${JSON.stringify(msg.data)}
|
|
|
146988
147759
|
finalityLoop?.stop();
|
|
146989
147760
|
} catch {
|
|
146990
147761
|
}
|
|
147762
|
+
try {
|
|
147763
|
+
unsubAnomaly?.();
|
|
147764
|
+
} catch {
|
|
147765
|
+
}
|
|
146991
147766
|
try {
|
|
146992
147767
|
await node.close();
|
|
146993
147768
|
} catch (err) {
|
|
@@ -147145,6 +147920,41 @@ data: ${JSON.stringify(msg.data)}
|
|
|
147145
147920
|
if (peer.queuedData > maxQueued) maxQueued = peer.queuedData;
|
|
147146
147921
|
if (peer.state === "ready") peersReady++;
|
|
147147
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
|
+
}
|
|
147148
147958
|
return {
|
|
147149
147959
|
topics,
|
|
147150
147960
|
peers: stats.peers.length,
|
|
@@ -147163,9 +147973,119 @@ data: ${JSON.stringify(msg.data)}
|
|
|
147163
147973
|
parityRan: (opts.parity?.runs ?? 0) > 0,
|
|
147164
147974
|
parityMissingInShadowBucket: bucket(opts.parity?.missingInShadow ?? 0, BACKLOG_BUCKETS),
|
|
147165
147975
|
parityExtraInShadowBucket: bucket(opts.parity?.extraInShadow ?? 0, BACKLOG_BUCKETS),
|
|
147166
|
-
parityFieldMismatchBucket: bucket(opts.parity?.fieldMismatch ?? 0, BACKLOG_BUCKETS)
|
|
147976
|
+
parityFieldMismatchBucket: bucket(opts.parity?.fieldMismatch ?? 0, BACKLOG_BUCKETS),
|
|
147977
|
+
...localDiagnostics
|
|
147167
147978
|
};
|
|
147168
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
|
+
}
|
|
148086
|
+
};
|
|
148087
|
+
}
|
|
148088
|
+
init_mesh_read_readiness();
|
|
147169
148089
|
init_mesh_dual_write();
|
|
147170
148090
|
init_mesh_parity();
|
|
147171
148091
|
init_mesh_config();
|
|
@@ -147536,6 +148456,7 @@ ${upgradeFailureNotice.notice}${supersededHint}`);
|
|
|
147536
148456
|
);
|
|
147537
148457
|
commandHandler.setAgentStreamManager(agentStreamManager);
|
|
147538
148458
|
let seqscribeNodeRef;
|
|
148459
|
+
let seqscribeCollector;
|
|
147539
148460
|
const router = new DaemonCommandRouter({
|
|
147540
148461
|
commandHandler,
|
|
147541
148462
|
cliManager,
|
|
@@ -147568,8 +148489,18 @@ ${upgradeFailureNotice.notice}${supersededHint}`);
|
|
|
147568
148489
|
try {
|
|
147569
148490
|
const dual = meshDualWriteCounters();
|
|
147570
148491
|
const parity = meshParityCounters();
|
|
147571
|
-
|
|
148492
|
+
const snapshot = seqscribeCollector?.snapshot() ?? null;
|
|
148493
|
+
if (!snapshot) return null;
|
|
148494
|
+
return summarizeSeqscribeStats(snapshot.stats, {
|
|
147572
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,
|
|
147573
148504
|
dualWrite: {
|
|
147574
148505
|
active: isMeshDualWriteActive(),
|
|
147575
148506
|
failed: dual.failed,
|
|
@@ -147623,6 +148554,22 @@ ${upgradeFailureNotice.notice}${supersededHint}`);
|
|
|
147623
148554
|
};
|
|
147624
148555
|
components.seqscribeNode = tryOpenDaemonSeqscribeNode({ daemonId: config2.statusInstanceId });
|
|
147625
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
|
+
}
|
|
147626
148573
|
if (components.seqscribeNode) {
|
|
147627
148574
|
try {
|
|
147628
148575
|
components.seqscribeProbe = startConvergenceProbe(components.seqscribeNode, {
|
|
@@ -147639,7 +148586,9 @@ ${upgradeFailureNotice.notice}${supersededHint}`);
|
|
|
147639
148586
|
try {
|
|
147640
148587
|
configureMeshDualWrite(components.seqscribeNode ?? null);
|
|
147641
148588
|
configureMeshReadModel(components.seqscribeNode ?? null);
|
|
148589
|
+
configureFleetStatusShadow(components.seqscribeNode ?? null);
|
|
147642
148590
|
if (components.seqscribeNode) {
|
|
148591
|
+
pruneStaleConsumersAtBoot();
|
|
147643
148592
|
components.seqscribeParityLoop = startMeshParityLoop(components.seqscribeNode);
|
|
147644
148593
|
}
|
|
147645
148594
|
} catch (error48) {
|
|
@@ -147700,7 +148649,8 @@ ${upgradeFailureNotice.notice}${supersededHint}`);
|
|
|
147700
148649
|
eventLoopMonitor,
|
|
147701
148650
|
seqscribeNode,
|
|
147702
148651
|
seqscribeProbe,
|
|
147703
|
-
seqscribeParityLoop
|
|
148652
|
+
seqscribeParityLoop,
|
|
148653
|
+
seqscribeCollector
|
|
147704
148654
|
} = components;
|
|
147705
148655
|
poller.stop();
|
|
147706
148656
|
cdpInitializer.stop();
|
|
@@ -147728,6 +148678,14 @@ ${upgradeFailureNotice.notice}${supersededHint}`);
|
|
|
147728
148678
|
seqscribeProbe?.stop();
|
|
147729
148679
|
} catch {
|
|
147730
148680
|
}
|
|
148681
|
+
try {
|
|
148682
|
+
seqscribeCollector?.stop();
|
|
148683
|
+
} catch {
|
|
148684
|
+
}
|
|
148685
|
+
try {
|
|
148686
|
+
configureMeshReadReadinessCollector(null);
|
|
148687
|
+
} catch {
|
|
148688
|
+
}
|
|
147731
148689
|
try {
|
|
147732
148690
|
seqscribeParityLoop?.stop();
|
|
147733
148691
|
} catch {
|
|
@@ -147736,6 +148694,10 @@ ${upgradeFailureNotice.notice}${supersededHint}`);
|
|
|
147736
148694
|
configureMeshDualWrite(null);
|
|
147737
148695
|
} catch {
|
|
147738
148696
|
}
|
|
148697
|
+
try {
|
|
148698
|
+
configureFleetStatusShadow(null);
|
|
148699
|
+
} catch {
|
|
148700
|
+
}
|
|
147739
148701
|
try {
|
|
147740
148702
|
configureMeshReadModel(null);
|
|
147741
148703
|
} catch {
|