@adhdev/daemon-standalone 1.0.58-rc.25 → 1.0.58-rc.27

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 CHANGED
@@ -31672,9 +31672,9 @@ var require_streamx = __commonJS({
31672
31672
  }
31673
31673
  });
31674
31674
 
31675
- // ../daemon-core/node_modules/b4a/index.js
31675
+ // ../../node_modules/tar-stream/node_modules/b4a/index.js
31676
31676
  var require_b4a2 = __commonJS({
31677
- "../daemon-core/node_modules/b4a/index.js"(exports2, module2) {
31677
+ "../../node_modules/tar-stream/node_modules/b4a/index.js"(exports2, module2) {
31678
31678
  "use strict";
31679
31679
  function isBuffer(value) {
31680
31680
  return Buffer.isBuffer(value) || value instanceof Uint8Array;
@@ -31830,9 +31830,9 @@ var require_b4a2 = __commonJS({
31830
31830
  }
31831
31831
  });
31832
31832
 
31833
- // ../daemon-core/node_modules/tar-stream/headers.js
31833
+ // ../../node_modules/tar-stream/headers.js
31834
31834
  var require_headers = __commonJS({
31835
- "../daemon-core/node_modules/tar-stream/headers.js"(exports2) {
31835
+ "../../node_modules/tar-stream/headers.js"(exports2) {
31836
31836
  "use strict";
31837
31837
  var b4a = require_b4a2();
31838
31838
  var ZEROS = "0000000000000000000";
@@ -32093,9 +32093,9 @@ var require_headers = __commonJS({
32093
32093
  }
32094
32094
  });
32095
32095
 
32096
- // ../daemon-core/node_modules/tar-stream/extract.js
32096
+ // ../../node_modules/tar-stream/extract.js
32097
32097
  var require_extract = __commonJS({
32098
- "../daemon-core/node_modules/tar-stream/extract.js"(exports2, module2) {
32098
+ "../../node_modules/tar-stream/extract.js"(exports2, module2) {
32099
32099
  "use strict";
32100
32100
  var { Writable, Readable, getStreamError } = require_streamx();
32101
32101
  var FIFO = require_fast_fifo();
@@ -32438,9 +32438,9 @@ var require_extract = __commonJS({
32438
32438
  }
32439
32439
  });
32440
32440
 
32441
- // ../daemon-core/node_modules/tar-stream/constants.js
32441
+ // ../../node_modules/tar-stream/constants.js
32442
32442
  var require_constants = __commonJS({
32443
- "../daemon-core/node_modules/tar-stream/constants.js"(exports2, module2) {
32443
+ "../../node_modules/tar-stream/constants.js"(exports2, module2) {
32444
32444
  "use strict";
32445
32445
  var constants = {
32446
32446
  // just for envs without fs
@@ -32459,9 +32459,9 @@ var require_constants = __commonJS({
32459
32459
  }
32460
32460
  });
32461
32461
 
32462
- // ../daemon-core/node_modules/tar-stream/pack.js
32462
+ // ../../node_modules/tar-stream/pack.js
32463
32463
  var require_pack = __commonJS({
32464
- "../daemon-core/node_modules/tar-stream/pack.js"(exports2, module2) {
32464
+ "../../node_modules/tar-stream/pack.js"(exports2, module2) {
32465
32465
  "use strict";
32466
32466
  var { Readable, Writable, getStreamError } = require_streamx();
32467
32467
  var b4a = require_b4a2();
@@ -32694,9 +32694,9 @@ var require_pack = __commonJS({
32694
32694
  }
32695
32695
  });
32696
32696
 
32697
- // ../daemon-core/node_modules/tar-stream/index.js
32697
+ // ../../node_modules/tar-stream/index.js
32698
32698
  var require_tar_stream = __commonJS({
32699
- "../daemon-core/node_modules/tar-stream/index.js"(exports2) {
32699
+ "../../node_modules/tar-stream/index.js"(exports2) {
32700
32700
  "use strict";
32701
32701
  exports2.extract = require_extract();
32702
32702
  exports2.pack = require_pack();
@@ -32939,9 +32939,9 @@ var require_pump = __commonJS({
32939
32939
  }
32940
32940
  });
32941
32941
 
32942
- // ../daemon-core/node_modules/tar-fs/index.js
32942
+ // ../../node_modules/tar-fs/index.js
32943
32943
  var require_tar_fs = __commonJS({
32944
- "../daemon-core/node_modules/tar-fs/index.js"(exports2) {
32944
+ "../../node_modules/tar-fs/index.js"(exports2) {
32945
32945
  "use strict";
32946
32946
  var tar = require_tar_stream();
32947
32947
  var pump = require_pump();
@@ -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 ? "efe780ecd60caa19f48dde6a1a48208aec20be14" : void 0) ?? "unknown";
36889
- const commitShort = readInjected(true ? "efe780ec" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
36890
- const version2 = readInjected(true ? "1.0.58-rc.25" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
36891
- const builtAt = readInjected(true ? "2026-08-27T05:14:03.988Z" : void 0);
36888
+ const commit = readInjected(true ? "6db781afb0c67986e7f3c0a1fab11fb6c464bfad" : void 0) ?? "unknown";
36889
+ const commitShort = readInjected(true ? "6db781af" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
36890
+ const version2 = readInjected(true ? "1.0.58-rc.27" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
36891
+ const builtAt = readInjected(true ? "2026-08-27T08:09:59.178Z" : void 0);
36892
36892
  cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
36893
36893
  return cached2;
36894
36894
  }
@@ -57870,17 +57870,23 @@ CREATE TABLE IF NOT EXISTS sq_archive (
57870
57870
  }
57871
57871
  }
57872
57872
  function recordMeshEventShadow(meshId, entry) {
57873
+ recordMeshEvent(meshId, entry, "inline");
57874
+ }
57875
+ function backfillMeshEventShadow(meshId, entry) {
57876
+ return recordMeshEvent(meshId, entry, "backfill");
57877
+ }
57878
+ function recordMeshEvent(meshId, entry, origin) {
57873
57879
  try {
57874
57880
  const node = activeNode2;
57875
- if (!node || activeMode === "off") return;
57881
+ if (!node || activeMode === "off") return false;
57876
57882
  const topic = ensureTopic(node, meshId);
57877
- if (!topic) return;
57883
+ if (!topic) return false;
57878
57884
  if (inflight >= MAX_INFLIGHT) {
57879
57885
  counters.dropped++;
57880
57886
  warnOnce2(
57881
57887
  `mesh dual-write shedding load \u2014 ${MAX_INFLIGHT} appends in flight; records are being dropped from the SHADOW leg only (the ledger is unaffected)`
57882
57888
  );
57883
- return;
57889
+ return false;
57884
57890
  }
57885
57891
  const projected = projectMeshLedgerEntry(entry);
57886
57892
  const estimated = estimateProjectedEntryBytes(topic, projected);
@@ -57890,27 +57896,32 @@ CREATE TABLE IF NOT EXISTS sq_archive (
57890
57896
  warnOnce2(
57891
57897
  `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.`
57892
57898
  );
57893
- return;
57899
+ return false;
57894
57900
  }
57895
57901
  inflight++;
57896
57902
  void node.node.log(topic).append(MESH_EVENT_ENTRY_KIND, toJsonValue(projected)).then(
57897
57903
  () => {
57898
57904
  inflight--;
57899
- counters.written++;
57905
+ if (origin === "backfill") counters.backfilled++;
57906
+ else counters.written++;
57900
57907
  },
57901
57908
  (error48) => {
57902
57909
  inflight--;
57903
- counters.failed++;
57910
+ if (origin === "backfill") counters.backfillFailed++;
57911
+ else counters.failed++;
57904
57912
  warnOnce2(
57905
57913
  `mesh dual-write append failed (further failures logged once): ${error48 instanceof Error ? error48.message : String(error48)}`
57906
57914
  );
57907
57915
  }
57908
57916
  );
57917
+ return true;
57909
57918
  } catch (error48) {
57910
- counters.failed++;
57919
+ if (origin === "backfill") counters.backfillFailed++;
57920
+ else counters.failed++;
57911
57921
  warnOnce2(
57912
57922
  `mesh dual-write threw synchronously (further throws logged once): ${error48 instanceof Error ? error48.message : String(error48)}`
57913
57923
  );
57924
+ return false;
57914
57925
  }
57915
57926
  }
57916
57927
  function meshDualWriteCounters() {
@@ -57938,6 +57949,8 @@ CREATE TABLE IF NOT EXISTS sq_archive (
57938
57949
  counters.failed = 0;
57939
57950
  counters.dropped = 0;
57940
57951
  counters.topicErrors = 0;
57952
+ counters.backfilled = 0;
57953
+ counters.backfillFailed = 0;
57941
57954
  counters.oversized = 0;
57942
57955
  }
57943
57956
  var MESH_DUAL_WRITE_ENV;
@@ -57962,6 +57975,8 @@ CREATE TABLE IF NOT EXISTS sq_archive (
57962
57975
  failed: 0,
57963
57976
  dropped: 0,
57964
57977
  topicErrors: 0,
57978
+ backfilled: 0,
57979
+ backfillFailed: 0,
57965
57980
  oversized: 0
57966
57981
  };
57967
57982
  definedTopics = /* @__PURE__ */ new Map();
@@ -58048,9 +58063,12 @@ CREATE TABLE IF NOT EXISTS sq_archive (
58048
58063
  return result;
58049
58064
  }
58050
58065
  const seen = /* @__PURE__ */ new Set();
58066
+ let oldestComparedMs = Infinity;
58051
58067
  for (const entry of ledgerEntries) {
58052
58068
  result.compared++;
58053
58069
  seen.add(entry.id);
58070
+ const entryMs = new Date(entry.timestamp).getTime();
58071
+ if (Number.isFinite(entryMs) && entryMs < oldestComparedMs) oldestComparedMs = entryMs;
58054
58072
  const actual = shadow.get(entry.id);
58055
58073
  if (!actual) {
58056
58074
  result.mismatches.push({
@@ -58072,6 +58090,8 @@ CREATE TABLE IF NOT EXISTS sq_archive (
58072
58090
  }
58073
58091
  for (const [id, record2] of shadow) {
58074
58092
  if (seen.has(id)) continue;
58093
+ const recordMs = new Date(record2.timestamp).getTime();
58094
+ if (Number.isFinite(recordMs) && recordMs < oldestComparedMs) continue;
58075
58095
  result.mismatches.push({
58076
58096
  kind: "extra_in_shadow",
58077
58097
  id,
@@ -96437,6 +96457,8 @@ ${e?.stderr || ""}`;
96437
96457
  OPERATING_NOTE_KIND: () => OPERATING_NOTE_KIND,
96438
96458
  OPERATING_NOTE_TOMBSTONE_KIND: () => OPERATING_NOTE_TOMBSTONE_KIND,
96439
96459
  P2pRelayFailureError: () => P2pRelayFailureError,
96460
+ PARITY_BACKFILL_CAP: () => PARITY_BACKFILL_CAP,
96461
+ PARITY_BACKFILL_FAILURE_LIMIT: () => PARITY_BACKFILL_FAILURE_LIMIT,
96440
96462
  PARITY_CONSUMER: () => PARITY_CONSUMER,
96441
96463
  PARITY_INTERVAL_MS: () => PARITY_INTERVAL_MS,
96442
96464
  PARITY_TAIL: () => PARITY_TAIL,
@@ -96497,6 +96519,7 @@ ${e?.stderr || ""}`;
96497
96519
  appendRemoteLedgerEntries: () => appendRemoteLedgerEntries,
96498
96520
  assertNoDependencyCycle: () => assertNoDependencyCycle,
96499
96521
  assistantJournalPolicy: () => assistantJournalPolicy,
96522
+ backfillMeshEventShadow: () => backfillMeshEventShadow,
96500
96523
  baseTopicDefinitions: () => baseTopicDefinitions,
96501
96524
  buildAssistantChatMessage: () => buildAssistantChatMessage,
96502
96525
  buildAvailableProviders: () => buildAvailableProviders2,
@@ -97143,18 +97166,21 @@ ${e?.stderr || ""}`;
97143
97166
  const answers = {};
97144
97167
  const entries = record2.answers;
97145
97168
  entries.forEach((entryRaw, index) => {
97146
- if (!entryRaw || typeof entryRaw !== "object" || Array.isArray(entryRaw)) return;
97147
- const entry = entryRaw;
97169
+ const entry = entryRaw && typeof entryRaw === "object" && !Array.isArray(entryRaw) ? entryRaw : { select: entryRaw };
97148
97170
  const questionId = readString(entry.questionId);
97149
97171
  const question = (questionId ? prompt.questions.find((q) => q.questionId === questionId) : void 0) ?? prompt.questions[index];
97150
97172
  if (!question) throw new Error(`No matching question for answer entry ${index}`);
97151
97173
  const freeformText = readString(entry.freeform) ?? readString(entry.freeformText);
97174
+ const select = entry.select ?? entry.answer ?? entry.selected;
97152
97175
  const selectedLabels = [];
97153
- const select = entry.select;
97154
97176
  if (Array.isArray(select)) {
97155
97177
  for (const sel of select) selectedLabels.push(resolveOneLabel(question, sel));
97156
97178
  } else if (select !== void 0 && select !== null) {
97157
97179
  selectedLabels.push(resolveOneLabel(question, select));
97180
+ } else if (!freeformText) {
97181
+ throw new Error(
97182
+ `Answer entry ${index} for ${question.questionId} has no recognized selection: expected "select" (option label, 1-based index, or array of either) or "freeform" (text).`
97183
+ );
97158
97184
  }
97159
97185
  answers[question.questionId] = {
97160
97186
  selectedLabels,
@@ -138685,7 +138711,16 @@ ${ptyResult.output.slice(-2e3)}`);
138685
138711
  queueBucket: count(seqscribe.queueBucket),
138686
138712
  fgenAgeBucket: count(seqscribe.fgenAgeBucket),
138687
138713
  quarantined: seqscribe.quarantined === true,
138688
- authority: seqscribe.authority === true
138714
+ authority: seqscribe.authority === true,
138715
+ dualWrite: seqscribe.dualWrite === true,
138716
+ dualWriteFailedBucket: count(seqscribe.dualWriteFailedBucket),
138717
+ dualWriteDroppedBucket: count(seqscribe.dualWriteDroppedBucket),
138718
+ dualWriteBackfilledBucket: count(seqscribe.dualWriteBackfilledBucket),
138719
+ parityMismatchBucket: count(seqscribe.parityMismatchBucket),
138720
+ parityRan: seqscribe.parityRan === true,
138721
+ parityMissingInShadowBucket: count(seqscribe.parityMissingInShadowBucket),
138722
+ parityExtraInShadowBucket: count(seqscribe.parityExtraInShadowBucket),
138723
+ parityFieldMismatchBucket: count(seqscribe.parityFieldMismatchBucket)
138689
138724
  };
138690
138725
  }
138691
138726
  function buildCloudStatusReportPayload(sessions, p2p, timestamp2, seqscribe) {
@@ -147123,8 +147158,12 @@ data: ${JSON.stringify(msg.data)}
147123
147158
  dualWrite: opts.dualWrite?.active ?? false,
147124
147159
  dualWriteFailedBucket: bucket(opts.dualWrite?.failed ?? 0, BACKLOG_BUCKETS),
147125
147160
  dualWriteDroppedBucket: bucket(opts.dualWrite?.dropped ?? 0, BACKLOG_BUCKETS),
147161
+ dualWriteBackfilledBucket: bucket(opts.dualWrite?.backfilled ?? 0, BACKLOG_BUCKETS),
147126
147162
  parityMismatchBucket: bucket(opts.parity?.mismatches ?? 0, BACKLOG_BUCKETS),
147127
- parityRan: (opts.parity?.runs ?? 0) > 0
147163
+ parityRan: (opts.parity?.runs ?? 0) > 0,
147164
+ parityMissingInShadowBucket: bucket(opts.parity?.missingInShadow ?? 0, BACKLOG_BUCKETS),
147165
+ parityExtraInShadowBucket: bucket(opts.parity?.extraInShadow ?? 0, BACKLOG_BUCKETS),
147166
+ parityFieldMismatchBucket: bucket(opts.parity?.fieldMismatch ?? 0, BACKLOG_BUCKETS)
147128
147167
  };
147129
147168
  }
147130
147169
  init_mesh_dual_write();
@@ -147136,13 +147175,57 @@ data: ${JSON.stringify(msg.data)}
147136
147175
  init_mesh_ledger();
147137
147176
  var PARITY_INTERVAL_MS = 15 * 60 * 1e3;
147138
147177
  var PARITY_TAIL = 500;
147178
+ var PARITY_BACKFILL_CAP = 100;
147179
+ var PARITY_BACKFILL_FAILURE_LIMIT = 2;
147139
147180
  function startMeshParityLoop(handle, opts = {}) {
147140
147181
  if (!isMeshDualWriteActive()) {
147141
147182
  LOG2.info("Seqscribe", "parity loop idle \u2014 mesh dual-write shadow is not active");
147142
147183
  return null;
147143
147184
  }
147144
147185
  const armedAt = opts.armedAt ?? Date.now();
147186
+ const backfillEnabled = opts.backfill !== false;
147187
+ const backfillCap = opts.backfillCap ?? PARITY_BACKFILL_CAP;
147145
147188
  let stopped = false;
147189
+ const backfillFailures = /* @__PURE__ */ new Map();
147190
+ const backfillMissing = (meshId, entries, result) => {
147191
+ if (!backfillEnabled) return;
147192
+ const missing = result.mismatches.filter((m) => m.kind === "missing_in_shadow");
147193
+ if (missing.length === 0) {
147194
+ backfillFailures.delete(meshId);
147195
+ return;
147196
+ }
147197
+ if ((backfillFailures.get(meshId) ?? 0) >= PARITY_BACKFILL_FAILURE_LIMIT) {
147198
+ LOG2.warn(
147199
+ "Seqscribe",
147200
+ `parity backfill paused mesh=${meshId} \u2014 ${PARITY_BACKFILL_FAILURE_LIMIT} consecutive failed sweeps; ${missing.length} entries remain unmirrored and parity keeps reporting them`
147201
+ );
147202
+ return;
147203
+ }
147204
+ const byId = new Map(entries.map((e) => [e.id, e]));
147205
+ let mirrored = 0;
147206
+ let failed = 0;
147207
+ let skipped = 0;
147208
+ for (const mismatch of missing) {
147209
+ if (stopped) break;
147210
+ if (mirrored + failed >= backfillCap) {
147211
+ skipped = missing.length - (mirrored + failed);
147212
+ break;
147213
+ }
147214
+ const entry = byId.get(mismatch.id);
147215
+ if (!entry) {
147216
+ skipped++;
147217
+ continue;
147218
+ }
147219
+ if (backfillMeshEventShadow(meshId, entry)) mirrored++;
147220
+ else failed++;
147221
+ }
147222
+ if (mirrored > 0) backfillFailures.delete(meshId);
147223
+ else if (failed > 0) backfillFailures.set(meshId, (backfillFailures.get(meshId) ?? 0) + 1);
147224
+ LOG2.info(
147225
+ "Seqscribe",
147226
+ `parity backfill mesh=${meshId} mirrored=${mirrored} failed=${failed}` + (skipped > 0 ? ` deferred=${skipped} (cap=${backfillCap}, next sweep)` : "") + " \u2014 these entries were appended by a process with no armed shadow leg (see mesh-dual-write.ts process-boundary note)"
147227
+ );
147228
+ };
147146
147229
  const runOnce = async () => {
147147
147230
  if (stopped) return;
147148
147231
  let meshIds;
@@ -147165,7 +147248,15 @@ data: ${JSON.stringify(msg.data)}
147165
147248
  return Number.isFinite(at) && at >= armedAt;
147166
147249
  });
147167
147250
  if (entries.length === 0) continue;
147168
- await runMeshParityCheck(handle, meshId, entries);
147251
+ const result = await runMeshParityCheck(handle, meshId, entries);
147252
+ try {
147253
+ backfillMissing(meshId, entries, result);
147254
+ } catch (error48) {
147255
+ LOG2.warn(
147256
+ "Seqscribe",
147257
+ `parity backfill failed mesh=${meshId}: ${error48 instanceof Error ? error48.message : String(error48)}`
147258
+ );
147259
+ }
147169
147260
  } catch (error48) {
147170
147261
  LOG2.warn(
147171
147262
  "Seqscribe",
@@ -147482,9 +147573,16 @@ ${upgradeFailureNotice.notice}${supersededHint}`);
147482
147573
  dualWrite: {
147483
147574
  active: isMeshDualWriteActive(),
147484
147575
  failed: dual.failed,
147485
- dropped: dual.dropped
147576
+ dropped: dual.dropped,
147577
+ backfilled: dual.backfilled
147486
147578
  },
147487
- parity: { runs: parity.runs, mismatches: parity.mismatches }
147579
+ parity: {
147580
+ runs: parity.runs,
147581
+ mismatches: parity.mismatches,
147582
+ missingInShadow: parity.missingInShadow,
147583
+ extraInShadow: parity.extraInShadow,
147584
+ fieldMismatch: parity.fieldMismatch
147585
+ }
147488
147586
  });
147489
147587
  } catch (error48) {
147490
147588
  LOG2.warn(