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