quantex-cli 0.0.1 → 0.0.2-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env bun
2
- import{r as e,s as t,y as n}from"./agents-BALRvoqc.mjs";import{i as r}from"./self-Bj9L_tIu.mjs";import i from"node:process";import{program as a}from"commander";import o from"picocolors";import s from"prompts";async function c(n,r){let i=await e(n);if(!i)return console.log(o.red(`Unknown agent: ${n}`)),1;let{agent:a,inspection:c}=i;if(!c.inPath){if(!(await s({type:`confirm`,name:`install`,message:`${a.displayName} is not installed. Would you like to install it?`,initial:!0})).install)return console.log(o.yellow(`Installation cancelled.`)),1;if(console.log(o.cyan(`Installing ${a.displayName}...`)),!(await t(a)).success)return console.log(o.red(`Failed to install ${a.displayName}.`)),1}try{let e=Bun.spawn([a.binaryName,...r],{stdio:[`inherit`,`inherit`,`inherit`]});return await e.exited,e.exitCode??1}catch(e){return console.log(o.red(`Failed to launch ${a.displayName}: ${e instanceof Error?e.message:String(e)}`)),1}}a.name(`quantex`).description(`统一的 AI Agent CLI 管理工具`).version(r()),a.command(`install <agent>`).alias(`i`).description(`安装指定 agent`).action(async e=>{let{installCommand:t}=await import(`./install-LlwsPjcI.mjs`);await t(e)}),a.command(`update`).argument(`[agent]`,`Agent name or alias`).option(`--all`,`更新所有已安装的 agent`).alias(`u`).description(`更新指定 agent`).action(async(e,t)=>{let{updateCommand:n}=await import(`./update-DTqFneka.mjs`);await n(e,t.all??!1)}),a.command(`uninstall <agent>`).alias(`rm`).description(`卸载指定 agent`).action(async e=>{let{uninstallCommand:t}=await import(`./uninstall-BYGbg7Kt.mjs`);await t(e)}),a.command(`list`).alias(`ls`).description(`列出所有支持的 agent`).action(async()=>{let{listCommand:e}=await import(`./list-C3iiju9D.mjs`);await e()}),a.command(`info <agent>`).description(`查看 agent 详细信息`).action(async e=>{let{infoCommand:t}=await import(`./info-m8Pm4m7N.mjs`);await t(e)}),a.command(`config`).argument(`[action]`,`Action: get, set, reset`).argument(`[key]`,`Config key`).argument(`[value]`,`Config value`).description(`配置管理`).action(async(e,t,n)=>{let{configCommand:r}=await import(`./config-B1BACpEg.mjs`);await r(e,t,n)}),a.command(`upgrade`).description(`升级 Quantex CLI`).option(`--channel <channel>`,`Update channel: stable or beta`).option(`--check`,`Only check whether an update is available`).action(async e=>{let{upgradeCommand:t}=await import(`./upgrade-CTQyBekz.mjs`);i.exitCode=await t({channel:e.channel===`beta`?`beta`:void 0,check:e.check??!1})}),a.command(`doctor`).description(`检查环境`).action(async()=>{let{doctorCommand:e}=await import(`./doctor-C3MeTdcd.mjs`);await e()});const l=i.argv[2],u=new Set([...a.commands.map(e=>e.name()),...a.commands.flatMap(e=>e.aliases()),`help`,`--help`,`--version`,`-v`]);if(l&&!l.startsWith(`-`)&&!u.has(l)&&n(l)){let e=await c(l,i.argv.slice(3));i.exit(e)}a.parse();export{};
2
+ import{r as e,s as t,y as n}from"./agents-BALRvoqc.mjs";import{i as r}from"./self-DckB0j9b.mjs";import i from"node:process";import{program as a}from"commander";import o from"picocolors";import s from"prompts";async function c(n,r){let i=await e(n);if(!i)return console.log(o.red(`Unknown agent: ${n}`)),1;let{agent:a,inspection:c}=i;if(!c.inPath){if(!(await s({type:`confirm`,name:`install`,message:`${a.displayName} is not installed. Would you like to install it?`,initial:!0})).install)return console.log(o.yellow(`Installation cancelled.`)),1;if(console.log(o.cyan(`Installing ${a.displayName}...`)),!(await t(a)).success)return console.log(o.red(`Failed to install ${a.displayName}.`)),1}try{let e=Bun.spawn([a.binaryName,...r],{stdio:[`inherit`,`inherit`,`inherit`]});return await e.exited,e.exitCode??1}catch(e){return console.log(o.red(`Failed to launch ${a.displayName}: ${e instanceof Error?e.message:String(e)}`)),1}}a.name(`quantex`).description(`统一的 AI Agent CLI 管理工具`).version(r()),a.command(`install <agent>`).alias(`i`).description(`安装指定 agent`).action(async e=>{let{installCommand:t}=await import(`./install-LlwsPjcI.mjs`);await t(e)}),a.command(`update`).argument(`[agent]`,`Agent name or alias`).option(`--all`,`更新所有已安装的 agent`).alias(`u`).description(`更新指定 agent`).action(async(e,t)=>{let{updateCommand:n}=await import(`./update-DTqFneka.mjs`);await n(e,t.all??!1)}),a.command(`uninstall <agent>`).alias(`rm`).description(`卸载指定 agent`).action(async e=>{let{uninstallCommand:t}=await import(`./uninstall-BYGbg7Kt.mjs`);await t(e)}),a.command(`list`).alias(`ls`).description(`列出所有支持的 agent`).action(async()=>{let{listCommand:e}=await import(`./list-C3iiju9D.mjs`);await e()}),a.command(`info <agent>`).description(`查看 agent 详细信息`).action(async e=>{let{infoCommand:t}=await import(`./info-m8Pm4m7N.mjs`);await t(e)}),a.command(`config`).argument(`[action]`,`Action: get, set, reset`).argument(`[key]`,`Config key`).argument(`[value]`,`Config value`).description(`配置管理`).action(async(e,t,n)=>{let{configCommand:r}=await import(`./config-B1BACpEg.mjs`);await r(e,t,n)}),a.command(`upgrade`).description(`升级 Quantex CLI`).option(`--channel <channel>`,`Update channel: stable or beta`).option(`--check`,`Only check whether an update is available`).action(async e=>{let{upgradeCommand:t}=await import(`./upgrade-BYdu-qcm.mjs`);i.exitCode=await t({channel:e.channel===`beta`?`beta`:void 0,check:e.check??!1})}),a.command(`doctor`).description(`检查环境`).action(async()=>{let{doctorCommand:e}=await import(`./doctor-CJu4vYWp.mjs`);await e()});const l=i.argv[2],u=new Set([...a.commands.map(e=>e.name()),...a.commands.flatMap(e=>e.aliases()),`help`,`--help`,`--version`,`-v`]);if(l&&!l.startsWith(`-`)&&!u.has(l)&&n(l)){let e=await c(l,i.argv.slice(3));i.exit(e)}a.parse();export{};
@@ -1,3 +1,3 @@
1
- import{_ as e,g as t,h as n,m as r,t as i}from"./agents-BALRvoqc.mjs";import{a,c as o}from"./self-Bj9L_tIu.mjs";import s from"picocolors";async function c(){console.log(s.bold(`
1
+ import{_ as e,g as t,h as n,m as r,t as i}from"./agents-BALRvoqc.mjs";import{a,c as o}from"./self-DckB0j9b.mjs";import s from"picocolors";async function c(){console.log(s.bold(`
2
2
  Quantex CLI Environment Check
3
3
  `)),console.log(s.bold(`Managed Installers:`));let c=await n();console.log(` Bun: ${c?s.green(`available`):s.red(`not found`)}`);let l=await t();console.log(` npm: ${l?s.green(`available`):s.red(`not found`)}`);let u=await r();console.log(` brew: ${u?s.green(`available`):s.red(`not found`)}`);let d=await e();console.log(` winget:${d?s.green(`available`):s.red(`not found`)}`);let f=await a(),p=f.latestVersion&&f.latestVersion!==f.currentVersion;if(console.log(`\n${s.bold(`Quantex CLI:`)}`),console.log(` Version: ${f.currentVersion}`),console.log(` Source: ${f.installSource}`),console.log(` Auto-update: ${f.canAutoUpdate?s.green(`supported`):s.yellow(`unsupported`)}`),f.latestVersion&&console.log(` Latest: ${f.latestVersion}${p?s.yellow(` (update available)`):``}`),p){let e=o(f);e&&console.log(` Recovery: ${e}`)}console.log(`\n${s.bold(`Installed Agents:`)}`);let m=await i(),h=!1;for(let e of m)if(e.inPath){h=!0;let t=e.installedVersion&&e.latestVersion&&e.installedVersion!==e.latestVersion;console.log(` ${e.agent.displayName}: ${e.installedVersion??`unknown`} [${e.lifecycle}; ${e.sourceLabel}]${t?s.yellow(` (update available: ${e.latestVersion})`):``}`)}h||console.log(s.dim(` No agents installed`)),console.log(`\n${s.bold(`Issues:`)}`);let g=[];if(!c&&!l&&!u&&!d&&g.push(`No managed installer found. Install bun, npm, brew, or winget.`),g.length===0)console.log(s.green(` No issues found.`));else for(let e of g)console.log(s.yellow(` - ${e}`));console.log()}export{c as doctorCommand};
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{a as e,i as t,n,o as r,s as i,t as a}from"./update-C6oNB0Kw.mjs";import{A as ee,B as te,C as ne,D as re,E as o,H as s,L as c,M as l,O as u,R as d,S as f,T as p,V as m,a as h,b as g,c as _,d as v,f as y,g as b,h as x,i as S,j as C,k as w,l as T,n as E,o as D,p as O,r as k,s as A,t as j,u as M,v as N,w as P,x as F,y as I,z as L}from"./agents-BALRvoqc.mjs";import{a as R,i as z,n as B,t as V}from"./config-DWeRAIFV.mjs";import{_ as ie,b as H,g as U,h as W,m as G,n as K,p as q,r as J,t as Y,v as ae,y as oe}from"./version-CrMPGstC.mjs";import{a as se,c as ce,i as le,l as ue,n as de,o as fe,r as pe,s as me,t as he,u as ge}from"./self-Bj9L_tIu.mjs";function X(e){return`${e.sort((e,t)=>e.name.localeCompare(t.name)).map(e=>`${e.checksum} ${e.name}`).join(`
1
+ import{a as e,i as t,n,o as r,s as i,t as a}from"./update-C6oNB0Kw.mjs";import{A as ee,B as te,C as ne,D as re,E as o,H as s,L as c,M as l,O as u,R as d,S as f,T as p,V as m,a as h,b as g,c as _,d as v,f as y,g as b,h as x,i as S,j as C,k as w,l as T,n as E,o as D,p as O,r as k,s as A,t as j,u as M,v as N,w as P,x as F,y as I,z as L}from"./agents-BALRvoqc.mjs";import{a as R,i as z,n as B,t as V}from"./config-DWeRAIFV.mjs";import{_ as ie,b as H,g as U,h as W,m as G,n as K,p as q,r as J,t as Y,v as ae,y as oe}from"./version-CrMPGstC.mjs";import{a as se,c as ce,i as le,l as ue,n as de,o as fe,r as pe,s as me,t as he,u as ge}from"./self-DckB0j9b.mjs";function X(e){return`${e.sort((e,t)=>e.name.localeCompare(t.name)).map(e=>`${e.checksum} ${e.name}`).join(`
2
2
  `)}\n`}function _e(e){let t=new Map;for(let n of e.split(/\r?\n/)){let e=n.trim();if(!e)continue;let[r,i]=e.split(/\s+/,2),a=i?.replace(/^\*/,``);r&&a&&t.set(a,r)}return t}function Z(e){let t=e.match(/^quantex-(darwin|linux|windows)-(arm64|x64)(?:\.exe)?$/);if(t)return{arch:t[2]===`arm64`?`arm64`:`x64`,platform:t[1]===`windows`?`win32`:t[1]===`darwin`?`darwin`:`linux`}}function Q(e){return e?e.startsWith(`git+`)?e.slice(4).replace(/\.git$/,``):e.startsWith(`git@github.com:`)?e.replace(`git@github.com:`,`https://github.com/`).replace(/\.git$/,``):e.replace(/\.git$/,``):`https://github.com/Drswith/quantex-cli`}function $(e){return e.includes(`beta`)?`beta`:`stable`}function ve(e){let t=Q(e.repositoryUrl),n=$(e.version),r=e.files.map(n=>{let r=Z(n.name);if(!r)return;let i=e.checksums.get(n.name);if(!i)throw Error(`Missing checksum entry for ${n.name}.`);return{arch:r.arch,checksum:i,downloadUrl:`${t}/releases/download/v${e.version}/${n.name}`,name:n.name,platform:r.platform,size:n.size}}).filter(e=>e!==void 0).sort((e,t)=>e.name.localeCompare(t.name));if(r.length===0)throw Error(`No release binaries were found when creating manifest.json.`);return{assets:r,channel:n,version:e.version}}function ye(e,t){if(e.assets.length===0)throw Error(`manifest.json must contain at least one binary asset.`);for(let n of e.assets){let e=t.get(n.name);if(!e)throw Error(`manifest.json references ${n.name}, but it is missing from SHA256SUMS.txt.`);if(n.checksum!==e)throw Error(`manifest.json checksum mismatch for ${n.name}.`);if(!Z(n.name))throw Error(`manifest.json contains an invalid binary asset name: ${n.name}.`)}}async function be(e,t){try{let n=Bun.spawn([e,...t],{stdio:[`inherit`,`inherit`,`inherit`]});return await n.exited,{success:n.exitCode===0,exitCode:n.exitCode??1}}catch{return{success:!1,exitCode:1}}}export{w as agentUpdateProviders,he as canAutoUpdateSelf,c as canLookupLatestVersionForInstallType,ee as canResolveAgentUpdate,d as canUninstallInstallType,L as canUpdateInstallType,u as claude,re as codex,o as copilot,ve as createReleaseManifest,t as createUpdatePlan,p as cursor,de as detectSelfInstallSource,P as droid,be as execCommand,X as formatChecksums,ne as gemini,N as getAgentByLookupName,I as getAgentByNameOrAlias,r as getAgentUpdateFailureHint,C as getAgentUpdateStrategy,g as getAllAgents,Y as getBinaryPath,ue as getBinaryReleaseAssetName,ge as getBinaryReleaseDownloadUrl,V as getConfigDir,B as getConfigFilePath,te as getInstallLifecycle,q as getInstalledAgentState,K as getInstalledVersion,m as getInstallerCapabilities,J as getLatestVersion,v as getManagedInstaller,i as getManualAgentUpdateMessage,pe as getManualSelfUpgradeCommand,D as getOrderedInstallMethods,y as getPlatform,G as getSelfState,me as getSelfUpgradeRecoveryHint,ce as getSelfUpgradeRecoveryHintForInspection,le as getSelfVersion,a as getSingleAgentUpdateStatus,W as getStateFilePath,S as inspectAgent,h as inspectAllAgents,j as inspectRegisteredAgents,se as inspectSelf,A as installAgent,O as isBinaryInPath,x as isBunAvailable,e as isInspectionUpdateAvailable,s as isManagedInstallType,b as isNpmAvailable,z as loadConfig,U as loadState,Q as normalizeRepositoryUrl,f as opencode,Z as parseBinaryTarget,_e as parseChecksums,F as pi,n as planAgentUpdates,ie as removeInstalledAgentState,E as resolveAgent,k as resolveAgentInspection,l as resolveAgentUpdateProvider,$ as resolveReleaseChannel,R as saveConfig,ae as saveState,oe as setInstalledAgentState,H as setSelfInstallSource,_ as uninstallAgent,T as updateAgent,M as updateAgentsByType,fe as upgradeSelf,ye as validateReleaseManifest};
@@ -0,0 +1 @@
1
+ import{i as e,t}from"./config-DWeRAIFV.mjs";import{b as n,d as r,i,m as a,r as o,s}from"./version-CrMPGstC.mjs";import{chmod as c,mkdir as l,mkdtemp as u,readFile as d,rename as f,rm as p,stat as m,writeFile as h}from"node:fs/promises";import{basename as g,dirname as _,join as v}from"node:path";import y from"node:process";import{fileURLToPath as b}from"node:url";import{Buffer as x}from"node:buffer";import{createHash as S}from"node:crypto";const C=`quantex-cli`,w=`https://github.com/Drswith/quantex-cli`,T=`0.0.2-beta.1`;function E(){return v(t(),`locks`,`self-upgrade.lock`)}async function D(){let e=E();await l(_(e),{recursive:!0});try{await l(e,{recursive:!1})}catch(e){if(typeof e==`object`&&e&&`code`in e&&e.code===`EEXIST`)return;throw e}return async()=>{await p(e,{force:!0,recursive:!0})}}async function ee(e,t,n,r){let i;try{i=await fetch(e)}catch(t){return A(`network`,`Failed to download ${e}.`,t)}if(!i.ok)return A(`network`,`Failed to download ${e}: HTTP ${i.status}.`);let a=await u(v(_(t),`.quantex-upgrade-`)),o=v(a,g(t)),s=`${t}.bak`;try{let l=x.from(await i.arrayBuffer()),u=await te(t),d=ie(l);if(d!==N(n))return A(`checksum`,`Checksum mismatch for ${e}. Expected ${N(n)}, got ${d}.`);if(await h(o,l),y.platform===`win32`)return ne(o,t,s,a,r);await c(o,u),await p(s,{force:!0}),await f(t,s),await f(o,t);let m=await re(t,r);return m.success?(await p(s,{force:!0}),{success:!0}):(await M(s,t),m)}catch(e){return A(j(e),`Failed to replace the current Quantex binary.`,e)}finally{y.platform!==`win32`&&await p(a,{recursive:!0,force:!0})}}async function te(e){try{return(await m(e)).mode&511}catch{return 493}}function ne(e,t,n,r,i){try{let a=O(e,t,n,r,y.pid,i);return Bun.spawn([`powershell.exe`,`-NoProfile`,`-NonInteractive`,`-ExecutionPolicy`,`Bypass`,`-WindowStyle`,`Hidden`,`-Command`,a],{stdio:[`ignore`,`ignore`,`ignore`],windowsHide:!0}).unref?.(),{success:!0}}catch(e){return A(`locked`,`Failed to schedule Windows binary replacement.`,e)}}function O(e,t,n,r,i,a){let o=k(e),s=k(t),c=k(n),l=k(r),u=k(a??``);return[`$pidToWait = ${i}`,`$tempPath = '${o}'`,`$targetPath = '${s}'`,`$backupPath = '${c}'`,`$tempDir = '${l}'`,`$expectedVersion = '${u}'`,`while (Get-Process -Id $pidToWait -ErrorAction SilentlyContinue) { Start-Sleep -Milliseconds 200 }`,`for ($attempt = 0; $attempt -lt 50; $attempt++) {`,` try {`,` if (Test-Path -LiteralPath $backupPath) { Remove-Item -LiteralPath $backupPath -Force -ErrorAction SilentlyContinue }`,` Move-Item -LiteralPath $targetPath -Destination $backupPath -Force -ErrorAction Stop`,` break`,` }`,` catch {`,` Start-Sleep -Milliseconds 200`,` }`,`}`,`Move-Item -LiteralPath $tempPath -Destination $targetPath -Force`,`if ($expectedVersion -ne '') {`,` $output = & $targetPath --version 2>$null`,` if ($LASTEXITCODE -ne 0 -or ($output -notmatch [regex]::Escape($expectedVersion))) {`,` Remove-Item -LiteralPath $targetPath -Force -ErrorAction SilentlyContinue`,` Move-Item -LiteralPath $backupPath -Destination $targetPath -Force`,` Remove-Item -LiteralPath $tempDir -Force -Recurse -ErrorAction SilentlyContinue`,` exit 1`,` }`,`}`,`Remove-Item -LiteralPath $backupPath -Force -ErrorAction SilentlyContinue`,`Remove-Item -LiteralPath $tempDir -Force -Recurse -ErrorAction SilentlyContinue`].join(`; `)}function k(e){return e.replaceAll(`'`,`''`)}function A(e,t,n){return{error:{detail:n,kind:e,message:t},success:!1}}function j(e){let t=typeof e==`object`&&e&&`code`in e?String(e.code):``;return t===`EACCES`||t===`EPERM`?`permission`:t===`EBUSY`?`locked`:`unknown`}async function M(e,t){await p(t,{force:!0}),await f(e,t)}async function re(e,t){if(!t)return{success:!0};try{let n=Bun.spawn([e,`--version`],{stdio:[`ignore`,`pipe`,`ignore`]}),r=n.stdout?await new Response(n.stdout).text():``,i=await n.exited;return i===0?r.includes(t)?{success:!0}:A(`verify`,`The upgraded Quantex binary reported an unexpected version during verification.`):A(`verify`,`The upgraded Quantex binary exited with code ${i} during verification.`)}catch(e){return A(`verify`,`Failed to execute the upgraded Quantex binary for verification.`,e)}}function ie(e){return S(`sha256`).update(e).digest(`hex`)}function N(e){return e.trim().toLowerCase()}function P(e){return e.replaceAll(`\\`,`/`).toLowerCase()}function F(e=y.execPath){if(g(P(e)).endsWith(`.exe`))return`quantex-windows-x64.exe`;if(y.platform===`darwin`)return y.arch===`arm64`?`quantex-darwin-arm64`:`quantex-darwin-x64`;if(y.platform===`linux`)return y.arch===`arm64`?`quantex-linux-arm64`:`quantex-linux-x64`}function I(e=y.execPath){let t=F(e);if(t)return`${w}/releases/latest/download/${t}`}function L(e,t,n=y.env){return e||(n.QUANTEX_UPDATE_CHANNEL===`beta`?`beta`:n.QUANTEX_UPDATE_CHANNEL===`stable`?`stable`:t===`beta`?`beta`:`stable`)}async function R(e){let t=await i(await z(e),`self:manifest:${e}`);if(!t)throw Error(`Failed to download release manifest.`);return t}async function z(e){if(e===`stable`)return`${w}/releases/latest/download/manifest.json`;let t=(await B(e)).assets.find(e=>e.name===`manifest.json`);if(!t?.browser_download_url)throw Error(`No manifest.json asset was found for the ${e} release channel.`);return t.browser_download_url}async function B(e){let t=H();if(!t)throw Error(`Failed to resolve the GitHub repository slug for Quantex releases.`);let n=await i(`https://api.github.com/repos/${t}/releases?per_page=20`,`self:github-releases`);if(!n)throw Error(`Failed to query GitHub releases.`);let r=n.find(t=>e===`beta`?t.prerelease:!t.prerelease);if(!r)throw Error(`No GitHub release was found for the ${e} channel.`);return r}function V(e,t=y.execPath){let n=y.platform,r=y.arch===`arm64`?`arm64`:`x64`,i=F(t);return e.assets.find(e=>e.platform===n&&e.arch===r&&(!i||e.name===i))}function H(){return w.match(/github\.com\/([^/]+\/[^/]+)$/)?.[1]}const U={source:`binary`,canHandle:e=>e.installSource===`binary`,getRecoveryHint:(e,t)=>{let n=t?.error?.detail&&typeof t.error.detail==`object`&&`downloadUrl`in t.error.detail?String(t.error.detail.downloadUrl):I(e.executablePath);if(n)return t?.error?.kind===`locked`?`close other qtx processes and retry, or download and replace the binary from ${n}`:t?.error?.kind===`permission`?`check write permission for the current binary path, or download and replace the binary from ${n}`:t?.error?.kind===`network`?`check network access and retry, or download and replace the binary from ${n}`:`download and replace the binary from ${n}`},async upgrade(e){if(!F(e.executablePath))return{error:{kind:`unsupported`,message:`No release artifact is available for the current platform and architecture.`},installSource:e.installSource,success:!1};let t;try{t=await R(e.updateChannel)}catch(t){return{error:{detail:t,kind:`network`,message:`Failed to resolve the ${e.updateChannel} release manifest.`},installSource:e.installSource,success:!1}}let n=V(t,e.executablePath);if(!n)return{error:{detail:{channel:e.updateChannel},kind:`unsupported`,message:`No binary asset is available for the current platform on the ${e.updateChannel} channel.`},installSource:e.installSource,success:!1};let r=await ee(n.downloadUrl,e.executablePath,n.checksum,t.version);return{...!r.success&&r.error?{...r,error:{...r.error,detail:{...typeof r.error.detail==`object`&&r.error.detail?r.error.detail:{},downloadUrl:n.downloadUrl}}}:r,installSource:e.installSource,newVersion:r.success?t.version:void 0}}},W={source:`bun`,canHandle:e=>e.installSource===`bun`,getRecoveryHint:e=>`bun add -g ${C}@${e.updateChannel===`beta`?`beta`:`latest`}`,async upgrade(e){let t=await r(C,`latest-major`,e.updateChannel===`beta`?`beta`:`latest`);return{error:t?void 0:{kind:`unknown`,message:`Failed to update ${C} through Bun.`},installSource:e.installSource,newVersion:t?e.latestVersion:void 0,success:t}}},G={source:`npm`,canHandle:e=>e.installSource===`npm`,getRecoveryHint:e=>`npm install -g ${C}@${e.updateChannel===`beta`?`beta`:`latest`}`,async upgrade(e){let t=await s(C,`latest-major`,e.updateChannel===`beta`?`beta`:`latest`);return{error:t?void 0:{kind:`unknown`,message:`Failed to update ${C} through npm.`},installSource:e.installSource,newVersion:t?e.latestVersion:void 0,success:t}}},K={source:`source`,canHandle:e=>e.installSource===`source`||e.installSource===`unknown`,getRecoveryHint:()=>void 0,async upgrade(e){return{error:{kind:`unsupported`,message:`Install source "${e.installSource}" does not support auto-update.`},installSource:e.installSource,success:!1}}},q=[W,G,U,K];function ae(e){return q.find(t=>t.canHandle(e))??K}function J(e,t,n=`stable`,r){if(r?.error?.kind===`locked`)return`another qtx upgrade is already running; wait for it to finish and retry`;if(e===`bun`)return`bun add -g ${C}@${n===`beta`?`beta`:`latest`}`;if(e===`npm`)return`npm install -g ${C}@${n===`beta`?`beta`:`latest`}`;if(e===`binary`){let e=I(t);return e?r?.error?.kind===`permission`?`check write permission for the current binary path, or download and replace the binary from ${e}`:r?.error?.kind===`network`?`check network access and retry, or download and replace the binary from ${e}`:`download and replace the binary from ${e}`:void 0}}function oe(e,t){return J(e.installSource,e.executablePath,e.updateChannel,t)}const Y=C,se=`/node_modules/${Y}`;async function X(t){let n=await ue(),r=y.execPath,i=n.foundPackageJson?Q(n.packageRoot):Q(``,r),o=await le((await a()).installSource,i),s=await e(),c=L(t?.updateChannel,s.selfUpdateChannel),l=await pe(o,r,c);return{canAutoUpdate:Z(o),currentVersion:n.version||`0.0.2-beta.1`,executablePath:r,installSource:o,latestVersion:l,packageRoot:n.packageRoot,recommendedUpgradeCommand:Z(o)?`quantex upgrade`:void 0,updateChannel:c}}async function ce(e){let t=e??await X(),n=await D();if(!n)return{error:{kind:`locked`,message:`Another qtx upgrade is already running.`},installSource:t.installSource,success:!1};try{return await ae(t).upgrade(t)}finally{await n()}}function Z(e){return e===`binary`||e===`bun`||e===`npm`}async function le(e,t){return t!==`unknown`&&e!==t?(await n(t),t):e??t}function Q(e,t=y.execPath){let n=$(e);return n.includes(`/.bun/install/global/`)?`bun`:n.includes(se)?`npm`:n?`source`:he(t)?`binary`:`unknown`}async function ue(e=import.meta.url){let t=ge(e),n=_(t);for(;;){let e=v(n,`package.json`),t=await me(e);if(t?.name===Y)return{foundPackageJson:!0,packageJsonPath:e,packageRoot:n,version:t.version??`0.0.2-beta.1`};let r=_(n);if(r===n)break;n=r}return{foundPackageJson:!1,packageJsonPath:v(_(t),`package.json`),packageRoot:_(t),version:T}}function de(){return T}function fe(e,t=y.execPath){return J(e,t)}async function pe(e,t,n){if(e===`binary`)try{let e=await R(n);return V(e,t)?e.version:void 0}catch{return}return o(Y,n===`beta`?`beta`:`latest`)}async function me(e){try{return JSON.parse(await d(e,`utf8`))}catch{return}}function $(e){return e.replaceAll(`\\`,`/`).toLowerCase()}function he(e){let t=g($(e));return t!==`bun`&&t!==`bun.exe`}function ge(e){try{return b(e)}catch{return y.execPath}}export{X as a,oe as c,de as i,F as l,Q as n,ce as o,fe as r,J as s,Z as t,I as u};
@@ -1 +1 @@
1
- import{a as e,c as t,o as n}from"./self-Bj9L_tIu.mjs";import r from"picocolors";async function i(i={}){let a=await e({updateChannel:i.channel});if(a.latestVersion&&a.latestVersion===a.currentVersion)return console.log(r.green(`Quantex CLI is already up to date (${a.currentVersion}).`)),0;if(i.check)return a.latestVersion?(console.log(r.yellow(`Update available for Quantex CLI: ${a.currentVersion} -> ${a.latestVersion} (${a.updateChannel}).`)),1):(console.log(r.yellow(`Unable to determine the latest Quantex CLI version.`)),2);if(!a.canAutoUpdate){console.log(r.yellow(`Quantex CLI cannot auto-update from the current install source: ${a.installSource}.`));let e=t(a);return e&&console.log(r.cyan(`Manual upgrade: ${e}`)),2}let o=a.latestVersion?` (${a.currentVersion} -> ${a.latestVersion})`:` (${a.currentVersion})`;console.log(r.cyan(`Upgrading Quantex CLI...${o}`));let s=await n(a);if(s.success)return console.log(r.green(`Quantex CLI upgraded successfully.`)),0;{console.log(r.red(`Failed to upgrade Quantex CLI.`)),s.error?.message&&console.log(r.yellow(`Reason: ${s.error.message}`));let e=t(a,s);return e&&console.log(r.cyan(`Manual recovery: ${e}`)),2}}export{i as upgradeCommand};
1
+ import{a as e,c as t,o as n}from"./self-DckB0j9b.mjs";import r from"picocolors";async function i(i={}){let a=await e({updateChannel:i.channel});if(a.latestVersion&&a.latestVersion===a.currentVersion)return console.log(r.green(`Quantex CLI is already up to date (${a.currentVersion}).`)),0;if(i.check)return a.latestVersion?(console.log(r.yellow(`Update available for Quantex CLI: ${a.currentVersion} -> ${a.latestVersion} (${a.updateChannel}).`)),1):(console.log(r.yellow(`Unable to determine the latest Quantex CLI version.`)),2);if(!a.canAutoUpdate){console.log(r.yellow(`Quantex CLI cannot auto-update from the current install source: ${a.installSource}.`));let e=t(a);return e&&console.log(r.cyan(`Manual upgrade: ${e}`)),2}let o=a.latestVersion?` (${a.currentVersion} -> ${a.latestVersion})`:` (${a.currentVersion})`;console.log(r.cyan(`Upgrading Quantex CLI...${o}`));let s=await n(a);if(s.success)return console.log(r.green(`Quantex CLI upgraded successfully.`)),0;{console.log(r.red(`Failed to upgrade Quantex CLI.`)),s.error?.message&&console.log(r.yellow(`Reason: ${s.error.message}`));let e=t(a,s);return e&&console.log(r.cyan(`Manual recovery: ${e}`)),2}}export{i as upgradeCommand};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "quantex-cli",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.0.2-beta.1",
5
5
  "packageManager": "bun@1.3.11",
6
6
  "description": "统一的 AI Agent CLI 管理工具,支持安装、更新、卸载、查询、快捷启动主流 AI 编程助手",
7
7
  "author": "Drswith <drswith@outlook.com>",
@@ -1 +0,0 @@
1
- import{i as e,t}from"./config-DWeRAIFV.mjs";import{b as n,d as r,i,m as a,r as o,s}from"./version-CrMPGstC.mjs";import{chmod as c,mkdir as l,mkdtemp as u,readFile as d,rename as f,rm as p,stat as m,writeFile as h}from"node:fs/promises";import{basename as g,dirname as _,join as v}from"node:path";import y from"node:process";import{fileURLToPath as b}from"node:url";import{Buffer as x}from"node:buffer";import{createHash as S}from"node:crypto";const C=`quantex-cli`,w=`https://github.com/Drswith/quantex-cli`,T=`0.0.1`;function E(){return v(t(),`locks`,`self-upgrade.lock`)}async function D(){let e=E();await l(_(e),{recursive:!0});try{await l(e,{recursive:!1})}catch(e){if(typeof e==`object`&&e&&`code`in e&&e.code===`EEXIST`)return;throw e}return async()=>{await p(e,{force:!0,recursive:!0})}}async function ee(e,t,n,r){let i;try{i=await fetch(e)}catch(t){return A(`network`,`Failed to download ${e}.`,t)}if(!i.ok)return A(`network`,`Failed to download ${e}: HTTP ${i.status}.`);let a=await u(v(_(t),`.quantex-upgrade-`)),o=v(a,g(t)),s=`${t}.bak`;try{let l=x.from(await i.arrayBuffer()),u=await te(t),d=ie(l);if(d!==N(n))return A(`checksum`,`Checksum mismatch for ${e}. Expected ${N(n)}, got ${d}.`);if(await h(o,l),y.platform===`win32`)return ne(o,t,s,a,r);await c(o,u),await p(s,{force:!0}),await f(t,s),await f(o,t);let m=await re(t,r);return m.success?(await p(s,{force:!0}),{success:!0}):(await M(s,t),m)}catch(e){return A(j(e),`Failed to replace the current Quantex binary.`,e)}finally{y.platform!==`win32`&&await p(a,{recursive:!0,force:!0})}}async function te(e){try{return(await m(e)).mode&511}catch{return 493}}function ne(e,t,n,r,i){try{let a=O(e,t,n,r,y.pid,i);return Bun.spawn([`powershell.exe`,`-NoProfile`,`-NonInteractive`,`-ExecutionPolicy`,`Bypass`,`-WindowStyle`,`Hidden`,`-Command`,a],{stdio:[`ignore`,`ignore`,`ignore`],windowsHide:!0}).unref?.(),{success:!0}}catch(e){return A(`locked`,`Failed to schedule Windows binary replacement.`,e)}}function O(e,t,n,r,i,a){let o=k(e),s=k(t),c=k(n),l=k(r),u=k(a??``);return[`$pidToWait = ${i}`,`$tempPath = '${o}'`,`$targetPath = '${s}'`,`$backupPath = '${c}'`,`$tempDir = '${l}'`,`$expectedVersion = '${u}'`,`while (Get-Process -Id $pidToWait -ErrorAction SilentlyContinue) { Start-Sleep -Milliseconds 200 }`,`for ($attempt = 0; $attempt -lt 50; $attempt++) {`,` try {`,` if (Test-Path -LiteralPath $backupPath) { Remove-Item -LiteralPath $backupPath -Force -ErrorAction SilentlyContinue }`,` Move-Item -LiteralPath $targetPath -Destination $backupPath -Force -ErrorAction Stop`,` break`,` }`,` catch {`,` Start-Sleep -Milliseconds 200`,` }`,`}`,`Move-Item -LiteralPath $tempPath -Destination $targetPath -Force`,`if ($expectedVersion -ne '') {`,` $output = & $targetPath --version 2>$null`,` if ($LASTEXITCODE -ne 0 -or ($output -notmatch [regex]::Escape($expectedVersion))) {`,` Remove-Item -LiteralPath $targetPath -Force -ErrorAction SilentlyContinue`,` Move-Item -LiteralPath $backupPath -Destination $targetPath -Force`,` Remove-Item -LiteralPath $tempDir -Force -Recurse -ErrorAction SilentlyContinue`,` exit 1`,` }`,`}`,`Remove-Item -LiteralPath $backupPath -Force -ErrorAction SilentlyContinue`,`Remove-Item -LiteralPath $tempDir -Force -Recurse -ErrorAction SilentlyContinue`].join(`; `)}function k(e){return e.replaceAll(`'`,`''`)}function A(e,t,n){return{error:{detail:n,kind:e,message:t},success:!1}}function j(e){let t=typeof e==`object`&&e&&`code`in e?String(e.code):``;return t===`EACCES`||t===`EPERM`?`permission`:t===`EBUSY`?`locked`:`unknown`}async function M(e,t){await p(t,{force:!0}),await f(e,t)}async function re(e,t){if(!t)return{success:!0};try{let n=Bun.spawn([e,`--version`],{stdio:[`ignore`,`pipe`,`ignore`]}),r=n.stdout?await new Response(n.stdout).text():``,i=await n.exited;return i===0?r.includes(t)?{success:!0}:A(`verify`,`The upgraded Quantex binary reported an unexpected version during verification.`):A(`verify`,`The upgraded Quantex binary exited with code ${i} during verification.`)}catch(e){return A(`verify`,`Failed to execute the upgraded Quantex binary for verification.`,e)}}function ie(e){return S(`sha256`).update(e).digest(`hex`)}function N(e){return e.trim().toLowerCase()}function P(e){return e.replaceAll(`\\`,`/`).toLowerCase()}function F(e=y.execPath){if(g(P(e)).endsWith(`.exe`))return`quantex-windows-x64.exe`;if(y.platform===`darwin`)return y.arch===`arm64`?`quantex-darwin-arm64`:`quantex-darwin-x64`;if(y.platform===`linux`)return y.arch===`arm64`?`quantex-linux-arm64`:`quantex-linux-x64`}function I(e=y.execPath){let t=F(e);if(t)return`${w}/releases/latest/download/${t}`}function L(e,t,n=y.env){return e||(n.QUANTEX_UPDATE_CHANNEL===`beta`?`beta`:n.QUANTEX_UPDATE_CHANNEL===`stable`?`stable`:t===`beta`?`beta`:`stable`)}async function R(e){let t=await i(await z(e),`self:manifest:${e}`);if(!t)throw Error(`Failed to download release manifest.`);return t}async function z(e){if(e===`stable`)return`${w}/releases/latest/download/manifest.json`;let t=(await B(e)).assets.find(e=>e.name===`manifest.json`);if(!t?.browser_download_url)throw Error(`No manifest.json asset was found for the ${e} release channel.`);return t.browser_download_url}async function B(e){let t=H();if(!t)throw Error(`Failed to resolve the GitHub repository slug for Quantex releases.`);let n=await i(`https://api.github.com/repos/${t}/releases?per_page=20`,`self:github-releases`);if(!n)throw Error(`Failed to query GitHub releases.`);let r=n.find(t=>e===`beta`?t.prerelease:!t.prerelease);if(!r)throw Error(`No GitHub release was found for the ${e} channel.`);return r}function V(e,t=y.execPath){let n=y.platform,r=y.arch===`arm64`?`arm64`:`x64`,i=F(t);return e.assets.find(e=>e.platform===n&&e.arch===r&&(!i||e.name===i))}function H(){return w.match(/github\.com\/([^/]+\/[^/]+)$/)?.[1]}const U={source:`binary`,canHandle:e=>e.installSource===`binary`,getRecoveryHint:(e,t)=>{let n=t?.error?.detail&&typeof t.error.detail==`object`&&`downloadUrl`in t.error.detail?String(t.error.detail.downloadUrl):I(e.executablePath);if(n)return t?.error?.kind===`locked`?`close other qtx processes and retry, or download and replace the binary from ${n}`:t?.error?.kind===`permission`?`check write permission for the current binary path, or download and replace the binary from ${n}`:t?.error?.kind===`network`?`check network access and retry, or download and replace the binary from ${n}`:`download and replace the binary from ${n}`},async upgrade(e){if(!F(e.executablePath))return{error:{kind:`unsupported`,message:`No release artifact is available for the current platform and architecture.`},installSource:e.installSource,success:!1};let t;try{t=await R(e.updateChannel)}catch(t){return{error:{detail:t,kind:`network`,message:`Failed to resolve the ${e.updateChannel} release manifest.`},installSource:e.installSource,success:!1}}let n=V(t,e.executablePath);if(!n)return{error:{detail:{channel:e.updateChannel},kind:`unsupported`,message:`No binary asset is available for the current platform on the ${e.updateChannel} channel.`},installSource:e.installSource,success:!1};let r=await ee(n.downloadUrl,e.executablePath,n.checksum,t.version);return{...!r.success&&r.error?{...r,error:{...r.error,detail:{...typeof r.error.detail==`object`&&r.error.detail?r.error.detail:{},downloadUrl:n.downloadUrl}}}:r,installSource:e.installSource,newVersion:r.success?t.version:void 0}}},W={source:`bun`,canHandle:e=>e.installSource===`bun`,getRecoveryHint:e=>`bun add -g ${C}@${e.updateChannel===`beta`?`beta`:`latest`}`,async upgrade(e){let t=await r(C,`latest-major`,e.updateChannel===`beta`?`beta`:`latest`);return{error:t?void 0:{kind:`unknown`,message:`Failed to update ${C} through Bun.`},installSource:e.installSource,newVersion:t?e.latestVersion:void 0,success:t}}},G={source:`npm`,canHandle:e=>e.installSource===`npm`,getRecoveryHint:e=>`npm install -g ${C}@${e.updateChannel===`beta`?`beta`:`latest`}`,async upgrade(e){let t=await s(C,`latest-major`,e.updateChannel===`beta`?`beta`:`latest`);return{error:t?void 0:{kind:`unknown`,message:`Failed to update ${C} through npm.`},installSource:e.installSource,newVersion:t?e.latestVersion:void 0,success:t}}},K={source:`source`,canHandle:e=>e.installSource===`source`||e.installSource===`unknown`,getRecoveryHint:()=>void 0,async upgrade(e){return{error:{kind:`unsupported`,message:`Install source "${e.installSource}" does not support auto-update.`},installSource:e.installSource,success:!1}}},q=[W,G,U,K];function ae(e){return q.find(t=>t.canHandle(e))??K}function J(e,t,n=`stable`,r){if(r?.error?.kind===`locked`)return`another qtx upgrade is already running; wait for it to finish and retry`;if(e===`bun`)return`bun add -g ${C}@${n===`beta`?`beta`:`latest`}`;if(e===`npm`)return`npm install -g ${C}@${n===`beta`?`beta`:`latest`}`;if(e===`binary`){let e=I(t);return e?r?.error?.kind===`permission`?`check write permission for the current binary path, or download and replace the binary from ${e}`:r?.error?.kind===`network`?`check network access and retry, or download and replace the binary from ${e}`:`download and replace the binary from ${e}`:void 0}}function oe(e,t){return J(e.installSource,e.executablePath,e.updateChannel,t)}const Y=C,se=`/node_modules/${Y}`;async function X(t){let n=await ue(),r=y.execPath,i=n.foundPackageJson?Q(n.packageRoot):Q(``,r),o=await le((await a()).installSource,i),s=await e(),c=L(t?.updateChannel,s.selfUpdateChannel),l=await pe(o,r,c);return{canAutoUpdate:Z(o),currentVersion:n.version||`0.0.1`,executablePath:r,installSource:o,latestVersion:l,packageRoot:n.packageRoot,recommendedUpgradeCommand:Z(o)?`quantex upgrade`:void 0,updateChannel:c}}async function ce(e){let t=e??await X(),n=await D();if(!n)return{error:{kind:`locked`,message:`Another qtx upgrade is already running.`},installSource:t.installSource,success:!1};try{return await ae(t).upgrade(t)}finally{await n()}}function Z(e){return e===`binary`||e===`bun`||e===`npm`}async function le(e,t){return t!==`unknown`&&e!==t?(await n(t),t):e??t}function Q(e,t=y.execPath){let n=$(e);return n.includes(`/.bun/install/global/`)?`bun`:n.includes(se)?`npm`:n?`source`:he(t)?`binary`:`unknown`}async function ue(e=import.meta.url){let t=ge(e),n=_(t);for(;;){let e=v(n,`package.json`),t=await me(e);if(t?.name===Y)return{foundPackageJson:!0,packageJsonPath:e,packageRoot:n,version:t.version??`0.0.1`};let r=_(n);if(r===n)break;n=r}return{foundPackageJson:!1,packageJsonPath:v(_(t),`package.json`),packageRoot:_(t),version:T}}function de(){return T}function fe(e,t=y.execPath){return J(e,t)}async function pe(e,t,n){if(e===`binary`)try{let e=await R(n);return V(e,t)?e.version:void 0}catch{return}return o(Y,n===`beta`?`beta`:`latest`)}async function me(e){try{return JSON.parse(await d(e,`utf8`))}catch{return}}function $(e){return e.replaceAll(`\\`,`/`).toLowerCase()}function he(e){let t=g($(e));return t!==`bun`&&t!==`bun.exe`}function ge(e){try{return b(e)}catch{return y.execPath}}export{X as a,oe as c,de as i,F as l,Q as n,ce as o,fe as r,J as s,Z as t,I as u};