@visa/cli 1.8.0 → 1.9.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,7 +1,8 @@
1
- "use strict";var dr=Object.create;var Nt=Object.defineProperty;var fr=Object.getOwnPropertyDescriptor;var pr=Object.getOwnPropertyNames;var gr=Object.getPrototypeOf,mr=Object.prototype.hasOwnProperty;var hr=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var yr=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of pr(t))!mr.call(e,s)&&s!==n&&Nt(e,s,{get:()=>t[s],enumerable:!(r=fr(t,s))||r.enumerable});return e};var g=(e,t,n)=>(n=e!=null?dr(gr(e)):{},yr(t||!e||!e.__esModule?Nt(n,"default",{value:e,enumerable:!0}):n,e));var nt=hr((qs,Pr)=>{Pr.exports={name:"@visa/cli",version:"1.8.0",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",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 nr=require("commander"),ze=g(require("crypto")),rr=g(require("fs")),j=g(require("os")),we=g(require("path")),sr=g(require("readline")),or=require("child_process"),ir=require("util");var ke=require("child_process"),Dt=require("util"),z=g(require("fs")),$e=g(require("os")),Qe=g(require("path")),K=(0,Dt.promisify)(ke.execFile),et=Qe.join($e.homedir(),".visa-mcp"),_e=Qe.join(et,"session-token"),U="visa-cli",J="session-token",Ce="rc-access",Sr=5e3;async function vr(){try{let{stdout:e}=await K("security",["find-generic-password","-s",U,"-a",J,"-w"],{timeout:5e3});return e.trim()||null}catch{return null}}async function br(e){try{try{await K("security",["delete-generic-password","-s",U,"-a",J],{timeout:5e3})}catch{}return await K("security",["add-generic-password","-s",U,"-a",J,"-w",e],{timeout:5e3}),!0}catch{return!1}}async function wr(){try{await K("security",["delete-generic-password","-s",U,"-a",J],{timeout:5e3})}catch{}}async function _r(){if(!tt())return null;try{let{stdout:e}=await K("secret-tool",["lookup","service",U,"account",J],{timeout:5e3});return e.trim()||null}catch{return null}}async function Cr(e){if(!tt())return!1;try{let t=(0,ke.execFile)("secret-tool",["store","--label",`${U} ${J}`,"service",U,"account",J]);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"))},Sr))]),!0):!1}catch{return!1}}async function kr(){if(tt())try{await K("secret-tool",["clear","service",U,"account",J],{timeout:5e3})}catch{}}function tt(){return!!process.env.DBUS_SESSION_BUS_ADDRESS}async function $r(){try{let{stdout:e}=await K("security",["find-generic-password","-s",U,"-a",Ce,"-w"],{timeout:5e3});return e.trim()||null}catch{return null}}async function Er(e){try{try{await K("security",["delete-generic-password","-s",U,"-a",Ce],{timeout:5e3})}catch{}await K("security",["add-generic-password","-s",U,"-a",Ce,"-w",e],{timeout:5e3})}catch{}}async function xr(){try{await K("security",["delete-generic-password","-s",U,"-a",Ce],{timeout:5e3})}catch{}}function Xe(){try{return z.readFileSync(_e,"utf-8").trim()||null}catch{return null}}function Ut(e){z.mkdirSync(et,{recursive:!0,mode:448}),z.writeFileSync(_e,e,{mode:384}),process.platform==="win32"&&Rr(_e)}function Ze(){try{z.unlinkSync(_e)}catch{}}function Rr(e){try{let t=$e.userInfo().username;(0,ke.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 Ye(){switch(process.platform){case"darwin":return{get:vr,store:br,delete:wr};case"linux":return{get:_r,store:Cr,delete:kr};default:return{get:async()=>Xe(),store:async e=>{try{return Ut(e),!0}catch{return!1}},delete:async()=>Ze(),storesInSessionFile:!0}}}var k=class{static async getSessionToken(){if(process.env.VISA_MOCK_KEYCHAIN==="true")return Promise.resolve("mock-session-token-for-testing");let t=Ye(),n=await t.get();if(n)return n;let r=Xe();return r?(await t.store(r),r):null}static async saveSessionToken(t){if(process.env.VISA_MOCK_KEYCHAIN==="true")return;let n=Ye();if(await n.store(t)){if(await n.get()===t){n.storesInSessionFile||Ze();return}await n.delete()}if(Ut(t),Xe()!==t)throw new Error("Failed to persist session token. "+(process.platform==="darwin"?'Check Keychain Access permissions for "visa-cli".':`Ensure ${et} is writable.`))}static async getRcAccessToken(){return process.env.VISA_MOCK_KEYCHAIN==="true"?"mock-rc-token-for-testing":$r()}static async saveRcAccessToken(t){process.env.VISA_MOCK_KEYCHAIN!=="true"&&await Er(t)}static async deleteSessionToken(){if(process.env.VISA_MOCK_KEYCHAIN==="true")return;await Ye().delete(),Ze()}static async clearAll(){await this.deleteSessionToken(),await xr()}};var Ee=g(require("crypto")),xe=g(require("tty")),Re=g(require("fs"));var Q="0000000000000000000000000000000000000000000000000000000000000000";function Tr(e){return/-rc\.|-beta\./.test(e)}function rt(e){return Ee.createHash("sha256").update(e.trim()).digest("hex")}function Mt(e){return Q==="SKIP"?!0:Ee.timingSafeEqual(Buffer.from(rt(e)),Buffer.from(Q))}function Ar(e){return new Promise((t,n)=>{let r=Re.openSync("/dev/tty","r+"),s=new xe.ReadStream(r),o=new xe.WriteStream(r),i=()=>{try{s.destroy()}catch{}try{o.destroy()}catch{}try{Re.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 yr=Object.create;var Ut=Object.defineProperty;var Sr=Object.getOwnPropertyDescriptor;var vr=Object.getOwnPropertyNames;var br=Object.getPrototypeOf,wr=Object.prototype.hasOwnProperty;var _r=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Cr=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of vr(t))!wr.call(e,s)&&s!==n&&Ut(e,s,{get:()=>t[s],enumerable:!(r=Sr(t,s))||r.enumerable});return e};var g=(e,t,n)=>(n=e!=null?yr(br(e)):{},Cr(t||!e||!e.__esModule?Ut(n,"default",{value:e,enumerable:!0}):n,e));var ot=_r((eo,Dr)=>{Dr.exports={name:"@visa/cli",version:"1.9.0-rc.0",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",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 cr=require("commander"),Ze=g(require("crypto")),lr=g(require("fs")),H=g(require("os")),ke=g(require("path")),ur=g(require("readline")),dr=require("child_process"),fr=require("util");var xe=require("child_process"),jt=require("util"),Y=g(require("fs")),Re=g(require("os")),nt=g(require("path")),B=(0,jt.promisify)(xe.execFile),rt=nt.join(Re.homedir(),".visa-mcp"),fe=nt.join(rt,"session-token"),U="visa-cli",z="session-token",$e="rc-access",kr=5e3,Ee=class extends Error{constructor(t){super(t),this.name="CredentialAccessError"}};function $r(e){let t=e;return[t?.message,t?.stderr].filter(n=>typeof n=="string").join(`
2
+ `)}function Ht(e){let t=e;if(t?.code==="EPERM"||t?.code==="EACCES")return!0;let n=$r(e).toLowerCase();return n.includes("operation not permitted")||n.includes("permission denied")}async function Er(){try{let{stdout:e}=await B("security",["find-generic-password","-s",U,"-a",z,"-w"],{timeout:5e3});return e.trim()||null}catch(e){if(Ht(e))throw new Ee("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 xr(e){try{try{await B("security",["delete-generic-password","-s",U,"-a",z],{timeout:5e3})}catch{}return await B("security",["add-generic-password","-s",U,"-a",z,"-w",e],{timeout:5e3}),!0}catch{return!1}}async function Rr(){try{await B("security",["delete-generic-password","-s",U,"-a",z],{timeout:5e3})}catch{}}async function Pr(){if(!st())return null;try{let{stdout:e}=await B("secret-tool",["lookup","service",U,"account",z],{timeout:5e3});return e.trim()||null}catch{return null}}async function Tr(e){if(!st())return!1;try{let t=(0,xe.execFile)("secret-tool",["store","--label",`${U} ${z}`,"service",U,"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"))},kr))]),!0):!1}catch{return!1}}async function Ar(){if(st())try{await B("secret-tool",["clear","service",U,"account",z],{timeout:5e3})}catch{}}function st(){return!!process.env.DBUS_SESSION_BUS_ADDRESS}async function Ir(){try{let{stdout:e}=await B("security",["find-generic-password","-s",U,"-a",$e,"-w"],{timeout:5e3});return e.trim()||null}catch{return null}}async function Lr(e){try{try{await B("security",["delete-generic-password","-s",U,"-a",$e],{timeout:5e3})}catch{}await B("security",["add-generic-password","-s",U,"-a",$e,"-w",e],{timeout:5e3})}catch{}}async function Or(){try{await B("security",["delete-generic-password","-s",U,"-a",$e],{timeout:5e3})}catch{}}function et(){try{return Y.readFileSync(fe,"utf-8").trim()||null}catch(e){if(Ht(e))throw new Ee(`Unable to read Visa CLI credentials from ${fe}. Check file permissions or rerun with access to the Visa CLI credential directory.`);return null}}function Vt(e){Y.mkdirSync(rt,{recursive:!0,mode:448}),Y.writeFileSync(fe,e,{mode:384}),process.platform==="win32"&&Nr(fe)}function tt(){try{Y.unlinkSync(fe)}catch{}}function Nr(e){try{let t=Re.userInfo().username;(0,xe.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 Qe(){switch(process.platform){case"darwin":return{get:Er,store:xr,delete:Rr};case"linux":return{get:Pr,store:Tr,delete:Ar};default:return{get:async()=>et(),store:async e=>{try{return Vt(e),!0}catch{return!1}},delete:async()=>tt(),storesInSessionFile:!0}}}var E=class{static async getSessionToken(){if(process.env.VISA_MOCK_KEYCHAIN==="true")return Promise.resolve("mock-session-token-for-testing");let t=Qe(),n=await t.get();if(n)return n;let r=et();return r?(await t.store(r),r):null}static async saveSessionToken(t){if(process.env.VISA_MOCK_KEYCHAIN==="true")return;let n=Qe();if(await n.store(t)){if(await n.get()===t){n.storesInSessionFile||tt();return}await n.delete()}if(Vt(t),et()!==t)throw new Error("Failed to persist session token. "+(process.platform==="darwin"?'Check Keychain Access permissions for "visa-cli".':`Ensure ${rt} is writable.`))}static async getRcAccessToken(){return process.env.VISA_MOCK_KEYCHAIN==="true"?"mock-rc-token-for-testing":Ir()}static async saveRcAccessToken(t){process.env.VISA_MOCK_KEYCHAIN!=="true"&&await Lr(t)}static async deleteSessionToken(){if(process.env.VISA_MOCK_KEYCHAIN==="true")return;await Qe().delete(),tt()}static async clearAll(){await this.deleteSessionToken(),await Or()}};var Pe=g(require("crypto")),Te=g(require("tty")),Ae=g(require("fs"));var ee="6820f6e91b762e645c9bf020c0d3673bb99d4a25a824880c0d548e10bb9bc7b1";function Mr(e){return/-rc\.|-beta\./.test(e)}function it(e){return Pe.createHash("sha256").update(e.trim()).digest("hex")}function Ft(e){return ee==="SKIP"?!0:Pe.timingSafeEqual(Buffer.from(it(e)),Buffer.from(ee))}function Ur(e){return new Promise((t,n)=>{let r=Ae.openSync("/dev/tty","r+"),s=new Te.ReadStream(r),o=new Te.WriteStream(r),i=()=>{try{s.destroy()}catch{}try{o.destroy()}catch{}try{Ae.closeSync(r)}catch{}};o.write(e),s.setRawMode(!0),s.resume(),s.setEncoding("utf8");let a="";s.on("data",c=>{c==="\r"||c===`
2
3
  `?(o.write(`
3
4
  `),i(),t(a)):c===""?(o.write(`
4
- `),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 Ir=`
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 jr=`
5
6
  \u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557
6
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
7
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
@@ -10,27 +11,27 @@
10
11
  \u255A\u2550\u2550\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D
11
12
 
12
13
  This is a Release Candidate build. Access is restricted to Visa employees.
13
- `;async function jt(e={}){let t=e.version??nt().version;if(!Tr(t))return;let n=process.env.VISA_RC_CODE;if(n&&Mt(n)){await k.saveRcAccessToken(rt(n));return}if(e.isMcp??!1){let i=await k.getRcAccessToken();if(i&&(Q==="SKIP"||i===Q))return;process.stderr.write(`[visa-cli] RC build requires access. Run: visa-cli setup
14
- `),process.exit(1)}let s=await k.getRcAccessToken();if(s&&(Q==="SKIP"||s===Q))return;console.log(Ir);let o=3;for(let i=1;i<=o;i++){let a;try{a=await Ar(" Enter RC access code: ")}catch{process.exit(1)}if(Mt(a)){await k.saveRcAccessToken(rt(a)),console.log(`
14
+ `;async function Bt(e={}){let t=e.version??ot().version;if(!Mr(t))return;let n=process.env.VISA_RC_CODE;if(n&&Ft(n)){await E.saveRcAccessToken(it(n));return}if(e.isMcp??!1){let i=await E.getRcAccessToken();if(i&&(ee==="SKIP"||i===ee))return;process.stderr.write(`[visa-cli] RC build requires access. Run: visa-cli setup
15
+ `),process.exit(1)}let s=await E.getRcAccessToken();if(s&&(ee==="SKIP"||s===ee))return;console.log(jr);let o=3;for(let i=1;i<=o;i++){let a;try{a=await Ur(" Enter RC access code: ")}catch{process.exit(1)}if(Ft(a)){await E.saveRcAccessToken(it(a)),console.log(`
15
16
  Access granted. Welcome.
16
17
  `);return}i<o&&console.log(`
17
18
  Invalid code. ${o-i} attempt(s) remaining.
18
19
  `)}console.log(`
19
20
  Invalid code. Contact your team lead.
20
- `),process.exit(1)}var Ht=require("child_process");function Lr(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 Or(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(`
21
- `)}function Nr(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 Vt(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,Ht.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 Or(e).split(`
22
- `))n(` ${c}`);n("");let i=Lr(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=Nr(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 Bt=g(require("crypto")),R=g(require("fs")),Pe=g(require("path"));function Kt(e,t){R.mkdirSync(Pe.dirname(e),{recursive:!0});let n=`${e}.${process.pid}.${Bt.randomBytes(8).toString("hex")}.tmp`;try{R.writeFileSync(n,JSON.stringify(t,null,2)+`
23
- `),R.renameSync(n,e)}catch(r){try{R.unlinkSync(n)}catch{}throw r}}function Ft(e){return`'${e.replace(/'/g,"'\\''")}'`}var qt="# visa-cli-hud-v1";function Dr(e,t){let n=e??process.execPath,r=t??process.argv[1]??"",s=r?Pe.resolve(r):"";return`${s?`${Ft(n)} ${Ft(s)} statusline`:"visa-cli statusline"} ${qt}`}function Wt(e){return typeof e!="string"?!1:e.includes(qt)?!0:e.includes("visa-cli")&&e.includes("statusline")}function st(e,t=Dr){let n={},r=!1;if(R.existsSync(e)){r=!0;try{n=JSON.parse(R.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 Wt(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()},Kt(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 Gt(e){if(!R.existsSync(e))return{removed:!1,message:"No ~/.claude/settings.json found."};let t;try{t=JSON.parse(R.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 Wt(n)?(delete t.statusLine,Kt(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 G=g(require("fs")),Y=g(require("path")),Ur=50,Mr=64*1024,Jt=10,ot=80;function jr(){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 it=jr(),S={reset:"\x1B[0m",visaBlue:it?"\x1B[38;2;20;52;203m":"\x1B[38;5;27m",visaBlueSoft:it?"\x1B[38;2;97;126;229m":"\x1B[38;5;111m",visaGold:it?"\x1B[38;2;247;182;0m":"\x1B[38;5;220m",green:"\x1B[38;5;48m",dim:"\x1B[2m"};function b(e,t){return e.length===0||process.env.NO_COLOR?e:`${t}${e}${S.reset}`}function zt(e){return e.replace(/\u001B\[[0-?]*[ -/]*[@-~]/g,"").replace(/[\u0000-\u001F\u007F]/g,"").length}async function Zt(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)},Ur);e.on("data",i),e.on("end",a),e.on("error",c)})}function Qt(e){let n=Math.round(Math.max(0,Math.min(1,e))*10),r="\u2588".repeat(n),s="\u2591".repeat(10-n);return`${b(r||"",S.visaBlueSoft)}${b(s||"",S.dim)}`}function Yt(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 Hr(e){let t=` ${b("\u2502",S.dim)} `,n=ee(e.model?.display_name)||"claude",r=e.cwd?ee(Y.basename(e.cwd)):"",s=Yr(e.workspace),o=r||s,i=s&&s!==o?` ${b(`@${s}`,S.visaBlueSoft)}`:"",a=[b(`[${n}]`,S.visaBlueSoft)];o&&a.push(`${b(o,S.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,d=[f?.input_tokens,f?.output_tokens,f?.cache_creation_input_tokens,f?.cache_read_input_tokens].filter(D=>typeof D=="number"&&Number.isFinite(D)),m=d.length>0?d.reduce((D,le)=>D+le,0):null,v=Number(e.context_window?.total_input_tokens??m??f?.input_tokens??0),C=u!==null?Math.max(0,Math.min(1,u/100)):l>0?Math.max(0,Math.min(1,v/l)):0,N=u!==null&&l>0?Math.round(C*l):v,$;if(l>0||u!==null){let D=`${String(Math.round(C*100)).padStart(2," ")}%`,le=l>0?` ${b(`(${Yt(N)}/${Yt(l)})`,S.dim)}`:"";$=`${b("Context",S.dim)} ${Qt(C)} ${b(D,S.green)}${le}`}else $=`${b("Context",S.dim)} ${b("-",S.dim)}`;let I=Fr(e.rate_limits),B=[$];I&&B.push(I);let H=B.join(t);return`${c}
24
- ${H}`}function Vr(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 Xt(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=Qt(r),o=n>=90?"\x1B[38;5;196m":n>=70?S.visaGold:S.green,i=`${String(Math.round(n)).padStart(2," ")}%`,a=Vr(e.resets_at),c=a?` ${b(`(${a} / ${t})`,S.dim)}`:` ${b(`(${t})`,S.dim)}`;return`${s} ${b(i,o)}${c}`}function Fr(e){if(!e)return null;let t=Xt(e.five_hour,"5h"),n=typeof e.seven_day?.used_percentage=="number"?e.seven_day.used_percentage:null,r=n!==null&&n>=90?Xt(e.seven_day,"7d"):null;if(!t&&!r)return null;let s=` ${b("\u2502",S.dim)} `,o=[t,r].filter(Boolean);return`${b("Usage",S.dim)} ${o.join(s)}`}function Br(e){let t;try{let n=G.statSync(e);if(!n.isFile())return null;let r=n.size;if(r===0)return null;let s=Math.min(r,Mr),o=r-s;t=G.openSync(e,"r");let i=Buffer.alloc(s);G.readSync(t,i,0,s,o);let a=i.toString("utf-8");if(o>0){let c=Buffer.alloc(1);if(G.readSync(t,c,0,1,o-1),c[0]!==10){let l=a.indexOf(`
25
- `);l>=0&&(a=a.slice(l+1))}}return a}catch{return null}finally{if(t!==void 0)try{G.closeSync(t)}catch{}}}function Kr(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=Y.basename(Y.dirname(s)),i=Y.basename(s);return o&&o!=="."&&o!=="/"?`${o}/${i}`:i}return s}}}function qr(e){let t=e.split(`
26
- `),n=[],r=new Set;for(let s=t.length-1;s>=0&&n.length<Jt*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 d=typeof f.id=="string"?f.id:"",m=d.length>0?!r.has(d):!1;n.push({name:f.name,target:Kr(f.input),running:m})}}}return n.reverse(),n.slice(Math.max(0,n.length-Jt))}function Wr(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 Gr(e){let t=e.running?b("\u25D0",S.visaGold):b("\u2713",S.green),n=e.running?S.visaGold:S.visaBlueSoft,r=b(ee(e.name),n),s=e.target?ee(e.target):"",o=s?`${b(":",S.dim)} ${b(s,S.dim)}`:"",i=e.count>1?` ${b(`\xD7${e.count}`,S.dim)}`:"";return o?`${t} ${r}${o}${i}`:`${t} ${r}${i}`}function Jr(e){let t=` ${b("\u2502",S.dim)} `,n=zt(t),r=e.slice();for(;r.length>0;){let c=r.join(t);if(zt(c)<=ot)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>ot-n-1?i.slice(0,ot-n-1)+s:i;return`${b(s,S.dim)}${t}${a}`}async function zr(e){if(!e||typeof e!="string")return null;let t=Br(e);if(!t)return null;let n;try{n=qr(t)}catch{return null}if(n.length===0)return null;let s=Wr(n).map(Gr);return Jr(s)||null}async function en(e,t){let n=[e];if(t){let r=Hr(t);if(r&&n.push(r),t.transcript_path){let s=await zr(t.transcript_path);s&&n.push(s)}}return n.join(`
27
- `)}function ee(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 Yr(e){if(typeof e=="string")return ee(Y.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 ee(t?Y.basename(t):e.name)}async function tn(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 Xr=/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;function rn(e,t){let n=nn(e),r=nn(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:Zr(n.pre,r.pre)>0}function nn(e){if(typeof e!="string")return null;let n=e.trim().replace(/^v/,"").match(Xr);return n?{main:[Number(n[1]),Number(n[2]),Number(n[3])],pre:n[4]??null}:null}function Zr(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 q(){return!!(sn(process.env.VISA_CLI_NO_UPDATE_CHECK)||sn(process.env.CI)||process.env.NODE_ENV==="test")}function sn(e){if(e===void 0)return!1;let t=e.trim().toLowerCase();return!(t===""||t==="0"||t==="false"||t==="no"||t==="off")}var X=g(require("fs")),cn=g(require("path"));var Te=g(require("fs")),on=g(require("path")),an=g(require("os"));var at=on.join(an.homedir(),".visa-mcp"),ue=class{static ensureConfigDir(){Te.existsSync(at)||Te.mkdirSync(at,{recursive:!0,mode:448})}static getConfigDir(){return at}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 Qr="settings.json";function Ae(){return cn.join(ue.getConfigDir(),Qr)}var de={"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 Ie(){let e=Ae();if(!X.existsSync(e))return{};try{let t=X.readFileSync(e,"utf-8"),n=JSON.parse(t);return!n||typeof n!="object"||Array.isArray(n)?{}:n}catch{return{}}}function ln(e){ue.ensureConfigDir();let t=Ae(),n=`${t}.tmp`,r=JSON.stringify(e,null,2)+`
28
- `;X.writeFileSync(n,r,{mode:384}),X.renameSync(n,t)}function ct(e){let t=Ie()[e];return typeof t=="string"?t:void 0}function un(e){let t=Ie()[e];if(typeof t=="boolean")return t;if(t==="true")return!0;if(t==="false")return!1}var re=class extends Error{constructor(t){let n=Object.keys(de).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"}},se=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"}},dn=["biometric.","spending.","account.","cards.","biometric"];function fn(e,t){if(dn.some(o=>e.startsWith(o)))throw new se(e);let n=de[e];if(!n)throw new re(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=Ie();return s[e]=r,ln(s),{key:e,value:r,requiresRestart:!!n.requiresRestart,path:Ae()}}function pn(e){if(dn.some(s=>e.startsWith(s)))throw new se(e);let t=de[e];if(!t)throw new re(e);let n=Ie(),r=e in n;return r&&(delete n[e],ln(n)),{key:e,removed:r,requiresRestart:r&&!!t.requiresRestart,path:Ae()}}var es="https://auth.visacli.sh";function gn(){let e=process.env.VISA_AUTH_URL;if(e!==void 0&&e!=="")return e;let t=ct("auth.serverUrl");return t!==void 0?t:es}var lt="1.8.0",oe=class{constructor(t){this.getSessionToken=t;this.baseUrl=gn()}getSessionToken;baseUrl;lastSignals={};parseServerSignals(t){if(this.lastSignals={},!q()){let r=t.headers.get("X-Latest-Version"),s=t.headers.get("X-Update-Message");r&&rn(r,lt)&&(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 lt}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 tn(`${this.baseUrl}${n}`,{method:t,headers:{...a,"X-Visa-CLI-Version":lt},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.`):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 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 gt=require("child_process"),bn=require("util"),wn=g(require("crypto")),E=g(require("fs")),_n=g(require("os")),W=g(require("path"));var P=g(require("fs")),ft=g(require("path")),mn=g(require("os")),dt=ft.join(mn.homedir(),".visa-mcp"),fe=ft.join(dt,"mcp-server.log"),ts=5*1024*1024,ut=null;function ns(){P.existsSync(dt)||P.mkdirSync(dt,{recursive:!0,mode:448})}function rs(){if(!ut){if(ns(),P.existsSync(fe)&&P.statSync(fe).size>ts){let t=fe+".1";P.existsSync(t)&&P.unlinkSync(t),P.renameSync(fe,t)}ut=P.createWriteStream(fe,{flags:"a"})}return ut}function Le(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}
29
- `;process.stderr.write(s),rs().write(s)}var ie={debug:(...e)=>Le("DEBUG",...e),info:(...e)=>Le("INFO",...e),warn:(...e)=>Le("WARN",...e),error:(...e)=>Le("ERROR",...e)};var ae=(0,bn.promisify)(gt.execFile),De=W.join(_n.homedir(),".visa-mcp","bin"),te=W.join(De,"Visa CLI"),ss=W.join(__dirname,"..","native"),hn="5",yn=W.join(De,"visa-keychain.version"),Sn=W.join(De,"visa-keychain.sha256");function vn(e){let t=E.readFileSync(e);return wn.createHash("sha256").update(t).digest("hex")}async function Cn(){try{if(E.readFileSync(yn,"utf-8").trim()===hn&&E.existsSync(te)){let r=E.readFileSync(Sn,"utf-8").trim();if(vn(te)!==r)ie.warn("binary:hash-mismatch",{message:"Binary hash mismatch \u2014 possible tampering detected. Recompiling from source."}),E.unlinkSync(te);else return te}}catch{}let e=W.join(ss,"visa-keychain.m");if(E.existsSync(e)||(e=W.resolve(__dirname,"..","..","native","visa-keychain.m")),E.existsSync(e)||(e=W.resolve(__dirname,"..","native","visa-keychain.m")),!E.existsSync(e))throw new Error("visa-keychain.m source not found. Reinstall Visa CLI.");E.mkdirSync(De,{recursive:!0,mode:448});try{await ae("clang",["-framework","Security","-framework","LocalAuthentication","-framework","Foundation","-framework","AppKit","-o",te,e],{timeout:3e4})}catch(n){throw n.code==="ENOENT"?new Error("Xcode Command Line Tools required. Install: xcode-select --install"):n}let t=vn(te);return E.writeFileSync(Sn,t,{mode:384}),E.writeFileSync(yn,hn,{mode:384}),te}async function kn(e){let t=await Cn(),n;try{n=(await ae(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 pt=null;function T(){return process.env.VISA_MOCK_TOUCHID==="true"?!0:process.platform!=="darwin"?!1:pt!==null?pt:(pt=!0,!0)}var Oe="visa-cli",Ne="attestation-key";async function os(e){try{await ae("security",["delete-generic-password","-s",Oe,"-a",Ne],{timeout:5e3})}catch{}await ae("security",["add-generic-password","-s",Oe,"-a",Ne,"-w",e],{timeout:5e3})}async function is(){try{let{stdout:e}=await ae("security",["find-generic-password","-s",Oe,"-a",Ne,"-w"],{timeout:5e3});return e.trim()||null}catch{return null}}async function Ue(){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 os(n),r}async function mt(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 Cn(),s=["sign",e];return t&&s.push(t),new Promise((o,i)=>{let a=(0,gt.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 $n(){try{await ae("security",["delete-generic-password","-s",Oe,"-a",Ne],{timeout:5e3})}catch{}try{await kn(["delete-key"])}catch{}}function En(e,t=process.stderr){if(q()||!e?.updateAvailable)return!1;let{message:n}=e.updateAvailable;return n?(t.write(`
21
+ `),process.exit(1)}var Kt=require("child_process");function Hr(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 Vr(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 Fr(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 qt(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,Kt.execFile)(c,l,d=>u(d))});n(""),n(" Sign in to Visa CLI by opening this URL in your browser:"),n("");for(let c of Vr(e).split(`
23
+ `))n(` ${c}`);n("");let i=Hr(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=Fr(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 Gt=g(require("crypto")),I=g(require("fs")),Ie=g(require("path"));function Jt(e,t){I.mkdirSync(Ie.dirname(e),{recursive:!0});let n=`${e}.${process.pid}.${Gt.randomBytes(8).toString("hex")}.tmp`;try{I.writeFileSync(n,JSON.stringify(t,null,2)+`
24
+ `),I.renameSync(n,e)}catch(r){try{I.unlinkSync(n)}catch{}throw r}}function Wt(e){return`'${e.replace(/'/g,"'\\''")}'`}var zt="# visa-cli-hud-v1";function Br(e,t){let n=e??process.execPath,r=t??process.argv[1]??"",s=r?Ie.resolve(r):"";return`${s?`${Wt(n)} ${Wt(s)} statusline`:"visa-cli statusline"} ${zt}`}function Yt(e){return typeof e!="string"?!1:e.includes(zt)?!0:e.includes("visa-cli")&&e.includes("statusline")}function at(e,t=Br){let n={},r=!1;if(I.existsSync(e)){r=!0;try{n=JSON.parse(I.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 Yt(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()},Jt(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 Xt(e){if(!I.existsSync(e))return{removed:!1,message:"No ~/.claude/settings.json found."};let t;try{t=JSON.parse(I.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 Yt(n)?(delete t.statusLine,Jt(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 W=g(require("fs")),X=g(require("path")),Kr=50,qr=64*1024,Zt=10,ct=80;function Wr(){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=Wr(),v={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 _(e,t){return e.length===0||process.env.NO_COLOR?e:`${t}${e}${v.reset}`}function Qt(e){return e.replace(/\u001B\[[0-?]*[ -/]*[@-~]/g,"").replace(/[\u0000-\u001F\u007F]/g,"").length}async function nn(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 d=JSON.parse(u);o(d&&typeof d=="object"?d:null)}catch{o(null)}},c=()=>o(null),l=setTimeout(()=>{n.length>0?a():o(null)},Kr);e.on("data",i),e.on("end",a),e.on("error",c)})}function rn(e){let n=Math.round(Math.max(0,Math.min(1,e))*10),r="\u2588".repeat(n),s="\u2591".repeat(10-n);return`${_(r||"",v.visaBlueSoft)}${_(s||"",v.dim)}`}function en(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 Gr(e){let t=` ${_("\u2502",v.dim)} `,n=te(e.model?.display_name)||"claude",r=e.cwd?te(X.basename(e.cwd)):"",s=rs(e.workspace),o=r||s,i=s&&s!==o?` ${_(`@${s}`,v.visaBlueSoft)}`:"",a=[_(`[${n}]`,v.visaBlueSoft)];o&&a.push(`${_(o,v.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,d=e.context_window?.current_usage,y=[d?.input_tokens,d?.output_tokens,d?.cache_creation_input_tokens,d?.cache_read_input_tokens].filter(R=>typeof R=="number"&&Number.isFinite(R)),b=y.length>0?y.reduce((R,J)=>R+J,0):null,C=Number(e.context_window?.total_input_tokens??b??d?.input_tokens??0),f=u!==null?Math.max(0,Math.min(1,u/100)):l>0?Math.max(0,Math.min(1,C/l)):0,S=u!==null&&l>0?Math.round(f*l):C,w;if(l>0||u!==null){let R=`${String(Math.round(f*100)).padStart(2," ")}%`,J=l>0?` ${_(`(${en(S)}/${en(l)})`,v.dim)}`:"";w=`${_("Context",v.dim)} ${rn(f)} ${_(R,v.green)}${J}`}else w=`${_("Context",v.dim)} ${_("-",v.dim)}`;let x=zr(e.rate_limits),P=[w];x&&P.push(x);let G=P.join(t);return`${c}
25
+ ${G}`}function Jr(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 tn(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=rn(r),o=n>=90?"\x1B[38;5;196m":n>=70?v.visaGold:v.green,i=`${String(Math.round(n)).padStart(2," ")}%`,a=Jr(e.resets_at),c=a?` ${_(`(${a} / ${t})`,v.dim)}`:` ${_(`(${t})`,v.dim)}`;return`${s} ${_(i,o)}${c}`}function zr(e){if(!e)return null;let t=tn(e.five_hour,"5h"),n=typeof e.seven_day?.used_percentage=="number"?e.seven_day.used_percentage:null,r=n!==null&&n>=90?tn(e.seven_day,"7d"):null;if(!t&&!r)return null;let s=` ${_("\u2502",v.dim)} `,o=[t,r].filter(Boolean);return`${_("Usage",v.dim)} ${o.join(s)}`}function Yr(e){let t;try{let n=W.statSync(e);if(!n.isFile())return null;let r=n.size;if(r===0)return null;let s=Math.min(r,qr),o=r-s;t=W.openSync(e,"r");let i=Buffer.alloc(s);W.readSync(t,i,0,s,o);let a=i.toString("utf-8");if(o>0){let c=Buffer.alloc(1);if(W.readSync(t,c,0,1,o-1),c[0]!==10){let l=a.indexOf(`
26
+ `);l>=0&&(a=a.slice(l+1))}}return a}catch{return null}finally{if(t!==void 0)try{W.closeSync(t)}catch{}}}function Xr(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 Zr(e){let t=e.split(`
27
+ `),n=[],r=new Set;for(let s=t.length-1;s>=0&&n.length<Zt*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 d=u;if(d.type==="tool_result"&&typeof d.tool_use_id=="string")r.add(d.tool_use_id);else if(d.type==="tool_use"&&typeof d.name=="string"){let y=typeof d.id=="string"?d.id:"",b=y.length>0?!r.has(y):!1;n.push({name:d.name,target:Xr(d.input),running:b})}}}return n.reverse(),n.slice(Math.max(0,n.length-Zt))}function Qr(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 es(e){let t=e.running?_("\u25D0",v.visaGold):_("\u2713",v.green),n=e.running?v.visaGold:v.visaBlueSoft,r=_(te(e.name),n),s=e.target?te(e.target):"",o=s?`${_(":",v.dim)} ${_(s,v.dim)}`:"",i=e.count>1?` ${_(`\xD7${e.count}`,v.dim)}`:"";return o?`${t} ${r}${o}${i}`:`${t} ${r}${i}`}function ts(e){let t=` ${_("\u2502",v.dim)} `,n=Qt(t),r=e.slice();for(;r.length>0;){let c=r.join(t);if(Qt(c)<=ct)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>ct-n-1?i.slice(0,ct-n-1)+s:i;return`${_(s,v.dim)}${t}${a}`}async function ns(e){if(!e||typeof e!="string")return null;let t=Yr(e);if(!t)return null;let n;try{n=Zr(t)}catch{return null}if(n.length===0)return null;let s=Qr(n).map(es);return ts(s)||null}async function sn(e,t){let n=[e];if(t){let r=Gr(t);if(r&&n.push(r),t.transcript_path){let s=await ns(t.transcript_path);s&&n.push(s)}}return n.join(`
28
+ `)}function te(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 rs(e){if(typeof e=="string")return te(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 te(t?X.basename(t):e.name)}async function on(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 ss=/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;function cn(e,t){let n=an(e),r=an(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:os(n.pre,r.pre)>0}function an(e){if(typeof e!="string")return null;let n=e.trim().replace(/^v/,"").match(ss);return n?{main:[Number(n[1]),Number(n[2]),Number(n[3])],pre:n[4]??null}:null}function os(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 K(){return!!(ln(process.env.VISA_CLI_NO_UPDATE_CHECK)||ln(process.env.CI)||process.env.NODE_ENV==="test")}function ln(e){if(e===void 0)return!1;let t=e.trim().toLowerCase();return!(t===""||t==="0"||t==="false"||t==="no"||t==="off")}var Z=g(require("fs")),fn=g(require("path"));var Le=g(require("fs")),un=g(require("path")),dn=g(require("os"));var ut=un.join(dn.homedir(),".visa-mcp"),pe=class{static ensureConfigDir(){Le.existsSync(ut)||Le.mkdirSync(ut,{recursive:!0,mode:448})}static getConfigDir(){return ut}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 is="settings.json";function Oe(){return fn.join(pe.getConfigDir(),is)}var ge={"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 Ne(){let e=Oe();if(!Z.existsSync(e))return{};try{let t=Z.readFileSync(e,"utf-8"),n=JSON.parse(t);return!n||typeof n!="object"||Array.isArray(n)?{}:n}catch{return{}}}function pn(e){pe.ensureConfigDir();let t=Oe(),n=`${t}.tmp`,r=JSON.stringify(e,null,2)+`
29
+ `;Z.writeFileSync(n,r,{mode:384}),Z.renameSync(n,t)}function dt(e){let t=Ne()[e];return typeof t=="string"?t:void 0}function gn(e){let t=Ne()[e];if(typeof t=="boolean")return t;if(t==="true")return!0;if(t==="false")return!1}var oe=class extends Error{constructor(t){let n=Object.keys(ge).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"}},ie=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"}},mn=["biometric.","spending.","account.","cards.","biometric"];function hn(e,t){if(mn.some(o=>e.startsWith(o)))throw new ie(e);let n=ge[e];if(!n)throw new oe(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=Ne();return s[e]=r,pn(s),{key:e,value:r,requiresRestart:!!n.requiresRestart,path:Oe()}}function yn(e){if(mn.some(s=>e.startsWith(s)))throw new ie(e);let t=ge[e];if(!t)throw new oe(e);let n=Ne(),r=e in n;return r&&(delete n[e],pn(n)),{key:e,removed:r,requiresRestart:r&&!!t.requiresRestart,path:Oe()}}var as="https://auth.visacli.sh";function Sn(){let e=process.env.VISA_AUTH_URL;if(e!==void 0&&e!=="")return e;let t=dt("auth.serverUrl");return t!==void 0?t:as}var ft="1.9.0-rc.0",ae=class{constructor(t){this.getSessionToken=t;this.baseUrl=Sn()}getSessionToken;baseUrl;lastSignals={};parseServerSignals(t){if(this.lastSignals={},!K()){let r=t.headers.get("X-Latest-Version"),s=t.headers.get("X-Update-Message");r&&cn(r,ft)&&(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 ft}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 on(`${this.baseUrl}${n}`,{method:t,headers:{...a,"X-Visa-CLI-Version":ft},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.`):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 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 yt=require("child_process"),kn=require("util"),$n=g(require("crypto")),T=g(require("fs")),En=g(require("os")),q=g(require("path"));var L=g(require("fs")),mt=g(require("path")),vn=g(require("os")),gt=mt.join(vn.homedir(),".visa-mcp"),me=mt.join(gt,"mcp-server.log"),cs=5*1024*1024,pt=null;function ls(){L.existsSync(gt)||L.mkdirSync(gt,{recursive:!0,mode:448})}function us(){if(!pt){if(ls(),L.existsSync(me)&&L.statSync(me).size>cs){let t=me+".1";L.existsSync(t)&&L.unlinkSync(t),L.renameSync(me,t)}pt=L.createWriteStream(me,{flags:"a"})}return pt}function De(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}
30
+ `;process.stderr.write(s),us().write(s)}var ce={debug:(...e)=>De("DEBUG",...e),info:(...e)=>De("INFO",...e),warn:(...e)=>De("WARN",...e),error:(...e)=>De("ERROR",...e)};var le=(0,kn.promisify)(yt.execFile),je=q.join(En.homedir(),".visa-mcp","bin"),ne=q.join(je,"Visa CLI"),ds=q.join(__dirname,"..","native"),bn="5",wn=q.join(je,"visa-keychain.version"),_n=q.join(je,"visa-keychain.sha256");function Cn(e){let t=T.readFileSync(e);return $n.createHash("sha256").update(t).digest("hex")}async function xn(){try{if(T.readFileSync(wn,"utf-8").trim()===bn&&T.existsSync(ne)){let r=T.readFileSync(_n,"utf-8").trim();if(Cn(ne)!==r)ce.warn("binary:hash-mismatch",{message:"Binary hash mismatch \u2014 possible tampering detected. Recompiling from source."}),T.unlinkSync(ne);else return ne}}catch{}let e=q.join(ds,"visa-keychain.m");if(T.existsSync(e)||(e=q.resolve(__dirname,"..","..","native","visa-keychain.m")),T.existsSync(e)||(e=q.resolve(__dirname,"..","native","visa-keychain.m")),!T.existsSync(e))throw new Error("visa-keychain.m source not found. Reinstall Visa CLI.");T.mkdirSync(je,{recursive:!0,mode:448});try{await le("clang",["-framework","Security","-framework","LocalAuthentication","-framework","Foundation","-framework","AppKit","-o",ne,e],{timeout:3e4})}catch(n){throw n.code==="ENOENT"?new Error("Xcode Command Line Tools required. Install: xcode-select --install"):n}let t=Cn(ne);return T.writeFileSync(_n,t,{mode:384}),T.writeFileSync(wn,bn,{mode:384}),ne}async function Rn(e){let t=await xn(),n;try{n=(await le(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 ht=null;function O(){return process.env.VISA_MOCK_TOUCHID==="true"?!0:process.platform!=="darwin"?!1:ht!==null?ht:(ht=!0,!0)}var Me="visa-cli",Ue="attestation-key";async function fs(e){try{await le("security",["delete-generic-password","-s",Me,"-a",Ue],{timeout:5e3})}catch{}await le("security",["add-generic-password","-s",Me,"-a",Ue,"-w",e],{timeout:5e3})}async function ps(){try{let{stdout:e}=await le("security",["find-generic-password","-s",Me,"-a",Ue,"-w"],{timeout:5e3});return e.trim()||null}catch{return null}}async function He(){let e=await Rn(["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 fs(n),r}async function St(e,t){if(process.env.VISA_MOCK_TOUCHID==="true")return Promise.resolve("mock-ecdsa-signature-for-testing");let n=await ps();if(!n)throw new Error("Attestation key not found. Run setup to generate a new key.");let r=await xn(),s=["sign",e];return t&&s.push(t),new Promise((o,i)=>{let a=(0,yt.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 Pn(){try{await le("security",["delete-generic-password","-s",Me,"-a",Ue],{timeout:5e3})}catch{}try{await Rn(["delete-key"])}catch{}}function Tn(e,t=process.stderr){if(K()||!e?.updateAvailable)return!1;let{message:n}=e.updateAvailable;return n?(t.write(`
30
31
  \x1B[33m\u2191 ${n}\x1B[0m
31
- `),!0):!1}function Rn(e,t,n,r){let s=r.currentVersion==="0.0.0"&&e.version?e.version:r.currentVersion,i=ps(e.spendingControls).dailyLimit,a=Math.max(0,pe(e.dailySpent)),c=i>0?Math.min(i,Math.max(0,pe(e.dailyRemaining??i-a))):0,l=i>0?Math.min(1,a/i):0,f=(Array.isArray(t)?t:[]).filter(ls),d=f.slice(0,3),m=us(f,3),v=(e.cards??[]).slice(0,3),C=r.latestVersion?yt(r.latestVersion):"",N=r.updateCheckDisabled?"update checks disabled":C?`update available: v${C}`:"up to date",$=Math.round(l*100),I=Z(e.status,e.enrolled?"approved":"not enrolled"),H=["VISA CLI",`Status: ${e.enrolled?"Visa ready":"Visa setup needed"} | account: ${I} | touch id: ${n?"ready":"unavailable"}`,`Version: v${s} | ${N}`,`Spend meter: ${xn(l)} ${String($).padStart(3," ")}% | remaining ${ce(c)}/day | daily cap ${ce(i)}`,"","Spend",` Remaining ${ce(c)} / ${ce(i)}`,` Usage ${xn(l)} ${$}%`,` Spent today ${ce(a)}`,` Attestation key ${e.hasAttestationKey?"registered":"missing"}`,"","Cards",...v.length>0?v.map(D=>` ${fs(D)}`):[" No cards enrolled"],"","Last 3 services",...m.length>0?m.map((D,le)=>` ${le+1}. ${D}`):[" No paid services yet"],"","Recent receipts",...d.length>0?d.map(D=>` ${ds(D)}`):[" No receipts yet"]];return r.updateMessage&&H.push("",`Update: ${yt(r.updateMessage)}`),`${H.join(`
32
+ `),!0):!1}function In(e,t,n,r){let s=r.currentVersion==="0.0.0"&&e.version?e.version:r.currentVersion,i=bs(e.spendingControls).dailyLimit,a=Math.max(0,he(e.dailySpent)),c=i>0?Math.min(i,Math.max(0,he(e.dailyRemaining??i-a))):0,l=i>0?Math.min(1,a/i):0,d=(Array.isArray(t)?t:[]).filter(hs),y=d.slice(0,3),b=ys(d,3),C=(e.cards??[]).slice(0,3),f=r.latestVersion?bt(r.latestVersion):"",S=r.updateCheckDisabled?"update checks disabled":f?`update available: v${f}`:"up to date",w=Math.round(l*100),x=Q(e.status,e.enrolled?"approved":"not enrolled"),G=["VISA CLI",`Status: ${e.enrolled?"Visa ready":"Visa setup needed"} | account: ${x} | touch id: ${n?"ready":"unavailable"}`,`Version: v${s} | ${S}`,`Spend meter: ${An(l)} ${String(w).padStart(3," ")}% | remaining ${ue(c)}/day | daily cap ${ue(i)}`,"","Spend",` Remaining ${ue(c)} / ${ue(i)}`,` Usage ${An(l)} ${w}%`,` Spent today ${ue(a)}`,` Attestation key ${e.hasAttestationKey?"registered":"missing"}`,"","Cards",...C.length>0?C.map(R=>` ${vs(R)}`):[" No cards enrolled"],"","Last 3 services",...b.length>0?b.map((R,J)=>` ${J+1}. ${R}`):[" No paid services yet"],"","Recent receipts",...y.length>0?y.map(R=>` ${Ss(R)}`):[" No receipts yet"]];return r.updateMessage&&G.push("",`Update: ${bt(r.updateMessage)}`),`${G.join(`
32
33
  `)}
33
- `}function as(e){return e.tool_name!=null}function cs(e){return pe(e.amount)===0&&e.status==="failed"}function ls(e){return as(e)&&!cs(e)}function us(e,t=1/0){let n=new Set,r=[];for(let s of e){if(r.length>=t)break;let o=Z(s.merchant_name,"Unknown merchant"),i=Z(s.tool_name,"unknown_tool"),a=`${o} :: ${i}`;n.has(a)||(n.add(a),r.push(`${o} [${i}]`))}return r}function ds(e){let t=Z(e.merchant_name,"Unknown merchant"),n=Z(e.tool_name,"unknown_tool"),r=ce(pe(e.amount)),s=Z(e.status,"unknown"),o=gs(e.created_at);return`${r} ${s.padEnd(9)} ${t} [${n}] ${o}`}function fs(e){let t=Z(e.brand?.toUpperCase(),"CARD"),n=e.isDefault?" default":"";return`${Number.isInteger(e.id)?`#${e.id} `:""}${t} ****${e.last4}${n}`}function ps(e){return{dailyLimit:pe(e?.daily_limit??e?.dailyLimit??0)}}function pe(e){let t=Number(typeof e=="string"?e:e??0);return Number.isFinite(t)?t:0}function ce(e){return`$${e.toFixed(2)}`}function xn(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 Z(e,t){let n=yt(e??"").trim();return n.length>0?n:t}function gs(e){if(!e)return"unknown time";let t=new Date(e);return Number.isNaN(t.getTime())?Z(e,"unknown time"):t.toISOString().slice(0,16).replace("T"," ")}function yt(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 y=g(require("fs")),Fe=g(require("os")),w=g(require("path")),Tn=require("child_process"),ms=2,Me="# >>> visa-cli shell hud v2 >>>",je="# <<< visa-cli shell hud v2 <<<",hs="# >>> visa-cli shell hud >>>",ys="# <<< visa-cli shell hud <<<",An=3e4,Ss=3e4;function wt(){try{return w.join(Mn(),".visa-cli")}catch{return w.join(Fe.tmpdir(),".visa-cli")}}function me(){return w.join(wt(),"shell-hud.json")}function Be(){return w.join(wt(),"shell-hud.line")}function In(){return w.join(wt(),"shell-hud.lock")}function Ke(e){let t=e??process.env.SHELL;if(!t)return null;let n=w.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=Mn();if(e==="zsh")return w.join(t,".zshrc");if(e==="bash")return w.join(t,".bashrc");let n=(process.platform==="win32","PowerShell");return w.join(t,"Documents",n,"Microsoft.PowerShell_profile.ps1")}function vs(e){let t="$HOME/.visa-cli/shell-hud.line",n=$s(e),r=Es(e);if(e==="zsh")return`${Me}
34
+ `}function gs(e){return e.tool_name!=null}function ms(e){return he(e.amount)===0&&e.status==="failed"}function hs(e){return gs(e)&&!ms(e)}function ys(e,t=1/0){let n=new Set,r=[];for(let s of e){if(r.length>=t)break;let o=Q(s.merchant_name,"Unknown merchant"),i=Q(s.tool_name,"unknown_tool"),a=`${o} :: ${i}`;n.has(a)||(n.add(a),r.push(`${o} [${i}]`))}return r}function Ss(e){let t=Q(e.merchant_name,"Unknown merchant"),n=Q(e.tool_name,"unknown_tool"),r=ue(he(e.amount)),s=Q(e.status,"unknown"),o=ws(e.created_at);return`${r} ${s.padEnd(9)} ${t} [${n}] ${o}`}function vs(e){let t=Q(e.brand?.toUpperCase(),"CARD"),n=e.isDefault?" default":"";return`${Number.isInteger(e.id)?`#${e.id} `:""}${t} ****${e.last4}${n}`}function bs(e){return{dailyLimit:he(e?.daily_limit??e?.dailyLimit??0)}}function he(e){let t=Number(typeof e=="string"?e:e??0);return Number.isFinite(t)?t:0}function ue(e){return`$${e.toFixed(2)}`}function An(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 Q(e,t){let n=bt(e??"").trim();return n.length>0?n:t}function ws(e){if(!e)return"unknown time";let t=new Date(e);return Number.isNaN(t.getTime())?Q(e,"unknown time"):t.toISOString().slice(0,16).replace("T"," ")}function bt(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 h=g(require("fs")),qe=g(require("os")),$=g(require("path")),On=require("child_process"),_s=2,Ve="# >>> visa-cli shell hud v2 >>>",Fe="# <<< visa-cli shell hud v2 <<<",Cs="# >>> visa-cli shell hud >>>",ks="# <<< visa-cli shell hud <<<",Nn=3e4,$s=3e4;function kt(){try{return $.join(Fn(),".visa-cli")}catch{return $.join(qe.tmpdir(),".visa-cli")}}function Se(){return $.join(kt(),"shell-hud.json")}function We(){return $.join(kt(),"shell-hud.line")}function Dn(){return $.join(kt(),"shell-hud.lock")}function Ge(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 Je(e){let t=Fn();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 Es(e){let t="$HOME/.visa-cli/shell-hud.line",n=Is(e),r=Ls(e);if(e==="zsh")return`${Ve}
34
35
  _visa_cli_shell_hud_precmd() {
35
36
  setopt localoptions no_bg_nice
36
37
  if [[ -f "${t}" ]]; then
@@ -47,7 +48,7 @@ autoload -Uz add-zsh-hook
47
48
  if [[ -z "\${precmd_functions[(r)_visa_cli_shell_hud_precmd]}" ]]; then
48
49
  add-zsh-hook precmd _visa_cli_shell_hud_precmd
49
50
  fi
50
- ${je}`;if(e==="powershell"){let s="(Join-Path $HOME '.visa-cli/shell-hud.line')";return`${Me}
51
+ ${Fe}`;if(e==="powershell"){let s="(Join-Path $HOME '.visa-cli/shell-hud.line')";return`${Ve}
51
52
  if (-not (Test-Path Function:\\global:__visa_cli_original_prompt)) {
52
53
  $function:global:__visa_cli_original_prompt = if (Test-Path Function:\\prompt) { $function:prompt } else { { '' } }
53
54
  }
@@ -66,7 +67,7 @@ function global:prompt {
66
67
  }
67
68
  & $function:global:__visa_cli_original_prompt
68
69
  }
69
- ${je}`}return`${Me}
70
+ ${Fe}`}return`${Ve}
70
71
  __visa_cli_shell_hud_precmd() {
71
72
  if [ -f "${t}" ]; then
72
73
  cat "${t}"
@@ -83,35 +84,37 @@ case ";$PROMPT_COMMAND;" in
83
84
  *";__visa_cli_shell_hud_precmd;"*) ;;
84
85
  *) PROMPT_COMMAND="__visa_cli_shell_hud_precmd\${PROMPT_COMMAND:+;$PROMPT_COMMAND}" ;;
85
86
  esac
86
- ${je}`}function Ln(e){let t=e;for(let[n,r]of[[Me,je],[hs,ys]])t=t.replace(new RegExp(`\\n?${Pn(n)}[\\s\\S]*?${Pn(r)}\\n?`,"g"),"");return t.trimEnd()}function bs(e,t){let n=Ln(e).trimEnd(),r=vs(t);return n.length>0?`${n}
87
+ ${Fe}`}function Mn(e){let t=e;for(let[n,r]of[[Ve,Fe],[Cs,ks]])t=t.replace(new RegExp(`\\n?${Ln(n)}[\\s\\S]*?${Ln(r)}\\n?`,"g"),"");return t.trimEnd()}function xs(e,t){let n=Mn(e).trimEnd(),r=Es(t);return n.length>0?`${n}
87
88
 
88
89
  ${r}
89
90
  `:`${r}
90
- `}function On(e=Ke()){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=y.existsSync(t)?y.readFileSync(t,"utf-8"):"",r=bs(n,e),s=r!==n;return s&&Ve(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}: ${jn(n)}`}}}function Nn(e=Ke()){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),!y.existsSync(t))return{removed:!1,shell:e,rcPath:t,message:`No ${e} rc file found at ${t}.`};let n=y.readFileSync(t,"utf-8"),r=Ln(n);return r===n.trimEnd()?{removed:!1,shell:e,rcPath:t,message:`Persistent shell HUD was not installed in ${t}.`}:(Ve(t,r.length>0?`${r}
91
- `:""),{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}: ${jn(n)}`}}}function _t(e,t){let n=t.currentVersion==="0.0.0"&&e.version?e.version:t.currentVersion,r=He(n),s=` ${M("\u2502",L.dim)} `;if(!e.enrolled)return`${M("VISA CLI",L.visaBlue)} ${M(`v${r}`,L.visaBlueSoft)}${s}${M("setup needed",L.visaGold)}`;let o=St(e.spendingControls?.daily_limit??e.spendingControls?.dailyLimit),i=Math.max(0,St(e.dailySpent)),a=o>0?Math.min(o,Math.max(0,St(e.dailyRemaining??o-i))):0,c=o>0?Math.max(0,Math.min(1,i/o)):0,l=Cs(e),u=o>0?`${_s(c)} ${M(`${vt(a)} left today`,L.green)} ${M(`(${vt(i)}/${vt(o)}/day)`,L.dim)}`:M("no spend limit",L.dim);return`${M("VISA CLI",L.visaBlue)} ${M(`v${r}`,L.visaBlueSoft)}${s}${M(l,L.visaGold)}${s}${u}`}function Dn(){let e=Un();return!!e&&Date.now()-e.renderedAt<=An}function Ct(){let e=Un();if(e&&Date.now()-e.renderedAt<=An||(ws(),e?.line))return e.line;try{let t=Be();if(y.existsSync(t))return y.readFileSync(t,"utf-8").trimEnd()}catch{}return"VISA | loading spend HUD\u2026"}function kt(e){try{let t=w.dirname(me());y.mkdirSync(t,{recursive:!0});let n=He(e),r={hudVersion:ms,renderedAt:Date.now(),line:n};Ve(me(),JSON.stringify(r)+`
92
- `),Ve(Be(),n+`
93
- `)}catch{}}function ge(){try{y.unlinkSync(In())}catch{}}function Un(){let e=me();if(!y.existsSync(e))return null;try{return JSON.parse(y.readFileSync(e,"utf-8"))}catch{return null}}function ws(){if(process.env.JEST_WORKER_ID)return;let e=In();try{if(y.mkdirSync(w.dirname(e),{recursive:!0}),!xs(e))return;let t=process.argv[1]?w.resolve(process.argv[1]):"";if(!t){ge();return}let n=(0,Tn.spawn)(process.execPath,[t,"shell-hud","refresh"],{detached:!0,stdio:"ignore",env:{...process.env,VISA_CLI_SHELL_HUD_BACKGROUND:"1"}});n.once("error",ge),n.unref()}catch{ge()}}function St(e){let t=Number(typeof e=="string"?e:e??0);return Number.isFinite(t)?t:0}function He(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 _s(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||"",L.green)}${M(s||"",L.dim)}`}function vt(e){return`$${e.toFixed(2)}`}function Cs(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=He(n.toUpperCase()),o=He(r);return`${t.isDefault?"default":"active"} ${s} ****${o}`}function ks(){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 bt=ks(),L={reset:"\x1B[0m",visaBlue:bt?"\x1B[38;2;20;52;203m":"\x1B[38;5;27m",visaBlueSoft:bt?"\x1B[38;2;97;126;229m":"\x1B[38;5;111m",visaGold:bt?"\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}${L.reset}`}function Pn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Mn(){let e=Fe.homedir();if(!e||!w.isAbsolute(e))throw new Error("unable to determine a valid home directory");return w.resolve(e)}function $s(e){return e==="powershell"?"& visa-cli shell-hud refresh":"visa-cli shell-hud refresh"}function Es(e){return e==="powershell"?"Get-Command visa-cli -ErrorAction SilentlyContinue -CommandType Application":"command -v visa-cli >/dev/null 2>&1"}function xs(e){for(let t=0;t<2;t+=1){let n;try{return n=y.openSync(e,"wx"),y.writeFileSync(n,String(Date.now())),!0}catch(r){if(r?.code!=="EEXIST")return!1;try{let s=y.statSync(e);if(Date.now()-s.mtimeMs<=Ss)return!1;y.unlinkSync(e)}catch{}}finally{n!==void 0&&y.closeSync(n)}}return!1}function jn(e){return e instanceof Error?e.message:"unknown file system error"}function Ve(e,t){y.mkdirSync(w.dirname(e),{recursive:!0});let n=`${e}.${process.pid}.${Date.now()}.tmp`;y.writeFileSync(n,t),y.renameSync(n,e)}async function $t(e,t){try{return await t()}catch(n){if(n.message==="Invalid signature"&&T()){ie.warn("attestation:key-mismatch",{action:"reregistering"});try{let r=await Ue();await e.registerAttestationKey(r),ie.info("attestation:key-reregistered")}catch(r){throw ie.error("attestation:reregister-failure",{error:r.message}),n}return await t()}throw n}}var Hn="1.8.0";function Et(e,t){return t?{kind:"env",var:e}:{kind:"default"}}function Rs(e,t,n){let r=process.env[e];if(r!==void 0&&r!=="")return{value:r,source:{kind:"env",var:e}};let s=ct(t);return s!==void 0?{value:s,source:{kind:"settings"}}:{value:n,source:{kind:"default"}}}function he(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=un(t);return s!==void 0?{value:s,source:{kind:"settings"}}:{value:n!=="opt-in",source:{kind:"default"}}}function O(e){return e==null?"\u2014":e?"yes":"no"}function We(e){return e==null?"\u2014":`$${e.toFixed(2)}`}async function Vn(e){let t=null,n=null;try{t=await e.api.getStatus()}catch($){n=$?.message||"unknown error"}let r=[],s=Rs("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:O(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:O(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:O(t?.hasAttestationKey),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}}),r.push({key:"biometric.deviceAvailable",value:T(),formatted:O(T()),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:We(a),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}}),r.push({key:"spending.dailyLimit",value:c,formatted:We(c),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}}),r.push({key:"spending.dailySpent",value:t?.dailySpent??null,formatted:We(t?.dailySpent),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}}),r.push({key:"spending.dailyRemaining",value:t?.dailyRemaining??null,formatted:We(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($=>$.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=he("VISA_SUPPRESS_BROWSER","ui.suppressBrowser","opt-in");r.push({key:"ui.suppressBrowser",value:u.value,formatted:O(u.value),source:u.source,hint:"Persist with `visa-cli config set ui.suppressBrowser true` to stop auto-opening result URLs."});let f=he("VISA_SUPPRESS_FEED","ui.suppressFeed","opt-in");r.push({key:"ui.suppressFeed",value:f.value,formatted:O(f.value),source:f.source});let d=q(),m;process.env.VISA_CLI_NO_UPDATE_CHECK?m={kind:"env",var:"VISA_CLI_NO_UPDATE_CHECK"}:process.env.CI?m={kind:"env",var:"CI"}:process.env.NODE_ENV==="test"?m={kind:"env",var:"NODE_ENV"}:m={kind:"default"},r.push({key:"ui.updateCheck",value:!d,formatted:O(!d),source:m});let v=he("VISA_META_TOOLS","tools.meta","opt-out");r.push({key:"tools.meta",value:v.value,formatted:O(v.value),source:v.source,hint:"Persist with `visa-cli config set tools.meta false`. Restart Claude Code for changes to take effect."});let C=he("VISA_SPECIFIC_TOOLS","tools.specific","opt-out");r.push({key:"tools.specific",value:C.value,formatted:O(C.value),source:C.source});let N=he("VISA_DISCOVER_TOOLS","tools.discover","opt-out");if(r.push({key:"tools.discover",value:N.value,formatted:O(N.value),source:N.source}),r.push({key:"client.version",value:Hn,formatted:Hn,source:{kind:"default"}}),e.includeDev){let $=process.env.VISA_MOCK_KEYCHAIN;r.push({key:"dev.mockKeychain",value:$==="true",formatted:O($==="true"),source:Et("VISA_MOCK_KEYCHAIN",!!$)});let I=process.env.VISA_MOCK_TOUCHID;r.push({key:"dev.mockTouchid",value:I==="true",formatted:O(I==="true"),source:Et("VISA_MOCK_TOUCHID",!!I)});let B=process.env.VISA_CLI_DEBUG;r.push({key:"dev.debug",value:!!B,formatted:O(!!B),source:Et("VISA_CLI_DEBUG",!!B)})}return{entries:r,statusError:n}}function Ps(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 Fn(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}(${Ps(o.source)})`),t.verbose&&o.hint&&s.push(` ${"\u21B3".padStart(n)} ${o.hint}`)}return s.join(`
94
- `)}function Bn(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 A=class extends Error{constructor(t){super(t),this.name="PayValidationError"}},Kn=["GET","POST"];function qn(e){let t;try{t=new URL(e)}catch{throw new A(`Invalid URL: ${e}. Expected a fully-qualified http(s) URL.`)}if(t.protocol!=="http:"&&t.protocol!=="https:")throw new A(`Unsupported URL scheme "${t.protocol}". Only http and https are allowed.`);return t}function Wn(e){let t=(e??"GET").toUpperCase();if(!Kn.includes(t))throw new A(`Unsupported HTTP method "${e}". Supported: ${Kn.join(", ")}.`);return t}function Gn(e){if(e!==void 0){try{JSON.parse(e)}catch(t){throw new A(`--body is not valid JSON: ${t?.message??"parse error"}`)}return e}}function Jn(e){if(!e||typeof e!="object")throw new A("Merchant returned no payment preview.");let t=e;if(typeof t.amount!="number"||!Number.isFinite(t.amount)||t.amount<=0)throw new A("Could not determine payment amount from merchant.");if(typeof t.merchantName!="string"||t.merchantName.trim().length===0)throw new A("Merchant returned an empty merchant name.");if(t.merchantName.length>200)throw new A(`Merchant name too long (${t.merchantName.length} chars).`);if(typeof t.currency!="string"||t.currency.trim().length===0)throw new A("Merchant returned an empty currency.");if(t.currency.length>10)throw new A(`Currency code too long (${t.currency.length} chars).`);return{amount:t.amount,currency:t.currency,merchantName:t.merchantName}}var h=g(require("fs")),p=g(require("path")),zn=g(require("os")),_=zn.homedir(),Ts=["Claude_","Anthropic.ClaudeDesktop_"];function Yn(){return process.env.APPDATA||p.join(_,"AppData","Roaming")}function As(){return process.env.LOCALAPPDATA||p.join(_,"AppData","Local")}function Xn(){if(process.platform!=="win32")return;let e=p.join(As(),"Packages");if(h.existsSync(e))try{let t=h.readdirSync(e,"utf-8");for(let n of Ts){let r=t.filter(s=>s.startsWith(n)).sort()[0];if(r)return p.join(e,r,"LocalCache","Roaming","Claude")}}catch{return}}function Zn(){if(process.platform==="win32"){let e=Xn();return e?p.join(e,"claude_desktop_config.json"):p.join(Yn(),"Claude","claude_desktop_config.json")}return p.join(_,"Library","Application Support","Claude","claude_desktop_config.json")}function Qn(){if(process.platform!=="win32")return[p.join(_,"Library","Application Support","Claude")];let e=[p.join(Yn(),"Claude")],t=Xn();return t&&e.push(t),e}function Ge(e){return e.id==="claude-desktop"?Zn():e.globalConfigPath}function Is(e){return e.id==="claude-desktop"?Qn():e.detectPaths}var V=[{id:"claude",displayName:"Claude Code",globalConfigPath:p.join(_,".claude.json"),configKey:"mcpServers",detectPaths:[p.join(_,".claude.json")],postInstallHint:"Restart Claude Code or run /mcp to connect."},{id:"claude-desktop",displayName:"Claude Desktop",globalConfigPath:Zn(),configKey:"mcpServers",detectPaths:Qn(),postInstallHint:"Restart the Claude desktop app to connect."},{id:"cursor",displayName:"Cursor",globalConfigPath:p.join(_,".cursor","mcp.json"),configKey:"mcpServers",detectPaths:[p.join(_,".cursor")],postInstallHint:"Restart Cursor to connect."},{id:"windsurf",displayName:"Windsurf",globalConfigPath:p.join(_,".codeium","windsurf","mcp_config.json"),configKey:"mcpServers",detectPaths:[p.join(_,".codeium","windsurf")],postInstallHint:"Restart Windsurf to connect."},{id:"cline",displayName:"Cline",globalConfigPath:p.join(_,".vscode","mcp.json"),configKey:"mcpServers",detectPaths:[p.join(_,".vscode","extensions","saoudrizwan.claude-dev-*")],postInstallHint:"Restart VS Code to connect."},{id:"roo-code",displayName:"Roo Code",globalConfigPath:p.join(_,".config","Roo","mcp_settings.json"),configKey:"mcpServers",detectPaths:[p.join(_,".vscode","extensions","RooVeterinaryInc.roo-cline-*")],postInstallHint:"Restart VS Code to connect."},{id:"copilot",displayName:"VS Code Copilot",globalConfigPath:p.join(_,".vscode","mcp.json"),configKey:"servers",detectPaths:[p.join(_,".vscode")],postInstallHint:"Restart VS Code to connect."},{id:"zed",displayName:"Zed",globalConfigPath:p.join(_,".config","zed","settings.json"),configKey:"context_servers",detectPaths:[p.join(_,".config","zed")],postInstallHint:"Restart Zed to connect.",buildEntry:e=>({source:"custom",...e})},{id:"codex",displayName:"Codex",globalConfigPath:p.join(_,".codex","config.toml"),configKey:"mcp_servers",configFormat:"toml",detectPaths:[p.join(_,".codex")],postInstallHint:"Restart Codex to connect."}];function xt(e){return V.find(t=>t.id===e)}function ye(e){return Is(e).some(t=>{if(t.includes("*")){let n=p.dirname(t),r=p.basename(t).replaceAll("*","");if(!h.existsSync(n))return!1;try{return h.readdirSync(n).some(s=>s.startsWith(r))}catch{return!1}}return h.existsSync(t)})}function er(){return{command:"node",args:[p.resolve(__dirname,"mcp-server/index.js")]}}function Rt(e,t){return t==="project"?"json":e.configFormat??"json"}function Ls(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 Pt(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 Tt(e,t){let n=e.split(`
95
- `),r=Pt(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]]=Ls(i[2]))}return Object.keys(s).length>0?s:void 0}function Os(e,t,n){let r=`[${n.args.map(c=>`"${c}"`).join(", ")}]`,s=[`[mcp_servers.${t}]`,`command = "${n.command}"`,`args = ${r}`],o=e.split(`
96
- `),i=Pt(o,t);if(i){o.splice(i.start,i.end-i.start,...s);let c=o.join(`
91
+ `}function Un(e=Ge()){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=Je(e);let n=h.existsSync(t)?h.readFileSync(t,"utf-8"):"",r=xs(n,e),s=r!==n;return s&&Ke(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}: ${Bn(n)}`}}}function jn(e=Ge()){if(!e)return{removed:!1,shell:null,message:"Shell HUD uninstall skipped: supported shells are zsh, bash, and PowerShell."};let t;try{if(t=Je(e),!h.existsSync(t))return{removed:!1,shell:e,rcPath:t,message:`No ${e} rc file found at ${t}.`};let n=h.readFileSync(t,"utf-8"),r=Mn(n);return r===n.trimEnd()?{removed:!1,shell:e,rcPath:t,message:`Persistent shell HUD was not installed in ${t}.`}:(Ke(t,r.length>0?`${r}
92
+ `:""),{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}: ${Bn(n)}`}}}function $t(e,t){let n=t.currentVersion==="0.0.0"&&e.version?e.version:t.currentVersion,r=Be(n),s=` ${j("\u2502",D.dim)} `;if(!e.enrolled)return`${j("VISA CLI",D.visaBlue)} ${j(`v${r}`,D.visaBlueSoft)}${s}${j("setup needed",D.visaGold)}`;let o=wt(e.spendingControls?.daily_limit??e.spendingControls?.dailyLimit),i=Math.max(0,wt(e.dailySpent)),a=o>0?Math.min(o,Math.max(0,wt(e.dailyRemaining??o-i))):0,c=o>0?Math.max(0,Math.min(1,i/o)):0,l=Ts(e),u=o>0?`${Ps(c)} ${j(`${_t(a)} left today`,D.green)} ${j(`(${_t(i)}/${_t(o)}/day)`,D.dim)}`:j("no spend limit",D.dim);return`${j("VISA CLI",D.visaBlue)} ${j(`v${r}`,D.visaBlueSoft)}${s}${j(l,D.visaGold)}${s}${u}`}function Hn(){let e=Vn();return!!e&&Date.now()-e.renderedAt<=Nn}function Et(){let e=Vn();if(e&&Date.now()-e.renderedAt<=Nn||(Rs(),e?.line))return e.line;try{let t=We();if(h.existsSync(t))return h.readFileSync(t,"utf-8").trimEnd()}catch{}return"VISA | loading spend HUD\u2026"}function xt(e){try{let t=$.dirname(Se());h.mkdirSync(t,{recursive:!0});let n=Be(e),r={hudVersion:_s,renderedAt:Date.now(),line:n};Ke(Se(),JSON.stringify(r)+`
93
+ `),Ke(We(),n+`
94
+ `)}catch{}}function ye(){try{h.unlinkSync(Dn())}catch{}}function Vn(){let e=Se();if(!h.existsSync(e))return null;try{return JSON.parse(h.readFileSync(e,"utf-8"))}catch{return null}}function Rs(){if(process.env.JEST_WORKER_ID)return;let e=Dn();try{if(h.mkdirSync($.dirname(e),{recursive:!0}),!Os(e))return;let t=process.argv[1]?$.resolve(process.argv[1]):"";if(!t){ye();return}let n=(0,On.spawn)(process.execPath,[t,"shell-hud","refresh"],{detached:!0,stdio:"ignore",env:{...process.env,VISA_CLI_SHELL_HUD_BACKGROUND:"1"}});n.once("error",ye),n.unref()}catch{ye()}}function wt(e){let t=Number(typeof e=="string"?e:e??0);return Number.isFinite(t)?t:0}function Be(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 Ps(e){let n=Math.round(Math.max(0,Math.min(1,e))*10),r="\u2588".repeat(n),s="\u2591".repeat(10-n);return`${j(r||"",D.green)}${j(s||"",D.dim)}`}function _t(e){return`$${e.toFixed(2)}`}function Ts(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=Be(n.toUpperCase()),o=Be(r);return`${t.isDefault?"default":"active"} ${s} ****${o}`}function As(){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 Ct=As(),D={reset:"\x1B[0m",visaBlue:Ct?"\x1B[38;2;20;52;203m":"\x1B[38;5;27m",visaBlueSoft:Ct?"\x1B[38;2;97;126;229m":"\x1B[38;5;111m",visaGold:Ct?"\x1B[38;2;247;182;0m":"\x1B[38;5;220m",green:"\x1B[38;5;48m",dim:"\x1B[2m"};function j(e,t){return e.length===0||process.env.NO_COLOR?e:`${t}${e}${D.reset}`}function Ln(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Fn(){let e=qe.homedir();if(!e||!$.isAbsolute(e))throw new Error("unable to determine a valid home directory");return $.resolve(e)}function Is(e){return e==="powershell"?"& visa-cli shell-hud refresh":"visa-cli shell-hud refresh"}function Ls(e){return e==="powershell"?"Get-Command visa-cli -ErrorAction SilentlyContinue -CommandType Application":"command -v visa-cli >/dev/null 2>&1"}function Os(e){for(let t=0;t<2;t+=1){let n;try{return n=h.openSync(e,"wx"),h.writeFileSync(n,String(Date.now())),!0}catch(r){if(r?.code!=="EEXIST")return!1;try{let s=h.statSync(e);if(Date.now()-s.mtimeMs<=$s)return!1;h.unlinkSync(e)}catch{}}finally{n!==void 0&&h.closeSync(n)}}return!1}function Bn(e){return e instanceof Error?e.message:"unknown file system error"}function Ke(e,t){h.mkdirSync($.dirname(e),{recursive:!0});let n=`${e}.${process.pid}.${Date.now()}.tmp`;h.writeFileSync(n,t),h.renameSync(n,e)}async function Rt(e,t){try{return await t()}catch(n){if(n.message==="Invalid signature"&&O()){ce.warn("attestation:key-mismatch",{action:"reregistering"});try{let r=await He();await e.registerAttestationKey(r),ce.info("attestation:key-reregistered")}catch(r){throw ce.error("attestation:reregister-failure",{error:r.message}),n}return await t()}throw n}}var Kn="1.9.0-rc.0";function Pt(e,t){return t?{kind:"env",var:e}:{kind:"default"}}function Ns(e,t,n){let r=process.env[e];if(r!==void 0&&r!=="")return{value:r,source:{kind:"env",var:e}};let s=dt(t);return s!==void 0?{value:s,source:{kind:"settings"}}:{value:n,source:{kind:"default"}}}function ve(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=gn(t);return s!==void 0?{value:s,source:{kind:"settings"}}:{value:n!=="opt-in",source:{kind:"default"}}}function M(e){return e==null?"\u2014":e?"yes":"no"}function ze(e){return e==null?"\u2014":`$${e.toFixed(2)}`}async function qn(e){let t=null,n=null;try{t=await e.api.getStatus()}catch(w){n=w?.message||"unknown error"}let r=[],s=Ns("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:M(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:M(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:M(t?.hasAttestationKey),source:t?{kind:"server"}:{kind:"unknown",reason:n||"offline"}}),r.push({key:"biometric.deviceAvailable",value:O(),formatted:M(O()),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(w=>w.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=ve("VISA_SUPPRESS_BROWSER","ui.suppressBrowser","opt-in");r.push({key:"ui.suppressBrowser",value:u.value,formatted:M(u.value),source:u.source,hint:"Persist with `visa-cli config set ui.suppressBrowser true` to stop auto-opening result URLs."});let d=ve("VISA_SUPPRESS_FEED","ui.suppressFeed","opt-in");r.push({key:"ui.suppressFeed",value:d.value,formatted:M(d.value),source:d.source});let y=K(),b;process.env.VISA_CLI_NO_UPDATE_CHECK?b={kind:"env",var:"VISA_CLI_NO_UPDATE_CHECK"}:process.env.CI?b={kind:"env",var:"CI"}:process.env.NODE_ENV==="test"?b={kind:"env",var:"NODE_ENV"}:b={kind:"default"},r.push({key:"ui.updateCheck",value:!y,formatted:M(!y),source:b});let C=ve("VISA_META_TOOLS","tools.meta","opt-out");r.push({key:"tools.meta",value:C.value,formatted:M(C.value),source:C.source,hint:"Persist with `visa-cli config set tools.meta false`. Restart Claude Code for changes to take effect."});let f=ve("VISA_SPECIFIC_TOOLS","tools.specific","opt-out");r.push({key:"tools.specific",value:f.value,formatted:M(f.value),source:f.source});let S=ve("VISA_DISCOVER_TOOLS","tools.discover","opt-out");if(r.push({key:"tools.discover",value:S.value,formatted:M(S.value),source:S.source}),r.push({key:"client.version",value:Kn,formatted:Kn,source:{kind:"default"}}),e.includeDev){let w=process.env.VISA_MOCK_KEYCHAIN;r.push({key:"dev.mockKeychain",value:w==="true",formatted:M(w==="true"),source:Pt("VISA_MOCK_KEYCHAIN",!!w)});let x=process.env.VISA_MOCK_TOUCHID;r.push({key:"dev.mockTouchid",value:x==="true",formatted:M(x==="true"),source:Pt("VISA_MOCK_TOUCHID",!!x)});let P=process.env.VISA_CLI_DEBUG;r.push({key:"dev.debug",value:!!P,formatted:M(!!P),source:Pt("VISA_CLI_DEBUG",!!P)})}return{entries:r,statusError:n}}function Ds(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 Wn(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}(${Ds(o.source)})`),t.verbose&&o.hint&&s.push(` ${"\u21B3".padStart(n)} ${o.hint}`)}return s.join(`
95
+ `)}function Gn(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 N=class extends Error{constructor(t){super(t),this.name="PayValidationError"}},Jn=["GET","POST"];function zn(e){let t;try{t=new URL(e)}catch{throw new N(`Invalid URL: ${e}. Expected a fully-qualified http(s) URL.`)}if(t.protocol!=="http:"&&t.protocol!=="https:")throw new N(`Unsupported URL scheme "${t.protocol}". Only http and https are allowed.`);return t}function Yn(e){let t=(e??"GET").toUpperCase();if(!Jn.includes(t))throw new N(`Unsupported HTTP method "${e}". Supported: ${Jn.join(", ")}.`);return t}function Xn(e){if(e!==void 0){try{JSON.parse(e)}catch(t){throw new N(`--body is not valid JSON: ${t?.message??"parse error"}`)}return e}}function Zn(e){if(!e||typeof e!="object")throw new N("Merchant returned no payment preview.");let t=e;if(typeof t.amount!="number"||!Number.isFinite(t.amount)||t.amount<=0)throw new N("Could not determine payment amount from merchant.");if(typeof t.merchantName!="string"||t.merchantName.trim().length===0)throw new N("Merchant returned an empty merchant name.");if(t.merchantName.length>200)throw new N(`Merchant name too long (${t.merchantName.length} chars).`);if(typeof t.currency!="string"||t.currency.trim().length===0)throw new N("Merchant returned an empty currency.");if(t.currency.length>10)throw new N(`Currency code too long (${t.currency.length} chars).`);return{amount:t.amount,currency:t.currency,merchantName:t.merchantName}}var m=g(require("fs")),p=g(require("path")),Qn=g(require("os")),k=Qn.homedir(),Ms=["Claude_","Anthropic.ClaudeDesktop_"],de=class extends Error{constructor(n,r,s){super(js(n,r,s));this.client=n;this.configPath=r;this.name="McpConfigAccessError"}client;configPath};function er(e){let t=e;return[t?.message,t?.stderr].filter(n=>typeof n=="string").join(`
96
+ `)}function Us(e){let t=e;if(t?.code==="EPERM"||t?.code==="EACCES")return!0;let n=er(e).toLowerCase();return n.includes("operation not permitted")||n.includes("permission denied")}function js(e,t,n){let r=t.replace(k,"~"),s=er(n).split(`
97
+ `).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 tr(){return process.env.APPDATA||p.join(k,"AppData","Roaming")}function Hs(){return process.env.LOCALAPPDATA||p.join(k,"AppData","Local")}function nr(){if(process.platform!=="win32")return;let e=p.join(Hs(),"Packages");if(m.existsSync(e))try{let t=m.readdirSync(e,"utf-8");for(let n of Ms){let r=t.filter(s=>s.startsWith(n)).sort()[0];if(r)return p.join(e,r,"LocalCache","Roaming","Claude")}}catch{return}}function rr(){if(process.platform==="win32"){let e=nr();return e?p.join(e,"claude_desktop_config.json"):p.join(tr(),"Claude","claude_desktop_config.json")}return p.join(k,"Library","Application Support","Claude","claude_desktop_config.json")}function sr(){if(process.platform!=="win32")return[p.join(k,"Library","Application Support","Claude")];let e=[p.join(tr(),"Claude")],t=nr();return t&&e.push(t),e}function Ye(e){return e.id==="claude-desktop"?rr():e.globalConfigPath}function Vs(e){return e.id==="claude-desktop"?sr():e.detectPaths}var V=[{id:"claude",displayName:"Claude Code",globalConfigPath:p.join(k,".claude.json"),configKey:"mcpServers",detectPaths:[p.join(k,".claude.json")],postInstallHint:"Restart Claude Code or run /mcp to connect."},{id:"claude-desktop",displayName:"Claude Desktop",globalConfigPath:rr(),configKey:"mcpServers",detectPaths:sr(),postInstallHint:"Restart the Claude desktop app to connect."},{id:"cursor",displayName:"Cursor",globalConfigPath:p.join(k,".cursor","mcp.json"),configKey:"mcpServers",detectPaths:[p.join(k,".cursor")],postInstallHint:"Restart Cursor to connect."},{id:"windsurf",displayName:"Windsurf",globalConfigPath:p.join(k,".codeium","windsurf","mcp_config.json"),configKey:"mcpServers",detectPaths:[p.join(k,".codeium","windsurf")],postInstallHint:"Restart Windsurf to connect."},{id:"cline",displayName:"Cline",globalConfigPath:p.join(k,".vscode","mcp.json"),configKey:"mcpServers",detectPaths:[p.join(k,".vscode","extensions","saoudrizwan.claude-dev-*")],postInstallHint:"Restart VS Code to connect."},{id:"roo-code",displayName:"Roo Code",globalConfigPath:p.join(k,".config","Roo","mcp_settings.json"),configKey:"mcpServers",detectPaths:[p.join(k,".vscode","extensions","RooVeterinaryInc.roo-cline-*")],postInstallHint:"Restart VS Code to connect."},{id:"copilot",displayName:"VS Code Copilot",globalConfigPath:p.join(k,".vscode","mcp.json"),configKey:"servers",detectPaths:[p.join(k,".vscode")],postInstallHint:"Restart VS Code to connect."},{id:"zed",displayName:"Zed",globalConfigPath:p.join(k,".config","zed","settings.json"),configKey:"context_servers",detectPaths:[p.join(k,".config","zed")],postInstallHint:"Restart Zed to connect.",buildEntry:e=>({source:"custom",...e})},{id:"codex",displayName:"Codex",globalConfigPath:p.join(k,".codex","config.toml"),configKey:"mcp_servers",configFormat:"toml",detectPaths:[p.join(k,".codex")],postInstallHint:"Restart Codex to connect."}];function Tt(e){return V.find(t=>t.id===e)}function be(e){return Vs(e).some(t=>{if(t.includes("*")){let n=p.dirname(t),r=p.basename(t).replaceAll("*","");if(!m.existsSync(n))return!1;try{return m.readdirSync(n).some(s=>s.startsWith(r))}catch{return!1}}return m.existsSync(t)})}function or(){return{command:"node",args:[p.resolve(__dirname,"mcp-server/index.js")]}}function At(e,t){return t==="project"?"json":e.configFormat??"json"}function Fs(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 It(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 Lt(e,t){let n=e.split(`
98
+ `),r=It(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]]=Fs(i[2]))}return Object.keys(s).length>0?s:void 0}function Bs(e,t,n){let r=`[${n.args.map(c=>`"${c}"`).join(", ")}]`,s=[`[mcp_servers.${t}]`,`command = "${n.command}"`,`args = ${r}`],o=e.split(`
99
+ `),i=It(o,t);if(i){o.splice(i.start,i.end-i.start,...s);let c=o.join(`
97
100
  `);return c.endsWith(`
98
101
  `)?c:c+`
99
102
  `}let a=e.trimEnd();return a+(a.length>0?`
100
103
 
101
104
  `:"")+s.join(`
102
105
  `)+`
103
- `}function Ns(e,t){let n=e.split(`
104
- `),r=Pt(n,t);return r?(n.splice(r.start,r.end-r.start),n.join(`
106
+ `}function Ks(e,t){let n=e.split(`
107
+ `),r=It(n,t);return r?(n.splice(r.start,r.end-r.start),n.join(`
105
108
  `).replace(/\n{3,}/g,`
106
109
 
107
- `)):e}function Se(e,t="global"){let n=t==="project"?p.join(process.cwd(),".mcp.json"):Ge(e),r=p.dirname(n);h.existsSync(r)||h.mkdirSync(r,{recursive:!0});let s=Rt(e,t),o=er();if(s==="toml"){let i=h.existsSync(n)?h.readFileSync(n,"utf-8"):"",a=Os(i,"visa-cli",o);h.writeFileSync(n,a)}else{let i={};if(h.existsSync(n))try{i=JSON.parse(h.readFileSync(n,"utf-8"))}catch{i={}}i[e.configKey]=i[e.configKey]||{},i[e.configKey]["visa-cli"]=e.buildEntry?e.buildEntry(o):o,h.writeFileSync(n,JSON.stringify(i,null,2)+`
108
- `)}return{installed:!0,configPath:n,message:e.postInstallHint}}function At(e,t="global"){let n=t==="project"?p.join(process.cwd(),".mcp.json"):Ge(e);if(!h.existsSync(n))return{removed:!1,configPath:n};if(Rt(e,t)==="toml"){let i=h.readFileSync(n,"utf-8");return Tt(i,"visa-cli")?(h.writeFileSync(n,Ns(i,"visa-cli")),{removed:!0,configPath:n}):{removed:!1,configPath:n}}let s;try{s=JSON.parse(h.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"],h.writeFileSync(n,JSON.stringify(s,null,2)+`
109
- `),{removed:!0,configPath:n})}function tr(e,t="global"){let n=t==="project"?p.join(process.cwd(),".mcp.json"):Ge(e);if(!h.existsSync(n))return!1;if(Rt(e,t)==="toml")try{let s=h.readFileSync(n,"utf-8");return!!Tt(s,"visa-cli")}catch{return!1}try{return!!JSON.parse(h.readFileSync(n,"utf-8"))?.[e.configKey]?.["visa-cli"]}catch{return!1}}function Ds(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 Us(e,t){if(e===t)return!0;let n=p.resolve(e),r=p.resolve(t);if(n===r)return!0;try{let s=h.realpathSync(n),o=h.realpathSync(r);return s===o}catch{return!1}}function ve(){let e=er(),t=e.args[e.args.length-1],n=[];for(let r of V){let s=Ge(r);if(!h.existsSync(s))continue;let o=r.configFormat??"json",i;if(o==="toml")try{let l=h.readFileSync(s,"utf-8");i=Tt(l,"visa-cli")}catch{continue}else{let l;try{l=JSON.parse(h.readFileSync(s,"utf-8"))}catch{continue}i=l?.[r.configKey]?.["visa-cli"]}if(!i)continue;let a=Ds(i);if(!a||Us(a,t))continue;let c=h.existsSync(a)?"mismatch":"missing";n.push({client:r,configPath:s,currentPath:a,expectedPath:t,staleReason:c})}return n}function It(e){return{configPath:Se(e.client,"global").configPath}}var Ms=(0,ir.promisify)(or.execFile);function js(e,t){return process.stdin.isTTY?new Promise(n=>{let r=sr.createInterface({input:process.stdin,output:process.stdout});r.question(e,s=>{r.close();let o=s.trim().toLowerCase();if(o===""){n(t);return}n(o==="y"||o==="yes")})}):Promise.resolve(t)}function Hs(e){let t=j.homedir(),n=s=>s.replace(t,"~"),r=e.staleReason==="missing"?"path missing on disk":"path mismatch";return` \u2022 ${e.client.displayName} (${n(e.configPath)})
110
- ${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(Hs(n))}var x=new nr.Command,Je=null,be=!1;function F(){return Je=new oe(()=>k.getSessionToken()),Je}x.name("visa-cli").description("Visa CLI - AI payment orchestration").version(nt().version);x.hook("preAction",async()=>{await jt()});x.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 all prompts (enable HUD etc) without asking \u2014 for CI/agent use").option("--no-hud","Skip the HUD install prompt (default: ask)").action(async e=>{try{if(e.check){let d=ve();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=ve(),n=new Map(t.map(d=>[d.client.id,d])),r=new Set;for(let d of V)if(ye(d)){let m=Se(d),v=n.get(d.id),C=v?` \u2014 repaired stale ${v.staleReason} entry`:"";console.log(` \u2713 ${d.displayName} (${m.configPath.replace(j.homedir(),"~")})${C}`),v&&r.add(d.id)}let s=t.filter(d=>!r.has(d.client.id));for(let d of s)It(d),console.log(` \u2713 ${d.client.displayName} (${d.configPath.replace(j.homedir(),"~")}) \u2014 repaired stale ${d.staleReason} entry`);let o=r.size+s.length;console.log(o===0?" \u2713 MCP config verified \u2014 nothing to repair.":` \u2713 Repaired ${o} stale MCP config ${o===1?"entry":"entries"}.`),console.log(`
111
- Step 2: Checking authentication...`);let i=await k.getSessionToken();if(i)try{await new oe(()=>Promise.resolve(i)).getStatus(),console.log(" Already authenticated.")}catch(d){let m=d instanceof Error?d.message:"";m.includes("session has expired")||m.includes("Not logged in")?(console.log(" Existing session expired \u2014 re-authenticating..."),await k.clearAll(),i=null):console.log(` Couldn't verify session (${m||"unknown error"}) \u2014 continuing with existing token.`)}if(i||(console.log(" No session found. Opening browser for GitHub login..."),i=await new Promise(async(d,m)=>{let v=ze.randomBytes(16).toString("hex"),C=`https://auth.visacli.sh/login?state=${v}`;await Vt(C);let N=3e4,$=300*1e3,I=Date.now()+$;for(;Date.now()<I;)try{let B=await globalThis.fetch("https://auth.visacli.sh/v1/auth-status",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({state:v,timeout:N}),signal:AbortSignal.timeout(N+5e3)});if(!B.ok)continue;let H=await B.json();if(H.status==="pending")continue;if(H.status==="expired"){m(new Error("Session expired. Please run setup again."));return}if(H.status==="complete"&&H.sessionToken){console.log(` Signed in as ${H.user}.`),d(H.sessionToken);return}}catch{}m(new Error("Login timed out after 5 minutes. Please run setup again."))}),await k.saveSessionToken(i),console.log(" Session token saved.")),console.log(`
112
- Step 3: Setting up authentication...`),!T())console.log(" Not macOS \u2014 skipping biometric setup.");else{try{await Ms("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 Ue();console.log(" Attestation key generated."),await F().registerAttestationKey(d),console.log(" Attestation key registered with server.")}catch(d){console.log(` Skipped: ${d.message}`)}}let a=we.join(j.homedir(),".claude","settings.json"),c=rr.existsSync(we.join(j.homedir(),".claude.json")),l=e.hud===!1;if(c&&!l){console.log(`
113
- Step 4: Enable the Visa spend HUD?`),console.log(" Pins your spend + card info below the Claude Code input, so"),console.log(" you can see your spend, card, and session usage in real time.");let d;if(e.yes?(d=!0,console.log(" (--yes) Enabling Visa HUD.")):process.stdin.isTTY?d=await js(" Enable Visa HUD? [Y/n] ",!0):(d=!1,console.log(" Non-interactive shell \u2014 skipping prompt. Enable with: visa-cli hud enable")),d){let m=st(a),v=m.installed==="new"||m.installed==="already-visa"||m.installed==="other-hud-present"?" \u2713 ":" Skipped: ";console.log(`${v}${m.message}`);try{let C=F(),N=await C.getStatus(),$={currentVersion:C.getClientVersion(),latestVersion:C.lastSignals?.updateAvailable?.version,updateMessage:C.lastSignals?.updateAvailable?.message,updateCheckDisabled:q()},I=_t(N,$);kt(I),console.log(` Preview: ${I.split(`
114
- `)[0]}`)}catch{}}else(e.yes===!1||process.stdin.isTTY)&&console.log(" Skipped. Enable any time with: visa-cli hud enable")}let u="\x1B[1m",f="\x1B[0m";console.log(`
110
+ `)):e}function we(e,t="global"){let n=t==="project"?p.join(process.cwd(),".mcp.json"):Ye(e);try{let r=p.dirname(n);m.existsSync(r)||m.mkdirSync(r,{recursive:!0});let s=At(e,t),o=or();if(s==="toml"){let i=m.existsSync(n)?m.readFileSync(n,"utf-8"):"",a=Bs(i,"visa-cli",o);m.writeFileSync(n,a)}else{let i={};if(m.existsSync(n))try{i=JSON.parse(m.readFileSync(n,"utf-8"))}catch{i={}}i[e.configKey]=i[e.configKey]||{},i[e.configKey]["visa-cli"]=e.buildEntry?e.buildEntry(o):o,m.writeFileSync(n,JSON.stringify(i,null,2)+`
111
+ `)}}catch(r){throw Us(r)?new de(e,n,r):r}return{installed:!0,configPath:n,message:e.postInstallHint}}function Ot(e,t="global"){let n=t==="project"?p.join(process.cwd(),".mcp.json"):Ye(e);if(!m.existsSync(n))return{removed:!1,configPath:n};if(At(e,t)==="toml"){let i=m.readFileSync(n,"utf-8");return Lt(i,"visa-cli")?(m.writeFileSync(n,Ks(i,"visa-cli")),{removed:!0,configPath:n}):{removed:!1,configPath:n}}let s;try{s=JSON.parse(m.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"],m.writeFileSync(n,JSON.stringify(s,null,2)+`
112
+ `),{removed:!0,configPath:n})}function ir(e,t="global"){let n=t==="project"?p.join(process.cwd(),".mcp.json"):Ye(e);if(!m.existsSync(n))return!1;if(At(e,t)==="toml")try{let s=m.readFileSync(n,"utf-8");return!!Lt(s,"visa-cli")}catch{return!1}try{return!!JSON.parse(m.readFileSync(n,"utf-8"))?.[e.configKey]?.["visa-cli"]}catch{return!1}}function qs(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 Ws(e,t){if(e===t)return!0;let n=p.resolve(e),r=p.resolve(t);if(n===r)return!0;try{let s=m.realpathSync(n),o=m.realpathSync(r);return s===o}catch{return!1}}function _e(){let e=or(),t=e.args[e.args.length-1],n=[];for(let r of V){let s=Ye(r);if(!m.existsSync(s))continue;let o=r.configFormat??"json",i;if(o==="toml")try{let l=m.readFileSync(s,"utf-8");i=Lt(l,"visa-cli")}catch{continue}else{let l;try{l=JSON.parse(m.readFileSync(s,"utf-8"))}catch{continue}i=l?.[r.configKey]?.["visa-cli"]}if(!i)continue;let a=qs(i);if(!a||Ws(a,t))continue;let c=m.existsSync(a)?"mismatch":"missing";n.push({client:r,configPath:s,currentPath:a,expectedPath:t,staleReason:c})}return n}function Nt(e){return{configPath:we(e.client,"global").configPath}}var Gs=(0,fr.promisify)(dr.execFile);function Js(e,t){return process.stdin.isTTY?new Promise(n=>{let r=ur.createInterface({input:process.stdin,output:process.stdout});r.question(e,s=>{r.close();let o=s.trim().toLowerCase();if(o===""){n(t);return}n(o==="y"||o==="yes")})}):Promise.resolve(t)}function zs(e){let t=H.homedir(),n=s=>s.replace(t,"~"),r=e.staleReason==="missing"?"path missing on disk":"path mismatch";return` \u2022 ${e.client.displayName} (${n(e.configPath)})
113
+ ${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(zs(n))}function ar(e){console.log(` ! ${e.client.displayName} skipped: ${e.message}`)}var A=new cr.Command,Xe=null,Ce=!1;function F(){return Xe=new ae(()=>E.getSessionToken()),Xe}A.name("visa-cli").description("Visa CLI - AI payment orchestration").version(ot().version);A.hook("preAction",async()=>{await Bt()});A.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 all prompts (enable HUD etc) without asking \u2014 for CI/agent use").option("--no-hud","Skip the HUD install prompt (default: ask)").action(async e=>{try{if(e.check){let f=_e();pr(f,"MCP config check:"),f.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(f=>[f.client.id,f])),r=new Set,s=new Set,o=new Set;for(let f of V)if(be(f)){let S;try{S=we(f)}catch(P){if(P instanceof de){ar(P),s.add(f.displayName),o.add(f.id);continue}throw P}let w=n.get(f.id),x=w?` \u2014 repaired stale ${w.staleReason} entry`:"";console.log(` \u2713 ${f.displayName} (${S.configPath.replace(H.homedir(),"~")})${x}`),w&&r.add(f.id)}let i=t.filter(f=>!r.has(f.client.id)&&!o.has(f.client.id)),a=0;for(let f of i){try{Nt(f)}catch(S){if(S instanceof de){ar(S),s.add(f.client.displayName),o.add(f.client.id);continue}throw S}console.log(` \u2713 ${f.client.displayName} (${f.configPath.replace(H.homedir(),"~")}) \u2014 repaired stale ${f.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(`
114
+ Step 2: Checking authentication...`);let l=await E.getSessionToken();if(l)try{await new ae(()=>Promise.resolve(l)).getStatus(),console.log(" Already authenticated.")}catch(f){let S=f instanceof Error?f.message:"";S.includes("session has expired")||S.includes("Not logged in")?(console.log(" Existing session expired \u2014 re-authenticating..."),await E.clearAll(),l=null):console.log(` Couldn't verify session (${S||"unknown error"}) \u2014 continuing with existing token.`)}if(l||(console.log(" No session found. Opening browser for GitHub login..."),l=await new Promise(async(f,S)=>{let w=Ze.randomBytes(16).toString("hex"),x=`https://auth.visacli.sh/login?state=${w}`;await qt(x);let P=3e4,G=300*1e3,R=Date.now()+G;for(;Date.now()<R;)try{let J=await globalThis.fetch("https://auth.visacli.sh/v1/auth-status",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({state:w,timeout:P}),signal:AbortSignal.timeout(P+5e3)});if(!J.ok)continue;let se=await J.json();if(se.status==="pending")continue;if(se.status==="expired"){S(new Error("Session expired. Please run setup again."));return}if(se.status==="complete"&&se.sessionToken){console.log(` Signed in as ${se.user}.`),f(se.sessionToken);return}}catch{}S(new Error("Login timed out after 5 minutes. Please run setup again."))}),await E.saveSessionToken(l),console.log(" Session token saved.")),console.log(`
115
+ Step 3: Setting up authentication...`),!O())console.log(" Not macOS \u2014 skipping biometric setup.");else{try{await Gs("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 f=await He();console.log(" Attestation key generated."),await F().registerAttestationKey(f),console.log(" Attestation key registered with server.")}catch(f){console.log(` Skipped: ${f.message}`)}}let u=ke.join(H.homedir(),".claude","settings.json"),d=lr.existsSync(ke.join(H.homedir(),".claude.json")),y=e.hud===!1;if(d&&!y){console.log(`
116
+ Step 4: Enable the Visa spend HUD?`),console.log(" Pins your spend + card info below the Claude Code input, so"),console.log(" you can see your spend, card, and session usage in real time.");let f;if(e.yes?(f=!0,console.log(" (--yes) Enabling Visa HUD.")):process.stdin.isTTY?f=await Js(" Enable Visa HUD? [Y/n] ",!0):(f=!1,console.log(" Non-interactive shell \u2014 skipping prompt. Enable with: visa-cli hud enable")),f){let S=at(u),w=S.installed==="new"||S.installed==="already-visa"||S.installed==="other-hud-present"?" \u2713 ":" Skipped: ";console.log(`${w}${S.message}`);try{let x=F(),P=await x.getStatus(),G={currentVersion:x.getClientVersion(),latestVersion:x.lastSignals?.updateAvailable?.version,updateMessage:x.lastSignals?.updateAvailable?.message,updateCheckDisabled:K()},R=$t(P,G);xt(R),console.log(` Preview: ${R.split(`
117
+ `)[0]}`)}catch{}}else(e.yes===!1||process.stdin.isTTY)&&console.log(" Skipped. Enable any time with: visa-cli hud enable")}let b="\x1B[1m",C="\x1B[0m";console.log(`
115
118
  \u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557
116
119
  \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
117
120
  \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
@@ -119,33 +122,33 @@ Step 4: Enable the Visa spend HUD?`),console.log(" Pins your spend + card info
119
122
  \u255A\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551
120
123
  \u255A\u2550\u2550\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u2588 CLI
121
124
 
122
- ${u}Setup complete.${f} Restart Claude Code or run /mcp to connect.
125
+ ${b}Setup complete.${C} Restart Claude Code or run /mcp to connect.
123
126
 
124
- ${u}Try it out:${f}
127
+ ${b}Try it out:${C}
125
128
  \u2022 Ask Claude: "Generate an image of a neon cityscape"
126
129
  \u2022 Ask Claude: "What's the price of ETH on Base?"
127
130
  \u2022 Or run: visa-cli pay <merchant-url>
128
131
 
129
- ${u}Verify:${f} visa-cli status
130
- ${u}HUD:${f} Restart Claude Code to see your spend pinned below the input
131
- ${u}Docs:${f} https://visacli.sh
132
- `)}catch(t){console.error("Error:",t.message),process.exit(1)}});x.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=ve();ar(o,"MCP config check:"),o.length>0&&process.exit(1);return}if(t.repair){let o=ve();if(o.length===0){console.log("\u2713 MCP config verified \u2014 nothing to repair.");return}for(let i of o)It(i),console.log(` \u2713 ${i.client.displayName} (${i.configPath.replace(j.homedir(),"~")}) \u2014 repaired stale ${i.staleReason} entry`);console.log(`
132
+ ${b}Verify:${C} visa-cli status
133
+ ${b}HUD:${C} Restart Claude Code to see your spend pinned below the input
134
+ ${b}Docs:${C} https://visacli.sh
135
+ `)}catch(t){console.error("Error:",t.message),process.exit(1)}});A.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)Nt(i),console.log(` \u2713 ${i.client.displayName} (${i.configPath.replace(H.homedir(),"~")}) \u2014 repaired stale ${i.staleReason} entry`);console.log(`
133
136
  Repaired ${o.length} stale MCP config ${o.length===1?"entry":"entries"}.`);return}if(t.list){console.log(`
134
137
  \x1B[1mSupported MCP Clients\x1B[0m
135
- `),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 V){let c=ye(a),l=tr(a),u=c?"Yes":"No",f=l?"Yes":"No",d=a.globalConfigPath.replace(j.homedir(),"~");console.log(` ${a.displayName.padEnd(18)} ${u.padEnd(10)} ${f.padEnd(11)} ${d}`)}console.log("");return}let n=t.scope==="project"?"project":"global";if(t.all){let o=[],i=[];for(let a of V){if(!ye(a)){i.push(a.displayName);continue}Se(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(`
136
- Supported clients: ${V.map(o=>o.id).join(", ")}`),process.exit(1));let r=xt(e);r||(console.error(`Unknown client: ${e}`),console.error(`Supported clients: ${V.map(o=>o.id).join(", ")}`),process.exit(1)),n==="global"&&!ye(r)&&(console.error(`${r.displayName} not detected on this machine.`),console.error(`Expected: ${r.detectPaths.join(", ")}`),process.exit(1));let s=Se(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)}});x.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 V)At(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(`
137
- Supported clients: ${V.map(o=>o.id).join(", ")}`),process.exit(1));let r=xt(e);r||(console.error(`Unknown client: ${e}`),console.error(`Supported clients: ${V.map(o=>o.id).join(", ")}`),process.exit(1));let s=At(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)}});x.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{qn(e);let n=Wn(t.method),r=Gn(t.body),s=new oe(()=>k.getSessionToken());console.log(`Checking payment for ${e}...`);let o=Jn(await s.paymentPreview({url:e}));console.log(` Merchant: ${o.merchantName}`),console.log(` Amount: $${o.amount.toFixed(2)} ${o.currency}`),console.log(` Rail: auto-detected
138
- `);let a=(await s.getStatus()).attestationRequired!==!1;a&&!T()&&console.warn("Warning: Touch ID unavailable on this system \u2014 payment will proceed without biometric attestation.");let c=ze.randomUUID(),l=await $t(s,async()=>{let u;if(a&&T())try{let{nonce:f}=await s.getAttestationChallenge(),d=Buffer.from(JSON.stringify({nonce:f,amount:o.amount,merchant:o.merchantName,context:e})).toString("base64");u={signature:await mt(d,`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(`
139
- 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 A?console.error(`Error: ${n.message}`):console.error("Error:",n.message),process.exit(1)}});x.command("status").description("Check enrollment, cards, wallet, and spending controls").action(async()=>{be=!1;try{let e=F(),t=await e.getStatus(),n={currentVersion:e.getClientVersion(),latestVersion:e.lastSignals.updateAvailable?.version,updateMessage:e.lastSignals.updateAvailable?.message,updateCheckDisabled:q()},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}
140
- `)}return{transactions:[]}});process.stdout.write(Rn(t,Array.isArray(r?.transactions)?r.transactions:[],T(),n)),be=!0}catch(e){be=!1,console.error("Error:",e.message),process.exit(1)}});x.command("reset").description("Log out and clear all credentials").action(async()=>{try{console.log(`Resetting Visa CLI...
141
- `);try{await F().logout(),console.log(" Server session invalidated.")}catch{console.log(" Server logout skipped (no active session).")}if(await k.clearAll(),console.log(" Keychain credentials cleared."),T())try{await $n(),console.log(" Secure Enclave key deleted.")}catch{console.log(" No Secure Enclave key to delete.")}console.log(`
142
- Reset complete.`)}catch(e){console.error("Error:",e.message),process.exit(1)}});x.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 k.getSessionToken()||(console.error("Not logged in. Run visa-cli setup first."),process.exit(1)),await F().feedback(e.trim()),console.log("Feedback submitted. Thanks!")}catch(t){console.error("Error:",t.message),process.exit(1)}});var Lt=x.command("config").description("Inspect the CLI configuration");Lt.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=F(),n=await Vn({api:t,includeDev:!!e.dev});if(e.json){console.log(Bn(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(Fn(n.entries,{verbose:!!e.verbose}))}catch(t){console.error("Error:",t.message),process.exit(1)}});function Vs(){return Object.entries(de).map(([e,t])=>` ${e.padEnd(22)} (${t.type}) ${t.description}`).join(`
143
- `)}Lt.command("set <key> <value>").description("Persist a CLI setting to ~/.visa-mcp/settings.json").addHelpText("after",`
138
+ `),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 V){let c=be(a),l=ir(a),u=c?"Yes":"No",d=l?"Yes":"No",y=a.globalConfigPath.replace(H.homedir(),"~");console.log(` ${a.displayName.padEnd(18)} ${u.padEnd(10)} ${d.padEnd(11)} ${y}`)}console.log("");return}let n=t.scope==="project"?"project":"global";if(t.all){let o=[],i=[];for(let a of V){if(!be(a)){i.push(a.displayName);continue}we(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(`
139
+ Supported clients: ${V.map(o=>o.id).join(", ")}`),process.exit(1));let r=Tt(e);r||(console.error(`Unknown client: ${e}`),console.error(`Supported clients: ${V.map(o=>o.id).join(", ")}`),process.exit(1)),n==="global"&&!be(r)&&(console.error(`${r.displayName} not detected on this machine.`),console.error(`Expected: ${r.detectPaths.join(", ")}`),process.exit(1));let s=we(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)}});A.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 V)Ot(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(`
140
+ Supported clients: ${V.map(o=>o.id).join(", ")}`),process.exit(1));let r=Tt(e);r||(console.error(`Unknown client: ${e}`),console.error(`Supported clients: ${V.map(o=>o.id).join(", ")}`),process.exit(1));let s=Ot(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)}});A.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{zn(e);let n=Yn(t.method),r=Xn(t.body),s=new ae(()=>E.getSessionToken());console.log(`Checking payment for ${e}...`);let o=Zn(await s.paymentPreview({url:e}));console.log(` Merchant: ${o.merchantName}`),console.log(` Amount: $${o.amount.toFixed(2)} ${o.currency}`),console.log(` Rail: auto-detected
141
+ `);let a=(await s.getStatus()).attestationRequired!==!1;a&&!O()&&console.warn("Warning: Touch ID unavailable on this system \u2014 payment will proceed without biometric attestation.");let c=Ze.randomUUID(),l=await Rt(s,async()=>{let u;if(a&&O())try{let{nonce:d}=await s.getAttestationChallenge(),y=Buffer.from(JSON.stringify({nonce:d,amount:o.amount,merchant:o.merchantName,context:e})).toString("base64");u={signature:await St(y,`pay $${o.amount.toFixed(2)} to ${o.merchantName}`),nonce:d,amount:o.amount,merchant:o.merchantName}}catch(d){throw new Error(`Touch ID confirmation failed: ${d?.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(`
142
+ 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 N?console.error(`Error: ${n.message}`):console.error("Error:",n.message),process.exit(1)}});A.command("status").description("Check enrollment, cards, wallet, and spending controls").action(async()=>{Ce=!1;try{let e=F(),t=await e.getStatus(),n={currentVersion:e.getClientVersion(),latestVersion:e.lastSignals.updateAvailable?.version,updateMessage:e.lastSignals.updateAvailable?.message,updateCheckDisabled:K()},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}
143
+ `)}return{transactions:[]}});process.stdout.write(In(t,Array.isArray(r?.transactions)?r.transactions:[],O(),n)),Ce=!0}catch(e){Ce=!1,console.error("Error:",e.message),process.exit(1)}});A.command("reset").description("Log out and clear all credentials").action(async()=>{try{console.log(`Resetting Visa CLI...
144
+ `);try{await F().logout(),console.log(" Server session invalidated.")}catch{console.log(" Server logout skipped (no active session).")}if(await E.clearAll(),console.log(" Keychain credentials cleared."),O())try{await Pn(),console.log(" Secure Enclave key deleted.")}catch{console.log(" No Secure Enclave key to delete.")}console.log(`
145
+ Reset complete.`)}catch(e){console.error("Error:",e.message),process.exit(1)}});A.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 E.getSessionToken()||(console.error("Not logged in. Run visa-cli setup first."),process.exit(1)),await F().feedback(e.trim()),console.log("Feedback submitted. Thanks!")}catch(t){console.error("Error:",t.message),process.exit(1)}});var Dt=A.command("config").description("Inspect the CLI configuration");Dt.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=F(),n=await qn({api:t,includeDev:!!e.dev});if(e.json){console.log(Gn(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(Wn(n.entries,{verbose:!!e.verbose}))}catch(t){console.error("Error:",t.message),process.exit(1)}});function Ys(){return Object.entries(ge).map(([e,t])=>` ${e.padEnd(22)} (${t.type}) ${t.description}`).join(`
146
+ `)}Dt.command("set <key> <value>").description("Persist a CLI setting to ~/.visa-mcp/settings.json").addHelpText("after",`
144
147
  Settable keys:
145
- ${Vs()}`).action((e,t)=>{try{let n=fn(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 re||n instanceof se?console.error(`Error: ${n.message}`):console.error(`Error: ${n.message}`),process.exit(1)}});Lt.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=pn(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 Ot=x.command("biometric").description("Manage Touch ID / biometric attestation enforcement");Ot.command("status").description("Show current biometric enforcement state").action(async()=>{try{await k.getSessionToken()||(console.error("Not logged in. Run visa-cli setup first."),process.exit(1));let n=await F().getStatus(),r=n.attestationRequired!==!1,s=!!n.hasAttestationKey,o=T();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)}});Ot.command("on").description("Require Touch ID for payments (security upgrade \u2014 no Touch ID needed)").action(async()=>{try{await k.getSessionToken()||(console.error("Not logged in. Run visa-cli setup first."),process.exit(1));let t=F(),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)}});Ot.command("off").description("Disable Touch ID requirement (security downgrade \u2014 one Touch ID confirmation required)").action(async()=>{try{await k.getSessionToken()||(console.error("Not logged in. Run visa-cli setup first."),process.exit(1));let t=F(),n=await t.getStatus();if(n.attestationRequired===!1){console.log("Touch ID is already disabled.");return}n.hasAttestationKey&&!T()&&(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 $t(t,async()=>{let s;if(n.hasAttestationKey&&T())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 mt(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 ne=x.command("shell-hud").description("Manage the persistent Visa HUD shown in your shell prompt");function cr(){let e=On();e.installed||(console.error(e.message),process.exit(1)),console.log(e.message)}function lr(){let e=Nn();e.removed||(console.error(e.message),process.exit(1)),console.log(e.message)}ne.command("install").description("Install the persistent shell HUD into your zsh or bash rc file").action(cr);ne.command("enable").description("Enable the persistent shell HUD").action(cr);ne.command("uninstall").description("Remove the persistent shell HUD from your shell rc file").action(lr);ne.command("disable").description("Disable the persistent shell HUD").action(lr);ne.command("segment").description("Print the cached shell HUD segment").action(()=>{process.stdout.write(`${Ct()}
146
- `)});ne.command("doctor").description("Diagnose shell HUD installation and connectivity").action(async()=>{let{existsSync:e,readFileSync:t}=await import("fs"),n=!0,r=(f,d,m)=>{console.log(` ${d?"\u2713":"\u2717"} ${f}: ${m}`),d||(n=!1)};console.log(`Shell HUD Doctor
147
- `);let s=Ke();if(r("Shell detected",!!s,s??"none (zsh, bash, or PowerShell required)"),s){let f=qe(s),d=e(f);if(r("RC file exists",d,f.replace(j.homedir(),"~")),d){let v=t(f,"utf-8").includes("visa-cli shell hud v2");r("HUD block installed",v,v?"found in rc file":"missing \u2014 run: visa-cli shell-hud install")}}let o=me(),i=e(o);if(r("Cache file",i,i?o.replace(j.homedir(),"~"):"missing \u2014 HUD has not refreshed yet"),i)try{let f=JSON.parse(t(o,"utf-8")),d=Date.now()-(f.renderedAt??0),m=Math.round(d/1e3),v=m<=30;console.log(` ${v?"\u2713":"\u26A0"} Cache freshness: ${m}s old${v?"":" (stale \u2014 will refresh on next prompt)"}`)}catch{r("Cache readable",!1,"corrupt JSON")}let a=Be(),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 k.getSessionToken()}catch{}if(r("Auth token",u,u?"found in keychain":"missing \u2014 run: visa-cli setup"),u)try{await F().getStatus(),r("API connectivity",!0,"GET /v1/status OK")}catch(f){let d=f instanceof Error?f.message:"unknown error";r("API connectivity",!1,d)}console.log(n?`
148
+ ${Ys()}`).action((e,t)=>{try{let n=hn(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 oe||n instanceof ie?console.error(`Error: ${n.message}`):console.error(`Error: ${n.message}`),process.exit(1)}});Dt.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=yn(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 Mt=A.command("biometric").description("Manage Touch ID / biometric attestation enforcement");Mt.command("status").description("Show current biometric enforcement state").action(async()=>{try{await E.getSessionToken()||(console.error("Not logged in. Run visa-cli setup first."),process.exit(1));let n=await F().getStatus(),r=n.attestationRequired!==!1,s=!!n.hasAttestationKey,o=O();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)}});Mt.command("on").description("Require Touch ID for payments (security upgrade \u2014 no Touch ID needed)").action(async()=>{try{await E.getSessionToken()||(console.error("Not logged in. Run visa-cli setup first."),process.exit(1));let t=F(),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)}});Mt.command("off").description("Disable Touch ID requirement (security downgrade \u2014 one Touch ID confirmation required)").action(async()=>{try{await E.getSessionToken()||(console.error("Not logged in. Run visa-cli setup first."),process.exit(1));let t=F(),n=await t.getStatus();if(n.attestationRequired===!1){console.log("Touch ID is already disabled.");return}n.hasAttestationKey&&!O()&&(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 Rt(t,async()=>{let s;if(n.hasAttestationKey&&O())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 St(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 re=A.command("shell-hud").description("Manage the persistent Visa HUD shown in your shell prompt");function gr(){let e=Un();e.installed||(console.error(e.message),process.exit(1)),console.log(e.message)}function mr(){let e=jn();e.removed||(console.error(e.message),process.exit(1)),console.log(e.message)}re.command("install").description("Install the persistent shell HUD into your zsh or bash rc file").action(gr);re.command("enable").description("Enable the persistent shell HUD").action(gr);re.command("uninstall").description("Remove the persistent shell HUD from your shell rc file").action(mr);re.command("disable").description("Disable the persistent shell HUD").action(mr);re.command("segment").description("Print the cached shell HUD segment").action(()=>{process.stdout.write(`${Et()}
149
+ `)});re.command("doctor").description("Diagnose shell HUD installation and connectivity").action(async()=>{let{existsSync:e,readFileSync:t}=await import("fs"),n=!0,r=(d,y,b)=>{console.log(` ${y?"\u2713":"\u2717"} ${d}: ${b}`),y||(n=!1)};console.log(`Shell HUD Doctor
150
+ `);let s=Ge();if(r("Shell detected",!!s,s??"none (zsh, bash, or PowerShell required)"),s){let d=Je(s),y=e(d);if(r("RC file exists",y,d.replace(H.homedir(),"~")),y){let C=t(d,"utf-8").includes("visa-cli shell hud v2");r("HUD block installed",C,C?"found in rc file":"missing \u2014 run: visa-cli shell-hud install")}}let o=Se(),i=e(o);if(r("Cache file",i,i?o.replace(H.homedir(),"~"):"missing \u2014 HUD has not refreshed yet"),i)try{let d=JSON.parse(t(o,"utf-8")),y=Date.now()-(d.renderedAt??0),b=Math.round(y/1e3),C=b<=30;console.log(` ${C?"\u2713":"\u26A0"} Cache freshness: ${b}s old${C?"":" (stale \u2014 will refresh on next prompt)"}`)}catch{r("Cache readable",!1,"corrupt JSON")}let a=We(),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 E.getSessionToken()}catch{}if(r("Auth token",u,u?"found in keychain":"missing \u2014 run: visa-cli setup"),u)try{await F().getStatus(),r("API connectivity",!0,"GET /v1/status OK")}catch(d){let y=d instanceof Error?d.message:"unknown error";r("API connectivity",!1,y)}console.log(n?`
148
151
  All checks passed.`:`
149
- Some checks failed \u2014 see above.`),n||process.exit(1)});ne.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&&Dn()))try{let t=F(),n=await t.getStatus(),r={currentVersion:t.getClientVersion(),latestVersion:t.lastSignals.updateAvailable?.version,updateMessage:t.lastSignals.updateAvailable?.message,updateCheckDisabled:q()},s=_t(n,r);kt(s)}catch{}finally{ge()}});x.command("statusline").description("Output the multi-line Visa HUD for Claude Code statusLine integration").action(async()=>{let e=await Zt(),n=Ct().split(`
150
- `)[0],r=await en(n,e);process.stdout.write(`${r}
151
- `)});var ur=x.command("hud").description("Manage the Visa HUD pinned below Claude Code input");ur.command("enable").description("Register Visa HUD as the Claude Code statusLine").action(()=>{let e=we.join(j.homedir(),".claude","settings.json"),t=st(e);console.log(t.message),(t.installed==="error"||t.installed==="malformed-json")&&process.exit(1)});ur.command("disable").description("Remove Visa HUD from Claude Code statusLine (leaves other tools untouched)").action(()=>{let e=we.join(j.homedir(),".claude","settings.json"),t=Gt(e);console.log(t.message),t.removed||process.exit(1)});x.hook("postAction",()=>{if(be){be=!1;return}Je&&En(Je.lastSignals)});x.parse();
152
+ Some checks failed \u2014 see above.`),n||process.exit(1)});re.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&&Hn()))try{let t=F(),n=await t.getStatus(),r={currentVersion:t.getClientVersion(),latestVersion:t.lastSignals.updateAvailable?.version,updateMessage:t.lastSignals.updateAvailable?.message,updateCheckDisabled:K()},s=$t(n,r);xt(s)}catch{}finally{ye()}});A.command("statusline").description("Output the multi-line Visa HUD for Claude Code statusLine integration").action(async()=>{let e=await nn(),n=Et().split(`
153
+ `)[0],r=await sn(n,e);process.stdout.write(`${r}
154
+ `)});var hr=A.command("hud").description("Manage the Visa HUD pinned below Claude Code input");hr.command("enable").description("Register Visa HUD as the Claude Code statusLine").action(()=>{let e=ke.join(H.homedir(),".claude","settings.json"),t=at(e);console.log(t.message),(t.installed==="error"||t.installed==="malformed-json")&&process.exit(1)});hr.command("disable").description("Remove Visa HUD from Claude Code statusLine (leaves other tools untouched)").action(()=>{let e=ke.join(H.homedir(),".claude","settings.json"),t=Xt(e);console.log(t.message),t.removed||process.exit(1)});A.hook("postAction",()=>{if(Ce){Ce=!1;return}Xe&&Tn(Xe.lastSignals)});A.parse();