@flapcode/cli 1.3.3 → 1.3.4

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/flapcode.cjs CHANGED
@@ -119,8 +119,8 @@ Filtered results for: ${this.inputValue?this.inputValue:ee.gray("Enter something
119
119
  `),this.close()}_(e,t){return e.toLowerCase()==="y"?(this.value=!0,this.submit()):e.toLowerCase()==="n"?(this.value=!1,this.submit()):this.bell()}render(){this.closed||(this.firstRender?this.out.write(Do.hide):this.out.write(Bu(this.outputText,this.out.columns)),super.render(),this.outputText=[Io.symbol(this.done,this.aborted),Mo.bold(this.msg),Io.delimiter(this.done),this.done?this.value?this.yesMsg:this.noMsg:Mo.gray(this.initialValue?this.yesOption:this.noOption)].join(" "),this.out.write(Yu.line+Do.to(0)+this.outputText))}};jo.exports=ki});var Fo=c((Kd,Ho)=>{"use strict";Ho.exports={TextPrompt:Dn(),SelectPrompt:Fn(),TogglePrompt:Gn(),DatePrompt:go(),NumberPrompt:_o(),MultiselectPrompt:Ai(),AutocompletePrompt:Po(),AutocompleteMultiselectPrompt:ko(),ConfirmPrompt:Vo()}});var No=c(Ro=>{"use strict";var P=Ro,Uu=Fo(),tt=i=>i;function B(i,e,t={}){return new Promise((s,r)=>{let n=new Uu[i](e),o=t.onAbort||tt,a=t.onSubmit||tt,l=t.onExit||tt;n.on("state",e.onState||tt),n.on("submit",h=>s(a(h))),n.on("exit",h=>s(l(h))),n.on("abort",h=>r(o(h)))})}P.text=i=>B("TextPrompt",i);P.password=i=>(i.style="password",P.text(i));P.invisible=i=>(i.style="invisible",P.text(i));P.number=i=>B("NumberPrompt",i);P.date=i=>B("DatePrompt",i);P.confirm=i=>B("ConfirmPrompt",i);P.list=i=>{let e=i.separator||",";return B("TextPrompt",i,{onSubmit:t=>t.split(e).map(s=>s.trim())})};P.toggle=i=>B("TogglePrompt",i);P.select=i=>B("SelectPrompt",i);P.multiselect=i=>{i.choices=[].concat(i.choices||[]);let e=t=>t.filter(s=>s.selected).map(s=>s.value);return B("MultiselectPrompt",i,{onAbort:e,onSubmit:e})};P.autocompleteMultiselect=i=>{i.choices=[].concat(i.choices||[]);let e=t=>t.filter(s=>s.selected).map(s=>s.value);return B("AutocompleteMultiselectPrompt",i,{onAbort:e,onSubmit:e})};var Wu=(i,e)=>Promise.resolve(e.filter(t=>t.title.slice(0,i.length).toLowerCase()===i.toLowerCase()));P.autocomplete=i=>(i.suggest=i.suggest||Wu,i.choices=[].concat(i.choices||[]),B("AutocompletePrompt",i))});var Bo=c((Zd,Go)=>{"use strict";var Mi=No(),Ju=["suggest","format","onState","validate","onRender","type"],Lo=()=>{};async function ae(i=[],{onSubmit:e=Lo,onCancel:t=Lo}={}){let s={},r=ae._override||{};i=[].concat(i);let n,o,a,l,h,d,f=async(p,O,b=!1)=>{if(!(!b&&p.validate&&p.validate(O)!==!0))return p.format?await p.format(O,s):O};for(o of i)if({name:l,type:h}=o,typeof h=="function"&&(h=await h(n,{...s},o),o.type=h),!!h){for(let p in o){if(Ju.includes(p))continue;let O=o[p];o[p]=typeof O=="function"?await O(n,{...s},d):O}if(d=o,typeof o.message!="string")throw new Error("prompt message is required");if({name:l,type:h}=o,Mi[h]===void 0)throw new Error(`prompt type (${h}) is not defined`);if(r[o.name]!==void 0&&(n=await f(o,r[o.name]),n!==void 0)){s[l]=n;continue}try{n=ae._injected?Ku(ae._injected,o.initial):await Mi[h](o),s[l]=n=await f(o,n,!0),a=await e(o,n,s)}catch{a=!await t(o,s)}if(a)return s}return s}function Ku(i,e){let t=i.shift();if(t instanceof Error)throw t;return t===void 0?e:t}function zu(i){ae._injected=(ae._injected||[]).concat(i)}function Zu(i){ae._override=Object.assign({},i)}Go.exports=Object.assign(ae,{prompt:ae,prompts:Mi,inject:zu,override:Zu})});var Ie=c((Xd,Yo)=>{function Xu(i){i=(Array.isArray(i)?i:i.split(".")).map(Number);let e=0,t=process.versions.node.split(".").map(Number);for(;e<i.length;e++){if(t[e]>i[e])return!1;if(i[e]>t[e])return!0}return!1}Yo.exports=Xu("8.6.0")?mn():Bo()});var ls=$(as(),1),{program:Pc,createCommand:Ec,createArgument:qc,createOption:Tc,CommanderError:kc,InvalidArgumentError:Mc,InvalidOptionArgumentError:Ic,Command:hs,Argument:Dc,Option:jc,Help:Vc}=ls.default;var xt,cs,ds,fs,ps=!0;typeof process<"u"&&({FORCE_COLOR:xt,NODE_DISABLE_COLORS:cs,NO_COLOR:ds,TERM:fs}=process.env||{},ps=process.stdout&&process.stdout.isTTY);var m={enabled:!cs&&ds==null&&fs!=="dumb"&&(xt!=null&&xt!=="0"||ps),reset:w(0,0),bold:w(1,22),dim:w(2,22),italic:w(3,23),underline:w(4,24),inverse:w(7,27),hidden:w(8,28),strikethrough:w(9,29),black:w(30,39),red:w(31,39),green:w(32,39),yellow:w(33,39),blue:w(34,39),magenta:w(35,39),cyan:w(36,39),white:w(37,39),gray:w(90,39),grey:w(90,39),bgBlack:w(40,49),bgRed:w(41,49),bgGreen:w(42,49),bgYellow:w(43,49),bgBlue:w(44,49),bgMagenta:w(45,49),bgCyan:w(46,49),bgWhite:w(47,49)};function us(i,e){let t=0,s,r="",n="";for(;t<i.length;t++)s=i[t],r+=s.open,n+=s.close,~e.indexOf(s.close)&&(e=e.replace(s.rgx,s.close+s.open));return r+e+n}function Ja(i,e){let t={has:i,keys:e};return t.reset=m.reset.bind(t),t.bold=m.bold.bind(t),t.dim=m.dim.bind(t),t.italic=m.italic.bind(t),t.underline=m.underline.bind(t),t.inverse=m.inverse.bind(t),t.hidden=m.hidden.bind(t),t.strikethrough=m.strikethrough.bind(t),t.black=m.black.bind(t),t.red=m.red.bind(t),t.green=m.green.bind(t),t.yellow=m.yellow.bind(t),t.blue=m.blue.bind(t),t.magenta=m.magenta.bind(t),t.cyan=m.cyan.bind(t),t.white=m.white.bind(t),t.gray=m.gray.bind(t),t.grey=m.grey.bind(t),t.bgBlack=m.bgBlack.bind(t),t.bgRed=m.bgRed.bind(t),t.bgGreen=m.bgGreen.bind(t),t.bgYellow=m.bgYellow.bind(t),t.bgBlue=m.bgBlue.bind(t),t.bgMagenta=m.bgMagenta.bind(t),t.bgCyan=m.bgCyan.bind(t),t.bgWhite=m.bgWhite.bind(t),t}function w(i,e){let t={open:`\x1B[${i}m`,close:`\x1B[${e}m`,rgx:new RegExp(`\\x1b\\[${e}m`,"g")};return function(s){return this!==void 0&&this.has!==void 0?(~this.has.indexOf(i)||(this.has.push(i),this.keys.push(t)),s===void 0?this:m.enabled?us(this.keys,s+""):s+""):s===void 0?Ja([i],[t]):m.enabled?us([t],s+""):s+""}}var u=m;var it=$(Ie(),1),ji=$(require("node:readline"),1);var de=$(require("node:fs"),1),ye=$(require("node:path"),1),Wo=$(require("node:os"),1),Qu=ye.default.join(Wo.default.homedir(),".flapcode"),ec=ye.default.join(Qu,"config.json"),tc=ye.default.join(process.cwd(),".flapcode"),Uo=ye.default.join(tc,"config.json"),Ii={api_base:"https://flapcode.com",api_token:null,current_claude_account:null,current_codex_account:null};function S(){let i=Ko();if(!de.default.existsSync(i))return{...Ii};try{return{...Ii,...JSON.parse(de.default.readFileSync(i,"utf8"))}}catch{return{...Ii}}}function V(i){let e=Ko(),t=ye.default.dirname(e);de.default.existsSync(t)||de.default.mkdirSync(t,{recursive:!0});let s=S();de.default.writeFileSync(e,JSON.stringify({...s,...i},null,2),"utf8")}function Jo(){V({api_token:null})}function Ko(){return de.default.existsSync(Uo)?Uo:ec}var le=class extends Error{constructor(e,t){super(e),this.statusCode=t}};async function De(i,e={}){let t=S();if(!t.api_token)throw new le("\u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u8FD0\u884C flapcode login",401);let s=`${t.api_base}${i}`,r=await fetch(s,{...e,headers:{Authorization:`Bearer ${t.api_token}`,"Content-Type":"application/json",...e.headers}}),n=await r.json().catch(()=>({statusMessage:r.statusText}));if(!r.ok)throw new le(n.statusMessage||n.message||`HTTP ${r.status}`,r.status);return n}async function ic(i,e={}){let s=`${S().api_base}${i}`,r=await fetch(s,{...e,headers:{"Content-Type":"application/json",...e.headers}}),n=await r.json().catch(()=>({statusMessage:r.statusText}));if(!r.ok)throw new le(n.statusMessage||n.message||`HTTP ${r.status}`,r.status);return n}async function H(i){return De(`/api/cli/accounts?provider=${i}`)}async function te(i,e){let t=e?`?provider=${i}&account_email=${encodeURIComponent(e)}`:`?provider=${i}`;return De(`/api/cli/config${t}`)}async function zo(){return De("/api/cli/me")}async function Zo(i,e){let t=await ic("/api/auth/login",{method:"POST",body:JSON.stringify({email:i,password:e})});if(t?.code!==0||!t?.data?.token)throw new le(t?.message||"\u767B\u5F55\u5931\u8D25",401);return t.data}async function Xo(i){let t=`${S().api_base}/api/user/get-api-token`,s=await fetch(t,{method:"GET",headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json"}}),r=await s.json().catch(()=>({statusMessage:s.statusText}));if(!s.ok)throw new le(r.statusMessage||r.message||`HTTP ${s.status}`,s.status);if(r?.code!==0||!r?.data?.api_token)throw new le(r?.message||"\u83B7\u53D6 API Token \u5931\u8D25",500);return r.data.api_token}async function Qo(i={}){if(S().api_token)if(console.log(u.yellow("\u5DF2\u767B\u5F55\u3002\u5982\u9700\u91CD\u65B0\u767B\u5F55\uFF0C\u8BF7\u5148\u8FD0\u884C flapcode logout")),i.token)console.log(u.dim("\u68C0\u6D4B\u5230 --token\uFF0C\u8986\u76D6\u73B0\u6709 token"));else{let{confirm:n}=await(0,it.default)({type:"confirm",name:"confirm",message:"\u662F\u5426\u8986\u76D6\u73B0\u6709 token\uFF1F",initial:!1});if(!n)return}let t=i.token?.trim(),s=i.email?.trim(),r;if(!t&&s&&(r=await Di("\u8BF7\u8F93\u5165\u767B\u5F55\u5BC6\u7801: ")),!t&&!s&&(await rc()==="password"?(s=(await nc("\u8BF7\u8F93\u5165\u767B\u5F55\u90AE\u7BB1: ")).trim(),r=await Di("\u8BF7\u8F93\u5165\u767B\u5F55\u5BC6\u7801: ")):t=await Di("\u8BF7\u7C98\u8D34 Flapcode API Token\uFF08\u53EF\u5728\u201C\u4E2A\u4EBA\u4E2D\u5FC3\u201D -> \u201CAPI \u8BBF\u95EE\u4EE4\u724C\u201D\u4E2D\u83B7\u53D6\uFF09: ")),!t&&s){if(!r){console.log(u.red("\u5DF2\u53D6\u6D88"));return}let n=await Zo(s,r);t=await Xo(n.token)}if(!t){console.log(u.red("\u5DF2\u53D6\u6D88"));return}V({api_token:t});try{let n=await De("/api/cli/me");await sc(),console.log(u.green(`\u2713 \u767B\u5F55\u6210\u529F\uFF01\u5F53\u524D\u7528\u6237\uFF1A${n.email??n.username??JSON.stringify(n)}`))}catch(n){V({api_token:null}),console.error(u.red(`\u2717 Token \u9A8C\u8BC1\u5931\u8D25\uFF1A${n.message}`)),process.exit(1)}}async function sc(){let i=S(),e={};if(!i.current_claude_account){let t=await H("claude").catch(()=>[]);t.length>0&&(e.current_claude_account=t[0].account_email)}if(!i.current_codex_account){let t=await H("codex").catch(()=>[]);t.length>0&&(e.current_codex_account=t[0].account_email)}Object.keys(e).length>0&&V(e)}async function rc(){return(await(0,it.default)({type:"select",name:"mode",message:"\u9009\u62E9\u767B\u5F55\u65B9\u5F0F",choices:[{title:"API Token",value:"token"},{title:"\u90AE\u7BB1\u548C\u5BC6\u7801",value:"password"}],initial:0})).mode??"token"}async function nc(i){return await new Promise(e=>{let t=ji.default.createInterface({input:process.stdin,output:process.stdout});t.question(i,s=>{t.close(),process.stdin.isTTY&&process.stdin.pause(),e(s)})})}async function Di(i){return!process.stdin.isTTY||!process.stdout.isTTY?(await(0,it.default)({type:"password",name:"token",message:i.trim(),validate:t=>t.trim().length>0||"\u4E0D\u80FD\u4E3A\u7A7A"})).token?.trim():await new Promise(e=>{let t=process.stdin,s=process.stdout,r=t.isRaw===!0,n="";ji.default.emitKeypressEvents(t),t.setRawMode(!0),t.resume(),s.write(i);let o=(l,h)=>{if(h?.ctrl&&h.name==="c"&&(a(),s.write(`
120
120
  `),process.exit(130)),h?.name==="escape"){a(),s.write(`
121
121
  `),e("");return}if(h?.name==="return"||h?.name==="enter"){a(),s.write(`
122
- `),e(n.trim());return}if(h?.name==="backspace"){if(!n.length)return;n=n.slice(0,-1),s.write("\b \b");return}!l||h?.ctrl||h?.meta||(n+=l,s.write("*"))};function a(){t.off("keypress",o),t.isTTY&&t.setRawMode(r),t.pause()}t.on("keypress",o)})}var ea=$(Ie(),1);async function ta(){if(!S().api_token){console.log(u.yellow("\u5F53\u524D\u672A\u767B\u5F55"));return}let{confirm:e}=await(0,ea.default)({type:"confirm",name:"confirm",message:"\u786E\u8BA4\u9000\u51FA\u767B\u5F55\uFF1F",initial:!1});if(!e){console.log("\u5DF2\u53D6\u6D88");return}Jo(),console.log(u.green("\u2713 \u5DF2\u9000\u51FA\u767B\u5F55"))}var fe=require("node:child_process"),oc="https://registry.npmjs.org";function _e(){try{(0,fe.execSync)("npm --version",{stdio:"ignore"})}catch{throw new Error("\u672A\u627E\u5230 npm\uFF0C\u8BF7\u5148\u5B89\u88C5 Node.js\uFF08https://nodejs.org\uFF09")}}function st(i){try{let e=(0,fe.execSync)("npm list -g --depth=0 --json",{encoding:"utf8"}),t=JSON.parse(e);return i in(t.dependencies||{})}catch{return!1}}function ve(i){let e=(0,fe.spawnSync)("npm",["install","-g",i],{stdio:"inherit",encoding:"utf8"});if(e.status!==0)throw new Error(`npm install -g ${i} \u5931\u8D25\uFF08exit code ${e.status}\uFF09`)}function Vi(i){try{return(0,fe.execSync)(`${i} --version`,{encoding:"utf8",timeout:5e3,stdio:["ignore","pipe","ignore"]}).trim().match(/\d+\.\d+\.\d+/)?.[0]??null}catch{return null}}function Hi(i){try{let e=(0,fe.execSync)("npm list -g --depth=0 --json",{encoding:"utf8"});return JSON.parse(e).dependencies?.[i]?.version??null}catch{return null}}async function ia(i){try{let e=await fetch(`${oc}/${encodeURIComponent(i)}`,{headers:{Accept:"application/json"}});return e.ok?(await e.json())?.["dist-tags"]?.latest??null:null}catch{return null}}function sa(i,e){let t=String(i||"").split(".").map(n=>Number.parseInt(n,10)||0),s=String(e||"").split(".").map(n=>Number.parseInt(n,10)||0),r=Math.max(t.length,s.length);for(let n=0;n<r;n+=1){let o=t[n]??0,a=s[n]??0;if(o>a)return 1;if(o<a)return-1}return 0}var ra=require("node:child_process"),M=$(require("node:fs"),1),na=$(require("node:os"),1),ie=$(require("node:path"),1),ac=ie.default.join("@anthropic-ai","claude-code");function lc(){return process.platform!=="linux"?null:process.arch==="x64"?ie.default.join("node_modules","@anthropic-ai","claude-code-linux-x64","claude"):process.arch==="arm64"?ie.default.join("node_modules","@anthropic-ai","claude-code-linux-arm64","claude"):null}function hc(){try{return(0,ra.execSync)("npm root -g",{encoding:"utf8"}).trim()}catch{return null}}function Fi(){let i=[],e=new Set,t=(a,l)=>{!a||e.has(a)||M.default.existsSync(a)&&(e.add(a),i.push({path:a,type:l}))},s=hc(),r=lc();if(s){let a=ie.default.join(s,ac);t(ie.default.join(a,"cli.js"),"js"),r&&t(ie.default.join(a,r),"binary")}let n=process.env.XDG_BIN_HOME||ie.default.join(na.default.homedir(),".local","bin"),o=ie.default.join(n,"claude");if(M.default.existsSync(o)){let a=o;try{a=M.default.realpathSync(o)}catch{}t(a,"binary")}if(i.length===0){let a=r?"\uFF08\u5DF2\u5C1D\u8BD5 npm root -g \u4E0B\u7684 cli.js / \u539F\u751F binary\uFF0C\u4EE5\u53CA ~/.local/bin/claude\uFF09":"\uFF08\u5DF2\u5C1D\u8BD5 npm root -g \u4E0B\u7684 cli.js \u4E0E ~/.local/bin/claude\uFF1B\u5F53\u524D\u5E73\u53F0\u6682\u672A\u652F\u6301 npm \u5305\u5185\u7684\u539F\u751F binary patch\uFF09";throw new Error(`\u627E\u4E0D\u5230 claude-code \u5B89\u88C5\u76EE\u6807 ${a}\uFF0C\u8BF7\u5148\u8FD0\u884C flapcode claude install`)}return i}function oa(i){let e=`${i}.bak`;M.default.existsSync(e)||M.default.copyFileSync(i,e)}function uc(i,e){let t=M.default.readFileSync(i,"utf8");if(e.every(({from:r})=>!t.includes(r)))return{patched:!1,alreadyPatched:!0};oa(i);for(let{from:r,to:n}of e)t.includes(r)&&(t=t.split(r).join(n));return M.default.writeFileSync(i,t,"utf8"),{patched:!0,alreadyPatched:!1}}function cc(i,e){let t=M.default.readFileSync(i),s=[],r=[];for(let{from:o,to:a}of e){let l=Buffer.from(o,"utf8"),h=Buffer.from(a,"utf8");if(l.length!==h.length){r.push({from:o,to:a,fromBytes:l.length,toBytes:h.length,reason:"length-mismatch"});continue}s.push({fromBuf:l,toBuf:h})}if(s.length===0)return{patched:!1,alreadyPatched:!1,skippedRules:r};if(s.every(({fromBuf:o})=>!t.includes(o)))return{patched:!1,alreadyPatched:!0,skippedRules:r};oa(i);for(let{fromBuf:o,toBuf:a}of s){let l=0;for(;(l=t.indexOf(o,l))!==-1;)a.copy(t,l),l+=a.length}return M.default.writeFileSync(i,t),{patched:!0,alreadyPatched:!1,skippedRules:r}}function aa(i){let e=Fi(),t=!1,s=!0,r=new Map;for(let{path:n,type:o}of e){let a=o==="binary"?cc(n,i):uc(n,i);if(a.patched&&(t=!0),a.alreadyPatched||(s=!1),a.skippedRules)for(let l of a.skippedRules)r.has(l.from)||r.set(l.from,l)}return{patched:t,alreadyPatched:!t&&s,skippedBinaryRules:[...r.values()]}}function la({path:i,type:e}){try{return e==="binary"?M.default.readFileSync(i):M.default.readFileSync(i,"utf8")}catch{return null}}function ha(i,e){return i===null?!1:Buffer.isBuffer(i)?i.includes(Buffer.from(e,"utf8")):i.includes(e)}function ua(i){let e;try{e=Fi()}catch{return null}let t=e.map(la);return i.map(({from:s,to:r})=>({from:s,to:r,applied:t.every(n=>!ha(n,s))}))}function ca(){try{let i=Fi();return i.length===0?!1:i.every(e=>ha(la(e),"gate.flapcode.com"))}catch{return!1}}var dc="@flapcode/cli",fc=10;async function fa(){let i=S();if(await pc(),!i.api_token){console.log(),console.log(u.red("\u2717 \u672A\u767B\u5F55")+" \u2192 \u8FD0\u884C flapcode login");return}let e="...";try{let s=await zo();e=s.email??s.username??"(\u672A\u77E5)",E("\u767B\u5F55\u72B6\u6001",u.green("\u2713 \u5DF2\u767B\u5F55"),u.dim(e))}catch(s){E("\u767B\u5F55\u72B6\u6001",u.red("\u2717 \u767B\u5F55\u5931\u6548"),u.dim(s.message))}pe("\u767B\u5F55\u7F51\u7AD9",i.api_base),console.log(u.bold(`
123
- Claude Code`));let t=Vi("claude");if(t?E("\u5B89\u88C5\u72B6\u6001",u.green("\u2713 \u5DF2\u5B89\u88C5"),`v${t}`):E("\u5B89\u88C5\u72B6\u6001",u.yellow("\u2717 \u672A\u5B89\u88C5"),"\u2192 \u8FD0\u884C flapcode claude install"),i.current_claude_account?pe("\u5F53\u524D\u8D26\u53F7",u.cyan(i.current_claude_account)):pe("\u5F53\u524D\u8D26\u53F7",u.dim("\u672A\u8BBE\u7F6E")),t)try{if(ca())return E("Patch",u.green("\u2713 \u5DF2\u751F\u6548")),da(i);let r=(i.current_claude_account?await te("claude",i.current_claude_account).catch(()=>null):null)?.patch_rules;r?.length?ua(r)?.every(a=>a.applied)?E("Patch",u.green("\u2713 \u5DF2\u751F\u6548")):E("Patch",u.yellow("\u2717 \u672A\u751F\u6548"),"\u2192 \u8FD0\u884C flapcode claude patch"):i.current_claude_account?E("Patch",u.dim("\u672A\u77E5"),"\uFF08\u65E0\u6CD5\u83B7\u53D6 patch \u89C4\u5219\uFF09"):E("Patch",u.dim("\u672A\u77E5"),"\uFF08\u672A\u8BBE\u7F6E Claude \u8D26\u53F7\uFF0C\u65E0\u6CD5\u83B7\u53D6 patch \u89C4\u5219\uFF09")}catch{E("Patch",u.dim("\u672A\u77E5"),"\uFF08\u68C0\u67E5\u5931\u8D25\uFF09")}da(i)}async function pc(){console.log(u.bold("Flapcode CLI")),E("\u5F53\u524D\u7248\u672C",u.green("\u2713 \u5DF2\u5B89\u88C5"),"v1.3.3");let i=await ia(dc);if(!i){pe("\u6700\u65B0\u7248\u672C",u.dim("\u68C0\u67E5\u5931\u8D25\u6216\u7F51\u7EDC\u4E0D\u53EF\u7528"));return}pe("\u6700\u65B0\u7248\u672C",`v${i}`),sa("1.3.3",i)<0&&E("\u5347\u7EA7\u63D0\u793A",u.yellow("\u21BB \u53EF\u5347\u7EA7"),"\u8FD0\u884C flapcode update")}function da(i){console.log(u.bold(`
122
+ `),e(n.trim());return}if(h?.name==="backspace"){if(!n.length)return;n=n.slice(0,-1),s.write("\b \b");return}!l||h?.ctrl||h?.meta||(n+=l,s.write("*"))};function a(){t.off("keypress",o),t.isTTY&&t.setRawMode(r),t.pause()}t.on("keypress",o)})}var ea=$(Ie(),1);async function ta(){if(!S().api_token){console.log(u.yellow("\u5F53\u524D\u672A\u767B\u5F55"));return}let{confirm:e}=await(0,ea.default)({type:"confirm",name:"confirm",message:"\u786E\u8BA4\u9000\u51FA\u767B\u5F55\uFF1F",initial:!1});if(!e){console.log("\u5DF2\u53D6\u6D88");return}Jo(),console.log(u.green("\u2713 \u5DF2\u9000\u51FA\u767B\u5F55"))}var fe=require("node:child_process"),oc="https://registry.npmjs.org";function _e(){try{(0,fe.execSync)("npm --version",{stdio:"ignore"})}catch{throw new Error("\u672A\u627E\u5230 npm\uFF0C\u8BF7\u5148\u5B89\u88C5 Node.js\uFF08https://nodejs.org\uFF09")}}function st(i){try{let e=(0,fe.execSync)("npm list -g --depth=0 --json",{encoding:"utf8"}),t=JSON.parse(e);return i in(t.dependencies||{})}catch{return!1}}function ve(i){let e=(0,fe.spawnSync)("npm",["install","-g",i],{stdio:"inherit",encoding:"utf8"});if(e.status!==0)throw new Error(`npm install -g ${i} \u5931\u8D25\uFF08exit code ${e.status}\uFF09`)}function Vi(i){try{return(0,fe.execSync)(`${i} --version`,{encoding:"utf8",timeout:5e3,stdio:["ignore","pipe","ignore"]}).trim().match(/\d+\.\d+\.\d+/)?.[0]??null}catch{return null}}function Hi(i){try{let e=(0,fe.execSync)("npm list -g --depth=0 --json",{encoding:"utf8"});return JSON.parse(e).dependencies?.[i]?.version??null}catch{return null}}async function ia(i){try{let e=await fetch(`${oc}/${encodeURIComponent(i)}`,{headers:{Accept:"application/json"}});return e.ok?(await e.json())?.["dist-tags"]?.latest??null:null}catch{return null}}function sa(i,e){let t=String(i||"").split(".").map(n=>Number.parseInt(n,10)||0),s=String(e||"").split(".").map(n=>Number.parseInt(n,10)||0),r=Math.max(t.length,s.length);for(let n=0;n<r;n+=1){let o=t[n]??0,a=s[n]??0;if(o>a)return 1;if(o<a)return-1}return 0}var ra=require("node:child_process"),M=$(require("node:fs"),1),na=$(require("node:os"),1),ie=$(require("node:path"),1),ac=ie.default.join("@anthropic-ai","claude-code");function lc(){return process.platform!=="linux"?null:process.arch==="x64"?ie.default.join("node_modules","@anthropic-ai","claude-code-linux-x64","claude"):process.arch==="arm64"?ie.default.join("node_modules","@anthropic-ai","claude-code-linux-arm64","claude"):null}function hc(){try{return(0,ra.execSync)("npm root -g",{encoding:"utf8"}).trim()}catch{return null}}function Fi(){let i=[],e=new Set,t=(a,l)=>{!a||e.has(a)||M.default.existsSync(a)&&(e.add(a),i.push({path:a,type:l}))},s=hc(),r=lc();if(s){let a=ie.default.join(s,ac);t(ie.default.join(a,"cli.js"),"js"),r&&t(ie.default.join(a,r),"binary")}let n=process.env.XDG_BIN_HOME||ie.default.join(na.default.homedir(),".local","bin"),o=ie.default.join(n,"claude");if(M.default.existsSync(o)){let a=o;try{a=M.default.realpathSync(o)}catch{}t(a,"binary")}if(i.length===0){let a=r?"\uFF08\u5DF2\u5C1D\u8BD5 npm root -g \u4E0B\u7684 cli.js / \u539F\u751F binary\uFF0C\u4EE5\u53CA ~/.local/bin/claude\uFF09":"\uFF08\u5DF2\u5C1D\u8BD5 npm root -g \u4E0B\u7684 cli.js \u4E0E ~/.local/bin/claude\uFF1B\u5F53\u524D\u5E73\u53F0\u6682\u672A\u652F\u6301 npm \u5305\u5185\u7684\u539F\u751F binary patch\uFF09";throw new Error(`\u627E\u4E0D\u5230 claude-code \u5B89\u88C5\u76EE\u6807 ${a}\uFF0C\u8BF7\u5148\u8FD0\u884C flapcode claude install`)}return i}function oa(i){let e=`${i}.bak`;M.default.existsSync(e)||M.default.copyFileSync(i,e)}function uc(i,e){let t=M.default.readFileSync(i,"utf8");if(e.every(({from:r})=>!t.includes(r)))return{patched:!1,alreadyPatched:!0};oa(i);for(let{from:r,to:n}of e)t.includes(r)&&(t=t.split(r).join(n));return M.default.writeFileSync(i,t,"utf8"),{patched:!0,alreadyPatched:!1}}function cc(i,e){let t=M.default.readFileSync(i),s=[],r=[];for(let{from:o,to:a}of e){let l=Buffer.from(o,"utf8"),h=Buffer.from(a,"utf8");if(l.length!==h.length){r.push({from:o,to:a,fromBytes:l.length,toBytes:h.length,reason:"length-mismatch"});continue}s.push({fromBuf:l,toBuf:h})}if(s.length===0)return{patched:!1,alreadyPatched:!1,skippedRules:r};if(s.every(({fromBuf:o})=>!t.includes(o)))return{patched:!1,alreadyPatched:!0,skippedRules:r};oa(i);for(let{fromBuf:o,toBuf:a}of s){let l=0;for(;(l=t.indexOf(o,l))!==-1;)a.copy(t,l),l+=a.length}return M.default.writeFileSync(i,t),{patched:!0,alreadyPatched:!1,skippedRules:r}}function aa(i){let e=Fi(),t=!1,s=!0,r=new Map;for(let{path:n,type:o}of e){let a=o==="binary"?cc(n,i):uc(n,i);if(a.patched&&(t=!0),a.alreadyPatched||(s=!1),a.skippedRules)for(let l of a.skippedRules)r.has(l.from)||r.set(l.from,l)}return{patched:t,alreadyPatched:!t&&s,skippedBinaryRules:[...r.values()]}}function la({path:i,type:e}){try{return e==="binary"?M.default.readFileSync(i):M.default.readFileSync(i,"utf8")}catch{return null}}function ha(i,e){return i===null?!1:Buffer.isBuffer(i)?i.includes(Buffer.from(e,"utf8")):i.includes(e)}function ua(i){let e;try{e=Fi()}catch{return null}let t=e.map(la);return i.map(({from:s,to:r})=>({from:s,to:r,applied:t.every(n=>!ha(n,s))}))}function ca(){try{let i=Fi();return i.length===0?!1:i.every(e=>ha(la(e),"gate.takemoon.com"))}catch{return!1}}var dc="@flapcode/cli",fc=10;async function fa(){let i=S();if(await pc(),!i.api_token){console.log(),console.log(u.red("\u2717 \u672A\u767B\u5F55")+" \u2192 \u8FD0\u884C flapcode login");return}let e="...";try{let s=await zo();e=s.email??s.username??"(\u672A\u77E5)",E("\u767B\u5F55\u72B6\u6001",u.green("\u2713 \u5DF2\u767B\u5F55"),u.dim(e))}catch(s){E("\u767B\u5F55\u72B6\u6001",u.red("\u2717 \u767B\u5F55\u5931\u6548"),u.dim(s.message))}pe("\u767B\u5F55\u7F51\u7AD9",i.api_base),console.log(u.bold(`
123
+ Claude Code`));let t=Vi("claude");if(t?E("\u5B89\u88C5\u72B6\u6001",u.green("\u2713 \u5DF2\u5B89\u88C5"),`v${t}`):E("\u5B89\u88C5\u72B6\u6001",u.yellow("\u2717 \u672A\u5B89\u88C5"),"\u2192 \u8FD0\u884C flapcode claude install"),i.current_claude_account?pe("\u5F53\u524D\u8D26\u53F7",u.cyan(i.current_claude_account)):pe("\u5F53\u524D\u8D26\u53F7",u.dim("\u672A\u8BBE\u7F6E")),t)try{if(ca())return E("Patch",u.green("\u2713 \u5DF2\u751F\u6548")),da(i);let r=(i.current_claude_account?await te("claude",i.current_claude_account).catch(()=>null):null)?.patch_rules;r?.length?ua(r)?.every(a=>a.applied)?E("Patch",u.green("\u2713 \u5DF2\u751F\u6548")):E("Patch",u.yellow("\u2717 \u672A\u751F\u6548"),"\u2192 \u8FD0\u884C flapcode claude patch"):i.current_claude_account?E("Patch",u.dim("\u672A\u77E5"),"\uFF08\u65E0\u6CD5\u83B7\u53D6 patch \u89C4\u5219\uFF09"):E("Patch",u.dim("\u672A\u77E5"),"\uFF08\u672A\u8BBE\u7F6E Claude \u8D26\u53F7\uFF0C\u65E0\u6CD5\u83B7\u53D6 patch \u89C4\u5219\uFF09")}catch{E("Patch",u.dim("\u672A\u77E5"),"\uFF08\u68C0\u67E5\u5931\u8D25\uFF09")}da(i)}async function pc(){console.log(u.bold("Flapcode CLI")),E("\u5F53\u524D\u7248\u672C",u.green("\u2713 \u5DF2\u5B89\u88C5"),"v1.3.4");let i=await ia(dc);if(!i){pe("\u6700\u65B0\u7248\u672C",u.dim("\u68C0\u67E5\u5931\u8D25\u6216\u7F51\u7EDC\u4E0D\u53EF\u7528"));return}pe("\u6700\u65B0\u7248\u672C",`v${i}`),sa("1.3.4",i)<0&&E("\u5347\u7EA7\u63D0\u793A",u.yellow("\u21BB \u53EF\u5347\u7EA7"),"\u8FD0\u884C flapcode update")}function da(i){console.log(u.bold(`
124
124
  Codex`));let e=Vi("codex");e?E("\u5B89\u88C5\u72B6\u6001",u.green("\u2713 \u5DF2\u5B89\u88C5"),`v${e}`):E("\u5B89\u88C5\u72B6\u6001",u.yellow("\u2717 \u672A\u5B89\u88C5"),"\u2192 \u8FD0\u884C flapcode codex install"),i.current_codex_account?pe("\u5F53\u524D\u8D26\u53F7",u.cyan(i.current_codex_account)):pe("\u5F53\u524D\u8D26\u53F7",u.dim("\u672A\u8BBE\u7F6E")),console.log()}function pe(i,e){let t=pa(i);console.log(` ${u.dim(t)} ${e}`)}function E(i,e,t=""){let s=pa(i);console.log(` ${u.dim(s)} ${e}${t?` ${t}`:""}`)}function pa(i){let e=`${i}:`,t=mc(e),s=Math.max(1,fc-t);return`${e}${" ".repeat(s)}`}function mc(i){let e=0;for(let t of i)e+=gc(t)?2:1;return e}function gc(i){return/[^\u0000-\u00ff]/.test(i)}async function ma(i){let e=i.provider??null,t=S(),s=e?[e]:["claude","codex"],r=!1;for(let n of s){let o;try{o=await H(n)}catch(l){console.error(u.red(`\u2717 \u83B7\u53D6 ${n} \u8D26\u53F7\u5931\u8D25\uFF1A${l.message}`));continue}if(!Array.isArray(o)||o.length===0){console.log(u.yellow(` ${n}\uFF1A\u6682\u65E0\u53EF\u7528\u8D26\u53F7`));continue}console.log(u.bold(`
125
125
  ${n.toUpperCase()} \u8D26\u53F7`));let a=n==="claude"?t.current_claude_account:t.current_codex_account;o.forEach((l,h)=>{let d=l.account_email===a,f=d?u.green("* "):" ",p=u.dim(`[${h+1}]`),O=d?u.green(l.account_email):l.account_email,b=l.plan_name?u.dim(` (${l.plan_name})`):"",q=l.expires_at?u.dim(` \u5230\u671F: ${new Date(l.expires_at).toLocaleDateString()}`):"";console.log(`${f}${p} ${O}${b}${q}`)}),r=!0}r||console.log(u.yellow(`
126
126
  \u6CA1\u6709\u53EF\u7528\u8D26\u53F7\u3002\u8BF7\u786E\u8BA4\u5DF2\u767B\u5F55\u5E76\u62E5\u6709\u6709\u6548\u8BA2\u9605\u3002`))}var rt="@flapcode/cli";async function ga(){_e();let i=Hi(rt);console.log(i?`${u.dim("\u5F53\u524D\u5168\u5C40\u7248\u672C:")} v${i}`:u.yellow("\u672A\u68C0\u6D4B\u5230\u5168\u5C40\u5B89\u88C5\u7684 Flapcode CLI\uFF0C\u5C06\u76F4\u63A5\u5B89\u88C5\u6700\u65B0\u7248\u672C")),console.log(u.cyan(`
@@ -132,4 +132,4 @@ ${u.green("\u2713")} Flapcode CLI \u66F4\u65B0\u5B8C\u6210`)}var Yi=$(Ie(),1);va
132
132
  \u2713 Claude Code \u914D\u7F6E\u5B8C\u6210\uFF01`)),console.log(` \u8D26\u53F7: ${u.cyan(i.account_email)}`),console.log(` \u8FD0\u884C ${u.bold("claude")} \u5373\u53EF\u5F00\u59CB\u4F7F\u7528
133
133
  `)}async function _a(){let i=S();console.log(u.dim("\u6B63\u5728\u62C9\u53D6 patch \u89C4\u5219..."));let e=await te("claude",i.current_claude_account);await xa(e.patch_rules)}async function va(i){let e=i;if(!e||/^\d+$/.test(e)){let s=await H("claude");(!Array.isArray(s)||s.length===0)&&(console.error(u.red("\u2717 \u6CA1\u6709\u53EF\u7528\u7684 Claude \u8D26\u53F7")),process.exit(1));let r=/^\d+$/.test(e)?parseInt(e,10)-1:null;if(r!==null)(r<0||r>=s.length)&&(console.error(u.red(`\u2717 \u5E8F\u53F7 ${e} \u8D85\u51FA\u8303\u56F4\uFF08\u5171 ${s.length} \u4E2A\u8D26\u53F7\uFF09`)),process.exit(1)),e=s[r].account_email;else{let n=await(0,Yi.default)({type:"select",name:"email",message:"\u9009\u62E9 Claude \u8D26\u53F7",choices:s.map(o=>({title:o.account_email,value:o.account_email}))});if(!n.email){console.log("\u5DF2\u53D6\u6D88");return}e=n.email}}console.log(u.dim(`\u6B63\u5728\u5207\u6362\u5230 ${e}...`));let t=await te("claude",e);Ri(t.account),V({current_claude_account:e}),console.log(u.green(`\u2713 \u5DF2\u5207\u6362\u5230 ${e}`))}async function wc(i){let e;try{e=await H(i)}catch(n){console.error(u.red(`\u2717 \u83B7\u53D6\u8D26\u53F7\u5217\u8868\u5931\u8D25\uFF1A${n.message}`)),process.exit(1)}if((!Array.isArray(e)||e.length===0)&&(console.error(u.red("\u2717 \u6CA1\u6709\u53EF\u7528\u8D26\u53F7\uFF0C\u8BF7\u786E\u8BA4\u8BA2\u9605\u6709\u6548")),process.exit(1)),e.length===1)return console.log(u.dim(`\u4F7F\u7528\u8D26\u53F7: ${e[0].account_email}`)),e[0];let s=S().current_claude_account,{email:r}=await(0,Yi.default)({type:"select",name:"email",message:"\u9009\u62E9\u8981\u4F7F\u7528\u7684 Claude \u8D26\u53F7",choices:e.map(n=>({title:n.account_email+(n.plan_name?` (${n.plan_name})`:""),value:n.account_email,selected:n.account_email===s}))});return r?e.find(n=>n.account_email===r):(console.log("\u5DF2\u53D6\u6D88"),null)}async function xa(i){if(!i?.length){console.log(u.dim("\u670D\u52A1\u7AEF\u672A\u4E0B\u53D1 patch \u89C4\u5219\uFF0C\u8DF3\u8FC7"));return}console.log(u.dim("\u6B63\u5728\u5E94\u7528 patch..."));let{patched:e,alreadyPatched:t,skippedBinaryRules:s}=aa(i);if(t?console.log(u.dim("Patch \u5DF2\u751F\u6548\uFF0C\u65E0\u9700\u91CD\u590D\u64CD\u4F5C")):e&&console.log(u.green("\u2713 Patch \u5E94\u7528\u6210\u529F")),s?.length)for(let{from:r,to:n,fromBytes:o,toBytes:a}of s)console.log(u.yellow(`\u26A0 binary \u8DF3\u8FC7\u89C4\u5219 '${r}' \u2192 '${n}' (${o} \u2192 ${a} bytes \u4E0D\u7B49\u957F)`))}var Ca=$(require("node:fs"),1),Ui=$(Ie(),1);var je="@openai/codex";async function Oa(){_e(),st(je)?console.log(u.dim(`${je} \u5DF2\u5B89\u88C5\uFF0C\u8DF3\u8FC7`)):(console.log(u.cyan(`\u6B63\u5728\u5B89\u88C5 ${je}...`)),ve(je),console.log(u.green(`\u2713 ${je} \u5B89\u88C5\u5B8C\u6210`)));let i=await yc();if(!i)return;console.log(u.dim("\u6B63\u5728\u62C9\u53D6\u914D\u7F6E..."));let e=await te("codex",i.account_email),t=Ni({api_token:e.api_token}),s=Li({base_url:e.base_url,provider_name:e.provider_name,model:e.model});ot(t,"Codex auth.json"),ot(s,"Codex config.toml"),V({current_codex_account:i.account_email}),console.log(u.green(`
134
134
  \u2713 Codex \u914D\u7F6E\u5B8C\u6210\uFF01`)),console.log(` \u8D26\u53F7: ${u.cyan(i.account_email)}`),console.log(` Auth: ${u.dim(t)}`),console.log(` Config: ${u.dim(s)}`),console.log(` \u8FD0\u884C ${u.bold("codex")} \u5373\u53EF\u5F00\u59CB\u4F7F\u7528
135
- `)}async function Sa(i){let e=i;if(!e||/^\d+$/.test(e)){let n=await H("codex");(!Array.isArray(n)||n.length===0)&&(console.error(u.red("\u2717 \u6CA1\u6709\u53EF\u7528\u7684 Codex \u8D26\u53F7")),process.exit(1));let o=/^\d+$/.test(e)?parseInt(e,10)-1:null;if(o!==null)(o<0||o>=n.length)&&(console.error(u.red(`\u2717 \u5E8F\u53F7 ${e} \u8D85\u51FA\u8303\u56F4\uFF08\u5171 ${n.length} \u4E2A\u8D26\u53F7\uFF09`)),process.exit(1)),e=n[o].account_email;else{let a=await(0,Ui.default)({type:"select",name:"email",message:"\u9009\u62E9 Codex \u8D26\u53F7",choices:n.map(l=>({title:l.account_email,value:l.account_email}))});if(!a.email){console.log("\u5DF2\u53D6\u6D88");return}e=a.email}}console.log(u.dim(`\u6B63\u5728\u5207\u6362\u5230 ${e}...`));let t=await te("codex",e),s=Ni({api_token:t.api_token}),r=Li({base_url:t.base_url,provider_name:t.provider_name,model:t.model});ot(s,"Codex auth.json"),ot(r,"Codex config.toml"),V({current_codex_account:e}),console.log(u.green(`\u2713 \u5DF2\u5207\u6362\u5230 ${e}`)),console.log(` Auth: ${u.dim(s)}`),console.log(` Config: ${u.dim(r)}`)}async function yc(){let i;try{i=await H("codex")}catch(r){console.error(u.red(`\u2717 \u83B7\u53D6\u8D26\u53F7\u5217\u8868\u5931\u8D25\uFF1A${r.message}`)),process.exit(1)}if((!Array.isArray(i)||i.length===0)&&(console.error(u.red("\u2717 \u6CA1\u6709\u53EF\u7528\u8D26\u53F7\uFF0C\u8BF7\u786E\u8BA4\u8BA2\u9605\u6709\u6548")),process.exit(1)),i.length===1)return console.log(u.dim(`\u4F7F\u7528\u8D26\u53F7: ${i[0].account_email}`)),i[0];let t=S().current_codex_account,{email:s}=await(0,Ui.default)({type:"select",name:"email",message:"\u9009\u62E9\u8981\u4F7F\u7528\u7684 Codex \u8D26\u53F7",choices:i.map(r=>({title:r.account_email+(r.plan_name?` (${r.plan_name})`:""),value:r.account_email,selected:r.account_email===t}))});return s?i.find(r=>r.account_email===s):(console.log("\u5DF2\u53D6\u6D88"),null)}function ot(i,e){if(!Ca.default.existsSync(i))throw new Error(`${e} \u5199\u5165\u5931\u8D25\uFF1A${i}`)}var se=new hs;se.name("flapcode").description("Flapcode CLI \u2014 \u7EDF\u4E00\u7BA1\u7406 Claude Code / Codex \u5B89\u88C5\u4E0E\u8D26\u53F7\u914D\u7F6E").version("1.3.3","-v, --version","\u663E\u793A\u7248\u672C\u53F7");se.command("login").description("\u4F7F\u7528 API Token \u6216\u90AE\u7BB1\u767B\u5F55").option("--token <token>","\u975E\u4EA4\u4E92\u6A21\u5F0F\u4E0B\u76F4\u63A5\u4F20\u5165 API Token").option("--email <email>","\u4F7F\u7528\u90AE\u7BB1\u767B\u5F55").action(Y(Qo));se.command("logout").description("\u9000\u51FA\u767B\u5F55\uFF0C\u6E05\u9664\u672C\u5730\u914D\u7F6E").action(Y(ta));se.command("status").description("\u663E\u793A\u5F53\u524D\u7528\u6237\u3001\u8D26\u53F7\u3001CC/Codex \u7248\u672C\u53CA patch \u72B6\u6001").action(Y(fa));se.command("update").description("\u5347\u7EA7 Flapcode CLI \u5230\u6700\u65B0\u7248\u672C").action(Y(ga));se.command("accounts").description("\u5217\u51FA\u5F53\u524D\u7528\u6237\u53EF\u7528\u7684\u8D26\u53F7").option("--provider <provider>","\u8FC7\u6EE4 provider\uFF08claude \u6216 codex\uFF09").action(Y(ma));var Wi=se.command("claude").description("\u7BA1\u7406 Claude Code");Wi.command("install").description("\u9996\u6B21\u5B8C\u6574\u914D\u7F6E\uFF1A\u5B89\u88C5 CC + patch + \u5199\u914D\u7F6E\u6587\u4EF6").action(Y(ya));Wi.command("patch").description("\u4EC5\u91CD\u6253 patch\uFF08\u5E94\u5BF9 CC \u5347\u7EA7\u540E URL \u88AB\u8986\u76D6\uFF09").action(Y(_a));Wi.command("use [account]").description("\u5207\u6362 Claude \u8D26\u53F7\uFF08\u4F20 email \u6216\u5E8F\u53F7\uFF0C\u7559\u7A7A\u8FDB\u884C\u4EA4\u4E92\u9009\u62E9\uFF09").action(Y(va));var $a=se.command("codex").description("\u7BA1\u7406 Codex");$a.command("install").description("\u9996\u6B21\u5B8C\u6574\u914D\u7F6E\uFF1A\u5B89\u88C5 Codex + \u5199\u914D\u7F6E\u6587\u4EF6").action(Y(Oa));$a.command("use [account]").description("\u5207\u6362 Codex \u8D26\u53F7\uFF08\u4F20 email \u6216\u5E8F\u53F7\uFF0C\u7559\u7A7A\u8FDB\u884C\u4EA4\u4E92\u9009\u62E9\uFF09").action(Y(Sa));se.parse();function Y(i){return async(...e)=>{try{await i(...e)}catch(t){console.error(u.red(`\u2717 ${t.message}`)),process.env.DEBUG&&console.error(t),process.exit(1)}}}
135
+ `)}async function Sa(i){let e=i;if(!e||/^\d+$/.test(e)){let n=await H("codex");(!Array.isArray(n)||n.length===0)&&(console.error(u.red("\u2717 \u6CA1\u6709\u53EF\u7528\u7684 Codex \u8D26\u53F7")),process.exit(1));let o=/^\d+$/.test(e)?parseInt(e,10)-1:null;if(o!==null)(o<0||o>=n.length)&&(console.error(u.red(`\u2717 \u5E8F\u53F7 ${e} \u8D85\u51FA\u8303\u56F4\uFF08\u5171 ${n.length} \u4E2A\u8D26\u53F7\uFF09`)),process.exit(1)),e=n[o].account_email;else{let a=await(0,Ui.default)({type:"select",name:"email",message:"\u9009\u62E9 Codex \u8D26\u53F7",choices:n.map(l=>({title:l.account_email,value:l.account_email}))});if(!a.email){console.log("\u5DF2\u53D6\u6D88");return}e=a.email}}console.log(u.dim(`\u6B63\u5728\u5207\u6362\u5230 ${e}...`));let t=await te("codex",e),s=Ni({api_token:t.api_token}),r=Li({base_url:t.base_url,provider_name:t.provider_name,model:t.model});ot(s,"Codex auth.json"),ot(r,"Codex config.toml"),V({current_codex_account:e}),console.log(u.green(`\u2713 \u5DF2\u5207\u6362\u5230 ${e}`)),console.log(` Auth: ${u.dim(s)}`),console.log(` Config: ${u.dim(r)}`)}async function yc(){let i;try{i=await H("codex")}catch(r){console.error(u.red(`\u2717 \u83B7\u53D6\u8D26\u53F7\u5217\u8868\u5931\u8D25\uFF1A${r.message}`)),process.exit(1)}if((!Array.isArray(i)||i.length===0)&&(console.error(u.red("\u2717 \u6CA1\u6709\u53EF\u7528\u8D26\u53F7\uFF0C\u8BF7\u786E\u8BA4\u8BA2\u9605\u6709\u6548")),process.exit(1)),i.length===1)return console.log(u.dim(`\u4F7F\u7528\u8D26\u53F7: ${i[0].account_email}`)),i[0];let t=S().current_codex_account,{email:s}=await(0,Ui.default)({type:"select",name:"email",message:"\u9009\u62E9\u8981\u4F7F\u7528\u7684 Codex \u8D26\u53F7",choices:i.map(r=>({title:r.account_email+(r.plan_name?` (${r.plan_name})`:""),value:r.account_email,selected:r.account_email===t}))});return s?i.find(r=>r.account_email===s):(console.log("\u5DF2\u53D6\u6D88"),null)}function ot(i,e){if(!Ca.default.existsSync(i))throw new Error(`${e} \u5199\u5165\u5931\u8D25\uFF1A${i}`)}var se=new hs;se.name("flapcode").description("Flapcode CLI \u2014 \u7EDF\u4E00\u7BA1\u7406 Claude Code / Codex \u5B89\u88C5\u4E0E\u8D26\u53F7\u914D\u7F6E").version("1.3.4","-v, --version","\u663E\u793A\u7248\u672C\u53F7");se.command("login").description("\u4F7F\u7528 API Token \u6216\u90AE\u7BB1\u767B\u5F55").option("--token <token>","\u975E\u4EA4\u4E92\u6A21\u5F0F\u4E0B\u76F4\u63A5\u4F20\u5165 API Token").option("--email <email>","\u4F7F\u7528\u90AE\u7BB1\u767B\u5F55").action(Y(Qo));se.command("logout").description("\u9000\u51FA\u767B\u5F55\uFF0C\u6E05\u9664\u672C\u5730\u914D\u7F6E").action(Y(ta));se.command("status").description("\u663E\u793A\u5F53\u524D\u7528\u6237\u3001\u8D26\u53F7\u3001CC/Codex \u7248\u672C\u53CA patch \u72B6\u6001").action(Y(fa));se.command("update").description("\u5347\u7EA7 Flapcode CLI \u5230\u6700\u65B0\u7248\u672C").action(Y(ga));se.command("accounts").description("\u5217\u51FA\u5F53\u524D\u7528\u6237\u53EF\u7528\u7684\u8D26\u53F7").option("--provider <provider>","\u8FC7\u6EE4 provider\uFF08claude \u6216 codex\uFF09").action(Y(ma));var Wi=se.command("claude").description("\u7BA1\u7406 Claude Code");Wi.command("install").description("\u9996\u6B21\u5B8C\u6574\u914D\u7F6E\uFF1A\u5B89\u88C5 CC + patch + \u5199\u914D\u7F6E\u6587\u4EF6").action(Y(ya));Wi.command("patch").description("\u4EC5\u91CD\u6253 patch\uFF08\u5E94\u5BF9 CC \u5347\u7EA7\u540E URL \u88AB\u8986\u76D6\uFF09").action(Y(_a));Wi.command("use [account]").description("\u5207\u6362 Claude \u8D26\u53F7\uFF08\u4F20 email \u6216\u5E8F\u53F7\uFF0C\u7559\u7A7A\u8FDB\u884C\u4EA4\u4E92\u9009\u62E9\uFF09").action(Y(va));var $a=se.command("codex").description("\u7BA1\u7406 Codex");$a.command("install").description("\u9996\u6B21\u5B8C\u6574\u914D\u7F6E\uFF1A\u5B89\u88C5 Codex + \u5199\u914D\u7F6E\u6587\u4EF6").action(Y(Oa));$a.command("use [account]").description("\u5207\u6362 Codex \u8D26\u53F7\uFF08\u4F20 email \u6216\u5E8F\u53F7\uFF0C\u7559\u7A7A\u8FDB\u884C\u4EA4\u4E92\u9009\u62E9\uFF09").action(Y(Sa));se.parse();function Y(i){return async(...e)=>{try{await i(...e)}catch(t){console.error(u.red(`\u2717 ${t.message}`)),process.env.DEBUG&&console.error(t),process.exit(1)}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flapcode/cli",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "description": "Flapcode CLI - 统一管理 Claude Code / Codex 安装与账号配置",
5
5
  "type": "module",
6
6
  "bin": {