aegiscode 6.8.11 → 6.8.12
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/README.md +46 -13
- package/bin/aegiscode.js +92 -2
- package/package.json +2 -2
- package/scripts/predist.mjs +25 -0
- package/src/app.js +75 -3
- package/src/caps.js +325 -1
- package/src/cloudsync.js +51 -7
- package/src/commands.js +51 -4
- package/src/events.js +24 -0
- package/src/fingerprint.js +559 -0
- package/src/panels.js +1 -1
- package/src/presence.js +235 -0
- package/src/screens.js +11 -4
- package/src/theme.js +126 -6
- package/vendor/client/aegis.js +180 -18
- package/vendor/client/attest.js +439 -0
- package/vendor/client/authorship-key.js +366 -0
- package/vendor/client/device-fingerprint.js +85 -3
- package/vendor/client/fingerprint.js +1061 -0
- package/vendor/client/presence-constants.js +104 -0
- package/vendor/client/presence.js +435 -0
- package/vendor/client/record-vault.js +834 -0
- package/vendor/client/touch.js +455 -0
- package/vendor/desktop/lib/local/autonomous.js +1 -0
- package/vendor/desktop/lib/local/prompt.js +6 -0
- package/vendor/desktop/lib/settings.js +154 -1
package/README.md
CHANGED
|
@@ -155,27 +155,60 @@ Only a **legacy** Windows console degrades — and it says why:
|
|
|
155
155
|
|
|
156
156
|
| host | mark | star | colour | reason |
|
|
157
157
|
| --- | --- | --- | --- | --- |
|
|
158
|
-
|
|
|
159
|
-
| win32
|
|
160
|
-
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
158
|
+
| any host, no override | `unicode` | `native` | truecolor | uniform default: nothing about the host is inferred |
|
|
159
|
+
| win32 legacy conhost | `ascii` | `narrow` | 16 | reported by `--terminal`; set `AEGIS_ART=ascii` to act on it |
|
|
160
|
+
| …requested | `ascii` | `narrow` | 16 | `AEGIS_ART=ascii` / `--ascii` |
|
|
161
|
+
|
|
162
|
+
The rendering is **uniform**: `process.platform`, `TERM`, `TERM_PROGRAM`,
|
|
163
|
+
`WT_SESSION` and the locale's character set are probed and reported
|
|
164
|
+
(`aegiscode --terminal`) but never change a byte that is drawn, because a font
|
|
165
|
+
that lacks a glyph is something only the person looking at the screen can
|
|
166
|
+
settle. Only an explicit switch changes the output, and every switch is spelled
|
|
167
|
+
the same way on every platform.
|
|
168
|
+
|
|
169
|
+
The one thing read from the terminal about *itself* is its background
|
|
170
|
+
brightness, and it is used for one decision only: which of the two legible
|
|
171
|
+
palettes `/theme`'s **Auto (match terminal)** row resolves to. The dark
|
|
172
|
+
palette's body text is white, so on a light terminal the wrong answer is an
|
|
173
|
+
invisible one — and the failure is symmetric: the *light* palette's body text is
|
|
174
|
+
near-black, so restoring it on a dark terminal is invisible too.
|
|
175
|
+
|
|
176
|
+
At startup, on a real terminal, `aegiscode` **asks** — an OSC 11 query
|
|
177
|
+
(`ESC ] 11 ; ? BEL`) that the terminal answers with its own background, e.g.
|
|
178
|
+
`rgb:1e1e/1e1e/2e2e`. That is the only signal that is neither an environment
|
|
179
|
+
variable nor a guess, and it is the one that matters: Alacritty, for instance,
|
|
180
|
+
sets no `COLORFGBG` and no `TERM_BACKGROUND`, so the palette used to be chosen
|
|
181
|
+
from silence. The environment is still read first and wins when set —
|
|
182
|
+
`COLORFGBG` (the background's ANSI index, as xterm, rxvt, Konsole and VTE
|
|
183
|
+
report it), `TERM_BACKGROUND=dark|light` (kitty, WezTerm), or
|
|
184
|
+
`AEGIS_BACKGROUND=dark|light` — and in that case nothing is asked at all. A
|
|
185
|
+
pipe, a CI run and `--print` never probe.
|
|
186
|
+
|
|
187
|
+
What the answer is *for*: a stored `/theme` row that cannot be read on the
|
|
188
|
+
terminal it is being restored on is corrected to the same palette family at the
|
|
189
|
+
other brightness (so "colorblind-friendly" survives, and the light/dark choice
|
|
190
|
+
inside it changes), saved, and announced once. A terminal that reports nothing
|
|
191
|
+
changes nothing — the dark default is not evidence, so a preference is never
|
|
192
|
+
overridden on the strength of it. `/terminal probe` asks again mid-session (for
|
|
193
|
+
a terminal whose theme changed after launch), and `/terminal background
|
|
194
|
+
dark|light` pins it outright without asking. None of this ever moves the mark,
|
|
195
|
+
the colour depth, the control sequences or the line ending.
|
|
167
196
|
|
|
168
197
|
Overrides, at launch — `--ascii`, `--unicode`, `--no-color`, `--color`,
|
|
169
198
|
`--width <cols>`, `--terminal` (print the report) — and in-session via
|
|
170
|
-
`/terminal ascii|unicode|color|no-color|star <native|narrow>|width <cols>|auto|status`.
|
|
199
|
+
`/terminal ascii|unicode|color|no-color|background <dark|light>|probe|star <native|narrow>|width <cols>|auto|status`.
|
|
171
200
|
`/terminal auto` re-probes rather than restoring launch flags. `/terminal width`
|
|
172
201
|
pins the frame, so resizes are ignored until `/terminal auto`; every other
|
|
173
|
-
`/terminal` switch leaves resize handling intact
|
|
202
|
+
`/terminal` switch leaves resize handling intact — the background probe is
|
|
203
|
+
deliberately not routed through the code path that pins a frame, so asking about
|
|
204
|
+
the background can never freeze the width.
|
|
174
205
|
|
|
175
206
|
The same axes are settable by environment for scripts and CI: `AEGIS_ART`,
|
|
176
207
|
`AEGIS_ASCII`, `AEGIS_UNICODE`, `AEGIS_STAR`, `AEGIS_COLOR`, `AEGIS_VT`,
|
|
177
|
-
`AEGIS_WIDTH`, `AEGIS_WIDE_RUNES
|
|
178
|
-
|
|
208
|
+
`AEGIS_WIDTH`, `AEGIS_WIDE_RUNES`, `AEGIS_BACKGROUND` (and `TERM_BACKGROUND`,
|
|
209
|
+
which the terminals that set it write themselves), plus `AEGIS_BACKGROUND_PROBE=0`
|
|
210
|
+
to skip the query while still honouring those variables. `NO_COLOR` is honoured
|
|
211
|
+
to the letter — "present and not an empty string, regardless of its value".
|
|
179
212
|
|
|
180
213
|
## First run
|
|
181
214
|
|
package/bin/aegiscode.js
CHANGED
|
@@ -50,6 +50,17 @@ Automation:
|
|
|
50
50
|
take a base URL but speak no MCP
|
|
51
51
|
aegiscode mcp help all subcommands and their flags
|
|
52
52
|
|
|
53
|
+
Attestation (φ(α) — a sealed record of what a session was):
|
|
54
|
+
aegiscode fingerprint status which authorship key is in use, and where
|
|
55
|
+
aegiscode fingerprint keygen mint a private key (0600, never printed)
|
|
56
|
+
aegiscode fingerprint mint seal the last session as a record
|
|
57
|
+
aegiscode fingerprint verify <file> recompute a record's attestation
|
|
58
|
+
aegiscode fingerprint backup --to DIR copy the key somewhere safe
|
|
59
|
+
aegiscode fingerprint publish [<file>] publish a record, link the copy
|
|
60
|
+
aegiscode fingerprint anchor <file> is the published copy still ours?
|
|
61
|
+
aegiscode fingerprint vault --audit what is in the vault, and is a key in it
|
|
62
|
+
aegiscode fingerprint help all subcommands and their flags
|
|
63
|
+
|
|
53
64
|
Options:
|
|
54
65
|
-m, --model <id> pin a model id (see /models; default: server choice)
|
|
55
66
|
--base <url> API base (default $AEGIS_API_BASE or aegiscloud.org)
|
|
@@ -142,6 +153,17 @@ function parseArgs(argv) {
|
|
|
142
153
|
opts.commandArg = sub;
|
|
143
154
|
opts.commandArgv = argv.slice(argv[1] && !argv[1].startsWith('-') ? 2 : 1);
|
|
144
155
|
argv = [];
|
|
156
|
+
} else if (head === 'fingerprint') {
|
|
157
|
+
// Same position-0 rule and the same reason as `mcp`/`autonomous`: the tail
|
|
158
|
+
// belongs to the subcommand (`--secret-file`, `--code-root`, `--force` are
|
|
159
|
+
// not this parser's flags), so it is handed over verbatim. A bare
|
|
160
|
+
// `fingerprint` is the status report — "is a key configured here?" is the
|
|
161
|
+
// question a user has — not a prompt and not an error.
|
|
162
|
+
const sub = argv[1] && !argv[1].startsWith('-') ? argv[1] : 'status';
|
|
163
|
+
opts.command = 'fingerprint';
|
|
164
|
+
opts.commandArg = sub;
|
|
165
|
+
opts.commandArgv = argv.slice(argv[1] && !argv[1].startsWith('-') ? 2 : 1);
|
|
166
|
+
argv = [];
|
|
145
167
|
}
|
|
146
168
|
|
|
147
169
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -446,7 +468,7 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
446
468
|
const key = rows.reduce((m, [k]) => Math.max(m, k.length), 0);
|
|
447
469
|
process.stdout.write(`aegiscode ${pkg.version} — terminal capabilities\n\n`);
|
|
448
470
|
for (const [k, v] of rows) process.stdout.write(` ${k.padEnd(key)} ${v}\n`);
|
|
449
|
-
process.stdout.write('\nOverride with --ascii / --color / --width, or AEGIS_ART,\nAEGIS_STAR, AEGIS_COLOR,
|
|
471
|
+
process.stdout.write('\nOverride with --ascii / --color / --light / --width, or AEGIS_ART,\nAEGIS_STAR, AEGIS_COLOR, AEGIS_BACKGROUND, AEGIS_BACKGROUND_PROBE, AEGIS_VT,\nAEGIS_WIDTH (see README).\n');
|
|
450
472
|
return 0;
|
|
451
473
|
}
|
|
452
474
|
|
|
@@ -458,6 +480,19 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
458
480
|
// Account subcommands run before a session is built: they are one-shot,
|
|
459
481
|
// non-interactive, and must work in a script (`aegiscode login "$KEY"`) as
|
|
460
482
|
// well as at a prompt.
|
|
483
|
+
// φ(α): the authorship key and the sealed session records. Dispatched here
|
|
484
|
+
// rather than in the account set because its subcommands own their flags —
|
|
485
|
+
// and before a session is built, because `fingerprint mint` must work with no
|
|
486
|
+
// terminal at all (a CI job sealing what it just ran), exactly like the queue.
|
|
487
|
+
if (opts.command === 'fingerprint') {
|
|
488
|
+
const { runFingerprint } = require('../src/fingerprint.js');
|
|
489
|
+
return runFingerprint(opts.commandArg || 'status', opts.commandArgv || [], {
|
|
490
|
+
json: opts.json,
|
|
491
|
+
stdout: process.stdout,
|
|
492
|
+
stderr: process.stderr,
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
|
|
461
496
|
if (ACCOUNT_COMMANDS.has(opts.command)) {
|
|
462
497
|
return runAccountCommand(opts.command, opts.commandArg, {
|
|
463
498
|
json: opts.json,
|
|
@@ -477,6 +512,22 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
477
512
|
// (0 done, 1 a task failed / another drain holds the lock, 2 usage or no
|
|
478
513
|
// credential) — never the interactive chat path's "no terminal and no prompt".
|
|
479
514
|
if (opts.command === 'autonomous') {
|
|
515
|
+
// A drain IS the thing the presence panel exists to show: a machine working
|
|
516
|
+
// through a queue with no terminal open. So this path beacons too — with
|
|
517
|
+
// `autonomous: true` and the live pending depth — and it beacons BEFORE the
|
|
518
|
+
// lock is taken, so a drain that exits immediately because another process
|
|
519
|
+
// holds the lock still registers as "this machine is here".
|
|
520
|
+
const presence = require('../src/presence.js');
|
|
521
|
+
const credentials = require('../src/credentials.js');
|
|
522
|
+
presence.start({
|
|
523
|
+
credentials,
|
|
524
|
+
autonomous: true,
|
|
525
|
+
queueDepth: presence.queueDepthReader(),
|
|
526
|
+
});
|
|
527
|
+
// The beacon's timer is unref'd, so nothing here holds the process open;
|
|
528
|
+
// this just cancels a scheduled beat that would otherwise fire mid-teardown.
|
|
529
|
+
process.once('exit', () => presence.stop());
|
|
530
|
+
|
|
480
531
|
const { runQueueCommand } = require('../src/autonomous.js');
|
|
481
532
|
return runQueueCommand(opts.commandArg, opts.commandArgv || [], {
|
|
482
533
|
json: opts.json,
|
|
@@ -504,6 +555,31 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
504
555
|
|
|
505
556
|
const { createApp } = require('../src/app.js');
|
|
506
557
|
|
|
558
|
+
// ── presence beacon (aegis1 /api/v1/heartbeat) ───────────────────────────
|
|
559
|
+
//
|
|
560
|
+
// "Who is running aegiscode right now" — the admin panel's presence card.
|
|
561
|
+
// Started for every SESSION, not for the account/lifecycle subcommands above
|
|
562
|
+
// (`login`, `key status`, `--version`, `mcp install` are things a user does
|
|
563
|
+
// once, not a machine being present).
|
|
564
|
+
//
|
|
565
|
+
// Keyed on the credential store's own resolution (env → credentials.json →
|
|
566
|
+
// config.json) so the beacon carries the key this session will actually use,
|
|
567
|
+
// and on the machine fingerprint (client/presence.js) so one laptop is one
|
|
568
|
+
// machine in the panel rather than one row per launch. No key ⇒ presence.js
|
|
569
|
+
// returns an inert store: no timer, no request, no 401 loop.
|
|
570
|
+
//
|
|
571
|
+
// Never fatal: `start()` swallows a load failure and returns an inert store,
|
|
572
|
+
// because a beacon is diagnostic and a session is not.
|
|
573
|
+
const presence = require('../src/presence.js');
|
|
574
|
+
presence.start({
|
|
575
|
+
credentials: require('../src/credentials.js'),
|
|
576
|
+
queueDepth: presence.queueDepthReader(),
|
|
577
|
+
});
|
|
578
|
+
// Every return path below ends the process, and the beacon's timer is
|
|
579
|
+
// unref'd, so this is tidiness rather than a requirement — but it means a
|
|
580
|
+
// quit never races a beat.
|
|
581
|
+
process.once('exit', () => presence.stop());
|
|
582
|
+
|
|
507
583
|
let prompt = opts.prompt;
|
|
508
584
|
if (prompt === '-') {
|
|
509
585
|
if (process.stdin.isTTY) {
|
|
@@ -546,7 +622,21 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
546
622
|
|
|
547
623
|
if (require.main === module) {
|
|
548
624
|
main()
|
|
549
|
-
.then((code) =>
|
|
625
|
+
.then(async (code) => {
|
|
626
|
+
// Before this process exits, let an in-flight presence beat finish. A
|
|
627
|
+
// one-shot run reaches this line in tens of milliseconds, and
|
|
628
|
+
// `process.exit()` would otherwise kill the beacon's first request
|
|
629
|
+
// mid-flight — the machine would run a whole command and still never
|
|
630
|
+
// appear in the admin panel. Bounded (1.5 s) so the beacon can never be
|
|
631
|
+
// the reason a CLI hangs; `flush()` is a no-op when nothing is in flight
|
|
632
|
+
// or when the beacon is off.
|
|
633
|
+
try {
|
|
634
|
+
await require('../src/presence.js').flush();
|
|
635
|
+
} catch {
|
|
636
|
+
/* a beacon must never affect the exit code */
|
|
637
|
+
}
|
|
638
|
+
process.exit(code || 0);
|
|
639
|
+
})
|
|
550
640
|
.catch((e) => {
|
|
551
641
|
process.stderr.write(`aegiscode: ${e && e.message ? e.message : e}\n`);
|
|
552
642
|
process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aegiscode",
|
|
3
3
|
"productName": "AEGIS Code",
|
|
4
|
-
"version": "6.8.
|
|
4
|
+
"version": "6.8.12",
|
|
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",
|
|
8
8
|
"email": "nborneklint@gmail.com"
|
|
9
9
|
},
|
|
10
|
-
"license": "
|
|
10
|
+
"license": "AGPL-3.0-or-later",
|
|
11
11
|
"homepage": "https://aegiscloud.org",
|
|
12
12
|
"bin": {
|
|
13
13
|
"aegiscode": "bin/aegiscode.js"
|
package/scripts/predist.mjs
CHANGED
|
@@ -55,6 +55,31 @@ const FILES = [
|
|
|
55
55
|
// for the same account on the same machine.
|
|
56
56
|
'client/auto-provision.js',
|
|
57
57
|
'client/device-fingerprint.js',
|
|
58
|
+
// The presence beacon (src/presence.js, started by bin/aegiscode.js) — the
|
|
59
|
+
// client half of the aegis1 route /api/v1/heartbeat. presence.js requires
|
|
60
|
+
// presence-constants.js and device-fingerprint.js from the same directory, so
|
|
61
|
+
// the three stay in one vendor tree; a package built without them loses the
|
|
62
|
+
// beacon silently (src/presence.js turns a load failure into an inert store),
|
|
63
|
+
// which is exactly the kind of missing-row bug no error message reports.
|
|
64
|
+
'client/presence.js',
|
|
65
|
+
'client/presence-constants.js',
|
|
66
|
+
// φ(α): the authorship key, the sealed session record and the vendored
|
|
67
|
+
// digest module they are built on. src/fingerprint.js resolves all three
|
|
68
|
+
// through resolveClientModule, and they require each other by same-directory
|
|
69
|
+
// relative paths (fingerprint.js -> ./touch.js, attest.js -> ./fingerprint.js
|
|
70
|
+
// and ./authorship-key.js), so all four must land in one vendor tree. A
|
|
71
|
+
// package missing them would fail the fingerprint subcommand at load — loud,
|
|
72
|
+
// but only for the user who tried it.
|
|
73
|
+
'client/touch.js',
|
|
74
|
+
'client/fingerprint.js',
|
|
75
|
+
'client/authorship-key.js',
|
|
76
|
+
'client/attest.js',
|
|
77
|
+
// The vault: where a sealed record travels so it can be looked at from
|
|
78
|
+
// anywhere, and the module that refuses to send the key with it (a secret in
|
|
79
|
+
// cloud storage can mint records that impersonate the owner). src/fingerprint.js
|
|
80
|
+
// resolves it through resolveClientModule, so a package staged without it
|
|
81
|
+
// loses `fingerprint publish|anchor|vault` at load with MODULE_NOT_FOUND.
|
|
82
|
+
'client/record-vault.js',
|
|
58
83
|
// The pooled-brain selection rule: which single entry stands for the Aegis
|
|
59
84
|
// class. Required at load time by src/models.js (through src/sharedpaths.js),
|
|
60
85
|
// which the picker, /model and the OpenAI-compatible shim all build their
|
package/src/app.js
CHANGED
|
@@ -23,7 +23,8 @@ const os = require('node:os');
|
|
|
23
23
|
const { randomUUID } = require('node:crypto');
|
|
24
24
|
const { createTools, createClient, usageTokens, usageBuckets, buildSystemPrompt, autoProvisionApiKey } = require('./deps.js');
|
|
25
25
|
const { createEngine, HOST_CLASSES, DEFAULT_CLASS, byokNamespace } = require('./engine.js');
|
|
26
|
-
const { GLYPH, VERBS, themeOf, RESET, THEME_TABLE } = require('./theme.js');
|
|
26
|
+
const { GLYPH, VERBS, themeOf, RESET, THEME_TABLE, AUTO_THEME_INDEX, themeIsLight, reconcileThemeIndex } = require('./theme.js');
|
|
27
|
+
const { probeTerminalBackground } = require('./caps.js');
|
|
27
28
|
const { LiveRegion, termWidth, w } = require('./screen.js');
|
|
28
29
|
const { editPreview } = require('./diff.js');
|
|
29
30
|
const { defaultOpen } = require('./diffview.js');
|
|
@@ -38,6 +39,9 @@ const {
|
|
|
38
39
|
setMemoryPersist,
|
|
39
40
|
} = require('./config.js');
|
|
40
41
|
const credentials = require('./credentials.js');
|
|
42
|
+
// The key pump, so the startup background query can hand back a keystroke that
|
|
43
|
+
// raced its answer (see the `probeTerminalBackground` call in `runInteractive`).
|
|
44
|
+
const events = require('./events.js');
|
|
41
45
|
const cloudsync = require('./cloudsync.js');
|
|
42
46
|
const { readSecret } = require('./secret.js');
|
|
43
47
|
const { normalizeModelCatalog, pickerEntries, catalogIds } = require('./models.js');
|
|
@@ -208,13 +212,23 @@ function createApp(options = {}) {
|
|
|
208
212
|
// choice is deliberately NOT persisted — a flag that meters every turn must
|
|
209
213
|
// not survive into a session where nobody asked for it.
|
|
210
214
|
recallDeep: false,
|
|
211
|
-
|
|
215
|
+
// "Auto (match terminal)" is the default row, not "Dark mode": the row's
|
|
216
|
+
// whole purpose is that it resolves against the terminal's reported
|
|
217
|
+
// background, and leaving the default on explicit Dark drew the dark
|
|
218
|
+
// palette's white body text over a light terminal — an invisible UI — for
|
|
219
|
+
// every user who never opened the picker.
|
|
220
|
+
themeIndex: opts.light ? 2 : AUTO_THEME_INDEX,
|
|
212
221
|
vim: false,
|
|
213
222
|
stream: opts.stream,
|
|
214
223
|
cwd: process.cwd(),
|
|
215
224
|
lastRecap: null,
|
|
216
225
|
sessionId: randomUUID(),
|
|
217
226
|
};
|
|
227
|
+
// The light flag must start consistent with the default row above, or the
|
|
228
|
+
// ctx and the palette disagree until the first `/theme`: with `AUTO_THEME_INDEX`
|
|
229
|
+
// as the default, a light-background terminal gets the light palette *and*
|
|
230
|
+
// the "light" label, a dark one is byte-identical to before.
|
|
231
|
+
if (commandCtx.themeIndex === AUTO_THEME_INDEX) commandCtx.light = themeIsLight(AUTO_THEME_INDEX);
|
|
218
232
|
// The transcript rows a handler reads/pushes (user/assistant/note/panel/…).
|
|
219
233
|
// It is also the source of the engine's conversation history, so /clear and
|
|
220
234
|
// /new genuinely reset context.
|
|
@@ -1876,10 +1890,54 @@ function createApp(options = {}) {
|
|
|
1876
1890
|
// appeared to work and every run after it died on startup.
|
|
1877
1891
|
if (!opts.light && typeof cfg.themeIndex === 'number' && THEME_TABLE[cfg.themeIndex]) {
|
|
1878
1892
|
commandCtx.themeIndex = cfg.themeIndex;
|
|
1879
|
-
|
|
1893
|
+
// `themeIsLight` and not `row.light`: row 0's own flag is the dark
|
|
1894
|
+
// fallback, and reading it directly is what pinned a light-terminal user
|
|
1895
|
+
// back to the dark palette on every launch after they chose "Auto".
|
|
1896
|
+
commandCtx.light = themeIsLight(cfg.themeIndex);
|
|
1897
|
+
// A stored row is a preference about a *terminal*, and the terminal it
|
|
1898
|
+
// was chosen on need not be the one it is being restored on. Row 2 is
|
|
1899
|
+
// "Light mode" — primary text `RGB(40,40,40)` — and restoring it onto a
|
|
1900
|
+
// dark terminal drew that text over `#1e1e2e`: contrast 1.11:1, a body of
|
|
1901
|
+
// text present and unreadable. Reading the row as a bare brightness (what
|
|
1902
|
+
// this line did before) is why nothing ever checked. The stored value is
|
|
1903
|
+
// left untouched: the correction belongs to this terminal, and moving
|
|
1904
|
+
// back to a light one restores the choice by itself.
|
|
1905
|
+
const fixed = reconcileThemeIndex(commandCtx.themeIndex);
|
|
1906
|
+
if (fixed.changed) {
|
|
1907
|
+
commandCtx.themeIndex = fixed.index;
|
|
1908
|
+
commandCtx.light = themeIsLight(fixed.index);
|
|
1909
|
+
commandCtx.themeNotice = fixed.reason;
|
|
1910
|
+
// And it is written back. The stored row is a choice that THIS terminal
|
|
1911
|
+
// cannot satisfy, so leaving it on disk would mean the correction is
|
|
1912
|
+
// re-applied — and re-announced — on every launch forever, with the
|
|
1913
|
+
// config asserting a preference the session never honours. `/theme`
|
|
1914
|
+
// still sets it, and the announcement says which value was saved, so
|
|
1915
|
+
// the file and the screen never disagree silently.
|
|
1916
|
+
try {
|
|
1917
|
+
updateConfig({ themeIndex: fixed.index, light: themeIsLight(fixed.index) });
|
|
1918
|
+
} catch {
|
|
1919
|
+
// An unwritable config is not a reason to draw unreadable text: the
|
|
1920
|
+
// in-memory correction above already applies, and the notice says so.
|
|
1921
|
+
commandCtx.themeNotice += ' (could not save it)';
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1880
1924
|
}
|
|
1881
1925
|
}
|
|
1882
1926
|
|
|
1927
|
+
/**
|
|
1928
|
+
* Say the stored theme was corrected for this terminal, once, on a real
|
|
1929
|
+
* screen. Emitted before the session takes the alternate screen so it lands
|
|
1930
|
+
* in scrollback rather than being wiped by the session's first frame, and
|
|
1931
|
+
* only when the correction actually happened — an unasked-for notice about an
|
|
1932
|
+
* unchanged setting is noise.
|
|
1933
|
+
*/
|
|
1934
|
+
function themeNoticeFirstRun() {
|
|
1935
|
+
if (!commandCtx.themeNotice) return;
|
|
1936
|
+
const reason = commandCtx.themeNotice;
|
|
1937
|
+
commandCtx.themeNotice = '';
|
|
1938
|
+
emit(render.renderNotice(ctx(), 'warn', `theme: ${reason} (saved)`));
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1883
1941
|
/**
|
|
1884
1942
|
* Interactive entry point. On a real terminal this is the full chatflow
|
|
1885
1943
|
* (alternate screen, header, transcript viewport, spinner, effort line,
|
|
@@ -1894,7 +1952,21 @@ function createApp(options = {}) {
|
|
|
1894
1952
|
process.stdin.isTTY &&
|
|
1895
1953
|
process.stdout.isTTY;
|
|
1896
1954
|
if (tty) {
|
|
1955
|
+
// Ask the terminal what its background is BEFORE the stored theme is
|
|
1956
|
+
// restored, because the restore is a decision *about that background*.
|
|
1957
|
+
// Nothing in the environment answers this on the terminals people run —
|
|
1958
|
+
// Alacritty sets neither `COLORFGBG` nor `TERM_BACKGROUND` — so without
|
|
1959
|
+
// the query the palette was chosen from silence. Bounded (120ms) and
|
|
1960
|
+
// skipped entirely when an env var already decided, so a session that
|
|
1961
|
+
// reports nothing is as fast as it was.
|
|
1962
|
+
//
|
|
1963
|
+
// A keypress can race the terminal's answer into the same read, so any
|
|
1964
|
+
// byte that was not the answer is handed back to the key pump's own queue
|
|
1965
|
+
// rather than to the stream: `events.feedKeys` delivers it exactly as a
|
|
1966
|
+
// `data` event would have, including after stdin has ended.
|
|
1967
|
+
await probeTerminalBackground({ onLeftover: (text) => events.feedKeys(text) });
|
|
1897
1968
|
restorePrefs();
|
|
1969
|
+
themeNoticeFirstRun();
|
|
1898
1970
|
adoptLegacyKeyOnce();
|
|
1899
1971
|
// Give aegis1 a chance to auto-provision a free device key BEFORE
|
|
1900
1972
|
// deciding whether onboarding needs to ask for one — a fresh install
|