shinjuku-shield 0.3.234 → 0.3.235

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
@@ -8,7 +8,7 @@ web services and AI answers from your private balance, so the payment does
8
8
  not show who paid. It works inside your AI app (Claude, Cursor, Codex) and in
9
9
  a terminal. Only you hold the keys: they never leave your computer.
10
10
 
11
- This is version 0.3.234. The command is `shinjuku`.
11
+ This is version 0.3.235. The command is `shinjuku`.
12
12
 
13
13
  ## Set up
14
14
 
@@ -112,7 +112,7 @@ Add it yourself. The name of the wallet in your app is `shinjuku`.
112
112
  Claude Code:
113
113
 
114
114
  ```sh
115
- claude mcp add --scope user shinjuku -- npx -y --prefer-offline --no-audit --no-fund shinjuku-shield@0.3.234 mcp
115
+ claude mcp add --scope user shinjuku -- npx -y --prefer-offline --no-audit --no-fund shinjuku-shield@0.3.235 mcp
116
116
  ```
117
117
 
118
118
  `--prefer-offline` runs the copy of the wallet that npm saved. If npm has not saved it yet, that start asks
@@ -131,7 +131,7 @@ with the Releases table in
131
131
  Versions are published from GitHub Actions with npm provenance.
132
132
 
133
133
  `shinjuku-shield` is the package that holds the wallet. `shinjuku-shielded`
134
- 0.3.234, its older name, runs this package at the same version, so wallets
134
+ 0.3.235, its older name, runs this package at the same version, so wallets
135
135
  installed under that name keep updating. New installs use `shinjuku`.
136
136
 
137
137
  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": "a58340f4851a631086255680831eba498530769d1468b0add3478959b264ec15",
5
- "bytes": 10510312,
6
- "sourceCommit": "b0aa438771a15fa66313864cd06a94195f4c30c1",
4
+ "sha256": "fb00d7e7c7adfd309912987afd9b4e4e521126a34be1976c8a9f93ebcb456992",
5
+ "bytes": 10519290,
6
+ "sourceCommit": "8f971ec6fd168cf61678901d1986b4f5adc48ca8",
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",
@@ -1968,5 +1968,5 @@
1968
1968
  }
1969
1969
  ]
1970
1970
  },
1971
- "publishedAt": "2026-11-17T08:21:23.545Z"
1971
+ "publishedAt": "2026-11-17T09:06:59.893Z"
1972
1972
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "shinjuku-shield",
3
- "version": "0.3.234",
3
+ "version": "0.3.235",
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": "a58340f4",
7
- "shinjukuSha256": "a58340f4851a631086255680831eba498530769d1468b0add3478959b264ec15",
6
+ "shinjukuRelease": "fb00d7e7",
7
+ "shinjukuSha256": "fb00d7e7c7adfd309912987afd9b4e4e521126a34be1976c8a9f93ebcb456992",
8
8
  "license": "SEE LICENSE IN LICENSE.txt",
9
9
  "author": "Shinjuku Shield",
10
10
  "homepage": "https://github.com/ShinjukuStaition/shinjuku-shield#readme",
@@ -43614,9 +43614,9 @@ function readRpcFileLine(path) {
43614
43614
  return void 0;
43615
43615
  }
43616
43616
  }
43617
- function resolveRpcUrl2({ rpcFile, rpc, env = process.env, origin, readFile: readFile6, notice } = {}) {
43617
+ function resolveRpcUrl2({ rpcFile, rpc, env = process.env, origin, readFile: readFile8, notice } = {}) {
43618
43618
  if (rpcFile !== void 0) {
43619
- const url2 = (readFile6 ?? readRpcFileLine)(rpcFile);
43619
+ const url2 = (readFile8 ?? readRpcFileLine)(rpcFile);
43620
43620
  if (!url2) throw new Error("rpc_file_unreadable: --rpc-file could not be read, or its first line is empty");
43621
43621
  return { url: url2, source: "rpc-file" };
43622
43622
  }
@@ -68442,8 +68442,8 @@ function spendHeads(spendableAtomic, largestAtomic, change = {}, options = {}) {
68442
68442
  }
68443
68443
  if (receivedOnlyOf(change?.report)) {
68444
68444
  return [
68445
- `You received ${total}; a payment can use it after you add funds once, and unshield sends one received payment at a time`,
68446
- `You received ${total}, usable after one add-funds or sent one payment at a time by unshield`
68445
+ `You received ${total}; a payment can use it after you add funds once, and a send to an address moves one received payment at a time`,
68446
+ `You received ${total}, usable after one add-funds, or sendable one received payment at a time`
68447
68447
  ];
68448
68448
  }
68449
68449
  return [`You have ${total}; no payment can use it yet`, `You have ${total}, not ready to pay yet`];
@@ -124157,7 +124157,7 @@ function refusalSay(a, tool, again, npmVersion) {
124157
124157
  }
124158
124158
  if (code2 === "p03_merchant_respend_no_spendable_account" || code2 === PAY_BALANCE_EMPTY_CODE || code2 === PAY_NOTHING_SPENDABLE_CODE) {
124159
124159
  if (tool === "wallet_unshield") {
124160
- return "Nothing was sent. Check your balance until it shows the received payment, then try again. One unshield sends one received payment.";
124160
+ return "Nothing was sent. Check your balance until it shows the received payment, then try again. One send moves one received payment.";
124161
124161
  }
124162
124162
  if (a.balanceEmpty === true) {
124163
124163
  const canShield = a.canAddFunds !== false;
@@ -124176,7 +124176,7 @@ function refusalSay(a, tool, again, npmVersion) {
124176
124176
  return largest ? `Nothing was sent. One send moves one part of your balance; the largest is ${largest} USDC. Send that much or less.` : "Nothing was sent. One send moves one part of your balance, up to its amount. Send a smaller amount.";
124177
124177
  }
124178
124178
  if (code2 === "mcp_unshield_received_payment_gone") {
124179
- return "Nothing was sent. The received payment this unshield chose is no longer available. Check your balance, then start a new unshield.";
124179
+ return "Nothing was sent. The received payment this send chose is no longer available. Check your balance, then send again.";
124180
124180
  }
124181
124181
  if (tool === "wallet_unshield" && (code2 === "mcp_unshield_above_balance" || code2 === "mcp_unshield_wait_for_deposit" || INSUFFICIENT_CODE.test(code2) && a.maxAtomic !== void 0)) {
124182
124182
  const have = usdcText2(a.balanceAtomic) ?? "0";
@@ -124311,6 +124311,7 @@ function refusalSay(a, tool, again, npmVersion) {
124311
124311
  }
124312
124312
  if (code2 === "mcp_unshield_declined") return "Not sent. The send was not confirmed.";
124313
124313
  if (code2 === "mcp_setup_declined" && unshown || code2 === "mcp_setup_needs_terminal") {
124314
+ if (underHermesPlugin()) return "Not set up. This Hermes session cannot show the setup question. Open Hermes in a chat window and ask again.";
124314
124315
  const head = "Not set up. This app cannot show the setup question.";
124315
124316
  return [
124316
124317
  `${head} Run ${agentCommandLine("setup", { npmVersion })} in a terminal, then reconnect the wallet.`,
@@ -125134,10 +125135,10 @@ function build(a, tool, npmVersion) {
125134
125135
  const send3 = a.privateSend;
125135
125136
  const count3 = Array.isArray(send3?.parts) ? send3.parts.length : 0;
125136
125137
  if (count3 < 1 && a.sendState === "sending") {
125137
- const where = a.stage === "exit" ? "it may already be there" : "it is on its way";
125138
+ const stop2 = typeof a.exitTransaction === "string" && a.exitTransaction ? " and cannot be stopped" : "";
125138
125139
  return firstFit(
125139
- `Sending ${what} to ${a.to} now; ${where}. Ask me later for its transaction.`,
125140
- `Sending ${what} to ${a.to} now; ${where}.`
125140
+ `The send of ${what} to ${a.to} has started${stop2}; ask me later to show its transaction.`,
125141
+ `The send of ${what} to ${a.to} has started${stop2}.`
125141
125142
  );
125142
125143
  }
125143
125144
  if (count3 < 1) return `Sending ${what} privately to ${a.to}.`;
@@ -125407,12 +125408,12 @@ var init_say = __esm({
125407
125408
  shield: "your shield",
125408
125409
  elsewhere: "a deposit into your private balance",
125409
125410
  deposit: "a deposit into your private balance",
125410
- unshield: "your unshield",
125411
+ unshield: "your send to an address",
125411
125412
  send: "your private send",
125412
- unshield_finish: "your unshield as it finishes",
125413
+ unshield_finish: "your send to an address as it finishes",
125413
125414
  payment: "a payment",
125414
125415
  money_call: "a payment or a move of your money",
125415
- money_job: "a shield, unshield or send",
125416
+ money_job: "a shield or a send",
125416
125417
  account_join: "getting your balance ready to send",
125417
125418
  pool_move: "your balance moving after an upgrade",
125418
125419
  pool_switch: "your balance moving after an upgrade",
@@ -141852,6 +141853,7 @@ var init_earlyAnswer = __esm({
141852
141853
 
141853
141854
  // wallet/src/mcp/localAiTool.mjs
141854
141855
  import { dirname as dirname38, resolve as resolve28 } from "node:path";
141856
+ import { readFile as readFile6 } from "node:fs/promises";
141855
141857
  async function within(promise, ms) {
141856
141858
  let timer;
141857
141859
  const late2 = new Promise((resolveLate) => {
@@ -141965,6 +141967,7 @@ function createLocalAiTool({
141965
141967
  start = startLocalAiServer,
141966
141968
  status = localAiServerStatus,
141967
141969
  stop: stop2 = stopLocalAiServer,
141970
+ state: state2 = localAiServerState,
141968
141971
  answerWithinMs = EARLY_ANSWER_MS
141969
141972
  } = {}) {
141970
141973
  const walletPath2 = () => session?.walletPath;
@@ -142096,7 +142099,7 @@ function createLocalAiTool({
142096
142099
  stop: STOP_LINE
142097
142100
  });
142098
142101
  const emptyNext = (empty) => empty === "known" ? ` ${emptyNextText(canAddFunds)}` : empty === "unsure" ? ` ${unsureZeroNextText(canAddFunds)}` : "";
142099
- const pasteNext = (caps, note, empty = false) => `Tell the user to add an OpenAI-compatible provider in their agent app with base_url and the model ${EXAMPLE_MODEL} from paste, and to get the api key: "${keyUserLine(keySteps())}" Do not do that step yourself, and do not ask the user to paste the key here: it stays out of this chat. ${capsLine(caps)}${note ? ` ${note}.` : ""} Tell the user: to stop it, they ask you (you call inference_server with action "stop"); it stops when the computer restarts, and then they ask you to start it again (action "start"); the api key stays the same.` + tooLowNext(caps) + emptyNext(empty);
142102
+ const pasteNext = (caps, note, empty = false) => `It runs now (checked); do not call inference_server again to check it. ${BALANCE_SHOWS_LOCAL_AI} Tell the user to add an OpenAI-compatible provider in their agent app with base_url and the model ${EXAMPLE_MODEL} from paste, and to get the api key: "${keyUserLine(keySteps())}" Do not do that step yourself, and do not ask the user to paste the key here: it stays out of this chat. ${capsLine(caps)}${note ? ` ${note}.` : ""} Tell the user: to stop it, they ask you (you call inference_server with action "stop"); it stops when the computer restarts, and then they ask you to start it again (action "start"); the api key stays the same.` + tooLowNext(caps) + emptyNext(empty);
142100
142103
  const emptyBalance = () => {
142101
142104
  if (typeof session?.openStore !== "function") return false;
142102
142105
  try {
@@ -142135,14 +142138,14 @@ function createLocalAiTool({
142135
142138
  const baseUrl = read2?.baseUrl ?? localAiBaseUrl();
142136
142139
  const empty = emptyBalance();
142137
142140
  return json3({
142138
- say: empty === "known" ? emptySay("Your private AI address is starting.") : capTooLow(caps) ? capTooLowSay("Your private AI address is starting", caps) : "Your private AI address is starting: it connects through Tor and opens your wallet first. Ask for its status in about 30 seconds.",
142141
+ say: empty === "known" ? emptySay("Your private AI address is starting.") : capTooLow(caps) ? capTooLowSay("Your private AI address is starting", caps) : "Your private AI address is starting: it connects through Tor and opens your wallet first. Ask me in about 30 seconds whether it runs.",
142139
142142
  ok: true,
142140
142143
  state: "starting",
142141
142144
  running: false,
142142
142145
  ...facts(baseUrl, caps),
142143
142146
  ...read2?.logPath ? { logPath: read2.logPath } : {},
142144
142147
  detail: `it proves Tor and opens the wallet before it listens at ${baseUrl}; the start goes on in the background; this call paid nothing`,
142145
- next: `Call inference_server with action "status" in about 30 s: it says when the address listens, or why it did not start. Tell the user it is starting; the lines in paste are the ones to give their agent app, and they work once it runs. For the api key: "${keyUserLine(keySteps())}" Do not do that step yourself.${caps ? ` ${capsLine(caps)}` : ""}` + tooLowNext(caps) + emptyNext(empty)
142148
+ next: `Do not call inference_server again to check it. ${BALANCE_SHOWS_LOCAL_AI} Tell the user it is starting; the lines in paste are the ones to give their agent app, and they work once it runs. For the api key: "${keyUserLine(keySteps())}" Do not do that step yourself.${caps ? ` ${capsLine(caps)}` : ""}` + tooLowNext(caps) + emptyNext(empty)
142146
142149
  });
142147
142150
  };
142148
142151
  const capsOf2 = (args) => {
@@ -142298,7 +142301,7 @@ function createLocalAiTool({
142298
142301
  pid ? "Your private AI address did not stop. Its process must be ended by hand; I tell you which one and how." : "Your private AI address did not stop yet. Ask me again to stop it in a few seconds.",
142299
142302
  "inference_server_stop_failed",
142300
142303
  String(result.detail ?? "the server did not end"),
142301
- pid ? `Tell the user to end process ${pid} (Windows: Task Manager, or taskkill /PID ${pid} /F; macOS or Linux: kill ${pid}), then call inference_server with action "status"` : 'Tell the user it did not stop yet. When the user asks again, call inference_server with action "stop" again, then action "status"',
142304
+ pid ? `Tell the user to end process ${pid} (Windows: Task Manager, or taskkill /PID ${pid} /F; macOS or Linux: kill ${pid}). ${BALANCE_SHOWS_LOCAL_AI}` : `Tell the user it did not stop yet. When the user asks again, call inference_server with action "stop" again. ${BALANCE_SHOWS_LOCAL_AI}`,
142302
142305
  { stopped: false }
142303
142306
  );
142304
142307
  }
@@ -142312,13 +142315,59 @@ function createLocalAiTool({
142312
142315
  ...result.forced ? { forced: true } : {},
142313
142316
  ...spent !== void 0 ? { spent, spentAtomic: String(result.spentAtomic), requests: requests2 } : {},
142314
142317
  detail: String(result.detail ?? "it stopped"),
142315
- next: `${result.forced ? "Check the balance with wallet_balance: the request that was cut off may have been paid. " : ""}Tell the user it stopped. Their agent app keeps base_url and the api key; inference_server with action "start" runs it again with the same key.`
142318
+ next: `${result.forced ? "Check the balance with wallet_balance: the request that was cut off may have been paid. " : ""}Tell the user it stopped (checked: its process ended); do not call inference_server again to check it. Their agent app keeps base_url and the api key; inference_server with action "start" runs it again with the same key.`
142316
142319
  });
142317
142320
  }
142321
+ async function balanceStateOf(path) {
142322
+ const read2 = await state2(path);
142323
+ if (read2.state === "listening") {
142324
+ const spent = usdc2(read2.spentAtomic ?? "0") ?? "0";
142325
+ const requests2 = Number.isSafeInteger(read2.requests) ? read2.requests : 0;
142326
+ return {
142327
+ field: { state: "running", baseUrl: read2.baseUrl, spent, requests: requests2 },
142328
+ next: `The private AI address for other apps runs at ${read2.baseUrl} (it paid ${spent} USDC for ${plural(requests2, "request")} in this run); say so only when the user asks about it`
142329
+ };
142330
+ }
142331
+ if (read2.running || starting) {
142332
+ return {
142333
+ field: { state: "starting" },
142334
+ next: "The private AI address for other apps is starting and does not answer yet; say so only when the user asks about it"
142335
+ };
142336
+ }
142337
+ let kept3;
142338
+ const file = startFile();
142339
+ let text3;
142340
+ if (file) {
142341
+ try {
142342
+ text3 = await readFile6(file, "utf8");
142343
+ } catch (error) {
142344
+ if (error?.code !== "ENOENT") throw error;
142345
+ }
142346
+ }
142347
+ const value2 = text3 === void 0 ? void 0 : JSON.parse(text3);
142348
+ if (value2 && typeof value2.at === "string" && (value2.state === "began" || value2.state === "failed")) kept3 = value2;
142349
+ if (!kept3 && lastStartFailure) kept3 = { state: "failed", ...lastStartFailure };
142350
+ const fileLast = read2.last;
142351
+ const ownNewer = kept3 && !(fileLast?.at && Date.parse(fileLast.at) >= Date.parse(kept3.at));
142352
+ if (ownNewer && kept3.state === "began") {
142353
+ return {
142354
+ field: { state: "not_known" },
142355
+ next: `The private AI address for other apps is not running; its last start's result is not known. When the user asks about it, say so; inference_server with action "status" gives the details`
142356
+ };
142357
+ }
142358
+ const last = ownNewer && kept3.state === "failed" ? { state: "failed" } : fileLast;
142359
+ if (last?.state === "failed") {
142360
+ return {
142361
+ field: { state: "failed" },
142362
+ next: 'The private AI address for other apps is not running: its last start failed. When the user asks about it, inference_server with action "status" gives the reason'
142363
+ };
142364
+ }
142365
+ return last ? { field: { state: "stopped" } } : void 0;
142366
+ }
142318
142367
  return {
142319
142368
  name: LOCAL_AI_TOOL_NAME,
142320
142369
  title: "Private local AI address for agent apps",
142321
- description: `Use this when the user wants a private AI address for another agent app: an OpenAI-compatible base_url and api key on this machine (${localAiBaseUrl()}). With no action it only reports the state and starts nothing. action "start" runs it in the background and answers the lines to paste into the app: OPENAI_BASE_URL and the model. The api key is never in an answer, so it stays out of the chat: the answer names the terminal command that the user runs to print it (and an install command when one is needed first); never run them yourself or ask for the key. It keeps running after this app or terminal closes, until action "stop" (the user asks you to stop it) or a computer restart. action "status" says whether it runs, its caps, and what it paid. COST: each answer the app asks for is paid from the private balance: the AI provider's price for the request's max_tokens, up front (${DEFAULT_MAX_TOKENS} when the request names none, 512 for claude-opus-5), plus the 0.001 USDC Shinjuku fee; the unused rest is NOT refunded. Caps: the lowest of the user's limits (else 0.05 USDC a call and 1 USDC per server run) and the limits in this app's wallet entry; max_payment and max_session (USDC, like "0.02") can only lower them. PRIVACY: it answers only on 127.0.0.1 with its api key, keeps no prompt or answer on disk, and reaches the AI provider through Tor: the AI provider and the company that runs the model see the words, not this machine's IP. This call pays nothing itself. For one answer inside this chat, use inference_chat instead.`,
142370
+ description: `Use this when the user wants a private AI address for another agent app: an OpenAI-compatible base_url and api key on this machine (${localAiBaseUrl()}). With no action it only reports the state and starts nothing. action "start" runs it in the background and answers the lines to paste into the app: OPENAI_BASE_URL and the model. The api key is never in an answer, so it stays out of the chat: the answer names the terminal command that the user runs to print it (and an install command when one is needed first); never run them yourself or ask for the key. It keeps running after this app or terminal closes, until action "stop" (the user asks you to stop it) or a computer restart. action "status" says whether it runs, its caps, and what it paid; for a quick check after a start or a stop, use wallet_balance (its localAi field; that read starts and stops nothing). COST: each answer the app asks for is paid from the private balance: the AI provider's price for the request's max_tokens, up front (${DEFAULT_MAX_TOKENS} when the request names none, 512 for claude-opus-5), plus the 0.001 USDC Shinjuku fee; the unused rest is NOT refunded. Caps: the lowest of the user's limits (else 0.05 USDC a call and 1 USDC per server run) and the limits in this app's wallet entry; max_payment and max_session (USDC, like "0.02") can only lower them. PRIVACY: it answers only on 127.0.0.1 with its api key, keeps no prompt or answer on disk, and reaches the AI provider through Tor: the AI provider and the company that runs the model see the words, not this machine's IP. This call pays nothing itself. For one answer inside this chat, use inference_chat instead.`,
142322
142371
  inputSchema: {
142323
142372
  type: "object",
142324
142373
  properties: {
@@ -142352,10 +142401,33 @@ function createLocalAiTool({
142352
142401
  if (action === "status") return runStatus();
142353
142402
  if (action === "stop") return runStop();
142354
142403
  return runStart(args);
142404
+ },
142405
+ /**
142406
+ * The address's state for wallet_balance's localAi field (BALANCE_SHOWS_LOCAL_AI): { field, next? } or undefined when this
142407
+ * wallet never started one and none runs. Local files only (the status reader writes nothing), bounded by `waitMs`;
142408
+ * never the api key and never the wallet file (no caps: those stay in inference_server's own answers).
142409
+ */
142410
+ async balanceState({ waitMs = 1500 } = {}) {
142411
+ const path = walletPath2();
142412
+ if (!path) return void 0;
142413
+ let timer;
142414
+ const late2 = new Promise((resolveLate) => {
142415
+ timer = setTimeout(resolveLate, waitMs, void 0);
142416
+ timer.unref?.();
142417
+ });
142418
+ const read2 = (async () => {
142419
+ await new Promise((resolveTurn) => setImmediate(resolveTurn));
142420
+ return balanceStateOf(path);
142421
+ })().catch(() => void 0);
142422
+ try {
142423
+ return await Promise.race([read2, late2]);
142424
+ } finally {
142425
+ clearTimeout(timer);
142426
+ }
142355
142427
  }
142356
142428
  };
142357
142429
  }
142358
- var LOCAL_AI_TOOL_NAME, ACTIONS, EXAMPLE_MODEL, MODEL_LINE, TOR_DOWN, SETUP_MISSING, STOP_LINE, ADD_MONEY_OFF, emptyNextText, ZERO_TRUSTED_MS, unsureZeroNextText, KEEPS_RUNNING, PRIVACY, CAPS, json3, refuse10, usdc2, plural, finiteCap, below, capTooLowSay, modelsLine, pasteLines, keyUserLine, keyNote;
142430
+ var LOCAL_AI_TOOL_NAME, BALANCE_SHOWS_LOCAL_AI, ACTIONS, EXAMPLE_MODEL, MODEL_LINE, TOR_DOWN, SETUP_MISSING, STOP_LINE, ADD_MONEY_OFF, emptyNextText, ZERO_TRUSTED_MS, unsureZeroNextText, KEEPS_RUNNING, PRIVACY, CAPS, json3, refuse10, usdc2, plural, finiteCap, below, capTooLowSay, modelsLine, pasteLines, keyUserLine, keyNote;
142359
142431
  var init_localAiTool = __esm({
142360
142432
  "wallet/src/mcp/localAiTool.mjs"() {
142361
142433
  "use strict";
@@ -142372,6 +142444,7 @@ var init_localAiTool = __esm({
142372
142444
  init_models();
142373
142445
  init_serveRunner();
142374
142446
  LOCAL_AI_TOOL_NAME = "inference_server";
142447
+ BALANCE_SHOWS_LOCAL_AI = "For a later check whether it runs, call wallet_balance: its localAi field shows it (that read starts and stops nothing).";
142375
142448
  ACTIONS = Object.freeze(["start", "status", "stop"]);
142376
142449
  EXAMPLE_MODEL = MODELS.find((model2) => model2.id === DEFAULT_MODEL)?.id ?? MODELS[0]?.id;
142377
142450
  MODEL_LINE = `model: ${EXAMPLE_MODEL} (others: ${MODELS.filter((model2) => model2.id !== EXAMPLE_MODEL).map((model2) => model2.id).join(", ")})`;
@@ -148025,6 +148098,38 @@ ${canonical5}`;
148025
148098
  } catch {
148026
148099
  }
148027
148100
  };
148101
+ const closedHeldSeen = /* @__PURE__ */ new Map();
148102
+ async function readClosedAddFundsHeld(store, { waitMs }) {
148103
+ let timer;
148104
+ const late2 = new Promise((resolveLate) => {
148105
+ timer = setTimeout(resolveLate, waitMs, []);
148106
+ timer.unref?.();
148107
+ });
148108
+ const read2 = (async () => {
148109
+ await new Promise((resolveTurn) => setImmediate(resolveTurn));
148110
+ const when = (record) => String(record.closedAt ?? record.createdAt ?? "");
148111
+ const closed2 = listPayMe(store).filter((record) => record.state === "closed" && typeof record.tokenAccount === "string" && linkKindOf(record.id) === "add_funds").sort((a, b) => when(b).localeCompare(when(a))).slice(0, LINK_HELD_READS_MAX);
148112
+ const rows2 = await Promise.all(closed2.map(async (record) => {
148113
+ const seen = closedHeldSeen.get(record.id);
148114
+ let held2 = seen && Date.now() - seen.atMs < LINK_HELD_FRESH_MS ? seen.held : void 0;
148115
+ if (held2 === void 0) {
148116
+ try {
148117
+ held2 = BigInt(await withTimeout(Promise.resolve().then(() => heldAt(session.connection, record.tokenAccount)), waitMs)).toString();
148118
+ } catch {
148119
+ return void 0;
148120
+ }
148121
+ closedHeldSeen.set(record.id, { atMs: Date.now(), held: held2 });
148122
+ }
148123
+ return BigInt(held2) > 0n ? { requestId: shownId(record.requestId, record.id), heldAtomic: held2 } : void 0;
148124
+ }));
148125
+ return rows2.filter(Boolean);
148126
+ })().catch(() => []);
148127
+ try {
148128
+ return await Promise.race([read2, late2]);
148129
+ } finally {
148130
+ clearTimeout(timer);
148131
+ }
148132
+ }
148028
148133
  const linkHeldReading = /* @__PURE__ */ new Map();
148029
148134
  function readOpenLinkHeld(store) {
148030
148135
  const reads = /* @__PURE__ */ new Map();
@@ -148432,7 +148537,7 @@ ${canonical5}`;
148432
148537
  lines.push(`Payment waiting on its seller: ${usdcText3(one.breakdown.openPaymentsAtomic)} USDC (asking for the same thing again finishes it and never pays twice; if the seller never takes it, Shinjuku sends it back by itself within about ${Math.round(FLOAT_REFUND_ETA_SECONDS / 60)} minutes)`);
148433
148538
  }
148434
148539
  const readAge = Number.isSafeInteger(unshielded.unshieldedReadAgeSeconds) ? ` (read ${unshielded.unshieldedReadAgeSeconds} s ago)` : "";
148435
- if (ATOMIC_TEXT.test(String(unshielded.unshieldedAtomic ?? ""))) lines.push(`Public USDC on this wallet's own key: ${usdcText3(unshielded.unshieldedAtomic)} USDC${readAge}`);
148540
+ if (/^[1-9][0-9]*$/.test(String(unshielded.unshieldedAtomic ?? ""))) lines.push(`Not private yet: ${usdcText3(unshielded.unshieldedAtomic)} USDC on your own address${readAge}`);
148436
148541
  let mode;
148437
148542
  try {
148438
148543
  mode = runNetworkMode();
@@ -148446,7 +148551,7 @@ ${canonical5}`;
148446
148551
  } catch {
148447
148552
  paid = void 0;
148448
148553
  }
148449
- if (paid === void 0) lines.push("Last payments to sellers: not readable just now (wallet_receipts lists them)");
148554
+ if (paid === void 0) lines.push("Last payments to sellers: not readable just now (ask me to show your receipts)");
148450
148555
  else if (!paid.length) lines.push("Last payments to sellers: none yet (show my receipts lists your sends and deposits too)");
148451
148556
  else {
148452
148557
  lines.push("Last payments to sellers (UTC):");
@@ -148455,7 +148560,7 @@ ${canonical5}`;
148455
148560
  lines.push(` ${iso2.slice(0, 10)} ${iso2.slice(11, 16)} ${row.sellerHost ?? row.host ?? "seller not recorded"} ${usdcText3(row.amountAtomic)} USDC`);
148456
148561
  }
148457
148562
  }
148458
- lines.push("Try: add funds, pay <url>, unshield 1 USDC to <address>, show my receipts");
148563
+ lines.push("Try: add funds, pay <url>, send 1 USDC to <address>, show my receipts");
148459
148564
  return lines.join("\n");
148460
148565
  }
148461
148566
  const balance = {
@@ -148541,6 +148646,7 @@ ${canonical5}`;
148541
148646
  }
148542
148647
  const ownSendEarly = runningSendsNow().length > 0 || recordSend;
148543
148648
  const linkReads = readOpenLinkHeld(store);
148649
+ const closedLateReads = readClosedAddFundsHeld(store, { waitMs: 3e3 });
148544
148650
  const startKnown = (id) => {
148545
148651
  try {
148546
148652
  return watcher?.startAtOf(linkKindOf(id), id) != null;
@@ -149189,6 +149295,23 @@ ${canonical5}`;
149189
149295
  const fromYourLimits = setLimits.some(([flag3]) => !capFlagFromLaunchLine(flag3));
149190
149296
  const sessionSummary = setLimits.length === 0 ? void 0 : `Spending limits: ${payCapFlag(policy.limits.maxPaymentAtomic) === "--max-session" ? "one payment can use all of the 24-hour limit, which is " : `${capWords2(policy.limits.maxPaymentAtomic)} per payment and `}${capWords2(policy.limits.maxSessionAtomic)} in any 24 hours, for this wallet (every app that runs this wallet counts; a pool upgrade starts a new 24-hour count)${sessionLeft === null ? "" : ` (${usdcText3(sessionLeft)} USDC left now)`}; ${usdcText3(policy.sessionSpentAtomic) ?? "0"} USDC paid in the last 24 hours. ` + setLimits.map(([flag3, limitName]) => `The ${limitName} comes from ${capPlaceWords(flag3)}. `).join("") + (setLimits.some(([flag3]) => capFlagFromLaunchLine(flag3)) ? "A limit set in this app's wallet entry: only the user can change it there (in USDC, like 0.05), then reconnect the wallet. " : "") + `To ${fromYourLimits ? "change a limit from your limits, or set another" : "set another limit"}, the user runs ${terminalCommand2("limits")} in a terminal (it asks each limit: one payment, 24 hours, all payments together)${["--max-payment", "--max-session"].every((flag3) => capCountsNow(flag3)) ? "; it counts at once" : ", then restarts the host"}`;
149191
149297
  if (setLimits.length === 0) next = `${next}. No spending limit is set; when the user asks about one, tell the user: ${noLimitSetLine()}`;
149298
+ let localAi;
149299
+ try {
149300
+ localAi = await inferenceServer.balanceState();
149301
+ } catch {
149302
+ localAi = void 0;
149303
+ }
149304
+ if (localAi?.next) next = next ? `${next}. ${localAi.next}` : localAi.next;
149305
+ let closedLate = [];
149306
+ try {
149307
+ closedLate = await closedLateReads;
149308
+ } catch {
149309
+ closedLate = [];
149310
+ }
149311
+ for (const row of closedLate) {
149312
+ const words2 = `${usdcText3(row.heldAtomic)} USDC arrived at an add-funds address that was closed (request_id "${row.requestId}"); ask the user, then call wallet_add_funds with request_id "${row.requestId}" to add it`;
149313
+ next = next ? `${next}. ${words2}` : words2;
149314
+ }
149192
149315
  const answer = {
149193
149316
  ok: true,
149194
149317
  ...reportPublic,
@@ -149223,6 +149346,8 @@ ${canonical5}`;
149223
149346
  ...sales ? { incomingFromSalesAtomic: sales.atomic, incomingFromSalesPayments: sales.payments } : {},
149224
149347
  ...sendWaiting ? { sendWaiting } : {},
149225
149348
  ...privateSends.length ? { privateSends } : {},
149349
+ ...localAi ? { localAi: localAi.field } : {},
149350
+ ...closedLate.length ? { closedAddressDeposits: closedLate } : {},
149226
149351
  ...notices,
149227
149352
  ...networkFields(),
149228
149353
  session: {
@@ -150807,14 +150932,13 @@ ${canonical5}`;
150807
150932
  return {};
150808
150933
  }
150809
150934
  }
150810
- const BACKUP_SAVED_NEXT = ". Tell the user a backup of the wallet was saved (say only that; its folder is in backupPath if the user asks)";
150811
150935
  function doneNext(kind, job) {
150812
150936
  if (kind === "unshield" && job.result?.privateSend) {
150813
- return sendDoneNext(job.to, job.result.privateSend) + `${job.result?.backupPath ? BACKUP_SAVED_NEXT : ""}`;
150937
+ return sendDoneNext(job.to, job.result.privateSend);
150814
150938
  }
150815
150939
  if (kind === "unshield") {
150816
150940
  const tx = job.result?.exitTransaction;
150817
- return `Sent ${usdcText3(job.amountAtomic)} USDC to ${job.to}${typeof tx === "string" ? ` (transaction ${tx})` : ""}. Tell the user; nothing to do: wallet_balance shows it${job.result?.backupPath ? BACKUP_SAVED_NEXT : ""}`;
150941
+ return `Sent ${usdcText3(job.amountAtomic)} USDC to ${job.to}${typeof tx === "string" ? ` (transaction ${tx})` : ""}. Tell the user; nothing to do: wallet_balance shows it`;
150818
150942
  }
150819
150943
  const post = job.post;
150820
150944
  if (!post || post.state === "running") {
@@ -150822,9 +150946,9 @@ ${canonical5}`;
150822
150946
  }
150823
150947
  if (!post.refreshed) return `the deposit landed; reading it from the chain failed (${post.refreshError}): call wallet_balance in a minute, it retries by itself`;
150824
150948
  if (post.spendableAtMs !== void 0 && post.spendableAtMs > Date.now()) {
150825
- return `the deposit landed and is in the private balance. It is spendable in about ${Math.ceil((post.spendableAtMs - Date.now()) / 1e3)} s: pay_for_service and wallet_unshield wait for it by themselves, so call them now if the user wants to${post.backupPath ? BACKUP_SAVED_NEXT : ""}`;
150949
+ return `the deposit landed and is in the private balance. It is spendable in about ${Math.ceil((post.spendableAtMs - Date.now()) / 1e3)} s: pay_for_service and wallet_unshield wait for it by themselves, so call them now if the user wants to`;
150826
150950
  }
150827
- return `the deposit landed and is in the private balance: pay_for_service and wallet_unshield can spend it now${post.backupPath ? BACKUP_SAVED_NEXT : ""}`;
150951
+ return "the deposit landed and is in the private balance: pay_for_service and wallet_unshield can spend it now";
150828
150952
  }
150829
150953
  const ELSEWHERE_PRIVACY = "the chain shows the other wallet paying this new one-time address, and that address depositing this amount into the pool (both public; Shinjuku also sees the amount and time). Later payments from the private balance do not show which deposit paid them. With few depositors in the pool, an amount few other deposits share, or a payment soon after the deposit, is easier to pair";
150830
150954
  const reclaimHow = (requestId) => `only the user can take it back, with one terminal command: ${terminalCommand2(`deposit-reclaim --pool <pool> --program <program> --rpc-file <a file with the RPC URL> --deposit-id ${elsewhereId(requestId)} --to <a USDC token address> --fee-payer-key-file <a key file with a little SOL>`, { code: true })}; the chain then links that key and the receiving address to the one-time address`;
@@ -150920,7 +151044,9 @@ ${canonical5}`;
150920
151044
  stage: job.stage,
150921
151045
  sendState: "sending",
150922
151046
  ...exitTransaction ? { exitTransaction } : {},
150923
- detail: `the send has started (now: ${stageWords(job.stage)}): the ${usdcText3(job.amountAtomic)} USDC is leaving the private balance for ${job.to}${where}; it cannot be stopped. It goes on in this wallet process. ${SEND_KEPT_ON_DISK}`,
151047
+ // "Cannot be stopped" only once the exit transaction is known (signed and sent); before it, "sending" can rest on a
151048
+ // payment record that a host cancel still stops (selfPayMayHaveSigned; Codex round 1 on 1062cb7b9 P1).
151049
+ detail: `the send has started (now: ${stageWords(job.stage)}): the ${usdcText3(job.amountAtomic)} USDC is leaving the private balance for ${job.to}${where}${exitTransaction ? "; it cannot be stopped" : ""}. It goes on in this wallet process. ${SEND_KEPT_ON_DISK}`,
150924
151050
  next: `Do not tell the user that no money moved or that nothing was sent: the send has started${job.stage === "exit" ? " and the USDC may already be at the address" : ""}. Tell the user the send is on its way. ${SEND_RESULT_READ(job.requestId)}`
150925
151051
  });
150926
151052
  }
@@ -154353,7 +154479,7 @@ ${canonical5}`;
154353
154479
  const blockedBy = stage === "pending" ? blockedByOf(linkBlockers(record)) : void 0;
154354
154480
  const differs = askedVsArrived(record, stage);
154355
154481
  const shown = extra.requestId ?? shownId(record.requestId, record.id);
154356
- const next = stage === "waiting_for_payment" ? `give the user link and line (${LINK_AS_TEXT}); after the payer sends, call wallet_pay_me_status with request_id "${shown}"` : finished ? `Tell the user: ${differs ? `${differs.sentence}, and it` : "the payment arrived and"} is now in the private (shielded) balance${outcome.again ? "; the link was paid more than once, so never share a used link" : ""}. wallet_balance shows the new balance. If the user wants another payment, call wallet_pay_me with a NEW request_id` : stage === "partly_shielded" ? `${differs ? `Tell the user: ${differs.sentence}. ` : ""}call wallet_pay_me_status with request_id "${shown}" again now: it shields the rest as the next round` : stage === "over_cap" ? `tell the user what detail says; nothing was shielded and the USDC is safe at the address. Call wallet_pay_me_status with request_id "${shown}" again once the shield limit leaves room (its 24 hours pass)${outcome.code === "mcp_shield_cap_exceeded" ? `, or tell the user how to raise the shield limit: ${capRaiseText("--max-shield")}` : ""}` : stage === "below_minimum" ? "tell the user what detail says; nothing more to do now. If the payer sends more to the same address, call wallet_pay_me_status again: it all goes in" : stage === "waiting" && outcome.code === "rpc_relay_limit" ? `Tell the user: ${relayLimitWords(relayLimitNow()) ?? "Shinjuku's free Solana chain reader reached its limit for now."} The deposit keeps its record, so nothing is lost; ask again after that time. Do not poll before then; after that time, call wallet_pay_me_status with request_id "${shown}"` : stage === "waiting" && outcome.landed === true ? `Tell the user: the USDC went into the private pool, but the step that stores its private record at Shinjuku did not finish; nothing is lost. Do not send USDC again. Ask again later: call wallet_pay_me_status with request_id "${shown}"` : stage === "waiting" && /pool_value_cap|above_pool_value/.test(String(outcome.code ?? "")) ? `Nothing was moved; the USDC is safe at the address. Do not poll. Tell the user: the private pool has no room for this amount now (it holds at most ${poolLimitsKnown()?.maxPoolValue === void 0 ? "a fixed total" : `${usdcText3(poolLimitsKnown().maxPoolValue)} USDC`} for all its users together), so the USDC waits safely at the address; a later balance ask tries again, and it goes in only when the private pool has room and the shield limit set for this wallet leaves room; until then it stays at the address` : stage === "waiting" && outcome.code === PROGRAM_START_REFUSED_CODE ? `Do not poll: this computer refuses the same program the same way. Tell the user: ${programStartWords({ smartAppControl: outcome.smartAppControl === true, code: "UNKNOWN" }, { done: DEPOSIT_START_REFUSED_DONE }).user}. Once the program can start, one balance ask makes the USDC at the address private` : stage === "waiting" && PAY_ME_OWNER_CODES.test(String(outcome.code ?? "")) ? "Nothing was moved; the USDC is safe at the address. Do not poll. Tell the user: Shinjuku does not relay this deposit now, so the USDC stays at the address, and the wallet keeps its record" : stage === "update_needed" ? `Tell the user: Shinjuku did not take this deposit, and this wallet version cannot tell why; the USDC is safe at the address and nothing was moved. ${updateStep(`call wallet_pay_me_status with request_id "${shown}" once`)}` : stage === "paid_not_shielded" ? "Nothing was moved. Tell the user: shielding a pay-me payment needs the wallet's setup files and Shinjuku, which relays the deposit (setup records both), and shielding must not be turned off in this app's wallet entry; run setup again in a terminal, then reconnect the wallet. The USDC stays at the address until then" : stage === "closed" ? `nothing to do now; if USDC is sent to this address later, call wallet_add_funds with request_id "${shown}" and it goes in. For a new address call wallet_add_funds without request_id` : stage === "reclaimed" ? "Tell the user what detail says: this link is finished (its deposit was taken back or closed), so nothing goes in through it; do not send to this address again. Do not poll it. For a new payment call wallet_pay_me with a NEW request_id" : `call wallet_pay_me_status with request_id "${shown}" again in ${POLL_SECONDS2} s`;
154482
+ const next = stage === "waiting_for_payment" ? `give the user link and line (${LINK_AS_TEXT}); after the payer sends, call wallet_pay_me_status with request_id "${shown}"` : finished ? `Tell the user: ${differs ? `${differs.sentence}, and it` : "the payment arrived and"} is now in the private (shielded) balance${outcome.again ? "; the link was paid more than once, so never share a used link" : ""}. wallet_balance shows the new balance. If the user wants another payment, call wallet_pay_me with a NEW request_id` : stage === "partly_shielded" ? `${differs ? `Tell the user: ${differs.sentence}. ` : ""}call wallet_pay_me_status with request_id "${shown}" again now: it shields the rest as the next round` : stage === "over_cap" ? `tell the user what detail says; nothing was shielded and the USDC is safe at the address. Call wallet_pay_me_status with request_id "${shown}" again once the shield limit leaves room (its 24 hours pass)${outcome.code === "mcp_shield_cap_exceeded" ? `, or tell the user how to raise the shield limit: ${capRaiseText("--max-shield")}` : ""}` : stage === "below_minimum" ? "tell the user what detail says; nothing more to do now. If the payer sends more to the same address, call wallet_pay_me_status again: it all goes in" : stage === "waiting" && outcome.code === "rpc_relay_limit" ? `Tell the user: ${relayLimitWords(relayLimitNow()) ?? "Shinjuku's free Solana chain reader reached its limit for now."} The deposit keeps its record, so nothing is lost; ask again after that time. Do not poll before then; after that time, call wallet_pay_me_status with request_id "${shown}"` : stage === "waiting" && outcome.landed === true ? `Tell the user: the USDC went into the private pool, but the step that stores its private record at Shinjuku did not finish; nothing is lost. Do not send USDC again. Ask again later: call wallet_pay_me_status with request_id "${shown}"` : stage === "waiting" && /pool_value_cap|above_pool_value/.test(String(outcome.code ?? "")) ? `Nothing was moved; the USDC is safe at the address. Do not poll. Tell the user: the private pool has no room for this amount now (it holds at most ${poolLimitsKnown()?.maxPoolValue === void 0 ? "a fixed total" : `${usdcText3(poolLimitsKnown().maxPoolValue)} USDC`} for all its users together), so the USDC waits safely at the address; a later balance ask tries again, and it goes in only when the private pool has room and the shield limit set for this wallet leaves room; until then it stays at the address` : stage === "waiting" && outcome.code === PROGRAM_START_REFUSED_CODE ? `Do not poll: this computer refuses the same program the same way. Tell the user: ${programStartWords({ smartAppControl: outcome.smartAppControl === true, code: "UNKNOWN" }, { done: DEPOSIT_START_REFUSED_DONE }).user}. Once the program can start, one balance ask makes the USDC at the address private` : stage === "waiting" && PAY_ME_OWNER_CODES.test(String(outcome.code ?? "")) ? "Nothing was moved; the USDC is safe at the address. Do not poll. Tell the user: Shinjuku does not relay this deposit now, so the USDC stays at the address, and the wallet keeps its record" : stage === "update_needed" ? `Tell the user: Shinjuku did not take this deposit, and this wallet version cannot tell why; the USDC is safe at the address and nothing was moved. ${updateStep(`call wallet_pay_me_status with request_id "${shown}" once`)}` : stage === "paid_not_shielded" ? "Nothing was moved. Tell the user: shielding a pay-me payment needs the wallet's setup files and Shinjuku, which relays the deposit (setup records both), and shielding must not be turned off in this app's wallet entry; run setup again in a terminal, then reconnect the wallet. The USDC stays at the address until then" : stage === "closed" ? `nothing to do now: it is closed (checked); do not call wallet_add_funds or wallet_cancel now to check it. For a later check that it is closed, call wallet_receipts with kind "moves" (it reads; it moves nothing). If USDC is sent to this address later (wallet_balance names it in closedAddressDeposits, or the user says so), call wallet_add_funds with request_id "${shown}" and it goes in. For a new address call wallet_add_funds without request_id` : stage === "reclaimed" ? "Tell the user what detail says: this link is finished (its deposit was taken back or closed), so nothing goes in through it; do not send to this address again. Do not poll it. For a new payment call wallet_pay_me with a NEW request_id" : `call wallet_pay_me_status with request_id "${shown}" again in ${POLL_SECONDS2} s`;
154357
154483
  const closedNote = takeClosedEarlier(record.id);
154358
154484
  const told = closedNote.closedEarlier ? `Tell the user first: the wallet closed an earlier waiting address that got nothing (${closedNote.closedEarlier.map((one) => one.address).join(", ")}); nobody should send USDC to it, and USDC sent there anyway stays at that address. ` : "";
154359
154485
  return json4({
@@ -156795,7 +156921,7 @@ function createSetupTools({
156795
156921
  return { notSaved: why };
156796
156922
  }
156797
156923
  }
156798
- async function confirm(plan) {
156924
+ async function confirm(plan, { torArg } = {}) {
156799
156925
  const limit = (atomic5) => String(atomic5) === NO_LIMIT_ATOMIC ? "no limit" : `${usdc5(atomic5)} USDC`;
156800
156926
  const limits = `spending limits: ${limit(plan.maxPaymentAtomic)} per payment, ${limit(plan.maxSessionAtomic)} in any 24 hours`;
156801
156927
  const message = configDamaged ? `Repair the wallet's settings file (${limits})? The damaged file is kept aside and a new one is written; your wallet, its keys and its money stay as they are.` : `Create a Shinjuku Shield wallet on this machine (${limits})? The keys and a random passphrase stay in private files on this machine.`;
@@ -156824,10 +156950,13 @@ function createSetupTools({
156824
156950
  }, elicitTimeoutMs);
156825
156951
  const ok = answer?.action === "accept" && answer?.content?.confirm !== false;
156826
156952
  const privateInference = answer?.content?.privateInference === true;
156953
+ const fieldless = !answer?.content || typeof answer.content !== "object" || Object.keys(answer.content).length === 0;
156954
+ const tor = fieldless && typeof torArg === "boolean" ? torArg || privateInference : answer?.content?.tor !== false || privateInference;
156827
156955
  return {
156828
156956
  ok,
156829
156957
  privateInference,
156830
- tor: answer?.content?.tor !== false || privateInference,
156958
+ tor,
156959
+ fieldless,
156831
156960
  unshown: !ok && elicitUnshown(askedAt, answer),
156832
156961
  ...ok ? typedAddress(answer?.content?.yourWalletAddress, Date.now() - askedAt) : {}
156833
156962
  };
@@ -156835,11 +156964,14 @@ function createSetupTools({
156835
156964
  return { ok: false, privateInference: false, tor: false, unshown: error?.timedOut !== true && elicitUnshown(askedAt) };
156836
156965
  }
156837
156966
  }
156838
- async function begin(ctx) {
156967
+ async function begin(ctx, args = {}) {
156839
156968
  if (job) {
156840
156969
  await waitForAnswer(ctx);
156841
156970
  return status(ctx);
156842
156971
  }
156972
+ if (args.tor !== void 0 && typeof args.tor !== "boolean") {
156973
+ return refuse11("mcp_argument_invalid", "tor must be true or false; nothing was created", 'ask the user "Use Tor?" and pass tor true or false, or leave it out (Tor stays on)');
156974
+ }
156843
156975
  const plan = setup.plan();
156844
156976
  if (!plan.ok && plan.say) {
156845
156977
  return refuse11(plan.code, plan.detail, `Tell the user: ${plan.detail[0].toUpperCase()}${plan.detail.slice(1)}.`, { say: plan.say });
@@ -156858,7 +156990,7 @@ function createSetupTools({
156858
156990
  answered2 = resolve45;
156859
156991
  }) };
156860
156992
  const started = (async () => {
156861
- const answer = await confirm(plan);
156993
+ const answer = await confirm(plan, { torArg: args.tor });
156862
156994
  if (!answer.ok) {
156863
156995
  job.state = "declined";
156864
156996
  job.stage = "declined";
@@ -156931,10 +157063,12 @@ function createSetupTools({
156931
157063
  const setupTool = {
156932
157064
  name: "shinjuku_setup",
156933
157065
  title: "Set up the wallet",
156934
- description: (configDamaged ? "The wallet's settings file (config.json) is damaged, so the wallet tools did not start; the wallet and its money are safe. This repairs it (the damaged file is set aside, a new one is written, the wallet is kept). Call this when the user wants to pay a paid URL, check a balance, or shield " : "The wallet is not set up on this machine yet. Call this when the user wants to pay a paid URL, check a balance, or shield ") + "USDC. It asks the user to confirm in this client (with the spending caps, Tor, and the user's own wallet address, optional: later sends to it need no question), then " + (configDamaged ? "keeps the wallet, its keys, its passphrase file and its money as they are and writes only a new settings file, checks the setup files " : "creates a self-custody wallet on this machine (keys and a random passphrase in private local files; no tool takes or returns them), downloads and checks the setup files ") + "(about 191 MB, minutes), and switches this server to the wallet tools. Takes no arguments. Call it again with no arguments as `next` says for the stage (confirming, waiting: another setup of this wallet runs and this one waits for it, tor, platform, release, passphrase, wallet, proof-tools, program-check, config, done; declined, no_tor or failed: the setup ended, and this call answers why). A decline creates nothing (mcp_setup_declined). A client that cannot confirm is refused (mcp_setup_needs_terminal) with the terminal command; a client that declines at once without showing the dialog gets mcp_setup_declined with the same terminal command.",
156935
- inputSchema: { type: "object", properties: {}, additionalProperties: false },
157066
+ description: (configDamaged ? "The wallet's settings file (config.json) is damaged, so the wallet tools did not start; the wallet and its money are safe. This repairs it (the damaged file is set aside, a new one is written, the wallet is kept). Call this when the user wants to pay a paid URL, check a balance, or shield " : "The wallet is not set up on this machine yet. Call this when the user wants to pay a paid URL, check a balance, or shield ") + "USDC. It asks the user to confirm in this client (with the spending caps, Tor, and the user's own wallet address, optional: later sends to it need no question), then " + (configDamaged ? "keeps the wallet, its keys, its passphrase file and its money as they are and writes only a new settings file, checks the setup files " : "creates a self-custody wallet on this machine (keys and a random passphrase in private local files; no tool takes or returns them), downloads and checks the setup files ") + '(about 191 MB, minutes), and switches this server to the wallet tools. Call it again as `next` says for the stage (confirming, waiting: another setup of this wallet runs and this one waits for it, tor, platform, release, passphrase, wallet, proof-tools, program-check, config, done; declined, no_tor or failed: the setup ended, and this call answers why). A decline creates nothing (mcp_setup_declined). A client that cannot confirm is refused (mcp_setup_needs_terminal) with the terminal command; a client that declines at once without showing the dialog gets mcp_setup_declined with the same terminal command. tor (optional): only for an app whose confirm box shows no fields (Hermes shows only Approve/Deny): ask the user "Use Tor? Yes is the default; it hides your IP address from the services the wallet reaches" in the chat first and pass the answer. A box with fields decides itself. The user\'s own wallet address is not asked there: the first send back to it asks the user to approve it.',
157067
+ inputSchema: { type: "object", properties: {
157068
+ tor: { type: "boolean", description: `Optional: the user's answer to "Use Tor?" given in the chat, used only when this app's confirm box shows no fields. Leave it out to keep Tor on.` }
157069
+ }, additionalProperties: false },
156936
157070
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
156937
- run: (args, ctx) => begin(ctx)
157071
+ run: (args, ctx) => begin(ctx, args && typeof args === "object" ? args : {})
156938
157072
  };
156939
157073
  const statusTool = {
156940
157074
  name: "wallet_status",
@@ -157719,7 +157853,7 @@ var init_tools = __esm({
157719
157853
  "wallet_move_status",
157720
157854
  "wallet_receive_shielded"
157721
157855
  ]);
157722
- setupTerminalNext = () => `Tell the user to run ${terminalCommand2("setup", { code: true })} in a terminal on this machine, then reconnect the wallet (${RESTART_STEPS})`;
157856
+ setupTerminalNext = () => underHermesPlugin() ? 'Tell the user: this Hermes session cannot show the setup question (a quiet, scheduled or unattended session). Open Hermes in a chat window and ask "set up my Shinjuku wallet" there' : `Tell the user to run ${terminalCommand2("setup", { code: true })} in a terminal on this machine, then reconnect the wallet (${RESTART_STEPS})`;
157723
157857
  SETUP_RUNNING_SAY = "The wallet is downloading its files now; you do not need to do anything.";
157724
157858
  SETUP_WAITING_SAY = "Another setup of this wallet is running in another window or app; this one waits for it. If that window asks something, answer it there.";
157725
157859
  ACCEPTED_NEXT = "The user accepted the setup box in this app (accepted shows the choices): do not tell the user the box did not appear or that limits were never asked. ";
@@ -160665,6 +160799,7 @@ var init_serve = __esm({
160665
160799
  // wallet/src/inference/serveRunner.mjs
160666
160800
  import { randomBytes as randomBytes41 } from "node:crypto";
160667
160801
  import { spawn as spawn6, spawnSync as spawnSync8 } from "node:child_process";
160802
+ import { readFile as readFile7 } from "node:fs/promises";
160668
160803
  import { dirname as dirname42, join as join48, resolve as resolve31 } from "node:path";
160669
160804
  function writeAtomic4(path, text3) {
160670
160805
  const temp = `${path}.${randomBytes41(4).toString("hex")}.tmp`;
@@ -161216,6 +161351,29 @@ async function startLocalAiServer({
161216
161351
  return failed(`the server did not start (${error?.code ?? error?.name ?? "Error"}); nothing was paid`, { failedAt: "threw" });
161217
161352
  }
161218
161353
  }
161354
+ async function localAiServerState(walletPath2) {
161355
+ walletPath2 = resolve31(walletPath2);
161356
+ const holder = await leaseHolder(localAiServerLockPath(walletPath2));
161357
+ if (holder && holder.alive === void 0) throw new Error("local_ai_lease_not_known");
161358
+ const running = holder?.alive === true;
161359
+ let text3;
161360
+ try {
161361
+ text3 = await readFile7(localAiServerStatusPath(walletPath2), "utf8");
161362
+ } catch (error) {
161363
+ if (error?.code !== "ENOENT") throw error;
161364
+ }
161365
+ const value2 = text3 === void 0 ? void 0 : JSON.parse(text3);
161366
+ if (value2 !== void 0 && value2?.schema !== STATUS_SCHEMA) throw new Error("local_ai_status_not_known");
161367
+ const status = value2;
161368
+ if (running && status?.pid === holder.pid && status.state === "listening") {
161369
+ return { running: true, state: "listening", baseUrl: localAiBaseUrl(status.port), spentAtomic: status.spentAtomic, requests: status.requests };
161370
+ }
161371
+ return {
161372
+ running,
161373
+ state: running ? "starting" : "stopped",
161374
+ ...!running && status && (status.state === "failed" || status.state === "stopped") ? { last: { state: status.state, at: status.updatedAt } } : {}
161375
+ };
161376
+ }
161219
161377
  async function localAiServerStatus({ walletPath: walletPath2, home, walletMaxPaymentAtomic } = {}) {
161220
161378
  walletPath2 = resolve31(walletPath2);
161221
161379
  const walletHome2 = home ?? dirname42(dirname42(walletPath2));