aegisone 1.0.33 → 1.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/README.md +1 -1
  2. package/bin/aegis.js +322 -1
  3. package/package.json +5 -4
  4. package/scripts/bump.mjs +211 -1
  5. package/scripts/bundle.js +129 -1
  6. package/scripts/predist.mjs +976 -1
  7. package/src/child.js +285 -1
  8. package/src/dispatch.js +269 -1
  9. package/src/doctor.js +639 -1
  10. package/src/host.js +111 -1
  11. package/src/permissions.js +383 -1
  12. package/src/probes.js +159 -1
  13. package/src/release.js +409 -1
  14. package/vendor/cli/package.json +7 -3
  15. package/vendor/cli/scripts/check.mjs +52 -1
  16. package/vendor/cli/scripts/demo.mjs +94 -1
  17. package/vendor/cli/scripts/predist.mjs +75 -1
  18. package/vendor/cli/scripts/runtests.mjs +56 -1
  19. package/vendor/cli/scripts/seal-gate.mjs +74 -1
  20. package/vendor/cli/src/agents.js +139 -1
  21. package/vendor/cli/src/app.js +2957 -1
  22. package/vendor/cli/src/art.js +289 -1
  23. package/vendor/cli/src/chatflow.js +3023 -1
  24. package/vendor/cli/src/checkpoint.js +90 -1
  25. package/vendor/cli/src/clipboard.js +424 -1
  26. package/vendor/cli/src/cloudsync.js +528 -1
  27. package/vendor/cli/src/commands.js +4089 -1
  28. package/vendor/cli/src/config.js +581 -1
  29. package/vendor/cli/src/connect.js +349 -1
  30. package/vendor/cli/src/credentials.js +33 -1
  31. package/vendor/cli/src/deps.js +232 -1
  32. package/vendor/cli/src/devrun.js +187 -1
  33. package/vendor/cli/src/diff.js +333 -1
  34. package/vendor/cli/src/diffview.js +296 -1
  35. package/vendor/cli/src/engine.js +297 -1
  36. package/vendor/cli/src/entitlement.js +355 -1
  37. package/vendor/cli/src/events.js +707 -1
  38. package/vendor/cli/src/export.js +67 -1
  39. package/vendor/cli/src/filepreview.js +153 -1
  40. package/vendor/cli/src/fingerprint.js +592 -1
  41. package/vendor/cli/src/format.js +259 -1
  42. package/vendor/cli/src/fuzzy.js +119 -1
  43. package/vendor/cli/src/history.js +423 -1
  44. package/vendor/cli/src/init.js +175 -1
  45. package/vendor/cli/src/input.js +139 -1
  46. package/vendor/cli/src/keys.js +183 -1
  47. package/vendor/cli/src/markdown.js +306 -1
  48. package/vendor/cli/src/models.js +507 -1
  49. package/vendor/cli/src/naming.js +57 -1
  50. package/vendor/cli/src/overlays.js +462 -1
  51. package/vendor/cli/src/panels.js +1418 -1
  52. package/vendor/cli/src/ping.js +226 -1
  53. package/vendor/cli/src/presence.js +238 -1
  54. package/vendor/cli/src/render.js +516 -1
  55. package/vendor/cli/src/screen.js +518 -1
  56. package/vendor/cli/src/screens.js +896 -1
  57. package/vendor/cli/src/secret.js +59 -1
  58. package/vendor/cli/src/securefs.js +359 -1
  59. package/vendor/cli/src/settings.js +155 -1
  60. package/vendor/cli/src/shared.js +52 -1
  61. package/vendor/cli/src/sharedpaths.js +53 -1
  62. package/vendor/cli/src/signup.js +156 -1
  63. package/vendor/cli/src/summarize.js +95 -1
  64. package/vendor/cli/src/sysdiag.js +585 -1
  65. package/vendor/cli/src/system.js +40 -1
  66. package/vendor/cli/src/theme.js +570 -1
  67. package/vendor/cli/src/title.js +220 -1
  68. package/vendor/cli/src/todos.js +115 -1
  69. package/vendor/cli/src/tokens.js +263 -1
  70. package/vendor/cli/src/topup.js +210 -1
  71. package/vendor/cli/src/update.js +191 -1
  72. package/vendor/cli/vendor/client/aegis.js +2441 -1
  73. package/vendor/cli/vendor/client/attest.js +518 -1
  74. package/vendor/cli/vendor/client/authorship-key.js +410 -1
  75. package/vendor/cli/vendor/client/auto-provision.js +134 -1
  76. package/vendor/cli/vendor/client/brain-catalog.js +268 -1
  77. package/vendor/cli/vendor/client/byok-catalog.js +199 -1
  78. package/vendor/cli/vendor/client/catalog-client.js +487 -1
  79. package/vendor/cli/vendor/client/conversation-export.js +177 -1
  80. package/vendor/cli/vendor/client/credentials.js +494 -1
  81. package/vendor/cli/vendor/client/device-fingerprint.js +141 -1
  82. package/vendor/cli/vendor/client/drive-connect.js +110 -1
  83. package/vendor/cli/vendor/client/drive-upload.js +234 -1
  84. package/vendor/cli/vendor/client/env-file.js +1273 -1
  85. package/vendor/cli/vendor/client/fingerprint.js +1064 -1
  86. package/vendor/cli/vendor/client/foreign-memory.js +669 -1
  87. package/vendor/cli/vendor/client/google-signin.js +133 -1
  88. package/vendor/cli/vendor/client/hooks.js +430 -1
  89. package/vendor/cli/vendor/client/model-discovery.js +373 -1
  90. package/vendor/cli/vendor/client/naming.js +283 -1
  91. package/vendor/cli/vendor/client/platform.js +937 -1
  92. package/vendor/cli/vendor/client/prefs.js +351 -1
  93. package/vendor/cli/vendor/client/presence-constants.js +107 -1
  94. package/vendor/cli/vendor/client/presence.js +438 -1
  95. package/vendor/cli/vendor/client/record-vault.js +1055 -3
  96. package/vendor/cli/vendor/client/session-store.js +575 -1
  97. package/vendor/cli/vendor/client/topup.js +297 -1
  98. package/vendor/cli/vendor/client/touch.js +458 -1
  99. package/vendor/cli/vendor/client/update.js +763 -1
  100. package/vendor/cli/vendor/client/user-models.js +381 -1
  101. package/vendor/cli/vendor/desktop/lib/local/agents.js +105 -1
  102. package/vendor/cli/vendor/desktop/lib/local/attachments.js +276 -1
  103. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1045 -1
  104. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1028 -1
  105. package/vendor/cli/vendor/desktop/lib/local/context.js +125 -1
  106. package/vendor/cli/vendor/desktop/lib/local/engine.js +3666 -1
  107. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +660 -1
  108. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +228 -1
  109. package/vendor/cli/vendor/desktop/lib/local/local.js +2145 -1
  110. package/vendor/cli/vendor/desktop/lib/local/prompt.js +280 -1
  111. package/vendor/cli/vendor/desktop/lib/local/queue.js +560 -1
  112. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +238 -1
  113. package/vendor/cli/vendor/desktop/lib/local/spill.js +75 -1
  114. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +300 -1
  115. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +235 -1
  116. package/vendor/cli/vendor/desktop/lib/settings.js +890 -1
  117. package/vendor/cli/vendor/desktop/renderer/usage.js +1239 -1
  118. package/vendor/cli/vendor/hosts/install.js +638 -1
  119. package/vendor/cli/vendor/hosts/openai-shim.js +515 -1
  120. package/vendor/cli/vendor/hosts/spec.js +164 -1
  121. package/vendor/cli/vendor/hosts/targets.js +346 -1
  122. package/vendor/cli/vendor/mcp/server.js +221 -1
  123. package/vendor/cli/vendor/mcp/tools.js +408 -1
  124. package/vendor/cli/vendor/one/src/child.js +285 -1
  125. package/vendor/cli/vendor/one/src/permissions.js +383 -1
  126. package/vendor/desktop/bin/aegis.js +32 -1
  127. package/vendor/desktop/lib/account-key.js +56 -1
  128. package/vendor/desktop/lib/auto.js +461 -1
  129. package/vendor/desktop/lib/avatar/companion.js +698 -1
  130. package/vendor/desktop/lib/avatar/cosmetics.js +532 -1
  131. package/vendor/desktop/lib/avatar/events.js +344 -1
  132. package/vendor/desktop/lib/avatar/holder-turn.js +350 -1
  133. package/vendor/desktop/lib/avatar/holders.js +612 -1
  134. package/vendor/desktop/lib/avatar/identity.js +641 -1
  135. package/vendor/desktop/lib/avatar/level.js +368 -1
  136. package/vendor/desktop/lib/avatar/mirror.js +524 -1
  137. package/vendor/desktop/lib/avatar/persona.js +388 -1
  138. package/vendor/desktop/lib/avatar/profile.js +977 -1
  139. package/vendor/desktop/lib/avatar/register.js +307 -1
  140. package/vendor/desktop/lib/avatar/store.js +472 -1
  141. package/vendor/desktop/lib/avatar/tiers.js +38 -1
  142. package/vendor/desktop/lib/avatar/transfer.js +415 -1
  143. package/vendor/desktop/lib/avatar/turn.js +216 -1
  144. package/vendor/desktop/lib/avatar/voice.js +328 -1
  145. package/vendor/desktop/lib/avatar/xp.js +404 -1
  146. package/vendor/desktop/lib/deep-link.js +120 -1
  147. package/vendor/desktop/lib/fingerprint.js +347 -2
  148. package/vendor/desktop/lib/google-connect.js +323 -1
  149. package/vendor/desktop/lib/local/agents.js +105 -1
  150. package/vendor/desktop/lib/local/attachments.js +276 -1
  151. package/vendor/desktop/lib/local/autonomous.js +1045 -1
  152. package/vendor/desktop/lib/local/claude-pro.js +1028 -1
  153. package/vendor/desktop/lib/local/context.js +125 -1
  154. package/vendor/desktop/lib/local/engine.js +3666 -1
  155. package/vendor/desktop/lib/local/entitlement.js +660 -1
  156. package/vendor/desktop/lib/local/git-scope.js +228 -1
  157. package/vendor/desktop/lib/local/local.js +2145 -1
  158. package/vendor/desktop/lib/local/prompt.js +280 -1
  159. package/vendor/desktop/lib/local/queue.js +560 -1
  160. package/vendor/desktop/lib/local/session-rounds.js +238 -1
  161. package/vendor/desktop/lib/local/spill.js +75 -1
  162. package/vendor/desktop/lib/local/telemetry.js +470 -1
  163. package/vendor/desktop/lib/local/turn-guard.js +300 -1
  164. package/vendor/desktop/lib/local/worktree-lock.js +235 -1
  165. package/vendor/desktop/lib/provider-key-mirror.js +252 -1
  166. package/vendor/desktop/lib/quick-launcher.js +84 -1
  167. package/vendor/desktop/lib/settings.js +890 -1
  168. package/vendor/desktop/lib/sync/memory-queue.js +60 -1
  169. package/vendor/desktop/lib/sync/persist-gate.js +148 -1
  170. package/vendor/desktop/lib/sync/sessions.js +106 -1
  171. package/vendor/desktop/lib/window-state.js +66 -1
  172. package/vendor/desktop/package.json +5 -3
  173. package/vendor/desktop/preload.js +679 -1
  174. package/vendor/desktop/renderer/app.js +7250 -1
  175. package/vendor/desktop/renderer/avatar/assemble.js +335 -1
  176. package/vendor/desktop/renderer/avatar/avatar.js +380 -1
  177. package/vendor/desktop/renderer/avatar/cards.js +141 -1
  178. package/vendor/desktop/renderer/avatar/hud.js +206 -1
  179. package/vendor/desktop/renderer/avatar/machine.js +213 -1
  180. package/vendor/desktop/renderer/avatar/pane.js +439 -1
  181. package/vendor/desktop/renderer/avatar/parts.js +437 -1
  182. package/vendor/desktop/renderer/budget.js +172 -1
  183. package/vendor/desktop/renderer/companion.js +223 -1
  184. package/vendor/desktop/renderer/diff.js +359 -1
  185. package/vendor/desktop/renderer/diffview.js +336 -1
  186. package/vendor/desktop/renderer/filepreview.js +211 -1
  187. package/vendor/desktop/renderer/fingerprint.js +789 -3
  188. package/vendor/desktop/renderer/markdown.js +168 -1
  189. package/vendor/desktop/renderer/provider-mark.js +311 -1
  190. package/vendor/desktop/renderer/provider-toolbar.js +134 -1
  191. package/vendor/desktop/renderer/providers.js +259 -1
  192. package/vendor/desktop/renderer/quick.js +285 -1
  193. package/vendor/desktop/renderer/stream-policy.js +387 -1
  194. package/vendor/desktop/renderer/transcript-view.js +323 -1
  195. package/vendor/desktop/renderer/usage.js +1239 -1
  196. package/vendor/desktop/vendor/aegis.js +2441 -1
  197. package/vendor/desktop/vendor/attest.js +518 -1
  198. package/vendor/desktop/vendor/authorship-key.js +410 -1
  199. package/vendor/desktop/vendor/auto-provision.js +134 -1
  200. package/vendor/desktop/vendor/brain-catalog.js +268 -1
  201. package/vendor/desktop/vendor/byok-catalog.js +199 -1
  202. package/vendor/desktop/vendor/catalog-client.js +487 -1
  203. package/vendor/desktop/vendor/conversation-export.js +177 -1
  204. package/vendor/desktop/vendor/credentials.js +494 -1
  205. package/vendor/desktop/vendor/device-fingerprint.js +141 -1
  206. package/vendor/desktop/vendor/drive-connect.js +110 -1
  207. package/vendor/desktop/vendor/drive-upload.js +234 -1
  208. package/vendor/desktop/vendor/env-file.js +1273 -1
  209. package/vendor/desktop/vendor/fingerprint.js +1064 -1
  210. package/vendor/desktop/vendor/foreign-memory.js +669 -1
  211. package/vendor/desktop/vendor/google-signin.js +133 -1
  212. package/vendor/desktop/vendor/hooks.js +430 -1
  213. package/vendor/desktop/vendor/model-discovery.js +373 -1
  214. package/vendor/desktop/vendor/naming.js +283 -1
  215. package/vendor/desktop/vendor/platform.js +937 -1
  216. package/vendor/desktop/vendor/prefs.js +351 -1
  217. package/vendor/desktop/vendor/presence-constants.js +107 -1
  218. package/vendor/desktop/vendor/presence.js +438 -1
  219. package/vendor/desktop/vendor/record-vault.js +1055 -3
  220. package/vendor/desktop/vendor/session-store.js +575 -1
  221. package/vendor/desktop/vendor/topup.js +297 -1
  222. package/vendor/desktop/vendor/touch.js +458 -1
  223. package/vendor/desktop/vendor/update.js +763 -1
  224. package/vendor/desktop/vendor/user-models.js +381 -1
  225. package/LICENSE +0 -661
  226. package/SOURCE-OFFER.txt +0 -9
@@ -1,3 +1,325 @@
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
+ // 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
+ * google-connect.js — the desktop's Google identity + Drive flow.
10
+ *
11
+ * Two distinct steps, run in this order because the second depends on the
12
+ * first having actually landed:
13
+ *
14
+ * 1. Sign in with Google (`client/google-signin.js`'s local round-trip) —
15
+ * replaces this machine's saved AEGIS key with the one tied to that
16
+ * Google identity, exactly as `aegiscode connect` already does for the
17
+ * CLI (cli/src/connect.js). Desktop never had this wiring before this
18
+ * file; the only Google sign-in that existed anywhere in this product
19
+ * was the CLI's.
20
+ * 2. Connect Drive (`client/drive-connect.js`, which opens `/connect/drive`
21
+ * in the system browser and polls `/api/drive/token`) — grants the
22
+ * `drive.file` scope to WHICHEVER Google identity that browser's
23
+ * consent screen uses. That is only the SAME account as step 1 if step
24
+ * 1 ran first on this machine: `/connect/drive`'s callback resolves an
25
+ * account purely by Google identity, with no notion of "the account
26
+ * this machine's API key already belongs to" — so connecting Drive
27
+ * before signing in attaches the tokens to a DIFFERENT account than the
28
+ * one this machine will poll, and the poll just times out.
29
+ *
30
+ * "Signed in with Google" is NOT "has an API key". Every install
31
+ * auto-provisions an anonymous device key, so a key always exists and an
32
+ * `!apiKey` guard never fires. The only honest source for the real
33
+ * question is the server's `google_linked` (users.google_id), carried on
34
+ * `/api/drive/token` and surfaced as `status().googleLinked` — so
35
+ * `connectDrive` refuses on that, and the renderer disables the button
36
+ * from the same flag.
37
+ *
38
+ * Electron-free and fully injected — same shape as `account-key.js` next to
39
+ * it — so the whole flow runs under a test with a stub `aegis` client, a
40
+ * stub `googleSignIn`/`driveConnect`/`driveUpload`, and no browser, window or
41
+ * network.
42
+ */
43
+
44
+ function createGoogleConnect({
45
+ aegis,
46
+ credentials,
47
+ persistKey,
48
+ openUrl,
49
+ googleSignIn,
50
+ driveConnect,
51
+ driveUpload,
52
+ conversationExport,
53
+ getSession,
54
+ getAuthor,
55
+ onAccountChange,
56
+ }) {
57
+ let signInInFlight = null;
58
+ let connectInFlight = null;
59
+ let lastSyncAt = null;
60
+ let lastSyncError = null;
61
+ // Did a Google round-trip complete in THIS process? That is first-hand
62
+ // evidence of a linked account and does not depend on the server reporting
63
+ // it — which older servers do not (see `status`).
64
+ let signedInViaGoogle = false;
65
+
66
+ /** Sign this machine in with Google, replacing whatever key it had. */
67
+ function signInWithGoogle() {
68
+ if (!signInInFlight) {
69
+ signInInFlight = (async () => {
70
+ try {
71
+ // Everything from here on (binding the local callback server,
72
+ // opening the browser, waiting for the round-trip) can fail, and
73
+ // every caller of this module — the IPC handler in main.js chief
74
+ // among them — is promised `{ ok, … }`/`{ ok: false, error }`,
75
+ // never a rejection. One try covers the whole flow instead of only
76
+ // the `session.wait()` half of it.
77
+ let session;
78
+ try {
79
+ session = await googleSignIn.startGoogleSignIn({ apiBase: aegis.apiBase });
80
+ } catch (e) {
81
+ return { ok: false, error: `could not start the local sign-in server — ${(e && e.message) || e}` };
82
+ }
83
+ const opened = Boolean(openUrl(session.url));
84
+ let result;
85
+ try {
86
+ result = await session.wait();
87
+ } catch (e) {
88
+ return { ok: false, opened, url: session.url, error: (e && e.message) || String(e) };
89
+ }
90
+ // Live client first: the very next call this process makes (e.g.
91
+ // the renderer asking for drive status right after this resolves)
92
+ // must see the new identity, not whatever key this process started
93
+ // with.
94
+ aegis.setApiKey(result.apiKey);
95
+ persistKey(result.apiKey);
96
+ if (result.memoryToken && credentials && typeof credentials.saveMemoryToken === 'function') {
97
+ try {
98
+ credentials.saveMemoryToken(result.memoryToken);
99
+ } catch {
100
+ /* best-effort — the account key itself is already saved */
101
+ }
102
+ }
103
+ // Before the notification, which is what makes the renderer re-read
104
+ // `status()` — otherwise that refresh races this assignment and
105
+ // reports the sign-in as not having happened.
106
+ signedInViaGoogle = true;
107
+ if (typeof onAccountChange === 'function') onAccountChange();
108
+ return { ok: true, opened, url: session.url, username: result.username || null };
109
+ } finally {
110
+ signInInFlight = null;
111
+ }
112
+ })();
113
+ }
114
+ return signInInFlight;
115
+ }
116
+
117
+ /** Open `/connect/drive` and wait for this account to show connected. */
118
+ async function connectDrive() {
119
+ if (!aegis.apiKey) {
120
+ return {
121
+ ok: false,
122
+ error: 'sign in with Google first — this device has no AEGIS account key yet',
123
+ };
124
+ }
125
+ if (!connectInFlight) {
126
+ connectInFlight = (async () => {
127
+ try {
128
+ // The key exists but may be an anonymous device key. Ask the server
129
+ // whether this account is actually tied to a Google identity before
130
+ // opening a consent screen that would attach the tokens elsewhere.
131
+ // Inside the in-flight promise so a double click cannot open two
132
+ // consent tabs. If the status call fails, fall through: a transport
133
+ // blip must not be reported as "not signed in with Google".
134
+ let linked = true;
135
+ try {
136
+ const st = await driveConnect.driveStatus(aegis);
137
+ // Refuse only on a definite "not linked". A server that predates
138
+ // `google_linked` answers the same shape as an unlinked account,
139
+ // and refusing on that would make a real Google sign-in unable to
140
+ // ever connect Drive — the exact dead end this guard exists to
141
+ // prevent, only inverted.
142
+ linked = !(st.googleLinkedKnown && !st.googleLinked);
143
+ } catch {
144
+ /* unknown — let the flow try rather than misreport the reason */
145
+ }
146
+ if (!linked) {
147
+ return {
148
+ ok: false,
149
+ error: 'sign in with Google first — this account is not linked to a Google identity yet, '
150
+ + 'and connecting Drive now would attach it to a different account',
151
+ };
152
+ }
153
+ const url = driveConnect.driveConnectUrl(aegis.apiBase);
154
+ const opened = Boolean(openUrl(url));
155
+ try {
156
+ const status = await driveConnect.waitForDriveConnected(aegis);
157
+ return { ok: true, opened, url, connected: status.connected, email: status.email };
158
+ } catch (e) {
159
+ return { ok: false, opened, url, error: (e && e.message) || String(e) };
160
+ }
161
+ } finally {
162
+ connectInFlight = null;
163
+ }
164
+ })();
165
+ }
166
+ return connectInFlight;
167
+ }
168
+
169
+ /**
170
+ * A one-shot read: signed in with Google, and if so, is Drive connected.
171
+ *
172
+ * `signedIn` is the server's `google_linked`, not "has an API key" — see
173
+ * the header. The old `apiKey ? true` form reported every anonymous
174
+ * auto-provisioned device as signed in, which both mislabelled the card
175
+ * ("signed in · Drive not connected yet" on a machine that never touched
176
+ * Google) and enabled Connect Drive ahead of the sign-in it depends on.
177
+ */
178
+ async function status() {
179
+ if (!aegis.apiKey) {
180
+ return { signedIn: false, googleLinked: false, googleLinkedKnown: true, connected: false, email: null };
181
+ }
182
+ const s = await driveConnect.driveStatus(aegis);
183
+ // A completed round-trip outranks a server that cannot answer: without
184
+ // this, signing in against a server that predates `google_linked` leaves
185
+ // the card reading "not signed in" forever, because the sign-in that just
186
+ // succeeded is the one thing the flag was supposed to prove.
187
+ const signedIn = s.googleLinked === true || signedInViaGoogle;
188
+ return {
189
+ signedIn,
190
+ ...s,
191
+ googleLinked: s.googleLinked === true || signedIn,
192
+ googleLinkedKnown: s.googleLinkedKnown || signedIn,
193
+ };
194
+ }
195
+
196
+ /** Pull this account's AEGIS cloud memory and back it up to Drive. */
197
+ async function syncMemoryNow() {
198
+ try {
199
+ const tokenInfo = await aegis.driveToken();
200
+ if (!tokenInfo || !tokenInfo.connected || !tokenInfo.access_token) {
201
+ throw new Error('Google Drive is not connected yet');
202
+ }
203
+ const pulled = await aegis.memoryPull(0);
204
+ const entries = (pulled && pulled.entries) || [];
205
+ const exportedAt = new Date().toISOString();
206
+ // The authorship stamp goes on the file itself, not just beside it: this
207
+ // export leaves the machine, and a copy in Drive that cannot say whose
208
+ // writing it is has to be taken on faith. `memoryMarkdown` is a no-op
209
+ // wrapper when there is no export module, so an older wiring still syncs.
210
+ const body = JSON.stringify({ exportedAt, entries }, null, 2);
211
+ const author = readAuthor();
212
+ const content = conversationExport && typeof conversationExport.memoryMarkdown === 'function'
213
+ ? conversationExport.memoryMarkdown(body, {
214
+ keyFingerprint: author.keyFingerprint,
215
+ email: tokenInfo.email || null,
216
+ exportedAt,
217
+ count: entries.length,
218
+ })
219
+ : body;
220
+ const result = await driveUpload.uploadMemoryBackup(tokenInfo.access_token, content, {
221
+ fileName: conversationExport ? 'aegis-memory-backup.md' : undefined,
222
+ mimeType: conversationExport ? 'text/markdown' : undefined,
223
+ });
224
+ lastSyncAt = Date.now();
225
+ lastSyncError = null;
226
+ return {
227
+ ok: true,
228
+ count: entries.length,
229
+ fileId: result.fileId,
230
+ webViewLink: result.webViewLink,
231
+ updated: result.updated,
232
+ author: authorText(author),
233
+ lastSyncAt,
234
+ };
235
+ } catch (e) {
236
+ lastSyncError = (e && e.message) || String(e);
237
+ return { ok: false, error: lastSyncError, lastSyncAt };
238
+ }
239
+ }
240
+
241
+ /** What the stamp will say about the key — never the key itself. */
242
+ function readAuthor() {
243
+ try {
244
+ const a = typeof getAuthor === 'function' ? getAuthor() : null;
245
+ return { keyFingerprint: (a && a.keyFingerprint) || null };
246
+ } catch {
247
+ return { keyFingerprint: null };
248
+ }
249
+ }
250
+
251
+ function authorText(author) {
252
+ if (!conversationExport || typeof conversationExport.authorLine !== 'function') return null;
253
+ return conversationExport.authorLine(author && author.keyFingerprint);
254
+ }
255
+
256
+ /**
257
+ * Save ONE conversation to Drive — the other of the two backups.
258
+ *
259
+ * Refusals are plain sentences, not exceptions, for the three things a person
260
+ * can actually do wrong here: Drive not connected, no conversation open, or an
261
+ * open conversation that has not been saved yet (nothing to export).
262
+ *
263
+ * The file is a NEW `.md` every call, named with its own timestamp — see
264
+ * `uploadConversation`'s header for why this scope never overwrites.
265
+ */
266
+ async function backupConversation({ sessionId } = {}) {
267
+ try {
268
+ if (!conversationExport || typeof conversationExport.conversationMarkdown !== 'function') {
269
+ return { ok: false, error: 'this build cannot export a conversation — the export module is missing' };
270
+ }
271
+ const tokenInfo = await aegis.driveToken();
272
+ if (!tokenInfo || !tokenInfo.connected || !tokenInfo.access_token) {
273
+ return { ok: false, error: 'connect Google Drive first — no Drive access token yet' };
274
+ }
275
+ if (!sessionId) {
276
+ return { ok: false, error: 'start a conversation first — there is nothing to save yet' };
277
+ }
278
+ const session = typeof getSession === 'function' ? getSession(sessionId) : null;
279
+ if (!session) {
280
+ return { ok: false, error: 'that conversation is not in the session store yet — send one message, then save' };
281
+ }
282
+ const messages = (session.messages || session.transcript || []);
283
+ if (Array.isArray(messages) && messages.length === 0) {
284
+ return { ok: false, error: 'that conversation has no messages yet — nothing to save' };
285
+ }
286
+
287
+ const exportedAt = new Date().toISOString();
288
+ const author = readAuthor();
289
+ const transcript = typeof conversationExport.toTranscript === 'function'
290
+ ? conversationExport.toTranscript(session)
291
+ : (session.markdown || '');
292
+ const content = conversationExport.conversationMarkdown(session, {
293
+ transcript,
294
+ keyFingerprint: author.keyFingerprint,
295
+ email: tokenInfo.email || null,
296
+ exportedAt,
297
+ count: Array.isArray(messages) ? messages.length : null,
298
+ });
299
+ const name = conversationExport.conversationFileName(session, exportedAt);
300
+
301
+ const result = await driveUpload.uploadConversation(tokenInfo.access_token, { name, content });
302
+ return {
303
+ ok: true,
304
+ fileId: result.fileId,
305
+ webViewLink: result.webViewLink,
306
+ file: result.path || name,
307
+ title: (session.title || session.id) || null,
308
+ author: authorText(author),
309
+ };
310
+ } catch (e) {
311
+ return { ok: false, error: (e && e.message) || String(e) };
312
+ }
313
+ }
314
+
315
+ return {
316
+ signInWithGoogle,
317
+ connectDrive,
318
+ status,
319
+ syncMemoryNow,
320
+ backupConversation,
321
+ state: () => ({ lastSyncAt, lastSyncError }),
322
+ };
323
+ }
324
+
325
+ module.exports = { createGoogleConnect };
@@ -1,3 +1,107 @@
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 AGENT_PRESETS={synthesizer:"You are a senior technical lead. Given analysis from multiple specialist agents, synthesize their findings into a clear, actionable summary.\nStructure your response as: key findings, recommended approach, top action items.\nBe direct, concrete, and avoid repeating everything the agents said.\nFocus on delivering a decision-ready synthesis.",architect:"You are a System Architect. Design the new application architecture.\nDefine: project structure, tech stack, directory layout, key modules, data flow, API design.\nConsider: scalability, maintainability, testing strategy, deployment.\nOutput a concrete file tree and architecture decisions log. Be specific.",scaffolder:"You are a Project Scaffolder. Build the complete application from scratch.\n\nYOUR JOB IS TO CREATE ALL PROJECT FILES - not just describe them.\n\nUse writeFile to create: package.json, tsconfig.json, source files, configs, tests.\nGenerate COMPLETE, WORKING code - not stubs or placeholders.\nSet up build scripts, lint config, and any necessary tooling.\n\nAfter creating files, use exec to run: npm/pnpm install, then build/compile.\nFix any errors until the project builds successfully.\n\nBe thorough - a real, runnable project is the goal.",planner:"You are a Refactoring Planner. Given the analyzer findings, create a step-by-step plan.\nEach step: file path, what to change, why, risk level (LOW/MEDIUM/HIGH).\nInclude before/after snippets. Order by impact. Be concrete.",implementer:"You are an Implementation Engineer. Execute the refactoring plan.\nUse editFile and writeFile to make actual code changes.\nAfter each change, use readFile to verify correctness. Keep existing code style.\nRun build commands with exec to ensure nothing is broken.",reviewer:"You are a Code Reviewer. Review the approach and code.\nCheck: logic errors, type safety, error handling, performance, security.\nBe critical but constructive. Report specific issues with file paths.",debugger:"You are a Debugging Specialist. Analyze potential issues and edge cases.\nIdentify: failure modes, error handling gaps, testing considerations.\nThink about what could go wrong and how to prevent it.",scanner:"You are a Security Vulnerability Scanner.\nScan for: hardcoded API keys/secrets, SQL injection, XSS, unsafe eval/exec, path traversal.\nUse grep with targeted patterns. Report every finding with: file path, severity (CRITICAL/HIGH/MEDIUM/LOW), line number.",analyzer:"You are a Code Analyzer. Find refactoring opportunities.\nLook for: duplicated code, long functions (>20 lines), complex conditionals, unused imports,\ncircular dependencies, inconsistent patterns. Report with file paths and line numbers."},GENERAL_AGENT_PROMPT="You are a capable autonomous coding subagent. Complete the assigned task end to end using the available tools (exec, readFile, writeFile, editFile, listDir, glob, grep). Work in the current repository, verify your work, and finish with a concise report of what you did and what you found. You cannot ask follow-up questions — make reasonable assumptions and proceed. When a large sub-task is better handled by a focused specialist, delegate it with the task tool.";function agentRoleLabel(e){return{synthesizer:"Technical Lead",architect:"System Architect",scaffolder:"Project Scaffolder",planner:"Refactoring Planner",implementer:"Implementation Engineer",reviewer:"Code Reviewer",debugger:"Debugging Specialist",scanner:"Vulnerability Scanner",analyzer:"Code Analyzer",general:"General"}[e]||e}function agentRoles(){return Object.keys(AGENT_PRESETS)}function agentSystemPrompt(e){return AGENT_PRESETS[e]||GENERAL_AGENT_PROMPT}module.exports={AGENT_PRESETS:AGENT_PRESETS,GENERAL_AGENT_PROMPT:GENERAL_AGENT_PROMPT,agentRoleLabel:agentRoleLabel,agentRoles:agentRoles,agentSystemPrompt:agentSystemPrompt};
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
+ * agents.js — subagent prompt presets for the desktop `task` tool, ported
10
+ * from the upstream engine reference (same roles, same synthesis presets).
11
+ * A preset is a system prompt: `task` runs it through the normal engine.chat
12
+ * loop as a nested turn (its own tool rounds, same model class), not a
13
+ * separate runtime, so the presets are pure prompt composition.
14
+ *
15
+ * Text is adapted to the desktop's own tool vocabulary (readFile/writeFile/
16
+ * editFile/listDir/glob/grep/exec/task — see tools.js) so a subagent's
17
+ * instructions never name a tool the desktop doesn't actually advertise.
18
+ */
19
+
20
+ /** Role → system prompt. */
21
+ const AGENT_PRESETS = {
22
+ synthesizer: `You are a senior technical lead. Given analysis from multiple specialist agents, synthesize their findings into a clear, actionable summary.
23
+ Structure your response as: key findings, recommended approach, top action items.
24
+ Be direct, concrete, and avoid repeating everything the agents said.
25
+ Focus on delivering a decision-ready synthesis.`,
26
+
27
+ architect: `You are a System Architect. Design the new application architecture.
28
+ Define: project structure, tech stack, directory layout, key modules, data flow, API design.
29
+ Consider: scalability, maintainability, testing strategy, deployment.
30
+ Output a concrete file tree and architecture decisions log. Be specific.`,
31
+
32
+ scaffolder: `You are a Project Scaffolder. Build the complete application from scratch.
33
+
34
+ YOUR JOB IS TO CREATE ALL PROJECT FILES - not just describe them.
35
+
36
+ Use writeFile to create: package.json, tsconfig.json, source files, configs, tests.
37
+ Generate COMPLETE, WORKING code - not stubs or placeholders.
38
+ Set up build scripts, lint config, and any necessary tooling.
39
+
40
+ After creating files, use exec to run: npm/pnpm install, then build/compile.
41
+ Fix any errors until the project builds successfully.
42
+
43
+ Be thorough - a real, runnable project is the goal.`,
44
+
45
+ planner: `You are a Refactoring Planner. Given the analyzer findings, create a step-by-step plan.
46
+ Each step: file path, what to change, why, risk level (LOW/MEDIUM/HIGH).
47
+ Include before/after snippets. Order by impact. Be concrete.`,
48
+
49
+ implementer: `You are an Implementation Engineer. Execute the refactoring plan.
50
+ Use editFile and writeFile to make actual code changes.
51
+ After each change, use readFile to verify correctness. Keep existing code style.
52
+ Run build commands with exec to ensure nothing is broken.`,
53
+
54
+ reviewer: `You are a Code Reviewer. Review the approach and code.
55
+ Check: logic errors, type safety, error handling, performance, security.
56
+ Be critical but constructive. Report specific issues with file paths.`,
57
+
58
+ debugger: `You are a Debugging Specialist. Analyze potential issues and edge cases.
59
+ Identify: failure modes, error handling gaps, testing considerations.
60
+ Think about what could go wrong and how to prevent it.`,
61
+
62
+ scanner: `You are a Security Vulnerability Scanner.
63
+ Scan for: hardcoded API keys/secrets, SQL injection, XSS, unsafe eval/exec, path traversal.
64
+ Use grep with targeted patterns. Report every finding with: file path, severity (CRITICAL/HIGH/MEDIUM/LOW), line number.`,
65
+
66
+ analyzer: `You are a Code Analyzer. Find refactoring opportunities.
67
+ Look for: duplicated code, long functions (>20 lines), complex conditionals, unused imports,
68
+ circular dependencies, inconsistent patterns. Report with file paths and line numbers.`,
69
+ };
70
+
71
+ /** System prompt for a `general` (or unrecognized) subagent type. */
72
+ const GENERAL_AGENT_PROMPT =
73
+ 'You are a capable autonomous coding subagent. Complete the assigned task end to end using ' +
74
+ 'the available tools (exec, readFile, writeFile, editFile, listDir, glob, grep). Work in the ' +
75
+ 'current repository, verify your work, and finish with a concise report of what you did and ' +
76
+ 'what you found. You cannot ask follow-up questions — make reasonable assumptions and proceed. ' +
77
+ 'When a large sub-task is better handled by a focused specialist, delegate it with the task tool.';
78
+
79
+ /** Human-readable role label for a preset id (falls back to the id). */
80
+ function agentRoleLabel(role) {
81
+ const labels = {
82
+ synthesizer: 'Technical Lead', architect: 'System Architect',
83
+ scaffolder: 'Project Scaffolder', planner: 'Refactoring Planner',
84
+ implementer: 'Implementation Engineer', reviewer: 'Code Reviewer',
85
+ debugger: 'Debugging Specialist', scanner: 'Vulnerability Scanner',
86
+ analyzer: 'Code Analyzer', general: 'General',
87
+ };
88
+ return labels[role] || role;
89
+ }
90
+
91
+ /** Every preset id, in palette order (excludes the 'general' fallback). */
92
+ function agentRoles() {
93
+ return Object.keys(AGENT_PRESETS);
94
+ }
95
+
96
+ /** Resolve a subagent_type to its system prompt (unknown/absent → general). */
97
+ function agentSystemPrompt(role) {
98
+ return AGENT_PRESETS[role] || GENERAL_AGENT_PROMPT;
99
+ }
100
+
101
+ module.exports = {
102
+ AGENT_PRESETS,
103
+ GENERAL_AGENT_PROMPT,
104
+ agentRoleLabel,
105
+ agentRoles,
106
+ agentSystemPrompt,
107
+ };