aegisone 1.0.34 → 1.0.35

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/LICENSE +661 -0
  2. package/README.md +1 -1
  3. package/SOURCE-OFFER.txt +9 -0
  4. package/bin/aegis.js +1 -322
  5. package/package.json +4 -5
  6. package/scripts/bump.mjs +1 -211
  7. package/scripts/bundle.js +1 -129
  8. package/scripts/predist.mjs +1 -976
  9. package/src/child.js +1 -285
  10. package/src/dispatch.js +1 -269
  11. package/src/doctor.js +1 -639
  12. package/src/host.js +1 -111
  13. package/src/permissions.js +1 -383
  14. package/src/probes.js +1 -159
  15. package/src/release.js +1 -409
  16. package/vendor/cli/package.json +3 -7
  17. package/vendor/cli/scripts/check.mjs +1 -52
  18. package/vendor/cli/scripts/demo.mjs +1 -94
  19. package/vendor/cli/scripts/predist.mjs +1 -75
  20. package/vendor/cli/scripts/runtests.mjs +1 -56
  21. package/vendor/cli/scripts/seal-gate.mjs +1 -74
  22. package/vendor/cli/src/agents.js +1 -139
  23. package/vendor/cli/src/app.js +1 -2957
  24. package/vendor/cli/src/art.js +1 -289
  25. package/vendor/cli/src/chatflow.js +1 -3023
  26. package/vendor/cli/src/checkpoint.js +1 -90
  27. package/vendor/cli/src/clipboard.js +1 -424
  28. package/vendor/cli/src/cloudsync.js +1 -528
  29. package/vendor/cli/src/commands.js +1 -4089
  30. package/vendor/cli/src/config.js +1 -581
  31. package/vendor/cli/src/connect.js +1 -349
  32. package/vendor/cli/src/credentials.js +1 -33
  33. package/vendor/cli/src/deps.js +1 -232
  34. package/vendor/cli/src/devrun.js +1 -187
  35. package/vendor/cli/src/diff.js +1 -333
  36. package/vendor/cli/src/diffview.js +1 -296
  37. package/vendor/cli/src/engine.js +1 -297
  38. package/vendor/cli/src/entitlement.js +1 -355
  39. package/vendor/cli/src/events.js +1 -707
  40. package/vendor/cli/src/export.js +1 -67
  41. package/vendor/cli/src/filepreview.js +1 -153
  42. package/vendor/cli/src/fingerprint.js +1 -592
  43. package/vendor/cli/src/format.js +1 -259
  44. package/vendor/cli/src/fuzzy.js +1 -119
  45. package/vendor/cli/src/history.js +1 -423
  46. package/vendor/cli/src/init.js +1 -175
  47. package/vendor/cli/src/input.js +1 -139
  48. package/vendor/cli/src/keys.js +1 -183
  49. package/vendor/cli/src/markdown.js +1 -306
  50. package/vendor/cli/src/models.js +1 -507
  51. package/vendor/cli/src/naming.js +1 -57
  52. package/vendor/cli/src/overlays.js +1 -462
  53. package/vendor/cli/src/panels.js +1 -1418
  54. package/vendor/cli/src/ping.js +1 -226
  55. package/vendor/cli/src/presence.js +1 -238
  56. package/vendor/cli/src/render.js +1 -516
  57. package/vendor/cli/src/screen.js +1 -518
  58. package/vendor/cli/src/screens.js +1 -896
  59. package/vendor/cli/src/secret.js +1 -59
  60. package/vendor/cli/src/securefs.js +1 -359
  61. package/vendor/cli/src/settings.js +1 -155
  62. package/vendor/cli/src/shared.js +1 -52
  63. package/vendor/cli/src/sharedpaths.js +1 -53
  64. package/vendor/cli/src/signup.js +1 -156
  65. package/vendor/cli/src/summarize.js +1 -95
  66. package/vendor/cli/src/sysdiag.js +1 -585
  67. package/vendor/cli/src/system.js +1 -40
  68. package/vendor/cli/src/theme.js +1 -570
  69. package/vendor/cli/src/title.js +1 -220
  70. package/vendor/cli/src/todos.js +1 -115
  71. package/vendor/cli/src/tokens.js +1 -263
  72. package/vendor/cli/src/topup.js +1 -210
  73. package/vendor/cli/src/update.js +1 -191
  74. package/vendor/cli/vendor/client/aegis.js +1 -2441
  75. package/vendor/cli/vendor/client/attest.js +1 -518
  76. package/vendor/cli/vendor/client/authorship-key.js +1 -410
  77. package/vendor/cli/vendor/client/auto-provision.js +1 -134
  78. package/vendor/cli/vendor/client/brain-catalog.js +1 -268
  79. package/vendor/cli/vendor/client/byok-catalog.js +1 -199
  80. package/vendor/cli/vendor/client/catalog-client.js +1 -487
  81. package/vendor/cli/vendor/client/conversation-export.js +1 -177
  82. package/vendor/cli/vendor/client/credentials.js +1 -494
  83. package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
  84. package/vendor/cli/vendor/client/drive-connect.js +1 -110
  85. package/vendor/cli/vendor/client/drive-upload.js +1 -234
  86. package/vendor/cli/vendor/client/env-file.js +1 -1273
  87. package/vendor/cli/vendor/client/fingerprint.js +1 -1064
  88. package/vendor/cli/vendor/client/foreign-memory.js +1 -669
  89. package/vendor/cli/vendor/client/google-signin.js +1 -133
  90. package/vendor/cli/vendor/client/hooks.js +1 -430
  91. package/vendor/cli/vendor/client/model-discovery.js +1 -373
  92. package/vendor/cli/vendor/client/naming.js +1 -283
  93. package/vendor/cli/vendor/client/platform.js +1 -937
  94. package/vendor/cli/vendor/client/prefs.js +1 -351
  95. package/vendor/cli/vendor/client/presence-constants.js +1 -107
  96. package/vendor/cli/vendor/client/presence.js +1 -438
  97. package/vendor/cli/vendor/client/record-vault.js +3 -1055
  98. package/vendor/cli/vendor/client/session-store.js +1 -575
  99. package/vendor/cli/vendor/client/topup.js +1 -297
  100. package/vendor/cli/vendor/client/touch.js +1 -458
  101. package/vendor/cli/vendor/client/update.js +1 -763
  102. package/vendor/cli/vendor/client/user-models.js +1 -381
  103. package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
  104. package/vendor/cli/vendor/desktop/lib/local/attachments.js +1 -276
  105. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
  106. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -1028
  107. package/vendor/cli/vendor/desktop/lib/local/context.js +1 -125
  108. package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3666
  109. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -660
  110. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
  111. package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2145
  112. package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -280
  113. package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
  114. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -238
  115. package/vendor/cli/vendor/desktop/lib/local/spill.js +1 -75
  116. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
  117. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
  118. package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
  119. package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
  120. package/vendor/cli/vendor/hosts/install.js +1 -638
  121. package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
  122. package/vendor/cli/vendor/hosts/spec.js +1 -164
  123. package/vendor/cli/vendor/hosts/targets.js +1 -346
  124. package/vendor/cli/vendor/mcp/server.js +1 -221
  125. package/vendor/cli/vendor/mcp/tools.js +1 -408
  126. package/vendor/cli/vendor/one/src/child.js +1 -285
  127. package/vendor/cli/vendor/one/src/permissions.js +1 -383
  128. package/vendor/desktop/bin/aegis.js +1 -32
  129. package/vendor/desktop/lib/account-key.js +1 -56
  130. package/vendor/desktop/lib/auto.js +1 -461
  131. package/vendor/desktop/lib/avatar/companion.js +1 -698
  132. package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
  133. package/vendor/desktop/lib/avatar/events.js +1 -344
  134. package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
  135. package/vendor/desktop/lib/avatar/holders.js +1 -612
  136. package/vendor/desktop/lib/avatar/identity.js +1 -641
  137. package/vendor/desktop/lib/avatar/level.js +1 -368
  138. package/vendor/desktop/lib/avatar/mirror.js +1 -524
  139. package/vendor/desktop/lib/avatar/persona.js +1 -388
  140. package/vendor/desktop/lib/avatar/profile.js +1 -977
  141. package/vendor/desktop/lib/avatar/register.js +1 -307
  142. package/vendor/desktop/lib/avatar/store.js +1 -472
  143. package/vendor/desktop/lib/avatar/tiers.js +1 -38
  144. package/vendor/desktop/lib/avatar/transfer.js +1 -415
  145. package/vendor/desktop/lib/avatar/turn.js +1 -216
  146. package/vendor/desktop/lib/avatar/voice.js +1 -328
  147. package/vendor/desktop/lib/avatar/xp.js +1 -404
  148. package/vendor/desktop/lib/deep-link.js +1 -120
  149. package/vendor/desktop/lib/fingerprint.js +2 -347
  150. package/vendor/desktop/lib/google-connect.js +1 -323
  151. package/vendor/desktop/lib/local/agents.js +1 -105
  152. package/vendor/desktop/lib/local/attachments.js +1 -276
  153. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  154. package/vendor/desktop/lib/local/claude-pro.js +1 -1028
  155. package/vendor/desktop/lib/local/context.js +1 -125
  156. package/vendor/desktop/lib/local/engine.js +1 -3666
  157. package/vendor/desktop/lib/local/entitlement.js +1 -660
  158. package/vendor/desktop/lib/local/git-scope.js +1 -228
  159. package/vendor/desktop/lib/local/local.js +1 -2145
  160. package/vendor/desktop/lib/local/prompt.js +1 -280
  161. package/vendor/desktop/lib/local/queue.js +1 -560
  162. package/vendor/desktop/lib/local/session-rounds.js +1 -238
  163. package/vendor/desktop/lib/local/spill.js +1 -75
  164. package/vendor/desktop/lib/local/telemetry.js +1 -470
  165. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  166. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  167. package/vendor/desktop/lib/provider-key-mirror.js +1 -252
  168. package/vendor/desktop/lib/quick-launcher.js +1 -84
  169. package/vendor/desktop/lib/settings.js +1 -890
  170. package/vendor/desktop/lib/sync/memory-queue.js +1 -60
  171. package/vendor/desktop/lib/sync/persist-gate.js +1 -148
  172. package/vendor/desktop/lib/sync/sessions.js +1 -106
  173. package/vendor/desktop/lib/window-state.js +1 -66
  174. package/vendor/desktop/package.json +2 -4
  175. package/vendor/desktop/preload.js +1 -679
  176. package/vendor/desktop/renderer/app.js +1 -7250
  177. package/vendor/desktop/renderer/avatar/assemble.js +1 -335
  178. package/vendor/desktop/renderer/avatar/avatar.js +1 -380
  179. package/vendor/desktop/renderer/avatar/cards.js +1 -141
  180. package/vendor/desktop/renderer/avatar/hud.js +1 -206
  181. package/vendor/desktop/renderer/avatar/machine.js +1 -213
  182. package/vendor/desktop/renderer/avatar/pane.js +1 -439
  183. package/vendor/desktop/renderer/avatar/parts.js +1 -437
  184. package/vendor/desktop/renderer/budget.js +1 -172
  185. package/vendor/desktop/renderer/companion.js +1 -223
  186. package/vendor/desktop/renderer/diff.js +1 -359
  187. package/vendor/desktop/renderer/diffview.js +1 -336
  188. package/vendor/desktop/renderer/filepreview.js +1 -211
  189. package/vendor/desktop/renderer/fingerprint.js +3 -789
  190. package/vendor/desktop/renderer/markdown.js +1 -168
  191. package/vendor/desktop/renderer/provider-mark.js +1 -311
  192. package/vendor/desktop/renderer/provider-toolbar.js +1 -134
  193. package/vendor/desktop/renderer/providers.js +1 -259
  194. package/vendor/desktop/renderer/quick.js +1 -285
  195. package/vendor/desktop/renderer/stream-policy.js +1 -387
  196. package/vendor/desktop/renderer/transcript-view.js +1 -323
  197. package/vendor/desktop/renderer/usage.js +1 -1239
  198. package/vendor/desktop/vendor/aegis.js +1 -2441
  199. package/vendor/desktop/vendor/attest.js +1 -518
  200. package/vendor/desktop/vendor/authorship-key.js +1 -410
  201. package/vendor/desktop/vendor/auto-provision.js +1 -134
  202. package/vendor/desktop/vendor/brain-catalog.js +1 -268
  203. package/vendor/desktop/vendor/byok-catalog.js +1 -199
  204. package/vendor/desktop/vendor/catalog-client.js +1 -487
  205. package/vendor/desktop/vendor/conversation-export.js +1 -177
  206. package/vendor/desktop/vendor/credentials.js +1 -494
  207. package/vendor/desktop/vendor/device-fingerprint.js +1 -141
  208. package/vendor/desktop/vendor/drive-connect.js +1 -110
  209. package/vendor/desktop/vendor/drive-upload.js +1 -234
  210. package/vendor/desktop/vendor/env-file.js +1 -1273
  211. package/vendor/desktop/vendor/fingerprint.js +1 -1064
  212. package/vendor/desktop/vendor/foreign-memory.js +1 -669
  213. package/vendor/desktop/vendor/google-signin.js +1 -133
  214. package/vendor/desktop/vendor/hooks.js +1 -430
  215. package/vendor/desktop/vendor/model-discovery.js +1 -373
  216. package/vendor/desktop/vendor/naming.js +1 -283
  217. package/vendor/desktop/vendor/platform.js +1 -937
  218. package/vendor/desktop/vendor/prefs.js +1 -351
  219. package/vendor/desktop/vendor/presence-constants.js +1 -107
  220. package/vendor/desktop/vendor/presence.js +1 -438
  221. package/vendor/desktop/vendor/record-vault.js +3 -1055
  222. package/vendor/desktop/vendor/session-store.js +1 -575
  223. package/vendor/desktop/vendor/topup.js +1 -297
  224. package/vendor/desktop/vendor/touch.js +1 -458
  225. package/vendor/desktop/vendor/update.js +1 -763
  226. package/vendor/desktop/vendor/user-models.js +1 -381
@@ -1,325 +1,3 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
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 };
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};
@@ -1,107 +1,3 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
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
- };
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};