aegiscode 6.8.16 → 6.8.18

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "aegiscode",
3
3
  "productName": "AEGIS Code",
4
- "version": "6.8.16",
4
+ "version": "6.8.18",
5
5
  "description": "aegiscode — the command-line version of AEGIS Desktop. The shared tool surface in your shell, over the same thin transport and tool registry as the MCP plugin and the desktop app. Ships transport + UI only; no brain.",
6
6
  "author": {
7
7
  "name": "AEGIS Code",
@@ -30,8 +30,30 @@
30
30
  * `--allow-remote` is passed explicitly (the endpoint spends the account's
31
31
  * tokens, so exposing it is a decision, not a default);
32
32
  * - never logs or echoes the AEGIS key;
33
- * - the key is resolved by the ordinary path (env → 0600 store → .env), so
34
- * the shim holds no credential of its own.
33
+ * - the key is resolved by the ordinary path (env → 0600 store → legacy
34
+ * config.json), so the shim holds no credential of its own.
35
+ *
36
+ * THE SHARED ENV FILE — and why `run()` below reads it before anything else.
37
+ *
38
+ * `credentials.resolveApiKey()` reads the *environment*, then its own stores;
39
+ * it has never opened `~/.aegiscode/.env` (that is `client/env-file.js`'s job,
40
+ * deliberately: one reader, one contract). Every other host in this repo calls
41
+ * that reader at start-up — `cli/bin/aegiscode.js` before caps and a session,
42
+ * `desktop/main.js` before `createClient`, `mcp/server.js` at load. This file
43
+ * did not, so it was the one host where the documented setup
44
+ *
45
+ * AEGIS_API_KEY=aegis_… # in ~/.aegiscode/.env
46
+ *
47
+ * silently did nothing: the shim started, the editor got a 401 on the first
48
+ * message, and the key instruction printed in this file's own `--help` named a
49
+ * file the shim never read. In a shell that had also exported the variable the
50
+ * bug was invisible, which is exactly how it survived — a GUI-launched editor
51
+ * has no such export, and that is the normal way this shim is used.
52
+ *
53
+ * So `run()` loads the file, then *checks* the key and refuses to serve without
54
+ * one, naming where a key can come from. A shim that starts keyless is worse
55
+ * than one that exits: the failure surfaces later, in another program's error
56
+ * dialog, as an unexplained 401.
35
57
  */
36
58
 
37
59
  const fs = require('node:fs');
@@ -73,8 +95,26 @@ function resolveModelsModule() {
73
95
  const { normalizeModelCatalog, pickerEntries } = require(resolveModelsModule());
74
96
 
75
97
  const DEFAULT_PORT = 8787;
98
+ const DEFAULT_HOST = '127.0.0.1';
76
99
  const LOOPBACK = new Set(['127.0.0.1', '::1', 'localhost']);
77
100
 
101
+ /**
102
+ * Refuse to bind anything but loopback unless the operator asked for it.
103
+ *
104
+ * Hoisted out of `createShimServer` because `main()` must apply it *first*:
105
+ * it is an argument refusal, and a keyless shim still cannot leak anything
106
+ * while a public one can. See the call site in `main()` for the ordering bug
107
+ * this caused when it lived only inside the server factory.
108
+ */
109
+ function assertBindAllowed(host, allowRemote) {
110
+ if (!LOOPBACK.has(host) && !allowRemote) {
111
+ throw new Error(
112
+ `refusing to bind ${host}: the shim spends your account's tokens, so it is loopback-only ` +
113
+ 'unless you pass --allow-remote'
114
+ );
115
+ }
116
+ }
117
+
78
118
  /** OpenAI's schema wants `owned_by` and a created timestamp; neither means
79
119
  * anything for a pooled provider, so both are stable constants. */
80
120
  const EPOCH = 1735689600; // 2025-01-01T00:00:00Z
@@ -146,18 +186,13 @@ function chunkFrame(id, model, delta, finishReason) {
146
186
  */
147
187
  function createShimServer(opts = {}) {
148
188
  const client = opts.client || createClient(credentials.clientOptions());
149
- const host = opts.host || '127.0.0.1';
189
+ const host = opts.host || DEFAULT_HOST;
150
190
  const port = opts.port === undefined ? DEFAULT_PORT : opts.port;
151
191
  const out = opts.log || process.stderr;
152
192
  const requireKey = opts.requireKey !== false;
153
193
  const fetchModels = opts.fetchModels || (() => client.listModels());
154
194
 
155
- if (!LOOPBACK.has(host) && !opts.allowRemote) {
156
- throw new Error(
157
- `refusing to bind ${host}: the shim spends your account's tokens, so it is loopback-only ` +
158
- 'unless you pass --allow-remote'
159
- );
160
- }
195
+ assertBindAllowed(host, opts.allowRemote);
161
196
 
162
197
  // The catalog is cached for a minute: a model picker calls /v1/models on
163
198
  // every focus, and hitting aegiscloud.org each time is a visible stall in the
@@ -391,6 +426,68 @@ async function main(argv) {
391
426
  ].join('\n'));
392
427
  return 0;
393
428
  }
429
+
430
+ const out = opts.log || process.stderr;
431
+
432
+ // ── argument refusal, before the credential precondition ─────────────────
433
+ //
434
+ // The loopback guard runs FIRST. It is an argument refusal — the operator
435
+ // asked for something the shim does not do — and every CLI convention
436
+ // validates arguments before resolving credentials. Ordering it the other
437
+ // way cost a real regression: `--host 0.0.0.0` without a key answered with
438
+ // the no-key line, so the one invocation that would expose the account to
439
+ // the network never printed the sentence that explains why it will not.
440
+ try {
441
+ assertBindAllowed(opts.host || DEFAULT_HOST, opts.allowRemote);
442
+ } catch (err) {
443
+ logLine(out, err.message);
444
+ return 1;
445
+ }
446
+
447
+ // ── the shared env file, before any credential is resolved ───────────────
448
+ //
449
+ // Placed after the `--help` early-return so help stays instant, and before
450
+ // `createShimServer` — which is where `createClient(credentials.clientOptions())`
451
+ // runs and therefore the last point at which process.env can still decide the
452
+ // key. An exported `AEGIS_API_KEY` always wins: loadEnvFile() fills only names
453
+ // the environment does not already have. Failure is never fatal here — an
454
+ // absent file is the pre-existing state — because the check right below turns
455
+ // "no key at all" into one sentence instead of a 401 from another program.
456
+ // Same call, same contract as cli/bin/aegiscode.js, desktop/main.js and
457
+ // mcp/server.js; see this file's header for what its absence cost.
458
+ try {
459
+ const envFile = require('../client/env-file.js');
460
+ const envResult = envFile.loadEnvFile();
461
+ if (envResult.loose) {
462
+ logLine(
463
+ out,
464
+ `${envResult.file} is readable by other accounts (mode ${envResult.mode.toString(8)}) — ` +
465
+ 'consider `chmod 600` on it'
466
+ );
467
+ }
468
+ } catch (e) {
469
+ logLine(out, `could not read the shared env file: ${e && e.message}`);
470
+ }
471
+
472
+ // Refuse to serve with no account key. The shim cannot answer a single
473
+ // request without one, and a keyless endpoint reports that failure to the
474
+ // *editor*, hours later, as an opaque 401 — the exact confusion this check
475
+ // removes. `--no-auth` is about the caller's bearer token, not this
476
+ // credential, so it does not relax this.
477
+ const resolved = credentials.resolveApiKey();
478
+ if (!resolved.key) {
479
+ logLine(
480
+ out,
481
+ `no AEGIS account key — ${credentials.HOW_TO_SET}, ` +
482
+ `or set ${credentials.KEY_ENV} in ~/.aegiscode/.env`
483
+ );
484
+ return 1;
485
+ }
486
+ // Where the key came from, never the key itself: "did it pick up my .env or
487
+ // the file an older sign-in wrote?" is the question a user actually has, and
488
+ // it is unanswerable from a masked key alone.
489
+ logLine(out, `AEGIS key: ${credentials.sourceLabel(resolved.source)}`);
490
+
394
491
  let shim;
395
492
  try {
396
493
  shim = createShimServer(opts);