shinjuku-shield 0.3.230 → 0.3.231

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.230. The command is `shinjuku`.
11
+ This is version 0.3.231. 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.230 mcp
115
+ claude mcp add --scope user shinjuku -- npx -y --prefer-offline --no-audit --no-fund shinjuku-shield@0.3.231 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.230, its older name, runs this package at the same version, so wallets
134
+ 0.3.231, 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": "2fc5d76655c3647dc53aa68ae46db4a45cc69964f6f514a089e0ce253e7f70bc",
5
- "bytes": 10371626,
6
- "sourceCommit": "c0704a702c21b172d0103f473ee317d42c847048",
4
+ "sha256": "85d42668d914c75fb1ebb54ae6a2f3915963bd346b4221aef2bbb4bbc6ac7837",
5
+ "bytes": 10387804,
6
+ "sourceCommit": "7592a8701ac1673497c3a7237b586a14e323ff2a",
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",
@@ -1075,8 +1075,8 @@
1075
1075
  ],
1076
1076
  "seller": {
1077
1077
  "file": "shinjuku-seller.mjs",
1078
- "sha256": "10b55d5356a04206c53b602d2c4d5157881619a1121dff4b7700b5b4fa31ffe9",
1079
- "bytes": 4194469,
1078
+ "sha256": "623b3c6834564b5bf95987f1496c4b63b3a07ac615c36bb95fd55ded5cc701cf",
1079
+ "bytes": 4199870,
1080
1080
  "entry": "wallet/src/seller/exact/index.mjs",
1081
1081
  "external": [
1082
1082
  "@x402/core/http",
@@ -1968,5 +1968,5 @@
1968
1968
  }
1969
1969
  ]
1970
1970
  },
1971
- "publishedAt": "2026-11-13T11:54:24.076Z"
1971
+ "publishedAt": "2026-11-13T13:35:40.888Z"
1972
1972
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "shinjuku-shield",
3
- "version": "0.3.230",
3
+ "version": "0.3.231",
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": "2fc5d766",
7
- "shinjukuSha256": "2fc5d76655c3647dc53aa68ae46db4a45cc69964f6f514a089e0ce253e7f70bc",
6
+ "shinjukuRelease": "85d42668",
7
+ "shinjukuSha256": "85d42668d914c75fb1ebb54ae6a2f3915963bd346b4221aef2bbb4bbc6ac7837",
8
8
  "license": "SEE LICENSE IN LICENSE.txt",
9
9
  "author": "Shinjuku Shield",
10
10
  "homepage": "https://github.com/ShinjukuStaition/shinjuku-shield#readme",
@@ -80028,14 +80028,20 @@ AUTHCHALLENGE SAFECOOKIE ${clientNonce.toString("hex")}\r
80028
80028
  socket.on("close", () => {
80029
80029
  streaming = false;
80030
80030
  });
80031
- resolvePromise({ close: () => {
80032
- streaming = false;
80033
- try {
80034
- socket.end("QUIT\r\n");
80035
- } catch {
80031
+ resolvePromise({
80032
+ close: () => {
80033
+ streaming = false;
80034
+ try {
80035
+ socket.end("QUIT\r\n");
80036
+ } catch {
80037
+ }
80038
+ socket.destroy();
80039
+ },
80040
+ send: (command) => {
80041
+ if (streaming && !socket.destroyed) socket.write(`${command}\r
80042
+ `);
80036
80043
  }
80037
- socket.destroy();
80038
- } });
80044
+ });
80039
80045
  if (text2) socket.emit("data", Buffer.alloc(0));
80040
80046
  return void 0;
80041
80047
  }
@@ -80862,6 +80868,149 @@ function startTorTimingMarks() {
80862
80868
  });
80863
80869
  }
80864
80870
  startTorTimingMarks();
80871
+ var STALL_CLOSE_MS = 1e4;
80872
+ var STALL_CLOSE_CAP = 2;
80873
+ var STALL_CLOSE_LOG = "stall-closes.log";
80874
+ var STALL_LOG_TAIL = 65536;
80875
+ var STALL_WAITING = /* @__PURE__ */ new Set(["NEW", "DETACHED"]);
80876
+ function loggedStallCloses(home, torStart2) {
80877
+ const perOnion = /* @__PURE__ */ new Map();
80878
+ const streams = /* @__PURE__ */ new Set();
80879
+ const path = join24(managedTorDir(home), STALL_CLOSE_LOG);
80880
+ let present = true;
80881
+ try {
80882
+ lstatSync(path);
80883
+ } catch (error) {
80884
+ present = error?.code !== "ENOENT";
80885
+ }
80886
+ let text2 = "";
80887
+ if (present) {
80888
+ text2 = readHomeFileTail(home, path, STALL_LOG_TAIL);
80889
+ if (typeof text2 !== "string") return void 0;
80890
+ }
80891
+ for (const line of text2.split("\n")) {
80892
+ const one = / tor (\S+) close \d+ onion ([a-z2-7]{8}) stream (\d{1,20}) /.exec(line);
80893
+ if (!one || one[1] !== torStart2) continue;
80894
+ if (!perOnion.has(one[2])) perOnion.set(one[2], /* @__PURE__ */ new Set());
80895
+ perOnion.get(one[2]).add(one[3]);
80896
+ streams.add(one[3]);
80897
+ }
80898
+ return { byOnion: new Map([...perOnion].map(([prefix, ids]) => [prefix, ids.size])), streams };
80899
+ }
80900
+ function startStallCloser() {
80901
+ const run2 = String(process.env.SHINJUKU_WALLET_PROXIED ?? "");
80902
+ if (!run2.startsWith("tor ")) return;
80903
+ setImmediate(async () => {
80904
+ try {
80905
+ const home = setupHome(process.env);
80906
+ const state2 = managedTorState(home);
80907
+ let tunnel;
80908
+ try {
80909
+ tunnel = new URL(run2.split(" ")[1]);
80910
+ } catch {
80911
+ return;
80912
+ }
80913
+ if (!state2 || tunnel.hostname !== "127.0.0.1" || state2.port !== Number(tunnel.port)) return;
80914
+ const torStart2 = `${state2.pid}:${state2.startedAt ?? "?"}`;
80915
+ const ours = ownOnionPrefixes();
80916
+ const streams = /* @__PURE__ */ new Map();
80917
+ const ended2 = /* @__PURE__ */ new Set();
80918
+ const got = /* @__PURE__ */ new Set();
80919
+ const matched = /* @__PURE__ */ new Set();
80920
+ const timers = [];
80921
+ let seq3 = 0;
80922
+ let lastRequested = 0;
80923
+ let previousNew;
80924
+ let stopped = false;
80925
+ let session;
80926
+ const close = (address2, hsdir, id) => {
80927
+ const prefix = ours.get(address2);
80928
+ const open3 = () => !stopped && session && prefix && !got.has(address2) && !ended2.has(`${address2} ${hsdir}`);
80929
+ const stream = streams.get(id);
80930
+ if (!open3() || !stream || !STALL_WAITING.has(stream.status)) return;
80931
+ const stamp = stream.stamp;
80932
+ const done = loggedStallCloses(home, torStart2);
80933
+ if (!done || (done.byOnion.get(prefix) ?? 0) >= STALL_CLOSE_CAP || done.streams.has(id)) return;
80934
+ const number2 = (done.byOnion.get(prefix) ?? 0) + 1;
80935
+ setImmediate(() => {
80936
+ try {
80937
+ const now = streams.get(id);
80938
+ if (!open3() || now !== stream || now.stamp !== stamp || !STALL_WAITING.has(now.status)) return;
80939
+ session.send(`CLOSESTREAM ${id} 1`);
80940
+ try {
80941
+ appendFileSync(
80942
+ join24(managedTorDir(home), STALL_CLOSE_LOG),
80943
+ `${(/* @__PURE__ */ new Date()).toISOString()} tor ${torStart2} close ${number2} onion ${prefix} stream ${id} ${now.status.toLowerCase()}
80944
+ `
80945
+ );
80946
+ } catch {
80947
+ stopped = true;
80948
+ }
80949
+ } catch {
80950
+ }
80951
+ });
80952
+ };
80953
+ session = await controlCheck(home, state2, { unref: true, events: (line) => {
80954
+ seq3 += 1;
80955
+ const before = previousNew;
80956
+ previousNew = void 0;
80957
+ const w = line.split(" ");
80958
+ if (w[1] === "STREAM" && /^\d{1,20}$/.test(w[2] ?? "")) {
80959
+ if (w[3] === "NEW" && w.includes("PURPOSE=DIR_FETCH")) {
80960
+ streams.set(w[2], { seq: seq3, stamp: seq3, status: "NEW" });
80961
+ previousNew = w[2];
80962
+ return;
80963
+ }
80964
+ const known = streams.get(w[2]);
80965
+ if (known) {
80966
+ known.status = w[3];
80967
+ known.stamp = seq3;
80968
+ if (w[3] === "CLOSED" || w[3] === "FAILED") streams.delete(w[2]);
80969
+ }
80970
+ return;
80971
+ }
80972
+ if (w[1] !== "HS_DESC") return;
80973
+ const since = lastRequested;
80974
+ if (w[2] === "REQUESTED") lastRequested = seq3;
80975
+ if (!ours.has(w[3])) return;
80976
+ const hsdir = /^\$([0-9A-F]{40})/.exec(w[5] ?? "")?.[1];
80977
+ if (!hsdir) return;
80978
+ if (w[2] === "RECEIVED") {
80979
+ got.add(w[3]);
80980
+ ended2.add(`${w[3]} ${hsdir}`);
80981
+ return;
80982
+ }
80983
+ if (w[2] === "FAILED") {
80984
+ ended2.add(`${w[3]} ${hsdir}`);
80985
+ return;
80986
+ }
80987
+ if (w[2] !== "REQUESTED") return;
80988
+ if (!before || matched.has(before)) return;
80989
+ const waiting = [...streams].filter(([id, s2]) => s2.seq > since && !matched.has(id) && STALL_WAITING.has(s2.status));
80990
+ if (waiting.length !== 1 || waiting[0][0] !== before) return;
80991
+ matched.add(before);
80992
+ const timer = setTimeout(() => {
80993
+ try {
80994
+ close(w[3], hsdir, before);
80995
+ } catch {
80996
+ }
80997
+ }, STALL_CLOSE_MS);
80998
+ timer.unref?.();
80999
+ timers.push(timer);
81000
+ } });
81001
+ if (!session) return;
81002
+ process.once("exit", () => {
81003
+ for (const timer of timers) clearTimeout(timer);
81004
+ try {
81005
+ session.close();
81006
+ } catch {
81007
+ }
81008
+ });
81009
+ } catch {
81010
+ }
81011
+ });
81012
+ }
81013
+ startStallCloser();
80865
81014
 
80866
81015
  // wallet/src/seller/setup.mjs
80867
81016
  init_tunnelGuard();
@@ -58203,9 +58203,49 @@ function windowsClaudeDesktopFile(env, home, runningDirs) {
58203
58203
  if (dataDirs.length > 1) throw ambiguous(dataDirs.map((dir) => join11(dir, CLAUDE_DESKTOP_FILE)), true);
58204
58204
  return dataDirs.length === 1 ? join11(dataDirs[0], CLAUDE_DESKTOP_FILE) : roaming;
58205
58205
  }
58206
+ function claudeAppHere({ platform = process.platform, env = process.env, home = homedir2(), storeApp = storeClaudeExe, exists: exists2 = existsSync } = {}) {
58207
+ if (platform === "win32") {
58208
+ const store = storeApp(env);
58209
+ if (store !== void 0 && exists2(store)) return true;
58210
+ return exists2(join11(env.LOCALAPPDATA || join11(home, "AppData", "Local"), "AnthropicClaude", "claude.exe"));
58211
+ }
58212
+ if (platform === "darwin") return exists2("/Applications/Claude.app") || exists2(join11(home, "Applications", "Claude.app"));
58213
+ return false;
58214
+ }
58215
+ function storeClaudeExe(env) {
58216
+ const query = "Get-AppxPackage -Name Claude | Where-Object { $_.Publisher -like '*Anthropic, PBC*' } | Select-Object -First 1 -ExpandProperty InstallLocation";
58217
+ try {
58218
+ const result = spawnSync2(windowsPowerShell(env), ["-NoProfile", "-NonInteractive", "-Command", query], { encoding: "utf8", timeout: 1e4, windowsHide: true });
58219
+ const folder = result.status === 0 ? String(result.stdout ?? "").trim() : "";
58220
+ return folder ? join11(folder, "app", "claude.exe") : void 0;
58221
+ } catch {
58222
+ return void 0;
58223
+ }
58224
+ }
58225
+ function claudeAppRunning({ platform = process.platform, env = process.env } = {}) {
58226
+ try {
58227
+ if (platform === "win32") {
58228
+ const query = `$ErrorActionPreference = 'Stop'; $me = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value; $n = 0; foreach ($p in @(Get-CimInstance Win32_Process -Filter "Name='claude.exe'" -ErrorAction Stop)) { $o = Invoke-CimMethod -InputObject $p -MethodName GetOwnerSid -ErrorAction Stop; if ($o.ReturnValue -eq 0 -and $o.Sid -eq $me) { $n++ } }; $n`;
58229
+ const result = spawnSync2(windowsPowerShell(env), ["-NoProfile", "-NonInteractive", "-Command", query], { encoding: "utf8", timeout: 3e4, windowsHide: true });
58230
+ if (result.error || result.status !== 0 || String(result.stderr ?? "").trim()) return void 0;
58231
+ const count3 = String(result.stdout ?? "").trim();
58232
+ return /^[0-9]+$/.test(count3) ? Number(count3) > 0 : void 0;
58233
+ }
58234
+ if (platform === "darwin") {
58235
+ const uid = typeof process.getuid === "function" ? String(process.getuid()) : void 0;
58236
+ if (uid === void 0) return void 0;
58237
+ const found = ["Claude", "claude"].map((name) => spawnSync2("pgrep", ["-x", "-U", uid, name], { timeout: 1e4 }).status);
58238
+ if (found.includes(0)) return true;
58239
+ return found.every((status) => status === 1) ? false : void 0;
58240
+ }
58241
+ } catch {
58242
+ return void 0;
58243
+ }
58244
+ return void 0;
58245
+ }
58206
58246
  function claudeDataDirs(env) {
58207
58247
  if (claudeDataDirsCache) return claudeDataDirsCache;
58208
- const shell = join11(env.SystemRoot || env.SYSTEMROOT || "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
58248
+ const shell = windowsPowerShell(env);
58209
58249
  const query = `Get-CimInstance Win32_Process -Filter "Name='claude.exe'" | ForEach-Object { $_.CommandLine }`;
58210
58250
  let text3 = "";
58211
58251
  try {
@@ -59554,7 +59594,7 @@ function changeFileOnce(file, change, { now, platform, restrict, codec = JSON_CO
59554
59594
  }
59555
59595
  return { changed: true, ...backup ? { backup } : {} };
59556
59596
  }
59557
- var import_web396, CONFIG_SCHEMA, CONFIG_FILE, NPM_PACKAGE_NAMES, COMMAND_PACKAGE, NPX_PACKAGE, NPX_INSTALL_FLAGS, MCP_SERVER_NAME, OLD_MCP_SERVER_NAMES, P03_BINDING, PRODUCTION, RETIRED_POOLS, NO_LIMIT_ATOMIC, DEFAULT_CAPS, OLD_DEFAULT_SETUP_CAPS, OLD_DEFAULT_WALLET_BUDGETS, capText, POSITIVE_ATOMIC, HOME_FOLDER, OLDER_HOME_FOLDER, defaultHomeWords, configPath, homeWalletPath, invalid, isPubkey, MAX_OWN_ADDRESSES, isOwnAddressText, salvagePath, repairPath, configRepairPending, clearConfigSalvage, HOST_TARGETS, HOST_NAMES, hostServersKey, CWD_HOSTS, hasPrefix, CODEX_STARTUP_TIMEOUT_SEC, CODEX_TOOL_TIMEOUT_SEC, PINNED_PACKAGE, LAUNCHER_PACKAGE, NPM_VERSION, knownNpmVersion, RECOVERY_WORDS, NPX_WALLET_LINE, RELEASES_URL, npmStartEnvironment, NPM_START_LOGS_MAX, WIN_ARG_CODE, NPM_START_KEYS, defaultWalletHome, CMD_UNSAFE, programOf, claudeLineDiffers, WINDOWS_SHELL_CODE, CLAUDE_DESKTOP_FILE, claudeDataDirsCache, CONTINUE_HEADER, tomlString, tomlKey, codexEntryOf, HERMES_TRUST, HERMES_TOOL_TIMEOUT_SEC, hermesCwd, HERMES_OWN_KEYS, HERMES_FORM, GOOSE_FORM, gooseServersIn, HERMES_RESERVED_PROFILES, yamlString, hermesEntryOf, gooseEntryOf, HERMES_YAML, GOOSE_YAML, isPlainObject, sameJson, claudeCodeEntry, READ_ONLY_TOOL_NAMES, claudeCodeAllowRules, claudeCodeSettingsFile, UNREADABLE_JSON, JSON_CODEC, indentAt, TEXT_CODEC, OPENCODE_TIMEOUT_MS, COPILOT_TIMEOUT_MS, OPENCLAW_REQUEST_TIMEOUT_MS, OPENCLAW_CONNECTION_TIMEOUT_MS, GOOSE_TIMEOUT_SEC, NESTED_JSON_HOSTS, NESTED_LAUNCH_KEYS, RACED;
59597
+ var import_web396, CONFIG_SCHEMA, CONFIG_FILE, NPM_PACKAGE_NAMES, COMMAND_PACKAGE, NPX_PACKAGE, NPX_INSTALL_FLAGS, MCP_SERVER_NAME, OLD_MCP_SERVER_NAMES, P03_BINDING, PRODUCTION, RETIRED_POOLS, NO_LIMIT_ATOMIC, DEFAULT_CAPS, OLD_DEFAULT_SETUP_CAPS, OLD_DEFAULT_WALLET_BUDGETS, capText, POSITIVE_ATOMIC, HOME_FOLDER, OLDER_HOME_FOLDER, defaultHomeWords, configPath, homeWalletPath, invalid, isPubkey, MAX_OWN_ADDRESSES, isOwnAddressText, salvagePath, repairPath, configRepairPending, clearConfigSalvage, HOST_TARGETS, HOST_NAMES, hostServersKey, CWD_HOSTS, hasPrefix, CODEX_STARTUP_TIMEOUT_SEC, CODEX_TOOL_TIMEOUT_SEC, PINNED_PACKAGE, LAUNCHER_PACKAGE, NPM_VERSION, knownNpmVersion, RECOVERY_WORDS, NPX_WALLET_LINE, RELEASES_URL, npmStartEnvironment, NPM_START_LOGS_MAX, WIN_ARG_CODE, NPM_START_KEYS, defaultWalletHome, CMD_UNSAFE, programOf, claudeLineDiffers, WINDOWS_SHELL_CODE, CLAUDE_DESKTOP_FILE, windowsPowerShell, claudeDataDirsCache, CONTINUE_HEADER, tomlString, tomlKey, codexEntryOf, HERMES_TRUST, HERMES_TOOL_TIMEOUT_SEC, hermesCwd, HERMES_OWN_KEYS, HERMES_FORM, GOOSE_FORM, gooseServersIn, HERMES_RESERVED_PROFILES, yamlString, hermesEntryOf, gooseEntryOf, HERMES_YAML, GOOSE_YAML, isPlainObject, sameJson, claudeCodeEntry, READ_ONLY_TOOL_NAMES, claudeCodeAllowRules, claudeCodeSettingsFile, UNREADABLE_JSON, JSON_CODEC, indentAt, TEXT_CODEC, OPENCODE_TIMEOUT_MS, COPILOT_TIMEOUT_MS, OPENCLAW_REQUEST_TIMEOUT_MS, OPENCLAW_CONNECTION_TIMEOUT_MS, GOOSE_TIMEOUT_SEC, NESTED_JSON_HOSTS, NESTED_LAUNCH_KEYS, RACED;
59558
59598
  var init_config = __esm({
59559
59599
  "wallet/src/setup/config.mjs"() {
59560
59600
  "use strict";
@@ -59683,6 +59723,7 @@ var init_config = __esm({
59683
59723
  claudeLineDiffers = (options) => claudeProgramWord(programOf(options), "win32", "cmd") !== claudeProgramWord(programOf(options), "win32", "powershell");
59684
59724
  WINDOWS_SHELL_CODE = /[%$`"\r\n]/;
59685
59725
  CLAUDE_DESKTOP_FILE = "claude_desktop_config.json";
59726
+ windowsPowerShell = (env) => join11(env.SystemRoot || env.SYSTEMROOT || "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
59686
59727
  CONTINUE_HEADER = Object.freeze(["name: Shinjuku Shield", "version: 0.0.1", "schema: v1", "mcpServers:"]);
59687
59728
  tomlString = (value2) => `"${String(value2).replace(/[\\"]/g, (c) => `\\${c}`).replace(/[\u0000-\u001f\u007f]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`)}"`;
59688
59729
  tomlKey = (key) => /^[A-Za-z0-9_-]+$/.test(key) ? key : tomlString(key);
@@ -150804,13 +150845,15 @@ ${canonical5}`;
150804
150845
  }
150805
150846
  }
150806
150847
  if (kind === "unshield" && ownAddress && request.to === ownAddress) {
150848
+ const owned = preApproved();
150849
+ const main8 = owned.length === 1 && owned[0] !== ownAddress;
150807
150850
  return refuse11(
150808
150851
  "mcp_unshield_to_not_allowed",
150809
150852
  // K22 F2 (2026-10-23): the agent told the user "your deposits were made from that address", but that deposit came
150810
150853
  // through a one-time wallet_add_funds address. The reason holds for both deposit paths: the key is the wallet's public address.
150811
150854
  "the address is this wallet's own key (ownAddress), its public address (wallet_shield deposits from it; wallet_add_funds deposits do not): an exit there would link the payment to this wallet on chain, so this private wallet does not send there; nothing was sent",
150812
- "Nothing was sent. Tell the user this address is the wallet's own public address, so a private send there would show the money is theirs. Ask for a different address (best: one that never sent USDC into this wallet); the exit to it is not linked to this wallet",
150813
- { requestId: request.requestId }
150855
+ "Nothing was sent. Tell the user this address is the wallet's own public address, so a private send there would show the money is theirs. " + (main8 ? "Offer the send to the user's main wallet (wallet_unshield with no to), or ask for a different address" : "Ask for a different address") + " (best: one that never sent USDC into this wallet); the exit to it is not linked to this wallet",
150856
+ { requestId: request.requestId, say: `Not sent: that is this wallet's own address; a send there would show the money is yours. ${main8 ? "Send to your main wallet instead." : "Give me another address to send to."}` }
150814
150857
  );
150815
150858
  }
150816
150859
  const recipientCheck = ops.unshieldRecipient ?? (ops.unshield ? void 0 : checkUnshieldRecipient);
@@ -156002,8 +156045,8 @@ var init_tools = __esm({
156002
156045
  OWN_ADDRESS_INVALID = "That is not a Solana address (32 to 44 letters and digits, as your wallet app shows it)";
156003
156046
  HOST_CHAT_NOT_PRIVATE = "This app's own chat does not change: it still goes to this app's own AI company, not privately. Only the answers you ask the private AI tool for are paid privately.";
156004
156047
  PRIVATE_INFERENCE_WHY = "Your agent then buys AI answers from an AI provider, paid from your private balance over Tor; the AI provider and the company that runs the model see the prompt, not who paid.";
156005
- RESTART_STEPS = `In Claude Code: type /mcp, pick ${MCP_SERVER_NAME}, and choose Reconnect. In Claude Desktop: quit it and open it again. In another app: restart it`;
156006
- HOST_BLOCKED_LINE = "If this app blocks a wallet tool (Claude Code's auto mode can), say nothing moved; in Claude Code, press shift+tab until it shows manual mode, then ask again. Never suggest a rule that lets a payment or send run with no question, or another way around the block.";
156048
+ RESTART_STEPS = `In Claude Code in a terminal: type /mcp, pick ${MCP_SERVER_NAME}, and choose Reconnect. In the Claude app (chat or Code): quit it and open it again. In another app: restart it`;
156049
+ HOST_BLOCKED_LINE = "If this app blocks a wallet tool (Claude Code's auto mode can), say nothing moved; in Claude Code in a terminal, press shift+tab until it shows manual mode; in the Claude app's Code tab, choose Manual in the mode selector under the prompt box; then ask again. Never suggest a rule that lets a payment or send run with no question, or another way around the block.";
156007
156050
  TOR_BROWSER_PORT = "http://127.0.0.1:9150";
156008
156051
  SETUP_TOR_TITLE = "Use Tor?";
156009
156052
  SETUP_TOR_WHY = "It hides your IP address from the payment service and sellers.";
@@ -163128,14 +163171,20 @@ AUTHCHALLENGE SAFECOOKIE ${clientNonce.toString("hex")}\r
163128
163171
  socket.on("close", () => {
163129
163172
  streaming = false;
163130
163173
  });
163131
- resolvePromise({ close: () => {
163132
- streaming = false;
163133
- try {
163134
- socket.end("QUIT\r\n");
163135
- } catch {
163174
+ resolvePromise({
163175
+ close: () => {
163176
+ streaming = false;
163177
+ try {
163178
+ socket.end("QUIT\r\n");
163179
+ } catch {
163180
+ }
163181
+ socket.destroy();
163182
+ },
163183
+ send: (command) => {
163184
+ if (streaming && !socket.destroyed) socket.write(`${command}\r
163185
+ `);
163136
163186
  }
163137
- socket.destroy();
163138
- } });
163187
+ });
163139
163188
  if (text3) socket.emit("data", Buffer.alloc(0));
163140
163189
  return void 0;
163141
163190
  }
@@ -163929,7 +163978,144 @@ function startTorTimingMarks() {
163929
163978
  }
163930
163979
  });
163931
163980
  }
163932
- var ownTorPlatform, MAC, LINUX, SYSTEM2, bundle, managedTorDir, stateFile, bundleDir, torExe, MAC_SIGNED, COMPLETE, LINUX_TOR, BUNDLE_FILES, logFile, BOOTSTRAP_STALL_MS, BOOTSTRAP_MAX_MS, STALL_RESTART_PERCENT, RESTART_MIN_MS, REACHED_RELAY_PERCENT, phaseWords, DOWNLOAD_TIMEOUT_MS, BIND_TRIES, POLL_MS2, pidAlive5, WIN_OWN_TOR, STOP_WAIT_MS, cookieFile, CONTROL_TIMEOUT_MS, SERVER_KEY, CLIENT_KEY, failure2, sleep4, tunnelOf, bundleComplete, LINUX_HASHES, fileSha256, startErrorsFile, NOTICE_READ_MAX, TUNNEL_LISTENER_LINE, ownPortsFile, OWN_PORTS_MAX, OWN_PORTS_READ_MAX, EVENT_LINE_MAX, EVENT_BLOCK_LINES, TOR_TIMING_MAX, HS_DESC_ACTIONS, HS_DESC_REASONS, CIRC_STATUSES, CIRC_PURPOSES, CIRC_HS_STATES, CIRC_REASONS, STREAM_STATUSES;
163981
+ function loggedStallCloses(home, torStart2) {
163982
+ const perOnion = /* @__PURE__ */ new Map();
163983
+ const streams = /* @__PURE__ */ new Set();
163984
+ const path = join51(managedTorDir(home), STALL_CLOSE_LOG);
163985
+ let present = true;
163986
+ try {
163987
+ lstatSync(path);
163988
+ } catch (error) {
163989
+ present = error?.code !== "ENOENT";
163990
+ }
163991
+ let text3 = "";
163992
+ if (present) {
163993
+ text3 = readHomeFileTail(home, path, STALL_LOG_TAIL);
163994
+ if (typeof text3 !== "string") return void 0;
163995
+ }
163996
+ for (const line of text3.split("\n")) {
163997
+ const one = / tor (\S+) close \d+ onion ([a-z2-7]{8}) stream (\d{1,20}) /.exec(line);
163998
+ if (!one || one[1] !== torStart2) continue;
163999
+ if (!perOnion.has(one[2])) perOnion.set(one[2], /* @__PURE__ */ new Set());
164000
+ perOnion.get(one[2]).add(one[3]);
164001
+ streams.add(one[3]);
164002
+ }
164003
+ return { byOnion: new Map([...perOnion].map(([prefix, ids]) => [prefix, ids.size])), streams };
164004
+ }
164005
+ function startStallCloser() {
164006
+ const run2 = String(process.env.SHINJUKU_WALLET_PROXIED ?? "");
164007
+ if (!run2.startsWith("tor ")) return;
164008
+ setImmediate(async () => {
164009
+ try {
164010
+ const home = setupHome(process.env);
164011
+ const state2 = managedTorState(home);
164012
+ let tunnel;
164013
+ try {
164014
+ tunnel = new URL(run2.split(" ")[1]);
164015
+ } catch {
164016
+ return;
164017
+ }
164018
+ if (!state2 || tunnel.hostname !== "127.0.0.1" || state2.port !== Number(tunnel.port)) return;
164019
+ const torStart2 = `${state2.pid}:${state2.startedAt ?? "?"}`;
164020
+ const ours = ownOnionPrefixes();
164021
+ const streams = /* @__PURE__ */ new Map();
164022
+ const ended2 = /* @__PURE__ */ new Set();
164023
+ const got = /* @__PURE__ */ new Set();
164024
+ const matched = /* @__PURE__ */ new Set();
164025
+ const timers = [];
164026
+ let seq3 = 0;
164027
+ let lastRequested = 0;
164028
+ let previousNew;
164029
+ let stopped = false;
164030
+ let session;
164031
+ const close = (address4, hsdir, id) => {
164032
+ const prefix = ours.get(address4);
164033
+ const open6 = () => !stopped && session && prefix && !got.has(address4) && !ended2.has(`${address4} ${hsdir}`);
164034
+ const stream = streams.get(id);
164035
+ if (!open6() || !stream || !STALL_WAITING.has(stream.status)) return;
164036
+ const stamp = stream.stamp;
164037
+ const done = loggedStallCloses(home, torStart2);
164038
+ if (!done || (done.byOnion.get(prefix) ?? 0) >= STALL_CLOSE_CAP || done.streams.has(id)) return;
164039
+ const number2 = (done.byOnion.get(prefix) ?? 0) + 1;
164040
+ setImmediate(() => {
164041
+ try {
164042
+ const now = streams.get(id);
164043
+ if (!open6() || now !== stream || now.stamp !== stamp || !STALL_WAITING.has(now.status)) return;
164044
+ session.send(`CLOSESTREAM ${id} 1`);
164045
+ try {
164046
+ appendFileSync(
164047
+ join51(managedTorDir(home), STALL_CLOSE_LOG),
164048
+ `${(/* @__PURE__ */ new Date()).toISOString()} tor ${torStart2} close ${number2} onion ${prefix} stream ${id} ${now.status.toLowerCase()}
164049
+ `
164050
+ );
164051
+ } catch {
164052
+ stopped = true;
164053
+ }
164054
+ } catch {
164055
+ }
164056
+ });
164057
+ };
164058
+ session = await controlCheck(home, state2, { unref: true, events: (line) => {
164059
+ seq3 += 1;
164060
+ const before = previousNew;
164061
+ previousNew = void 0;
164062
+ const w = line.split(" ");
164063
+ if (w[1] === "STREAM" && /^\d{1,20}$/.test(w[2] ?? "")) {
164064
+ if (w[3] === "NEW" && w.includes("PURPOSE=DIR_FETCH")) {
164065
+ streams.set(w[2], { seq: seq3, stamp: seq3, status: "NEW" });
164066
+ previousNew = w[2];
164067
+ return;
164068
+ }
164069
+ const known = streams.get(w[2]);
164070
+ if (known) {
164071
+ known.status = w[3];
164072
+ known.stamp = seq3;
164073
+ if (w[3] === "CLOSED" || w[3] === "FAILED") streams.delete(w[2]);
164074
+ }
164075
+ return;
164076
+ }
164077
+ if (w[1] !== "HS_DESC") return;
164078
+ const since = lastRequested;
164079
+ if (w[2] === "REQUESTED") lastRequested = seq3;
164080
+ if (!ours.has(w[3])) return;
164081
+ const hsdir = /^\$([0-9A-F]{40})/.exec(w[5] ?? "")?.[1];
164082
+ if (!hsdir) return;
164083
+ if (w[2] === "RECEIVED") {
164084
+ got.add(w[3]);
164085
+ ended2.add(`${w[3]} ${hsdir}`);
164086
+ return;
164087
+ }
164088
+ if (w[2] === "FAILED") {
164089
+ ended2.add(`${w[3]} ${hsdir}`);
164090
+ return;
164091
+ }
164092
+ if (w[2] !== "REQUESTED") return;
164093
+ if (!before || matched.has(before)) return;
164094
+ const waiting = [...streams].filter(([id, s3]) => s3.seq > since && !matched.has(id) && STALL_WAITING.has(s3.status));
164095
+ if (waiting.length !== 1 || waiting[0][0] !== before) return;
164096
+ matched.add(before);
164097
+ const timer = setTimeout(() => {
164098
+ try {
164099
+ close(w[3], hsdir, before);
164100
+ } catch {
164101
+ }
164102
+ }, STALL_CLOSE_MS);
164103
+ timer.unref?.();
164104
+ timers.push(timer);
164105
+ } });
164106
+ if (!session) return;
164107
+ process.once("exit", () => {
164108
+ for (const timer of timers) clearTimeout(timer);
164109
+ try {
164110
+ session.close();
164111
+ } catch {
164112
+ }
164113
+ });
164114
+ } catch {
164115
+ }
164116
+ });
164117
+ }
164118
+ var ownTorPlatform, MAC, LINUX, SYSTEM2, bundle, managedTorDir, stateFile, bundleDir, torExe, MAC_SIGNED, COMPLETE, LINUX_TOR, BUNDLE_FILES, logFile, BOOTSTRAP_STALL_MS, BOOTSTRAP_MAX_MS, STALL_RESTART_PERCENT, RESTART_MIN_MS, REACHED_RELAY_PERCENT, phaseWords, DOWNLOAD_TIMEOUT_MS, BIND_TRIES, POLL_MS2, pidAlive5, WIN_OWN_TOR, STOP_WAIT_MS, cookieFile, CONTROL_TIMEOUT_MS, SERVER_KEY, CLIENT_KEY, failure2, sleep4, tunnelOf, bundleComplete, LINUX_HASHES, fileSha256, startErrorsFile, NOTICE_READ_MAX, TUNNEL_LISTENER_LINE, ownPortsFile, OWN_PORTS_MAX, OWN_PORTS_READ_MAX, EVENT_LINE_MAX, EVENT_BLOCK_LINES, TOR_TIMING_MAX, HS_DESC_ACTIONS, HS_DESC_REASONS, CIRC_STATUSES, CIRC_PURPOSES, CIRC_HS_STATES, CIRC_REASONS, STREAM_STATUSES, STALL_CLOSE_MS, STALL_CLOSE_CAP, STALL_CLOSE_LOG, STALL_LOG_TAIL, STALL_WAITING;
163933
164119
  var init_managedTor = __esm({
163934
164120
  "wallet/src/net/managedTor.mjs"() {
163935
164121
  "use strict";
@@ -164117,6 +164303,12 @@ public static class ShinjukuOwnTor {
164117
164303
  ]);
164118
164304
  STREAM_STATUSES = /* @__PURE__ */ new Set(["NEW", "SENTCONNECT", "SUCCEEDED", "FAILED", "CLOSED", "DETACHED"]);
164119
164305
  startTorTimingMarks();
164306
+ STALL_CLOSE_MS = 1e4;
164307
+ STALL_CLOSE_CAP = 2;
164308
+ STALL_CLOSE_LOG = "stall-closes.log";
164309
+ STALL_LOG_TAIL = 65536;
164310
+ STALL_WAITING = /* @__PURE__ */ new Set(["NEW", "DETACHED"]);
164311
+ startStallCloser();
164120
164312
  }
164121
164313
  });
164122
164314
 
@@ -174732,11 +174924,15 @@ function hostAddedNext(target, app, platform) {
174732
174924
  }
174733
174925
  return RESTART_APP(app);
174734
174926
  }
174735
- function allowWalletChecks(deps) {
174927
+ function allowWalletChecks(deps, { codeTab = false } = {}) {
174736
174928
  const file = claudeCodeSettingsFile({ env: deps.env, home: deps.homedir() });
174737
174929
  try {
174738
174930
  const { changed, backup } = allowInClaudeCode(file);
174739
- return { same: !changed, say: `Claude Code runs the wallet's checks that move no money (balance, receipts) without a question${backup ? ` (its old settings file was copied to ${backup}, readable by you alone)` : ""}. Claude Code may start in auto mode: then a payment or a send can run with no question, or be blocked. Press shift+tab until it shows manual mode: there every payment and send asks you first. To undo the wallet's rules, remove the shinjuku rules in Claude Code's /permissions.` };
174931
+ const kept3 = backup ? ` (its old settings file was copied to ${backup}, readable by you alone)` : "";
174932
+ if (codeTab) {
174933
+ return { same: !changed, say: `The Code tab runs the wallet's checks that move no money (balance, receipts) without a question${kept3}. In Auto mode a payment or a send can run with no question, or be blocked: choose Manual in the mode selector under the prompt box, and every payment and send asks you first. To undo the wallet's rules, remove the shinjuku rules in ${file}.` };
174934
+ }
174935
+ return { same: !changed, say: `Claude Code runs the wallet's checks that move no money (balance, receipts) without a question${kept3}. Claude Code may start in auto mode: then a payment or a send can run with no question, or be blocked. In a terminal, press shift+tab until it shows manual mode; in the Claude app's Code tab, choose Manual in the mode selector under the prompt box. There every payment and send asks you first. To undo the wallet's rules, remove the shinjuku rules in Claude Code's /permissions, or in ${file}.` };
174740
174936
  } catch (error) {
174741
174937
  const unreadable = String(error.message).startsWith("setup_host_config_unreadable:");
174742
174938
  return { same: false, say: `Claude Code still asks before each wallet check: ${unreadable ? `the wallet cannot read the settings in ${file}, so it did not change that file` : `the wallet could not write ${file}`}.` };
@@ -174818,6 +175014,121 @@ async function hostCheckProxy(home, deps, noTor) {
174818
175014
  }
174819
175015
  return { url: proxy.url };
174820
175016
  }
175017
+ var hostWriteCode = (error) => String(error?.message).match(/^(setup_host_config_[a-z_]+): /)?.[1];
175018
+ function hostWriteWhy(code2, file, app) {
175019
+ if (code2 === "setup_host_config_conflict") {
175020
+ return `${file} already has another server named "${MCP_SERVER_NAME}", and the wallet did not change that file; to use the wallet there, put the entry below in its place`;
175021
+ }
175022
+ if (code2 === "setup_host_config_unreadable") return `the wallet cannot read the settings in ${file}, so it did not change that file; fix that file, then add the entry below to it by hand`;
175023
+ if (code2 === "setup_host_config_acl_failed") return `the wallet could not limit a new copy of ${file} to you alone, so it did not change that file; add the entry below to it by hand`;
175024
+ if (code2 === "setup_host_config_changed") return `${app} changed its settings while setup ran, so the wallet left ${file} as ${app} wrote it; run this step again`;
175025
+ if (code2 === "setup_host_config_link_broken") return `${file} is a link to a file that does not exist, so the wallet did not change it; fix that link, or add the entry below by hand`;
175026
+ if (code2 === "setup_host_config_path_dropped") {
175027
+ return `${app} does not pass a PATH to the servers it starts, and here the wallet needs one to find Node.js, so the wallet did not change ${file}; install Node.js so that a new terminal finds the node command, then do this step again`;
175028
+ }
175029
+ return `the wallet could not write ${file}, so that file is unchanged; add the entry below to it by hand`;
175030
+ }
175031
+ var CLAUDE_APP_CODE = "the Claude app (Code)";
175032
+ function claudeAppQuit(platform) {
175033
+ return platform === "win32" ? "right-click its icon by the clock (it may be under the ^ arrow there) and choose Exit (closing its window does not quit it)" : platform === "darwin" ? "choose Claude > Quit Claude, or press Command+Q" : "quit it from its menu";
175034
+ }
175035
+ var CLAUDE_APP_CODE_NEXT = 'Open the Claude app, start a new session in Code, and ask in plain words, for example "what is my Shinjuku balance".';
175036
+ var canonicalJson2 = (value2) => JSON.stringify(value2, (key, each) => each && typeof each === "object" && !Array.isArray(each) ? Object.fromEntries(Object.keys(each).sort().map((name) => [name, each[name]])) : each);
175037
+ function jsonTopKeys(file) {
175038
+ try {
175039
+ const value2 = JSON.parse(readFileSync(file, "utf8"));
175040
+ return value2 && typeof value2 === "object" && !Array.isArray(value2) ? Object.keys(value2) : void 0;
175041
+ } catch {
175042
+ return void 0;
175043
+ }
175044
+ }
175045
+ var CLAUDE_APP_UNKNOWN_TRIES = 3;
175046
+ async function claudeAppClosed(deps, { platform, ask, file, entry }) {
175047
+ const running = deps.claudeAppRunning ?? claudeAppRunning;
175048
+ let unknown = 0;
175049
+ for (; ; ) {
175050
+ const open6 = running({ platform, env: deps.env ?? process.env });
175051
+ if (open6 === false) return true;
175052
+ if (open6 !== true) unknown += 1;
175053
+ if (unknown >= CLAUDE_APP_UNKNOWN_TRIES) {
175054
+ deps.io.out(`Not added to ${CLAUDE_APP_CODE}: setup cannot tell whether the Claude app is closed, so it changed nothing. To add the wallet by hand, first quit the Claude app: ${claudeAppQuit(platform)}. Then open ${file} in a text editor and add these lines inside the { } after "mcpServers" (put a comma after the entry before them; a file with no "mcpServers" gets "mcpServers": { } first):
175055
+ ${JSON.stringify(MCP_SERVER_NAME)}: ${JSON.stringify(entry)}
175056
+ `);
175057
+ return false;
175058
+ }
175059
+ const state2 = open6 === true ? "the Claude app is open" : "setup cannot tell whether the Claude app is open";
175060
+ if (ask === void 0) {
175061
+ deps.io.out(`Not added to ${CLAUDE_APP_CODE}: ${state2}, and it can save ${file} while setup writes it, so setup changed nothing. Quit the Claude app: ${claudeAppQuit(platform)}. Then run this setup line again.
175062
+ `);
175063
+ return false;
175064
+ }
175065
+ const answer = String(await ask(`${state2[0].toUpperCase()}${state2.slice(1)}, and it can save ${file} while setup writes it. Quit it now: ${claudeAppQuit(platform)}. Then press Enter here (or type q and Enter to stop): `)).trim();
175066
+ if (/^q/i.test(answer)) {
175067
+ deps.io.out(`Not added to ${CLAUDE_APP_CODE}; nothing was changed.
175068
+ `);
175069
+ return false;
175070
+ }
175071
+ }
175072
+ }
175073
+ async function addToClaudeAppCode(home, deps, { force = false, npmVersion, ask, noTor = false } = {}) {
175074
+ const io = deps.io;
175075
+ const options = { home, env: deps.env, platform: deps.platform ?? process.platform, npmVersion };
175076
+ const file = join58(deps.env?.CLAUDE_CONFIG_DIR || deps.homedir(), ".claude.json");
175077
+ io.out(`This computer has the Claude app but no claude command, so setup adds the wallet to ${CLAUDE_APP_CODE} itself, in ${file}.
175078
+ `);
175079
+ const check = await hostStartCheck(CLAUDE_APP_CODE, options, deps, { terminal: false, noTor });
175080
+ if (!check.ok) {
175081
+ io.out(`Not added to ${CLAUDE_APP_CODE}: ${hostCheckWords(CLAUDE_APP_CODE, check)}
175082
+ `);
175083
+ return "no";
175084
+ }
175085
+ const written = mcpServerEntry({ ...options, ...check.path ? { path: check.path } : {} });
175086
+ const entry = { type: "stdio", ...written };
175087
+ const existing = claudeCodeEntryOf(deps);
175088
+ if (existing !== void 0 && canonicalJson2(existing) === canonicalJson2(entry)) {
175089
+ const checks2 = allowWalletChecks(deps, { codeTab: true });
175090
+ io.out(`The Claude app (Code) already has the wallet (nothing changed).${checks2.same ? "" : ` ${checks2.say}`} If it does not show the wallet yet, quit the Claude app: ${claudeAppQuit(options.platform)}. ${CLAUDE_APP_CODE_NEXT}
175091
+ `);
175092
+ return "added";
175093
+ }
175094
+ const otherHome = !force && existing !== void 0 ? otherHomeOfClaudeCodeEntry(existing, options) : void 0;
175095
+ const replace = otherHome !== void 0 && ask !== void 0 ? yes(await ask(`The Claude app (Code) already has a Shinjuku Shield entry for another wallet home (${otherHome}). Replace it with this one? [y/N] `)) : void 0;
175096
+ if (replace === false) {
175097
+ io.out(`The Claude app (Code) keeps the wallet in ${otherHome}; nothing was changed. To use this wallet there instead, do this step again and answer y.
175098
+ `);
175099
+ return "kept";
175100
+ }
175101
+ if (existing !== void 0 && !force && replace !== true && !isOlderClaudeCodeEntry(existing, options)) {
175102
+ io.out(`Not added to ${CLAUDE_APP_CODE}: ${hostWriteWhy("setup_host_config_conflict", file, "The Claude app").replace("the entry below", "this entry")}.
175103
+ ${JSON.stringify(MCP_SERVER_NAME)}: ${JSON.stringify(entry)}
175104
+ `);
175105
+ return "no";
175106
+ }
175107
+ if (!await claudeAppClosed(deps, { platform: options.platform, ask, file, entry })) return "no";
175108
+ const keysBefore = jsonTopKeys(file) ?? [];
175109
+ let added;
175110
+ try {
175111
+ added = addToJsonHost(file, entry, { force: force || replace === true });
175112
+ } catch (error) {
175113
+ io.out(`Not added to ${CLAUDE_APP_CODE}: ${hostWriteWhy(hostWriteCode(error), file, "The Claude app").replace("the entry below", "this entry")}.
175114
+ ${JSON.stringify(MCP_SERVER_NAME)}: ${JSON.stringify(entry)}
175115
+ `);
175116
+ return "no";
175117
+ }
175118
+ const keysAfter = jsonTopKeys(file) ?? [];
175119
+ const lost = keysBefore.filter((key) => !keysAfter.includes(key));
175120
+ const readBack = claudeCodeEntryOf(deps);
175121
+ if (lost.length || readBack === void 0 || canonicalJson2(readBack) !== canonicalJson2(entry)) {
175122
+ io.out(`Setup wrote ${file}, but a read after the write ${lost.length ? `misses the settings ${lost.join(", ")}` : "does not show the wallet's entry"}${added.backup ? `; the file from before the write is ${added.backup}, readable by you alone` : ""}. Quit the Claude app: ${claudeAppQuit(options.platform)}. Then run this setup line again.
175123
+ `);
175124
+ return "no";
175125
+ }
175126
+ const checks = allowWalletChecks(deps, { codeTab: true });
175127
+ const homeNow = replace === true ? ` The Claude app (Code) now uses the wallet in ${home}; the wallet in ${otherHome} is unchanged.` : "";
175128
+ io.out(`Added the wallet to ${CLAUDE_APP_CODE}, for all your folders: ${file}${added.backup ? ` (the old file was copied to ${added.backup}, readable by you alone)` : ""}. The wallet starts with this entry (checked).${homeNow} ${checks.say} ${CLAUDE_APP_CODE_NEXT}${noStartFolderWords("claude-code", written)}
175129
+ `);
175130
+ return "added";
175131
+ }
174821
175132
  async function addToHosts(targets, home, deps, { force = false, npmVersion, ask, noTor = false } = {}) {
174822
175133
  const io = deps.io;
174823
175134
  const options = { home, env: deps.env, platform: deps.platform ?? process.platform, npmVersion };
@@ -174825,6 +175136,13 @@ async function addToHosts(targets, home, deps, { force = false, npmVersion, ask,
174825
175136
  const kept3 = /* @__PURE__ */ new Set();
174826
175137
  for (const target of targets) {
174827
175138
  if (target === "claude-code") {
175139
+ const claudeProgram = claudeCodeProgram({ env: deps.env ?? process.env, platform: options.platform, userHome: deps.homedir() });
175140
+ if (claudeProgram === void 0 && (deps.claudeAppHere ?? claudeAppHere)({ platform: options.platform, env: deps.env ?? process.env, home: deps.homedir() })) {
175141
+ const result = await addToClaudeAppCode(home, deps, { force, npmVersion, ask, noTor });
175142
+ if (result === "added") done.add(target);
175143
+ else if (result === "kept") kept3.add(target);
175144
+ continue;
175145
+ }
174828
175146
  const why = claudeCodeShellWhy(options);
174829
175147
  if (why) {
174830
175148
  io.out(`Not added to Claude Code: ${why}.
@@ -174837,7 +175155,6 @@ async function addToHosts(targets, home, deps, { force = false, npmVersion, ask,
174837
175155
  `);
174838
175156
  continue;
174839
175157
  }
174840
- const claudeProgram = claudeCodeProgram({ env: deps.env ?? process.env, platform: options.platform, userHome: deps.homedir() });
174841
175158
  const claudeOptions = { ...options, userHome: deps.homedir() };
174842
175159
  if (claudeProgram === void 0) {
174843
175160
  io.out(`Not added to Claude Code: its command, claude, is not on this computer's PATH and not in the folders where Claude Code's installers put it (${options.platform === "win32" ? "%USERPROFILE%\\.local\\bin, or npm's folder" : "~/.local/bin"}). If Claude Code is not installed, install it (https://code.claude.com/docs/en/setup), then do this step again. If it is in another folder, run this line in a window where claude works:
@@ -174926,8 +175243,8 @@ ${claudeRemoveLines(claudeProgram, options.platform)}
174926
175243
  `);
174927
175244
  done.add(target);
174928
175245
  } catch (error) {
174929
- const code2 = String(error.message).match(/^(setup_host_config_[a-z_]+): /)?.[1];
174930
- const why = code2 === "setup_host_config_conflict" ? `${file} already has another server named "${MCP_SERVER_NAME}", and the wallet did not change that file; to use the wallet there, put the entry below in its place` : code2 === "setup_host_config_unreadable" ? `the wallet cannot read the settings in ${file}, so it did not change that file; fix that file, then add the entry below to it by hand` : code2 === "setup_host_config_acl_failed" ? `the wallet could not limit a new copy of ${file} to you alone, so it did not change that file; add the entry below to it by hand` : code2 === "setup_host_config_changed" ? `${app} changed its settings while setup ran, so the wallet left ${file} as ${app} wrote it; run this step again` : code2 === "setup_host_config_link_broken" ? `${file} is a link to a file that does not exist, so the wallet did not change it; fix that link, or add the entry below by hand` : code2 === "setup_host_config_path_dropped" ? `${app} does not pass a PATH to the servers it starts, and here the wallet needs one to find Node.js, so the wallet did not change ${file}; install Node.js so that a new terminal finds the node command, then do this step again` : `the wallet could not write ${file}, so that file is unchanged; add the entry below to it by hand`;
175246
+ const code2 = hostWriteCode(error);
175247
+ const why = hostWriteWhy(code2, file, app);
174931
175248
  const own = code2 === "setup_host_config_unreadable" ? hostOwnAddLine(target, hostEntry(target, mcpServerEntry(options), options.platform), options.platform) : void 0;
174932
175249
  io.out(`Not added to ${app}: ${why}.${own ? ` Or run ${app}'s own line for it:
174933
175250
  ${own}` : ""}