@vibeapi/api-helper 0.0.140 → 0.0.141

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{chmodSync as e,copyFileSync as t,existsSync as r,lstatSync as n,mkdirSync as o,readdirSync as s,readFileSync as a,readlinkSync as i,renameSync as l,rmSync as c,symlinkSync as u,writeFileSync as p}from"fs";import{homedir as d}from"os";import{basename as m,dirname as f,join as h,sep as _}from"path";import{spawnSync as g}from"child_process";import y from"chalk";import{checkForUpdate as x,readLocalPackage as v,UPDATE_SOURCES as k}from"../commands/update.js";import{i18n as w}from"./i18n.js";import{isColorEnabled as S}from"./runtime-options.js";import{logger as b}from"../utils/logger.js";import{isHelpRequest as $}from"./cli-help.js";import{brand as E,brandEnvName as P}from"./brand.js";export const INSTALL_RETRY_INTERVAL_MS=36e5;export const INSTALL_TIMEOUT_MS=45e3;function I(e,t){return S()?e(t):t}export function resolveUpdateCachePath(e=process.env){const t=e[P("CONFIG_DIR")]?.trim();if(t)return h(t,"update-state.json");const r=e[P("TEST_HOME")]?.trim();return h(r||d(),E().configDirName,"update-state.json")}export function isGlobalPackageInstall(e){return e.split(_).includes("node_modules")}export function isNpxExecution(e=process.env){return"exec"===e.npm_command||"npx"===e.npm_lifecycle_event}export function isPnpmGlobalInstall(e){return e.includes(`${_}.pnpm${_}`)||e.includes(`${_}pnpm${_}global${_}`)}export function resolveNpmGlobalPrefix(e){const t=`${_}node_modules${_}`,r=e.indexOf(t);if(r<0)return null;const n=e.slice(0,r);return n.endsWith(`${_}lib`)?f(n):n}export function shouldSkipStartupUpdate(e,t=process.env){return"1"===t[P("SKIP_AUTO_UPDATE")]||"1"===t[P("DISABLE_AUTO_UPDATE")]||(!(!["--json","--non-interactive","--dry-run","--help","-h","--version","-v"].some(t=>e.includes(t))&&!$(e))||e.includes("update")||e.includes("completion"))}function A(t,r,n,s,a){try{o(f(t),{recursive:!0,mode:448});const i=`${t}.tmp-${process.pid}`,c={package_name:r,checked_at:n,latest:s.latest,source:s.source,registry:s.registry,errors:s.errors,...void 0===a?{}:{install_attempted_at:a,install_attempted_version:s.latest||void 0}};p(i,JSON.stringify(c),{encoding:"utf-8",mode:384}),l(i,t),e(t,384)}catch(e){b.warn("Failed to persist update check cache:",e)}}export function windowsShellCommand(e,t){return[e,...t.map(e=>`"${e}"`)].join(" ")}const N=(e,t)=>{const r={stdio:"inherit",timeout:45e3,killSignal:"SIGTERM"};return"win32"===process.platform?g(windowsShellCommand(e,t),{...r,shell:!0}):g(e,t,r)},j=(e,t)=>g(process.execPath,[process.argv[1],...e],{stdio:"inherit",env:t}),T="-update-";function U(e,t){for(let r=0;;r++)try{return void l(e,t)}catch(e){const t=e.code;if(r>=9||"EPERM"!==t&&"EACCES"!==t&&"EBUSY"!==t)throw e;Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,200)}}export function swapStagedPackage(e,s,l,p,d){const _=p.split("/"),g=[h(e,"node_modules",..._),h(e,"lib","node_modules",..._)].find(e=>r(h(e,"package.json")));if(!g)return!1;const y=JSON.parse(a(h(g,"package.json"),"utf-8"));if(y.version!==d)return!1;const x=h(f(l),`.${m(l)}${T}old-${process.pid}`);U(l,x);try{U(g,l)}catch(e){throw U(x,l),e}c(x,{recursive:!0,force:!0,maxRetries:3});const v="string"==typeof y.bin?[_[_.length-1]]:Object.keys(y.bin||{});for(const[r,a]of[[h(e,"bin"),h(s,"bin")],[e,s]])for(const e of v.flatMap(e=>["",".cmd",".ps1"].map(t=>e+t))){const s=h(r,e),l=h(a,e),c=n(s,{throwIfNoEntry:!1});if(!n(l,{throwIfNoEntry:!1})&&c&&!c.isDirectory())try{o(a,{recursive:!0}),c.isSymbolicLink()?u(i(s),l):t(s,l)}catch(e){b.warn("Failed to restore command shim:",e)}}return!0}export async function runStartupUpdate(e,t={}){const n=t.env||process.env,o=t.localPackage||v(),i=t.globalInstall??isGlobalPackageInstall(o.root),l=t.npx??isNpxExecution(n);if(!i||l||shouldSkipStartupUpdate(e,n))return{status:"skipped",handled:!1,source:null};const u=t.now??Date.now(),p=t.cachePath||resolveUpdateCachePath(n),d=function(e,t){try{if(!r(e))return null;const n=JSON.parse(a(e,"utf-8"));return n.package_name===t.name&&Number.isFinite(n.checked_at)?n:null}catch{return null}}(p,o);let g=function(e,t,r){if(!e||e.latest||r-e.checked_at>=6e5)return null;const n=Array.isArray(e.errors)?e.errors:[];return{current:t.version,latest:null,up_to_date:null,source:e.source,registry:e.registry,errors:n,error:n.map(e=>`${e.source}: ${e.error}`).join("; ")||"unknown"}}(d,o,u),S=null;if(g||(g=await x({localPackage:o,fetchFn:t.fetchFn}),g.latest&&d?.install_attempted_version===g.latest&&Number.isFinite(d.install_attempted_at)&&(S=d.install_attempted_at),A(p,o.name,u,g,S??void 0)),!g.latest)return{status:"unavailable",handled:!1,source:null};if(g.up_to_date)return{status:"current",handled:!1,source:g.source};if(null!==S&&u-S<36e5)return{status:"update_failed",handled:!1,source:g.source};const b=t.output||console.log,$=t.errorOutput||console.error,E=t.installRunner||N,U=isPnpmGlobalInstall(o.root),O=U?"win32"===process.platform?"pnpm.cmd":"pnpm":"win32"===process.platform?"npm.cmd":"npm",R=U?null:resolveNpmGlobalPrefix(o.root),D=o.root,C=R&&D.endsWith(_+o.name.split("/").join(_))?h(f(D),`.${m(D)}${T}${process.pid}`):null;C&&function(e,t){try{for(const r of s(e))r.startsWith(`.${t}${T}`)&&c(h(e,r),{recursive:!0,force:!0})}catch{}}(f(D),m(D)),A(p,o.name,u,g,u),b(I(y.cyan,w.t("update.auto_installing",{version:g.latest})));const G=[...g.registry?[g.registry]:[],...k.map(e=>e.registry).filter(e=>e!==g.registry)],F=Date.now();let L=null,M="unknown";for(const e of G){if(Date.now()-F>=45e3)break;const t=E(O,U?["add","--global",`${o.name}@${g.latest}`,"--registry",e]:["install","--global",...C?["--prefix",C]:R?["--prefix",R]:[],`${o.name}@${g.latest}`,"--registry",e,"--no-audit","--no-fund","--fetch-timeout=15000","--fetch-retries=1","--fetch-retry-mintimeout=1000","--fetch-retry-maxtimeout=3000"]);if(0===t.status){if(!C){L=e;break}try{if(!swapStagedPackage(C,R,D,o.name,g.latest)){M="staged install incomplete";continue}L=e;break}catch(e){M=e instanceof Error?e.message:String(e);break}finally{c(C,{recursive:!0,force:!0,maxRetries:3})}}else M=t.error?.message||`exit ${t.status??"unknown"}`,C&&c(C,{recursive:!0,force:!0,maxRetries:3})}if(!L)return $(I(y.yellow,w.t("update.auto_failed",{error:M}))),{status:"update_failed",handled:!1,source:g.source};b(I(y.green,w.t("update.auto_installed",{version:g.latest})));const B=(t.reexecRunner||j)(e,{...n,[P("SKIP_AUTO_UPDATE")]:"1"});return B.error?($(I(y.yellow,w.t("update.reexec_failed",{error:B.error.message}))),{status:"update_failed",handled:!1,source:g.source}):(process.exitCode=B.status??1,{status:"reexecuted",handled:!0,source:g.source})}
1
+ import{chmodSync as e,copyFileSync as t,existsSync as r,lstatSync as o,mkdirSync as n,readdirSync as s,readFileSync as a,readlinkSync as i,renameSync as l,rmSync as c,symlinkSync as u,writeFileSync as p}from"fs";import{homedir as d}from"os";import{basename as m,dirname as f,join as h,sep as _}from"path";import{spawnSync as g}from"child_process";import y from"chalk";import{checkForUpdate as v,readLocalPackage as x,UPDATE_SOURCES as w}from"../commands/update.js";import{i18n as k}from"./i18n.js";import{isColorEnabled as S}from"./runtime-options.js";import{logger as b}from"../utils/logger.js";import{isHelpRequest as $}from"./cli-help.js";import{brand as E,brandEnvName as P}from"./brand.js";import{flushTelemetry as I,track as j}from"./telemetry.js";export const INSTALL_RETRY_INTERVAL_MS=36e5;export const INSTALL_TIMEOUT_MS=45e3;function A(e,t){return S()?e(t):t}export function resolveUpdateCachePath(e=process.env){const t=e[P("CONFIG_DIR")]?.trim();if(t)return h(t,"update-state.json");const r=e[P("TEST_HOME")]?.trim();return h(r||d(),E().configDirName,"update-state.json")}export function isGlobalPackageInstall(e){return e.split(_).includes("node_modules")}export function isNpxExecution(e=process.env){return"exec"===e.npm_command||"npx"===e.npm_lifecycle_event}export function isPnpmGlobalInstall(e){return e.includes(`${_}.pnpm${_}`)||e.includes(`${_}pnpm${_}global${_}`)}export function resolveNpmGlobalPrefix(e){const t=`${_}node_modules${_}`,r=e.indexOf(t);if(r<0)return null;const o=e.slice(0,r);return o.endsWith(`${_}lib`)?f(o):o}export function shouldSkipStartupUpdate(e,t=process.env){return"1"===t[P("SKIP_AUTO_UPDATE")]||"1"===t[P("DISABLE_AUTO_UPDATE")]||(!(!["--json","--non-interactive","--dry-run","--help","-h","--version","-v"].some(t=>e.includes(t))&&!$(e))||e.includes("update")||e.includes("completion"))}function N(t,r,o,s,a){try{n(f(t),{recursive:!0,mode:448});const i=`${t}.tmp-${process.pid}`,c={package_name:r,checked_at:o,latest:s.latest,source:s.source,registry:s.registry,errors:s.errors,...void 0===a?{}:{install_attempted_at:a,install_attempted_version:s.latest||void 0}};p(i,JSON.stringify(c),{encoding:"utf-8",mode:384}),l(i,t),e(t,384)}catch(e){b.warn("Failed to persist update check cache:",e)}}export function windowsShellCommand(e,t){return[e,...t.map(e=>`"${e}"`)].join(" ")}const T=(e,t)=>{const r={stdio:"inherit",timeout:45e3,killSignal:"SIGTERM"};return"win32"===process.platform?g(windowsShellCommand(e,t),{...r,shell:!0}):g(e,t,r)},U=(e,t)=>g(process.execPath,[process.argv[1],...e],{stdio:"inherit",env:t}),O="-update-";function D(e,t){for(let r=0;;r++)try{return void l(e,t)}catch(e){const t=e.code;if(r>=9||"EPERM"!==t&&"EACCES"!==t&&"EBUSY"!==t)throw e;Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,200)}}export function swapStagedPackage(e,s,l,p,d){const _=p.split("/"),g=[h(e,"node_modules",..._),h(e,"lib","node_modules",..._)].find(e=>r(h(e,"package.json")));if(!g)return!1;const y=JSON.parse(a(h(g,"package.json"),"utf-8"));if(y.version!==d)return!1;const v=h(f(l),`.${m(l)}${O}old-${process.pid}`);D(l,v);try{D(g,l)}catch(e){throw D(v,l),e}c(v,{recursive:!0,force:!0,maxRetries:3});const x="string"==typeof y.bin?[_[_.length-1]]:Object.keys(y.bin||{});for(const[r,a]of[[h(e,"bin"),h(s,"bin")],[e,s]])for(const e of x.flatMap(e=>["",".cmd",".ps1"].map(t=>e+t))){const s=h(r,e),l=h(a,e),c=o(s,{throwIfNoEntry:!1});if(!o(l,{throwIfNoEntry:!1})&&c&&!c.isDirectory())try{n(a,{recursive:!0}),c.isSymbolicLink()?u(i(s),l):t(s,l)}catch(e){b.warn("Failed to restore command shim:",e)}}return!0}export async function runStartupUpdate(e,t={}){const o=t.env||process.env,n=t.localPackage||x(),i=t.globalInstall??isGlobalPackageInstall(n.root),l=t.npx??isNpxExecution(o);if(!i||l||shouldSkipStartupUpdate(e,o))return{status:"skipped",handled:!1,source:null};const u=t.now??Date.now(),p=t.cachePath||resolveUpdateCachePath(o),d=function(e,t){try{if(!r(e))return null;const o=JSON.parse(a(e,"utf-8"));return o.package_name===t.name&&Number.isFinite(o.checked_at)?o:null}catch{return null}}(p,n);let g=function(e,t,r){if(!e||e.latest||r-e.checked_at>=6e5)return null;const o=Array.isArray(e.errors)?e.errors:[];return{current:t.version,latest:null,up_to_date:null,source:e.source,registry:e.registry,errors:o,error:o.map(e=>`${e.source}: ${e.error}`).join("; ")||"unknown"}}(d,n,u),S=null;if(g||(g=await v({localPackage:n,fetchFn:t.fetchFn}),g.latest&&d?.install_attempted_version===g.latest&&Number.isFinite(d.install_attempted_at)&&(S=d.install_attempted_at),N(p,n.name,u,g,S??void 0)),!g.latest)return{status:"unavailable",handled:!1,source:null};if(g.up_to_date)return{status:"current",handled:!1,source:g.source};if(null!==S&&u-S<36e5)return{status:"update_failed",handled:!1,source:g.source};const b=t.output||console.log,$=t.errorOutput||console.error,E=t.installRunner||T,D=isPnpmGlobalInstall(n.root),R=D?"win32"===process.platform?"pnpm.cmd":"pnpm":"win32"===process.platform?"npm.cmd":"npm",C=D?null:resolveNpmGlobalPrefix(n.root),G=n.root,F=C&&G.endsWith(_+n.name.split("/").join(_))?h(f(G),`.${m(G)}${O}${process.pid}`):null;F&&function(e,t){try{for(const r of s(e))r.startsWith(`.${t}${O}`)&&c(h(e,r),{recursive:!0,force:!0})}catch{}}(f(G),m(G)),N(p,n.name,u,g,u),b(A(y.cyan,k.t("update.auto_installing",{version:g.latest})));const L={from:n.version,to:g.latest,staged:Boolean(F)};j("self-update","start",{detail:L}),await I();const M=[...g.registry?[g.registry]:[],...w.map(e=>e.registry).filter(e=>e!==g.registry)],B=Date.now();let J=null,W="unknown",K=0;for(const e of M){if(Date.now()-B>=45e3)break;K++;const t=E(R,D?["add","--global",`${n.name}@${g.latest}`,"--registry",e]:["install","--global",...F?["--prefix",F]:C?["--prefix",C]:[],`${n.name}@${g.latest}`,"--registry",e,"--no-audit","--no-fund","--fetch-timeout=15000","--fetch-retries=1","--fetch-retry-mintimeout=1000","--fetch-retry-maxtimeout=3000"]);if(0===t.status){if(!F){J=e;break}try{if(!swapStagedPackage(F,C,G,n.name,g.latest)){W="staged install incomplete";continue}J=e;break}catch(e){W=e instanceof Error?e.message:String(e);break}finally{c(F,{recursive:!0,force:!0,maxRetries:3})}}else W=t.error?.message||`exit ${t.status??"unknown"}`,F&&c(F,{recursive:!0,force:!0,maxRetries:3})}const Y=Date.now()-B;if(j("self-update",J?"ok":Y>=45e3?"timeout":"fail",{duration_ms:Y,...J?{}:{error:W},detail:{...L,attempts:K,registry:J}}),await I(),!J)return $(A(y.yellow,k.t("update.auto_failed",{error:W}))),{status:"update_failed",handled:!1,source:g.source};b(A(y.green,k.t("update.auto_installed",{version:g.latest})));const H=(t.reexecRunner||U)(e,{...o,[P("SKIP_AUTO_UPDATE")]:"1"});return H.error?($(A(y.yellow,k.t("update.reexec_failed",{error:H.error.message}))),{status:"update_failed",handled:!1,source:g.source}):(process.exitCode=H.status??1,{status:"reexecuted",handled:!0,source:g.source})}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibeapi/api-helper",
3
- "version": "0.0.140",
3
+ "version": "0.0.141",
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",