aegisone 1.0.33 → 1.0.34

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 (226) hide show
  1. package/README.md +1 -1
  2. package/bin/aegis.js +322 -1
  3. package/package.json +5 -4
  4. package/scripts/bump.mjs +211 -1
  5. package/scripts/bundle.js +129 -1
  6. package/scripts/predist.mjs +976 -1
  7. package/src/child.js +285 -1
  8. package/src/dispatch.js +269 -1
  9. package/src/doctor.js +639 -1
  10. package/src/host.js +111 -1
  11. package/src/permissions.js +383 -1
  12. package/src/probes.js +159 -1
  13. package/src/release.js +409 -1
  14. package/vendor/cli/package.json +7 -3
  15. package/vendor/cli/scripts/check.mjs +52 -1
  16. package/vendor/cli/scripts/demo.mjs +94 -1
  17. package/vendor/cli/scripts/predist.mjs +75 -1
  18. package/vendor/cli/scripts/runtests.mjs +56 -1
  19. package/vendor/cli/scripts/seal-gate.mjs +74 -1
  20. package/vendor/cli/src/agents.js +139 -1
  21. package/vendor/cli/src/app.js +2957 -1
  22. package/vendor/cli/src/art.js +289 -1
  23. package/vendor/cli/src/chatflow.js +3023 -1
  24. package/vendor/cli/src/checkpoint.js +90 -1
  25. package/vendor/cli/src/clipboard.js +424 -1
  26. package/vendor/cli/src/cloudsync.js +528 -1
  27. package/vendor/cli/src/commands.js +4089 -1
  28. package/vendor/cli/src/config.js +581 -1
  29. package/vendor/cli/src/connect.js +349 -1
  30. package/vendor/cli/src/credentials.js +33 -1
  31. package/vendor/cli/src/deps.js +232 -1
  32. package/vendor/cli/src/devrun.js +187 -1
  33. package/vendor/cli/src/diff.js +333 -1
  34. package/vendor/cli/src/diffview.js +296 -1
  35. package/vendor/cli/src/engine.js +297 -1
  36. package/vendor/cli/src/entitlement.js +355 -1
  37. package/vendor/cli/src/events.js +707 -1
  38. package/vendor/cli/src/export.js +67 -1
  39. package/vendor/cli/src/filepreview.js +153 -1
  40. package/vendor/cli/src/fingerprint.js +592 -1
  41. package/vendor/cli/src/format.js +259 -1
  42. package/vendor/cli/src/fuzzy.js +119 -1
  43. package/vendor/cli/src/history.js +423 -1
  44. package/vendor/cli/src/init.js +175 -1
  45. package/vendor/cli/src/input.js +139 -1
  46. package/vendor/cli/src/keys.js +183 -1
  47. package/vendor/cli/src/markdown.js +306 -1
  48. package/vendor/cli/src/models.js +507 -1
  49. package/vendor/cli/src/naming.js +57 -1
  50. package/vendor/cli/src/overlays.js +462 -1
  51. package/vendor/cli/src/panels.js +1418 -1
  52. package/vendor/cli/src/ping.js +226 -1
  53. package/vendor/cli/src/presence.js +238 -1
  54. package/vendor/cli/src/render.js +516 -1
  55. package/vendor/cli/src/screen.js +518 -1
  56. package/vendor/cli/src/screens.js +896 -1
  57. package/vendor/cli/src/secret.js +59 -1
  58. package/vendor/cli/src/securefs.js +359 -1
  59. package/vendor/cli/src/settings.js +155 -1
  60. package/vendor/cli/src/shared.js +52 -1
  61. package/vendor/cli/src/sharedpaths.js +53 -1
  62. package/vendor/cli/src/signup.js +156 -1
  63. package/vendor/cli/src/summarize.js +95 -1
  64. package/vendor/cli/src/sysdiag.js +585 -1
  65. package/vendor/cli/src/system.js +40 -1
  66. package/vendor/cli/src/theme.js +570 -1
  67. package/vendor/cli/src/title.js +220 -1
  68. package/vendor/cli/src/todos.js +115 -1
  69. package/vendor/cli/src/tokens.js +263 -1
  70. package/vendor/cli/src/topup.js +210 -1
  71. package/vendor/cli/src/update.js +191 -1
  72. package/vendor/cli/vendor/client/aegis.js +2441 -1
  73. package/vendor/cli/vendor/client/attest.js +518 -1
  74. package/vendor/cli/vendor/client/authorship-key.js +410 -1
  75. package/vendor/cli/vendor/client/auto-provision.js +134 -1
  76. package/vendor/cli/vendor/client/brain-catalog.js +268 -1
  77. package/vendor/cli/vendor/client/byok-catalog.js +199 -1
  78. package/vendor/cli/vendor/client/catalog-client.js +487 -1
  79. package/vendor/cli/vendor/client/conversation-export.js +177 -1
  80. package/vendor/cli/vendor/client/credentials.js +494 -1
  81. package/vendor/cli/vendor/client/device-fingerprint.js +141 -1
  82. package/vendor/cli/vendor/client/drive-connect.js +110 -1
  83. package/vendor/cli/vendor/client/drive-upload.js +234 -1
  84. package/vendor/cli/vendor/client/env-file.js +1273 -1
  85. package/vendor/cli/vendor/client/fingerprint.js +1064 -1
  86. package/vendor/cli/vendor/client/foreign-memory.js +669 -1
  87. package/vendor/cli/vendor/client/google-signin.js +133 -1
  88. package/vendor/cli/vendor/client/hooks.js +430 -1
  89. package/vendor/cli/vendor/client/model-discovery.js +373 -1
  90. package/vendor/cli/vendor/client/naming.js +283 -1
  91. package/vendor/cli/vendor/client/platform.js +937 -1
  92. package/vendor/cli/vendor/client/prefs.js +351 -1
  93. package/vendor/cli/vendor/client/presence-constants.js +107 -1
  94. package/vendor/cli/vendor/client/presence.js +438 -1
  95. package/vendor/cli/vendor/client/record-vault.js +1055 -3
  96. package/vendor/cli/vendor/client/session-store.js +575 -1
  97. package/vendor/cli/vendor/client/topup.js +297 -1
  98. package/vendor/cli/vendor/client/touch.js +458 -1
  99. package/vendor/cli/vendor/client/update.js +763 -1
  100. package/vendor/cli/vendor/client/user-models.js +381 -1
  101. package/vendor/cli/vendor/desktop/lib/local/agents.js +105 -1
  102. package/vendor/cli/vendor/desktop/lib/local/attachments.js +276 -1
  103. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1045 -1
  104. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1028 -1
  105. package/vendor/cli/vendor/desktop/lib/local/context.js +125 -1
  106. package/vendor/cli/vendor/desktop/lib/local/engine.js +3666 -1
  107. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +660 -1
  108. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +228 -1
  109. package/vendor/cli/vendor/desktop/lib/local/local.js +2145 -1
  110. package/vendor/cli/vendor/desktop/lib/local/prompt.js +280 -1
  111. package/vendor/cli/vendor/desktop/lib/local/queue.js +560 -1
  112. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +238 -1
  113. package/vendor/cli/vendor/desktop/lib/local/spill.js +75 -1
  114. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +300 -1
  115. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +235 -1
  116. package/vendor/cli/vendor/desktop/lib/settings.js +890 -1
  117. package/vendor/cli/vendor/desktop/renderer/usage.js +1239 -1
  118. package/vendor/cli/vendor/hosts/install.js +638 -1
  119. package/vendor/cli/vendor/hosts/openai-shim.js +515 -1
  120. package/vendor/cli/vendor/hosts/spec.js +164 -1
  121. package/vendor/cli/vendor/hosts/targets.js +346 -1
  122. package/vendor/cli/vendor/mcp/server.js +221 -1
  123. package/vendor/cli/vendor/mcp/tools.js +408 -1
  124. package/vendor/cli/vendor/one/src/child.js +285 -1
  125. package/vendor/cli/vendor/one/src/permissions.js +383 -1
  126. package/vendor/desktop/bin/aegis.js +32 -1
  127. package/vendor/desktop/lib/account-key.js +56 -1
  128. package/vendor/desktop/lib/auto.js +461 -1
  129. package/vendor/desktop/lib/avatar/companion.js +698 -1
  130. package/vendor/desktop/lib/avatar/cosmetics.js +532 -1
  131. package/vendor/desktop/lib/avatar/events.js +344 -1
  132. package/vendor/desktop/lib/avatar/holder-turn.js +350 -1
  133. package/vendor/desktop/lib/avatar/holders.js +612 -1
  134. package/vendor/desktop/lib/avatar/identity.js +641 -1
  135. package/vendor/desktop/lib/avatar/level.js +368 -1
  136. package/vendor/desktop/lib/avatar/mirror.js +524 -1
  137. package/vendor/desktop/lib/avatar/persona.js +388 -1
  138. package/vendor/desktop/lib/avatar/profile.js +977 -1
  139. package/vendor/desktop/lib/avatar/register.js +307 -1
  140. package/vendor/desktop/lib/avatar/store.js +472 -1
  141. package/vendor/desktop/lib/avatar/tiers.js +38 -1
  142. package/vendor/desktop/lib/avatar/transfer.js +415 -1
  143. package/vendor/desktop/lib/avatar/turn.js +216 -1
  144. package/vendor/desktop/lib/avatar/voice.js +328 -1
  145. package/vendor/desktop/lib/avatar/xp.js +404 -1
  146. package/vendor/desktop/lib/deep-link.js +120 -1
  147. package/vendor/desktop/lib/fingerprint.js +347 -2
  148. package/vendor/desktop/lib/google-connect.js +323 -1
  149. package/vendor/desktop/lib/local/agents.js +105 -1
  150. package/vendor/desktop/lib/local/attachments.js +276 -1
  151. package/vendor/desktop/lib/local/autonomous.js +1045 -1
  152. package/vendor/desktop/lib/local/claude-pro.js +1028 -1
  153. package/vendor/desktop/lib/local/context.js +125 -1
  154. package/vendor/desktop/lib/local/engine.js +3666 -1
  155. package/vendor/desktop/lib/local/entitlement.js +660 -1
  156. package/vendor/desktop/lib/local/git-scope.js +228 -1
  157. package/vendor/desktop/lib/local/local.js +2145 -1
  158. package/vendor/desktop/lib/local/prompt.js +280 -1
  159. package/vendor/desktop/lib/local/queue.js +560 -1
  160. package/vendor/desktop/lib/local/session-rounds.js +238 -1
  161. package/vendor/desktop/lib/local/spill.js +75 -1
  162. package/vendor/desktop/lib/local/telemetry.js +470 -1
  163. package/vendor/desktop/lib/local/turn-guard.js +300 -1
  164. package/vendor/desktop/lib/local/worktree-lock.js +235 -1
  165. package/vendor/desktop/lib/provider-key-mirror.js +252 -1
  166. package/vendor/desktop/lib/quick-launcher.js +84 -1
  167. package/vendor/desktop/lib/settings.js +890 -1
  168. package/vendor/desktop/lib/sync/memory-queue.js +60 -1
  169. package/vendor/desktop/lib/sync/persist-gate.js +148 -1
  170. package/vendor/desktop/lib/sync/sessions.js +106 -1
  171. package/vendor/desktop/lib/window-state.js +66 -1
  172. package/vendor/desktop/package.json +5 -3
  173. package/vendor/desktop/preload.js +679 -1
  174. package/vendor/desktop/renderer/app.js +7250 -1
  175. package/vendor/desktop/renderer/avatar/assemble.js +335 -1
  176. package/vendor/desktop/renderer/avatar/avatar.js +380 -1
  177. package/vendor/desktop/renderer/avatar/cards.js +141 -1
  178. package/vendor/desktop/renderer/avatar/hud.js +206 -1
  179. package/vendor/desktop/renderer/avatar/machine.js +213 -1
  180. package/vendor/desktop/renderer/avatar/pane.js +439 -1
  181. package/vendor/desktop/renderer/avatar/parts.js +437 -1
  182. package/vendor/desktop/renderer/budget.js +172 -1
  183. package/vendor/desktop/renderer/companion.js +223 -1
  184. package/vendor/desktop/renderer/diff.js +359 -1
  185. package/vendor/desktop/renderer/diffview.js +336 -1
  186. package/vendor/desktop/renderer/filepreview.js +211 -1
  187. package/vendor/desktop/renderer/fingerprint.js +789 -3
  188. package/vendor/desktop/renderer/markdown.js +168 -1
  189. package/vendor/desktop/renderer/provider-mark.js +311 -1
  190. package/vendor/desktop/renderer/provider-toolbar.js +134 -1
  191. package/vendor/desktop/renderer/providers.js +259 -1
  192. package/vendor/desktop/renderer/quick.js +285 -1
  193. package/vendor/desktop/renderer/stream-policy.js +387 -1
  194. package/vendor/desktop/renderer/transcript-view.js +323 -1
  195. package/vendor/desktop/renderer/usage.js +1239 -1
  196. package/vendor/desktop/vendor/aegis.js +2441 -1
  197. package/vendor/desktop/vendor/attest.js +518 -1
  198. package/vendor/desktop/vendor/authorship-key.js +410 -1
  199. package/vendor/desktop/vendor/auto-provision.js +134 -1
  200. package/vendor/desktop/vendor/brain-catalog.js +268 -1
  201. package/vendor/desktop/vendor/byok-catalog.js +199 -1
  202. package/vendor/desktop/vendor/catalog-client.js +487 -1
  203. package/vendor/desktop/vendor/conversation-export.js +177 -1
  204. package/vendor/desktop/vendor/credentials.js +494 -1
  205. package/vendor/desktop/vendor/device-fingerprint.js +141 -1
  206. package/vendor/desktop/vendor/drive-connect.js +110 -1
  207. package/vendor/desktop/vendor/drive-upload.js +234 -1
  208. package/vendor/desktop/vendor/env-file.js +1273 -1
  209. package/vendor/desktop/vendor/fingerprint.js +1064 -1
  210. package/vendor/desktop/vendor/foreign-memory.js +669 -1
  211. package/vendor/desktop/vendor/google-signin.js +133 -1
  212. package/vendor/desktop/vendor/hooks.js +430 -1
  213. package/vendor/desktop/vendor/model-discovery.js +373 -1
  214. package/vendor/desktop/vendor/naming.js +283 -1
  215. package/vendor/desktop/vendor/platform.js +937 -1
  216. package/vendor/desktop/vendor/prefs.js +351 -1
  217. package/vendor/desktop/vendor/presence-constants.js +107 -1
  218. package/vendor/desktop/vendor/presence.js +438 -1
  219. package/vendor/desktop/vendor/record-vault.js +1055 -3
  220. package/vendor/desktop/vendor/session-store.js +575 -1
  221. package/vendor/desktop/vendor/topup.js +297 -1
  222. package/vendor/desktop/vendor/touch.js +458 -1
  223. package/vendor/desktop/vendor/update.js +763 -1
  224. package/vendor/desktop/vendor/user-models.js +381 -1
  225. package/LICENSE +0 -661
  226. package/SOURCE-OFFER.txt +0 -9
package/src/doctor.js CHANGED
@@ -1,3 +1,641 @@
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 homeHint(e){const t=e||{};return t.AEGISCODE_HOME||t.AEGIS_HOME||null}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 s;try{s=fs.readdirSync(e,{withFileTypes:!0})}catch{return}for(const o of s){if("node_modules"===o.name||".git"===o.name)continue;const s=path.join(e,o.name);o.isDirectory()?r(s):n.push(path.relative(t,s).split(path.sep).join("/"))}};return r(e),n.sort()}function defaultElectronPaths(e,t){const n=t||{},r=homeHint(e)||path.join(e&&e.HOME?e.HOME:"",".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(){let e=null;const t=()=>{if(e)return e;const t=[path.join(repoDir(),"client","update.js"),path.join(oneDir(),"vendor","cli","vendor","client","update.js")];for(const n of t)try{e=require(n);break}catch{}return e};return{check(e){const n=t();return n&&"function"==typeof n.updateNotice?n.updateNotice(e||{}):{latest:null,behind:!1,reason:"unavailable"}},plan(e){const n=t();return n&&"function"==typeof n.updatePlan?n.updatePlan(e||{}):null}}}function defaultStorePath(e){try{const t=require(path.join(repoDir(),"client","prefs.js"));if("function"==typeof t.prefsFile)return t.prefsFile(e)}catch{}const t=homeHint(e)||path.join(e&&e.HOME||"",".aegiscode");return path.join(t,"preferences.json")}function defaultCredentials(){let e=null;return{resolve(t){if(!e)try{e=require(path.join(repoDir(),"client","credentials.js"))}catch{e=null}if(!e||"function"!=typeof e.resolveApiKey)return{key:"",source:"none",from:""};try{return e.resolveApiKey(t||{})}catch{return{key:"",source:"none",from:""}}}}}function vendorPairs(e){const{root:t,exists:n}=e,r=[];for(const{face:s,root:o,staged:a}of BUNDLE_FACES){const i=path.join(t,a),c=e.listFiles(i,i);for(const e of c){const i=[];if(e.startsWith("vendor/")){const n=e.slice(7);if(i.push(path.join(t,n)),i.push(path.join(t,o,n)),"desktop"===s){const e=path.basename(n);for(const n of["client","mcp","covenant","commands","skills","tools","hosts"])i.push(path.join(t,n,e));i.push(path.join(t,e))}}else i.push(path.join(t,o,e)),i.push(path.join(t,e));const c=i.find((e=>n(e)))||null;r.push({face:s,staged:path.join(a,e),source:c,candidates:i})}}return r}function checkVendor(e,t){const n=t||vendorPairs(e),r=[],s=[];let o=0,a=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){s.push({staged:t.staged,source:t.source,error:String(e&&e.message||e)});continue}n===i?o+=1:s.push({staged:t.staged,source:t.source})}return{staged:a,matched:o,mismatch:s,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(),s=t||{};return{root:t.root||repoDir(),platform:t.platform||"linux",env:n,exists:s.exists||r.exists,readFile:s.readFile||r.readFile,hashFile:s.hashFile||r.hashFile,listFiles:s.listFiles||r.listFiles,credentials:t.credentials||defaultCredentials(),storePath:t.storePath||defaultStorePath(n),registry:t.registry||defaultRegistry(),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}}function diagnose(e){const t=resolveSeams(e),n=[],r=(e,t)=>n.push({level:"broken",code:e,detail:t}),s=(e,t)=>n.push({level:"warn",code:e,detail:t}),o=readJson(t,"one/package.json"),a=o.ok?{name:o.value.name||"aegisone",version:String(o.value.version||"")}:{name:"aegisone",version:""};o.ok||r("product-unreadable","one/package.json "+(o.unreadable?"is unreadable":"is missing"));let i=null;try{i=require("./release.js").deriveFaceVersions(a.version)}catch(e){i=null,o.ok&&r("product-version-invalid",`${a.version}: ${String(e&&e.message||e)}`)}const c={};for(const{dir:e,package:n}of FACE_PACKAGES){const s=readJson(t,`${e}/package.json`),o=s.ok?String(s.value.version||""):"",l=i&&i[n]?i[n].version:null;s.ok?l&&o!==l&&r("version-mismatch",`${n} is ${o}, product ${a.version} derives ${l}`):r("face-unreadable",`${e}/package.json ${s.unreadable?"is unreadable":"is missing"}`),c[n]={dir:e,version:o,expected:l,ok:Boolean(l&&o===l)}}let l={key:"",source:"none",from:""};try{l=t.credentials.resolve({env:t.env})||l}catch{l={key:"",source:"none",from:""}}const u=t.electronPaths||{};let d=l.key?"env"===l.source?"env":(l.source,"env-file"):"none";if(!l.key&&u.keychain&&t.exists(u.keychain)){const e=(()=>{try{return t.readFile(u.keychain)}catch{return null}})();e&&/encrypt|safeStorage/i.test(e)&&(d="keychain")}"none"===d&&s("no-credential","no credential found (env, credentials.json, or the OS keychain)");const h={path:t.storePath,exists:!1,readable:null,legacy:null};try{h.exists=t.exists(t.storePath)}catch{h.exists=!1}let p,f=h.path;if(h.exists){let e=null;try{e=t.readFile(h.path)}catch(e){h.readable=!1,r("store-unreadable",`${h.path}: ${String(e&&e.message||e)}`)}if(null===h.readable)if(null==e)h.readable=!1,r("store-unreadable",`${h.path} exists but could not be read`);else try{const t=JSON.parse(e);h.readable=!0,h.legacy=t&&t.version||null}catch(e){h.readable=!1,r("store-unreadable",`${h.path} is not valid JSON: ${String(e&&e.message||e)}`)}f=path.basename(h.path)}h.display=f;try{p=checkVendor(t,t.vendorPairs)}catch(e){p={staged:0,matched:0,mismatch:[],missingSource:[],stale:!1,checked:0,error:String(e&&e.message||e)},r("vendor-unreadable",p.error)}for(const e of p.mismatch)r("vendor-hash-mismatch",`${e.staged} differs from ${e.source||"its source"}`);for(const e of p.missingSource)r("vendor-source-missing",`${e} has no source to be re-derived from`);p.stale&&s("vendor-stale","the ONE bundle has never been staged (one/vendor is empty) — run `npm run predist`");const g={channel:"npm",current:a.version,latest:null,behind:!1,reason:null,checkedAt:null,cached:!0,action:"none",applier:"npm",instruction:null};try{const e=t.registry.check({current:a.version,cache:t.updateCache,save:t.saveUpdateCache,now:t.now})||{};g.latest=e.latest||null,g.behind=Boolean(e.behind),g.reason=e.reason||null}catch(e){g.reason="unavailable",g.error=String(e&&e.message||e)}try{const e=t.registry.plan({current:a.version,latest:g.latest,behind:g.behind});e&&(g.action=e.action,g.applier=e.applier,g.instruction=e.instruction)}catch{}g.behind&&s("update-available",`${g.current} → ${g.latest} (${g.instruction||"run the channel updater"})`);const v=u&&u.electron||null;t.guiRequested&&!v&&r("gui-without-electron","--gui was requested but Electron is not installed — use --tui");const m=n.filter((e=>"broken"===e.level)).length,y=n.filter((e=>"warn"===e.level)).length,b=m?EXIT.BROKEN:y?EXIT.WARN:EXIT.OK;return{report:{aegis:"one",status:m?"broken":y?"warn":"healthy",exitCode:b,product:a,faces:c,credential:{source:d,found:Boolean(l.key),from:l.key?l.from:""},store:{path:h.path,exists:h.exists,readable:h.exists?!0===h.readable:null},vendor:{staged:p.staged,matched:p.matched,mismatched:p.mismatch.length,missingSource:p.missingSource.length,stale:p.stale},update:g,gui:{requested:Boolean(t.guiRequested),electron:v||null,usable:Boolean(v)&&(!t.guiImplied||t.guiImplied)},problems:n},code:b}}function render(e){const t=[];t.push(`aegis doctor — ${e.status} (exit ${e.exitCode})`),t.push(` product ${e.product.name} ${e.product.version}`);for(const[r,s]of Object.entries(e.faces)){const e=s.ok?"":` (expected ${s.expected||"unknown"})`;t.push(` ${n=r,14,String(n)+" ".repeat(Math.max(0,14-String(n).length))} ${s.version||"unknown"}${e}`)}var n;t.push(` credential ${e.credential.source}`),t.push(` shared store ${e.store.path} ${e.store.exists?e.store.readable?"(readable)":"(unreadable)":"(absent)"}`),t.push(` 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:[],s=n.stdout||process.stdout,o=n.env||process.env||{},a=Object.assign({},n,{env:o,guiRequested:wantsGui(r,o)}),{report:i,code:c}=diagnose(a),l=r.includes("--json")?JSON.stringify(i)+"\n":render(i);try{s.write(l)}catch{}return c}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
+ // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
+ // Conveying a modified copy, or running one as a network service, owes the
5
+ // corresponding source under this licence (§5/§13) — see LICENSING.md.
6
+ 'use strict';
7
+
8
+ /**
9
+ * doctor.js — ONE report about this AEGISONE install (AEGISONE decision D7).
10
+ *
11
+ * aegis doctor → the report, for a human
12
+ * aegis doctor --json → the same object, printed as JSON
13
+ *
14
+ * The exit code is the contract scripts branch on, so it is real:
15
+ *
16
+ * 0 healthy everything this file can check agrees with itself
17
+ * 1 warn usable, but something is out of date: a vendor tree that was
18
+ * never staged (or is entirely absent), a newer version
19
+ * published, no credential configured yet
20
+ * 2 broken the install cannot be trusted: a face version that does not
21
+ * match the product version, an unreadable shared store, a
22
+ * staged file that differs from its source, `--gui` asked for
23
+ * with no Electron to serve it
24
+ *
25
+ * ## Every input is a seam
26
+ *
27
+ * The report reads a lot of the machine — versions, the credential store, the
28
+ * environment file, a staged tree, the registry. None of it is read at module
29
+ * scope, and none of it is read from inside the decision: `report()` takes
30
+ * `{ platform, env, exists, readFile, hashFile, registry, electronPaths }` (plus
31
+ * the path and pair overrides below) and every one of them defaults to a real
32
+ * implementation built lazily *inside* the function that needs it. That is the
33
+ * standing ON rule — nothing in `one/` touches `process.*` at module scope —
34
+ * and it is what lets the ON5 test reach all three exit codes without a network,
35
+ * without a display, and without a real install to break.
36
+ *
37
+ * ## One check, not a second one
38
+ *
39
+ * The "is there a newer version" answer comes from `client/update.js`, the
40
+ * module that already owns the registry probe, the 2.5s timeout and the
41
+ * once-a-day cache (`CHECK_INTERVAL_MS`). Doctor passes the injected probe
42
+ * through to it and reports what it returns — it does not fetch anything
43
+ * itself, and it does not add a second cache. The same call is the one the
44
+ * desktop's applier consumes (see `client/update.js::checkPublished` and
45
+ * `desktop/main.js::fetchDetailed`), which is D7's "one update path".
46
+ */
47
+
48
+ const path = require('node:path');
49
+ const fs = require('node:fs');
50
+ const crypto = require('node:crypto');
51
+
52
+ /** Exit codes. Public: scripts branch on these, so they are frozen. */
53
+ const EXIT = Object.freeze({ OK: 0, WARN: 1, BROKEN: 2 });
54
+
55
+ /** The two faces, in package-name order, with the versions they must carry. */
56
+ const FACE_PACKAGES = Object.freeze([
57
+ Object.freeze({ dir: 'cli', package: 'aegiscode' }),
58
+ Object.freeze({ dir: 'desktop', package: 'aegis-desktop' }),
59
+ ]);
60
+
61
+ /** Where the ONE bundle keeps the two staged faces (D6 layout). */
62
+ const BUNDLE_FACES = Object.freeze([
63
+ Object.freeze({ face: 'cli', root: 'cli', staged: 'one/vendor/cli' }),
64
+ Object.freeze({ face: 'desktop', root: 'desktop', staged: 'one/vendor/desktop' }),
65
+ ]);
66
+
67
+ // ---------------------------------------------------------------------------
68
+ // Real seams. Built lazily, inside functions — never at module scope.
69
+ // ---------------------------------------------------------------------------
70
+
71
+ /** The directory this file lives in, without asking `process` anything. */
72
+ function oneDir() {
73
+ return path.resolve(__dirname, '..');
74
+ }
75
+
76
+ function repoDir() {
77
+ return path.resolve(__dirname, '..', '..');
78
+ }
79
+
80
+ /** `@returns {{path: string|null}}` — the home AEGISCODE_HOME resolves to. */
81
+ function homeHint(env) {
82
+ const e = env || {};
83
+ return e.AEGISCODE_HOME || e.AEGIS_HOME || null;
84
+ }
85
+
86
+ /**
87
+ * The default `{ exists, readFile, hashFile }` set.
88
+ *
89
+ * `readFile` returns text and NEVER throws for a missing file (it returns
90
+ * null) — because "the file is not there" and "the file is there and I cannot
91
+ * read it" are different facts, and the second one is exit 2. Callers that
92
+ * need to tell them apart use `exists` first; a throw from `readFile` is
93
+ * therefore a real I/O failure and is treated as one.
94
+ */
95
+ function defaultFs() {
96
+ return {
97
+ exists: (p) => {
98
+ try {
99
+ return fs.existsSync(p);
100
+ } catch {
101
+ return false;
102
+ }
103
+ },
104
+ readFile: (p) => {
105
+ try {
106
+ return fs.readFileSync(p, 'utf8');
107
+ } catch (err) {
108
+ if (err && (err.code === 'ENOENT' || err.code === 'EISDIR')) return null;
109
+ throw err;
110
+ }
111
+ },
112
+ hashFile: (p) => crypto.createHash('sha256').update(fs.readFileSync(p)).digest('hex'),
113
+ listFiles: (dir, base) => listFiles(dir, base === undefined ? dir : base),
114
+ };
115
+ }
116
+
117
+ /** Every file under `dir`, as paths relative to `base`. Sorted, so it is stable. */
118
+ function listFiles(dir, base) {
119
+ const out = [];
120
+ const walk = (d) => {
121
+ let entries;
122
+ try {
123
+ entries = fs.readdirSync(d, { withFileTypes: true });
124
+ } catch {
125
+ return;
126
+ }
127
+ for (const e of entries) {
128
+ if (e.name === 'node_modules' || e.name === '.git') continue;
129
+ const p = path.join(d, e.name);
130
+ if (e.isDirectory()) walk(p);
131
+ else out.push(path.relative(base, p).split(path.sep).join('/'));
132
+ }
133
+ };
134
+ walk(dir);
135
+ return out.sort();
136
+ }
137
+
138
+ /**
139
+ * Where the desktop keeps what only the OS can decrypt.
140
+ *
141
+ * On Linux a plain Node process cannot read `safeStorage` blobs, so the CLI
142
+ * reports *that the keychain holds something*, never the key. The location is
143
+ * derived from the same `$AEGISCODE_HOME`-or-`~/.aegiscode` rule
144
+ * `client/credentials.js` uses, with the Electron userData path preferred when
145
+ * the caller knows it.
146
+ */
147
+ function defaultElectronPaths(env, deps) {
148
+ const d = deps || {};
149
+ const home = homeHint(env);
150
+ const base = home || path.join(env && env.HOME ? env.HOME : '', '.aegiscode');
151
+ return {
152
+ electron: d.electron !== undefined ? d.electron : null,
153
+ desktopMain: d.desktopMain !== undefined ? d.desktopMain : null,
154
+ userData: d.userData !== undefined ? d.userData : base,
155
+ keychain: d.keychain !== undefined ? d.keychain : path.join(base, 'settings.json'),
156
+ };
157
+ }
158
+
159
+ /**
160
+ * The one registry check, reached through `client/update.js`.
161
+ *
162
+ * Lazy and injectable: doctor never contains a fetch, a timeout or an
163
+ * interval — the shared module owns all three, and the caller can replace the
164
+ * whole thing with a stub. Requires are inside the function so `doctor.js`
165
+ * can be loaded in a test with no client tree beside it.
166
+ */
167
+ function defaultRegistry() {
168
+ let shared = null;
169
+ const load = () => {
170
+ if (shared) return shared;
171
+ const candidates = [
172
+ path.join(repoDir(), 'client', 'update.js'),
173
+ path.join(oneDir(), 'vendor', 'cli', 'vendor', 'client', 'update.js'),
174
+ ];
175
+ for (const c of candidates) {
176
+ try {
177
+ // eslint-disable-next-line global-require
178
+ shared = require(c);
179
+ break;
180
+ } catch {
181
+ /* try the next layout */
182
+ }
183
+ }
184
+ return shared;
185
+ };
186
+ return {
187
+ /** The cached once-a-day check. Non-blocking by construction. */
188
+ check(opts) {
189
+ const mod = load();
190
+ if (!mod || typeof mod.updateNotice !== 'function') {
191
+ return { latest: null, behind: false, reason: 'unavailable' };
192
+ }
193
+ return mod.updateNotice(opts || {});
194
+ },
195
+ /** The shared "what happens next" verdict both appliers consume. */
196
+ plan(opts) {
197
+ const mod = load();
198
+ if (!mod || typeof mod.updatePlan !== 'function') return null;
199
+ return mod.updatePlan(opts || {});
200
+ },
201
+ };
202
+ }
203
+
204
+ /** The shared non-secret preference store (ON4/D5), resolved lazily. */
205
+ function defaultStorePath(env) {
206
+ try {
207
+ // eslint-disable-next-line global-require
208
+ const prefs = require(path.join(repoDir(), 'client', 'prefs.js'));
209
+ if (typeof prefs.prefsFile === 'function') return prefs.prefsFile(env);
210
+ } catch {
211
+ /* fall through to the documented rule */
212
+ }
213
+ const home = homeHint(env);
214
+ const base = home || path.join((env && env.HOME) || '', '.aegiscode');
215
+ return path.join(base, 'preferences.json');
216
+ }
217
+
218
+ /** The credential resolver, lazy for the same reason the registry is. */
219
+ function defaultCredentials() {
220
+ let mod = null;
221
+ return {
222
+ resolve(o) {
223
+ if (!mod) {
224
+ try {
225
+ // eslint-disable-next-line global-require
226
+ mod = require(path.join(repoDir(), 'client', 'credentials.js'));
227
+ } catch {
228
+ mod = null;
229
+ }
230
+ }
231
+ if (!mod || typeof mod.resolveApiKey !== 'function') return { key: '', source: 'none', from: '' };
232
+ try {
233
+ return mod.resolveApiKey(o || {});
234
+ } catch {
235
+ return { key: '', source: 'none', from: '' };
236
+ }
237
+ },
238
+ };
239
+ }
240
+
241
+ // ---------------------------------------------------------------------------
242
+ // Vendor integrity
243
+ // ---------------------------------------------------------------------------
244
+
245
+ /**
246
+ * Every staged file in the ONE bundle, paired with the source it was copied
247
+ * from.
248
+ *
249
+ * The rule is D6's layout, not a second manifest: inside `one/vendor/<face>/`
250
+ * a path either mirrors the face's own tree (`<rel>` ← `<face>/<rel>`) or is a
251
+ * staged shared module (`vendor/<rel>` ← `<rel>` at the repo root). The desktop
252
+ * stages the shared half FLAT, so a `desktop/vendor/<name>` may come from any
253
+ * of the shared roots — the candidates below are tried in a fixed order and the
254
+ * first that exists wins. A staged file with no source at all is reported as
255
+ * such: it means the bundle cannot be re-derived, which is a broken tree, not
256
+ * a cosmetic one.
257
+ */
258
+ function vendorPairs(seams) {
259
+ const { root, exists } = seams;
260
+ const pairs = [];
261
+ for (const { face, root: faceRoot, staged } of BUNDLE_FACES) {
262
+ const stagedAbs = path.join(root, staged);
263
+ const files = seams.listFiles(stagedAbs, stagedAbs);
264
+ for (const rel of files) {
265
+ const candidates = [];
266
+ if (rel.startsWith('vendor/')) {
267
+ const trimmed = rel.slice('vendor/'.length);
268
+ candidates.push(path.join(root, trimmed));
269
+ candidates.push(path.join(root, faceRoot, trimmed));
270
+ if (face === 'desktop') {
271
+ const base = path.basename(trimmed);
272
+ for (const shared of ['client', 'mcp', 'covenant', 'commands', 'skills', 'tools', 'hosts']) {
273
+ candidates.push(path.join(root, shared, base));
274
+ }
275
+ candidates.push(path.join(root, base));
276
+ }
277
+ } else {
278
+ candidates.push(path.join(root, faceRoot, rel));
279
+ candidates.push(path.join(root, rel));
280
+ }
281
+ const source = candidates.find((c) => exists(c)) || null;
282
+ pairs.push({ face, staged: path.join(staged, rel), source, candidates });
283
+ }
284
+ }
285
+ return pairs;
286
+ }
287
+
288
+ function checkVendor(seams, injectedPairs) {
289
+ const pairs = injectedPairs || vendorPairs(seams);
290
+ const missingSource = [];
291
+ const mismatch = [];
292
+ let matched = 0;
293
+ let staged = 0;
294
+ for (const p of pairs) {
295
+ if (!seams.exists(path.join(seams.root, p.staged))) continue;
296
+ staged += 1;
297
+ if (!p.source) {
298
+ missingSource.push(p.staged);
299
+ continue;
300
+ }
301
+ let a;
302
+ let b;
303
+ try {
304
+ a = seams.hashFile(path.join(seams.root, p.source));
305
+ b = seams.hashFile(path.join(seams.root, p.staged));
306
+ } catch (err) {
307
+ mismatch.push({ staged: p.staged, source: p.source, error: String((err && err.message) || err) });
308
+ continue;
309
+ }
310
+ if (a === b) matched += 1;
311
+ else mismatch.push({ staged: p.staged, source: p.source });
312
+ }
313
+ return {
314
+ staged,
315
+ matched,
316
+ mismatch,
317
+ missingSource,
318
+ // A bundle that was never staged is *stale*, not corrupt: the sources are
319
+ // fine and the packaged faces are the only thing missing. That is a warn.
320
+ stale: pairs.length > 0 && staged === 0,
321
+ checked: pairs.length,
322
+ };
323
+ }
324
+
325
+ // ---------------------------------------------------------------------------
326
+ // The report
327
+ // ---------------------------------------------------------------------------
328
+
329
+ function readJson(seams, rel) {
330
+ const abs = path.join(seams.root, rel);
331
+ if (!seams.exists(abs)) return { ok: false, missing: true, value: null, path: rel };
332
+ let text;
333
+ try {
334
+ text = seams.readFile(abs);
335
+ } catch (err) {
336
+ return { ok: false, unreadable: true, value: null, path: rel, error: String((err && err.message) || err) };
337
+ }
338
+ if (text == null) return { ok: false, missing: true, value: null, path: rel };
339
+ try {
340
+ return { ok: true, value: JSON.parse(text), path: rel };
341
+ } catch (err) {
342
+ return { ok: false, unreadable: true, value: null, path: rel, error: String((err && err.message) || err) };
343
+ }
344
+ }
345
+
346
+ /** `undefined` when the seam was not supplied, so a caller knows to default. */
347
+ function resolveSeams(options) {
348
+ const o = options || {};
349
+ const env = o.env || {};
350
+ const base = defaultFs();
351
+ const supplied = o || {};
352
+ return {
353
+ root: o.root || repoDir(),
354
+ platform: o.platform || 'linux',
355
+ env,
356
+ exists: supplied.exists || base.exists,
357
+ readFile: supplied.readFile || base.readFile,
358
+ hashFile: supplied.hashFile || base.hashFile,
359
+ listFiles: supplied.listFiles || base.listFiles,
360
+ credentials: o.credentials || defaultCredentials(),
361
+ storePath: o.storePath || defaultStorePath(env),
362
+ registry: o.registry || defaultRegistry(),
363
+ electronPaths: o.electronPaths || defaultElectronPaths(env, o),
364
+ updateCache: o.updateCache,
365
+ saveUpdateCache: o.saveUpdateCache,
366
+ now: typeof o.now === 'number' ? o.now : 0,
367
+ guiRequested: Boolean(o.guiRequested),
368
+ guiImplied: o.guiImplied,
369
+ vendorPairs: o.vendorPairs,
370
+ };
371
+ }
372
+
373
+ /**
374
+ * Build the report and its exit code. Pure given the seams.
375
+ *
376
+ * @param {object} [options] the seam object documented at the top.
377
+ * @returns {{report: object, code: number}}
378
+ */
379
+ function diagnose(options) {
380
+ const seams = resolveSeams(options);
381
+ const problems = [];
382
+ const broken = (code, detail) => problems.push({ level: 'broken', code, detail });
383
+ const warn = (code, detail) => problems.push({ level: 'warn', code, detail });
384
+
385
+ // ── versions ─────────────────────────────────────────────────────────────
386
+ const productFile = readJson(seams, 'one/package.json');
387
+ const product = productFile.ok
388
+ ? { name: productFile.value.name || 'aegisone', version: String(productFile.value.version || '') }
389
+ : { name: 'aegisone', version: '' };
390
+ if (!productFile.ok) broken('product-unreadable', `one/package.json ${productFile.unreadable ? 'is unreadable' : 'is missing'}`);
391
+
392
+ let expected = null;
393
+ try {
394
+ // eslint-disable-next-line global-require
395
+ expected = require('./release.js').deriveFaceVersions(product.version);
396
+ } catch (err) {
397
+ expected = null;
398
+ if (productFile.ok) broken('product-version-invalid', `${product.version}: ${String((err && err.message) || err)}`);
399
+ }
400
+
401
+ const faces = {};
402
+ for (const { dir, package: pkg } of FACE_PACKAGES) {
403
+ const file = readJson(seams, `${dir}/package.json`);
404
+ const actual = file.ok ? String(file.value.version || '') : '';
405
+ const want = expected && expected[pkg] ? expected[pkg].version : null;
406
+ if (!file.ok) broken('face-unreadable', `${dir}/package.json ${file.unreadable ? 'is unreadable' : 'is missing'}`);
407
+ else if (want && actual !== want) {
408
+ broken('version-mismatch', `${pkg} is ${actual}, product ${product.version} derives ${want}`);
409
+ }
410
+ faces[pkg] = { dir, version: actual, expected: want, ok: Boolean(want && actual === want) };
411
+ }
412
+
413
+ // ── credential ───────────────────────────────────────────────────────────
414
+ let cred = { key: '', source: 'none', from: '' };
415
+ try {
416
+ cred = seams.credentials.resolve({ env: seams.env }) || cred;
417
+ } catch {
418
+ cred = { key: '', source: 'none', from: '' };
419
+ }
420
+ const electronPaths = seams.electronPaths || {};
421
+ let credentialSource = cred.key ? (cred.source === 'env' ? 'env' : cred.source === 'envfile' ? 'env-file' : 'env-file') : 'none';
422
+ if (!cred.key && electronPaths.keychain && seams.exists(electronPaths.keychain)) {
423
+ const text = (() => {
424
+ try {
425
+ return seams.readFile(electronPaths.keychain);
426
+ } catch {
427
+ return null;
428
+ }
429
+ })();
430
+ if (text && /encrypt|safeStorage/i.test(text)) credentialSource = 'keychain';
431
+ }
432
+ if (credentialSource === 'none') warn('no-credential', 'no credential found (env, credentials.json, or the OS keychain)');
433
+
434
+ // ── shared store ─────────────────────────────────────────────────────────
435
+ const store = { path: seams.storePath, exists: false, readable: null, legacy: null };
436
+ try {
437
+ store.exists = seams.exists(seams.storePath);
438
+ } catch {
439
+ store.exists = false;
440
+ }
441
+ let storeRel = store.path;
442
+ if (store.exists) {
443
+ let text = null;
444
+ try {
445
+ text = seams.readFile(store.path);
446
+ } catch (err) {
447
+ store.readable = false;
448
+ broken('store-unreadable', `${store.path}: ${String((err && err.message) || err)}`);
449
+ }
450
+ if (store.readable === null) {
451
+ if (text == null) {
452
+ store.readable = false;
453
+ broken('store-unreadable', `${store.path} exists but could not be read`);
454
+ } else {
455
+ try {
456
+ const parsed = JSON.parse(text);
457
+ store.readable = true;
458
+ store.legacy = (parsed && parsed.version) || null;
459
+ } catch (err) {
460
+ store.readable = false;
461
+ broken('store-unreadable', `${store.path} is not valid JSON: ${String((err && err.message) || err)}`);
462
+ }
463
+ }
464
+ }
465
+ storeRel = path.basename(store.path);
466
+ }
467
+ store.display = storeRel;
468
+
469
+ // ── vendor integrity ─────────────────────────────────────────────────────
470
+ let vendor;
471
+ try {
472
+ vendor = checkVendor(seams, seams.vendorPairs);
473
+ } catch (err) {
474
+ vendor = { staged: 0, matched: 0, mismatch: [], missingSource: [], stale: false, checked: 0, error: String((err && err.message) || err) };
475
+ broken('vendor-unreadable', vendor.error);
476
+ }
477
+ for (const m of vendor.mismatch) {
478
+ broken('vendor-hash-mismatch', `${m.staged} differs from ${m.source || 'its source'}`);
479
+ }
480
+ for (const m of vendor.missingSource) broken('vendor-source-missing', `${m} has no source to be re-derived from`);
481
+ if (vendor.stale) warn('vendor-stale', 'the ONE bundle has never been staged (one/vendor is empty) — run `npm run predist`');
482
+
483
+ // ── update state: the ONE check ──────────────────────────────────────────
484
+ const update = {
485
+ channel: 'npm',
486
+ current: product.version,
487
+ latest: null,
488
+ behind: false,
489
+ reason: null,
490
+ checkedAt: null,
491
+ cached: true,
492
+ action: 'none',
493
+ applier: 'npm',
494
+ instruction: null,
495
+ };
496
+ try {
497
+ const notice =
498
+ seams.registry.check({
499
+ current: product.version,
500
+ cache: seams.updateCache,
501
+ save: seams.saveUpdateCache,
502
+ now: seams.now,
503
+ }) || {};
504
+ update.latest = notice.latest || null;
505
+ update.behind = Boolean(notice.behind);
506
+ update.reason = notice.reason || null;
507
+ } catch (err) {
508
+ update.reason = 'unavailable';
509
+ update.error = String((err && err.message) || err);
510
+ }
511
+ try {
512
+ const plan = seams.registry.plan({ current: product.version, latest: update.latest, behind: update.behind });
513
+ if (plan) {
514
+ update.action = plan.action;
515
+ update.applier = plan.applier;
516
+ update.instruction = plan.instruction;
517
+ }
518
+ } catch {
519
+ /* the plan is a projection; without it the raw check still reports */
520
+ }
521
+ if (update.behind) {
522
+ warn('update-available', `${update.current} → ${update.latest} (${update.instruction || 'run the channel updater'})`);
523
+ }
524
+
525
+ // ── the window face, when it was asked for ───────────────────────────────
526
+ const electron = (electronPaths && electronPaths.electron) || null;
527
+ if (seams.guiRequested && !electron) {
528
+ broken('gui-without-electron', '--gui was requested but Electron is not installed — use --tui');
529
+ }
530
+
531
+ const brokenCount = problems.filter((p) => p.level === 'broken').length;
532
+ const warnCount = problems.filter((p) => p.level === 'warn').length;
533
+ const code = brokenCount ? EXIT.BROKEN : warnCount ? EXIT.WARN : EXIT.OK;
534
+
535
+ const report = {
536
+ aegis: 'one',
537
+ status: brokenCount ? 'broken' : warnCount ? 'warn' : 'healthy',
538
+ exitCode: code,
539
+ product,
540
+ faces,
541
+ credential: { source: credentialSource, found: Boolean(cred.key), from: cred.key ? cred.from : '' },
542
+ store: { path: store.path, exists: store.exists, readable: store.exists ? store.readable === true : null },
543
+ vendor: {
544
+ staged: vendor.staged,
545
+ matched: vendor.matched,
546
+ mismatched: vendor.mismatch.length,
547
+ missingSource: vendor.missingSource.length,
548
+ stale: vendor.stale,
549
+ },
550
+ update,
551
+ gui: {
552
+ requested: Boolean(seams.guiRequested),
553
+ electron: electron || null,
554
+ usable: Boolean(electron) && (!seams.guiImplied || seams.guiImplied),
555
+ },
556
+ problems,
557
+ };
558
+ return { report, code };
559
+ }
560
+
561
+ /** The same object, for a human. Derived from `report` — never a second truth. */
562
+ function render(report) {
563
+ const lines = [];
564
+ const pad = (s, n) => String(s) + ' '.repeat(Math.max(0, n - String(s).length));
565
+ lines.push(`aegis doctor — ${report.status} (exit ${report.exitCode})`);
566
+ lines.push(` product ${report.product.name} ${report.product.version}`);
567
+ for (const [pkg, f] of Object.entries(report.faces)) {
568
+ const tail = f.ok ? '' : ` (expected ${f.expected || 'unknown'})`;
569
+ lines.push(` ${pad(pkg, 14)} ${f.version || 'unknown'}${tail}`);
570
+ }
571
+ lines.push(` credential ${report.credential.source}`);
572
+ lines.push(` shared store ${report.store.path} ${report.store.exists ? (report.store.readable ? '(readable)' : '(unreadable)') : '(absent)'}`);
573
+ lines.push(
574
+ ` vendor ${report.vendor.staged} staged, ${report.vendor.matched} matching, ` +
575
+ `${report.vendor.mismatched} mismatched, ${report.vendor.missingSource} without a source` +
576
+ (report.vendor.stale ? ' (never staged)' : '')
577
+ );
578
+ const u = report.update;
579
+ lines.push(
580
+ ` update ${u.behind ? `${u.current} → ${u.latest}` : `${u.current} is current`}` +
581
+ ` (next: ${u.action}${u.instruction ? ` — ${u.instruction}` : ''})`
582
+ );
583
+ lines.push(` window face ${report.gui.electron ? `Electron at ${report.gui.electron}` : 'not installed'}`);
584
+ if (report.problems.length) {
585
+ lines.push(' problems:');
586
+ for (const p of report.problems) lines.push(` ${p.level === 'broken' ? '✗' : '!'} ${p.code}: ${p.detail}`);
587
+ }
588
+ return lines.join('\n') + '\n';
589
+ }
590
+
591
+ /** Does this argv ask the doctor about the window face? */
592
+ function wantsGui(argv, env) {
593
+ const args = Array.isArray(argv) ? argv : [];
594
+ if (args.includes('--gui')) return true;
595
+ return (env || {}).AEGISONE_FACE === 'gui';
596
+ }
597
+
598
+ /**
599
+ * `aegis doctor` — print and return an exit code.
600
+ *
601
+ * @param {string[]} argv arguments after `doctor`
602
+ * @param {object} [deps] seam overrides, plus `{ stdout, stderr }`
603
+ * @returns {number} EXIT.OK | EXIT.WARN | EXIT.BROKEN
604
+ */
605
+ function main(argv, deps) {
606
+ const d = deps || {};
607
+ const args = Array.isArray(argv) ? argv : [];
608
+ const out = d.stdout || process.stdout;
609
+ const env = d.env || process.env || {};
610
+ const options = Object.assign({}, d, { env, guiRequested: wantsGui(args, env) });
611
+ const { report, code } = diagnose(options);
612
+ const text = args.includes('--json') ? JSON.stringify(report) + '\n' : render(report);
613
+ try {
614
+ out.write(text);
615
+ } catch {
616
+ /* a closed pipe is not a broken install */
617
+ }
618
+ return code;
619
+ }
620
+
621
+ module.exports = {
622
+ EXIT,
623
+ FACE_PACKAGES,
624
+ wantsGui,
625
+ diagnose,
626
+ render,
627
+ main,
628
+ // Exported for tests and for a future `aegis doctor --fix`: the same seams.
629
+ vendorPairs,
630
+ resolveSeams,
631
+ };
632
+
633
+ // `aegis doctor` reaches main() through one/bin/aegis.js, but this file is also
634
+ // a program in its own right: `node one/src/doctor.js` is what runs when the bin
635
+ // is not on PATH, and what a bug report pastes. It shipped without this block,
636
+ // so that invocation printed nothing and exited 0 — "never silently do nothing",
637
+ // broken in the one command whose whole job is to say what is wrong. The guard
638
+ // is the same idiom as one/scripts/bundle.js and one/bin/aegis.js, and it is
639
+ // inert on import: `require('./doctor.js')` from the bin reads nothing, which is
640
+ // the property the ON seam rule under `one/` actually protects.
641
+ if (require.main === module) process.exitCode = main(process.argv.slice(2));