@neuvybe/jarvis 0.3.0 → 0.3.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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{readFileSync as M}from"node:fs";var v={debug:0,info:1,warn:2,error:3};function k(r){try{return JSON.stringify(r,(e,t)=>t instanceof Error?{name:t.name,message:t.message,stack:t.stack}:t)}catch{return"[unserializable meta]"}}var m=class{level;constructor(e="info"){this.level=e}setLevel(e){this.level=e}getLevel(){return this.level}debug(e,t){this.emit("debug",e,t)}info(e,t){this.emit("info",e,t)}warn(e,t){this.emit("warn",e,t)}error(e,t){this.emit("error",e,t)}emit(e,t,o){if(v[e]<v[this.level])return;let a=`[${new Date().toISOString()}] ${e.toUpperCase()}`,s=o!==void 0?`${a} ${t} ${k(o)}`:`${a} ${t}`;e==="error"?console.error(s):e==="warn"?console.warn(s):console.log(s)}},n=new m;import{execSync as y,spawnSync as S}from"node:child_process";import{existsSync as $}from"node:fs";import{join as j}from"node:path";function u(r,e){let t=a=>(a.split("-")[0]??"").split(".").map(s=>Number.parseInt(s,10)||0),o=t(r),c=t(e);for(let a=0;a<Math.max(o.length,c.length);a++){let s=o[a]??0,i=c[a]??0;if(s!==i)return s>i}return!1}var p=class{constructor(e){this.currentVersion=e}currentVersion;packageName="@neuvybe/jarvis";registryTimeoutMs=3e3;safeVersion=/^[0-9A-Za-z.\-+]+$/;npmCmd(){return process.platform==="win32"?"npm.cmd":"npm"}async fetchLatest(){try{let e=await fetch(`https://registry.npmjs.org/${this.packageName}/latest`,{headers:{accept:"application/json"},signal:AbortSignal.timeout(this.registryTimeoutMs)});if(!e.ok)return null;let t=await e.json();return typeof t.version=="string"?t.version:null}catch{return null}}async status(){n.info(`jarvis ${this.currentVersion}`);let e=await this.fetchLatest();return e===null?n.info("could not check for updates (offline?)"):u(e,this.currentVersion)?n.info(`upgrade available: ${this.currentVersion} -> ${e} (run: jarvis upgrade)`):n.info("up to date"),0}async upgrade(){n.info("checking for updates...");let e=await this.fetchLatest();if(e===null)return n.warn("could not reach the npm registry; try again later"),1;if(!u(e,this.currentVersion))return n.info(`already on the latest version (${this.currentVersion})`),0;if(!this.safeVersion.test(e))return n.error(`refusing to install unexpected version string: ${e}`),1;n.info(`upgrading ${this.currentVersion} -> ${e}...`),await this.stopCore();let t=`${this.npmCmd()} install -g ${this.packageName}@${e}`;try{y(t,{stdio:"inherit"})}catch{return n.error(`upgrade failed; run manually: ${this.npmCmd()} install -g ${this.packageName}@latest`),1}let o=this.resolveFreshEntrypoint();return o===null?(n.info(`upgraded to ${e}. run "jarvis --version" to confirm.`),0):(n.info("verifying the freshly installed jarvis..."),S(process.execPath,[o,"--version"],{stdio:"inherit"}).status!==0?(n.warn('upgrade installed but the fresh entrypoint exited abnormally; run "jarvis --version" to confirm'),1):(n.info(`upgraded to ${e}.`),0))}async stopCore(){return n.debug("stop-core hook: no daemon in v0.1; nothing to stop (proposal 0013 fills this in)"),Promise.resolve()}resolveFreshEntrypoint(){try{let e=y(`${this.npmCmd()} root -g`,{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim();if(!e)return null;let t=j(e,this.packageName,"dist","index.js");return $(t)?t:null}catch{return null}}};import{spawn as N}from"node:child_process";import{existsSync as A,readFileSync as O,writeFileSync as P}from"node:fs";import{mkdirSync as x}from"node:fs";import{homedir as C}from"node:os";import{join as w,resolve as V}from"node:path";var g=class{envOverride="JARVIS_HOME";dirName=".jarvis";dir(){let e=process.env[this.envOverride]?.trim();return e?V(e):w(C(),this.dirName)}resolve(...e){return w(this.dir(),...e)}ensureDir(){let e=this.dir();return x(e,{recursive:!0,mode:448}),e}},b=new g;var d=class{constructor(e,t=b){this.currentVersion=e;this.home=t}currentVersion;home;packageName="@neuvybe/jarvis";cacheFile="update-check.json";ttlMs=360*60*1e3;cachePath(){return this.home.resolve(this.cacheFile)}read(){let e=this.cachePath();if(!A(e))return null;try{let t=JSON.parse(O(e,"utf8"));return typeof t.lastCheckedAt=="number"&&typeof t.latestVersion=="string"?{lastCheckedAt:t.lastCheckedAt,latestVersion:t.latestVersion}:null}catch{return null}}write(e,t){let o={lastCheckedAt:t,latestVersion:e};try{this.home.ensureDir(),P(this.cachePath(),JSON.stringify(o))}catch{}}isStale(e){let t=this.read();return!t||e-t.lastCheckedAt>this.ttlMs}notice(){let e=this.read();return!e||!u(e.latestVersion,this.currentVersion)?null:L(`upgrade available: ${this.currentVersion} -> ${e.latestVersion} (run: jarvis upgrade)`)}refreshInBackground(){try{let e=this.cachePath();this.home.ensureDir();let t=`
2
+ import{readFileSync as M}from"node:fs";var v={debug:0,info:1,warn:2,error:3};function k(r){try{return JSON.stringify(r,(e,t)=>t instanceof Error?{name:t.name,message:t.message,stack:t.stack}:t)}catch{return"[unserializable meta]"}}var m=class{level;constructor(e="info"){this.level=e}setLevel(e){this.level=e}getLevel(){return this.level}debug(e,t){this.emit("debug",e,t)}info(e,t){this.emit("info",e,t)}warn(e,t){this.emit("warn",e,t)}error(e,t){this.emit("error",e,t)}emit(e,t,o){if(v[e]<v[this.level])return;let a=`[${new Date().toISOString()}] ${e.toUpperCase()}`,s=o!==void 0?`${a} ${t} ${k(o)}`:`${a} ${t}`;e==="error"?console.error(s):e==="warn"?console.warn(s):console.log(s)}},n=new m;import{execSync as y,spawnSync as S}from"node:child_process";import{existsSync as $}from"node:fs";import{join as j}from"node:path";function u(r,e){let t=a=>(a.split("-")[0]??"").split(".").map(s=>Number.parseInt(s,10)||0),o=t(r),c=t(e);for(let a=0;a<Math.max(o.length,c.length);a++){let s=o[a]??0,i=c[a]??0;if(s!==i)return s>i}return!1}var p=class{constructor(e){this.currentVersion=e}currentVersion;packageName="@neuvybe/jarvis";registryTimeoutMs=3e3;safeVersion=/^[0-9A-Za-z.\-+]+$/;npmCmd(){return process.platform==="win32"?"npm.cmd":"npm"}async fetchLatest(){try{let e=await fetch(`https://registry.npmjs.org/${this.packageName}/latest`,{headers:{accept:"application/json"},signal:AbortSignal.timeout(this.registryTimeoutMs)});if(!e.ok)return null;let t=await e.json();return typeof t.version=="string"?t.version:null}catch{return null}}async status(){n.info(`jarvis ${this.currentVersion}`);let e=await this.fetchLatest();return e===null?n.info("could not check for updates (offline?)"):u(e,this.currentVersion)?n.info(`upgrade available: ${this.currentVersion} -> ${e} (run: jarvis upgrade)`):n.info("up to date"),0}async upgrade(){n.info("checking for updates...");let e=await this.fetchLatest();if(e===null)return n.warn("could not reach the npm registry; try again later"),1;if(!u(e,this.currentVersion))return n.info(`already on the latest version (${this.currentVersion})`),0;if(!this.safeVersion.test(e))return n.error(`refusing to install unexpected version string: ${e}`),1;n.info(`upgrading ${this.currentVersion} -> ${e}...`),await this.stopCore();let t=`${this.npmCmd()} install -g ${this.packageName}@${e}`;try{y(t,{stdio:"inherit"})}catch{return n.error(`upgrade failed; run manually: ${this.npmCmd()} install -g ${this.packageName}@latest`),1}let o=this.resolveFreshEntrypoint();return o===null?(n.info(`upgraded to ${e}. run "jarvis --version" to confirm.`),0):(n.info("verifying the freshly installed jarvis..."),S(process.execPath,[o,"--version"],{stdio:"inherit"}).status!==0?(n.warn('upgrade installed but the fresh entrypoint exited abnormally; run "jarvis --version" to confirm'),0):(n.info(`upgraded to ${e}.`),0))}async stopCore(){return n.debug("stop-core hook: no daemon in v0.1; nothing to stop (proposal 0013 fills this in)"),Promise.resolve()}resolveFreshEntrypoint(){try{let e=y(`${this.npmCmd()} root -g`,{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim();if(!e)return null;let t=j(e,this.packageName,"dist","index.js");return $(t)?t:null}catch{return null}}};import{spawn as N}from"node:child_process";import{existsSync as A,readFileSync as O,writeFileSync as P}from"node:fs";import{mkdirSync as x}from"node:fs";import{homedir as C}from"node:os";import{join as w,resolve as V}from"node:path";var g=class{envOverride="JARVIS_HOME";dirName=".jarvis";dir(){let e=process.env[this.envOverride]?.trim();return e?V(e):w(C(),this.dirName)}resolve(...e){return w(this.dir(),...e)}ensureDir(){let e=this.dir();return x(e,{recursive:!0,mode:448}),e}},b=new g;var d=class{constructor(e,t=b){this.currentVersion=e;this.home=t}currentVersion;home;packageName="@neuvybe/jarvis";cacheFile="update-check.json";ttlMs=360*60*1e3;cachePath(){return this.home.resolve(this.cacheFile)}read(){let e=this.cachePath();if(!A(e))return null;try{let t=JSON.parse(O(e,"utf8"));return typeof t.lastCheckedAt=="number"&&typeof t.latestVersion=="string"?{lastCheckedAt:t.lastCheckedAt,latestVersion:t.latestVersion}:null}catch{return null}}write(e,t){let o={lastCheckedAt:t,latestVersion:e};try{this.home.ensureDir(),P(this.cachePath(),JSON.stringify(o))}catch{}}isStale(e){let t=this.read();return!t||e-t.lastCheckedAt>this.ttlMs}notice(){let e=this.read();return!e||!u(e.latestVersion,this.currentVersion)?null:L(`upgrade available: ${this.currentVersion} -> ${e.latestVersion} (run: jarvis upgrade)`)}refreshInBackground(){try{let e=this.cachePath();this.home.ensureDir();let t=`
3
3
  import { writeFileSync } from 'node:fs';
4
4
  try {
5
5
  const res = await fetch('https://registry.npmjs.org/${this.packageName}/latest', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neuvybe/jarvis",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Jarvis - a voice-first personal agent (CLI).",