aegisone 1.0.79 → 1.0.81

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # AEGISONE
2
2
 
3
- Product version: **1.0.79**
3
+ Product version: **1.0.81**
4
4
 
5
5
  One product, two faces: the terminal (`aegiscode`) and the window (`aegis-desktop`),
6
6
  reached through one command — `aegis` — and released as one version.
package/bin/aegis.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
  // SPDX-License-Identifier: AGPL-3.0-or-later
3
3
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
4
- "use strict";const fs=require("node:fs"),path=require("node:path"),{spawnSync:spawnSync,spawn:spawn}=require("node:child_process"),{decide:decide,FACE:FACE}=require("../src/dispatch.js"),WIN=require("../src/iface/window.js"),probes=require("../src/probes.js"),electronRepair=require("../src/electron-repair.js"),release=require("../src/release.js"),productHelp=require("../src/producthelp.js"),productUpdate=require("../src/productupdate.js"),EXIT_USAGE=2,PRODUCT=require("../package.json");function faceManifestPaths(e,t){const r=t||__dirname;return[path.join(r,"..","vendor",e.dir,"package.json"),path.join(r,"..","..",e.dir,"package.json")]}function readFaceVersions(e){return release.FACE_LINES.map(t=>{for(const r of faceManifestPaths(t,e))try{return{package:t.package,version:JSON.parse(fs.readFileSync(r,"utf8")).version,source:r}}catch{}return{package:t.package,version:null,source:null}})}function write(e,t){try{e.write(t.endsWith("\n")?t:t+"\n")}catch{}}function runUpdate(e,t,r){const n=t||{},{stdout:s,stderr:i,input:o}=r,a=void 0!==n.installed?n.installed:isInstalledLayout(n.binDir),c=n.updatePlan?n.updatePlan():productUpdate.plan({installed:a,env:o&&o.env||{}});if(!c.ok)return write(i,`aegis: ${c.msg}`),2;const u=n.fetchLatest||defaultFetchLatest(n.binDir);return productUpdate.check({current:PRODUCT.version,action:e.action},{fetchImpl:u}).then(t=>{for(const e of t.lines)write(s,e);if("apply"!==e.action)return!0===t.upToDate?0:1;const r=productUpdate.apply(c,t,{runImpl:n.runInstall||defaultRunInstall,spawnSpec:n.spawnSpec||defaultSpawnSpec(n.binDir)});if(r.ok){write(s,r.lines?r.lines[0]:"Installed.");for(const e of String(r.output||"").split("\n").slice(-6))e.trim()&&write(s,` ${e}`);return 0}return r.skipped?(write(s,` ${r.msg}`),!0===t.upToDate?0:1):(write(i,`aegis: ${r.msg||"the install failed"}`),r.error&&write(i,`aegis: ${r.error}`),r.command&&write(i,`aegis: run it yourself: ${r.command}`),3)})}function isInstalledLayout(e){const t=e||__dirname,r=path.join(t,"..");try{return!fs.existsSync(path.join(r,"..","one","package.json"))}catch{return!0}}function defaultFetchLatest(e){const t=e||__dirname,r=path.join(t,".."),n=[path.join(r,"client","update.js"),path.join(r,"vendor","cli","vendor","client","update.js")];for(const e of n)try{const t=require(e);if("function"==typeof t.fetchLatestDetailed)return e=>t.fetchLatestDetailed({...e||{},pkg:productUpdate.PRODUCT_PKG});if("function"==typeof t.fetchLatest)return e=>t.fetchLatest({...e||{},pkg:productUpdate.PRODUCT_PKG})}catch{}return null}function defaultSpawnSpec(e){const t=e||__dirname,r=path.join(t,".."),n=[path.join(r,"client","update.js"),path.join(r,"vendor","cli","vendor","client","update.js")],s={command:"npm",args:["i","-g",`${productUpdate.PRODUCT_PKG}@latest`]};for(const e of n)try{const t=require(e);if("function"==typeof t.installSpawn){const e=t.installSpawn(s,{env:process.env});if(e&&e.command)return e}}catch{}return null}function defaultRunInstall(e){try{const t=spawnSync(e.command,e.args,{encoding:"utf8",timeout:18e4,stdio:["ignore","pipe","pipe"],shell:!0===e.shell,windowsHide:!0});return t.error?{ok:!1,error:String(t.error.message||t.error)}:0!==t.status?{ok:!1,error:String((t.stderr||t.stdout||"").trim()||`exited ${t.status}`)}:{ok:!0,output:String(t.stdout||"")}}catch(e){return{ok:!1,error:String(e&&e.message||e)}}}const WINDOW_STDERR_NOISE=[/libva (error|warning)/i,/^libva:/i,/vaGetDriverNameByIndex|vaInitialize/,/gpu_init\.cc.*Passthrough is not supported/i,/gpu_persistent_cache\.cc.*Persistent cache error/i,/ERROR:gpu\/command_buffer\/service\/gles2_cmd_decoder/,/swiftshader|llvmpipe|MESA-LOADER|libGL error|DRI3|MESA-VULKAN/i,/^MESA-(VOID|DRI|LOADER)/,/vulkan.*(incomplete|not supported|failed)/i];function forwardWindowStderr(e,t){let r="";e.setEncoding("utf8"),e.on("data",e=>{r+=e;const n=r.split("\n");r=n.pop()||"";for(const e of n)e.trim()&&(WINDOW_STDERR_NOISE.some(t=>t.test(e))||write(t,e))});const n=()=>{r.trim()&&!WINDOW_STDERR_NOISE.some(e=>e.test(r))&&write(t,r),r=""};e.on("end",n),e.on("close",n),e.on("error",()=>{})}function statusOf(e){return"number"==typeof e.status?e.status:"SIGINT"===e.signal?130:"SIGTERM"===e.signal?143:1}function run(e,t){const r=t||{},n=r.stderr||process.stderr,s=r.stdout||process.stdout,i=r.repair||electronRepair.repairElectron;if(!r.input&&"function"==typeof i)try{i({})}catch{}const o=r.input||probes.collect({argv:e}),a=Array.isArray(e)?{...o,argv:e}:o,c=release.versionRequest(a.argv);if(c){const e=c.verbose?r.readFaceVersions?r.readFaceVersions():readFaceVersions(r.binDir):null;return write(s,release.renderVersion({product:{name:PRODUCT.name,version:PRODUCT.version},faces:e})),0}if((r.helpRequest||productHelp.helpRequest)(a.argv))return write(s,productHelp.renderHelp({version:PRODUCT.version})),0;const u=(r.updateRequest||productUpdate.updateRequest)(a.argv);if(u&&"help"===u.action)return write(s,productUpdate.renderUsage(PRODUCT.version)),0;if(u)return runUpdate(u,r,{stdout:s,stderr:n,input:a});const d=(a.argv||[]).indexOf("doctor");if(-1!==d&&!(a.argv||[]).slice(0,d).some(e=>!e.startsWith("-"))){const e=r.doctor||require("../src/doctor.js"),t=Object.assign({env:a.env,stdout:s,electron:a._electron||r.electron||null},r.doctorDeps||{}),n=e.main((a.argv||[]).slice(d+1),t);return"number"==typeof n?n:2}const p=decide(a);if(p.face===FACE.TUI&&!a._cliBin&&!r.cliBin)return write(n,"aegis: the terminal face is not installed beside aegisone."),write(n,"aegis: reinstall aegisone, or set AEGISONE_CLI_BIN to bin/aegiscode.js."),127;const l=r.permissions||require("../src/permissions.js"),f=(a.argv||[]).indexOf(l.SKIP_FLAG||"--dangerously-skip-permissions"),g=Boolean(a.tty&&a.tty.stdin&&a.tty.stdout),m=g?"interactive":"headless",h=r.stored||l.storedPermissionFacts(r.storedOpts||{}),w=l.resolvePosture({rules:void 0!==r.rules?r.rules:h.rules,gate:void 0!==r.gate?r.gate:h.confirmationsOn,permissionMode:void 0!==r.permissionMode?r.permissionMode:h.permissionMode,flag:-1!==f,env:a.env,interactive:g,childKind:m});w.warning&&write(n,`aegis: ${w.warning}`),w.skip&&w.skipFromFlag&&write(n,l.skipReport(w));const v=-1===f?p.args:p.args.filter(e=>e!==(l.SKIP_FLAG||"--dangerously-skip-permissions")),S=w.skipFromFlag?{AEGISONE_SKIP_PERMISSIONS:"1"}:{},I={AEGIS_INSTALL_METHOD:"npm"};if("1"===(a.env||{}).AEGISONE_PRINT_DECISION&&write(n,"aegis: decision "+JSON.stringify({face:p.face,kind:p.kind,reason:p.reason,args:v,skip:w.skip})),null===p.face)return write(n,`aegis: ${p.error}`),p.hint&&write(n,`aegis: ${p.hint}`),p.code||2;p.notice&&write(n,`aegis: ${p.notice} — running the terminal face.`);const _=r.spawnSync||spawnSync,O=r.spawn||spawn,E=Object.assign({},process.env,r.env||{});if(p.face===FACE.TUI){const e=a._cliBin||r.cliBin;return e?statusOf(_(process.execPath,[e,...v],{stdio:"inherit",env:Object.assign({},E,S,I),argv0:"aegiscode"})||{}):(write(n,"aegis: the terminal face is not installed beside aegisone."),write(n,"aegis: reinstall aegisone, or set AEGISONE_CLI_BIN to bin/aegiscode.js."),127)}const y=a._electron||r.electron,R=a._desktopMain||r.desktopMain,k=WIN.plan({decision:p,electron:Boolean(y),target:r.target||a.target});if(!k||!R)return write(n,"aegis: cannot open the window — Electron or the desktop entry point went missing after the check."),write(n,"aegis: Use --tui for the terminal face."),2;delete E.ELECTRON_RUN_AS_NODE;const j=WIN.open(k,{main:R,args:v,env:Object.assign({},E,S,I)},{openElectron:e=>{const t=O(process.execPath,[e.main,...e.args],{stdio:["ignore","ignore","pipe"],env:e.env,detached:!1});return t&&t.stderr&&forwardWindowStderr(t.stderr,n),t}});if(!j||!j.ok)return write(n,`aegis: cannot open the window — ${j&&j.msg||"no usable window plan"}.`),write(n,"aegis: Use --tui for the terminal face."),2;const D=j.handle;return new Promise(e=>{D.on("error",t=>{write(n,`aegis: could not start the window: ${t&&t.message}`),e(1)}),D.on("exit",(t,r)=>e(statusOf({status:t,signal:r})))})}function main(e){const t=run(e);return"number"==typeof t?(process.exitCode=t,t):t.then(e=>(process.exitCode=e,e))}if(module.exports={main:main,run:run,statusOf:statusOf,EXIT_USAGE:2,isInstalledLayout:isInstalledLayout,defaultFetchLatest:defaultFetchLatest},require.main===module){const e=main(process.argv.slice(2));e&&"function"==typeof e.then&&e.catch(e=>{write(process.stderr,`aegis: ${e&&e.stack||e}`),process.exitCode=1})}
4
+ "use strict";const fs=require("node:fs"),path=require("node:path"),{spawnSync:spawnSync,spawn:spawn}=require("node:child_process"),{decide:decide,FACE:FACE}=require("../src/dispatch.js"),WIN=require("../src/iface/window.js"),probes=require("../src/probes.js"),electronRepair=require("../src/electron-repair.js"),release=require("../src/release.js"),productHelp=require("../src/producthelp.js"),productUpdate=require("../src/productupdate.js"),EXIT_USAGE=2,PRODUCT=require("../package.json");function faceManifestPaths(e,t){const r=t||__dirname;return[path.join(r,"..","vendor",e.dir,"package.json"),path.join(r,"..","..",e.dir,"package.json")]}function readFaceVersions(e){return release.FACE_LINES.map(t=>{for(const r of faceManifestPaths(t,e))try{return{package:t.package,version:JSON.parse(fs.readFileSync(r,"utf8")).version,source:r}}catch{}return{package:t.package,version:null,source:null}})}function write(e,t){try{e.write(t.endsWith("\n")?t:t+"\n")}catch{}}function runUpdate(e,t,r){const n=t||{},{stdout:s,stderr:i,input:o}=r,a=void 0!==n.installed?n.installed:isInstalledLayout(n.binDir),c=n.updatePlan?n.updatePlan():productUpdate.plan({installed:a,env:o&&o.env||{}});if(!c.ok)return write(i,`aegis: ${c.msg}`),2;const d=n.fetchLatest||defaultFetchLatest(n.binDir);return productUpdate.check({current:PRODUCT.version,action:e.action},{fetchImpl:d}).then(t=>{for(const e of t.lines)write(s,e);if("apply"!==e.action)return!0===t.upToDate?0:1;const r=productUpdate.apply(c,t,{runImpl:n.runInstall||defaultRunInstall,spawnSpec:n.spawnSpec||defaultSpawnSpec(n.binDir)});if(r.ok){write(s,r.lines?r.lines[0]:"Installed.");for(const e of String(r.output||"").split("\n").slice(-6))e.trim()&&write(s,` ${e}`);return 0}return r.skipped?(write(s,` ${r.msg}`),!0===t.upToDate?0:1):(write(i,`aegis: ${r.msg||"the install failed"}`),r.error&&write(i,`aegis: ${r.error}`),r.command&&write(i,`aegis: run it yourself: ${r.command}`),3)})}function isInstalledLayout(e){const t=e||__dirname,r=path.join(t,"..");try{return!fs.existsSync(path.join(r,"..","one","package.json"))}catch{return!0}}function defaultFetchLatest(e){const t=e||__dirname,r=path.join(t,".."),n=[path.join(r,"client","update.js"),path.join(r,"vendor","cli","vendor","client","update.js")];for(const e of n)try{const t=require(e);if("function"==typeof t.fetchLatestDetailed)return e=>t.fetchLatestDetailed({...e||{},pkg:productUpdate.PRODUCT_PKG});if("function"==typeof t.fetchLatest)return e=>t.fetchLatest({...e||{},pkg:productUpdate.PRODUCT_PKG})}catch{}return null}function defaultSpawnSpec(e){const t=e||__dirname,r=path.join(t,".."),n=[path.join(r,"client","update.js"),path.join(r,"vendor","cli","vendor","client","update.js")],s={command:"npm",args:["i","-g",`${productUpdate.PRODUCT_PKG}@latest`]};for(const e of n)try{const t=require(e);if("function"==typeof t.installSpawn){const e=t.installSpawn(s,{env:process.env});if(e&&e.command)return e}}catch{}return null}function defaultRunInstall(e){try{const t=spawnSync(e.command,e.args,{encoding:"utf8",timeout:18e4,stdio:["ignore","pipe","pipe"],shell:!0===e.shell,windowsHide:!0});return t.error?{ok:!1,error:String(t.error.message||t.error)}:0!==t.status?{ok:!1,error:String((t.stderr||t.stdout||"").trim()||`exited ${t.status}`)}:{ok:!0,output:String(t.stdout||"")}}catch(e){return{ok:!1,error:String(e&&e.message||e)}}}const WINDOW_STDERR_NOISE=[/libva (error|warning)/i,/^libva:/i,/vaGetDriverNameByIndex|vaInitialize/,/gpu_init\.cc.*Passthrough is not supported/i,/gpu_persistent_cache\.cc.*Persistent cache error/i,/ERROR:gpu\/command_buffer\/service\/gles2_cmd_decoder/,/swiftshader|llvmpipe|MESA-LOADER|libGL error|DRI3|MESA-VULKAN/i,/^MESA-(VOID|DRI|LOADER)/,/vulkan.*(incomplete|not supported|failed)/i];function forwardWindowStderr(e,t){let r="";e.setEncoding("utf8"),e.on("data",e=>{r+=e;const n=r.split("\n");r=n.pop()||"";for(const e of n)e.trim()&&(WINDOW_STDERR_NOISE.some(t=>t.test(e))||write(t,e))});const n=()=>{r.trim()&&!WINDOW_STDERR_NOISE.some(e=>e.test(r))&&write(t,r),r=""};e.on("end",n),e.on("close",n),e.on("error",()=>{})}function statusOf(e){return"number"==typeof e.status?e.status:"SIGINT"===e.signal?130:"SIGTERM"===e.signal?143:1}function run(e,t){const r=t||{},n=r.stderr||process.stderr,s=r.stdout||process.stdout,i=r.repair||electronRepair.repairElectron;if(!r.input&&"function"==typeof i)try{i({})}catch{}const o=r.input||probes.collect({argv:e}),a=Array.isArray(e)?{...o,argv:e}:o,c=release.versionRequest(a.argv);if(c){const e=c.verbose?r.readFaceVersions?r.readFaceVersions():readFaceVersions(r.binDir):null;return write(s,release.renderVersion({product:{name:PRODUCT.name,version:PRODUCT.version},faces:e})),0}if((r.helpRequest||productHelp.helpRequest)(a.argv))return write(s,productHelp.renderHelp({version:PRODUCT.version})),0;const d=(r.updateRequest||productUpdate.updateRequest)(a.argv);if(d&&"help"===d.action)return write(s,productUpdate.renderUsage(PRODUCT.version)),0;if(d)return runUpdate(d,r,{stdout:s,stderr:n,input:a});const p=(a.argv||[]).indexOf("doctor");if(-1!==p&&!(a.argv||[]).slice(0,p).some(e=>!e.startsWith("-"))){const e=r.doctor||require("../src/doctor.js"),t=Object.assign({env:a.env,stdout:s,electron:a._electron||r.electron||null,appBundle:a._appBundle||r.appBundle||null},r.doctorDeps||{}),n=e.main((a.argv||[]).slice(p+1),t);return"number"==typeof n?n:2}const u=decide(a);if(u.face===FACE.TUI&&!a._cliBin&&!r.cliBin)return write(n,"aegis: the terminal face is not installed beside aegisone."),write(n,"aegis: reinstall aegisone, or set AEGISONE_CLI_BIN to bin/aegiscode.js."),127;const l=r.permissions||require("../src/permissions.js"),f=(a.argv||[]).indexOf(l.SKIP_FLAG||"--dangerously-skip-permissions"),g=Boolean(a.tty&&a.tty.stdin&&a.tty.stdout),m=g?"interactive":"headless",h=r.stored||l.storedPermissionFacts(r.storedOpts||{}),w=l.resolvePosture({rules:void 0!==r.rules?r.rules:h.rules,gate:void 0!==r.gate?r.gate:h.confirmationsOn,permissionMode:void 0!==r.permissionMode?r.permissionMode:h.permissionMode,flag:-1!==f,env:a.env,interactive:g,childKind:m});w.warning&&write(n,`aegis: ${w.warning}`),w.skip&&w.skipFromFlag&&write(n,l.skipReport(w));const v=-1===f?u.args:u.args.filter(e=>e!==(l.SKIP_FLAG||"--dangerously-skip-permissions")),S=w.skipFromFlag?{AEGISONE_SKIP_PERMISSIONS:"1"}:{},I={AEGIS_INSTALL_METHOD:"npm"};if("1"===(a.env||{}).AEGISONE_PRINT_DECISION&&write(n,"aegis: decision "+JSON.stringify({face:u.face,kind:u.kind,reason:u.reason,args:v,skip:w.skip})),null===u.face)return write(n,`aegis: ${u.error}`),u.hint&&write(n,`aegis: ${u.hint}`),u.code||2;u.notice&&write(n,`aegis: ${u.notice} — running the terminal face.`);const _=r.spawnSync||spawnSync,O=r.spawn||spawn,E=Object.assign({},process.env,r.env||{});if(u.face===FACE.TUI){const e=a._cliBin||r.cliBin;return e?statusOf(_(process.execPath,[e,...v],{stdio:"inherit",env:Object.assign({},E,S,I),argv0:"aegiscode"})||{}):(write(n,"aegis: the terminal face is not installed beside aegisone."),write(n,"aegis: reinstall aegisone, or set AEGISONE_CLI_BIN to bin/aegiscode.js."),127)}const y=a._electron||r.electron,R=a._desktopMain||r.desktopMain,k=a._appBundle||r.appBundle||null,j=WIN.plan({decision:u,electron:Boolean(y)||Boolean(k),target:r.target||a.target});if(!j||!R&&!k)return write(n,"aegis: cannot open the window — Electron or the desktop entry point went missing after the check."),write(n,"aegis: Use --tui for the terminal face."),2;delete E.ELECTRON_RUN_AS_NODE;const D=WIN.open(j,{main:R,args:v,env:Object.assign({},E,S,I)},{openElectron:e=>{if(k){const t=O(k,e.args||[],{stdio:["ignore","ignore","pipe"],env:e.env,detached:!1});return t&&t.stderr&&forwardWindowStderr(t.stderr,n),t}const t=O(process.execPath,[e.main,...e.args],{stdio:["ignore","ignore","pipe"],env:e.env,detached:!1});return t&&t.stderr&&forwardWindowStderr(t.stderr,n),t}});if(!D||!D.ok)return write(n,`aegis: cannot open the window — ${D&&D.msg||"no usable window plan"}.`),write(n,"aegis: Use --tui for the terminal face."),2;const U=D.handle;return new Promise(e=>{U.on("error",t=>{write(n,`aegis: could not start the window: ${t&&t.message}`),e(1)}),U.on("exit",(t,r)=>e(statusOf({status:t,signal:r})))})}function main(e){const t=run(e);return"number"==typeof t?(process.exitCode=t,t):t.then(e=>(process.exitCode=e,e))}if(module.exports={main:main,run:run,statusOf:statusOf,EXIT_USAGE:2,isInstalledLayout:isInstalledLayout,defaultFetchLatest:defaultFetchLatest},require.main===module){const e=main(process.argv.slice(2));e&&"function"==typeof e.then&&e.catch(e=>{write(process.stderr,`aegis: ${e&&e.stack||e}`),process.exitCode=1})}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "aegisone",
3
3
  "productName": "AEGISONE",
4
- "version": "1.0.79",
4
+ "version": "1.0.81",
5
5
  "description": "AEGISONE — one product, two faces. `aegis` opens the window when there is nothing else to do and runs the terminal otherwise; `aegiscode` keeps behaving exactly as it always has.",
6
6
  "author": {
7
7
  "name": "AEGIS Code",
package/src/dispatch.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
- "use strict";const FACE=Object.freeze({TUI:"tui",GUI:"gui"}),FACE_ENV="AEGISONE_FACE",TUI_VERBS=new Set(["login","connect","logout","key","mcp","fingerprint","gate","autonomous","permissions","doctor","update","models","config","init","signup","help","version","status","resume"]),SCRIPT_FLAGS=new Set(["-p","--print","--json"]),FORCE_GUI_FLAGS=["--gui"],FORCE_TUI_FLAGS=["--tui"],SPELLING_GUI="desktop",SPELLING_TUI="code";function flagIndex(e,t){for(let n=0;n<e.length;n++)if(t.includes(e[n]))return n;return-1}function without(e,t){return e.filter(e=>!t.includes(e))}function has(e,t){return e.some(e=>t.includes(e))}function guiBlockers(e,t){const n=[];return e||n.push("no display (DISPLAY / WAYLAND_DISPLAY are unset)"),t||n.push("Electron is not installed beside this package"),n}function decide(e){const t=e||{},n=Array.isArray(t.argv)?t.argv.map(String):[],i=t.env||{},s=t.tty||{},o=Boolean(t.hasDisplay),r=Boolean(t.electronResolvable),a=String(t.invokedAs||"aegis").replace(/\.js$/,""),l=guiBlockers(o,r),c=0===l.length,u=(e,t,n)=>({face:FACE.GUI,kind:e,reason:t,args:n,notice:null}),d=(e,t,n,i)=>({face:FACE.TUI,kind:e,reason:t,args:n,notice:i||null}),g=e=>({face:null,kind:"error",code:2,reason:`${e} cannot open the window`,error:`${e}: cannot open the window — ${l.join(", ")}.`,hint:"Use --tui for the terminal face.",args:[],notice:null});if("aegiscode"===a)return d("compat","aegiscode is the compatibility bin",n);const E=String(null==i[FACE_ENV]?"":i[FACE_ENV]).trim().toLowerCase();if(E)return E===FACE.GUI?c?u("forced",`${FACE_ENV}=gui`,n):g(`${FACE_ENV}=gui`):"cli"===E||E===FACE.TUI?d("forced",`${FACE_ENV}=${E}`,n):{face:null,kind:"error",code:2,reason:`${FACE_ENV}=${E} is not a face`,error:`${FACE_ENV}=${E} is not a face. Set cli or gui.`,hint:"Unset it to let aegis decide from the arguments.",args:[],notice:null};if(has(n,FORCE_GUI_FLAGS)){const e=without(n,FORCE_GUI_FLAGS);return c?u("explicit","--gui was passed",e):g("--gui")}if(has(n,FORCE_TUI_FLAGS))return d("explicit","--tui was passed",without(n,FORCE_TUI_FLAGS));const f=n.filter(e=>!e.startsWith("-")),p=f.length?f[0]:null;if("desktop"===p){const e=n.filter(e=>"desktop"!==e);return c?u("spelling","aegis desktop",e):g("aegis desktop")}if("code"===p)return d("spelling","aegis code",n.filter(e=>"code"!==e));const A=n.find(e=>SCRIPT_FLAGS.has(e));return A?d("script",`${A} means this call is a script`,n):p?d("argument",TUI_VERBS.has(p)?`'${p}' is a terminal verb`:`'${p}' is a prompt, not a window request`,n):n.length?d("flags","options were passed; the window takes none",n):!1===s.stdin||!1===s.stdout?d("default","stdio is not a terminal",[],"stdio is not a terminal"):l.length?d("default",l[0],[],l[0]):u("default","nothing else was asked for",[])}module.exports={decide:decide,FACE:FACE,FACE_ENV:FACE_ENV,TUI_VERBS:TUI_VERBS};
3
+ "use strict";const FACE=Object.freeze({TUI:"tui",GUI:"gui"}),FACE_ENV="AEGISONE_FACE",TUI_VERBS=new Set(["login","connect","logout","key","mcp","fingerprint","gate","autonomous","permissions","doctor","update","models","config","init","signup","help","version","status","resume"]),SCRIPT_FLAGS=new Set(["-p","--print","--json"]),FORCE_GUI_FLAGS=["--gui"],FORCE_TUI_FLAGS=["--tui"],SPELLING_GUI="desktop",SPELLING_TUI="code";function flagIndex(e,t){for(let n=0;n<e.length;n++)if(t.includes(e[n]))return n;return-1}function without(e,t){return e.filter(e=>!t.includes(e))}function has(e,t){return e.some(e=>t.includes(e))}function guiBlockers(e,t){const n=[];return e||n.push("no display (DISPLAY / WAYLAND_DISPLAY are unset)"),t||n.push("Electron is not installed beside this package"),n}function decide(e){const t=e||{},n=Array.isArray(t.argv)?t.argv.map(String):[],i=t.env||{},o=t.tty||{},s=Boolean(t.hasDisplay),r=Boolean(t.electronResolvable),a=String(t.invokedAs||"aegis").replace(/\.js$/,""),l=String(t.platform||""),c="darwin"===l||"win32"===l,u=Boolean(t.ci),d=guiBlockers(s,r),g=0===d.length,E=(e,t,n)=>({face:FACE.GUI,kind:e,reason:t,args:n,notice:null}),p=(e,t,n,i)=>({face:FACE.TUI,kind:e,reason:t,args:n,notice:i||null}),f=e=>({face:null,kind:"error",code:2,reason:`${e} cannot open the window`,error:`${e}: cannot open the window — ${d.join(", ")}.`,hint:"Use --tui for the terminal face.",args:[],notice:null});if("aegiscode"===a)return p("compat","aegiscode is the compatibility bin",n);const A=String(null==i[FACE_ENV]?"":i[FACE_ENV]).trim().toLowerCase();if(A)return A===FACE.GUI?g?E("forced",`${FACE_ENV}=gui`,n):f(`${FACE_ENV}=gui`):"cli"===A||A===FACE.TUI?p("forced",`${FACE_ENV}=${A}`,n):{face:null,kind:"error",code:2,reason:`${FACE_ENV}=${A} is not a face`,error:`${FACE_ENV}=${A} is not a face. Set cli or gui.`,hint:"Unset it to let aegis decide from the arguments.",args:[],notice:null};if(has(n,FORCE_GUI_FLAGS)){const e=without(n,FORCE_GUI_FLAGS);return g?E("explicit","--gui was passed",e):f("--gui")}if(has(n,FORCE_TUI_FLAGS))return p("explicit","--tui was passed",without(n,FORCE_TUI_FLAGS));const h=n.filter(e=>!e.startsWith("-")),F=h.length?h[0]:null;if("desktop"===F){const e=n.filter(e=>"desktop"!==e);return g?E("spelling","aegis desktop",e):f("aegis desktop")}if("code"===F)return p("spelling","aegis code",n.filter(e=>"code"!==e));const _=n.find(e=>SCRIPT_FLAGS.has(e));return _?p("script",`${_} means this call is a script`,n):F?p("argument",TUI_VERBS.has(F)?`'${F}' is a terminal verb`:`'${F}' is a prompt, not a window request`,n):n.length?p("flags","options were passed; the window takes none",n):!1===o.stdin||!1===o.stdout?c&&!u&&g?E("launcher","a desktop launch on a platform that always has a display",[]):p("default","stdio is not a terminal",[],"stdio is not a terminal"):d.length?p("default",d[0],[],d[0]):E("default","nothing else was asked for",[])}module.exports={decide:decide,FACE:FACE,FACE_ENV:FACE_ENV,TUI_VERBS:TUI_VERBS};
package/src/doctor.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
- "use strict";const path=require("node:path"),fs=require("node:fs"),crypto=require("node:crypto"),EXIT=Object.freeze({OK:0,WARN:1,BROKEN:2}),FACE_PACKAGES=Object.freeze([Object.freeze({dir:"cli",package:"aegiscode"}),Object.freeze({dir:"desktop",package:"aegis-desktop"})]),BUNDLE_FACES=Object.freeze([Object.freeze({face:"cli",root:"cli",staged:"one/vendor/cli"}),Object.freeze({face:"desktop",root:"desktop",staged:"one/vendor/desktop"})]);function oneDir(){return path.resolve(__dirname,"..")}function repoDir(){return path.resolve(__dirname,"..","..")}function layoutOf(e,t){const n=t=>{try{return Boolean(e.exists(t))}catch{return!1}};if(t){const e=!n(path.join(t,"one","package.json"));return{root:t,installed:e,facePrefix:e?["vendor"]:[]}}const r=repoDir(),o=!n(path.join(r,"one","package.json"));return{root:o?oneDir():r,installed:o,facePrefix:o?["vendor"]:[]}}function inLayout(e,t){if(!e.installed)return t;const n=t.split("/");if("one"===n[0]){const e=n.slice(1).join("/");return"src/selfhost.js"===e?"vendor/desktop/vendor/selfhost.js":("vendor/cli"===e||e.startsWith("vendor/"),e)}return"cli"===n[0]||"desktop"===n[0]?path.posix.join("vendor",t).split(path.sep).join("/"):path.posix.join("vendor","cli","vendor",t).split(path.sep).join("/")}function homeHint(e){const t=e||{};return t.AEGISCODE_HOME||t.AEGIS_HOME||null}function homeDir(e){try{return require("./host.js").hostHome(e||{})}catch{const t=e||{},n=t.USERPROFILE||t.HOME;return n?String(n).trim():""}}function defaultFs(){return{exists:e=>{try{return fs.existsSync(e)}catch{return!1}},readFile:e=>{try{return fs.readFileSync(e,"utf8")}catch(e){if(e&&("ENOENT"===e.code||"EISDIR"===e.code))return null;throw e}},hashFile:e=>crypto.createHash("sha256").update(fs.readFileSync(e)).digest("hex"),listFiles:(e,t)=>listFiles(e,void 0===t?e:t)}}function listFiles(e,t){const n=[],r=e=>{let o;try{o=fs.readdirSync(e,{withFileTypes:!0})}catch{return}for(const s of o){if("node_modules"===s.name||".git"===s.name)continue;const o=path.join(e,s.name);s.isDirectory()?r(o):n.push(path.relative(t,o).split(path.sep).join("/"))}};return r(e),n.sort()}function defaultElectronPaths(e,t){const n=t||{},r=homeHint(e)||path.join(homeDir(e),".aegiscode");return{electron:void 0!==n.electron?n.electron:null,desktopMain:void 0!==n.desktopMain?n.desktopMain:null,userData:void 0!==n.userData?n.userData:r,keychain:void 0!==n.keychain?n.keychain:path.join(r,"settings.json")}}function defaultRegistry(e){let t=null;const n=()=>{if(t)return t;const n=e&&e.layout?e.layout:{root:repoDir(),installed:!1},r=[path.join(n.root,"client","update.js"),path.join(n.root,"vendor","cli","vendor","client","update.js")];for(const e of r)try{t=require(e);break}catch{}return t};return{check(e){const t=n();return t&&"function"==typeof t.updateNotice?t.updateNotice(e||{}):{latest:null,behind:!1,reason:"unavailable"}},plan(e){const t=n();return t&&"function"==typeof t.updatePlan?t.updatePlan(e||{}):null}}}function clientModuleCandidates(e){return[path.join(e.root,"client"),path.join(e.root,"vendor","cli","vendor","client")]}function loadClientModule(e,t){const n=e&&e.layout?e.layout:{root:repoDir(),installed:!1};for(const e of clientModuleCandidates(n))try{return require(path.join(e,t))}catch{}return null}function defaultStorePath(e,t){try{const n=loadClientModule(t,"prefs.js");if(n&&"function"==typeof n.prefsFile)return n.prefsFile(e)}catch{}const n=homeHint(e)||path.join(homeDir(e),".aegiscode");return path.join(n,"preferences.json")}function defaultCredentials(e){let t=null,n=!1;return{resolve(r){if(n||(n=!0,t=loadClientModule(e,"credentials.js")),!t||"function"!=typeof t.resolveApiKey)return{key:"",source:"none",from:""};try{return t.resolveApiKey(r||{})}catch{return{key:"",source:"none",from:""}}}}}function vendorPairs(e){const{exists:t}=e,n=[];if((e.layout||{installed:!1,facePrefix:[]}).installed)return n;for(const{face:r,root:o,staged:s}of BUNDLE_FACES){const a=path.join(e.root,s),i=e.listFiles(a,a);for(const a of i){const i=[];if(a.startsWith("vendor/")){const e=a.slice(7);if(i.push(e),i.push(path.join(o,e)),"selfhost.js"===e&&i.push(path.join("one","src","selfhost.js")),"protocol.js"===e&&i.push(path.join("one","src","protocol.js")),"pty.js"===e&&i.push(path.join("one","src","iface","pty.js")),"desktop"===r){const t=path.basename(e);for(const e of["client","mcp","covenant","commands","skills","tools","hosts"])i.push(path.join(e,t));i.push(t)}}else i.push(path.join(o,a)),i.push(a);const l=i.find(n=>t(path.join(e.root,n)))||null;n.push({face:r,staged:path.join(s,a),source:l,candidates:i})}}return n}function layoutsInstalled(e){return Boolean(e&&e.installed)}function checkVendor(e,t){const n=t||vendorPairs(e),r=[],o=[];let s=0,a=0;const i=e.layout||{installed:!1,facePrefix:[]};if(layoutsInstalled(i)){for(const t of BUNDLE_FACES){const n=path.join(e.root,inLayout(i,t.staged));e.exists(n)&&(a+=e.listFiles(n,n).length)}return{staged:a,matched:0,mismatch:o,missingSource:r,stale:0===a,checked:0}}for(const t of n){if(!e.exists(path.join(e.root,t.staged)))continue;if(a+=1,!t.source){r.push(t.staged);continue}let n,i;try{n=e.hashFile(path.join(e.root,t.source)),i=e.hashFile(path.join(e.root,t.staged))}catch(e){o.push({staged:t.staged,source:t.source,error:String(e&&e.message||e)});continue}n===i?s+=1:o.push({staged:t.staged,source:t.source})}return{staged:a,matched:s,mismatch:o,missingSource:r,stale:n.length>0&&0===a,checked:n.length}}function readJson(e,t){const n=path.join(e.root,t);if(!e.exists(n))return{ok:!1,missing:!0,value:null,path:t};let r;try{r=e.readFile(n)}catch(e){return{ok:!1,unreadable:!0,value:null,path:t,error:String(e&&e.message||e)}}if(null==r)return{ok:!1,missing:!0,value:null,path:t};try{return{ok:!0,value:JSON.parse(r),path:t}}catch(e){return{ok:!1,unreadable:!0,value:null,path:t,error:String(e&&e.message||e)}}}function resolveSeams(e){const t=e||{},n=t.env||{},r=defaultFs(),o=t||{},s=o.exists||r.exists,a=t.layout||layoutOf({exists:s,root:t.root},t.root),i=t.root||a.root,l={root:i,layout:Object.assign({},a,{root:i}),platform:t.platform||"linux",env:n,exists:s,readFile:o.readFile||r.readFile,hashFile:o.hashFile||r.hashFile,listFiles:o.listFiles||r.listFiles,electronPaths:t.electronPaths||defaultElectronPaths(n,t),updateCache:t.updateCache,saveUpdateCache:t.saveUpdateCache,now:"number"==typeof t.now?t.now:0,guiRequested:Boolean(t.guiRequested),guiImplied:t.guiImplied,vendorPairs:t.vendorPairs};return l.credentials=t.credentials||defaultCredentials(l),l.storePath=t.storePath||defaultStorePath(n,l),l.registry=t.registry||defaultRegistry(l),l}function diagnose(e){const t=resolveSeams(e),n=[],r=(e,t)=>n.push({level:"broken",code:e,detail:t}),o=(e,t)=>n.push({level:"warn",code:e,detail:t}),s=t.layout,a=inLayout(s,"one/package.json"),i=readJson(t,a),l=i.ok?{name:i.value.name||"aegisone",version:String(i.value.version||"")}:{name:"aegisone",version:""};i.ok||r("product-unreadable",`${a} ${i.unreadable?"is unreadable":"is missing"}`);let c=null;try{c=require("./release.js").deriveFaceVersions(l.version)}catch(e){c=null,i.ok&&r("product-version-invalid",`${l.version}: ${String(e&&e.message||e)}`)}const u={};for(const{dir:e,package:n}of FACE_PACKAGES){const o=inLayout(s,`${e}/package.json`),a=readJson(t,o),i=a.ok?String(a.value.version||""):"",d=c&&c[n]?c[n].version:null;a.ok?d&&i!==d&&r("version-mismatch",`${n} is ${i}, product ${l.version} derives ${d}`):r("face-unreadable",`${o} ${a.unreadable?"is unreadable":"is missing"}`),u[n]={dir:e,version:i,expected:d,ok:Boolean(d&&i===d)}}let d={key:"",source:"none",from:""};try{d=t.credentials.resolve({env:t.env})||d}catch{d={key:"",source:"none",from:""}}const h=t.electronPaths||{};let p=d.key?"env"===d.source?"env":(d.source,"env-file"):"none";if(!d.key&&h.keychain&&t.exists(h.keychain)){const e=(()=>{try{return t.readFile(h.keychain)}catch{return null}})();e&&/encrypt|safeStorage/i.test(e)&&(p="keychain")}"none"===p&&o("no-credential","no credential found (env, credentials.json, or the OS keychain)");const f={path:t.storePath,exists:!1,readable:null,legacy:null};try{f.exists=t.exists(t.storePath)}catch{f.exists=!1}let g,v=f.path;if(f.exists){let e=null;try{e=t.readFile(f.path)}catch(e){f.readable=!1,r("store-unreadable",`${f.path}: ${String(e&&e.message||e)}`)}if(null===f.readable)if(null==e)f.readable=!1,r("store-unreadable",`${f.path} exists but could not be read`);else try{const t=JSON.parse(e);f.readable=!0,f.legacy=t&&t.version||null}catch(e){f.readable=!1,r("store-unreadable",`${f.path} is not valid JSON: ${String(e&&e.message||e)}`)}v=path.basename(f.path)}f.display=v;try{g=checkVendor(t,t.vendorPairs)}catch(e){g={staged:0,matched:0,mismatch:[],missingSource:[],stale:!1,checked:0,error:String(e&&e.message||e)},r("vendor-unreadable",g.error)}for(const e of g.mismatch)r("vendor-hash-mismatch",`${e.staged} differs from ${e.source||"its source"}`);for(const e of g.missingSource)r("vendor-source-missing",`${e} has no source to be re-derived from`);g.stale&&(s.installed?r("vendor-missing","the ONE bundle is empty — reinstall aegisone"):o("vendor-stale","the ONE bundle has never been staged (one/vendor is empty) — run `npm run predist`"));const m={channel:"npm",current:l.version,latest:null,behind:!1,reason:null,checkedAt:null,cached:!0,action:"none",applier:"npm",instruction:null};try{const e=t.registry.check({current:l.version,cache:t.updateCache,save:t.saveUpdateCache,now:t.now})||{};m.latest=e.latest||null,m.behind=Boolean(e.behind),m.reason=e.reason||null}catch(e){m.reason="unavailable",m.error=String(e&&e.message||e)}try{const e=t.registry.plan({current:l.version,latest:m.latest,behind:m.behind});e&&(m.action=e.action,m.applier=e.applier,m.instruction=e.instruction)}catch{}m.behind&&o("update-available",`${m.current} → ${m.latest} (${m.instruction||"run the channel updater"})`);const y=h&&h.electron||null;t.guiRequested&&!y&&r("gui-without-electron","--gui was requested but Electron is not installed — use --tui");const b=n.filter(e=>"broken"===e.level).length,j=n.filter(e=>"warn"===e.level).length,k=b?EXIT.BROKEN:j?EXIT.WARN:EXIT.OK;return{report:{aegis:"one",status:b?"broken":j?"warn":"healthy",exitCode:k,product:l,faces:u,credential:{source:p,found:Boolean(d.key),from:d.key?d.from:""},store:{path:f.path,exists:f.exists,readable:f.exists?!0===f.readable:null},vendor:{staged:g.staged,matched:g.matched,mismatched:g.mismatch.length,missingSource:g.missingSource.length,stale:g.stale,verifiable:!s.installed},update:m,gui:{requested:Boolean(t.guiRequested),electron:y||null,usable:Boolean(y)&&(!t.guiImplied||t.guiImplied)},problems:n},code:k}}function render(e){const t=[],n=(e,t)=>String(e)+" ".repeat(Math.max(0,t-String(e).length));t.push(`aegis doctor — ${e.status} (exit ${e.exitCode})`),t.push(` product ${e.product.name} ${e.product.version}`);for(const[r,o]of Object.entries(e.faces)){const e=o.ok?"":` (expected ${o.expected||"unknown"})`;t.push(` ${n(r,14)} ${o.version||"unknown"}${e}`)}t.push(` credential ${e.credential.source}`),t.push(` shared store ${e.store.path} ${e.store.exists?e.store.readable?"(readable)":"(unreadable)":"(absent)"}`),t.push(!1===e.vendor.verifiable?` vendor ${e.vendor.staged} staged (sources not shipped — not re-derivable here)`:` vendor ${e.vendor.staged} staged, ${e.vendor.matched} matching, ${e.vendor.mismatched} mismatched, ${e.vendor.missingSource} without a source`+(e.vendor.stale?" (never staged)":""));const r=e.update;if(t.push(" update "+(r.behind?`${r.current} → ${r.latest}`:`${r.current} is current`)+` (next: ${r.action}${r.instruction?` — ${r.instruction}`:""})`),t.push(" window face "+(e.gui.electron?`Electron at ${e.gui.electron}`:"not installed")),e.problems.length){t.push(" problems:");for(const n of e.problems)t.push(` ${"broken"===n.level?"✗":"!"} ${n.code}: ${n.detail}`)}return t.join("\n")+"\n"}function wantsGui(e,t){return!!(Array.isArray(e)?e:[]).includes("--gui")||"gui"===(t||{}).AEGISONE_FACE}function main(e,t){const n=t||{},r=Array.isArray(e)?e:[],o=n.stdout||process.stdout,s=n.env||process.env||{},a=Object.assign({},n,{env:s,guiRequested:wantsGui(r,s)}),{report:i,code:l}=diagnose(a),c=r.includes("--json")?JSON.stringify(i)+"\n":render(i);try{o.write(c)}catch{}return l}module.exports={EXIT:EXIT,FACE_PACKAGES:FACE_PACKAGES,wantsGui:wantsGui,diagnose:diagnose,render:render,main:main,vendorPairs:vendorPairs,resolveSeams:resolveSeams},require.main===module&&(process.exitCode=main(process.argv.slice(2)));
3
+ "use strict";const path=require("node:path"),fs=require("node:fs"),crypto=require("node:crypto"),EXIT=Object.freeze({OK:0,WARN:1,BROKEN:2}),FACE_PACKAGES=Object.freeze([Object.freeze({dir:"cli",package:"aegiscode"}),Object.freeze({dir:"desktop",package:"aegis-desktop"})]),BUNDLE_FACES=Object.freeze([Object.freeze({face:"cli",root:"cli",staged:"one/vendor/cli"}),Object.freeze({face:"desktop",root:"desktop",staged:"one/vendor/desktop"})]);function oneDir(){return path.resolve(__dirname,"..")}function repoDir(){return path.resolve(__dirname,"..","..")}function layoutOf(e,t){const n=t=>{try{return Boolean(e.exists(t))}catch{return!1}};if(t){const e=!n(path.join(t,"one","package.json"));return{root:t,installed:e,facePrefix:e?["vendor"]:[]}}const o=repoDir(),r=!n(path.join(o,"one","package.json"));return{root:r?oneDir():o,installed:r,facePrefix:r?["vendor"]:[]}}function inLayout(e,t){if(!e.installed)return t;const n=t.split("/");if("one"===n[0]){const e=n.slice(1).join("/");return"src/selfhost.js"===e?"vendor/desktop/vendor/selfhost.js":("vendor/cli"===e||e.startsWith("vendor/"),e)}return"cli"===n[0]||"desktop"===n[0]?path.posix.join("vendor",t).split(path.sep).join("/"):path.posix.join("vendor","cli","vendor",t).split(path.sep).join("/")}function homeHint(e){const t=e||{};return t.AEGISCODE_HOME||t.AEGIS_HOME||null}function homeDir(e){try{return require("./host.js").hostHome(e||{})}catch{const t=e||{},n=t.USERPROFILE||t.HOME;return n?String(n).trim():""}}function defaultFs(){return{exists:e=>{try{return fs.existsSync(e)}catch{return!1}},readFile:e=>{try{return fs.readFileSync(e,"utf8")}catch(e){if(e&&("ENOENT"===e.code||"EISDIR"===e.code))return null;throw e}},hashFile:e=>crypto.createHash("sha256").update(fs.readFileSync(e)).digest("hex"),listFiles:(e,t)=>listFiles(e,void 0===t?e:t)}}function listFiles(e,t){const n=[],o=e=>{let r;try{r=fs.readdirSync(e,{withFileTypes:!0})}catch{return}for(const s of r){if("node_modules"===s.name||".git"===s.name)continue;const r=path.join(e,s.name);s.isDirectory()?o(r):n.push(path.relative(t,r).split(path.sep).join("/"))}};return o(e),n.sort()}function defaultElectronPaths(e,t){const n=t||{},o=homeHint(e)||path.join(homeDir(e),".aegiscode");return{electron:void 0!==n.electron?n.electron:null,appBundle:void 0!==n.appBundle?n.appBundle:null,desktopMain:void 0!==n.desktopMain?n.desktopMain:null,userData:void 0!==n.userData?n.userData:o,keychain:void 0!==n.keychain?n.keychain:path.join(o,"settings.json")}}function defaultRegistry(e){let t=null;const n=()=>{if(t)return t;const n=e&&e.layout?e.layout:{root:repoDir(),installed:!1},o=[path.join(n.root,"client","update.js"),path.join(n.root,"vendor","cli","vendor","client","update.js")];for(const e of o)try{t=require(e);break}catch{}return t};return{check(e){const t=n();return t&&"function"==typeof t.updateNotice?t.updateNotice(e||{}):{latest:null,behind:!1,reason:"unavailable"}},plan(e){const t=n();return t&&"function"==typeof t.updatePlan?t.updatePlan(e||{}):null}}}function clientModuleCandidates(e){return[path.join(e.root,"client"),path.join(e.root,"vendor","cli","vendor","client")]}function loadClientModule(e,t){const n=e&&e.layout?e.layout:{root:repoDir(),installed:!1};for(const e of clientModuleCandidates(n))try{return require(path.join(e,t))}catch{}return null}function defaultStorePath(e,t){try{const n=loadClientModule(t,"prefs.js");if(n&&"function"==typeof n.prefsFile)return n.prefsFile(e)}catch{}const n=homeHint(e)||path.join(homeDir(e),".aegiscode");return path.join(n,"preferences.json")}function defaultCredentials(e){let t=null,n=!1;return{resolve(o){if(n||(n=!0,t=loadClientModule(e,"credentials.js")),!t||"function"!=typeof t.resolveApiKey)return{key:"",source:"none",from:""};try{return t.resolveApiKey(o||{})}catch{return{key:"",source:"none",from:""}}}}}function vendorPairs(e){const{exists:t}=e,n=[];if((e.layout||{installed:!1,facePrefix:[]}).installed)return n;for(const{face:o,root:r,staged:s}of BUNDLE_FACES){const a=path.join(e.root,s),i=e.listFiles(a,a);for(const a of i){const i=[];if(a.startsWith("vendor/")){const e=a.slice(7);if(i.push(e),i.push(path.join(r,e)),"selfhost.js"===e&&i.push(path.join("one","src","selfhost.js")),"protocol.js"===e&&i.push(path.join("one","src","protocol.js")),"pty.js"===e&&i.push(path.join("one","src","iface","pty.js")),"desktop"===o){const t=path.basename(e);for(const e of["client","mcp","covenant","commands","skills","tools","hosts"])i.push(path.join(e,t));i.push(t)}}else i.push(path.join(r,a)),i.push(a);const l=i.find(n=>t(path.join(e.root,n)))||null;n.push({face:o,staged:path.join(s,a),source:l,candidates:i})}}return n}function layoutsInstalled(e){return Boolean(e&&e.installed)}function checkVendor(e,t){const n=t||vendorPairs(e),o=[],r=[];let s=0,a=0;const i=e.layout||{installed:!1,facePrefix:[]};if(layoutsInstalled(i)){for(const t of BUNDLE_FACES){const n=path.join(e.root,inLayout(i,t.staged));e.exists(n)&&(a+=e.listFiles(n,n).length)}return{staged:a,matched:0,mismatch:r,missingSource:o,stale:0===a,checked:0}}for(const t of n){if(!e.exists(path.join(e.root,t.staged)))continue;if(a+=1,!t.source){o.push(t.staged);continue}let n,i;try{n=e.hashFile(path.join(e.root,t.source)),i=e.hashFile(path.join(e.root,t.staged))}catch(e){r.push({staged:t.staged,source:t.source,error:String(e&&e.message||e)});continue}n===i?s+=1:r.push({staged:t.staged,source:t.source})}return{staged:a,matched:s,mismatch:r,missingSource:o,stale:n.length>0&&0===a,checked:n.length}}function readJson(e,t){const n=path.join(e.root,t);if(!e.exists(n))return{ok:!1,missing:!0,value:null,path:t};let o;try{o=e.readFile(n)}catch(e){return{ok:!1,unreadable:!0,value:null,path:t,error:String(e&&e.message||e)}}if(null==o)return{ok:!1,missing:!0,value:null,path:t};try{return{ok:!0,value:JSON.parse(o),path:t}}catch(e){return{ok:!1,unreadable:!0,value:null,path:t,error:String(e&&e.message||e)}}}function resolveSeams(e){const t=e||{},n=t.env||{},o=defaultFs(),r=t||{},s=r.exists||o.exists,a=t.layout||layoutOf({exists:s,root:t.root},t.root),i=t.root||a.root,l={root:i,layout:Object.assign({},a,{root:i}),platform:t.platform||"linux",env:n,exists:s,readFile:r.readFile||o.readFile,hashFile:r.hashFile||o.hashFile,listFiles:r.listFiles||o.listFiles,electronPaths:t.electronPaths||defaultElectronPaths(n,t),updateCache:t.updateCache,saveUpdateCache:t.saveUpdateCache,now:"number"==typeof t.now?t.now:0,guiRequested:Boolean(t.guiRequested),guiImplied:t.guiImplied,vendorPairs:t.vendorPairs};return l.credentials=t.credentials||defaultCredentials(l),l.storePath=t.storePath||defaultStorePath(n,l),l.registry=t.registry||defaultRegistry(l),l}function diagnose(e){const t=resolveSeams(e),n=[],o=(e,t)=>n.push({level:"broken",code:e,detail:t}),r=(e,t)=>n.push({level:"warn",code:e,detail:t}),s=t.layout,a=inLayout(s,"one/package.json"),i=readJson(t,a),l=i.ok?{name:i.value.name||"aegisone",version:String(i.value.version||"")}:{name:"aegisone",version:""};i.ok||o("product-unreadable",`${a} ${i.unreadable?"is unreadable":"is missing"}`);let c=null;try{c=require("./release.js").deriveFaceVersions(l.version)}catch(e){c=null,i.ok&&o("product-version-invalid",`${l.version}: ${String(e&&e.message||e)}`)}const u={};for(const{dir:e,package:n}of FACE_PACKAGES){const r=inLayout(s,`${e}/package.json`),a=readJson(t,r),i=a.ok?String(a.value.version||""):"",d=c&&c[n]?c[n].version:null;a.ok?d&&i!==d&&o("version-mismatch",`${n} is ${i}, product ${l.version} derives ${d}`):o("face-unreadable",`${r} ${a.unreadable?"is unreadable":"is missing"}`),u[n]={dir:e,version:i,expected:d,ok:Boolean(d&&i===d)}}let d={key:"",source:"none",from:""};try{d=t.credentials.resolve({env:t.env})||d}catch{d={key:"",source:"none",from:""}}const h=t.electronPaths||{};let p=d.key?"env"===d.source?"env":(d.source,"env-file"):"none";if(!d.key&&h.keychain&&t.exists(h.keychain)){const e=(()=>{try{return t.readFile(h.keychain)}catch{return null}})();e&&/encrypt|safeStorage/i.test(e)&&(p="keychain")}"none"===p&&r("no-credential","no credential found (env, credentials.json, or the OS keychain)");const f={path:t.storePath,exists:!1,readable:null,legacy:null};try{f.exists=t.exists(t.storePath)}catch{f.exists=!1}let g,v=f.path;if(f.exists){let e=null;try{e=t.readFile(f.path)}catch(e){f.readable=!1,o("store-unreadable",`${f.path}: ${String(e&&e.message||e)}`)}if(null===f.readable)if(null==e)f.readable=!1,o("store-unreadable",`${f.path} exists but could not be read`);else try{const t=JSON.parse(e);f.readable=!0,f.legacy=t&&t.version||null}catch(e){f.readable=!1,o("store-unreadable",`${f.path} is not valid JSON: ${String(e&&e.message||e)}`)}v=path.basename(f.path)}f.display=v;try{g=checkVendor(t,t.vendorPairs)}catch(e){g={staged:0,matched:0,mismatch:[],missingSource:[],stale:!1,checked:0,error:String(e&&e.message||e)},o("vendor-unreadable",g.error)}for(const e of g.mismatch)o("vendor-hash-mismatch",`${e.staged} differs from ${e.source||"its source"}`);for(const e of g.missingSource)o("vendor-source-missing",`${e} has no source to be re-derived from`);g.stale&&(s.installed?o("vendor-missing","the ONE bundle is empty — reinstall aegisone"):r("vendor-stale","the ONE bundle has never been staged (one/vendor is empty) — run `npm run predist`"));const m={channel:"npm",current:l.version,latest:null,behind:!1,reason:null,checkedAt:null,cached:!0,action:"none",applier:"npm",instruction:null};try{const e=t.registry.check({current:l.version,cache:t.updateCache,save:t.saveUpdateCache,now:t.now})||{};m.latest=e.latest||null,m.behind=Boolean(e.behind),m.reason=e.reason||null}catch(e){m.reason="unavailable",m.error=String(e&&e.message||e)}try{const e=t.registry.plan({current:l.version,latest:m.latest,behind:m.behind});e&&(m.action=e.action,m.applier=e.applier,m.instruction=e.instruction)}catch{}m.behind&&r("update-available",`${m.current} → ${m.latest} (${m.instruction||"run the channel updater"})`);const y=h&&h.electron||null,b=h&&h.appBundle||null,j=y||b||null;t.guiRequested&&!j&&o("gui-without-electron","--gui was requested but Electron is not installed — use --tui");const k=n.filter(e=>"broken"===e.level).length,$=n.filter(e=>"warn"===e.level).length,S=k?EXIT.BROKEN:$?EXIT.WARN:EXIT.OK;return{report:{aegis:"one",status:k?"broken":$?"warn":"healthy",exitCode:S,product:l,faces:u,credential:{source:p,found:Boolean(d.key),from:d.key?d.from:""},store:{path:f.path,exists:f.exists,readable:f.exists?!0===f.readable:null},vendor:{staged:g.staged,matched:g.matched,mismatched:g.mismatch.length,missingSource:g.missingSource.length,stale:g.stale,verifiable:!s.installed},update:m,gui:{requested:Boolean(t.guiRequested),electron:y||null,appBundle:b||null,usable:Boolean(j)&&(!t.guiImplied||t.guiImplied)},problems:n},code:S}}function render(e){const t=[],n=(e,t)=>String(e)+" ".repeat(Math.max(0,t-String(e).length));t.push(`aegis doctor — ${e.status} (exit ${e.exitCode})`),t.push(` product ${e.product.name} ${e.product.version}`);for(const[o,r]of Object.entries(e.faces)){const e=r.ok?"":` (expected ${r.expected||"unknown"})`;t.push(` ${n(o,14)} ${r.version||"unknown"}${e}`)}t.push(` credential ${e.credential.source}`),t.push(` shared store ${e.store.path} ${e.store.exists?e.store.readable?"(readable)":"(unreadable)":"(absent)"}`),t.push(!1===e.vendor.verifiable?` vendor ${e.vendor.staged} staged (sources not shipped — not re-derivable here)`:` vendor ${e.vendor.staged} staged, ${e.vendor.matched} matching, ${e.vendor.mismatched} mismatched, ${e.vendor.missingSource} without a source`+(e.vendor.stale?" (never staged)":""));const o=e.update;if(t.push(" update "+(o.behind?`${o.current} → ${o.latest}`:`${o.current} is current`)+` (next: ${o.action}${o.instruction?` — ${o.instruction}`:""})`),t.push(" window face "+(e.gui.electron?`Electron at ${e.gui.electron}`:e.gui.appBundle?`native app at ${e.gui.appBundle}`:"not installed")),e.problems.length){t.push(" problems:");for(const n of e.problems)t.push(` ${"broken"===n.level?"✗":"!"} ${n.code}: ${n.detail}`)}return t.join("\n")+"\n"}function wantsGui(e,t){return!!(Array.isArray(e)?e:[]).includes("--gui")||"gui"===(t||{}).AEGISONE_FACE}function main(e,t){const n=t||{},o=Array.isArray(e)?e:[],r=n.stdout||process.stdout,s=n.env||process.env||{},a=Object.assign({},n,{env:s,guiRequested:wantsGui(o,s)}),{report:i,code:l}=diagnose(a),c=o.includes("--json")?JSON.stringify(i)+"\n":render(i);try{r.write(c)}catch{}return l}module.exports={EXIT:EXIT,FACE_PACKAGES:FACE_PACKAGES,wantsGui:wantsGui,diagnose:diagnose,render:render,main:main,vendorPairs:vendorPairs,resolveSeams:resolveSeams},require.main===module&&(process.exitCode=main(process.argv.slice(2)));
package/src/probes.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
- "use strict";const fs=require("node:fs"),path=require("node:path"),{createRequire:createRequire}=require("node:module"),host=require("./host.js");function hasDisplay(e,t){const r=e||{},n=t||host.hostPlatform();return"darwin"===n||"win32"===n||Boolean(r.DISPLAY||r.WAYLAND_DISPLAY||r.MIR_SERVER_SOCKET)}function resolveFrom(e,t){if(!e)return null;try{return createRequire(path.join(e,"package.json")).resolve(t)}catch{return null}}function electronExecutable(e){const t=Array.isArray(e)?e:[e];for(const e of t){if(!e)continue;const t=packageDirOf(e,"electron");if(!t)continue;const r=unpackedBinary(t);if(r)return r}return null}function packageDirOf(e,t){const r=resolveFrom(e,t+"/package.json");if(r)return path.dirname(r);const n=resolveFrom(e,t);return n?path.dirname(n):null}function unpackedBinary(e){try{const t=fs.readFileSync(path.join(e,"path.txt"),"utf8").trim();if(!t)return null;const r=path.join(e,"dist",t);return fs.existsSync(r)?r:null}catch{return null}}function stdioTty(e,t){const r=e=>{try{return Boolean(e&&e.isTTY)}catch{return!1}};return{stdin:r(void 0===e?process.stdin:e),stdout:r(void 0===t?process.stdout:t)}}function packageDirs(e,t){const r=[path.join(e,"..",t)],n=path.join(e,"vendor",t);return fs.existsSync(n)&&r.push(n),r}function firstFile(e){for(const t of e)if(t&&fs.existsSync(t))return t;return null}function collect(e){const t=e||{},r=t.oneDir||path.resolve(__dirname,".."),n=t.env||process.env,o=t.platform||host.hostPlatform(),s=t.invokedAs||path.basename(process.argv[1]||"aegis"),i=n.AEGISONE_CLI_BIN||firstFile(packageDirs(r,"cli").map(e=>path.join(e,"bin","aegiscode.js"))),a=n.AEGISONE_DESKTOP_BIN||firstFile(packageDirs(r,"desktop").map(e=>path.join(e,"bin","aegis.js"))),c=void 0!==t.electron?t.electron:electronExecutable(packageDirs(r,"desktop"));return{argv:t.argv||process.argv.slice(2),env:n,platform:o,tty:t.tty||stdioTty(process.stdin,process.stdout),hasDisplay:void 0!==t.hasDisplay?Boolean(t.hasDisplay):hasDisplay(n,o),electronResolvable:Boolean(c),invokedAs:s,_cliBin:i,_desktopMain:a,_electron:c}}module.exports={hasDisplay:hasDisplay,resolveFrom:resolveFrom,electronExecutable:electronExecutable,packageDirOf:packageDirOf,unpackedBinary:unpackedBinary,stdioTty:stdioTty,packageDirs:packageDirs,firstFile:firstFile,collect:collect};
3
+ "use strict";const fs=require("node:fs"),path=require("node:path"),{createRequire:createRequire}=require("node:module"),host=require("./host.js");function hasDisplay(e,n){const t=e||{},o=n||host.hostPlatform();return"darwin"===o||"win32"===o||Boolean(t.DISPLAY||t.WAYLAND_DISPLAY||t.MIR_SERVER_SOCKET)}function resolveFrom(e,n){if(!e)return null;try{return createRequire(path.join(e,"package.json")).resolve(n)}catch{return null}}function electronExecutable(e){const n=Array.isArray(e)?e:[e];for(const e of n){if(!e)continue;const n=packageDirOf(e,"electron");if(!n)continue;const t=unpackedBinary(n);if(t)return t}return null}function packageDirOf(e,n){const t=resolveFrom(e,n+"/package.json");if(t)return path.dirname(t);const o=resolveFrom(e,n);return o?path.dirname(o):null}function unpackedBinary(e){try{const n=fs.readFileSync(path.join(e,"path.txt"),"utf8").trim();if(!n)return null;const t=path.join(e,"dist",n);return fs.existsSync(t)?t:null}catch{return null}}function stdioTty(e,n){const t=e=>{try{return Boolean(e&&e.isTTY)}catch{return!1}};return{stdin:t(void 0===e?process.stdin:e),stdout:t(void 0===n?process.stdout:n)}}function isCi(e){const n=e||{},t=n.AEGISONE_CI;if(void 0!==t)return"1"===t||"true"===t;const o=n.CI;return void 0!==o&&""!==o&&"0"!==o&&"false"!==o}function installedAppBundle(e,n){const t=e||{},o=n||host.hostPlatform();if("darwin"===o){const e=t.HOME||"",n=["/Applications",e?path.join(e,"Applications"):null].filter(Boolean);for(const e of n){const n=path.join(e,"aegis one.app","Contents","MacOS","aegis one");if(fs.existsSync(n))return n}return null}if("win32"===o){const e=t.LOCALAPPDATA||(t.USERPROFILE?path.join(t.USERPROFILE,"AppData","Local"):"");if(!e)return null;const n=[path.join(e,"Programs","aegis one")];t.ProgramFiles&&n.push(path.join(t.ProgramFiles,"aegis one")),t["ProgramFiles(x86)"]&&n.push(path.join(t["ProgramFiles(x86)"],"aegis one"));for(const e of n){const n=path.join(e,"aegis one.exe");if(fs.existsSync(n))return n}return null}return null}function packageDirs(e,n){const t=[path.join(e,"..",n)],o=path.join(e,"vendor",n);return fs.existsSync(o)&&t.push(o),t}function firstFile(e){for(const n of e)if(n&&fs.existsSync(n))return n;return null}function collect(e){const n=e||{},t=n.oneDir||path.resolve(__dirname,".."),o=n.env||process.env,r=n.platform||host.hostPlatform(),i=n.invokedAs||path.basename(process.argv[1]||"aegis"),s=o.AEGISONE_CLI_BIN||firstFile(packageDirs(t,"cli").map(e=>path.join(e,"bin","aegiscode.js"))),a=o.AEGISONE_DESKTOP_BIN||firstFile(packageDirs(t,"desktop").map(e=>path.join(e,"bin","aegis.js"))),l=void 0!==n.electron?n.electron:electronExecutable(packageDirs(t,"desktop")),c=void 0!==n.appBundle?n.appBundle:installedAppBundle(o,r);return{argv:n.argv||process.argv.slice(2),env:o,platform:r,tty:n.tty||stdioTty(process.stdin,process.stdout),hasDisplay:void 0!==n.hasDisplay?Boolean(n.hasDisplay):hasDisplay(o,r),electronResolvable:Boolean(l)||Boolean(c),ci:void 0!==n.ci?Boolean(n.ci):isCi(o),invokedAs:i,_cliBin:s,_desktopMain:a,_electron:l,_appBundle:c}}module.exports={hasDisplay:hasDisplay,isCi:isCi,resolveFrom:resolveFrom,electronExecutable:electronExecutable,installedAppBundle:installedAppBundle,packageDirOf:packageDirOf,unpackedBinary:unpackedBinary,stdioTty:stdioTty,packageDirs:packageDirs,firstFile:firstFile,collect:collect};
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "aegiscode",
3
3
  "productName": "AEGIS Code",
4
- "version": "7.0.71",
4
+ "version": "7.0.73",
5
5
  "description": "aegiscode — the command-line version of AEGIS One. The shared tool surface in your shell, over the same thin transport and tool registry as the MCP plugin and the desktop app. Ships transport + UI only; no brain.",
6
6
  "author": {
7
7
  "name": "AEGIS Code",
@@ -2,7 +2,7 @@
2
2
  "name": "aegis-desktop",
3
3
  "productName": "aegis one",
4
4
  "desktopName": "aegis-desktop",
5
- "version": "1.0.71",
5
+ "version": "1.0.73",
6
6
  "description": "Thin Electron host for AEGIS — a local chat UI over the shared client/aegis.js transport. Ships transport + UI only; engine logic stays server-side.",
7
7
  "author": {
8
8
  "name": "AEGIS Code",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "aegiscode",
3
3
  "productName": "AEGIS Code",
4
- "version": "7.0.71",
4
+ "version": "7.0.73",
5
5
  "description": "aegiscode — the command-line version of AEGIS One. The shared tool surface in your shell, over the same thin transport and tool registry as the MCP plugin and the desktop app. Ships transport + UI only; no brain.",
6
6
  "author": {
7
7
  "name": "AEGIS Code",