aegiscode 6.8.2 → 6.8.4
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 +35 -5
- package/package.json +1 -1
- package/scripts/predist.mjs +99 -0
- package/src/app.js +40 -8
- package/src/chatflow.js +181 -33
- package/src/commands.js +172 -22
- package/src/deps.js +2 -1
- package/src/events.js +37 -14
- package/src/mcp.js +683 -0
- package/src/panels.js +65 -15
- package/src/screen.js +130 -5
- package/src/screens.js +36 -7
- package/src/signup.js +153 -0
- package/src/title.js +217 -0
- package/src/tokens.js +74 -95
- package/src/update.js +75 -1
- package/vendor/desktop/lib/local/engine.js +24 -0
- package/vendor/desktop/lib/settings.js +67 -0
- package/vendor/desktop/renderer/usage.js +372 -41
- 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
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The host registry — every coding program AEGIS can appear in, and the exact
|
|
5
|
+
* dialect each one wants.
|
|
6
|
+
*
|
|
7
|
+
* This file is DATA. It contains no I/O, no prompting and no CLI text: the
|
|
8
|
+
* installer (`./install.js`) walks this table, and `aegiscode mcp print` renders
|
|
9
|
+
* one entry without touching the disk. Adding a host is adding a row.
|
|
10
|
+
*
|
|
11
|
+
* Two things are worth knowing before editing a row:
|
|
12
|
+
*
|
|
13
|
+
* - `container` is the dotted key path inside the config file that holds the
|
|
14
|
+
* server map. VS Code uses `servers`, most of the ecosystem uses
|
|
15
|
+
* `mcpServers`, Zed uses `context_servers`, and OpenCode nests a single
|
|
16
|
+
* `mcp` object. Getting this wrong does not error — the editor just never
|
|
17
|
+
* starts the server — so each row carries `docs` and `verified` so a user
|
|
18
|
+
* can check the claim against the host's own documentation.
|
|
19
|
+
*
|
|
20
|
+
* - `entry()` returns the host's own object shape, built from the canonical
|
|
21
|
+
* spec in `./spec.js`. Nothing else in the codebase needs to know that
|
|
22
|
+
* Windsurf and Cline disagree about `type: "stdio"`.
|
|
23
|
+
*
|
|
24
|
+
* `scopes`: `user` writes to the machine-wide config, `workspace` writes into
|
|
25
|
+
* the current directory (committed to git in many projects — which is exactly
|
|
26
|
+
* why no API key is written unless the user asks).
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
const os = require('node:os');
|
|
30
|
+
const path = require('node:path');
|
|
31
|
+
|
|
32
|
+
const { SERVER_NAME, vscodeKeyInput } = require('./spec.js');
|
|
33
|
+
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Path helpers — platform-aware, and injectable so tests never touch $HOME.
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
function home(ctx) {
|
|
39
|
+
return ctx.home || ctx.env.HOME || ctx.env.USERPROFILE || os.homedir();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** XDG on Linux, Application Support on macOS, APPDATA on Windows. */
|
|
43
|
+
function appConfig(ctx) {
|
|
44
|
+
const { env, platform } = ctx;
|
|
45
|
+
if (env.XDG_CONFIG_HOME) return env.XDG_CONFIG_HOME;
|
|
46
|
+
if (platform === 'win32') return env.APPDATA || path.join(home(ctx), 'AppData', 'Roaming');
|
|
47
|
+
if (platform === 'darwin') return path.join(home(ctx), 'Library', 'Application Support');
|
|
48
|
+
return path.join(home(ctx), '.config');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Zed keeps its settings in a plain dotfile even on macOS. */
|
|
52
|
+
function zedConfig(ctx) {
|
|
53
|
+
const { env, platform } = ctx;
|
|
54
|
+
if (platform === 'win32') return path.join(env.APPDATA || path.join(home(ctx), 'AppData', 'Roaming'), 'Zed');
|
|
55
|
+
return path.join(env.XDG_CONFIG_HOME || path.join(home(ctx), '.config'), 'zed');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function dot(ctx, ...parts) {
|
|
59
|
+
return path.join(home(ctx), ...parts);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function vscodeUserFile(ctx, variant) {
|
|
63
|
+
return path.join(appConfig(ctx), variant, 'User', 'mcp.json');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** `env` is omitted entirely when empty: an empty object in these files is
|
|
67
|
+
* noise, and Cline in particular treats a present-but-empty `env` as a change
|
|
68
|
+
* worth re-asking the user about. */
|
|
69
|
+
function orEnv(spec) {
|
|
70
|
+
const env = spec.env && Object.keys(spec.env).length ? spec.env : null;
|
|
71
|
+
return env;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function plainEntry(spec) {
|
|
75
|
+
const env = orEnv(spec);
|
|
76
|
+
const out = { command: spec.command, args: spec.args };
|
|
77
|
+
if (env) out.env = env;
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
// The registry
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
|
|
85
|
+
const TARGETS = [
|
|
86
|
+
{
|
|
87
|
+
id: 'vscode',
|
|
88
|
+
label: 'VS Code',
|
|
89
|
+
kind: 'mcp-json',
|
|
90
|
+
container: 'servers',
|
|
91
|
+
scopes: ['user', 'workspace'],
|
|
92
|
+
docs: 'https://code.visualstudio.com/docs/copilot/customization/mcp-servers',
|
|
93
|
+
verified: true,
|
|
94
|
+
supportsKeyPrompt: true,
|
|
95
|
+
note: 'Copilot agent mode reads `.vscode/mcp.json` for the workspace, or the user file for every project.',
|
|
96
|
+
path(scope, ctx) {
|
|
97
|
+
return scope === 'workspace' ? path.join(ctx.cwd, '.vscode', 'mcp.json') : vscodeUserFile(ctx, 'Code');
|
|
98
|
+
},
|
|
99
|
+
// VS Code is the one host with a first-class stdio type tag and a secret
|
|
100
|
+
// input mechanism, so it is the only row that gets either.
|
|
101
|
+
entry(spec) {
|
|
102
|
+
const out = { type: 'stdio', command: spec.command, args: spec.args };
|
|
103
|
+
const env = orEnv(spec);
|
|
104
|
+
if (env) out.env = env;
|
|
105
|
+
return out;
|
|
106
|
+
},
|
|
107
|
+
extras(spec) {
|
|
108
|
+
return spec.keyRef && spec.keyRef.startsWith('${input:')
|
|
109
|
+
? { inputs: [vscodeKeyInput()] }
|
|
110
|
+
: null;
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
id: 'vscode-insiders',
|
|
115
|
+
label: 'VS Code Insiders',
|
|
116
|
+
kind: 'mcp-json',
|
|
117
|
+
container: 'servers',
|
|
118
|
+
scopes: ['user'],
|
|
119
|
+
docs: 'https://code.visualstudio.com/docs/copilot/customization/mcp-servers',
|
|
120
|
+
verified: true,
|
|
121
|
+
supportsKeyPrompt: true,
|
|
122
|
+
path(scope, ctx) { return vscodeUserFile(ctx, 'Code - Insiders'); },
|
|
123
|
+
entry: (spec) => TARGETS[0].entry(spec),
|
|
124
|
+
extras: (spec) => TARGETS[0].extras(spec),
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
id: 'vscodium',
|
|
128
|
+
label: 'VSCodium',
|
|
129
|
+
kind: 'mcp-json',
|
|
130
|
+
container: 'servers',
|
|
131
|
+
scopes: ['user', 'workspace'],
|
|
132
|
+
docs: 'https://code.visualstudio.com/docs/copilot/customization/mcp-servers',
|
|
133
|
+
verified: true,
|
|
134
|
+
supportsKeyPrompt: true,
|
|
135
|
+
path(scope, ctx) {
|
|
136
|
+
return scope === 'workspace' ? path.join(ctx.cwd, '.vscode', 'mcp.json') : vscodeUserFile(ctx, 'VSCodium');
|
|
137
|
+
},
|
|
138
|
+
entry: (spec) => TARGETS[0].entry(spec),
|
|
139
|
+
extras: (spec) => TARGETS[0].extras(spec),
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
id: 'cursor',
|
|
143
|
+
label: 'Cursor',
|
|
144
|
+
kind: 'mcp-json',
|
|
145
|
+
container: 'mcpServers',
|
|
146
|
+
scopes: ['user', 'workspace'],
|
|
147
|
+
docs: 'https://cursor.com/docs/context/mcp',
|
|
148
|
+
verified: true,
|
|
149
|
+
path(scope, ctx) {
|
|
150
|
+
return scope === 'workspace'
|
|
151
|
+
? path.join(ctx.cwd, '.cursor', 'mcp.json')
|
|
152
|
+
: path.join(appConfig(ctx), 'Cursor', 'mcp.json');
|
|
153
|
+
},
|
|
154
|
+
entry: plainEntry,
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
id: 'windsurf',
|
|
158
|
+
label: 'Windsurf',
|
|
159
|
+
kind: 'mcp-json',
|
|
160
|
+
container: 'mcpServers',
|
|
161
|
+
scopes: ['user'],
|
|
162
|
+
docs: 'https://docs.windsurf.com/windsurf/cascade/mcp',
|
|
163
|
+
verified: true,
|
|
164
|
+
// Windsurf reads ~/.codeium/windsurf/mcp_config.json on every platform.
|
|
165
|
+
path(scope, ctx) { return dot(ctx, '.codeium', 'windsurf', 'mcp_config.json'); },
|
|
166
|
+
entry: plainEntry,
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
id: 'cline',
|
|
170
|
+
label: 'Cline (VS Code extension)',
|
|
171
|
+
kind: 'mcp-json',
|
|
172
|
+
container: 'mcpServers',
|
|
173
|
+
scopes: ['user'],
|
|
174
|
+
docs: 'https://docs.cline.bot/mcp/configuring-mcp-servers',
|
|
175
|
+
verified: true,
|
|
176
|
+
path(scope, ctx) {
|
|
177
|
+
return path.join(
|
|
178
|
+
appConfig(ctx), 'Code', 'User', 'globalStorage',
|
|
179
|
+
'saoudrizwan.claude-dev', 'settings', 'cline_mcp_settings.json'
|
|
180
|
+
);
|
|
181
|
+
},
|
|
182
|
+
entry(spec) {
|
|
183
|
+
return { ...plainEntry(spec), disabled: false, autoApprove: [], type: 'stdio' };
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
id: 'roo',
|
|
188
|
+
label: 'Roo Code (VS Code extension)',
|
|
189
|
+
kind: 'mcp-json',
|
|
190
|
+
container: 'mcpServers',
|
|
191
|
+
scopes: ['user'],
|
|
192
|
+
docs: 'https://docs.roocode.com/features/mcp/using-mcp-in-roo',
|
|
193
|
+
verified: true,
|
|
194
|
+
path(scope, ctx) {
|
|
195
|
+
return path.join(
|
|
196
|
+
appConfig(ctx), 'Code', 'User', 'globalStorage',
|
|
197
|
+
'rooveterinaryinc.roo-cline', 'settings', 'mcp_settings.json'
|
|
198
|
+
);
|
|
199
|
+
},
|
|
200
|
+
entry(spec) {
|
|
201
|
+
return { ...plainEntry(spec), disabled: false, alwaysAllow: [], type: 'stdio' };
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
id: 'zed',
|
|
206
|
+
label: 'Zed',
|
|
207
|
+
kind: 'mcp-json',
|
|
208
|
+
container: 'context_servers',
|
|
209
|
+
scopes: ['user'],
|
|
210
|
+
docs: 'https://zed.dev/docs/ai/mcp',
|
|
211
|
+
verified: true,
|
|
212
|
+
path(scope, ctx) { return path.join(zedConfig(ctx), 'settings.json'); },
|
|
213
|
+
// Zed wraps the process in a `command` object and requires the custom
|
|
214
|
+
// source tag; a bare `command` string here is silently ignored.
|
|
215
|
+
entry(spec) {
|
|
216
|
+
const command = { path: spec.command, args: spec.args };
|
|
217
|
+
const env = orEnv(spec);
|
|
218
|
+
if (env) command.env = env;
|
|
219
|
+
return { source: 'custom', command };
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
id: 'continue',
|
|
224
|
+
label: 'Continue (VS Code / JetBrains)',
|
|
225
|
+
kind: 'mcp-json',
|
|
226
|
+
container: 'mcpServers',
|
|
227
|
+
scopes: ['user'],
|
|
228
|
+
docs: 'https://docs.continue.dev/customize/deep-dives/mcp',
|
|
229
|
+
verified: true,
|
|
230
|
+
path(scope, ctx) { return dot(ctx, '.continue', 'config.json'); },
|
|
231
|
+
entry: plainEntry,
|
|
232
|
+
// Continue has moved to config.yaml; writing config.json into a directory
|
|
233
|
+
// that already holds a yaml config produces a file Continue ignores.
|
|
234
|
+
yamlWins: true,
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
id: 'claude',
|
|
238
|
+
label: 'Claude Code (project scope)',
|
|
239
|
+
kind: 'mcp-json',
|
|
240
|
+
container: 'mcpServers',
|
|
241
|
+
scopes: ['workspace'],
|
|
242
|
+
docs: 'https://docs.claude.com/en/docs/claude-code/mcp',
|
|
243
|
+
verified: true,
|
|
244
|
+
path(scope, ctx) { return path.join(ctx.cwd, '.mcp.json'); },
|
|
245
|
+
entry: plainEntry,
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
id: 'gemini',
|
|
249
|
+
label: 'Gemini CLI',
|
|
250
|
+
kind: 'mcp-json',
|
|
251
|
+
container: 'mcpServers',
|
|
252
|
+
scopes: ['user'],
|
|
253
|
+
docs: 'https://github.com/google-gemini/gemini-cli/blob/main/docs/tools/mcp-server.md',
|
|
254
|
+
verified: true,
|
|
255
|
+
path(scope, ctx) { return dot(ctx, '.gemini', 'settings.json'); },
|
|
256
|
+
entry: plainEntry,
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
id: 'codex',
|
|
260
|
+
label: 'Codex CLI',
|
|
261
|
+
kind: 'mcp-toml',
|
|
262
|
+
container: 'mcp_servers',
|
|
263
|
+
scopes: ['user'],
|
|
264
|
+
docs: 'https://github.com/openai/codex/blob/main/docs/config.md',
|
|
265
|
+
verified: true,
|
|
266
|
+
path(scope, ctx) { return dot(ctx, '.codex', 'config.toml'); },
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
id: 'junie',
|
|
270
|
+
label: 'JetBrains Junie / AI Assistant',
|
|
271
|
+
kind: 'mcp-json',
|
|
272
|
+
container: 'mcpServers',
|
|
273
|
+
scopes: ['user', 'workspace'],
|
|
274
|
+
docs: 'https://www.jetbrains.com/help/junie/mcp.html',
|
|
275
|
+
verified: false,
|
|
276
|
+
note: 'JetBrains reads this file but the IDE also caches MCP config in Settings — restart the IDE and confirm the server is listed there.',
|
|
277
|
+
path(scope, ctx) {
|
|
278
|
+
return scope === 'workspace'
|
|
279
|
+
? path.join(ctx.cwd, '.junie', 'mcp', 'mcp.json')
|
|
280
|
+
: dot(ctx, '.junie', 'mcp', 'mcp.json');
|
|
281
|
+
},
|
|
282
|
+
entry: plainEntry,
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
id: 'opencode',
|
|
286
|
+
label: 'OpenCode',
|
|
287
|
+
kind: 'mcp-json',
|
|
288
|
+
container: 'mcp',
|
|
289
|
+
scopes: ['user'],
|
|
290
|
+
docs: 'https://opencode.ai/docs/mcp-servers/',
|
|
291
|
+
verified: false,
|
|
292
|
+
note: 'OpenCode takes a single command array instead of command + args.',
|
|
293
|
+
path(scope, ctx) { return path.join(appConfig(ctx), 'opencode', 'opencode.json'); },
|
|
294
|
+
entry(spec) {
|
|
295
|
+
const env = orEnv(spec);
|
|
296
|
+
const out = { type: 'local', command: [spec.command, ...spec.args], enabled: true };
|
|
297
|
+
if (env) out.environment = env;
|
|
298
|
+
return out;
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
];
|
|
302
|
+
|
|
303
|
+
const BY_ID = new Map(TARGETS.map((t) => [t.id, t]));
|
|
304
|
+
|
|
305
|
+
/** Aliases people actually type, and the VS Code variants' shared row. */
|
|
306
|
+
const ALIASES = {
|
|
307
|
+
code: 'vscode',
|
|
308
|
+
'vs-code': 'vscode',
|
|
309
|
+
'vscode-code': 'vscode',
|
|
310
|
+
windsurfcodeium: 'windsurf',
|
|
311
|
+
'roo-code': 'roo',
|
|
312
|
+
'roocode': 'roo',
|
|
313
|
+
jetbrains: 'junie',
|
|
314
|
+
'claude-code': 'claude',
|
|
315
|
+
gemini_cli: 'gemini',
|
|
316
|
+
'codex-cli': 'codex',
|
|
317
|
+
vsc: 'vscodium',
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
function getTarget(id) {
|
|
321
|
+
if (!id) return null;
|
|
322
|
+
const key = String(id).toLowerCase().trim();
|
|
323
|
+
return BY_ID.get(key) || BY_ID.get(ALIASES[key]) || null;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function targetIds() {
|
|
327
|
+
return TARGETS.map((t) => t.id);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Hosts whose MCP config lives inside a VS Code-family `User` directory, keyed
|
|
332
|
+
* by the directory name — used by `status` to explain a missing file.
|
|
333
|
+
*/
|
|
334
|
+
const VSCODE_VARIANTS = ['Code', 'Code - Insiders', 'VSCodium'];
|
|
335
|
+
|
|
336
|
+
module.exports = {
|
|
337
|
+
TARGETS,
|
|
338
|
+
ALIASES,
|
|
339
|
+
VSCODE_VARIANTS,
|
|
340
|
+
getTarget,
|
|
341
|
+
targetIds,
|
|
342
|
+
SERVER_NAME,
|
|
343
|
+
appConfig,
|
|
344
|
+
zedConfig,
|
|
345
|
+
home,
|
|
346
|
+
};
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* AEGIS MCP server — exposes aegiscloud capabilities to any Claude Code user.
|
|
4
|
+
*
|
|
5
|
+
* Zero dependencies: raw JSON-RPC 2.0 over stdio (newline-delimited), Node's
|
|
6
|
+
* global fetch. Runs from a bare `node server.js` — no npm install required.
|
|
7
|
+
*
|
|
8
|
+
* This is a thin HOST: all transport lives in ../client/aegis.js and the tool
|
|
9
|
+
* registry lives in ./tools.js. This file only speaks MCP JSON-RPC.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
const { createClient } = require('../client/aegis.js');
|
|
15
|
+
const credentials = require('../client/credentials.js');
|
|
16
|
+
const { createTools } = require('./tools.js');
|
|
17
|
+
|
|
18
|
+
// `~/.aegiscode/.env` read into process.env once, before anything resolves a
|
|
19
|
+
// credential. Without this the one-instruction setup ("put your key in
|
|
20
|
+
// ~/.aegiscode/.env") would be true in the CLI and the desktop and false here,
|
|
21
|
+
// because this host resolves a key from the environment or the 0600 store and
|
|
22
|
+
// nothing filled the environment from the file. A variable already exported in
|
|
23
|
+
// the environment Claude Code was launched from always wins. Failure is never
|
|
24
|
+
// fatal: an absent file is the pre-existing state, not an error.
|
|
25
|
+
try {
|
|
26
|
+
const loaded = require('../client/env-file.js').loadEnvFile();
|
|
27
|
+
if (loaded.loose) {
|
|
28
|
+
process.stderr.write(
|
|
29
|
+
`aegis: ${loaded.file} is readable by other accounts (mode ` +
|
|
30
|
+
`${loaded.mode.toString(8)}) — consider \`chmod 600\` on it.\n`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
} catch { /* an absent or unreadable file is not a startup error */ }
|
|
34
|
+
|
|
35
|
+
// The account credential is resolved the same way in all four hosts: the
|
|
36
|
+
// environment first, then the 0600 store the terminal host writes with
|
|
37
|
+
// `aegiscode login` (or /key), then a legacy config.json. This host used to
|
|
38
|
+
// read `AEGIS_API_KEY` from the environment alone, so a user who signed in from
|
|
39
|
+
// the CLI still met "No AEGIS_API_KEY is set" here — the credential existed,
|
|
40
|
+
// this process just would not look at it.
|
|
41
|
+
//
|
|
42
|
+
// `client/` is inside the tree the plugin ships (mcp/ + client/), so this needs
|
|
43
|
+
// no dependency on the CLI package to work when installed.
|
|
44
|
+
const aegis = createClient(credentials.clientOptions());
|
|
45
|
+
// The tool registry lives in ./tools.js, shared with the terminal host
|
|
46
|
+
// (cli/) so the two hosts cannot drift apart. This file owns the JSON-RPC
|
|
47
|
+
// plumbing and nothing else.
|
|
48
|
+
const { TOOLS, toolList } = createTools(aegis);
|
|
49
|
+
const API_KEY = aegis.apiKey;
|
|
50
|
+
const API_BASE = aegis.apiBase;
|
|
51
|
+
const SERVER_NAME = 'aegis';
|
|
52
|
+
// Keep in sync with .claude-plugin/plugin.json "version".
|
|
53
|
+
const SERVER_VERSION = '0.4.0';
|
|
54
|
+
|
|
55
|
+
/** The one instruction that actually resolves a missing key. */
|
|
56
|
+
function missingKeyText() {
|
|
57
|
+
const { path } = credentials.keyStatus();
|
|
58
|
+
return [
|
|
59
|
+
'No AEGIS API key is configured for this session.',
|
|
60
|
+
'',
|
|
61
|
+
'Set one with any of:',
|
|
62
|
+
' • `aegiscode login` in a terminal (saves it to ' + path + ', mode 0600)',
|
|
63
|
+
' • export AEGIS_API_KEY=… in the environment Claude Code was launched from',
|
|
64
|
+
' • put `AEGIS_API_KEY=…` in ~/.aegiscode/.env (read at startup, every host)',
|
|
65
|
+
'',
|
|
66
|
+
'Then restart Claude Code. Get a key at https://aegiscloud.org.',
|
|
67
|
+
].join('\n');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
// JSON-RPC / MCP plumbing
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
|
|
74
|
+
function send(msg) {
|
|
75
|
+
process.stdout.write(JSON.stringify(msg) + '\n');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function reply(id, result) {
|
|
79
|
+
send({ jsonrpc: '2.0', id, result });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function replyError(id, code, message) {
|
|
83
|
+
send({ jsonrpc: '2.0', id, error: { code, message } });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Track in-flight handlers so we don't exit while a fetch is pending.
|
|
87
|
+
let pending = 0;
|
|
88
|
+
let stdinClosed = false;
|
|
89
|
+
function maybeExit() {
|
|
90
|
+
if (stdinClosed && pending === 0) process.exit(0);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function handleMessage(msg) {
|
|
94
|
+
const { id, method, params } = msg;
|
|
95
|
+
const isNotification = id === undefined || id === null;
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
switch (method) {
|
|
99
|
+
case 'initialize':
|
|
100
|
+
reply(id, {
|
|
101
|
+
protocolVersion: (params && params.protocolVersion) || '2024-11-05',
|
|
102
|
+
capabilities: { tools: {} },
|
|
103
|
+
serverInfo: { name: SERVER_NAME, version: SERVER_VERSION },
|
|
104
|
+
});
|
|
105
|
+
return;
|
|
106
|
+
|
|
107
|
+
case 'notifications/initialized':
|
|
108
|
+
case 'notifications/cancelled':
|
|
109
|
+
return; // no response for notifications
|
|
110
|
+
|
|
111
|
+
case 'ping':
|
|
112
|
+
if (!isNotification) reply(id, {});
|
|
113
|
+
return;
|
|
114
|
+
|
|
115
|
+
case 'tools/list':
|
|
116
|
+
reply(id, { tools: toolList() });
|
|
117
|
+
return;
|
|
118
|
+
|
|
119
|
+
case 'tools/call': {
|
|
120
|
+
const name = params && params.name;
|
|
121
|
+
const tool = TOOLS[name];
|
|
122
|
+
if (!tool) {
|
|
123
|
+
reply(id, {
|
|
124
|
+
content: [{ type: 'text', text: `Unknown tool: ${name}` }],
|
|
125
|
+
isError: true,
|
|
126
|
+
});
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (!API_KEY) {
|
|
130
|
+
reply(id, {
|
|
131
|
+
content: [{ type: 'text', text: missingKeyText() }],
|
|
132
|
+
isError: true,
|
|
133
|
+
});
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
const text = await tool.run((params && params.arguments) || {});
|
|
138
|
+
reply(id, { content: [{ type: 'text', text }], isError: false });
|
|
139
|
+
} catch (err) {
|
|
140
|
+
reply(id, {
|
|
141
|
+
content: [{ type: 'text', text: `AEGIS error: ${err.message}` }],
|
|
142
|
+
isError: true,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
default:
|
|
149
|
+
if (!isNotification) replyError(id, -32601, `Method not found: ${method}`);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
} catch (err) {
|
|
153
|
+
if (!isNotification) replyError(id, -32603, err.message);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ---------------------------------------------------------------------------
|
|
158
|
+
// stdin loop — newline-delimited JSON-RPC
|
|
159
|
+
// ---------------------------------------------------------------------------
|
|
160
|
+
|
|
161
|
+
let buffer = '';
|
|
162
|
+
process.stdin.setEncoding('utf8');
|
|
163
|
+
process.stdin.on('data', (chunk) => {
|
|
164
|
+
buffer += chunk;
|
|
165
|
+
let nl;
|
|
166
|
+
while ((nl = buffer.indexOf('\n')) !== -1) {
|
|
167
|
+
const line = buffer.slice(0, nl).trim();
|
|
168
|
+
buffer = buffer.slice(nl + 1);
|
|
169
|
+
if (!line) continue;
|
|
170
|
+
let msg;
|
|
171
|
+
try {
|
|
172
|
+
msg = JSON.parse(line);
|
|
173
|
+
} catch {
|
|
174
|
+
continue; // skip malformed lines
|
|
175
|
+
}
|
|
176
|
+
pending++;
|
|
177
|
+
Promise.resolve(handleMessage(msg)).finally(() => {
|
|
178
|
+
pending--;
|
|
179
|
+
maybeExit();
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
process.stdin.on('end', () => {
|
|
184
|
+
stdinClosed = true;
|
|
185
|
+
maybeExit();
|
|
186
|
+
});
|