aegiscode 7.0.12 → 7.0.14
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/bin/aegiscode.js +12 -0
- package/package.json +2 -1
- package/scripts/predist.mjs +6 -3
- package/src/app.js +102 -1
- package/src/chatflow.js +14 -2
- package/src/commands.js +61 -5
- package/src/limits.js +1 -1
- package/src/provenance.lock.json +2 -2
- package/src/update.js +103 -12
- package/vendor/client/aegis.js +297 -6
- package/vendor/client/drive-connect.js +112 -0
- package/vendor/client/drive-upload.js +176 -0
- package/vendor/client/google-signin.js +12 -4
- package/vendor/client/model-discovery.js +43 -0
- package/vendor/client/update.js +100 -8
- package/vendor/desktop/lib/local/engine.js +138 -2
- package/vendor/desktop/lib/local/entitlement.js +7 -1
- package/vendor/desktop/lib/local/prompt.js +67 -37
- package/vendor/desktop/lib/local/tools.js +49 -13
|
@@ -37,10 +37,14 @@ function escapeHtml(s) {
|
|
|
37
37
|
}[c]));
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
function page({ ok, error, username }) {
|
|
40
|
+
function page({ ok, error, username, surface }) {
|
|
41
41
|
const title = ok ? 'Signed in' : 'Sign-in failed';
|
|
42
|
+
// This page is shared by the CLI and the desktop, and only one of them is
|
|
43
|
+
// a terminal. The desktop passes `surface: 'app'`; the default keeps the
|
|
44
|
+
// CLI's existing wording.
|
|
45
|
+
const where = surface === 'app' ? 'the app' : 'the terminal';
|
|
42
46
|
const body = ok
|
|
43
|
-
? `Signed in${username ? ` as <b>${escapeHtml(username)}</b>` : ''}. You can close this tab and return to
|
|
47
|
+
? `Signed in${username ? ` as <b>${escapeHtml(username)}</b>` : ''}. You can close this tab and return to ${where}.`
|
|
44
48
|
: `Sign-in failed: ${escapeHtml(error || 'no token was returned')}. You can close this tab and try again.`;
|
|
45
49
|
return `<!doctype html><html><head><meta charset="utf-8"><title>${title} — AEGIS</title></head>` +
|
|
46
50
|
`<body style="font:16px sans-serif;max-width:32rem;margin:4rem auto;text-align:center;">` +
|
|
@@ -62,9 +66,13 @@ function buildAuthUrl(apiBase, callbackUrl) {
|
|
|
62
66
|
* else (a browser pre-connect, `/favicon.ico`) gets a plain 404 and the
|
|
63
67
|
* server keeps listening for the real one.
|
|
64
68
|
*
|
|
69
|
+
* `surface` only changes the wording of the page the browser lands on after
|
|
70
|
+
* signing in ('terminal' for the CLI, 'app' for the desktop) — it changes
|
|
71
|
+
* nothing about the flow itself.
|
|
72
|
+
*
|
|
65
73
|
* @returns {Promise<{url: string, wait: () => Promise<{apiKey:string, username:?string, memoryToken:?string}>}>}
|
|
66
74
|
*/
|
|
67
|
-
async function startGoogleSignIn({ apiBase, host = '127.0.0.1', timeoutMs = 5 * 60 * 1000 } = {}) {
|
|
75
|
+
async function startGoogleSignIn({ apiBase, host = '127.0.0.1', timeoutMs = 5 * 60 * 1000, surface = 'terminal' } = {}) {
|
|
68
76
|
if (!apiBase) throw new Error('startGoogleSignIn requires apiBase');
|
|
69
77
|
|
|
70
78
|
let settled = false;
|
|
@@ -93,7 +101,7 @@ async function startGoogleSignIn({ apiBase, host = '127.0.0.1', timeoutMs = 5 *
|
|
|
93
101
|
return;
|
|
94
102
|
}
|
|
95
103
|
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
96
|
-
res.end(page({ ok: Boolean(token), error, username }));
|
|
104
|
+
res.end(page({ ok: Boolean(token), error, username, surface }));
|
|
97
105
|
|
|
98
106
|
if (settled) return;
|
|
99
107
|
settled = true;
|
|
@@ -101,6 +101,36 @@ const ENDPOINTS = Object.freeze({
|
|
|
101
101
|
headers: bearer,
|
|
102
102
|
note: 'OpenAI-compatible',
|
|
103
103
|
}),
|
|
104
|
+
// The remaining providers in aegis1's catalog that speak `openai_chat` and
|
|
105
|
+
// answer a standard OpenAI-shaped list on `<base_url>/models`.
|
|
106
|
+
//
|
|
107
|
+
// Probed live rather than assumed, because "OpenAI-compatible chat" does not
|
|
108
|
+
// imply "has a list endpoint": cerebras, fireworks and sakana answer 401/403
|
|
109
|
+
// without a key (the endpoint exists and is gated) and NVIDIA's list answers
|
|
110
|
+
// 200 unauthenticated with 84 rows, which is why it is the one endpoint here
|
|
111
|
+
// whose list is public. Ollama is deliberately absent: it is keyless and
|
|
112
|
+
// local, so it has nothing to put in the API key this module requires, and
|
|
113
|
+
// `canDiscover` would be reporting a capability the caller cannot use.
|
|
114
|
+
cerebras: Object.freeze({
|
|
115
|
+
url: 'https://api.cerebras.ai/v1/models',
|
|
116
|
+
headers: bearer,
|
|
117
|
+
note: 'OpenAI-compatible under /v1',
|
|
118
|
+
}),
|
|
119
|
+
fireworks: Object.freeze({
|
|
120
|
+
url: 'https://api.fireworks.ai/inference/v1/models',
|
|
121
|
+
headers: bearer,
|
|
122
|
+
note: 'OpenAI-compatible under /inference/v1; ids are "accounts/fireworks/models/<id>"',
|
|
123
|
+
}),
|
|
124
|
+
nvidia_nim: Object.freeze({
|
|
125
|
+
url: 'https://integrate.api.nvidia.com/v1/models',
|
|
126
|
+
headers: bearer,
|
|
127
|
+
note: 'OpenAI-compatible; ids are "<vendor>/<model>"',
|
|
128
|
+
}),
|
|
129
|
+
sakana: Object.freeze({
|
|
130
|
+
url: 'https://api.sakana.ai/v1/models',
|
|
131
|
+
headers: bearer,
|
|
132
|
+
note: 'OpenAI-compatible under /v1',
|
|
133
|
+
}),
|
|
104
134
|
});
|
|
105
135
|
|
|
106
136
|
/** Other spellings a user types for a provider this module knows. */
|
|
@@ -112,6 +142,19 @@ const ALIASES = Object.freeze({
|
|
|
112
142
|
'googleai': 'gemini',
|
|
113
143
|
'open-ai': 'openai',
|
|
114
144
|
'deep-seek': 'deepseek',
|
|
145
|
+
// Two catalog rows that are the SAME VENDOR under a second provider id: both
|
|
146
|
+
// `openai-gpt4o-mini` and `anthropic-haiku` share their sibling's credential
|
|
147
|
+
// and base_url, and differ only in the default model they pin (see
|
|
148
|
+
// `client/byok-catalog.js`, which notes the two OpenAI ids "share one
|
|
149
|
+
// credential and one model"). Discovery asks a vendor, so both spellings must
|
|
150
|
+
// reach the one list its key can already answer — otherwise a user holding a
|
|
151
|
+
// key filed under the `-haiku` / `-gpt4o-mini` row is told this client has no
|
|
152
|
+
// endpoint for their provider while the identical key under the sibling row
|
|
153
|
+
// is accepted. `custom` and `ollama` are deliberately NOT aliased: the first
|
|
154
|
+
// has no fixed base_url (it is supplied per request), and the second is
|
|
155
|
+
// keyless, so neither has a vendor list this module could ask.
|
|
156
|
+
'openai-gpt4o-mini': 'openai',
|
|
157
|
+
'anthropic-haiku': 'anthropic',
|
|
115
158
|
});
|
|
116
159
|
|
|
117
160
|
/**
|
package/vendor/client/update.js
CHANGED
|
@@ -399,19 +399,21 @@ function updateNotice({
|
|
|
399
399
|
*
|
|
400
400
|
* @param {{current: string, latest: ?string, behind: boolean, channel?: 'npm'|'desktop', pkg?: string}} input
|
|
401
401
|
*/
|
|
402
|
-
function updatePlan({ current, latest, behind, channel = 'npm', pkg = PKG } = {}) {
|
|
402
|
+
function updatePlan({ current, latest, behind, channel = 'npm', pkg = PKG, method = 'npm' } = {}) {
|
|
403
403
|
const currentText = String(current == null ? '' : current);
|
|
404
404
|
const latestText = latest ? String(latest) : null;
|
|
405
405
|
const pending = Boolean(behind) && Boolean(latestText);
|
|
406
406
|
if (!pending) {
|
|
407
407
|
return {
|
|
408
408
|
channel,
|
|
409
|
+
method,
|
|
409
410
|
current: currentText,
|
|
410
411
|
latest: latestText,
|
|
411
412
|
behind: false,
|
|
412
413
|
action: 'none',
|
|
413
414
|
applier: 'none',
|
|
414
415
|
instruction: null,
|
|
416
|
+
apply: null,
|
|
415
417
|
};
|
|
416
418
|
}
|
|
417
419
|
if (channel === 'desktop') {
|
|
@@ -420,25 +422,101 @@ function updatePlan({ current, latest, behind, channel = 'npm', pkg = PKG } = {}
|
|
|
420
422
|
// beside the running app. The applier is the app's own updater.
|
|
421
423
|
return {
|
|
422
424
|
channel,
|
|
425
|
+
method,
|
|
423
426
|
current: currentText,
|
|
424
427
|
latest: latestText,
|
|
425
428
|
behind: true,
|
|
426
429
|
action: 'desktop-update',
|
|
427
430
|
applier: 'electron-updater',
|
|
428
431
|
instruction: 'Aegis Desktop → Check for Updates…',
|
|
432
|
+
apply: null,
|
|
429
433
|
};
|
|
430
434
|
}
|
|
435
|
+
|
|
436
|
+
// Which installer owns this copy. The command is not cosmetic: `npm i -g`
|
|
437
|
+
// against a pip-installed `aegiscode` writes a second copy beside the one the
|
|
438
|
+
// user actually runs, and the "upgrade" appears to do nothing. Same for an
|
|
439
|
+
// `npx` run, which has nothing installed to upgrade at all.
|
|
440
|
+
const applier = APPLIERS[method] || APPLIERS.npm;
|
|
431
441
|
return {
|
|
432
442
|
channel,
|
|
443
|
+
method,
|
|
433
444
|
current: currentText,
|
|
434
445
|
latest: latestText,
|
|
435
446
|
behind: true,
|
|
436
|
-
action:
|
|
437
|
-
applier:
|
|
438
|
-
instruction:
|
|
447
|
+
action: applier.action,
|
|
448
|
+
applier: applier.name,
|
|
449
|
+
instruction: applier.instruction(pkg),
|
|
450
|
+
apply: applier.apply ? applier.apply(pkg) : null,
|
|
439
451
|
};
|
|
440
452
|
}
|
|
441
453
|
|
|
454
|
+
/**
|
|
455
|
+
* The ways this product reaches a machine, and what "update it" means for each.
|
|
456
|
+
*
|
|
457
|
+
* `apply` names argv to run — it is what the window's Update button and the
|
|
458
|
+
* CLI's `/upgrade apply` execute. `null` means there is nothing to install:
|
|
459
|
+
* `npx` fetches `latest` on every launch by definition, and a source checkout
|
|
460
|
+
* belongs to its owner's git remote.
|
|
461
|
+
*/
|
|
462
|
+
const APPLIERS = Object.freeze({
|
|
463
|
+
npm: Object.freeze({
|
|
464
|
+
name: 'npm',
|
|
465
|
+
action: 'npm-update',
|
|
466
|
+
instruction: (pkg) => `npm i -g ${pkg}@latest`,
|
|
467
|
+
apply: (pkg) => ({ command: 'npm', args: ['i', '-g', `${pkg}@latest`] }),
|
|
468
|
+
}),
|
|
469
|
+
pip: Object.freeze({
|
|
470
|
+
name: 'pip',
|
|
471
|
+
action: 'pip-update',
|
|
472
|
+
// The published pip package is a launcher for the npm one, so this is
|
|
473
|
+
// genuinely a different command — not an npm call with a different word.
|
|
474
|
+
instruction: (pkg) => `pip install -U ${pkg}`,
|
|
475
|
+
apply: (pkg) => ({ command: process.platform === 'win32' ? 'python' : 'python3',
|
|
476
|
+
args: ['-m', 'pip', 'install', '-U', pkg] }),
|
|
477
|
+
}),
|
|
478
|
+
npx: Object.freeze({
|
|
479
|
+
name: 'none',
|
|
480
|
+
action: 'npx-update',
|
|
481
|
+
instruction: () => 'already fetched fresh on every run — restart to pick up the new version',
|
|
482
|
+
apply: null,
|
|
483
|
+
}),
|
|
484
|
+
source: Object.freeze({
|
|
485
|
+
name: 'git',
|
|
486
|
+
action: 'source-update',
|
|
487
|
+
instruction: () => 'git pull && npm ci (this copy is a source checkout)',
|
|
488
|
+
apply: null,
|
|
489
|
+
}),
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Which installer owns the copy that is running — so the sentence names a
|
|
494
|
+
* command that actually changes THIS binary.
|
|
495
|
+
*
|
|
496
|
+
* Order matters. An explicit declaration wins (the pip launcher sets
|
|
497
|
+
* `AEGIS_INSTALL_METHOD=pip` before exec'ing the real CLI, which is the only
|
|
498
|
+
* way the npm package can know a Python install is driving it). Then npx, which
|
|
499
|
+
* is detectable from the argv it builds. Then a source checkout, then npm.
|
|
500
|
+
*
|
|
501
|
+
* Pure and injectable: `env`, `argv` and a file probe, no `process` reads, so a
|
|
502
|
+
* test can assert every branch without npm or pip being installed.
|
|
503
|
+
*/
|
|
504
|
+
function detectInstallMethod({
|
|
505
|
+
env = {}, argv = [], pkg = PKG, fileExists = () => false, entry = '',
|
|
506
|
+
} = {}) {
|
|
507
|
+
const declared = String((env && env.AEGIS_INSTALL_METHOD) || '').trim().toLowerCase();
|
|
508
|
+
if (declared && Object.prototype.hasOwnProperty.call(APPLIERS, declared)) return declared;
|
|
509
|
+
|
|
510
|
+
const joined = argv.map((a) => String(a)).join(' ');
|
|
511
|
+
if (/\bnpx\b/.test(joined) || /_npx[\\/]/.test(joined) || /_npx[\\/]/.test(entry)) return 'npx';
|
|
512
|
+
if (/[\\/]pipx[\\/]venvs[\\/]/.test(entry) || /[\\/]site-packages[\\/]/.test(entry)) return 'pip';
|
|
513
|
+
if (/[\\/]node_modules[\\/]/.test(entry)) return 'npm';
|
|
514
|
+
// A git checkout has the repo's own marker files; a global npm install does
|
|
515
|
+
// not (they are not in the package's `files` list).
|
|
516
|
+
if (fileExists('.git') && fileExists('client/update.js')) return 'source';
|
|
517
|
+
return 'npm';
|
|
518
|
+
}
|
|
519
|
+
|
|
442
520
|
/**
|
|
443
521
|
* The same once-a-day check as `updateNotice`, but *awaited* and detailed.
|
|
444
522
|
*
|
|
@@ -518,11 +596,23 @@ async function checkPublished({
|
|
|
518
596
|
* Rendered from `updatePlan`, not from a second copy of the sentence: the
|
|
519
597
|
* command the terminal tells the user to run and the command the window's
|
|
520
598
|
* banner offers are the same string produced by the same verdict.
|
|
599
|
+
*
|
|
600
|
+
* `method` is the install channel the caller detected (see
|
|
601
|
+
* `detectInstallMethod`). It is threaded through rather than assumed to be npm
|
|
602
|
+
* because the previous version returned `null` — silence — for every channel
|
|
603
|
+
* that was not npm, so a pip install and an npx run were never told a release
|
|
604
|
+
* existed. A host that knows how it was installed should say so.
|
|
521
605
|
*/
|
|
522
|
-
function updateLine({ current, latest, behind, pkg = PKG }) {
|
|
523
|
-
const plan = updatePlan({ current, latest, behind, channel: 'npm', pkg });
|
|
524
|
-
if (plan.
|
|
525
|
-
|
|
606
|
+
function updateLine({ current, latest, behind, pkg = PKG, method = 'npm' }) {
|
|
607
|
+
const plan = updatePlan({ current, latest, behind, channel: 'npm', pkg, method });
|
|
608
|
+
if (!plan.behind) return null;
|
|
609
|
+
const head = `Update available: ${plan.current} → ${plan.latest}`;
|
|
610
|
+
// `apply` is null for the two channels with nothing to install, whose
|
|
611
|
+
// instruction is already a sentence — prefixing those with "run:" would read
|
|
612
|
+
// as a command that does not exist.
|
|
613
|
+
return plan.apply
|
|
614
|
+
? `${head} run: ${plan.instruction}`
|
|
615
|
+
: `${head} ${plan.instruction}`;
|
|
526
616
|
}
|
|
527
617
|
|
|
528
618
|
/**
|
|
@@ -607,6 +697,8 @@ module.exports = {
|
|
|
607
697
|
checkPublished,
|
|
608
698
|
updatePlan,
|
|
609
699
|
updateLine,
|
|
700
|
+
detectInstallMethod,
|
|
701
|
+
APPLIERS,
|
|
610
702
|
PKG,
|
|
611
703
|
CHECK_INTERVAL_MS,
|
|
612
704
|
REASONS,
|
|
@@ -167,6 +167,32 @@ function normalizeToolArgs(T, name, args, ctx) {
|
|
|
167
167
|
return fn(name, args, ctx);
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
/**
|
|
171
|
+
* Is `dir` inside a git work tree? Walks up the way git itself does, so a turn
|
|
172
|
+
* running in a subdirectory of a repo is still told it is one.
|
|
173
|
+
*
|
|
174
|
+
* Returns `'git'`, `''` (definitely not a repo), or `null` when the probe could
|
|
175
|
+
* not answer — the caller omits the line rather than asserting "not a repo",
|
|
176
|
+
* because a wrong negative is exactly the kind of fact a model will act on.
|
|
177
|
+
*/
|
|
178
|
+
function detectVcs(dir) {
|
|
179
|
+
if (!dir) return null;
|
|
180
|
+
try {
|
|
181
|
+
const fs = require('node:fs');
|
|
182
|
+
const path = require('node:path');
|
|
183
|
+
let probe = path.resolve(String(dir));
|
|
184
|
+
for (let i = 0; i < 8; i += 1) {
|
|
185
|
+
if (fs.existsSync(path.join(probe, '.git'))) return 'git';
|
|
186
|
+
const up = path.dirname(probe);
|
|
187
|
+
if (up === probe) break;
|
|
188
|
+
probe = up;
|
|
189
|
+
}
|
|
190
|
+
return '';
|
|
191
|
+
} catch {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
170
196
|
function hostEnv(base = {}, supplied = {}, payload = null) {
|
|
171
197
|
const b = base || {};
|
|
172
198
|
const s = supplied || {};
|
|
@@ -250,6 +276,16 @@ function hostEnv(base = {}, supplied = {}, payload = null) {
|
|
|
250
276
|
// a `{ key, value }` facet, or a bare string.
|
|
251
277
|
languages: pick('languages', b.languages),
|
|
252
278
|
cwd: pick('cwd', cwd),
|
|
279
|
+
// Whether the turn's directory is a git work tree, probed once per turn.
|
|
280
|
+
// Measured reason: the work rules order the model to check prior work with
|
|
281
|
+
// `git log` before it starts, and a benchmark workspace (a temp dir holding
|
|
282
|
+
// three files) is NOT a repo. On every task the model dutifully spent its
|
|
283
|
+
// second round on `cd … && git log`, paid a failed exec, and carried the
|
|
284
|
+
// error text into every later round's prompt — one wasted round in seven,
|
|
285
|
+
// and a bigger prefix for the rest. The host already knew; this states it
|
|
286
|
+
// so the rule can say "skip the sources the workspace does not have" and
|
|
287
|
+
// mean something the model can act on without guessing.
|
|
288
|
+
vcs: pick('vcs', b.vcs != null ? b.vcs : detectVcs(cwd)),
|
|
253
289
|
shell: pick('shell', shellName),
|
|
254
290
|
shellKind: pick('shellKind', shellKind),
|
|
255
291
|
roots: pick('roots', b.roots),
|
|
@@ -709,6 +745,7 @@ const { offerableCatalog } = requireSharedBrain();
|
|
|
709
745
|
const { withByokAdditions } = requireSharedByokCatalog();
|
|
710
746
|
const {
|
|
711
747
|
withUserModels,
|
|
748
|
+
unmatchedUserProviders,
|
|
712
749
|
load: loadUserModels,
|
|
713
750
|
addUserModel,
|
|
714
751
|
removeUserModel,
|
|
@@ -1635,6 +1672,16 @@ function createLocalEngine({
|
|
|
1635
1672
|
// it via `fee.require_balance` below.
|
|
1636
1673
|
let providers = [];
|
|
1637
1674
|
let fee = null;
|
|
1675
|
+
// Did the CATALOG itself fail to arrive, as opposed to arriving empty?
|
|
1676
|
+
// The two are different states and the picker must not confuse them: a
|
|
1677
|
+
// 5xx / offline relay used to fall into the bare `catch` below and hand
|
|
1678
|
+
// back `providers: []`, which reads on screen exactly like an account
|
|
1679
|
+
// with nothing configured — while the user's provider row and their
|
|
1680
|
+
// `models.json` declaration sat intact on disk. Reported instead, the
|
|
1681
|
+
// same way the 'local' branch reports `listed: false` for a tag list
|
|
1682
|
+
// that did not arrive.
|
|
1683
|
+
let providersFailed = false;
|
|
1684
|
+
let providersError = null;
|
|
1638
1685
|
try {
|
|
1639
1686
|
const data = await aegis.byokProviders();
|
|
1640
1687
|
// The server's catalog, plus the ids it does not name but the vendor
|
|
@@ -1652,8 +1699,16 @@ function createLocalEngine({
|
|
|
1652
1699
|
// Absent until the server publishes one, and the UI must then say
|
|
1653
1700
|
// nothing rather than show a guess.
|
|
1654
1701
|
fee = (data && data.fee) || null;
|
|
1655
|
-
} catch {
|
|
1702
|
+
} catch (err) {
|
|
1703
|
+
// Keep the empty list (nothing to offer) but SAY why, so the renderer
|
|
1704
|
+
// can distinguish "catalog unreachable" from "catalog said none". The
|
|
1705
|
+
// message is carried rather than a boolean alone because the two cases
|
|
1706
|
+
// need different copy: offline wants a retry, a server error wants the
|
|
1707
|
+
// status. `err.message` is the transport's own text, already shaped
|
|
1708
|
+
// elsewhere in this file.
|
|
1656
1709
|
providers = [];
|
|
1710
|
+
providersFailed = true;
|
|
1711
|
+
providersError = (err && err.message) || String(err);
|
|
1657
1712
|
}
|
|
1658
1713
|
const models = [];
|
|
1659
1714
|
for (const p of providers) {
|
|
@@ -1689,6 +1744,18 @@ function createLocalEngine({
|
|
|
1689
1744
|
needsProviderKey: models.length > 0 && !models.some((m) => m.configured),
|
|
1690
1745
|
needsAegisKey: !aegis.apiKey,
|
|
1691
1746
|
fee,
|
|
1747
|
+
// True only when the catalog did not arrive — never merely because it
|
|
1748
|
+
// arrived with no providers. `withUserModels` never fabricates a
|
|
1749
|
+
// provider, so this list is the same either side of the fold above.
|
|
1750
|
+
providersFailed,
|
|
1751
|
+
providersError,
|
|
1752
|
+
// Declarations in `models.json` naming a provider the catalog does not
|
|
1753
|
+
// list — a typo, or a provider renamed/dropped server-side. `withUserModels`
|
|
1754
|
+
// deliberately does NOT invent a row for them (it would 401 on its first
|
|
1755
|
+
// turn), but silence is the other wrong answer: the model stays in the
|
|
1756
|
+
// file and the user is entitled to know the picker cannot show it.
|
|
1757
|
+
// Carried as the ids alone; the renderer names them.
|
|
1758
|
+
unmatchedProviders: unmatchedUserProviders(providers),
|
|
1692
1759
|
};
|
|
1693
1760
|
}
|
|
1694
1761
|
if (cls === 'local') {
|
|
@@ -2408,6 +2475,32 @@ function createLocalEngine({
|
|
|
2408
2475
|
const refusal = localT.remoteRefusal(cfg.baseURL || localT.DEFAULT_BASE);
|
|
2409
2476
|
if (refusal) throw refusal;
|
|
2410
2477
|
}
|
|
2478
|
+
// `custom` is the mirror of `local`: both are rows whose payload is an
|
|
2479
|
+
// ADDRESS rather than a credential, and both are unusable without it.
|
|
2480
|
+
// They differ in what absence MEANS. A blank `local` row falls back to
|
|
2481
|
+
// DEFAULT_BASE (the stock Ollama port) because there is exactly one
|
|
2482
|
+
// sensible address to guess. A blank `custom` row has no default at all —
|
|
2483
|
+
// the catalog descriptor pins none, so the server refuses the call with a
|
|
2484
|
+
// bare 400 that says nothing about which half of the setup is missing.
|
|
2485
|
+
//
|
|
2486
|
+
// Caught here, before any byte goes out, so the message can name the
|
|
2487
|
+
// command that fixes it. Reachable in practice: `/byok-key custom <key>`
|
|
2488
|
+
// stores a key with no address, and the CLI explicitly trusts an
|
|
2489
|
+
// unreachable catalog rather than refusing the id — so a user who typed
|
|
2490
|
+
// the key first and the endpoint never has a row that looks configured.
|
|
2491
|
+
// Keyed on the provider, not the class: every other byok provider's host
|
|
2492
|
+
// is a server-side constant and needs no address from us.
|
|
2493
|
+
if (cls === 'byok' && byokParts.provider === 'custom' && !(cfg.baseURL || '').trim()) {
|
|
2494
|
+
const err = new Error(
|
|
2495
|
+
'No endpoint saved for the "custom" provider — its key is on this machine but the address ' +
|
|
2496
|
+
'it dials is not, and no default exists for a vendor AEGIS does not know. Fix: ' +
|
|
2497
|
+
'/model-add custom <https-base-url> <api-key> <model-id> (writes both halves), or the ' +
|
|
2498
|
+
'endpoint field in Settings › Provider (custom).'
|
|
2499
|
+
);
|
|
2500
|
+
err.status = 400;
|
|
2501
|
+
err.code = 'custom_endpoint_missing';
|
|
2502
|
+
throw err;
|
|
2503
|
+
}
|
|
2411
2504
|
const base = {
|
|
2412
2505
|
cls, model, mode: payload && payload.mode, maxTokens, statedMaxTokens, autonomous, sessionId, signal, onDelta, cfg, apiKey, toolChoice,
|
|
2413
2506
|
// The turn's working directory, computed above as `turnCwd` — `dispatch`
|
|
@@ -2563,7 +2656,34 @@ function createLocalEngine({
|
|
|
2563
2656
|
// dispatch is summed, including the truncation retry and the synthesis
|
|
2564
2657
|
// re-dispatch: both are real, separately billed provider calls.
|
|
2565
2658
|
const turnUsage = { calls: 0 };
|
|
2566
|
-
|
|
2659
|
+
// The cache fields MUST be listed here, not just summed at the top level.
|
|
2660
|
+
// DeepSeek reports its hit count as `prompt_cache_hit_tokens` and its
|
|
2661
|
+
// miss count as `prompt_cache_miss_tokens`, and neither name was in this
|
|
2662
|
+
// list — so every tool-using turn dropped them on the way out and handed
|
|
2663
|
+
// its caller a usage object with no cache information at all. The CLI's
|
|
2664
|
+
// `--json` republishes exactly this accumulator, `usageBuckets` then had
|
|
2665
|
+
// nothing to read, and the published cost of an agentic run was priced
|
|
2666
|
+
// entirely at the miss rate. Measured on the 3-task sweep: `cache_read: 0`
|
|
2667
|
+
// on all three trials (tokens_in 210,904) while the row's own baseline
|
|
2668
|
+
// showed 72,448 cached tokens. The same defect the CLI's per-turn readout
|
|
2669
|
+
// was fixed for, here one layer below it.
|
|
2670
|
+
const USAGE_FIELDS = [
|
|
2671
|
+
'input_tokens', 'output_tokens', 'prompt_tokens', 'completion_tokens', 'total_tokens',
|
|
2672
|
+
// Anthropic spelling (disjoint from its input count).
|
|
2673
|
+
'cache_read_input_tokens', 'cache_creation_input_tokens',
|
|
2674
|
+
// DeepSeek/OpenAI spelling (both SUBSETs of the prompt count, which is
|
|
2675
|
+
// what `usageBuckets` detects and subtracts rather than double-billing).
|
|
2676
|
+
'prompt_cache_hit_tokens', 'prompt_cache_miss_tokens',
|
|
2677
|
+
// Hidden deliberation, which every provider here bills as OUTPUT but
|
|
2678
|
+
// none of them split out for free. These were absent from the list
|
|
2679
|
+
// while `reasoningTokensOf` (below) already knew how to read them, so
|
|
2680
|
+
// the one place that could have separated "wrote more code" from
|
|
2681
|
+
// "thought longer" threw the split away at the accumulator and handed
|
|
2682
|
+
// its caller a single `output_tokens` with CoT folded in. A benchmark
|
|
2683
|
+
// row could therefore see that a turn cost 1.9x another's output and
|
|
2684
|
+
// still have no way to say which half moved.
|
|
2685
|
+
'reasoning_tokens', 'thinking_tokens',
|
|
2686
|
+
];
|
|
2567
2687
|
const addUsage = (res) => {
|
|
2568
2688
|
const u = res && res.usage;
|
|
2569
2689
|
if (!u || typeof u !== 'object') return;
|
|
@@ -2961,6 +3081,22 @@ function createLocalEngine({
|
|
|
2961
3081
|
});
|
|
2962
3082
|
}
|
|
2963
3083
|
}
|
|
3084
|
+
} catch (e) {
|
|
3085
|
+
// Stamp the stop at the one place it is known for certain.
|
|
3086
|
+
//
|
|
3087
|
+
// `cancel(sessionId)` aborts THIS turn's controller, and the in-flight
|
|
3088
|
+
// transport unwinds as a rejection. The host has to tell that rejection
|
|
3089
|
+
// apart from a genuine provider/transport failure before it can stop
|
|
3090
|
+
// printing Ctrl-X as an application crash — and it used to guess from the
|
|
3091
|
+
// message text, which is exactly how a real failure ("connection aborted
|
|
3092
|
+
// by peer", "upstream aborted the connection") gets relabelled as a
|
|
3093
|
+
// deliberate stop and leaves the user with a silently empty answer. The
|
|
3094
|
+
// message is not evidence. This is: the signal reads aborted only because
|
|
3095
|
+
// the user asked for it, so it cannot be confused with anything upstream
|
|
3096
|
+
// did. Attached to the error object itself so it survives any rethrow,
|
|
3097
|
+
// and read by `isAbortShapedError` in desktop/main.js.
|
|
3098
|
+
if (signal.aborted && e && typeof e === 'object') e.aegisCancelled = true;
|
|
3099
|
+
throw e;
|
|
2964
3100
|
} finally {
|
|
2965
3101
|
if (shell) shell.dispose();
|
|
2966
3102
|
controllers.delete(sessionId);
|
|
@@ -203,9 +203,15 @@ function byokFeeLine(fee) {
|
|
|
203
203
|
// default-off gate after it. Joined with ' — ' only when there IS a second
|
|
204
204
|
// clause: a sentence-ending dash with nothing after it ("…provider's bill —.")
|
|
205
205
|
// is what the first live run of this line actually printed.
|
|
206
|
+
//
|
|
207
|
+
// This rate is the deployment's published RATE, not a quote for the reader
|
|
208
|
+
// specifically — an Unlimited subscriber is waived from this fee entirely
|
|
209
|
+
// (billing_service.is_unlimited on aegis1), so the number above is what a
|
|
210
|
+
// Free-tier BYOK caller pays, not what everyone pays.
|
|
206
211
|
const price = `Bring your own key: relayed through AEGIS, handled at `
|
|
207
212
|
+ `${ratePerMillion(inRate)} in / ${ratePerMillion(outRate)} out, `
|
|
208
|
-
+ `on top of your provider's bill
|
|
213
|
+
+ `on top of your provider's bill — no fee at all on Unlimited, `
|
|
214
|
+
+ `and no fee at all during the free 1-month Unlimited trial`;
|
|
209
215
|
let clause = '';
|
|
210
216
|
if (f.require_account === true) {
|
|
211
217
|
clause = 'and needs an AEGIS account key (X-AEGIS-Key) for the fee to be billed';
|
|
@@ -30,50 +30,62 @@
|
|
|
30
30
|
|
|
31
31
|
/** Identity + work rules. Ported from the upstream engine reference. */
|
|
32
32
|
const MAIN_CHAT_PROMPT =
|
|
33
|
-
`You are Aegiscodex, a terminal coding assistant
|
|
34
|
-
`
|
|
35
|
-
|
|
33
|
+
`You are Aegiscodex, a terminal coding assistant working in the user's repository: read and ` +
|
|
34
|
+
`reason about code, write and edit files, run shell commands, investigate bugs. Work rules:\n` +
|
|
35
|
+
`- Output is billed by the token and is the largest line on the bill, so spend it where it is ` +
|
|
36
|
+
` read. Before a tool call, one short sentence on what you are about to find out. Do NOT ` +
|
|
37
|
+
` restate file contents, diffs, command output or test results the user can already see. ` +
|
|
38
|
+
` Finish with the answer in a few lines — expand only when asked to explain, or when the ` +
|
|
39
|
+
` change's correctness depends on a detail the user must check.\n` +
|
|
40
|
+
`- Batch independent tool calls into ONE turn: read several files, or grep for several ` +
|
|
41
|
+
` patterns, at once, or use one exec command that does the whole job. Every round ` +
|
|
42
|
+
` re-sends the prefix and bills fresh output; one call per round is the expensive shape.\n` +
|
|
36
43
|
`- Use tools silently. A one-line reason is enough; do not narrate your plan as a story. ` +
|
|
37
44
|
`- Never claim what a tool found or what a command returned before the tool actually runs. ` +
|
|
38
45
|
` Report only the results you really received. ` +
|
|
39
|
-
`- Before
|
|
40
|
-
` it
|
|
41
|
-
`
|
|
42
|
-
`
|
|
43
|
-
`
|
|
44
|
-
`
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
`
|
|
48
|
-
`
|
|
46
|
+
`- Before starting a fix or feature, check whether they have asked for it before and whether ` +
|
|
47
|
+
` it was delivered: recalled memory, \`queue.jsonl\`, \`PLAN.md\`/notes and \`git log\` — ` +
|
|
48
|
+
` ONE batched command over sources that exist: if the Environment block says this ` +
|
|
49
|
+
` directory has no version control, skip it. ` +
|
|
50
|
+
` If it was resolved before and the problem is back, report how it was resolved and ` +
|
|
51
|
+
` why it regressed, then fix the cause — never re-fix blind as if it were new. ` +
|
|
52
|
+
` If it was never met, say so plainly before starting. ` +
|
|
53
|
+
`- Match the response to the request. A greeting, a question you already know the answer to, ` +
|
|
54
|
+
` or a request for an opinion is answered in plain words with NO tools. Reach for a tool ` +
|
|
55
|
+
` only when the answer depends on something in this repo or on this machine. ` +
|
|
56
|
+
` "hey" is not a task.\n` +
|
|
49
57
|
`- WHEN THE USER HAS ASKED FOR WORK: act, don't just inspect. After at most 2 rounds of ` +
|
|
50
58
|
` reading or exploration, start making changes with writeFile or editFile. Reconnaissance ` +
|
|
51
|
-
` is not progress — implement, then verify. This
|
|
52
|
-
`
|
|
59
|
+
` is not progress — implement, then verify. This is about HOW to carry out a task you were ` +
|
|
60
|
+
` given; it is never a reason to invent one. Never write or modify a file the user ` +
|
|
53
61
|
` did not ask you to touch.\n` +
|
|
54
|
-
`- Zero tolerance for stalling: once the
|
|
55
|
-
`
|
|
56
|
-
`
|
|
57
|
-
`
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
` user's question. Never end your turn with an intention like "Let me check…" or "I'll now…" ` +
|
|
61
|
-
` — that is not an answer. ` +
|
|
62
|
+
`- Zero tolerance for stalling: once the cause is identified and only the edit remains, make ` +
|
|
63
|
+
` it in the same turn. Never end a turn with an empty or no-op response, or a "let me ` +
|
|
64
|
+
` continue"/"I'll now…" placeholder when the user says continue — that wastes their turn. ` +
|
|
65
|
+
` This has been flagged as non-compliance before; treat it as a hard rule. ` +
|
|
66
|
+
`- When you have what you need, stop using tools and give a concise, direct answer. Never ` +
|
|
67
|
+
` end a turn with an intention like "Let me check…" — that is not an answer. ` +
|
|
62
68
|
`- When a focused multi-step sub-task can be delegated, use the task tool to spawn a ` +
|
|
63
|
-
` specialist subagent rather than doing
|
|
69
|
+
` specialist subagent rather than doing it inline. ` +
|
|
64
70
|
`- If the user references a workflow you don't recognize, inspect the repo/scripts for that ` +
|
|
65
|
-
` mechanism before acting
|
|
71
|
+
` mechanism before acting.`;
|
|
66
72
|
|
|
67
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* The tool line: what each tool is, and the two facts a schema cannot carry.
|
|
75
|
+
*
|
|
76
|
+
* It used to restate the path rule in full — absolute, `~` expansion, relative
|
|
77
|
+
* resolution — which `PATH_ARG_DESC` already says once per path argument in nine
|
|
78
|
+
* schemas. That duplication is what `d01068b` unwound from the schemas; this is
|
|
79
|
+
* the other end of it. What stays is the part no schema carries: the
|
|
80
|
+
* platform-specific example (the one form a model gets wrong) and the persistent
|
|
81
|
+
* shell, which is a property of the session rather than an argument.
|
|
82
|
+
*/
|
|
68
83
|
const TOOL_LINE =
|
|
69
|
-
'Tools: readFile, writeFile, editFile, listDir, glob, grep, exec, task. Paths are absolute
|
|
70
|
-
'
|
|
71
|
-
'
|
|
72
|
-
'
|
|
73
|
-
'
|
|
74
|
-
'exec runs in a persistent shell session on this machine — cd and exported env vars carry ' +
|
|
75
|
-
'across calls within the turn, like a real terminal. task spawns a specialist subagent ' +
|
|
76
|
-
'(its own tool loop, same model) for a focused, self-contained piece of work.';
|
|
84
|
+
'Tools: readFile, writeFile, editFile, listDir, glob, grep, exec, task. Paths are absolute ' +
|
|
85
|
+
'in the form THIS machine uses (see the Environment block): on win32 that means ' +
|
|
86
|
+
'C:\\Users\\you\\Desktop\\file.txt, not /home/you/Desktop/file.txt or /tmp/file.txt. ' +
|
|
87
|
+
'exec runs in a persistent shell session — cd and exported env vars carry across calls ' +
|
|
88
|
+
'within the turn. task spawns a specialist subagent (its own tool loop, same model).';
|
|
77
89
|
|
|
78
90
|
/**
|
|
79
91
|
* One durable-language entry as a sentence fragment, accepting the three shapes
|
|
@@ -109,6 +121,7 @@ function environmentPreamble(env = {}) {
|
|
|
109
121
|
localeName,
|
|
110
122
|
languages,
|
|
111
123
|
cwd,
|
|
124
|
+
vcs,
|
|
112
125
|
shell,
|
|
113
126
|
shellKind,
|
|
114
127
|
roots,
|
|
@@ -164,8 +177,7 @@ function environmentPreamble(env = {}) {
|
|
|
164
177
|
if (desktopdir) {
|
|
165
178
|
bits.push(
|
|
166
179
|
`desktop directory: ${desktopdir} — use this exact path when the user says "my desktop"; ` +
|
|
167
|
-
'do NOT build it yourself from the home directory,
|
|
168
|
-
'called "Desktop" there',
|
|
180
|
+
'do NOT build it yourself from the home directory',
|
|
169
181
|
);
|
|
170
182
|
}
|
|
171
183
|
// Same failure mode as the desktop line, one directory over, and reported
|
|
@@ -176,13 +188,31 @@ function environmentPreamble(env = {}) {
|
|
|
176
188
|
// missing path cannot tell a typo from an empty directory.
|
|
177
189
|
if (dataDir) {
|
|
178
190
|
bits.push(
|
|
179
|
-
`AEGIS data directory: ${dataDir} —
|
|
191
|
+
`AEGIS data directory: ${dataDir} — the store itself (config, sessions, ` +
|
|
180
192
|
'credentials, queue). Use this exact path; do NOT append it to the home directory ' +
|
|
181
193
|
'yourself, because a dropped separator ("C:\\Users\\you.aegiscode") names a path that ' +
|
|
182
194
|
'does not exist and looks like an empty directory rather than a mistake',
|
|
183
195
|
);
|
|
184
196
|
}
|
|
185
197
|
if (cwd) bits.push(`working directory: ${cwd}`);
|
|
198
|
+
// The version-control fact, which turns the work rules' "check whether this
|
|
199
|
+
// was already delivered" from a guess into a decision. Measured: in a temp
|
|
200
|
+
// workspace with no `.git`, the model still ran `git log` on its second round
|
|
201
|
+
// of all three tasks, spent a round on a guaranteed failure, and carried the
|
|
202
|
+
// error into the rest of the turn. Stated only when the host actually probed
|
|
203
|
+
// (`null`/`undefined` means "could not tell", and silence beats a wrong fact).
|
|
204
|
+
if (vcs === 'git') {
|
|
205
|
+
bits.push(
|
|
206
|
+
`version control: this directory IS inside a git work tree, so \`git log\`, ` +
|
|
207
|
+
'`git diff` and `git status` are usable for checking what was already done',
|
|
208
|
+
);
|
|
209
|
+
} else if (vcs === '') {
|
|
210
|
+
bits.push(
|
|
211
|
+
`version control: this directory is NOT a git repository and has no history to ` +
|
|
212
|
+
'consult — do NOT run `git log`, `git diff`, `git blame` or `git status`; they ' +
|
|
213
|
+
'fail here and cost a round. Read the files that exist instead',
|
|
214
|
+
);
|
|
215
|
+
}
|
|
186
216
|
if (shell) bits.push(`exec shell: ${shell}${shellKind ? ` (${shellKind})` : ''}`);
|
|
187
217
|
if (model) bits.push(`model: ${model}`);
|
|
188
218
|
if (appVersion) bits.push(`AEGIS Desktop ${appVersion}`);
|