aegiscode 7.0.11 → 7.0.12

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.
package/src/connect.js ADDED
@@ -0,0 +1,351 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
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 };
package/src/engine.js CHANGED
@@ -226,6 +226,20 @@ function createEngine({ client, getConfirmMode, getClass, getProEnabled, setting
226
226
  return (await local.listClasses()).filter((c) => allowed.includes(c.class));
227
227
  },
228
228
  listModels: (cls) => local.listModels(cls || currentClass()),
229
+ // The user's own model declarations (`$AEGISCODE_HOME/models.json`), read
230
+ // through the shared store (`client/user-models.js`) this host's engine
231
+ // already applies to every `listModels('byok')` call. Exposed on the
232
+ // surface because a caller outside the engine needs to know WHEN that list
233
+ // changed: the picker's cache (`app.js` byokCache) is keyed on this file's
234
+ // content as well as on time, since a declaration written by the desktop's
235
+ // Custom provider card, by `/model-add` in another terminal, or by the
236
+ // user's editor cannot notify this process. Degrades to an empty map on a
237
+ // vendored tree that predates the reader (`local.userModels`), so a cache
238
+ // key can never throw on the path that paints a picker.
239
+ userModels: () =>
240
+ typeof local.userModels === 'function'
241
+ ? local.userModels()
242
+ : { dir: '', file: '', map: {}, invalid: [] },
229
243
  classLabel: (cls) => CLASS_LABELS[cls] || CLASS_LABELS[DEFAULT_CLASS],
230
244
  getClass: currentClass,
231
245
  /** The classes selectable right now (see offeredClasses) — for surfaces
@@ -140,8 +140,19 @@ Key:
140
140
  Vault:
141
141
  publish copies the SEALED BYTES to the vault, byte-identical, and
142
142
  writes the link (<record>.anchor.json) beside the local
143
- copy. Default target gdrive:AEGIS-AGPL (override with
144
- --remote/--root, or AEGIS_VAULT_REMOTE/ROOT).
143
+ copy.
144
+
145
+ DEFAULT BACKEND: aegiscloud — the account this machine
146
+ already registered for (the same device key every other
147
+ cloud feature uses, so publishing needs no second
148
+ sign-in). Nothing to configure; if there is no key yet,
149
+ 'aegiscode login' gives you one.
150
+
151
+ --backend rclone puts the copy somewhere YOU own instead:
152
+ --remote <name> --root <folder> (AEGIS_VAULT_REMOTE /
153
+ AEGIS_VAULT_ROOT), e.g. --remote gdrive --root
154
+ AEGIS-AGPL. That needs an rclone remote already
155
+ configured; the account vault does not.
145
156
  anchor re-downloads the published copy and checks three separate
146
157
  things: present, unchanged (sha256), still attested.
147
158
  vault --audit inspects every object already in the vault for key
@@ -370,7 +381,7 @@ function newestRecord(dataDir) {
370
381
  return files.length ? files[0].f : null;
371
382
  }
372
383
 
373
- function publish(argv, io) {
384
+ async function publish(argv, io) {
374
385
  const { authorship, vault } = load();
375
386
  const env = io.env || process.env;
376
387
  const positional = argv.find((a) => !a.startsWith('-'));
@@ -385,7 +396,7 @@ function publish(argv, io) {
385
396
  }
386
397
  if (!fs.existsSync(file)) throw new Error(`fingerprint: no record at ${file}`);
387
398
 
388
- const r = vault.publish({
399
+ const r = await vault.publish({
389
400
  file,
390
401
  argv,
391
402
  env,
@@ -401,6 +412,7 @@ function publish(argv, io) {
401
412
  io.stdout.write(
402
413
  [
403
414
  `dry run nothing uploaded`,
415
+ `backend ${r.backend}`,
404
416
  `record ${file}`,
405
417
  `would go ${r.remotePath}`,
406
418
  ...r.commands.map((c) => ` ${c}`),
@@ -410,10 +422,10 @@ function publish(argv, io) {
410
422
  }
411
423
  io.stdout.write(
412
424
  [
413
- `published ${r.remotePath}`,
425
+ `published ${r.remotePath} (${r.backend})`,
414
426
  `identity φ_${r.anchor.keyFingerprint}-${r.anchor.behaviour || 'unobserved'}`,
415
427
  `digest sha256 ${r.sha256.slice(0, 16)}… (${r.bytes} bytes, byte-identical to ${file})`,
416
- `link ${r.url || '(no Drive id returned — the copy is at the path above)'}`,
428
+ `link ${r.url || '(no share link — the copy is at the path above)'}`,
417
429
  `anchored ${r.localAnchor}${r.indexLines === null ? '' : ` · ledger lines ${r.indexLines}`}`,
418
430
  '',
419
431
  'The key was NOT published. Only the sealed record travels; verify the copy',
@@ -423,12 +435,12 @@ function publish(argv, io) {
423
435
  return 0;
424
436
  }
425
437
 
426
- function anchorCmd(argv, io) {
438
+ async function anchorCmd(argv, io) {
427
439
  const { vault } = load();
428
440
  const file = argv.find((a) => !a.startsWith('-'));
429
441
  if (!file) throw new Error('fingerprint: anchor needs a record file (the one you published)');
430
442
 
431
- const r = vault.checkAnchor({ file: path.resolve(file), argv, env: io.env || process.env });
443
+ const r = await vault.checkAnchor({ file: path.resolve(file), argv, env: io.env || process.env });
432
444
  if (io.json) {
433
445
  io.stdout.write(JSON.stringify(r, null, 2) + '\n');
434
446
  return r.ok ? 0 : 1;
@@ -452,13 +464,13 @@ function anchorCmd(argv, io) {
452
464
  return r.ok ? 0 : 1;
453
465
  }
454
466
 
455
- function vaultCmd(argv, io) {
467
+ async function vaultCmd(argv, io) {
456
468
  const { authorship, vault } = load();
457
469
  const env = io.env || process.env;
458
470
  const audit = has(argv, '--audit');
459
471
 
460
472
  if (audit) {
461
- const r = vault.audit({ argv, env, secret: secretOrNull(authorship, argv, env) });
473
+ const r = await vault.audit({ argv, env, secret: secretOrNull(authorship, argv, env) });
462
474
  if (io.json) {
463
475
  io.stdout.write(JSON.stringify(r, null, 2) + '\n');
464
476
  return r.ok ? 0 : 1;
@@ -469,7 +481,7 @@ function vaultCmd(argv, io) {
469
481
  }
470
482
  io.stdout.write(
471
483
  [
472
- `vault ${r.remote}:${r.root}`,
484
+ `vault ${r.where} (backend ${r.backend})`,
473
485
  `inspected ${r.checked} of ${r.files} object(s)`,
474
486
  r.uninspected.length ? `skipped ${r.uninspected.length} (see --json)` : '',
475
487
  '',
@@ -490,12 +502,12 @@ function vaultCmd(argv, io) {
490
502
  return r.ok ? 0 : 1;
491
503
  }
492
504
 
493
- const r = vault.list({ argv, env });
505
+ const r = await vault.list({ argv, env });
494
506
  if (io.json) {
495
507
  io.stdout.write(JSON.stringify(r, null, 2) + '\n');
496
508
  return 0;
497
509
  }
498
- const lines = [`vault ${r.remote}:${r.root} (${r.records.length} record(s))`];
510
+ const lines = [`vault ${r.where} (${r.records.length} record(s), backend ${r.backend})`];
499
511
  for (const rec of r.records) {
500
512
  lines.push(
501
513
  ` ${rec.name}`,
@@ -545,12 +557,18 @@ function runFingerprint(sub, argv = [], io = {}) {
545
557
  return verify(argv, out);
546
558
  case 'backup':
547
559
  return backup(argv, out);
560
+ // The three vault subcommands are async because the default vault is
561
+ // the account (an HTTP vault) as well as rclone. They keep the same
562
+ // contract though — an exit code, and a throw becomes exit 2 — so a
563
+ // caller only has to `await` the result; the sync subcommands above
564
+ // still return a plain number, which is what `runFingerprint` always did
565
+ // and what its tests assert.
548
566
  case 'publish':
549
- return publish(argv, out);
567
+ return asExitCode(publish(argv, out), out);
550
568
  case 'anchor':
551
- return anchorCmd(argv, out);
569
+ return asExitCode(anchorCmd(argv, out), out);
552
570
  case 'vault':
553
- return vaultCmd(argv, out);
571
+ return asExitCode(vaultCmd(argv, out), out);
554
572
  default:
555
573
  out.stderr.write(`aegiscode: unknown fingerprint subcommand "${sub}"\n\n${HELP}\n`);
556
574
  return 2;
@@ -561,4 +579,16 @@ function runFingerprint(sub, argv = [], io = {}) {
561
579
  }
562
580
  }
563
581
 
582
+ /**
583
+ * A vault subcommand's promise, as the same exit-code contract the sync
584
+ * subcommands have: a rejection is a usage-shaped line on stderr and exit 2,
585
+ * never a stack trace over a user's record (see this file's header on 1 vs 2).
586
+ */
587
+ function asExitCode(promise, io) {
588
+ return promise.catch((e) => {
589
+ io.stderr.write(`aegiscode: ${(e && e.message) || e}\n`);
590
+ return 2;
591
+ });
592
+ }
593
+
564
594
  module.exports = { runFingerprint, HELP, slug, defaultRecordPath, flag, everyFlag };
package/src/limits.js CHANGED
@@ -101,7 +101,7 @@ const UNITS = Object.freeze([
101
101
  * The masked digest of the sealed set. Rewritten ONLY by
102
102
  * `node tools/provenance.mjs seal --write`, never by hand.
103
103
  */
104
- const SEALED = '4affd4840744736343e06c20f92b51d4e16cd061faa9539e46d9965b06dda04b';
104
+ const SEALED = '5109d6727943ad3404b26820f686c7a4e056b5a334e1f5905322e403c06fb68a';
105
105
 
106
106
  /** Subcommands that a build failing this check does not get to run. */
107
107
  const PRIVILEGED = Object.freeze(['gate', 'provenance', 'mcp']);
@@ -24,13 +24,13 @@
24
24
  "license": "AGPL-3.0-or-later",
25
25
  "source": "https://github.com/aegisinfo/aegiscode-plugin",
26
26
  "units": {
27
- "p1": "6ab4d502c73d950c4c17afaaa5afc350475050a0bb45e883a8fdb8c71ca04757",
27
+ "p1": "b992aa725ee2c371e3ae857d6dedd4aa398b8decff00326d2ad11ed996299eb0",
28
28
  "p2": "d63d147de5455eea111d000b748d7eef9572a11a08d31f2471d5ff146701342c",
29
29
  "p3": "ff962ac8dbf42cecb2477e2f77bf5ec61f88aa1751b0d4e506bf030fbc5fc6c6",
30
30
  "p4": "2e8385c3a653a2af324050b4b92aeb9d142fc6765c91a13ccc928c5d4a2dbedb",
31
31
  "p5": "408d67f78f31f6d637a26d2852e0c809a260544e613afdc64b731401c0ba3801",
32
32
  "p6": "22bcd0b5dc1afad8d870652fbf1fd25bd0a547be9d8700161449cafa35bab6eb",
33
- "p7": "1ff7c8ddf9f2f2f15d60a9c40ab5ab777bfa4e0e69e5876f65073535ce6790f2",
33
+ "p7": "89ee0c5ab9640c470c03cddcfa9e3722182dca62eb2df8e3f0a53342e59207f3",
34
34
  "p8": "3cc054d06715e065fe635b37b7d1bb98bf7989d64453a572ddbb77cec5b830e7"
35
35
  }
36
36
  }
package/src/screens.js CHANGED
@@ -44,7 +44,7 @@ const { TAGLINE, TAGLINE_SHORT, welcomeArtParts } = require('./art.js');
44
44
  const { renderDiffPreview } = require('./markdown.js');
45
45
  const render = require('./render.js');
46
46
  const { updateConfig, configExists, loadConfig } = require('./config.js');
47
- const { updateNotice, updateLine } = require('./update.js');
47
+ const { updateNotice, updateLine, serverNotice, serverUpdateLine } = require('./update.js');
48
48
  const credentials = require('./credentials.js');
49
49
  const { signupUrl, signupDisplayUrl } = require('./signup.js');
50
50
  const { createSettingsStore, isReservedNamespace } = require('./deps.js');
@@ -392,6 +392,19 @@ function welcomeLines(ctx, cols, rows, firstRun = true) {
392
392
  save: (v) => { try { updateConfig({ updateCheck: v }); } catch { /* not fatal */ } },
393
393
  });
394
394
  updateMsg = updateLine({ current: VERSION, ...notice });
395
+
396
+ // The server's own verdict, which outranks the registry's: "a newer
397
+ // release exists" is a suggestion, "this build is no longer served" is
398
+ // the app about to stop working. aegis1 refuses clients below
399
+ // MIN_CLIENT_VERSION with a 426, so without this line a user learns it
400
+ // by being cut off mid-task instead of by reading their welcome box.
401
+ // Same cache-read-only rule: the refresh lands for the next launch.
402
+ const srv = serverNotice({
403
+ current: VERSION,
404
+ cache: cfg.updateCheckServer,
405
+ save: (v) => { try { updateConfig({ updateCheckServer: v }); } catch { /* not fatal */ } },
406
+ });
407
+ updateMsg = serverUpdateLine(srv) || updateMsg;
395
408
  } catch {
396
409
  // An update notice is never worth failing a launch over.
397
410
  }
@@ -382,8 +382,15 @@ function clientOptions(o = {}) {
382
382
  const { key } = resolveApiKey(o);
383
383
  const { token } = resolveMemoryToken(o);
384
384
  const opts = {};
385
- if (key) opts.apiKey = key;
386
- if (token) opts.memoryToken = token;
385
+ // Set explicitly, even when empty: `createClient` only re-checks its own
386
+ // (real, ambient) process.env when `apiKey`/`memoryToken` are `undefined`.
387
+ // Omitting an empty result here was indistinguishable from "not resolved
388
+ // yet" and let that fallback see the real environment's key even when an
389
+ // injected `o.env`/`o.dir` (tests, a hosted agent, a `--base` against a
390
+ // staging account — the reason this function takes them at all) had
391
+ // already and correctly resolved to "no key".
392
+ opts.apiKey = key;
393
+ opts.memoryToken = token;
387
394
  // The host names itself so upgrade prompts raised inside the shared client
388
395
  // are attributed to the right product. Unset means desktop, which matches
389
396
  // createClient's own default.