@vibeapi/cli 0.0.151 → 0.0.152

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.
@@ -18,5 +18,7 @@ export declare class Command {
18
18
  private rejectUnknownCommand;
19
19
  private suggestCommand;
20
20
  private normalizeCommanderError;
21
+ /** The longest known long option `name` starts with, when more text follows it (`--keysk-…` → `--key`). */
22
+ private gluedOption;
21
23
  getProgram(): Commander;
22
24
  }
@@ -1 +1 @@
1
- import{i18n as r,detectSystemLang as n}from"./i18n.js";import{configManager as o}from"./config.js";import{runModelRefresh as t}from"./model-refresh.js";import{refreshClientConfig as e}from"./client-config-sync.js";import{normalizeBaseUrl as i}from"./gateway-addresses.js";import s from"chalk";import{setRuntimeOptions as m,detectColorPreferenceFromEnv as a,isDryRun as c}from"./runtime-options.js";import{runStartupUpdate as d}from"./auto-update.js";import{buildProgram as u}from"./program.js";import{firstCommandWord as l,isHelpRequest as p,renderHelpTopic as g}from"./cli-help.js";import{reportCliError as f,usageError as h,CliError as y}from"./errors.js";import{CLI_NAME as _}from"./brand.js";import{dryRunUnsupportedCommand as w}from"./dry-run.js";import{flushTelemetry as j,installClientHeaders as k,setTelemetryCommand as v,track as C}from"./telemetry.js";export{buildProgram}from"./program.js";const x=new Set(["setup","init","auth","enter","config"]);export class Command{program;configuring=!1;constructor(){const t=o.isLangChosen()?o.getLang():n();r.loadFromConfig(t),this.program=u()}preflightArgs(r){const n=n=>r.includes(n),t=!n("--no-color")&&a();if(m({nonInteractive:n("--non-interactive"),json:n("--json"),yes:n("--yes")||n("-y"),dryRun:n("--dry-run"),color:t}),t||(s.level=0),this.configuring=!1,p(r))return;let e;for(let n=0;n<r.length;n+=1){const o=r[n];"--base"===o&&r[n+1]?(e=r[n+1],n+=1):o.startsWith("--base=")&&(e=o.slice(7))}const c=l(r),d=void 0===c&&!["--version","-v"].some(n);this.configuring=d||void 0!==c&&x.has(c),e&&o.setBaseUrl(i(e)??e,this.configuring&&!n("--dry-run"))}async execute(r){const n=Date.now();let o=!1;try{if(this.preflightArgs(r),k(),p(r)||["--version","-v"].some(n=>r.includes(n))||(v(l(r)??"wizard"),C("command","start",{detail:{args:r.filter(r=>r.startsWith("-")&&!/key/i.test(r))}}),o=!0),"help"===r[0]&&r[1]){const n=g(r[1]);if(n)return void process.stdout.write(n)}if(this.rejectUnknownCommand(r),!p(r)){if(c()&&this.rejectUnsupportedDryRun(r),(await d(r)).handled)return;this.configuring&&await e({timeoutMs:5e3}),await t(r)}if(await this.program.parseAsync(r,{from:"user"}),o){const r=Boolean(process.exitCode)&&0!==process.exitCode;C("command",r?"fail":"ok",{duration_ms:Date.now()-n,...r?{detail:{exit_code:process.exitCode}}:{}})}}catch(t){if("commander.helpDisplayed"===t?.code||"commander.version"===t?.code)return;const e=this.normalizeCommanderError(t,r),i=f(e);if(o){const r=e instanceof y?`${e.type}${e.subtype?"/"+e.subtype:""}`:void 0;C("command",130===i?"cancel":"fail",{duration_ms:Date.now()-n,error:e,detail:{exit_code:i,...r?{type:r}:{}}})}}finally{o&&await j()}}rejectUnsupportedDryRun(n){const o=w(n);if(null!==o)throw h(r.t("runtime.dry_run_unsupported",{command:o,cli:_}),r.t("runtime.dry_run_unsupported_hint",{cli:_}),"dry_run_unsupported")}rejectUnknownCommand(n){const o=l(n);if(!o||"help"===o)return;if(this.program.commands.some(r=>r.name()===o))return;const t=this.suggestCommand(o),e=t?r.t("cli.unknown_hint_suggestion",{command:t}):r.t("cli.unknown_hint");throw h(r.t("cli.error_unknown",{command:o}),e,"unknown_command")}suggestCommand(r){const n=(r,n)=>{const o=Array.from({length:n.length+1},(r,n)=>n);for(let t=1;t<=r.length;t+=1){let e=o[0];o[0]=t;for(let i=1;i<=n.length;i+=1){const s=o[i];o[i]=Math.min(o[i]+1,o[i-1]+1,e+(r[t-1]===n[i-1]?0:1)),e=s}}return o[n.length]};return this.program.commands.map(r=>r.name()).map(o=>({name:o,score:n(r,o)})).filter(({score:n})=>n<=Math.max(2,Math.floor(r.length/2))).sort((r,n)=>r.score-n.score)[0]?.name}normalizeCommanderError(n,o){if(n instanceof y)return n;const t=n?.code,e=n instanceof Error?n.message:String(n);if("commander.unknownOption"===t||"commander.missingArgument"===t||"commander.missingMandatoryOption"===t||"commander.invalidArgument"===t){const n=l(o),i=/'([^']+)'/.exec(e)?.[1]??"",s="commander.unknownOption"===t?"cli.err_unknown_option":"commander.missingArgument"===t?"cli.err_missing_argument":"commander.missingMandatoryOption"===t?"cli.err_missing_option":null,m=s&&i?r.t(s,{name:i}):e.replace(/^error:\s*/,"");return h(m,n?r.t("cli.unknown_option_hint",{command:n}):r.t("cli.unknown_option_hint_root"),t)}return n}getProgram(){return this.program}}
1
+ import{i18n as n,detectSystemLang as o}from"./i18n.js";import{configManager as r}from"./config.js";import{runModelRefresh as t}from"./model-refresh.js";import{refreshClientConfig as e}from"./client-config-sync.js";import{normalizeBaseUrl as i}from"./gateway-addresses.js";import s from"chalk";import{setRuntimeOptions as m,detectColorPreferenceFromEnv as a,isDryRun as c}from"./runtime-options.js";import{runStartupUpdate as d}from"./auto-update.js";import{buildProgram as l}from"./program.js";import{firstCommandWord as u,isHelpRequest as p,renderHelpTopic as g}from"./cli-help.js";import{reportCliError as f,usageError as h,CliError as _}from"./errors.js";import{CLI_NAME as y}from"./brand.js";import{dryRunUnsupportedCommand as w}from"./dry-run.js";import{flushTelemetry as j,installClientHeaders as k,maskSecrets as v,setTelemetryCommand as C,track as x}from"./telemetry.js";export{buildProgram}from"./program.js";const A=new Set(["setup","init","auth","enter","config"]);export class Command{program;configuring=!1;constructor(){const t=r.isLangChosen()?r.getLang():o();n.loadFromConfig(t),this.program=l()}preflightArgs(n){const o=o=>n.includes(o),t=!o("--no-color")&&a();if(m({nonInteractive:o("--non-interactive"),json:o("--json"),yes:o("--yes")||o("-y"),dryRun:o("--dry-run"),color:t}),t||(s.level=0),this.configuring=!1,p(n))return;let e;for(let o=0;o<n.length;o+=1){const r=n[o];"--base"===r&&n[o+1]?(e=n[o+1],o+=1):r.startsWith("--base=")&&(e=r.slice(7))}const c=u(n),d=void 0===c&&!["--version","-v"].some(o);this.configuring=d||void 0!==c&&A.has(c),e&&r.setBaseUrl(i(e)??e,this.configuring&&!o("--dry-run"))}async execute(n){const o=Date.now();let r=!1;try{if(this.preflightArgs(n),k(),p(n)||["--version","-v"].some(o=>n.includes(o))||(C(u(n)??"wizard"),x("command","start",{detail:{args:n.filter(n=>n.startsWith("-")&&!/key/i.test(n))}}),r=!0),"help"===n[0]&&n[1]){const o=g(n[1]);if(o)return void process.stdout.write(o)}if(this.rejectUnknownCommand(n),!p(n)){if(c()&&this.rejectUnsupportedDryRun(n),(await d(n)).handled)return;this.configuring&&await e({timeoutMs:5e3}),await t(n)}if(await this.program.parseAsync(n,{from:"user"}),r){const n=Boolean(process.exitCode)&&0!==process.exitCode;x("command",n?"fail":"ok",{duration_ms:Date.now()-o,...n?{detail:{exit_code:process.exitCode}}:{}})}}catch(t){if("commander.helpDisplayed"===t?.code||"commander.version"===t?.code)return;const e=this.normalizeCommanderError(t,n),i=f(e);if(r){const n=e instanceof _?`${e.type}${e.subtype?"/"+e.subtype:""}`:void 0;x("command",130===i?"cancel":"fail",{duration_ms:Date.now()-o,error:e,detail:{exit_code:i,...n?{type:n}:{}}})}}finally{r&&await j()}}rejectUnsupportedDryRun(o){const r=w(o);if(null!==r)throw h(n.t("runtime.dry_run_unsupported",{command:r,cli:y}),n.t("runtime.dry_run_unsupported_hint",{cli:y}),"dry_run_unsupported")}rejectUnknownCommand(o){const r=u(o);if(!r||"help"===r)return;if(this.program.commands.some(n=>n.name()===r))return;const t=this.suggestCommand(r),e=t?n.t("cli.unknown_hint_suggestion",{command:t}):n.t("cli.unknown_hint");throw h(n.t("cli.error_unknown",{command:r}),e,"unknown_command")}suggestCommand(n){const o=(n,o)=>{const r=Array.from({length:o.length+1},(n,o)=>o);for(let t=1;t<=n.length;t+=1){let e=r[0];r[0]=t;for(let i=1;i<=o.length;i+=1){const s=r[i];r[i]=Math.min(r[i]+1,r[i-1]+1,e+(n[t-1]===o[i-1]?0:1)),e=s}}return r[o.length]};return this.program.commands.map(n=>n.name()).map(r=>({name:r,score:o(n,r)})).filter(({score:o})=>o<=Math.max(2,Math.floor(n.length/2))).sort((n,o)=>n.score-o.score)[0]?.name}normalizeCommanderError(o,r){if(o instanceof _)return o;const t=o?.code,e=o instanceof Error?o.message:String(o);if("commander.unknownOption"===t||"commander.missingArgument"===t||"commander.missingMandatoryOption"===t||"commander.invalidArgument"===t){const o=u(r),i=/'([^']+)'/.exec(e)?.[1]??"",s="commander.unknownOption"===t?"cli.err_unknown_option":"commander.missingArgument"===t?"cli.err_missing_argument":"commander.missingMandatoryOption"===t?"cli.err_missing_option":null,m="commander.unknownOption"===t?this.gluedOption(i):void 0,a=v(i),c=m?n.t("cli.err_glued_option",{name:a,option:m}):s&&i?n.t(s,{name:a}):v(e.replace(/^error:\s*/,""));return h(c,o?n.t("cli.unknown_option_hint",{command:o}):n.t("cli.unknown_option_hint_root"),t)}return o}gluedOption(n){const o=new Set,r=n=>{for(const r of n.options)r.long&&o.add(r.long);for(const o of n.commands)r(o)};return r(this.program),[...o].filter(o=>n.length>o.length&&n.startsWith(o)).sort((n,o)=>o.length-n.length)[0]}getProgram(){return this.program}}
@@ -1 +1 @@
1
- import{randomUUID as e}from"crypto";import{arch as t,homedir as r,release as o}from"os";import{brand as n,brandEnv as s,CLI_NAME as a}from"./brand.js";import{clientVersion as i,installId as c}from"./client-config.js";import{configManager as l}from"./config.js";import{gatewayAddresses as u}from"./gateway-addresses.js";import{INSTALL_ID_HEADER as f}from"./gateway-protocol.js";const d=e();let m="wizard",p=[];const g=new Set;let h=null,y=b;export function telemetryEnabled(){if(process.env.VITEST&&!w)return!1;const e=s("TELEMETRY")?.trim().toLowerCase();return!("0"===e||"false"===e||"off"===e)}let w=!1;export function setTelemetrySenderForTests(e){y=e??b,w=null!==e,p=[]}export function clientHeaders(){const e=`${a}/${i()} (${process.platform} ${o()}; ${t()}) node/${process.versions.node}`;return telemetryEnabled()?{"User-Agent":e,[f]:c()}:{"User-Agent":e}}export function installClientHeaders(){const e=globalThis.fetch;if(!e||e.gatewayHeaders)return;const t=(t,r)=>{try{const o=new URL("string"==typeof t||t instanceof URL?t.toString():t.url);if(new Set([l.getBaseUrl(),...u().map(e=>e.url)].map(e=>new URL(e).host)).has(o.host)){const o=new Headers(r?.headers??(t instanceof Request?t.headers:void 0));for(const[e,t]of Object.entries(clientHeaders()))o.has(e)||o.set(e,t);return e(t,{...r,headers:o})}}catch{}return e(t,r)};t.gatewayHeaders=!0,globalThis.fetch=t}export function telemetryPending(){return g.size>0}function T(){return{install_id:c(),cli_version:i(),brand:n().id,os:process.platform,os_release:o(),arch:t(),node_version:process.versions.node}}export function maskHome(e){const t=r();if(!t||t.length<2)return e;const o=new Set([t,t.replace(/\\/g,"/")]);let n=e;for(const e of o)n=n.split(e).join("~");return n}export function maskSecrets(e){return maskHome(e).replace(/\b(sk-[A-Za-z0-9_-]{2})[A-Za-z0-9_-]{8,}([A-Za-z0-9_-]{4})\b/g,"$1…$2").replace(/(Bearer\s+)[A-Za-z0-9._~+/=-]{8,}/gi,"$1…")}export function setTelemetryCommand(e){m=e}export function track(e,t,r={}){if(!telemetryEnabled())return;const o=void 0===r.error?void 0:maskSecrets(r.error instanceof Error?r.error.message:String(r.error)).slice(0,2e3);p.push({ts:Date.now(),session:d,command:m,step:e,status:t,...void 0!==r.duration_ms?{duration_ms:Math.round(r.duration_ms)}:{},...o?{error:o}:{},...r.detail?{detail:r.detail}:{}}),"start"===t?S():h||(h=setTimeout(S,500),h.unref())}export async function trackStep(e,t,r){const o=Date.now();track(e,"start",r?{detail:r}:{});try{const r=await t();return track(e,"ok",{duration_ms:Date.now()-o}),r}catch(t){throw track(e,"fail",{duration_ms:Date.now()-o,error:t}),t}}function S(){if(h&&(clearTimeout(h),h=null),0===p.length)return;const e=p.splice(0,50),t=y("/api/platform/vibecode/telemetry",{...T(),events:e},3e3).then(()=>{},()=>{}).finally(()=>g.delete(t));g.add(t),p.length>0&&S()}export async function flushTelemetry(e=1500){S(),0!==g.size&&await Promise.race([Promise.allSettled([...g]),new Promise(t=>setTimeout(t,e).unref())])}export async function uploadReport(e){try{const t=await y("/api/platform/vibecode/report",{...T(),report:e},2e4),r=t?.data?.code;return"string"==typeof r&&r?r:null}catch{return null}}async function b(e,t,r){const o=l.getApiKey()?.trim(),n=await fetch(new URL(e,l.getBaseUrl()).toString(),{method:"POST",headers:{"Content-Type":"application/json",...clientHeaders(),...o?{Authorization:`Bearer ${o}`}:{}},body:JSON.stringify(t),signal:AbortSignal.timeout(r)});if(!n.ok)throw new Error(`HTTP ${n.status}`);return n.json().catch(()=>null)}
1
+ import{randomUUID as e}from"crypto";import{arch as t,homedir as r,release as o}from"os";import{brand as n,brandEnv as s,CLI_NAME as a}from"./brand.js";import{clientVersion as i,installId as c}from"./client-config.js";import{configManager as l}from"./config.js";import{gatewayAddresses as u}from"./gateway-addresses.js";import{INSTALL_ID_HEADER as f}from"./gateway-protocol.js";const d=e();let m="wizard",p=[];const g=new Set;let h=null,y=b;export function telemetryEnabled(){if(process.env.VITEST&&!w)return!1;const e=s("TELEMETRY")?.trim().toLowerCase();return!("0"===e||"false"===e||"off"===e)}let w=!1;export function setTelemetrySenderForTests(e){y=e??b,w=null!==e,p=[]}export function clientHeaders(){const e=`${a}/${i()} (${process.platform} ${o()}; ${t()}) node/${process.versions.node}`;return telemetryEnabled()?{"User-Agent":e,[f]:c()}:{"User-Agent":e}}export function installClientHeaders(){const e=globalThis.fetch;if(!e||e.gatewayHeaders)return;const t=(t,r)=>{try{const o=new URL("string"==typeof t||t instanceof URL?t.toString():t.url);if(new Set([l.getBaseUrl(),...u().map(e=>e.url)].map(e=>new URL(e).host)).has(o.host)){const o=new Headers(r?.headers??(t instanceof Request?t.headers:void 0));for(const[e,t]of Object.entries(clientHeaders()))o.has(e)||o.set(e,t);return e(t,{...r,headers:o})}}catch{}return e(t,r)};t.gatewayHeaders=!0,globalThis.fetch=t}export function telemetryPending(){return g.size>0}function T(){return{install_id:c(),cli_version:i(),brand:n().id,os:process.platform,os_release:o(),arch:t(),node_version:process.versions.node}}export function maskHome(e){const t=r();if(!t||t.length<2)return e;const o=new Set([t,t.replace(/\\/g,"/")]);let n=e;for(const e of o)n=n.split(e).join("~");return n}export function maskSecrets(e){return maskHome(e).replace(/(sk-[A-Za-z0-9_-]{2})[A-Za-z0-9_-]{8,}([A-Za-z0-9_-]{4})\b/g,"$1…$2").replace(/(Bearer\s+)[A-Za-z0-9._~+/=-]{8,}/gi,"$1…")}export function setTelemetryCommand(e){m=e}export function track(e,t,r={}){if(!telemetryEnabled())return;const o=void 0===r.error?void 0:maskSecrets(r.error instanceof Error?r.error.message:String(r.error)).slice(0,2e3);p.push({ts:Date.now(),session:d,command:m,step:e,status:t,...void 0!==r.duration_ms?{duration_ms:Math.round(r.duration_ms)}:{},...o?{error:o}:{},...r.detail?{detail:r.detail}:{}}),"start"===t?S():h||(h=setTimeout(S,500),h.unref())}export async function trackStep(e,t,r){const o=Date.now();track(e,"start",r?{detail:r}:{});try{const r=await t();return track(e,"ok",{duration_ms:Date.now()-o}),r}catch(t){throw track(e,"fail",{duration_ms:Date.now()-o,error:t}),t}}function S(){if(h&&(clearTimeout(h),h=null),0===p.length)return;const e=p.splice(0,50),t=y("/api/platform/vibecode/telemetry",{...T(),events:e},3e3).then(()=>{},()=>{}).finally(()=>g.delete(t));g.add(t),p.length>0&&S()}export async function flushTelemetry(e=1500){S(),0!==g.size&&await Promise.race([Promise.allSettled([...g]),new Promise(t=>setTimeout(t,e).unref())])}export async function uploadReport(e){try{const t=await y("/api/platform/vibecode/report",{...T(),report:e},2e4),r=t?.data?.code;return"string"==typeof r&&r?r:null}catch{return null}}async function b(e,t,r){const o=l.getApiKey()?.trim(),n=await fetch(new URL(e,l.getBaseUrl()).toString(),{method:"POST",headers:{"Content-Type":"application/json",...clientHeaders(),...o?{Authorization:`Bearer ${o}`}:{}},body:JSON.stringify(t),signal:AbortSignal.timeout(r)});if(!n.ok)throw new Error(`HTTP ${n.status}`);return n.json().catch(()=>null)}
@@ -1,6 +1,10 @@
1
1
  import { type ToolInstallSpec } from './tools/tool-installs.js';
2
2
  /** How the last runCommand ended (for the support events and the fallback message). */
3
3
  export type RunOutcome = 'ok' | 'fail' | 'timeout' | 'stalled';
4
+ /** Last lines of the output, ANSI colors and progress-bar redraws removed. */
5
+ export declare function outputTail(text: string): string;
6
+ /** What the last watched command printed last, cleaned up (empty when it printed nothing). */
7
+ export declare function lastCommandOutput(): string;
4
8
  export interface RunLimits {
5
9
  /** Stop after this long in total. */
6
10
  timeoutMs?: number;
@@ -1 +1 @@
1
- import{spawn as t,spawnSync as e}from"child_process";import{rmSync as o}from"fs";import{join as r}from"path";import n from"chalk";import i from"inquirer";import{i18n as s}from"./i18n.js";import{logger as a}from"../utils/logger.js";import{compareVersions as l,getToolMinVersion as c}from"./model-registry.js";import{getAdapter as p}from"./tools/registry.js";import{findInstalls as m,findInstallsIncludingNative as u,forgetInstalls as d,installLabel as g,npmMirrorInstallCommand as f,npmMirrorVersion as w,npmUninstallCommand as h}from"./tools/tool-installs.js";import{toolHome as y}from"./tools/types.js";import{isJsonMode as v,isNonInteractive as _,shouldAutoConfirm as k}from"./runtime-options.js";import{track as b}from"./telemetry.js";import{isWindowsPowerShell as $,powerShellEnv as j}from"./powershell-env.js";let T="ok",M=async(t,o,r={})=>(console.log(n.gray("$ ")+[t,...o].join(" ")),T=r.idleMs?await runWatched(t,o,r):function(t,o,r){const n=D(t)?e(E(t,o),{stdio:S(),shell:!0,timeout:r}):e(t,o,{stdio:S(),timeout:r,env:x(t)});return n.error&&a.logError(`upgrade: ${t}`,n.error),"ETIMEDOUT"===n.error?.code?"timeout":0===n.status?"ok":"fail"}(t,o,r.timeoutMs),"ok"===T);const D=t=>"win32"===process.platform&&!/\.exe$/i.test(t),x=t=>$(t)?j():process.env,E=(t,e)=>[t,...e].map(t=>/\s/.test(t)?`"${t}"`:t).join(" "),S=()=>["inherit",v()?2:"inherit","inherit"];export function runWatched(e,o,r){return new Promise(n=>{const i=r.env?{...x(e),...r.env}:x(e),s=D(e)?t(E(e,o),{stdio:["inherit","pipe","pipe"],shell:!0,env:i}):t(e,o,{stdio:["inherit","pipe","pipe"],env:i});let l;const c=t=>{l=t,s.kill()};let p;const m=()=>{clearTimeout(p),r.idleMs&&(p=setTimeout(()=>c("stalled"),r.idleMs))},u=r.timeoutMs?setTimeout(()=>c("timeout"),r.timeoutMs):void 0;m(),s.stdout?.on("data",t=>{(v()?process.stderr:process.stdout).write(t),m()}),s.stderr?.on("data",t=>{process.stderr.write(t),m()});const d=t=>{clearTimeout(p),clearTimeout(u),n(t)};s.on("error",t=>{a.logError(`upgrade: ${e}`,t),d(l??"fail")}),s.on("close",t=>{l&&(v()?process.stderr:process.stdout).write("\n"),d(l??(0===t?"ok":"fail"))})})}export function setUpgradeRunnerForTests(t){M=async(e,o,r)=>{const n=await t(e,o,r);return T="string"==typeof n?n:n?"ok":"fail","ok"===T}}const P={ok:"install.script_failed_npm",fail:"install.script_failed_npm",stalled:"install.script_stalled_npm",timeout:"install.script_timeout_npm"};export async function mirrorInstall(t){if(!t.mirrorScript)return I(t);console.log(n.gray(s.t("install.downloading")));const e=`install-script:${t.command}`,o=Date.now();b(e,"start");const r={idleMs:18e4,timeoutMs:36e5},i="win32"===process.platform?await M("powershell.exe",["-NoProfile","-ExecutionPolicy","Bypass","-Command",`irm ${t.mirrorScript.ps1} -TimeoutSec 30 | iex`],r):await M("sh",["-c",`script=$(curl -fsSL --connect-timeout 15 --max-time 60 ${t.mirrorScript.sh}) && printf '%s\\n' "$script" | sh`],r),a=T;return b(e,"stalled"===a?"timeout":a,{duration_ms:Date.now()-o,..."stalled"===a||"timeout"===a?{detail:{reason:a}}:{}}),i||!t.npmPackage?i:(console.log(n.yellow(" ! "+s.t(P[a],{minutes:String(3)}))),b(e,"fallback"),I(t))}async function I(t){const e=f(t,await w(t)),[o,...r]=e.split(" "),i=`install-npm:${t.command}`,a=Date.now();b(i,"start");const l=await M(o,r);return b(i,l?"ok":"fail",{duration_ms:Date.now()-a}),l||"win32"===process.platform||console.log(n.yellow(" ! "+s.t("upgrade.npm_permission",{command:e}))),l}async function U(t,e){switch(e.kind){case"npm":t.npmPackage&&await M("npm",["uninstall","-g",t.npmPackage]);break;case"brew":t.brew&&await M("brew",["uninstall",t.brew]);break;case"native":try{o(e.path,{force:!0});for(const e of t.native?.dataDirs??[])o(r(y(),...e),{recursive:!0,force:!0})}catch(t){a.logError("upgrade: remove native copy",t)}break;default:return!1}return d(),!m(t).some(t=>t.path===e.path)}function N(t,e){switch(e.kind){case"npm":return h(t);case"brew":return`brew uninstall ${t.brew}`;case"native":return s.t("upgrade.delete_paths",{paths:[e.path,...(t.native?.dataDirs??[]).map(t=>r(y(),...t))].join("、")});default:return s.t("upgrade.delete_paths",{paths:e.path})}}export async function upgradeTool(t){const e=Date.now();b(`upgrade:${t}`,"start");try{const o=await async function(t){const e=p(t),o=e?.installSpec;if(!e||!o)throw new Error(s.t("upgrade.unsupported",{tool:t}));const r=e.displayName;d();const f=m(o);if(console.log(n.bold(`\n${r}`)),0===f.length)console.log(s.t("upgrade.not_installed_installing",{tool:r})),await mirrorInstall(o);else{const t=f[0];console.log(n.gray(" "+s.t("upgrade.current",{copy:g(t)})));const e=await async function(t,e){switch(e.kind){case"native":return M(e.path,t.native?.updateArgs??["update"],{timeoutMs:t.native?.updateTimeoutMs});case"npm":return I(t);case"brew":return!!t.brew&&M("brew",["upgrade",t.brew]);default:return!1}}(o,t);e||"other"!==t.kind?e||"npm"===t.kind||"native"===t.kind&&await async function(t){const e=t.native?.mirrorUpdate;if(!e)return!1;console.log(n.yellow(" ! "+s.t("upgrade.native_mirror_trying")));try{const{version:t,manifestVerified:o}=await e();return console.log(n.green(" √ "+s.t(o?"upgrade.native_mirror_done_verified":"upgrade.native_mirror_done",{version:t}))),!0}catch(t){return a.logError("upgrade: native mirror",t),console.log(n.yellow(" ! "+s.t("upgrade.native_mirror_failed",{reason:t instanceof Error?t.message:String(t)}))),!1}}(o)||(console.log(n.yellow(" ! "+s.t("upgrade.fallback_mirror"))),await mirrorInstall(o)):console.log(n.yellow(" ! "+s.t("upgrade.unknown_install",{path:t.path})))}d(),await async function(t,e){const o=m(t);if(o.length<2)return;const r=function(t){return t.reduce((t,e)=>e.version&&(!t.version||l(e.version,t.version)>0)?e:t)}(o),a=o.filter(t=>t!==r);console.log(n.yellow(" ! "+s.t("upgrade.duplicates",{tool:e,keep:g(r),others:a.map(g).join("、")})));let c=k();c||_()||!process.stdin.isTTY||(c=(await i.prompt([{type:"confirm",name:"remove",message:s.t("upgrade.confirm_remove"),default:!0}])).remove);for(const e of a)c&&await U(t,e)?console.log(n.green(" √ "+s.t("upgrade.removed",{copy:g(e)}))):console.log(n.yellow(" ! "+s.t("upgrade.remove_by_hand",{how:N(t,e)})))}(o,r),d();const w=u(o)[0];if(!w)return console.log(n.red(" × "+s.t("upgrade.still_missing",{tool:r}))),!1;w.onPath||console.log(n.gray(" "+s.t("components.new_terminal")));const h=c(t);if(h&&w.version&&l(w.version,h)<0){console.log(n.yellow(" ! "+s.t("upgrade.still_old",{copy:g(w),min:h})));for(const t of e.upgradeHints?.(h)??[])console.log(n.yellow(" ! "+t));return!1}return console.log(n.green(" √ "+s.t("upgrade.done",{copy:g(w)}))),!0}(t);return b(`upgrade:${t}`,o?"ok":"fail",{duration_ms:Date.now()-e}),o}catch(o){throw b(`upgrade:${t}`,"fail",{duration_ms:Date.now()-e,error:o}),o}}
1
+ import{spawn as t,spawnSync as e}from"child_process";import{rmSync as o}from"fs";import{join as r}from"path";import n from"chalk";import i from"inquirer";import{i18n as s}from"./i18n.js";import{logger as a}from"../utils/logger.js";import{compareVersions as l,getToolMinVersion as c}from"./model-registry.js";import{getAdapter as p}from"./tools/registry.js";import{findInstalls as u,findInstallsIncludingNative as m,forgetInstalls as d,installLabel as g,npmMirrorInstallCommand as f,npmMirrorVersion as w,npmUninstallCommand as h}from"./tools/tool-installs.js";import{toolHome as y}from"./tools/types.js";import{isJsonMode as v,isNonInteractive as _,shouldAutoConfirm as k}from"./runtime-options.js";import{track as b}from"./telemetry.js";import{isWindowsPowerShell as $,powerShellEnv as T}from"./powershell-env.js";let j="ok",x="";const M=t=>{x=(x+t.toString("utf-8")).slice(-3e3)};export function outputTail(t){return t.replace(/\x1b\[[0-9;?]*[A-Za-z]/g,"").split(/\r?\n/).map(t=>t.split("\r").pop().trimEnd()).filter(Boolean).join("\n").slice(-1500)}export function lastCommandOutput(){return outputTail(x)}let D=async(t,o,r={})=>(console.log(n.gray("$ ")+[t,...o].join(" ")),x="",j=r.idleMs?await runWatched(t,o,r):function(t,o,r){const n=E(t)?e(P(t,o),{stdio:C(),shell:!0,timeout:r}):e(t,o,{stdio:C(),timeout:r,env:S(t)});return n.error&&a.logError(`upgrade: ${t}`,n.error),"ETIMEDOUT"===n.error?.code?"timeout":0===n.status?"ok":"fail"}(t,o,r.timeoutMs),"ok"===j);const E=t=>"win32"===process.platform&&!/\.exe$/i.test(t),S=t=>$(t)?T():process.env,P=(t,e)=>[t,...e].map(t=>/\s/.test(t)?`"${t}"`:t).join(" "),C=()=>["inherit",v()?2:"inherit","inherit"];export function runWatched(e,o,r){return new Promise(n=>{const i=r.env?{...S(e),...r.env}:S(e),s=E(e)?t(P(e,o),{stdio:["inherit","pipe","pipe"],shell:!0,env:i}):t(e,o,{stdio:["inherit","pipe","pipe"],env:i});let l;const c=t=>{l=t,s.kill()};let p;const u=()=>{clearTimeout(p),r.idleMs&&(p=setTimeout(()=>c("stalled"),r.idleMs))},m=r.timeoutMs?setTimeout(()=>c("timeout"),r.timeoutMs):void 0;u(),s.stdout?.on("data",t=>{(v()?process.stderr:process.stdout).write(t),M(t),u()}),s.stderr?.on("data",t=>{process.stderr.write(t),M(t),u()});const d=t=>{clearTimeout(p),clearTimeout(m),n(t)};s.on("error",t=>{a.logError(`upgrade: ${e}`,t),d(l??"fail")}),s.on("close",t=>{l&&(v()?process.stderr:process.stdout).write("\n"),d(l??(0===t?"ok":"fail"))})})}export function setUpgradeRunnerForTests(t){D=async(e,o,r)=>{const n=await t(e,o,r);return j="string"==typeof n?n:n?"ok":"fail","ok"===j}}const I={ok:"install.script_failed_npm",fail:"install.script_failed_npm",stalled:"install.script_stalled_npm",timeout:"install.script_timeout_npm"};export async function mirrorInstall(t){if(!t.mirrorScript)return O(t);console.log(n.gray(s.t("install.downloading")));const e=`install-script:${t.command}`,o=Date.now();b(e,"start");const r={idleMs:18e4,timeoutMs:36e5},i="win32"===process.platform?await D("powershell.exe",["-NoProfile","-ExecutionPolicy","Bypass","-Command",`irm ${t.mirrorScript.ps1} -TimeoutSec 30 | iex`],r):await D("sh",["-c",`script=$(curl -fsSL --connect-timeout 15 --max-time 60 ${t.mirrorScript.sh}) && printf '%s\\n' "$script" | sh`],r),a=j;return b(e,"stalled"===a?"timeout":a,{duration_ms:Date.now()-o,..."stalled"===a||"timeout"===a?{detail:{reason:a}}:{},..."ok"!==a&&lastCommandOutput()?{error:lastCommandOutput()}:{}}),i||!t.npmPackage?i:(console.log(n.yellow(" ! "+s.t(I[a],{minutes:String(3)}))),b(e,"fallback"),O(t))}async function O(t){const e=f(t,await w(t)),[o,...r]=e.split(" "),i=`install-npm:${t.command}`,a=Date.now();b(i,"start");const l=await D(o,r);return b(i,l?"ok":"fail",{duration_ms:Date.now()-a}),l||"win32"===process.platform||console.log(n.yellow(" ! "+s.t("upgrade.npm_permission",{command:e}))),l}async function U(t,e){switch(e.kind){case"npm":t.npmPackage&&await D("npm",["uninstall","-g",t.npmPackage]);break;case"brew":t.brew&&await D("brew",["uninstall",t.brew]);break;case"native":try{o(e.path,{force:!0});for(const e of t.native?.dataDirs??[])o(r(y(),...e),{recursive:!0,force:!0})}catch(t){a.logError("upgrade: remove native copy",t)}break;default:return!1}return d(),!u(t).some(t=>t.path===e.path)}function A(t,e){switch(e.kind){case"npm":return h(t);case"brew":return`brew uninstall ${t.brew}`;case"native":return s.t("upgrade.delete_paths",{paths:[e.path,...(t.native?.dataDirs??[]).map(t=>r(y(),...t))].join("、")});default:return s.t("upgrade.delete_paths",{paths:e.path})}}export async function upgradeTool(t){const e=Date.now();b(`upgrade:${t}`,"start");try{const o=await async function(t){const e=p(t),o=e?.installSpec;if(!e||!o)throw new Error(s.t("upgrade.unsupported",{tool:t}));const r=e.displayName;d();const f=u(o);if(console.log(n.bold(`\n${r}`)),0===f.length)console.log(s.t("upgrade.not_installed_installing",{tool:r})),await mirrorInstall(o);else{const t=f[0];console.log(n.gray(" "+s.t("upgrade.current",{copy:g(t)})));const e=await async function(t,e){switch(e.kind){case"native":return D(e.path,t.native?.updateArgs??["update"],{timeoutMs:t.native?.updateTimeoutMs});case"npm":return O(t);case"brew":return!!t.brew&&D("brew",["upgrade",t.brew]);default:return!1}}(o,t);e||"other"!==t.kind?e||"npm"===t.kind||"native"===t.kind&&await async function(t){const e=t.native?.mirrorUpdate;if(!e)return!1;console.log(n.yellow(" ! "+s.t("upgrade.native_mirror_trying")));try{const{version:t,manifestVerified:o}=await e();return console.log(n.green(" √ "+s.t(o?"upgrade.native_mirror_done_verified":"upgrade.native_mirror_done",{version:t}))),!0}catch(t){return a.logError("upgrade: native mirror",t),console.log(n.yellow(" ! "+s.t("upgrade.native_mirror_failed",{reason:t instanceof Error?t.message:String(t)}))),!1}}(o)||(console.log(n.yellow(" ! "+s.t("upgrade.fallback_mirror"))),await mirrorInstall(o)):console.log(n.yellow(" ! "+s.t("upgrade.unknown_install",{path:t.path})))}d(),await async function(t,e){const o=u(t);if(o.length<2)return;const r=function(t){return t.reduce((t,e)=>e.version&&(!t.version||l(e.version,t.version)>0)?e:t)}(o),a=o.filter(t=>t!==r);console.log(n.yellow(" ! "+s.t("upgrade.duplicates",{tool:e,keep:g(r),others:a.map(g).join("、")})));let c=k();c||_()||!process.stdin.isTTY||(c=(await i.prompt([{type:"confirm",name:"remove",message:s.t("upgrade.confirm_remove"),default:!0}])).remove);for(const e of a)c&&await U(t,e)?console.log(n.green(" √ "+s.t("upgrade.removed",{copy:g(e)}))):console.log(n.yellow(" ! "+s.t("upgrade.remove_by_hand",{how:A(t,e)})))}(o,r),d();const w=m(o)[0];if(!w)return console.log(n.red(" × "+s.t("upgrade.still_missing",{tool:r}))),!1;w.onPath||console.log(n.gray(" "+s.t("components.new_terminal")));const h=c(t);if(h&&w.version&&l(w.version,h)<0){console.log(n.yellow(" ! "+s.t("upgrade.still_old",{copy:g(w),min:h})));for(const t of e.upgradeHints?.(h)??[])console.log(n.yellow(" ! "+t));return!1}return console.log(n.green(" √ "+s.t("upgrade.done",{copy:g(w)}))),!0}(t);return b(`upgrade:${t}`,o?"ok":"fail",{duration_ms:Date.now()-e}),o}catch(o){throw b(`upgrade:${t}`,"fail",{duration_ms:Date.now()-e,error:o}),o}}
@@ -4,6 +4,7 @@
4
4
  "unknown_hint": "Next: run {{cli}} --help to see the available commands.",
5
5
  "unknown_hint_suggestion": "Did you mean {{cli}} {{command}}?",
6
6
  "err_unknown_option": "Unknown option: {{name}}",
7
+ "err_glued_option": "Unknown option: {{name}}. Put a space between {{option}} and its value",
7
8
  "err_missing_argument": "Missing argument: {{name}}",
8
9
  "err_missing_option": "Missing required option: {{name}}",
9
10
  "unknown_option_hint": "Next: run {{cli}} {{command}} --help to see the correct usage.",
@@ -4,6 +4,7 @@
4
4
  "unknown_hint": "下一步:运行 {{cli}} --help 查看可用命令。",
5
5
  "unknown_hint_suggestion": "你是不是想运行 {{cli}} {{command}}?",
6
6
  "err_unknown_option": "未知选项:{{name}}",
7
+ "err_glued_option": "未知选项:{{name}}。{{option}} 和后面的值之间要有空格",
7
8
  "err_missing_argument": "缺少参数:{{name}}",
8
9
  "err_missing_option": "缺少必填选项:{{name}}",
9
10
  "unknown_option_hint": "下一步:运行 {{cli}} {{command}} --help 查看正确用法。",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibeapi/cli",
3
- "version": "0.0.151",
3
+ "version": "0.0.152",
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",