shinjuku-shielded 0.3.71 → 0.3.73

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/manifest.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "schema": "carbon-shielded-wallet/bundle-manifest/v1",
3
3
  "file": "shinjuku-wallet.mjs",
4
- "sha256": "61674c4e8c6309ae6c93338211bf57a674837f572e498215300031a65b9aa743",
5
- "bytes": 12200396,
6
- "sourceCommit": "ec62139d8d55db9f55e17c488d052b6c8248acda",
4
+ "sha256": "ff6f25bccfd2a50929a8dc82137b4fb42172790f9d71a6c07f166bda3e052d22",
5
+ "bytes": 12210958,
6
+ "sourceCommit": "0e33e750c294c38e85c041b105e87cf864edd5db",
7
7
  "sourceDirty": false,
8
8
  "installRecordMatchesLockfile": true,
9
9
  "releaseRule": "valid only when two fresh npm ci --ignore-scripts builds on different OSes give the same sha256; installRecordMatchesLockfile true means every entry npm installed equals its package-lock.json entry and every entry not marked optional, devOptional included, is installed: an optional entry (a package for another platform) may be absent",
@@ -1282,5 +1282,5 @@
1282
1282
  "version": "1.8.0"
1283
1283
  }
1284
1284
  ],
1285
- "publishedAt": "2026-10-22T16:40:39.055Z"
1285
+ "publishedAt": "2026-10-22T18:10:20.059Z"
1286
1286
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "shinjuku-shielded",
3
- "version": "0.3.71",
3
+ "version": "0.3.73",
4
4
  "mcpName": "io.github.ShinjukuStaition/shinjuku-mcp",
5
5
  "description": "Shinjuku Shielded, the private x402 facilitator on Solana: the self-custody wallet CLI and its MCP server. Shield, pay, and unshield USDC from any MCP agent, under caps you set.",
6
- "shinjukuRelease": "61674c4e",
7
- "shinjukuSha256": "61674c4e8c6309ae6c93338211bf57a674837f572e498215300031a65b9aa743",
6
+ "shinjukuRelease": "ff6f25bc",
7
+ "shinjukuSha256": "ff6f25bccfd2a50929a8dc82137b4fb42172790f9d71a6c07f166bda3e052d22",
8
8
  "license": "SEE LICENSE IN LICENSE.txt",
9
9
  "author": "Shinjuku Shielded",
10
10
  "homepage": "https://github.com/ShinjukuStaition/shinjuku-mcp#readme",
@@ -57150,6 +57150,16 @@ function rewriteFoldRoots(pool2, cache, next) {
57150
57150
  })().catch(() => {
57151
57151
  });
57152
57152
  }
57153
+ function dropCompactCacheRecords(pool2, cache) {
57154
+ if (cache === void 0 || cache === null) return Promise.resolve();
57155
+ return (async () => {
57156
+ const current = await cache.load();
57157
+ if (!current || current.pool !== pool2) return;
57158
+ const { foldRoots, savedAt, served, ...rest } = current;
57159
+ await cache.save({ ...rest, served: servedWithoutRecords(served) }, { savedAt });
57160
+ })().catch(() => {
57161
+ });
57162
+ }
57153
57163
  function markFoldRootsVerified(pool2, cache) {
57154
57164
  rewriteFoldRoots(pool2, cache, (foldRoots) => {
57155
57165
  const hashed = lastFolds.get(pool2);
@@ -57224,12 +57234,12 @@ function canonicalAddress(value, label) {
57224
57234
  }
57225
57235
  throw refuse3("p03_compact_history_record_invalid");
57226
57236
  }
57227
- function validateImport(raw, from) {
57237
+ function validateImport(raw, from, size = P03_COMPACT_PAGE) {
57228
57238
  const invalid5 = () => refuse3("p03_compact_history_source_answer_invalid");
57229
57239
  if (raw === null || typeof raw !== "object" || Array.isArray(raw) || Object.keys(raw).sort().join(",") !== IMPORT_KEYS.join(",")) throw invalid5();
57230
57240
  const { afterOrdinal, record, values, signature: signature2, slot: slot3, transactionIndex, instructionIndex } = raw;
57231
57241
  if (!isIndex(afterOrdinal) || !isSignature(signature2) || !isIndex(slot3) || !isIndex(transactionIndex) || !isIndex(instructionIndex)) throw invalid5();
57232
- if (from !== void 0 && !(afterOrdinal > from && afterOrdinal <= from + P03_COMPACT_PAGE || from === 0 && afterOrdinal === 0)) {
57242
+ if (from !== void 0 && !(afterOrdinal > from && afterOrdinal <= from + size || from === 0 && afterOrdinal === 0)) {
57233
57243
  throw invalid5();
57234
57244
  }
57235
57245
  if (!Array.isArray(values) || values.length > IMPORT_MAX_VALUES) throw invalid5();
@@ -57365,18 +57375,18 @@ function validateRecord(raw, ordinal, { programId, pool: pool2, poolDomain, snap
57365
57375
  })
57366
57376
  });
57367
57377
  }
57368
- function requestPage(history, pool2, from) {
57369
- return from === 0 ? requestPageZero(history, pool2) : requestPageNow(history, pool2, from);
57378
+ function requestPage(history, pool2, from, signal) {
57379
+ return from === 0 ? requestPageZero(history, pool2, signal) : requestPageNow(history, pool2, from);
57370
57380
  }
57371
- function requestPageZero(history, pool2) {
57381
+ function requestPageZero(history, pool2, signal) {
57372
57382
  const source = typeof history?.rpcEndpoint === "string" ? history.rpcEndpoint : history;
57373
57383
  let byPool = pageZeroInFlight.get(source);
57374
57384
  const joined = byPool?.get(pool2);
57375
57385
  if (joined !== void 0) {
57376
57386
  markPhase("compact-page0-joined");
57377
- return joined.then((answer) => answer.error === void 0 ? answer : requestPageNow(history, pool2, 0));
57387
+ return joined.then((answer) => answer.error === void 0 ? answer : signal?.aborted ? answer : requestPageNow(history, pool2, 0, signal));
57378
57388
  }
57379
- const pending = requestPageNow(history, pool2, 0);
57389
+ const pending = requestPageNow(history, pool2, 0, signal);
57380
57390
  if (byPool === void 0) pageZeroInFlight.set(source, byPool = /* @__PURE__ */ new Map());
57381
57391
  byPool.set(pool2, pending);
57382
57392
  pending.then(() => {
@@ -57385,16 +57395,14 @@ function requestPageZero(history, pool2) {
57385
57395
  });
57386
57396
  return pending;
57387
57397
  }
57388
- function requestPageNow(history, pool2, from) {
57398
+ function requestPageNow(history, pool2, from, signal) {
57399
+ const params = [pool2, { commitment: "finalized", fromOrdinal: from, toOrdinal: from + P03_COMPACT_PAGE }];
57400
+ const read = signal !== void 0 && typeof history.abortableRpcRequest === "function" ? () => history.abortableRpcRequest("getP03Transitions", params, signal, void 0, { rejectHttpError: true }) : () => history._rpcRequest("getP03Transitions", params);
57389
57401
  const attempt = async (index) => {
57390
57402
  try {
57391
- return { response: await history._rpcRequest("getP03Transitions", [pool2, {
57392
- commitment: "finalized",
57393
- fromOrdinal: from,
57394
- toOrdinal: from + P03_COMPACT_PAGE
57395
- }]) };
57403
+ return { response: await read() };
57396
57404
  } catch (error) {
57397
- if (index + 1 >= LIST_ATTEMPTS || proxyRefusedConnection(error)) return { error };
57405
+ if (index + 1 >= LIST_ATTEMPTS || proxyRefusedConnection(error) || signal?.aborted) return { error };
57398
57406
  markPhase("compact-list-retry");
57399
57407
  await new Promise((resolve38) => setTimeout(resolve38, Math.min(8e3, 1e3 * 2 ** index)));
57400
57408
  return attempt(index + 1);
@@ -57502,17 +57510,79 @@ function startCompactPoolSnapshot({ connection, programId, pool: pool2 }) {
57502
57510
  });
57503
57511
  return { sliced, full };
57504
57512
  }
57505
- function requestCompactFirstPage({ history, pool: pool2 }) {
57513
+ function requestCompactFirstPage({ history, pool: pool2, signal }) {
57506
57514
  try {
57507
57515
  const source = typeof history === "string" ? connect2(history, "finalized", { timeoutMs: HISTORY_RPC_REQUEST_TIMEOUT_MS }) : history;
57508
57516
  if (!source || typeof source._rpcRequest !== "function") return Promise.resolve({ error: refuse3("p03_compact_history_connection_invalid") });
57509
- return requestPage(source, new import_web397.PublicKey(pool2).toBase58(), 0);
57517
+ return requestPage(source, new import_web397.PublicKey(pool2).toBase58(), 0, signal);
57510
57518
  } catch (error) {
57511
57519
  return Promise.resolve({ error });
57512
57520
  }
57513
57521
  }
57514
- function pageShapeValid(result, pool2, from) {
57515
- return Boolean(result) && typeof result === "object" && result.pool === pool2 && result.fromOrdinal === from && isIndex(result.total) && isIndex(result.syncedSlot) && Array.isArray(result.records) && result.records.length === Math.max(0, Math.min(result.total, from + P03_COMPACT_PAGE) - from) && Boolean(result.initialization) && isSignature(result.initialization.signature) && isIndex(result.initialization.slot);
57522
+ function pageShapeValid(result, pool2, from, size = P03_COMPACT_PAGE) {
57523
+ return Boolean(result) && typeof result === "object" && result.pool === pool2 && result.fromOrdinal === from && isIndex(result.total) && isIndex(result.syncedSlot) && Array.isArray(result.records) && result.records.length === Math.max(0, Math.min(result.total, from + size) - from) && Boolean(result.initialization) && isSignature(result.initialization.signature) && isIndex(result.initialization.slot);
57524
+ }
57525
+ function requestTailPage(history, pool2, from, grid) {
57526
+ return Promise.resolve().then(() => history._rpcRequest("getP03Transitions", [pool2, { commitment: "finalized", fromOrdinal: from, toOrdinal: from + grid }])).then((response) => ({ response }), (error) => ({ error }));
57527
+ }
57528
+ function requestCompactTailPage({ history, pool: pool2, currentIndex }) {
57529
+ try {
57530
+ const count2 = Number(BigInt(currentIndex) / SUBTREE_LEAVES3);
57531
+ if (!Number.isSafeInteger(count2) || count2 === 0) return Promise.resolve({ error: new Error("no records") });
57532
+ const source = typeof history === "string" ? connect2(history, "finalized", { timeoutMs: HISTORY_RPC_REQUEST_TIMEOUT_MS }) : history;
57533
+ if (!source || typeof source._rpcRequest !== "function") return Promise.resolve({ error: refuse3("p03_compact_history_connection_invalid") });
57534
+ return requestTailPage(source, new import_web397.PublicKey(pool2).toBase58(), tailFrom(count2, P03_COMPACT_TAIL_GRID), P03_COMPACT_TAIL_GRID);
57535
+ } catch (error) {
57536
+ return Promise.resolve({ error });
57537
+ }
57538
+ }
57539
+ function combineCompactTail(prefix, answer, { pool: pool2, from, count: count2, grid }) {
57540
+ if (answer.error !== void 0) return { miss: "fetch-failed" };
57541
+ const { response } = answer;
57542
+ if (response === null || typeof response !== "object" || "error" in response) return { miss: "fetch-failed" };
57543
+ const result = response.result;
57544
+ if (!pageShapeValid(result, pool2, from, grid)) return { miss: "shape-invalid" };
57545
+ if (result.total < count2) return { miss: "behind" };
57546
+ if (result.initialization.signature !== prefix.initialization.signature || result.initialization.slot !== prefix.initialization.slot) {
57547
+ return { miss: "init-mismatch" };
57548
+ }
57549
+ if (isIndex(prefix.syncedSlot) && result.syncedSlot < prefix.syncedSlot) return { miss: "synced-older" };
57550
+ let tailImports = [];
57551
+ if (result.imports !== void 0) {
57552
+ if (!Array.isArray(result.imports)) return { miss: "import-invalid" };
57553
+ try {
57554
+ for (const entry of result.imports) validateImport(entry, from, grid);
57555
+ } catch {
57556
+ return { miss: "import-invalid" };
57557
+ }
57558
+ tailImports = result.imports;
57559
+ }
57560
+ const cachedImports = Array.isArray(prefix.imports) ? prefix.imports : [];
57561
+ const held = Math.min(prefix.records.length, count2);
57562
+ for (let ordinal = from; ordinal < held; ordinal += 1) {
57563
+ if (!sameJson(prefix.records[ordinal], result.records[ordinal - from])) return { miss: "overlap-mismatch" };
57564
+ }
57565
+ const between = (entry) => entry?.afterOrdinal > from && entry.afterOrdinal < held;
57566
+ if (!sameJson(cachedImports.filter(between), tailImports.filter(between))) return { miss: "overlap-mismatch" };
57567
+ return { page: {
57568
+ records: [...prefix.records.slice(0, from), ...result.records.slice(0, count2 - from)],
57569
+ imports: [...from === 0 ? [] : cachedImports.filter((entry) => entry?.afterOrdinal <= from), ...tailImports],
57570
+ initialization: result.initialization,
57571
+ syncedSlot: result.syncedSlot
57572
+ } };
57573
+ }
57574
+ function comparePageZero(first, prefix, { pool: pool2, from }) {
57575
+ return first.then((answer) => {
57576
+ const result = answer?.response?.result;
57577
+ if (answer?.error !== void 0 || !pageShapeValid(result, pool2, 0)) return "unavailable";
57578
+ const upTo = Math.min(from, result.records.length);
57579
+ for (let ordinal = 0; ordinal < upTo; ordinal += 1) {
57580
+ if (!sameJson(prefix.records[ordinal], result.records[ordinal])) return "mismatch";
57581
+ }
57582
+ const reach = result.total > upTo ? upTo : upTo - 1;
57583
+ const imports = (list) => (Array.isArray(list) ? list : []).filter((entry) => entry?.afterOrdinal <= reach);
57584
+ return sameJson(imports(prefix.imports), imports(result.imports)) ? "match" : "mismatch";
57585
+ }, () => "unavailable");
57516
57586
  }
57517
57587
  function isCompactPageZeroAnswer(response, pool2) {
57518
57588
  if (response === null || typeof response !== "object" || "error" in response) return false;
@@ -57884,7 +57954,19 @@ async function readCompactP03HistoryNow({
57884
57954
  // check: they are NOT verified yet. A payment asks the memo service for their memos here
57885
57955
  // (payAndFetch.mjs), and uses an answer only for a context the verified report names. Its
57886
57956
  // result and any throw are ignored.
57887
- onList
57957
+ onList,
57958
+ // compactP03HistoryReport: the records of a compact cache that is not warm (cached.served). When the
57959
+ // list is read (no knownSnapshot), these records (or `served`'s, when the pool outgrew them) that pass
57960
+ // the start of the pool's last grid page take that page instead of every page (3b, combineCompactTail);
57961
+ // page 0 still goes out and is read to its end.
57962
+ prefix,
57963
+ // The tail page's size; P03_COMPACT_TAIL_GRID outside tests.
57964
+ tailGrid = P03_COMPACT_TAIL_GRID,
57965
+ // false: no tail request (compactP03HistoryReport's read again after a refused tail hit; it sent its tail already).
57966
+ tail = true,
57967
+ // compactP03HistoryReport: called on a tail hit with { first (page 0's answer promise), snapshot (the pool
57968
+ // account read) }, so a refused list can be read again from that same page 0 and pool read.
57969
+ onTailHit
57888
57970
  }) {
57889
57971
  const program = new import_web397.PublicKey(programId);
57890
57972
  const poolKey = new import_web397.PublicKey(pool2);
@@ -57917,18 +57999,57 @@ async function readCompactP03HistoryNow({
57917
57999
  const count2 = Number(snapshot.currentIndex / SUBTREE_LEAVES3);
57918
58000
  if (!Number.isSafeInteger(count2)) throw refuse3("p03_compact_history_snapshot_invalid");
57919
58001
  const anchors = freezeFinalizedAnchors(snapshot);
57920
- const readServedPages = () => {
58002
+ const readServedPages = (zero = first) => {
57921
58003
  if (reusedFirst !== void 0) markPhase("compact-behind-page0-reused");
57922
58004
  if (first === void 0 && preFirst !== void 0) markPhase("compact-page0-handed-over");
57923
- return readPages(source, poolString, count2, first ?? preFirst, { wakeSlot: snapshot.slot });
58005
+ return readPages(source, poolString, count2, zero ?? preFirst, { wakeSlot: snapshot.slot });
58006
+ };
58007
+ let prefixCheck;
58008
+ const readTailOrPages = async () => {
58009
+ if (knownSnapshot !== void 0 || !tail) return readServedPages();
58010
+ const zero = first ?? preFirst ?? requestPage(source, poolString, 0);
58011
+ if (first === void 0 && preFirst === void 0) markPhase("compact-page0-sent");
58012
+ const from = tailFrom(count2, tailGrid);
58013
+ const tailRead = requestTailPage(source, poolString, from, tailGrid);
58014
+ markPhase("compact-tail-sent");
58015
+ const cachedRecords = served ?? prefix;
58016
+ if (!Array.isArray(cachedRecords?.records) || !cachedRecords.initialization) {
58017
+ markPhase("compact-tail-miss-no-cache");
58018
+ return readServedPages(zero);
58019
+ }
58020
+ if (cachedRecords.records.length <= from) {
58021
+ markPhase("compact-tail-miss-k-not-above-from");
58022
+ return readServedPages(zero);
58023
+ }
58024
+ if (await Promise.race([zero.then((answer) => answer.error === void 0), tailRead.then(() => false)])) {
58025
+ markPhase("compact-tail-miss-page0-first");
58026
+ return readServedPages(zero);
58027
+ }
58028
+ const combined = combineCompactTail(cachedRecords, await tailRead, { pool: poolString, from, count: count2, grid: tailGrid });
58029
+ if (combined.miss !== void 0) {
58030
+ markPhase(`compact-tail-miss-${combined.miss}`);
58031
+ return readServedPages(zero);
58032
+ }
58033
+ markPhase("compact-tail-hit");
58034
+ prefixCheck = comparePageZero(zero, cachedRecords, { pool: poolString, from });
58035
+ try {
58036
+ onTailHit?.({ first: zero, snapshot, check: prefixCheck });
58037
+ } catch {
58038
+ }
58039
+ return combined.page;
57924
58040
  };
57925
- const page = count2 === 0 ? { records: [], imports: [], initialization: void 0, syncedSlot: void 0 } : served !== void 0 && Array.isArray(served.records) && served.records.length >= count2 && served.initialization ? {
58041
+ const servedReaches = count2 > 0 && served !== void 0 && Array.isArray(served.records) && served.records.length >= count2 && Boolean(served.initialization);
58042
+ if (servedReaches && knownSnapshot === void 0 && tail && (first !== void 0 || preFirst !== void 0)) {
58043
+ requestTailPage(source, poolString, tailFrom(count2, tailGrid), tailGrid);
58044
+ markPhase("compact-tail-sent-unused");
58045
+ }
58046
+ const page = count2 === 0 ? { records: [], imports: [], initialization: void 0, syncedSlot: void 0 } : servedReaches ? {
57926
58047
  records: served.records.slice(0, count2),
57927
58048
  imports: Array.isArray(served.imports) ? served.imports : [],
57928
58049
  initialization: served.initialization,
57929
58050
  syncedSlot: served.syncedSlot,
57930
58051
  cached: true
57931
- } : await readServedPages().catch((error) => {
58052
+ } : await readTailOrPages().catch((error) => {
57932
58053
  if (error?.compactHistoryRefusal === "p03_compact_history_source_behind") error.behindSnapshot = snapshot;
57933
58054
  throw error;
57934
58055
  });
@@ -58087,7 +58208,9 @@ async function readCompactP03HistoryNow({
58087
58208
  ...page.imports.length > 0 ? { imports: page.imports } : {},
58088
58209
  initialization: page.initialization,
58089
58210
  syncedSlot: page.syncedSlot
58090
- })
58211
+ }),
58212
+ // 3b, a tail hit only: resolves "match", "mismatch" or "unavailable" when page 0 has come in full (comparePageZero).
58213
+ ...prefixCheck !== void 0 ? { prefixCheck } : {}
58091
58214
  });
58092
58215
  }
58093
58216
  function refusalReason(error) {
@@ -58118,7 +58241,8 @@ async function compactP03HistoryReportRun({
58118
58241
  knownFirst,
58119
58242
  poolPreRead,
58120
58243
  firstPreRead,
58121
- onList
58244
+ onList,
58245
+ tailGrid
58122
58246
  }) {
58123
58247
  if (deploymentIdentity === void 0) throw new Error("p03_history_deployment_identity_required");
58124
58248
  const program = new import_web397.PublicKey(programId);
@@ -58191,7 +58315,7 @@ async function compactP03HistoryReportRun({
58191
58315
  };
58192
58316
  const preFold = cached ? startCompactPreFold(poolKey.toBase58(), cached) : void 0;
58193
58317
  const e1Ahead = cached ? startCompactE1Candidate(program.toBase58(), poolKey.toBase58(), cached, preFold) : void 0;
58194
- const compact = await readCompactP03History({
58318
+ const readOnce = (extra) => readCompactP03History({
58195
58319
  history,
58196
58320
  own: connection,
58197
58321
  programId,
@@ -58205,8 +58329,48 @@ async function compactP03HistoryReportRun({
58205
58329
  ...firstPreRead !== void 0 ? { firstPreRead } : {},
58206
58330
  ...onList !== void 0 ? { onList } : {},
58207
58331
  ...warm ? { served: cached.served } : {},
58208
- ...cached ? { initialization: cached.initialization } : {}
58332
+ ...cached ? { initialization: cached.initialization } : {},
58333
+ ...tailGrid !== void 0 ? { tailGrid } : {},
58334
+ ...extra
58209
58335
  });
58336
+ let pageZeroMismatch = false;
58337
+ let readAgain = false;
58338
+ let replaced = false;
58339
+ let saving;
58340
+ let dropping;
58341
+ const watchPageZero = (check) => check.then((result) => {
58342
+ markPhase(`compact-page0-compare-${result}`);
58343
+ if (result !== "mismatch") return;
58344
+ try {
58345
+ process.stderr.write("history: WARNING the history source's page 0 differs from this wallet's cached records before the pool's last page; the cache's records are replaced or dropped so the next read takes every page\n");
58346
+ } catch {
58347
+ }
58348
+ pageZeroMismatch = true;
58349
+ if (replaced) return;
58350
+ if (!readAgain) lastFolds.delete(poolKey.toBase58());
58351
+ const drop = () => replaced ? void 0 : dropCompactCacheRecords(poolKey.toBase58(), cache);
58352
+ dropping = (saving ?? Promise.resolve()).then(drop, drop);
58353
+ }).catch(() => {
58354
+ });
58355
+ let tailHit;
58356
+ let compact;
58357
+ try {
58358
+ compact = await readOnce(cached ? { ...warm ? {} : { prefix: cached.served }, onTailHit: (hit) => {
58359
+ tailHit = hit;
58360
+ watchPageZero(hit.check);
58361
+ } } : {});
58362
+ } catch (error) {
58363
+ if (tailHit === void 0 || !TAIL_RETRY_REFUSALS.has(error?.compactHistoryRefusal)) throw error;
58364
+ markPhase("compact-tail-refused-page0");
58365
+ readAgain = true;
58366
+ lastFolds.delete(poolKey.toBase58());
58367
+ try {
58368
+ process.stderr.write(`history: WARNING this wallet's cached records with the pool's last page failed a check (${error.compactHistoryRefusal}); reading every page again
58369
+ `);
58370
+ } catch {
58371
+ }
58372
+ compact = await readOnce({ firstPreRead: tailHit.first, poolPreRead: Promise.resolve(tailHit.snapshot), tail: false });
58373
+ }
58210
58374
  const initialization = compact.verifiedInitialization;
58211
58375
  if (initialization === void 0) throw refuse3("p03_compact_history_pool_empty");
58212
58376
  const snapshot = compact.poolSnapshot;
@@ -58269,8 +58433,9 @@ async function compactP03HistoryReportRun({
58269
58433
  });
58270
58434
  }
58271
58435
  if (cache) {
58436
+ if (dropping !== void 0) await dropping;
58272
58437
  try {
58273
- await cache.save({
58438
+ await (saving = Promise.resolve().then(() => cache.save({
58274
58439
  programId: program.toBase58(),
58275
58440
  pool: poolKey.toBase58(),
58276
58441
  snapshot: {
@@ -58282,10 +58447,12 @@ async function compactP03HistoryReportRun({
58282
58447
  // pre-fold hashes their roots ahead. Counts only: every root is checked live again.
58283
58448
  anchorCounts: [...new Set(compact.finalizedPoolSnapshot.anchors.map((anchor) => Number(anchor.index / SUBTREE_LEAVES3)))]
58284
58449
  },
58285
- served: compact.served,
58450
+ served: pageZeroMismatch && !readAgain ? servedWithoutRecords(compact.served) : compact.served,
58286
58451
  initialization,
58287
58452
  attestation: attested.attestation
58288
- });
58453
+ })).then(() => {
58454
+ if (readAgain) replaced = true;
58455
+ }));
58289
58456
  } catch {
58290
58457
  }
58291
58458
  }
@@ -58306,7 +58473,7 @@ async function tryCompactP03HistoryReport(options) {
58306
58473
  return { ok: false, reason, ...detail ? { detail } : {}, error };
58307
58474
  }
58308
58475
  }
58309
- var import_web397, P03_COMPACT_HISTORY_SOURCE_MODEL, P03_COMPACT_PAGE, P03_COMPACT_SPOT_CHECKS, FIELD_MODULUS5, SUBTREE_LEAVES3, LOCAL_DEPTH2, OUTER_DEPTH2, PRIMARY_PROOF_BYTES2, FIELD_BYTES3, ED25519_SPKI_PREFIX2, VERSION_1_PREFIX2, HEX64, BASE58, REPLAY_STORE_INDEXED2, PROFILES2, MOVE_HEAD_BYTES2, MOVE_INSERTED_VALUES2, refuse3, hash4, bitAt, zeroRootsMemo, lastFolds, PRE_FOLD_SLICE_MS, preFolds, hex64, droppedPools, verifyQuietMs, VERIFY_SLICE_MS, VERIFY_POLL_MS, verifying, unrefTurn, isSignature, isIndex, IMPORT_KEYS, IMPORT_MAX_VALUES, LIST_ATTEMPTS, pageZeroInFlight, OWN_READ_TIMEOUT_MS, BOUNDED_OWN_METHODS, SPOT_HEDGE_AFTER_MS, SPOT_HEDGE_LANE, spotReadId, POOL_HEDGE_AFTER_MS, POOL_HEDGE_LANE, poolReadId, compactReportsRunning, compactHistoryReadsRunning;
58476
+ var import_web397, P03_COMPACT_HISTORY_SOURCE_MODEL, P03_COMPACT_PAGE, P03_COMPACT_SPOT_CHECKS, FIELD_MODULUS5, SUBTREE_LEAVES3, LOCAL_DEPTH2, OUTER_DEPTH2, PRIMARY_PROOF_BYTES2, FIELD_BYTES3, ED25519_SPKI_PREFIX2, VERSION_1_PREFIX2, HEX64, BASE58, REPLAY_STORE_INDEXED2, PROFILES2, MOVE_HEAD_BYTES2, MOVE_INSERTED_VALUES2, refuse3, hash4, bitAt, zeroRootsMemo, lastFolds, PRE_FOLD_SLICE_MS, preFolds, hex64, droppedPools, servedWithoutRecords, verifyQuietMs, VERIFY_SLICE_MS, VERIFY_POLL_MS, verifying, unrefTurn, isSignature, isIndex, IMPORT_KEYS, IMPORT_MAX_VALUES, LIST_ATTEMPTS, pageZeroInFlight, OWN_READ_TIMEOUT_MS, BOUNDED_OWN_METHODS, P03_COMPACT_TAIL_GRID, TAIL_RETRY_REFUSALS, tailFrom, sameJson, SPOT_HEDGE_AFTER_MS, SPOT_HEDGE_LANE, spotReadId, POOL_HEDGE_AFTER_MS, POOL_HEDGE_LANE, poolReadId, compactReportsRunning, compactHistoryReadsRunning;
58310
58477
  var init_compact = __esm({
58311
58478
  "wallet/src/history/compact.mjs"() {
58312
58479
  "use strict";
@@ -58423,6 +58590,11 @@ var init_compact = __esm({
58423
58590
  preFolds = /* @__PURE__ */ new Map();
58424
58591
  hex64 = (value) => value.toString(16).padStart(64, "0");
58425
58592
  droppedPools = /* @__PURE__ */ new Set();
58593
+ servedWithoutRecords = (served) => ({
58594
+ records: [],
58595
+ initialization: served.initialization,
58596
+ ...served.syncedSlot !== void 0 ? { syncedSlot: served.syncedSlot } : {}
58597
+ });
58426
58598
  verifyQuietMs = 3e3;
58427
58599
  VERIFY_SLICE_MS = 20;
58428
58600
  VERIFY_POLL_MS = 250;
@@ -58439,6 +58611,17 @@ var init_compact = __esm({
58439
58611
  pageZeroInFlight = /* @__PURE__ */ new Map();
58440
58612
  OWN_READ_TIMEOUT_MS = HISTORY_RPC_REQUEST_TIMEOUT_MS;
58441
58613
  BOUNDED_OWN_METHODS = /* @__PURE__ */ new Set(["getAccountInfo", "getAccountInfoAndContext", "getMultipleAccountsInfo", "getMultipleAccountsInfoAndContext"]);
58614
+ P03_COMPACT_TAIL_GRID = 512;
58615
+ TAIL_RETRY_REFUSALS = /* @__PURE__ */ new Set([
58616
+ "p03_compact_history_root_mismatch",
58617
+ "p03_compact_history_kind_count_mismatch",
58618
+ "p03_compact_history_record_order_invalid",
58619
+ "p03_compact_history_record_invalid",
58620
+ "p03_compact_history_record_after_snapshot",
58621
+ "p03_compact_history_source_answer_invalid"
58622
+ ]);
58623
+ tailFrom = (count2, grid) => Math.floor((count2 - 1) / grid) * grid;
58624
+ sameJson = (left, right) => JSON.stringify(left) === JSON.stringify(right);
58442
58625
  SPOT_HEDGE_AFTER_MS = 4e3;
58443
58626
  SPOT_HEDGE_LANE = "spot-hedge";
58444
58627
  spotReadId = 0;
@@ -59243,13 +59426,19 @@ async function walkWalletP03HistoryNow({ store, connection: given, programId, po
59243
59426
  } else if (earlier !== void 0) {
59244
59427
  markPhase("refresh-start");
59245
59428
  let slicedPreRead;
59429
+ let page0Asked = false;
59430
+ let page0Answered = false;
59246
59431
  if (compactNext) {
59247
59432
  const started = startCompactPoolSnapshot({ connection, programId, pool: pool2 });
59248
59433
  slicedPreRead = started.sliced;
59249
59434
  poolPreRead = started.full;
59250
59435
  markPhase("compact-pool-prestarted");
59251
- if (!inTorRun() && Date.now() - remembered.at > PAGE0_PREREAD_AFTER_MS) {
59436
+ if (inTorRun() || Date.now() - remembered.at > PAGE0_PREREAD_AFTER_MS) {
59437
+ page0Asked = true;
59252
59438
  firstPreRead = requestCompactFirstPage({ history: connection.historyRpcSource, pool: pool2 });
59439
+ firstPreRead.then(() => {
59440
+ page0Answered = true;
59441
+ });
59253
59442
  markPhase("compact-page0-prestarted");
59254
59443
  }
59255
59444
  }
@@ -59275,6 +59464,14 @@ async function walkWalletP03HistoryNow({ store, connection: given, programId, po
59275
59464
  try {
59276
59465
  const refreshed = await refreshing;
59277
59466
  markPhase("walk-refreshed");
59467
+ if (page0Asked) {
59468
+ markPhase(page0Answered ? "compact-page0-answered-before-hit" : "compact-page0-read-on-after-hit");
59469
+ const currentIndex = refreshed?.finalizedPoolSnapshot?.currentIndex;
59470
+ if (typeof currentIndex === "bigint" && currentIndex > 0n) {
59471
+ requestCompactTailPage({ history: connection.historyRpcSource, pool: pool2, currentIndex });
59472
+ markPhase("compact-tail-sent-on-hit");
59473
+ }
59474
+ }
59278
59475
  rememberRunReport(runKey, refreshed);
59279
59476
  writeStderr("history: the pool made no transition since this run's last walk; that history was moved to the current pool account " + (fromSliced ? "(your own RPC read the pool account and the program's deployment account in one request)\n" : "(your own RPC read the pool account and the program's deployment account; the history source answered one signature read)\n"));
59280
59477
  return refreshed;
@@ -103884,7 +104081,7 @@ function hostConfigText({ home, env = process.env, platform = process.platform }
103884
104081
  function isOlderSetupEntry(existing, entry) {
103885
104082
  if (!isPlainObject3(existing) || entry.command !== "npx" || !Array.isArray(entry.args)) return false;
103886
104083
  const older = { ...entry, args: entry.args.filter((arg) => !NPX_INSTALL_FLAGS.includes(arg)) };
103887
- return older.args.length !== entry.args.length && sameJson(existing, older);
104084
+ return older.args.length !== entry.args.length && sameJson2(existing, older);
103888
104085
  }
103889
104086
  function restrictToOwnerWindows(file, { run: run5 = execFileSync2 } = {}) {
103890
104087
  const system32 = join18(process.env.SystemRoot || "C:/Windows", "System32");
@@ -103917,7 +104114,7 @@ function addToJsonHost(file, entry, { now = /* @__PURE__ */ new Date(), force =
103917
104114
  }
103918
104115
  const existing = current.mcpServers?.[MCP_SERVER_NAME];
103919
104116
  if (existing !== void 0) {
103920
- if (sameJson(existing, entry)) return { file, changed: false };
104117
+ if (sameJson2(existing, entry)) return { file, changed: false };
103921
104118
  if (!force && !isOlderSetupEntry(existing, entry)) {
103922
104119
  throw new Error(`setup_host_config_conflict: the host's config file already has a different "${MCP_SERVER_NAME}" server, so setup left it alone; rerun setup with --force to replace it (the old file is backed up first), or edit it by hand`);
103923
104120
  }
@@ -103965,7 +104162,7 @@ function addToJsonHost(file, entry, { now = /* @__PURE__ */ new Date(), force =
103965
104162
  }
103966
104163
  return { file, changed: true, ...backup ? { backup } : {} };
103967
104164
  }
103968
- var import_web3118, CONFIG_SCHEMA, CONFIG_FILE, NPX_PACKAGE, NPX_INSTALL_FLAGS, MCP_SERVER_NAME, P03_BINDING2, PRODUCTION, RETIRED_POOLS, NO_LIMIT_ATOMIC2, DEFAULT_CAPS, OLD_DEFAULT_SETUP_CAPS, OLD_DEFAULT_WALLET_BUDGETS, capText, POSITIVE_ATOMIC2, configPath, homeWalletPath, invalid3, isPubkey, HOST_TARGETS, WINDOWS_SHELL_CODE, isPlainObject3, sameJson;
104165
+ var import_web3118, CONFIG_SCHEMA, CONFIG_FILE, NPX_PACKAGE, NPX_INSTALL_FLAGS, MCP_SERVER_NAME, P03_BINDING2, PRODUCTION, RETIRED_POOLS, NO_LIMIT_ATOMIC2, DEFAULT_CAPS, OLD_DEFAULT_SETUP_CAPS, OLD_DEFAULT_WALLET_BUDGETS, capText, POSITIVE_ATOMIC2, configPath, homeWalletPath, invalid3, isPubkey, HOST_TARGETS, WINDOWS_SHELL_CODE, isPlainObject3, sameJson2;
103969
104166
  var init_config2 = __esm({
103970
104167
  "wallet/src/setup/config.mjs"() {
103971
104168
  "use strict";
@@ -104016,7 +104213,7 @@ var init_config2 = __esm({
104016
104213
  HOST_TARGETS = Object.freeze(["claude-code", "claude-desktop", "cursor"]);
104017
104214
  WINDOWS_SHELL_CODE = /[%$`"\r\n]/;
104018
104215
  isPlainObject3 = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
104019
- sameJson = (a, b) => {
104216
+ sameJson2 = (a, b) => {
104020
104217
  const canonical5 = (value) => Array.isArray(value) ? value.map(canonical5) : isPlainObject3(value) ? Object.fromEntries(Object.keys(value).sort().map((key) => [key, canonical5(value[key])])) : value;
104021
104218
  return JSON.stringify(canonical5(a)) === JSON.stringify(canonical5(b));
104022
104219
  };