shinjuku-shield 0.3.203 → 0.3.205

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/README.md CHANGED
@@ -5,12 +5,12 @@ web services and AI answers from your private balance, so the payment does
5
5
  not show who paid. It works inside your AI app (Claude, Cursor, Codex) and in
6
6
  a terminal. Only you hold the keys: they never leave your computer.
7
7
 
8
- This is version 0.3.203. The command is `shinjuku`.
8
+ This is version 0.3.205. The command is `shinjuku`.
9
9
 
10
10
  ## Set up
11
11
 
12
12
  ```sh
13
- npx -y shinjuku@0.3.203 setup
13
+ npx -y shinjuku@0.3.205 setup
14
14
  ```
15
15
 
16
16
  Setup does every step for you:
@@ -42,13 +42,6 @@ shinjuku setup --add-to claude-code
42
42
  Then reconnect the wallet in Claude Code: type `/mcp`, pick `shinjuku`, and
43
43
  choose Reconnect.
44
44
 
45
- > **In this test version (not offered yet):**
46
- > - On Windows, the wallet downloads and starts Tor by itself, and starts it
47
- > again after a restart.
48
- > - `setup --add-to claude-desktop`, `--add-to cursor` and `--add-to codex` add
49
- > the wallet to Claude Desktop, Cursor and Codex. At the end of setup, the
50
- > wallet prints this line for every app it knows.
51
-
52
45
  ## Add money
53
46
 
54
47
  Ask your AI app: "Add 0.50 USDC to my private balance." It gives you a
@@ -107,28 +100,7 @@ Add it yourself. The name of the wallet in your app is `shinjuku`.
107
100
  Claude Code:
108
101
 
109
102
  ```sh
110
- claude mcp add --scope user shinjuku -- npx -y --no-audit --no-fund shinjuku-shield@0.3.203 mcp
111
- ```
112
-
113
- In this test version only (not offered yet), the same entry for Claude Desktop
114
- (`claude_desktop_config.json`) or Cursor (`~/.cursor/mcp.json`):
115
-
116
- ```json
117
- { "mcpServers": { "shinjuku": { "command": "npx", "args": ["-y", "--no-audit", "--no-fund", "shinjuku-shield@0.3.203", "mcp"] } } }
118
- ```
119
-
120
- On Windows, if the app cannot find `npx`, use `"command": "cmd"` and put
121
- `"/c", "npx"` at the start of `args`.
122
-
123
- In this test version only (not offered yet), Codex (the Codex app and Codex
124
- CLI read `~/.codex/config.toml`):
125
-
126
- ```toml
127
- [mcp_servers.shinjuku]
128
- command = "npx"
129
- args = ["-y", "--no-audit", "--no-fund", "shinjuku-shield@0.3.203", "mcp"]
130
- startup_timeout_sec = 120
131
- tool_timeout_sec = 300
103
+ claude mcp add --scope user shinjuku -- npx -y --no-audit --no-fund shinjuku-shield@0.3.205 mcp
132
104
  ```
133
105
 
134
106
  ## For builders: check what you install
@@ -144,7 +116,7 @@ with the Releases table in
144
116
  Versions are published from GitHub Actions with npm provenance.
145
117
 
146
118
  `shinjuku-shield` is the package that holds the wallet. `shinjuku-shielded`
147
- 0.3.203, its older name, runs this package at the same version, so wallets
119
+ 0.3.205, its older name, runs this package at the same version, so wallets
148
120
  installed under that name keep updating. New installs use `shinjuku`.
149
121
 
150
122
  The full guide is
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": "b5d26888908f60a311b42d9d0ba42bb5be37f1464a4bdcfe1ef3ea4534363443",
5
- "bytes": 9493844,
6
- "sourceCommit": "83c229cc05ec51cbedb6720e31c9f21fb5e8a540",
4
+ "sha256": "a74629364f4ac22ce7b0ac74294824d926277cc1d2c5fb160f69087cb04a0303",
5
+ "bytes": 9497703,
6
+ "sourceCommit": "e9c59a9bbfb935841c6182998ac30701f93aedfb",
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",
@@ -1932,5 +1932,5 @@
1932
1932
  }
1933
1933
  ]
1934
1934
  },
1935
- "publishedAt": "2026-11-09T07:57:59.571Z"
1935
+ "publishedAt": "2026-11-09T09:27:36.428Z"
1936
1936
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "shinjuku-shield",
3
- "version": "0.3.203",
3
+ "version": "0.3.205",
4
4
  "mcpName": "io.github.ShinjukuStaition/shinjuku-shield",
5
5
  "description": "Shinjuku Shield, private x402 payments 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": "b5d26888",
7
- "shinjukuSha256": "b5d26888908f60a311b42d9d0ba42bb5be37f1464a4bdcfe1ef3ea4534363443",
6
+ "shinjukuRelease": "a7462936",
7
+ "shinjukuSha256": "a74629364f4ac22ce7b0ac74294824d926277cc1d2c5fb160f69087cb04a0303",
8
8
  "license": "SEE LICENSE IN LICENSE.txt",
9
9
  "author": "Shinjuku Shield",
10
10
  "homepage": "https://github.com/ShinjukuStaition/shinjuku-shield#readme",
@@ -110113,6 +110113,10 @@ function refundArrived(snapshot, refundTo) {
110113
110113
  function floatRefundHeld(snapshot, record) {
110114
110114
  return refundArrived(snapshot, record?.refundTo);
110115
110115
  }
110116
+ function submittedNewsOld(times, atMs) {
110117
+ const since = times.find((ms) => validPaymentTimeMs(ms) && ms <= atMs);
110118
+ return since === void 0 ? false : atMs - since >= REFUND_OUTCOME_NEWS_MS;
110119
+ }
110116
110120
  function returnArrivedFloatRefundBudgets(store, snapshot) {
110117
110121
  const refreshedAtMs = Date.parse(snapshot?.refreshedAt ?? "");
110118
110122
  const knowsRecipients = snapshotKnowsRecipients(snapshot);
@@ -110121,17 +110125,14 @@ function returnArrivedFloatRefundBudgets(store, snapshot) {
110121
110125
  const record = store.readWal(name);
110122
110126
  if (record?.schema !== FLOAT_PAYMENT_SCHEMA2 || typeof record.innerRequestId !== "string") continue;
110123
110127
  const state2 = floatRecordState(record);
110124
- if (state2 === "submitted") {
110125
- if (refundArrived(snapshot, record.refundTo)) releaseRefundedReservation({ store, requestId: record.innerRequestId });
110126
- continue;
110127
- }
110128
- if (state2 !== "refund_pending") continue;
110128
+ const submitted = state2 === "submitted";
110129
+ if (!submitted && state2 !== "refund_pending") continue;
110129
110130
  const arrivedNow = refundArrived(snapshot, record.refundTo);
110130
110131
  if (arrivedNow) releaseRefundedReservation({ store, requestId: record.innerRequestId });
110131
- const outcome = arrivedNow ? "refund_arrived" : record.refundOutcome === void 0 && refundCountStopped(record, refreshedAtMs, knowsRecipients) ? "refund_not_seen" : void 0;
110132
+ const outcome = arrivedNow ? "refund_arrived" : !submitted && record.refundOutcome === void 0 && refundCountStopped(record, refreshedAtMs, knowsRecipients) ? "refund_not_seen" : void 0;
110132
110133
  if (outcome === void 0 || outcome === record.refundOutcome) continue;
110133
110134
  const atMs = Number.isFinite(refreshedAtMs) ? refreshedAtMs : Date.now();
110134
- const old = !(atMs - record.refundPendingAtMs < REFUND_OUTCOME_NEWS_MS);
110135
+ const old = submitted ? submittedNewsOld([record.submittedAtMs, record.floatPaidAtMs, record.createdAtMs], atMs) : !(atMs - record.refundPendingAtMs < REFUND_OUTCOME_NEWS_MS);
110135
110136
  try {
110136
110137
  store.writeWal(name, { ...record, refundOutcome: outcome, refundOutcomeAtMs: atMs, refundOutcomeShown: old });
110137
110138
  } catch {
@@ -110145,7 +110146,17 @@ function floatSellerHost(record) {
110145
110146
  return void 0;
110146
110147
  }
110147
110148
  }
110148
- function readFloatRefundOutcomes(store) {
110149
+ function paymentTimeText(paidAtMs, nowMs = Date.now()) {
110150
+ if (!validPaymentTimeMs(paidAtMs)) return void 0;
110151
+ const at = new Date(paidAtMs).toISOString();
110152
+ const day = at.slice(0, 10);
110153
+ const today = Number.isFinite(new Date(nowMs).getTime()) ? new Date(nowMs).toISOString().slice(0, 10) : void 0;
110154
+ return `${at.slice(11, 16)} UTC${day === today ? "" : ` on ${day}`}`;
110155
+ }
110156
+ function validPaymentTimeMs(ms) {
110157
+ return Number.isSafeInteger(ms) && ms >= PAYMENT_TIME_MIN_MS && ms <= PAYMENT_TIME_MAX_MS && Number.isFinite(new Date(ms).getTime());
110158
+ }
110159
+ function readFloatRefundOutcomes(store, now = Date.now()) {
110149
110160
  const outcomes = [];
110150
110161
  let names;
110151
110162
  try {
@@ -110157,9 +110168,20 @@ function readFloatRefundOutcomes(store) {
110157
110168
  if (!name.startsWith(FLOAT_PAYMENT_WAL_PREFIX2)) continue;
110158
110169
  try {
110159
110170
  const record = store.readWal(name);
110160
- if (record?.schema !== FLOAT_PAYMENT_SCHEMA2 || floatRecordState(record) !== "refund_pending") continue;
110171
+ if (record?.schema !== FLOAT_PAYMENT_SCHEMA2 || !["refund_pending", "submitted"].includes(floatRecordState(record))) continue;
110161
110172
  if (record.refundOutcome === void 0 || record.refundOutcomeShown !== false) continue;
110162
- outcomes.push({ floatId: record.floatId, paidAtomic: record.paidAtomic, host: floatSellerHost(record), outcome: record.refundOutcome, atMs: record.refundOutcomeAtMs });
110173
+ const inner = String(record.innerRequestId ?? "");
110174
+ outcomes.push({
110175
+ floatId: record.floatId,
110176
+ paidAtomic: record.paidAtomic,
110177
+ host: floatSellerHost(record),
110178
+ outcome: record.refundOutcome,
110179
+ atMs: record.refundOutcomeAtMs,
110180
+ // The first VALID time (Codex round 1 on 7faf9c93: `??` took an invalid non-null time before a valid later one).
110181
+ // and never one after now (Codex round 1 on 41e095b2: a time in the future is no time).
110182
+ paidAtMs: [record.floatPaidAtMs, record.submittedAtMs, record.createdAtMs].find((ms) => validPaymentTimeMs(ms) && ms <= now),
110183
+ ...inner.endsWith(":float") ? { requestId: inner.slice(0, -":float".length) } : {}
110184
+ });
110163
110185
  } catch {
110164
110186
  }
110165
110187
  }
@@ -112105,7 +112127,7 @@ function paidResult(record, replayed) {
112105
112127
  float: { floatId: record.floatId }
112106
112128
  };
112107
112129
  }
112108
- var import_web3117, FLOAT_PAYMENT_SCHEMA2, REGENERATE_CODES, FLOAT_PAYMENT_WAL_PREFIX2, FLOAT_CONFIG_SCHEMA, FLOAT_PAY_PATH, FLOAT_MEMO_PATH, FLOAT_STATUS_PATH, MAX_BODY_BYTES, FLOAT_REFUND_ETA_SECONDS, REFUND_READ_EARLY_MS, REFUND_ETA_MAX_SECONDS, RERUN_STATUS_READ_MAX_MS, REFUND_SENT_FLOOR_SECONDS, refundDueOf, REFUND_SETTLED_AFTER_MS, REFUND_OUTCOME_NEWS_MS, FINISHING_POLL_MS, FINISHING_LIMIT_MS, SELLER_TIMEOUT_MS, SELLER_TIMEOUT_ABSURD_SECONDS, SELLER_STALL_CHECK_AFTER_MS, SELLER_STALL_CHECK_EVERY_MS, SELLER_STALL_CHECK_TIMEOUT_MS, SELLER_STALL_MISSES, RESULT_LIMIT_BYTES, FLOAT_STATUS_START_MS, FLOAT_STATUS_POLL_MS, FLOAT_STATUS_TIMEOUT_MS, CONFIRM_READ_MS, FLOAT_TRANSFER_DEAD, FLOAT_PAYMENT_REVERTED, VERDICT_POLL_MS, SELLER_ANSWER_VERDICT_MS, TRANSFER_MIN_BLOCKS_LEFT, TRANSFER_FRESH_MS, BLOCK_HEIGHT_TIMEOUT_MS, CONFIG_TIMEOUT_MS, MEMO_UPLOAD_TIMEOUT_MS, CONFIG_CACHE_MS, FLOAT_POOL_WARM_MS, DECIMAL3, POSITIVE, PENDING_CODES, FLOAT_FRONT_HEADER, hash7, fail25, GENERIC_REASON, SELLER_REASON_MAX, SELLER_REASON_READ_BYTES, FEE_PAYER_RESENDS, FEE_PAYER_RESEND_MS, GLOBAL_DISPATCHER5, sortedJson, MODEL_ID, RESIGN_ASK_WINDOW_MS, RESIGN_ASK_TIMEOUT_MS, RESIGN_FINISHING_WAIT_MS, RESIGN_MIN_SELLER_LEFT_MS, RESIGN_ANSWER_MAX_BYTES, floatPaymentWalName, floatRecordName, FLOAT_KEEP_BYTES_MS, memoryOnlyNeedsScrub, FLOAT_KEEP_OPEN_REQUEST_MS, configCache, configGeneration, configReadSequence, configReads, configRefreshes, SPECULATED_MAX_AGE_MS, speculatedQuotes, poolDomains, FLOAT_FACTS_SCHEMA, floatFacts, floatFactsKey, floatFactsMac, poolDomainReads, poolDomainWarmFailedAt, WARM_RETRY_MS, payerGenerator, etaEntry, loadPayerGenerator, plainText, quoteLimits, originOf, BROADCAST_REFUSED, BROADCAST_REFUSED_STANDARD, BROADCAST_DEAD, TRANSFER_LANDING_WINDOW_MS, PROOF_DELIVERY_MS, SELF_BROADCAST_LEG1_LEFT_MS, BROADCAST_UNSIGNED, BROADCAST_NO_LOOKUP, BROADCAST_LANDED, BROADCAST_LIMIT_MS, BROADCAST_QUOTE_MARGIN_MS, SELF_BROADCAST_RESEND_MS, SELF_BROADCAST_UNANSWERED_RESEND_MS, SELLER_HEADERS_MAX_COUNT, SELLER_HEADERS_MAX_BYTES, FINAL_AFTER_202_MS, SELLER_HEADERS_KEPT;
112130
+ var import_web3117, FLOAT_PAYMENT_SCHEMA2, REGENERATE_CODES, FLOAT_PAYMENT_WAL_PREFIX2, FLOAT_CONFIG_SCHEMA, FLOAT_PAY_PATH, FLOAT_MEMO_PATH, FLOAT_STATUS_PATH, MAX_BODY_BYTES, FLOAT_REFUND_ETA_SECONDS, REFUND_READ_EARLY_MS, REFUND_ETA_MAX_SECONDS, RERUN_STATUS_READ_MAX_MS, REFUND_SENT_FLOOR_SECONDS, refundDueOf, REFUND_SETTLED_AFTER_MS, REFUND_OUTCOME_NEWS_MS, FINISHING_POLL_MS, FINISHING_LIMIT_MS, SELLER_TIMEOUT_MS, SELLER_TIMEOUT_ABSURD_SECONDS, SELLER_STALL_CHECK_AFTER_MS, SELLER_STALL_CHECK_EVERY_MS, SELLER_STALL_CHECK_TIMEOUT_MS, SELLER_STALL_MISSES, RESULT_LIMIT_BYTES, FLOAT_STATUS_START_MS, FLOAT_STATUS_POLL_MS, FLOAT_STATUS_TIMEOUT_MS, CONFIRM_READ_MS, FLOAT_TRANSFER_DEAD, FLOAT_PAYMENT_REVERTED, VERDICT_POLL_MS, SELLER_ANSWER_VERDICT_MS, TRANSFER_MIN_BLOCKS_LEFT, TRANSFER_FRESH_MS, BLOCK_HEIGHT_TIMEOUT_MS, CONFIG_TIMEOUT_MS, MEMO_UPLOAD_TIMEOUT_MS, CONFIG_CACHE_MS, FLOAT_POOL_WARM_MS, DECIMAL3, POSITIVE, PENDING_CODES, FLOAT_FRONT_HEADER, hash7, fail25, GENERIC_REASON, SELLER_REASON_MAX, SELLER_REASON_READ_BYTES, FEE_PAYER_RESENDS, FEE_PAYER_RESEND_MS, GLOBAL_DISPATCHER5, sortedJson, MODEL_ID, RESIGN_ASK_WINDOW_MS, RESIGN_ASK_TIMEOUT_MS, RESIGN_FINISHING_WAIT_MS, RESIGN_MIN_SELLER_LEFT_MS, RESIGN_ANSWER_MAX_BYTES, floatPaymentWalName, floatRecordName, PAYMENT_TIME_MIN_MS, PAYMENT_TIME_MAX_MS, FLOAT_KEEP_BYTES_MS, memoryOnlyNeedsScrub, FLOAT_KEEP_OPEN_REQUEST_MS, configCache, configGeneration, configReadSequence, configReads, configRefreshes, SPECULATED_MAX_AGE_MS, speculatedQuotes, poolDomains, FLOAT_FACTS_SCHEMA, floatFacts, floatFactsKey, floatFactsMac, poolDomainReads, poolDomainWarmFailedAt, WARM_RETRY_MS, payerGenerator, etaEntry, loadPayerGenerator, plainText, quoteLimits, originOf, BROADCAST_REFUSED, BROADCAST_REFUSED_STANDARD, BROADCAST_DEAD, TRANSFER_LANDING_WINDOW_MS, PROOF_DELIVERY_MS, SELF_BROADCAST_LEG1_LEFT_MS, BROADCAST_UNSIGNED, BROADCAST_NO_LOOKUP, BROADCAST_LANDED, BROADCAST_LIMIT_MS, BROADCAST_QUOTE_MARGIN_MS, SELF_BROADCAST_RESEND_MS, SELF_BROADCAST_UNANSWERED_RESEND_MS, SELLER_HEADERS_MAX_COUNT, SELLER_HEADERS_MAX_BYTES, FINAL_AFTER_202_MS, SELLER_HEADERS_KEPT;
112109
112131
  var init_floatPay = __esm({
112110
112132
  "wallet/src/pay/floatPay.mjs"() {
112111
112133
  "use strict";
@@ -112200,6 +112222,8 @@ var init_floatPay = __esm({
112200
112222
  RESIGN_ANSWER_MAX_BYTES = 128 * 1024;
112201
112223
  floatPaymentWalName = (requestKey) => `${FLOAT_PAYMENT_WAL_PREFIX2}${requestKey}`;
112202
112224
  floatRecordName = (requestId) => floatPaymentWalName(hash7(requestId));
112225
+ PAYMENT_TIME_MIN_MS = Date.UTC(2024, 0, 1);
112226
+ PAYMENT_TIME_MAX_MS = Date.UTC(9999, 11, 31);
112203
112227
  FLOAT_KEEP_BYTES_MS = 6e5;
112204
112228
  memoryOnlyNeedsScrub = (record) => record?.memoryOnly === true && (record.resultSha256 !== void 0 || Array.isArray(record.sellerHeaders) && record.sellerHeaders.length > 0 || record.request?.bodySha256 !== void 0 || record.request?.headersSha256 !== void 0 || !/^memory-[0-9a-f]{64}$/.test(String(record.fingerprint ?? "")));
112205
112229
  FLOAT_KEEP_OPEN_REQUEST_MS = 36e5;
@@ -116250,6 +116274,13 @@ function sellerInputLine(missing, line, room = SAY_MAX_WORDS) {
116250
116274
  const lines = tries.map((text3) => line(text3, list.length));
116251
116275
  return lines.find((text3) => words(text3) <= room) ?? lines[lines.length - 1];
116252
116276
  }
116277
+ function refundInFlightAtomic(breakdown) {
116278
+ const total = String(breakdown?.refundsInFlightAtomic ?? "");
116279
+ if (!ATOMIC7.test(total)) return void 0;
116280
+ const arrived2 = (Array.isArray(breakdown.refundsInFlight) ? breakdown.refundsInFlight : []).filter((entry) => entry?.refundArrived === true && ATOMIC7.test(String(entry.refundAtomic ?? ""))).reduce((sum2, entry) => sum2 + BigInt(entry.refundAtomic), 0n);
116281
+ const left = BigInt(total) - arrived2;
116282
+ return (left > 0n ? left : 0n).toString();
116283
+ }
116253
116284
  function spendSentence(a, tails = ["."], room = SAY_MAX_WORDS) {
116254
116285
  if (!ATOMIC7.test(String(a?.balanceAtomic ?? ""))) return void 0;
116255
116286
  const heads = spendHeads(a.balanceAtomic, a.largestPaymentAtomic, a);
@@ -117717,7 +117748,7 @@ var init_say = __esm({
117717
117748
  doneInText = (a) => Number.isSafeInteger(a.doneInMinutesLow) && Number.isSafeInteger(a.doneInMinutesHigh) ? `about ${a.doneInMinutesLow} to ${a.doneInMinutesHigh} minutes` : "";
117718
117749
  positive = (text3) => text3 !== void 0 && text3 !== "0";
117719
117750
  str = (value2) => typeof value2 === "string" ? value2 : "";
117720
- refundInFlight = (a) => Array.isArray(a.refundNotices) && a.refundNotices.length ? void 0 : usdcText2(a.breakdown?.refundsInFlightAtomic);
117751
+ refundInFlight = (a) => usdcText2(refundInFlightAtomic(a.breakdown));
117721
117752
  sellerAnswered = (status, data) => status >= 500 ? "had a server error" : status >= 400 ? "refused the request" : `sent no ${data}`;
117722
117753
  urlAnswered = (status) => status === 404 || status === 410 ? "was not found" : status === 401 || status === 403 ? "refused access" : status >= 500 ? "had a server error" : "refused the request";
117723
117754
  OWN_WORK_WORDS = Object.freeze({
@@ -135751,11 +135782,51 @@ async function sellerTokenAccountExists(connection, asset, payTo) {
135751
135782
  return void 0;
135752
135783
  }
135753
135784
  }
135754
- function refundOutcomeText(outcome) {
135755
- const amount = ATOMIC_TEXT.test(String(outcome?.paidAtomic ?? "")) ? `${usdcText3(outcome.paidAtomic)} USDC` : "a Shinjuku payment";
135756
- const payment = typeof outcome?.host === "string" && /^[a-z0-9.-]{1,253}$/i.test(outcome.host) ? ` for the payment to ${outcome.host}` : "";
135757
- if (outcome?.outcome === "refund_arrived") return `The refund of ${amount}${payment} arrived.`;
135758
- return `The refund of ${amount}${payment} could not be matched in your balance (this balance read cannot tell refunds apart); if it came back, balanceAtomic counts it already.`;
135785
+ function refundOutcomeText(outcome, nowMs = Date.now()) {
135786
+ const amount = ATOMIC_TEXT.test(String(outcome?.paidAtomic ?? "")) ? `${usdcText3(outcome.paidAtomic)} USDC ` : "";
135787
+ const host = typeof outcome?.host === "string" && /^[a-z0-9.-]{1,253}$/i.test(outcome.host) ? outcome.host : void 0;
135788
+ const when = paymentTimeText(outcome?.paidAtMs, nowMs);
135789
+ const payment = `your earlier ${host ? `payment to ${host}` : "Shinjuku payment"}${when ? ` (paid ${when})` : ""}`;
135790
+ if (outcome?.outcome === "refund_arrived") return `The ${amount}refund for ${payment} arrived.`;
135791
+ return `The ${amount}refund for ${payment} could not be matched in your balance (this balance read cannot tell refunds apart); if it came back, balanceAtomic counts it already.`;
135792
+ }
135793
+ function refundOutcomesToShow(outcomes, shown, exceptFloatId) {
135794
+ return outcomes.filter(({ floatId, outcome }) => !shown.has(`${floatId}:${outcome}`) && !(typeof exceptFloatId === "string" && floatId === exceptFloatId));
135795
+ }
135796
+ function noticesOnce({
135797
+ outcomes,
135798
+ readUnkept,
135799
+ shown,
135800
+ exceptFloatId,
135801
+ markRefunds,
135802
+ markUnkept,
135803
+ textOf: textOf2 = (outcome) => refundOutcomeText(outcome),
135804
+ unkeptText = answerNotKeptNoticeWords
135805
+ }) {
135806
+ const fresh = refundOutcomesToShow(outcomes, shown, exceptFloatId);
135807
+ let unkept;
135808
+ let refundNotices;
135809
+ let paidNotices;
135810
+ try {
135811
+ unkept = readUnkept().filter(({ requestId }) => !shown.has(`unkept:${requestId}`));
135812
+ refundNotices = fresh.map((outcome) => textOf2(outcome));
135813
+ paidNotices = unkept.map((notice) => unkeptText(notice));
135814
+ } catch {
135815
+ return { notices: {}, arrived: [] };
135816
+ }
135817
+ for (const { floatId, outcome } of fresh) shown.add(`${floatId}:${outcome}`);
135818
+ for (const { requestId } of unkept) shown.add(`unkept:${requestId}`);
135819
+ if (fresh.length) markRefunds(fresh);
135820
+ if (unkept.length) markUnkept(unkept);
135821
+ return {
135822
+ notices: { ...refundNotices.length ? { refundNotices } : {}, ...paidNotices.length ? { paidNotices } : {} },
135823
+ arrived: fresh.filter(({ outcome }) => outcome === "refund_arrived")
135824
+ };
135825
+ }
135826
+ function markArrivedRefunds(breakdown, arrived2) {
135827
+ if (!breakdown || !Array.isArray(breakdown.refundsInFlight) || !arrived2?.length) return breakdown;
135828
+ const named = (entry) => arrived2.some((one) => typeof entry?.requestId === "string" && entry.requestId === one.requestId || typeof entry?.floatId === "string" && entry.floatId === one.floatId);
135829
+ return { ...breakdown, refundsInFlight: breakdown.refundsInFlight.map((entry) => named(entry) ? { ...entry, refundArrived: true } : entry) };
135759
135830
  }
135760
135831
  function floatRefusal(error, overLimit, tool = "pay_for_service") {
135761
135832
  const code2 = String(error?.message ?? "").split(/[\s:;(]/, 1)[0];
@@ -137439,12 +137510,12 @@ ${key}`).digest("hex").slice(0, 40)}.json`);
137439
137510
  ...share ? { share } : {}
137440
137511
  });
137441
137512
  const shownRefunds = /* @__PURE__ */ new Set();
137442
- const takeRefundNotices = (store) => {
137513
+ const takeRefundNotices = (store, exceptFloatId) => {
137443
137514
  let open5;
137444
137515
  try {
137445
137516
  open5 = store ?? session.openStore();
137446
137517
  } catch {
137447
- return {};
137518
+ return { notices: {}, arrived: [] };
137448
137519
  }
137449
137520
  let outcomes;
137450
137521
  try {
@@ -137452,18 +137523,16 @@ ${key}`).digest("hex").slice(0, 40)}.json`);
137452
137523
  } catch {
137453
137524
  outcomes = [];
137454
137525
  }
137455
- const fresh = outcomes.filter(({ floatId, outcome }) => !shownRefunds.has(`${floatId}:${outcome}`));
137456
- const unkept = readAnswerNotKeptNotices(open5).filter(({ requestId }) => !shownRefunds.has(`unkept:${requestId}`));
137457
- for (const { floatId, outcome } of fresh) shownRefunds.add(`${floatId}:${outcome}`);
137458
- for (const { requestId } of unkept) shownRefunds.add(`unkept:${requestId}`);
137459
- if (fresh.length) underLease((leased) => markFloatRefundOutcomesShown(leased, fresh)).catch(() => {
137460
- });
137461
- if (unkept.length) underLease((leased) => markAnswerNotKeptShown(leased, unkept)).catch(() => {
137526
+ return noticesOnce({
137527
+ outcomes,
137528
+ readUnkept: () => readAnswerNotKeptNotices(open5),
137529
+ shown: shownRefunds,
137530
+ exceptFloatId,
137531
+ markRefunds: (fresh) => underLease((leased) => markFloatRefundOutcomesShown(leased, fresh)).catch(() => {
137532
+ }),
137533
+ markUnkept: (unkept) => underLease((leased) => markAnswerNotKeptShown(leased, unkept)).catch(() => {
137534
+ })
137462
137535
  });
137463
- return {
137464
- ...fresh.length ? { refundNotices: fresh.map(refundOutcomeText) } : {},
137465
- ...unkept.length ? { paidNotices: unkept.map(answerNotKeptNoticeWords) } : {}
137466
- };
137467
137536
  };
137468
137537
  const noticesStep = (notices) => [notices.refundNotices ? "refundNotices" : void 0, notices.paidNotices ? "paidNotices" : void 0].filter(Boolean).map((field5) => `. Tell the user each ${field5} line`).join("");
137469
137538
  const withRefundNotices = (answer, store) => {
@@ -137474,10 +137543,11 @@ ${key}`).digest("hex").slice(0, 40)}.json`);
137474
137543
  return answer;
137475
137544
  }
137476
137545
  if (!value2 || typeof value2 !== "object" || Array.isArray(value2)) return answer;
137477
- const notices = takeRefundNotices(store);
137546
+ const { notices, arrived: arrived2 } = takeRefundNotices(store, value2.floatId);
137478
137547
  if (!notices.refundNotices && !notices.paidNotices) return answer;
137479
137548
  return json4({
137480
137549
  ...value2,
137550
+ ...value2.breakdown ? { breakdown: markArrivedRefunds(value2.breakdown, arrived2) } : {},
137481
137551
  ...notices,
137482
137552
  ...typeof value2.next === "string" ? { next: `${value2.next.replace(/[.\s]+$/, "")}${noticesStep(notices)}` } : {}
137483
137553
  });
@@ -139157,7 +139227,8 @@ ${canonical5}`;
139157
139227
  }
139158
139228
  mark("mcp-result");
139159
139229
  const shinjukuTransaction = floatPaid ? leg1Transaction(paidStore, float, requestId) : null;
139160
- const notices = takeRefundNotices(paidStore);
139230
+ const { notices, arrived: arrivedRefunds } = takeRefundNotices(paidStore, float?.floatId);
139231
+ const shownBalance = balanceAnswer(one);
139161
139232
  return answerResult(paidAnswerContent({
139162
139233
  status: response.status,
139163
139234
  headers: response.headers,
@@ -139177,7 +139248,8 @@ ${canonical5}`;
139177
139248
  receiptFinality: unpaid ? "never-finalized" : receipt.receiptFinality ?? null,
139178
139249
  // Leg 1 (this wallet's private payment to Shinjuku, a pool transaction): the seller may return no settle signature.
139179
139250
  ...floatPaid ? { via: "shinjuku", shinjukuTransaction } : {},
139180
- ...balanceAnswer(one),
139251
+ ...shownBalance,
139252
+ ...shownBalance.breakdown ? { breakdown: markArrivedRefunds(shownBalance.breakdown, arrivedRefunds) } : {},
139181
139253
  ...notices,
139182
139254
  next: (unpaid ? "nothing was paid: this request id's payment never landed (the pool's public history proves it), and the answer it got came back again; nothing new was paid. Tell the user nothing was paid for it" : receipt.replayed === true ? "this request id was already paid: the stored receipt came back and nothing new was paid" + (floatPaid && receipt.receiptFinality === "pending" ? `. ${floatPaidNext({ transaction, shinjukuTransaction, pending: true })}` : "") : floatPaid ? floatPaidNext({ transaction: unpaid ? null : transaction, shinjukuTransaction, pending: receipt.receiptFinality === "pending" }) + (receipt.stallResent === true || float?.sellerStallResent === true ? `. Tell the user too: ${stallResentLine()}` : "") : "paid; tell the user what was paid (amountAtomic, transaction). wallet_receipts lists this payment, wallet_balance shows the new balance") + noticesStep(notices)
139183
139255
  }, "pay_for_service")
@@ -140085,11 +140157,12 @@ ${canonical5}`;
140085
140157
  }
140086
140158
  }
140087
140159
  const landedFrom = (total, sales) => sales <= 0n ? "USDC you added" : sales >= total ? "USDC from your sales" : "USDC you added and from your sales";
140088
- function walletCard({ one, unshielded, landingAtomic, landingSalesAtomic = 0n, recordFaultAtomic = 0n, sales, store, lastRead, refundNotices, refresh = {} }) {
140160
+ function walletCard({ one, unshielded, landingAtomic, landingSalesAtomic = 0n, recordFaultAtomic = 0n, sales, store, lastRead, refundBreakdown = one.breakdown, refresh = {} }) {
140089
140161
  const known = ATOMIC_TEXT.test(String(one.balanceAtomic ?? ""));
140090
140162
  const landing = `${landingAtomic > 0n ? `; ${usdcText3(landingAtomic)} ${landedFrom(landingAtomic, landingSalesAtomic)} is being counted` : ""}${sales ? `; ${sales.line}` : ""}`;
140091
140163
  const reading2 = lastRead ? `the wallet is still reading it; the last full read, ${ageWords2(lastRead.ageMinutes)} ago, showed ${usdcText3(lastRead.privateAtomic)} USDC` : "the wallet is still reading it";
140092
- const inFlight = /^[1-9][0-9]*$/.test(String(one.breakdown?.refundsInFlightAtomic ?? "")) && !refundNotices?.length ? usdcText3(one.breakdown.refundsInFlightAtomic) : void 0;
140164
+ const inFlightAtomic = refundInFlightAtomic(refundBreakdown);
140165
+ const inFlight = /^0*[1-9][0-9]*$/.test(String(inFlightAtomic ?? "")) ? usdcText3(inFlightAtomic) : void 0;
140093
140166
  const checking = refresh.refreshing === true && (refresh.refreshReason === void 0 || refresh.refreshReason === "refund_check");
140094
140167
  const lines = [!known ? `Private balance: not known yet (${reading2})${landing}` : checking ? `Private balance: last known ${usdcText3(one.balanceAtomic)} USDC${inFlight ? `, plus a ${inFlight} USDC refund` : ""}; the wallet is checking it now${landing}` : `Private balance: ${spendHeads(one.balanceAtomic, one.largestPaymentAtomic, one)[0].replace(/^You /, "you ")}${inFlight ? `, plus ${inFlight} USDC refund on its way` : ""}${landing}`];
140095
140168
  if (recordFaultAtomic > 0n) lines.push(`${usdcText3(recordFaultAtomic)} USDC you added landed, but Shinjuku's record of it does not match; nothing is lost; do not send it again`);
@@ -140634,7 +140707,7 @@ ${canonical5}`;
140634
140707
  if (sales) {
140635
140708
  next = `${next}. Tell the user: buyers paid ${sales.usdc} USDC for ${sales.payments === 1 ? "a sale" : `${sales.payments} sales`}, and the wallet is moving it into the private balance by itself (it is not in the balance yet; nothing to do). Call wallet_balance in a few minutes to see it in the balance`;
140636
140709
  }
140637
- const notices = takeRefundNotices();
140710
+ const { notices, arrived: arrivedRefunds } = takeRefundNotices();
140638
140711
  next = `${next}${noticesStep(notices)}`;
140639
140712
  if (ownTokens?.tokens.length) {
140640
140713
  const count3 = ownTokens.tokens.length + ownTokens.more;
@@ -140675,7 +140748,7 @@ ${canonical5}`;
140675
140748
  }
140676
140749
  internal.unshieldedTotalAtomic = exitedTotalAtomic ?? null;
140677
140750
  const { setAsideAtomic, ...breakdownRest } = one.breakdown;
140678
- const breakdown = setAsideAtomic === "0" ? breakdownRest : one.breakdown;
140751
+ const breakdown = markArrivedRefunds(setAsideAtomic === "0" ? breakdownRest : one.breakdown, arrivedRefunds);
140679
140752
  if (setAsideAtomic === "0") internal.setAsideAtomic = "0";
140680
140753
  const noLimit = (atomic5) => atomic5 === void 0 || atomic5 === null || String(atomic5) === NO_LIMIT_ATOMIC;
140681
140754
  const capWords2 = (atomic5) => noLimit(atomic5) ? "no limit" : `${usdcText3(atomic5)} USDC`;
@@ -140698,7 +140771,7 @@ ${canonical5}`;
140698
140771
  ...reportPublic,
140699
140772
  ...firstRead ? { status: "reading" } : {},
140700
140773
  ...balanceTextFields(one),
140701
- card: walletCard({ one, unshielded, landingAtomic, landingSalesAtomic: landingParts.salesAtomic, recordFaultAtomic: landingParts.recordFaultAtomic, sales, store, lastRead, refundNotices: notices.refundNotices, refresh }),
140774
+ card: walletCard({ one, unshielded, landingAtomic, landingSalesAtomic: landingParts.salesAtomic, recordFaultAtomic: landingParts.recordFaultAtomic, sales, store, lastRead, refundBreakdown: breakdown, refresh }),
140702
140775
  ...lastRead ? { lastRead } : {},
140703
140776
  // joinSteps: the joins, one after another (autoJoin.mjs joinParts joins), when the wallet gets the balance ready by
140704
140777
  // itself; doneInMinutes*: the time to send all of it (UX128-9).