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,351 +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
- * `aegiscode connect` — this machine, signed in, in one step.
10
- *
11
- * ## Why this exists next to `login`
12
- *
13
- * `login` saves a key the user already has. That is the right command for
14
- * someone who has been to the dashboard, and the wrong one for a fresh
15
- * install: at that point there is no key to paste, so the first thing the user
16
- * meets is a prompt for something they cannot produce yet, and every cloud
17
- * feature (memory sync, conversation sync, the record vault) answers "no key"
18
- * until they work out where one comes from.
19
- *
20
- * `connect` is the other door. **By default it signs in with Google**
21
- * (`client/google-signin.js`, driving aegis1's existing `/auth/google`
22
- * desktop round-trip): a browser opens, and the key this machine saves is
23
- * tied to that real identity rather than to the machine itself — the same
24
- * account comes back on a second machine signed in with the same Google
25
- * account, which an anonymous per-machine key can never do.
26
- *
27
- * `--anonymous` (or `--device`) keeps the original door for anyone who wants
28
- * no Google identity involved at all: `POST /api/v1/auth/register-device`
29
- * (client/aegis.js's `registerDevice`, driven by client/auto-provision.js's
30
- * `autoProvisionApiKey`). That call is idempotent per machine fingerprint, so:
31
- *
32
- * - on a NEW machine it mints the account (and aegis1's one-time welcome
33
- * trial), saves the key, and the vault/memory now work;
34
- * - on a machine that has registered before it returns the SAME account
35
- * rather than a second, unfunded one, which is why this command is safe to
36
- * re-run after a wiped credential store.
37
- *
38
- * Both outcomes are reported in the caller's own words — `trialOutcomeNote`
39
- * from the shared module, so this cannot describe a reused machine as a clean
40
- * install (the exact bug that clause exists for).
41
- *
42
- * ## Not a second credential
43
- *
44
- * There is no token of its own here. What it writes is the ordinary saved key
45
- * in client/credentials.js, so `login`, `/key`, the desktop's Settings pane and
46
- * every other host read the same one afterwards. A "connect" that invented its
47
- * own store would be a second thing to go stale.
48
- *
49
- * ## `--status`
50
- *
51
- * The question a script and a first-run prompt both need answered without a
52
- * side effect. Exit 0 when connected, 1 when not, 2 when it could not be
53
- * established at all (no network, server refused) — the same 0/1/2 contract
54
- * `fingerprint` uses, and for the same reason: "not connected" and "could not
55
- * ask" are different events.
56
- */
57
-
58
- const { resolveClientModule } = require('./shared.js');
59
- const { maskKey } = require('./format.js');
60
- const { openUrl: defaultOpenUrl } = require('./system.js');
61
-
62
- function load() {
63
- return {
64
- credentials: require(resolveClientModule('credentials.js')),
65
- autoProvision: require(resolveClientModule('auto-provision.js')),
66
- client: require(resolveClientModule('aegis.js')),
67
- vault: require(resolveClientModule('record-vault.js')),
68
- googleSignIn: require(resolveClientModule('google-signin.js')),
69
- };
70
- }
71
-
72
- const HELP = `aegiscode connect — sign this machine in (and register it, if it is new).
73
-
74
- Usage:
75
- aegiscode connect sign in with Google (default) — opens a
76
- browser; the key this machine saves is
77
- tied to that account, so the same account
78
- comes back on any machine signed in with it
79
- aegiscode connect --anonymous sign in with an anonymous per-machine key
80
- instead (no Google identity involved);
81
- registers this device if it has no account
82
- yet (one request, idempotent per machine —
83
- a machine that registered before gets the
84
- same account back)
85
- aegiscode connect --status is this machine connected? (--json; exit 1
86
- when it is not)
87
- aegiscode connect --logout forget the saved key on this machine
88
- aegiscode connect --help
89
-
90
- What it gives you, with no further setup:
91
- cloud memory sync, conversation sync, and the DEFAULT RECORD VAULT
92
- (aegiscode fingerprint publish goes to your account vault).
93
-
94
- It writes the same key \`aegiscode login\` writes, so a key you already saved is
95
- used as-is: this never replaces a working credential.
96
-
97
- Options:
98
- --status report only; changes nothing
99
- --anonymous, --device sign in with the anonymous per-machine key, not Google
100
- --google sign in with Google (the default — accepted explicitly too)
101
- --logout remove the saved key from this machine
102
- --json machine-readable output
103
- --app NAME the host name sent to the server (default: cli)
104
- --base URL API base (same as $AEGIS_API_BASE)`;
105
-
106
- /** `--flag value`, tolerating `--flag=value`. */
107
- function flag(argv, name) {
108
- for (let i = 0; i < argv.length; i += 1) {
109
- const a = String(argv[i]);
110
- if (a === name && argv[i + 1] !== undefined && !String(argv[i + 1]).startsWith('--')) return argv[i + 1];
111
- if (a.startsWith(`${name}=`)) return a.slice(name.length + 1);
112
- }
113
- return null;
114
- }
115
-
116
- function has(argv, name) {
117
- return (Array.isArray(argv) ? argv : []).some((a) => a === name || String(a).startsWith(`${name}=`));
118
- }
119
-
120
- /**
121
- * The credential store, scoped to the environment this run was given.
122
- *
123
- * `credentials` resolves its directory from `AEGISCODE_HOME`, and an injected
124
- * env is the whole reason this module takes one (the tests, a hosted agent, a
125
- * `--base` against a staging account). Calling the store without the dir left
126
- * every one of those reading the ambient `~/.aegiscode` instead — so a run
127
- * meant for a scratch home reported the real user's account as "already
128
- * connected" and skipped the registration it was asked for. Two variables, and
129
- * both are needed: AEGIS_HOME holds the φ(α) keys, AEGISCODE_HOME the account
130
- * key.
131
- */
132
- function storeFor(credentials, env) {
133
- const dir = credentials.aegisHome(env);
134
- return {
135
- dir,
136
- keyStatus: () => credentials.keyStatus({ env, dir }),
137
- clearApiKey: () => credentials.clearApiKey(dir),
138
- // autoProvisionApiKey calls exactly this one method on the store object.
139
- saveApiKey: (key) => credentials.saveApiKey(key, dir),
140
- };
141
- }
142
-
143
- /** The four fields a caller can act on, and nothing derived from the key. */
144
- function report(credentials, vault, env) {
145
- const st = credentials.keyStatus({ env, dir: credentials.aegisHome(env) });
146
- let backend = null;
147
- try {
148
- backend = vault.vaultTarget(env, []).backend;
149
- } catch {
150
- backend = null;
151
- }
152
- return {
153
- connected: Boolean(st.configured),
154
- source: st.source || 'none',
155
- path: st.path || null,
156
- file_mode: st.fileMode || null,
157
- // Only meaningful WITH a key: a memory token without an account key is a
158
- // leftover in the env, and reporting "cloud sync ready" beside
159
- // "connected: no" is the sort of contradiction that makes a status report
160
- // untrustworthy.
161
- memory_token: Boolean(st.configured && st.memoryToken),
162
- vault_backend: backend,
163
- // Never the key: this output is the one a user pastes into a bug report.
164
- masked: st.configured ? maskKey(st.key) : null,
165
- };
166
- }
167
-
168
- /**
169
- * Run one subcommand. Returns the process exit code; never throws.
170
- *
171
- * @param {string[]} argv flags after `connect`
172
- * @param {{stdout?:object, stderr?:object, env?:object, json?:boolean, fetch?:Function}} io
173
- */
174
- async function runConnect(argv = [], io = {}) {
175
- const out = {
176
- stdout: process.stdout,
177
- stderr: process.stderr,
178
- env: process.env,
179
- json: false,
180
- ...io,
181
- json: Boolean(io.json) || has(argv, '--json'),
182
- };
183
- const fail = (code, message) => {
184
- if (out.json) out.stdout.write(JSON.stringify({ connected: false, error: message }, null, 2) + '\n');
185
- else out.stderr.write(`aegiscode: ${message}\n`);
186
- return code;
187
- };
188
-
189
- try {
190
- if (has(argv, '--help') || has(argv, '-h')) {
191
- out.stdout.write(HELP + '\n');
192
- return 0;
193
- }
194
-
195
- const { credentials, autoProvision, client, vault, googleSignIn } = load();
196
- const base = flag(argv, '--base');
197
- if (base) out.env.AEGIS_API_BASE = base;
198
-
199
- const store = storeFor(credentials, out.env);
200
-
201
- if (has(argv, '--logout')) {
202
- const res = store.clearApiKey();
203
- if (out.json) out.stdout.write(JSON.stringify({ connected: false, cleared: res.cleared }, null, 2) + '\n');
204
- else {
205
- out.stdout.write(
206
- res.cleared
207
- ? `aegiscode: key removed from ${res.path} — this machine is signed out\n`
208
- : 'aegiscode: this machine had no saved key\n',
209
- );
210
- }
211
- return 0;
212
- }
213
-
214
- if (has(argv, '--status')) {
215
- const r = report(credentials, vault, out.env);
216
- if (out.json) out.stdout.write(JSON.stringify(r, null, 2) + '\n');
217
- else {
218
- out.stdout.write(
219
- [
220
- `connected: ${r.connected ? 'yes' : 'no'}`,
221
- `key: ${r.masked || 'not set'}${r.file_mode ? ` (${r.file_mode})` : ''}`,
222
- `source: ${r.source}`,
223
- `file: ${r.path || '-'}`,
224
- `memory: ${r.memory_token ? 'token held (cloud sync ready)' : 'no token yet'}`,
225
- `vault: ${r.vault_backend || 'unknown'} (record publishing)`,
226
- r.connected ? '' : 'Sign in with: aegiscode connect',
227
- ]
228
- .filter((l) => l !== '')
229
- .join('\n') + '\n',
230
- );
231
- }
232
- return r.connected ? 0 : 1;
233
- }
234
-
235
- // Already connected: say so and stop. Re-registering to "make sure" would
236
- // spend the server's per-IP registration budget for no gain, and this
237
- // command must be safe to run twice.
238
- const before = report(credentials, vault, out.env);
239
- if (before.connected) {
240
- if (out.json) out.stdout.write(JSON.stringify({ ...before, already: true }, null, 2) + '\n');
241
- else {
242
- out.stdout.write(
243
- [
244
- `already connected — ${before.masked} (${before.source})`,
245
- `vault: ${before.vault_backend}`,
246
- '',
247
- 'Nothing changed. Sign out first (`aegiscode connect --logout`) to switch accounts.',
248
- ].join('\n') + '\n',
249
- );
250
- }
251
- return 0;
252
- }
253
-
254
- if (!has(argv, '--anonymous') && !has(argv, '--device')) {
255
- const aegisForBase = client.createClient(credentials.clientOptions({ channel: 'cli', env: out.env, dir: store.dir }));
256
- let session;
257
- try {
258
- session = await googleSignIn.startGoogleSignIn({ apiBase: aegisForBase.apiBase });
259
- } catch (e) {
260
- return fail(2, `could not start the local sign-in server — ${(e && e.message) || e}`);
261
- }
262
-
263
- if (!out.json) out.stdout.write(`aegiscode: opening a browser to sign in with Google…\n`);
264
- const opener = io.openUrl || defaultOpenUrl;
265
- if (!opener(session.url) && !out.json) {
266
- out.stdout.write(`aegiscode: could not open a browser automatically — open this URL:\n ${session.url}\n`);
267
- }
268
-
269
- let googleResult;
270
- try {
271
- googleResult = await session.wait();
272
- } catch (e) {
273
- return fail(2, `google sign-in did not complete — ${(e && e.message) || e}`);
274
- }
275
-
276
- const saved = store.saveApiKey(googleResult.apiKey);
277
- if (!saved.ok) {
278
- return fail(2, saved.message || `could not save the key to ${saved.path}`);
279
- }
280
- if (googleResult.memoryToken) credentials.saveMemoryToken(googleResult.memoryToken, {}, store.dir);
281
-
282
- const afterGoogle = report(credentials, vault, out.env);
283
- if (out.json) {
284
- out.stdout.write(
285
- JSON.stringify({ ...afterGoogle, registered: true, provider: 'google', username: googleResult.username }, null, 2) + '\n',
286
- );
287
- return 0;
288
- }
289
- out.stdout.write(
290
- [
291
- `connected — ${afterGoogle.masked}${googleResult.username ? ` (signed in as ${googleResult.username})` : ''}`,
292
- `key saved to ${afterGoogle.path}`,
293
- `vault ${afterGoogle.vault_backend} — \`aegiscode fingerprint publish\` lands here`,
294
- afterGoogle.memory_token ? 'Cloud memory sync is ready on this account.' : 'Cloud sync takes a moment to provision; the key is already valid.',
295
- ].join('\n') + '\n',
296
- );
297
- return 0;
298
- }
299
-
300
- // --anonymous (or --device): the original door, kept for a user who wants
301
- // no Google identity involved at all. The registration itself: the shared
302
- // helper every host uses, so the account this mints is the one the
303
- // desktop and the MCP plugin will find.
304
- const aegis = client.createClient(credentials.clientOptions({ channel: 'cli', env: out.env, dir: store.dir }));
305
- const result = await autoProvision.autoProvisionApiKey(aegis, store, {
306
- app: flag(argv, '--app') || 'cli',
307
- });
308
-
309
- if (!result.key) {
310
- return fail(2, `could not register this device — ${autoProvision.provisionFailureText(result)}`);
311
- }
312
-
313
- const after = report(credentials, vault, out.env);
314
- const note = autoProvision.trialOutcomeNote(result);
315
- if (out.json) {
316
- out.stdout.write(
317
- JSON.stringify(
318
- {
319
- ...after,
320
- registered: true,
321
- trial_granted: result.trialGranted,
322
- reused_account: Boolean(result.reusedAccount),
323
- saved: Boolean(result.ok),
324
- },
325
- null,
326
- 2,
327
- ) + '\n',
328
- );
329
- return result.ok ? 0 : 2;
330
- }
331
-
332
- out.stdout.write(
333
- [
334
- `${result.reusedAccount ? 'welcome back' : 'connected'} — ${after.masked}`,
335
- `registered this machine${note}`,
336
- `key ${result.ok ? `saved to ${after.path}` : 'COULD NOT SAVE — re-run `aegiscode connect`'}`,
337
- `vault ${after.vault_backend} — \`aegiscode fingerprint publish\` lands here`,
338
- '',
339
- after.memory_token ? 'Cloud memory sync is ready on this account.' : 'Cloud sync takes a moment to provision; the key is already valid.',
340
- result.reusedAccount ? '' : `Fund or inspect the account: ${aegis.promptUrl('topup', 'welcome_cloud')}`,
341
- ]
342
- .filter(Boolean)
343
- .join('\n') + '\n',
344
- );
345
- return result.ok ? 0 : 2;
346
- } catch (e) {
347
- return fail(2, (e && e.message) || String(e));
348
- }
349
- }
350
-
351
- module.exports = { runConnect, HELP, report };
3
+ "use strict";const{resolveClientModule:resolveClientModule}=require("./shared.js"),{maskKey:maskKey}=require("./format.js"),{openUrl:defaultOpenUrl}=require("./system.js");function load(){return{credentials:require(resolveClientModule("credentials.js")),autoProvision:require(resolveClientModule("auto-provision.js")),client:require(resolveClientModule("aegis.js")),vault:require(resolveClientModule("record-vault.js")),googleSignIn:require(resolveClientModule("google-signin.js"))}}const HELP="aegiscode connect — sign this machine in (and register it, if it is new).\n\nUsage:\n aegiscode connect sign in with Google (default) — opens a\n browser; the key this machine saves is\n tied to that account, so the same account\n comes back on any machine signed in with it\n aegiscode connect --anonymous sign in with an anonymous per-machine key\n instead (no Google identity involved);\n registers this device if it has no account\n yet (one request, idempotent per machine —\n a machine that registered before gets the\n same account back)\n aegiscode connect --status is this machine connected? (--json; exit 1\n when it is not)\n aegiscode connect --logout forget the saved key on this machine\n aegiscode connect --help\n\nWhat it gives you, with no further setup:\n cloud memory sync, conversation sync, and the DEFAULT RECORD VAULT\n (aegiscode fingerprint publish goes to your account vault).\n\nIt writes the same key `aegiscode login` writes, so a key you already saved is\nused as-is: this never replaces a working credential.\n\nOptions:\n --status report only; changes nothing\n --anonymous, --device sign in with the anonymous per-machine key, not Google\n --google sign in with Google (the default — accepted explicitly too)\n --logout remove the saved key from this machine\n --json machine-readable output\n --app NAME the host name sent to the server (default: cli)\n --base URL API base (same as $AEGIS_API_BASE)";function flag(e,n){for(let t=0;t<e.length;t+=1){const o=String(e[t]);if(o===n&&void 0!==e[t+1]&&!String(e[t+1]).startsWith("--"))return e[t+1];if(o.startsWith(`${n}=`))return o.slice(n.length+1)}return null}function has(e,n){return(Array.isArray(e)?e:[]).some((e=>e===n||String(e).startsWith(`${n}=`)))}function storeFor(e,n){const t=e.aegisHome(n);return{dir:t,keyStatus:()=>e.keyStatus({env:n,dir:t}),clearApiKey:()=>e.clearApiKey(t),saveApiKey:n=>e.saveApiKey(n,t)}}function report(e,n,t){const o=e.keyStatus({env:t,dir:e.aegisHome(t)});let s=null;try{s=n.vaultTarget(t,[]).backend}catch{s=null}return{connected:Boolean(o.configured),source:o.source||"none",path:o.path||null,file_mode:o.fileMode||null,memory_token:Boolean(o.configured&&o.memoryToken),vault_backend:s,masked:o.configured?maskKey(o.key):null}}async function runConnect(e=[],n={}){const t={stdout:process.stdout,stderr:process.stderr,env:process.env,json:!1,...n,json:Boolean(n.json)||has(e,"--json")},o=(e,n)=>(t.json?t.stdout.write(JSON.stringify({connected:!1,error:n},null,2)+"\n"):t.stderr.write(`aegiscode: ${n}\n`),e);try{if(has(e,"--help")||has(e,"-h"))return t.stdout.write(HELP+"\n"),0;const{credentials:s,autoProvision:i,client:r,vault:a,googleSignIn:c}=load(),l=flag(e,"--base");l&&(t.env.AEGIS_API_BASE=l);const u=storeFor(s,t.env);if(has(e,"--logout")){const e=u.clearApiKey();return t.json?t.stdout.write(JSON.stringify({connected:!1,cleared:e.cleared},null,2)+"\n"):t.stdout.write(e.cleared?`aegiscode: key removed from ${e.path} — this machine is signed out\n`:"aegiscode: this machine had no saved key\n"),0}if(has(e,"--status")){const e=report(s,a,t.env);return t.json?t.stdout.write(JSON.stringify(e,null,2)+"\n"):t.stdout.write(["connected: "+(e.connected?"yes":"no"),`key: ${e.masked||"not set"}${e.file_mode?` (${e.file_mode})`:""}`,`source: ${e.source}`,`file: ${e.path||"-"}`,"memory: "+(e.memory_token?"token held (cloud sync ready)":"no token yet"),`vault: ${e.vault_backend||"unknown"} (record publishing)`,e.connected?"":"Sign in with: aegiscode connect"].filter((e=>""!==e)).join("\n")+"\n"),e.connected?0:1}const d=report(s,a,t.env);if(d.connected)return t.json?t.stdout.write(JSON.stringify({...d,already:!0},null,2)+"\n"):t.stdout.write([`already connected — ${d.masked} (${d.source})`,`vault: ${d.vault_backend}`,"","Nothing changed. Sign out first (`aegiscode connect --logout`) to switch accounts."].join("\n")+"\n"),0;if(!has(e,"--anonymous")&&!has(e,"--device")){const i=r.createClient(s.clientOptions({channel:"cli",env:t.env,dir:u.dir}));let l,d;try{l=await c.startGoogleSignIn({apiBase:i.apiBase})}catch(e){return o(2,`could not start the local sign-in server — ${e&&e.message||e}`)}t.json||t.stdout.write("aegiscode: opening a browser to sign in with Google…\n"),(n.openUrl||defaultOpenUrl)(l.url)||t.json||t.stdout.write(`aegiscode: could not open a browser automatically — open this URL:\n ${l.url}\n`);try{d=await l.wait()}catch(e){return o(2,`google sign-in did not complete — ${e&&e.message||e}`)}const g=u.saveApiKey(d.apiKey);if(!g.ok)return o(2,g.message||`could not save the key to ${g.path}`);d.memoryToken&&s.saveMemoryToken(d.memoryToken,{},u.dir);const h=report(s,a,t.env);return t.json?(t.stdout.write(JSON.stringify({...h,registered:!0,provider:"google",username:d.username},null,2)+"\n"),0):(t.stdout.write([`connected — ${h.masked}${d.username?` (signed in as ${d.username})`:""}`,`key saved to ${h.path}`,`vault ${h.vault_backend} — \`aegiscode fingerprint publish\` lands here`,h.memory_token?"Cloud memory sync is ready on this account.":"Cloud sync takes a moment to provision; the key is already valid."].join("\n")+"\n"),0)}const g=r.createClient(s.clientOptions({channel:"cli",env:t.env,dir:u.dir})),h=await i.autoProvisionApiKey(g,u,{app:flag(e,"--app")||"cli"});if(!h.key)return o(2,`could not register this device — ${i.provisionFailureText(h)}`);const m=report(s,a,t.env),y=i.trialOutcomeNote(h);return t.json?(t.stdout.write(JSON.stringify({...m,registered:!0,trial_granted:h.trialGranted,reused_account:Boolean(h.reusedAccount),saved:Boolean(h.ok)},null,2)+"\n"),h.ok?0:2):(t.stdout.write([`${h.reusedAccount?"welcome back":"connected"} — ${m.masked}`,`registered this machine${y}`,"key "+(h.ok?`saved to ${m.path}`:"COULD NOT SAVE — re-run `aegiscode connect`"),`vault ${m.vault_backend} — \`aegiscode fingerprint publish\` lands here`,"",m.memory_token?"Cloud memory sync is ready on this account.":"Cloud sync takes a moment to provision; the key is already valid.",h.reusedAccount?"":`Fund or inspect the account: ${g.promptUrl("topup","welcome_cloud")}`].filter(Boolean).join("\n")+"\n"),h.ok?0:2)}catch(e){return o(2,e&&e.message||String(e))}}module.exports={runConnect:runConnect,HELP:HELP,report:report};
@@ -1,35 +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
- * The AEGIS account credential store for the terminal host.
10
- *
11
- * The implementation moved to `client/credentials.js` — the tree every host in
12
- * this repo already bundles — because the desktop app and the MCP plugin read
13
- * the same file now. Before that move the MCP host took its key from the
14
- * environment only (it ships as `mcp/` + `client/`, so it could not require this
15
- * directory), which meant `aegiscode login` made the CLI work and left the
16
- * plugin saying "No AEGIS_API_KEY is set".
17
- *
18
- * This module stays as the CLI's name for that store, so the resolution order,
19
- * the 0600 write and the legacy-adoption behaviour are unchanged for every
20
- * existing caller and test:
21
- *
22
- * 1. `AEGIS_API_KEY` — the environment, so CI and an explicit export keep
23
- * working and nothing written here can shadow them.
24
- * 2. `credentials.json` in the data dir, mode 0600. The writable store.
25
- * 3. `config.json`'s `aegiscloud.api_key` / `memory.token` — the shape an
26
- * earlier AEGIS CLI left in the same data dir. Read, never written or
27
- * deleted; adopted into the 0600 store once so the next run reads that.
28
- *
29
- * A re-export, not a copy: two implementations is how the CLI and the plugin
30
- * would come to disagree about which key is configured.
31
- */
32
-
33
- const shared = require('./shared.js');
34
-
35
- module.exports = shared.credentials;
3
+ "use strict";const shared=require("./shared.js");module.exports=shared.credentials;
@@ -1,234 +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
- * Where the CLI finds the modules it shares with the rest of the repo.
10
- *
11
- * Two layouts must work:
12
- *
13
- * in-repo <repo>/cli/src/deps.js -> <repo>/client/aegis.js, <repo>/mcp/tools.js
14
- * npm <pkg>/src/deps.js -> <pkg>/vendor/{client,mcp,desktop}/...
15
- *
16
- * The published package is staged by `scripts/predist.mjs` into `cli/vendor/`
17
- * keeping the repo's own relative shape, so nothing here (or in the copied
18
- * files) needs a path rewrite — `vendor/mcp/tools.js` requiring
19
- * `../client/foreign-memory.js` resolves inside the vendor tree by construction.
20
- *
21
- * Resolution is by existence, and a missing module is a loud error rather than
22
- * a silent fallback to a second copy: duplicate transports are how the two
23
- * hosts would drift.
24
- */
25
-
26
- const path = require('node:path');
27
-
28
- // Where the shared modules live, WITHOUT loading any of them. Kept in its own
29
- // module because this file eagerly requires everything it resolves, which
30
- // makes it unusable from inside the engine's own dependency graph.
31
- const { roots, resolveShared } = require('./sharedpaths.js');
32
-
33
- const clientPath = resolveShared(path.join('client', 'aegis.js'));
34
- const toolsPath = resolveShared(path.join('mcp', 'tools.js'));
35
- // The desktop's pure usage module is the single source of truth for turning a
36
- // provider's usage object into a display number. The CLI reuses the same file
37
- // instead of re-implementing the mapping, so the terminal and the GUI can never
38
- // disagree about what a call consumed (test/cli-tools.test.mjs asserts the
39
- // function identity).
40
- const usagePath = resolveShared(path.join('desktop', 'renderer', 'usage.js'));
41
- // The desktop's agent-loop engine — persistent-shell exec, editFile/grep,
42
- // Task subagents — reused verbatim (src/engine.js scopes it to the 'aegis'
43
- // class) so the CLI's chat loop is the same tool loop as the GUI's, not a
44
- // second implementation that can drift out of step with it.
45
- const enginePath = resolveShared(path.join('desktop', 'lib', 'local', 'engine.js'));
46
- // The provider-config store the desktop's settings pane writes (one row per
47
- // provider: base URL + key, 0600 on disk). The CLI reads the same file for the
48
- // 'byok' class' per-provider keys, so a key saved in either host is the same
49
- // key — and so there is one implementation of "where a provider key lives"
50
- // rather than a second one that drifts.
51
- const settingsPath = resolveShared(path.join('desktop', 'lib', 'settings.js'));
52
- // Subagent role presets (/agents lists these; the model's task tool delegates
53
- // to them by name) — lives beside engine.js, staged into the same vendor dir.
54
- const agentsPath = resolveShared(path.join('desktop', 'lib', 'local', 'agents.js'));
55
- // The persona the tool loop runs under. The CLI sent NO system prompt at all,
56
- // so a pooled turn reached the model as a bare user message plus tool schemas
57
- // with nothing saying when a tool is appropriate — which is how "hey" started
58
- // running shell commands. Same file as the GUI, for the same reason engine.js
59
- // is: two personas would drift, and only one of them would get fixed.
60
- const promptPath = resolveShared(path.join('desktop', 'lib', 'local', 'prompt.js'));
61
- // The Claude Code Pro class' transport — the user's own subscription, spent by
62
- // spawning the `claude` CLI (desktop/lib/local/claude-pro.js). Shared with the
63
- // desktop host rather than re-implemented, for the reason engine.js is: one
64
- // module owns the child argv, the credential read and the stream-json parser,
65
- // so the GUI and the terminal cannot disagree about what a Pro turn was allowed
66
- // to do or which models the subscription can address. The CLI needs it for the
67
- // picker's rows and the pin rules, which must read the SAME alias list the
68
- // transport does — a second copy here is exactly the drift this file exists to
69
- // prevent.
70
- const claudeProPath = resolveShared(path.join('desktop', 'lib', 'local', 'claude-pro.js'));
71
- // The npm update checker, shared with the desktop host: two package names, one
72
- // implementation, so a fix to the check reaches both.
73
- const updatePath = resolveShared(path.join('client', 'update.js'));
74
- // The autonomous work queue: the durable task list (`queue.js`) and the
75
- // unattended worker that drives the same engine (`autonomous.js`). Shared with
76
- // the desktop host rather than reimplemented, for the reason engine.js is —
77
- // `aegiscode autonomous proceed` on a systemd timer and the GUI's Drain button
78
- // must work the SAME queue with the SAME rules (scoped commits included).
79
- const queuePath = resolveShared(path.join('desktop', 'lib', 'local', 'queue.js'));
80
- const autonomousPath = resolveShared(path.join('desktop', 'lib', 'local', 'autonomous.js'));
81
- // Auto-provision a free device key when no key is configured anywhere — same
82
- // module the MCP plugin and the desktop app use, so all three ask aegis1 for
83
- // the same account on the same machine, with the same timeout.
84
- const autoProvisionPath = resolveShared(path.join('client', 'auto-provision.js'));
85
-
86
- const { createClient } = require(clientPath);
87
- const { createTools } = require(toolsPath);
88
- const { usageTokens, usageBuckets } = require(usagePath);
89
- const { createLocalEngine, hostEnv } = require(enginePath);
90
- const { createSettingsStore, isReservedNamespace } = require(settingsPath);
91
- const { agentRoles, agentRoleLabel } = require(agentsPath);
92
- const { buildSystemPrompt } = require(promptPath);
93
- const claudePro = require(claudeProPath);
94
- const updater = require(updatePath);
95
- const queue = require(queuePath);
96
- const autonomousModule = require(autonomousPath);
97
-
98
- /**
99
- * The shared worker factory, wrapped so a drain closes the model it warmed.
100
- *
101
- * ## Why the wrapper lives here and not at the call site
102
- *
103
- * The desktop's rule is "closing this host closes the model" (`main.js`
104
- * before-quit -> `engine.unloadLocalModels` -> `local.js unloadAll`). The chat
105
- * surfaces on this host have it since `app.js` `releaseLocalModel`, but the
106
- * unattended drain did not: `aegiscode autonomous proceed` builds the same
107
- * engine, runs N turns on the local lane and then exits, leaving whatever it
108
- * warmed resident for the rest of the pin the FIRST turn paid for
109
- * (`DEFAULT_WARM_SECS` = 1800 in local.js, i.e. up to thirty minutes). A queue
110
- * drained from a systemd timer is the worst case, not an edge case: nothing is
111
- * watching the tray, and the timer re-arms every few minutes, so the weights can
112
- * be kept hot indefinitely by a process that exited long ago. The local class
113
- * bills nobody because the compute is already bought — a loaded model with no
114
- * user is the one cost it was meant never to have.
115
- *
116
- * The fix belongs here because `createQueueWorker` does not hand its engine
117
- * back: it returns `{ runTask, runOne, proceed, reconcile, cancel,
118
- * sessionIdFor, resolveModel }` and nothing else, so the caller holds no handle
119
- * to unload. This module is the seam that SUPPLIES that engine (it is built
120
- * from `cli/src/engine.js`, which now carries `unloadLocalModels`), and it is
121
- * the one place on the drain path that is not a sealed unit — `bin/aegiscode.js`
122
- * is provenance p1 and `src/autonomous.js` is p6, both of which a real fix
123
- * there would require resealing deliberately, with a version bump.
124
- *
125
- * ## What is wrapped, and why exactly those
126
- *
127
- * Only the two calls that are a whole DRAIN: `proceed` (which `run` and `retry`
128
- * reach, since `src/autonomous.js` routes `run` to `proceed({ max: 1 })`) and
129
- * `reconcile` (which queues a plan and then drains it in the same call —
130
- * `await proceed(...)` inside the shared worker — so it warms a model exactly
131
- * like `proceed` does).
132
- *
133
- * `runOne` is deliberately NOT wrapped, even though it also runs a turn. A
134
- * drain calls it once per task, so a release there would evict the model
135
- * between tasks of the SAME drain and make every task after the first pay the
136
- * cold prefill the pin exists to avoid. The release belongs at the boundary of
137
- * the drain, not at each turn inside it.
138
- *
139
- * Both wrappers release in a `finally`, so a WARMED-BUT-FAILED drain still
140
- * closes its model — the case most likely to leave weights behind, since the
141
- * successful path at least had a user watching it.
142
- *
143
- * A fire-and-forget `process.on('exit')` would NOT work here and is not used:
144
- * that callback cannot await, and the bin hard-exits (`process.exit(code)` in
145
- * `bin/aegiscode.js`), which skips `beforeExit` entirely — a handler registered
146
- * for it would never run for the drain. Awaiting in a `finally` before the exit
147
- * code is returned is the only ordering that actually issues the request.
148
- *
149
- * Best-effort by construction: a release that throws must never turn a drain
150
- * that did its work into a failed one, and a worker built against a much older
151
- * engine simply has nothing to release.
152
- */
153
- function withModelRelease(worker, engine) {
154
- const release = async () => {
155
- try {
156
- if (engine && typeof engine.unloadLocalModels === 'function') {
157
- await engine.unloadLocalModels();
158
- }
159
- } catch {
160
- // A teardown that crashes is worse than a residency window that lapses on
161
- // its own (see cli/src/engine.js's `unloadLocalModels` note).
162
- }
163
- };
164
-
165
- const wrapDrain = (name) => {
166
- const original = worker[name];
167
- if (typeof original !== 'function') return original;
168
- return async (...args) => {
169
- try {
170
- return await original.apply(worker, args);
171
- } finally {
172
- await release();
173
- }
174
- };
175
- };
176
-
177
- return {
178
- ...worker,
179
- proceed: wrapDrain('proceed'),
180
- reconcile: wrapDrain('reconcile'),
181
- };
182
- }
183
-
184
- const autonomous = {
185
- ...autonomousModule,
186
- createQueueWorker: (opts = {}) =>
187
- autonomousModule.createQueueWorker
188
- ? withModelRelease(autonomousModule.createQueueWorker(opts), opts && opts.engine)
189
- // A staged/vendored shared module older than the worker factory itself:
190
- // degrade to whatever it exports rather than throwing on the drain path.
191
- : autonomousModule.createQueueWorker,
192
- };
193
- const { autoProvisionApiKey, provisionFailureText, trialOutcomeNote } = require(autoProvisionPath);
194
-
195
- // The trial clause is shared so the CLI's two notice sites and the desktop
196
- // cannot word the same outcome differently — but a staged/vendored copy of
197
- // client/auto-provision.js can lag the canonical one (desktop/vendor and
198
- // cli/vendor are generated, and a shipped tree may predate trialOutcomeNote).
199
- // Missing it must degrade to silence, not to a TypeError on the very path that
200
- // has just successfully provisioned a key.
201
- const trialNote = typeof trialOutcomeNote === 'function' ? trialOutcomeNote : () => '';
202
-
203
- module.exports = {
204
- resolveShared,
205
- createClient,
206
- createTools,
207
- usageTokens,
208
- usageBuckets,
209
- createLocalEngine,
210
- // The environment block the two hosts must agree on (see engine.js hostEnv).
211
- // Re-exported so app.js builds its persona from the SAME function the desktop
212
- // engine uses, instead of a three-field subset that omitted the shell dialect
213
- // and the user's real Desktop.
214
- hostEnv,
215
- createSettingsStore,
216
- isReservedNamespace,
217
- agentRoles,
218
- agentRoleLabel,
219
- buildSystemPrompt,
220
- claudePro,
221
- updater,
222
- queue,
223
- autonomous,
224
- autoProvisionApiKey,
225
- provisionFailureText,
226
- // The shared welcome-trial clause ('' when there is nothing to say, and ''
227
- // rather than a throw when a staged copy predates it). Exported so app.js
228
- // does not re-implement the three-way outcome inline — the inline version
229
- // only knew about `trialGranted`, which is why a re-registered machine got a
230
- // first-install notice and no word about the trial it did not receive.
231
- trialNote,
232
- paths: { client: clientPath, tools: toolsPath, usage: usagePath, engine: enginePath, settings: settingsPath, agents: agentsPath, prompt: promptPath, claudePro: claudeProPath, update: updatePath, queue: queuePath, autonomous: autonomousPath, autoProvision: autoProvisionPath },
233
- roots,
234
- };
3
+ "use strict";const path=require("node:path"),{roots:roots,resolveShared:resolveShared}=require("./sharedpaths.js"),clientPath=resolveShared(path.join("client","aegis.js")),toolsPath=resolveShared(path.join("mcp","tools.js")),usagePath=resolveShared(path.join("desktop","renderer","usage.js")),enginePath=resolveShared(path.join("desktop","lib","local","engine.js")),settingsPath=resolveShared(path.join("desktop","lib","settings.js")),agentsPath=resolveShared(path.join("desktop","lib","local","agents.js")),promptPath=resolveShared(path.join("desktop","lib","local","prompt.js")),claudeProPath=resolveShared(path.join("desktop","lib","local","claude-pro.js")),updatePath=resolveShared(path.join("client","update.js")),queuePath=resolveShared(path.join("desktop","lib","local","queue.js")),autonomousPath=resolveShared(path.join("desktop","lib","local","autonomous.js")),autoProvisionPath=resolveShared(path.join("client","auto-provision.js")),{createClient:createClient}=require(clientPath),{createTools:createTools}=require(toolsPath),{usageTokens:usageTokens,usageBuckets:usageBuckets}=require(usagePath),{createLocalEngine:createLocalEngine,hostEnv:hostEnv}=require(enginePath),{createSettingsStore:createSettingsStore,isReservedNamespace:isReservedNamespace}=require(settingsPath),{agentRoles:agentRoles,agentRoleLabel:agentRoleLabel}=require(agentsPath),{buildSystemPrompt:buildSystemPrompt}=require(promptPath),claudePro=require(claudeProPath),updater=require(updatePath),queue=require(queuePath),autonomousModule=require(autonomousPath);function withModelRelease(e,t){const o=o=>{const a=e[o];return"function"!=typeof a?a:async(...o)=>{try{return await a.apply(e,o)}finally{await(async()=>{try{t&&"function"==typeof t.unloadLocalModels&&await t.unloadLocalModels()}catch{}})()}}};return{...e,proceed:o("proceed"),reconcile:o("reconcile")}}const autonomous={...autonomousModule,createQueueWorker:(e={})=>autonomousModule.createQueueWorker?withModelRelease(autonomousModule.createQueueWorker(e),e&&e.engine):autonomousModule.createQueueWorker},{autoProvisionApiKey:autoProvisionApiKey,provisionFailureText:provisionFailureText,trialOutcomeNote:trialOutcomeNote}=require(autoProvisionPath),trialNote="function"==typeof trialOutcomeNote?trialOutcomeNote:()=>"";module.exports={resolveShared:resolveShared,createClient:createClient,createTools:createTools,usageTokens:usageTokens,usageBuckets:usageBuckets,createLocalEngine:createLocalEngine,hostEnv:hostEnv,createSettingsStore:createSettingsStore,isReservedNamespace:isReservedNamespace,agentRoles:agentRoles,agentRoleLabel:agentRoleLabel,buildSystemPrompt:buildSystemPrompt,claudePro:claudePro,updater:updater,queue:queue,autonomous:autonomous,autoProvisionApiKey:autoProvisionApiKey,provisionFailureText:provisionFailureText,trialNote:trialNote,paths:{client:clientPath,tools:toolsPath,usage:usagePath,engine:enginePath,settings:settingsPath,agents:agentsPath,prompt:promptPath,claudePro:claudeProPath,update:updatePath,queue:queuePath,autonomous:autonomousPath,autoProvision:autoProvisionPath},roots:roots};