aegisone 1.0.53 → 1.0.55

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.53**
3
+ Product version: **1.0.55**
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"),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 s=t||{},{stdout:n,stderr:i,input:o}=r,a=void 0!==s.installed?s.installed:isInstalledLayout(s.binDir),c=s.updatePlan?s.updatePlan():productUpdate.plan({installed:a,env:o&&o.env||{}});if(!c.ok)return write(i,`aegis: ${c.msg}`),EXIT_USAGE;const u=s.fetchLatest||defaultFetchLatest(s.binDir);return productUpdate.check({current:PRODUCT.version,action:e.action},{fetchImpl:u}).then((t=>{for(const e of t.lines)write(n,e);if("apply"!==e.action)return!0===t.upToDate?0:1;const r=productUpdate.apply(c,t,{runImpl:s.runInstall||defaultRunInstall});if(r.ok){write(n,r.lines?r.lines[0]:"Installed.");for(const e of String(r.output||"").split("\n").slice(-6))e.trim()&&write(n,` ${e}`);return 0}return r.skipped?(write(n,` ${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,".."),s=[path.join(r,"client","update.js"),path.join(r,"vendor","cli","vendor","client","update.js")];for(const e of s)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 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)}}}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||{},s=r.stderr||process.stderr,n=r.stdout||process.stdout,i=r.input||probes.collect({argv:e}),o=Array.isArray(e)?{...i,argv:e}:i,a=release.versionRequest(o.argv);if(a){const e=a.verbose?r.readFaceVersions?r.readFaceVersions():readFaceVersions(r.binDir):null;return write(n,release.renderVersion({product:{name:PRODUCT.name,version:PRODUCT.version},faces:e})),0}if((r.helpRequest||productHelp.helpRequest)(o.argv))return write(n,productHelp.renderHelp({version:PRODUCT.version})),0;const c=(r.updateRequest||productUpdate.updateRequest)(o.argv);if(c&&"help"===c.action)return write(n,productUpdate.renderUsage(PRODUCT.version)),0;if(c)return runUpdate(c,r,{stdout:n,stderr:s,input:o});const u=(o.argv||[]).indexOf("doctor");if(-1!==u&&!(o.argv||[]).slice(0,u).some((e=>!e.startsWith("-")))){const e=r.doctor||require("../src/doctor.js"),t=Object.assign({env:o.env,stdout:n,electron:o._electron||r.electron||null},r.doctorDeps||{}),s=e.main((o.argv||[]).slice(u+1),t);return"number"==typeof s?s:EXIT_USAGE}const d=decide(o),p=r.permissions||require("../src/permissions.js"),l=(o.argv||[]).indexOf(p.SKIP_FLAG||"--dangerously-skip-permissions"),f=Boolean(o.tty&&o.tty.stdin&&o.tty.stdout),g=f?"interactive":"headless",h=r.stored||p.storedPermissionFacts(r.storedOpts||{}),m=p.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!==l,env:o.env,interactive:f,childKind:g});m.warning&&write(s,`aegis: ${m.warning}`),m.skip&&m.skipFromFlag&&write(s,p.skipReport(m));const w=-1===l?d.args:d.args.filter((e=>e!==(p.SKIP_FLAG||"--dangerously-skip-permissions"))),v=m.skipFromFlag?{AEGISONE_SKIP_PERMISSIONS:"1"}:{};if("1"===(o.env||{}).AEGISONE_PRINT_DECISION&&write(s,"aegis: decision "+JSON.stringify({face:d.face,kind:d.kind,reason:d.reason,args:w,skip:m.skip})),null===d.face)return write(s,`aegis: ${d.error}`),d.hint&&write(s,`aegis: ${d.hint}`),d.code||EXIT_USAGE;d.notice&&write(s,`aegis: ${d.notice} — running the terminal face.`);const I=r.spawnSync||spawnSync,S=r.spawn||spawn,E=Object.assign({},process.env,r.env||{});if(d.face===FACE.TUI){const e=o._cliBin||r.cliBin;return e?statusOf(I(process.execPath,[e,...w],{stdio:"inherit",env:Object.assign({},E,v),argv0:"aegiscode"})||{}):(write(s,"aegis: the terminal face is not installed beside aegisone."),write(s,"aegis: reinstall aegisone, or set AEGISONE_CLI_BIN to bin/aegiscode.js."),127)}const k=o._electron||r.electron,y=o._desktopMain||r.desktopMain,_=WIN.plan({decision:d,electron:Boolean(k),target:r.target||o.target});if(!_||!y)return write(s,"aegis: cannot open the window — Electron or the desktop entry point went missing after the check."),write(s,"aegis: Use --tui for the terminal face."),EXIT_USAGE;delete E.ELECTRON_RUN_AS_NODE;const U=WIN.open(_,{main:y,args:w,env:Object.assign({},E,v)},{openElectron:e=>S(process.execPath,[e.main,...e.args],{stdio:"inherit",env:e.env,detached:!1})});if(!U||!U.ok)return write(s,`aegis: cannot open the window — ${U&&U.msg||"no usable window plan"}.`),write(s,"aegis: Use --tui for the terminal face."),EXIT_USAGE;const O=U.handle;return new Promise((e=>{O.on("error",(t=>{write(s,`aegis: could not start the window: ${t&&t.message}`),e(1)})),O.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:EXIT_USAGE,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"),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 s=t||{},{stdout:n,stderr:i,input:o}=r,a=void 0!==s.installed?s.installed:isInstalledLayout(s.binDir),c=s.updatePlan?s.updatePlan():productUpdate.plan({installed:a,env:o&&o.env||{}});if(!c.ok)return write(i,`aegis: ${c.msg}`),EXIT_USAGE;const u=s.fetchLatest||defaultFetchLatest(s.binDir);return productUpdate.check({current:PRODUCT.version,action:e.action},{fetchImpl:u}).then((t=>{for(const e of t.lines)write(n,e);if("apply"!==e.action)return!0===t.upToDate?0:1;const r=productUpdate.apply(c,t,{runImpl:s.runInstall||defaultRunInstall});if(r.ok){write(n,r.lines?r.lines[0]:"Installed.");for(const e of String(r.output||"").split("\n").slice(-6))e.trim()&&write(n,` ${e}`);return 0}return r.skipped?(write(n,` ${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,".."),s=[path.join(r,"client","update.js"),path.join(r,"vendor","cli","vendor","client","update.js")];for(const e of s)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 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)}}}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||{},s=r.stderr||process.stderr,n=r.stdout||process.stdout,i=r.input||probes.collect({argv:e}),o=Array.isArray(e)?{...i,argv:e}:i,a=release.versionRequest(o.argv);if(a){const e=a.verbose?r.readFaceVersions?r.readFaceVersions():readFaceVersions(r.binDir):null;return write(n,release.renderVersion({product:{name:PRODUCT.name,version:PRODUCT.version},faces:e})),0}if((r.helpRequest||productHelp.helpRequest)(o.argv))return write(n,productHelp.renderHelp({version:PRODUCT.version})),0;const c=(r.updateRequest||productUpdate.updateRequest)(o.argv);if(c&&"help"===c.action)return write(n,productUpdate.renderUsage(PRODUCT.version)),0;if(c)return runUpdate(c,r,{stdout:n,stderr:s,input:o});const u=(o.argv||[]).indexOf("doctor");if(-1!==u&&!(o.argv||[]).slice(0,u).some((e=>!e.startsWith("-")))){const e=r.doctor||require("../src/doctor.js"),t=Object.assign({env:o.env,stdout:n,electron:o._electron||r.electron||null},r.doctorDeps||{}),s=e.main((o.argv||[]).slice(u+1),t);return"number"==typeof s?s:EXIT_USAGE}const d=decide(o),p=r.permissions||require("../src/permissions.js"),l=(o.argv||[]).indexOf(p.SKIP_FLAG||"--dangerously-skip-permissions"),f=Boolean(o.tty&&o.tty.stdin&&o.tty.stdout),g=f?"interactive":"headless",h=r.stored||p.storedPermissionFacts(r.storedOpts||{}),m=p.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!==l,env:o.env,interactive:f,childKind:g});m.warning&&write(s,`aegis: ${m.warning}`),m.skip&&m.skipFromFlag&&write(s,p.skipReport(m));const w=-1===l?d.args:d.args.filter((e=>e!==(p.SKIP_FLAG||"--dangerously-skip-permissions"))),v=m.skipFromFlag?{AEGISONE_SKIP_PERMISSIONS:"1"}:{},I={AEGIS_INSTALL_METHOD:"npm"};if("1"===(o.env||{}).AEGISONE_PRINT_DECISION&&write(s,"aegis: decision "+JSON.stringify({face:d.face,kind:d.kind,reason:d.reason,args:w,skip:m.skip})),null===d.face)return write(s,`aegis: ${d.error}`),d.hint&&write(s,`aegis: ${d.hint}`),d.code||EXIT_USAGE;d.notice&&write(s,`aegis: ${d.notice} — running the terminal face.`);const S=r.spawnSync||spawnSync,E=r.spawn||spawn,_=Object.assign({},process.env,r.env||{});if(d.face===FACE.TUI){const e=o._cliBin||r.cliBin;return e?statusOf(S(process.execPath,[e,...w],{stdio:"inherit",env:Object.assign({},_,v,I),argv0:"aegiscode"})||{}):(write(s,"aegis: the terminal face is not installed beside aegisone."),write(s,"aegis: reinstall aegisone, or set AEGISONE_CLI_BIN to bin/aegiscode.js."),127)}const k=o._electron||r.electron,y=o._desktopMain||r.desktopMain,O=WIN.plan({decision:d,electron:Boolean(k),target:r.target||o.target});if(!O||!y)return write(s,"aegis: cannot open the window — Electron or the desktop entry point went missing after the check."),write(s,"aegis: Use --tui for the terminal face."),EXIT_USAGE;delete _.ELECTRON_RUN_AS_NODE;const U=WIN.open(O,{main:y,args:w,env:Object.assign({},_,v,I)},{openElectron:e=>E(process.execPath,[e.main,...e.args],{stdio:"inherit",env:e.env,detached:!1})});if(!U||!U.ok)return write(s,`aegis: cannot open the window — ${U&&U.msg||"no usable window plan"}.`),write(s,"aegis: Use --tui for the terminal face."),EXIT_USAGE;const j=U.handle;return new Promise((e=>{j.on("error",(t=>{write(s,`aegis: could not start the window: ${t&&t.message}`),e(1)})),j.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:EXIT_USAGE,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.53",
4
+ "version": "1.0.55",
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",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "aegiscode",
3
3
  "productName": "AEGIS Code",
4
- "version": "7.0.45",
4
+ "version": "7.0.47",
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",
@@ -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{resolveClientModule:resolveClientModule}=require("./shared.js"),{maskKey:maskKey}=require("./format.js"),{openUrl:defaultOpenUrl}=require("./system.js");function load(){return{credentials:require(resolveClientModule("credentials.js")),autoProvision:require(resolveClientModule("auto-provision.js")),client:require(resolveClientModule("aegis.js")),vault:require(resolveClientModule("record-vault.js")),googleSignIn:require(resolveClientModule("google-signin.js"))}}const HELP="aegiscode connect — sign this machine in (and register it, if it is new).\n\nUsage:\n aegiscode connect sign in with Google (default) — opens a\n browser; the key this machine saves is\n tied to that account, so the same account\n comes back on any machine signed in with it\n aegiscode connect --anonymous sign in with an anonymous per-machine key\n instead (no Google identity involved);\n registers this device if it has no account\n yet (one request, idempotent per machine —\n a machine that registered before gets the\n same account back)\n aegiscode connect --status is this machine connected? (--json; exit 1\n when it is not)\n aegiscode connect --logout forget the saved key on this machine\n aegiscode connect --help\n\nWhat it gives you, with no further setup:\n cloud memory sync, conversation sync, and the DEFAULT RECORD VAULT\n (aegiscode fingerprint publish goes to your account vault).\n\nIt writes the same key `aegiscode login` writes, so a key you already saved is\nused as-is: this never replaces a working credential.\n\nOptions:\n --status report only; changes nothing\n --anonymous, --device sign in with the anonymous per-machine key, not Google\n --google sign in with Google (the default — accepted explicitly too)\n --logout remove the saved key from this machine\n --json machine-readable output\n --app NAME the host name sent to the server (default: cli)\n --base URL API base (same as $AEGIS_API_BASE)";function flag(e,n){for(let t=0;t<e.length;t+=1){const o=String(e[t]);if(o===n&&void 0!==e[t+1]&&!String(e[t+1]).startsWith("--"))return e[t+1];if(o.startsWith(`${n}=`))return o.slice(n.length+1)}return null}function has(e,n){return(Array.isArray(e)?e:[]).some((e=>e===n||String(e).startsWith(`${n}=`)))}function storeFor(e,n){const t=e.aegisHome(n);return{dir:t,keyStatus:()=>e.keyStatus({env:n,dir:t}),clearApiKey:()=>e.clearApiKey(t),saveApiKey:n=>e.saveApiKey(n,t)}}function report(e,n,t){const o=e.keyStatus({env:t,dir:e.aegisHome(t)});let s=null;try{s=n.vaultTarget(t,[]).backend}catch{s=null}return{connected:Boolean(o.configured),source:o.source||"none",path:o.path||null,file_mode:o.fileMode||null,memory_token:Boolean(o.configured&&o.memoryToken),vault_backend:s,masked:o.configured?maskKey(o.key):null}}async function runConnect(e=[],n={}){const t={stdout:process.stdout,stderr:process.stderr,env:process.env,json:!1,...n,json:Boolean(n.json)||has(e,"--json")},o=(e,n)=>(t.json?t.stdout.write(JSON.stringify({connected:!1,error:n},null,2)+"\n"):t.stderr.write(`aegiscode: ${n}\n`),e);try{if(has(e,"--help")||has(e,"-h"))return t.stdout.write(HELP+"\n"),0;const{credentials:s,autoProvision:i,client:r,vault:a,googleSignIn:c}=load(),l=flag(e,"--base");l&&(t.env.AEGIS_API_BASE=l);const u=storeFor(s,t.env);if(has(e,"--logout")){const e=u.clearApiKey();return t.json?t.stdout.write(JSON.stringify({connected:!1,cleared:e.cleared},null,2)+"\n"):t.stdout.write(e.cleared?`aegiscode: key removed from ${e.path} — this machine is signed out\n`:"aegiscode: this machine had no saved key\n"),0}if(has(e,"--status")){const e=report(s,a,t.env);return t.json?t.stdout.write(JSON.stringify(e,null,2)+"\n"):t.stdout.write(["connected: "+(e.connected?"yes":"no"),`key: ${e.masked||"not set"}${e.file_mode?` (${e.file_mode})`:""}`,`source: ${e.source}`,`file: ${e.path||"-"}`,"memory: "+(e.memory_token?"token held (cloud sync ready)":"no token yet"),`vault: ${e.vault_backend||"unknown"} (record publishing)`,e.connected?"":"Sign in with: aegiscode connect"].filter((e=>""!==e)).join("\n")+"\n"),e.connected?0:1}const d=report(s,a,t.env);if(d.connected)return t.json?t.stdout.write(JSON.stringify({...d,already:!0},null,2)+"\n"):t.stdout.write([`already connected — ${d.masked} (${d.source})`,`vault: ${d.vault_backend}`,"","Nothing changed. Sign out first (`aegiscode connect --logout`) to switch accounts."].join("\n")+"\n"),0;if(!has(e,"--anonymous")&&!has(e,"--device")){const i=r.createClient(s.clientOptions({channel:"cli",env:t.env,dir:u.dir}));let l,d;try{l=await c.startGoogleSignIn({apiBase:i.apiBase})}catch(e){return o(2,`could not start the local sign-in server — ${e&&e.message||e}`)}t.json||t.stdout.write("aegiscode: opening a browser to sign in with Google…\n"),(n.openUrl||defaultOpenUrl)(l.url)||t.json||t.stdout.write(`aegiscode: could not open a browser automatically — open this URL:\n ${l.url}\n`);try{d=await l.wait()}catch(e){return o(2,`google sign-in did not complete — ${e&&e.message||e}`)}const g=u.saveApiKey(d.apiKey);if(!g.ok)return o(2,g.message||`could not save the key to ${g.path}`);d.memoryToken&&s.saveMemoryToken(d.memoryToken,{},u.dir);const h=report(s,a,t.env);return t.json?(t.stdout.write(JSON.stringify({...h,registered:!0,provider:"google",username:d.username},null,2)+"\n"),0):(t.stdout.write([`connected — ${h.masked}${d.username?` (signed in as ${d.username})`:""}`,`key saved to ${h.path}`,`vault ${h.vault_backend} — \`aegiscode fingerprint publish\` lands here`,h.memory_token?"Cloud memory sync is ready on this account.":"Cloud sync takes a moment to provision; the key is already valid."].join("\n")+"\n"),0)}const g=r.createClient(s.clientOptions({channel:"cli",env:t.env,dir:u.dir})),h=await i.autoProvisionApiKey(g,u,{app:flag(e,"--app")||"cli"});if(!h.key)return o(2,`could not register this device — ${i.provisionFailureText(h)}`);const m=report(s,a,t.env),y=i.trialOutcomeNote(h);return t.json?(t.stdout.write(JSON.stringify({...m,registered:!0,trial_granted:h.trialGranted,reused_account:Boolean(h.reusedAccount),saved:Boolean(h.ok)},null,2)+"\n"),h.ok?0:2):(t.stdout.write([`${h.reusedAccount?"welcome back":"connected"} — ${m.masked}`,`registered this machine${y}`,"key "+(h.ok?`saved to ${m.path}`:"COULD NOT SAVE — re-run `aegiscode connect`"),`vault ${m.vault_backend} — \`aegiscode fingerprint publish\` lands here`,"",m.memory_token?"Cloud memory sync is ready on this account.":"Cloud sync takes a moment to provision; the key is already valid.",h.reusedAccount?"":`Fund or inspect the account: ${g.promptUrl("topup","welcome_cloud")}`].filter(Boolean).join("\n")+"\n"),h.ok?0:2)}catch(e){return o(2,e&&e.message||String(e))}}module.exports={runConnect:runConnect,HELP:HELP,report:report};
3
+ "use strict";const{resolveClientModule:resolveClientModule}=require("./shared.js"),{maskKey:maskKey}=require("./format.js"),{openUrl:defaultOpenUrl}=require("./system.js");function load(){return{credentials:require(resolveClientModule("credentials.js")),autoProvision:require(resolveClientModule("auto-provision.js")),client:require(resolveClientModule("aegis.js")),vault:require(resolveClientModule("record-vault.js")),googleSignIn:require(resolveClientModule("google-signin.js")),fingerprint:require(resolveClientModule("device-fingerprint.js"))}}const HELP="aegiscode connect — sign this machine in (and register it, if it is new).\n\nUsage:\n aegiscode connect sign in with Google (default) — opens a\n browser; the key this machine saves is\n tied to that account, so the same account\n comes back on any machine signed in with it\n aegiscode connect --anonymous sign in with an anonymous per-machine key\n instead (no Google identity involved);\n registers this device if it has no account\n yet (one request, idempotent per machine —\n a machine that registered before gets the\n same account back)\n aegiscode connect --status is this machine connected? (--json; exit 1\n when it is not)\n aegiscode connect --logout forget the saved key on this machine\n aegiscode connect --help\n\nWhat it gives you, with no further setup:\n cloud memory sync, conversation sync, and the DEFAULT RECORD VAULT\n (aegiscode fingerprint publish goes to your account vault).\n\nIt writes the same key `aegiscode login` writes, so a key you already saved is\nused as-is: this never replaces a working credential.\n\nOptions:\n --status report only; changes nothing\n --anonymous, --device sign in with the anonymous per-machine key, not Google\n --google sign in with Google (the default — accepted explicitly too)\n --logout remove the saved key from this machine\n --json machine-readable output\n --app NAME the host name sent to the server (default: cli)\n --base URL API base (same as $AEGIS_API_BASE)";function flag(e,n){for(let t=0;t<e.length;t+=1){const o=String(e[t]);if(o===n&&void 0!==e[t+1]&&!String(e[t+1]).startsWith("--"))return e[t+1];if(o.startsWith(`${n}=`))return o.slice(n.length+1)}return null}function has(e,n){return(Array.isArray(e)?e:[]).some((e=>e===n||String(e).startsWith(`${n}=`)))}function storeFor(e,n){const t=e.aegisHome(n);return{dir:t,keyStatus:()=>e.keyStatus({env:n,dir:t}),clearApiKey:()=>e.clearApiKey(t),saveApiKey:n=>e.saveApiKey(n,t)}}function report(e,n,t){const o=e.keyStatus({env:t,dir:e.aegisHome(t)});let i=null;try{i=n.vaultTarget(t,[]).backend}catch{i=null}return{connected:Boolean(o.configured),source:o.source||"none",path:o.path||null,file_mode:o.fileMode||null,memory_token:Boolean(o.configured&&o.memoryToken),vault_backend:i,masked:o.configured?maskKey(o.key):null}}async function runConnect(e=[],n={}){const t={stdout:process.stdout,stderr:process.stderr,env:process.env,json:!1,...n,json:Boolean(n.json)||has(e,"--json")},o=(e,n)=>(t.json?t.stdout.write(JSON.stringify({connected:!1,error:n},null,2)+"\n"):t.stderr.write(`aegiscode: ${n}\n`),e);try{if(has(e,"--help")||has(e,"-h"))return t.stdout.write(HELP+"\n"),0;const{credentials:i,autoProvision:s,client:r,vault:a,googleSignIn:c,fingerprint:l}=load(),u=flag(e,"--base");u&&(t.env.AEGIS_API_BASE=u);const d=storeFor(i,t.env);if(has(e,"--logout")){const e=d.clearApiKey();return t.json?t.stdout.write(JSON.stringify({connected:!1,cleared:e.cleared},null,2)+"\n"):t.stdout.write(e.cleared?`aegiscode: key removed from ${e.path} — this machine is signed out\n`:"aegiscode: this machine had no saved key\n"),0}if(has(e,"--status")){const e=report(i,a,t.env);return t.json?t.stdout.write(JSON.stringify(e,null,2)+"\n"):t.stdout.write(["connected: "+(e.connected?"yes":"no"),`key: ${e.masked||"not set"}${e.file_mode?` (${e.file_mode})`:""}`,`source: ${e.source}`,`file: ${e.path||"-"}`,"memory: "+(e.memory_token?"token held (cloud sync ready)":"no token yet"),`vault: ${e.vault_backend||"unknown"} (record publishing)`,e.connected?"":"Sign in with: aegiscode connect"].filter((e=>""!==e)).join("\n")+"\n"),e.connected?0:1}const g=report(i,a,t.env);if(g.connected)return t.json?t.stdout.write(JSON.stringify({...g,already:!0},null,2)+"\n"):t.stdout.write([`already connected — ${g.masked} (${g.source})`,`vault: ${g.vault_backend}`,"","Nothing changed. Sign out first (`aegiscode connect --logout`) to switch accounts."].join("\n")+"\n"),0;if(!has(e,"--anonymous")&&!has(e,"--device")){const s=r.createClient(i.clientOptions({channel:"cli",env:t.env,dir:d.dir})),u=flag(e,"--app")||"cli";let g,h;try{g=await c.startGoogleSignIn({apiBase:s.apiBase,fingerprint:l.machineFingerprint(),app:u})}catch(e){return o(2,`could not start the local sign-in server — ${e&&e.message||e}`)}t.json||t.stdout.write("aegiscode: opening a browser to sign in with Google…\n"),(n.openUrl||defaultOpenUrl)(g.url)||t.json||t.stdout.write(`aegiscode: could not open a browser automatically — open this URL:\n ${g.url}\n`);try{h=await g.wait()}catch(e){return o(2,`google sign-in did not complete — ${e&&e.message||e}`)}const m=d.saveApiKey(h.apiKey);if(!m.ok)return o(2,m.message||`could not save the key to ${m.path}`);h.memoryToken&&i.saveMemoryToken(h.memoryToken,{},d.dir);const y=report(i,a,t.env);return t.json?(t.stdout.write(JSON.stringify({...y,registered:!0,provider:"google",username:h.username},null,2)+"\n"),0):(t.stdout.write([`connected — ${y.masked}${h.username?` (signed in as ${h.username})`:""}`,`key saved to ${y.path}`,`vault ${y.vault_backend} — \`aegiscode fingerprint publish\` lands here`,y.memory_token?"Cloud memory sync is ready on this account.":"Cloud sync takes a moment to provision; the key is already valid."].join("\n")+"\n"),0)}const h=r.createClient(i.clientOptions({channel:"cli",env:t.env,dir:d.dir})),m=await s.autoProvisionApiKey(h,d,{app:flag(e,"--app")||"cli"});if(!m.key)return o(2,`could not register this device — ${s.provisionFailureText(m)}`);const y=report(i,a,t.env),p=s.trialOutcomeNote(m);return t.json?(t.stdout.write(JSON.stringify({...y,registered:!0,trial_granted:m.trialGranted,reused_account:Boolean(m.reusedAccount),saved:Boolean(m.ok)},null,2)+"\n"),m.ok?0:2):(t.stdout.write([`${m.reusedAccount?"welcome back":"connected"} — ${y.masked}`,`registered this machine${p}`,"key "+(m.ok?`saved to ${y.path}`:"COULD NOT SAVE — re-run `aegiscode connect`"),`vault ${y.vault_backend} — \`aegiscode fingerprint publish\` lands here`,"",y.memory_token?"Cloud memory sync is ready on this account.":"Cloud sync takes a moment to provision; the key is already valid.",m.reusedAccount?"":`Fund or inspect the account: ${h.promptUrl("topup","welcome_cloud")}`].filter(Boolean).join("\n")+"\n"),m.ok?0:2)}catch(e){return o(2,e&&e.message||String(e))}}module.exports={runConnect:runConnect,HELP:HELP,report:report};
@@ -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 http=require("node:http"),{URL:URL}=require("node:url");function escapeHtml(e){return String(null==e?"":e).replace(/[&<>"']/g,(e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[e])))}function page({ok:e,error:t,username:r,surface:n}){const a=e?"Signed in":"Sign-in failed",o="app"===n?"the app":"the terminal";return`<!doctype html><html><head><meta charset="utf-8"><title>${a} — AEGIS</title></head><body style="font:16px sans-serif;max-width:32rem;margin:4rem auto;text-align:center;"><h2>${a}</h2><p>${e?`Signed in${r?` as <b>${escapeHtml(r)}</b>`:""}. You can close this tab and return to ${o}.`:`Sign-in failed: ${escapeHtml(t||"no token was returned")}. You can close this tab and try again.`}</p></body></html>`}function buildAuthUrl(e,t){const r=new URL("/auth/google",e);return r.searchParams.set("callback",t),r.toString()}async function startGoogleSignIn({apiBase:e,host:t="127.0.0.1",timeoutMs:r=3e5,surface:n="terminal"}={}){if(!e)throw new Error("startGoogleSignIn requires apiBase");let a,o,s=!1;const i=new Promise(((e,t)=>{a=e,o=t})),u=http.createServer(((e,r)=>{let i;try{i=new URL(e.url,`http://${t}`)}catch{return void r.writeHead(400).end()}const l=i.searchParams.get("token"),c=i.searchParams.get("username"),m=i.searchParams.get("memory_token"),d=i.searchParams.get("error");l||d?(r.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),r.end(page({ok:Boolean(l),error:d,username:c,surface:n})),s||(s=!0,clearTimeout(h),u.close(),l?a({apiKey:l,username:c||null,memoryToken:m||null}):o(new Error(d||"no token was returned")))):r.writeHead(404).end()}));await new Promise(((e,r)=>{u.once("error",r),u.listen(0,t,e)}));const{port:l}=u.address(),c=buildAuthUrl(e,`http://${t}:${l}`),h=setTimeout((()=>{s||(s=!0,u.close(),o(new Error(`timed out after ${Math.round(r/1e3)}s waiting for the browser sign-in`)))}),r);return"function"==typeof h.unref&&h.unref(),{url:c,wait:()=>i}}module.exports={startGoogleSignIn:startGoogleSignIn,buildAuthUrl:buildAuthUrl};
3
+ "use strict";const http=require("node:http"),{URL:URL}=require("node:url");function escapeHtml(e){return String(null==e?"":e).replace(/[&<>"']/g,(e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[e])))}function page({ok:e,error:t,username:r,surface:n}){const a=e?"Signed in":"Sign-in failed",o="app"===n?"the app":"the terminal";return`<!doctype html><html><head><meta charset="utf-8"><title>${a} — AEGIS</title></head><body style="font:16px sans-serif;max-width:32rem;margin:4rem auto;text-align:center;"><h2>${a}</h2><p>${e?`Signed in${r?` as <b>${escapeHtml(r)}</b>`:""}. You can close this tab and return to ${o}.`:`Sign-in failed: ${escapeHtml(t||"no token was returned")}. You can close this tab and try again.`}</p></body></html>`}function buildAuthUrl(e,t,{fingerprint:r,app:n}={}){const a=new URL("/auth/google",e);return a.searchParams.set("callback",t),r&&a.searchParams.set("fingerprint",String(r)),n&&a.searchParams.set("app",String(n)),a.toString()}async function startGoogleSignIn({apiBase:e,host:t="127.0.0.1",timeoutMs:r=3e5,surface:n="terminal",fingerprint:a=null,app:o=null}={}){if(!e)throw new Error("startGoogleSignIn requires apiBase");let i,s,l=!1;const u=new Promise(((e,t)=>{i=e,s=t})),c=http.createServer(((e,r)=>{let a;try{a=new URL(e.url,`http://${t}`)}catch{return void r.writeHead(400).end()}const o=a.searchParams.get("token"),u=a.searchParams.get("username"),p=a.searchParams.get("memory_token"),h=a.searchParams.get("error");o||h?(r.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),r.end(page({ok:Boolean(o),error:h,username:u,surface:n})),l||(l=!0,clearTimeout(m),c.close(),o?i({apiKey:o,username:u||null,memoryToken:p||null}):s(new Error(h||"no token was returned")))):r.writeHead(404).end()}));await new Promise(((e,r)=>{c.once("error",r),c.listen(0,t,e)}));const{port:p}=c.address(),h=buildAuthUrl(e,`http://${t}:${p}`,{fingerprint:a,app:o}),m=setTimeout((()=>{l||(l=!0,c.close(),s(new Error(`timed out after ${Math.round(r/1e3)}s waiting for the browser sign-in`)))}),r);return"function"==typeof m.unref&&m.unref(),{url:h,wait:()=>u}}module.exports={startGoogleSignIn:startGoogleSignIn,buildAuthUrl:buildAuthUrl};
@@ -134,7 +134,7 @@ const UNITS = Object.freeze([
134
134
  * (`tools/desktop-seal.mjs` in the source tree, `tools/obfuscate-faces.mjs`
135
135
  * after obfuscation), never by hand.
136
136
  */
137
- const SEALED = '748b1a00ed6c17df08b27b27d4f90eda70b75ab0fc56ab6f50f643952748c580';
137
+ const SEALED = 'ddcc46761db6f3f1ae5c427cc59aaef440bc4949998dc0dfc7d5cf94296ed5db';
138
138
 
139
139
  /**
140
140
  * Ask the question. Never throws — a check that can break the program it is
@@ -4257,6 +4257,59 @@ function describeRegistryFailure(reason, status, pkg) {
4257
4257
  }
4258
4258
  }
4259
4259
 
4260
+ /**
4261
+ * Who owns the copy that is actually running.
4262
+ *
4263
+ * WHY THIS IS NOT A CONSTANT
4264
+ *
4265
+ * This manager used to hardcode `PKG = 'aegis-desktop'`. That is correct for a
4266
+ * global `npm i -g aegis-desktop` and WRONG for the product install: `aegis`
4267
+ * launches `<aegisone>/vendor/desktop`, and `npm i -g aegis-desktop@latest`
4268
+ * never touches that path. The banner would announce the standalone package's
4269
+ * newer version and offer a command that installs a second copy beside the one
4270
+ * the user is looking at — the silent no-op the packaged branch already guards
4271
+ * against, one case over — while the `aegisone` update they actually have
4272
+ * pending went unmentioned.
4273
+ *
4274
+ * The tell is the path: a vendored launch lives at `<aegisone>/vendor/desktop`,
4275
+ * so the product manifest is two levels up. Everything else is a standalone
4276
+ * desktop install (global npm, checkout) and keeps naming `aegis-desktop`.
4277
+ *
4278
+ * The version that matters follows the owner. In a vendored launch it is the
4279
+ * PRODUCT's version, not this face's: the faces ship in lockstep inside
4280
+ * `aegisone` (derived from one product number at release time — see
4281
+ * `tools/release-npm.mjs` and `test/one-version.test.mjs`), so comparing the
4282
+ * vendored face against `aegis-desktop@latest` reports "available" for a
4283
+ * product that is already current, and offers a command that cannot satisfy it.
4284
+ *
4285
+ * Pure and injectable (`dir`, `readJson`) so both layouts are testable without
4286
+ * one of them existing on disk.
4287
+ */
4288
+ function resolveUpdateOwner({
4289
+ dir = __dirname,
4290
+ readJson = (p) => JSON.parse(fs.readFileSync(p, 'utf8')),
4291
+ } = {}) {
4292
+ const marker = `${path.sep}vendor${path.sep}desktop`;
4293
+ const at = String(dir).lastIndexOf(marker);
4294
+ if (at > 0) {
4295
+ const productDir = String(dir).slice(0, at);
4296
+ try {
4297
+ const version = readJson(path.join(productDir, 'package.json')).version;
4298
+ if (version) return { pkg: 'aegisone', current: String(version), productDir };
4299
+ } catch {
4300
+ // No readable product manifest: fall through to the standalone identity
4301
+ // rather than claiming an owner we could not read a version for.
4302
+ }
4303
+ }
4304
+ try {
4305
+ const version = readJson(path.join(dir, 'package.json')).version;
4306
+ if (version) return { pkg: 'aegis-desktop', current: String(version), productDir: null };
4307
+ } catch {
4308
+ /* version is cosmetic here */
4309
+ }
4310
+ return { pkg: 'aegis-desktop', current: 'unknown', productDir: null };
4311
+ }
4312
+
4260
4313
  function createNpmUpdateManager({
4261
4314
  onStatus,
4262
4315
  // A packaged build (AppImage/deb/NSIS/dmg) is NOT the npm copy. `npm i -g`
@@ -4274,14 +4327,13 @@ function createNpmUpdateManager({
4274
4327
  // killing the test runner's own process.
4275
4328
  runUpgrade,
4276
4329
  relaunch,
4330
+ // Injectable so a test can assert both layouts. Defaults to asking the
4331
+ // filesystem which copy this is (see `resolveUpdateOwner`).
4332
+ owner: ownerOverride,
4277
4333
  } = {}) {
4278
- const PKG = 'aegis-desktop';
4279
- let current = 'unknown';
4280
- try {
4281
- current = require('./package.json').version;
4282
- } catch {
4283
- /* version is cosmetic here */
4284
- }
4334
+ const owner = ownerOverride || resolveUpdateOwner();
4335
+ const PKG = owner.pkg;
4336
+ let current = owner.current;
4285
4337
  // `reason`/`transient`/`attempts`/`retryInMs`/`canDownload` are additive: the
4286
4338
  // banner needs them to decide whether a failure deserves the user's
4287
4339
  // attention at all, and whether there is a button worth offering.
@@ -5693,6 +5745,12 @@ function bootstrap() {
5693
5745
  }
5694
5746
  },
5695
5747
  onAccountChange: () => broadcastAccountStatus(accountKey.status()),
5748
+ // The same machine identity the presence beacon below sends (`install`),
5749
+ // so a Google sign-in is filed against this install's existing row instead
5750
+ // of a second one. A thunk, not a value: the module is required lazily out
5751
+ // of `client/` or `vendor/` (see sharedFingerprint at the top), so reading
5752
+ // it here would capture whatever the load-time try/catch left behind.
5753
+ machineFingerprint: () => sharedFingerprint.machineFingerprint(),
5696
5754
  });
5697
5755
  const keyPresentAtStart = Boolean(aegis.apiKey);
5698
5756
  const earlyKeyProvision = autoProvision.autoProvisionApiKey(aegis, credentials, { app: 'desktop' }).then((result) => {
@@ -6681,6 +6739,7 @@ module.exports = {
6681
6739
  isSafeExternalUrl,
6682
6740
  createUpdateManager,
6683
6741
  createNpmUpdateManager,
6742
+ resolveUpdateOwner,
6684
6743
  createUpdateDispatch,
6685
6744
  describeRegistryFailure,
6686
6745
  UPDATE_RETRY_BACKOFF_MS,
@@ -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";function createGoogleConnect({aegis:e,credentials:n,persistKey:t,openUrl:o,googleSignIn:r,driveConnect:i,driveUpload:a,conversationExport:s,getSession:c,getAuthor:l,onAccountChange:u}){let g=null,y=null,d=null,k=null,p=!1;function f(){try{const e="function"==typeof l?l():null;return{keyFingerprint:e&&e.keyFingerprint||null}}catch{return{keyFingerprint:null}}}function m(e){return s&&"function"==typeof s.authorLine?s.authorLine(e&&e.keyFingerprint):null}return{signInWithGoogle:function(){return g||(g=(async()=>{try{let i;try{i=await r.startGoogleSignIn({apiBase:e.apiBase})}catch(e){return{ok:!1,error:`could not start the local sign-in server — ${e&&e.message||e}`}}const a=Boolean(o(i.url));let s;try{s=await i.wait()}catch(e){return{ok:!1,opened:a,url:i.url,error:e&&e.message||String(e)}}if(e.setApiKey(s.apiKey),t(s.apiKey),s.memoryToken&&n&&"function"==typeof n.saveMemoryToken)try{n.saveMemoryToken(s.memoryToken)}catch{}return p=!0,"function"==typeof u&&u(),{ok:!0,opened:a,url:i.url,username:s.username||null}}finally{g=null}})()),g},connectDrive:async function(){return e.apiKey?(y||(y=(async()=>{try{let n=!0;try{const t=await i.driveStatus(e);n=!(t.googleLinkedKnown&&!t.googleLinked)}catch{}if(!n)return{ok:!1,error:"sign in with Google first — this account is not linked to a Google identity yet, and connecting Drive now would attach it to a different account"};const t=i.driveConnectUrl(e.apiBase),r=Boolean(o(t));try{const n=await i.waitForDriveConnected(e);return{ok:!0,opened:r,url:t,connected:n.connected,email:n.email}}catch(e){return{ok:!1,opened:r,url:t,error:e&&e.message||String(e)}}}finally{y=null}})()),y):{ok:!1,error:"sign in with Google first — this device has no AEGIS account key yet"}},status:async function(){if(!e.apiKey)return{signedIn:!1,googleLinked:!1,googleLinkedKnown:!0,connected:!1,email:null};const n=await i.driveStatus(e),t=!0===n.googleLinked||p;return{signedIn:t,...n,googleLinked:!0===n.googleLinked||t,googleLinkedKnown:n.googleLinkedKnown||t}},syncMemoryNow:async function(){try{const n=await e.driveToken();if(!n||!n.connected||!n.access_token)throw new Error("Google Drive is not connected yet");const t=await e.memoryPull(0),o=t&&t.entries||[],r=(new Date).toISOString(),i=JSON.stringify({exportedAt:r,entries:o},null,2),c=f(),l=s&&"function"==typeof s.memoryMarkdown?s.memoryMarkdown(i,{keyFingerprint:c.keyFingerprint,email:n.email||null,exportedAt:r,count:o.length}):i,u=await a.uploadMemoryBackup(n.access_token,l,{fileName:s?"aegis-memory-backup.md":void 0,mimeType:s?"text/markdown":void 0});return d=Date.now(),k=null,{ok:!0,count:o.length,fileId:u.fileId,webViewLink:u.webViewLink,updated:u.updated,author:m(c),lastSyncAt:d}}catch(e){return k=e&&e.message||String(e),{ok:!1,error:k,lastSyncAt:d}}},backupConversation:async function({sessionId:n}={}){try{if(!s||"function"!=typeof s.conversationMarkdown)return{ok:!1,error:"this build cannot export a conversation — the export module is missing"};const t=await e.driveToken();if(!t||!t.connected||!t.access_token)return{ok:!1,error:"connect Google Drive first — no Drive access token yet"};if(!n)return{ok:!1,error:"start a conversation first — there is nothing to save yet"};const o="function"==typeof c?c(n):null;if(!o)return{ok:!1,error:"that conversation is not in the session store yet — send one message, then save"};const r=o.messages||o.transcript||[];if(Array.isArray(r)&&0===r.length)return{ok:!1,error:"that conversation has no messages yet — nothing to save"};const i=(new Date).toISOString(),l=f(),u="function"==typeof s.toTranscript?s.toTranscript(o):o.markdown||"",g=s.conversationMarkdown(o,{transcript:u,keyFingerprint:l.keyFingerprint,email:t.email||null,exportedAt:i,count:Array.isArray(r)?r.length:null}),y=s.conversationFileName(o,i),d=await a.uploadConversation(t.access_token,{name:y,content:g});return{ok:!0,fileId:d.fileId,webViewLink:d.webViewLink,file:d.path||y,title:o.title||o.id||null,author:m(l)}}catch(e){return{ok:!1,error:e&&e.message||String(e)}}},state:()=>({lastSyncAt:d,lastSyncError:k})}}module.exports={createGoogleConnect:createGoogleConnect};
3
+ "use strict";function createGoogleConnect({aegis:e,credentials:n,persistKey:t,openUrl:o,googleSignIn:r,driveConnect:i,driveUpload:a,conversationExport:s,getSession:c,getAuthor:l,onAccountChange:u,machineFingerprint:g}){let y=null,d=null,k=null,p=null,f=!1;function m(){try{const e="function"==typeof l?l():null;return{keyFingerprint:e&&e.keyFingerprint||null}}catch{return{keyFingerprint:null}}}function h(e){return s&&"function"==typeof s.authorLine?s.authorLine(e&&e.keyFingerprint):null}return{signInWithGoogle:function(){return y||(y=(async()=>{try{let i;try{let n=null;try{n="function"==typeof g?g():null}catch{n=null}i=await r.startGoogleSignIn({apiBase:e.apiBase,fingerprint:n,app:"desktop"})}catch(e){return{ok:!1,error:`could not start the local sign-in server — ${e&&e.message||e}`}}const a=Boolean(o(i.url));let s;try{s=await i.wait()}catch(e){return{ok:!1,opened:a,url:i.url,error:e&&e.message||String(e)}}if(e.setApiKey(s.apiKey),t(s.apiKey),s.memoryToken&&n&&"function"==typeof n.saveMemoryToken)try{n.saveMemoryToken(s.memoryToken)}catch{}return f=!0,"function"==typeof u&&u(),{ok:!0,opened:a,url:i.url,username:s.username||null}}finally{y=null}})()),y},connectDrive:async function(){return e.apiKey?(d||(d=(async()=>{try{let n=!0;try{const t=await i.driveStatus(e);n=!(t.googleLinkedKnown&&!t.googleLinked)}catch{}if(!n)return{ok:!1,error:"sign in with Google first — this account is not linked to a Google identity yet, and connecting Drive now would attach it to a different account"};const t=i.driveConnectUrl(e.apiBase),r=Boolean(o(t));try{const n=await i.waitForDriveConnected(e);return{ok:!0,opened:r,url:t,connected:n.connected,email:n.email}}catch(e){return{ok:!1,opened:r,url:t,error:e&&e.message||String(e)}}}finally{d=null}})()),d):{ok:!1,error:"sign in with Google first — this device has no AEGIS account key yet"}},status:async function(){if(!e.apiKey)return{signedIn:!1,googleLinked:!1,googleLinkedKnown:!0,connected:!1,email:null};const n=await i.driveStatus(e),t=!0===n.googleLinked||f;return{signedIn:t,...n,googleLinked:!0===n.googleLinked||t,googleLinkedKnown:n.googleLinkedKnown||t}},syncMemoryNow:async function(){try{const n=await e.driveToken();if(!n||!n.connected||!n.access_token)throw new Error("Google Drive is not connected yet");const t=await e.memoryPull(0),o=t&&t.entries||[],r=(new Date).toISOString(),i=JSON.stringify({exportedAt:r,entries:o},null,2),c=m(),l=s&&"function"==typeof s.memoryMarkdown?s.memoryMarkdown(i,{keyFingerprint:c.keyFingerprint,email:n.email||null,exportedAt:r,count:o.length}):i,u=await a.uploadMemoryBackup(n.access_token,l,{fileName:s?"aegis-memory-backup.md":void 0,mimeType:s?"text/markdown":void 0});return k=Date.now(),p=null,{ok:!0,count:o.length,fileId:u.fileId,webViewLink:u.webViewLink,updated:u.updated,author:h(c),lastSyncAt:k}}catch(e){return p=e&&e.message||String(e),{ok:!1,error:p,lastSyncAt:k}}},backupConversation:async function({sessionId:n}={}){try{if(!s||"function"!=typeof s.conversationMarkdown)return{ok:!1,error:"this build cannot export a conversation — the export module is missing"};const t=await e.driveToken();if(!t||!t.connected||!t.access_token)return{ok:!1,error:"connect Google Drive first — no Drive access token yet"};if(!n)return{ok:!1,error:"start a conversation first — there is nothing to save yet"};const o="function"==typeof c?c(n):null;if(!o)return{ok:!1,error:"that conversation is not in the session store yet — send one message, then save"};const r=o.messages||o.transcript||[];if(Array.isArray(r)&&0===r.length)return{ok:!1,error:"that conversation has no messages yet — nothing to save"};const i=(new Date).toISOString(),l=m(),u="function"==typeof s.toTranscript?s.toTranscript(o):o.markdown||"",g=s.conversationMarkdown(o,{transcript:u,keyFingerprint:l.keyFingerprint,email:t.email||null,exportedAt:i,count:Array.isArray(r)?r.length:null}),y=s.conversationFileName(o,i),d=await a.uploadConversation(t.access_token,{name:y,content:g});return{ok:!0,fileId:d.fileId,webViewLink:d.webViewLink,file:d.path||y,title:o.title||o.id||null,author:h(l)}}catch(e){return{ok:!1,error:e&&e.message||String(e)}}},state:()=>({lastSyncAt:k,lastSyncError:p})}}module.exports={createGoogleConnect:createGoogleConnect};
@@ -134,7 +134,7 @@ const UNITS = Object.freeze([
134
134
  * (`tools/desktop-seal.mjs` in the source tree, `tools/obfuscate-faces.mjs`
135
135
  * after obfuscation), never by hand.
136
136
  */
137
- const SEALED = '748b1a00ed6c17df08b27b27d4f90eda70b75ab0fc56ab6f50f643952748c580';
137
+ const SEALED = 'ddcc46761db6f3f1ae5c427cc59aaef440bc4949998dc0dfc7d5cf94296ed5db';
138
138
 
139
139
  /**
140
140
  * Ask the question. Never throws — a check that can break the program it is
@@ -4257,6 +4257,59 @@ function describeRegistryFailure(reason, status, pkg) {
4257
4257
  }
4258
4258
  }
4259
4259
 
4260
+ /**
4261
+ * Who owns the copy that is actually running.
4262
+ *
4263
+ * WHY THIS IS NOT A CONSTANT
4264
+ *
4265
+ * This manager used to hardcode `PKG = 'aegis-desktop'`. That is correct for a
4266
+ * global `npm i -g aegis-desktop` and WRONG for the product install: `aegis`
4267
+ * launches `<aegisone>/vendor/desktop`, and `npm i -g aegis-desktop@latest`
4268
+ * never touches that path. The banner would announce the standalone package's
4269
+ * newer version and offer a command that installs a second copy beside the one
4270
+ * the user is looking at — the silent no-op the packaged branch already guards
4271
+ * against, one case over — while the `aegisone` update they actually have
4272
+ * pending went unmentioned.
4273
+ *
4274
+ * The tell is the path: a vendored launch lives at `<aegisone>/vendor/desktop`,
4275
+ * so the product manifest is two levels up. Everything else is a standalone
4276
+ * desktop install (global npm, checkout) and keeps naming `aegis-desktop`.
4277
+ *
4278
+ * The version that matters follows the owner. In a vendored launch it is the
4279
+ * PRODUCT's version, not this face's: the faces ship in lockstep inside
4280
+ * `aegisone` (derived from one product number at release time — see
4281
+ * `tools/release-npm.mjs` and `test/one-version.test.mjs`), so comparing the
4282
+ * vendored face against `aegis-desktop@latest` reports "available" for a
4283
+ * product that is already current, and offers a command that cannot satisfy it.
4284
+ *
4285
+ * Pure and injectable (`dir`, `readJson`) so both layouts are testable without
4286
+ * one of them existing on disk.
4287
+ */
4288
+ function resolveUpdateOwner({
4289
+ dir = __dirname,
4290
+ readJson = (p) => JSON.parse(fs.readFileSync(p, 'utf8')),
4291
+ } = {}) {
4292
+ const marker = `${path.sep}vendor${path.sep}desktop`;
4293
+ const at = String(dir).lastIndexOf(marker);
4294
+ if (at > 0) {
4295
+ const productDir = String(dir).slice(0, at);
4296
+ try {
4297
+ const version = readJson(path.join(productDir, 'package.json')).version;
4298
+ if (version) return { pkg: 'aegisone', current: String(version), productDir };
4299
+ } catch {
4300
+ // No readable product manifest: fall through to the standalone identity
4301
+ // rather than claiming an owner we could not read a version for.
4302
+ }
4303
+ }
4304
+ try {
4305
+ const version = readJson(path.join(dir, 'package.json')).version;
4306
+ if (version) return { pkg: 'aegis-desktop', current: String(version), productDir: null };
4307
+ } catch {
4308
+ /* version is cosmetic here */
4309
+ }
4310
+ return { pkg: 'aegis-desktop', current: 'unknown', productDir: null };
4311
+ }
4312
+
4260
4313
  function createNpmUpdateManager({
4261
4314
  onStatus,
4262
4315
  // A packaged build (AppImage/deb/NSIS/dmg) is NOT the npm copy. `npm i -g`
@@ -4274,14 +4327,13 @@ function createNpmUpdateManager({
4274
4327
  // killing the test runner's own process.
4275
4328
  runUpgrade,
4276
4329
  relaunch,
4330
+ // Injectable so a test can assert both layouts. Defaults to asking the
4331
+ // filesystem which copy this is (see `resolveUpdateOwner`).
4332
+ owner: ownerOverride,
4277
4333
  } = {}) {
4278
- const PKG = 'aegis-desktop';
4279
- let current = 'unknown';
4280
- try {
4281
- current = require('./package.json').version;
4282
- } catch {
4283
- /* version is cosmetic here */
4284
- }
4334
+ const owner = ownerOverride || resolveUpdateOwner();
4335
+ const PKG = owner.pkg;
4336
+ let current = owner.current;
4285
4337
  // `reason`/`transient`/`attempts`/`retryInMs`/`canDownload` are additive: the
4286
4338
  // banner needs them to decide whether a failure deserves the user's
4287
4339
  // attention at all, and whether there is a button worth offering.
@@ -5693,6 +5745,12 @@ function bootstrap() {
5693
5745
  }
5694
5746
  },
5695
5747
  onAccountChange: () => broadcastAccountStatus(accountKey.status()),
5748
+ // The same machine identity the presence beacon below sends (`install`),
5749
+ // so a Google sign-in is filed against this install's existing row instead
5750
+ // of a second one. A thunk, not a value: the module is required lazily out
5751
+ // of `client/` or `vendor/` (see sharedFingerprint at the top), so reading
5752
+ // it here would capture whatever the load-time try/catch left behind.
5753
+ machineFingerprint: () => sharedFingerprint.machineFingerprint(),
5696
5754
  });
5697
5755
  const keyPresentAtStart = Boolean(aegis.apiKey);
5698
5756
  const earlyKeyProvision = autoProvision.autoProvisionApiKey(aegis, credentials, { app: 'desktop' }).then((result) => {
@@ -6681,6 +6739,7 @@ module.exports = {
6681
6739
  isSafeExternalUrl,
6682
6740
  createUpdateManager,
6683
6741
  createNpmUpdateManager,
6742
+ resolveUpdateOwner,
6684
6743
  createUpdateDispatch,
6685
6744
  describeRegistryFailure,
6686
6745
  UPDATE_RETRY_BACKOFF_MS,
@@ -2,7 +2,7 @@
2
2
  "name": "aegis-desktop",
3
3
  "productName": "aegis one",
4
4
  "desktopName": "aegis-desktop",
5
- "version": "1.0.45",
5
+ "version": "1.0.47",
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",