aegisone 1.0.18 → 1.0.21

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 (61) hide show
  1. package/README.md +2 -2
  2. package/package.json +2 -1
  3. package/scripts/bump.mjs +29 -4
  4. package/scripts/predist.mjs +15 -2
  5. package/src/dispatch.js +1 -0
  6. package/vendor/cli/bin/aegiscode.js +41 -0
  7. package/vendor/cli/package.json +2 -1
  8. package/vendor/cli/scripts/predist.mjs +6 -3
  9. package/vendor/cli/src/app.js +436 -24
  10. package/vendor/cli/src/autonomous.js +19 -2
  11. package/vendor/cli/src/chatflow.js +77 -4
  12. package/vendor/cli/src/commands.js +220 -10
  13. package/vendor/cli/src/config.js +21 -0
  14. package/vendor/cli/src/connect.js +351 -0
  15. package/vendor/cli/src/deps.js +97 -1
  16. package/vendor/cli/src/engine.js +98 -8
  17. package/vendor/cli/src/fingerprint.js +46 -16
  18. package/vendor/cli/src/limits.js +1 -1
  19. package/vendor/cli/src/overlays.js +54 -0
  20. package/vendor/cli/src/provenance.lock.json +3 -3
  21. package/vendor/cli/src/screens.js +14 -1
  22. package/vendor/cli/src/update.js +103 -12
  23. package/vendor/cli/vendor/client/aegis.js +169 -3
  24. package/vendor/cli/vendor/client/credentials.js +9 -2
  25. package/vendor/cli/vendor/client/drive-connect.js +87 -0
  26. package/vendor/cli/vendor/client/drive-upload.js +176 -0
  27. package/vendor/cli/vendor/client/google-signin.js +127 -0
  28. package/vendor/cli/vendor/client/record-vault.js +431 -113
  29. package/vendor/cli/vendor/client/update.js +366 -8
  30. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +134 -11
  31. package/vendor/cli/vendor/desktop/lib/local/engine.js +111 -26
  32. package/vendor/cli/vendor/desktop/lib/local/prompt.js +67 -37
  33. package/vendor/cli/vendor/desktop/lib/local/tools.js +49 -13
  34. package/vendor/cli/vendor/desktop/lib/settings.js +65 -24
  35. package/vendor/desktop/lib/auto.js +11 -7
  36. package/vendor/desktop/lib/fingerprint.js +76 -17
  37. package/vendor/desktop/lib/google-connect.js +171 -0
  38. package/vendor/desktop/lib/local/claude-pro.js +134 -11
  39. package/vendor/desktop/lib/local/engine.js +111 -26
  40. package/vendor/desktop/lib/local/prompt.js +67 -37
  41. package/vendor/desktop/lib/local/tools.js +49 -13
  42. package/vendor/desktop/lib/settings.js +65 -24
  43. package/vendor/desktop/main.js +270 -36
  44. package/vendor/desktop/package.json +5 -2
  45. package/vendor/desktop/preload.js +45 -12
  46. package/vendor/desktop/renderer/app.js +691 -22
  47. package/vendor/desktop/renderer/budget.js +18 -9
  48. package/vendor/desktop/renderer/companion.js +225 -0
  49. package/vendor/desktop/renderer/fingerprint.css +16 -0
  50. package/vendor/desktop/renderer/fingerprint.js +136 -2
  51. package/vendor/desktop/renderer/index.html +302 -121
  52. package/vendor/desktop/renderer/provider-toolbar.js +136 -0
  53. package/vendor/desktop/renderer/providers.js +261 -0
  54. package/vendor/desktop/renderer/style.css +547 -171
  55. package/vendor/desktop/vendor/aegis.js +169 -3
  56. package/vendor/desktop/vendor/credentials.js +9 -2
  57. package/vendor/desktop/vendor/drive-connect.js +87 -0
  58. package/vendor/desktop/vendor/drive-upload.js +176 -0
  59. package/vendor/desktop/vendor/google-signin.js +127 -0
  60. package/vendor/desktop/vendor/record-vault.js +431 -113
  61. package/vendor/desktop/vendor/update.js +366 -8
@@ -158,6 +158,198 @@ function fetchLatest(opts = {}) {
158
158
  return fetchLatestDetailed(opts).then((r) => (r.ok ? r.latest : null));
159
159
  }
160
160
 
161
+ //: Where the AEGIS server answers "am I still allowed to talk to you".
162
+ const DEFAULT_API_BASE = 'https://aegiscloud.org';
163
+ /** /api/v1/version is a tiny JSON document; anything bigger is a proxy page. */
164
+ const VERSION_BODY_CAP = 64 * 1024;
165
+
166
+ /**
167
+ * Ask the SERVER whether this client is still serviceable.
168
+ *
169
+ * Why this exists next to the npm check: they answer different questions.
170
+ * The registry says what was *published*; the server says what it will
171
+ * *accept*. aegis1 refuses every request from a client below
172
+ * `MIN_CLIENT_VERSION` with a 426, so a client that only asks npm learns it is
173
+ * unservicable by being refused mid-task — an outage, not a notice. Asking
174
+ * `/api/v1/version` first turns the same fact into a sentence the user reads
175
+ * before they hit the wall.
176
+ *
177
+ * `/api/v1/version` is informational: it never refuses anyone, and it echoes
178
+ * the verdict for the version header we send (`upgrade_required`).
179
+ *
180
+ * Resolves `{ ok, minClient, latestCli, latestDesktop, upgradeRequired,
181
+ * downloadUrl, reason, status }` and never rejects — same contract as
182
+ * `fetchLatestDetailed`, so a host can render "registry unreachable" and
183
+ * "server unreachable" differently instead of inventing a third story.
184
+ */
185
+ function fetchServerVersionDetailed({
186
+ base = DEFAULT_API_BASE,
187
+ clientVersion = null,
188
+ timeoutMs = TIMEOUT_MS,
189
+ getImpl = null,
190
+ } = {}) {
191
+ return new Promise((resolve) => {
192
+ let settled = false;
193
+ const done = (v) => {
194
+ if (!settled) {
195
+ settled = true;
196
+ resolve(v);
197
+ }
198
+ };
199
+ const fail = (reason, status = null) =>
200
+ done({
201
+ ok: false, minClient: null, latestCli: null, latestDesktop: null,
202
+ upgradeRequired: null, downloadUrl: '', reason, status,
203
+ });
204
+ const succeed = (body, status) => {
205
+ const minClient = body && typeof body.min_client === 'string' ? body.min_client : null;
206
+ // A 200 without `min_client` is malformed, not a slow network: do not
207
+ // invite a retry ladder for a document that will parse the same way.
208
+ if (!minClient) return fail(REASONS.MALFORMED, status);
209
+ done({
210
+ ok: true,
211
+ minClient,
212
+ latestCli: typeof body.latest_cli === 'string' ? body.latest_cli : '',
213
+ latestDesktop: typeof body.latest_desktop === 'string' ? body.latest_desktop : '',
214
+ // Trust the header echo only when we actually sent a version: without
215
+ // one the server answers for `require_header=False` and the answer is
216
+ // about nothing in particular. `null` here means "the server did not
217
+ // say", which is different from "the server said no" — the caller must
218
+ // be able to fall back without overriding an answer it was given.
219
+ upgradeRequired:
220
+ clientVersion && typeof body.upgrade_required === 'boolean'
221
+ ? body.upgrade_required
222
+ : null,
223
+ downloadUrl: typeof body.download_url === 'string' ? body.download_url : '',
224
+ reason: null,
225
+ status,
226
+ });
227
+ };
228
+
229
+ try {
230
+ const url = `${String(base || DEFAULT_API_BASE).replace(/\/+$/, '')}/api/v1/version`;
231
+ const headers = { accept: 'application/json' };
232
+ if (clientVersion) headers['X-AEGIS-Version'] = String(clientVersion);
233
+
234
+ const onResponse = (res) => {
235
+ const status = res.statusCode;
236
+ if (status !== 200) {
237
+ res.resume();
238
+ if (status === 404) return fail(REASONS.NOT_FOUND, status);
239
+ if (status === 401 || status === 403) return fail(REASONS.FORBIDDEN, status);
240
+ // 426 here would mean the endpoint itself were gated; treat it as a
241
+ // real answer rather than a transport failure if it ever happens.
242
+ if (status === 426) return fail(REASONS.HTTP, status);
243
+ return fail(REASONS.HTTP, status);
244
+ }
245
+ let body = '';
246
+ res.setEncoding('utf8');
247
+ res.on('data', (c) => {
248
+ body += c;
249
+ if (body.length > VERSION_BODY_CAP) {
250
+ res.destroy();
251
+ fail(REASONS.TOO_LARGE, status);
252
+ }
253
+ });
254
+ res.on('end', () => {
255
+ if (settled) return;
256
+ try {
257
+ succeed(JSON.parse(body), status);
258
+ } catch {
259
+ fail(REASONS.MALFORMED, status);
260
+ }
261
+ });
262
+ };
263
+
264
+ if (typeof getImpl === 'function') {
265
+ // Injected transport for tests and hosts that already own a fetch:
266
+ // `getImpl({url, headers, timeoutMs})` resolves `{status, text}`.
267
+ Promise.resolve(getImpl({ url, headers, timeoutMs }))
268
+ .then((r) => {
269
+ const status = r && r.status != null ? r.status : 0;
270
+ if (!status) return fail(REASONS.NETWORK);
271
+ if (status !== 200) {
272
+ if (status === 404) return fail(REASONS.NOT_FOUND, status);
273
+ if (status === 401 || status === 403) return fail(REASONS.FORBIDDEN, status);
274
+ return fail(REASONS.HTTP, status);
275
+ }
276
+ const text = r && typeof r.text === 'string' ? r.text : '';
277
+ if (text.length > VERSION_BODY_CAP) return fail(REASONS.TOO_LARGE, status);
278
+ try {
279
+ succeed(JSON.parse(text), status);
280
+ } catch {
281
+ fail(REASONS.MALFORMED, status);
282
+ }
283
+ })
284
+ .catch(() => fail(REASONS.NETWORK));
285
+ return;
286
+ }
287
+
288
+ const req = require(/^http:\/\//i.test(url) ? 'node:http' : 'node:https')
289
+ .get(url, { headers, timeout: timeoutMs }, onResponse);
290
+ req.on('timeout', () => {
291
+ req.destroy();
292
+ fail(REASONS.TIMEOUT);
293
+ });
294
+ req.on('error', () => fail(REASONS.NETWORK));
295
+ } catch {
296
+ fail(REASONS.NETWORK);
297
+ }
298
+ });
299
+ }
300
+
301
+ /** The server's minimum client version, or null. */
302
+ function fetchServerVersion(opts = {}) {
303
+ return fetchServerVersionDetailed(opts).then((r) => (r.ok ? r.minClient : null));
304
+ }
305
+
306
+ /**
307
+ * The server's verdict, expressed in the shape the notice/plan code already
308
+ * speaks: `{ behind, latest, required, downloadUrl, ok, reason, status }`.
309
+ *
310
+ * `behind` is true when the SERVER says this client is below its minimum —
311
+ * regardless of whether npm happens to have something newer. That ordering is
312
+ * deliberate: being refused is actionable now, being merely superseded is not.
313
+ */
314
+ async function serverUpdateVerdict({
315
+ current,
316
+ base = DEFAULT_API_BASE,
317
+ timeoutMs = TIMEOUT_MS,
318
+ getImpl = null,
319
+ } = {}) {
320
+ const res = await fetchServerVersionDetailed({ base, clientVersion: current, timeoutMs, getImpl });
321
+ if (!res.ok) {
322
+ return { ok: false, behind: false, latest: null, required: null, downloadUrl: '', reason: res.reason, status: res.status };
323
+ }
324
+ const required = res.minClient || null;
325
+ // The server's echo decides. Falling back to local arithmetic only when it
326
+ // said nothing (`null`) — OR'ing the two would let our own comparison
327
+ // override the very authority we asked, which is the bug this line exists to
328
+ // not have.
329
+ const behind =
330
+ res.upgradeRequired === true
331
+ ? true
332
+ : res.upgradeRequired === false
333
+ ? false
334
+ : required
335
+ ? isNewer(required, current)
336
+ : false;
337
+ return {
338
+ ok: true,
339
+ behind,
340
+ // The server's own minimum is the target when it is the thing refusing us;
341
+ // a published version is preferred when it names one, because that is what
342
+ // the user should actually install.
343
+ latest: (behind && (res.latestCli || res.latestDesktop)) || required,
344
+ latestCli: res.latestCli,
345
+ latestDesktop: res.latestDesktop,
346
+ required,
347
+ downloadUrl: res.downloadUrl,
348
+ reason: null,
349
+ status: res.status,
350
+ };
351
+ }
352
+
161
353
  /**
162
354
  * The notice to show, from cache. Never waits on the network.
163
355
  *
@@ -207,19 +399,21 @@ function updateNotice({
207
399
  *
208
400
  * @param {{current: string, latest: ?string, behind: boolean, channel?: 'npm'|'desktop', pkg?: string}} input
209
401
  */
210
- function updatePlan({ current, latest, behind, channel = 'npm', pkg = PKG } = {}) {
402
+ function updatePlan({ current, latest, behind, channel = 'npm', pkg = PKG, method = 'npm' } = {}) {
211
403
  const currentText = String(current == null ? '' : current);
212
404
  const latestText = latest ? String(latest) : null;
213
405
  const pending = Boolean(behind) && Boolean(latestText);
214
406
  if (!pending) {
215
407
  return {
216
408
  channel,
409
+ method,
217
410
  current: currentText,
218
411
  latest: latestText,
219
412
  behind: false,
220
413
  action: 'none',
221
414
  applier: 'none',
222
415
  instruction: null,
416
+ apply: null,
223
417
  };
224
418
  }
225
419
  if (channel === 'desktop') {
@@ -228,25 +422,101 @@ function updatePlan({ current, latest, behind, channel = 'npm', pkg = PKG } = {}
228
422
  // beside the running app. The applier is the app's own updater.
229
423
  return {
230
424
  channel,
425
+ method,
231
426
  current: currentText,
232
427
  latest: latestText,
233
428
  behind: true,
234
429
  action: 'desktop-update',
235
430
  applier: 'electron-updater',
236
431
  instruction: 'Aegis Desktop → Check for Updates…',
432
+ apply: null,
237
433
  };
238
434
  }
435
+
436
+ // Which installer owns this copy. The command is not cosmetic: `npm i -g`
437
+ // against a pip-installed `aegiscode` writes a second copy beside the one the
438
+ // user actually runs, and the "upgrade" appears to do nothing. Same for an
439
+ // `npx` run, which has nothing installed to upgrade at all.
440
+ const applier = APPLIERS[method] || APPLIERS.npm;
239
441
  return {
240
442
  channel,
443
+ method,
241
444
  current: currentText,
242
445
  latest: latestText,
243
446
  behind: true,
244
- action: 'npm-update',
245
- applier: 'npm',
246
- instruction: `npm i -g ${pkg}@latest`,
447
+ action: applier.action,
448
+ applier: applier.name,
449
+ instruction: applier.instruction(pkg),
450
+ apply: applier.apply ? applier.apply(pkg) : null,
247
451
  };
248
452
  }
249
453
 
454
+ /**
455
+ * The ways this product reaches a machine, and what "update it" means for each.
456
+ *
457
+ * `apply` names argv to run — it is what the window's Update button and the
458
+ * CLI's `/upgrade apply` execute. `null` means there is nothing to install:
459
+ * `npx` fetches `latest` on every launch by definition, and a source checkout
460
+ * belongs to its owner's git remote.
461
+ */
462
+ const APPLIERS = Object.freeze({
463
+ npm: Object.freeze({
464
+ name: 'npm',
465
+ action: 'npm-update',
466
+ instruction: (pkg) => `npm i -g ${pkg}@latest`,
467
+ apply: (pkg) => ({ command: 'npm', args: ['i', '-g', `${pkg}@latest`] }),
468
+ }),
469
+ pip: Object.freeze({
470
+ name: 'pip',
471
+ action: 'pip-update',
472
+ // The published pip package is a launcher for the npm one, so this is
473
+ // genuinely a different command — not an npm call with a different word.
474
+ instruction: (pkg) => `pip install -U ${pkg}`,
475
+ apply: (pkg) => ({ command: process.platform === 'win32' ? 'python' : 'python3',
476
+ args: ['-m', 'pip', 'install', '-U', pkg] }),
477
+ }),
478
+ npx: Object.freeze({
479
+ name: 'none',
480
+ action: 'npx-update',
481
+ instruction: () => 'already fetched fresh on every run — restart to pick up the new version',
482
+ apply: null,
483
+ }),
484
+ source: Object.freeze({
485
+ name: 'git',
486
+ action: 'source-update',
487
+ instruction: () => 'git pull && npm ci (this copy is a source checkout)',
488
+ apply: null,
489
+ }),
490
+ });
491
+
492
+ /**
493
+ * Which installer owns the copy that is running — so the sentence names a
494
+ * command that actually changes THIS binary.
495
+ *
496
+ * Order matters. An explicit declaration wins (the pip launcher sets
497
+ * `AEGIS_INSTALL_METHOD=pip` before exec'ing the real CLI, which is the only
498
+ * way the npm package can know a Python install is driving it). Then npx, which
499
+ * is detectable from the argv it builds. Then a source checkout, then npm.
500
+ *
501
+ * Pure and injectable: `env`, `argv` and a file probe, no `process` reads, so a
502
+ * test can assert every branch without npm or pip being installed.
503
+ */
504
+ function detectInstallMethod({
505
+ env = {}, argv = [], pkg = PKG, fileExists = () => false, entry = '',
506
+ } = {}) {
507
+ const declared = String((env && env.AEGIS_INSTALL_METHOD) || '').trim().toLowerCase();
508
+ if (declared && Object.prototype.hasOwnProperty.call(APPLIERS, declared)) return declared;
509
+
510
+ const joined = argv.map((a) => String(a)).join(' ');
511
+ if (/\bnpx\b/.test(joined) || /_npx[\\/]/.test(joined) || /_npx[\\/]/.test(entry)) return 'npx';
512
+ if (/[\\/]pipx[\\/]venvs[\\/]/.test(entry) || /[\\/]site-packages[\\/]/.test(entry)) return 'pip';
513
+ if (/[\\/]node_modules[\\/]/.test(entry)) return 'npm';
514
+ // A git checkout has the repo's own marker files; a global npm install does
515
+ // not (they are not in the package's `files` list).
516
+ if (fileExists('.git') && fileExists('client/update.js')) return 'source';
517
+ return 'npm';
518
+ }
519
+
250
520
  /**
251
521
  * The same once-a-day check as `updateNotice`, but *awaited* and detailed.
252
522
  *
@@ -326,23 +596,111 @@ async function checkPublished({
326
596
  * Rendered from `updatePlan`, not from a second copy of the sentence: the
327
597
  * command the terminal tells the user to run and the command the window's
328
598
  * banner offers are the same string produced by the same verdict.
599
+ *
600
+ * `method` is the install channel the caller detected (see
601
+ * `detectInstallMethod`). It is threaded through rather than assumed to be npm
602
+ * because the previous version returned `null` — silence — for every channel
603
+ * that was not npm, so a pip install and an npx run were never told a release
604
+ * existed. A host that knows how it was installed should say so.
605
+ */
606
+ function updateLine({ current, latest, behind, pkg = PKG, method = 'npm' }) {
607
+ const plan = updatePlan({ current, latest, behind, channel: 'npm', pkg, method });
608
+ if (!plan.behind) return null;
609
+ const head = `Update available: ${plan.current} → ${plan.latest}`;
610
+ // `apply` is null for the two channels with nothing to install, whose
611
+ // instruction is already a sentence — prefixing those with "run:" would read
612
+ // as a command that does not exist.
613
+ return plan.apply
614
+ ? `${head} run: ${plan.instruction}`
615
+ : `${head} ${plan.instruction}`;
616
+ }
617
+
618
+ /**
619
+ * The server's verdict, from cache. Never waits on the network.
620
+ *
621
+ * Same contract and the same once-a-day rule as `updateNotice`, for the same
622
+ * reason: the welcome box draws from what the last run learned, and the
623
+ * refresh lands for the next one. A first run shows nothing, which is right —
624
+ * it has no verdict yet.
625
+ *
626
+ * Returns `{ behind, latest, required, downloadUrl }`. `behind` is the server's
627
+ * answer, not a comparison this module invented, so the box says "update" only
628
+ * when the server would actually refuse this client.
629
+ */
630
+ function serverNotice({
631
+ current,
632
+ cache,
633
+ save,
634
+ now = Date.now(),
635
+ verdictImpl = serverUpdateVerdict,
636
+ intervalMs = CHECK_INTERVAL_MS,
637
+ } = {}) {
638
+ const c = cache || {};
639
+ const fresh = typeof c.checkedAt === 'number' && now - c.checkedAt < intervalMs;
640
+
641
+ if (!fresh) {
642
+ Promise.resolve()
643
+ .then(() => verdictImpl({ current }))
644
+ .then((v) => {
645
+ if (!v || typeof save !== 'function') return;
646
+ // Persist the verdict even when it is "not behind": that is what tells
647
+ // the next run it already asked today, and stops a check per launch.
648
+ save({
649
+ checkedAt: now,
650
+ behind: Boolean(v.behind),
651
+ required: v.required || null,
652
+ latest: v.latest || null,
653
+ downloadUrl: v.downloadUrl || '',
654
+ reason: v.reason || null,
655
+ });
656
+ })
657
+ .catch(() => {});
658
+ }
659
+
660
+ return {
661
+ behind: Boolean(c.behind),
662
+ latest: c.latest || null,
663
+ required: c.required || null,
664
+ downloadUrl: c.downloadUrl || '',
665
+ };
666
+ }
667
+
668
+ /**
669
+ * The line for the welcome box when the SERVER says this build is too old.
670
+ *
671
+ * Distinct from `updateLine` on purpose: "a newer release exists" and "the
672
+ * server will refuse you" are different urgency, and only the second one means
673
+ * the app is about to stop working. Says where to get it, because a user who
674
+ * is being cut off needs a destination, not a version number.
329
675
  */
330
- function updateLine({ current, latest, behind, pkg = PKG }) {
331
- const plan = updatePlan({ current, latest, behind, channel: 'npm', pkg });
332
- if (plan.action !== 'npm-update') return null;
333
- return `Update available: ${plan.current} → ${plan.latest} run: ${plan.instruction}`;
676
+ function serverUpdateLine({ behind, latest, required, downloadUrl } = {}) {
677
+ if (!behind) return null;
678
+ const target = latest || required || '';
679
+ const head = target
680
+ ? `This build is no longer served — update to v${target}.`
681
+ : 'This build is no longer served — update to the latest release.';
682
+ const where = downloadUrl ? ` ${downloadUrl}` : '';
683
+ return `${head}${where}`;
334
684
  }
335
685
 
336
686
  module.exports = {
337
687
  isNewer,
338
688
  fetchLatest,
339
689
  fetchLatestDetailed,
690
+ fetchServerVersion,
691
+ fetchServerVersionDetailed,
692
+ serverUpdateVerdict,
693
+ serverNotice,
694
+ serverUpdateLine,
340
695
  isTransientReason,
341
696
  updateNotice,
342
697
  checkPublished,
343
698
  updatePlan,
344
699
  updateLine,
700
+ detectInstallMethod,
701
+ APPLIERS,
345
702
  PKG,
346
703
  CHECK_INTERVAL_MS,
347
704
  REASONS,
705
+ DEFAULT_API_BASE,
348
706
  };