aegiscode 7.0.26 → 7.0.28

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 (118) hide show
  1. package/SOURCE-OFFER.txt +9 -0
  2. package/package.json +4 -7
  3. package/scripts/check.mjs +1 -52
  4. package/scripts/demo.mjs +1 -94
  5. package/scripts/predist.mjs +1 -75
  6. package/scripts/runtests.mjs +1 -56
  7. package/scripts/seal-gate.mjs +1 -74
  8. package/src/agents.js +1 -139
  9. package/src/app.js +1 -2957
  10. package/src/art.js +1 -289
  11. package/src/chatflow.js +1 -3023
  12. package/src/checkpoint.js +1 -90
  13. package/src/clipboard.js +1 -424
  14. package/src/cloudsync.js +1 -528
  15. package/src/commands.js +1 -4089
  16. package/src/config.js +1 -581
  17. package/src/connect.js +1 -349
  18. package/src/credentials.js +1 -33
  19. package/src/deps.js +1 -232
  20. package/src/devrun.js +1 -187
  21. package/src/diff.js +1 -333
  22. package/src/diffview.js +1 -296
  23. package/src/engine.js +1 -297
  24. package/src/entitlement.js +1 -355
  25. package/src/events.js +1 -707
  26. package/src/export.js +1 -67
  27. package/src/filepreview.js +1 -153
  28. package/src/fingerprint.js +1 -592
  29. package/src/format.js +1 -259
  30. package/src/fuzzy.js +1 -119
  31. package/src/history.js +1 -423
  32. package/src/init.js +1 -175
  33. package/src/input.js +1 -139
  34. package/src/keys.js +1 -183
  35. package/src/markdown.js +1 -306
  36. package/src/models.js +1 -507
  37. package/src/naming.js +1 -57
  38. package/src/overlays.js +1 -462
  39. package/src/panels.js +1 -1418
  40. package/src/ping.js +1 -226
  41. package/src/presence.js +1 -238
  42. package/src/render.js +1 -516
  43. package/src/screen.js +1 -518
  44. package/src/screens.js +1 -896
  45. package/src/secret.js +1 -59
  46. package/src/securefs.js +1 -359
  47. package/src/settings.js +1 -155
  48. package/src/shared.js +1 -52
  49. package/src/sharedpaths.js +1 -53
  50. package/src/signup.js +1 -156
  51. package/src/summarize.js +1 -95
  52. package/src/sysdiag.js +1 -585
  53. package/src/system.js +1 -40
  54. package/src/theme.js +1 -570
  55. package/src/title.js +1 -220
  56. package/src/todos.js +1 -115
  57. package/src/tokens.js +1 -263
  58. package/src/topup.js +1 -210
  59. package/src/update.js +1 -191
  60. package/vendor/client/aegis.js +1 -2441
  61. package/vendor/client/attest.js +1 -518
  62. package/vendor/client/authorship-key.js +1 -410
  63. package/vendor/client/auto-provision.js +1 -134
  64. package/vendor/client/brain-catalog.js +1 -268
  65. package/vendor/client/byok-catalog.js +1 -199
  66. package/vendor/client/catalog-client.js +1 -487
  67. package/vendor/client/conversation-export.js +1 -177
  68. package/vendor/client/credentials.js +1 -494
  69. package/vendor/client/device-fingerprint.js +1 -141
  70. package/vendor/client/drive-connect.js +1 -110
  71. package/vendor/client/drive-upload.js +1 -234
  72. package/vendor/client/env-file.js +1 -1273
  73. package/vendor/client/fingerprint.js +1 -1064
  74. package/vendor/client/foreign-memory.js +1 -669
  75. package/vendor/client/google-signin.js +1 -133
  76. package/vendor/client/hooks.js +1 -430
  77. package/vendor/client/model-discovery.js +1 -373
  78. package/vendor/client/naming.js +1 -283
  79. package/vendor/client/platform.js +1 -937
  80. package/vendor/client/prefs.js +1 -351
  81. package/vendor/client/presence-constants.js +1 -107
  82. package/vendor/client/presence.js +1 -438
  83. package/vendor/client/record-vault.js +3 -1055
  84. package/vendor/client/session-store.js +1 -575
  85. package/vendor/client/topup.js +1 -297
  86. package/vendor/client/touch.js +1 -458
  87. package/vendor/client/update.js +1 -763
  88. package/vendor/client/user-models.js +1 -381
  89. package/vendor/desktop/lib/local/agents.js +1 -105
  90. package/vendor/desktop/lib/local/attachments.js +1 -276
  91. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  92. package/vendor/desktop/lib/local/claude-pro.js +1 -1028
  93. package/vendor/desktop/lib/local/context.js +1 -125
  94. package/vendor/desktop/lib/local/engine.js +1 -3666
  95. package/vendor/desktop/lib/local/entitlement.js +1 -660
  96. package/vendor/desktop/lib/local/exec-plan.js +1 -269
  97. package/vendor/desktop/lib/local/git-scope.js +1 -228
  98. package/vendor/desktop/lib/local/integrity.js +1 -163
  99. package/vendor/desktop/lib/local/local.js +1 -2145
  100. package/vendor/desktop/lib/local/prompt.js +1 -280
  101. package/vendor/desktop/lib/local/queue.js +1 -560
  102. package/vendor/desktop/lib/local/session-rounds.js +1 -238
  103. package/vendor/desktop/lib/local/shell.js +1 -712
  104. package/vendor/desktop/lib/local/spill.js +1 -75
  105. package/vendor/desktop/lib/local/tools.js +1 -1328
  106. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  107. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  108. package/vendor/desktop/lib/settings.js +1 -890
  109. package/vendor/desktop/main.js +1 -4890
  110. package/vendor/desktop/renderer/usage.js +1 -1239
  111. package/vendor/hosts/install.js +1 -638
  112. package/vendor/hosts/openai-shim.js +1 -515
  113. package/vendor/hosts/spec.js +1 -164
  114. package/vendor/hosts/targets.js +1 -346
  115. package/vendor/mcp/server.js +1 -221
  116. package/vendor/mcp/tools.js +1 -408
  117. package/vendor/one/src/child.js +1 -285
  118. package/vendor/one/src/permissions.js +1 -383
package/src/connect.js CHANGED
@@ -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 e=r.createClient(s.clientOptions({channel:"cli",env:t.env,dir:u.dir}));let i,l;try{i=await c.startGoogleSignIn({apiBase:e.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)(i.url)||t.json||t.stdout.write(`aegiscode: could not open a browser automatically — open this URL:\n ${i.url}\n`);try{l=await i.wait()}catch(e){return o(2,`google sign-in did not complete — ${e&&e.message||e}`)}const d=u.saveApiKey(l.apiKey);if(!d.ok)return o(2,d.message||`could not save the key to ${d.path}`);l.memoryToken&&s.saveMemoryToken(l.memoryToken,{},u.dir);const g=report(s,a,t.env);return t.json?(t.stdout.write(JSON.stringify({...g,registered:!0,provider:"google",username:l.username},null,2)+"\n"),0):(t.stdout.write([`connected — ${g.masked}${l.username?` (signed in as ${l.username})`:""}`,`key saved to ${g.path}`,`vault ${g.vault_backend} — \`aegiscode fingerprint publish\` lands here`,g.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
+ const e=require("./shared.js");module.exports=e.credentials;
package/src/deps.js CHANGED
@@ -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};