aegiscode 6.8.6 → 6.8.8
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 +2 -2
- package/scripts/predist.mjs +12 -0
- package/scripts/runtests.mjs +54 -0
- package/src/app.js +115 -3
- package/src/art.js +26 -19
- package/src/caps.js +106 -158
- package/src/chatflow.js +29 -15
- package/src/checkpoint.js +4 -2
- package/src/clipboard.js +89 -13
- package/src/commands.js +47 -3
- package/src/config.js +8 -9
- package/src/deps.js +7 -1
- package/src/diffview.js +10 -3
- package/src/events.js +27 -1
- package/src/history.js +5 -3
- package/src/models.js +46 -12
- package/src/securefs.js +319 -0
- package/src/theme.js +23 -21
- package/vendor/client/aegis.js +16 -1
- package/vendor/client/auto-provision.js +52 -0
- package/vendor/client/brain-catalog.js +113 -0
- package/vendor/client/device-fingerprint.js +63 -0
- package/vendor/desktop/lib/local/engine.js +37 -31
- package/vendor/mcp/server.js +33 -2
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.8",
|
|
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",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"predist": "node scripts/predist.mjs",
|
|
28
28
|
"prepublishOnly": "npm run predist",
|
|
29
29
|
"check": "node --check bin/aegiscode.js && for f in src/*.js; do node --check \"$f\" || exit 1; done && node --check scripts/predist.mjs",
|
|
30
|
-
"test": "
|
|
30
|
+
"test": "node scripts/runtests.mjs"
|
|
31
31
|
},
|
|
32
32
|
"keywords": [
|
|
33
33
|
"aegis",
|
package/scripts/predist.mjs
CHANGED
|
@@ -50,6 +50,18 @@ const FILES = [
|
|
|
50
50
|
// comments in this array: test/packaging.test.mjs parses it by pairing single
|
|
51
51
|
// quotes, and one stray one silently swallows the next real entry.)
|
|
52
52
|
'client/env-file.js',
|
|
53
|
+
// Auto-provision a free device key when no key is configured anywhere —
|
|
54
|
+
// shared with the desktop app and the MCP plugin so all three ask aegis1
|
|
55
|
+
// for the same account on the same machine.
|
|
56
|
+
'client/auto-provision.js',
|
|
57
|
+
'client/device-fingerprint.js',
|
|
58
|
+
// The pooled-brain selection rule: which single entry stands for the Aegis
|
|
59
|
+
// class. Required at load time by src/models.js (through src/sharedpaths.js),
|
|
60
|
+
// which the picker, /model and the OpenAI-compatible shim all build their
|
|
61
|
+
// model list from — and by the desktop engine, so the GUI and the terminal
|
|
62
|
+
// offer one account one list. Leaving it out stages a package whose every
|
|
63
|
+
// model listing throws MODULE_NOT_FOUND before it can print a prompt.
|
|
64
|
+
'client/brain-catalog.js',
|
|
53
65
|
'mcp/tools.js',
|
|
54
66
|
// The stdio MCP server itself — the process every editor config written by
|
|
55
67
|
// `aegiscode mcp install` points at. Staging the registry without it ships a
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Run every `test/cli-*.test.mjs` and report all of them.
|
|
4
|
+
*
|
|
5
|
+
* This replaces `for f in …; do node "$f" || exit 1; done`. That loop stops at
|
|
6
|
+
* the first failure, and since the files run in glob (alphabetical) order, one
|
|
7
|
+
* broken file silently hides every file after it — `cli-click` sorts 5th of 28,
|
|
8
|
+
* so a single failure there meant 23 test files had not run at all while the
|
|
9
|
+
* command still looked like "the suite".
|
|
10
|
+
*
|
|
11
|
+
* Failures are collected, each file's own output is streamed through, and the
|
|
12
|
+
* summary names what failed. Exit is non-zero if anything failed, so CI and
|
|
13
|
+
* `npm test` still gate on it.
|
|
14
|
+
*/
|
|
15
|
+
import { readdirSync } from 'node:fs';
|
|
16
|
+
import { spawnSync } from 'node:child_process';
|
|
17
|
+
import { dirname, join, resolve } from 'node:path';
|
|
18
|
+
import { fileURLToPath } from 'node:url';
|
|
19
|
+
|
|
20
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
21
|
+
const testDir = resolve(here, '..', '..', 'test');
|
|
22
|
+
|
|
23
|
+
const files = readdirSync(testDir)
|
|
24
|
+
.filter((f) => /^cli-.*\.test\.mjs$/.test(f))
|
|
25
|
+
.sort();
|
|
26
|
+
|
|
27
|
+
if (files.length === 0) {
|
|
28
|
+
process.stderr.write(`no cli-*.test.mjs found in ${testDir}\n`);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const failed = [];
|
|
33
|
+
const passed = [];
|
|
34
|
+
|
|
35
|
+
for (const f of files) {
|
|
36
|
+
const full = join(testDir, f);
|
|
37
|
+
process.stdout.write(`\n── ${f} ${'─'.repeat(Math.max(0, 60 - f.length))}\n`);
|
|
38
|
+
const res = spawnSync(process.execPath, [full], { stdio: 'inherit' });
|
|
39
|
+
if (res.status === 0) {
|
|
40
|
+
passed.push(f);
|
|
41
|
+
} else {
|
|
42
|
+
failed.push({ f, status: res.status, signal: res.signal });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
process.stdout.write(`\n${'═'.repeat(64)}\n`);
|
|
47
|
+
process.stdout.write(`cli suite: ${passed.length}/${files.length} files passed\n`);
|
|
48
|
+
if (failed.length) {
|
|
49
|
+
process.stdout.write(`\nFAILED (${failed.length}):\n`);
|
|
50
|
+
for (const { f, status, signal } of failed) {
|
|
51
|
+
process.stdout.write(` ✗ ${f}${signal ? ` (signal ${signal})` : ` (exit ${status})`}\n`);
|
|
52
|
+
}
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
package/src/app.js
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
const readline = require('node:readline');
|
|
22
22
|
const os = require('node:os');
|
|
23
23
|
const { randomUUID } = require('node:crypto');
|
|
24
|
-
const { createTools, createClient, usageTokens, usageBuckets, buildSystemPrompt } = require('./deps.js');
|
|
24
|
+
const { createTools, createClient, usageTokens, usageBuckets, buildSystemPrompt, autoProvisionApiKey } = require('./deps.js');
|
|
25
25
|
const { createEngine, HOST_CLASSES, DEFAULT_CLASS, byokNamespace } = require('./engine.js');
|
|
26
26
|
const { GLYPH, VERBS, themeOf, RESET, THEME_TABLE } = require('./theme.js');
|
|
27
27
|
const { LiveRegion, termWidth, w } = require('./screen.js');
|
|
@@ -115,6 +115,34 @@ function createApp(options = {}) {
|
|
|
115
115
|
const client = options.client || createClient(credentials.clientOptions({ channel: 'cli' }));
|
|
116
116
|
const { TOOLS, toolList } = options.tools || createTools(client);
|
|
117
117
|
|
|
118
|
+
// With no key configured anywhere, ask aegis1 for a free device key before
|
|
119
|
+
// ever showing "no key" — same shared helper (client/auto-provision.js) the
|
|
120
|
+
// MCP plugin and the desktop app use, so all three ask for the same account
|
|
121
|
+
// on the same machine. One attempt per `createApp()` instance, not one per
|
|
122
|
+
// call: register-device is rate-limited server-side, and a session that
|
|
123
|
+
// fires several turns before noticing a failure must not retry the same
|
|
124
|
+
// failing call each time. The provisioned account starts at zero
|
|
125
|
+
// token-bank balance and still needs an upgraded plan for pooled
|
|
126
|
+
// aegiscloud models (aegis1's is_pro() gate) — this only unblocks BYOK and
|
|
127
|
+
// account status/settings, never silently free inference.
|
|
128
|
+
let provisionAttempted = false;
|
|
129
|
+
async function ensureApiKey() {
|
|
130
|
+
if (client.apiKey || provisionAttempted) return;
|
|
131
|
+
provisionAttempted = true;
|
|
132
|
+
const result = await autoProvisionApiKey(client, credentials);
|
|
133
|
+
if (result.key) {
|
|
134
|
+
emit(
|
|
135
|
+
render.renderNotice(
|
|
136
|
+
ctx(),
|
|
137
|
+
'info',
|
|
138
|
+
`no AEGIS key was configured — auto-provisioned a free account` +
|
|
139
|
+
(result.ok ? ` (saved to ${credentials.credentialsPath()})` : ' (could not save it — reconfigure with /key)') +
|
|
140
|
+
`. Fund it at ${client.promptUrl('topup', 'device_autoprovision')} or run /byok to use your own key.`
|
|
141
|
+
)
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
118
146
|
// Tool-approval gate (exec/writeFile/editFile confirm before running).
|
|
119
147
|
// Read per call, so /permissions and /yolo take effect on the very next tool
|
|
120
148
|
// round rather than needing a restart. The mode is read LIVE from the
|
|
@@ -192,6 +220,12 @@ function createApp(options = {}) {
|
|
|
192
220
|
// /new genuinely reset context.
|
|
193
221
|
const transcript = [];
|
|
194
222
|
let wantExit = false;
|
|
223
|
+
// When non-null, `emit` appends here instead of writing to `out`. Used by the
|
|
224
|
+
// one-shot path to run a command and report its output as one JSON document
|
|
225
|
+
// (`--json`) rather than as loose human text on stdout. Every command's output
|
|
226
|
+
// funnels through `emit` (pushRow's panel/note/turn branches all call it), so
|
|
227
|
+
// one switch here covers the whole command surface.
|
|
228
|
+
let capture = null;
|
|
195
229
|
|
|
196
230
|
const ctx = () => ({ light: commandCtx.light });
|
|
197
231
|
|
|
@@ -637,7 +671,10 @@ function createApp(options = {}) {
|
|
|
637
671
|
*/
|
|
638
672
|
function emit(lines) {
|
|
639
673
|
const block = typeof lines === 'string' ? [lines] : lines;
|
|
640
|
-
for (const l of block)
|
|
674
|
+
for (const l of block) {
|
|
675
|
+
if (capture) capture.push(l);
|
|
676
|
+
else out.write(l + '\n');
|
|
677
|
+
}
|
|
641
678
|
}
|
|
642
679
|
|
|
643
680
|
// --- the ask path ---------------------------------------------------------
|
|
@@ -875,6 +912,7 @@ function createApp(options = {}) {
|
|
|
875
912
|
emit(render.renderNotice(ctx(), 'warn', 'nothing to ask — give /ask a prompt'));
|
|
876
913
|
return;
|
|
877
914
|
}
|
|
915
|
+
if (!client.apiKey) await ensureApiKey();
|
|
878
916
|
if (!client.apiKey) {
|
|
879
917
|
emit(
|
|
880
918
|
render.renderNotice(
|
|
@@ -950,6 +988,7 @@ function createApp(options = {}) {
|
|
|
950
988
|
async function runTool(name, args) {
|
|
951
989
|
const tool = TOOLS[name];
|
|
952
990
|
if (!tool) throw new Error(`unknown tool: ${name}`);
|
|
991
|
+
if (!client.apiKey) await ensureApiKey();
|
|
953
992
|
if (!client.apiKey) {
|
|
954
993
|
throw new Error(`no AEGIS account key — ${credentials.HOW_TO_SET}`);
|
|
955
994
|
}
|
|
@@ -1402,9 +1441,20 @@ function createApp(options = {}) {
|
|
|
1402
1441
|
async function runOnce(prompt, { json = false } = {}) {
|
|
1403
1442
|
adoptLegacyKeyOnce();
|
|
1404
1443
|
if (!client.apiKey) {
|
|
1405
|
-
err.write(`aegiscode: no AEGIS account key. ${credentials.HOW_TO_SET}, or set
|
|
1444
|
+
err.write(`aegiscode: no AEGIS account key. ${credentials.HOW_TO_SET}, or set ${credentials.KEY_ENV}.\n`);
|
|
1406
1445
|
return 2;
|
|
1407
1446
|
}
|
|
1447
|
+
// A leading `/` is a LOCAL command at every other entry point (the chatflow
|
|
1448
|
+
// dispatches it, the linear REPL dispatches it), so it must be one here too.
|
|
1449
|
+
// This path used to skip the dispatcher entirely and hand `"/cost"` to the
|
|
1450
|
+
// model as ordinary user text: the request went out as a chat completion, and
|
|
1451
|
+
// the pool — which has no answer for a bare slash command — opened an
|
|
1452
|
+
// event-stream and sent nothing, so the turn died on the client's 60s idle
|
|
1453
|
+
// watchdog with "stream stalled". Every documented non-interactive use of a
|
|
1454
|
+
// command (`aegiscode -p "/cost"`, `--json -p "/models"`) was affected, and
|
|
1455
|
+
// the failure was indistinguishable from a server outage.
|
|
1456
|
+
const parsed = parseLine(prompt);
|
|
1457
|
+
if (parsed.kind !== 'prompt') return runOnceCommand(prompt, parsed, { json });
|
|
1408
1458
|
// Snapshot the account's existing ledger BEFORE the billed call. Without
|
|
1409
1459
|
// this the refresh after the turn would treat every historical row as new,
|
|
1410
1460
|
// and the reported charge would be whatever the account spent last rather
|
|
@@ -1443,6 +1493,64 @@ function createApp(options = {}) {
|
|
|
1443
1493
|
return res.interrupted ? 130 : 0;
|
|
1444
1494
|
}
|
|
1445
1495
|
|
|
1496
|
+
/**
|
|
1497
|
+
* The one-shot variant of `handleLine`: run a local command and print what it
|
|
1498
|
+
* produced. Returns the process exit code.
|
|
1499
|
+
*
|
|
1500
|
+
* The commands are dispatched through the SAME `handleLine` the interactive
|
|
1501
|
+
* loop uses — not a second implementation — so `/cost`, `/models` and friends
|
|
1502
|
+
* cannot answer differently depending on whether a human was watching. What
|
|
1503
|
+
* this adds over the interactive path is only the two things a non-interactive
|
|
1504
|
+
* caller has that the loop does not: an exit code, and, under `--json`, a
|
|
1505
|
+
* machine-readable envelope around the command's own output.
|
|
1506
|
+
*
|
|
1507
|
+
* Preferences are restored first. The interactive entry point calls
|
|
1508
|
+
* `restorePrefs()` on startup and this one never did, so a command run through
|
|
1509
|
+
* `-p` would have read a context that ignored the config on disk — `/model`
|
|
1510
|
+
* with no pin, for instance, would not have seen the model the user pinned.
|
|
1511
|
+
*/
|
|
1512
|
+
async function runOnceCommand(line, parsed, { json }) {
|
|
1513
|
+
if (parsed.kind === 'empty') return 0;
|
|
1514
|
+
if (parsed.kind === 'unknown') {
|
|
1515
|
+
// Straight to stderr, and non-zero: an unknown command is a caller bug, and
|
|
1516
|
+
// `-p` is the entry point scripts use. Going through `emit` would put the
|
|
1517
|
+
// diagnostic on stdout where a `$(...)` capture would swallow it, and
|
|
1518
|
+
// exiting 0 would make a typo look like a success.
|
|
1519
|
+
const alt = nearest(parsed.name);
|
|
1520
|
+
err.write(`aegiscode: unknown command: /${parsed.name}${alt ? ` — did you mean /${alt}?` : ''}\n`);
|
|
1521
|
+
return 2;
|
|
1522
|
+
}
|
|
1523
|
+
restorePrefs();
|
|
1524
|
+
await refreshSpend();
|
|
1525
|
+
const lines = json ? [] : null;
|
|
1526
|
+
if (lines) capture = lines;
|
|
1527
|
+
let keep = true;
|
|
1528
|
+
try {
|
|
1529
|
+
keep = await handleLine(line);
|
|
1530
|
+
} finally {
|
|
1531
|
+
capture = null;
|
|
1532
|
+
}
|
|
1533
|
+
if (json) {
|
|
1534
|
+
out.write(
|
|
1535
|
+
JSON.stringify(
|
|
1536
|
+
{
|
|
1537
|
+
command: parsed.kind === 'command' ? '/' + parsed.command.name : line,
|
|
1538
|
+
arg: parsed.arg || '',
|
|
1539
|
+
// `handleLine` returns false when the command asked to end the
|
|
1540
|
+
// session (`/quit`, `/exit`); in one-shot that simply means the
|
|
1541
|
+
// command ran and there is nothing further to do.
|
|
1542
|
+
ended: keep === false,
|
|
1543
|
+
output: lines,
|
|
1544
|
+
balance_eur: session.balance,
|
|
1545
|
+
},
|
|
1546
|
+
null,
|
|
1547
|
+
2
|
|
1548
|
+
) + '\n'
|
|
1549
|
+
);
|
|
1550
|
+
}
|
|
1551
|
+
return 0;
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1446
1554
|
/** Fold one completed turn's usage into the session tallies.
|
|
1447
1555
|
* @returns {number|null} the total token count for the turn, when known. */
|
|
1448
1556
|
function recordTurn(res) {
|
|
@@ -1775,6 +1883,10 @@ function createApp(options = {}) {
|
|
|
1775
1883
|
if (tty) {
|
|
1776
1884
|
restorePrefs();
|
|
1777
1885
|
adoptLegacyKeyOnce();
|
|
1886
|
+
// Give aegis1 a chance to auto-provision a free device key BEFORE
|
|
1887
|
+
// deciding whether onboarding needs to ask for one — a fresh install
|
|
1888
|
+
// should never be prompted for a key it can get on its own.
|
|
1889
|
+
if (!client.apiKey) await ensureApiKey();
|
|
1778
1890
|
// Onboarding runs in the normal buffer, before the session takes the
|
|
1779
1891
|
// alternate screen — the reference's order. A declined trust check must
|
|
1780
1892
|
// abort: the reference returns without ever reaching `session(ctx)`.
|
package/src/art.js
CHANGED
|
@@ -9,7 +9,10 @@ const { caps, detect, cells, padCells } = require('./caps.js');
|
|
|
9
9
|
* A platform *name* is still accepted because it is the shape a test wants when
|
|
10
10
|
* it is asking "what would the mark look like on that host?"; it is resolved
|
|
11
11
|
* through the same `detect()` the live process uses, so a platform string is a
|
|
12
|
-
* convenience alias for a capability probe, never a second decision path.
|
|
12
|
+
* convenience alias for a capability probe, never a second decision path. Under
|
|
13
|
+
* the uniform policy `detect()` ignores the platform it is handed, so
|
|
14
|
+
* `capsOf('win32')` and `capsOf('linux')` return the same axes — which is the
|
|
15
|
+
* point, and is asserted by `test/cli-terminal-caps.test.mjs`.
|
|
13
16
|
*/
|
|
14
17
|
function capsOf(target) {
|
|
15
18
|
if (!target) return caps();
|
|
@@ -81,27 +84,31 @@ const TAGLINE = 'Your intent, AI automated.';
|
|
|
81
84
|
const TAGLINE_SHORT = 'Your intent, automated.';
|
|
82
85
|
|
|
83
86
|
// ── Terminal portability ─────────────────────────────────────────────────────
|
|
84
|
-
// The wordmark is drawn with U+2550 box-drawing runes
|
|
85
|
-
//
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
// offending code points 1:1 (same character count per row) so the width maths
|
|
89
|
-
// stays exact and the mark keeps its shape.
|
|
87
|
+
// The wordmark is drawn with U+2550 box-drawing runes, which are single-width on
|
|
88
|
+
// essentially every terminal in use. Each pass swaps offending code points 1:1
|
|
89
|
+
// (same character count per row) so the width maths stays exact and the mark
|
|
90
|
+
// keeps its shape.
|
|
90
91
|
//
|
|
91
|
-
//
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
//
|
|
92
|
+
// A pass is applied when the user ASKS for one — `AEGIS_ART=ascii` for a font
|
|
93
|
+
// with no box-drawing or block range, `AEGIS_STAR=narrow` for a font that
|
|
94
|
+
// renders ✦ through a two-cell emoji fallback. It is never triggered by the
|
|
95
|
+
// host: `process.platform`, `TERM`, `TERM_PROGRAM`, `WT_SESSION` and the
|
|
96
|
+
// locale's character set are probed and reported by `caps.js` and then
|
|
97
|
+
// deliberately ignored, because a font that lacks the runes is something only
|
|
98
|
+
// the person looking at the screen can settle. Previously PowerShell outside
|
|
99
|
+
// Windows Terminal, Terminal.app and any `LANG=C` shell each silently got a
|
|
100
|
+
// different mark from the same build.
|
|
101
|
+
//
|
|
102
|
+
// The passes still compose rather than being picked one-of-three, because the
|
|
103
|
+
// two overrides are independent: `AEGIS_STAR=narrow` alone gives a native block
|
|
104
|
+
// palette with a single-column star, which no single flat table could express.
|
|
98
105
|
//
|
|
99
106
|
// This table is the ONE stencil source of truth for the product. `theme.js`
|
|
100
107
|
// resolves `GLYPH.star` through `stencilGlyph(STAR, caps)` rather than carrying
|
|
101
108
|
// its own `'✦' → '*'` rule, and `render.js` builds the mark's tint map by
|
|
102
109
|
// stencilling its runes — both had a private copy of the same decision, which
|
|
103
|
-
// is how a stencil edit here could leave the star wide on
|
|
104
|
-
// untinted on
|
|
110
|
+
// is how a stencil edit here could leave the star wide on one host and the mark
|
|
111
|
+
// untinted on another. `test/cli-terminal-caps.test.mjs` pins all of it.
|
|
105
112
|
const STAR = '✦';
|
|
106
113
|
|
|
107
114
|
/** The quartile/quadrant face edges. The wordmark no longer draws them, but the
|
|
@@ -145,9 +152,9 @@ const EDGE_STENCIL = new Map(EDGE_RUNES.map((c) => [c, '#']));
|
|
|
145
152
|
const STAR_STENCIL = new Map([[STAR, '*']]);
|
|
146
153
|
|
|
147
154
|
/**
|
|
148
|
-
* The named passes. They compose rather than being picked one-of-three:
|
|
149
|
-
*
|
|
150
|
-
*
|
|
155
|
+
* The named passes. They compose rather than being picked one-of-three:
|
|
156
|
+
* `AEGIS_STAR=narrow` takes `star` only — a native block palette with a
|
|
157
|
+
* single-column star — and `AEGIS_ART=ascii` takes the full pass.
|
|
151
158
|
*/
|
|
152
159
|
const STENCILS = { ascii: ASCII_STENCIL, edges: EDGE_STENCIL, star: STAR_STENCIL };
|
|
153
160
|
|