@vpxa/aikit 0.1.283 → 0.1.284
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/package.json +1 -1
- package/packages/cli/dist/index.js +6 -6
- package/packages/cli/dist/{init-CRKUTp9B.js → init-gltXD_CW.js} +1 -1
- package/packages/cli/dist/{templates-Lf2jzrRP.js → templates-CYwnTZ8H.js} +1 -1
- package/packages/server/dist/bin.js +1 -1
- package/packages/server/dist/index.js +1 -1
- package/packages/server/dist/{server-BiFuQDqy.js → server-9ETDX3Qp.js} +129 -129
- package/packages/server/dist/{server-GTvNc3rR.js → server-CgOH5oTb.js} +129 -129
- package/packages/server/dist/version-check-CJK1Fwmy.js +2 -0
- package/packages/server/dist/version-check-yzdUDXHC.js +1 -0
- package/scaffold/definitions/mcp-entry.json +1 -1
- package/scaffold/dist/definitions/mcp-entry.json +1 -1
- package/packages/server/dist/version-check-BhvsN1fC.js +0 -2
- package/packages/server/dist/version-check-DAQdKLy7.js +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{existsSync as e,mkdirSync as t,readFileSync as n,renameSync as r,rmSync as i,writeFileSync as a}from"node:fs";import{dirname as o,join as s,resolve as c}from"node:path";import{fileURLToPath as l}from"node:url";import{createLogger as u}from"../../core/dist/index.js";import{homedir as d}from"node:os";import{execFile as f,execSync as p}from"node:child_process";const m=`@vpxa/aikit`,h=`https://registry.npmjs.org/${m}/latest`,g=u(`server`),_=s(d(),`.aikit`),v=s(_,`current-version.json`),y=s(_,`versions`),b=/^\d+\.\d+\.\d+(-[\w.+]+)?(\+[\w.]+)?$/;function x(e){if(!b.test(e))throw Error(`Invalid semver version: ${JSON.stringify(e)}`)}function S(){let e=c(o(l(import.meta.url)),`..`,`..`,`..`,`package.json`);try{return JSON.parse(n(e,`utf-8`)).version??`0.0.0`}catch{return`0.0.0`}}function C(e,t){let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++){let t=(n[e]??0)-(r[e]??0);if(t!==0)return t>0?1:-1}return 0}function w(e,t){let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++){if((n[e]??0)>(r[e]??0))return!0;if((n[e]??0)<(r[e]??0))return!1}return!1}async function T(n){x(n);let o=`v${n}`,c=s(y,`${o}-staging`),l=s(y,o);try{e(c)&&i(c,{recursive:!0,force:!0}),t(c,{recursive:!0}),p(`tar -xzf "${p(`npm pack ${m}@${n}`,{cwd:c,encoding:`utf-8`,timeout:6e4,windowsHide:!0}).trim()}"`,{cwd:c,encoding:`utf-8`,timeout:3e4,windowsHide:!0});let u=s(c,`package`);p(`npm install --production --install-strategy=nested --no-audit --no-fund`,{cwd:u,encoding:`utf-8`,timeout:12e4,windowsHide:!0});let d=s(u,`packages`,`server`,`dist`,`bin.js`);if(!e(d))throw Error(`Server entry not found at ${d}`);if(!e(s(u,`node_modules`)))throw Error(`node_modules not found — npm install may have failed`);let f=`${v}.tmp`;a(f,JSON.stringify({version:n,installedAt:new Date().toISOString()},null,2)),r(f,v),e(l)&&i(l,{recursive:!0,force:!0}),r(u,l),g.info(`Installed version ${o}`,{targetDir:l})}finally{e(c)&&i(c,{recursive:!0,force:!0})}}async function E(){try{let t=n(v,`utf-8`),{version:i}=JSON.parse(t),o=await fetch(h,{signal:AbortSignal.timeout(1e4)});if(!o.ok)return;let c=(await o.json()).version;if(!c||c===i||!w(c,i))return;if(e(s(y,`v${c}`))){let e=`${v}.tmp`;a(e,JSON.stringify({version:c,installedAt:new Date().toISOString()},null,2)),r(e,v),g.info(`Re-activated existing version v${c} — no download needed`);return}g.info(`New version available: ${c}. Installing...`),await T(c),g.info(`Updated to v${c}. Restart to use.`)}catch(e){g.error(`Background update check failed: ${e instanceof Error?e.message:String(e)}`)}}function D(){if(e(v)){E();return}let t=S();fetch(h,{signal:AbortSignal.timeout(1e4)}).then(e=>{if(e.ok)return e.json()}).then(async e=>{if(!e||typeof e!=`object`)return;let n=e.version;if(n&&C(t,n)<0){g.info(`Newer version available — installing`,{currentVersion:t,latestVersion:n});try{await T(n),g.info(`Installed v${n}. Restart MCP to use.`)}catch(e){g.warn(`Auto-install failed`,{error:e instanceof Error?e.message:String(e),latestVersion:n})}}}).catch(()=>{})}function O(){try{let t=c(d(),`.copilot`,`.aikit-scaffold.json`);return e(t)?JSON.parse(n(t,`utf-8`)).version??null:null}catch{return null}}function k(){try{let t=c(process.cwd(),`.github`,`.aikit-scaffold.json`);return e(t)?JSON.parse(n(t,`utf-8`)).version??null:null}catch{return null}}let A=`idle`,j=null,M=null;function N(){return{state:A,error:j}}function P(){A=`idle`,j=null}function F(){try{let t=S(),n=O(),r=k(),i=n!=null&&n!==t,a=r!=null&&r!==t;if(D(),!i&&!a||(M!==t&&(P(),M=t),A!==`idle`))return;A=`pending`,j=null,g.info(`Scaffold version mismatch — auto-upgrading`,{serverVersion:t,userScaffoldVersion:n,workspaceScaffoldVersion:r});let s=o(l(import.meta.url)),u=[c(s,`..`,`..`,`..`,`bin`,`aikit.mjs`),c(s,`..`,`bin`,`aikit.mjs`),...process.argv[1]?[c(o(process.argv[1]),`aikit.mjs`)]:[]],d=u.find(t=>e(t));if(!d){A=`failed`,j=`aikit CLI binary not found. Tried: ${u.join(`, `)}`,g.warn(`Cannot auto-upgrade: aikit CLI binary not found`,{candidates:u,platform:process.platform});return}f(process.execPath,[d,`upgrade`],{timeout:3e4,windowsHide:!0},(e,n,r)=>{e?(A=`failed`,j=e.message,g.warn(`Auto-upgrade failed`,{error:e.message,stderr:r?.slice(0,500),binPath:d,platform:process.platform})):(A=`success`,j=null,g.info(`Auto-upgrade completed to version ${t}`))}).unref()}catch(e){A=`failed`,j=e instanceof Error?e.message:String(e),g.warn(`Auto-upgrade check failed`,{error:j})}}export{F as autoUpgradeScaffold,D as checkForUpdates,S as getCurrentVersion,N as getUpgradeState};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{existsSync as e,mkdirSync as t,readFileSync as n,renameSync as r,rmSync as i,writeFileSync as a}from"node:fs";import{dirname as o,join as s,resolve as c}from"node:path";import{fileURLToPath as l}from"node:url";import{createLogger as u}from"../../core/dist/index.js";import{execFile as d,execSync as f}from"node:child_process";import{homedir as p}from"node:os";const m=`@vpxa/aikit`,h=`https://registry.npmjs.org/${m}/latest`,g=u(`server`),_=s(p(),`.aikit`),v=s(_,`current-version.json`),y=s(_,`versions`),b=/^\d+\.\d+\.\d+(-[\w.+]+)?(\+[\w.]+)?$/;function x(e){if(!b.test(e))throw Error(`Invalid semver version: ${JSON.stringify(e)}`)}function S(){let e=c(o(l(import.meta.url)),`..`,`..`,`..`,`package.json`);try{return JSON.parse(n(e,`utf-8`)).version??`0.0.0`}catch{return`0.0.0`}}function C(e,t){let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++){let t=(n[e]??0)-(r[e]??0);if(t!==0)return t>0?1:-1}return 0}function w(e,t){let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++){if((n[e]??0)>(r[e]??0))return!0;if((n[e]??0)<(r[e]??0))return!1}return!1}async function T(n){x(n);let o=`v${n}`,c=s(y,`${o}-staging`),l=s(y,o);try{e(c)&&i(c,{recursive:!0,force:!0}),t(c,{recursive:!0}),f(`tar -xzf "${f(`npm pack ${m}@${n}`,{cwd:c,encoding:`utf-8`,timeout:6e4,windowsHide:!0}).trim()}"`,{cwd:c,encoding:`utf-8`,timeout:3e4,windowsHide:!0});let u=s(c,`package`);f(`npm install --production --install-strategy=nested --no-audit --no-fund`,{cwd:u,encoding:`utf-8`,timeout:12e4,windowsHide:!0});let d=s(u,`packages`,`server`,`dist`,`bin.js`);if(!e(d))throw Error(`Server entry not found at ${d}`);if(!e(s(u,`node_modules`)))throw Error(`node_modules not found — npm install may have failed`);let p=`${v}.tmp`;a(p,JSON.stringify({version:n,installedAt:new Date().toISOString()},null,2)),r(p,v),e(l)&&i(l,{recursive:!0,force:!0}),r(u,l),g.info(`Installed version ${o}`,{targetDir:l})}finally{e(c)&&i(c,{recursive:!0,force:!0})}}async function E(){try{let t=n(v,`utf-8`),{version:i}=JSON.parse(t),o=await fetch(h,{signal:AbortSignal.timeout(1e4)});if(!o.ok)return;let c=(await o.json()).version;if(!c||c===i||!w(c,i))return;if(e(s(y,`v${c}`))){let e=`${v}.tmp`;a(e,JSON.stringify({version:c,installedAt:new Date().toISOString()},null,2)),r(e,v),g.info(`Re-activated existing version v${c} — no download needed`);return}g.info(`New version available: ${c}. Installing...`),await T(c),g.info(`Updated to v${c}. Restart to use.`)}catch(e){g.error(`Background update check failed: ${e instanceof Error?e.message:String(e)}`)}}function D(){if(e(v)){E();return}let t=S();fetch(h,{signal:AbortSignal.timeout(1e4)}).then(e=>{if(e.ok)return e.json()}).then(async e=>{if(!e||typeof e!=`object`)return;let n=e.version;if(n&&C(t,n)<0){g.info(`Newer version available — installing`,{currentVersion:t,latestVersion:n});try{await T(n),g.info(`Installed v${n}. Restart MCP to use.`)}catch(e){g.warn(`Auto-install failed`,{error:e instanceof Error?e.message:String(e),latestVersion:n})}}}).catch(()=>{})}function O(){try{let t=c(p(),`.copilot`,`.aikit-scaffold.json`);return e(t)?JSON.parse(n(t,`utf-8`)).version??null:null}catch{return null}}function k(){try{let t=c(process.cwd(),`.github`,`.aikit-scaffold.json`);return e(t)?JSON.parse(n(t,`utf-8`)).version??null:null}catch{return null}}let A=`idle`,j=null,M=null;function N(){return{state:A,error:j}}function P(){A=`idle`,j=null}function F(){try{let t=S(),n=O(),r=k(),i=n!=null&&n!==t,a=r!=null&&r!==t;if(D(),!i&&!a||(M!==t&&(P(),M=t),A!==`idle`))return;A=`pending`,j=null,g.info(`Scaffold version mismatch — auto-upgrading`,{serverVersion:t,userScaffoldVersion:n,workspaceScaffoldVersion:r});let s=o(l(import.meta.url)),u=[c(s,`..`,`..`,`..`,`bin`,`aikit.mjs`),c(s,`..`,`bin`,`aikit.mjs`),...process.argv[1]?[c(o(process.argv[1]),`aikit.mjs`)]:[]],f=u.find(t=>e(t));if(!f){A=`failed`,j=`aikit CLI binary not found. Tried: ${u.join(`, `)}`,g.warn(`Cannot auto-upgrade: aikit CLI binary not found`,{candidates:u,platform:process.platform});return}d(process.execPath,[f,`upgrade`],{timeout:3e4,windowsHide:!0},(e,n,r)=>{e?(A=`failed`,j=e.message,g.warn(`Auto-upgrade failed`,{error:e.message,stderr:r?.slice(0,500),binPath:f,platform:process.platform})):(A=`success`,j=null,g.info(`Auto-upgrade completed to version ${t}`))}).unref()}catch(e){A=`failed`,j=e instanceof Error?e.message:String(e),g.warn(`Auto-upgrade check failed`,{error:j})}}export{F as autoUpgradeScaffold,D as checkForUpdates,S as getCurrentVersion,N as getUpgradeState};
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
"command": "node",
|
|
4
4
|
"args": [
|
|
5
5
|
"-e",
|
|
6
|
-
"const{execSync:x}=require('child_process');const{existsSync:e,renameSync:m}=require('fs');const{join:j}=require('path');const c=j(process.env.LOCALAPPDATA||process.env.HOME||'','npm-cache');const s={stdio:'inherit'};try{x('npx -y @vpxa/aikit@latest serve',{...s,timeout:180000})}catch{try{const d=j(c,'_npx');if(e(d))m(d,j(c,'_npx_'+Date.now()))}catch{};try{x('npm cache verify',{stdio:'ignore',timeout:30000})}catch{};try{x('npm cache clean --force',{stdio:'ignore',timeout:30000})}catch{};try{x('npx -y @vpxa/aikit@latest serve',s)}catch(e){process.stderr.write('aikit: all recovery attempts failed. Run:
|
|
6
|
+
"const{execSync:x}=require('child_process');const{existsSync:e,readFileSync:r,renameSync:m}=require('fs');const{join:j}=require('path');const{homedir:h}=require('os');const f=j(h(),'.aikit','current-version.json');if(e(f)){try{const{version:g}=JSON.parse(r(f,'utf-8'));const p=j(h(),'.aikit','versions','v'+g,'packages','server','dist','bin.js');if(!e(p)){throw Error('Local install not found at '+p)};x('\"'+process.execPath+'\" \"'+p+'\" serve',{stdio:'inherit'});process.exit(0)}catch(c){try{process.stderr.write('aikit: local install failed - '+c.message+'. Run: aikit install')}catch{}process.exit(1)}};const c=j(process.env.LOCALAPPDATA||process.env.HOME||'','npm-cache');const s={stdio:'inherit'};try{x('npx -y @vpxa/aikit@latest serve',{...s,timeout:180000})}catch{try{const d=j(c,'_npx');if(e(d))m(d,'\"'+j(c,'_npx_'+Date.now())+'\"')}catch{};try{x('npm cache verify',{stdio:'ignore',timeout:30000})}catch{};try{x('npm cache clean --force',{stdio:'ignore',timeout:30000})}catch{};try{x('npx -y @vpxa/aikit@latest serve',s)}catch(e){try{process.stderr.write('aikit: all recovery attempts failed. Run: aikit install')}catch{}process.exit(1)}}"
|
|
7
7
|
]
|
|
8
8
|
}
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
"command": "node",
|
|
4
4
|
"args": [
|
|
5
5
|
"-e",
|
|
6
|
-
"const{execSync:x}=require('child_process');const{existsSync:e,renameSync:m}=require('fs');const{join:j}=require('path');const c=j(process.env.LOCALAPPDATA||process.env.HOME||'','npm-cache');const s={stdio:'inherit'};try{x('npx -y @vpxa/aikit@latest serve',{...s,timeout:180000})}catch{try{const d=j(c,'_npx');if(e(d))m(d,j(c,'_npx_'+Date.now()))}catch{};try{x('npm cache verify',{stdio:'ignore',timeout:30000})}catch{};try{x('npm cache clean --force',{stdio:'ignore',timeout:30000})}catch{};try{x('npx -y @vpxa/aikit@latest serve',s)}catch(e){process.stderr.write('aikit: all recovery attempts failed. Run:
|
|
6
|
+
"const{execSync:x}=require('child_process');const{existsSync:e,readFileSync:r,renameSync:m}=require('fs');const{join:j}=require('path');const{homedir:h}=require('os');const f=j(h(),'.aikit','current-version.json');if(e(f)){try{const{version:g}=JSON.parse(r(f,'utf-8'));const p=j(h(),'.aikit','versions','v'+g,'packages','server','dist','bin.js');if(!e(p)){throw Error('Local install not found at '+p)};x('\"'+process.execPath+'\" \"'+p+'\" serve',{stdio:'inherit'});process.exit(0)}catch(c){try{process.stderr.write('aikit: local install failed - '+c.message+'. Run: aikit install')}catch{}process.exit(1)}};const c=j(process.env.LOCALAPPDATA||process.env.HOME||'','npm-cache');const s={stdio:'inherit'};try{x('npx -y @vpxa/aikit@latest serve',{...s,timeout:180000})}catch{try{const d=j(c,'_npx');if(e(d))m(d,'\"'+j(c,'_npx_'+Date.now())+'\"')}catch{};try{x('npm cache verify',{stdio:'ignore',timeout:30000})}catch{};try{x('npm cache clean --force',{stdio:'ignore',timeout:30000})}catch{};try{x('npx -y @vpxa/aikit@latest serve',s)}catch(e){try{process.stderr.write('aikit: all recovery attempts failed. Run: aikit install')}catch{}process.exit(1)}}"
|
|
7
7
|
]
|
|
8
8
|
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{existsSync as e,mkdirSync as t,readFileSync as n,renameSync as r,rmSync as i,writeFileSync as a}from"node:fs";import{dirname as o,join as s,resolve as c}from"node:path";import{fileURLToPath as l}from"node:url";import{createLogger as u}from"../../core/dist/index.js";import{homedir as d}from"node:os";import{execFile as f,execSync as p}from"node:child_process";const m=`@vpxa/aikit`,h=`https://registry.npmjs.org/${m}/latest`,g=u(`server`),_=s(d(),`.aikit`),v=s(_,`current-version.json`),y=s(_,`versions`);function b(){let e=c(o(l(import.meta.url)),`..`,`..`,`..`,`package.json`);try{return JSON.parse(n(e,`utf-8`)).version??`0.0.0`}catch{return`0.0.0`}}function x(e,t){let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++){let t=(n[e]??0)-(r[e]??0);if(t!==0)return t>0?1:-1}return 0}function S(e,t){let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++){if((n[e]??0)>(r[e]??0))return!0;if((n[e]??0)<(r[e]??0))return!1}return!1}async function C(n){let o=s(_,`staging`,n),c=s(y,n);try{e(o)&&i(o,{recursive:!0,force:!0}),t(o,{recursive:!0}),p(`tar -xzf "${p(`npm pack ${m}@${n}`,{cwd:o,encoding:`utf-8`,timeout:6e4,windowsHide:!0}).trim()}"`,{cwd:o,encoding:`utf-8`,timeout:3e4,windowsHide:!0});let l=s(o,`package`);p(`npm install --production`,{cwd:l,encoding:`utf-8`,timeout:12e4,windowsHide:!0});let u=s(l,`packages`,`server`,`dist`,`bin.js`);if(!e(u))throw Error(`Server entry not found at ${u}`);e(c)&&i(c,{recursive:!0,force:!0}),r(l,c);let d=`${v}.tmp`;a(d,JSON.stringify({version:n,installedAt:new Date().toISOString()},null,2)),r(d,v),g.info(`Installed version ${n}`,{targetDir:c})}finally{e(o)&&i(o,{recursive:!0,force:!0})}}async function w(){try{let e=n(v,`utf-8`),{version:t}=JSON.parse(e),r=await fetch(h,{signal:AbortSignal.timeout(1e4)});if(!r.ok)return;let i=(await r.json()).version;if(!i||i===t||!S(i,t))return;g.info(`New version available: ${i}. Installing...`),await C(i),g.info(`Updated to v${i}. Restart to use.`)}catch(e){g.error(`Background update check failed: ${e instanceof Error?e.message:String(e)}`)}}function T(){if(e(v)){w();return}let t=b();fetch(h,{signal:AbortSignal.timeout(5e3)}).then(e=>{if(e.ok)return e.json()}).then(e=>{if(!e||typeof e!=`object`)return;let n=e.version;n&&x(t,n)<0&&g.warn(`Update available`,{currentVersion:t,latestVersion:n,updateCommand:`aikit upgrade`})}).catch(()=>{})}function E(){try{let t=c(d(),`.copilot`,`.aikit-scaffold.json`);return e(t)?JSON.parse(n(t,`utf-8`)).version??null:null}catch{return null}}function D(){try{let t=c(process.cwd(),`.github`,`.aikit-scaffold.json`);return e(t)?JSON.parse(n(t,`utf-8`)).version??null:null}catch{return null}}let O=`idle`,k=null;function A(){return{state:O,error:k}}function j(){try{let t=b(),n=E(),r=D();if(!(n!=null&&n!==t)&&!(r!=null&&r!==t)||O===`pending`||O===`success`)return;O=`pending`,k=null,g.info(`Scaffold version mismatch — auto-upgrading`,{serverVersion:t,userScaffoldVersion:n,workspaceScaffoldVersion:r});let i=o(l(import.meta.url)),a=[c(i,`..`,`..`,`..`,`bin`,`aikit.mjs`),c(i,`..`,`bin`,`aikit.mjs`),...process.argv[1]?[c(o(process.argv[1]),`aikit.mjs`)]:[]],s=a.find(t=>e(t));if(!s){O=`failed`,k=`aikit CLI binary not found. Tried: ${a.join(`, `)}`,g.warn(`Cannot auto-upgrade: aikit CLI binary not found`,{candidates:a,platform:process.platform});return}f(process.execPath,[s,`upgrade`],{timeout:3e4,windowsHide:!0},(e,n,r)=>{e?(O=`failed`,k=e.message,g.warn(`Auto-upgrade failed`,{error:e.message,stderr:r?.slice(0,500),binPath:s,platform:process.platform})):(O=`success`,k=null,g.info(`Auto-upgrade completed to version ${t}`))}).unref()}catch(e){O=`failed`,k=e instanceof Error?e.message:String(e),g.warn(`Auto-upgrade check failed`,{error:k})}}export{j as autoUpgradeScaffold,T as checkForUpdates,b as getCurrentVersion,A as getUpgradeState};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{existsSync as e,mkdirSync as t,readFileSync as n,renameSync as r,rmSync as i,writeFileSync as a}from"node:fs";import{dirname as o,join as s,resolve as c}from"node:path";import{fileURLToPath as l}from"node:url";import{createLogger as u}from"../../core/dist/index.js";import{execFile as d,execSync as f}from"node:child_process";import{homedir as p}from"node:os";const m=`@vpxa/aikit`,h=`https://registry.npmjs.org/${m}/latest`,g=u(`server`),_=s(p(),`.aikit`),v=s(_,`current-version.json`),y=s(_,`versions`);function b(){let e=c(o(l(import.meta.url)),`..`,`..`,`..`,`package.json`);try{return JSON.parse(n(e,`utf-8`)).version??`0.0.0`}catch{return`0.0.0`}}function x(e,t){let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++){let t=(n[e]??0)-(r[e]??0);if(t!==0)return t>0?1:-1}return 0}function S(e,t){let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++){if((n[e]??0)>(r[e]??0))return!0;if((n[e]??0)<(r[e]??0))return!1}return!1}async function C(n){let o=s(_,`staging`,n),c=s(y,n);try{e(o)&&i(o,{recursive:!0,force:!0}),t(o,{recursive:!0}),f(`tar -xzf "${f(`npm pack ${m}@${n}`,{cwd:o,encoding:`utf-8`,timeout:6e4,windowsHide:!0}).trim()}"`,{cwd:o,encoding:`utf-8`,timeout:3e4,windowsHide:!0});let l=s(o,`package`);f(`npm install --production`,{cwd:l,encoding:`utf-8`,timeout:12e4,windowsHide:!0});let u=s(l,`packages`,`server`,`dist`,`bin.js`);if(!e(u))throw Error(`Server entry not found at ${u}`);e(c)&&i(c,{recursive:!0,force:!0}),r(l,c);let d=`${v}.tmp`;a(d,JSON.stringify({version:n,installedAt:new Date().toISOString()},null,2)),r(d,v),g.info(`Installed version ${n}`,{targetDir:c})}finally{e(o)&&i(o,{recursive:!0,force:!0})}}async function w(){try{let e=n(v,`utf-8`),{version:t}=JSON.parse(e),r=await fetch(h,{signal:AbortSignal.timeout(1e4)});if(!r.ok)return;let i=(await r.json()).version;if(!i||i===t||!S(i,t))return;g.info(`New version available: ${i}. Installing...`),await C(i),g.info(`Updated to v${i}. Restart to use.`)}catch(e){g.error(`Background update check failed: ${e instanceof Error?e.message:String(e)}`)}}function T(){if(e(v)){w();return}let t=b();fetch(h,{signal:AbortSignal.timeout(5e3)}).then(e=>{if(e.ok)return e.json()}).then(e=>{if(!e||typeof e!=`object`)return;let n=e.version;n&&x(t,n)<0&&g.warn(`Update available`,{currentVersion:t,latestVersion:n,updateCommand:`aikit upgrade`})}).catch(()=>{})}function E(){try{let t=c(p(),`.copilot`,`.aikit-scaffold.json`);return e(t)?JSON.parse(n(t,`utf-8`)).version??null:null}catch{return null}}function D(){try{let t=c(process.cwd(),`.github`,`.aikit-scaffold.json`);return e(t)?JSON.parse(n(t,`utf-8`)).version??null:null}catch{return null}}let O=`idle`,k=null;function A(){return{state:O,error:k}}function j(){try{let t=b(),n=E(),r=D();if(!(n!=null&&n!==t)&&!(r!=null&&r!==t)||O===`pending`||O===`success`)return;O=`pending`,k=null,g.info(`Scaffold version mismatch — auto-upgrading`,{serverVersion:t,userScaffoldVersion:n,workspaceScaffoldVersion:r});let i=o(l(import.meta.url)),a=[c(i,`..`,`..`,`..`,`bin`,`aikit.mjs`),c(i,`..`,`bin`,`aikit.mjs`),...process.argv[1]?[c(o(process.argv[1]),`aikit.mjs`)]:[]],s=a.find(t=>e(t));if(!s){O=`failed`,k=`aikit CLI binary not found. Tried: ${a.join(`, `)}`,g.warn(`Cannot auto-upgrade: aikit CLI binary not found`,{candidates:a,platform:process.platform});return}d(process.execPath,[s,`upgrade`],{timeout:3e4,windowsHide:!0},(e,n,r)=>{e?(O=`failed`,k=e.message,g.warn(`Auto-upgrade failed`,{error:e.message,stderr:r?.slice(0,500),binPath:s,platform:process.platform})):(O=`success`,k=null,g.info(`Auto-upgrade completed to version ${t}`))}).unref()}catch(e){O=`failed`,k=e instanceof Error?e.message:String(e),g.warn(`Auto-upgrade check failed`,{error:k})}}export{j as autoUpgradeScaffold,T as checkForUpdates,b as getCurrentVersion,A as getUpgradeState};
|