aegiscode 6.8.17 → 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.17",
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",
@@ -95,8 +95,26 @@ function resolveModelsModule() {
95
95
  const { normalizeModelCatalog, pickerEntries } = require(resolveModelsModule());
96
96
 
97
97
  const DEFAULT_PORT = 8787;
98
+ const DEFAULT_HOST = '127.0.0.1';
98
99
  const LOOPBACK = new Set(['127.0.0.1', '::1', 'localhost']);
99
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
+
100
118
  /** OpenAI's schema wants `owned_by` and a created timestamp; neither means
101
119
  * anything for a pooled provider, so both are stable constants. */
102
120
  const EPOCH = 1735689600; // 2025-01-01T00:00:00Z
@@ -168,18 +186,13 @@ function chunkFrame(id, model, delta, finishReason) {
168
186
  */
169
187
  function createShimServer(opts = {}) {
170
188
  const client = opts.client || createClient(credentials.clientOptions());
171
- const host = opts.host || '127.0.0.1';
189
+ const host = opts.host || DEFAULT_HOST;
172
190
  const port = opts.port === undefined ? DEFAULT_PORT : opts.port;
173
191
  const out = opts.log || process.stderr;
174
192
  const requireKey = opts.requireKey !== false;
175
193
  const fetchModels = opts.fetchModels || (() => client.listModels());
176
194
 
177
- if (!LOOPBACK.has(host) && !opts.allowRemote) {
178
- throw new Error(
179
- `refusing to bind ${host}: the shim spends your account's tokens, so it is loopback-only ` +
180
- 'unless you pass --allow-remote'
181
- );
182
- }
195
+ assertBindAllowed(host, opts.allowRemote);
183
196
 
184
197
  // The catalog is cached for a minute: a model picker calls /v1/models on
185
198
  // every focus, and hitting aegiscloud.org each time is a visible stall in the
@@ -414,6 +427,23 @@ async function main(argv) {
414
427
  return 0;
415
428
  }
416
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
+
417
447
  // ── the shared env file, before any credential is resolved ───────────────
418
448
  //
419
449
  // Placed after the `--help` early-return so help stays instant, and before
@@ -425,7 +455,6 @@ async function main(argv) {
425
455
  // "no key at all" into one sentence instead of a 401 from another program.
426
456
  // Same call, same contract as cli/bin/aegiscode.js, desktop/main.js and
427
457
  // mcp/server.js; see this file's header for what its absence cost.
428
- const out = opts.log || process.stderr;
429
458
  try {
430
459
  const envFile = require('../client/env-file.js');
431
460
  const envResult = envFile.loadEnvFile();