aegisone 1.0.32 → 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
@@ -1,5 +1,791 @@
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(e,t){const n=function(){const e={cardStatus:"fp-card-status",cardOpen:"fp-open",overlay:"fp-overlay",backdrop:"fp-backdrop",close:"fp-close",keySource:"fp-key-source",keyPath:"fp-key-path",keyTag:"fp-key-tag",keyWarning:"fp-key-warning",vaultTarget:"fp-vault-target",vaultBackendDrive:"fp-vault-backend-drive",vaultBackendCloud:"fp-vault-backend-aegiscloud",vaultBackendOff:"fp-vault-backend-off",label:"fp-label",publishOnMint:"fp-publish-on-mint",autoSeal:"fp-auto-seal",autoSealLabel:"fp-auto-seal-label",autoHint:"fp-auto-hint",sealNow:"fp-seal-now",keygen:"fp-keygen",seal:"fp-seal",sealCard:"fp-seal-card",verify:"fp-verify",publish:"fp-publish",anchor:"fp-anchor",backupTo:"fp-backup-to",backup:"fp-backup",vault:"fp-vault",audit:"fp-audit",vaultList:"fp-vault-list",out:"fp-out",driveStatus:"fp-drive-status",driveSignIn:"fp-drive-signin",driveConnect:"fp-drive-connect",driveSyncNow:"fp-drive-sync",driveBackupChat:"fp-drive-backup-chat",driveHint:"fp-drive-hint"},t=e=>null==e||""===e?"–":String(e);function n(e){return e?!1===e.ok?e.error||"unavailable":e.configured?`key ${t(e.keyFingerprint)} · ${t(e.keySource)}`:"no key — mint one to seal records":"checking…"}function a(e){if(!e||!1===e.ok)return[{k:"state",v:e&&e.error||"unavailable"}];const n=[{k:"key",v:e.configured?e.keyFingerprint:"none"},{k:"source",v:t(e.keySource)},{k:"expected at",v:t(e.defaultKeyPath)},{k:"history",v:e.historyPresent?e.historyPath:"none yet"}];return e.configured&&e.keyPath&&e.keyPath!==e.defaultKeyPath&&n.splice(2,0,{k:"in use",v:e.keyPath}),n}function o(e){const t=e&&e.error?String(e.error):"";return/chmod/i.test(t)?t:""}function i(e){if(!e||!1===e.ok)return[{name:"vault unavailable",detail:e&&e.error||"unknown error"}];const t=Array.isArray(e.records)?e.records:Array.isArray(e.items)?e.items:Array.isArray(e.entries)?e.entries:[];return t.length?t.map((e=>{const t=e.name||e.file||e.path||e.id||"record",n=[e.id,e.publishedAt||e.createdAt,e.url].filter(Boolean);return{name:String(t),detail:n.join(" · ")}})):[{name:"nothing published yet",detail:""}]}function r(e){return e&&!1!==e.ok?e.signedIn?e.connected?"Google Drive connected"+(e.email?` · ${e.email}`:""):"signed in · Google Drive not connected yet":"not signed in — sign in with Google first":e&&e.error||"unavailable"}function s(e){if(!e||!1===e.ok)return{ok:!1,label:e&&e.error||"anchor check failed",claims:[]};const t=void 0!==e.present?e.present:e.presence,n=[{k:"present",v:t},{k:"unchanged",v:e.unchanged},{k:"attested",v:e.attested}],a=!0===t&&!0===e.unchanged&&!0===e.attested;return{ok:a,label:a?"the published copy is this record":"the published copy is not verifiably this record",claims:n}}function l(e){if(!e||!1===e.ok)return{ok:!1,label:e&&e.error||"audit failed",findings:[]};const t=Array.isArray(e.findings)?e.findings:Array.isArray(e.leaks)?e.leaks:Array.isArray(e.hits)?e.hits:[];return t.length?{ok:!1,label:`${t.length} item(s) in the vault look like key material`,findings:t}:{ok:!0,label:"no key material in the vault",findings:[]}}function u(e){if(!e||!1===e.ok)return{ok:!1,text:e&&e.error||"seal failed"};const n=e.record||{},a=[`sealed ${t(n.id)}`,`key ${t(n.keyFingerprint)}`,e.out];return a.push(n.aiKey?`ai ${t(n.ai)} on ${t(n.aiKey)}`:"ai unobserved"+(n.ai?` (${t(n.ai)})`:"")),e.vault&&e.vault.url?a.push(`published ${e.vault.url}`):e.vault&&a.push(`published ${t(e.vault.remote||e.vault.path)}`),e.vaultError&&a.push(`publish failed: ${e.vaultError}`),{ok:!0,text:a.filter(Boolean).join(" · "),file:e.out||null,record:e.record||null}}function c(e){if(!e||"object"!=typeof e)return"–";if(!0!==e.enabled)return"off — sealing stays a button";const t=[],n=Number(e.quietMs);return t.push(Number.isFinite(n)?`seals ${Math.round(n/1e3)}s after the last turn`:"seals when the session goes quiet"),e.publish&&t.push("publishes to the vault"),e.pendingTurns&&t.push(`${e.pendingTurns} turn${1===e.pendingTurns?"":"s"} pending`),e.seals&&t.push(`${e.seals} sealed`),e.failures&&t.push(`${e.failures} failed`),e.lastError&&t.push(`last error: ${e.lastError}`),t.join(" · ")}return{IDS:e,mount:function({api:d,doc:f,auto:p,getSessionId:k}={}){const y=f||("undefined"!=typeof document?document:null);if(!y)throw new Error("fingerprint: mount needs a document");const h=d||("undefined"!=typeof window?window.aegis:null),v=p||("undefined"!=typeof window?window.auto:null),b=e=>y.getElementById(e),g={status:null,last:null,busy:!1,mounted:!0};function $(t,n){const a=b(e.out);a&&(a.textContent=t,a.className=n?"fp-out fp-bad":"fp-out")}async function w(e,t){if(!h||"function"!=typeof h[e])return{ok:!1,error:`this build has no ${e} bridge`};try{const n=await h[e](t);return n&&"object"==typeof n?n:{ok:!1,error:`${e} returned nothing`}}catch(e){return{ok:!1,error:e&&e.message||String(e)}}}async function m(){const t=await w("getVaultBackend");return g.vaultBackend=t&&t.backend?t.backend:"aegiscloud",function(t){const n={drive:b(e.vaultBackendDrive),aegiscloud:b(e.vaultBackendCloud),off:b(e.vaultBackendOff)};for(const[e,a]of Object.entries(n))a&&a.setAttribute("aria-pressed",String(e===t))}(g.vaultBackend),g.vaultBackend}const S=e=>I("vault: "+("drive"===e?"Google Drive":"off"===e?"no sync":"AE"),(async()=>{const t=await w("setVaultBackend",e);return t&&t.backend?{ok:!0,...t}:{ok:!1,error:"could not save that"}}),{after:e=>e&&e.ok?L():null,say:e=>e.ok?`vault backend set to ${t(e.backend)}`:`could not save that: ${e.error}`});function B(){try{return"function"==typeof k&&k()||null}catch{return null}}async function C(){const t=await w("driveStatus");return g.drive=t,function(t){const n=b(e.driveStatus);n&&(n.textContent=r(t));const a=b(e.driveConnect);a&&(a.disabled=Boolean(t&&!t.signedIn));const o=Boolean(t&&t.connected),i=b(e.driveSyncNow);i&&(i.disabled=!o);const s=b(e.driveBackupChat);s&&(s.disabled=!(o&&Boolean(B())));const l=b(e.driveHint);l&&(l.textContent=o?"Each saved file starts with who wrote it, so it still makes sense in Drive without this app.":"Nothing is uploaded until you pick one of the two backups below.")}(t),t}const x=()=>I("sign in with Google",(()=>w("driveSignIn")),{after:e=>e&&e.ok?C():null,say:e=>e.ok?"signed in"+(e.username?` as ${e.username}`:""):`sign-in failed: ${e.error}`}),A=()=>I("connect Google Drive",(()=>w("driveConnect")),{after:e=>e&&e.ok?C():null,say:e=>e.ok?"Google Drive connected"+(e.email?` · ${e.email}`:""):`could not connect: ${e.error}`}),D=()=>I("back up all memory to Drive",(()=>w("driveSyncMemory")),{say:e=>e.ok?`backed up all ${e.count} memory entr${1===e.count?"y":"ies"}${e.author?` · authored ${e.author}`:""}${e.webViewLink?` → ${e.webViewLink}`:""}`:`backup failed: ${e.error}`}),N=()=>I("back up this conversation to Drive",(()=>w("driveBackupConversation",{sessionId:B()})),{say:e=>e.ok?`saved ${e.title?`“${e.title}”`:"this conversation"}${e.author?` · authored ${e.author}`:""}${e.webViewLink?` → ${e.webViewLink}`:""}`:`could not save this conversation: ${e.error}`});function V(t){const n=b(e.vaultList);if(n){n.textContent="";for(const e of i(t)){const t=y.createElement("li");t.className="fp-vault-row";const a=y.createElement("span");if(a.className="fp-vault-name",a.textContent=e.name,t.appendChild(a),e.detail){const n=y.createElement("span");n.className="fp-vault-detail",n.textContent=e.detail,t.appendChild(n)}n.appendChild(t)}}}async function L(){return g.status=await w("fingerprintStatus"),function(){const i=g.status,r=b(e.cardStatus);r&&(r.textContent=n(i));const s=b(e.keySource),l=b(e.keyPath),u=b(e.keyTag),c=b(e.keyWarning),d=b(e.vaultTarget),f=a(i),p=e=>{const t=f.find((t=>t.k===e));return t?t.v:"–"};if(s&&(s.textContent=p("source")),l&&(l.textContent=i&&i.keyPath?i.keyPath:p("expected at")),u&&(u.textContent=i&&i.configured?t(i.keyFingerprint):"none"),c){const e=o(i);c.textContent=e,c.hidden=!e}d&&i&&i.vault?
4
- // not where anything goes — printing `gdrive:AEGIS-AGPL/records` for a
5
- d.textContent="off"===i.vault.backend?"nothing — sync is off":"aegiscloud"===i.vault.backend?`aegiscloud:${t(i.vault.recordsDir)}`:`${t(i.vault.remote)}:${t(i.vault.recordsDir||i.vault.root)}`:d&&(d.textContent="–");const k=b(e.keygen);k&&(k.textContent=i&&i.configured?"Replace key…":"Mint key")}(),await O(),await m(),await C(),g.status}function M(t){if(!t||"object"!=typeof t)return;const n=b(e.autoSeal);n&&(n.checked=!0===t.enabled);const a=b(e.autoSealLabel);a&&(a.textContent=t.enabled?"sealing automatically when quiet":"seal automatically when quiet");const o=b(e.autoHint);o&&(o.textContent=c(t))}async function O(){if(!v||"function"!=typeof v.status){const t=b(e.autoHint);return t&&(t.textContent="this build has no automation bridge — sealing stays a button"),null}try{const e=await v.status();return e&&e.mint&&M(e.mint),e}catch(t){const n=b(e.autoHint);return n&&(n.textContent=`automation status unavailable: ${t&&t.message||String(t)}`),null}}async function P(){const n=Boolean(b(e.publishOnMint)&&b(e.publishOnMint).checked);return I("seal now",(async()=>v&&"function"==typeof v.sealNow?v.sealNow(n):{ok:!1,error:"this build has no automation bridge"}),{paint:e=>{e&&e.ok&&e.out&&(g.last={file:e.out,record:e.record||null})},say:e=>{if(!e)return"seal now: nothing happened";if(!1===e.ok)return`seal failed: ${e.error||"unknown"}`;if("skip"===e.type)return`nothing to seal (${e.reason||"no new turns"})`;const n=u(e);return n.ok?`sealed ${t((e.record||{}).id)} → ${t(e.out)}`:`seal failed: ${n.text}`}})}async function I(e,t,n){const a=n||{};if(g.busy)return null;g.busy=!0,$(`${e}…`,!1);try{const n=await t();return a.paint&&a.paint(n),a.after&&await a.after(n),$(a.say?a.say(n):`${e}: ${n&&!1===n.ok?n.error:"done"}`,Boolean(n&&!1===n.ok)),n}finally{g.busy=!1}}const E=()=>I("mint key",(()=>w("fingerprintKeygen",{force:Boolean(g.status&&g.status.configured)})),{after:L,say:e=>e.ok?`minted ${t(e.keyFingerprint)} at ${t(e.path)}`:`mint failed: ${e.error}`}),T=()=>{const e=b("model-select");return e&&e.value?e.value:null},j=()=>I("seal session",(()=>w("fingerprintMint",{label:b(e.label)&&b(e.label).value.trim()||null,publish:Boolean(b(e.publishOnMint)&&b(e.publishOnMint).checked),model:T()})),{paint:e=>{e.ok&&(g.last={file:e.out,record:e.record})},say:e=>{const n=u(e);return n.ok?`sealed ${t((e.record||{}).id)} → ${t(e.out)}`:`seal failed: ${n.text}`}}),F=()=>I("verify",(async()=>g.last&&g.last.file?w("fingerprintVerify",{file:g.last.file}):g.last&&g.last.record?w("fingerprintVerify",{record:g.last.record}):{ok:!1,error:"nothing sealed in this window yet — seal a session first"}),{say:e=>e.ok?`verified ${t(e.id)} · key ${t(e.keySource)}`:`not verified: ${e.error||e.reason}`}),G=()=>I("publish",(()=>g.last&&g.last.file?w("fingerprintPublish",{file:g.last.file}):g.last&&g.last.record?w("fingerprintPublish",{record:g.last.record}):{ok:!1,error:"nothing sealed in this window yet — seal a session first"}),{say:e=>e.ok?`published ${t(e.url||e.path)}${e.sha256?` · sha256 ${String(e.sha256).slice(0,12)}`:""}`:`publish failed: ${e.error}`}),H=()=>I("check anchor",(()=>g.last&&g.last.file?w("fingerprintAnchor",{file:g.last.file}):w("fingerprintAnchor",{})),{say:e=>{const t=s(e),n=t.claims.map((e=>`${e.k} ${!0===e.v?"yes":!1===e.v?"no":"unknown"}`)).join(" · ");return`${t.label}${n?` — ${n}`:""}`}}),K=()=>I("back up key",(()=>{const t=b(e.backupTo)&&b(e.backupTo).value.trim();return t?w("fingerprintBackup",{to:t}):{ok:!1,error:"backup needs a destination directory"}}),{say:e=>e.ok?`key copied to ${t(e.to||e.path)}`:`backup refused: ${e.error}`}),q=()=>I("list vault",(()=>w("fingerprintVault")),{paint:V,say:e=>e.ok?`vault listed — ${i(e).length} entry(ies)`:`vault unavailable: ${e.error}`}),R=()=>I("audit vault",(()=>w("fingerprintVaultAudit")),{say:e=>{const t=l(e),n=t.findings.map((e=>e&&(e.path||e.name)||String(e))).slice(0,3);return`${t.label}${n.length?` — ${n.join(", ")}`:""}`}});async function W(t){const n=b(e.overlay);if(!n)return;if(n.hidden=!1,y.body&&y.body.classList&&y.body.classList.add("fp-open"),await L(),await q(),t&&"drive"===t.focus){const t=b(e.driveStatus);t&&t.scrollIntoView&&t.scrollIntoView({block:"center"});const n=[e.driveSignIn,e.driveConnect,e.driveBackupChat,e.driveSyncNow].map(b).find((e=>e&&!e.disabled));return void(n&&n.focus())}const a=b(e.close);a&&a.focus()}function z(){const t=b(e.overlay);if(!t)return;t.hidden=!0,y.body&&y.body.classList&&y.body.classList.remove("fp-open");const n=b(e.cardOpen);n&&n.focus()}const J=(e,t,n)=>{const a=b(e);a&&a.addEventListener(t,n)};return J(e.cardOpen,"click",W),J(e.close,"click",z),J(e.backdrop,"click",z),J(e.keygen,"click",E),J(e.seal,"click",j),J(e.sealCard,"click",(async()=>{const e=await j();e&&e.ok&&await W()})),J(e.verify,"click",F),J(e.publish,"click",G),J(e.anchor,"click",H),J(e.backup,"click",K),J(e.vault,"click",q),J(e.audit,"click",R),J(e.vaultBackendDrive,"click",(()=>S("drive"))),J(e.vaultBackendCloud,"click",(()=>S("aegiscloud"))),J(e.vaultBackendOff,"click",(()=>S("off"))),J(e.driveSignIn,"click",x),J(e.driveConnect,"click",A),J(e.driveSyncNow,"click",D),J(e.driveBackupChat,"click",N),b(e.autoSeal)&&J(e.autoSeal,"change",(()=>{const t=b(e.autoSeal);return async function(t){if(!v||"function"!=typeof v.setMint)return null;const n=Boolean(b(e.publishOnMint)&&b(e.publishOnMint).checked);try{const e=await v.setMint({enabled:Boolean(t),publish:n});return e&&e.mint?M(e.mint):e&&!1===e.ok&&$(e.error||"could not save that",!0),e}catch(e){return $(`could not save that: ${e&&e.message||String(e)}`,!0),null}}(Boolean(t&&t.checked))})),b(e.sealNow)&&J(e.sealNow,"click",P),{open:W,close:z,isOpen:()=>{const t=b(e.overlay);return Boolean(t)&&!t.hidden},refresh:L,loadAutoMint:O,state:g,actions:{doKeygen:E,doSeal:j,doSealNow:P,doVerify:F,doPublish:G,doAnchor:H,doBackup:K,doVault:q,doAudit:R,doSetVaultBackend:S,doDriveSignIn:x,doDriveConnect:A,doDriveSyncNow:D,doDriveBackupChat:N},loadVaultBackend:m,loadDriveStatus:C}},keyLine:n,statusRows:a,keyWarning:o,vaultRows:i,anchorVerdict:s,auditVerdict:l,sealLine:u,autoMintLine:c,driveLine:r,dash:t}}();"undefined"!=typeof module&&module.exports&&(module.exports=n),e&&(e.aegisFingerprint=n)}("undefined"!=typeof window?window:null);
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
+ * fingerprint.js — the φ(α) panel: authorship key, sealed records, the vault.
10
+ *
11
+ * The IPC surface has existed since 5072779 (`fingerprintStatus` …
12
+ * `fingerprintVaultAudit`, desktop/preload.js:171-183, main.js:750-765) and
13
+ * until now nothing in desktop/renderer/ called any of it —
14
+ * `grep -rn fingerprint desktop/renderer/` returned nothing, so a GUI user had
15
+ * no button for a feature the terminal has had since `aegiscode fingerprint`.
16
+ * This file is that button.
17
+ *
18
+ * It obeys the same two rules the backend half already keeps:
19
+ *
20
+ * 1. **The key never reaches the DOM.** No payload from main carries
21
+ * `secret`, and nothing here invents a field that might. What gets painted
22
+ * is `status.keyFingerprint` — the derived 12-hex tag — which is public by
23
+ * construction (client/authorship-key.js prints exactly this).
24
+ * 2. **A refusal is shown, not swallowed.** Every handler resolves
25
+ * `{ ok: false, error }` instead of throwing, so the panel prints the
26
+ * reason ("this key file is readable by other users", "rclone is not
27
+ * installed") rather than an empty state that reads like success.
28
+ *
29
+ * Pure formatting (`keyLine`, `anchorVerdict`, `auditVerdict`, …) is kept
30
+ * separate from painting so test/renderer-fingerprint.test.mjs can assert the
31
+ * strings that carry the three-claim anchor verdict without standing up a DOM —
32
+ * and the functions it asserts are the exact ones that paint.
33
+ *
34
+ * Classic script, no imports: loaded before app.js by index.html and called
35
+ * from init(). It does not auto-mount, so requiring it under test has no side
36
+ * effects.
37
+ */
38
+
39
+ (function (root, factory) {
40
+ const api = factory();
41
+ // `module` first: under Node the test requires this file directly, and the
42
+ // renderer's `window` is not there.
43
+ if (typeof module !== 'undefined' && module.exports) module.exports = api;
44
+ if (root) root.aegisFingerprint = api;
45
+ })(typeof window !== 'undefined' ? window : null, function () {
46
+ /** Every id this file reads. The test asserts each one exists in index.html —
47
+ * a typo here is otherwise a silent no-op, which is how a panel ships with
48
+ * one dead button and no error. */
49
+ const IDS = {
50
+ cardStatus: 'fp-card-status',
51
+ cardOpen: 'fp-open',
52
+ overlay: 'fp-overlay',
53
+ backdrop: 'fp-backdrop',
54
+ close: 'fp-close',
55
+ keySource: 'fp-key-source',
56
+ keyPath: 'fp-key-path',
57
+ keyTag: 'fp-key-tag',
58
+ keyWarning: 'fp-key-warning',
59
+ vaultTarget: 'fp-vault-target',
60
+ vaultBackendDrive: 'fp-vault-backend-drive',
61
+ vaultBackendCloud: 'fp-vault-backend-aegiscloud',
62
+ vaultBackendOff: 'fp-vault-backend-off',
63
+ label: 'fp-label',
64
+ publishOnMint: 'fp-publish-on-mint',
65
+ autoSeal: 'fp-auto-seal',
66
+ autoSealLabel: 'fp-auto-seal-label',
67
+ autoHint: 'fp-auto-hint',
68
+ sealNow: 'fp-seal-now',
69
+ keygen: 'fp-keygen',
70
+ seal: 'fp-seal',
71
+ sealCard: 'fp-seal-card',
72
+ verify: 'fp-verify',
73
+ publish: 'fp-publish',
74
+ anchor: 'fp-anchor',
75
+ backupTo: 'fp-backup-to',
76
+ backup: 'fp-backup',
77
+ vault: 'fp-vault',
78
+ audit: 'fp-audit',
79
+ vaultList: 'fp-vault-list',
80
+ out: 'fp-out',
81
+ driveStatus: 'fp-drive-status',
82
+ driveSignIn: 'fp-drive-signin',
83
+ driveConnect: 'fp-drive-connect',
84
+ driveSyncNow: 'fp-drive-sync',
85
+ driveBackupChat: 'fp-drive-backup-chat',
86
+ driveHint: 'fp-drive-hint',
87
+ };
88
+
89
+ // ------------------------------------------------------------- formatting
90
+
91
+ const dash = (v) => (v === null || v === undefined || v === '' ? '–' : String(v));
92
+
93
+ /** The one-line state that goes in the sidebar card, where there is room for
94
+ * a sentence and not a table. */
95
+ function keyLine(status) {
96
+ if (!status) return 'checking…';
97
+ if (status.ok === false) return status.error || 'unavailable';
98
+ if (!status.configured) return 'no key — mint one to seal records';
99
+ return `key ${dash(status.keyFingerprint)} · ${dash(status.keySource)}`;
100
+ }
101
+
102
+ /** Everything the panel can say about the key without saying the key. */
103
+ function statusRows(status) {
104
+ if (!status || status.ok === false) {
105
+ return [{ k: 'state', v: (status && status.error) || 'unavailable' }];
106
+ }
107
+ const rows = [
108
+ { k: 'key', v: status.configured ? status.keyFingerprint : 'none' },
109
+ { k: 'source', v: dash(status.keySource) },
110
+ { k: 'expected at', v: dash(status.defaultKeyPath) },
111
+ { k: 'history', v: status.historyPresent ? status.historyPath : 'none yet' },
112
+ ];
113
+ // Only when it resolves somewhere else than expected is it worth a row: a
114
+ // key coming from AEGIS_AUTHORSHIP_SECRET or --secret is exactly the
115
+ // situation where "which key am I actually signing with" needs an answer.
116
+ if (status.configured && status.keyPath && status.keyPath !== status.defaultKeyPath) {
117
+ rows.splice(2, 0, { k: 'in use', v: status.keyPath });
118
+ }
119
+ return rows;
120
+ }
121
+
122
+ /** The 0644 refusal is the one failure where the fix is a command the user
123
+ * can run, so it is surfaced as a warning line rather than buried in the
124
+ * result pane. */
125
+ function keyWarning(status) {
126
+ const err = status && status.error ? String(status.error) : '';
127
+ return /chmod/i.test(err) ? err : '';
128
+ }
129
+
130
+ /** One line per vault entry. Tolerant of the key the shared module chooses,
131
+ * because the panel's job here is to show what came back, not to insist. */
132
+ function vaultRows(list) {
133
+ if (!list || list.ok === false) {
134
+ return [{ name: 'vault unavailable', detail: (list && list.error) || 'unknown error' }];
135
+ }
136
+ const items = Array.isArray(list.records) ? list.records
137
+ : Array.isArray(list.items) ? list.items
138
+ : Array.isArray(list.entries) ? list.entries
139
+ : [];
140
+ if (!items.length) return [{ name: 'nothing published yet', detail: '' }];
141
+ return items.map((it) => {
142
+ const name = it.name || it.file || it.path || it.id || 'record';
143
+ const parts = [it.id, it.publishedAt || it.createdAt, it.url].filter(Boolean);
144
+ return { name: String(name), detail: parts.join(' · ') };
145
+ });
146
+ }
147
+
148
+ /**
149
+ * The one-line summary of the Google Drive card — `desktop/lib/
150
+ * google-connect.js`'s `status()` shape, `{signedIn, connected, email}`.
151
+ *
152
+ * Three distinct states, because "not connected" means something different
153
+ * depending on whether this machine has signed in with Google at all:
154
+ * connecting Drive before signing in attaches the tokens to a different
155
+ * account than the one this machine polls (see google-connect.js's header
156
+ * comment), so the line has to say WHICH step is next, not just "no".
157
+ */
158
+ function driveLine(status) {
159
+ if (!status || status.ok === false) return (status && status.error) || 'unavailable';
160
+ if (!status.signedIn) return 'not signed in — sign in with Google first';
161
+ if (!status.connected) return 'signed in · Google Drive not connected yet';
162
+ return `Google Drive connected${status.email ? ` · ${status.email}` : ''}`;
163
+ }
164
+
165
+ /** The anchor answer, kept as three separate claims on purpose: "the file is
166
+ * gone", "the file was replaced" and "the key that sealed it has moved on"
167
+ * are three different situations, and one boolean hides the interesting one
168
+ * (client/record-vault.js checkAnchor). `present` is read as well as
169
+ * `presence` because that spelling was a real bug once. */
170
+ function anchorVerdict(a) {
171
+ if (!a || a.ok === false) {
172
+ return { ok: false, label: (a && a.error) || 'anchor check failed', claims: [] };
173
+ }
174
+ const present = a.present !== undefined ? a.present : a.presence;
175
+ const claims = [
176
+ { k: 'present', v: present },
177
+ { k: 'unchanged', v: a.unchanged },
178
+ { k: 'attested', v: a.attested },
179
+ ];
180
+ const ok = present === true && a.unchanged === true && a.attested === true;
181
+ return {
182
+ ok,
183
+ // Ambiguity is not success: an undefined claim is reported as unknown,
184
+ // never folded into a yes.
185
+ label: ok ? 'the published copy is this record' : 'the published copy is not verifiably this record',
186
+ claims,
187
+ };
188
+ }
189
+
190
+ /** What the audit found. A finding is a fact about the vault, not an error
191
+ * from it, so a clean run says so explicitly rather than showing nothing. */
192
+ function auditVerdict(a) {
193
+ if (!a || a.ok === false) return { ok: false, label: (a && a.error) || 'audit failed', findings: [] };
194
+ const findings = Array.isArray(a.findings) ? a.findings
195
+ : Array.isArray(a.leaks) ? a.leaks
196
+ : Array.isArray(a.hits) ? a.hits
197
+ : [];
198
+ if (findings.length) {
199
+ return { ok: false, label: `${findings.length} item(s) in the vault look like key material`, findings };
200
+ }
201
+ return { ok: true, label: 'no key material in the vault', findings: [] };
202
+ }
203
+
204
+ /** A minted record as the panel reports it. The local file is the evidence —
205
+ * a failed publish does not unseal it (desktop/lib/fingerprint.js mint) —
206
+ * so an upload failure is said beside the seal, not instead of it. */
207
+ function sealLine(r) {
208
+ if (!r || r.ok === false) return { ok: false, text: (r && r.error) || 'seal failed' };
209
+ const rec = r.record || {};
210
+ const bits = [`sealed ${dash(rec.id)}`, `key ${dash(rec.keyFingerprint)}`, r.out];
211
+ // Both halves of the session, in the record and in the line: the key that
212
+ // sealed it, and the mind that answered. An un-nominated AI credential reads
213
+ // as "ai unobserved", never as a borrowed key.
214
+ bits.push(
215
+ rec.aiKey
216
+ ? `ai ${dash(rec.ai)} on ${dash(rec.aiKey)}`
217
+ : `ai unobserved${rec.ai ? ` (${dash(rec.ai)})` : ''}`,
218
+ );
219
+ if (r.vault && r.vault.url) bits.push(`published ${r.vault.url}`);
220
+ else if (r.vault) bits.push(`published ${dash(r.vault.remote || r.vault.path)}`);
221
+ if (r.vaultError) bits.push(`publish failed: ${r.vaultError}`);
222
+ return { ok: true, text: bits.filter(Boolean).join(' · '), file: r.out || null, record: r.record || null };
223
+ }
224
+
225
+ // ---------------------------------------------------------------- painting
226
+
227
+ /**
228
+ * One line describing the auto-seal state, in the same voice as the rest of
229
+ * the panel: what is armed, what it has filed, and the last thing that went
230
+ * wrong. Pure, so the test asserts the string the panel paints.
231
+ */
232
+ function autoMintLine(s) {
233
+ if (!s || typeof s !== 'object') return '–';
234
+ if (s.enabled !== true) return 'off — sealing stays a button';
235
+ const bits = [];
236
+ const secs = Number(s.quietMs);
237
+ bits.push(Number.isFinite(secs) ? `seals ${Math.round(secs / 1000)}s after the last turn` : 'seals when the session goes quiet');
238
+ if (s.publish) bits.push('publishes to the vault');
239
+ if (s.pendingTurns) bits.push(`${s.pendingTurns} turn${s.pendingTurns === 1 ? '' : 's'} pending`);
240
+ if (s.seals) bits.push(`${s.seals} sealed`);
241
+ if (s.failures) bits.push(`${s.failures} failed`);
242
+ if (s.lastError) bits.push(`last error: ${s.lastError}`);
243
+ return bits.join(' · ');
244
+ }
245
+
246
+ function mount({ api, doc, auto, getSessionId } = {}) {
247
+ const d = doc || (typeof document !== 'undefined' ? document : null);
248
+ if (!d) throw new Error('fingerprint: mount needs a document');
249
+ const bridge = api || (typeof window !== 'undefined' ? window.aegis : null);
250
+ // The automation bridge (main.js registerAutoIpc). Injectable for the same
251
+ // reason `api` is, and optional: a preload predating that surface leaves the
252
+ // auto-seal control inert rather than throwing at mount.
253
+ const autoBridge = auto || (typeof window !== 'undefined' ? window.auto : null);
254
+
255
+ const el = (id) => d.getElementById(id);
256
+ const state = { status: null, last: null, busy: false, mounted: true };
257
+
258
+ function say(text, bad) {
259
+ const out = el(IDS.out);
260
+ if (!out) return;
261
+ out.textContent = text;
262
+ out.className = bad ? 'fp-out fp-bad' : 'fp-out';
263
+ }
264
+
265
+ /** Every bridge call goes through here. A handler that rejects (Electron
266
+ * turns a thrown main-process error into a rejected invoke) must not leave
267
+ * the panel mid-action, so the catch produces the same `{ ok, error }`
268
+ * shape the handlers themselves do. */
269
+ async function call(name, payload) {
270
+ if (!bridge || typeof bridge[name] !== 'function') {
271
+ return { ok: false, error: `this build has no ${name} bridge` };
272
+ }
273
+ try {
274
+ const r = await bridge[name](payload);
275
+ if (!r || typeof r !== 'object') return { ok: false, error: `${name} returned nothing` };
276
+ return r;
277
+ } catch (e) {
278
+ return { ok: false, error: (e && e.message) || String(e) };
279
+ }
280
+ }
281
+
282
+ function paintStatus() {
283
+ const s = state.status;
284
+ const card = el(IDS.cardStatus);
285
+ if (card) card.textContent = keyLine(s);
286
+ const src = el(IDS.keySource);
287
+ const pth = el(IDS.keyPath);
288
+ const tag = el(IDS.keyTag);
289
+ const warn = el(IDS.keyWarning);
290
+ const vt = el(IDS.vaultTarget);
291
+ const rows = statusRows(s);
292
+ const pick = (k) => {
293
+ const row = rows.find((r) => r.k === k);
294
+ return row ? row.v : '–';
295
+ };
296
+ if (src) src.textContent = pick('source');
297
+ if (pth) pth.textContent = s && s.keyPath ? s.keyPath : pick('expected at');
298
+ if (tag) tag.textContent = s && s.configured ? dash(s.keyFingerprint) : 'none';
299
+ if (warn) {
300
+ const w = keyWarning(s);
301
+ warn.textContent = w;
302
+ warn.hidden = !w;
303
+ }
304
+ if (vt && s && s.vault) {
305
+ // The default backend is the account (`aegiscloud`), where "gdrive" is
306
+ // not where anything goes — printing `gdrive:AEGIS-AGPL/records` for a
307
+ // cloud publish would name a folder the record never touches. Say the
308
+ // backend for that case, and keep the remembered rclone target for the
309
+ // case where it IS a remote. 'off' names neither — nothing is resolved
310
+ // behind it (desktop/lib/fingerprint.js's status() short-circuits
311
+ // before ever calling vaultTarget()), so the line says so plainly
312
+ // rather than printing the leftover "–:–" two dashes would read as.
313
+ vt.textContent = s.vault.backend === 'off'
314
+ ? 'nothing — sync is off'
315
+ : s.vault.backend === 'aegiscloud'
316
+ ? `aegiscloud:${dash(s.vault.recordsDir)}`
317
+ : `${dash(s.vault.remote)}:${dash(s.vault.recordsDir || s.vault.root)}`;
318
+ } else if (vt) {
319
+ vt.textContent = '–';
320
+ }
321
+ // A key that is present makes keygen a REPLACE, which orphans every
322
+ // record sealed with the old one. Saying that on the button is the whole
323
+ // warning; the confirm below is the second line of defence.
324
+ const kg = el(IDS.keygen);
325
+ if (kg) kg.textContent = s && s.configured ? 'Replace key…' : 'Mint key';
326
+ }
327
+
328
+ /**
329
+ * The three backend buttons' pressed state.
330
+ *
331
+ * Deliberately read from `getVaultBackend` (the preference the user set),
332
+ * NOT from `status().vault.backend` (the resolved record-vault.js
333
+ * backend id): the preference vocabulary is 'aegiscloud' | 'drive' | 'off',
334
+ * the resolved one is 'aegiscloud' | 'rclone' | 'off' — a 'drive'
335
+ * preference resolves to 'rclone', so pressing "Google Drive" from status
336
+ * alone would never read back as pressed.
337
+ */
338
+ function paintVaultBackend(backend) {
339
+ const map = {
340
+ drive: el(IDS.vaultBackendDrive),
341
+ aegiscloud: el(IDS.vaultBackendCloud),
342
+ off: el(IDS.vaultBackendOff),
343
+ };
344
+ for (const [key, btn] of Object.entries(map)) {
345
+ if (btn) btn.setAttribute('aria-pressed', String(key === backend));
346
+ }
347
+ }
348
+
349
+ async function loadVaultBackend() {
350
+ const r = await call('getVaultBackend');
351
+ state.vaultBackend = r && r.backend ? r.backend : 'aegiscloud';
352
+ paintVaultBackend(state.vaultBackend);
353
+ return state.vaultBackend;
354
+ }
355
+
356
+ const doSetVaultBackend = (backend) =>
357
+ action(`vault: ${backend === 'drive' ? 'Google Drive' : backend === 'off' ? 'no sync' : 'AE'}`, async () => {
358
+ const r = await call('setVaultBackend', backend);
359
+ return r && r.backend ? { ok: true, ...r } : { ok: false, error: 'could not save that' };
360
+ }, {
361
+ // The "publishes to" line names the backend too, so both it and the
362
+ // three buttons must repaint the moment the preference changes — not
363
+ // just on the next open().
364
+ after: (r) => (r && r.ok ? refresh() : null),
365
+ say: (r) => (r.ok ? `vault backend set to ${dash(r.backend)}` : `could not save that: ${r.error}`),
366
+ });
367
+
368
+ /**
369
+ * Google Drive — memory backup (desktop/lib/google-connect.js, exposed
370
+ * over `aegis.driveSignIn`/`driveConnect`/`driveStatus`/`driveSyncMemory`).
371
+ *
372
+ * Distinct from the vault backend buttons above: those choose where a
373
+ * SEALED φ(α) RECORD is published (rclone or the account vault). This is
374
+ * the account's AEGIS CLOUD MEMORY, backed up to the user's own Drive
375
+ * through real Google OAuth — unrelated data, unrelated credential.
376
+ */
377
+ /**
378
+ * What the conversation button's enabled state depends on: Drive connected
379
+ * AND a conversation actually open. Read through the injected
380
+ * `getSessionId` thunk on every paint, so a resume makes the button live and
381
+ * New Chat makes it dead without this file tracking session state itself.
382
+ */
383
+ function currentSessionId() {
384
+ try {
385
+ return typeof getSessionId === 'function' ? (getSessionId() || null) : null;
386
+ } catch {
387
+ return null;
388
+ }
389
+ }
390
+
391
+ function paintDrive(status) {
392
+ const line = el(IDS.driveStatus);
393
+ if (line) line.textContent = driveLine(status);
394
+ const connectBtn = el(IDS.driveConnect);
395
+ if (connectBtn) connectBtn.disabled = Boolean(status && !status.signedIn);
396
+ const connected = Boolean(status && status.connected);
397
+ const syncBtn = el(IDS.driveSyncNow);
398
+ if (syncBtn) syncBtn.disabled = !connected;
399
+ // One conversation can only be saved when Drive is connected and there is
400
+ // a conversation open — the same two conditions `backupConversation`
401
+ // refuses on, so the button never invites a click that can only fail.
402
+ const chatBtn = el(IDS.driveBackupChat);
403
+ if (chatBtn) chatBtn.disabled = !(connected && Boolean(currentSessionId()));
404
+ const hint = el(IDS.driveHint);
405
+ if (hint) {
406
+ hint.textContent = connected
407
+ ? 'Each saved file starts with who wrote it, so it still makes sense in Drive without this app.'
408
+ : 'Nothing is uploaded until you pick one of the two backups below.';
409
+ }
410
+ }
411
+
412
+ async function loadDriveStatus() {
413
+ const r = await call('driveStatus');
414
+ state.drive = r;
415
+ paintDrive(r);
416
+ return r;
417
+ }
418
+
419
+ const doDriveSignIn = () =>
420
+ action('sign in with Google', () => call('driveSignIn'), {
421
+ after: (r) => (r && r.ok ? loadDriveStatus() : null),
422
+ say: (r) => (r.ok ? `signed in${r.username ? ` as ${r.username}` : ''}` : `sign-in failed: ${r.error}`),
423
+ });
424
+
425
+ const doDriveConnect = () =>
426
+ action('connect Google Drive', () => call('driveConnect'), {
427
+ after: (r) => (r && r.ok ? loadDriveStatus() : null),
428
+ say: (r) => (r.ok ? `Google Drive connected${r.email ? ` · ${r.email}` : ''}` : `could not connect: ${r.error}`),
429
+ });
430
+
431
+ const doDriveSyncNow = () =>
432
+ action('back up all memory to Drive', () => call('driveSyncMemory'), {
433
+ say: (r) => (r.ok
434
+ ? `backed up all ${r.count} memory entr${r.count === 1 ? 'y' : 'ies'}${r.author ? ` · authored ${r.author}` : ''}${r.webViewLink ? ` → ${r.webViewLink}` : ''}`
435
+ : `backup failed: ${r.error}`),
436
+ });
437
+
438
+ /**
439
+ * Save the open conversation. Reads the session id at click time, not at
440
+ * mount time, so this always saves what is on screen right now.
441
+ */
442
+ const doDriveBackupChat = () =>
443
+ action('back up this conversation to Drive', () => call('driveBackupConversation', { sessionId: currentSessionId() }), {
444
+ say: (r) => (r.ok
445
+ ? `saved ${r.title ? `“${r.title}”` : 'this conversation'}${r.author ? ` · authored ${r.author}` : ''}${r.webViewLink ? ` → ${r.webViewLink}` : ''}`
446
+ : `could not save this conversation: ${r.error}`),
447
+ });
448
+
449
+ function paintVault(list) {
450
+ const ul = el(IDS.vaultList);
451
+ if (!ul) return;
452
+ ul.textContent = '';
453
+ for (const row of vaultRows(list)) {
454
+ const li = d.createElement('li');
455
+ li.className = 'fp-vault-row';
456
+ const name = d.createElement('span');
457
+ name.className = 'fp-vault-name';
458
+ name.textContent = row.name;
459
+ li.appendChild(name);
460
+ if (row.detail) {
461
+ const det = d.createElement('span');
462
+ det.className = 'fp-vault-detail';
463
+ det.textContent = row.detail;
464
+ li.appendChild(det);
465
+ }
466
+ ul.appendChild(li);
467
+ }
468
+ }
469
+
470
+ async function refresh() {
471
+ state.status = await call('fingerprintStatus');
472
+ paintStatus();
473
+ await loadAutoMint();
474
+ await loadVaultBackend();
475
+ await loadDriveStatus();
476
+ return state.status;
477
+ }
478
+
479
+ /**
480
+ * The auto-seal control (settings.js `__autoMint`, through lib/auto.js).
481
+ *
482
+ * Read-only paint from MAIN, for the reason the rest of this panel is: the
483
+ * renderer must never be the place that decides a record gets filed, and a
484
+ * checkbox state this file invented would disagree with the timer the moment
485
+ * anything else (the queue card's window, a restart) changed the setting.
486
+ */
487
+ function renderAutoMint(s) {
488
+ if (!s || typeof s !== 'object') return;
489
+ const sw = el(IDS.autoSeal);
490
+ if (sw) sw.checked = s.enabled === true;
491
+ const label = el(IDS.autoSealLabel);
492
+ if (label) label.textContent = s.enabled ? 'sealing automatically when quiet' : 'seal automatically when quiet';
493
+ const hint = el(IDS.autoHint);
494
+ if (!hint) return;
495
+ hint.textContent = autoMintLine(s);
496
+ }
497
+
498
+ async function loadAutoMint() {
499
+ if (!autoBridge || typeof autoBridge.status !== 'function') {
500
+ const hint = el(IDS.autoHint);
501
+ // Said plainly rather than left blank: an inert toggle with no
502
+ // explanation is the failure mode this whole panel exists to avoid.
503
+ if (hint) hint.textContent = 'this build has no automation bridge — sealing stays a button';
504
+ return null;
505
+ }
506
+ try {
507
+ const r = await autoBridge.status();
508
+ if (r && r.mint) renderAutoMint(r.mint);
509
+ return r;
510
+ } catch (e) {
511
+ const hint = el(IDS.autoHint);
512
+ if (hint) hint.textContent = `automation status unavailable: ${(e && e.message) || String(e)}`;
513
+ return null;
514
+ }
515
+ }
516
+
517
+ /** Persist the switch through main and paint main's answer. */
518
+ async function setAutoMint(enabled) {
519
+ if (!autoBridge || typeof autoBridge.setMint !== 'function') return null;
520
+ const publish = Boolean(el(IDS.publishOnMint) && el(IDS.publishOnMint).checked);
521
+ try {
522
+ const r = await autoBridge.setMint({ enabled: Boolean(enabled), publish });
523
+ if (r && r.mint) renderAutoMint(r.mint);
524
+ else if (r && r.ok === false) say(r.error || 'could not save that', true);
525
+ return r;
526
+ } catch (e) {
527
+ say(`could not save that: ${(e && e.message) || String(e)}`, true);
528
+ return null;
529
+ }
530
+ }
531
+
532
+ /** Seal right now, through the automation rather than the raw mint: the
533
+ * same call resets the pending-turn counter, so the quiet timer will not
534
+ * file a second identical record for this session. */
535
+ async function doSealNow() {
536
+ const publish = Boolean(el(IDS.publishOnMint) && el(IDS.publishOnMint).checked);
537
+ return action('seal now', async () => {
538
+ if (!autoBridge || typeof autoBridge.sealNow !== 'function') {
539
+ return { ok: false, error: 'this build has no automation bridge' };
540
+ }
541
+ return autoBridge.sealNow(publish);
542
+ }, {
543
+ paint: (r) => { if (r && r.ok && r.out) state.last = { file: r.out, record: r.record || null }; },
544
+ say: (r) => {
545
+ if (!r) return 'seal now: nothing happened';
546
+ if (r.ok === false) return `seal failed: ${r.error || 'unknown'}`;
547
+ if (r.type === 'skip') return `nothing to seal (${r.reason || 'no new turns'})`;
548
+ const line = sealLine(r);
549
+ return line.ok ? `sealed ${dash((r.record || {}).id)} → ${dash(r.out)}` : `seal failed: ${line.text}`;
550
+ },
551
+ });
552
+ }
553
+
554
+ /** Run one action, repaint what it changed, and say what it did. `confirm`
555
+ * is injectable so the harness can answer it deterministically. */
556
+ async function action(label, fn, opts) {
557
+ const o = opts || {};
558
+ if (state.busy) return null;
559
+ state.busy = true;
560
+ say(`${label}…`, false);
561
+ try {
562
+ const r = await fn();
563
+ if (o.paint) o.paint(r);
564
+ if (o.after) await o.after(r);
565
+ say(o.say ? o.say(r) : `${label}: ${r && r.ok === false ? r.error : 'done'}`, Boolean(r && r.ok === false));
566
+ return r;
567
+ } finally {
568
+ state.busy = false;
569
+ }
570
+ }
571
+
572
+ const doKeygen = () =>
573
+ action('mint key', () => call('fingerprintKeygen', {
574
+ force: Boolean(state.status && state.status.configured),
575
+ }), {
576
+ // Only after a successful mint: status moved from "no key" to a key,
577
+ // and repainting is what turns "Mint key" into "Replace key…".
578
+ after: refresh,
579
+ say: (r) => (r.ok
580
+ ? `minted ${dash(r.keyFingerprint)} at ${dash(r.path)}`
581
+ : `mint failed: ${r.error}`),
582
+ });
583
+
584
+ /* The model the window is currently set to, so the sealed record's AI axis
585
+ * says which mind answered. Passed as `model` (the record's own field) rather
586
+ * than `aiModel`: main forwards `aiModel` only as an override, while `model`
587
+ * is what the shared adapter also reads to NOMINATE the provider key this
588
+ * row needs — without it the axis was minted unobserved no matter how much
589
+ * history the session had. Empty when no model list has loaded, which reads
590
+ * as "the record did not say", never as a guessed id. */
591
+ const currentModel = () => {
592
+ const sel = el('model-select');
593
+ return sel && sel.value ? sel.value : null;
594
+ };
595
+
596
+ const doSeal = () =>
597
+ action('seal session', () => call('fingerprintMint', {
598
+ label: (el(IDS.label) && el(IDS.label).value.trim()) || null,
599
+ publish: Boolean(el(IDS.publishOnMint) && el(IDS.publishOnMint).checked),
600
+ model: currentModel(),
601
+ }), {
602
+ paint: (r) => { if (r.ok) state.last = { file: r.out, record: r.record }; },
603
+ say: (r) => {
604
+ const line = sealLine(r);
605
+ return line.ok ? `sealed ${dash((r.record || {}).id)} → ${dash(r.out)}` : `seal failed: ${line.text}`;
606
+ },
607
+ });
608
+
609
+ /** Verify/publish/anchor act on the record this panel sealed. A path is
610
+ * preferred over the in-memory record because the sha256 in the anchor is
611
+ * then about the bytes on disk rather than a re-serialisation of them
612
+ * (desktop/lib/fingerprint.js publish makes the same argument) — so `file`
613
+ * wins when there is one, and the record is the fallback for a host where
614
+ * the write failed but the seal did not. */
615
+ const doVerify = () =>
616
+ action('verify', async () => {
617
+ if (state.last && state.last.file) return call('fingerprintVerify', { file: state.last.file });
618
+ if (state.last && state.last.record) return call('fingerprintVerify', { record: state.last.record });
619
+ return { ok: false, error: 'nothing sealed in this window yet — seal a session first' };
620
+ }, {
621
+ say: (r) => (r.ok ? `verified ${dash(r.id)} · key ${dash(r.keySource)}` : `not verified: ${r.error || r.reason}`),
622
+ });
623
+
624
+ const doPublish = () =>
625
+ action('publish', () => {
626
+ if (state.last && state.last.file) return call('fingerprintPublish', { file: state.last.file });
627
+ if (state.last && state.last.record) return call('fingerprintPublish', { record: state.last.record });
628
+ return { ok: false, error: 'nothing sealed in this window yet — seal a session first' };
629
+ }, {
630
+ say: (r) => (r.ok
631
+ ? `published ${dash(r.url || r.path)}${r.sha256 ? ` · sha256 ${String(r.sha256).slice(0, 12)}` : ''}`
632
+ : `publish failed: ${r.error}`),
633
+ });
634
+
635
+ const doAnchor = () =>
636
+ action('check anchor', () => {
637
+ if (state.last && state.last.file) return call('fingerprintAnchor', { file: state.last.file });
638
+ return call('fingerprintAnchor', {});
639
+ }, {
640
+ say: (r) => {
641
+ const v = anchorVerdict(r);
642
+ const claims = v.claims.map((c) => `${c.k} ${c.v === true ? 'yes' : c.v === false ? 'no' : 'unknown'}`).join(' · ');
643
+ return `${v.label}${claims ? ` — ${claims}` : ''}`;
644
+ },
645
+ });
646
+
647
+ const doBackup = () =>
648
+ action('back up key', () => {
649
+ const to = el(IDS.backupTo) && el(IDS.backupTo).value.trim();
650
+ if (!to) return { ok: false, error: 'backup needs a destination directory' };
651
+ return call('fingerprintBackup', { to });
652
+ }, {
653
+ say: (r) => (r.ok ? `key copied to ${dash(r.to || r.path)}` : `backup refused: ${r.error}`),
654
+ });
655
+
656
+ const doVault = () =>
657
+ action('list vault', () => call('fingerprintVault'), {
658
+ paint: paintVault,
659
+ say: (r) => (r.ok ? `vault listed — ${vaultRows(r).length} entry(ies)` : `vault unavailable: ${r.error}`),
660
+ });
661
+
662
+ const doAudit = () =>
663
+ action('audit vault', () => call('fingerprintVaultAudit'), {
664
+ say: (r) => {
665
+ const v = auditVerdict(r);
666
+ const names = v.findings.map((f) => (f && (f.path || f.name)) || String(f)).slice(0, 3);
667
+ return `${v.label}${names.length ? ` — ${names.join(', ')}` : ''}`;
668
+ },
669
+ });
670
+
671
+ const isOpen = () => {
672
+ const o = el(IDS.overlay);
673
+ return Boolean(o) && !o.hidden;
674
+ };
675
+
676
+ async function open(opts) {
677
+ const o = el(IDS.overlay);
678
+ if (!o) return;
679
+ o.hidden = false;
680
+ // Body class so the page behind cannot scroll under the sheet, matching
681
+ // the memory inspector's `.memory-open` rule.
682
+ if (d.body && d.body.classList) d.body.classList.add('fp-open');
683
+ await refresh();
684
+ await doVault();
685
+ // The Google Drive row sits at the bottom of a panel most of whose
686
+ // controls are unrelated (the φ(α) key). The top-menu entry for it
687
+ // (main.js's "Google Drive Backup…") opens straight here instead of
688
+ // leaving the user to find it among Seal/Verify/Publish/Vault.
689
+ if (opts && opts.focus === 'drive') {
690
+ const row = el(IDS.driveStatus);
691
+ if (row && row.scrollIntoView) row.scrollIntoView({ block: 'center' });
692
+ // Whichever Drive action is actually clickable right now — sign-in
693
+ // first, then connect, then sync — so focus lands on the next step
694
+ // instead of a disabled button.
695
+ const next = [IDS.driveSignIn, IDS.driveConnect, IDS.driveBackupChat, IDS.driveSyncNow]
696
+ .map(el)
697
+ .find((btn) => btn && !btn.disabled);
698
+ if (next) next.focus();
699
+ return;
700
+ }
701
+ const f = el(IDS.close);
702
+ if (f) f.focus();
703
+ }
704
+
705
+ function close() {
706
+ const o = el(IDS.overlay);
707
+ if (!o) return;
708
+ o.hidden = true;
709
+ if (d.body && d.body.classList) d.body.classList.remove('fp-open');
710
+ const btn = el(IDS.cardOpen);
711
+ if (btn) btn.focus();
712
+ }
713
+
714
+ // ------------------------------------------------------------- listeners
715
+ // Bound here rather than in app.js so the panel owns its own markup: every
716
+ // id in IDS is read by this file only, and the test asserts they all exist.
717
+ const bind = (id, type, fn) => {
718
+ const node = el(id);
719
+ if (node) node.addEventListener(type, fn);
720
+ };
721
+
722
+ bind(IDS.cardOpen, 'click', open);
723
+ bind(IDS.close, 'click', close);
724
+ bind(IDS.backdrop, 'click', close);
725
+ bind(IDS.keygen, 'click', doKeygen);
726
+ bind(IDS.seal, 'click', doSeal);
727
+ // The sidebar's one-click seal runs the same action; on success it also
728
+ // opens the panel, because a record filed silently behind a closed sheet is
729
+ // indistinguishable from a button that did nothing.
730
+ bind(IDS.sealCard, 'click', async () => {
731
+ const r = await doSeal();
732
+ if (r && r.ok) await open();
733
+ });
734
+ bind(IDS.verify, 'click', doVerify);
735
+ bind(IDS.publish, 'click', doPublish);
736
+ bind(IDS.anchor, 'click', doAnchor);
737
+ bind(IDS.backup, 'click', doBackup);
738
+ bind(IDS.vault, 'click', doVault);
739
+ bind(IDS.audit, 'click', doAudit);
740
+ bind(IDS.vaultBackendDrive, 'click', () => doSetVaultBackend('drive'));
741
+ bind(IDS.vaultBackendCloud, 'click', () => doSetVaultBackend('aegiscloud'));
742
+ bind(IDS.vaultBackendOff, 'click', () => doSetVaultBackend('off'));
743
+ bind(IDS.driveSignIn, 'click', doDriveSignIn);
744
+ bind(IDS.driveConnect, 'click', doDriveConnect);
745
+ bind(IDS.driveSyncNow, 'click', doDriveSyncNow);
746
+ bind(IDS.driveBackupChat, 'click', doDriveBackupChat);
747
+ // The auto-seal switch is the ONE control on this panel that can file a
748
+ // record with nobody watching, so it is the one that must repaint from
749
+ // main's answer rather than from the checkbox the user just clicked.
750
+ if (el(IDS.autoSeal)) {
751
+ bind(IDS.autoSeal, 'change', () => {
752
+ const box = el(IDS.autoSeal);
753
+ return setAutoMint(Boolean(box && box.checked));
754
+ });
755
+ }
756
+ if (el(IDS.sealNow)) bind(IDS.sealNow, 'click', doSealNow);
757
+
758
+ return {
759
+ open,
760
+ close,
761
+ isOpen,
762
+ refresh,
763
+ loadAutoMint,
764
+ state,
765
+ // Exposed for the test and for app.js's on-demand repaint. Every one is
766
+ // idempotent, so calling them from a console is safe.
767
+ actions: {
768
+ doKeygen, doSeal, doSealNow, doVerify, doPublish, doAnchor, doBackup, doVault, doAudit,
769
+ doSetVaultBackend, doDriveSignIn, doDriveConnect, doDriveSyncNow, doDriveBackupChat,
770
+ },
771
+ loadVaultBackend,
772
+ loadDriveStatus,
773
+ };
774
+ }
775
+
776
+ return {
777
+ IDS,
778
+ mount,
779
+ // Pure, and asserted as such by the test.
780
+ keyLine,
781
+ statusRows,
782
+ keyWarning,
783
+ vaultRows,
784
+ anchorVerdict,
785
+ auditVerdict,
786
+ sealLine,
787
+ autoMintLine,
788
+ driveLine,
789
+ dash,
790
+ };
791
+ });