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,681 +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
- * Preload — the ONLY bridge between the isolated renderer and the main
10
- * process. Exposes a whitelisted window.aegis.* surface backed by
11
- * ipcRenderer.invoke over the aegis:<method> channels registered in main.js.
12
- *
13
- * Security: contextIsolation + sandbox are enabled in main.js; no Node
14
- * globals leak through this bridge. Every method returns the backend's plain
15
- * JSON payload, and the API key never crosses this bridge — the renderer only
16
- * ever sees a masked preview via `status`.
17
- */
18
-
19
- const { contextBridge, ipcRenderer } = require('electron');
20
-
21
- const IPC_PREFIX = 'aegis:';
22
- const MODEL_PREFIX = 'model:';
23
- const SYNC_PREFIX = 'sync:';
24
- const QUICK_PREFIX = 'quick:';
25
- const QUEUE_PREFIX = 'queue:';
26
- const AUTO_PREFIX = 'auto:';
27
- const QUEUE_PROGRESS_CHANNEL = `${QUEUE_PREFIX}progress`;
28
- const CHAT_DELTA_CHANNEL = `${IPC_PREFIX}chatDelta`;
29
- const UPDATE_STATUS_CHANNEL = `${IPC_PREFIX}updateStatus`;
30
- const ACCOUNT_STATUS_CHANNEL = `${IPC_PREFIX}accountStatusChanged`;
31
- const MENU_NEW_CHAT_CHANNEL = `${IPC_PREFIX}menuNewChat`;
32
- const MENU_SEARCH_CHANNEL = `${IPC_PREFIX}menuSearch`;
33
- const MENU_EXPORT_MARKDOWN_CHANNEL = `${IPC_PREFIX}menuExportMarkdown`;
34
- const MENU_EXPORT_JSON_CHANNEL = `${IPC_PREFIX}menuExportJson`;
35
- const MENU_FINGERPRINT_CHANNEL = `${IPC_PREFIX}menuFingerprint`;
36
- const MENU_GOOGLE_DRIVE_CHANNEL = `${IPC_PREFIX}menuGoogleDrive`;
37
- const DEEP_LINK_CHANNEL = `${IPC_PREFIX}deepLink`;
38
- const QUICK_LAUNCHER_PUSH_CHANNEL = `${IPC_PREFIX}quickLauncherPush`;
39
-
40
- function invoke(name, payload) {
41
- return ipcRenderer.invoke(
42
- IPC_PREFIX + name,
43
- payload === undefined ? undefined : payload
44
- );
45
- }
46
-
47
- function invokeModel(name, payload) {
48
- return ipcRenderer.invoke(
49
- MODEL_PREFIX + name,
50
- payload === undefined ? undefined : payload
51
- );
52
- }
53
-
54
- function invokeSync(name, payload) {
55
- return ipcRenderer.invoke(
56
- SYNC_PREFIX + name,
57
- payload === undefined ? undefined : payload
58
- );
59
- }
60
-
61
- function invokeQuick(name, payload) {
62
- return ipcRenderer.invoke(
63
- QUICK_PREFIX + name,
64
- payload === undefined ? undefined : payload
65
- );
66
- }
67
-
68
- function invokeQueue(name, payload) {
69
- return ipcRenderer.invoke(
70
- QUEUE_PREFIX + name,
71
- payload === undefined ? undefined : payload
72
- );
73
- }
74
-
75
- function invokeAuto(name, payload) {
76
- return ipcRenderer.invoke(
77
- AUTO_PREFIX + name,
78
- payload === undefined ? undefined : payload
79
- );
80
- }
81
-
82
- /**
83
- * Build the chatDelta listener for one streaming request.
84
- *
85
- * Chunks arrive on a single shared channel, tagged by the main process with
86
- * the sessionId of the request they came from (see `taggedChunk` in main.js).
87
- * Filtering here is what makes concurrent streams safe: the primary answer and
88
- * each card of the horizontal discovery lane subscribe with their own
89
- * sessionId, so one reply can never bleed into another card's body.
90
- *
91
- * The normalisation is deliberately loose-strict: `undefined`/`''` ids
92
- * (legacy single-stream callers that pass no sessionId) are treated as one
93
- * bucket, so the old behaviour — receive every untagged chunk — is preserved
94
- * byte for byte.
95
- */
96
- function deltaListener(sessionId, onDelta) {
97
- const want = sessionId || null;
98
- return (_event, chunk) => {
99
- const id = chunk && chunk.id ? chunk.id : null;
100
- if (id !== want) return;
101
- onDelta(chunk);
102
- };
103
- }
104
-
105
- // Whitelist — mirrors the dispatch map in main.js. If a method is not listed
106
- // here the renderer cannot call it: add surface here AND there deliberately.
107
- const api = {
108
- status: () => invoke('status'),
109
- // ── Drag-and-drop attachments ───────────────────────────────────────────
110
- //
111
- // The composer drops files, pictures and search paths onto the window. A
112
- // sandboxed renderer CANNOT read a dropped file: `File.path` was removed
113
- // from Electron, and this window runs with contextIsolation, so the renderer
114
- // only ever sees a File handle with no location.
115
- //
116
- // `webUtils.getPathForFile` is the supported replacement, and it MUST be
117
- // called here in preload — `webUtils` is not exposed to a sandboxed renderer
118
- // at all, and the File object only carries its path inside the same process
119
- // that received the drop. So the renderer calls `attachments.pathFor(file)`,
120
- // gets a plain string back, and hands it to `ingest` (main.js
121
- // ingestAttachment), which is where the realpath/regular-file/size checks
122
- // live. Nothing about the file's bytes ever passes through this bridge
123
- // unvalidated, and no directory-listing or arbitrary-read capability is
124
- // added: ingest reads exactly the one path it is given, once.
125
- attachments: Object.freeze({
126
- pathFor: (file) => {
127
- try {
128
- const { webUtils } = require('electron');
129
- if (!webUtils || typeof webUtils.getPathForFile !== 'function') return '';
130
- return webUtils.getPathForFile(file) || '';
131
- } catch {
132
- return '';
133
- }
134
- },
135
- ingest: (filePath) => invoke('attachments:ingest', { path: String(filePath == null ? '' : filePath) }),
136
- }),
137
- // In-app key entry: the raw key flows renderer -> main only (never back).
138
- // The main process persists it encrypted and returns a masked preview.
139
- setApiKey: (key) => invoke('setApiKey', { key }),
140
- verifyApiKey: () => invoke('verifyApiKey'),
141
- tokenBankBalance: () => invoke('tokenBankBalance'),
142
- // Billing: both start a Stripe-hosted checkout and resolve a shaped
143
- // `{ ok, url | status, reason, upgrade }` (main.js billingResult). The
144
- // renderer opens the returned URL with openExternal below — the checkout
145
- // page itself never loads in this window.
146
- billingCheckout: () => invoke('billingCheckout'),
147
- tokenBankTopup: (amountEur) => invoke('tokenBankTopup', { amountEur }),
148
- listModels: () => invoke('listModels'),
149
- // Pre-edit file read for the diff preview (renderer/deriveDiff). A Write's
150
- // preview needs the file's contents as they were *before* the executor
151
- // overwrites them, and editPreview consumes a reader synchronously — so this
152
- // one method is sentSync, not invoke. It is the narrowest possible widening
153
- // of the bridge: main constrains the path to inside `cwd` and caps the read
154
- // (main.js readTextFileForPreview), so the renderer can only ever reach files
155
- // the session it is displaying is already allowed to edit. Returns
156
- // `{ text, truncated }` or null; a bridge failure reports null rather than
157
- // throwing onto the render path, which degrades the diff to a create-style
158
- // "all additions" block.
159
- readTextFile: (file, cwd) => {
160
- try {
161
- return ipcRenderer.sendSync(MODEL_PREFIX + 'readTextFile', {
162
- file,
163
- cwd,
164
- });
165
- } catch {
166
- return null;
167
- }
168
- },
169
- // Streaming chat (D2.1): pass an onDelta callback to receive SSE chunks as
170
- // they arrive (pushed from main over aegis:chatDelta). The invoke promise
171
- // resolves once with the normalised final result. Without a callback the
172
- // request is plain non-streaming, exactly as before.
173
- chatCompletion: (payload, onDelta) => {
174
- const opts = payload || {};
175
- if (typeof onDelta !== 'function') {
176
- return invoke('chatCompletion', { ...opts, stream: false });
177
- }
178
- const listener = deltaListener(opts.sessionId, onDelta);
179
- const cleanup = () =>
180
- ipcRenderer.removeListener(CHAT_DELTA_CHANNEL, listener);
181
- ipcRenderer.on(CHAT_DELTA_CHANNEL, listener);
182
- return invoke('chatCompletion', { ...opts, stream: true }).then(
183
- (result) => {
184
- cleanup();
185
- return result;
186
- },
187
- (err) => {
188
- cleanup();
189
- throw err;
190
- }
191
- );
192
- },
193
- byokStatus: () => invoke('byokStatus'),
194
- byokSet: (provider, apiKey) => invoke('byokSet', { provider, apiKey }),
195
- memorySearch: (query, limit) => invoke('memorySearch', { query, limit }),
196
- memorySave: (entry) => invoke('memorySave', { entry }),
197
- memoryList: (limit) => invoke('memoryList', { limit }),
198
- verifyToken: (token) => invoke('verifyToken', { token }),
199
- memoryActivate: (token) => invoke('memoryActivate', { token }),
200
- memoryPull: (since) => invoke('memoryPull', { since }),
201
- memorySaveBatch: (entries) => invoke('memorySaveBatch', { entries }),
202
- memoryImport: (payload) => invoke('memoryImport', payload || {}),
203
- importConversation: (payload) => invoke('importConversation', payload || {}),
204
- // Rendered markdown's links (and the discovery lane's) open in the OS
205
- // default browser, never the app's own BrowserWindow — see main.js
206
- // isSafeExternalUrl for the http/https-only allowlist.
207
- openExternal: (url) => invoke('openExternal', { url }),
208
-
209
- // φ(α) — the authorship key and sealed session records (main.js
210
- // createIpcDispatch -> lib/fingerprint.js). Every call resolves
211
- // `{ ok, … }`/`{ ok: false, error }` rather than throwing, so the UI shows the
212
- // actual reason (e.g. "this key file is readable by other users") instead of
213
- // Electron's opaque "Error invoking remote method". The key itself is never
214
- // returned in any of these payloads — only its derived 12-hex fingerprint.
215
- fingerprintStatus: () => invoke('fingerprintStatus'),
216
- fingerprintKeygen: (payload) => invoke('fingerprintKeygen', payload || {}),
217
- fingerprintMint: (payload) => invoke('fingerprintMint', payload || {}),
218
- fingerprintVerify: (payload) => invoke('fingerprintVerify', payload || {}),
219
- fingerprintBackup: (payload) => invoke('fingerprintBackup', payload || {}),
220
- // The vault: publish a sealed record (default gdrive:AEGIS-AGPL/records),
221
- // check the published copy against the link, list it, audit it for key
222
- // material. `publish` is also a flag on fingerprintMint (`{ publish: true }`),
223
- // which seals and travels in one call. No handler takes or returns the key.
224
- fingerprintPublish: (payload) => invoke('fingerprintPublish', payload || {}),
225
- fingerprintAnchor: (payload) => invoke('fingerprintAnchor', payload || {}),
226
- fingerprintVault: () => invoke('fingerprintVault'),
227
- fingerprintVaultAudit: () => invoke('fingerprintVaultAudit'),
228
-
229
- // Tool-call approval toggle (Settings → "Confirm before running tools"):
230
- // main.js createConfirmModeDispatch persists it in the settings store's
231
- // reserved `__confirmMode` namespace, and the engine's gate
232
- // (lib/local/engine.js gatedExecuteTool) reads it on every mutating tool
233
- // call. Both resolve `{ enabled }`.
234
- getConfirmMode: () => invoke('getConfirmMode'),
235
- setConfirmMode: (enabled) => invoke('setConfirmMode', { enabled: Boolean(enabled) }),
236
-
237
- // Vault backend (the authorship panel's Google Drive / AE / No sync picker):
238
- // main.js createVaultBackendDispatch persists it in the settings store's
239
- // reserved `__vaultBackend` namespace, and lib/fingerprint.js's
240
- // vaultScope()/vaultDisabled() read it on every publish/anchor/vault/audit
241
- // call. Both resolve `{ backend }`.
242
- getVaultBackend: () => invoke('getVaultBackend'),
243
- setVaultBackend: (backend) => invoke('setVaultBackend', { backend: String(backend || '') }),
244
-
245
- // Funnel instrumentation (Phase 2 of docs/upgrade-conversion-plan.md). The
246
- // renderer emits exactly two event names, on two surfaces, carrying a
247
- // campaign and a surface — nothing else, ever. This method picks those three
248
- // fields explicitly (never the raw payload) and hands them to main's
249
- // whitelist (lib/local/telemetry.js), so no key, no prompt text, no path and
250
- // no model output can ride along even by accident.
251
- //
252
- // FIRE AND FORGET: the renderer must not await this and nothing it resolves
253
- // changes what is drawn. main's handler answers `{ ok }` and never rejects;
254
- // a failure on that side is invisible here by design.
255
- telemetryEvent: (name, payload) => {
256
- const p = payload || {};
257
- return invoke('telemetryEvent', {
258
- event: name == null ? '' : String(name),
259
- campaign: p.campaign == null ? null : String(p.campaign),
260
- surface: p.surface == null ? null : String(p.surface),
261
- });
262
- },
263
- // The local summary (`{ enabled, transport, file, byCampaign, … }`). Exists
264
- // because the transport is local-first while aegis1 has no ingest route; the
265
- // offline reader is scripts/funnel-report.mjs.
266
- telemetryReport: () => invoke('telemetryReport'),
267
- // The ÆGIS covenant (ÆL/1) — READ THE WHOLE COMMENT BEFORE ADDING TO THIS.
268
- //
269
- // Both methods are pure reads of the decoded seal: `covenantStatus` returns
270
- // the clause counts, the rights/duties/tiers, the safety axioms, the
271
- // immutable set, src_sha256 and the seal hash; `covenantGapReport` returns
272
- // which duties the host actually enforces versus only carries (Λ7's duty to
273
- // name the gap rather than imply it is closed).
274
- //
275
- // THERE IS DELIBERATELY NO WRITE HALF. No setCovenant, no disable, no
276
- // amend, no override — main.js registers exactly two read-only handlers and
277
- // nothing else, so there is no channel for a renderer to call even if one
278
- // wanted to. That is the §9 amendment invariant ¬M(Λ1) ∧ ¬M(Λ2) ∧ ¬M(Λ4)
279
- // holding at the process boundary: Λ1 honesty, Λ2 non-harm and Λ4
280
- // accountability cannot be removed by any vote, tier, config or message.
281
- // Enforcement does not live here at all — it is the unconditional
282
- // pre-action assert in lib/local/engine.js guardedExecute, which a renderer
283
- // request cannot reach, skip, or reverse.
284
- covenantStatus: () => invoke('covenantStatus'),
285
- covenantGapReport: () => invoke('covenantGapReport'),
286
- // Persisting memory (the desktop counterpart of the CLI's `memoryPersist`):
287
- // whether a finished turn is pushed to cloud memory automatically. Default
288
- // ON; `source` distinguishes a stored preference from that default.
289
- getMemoryPersist: () => invoke('memoryPersist.get'),
290
- setMemoryPersist: (enabled) => invoke('memoryPersist.set', { enabled: Boolean(enabled) }),
291
-
292
- // Auto-update (npm registry — see main.js createUpdateManager). check and
293
- // download resolve the same status shape the push channel delivers: download
294
- // installs on an explicit click and only then, and quitAndInstallUpdate must
295
- // only ever be called from an explicit user action (the banner's "Restart to
296
- // install" button) — main.js never restarts on its own.
297
- checkForUpdates: () => invoke('checkForUpdates'),
298
- downloadUpdate: () => invoke('downloadUpdate'),
299
- quitAndInstallUpdate: () => invoke('quitAndInstallUpdate'),
300
- updateStatus: () => invoke('updateStatus'),
301
- // Live push as the state machine advances (checking -> available ->
302
- // downloading -> downloaded, or -> error at any point). Returns an
303
- // unsubscribe function, same shape as the chat delta listeners above.
304
- onUpdateStatus: (onStatus) => {
305
- const listener = (_event, state) => onStatus(state);
306
- ipcRenderer.on(UPDATE_STATUS_CHANNEL, listener);
307
- return () => ipcRenderer.removeListener(UPDATE_STATUS_CHANNEL, listener);
308
- },
309
- accountStatus: () => invoke('accountStatus'),
310
- registerAccount: () => invoke('registerAccount'),
311
- onAccountStatus: (onStatus) => {
312
- const listener = (_event, state) => onStatus(state);
313
- ipcRenderer.on(ACCOUNT_STATUS_CHANNEL, listener);
314
- return () => ipcRenderer.removeListener(ACCOUNT_STATUS_CHANNEL, listener);
315
- },
316
- // Google sign-in + Drive connect/sync (main.js lib/google-connect.js).
317
- // `driveSignIn` opens a browser for aegis1's `/auth/google` round-trip and
318
- // replaces this machine's saved key with the Google-linked one — the
319
- // desktop counterpart of the CLI's `aegiscode connect`. `driveConnect`
320
- // opens `/connect/drive` and polls until this (now Google-linked) account
321
- // shows a Drive token on file; it is only coherent once `driveSignIn` has
322
- // actually run. `driveStatus` is a one-shot, no-browser read for painting
323
- // the card on load. `driveSyncMemory` pulls this account's AEGIS cloud
324
- // memory and backs it up to a dedicated "AEGIS Memory" Drive folder.
325
- // `driveBackupConversation` saves ONE conversation as its own dated `.md`
326
- // there instead — a different scope from `driveSyncMemory`, deliberately a
327
- // separate channel. Every one resolves `{ ok, … }` / `{ ok: false, error }`,
328
- // never throws.
329
- driveSignIn: () => invoke('driveSignIn'),
330
- driveConnect: () => invoke('driveConnect'),
331
- driveStatus: () => invoke('driveStatus'),
332
- driveSyncMemory: () => invoke('driveSyncMemory'),
333
- driveBackupConversation: (sessionId) => invoke('driveBackupConversation', { sessionId }),
334
- // Native menu accelerators with no built-in Electron role (Cmd/Ctrl+N,
335
- // Cmd/Ctrl+K — see main.js buildAppMenu): main.js just pings the channel,
336
- // the renderer owns what "new chat" / "search" actually do.
337
- onMenuNewChat: (onTrigger) => {
338
- const listener = () => onTrigger();
339
- ipcRenderer.on(MENU_NEW_CHAT_CHANNEL, listener);
340
- return () => ipcRenderer.removeListener(MENU_NEW_CHAT_CHANNEL, listener);
341
- },
342
- onMenuSearch: (onTrigger) => {
343
- const listener = () => onTrigger();
344
- ipcRenderer.on(MENU_SEARCH_CHANNEL, listener);
345
- return () => ipcRenderer.removeListener(MENU_SEARCH_CHANNEL, listener);
346
- },
347
- // File > Save as… / Export Session… (see main.js buildAppMenu): the menu
348
- // has no renderer state of its own, so it just pings which format was
349
- // asked for; the renderer's handler knows the open session id and calls
350
- // exportSession() below — the same path the sidebar's Export button uses.
351
- onMenuExportMarkdown: (onTrigger) => {
352
- const listener = () => onTrigger();
353
- ipcRenderer.on(MENU_EXPORT_MARKDOWN_CHANNEL, listener);
354
- return () => ipcRenderer.removeListener(MENU_EXPORT_MARKDOWN_CHANNEL, listener);
355
- },
356
- // View > Authorship Panel… — the sidebar card that used to open the φ(α)
357
- // sheet is gone (sealing runs in the background), so the menu is the entry
358
- // point. The renderer owns the sheet, main only asks for it.
359
- onMenuFingerprint: (onTrigger) => {
360
- const listener = () => onTrigger();
361
- ipcRenderer.on(MENU_FINGERPRINT_CHANNEL, listener);
362
- return () => ipcRenderer.removeListener(MENU_FINGERPRINT_CHANNEL, listener);
363
- },
364
- // Account > Google Drive Backup… — same sheet as Authorship Panel above,
365
- // opened straight to the Drive row instead of leaving the Google sign-in
366
- // buttons to be found by scrolling past the unrelated φ(α) key controls.
367
- onMenuGoogleDrive: (onTrigger) => {
368
- const listener = () => onTrigger();
369
- ipcRenderer.on(MENU_GOOGLE_DRIVE_CHANNEL, listener);
370
- return () => ipcRenderer.removeListener(MENU_GOOGLE_DRIVE_CHANNEL, listener);
371
- },
372
- onMenuExportJson: (onTrigger) => {
373
- const listener = () => onTrigger();
374
- ipcRenderer.on(MENU_EXPORT_JSON_CHANNEL, listener);
375
- return () => ipcRenderer.removeListener(MENU_EXPORT_JSON_CHANNEL, listener);
376
- },
377
- // Writes the given session to a user-picked file (dialog.showSaveDialog
378
- // runs in main — see main.js createExportDispatch); resolves
379
- // { ok, filePath } or { ok: false, canceled | reason }.
380
- exportSession: (sessionId, format) => invoke('exportSession', { sessionId, format }),
381
- // aegis:// deep link (main.js sendDeepLinkToWindow): fires with
382
- // { action: 'open', sessionId } or { action: 'new', prompt }.
383
- onDeepLink: (onLink) => {
384
- const listener = (_event, parsed) => onLink(parsed);
385
- ipcRenderer.on(DEEP_LINK_CHANNEL, listener);
386
- return () => ipcRenderer.removeListener(DEEP_LINK_CHANNEL, listener);
387
- },
388
- // Quick launcher "add to chat" (main.js pushQuickLauncherResult): fires
389
- // with { prompt, response, model } once the user pushes a launcher answer
390
- // into the main window — see renderer/app.js's handler for what it builds.
391
- onQuickLauncherPush: (onPush) => {
392
- const listener = (_event, payload) => onPush(payload);
393
- ipcRenderer.on(QUICK_LAUNCHER_PUSH_CHANNEL, listener);
394
- return () => ipcRenderer.removeListener(QUICK_LAUNCHER_PUSH_CHANNEL, listener);
395
- },
396
- };
397
-
398
- // Model-class surface (plan P1 §5.3): backed by the `model:` channels in
399
- // main.js. Full keys never cross this bridge — settings.get/set return only
400
- // masked previews.
401
- const models = {
402
- listClasses: () => invokeModel('listClasses'),
403
- listModels: (cls) => invokeModel('listModels', { class: cls }),
404
- // Always streaming: pass an onDelta callback to receive live chunks over
405
- // CHAT_DELTA_CHANNEL; the invoke resolves once with the final result.
406
- chat: (payload, onDelta) => {
407
- const opts = payload || {};
408
- if (typeof onDelta !== 'function') {
409
- return invokeModel('chat', opts);
410
- }
411
- const listener = deltaListener(opts.sessionId, onDelta);
412
- const cleanup = () =>
413
- ipcRenderer.removeListener(CHAT_DELTA_CHANNEL, listener);
414
- ipcRenderer.on(CHAT_DELTA_CHANNEL, listener);
415
- return invokeModel('chat', opts).then(
416
- (result) => {
417
- cleanup();
418
- return result;
419
- },
420
- (err) => {
421
- cleanup();
422
- throw err;
423
- }
424
- );
425
- },
426
- settings: {
427
- get: () => invokeModel('settings.get'),
428
- set: (provider, cfg) =>
429
- invokeModel('settings.set', {
430
- provider,
431
- baseURL: cfg && cfg.baseURL,
432
- key: cfg && cfg.key,
433
- }),
434
- remove: (provider) => invokeModel('settings.remove', { provider }),
435
- },
436
- // The user's OWN model declarations (client/user-models.js): the file the
437
- // CLI's `/model-add` writes, reached here so a model the server's catalog
438
- // does not name can be added from Settings instead of by hand. `get()`
439
- // resolves `{ dir, file, map, invalid }` — `file` is shown in the UI so the
440
- // remaining escape hatch (an editor) is discoverable, and `invalid` names any
441
- // hand-edited row that was skipped. `add`/`remove` reject with the validation
442
- // message for a malformed provider or model id.
443
- userModels: {
444
- get: () => invokeModel('userModels.get'),
445
- add: (provider, model) => invokeModel('userModels.add', { provider, model }),
446
- remove: (provider, model) => invokeModel('userModels.remove', { provider, model }),
447
- // Discovery: the renderer names a provider, the MAIN process resolves the
448
- // key and asks the vendor's list API. No key crosses this bridge in either
449
- // direction — `discover` returns ids (or an error string to print) and
450
- // `addAll` returns counts, so a compromised renderer cannot read a
451
- // credential out of the discovery path.
452
- discover: (provider) => invokeModel('userModels.discover', { provider }),
453
- addAll: (provider, ids) => invokeModel('userModels.addAll', { provider, ids }),
454
- canDiscover: (provider) => invokeModel('userModels.canDiscover', { provider }),
455
- discoverable: () => invokeModel('userModels.discoverable'),
456
- },
457
- cancel: (sessionId) => invokeModel('cancel', { sessionId }),
458
- // Tool-call approval gate: the renderer's approval card calls this to
459
- // answer a pending exec/writeFile/editFile request (the approval itself
460
- // arrives as a `{ approval }` chunk on the same chat() delta stream — see
461
- // deltaListener above). clearApprovals wipes a conversation's "allow for
462
- // this session" grants; newChat() calls it so a fresh thread starts clean.
463
- respondApproval: (approvalId, decision) =>
464
- invokeModel('respondApproval', { approvalId, decision }),
465
- // Round-horizon gate: answers a pending `{ rounds }` ask raised by the engine
466
- // when a turn has used every tool round it was allowed (see app.js
467
- // renderRoundsCard, and requestRoundsAsk in lib/local/engine.js). Same shape
468
- // and same channel as respondApproval above.
469
- respondRoundsAsk: (roundsAskId, decision) =>
470
- invokeModel('respondRoundsAsk', { roundsAskId, decision }),
471
- clearApprovals: (sessionId) => invokeModel('clearApprovals', { sessionId }),
472
- };
473
-
474
- // Session sync surface (plan P1 §5.3 / P3 §7): local persistence now, cloud
475
- // push/pull later.
476
- const sync = {
477
- listSessions: () => invokeSync('listSessions'),
478
- open: (sessionId) => invokeSync('open', { sessionId }),
479
- save: (session) => invokeSync('save', session || {}),
480
- // Name a thread the way the terminal does (client/naming.js): one model
481
- // round on the session's own class/model, off the critical path. Resolves
482
- // the name, or null when it has no opinion (a greeting, an echo, or no
483
- // usable answer). `sessionId` must already exist in the store.
484
- nameSession: (payload) =>
485
- invokeSync('nameSession', {
486
- sessionId: payload && payload.sessionId,
487
- prompt: payload && payload.prompt,
488
- class: payload && payload.class,
489
- model: payload && payload.model,
490
- }),
491
- append: (sessionId, message) => invokeSync('append', { sessionId, message }),
492
- delete: (sessionId) => invokeSync('delete', { sessionId }),
493
- push: () => invokeSync('push'),
494
- pull: () => invokeSync('pull'),
495
- status: () => invokeSync('status'),
496
- // The automatic post-turn push ("persisting memory"). Gate-checked in main
497
- // against the `__memoryPersist` preference, so calling this on every turn is
498
- // cheap when persistence is off — it returns `{ skipped: true }` without
499
- // opening a request. `memoryPersistState()` reports the gate itself.
500
- auto: () => invokeSync('auto'),
501
- memoryPersistState: () => invokeSync('memoryPersistState'),
502
- };
503
-
504
- // Quick launcher surface: loaded by BOTH renderer/index.html (the settings
505
- // card that configures the global shortcut) and renderer/quick.html (the
506
- // launcher popup itself, which calls pushToMain when the user keeps an
507
- // answer) — one bridge, two consumers, same whitelist-only shape as
508
- // aegis/models/sync above.
509
- const quickLauncher = {
510
- // { enabled, shortcut, packaged, active, reason } — see main.js
511
- // createQuickLauncherDispatch. `active` reflects whether the shortcut is
512
- // actually registered right now; `reason` explains a failed registration.
513
- status: () => invokeQuick('status'),
514
- setConfig: (cfg) =>
515
- invokeQuick('setConfig', {
516
- enabled: cfg && cfg.enabled,
517
- shortcut: cfg && cfg.shortcut,
518
- }),
519
- // Called by renderer/quick.js once an answer exists; resolves
520
- // { ok, reason? }.
521
- pushToMain: (payload) => invokeQuick('pushToMain', payload || {}),
522
- };
523
-
524
- // Local autonomous work queue: the desktop half of the durable queue
525
- // (desktop/lib/local/queue.js) plus the unattended worker
526
- // (desktop/lib/local/autonomous.js), wired in main.js registerQueueIpc.
527
- //
528
- // Two things this surface deliberately does NOT have:
529
- //
530
- // 1. No shell and no free-form path passthrough. Every field is named and
531
- // coerced here, so the renderer can never smuggle an extra key (a `source`,
532
- // an `id`, a future `command`) into a queue file the CLI and the other
533
- // hosts also read. The one path-like field is `cwd` — the directory the
534
- // task's own tool loop runs in — and main.js refuses it unless it is an
535
- // absolute path that already exists; this file never joins, reads or writes
536
- // a path itself.
537
- // 2. No drain that starts by itself unless the persisted switch says so —
538
- // and in a default install it DOES say so. `drain`/`proceed` above are the
539
- // manual entry points (the queue card is hidden now; the same calls back
540
- // the `aegis autonomous` CLI path), and the timer that calls `proceed()`
541
- // with no click lives in desktop/lib/auto.js, armed from settings.js's
542
- // reserved `__autoDrain` namespace. That namespace is ON unless an
543
- // explicit `enabled: false` is written — which is exactly what
544
- // `aegis.auto.setDrain({ enabled: false })` below persists. Every tick
545
- // re-reads it, so switching it off stops the very next one. Draining
546
- // spends money on a real model in a real checkout, so the switch stays in
547
- // the settings store rather than in this file's defaults.
548
- const queue = {
549
- // Queue one task. `payload` is { task, cwd, class, model, effort, workers,
550
- // maxRounds, commit }; main.js range-checks every field and answers
551
- // { ok, item, items, pending, running, runs, … } or { ok: false, reason }.
552
- enqueue: (payload) => invokeQueue('enqueue', queueTaskFields(payload)),
553
- // Full state: { items, pending, running, draining, runs, defaultCwd, … }.
554
- list: () => invokeQueue('list'),
555
- // Drop finished tasks; `all` is the explicit "empty the queue" escape hatch.
556
- clear: (all) => invokeQueue('clear', { all: Boolean(all) }),
557
- // What this session may spend on (Phase 4): { pro, plan, maxWorkers, source,
558
- // degraded, campaign, upgradeUrl, … } from desktop/lib/local/entitlement.js,
559
- // decided in the MAIN process. The card displays this; it never computes it —
560
- // a renderer-side entitlement is cosmetic and trivially bypassed.
561
- // `force: true` re-probes the account instead of answering from the cache.
562
- entitlement: (force) => invokeQueue('entitlement', { force: Boolean(force) }),
563
- // Put a finished/failed task back in line (by id), or drop it (by id).
564
- retry: (id) => queueWithId('retry', id),
565
- remove: (id) => queueWithId('remove', id),
566
- // Work one pending task, or all of them. `stop` cancels the turn in flight
567
- // AND the loop, so the next pending task does not simply start.
568
- drain: () => invokeQueue('drain', {}),
569
- proceed: () => invokeQueue('proceed', {}),
570
- stop: (id) => {
571
- const taskId = queueTaskId(id);
572
- return invokeQueue('stop', taskId == null ? {} : { id: taskId });
573
- },
574
- // Live drain progress pushed from main over queue:progress — one event per
575
- // turn frame ({ type: 'start'|'tool'|'delta'|'reasoning'|'finish', taskId, … }).
576
- // Note the channel: a worker's output is NOT a chat answer, so it never rides
577
- // aegis:chatDelta and can never be typed into the open transcript. Returns an
578
- // unsubscribe function, same shape as onUpdateStatus above.
579
- onProgress: (onEvent) => {
580
- if (typeof onEvent !== 'function') return () => {};
581
- const listener = (_event, payload) => onEvent(payload);
582
- ipcRenderer.on(QUEUE_PROGRESS_CHANNEL, listener);
583
- return () => ipcRenderer.removeListener(QUEUE_PROGRESS_CHANNEL, listener);
584
- },
585
- };
586
-
587
- /**
588
- * The two opt-in automations (desktop/lib/auto.js via main.js
589
- * registerAutoIpc): the auto-drain timer over the queue, and the seal-on-quiet
590
- * timer over the current session.
591
- *
592
- * Same discipline as the queue surface above: every field is named and coerced
593
- * HERE, so the renderer cannot smuggle an extra key into a settings namespace
594
- * that main.js reserved (`__autoDrain` / `__autoMint`), and no path, secret or
595
- * free-form string crosses. In particular there is NO field for an AI secret:
596
- * the AI half of a sealed record is attested from `$AEGIS_AI_SECRET` in the
597
- * app's own scope (client/attest.js), so no key can be handed in from the DOM
598
- * even by a mistake in main.js.
599
- *
600
- * Both switches are ON unless the settings store says otherwise; these calls
601
- * are how a host turns one OFF. Nothing on screen has to ask first — see the
602
- * queue section's note 2 above.
603
- */
604
- const auto = {
605
- // { ok, drain: { enabled, intervalMs, armed, busy, ticks, drains, last, lastSkip }, mint: { … } }
606
- status: () => invokeAuto('autoStatus'),
607
- // Persist the drain switch and re-arm to match. `intervalMs` is clamped in
608
- // settings.js (15s–30min); the renderer sends what the user picked and does
609
- // not decide the floor.
610
- setDrain: (patch) => {
611
- const p = patch || {};
612
- const out = { enabled: Boolean(p.enabled) };
613
- if (p.intervalMs != null && Number.isFinite(Number(p.intervalMs))) {
614
- out.intervalMs = Number(p.intervalMs);
615
- }
616
- return invokeAuto('autoSetDrain', out);
617
- },
618
- // Persist the auto-seal switch. `publish` is independent of `enabled`: a
619
- // failed publish never unseals anything, so the two are separate answers.
620
- setMint: (patch) => {
621
- const p = patch || {};
622
- return invokeAuto('autoSetMint', {
623
- enabled: Boolean(p.enabled),
624
- publish: Boolean(p.publish),
625
- });
626
- },
627
- // Seal the open session now, through the same automation the timer uses — so
628
- // the pending-turn counter is reset by the same call and a session is never
629
- // sealed twice.
630
- sealNow: (publish) => invokeAuto('autoSealNow', { publish: Boolean(publish) }),
631
- };
632
-
633
- /**
634
- * Task ids are the queue file's positive integers (queue.js nextId). A retry or
635
- * a remove with anything else is answered locally instead of being sent as a
636
- * string that would find no task and read as "no task #NaN" in the UI.
637
- */
638
- function queueTaskId(id) {
639
- const n = Number(id);
640
- return Number.isInteger(n) && n > 0 ? n : null;
641
- }
642
-
643
- function queueWithId(name, id) {
644
- const taskId = queueTaskId(id);
645
- if (taskId == null) {
646
- return Promise.resolve({ ok: false, reason: `${name} needs a task id` });
647
- }
648
- return invokeQueue(name, { id: taskId });
649
- }
650
-
651
- /** Pick the enqueue fields explicitly (never the raw payload) and coerce them to
652
- * the types main.js range-checks, exactly like byokSet/setConfirmMode above. */
653
- function queueTaskFields(payload) {
654
- const p = payload || {};
655
- return {
656
- task: String(p.task == null ? '' : p.task),
657
- cwd: String(p.cwd == null ? '' : p.cwd),
658
- // 'aegis' | 'byok' | 'local' — same three classes the main composer uses
659
- // (window.models.listClasses()). main.js defaults a blank/missing value to
660
- // 'aegis' (autonomous.normalizeClass), so an older renderer build that
661
- // never sends this field keeps behaving exactly as it did before.
662
- class: p.class == null ? null : String(p.class),
663
- model: p.model == null ? null : String(p.model),
664
- effort: p.effort == null ? null : String(p.effort),
665
- workers: p.workers == null ? null : Number(p.workers),
666
- maxRounds: p.maxRounds == null ? null : Number(p.maxRounds),
667
- // The fan-out request travels as a boolean and nothing else: main.js decides
668
- // whether this session may have it (Phase 4 gate), so a renderer that sends
669
- // `fanout: true` while free is REFUSED there rather than quietly honoured —
670
- // see desktop/lib/local/entitlement.js gateFanout().
671
- fanout: Boolean(p.fanout),
672
- commit: Boolean(p.commit),
673
- };
674
- }
675
-
676
- contextBridge.exposeInMainWorld('aegis', Object.freeze(api));
677
- contextBridge.exposeInMainWorld('models', Object.freeze(models));
678
- contextBridge.exposeInMainWorld('sync', Object.freeze(sync));
679
- contextBridge.exposeInMainWorld('quickLauncher', Object.freeze(quickLauncher));
680
- contextBridge.exposeInMainWorld('queue', Object.freeze(queue));
681
- contextBridge.exposeInMainWorld('auto', Object.freeze(auto));
3
+ "use strict";const{contextBridge:contextBridge,ipcRenderer:ipcRenderer}=require("electron"),IPC_PREFIX="aegis:",MODEL_PREFIX="model:",SYNC_PREFIX="sync:",QUICK_PREFIX="quick:",QUEUE_PREFIX="queue:",AUTO_PREFIX="auto:",QUEUE_PROGRESS_CHANNEL=`${QUEUE_PREFIX}progress`,CHAT_DELTA_CHANNEL="aegis:chatDelta",UPDATE_STATUS_CHANNEL="aegis:updateStatus",ACCOUNT_STATUS_CHANNEL="aegis:accountStatusChanged",MENU_NEW_CHAT_CHANNEL="aegis:menuNewChat",MENU_SEARCH_CHANNEL="aegis:menuSearch",MENU_EXPORT_MARKDOWN_CHANNEL="aegis:menuExportMarkdown",MENU_EXPORT_JSON_CHANNEL="aegis:menuExportJson",MENU_FINGERPRINT_CHANNEL="aegis:menuFingerprint",MENU_GOOGLE_DRIVE_CHANNEL="aegis:menuGoogleDrive",DEEP_LINK_CHANNEL="aegis:deepLink",QUICK_LAUNCHER_PUSH_CHANNEL="aegis:quickLauncherPush";function invoke(e,n){return ipcRenderer.invoke("aegis:"+e,void 0===n?void 0:n)}function invokeModel(e,n){return ipcRenderer.invoke("model:"+e,void 0===n?void 0:n)}function invokeSync(e,n){return ipcRenderer.invoke("sync:"+e,void 0===n?void 0:n)}function invokeQuick(e,n){return ipcRenderer.invoke("quick:"+e,void 0===n?void 0:n)}function invokeQueue(e,n){return ipcRenderer.invoke(QUEUE_PREFIX+e,void 0===n?void 0:n)}function invokeAuto(e,n){return ipcRenderer.invoke("auto:"+e,void 0===n?void 0:n)}function deltaListener(e,n){const o=e||null;return(e,i)=>{(i&&i.id?i.id:null)===o&&n(i)}}const api={status:()=>invoke("status"),attachments:Object.freeze({pathFor:e=>{try{const{webUtils:n}=require("electron");return n&&"function"==typeof n.getPathForFile&&n.getPathForFile(e)||""}catch{return""}},ingest:e=>invoke("attachments:ingest",{path:String(null==e?"":e)})}),setApiKey:e=>invoke("setApiKey",{key:e}),verifyApiKey:()=>invoke("verifyApiKey"),tokenBankBalance:()=>invoke("tokenBankBalance"),billingCheckout:()=>invoke("billingCheckout"),tokenBankTopup:e=>invoke("tokenBankTopup",{amountEur:e}),listModels:()=>invoke("listModels"),readTextFile:(e,n)=>{try{return ipcRenderer.sendSync("model:readTextFile",{file:e,cwd:n})}catch{return null}},chatCompletion:(e,n)=>{const o=e||{};if("function"!=typeof n)return invoke("chatCompletion",{...o,stream:!1});const i=deltaListener(o.sessionId,n),t=()=>ipcRenderer.removeListener("aegis:chatDelta",i);return ipcRenderer.on("aegis:chatDelta",i),invoke("chatCompletion",{...o,stream:!0}).then((e=>(t(),e)),(e=>{throw t(),e}))},byokStatus:()=>invoke("byokStatus"),byokSet:(e,n)=>invoke("byokSet",{provider:e,apiKey:n}),memorySearch:(e,n)=>invoke("memorySearch",{query:e,limit:n}),memorySave:e=>invoke("memorySave",{entry:e}),memoryList:e=>invoke("memoryList",{limit:e}),verifyToken:e=>invoke("verifyToken",{token:e}),memoryActivate:e=>invoke("memoryActivate",{token:e}),memoryPull:e=>invoke("memoryPull",{since:e}),memorySaveBatch:e=>invoke("memorySaveBatch",{entries:e}),memoryImport:e=>invoke("memoryImport",e||{}),importConversation:e=>invoke("importConversation",e||{}),openExternal:e=>invoke("openExternal",{url:e}),fingerprintStatus:()=>invoke("fingerprintStatus"),fingerprintKeygen:e=>invoke("fingerprintKeygen",e||{}),fingerprintMint:e=>invoke("fingerprintMint",e||{}),fingerprintVerify:e=>invoke("fingerprintVerify",e||{}),fingerprintBackup:e=>invoke("fingerprintBackup",e||{}),fingerprintPublish:e=>invoke("fingerprintPublish",e||{}),fingerprintAnchor:e=>invoke("fingerprintAnchor",e||{}),fingerprintVault:()=>invoke("fingerprintVault"),fingerprintVaultAudit:()=>invoke("fingerprintVaultAudit"),getConfirmMode:()=>invoke("getConfirmMode"),setConfirmMode:e=>invoke("setConfirmMode",{enabled:Boolean(e)}),getVaultBackend:()=>invoke("getVaultBackend"),setVaultBackend:e=>invoke("setVaultBackend",{backend:String(e||"")}),telemetryEvent:(e,n)=>{const o=n||{};return invoke("telemetryEvent",{event:null==e?"":String(e),campaign:null==o.campaign?null:String(o.campaign),surface:null==o.surface?null:String(o.surface)})},telemetryReport:()=>invoke("telemetryReport"),covenantStatus:()=>invoke("covenantStatus"),covenantGapReport:()=>invoke("covenantGapReport"),getMemoryPersist:()=>invoke("memoryPersist.get"),setMemoryPersist:e=>invoke("memoryPersist.set",{enabled:Boolean(e)}),checkForUpdates:()=>invoke("checkForUpdates"),downloadUpdate:()=>invoke("downloadUpdate"),quitAndInstallUpdate:()=>invoke("quitAndInstallUpdate"),updateStatus:()=>invoke("updateStatus"),onUpdateStatus:e=>{const n=(n,o)=>e(o);return ipcRenderer.on("aegis:updateStatus",n),()=>ipcRenderer.removeListener("aegis:updateStatus",n)},accountStatus:()=>invoke("accountStatus"),registerAccount:()=>invoke("registerAccount"),onAccountStatus:e=>{const n=(n,o)=>e(o);return ipcRenderer.on(ACCOUNT_STATUS_CHANNEL,n),()=>ipcRenderer.removeListener(ACCOUNT_STATUS_CHANNEL,n)},driveSignIn:()=>invoke("driveSignIn"),driveConnect:()=>invoke("driveConnect"),driveStatus:()=>invoke("driveStatus"),driveSyncMemory:()=>invoke("driveSyncMemory"),driveBackupConversation:e=>invoke("driveBackupConversation",{sessionId:e}),onMenuNewChat:e=>{const n=()=>e();return ipcRenderer.on("aegis:menuNewChat",n),()=>ipcRenderer.removeListener("aegis:menuNewChat",n)},onMenuSearch:e=>{const n=()=>e();return ipcRenderer.on("aegis:menuSearch",n),()=>ipcRenderer.removeListener("aegis:menuSearch",n)},onMenuExportMarkdown:e=>{const n=()=>e();return ipcRenderer.on("aegis:menuExportMarkdown",n),()=>ipcRenderer.removeListener("aegis:menuExportMarkdown",n)},onMenuFingerprint:e=>{const n=()=>e();return ipcRenderer.on("aegis:menuFingerprint",n),()=>ipcRenderer.removeListener("aegis:menuFingerprint",n)},onMenuGoogleDrive:e=>{const n=()=>e();return ipcRenderer.on("aegis:menuGoogleDrive",n),()=>ipcRenderer.removeListener("aegis:menuGoogleDrive",n)},onMenuExportJson:e=>{const n=()=>e();return ipcRenderer.on("aegis:menuExportJson",n),()=>ipcRenderer.removeListener("aegis:menuExportJson",n)},exportSession:(e,n)=>invoke("exportSession",{sessionId:e,format:n}),onDeepLink:e=>{const n=(n,o)=>e(o);return ipcRenderer.on("aegis:deepLink",n),()=>ipcRenderer.removeListener("aegis:deepLink",n)},onQuickLauncherPush:e=>{const n=(n,o)=>e(o);return ipcRenderer.on("aegis:quickLauncherPush",n),()=>ipcRenderer.removeListener("aegis:quickLauncherPush",n)}},models={listClasses:()=>invokeModel("listClasses"),listModels:e=>invokeModel("listModels",{class:e}),chat:(e,n)=>{const o=e||{};if("function"!=typeof n)return invokeModel("chat",o);const i=deltaListener(o.sessionId,n),t=()=>ipcRenderer.removeListener("aegis:chatDelta",i);return ipcRenderer.on("aegis:chatDelta",i),invokeModel("chat",o).then((e=>(t(),e)),(e=>{throw t(),e}))},settings:{get:()=>invokeModel("settings.get"),set:(e,n)=>invokeModel("settings.set",{provider:e,baseURL:n&&n.baseURL,key:n&&n.key}),remove:e=>invokeModel("settings.remove",{provider:e})},userModels:{get:()=>invokeModel("userModels.get"),add:(e,n)=>invokeModel("userModels.add",{provider:e,model:n}),remove:(e,n)=>invokeModel("userModels.remove",{provider:e,model:n}),discover:e=>invokeModel("userModels.discover",{provider:e}),addAll:(e,n)=>invokeModel("userModels.addAll",{provider:e,ids:n}),canDiscover:e=>invokeModel("userModels.canDiscover",{provider:e}),discoverable:()=>invokeModel("userModels.discoverable")},cancel:e=>invokeModel("cancel",{sessionId:e}),respondApproval:(e,n)=>invokeModel("respondApproval",{approvalId:e,decision:n}),respondRoundsAsk:(e,n)=>invokeModel("respondRoundsAsk",{roundsAskId:e,decision:n}),clearApprovals:e=>invokeModel("clearApprovals",{sessionId:e})},sync={listSessions:()=>invokeSync("listSessions"),open:e=>invokeSync("open",{sessionId:e}),save:e=>invokeSync("save",e||{}),nameSession:e=>invokeSync("nameSession",{sessionId:e&&e.sessionId,prompt:e&&e.prompt,class:e&&e.class,model:e&&e.model}),append:(e,n)=>invokeSync("append",{sessionId:e,message:n}),delete:e=>invokeSync("delete",{sessionId:e}),push:()=>invokeSync("push"),pull:()=>invokeSync("pull"),status:()=>invokeSync("status"),auto:()=>invokeSync("auto"),memoryPersistState:()=>invokeSync("memoryPersistState")},quickLauncher={status:()=>invokeQuick("status"),setConfig:e=>invokeQuick("setConfig",{enabled:e&&e.enabled,shortcut:e&&e.shortcut}),pushToMain:e=>invokeQuick("pushToMain",e||{})},queue={enqueue:e=>invokeQueue("enqueue",queueTaskFields(e)),list:()=>invokeQueue("list"),clear:e=>invokeQueue("clear",{all:Boolean(e)}),entitlement:e=>invokeQueue("entitlement",{force:Boolean(e)}),retry:e=>queueWithId("retry",e),remove:e=>queueWithId("remove",e),drain:()=>invokeQueue("drain",{}),proceed:()=>invokeQueue("proceed",{}),stop:e=>{const n=queueTaskId(e);return invokeQueue("stop",null==n?{}:{id:n})},onProgress:e=>{if("function"!=typeof e)return()=>{};const n=(n,o)=>e(o);return ipcRenderer.on(QUEUE_PROGRESS_CHANNEL,n),()=>ipcRenderer.removeListener(QUEUE_PROGRESS_CHANNEL,n)}},auto={status:()=>invokeAuto("autoStatus"),setDrain:e=>{const n=e||{},o={enabled:Boolean(n.enabled)};return null!=n.intervalMs&&Number.isFinite(Number(n.intervalMs))&&(o.intervalMs=Number(n.intervalMs)),invokeAuto("autoSetDrain",o)},setMint:e=>{const n=e||{};return invokeAuto("autoSetMint",{enabled:Boolean(n.enabled),publish:Boolean(n.publish)})},sealNow:e=>invokeAuto("autoSealNow",{publish:Boolean(e)})};function queueTaskId(e){const n=Number(e);return Number.isInteger(n)&&n>0?n:null}function queueWithId(e,n){const o=queueTaskId(n);return null==o?Promise.resolve({ok:!1,reason:`${e} needs a task id`}):invokeQueue(e,{id:o})}function queueTaskFields(e){const n=e||{};return{task:String(null==n.task?"":n.task),cwd:String(null==n.cwd?"":n.cwd),class:null==n.class?null:String(n.class),model:null==n.model?null:String(n.model),effort:null==n.effort?null:String(n.effort),workers:null==n.workers?null:Number(n.workers),maxRounds:null==n.maxRounds?null:Number(n.maxRounds),fanout:Boolean(n.fanout),commit:Boolean(n.commit)}}contextBridge.exposeInMainWorld("aegis",Object.freeze(api)),contextBridge.exposeInMainWorld("models",Object.freeze(models)),contextBridge.exposeInMainWorld("sync",Object.freeze(sync)),contextBridge.exposeInMainWorld("quickLauncher",Object.freeze(quickLauncher)),contextBridge.exposeInMainWorld("queue",Object.freeze(queue)),contextBridge.exposeInMainWorld("auto",Object.freeze(auto));