@visa/cli 1.11.0-rc.1 → 1.11.0-rc.2

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/dist/cli.js CHANGED
@@ -1,8 +1,8 @@
1
- "use strict";var Lr=Object.create;var zt=Object.defineProperty;var Or=Object.getOwnPropertyDescriptor;var Nr=Object.getOwnPropertyNames;var Dr=Object.getPrototypeOf,Ur=Object.prototype.hasOwnProperty;var jr=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Mr=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Nr(t))!Ur.call(e,s)&&s!==n&&zt(e,s,{get:()=>t[s],enumerable:!(r=Or(t,s))||r.enumerable});return e};var h=(e,t,n)=>(n=e!=null?Lr(Dr(e)):{},Mr(t||!e||!e.__esModule?zt(n,"default",{value:e,enumerable:!0}):n,e));var lt=jr((xo,Zr)=>{Zr.exports={name:"@visa/cli",version:"1.11.0-rc.1",description:"AI-powered payments for Claude Code",bin:{"visa-cli":"./bin/visa-cli.js"},scripts:{build:"tsc --noEmit && node esbuild.config.js",dev:"tsc --watch",pretest:"pnpm build",start:"node dist/mcp-server/index.js",test:"jest --config jest.config.js","test:unit":"jest --config jest.config.js","test:unit:watch":"jest --config jest.config.js --watch","test:unit:coverage":"jest --config jest.config.js --coverage","test:smoke":"VISA_AUTH_URL=https://auth.visacli.sh jest --config jest.smoke.config.js","test:integration":"jest --config jest.integration.config.js","test:e2e":"jest --config jest.e2e.config.js","test:catalog-e2e":"jest --config jest.catalog-e2e.config.js","test:all":"npm run test:unit && npm run test:integration && npm run test:e2e",prepublishOnly:"npm run build && npm test",lint:"eslint src/**/*.ts",format:'prettier --write "src/**/*.ts"',"format:check":'prettier --check "src/**/*.ts"'},keywords:["visa","checkout","mcp","ai-agent","payments","click-to-pay","usdc","stablecoin"],author:"Visa Crypto Labs",license:"SEE LICENSE IN LICENSE",dependencies:{"@modelcontextprotocol/sdk":"^1.0.0",commander:"^12.1.0",zod:"^3.23.0"},devDependencies:{"@visa-cli/tools":"workspace:*","@changesets/changelog-git":"^0.2.1","@changesets/cli":"^2.31.0","@types/jest":"^30.0.0","@types/node":"^25.6.0","@typescript-eslint/eslint-plugin":"^8.59.0","@typescript-eslint/parser":"^8.59.0","@types/express":"^5.0.0",esbuild:"^0.27.4",express:"^4.21.0",eslint:"^10.0.2","eslint-config-prettier":"^10.1.8",jest:"^29.7.0",prettier:"^3.8.3","ts-jest":"^29.2.0",typescript:"^5.7.0"},engines:{node:">=18.0.0"},mcpName:"io.github.visa-crypto-labs/visa-cli",files:["bin/visa-cli.js","dist/","install.ps1","native/visa-keychain.m","server.json","README.md","LICENSE"]}});var kr=require("commander"),tt=h(require("crypto")),$r=h(require("fs")),R=h(require("os")),se=h(require("path")),xr=require("child_process"),Er=require("util");var Te=require("child_process"),Yt=require("util"),Q=h(require("fs")),Ae=h(require("os")),it=h(require("path"));var z="6820f6e91b762e645c9bf020c0d3673bb99d4a25a824880c0d548e10bb9bc7b1";var G=(0,Yt.promisify)(Te.execFile),at=it.join(Ae.homedir(),".visa-mcp"),ge=it.join(at,"session-token"),B="visa-cli",Z="session-token",Ee="rc-access",Hr=5e3,Pe=class extends Error{constructor(t){super(t),this.name="CredentialAccessError"}};function Vr(e){let t=e;return[t?.message,t?.stderr].filter(n=>typeof n=="string").join(`
2
- `)}function Xt(e){let t=e;if(t?.code==="EPERM"||t?.code==="EACCES")return!0;let n=Vr(e).toLowerCase();return n.includes("operation not permitted")||n.includes("permission denied")}async function Fr(){try{let{stdout:e}=await G("security",["find-generic-password","-s",B,"-a",Z,"-w"],{timeout:5e3});return e.trim()||null}catch(e){if(Xt(e))throw new Pe("Unable to read Visa CLI credentials from macOS Keychain. In sandboxed agents such as Codex, rerun with keychain access or run this command outside the sandbox.");return null}}async function Br(e){try{try{await G("security",["delete-generic-password","-s",B,"-a",Z],{timeout:5e3})}catch{}return await G("security",["add-generic-password","-s",B,"-a",Z,"-w",e],{timeout:5e3}),!0}catch{return!1}}async function Kr(){try{await G("security",["delete-generic-password","-s",B,"-a",Z],{timeout:5e3})}catch{}}async function qr(){if(!ct())return null;try{let{stdout:e}=await G("secret-tool",["lookup","service",B,"account",Z],{timeout:5e3});return e.trim()||null}catch{return null}}async function Gr(e){if(!ct())return!1;try{let t=(0,Te.execFile)("secret-tool",["store","--label",`${B} ${Z}`,"service",B,"account",Z]);return t.stdin?(t.stdin.write(e),t.stdin.end(),await Promise.race([new Promise((n,r)=>{t.on("exit",s=>s===0?n():r(new Error(`secret-tool exited ${s}`))),t.on("error",r)}),new Promise((n,r)=>setTimeout(()=>{t.kill(),r(new Error("secret-tool timed out"))},Hr))]),!0):!1}catch{return!1}}async function Wr(){if(ct())try{await G("secret-tool",["clear","service",B,"account",Z],{timeout:5e3})}catch{}}function ct(){return!!process.env.DBUS_SESSION_BUS_ADDRESS}async function Jr(){try{let{stdout:e}=await G("security",["find-generic-password","-s",B,"-a",Ee,"-w"],{timeout:5e3});return e.trim()||null}catch{return null}}async function zr(e){try{try{await G("security",["delete-generic-password","-s",B,"-a",Ee],{timeout:5e3})}catch{}await G("security",["add-generic-password","-s",B,"-a",Ee,"-w",e],{timeout:5e3})}catch{}}async function Yr(){try{await G("security",["delete-generic-password","-s",B,"-a",Ee],{timeout:5e3})}catch{}}function st(){try{return Q.readFileSync(ge,"utf-8").trim()||null}catch(e){if(Xt(e))throw new Pe(`Unable to read Visa CLI credentials from ${ge}. Check file permissions or rerun with access to the Visa CLI credential directory.`);return null}}function Zt(e){Q.mkdirSync(at,{recursive:!0,mode:448}),Q.writeFileSync(ge,e,{mode:384}),process.platform==="win32"&&Xr(ge)}function ot(){try{Q.unlinkSync(ge)}catch{}}function Xr(e){try{let t=Ae.userInfo().username;(0,Te.execFile)("icacls",[e,"/inheritance:r","/grant:r",`${t}:F`],{timeout:5e3},n=>{n&&console.error(`[visa-cli] icacls ACL restriction failed: ${n.message}`)})}catch(t){console.error(`[visa-cli] Failed to invoke icacls: ${t instanceof Error?t.message:String(t)}`)}}function rt(){switch(process.platform){case"darwin":return{get:Fr,store:Br,delete:Kr};case"linux":return{get:qr,store:Gr,delete:Wr};default:return{get:async()=>st(),store:async e=>{try{return Zt(e),!0}catch{return!1}},delete:async()=>ot(),storesInSessionFile:!0}}}var $=class{static async getSessionToken(){if(process.env.VISA_MOCK_KEYCHAIN==="true")return Promise.resolve("mock-session-token-for-testing");let t=rt(),n=await t.get();if(n)return n;let r=st();return r?(await t.store(r),r):null}static async saveSessionToken(t){if(process.env.VISA_MOCK_KEYCHAIN==="true")return;let n=rt();if(await n.store(t)){if(await n.get()===t){n.storesInSessionFile||ot();return}await n.delete()}if(Zt(t),st()!==t)throw new Error("Failed to persist session token. "+(process.platform==="darwin"?'Check Keychain Access permissions for "visa-cli".':`Ensure ${at} is writable.`))}static async getRcAccessToken(){return process.env.VISA_MOCK_KEYCHAIN==="true"?z:Jr()}static async saveRcAccessToken(t){process.env.VISA_MOCK_KEYCHAIN!=="true"&&await zr(t)}static async deleteSessionToken(){if(process.env.VISA_MOCK_KEYCHAIN==="true")return;await rt().delete(),ot()}static async clearAll(){await this.deleteSessionToken(),await Yr()}};var Re=h(require("crypto")),Ie=h(require("tty")),Le=h(require("fs"));function Qr(e){return/-rc\.|-beta\./.test(e)}function ut(e){return Re.createHash("sha256").update(e.trim()).digest("hex")}function Qt(e){return z==="SKIP"?!0:Re.timingSafeEqual(Buffer.from(ut(e)),Buffer.from(z))}function es(e){return new Promise((t,n)=>{let r=Le.openSync("/dev/tty","r+"),s=new Ie.ReadStream(r),o=new Ie.WriteStream(r),i=()=>{try{s.destroy()}catch{}try{o.destroy()}catch{}try{Le.closeSync(r)}catch{}};o.write(e),s.setRawMode(!0),s.resume(),s.setEncoding("utf8");let a="";s.on("data",c=>{c==="\r"||c===`
1
+ "use strict";var Or=Object.create;var Zt=Object.defineProperty;var Dr=Object.getOwnPropertyDescriptor;var Ur=Object.getOwnPropertyNames;var jr=Object.getPrototypeOf,Mr=Object.prototype.hasOwnProperty;var Hr=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Vr=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ur(t))!Mr.call(e,s)&&s!==n&&Zt(e,s,{get:()=>t[s],enumerable:!(r=Dr(t,s))||r.enumerable});return e};var h=(e,t,n)=>(n=e!=null?Or(jr(e)):{},Vr(t||!e||!e.__esModule?Zt(n,"default",{value:e,enumerable:!0}):n,e));var dt=Hr((To,es)=>{es.exports={name:"@visa/cli",version:"1.11.0-rc.2",description:"AI-powered payments for Claude Code",bin:{"visa-cli":"./bin/visa-cli.js"},scripts:{build:"tsc --noEmit && node esbuild.config.js",dev:"tsc --watch",pretest:"pnpm build",start:"node dist/mcp-server/index.js",test:"jest --config jest.config.js","test:unit":"jest --config jest.config.js","test:unit:watch":"jest --config jest.config.js --watch","test:unit:coverage":"jest --config jest.config.js --coverage","test:smoke":"VISA_AUTH_URL=https://auth.visacli.sh jest --config jest.smoke.config.js","test:integration":"jest --config jest.integration.config.js","test:e2e":"jest --config jest.e2e.config.js","test:catalog-e2e":"jest --config jest.catalog-e2e.config.js","test:all":"npm run test:unit && npm run test:integration && npm run test:e2e",prepublishOnly:"npm run build && npm test",lint:"eslint src/**/*.ts",format:'prettier --write "src/**/*.ts"',"format:check":'prettier --check "src/**/*.ts"'},keywords:["visa","checkout","mcp","ai-agent","payments","click-to-pay","usdc","stablecoin"],author:"Visa Crypto Labs",license:"SEE LICENSE IN LICENSE",dependencies:{"@modelcontextprotocol/sdk":"^1.0.0",commander:"^12.1.0",zod:"^3.23.0"},devDependencies:{"@visa-cli/tools":"workspace:*","@changesets/changelog-git":"^0.2.1","@changesets/cli":"^2.31.0","@types/jest":"^30.0.0","@types/node":"^25.6.0","@typescript-eslint/eslint-plugin":"^8.59.0","@typescript-eslint/parser":"^8.59.0","@types/express":"^5.0.0",esbuild:"^0.27.4",express:"^4.21.0",eslint:"^10.0.2","eslint-config-prettier":"^10.1.8",jest:"^29.7.0",prettier:"^3.8.3","ts-jest":"^29.2.0",typescript:"^5.7.0"},engines:{node:">=18.0.0"},mcpName:"io.github.visa-crypto-labs/visa-cli",files:["bin/visa-cli.js","dist/","install.ps1","native/visa-keychain.m","server.json","README.md","LICENSE"]}});var $r=require("commander"),rt=h(require("crypto")),Er=h(require("fs")),R=h(require("os")),se=h(require("path")),Pr=require("child_process"),Tr=require("util");var Ae=require("child_process"),Qt=require("util"),Q=h(require("fs")),Re=h(require("os")),ct=h(require("path"));var z="6820f6e91b762e645c9bf020c0d3673bb99d4a25a824880c0d548e10bb9bc7b1";var G=(0,Qt.promisify)(Ae.execFile),lt=ct.join(Re.homedir(),".visa-mcp"),ge=ct.join(lt,"session-token"),B="visa-cli",Z="session-token",Pe="rc-access",Fr=5e3,Te=class extends Error{constructor(t){super(t),this.name="CredentialAccessError"}};function Br(e){let t=e;return[t?.message,t?.stderr].filter(n=>typeof n=="string").join(`
2
+ `)}function en(e){let t=e;if(t?.code==="EPERM"||t?.code==="EACCES")return!0;let n=Br(e).toLowerCase();return n.includes("operation not permitted")||n.includes("permission denied")}async function Kr(){try{let{stdout:e}=await G("security",["find-generic-password","-s",B,"-a",Z,"-w"],{timeout:5e3});return e.trim()||null}catch(e){if(en(e))throw new Te("Unable to read Visa CLI credentials from macOS Keychain. In sandboxed agents such as Codex, rerun with keychain access or run this command outside the sandbox.");return null}}async function qr(e){try{try{await G("security",["delete-generic-password","-s",B,"-a",Z],{timeout:5e3})}catch{}return await G("security",["add-generic-password","-s",B,"-a",Z,"-w",e],{timeout:5e3}),!0}catch{return!1}}async function Gr(){try{await G("security",["delete-generic-password","-s",B,"-a",Z],{timeout:5e3})}catch{}}async function Jr(){if(!ut())return null;try{let{stdout:e}=await G("secret-tool",["lookup","service",B,"account",Z],{timeout:5e3});return e.trim()||null}catch{return null}}async function Wr(e){if(!ut())return!1;try{let t=(0,Ae.execFile)("secret-tool",["store","--label",`${B} ${Z}`,"service",B,"account",Z]);return t.stdin?(t.stdin.write(e),t.stdin.end(),await Promise.race([new Promise((n,r)=>{t.on("exit",s=>s===0?n():r(new Error(`secret-tool exited ${s}`))),t.on("error",r)}),new Promise((n,r)=>setTimeout(()=>{t.kill(),r(new Error("secret-tool timed out"))},Fr))]),!0):!1}catch{return!1}}async function zr(){if(ut())try{await G("secret-tool",["clear","service",B,"account",Z],{timeout:5e3})}catch{}}function ut(){return!!process.env.DBUS_SESSION_BUS_ADDRESS}async function Yr(){try{let{stdout:e}=await G("security",["find-generic-password","-s",B,"-a",Pe,"-w"],{timeout:5e3});return e.trim()||null}catch{return null}}async function Xr(e){try{try{await G("security",["delete-generic-password","-s",B,"-a",Pe],{timeout:5e3})}catch{}await G("security",["add-generic-password","-s",B,"-a",Pe,"-w",e],{timeout:5e3})}catch{}}async function Zr(){try{await G("security",["delete-generic-password","-s",B,"-a",Pe],{timeout:5e3})}catch{}}function it(){try{return Q.readFileSync(ge,"utf-8").trim()||null}catch(e){if(en(e))throw new Te(`Unable to read Visa CLI credentials from ${ge}. Check file permissions or rerun with access to the Visa CLI credential directory.`);return null}}function tn(e){Q.mkdirSync(lt,{recursive:!0,mode:448}),Q.writeFileSync(ge,e,{mode:384}),process.platform==="win32"&&Qr(ge)}function at(){try{Q.unlinkSync(ge)}catch{}}function Qr(e){try{let t=Re.userInfo().username;(0,Ae.execFile)("icacls",[e,"/inheritance:r","/grant:r",`${t}:F`],{timeout:5e3},n=>{n&&console.error(`[visa-cli] icacls ACL restriction failed: ${n.message}`)})}catch(t){console.error(`[visa-cli] Failed to invoke icacls: ${t instanceof Error?t.message:String(t)}`)}}function ot(){switch(process.platform){case"darwin":return{get:Kr,store:qr,delete:Gr};case"linux":return{get:Jr,store:Wr,delete:zr};default:return{get:async()=>it(),store:async e=>{try{return tn(e),!0}catch{return!1}},delete:async()=>at(),storesInSessionFile:!0}}}var x=class{static async getSessionToken(){if(process.env.VISA_MOCK_KEYCHAIN==="true")return Promise.resolve("mock-session-token-for-testing");let t=ot(),n=await t.get();if(n)return n;let r=it();return r?(await t.store(r),r):null}static async saveSessionToken(t){if(process.env.VISA_MOCK_KEYCHAIN==="true")return;let n=ot();if(await n.store(t)){if(await n.get()===t){n.storesInSessionFile||at();return}await n.delete()}if(tn(t),it()!==t)throw new Error("Failed to persist session token. "+(process.platform==="darwin"?'Check Keychain Access permissions for "visa-cli".':`Ensure ${lt} is writable.`))}static async getRcAccessToken(){return process.env.VISA_MOCK_KEYCHAIN==="true"?z:Yr()}static async saveRcAccessToken(t){process.env.VISA_MOCK_KEYCHAIN!=="true"&&await Xr(t)}static async deleteSessionToken(){if(process.env.VISA_MOCK_KEYCHAIN==="true")return;await ot().delete(),at()}static async clearAll(){await this.deleteSessionToken(),await Zr()}};var Ie=h(require("crypto")),Le=h(require("tty")),Ne=h(require("fs"));function ts(e){return/-rc\.|-beta\./.test(e)}function ft(e){return Ie.createHash("sha256").update(e.trim()).digest("hex")}function nn(e){return z==="SKIP"?!0:Ie.timingSafeEqual(Buffer.from(ft(e)),Buffer.from(z))}function ns(){try{let e=Ne.openSync("/dev/tty","r+"),t=new Le.ReadStream(e),n=new Le.WriteStream(e),r=!1;return{input:t,output:n,cleanupStreams:()=>{if(!r){r=!0;try{t.destroy()}catch{}try{n.destroy()}catch{}try{Ne.closeSync(e)}catch{}}}}}catch{if(!process.stdin.isTTY)throw new Error("No interactive terminal available. Set VISA_RC_CODE env var instead.");return{input:process.stdin,output:process.stderr,cleanupStreams:()=>{}}}}function rs(e){return new Promise((t,n)=>{let r;try{r=ns()}catch(u){n(u);return}let{input:s,output:o,cleanupStreams:i}=r,a=()=>{s.off("data",l);try{s.setRawMode?.(!1)}catch{}i()};o.write(e),s.setRawMode?.(!0),s.resume(),s.setEncoding("utf8");let c="",l=u=>{u==="\r"||u===`
3
3
  `?(o.write(`
4
- `),i(),t(a)):c===""?(o.write(`
5
- `),i(),n(new Error("Cancelled"))):c==="\x7F"||c==="\b"?a.length>0&&(a=a.slice(0,-1),o.write("\b \b")):(a+=c,o.write("\u2022"))})})}var ts=`
4
+ `),a(),t(c)):u===""?(o.write(`
5
+ `),a(),n(new Error("Cancelled"))):u==="\x7F"||u==="\b"?c.length>0&&(c=c.slice(0,-1),o.write("\b \b")):(c+=u,o.write("\u2022"))};s.on("data",l)})}var ss=`
6
6
  \u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557
7
7
  \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557
8
8
  \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551
@@ -11,31 +11,31 @@
11
11
  \u255A\u2550\u2550\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D
12
12
 
13
13
  This is a Release Candidate build. Access is restricted to Visa employees.
14
- `;async function en(e={}){let t=e.version??lt().version;if(!Qr(t))return;let n=process.env.VISA_RC_CODE;if(n&&Qt(n)){await $.saveRcAccessToken(ut(n));return}if(e.isMcp??!1){let i=await $.getRcAccessToken();if(i&&(z==="SKIP"||i===z))return;process.stderr.write(`[visa-cli] RC build requires access. Run: visa-cli setup
15
- `),process.exit(1)}let s=await $.getRcAccessToken();if(s&&(z==="SKIP"||s===z))return;console.log(ts);let o=3;for(let i=1;i<=o;i++){let a;try{a=await es(" Enter RC access code: ")}catch{process.exit(1)}if(Qt(a)){await $.saveRcAccessToken(ut(a)),console.log(`
14
+ `;async function rn(e={}){let t=e.version??dt().version;if(!ts(t))return;let n=process.env.VISA_RC_CODE;if(n&&nn(n)){await x.saveRcAccessToken(ft(n));return}if(e.isMcp??!1){let i=await x.getRcAccessToken();if(i&&(z==="SKIP"||i===z))return;process.stderr.write(`[visa-cli] RC build requires access. Run: visa-cli setup
15
+ `),process.exit(1)}let s=await x.getRcAccessToken();if(s&&(z==="SKIP"||s===z))return;console.log(ss);let o=3;for(let i=1;i<=o;i++){let a;try{a=await rs(" Enter RC access code: ")}catch{process.exit(1)}if(nn(a)){await x.saveRcAccessToken(ft(a)),console.log(`
16
16
  Access granted. Welcome.
17
17
  `);return}i<o&&console.log(`
18
18
  Invalid code. ${o-i} attempt(s) remaining.
19
19
  `)}console.log(`
20
20
  Invalid code. Contact your team lead.
21
- `),process.exit(1)}var tn=require("child_process");function ns(e=process.env,t=process.platform){return e.VISA_CLI_NO_BROWSER==="1"||e.VISA_CLI_NO_BROWSER==="true"?{headless:!0,reason:"VISA_CLI_NO_BROWSER is set"}:e.CI==="true"||e.CI==="1"?{headless:!0,reason:"CI environment detected"}:e.SSH_CONNECTION||e.SSH_TTY?{headless:!0,reason:"SSH session detected"}:t==="linux"&&!e.DISPLAY&&!e.WAYLAND_DISPLAY?{headless:!0,reason:"Linux with no $DISPLAY or $WAYLAND_DISPLAY"}:{headless:!1}}function rs(e){let n=e.length+4;return[`\u250C${"\u2500".repeat(n)}\u2510`,`\u2502${" ".repeat(2)}${e}${" ".repeat(2)}\u2502`,`\u2514${"\u2500".repeat(n)}\u2518`].join(`
22
- `)}function ss(e,t=process.platform){return t==="darwin"?{cmd:"open",args:[e]}:t==="win32"?{cmd:"cmd",args:["/c","start","",e]}:t==="linux"?{cmd:"xdg-open",args:[e]}:null}async function nn(e,t={}){let n=t.log??(c=>console.log(c)),r=t.env??process.env,s=t.platform??process.platform,o=t.spawn??((c,l,d)=>{(0,tn.execFile)(c,l,f=>d(f))});n(""),n(" Sign in to Visa CLI by opening this URL in your browser:"),n("");for(let c of rs(e).split(`
23
- `))n(` ${c}`);n("");let i=ns(r,s);if(i.headless){n(` (${i.reason} \u2014 skipping browser auto-open.)`),n(" Open the URL above on any device with a browser. The CLI will"),n(" continue waiting for you to complete sign-in."),n("");return}let a=ss(e,s);if(!a){n(` No known browser-open command for platform "${s}".`),n(" Open the URL above manually to continue."),n("");return}await new Promise(c=>{o(a.cmd,a.args,l=>{l?(n(` Could not open browser automatically (${l.message}).`),n(" Open the URL above manually to continue."),n("")):(n(" Opened browser. Waiting for you to sign in..."),n("")),c()})})}var sn=h(require("crypto")),O=h(require("fs")),Oe=h(require("path"));function on(e,t){O.mkdirSync(Oe.dirname(e),{recursive:!0});let n=`${e}.${process.pid}.${sn.randomBytes(8).toString("hex")}.tmp`;try{O.writeFileSync(n,JSON.stringify(t,null,2)+`
24
- `),O.renameSync(n,e)}catch(r){try{O.unlinkSync(n)}catch{}throw r}}function rn(e){return`'${e.replace(/'/g,"'\\''")}'`}var an="# visa-cli-hud-v1";function os(e,t){let n=e??process.execPath,r=t??process.argv[1]??"",s=r?Oe.resolve(r):"";return`${s?`${rn(n)} ${rn(s)} statusline`:"visa-cli statusline"} ${an}`}function cn(e){return typeof e!="string"?!1:e.includes(an)?!0:e.includes("visa-cli")&&e.includes("statusline")}function Ne(e,t=os){let n={},r=!1;if(O.existsSync(e)){r=!0;try{n=JSON.parse(O.readFileSync(e,"utf-8"))}catch(s){return{installed:"malformed-json",message:`~/.claude/settings.json is not valid JSON (${s.message}). Fix the file manually, then run: visa-cli hud enable`}}}if(n.statusLine){let s=typeof n.statusLine=="object"?n.statusLine.command:"";return cn(s)?{installed:"already-visa",message:"Visa HUD already registered in ~/.claude/settings.json."}:{installed:"other-hud-present",message:"Another HUD is already configured (keeping it). To switch to Visa HUD, edit ~/.claude/settings.json \u2192 statusLine.command"}}try{return n.statusLine={type:"command",command:t()},on(e,n),{installed:"new",message:`Visa HUD registered in ~/.claude/settings.json${r?"":" (new file)"}. Restart Claude Code to see it pinned below the input.`}}catch(s){return{installed:"error",message:`Failed to write settings: ${s.message}. Enable manually later with: visa-cli hud enable`}}}function dt(e){if(!O.existsSync(e))return{removed:!1,message:"No ~/.claude/settings.json found."};let t;try{t=JSON.parse(O.readFileSync(e,"utf-8"))}catch(r){return{removed:!1,message:`~/.claude/settings.json is not valid JSON: ${r.message}`}}if(!t.statusLine)return{removed:!1,message:"No statusLine configured."};let n=typeof t.statusLine=="object"?t.statusLine.command:"";return cn(n)?(delete t.statusLine,on(e,t),{removed:!0,message:"Visa HUD removed from ~/.claude/settings.json. Restart Claude Code to take effect."}):{removed:!1,message:"statusLine is owned by another tool \u2014 leaving it alone."}}var Y=h(require("fs")),X=h(require("path")),is=1,ne={CLAUDE_CODE:"claude-code",CODEX:"codex",UNKNOWN:"unknown"},as=["claude","claude-code","codex","all"];function ht(e){let t=e.toLowerCase();return as.includes(t)?t:null}var cs=50,ls=64*1024,ln=10,ft=80;function us(){let e=(process.env.COLORTERM??"").toLowerCase();if(e==="truecolor"||e==="24bit")return!0;let t=(process.env.TERM??"").toLowerCase();return t.includes("truecolor")||t.includes("24bit")}var pt=us(),p={reset:"\x1B[0m",visaBlue:pt?"\x1B[38;2;20;52;203m":"\x1B[38;5;27m",visaBlueSoft:pt?"\x1B[38;2;97;126;229m":"\x1B[38;5;111m",visaGold:pt?"\x1B[38;2;247;182;0m":"\x1B[38;5;220m",green:"\x1B[38;5;48m",dim:"\x1B[2m"};function g(e,t){return e.length===0||process.env.NO_COLOR?e:`${t}${e}${p.reset}`}function un(e){return e.replace(/\u001B\[[0-?]*[ -/]*[@-~]/g,"").replace(/[\u0000-\u001F\u007F]/g,"").length}async function gn(e=process.stdin){return e.isTTY?null:new Promise(t=>{let n=[],r=!1,s=()=>{e.removeListener("data",i),e.removeListener("end",a),e.removeListener("error",c),clearTimeout(l)},o=d=>{r||(r=!0,s(),t(d))},i=d=>{n.push(typeof d=="string"?Buffer.from(d):d)},a=()=>{let d=Buffer.concat(n).toString("utf-8").trim();if(!d)return o(null);try{let f=JSON.parse(d);o(f&&typeof f=="object"?f:null)}catch{o(null)}},c=()=>o(null),l=setTimeout(()=>{n.length>0?a():o(null)},cs);e.on("data",i),e.on("end",a),e.on("error",c)})}function De(e){let n=Math.round(Math.max(0,Math.min(1,e))*10),r="\u2588".repeat(n),s="\u2591".repeat(10-n);return`${g(r||"",p.visaBlueSoft)}${g(s||"",p.dim)}`}function gt(e){return!Number.isFinite(e)||e<0?"0":e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:String(Math.round(e))}function ds(e){if(_s(e))return fs(e);let t=` ${g("\u2502",p.dim)} `,n=mt(e)||"claude",r=e.cwd?P(X.basename(e.cwd)):"",s=yt(e.workspace),o=r||s,i=s&&s!==o?` ${g(`@${s}`,p.visaBlueSoft)}`:"",a=[g(`[${n}]`,p.visaBlueSoft)];o&&a.push(`${g(o,p.visaGold)}${i}`);let c=a.join(t),l=Number(e.context_window?.context_window_size??0),d=typeof e.context_window?.used_percentage=="number"?e.context_window.used_percentage:typeof e.context_window?.remaining_percentage=="number"?100-e.context_window.remaining_percentage:null,f=e.context_window?.current_usage,y=[f?.input_tokens,f?.output_tokens,f?.cache_creation_input_tokens,f?.cache_read_input_tokens].filter(I=>typeof I=="number"&&Number.isFinite(I)),w=y.length>0?y.reduce((I,F)=>I+F,0):null,u=Number(e.context_window?.total_input_tokens??w??f?.input_tokens??0),S=d!==null?Math.max(0,Math.min(1,d/100)):l>0?Math.max(0,Math.min(1,u/l)):0,_=d!==null&&l>0?Math.round(S*l):u,C;if(l>0||d!==null){let I=`${String(Math.round(S*100)).padStart(2," ")}%`,F=l>0?` ${g(`(${gt(_)}/${gt(l)})`,p.dim)}`:"";C=`${g("Context",p.dim)} ${De(S)} ${g(I,p.green)}${F}`}else C=`${g("Context",p.dim)} ${g("-",p.dim)}`;let E=gs(e.rate_limits),V=[C];E&&V.push(E);let ie=V.join(t);return`${c}
25
- ${ie}`}function fs(e){let t=` ${g("\u2502",p.dim)} `,n=wn(e),r=n.model||"codex",s=[g(`[${r}]`,p.visaBlueSoft)];n.project&&s.push(g(n.project,p.visaGold)),n.gitBranch&&s.push(`${g("git",p.dim)} ${g(n.gitBranch,p.visaGold)}`);let o=s.join(t),i=[];if(typeof n.contextUsedPercent=="number"){let c=Math.max(0,Math.min(1,n.contextUsedPercent/100));i.push(`${g("Context",p.dim)} ${De(c)} ${g(`${Math.round(n.contextUsedPercent)}%`,p.green)}`)}else if(typeof n.contextRemainingPercent=="number"){let c=100-n.contextRemainingPercent,l=Math.max(0,Math.min(1,c/100));i.push(`${g("Context",p.dim)} ${De(l)} ${g(`${Math.round(c)}%`,p.green)}`)}typeof n.usedTokens=="number"&&i.push(`${g("Tokens",p.dim)} ${gt(n.usedTokens)}`),n.status&&i.push(`${g("Status",p.dim)} ${g(n.status,p.visaBlueSoft)}`),n.threadTitle&&i.push(`${g("Thread",p.dim)} ${g(n.threadTitle,p.visaBlueSoft)}`);let a=i.length>0?i.join(t):`${g("Context",p.dim)} ${g("-",p.dim)}`;return`${o}
26
- ${a}`}function ps(e){if(typeof e!="number"||e<=0)return"";let n=(e>1e12?e:e*1e3)-Date.now();if(n<=0||n>=10080*60*1e3)return"";let r=Math.floor(n/6e4),s=Math.floor(r/60),o=r%60;return s>0?`${s}h ${o}m`:`${o}m`}function dn(e,t){if(!e||typeof e.used_percentage!="number")return null;let n=Math.max(0,Math.min(100,e.used_percentage)),r=n/100,s=De(r),o=n>=90?"\x1B[38;5;196m":n>=70?p.visaGold:p.green,i=`${String(Math.round(n)).padStart(2," ")}%`,a=ps(e.resets_at),c=a?` ${g(`(${a} / ${t})`,p.dim)}`:` ${g(`(${t})`,p.dim)}`;return`${s} ${g(i,o)}${c}`}function gs(e){if(!e)return null;let t=dn(e.five_hour,"5h"),n=typeof e.seven_day?.used_percentage=="number"?e.seven_day.used_percentage:null,r=n!==null&&n>=90?dn(e.seven_day,"7d"):null;if(!t&&!r)return null;let s=` ${g("\u2502",p.dim)} `,o=[t,r].filter(Boolean);return`${g("Usage",p.dim)} ${o.join(s)}`}function ms(e){let t;try{let n=Y.statSync(e);if(!n.isFile())return null;let r=n.size;if(r===0)return null;let s=Math.min(r,ls),o=r-s;t=Y.openSync(e,"r");let i=Buffer.alloc(s);Y.readSync(t,i,0,s,o);let a=i.toString("utf-8");if(o>0){let c=Buffer.alloc(1);if(Y.readSync(t,c,0,1,o-1),c[0]!==10){let l=a.indexOf(`
27
- `);l>=0&&(a=a.slice(l+1))}}return a}catch{return null}finally{if(t!==void 0)try{Y.closeSync(t)}catch{}}}function hs(e){if(!e||typeof e!="object")return;let t=e,n=["file_path","path","notebook_path","pattern","command","url"];for(let r of n){let s=t[r];if(typeof s=="string"&&s.length>0){if(r.endsWith("_path")||r==="path"){let o=X.basename(X.dirname(s)),i=X.basename(s);return o&&o!=="."&&o!=="/"?`${o}/${i}`:i}return s}}}function ys(e){let t=e.split(`
28
- `),n=[],r=new Set;for(let s=t.length-1;s>=0&&n.length<ln*3;s-=1){let o=t[s].trim();if(!o)continue;let i;try{i=JSON.parse(o)}catch{continue}if(!i||typeof i!="object")continue;let c=i.message;if(!c||typeof c!="object")continue;let l=c.content;if(Array.isArray(l))for(let d of l){if(!d||typeof d!="object")continue;let f=d;if(f.type==="tool_result"&&typeof f.tool_use_id=="string")r.add(f.tool_use_id);else if(f.type==="tool_use"&&typeof f.name=="string"){let y=typeof f.id=="string"?f.id:"",w=y.length>0?!r.has(y):!1;n.push({name:f.name,target:hs(f.input),running:w})}}}return n.reverse(),n.slice(Math.max(0,n.length-ln))}function Ss(e){let t=[];for(let n of e){let r=t[t.length-1];r&&!r.running&&!n.running&&r.name===n.name&&r.target===void 0&&n.target===void 0?r.count+=1:t.push({...n,count:1})}return t}function vs(e){let t=e.running?g("\u25D0",p.visaGold):g("\u2713",p.green),n=e.running?p.visaGold:p.visaBlueSoft,r=g(P(e.name),n),s=e.target?P(e.target):"",o=s?`${g(":",p.dim)} ${g(s,p.dim)}`:"",i=e.count>1?` ${g(`\xD7${e.count}`,p.dim)}`:"";return o?`${t} ${r}${o}${i}`:`${t} ${r}${i}`}function bs(e){let t=` ${g("\u2502",p.dim)} `,n=un(t),r=e.slice();for(;r.length>0;){let c=r.join(t);if(un(c)<=ft)return c;r=r.slice(1)}if(e.length===0)return"";let s="\u2026",i=e[e.length-1].replace(/\u001B\[[0-?]*[ -/]*[@-~]/g,""),a=i.length>ft-n-1?i.slice(0,ft-n-1)+s:i;return`${g(s,p.dim)}${t}${a}`}async function ws(e){if(!e||typeof e!="string")return null;let t=ms(e);if(!t)return null;let n;try{n=ys(t)}catch{return null}if(n.length===0)return null;let s=Ss(n).map(vs);return bs(s)||null}async function mn(e,t){return(await hn(e,t)).join(`
29
- `)}async function hn(e,t){let n=[e];if(t){let r=ds(t);if(r&&n.push(...r.split(`
30
- `)),t.transcript_path){let s=await ws(t.transcript_path);s&&n.push(...s.split(`
31
- `))}}return n}async function yn(e,t){let n=await hn(e,t),r=n.join(`
32
- `);return{schemaVersion:is,client:t?bn(t):ne.UNKNOWN,rendered:r,lines:n.map(pn),visa:{spendLine:pn(e)},context:t?wn(t):{}}}function P(e){return e?e.replace(/\u001B\][^\u0007]*(?:\u0007|\u001B\\)/g,"").replace(/\u001B\[[0-?]*[ -/]*[@-~]/g,"").replace(/[\u0000-\u0008\u000B-\u001F\u007F-\u009F]/g,"").replace(/\s+/g," ").trim():""}function yt(e){if(typeof e=="string")return P(X.basename(e));if(!e||typeof e!="object")return"";let t=typeof e.current_dir=="string"?e.current_dir:typeof e.path=="string"?e.path:"";return P(t?X.basename(t):e.name)}function Sn(e){return P(e.app_name??e.appName??e.app??e.client)}function mt(e){return P(e.model?.display_name??e.model_name??e.modelName)}function vn(e){return P(e.cwd??e.current_dir??e.project_root)}function fn(e){let t=P(e.project);if(t)return t;let n=vn(e);if(n)return P(X.basename(n));let r=yt(e.workspace);return r||""}function K(e){if(!(typeof e!="number"||!Number.isFinite(e)))return e}function bn(e){let t=Sn(e).toLowerCase();return t.includes("codex")?ne.CODEX:t.includes("claude")||e.model?.display_name||e.transcript_path||e.rate_limits?ne.CLAUDE_CODE:e.run_state||e.runState||e.thread_title||e.threadTitle||e.git_branch||K(e.context_used)!==void 0?ne.CODEX:ne.UNKNOWN}function _s(e){return bn(e)===ne.CODEX}function wn(e){let t=Sn(e),n=vn(e),r=yt(e.workspace),s=K(e.context_used)??K(e.context_window?.used_percentage??void 0),o=K(e.context_remaining)??K(e.context_window?.remaining_percentage??void 0);return{...t?{app:t}:{},...mt(e)?{model:mt(e)}:{},...fn(e)?{project:fn(e)}:{},...r?{workspace:r}:{},...n?{cwd:n}:{},...P(e.git_branch??e.branch)?{gitBranch:P(e.git_branch??e.branch)}:{},...P(e.status??e.run_state??e.runState)?{status:P(e.status??e.run_state??e.runState)}:{},...P(e.thread_title??e.threadTitle)?{threadTitle:P(e.thread_title??e.threadTitle)}:{},...s!==void 0?{contextUsedPercent:s}:{},...o!==void 0?{contextRemainingPercent:o}:{},...K(e.used_tokens)!==void 0?{usedTokens:K(e.used_tokens)}:{},...K(e.total_input_tokens)!==void 0?{totalInputTokens:K(e.total_input_tokens)}:{},...K(e.total_output_tokens)!==void 0?{totalOutputTokens:K(e.total_output_tokens)}:{}}}function pn(e){return e.replace(/\u001B\[[0-?]*[ -/]*[@-~]/g,"")}async function _n(e,t){let n=t?.timeoutMs??3e4,r=new AbortController,s=setTimeout(()=>r.abort(),n);try{let{timeoutMs:o,...i}=t??{};return await fetch(e,{...i,signal:r.signal})}finally{clearTimeout(s)}}var Cs=/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;function kn(e,t){let n=Cn(e),r=Cn(t);if(!n||!r)return!1;for(let s=0;s<3;s++)if(n.main[s]!==r.main[s])return n.main[s]>r.main[s];return n.pre&&!r.pre?!1:!n.pre&&r.pre?!0:!n.pre&&!r.pre?!1:ks(n.pre,r.pre)>0}function Cn(e){if(typeof e!="string")return null;let n=e.trim().replace(/^v/,"").match(Cs);return n?{main:[Number(n[1]),Number(n[2]),Number(n[3])],pre:n[4]??null}:null}function ks(e,t){let n=e.split("."),r=t.split("."),s=Math.max(n.length,r.length);for(let o=0;o<s;o++){if(o>=n.length)return-1;if(o>=r.length)return 1;let i=n[o],a=r[o],c=/^\d+$/.test(i),l=/^\d+$/.test(a);if(c&&l){let d=Number(i)-Number(a);if(d!==0)return d}else{if(c)return-1;if(l)return 1;if(i<a)return-1;if(i>a)return 1}}return 0}function W(){return!!($n(process.env.VISA_CLI_NO_UPDATE_CHECK)||$n(process.env.CI)||process.env.NODE_ENV==="test")}function $n(e){if(e===void 0)return!1;let t=e.trim().toLowerCase();return!(t===""||t==="0"||t==="false"||t==="no"||t==="off")}var ee=h(require("fs")),Pn=h(require("path"));var Ue=h(require("fs")),xn=h(require("path")),En=h(require("os"));var St=xn.join(En.homedir(),".visa-mcp"),me=class{static ensureConfigDir(){Ue.existsSync(St)||Ue.mkdirSync(St,{recursive:!0,mode:448})}static getConfigDir(){return St}static TOOL_STATES={login:!0,get_status:!0,get_cards:!0,add_card:!0,pay:!0,transaction_history:!0,update_spending_controls:!0,enroll_device:!1,verify_otp:!1,reset:!0,batch:!0,generate_x402_image:!1,browser_launch:!1,browser_navigate:!1,browser_snapshot:!1,browser_click:!1,browser_type:!1,browser_scroll:!1,generate_music_card:!1,generate_image_card:!0,query_onchain_prices_card:!0,generate_music_tempo_card:!0,check_music_status_tempo_card:!0,generate_image_fast_card:!0,pxlwall_card:!1,generate_video_tempo_card:!0};static loadToolStates(){return{...this.TOOL_STATES}}static getDisabledTools(){let t=new Set;for(let[n,r]of Object.entries(this.TOOL_STATES))r||t.add(n);return t}static isToolDisabled(t){return this.TOOL_STATES[t]===!1}};var $s="settings.json";function je(){return Pn.join(me.getConfigDir(),$s)}var he={"auth.serverUrl":{type:"string",description:"Auth server base URL. Override for staging / self-hosted backends.",requiresRestart:!0,validate:e=>{if(typeof e!="string")throw new Error("auth.serverUrl must be a string");let t;try{t=new URL(e)}catch{throw new Error(`auth.serverUrl must be a valid URL (got: ${JSON.stringify(e)})`)}if(t.protocol!=="https:"&&t.protocol!=="http:")throw new Error(`auth.serverUrl must use http or https (got: ${t.protocol})`)}},"ui.suppressBrowser":{type:"boolean",description:"When true, the CLI/MCP server stops auto-opening result URLs in your browser."},"ui.suppressFeed":{type:"boolean",description:"When true, generated images/music are not auto-submitted to the public Made-with-Visa feed."},"tools.meta":{type:"boolean",description:"Show category meta-tools (generate_image, generate_music, ...). Restart required.",requiresRestart:!0},"tools.specific":{type:"boolean",description:"Show hardcoded per-merchant tools (generate_image_card, query_onchain_prices_card, ...). Restart required.",requiresRestart:!0},"tools.discover":{type:"boolean",description:"Show the dynamic-catalog tools (discover_tools, execute_tool). Restart required.",requiresRestart:!0}};function Me(){let e=je();if(!ee.existsSync(e))return{};try{let t=ee.readFileSync(e,"utf-8"),n=JSON.parse(t);return!n||typeof n!="object"||Array.isArray(n)?{}:n}catch{return{}}}function Tn(e){me.ensureConfigDir();let t=je(),n=`${t}.tmp`,r=JSON.stringify(e,null,2)+`
33
- `;ee.writeFileSync(n,r,{mode:384}),ee.renameSync(n,t)}function vt(e){let t=Me()[e];return typeof t=="string"?t:void 0}function An(e){let t=Me()[e];if(typeof t=="boolean")return t;if(t==="true")return!0;if(t==="false")return!1}var ae=class extends Error{constructor(t){let n=Object.keys(he).sort().join(", ");super(`Unknown setting "${t}". Settable keys: ${n}. For server-controlled values (biometric.*, spending.*) use the dedicated tools (biometric_on/off, update_spending_controls).`),this.name="UnknownSettingKeyError"}},ce=class extends Error{constructor(t){let n="";t.startsWith("biometric.")?n="biometric_on / biometric_off":t.startsWith("spending.")?n="update_spending_controls":t.startsWith("cards.")?n="add_card / remove_card / set_default_card":t.startsWith("account.")&&(n="login / reset"),super(`"${t}" is a server-controlled value and cannot be set via config set. `+(n?`Use ${n} instead.`:"No client-side override is supported.")),this.name="ServerOnlySettingError"}},Rn=["biometric.","spending.","account.","cards.","biometric"];function In(e,t){if(Rn.some(o=>e.startsWith(o)))throw new ce(e);let n=he[e];if(!n)throw new ae(e);let r;if(n.type==="boolean")if(typeof t=="boolean")r=t;else if(typeof t=="string"){let o=t.toLowerCase();if(o==="true")r=!0;else if(o==="false")r=!1;else throw new Error(`${e} expects true or false (got: ${JSON.stringify(t)})`)}else throw new Error(`${e} expects a boolean (got: ${typeof t})`);else{if(typeof t!="string"||t.length===0)throw new Error(`${e} expects a non-empty string`);r=t}n.validate&&n.validate(r);let s=Me();return s[e]=r,Tn(s),{key:e,value:r,requiresRestart:!!n.requiresRestart,path:je()}}function Ln(e){if(Rn.some(s=>e.startsWith(s)))throw new ce(e);let t=he[e];if(!t)throw new ae(e);let n=Me(),r=e in n;return r&&(delete n[e],Tn(n)),{key:e,removed:r,requiresRestart:r&&!!t.requiresRestart,path:je()}}var xs="https://auth.visacli.sh";function On(){let e=process.env.VISA_AUTH_URL;if(e!==void 0&&e!=="")return e;let t=vt("auth.serverUrl");return t!==void 0?t:xs}var bt="1.11.0-rc.1",le=class{constructor(t){this.getSessionToken=t;this.baseUrl=On()}getSessionToken;baseUrl;lastSignals={};parseServerSignals(t){if(this.lastSignals={},!W()){let r=t.headers.get("X-Latest-Version"),s=t.headers.get("X-Update-Message");r&&kn(r,bt)&&(this.lastSignals.updateAvailable={version:r,message:s||`Update available: v${r}. Run: npm install -g @visa/cli && visa-cli setup`})}let n=t.headers.get("X-Feedback-Prompt");if(n)try{this.lastSignals.feedbackPrompt=JSON.parse(n)}catch{}}getClientVersion(){return bt}async request(t,n,r,s,o){let i=await this.getSessionToken();if(!i)throw new Error("Not logged in. Sign up at https://visacli.sh or run: visa-cli setup");let a={Authorization:`Bearer ${i}`};o&&(t==="GET"?a["X-User-Context"]=o.replace(/[\r\n\0]/g," ").slice(0,1e3):r={...r||{},user_context:o}),r&&(a["Content-Type"]="application/json");let c;try{c=await _n(`${this.baseUrl}${n}`,{method:t,headers:{...a,"X-Visa-CLI-Version":bt},body:r?JSON.stringify(r):void 0,timeoutMs:s})}catch(d){throw d.name==="AbortError"||d.message?.includes("aborted")?new Error("The request timed out. The server may be under heavy load. Please try again."):new Error("Cannot reach the Visa CLI server. Check your internet connection and try again.")}if(this.parseServerSignals(c),c.status===401)throw new Error("Your session has expired. Run: visa-cli setup");if(c.status===429){let d=c.headers.get("Retry-After")||"3";throw new Error(`Rate limited \u2014 wait ${d}s. Tip: use the batch tool to combine multiple requests into one.`)}if(c.status===503)throw new Error("Visa CLI is temporarily unavailable. Check https://visacli.sh for status.");let l;try{l=await c.json()}catch{throw c.status===500?new Error(`Server error on ${n}. Try again or check https://visacli.sh for status.`):new Error(`Unexpected response from ${n}. Try again.`)}if(!c.ok)throw c.status===500?new Error(`Server error on ${n}. Try again or check https://visacli.sh for status.`):new Error(l?.error||`Request failed (${c.status}). Try again.`);return l}async pay(t,n){return this.request("POST","/v1/pay",t,void 0,n)}async shortcut(t,n,r,s){return this.request("POST",`/v1/shortcuts/${encodeURIComponent(t)}`,n,r,s)}async batch(t,n,r){return this.request("POST","/v1/batch",t,n,r)}async catalogSearch(t,n){let r=new URLSearchParams;t&&r.set("q",t),n&&r.set("category",n);let s=r.toString();return this.request("GET",`/v1/catalog${s?`?${s}`:""}`)}async catalogTool(t){try{return await this.request("GET",`/v1/catalog/${encodeURIComponent(t)}`)}catch{return null}}async paymentPreview(t,n){return this.request("POST","/v1/payment-preview",t,void 0,n)}async getStatus(t){return this.request("GET","/v1/status",void 0,void 0,t)}async getTransactions(t){return this.request("GET","/v1/transactions",void 0,void 0,t)}async updateSpendingControls(t,n){return this.request("POST","/v1/spending-controls",t,void 0,n)}async removeCard(t,n,r){return this.request("DELETE",`/v1/cards/${encodeURIComponent(String(t))}`,n,void 0,r)}async setDefaultCard(t,n,r){return this.request("POST",`/v1/cards/${encodeURIComponent(String(t))}/default`,n,void 0,r)}async getAttestationChallenge(){return this.request("GET","/v1/attestation-challenge")}async registerAttestationKey(t){return this.request("POST","/v1/attestation-key",{publicKey:t})}async setBiometricPreference(t,n){return this.request("POST","/v1/biometric-preference",{...t,confirm:!0},void 0,n)}async logout(t,n){return this.request("POST","/v1/logout",t,void 0,n)}async feedback(t,n,r){return this.request("POST","/v1/feedback",{message:t,...n&&{transaction_id:n}},void 0,r)}async createAppApiKey(t){return this.request("POST","/v1/api/keys",t)}async listAppApiKeys(){return this.request("GET","/v1/api/keys")}async revokeAppApiKey(t){return this.request("DELETE",`/v1/api/keys/${encodeURIComponent(String(t))}`)}async feedSubmit(t){return this.request("POST","/v1/feed",t)}async feedList(t){let n=new URLSearchParams;t?.tab&&n.set("tab",t.tab),t?.limit&&n.set("limit",String(t.limit)),t?.offset&&n.set("offset",String(t.offset));let r=n.toString();return this.request("GET",`/v1/feed${r?"?"+r:""}`)}async feedVote(t,n){return this.request("POST",`/v1/feed/${encodeURIComponent(t)}/vote`,{direction:n})}async feedApprove(t){return this.request("POST",`/v1/feed/${encodeURIComponent(t)}/approve`)}async feedDelete(t){return this.request("DELETE",`/v1/feed/${encodeURIComponent(t)}`)}async feedPending(){return this.request("GET","/v1/feed/pending")}async submitFeedback(t,n,r){return this.request("POST","/v1/feedback",{message:t,...n&&{transaction_id:n}},void 0,r)}async getFeedback(t,n){let r=new URLSearchParams;t&&r.set("limit",String(t));let s=r.toString();return this.request("GET",`/v1/feedback${s?"?"+s:""}`,void 0,void 0,n)}async submitRatedFeedback(t){return this.request("POST","/v1/feedback",t)}};var $t=require("child_process"),Hn=require("util"),Vn=h(require("crypto")),A=h(require("fs")),Fn=h(require("os")),J=h(require("path"));var N=h(require("fs")),Ct=h(require("path")),Nn=h(require("os")),_t=Ct.join(Nn.homedir(),".visa-mcp"),ye=Ct.join(_t,"mcp-server.log"),Es=5*1024*1024,wt=null;function Ps(){N.existsSync(_t)||N.mkdirSync(_t,{recursive:!0,mode:448})}function Ts(){if(!wt){if(Ps(),N.existsSync(ye)&&N.statSync(ye).size>Es){let t=ye+".1";N.existsSync(t)&&N.unlinkSync(t),N.renameSync(ye,t)}wt=N.createWriteStream(ye,{flags:"a"})}return wt}function He(e,...t){let n=new Date().toISOString(),r=t.map(o=>typeof o=="string"?o:JSON.stringify(o,null,2)).join(" "),s=`[${n}] [${e}] ${r}
34
- `;process.stderr.write(s),Ts().write(s)}var ue={debug:(...e)=>He("DEBUG",...e),info:(...e)=>He("INFO",...e),warn:(...e)=>He("WARN",...e),error:(...e)=>He("ERROR",...e)};var de=(0,Hn.promisify)($t.execFile),Be=J.join(Fn.homedir(),".visa-mcp","bin"),re=J.join(Be,"Visa CLI"),As=J.join(__dirname,"..","native"),Dn="5",Un=J.join(Be,"visa-keychain.version"),jn=J.join(Be,"visa-keychain.sha256");function Mn(e){let t=A.readFileSync(e);return Vn.createHash("sha256").update(t).digest("hex")}async function Bn(){try{if(A.readFileSync(Un,"utf-8").trim()===Dn&&A.existsSync(re)){let r=A.readFileSync(jn,"utf-8").trim();if(Mn(re)!==r)ue.warn("binary:hash-mismatch",{message:"Binary hash mismatch \u2014 possible tampering detected. Recompiling from source."}),A.unlinkSync(re);else return re}}catch{}let e=J.join(As,"visa-keychain.m");if(A.existsSync(e)||(e=J.resolve(__dirname,"..","..","native","visa-keychain.m")),A.existsSync(e)||(e=J.resolve(__dirname,"..","native","visa-keychain.m")),!A.existsSync(e))throw new Error("visa-keychain.m source not found. Reinstall Visa CLI.");A.mkdirSync(Be,{recursive:!0,mode:448});try{await de("clang",["-framework","Security","-framework","LocalAuthentication","-framework","Foundation","-framework","AppKit","-o",re,e],{timeout:3e4})}catch(n){throw n.code==="ENOENT"?new Error("Xcode Command Line Tools required. Install: xcode-select --install"):n}let t=Mn(re);return A.writeFileSync(jn,t,{mode:384}),A.writeFileSync(Un,Dn,{mode:384}),re}async function Kn(e){let t=await Bn(),n;try{n=(await de(t,e,{timeout:6e4})).stdout}catch(o){n=o.stdout||"";let i=n.trim();throw i.startsWith("ERROR:")?new Error(i.slice(6)):new Error(o.stderr?.trim()||o.message||"Unknown error")}let r=n.trim();if(r.startsWith("OK:"))return r.slice(3);if(r==="OK")return;let s=r.startsWith("ERROR:")?r.slice(6):"Unknown error";throw new Error(s)}var kt=null;function D(){return process.env.VISA_MOCK_TOUCHID==="true"?!0:process.platform!=="darwin"?!1:kt!==null?kt:(kt=!0,!0)}var Ve="visa-cli",Fe="attestation-key";async function Rs(e){try{await de("security",["delete-generic-password","-s",Ve,"-a",Fe],{timeout:5e3})}catch{}await de("security",["add-generic-password","-s",Ve,"-a",Fe,"-w",e],{timeout:5e3})}async function Is(){try{let{stdout:e}=await de("security",["find-generic-password","-s",Ve,"-a",Fe,"-w"],{timeout:5e3});return e.trim()||null}catch{return null}}async function Ke(){let e=await Kn(["generate-key"]);if(!e)throw new Error("Key generation returned no output");let t=e.indexOf(":");if(t<0)throw new Error("Unexpected generate-key output format");let n=e.slice(0,t),r=e.slice(t+1);return await Rs(n),r}async function xt(e,t){if(process.env.VISA_MOCK_TOUCHID==="true")return Promise.resolve("mock-ecdsa-signature-for-testing");let n=await Is();if(!n)throw new Error("Attestation key not found. Run setup to generate a new key.");let r=await Bn(),s=["sign",e];return t&&s.push(t),new Promise((o,i)=>{let a=(0,$t.execFile)(r,s,{timeout:6e4},(c,l)=>{let d=(l||"").trim();if(c){d.startsWith("ERROR:")?i(new Error(d.slice(6))):i(new Error(c.stderr?.trim()||c.message||"Unknown error"));return}d.startsWith("OK:")?o(d.slice(3)):i(new Error(d.startsWith("ERROR:")?d.slice(6):"Unknown error"))});a.stdin.write(n),a.stdin.end()})}async function qn(){try{await de("security",["delete-generic-password","-s",Ve,"-a",Fe],{timeout:5e3})}catch{}try{await Kn(["delete-key"])}catch{}}function Gn(e,t=process.stderr){if(W()||!e?.updateAvailable)return!1;let{message:n}=e.updateAvailable;return n?(t.write(`
21
+ `),process.exit(1)}var sn=require("child_process");function os(e=process.env,t=process.platform){return e.VISA_CLI_NO_BROWSER==="1"||e.VISA_CLI_NO_BROWSER==="true"?{headless:!0,reason:"VISA_CLI_NO_BROWSER is set"}:e.CI==="true"||e.CI==="1"?{headless:!0,reason:"CI environment detected"}:e.SSH_CONNECTION||e.SSH_TTY?{headless:!0,reason:"SSH session detected"}:t==="linux"&&!e.DISPLAY&&!e.WAYLAND_DISPLAY?{headless:!0,reason:"Linux with no $DISPLAY or $WAYLAND_DISPLAY"}:{headless:!1}}function is(e){let n=e.length+4;return[`\u250C${"\u2500".repeat(n)}\u2510`,`\u2502${" ".repeat(2)}${e}${" ".repeat(2)}\u2502`,`\u2514${"\u2500".repeat(n)}\u2518`].join(`
22
+ `)}function as(e,t=process.platform){return t==="darwin"?{cmd:"open",args:[e]}:t==="win32"?{cmd:"cmd",args:["/c","start","",e]}:t==="linux"?{cmd:"xdg-open",args:[e]}:null}async function on(e,t={}){let n=t.log??(c=>console.log(c)),r=t.env??process.env,s=t.platform??process.platform,o=t.spawn??((c,l,u)=>{(0,sn.execFile)(c,l,f=>u(f))});n(""),n(" Sign in to Visa CLI by opening this URL in your browser:"),n("");for(let c of is(e).split(`
23
+ `))n(` ${c}`);n("");let i=os(r,s);if(i.headless){n(` (${i.reason} \u2014 skipping browser auto-open.)`),n(" Open the URL above on any device with a browser. The CLI will"),n(" continue waiting for you to complete sign-in."),n("");return}let a=as(e,s);if(!a){n(` No known browser-open command for platform "${s}".`),n(" Open the URL above manually to continue."),n("");return}await new Promise(c=>{o(a.cmd,a.args,l=>{l?(n(` Could not open browser automatically (${l.message}).`),n(" Open the URL above manually to continue."),n("")):(n(" Opened browser. Waiting for you to sign in..."),n("")),c()})})}var cn=h(require("crypto")),N=h(require("fs")),Oe=h(require("path"));function ln(e,t){N.mkdirSync(Oe.dirname(e),{recursive:!0});let n=`${e}.${process.pid}.${cn.randomBytes(8).toString("hex")}.tmp`;try{N.writeFileSync(n,JSON.stringify(t,null,2)+`
24
+ `),N.renameSync(n,e)}catch(r){try{N.unlinkSync(n)}catch{}throw r}}function an(e){return`'${e.replace(/'/g,"'\\''")}'`}var un="# visa-cli-hud-v1";function cs(e,t){let n=e??process.execPath,r=t??process.argv[1]??"",s=r?Oe.resolve(r):"";return`${s?`${an(n)} ${an(s)} statusline`:"visa-cli statusline"} ${un}`}function dn(e){return typeof e!="string"?!1:e.includes(un)?!0:e.includes("visa-cli")&&e.includes("statusline")}function De(e,t=cs){let n={},r=!1;if(N.existsSync(e)){r=!0;try{n=JSON.parse(N.readFileSync(e,"utf-8"))}catch(s){return{installed:"malformed-json",message:`~/.claude/settings.json is not valid JSON (${s.message}). Fix the file manually, then run: visa-cli hud enable`}}}if(n.statusLine){let s=typeof n.statusLine=="object"?n.statusLine.command:"";return dn(s)?{installed:"already-visa",message:"Visa HUD already registered in ~/.claude/settings.json."}:{installed:"other-hud-present",message:"Another HUD is already configured (keeping it). To switch to Visa HUD, edit ~/.claude/settings.json \u2192 statusLine.command"}}try{return n.statusLine={type:"command",command:t()},ln(e,n),{installed:"new",message:`Visa HUD registered in ~/.claude/settings.json${r?"":" (new file)"}. Restart Claude Code to see it pinned below the input.`}}catch(s){return{installed:"error",message:`Failed to write settings: ${s.message}. Enable manually later with: visa-cli hud enable`}}}function pt(e){if(!N.existsSync(e))return{removed:!1,message:"No ~/.claude/settings.json found."};let t;try{t=JSON.parse(N.readFileSync(e,"utf-8"))}catch(r){return{removed:!1,message:`~/.claude/settings.json is not valid JSON: ${r.message}`}}if(!t.statusLine)return{removed:!1,message:"No statusLine configured."};let n=typeof t.statusLine=="object"?t.statusLine.command:"";return dn(n)?(delete t.statusLine,ln(e,t),{removed:!0,message:"Visa HUD removed from ~/.claude/settings.json. Restart Claude Code to take effect."}):{removed:!1,message:"statusLine is owned by another tool \u2014 leaving it alone."}}var Y=h(require("fs")),X=h(require("path")),ls=1,ne={CLAUDE_CODE:"claude-code",CODEX:"codex",UNKNOWN:"unknown"},us=["claude","claude-code","codex","all"];function St(e){let t=e.toLowerCase();return us.includes(t)?t:null}var ds=50,fs=64*1024,fn=10,gt=80;function ps(){let e=(process.env.COLORTERM??"").toLowerCase();if(e==="truecolor"||e==="24bit")return!0;let t=(process.env.TERM??"").toLowerCase();return t.includes("truecolor")||t.includes("24bit")}var mt=ps(),p={reset:"\x1B[0m",visaBlue:mt?"\x1B[38;2;20;52;203m":"\x1B[38;5;27m",visaBlueSoft:mt?"\x1B[38;2;97;126;229m":"\x1B[38;5;111m",visaGold:mt?"\x1B[38;2;247;182;0m":"\x1B[38;5;220m",green:"\x1B[38;5;48m",dim:"\x1B[2m"};function m(e,t){return e.length===0||process.env.NO_COLOR?e:`${t}${e}${p.reset}`}function pn(e){return e.replace(/\u001B\[[0-?]*[ -/]*[@-~]/g,"").replace(/[\u0000-\u001F\u007F]/g,"").length}async function yn(e=process.stdin){return e.isTTY?null:new Promise(t=>{let n=[],r=!1,s=()=>{e.removeListener("data",i),e.removeListener("end",a),e.removeListener("error",c),clearTimeout(l)},o=u=>{r||(r=!0,s(),t(u))},i=u=>{n.push(typeof u=="string"?Buffer.from(u):u)},a=()=>{let u=Buffer.concat(n).toString("utf-8").trim();if(!u)return o(null);try{let f=JSON.parse(u);o(f&&typeof f=="object"?f:null)}catch{o(null)}},c=()=>o(null),l=setTimeout(()=>{n.length>0?a():o(null)},ds);e.on("data",i),e.on("end",a),e.on("error",c)})}function Ue(e){let n=Math.round(Math.max(0,Math.min(1,e))*10),r="\u2588".repeat(n),s="\u2591".repeat(10-n);return`${m(r||"",p.visaBlueSoft)}${m(s||"",p.dim)}`}function ht(e){return!Number.isFinite(e)||e<0?"0":e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:String(Math.round(e))}function gs(e){if(xs(e))return ms(e);let t=` ${m("\u2502",p.dim)} `,n=yt(e)||"claude",r=e.cwd?P(X.basename(e.cwd)):"",s=vt(e.workspace),o=r||s,i=s&&s!==o?` ${m(`@${s}`,p.visaBlueSoft)}`:"",a=[m(`[${n}]`,p.visaBlueSoft)];o&&a.push(`${m(o,p.visaGold)}${i}`);let c=a.join(t),l=Number(e.context_window?.context_window_size??0),u=typeof e.context_window?.used_percentage=="number"?e.context_window.used_percentage:typeof e.context_window?.remaining_percentage=="number"?100-e.context_window.remaining_percentage:null,f=e.context_window?.current_usage,y=[f?.input_tokens,f?.output_tokens,f?.cache_creation_input_tokens,f?.cache_read_input_tokens].filter(I=>typeof I=="number"&&Number.isFinite(I)),w=y.length>0?y.reduce((I,F)=>I+F,0):null,d=Number(e.context_window?.total_input_tokens??w??f?.input_tokens??0),S=u!==null?Math.max(0,Math.min(1,u/100)):l>0?Math.max(0,Math.min(1,d/l)):0,_=u!==null&&l>0?Math.round(S*l):d,C;if(l>0||u!==null){let I=`${String(Math.round(S*100)).padStart(2," ")}%`,F=l>0?` ${m(`(${ht(_)}/${ht(l)})`,p.dim)}`:"";C=`${m("Context",p.dim)} ${Ue(S)} ${m(I,p.green)}${F}`}else C=`${m("Context",p.dim)} ${m("-",p.dim)}`;let E=ys(e.rate_limits),V=[C];E&&V.push(E);let ie=V.join(t);return`${c}
25
+ ${ie}`}function ms(e){let t=` ${m("\u2502",p.dim)} `,n=kn(e),r=n.model||"codex",s=[m(`[${r}]`,p.visaBlueSoft)];n.project&&s.push(m(n.project,p.visaGold)),n.gitBranch&&s.push(`${m("git",p.dim)} ${m(n.gitBranch,p.visaGold)}`);let o=s.join(t),i=[];if(typeof n.contextUsedPercent=="number"){let c=Math.max(0,Math.min(1,n.contextUsedPercent/100));i.push(`${m("Context",p.dim)} ${Ue(c)} ${m(`${Math.round(n.contextUsedPercent)}%`,p.green)}`)}else if(typeof n.contextRemainingPercent=="number"){let c=100-n.contextRemainingPercent,l=Math.max(0,Math.min(1,c/100));i.push(`${m("Context",p.dim)} ${Ue(l)} ${m(`${Math.round(c)}%`,p.green)}`)}typeof n.usedTokens=="number"&&i.push(`${m("Tokens",p.dim)} ${ht(n.usedTokens)}`),n.status&&i.push(`${m("Status",p.dim)} ${m(n.status,p.visaBlueSoft)}`),n.threadTitle&&i.push(`${m("Thread",p.dim)} ${m(n.threadTitle,p.visaBlueSoft)}`);let a=i.length>0?i.join(t):`${m("Context",p.dim)} ${m("-",p.dim)}`;return`${o}
26
+ ${a}`}function hs(e){if(typeof e!="number"||e<=0)return"";let n=(e>1e12?e:e*1e3)-Date.now();if(n<=0||n>=10080*60*1e3)return"";let r=Math.floor(n/6e4),s=Math.floor(r/60),o=r%60;return s>0?`${s}h ${o}m`:`${o}m`}function gn(e,t){if(!e||typeof e.used_percentage!="number")return null;let n=Math.max(0,Math.min(100,e.used_percentage)),r=n/100,s=Ue(r),o=n>=90?"\x1B[38;5;196m":n>=70?p.visaGold:p.green,i=`${String(Math.round(n)).padStart(2," ")}%`,a=hs(e.resets_at),c=a?` ${m(`(${a} / ${t})`,p.dim)}`:` ${m(`(${t})`,p.dim)}`;return`${s} ${m(i,o)}${c}`}function ys(e){if(!e)return null;let t=gn(e.five_hour,"5h"),n=typeof e.seven_day?.used_percentage=="number"?e.seven_day.used_percentage:null,r=n!==null&&n>=90?gn(e.seven_day,"7d"):null;if(!t&&!r)return null;let s=` ${m("\u2502",p.dim)} `,o=[t,r].filter(Boolean);return`${m("Usage",p.dim)} ${o.join(s)}`}function Ss(e){let t;try{let n=Y.statSync(e);if(!n.isFile())return null;let r=n.size;if(r===0)return null;let s=Math.min(r,fs),o=r-s;t=Y.openSync(e,"r");let i=Buffer.alloc(s);Y.readSync(t,i,0,s,o);let a=i.toString("utf-8");if(o>0){let c=Buffer.alloc(1);if(Y.readSync(t,c,0,1,o-1),c[0]!==10){let l=a.indexOf(`
27
+ `);l>=0&&(a=a.slice(l+1))}}return a}catch{return null}finally{if(t!==void 0)try{Y.closeSync(t)}catch{}}}function vs(e){if(!e||typeof e!="object")return;let t=e,n=["file_path","path","notebook_path","pattern","command","url"];for(let r of n){let s=t[r];if(typeof s=="string"&&s.length>0){if(r.endsWith("_path")||r==="path"){let o=X.basename(X.dirname(s)),i=X.basename(s);return o&&o!=="."&&o!=="/"?`${o}/${i}`:i}return s}}}function bs(e){let t=e.split(`
28
+ `),n=[],r=new Set;for(let s=t.length-1;s>=0&&n.length<fn*3;s-=1){let o=t[s].trim();if(!o)continue;let i;try{i=JSON.parse(o)}catch{continue}if(!i||typeof i!="object")continue;let c=i.message;if(!c||typeof c!="object")continue;let l=c.content;if(Array.isArray(l))for(let u of l){if(!u||typeof u!="object")continue;let f=u;if(f.type==="tool_result"&&typeof f.tool_use_id=="string")r.add(f.tool_use_id);else if(f.type==="tool_use"&&typeof f.name=="string"){let y=typeof f.id=="string"?f.id:"",w=y.length>0?!r.has(y):!1;n.push({name:f.name,target:vs(f.input),running:w})}}}return n.reverse(),n.slice(Math.max(0,n.length-fn))}function ws(e){let t=[];for(let n of e){let r=t[t.length-1];r&&!r.running&&!n.running&&r.name===n.name&&r.target===void 0&&n.target===void 0?r.count+=1:t.push({...n,count:1})}return t}function _s(e){let t=e.running?m("\u25D0",p.visaGold):m("\u2713",p.green),n=e.running?p.visaGold:p.visaBlueSoft,r=m(P(e.name),n),s=e.target?P(e.target):"",o=s?`${m(":",p.dim)} ${m(s,p.dim)}`:"",i=e.count>1?` ${m(`\xD7${e.count}`,p.dim)}`:"";return o?`${t} ${r}${o}${i}`:`${t} ${r}${i}`}function Cs(e){let t=` ${m("\u2502",p.dim)} `,n=pn(t),r=e.slice();for(;r.length>0;){let c=r.join(t);if(pn(c)<=gt)return c;r=r.slice(1)}if(e.length===0)return"";let s="\u2026",i=e[e.length-1].replace(/\u001B\[[0-?]*[ -/]*[@-~]/g,""),a=i.length>gt-n-1?i.slice(0,gt-n-1)+s:i;return`${m(s,p.dim)}${t}${a}`}async function ks(e){if(!e||typeof e!="string")return null;let t=Ss(e);if(!t)return null;let n;try{n=bs(t)}catch{return null}if(n.length===0)return null;let s=ws(n).map(_s);return Cs(s)||null}async function Sn(e,t){return(await vn(e,t)).join(`
29
+ `)}async function vn(e,t){let n=[e];if(t){let r=gs(t);if(r&&n.push(...r.split(`
30
+ `)),t.transcript_path){let s=await ks(t.transcript_path);s&&n.push(...s.split(`
31
+ `))}}return n}async function bn(e,t){let n=await vn(e,t),r=n.join(`
32
+ `);return{schemaVersion:ls,client:t?Cn(t):ne.UNKNOWN,rendered:r,lines:n.map(hn),visa:{spendLine:hn(e)},context:t?kn(t):{}}}function P(e){return e?e.replace(/\u001B\][^\u0007]*(?:\u0007|\u001B\\)/g,"").replace(/\u001B\[[0-?]*[ -/]*[@-~]/g,"").replace(/[\u0000-\u0008\u000B-\u001F\u007F-\u009F]/g,"").replace(/\s+/g," ").trim():""}function vt(e){if(typeof e=="string")return P(X.basename(e));if(!e||typeof e!="object")return"";let t=typeof e.current_dir=="string"?e.current_dir:typeof e.path=="string"?e.path:"";return P(t?X.basename(t):e.name)}function wn(e){return P(e.app_name??e.appName??e.app??e.client)}function yt(e){return P(e.model?.display_name??e.model_name??e.modelName)}function _n(e){return P(e.cwd??e.current_dir??e.project_root)}function mn(e){let t=P(e.project);if(t)return t;let n=_n(e);if(n)return P(X.basename(n));let r=vt(e.workspace);return r||""}function K(e){if(!(typeof e!="number"||!Number.isFinite(e)))return e}function Cn(e){let t=wn(e).toLowerCase();return t.includes("codex")?ne.CODEX:t.includes("claude")||e.model?.display_name||e.transcript_path||e.rate_limits?ne.CLAUDE_CODE:e.run_state||e.runState||e.thread_title||e.threadTitle||e.git_branch||K(e.context_used)!==void 0?ne.CODEX:ne.UNKNOWN}function xs(e){return Cn(e)===ne.CODEX}function kn(e){let t=wn(e),n=_n(e),r=vt(e.workspace),s=K(e.context_used)??K(e.context_window?.used_percentage??void 0),o=K(e.context_remaining)??K(e.context_window?.remaining_percentage??void 0);return{...t?{app:t}:{},...yt(e)?{model:yt(e)}:{},...mn(e)?{project:mn(e)}:{},...r?{workspace:r}:{},...n?{cwd:n}:{},...P(e.git_branch??e.branch)?{gitBranch:P(e.git_branch??e.branch)}:{},...P(e.status??e.run_state??e.runState)?{status:P(e.status??e.run_state??e.runState)}:{},...P(e.thread_title??e.threadTitle)?{threadTitle:P(e.thread_title??e.threadTitle)}:{},...s!==void 0?{contextUsedPercent:s}:{},...o!==void 0?{contextRemainingPercent:o}:{},...K(e.used_tokens)!==void 0?{usedTokens:K(e.used_tokens)}:{},...K(e.total_input_tokens)!==void 0?{totalInputTokens:K(e.total_input_tokens)}:{},...K(e.total_output_tokens)!==void 0?{totalOutputTokens:K(e.total_output_tokens)}:{}}}function hn(e){return e.replace(/\u001B\[[0-?]*[ -/]*[@-~]/g,"")}async function xn(e,t){let n=t?.timeoutMs??3e4,r=new AbortController,s=setTimeout(()=>r.abort(),n);try{let{timeoutMs:o,...i}=t??{};return await fetch(e,{...i,signal:r.signal})}finally{clearTimeout(s)}}var je=class extends Error{retryable;code;reason;constructor(t,n,r,s){super(t),this.name="CardDeclinedError",this.retryable=n,this.code=r,this.reason=s}};var $s=/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;function En(e,t){let n=$n(e),r=$n(t);if(!n||!r)return!1;for(let s=0;s<3;s++)if(n.main[s]!==r.main[s])return n.main[s]>r.main[s];return n.pre&&!r.pre?!1:!n.pre&&r.pre?!0:!n.pre&&!r.pre?!1:Es(n.pre,r.pre)>0}function $n(e){if(typeof e!="string")return null;let n=e.trim().replace(/^v/,"").match($s);return n?{main:[Number(n[1]),Number(n[2]),Number(n[3])],pre:n[4]??null}:null}function Es(e,t){let n=e.split("."),r=t.split("."),s=Math.max(n.length,r.length);for(let o=0;o<s;o++){if(o>=n.length)return-1;if(o>=r.length)return 1;let i=n[o],a=r[o],c=/^\d+$/.test(i),l=/^\d+$/.test(a);if(c&&l){let u=Number(i)-Number(a);if(u!==0)return u}else{if(c)return-1;if(l)return 1;if(i<a)return-1;if(i>a)return 1}}return 0}function J(){return!!(Pn(process.env.VISA_CLI_NO_UPDATE_CHECK)||Pn(process.env.CI)||process.env.NODE_ENV==="test")}function Pn(e){if(e===void 0)return!1;let t=e.trim().toLowerCase();return!(t===""||t==="0"||t==="false"||t==="no"||t==="off")}var ee=h(require("fs")),Rn=h(require("path"));var Me=h(require("fs")),Tn=h(require("path")),An=h(require("os"));var bt=Tn.join(An.homedir(),".visa-mcp"),me=class{static ensureConfigDir(){Me.existsSync(bt)||Me.mkdirSync(bt,{recursive:!0,mode:448})}static getConfigDir(){return bt}static TOOL_STATES={login:!0,get_status:!0,get_cards:!0,add_card:!0,pay:!0,transaction_history:!0,update_spending_controls:!0,enroll_device:!1,verify_otp:!1,reset:!0,batch:!0,generate_x402_image:!1,browser_launch:!1,browser_navigate:!1,browser_snapshot:!1,browser_click:!1,browser_type:!1,browser_scroll:!1,generate_music_card:!1,generate_image_card:!0,query_onchain_prices_card:!0,generate_music_tempo_card:!0,check_music_status_tempo_card:!0,generate_image_fast_card:!0,pxlwall_card:!1,generate_video_tempo_card:!0};static loadToolStates(){return{...this.TOOL_STATES}}static getDisabledTools(){let t=new Set;for(let[n,r]of Object.entries(this.TOOL_STATES))r||t.add(n);return t}static isToolDisabled(t){return this.TOOL_STATES[t]===!1}};var Ps="settings.json";function He(){return Rn.join(me.getConfigDir(),Ps)}var he={"auth.serverUrl":{type:"string",description:"Auth server base URL. Override for staging / self-hosted backends.",requiresRestart:!0,validate:e=>{if(typeof e!="string")throw new Error("auth.serverUrl must be a string");let t;try{t=new URL(e)}catch{throw new Error(`auth.serverUrl must be a valid URL (got: ${JSON.stringify(e)})`)}if(t.protocol!=="https:"&&t.protocol!=="http:")throw new Error(`auth.serverUrl must use http or https (got: ${t.protocol})`)}},"ui.suppressBrowser":{type:"boolean",description:"When true, the CLI/MCP server stops auto-opening result URLs in your browser."},"ui.suppressFeed":{type:"boolean",description:"When true, generated images/music are not auto-submitted to the public Made-with-Visa feed."},"tools.meta":{type:"boolean",description:"Show category meta-tools (generate_image, generate_music, ...). Restart required.",requiresRestart:!0},"tools.specific":{type:"boolean",description:"Show hardcoded per-merchant tools (generate_image_card, query_onchain_prices_card, ...). Restart required.",requiresRestart:!0},"tools.discover":{type:"boolean",description:"Show the dynamic-catalog tools (discover_tools, execute_tool). Restart required.",requiresRestart:!0}};function Ve(){let e=He();if(!ee.existsSync(e))return{};try{let t=ee.readFileSync(e,"utf-8"),n=JSON.parse(t);return!n||typeof n!="object"||Array.isArray(n)?{}:n}catch{return{}}}function In(e){me.ensureConfigDir();let t=He(),n=`${t}.tmp`,r=JSON.stringify(e,null,2)+`
33
+ `;ee.writeFileSync(n,r,{mode:384}),ee.renameSync(n,t)}function wt(e){let t=Ve()[e];return typeof t=="string"?t:void 0}function Ln(e){let t=Ve()[e];if(typeof t=="boolean")return t;if(t==="true")return!0;if(t==="false")return!1}var ae=class extends Error{constructor(t){let n=Object.keys(he).sort().join(", ");super(`Unknown setting "${t}". Settable keys: ${n}. For server-controlled values (biometric.*, spending.*) use the dedicated tools (biometric_on/off, update_spending_controls).`),this.name="UnknownSettingKeyError"}},ce=class extends Error{constructor(t){let n="";t.startsWith("biometric.")?n="biometric_on / biometric_off":t.startsWith("spending.")?n="update_spending_controls":t.startsWith("cards.")?n="add_card / remove_card / set_default_card":t.startsWith("account.")&&(n="login / reset"),super(`"${t}" is a server-controlled value and cannot be set via config set. `+(n?`Use ${n} instead.`:"No client-side override is supported.")),this.name="ServerOnlySettingError"}},Nn=["biometric.","spending.","account.","cards.","biometric"];function On(e,t){if(Nn.some(o=>e.startsWith(o)))throw new ce(e);let n=he[e];if(!n)throw new ae(e);let r;if(n.type==="boolean")if(typeof t=="boolean")r=t;else if(typeof t=="string"){let o=t.toLowerCase();if(o==="true")r=!0;else if(o==="false")r=!1;else throw new Error(`${e} expects true or false (got: ${JSON.stringify(t)})`)}else throw new Error(`${e} expects a boolean (got: ${typeof t})`);else{if(typeof t!="string"||t.length===0)throw new Error(`${e} expects a non-empty string`);r=t}n.validate&&n.validate(r);let s=Ve();return s[e]=r,In(s),{key:e,value:r,requiresRestart:!!n.requiresRestart,path:He()}}function Dn(e){if(Nn.some(s=>e.startsWith(s)))throw new ce(e);let t=he[e];if(!t)throw new ae(e);let n=Ve(),r=e in n;return r&&(delete n[e],In(n)),{key:e,removed:r,requiresRestart:r&&!!t.requiresRestart,path:He()}}var Ts="https://auth.visacli.sh";function Un(){let e=process.env.VISA_AUTH_URL;if(e!==void 0&&e!=="")return e;let t=wt("auth.serverUrl");return t!==void 0?t:Ts}var _t="1.11.0-rc.2",le=class{constructor(t){this.getSessionToken=t;this.baseUrl=Un()}getSessionToken;baseUrl;lastSignals={};parseServerSignals(t){if(this.lastSignals={},!J()){let r=t.headers.get("X-Latest-Version"),s=t.headers.get("X-Update-Message");r&&En(r,_t)&&(this.lastSignals.updateAvailable={version:r,message:s||`Update available: v${r}. Run: npm install -g @visa/cli && visa-cli setup`})}let n=t.headers.get("X-Feedback-Prompt");if(n)try{this.lastSignals.feedbackPrompt=JSON.parse(n)}catch{}}getClientVersion(){return _t}async request(t,n,r,s,o){let i=await this.getSessionToken();if(!i)throw new Error("Not logged in. Sign up at https://visacli.sh or run: visa-cli setup");let a={Authorization:`Bearer ${i}`};o&&(t==="GET"?a["X-User-Context"]=o.replace(/[\r\n\0]/g," ").slice(0,1e3):r={...r||{},user_context:o}),r&&(a["Content-Type"]="application/json");let c;try{c=await xn(`${this.baseUrl}${n}`,{method:t,headers:{...a,"X-Visa-CLI-Version":_t},body:r?JSON.stringify(r):void 0,timeoutMs:s})}catch(u){throw u.name==="AbortError"||u.message?.includes("aborted")?new Error("The request timed out. The server may be under heavy load. Please try again."):new Error("Cannot reach the Visa CLI server. Check your internet connection and try again.")}if(this.parseServerSignals(c),c.status===401)throw new Error("Your session has expired. Run: visa-cli setup");if(c.status===429){let u=c.headers.get("Retry-After")||"3";throw new Error(`Rate limited \u2014 wait ${u}s. Tip: use the batch tool to combine multiple requests into one.`)}if(c.status===503)throw new Error("Visa CLI is temporarily unavailable. Check https://visacli.sh for status.");let l;try{l=await c.json()}catch{throw c.status===500?new Error(`Server error on ${n}. Try again or check https://visacli.sh for status.`):new Error(`Unexpected response from ${n}. Try again.`)}if(!c.ok)throw c.status===500?new Error(`Server error on ${n}. Try again or check https://visacli.sh for status.`):l?.declined?new je(l.error||"Your card was declined.",!!l.retryable,l.code,l.reason):new Error(l?.error||`Request failed (${c.status}). Try again.`);return l}async pay(t,n){return this.request("POST","/v1/pay",t,void 0,n)}async shortcut(t,n,r,s){return this.request("POST",`/v1/shortcuts/${encodeURIComponent(t)}`,n,r,s)}async batch(t,n,r){return this.request("POST","/v1/batch",t,n,r)}async catalogSearch(t,n){let r=new URLSearchParams;t&&r.set("q",t),n&&r.set("category",n);let s=r.toString();return this.request("GET",`/v1/catalog${s?`?${s}`:""}`)}async catalogTool(t){try{return await this.request("GET",`/v1/catalog/${encodeURIComponent(t)}`)}catch{return null}}async paymentPreview(t,n){return this.request("POST","/v1/payment-preview",t,void 0,n)}async getStatus(t){return this.request("GET","/v1/status",void 0,void 0,t)}async getTransactions(t){return this.request("GET","/v1/transactions",void 0,void 0,t)}async updateSpendingControls(t,n){return this.request("POST","/v1/spending-controls",t,void 0,n)}async removeCard(t,n,r){return this.request("DELETE",`/v1/cards/${encodeURIComponent(String(t))}`,n,void 0,r)}async setDefaultCard(t,n,r){return this.request("POST",`/v1/cards/${encodeURIComponent(String(t))}/default`,n,void 0,r)}async getAttestationChallenge(){return this.request("GET","/v1/attestation-challenge")}async registerAttestationKey(t){return this.request("POST","/v1/attestation-key",{publicKey:t})}async setBiometricPreference(t,n){return this.request("POST","/v1/biometric-preference",{...t,confirm:!0},void 0,n)}async logout(t,n){return this.request("POST","/v1/logout",t,void 0,n)}async feedback(t,n,r){return this.request("POST","/v1/feedback",{message:t,...n&&{transaction_id:n}},void 0,r)}async createAppApiKey(t){return this.request("POST","/v1/api/keys",t)}async listAppApiKeys(){return this.request("GET","/v1/api/keys")}async revokeAppApiKey(t){return this.request("DELETE",`/v1/api/keys/${encodeURIComponent(String(t))}`)}async feedSubmit(t){return this.request("POST","/v1/feed",t)}async feedList(t){let n=new URLSearchParams;t?.tab&&n.set("tab",t.tab),t?.limit&&n.set("limit",String(t.limit)),t?.offset&&n.set("offset",String(t.offset));let r=n.toString();return this.request("GET",`/v1/feed${r?"?"+r:""}`)}async feedVote(t,n){return this.request("POST",`/v1/feed/${encodeURIComponent(t)}/vote`,{direction:n})}async feedApprove(t){return this.request("POST",`/v1/feed/${encodeURIComponent(t)}/approve`)}async feedDelete(t){return this.request("DELETE",`/v1/feed/${encodeURIComponent(t)}`)}async feedPending(){return this.request("GET","/v1/feed/pending")}async submitFeedback(t,n,r){return this.request("POST","/v1/feedback",{message:t,...n&&{transaction_id:n}},void 0,r)}async getFeedback(t,n){let r=new URLSearchParams;t&&r.set("limit",String(t));let s=r.toString();return this.request("GET",`/v1/feedback${s?"?"+s:""}`,void 0,void 0,n)}async submitRatedFeedback(t){return this.request("POST","/v1/feedback",t)}};var Et=require("child_process"),Bn=require("util"),Kn=h(require("crypto")),A=h(require("fs")),qn=h(require("os")),W=h(require("path"));var O=h(require("fs")),xt=h(require("path")),jn=h(require("os")),kt=xt.join(jn.homedir(),".visa-mcp"),ye=xt.join(kt,"mcp-server.log"),As=5*1024*1024,Ct=null;function Rs(){O.existsSync(kt)||O.mkdirSync(kt,{recursive:!0,mode:448})}function Is(){if(!Ct){if(Rs(),O.existsSync(ye)&&O.statSync(ye).size>As){let t=ye+".1";O.existsSync(t)&&O.unlinkSync(t),O.renameSync(ye,t)}Ct=O.createWriteStream(ye,{flags:"a"})}return Ct}function Fe(e,...t){let n=new Date().toISOString(),r=t.map(o=>typeof o=="string"?o:JSON.stringify(o,null,2)).join(" "),s=`[${n}] [${e}] ${r}
34
+ `;process.stderr.write(s),Is().write(s)}var ue={debug:(...e)=>Fe("DEBUG",...e),info:(...e)=>Fe("INFO",...e),warn:(...e)=>Fe("WARN",...e),error:(...e)=>Fe("ERROR",...e)};var de=(0,Bn.promisify)(Et.execFile),qe=W.join(qn.homedir(),".visa-mcp","bin"),re=W.join(qe,"Visa CLI"),Ls=W.join(__dirname,"..","native"),Mn="5",Hn=W.join(qe,"visa-keychain.version"),Vn=W.join(qe,"visa-keychain.sha256");function Fn(e){let t=A.readFileSync(e);return Kn.createHash("sha256").update(t).digest("hex")}async function Gn(){try{if(A.readFileSync(Hn,"utf-8").trim()===Mn&&A.existsSync(re)){let r=A.readFileSync(Vn,"utf-8").trim();if(Fn(re)!==r)ue.warn("binary:hash-mismatch",{message:"Binary hash mismatch \u2014 possible tampering detected. Recompiling from source."}),A.unlinkSync(re);else return re}}catch{}let e=W.join(Ls,"visa-keychain.m");if(A.existsSync(e)||(e=W.resolve(__dirname,"..","..","native","visa-keychain.m")),A.existsSync(e)||(e=W.resolve(__dirname,"..","native","visa-keychain.m")),!A.existsSync(e))throw new Error("visa-keychain.m source not found. Reinstall Visa CLI.");A.mkdirSync(qe,{recursive:!0,mode:448});try{await de("clang",["-framework","Security","-framework","LocalAuthentication","-framework","Foundation","-framework","AppKit","-o",re,e],{timeout:3e4})}catch(n){throw n.code==="ENOENT"?new Error("Xcode Command Line Tools required. Install: xcode-select --install"):n}let t=Fn(re);return A.writeFileSync(Vn,t,{mode:384}),A.writeFileSync(Hn,Mn,{mode:384}),re}async function Jn(e){let t=await Gn(),n;try{n=(await de(t,e,{timeout:6e4})).stdout}catch(o){n=o.stdout||"";let i=n.trim();throw i.startsWith("ERROR:")?new Error(i.slice(6)):new Error(o.stderr?.trim()||o.message||"Unknown error")}let r=n.trim();if(r.startsWith("OK:"))return r.slice(3);if(r==="OK")return;let s=r.startsWith("ERROR:")?r.slice(6):"Unknown error";throw new Error(s)}var $t=null;function D(){return process.env.VISA_MOCK_TOUCHID==="true"?!0:process.platform!=="darwin"?!1:$t!==null?$t:($t=!0,!0)}var Be="visa-cli",Ke="attestation-key";async function Ns(e){try{await de("security",["delete-generic-password","-s",Be,"-a",Ke],{timeout:5e3})}catch{}await de("security",["add-generic-password","-s",Be,"-a",Ke,"-w",e],{timeout:5e3})}async function Os(){try{let{stdout:e}=await de("security",["find-generic-password","-s",Be,"-a",Ke,"-w"],{timeout:5e3});return e.trim()||null}catch{return null}}async function Ge(){let e=await Jn(["generate-key"]);if(!e)throw new Error("Key generation returned no output");let t=e.indexOf(":");if(t<0)throw new Error("Unexpected generate-key output format");let n=e.slice(0,t),r=e.slice(t+1);return await Ns(n),r}async function Pt(e,t){if(process.env.VISA_MOCK_TOUCHID==="true")return Promise.resolve("mock-ecdsa-signature-for-testing");let n=await Os();if(!n)throw new Error("Attestation key not found. Run setup to generate a new key.");let r=await Gn(),s=["sign",e];return t&&s.push(t),new Promise((o,i)=>{let a=(0,Et.execFile)(r,s,{timeout:6e4},(c,l)=>{let u=(l||"").trim();if(c){u.startsWith("ERROR:")?i(new Error(u.slice(6))):i(new Error(c.stderr?.trim()||c.message||"Unknown error"));return}u.startsWith("OK:")?o(u.slice(3)):i(new Error(u.startsWith("ERROR:")?u.slice(6):"Unknown error"))});a.stdin.write(n),a.stdin.end()})}async function Wn(){try{await de("security",["delete-generic-password","-s",Be,"-a",Ke],{timeout:5e3})}catch{}try{await Jn(["delete-key"])}catch{}}function zn(e,t=process.stderr){if(J()||!e?.updateAvailable)return!1;let{message:n}=e.updateAvailable;return n?(t.write(`
35
35
  \x1B[33m\u2191 ${n}\x1B[0m
36
- `),!0):!1}function Jn(e,t,n,r){let s=r.currentVersion==="0.0.0"&&e.version?e.version:r.currentVersion,i=Ms(e.spendingControls).dailyLimit,a=Math.max(0,Se(e.dailySpent)),c=i>0?Math.min(i,Math.max(0,Se(e.dailyRemaining??i-a))):0,l=i>0?Math.min(1,a/i):0,f=(Array.isArray(t)?t:[]).filter(Ns),y=f.slice(0,3),w=Ds(f,3),u=(e.cards??[]).slice(0,3),S=r.latestVersion?Pt(r.latestVersion):"",_=r.updateCheckDisabled?"update checks disabled":S?`update ready: v${S}`:"up to date",C=Math.round(l*100),E=te(e.status,e.enrolled?"approved":"not enrolled"),ie=["VISA CLI",`Status: ${e.enrolled?"Visa ready":"Visa setup needed"} | account: ${E} | touch id: ${n?"ready":"unavailable"}`,`Version: v${s} | ${_}`,`Spend meter: ${Wn(l)} ${String(C).padStart(3," ")}% | remaining ${fe(c)}/day | daily cap ${fe(i)}`,"","Spend",` Remaining ${fe(c)} / ${fe(i)}`,` Usage ${Wn(l)} ${C}%`,` Spent today ${fe(a)}`,` Attestation key ${e.hasAttestationKey?"registered":"missing"}`,"","Cards",...u.length>0?u.map(I=>` ${js(I)}`):[" No cards enrolled"],"","Last 3 services",...w.length>0?w.map((I,F)=>` ${F+1}. ${I}`):[" No paid services yet"],"","Recent receipts",...y.length>0?y.map(I=>` ${Us(I)}`):[" No receipts yet"]];return r.updateMessage&&ie.push("",`Update: ${Pt(r.updateMessage)}`),`${ie.join(`
36
+ `),!0):!1}function Xn(e,t,n,r){let s=r.currentVersion==="0.0.0"&&e.version?e.version:r.currentVersion,i=Fs(e.spendingControls).dailyLimit,a=Math.max(0,Se(e.dailySpent)),c=i>0?Math.min(i,Math.max(0,Se(e.dailyRemaining??i-a))):0,l=i>0?Math.min(1,a/i):0,f=(Array.isArray(t)?t:[]).filter(js),y=f.slice(0,3),w=Ms(f,3),d=(e.cards??[]).slice(0,3),S=r.latestVersion?At(r.latestVersion):"",_=r.updateCheckDisabled?"update checks disabled":S?`update ready: v${S}`:"up to date",C=Math.round(l*100),E=te(e.status,e.enrolled?"approved":"not enrolled"),ie=["VISA CLI",`Status: ${e.enrolled?"Visa ready":"Visa setup needed"} | account: ${E} | touch id: ${n?"ready":"unavailable"}`,`Version: v${s} | ${_}`,`Spend meter: ${Yn(l)} ${String(C).padStart(3," ")}% | remaining ${fe(c)}/day | daily cap ${fe(i)}`,"","Spend",` Remaining ${fe(c)} / ${fe(i)}`,` Usage ${Yn(l)} ${C}%`,` Spent today ${fe(a)}`,` Attestation key ${e.hasAttestationKey?"registered":"missing"}`,"","Cards",...d.length>0?d.map(I=>` ${Vs(I)}`):[" No cards enrolled"],"","Last 3 services",...w.length>0?w.map((I,F)=>` ${F+1}. ${I}`):[" No paid services yet"],"","Recent receipts",...y.length>0?y.map(I=>` ${Hs(I)}`):[" No receipts yet"]];return r.updateMessage&&ie.push("",`Update: ${At(r.updateMessage)}`),`${ie.join(`
37
37
  `)}
38
- `}function Ls(e){return e.tool_name!=null}function Os(e){return Se(e.amount)===0&&e.status==="failed"}function Ns(e){return Ls(e)&&!Os(e)}function Ds(e,t=1/0){let n=new Set,r=[];for(let s of e){if(r.length>=t)break;let o=te(s.merchant_name,"Unknown merchant"),i=te(s.tool_name,"unknown_tool"),a=`${o} :: ${i}`;n.has(a)||(n.add(a),r.push(`${o} [${i}]`))}return r}function Us(e){let t=te(e.merchant_name,"Unknown merchant"),n=te(e.tool_name,"unknown_tool"),r=fe(Se(e.amount)),s=te(e.status,"unknown"),o=Hs(e.created_at);return`${r} ${s.padEnd(9)} ${t} [${n}] ${o}`}function js(e){let t=te(e.brand?.toUpperCase(),"CARD"),n=e.isDefault?" default":"";return`${Number.isInteger(e.id)?`#${e.id} `:""}${t} ****${e.last4}${n}`}function Ms(e){return{dailyLimit:Se(e?.daily_limit??e?.dailyLimit??0)}}function Se(e){let t=Number(typeof e=="string"?e:e??0);return Number.isFinite(t)?t:0}function fe(e){return`$${e.toFixed(2)}`}function Wn(e,t=20){let n=Math.max(0,Math.min(1,e)),r=Math.round(n*t);return`[${"\u2588".repeat(r)}${"\u2591".repeat(t-r)}]`}function te(e,t){let n=Pt(e??"").trim();return n.length>0?n:t}function Hs(e){if(!e)return"unknown time";let t=new Date(e);return Number.isNaN(t.getTime())?te(e,"unknown time"):t.toISOString().slice(0,16).replace("T"," ")}function Pt(e){return e.replace(/\u001B\][^\u0007]*(?:\u0007|\u001B\\)/g,"").replace(/\u001B\[[0-?]*[ -/]*[@-~]/g,"").replace(/[\u0000-\u0008\u000B-\u001F\u007F-\u009F]/g,"").replace(/\s+/g," ")}var b=h(require("fs")),Je=h(require("os")),x=h(require("path")),Yn=require("child_process"),Vs=2,qe="# >>> visa-cli shell hud v2 >>>",Ge="# <<< visa-cli shell hud v2 <<<",Fs="# >>> visa-cli shell hud >>>",Bs="# <<< visa-cli shell hud <<<",Xn=3e4,Ks={currentVersion:"0.0.0"},qs=3e4;function It(){try{return x.join(rr(),".visa-cli")}catch{return x.join(Je.tmpdir(),".visa-cli")}}function be(){return x.join(It(),"shell-hud.json")}function ze(){return x.join(It(),"shell-hud.line")}function Zn(){return x.join(It(),"shell-hud.lock")}function Ye(e){let t=e??process.env.SHELL;if(!t)return null;let n=x.basename(t.replace(/\\/g,"/")).toLowerCase();return n==="zsh"?"zsh":n==="bash"?"bash":n==="pwsh"||n==="pwsh.exe"||n==="powershell"||n==="powershell.exe"?"powershell":null}function Xe(e){let t=rr();if(e==="zsh")return x.join(t,".zshrc");if(e==="bash")return x.join(t,".bashrc");let n=(process.platform==="win32","PowerShell");return x.join(t,"Documents",n,"Microsoft.PowerShell_profile.ps1")}function Gs(e){let t="$HOME/.visa-cli/shell-hud.line",n=to(e),r=no(e);if(e==="zsh")return`${qe}
38
+ `}function Ds(e){return e.tool_name!=null}function Us(e){return Se(e.amount)===0&&e.status==="failed"}function js(e){return Ds(e)&&!Us(e)}function Ms(e,t=1/0){let n=new Set,r=[];for(let s of e){if(r.length>=t)break;let o=te(s.merchant_name,"Unknown merchant"),i=te(s.tool_name,"unknown_tool"),a=`${o} :: ${i}`;n.has(a)||(n.add(a),r.push(`${o} [${i}]`))}return r}function Hs(e){let t=te(e.merchant_name,"Unknown merchant"),n=te(e.tool_name,"unknown_tool"),r=fe(Se(e.amount)),s=te(e.status,"unknown"),o=Bs(e.created_at);return`${r} ${s.padEnd(9)} ${t} [${n}] ${o}`}function Vs(e){let t=te(e.brand?.toUpperCase(),"CARD"),n=e.isDefault?" default":"";return`${Number.isInteger(e.id)?`#${e.id} `:""}${t} ****${e.last4}${n}`}function Fs(e){return{dailyLimit:Se(e?.daily_limit??e?.dailyLimit??0)}}function Se(e){let t=Number(typeof e=="string"?e:e??0);return Number.isFinite(t)?t:0}function fe(e){return`$${e.toFixed(2)}`}function Yn(e,t=20){let n=Math.max(0,Math.min(1,e)),r=Math.round(n*t);return`[${"\u2588".repeat(r)}${"\u2591".repeat(t-r)}]`}function te(e,t){let n=At(e??"").trim();return n.length>0?n:t}function Bs(e){if(!e)return"unknown time";let t=new Date(e);return Number.isNaN(t.getTime())?te(e,"unknown time"):t.toISOString().slice(0,16).replace("T"," ")}function At(e){return e.replace(/\u001B\][^\u0007]*(?:\u0007|\u001B\\)/g,"").replace(/\u001B\[[0-?]*[ -/]*[@-~]/g,"").replace(/[\u0000-\u0008\u000B-\u001F\u007F-\u009F]/g,"").replace(/\s+/g," ")}var b=h(require("fs")),Ye=h(require("os")),$=h(require("path")),Qn=require("child_process"),Ks=2,Je="# >>> visa-cli shell hud v2 >>>",We="# <<< visa-cli shell hud v2 <<<",qs="# >>> visa-cli shell hud >>>",Gs="# <<< visa-cli shell hud <<<",er=3e4,Js={currentVersion:"0.0.0"},Ws=3e4;function Nt(){try{return $.join(ir(),".visa-cli")}catch{return $.join(Ye.tmpdir(),".visa-cli")}}function be(){return $.join(Nt(),"shell-hud.json")}function Xe(){return $.join(Nt(),"shell-hud.line")}function tr(){return $.join(Nt(),"shell-hud.lock")}function Ze(e){let t=e??process.env.SHELL;if(!t)return null;let n=$.basename(t.replace(/\\/g,"/")).toLowerCase();return n==="zsh"?"zsh":n==="bash"?"bash":n==="pwsh"||n==="pwsh.exe"||n==="powershell"||n==="powershell.exe"?"powershell":null}function Qe(e){let t=ir();if(e==="zsh")return $.join(t,".zshrc");if(e==="bash")return $.join(t,".bashrc");let n=(process.platform==="win32","PowerShell");return $.join(t,"Documents",n,"Microsoft.PowerShell_profile.ps1")}function zs(e){let t="$HOME/.visa-cli/shell-hud.line",n=so(e),r=oo(e);if(e==="zsh")return`${Je}
39
39
  _visa_cli_shell_hud_precmd() {
40
40
  setopt localoptions no_bg_nice
41
41
  if [[ -f "${t}" ]]; then
@@ -52,7 +52,7 @@ autoload -Uz add-zsh-hook
52
52
  if [[ -z "\${precmd_functions[(r)_visa_cli_shell_hud_precmd]}" ]]; then
53
53
  add-zsh-hook precmd _visa_cli_shell_hud_precmd
54
54
  fi
55
- ${Ge}`;if(e==="powershell"){let s="(Join-Path $HOME '.visa-cli/shell-hud.line')";return`${qe}
55
+ ${We}`;if(e==="powershell"){let s="(Join-Path $HOME '.visa-cli/shell-hud.line')";return`${Je}
56
56
  if (-not (Test-Path Function:\\global:__visa_cli_original_prompt)) {
57
57
  $function:global:__visa_cli_original_prompt = if (Test-Path Function:\\prompt) { $function:prompt } else { { '' } }
58
58
  }
@@ -71,7 +71,7 @@ function global:prompt {
71
71
  }
72
72
  & $function:global:__visa_cli_original_prompt
73
73
  }
74
- ${Ge}`}return`${qe}
74
+ ${We}`}return`${Je}
75
75
  __visa_cli_shell_hud_precmd() {
76
76
  if [ -f "${t}" ]; then
77
77
  cat "${t}"
@@ -88,37 +88,37 @@ case ";$PROMPT_COMMAND;" in
88
88
  *";__visa_cli_shell_hud_precmd;"*) ;;
89
89
  *) PROMPT_COMMAND="__visa_cli_shell_hud_precmd\${PROMPT_COMMAND:+;$PROMPT_COMMAND}" ;;
90
90
  esac
91
- ${Ge}`}function Qn(e){let t=e;for(let[n,r]of[[qe,Ge],[Fs,Bs]])t=t.replace(new RegExp(`\\n?${zn(n)}[\\s\\S]*?${zn(r)}\\n?`,"g"),"");return t.trimEnd()}function Ws(e,t){let n=Qn(e).trimEnd(),r=Gs(t);return n.length>0?`${n}
91
+ ${We}`}function nr(e){let t=e;for(let[n,r]of[[Je,We],[qs,Gs]])t=t.replace(new RegExp(`\\n?${Zn(n)}[\\s\\S]*?${Zn(r)}\\n?`,"g"),"");return t.trimEnd()}function Ys(e,t){let n=nr(e).trimEnd(),r=zs(t);return n.length>0?`${n}
92
92
 
93
93
  ${r}
94
94
  `:`${r}
95
- `}function Lt(e=Ye()){if(!e)return{installed:!1,changed:!1,shell:null,message:"Shell HUD auto-install skipped: supported shells are zsh, bash, and PowerShell."};let t;try{t=Xe(e);let n=b.existsSync(t)?b.readFileSync(t,"utf-8"):"",r=Ws(n,e),s=r!==n;return s&&We(t,r),{installed:!0,changed:s,shell:e,rcPath:t,message:s?`Persistent shell HUD installed in ${t}. Open a new terminal to start seeing it. Disable it any time with: visa-cli shell-hud disable`:`Persistent shell HUD already installed in ${t}. Disable it any time with: visa-cli shell-hud disable`}}catch(n){return{installed:!1,changed:!1,shell:e,rcPath:t,message:`Failed to install persistent shell HUD in ${t}: ${sr(n)}`}}}function Ot(e=Ye()){if(!e)return{removed:!1,shell:null,message:"Shell HUD uninstall skipped: supported shells are zsh, bash, and PowerShell."};let t;try{if(t=Xe(e),!b.existsSync(t))return{removed:!1,shell:e,rcPath:t,message:`No ${e} rc file found at ${t}.`};let n=b.readFileSync(t,"utf-8"),r=Qn(n);return r===n.trimEnd()?{removed:!1,shell:e,rcPath:t,message:`Persistent shell HUD was not installed in ${t}.`}:(We(t,r.length>0?`${r}
96
- `:""),{removed:!0,shell:e,rcPath:t,message:`Removed persistent shell HUD from ${t}.`})}catch(n){return{removed:!1,shell:e,rcPath:t,message:`Failed to remove persistent shell HUD from ${t}: ${sr(n)}`}}}function Nt(e,t){let n=t??Ks,r=n.currentVersion==="0.0.0"&&e.version?e.version:n.currentVersion,s=we(r),o=` ${U("\u2502",L.dim)} `,i=er(n),a=Js(s,i),c=zs(n,i);if(!e.enrolled)return[a,U("setup needed",L.visaGold),c].filter(Boolean).join(o);let l=Tt(e.spendingControls?.daily_limit??e.spendingControls?.dailyLimit),d=Math.max(0,Tt(e.dailySpent)),f=l>0?Math.min(l,Math.max(0,Tt(e.dailyRemaining??l-d))):0,y=l>0?Math.max(0,Math.min(1,d/l)):0,w=Qs(e),u=l>0?`${Zs(y)} ${U(`${At(f)} left today`,L.green)} ${U(`(${At(d)}/${At(l)}/day)`,L.dim)}`:U("no spend limit",L.dim);return[a,U(w,L.visaGold),u,c].filter(Boolean).join(o)}function Js(e,t){let n=`${U("VISA CLI",L.visaBlue)} ${U(`v${e}`,L.visaBlueSoft)}`;return t?`${n} ${U("\u2B06 update",L.visaGold)} ${U(`v${t}`,L.visaGold)}`:n}function zs(e,t){return t?null:Ys(e)}function er(e){return e.latestVersion?we(e.latestVersion):""}function Ys(e){let t=er(e);return t?U(`update ready v${t}`,L.visaGold):e.updateMessage?U("update ready",L.visaGold):null}function tr(){let e=nr();return!!e&&Date.now()-e.renderedAt<=Xn}function Dt(){let e=nr();if(e&&Date.now()-e.renderedAt<=Xn||(Xs(),e?.line))return e.line;try{let t=ze();if(b.existsSync(t))return b.readFileSync(t,"utf-8").trimEnd()}catch{}return"VISA | loading spend HUD\u2026"}function Ut(e){try{let t=x.dirname(be());b.mkdirSync(t,{recursive:!0});let n=we(e),r={hudVersion:Vs,renderedAt:Date.now(),line:n};We(be(),JSON.stringify(r)+`
97
- `),We(ze(),n+`
98
- `)}catch{}}function ve(){try{b.unlinkSync(Zn())}catch{}}function nr(){let e=be();if(!b.existsSync(e))return null;try{return JSON.parse(b.readFileSync(e,"utf-8"))}catch{return null}}function Xs(){if(process.env.JEST_WORKER_ID)return;let e=Zn();try{if(b.mkdirSync(x.dirname(e),{recursive:!0}),!ro(e))return;let t=process.argv[1]?x.resolve(process.argv[1]):"";if(!t){ve();return}let n=(0,Yn.spawn)(process.execPath,[t,"shell-hud","refresh"],{detached:!0,stdio:"ignore",env:{...process.env,VISA_CLI_SHELL_HUD_BACKGROUND:"1"}});n.once("error",ve),n.unref()}catch{ve()}}function Tt(e){let t=Number(typeof e=="string"?e:e??0);return Number.isFinite(t)?t:0}function we(e){return e.replace(/\u001B\][^\u0007]*(?:\u0007|\u001B\\)/g,"").replace(/\u001B\[[0-?]*[ -/]*[@-~]/g,"").replace(/\u001B[P_^][^\u001B]*(?:\u001B\\|\u0007)/g,"").replace(/[\u0000-\u0008\u000B-\u001F\u007F-\u009F]/g,"").replace(/\s+/g," ").trim()}function Zs(e){let n=Math.round(Math.max(0,Math.min(1,e))*10),r="\u2588".repeat(n),s="\u2591".repeat(10-n);return`${U(r||"",L.green)}${U(s||"",L.dim)}`}function At(e){return`$${e.toFixed(2)}`}function Qs(e){let t=e.cards?.find(a=>a.isDefault)??e.cards?.[0];if(!t)return"card none";let n=typeof t.brand=="string"?t.brand:"card",r=typeof t.last4=="string"?t.last4:"????",s=we(n.toUpperCase()),o=we(r);return`${t.isDefault?"default":"active"} ${s} ****${o}`}function eo(){let e=(process.env.COLORTERM??"").toLowerCase();if(e==="truecolor"||e==="24bit")return!0;let t=(process.env.TERM??"").toLowerCase();return t.includes("truecolor")||t.includes("24bit")}var Rt=eo(),L={reset:"\x1B[0m",visaBlue:Rt?"\x1B[38;2;20;52;203m":"\x1B[38;5;27m",visaBlueSoft:Rt?"\x1B[38;2;97;126;229m":"\x1B[38;5;111m",visaGold:Rt?"\x1B[38;2;247;182;0m":"\x1B[38;5;220m",green:"\x1B[38;5;48m",dim:"\x1B[2m"};function U(e,t){return e.length===0||process.env.NO_COLOR?e:`${t}${e}${L.reset}`}function zn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function rr(){let e=Je.homedir();if(!e||!x.isAbsolute(e))throw new Error("unable to determine a valid home directory");return x.resolve(e)}function to(e){return e==="powershell"?"& visa-cli shell-hud refresh":"visa-cli shell-hud refresh"}function no(e){return e==="powershell"?"Get-Command visa-cli -ErrorAction SilentlyContinue -CommandType Application":"command -v visa-cli >/dev/null 2>&1"}function ro(e){for(let t=0;t<2;t+=1){let n;try{return n=b.openSync(e,"wx"),b.writeFileSync(n,String(Date.now())),!0}catch(r){if(r?.code!=="EEXIST")return!1;try{let s=b.statSync(e);if(Date.now()-s.mtimeMs<=qs)return!1;b.unlinkSync(e)}catch{}}finally{n!==void 0&&b.closeSync(n)}}return!1}function sr(e){return e instanceof Error?e.message:"unknown file system error"}function We(e,t){b.mkdirSync(x.dirname(e),{recursive:!0});let n=`${e}.${process.pid}.${Date.now()}.tmp`;b.writeFileSync(n,t),b.renameSync(n,e)}async function jt(e,t){try{return await t()}catch(n){if(n.message==="Invalid signature"&&D()){ue.warn("attestation:key-mismatch",{action:"reregistering"});try{let r=await Ke();await e.registerAttestationKey(r),ue.info("attestation:key-reregistered")}catch(r){throw ue.error("attestation:reregister-failure",{error:r.message}),n}return await t()}throw n}}var or="1.11.0-rc.1";function Mt(e,t){return t?{kind:"env",var:e}:{kind:"default"}}function so(e,t,n){let r=process.env[e];if(r!==void 0&&r!=="")return{value:r,source:{kind:"env",var:e}};let s=vt(t);return s!==void 0?{value:s,source:{kind:"settings"}}:{value:n,source:{kind:"default"}}}function _e(e,t,n){let r=process.env[e];if(r!==void 0)return{value:n==="opt-in"?r==="true":r!=="false",source:{kind:"env",var:e}};let s=An(t);return s!==void 0?{value:s,source:{kind:"settings"}}:{value:n!=="opt-in",source:{kind:"default"}}}function H(e){return e==null?"\u2014":e?"yes":"no"}function Ze(e){return e==null?"\u2014":`$${e.toFixed(2)}`}async function ir(e){let t=null,n=null;try{t=await e.api.getStatus()}catch(C){n=C?.message||"unknown error"}let r=[],s=so("VISA_AUTH_URL","auth.serverUrl","https://auth.visacli.sh");r.push({key:"auth.serverUrl",value:s.value,formatted:s.value,source:s.source,hint:s.source.kind==="default"?"Persist with `visa-cli config set auth.serverUrl <url>` (or set VISA_AUTH_URL for one-off overrides).":void 0}),r.push({key:"account.enrolled",value:t?.enrolled??null,formatted:H(t?.enrolled),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}}),t?.githubUser&&r.push({key:"account.githubUser",value:t.githubUser,formatted:t.githubUser,source:{kind:"server"}});let o=t?t.attestationRequired!==!1:void 0;r.push({key:"biometric.required",value:o,formatted:H(o),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"},hint:o===!1?"Touch ID prompts are suppressed. Re-enable with `visa-cli biometric on`.":void 0}),r.push({key:"biometric.keyRegistered",value:t?.hasAttestationKey??null,formatted:H(t?.hasAttestationKey),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}}),r.push({key:"biometric.deviceAvailable",value:D(),formatted:H(D()),source:{kind:"device"}});let i=t?.spendingControls,a=i?i.max_transaction_amount??i.maxTransactionAmount??null:null,c=i?i.daily_limit??i.dailyLimit??null:null;r.push({key:"spending.maxPerTxn",value:a,formatted:Ze(a),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}}),r.push({key:"spending.dailyLimit",value:c,formatted:Ze(c),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}}),r.push({key:"spending.dailySpent",value:t?.dailySpent??null,formatted:Ze(t?.dailySpent),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}}),r.push({key:"spending.dailyRemaining",value:t?.dailyRemaining??null,formatted:Ze(t?.dailyRemaining),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}}),r.push({key:"cards.count",value:t?.cardCount??null,formatted:t?.cardCount!=null?String(t.cardCount):"\u2014",source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}});let l=t?.cards?.find(C=>C.isDefault)??t?.cards?.[0];l&&r.push({key:"cards.default",value:{brand:l.brand??null,last4:l.last4},formatted:`${l.brand||"card"} \u2022\u2022\u2022\u2022 ${l.last4}`,source:{kind:"server"}});let d=_e("VISA_SUPPRESS_BROWSER","ui.suppressBrowser","opt-in");r.push({key:"ui.suppressBrowser",value:d.value,formatted:H(d.value),source:d.source,hint:"Persist with `visa-cli config set ui.suppressBrowser true` to stop auto-opening result URLs."});let f=_e("VISA_SUPPRESS_FEED","ui.suppressFeed","opt-in");r.push({key:"ui.suppressFeed",value:f.value,formatted:H(f.value),source:f.source});let y=W(),w;process.env.VISA_CLI_NO_UPDATE_CHECK?w={kind:"env",var:"VISA_CLI_NO_UPDATE_CHECK"}:process.env.CI?w={kind:"env",var:"CI"}:process.env.NODE_ENV==="test"?w={kind:"env",var:"NODE_ENV"}:w={kind:"default"},r.push({key:"ui.updateCheck",value:!y,formatted:H(!y),source:w});let u=_e("VISA_META_TOOLS","tools.meta","opt-out");r.push({key:"tools.meta",value:u.value,formatted:H(u.value),source:u.source,hint:"Persist with `visa-cli config set tools.meta false`. Restart Claude Code for changes to take effect."});let S=_e("VISA_SPECIFIC_TOOLS","tools.specific","opt-out");r.push({key:"tools.specific",value:S.value,formatted:H(S.value),source:S.source});let _=_e("VISA_DISCOVER_TOOLS","tools.discover","opt-out");if(r.push({key:"tools.discover",value:_.value,formatted:H(_.value),source:_.source}),r.push({key:"client.version",value:or,formatted:or,source:{kind:"default"}}),e.includeDev){let C=process.env.VISA_MOCK_KEYCHAIN;r.push({key:"dev.mockKeychain",value:C==="true",formatted:H(C==="true"),source:Mt("VISA_MOCK_KEYCHAIN",!!C)});let E=process.env.VISA_MOCK_TOUCHID;r.push({key:"dev.mockTouchid",value:E==="true",formatted:H(E==="true"),source:Mt("VISA_MOCK_TOUCHID",!!E)});let V=process.env.VISA_CLI_DEBUG;r.push({key:"dev.debug",value:!!V,formatted:H(!!V),source:Mt("VISA_CLI_DEBUG",!!V)})}return{entries:r,statusError:n}}function oo(e){switch(e.kind){case"default":return"default";case"env":return`env ${e.var}`;case"settings":return"settings.json";case"server":return"server";case"device":return"device";case"unset":return"unset";case"unknown":return`unknown (${e.reason})`}}function ar(e,t={}){if(e.length===0)return"";let n=Math.max(...e.map(o=>o.key.length)),r=Math.max(...e.map(o=>o.formatted.length)),s=[];for(let o of e){let i=o.key.padEnd(n+2),a=o.formatted.padEnd(r+2);s.push(`${i}${a}(${oo(o.source)})`),t.verbose&&o.hint&&s.push(` ${"\u21B3".padStart(n)} ${o.hint}`)}return s.join(`
99
- `)}function cr(e){return JSON.stringify({config:e.entries.map(t=>({key:t.key,value:t.value,source:t.source,hint:t.hint})),statusError:e.statusError},null,2)}var j=class extends Error{constructor(t){super(t),this.name="PayValidationError"}},lr=["GET","POST"];function ur(e){let t;try{t=new URL(e)}catch{throw new j(`Invalid URL: ${e}. Expected a fully-qualified http(s) URL.`)}if(t.protocol!=="http:"&&t.protocol!=="https:")throw new j(`Unsupported URL scheme "${t.protocol}". Only http and https are allowed.`);return t}function dr(e){let t=(e??"GET").toUpperCase();if(!lr.includes(t))throw new j(`Unsupported HTTP method "${e}". Supported: ${lr.join(", ")}.`);return t}function fr(e){if(e!==void 0){try{JSON.parse(e)}catch(t){throw new j(`--body is not valid JSON: ${t?.message??"parse error"}`)}return e}}function pr(e){if(!e||typeof e!="object")throw new j("Merchant returned no payment preview.");let t=e;if(typeof t.amount!="number"||!Number.isFinite(t.amount)||t.amount<=0)throw new j("Could not determine payment amount from merchant.");if(typeof t.merchantName!="string"||t.merchantName.trim().length===0)throw new j("Merchant returned an empty merchant name.");if(t.merchantName.length>200)throw new j(`Merchant name too long (${t.merchantName.length} chars).`);if(typeof t.currency!="string"||t.currency.trim().length===0)throw new j("Merchant returned an empty currency.");if(t.currency.length>10)throw new j(`Currency code too long (${t.currency.length} chars).`);return{amount:t.amount,currency:t.currency,merchantName:t.merchantName}}var v=h(require("fs")),m=h(require("path")),gr=h(require("os")),k=gr.homedir(),io=["Claude_","Anthropic.ClaudeDesktop_"],pe=class extends Error{constructor(n,r,s){super(co(n,r,s));this.client=n;this.configPath=r;this.name="McpConfigAccessError"}client;configPath};function mr(e){let t=e;return[t?.message,t?.stderr].filter(n=>typeof n=="string").join(`
100
- `)}function ao(e){let t=e;if(t?.code==="EPERM"||t?.code==="EACCES")return!0;let n=mr(e).toLowerCase();return n.includes("operation not permitted")||n.includes("permission denied")}function co(e,t,n){let r=t.replace(k,"~"),s=mr(n).split(`
101
- `).find(Boolean),o=s?` (${s})`:"";return e.id==="codex"?`Could not update Codex MCP config at ${r}: filesystem access was denied${o}. In Codex, rerun with elevated filesystem access or run \`visa-cli install codex\` outside the sandbox.`:`Could not update ${e.displayName} MCP config at ${r}: filesystem access was denied${o}.`}function hr(){return process.env.APPDATA||m.join(k,"AppData","Roaming")}function lo(){return process.env.LOCALAPPDATA||m.join(k,"AppData","Local")}function yr(){if(process.platform!=="win32")return;let e=m.join(lo(),"Packages");if(v.existsSync(e))try{let t=v.readdirSync(e,"utf-8");for(let n of io){let r=t.filter(s=>s.startsWith(n)).sort()[0];if(r)return m.join(e,r,"LocalCache","Roaming","Claude")}}catch{return}}function Sr(){if(process.platform==="win32"){let e=yr();return e?m.join(e,"claude_desktop_config.json"):m.join(hr(),"Claude","claude_desktop_config.json")}return m.join(k,"Library","Application Support","Claude","claude_desktop_config.json")}function vr(){if(process.platform!=="win32")return[m.join(k,"Library","Application Support","Claude")];let e=[m.join(hr(),"Claude")],t=yr();return t&&e.push(t),e}function Qe(e){return e.id==="claude-desktop"?Sr():e.globalConfigPath}function uo(e){return e.id==="claude-desktop"?vr():e.detectPaths}var q=[{id:"claude",displayName:"Claude Code",globalConfigPath:m.join(k,".claude.json"),configKey:"mcpServers",detectPaths:[m.join(k,".claude.json")],postInstallHint:"Restart Claude Code or run /mcp to connect."},{id:"claude-desktop",displayName:"Claude Desktop",globalConfigPath:Sr(),configKey:"mcpServers",detectPaths:vr(),postInstallHint:"Restart the Claude desktop app to connect."},{id:"cursor",displayName:"Cursor",globalConfigPath:m.join(k,".cursor","mcp.json"),configKey:"mcpServers",detectPaths:[m.join(k,".cursor")],postInstallHint:"Restart Cursor to connect."},{id:"windsurf",displayName:"Windsurf",globalConfigPath:m.join(k,".codeium","windsurf","mcp_config.json"),configKey:"mcpServers",detectPaths:[m.join(k,".codeium","windsurf")],postInstallHint:"Restart Windsurf to connect."},{id:"cline",displayName:"Cline",globalConfigPath:m.join(k,".vscode","mcp.json"),configKey:"mcpServers",detectPaths:[m.join(k,".vscode","extensions","saoudrizwan.claude-dev-*")],postInstallHint:"Restart VS Code to connect."},{id:"roo-code",displayName:"Roo Code",globalConfigPath:m.join(k,".config","Roo","mcp_settings.json"),configKey:"mcpServers",detectPaths:[m.join(k,".vscode","extensions","RooVeterinaryInc.roo-cline-*")],postInstallHint:"Restart VS Code to connect."},{id:"copilot",displayName:"VS Code Copilot",globalConfigPath:m.join(k,".vscode","mcp.json"),configKey:"servers",detectPaths:[m.join(k,".vscode")],postInstallHint:"Restart VS Code to connect."},{id:"zed",displayName:"Zed",globalConfigPath:m.join(k,".config","zed","settings.json"),configKey:"context_servers",detectPaths:[m.join(k,".config","zed")],postInstallHint:"Restart Zed to connect.",buildEntry:e=>({source:"custom",...e})},{id:"codex",displayName:"Codex",globalConfigPath:m.join(k,".codex","config.toml"),configKey:"mcp_servers",configFormat:"toml",detectPaths:[m.join(k,".codex")],postInstallHint:"Restart Codex to connect. For the terminal HUD, run: visa-cli hud enable codex"}];function Ht(e){return q.find(t=>t.id===e)}function Ce(e){return uo(e).some(t=>{if(t.includes("*")){let n=m.dirname(t),r=m.basename(t).replaceAll("*","");if(!v.existsSync(n))return!1;try{return v.readdirSync(n).some(s=>s.startsWith(r))}catch{return!1}}return v.existsSync(t)})}function br(){return{command:"node",args:[m.resolve(__dirname,"mcp-server/index.js")]}}function Vt(e,t){return t==="project"?"json":e.configFormat??"json"}function fo(e){if(e=e.trim(),e==="true")return!0;if(e==="false")return!1;if(e.startsWith('"')&&e.endsWith('"'))return e.slice(1,-1);if(e.startsWith("[")&&e.endsWith("]")){let n=e.slice(1,-1).trim();return n.length===0?[]:n.split(",").map(r=>r.trim()).filter(Boolean).map(r=>r.startsWith('"')&&r.endsWith('"')?r.slice(1,-1):r)}let t=Number(e);return isNaN(t)?e:t}function Ft(e,t){let n=`[mcp_servers.${t}]`,r=e.findIndex(o=>o.trim()===n);if(r===-1)return;let s=r+1;for(;s<e.length&&!e[s].trim().startsWith("[");)s++;return{start:r,end:s}}function Bt(e,t){let n=e.split(`
102
- `),r=Ft(n,t);if(!r)return;let s={};for(let o=r.start+1;o<r.end;o++){let i=n[o].trim().match(/^(\w+)\s*=\s*(.+)$/);i&&(s[i[1]]=fo(i[2]))}return Object.keys(s).length>0?s:void 0}function po(e,t,n){let r=`[${n.args.map(c=>`"${c}"`).join(", ")}]`,s=[`[mcp_servers.${t}]`,`command = "${n.command}"`,`args = ${r}`],o=e.split(`
103
- `),i=Ft(o,t);if(i){o.splice(i.start,i.end-i.start,...s);let c=o.join(`
95
+ `}function Ot(e=Ze()){if(!e)return{installed:!1,changed:!1,shell:null,message:"Shell HUD auto-install skipped: supported shells are zsh, bash, and PowerShell."};let t;try{t=Qe(e);let n=b.existsSync(t)?b.readFileSync(t,"utf-8"):"",r=Ys(n,e),s=r!==n;return s&&ze(t,r),{installed:!0,changed:s,shell:e,rcPath:t,message:s?`Persistent shell HUD installed in ${t}. Open a new terminal to start seeing it. Disable it any time with: visa-cli shell-hud disable`:`Persistent shell HUD already installed in ${t}. Disable it any time with: visa-cli shell-hud disable`}}catch(n){return{installed:!1,changed:!1,shell:e,rcPath:t,message:`Failed to install persistent shell HUD in ${t}: ${ar(n)}`}}}function Dt(e=Ze()){if(!e)return{removed:!1,shell:null,message:"Shell HUD uninstall skipped: supported shells are zsh, bash, and PowerShell."};let t;try{if(t=Qe(e),!b.existsSync(t))return{removed:!1,shell:e,rcPath:t,message:`No ${e} rc file found at ${t}.`};let n=b.readFileSync(t,"utf-8"),r=nr(n);return r===n.trimEnd()?{removed:!1,shell:e,rcPath:t,message:`Persistent shell HUD was not installed in ${t}.`}:(ze(t,r.length>0?`${r}
96
+ `:""),{removed:!0,shell:e,rcPath:t,message:`Removed persistent shell HUD from ${t}.`})}catch(n){return{removed:!1,shell:e,rcPath:t,message:`Failed to remove persistent shell HUD from ${t}: ${ar(n)}`}}}function Ut(e,t){let n=t??Js,r=n.currentVersion==="0.0.0"&&e.version?e.version:n.currentVersion,s=we(r),o=` ${U("\u2502",L.dim)} `,i=rr(n),a=Xs(s,i),c=Zs(n,i);if(!e.enrolled)return[a,U("setup needed",L.visaGold),c].filter(Boolean).join(o);let l=Rt(e.spendingControls?.daily_limit??e.spendingControls?.dailyLimit),u=Math.max(0,Rt(e.dailySpent)),f=l>0?Math.min(l,Math.max(0,Rt(e.dailyRemaining??l-u))):0,y=l>0?Math.max(0,Math.min(1,u/l)):0,w=no(e),d=l>0?`${to(y)} ${U(`${It(f)} left today`,L.green)} ${U(`(${It(u)}/${It(l)}/day)`,L.dim)}`:U("no spend limit",L.dim);return[a,U(w,L.visaGold),d,c].filter(Boolean).join(o)}function Xs(e,t){let n=`${U("VISA CLI",L.visaBlue)} ${U(`v${e}`,L.visaBlueSoft)}`;return t?`${n} ${U("\u2B06 update",L.visaGold)} ${U(`v${t}`,L.visaGold)}`:n}function Zs(e,t){return t?null:Qs(e)}function rr(e){return e.latestVersion?we(e.latestVersion):""}function Qs(e){let t=rr(e);return t?U(`update ready v${t}`,L.visaGold):e.updateMessage?U("update ready",L.visaGold):null}function sr(){let e=or();return!!e&&Date.now()-e.renderedAt<=er}function jt(){let e=or();if(e&&Date.now()-e.renderedAt<=er||(eo(),e?.line))return e.line;try{let t=Xe();if(b.existsSync(t))return b.readFileSync(t,"utf-8").trimEnd()}catch{}return"VISA | loading spend HUD\u2026"}function Mt(e){try{let t=$.dirname(be());b.mkdirSync(t,{recursive:!0});let n=we(e),r={hudVersion:Ks,renderedAt:Date.now(),line:n};ze(be(),JSON.stringify(r)+`
97
+ `),ze(Xe(),n+`
98
+ `)}catch{}}function ve(){try{b.unlinkSync(tr())}catch{}}function or(){let e=be();if(!b.existsSync(e))return null;try{return JSON.parse(b.readFileSync(e,"utf-8"))}catch{return null}}function eo(){if(process.env.JEST_WORKER_ID)return;let e=tr();try{if(b.mkdirSync($.dirname(e),{recursive:!0}),!io(e))return;let t=process.argv[1]?$.resolve(process.argv[1]):"";if(!t){ve();return}let n=(0,Qn.spawn)(process.execPath,[t,"shell-hud","refresh"],{detached:!0,stdio:"ignore",env:{...process.env,VISA_CLI_SHELL_HUD_BACKGROUND:"1"}});n.once("error",ve),n.unref()}catch{ve()}}function Rt(e){let t=Number(typeof e=="string"?e:e??0);return Number.isFinite(t)?t:0}function we(e){return e.replace(/\u001B\][^\u0007]*(?:\u0007|\u001B\\)/g,"").replace(/\u001B\[[0-?]*[ -/]*[@-~]/g,"").replace(/\u001B[P_^][^\u001B]*(?:\u001B\\|\u0007)/g,"").replace(/[\u0000-\u0008\u000B-\u001F\u007F-\u009F]/g,"").replace(/\s+/g," ").trim()}function to(e){let n=Math.round(Math.max(0,Math.min(1,e))*10),r="\u2588".repeat(n),s="\u2591".repeat(10-n);return`${U(r||"",L.green)}${U(s||"",L.dim)}`}function It(e){return`$${e.toFixed(2)}`}function no(e){let t=e.cards?.find(a=>a.isDefault)??e.cards?.[0];if(!t)return"card none";let n=typeof t.brand=="string"?t.brand:"card",r=typeof t.last4=="string"?t.last4:"????",s=we(n.toUpperCase()),o=we(r);return`${t.isDefault?"default":"active"} ${s} ****${o}`}function ro(){let e=(process.env.COLORTERM??"").toLowerCase();if(e==="truecolor"||e==="24bit")return!0;let t=(process.env.TERM??"").toLowerCase();return t.includes("truecolor")||t.includes("24bit")}var Lt=ro(),L={reset:"\x1B[0m",visaBlue:Lt?"\x1B[38;2;20;52;203m":"\x1B[38;5;27m",visaBlueSoft:Lt?"\x1B[38;2;97;126;229m":"\x1B[38;5;111m",visaGold:Lt?"\x1B[38;2;247;182;0m":"\x1B[38;5;220m",green:"\x1B[38;5;48m",dim:"\x1B[2m"};function U(e,t){return e.length===0||process.env.NO_COLOR?e:`${t}${e}${L.reset}`}function Zn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ir(){let e=Ye.homedir();if(!e||!$.isAbsolute(e))throw new Error("unable to determine a valid home directory");return $.resolve(e)}function so(e){return e==="powershell"?"& visa-cli shell-hud refresh":"visa-cli shell-hud refresh"}function oo(e){return e==="powershell"?"Get-Command visa-cli -ErrorAction SilentlyContinue -CommandType Application":"command -v visa-cli >/dev/null 2>&1"}function io(e){for(let t=0;t<2;t+=1){let n;try{return n=b.openSync(e,"wx"),b.writeFileSync(n,String(Date.now())),!0}catch(r){if(r?.code!=="EEXIST")return!1;try{let s=b.statSync(e);if(Date.now()-s.mtimeMs<=Ws)return!1;b.unlinkSync(e)}catch{}}finally{n!==void 0&&b.closeSync(n)}}return!1}function ar(e){return e instanceof Error?e.message:"unknown file system error"}function ze(e,t){b.mkdirSync($.dirname(e),{recursive:!0});let n=`${e}.${process.pid}.${Date.now()}.tmp`;b.writeFileSync(n,t),b.renameSync(n,e)}async function Ht(e,t){try{return await t()}catch(n){if(n.message==="Invalid signature"&&D()){ue.warn("attestation:key-mismatch",{action:"reregistering"});try{let r=await Ge();await e.registerAttestationKey(r),ue.info("attestation:key-reregistered")}catch(r){throw ue.error("attestation:reregister-failure",{error:r.message}),n}return await t()}throw n}}var cr="1.11.0-rc.2";function Vt(e,t){return t?{kind:"env",var:e}:{kind:"default"}}function ao(e,t,n){let r=process.env[e];if(r!==void 0&&r!=="")return{value:r,source:{kind:"env",var:e}};let s=wt(t);return s!==void 0?{value:s,source:{kind:"settings"}}:{value:n,source:{kind:"default"}}}function _e(e,t,n){let r=process.env[e];if(r!==void 0)return{value:n==="opt-in"?r==="true":r!=="false",source:{kind:"env",var:e}};let s=Ln(t);return s!==void 0?{value:s,source:{kind:"settings"}}:{value:n!=="opt-in",source:{kind:"default"}}}function H(e){return e==null?"\u2014":e?"yes":"no"}function et(e){return e==null?"\u2014":`$${e.toFixed(2)}`}async function lr(e){let t=null,n=null;try{t=await e.api.getStatus()}catch(C){n=C?.message||"unknown error"}let r=[],s=ao("VISA_AUTH_URL","auth.serverUrl","https://auth.visacli.sh");r.push({key:"auth.serverUrl",value:s.value,formatted:s.value,source:s.source,hint:s.source.kind==="default"?"Persist with `visa-cli config set auth.serverUrl <url>` (or set VISA_AUTH_URL for one-off overrides).":void 0}),r.push({key:"account.enrolled",value:t?.enrolled??null,formatted:H(t?.enrolled),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}}),t?.githubUser&&r.push({key:"account.githubUser",value:t.githubUser,formatted:t.githubUser,source:{kind:"server"}});let o=t?t.attestationRequired!==!1:void 0;r.push({key:"biometric.required",value:o,formatted:H(o),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"},hint:o===!1?"Touch ID prompts are suppressed. Re-enable with `visa-cli biometric on`.":void 0}),r.push({key:"biometric.keyRegistered",value:t?.hasAttestationKey??null,formatted:H(t?.hasAttestationKey),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}}),r.push({key:"biometric.deviceAvailable",value:D(),formatted:H(D()),source:{kind:"device"}});let i=t?.spendingControls,a=i?i.max_transaction_amount??i.maxTransactionAmount??null:null,c=i?i.daily_limit??i.dailyLimit??null:null;r.push({key:"spending.maxPerTxn",value:a,formatted:et(a),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}}),r.push({key:"spending.dailyLimit",value:c,formatted:et(c),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}}),r.push({key:"spending.dailySpent",value:t?.dailySpent??null,formatted:et(t?.dailySpent),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}}),r.push({key:"spending.dailyRemaining",value:t?.dailyRemaining??null,formatted:et(t?.dailyRemaining),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}}),r.push({key:"cards.count",value:t?.cardCount??null,formatted:t?.cardCount!=null?String(t.cardCount):"\u2014",source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}});let l=t?.cards?.find(C=>C.isDefault)??t?.cards?.[0];l&&r.push({key:"cards.default",value:{brand:l.brand??null,last4:l.last4},formatted:`${l.brand||"card"} \u2022\u2022\u2022\u2022 ${l.last4}`,source:{kind:"server"}});let u=_e("VISA_SUPPRESS_BROWSER","ui.suppressBrowser","opt-in");r.push({key:"ui.suppressBrowser",value:u.value,formatted:H(u.value),source:u.source,hint:"Persist with `visa-cli config set ui.suppressBrowser true` to stop auto-opening result URLs."});let f=_e("VISA_SUPPRESS_FEED","ui.suppressFeed","opt-in");r.push({key:"ui.suppressFeed",value:f.value,formatted:H(f.value),source:f.source});let y=J(),w;process.env.VISA_CLI_NO_UPDATE_CHECK?w={kind:"env",var:"VISA_CLI_NO_UPDATE_CHECK"}:process.env.CI?w={kind:"env",var:"CI"}:process.env.NODE_ENV==="test"?w={kind:"env",var:"NODE_ENV"}:w={kind:"default"},r.push({key:"ui.updateCheck",value:!y,formatted:H(!y),source:w});let d=_e("VISA_META_TOOLS","tools.meta","opt-out");r.push({key:"tools.meta",value:d.value,formatted:H(d.value),source:d.source,hint:"Persist with `visa-cli config set tools.meta false`. Restart Claude Code for changes to take effect."});let S=_e("VISA_SPECIFIC_TOOLS","tools.specific","opt-out");r.push({key:"tools.specific",value:S.value,formatted:H(S.value),source:S.source});let _=_e("VISA_DISCOVER_TOOLS","tools.discover","opt-out");if(r.push({key:"tools.discover",value:_.value,formatted:H(_.value),source:_.source}),r.push({key:"client.version",value:cr,formatted:cr,source:{kind:"default"}}),e.includeDev){let C=process.env.VISA_MOCK_KEYCHAIN;r.push({key:"dev.mockKeychain",value:C==="true",formatted:H(C==="true"),source:Vt("VISA_MOCK_KEYCHAIN",!!C)});let E=process.env.VISA_MOCK_TOUCHID;r.push({key:"dev.mockTouchid",value:E==="true",formatted:H(E==="true"),source:Vt("VISA_MOCK_TOUCHID",!!E)});let V=process.env.VISA_CLI_DEBUG;r.push({key:"dev.debug",value:!!V,formatted:H(!!V),source:Vt("VISA_CLI_DEBUG",!!V)})}return{entries:r,statusError:n}}function co(e){switch(e.kind){case"default":return"default";case"env":return`env ${e.var}`;case"settings":return"settings.json";case"server":return"server";case"device":return"device";case"unset":return"unset";case"unknown":return`unknown (${e.reason})`}}function ur(e,t={}){if(e.length===0)return"";let n=Math.max(...e.map(o=>o.key.length)),r=Math.max(...e.map(o=>o.formatted.length)),s=[];for(let o of e){let i=o.key.padEnd(n+2),a=o.formatted.padEnd(r+2);s.push(`${i}${a}(${co(o.source)})`),t.verbose&&o.hint&&s.push(` ${"\u21B3".padStart(n)} ${o.hint}`)}return s.join(`
99
+ `)}function dr(e){return JSON.stringify({config:e.entries.map(t=>({key:t.key,value:t.value,source:t.source,hint:t.hint})),statusError:e.statusError},null,2)}var j=class extends Error{constructor(t){super(t),this.name="PayValidationError"}},fr=["GET","POST"];function pr(e){let t;try{t=new URL(e)}catch{throw new j(`Invalid URL: ${e}. Expected a fully-qualified http(s) URL.`)}if(t.protocol!=="http:"&&t.protocol!=="https:")throw new j(`Unsupported URL scheme "${t.protocol}". Only http and https are allowed.`);return t}function gr(e){let t=(e??"GET").toUpperCase();if(!fr.includes(t))throw new j(`Unsupported HTTP method "${e}". Supported: ${fr.join(", ")}.`);return t}function mr(e){if(e!==void 0){try{JSON.parse(e)}catch(t){throw new j(`--body is not valid JSON: ${t?.message??"parse error"}`)}return e}}function hr(e){if(!e||typeof e!="object")throw new j("Merchant returned no payment preview.");let t=e;if(typeof t.amount!="number"||!Number.isFinite(t.amount)||t.amount<=0)throw new j("Could not determine payment amount from merchant.");if(typeof t.merchantName!="string"||t.merchantName.trim().length===0)throw new j("Merchant returned an empty merchant name.");if(t.merchantName.length>200)throw new j(`Merchant name too long (${t.merchantName.length} chars).`);if(typeof t.currency!="string"||t.currency.trim().length===0)throw new j("Merchant returned an empty currency.");if(t.currency.length>10)throw new j(`Currency code too long (${t.currency.length} chars).`);return{amount:t.amount,currency:t.currency,merchantName:t.merchantName}}var v=h(require("fs")),g=h(require("path")),yr=h(require("os")),k=yr.homedir(),lo=["Claude_","Anthropic.ClaudeDesktop_"],pe=class extends Error{constructor(n,r,s){super(fo(n,r,s));this.client=n;this.configPath=r;this.name="McpConfigAccessError"}client;configPath};function Sr(e){let t=e;return[t?.message,t?.stderr].filter(n=>typeof n=="string").join(`
100
+ `)}function uo(e){let t=e;if(t?.code==="EPERM"||t?.code==="EACCES")return!0;let n=Sr(e).toLowerCase();return n.includes("operation not permitted")||n.includes("permission denied")}function fo(e,t,n){let r=t.replace(k,"~"),s=Sr(n).split(`
101
+ `).find(Boolean),o=s?` (${s})`:"";return e.id==="codex"?`Could not update Codex MCP config at ${r}: filesystem access was denied${o}. In Codex, rerun with elevated filesystem access or run \`visa-cli install codex\` outside the sandbox.`:`Could not update ${e.displayName} MCP config at ${r}: filesystem access was denied${o}.`}function Ce(){return process.env.APPDATA||g.join(k,"AppData","Roaming")}function po(){return process.env.LOCALAPPDATA||g.join(k,"AppData","Local")}function Ft(e){return process.platform==="win32"?e.win32:e.posix}function vr(){if(process.platform!=="win32")return;let e=g.join(po(),"Packages");if(v.existsSync(e))try{let t=v.readdirSync(e,"utf-8");for(let n of lo){let r=t.filter(s=>s.startsWith(n)).sort()[0];if(r)return g.join(e,r,"LocalCache","Roaming","Claude")}}catch{return}}function br(){if(process.platform==="win32"){let e=vr();return e?g.join(e,"claude_desktop_config.json"):g.join(Ce(),"Claude","claude_desktop_config.json")}return g.join(k,"Library","Application Support","Claude","claude_desktop_config.json")}function wr(){if(process.platform!=="win32")return[g.join(k,"Library","Application Support","Claude")];let e=[g.join(Ce(),"Claude")],t=vr();return t&&e.push(t),e}function tt(e){return e.id==="claude-desktop"?br():e.globalConfigPath}function go(e){return e.id==="claude-desktop"?wr():e.detectPaths}var q=[{id:"claude",displayName:"Claude Code",globalConfigPath:g.join(k,".claude.json"),configKey:"mcpServers",detectPaths:[g.join(k,".claude.json")],postInstallHint:"Restart Claude Code or run /mcp to connect."},{id:"claude-desktop",displayName:"Claude Desktop",globalConfigPath:br(),configKey:"mcpServers",detectPaths:wr(),postInstallHint:"Restart the Claude desktop app to connect."},{id:"cursor",displayName:"Cursor",globalConfigPath:g.join(k,".cursor","mcp.json"),configKey:"mcpServers",detectPaths:[g.join(k,".cursor")],postInstallHint:"Restart Cursor to connect."},{id:"windsurf",displayName:"Windsurf",globalConfigPath:g.join(k,".codeium","windsurf","mcp_config.json"),configKey:"mcpServers",detectPaths:[g.join(k,".codeium","windsurf")],postInstallHint:"Restart Windsurf to connect."},{id:"cline",displayName:"Cline",globalConfigPath:g.join(k,".vscode","mcp.json"),configKey:"mcpServers",detectPaths:[g.join(k,".vscode","extensions","saoudrizwan.claude-dev-*")],postInstallHint:"Restart VS Code to connect."},{id:"roo-code",displayName:"Roo Code",globalConfigPath:Ft({win32:g.join(Ce(),"Roo","mcp_settings.json"),posix:g.join(k,".config","Roo","mcp_settings.json")}),configKey:"mcpServers",detectPaths:[g.join(k,".vscode","extensions","RooVeterinaryInc.roo-cline-*")],postInstallHint:"Restart VS Code to connect."},{id:"copilot",displayName:"VS Code Copilot",globalConfigPath:g.join(k,".vscode","mcp.json"),configKey:"servers",detectPaths:[g.join(k,".vscode")],postInstallHint:"Restart VS Code to connect."},{id:"zed",displayName:"Zed",globalConfigPath:Ft({win32:g.join(Ce(),"Zed","settings.json"),posix:g.join(k,".config","zed","settings.json")}),configKey:"context_servers",detectPaths:Ft({win32:[g.join(Ce(),"Zed")],posix:[g.join(k,".config","zed")]}),postInstallHint:"Restart Zed to connect.",buildEntry:e=>({source:"custom",...e})},{id:"codex",displayName:"Codex",globalConfigPath:g.join(k,".codex","config.toml"),configKey:"mcp_servers",configFormat:"toml",detectPaths:[g.join(k,".codex")],postInstallHint:"Restart Codex to connect. For the terminal HUD, run: visa-cli hud enable codex"}];function Bt(e){return q.find(t=>t.id===e)}function ke(e){return go(e).some(t=>{if(t.includes("*")){let n=g.dirname(t),r=g.basename(t).replaceAll("*","");if(!v.existsSync(n))return!1;try{return v.readdirSync(n).some(s=>s.startsWith(r))}catch{return!1}}return v.existsSync(t)})}function _r(){return{command:"node",args:[g.resolve(__dirname,"mcp-server/index.js")]}}function Kt(e,t){return t==="project"?"json":e.configFormat??"json"}function mo(e){if(e=e.trim(),e==="true")return!0;if(e==="false")return!1;if(e.startsWith('"')&&e.endsWith('"'))return e.slice(1,-1);if(e.startsWith("[")&&e.endsWith("]")){let n=e.slice(1,-1).trim();return n.length===0?[]:n.split(",").map(r=>r.trim()).filter(Boolean).map(r=>r.startsWith('"')&&r.endsWith('"')?r.slice(1,-1):r)}let t=Number(e);return isNaN(t)?e:t}function qt(e,t){let n=`[mcp_servers.${t}]`,r=e.findIndex(o=>o.trim()===n);if(r===-1)return;let s=r+1;for(;s<e.length&&!e[s].trim().startsWith("[");)s++;return{start:r,end:s}}function Gt(e,t){let n=e.split(`
102
+ `),r=qt(n,t);if(!r)return;let s={};for(let o=r.start+1;o<r.end;o++){let i=n[o].trim().match(/^(\w+)\s*=\s*(.+)$/);i&&(s[i[1]]=mo(i[2]))}return Object.keys(s).length>0?s:void 0}function ho(e,t,n){let r=`[${n.args.map(c=>`"${c}"`).join(", ")}]`,s=[`[mcp_servers.${t}]`,`command = "${n.command}"`,`args = ${r}`],o=e.split(`
103
+ `),i=qt(o,t);if(i){o.splice(i.start,i.end-i.start,...s);let c=o.join(`
104
104
  `);return c.endsWith(`
105
105
  `)?c:c+`
106
106
  `}let a=e.trimEnd();return a+(a.length>0?`
107
107
 
108
108
  `:"")+s.join(`
109
109
  `)+`
110
- `}function go(e,t){let n=e.split(`
111
- `),r=Ft(n,t);return r?(n.splice(r.start,r.end-r.start),n.join(`
110
+ `}function yo(e,t){let n=e.split(`
111
+ `),r=qt(n,t);return r?(n.splice(r.start,r.end-r.start),n.join(`
112
112
  `).replace(/\n{3,}/g,`
113
113
 
114
- `)):e}function ke(e,t="global"){let n=t==="project"?m.join(process.cwd(),".mcp.json"):Qe(e);try{let r=m.dirname(n);v.existsSync(r)||v.mkdirSync(r,{recursive:!0});let s=Vt(e,t),o=br();if(s==="toml"){let i=v.existsSync(n)?v.readFileSync(n,"utf-8"):"",a=po(i,"visa-cli",o);v.writeFileSync(n,a)}else{let i={};if(v.existsSync(n))try{i=JSON.parse(v.readFileSync(n,"utf-8"))}catch{i={}}i[e.configKey]=i[e.configKey]||{},i[e.configKey]["visa-cli"]=e.buildEntry?e.buildEntry(o):o,v.writeFileSync(n,JSON.stringify(i,null,2)+`
115
- `)}}catch(r){throw ao(r)?new pe(e,n,r):r}return{installed:!0,configPath:n,message:e.postInstallHint}}function Kt(e,t="global"){let n=t==="project"?m.join(process.cwd(),".mcp.json"):Qe(e);if(!v.existsSync(n))return{removed:!1,configPath:n};if(Vt(e,t)==="toml"){let i=v.readFileSync(n,"utf-8");return Bt(i,"visa-cli")?(v.writeFileSync(n,go(i,"visa-cli")),{removed:!0,configPath:n}):{removed:!1,configPath:n}}let s;try{s=JSON.parse(v.readFileSync(n,"utf-8"))}catch{return{removed:!1,configPath:n}}let o=s[e.configKey];return!o||!o["visa-cli"]?{removed:!1,configPath:n}:(delete o["visa-cli"],v.writeFileSync(n,JSON.stringify(s,null,2)+`
116
- `),{removed:!0,configPath:n})}function wr(e,t="global"){let n=t==="project"?m.join(process.cwd(),".mcp.json"):Qe(e);if(!v.existsSync(n))return!1;if(Vt(e,t)==="toml")try{let s=v.readFileSync(n,"utf-8");return!!Bt(s,"visa-cli")}catch{return!1}try{return!!JSON.parse(v.readFileSync(n,"utf-8"))?.[e.configKey]?.["visa-cli"]}catch{return!1}}function mo(e){if(!e||typeof e!="object")return;let t=e;if(t.command!=="node"||!Array.isArray(t.args)||t.args.length===0)return;let n=t.args[t.args.length-1];if(!(typeof n!="string"||n.length===0))return n}function ho(e,t){if(e===t)return!0;let n=m.resolve(e),r=m.resolve(t);if(n===r)return!0;try{let s=v.realpathSync(n),o=v.realpathSync(r);return s===o}catch{return!1}}function $e(){let e=br(),t=e.args[e.args.length-1],n=[];for(let r of q){let s=Qe(r);if(!v.existsSync(s))continue;let o=r.configFormat??"json",i;if(o==="toml")try{let l=v.readFileSync(s,"utf-8");i=Bt(l,"visa-cli")}catch{continue}else{let l;try{l=JSON.parse(v.readFileSync(s,"utf-8"))}catch{continue}i=l?.[r.configKey]?.["visa-cli"]}if(!i)continue;let a=mo(i);if(!a||ho(a,t))continue;let c=v.existsSync(a)?"mismatch":"missing";n.push({client:r,configPath:s,currentPath:a,expectedPath:t,staleReason:c})}return n}function qt(e){return{configPath:ke(e.client,"global").configPath}}var _r=(0,Er.promisify)(xr.execFile);function yo(e){let t=R.homedir(),n=s=>s.replace(t,"~"),r=e.staleReason==="missing"?"path missing on disk":"path mismatch";return` \u2022 ${e.client.displayName} (${n(e.configPath)})
117
- ${r}: ${n(e.currentPath)}`}function Pr(e,t){if(e.length===0){console.log(`${t} \u2713 All MCP client configs are up to date.`);return}console.log(`${t} Found ${e.length} stale MCP config ${e.length===1?"entry":"entries"}:`);for(let n of e)console.log(yo(n))}function Cr(e){console.log(` ! ${e.client.displayName} skipped: ${e.message}`)}var T=new kr.Command,et=null,xe=!1;function M(){return et=new le(()=>$.getSessionToken()),et}function Tr(e){return`$${(e/100).toFixed(2)}`}function So(e){let t=`visa-cli-${R.hostname()||"local"}`,n=(e?.trim()||t).trim();if(!n)throw new Error("API key label is required.");if(n.length>128)throw new Error("API key label must be 128 characters or fewer.");return n}function vo(e){if(!e)return;let t=e.split(",").map(s=>s.trim()).filter(Boolean),n=Array.from(new Set(t)),r=n.find(s=>s.length>64);if(r)throw new Error(`Tool id is too long: ${r}`);return n}function bo(e){if(!e)return;let t=Number(e);if(!Number.isFinite(t)||t<=0)throw new Error("--daily-cap must be a positive USD amount.");let n=Math.round(t*100);if(n<100||n>1e4)throw new Error("--daily-cap must be between 1 and 100 USD.");return n}function Ar(e){return e&&e.length>0?e.join(", "):"all tools"}T.name("visa-cli").description("Visa CLI - AI payment orchestration").version(lt().version);T.hook("preAction",async()=>{await en()});T.command("setup").description("Register MCP server, authenticate, and generate attestation key").option("--check","Scan MCP client configs for stale visa-cli entries and exit without making changes").option("--yes","Accept setup prompts without asking \u2014 for CI/agent use").option("--hud","Also enable the Claude Code HUD during setup").option("--no-hud","Do not install the HUD during setup (default)").action(async e=>{try{if(e.check){let u=$e();Pr(u,"MCP config check:"),u.length>0&&(console.log("\nRun `visa-cli setup` (or `visa-cli install --repair`) to rewrite these entries."),process.exit(1));return}console.log("Step 1: Registering MCP server...");let t=$e(),n=new Map(t.map(u=>[u.client.id,u])),r=new Set,s=new Set,o=new Set;for(let u of q)if(Ce(u)){let S;try{S=ke(u)}catch(E){if(E instanceof pe){Cr(E),s.add(u.displayName),o.add(u.id);continue}throw E}let _=n.get(u.id),C=_?` \u2014 repaired stale ${_.staleReason} entry`:"";console.log(` \u2713 ${u.displayName} (${S.configPath.replace(R.homedir(),"~")})${C}`),_&&r.add(u.id)}let i=t.filter(u=>!r.has(u.client.id)&&!o.has(u.client.id)),a=0;for(let u of i){try{qt(u)}catch(S){if(S instanceof pe){Cr(S),s.add(u.client.displayName),o.add(u.client.id);continue}throw S}console.log(` \u2713 ${u.client.displayName} (${u.configPath.replace(R.homedir(),"~")}) \u2014 repaired stale ${u.staleReason} entry`),a++}let c=r.size+a;c===0&&s.size===0?console.log(" \u2713 MCP config verified \u2014 nothing to repair."):c>0&&console.log(` \u2713 Repaired ${c} stale MCP config ${c===1?"entry":"entries"}.`),s.size>0&&console.log(` ! Skipped MCP registration for: ${Array.from(s).join(", ")}. Rerun with access to those config files to complete registration.`),console.log(`
118
- Step 2: Checking authentication...`);let l=await $.getSessionToken();if(l)try{await new le(()=>Promise.resolve(l)).getStatus(),console.log(" Already authenticated.")}catch(u){let S=u instanceof Error?u.message:"";S.includes("session has expired")||S.includes("Not logged in")?(console.log(" Existing session expired \u2014 re-authenticating..."),await $.clearAll(),l=null):console.log(` Couldn't verify session (${S||"unknown error"}) \u2014 continuing with existing token.`)}if(!l){let u=null;try{let{stdout:S}=await _r("gh",["auth","token"],{timeout:5e3});u=S.trim()}catch{}if(u||(u=process.env.GITHUB_TOKEN||null),u)try{console.log(" Found GitHub token \u2014 attempting headless login...");let S=await globalThis.fetch("https://auth.visacli.sh/v1/auth/token-exchange",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({github_token:u}),signal:AbortSignal.timeout(1e4)});if(S.ok){let _=await S.json();if(_.success&&_.sessionToken){let C=_.sessionToken;l=C,await $.saveSessionToken(C),console.log(` Signed in as ${_.user} (headless).`)}}else(await S.json().catch(()=>({}))).hint==="card_required"&&console.log(" GitHub token valid but no card on file \u2014 opening browser for card enrollment...")}catch{}}if(l||(console.log(" No session found. Opening browser for GitHub login..."),l=await new Promise(async(u,S)=>{let _=tt.randomBytes(16).toString("hex"),C=`https://auth.visacli.sh/login?state=${_}`;await nn(C);let E=3e4,V=300*1e3,ie=Date.now()+V;for(;Date.now()<ie;)try{let I=await globalThis.fetch("https://auth.visacli.sh/v1/auth-status",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({state:_,timeout:E}),signal:AbortSignal.timeout(E+5e3)});if(!I.ok)continue;let F=await I.json();if(F.status==="pending")continue;if(F.status==="expired"){S(new Error("Session expired. Please run setup again."));return}if(F.status==="complete"&&F.sessionToken){console.log(` Signed in as ${F.user}.`),u(F.sessionToken);return}}catch{}S(new Error("Login timed out after 5 minutes. Please run setup again."))}),await $.saveSessionToken(l),console.log(" Session token saved.")),console.log(`
119
- Step 3: Setting up authentication...`),!D())console.log(" Not macOS \u2014 skipping biometric setup.");else{try{await _r("clang",["--version"])}catch{console.error(" Xcode Command Line Tools are required for payment authentication."),console.error(" Install them by running: xcode-select --install"),console.error(" Then re-run: visa-cli setup"),process.exit(1)}try{let u=await Ke();console.log(" Attestation key generated."),await M().registerAttestationKey(u),console.log(" Attestation key registered with server.")}catch(u){console.log(` Skipped: ${u.message}`)}}let d=se.join(R.homedir(),".claude","settings.json"),f=$r.existsSync(se.join(R.homedir(),".claude.json"));if(e.hud===!0)if(!f)console.log(`
114
+ `)):e}function xe(e,t="global"){let n=t==="project"?g.join(process.cwd(),".mcp.json"):tt(e);try{let r=g.dirname(n);v.existsSync(r)||v.mkdirSync(r,{recursive:!0});let s=Kt(e,t),o=_r();if(s==="toml"){let i=v.existsSync(n)?v.readFileSync(n,"utf-8"):"",a=ho(i,"visa-cli",o);v.writeFileSync(n,a)}else{let i={};if(v.existsSync(n))try{i=JSON.parse(v.readFileSync(n,"utf-8"))}catch{i={}}i[e.configKey]=i[e.configKey]||{},i[e.configKey]["visa-cli"]=e.buildEntry?e.buildEntry(o):o,v.writeFileSync(n,JSON.stringify(i,null,2)+`
115
+ `)}}catch(r){throw uo(r)?new pe(e,n,r):r}return{installed:!0,configPath:n,message:e.postInstallHint}}function Jt(e,t="global"){let n=t==="project"?g.join(process.cwd(),".mcp.json"):tt(e);if(!v.existsSync(n))return{removed:!1,configPath:n};if(Kt(e,t)==="toml"){let i=v.readFileSync(n,"utf-8");return Gt(i,"visa-cli")?(v.writeFileSync(n,yo(i,"visa-cli")),{removed:!0,configPath:n}):{removed:!1,configPath:n}}let s;try{s=JSON.parse(v.readFileSync(n,"utf-8"))}catch{return{removed:!1,configPath:n}}let o=s[e.configKey];return!o||!o["visa-cli"]?{removed:!1,configPath:n}:(delete o["visa-cli"],v.writeFileSync(n,JSON.stringify(s,null,2)+`
116
+ `),{removed:!0,configPath:n})}function Cr(e,t="global"){let n=t==="project"?g.join(process.cwd(),".mcp.json"):tt(e);if(!v.existsSync(n))return!1;if(Kt(e,t)==="toml")try{let s=v.readFileSync(n,"utf-8");return!!Gt(s,"visa-cli")}catch{return!1}try{return!!JSON.parse(v.readFileSync(n,"utf-8"))?.[e.configKey]?.["visa-cli"]}catch{return!1}}function So(e){if(!e||typeof e!="object")return;let t=e;if(t.command!=="node"||!Array.isArray(t.args)||t.args.length===0)return;let n=t.args[t.args.length-1];if(!(typeof n!="string"||n.length===0))return n}function vo(e,t){if(e===t)return!0;let n=g.resolve(e),r=g.resolve(t);if(n===r)return!0;try{let s=v.realpathSync(n),o=v.realpathSync(r);return s===o}catch{return!1}}function $e(){let e=_r(),t=e.args[e.args.length-1],n=[];for(let r of q){let s=tt(r);if(!v.existsSync(s))continue;let o=r.configFormat??"json",i;if(o==="toml")try{let l=v.readFileSync(s,"utf-8");i=Gt(l,"visa-cli")}catch{continue}else{let l;try{l=JSON.parse(v.readFileSync(s,"utf-8"))}catch{continue}i=l?.[r.configKey]?.["visa-cli"]}if(!i)continue;let a=So(i);if(!a||vo(a,t))continue;let c=v.existsSync(a)?"mismatch":"missing";n.push({client:r,configPath:s,currentPath:a,expectedPath:t,staleReason:c})}return n}function Wt(e){return{configPath:xe(e.client,"global").configPath}}var kr=(0,Tr.promisify)(Pr.execFile);function bo(e){let t=R.homedir(),n=s=>s.replace(t,"~"),r=e.staleReason==="missing"?"path missing on disk":"path mismatch";return` \u2022 ${e.client.displayName} (${n(e.configPath)})
117
+ ${r}: ${n(e.currentPath)}`}function Ar(e,t){if(e.length===0){console.log(`${t} \u2713 All MCP client configs are up to date.`);return}console.log(`${t} Found ${e.length} stale MCP config ${e.length===1?"entry":"entries"}:`);for(let n of e)console.log(bo(n))}function xr(e){console.log(` ! ${e.client.displayName} skipped: ${e.message}`)}var T=new $r.Command,nt=null,Ee=!1;function M(){return nt=new le(()=>x.getSessionToken()),nt}function Rr(e){return`$${(e/100).toFixed(2)}`}function wo(e){let t=`visa-cli-${R.hostname()||"local"}`,n=(e?.trim()||t).trim();if(!n)throw new Error("API key label is required.");if(n.length>128)throw new Error("API key label must be 128 characters or fewer.");return n}function _o(e){if(!e)return;let t=e.split(",").map(s=>s.trim()).filter(Boolean),n=Array.from(new Set(t)),r=n.find(s=>s.length>64);if(r)throw new Error(`Tool id is too long: ${r}`);return n}function Co(e){if(!e)return;let t=Number(e);if(!Number.isFinite(t)||t<=0)throw new Error("--daily-cap must be a positive USD amount.");let n=Math.round(t*100);if(n<100||n>1e4)throw new Error("--daily-cap must be between 1 and 100 USD.");return n}function Ir(e){return e&&e.length>0?e.join(", "):"all tools"}T.name("visa-cli").description("Visa CLI - AI payment orchestration").version(dt().version);T.hook("preAction",async()=>{await rn()});T.command("setup").description("Register MCP server, authenticate, and generate attestation key").option("--check","Scan MCP client configs for stale visa-cli entries and exit without making changes").option("--yes","Accept setup prompts without asking \u2014 for CI/agent use").option("--hud","Also enable the Claude Code HUD during setup").option("--no-hud","Do not install the HUD during setup (default)").action(async e=>{try{if(e.check){let d=$e();Ar(d,"MCP config check:"),d.length>0&&(console.log("\nRun `visa-cli setup` (or `visa-cli install --repair`) to rewrite these entries."),process.exit(1));return}console.log("Step 1: Registering MCP server...");let t=$e(),n=new Map(t.map(d=>[d.client.id,d])),r=new Set,s=new Set,o=new Set;for(let d of q)if(ke(d)){let S;try{S=xe(d)}catch(E){if(E instanceof pe){xr(E),s.add(d.displayName),o.add(d.id);continue}throw E}let _=n.get(d.id),C=_?` \u2014 repaired stale ${_.staleReason} entry`:"";console.log(` \u2713 ${d.displayName} (${S.configPath.replace(R.homedir(),"~")})${C}`),_&&r.add(d.id)}let i=t.filter(d=>!r.has(d.client.id)&&!o.has(d.client.id)),a=0;for(let d of i){try{Wt(d)}catch(S){if(S instanceof pe){xr(S),s.add(d.client.displayName),o.add(d.client.id);continue}throw S}console.log(` \u2713 ${d.client.displayName} (${d.configPath.replace(R.homedir(),"~")}) \u2014 repaired stale ${d.staleReason} entry`),a++}let c=r.size+a;c===0&&s.size===0?console.log(" \u2713 MCP config verified \u2014 nothing to repair."):c>0&&console.log(` \u2713 Repaired ${c} stale MCP config ${c===1?"entry":"entries"}.`),s.size>0&&console.log(` ! Skipped MCP registration for: ${Array.from(s).join(", ")}. Rerun with access to those config files to complete registration.`),console.log(`
118
+ Step 2: Checking authentication...`);let l=await x.getSessionToken();if(l)try{await new le(()=>Promise.resolve(l)).getStatus(),console.log(" Already authenticated.")}catch(d){let S=d instanceof Error?d.message:"";S.includes("session has expired")||S.includes("Not logged in")?(console.log(" Existing session expired \u2014 re-authenticating..."),await x.clearAll(),l=null):console.log(` Couldn't verify session (${S||"unknown error"}) \u2014 continuing with existing token.`)}if(!l){let d=null;try{let{stdout:S}=await kr("gh",["auth","token"],{timeout:5e3});d=S.trim()}catch{}if(d||(d=process.env.GITHUB_TOKEN||null),d)try{console.log(" Found GitHub token \u2014 attempting headless login...");let S=await globalThis.fetch("https://auth.visacli.sh/v1/auth/token-exchange",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({github_token:d}),signal:AbortSignal.timeout(1e4)});if(S.ok){let _=await S.json();if(_.success&&_.sessionToken){let C=_.sessionToken;l=C,await x.saveSessionToken(C),console.log(` Signed in as ${_.user} (headless).`)}}else(await S.json().catch(()=>({}))).hint==="card_required"&&console.log(" GitHub token valid but no card on file \u2014 opening browser for card enrollment...")}catch{}}if(l||(console.log(" No session found. Opening browser for GitHub login..."),l=await new Promise(async(d,S)=>{let _=rt.randomBytes(16).toString("hex"),C=`https://auth.visacli.sh/login?state=${_}`;await on(C);let E=3e4,V=300*1e3,ie=Date.now()+V;for(;Date.now()<ie;)try{let I=await globalThis.fetch("https://auth.visacli.sh/v1/auth-status",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({state:_,timeout:E}),signal:AbortSignal.timeout(E+5e3)});if(!I.ok)continue;let F=await I.json();if(F.status==="pending")continue;if(F.status==="expired"){S(new Error("Session expired. Please run setup again."));return}if(F.status==="complete"&&F.sessionToken){console.log(` Signed in as ${F.user}.`),d(F.sessionToken);return}}catch{}S(new Error("Login timed out after 5 minutes. Please run setup again."))}),await x.saveSessionToken(l),console.log(" Session token saved.")),console.log(`
119
+ Step 3: Setting up authentication...`),!D())console.log(" Not macOS \u2014 skipping biometric setup.");else{try{await kr("clang",["--version"])}catch{console.error(" Xcode Command Line Tools are required for payment authentication."),console.error(" Install them by running: xcode-select --install"),console.error(" Then re-run: visa-cli setup"),process.exit(1)}try{let d=await Ge();console.log(" Attestation key generated."),await M().registerAttestationKey(d),console.log(" Attestation key registered with server.")}catch(d){console.log(` Skipped: ${d.message}`)}}let u=se.join(R.homedir(),".claude","settings.json"),f=Er.existsSync(se.join(R.homedir(),".claude.json"));if(e.hud===!0)if(!f)console.log(`
120
120
  Step 4: HUD requested, but Claude Code config was not detected.`),console.log(" Skipped. Enable later with: visa-cli hud enable");else{console.log(`
121
- Step 4: Enabling the Visa spend HUD...`);let u=Ne(d),S=u.installed==="new"||u.installed==="already-visa"||u.installed==="other-hud-present"?" \u2713 ":" Skipped: ";console.log(`${S}${u.message}`);try{let _=M(),C=await _.getStatus(),E={currentVersion:_.getClientVersion(),latestVersion:_.lastSignals?.updateAvailable?.version,updateMessage:_.lastSignals?.updateAvailable?.message,updateCheckDisabled:W()},V=Nt(C,E);Ut(V),console.log(` Preview: ${V.split(`
121
+ Step 4: Enabling the Visa spend HUD...`);let d=De(u),S=d.installed==="new"||d.installed==="already-visa"||d.installed==="other-hud-present"?" \u2713 ":" Skipped: ";console.log(`${S}${d.message}`);try{let _=M(),C=await _.getStatus(),E={currentVersion:_.getClientVersion(),latestVersion:_.lastSignals?.updateAvailable?.version,updateMessage:_.lastSignals?.updateAvailable?.message,updateCheckDisabled:J()},V=Ut(C,E);Mt(V),console.log(` Preview: ${V.split(`
122
122
  `)[0]}`)}catch{}}let y="\x1B[1m",w="\x1B[0m";console.log(`
123
123
  \u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557
124
124
  \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557
@@ -137,24 +137,24 @@ Step 4: Enabling the Visa spend HUD...`);let u=Ne(d),S=u.installed==="new"||u.in
137
137
  ${y}Verify:${w} visa-cli status
138
138
  ${y}HUD:${w} visa-cli hud enable
139
139
  ${y}Docs:${w} https://visacli.sh
140
- `)}catch(t){console.error("Error:",t.message),process.exit(1)}});T.command("install [client]").description("Register MCP server with an AI client (claude, cursor, windsurf, cline, zed, ...)").option("--all","Install for all detected clients").option("--list","Show supported clients and install status").option("--check","Scan MCP client configs for stale visa-cli entries and exit without making changes").option("--repair","Repair stale MCP client configs without re-running the full setup flow").option("--scope <scope>","Install scope: global or project","global").action(async(e,t)=>{try{if(t.check){let o=$e();Pr(o,"MCP config check:"),o.length>0&&process.exit(1);return}if(t.repair){let o=$e();if(o.length===0){console.log("\u2713 MCP config verified \u2014 nothing to repair.");return}for(let i of o)qt(i),console.log(` \u2713 ${i.client.displayName} (${i.configPath.replace(R.homedir(),"~")}) \u2014 repaired stale ${i.staleReason} entry`);console.log(`
140
+ `)}catch(t){console.error("Error:",t.message),process.exit(1)}});T.command("install [client]").description("Register MCP server with an AI client (claude, cursor, windsurf, cline, zed, ...)").option("--all","Install for all detected clients").option("--list","Show supported clients and install status").option("--check","Scan MCP client configs for stale visa-cli entries and exit without making changes").option("--repair","Repair stale MCP client configs without re-running the full setup flow").option("--scope <scope>","Install scope: global or project","global").action(async(e,t)=>{try{if(t.check){let o=$e();Ar(o,"MCP config check:"),o.length>0&&process.exit(1);return}if(t.repair){let o=$e();if(o.length===0){console.log("\u2713 MCP config verified \u2014 nothing to repair.");return}for(let i of o)Wt(i),console.log(` \u2713 ${i.client.displayName} (${i.configPath.replace(R.homedir(),"~")}) \u2014 repaired stale ${i.staleReason} entry`);console.log(`
141
141
  Repaired ${o.length} stale MCP config ${o.length===1?"entry":"entries"}.`);return}if(t.list){console.log(`
142
142
  \x1B[1mSupported MCP Clients\x1B[0m
143
- `),console.log(` ${"Client".padEnd(18)} ${"Detected".padEnd(10)} ${"Installed".padEnd(11)} Config Path`),console.log(` ${"\u2500".repeat(18)} ${"\u2500".repeat(10)} ${"\u2500".repeat(11)} ${"\u2500".repeat(40)}`);for(let a of q){let c=Ce(a),l=wr(a),d=c?"Yes":"No",f=l?"Yes":"No",y=a.globalConfigPath.replace(R.homedir(),"~");console.log(` ${a.displayName.padEnd(18)} ${d.padEnd(10)} ${f.padEnd(11)} ${y}`)}console.log("");return}let n=t.scope==="project"?"project":"global";if(t.all){let o=[],i=[];for(let a of q){if(!Ce(a)){i.push(a.displayName);continue}ke(a,n),o.push(a.displayName)}o.length>0&&console.log(`Installed for: ${o.join(", ")}.`),i.length>0&&console.log(`Skipped: ${i.map(a=>`${a} (not detected)`).join(", ")}.`),o.length===0&&i.length===0&&console.log("No supported clients found.");return}e||(console.error("Usage: visa-cli install <client>"),console.error(" visa-cli install --all"),console.error(" visa-cli install --list"),console.error(`
144
- Supported clients: ${q.map(o=>o.id).join(", ")}`),process.exit(1));let r=Ht(e);r||(console.error(`Unknown client: ${e}`),console.error(`Supported clients: ${q.map(o=>o.id).join(", ")}`),process.exit(1)),n==="global"&&!Ce(r)&&(console.error(`${r.displayName} not detected on this machine.`),console.error(`Expected: ${r.detectPaths.join(", ")}`),process.exit(1));let s=ke(r,n);console.log(`Registered visa-cli MCP server in ${s.configPath}`),console.log(s.message)}catch(n){console.error("Error:",n.message),process.exit(1)}});T.command("uninstall [client]").description("Remove MCP server from an AI client").option("--all","Remove from all clients").option("--scope <scope>","Uninstall scope: global or project","global").action(async(e,t)=>{try{let n=t.scope==="project"?"project":"global";if(t.all){let o=[];for(let i of q)Kt(i,n).removed&&o.push(i.displayName);o.length>0?console.log(`Removed visa-cli from: ${o.join(", ")}.`):console.log("visa-cli was not installed in any client.");return}e||(console.error("Usage: visa-cli uninstall <client>"),console.error(" visa-cli uninstall --all"),console.error(`
145
- Supported clients: ${q.map(o=>o.id).join(", ")}`),process.exit(1));let r=Ht(e);r||(console.error(`Unknown client: ${e}`),console.error(`Supported clients: ${q.map(o=>o.id).join(", ")}`),process.exit(1));let s=Kt(r,n);s.removed?console.log(`Removed visa-cli from ${s.configPath}`):console.log(`visa-cli was not installed for ${r.displayName}.`)}catch(n){console.error("Error:",n.message),process.exit(1)}});T.command("pay <url>").description("Pay a merchant URL (amount auto-detected from HTTP 402 response)").option("-m, --method <method>","HTTP method (GET or POST)","GET").option("-b, --body <json>","JSON request body for POST endpoints").action(async(e,t)=>{try{ur(e);let n=dr(t.method),r=fr(t.body),s=new le(()=>$.getSessionToken());console.log(`Checking payment for ${e}...`);let o=pr(await s.paymentPreview({url:e}));console.log(` Merchant: ${o.merchantName}`),console.log(` Amount: $${o.amount.toFixed(2)} ${o.currency}`),console.log(` Rail: auto-detected
146
- `);let a=(await s.getStatus()).attestationRequired!==!1;a&&!D()&&console.warn("Warning: Touch ID unavailable on this system \u2014 payment will proceed without biometric attestation.");let c=tt.randomUUID(),l=await jt(s,async()=>{let d;if(a&&D())try{let{nonce:f}=await s.getAttestationChallenge(),y=Buffer.from(JSON.stringify({nonce:f,amount:o.amount,merchant:o.merchantName,context:e})).toString("base64");d={signature:await xt(y,`pay $${o.amount.toFixed(2)} to ${o.merchantName}`),nonce:f,amount:o.amount,merchant:o.merchantName}}catch(f){throw new Error(`Touch ID confirmation failed: ${f?.message||"user cancelled or biometric error"}`)}return s.pay({url:e,method:n,body:r,attestation:d,idempotencyKey:c})});if(l.success){if(console.log(`Payment complete: $${(l.amount??o.amount).toFixed(2)} \u2192 ${l.merchantName??o.merchantName}`),l.receipt?.urls?.length){console.log(`
147
- Result URLs:`);for(let d of l.receipt.urls)console.log(` ${d}`)}}else console.error(`Payment failed: ${l.message||"Unknown error"}`),process.exit(1)}catch(n){n instanceof j?console.error(`Error: ${n.message}`):console.error("Error:",n.message),process.exit(1)}});T.command("status").description("Check enrollment, cards, wallet, and spending controls").action(async()=>{xe=!1;try{let e=M(),t=await e.getStatus(),n={currentVersion:e.getClientVersion(),latestVersion:e.lastSignals.updateAvailable?.version,updateMessage:e.lastSignals.updateAvailable?.message,updateCheckDisabled:W()},r=await e.getTransactions().catch(s=>{if(process.env.VISA_CLI_DEBUG){let o=s instanceof Error?s.message:String(s);process.stderr.write(`[visa-cli] getTransactions failed (HUD will omit): ${o}
148
- `)}return{transactions:[]}});process.stdout.write(Jn(t,Array.isArray(r?.transactions)?r.transactions:[],D(),n)),xe=!0}catch(e){xe=!1,console.error("Error:",e.message),process.exit(1)}});var Gt=T.command("api-key").alias("api-keys").description("Create and manage API keys for apps and agents");Gt.command("create [label]").description("Create an API key for the authenticated approved user").option("--tools <ids>","Comma-separated allowed tool ids (default: all tools)").option("--daily-cap <usd>","Daily cap in USD, between 1 and 100 (default: server default)").option("--json","Output raw JSON").action(async(e,t)=>{try{let r=await M().createAppApiKey({label:So(e),allowed_tools:vo(t.tools),daily_cap_cents:bo(t.dailyCap)});if(t.json){console.log(JSON.stringify(r,null,2));return}console.log("API key created."),console.log(""),console.log(`Key: ${r.key}`),console.log(`Label: ${r.label}`),console.log(`Owner: ${r.owner}`),console.log(`Allowed tools: ${Ar(r.allowed_tools)}`),console.log(`Daily cap: ${Tr(r.daily_cap_cents)}/day`),console.log(""),console.log("Store this key now. It will not be shown again."),console.log(""),console.log("Example:"),console.log(" curl -X POST https://auth.visacli.sh/v1/api/shortcuts/generate_image_card \\"),console.log(` -H "X-Api-Key: ${r.key}" \\`),console.log(' -H "Content-Type: application/json" \\'),console.log(` -d '{"prompt":"a neon cityscape at dusk"}'`)}catch(n){console.error("Error:",n.message),process.exit(1)}});Gt.command("list").description("List API keys for the authenticated user").option("--json","Output raw JSON").action(async e=>{try{let n=await M().listAppApiKeys();if(e.json){console.log(JSON.stringify(n,null,2));return}let r=n.keys||[];if(r.length===0){console.log("No API keys found. Create one with: visa-cli api-key create");return}console.log("API keys"),console.log("");for(let s of r)console.log(`${s.id}. ${s.label} (${s.key_prefix})`),console.log(` Status: ${s.status}`),console.log(` Owner: ${s.owner}`),console.log(` Allowed tools: ${Ar(s.allowed_tools)}`),console.log(` Daily cap: ${Tr(s.daily_cap_cents)}/day`),console.log(` Last used: ${s.last_used_at||"never"}`)}catch(t){console.error("Error:",t.message),process.exit(1)}});Gt.command("revoke <id>").alias("delete").description("Revoke (or delete) an API key by id").action(async e=>{try{let t=Number(e);if(!Number.isInteger(t)||t<=0)throw new Error("API key id must be a positive integer. Run `visa-cli api-key list` first.");let r=await M().revokeAppApiKey(t);console.log(`Revoked API key ${r.revoked}.`)}catch(t){console.error("Error:",t.message),process.exit(1)}});T.command("reset").description("Log out and clear all credentials").action(async()=>{try{console.log(`Resetting Visa CLI...
149
- `);try{await M().logout(),console.log(" Server session invalidated.")}catch{console.log(" Server logout skipped (no active session).")}if(await $.clearAll(),console.log(" Keychain credentials cleared."),D())try{await qn(),console.log(" Secure Enclave key deleted.")}catch{console.log(" No Secure Enclave key to delete.")}console.log(`
150
- Reset complete.`)}catch(e){console.error("Error:",e.message),process.exit(1)}});T.command("feedback").description("Submit feedback about Visa CLI").argument("[message]","Your feedback message").action(async e=>{(!e||e.trim().length===0)&&(console.log('Usage: visa-cli feedback "your message"'),process.exit(1));try{await $.getSessionToken()||(console.error("Not logged in. Run visa-cli setup first."),process.exit(1)),await M().feedback(e.trim()),console.log("Feedback submitted. Thanks!")}catch(t){console.error("Error:",t.message),process.exit(1)}});var Wt=T.command("config").description("Inspect the CLI configuration");Wt.command("list").description("Show resolved config values (env vars, server state, defaults) with their source").option("--json","Output as JSON for scripting / agent consumption").option("--dev","Include developer/test hooks (VISA_MOCK_*, VISA_CLI_DEBUG)").option("--verbose","Show one-line hints beneath entries that have them").action(async e=>{try{let t=M(),n=await ir({api:t,includeDev:!!e.dev});if(e.json){console.log(cr(n));return}n.statusError&&(console.error(`Warning: could not reach auth server (${n.statusError}).`),console.error("Server-sourced entries show '\u2014'. Log in with `visa-cli setup` if you expected values here."),console.error("")),console.log(ar(n.entries,{verbose:!!e.verbose}))}catch(t){console.error("Error:",t.message),process.exit(1)}});function wo(){return Object.entries(he).map(([e,t])=>` ${e.padEnd(22)} (${t.type}) ${t.description}`).join(`
151
- `)}Wt.command("set <key> <value>").description("Persist a CLI setting to ~/.visa-mcp/settings.json").addHelpText("after",`
143
+ `),console.log(` ${"Client".padEnd(18)} ${"Detected".padEnd(10)} ${"Installed".padEnd(11)} Config Path`),console.log(` ${"\u2500".repeat(18)} ${"\u2500".repeat(10)} ${"\u2500".repeat(11)} ${"\u2500".repeat(40)}`);for(let a of q){let c=ke(a),l=Cr(a),u=c?"Yes":"No",f=l?"Yes":"No",y=a.globalConfigPath.replace(R.homedir(),"~");console.log(` ${a.displayName.padEnd(18)} ${u.padEnd(10)} ${f.padEnd(11)} ${y}`)}console.log("");return}let n=t.scope==="project"?"project":"global";if(t.all){let o=[],i=[];for(let a of q){if(!ke(a)){i.push(a.displayName);continue}xe(a,n),o.push(a.displayName)}o.length>0&&console.log(`Installed for: ${o.join(", ")}.`),i.length>0&&console.log(`Skipped: ${i.map(a=>`${a} (not detected)`).join(", ")}.`),o.length===0&&i.length===0&&console.log("No supported clients found.");return}e||(console.error("Usage: visa-cli install <client>"),console.error(" visa-cli install --all"),console.error(" visa-cli install --list"),console.error(`
144
+ Supported clients: ${q.map(o=>o.id).join(", ")}`),process.exit(1));let r=Bt(e);r||(console.error(`Unknown client: ${e}`),console.error(`Supported clients: ${q.map(o=>o.id).join(", ")}`),process.exit(1)),n==="global"&&!ke(r)&&(console.error(`${r.displayName} not detected on this machine.`),console.error(`Expected: ${r.detectPaths.join(", ")}`),process.exit(1));let s=xe(r,n);console.log(`Registered visa-cli MCP server in ${s.configPath}`),console.log(s.message)}catch(n){console.error("Error:",n.message),process.exit(1)}});T.command("uninstall [client]").description("Remove MCP server from an AI client").option("--all","Remove from all clients").option("--scope <scope>","Uninstall scope: global or project","global").action(async(e,t)=>{try{let n=t.scope==="project"?"project":"global";if(t.all){let o=[];for(let i of q)Jt(i,n).removed&&o.push(i.displayName);o.length>0?console.log(`Removed visa-cli from: ${o.join(", ")}.`):console.log("visa-cli was not installed in any client.");return}e||(console.error("Usage: visa-cli uninstall <client>"),console.error(" visa-cli uninstall --all"),console.error(`
145
+ Supported clients: ${q.map(o=>o.id).join(", ")}`),process.exit(1));let r=Bt(e);r||(console.error(`Unknown client: ${e}`),console.error(`Supported clients: ${q.map(o=>o.id).join(", ")}`),process.exit(1));let s=Jt(r,n);s.removed?console.log(`Removed visa-cli from ${s.configPath}`):console.log(`visa-cli was not installed for ${r.displayName}.`)}catch(n){console.error("Error:",n.message),process.exit(1)}});T.command("pay <url>").description("Pay a merchant URL (amount auto-detected from HTTP 402 response)").option("-m, --method <method>","HTTP method (GET or POST)","GET").option("-b, --body <json>","JSON request body for POST endpoints").action(async(e,t)=>{try{pr(e);let n=gr(t.method),r=mr(t.body),s=new le(()=>x.getSessionToken());console.log(`Checking payment for ${e}...`);let o=hr(await s.paymentPreview({url:e}));console.log(` Merchant: ${o.merchantName}`),console.log(` Amount: $${o.amount.toFixed(2)} ${o.currency}`),console.log(` Rail: auto-detected
146
+ `);let a=(await s.getStatus()).attestationRequired!==!1;a&&!D()&&console.warn("Warning: Touch ID unavailable on this system \u2014 payment will proceed without biometric attestation.");let c=rt.randomUUID(),l=await Ht(s,async()=>{let u;if(a&&D())try{let{nonce:f}=await s.getAttestationChallenge(),y=Buffer.from(JSON.stringify({nonce:f,amount:o.amount,merchant:o.merchantName,context:e})).toString("base64");u={signature:await Pt(y,`pay $${o.amount.toFixed(2)} to ${o.merchantName}`),nonce:f,amount:o.amount,merchant:o.merchantName}}catch(f){throw new Error(`Touch ID confirmation failed: ${f?.message||"user cancelled or biometric error"}`)}return s.pay({url:e,method:n,body:r,attestation:u,idempotencyKey:c})});if(l.success){if(console.log(`Payment complete: $${(l.amount??o.amount).toFixed(2)} \u2192 ${l.merchantName??o.merchantName}`),l.receipt?.urls?.length){console.log(`
147
+ Result URLs:`);for(let u of l.receipt.urls)console.log(` ${u}`)}}else console.error(`Payment failed: ${l.message||"Unknown error"}`),process.exit(1)}catch(n){n instanceof j?console.error(`Error: ${n.message}`):console.error("Error:",n.message),process.exit(1)}});T.command("status").description("Check enrollment, cards, wallet, and spending controls").action(async()=>{Ee=!1;try{let e=M(),t=await e.getStatus(),n={currentVersion:e.getClientVersion(),latestVersion:e.lastSignals.updateAvailable?.version,updateMessage:e.lastSignals.updateAvailable?.message,updateCheckDisabled:J()},r=await e.getTransactions().catch(s=>{if(process.env.VISA_CLI_DEBUG){let o=s instanceof Error?s.message:String(s);process.stderr.write(`[visa-cli] getTransactions failed (HUD will omit): ${o}
148
+ `)}return{transactions:[]}});process.stdout.write(Xn(t,Array.isArray(r?.transactions)?r.transactions:[],D(),n)),Ee=!0}catch(e){Ee=!1,console.error("Error:",e.message),process.exit(1)}});var zt=T.command("api-key").alias("api-keys").description("Create and manage API keys for apps and agents");zt.command("create [label]").description("Create an API key for the authenticated approved user").option("--tools <ids>","Comma-separated allowed tool ids (default: all tools)").option("--daily-cap <usd>","Daily cap in USD, between 1 and 100 (default: server default)").option("--json","Output raw JSON").action(async(e,t)=>{try{let r=await M().createAppApiKey({label:wo(e),allowed_tools:_o(t.tools),daily_cap_cents:Co(t.dailyCap)});if(t.json){console.log(JSON.stringify(r,null,2));return}console.log("API key created."),console.log(""),console.log(`Key: ${r.key}`),console.log(`Label: ${r.label}`),console.log(`Owner: ${r.owner}`),console.log(`Allowed tools: ${Ir(r.allowed_tools)}`),console.log(`Daily cap: ${Rr(r.daily_cap_cents)}/day`),console.log(""),console.log("Store this key now. It will not be shown again."),console.log(""),console.log("Example:"),console.log(" curl -X POST https://auth.visacli.sh/v1/api/shortcuts/generate_image_card \\"),console.log(` -H "X-Api-Key: ${r.key}" \\`),console.log(' -H "Content-Type: application/json" \\'),console.log(` -d '{"prompt":"a neon cityscape at dusk"}'`)}catch(n){console.error("Error:",n.message),process.exit(1)}});zt.command("list").description("List API keys for the authenticated user").option("--json","Output raw JSON").action(async e=>{try{let n=await M().listAppApiKeys();if(e.json){console.log(JSON.stringify(n,null,2));return}let r=n.keys||[];if(r.length===0){console.log("No API keys found. Create one with: visa-cli api-key create");return}console.log("API keys"),console.log("");for(let s of r)console.log(`${s.id}. ${s.label} (${s.key_prefix})`),console.log(` Status: ${s.status}`),console.log(` Owner: ${s.owner}`),console.log(` Allowed tools: ${Ir(s.allowed_tools)}`),console.log(` Daily cap: ${Rr(s.daily_cap_cents)}/day`),console.log(` Last used: ${s.last_used_at||"never"}`)}catch(t){console.error("Error:",t.message),process.exit(1)}});zt.command("revoke <id>").alias("delete").description("Revoke (or delete) an API key by id").action(async e=>{try{let t=Number(e);if(!Number.isInteger(t)||t<=0)throw new Error("API key id must be a positive integer. Run `visa-cli api-key list` first.");let r=await M().revokeAppApiKey(t);console.log(`Revoked API key ${r.revoked}.`)}catch(t){console.error("Error:",t.message),process.exit(1)}});T.command("reset").description("Log out and clear all credentials").action(async()=>{try{console.log(`Resetting Visa CLI...
149
+ `);try{await M().logout(),console.log(" Server session invalidated.")}catch{console.log(" Server logout skipped (no active session).")}if(await x.clearAll(),console.log(" Keychain credentials cleared."),D())try{await Wn(),console.log(" Secure Enclave key deleted.")}catch{console.log(" No Secure Enclave key to delete.")}console.log(`
150
+ Reset complete.`)}catch(e){console.error("Error:",e.message),process.exit(1)}});T.command("feedback").description("Submit feedback about Visa CLI").argument("[message]","Your feedback message").action(async e=>{(!e||e.trim().length===0)&&(console.log('Usage: visa-cli feedback "your message"'),process.exit(1));try{await x.getSessionToken()||(console.error("Not logged in. Run visa-cli setup first."),process.exit(1)),await M().feedback(e.trim()),console.log("Feedback submitted. Thanks!")}catch(t){console.error("Error:",t.message),process.exit(1)}});var Yt=T.command("config").description("Inspect the CLI configuration");Yt.command("list").description("Show resolved config values (env vars, server state, defaults) with their source").option("--json","Output as JSON for scripting / agent consumption").option("--dev","Include developer/test hooks (VISA_MOCK_*, VISA_CLI_DEBUG)").option("--verbose","Show one-line hints beneath entries that have them").action(async e=>{try{let t=M(),n=await lr({api:t,includeDev:!!e.dev});if(e.json){console.log(dr(n));return}n.statusError&&(console.error(`Warning: could not reach auth server (${n.statusError}).`),console.error("Server-sourced entries show '\u2014'. Log in with `visa-cli setup` if you expected values here."),console.error("")),console.log(ur(n.entries,{verbose:!!e.verbose}))}catch(t){console.error("Error:",t.message),process.exit(1)}});function ko(){return Object.entries(he).map(([e,t])=>` ${e.padEnd(22)} (${t.type}) ${t.description}`).join(`
151
+ `)}Yt.command("set <key> <value>").description("Persist a CLI setting to ~/.visa-mcp/settings.json").addHelpText("after",`
152
152
  Settable keys:
153
- ${wo()}`).action((e,t)=>{try{let n=In(e,t);console.log(`Saved ${n.key}=${JSON.stringify(n.value)} \u2192 ${n.path}`),n.requiresRestart&&console.log("Restart Claude Code (or your MCP-enabled client) for the change to take effect.")}catch(n){n instanceof ae||n instanceof ce?console.error(`Error: ${n.message}`):console.error(`Error: ${n.message}`),process.exit(1)}});Wt.command("unset <key>").description("Remove a CLI setting from ~/.visa-mcp/settings.json (falls back to env var or default)").action(e=>{try{let t=Ln(e);t.removed?(console.log(`Removed ${t.key} from ${t.path}`),t.requiresRestart&&console.log("Restart Claude Code (or your MCP-enabled client) for the change to take effect.")):console.log(`No-op: ${t.key} was not set in ${t.path}.`)}catch(t){console.error(`Error: ${t.message}`),process.exit(1)}});var Jt=T.command("biometric").description("Manage Touch ID / biometric attestation enforcement");Jt.command("status").description("Show current biometric enforcement state").action(async()=>{try{await $.getSessionToken()||(console.error("Not logged in. Run visa-cli setup first."),process.exit(1));let n=await M().getStatus(),r=n.attestationRequired!==!1,s=!!n.hasAttestationKey,o=D();console.log(`Server policy: Touch ID ${r?"REQUIRED":"NOT required"}`),console.log(`Attestation key registered: ${s?"yes":"no"}`),console.log(`Touch ID available on this device: ${o?"yes":"no"}`)}catch(e){console.error("Error:",e.message),process.exit(1)}});Jt.command("on").description("Require Touch ID for payments (security upgrade \u2014 no Touch ID needed)").action(async()=>{try{await $.getSessionToken()||(console.error("Not logged in. Run visa-cli setup first."),process.exit(1));let t=M(),n=await t.setBiometricPreference({required:!0});n.success||(console.error(`Failed: ${n.error||"unknown error"}`),process.exit(1)),console.log("Touch ID is now REQUIRED for payments."),(await t.getStatus()).hasAttestationKey||console.warn("Note: no attestation key is registered yet. Run `visa-cli setup` to enroll Touch ID.")}catch(e){console.error("Error:",e.message),process.exit(1)}});Jt.command("off").description("Disable Touch ID requirement (security downgrade \u2014 one Touch ID confirmation required)").action(async()=>{try{await $.getSessionToken()||(console.error("Not logged in. Run visa-cli setup first."),process.exit(1));let t=M(),n=await t.getStatus();if(n.attestationRequired===!1){console.log("Touch ID is already disabled.");return}n.hasAttestationKey&&!D()&&(console.error("Touch ID is unavailable on this device but the server has a registered key."),console.error("Disable Touch ID from a device that can sign, or contact support."),process.exit(1));let r=await jt(t,async()=>{let s;if(n.hasAttestationKey&&D())try{let{nonce:o}=await t.getAttestationChallenge(),i=0,a="",c=Buffer.from(JSON.stringify({nonce:o,amount:i,merchant:a,context:"biometric-preference"})).toString("base64");s={signature:await xt(c,"disable Touch ID requirement"),nonce:o,amount:i,merchant:a}}catch(o){throw new Error(`Touch ID confirmation failed: ${o?.message||"cancelled"}`)}return t.setBiometricPreference({required:!1,attestation:s})});r.success||(console.error(`Failed: ${r.error||"unknown error"}`),process.exit(1)),console.log("Touch ID is no longer required for payments.")}catch(e){console.error("Error:",e.message),process.exit(1)}});var oe=T.command("shell-hud").description("Manage the persistent Visa HUD shown in your shell prompt");function Rr(){let e=Lt();e.installed||(console.error(e.message),process.exit(1)),console.log(e.message)}function Ir(){let e=Ot();e.removed||(console.error(e.message),process.exit(1)),console.log(e.message)}oe.command("install").description("Install the persistent shell HUD into your zsh or bash rc file").action(Rr);oe.command("enable").description("Enable the persistent shell HUD").action(Rr);oe.command("uninstall").description("Remove the persistent shell HUD from your shell rc file").action(Ir);oe.command("disable").description("Disable the persistent shell HUD").action(Ir);oe.command("segment").description("Print the cached shell HUD segment").action(()=>{process.stdout.write(`${Dt()}
153
+ ${ko()}`).action((e,t)=>{try{let n=On(e,t);console.log(`Saved ${n.key}=${JSON.stringify(n.value)} \u2192 ${n.path}`),n.requiresRestart&&console.log("Restart Claude Code (or your MCP-enabled client) for the change to take effect.")}catch(n){n instanceof ae||n instanceof ce?console.error(`Error: ${n.message}`):console.error(`Error: ${n.message}`),process.exit(1)}});Yt.command("unset <key>").description("Remove a CLI setting from ~/.visa-mcp/settings.json (falls back to env var or default)").action(e=>{try{let t=Dn(e);t.removed?(console.log(`Removed ${t.key} from ${t.path}`),t.requiresRestart&&console.log("Restart Claude Code (or your MCP-enabled client) for the change to take effect.")):console.log(`No-op: ${t.key} was not set in ${t.path}.`)}catch(t){console.error(`Error: ${t.message}`),process.exit(1)}});var Xt=T.command("biometric").description("Manage Touch ID / biometric attestation enforcement");Xt.command("status").description("Show current biometric enforcement state").action(async()=>{try{await x.getSessionToken()||(console.error("Not logged in. Run visa-cli setup first."),process.exit(1));let n=await M().getStatus(),r=n.attestationRequired!==!1,s=!!n.hasAttestationKey,o=D();console.log(`Server policy: Touch ID ${r?"REQUIRED":"NOT required"}`),console.log(`Attestation key registered: ${s?"yes":"no"}`),console.log(`Touch ID available on this device: ${o?"yes":"no"}`)}catch(e){console.error("Error:",e.message),process.exit(1)}});Xt.command("on").description("Require Touch ID for payments (security upgrade \u2014 no Touch ID needed)").action(async()=>{try{await x.getSessionToken()||(console.error("Not logged in. Run visa-cli setup first."),process.exit(1));let t=M(),n=await t.setBiometricPreference({required:!0});n.success||(console.error(`Failed: ${n.error||"unknown error"}`),process.exit(1)),console.log("Touch ID is now REQUIRED for payments."),(await t.getStatus()).hasAttestationKey||console.warn("Note: no attestation key is registered yet. Run `visa-cli setup` to enroll Touch ID.")}catch(e){console.error("Error:",e.message),process.exit(1)}});Xt.command("off").description("Disable Touch ID requirement (security downgrade \u2014 one Touch ID confirmation required)").action(async()=>{try{await x.getSessionToken()||(console.error("Not logged in. Run visa-cli setup first."),process.exit(1));let t=M(),n=await t.getStatus();if(n.attestationRequired===!1){console.log("Touch ID is already disabled.");return}n.hasAttestationKey&&!D()&&(console.error("Touch ID is unavailable on this device but the server has a registered key."),console.error("Disable Touch ID from a device that can sign, or contact support."),process.exit(1));let r=await Ht(t,async()=>{let s;if(n.hasAttestationKey&&D())try{let{nonce:o}=await t.getAttestationChallenge(),i=0,a="",c=Buffer.from(JSON.stringify({nonce:o,amount:i,merchant:a,context:"biometric-preference"})).toString("base64");s={signature:await Pt(c,"disable Touch ID requirement"),nonce:o,amount:i,merchant:a}}catch(o){throw new Error(`Touch ID confirmation failed: ${o?.message||"cancelled"}`)}return t.setBiometricPreference({required:!1,attestation:s})});r.success||(console.error(`Failed: ${r.error||"unknown error"}`),process.exit(1)),console.log("Touch ID is no longer required for payments.")}catch(e){console.error("Error:",e.message),process.exit(1)}});var oe=T.command("shell-hud").description("Manage the persistent Visa HUD shown in your shell prompt");function Lr(){let e=Ot();e.installed||(console.error(e.message),process.exit(1)),console.log(e.message)}function Nr(){let e=Dt();e.removed||(console.error(e.message),process.exit(1)),console.log(e.message)}oe.command("install").description("Install the persistent shell HUD into your zsh or bash rc file").action(Lr);oe.command("enable").description("Enable the persistent shell HUD").action(Lr);oe.command("uninstall").description("Remove the persistent shell HUD from your shell rc file").action(Nr);oe.command("disable").description("Disable the persistent shell HUD").action(Nr);oe.command("segment").description("Print the cached shell HUD segment").action(()=>{process.stdout.write(`${jt()}
154
154
  `)});oe.command("doctor").description("Diagnose shell HUD installation and connectivity").action(async()=>{let{existsSync:e,readFileSync:t}=await import("fs"),n=!0,r=(f,y,w)=>{console.log(` ${y?"\u2713":"\u2717"} ${f}: ${w}`),y||(n=!1)};console.log(`Shell HUD Doctor
155
- `);let s=Ye();if(r("Shell detected",!!s,s??"none (zsh, bash, or PowerShell required)"),s){let f=Xe(s),y=e(f);if(r("RC file exists",y,f.replace(R.homedir(),"~")),y){let u=t(f,"utf-8").includes("visa-cli shell hud v2");r("HUD block installed",u,u?"found in rc file":"missing \u2014 run: visa-cli shell-hud install")}}let o=be(),i=e(o);if(r("Cache file",i,i?o.replace(R.homedir(),"~"):"missing \u2014 HUD has not refreshed yet"),i)try{let f=JSON.parse(t(o,"utf-8")),y=Date.now()-(f.renderedAt??0),w=Math.round(y/1e3),u=w<=30;console.log(` ${u?"\u2713":"\u26A0"} Cache freshness: ${w}s old${u?"":" (stale \u2014 will refresh on next prompt)"}`)}catch{r("Cache readable",!1,"corrupt JSON")}let a=ze(),c=e(a),l="missing";if(c)try{l=t(a,"utf-8").trim().slice(0,80)}catch{l="unreadable"}r("Line file",c,l);let d=!1;try{d=!!await $.getSessionToken()}catch{}if(r("Auth token",d,d?"found in keychain":"missing \u2014 run: visa-cli setup"),d)try{await M().getStatus(),r("API connectivity",!0,"GET /v1/status OK")}catch(f){let y=f instanceof Error?f.message:"unknown error";r("API connectivity",!1,y)}console.log(n?`
155
+ `);let s=Ze();if(r("Shell detected",!!s,s??"none (zsh, bash, or PowerShell required)"),s){let f=Qe(s),y=e(f);if(r("RC file exists",y,f.replace(R.homedir(),"~")),y){let d=t(f,"utf-8").includes("visa-cli shell hud v2");r("HUD block installed",d,d?"found in rc file":"missing \u2014 run: visa-cli shell-hud install")}}let o=be(),i=e(o);if(r("Cache file",i,i?o.replace(R.homedir(),"~"):"missing \u2014 HUD has not refreshed yet"),i)try{let f=JSON.parse(t(o,"utf-8")),y=Date.now()-(f.renderedAt??0),w=Math.round(y/1e3),d=w<=30;console.log(` ${d?"\u2713":"\u26A0"} Cache freshness: ${w}s old${d?"":" (stale \u2014 will refresh on next prompt)"}`)}catch{r("Cache readable",!1,"corrupt JSON")}let a=Xe(),c=e(a),l="missing";if(c)try{l=t(a,"utf-8").trim().slice(0,80)}catch{l="unreadable"}r("Line file",c,l);let u=!1;try{u=!!await x.getSessionToken()}catch{}if(r("Auth token",u,u?"found in keychain":"missing \u2014 run: visa-cli setup"),u)try{await M().getStatus(),r("API connectivity",!0,"GET /v1/status OK")}catch(f){let y=f instanceof Error?f.message:"unknown error";r("API connectivity",!1,y)}console.log(n?`
156
156
  All checks passed.`:`
157
- Some checks failed \u2014 see above.`),n||process.exit(1)});oe.command("refresh").description("Refresh the shell HUD cache (no-op if cache is fresh unless --force)").option("--force","Bypass the cache freshness gate and always refresh").action(async e=>{if(!(!e.force&&tr()))try{let t=M(),n=await t.getStatus(),r={currentVersion:t.getClientVersion(),latestVersion:t.lastSignals.updateAvailable?.version,updateMessage:t.lastSignals.updateAvailable?.message,updateCheckDisabled:W()},s=Nt(n,r);Ut(s)}catch{}finally{ve()}});T.command("statusline").description("Output the Visa HUD for agent statusline integrations").option("--json","Output structured JSON for clients that render their own HUD").action(async e=>{try{let t=await gn(),r=Dt().split(`
158
- `)[0];if(e.json){let o=await yn(r,t);process.stdout.write(`${JSON.stringify(o,null,2)}
159
- `);return}let s=await mn(r,t);process.stdout.write(`${s}
160
- `)}catch(t){let n=t instanceof Error?t.message:"unknown error";console.error(`Failed to render Visa HUD: ${n}`),process.exit(1)}});var nt=T.command("hud").description("Manage the Visa HUD for supported agent terminals");nt.command("enable").description("Register Visa HUD for Claude Code or Codex").argument("[client]","Agent client to enable: claude, codex, or all","claude").action(e=>{let t=ht(e);if(t||(console.error(`Unknown HUD client: ${e}`),console.error("Supported clients: claude, codex, all"),process.exit(1)),t==="claude"||t==="claude-code"||t==="all"){let n=se.join(R.homedir(),".claude","settings.json"),r=Ne(n);console.log(r.message),(r.installed==="error"||r.installed==="malformed-json")&&process.exit(1)}if(t==="codex"||t==="all"){let n=Lt();console.log(n.message),console.log("Codex structured HUD payload is available with: visa-cli statusline --json"),console.log("Codex does not currently expose a Claude-style command statusLine install path, so this enables the terminal HUD fallback."),n.installed||process.exit(1)}});nt.command("disable").description("Remove Visa HUD from Claude Code or Codex terminal surfaces").argument("[client]","Agent client to disable: claude, codex, or all","claude").action(e=>{let t=ht(e);t||(console.error(`Unknown HUD client: ${e}`),console.error("Supported clients: claude, codex, all"),process.exit(1));let n=!1,r=!1;if(t==="claude"||t==="claude-code"||t==="all"){let s=se.join(R.homedir(),".claude","settings.json"),o=dt(s);console.log(o.message),o.removed&&(r=!0),!o.removed&&t!=="all"&&(n=!0)}if(t==="codex"||t==="all"){let s=Ot();console.log(s.message),s.removed&&(r=!0),!s.removed&&t!=="all"&&(n=!0)}t==="all"&&!r&&(n=!0),n&&process.exit(1)});nt.command("enable-claude").description("Register Visa HUD as the Claude Code statusLine").action(()=>{let e=se.join(R.homedir(),".claude","settings.json"),t=Ne(e);console.log(t.message),(t.installed==="error"||t.installed==="malformed-json")&&process.exit(1)});nt.command("disable-claude").description("Remove Visa HUD from Claude Code statusLine (leaves other tools untouched)").action(()=>{let e=se.join(R.homedir(),".claude","settings.json"),t=dt(e);console.log(t.message),t.removed||process.exit(1)});T.hook("postAction",()=>{if(xe){xe=!1;return}et&&Gn(et.lastSignals)});T.parse();
157
+ Some checks failed \u2014 see above.`),n||process.exit(1)});oe.command("refresh").description("Refresh the shell HUD cache (no-op if cache is fresh unless --force)").option("--force","Bypass the cache freshness gate and always refresh").action(async e=>{if(!(!e.force&&sr()))try{let t=M(),n=await t.getStatus(),r={currentVersion:t.getClientVersion(),latestVersion:t.lastSignals.updateAvailable?.version,updateMessage:t.lastSignals.updateAvailable?.message,updateCheckDisabled:J()},s=Ut(n,r);Mt(s)}catch{}finally{ve()}});T.command("statusline").description("Output the Visa HUD for agent statusline integrations").option("--json","Output structured JSON for clients that render their own HUD").action(async e=>{try{let t=await yn(),r=jt().split(`
158
+ `)[0];if(e.json){let o=await bn(r,t);process.stdout.write(`${JSON.stringify(o,null,2)}
159
+ `);return}let s=await Sn(r,t);process.stdout.write(`${s}
160
+ `)}catch(t){let n=t instanceof Error?t.message:"unknown error";console.error(`Failed to render Visa HUD: ${n}`),process.exit(1)}});var st=T.command("hud").description("Manage the Visa HUD for supported agent terminals");st.command("enable").description("Register Visa HUD for Claude Code or Codex").argument("[client]","Agent client to enable: claude, codex, or all","claude").action(e=>{let t=St(e);if(t||(console.error(`Unknown HUD client: ${e}`),console.error("Supported clients: claude, codex, all"),process.exit(1)),t==="claude"||t==="claude-code"||t==="all"){let n=se.join(R.homedir(),".claude","settings.json"),r=De(n);console.log(r.message),(r.installed==="error"||r.installed==="malformed-json")&&process.exit(1)}if(t==="codex"||t==="all"){let n=Ot();console.log(n.message),console.log("Codex structured HUD payload is available with: visa-cli statusline --json"),console.log("Codex does not currently expose a Claude-style command statusLine install path, so this enables the terminal HUD fallback."),n.installed||process.exit(1)}});st.command("disable").description("Remove Visa HUD from Claude Code or Codex terminal surfaces").argument("[client]","Agent client to disable: claude, codex, or all","claude").action(e=>{let t=St(e);t||(console.error(`Unknown HUD client: ${e}`),console.error("Supported clients: claude, codex, all"),process.exit(1));let n=!1,r=!1;if(t==="claude"||t==="claude-code"||t==="all"){let s=se.join(R.homedir(),".claude","settings.json"),o=pt(s);console.log(o.message),o.removed&&(r=!0),!o.removed&&t!=="all"&&(n=!0)}if(t==="codex"||t==="all"){let s=Dt();console.log(s.message),s.removed&&(r=!0),!s.removed&&t!=="all"&&(n=!0)}t==="all"&&!r&&(n=!0),n&&process.exit(1)});st.command("enable-claude").description("Register Visa HUD as the Claude Code statusLine").action(()=>{let e=se.join(R.homedir(),".claude","settings.json"),t=De(e);console.log(t.message),(t.installed==="error"||t.installed==="malformed-json")&&process.exit(1)});st.command("disable-claude").description("Remove Visa HUD from Claude Code statusLine (leaves other tools untouched)").action(()=>{let e=se.join(R.homedir(),".claude","settings.json"),t=pt(e);console.log(t.message),t.removed||process.exit(1)});T.hook("postAction",()=>{if(Ee){Ee=!1;return}nt&&zn(nt.lastSignals)});T.parse();