aegis-desktop 1.0.13 → 1.0.15

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