aegisone 1.0.20 → 1.0.22

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 (39) hide show
  1. package/README.md +1 -1
  2. package/package.json +2 -1
  3. package/scripts/predist.mjs +13 -2
  4. package/vendor/cli/bin/aegiscode.js +12 -0
  5. package/vendor/cli/package.json +2 -1
  6. package/vendor/cli/scripts/predist.mjs +6 -3
  7. package/vendor/cli/src/app.js +102 -1
  8. package/vendor/cli/src/chatflow.js +14 -2
  9. package/vendor/cli/src/commands.js +61 -5
  10. package/vendor/cli/src/limits.js +1 -1
  11. package/vendor/cli/src/provenance.lock.json +2 -2
  12. package/vendor/cli/src/update.js +103 -12
  13. package/vendor/cli/vendor/client/aegis.js +297 -6
  14. package/vendor/cli/vendor/client/drive-connect.js +112 -0
  15. package/vendor/cli/vendor/client/drive-upload.js +176 -0
  16. package/vendor/cli/vendor/client/google-signin.js +12 -4
  17. package/vendor/cli/vendor/client/model-discovery.js +43 -0
  18. package/vendor/cli/vendor/client/update.js +100 -8
  19. package/vendor/cli/vendor/desktop/lib/local/engine.js +138 -2
  20. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +7 -1
  21. package/vendor/cli/vendor/desktop/lib/local/prompt.js +67 -37
  22. package/vendor/cli/vendor/desktop/lib/local/tools.js +49 -13
  23. package/vendor/desktop/lib/google-connect.js +229 -0
  24. package/vendor/desktop/lib/local/engine.js +138 -2
  25. package/vendor/desktop/lib/local/entitlement.js +7 -1
  26. package/vendor/desktop/lib/local/prompt.js +67 -37
  27. package/vendor/desktop/lib/local/tools.js +49 -13
  28. package/vendor/desktop/main.js +446 -128
  29. package/vendor/desktop/package.json +2 -4
  30. package/vendor/desktop/preload.js +27 -5
  31. package/vendor/desktop/renderer/app.js +117 -7
  32. package/vendor/desktop/renderer/fingerprint.js +92 -2
  33. package/vendor/desktop/renderer/index.html +17 -0
  34. package/vendor/desktop/vendor/aegis.js +297 -6
  35. package/vendor/desktop/vendor/drive-connect.js +112 -0
  36. package/vendor/desktop/vendor/drive-upload.js +176 -0
  37. package/vendor/desktop/vendor/google-signin.js +12 -4
  38. package/vendor/desktop/vendor/model-discovery.js +43 -0
  39. package/vendor/desktop/vendor/update.js +100 -8
@@ -37,10 +37,14 @@ function escapeHtml(s) {
37
37
  }[c]));
38
38
  }
39
39
 
40
- function page({ ok, error, username }) {
40
+ function page({ ok, error, username, surface }) {
41
41
  const title = ok ? 'Signed in' : 'Sign-in failed';
42
+ // This page is shared by the CLI and the desktop, and only one of them is
43
+ // a terminal. The desktop passes `surface: 'app'`; the default keeps the
44
+ // CLI's existing wording.
45
+ const where = surface === 'app' ? 'the app' : 'the terminal';
42
46
  const body = ok
43
- ? `Signed in${username ? ` as <b>${escapeHtml(username)}</b>` : ''}. You can close this tab and return to the terminal.`
47
+ ? `Signed in${username ? ` as <b>${escapeHtml(username)}</b>` : ''}. You can close this tab and return to ${where}.`
44
48
  : `Sign-in failed: ${escapeHtml(error || 'no token was returned')}. You can close this tab and try again.`;
45
49
  return `<!doctype html><html><head><meta charset="utf-8"><title>${title} — AEGIS</title></head>` +
46
50
  `<body style="font:16px sans-serif;max-width:32rem;margin:4rem auto;text-align:center;">` +
@@ -62,9 +66,13 @@ function buildAuthUrl(apiBase, callbackUrl) {
62
66
  * else (a browser pre-connect, `/favicon.ico`) gets a plain 404 and the
63
67
  * server keeps listening for the real one.
64
68
  *
69
+ * `surface` only changes the wording of the page the browser lands on after
70
+ * signing in ('terminal' for the CLI, 'app' for the desktop) — it changes
71
+ * nothing about the flow itself.
72
+ *
65
73
  * @returns {Promise<{url: string, wait: () => Promise<{apiKey:string, username:?string, memoryToken:?string}>}>}
66
74
  */
67
- async function startGoogleSignIn({ apiBase, host = '127.0.0.1', timeoutMs = 5 * 60 * 1000 } = {}) {
75
+ async function startGoogleSignIn({ apiBase, host = '127.0.0.1', timeoutMs = 5 * 60 * 1000, surface = 'terminal' } = {}) {
68
76
  if (!apiBase) throw new Error('startGoogleSignIn requires apiBase');
69
77
 
70
78
  let settled = false;
@@ -93,7 +101,7 @@ async function startGoogleSignIn({ apiBase, host = '127.0.0.1', timeoutMs = 5 *
93
101
  return;
94
102
  }
95
103
  res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
96
- res.end(page({ ok: Boolean(token), error, username }));
104
+ res.end(page({ ok: Boolean(token), error, username, surface }));
97
105
 
98
106
  if (settled) return;
99
107
  settled = true;
@@ -101,6 +101,36 @@ const ENDPOINTS = Object.freeze({
101
101
  headers: bearer,
102
102
  note: 'OpenAI-compatible',
103
103
  }),
104
+ // The remaining providers in aegis1's catalog that speak `openai_chat` and
105
+ // answer a standard OpenAI-shaped list on `<base_url>/models`.
106
+ //
107
+ // Probed live rather than assumed, because "OpenAI-compatible chat" does not
108
+ // imply "has a list endpoint": cerebras, fireworks and sakana answer 401/403
109
+ // without a key (the endpoint exists and is gated) and NVIDIA's list answers
110
+ // 200 unauthenticated with 84 rows, which is why it is the one endpoint here
111
+ // whose list is public. Ollama is deliberately absent: it is keyless and
112
+ // local, so it has nothing to put in the API key this module requires, and
113
+ // `canDiscover` would be reporting a capability the caller cannot use.
114
+ cerebras: Object.freeze({
115
+ url: 'https://api.cerebras.ai/v1/models',
116
+ headers: bearer,
117
+ note: 'OpenAI-compatible under /v1',
118
+ }),
119
+ fireworks: Object.freeze({
120
+ url: 'https://api.fireworks.ai/inference/v1/models',
121
+ headers: bearer,
122
+ note: 'OpenAI-compatible under /inference/v1; ids are "accounts/fireworks/models/<id>"',
123
+ }),
124
+ nvidia_nim: Object.freeze({
125
+ url: 'https://integrate.api.nvidia.com/v1/models',
126
+ headers: bearer,
127
+ note: 'OpenAI-compatible; ids are "<vendor>/<model>"',
128
+ }),
129
+ sakana: Object.freeze({
130
+ url: 'https://api.sakana.ai/v1/models',
131
+ headers: bearer,
132
+ note: 'OpenAI-compatible under /v1',
133
+ }),
104
134
  });
105
135
 
106
136
  /** Other spellings a user types for a provider this module knows. */
@@ -112,6 +142,19 @@ const ALIASES = Object.freeze({
112
142
  'googleai': 'gemini',
113
143
  'open-ai': 'openai',
114
144
  'deep-seek': 'deepseek',
145
+ // Two catalog rows that are the SAME VENDOR under a second provider id: both
146
+ // `openai-gpt4o-mini` and `anthropic-haiku` share their sibling's credential
147
+ // and base_url, and differ only in the default model they pin (see
148
+ // `client/byok-catalog.js`, which notes the two OpenAI ids "share one
149
+ // credential and one model"). Discovery asks a vendor, so both spellings must
150
+ // reach the one list its key can already answer — otherwise a user holding a
151
+ // key filed under the `-haiku` / `-gpt4o-mini` row is told this client has no
152
+ // endpoint for their provider while the identical key under the sibling row
153
+ // is accepted. `custom` and `ollama` are deliberately NOT aliased: the first
154
+ // has no fixed base_url (it is supplied per request), and the second is
155
+ // keyless, so neither has a vendor list this module could ask.
156
+ 'openai-gpt4o-mini': 'openai',
157
+ 'anthropic-haiku': 'anthropic',
115
158
  });
116
159
 
117
160
  /**
@@ -399,19 +399,21 @@ function updateNotice({
399
399
  *
400
400
  * @param {{current: string, latest: ?string, behind: boolean, channel?: 'npm'|'desktop', pkg?: string}} input
401
401
  */
402
- function updatePlan({ current, latest, behind, channel = 'npm', pkg = PKG } = {}) {
402
+ function updatePlan({ current, latest, behind, channel = 'npm', pkg = PKG, method = 'npm' } = {}) {
403
403
  const currentText = String(current == null ? '' : current);
404
404
  const latestText = latest ? String(latest) : null;
405
405
  const pending = Boolean(behind) && Boolean(latestText);
406
406
  if (!pending) {
407
407
  return {
408
408
  channel,
409
+ method,
409
410
  current: currentText,
410
411
  latest: latestText,
411
412
  behind: false,
412
413
  action: 'none',
413
414
  applier: 'none',
414
415
  instruction: null,
416
+ apply: null,
415
417
  };
416
418
  }
417
419
  if (channel === 'desktop') {
@@ -420,25 +422,101 @@ function updatePlan({ current, latest, behind, channel = 'npm', pkg = PKG } = {}
420
422
  // beside the running app. The applier is the app's own updater.
421
423
  return {
422
424
  channel,
425
+ method,
423
426
  current: currentText,
424
427
  latest: latestText,
425
428
  behind: true,
426
429
  action: 'desktop-update',
427
430
  applier: 'electron-updater',
428
431
  instruction: 'Aegis Desktop → Check for Updates…',
432
+ apply: null,
429
433
  };
430
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;
431
441
  return {
432
442
  channel,
443
+ method,
433
444
  current: currentText,
434
445
  latest: latestText,
435
446
  behind: true,
436
- action: 'npm-update',
437
- applier: 'npm',
438
- 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,
439
451
  };
440
452
  }
441
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
+
442
520
  /**
443
521
  * The same once-a-day check as `updateNotice`, but *awaited* and detailed.
444
522
  *
@@ -518,11 +596,23 @@ async function checkPublished({
518
596
  * Rendered from `updatePlan`, not from a second copy of the sentence: the
519
597
  * command the terminal tells the user to run and the command the window's
520
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.
521
605
  */
522
- function updateLine({ current, latest, behind, pkg = PKG }) {
523
- const plan = updatePlan({ current, latest, behind, channel: 'npm', pkg });
524
- if (plan.action !== 'npm-update') return null;
525
- return `Update available: ${plan.current} → ${plan.latest} run: ${plan.instruction}`;
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}`;
526
616
  }
527
617
 
528
618
  /**
@@ -607,6 +697,8 @@ module.exports = {
607
697
  checkPublished,
608
698
  updatePlan,
609
699
  updateLine,
700
+ detectInstallMethod,
701
+ APPLIERS,
610
702
  PKG,
611
703
  CHECK_INTERVAL_MS,
612
704
  REASONS,