run402 4.93.2 → 4.95.0

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.
Files changed (316) hide show
  1. package/README.md +61 -59
  2. package/cli.mjs +40 -47
  3. package/core-dist/config.js +52 -18
  4. package/core-dist/control-plane-session.js +31 -6
  5. package/core-dist/keystore.js +7 -7
  6. package/core-dist/profiles.js +9 -7
  7. package/core-dist/{allowance-auth.js → wallet-auth.js} +15 -15
  8. package/{sdk/core-dist/allowance.js → core-dist/wallet.js} +20 -20
  9. package/{sdk/core-dist/write-auth-session.js → core-dist/write-approvals.js} +19 -19
  10. package/gitvault-surface.json +2 -2
  11. package/lib/admin.mjs +6 -6
  12. package/lib/agent.mjs +20 -18
  13. package/lib/ai.mjs +5 -5
  14. package/lib/approve.mjs +81 -0
  15. package/lib/apps.mjs +12 -12
  16. package/lib/archives.mjs +371 -8
  17. package/lib/argparse.mjs +5 -5
  18. package/lib/assets.mjs +14 -14
  19. package/lib/auth.mjs +34 -34
  20. package/lib/billing.mjs +6 -6
  21. package/lib/branches.mjs +7 -7
  22. package/lib/buzz-doctor.mjs +2 -2
  23. package/lib/buzz-notifications.mjs +5 -5
  24. package/lib/buzz.mjs +3 -3
  25. package/lib/buzz.test.mjs +1 -1
  26. package/lib/cache.mjs +1 -1
  27. package/lib/cdn.mjs +2 -2
  28. package/lib/ci.mjs +12 -12
  29. package/lib/claims.mjs +2 -2
  30. package/lib/cold-start.mjs +21 -21
  31. package/lib/command-manifest.mjs +55 -70
  32. package/lib/config.mjs +28 -28
  33. package/lib/contacts.mjs +16 -16
  34. package/lib/contracts.mjs +12 -12
  35. package/lib/credentials.mjs +33 -33
  36. package/lib/daemon-path.mjs +1 -1
  37. package/lib/delegates.mjs +14 -14
  38. package/lib/deliveries.mjs +6 -6
  39. package/lib/deploy-rehearse-discovery.test.mjs +7 -7
  40. package/lib/deploy-v2.mjs +241 -193
  41. package/lib/deploy.mjs +21 -53
  42. package/lib/dev.mjs +3 -3
  43. package/lib/doctor-source-scan.mjs +1 -1
  44. package/lib/doctor.mjs +63 -63
  45. package/lib/domains.mjs +27 -27
  46. package/lib/email.mjs +38 -38
  47. package/lib/errors.mjs +40 -24
  48. package/lib/escalations.mjs +5 -5
  49. package/lib/events.mjs +32 -25
  50. package/lib/feedback.mjs +12 -12
  51. package/lib/functions.mjs +34 -34
  52. package/lib/gitvault-daemon.mjs +1 -1
  53. package/lib/gitvault-scaffold.mjs +2 -2
  54. package/lib/gitvault.mjs +2 -2
  55. package/lib/grants.mjs +7 -7
  56. package/lib/image.mjs +10 -10
  57. package/lib/init.mjs +69 -69
  58. package/lib/jobs.mjs +15 -15
  59. package/lib/lightning-wallet.mjs +28 -28
  60. package/lib/live.mjs +1 -1
  61. package/lib/login.mjs +207 -0
  62. package/lib/logout.mjs +53 -0
  63. package/lib/logs.mjs +8 -8
  64. package/lib/messages.mjs +5 -5
  65. package/lib/next-actions.mjs +16 -16
  66. package/lib/org-context.mjs +13 -13
  67. package/lib/{org.mjs → orgs.mjs} +215 -167
  68. package/lib/pay.mjs +1 -1
  69. package/lib/projects.mjs +70 -84
  70. package/lib/redeem.mjs +7 -8
  71. package/lib/remote-helper-session.mjs +12 -12
  72. package/lib/repos.mjs +83 -83
  73. package/lib/rooms.mjs +105 -69
  74. package/lib/sdk-errors.mjs +10 -5
  75. package/lib/sdk.mjs +3 -3
  76. package/lib/secrets.mjs +13 -13
  77. package/lib/service.mjs +5 -5
  78. package/lib/session-proofs.mjs +21 -0
  79. package/lib/sign-in.mjs +296 -0
  80. package/lib/sites.mjs +22 -22
  81. package/lib/snapshots.mjs +10 -10
  82. package/lib/stats.mjs +2 -2
  83. package/lib/status.mjs +25 -25
  84. package/lib/subdomains.mjs +30 -30
  85. package/lib/subscriptions.mjs +10 -10
  86. package/lib/tier.mjs +29 -22
  87. package/lib/transfer.mjs +59 -86
  88. package/lib/up.mjs +14 -14
  89. package/lib/wallet-context.mjs +4 -4
  90. package/lib/wallet-context.test.mjs +3 -3
  91. package/lib/wallets.mjs +197 -32
  92. package/lib/webhook-secret.mjs +6 -6
  93. package/lib/webhooks.mjs +8 -8
  94. package/lib/whoami.mjs +102 -0
  95. package/package.json +1 -1
  96. package/sdk/core-dist/config.js +52 -18
  97. package/sdk/core-dist/control-plane-session.js +31 -6
  98. package/sdk/core-dist/keystore.js +7 -7
  99. package/sdk/core-dist/profiles.js +9 -7
  100. package/sdk/core-dist/{allowance-auth.js → wallet-auth.js} +15 -15
  101. package/{core-dist/allowance.js → sdk/core-dist/wallet.js} +20 -20
  102. package/{core-dist/write-auth-session.js → sdk/core-dist/write-approvals.js} +19 -19
  103. package/sdk/dist/actions.d.ts +4 -4
  104. package/sdk/dist/actions.d.ts.map +1 -1
  105. package/sdk/dist/app-up.d.ts +2 -2
  106. package/sdk/dist/app-up.d.ts.map +1 -1
  107. package/sdk/dist/config.d.ts +1 -2
  108. package/sdk/dist/config.d.ts.map +1 -1
  109. package/sdk/dist/config.js.map +1 -1
  110. package/sdk/dist/control-plane-credentials.d.ts +8 -8
  111. package/sdk/dist/control-plane-credentials.js +7 -7
  112. package/sdk/dist/credentials.d.ts +20 -20
  113. package/sdk/dist/credentials.d.ts.map +1 -1
  114. package/sdk/dist/credentials.js +1 -1
  115. package/sdk/dist/errors.d.ts +26 -28
  116. package/sdk/dist/errors.d.ts.map +1 -1
  117. package/sdk/dist/errors.js +35 -38
  118. package/sdk/dist/errors.js.map +1 -1
  119. package/sdk/dist/index.d.ts +29 -16
  120. package/sdk/dist/index.d.ts.map +1 -1
  121. package/sdk/dist/index.js +30 -17
  122. package/sdk/dist/index.js.map +1 -1
  123. package/sdk/dist/kernel.d.ts +1 -1
  124. package/sdk/dist/kernel.d.ts.map +1 -1
  125. package/sdk/dist/kernel.js +10 -9
  126. package/sdk/dist/kernel.js.map +1 -1
  127. package/sdk/dist/namespaces/admin.d.ts +52 -121
  128. package/sdk/dist/namespaces/admin.d.ts.map +1 -1
  129. package/sdk/dist/namespaces/admin.js +41 -45
  130. package/sdk/dist/namespaces/admin.js.map +1 -1
  131. package/sdk/dist/namespaces/agent.d.ts +2 -2
  132. package/sdk/dist/namespaces/agent.d.ts.map +1 -1
  133. package/sdk/dist/namespaces/agent.js +2 -2
  134. package/sdk/dist/namespaces/agent.js.map +1 -1
  135. package/sdk/dist/namespaces/ai.d.ts +2 -2
  136. package/sdk/dist/namespaces/ai.js +3 -3
  137. package/sdk/dist/namespaces/ai.js.map +1 -1
  138. package/sdk/dist/namespaces/assets.js +1 -1
  139. package/sdk/dist/namespaces/assets.js.map +1 -1
  140. package/sdk/dist/namespaces/billing.d.ts +6 -3
  141. package/sdk/dist/namespaces/billing.d.ts.map +1 -1
  142. package/sdk/dist/namespaces/billing.js.map +1 -1
  143. package/sdk/dist/namespaces/buzz-notifications.types.d.ts +1 -1
  144. package/sdk/dist/namespaces/buzz.d.ts +2 -2
  145. package/sdk/dist/namespaces/buzz.d.ts.map +1 -1
  146. package/sdk/dist/namespaces/buzz.js +2 -2
  147. package/sdk/dist/namespaces/buzz.js.map +1 -1
  148. package/sdk/dist/namespaces/buzz.types.d.ts +2 -2
  149. package/sdk/dist/namespaces/buzz.types.d.ts.map +1 -1
  150. package/sdk/dist/namespaces/ci.js +3 -3
  151. package/sdk/dist/namespaces/ci.js.map +1 -1
  152. package/sdk/dist/namespaces/credentials.types.d.ts +1 -1
  153. package/sdk/dist/namespaces/deploy.d.ts +1 -1
  154. package/sdk/dist/namespaces/deploy.d.ts.map +1 -1
  155. package/sdk/dist/namespaces/deploy.js +31 -32
  156. package/sdk/dist/namespaces/deploy.js.map +1 -1
  157. package/sdk/dist/namespaces/deploy.types.d.ts +6 -6
  158. package/sdk/dist/namespaces/deploy.types.d.ts.map +1 -1
  159. package/sdk/dist/namespaces/domains.d.ts +10 -2
  160. package/sdk/dist/namespaces/domains.d.ts.map +1 -1
  161. package/sdk/dist/namespaces/domains.js +10 -5
  162. package/sdk/dist/namespaces/domains.js.map +1 -1
  163. package/sdk/dist/namespaces/errors.js +1 -1
  164. package/sdk/dist/namespaces/escalations.d.ts +1 -1
  165. package/sdk/dist/namespaces/escalations.js +1 -1
  166. package/sdk/dist/namespaces/escalations.types.d.ts +2 -2
  167. package/sdk/dist/namespaces/escalations.types.d.ts.map +1 -1
  168. package/sdk/dist/namespaces/events.types.d.ts +1 -1
  169. package/sdk/dist/namespaces/functions.d.ts +1 -1
  170. package/sdk/dist/namespaces/functions.js +2 -2
  171. package/sdk/dist/namespaces/functions.js.map +1 -1
  172. package/sdk/dist/namespaces/gitvault.crypto.d.ts +1 -1
  173. package/sdk/dist/namespaces/gitvault.d.ts +26 -26
  174. package/sdk/dist/namespaces/gitvault.d.ts.map +1 -1
  175. package/sdk/dist/namespaces/gitvault.js +113 -113
  176. package/sdk/dist/namespaces/gitvault.js.map +1 -1
  177. package/sdk/dist/namespaces/me.d.ts +120 -0
  178. package/sdk/dist/namespaces/me.d.ts.map +1 -0
  179. package/sdk/dist/namespaces/me.js +34 -0
  180. package/sdk/dist/namespaces/me.js.map +1 -0
  181. package/sdk/dist/namespaces/org.d.ts +108 -6
  182. package/sdk/dist/namespaces/org.d.ts.map +1 -1
  183. package/sdk/dist/namespaces/org.js +63 -7
  184. package/sdk/dist/namespaces/org.js.map +1 -1
  185. package/sdk/dist/namespaces/org.types.d.ts +29 -9
  186. package/sdk/dist/namespaces/org.types.d.ts.map +1 -1
  187. package/sdk/dist/namespaces/pay.js +3 -3
  188. package/sdk/dist/namespaces/pay.js.map +1 -1
  189. package/sdk/dist/namespaces/projects.d.ts +9 -9
  190. package/sdk/dist/namespaces/projects.js +15 -15
  191. package/sdk/dist/namespaces/projects.js.map +1 -1
  192. package/sdk/dist/namespaces/projects.types.d.ts +28 -12
  193. package/sdk/dist/namespaces/projects.types.d.ts.map +1 -1
  194. package/sdk/dist/namespaces/rooms.d.ts +7 -7
  195. package/sdk/dist/namespaces/rooms.js +17 -17
  196. package/sdk/dist/namespaces/rooms.js.map +1 -1
  197. package/sdk/dist/namespaces/rooms.types.d.ts +9 -9
  198. package/sdk/dist/namespaces/rooms.types.d.ts.map +1 -1
  199. package/sdk/dist/namespaces/service.d.ts +1 -1
  200. package/sdk/dist/namespaces/service.js +1 -1
  201. package/sdk/dist/namespaces/{operator-session.d.ts → session.d.ts} +135 -51
  202. package/sdk/dist/namespaces/session.d.ts.map +1 -0
  203. package/sdk/dist/namespaces/{operator-session.js → session.js} +118 -30
  204. package/sdk/dist/namespaces/session.js.map +1 -0
  205. package/sdk/dist/namespaces/subdomains.d.ts +5 -5
  206. package/sdk/dist/namespaces/subdomains.d.ts.map +1 -1
  207. package/sdk/dist/namespaces/subdomains.js +6 -6
  208. package/sdk/dist/namespaces/subdomains.js.map +1 -1
  209. package/sdk/dist/namespaces/tier.d.ts +44 -21
  210. package/sdk/dist/namespaces/tier.d.ts.map +1 -1
  211. package/sdk/dist/namespaces/tier.js +7 -7
  212. package/sdk/dist/namespaces/tier.js.map +1 -1
  213. package/sdk/dist/namespaces/transfers.d.ts +119 -85
  214. package/sdk/dist/namespaces/transfers.d.ts.map +1 -1
  215. package/sdk/dist/namespaces/transfers.js +31 -38
  216. package/sdk/dist/namespaces/transfers.js.map +1 -1
  217. package/sdk/dist/namespaces/vouchers.d.ts +9 -10
  218. package/sdk/dist/namespaces/vouchers.d.ts.map +1 -1
  219. package/sdk/dist/namespaces/vouchers.js +4 -5
  220. package/sdk/dist/namespaces/vouchers.js.map +1 -1
  221. package/sdk/dist/namespaces/wallets.d.ts +72 -3
  222. package/sdk/dist/namespaces/wallets.d.ts.map +1 -1
  223. package/sdk/dist/namespaces/wallets.js +141 -3
  224. package/sdk/dist/namespaces/wallets.js.map +1 -1
  225. package/sdk/dist/namespaces/write-approval.d.ts +101 -0
  226. package/sdk/dist/namespaces/write-approval.d.ts.map +1 -0
  227. package/sdk/dist/namespaces/write-approval.js +62 -0
  228. package/sdk/dist/namespaces/write-approval.js.map +1 -0
  229. package/sdk/dist/node/actions-node.d.ts +3 -3
  230. package/sdk/dist/node/actions-node.d.ts.map +1 -1
  231. package/sdk/dist/node/actions-node.js +44 -44
  232. package/sdk/dist/node/actions-node.js.map +1 -1
  233. package/sdk/dist/node/assets-node.js +6 -6
  234. package/sdk/dist/node/assets-node.js.map +1 -1
  235. package/sdk/dist/node/{bearer-claim-key.d.ts → bearer-redeem-key.d.ts} +12 -12
  236. package/sdk/dist/node/bearer-redeem-key.d.ts.map +1 -0
  237. package/sdk/dist/node/{bearer-claim-key.js → bearer-redeem-key.js} +21 -21
  238. package/sdk/dist/node/bearer-redeem-key.js.map +1 -0
  239. package/sdk/dist/node/ci.d.ts +1 -1
  240. package/sdk/dist/node/ci.d.ts.map +1 -1
  241. package/sdk/dist/node/ci.js +6 -6
  242. package/sdk/dist/node/ci.js.map +1 -1
  243. package/sdk/dist/node/credentials.d.ts +18 -17
  244. package/sdk/dist/node/credentials.d.ts.map +1 -1
  245. package/sdk/dist/node/credentials.js +29 -28
  246. package/sdk/dist/node/credentials.js.map +1 -1
  247. package/sdk/dist/node/deploy-manifest.d.ts +3 -5
  248. package/sdk/dist/node/deploy-manifest.d.ts.map +1 -1
  249. package/sdk/dist/node/deploy-manifest.js +3 -12
  250. package/sdk/dist/node/deploy-manifest.js.map +1 -1
  251. package/sdk/dist/node/funding-recovery.d.ts +1 -1
  252. package/sdk/dist/node/funding-recovery.d.ts.map +1 -1
  253. package/sdk/dist/node/funding-recovery.js +1 -1
  254. package/sdk/dist/node/funding-recovery.js.map +1 -1
  255. package/sdk/dist/node/gitvault-apply.d.ts +1 -1
  256. package/sdk/dist/node/gitvault-apply.d.ts.map +1 -1
  257. package/sdk/dist/node/gitvault-apply.js +1 -1
  258. package/sdk/dist/node/gitvault-apply.js.map +1 -1
  259. package/sdk/dist/node/gitvault-handoff.d.ts +22 -22
  260. package/sdk/dist/node/gitvault-handoff.d.ts.map +1 -1
  261. package/sdk/dist/node/gitvault-handoff.js +45 -45
  262. package/sdk/dist/node/gitvault-handoff.js.map +1 -1
  263. package/sdk/dist/node/gitvault-prewarm.js +7 -7
  264. package/sdk/dist/node/gitvault-prewarm.js.map +1 -1
  265. package/sdk/dist/node/gitvault-restore.d.ts +1 -1
  266. package/sdk/dist/node/gitvault-restore.js +1 -1
  267. package/sdk/dist/node/index.d.ts +16 -16
  268. package/sdk/dist/node/index.d.ts.map +1 -1
  269. package/sdk/dist/node/index.js +15 -15
  270. package/sdk/dist/node/index.js.map +1 -1
  271. package/sdk/dist/node/manifest-export.js +2 -2
  272. package/sdk/dist/node/manifest-export.js.map +1 -1
  273. package/sdk/dist/node/org-adopt.d.ts +49 -0
  274. package/sdk/dist/node/org-adopt.d.ts.map +1 -0
  275. package/sdk/dist/node/org-adopt.js +77 -0
  276. package/sdk/dist/node/org-adopt.js.map +1 -0
  277. package/sdk/dist/node/paid-fetch.d.ts +7 -7
  278. package/sdk/dist/node/paid-fetch.d.ts.map +1 -1
  279. package/sdk/dist/node/paid-fetch.js +54 -54
  280. package/sdk/dist/node/paid-fetch.js.map +1 -1
  281. package/sdk/dist/node/preflight.d.ts +1 -1
  282. package/sdk/dist/node/preflight.d.ts.map +1 -1
  283. package/sdk/dist/node/preflight.js +1 -1
  284. package/sdk/dist/node/preflight.js.map +1 -1
  285. package/sdk/dist/node/sites-node.js +1 -1
  286. package/sdk/dist/node/sites-node.js.map +1 -1
  287. package/sdk/dist/node/source-scan.d.ts +1 -1
  288. package/sdk/dist/node/source-scan.js +2 -2
  289. package/sdk/dist/node/source-scan.js.map +1 -1
  290. package/sdk/dist/scoped.d.ts +11 -11
  291. package/sdk/dist/scoped.d.ts.map +1 -1
  292. package/sdk/dist/scoped.js +5 -5
  293. package/sdk/dist/scoped.js.map +1 -1
  294. package/core-dist/operator-session.js +0 -154
  295. package/lib/allowance.mjs +0 -355
  296. package/lib/cloud.mjs +0 -256
  297. package/lib/core.mjs +0 -123
  298. package/lib/operator-proofs.mjs +0 -22
  299. package/lib/operator.mjs +0 -771
  300. package/sdk/core-dist/operator-session.js +0 -154
  301. package/sdk/dist/namespaces/allowance.d.ts +0 -79
  302. package/sdk/dist/namespaces/allowance.d.ts.map +0 -1
  303. package/sdk/dist/namespaces/allowance.js +0 -149
  304. package/sdk/dist/namespaces/allowance.js.map +0 -1
  305. package/sdk/dist/namespaces/operator-session.d.ts.map +0 -1
  306. package/sdk/dist/namespaces/operator-session.js.map +0 -1
  307. package/sdk/dist/namespaces/operator.d.ts +0 -359
  308. package/sdk/dist/namespaces/operator.d.ts.map +0 -1
  309. package/sdk/dist/namespaces/operator.js +0 -272
  310. package/sdk/dist/namespaces/operator.js.map +0 -1
  311. package/sdk/dist/node/bearer-claim-key.d.ts.map +0 -1
  312. package/sdk/dist/node/bearer-claim-key.js.map +0 -1
  313. package/sdk/dist/node/operator-claim.d.ts +0 -49
  314. package/sdk/dist/node/operator-claim.d.ts.map +0 -1
  315. package/sdk/dist/node/operator-claim.js +0 -77
  316. package/sdk/dist/node/operator-claim.js.map +0 -1
package/lib/whoami.mjs ADDED
@@ -0,0 +1,102 @@
1
+ /**
2
+ * `run402 whoami` — who this CLI acts as: the principal, its org memberships,
3
+ * and the sign-in session (`session.grade`: `browser` | `loopback` | `device`,
4
+ * or `null` for a wallet caller) from `GET /agent/v1/whoami`, plus the write
5
+ * approvals cached on this machine. See sign-in.mjs. `--set-name <name>`
6
+ * sets the principal's display name (`PATCH /agent/v1/me`) and prints the
7
+ * updated identity.
8
+ */
9
+
10
+ import { fail, reportSdkError } from "./sdk-errors.mjs";
11
+ import { getSdk } from "./sdk.mjs";
12
+ import { normalizeArgv, hasHelp, assertKnownFlags, flagValue, positionalArgs } from "./argparse.mjs";
13
+ import { loadLiveControlPlaneSession, clearControlPlaneSession } from "../core-dist/control-plane-session.js";
14
+ import { readApprovals } from "../core-dist/write-approvals.js";
15
+
16
+ const HELP = `run402 whoami — who this CLI acts as
17
+
18
+ Usage:
19
+ run402 whoami
20
+ run402 whoami --set-name <name>
21
+
22
+ Calls GET /agent/v1/whoami. With a live sign-in session ('run402 login') it
23
+ reads as that session and reports session.grade: loopback (full), browser, or
24
+ device (read-only). Without one it reads as the active wallet and session is
25
+ null. The output also lists the write approvals cached on this machine
26
+ ('run402 approve'), each with its action, target, and expiry.
27
+
28
+ --set-name <name> sets this principal's display name (PATCH /agent/v1/me,
29
+ 1-64 characters): the name promotion credit, \`run402 up\`'s room presence,
30
+ and audit surfaces show. \`up\` sets a detected default when it is empty. It
31
+ is sent with the active wallet, and the output is the updated identity.
32
+ For local wallet/profile state use 'run402 status'.
33
+ `;
34
+
35
+ /** Live cached write approvals: action, target, expiry. Never the token. */
36
+ function cachedApprovals(nowMs = Date.now()) {
37
+ try {
38
+ return readApprovals()
39
+ .filter((a) => a.expires_at > nowMs)
40
+ .map((a) => ({
41
+ action: a.action,
42
+ org_id: a.org_id ?? null,
43
+ project_id: a.project_id ?? null,
44
+ expires_at: new Date(a.expires_at).toISOString(),
45
+ }));
46
+ } catch {
47
+ return [];
48
+ }
49
+ }
50
+
51
+ export async function run(args = []) {
52
+ args = normalizeArgv(args);
53
+ if (hasHelp(args)) {
54
+ console.log(HELP);
55
+ process.exit(0);
56
+ }
57
+ assertKnownFlags(args, ["--help", "-h", "--set-name"], ["--set-name"]);
58
+ const extra = positionalArgs(args, ["--set-name"]);
59
+ if (extra.length > 0) {
60
+ fail({ code: "BAD_USAGE", message: `Unexpected argument for whoami: ${extra[0]}`, hint: "Use `run402 whoami` or `run402 whoami --set-name <name>`." });
61
+ }
62
+ const setName = flagValue(args, "--set-name");
63
+ if (setName !== null && setName.trim() === "") {
64
+ fail({
65
+ code: "BAD_USAGE",
66
+ message: "--set-name must not be empty.",
67
+ details: { field: "--set-name" },
68
+ hint: "Pass a 1-64 character display name.",
69
+ });
70
+ }
71
+ const sdk = getSdk();
72
+ if (setName !== null) {
73
+ try {
74
+ const updated = await sdk.orgs.setDisplayName(setName.trim());
75
+ console.log(JSON.stringify({ ...updated, write_approvals: cachedApprovals() }, null, 2));
76
+ } catch (err) {
77
+ reportSdkError(err);
78
+ }
79
+ return;
80
+ }
81
+ const session = loadLiveControlPlaneSession();
82
+ let who;
83
+ try {
84
+ who = session
85
+ ? await sdk.session.whoami({ token: session.control_plane_session_token })
86
+ : await sdk.orgs.whoami();
87
+ } catch (err) {
88
+ // A cached session the gateway no longer honours (revoked or expired
89
+ // server-side): drop it so the next command does not replay a dead token.
90
+ if (session && err && err.status === 401) {
91
+ clearControlPlaneSession();
92
+ return fail({
93
+ code: "SESSION_INVALID",
94
+ message: "The cached sign-in session is no longer valid (revoked or expired).",
95
+ hint: "Run 'run402 login' to sign in again.",
96
+ next_actions: [{ type: "authenticate", command: "run402 login" }],
97
+ });
98
+ }
99
+ return reportSdkError(err);
100
+ }
101
+ console.log(JSON.stringify({ ...who, write_approvals: cachedApprovals() }, null, 2));
102
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "run402",
3
- "version": "4.93.2",
3
+ "version": "4.95.0",
4
4
  "description": "CLI for Run402 — full-stack backend infrastructure for AI agents: Postgres, auth, storage, serverless functions and atomic deploys. Paid with x402/MPP. Includes $0.03 image generation.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,6 +1,6 @@
1
1
  import { homedir } from "node:os";
2
2
  import { dirname, join } from "node:path";
3
- import { existsSync, renameSync, mkdirSync, chmodSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { existsSync, renameSync, mkdirSync, chmodSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
4
4
  import { randomBytes } from "node:crypto";
5
5
  import { describeRejectedValue } from "./redact.js";
6
6
  export const DEFAULT_API_BASE = "https://api.run402.com";
@@ -118,7 +118,7 @@ export function getProfilesDir() {
118
118
  * The effective config directory for the *active* wallet. The `default` wallet
119
119
  * resolves to the base dir (zero migration for existing single-wallet
120
120
  * installs); any named wallet resolves to `{base}/profiles/<name>`. Because
121
- * keystore, allowance, and meta paths all derive from this, switching the
121
+ * keystore, wallet, and meta paths all derive from this, switching the
122
122
  * profile env var moves the whole wallet bundle atomically — and the SDK/MCP
123
123
  * inherit profile selection for free.
124
124
  */
@@ -232,27 +232,61 @@ export function isCoreApiTarget() {
232
232
  return true;
233
233
  return false;
234
234
  }
235
- export function getAllowancePath() {
236
- if (process.env.RUN402_ALLOWANCE_PATH)
237
- return process.env.RUN402_ALLOWANCE_PATH;
238
- const dir = getConfigDir();
239
- const newPath = join(dir, "allowance.json");
240
- const oldPath = join(dir, "wallet.json");
241
- // Auto-migrate from wallet.json → allowance.json. renameSync preserves the
242
- // source file's mode, so a legacy world-readable wallet.json (mode 0644)
243
- // would otherwise carry that mode forward and leave the private key
244
- // world-readable on a shared machine. Tighten to 0600 after the rename.
245
- if (!existsSync(newPath) && existsSync(oldPath)) {
246
- mkdirSync(dir, { recursive: true });
247
- renameSync(oldPath, newPath);
235
+ /**
236
+ * The file that holds a wallet's key, in the base config dir (the `default`
237
+ * wallet) and in each `profiles/<name>/` directory.
238
+ */
239
+ export const WALLET_FILE_NAME = "wallet.json";
240
+ /** The name the wallet key file had before it was `wallet.json`. */
241
+ const PREVIOUS_WALLET_FILE_NAME = "allowance.json";
242
+ const walletFilesMovedFor = new Set();
243
+ /**
244
+ * One-time local move of the wallet key file to its current name: in the base
245
+ * config dir and every `profiles/<name>/` directory, `allowance.json` is
246
+ * renamed to `wallet.json` (an atomic same-directory rename) when
247
+ * `wallet.json` is absent, then tightened to 0600. A directory that already
248
+ * holds `wallet.json` is left untouched. Runs once per base dir per process;
249
+ * nothing reads the previous name afterwards.
250
+ */
251
+ export function moveWalletFiles() {
252
+ const base = getConfigBaseDir();
253
+ if (walletFilesMovedFor.has(base))
254
+ return;
255
+ walletFilesMovedFor.add(base);
256
+ const dirs = [base];
257
+ try {
258
+ for (const entry of readdirSync(join(base, "profiles"), { withFileTypes: true })) {
259
+ if (entry.isDirectory())
260
+ dirs.push(join(base, "profiles", entry.name));
261
+ }
262
+ }
263
+ catch {
264
+ // No profiles directory yet.
265
+ }
266
+ for (const dir of dirs) {
267
+ const from = join(dir, PREVIOUS_WALLET_FILE_NAME);
268
+ const to = join(dir, WALLET_FILE_NAME);
269
+ if (existsSync(to) || !existsSync(from))
270
+ continue;
271
+ try {
272
+ renameSync(from, to);
273
+ }
274
+ catch {
275
+ continue;
276
+ }
248
277
  try {
249
- chmodSync(newPath, 0o600);
278
+ chmodSync(to, 0o600);
250
279
  }
251
280
  catch {
252
281
  // Best-effort (e.g. Windows / exotic filesystems). Read-time self-heal
253
- // in readAllowance() is the backstop.
282
+ // in readWallet() is the backstop.
254
283
  }
255
284
  }
256
- return newPath;
285
+ }
286
+ export function getWalletPath() {
287
+ if (process.env.RUN402_WALLET_PATH)
288
+ return process.env.RUN402_WALLET_PATH;
289
+ moveWalletFiles();
290
+ return join(getConfigDir(), WALLET_FILE_NAME);
257
291
  }
258
292
  //# sourceMappingURL=config.js.map
@@ -10,6 +10,14 @@ export function getControlPlaneSessionPath() {
10
10
  return (process.env.RUN402_CONTROL_PLANE_SESSION_PATH ||
11
11
  join(getConfigBaseDir(), "control-plane-session.json"));
12
12
  }
13
+ /**
14
+ * Read a wire grade. An unknown or absent value is treated as `device` (the
15
+ * read-only grade) so a cache the client cannot classify never claims more
16
+ * authority than the gateway will grant.
17
+ */
18
+ function toGrade(raw) {
19
+ return raw === "browser" || raw === "loopback" || raw === "device" ? raw : "device";
20
+ }
13
21
  /** Tighten 0600 if group/other-readable, warning once. Best-effort, POSIX-only. */
14
22
  function selfHealPermissions(p) {
15
23
  if (process.platform === "win32")
@@ -50,20 +58,20 @@ export function readControlPlaneSession(path) {
50
58
  return null;
51
59
  }
52
60
  if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
53
- throw new Error("control-plane-session.json must contain a JSON object. Delete it and run 'run402 operator login --loopback' to recreate it.");
61
+ throw new Error("control-plane-session.json must contain a JSON object. Delete it and run 'run402 login' to recreate it.");
54
62
  }
55
63
  const data = parsed;
56
64
  if (typeof data.control_plane_session_token !== "string" ||
57
65
  data.control_plane_session_token.length === 0) {
58
- throw new Error("control-plane-session.json missing valid 'control_plane_session_token'. Run 'run402 operator login --loopback' to refresh it.");
66
+ throw new Error("control-plane-session.json missing valid 'control_plane_session_token'. Run 'run402 login' to refresh it.");
59
67
  }
60
68
  if (typeof data.expires_at !== "number" || !Number.isFinite(data.expires_at)) {
61
- throw new Error("control-plane-session.json missing valid 'expires_at'. Run 'run402 operator login --loopback' to refresh it.");
69
+ throw new Error("control-plane-session.json missing valid 'expires_at'. Run 'run402 login' to refresh it.");
62
70
  }
63
71
  return {
64
72
  control_plane_session_token: data.control_plane_session_token,
65
73
  token_type: typeof data.token_type === "string" ? data.token_type : "Bearer",
66
- provenance: typeof data.provenance === "string" ? data.provenance : "loopback_pkce",
74
+ grade: toGrade(data.grade),
67
75
  principal_id: typeof data.principal_id === "string" ? data.principal_id : "",
68
76
  amr: Array.isArray(data.amr) ? data.amr.filter((a) => typeof a === "string") : [],
69
77
  expires_at: data.expires_at,
@@ -79,7 +87,7 @@ export function saveControlPlaneSession(data, path) {
79
87
  renameSync(tmp, p);
80
88
  chmodSync(p, 0o600);
81
89
  }
82
- /** Delete the cached control-plane session — local half of `operator logout`. Idempotent. */
90
+ /** Delete the cached sign-in session — local half of `run402 logout`. Idempotent. */
83
91
  export function clearControlPlaneSession(path) {
84
92
  const p = path ?? getControlPlaneSessionPath();
85
93
  try {
@@ -105,10 +113,27 @@ export function controlPlaneSessionFromTokenResponse(resp, nowMs = Date.now()) {
105
113
  return {
106
114
  control_plane_session_token: resp.control_plane_session_token,
107
115
  token_type: resp.token_type ?? "Bearer",
108
- provenance: resp.provenance ?? "loopback_pkce",
116
+ grade: toGrade(resp.grade),
109
117
  principal_id: resp.principal_id ?? "",
110
118
  amr: Array.isArray(resp.amr) ? resp.amr.filter((a) => typeof a === "string") : [],
111
119
  expires_at: nowMs + (typeof resp.expires_in === "number" ? resp.expires_in : 0) * 1000,
112
120
  };
113
121
  }
122
+ /**
123
+ * Delete the session caches of the retired email-scoped session
124
+ * (`{base}/operator-session.json`) and the retired approval cache file
125
+ * (`{base}/write-auth-session.json`). Neither is read any more; `run402 login`
126
+ * and `run402 logout` call this so a stale token does not linger on disk.
127
+ * Best-effort and idempotent.
128
+ */
129
+ export function clearRetiredSessionCaches() {
130
+ for (const name of ["operator-session.json", "write-auth-session.json"]) {
131
+ try {
132
+ rmSync(join(getConfigBaseDir(), name), { force: true });
133
+ }
134
+ catch {
135
+ // Best-effort: a failed unlink never blocks login or logout.
136
+ }
137
+ }
138
+ }
114
139
  //# sourceMappingURL=control-plane-session.js.map
@@ -3,7 +3,7 @@ import { dirname, join } from "node:path";
3
3
  import { randomBytes } from "node:crypto";
4
4
  import { getLegacyProjectsPath, getProjectCredentialsPath } from "./config.js";
5
5
  import { clearActiveProjectId as clearProfileActiveProjectId, getActiveProjectId as getProfileActiveProjectId, recordMigration, setActiveProjectId as setProfileActiveProjectId, } from "./profile-state.js";
6
- import { readAllowance } from "./allowance.js";
6
+ import { readWallet } from "./wallet.js";
7
7
  function withFileLock(path, fn, { retries = 200, delayMs = 20 } = {}) {
8
8
  const lockDir = path + ".lock";
9
9
  mkdirSync(dirname(path), { recursive: true });
@@ -99,7 +99,7 @@ function migrateLegacyProjectsJson(targetPath) {
99
99
  // Scoped the same way every other write in this module now is (see
100
100
  // `currentPrincipal`'s doc comment) — an unscoped write here is exactly
101
101
  // what poisons the "unknown"-principal bucket for good on a machine that
102
- // migrates before its wallet allowance exists yet.
102
+ // migrates before its wallet exists yet.
103
103
  setProfileActiveProjectId(legacy.active_project_id, undefined, { principal: currentPrincipal() });
104
104
  }
105
105
  recordMigration("projects_json_import", {
@@ -174,7 +174,7 @@ export function removeProject(projectId, path) {
174
174
  }
175
175
  /**
176
176
  * The active-project scope's `principal`, derived from the CURRENT wallet's
177
- * allowance — matching exactly what `NodeCredentialsProvider.setActiveProject`
177
+ * wallet — matching exactly what `NodeCredentialsProvider.setActiveProject`
178
178
  * (sdk/src/node/credentials.ts) writes after `projects.provision` /
179
179
  * `projects.use`. Without this, every reader here used the profile-state
180
180
  * module's own default (empty) scope, which resolves to a FIXED
@@ -185,7 +185,7 @@ export function removeProject(projectId, path) {
185
185
  * `profile-state.ts#getActiveProjectId` happens to agree), but once the
186
186
  * "unknown" bucket is EVER populated by any principal-less write — the
187
187
  * one-time legacy `projects.json` migration below, or any provision/`use`
188
- * call made before this machine had a wallet allowance — it never gets
188
+ * call made before this machine had a wallet — it never gets
189
189
  * updated again (real wallet operations write to the principal-keyed
190
190
  * bucket, not "unknown") and PERMANENTLY shadows every later wallet-scoped
191
191
  * activation for every caller that reads through this module: `resolveProjectId`
@@ -197,13 +197,13 @@ export function removeProject(projectId, path) {
197
197
  * stale "unknown"-bucket entry first and never falls through to the
198
198
  * freshly-updated flat value.
199
199
  *
200
- * Best-effort: an unreadable/malformed allowance degrades to `null` (the
200
+ * Best-effort: an unreadable/malformed wallet degrades to `null` (the
201
201
  * "unknown" bucket callers tolerate), never a
202
- * throw — this is a read-scoping concern, not an allowance-validity one.
202
+ * throw — this is a read-scoping concern, not a wallet-validity one.
203
203
  */
204
204
  function currentPrincipal() {
205
205
  try {
206
- return readAllowance()?.address ?? null;
206
+ return readWallet()?.address ?? null;
207
207
  }
208
208
  catch {
209
209
  return null;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * A "wallet" is a whole config directory. The reserved `default` wallet lives
5
5
  * at the base config dir (zero migration for existing installs); every named
6
- * wallet lives under `{base}/profiles/<name>/` with its own `allowance.json`,
6
+ * wallet lives under `{base}/profiles/<name>/` with its own `wallet.json`,
7
7
  * `projects.json`, and this module's non-secret `meta.json`.
8
8
  *
9
9
  * Two levels of active state, mirroring the wallet → project model:
@@ -17,7 +17,7 @@
17
17
  import { readFileSync, writeFileSync, mkdirSync, renameSync, chmodSync, existsSync, readdirSync, rmSync, } from "node:fs";
18
18
  import { dirname, join } from "node:path";
19
19
  import { randomBytes } from "node:crypto";
20
- import { getConfigBaseDir, getProfilesDir, DEFAULT_PROFILE, isValidProfileName, } from "./config.js";
20
+ import { getConfigBaseDir, getProfilesDir, DEFAULT_PROFILE, isValidProfileName, moveWalletFiles, WALLET_FILE_NAME, } from "./config.js";
21
21
  import { describeRejectedValue } from "./redact.js";
22
22
  function atomicWrite(p, content, mode) {
23
23
  const dir = dirname(p);
@@ -114,17 +114,19 @@ export function writeMeta(name, meta) {
114
114
  atomicWrite(metaPath(name), JSON.stringify(meta, null, 2), 0o600);
115
115
  }
116
116
  // --- enumeration + lifecycle ---
117
- /** True when a wallet's `allowance.json` exists on disk. */
117
+ /** True when a wallet's `wallet.json` exists on disk. */
118
118
  export function profileExists(name) {
119
- return existsSync(join(profileDir(name), "allowance.json"));
119
+ moveWalletFiles();
120
+ return existsSync(join(profileDir(name), WALLET_FILE_NAME));
120
121
  }
121
122
  /**
122
- * All wallet names on disk: `default` (only if a root allowance.json exists)
123
+ * All wallet names on disk: `default` (only if a root wallet.json exists)
123
124
  * plus every valid directory under `profiles/`.
124
125
  */
125
126
  export function listProfileNames() {
127
+ moveWalletFiles();
126
128
  const names = [];
127
- if (existsSync(join(getConfigBaseDir(), "allowance.json"))) {
129
+ if (existsSync(join(getConfigBaseDir(), WALLET_FILE_NAME))) {
128
130
  names.push(DEFAULT_PROFILE);
129
131
  }
130
132
  try {
@@ -184,7 +186,7 @@ export function renameProfile(oldName, newName) {
184
186
  /* best-effort */
185
187
  }
186
188
  const base = getConfigBaseDir();
187
- for (const f of ["allowance.json", "projects.json", "meta.json"]) {
189
+ for (const f of [WALLET_FILE_NAME, "projects.json", "meta.json"]) {
188
190
  const src = join(base, f);
189
191
  if (existsSync(src))
190
192
  renameSync(src, join(dest, f));
@@ -1,12 +1,12 @@
1
1
  /**
2
- * Allowance auth helper — generates SIWX (Sign-In With X / EIP-4361) headers for Run402 API.
2
+ * SIWX auth helper — generates SIWX (Sign-In With X / EIP-4361) headers for Run402 API.
3
3
  * Uses @noble/curves (lighter than viem) for signing.
4
4
  */
5
5
  import { randomBytes } from "node:crypto";
6
6
  import { secp256k1 } from "@noble/curves/secp256k1.js";
7
7
  import { keccak_256 } from "@noble/hashes/sha3.js";
8
8
  import { bytesToHex } from "@noble/hashes/utils.js";
9
- import { readAllowance } from "./allowance.js";
9
+ import { readWallet } from "./wallet.js";
10
10
  import { getApiBase } from "./config.js";
11
11
  /**
12
12
  * EIP-55 mixed-case checksum encoding.
@@ -21,7 +21,7 @@ export function toChecksumAddress(address) {
21
21
  return checksummed;
22
22
  }
23
23
  /**
24
- * EIP-191 personal_sign: sign a message with the allowance's private key.
24
+ * EIP-191 personal_sign: sign a message with the wallet's private key.
25
25
  */
26
26
  function personalSign(privateKeyHex, address, message) {
27
27
  const msgBytes = new TextEncoder().encode(message);
@@ -86,11 +86,11 @@ export function formatSIWEMessage(opts, address) {
86
86
  return lines.join("\n");
87
87
  }
88
88
  export function buildSIWxAuthHeaders(opts) {
89
- const message = formatSIWEMessage(opts, opts.allowance.address);
90
- const signature = personalSign(opts.allowance.privateKey, opts.allowance.address, message);
89
+ const message = formatSIWEMessage(opts, opts.wallet.address);
90
+ const signature = personalSign(opts.wallet.privateKey, opts.wallet.address, message);
91
91
  const payload = {
92
92
  domain: opts.domain,
93
- address: toChecksumAddress(opts.allowance.address),
93
+ address: toChecksumAddress(opts.wallet.address),
94
94
  statement: opts.statement,
95
95
  uri: opts.uri,
96
96
  version: opts.version ?? "1",
@@ -110,18 +110,18 @@ export function buildSIWxAuthHeaders(opts) {
110
110
  }
111
111
  /**
112
112
  * Get SIWX auth headers for the Run402 API.
113
- * Returns null if no allowance is configured.
113
+ * Returns null if no local wallet is configured.
114
114
  *
115
115
  * @param path - API path (e.g. "/projects/v1") used to build the SIWE uri field.
116
116
  */
117
- export function getAllowanceAuthHeaders(path, allowancePath) {
118
- // readAllowance throws on a malformed-shape allowance file. The
119
- // CLI's higher-level readAllowance wrapper surfaces this as a structured
120
- // BAD_ALLOWANCE_FILE envelope; here we preserve the public contract that
117
+ export function getWalletAuthHeaders(path, walletPath) {
118
+ // readWallet throws on a malformed-shape wallet file. The
119
+ // CLI's higher-level readWallet wrapper surfaces this as a structured
120
+ // BAD_WALLET_FILE envelope; here we preserve the public contract that
121
121
  // this helper returns SIWxAuthHeaders | null. Re-throw so callers above
122
122
  // the CLI's wrapper (e.g. SDK paid-fetch) can decide whether to swallow it.
123
- const allowance = readAllowance(allowancePath);
124
- if (!allowance || !allowance.address || !allowance.privateKey)
123
+ const localWallet = readWallet(walletPath);
124
+ if (!localWallet || !localWallet.address || !localWallet.privateKey)
125
125
  return null;
126
126
  const apiBase = getApiBase();
127
127
  const url = new URL(apiBase);
@@ -132,7 +132,7 @@ export function getAllowanceAuthHeaders(path, allowancePath) {
132
132
  const issuedAt = now.toISOString();
133
133
  const expirationTime = new Date(now.getTime() + 5 * 60 * 1000).toISOString();
134
134
  return buildSIWxAuthHeaders({
135
- allowance,
135
+ wallet: localWallet,
136
136
  domain,
137
137
  uri,
138
138
  statement: "Sign in to Run402",
@@ -151,4 +151,4 @@ function messageChainId(chainId) {
151
151
  function payloadChainId(chainId) {
152
152
  return typeof chainId === "number" ? `eip155:${chainId}` : chainId;
153
153
  }
154
- //# sourceMappingURL=allowance-auth.js.map
154
+ //# sourceMappingURL=wallet-auth.js.map
@@ -1,36 +1,36 @@
1
1
  import { readFileSync, writeFileSync, mkdirSync, existsSync, chmodSync, renameSync, statSync } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
3
  import { randomBytes } from "node:crypto";
4
- import { getAllowancePath } from "./config.js";
4
+ import { getWalletPath } from "./config.js";
5
5
  // 0x-prefixed 40-hex EVM address.
6
6
  const ADDRESS_RE = /^0x[a-fA-F0-9]{40}$/;
7
7
  // 0x-prefixed 64-hex secp256k1 private key (32 bytes).
8
8
  const PRIVATE_KEY_RE = /^0x[a-fA-F0-9]{64}$/;
9
9
  /**
10
- * Load the agent allowance from disk.
10
+ * Load the agent wallet from disk.
11
11
  *
12
- * Returns `null` for the two "no allowance configured" cases:
12
+ * Returns `null` for the two "no local wallet configured" cases:
13
13
  * - the file does not exist
14
14
  * - the file exists but is not parseable JSON (preserve existing UX —
15
- * consumers print "no_allowance" and tell the user to run init)
15
+ * consumers print "no_wallet" and tell the user to run init)
16
16
  *
17
17
  * Throws a structured `Error` when the file parses as JSON but the
18
18
  * shape is wrong (missing/wrong-type/wrong-length fields). Without this guard
19
19
  * downstream callers crash with raw stack traces:
20
- * - `cli/lib/status.mjs` reaches for `allowance.address.toLowerCase()`
20
+ * - `cli/lib/status.mjs` reaches for `wallet.address.toLowerCase()`
21
21
  * and crashes with `TypeError: Cannot read properties of undefined`.
22
- * - `core/src/allowance-auth.ts` passes a malformed `privateKey` to
22
+ * - `core/src/wallet-auth.ts` passes a malformed `privateKey` to
23
23
  * `@noble/curves` which throws "expected 32 bytes, got N".
24
24
  *
25
- * The CLI's `cli/lib/config.mjs:readAllowance()` wrapper and the MCP
25
+ * The CLI's `cli/lib/config.mjs:readWallet()` wrapper and the MCP
26
26
  * `src/tools/{status,init}.ts` callers translate the throw into their own
27
- * structured envelopes (`code: BAD_ALLOWANCE_FILE`).
27
+ * structured envelopes (`code: BAD_WALLET_FILE`).
28
28
  */
29
29
  /**
30
- * If an allowance file is readable by group or other (any of the low 0o077
30
+ * If a wallet file is readable by group or other (any of the low 0o077
31
31
  * bits set), tighten it to 0600 and warn once on stderr. This self-heals the
32
32
  * historical case where a legacy world-readable `wallet.json` (mode 0644) was
33
- * migrated to `allowance.json` via a mode-preserving rename, leaving the
33
+ * migrated to `wallet.json` via a mode-preserving rename, leaving the
34
34
  * private key exposed on a shared machine. Best-effort: POSIX-only and silent
35
35
  * on platforms without meaningful Unix modes (e.g. Windows).
36
36
  */
@@ -48,8 +48,8 @@ function selfHealPermissions(p) {
48
48
  // Best-effort; never block a read on a chmod/stat failure.
49
49
  }
50
50
  }
51
- export function readAllowance(path) {
52
- const p = path ?? getAllowancePath();
51
+ export function readWallet(path) {
52
+ const p = path ?? getWalletPath();
53
53
  if (!existsSync(p))
54
54
  return null;
55
55
  selfHealPermissions(p);
@@ -66,31 +66,31 @@ export function readAllowance(path) {
66
66
  }
67
67
  catch {
68
68
  // Preserve historical UX — completely unparseable input reads as "no
69
- // allowance configured" rather than as an error. Consumers already handle
69
+ // wallet configured" rather than as an error. Consumers already handle
70
70
  // null with a friendly "run 'run402 init'" message.
71
71
  return null;
72
72
  }
73
73
  if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
74
- throw new Error(`allowance.json must contain a JSON object (got ${Array.isArray(parsed) ? "array" : parsed === null ? "null" : typeof parsed}). Back up the file and run 'run402 init' to recreate it.`);
74
+ throw new Error(`wallet.json must contain a JSON object (got ${Array.isArray(parsed) ? "array" : parsed === null ? "null" : typeof parsed}). Back up the file and run 'run402 init' to recreate it.`);
75
75
  }
76
76
  const data = parsed;
77
77
  if (typeof data.address !== "string" || !ADDRESS_RE.test(data.address)) {
78
- throw new Error("allowance.json missing valid 'address' (expected 0x-prefixed 40-hex string). " +
78
+ throw new Error("wallet.json missing valid 'address' (expected 0x-prefixed 40-hex string). " +
79
79
  "Back up the file and run 'run402 init' to recreate it.");
80
80
  }
81
81
  if (typeof data.privateKey !== "string" || !PRIVATE_KEY_RE.test(data.privateKey)) {
82
- throw new Error("allowance.json missing valid 'privateKey' (expected 0x-prefixed 64-hex string). " +
82
+ throw new Error("wallet.json missing valid 'privateKey' (expected 0x-prefixed 64-hex string). " +
83
83
  "Back up the file and run 'run402 init' to recreate it.");
84
84
  }
85
85
  return data;
86
86
  }
87
- export function saveAllowance(data, path) {
88
- const p = path ?? getAllowancePath();
87
+ export function saveWallet(data, path) {
88
+ const p = path ?? getWalletPath();
89
89
  const dir = dirname(p);
90
90
  mkdirSync(dir, { recursive: true });
91
- const tmp = join(dir, `.allowance.${randomBytes(4).toString("hex")}.tmp`);
91
+ const tmp = join(dir, `.wallet.${randomBytes(4).toString("hex")}.tmp`);
92
92
  writeFileSync(tmp, JSON.stringify(data, null, 2), { mode: 0o600 });
93
93
  renameSync(tmp, p);
94
94
  chmodSync(p, 0o600);
95
95
  }
96
- //# sourceMappingURL=allowance.js.map
96
+ //# sourceMappingURL=wallet.js.map