aegiscode 6.8.3 → 6.8.5
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 +2 -2
- package/bin/aegiscode.js +35 -5
- package/package.json +1 -6
- package/scripts/predist.mjs +99 -0
- package/src/agents.js +1 -1
- package/src/app.js +41 -9
- package/src/caps.js +1 -1
- package/src/chatflow.js +182 -34
- package/src/checkpoint.js +1 -1
- package/src/clipboard.js +1 -1
- package/src/commands.js +158 -21
- package/src/config.js +2 -2
- package/src/deps.js +2 -1
- package/src/devrun.js +1 -1
- package/src/diff.js +1 -1
- package/src/events.js +38 -15
- package/src/export.js +1 -1
- package/src/fuzzy.js +1 -1
- package/src/history.js +3 -3
- package/src/init.js +1 -1
- package/src/input.js +1 -1
- package/src/keys.js +1 -1
- package/src/markdown.js +2 -2
- package/src/mcp.js +683 -0
- package/src/overlays.js +2 -2
- package/src/panels.js +52 -19
- package/src/permissions.js +2 -2
- package/src/render.js +2 -2
- package/src/screen.js +133 -8
- package/src/screens.js +1 -1
- package/src/summarize.js +1 -1
- package/src/system.js +2 -2
- package/src/theme.js +6 -6
- package/src/title.js +217 -0
- package/src/tokens.js +75 -96
- package/src/update.js +75 -1
- package/vendor/desktop/lib/local/agents.js +1 -1
- package/vendor/desktop/lib/local/autonomous.js +1 -1
- package/vendor/desktop/lib/local/engine.js +32 -8
- package/vendor/desktop/lib/local/git-scope.js +1 -1
- package/vendor/desktop/lib/local/prompt.js +3 -3
- package/vendor/desktop/lib/local/queue.js +2 -2
- package/vendor/desktop/lib/local/shell.js +1 -1
- package/vendor/desktop/lib/local/tools.js +2 -2
- package/vendor/desktop/lib/local/turn-guard.js +1 -1
- package/vendor/desktop/lib/local/worktree-lock.js +1 -1
- package/vendor/desktop/lib/settings.js +67 -0
- package/vendor/desktop/renderer/usage.js +377 -46
- package/vendor/hosts/install.js +638 -0
- package/vendor/hosts/openai-shim.js +419 -0
- package/vendor/hosts/spec.js +164 -0
- package/vendor/hosts/targets.js +346 -0
- package/vendor/mcp/server.js +186 -0
package/src/tokens.js
CHANGED
|
@@ -3,92 +3,36 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Token + cost estimation. Tokens are estimated from text length (~4
|
|
5
5
|
* chars/token, the usual rule of thumb) and priced against the per-model rates
|
|
6
|
-
*
|
|
6
|
+
* in the SHARED table. Everything is labeled approximate in the UI.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* The rate table itself is not here — see the block below.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
//
|
|
11
|
+
// ── The rate table is NOT defined here ─────────────────────────────────────
|
|
12
12
|
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
13
|
+
// This file used to carry its own copy of `RATES`, and that copy is how the
|
|
14
|
+
// DeepSeek row came to be wrong in one host and right in the other: the table
|
|
15
|
+
// existed twice (here and desktop/renderer/usage.js), so a rate read off the
|
|
16
|
+
// vendor's pricing page reached whichever copy someone happened to edit. The
|
|
17
|
+
// CLI's copy still said $0.14/$0.28 — the retired V4-Flash tier — while the
|
|
18
|
+
// desktop's had been corrected, and `/cost` would have disagreed with the GUI
|
|
19
|
+
// about the same turn on the same engine.
|
|
18
20
|
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
// This row was MISSING, and usageCost fell through to RATES.sonnet for every
|
|
31
|
-
// DeepSeek turn: $3.00/$15.00 per M against a real $0.14/$0.28 — 21x the
|
|
32
|
-
// input rate and 54x the output rate, on every direct DeepSeek call. That is
|
|
33
|
-
// the number that made a local turn look like it cost a fraction of the
|
|
34
|
-
// cloud's, when most of the reported gap was the meter itself.
|
|
35
|
-
//
|
|
36
|
-
// cacheRead is 0.1x input (aegis1 services/pricing.py
|
|
37
|
-
// CACHE_READ_FRACTION_BY_COMPANY["deepseek"] = 0.1 -> $0.014/M).
|
|
38
|
-
// cacheWrite is the input rate: DeepSeek bills a cache write as ordinary
|
|
39
|
-
// input tokens and charges no separate write premium, unlike Anthropic's
|
|
40
|
-
// 1.25x. A zero here would understate a session that writes cache.
|
|
41
|
-
deepseek: { input: 0.14, output: 0.28, cacheRead: 0.014, cacheWrite: 0.14 },
|
|
42
|
-
};
|
|
21
|
+
// So the table lives in exactly one place. `desktop/renderer/usage.js` is
|
|
22
|
+
// already the declared single source of truth for turning a provider's usage
|
|
23
|
+
// object into a display number (cli/src/deps.js resolves it, and
|
|
24
|
+
// test/cli-tools.test.mjs asserts the function identity), so the rates belong
|
|
25
|
+
// there too rather than in a second table that can only drift.
|
|
26
|
+
//
|
|
27
|
+
// `sharedpaths.js` is used rather than `deps.js` because deps.js eagerly
|
|
28
|
+
// requires the engine, the client and the tool registry — pulling all of that
|
|
29
|
+
// in to read a number would be a require cycle for anything in that graph.
|
|
30
|
+
const path = require('node:path');
|
|
43
31
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
* Anthropic spells its family *inside* the id — "claude-opus-4" matches no
|
|
47
|
-
* prefix — so prefix matching alone cannot see it.
|
|
48
|
-
*/
|
|
49
|
-
const RATE_FAMILIES = Object.keys(RATES).filter((k) => k !== 'default');
|
|
32
|
+
const { resolveShared } = require('./sharedpaths.js');
|
|
33
|
+
const shared = require(resolveShared(path.join('desktop', 'renderer', 'usage.js')));
|
|
50
34
|
|
|
51
|
-
|
|
52
|
-
* The rate row for a model id, provider, or alias. Exact id wins, then the
|
|
53
|
-
* longest matching prefix, then a family named inside the id, then the
|
|
54
|
-
* Sonnet-class default — the same resolution order contextWindowFor uses, so
|
|
55
|
-
* the cost meter and the context meter cannot disagree about which family a
|
|
56
|
-
* model belongs to.
|
|
57
|
-
*/
|
|
58
|
-
function ratesFor(model) {
|
|
59
|
-
const raw = String(model || '').toLowerCase();
|
|
60
|
-
if (!raw) return RATES.default;
|
|
61
|
-
// `/class byok` selects a "provider:model" id, and the provider half is a
|
|
62
|
-
// routing label, not a rate: rating it as written fell through every prefix
|
|
63
|
-
// to RATES.default, so an Opus BYOK turn was priced at Sonnet's $3/$15
|
|
64
|
-
// against the vendor's real $5/$25.
|
|
65
|
-
const ids = [raw];
|
|
66
|
-
const tail = raw.slice(raw.lastIndexOf(':') + 1);
|
|
67
|
-
if (tail && tail !== raw) ids.push(tail);
|
|
68
|
-
for (const id of ids) {
|
|
69
|
-
if (RATES[id]) return RATES[id];
|
|
70
|
-
let best = null;
|
|
71
|
-
let bestLen = 0;
|
|
72
|
-
for (const [prefix, rates] of Object.entries(RATES)) {
|
|
73
|
-
if (id.startsWith(prefix) && prefix.length > bestLen) {
|
|
74
|
-
best = rates;
|
|
75
|
-
bestLen = prefix.length;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (best) return best;
|
|
79
|
-
}
|
|
80
|
-
// Longest family-key hit wins, so an overlapping pair resolves the same way
|
|
81
|
-
// twice running rather than by object key order.
|
|
82
|
-
let family = null;
|
|
83
|
-
let familyLen = 0;
|
|
84
|
-
for (const key of RATE_FAMILIES) {
|
|
85
|
-
if (raw.includes(key) && key.length > familyLen) {
|
|
86
|
-
family = RATES[key];
|
|
87
|
-
familyLen = key.length;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return family || RATES.default;
|
|
91
|
-
}
|
|
35
|
+
const { RATES, RATE_BASIS, UNPRICED_BY_DESIGN, isPeak, ratesFor, costBreakdown, cacheHitRate } = shared;
|
|
92
36
|
|
|
93
37
|
// System prompt + tool definitions overhead, roughly, in tokens.
|
|
94
38
|
const SYSTEM_TOKENS = 18000;
|
|
@@ -127,11 +71,11 @@ const CONTEXT_WINDOWS = {
|
|
|
127
71
|
function contextWindowFor(model) {
|
|
128
72
|
const raw = String(model || '').toLowerCase();
|
|
129
73
|
if (!raw) return CONTEXT_WINDOW;
|
|
130
|
-
// Same two-candidate lookup as ratesFor
|
|
131
|
-
// id ("deepseek:deepseek-v4-flash") carries a routing label in
|
|
132
|
-
// model, and matching it as written left the 1M-token DeepSeek
|
|
133
|
-
// as the 200k default — a meter that would have told a user
|
|
134
|
-
// of a context that was 4% full.
|
|
74
|
+
// Same two-candidate lookup as ratesFor in the shared table, for the same
|
|
75
|
+
// reason: a byok id ("deepseek:deepseek-v4-flash") carries a routing label in
|
|
76
|
+
// front of the model, and matching it as written left the 1M-token DeepSeek
|
|
77
|
+
// window reading as the 200k default — a meter that would have told a user
|
|
78
|
+
// they were at 20% of a context that was 4% full.
|
|
135
79
|
const ids = [raw];
|
|
136
80
|
const tail = raw.slice(raw.lastIndexOf(':') + 1);
|
|
137
81
|
if (tail && tail !== raw) ids.push(tail);
|
|
@@ -168,14 +112,24 @@ function transcriptUsage(transcript, model = 'sonnet') {
|
|
|
168
112
|
return { input, output, cacheRead, cacheWrite };
|
|
169
113
|
}
|
|
170
114
|
|
|
171
|
-
/**
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Dollar cost of a usage record at the given model's rates.
|
|
117
|
+
*
|
|
118
|
+
* Returns a number for backward compatibility, but the basis is not lost: use
|
|
119
|
+
* `costBreakdown` when the caller needs to know whether the figure is real.
|
|
120
|
+
* (`usageCost` in the shared module, which also folds the record through
|
|
121
|
+
* `usageBuckets` first — so a wire usage object is normalized identically in
|
|
122
|
+
* both hosts, where this file's old copy read `usage.input` directly.)
|
|
123
|
+
*
|
|
124
|
+
* `model` has no `= 'sonnet'` default here either, and that matters for more
|
|
125
|
+
* than tidiness: a default parameter in THIS file would re-introduce exactly
|
|
126
|
+
* the split the shared module just removed, and only on the CLI side — so
|
|
127
|
+
* `usageCost(u)` would report `basis: 'exact'` in the terminal and
|
|
128
|
+
* `basis: 'default'` in the GUI for the same turn on the same engine. The
|
|
129
|
+
* whole point of delegating is that both hosts answer identically.
|
|
130
|
+
*/
|
|
131
|
+
function usageCost(usage, model, opts = {}) {
|
|
132
|
+
return shared.usageCost(usage, model, opts);
|
|
179
133
|
}
|
|
180
134
|
|
|
181
135
|
/** Full session accounting: per-bucket tokens, cost, and context used %. */
|
|
@@ -186,6 +140,14 @@ function sessionAccounting(transcript, model = 'sonnet') {
|
|
|
186
140
|
const history = usage.input + usage.output;
|
|
187
141
|
const used = system + tools + history;
|
|
188
142
|
const contextWindow = contextWindowFor(model);
|
|
143
|
+
// ONE breakdown, not a cost call plus a separate basis call: ratesFor reads
|
|
144
|
+
// the wall clock for peak/off-peak, so two evaluations straddling a peak
|
|
145
|
+
// boundary would report a peak cost with an off-peak basis (or vice versa) —
|
|
146
|
+
// two different claims about the same number, which is the thing this return
|
|
147
|
+
// shape exists to prevent. The upstream engine's sessionAccounting is written the
|
|
148
|
+
// same way; if one host folds this into two calls again the two will disagree
|
|
149
|
+
// about the same turn, which is how the rate table split in the first place.
|
|
150
|
+
const breakdown = costBreakdown(usage, model);
|
|
189
151
|
return {
|
|
190
152
|
usage,
|
|
191
153
|
system,
|
|
@@ -194,18 +156,24 @@ function sessionAccounting(transcript, model = 'sonnet') {
|
|
|
194
156
|
used,
|
|
195
157
|
contextWindow,
|
|
196
158
|
pct: Math.min(100, Math.round((used / contextWindow) * 100)),
|
|
197
|
-
cost:
|
|
159
|
+
cost: breakdown.cost,
|
|
160
|
+
// Which rate row priced this. 'default' means the model is unpriced and
|
|
161
|
+
// `cost` is a Sonnet-class placeholder — surfaced rather than swallowed so
|
|
162
|
+
// /cost can label it instead of printing a fabricated figure.
|
|
163
|
+
costBasis: breakdown.basis,
|
|
164
|
+
costPriced: breakdown.priced,
|
|
198
165
|
};
|
|
199
166
|
}
|
|
200
167
|
|
|
201
168
|
/**
|
|
202
|
-
*
|
|
169
|
+
* Build the same accounting shape from summed history.jsonl token
|
|
203
170
|
* records (live usage numbers when `real`, estimated otherwise). Real usage
|
|
204
171
|
* already includes system prompt + tools in cacheRead, so `used` counts
|
|
205
172
|
* input + output + cache instead of re-adding the constants.
|
|
206
173
|
*/
|
|
207
|
-
function accountingFromUsage(usage, model = 'sonnet', { exchanges = 0, real = false, costUsd } = {}) {
|
|
208
|
-
const
|
|
174
|
+
function accountingFromUsage(usage, model = 'sonnet', { exchanges = 0, real = false, costUsd, at } = {}) {
|
|
175
|
+
const breakdown = costBreakdown(usage, model, { at });
|
|
176
|
+
const cost = typeof costUsd === 'number' ? costUsd : breakdown.cost;
|
|
209
177
|
const used = real
|
|
210
178
|
? usage.input + usage.output + usage.cacheRead + usage.cacheWrite
|
|
211
179
|
: SYSTEM_TOKENS + TOOL_TOKENS + usage.input + usage.output;
|
|
@@ -219,6 +187,12 @@ function accountingFromUsage(usage, model = 'sonnet', { exchanges = 0, real = fa
|
|
|
219
187
|
contextWindow,
|
|
220
188
|
pct: Math.min(100, Math.round((used / contextWindow) * 100)),
|
|
221
189
|
cost,
|
|
190
|
+
// A settled charge (costUsd) is the ledger's own truth, so it is 'settled'
|
|
191
|
+
// rather than a table match — the pool's bill carries a margin and a
|
|
192
|
+
// prompt-cache discount the table cannot see, so the two must never be
|
|
193
|
+
// conflated.
|
|
194
|
+
costBasis: typeof costUsd === 'number' ? 'settled' : breakdown.basis,
|
|
195
|
+
costPriced: typeof costUsd === 'number' ? true : breakdown.priced,
|
|
222
196
|
exchanges,
|
|
223
197
|
real,
|
|
224
198
|
};
|
|
@@ -235,12 +209,17 @@ function fmtCost(d) {
|
|
|
235
209
|
|
|
236
210
|
module.exports = {
|
|
237
211
|
RATES,
|
|
212
|
+
RATE_BASIS,
|
|
213
|
+
UNPRICED_BY_DESIGN,
|
|
214
|
+
isPeak,
|
|
238
215
|
SYSTEM_TOKENS,
|
|
239
216
|
TOOL_TOKENS,
|
|
240
217
|
CONTEXT_WINDOW,
|
|
241
218
|
CONTEXT_WINDOWS,
|
|
242
219
|
contextWindowFor,
|
|
243
220
|
ratesFor,
|
|
221
|
+
costBreakdown,
|
|
222
|
+
cacheHitRate,
|
|
244
223
|
estimateTokens,
|
|
245
224
|
transcriptUsage,
|
|
246
225
|
usageCost,
|
package/src/update.js
CHANGED
|
@@ -7,7 +7,81 @@
|
|
|
7
7
|
* the same thing for `aegis-desktop`: two hosts, two package names, one
|
|
8
8
|
* checker. Resolved through deps.js so the in-repo and published-vendor
|
|
9
9
|
* layouts both work.
|
|
10
|
+
*
|
|
11
|
+
* On top of the shared checker this module carries the three pieces /upgrade
|
|
12
|
+
* needs — `compareVersions`, `upgradeAdvice` and `latestPublishedVersion` —
|
|
13
|
+
* ported from the upstream engine reference. They belong
|
|
14
|
+
* here, next to `isNewer`/`updateLine`, so the CLI has ONE idea of "is there a
|
|
15
|
+
* newer published version": the welcome-box notice and /upgrade now answer
|
|
16
|
+
* from the same place and compare versions the same way. The shared module's
|
|
17
|
+
* own functions are spread through unchanged, keeping the identity the
|
|
18
|
+
* update-channel test pins (the shim and the shared file must be the SAME
|
|
19
|
+
* code, not a copy).
|
|
10
20
|
*/
|
|
11
21
|
|
|
22
|
+
const { execFileSync } = require('node:child_process');
|
|
23
|
+
|
|
12
24
|
const { resolveShared } = require('./deps.js');
|
|
13
|
-
|
|
25
|
+
|
|
26
|
+
const shared = require(resolveShared('client/update.js'));
|
|
27
|
+
|
|
28
|
+
const VERSION = require('../package.json').version;
|
|
29
|
+
/** Both hosts publish from npm; the CLI is `aegiscode`. */
|
|
30
|
+
const PKG = shared.PKG || 'aegiscode';
|
|
31
|
+
|
|
32
|
+
// ── /upgrade ─────────────────────────────────────────────────────────────────
|
|
33
|
+
|
|
34
|
+
/** Compare two dotted version strings: -1 | 0 | 1 (prerelease tags ignored). */
|
|
35
|
+
function compareVersions(a, b) {
|
|
36
|
+
const pa = String(a || '0').split('-')[0].split('.').map((n) => Number.parseInt(n, 10) || 0);
|
|
37
|
+
const pb = String(b || '0').split('-')[0].split('.').map((n) => Number.parseInt(n, 10) || 0);
|
|
38
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
39
|
+
const d = (pa[i] || 0) - (pb[i] || 0);
|
|
40
|
+
if (d) return d > 0 ? 1 : -1;
|
|
41
|
+
}
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** What /upgrade should say, given the local and published versions. */
|
|
46
|
+
function upgradeAdvice({ current = VERSION, latest = null, packageName = PKG } = {}) {
|
|
47
|
+
if (!latest) {
|
|
48
|
+
return {
|
|
49
|
+
upToDate: null,
|
|
50
|
+
lines: [` Could not read the npm registry — local version is ${current}.`],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const cmp = compareVersions(latest, current);
|
|
54
|
+
if (cmp > 0) {
|
|
55
|
+
return {
|
|
56
|
+
upToDate: false,
|
|
57
|
+
lines: [
|
|
58
|
+
` Installed: ${current}`,
|
|
59
|
+
` Published: ${latest}`,
|
|
60
|
+
` Upgrade: npm i -g ${packageName}@latest`,
|
|
61
|
+
],
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
upToDate: true,
|
|
66
|
+
lines: [` Installed ${current} is the published ${latest} — nothing to upgrade.`],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Best-effort registry lookup (5s cap). Returns a version string or null. */
|
|
71
|
+
function latestPublishedVersion({ packageName = PKG, timeoutMs = 5000 } = {}) {
|
|
72
|
+
try {
|
|
73
|
+
const out = execFileSync('npm', ['view', packageName, 'version'], {
|
|
74
|
+
encoding: 'utf8', timeout: timeoutMs, stdio: ['ignore', 'pipe', 'ignore'],
|
|
75
|
+
});
|
|
76
|
+
const v = String(out).trim();
|
|
77
|
+
return /^\d+\.\d+\.\d+/.test(v) ? v : null;
|
|
78
|
+
} catch { return null; }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = {
|
|
82
|
+
...shared,
|
|
83
|
+
VERSION,
|
|
84
|
+
compareVersions,
|
|
85
|
+
upgradeAdvice,
|
|
86
|
+
latestPublishedVersion,
|
|
87
|
+
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* agents.js — subagent prompt presets for the desktop `task` tool, ported
|
|
5
|
-
* from
|
|
5
|
+
* from the upstream engine reference (same roles, same synthesis presets).
|
|
6
6
|
* A preset is a system prompt: `task` runs it through the normal engine.chat
|
|
7
7
|
* loop as a nested turn (its own tool rounds, same model class), not a
|
|
8
8
|
* separate runtime, so the presets are pure prompt composition.
|
|
@@ -311,7 +311,7 @@ function resolveEffort({ effort, env, fanout } = {}) {
|
|
|
311
311
|
|
|
312
312
|
/**
|
|
313
313
|
* The operating directive injected as the autonomous turn's prompt preamble.
|
|
314
|
-
* Ported verbatim in spirit from
|
|
314
|
+
* Ported verbatim in spirit from the upstream engine reference so both
|
|
315
315
|
* clients behave the same; duplicated rather than vendored because the plugin
|
|
316
316
|
* hosts no ESM build of that module.
|
|
317
317
|
*/
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* chosen class is the user's explicit selection.
|
|
9
9
|
*
|
|
10
10
|
* Since the tool-calling port it ALSO owns the agent loop (the client half of
|
|
11
|
-
*
|
|
11
|
+
* the upstream engine's src/backend.js runProvider): every turn carries a real
|
|
12
12
|
* system prompt (prompt.js) and the builtin tool schemas (tools.js), and when
|
|
13
13
|
* a provider answers with tool calls the loop executes them in-process and
|
|
14
14
|
* feeds the results back for as many rounds as the model keeps calling tools
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* executor never has to be exposed to the renderer.
|
|
28
28
|
*
|
|
29
29
|
* Two turn-scoped resources ride along with the loop, mirroring
|
|
30
|
-
*
|
|
30
|
+
* the upstream engine's runProvider exactly:
|
|
31
31
|
* - a lazily-started ShellSession (shell.js) that the `exec` tool shares,
|
|
32
32
|
* so cd/export state persists across calls within one turn instead of
|
|
33
33
|
* each call spawning a fresh process;
|
|
@@ -159,7 +159,7 @@ function providerKeyFromEnv(provider) {
|
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
/**
|
|
162
|
-
* Mirrors
|
|
162
|
+
* Mirrors the upstream engine's src/backend.js DEEPSEEK_REASONING_MODEL_RE +
|
|
163
163
|
* EFFORT_TOKEN_BUDGET verbatim. DeepSeek's reasoning models (deepseek-flash,
|
|
164
164
|
* i.e. "Flash 4.1", deepseek-v4-pro, the deprecated deepseek-reasoner, and the
|
|
165
165
|
* legacy v4-flash/v4.1-flash aliases some configs still carry) spend part of
|
|
@@ -170,7 +170,7 @@ function providerKeyFromEnv(provider) {
|
|
|
170
170
|
* tool calls, just a turn that "completes" with nothing to show for it (the
|
|
171
171
|
* empty-response bug). A user pointing the Custom OpenAI-compatible class
|
|
172
172
|
* straight at DeepSeek's API hits exactly this, so the request is sized by the
|
|
173
|
-
* same effort budget
|
|
173
|
+
* same effort budget the upstream engine uses for its own direct DeepSeek calls.
|
|
174
174
|
*
|
|
175
175
|
* desktop/renderer/budget.js carries the renderer's copy of these two
|
|
176
176
|
* constants plus budgetFor() below; test/budget.test.mjs requires both and
|
|
@@ -437,6 +437,18 @@ function createLocalEngine({
|
|
|
437
437
|
settings,
|
|
438
438
|
tools,
|
|
439
439
|
promptBuilder,
|
|
440
|
+
// The level's recall breadth, injected by the host that owns the
|
|
441
|
+
// avatar ledger (desktop/main.js builds one from lib/avatar/turn.js). It is a
|
|
442
|
+
// SEAM rather than a call into lib/avatar/* because this engine is shared with
|
|
443
|
+
// the CLI (cli/src/deps.js loads this file): the engine must not grow a
|
|
444
|
+
// dependency on the desktop's avatar directory, and a host with no avatar
|
|
445
|
+
// simply passes nothing and gets the exact pre-Phase-20 turn.
|
|
446
|
+
//
|
|
447
|
+
// `recallProvider({ payload, env, system })` may be sync or async and returns
|
|
448
|
+
// either the final system prompt or `{ system }`. It runs once per turn,
|
|
449
|
+
// before the first dispatch, and its result is the system prompt every round
|
|
450
|
+
// of that turn travels with.
|
|
451
|
+
recallProvider,
|
|
440
452
|
env,
|
|
441
453
|
getConfirmMode,
|
|
442
454
|
// Injectable for tests; defaults to the real transport so every existing
|
|
@@ -908,7 +920,7 @@ function createLocalEngine({
|
|
|
908
920
|
// that used to claim a figure for the pooled class is gone — see
|
|
909
921
|
// desktop/renderer/budget.js). Omitting the field is
|
|
910
922
|
// what tells aegis1 "no cap stated — let effort decide", the same
|
|
911
|
-
// contract
|
|
923
|
+
// contract the upstream engine sends.
|
|
912
924
|
//
|
|
913
925
|
// A cap the caller DID state is a different thing, and dropping it was
|
|
914
926
|
// a bug: aegis1 reads a body max_tokens as a ceiling over its ladder,
|
|
@@ -948,7 +960,7 @@ function createLocalEngine({
|
|
|
948
960
|
//
|
|
949
961
|
// Writing is still available, explicitly: the aegis_memory_save tool
|
|
950
962
|
// (mcp/tools.js; the CLI exposes it as /memory). Recall on every turn,
|
|
951
|
-
// store only what the user asks for — which is what
|
|
963
|
+
// store only what the user asks for — which is what the upstream engine's
|
|
952
964
|
// own cross-session memory does, and what this comment claimed to
|
|
953
965
|
// match while sending both halves.
|
|
954
966
|
//
|
|
@@ -1312,7 +1324,7 @@ function createLocalEngine({
|
|
|
1312
1324
|
let truncationRetried = false;
|
|
1313
1325
|
let synthesisDone = false;
|
|
1314
1326
|
|
|
1315
|
-
// Round cap —
|
|
1327
|
+
// Round cap — a bound the upstream engine has had all along and this engine
|
|
1316
1328
|
// did not. Removing the old fixed cap (12) was right in spirit and wrong
|
|
1317
1329
|
// in effect: it left the turn with NO horizon, and on 2026-09-15 the
|
|
1318
1330
|
// question "can you check the plan" ran ~70 rounds, grew the context
|
|
@@ -1321,7 +1333,7 @@ function createLocalEngine({
|
|
|
1321
1333
|
// re-sends the whole conversation, so an unbounded loop gets more
|
|
1322
1334
|
// expensive the longer it runs.
|
|
1323
1335
|
//
|
|
1324
|
-
// The numbers match
|
|
1336
|
+
// The numbers match the upstream engine's (src/autonomous.js) so both clients
|
|
1325
1337
|
// behave the same: 24 rounds for a chat turn, 40 for an autonomous one.
|
|
1326
1338
|
// Env-overridable for a deliberately long job.
|
|
1327
1339
|
// A stated horizon (env) still wins outright — an explicit number is the
|
|
@@ -1532,6 +1544,12 @@ function createLocalEngine({
|
|
|
1532
1544
|
statedMaxTokens: opts.statedMaxTokens ? doubledBudget(opts.statedMaxTokens) : undefined,
|
|
1533
1545
|
});
|
|
1534
1546
|
addUsage(res);
|
|
1547
|
+
// Same guard as line ~1499, for the same reason: an abort landing
|
|
1548
|
+
// during THIS dispatch also resolves as empty text, and without
|
|
1549
|
+
// this check that "no answer" would fall straight into the
|
|
1550
|
+
// empty-turn nudge below instead of ending the turn — a cancelled
|
|
1551
|
+
// request quietly buying a THIRD billed call.
|
|
1552
|
+
if (signal.aborted) return withTurnUsage(res);
|
|
1535
1553
|
}
|
|
1536
1554
|
|
|
1537
1555
|
const calls = toolSchemas.length ? extractToolCalls(res) : [];
|
|
@@ -1562,6 +1580,12 @@ function createLocalEngine({
|
|
|
1562
1580
|
tools: [],
|
|
1563
1581
|
});
|
|
1564
1582
|
addUsage(res);
|
|
1583
|
+
// Same guard again: a cancel landing during the synthesis pass
|
|
1584
|
+
// resolves empty too, and without this check it fell through to
|
|
1585
|
+
// emptyTurnError — a real exception, so the renderer painted a red
|
|
1586
|
+
// "no answer" failure over what was actually just the user hitting
|
|
1587
|
+
// Cancel.
|
|
1588
|
+
if (signal.aborted) return withTurnUsage(res);
|
|
1565
1589
|
if (!assistantText(res)) {
|
|
1566
1590
|
throw emptyTurnError({
|
|
1567
1591
|
cls,
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Minimal git worktree introspection: where the repo root is, and what is
|
|
5
5
|
* dirty right now with a content hash per path.
|
|
6
6
|
*
|
|
7
|
-
* Ported from
|
|
7
|
+
* Ported from the upstream engine reference (ESM → CommonJS). `turn-guard.js`
|
|
8
8
|
* uses `gitRoot` and `gitStatusSnapshot`; the queue now hosts the commit path
|
|
9
9
|
* too, so `foreignChanges` and `scopedCommit` are carried over as well — they
|
|
10
10
|
* were deliberately absent while nothing here queued work, because a copy of
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* prompt.js — the desktop client's system prompt (client half of
|
|
5
|
-
*
|
|
5
|
+
* the upstream engine's tool calling).
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* The upstream engine sends a real persona on every provider turn
|
|
8
8
|
* (src/backend.js MAIN_CHAT_PROMPT plus a docs/operating-context.md block).
|
|
9
9
|
* The desktop renderer used to send nothing at all, so every model answered a
|
|
10
10
|
* bare user string with no identity, no work rules and no idea which machine
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* repo roots the host already knows (main.js), so the model stops asking.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
/** Identity + work rules. Ported from
|
|
26
|
+
/** Identity + work rules. Ported from the upstream engine reference. */
|
|
27
27
|
const MAIN_CHAT_PROMPT =
|
|
28
28
|
`You are Aegiscodex, a terminal coding assistant that works in the user's repository. ` +
|
|
29
29
|
`Help with software engineering tasks: read and reason about code, write and edit files, ` +
|
|
@@ -443,8 +443,8 @@ function parsePlanStatus(text) {
|
|
|
443
443
|
if (line.trim() === '' || /^\s+\S/.test(line)) continue;
|
|
444
444
|
inStatus = false; // anything else (e.g. '---') ends the block
|
|
445
445
|
}
|
|
446
|
-
// Every PLAN.md in these repos writes `## Phase
|
|
447
|
-
// the number). A trailing `## Phase
|
|
446
|
+
// Every PLAN.md in these repos writes `## Phase N ✅ — title` (✅ right after
|
|
447
|
+
// the number). A trailing `## Phase N — title ✅` is accepted too, because
|
|
448
448
|
// reconcile reads plans other sessions and agents wrote, and a heading that
|
|
449
449
|
// says it shipped means it shipped wherever the ✅ sits.
|
|
450
450
|
const hm = line.match(/^##\s*Phase\s+(\d+)\b/);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* shell.js — a persistent shell session for the `exec` tool, ported from
|
|
5
|
-
*
|
|
5
|
+
* the upstream engine reference (client half of the same design).
|
|
6
6
|
*
|
|
7
7
|
* The desktop `exec` tool used to spawn ONE process per call: `cd /foo` in
|
|
8
8
|
* one turn had no effect on the next call, so a model that wanted to work
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* tools.js — the local tool layer for the desktop agent loop (client half of
|
|
5
|
-
*
|
|
5
|
+
* the upstream engine's tool calling).
|
|
6
6
|
*
|
|
7
|
-
* Two jobs, mirroring
|
|
7
|
+
* Two jobs, mirroring the upstream engine reference:
|
|
8
8
|
* 1. Tool schemas in the wire format each API family expects — Anthropic's
|
|
9
9
|
* `{name, description, input_schema}` vs OpenAI-compatible
|
|
10
10
|
* `{type:'function', function:{name, description, parameters}}`.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Turn-start foreign-write detection.
|
|
5
5
|
*
|
|
6
|
-
* Ported from
|
|
6
|
+
* Ported from the upstream engine reference (ESM → CommonJS).
|
|
7
7
|
*
|
|
8
8
|
* Bug this exists for: the commit-time scope check already knew how to tell
|
|
9
9
|
* "my changes" from "somebody else's in-flight work" — but only *after* a
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Cross-process lock on a git working tree.
|
|
5
5
|
*
|
|
6
|
-
* Ported from
|
|
6
|
+
* Ported from the upstream engine reference (ESM → CommonJS).
|
|
7
7
|
*
|
|
8
8
|
* Bug this exists for: nothing keyed on *the working tree*. A session-scoped
|
|
9
9
|
* lock only stops two processes resuming the SAME transcript, so three
|
|
@@ -74,6 +74,17 @@ const CONFIRM_MODE_NAMESPACE = '__confirmMode';
|
|
|
74
74
|
* what turns it off. Nothing secret lives here, so no encryption. */
|
|
75
75
|
const MEMORY_PERSIST_NAMESPACE = '__memoryPersist';
|
|
76
76
|
|
|
77
|
+
/** Reserved namespace for the avatar/companion preferences:
|
|
78
|
+
* `{ enabled, showLevel, motion }` — app-level, not a provider, so it stays out
|
|
79
|
+
* of the provider CRUD surface for the same reason the AEGIS key does. The
|
|
80
|
+
* persona itself is deliberately NOT stored here: it is a document, not a
|
|
81
|
+
* preference, and it lives at `<userData>/avatar/persona.json`, read and
|
|
82
|
+
* written by main through lib/avatar/store.js so a hand-edited or imported
|
|
83
|
+
* persona is validated on the way in.
|
|
84
|
+
* Defaults are the shipped behaviour: the avatar is ON, the level readout is
|
|
85
|
+
* shown, and motion follows the OS `prefers-reduced-motion` setting. */
|
|
86
|
+
const AVATAR_NAMESPACE = '__avatar';
|
|
87
|
+
|
|
77
88
|
/** Namespaces the provider-config surface must never see or mutate. */
|
|
78
89
|
const RESERVED_NAMESPACES = Object.freeze([
|
|
79
90
|
AEGIS_KEY_NAMESPACE,
|
|
@@ -81,8 +92,12 @@ const RESERVED_NAMESPACES = Object.freeze([
|
|
|
81
92
|
QUICK_LAUNCHER_NAMESPACE,
|
|
82
93
|
CONFIRM_MODE_NAMESPACE,
|
|
83
94
|
MEMORY_PERSIST_NAMESPACE,
|
|
95
|
+
AVATAR_NAMESPACE,
|
|
84
96
|
]);
|
|
85
97
|
|
|
98
|
+
/** Motion modes the renderer understands (`system` = follow the OS). */
|
|
99
|
+
const AVATAR_MOTION_MODES = Object.freeze(['system', 'full', 'minimal']);
|
|
100
|
+
|
|
86
101
|
/** True for the AEGIS-key namespace(s) — provider CRUD must refuse these. */
|
|
87
102
|
function isReservedNamespace(provider) {
|
|
88
103
|
return RESERVED_NAMESPACES.includes(provider);
|
|
@@ -359,6 +374,53 @@ function createSettingsStore({ dir, safeStorage } = {}) {
|
|
|
359
374
|
return memoryPersistState();
|
|
360
375
|
}
|
|
361
376
|
|
|
377
|
+
// --- Avatar: reserved namespace, plain preferences ------------
|
|
378
|
+
// The companion's on/off switch, its level readout, and its motion mode.
|
|
379
|
+
// Nothing secret lives here, so no encryption — same reasoning as the quick
|
|
380
|
+
// launcher and memory-persist namespaces above.
|
|
381
|
+
//
|
|
382
|
+
// Deliberately narrow: `setAvatar()` stores only these three known keys, so a
|
|
383
|
+
// renderer (or a hand-edited settings.json) cannot park arbitrary state — a
|
|
384
|
+
// persona document, a capability override — in a namespace main reads back.
|
|
385
|
+
// The persona is a separate, validated file (lib/avatar/store.js) for exactly
|
|
386
|
+
// that reason.
|
|
387
|
+
|
|
388
|
+
function getAvatar() {
|
|
389
|
+
const cfg = load()[AVATAR_NAMESPACE] || {};
|
|
390
|
+
return {
|
|
391
|
+
// Unset === true: the companion ships on; an explicit `false` is the only
|
|
392
|
+
// thing that turns it off (and it must survive a reload).
|
|
393
|
+
enabled: cfg.enabled === undefined ? true : Boolean(cfg.enabled),
|
|
394
|
+
showLevel: cfg.showLevel === undefined ? true : Boolean(cfg.showLevel),
|
|
395
|
+
motion: AVATAR_MOTION_MODES.includes(cfg.motion) ? cfg.motion : 'system',
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** `{ ...preferences, source }` — mirrors memoryPersistState() so "off" and
|
|
400
|
+
* "never set" stay distinguishable in the UI and in tests. */
|
|
401
|
+
function avatarState() {
|
|
402
|
+
const cfg = load()[AVATAR_NAMESPACE] || {};
|
|
403
|
+
return {
|
|
404
|
+
...getAvatar(),
|
|
405
|
+
source: cfg.enabled === undefined ? 'default' : 'config',
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/** Partial merge of the three known keys. Unknown keys are dropped, not saved. */
|
|
410
|
+
function setAvatar(patch = {}) {
|
|
411
|
+
const current = getAvatar();
|
|
412
|
+
const p = patch && typeof patch === 'object' ? patch : {};
|
|
413
|
+
const next = {
|
|
414
|
+
enabled: p.enabled === undefined ? current.enabled : Boolean(p.enabled),
|
|
415
|
+
showLevel: p.showLevel === undefined ? current.showLevel : Boolean(p.showLevel),
|
|
416
|
+
motion: AVATAR_MOTION_MODES.includes(p.motion) ? p.motion : current.motion,
|
|
417
|
+
};
|
|
418
|
+
const data = load();
|
|
419
|
+
data[AVATAR_NAMESPACE] = next;
|
|
420
|
+
save(data);
|
|
421
|
+
return avatarState();
|
|
422
|
+
}
|
|
423
|
+
|
|
362
424
|
return {
|
|
363
425
|
file,
|
|
364
426
|
get,
|
|
@@ -379,6 +441,9 @@ function createSettingsStore({ dir, safeStorage } = {}) {
|
|
|
379
441
|
getMemoryPersist,
|
|
380
442
|
memoryPersistState,
|
|
381
443
|
setMemoryPersist,
|
|
444
|
+
getAvatar,
|
|
445
|
+
avatarState,
|
|
446
|
+
setAvatar,
|
|
382
447
|
};
|
|
383
448
|
}
|
|
384
449
|
|
|
@@ -389,6 +454,8 @@ module.exports = {
|
|
|
389
454
|
QUICK_LAUNCHER_NAMESPACE,
|
|
390
455
|
CONFIRM_MODE_NAMESPACE,
|
|
391
456
|
MEMORY_PERSIST_NAMESPACE,
|
|
457
|
+
AVATAR_NAMESPACE,
|
|
458
|
+
AVATAR_MOTION_MODES,
|
|
392
459
|
DEFAULT_QUICK_LAUNCHER_SHORTCUT,
|
|
393
460
|
RESERVED_NAMESPACES,
|
|
394
461
|
isReservedNamespace,
|