shinjuku-shielded 0.3.121 → 0.3.123

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
@@ -6,19 +6,19 @@ answers privately, in a terminal chat or for your agent app. Its `mcp`
6
6
  command runs a local MCP server (stdio) for your agent. Your keys never
7
7
  leave your machine.
8
8
 
9
- This is version 0.3.121. The npm packages `shinjuku-shield` and
9
+ This is version 0.3.123. The npm packages `shinjuku-shield` and
10
10
  `shinjuku-shielded` hold the same files. The command is `shinjuku`.
11
11
 
12
12
  ## Set up
13
13
 
14
14
  ```sh
15
- npm install -g shinjuku@0.3.121
15
+ npm install -g shinjuku@0.3.123
16
16
  shinjuku setup
17
17
  ```
18
18
 
19
19
  Type the two lines as they are. `npx install shinjuku` does not work: npx
20
20
  reads `install` as the name of another npm package. To set up without
21
- installing, type `npx shinjuku@0.3.121 setup`.
21
+ installing, type `npx shinjuku@0.3.123 setup`.
22
22
 
23
23
  Setup makes the wallet on this machine, a private passphrase file, and the
24
24
  checked proof tools (about 191 MB), and writes `config.json`. It also writes
@@ -36,13 +36,13 @@ Every wallet command works after `shinjuku`, for example `shinjuku balance`,
36
36
  Claude Code:
37
37
 
38
38
  ```sh
39
- claude mcp add --scope user shinjuku -- npx -y --no-audit --no-fund shinjuku-shield@0.3.121 mcp
39
+ claude mcp add --scope user shinjuku -- npx -y --no-audit --no-fund shinjuku-shield@0.3.123 mcp
40
40
  ```
41
41
 
42
42
  Claude Desktop (`claude_desktop_config.json`) or Cursor (`~/.cursor/mcp.json`):
43
43
 
44
44
  ```json
45
- { "mcpServers": { "shinjuku": { "command": "npx", "args": ["-y", "--no-audit", "--no-fund", "shinjuku-shield@0.3.121", "mcp"] } } }
45
+ { "mcpServers": { "shinjuku": { "command": "npx", "args": ["-y", "--no-audit", "--no-fund", "shinjuku-shield@0.3.123", "mcp"] } } }
46
46
  ```
47
47
 
48
48
  On native Windows, if the host cannot find `npx`, use `"command": "cmd"` and
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": "b2d6f4507136f85fea6e6305a0a958a98b95c3ba2b82a060cc182b4a6d6f26bd",
5
- "bytes": 8471165,
6
- "sourceCommit": "9337bf3eaa4a9ac34e6d850cc800b8951dc657cd",
4
+ "sha256": "916f76a4396c16a3e274e9644291fef6362b5ba89f462400859888f9d94f77f9",
5
+ "bytes": 8474565,
6
+ "sourceCommit": "51234a177dae9a65c677dd4716a7f386b2e8b2eb",
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",
@@ -1037,5 +1037,5 @@
1037
1037
  "version": "1.8.0"
1038
1038
  }
1039
1039
  ],
1040
- "publishedAt": "2026-10-28T18:56:33.630Z"
1040
+ "publishedAt": "2026-10-28T20:30:28.766Z"
1041
1041
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "shinjuku-shielded",
3
- "version": "0.3.121",
3
+ "version": "0.3.123",
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": "b2d6f450",
7
- "shinjukuSha256": "b2d6f4507136f85fea6e6305a0a958a98b95c3ba2b82a060cc182b4a6d6f26bd",
6
+ "shinjukuRelease": "916f76a4",
7
+ "shinjukuSha256": "916f76a4396c16a3e274e9644291fef6362b5ba89f462400859888f9d94f77f9",
8
8
  "license": "SEE LICENSE IN LICENSE.txt",
9
9
  "author": "Shinjuku Shielded",
10
10
  "homepage": "https://github.com/ShinjukuStaition/shinjuku-shield#readme",
@@ -107110,7 +107110,10 @@ function refusalSay(a, tool, again, npmVersion) {
107110
107110
  const total2 = usdcText2(a.totalAtomic);
107111
107111
  const cap = usdcText2(a.capAtomic);
107112
107112
  const limit = /^[a-z0-9 -]{1,40}$/i.test(str(a.limitName)) ? a.limitName : "limit";
107113
- const over = total2 && cap ? `${total2} USDC above your ${cap} USDC ${limit}` : `this above your ${limit}`;
107113
+ const price = usdcText2(a.priceAtomic);
107114
+ const fee = usdcText2(a.feeAtomic);
107115
+ const split4 = price && positive(fee) ? ` (the price ${price} USDC plus Shinjuku's fee ${fee} USDC)` : "";
107116
+ const over = total2 && cap ? `${total2} USDC${split4} above your ${cap} USDC ${limit}` : `this above your ${limit}`;
107114
107117
  const head = `Nothing was ${verb}:`;
107115
107118
  const lines = {
107116
107119
  declined: [`${head} you chose not to allow ${over}.`],
@@ -108322,13 +108325,16 @@ async function payTurn({ session, target, method, headers, body, maxPrice, polic
108322
108325
  );
108323
108326
  }
108324
108327
  if (BigInt(price.amountAtomic) > BigInt(cap)) {
108328
+ const fee = price.rail === "exact" ? BigInt(price.amountAtomic) - BigInt(price.priceAtomic) : 0n;
108329
+ const split4 = fee > 0n ? { priceAtomic: String(price.priceAtomic), feeAtomic: fee.toString() } : {};
108325
108330
  throw new SpendRefusalError({
108326
108331
  ok: false,
108327
108332
  error: "spend_payment_cap_exceeded",
108328
- detail: `the price ${usdcWords(price.amountAtomic)} is above this call's cap ${usdcWords(cap)}; nothing was paid`,
108333
+ detail: `the price ${usdcWords(price.amountAtomic)}${fee > 0n ? ` (the seller's ${usdcWords(price.priceAtomic)} plus Shinjuku's fee ${usdcWords(fee)})` : ""} is above this call's cap ${usdcWords(cap)}; nothing was paid`,
108329
108334
  next: `pay only sellers priced at ${usdcWords(cap)} or less, or raise the limit per payment (maxPaymentAtomic)`,
108330
108335
  totalAtomic: String(price.amountAtomic),
108331
- capAtomic: String(cap)
108336
+ capAtomic: String(cap),
108337
+ ...split4
108332
108338
  });
108333
108339
  }
108334
108340
  if (store !== void 0 && price.floatConfig && standardResourceMatches(paymentRequired?.resource?.url, target)) {
@@ -110116,6 +110122,16 @@ var init_balanceNow = __esm({
110116
110122
  });
110117
110123
 
110118
110124
  // wallet/src/balance/emptyBalance.mjs
110125
+ function proofWalkHolds(store) {
110126
+ const last = lastProofRecovery(store);
110127
+ const recovered = last?.pool === store.state.pool && last.recovery?.narrowedByDigests !== true && Array.isArray(last.recovery?.recovered) ? last.recovery.recovered : void 0;
110128
+ if (!recovered) return void 0;
110129
+ const unspent = recovered.filter((entry) => entry?.spendStatus === "unspent");
110130
+ return {
110131
+ none: !recovered.some((entry) => entry?.spendStatus === "unspent" || entry?.spendStatus === "succession-movable"),
110132
+ receivedOnly: !unspent.some((entry) => entry.kind === "account") && unspent.some((entry) => entry.kind === "note")
110133
+ };
110134
+ }
110119
110135
  function knownEmptyBalance(store, { maxAgeMs } = {}) {
110120
110136
  try {
110121
110137
  const parts = balanceNow(store);
@@ -110136,6 +110152,7 @@ var init_emptyBalance = __esm({
110136
110152
  "wallet/src/balance/emptyBalance.mjs"() {
110137
110153
  "use strict";
110138
110154
  init_balanceNow();
110155
+ init_prepareRecoveredPayment();
110139
110156
  ABOVE_0 = /^0*[1-9]/;
110140
110157
  }
110141
110158
  });
@@ -126224,7 +126241,7 @@ function createWalletTools({
126224
126241
  const notAllowed = (why, { tool, requestId, numbers, flag: flag3 = payCapFlag(numbers.capAtomic), verb = "paid", more = false }, extra = {}) => {
126225
126242
  const answer = Object.hasOwn(NOT_ALLOWED_DETAIL, why) ? why : "error";
126226
126243
  const limitName = capName(flag3);
126227
- const amounts = `${usdcText3(numbers.totalAtomic)} USDC once, above the ${limitName} of ${usdcText3(numbers.capAtomic)} USDC`;
126244
+ const amounts = `${usdcText3(numbers.totalAtomic)} USDC${splitWords(floatSplitOf(extra), "the price")} once, above the ${limitName} of ${usdcText3(numbers.capAtomic)} USDC`;
126228
126245
  const nothing = `nothing ${more ? "more " : ""}was ${verb}`;
126229
126246
  const again2 = `call ${tool} again with request_id "${requestId}" and the same arguments: the wallet asks the user again`;
126230
126247
  const around = verb === "paid" ? "Do not change max_payment or the request to get around this." : "Do not split it into smaller amounts or change the amount to get around this.";
@@ -127397,15 +127414,8 @@ ${canonical5}`;
127397
127414
  const one = readBalance(store);
127398
127415
  const refunds = [one?.breakdown?.refundsInFlightAtomic, one?.breakdown?.refundsNotCertainAtomic].some((atomic4) => /^0*[1-9]/.test(String(atomic4 ?? "")));
127399
127416
  const known = knownEmptyBalance(store, { maxAgeMs: balanceNow(store)?.report?.status === "empty" ? void 0 : maxAgeMs });
127400
- const last = lastProofRecovery(store);
127401
- const recovered = last?.pool === store.state.pool && last.recovery?.narrowedByDigests !== true && Array.isArray(last.recovery?.recovered) ? last.recovery.recovered : void 0;
127402
- if (recovered) {
127403
- const unspent = recovered.filter((entry) => entry?.spendStatus === "unspent");
127404
- return {
127405
- receivedOnly: !unspent.some((entry) => entry.kind === "account") && unspent.some((entry) => entry.kind === "note"),
127406
- empty: !recovered.some((entry) => entry?.spendStatus === "unspent" || entry?.spendStatus === "succession-movable") && !refunds && known
127407
- };
127408
- }
127417
+ const walk = proofWalkHolds(store);
127418
+ if (walk) return { receivedOnly: walk.receivedOnly, empty: walk.none && !refunds && known };
127409
127419
  const receivedOnly = one?.receivedOnly === true;
127410
127420
  return { receivedOnly, empty: !receivedOnly && !refunds && known };
127411
127421
  } catch {
@@ -127422,7 +127432,15 @@ ${canonical5}`;
127422
127432
  { requestId, paid: false, balanceEmpty: true, ...publicAtomic ? { publicAtomic } : {} }
127423
127433
  );
127424
127434
  }
127425
- const zeroBeforeAsk = (tool, requestId) => knownZeroBalance({ maxAgeMs: INBOUND_REFRESH_AGE_MS }).empty ? zeroBalanceStop({ tool, requestId, same: tool === "x402_pay" ? "the same url, method, headers, and body" : "the same arguments" }) : void 0;
127435
+ async function knownZeroFresh() {
127436
+ if (knownZeroBalance({ maxAgeMs: INBOUND_REFRESH_AGE_MS }).empty) return true;
127437
+ if (!knownZeroBalance().empty || refreshFailedAt && Date.now() - refreshFailedAt < REFRESH_RETRY_MS) return false;
127438
+ const outcome = await Promise.race([refreshShared().then(() => "done", () => "failed"), sleep2(balanceRefreshWaitMs).then(() => "waiting")]);
127439
+ return outcome === "done" && knownZeroBalance({ maxAgeMs: INBOUND_REFRESH_AGE_MS }).empty;
127440
+ }
127441
+ const zeroBeforeAsk = async (tool, requestId) => await knownZeroFresh() ? zeroBalanceStop({ tool, requestId, same: tool === "x402_pay" ? "the same url, method, headers, and body" : "the same arguments" }) : void 0;
127442
+ const floatSplitOf = (error) => ATOMIC_TEXT.test(String(error?.priceAtomic ?? "")) && ATOMIC_TEXT.test(String(error?.feeAtomic ?? "")) ? { priceAtomic: String(error.priceAtomic), feeAtomic: String(error.feeAtomic) } : void 0;
127443
+ const splitWords = (split4, price) => split4 ? ` (${price} ${usdcText3(split4.priceAtomic)} USDC plus Shinjuku's fee ${usdcText3(split4.feeAtomic)} USDC)` : "";
127426
127444
  async function askLimit2({ requestId, url, numbers, calledAt, message }) {
127427
127445
  const answer = await confirmOnce({ message, waitMs: budgetLeft(calledAt) });
127428
127446
  if (!answer.ok) {
@@ -127485,7 +127503,7 @@ ${canonical5}`;
127485
127503
  async function payCall({ target, request, argument: argument2, requestId, given, calledAt, progress: progress3, canProgress, signal }) {
127486
127504
  let cap = policy.resolvePaymentCap(argument2, { requestId });
127487
127505
  if (!cap.ok && cap.error === "mcp_cap_argument_above_launch_cap") {
127488
- const zero = zeroBeforeAsk("x402_pay", requestId);
127506
+ const zero = await zeroBeforeAsk("x402_pay", requestId);
127489
127507
  if (zero) return zero;
127490
127508
  const numbers = { totalAtomic: String(argument2), capAtomic: policy.limits.maxPaymentAtomic };
127491
127509
  const asked = await askLimit2({
@@ -127595,21 +127613,22 @@ ${canonical5}`;
127595
127613
  const launch = policy.limits.maxPaymentAtomic;
127596
127614
  const total = code2 === "p03_float_over_maximum" ? ATOMIC_TEXT.test(String(error?.paidAtomic ?? "")) ? String(error.paidAtomic) : void 0 : capNumbers(error?.refusal).totalAtomic;
127597
127615
  if (total !== void 0 && BigInt(total) > BigInt(launch) && BigInt(maxNow) === BigInt(launch)) {
127598
- const zero = zeroBeforeAsk("x402_pay", requestId);
127616
+ const zero = await zeroBeforeAsk("x402_pay", requestId);
127599
127617
  if (zero) return zero;
127600
127618
  const numbers = { totalAtomic: total, capAtomic: launch };
127619
+ const split4 = floatSplitOf(code2 === "p03_float_over_maximum" ? error : error?.refusal);
127601
127620
  const asked = await askLimit2({
127602
127621
  requestId,
127603
127622
  url: target.url,
127604
127623
  numbers,
127605
127624
  calledAt,
127606
- message: `This costs ${usdcText3(total)} USDC. Your ${payCapName(launch)} is ${usdcText3(launch)} USDC. Allow it once?`
127625
+ message: `This costs ${usdcText3(total)} USDC${splitWords(split4, "the price")}. Your ${payCapName(launch)} is ${usdcText3(launch)} USDC. Allow it once?`
127607
127626
  });
127608
127627
  if (asked.ok) {
127609
127628
  maxNow = total;
127610
127629
  continue;
127611
127630
  }
127612
- if (asked.why !== "unsupported") return notAllowed(asked.why, { tool: "x402_pay", requestId, numbers });
127631
+ if (asked.why !== "unsupported") return notAllowed(asked.why, { tool: "x402_pay", requestId, numbers }, split4 ?? {});
127613
127632
  askUnshown = true;
127614
127633
  }
127615
127634
  }
@@ -128426,6 +128445,7 @@ ${canonical5}`;
128426
128445
  };
128427
128446
  const positive2 = (atomic4) => /^[1-9][0-9]*$/.test(String(atomic4 ?? ""));
128428
128447
  let refresh = {};
128448
+ let backgroundWalked = false;
128429
128449
  const recentlyFailed = refreshFailedAt && Date.now() - refreshFailedAt < REFRESH_RETRY_MS && !refreshRun;
128430
128450
  if (report.split?.shieldedAtomic != null && report.status === "stale") {
128431
128451
  if (!recentlyFailed && (!finalityWait || refreshDeferred)) refreshShared().catch(() => {
@@ -128443,7 +128463,9 @@ ${canonical5}`;
128443
128463
  refresh = { refreshed: true };
128444
128464
  } else refresh = { refreshing: true, refreshReason: "refund_check" };
128445
128465
  } else if (report.split?.shieldedAtomic != null && !recentlyFailed && !finalityWait && !refreshRun && (report.detail?.lastRefresh?.ageSeconds ?? 0) * 1e3 >= INBOUND_REFRESH_AGE_MS) {
128446
- refreshShared({ background: true }).catch(() => {
128466
+ refreshShared({ background: true }).then(() => {
128467
+ backgroundWalked = true;
128468
+ }, () => {
128447
128469
  });
128448
128470
  } else if (report.split?.shieldedAtomic == null && recentlyFailed) {
128449
128471
  refresh = { refreshed: false, refreshError: refreshFailedCode ?? "mcp_refresh_failed" };
@@ -128505,6 +128527,13 @@ ${canonical5}`;
128505
128527
  });
128506
128528
  const answered2 = await Promise.race([publicRead, answerWindow]);
128507
128529
  if (tokensAnswered.reading) await Promise.race([tokensRead, answerWindow]);
128530
+ if (backgroundWalked) {
128531
+ try {
128532
+ store = session.openStore();
128533
+ } catch {
128534
+ }
128535
+ reread("refresh");
128536
+ }
128508
128537
  mark("balance-public-read", answered2.reading ? "missed" : answered2.read ? "answered" : "failed");
128509
128538
  mark("balance-tokens-read", tokensAnswered.reading ? "missed" : tokensAnswered.rows ? "answered" : "failed");
128510
128539
  let ownTokens;
@@ -131143,7 +131172,7 @@ ${canonical5}`;
131143
131172
  const capNext = (detail) => `Nothing was moved. Tell your owner: ${detail}. ${capRaiseText(spec.capFlag)} Then call ${spec.tool} again.`;
131144
131173
  if (max !== void 0 && amount > max) {
131145
131174
  const detail = `${record ? `the recorded ${spec.noun} of request_id "${request.requestId}" is not finished; its ` : ""}amount_atomic ${amount} (${usdcText3(amount)} USDC) is above the ${capName(spec.capFlag)} of ${usdcFlagText(max)} USDC`;
131146
- const empty = kind === "unshield" && !record && knownZeroBalance({ maxAgeMs: INBOUND_REFRESH_AGE_MS }).empty ? zeroBalanceFacts() : void 0;
131175
+ const empty = kind === "unshield" && !record && await knownZeroFresh() ? zeroBalanceFacts() : void 0;
131147
131176
  if (empty && !empty.depositInFlight && !empty.heldUnknown) {
131148
131177
  return refuse12(
131149
131178
  "mcp_unshield_balance_empty",
@@ -133876,7 +133905,7 @@ ${canonical5}`;
133876
133905
  const facts = { model: args.model, maxTokens: args.max_tokens, ceilingAtomic: ceiling.toString(), ceiling: usd(ceiling) };
133877
133906
  let cap = policy.resolvePaymentCap(argument2, { requestId });
133878
133907
  if (!cap.ok && cap.error === "mcp_cap_argument_above_launch_cap") {
133879
- const zero = zeroBeforeAsk("inference_chat", requestId);
133908
+ const zero = await zeroBeforeAsk("inference_chat", requestId);
133880
133909
  if (zero) return zero;
133881
133910
  const numbers = { totalAtomic: String(argument2), capAtomic: launch };
133882
133911
  const asked2 = await askLimit2({
@@ -133926,7 +133955,7 @@ ${canonical5}`;
133926
133955
  }
133927
133956
  );
133928
133957
  }
133929
- const zero = zeroBeforeAsk("inference_chat", requestId);
133958
+ const zero = await zeroBeforeAsk("inference_chat", requestId);
133930
133959
  if (zero) return zero;
133931
133960
  askedLimit = true;
133932
133961
  const numbers = { totalAtomic: ceiling.toString(), capAtomic: launch };
@@ -134008,22 +134037,23 @@ ${canonical5}`;
134008
134037
  const total = ATOMIC_TEXT.test(String(error?.paidAtomic ?? "")) ? String(error.paidAtomic) : void 0;
134009
134038
  const lifted = BigInt(narrowed) > BigInt(launch);
134010
134039
  if (total !== void 0 && BigInt(total) > BigInt(launch) && BigInt(narrowed) === BigInt(launch) && !askedLimit) {
134011
- const zero = zeroBeforeAsk("inference_chat", requestId);
134040
+ const zero = await zeroBeforeAsk("inference_chat", requestId);
134012
134041
  if (zero) return zero;
134013
134042
  askedLimit = true;
134014
134043
  const numbers = { totalAtomic: total, capAtomic: launch };
134044
+ const split4 = floatSplitOf(error);
134015
134045
  const asked2 = await askLimit2({
134016
134046
  requestId,
134017
134047
  url: target.url,
134018
134048
  numbers,
134019
134049
  calledAt,
134020
- message: `This costs ${usdcText3(total)} USDC with the fee. Your ${payCapName(launch)} is ${usdcText3(launch)} USDC. Allow it once?`
134050
+ message: `This costs ${usdcText3(total)} USDC${split4 ? splitWords(split4, "the AI provider's price") : " with the fee"}. Your ${payCapName(launch)} is ${usdcText3(launch)} USDC. Allow it once?`
134021
134051
  });
134022
134052
  if (asked2.ok) {
134023
134053
  narrowed = total;
134024
134054
  continue;
134025
134055
  }
134026
- if (asked2.why !== "unsupported") return notAllowed(asked2.why, { tool: "inference_chat", requestId, numbers }, facts);
134056
+ if (asked2.why !== "unsupported") return notAllowed(asked2.why, { tool: "inference_chat", requestId, numbers }, { ...facts, ...split4 });
134027
134057
  return refuse12("p03_float_over_maximum", floatRefusal(error)[1], limitNext(numbers), { requestId, paid: false, ...numbers, ...facts });
134028
134058
  }
134029
134059
  if (total !== void 0 && lifted) {
@@ -135253,8 +135283,9 @@ var init_tools = __esm({
135253
135283
  JOIN_RETRY_BACKOFF_MS = Object.freeze([6e4, 2 * 6e4, 4 * 6e4, 8 * 6e4, 16 * 6e4, 30 * 6e4, 30 * 6e4]);
135254
135284
  WALLET_CAP_FIX = {
135255
135285
  // Functions: the command name is read at answer time (cli/commandName.mjs checks PATH then, 0.3.98).
135256
- wallet_spend_refused_per_payment_cap_exceeded: () => `the wallet file's per-payment cap; the owner removes it with ${terminalCommand2("limits --pool <pool> --max-payment none", { code: true })} (or a higher number in place of none)`,
135257
- wallet_spend_refused_cumulative_cap_exceeded: () => `the wallet file's total budget; the owner removes it with ${terminalCommand2("limits --pool <pool> --max-cumulative none", { code: true })} (or a higher number in place of none)`
135286
+ // The plain limits step, never a pool id or "removes it" (mcp6 live pass of npm 0.3.122, 2026-10-28; the CLI hint too).
135287
+ wallet_spend_refused_per_payment_cap_exceeded: () => `the limit for one payment; the owner changes it with ${terminalCommand2("limits", { code: true })} in a terminal (it shows the limits and asks for new ones)`,
135288
+ wallet_spend_refused_cumulative_cap_exceeded: () => `the limit for all payments together; the owner changes it with ${terminalCommand2("limits", { code: true })} in a terminal (it shows the limits and what was paid, and asks for new ones)`
135258
135289
  };
135259
135290
  MCP_CAP_FIX = {
135260
135291
  mcp_session_cap_exceeded: () => ` This is the 24-hour payment limit. ${capRaiseText("--max-session")} ${cheaperSellerText}`,
@@ -135299,8 +135330,8 @@ var init_tools = __esm({
135299
135330
  "p03_float_refund_pending"
135300
135331
  ]);
135301
135332
  FLOAT_PRIVATE_LEG = "a private payment, so this answer has no transaction ID; wallet_receipts lists it";
135302
- SELLER_ONLY_HERE = "Never reach a seller URL outside this wallet (no curl, browser, fetch or DNS lookup of your own): over Tor that would show the user's IP address to the site.";
135303
- outsideWalletRule = (what) => `Never reach ${what} outside this wallet (no curl, browser, fetch or DNS lookup of your own)` + (inTorRun() ? ": this wallet reaches it over Tor, and a request of your own would show the user's IP address" : "");
135333
+ SELLER_ONLY_HERE = "Reach a seller URL or its domain only with this wallet's tools, never yourself (no curl, browser, fetch, ping, DNS or DNS-over-HTTPS lookup), also when the user asks for no Tor: that would show the user's IP address to the site or to a DNS company.";
135334
+ outsideWalletRule = (what) => `Never reach ${what} or its domain outside this wallet (no curl, browser, fetch, ping, DNS or DNS-over-HTTPS lookup of your own), also when the user asks for no Tor` + (inTorRun() ? ": this wallet reaches it over Tor, and a lookup of your own would show the user's IP address" : "");
135304
135335
  proxyStartStep = (tor) => tor ? `Make sure Tor is running (start it, or run ${terminalCommand2("setup")} again)` : "Tell the user to make sure the private connection this wallet runs through (its proxy) is running";
135305
135336
  MONEY_ID2 = /^[A-Za-z0-9_-]{1,44}$/;
135306
135337
  toRecordId = (requestId) => requestId === "" ? "" : recordId(String(requestId));
@@ -136911,7 +136942,7 @@ var init_stdioServer = __esm({
136911
136942
  SUPPORTED_PROTOCOL_VERSIONS = Object.freeze(["2025-06-18", "2025-03-26", "2024-11-05"]);
136912
136943
  MAX_LINE_BYTES = 4 * 1024 * 1024;
136913
136944
  POSITIVE_ATOMIC7 = /^[1-9][0-9]{0,30}$/;
136914
- INSTRUCTIONS = `A self-custody Shinjuku Shield wallet on this machine; no tool takes or returns its keys or passphrase. Each answer's say is one plain sentence for the user; other fields hold the numbers. Never tell the user a tool, field, code or protocol name (x402, MCP) unless told to. Map the user's plain request to one tool: "what is my balance" -> wallet_balance (safe at any time); "add money" / "deposit" / "move USDC in from Phantom or an exchange" -> wallet_add_funds (a one-time address; the next wallet_balance after the USDC arrives makes it private, up to 5 USDC private); "shield the USDC on this wallet's own address" -> wallet_shield; "stop" / "cancel" -> wallet_cancel with the request_id of what to stop; "pay this URL" -> x402_pay (no preview needed); "what does this URL cost" -> x402_preview (only when asked); "find a paid API for X" -> x402_discover, then x402_pay on the url it found; "send 2 USDC to <address>" -> wallet_unshield; "show my payments" -> wallet_receipts; "send another token" -> wallet_transfer_token; "ask an AI model" / "which AI models" -> inference_chat (each answer paid privately; with no prompt it lists the models and prices); "give my other AI app a private AI" -> inference_server (a local OpenAI-compatible URL and key for that app, each answer paid privately). wallet_balance answers ONE balance (balanceAtomic), and x402_pay pays any paid URL from it (a seller that cannot take a private payment is paid through Shinjuku: max_payment covers amountAtomic, fee included). Fields ending in Atomic are atomic units (1000000 = 1 USDC); tell the user USDC. The wallet does its own upkeep (no user command). A shield, add-funds or unshield call can run for minutes: call again with the SAME request_id as next says. Pass your own request_id to x402_pay: the same request_id never pays or moves money twice (a code ending in _retry_same_request: call again with it). A wallet_unshield send to an address not approved ahead asks the user to confirm first. x402_pay never pays above the owner's limits (one payment; any 24 hours); with none, the balance is the only bound. Never claim a payment happened unless the answer has a transaction. Privacy: the chain does not show which wallet paid, but this app and its model provider see every URL, body, price and paid answer you handle; reach a seller only through these tools, never by your own curl, browser or DNS lookup (it shows the user's IP address). When an item of an answer's poolSwitch.items[] has tellUser true, tell the user its message once, in plain words; the wallet moves the balance by itself.`;
136945
+ INSTRUCTIONS = `A self-custody Shinjuku Shield wallet on this machine; no tool takes or returns its keys or passphrase. Each answer's say is one plain sentence for the user; other fields hold the numbers. Never tell the user a tool, field, code or protocol name (x402, MCP) unless told to. Map the user's plain request to one tool: "what is my balance" -> wallet_balance (safe at any time); "add money" / "deposit" / "move USDC in from Phantom or an exchange" -> wallet_add_funds (a one-time address; the next wallet_balance after the USDC arrives makes it private, up to 5 USDC private); "shield the USDC on this wallet's own address" -> wallet_shield; "stop" / "cancel" -> wallet_cancel with the request_id of what to stop; "pay this URL" -> x402_pay (no preview needed); "what does this URL cost" -> x402_preview (only when asked); "find a paid API for X" -> x402_discover, then x402_pay on the url it found; "send 2 USDC to <address>" -> wallet_unshield; "show my payments" -> wallet_receipts; "send another token" -> wallet_transfer_token; "ask an AI model" / "which AI models" -> inference_chat (with no prompt it lists the models and prices); "give my other AI app a private AI" -> inference_server (a local OpenAI-compatible URL and key for that app). wallet_balance answers ONE balance (balanceAtomic), and x402_pay pays any paid URL from it (a seller that cannot take a private payment is paid through Shinjuku: max_payment covers amountAtomic, fee included). Fields ending in Atomic are atomic units (1000000 = 1 USDC); tell the user USDC. The wallet does its own upkeep (no user command). A shield, add-funds or unshield call can run for minutes: call again with the SAME request_id as next says. Pass your own request_id to x402_pay: the same request_id never pays or moves money twice (a code ending in _retry_same_request: call again with it). A wallet_unshield send to an address not approved ahead asks the user to confirm first. x402_pay never pays above the owner's limits (one payment; any 24 hours); with none, the balance is the only bound. Never claim a payment happened unless the answer has a transaction. Privacy: the chain does not show which wallet paid, but this app and its model provider see every URL, body, price and paid answer you handle; reach a seller or its domain only through these tools, never yourself (no curl, browser or DNS lookup, DNS-over-HTTPS too), also when the user asks for no Tor: it shows the user's IP address to the site or a DNS company. When an item of an answer's poolSwitch.items[] has tellUser true, tell the user its message once, in plain words; the wallet moves the balance by itself.`;
136915
136946
  MCP_LOG_LEVELS = Object.freeze(["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"]);
136916
136947
  POOL_SWITCH_LOG_LEVEL = "info";
136917
136948
  validId = (id) => id === null || typeof id === "string" || typeof id === "number" && Number.isFinite(id);
@@ -136947,7 +136978,7 @@ var init_stdioServer = __esm({
136947
136978
  MCP_CLOSE_UNREADABLE_BOUND_MS = 6e4;
136948
136979
  MCP_CLOSE_POLL_MS = 500;
136949
136980
  closeHistoryBusy = (server) => () => compactHistoryReadsRunning() > 0 || memoReadsAheadRunning() > 0 || server.refreshOpen?.() === true;
136950
- SETUP_INSTRUCTIONS = `This Shinjuku Shield wallet is NOT SET UP on this machine yet: every money tool answers wallet_not_set_up. When the user wants to pay, check a balance, or add money, call shinjuku_setup: it asks the user to confirm in this app, creates the wallet, and downloads the proof tools (minutes: call again as next says). At stage done the wallet tools are live in this server. After setup: ${INSTRUCTIONS}`;
136981
+ SETUP_INSTRUCTIONS = `This Shinjuku Shield wallet is NOT SET UP yet: every money tool answers wallet_not_set_up. When the user wants to pay, check a balance, or add money, call shinjuku_setup: it asks the user to confirm, creates the wallet and downloads the proof tools (minutes: call again as next says). At stage done the wallet tools work. After setup: ${INSTRUCTIONS}`;
136951
136982
  TOR_RELAY_READY_MS = 18e4;
136952
136983
  RELAY_INIT_ID = "shinjuku-wallet-relay-initialize";
136953
136984
  runMcp = runMcpServer;
@@ -137019,11 +137050,12 @@ function errorBody(error, restartStep, leastAtomic = 0n) {
137019
137050
  } } };
137020
137051
  }
137021
137052
  if (code2 === "p03_merchant_respend_no_spendable_account") {
137053
+ const why = error?.knownZero === true ? "your private balance is 0 USDC, so there is nothing to pay with yet" : "this wallet has nothing it can pay with yet (its private balance is 0, or it holds only payments it received, which can pay only after you add money once)";
137022
137054
  return { status: 402, body: { error: {
137023
137055
  type: OPENAI_TYPE.quota,
137024
137056
  param: null,
137025
137057
  code: OPENAI_TYPE.quota,
137026
- message: `nothing was paid: this wallet has nothing it can pay with yet (its private balance is 0, or it holds only payments it received, which can pay only after you add money once). Add money first: run ${commandLine("add-funds")} in a terminal (it asks the amount, from 0.01 USDC), then send the request again. This server pays from the new balance once add-funds says ready; nothing to restart`
137058
+ message: `nothing was paid: ${why}. Add money first: run ${commandLine("add-funds")} in a terminal (it asks the amount, from 0.01 USDC), then send the request again. This server pays from the new balance once add-funds says ready; nothing to restart`
137027
137059
  } } };
137028
137060
  }
137029
137061
  if (INSUFFICIENT_CODE.test(code2 ?? "")) {
@@ -137263,7 +137295,7 @@ function createInferenceServer({
137263
137295
  } catch {
137264
137296
  empty = false;
137265
137297
  }
137266
- if (empty) throw new Error("p03_merchant_respend_no_spendable_account");
137298
+ if (empty) throw Object.assign(new Error("p03_merchant_respend_no_spendable_account"), { knownZero: true });
137267
137299
  let result;
137268
137300
  try {
137269
137301
  result = await inference.inferenceChat({
@@ -144677,7 +144709,15 @@ async function pocketFillGate(args, values, deps, io) {
144677
144709
  return index < 0 ? args : [...args.slice(0, index + 1), target, ...args.slice(index + 2)];
144678
144710
  }
144679
144711
  async function runCurl(values, deps) {
144680
- if (values.has("--max-payment")) return runCurlPaid(values, deps);
144712
+ if (values.has("--max-payment")) {
144713
+ const aboveLimits = capAboveLimitsLine(
144714
+ { maxPaymentAtomic: values.get("--max-payment") },
144715
+ cliUserLimits(values, deps),
144716
+ { again: `the same ${cli2()} curl command` }
144717
+ );
144718
+ if (aboveLimits) throw new PublicFailure(`${CAP_ABOVE_LIMIT_CODE}: ${aboveLimits}`);
144719
+ return runCurlPaid(values, deps);
144720
+ }
144681
144721
  if (!(deps.stdinIsTTY() && deps.stdoutIsTTY?.() === true)) {
144682
144722
  throw new UsageError("curl is missing --max-payment <usdc>: the most this request may pay, in USDC (0.02 = 2 cents); in a terminal, curl shows the seller's price and asks instead", COMMAND_BY_NAME.get("curl"));
144683
144723
  }
@@ -144948,7 +144988,7 @@ function inferPreflight(inference, values, prompt, deps) {
144948
144988
  const least = floor + SHINJUKU_FEE_ATOMIC;
144949
144989
  const fits = (bound) => bound === void 0 || least <= BigInt(bound);
144950
144990
  const lowerTokens = ceiling !== void 0 && ceiling > floor && fits(values.get("--max-payment")) && fits(limits?.maxPaymentAtomic) && fits(limits?.maxSessionAtomic) && fits(room?.day?.leftAtomic) && fits(room?.total?.leftAtomic);
144951
- throw new PublicFailure(`${CEILING_OVER_CAP_CODE}: the AI provider's price for this request may be up to ${usdcOr(worst)} (${ceiling === void 0 ? "its minimum for one request" : `ceiling ${usdcOr(ceiling)}, minimum ${usdcOr(floor)}`}), and with Shinjuku's ${usdcOr(SHINJUKU_FEE_ATOMIC)} fee up to ${usdcOr(needed)} in all; that is above --max-payment ${usdcFlagText(values.get("--max-payment"))} (${usdcOr(values.get("--max-payment"))}); nothing was paid. ${overLimit ?? `Raise --max-payment to at least ${usdcFlagText(needed)} (${usdcOr(needed)})`}${lowerTokens ? ", or lower --max-tokens" : ""}. The cap is only a limit, not the price: the call pays the AI provider's price for its tokens plus the 0.001 USDC fee, and a larger cap never pays more`);
144991
+ throw new PublicFailure(`${CEILING_OVER_CAP_CODE}: the AI provider's price for this request may be up to ${usdcOr(worst)} (${ceiling === void 0 ? "its minimum for one request" : `ceiling ${usdcOr(ceiling)}, minimum ${usdcOr(floor)}`}), and with Shinjuku's ${usdcOr(SHINJUKU_FEE_ATOMIC)} fee up to ${usdcOr(needed)} in all; that is above --max-payment ${usdcFlagText(values.get("--max-payment"))} USDC; nothing was paid. ${overLimit ?? `Raise --max-payment to at least ${usdcFlagText(needed)} USDC`}${lowerTokens ? ", or lower --max-tokens" : ""}. The cap is only a limit, not the price: the call pays the AI provider's price for its tokens plus the 0.001 USDC fee, and a larger cap never pays more`);
144952
144992
  }
144953
144993
  return { model, maxTokens, ceiling, worst };
144954
144994
  }
@@ -144997,7 +145037,7 @@ async function runInfer(values, deps) {
144997
145037
  try {
144998
145038
  assertSessionPool(values, session.pool);
144999
145039
  if (!quiet) {
145000
- io.err(`model ${model}: this request may pay the AI provider up to ${usdcOr(worst)}, plus Shinjuku's fee, and never more than --max-payment ${usdcFlagText(values.get("--max-payment"))} (${usdcOr(values.get("--max-payment"))}) in all. ${inference.INFERENCE_NOTICE ?? `${INFER_COST_LINE}.`}
145040
+ io.err(`model ${model}: this request may pay the AI provider up to ${usdcOr(worst)}, plus Shinjuku's fee, and never more than --max-payment ${usdcFlagText(values.get("--max-payment"))} USDC in all. ${inference.INFERENCE_NOTICE ?? `${INFER_COST_LINE}.`}
145001
145041
  `);
145002
145042
  io.err(`request-id ${requestId}${given ? "" : ` (if this run stops, rerun with --request-id ${requestId}: it never pays twice)`}
145003
145043
  `);
@@ -145143,7 +145183,15 @@ async function runInferServe(values, deps) {
145143
145183
  try {
145144
145184
  return await (deps.payAndFetch ?? payAndFetch)(session, url, init, { ...options, memoryOnly: true });
145145
145185
  } catch (error) {
145146
- throw inferFailure(error);
145186
+ const failure2 = inferFailure(error);
145187
+ if (localErrorCodes(error).includes("p03_merchant_respend_no_spendable_account")) {
145188
+ try {
145189
+ const store = session.openStore();
145190
+ if (proofWalkHolds(store)?.none === true && knownEmptyBalance(store)) failure2.knownZero = true;
145191
+ } catch {
145192
+ }
145193
+ }
145194
+ throw failure2;
145147
145195
  }
145148
145196
  };
145149
145197
  server = createInferenceServer2({
@@ -149799,7 +149847,6 @@ function serversOf(command, values, env = {}) {
149799
149847
  if (command.name.startsWith("privacy-cash ") && (values?.get("--via") ?? "sdk") !== "local") names.push("Privacy Cash's server (--via sdk)");
149800
149848
  return names.length > 1 ? `${names.slice(0, -1).join(", ")} and ${names.at(-1)}` : names[0];
149801
149849
  }
149802
- var capWallet = (values, pool2) => values?.has("--wallet") ? `--wallet ${values.get("--wallet")} --passphrase-file <file>` : `--pool ${pool2 ?? "<pool>"}`;
149803
149850
  function runBalanceParts(values, deps) {
149804
149851
  try {
149805
149852
  const walletPath2 = values.has("--wallet") ? resolve32(values.get("--wallet")) : deps.walletPath(values.get("--pool"));
@@ -149825,6 +149872,7 @@ function insufficientWords(cause, parts) {
149825
149872
  }
149826
149873
  }
149827
149874
  }
149875
+ var CAP_REFUSAL_CODES = ["spend_payment_cap_exceeded", "wallet_spend_refused_per_payment_cap_exceeded", "wallet_spend_refused_cumulative_cap_exceeded"];
149828
149876
  function failureHint(command, reason, deps, values, floatError) {
149829
149877
  const pool2 = values?.get("--pool");
149830
149878
  const historyHint = historyRpcHint(reason, { signsNothing: signsNothing(command, values) });
@@ -149903,7 +149951,7 @@ function failureHint(command, reason, deps, values, floatError) {
149903
149951
  if (/spend_payment_cap_exceeded|mcp_cap_argument_above_launch_cap/.test(reason)) {
149904
149952
  const total = floatError?.refusal?.totalAtomic;
149905
149953
  const over = /^[1-9][0-9]{0,30}$/.test(String(total ?? "")) ? cliOverLimitStep(values, deps, BigInt(total), { command }) : void 0;
149906
- return over ?? "nothing was paid: the seller's price (the line names it) is above --max-payment. If you agree to that price, rerun with a --max-payment at least as high; else pay a cheaper seller";
149954
+ return over ?? "if you agree to that price, rerun with a --max-payment at least as high; else pay a cheaper seller";
149907
149955
  }
149908
149956
  if (/spend_host_day_cap_exceeded/.test(reason)) {
149909
149957
  return "nothing was paid: this seller host would pass --max-per-host-day in the last 24 hours (unfinished payments count). Rerun later, or with a higher --max-per-host-day";
@@ -149940,11 +149988,15 @@ function failureHint(command, reason, deps, values, floatError) {
149940
149988
  if (/fetch_session_closed/.test(reason)) return "the payer session closed before this payment started; nothing new was paid. Rerun the same command (same --request-id)";
149941
149989
  if (/curl_binary_to_terminal/.test(reason)) return "add -o <file> with the same --request-id: the answer goes to that file, and a paid request is replayed, never paid twice";
149942
149990
  if (/wallet_passphrase_file_unreadable/.test(reason)) return `pass a --passphrase-file you can read (the passphrase alone in it), or export ${PASSPHRASE_ENV2}; nothing was sent`;
149943
- if (/wallet_spend_refused_per_payment_cap_exceeded/.test(reason)) {
149944
- return `nothing was paid: the price is above this wallet's limit for one payment (${cli2()} limits shows it). To remove the limit: ${cli2()} limits ${capWallet(values, pool2)} --max-payment none (or a higher number), then rerun the payment`;
149945
- }
149946
- if (/wallet_spend_refused_cumulative_cap_exceeded/.test(reason)) {
149947
- return `nothing was paid: this payment would pass the wallet's total payment budget (--max-cumulative; ${cli2()} limits shows it with usedAtomic). To remove the budget: ${cli2()} limits ${capWallet(values, pool2)} --max-cumulative none (or a higher number), then rerun the payment`;
149991
+ if (/wallet_spend_refused_(per_payment|cumulative)_cap_exceeded/.test(reason)) {
149992
+ const one = /wallet_spend_refused_per_payment/.test(reason);
149993
+ let limit;
149994
+ try {
149995
+ limit = one ? cliUserLimits(values, deps)?.maxPaymentAtomic : cliLimitRoom(values, deps)?.total?.limitAtomic;
149996
+ } catch {
149997
+ limit = void 0;
149998
+ }
149999
+ return `nothing was paid: ${one ? "this payment is above your limit for one payment" : "this payment would pass your limit for all payments together"}${limit === void 0 ? "" : ` (${usdcOr(limit)})`}. Run ${cli2()} limits: it shows your limits${one ? "" : " and what you paid so far"} and asks for new ones. Then run the same command again`;
149948
150000
  }
149949
150001
  if (/wallet_spend_refused_/.test(reason)) return "nothing was paid: the seller's price is not a positive amount; do not pay this seller";
149950
150002
  if (/p03_resource_payment_confidential_(retired|use_laneb_pay_url)/.test(reason)) {
@@ -150720,7 +150772,7 @@ This copy: ${walletVersionLine(deps.walletVersion())}
150720
150772
  const reason = failureReason(command, error, values);
150721
150773
  const codes = failureCodes(error, reason);
150722
150774
  writeRunResult(deps, command, 1, error, codes);
150723
- const plainCode = [NOT_SET_UP_CODE, EMPTY_BALANCE_CODE, OVER_LIMITS_CODE, CEILING_OVER_CAP_CODE].find((code2) => reason.startsWith(`${code2}: `));
150775
+ const plainCode = [NOT_SET_UP_CODE, EMPTY_BALANCE_CODE, OVER_LIMITS_CODE, CEILING_OVER_CAP_CODE, CAP_ABOVE_LIMIT_CODE].find((code2) => reason.startsWith(`${code2}: `));
150724
150776
  if (plainCode) {
150725
150777
  const plain = reason.slice(plainCode.length + 2);
150726
150778
  io.err(`${plain[0].toUpperCase()}${plain.slice(1)}
@@ -150759,6 +150811,13 @@ Next: fund that address, then rerun the same command; it continues where it stop
150759
150811
  }
150760
150812
  const floatError = { ...error?.cause && typeof error.cause === "object" ? error.cause : {}, ...error && typeof error === "object" ? error : {} };
150761
150813
  const hint = failureHint(command, codes.join(" "), deps, values, floatError);
150814
+ const capCode = CAP_REFUSAL_CODES.find((code2) => codes.includes(code2));
150815
+ if (capCode && hint) {
150816
+ const said = reason.startsWith(`${capCode}: `) ? reason.slice(capCode.length + 2) : "";
150817
+ io.err(`${[said, hint].filter(Boolean).map((text3) => `${text3[0].toUpperCase()}${text3.slice(1).replace(/[\s.;]+$/, "")}.`).join("\n")}
150818
+ `);
150819
+ return 1;
150820
+ }
150762
150821
  const blocking = error?.blockingRequestId ?? error?.cause?.blockingRequestId;
150763
150822
  const blockingLine = typeof blocking === "string" && /^[A-Za-z0-9._:-]{1,128}$/.test(blocking) ? `earlier payment: --request-id ${blocking}
150764
150823
  ` : "";