aegiscode 6.8.15 → 6.8.16
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/LICENSE +661 -0
- package/README.md +7 -0
- package/bin/aegiscode.js +19 -15
- package/package.json +1 -1
- package/src/app.js +66 -2
- package/src/chatflow.js +8 -1
- package/src/commands.js +17 -2
- package/src/events.js +103 -2
- package/src/screen.js +27 -0
- package/vendor/client/brain-catalog.js +77 -0
- package/vendor/client/env-file.js +13 -2
- package/vendor/desktop/lib/local/engine.js +41 -18
- package/vendor/desktop/lib/local/shell.js +45 -4
package/bin/aegiscode.js
CHANGED
|
@@ -658,26 +658,30 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
658
658
|
// while four pty runs competed for the cpu, 0 of 12 when they did not. The
|
|
659
659
|
// teardown is guaranteed the same way (see chatflow.js); the hint now is too,
|
|
660
660
|
// so the bytes no longer depend on which of the two paths ended the process.
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
661
|
+
// The hint is handed to the screen module instead of being scheduled here.
|
|
662
|
+
// It is emitted *by* `leaveAltScreen()`, i.e. by the restore itself, because
|
|
663
|
+
// position cannot be guaranteed by ordering where three paths can reach the
|
|
664
|
+
// teardown (the loop's `finally`, the session's `exit` handler, this file's
|
|
665
|
+
// `exit` handler) and their relative order is timing-dependent. That race put
|
|
666
|
+
// the same 81 bytes in two different positions from run to run — the parity
|
|
667
|
+
// suite saw linux/darwin/win32 diverge and then converge, at random, with
|
|
668
|
+
// platform swapped out for luck. See `queueExitNotice` in src/screen.js.
|
|
669
|
+
const screen = require('../src/screen.js');
|
|
670
|
+
screen.queueExitNotice('\nResume this session with:\n aegiscode --continue (or /resume for the list)\n');
|
|
671
|
+
// A queued notice is consumed exactly once, by the first restore to run; the
|
|
672
|
+
// flush covers the paths that never leave an alternate screen (a crash before
|
|
673
|
+
// the screen was taken, a host that drives the loop with its own stdin), so
|
|
674
|
+
// the hint cannot be lost by the very mechanism that guarantees its position.
|
|
675
|
+
const leaveHint = () => {
|
|
665
676
|
try {
|
|
666
|
-
|
|
677
|
+
if (screen.isAltScreen()) screen.leaveAltScreen();
|
|
678
|
+
screen.flushExitNotice();
|
|
667
679
|
} catch { /* the terminal is already gone; nothing to say it to */ }
|
|
668
680
|
};
|
|
669
|
-
// Registration order *is* byte order: `process.once('exit')` handlers run in
|
|
670
|
-
// the order they were added, and the session registers its own teardown
|
|
671
|
-
// (leave the alternate screen, drop mouse reporting) inside
|
|
672
|
-
// `runInteractive`. Adding this handler *after* that call is what puts the
|
|
673
|
-
// hint last, i.e. outside the alternate screen. Written before the teardown
|
|
674
|
-
// it is erased by the restore that follows it — the user sees a clean shell
|
|
675
|
-
// and concludes the session was never saved, which is the same bug as losing
|
|
676
|
-
// the hint outright, one layer down.
|
|
677
681
|
const running = app.runInteractive();
|
|
678
|
-
process.once('exit',
|
|
682
|
+
process.once('exit', leaveHint);
|
|
679
683
|
const code = await running;
|
|
680
|
-
|
|
684
|
+
leaveHint();
|
|
681
685
|
return code;
|
|
682
686
|
}
|
|
683
687
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aegiscode",
|
|
3
3
|
"productName": "AEGIS Code",
|
|
4
|
-
"version": "6.8.
|
|
4
|
+
"version": "6.8.16",
|
|
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",
|
package/src/app.js
CHANGED
|
@@ -546,13 +546,77 @@ function createApp(options = {}) {
|
|
|
546
546
|
async function listModelsFor(cls) {
|
|
547
547
|
const want = HOST_CLASSES.includes(cls) ? cls : commandCtx.modelClass;
|
|
548
548
|
try {
|
|
549
|
-
if (want === 'byok')
|
|
549
|
+
if (want === 'byok') {
|
|
550
|
+
const byok = await loadByokModels();
|
|
551
|
+
// The pooled catalog may never have been fetched on a byok-only session
|
|
552
|
+
// (`/model` alone on a fresh install), and the Nexus row below can only
|
|
553
|
+
// come from it — so read it here, best-effort. A failed read (offline,
|
|
554
|
+
// or no account key) leaves the byok rows, which is the honest list: no
|
|
555
|
+
// pooled row, rather than one this process cannot name.
|
|
556
|
+
if (!modelCache.models.length) {
|
|
557
|
+
try {
|
|
558
|
+
await loadModels();
|
|
559
|
+
} catch {
|
|
560
|
+
/* no pooled catalog to read — byok rows stand alone */
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return classScopedModels(byok);
|
|
564
|
+
}
|
|
550
565
|
return await loadModels();
|
|
551
566
|
} catch {
|
|
552
567
|
return [];
|
|
553
568
|
}
|
|
554
569
|
}
|
|
555
570
|
|
|
571
|
+
/** The pooled class's pickable rows, each tagged with the class it runs on. */
|
|
572
|
+
function pooledRows() {
|
|
573
|
+
return pickerEntries(modelCache.models).map((m) => ({ ...m, cls: 'aegis' }));
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/** The byok class's own `provider:model` rows, tagged the same way. */
|
|
577
|
+
function byokRows() {
|
|
578
|
+
return pickerEntries(byokCache.models).map((m) => ({ ...m, cls: 'byok' }));
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* The class-scoped model list — `state().models`, `/models`, the alt+p chord
|
|
583
|
+
* and the `/class` auto-pick all read it, so it is one list and not four.
|
|
584
|
+
*
|
|
585
|
+
* On the POOLED class it is just the catalog's pickable rows. On the BYOK
|
|
586
|
+
* class it is those rows PLUS the pooled Nexus row, which the server's
|
|
587
|
+
* `provider:model` listing can never contain: the two id spaces are disjoint
|
|
588
|
+
* (`models.js` documents it, and `pinBelongsToClass` enforces it), so a
|
|
589
|
+
* session sitting on byok used to see a list with no way back to the pooled
|
|
590
|
+
* lane in it — the same "correct list, undiscoverable half" defect
|
|
591
|
+
* `mergedPickerModels` in commands.js fixes for the `/model` picker, fixed
|
|
592
|
+
* here for the list the other surfaces read, so the panel, the chord and the
|
|
593
|
+
* picker cannot disagree about whether Nexus is an option.
|
|
594
|
+
*
|
|
595
|
+
* Each row carries its own `cls`, which is what the picker's ENTER handler
|
|
596
|
+
* switches on and what `/models` paints its "pooled lane" marker from:
|
|
597
|
+
* picking Nexus from the byok list moves the session to the pooled class
|
|
598
|
+
* BEFORE the pin applies, because a pooled id pinned under byok is parsed as
|
|
599
|
+
* a provider name and 400s at the relay. Tagging is not decoration — it is
|
|
600
|
+
* why this row is safe to offer from a class that cannot run it.
|
|
601
|
+
*
|
|
602
|
+
* The pooled row comes from the same `pickerEntries` shaping the pooled class
|
|
603
|
+
* uses (`filterAegisCatalog`'s single-row collapse), never a hand-built
|
|
604
|
+
* literal: a second spelling of "the brain's id and label" is exactly the
|
|
605
|
+
* drift `client/brain-catalog.js` exists to end. Its absence is not an error
|
|
606
|
+
* — no account key means no pooled catalog to read, and a byok-only session
|
|
607
|
+
* must still list its own models.
|
|
608
|
+
*
|
|
609
|
+
* @param {Array<object>} [byokOverride] rows already fetched by an async
|
|
610
|
+
* caller, so an awaiting caller does not re-read a cache it just filled.
|
|
611
|
+
*/
|
|
612
|
+
function classScopedModels(byokOverride) {
|
|
613
|
+
if (commandCtx.modelClass !== 'byok') return pooledRows();
|
|
614
|
+
const byok = Array.isArray(byokOverride)
|
|
615
|
+
? byokOverride.map((m) => ({ ...m, cls: 'byok' }))
|
|
616
|
+
: byokRows();
|
|
617
|
+
return [...pooledRows(), ...byok];
|
|
618
|
+
}
|
|
619
|
+
|
|
556
620
|
/**
|
|
557
621
|
* Whether a pinned id can run on `cls`, decided synchronously (switchClass is
|
|
558
622
|
* not async). byok ids are `provider:model`; aegis takes anything that is
|
|
@@ -1105,7 +1169,7 @@ function createApp(options = {}) {
|
|
|
1105
1169
|
// dropped, live ids only (see models.js pickerEntries).
|
|
1106
1170
|
// Whichever class is live decides what is pinnable — the pooled ids the
|
|
1107
1171
|
// server advertises, or the `provider:model` ids this machine can relay.
|
|
1108
|
-
models:
|
|
1172
|
+
models: classScopedModels(),
|
|
1109
1173
|
commands: visibleCommands(),
|
|
1110
1174
|
transcript: transcript.slice(),
|
|
1111
1175
|
sessions: [],
|
package/src/chatflow.js
CHANGED
|
@@ -42,7 +42,7 @@ const {
|
|
|
42
42
|
} = require('./screen.js');
|
|
43
43
|
const {
|
|
44
44
|
KEY, STREAM_END, attachKeyStream, nextKey, nextKeyTimeout, requeueKeys, resetKeyStream,
|
|
45
|
-
isKeyStreamSuspended,
|
|
45
|
+
markSessionStart, isKeyStreamSuspended,
|
|
46
46
|
} = require('./events.js');
|
|
47
47
|
const { GLYPH, VERBS, DONE_VERBS, BOLD, BOLD_OFF, themeOf } = require('./theme.js');
|
|
48
48
|
const { LineEditor } = require('./input.js');
|
|
@@ -2071,6 +2071,13 @@ async function runSession(host) {
|
|
|
2071
2071
|
// Enter the alternate screen and take over the terminal. `host.stdin` exists
|
|
2072
2072
|
// so the loop can be driven from a test with a synthetic key stream.
|
|
2073
2073
|
const stdin = host.stdin || process.stdin;
|
|
2074
|
+
// Claim the queue BEFORE attaching. Everything queued up to this instant was
|
|
2075
|
+
// typed at a terminal no session owned yet — it survived onboarding's pump
|
|
2076
|
+
// teardown only because the pump knew no session had started (`drainQueue`),
|
|
2077
|
+
// and this is the line that ends that grace period: from here the queue is
|
|
2078
|
+
// this session's, and a later teardown may clear it. Order matters — after
|
|
2079
|
+
// `attachKeyStream` would be too late for the keys already held.
|
|
2080
|
+
markSessionStart();
|
|
2074
2081
|
attachKeyStream(stdin);
|
|
2075
2082
|
enableBracketedPaste();
|
|
2076
2083
|
enableMouseTracking();
|
package/src/commands.js
CHANGED
|
@@ -2452,7 +2452,14 @@ const COMMANDS = [
|
|
|
2452
2452
|
// land on one this machine can actually run — a provider it holds a key
|
|
2453
2453
|
// for wins, since the alternative 400s on the key rather than the id.
|
|
2454
2454
|
if (res.class === 'byok' && !(c.ctx && c.ctx.model)) {
|
|
2455
|
-
|
|
2455
|
+
// The byok list carries the pooled Nexus row too (app.js
|
|
2456
|
+
// classScopedModels) so the lane is discoverable — but this host cannot
|
|
2457
|
+
// RUN it under byok: the relay reads a pinned id as a provider name, so
|
|
2458
|
+
// auto-pinning Nexus here would fail the very next turn, which is the
|
|
2459
|
+
// failure this whole branch exists to avoid. Pick from this class's own
|
|
2460
|
+
// rows only.
|
|
2461
|
+
const models = ((await c.listModelsFor('byok')) || [])
|
|
2462
|
+
.filter((m) => !m.cls || m.cls === 'byok');
|
|
2456
2463
|
const pick = models.find((m) => m.configured) || models[0];
|
|
2457
2464
|
if (pick) {
|
|
2458
2465
|
c.ctx.model = pick.id;
|
|
@@ -2496,10 +2503,18 @@ const COMMANDS = [
|
|
|
2496
2503
|
const pinned = c.ctx && c.ctx.model;
|
|
2497
2504
|
for (const m of models) {
|
|
2498
2505
|
const on = pinned === m.id;
|
|
2506
|
+
// A row from the OTHER class rides on this list on purpose — the
|
|
2507
|
+
// pooled Nexus row is what makes the byok list able to show a way
|
|
2508
|
+
// back to the pooled lane (app.js classScopedModels). It is not
|
|
2509
|
+
// pinnable here, so it says which class it runs on instead of
|
|
2510
|
+
// looking like a byok id that would 400 at the relay.
|
|
2511
|
+
const other = m.cls && m.cls !== cls;
|
|
2499
2512
|
lines.push([
|
|
2500
2513
|
span(on ? C.green : C.gray, ` ${on ? '●' : '○'} `),
|
|
2501
2514
|
span(on ? C.green : C.gray, String(m.id).padEnd(30)),
|
|
2502
|
-
span(C.gray,
|
|
2515
|
+
span(C.gray, other
|
|
2516
|
+
? `${m.note || m.label || ''} · pooled lane — /class ${m.cls}`
|
|
2517
|
+
: m.note || m.label || ''),
|
|
2503
2518
|
]);
|
|
2504
2519
|
}
|
|
2505
2520
|
lines.push('', [span(C.gray, ' pin one with /model <id> — /model alone opens the picker')]);
|
package/src/events.js
CHANGED
|
@@ -82,6 +82,12 @@ let suspended = false;
|
|
|
82
82
|
// `resetKeyStream()`'s transient state because the loop can ask for a key long
|
|
83
83
|
// after the EOF arrived. Cleared only by attaching a fresh stream.
|
|
84
84
|
let streamEnded = false;
|
|
85
|
+
// Has the interactive SESSION taken the terminal yet? Onboarding attaches a
|
|
86
|
+
// pump of its own before the session loop does (`screens.js` owns that attach
|
|
87
|
+
// and detaches it in a `finally`), so "a pump is attached" is not the same
|
|
88
|
+
// question as "a session owns these keys" — and the difference decides whether
|
|
89
|
+
// the teardown is allowed to destroy what is in the queue. See `drainQueue`.
|
|
90
|
+
let sessionStarted = false;
|
|
85
91
|
|
|
86
92
|
function isKeyStreamSuspended() {
|
|
87
93
|
return suspended;
|
|
@@ -92,7 +98,34 @@ function attachKeyStream(stdin) {
|
|
|
92
98
|
everAttached = true;
|
|
93
99
|
// A fresh stream is a fresh session: the previous one's EOF must not be
|
|
94
100
|
// inherited, or the new loop would exit on its first `nextKey()`.
|
|
95
|
-
|
|
101
|
+
//
|
|
102
|
+
// …unless this stream is ALREADY finished, which is not the exception but a
|
|
103
|
+
// routine startup state. `end`/`close` are emitted once, to whoever is
|
|
104
|
+
// listening at that instant: the startup background probe resumes and then
|
|
105
|
+
// *pauses* stdin without an end listener (`caps.probeBackground`), and
|
|
106
|
+
// onboarding attaches a pump and detaches it in a `finally`. If the pty's
|
|
107
|
+
// write end closed during either gap, the EOF was announced into an empty
|
|
108
|
+
// room — so clearing the latch here, in the one place that could re-learn the
|
|
109
|
+
// fact, strands the loop in a way the latch exists to prevent: `nextKey()`
|
|
110
|
+
// parks on a stream that will never emit again, the session promise never
|
|
111
|
+
// settles, and the teardown and the resume hint are skipped entirely.
|
|
112
|
+
//
|
|
113
|
+
// Measured on the real binary through a pty: 2 of 12 runs ended at a fully
|
|
114
|
+
// drawn 9120-byte welcome frame with NO teardown at all — no `\x1b[?1049l`,
|
|
115
|
+
// no hint — the command sent at launch (`/exit`) never seen and never
|
|
116
|
+
// resolved. `test/cli-platform-parity.test.mjs` reports that as "linux and
|
|
117
|
+
// darwin wrote different bytes", because whichever platform drew the short
|
|
118
|
+
// frame is compared against one that drew the long one. It is a race, not a
|
|
119
|
+
// platform difference, and the short frame is always the losing side.
|
|
120
|
+
//
|
|
121
|
+
// So: BELIEVE the stream's own state rather than the absence of an event. If
|
|
122
|
+
// it has already ended, keep the latch (a first-time attach that finds a
|
|
123
|
+
// finished stream must set it, not clear it). Launch keystrokes are not lost
|
|
124
|
+
// by doing so — `nextKey()` consults the queues before the latch, so input
|
|
125
|
+
// captured ahead of the session is still delivered and the loop resolves on
|
|
126
|
+
// the first call instead of after it.
|
|
127
|
+
const alreadyEnded = !!(stdin && (stdin.readableEnded === true || stdin.destroyed === true));
|
|
128
|
+
streamEnded = alreadyEnded;
|
|
96
129
|
onData = (chunk) => pushChars(String(chunk));
|
|
97
130
|
// Before the listener goes on, take anything the terminal already delivered
|
|
98
131
|
// while NOTHING owned the stream. That window is real: the startup background
|
|
@@ -403,6 +436,30 @@ function dispatch(key) {
|
|
|
403
436
|
}
|
|
404
437
|
}
|
|
405
438
|
|
|
439
|
+
/**
|
|
440
|
+
* Has the attached stream already finished?
|
|
441
|
+
*
|
|
442
|
+
* Ground truth, asked of the stream rather than remembered as an event. `end`
|
|
443
|
+
* and `close` are announced once, to whoever happens to be listening: the
|
|
444
|
+
* startup background probe resumes and pauses stdin with no end listener
|
|
445
|
+
* (`caps.probeBackground`), onboarding attaches a pump and detaches it in a
|
|
446
|
+
* `finally`, and `resume()` itself can flush a pending `end` in the window
|
|
447
|
+
* between the check in `attachKeyStream` and `attachEndHandler` going on. In any
|
|
448
|
+
* of those the EOF is announced into an empty room and the `streamEnded` latch
|
|
449
|
+
* stays false forever, so a parked `nextKey()` waits on a stream that will never
|
|
450
|
+
* speak again.
|
|
451
|
+
*
|
|
452
|
+
* That is the whole of the 9120-byte exit frame: the loop parks, the session
|
|
453
|
+
* promise never settles, and the teardown and resume hint are skipped — 2 of 12
|
|
454
|
+
* runs of the real binary through a pty, reported by the parity suite as a
|
|
455
|
+
* cross-platform byte difference because the short frame was measured against a
|
|
456
|
+
* long one. Asking the stream makes the answer independent of who was listening.
|
|
457
|
+
*/
|
|
458
|
+
function streamFinished() {
|
|
459
|
+
if (!attachedStdin) return false;
|
|
460
|
+
return attachedStdin.readableEnded === true || attachedStdin.destroyed === true;
|
|
461
|
+
}
|
|
462
|
+
|
|
406
463
|
/** The next key, waiting as long as it takes. */
|
|
407
464
|
function nextKey() {
|
|
408
465
|
if (queue.length) return Promise.resolve(queue.shift());
|
|
@@ -414,7 +471,13 @@ function nextKey() {
|
|
|
414
471
|
// that is finished and will never emit another byte. That is the hang: the
|
|
415
472
|
// session never settles, so the teardown and the resume hint are skipped and
|
|
416
473
|
// the process only ends when the event loop drains by itself.
|
|
417
|
-
|
|
474
|
+
//
|
|
475
|
+
// The latch is checked *together with* the stream's own state, because the
|
|
476
|
+
// latch can only record an event that was heard (see `streamFinished`). Order
|
|
477
|
+
// matters and is deliberate: both queues are consulted first, so a command
|
|
478
|
+
// captured at launch is still delivered and this returns it rather than the
|
|
479
|
+
// end of input.
|
|
480
|
+
if (streamEnded || streamFinished()) return Promise.resolve(STREAM_END);
|
|
418
481
|
return new Promise((resolve) => waiting.push(resolve));
|
|
419
482
|
}
|
|
420
483
|
|
|
@@ -453,9 +516,46 @@ function drainQueue() {
|
|
|
453
516
|
// Only this session's keys. `preSessionKeys` is deliberately left alone: it
|
|
454
517
|
// holds input captured before any session existed, and clearing it here is
|
|
455
518
|
// exactly the bug its comment describes.
|
|
519
|
+
//
|
|
520
|
+
// …and while no session has started, nothing in the queue is "this session's"
|
|
521
|
+
// either — it is input aimed at the session that has not begun yet, so it is
|
|
522
|
+
// moved rather than dropped. Onboarding is why: it attaches the pump *before*
|
|
523
|
+
// the session loop does, so the launch command lands in `queue` (a pump is
|
|
524
|
+
// attached, `everAttached` is true, so `dispatch` puts it there and NOT in
|
|
525
|
+
// `preSessionKeys`), and its `finally` then detaches — draining the queue and
|
|
526
|
+
// destroying the command as it goes. The session that follows has nothing to
|
|
527
|
+
// read and no EOF pending (`script` keeps the pty open until the command
|
|
528
|
+
// exits), so it parks on `nextKey()` forever: the teardown never runs, the
|
|
529
|
+
// resume hint is never printed, and the process only ends when an outer
|
|
530
|
+
// deadline kills it. Measured through a pty on the real binary, a hung run
|
|
531
|
+
// observed from inside the process showed `dataListeners=1 endListeners=3
|
|
532
|
+
// ended=false isRaw=true` — attached, raw, alive, waiting on input that had
|
|
533
|
+
// already been thrown away. That is 4 of 16 runs, and it is the entire
|
|
534
|
+
// cli-platform-parity flake: the losing run writes a 9120-byte frame with no
|
|
535
|
+
// `\x1b[?1049l` and no hint, and the suite compares it against a 9561-byte
|
|
536
|
+
// one from another platform and calls the difference a platform divergence.
|
|
537
|
+
//
|
|
538
|
+
// Order is preserved (a FIFO move, not a stack) so `/exit\r` still arrives as
|
|
539
|
+
// `/`, `e`, `x`, `i`, `t`, enter. Once the session has started, the old
|
|
540
|
+
// contract holds unchanged: typed-ahead from a dead session must not land in
|
|
541
|
+
// the next one.
|
|
542
|
+
if (!sessionStarted) {
|
|
543
|
+
while (queue.length) preSessionKeys.push(queue.shift());
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
456
546
|
queue.length = 0;
|
|
457
547
|
}
|
|
458
548
|
|
|
549
|
+
/**
|
|
550
|
+
* The interactive session has taken the terminal: from here on the queue
|
|
551
|
+
* belongs to it, and `drainQueue()` may destroy what it holds. Called by the
|
|
552
|
+
* session loop immediately before it attaches (`chatflow.js`), never by a
|
|
553
|
+
* transient screen pump.
|
|
554
|
+
*/
|
|
555
|
+
function markSessionStart() {
|
|
556
|
+
sessionStarted = true;
|
|
557
|
+
}
|
|
558
|
+
|
|
459
559
|
/** Test seam: forget attached stdin, timers and queued keys. */
|
|
460
560
|
/** True once a key stream is attached — i.e. whether nextKey() has a source. */
|
|
461
561
|
function isKeyStreamAttached() {
|
|
@@ -539,5 +639,6 @@ module.exports = {
|
|
|
539
639
|
nextKeyTimeout,
|
|
540
640
|
requeueKeys,
|
|
541
641
|
drainQueue,
|
|
642
|
+
markSessionStart,
|
|
542
643
|
resetKeyStream,
|
|
543
644
|
};
|
package/src/screen.js
CHANGED
|
@@ -216,7 +216,31 @@ function leaveAltScreen() {
|
|
|
216
216
|
if (!inAlt) return;
|
|
217
217
|
inAlt = false;
|
|
218
218
|
process.stdout.write('\x1b[?1049l');
|
|
219
|
+
flushExitNotice();
|
|
219
220
|
}
|
|
221
|
+
|
|
222
|
+
// ── exit notice: text that must land OUTSIDE the alternate screen ───────────
|
|
223
|
+
// The resume hint is written on the way out, and its *position* is the whole
|
|
224
|
+
// contract: written inside the screen, the restore that follows paints over it
|
|
225
|
+
// and the user is told nothing. Ordering cannot deliver that guarantee here —
|
|
226
|
+
// the teardown is reachable from three places (the session loop's `finally`,
|
|
227
|
+
// the session's `process.once('exit')` handler, and the entrypoint's own exit
|
|
228
|
+
// handler) and which one runs first varies with timing, which showed up as the
|
|
229
|
+
// same 81 bytes in two positions across runs and platforms. So the notice is
|
|
230
|
+
// not *scheduled* next to the restore; it is emitted *by* the restore, cleared
|
|
231
|
+
// as it goes, which makes "outside the screen" true by construction and lets
|
|
232
|
+
// only one of the paths ever produce it.
|
|
233
|
+
let exitNotice = null;
|
|
234
|
+
function queueExitNotice(text) {
|
|
235
|
+
exitNotice = text;
|
|
236
|
+
}
|
|
237
|
+
function flushExitNotice() {
|
|
238
|
+
if (exitNotice === null) return;
|
|
239
|
+
const text = exitNotice;
|
|
240
|
+
exitNotice = null;
|
|
241
|
+
process.stdout.write(text);
|
|
242
|
+
}
|
|
243
|
+
const hasExitNotice = () => exitNotice !== null;
|
|
220
244
|
const isAltScreen = () => inAlt;
|
|
221
245
|
|
|
222
246
|
// Bracketed paste (DEC 2004): a paste arrives as one \x1b[200~ … \x1b[201~
|
|
@@ -436,6 +460,9 @@ class LiveRegion {
|
|
|
436
460
|
}
|
|
437
461
|
|
|
438
462
|
module.exports = {
|
|
463
|
+
queueExitNotice,
|
|
464
|
+
flushExitNotice,
|
|
465
|
+
hasExitNotice,
|
|
439
466
|
// plain-string width helpers (kept for the string renderers + app/bin)
|
|
440
467
|
w,
|
|
441
468
|
clip,
|
|
@@ -35,6 +35,32 @@
|
|
|
35
35
|
/** Every id the server uses for the pooled brain, canonical spelling first. */
|
|
36
36
|
const NEXUS_BRAIN_IDS = Object.freeze(['nexus-brain', 'aegis-brain']);
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Every id the AEGIS Cloud (aegiscloud) lane serves that is NOT a per-provider
|
|
40
|
+
* id: the pooled brain and the `-smart`/`-neo` tier spellings the server sends
|
|
41
|
+
* as aliases of it. Verified against the live catalog 2026-09-30 —
|
|
42
|
+
* `GET /api/v1/models` answers exactly `deepseek`, `nexus-brain`, `aegis-brain`,
|
|
43
|
+
* `nexus-brain-smart`, `aegis-brain-smart`, `nexus-brain-neo`, `aegis-brain-neo`.
|
|
44
|
+
*
|
|
45
|
+
* A host that must not OFFER the aegiscloud lane needs this list rather than a
|
|
46
|
+
* bare `NEXUS_BRAIN_IDS` check: four of the six spellings are not in that array,
|
|
47
|
+
* and a filter written against it alone would leave `nexus-brain-neo` on screen
|
|
48
|
+
* — the "five spellings of one brain" defect again, one host at a time. The
|
|
49
|
+
* spelling is kept here, next to the ids, because this module is the one place
|
|
50
|
+
* both hosts already agree about what the pooled lane is called.
|
|
51
|
+
*/
|
|
52
|
+
const AEGIS_CLOUD_MODEL_IDS = Object.freeze([
|
|
53
|
+
'nexus-brain',
|
|
54
|
+
'aegis-brain',
|
|
55
|
+
'nexus-brain-smart',
|
|
56
|
+
'aegis-brain-smart',
|
|
57
|
+
'nexus-brain-neo',
|
|
58
|
+
'aegis-brain-neo',
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
/** The tier-family shape, for a spelling the server adds after this release. */
|
|
62
|
+
const AEGIS_CLOUD_MODEL_RE = /^(?:nexus|aegis)-brain(?:-(?:smart|neo))?$/;
|
|
63
|
+
|
|
38
64
|
/** The name users see for the collapsed entry. */
|
|
39
65
|
const NEXUS_LABEL = 'Nexus';
|
|
40
66
|
|
|
@@ -105,6 +131,54 @@ function filterAegisCatalog(models) {
|
|
|
105
131
|
return [{ ...rest, label: NEXUS_LABEL }];
|
|
106
132
|
}
|
|
107
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Whether an entry is a model of the AEGIS CLOUD (aegiscloud) lane — the pooled
|
|
136
|
+
* brain under any of its spellings, whether it is the canonical id, a
|
|
137
|
+
* `-smart`/`-neo` tier, or a row that aliases the brain (`alias_of` in the
|
|
138
|
+
* relay's shape, `aliasOf` in the CLI's).
|
|
139
|
+
*
|
|
140
|
+
* Accepts an id string or an entry object, like the rest of this module.
|
|
141
|
+
*
|
|
142
|
+
* @param {string|object} entry
|
|
143
|
+
* @returns {boolean}
|
|
144
|
+
*/
|
|
145
|
+
function isAegisCloudModel(entry) {
|
|
146
|
+
const id = typeof entry === 'string'
|
|
147
|
+
? entry.trim()
|
|
148
|
+
: entry && typeof entry === 'object' && typeof entry.id === 'string'
|
|
149
|
+
? entry.id.trim()
|
|
150
|
+
: '';
|
|
151
|
+
if (AEGIS_CLOUD_MODEL_IDS.includes(id)) return true;
|
|
152
|
+
if (AEGIS_CLOUD_MODEL_RE.test(id)) return true;
|
|
153
|
+
return NEXUS_BRAIN_IDS.includes(aliasOfEntry(entry));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The same list with the AEGIS Cloud (aegiscloud) models omitted.
|
|
158
|
+
*
|
|
159
|
+
* A host that keeps the cloud lane's *credential* (the account key BYOK billing
|
|
160
|
+
* rides on) without offering its *models* needs a filter that is one rule and
|
|
161
|
+
* survives a renamed tier — which is why this is here and not a regex spelled
|
|
162
|
+
* again inside a host: a second copy is how this repo's two clients came to show
|
|
163
|
+
* one account two different model lists in the first place.
|
|
164
|
+
*
|
|
165
|
+
* Pure and non-mutating; a non-array yields `[]`, and an entry with no usable id
|
|
166
|
+
* is dropped rather than passed through, because "a row we cannot name" is not a
|
|
167
|
+
* row a picker may paint.
|
|
168
|
+
*
|
|
169
|
+
* @param {Array<object|string>} models
|
|
170
|
+
* @returns {Array} a new array, order preserved
|
|
171
|
+
*/
|
|
172
|
+
function omitAegisCloudModels(models) {
|
|
173
|
+
const list = Array.isArray(models) ? models : [];
|
|
174
|
+
return list.filter((m) => {
|
|
175
|
+
if (!m) return false;
|
|
176
|
+
if (typeof m === 'string') return !isAegisCloudModel(m);
|
|
177
|
+
const id = typeof m.id === 'string' ? m.id.trim() : '';
|
|
178
|
+
return Boolean(id) && !isAegisCloudModel(m);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
108
182
|
/**
|
|
109
183
|
* The Aegis-class catalog as a host must OFFER it: the FULL list the server
|
|
110
184
|
* advertises — the pooled brain first, under its one name, then every other
|
|
@@ -182,6 +256,9 @@ function offerableCatalog(models) {
|
|
|
182
256
|
module.exports = {
|
|
183
257
|
NEXUS_BRAIN_IDS,
|
|
184
258
|
NEXUS_LABEL,
|
|
259
|
+
AEGIS_CLOUD_MODEL_IDS,
|
|
260
|
+
isAegisCloudModel,
|
|
261
|
+
omitAegisCloudModels,
|
|
185
262
|
selectBrainEntry,
|
|
186
263
|
filterAegisCatalog,
|
|
187
264
|
offerableCatalog,
|
|
@@ -507,7 +507,14 @@ function upsertEnvText(text, name, value) {
|
|
|
507
507
|
// blank line to a file that ended cleanly.
|
|
508
508
|
const hadFinalNewline = src === '' ? true : src.endsWith('\n');
|
|
509
509
|
const trailingBlank = src === '' ? false : src.split('\n').slice(-1)[0] === '';
|
|
510
|
-
|
|
510
|
+
// An EMPTY file is zero lines, not one empty line: `''.split('\n')` is `['']`,
|
|
511
|
+
// and that stray element survives to `out` because the pop above only fires
|
|
512
|
+
// when `trailingBlank` is true (forced false for an empty source). The result
|
|
513
|
+
// was a first-ever write that opened the file with a leading blank line —
|
|
514
|
+
// `'\nNAME=secret\n'` — breaking the contract the comment two lines up
|
|
515
|
+
// states and the round-trip guarantee below. The common case is exactly this
|
|
516
|
+
// one: a fresh ~/.aegiscode/.env on a new machine.
|
|
517
|
+
const lines = src === '' ? [] : src.split('\n');
|
|
511
518
|
if (trailingBlank) lines.pop();
|
|
512
519
|
|
|
513
520
|
const re = new RegExp(`^(\\s*(?:export\\s+)?)${name}\\s*=`);
|
|
@@ -656,7 +663,11 @@ function removeEnvText(text, name) {
|
|
|
656
663
|
const src = String(text == null ? '' : text);
|
|
657
664
|
const hadFinalNewline = src === '' ? true : src.endsWith('\n');
|
|
658
665
|
const trailingBlank = src === '' ? false : src.split('\n').slice(-1)[0] === '';
|
|
659
|
-
|
|
666
|
+
// Zero lines for an empty source — see upsertEnvText. Here it is defensive
|
|
667
|
+
// rather than observable (a remover on an empty file writes nothing either
|
|
668
|
+
// way), but the two functions must split identically or a later change to one
|
|
669
|
+
// starts disagreeing with the other about what a line is.
|
|
670
|
+
const lines = src === '' ? [] : src.split('\n');
|
|
660
671
|
if (trailingBlank) lines.pop();
|
|
661
672
|
|
|
662
673
|
// Same definition matcher as upsertEnvText, so the two can never disagree
|
|
@@ -305,28 +305,37 @@ function normalizeCatalog(models) {
|
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
/**
|
|
308
|
-
* The Aegis Cloud (pooled) dropdown
|
|
308
|
+
* The Aegis Cloud (pooled) dropdown.
|
|
309
309
|
*
|
|
310
|
-
* The catalog (`/api/v1/models`) lists
|
|
311
|
-
* `anthropic`, `groq`, `openai`, ...) alongside
|
|
312
|
-
* spellings (`{aegis,nexus}-brain[-smart|-neo]`) that all
|
|
313
|
-
* worker pool
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
310
|
+
* It offers NO aegiscloud model. The catalog (`/api/v1/models`) lists
|
|
311
|
+
* per-provider ids (`deepseek`, `anthropic`, `groq`, `openai`, ...) alongside
|
|
312
|
+
* five pooled-brain tier spellings (`{aegis,nexus}-brain[-smart|-neo]`) that all
|
|
313
|
+
* route the same worker pool, and this host must offer neither: "omit the
|
|
314
|
+
* aegiscloud models" is the instruction, and a host that omitted the brain row
|
|
315
|
+
* while leaving `deepseek` on screen would have kept exactly the per-provider
|
|
316
|
+
* pin the Aegis Cloud policy is about. The class stays selectable and its
|
|
317
|
+
* dropdown keeps the "server default (auto)" row, so the pooled lane still runs
|
|
318
|
+
* — it just advertises nothing to pin.
|
|
318
319
|
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
320
|
+
* What is NOT changed: the account key, and everything the key is *for* — the
|
|
321
|
+
* pooled turn itself, cloud memory sync, and the BYOK handling fee that is
|
|
322
|
+
* billed to this account (see the byok branch below, which still offers every
|
|
323
|
+
* provider id the server's catalog names). Omitting a model list is not
|
|
324
|
+
* disconnecting the lane.
|
|
325
|
+
*
|
|
326
|
+
* The omission itself is one shared rule (`omitAegisCloudModels`, and the
|
|
327
|
+
* collapse it is composed with) in `client/brain-catalog.js`, shared with the
|
|
328
|
+
* CLI: two copies is how this host and the terminal previously came to offer
|
|
329
|
+
* the same account two different model lists. Resolved the two ways this repo
|
|
326
330
|
* resolves every shared module — repo-relative in a checkout, and this app's
|
|
327
331
|
* staged vendor/ tree.
|
|
332
|
+
*
|
|
333
|
+
* `filterAegisCatalog` is kept in the composition rather than dropped for the
|
|
334
|
+
* shorter `models: []`: a payload with no brain tier at all (a self-hosted or
|
|
335
|
+
* trimmed deployment) must still yield nothing here rather than leaking its
|
|
336
|
+
* per-provider ids, and that is precisely the case the collapse already answers.
|
|
328
337
|
*/
|
|
329
|
-
const { filterAegisCatalog } = requireSharedBrain();
|
|
338
|
+
const { filterAegisCatalog, omitAegisCloudModels } = requireSharedBrain();
|
|
330
339
|
|
|
331
340
|
/**
|
|
332
341
|
* The BYOK additions, applied to the server's provider catalog below. Same
|
|
@@ -846,7 +855,21 @@ function createLocalEngine({
|
|
|
846
855
|
// entry so the class is usable the moment a key lands.
|
|
847
856
|
if (!aegis.apiKey) return { class: cls, models: [], needsKey: true };
|
|
848
857
|
const data = await aegis.listModels();
|
|
849
|
-
|
|
858
|
+
// No aegiscloud model is offered — see the rule above. The class, the
|
|
859
|
+
// auto row and the pooled turn are untouched; only the pinnable list is
|
|
860
|
+
// emptied, which is why `needsKey` keeps its meaning and the renderer's
|
|
861
|
+
// hint for this class is unchanged.
|
|
862
|
+
return {
|
|
863
|
+
class: cls,
|
|
864
|
+
// Omit FIRST, then collapse: the omission has to see the payload's own
|
|
865
|
+
// `alias_of` bookkeeping, which the collapse deliberately strips (a
|
|
866
|
+
// collapsed row IS the selection, so a renderer must not filter it back
|
|
867
|
+
// out as a hidden alias). Filtering a collapsed row instead would leave
|
|
868
|
+
// a renamed tier — `nexus-brain-v2`, an alias OF the brain under a
|
|
869
|
+
// spelling this release has never seen — on screen, which is the one
|
|
870
|
+
// case the rule exists to catch.
|
|
871
|
+
models: filterAegisCatalog(omitAegisCloudModels(normalizeCatalog(data && data.models))),
|
|
872
|
+
};
|
|
850
873
|
}
|
|
851
874
|
if (cls === 'byok') {
|
|
852
875
|
// The server's catalog names every provider it accepts a key for, the
|