@vibeapi/api-helper 0.0.98 → 0.0.100

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.
@@ -1 +1 @@
1
- import o from"chalk";import{getAdapter as e}from"../lib/tools/registry.js";import{postApplyPrompts as t}from"../lib/post-apply.js";import{ensureReachableGatewayAddress as i}from"./base.js";import{i18n as s}from"../lib/i18n.js";import{configManager as l}from"../lib/config.js";import{toolManager as a,SUPPORTED_TOOLS as n}from"../lib/tool-manager.js";import{validateApiKey as r,fetchModels as p}from"../lib/api-validator.js";import{CODEX_ONE_MILLION_CONTEXT_SETTING as d,setCodexOneMillionContext as c}from"../lib/tools/codex.js";import{resolveModelCatalog as u}from"../lib/model-catalog.js";import{CLAUDE_DESKTOP_FORCE_REGISTRY_SETTING as m,CLAUDE_DESKTOP_HIDE_OFFICIAL_LOGIN_SETTING as f}from"../lib/tools/claude-desktop.js";import{operationError as g,authenticationError as y,networkError as k,EXIT_CODES as _}from"../lib/errors.js";import{isJsonMode as h,isNonInteractive as b,shouldAutoConfirm as w}from"../lib/runtime-options.js";import v from"inquirer";import{logger as x}from"../utils/logger.js";import{forgetInstalls as C}from"../lib/tools/tool-installs.js";import{CLI_NAME as j,brandEnv as T}from"../lib/brand.js";export const DEDICATED_KEYS=[{option:"claudekey",tool:"claude-code",need:"claude"},{option:"codexkey",tool:"codex",need:"gpt"},{option:"grokkey",tool:"grok",need:"grok"},{option:"desktopkey",tool:"claude-desktop",need:"claude"},{option:"agykey",tool:"agy",need:"gemini"},{option:"openclawkey",tool:"openclaw",need:"any",hidden:!0},{option:"hermeskey",tool:"hermes",need:"any",hidden:!0},{option:"atomcodekey",tool:"atomcode",need:"any",hidden:!0}];async function K(o){const e=await p(o);if(!e.ok)return{hasClaude:!0,hasGpt:!0,hasGrok:!0,hasGemini:!0,probed:!1};const t=e.models.map(o=>o.toLowerCase());return{hasClaude:t.some(o=>o.includes("claude")),hasGpt:t.some(o=>o.startsWith("gpt")||o.includes("gpt-")||/^o\d/.test(o)),hasGrok:t.some(o=>o.includes("grok")),hasGemini:t.some(o=>o.startsWith("gemini")),probed:!0}}function $(o,e){switch(e){case"claude":return o.hasClaude;case"gpt":return o.hasGpt;case"grok":return o.hasGrok;case"gemini":return o.hasGemini;default:return!0}}export function parseOnOff(o){const e=(o??"").trim().toLowerCase();return!!["on","true","show","1","yes","y"].includes(e)||!["off","false","hide","0","no","n"].includes(e)&&void 0}function G(e){console.log(o.green(e))}function S(e){console.log(o.yellow(e))}function M(e){console.error(o.red(e))}let N=null;function E(o){const e={operation:1,authentication:2,network:3};(!N||e[o]>e[N])&&(N=o)}async function I(e,t){h()||console.log(o.gray(s.t("setup.validating",{label:e})));const i=await r(t);if(i.valid)return!0;const a="zh_CN"===s.getLocale()?"<你的 Key>":"<your key>",n="--key"===e?`${j} setup --key ${a}`:`${j} setup ${e} ${a}`;let p;if("network_error"===i.error?(E("network"),p=k(s.t("setup.unreachable",{url:l.getBaseUrl(),reason:i.message||"network error"}),`${j} base auto`,"network_error")):"invalid_api_key"===i.error?(E("authentication"),p=y(s.t("setup.invalid_key",{label:e,reason:i.message||"invalid"}),n,"invalid_api_key")):(E("operation"),p=g(s.t("setup.invalid_key",{label:e,reason:i.message||i.error||"unknown"}),n,i.error)),h())throw p;return M(p.message),console.log(o.gray(s.t("errors.next_step",{command:p.hint}))),!1}async function O(t,i,r={}){const{oneMillion:p,officialLogin:c,desktopRegistry:u,force:y}=r,k=n[t];try{"claude-desktop"===t&&void 0!==u&&l.setToolSetting("claude-desktop",m,u),"codex"===t&&void 0!==p&&l.setToolSetting("codex",d,p),"claude-desktop"===t&&void 0!==c&&l.setToolSetting("claude-desktop",f,!c),await a.applyPrivateConfig(t,i,l.getModelsForTool(t),{force:y})}catch(o){if(h())throw g(o instanceof Error?o.message:String(o),`${j} setup --key ${"zh_CN"===s.getLocale()?"<你的 Key>":"<your key>"}`,"config_write_failed");const e=(o instanceof Error?o.message:String(o)).replace(/\s+/g," ").trim();return M("× "+s.t("setup.apply_failed",{tool:k.displayName,reason:e})),!1}return a.printApplied(t),y&&console.log(o.gray(" "+s.t("config.force_done",{tool:k.displayName}))),"codex"===t&&void 0!==p&&console.log(o.gray(" "+s.t(p?"setup.codex_1m_enabled":"setup.codex_1m_disabled"))),e(t)?.isInstalled&&!a.isToolInstalled(t)&&console.log(o.yellow(" ! "+s.t("setup.install_hint",{tool:k.displayName,install:k.installCommand}))),!0}export async function setupCommand(r){N=null;const p=r.key?.trim(),m=DEDICATED_KEYS.map(o=>({...o,apiKey:r[o.option]?.trim()})).filter(o=>Boolean(o.apiKey)),f=void 0!==r.oneMillion,g=void 0!==r.claudeOfficial;let y;if(g&&(y=parseOnOff(r.claudeOfficial),void 0===y))return M(s.t("setup.claude_official_invalid",{value:String(r.claudeOfficial)})),void(process.exitCode=1);const k=void 0!==r.desktopRegistry;let E;if(k&&(E=parseOnOff(r.desktopRegistry),void 0===E))return M(s.t("setup.desktop_registry_invalid",{value:String(r.desktopRegistry)})),void(process.exitCode=1);const A=g||k,L=Boolean(p||m.length>0),D={oneMillion:r.oneMillion,officialLogin:y,desktopRegistry:E,force:r.force};if(!L&&(f||A)){if(f){const o=l.getApiKeyForTool("codex");if(o)try{const e=!0===r.oneMillion;l.setToolSetting("codex",d,e);const t=await u(o);c(e,t??void 0),G(s.t(e?"setup.codex_1m_enabled":"setup.codex_1m_disabled"))}catch(o){M(s.t("setup.apply_failed",{tool:n.codex.displayName,reason:o instanceof Error?o.message:String(o)})),process.exitCode=1}else M(s.t("setup.codex_1m_missing_key")),process.exitCode=1}if(A){const o=l.getApiKeyForTool("claude-desktop");o?await O("claude-desktop",o,{...D,oneMillion:void 0})?await t(["claude-desktop"]):process.exitCode=1:(M(s.t("setup.desktop_official_login_missing_key")),process.exitCode=1)}return}if(!L)return M(s.t("setup.usage")),void(process.exitCode=1);await i(p||m[0].apiKey);let R=0,B=0;const Y=new Set,q=m.map(o=>({tool:o.tool,label:`--${o.option}`,apiKey:o.apiKey,need:o.need}));for(const o of q){if(!await I(o.label,o.apiKey)){B+=1;continue}const e=await K(o.apiKey);!e.probed||$(e,o.need)?(e.probed||S(s.t("setup.probe_failed",{label:o.label})),l.setToolApiKey(o.tool,o.apiKey),await O(o.tool,o.apiKey,D)?(R+=1,Y.add(o.tool)):B+=1):(M(s.t(`setup.key_no_${o.need}`,{label:o.label,tool:n[o.tool].displayName})),B+=1)}if(p){if(!await I("--key",p))return void(process.exitCode=_[N??"operation"]);l.setApiKey(p);const o=await K(p);if(o.probed||S(s.t("setup.probe_failed",{label:"--key"})),o.probed&&!o.hasClaude&&!o.hasGpt&&!o.hasGrok&&!o.hasGemini)return M(s.t("setup.key_no_family")),void(process.exitCode=1);const e=[{tool:"claude-code",capable:o.hasClaude,skipMsg:s.t("setup.skip_no_claude")},{tool:"codex",capable:o.hasGpt,skipMsg:s.t("setup.skip_no_gpt")},{tool:"grok",capable:o.hasGrok,skipMsg:s.t("setup.skip_no_grok")},{tool:"claude-desktop",capable:o.hasClaude&&a.isToolInstalled("claude-desktop"),skipMsg:s.t("setup.skip_desktop_not_installed"),quiet:!o.hasClaude},{tool:"agy",capable:o.hasGemini,skipMsg:s.t("setup.skip_no_gemini")}];for(const o of e)Y.has(o.tool)||(o.capable?await O(o.tool,p,D)?(R+=1,Y.add(o.tool)):B+=1:o.quiet||S(o.skipMsg))}if(R>0){const t=await async function(t,i){const l=t.filter(o=>!e(o)?.isInstalled&&!a.isToolInstalled(o));if(0===l.length)return[];const r=l.map(o=>n[o].displayName).join(s.t("setup.list_separator"));let p=i;if(void 0!==p||h()||(w()?p=!b():process.stdin.isTTY&&(console.log(""),p=(await v.prompt([{type:"confirm",name:"go",message:s.t("setup.install_confirm",{tools:r}),default:!0}])).go)),!p){console.log("");for(const e of l)console.log(o.yellow("! "+s.t("setup.install_hint",{tool:n[e].displayName,install:n[e].installCommand})));return h()||console.log(o.gray(s.t("setup.install_all_hint",{cli:j}))),l}const d=[];for(const e of l){console.log(o.bold(`\n${n[e].displayName}`));try{await a.installTool(e)}catch(o){x.logError(`setup: install ${e}`,o)}C(),a.isToolInstalled(e)||d.push(e)}return d}([...Y],r.install),i=[...Y].filter(o=>!e(o)?.isInstalled&&!t.includes(o)),l=i.map(o=>n[o]?.command).filter(Boolean).join(" / "),p=s.t("setup.done",{count:String(R)});G("\n"+(l?`${p}${s.t("setup.done_commands",{commands:l})}`:p)),t.length>0&&S(s.t("setup.still_missing",{tools:t.map(o=>n[o].displayName).join(s.t("setup.list_separator"))}));const d=i.filter(o=>!a.isOnPath(o));if(d.length>0&&!h()&&"1"!==T("PATH_HINT_BY_CALLER")){const e=d.map(o=>n[o].command).join(" / ");console.log(o.yellow(" ! "+s.t("win32"===process.platform?"setup.path_reload_windows":"setup.path_reload",{commands:e})))}}B>0&&(M(s.t("setup.failed_summary",{count:String(B)})),h()||console.error(`${j} setup --key ${"zh_CN"===s.getLocale()?"<你的 Key>":"<your key>"}`)),await t([...Y]),(B>0||0===R)&&(process.exitCode=_[N??"operation"])}
1
+ import o from"chalk";import{getAdapter as e}from"../lib/tools/registry.js";import{postApplyPrompts as t}from"../lib/post-apply.js";import{ensureReachableGatewayAddress as i}from"./base.js";import{i18n as s}from"../lib/i18n.js";import{configManager as l}from"../lib/config.js";import{toolManager as a,SUPPORTED_TOOLS as n}from"../lib/tool-manager.js";import{validateApiKey as r,fetchModels as p}from"../lib/api-validator.js";import{CODEX_ONE_MILLION_CONTEXT_SETTING as d,setCodexOneMillionContext as c}from"../lib/tools/codex.js";import{resolveModelCatalog as u}from"../lib/model-catalog.js";import{CLAUDE_DESKTOP_FORCE_REGISTRY_SETTING as m,CLAUDE_DESKTOP_HIDE_OFFICIAL_LOGIN_SETTING as f}from"../lib/tools/claude-desktop.js";import{operationError as g,authenticationError as y,networkError as k,EXIT_CODES as _}from"../lib/errors.js";import{isJsonMode as h,isNonInteractive as b,shouldAutoConfirm as w}from"../lib/runtime-options.js";import v from"inquirer";import{logger as x}from"../utils/logger.js";import{forgetInstalls as C}from"../lib/tools/tool-installs.js";import{CLI_NAME as T,brandEnv as j}from"../lib/brand.js";export const DEDICATED_KEYS=[{option:"claudekey",tool:"claude-code",need:"claude"},{option:"codexkey",tool:"codex",need:"gpt"},{option:"grokkey",tool:"grok",need:"grok"},{option:"desktopkey",tool:"claude-desktop",need:"claude"},{option:"agykey",tool:"agy",need:"gemini"},{option:"openclawkey",tool:"openclaw",need:"any",hidden:!0},{option:"hermeskey",tool:"hermes",need:"any",hidden:!0},{option:"atomcodekey",tool:"atomcode",need:"any",hidden:!0}];async function K(o){const e=await p(o);if(!e.ok)return{hasClaude:!0,hasGpt:!0,hasGrok:!0,hasGemini:!0,probed:!1};const t=e.models.map(o=>o.toLowerCase());return{hasClaude:t.some(o=>o.includes("claude")),hasGpt:t.some(o=>o.startsWith("gpt")||o.includes("gpt-")||/^o\d/.test(o)),hasGrok:t.some(o=>o.includes("grok")),hasGemini:t.some(o=>o.startsWith("gemini")),probed:!0}}function $(o,e){switch(e){case"claude":return o.hasClaude;case"gpt":return o.hasGpt;case"grok":return o.hasGrok;case"gemini":return o.hasGemini;default:return!0}}export function parseOnOff(o){const e=(o??"").trim().toLowerCase();return!!["on","true","show","1","yes","y"].includes(e)||!["off","false","hide","0","no","n"].includes(e)&&void 0}function G(e){console.log(o.green(e))}function M(e){console.log(o.yellow(e))}function S(e){console.error(o.red(e))}let N=null;function E(o){const e={operation:1,authentication:2,network:3};(!N||e[o]>e[N])&&(N=o)}async function A(e,t){h()||console.log(o.gray(s.t("setup.validating",{label:e})));const i=await r(t);if(i.valid)return!0;const a="zh_CN"===s.getLocale()?"<你的 Key>":"<your key>",n="--key"===e?`${T} setup --key ${a}`:`${T} setup ${e} ${a}`;let p;if("network_error"===i.error?(E("network"),p=k(s.t("setup.unreachable",{url:l.getBaseUrl(),reason:i.message||"network error"}),`${T} base auto`,"network_error")):"invalid_api_key"===i.error?(E("authentication"),p=y(s.t("setup.invalid_key",{label:e,reason:i.message||"invalid"}),n,"invalid_api_key")):(E("operation"),p=g(s.t("setup.invalid_key",{label:e,reason:i.message||i.error||"unknown"}),n,i.error)),h())throw p;return S(p.message),console.log(o.gray(s.t("errors.next_step",{command:p.hint}))),!1}async function I(t,i,r={}){const{oneMillion:p,officialLogin:c,desktopRegistry:u,force:y}=r,k=n[t];try{"claude-desktop"===t&&void 0!==u&&l.setToolSetting("claude-desktop",m,u),"codex"===t&&void 0!==p&&l.setToolSetting("codex",d,p),"claude-desktop"===t&&void 0!==c&&l.setToolSetting("claude-desktop",f,!c),await a.applyPrivateConfig(t,i,l.getModelsForTool(t),{force:y})}catch(o){if(h())throw g(o instanceof Error?o.message:String(o),`${T} setup --key ${"zh_CN"===s.getLocale()?"<你的 Key>":"<your key>"}`,"config_write_failed");const e=(o instanceof Error?o.message:String(o)).replace(/\s+/g," ").trim();return S("× "+s.t("setup.apply_failed",{tool:k.displayName,reason:e})),!1}return a.printApplied(t),y&&console.log(o.gray(" "+s.t("config.force_done",{tool:k.displayName}))),"codex"===t&&void 0!==p&&console.log(o.gray(" "+s.t(p?"setup.codex_1m_enabled":"setup.codex_1m_disabled"))),e(t)?.isInstalled&&!a.isToolInstalled(t)&&console.log(o.yellow(" ! "+s.t("setup.install_hint",{tool:k.displayName,install:k.installCommand}))),!0}export async function setupCommand(r){N=null;const p=r.key?.trim(),m=DEDICATED_KEYS.map(o=>({...o,apiKey:r[o.option]?.trim()})).filter(o=>Boolean(o.apiKey)),f=void 0!==r.oneMillion,g=void 0!==r.claudeOfficial;let y;if(g&&(y=parseOnOff(r.claudeOfficial),void 0===y))return S(s.t("setup.claude_official_invalid",{value:String(r.claudeOfficial)})),void(process.exitCode=1);const k=void 0!==r.desktopRegistry;let E;if(k&&(E=parseOnOff(r.desktopRegistry),void 0===E))return S(s.t("setup.desktop_registry_invalid",{value:String(r.desktopRegistry)})),void(process.exitCode=1);const O=g||k,L=Boolean(p||m.length>0),D={oneMillion:r.oneMillion,officialLogin:y,desktopRegistry:E,force:r.force};if(!L&&(f||O)){if(f){const o=l.getApiKeyForTool("codex");if(o)try{const e=!0===r.oneMillion;l.setToolSetting("codex",d,e);const t=await u(o);c(e,t??void 0),G(s.t(e?"setup.codex_1m_enabled":"setup.codex_1m_disabled"))}catch(o){S(s.t("setup.apply_failed",{tool:n.codex.displayName,reason:o instanceof Error?o.message:String(o)})),process.exitCode=1}else S(s.t("setup.codex_1m_missing_key")),process.exitCode=1}if(O){const o=l.getApiKeyForTool("claude-desktop");o?await I("claude-desktop",o,{...D,oneMillion:void 0})?await t(["claude-desktop"]):process.exitCode=1:(S(s.t("setup.desktop_official_login_missing_key")),process.exitCode=1)}return}if(!L)return S(s.t("setup.usage")),void(process.exitCode=1);await i(p||m[0].apiKey);let R=0,B=0;const F=new Set,Y=m.map(o=>({tool:o.tool,label:`--${o.option}`,apiKey:o.apiKey,need:o.need}));for(const o of Y){if(!await A(o.label,o.apiKey)){B+=1;continue}const e=await K(o.apiKey);!e.probed||$(e,o.need)?(e.probed||M(s.t("setup.probe_failed",{label:o.label})),l.setToolApiKey(o.tool,o.apiKey),await I(o.tool,o.apiKey,D)?(R+=1,F.add(o.tool)):B+=1):(S(s.t(`setup.key_no_${o.need}`,{label:o.label,tool:n[o.tool].displayName})),B+=1)}if(p){if(!await A("--key",p))return void(process.exitCode=_[N??"operation"]);l.setApiKey(p);const o=await K(p);if(o.probed||M(s.t("setup.probe_failed",{label:"--key"})),o.probed&&!o.hasClaude&&!o.hasGpt&&!o.hasGrok&&!o.hasGemini)return S(s.t("setup.key_no_family")),void(process.exitCode=1);const e=[{tool:"claude-code",capable:o.hasClaude,skipMsg:s.t("setup.skip_no_claude")},{tool:"codex",capable:o.hasGpt,skipMsg:s.t("setup.skip_no_gpt")},{tool:"grok",capable:o.hasGrok,skipMsg:s.t("setup.skip_no_grok")},{tool:"claude-desktop",capable:o.hasClaude&&a.isToolInstalled("claude-desktop"),skipMsg:s.t("setup.skip_desktop_not_installed"),quiet:!o.hasClaude},{tool:"agy",capable:o.hasGemini,skipMsg:s.t("setup.skip_no_gemini")}];for(const o of e)F.has(o.tool)||(o.capable?await I(o.tool,p,D)?(R+=1,F.add(o.tool)):B+=1:o.quiet||M(o.skipMsg))}if(R>0){const t=await async function(t,i,r){const p=t.filter(o=>!e(o)?.isInstalled&&!a.isToolInstalled(o));if(0===p.length)return[];const d=p.map(o=>n[o].displayName).join(s.t("setup.list_separator"));let c=i;if(void 0!==c||h()||(w()?c=!b():process.stdin.isTTY&&(console.log(""),c=(await v.prompt([{type:"confirm",name:"go",message:s.t("setup.install_confirm",{tools:d}),default:!0}])).go)),!c){console.log("");for(const e of p)console.log(o.yellow("! "+s.t("setup.install_hint",{tool:n[e].displayName,install:n[e].installCommand})));return h()||console.log(o.gray(s.t("setup.install_all_hint",{cli:T}))),p}const u=[];for(const e of p){console.log(o.bold(`\n${n[e].displayName}`));try{await a.installTool(e)}catch(o){x.logError(`setup: install ${e}`,o)}C(),a.isToolInstalled(e)||u.push(e)}const m=p.filter(o=>!u.includes(o));m.length>0&&console.log("");for(const o of m){const e=l.getApiKeyForTool(o);e&&await I(o,e,{...r,oneMillion:void 0,force:void 0})}return u}([...F],r.install,D),i=[...F].filter(o=>!e(o)?.isInstalled&&!t.includes(o)),p=i.map(o=>n[o]?.command).filter(Boolean).join(" / "),d=s.t("setup.done",{count:String(R)});G("\n"+(p?`${d}${s.t("setup.done_commands",{commands:p})}`:d)),t.length>0&&M(s.t("setup.still_missing",{tools:t.map(o=>n[o].displayName).join(s.t("setup.list_separator"))}));const c=i.filter(o=>!a.isOnPath(o));if(c.length>0&&!h()&&"1"!==j("PATH_HINT_BY_CALLER")){const e=c.map(o=>n[o].command).join(" / ");console.log(o.yellow(" ! "+s.t("win32"===process.platform?"setup.path_reload_windows":"setup.path_reload",{commands:e})))}}B>0&&(S(s.t("setup.failed_summary",{count:String(B)})),h()||console.error(`${T} setup --key ${"zh_CN"===s.getLocale()?"<你的 Key>":"<your key>"}`)),await t([...F]),(B>0||0===R)&&(process.exitCode=_[N??"operation"])}
@@ -1 +1 @@
1
- import{Command as e,Option as o}from"commander";import{readFileSync as t}from"fs";import{join as s,dirname as a}from"path";import{fileURLToPath as n}from"url";import{i18n as i}from"./i18n.js";import{wizard as r}from"./wizard.js";import{SUPPORTED_TOOLS as c}from"./tool-manager.js";import{DEFAULT_BASE_URL as l}from"./config.js";import{attachCommandHelp as p,helpConfiguration as u}from"./cli-help.js";import{langCommand as m,authCommand as d,doctorCommand as g,configCommand as f,statusCommand as x,refreshCommand as y}from"../commands/index.js";import{logsCommand as b}from"../commands/logs.js";import{completionCommand as h}from"../commands/completion.js";import{benchCommand as $}from"../commands/bench.js";import{updateCommand as k}from"../commands/update.js";import{upgradeCommand as _}from"../commands/upgrade.js";import{codexSessionsCommand as w}from"../commands/codex-sessions.js";import{setupCommand as v,DEDICATED_KEYS as j}from"../commands/setup.js";import{baseCommand as O}from"../commands/base.js";import{usageError as S}from"./errors.js";import{brand as z,CLI_NAME as A}from"./brand.js";const C=(z().gatewayAddresses[1]??z().gatewayAddresses[0]).url,G=(z().gatewayAddresses[2]??z().gatewayAddresses[0]).url;function R(e,o){return i.t(`help.${e}`,o)}function E(e,o){return{command:e,note:R(o)}}function L(e){const o=R(e);return o===`help.${e}`?"":o}function N(e,o=[]){return{when:L(`${e}.when`),prerequisites:L(`${e}.needs`).split("\n").filter(Boolean),alternatives:o.map(([e,o])=>E(e,o))}}function K(e){return e.helpCommand("help [command]",R("help_command"))}export function buildProgram(){const z=new e;z.name(`${A}`).summary(R("root.summary")).description(R("root.description")).configureHelp(u()).allowExcessArguments(!0).optionsGroup(R("group.global_options")).helpOption("-h, --help",R("global.help")).version(function(){try{const e=a(n(import.meta.url));return JSON.parse(t(s(e,"../../package.json"),"utf-8")).version}catch{return"1.0.0"}}(),"-v, --version",R("global.version")).option("--base <url>",R("global.base")).option("--non-interactive",R("global.non_interactive")).option("--json",R("global.json")).option("-y, --yes",R("global.yes")).option("--dry-run",R("global.dry_run")).option("--no-color",R("global.no_color")),z.configureOutput({writeErr:()=>{},outputError:()=>{}}),z.showSuggestionAfterError(),z.exitOverride(e=>{throw e}),z.commandsGroup(R("group.configure"));const L=z.command("setup").summary(R("setup.summary")).description(R("setup.description")).option("--key <key>",R("setup.opt.key"));for(const e of j){const t=new o(`--${e.option} <key>`,R(`setup.opt.${e.option}`));e.hidden&&t.hideHelp(),L.addOption(t)}L.option("--1m",R("setup.opt.one_m")).option("--no-1m",R("setup.opt.no_one_m")).option("--claude-official <on|off>",R("setup.opt.claude_official")).option("--desktop-registry <on|off>",R("setup.opt.desktop_registry")).option("--force",R("setup.opt.force")).option("--install",R("setup.opt.install")).option("--no-install",R("setup.opt.no_install")).option("--all",R("setup.opt.all")).action(async e=>{const o=Boolean(e.key||j.some(o=>e[o.option])),t=void 0!==e["1m"]||void 0!==e.claudeOfficial||void 0!==e.desktopRegistry,s="zh_CN"===i.getLocale()?"<你的 Key>":"<your key>";if(!o&&!t)throw S(i.t("setup.usage"),`${A} setup --key ${s}`,"missing_key");if(void 0!==e.claudeOfficial&&!["on","off"].includes(String(e.claudeOfficial).toLowerCase()))throw S(i.t("setup.claude_official_invalid",{value:String(e.claudeOfficial)}),`${A} setup --claude-official on|off`,"invalid_value");if(void 0!==e.desktopRegistry&&!["on","off"].includes(String(e.desktopRegistry).toLowerCase()))throw S(i.t("setup.desktop_registry_invalid",{value:String(e.desktopRegistry)}),`${A} setup --desktop-registry on|off`,"invalid_value");await v({key:e.key,...Object.fromEntries(j.map(o=>[o.option,e[o.option]])),all:e.all,oneMillion:e["1m"],claudeOfficial:e.claudeOfficial,desktopRegistry:e.desktopRegistry,force:e.force,install:e.install})}),p(L,{...N("setup",[[`${A} init`,"setup.alt.init"],[`${A} config <tool>`,"setup.alt.config"],[`${A} auth <key>`,"setup.alt.auth"]]),sections:[{title:R("setup.autodetect_title"),rows:[["Claude",R("setup.autodetect.claude")],["GPT",R("setup.autodetect.gpt")],["Grok",R("setup.autodetect.grok")],["Gemini",R("setup.autodetect.gemini")]]}],examples:[E(`${A} setup --key sk-xxx`,"setup.ex.key"),E(`${A} setup --key sk-xxx --install`,"setup.ex.install"),E(`${A} setup --claudekey sk-a --codexkey sk-b --agykey sk-g`,"setup.ex.split"),E(`${A} setup --key sk-xxx --force`,"setup.ex.force"),E(`${A} setup --key sk-xxx --base ${C}`,"setup.ex.base")]});const B=z.command("init").summary(R("init.summary")).description(R("init.description")).action(async()=>{await r.runFirstTimeSetup()});p(B,{...N("init",[[`${A} setup --key <key>`,"init.alt.setup"],[`${A}`,"init.alt.menu"]]),examples:[E(`${A} init`,"init.ex.run"),E(`${A} init --base ${C}`,"init.ex.base"),E(`${A}`,"init.ex.menu")]});const H=z.command("auth").summary(R("auth.summary")).description(R("auth.description")).argument("[token]",R("auth.arg.token")).action(async e=>{const o=[];e&&o.push(e),await d(o)});K(H);const M=H.command("revoke").description(R("auth.revoke")).action(async()=>{await d(["revoke"])});p(M,{examples:[E(`${A} auth revoke`,"auth.ex.revoke_ask"),E(`${A} auth revoke --yes`,"auth.ex.revoke")]});const P=H.command("reload <tool>").description(R("auth.reload")).action(async e=>{await d(["reload",e])});p(P,{examples:[E(`${A} auth reload claude-code`,"auth.ex.reload"),E(`${A} auth reload claude-code --json`,"auth.ex.reload_json")]}),p(H,{...N("auth",[[`${A} setup --key <key>`,"auth.alt.setup"]]),examples:[E(`${A} auth`,"auth.ex.prompt"),E(`${A} auth sk-xxx --non-interactive`,"auth.ex.save"),E(`${A} auth revoke --yes`,"auth.ex.revoke"),E(`${A} auth reload claude-code`,"auth.ex.reload")]});const T=z.command("config").summary(R("config.summary")).description(R("config.description")).argument("[args...]",R("config.arg.args")).option("-f, --force",R("config.opt.force")).allowUnknownOption(!0).action(async(e=[],o={})=>{await f(o.force?[...e,"--force"]:e)});p(T,{...N("config",[[`${A} setup --key <key> --force`,"config.alt.setup"],[`${A} status`,"config.alt.status"]]),sections:[{title:R("config.subcommands_title"),rows:[["<tool>",R("config.sub.tool")],["<tool> --force",R("config.sub.tool_force")],["<tool> --non-interactive",R("config.sub.tool_non_interactive")],["<tool> restore",R("config.sub.tool_restore")],["<tool> backups",R("config.sub.tool_backups")],["<tool> clear-model",R("config.sub.tool_clear_model")],["tool-model list",R("config.sub.tool_model_list")],["tool-model set <tool> [slot] <model>",R("config.sub.tool_model_set")],["tool-model clear <tool>",R("config.sub.tool_model_clear")],["profile list",R("config.sub.profile_list")],["profile create <name>",R("config.sub.profile_create")],["profile use <name>",R("config.sub.profile_use")],["profile delete <name>",R("config.sub.profile_delete")],["preset list",R("config.sub.preset_list")],["preset save <name>",R("config.sub.preset_save")],["preset use <name>",R("config.sub.preset_use")],["preset delete <name>",R("config.sub.preset_delete")],["backup list",R("config.sub.backup_list")],["backup create [label]",R("config.sub.backup_create")],["backup restore <name>",R("config.sub.backup_restore")]]},{title:R("config.tools_title"),rows:Object.values(c).filter(e=>!e.hidden).map(e=>[e.name,e.displayName])}],examples:[E(`${A} config codex`,"config.ex.menu"),E(`${A} config claude-code --force`,"config.ex.force"),E(`${A} config tool-model set codex gpt-6-astra`,"config.ex.tool_model"),E(`${A} config profile create work`,"config.ex.profile"),E(`${A} config backup create before-upgrade`,"config.ex.backup")]});const U=z.command("base").summary(R("base.summary")).description(R("base.description")).argument("[target]",R("base.arg.target")).action(async e=>{await O(e)});p(U,{...N("base",[[`${A} doctor`,"base.alt.doctor"],[`${A} bench`,"base.alt.bench"]]),sections:[{title:R("base.targets_title"),rows:[[R("base.target.none_term"),R("base.target.none")],[R("base.target.index_term"),R("base.target.index")],[R("base.target.url_term"),R("base.target.url")],["auto",R("base.target.auto")],["default",R("base.target.default",{url:l})]]}],examples:[E(`${A} base`,"base.ex.list"),E(`${A} base auto`,"base.ex.auto"),E(`${A} base 2`,"base.ex.index"),E(`${A} base ${C}`,"base.ex.url"),E(`${A} base default`,"base.ex.default")]}),z.commandsGroup(R("group.diagnose"));const q=z.command("status").summary(R("status.summary")).description(R("status.description")).action(async()=>{await x()});p(q,{...N("status",[[`${A} doctor`,"status.alt.doctor"]]),examples:[E(`${A} status`,"status.ex.show"),E(`${A} status --json`,"status.ex.json")]});const F=z.command("doctor").summary(R("doctor.summary")).description(R("doctor.description")).option("--deep",R("doctor.opt.deep")).action(async e=>{await g({deep:e.deep})});p(F,{...N("doctor",[[`${A} base auto`,"doctor.alt.base"],[`${A} logs tail`,"doctor.alt.logs"]]),examples:[E(`${A} doctor`,"doctor.ex.run"),E(`${A} doctor --deep`,"doctor.ex.deep")]});const J=z.command("bench").summary(R("bench.summary")).description(R("bench.description")).option("--samples <n>",R("bench.opt.samples"),"5").action(async e=>{const o=[];e.samples&&o.push("--samples",e.samples),await $(o)});p(J,{...N("bench",[[`${A} base`,"bench.alt.base"]]),examples:[E(`${A} bench`,"bench.ex.run"),E(`${A} bench --samples 3`,"bench.ex.samples"),E(`${A} bench --json`,"bench.ex.json")]});const D=z.command("logs").summary(R("logs.summary")).description(R("logs.description")).argument("[action]",R("logs.arg.action")).argument("[file]",R("logs.arg.file")).action(async(e,o)=>{const t=[];e&&t.push(e),o&&t.push(o),await b(t)});p(D,{...N("logs",[[`${A} doctor`,"logs.alt.doctor"]]),sections:[{title:R("logs.actions_title"),rows:[["list",R("logs.action.list")],["tail [file]",R("logs.action.tail")],["path",R("logs.action.path")]]}],examples:[E(`${A} logs`,"logs.ex.list"),E(`${A} logs tail`,"logs.ex.tail"),E(`${A} logs path`,"logs.ex.path")]}),z.commandsGroup(R("group.maintain"));const I=z.command("upgrade").summary(R("upgrade.summary")).description(R("upgrade.description")).argument("[tools...]",R("upgrade.arg.tools")).action(async(e=[])=>{await _(e)});p(I,{...N("upgrade",[[`${A} update`,"upgrade.alt.update"]]),examples:[E(`${A} upgrade`,"upgrade.ex.all"),E(`${A} upgrade claude-code`,"upgrade.ex.one"),E(`${A} upgrade codex agy`,"upgrade.ex.many")]});const Q=z.command("refresh").summary(R("refresh.summary")).description(R("refresh.description")).action(async()=>{await y()});p(Q,{...N("refresh",[[`${A} setup --key <你的 Key>`,"refresh.alt.setup"]]),examples:[E(`${A} refresh`,"refresh.ex.run"),E(`${A} refresh --base ${G}`,"refresh.ex.base")]});const V=z.command("update").summary(R("update.summary")).description(R("update.description")).action(async()=>{await k()});p(V,{...N("update",[[`${A} upgrade`,"update.alt.upgrade"]]),examples:[E(`${A} update`,"update.ex.check"),E(`${A} update --json`,"update.ex.json")]});const W=z.command("codex").summary(R("codex.summary")).description(R("codex.description"));K(W);const X=W.command("sessions").summary(R("codex_sessions.summary")).description(R("codex_sessions.description")).option("--to <provider>",R("codex_sessions.opt.to")).option("--undo <dir>",R("codex_sessions.opt.undo")).action(async e=>{await w(e)});p(W,{...N("codex"),examples:[E(`${A} codex sessions`,"codex_sessions.ex.move"),E(`${A} codex sessions --undo <dir>`,"codex_sessions.ex.undo")]}),p(X,{...N("codex_sessions",[[`${A} codex sessions --undo <dir>`,"codex_sessions.alt.undo"]]),examples:[E(`${A} codex sessions`,"codex_sessions.ex.move"),E(`${A} codex sessions --to custom`,"codex_sessions.ex.to"),E(`${A} codex sessions --undo <dir>`,"codex_sessions.ex.undo")]});const Y=z.command("lang").summary(R("lang.summary")).description(R("lang.description"));K(Y);const Z=Y.command("show").description(R("lang.show")).action(async()=>{await m(["show"])}),ee=Y.command("set <locale>").description(R("lang.set")).action(async e=>{await m(["set",e])}),oe=[E(`${A} lang show`,"lang.ex.show"),E(`${A} lang set en_US`,"lang.ex.set_en"),E(`${A} lang set zh_CN`,"lang.ex.set_zh")];p(Y,{...N("lang",[[`${A} enter lang`,"lang.alt.enter"]]),examples:oe}),p(Z,{examples:[oe[0],E(`${A} lang show --json`,"lang.ex.show_json")]}),p(ee,{examples:oe.slice(1)});const te=z.command("completion").summary(R("completion.summary")).description(R("completion.description")).argument("<shell>",R("completion.arg.shell")).action(async e=>{await h([e])});p(te,{...N("completion"),examples:[E(`${A} completion bash > ~/.${A}-completion.bash`,"completion.ex.bash"),E(`${A} completion zsh > ~/.${A}-completion.zsh`,"completion.ex.zsh"),E(`${A} completion fish > ~/.config/fish/completions/${A}.fish`,"completion.ex.fish")]});const se=z.command("enter").summary(R("enter.summary")).description(R("enter.description")).argument("[option]",R("enter.arg.option")).action(async e=>{if(e)switch(e){case"lang":case"language":await r.configLanguage();break;case"apikey":case"api-key":await r.configApiKey();break;case"models":await r.configModels();break;default:await f([e])}else await r.run()});p(se,{...N("enter",[[`${A}`,"enter.alt.menu"],[`${A} config <tool>`,"enter.alt.config"]]),sections:[{title:R("enter.options_title"),rows:[[R("enter.option.none_term"),R("enter.option.none")],["lang",R("enter.option.lang")],["apikey",R("enter.option.apikey")],["models",R("enter.option.models")],["<tool>",R("enter.option.tool")]]}],examples:[E(`${A} enter`,"enter.ex.menu"),E(`${A} enter models`,"enter.ex.models"),E(`${A} enter codex`,"enter.ex.tool")]}),K(z),z.action(async()=>{await r.run()}),p(z,{examples:[E(`${A}`,"root.ex.menu"),E(`${A} setup --key sk-xxx`,"root.ex.setup"),E(`${A} doctor`,"root.ex.doctor"),E(`${A} base auto`,"root.ex.base"),E(`${A} config codex`,"root.ex.config")]});const ae=e=>{for(const o of e.commands)o.helpOption("-h, --help",R("global.help")),ae(o)};return ae(z),z}
1
+ import{Command as e,Option as o}from"commander";import{readFileSync as t}from"fs";import{join as s,dirname as a}from"path";import{fileURLToPath as n}from"url";import{i18n as i}from"./i18n.js";import{wizard as r}from"./wizard.js";import{SUPPORTED_TOOLS as c}from"./tool-manager.js";import{DEFAULT_BASE_URL as l}from"./config.js";import{attachCommandHelp as p,helpConfiguration as u}from"./cli-help.js";import{langCommand as m,authCommand as d,doctorCommand as g,configCommand as f,statusCommand as x,refreshCommand as y}from"../commands/index.js";import{logsCommand as b}from"../commands/logs.js";import{completionCommand as h}from"../commands/completion.js";import{benchCommand as $}from"../commands/bench.js";import{updateCommand as k}from"../commands/update.js";import{upgradeCommand as _}from"../commands/upgrade.js";import{codexSessionsCommand as w}from"../commands/codex-sessions.js";import{setupCommand as v,DEDICATED_KEYS as j}from"../commands/setup.js";import{baseCommand as O}from"../commands/base.js";import{usageError as S}from"./errors.js";import{brand as z,brandEnv as A,CLI_NAME as C}from"./brand.js";const E=(z().gatewayAddresses[1]??z().gatewayAddresses[0]).url,G=(z().gatewayAddresses[2]??z().gatewayAddresses[0]).url;function R(e,o){return i.t(`help.${e}`,o)}function K(e,o){return{command:e,note:R(o)}}function L(e){const o=R(e);return o===`help.${e}`?"":o}function N(e,o=[]){return{when:L(`${e}.when`),prerequisites:L(`${e}.needs`).split("\n").filter(Boolean),alternatives:o.map(([e,o])=>K(e,o))}}function P(e){return e.helpCommand("help [command]",R("help_command"))}export function buildProgram(){const z=new e;z.name(`${C}`).summary(R("root.summary")).description(R("root.description")).configureHelp(u()).allowExcessArguments(!0).optionsGroup(R("group.global_options")).helpOption("-h, --help",R("global.help")).version(function(){try{const e=a(n(import.meta.url));return JSON.parse(t(s(e,"../../package.json"),"utf-8")).version}catch{return"1.0.0"}}(),"-v, --version",R("global.version")).option("--base <url>",R("global.base")).option("--non-interactive",R("global.non_interactive")).option("--json",R("global.json")).option("-y, --yes",R("global.yes")).option("--dry-run",R("global.dry_run")).option("--no-color",R("global.no_color")),z.configureOutput({writeErr:()=>{},outputError:()=>{}}),z.showSuggestionAfterError(),z.exitOverride(e=>{throw e}),z.commandsGroup(R("group.configure"));const L=z.command("setup").summary(R("setup.summary")).description(R("setup.description")).option("--key <key>",R("setup.opt.key"));for(const e of j){const t=new o(`--${e.option} <key>`,R(`setup.opt.${e.option}`));e.hidden&&t.hideHelp(),L.addOption(t)}L.option("--1m",R("setup.opt.one_m")).option("--no-1m",R("setup.opt.no_one_m")).option("--claude-official <on|off>",R("setup.opt.claude_official")).option("--desktop-registry <on|off>",R("setup.opt.desktop_registry")).option("--force",R("setup.opt.force")).option("--install",R("setup.opt.install")).option("--no-install",R("setup.opt.no_install")).option("--all",R("setup.opt.all")).action(async e=>{e.key||j.some(o=>e[o.option])||(e.key=A("SETUP_KEY")?.trim()||void 0);const o=Boolean(e.key||j.some(o=>e[o.option])),t=void 0!==e["1m"]||void 0!==e.claudeOfficial||void 0!==e.desktopRegistry,s="zh_CN"===i.getLocale()?"<你的 Key>":"<your key>";if(!o&&!t)throw S(i.t("setup.usage"),`${C} setup --key ${s}`,"missing_key");if(void 0!==e.claudeOfficial&&!["on","off"].includes(String(e.claudeOfficial).toLowerCase()))throw S(i.t("setup.claude_official_invalid",{value:String(e.claudeOfficial)}),`${C} setup --claude-official on|off`,"invalid_value");if(void 0!==e.desktopRegistry&&!["on","off"].includes(String(e.desktopRegistry).toLowerCase()))throw S(i.t("setup.desktop_registry_invalid",{value:String(e.desktopRegistry)}),`${C} setup --desktop-registry on|off`,"invalid_value");await v({key:e.key,...Object.fromEntries(j.map(o=>[o.option,e[o.option]])),all:e.all,oneMillion:e["1m"],claudeOfficial:e.claudeOfficial,desktopRegistry:e.desktopRegistry,force:e.force,install:e.install})}),p(L,{...N("setup",[[`${C} init`,"setup.alt.init"],[`${C} config <tool>`,"setup.alt.config"],[`${C} auth <key>`,"setup.alt.auth"]]),sections:[{title:R("setup.autodetect_title"),rows:[["Claude",R("setup.autodetect.claude")],["GPT",R("setup.autodetect.gpt")],["Grok",R("setup.autodetect.grok")],["Gemini",R("setup.autodetect.gemini")]]}],examples:[K(`${C} setup --key sk-xxx`,"setup.ex.key"),K(`${C} setup --key sk-xxx --install`,"setup.ex.install"),K(`${C} setup --claudekey sk-a --codexkey sk-b --agykey sk-g`,"setup.ex.split"),K(`${C} setup --key sk-xxx --force`,"setup.ex.force"),K(`${C} setup --key sk-xxx --base ${E}`,"setup.ex.base")]});const T=z.command("init").summary(R("init.summary")).description(R("init.description")).action(async()=>{await r.runFirstTimeSetup()});p(T,{...N("init",[[`${C} setup --key <key>`,"init.alt.setup"],[`${C}`,"init.alt.menu"]]),examples:[K(`${C} init`,"init.ex.run"),K(`${C} init --base ${E}`,"init.ex.base"),K(`${C}`,"init.ex.menu")]});const U=z.command("auth").summary(R("auth.summary")).description(R("auth.description")).argument("[token]",R("auth.arg.token")).action(async e=>{const o=[];e&&o.push(e),await d(o)});P(U);const B=U.command("revoke").description(R("auth.revoke")).action(async()=>{await d(["revoke"])});p(B,{examples:[K(`${C} auth revoke`,"auth.ex.revoke_ask"),K(`${C} auth revoke --yes`,"auth.ex.revoke")]});const H=U.command("reload <tool>").description(R("auth.reload")).action(async e=>{await d(["reload",e])});p(H,{examples:[K(`${C} auth reload claude-code`,"auth.ex.reload"),K(`${C} auth reload claude-code --json`,"auth.ex.reload_json")]}),p(U,{...N("auth",[[`${C} setup --key <key>`,"auth.alt.setup"]]),examples:[K(`${C} auth`,"auth.ex.prompt"),K(`${C} auth sk-xxx --non-interactive`,"auth.ex.save"),K(`${C} auth revoke --yes`,"auth.ex.revoke"),K(`${C} auth reload claude-code`,"auth.ex.reload")]});const M=z.command("config").summary(R("config.summary")).description(R("config.description")).argument("[args...]",R("config.arg.args")).option("-f, --force",R("config.opt.force")).allowUnknownOption(!0).action(async(e=[],o={})=>{await f(o.force?[...e,"--force"]:e)});p(M,{...N("config",[[`${C} setup --key <key> --force`,"config.alt.setup"],[`${C} status`,"config.alt.status"]]),sections:[{title:R("config.subcommands_title"),rows:[["<tool>",R("config.sub.tool")],["<tool> --force",R("config.sub.tool_force")],["<tool> --non-interactive",R("config.sub.tool_non_interactive")],["<tool> restore",R("config.sub.tool_restore")],["<tool> backups",R("config.sub.tool_backups")],["<tool> clear-model",R("config.sub.tool_clear_model")],["tool-model list",R("config.sub.tool_model_list")],["tool-model set <tool> [slot] <model>",R("config.sub.tool_model_set")],["tool-model clear <tool>",R("config.sub.tool_model_clear")],["profile list",R("config.sub.profile_list")],["profile create <name>",R("config.sub.profile_create")],["profile use <name>",R("config.sub.profile_use")],["profile delete <name>",R("config.sub.profile_delete")],["preset list",R("config.sub.preset_list")],["preset save <name>",R("config.sub.preset_save")],["preset use <name>",R("config.sub.preset_use")],["preset delete <name>",R("config.sub.preset_delete")],["backup list",R("config.sub.backup_list")],["backup create [label]",R("config.sub.backup_create")],["backup restore <name>",R("config.sub.backup_restore")]]},{title:R("config.tools_title"),rows:Object.values(c).filter(e=>!e.hidden).map(e=>[e.name,e.displayName])}],examples:[K(`${C} config codex`,"config.ex.menu"),K(`${C} config claude-code --force`,"config.ex.force"),K(`${C} config tool-model set codex gpt-6-astra`,"config.ex.tool_model"),K(`${C} config profile create work`,"config.ex.profile"),K(`${C} config backup create before-upgrade`,"config.ex.backup")]});const q=z.command("base").summary(R("base.summary")).description(R("base.description")).argument("[target]",R("base.arg.target")).action(async e=>{await O(e)});p(q,{...N("base",[[`${C} doctor`,"base.alt.doctor"],[`${C} bench`,"base.alt.bench"]]),sections:[{title:R("base.targets_title"),rows:[[R("base.target.none_term"),R("base.target.none")],[R("base.target.index_term"),R("base.target.index")],[R("base.target.url_term"),R("base.target.url")],["auto",R("base.target.auto")],["default",R("base.target.default",{url:l})]]}],examples:[K(`${C} base`,"base.ex.list"),K(`${C} base auto`,"base.ex.auto"),K(`${C} base 2`,"base.ex.index"),K(`${C} base ${E}`,"base.ex.url"),K(`${C} base default`,"base.ex.default")]}),z.commandsGroup(R("group.diagnose"));const F=z.command("status").summary(R("status.summary")).description(R("status.description")).action(async()=>{await x()});p(F,{...N("status",[[`${C} doctor`,"status.alt.doctor"]]),examples:[K(`${C} status`,"status.ex.show"),K(`${C} status --json`,"status.ex.json")]});const J=z.command("doctor").summary(R("doctor.summary")).description(R("doctor.description")).option("--deep",R("doctor.opt.deep")).action(async e=>{await g({deep:e.deep})});p(J,{...N("doctor",[[`${C} base auto`,"doctor.alt.base"],[`${C} logs tail`,"doctor.alt.logs"]]),examples:[K(`${C} doctor`,"doctor.ex.run"),K(`${C} doctor --deep`,"doctor.ex.deep")]});const Y=z.command("bench").summary(R("bench.summary")).description(R("bench.description")).option("--samples <n>",R("bench.opt.samples"),"5").action(async e=>{const o=[];e.samples&&o.push("--samples",e.samples),await $(o)});p(Y,{...N("bench",[[`${C} base`,"bench.alt.base"]]),examples:[K(`${C} bench`,"bench.ex.run"),K(`${C} bench --samples 3`,"bench.ex.samples"),K(`${C} bench --json`,"bench.ex.json")]});const D=z.command("logs").summary(R("logs.summary")).description(R("logs.description")).argument("[action]",R("logs.arg.action")).argument("[file]",R("logs.arg.file")).action(async(e,o)=>{const t=[];e&&t.push(e),o&&t.push(o),await b(t)});p(D,{...N("logs",[[`${C} doctor`,"logs.alt.doctor"]]),sections:[{title:R("logs.actions_title"),rows:[["list",R("logs.action.list")],["tail [file]",R("logs.action.tail")],["path",R("logs.action.path")]]}],examples:[K(`${C} logs`,"logs.ex.list"),K(`${C} logs tail`,"logs.ex.tail"),K(`${C} logs path`,"logs.ex.path")]}),z.commandsGroup(R("group.maintain"));const I=z.command("upgrade").summary(R("upgrade.summary")).description(R("upgrade.description")).argument("[tools...]",R("upgrade.arg.tools")).action(async(e=[])=>{await _(e)});p(I,{...N("upgrade",[[`${C} update`,"upgrade.alt.update"]]),examples:[K(`${C} upgrade`,"upgrade.ex.all"),K(`${C} upgrade claude-code`,"upgrade.ex.one"),K(`${C} upgrade codex agy`,"upgrade.ex.many")]});const Q=z.command("refresh").summary(R("refresh.summary")).description(R("refresh.description")).action(async()=>{await y()});p(Q,{...N("refresh",[[`${C} setup --key <你的 Key>`,"refresh.alt.setup"]]),examples:[K(`${C} refresh`,"refresh.ex.run"),K(`${C} refresh --base ${G}`,"refresh.ex.base")]});const V=z.command("update").summary(R("update.summary")).description(R("update.description")).action(async()=>{await k()});p(V,{...N("update",[[`${C} upgrade`,"update.alt.upgrade"]]),examples:[K(`${C} update`,"update.ex.check"),K(`${C} update --json`,"update.ex.json")]});const W=z.command("codex").summary(R("codex.summary")).description(R("codex.description"));P(W);const X=W.command("sessions").summary(R("codex_sessions.summary")).description(R("codex_sessions.description")).option("--to <provider>",R("codex_sessions.opt.to")).option("--undo <dir>",R("codex_sessions.opt.undo")).action(async e=>{await w(e)});p(W,{...N("codex"),examples:[K(`${C} codex sessions`,"codex_sessions.ex.move"),K(`${C} codex sessions --undo <dir>`,"codex_sessions.ex.undo")]}),p(X,{...N("codex_sessions",[[`${C} codex sessions --undo <dir>`,"codex_sessions.alt.undo"]]),examples:[K(`${C} codex sessions`,"codex_sessions.ex.move"),K(`${C} codex sessions --to custom`,"codex_sessions.ex.to"),K(`${C} codex sessions --undo <dir>`,"codex_sessions.ex.undo")]});const Z=z.command("lang").summary(R("lang.summary")).description(R("lang.description"));P(Z);const ee=Z.command("show").description(R("lang.show")).action(async()=>{await m(["show"])}),oe=Z.command("set <locale>").description(R("lang.set")).action(async e=>{await m(["set",e])}),te=[K(`${C} lang show`,"lang.ex.show"),K(`${C} lang set en_US`,"lang.ex.set_en"),K(`${C} lang set zh_CN`,"lang.ex.set_zh")];p(Z,{...N("lang",[[`${C} enter lang`,"lang.alt.enter"]]),examples:te}),p(ee,{examples:[te[0],K(`${C} lang show --json`,"lang.ex.show_json")]}),p(oe,{examples:te.slice(1)});const se=z.command("completion").summary(R("completion.summary")).description(R("completion.description")).argument("<shell>",R("completion.arg.shell")).action(async e=>{await h([e])});p(se,{...N("completion"),examples:[K(`${C} completion bash > ~/.${C}-completion.bash`,"completion.ex.bash"),K(`${C} completion zsh > ~/.${C}-completion.zsh`,"completion.ex.zsh"),K(`${C} completion fish > ~/.config/fish/completions/${C}.fish`,"completion.ex.fish")]});const ae=z.command("enter").summary(R("enter.summary")).description(R("enter.description")).argument("[option]",R("enter.arg.option")).action(async e=>{if(e)switch(e){case"lang":case"language":await r.configLanguage();break;case"apikey":case"api-key":await r.configApiKey();break;case"models":await r.configModels();break;default:await f([e])}else await r.run()});p(ae,{...N("enter",[[`${C}`,"enter.alt.menu"],[`${C} config <tool>`,"enter.alt.config"]]),sections:[{title:R("enter.options_title"),rows:[[R("enter.option.none_term"),R("enter.option.none")],["lang",R("enter.option.lang")],["apikey",R("enter.option.apikey")],["models",R("enter.option.models")],["<tool>",R("enter.option.tool")]]}],examples:[K(`${C} enter`,"enter.ex.menu"),K(`${C} enter models`,"enter.ex.models"),K(`${C} enter codex`,"enter.ex.tool")]}),P(z),z.action(async()=>{await r.run()}),p(z,{examples:[K(`${C}`,"root.ex.menu"),K(`${C} setup --key sk-xxx`,"root.ex.setup"),K(`${C} doctor`,"root.ex.doctor"),K(`${C} base auto`,"root.ex.base"),K(`${C} config codex`,"root.ex.config")]});const ne=e=>{for(const o of e.commands)o.helpOption("-h, --help",R("global.help")),ne(o)};return ne(z),z}
@@ -1 +1 @@
1
- import{join as e}from"path";import{applyGatewayModels as t,claudeCodeManager as o}from"../claude-code-manager.js";import{backupBeforeWrite as a}from"./backup.js";import{i18n as n}from"../i18n.js";import{baseModelId as s}from"../model-catalog.js";import{gatewayModelSpecs as i,prettyModelName as r,vendorNames as d}from"../gateway-models.js";import{toolHome as l}from"./types.js";import{spawnSync as c}from"child_process";import{existsSync as u,readFileSync as p}from"fs";import{detectManagedOverrides as m}from"./claude-managed.js";import{installOfficialPlugins as g}from"./claude-plugins.js";import{findInstalls as f,mirrorInstallCommand as h,brandInstallScripts as C}from"./tool-installs.js";import{updateNativeFromMirror as _}from"./claude-native-mirror.js";import{brandEnv as j}from"../brand.js";const k=e(l(),".claude","settings.json"),y=e(l(),".claude.json");let P,S=null,v=()=>0===c("security",["find-generic-password","-s","Claude Code-credentials"],{stdio:"ignore"}).status;export function setClaudeKeychainProbeForTests(e){v=e}export function claudeAccountLoginPresent(){const t=process.env.CLAUDE_CONFIG_DIR?.trim()||e(l(),".claude");if(u(e(t,".credentials.json")))return!0;if("darwin"!==process.platform||j("TEST_HOME"))return!1;try{return v()}catch{return!1}}function b(){try{const t=JSON.parse(p(e(l(),".claude","settings.json"),"utf-8"));return"string"==typeof t.autoUpdatesChannel?t.autoUpdatesChannel:"latest"}catch{return"latest"}}function x(e){if(!e)return;const t=new Set(e.models);return i("claude-code",e.clientModels).filter(e=>t.has(e.id))}const w={command:"claude",npmPackage:"@anthropic-ai/claude-code",native:{binDir:[".local","bin"],updateArgs:["update"],dataDirs:[[".local","share","claude"]],mirrorUpdate:()=>_(b())},mirrorScript:C("claude-code"),brew:"claude-code"};export const claudeCodeAdapter={name:"claude-code",displayName:"Claude Code",command:"claude",installCommand:h(w),upgradeCommand:"claude update",installSpec:w,upgradeHints:e=>"stable"===b()?[n.t("tools.claude_code.stable_channel",{min:e})]:[],configPath:k,wantsModelCatalog:!0,loadPrivateConfig(e){a(k),a(y),P=x(e.catalog),o.loadPrivateConfig(e.apiKey,e.models,e.catalog?.models,P);const t=f(claudeCodeAdapter.installSpec)[0];S=t?g(t.path):null},unloadPrivateConfig(){a(k),o.unloadPrivateConfig()},detectCurrentConfig:()=>o.detectCurrentConfig(),getConfig:()=>({settings:o.getSettings(),mcp:o.getMCPConfig()}),updateConfig(e){const t=e||{};t.settings&&o.saveSettings(t.settings),t.mcp&&o.saveMCPConfig(t.mcp)},clearPinnedModels:e=>(a(k),o.clearPinnedModels(e?.models)),listedModels(){const e=o.getSettings().modelPicker;return Array.isArray(e?.options)?e.options.map(e=>s(String(e.model))):null},refreshModelMenu(e){const n=o.getSettings(),s=t(n,x(e.catalog));JSON.stringify(s)!==JSON.stringify(n)&&(a(k),o.saveSettings(s))},applyNotes(){const e=[];S?.installed.length&&(e.push({kind:"summary",text:n.t("tools.claude_code.plugins_installed",{count:String(S.installed.length)})}),e.push({kind:"detail",text:S.installed.join(", ")})),("marketplace"===S?.skipped||S?.failed.length)&&e.push({kind:"action",text:n.t("tools.claude_code.plugins_failed")}),P&&P.length>0&&(e.push({kind:"summary",text:n.t("tools.claude_code.gateway_models",{count:String(P.length),vendors:d(P.map(e=>e.id)).join(" / ")})}),e.push({kind:"detail",text:P.map(e=>e.name||r(e.id)).join(", ")})),"win32"!==process.platform||process.env.CLAUDE_CODE_GIT_BASH_PATH||0===c("where",["git"],{windowsHide:!0,stdio:"ignore"}).status||e.push({kind:"action",text:n.t("tools.claude_code.no_git_bash")}),claudeAccountLoginPresent()&&e.push({kind:"detail",text:n.t("tools.claude_code.account_login_overridden")});for(const t of m())e.push({kind:"action",text:n.t("tools.claude_code.managed_override",{source:t.source,keys:t.keys.join(", ")})});for(const t of o.getLastTierFallbacks())e.push({kind:"detail",text:n.t("tools.claude_code.tier_fallback",{tier:t.tier,from:t.from,to:t.to})});return e},backupPaths:()=>[k,y],forceResetPaths:()=>[k]};
1
+ import{join as e}from"path";import{applyGatewayModels as t,claudeCodeManager as o}from"../claude-code-manager.js";import{backupBeforeWrite as n}from"./backup.js";import{i18n as a}from"../i18n.js";import{baseModelId as s}from"../model-catalog.js";import{gatewayModelSpecs as i,prettyModelName as r,vendorNames as l}from"../gateway-models.js";import{toolHome as d}from"./types.js";import{spawnSync as c}from"child_process";import{existsSync as u,readFileSync as p}from"fs";import{detectManagedOverrides as m}from"./claude-managed.js";import{installOfficialPlugins as g}from"./claude-plugins.js";import{findInstalls as f,mirrorInstallCommand as h,brandInstallScripts as C}from"./tool-installs.js";import{updateNativeFromMirror as _}from"./claude-native-mirror.js";import{brandEnv as k}from"../brand.js";const j=e(d(),".claude","settings.json"),y=e(d(),".claude.json");let P,S=null,v=()=>0===c("security",["find-generic-password","-s","Claude Code-credentials"],{stdio:"ignore"}).status;export function setClaudeKeychainProbeForTests(e){v=e}export function claudeAccountLoginPresent(){const t=process.env.CLAUDE_CONFIG_DIR?.trim()||e(d(),".claude");if(u(e(t,".credentials.json")))return!0;if("darwin"!==process.platform||k("TEST_HOME"))return!1;try{return v()}catch{return!1}}function x(){try{const t=JSON.parse(p(e(d(),".claude","settings.json"),"utf-8"));return"string"==typeof t.autoUpdatesChannel?t.autoUpdatesChannel:"latest"}catch{return"latest"}}function b(e){if(!e)return;const t=new Set(e.models);return i("claude-code",e.clientModels).filter(e=>t.has(e.id))}const w={command:"claude",npmPackage:"@anthropic-ai/claude-code",native:{binDir:[".local","bin"],updateArgs:["update"],dataDirs:[[".local","share","claude"]],mirrorUpdate:()=>_(x())},mirrorScript:C("claude-code"),brew:"claude-code"};export const claudeCodeAdapter={name:"claude-code",displayName:"Claude Code",command:"claude",installCommand:h(w),upgradeCommand:"claude update",installSpec:w,upgradeHints:e=>"stable"===x()?[a.t("tools.claude_code.stable_channel",{min:e})]:[],configPath:j,wantsModelCatalog:!0,loadPrivateConfig(t){n(j),n(y),P=b(t.catalog),o.loadPrivateConfig(t.apiKey,t.models,t.catalog?.models,P);const a=e(d(),".local","bin","win32"===process.platform?"claude.exe":"claude"),s=f(claudeCodeAdapter.installSpec)[0]?.path??(u(a)?a:null);S=s?g(s):null},unloadPrivateConfig(){n(j),o.unloadPrivateConfig()},detectCurrentConfig:()=>o.detectCurrentConfig(),getConfig:()=>({settings:o.getSettings(),mcp:o.getMCPConfig()}),updateConfig(e){const t=e||{};t.settings&&o.saveSettings(t.settings),t.mcp&&o.saveMCPConfig(t.mcp)},clearPinnedModels:e=>(n(j),o.clearPinnedModels(e?.models)),listedModels(){const e=o.getSettings().modelPicker;return Array.isArray(e?.options)?e.options.map(e=>s(String(e.model))):null},refreshModelMenu(e){const a=o.getSettings(),s=t(a,b(e.catalog));JSON.stringify(s)!==JSON.stringify(a)&&(n(j),o.saveSettings(s))},applyNotes(){const e=[];S?.installed.length&&(e.push({kind:"summary",text:a.t("tools.claude_code.plugins_installed",{count:String(S.installed.length)})}),e.push({kind:"detail",text:S.installed.join(", ")})),"git"===S?.skipped?e.push({kind:"action",text:a.t("tools.claude_code.plugins_need_git")}):("marketplace"===S?.skipped||S?.failed.length)&&e.push({kind:"action",text:a.t("tools.claude_code.plugins_failed")}),P&&P.length>0&&(e.push({kind:"summary",text:a.t("tools.claude_code.gateway_models",{count:String(P.length),vendors:l(P.map(e=>e.id)).join(" / ")})}),e.push({kind:"detail",text:P.map(e=>e.name||r(e.id)).join(", ")})),"win32"!==process.platform||process.env.CLAUDE_CODE_GIT_BASH_PATH||0===c("where",["git"],{windowsHide:!0,stdio:"ignore"}).status||e.push({kind:"action",text:a.t("tools.claude_code.no_git_bash")}),claudeAccountLoginPresent()&&e.push({kind:"detail",text:a.t("tools.claude_code.account_login_overridden")});for(const t of m())e.push({kind:"action",text:a.t("tools.claude_code.managed_override",{source:t.source,keys:t.keys.join(", ")})});for(const t of o.getLastTierFallbacks())e.push({kind:"detail",text:a.t("tools.claude_code.tier_fallback",{tier:t.tier,from:t.from,to:t.to})});return e},backupPaths:()=>[j,y],forceResetPaths:()=>[j]};
@@ -1 +1 @@
1
- import{spawnSync as e}from"child_process";import{readFileSync as t}from"fs";import{join as i}from"path";import{logger as o}from"../../utils/logger.js";import{configManager as s}from"../config.js";import{toolHome as n}from"./types.js";import{brandEnv as r,brand as l}from"../brand.js";export const PLUGIN_SOURCES=[...l().pluginMarketplaces,{name:"claude-plugins-official",add:"anthropics/claude-plugins-official",probe:"https://github.com/anthropics/claude-plugins-official.git"}];export const OFFICIAL_PLUGINS=["code-review","feature-dev","frontend-design","pr-review-toolkit","commit-commands","security-guidance","code-simplifier","skill-creator","claude-md-management","claude-code-setup"];const a="official_plugins_offered";let d=(t,s)=>{const l=e(t,s,{env:r("TEST_HOME")?{...process.env,CLAUDE_CONFIG_DIR:i(n(),".claude")}:process.env,encoding:"utf-8",timeout:12e4,windowsHide:!0,stdio:["ignore","pipe","pipe"],shell:"win32"===process.platform&&/\.cmd$/i.test(t)});return 0!==l.status&&o.logError(`claude ${s.join(" ")}`,new Error(`${l.stderr??""}${l.stdout??""}`.trim())),0===l.status},c=t=>0===e("git",["ls-remote","--heads",t],{timeout:8e3,windowsHide:!0,stdio:"ignore"}).status;export function setClaudePluginRunnerForTests(e){d=e}export function setPluginSourceProbeForTests(e){c=e}export function installOfficialPlugins(e){if("1"===r("SKIP_CLAUDE_PLUGINS"))return{installed:[],failed:[],skipped:"disabled"};const o=s.getToolSetting("claude-code",a),l=new Set("string"==typeof o?o.split(",").filter(Boolean):[]),p=function(){try{const e=JSON.parse(t(i(n(),".claude","plugins","installed_plugins.json"),"utf-8"));return new Set(Object.keys(e.plugins??{}).map(e=>e.replace(/@[^@]*$/,"")))}catch{return new Set}}(),u=e=>p.has(e),f=OFFICIAL_PLUGINS.filter(e=>!l.has(e)&&!u(e));if(0===f.length)return{installed:[],failed:[],skipped:null};const m=PLUGIN_SOURCES.find(e=>c(e.probe));if(!m)return{installed:[],failed:[],skipped:"marketplace"};d(e,["plugin","marketplace","add",m.add]);const g={installed:[],failed:[],skipped:null,source:m.name};for(const t of f)d(e,["plugin","install",`${t}@${m.name}`])?(g.installed.push(t),l.add(t)):g.failed.push(t);for(const e of OFFICIAL_PLUGINS)u(e)&&l.add(e);return s.setToolSetting("claude-code",a,[...l].join(",")),g}
1
+ import{spawnSync as e}from"child_process";import{existsSync as t,readFileSync as i}from"fs";import{join as o}from"path";import{logger as s}from"../../utils/logger.js";import{configManager as n}from"../config.js";import{toolHome as r}from"./types.js";import{brandEnv as l,brand as a}from"../brand.js";export const PLUGIN_SOURCES=[...a().pluginMarketplaces,{name:"claude-plugins-official",add:"anthropics/claude-plugins-official",probe:"https://github.com/anthropics/claude-plugins-official.git"}];export const OFFICIAL_PLUGINS=["code-review","feature-dev","frontend-design","pr-review-toolkit","commit-commands","security-guidance","code-simplifier","skill-creator","claude-md-management","claude-code-setup"];const d="official_plugins_offered";let p=(t,i)=>{const n=e(t,i,{env:l("TEST_HOME")?{...process.env,CLAUDE_CONFIG_DIR:o(r(),".claude")}:process.env,encoding:"utf-8",timeout:12e4,windowsHide:!0,stdio:["ignore","pipe","pipe"],shell:"win32"===process.platform&&/\.cmd$/i.test(t)});return 0!==n.status&&s.logError(`claude ${i.join(" ")}`,new Error(`${n.stderr??""}${n.stdout??""}`.trim())),0===n.status},c=t=>0===e("git",["ls-remote","--heads",t],{timeout:8e3,windowsHide:!0,stdio:"ignore"}).status;export function setClaudePluginRunnerForTests(e){p=e}export function setPluginSourceProbeForTests(e){c=e}export function installOfficialPlugins(s){if("1"===l("SKIP_CLAUDE_PLUGINS"))return{installed:[],failed:[],skipped:"disabled"};const a=n.getToolSetting("claude-code",d),u=new Set("string"==typeof a?a.split(",").filter(Boolean):[]),f=function(){try{const e=JSON.parse(i(o(r(),".claude","plugins","installed_plugins.json"),"utf-8"));return new Set(Object.keys(e.plugins??{}).map(e=>e.replace(/@[^@]*$/,"")))}catch{return new Set}}(),m=e=>f.has(e),g=OFFICIAL_PLUGINS.filter(e=>!u.has(e)&&!m(e));if(0===g.length)return{installed:[],failed:[],skipped:null};if("darwin"===process.platform&&0!==e("xcode-select",["-p"],{stdio:"ignore"}).status&&!["/opt/homebrew/bin/git","/usr/local/bin/git"].some(e=>t(e))||0!==e("git",["--version"],{timeout:8e3,windowsHide:!0,stdio:"ignore"}).status)return{installed:[],failed:[],skipped:"git"};const S=PLUGIN_SOURCES.find(e=>c(e.probe));if(!S)return{installed:[],failed:[],skipped:"marketplace"};p(s,["plugin","marketplace","add",S.add]);const h={installed:[],failed:[],skipped:null,source:S.name};for(const e of g)p(s,["plugin","install",`${e}@${S.name}`])?(h.installed.push(e),u.add(e)):h.failed.push(e);for(const e of OFFICIAL_PLUGINS)m(e)&&u.add(e);return n.setToolSetting("claude-code",d,[...u].join(",")),h}
@@ -1 +1 @@
1
- import{spawnSync as t}from"child_process";import{existsSync as e,readFileSync as o}from"fs";import{dirname as n,join as i}from"path";import{fileURLToPath as s}from"url";import{logger as r}from"../../utils/logger.js";import{getCodexRules as l,compareVersions as u}from"../model-registry.js";import{autoCompactTokens as a,modelBlurb as d,prettyModelName as c}from"../gateway-models.js";import{toolHome as p}from"./types.js";import{brandEnv as _,PROVIDER_KEY as m}from"../brand.js";const f=n(s(import.meta.url));export const CODEX_CATALOG_FILE=`${m}-model-catalog.json`;export const codexCatalogPath=()=>i(p(),".codex",CODEX_CATALOG_FILE);function x(t){return!!t&&"object"==typeof t&&!Array.isArray(t)}function w(t){try{const e=JSON.parse(t),o=x(e)&&Array.isArray(e.models)?e.models.filter(x):[];return o.length>0?o:null}catch{return null}}export function loadBundledCodexModels(){for(const o of function(){const t=_("CODEX_BIN");if(void 0!==t)return t.trim()?[t.trim()]:[];const e=["codex"];if("darwin"===process.platform)for(const t of["/Applications",i(p(),"Applications")])e.push(i(t,"ChatGPT.app/Contents/Resources/codex-cli/bin/codex")),e.push(i(t,"Codex.app/Contents/Resources/codex"));return e}()){if("codex"!==o&&!e(o))continue;const n={encoding:"utf-8",timeout:2e4,maxBuffer:67108864,windowsHide:!0,stdio:["ignore","pipe","pipe"]},i="win32"===process.platform&&"codex"===o?t("codex debug models --bundled",{...n,shell:!0}):t(o,["debug","models","--bundled"],n);if(0===i.status&&i.stdout){const t=w(i.stdout);if(t)return t}(i.error||0!==i.status)&&r.logError("loadBundledCodexModels",i.error??new Error(`${o} exited ${i.status}`))}return null}export function loadPreviousCodexModels(){const t=g()?.filter(t=>!h(t));return t&&t.length>0?t:null}export function previousGatewayModelIds(){return(g()??[]).filter(h).map(t=>String(t.slug))}function g(){return e(codexCatalogPath())?w(o(codexCatalogPath(),"utf-8")):null}function h(t){return"number"==typeof t.priority&&t.priority>=1e3}let y=null;function b(){if(null!==y)return y;const t=[i(f,"..","..","..","codex-base-instructions.md"),i(f,"..","..","codex-base-instructions.md"),i(f,"codex-base-instructions.md")],n=t.find(t=>e(t));if(!n)throw new Error(`codex-base-instructions.md not found, searched: ${t.join(", ")}`);return y=o(n,"utf-8"),y}function C(t){return"number"==typeof t&&Number.isFinite(t)&&t>0?t:void 0}function v(t,e,o,n){const i=o?t:Math.min(t,e);return{window:i,compact:a(i,n)}}function M(t,e,o,n){const{standardContextWindow:i}=l();let s=C(t.contextWindow)??i;n&&t.id.startsWith("claude-")&&(s=n.has(t.id)?Math.max(s,1e6):Math.min(s,2e5));const{window:r,compact:u}=v(s,i,o,C(t.autoCompactTokens));return{slug:t.id,display_name:t.name||c(t.id),description:d(t.description,{millionContext:r>=1e6})??null,supported_reasoning_levels:[],shell_type:"unified_exec",visibility:"list",supported_in_api:!0,priority:e,additional_speed_tiers:[],service_tiers:[],availability_nux:null,upgrade:null,model_messages:{instructions_template:b()},base_instructions:b(),supports_reasoning_summaries:!0,supports_parallel_tool_calls:!1,prefer_websockets:!1,include_skills_usage_instructions:!1,include_plugin_usage_instructions:!1,include_apps_usage_instructions:!1,default_reasoning_summary:"auto",support_verbosity:!1,default_verbosity:null,apply_patch_tool_type:null,web_search_tool_type:"text",truncation_policy:{mode:"bytes",limit:1e4},supports_image_detail_original:!1,context_window:r,max_context_window:r,auto_compact_token_limit:u,effective_context_window_percent:95,experimental_supported_tools:[],input_modalities:["text","image"],supports_search_tool:!1,supports_experimental_context:!1,use_responses_lite:!1,supports_reasoning_effort_updates:!1,node_repl_auto_review_required:!1,node_repl_disabled:!1}}function A(t,e,o){if("list"!==t.visibility)return t;const n=C(t.context_window);if(!n)return t;const i=C(t.max_context_window)??n,s=o?Math.min(C(e?.contextWindow)??i,i):n,{window:r,compact:l}=v(s,n,!0,C(e?.autoCompactTokens));return{...t,context_window:r,auto_compact_token_limit:l}}export function buildCodexCatalog(t){const{bundled:e,specs:o,oneMillion:n,selectedModel:i}=t,s=t.claudeOneMillion?new Set(t.claudeOneMillion):void 0,r=t.keyModels?new Set(t.keyModels):null,l=new Set(t.gatewayAvailable),a=t=>!r||r.has(t)||t===i,d=t=>l.has(t)||t===i,c=new Map(o.map(t=>[t.id,t])),p=[],_=new Set;for(const t of e){const e="string"==typeof t.slug?t.slug:"";e&&!_.has(e)&&("list"!==t.visibility||a(e))&&(_.add(e),p.push(A(t,c.get(e),n)))}const m=[...o];i&&!c.has(i)&&m.push({id:i});const f=function(t){const e=new Map;for(const o of t){const t=/^claude-([a-z]+)-(.+)$/.exec(o);if(!t)continue;const n=t[2].split("-").filter(t=>/^\d{1,2}$/.test(t)).join("."),i=e.get(t[1]);(!i||u(n,i.version)>0)&&e.set(t[1],{id:o,version:n})}return new Set([...e.values()].map(t=>t.id))}(m.map(t=>t.id).filter(d));for(const t of m)!_.has(t.id)&&d(t.id)&&(t.id.startsWith("claude-")&&!f.has(t.id)&&t.id!==i||(_.add(t.id),p.push(M(t,1e3+p.length,n,s))));return{models:p}}
1
+ import{spawnSync as t}from"child_process";import{existsSync as e,readFileSync as o}from"fs";import{dirname as n,join as i}from"path";import{fileURLToPath as s}from"url";import{logger as r}from"../../utils/logger.js";import{getCodexRules as l,compareVersions as a}from"../model-registry.js";import{autoCompactTokens as d,modelBlurb as u,prettyModelName as c}from"../gateway-models.js";import{toolHome as p}from"./types.js";import{brandEnv as _,PROVIDER_KEY as m}from"../brand.js";const f=n(s(import.meta.url));export const CODEX_CATALOG_FILE=`${m}-model-catalog.json`;export const codexCatalogPath=()=>i(p(),".codex",CODEX_CATALOG_FILE);function x(t){return!!t&&"object"==typeof t&&!Array.isArray(t)}function w(t){try{const e=JSON.parse(t),o=x(e)&&Array.isArray(e.models)?e.models.filter(x):[];return o.length>0?o:null}catch{return null}}export function loadBundledCodexModels(){for(const o of function(){const t=_("CODEX_BIN");if(void 0!==t)return t.trim()?[t.trim()]:[];const e=["codex"];if("win32"===process.platform){const t=process.env.LOCALAPPDATA||i(p(),"AppData","Local");e.push(i(t,"Programs","OpenAI","Codex","bin","codex.exe"))}else e.push(i(p(),".local","bin","codex"));if("darwin"===process.platform)for(const t of["/Applications",i(p(),"Applications")])e.push(i(t,"ChatGPT.app/Contents/Resources/codex-cli/bin/codex")),e.push(i(t,"Codex.app/Contents/Resources/codex"));return e}()){if("codex"!==o&&!e(o))continue;const n={encoding:"utf-8",timeout:2e4,maxBuffer:67108864,windowsHide:!0,stdio:["ignore","pipe","pipe"]},i="win32"===process.platform&&"codex"===o?t("codex debug models --bundled",{...n,shell:!0}):t(o,["debug","models","--bundled"],n);if(0===i.status&&i.stdout){const t=w(i.stdout);if(t)return t}(i.error||0!==i.status)&&r.logError("loadBundledCodexModels",i.error??new Error(`${o} exited ${i.status}`))}return null}export function loadPreviousCodexModels(){const t=g()?.filter(t=>!h(t));return t&&t.length>0?t:null}export function previousGatewayModelIds(){return(g()??[]).filter(h).map(t=>String(t.slug))}function g(){return e(codexCatalogPath())?w(o(codexCatalogPath(),"utf-8")):null}function h(t){return"number"==typeof t.priority&&t.priority>=1e3}let y=null;function b(){if(null!==y)return y;const t=[i(f,"..","..","..","codex-base-instructions.md"),i(f,"..","..","codex-base-instructions.md"),i(f,"codex-base-instructions.md")],n=t.find(t=>e(t));if(!n)throw new Error(`codex-base-instructions.md not found, searched: ${t.join(", ")}`);return y=o(n,"utf-8"),y}function C(t){return"number"==typeof t&&Number.isFinite(t)&&t>0?t:void 0}function v(t,e,o,n){const i=o?t:Math.min(t,e);return{window:i,compact:d(i,n)}}function A(t,e,o,n){const{standardContextWindow:i}=l();let s=C(t.contextWindow)??i;n&&t.id.startsWith("claude-")&&(s=n.has(t.id)?Math.max(s,1e6):Math.min(s,2e5));const{window:r,compact:a}=v(s,i,o,C(t.autoCompactTokens));return{slug:t.id,display_name:t.name||c(t.id),description:u(t.description,{millionContext:r>=1e6})??null,supported_reasoning_levels:[],shell_type:"unified_exec",visibility:"list",supported_in_api:!0,priority:e,additional_speed_tiers:[],service_tiers:[],availability_nux:null,upgrade:null,model_messages:{instructions_template:b()},base_instructions:b(),supports_reasoning_summaries:!0,supports_parallel_tool_calls:!1,prefer_websockets:!1,include_skills_usage_instructions:!1,include_plugin_usage_instructions:!1,include_apps_usage_instructions:!1,default_reasoning_summary:"auto",support_verbosity:!1,default_verbosity:null,apply_patch_tool_type:null,web_search_tool_type:"text",truncation_policy:{mode:"bytes",limit:1e4},supports_image_detail_original:!1,context_window:r,max_context_window:r,auto_compact_token_limit:a,effective_context_window_percent:95,experimental_supported_tools:[],input_modalities:["text","image"],supports_search_tool:!1,supports_experimental_context:!1,use_responses_lite:!1,supports_reasoning_effort_updates:!1,node_repl_auto_review_required:!1,node_repl_disabled:!1}}function M(t,e,o){if("list"!==t.visibility)return t;const n=C(t.context_window);if(!n)return t;const i=C(t.max_context_window)??n,s=o?Math.min(C(e?.contextWindow)??i,i):n,{window:r,compact:l}=v(s,n,!0,C(e?.autoCompactTokens));return{...t,context_window:r,auto_compact_token_limit:l}}export function buildCodexCatalog(t){const{bundled:e,specs:o,oneMillion:n,selectedModel:i}=t,s=t.claudeOneMillion?new Set(t.claudeOneMillion):void 0,r=t.keyModels?new Set(t.keyModels):null,l=new Set(t.gatewayAvailable),d=t=>!r||r.has(t)||t===i,u=t=>l.has(t)||t===i,c=new Map(o.map(t=>[t.id,t])),p=[],_=new Set;for(const t of e){const e="string"==typeof t.slug?t.slug:"";e&&!_.has(e)&&("list"!==t.visibility||d(e))&&(_.add(e),p.push(M(t,c.get(e),n)))}const m=[...o];i&&!c.has(i)&&m.push({id:i});const f=function(t){const e=new Map;for(const o of t){const t=/^claude-([a-z]+)-(.+)$/.exec(o);if(!t)continue;const n=t[2].split("-").filter(t=>/^\d{1,2}$/.test(t)).join("."),i=e.get(t[1]);(!i||a(n,i.version)>0)&&e.set(t[1],{id:o,version:n})}return new Set([...e.values()].map(t=>t.id))}(m.map(t=>t.id).filter(u));for(const t of m)!_.has(t.id)&&u(t.id)&&(t.id.startsWith("claude-")&&!f.has(t.id)&&t.id!==i||(_.add(t.id),p.push(A(t,1e3+p.length,n,s))));return{models:p}}
@@ -411,7 +411,8 @@
411
411
  "no_git_bash": "Git for Windows not found: Claude Code falls back to PowerShell for commands, which works, but bash commands and scripts won't; install Git (winget install Git.Git, or download from https://registry.npmmirror.com/binary.html?path=git-for-windows/)",
412
412
  "plugins_installed": "{{count}} official plugins installed (code review, feature dev, frontend design, …); type / to see them",
413
413
  "plugins_failed": "Official plugins could not be installed (GitHub unreachable, most likely); everything else works. Run {{cli}} config claude-code --non-interactive again later",
414
- "account_login_overridden": "Claude Code on this computer is signed in to a Claude account; the {{brand}} token {{product}} writes takes precedence, so Claude Code uses {{brand}}. To go back to the account, remove the {{brand}} config with {{cli}} config claude-code"
414
+ "account_login_overridden": "Claude Code on this computer is signed in to a Claude account; the {{brand}} token {{product}} writes takes precedence, so Claude Code uses {{brand}}. To go back to the account, remove the {{brand}} config with {{cli}} config claude-code",
415
+ "plugins_need_git": "Official plugins are downloaded with Git, which this computer doesn't have yet (on a Mac, Apple's Command Line Tools); everything else works. Once Git is installed, run {{cli}} config claude-code --non-interactive"
415
416
  },
416
417
  "model_family": {
417
418
  "gpt": "GPT",
@@ -411,7 +411,8 @@
411
411
  "no_git_bash": "没找到 Git for Windows:Claude Code 会改用 PowerShell 执行命令,可以用,但 bash 写法的命令和脚本跑不了;建议安装 Git(winget install Git.Git,或从国内镜像 https://registry.npmmirror.com/binary.html?path=git-for-windows/ 下载)",
412
412
  "plugins_installed": "装好 {{count}} 个官方插件(代码审查、功能开发、前端设计等),输入 / 可以看到",
413
413
  "plugins_failed": "官方插件没装上(多半是连不上 GitHub),不影响使用;网络好时再运行 {{cli}} config claude-code --non-interactive 即可",
414
- "account_login_overridden": "这台电脑的 Claude Code 登录过 Claude 官方账号;{{product}} 写入的 {{brand}} 令牌会优先生效,Claude Code 走 {{brand}}。要改回官方账号,用 {{cli}} config claude-code 移除 {{brand}} 配置"
414
+ "account_login_overridden": "这台电脑的 Claude Code 登录过 Claude 官方账号;{{product}} 写入的 {{brand}} 令牌会优先生效,Claude Code 走 {{brand}}。要改回官方账号,用 {{cli}} config claude-code 移除 {{brand}} 配置",
415
+ "plugins_need_git": "官方插件要用 Git 下载,这台电脑还没有 Git(Mac 上要先装好苹果命令行工具),不影响使用;装好 Git 后运行 {{cli}} config claude-code --non-interactive 补装"
415
416
  },
416
417
  "model_family": {
417
418
  "gpt": "GPT",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibeapi/api-helper",
3
- "version": "0.0.98",
3
+ "version": "0.0.100",
4
4
  "description": "CLI tool for managing AI coding assistants (Claude Code, Codex, OpenClaw, Hermes, AtomCode, Grok Build) with one unified config",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",