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.
Files changed (53) hide show
  1. package/README.md +2 -2
  2. package/bin/aegiscode.js +35 -5
  3. package/package.json +1 -6
  4. package/scripts/predist.mjs +99 -0
  5. package/src/agents.js +1 -1
  6. package/src/app.js +41 -9
  7. package/src/caps.js +1 -1
  8. package/src/chatflow.js +182 -34
  9. package/src/checkpoint.js +1 -1
  10. package/src/clipboard.js +1 -1
  11. package/src/commands.js +158 -21
  12. package/src/config.js +2 -2
  13. package/src/deps.js +2 -1
  14. package/src/devrun.js +1 -1
  15. package/src/diff.js +1 -1
  16. package/src/events.js +38 -15
  17. package/src/export.js +1 -1
  18. package/src/fuzzy.js +1 -1
  19. package/src/history.js +3 -3
  20. package/src/init.js +1 -1
  21. package/src/input.js +1 -1
  22. package/src/keys.js +1 -1
  23. package/src/markdown.js +2 -2
  24. package/src/mcp.js +683 -0
  25. package/src/overlays.js +2 -2
  26. package/src/panels.js +52 -19
  27. package/src/permissions.js +2 -2
  28. package/src/render.js +2 -2
  29. package/src/screen.js +133 -8
  30. package/src/screens.js +1 -1
  31. package/src/summarize.js +1 -1
  32. package/src/system.js +2 -2
  33. package/src/theme.js +6 -6
  34. package/src/title.js +217 -0
  35. package/src/tokens.js +75 -96
  36. package/src/update.js +75 -1
  37. package/vendor/desktop/lib/local/agents.js +1 -1
  38. package/vendor/desktop/lib/local/autonomous.js +1 -1
  39. package/vendor/desktop/lib/local/engine.js +32 -8
  40. package/vendor/desktop/lib/local/git-scope.js +1 -1
  41. package/vendor/desktop/lib/local/prompt.js +3 -3
  42. package/vendor/desktop/lib/local/queue.js +2 -2
  43. package/vendor/desktop/lib/local/shell.js +1 -1
  44. package/vendor/desktop/lib/local/tools.js +2 -2
  45. package/vendor/desktop/lib/local/turn-guard.js +1 -1
  46. package/vendor/desktop/lib/local/worktree-lock.js +1 -1
  47. package/vendor/desktop/lib/settings.js +67 -0
  48. package/vendor/desktop/renderer/usage.js +377 -46
  49. package/vendor/hosts/install.js +638 -0
  50. package/vendor/hosts/openai-shim.js +419 -0
  51. package/vendor/hosts/spec.js +164 -0
  52. package/vendor/hosts/targets.js +346 -0
  53. package/vendor/mcp/server.js +186 -0
package/README.md CHANGED
@@ -58,12 +58,12 @@ product, so they are one name now:
58
58
  |---|---|
59
59
  | `aegiscode` | **this host**, v6.0.0. Installs a single binary, `aegiscode`. |
60
60
  | `aegis-terminal` | deprecated — the 0.1.x spelling of this package, folded into `aegiscode`. |
61
- | `aegiscode-cli` | 4.0.3, an earlier name of the full `aegisinfo/aegiscode` coding-assistant CLI. Untouched. |
61
+ | `aegiscode-cli` | 4.0.3, an earlier name of this CLI's predecessor line. Untouched. |
62
62
  | `aegis-cli` | 0.4.8 (unrelated). |
63
63
  | `aegis` (bin) | claimed **twice already** — by `aegiscode-cli` (→ `bin/cli.js`) and by `aegis-desktop` (→ `bin/aegis.js`). Pre-existing; whichever installs last wins. |
64
64
 
65
65
  Publishing this host as `aegiscode` moves the `latest` dist-tag for that name
66
- onto it. The previous line (`aegiscode@5.x`, the `aegisinfo/aegiscode` agent) is
66
+ onto it. The previous line (`aegiscode@5.x`, the earlier agent build) is
67
67
  still installable and immutable on the registry — pin `aegiscode@5` for it.
68
68
 
69
69
  ## Installation
package/bin/aegiscode.js CHANGED
@@ -41,11 +41,14 @@ Account:
41
41
  aegiscode logout remove the saved key
42
42
  aegiscode key status show which key is in use and where it came from
43
43
 
44
- Autonomous work queue (no terminal needed — cron/systemd/ssh friendly):
45
- aegiscode autonomous add "task" queue a task to run unattended
46
- aegiscode autonomous list show the queue (--json for machines)
47
- aegiscode autonomous proceed drain every pending task, then exit
48
- aegiscode autonomous help all subcommands and their flags
44
+ Automation:
45
+ aegiscode autonomous help run queued tasks with no terminal at all
46
+ aegiscode mcp install put AEGIS inside VS Code / Cursor / Zed /
47
+ Cline / Windsurf / … ('mcp list' shows them)
48
+ aegiscode mcp status which editors are configured, and do they work
49
+ aegiscode mcp shim OpenAI-compatible endpoint for clients that
50
+ take a base URL but speak no MCP
51
+ aegiscode mcp help all subcommands and their flags
49
52
 
50
53
  Options:
51
54
  -m, --model <id> pin a model id (see /models; default: server choice)
@@ -128,6 +131,17 @@ function parseArgs(argv) {
128
131
  opts.commandArg = sub;
129
132
  opts.commandArgv = argv.slice(argv[1] && !argv[1].startsWith('-') ? 2 : 1);
130
133
  argv = [];
134
+ } else if (head === 'mcp') {
135
+ // The editor-integration surface, wired exactly like `autonomous` and for
136
+ // the same reason: everything after `mcp <sub>` is the subcommand's argv
137
+ // (`--target cursor,zed` is not this parser's flag), so the tail is handed
138
+ // over untouched. A bare `mcp` is the status report — the question a user
139
+ // actually has ("is AEGIS in my editors?") — not a prompt and not an error.
140
+ const sub = argv[1] && !argv[1].startsWith('-') ? argv[1] : 'status';
141
+ opts.command = 'mcp';
142
+ opts.commandArg = sub;
143
+ opts.commandArgv = argv.slice(argv[1] && !argv[1].startsWith('-') ? 2 : 1);
144
+ argv = [];
131
145
  }
132
146
 
133
147
  for (let i = 0; i < argv.length; i++) {
@@ -472,6 +486,22 @@ async function main(argv = process.argv.slice(2)) {
472
486
  });
473
487
  }
474
488
 
489
+ // The editor-integration surface. Dispatched here rather than among the
490
+ // account commands because it is not about THIS run: `mcp install` edits files
491
+ // other programs read, and `mcp serve` / `mcp shim` are long-running
492
+ // processes that must not be wrapped in a session (they are what an editor
493
+ // spawns behind a session of its own). Loaded lazily so `--help`,
494
+ // `--version` and an ordinary prompt never pay for the host registry.
495
+ if (opts.command === 'mcp') {
496
+ const { runMcpCommand } = require('../src/mcp.js');
497
+ return runMcpCommand(opts.commandArg, opts.commandArgv || [], {
498
+ json: opts.json,
499
+ stdin: process.stdin,
500
+ stdout: process.stdout,
501
+ stderr: process.stderr,
502
+ });
503
+ }
504
+
475
505
  const { createApp } = require('../src/app.js');
476
506
 
477
507
  let prompt = opts.prompt;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "aegiscode",
3
3
  "productName": "AEGIS Code",
4
- "version": "6.8.3",
4
+ "version": "6.8.5",
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",
@@ -9,11 +9,6 @@
9
9
  },
10
10
  "license": "MIT",
11
11
  "homepage": "https://aegiscloud.org",
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/aegisinfo/aegiscode-plugin.git",
15
- "directory": "cli"
16
- },
17
12
  "bin": {
18
13
  "aegiscode": "bin/aegiscode.js"
19
14
  },
@@ -51,6 +51,29 @@ const FILES = [
51
51
  // quotes, and one stray one silently swallows the next real entry.)
52
52
  'client/env-file.js',
53
53
  'mcp/tools.js',
54
+ // The stdio MCP server itself — the process every editor config written by
55
+ // `aegiscode mcp install` points at. Staging the registry without it ships a
56
+ // package whose configs name a file that is not in the package, and an editor
57
+ // reports that as a server that simply never starts: no error the user can
58
+ // see. It exports nothing and registers its stdin handlers at load time, so
59
+ // it is verified by COMPILING it (see the probe below) and never required
60
+ // here — requiring it would switch the predist process stdin to flowing mode
61
+ // and it would then never exit.
62
+ 'mcp/server.js',
63
+ // The editor-integration layer: the host registry, the canonical server spec,
64
+ // and the merge-only installer behind `aegiscode mcp install|status|remove`.
65
+ // Staged under vendor/hosts/ so the tree keeps the repo shape — these files
66
+ // require ../client/*.js, which resolves INSIDE the vendor tree, and
67
+ // hosts/spec.js finds the server one level up as vendor/mcp/server.js.
68
+ 'hosts/spec.js',
69
+ 'hosts/targets.js',
70
+ 'hosts/install.js',
71
+ // The OpenAI-compatible shim (loopback /v1/chat/completions), for the many
72
+ // coding programs that take a base URL but speak no MCP. It resolves
73
+ // cli/src/models.js from either layout itself; in a checkout that is
74
+ // cli/src/models.js and in the package it is src/models.js, which ships
75
+ // because the CLI own source directory is published as-is.
76
+ 'hosts/openai-shim.js',
54
77
  'desktop/renderer/usage.js',
55
78
  // The agent-loop engine (persistent shell, editFile/grep/exec, Task
56
79
  // subagents) the desktop app already ships (desktop/lib/local/). The CLI
@@ -135,6 +158,82 @@ function main() {
135
158
  console.log(`predist: staged ${staged.length} shared modules into cli/vendor/`);
136
159
  for (const s of staged) console.log(` ${s}`);
137
160
  console.log(`predist: staged registry loads standalone (${count} tools)`);
161
+
162
+ // -------------------------------------------------------------------------
163
+ // The editor layer, proven from inside the staged tree.
164
+ // -------------------------------------------------------------------------
165
+ //
166
+ // Three things have to be true of the package we are about to publish, and
167
+ // none of them are visible from the repo:
168
+ //
169
+ // 1. the stdio server is present and is valid JavaScript;
170
+ // 2. `hosts/spec.js` resolves THAT copy of it, not a checkout path that
171
+ // only exists on this machine — an editor config pointing at a missing
172
+ // file fails silently, which is the worst failure mode there is;
173
+ // 3. `hosts/install.js` loads with its siblings resolved from vendor/.
174
+ //
175
+ // The server is compiled rather than required, deliberately: it registers
176
+ // process.stdin handlers at load time and exports nothing, so requiring it
177
+ // here would take over predist's own stdin and keep it alive forever.
178
+ const vm = require('node:vm');
179
+ const serverJs = path.join(VENDOR, 'mcp', 'server.js');
180
+ try {
181
+ new vm.Script(fs.readFileSync(serverJs, 'utf8'), { filename: serverJs });
182
+ } catch (err) {
183
+ console.error(`predist: staged mcp/server.js does not compile: ${err.message}`);
184
+ process.exit(1);
185
+ }
186
+
187
+ const hostsDir = path.join(VENDOR, 'hosts');
188
+ const spec = require(path.join(hostsDir, 'spec.js'));
189
+ const install = require(path.join(hostsDir, 'install.js'));
190
+ const targets = require(path.join(hostsDir, 'targets.js'));
191
+
192
+ // An empty AEGIS_MCP_SERVER so a developer's own override cannot mask a
193
+ // broken staged tree — the candidate we are asserting on must be the staged
194
+ // one, and nothing else.
195
+ const resolved = spec.resolveServer({ AEGIS_MCP_SERVER: '' });
196
+ const stagedServer = path.join(VENDOR, 'mcp', 'server.js');
197
+ if (!resolved.exists || resolved.path !== stagedServer) {
198
+ console.error(
199
+ `predist: staged hosts/spec.js resolves the server as ${resolved.path} ` +
200
+ `(exists: ${resolved.exists}), expected ${stagedServer}. An installed ` +
201
+ 'aegiscode would write editor configs pointing at a file the package ' +
202
+ `never shipped. Candidates were:\n ${resolved.candidates.join('\n ')}`
203
+ );
204
+ process.exit(1);
205
+ }
206
+
207
+ // Plan one real install against a throwaway home: this is the exact document
208
+ // `aegiscode mcp install vscode` would write, so it is the cheapest possible
209
+ // proof that the packaged command points at a file that exists.
210
+ const vscode = targets.getTarget('vscode');
211
+ const plan = install.planTarget(vscode, 'user', {
212
+ ctx: install.hostCtx({ home: path.join(VENDOR, '.predist-home'), env: {}, cwd: REPO_DIR }),
213
+ specOpts: { env: { AEGIS_MCP_SERVER: '' } },
214
+ });
215
+ const wrote = JSON.stringify(plan.after || '');
216
+ if (plan.error || !plan.changed || !wrote.includes(JSON.stringify(stagedServer).slice(1, -1))) {
217
+ console.error(
218
+ `predist: a planned vscode install does not name the staged server ` +
219
+ `(error: ${plan.error && plan.error.message}, changed: ${plan.changed})`
220
+ );
221
+ process.exit(1);
222
+ }
223
+
224
+ // The shim resolves cli/src/models.js from either layout on its own load; a
225
+ // checkout has it and the package ships it as src/models.js. Loading it here
226
+ // is what catches a repo-shaped require that only works in development.
227
+ const shim = require(path.join(hostsDir, 'openai-shim.js'));
228
+ if (typeof shim.createShimServer !== 'function') {
229
+ console.error('predist: staged hosts/openai-shim.js exposes no createShimServer');
230
+ process.exit(1);
231
+ }
232
+
233
+ console.log(
234
+ `predist: editor layer verified (${targets.targetIds().length} host targets, ` +
235
+ `server resolves to vendor/mcp/server.js, shim loads)`
236
+ );
138
237
  }
139
238
 
140
239
  main();
package/src/agents.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  /**
4
- * Sub-agent prompt presets — ported verbatim from aegiscodex-dev/src/agents.js
4
+ * Sub-agent prompt presets — ported verbatim from the upstream engine reference
5
5
  * (which in turn came from the reference's slash-commands builtinCommands.ts
6
6
  * buildMultiAgents() and the research-council member prompts). This build has
7
7
  * no parallel-agent runtime, so the presets are prompt composition:
package/src/app.js CHANGED
@@ -11,7 +11,7 @@
11
11
  * lives here.
12
12
  *
13
13
  * Commands come from `./commands.js`. Each entry is either handler-backed
14
- * (`cmd.handler(c, args)`, the reference aegiscodex-dev contract), tool-backed
14
+ * (`cmd.handler(c, args)`, the upstream engine contract), tool-backed
15
15
  * (`cmd.tool` + `cmd.build`), a generic escape hatch (`cmd.generic`, `/tool`),
16
16
  * or `unavailable` (a Claude Code auth-loop command this client cannot honour).
17
17
  * Handlers run against the FROZEN command context built below; the tool path
@@ -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, buildSystemPrompt } = require('./deps.js');
24
+ const { createTools, createClient, usageTokens, usageBuckets, buildSystemPrompt } = 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');
@@ -201,6 +201,8 @@ function createApp(options = {}) {
201
201
  tokens: 0,
202
202
  inputTokens: 0,
203
203
  outputTokens: 0,
204
+ cacheReadTokens: 0,
205
+ cacheWriteTokens: 0,
204
206
  cost: 0, // € spent, from the ledger rows that landed AFTER the baseline
205
207
  balance: null,
206
208
  // How many times each ledger-row identity is already accounted for.
@@ -1033,7 +1035,17 @@ function createApp(options = {}) {
1033
1035
  turns: session.turns,
1034
1036
  calls: session.calls,
1035
1037
  startedAt: session.startedAt,
1036
- tokens: { input: session.inputTokens, output: session.outputTokens, total: session.tokens },
1038
+ // The shared bucket shape `{input, output, cacheRead, cacheWrite}` — the
1039
+ // same object /cost's accounting and the ledger carry, so the panels
1040
+ // cannot render a different turn than the one that was billed. `input` is
1041
+ // the miss half; see recordTurn.
1042
+ tokens: {
1043
+ input: session.inputTokens,
1044
+ output: session.outputTokens,
1045
+ cacheRead: session.cacheReadTokens,
1046
+ cacheWrite: session.cacheWriteTokens,
1047
+ total: session.tokens,
1048
+ },
1037
1049
  costEur: session.cost,
1038
1050
  balance: session.balance,
1039
1051
  plan: session.plan || null,
@@ -1440,8 +1452,24 @@ function createApp(options = {}) {
1440
1452
  const tokens = usageTokens(usage);
1441
1453
  if (tokens != null) {
1442
1454
  session.tokens += tokens;
1443
- session.inputTokens += Number(usage.input_tokens ?? usage.prompt_tokens ?? 0) || 0;
1444
- session.outputTokens += Number(usage.output_tokens ?? usage.completion_tokens ?? 0) || 0;
1455
+ // The session tally is folded through the SHARED normaliser, not the raw
1456
+ // wire spellings. Reading `input_tokens ?? prompt_tokens` here is what
1457
+ // made the CLI's live tally disagree with its own ledger about the same
1458
+ // turn: the providers do not merely spell these fields differently, they
1459
+ // MEASURE them differently. Anthropic's `input_tokens` EXCLUDES
1460
+ // `cache_read_input_tokens`; OpenAI/DeepSeek's `prompt_tokens` INCLUDES
1461
+ // the hit. So `input + cacheRead` is right for the first and a
1462
+ // double-count of the prompt for the second. `usageBuckets` resolves
1463
+ // `input` to the MISS half in both cases (the same normalisation the
1464
+ // ledger row, the desktop roll and costBreakdown already use), which is
1465
+ // the only reading under which the /context prompt row means one thing on
1466
+ // every provider. Without this the CLI accumulated no cache buckets at
1467
+ // all, so /tokens drew two bars it could never fill.
1468
+ const b = usageBuckets(usage);
1469
+ session.inputTokens += b.input;
1470
+ session.outputTokens += b.output;
1471
+ session.cacheReadTokens += b.cacheRead;
1472
+ session.cacheWriteTokens += b.cacheWrite;
1445
1473
  }
1446
1474
  return tokens;
1447
1475
  }
@@ -1475,10 +1503,14 @@ function createApp(options = {}) {
1475
1503
  status,
1476
1504
  usage: usage
1477
1505
  ? {
1478
- input: Number(usage.input_tokens ?? usage.prompt_tokens ?? 0) || 0,
1479
- output: Number(usage.output_tokens ?? usage.completion_tokens ?? 0) || 0,
1480
- cacheRead: Number(usage.cache_read_input_tokens ?? 0) || 0,
1481
- cacheWrite: Number(usage.cache_creation_input_tokens ?? 0) || 0,
1506
+ // Not re-derived here. `usageBuckets` is the one module both
1507
+ // hosts resolve (deps.js), so the terminal and the GUI cannot
1508
+ // disagree about what a turn consumed — including whether a
1509
+ // provider's cached count sits INSIDE its prompt count
1510
+ // (OpenAI, DeepSeek) or BESIDE it (Anthropic). Reading only the
1511
+ // Anthropic spelling recorded cacheRead: 0 for every DeepSeek
1512
+ // turn, which priced the whole prompt at the miss rate.
1513
+ ...usageBuckets(usage),
1482
1514
  ...(settled != null ? { costUsd: settled } : {}),
1483
1515
  }
1484
1516
  : settled != null
package/src/caps.js CHANGED
@@ -55,7 +55,7 @@
55
55
 
56
56
  // ── the cell-width core ──────────────────────────────────────────────────────
57
57
  // Real terminal cell width (wcwidth-style), copied verbatim from
58
- // aegiscodex-dev/src/screen.js. Combining marks and variation selectors occupy
58
+ // the upstream engine reference. Combining marks and variation selectors occupy
59
59
  // no cell; CJK fullwidth forms and emoji-presentation glyphs occupy two;
60
60
  // everything else one. A plain code-point count misaligns every width decision
61
61
  // the moment a line contains CJK, emoji or a terminal's wide fallback glyph.