@mwillbanks/ast-mcp 0.1.3 → 0.2.0
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 +59 -20
- package/dist/ast-mcp.js +232 -130
- package/dist/ast-mcp.js.map +107 -27
- package/package.json +2 -1
- package/src/ast-bro/capability.ts +3 -8
- package/src/ast-bro/client.ts +18 -2
- package/src/ast-bro/result.ts +5 -12
- package/src/cli.ts +70 -95
- package/src/config-cli.ts +54 -0
- package/src/config.ts +886 -0
- package/src/helpers/aider.ts +252 -0
- package/src/helpers/ast-bro.ts +64 -0
- package/src/helpers/config.ts +149 -0
- package/src/helpers/hook.ts +60 -0
- package/src/helpers/installer.ts +249 -0
- package/src/helpers/json.ts +19 -0
- package/src/helpers/mcp-schema.ts +31 -0
- package/src/helpers/process.ts +31 -0
- package/src/helpers/string.ts +97 -0
- package/src/hook.ts +135 -40
- package/src/http-entry.ts +1 -1
- package/src/http.ts +118 -103
- package/src/installer-transport.ts +190 -0
- package/src/installer.ts +579 -242
- package/src/mcp-cli.ts +104 -0
- package/src/patch/aider.ts +6 -199
- package/src/patch/engine.ts +271 -197
- package/src/runtime/dependencies.ts +48 -29
- package/src/runtime/file-delete.ts +13 -9
- package/src/runtime/file-read.ts +91 -57
- package/src/runtime/file-rename.ts +158 -0
- package/src/runtime/format.ts +57 -34
- package/src/runtime/paths.ts +30 -16
- package/src/runtime/policy.ts +21 -0
- package/src/runtime/process-input.ts +14 -4
- package/src/service.ts +219 -0
- package/src/shell-policy.ts +331 -0
- package/src/stdio.ts +47 -35
- package/src/tools/ast-bro.ts +12 -6
- package/src/tools/configured.ts +28 -0
- package/src/tools/files.ts +24 -27
- package/src/tools/index.ts +5 -3
- package/src/tools/lifecycle.ts +69 -55
- package/templates/skills/ast-mcp/SKILL.md +7 -6
- package/templates/skills/ast-mcp/evals/batch.evals.json +48 -0
- package/templates/skills/ast-mcp/evals/evals.json +1 -0
- package/templates/skills/ast-mcp/evals/score.test.ts +175 -0
- package/templates/skills/ast-mcp/evals/score.ts +304 -267
- package/templates/skills/ast-mcp/evals/semantic.test.ts +322 -0
- package/templates/skills/ast-mcp/evals/semantic.ts +390 -135
- package/templates/skills/ast-mcp/evals/shell-policy.ts +252 -0
- package/templates/skills/ast-mcp/evals/source.test.ts +46 -0
- package/templates/skills/ast-mcp/evals/source.ts +164 -0
- package/templates/skills/ast-mcp/evals/trigger-queries.json +1 -1
- package/templates/skills/ast-mcp/references/installation.md +9 -8
- package/templates/skills/ast-mcp/references/patch-state-machine.md +5 -5
- package/templates/skills/ast-mcp/references/tool-catalog.md +4 -2
- package/templates/skills/ast-mcp/scripts/check-install.ts +312 -110
|
@@ -5,23 +5,91 @@ import path from "node:path";
|
|
|
5
5
|
|
|
6
6
|
type Scope = "local" | "global";
|
|
7
7
|
type Target = "codex" | "claude" | "copilot";
|
|
8
|
+
type Transport = "stdio" | "http";
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
type CheckOptions = {
|
|
11
|
+
host: string;
|
|
12
|
+
port: number;
|
|
13
|
+
root: string;
|
|
14
|
+
scope: Scope;
|
|
15
|
+
service: boolean;
|
|
16
|
+
target: Target;
|
|
17
|
+
transport: Transport;
|
|
18
|
+
url: string;
|
|
19
|
+
};
|
|
20
|
+
type MutableCheckOptions = Omit<CheckOptions, "url">;
|
|
21
|
+
function applyOption(
|
|
22
|
+
options: MutableCheckOptions,
|
|
23
|
+
args: string[],
|
|
24
|
+
index: number,
|
|
25
|
+
) {
|
|
26
|
+
const option = args[index];
|
|
27
|
+
const value = args[index + 1];
|
|
28
|
+
switch (option) {
|
|
29
|
+
case "--scope":
|
|
30
|
+
options.scope = value as Scope;
|
|
31
|
+
return index + 1;
|
|
32
|
+
case "--target":
|
|
33
|
+
options.target = value as Target;
|
|
34
|
+
return index + 1;
|
|
35
|
+
case "--root":
|
|
36
|
+
options.root = path.resolve(value);
|
|
37
|
+
return index + 1;
|
|
38
|
+
case "--transport":
|
|
39
|
+
options.transport = value as Transport;
|
|
40
|
+
return index + 1;
|
|
41
|
+
case "--host":
|
|
42
|
+
options.host = value;
|
|
43
|
+
return index + 1;
|
|
44
|
+
case "--port":
|
|
45
|
+
options.port = Number(value);
|
|
46
|
+
return index + 1;
|
|
47
|
+
case "--service":
|
|
48
|
+
options.service = true;
|
|
49
|
+
return index;
|
|
50
|
+
default:
|
|
51
|
+
throw new Error(`Unknown argument: ${option}`);
|
|
18
52
|
}
|
|
53
|
+
}
|
|
54
|
+
function validateOptions(options: MutableCheckOptions) {
|
|
55
|
+
if (
|
|
56
|
+
!["local", "global"].includes(options.scope) ||
|
|
57
|
+
!["codex", "claude", "copilot"].includes(options.target) ||
|
|
58
|
+
!["stdio", "http"].includes(options.transport)
|
|
59
|
+
)
|
|
60
|
+
throw new Error("Invalid --scope, --target, or --transport");
|
|
19
61
|
if (
|
|
20
|
-
!
|
|
21
|
-
|
|
62
|
+
!Number.isInteger(options.port) ||
|
|
63
|
+
options.port < 1 ||
|
|
64
|
+
options.port > 65_535
|
|
22
65
|
)
|
|
23
|
-
throw new Error("Invalid --
|
|
24
|
-
|
|
66
|
+
throw new Error("Invalid --port");
|
|
67
|
+
if (options.service && options.transport !== "http")
|
|
68
|
+
throw new Error("--service requires --transport http");
|
|
69
|
+
}
|
|
70
|
+
function clientHost(host: string) {
|
|
71
|
+
if (host === "0.0.0.0") return "127.0.0.1";
|
|
72
|
+
if (host === "::") return "::1";
|
|
73
|
+
return host.startsWith("[") && host.endsWith("]") ? host.slice(1, -1) : host;
|
|
74
|
+
}
|
|
75
|
+
function endpointUrl(host: string, port: number) {
|
|
76
|
+
const client = clientHost(host);
|
|
77
|
+
return `http://${client.includes(":") ? `[${client}]` : client}:${port}/mcp`;
|
|
78
|
+
}
|
|
79
|
+
function parse(args: string[]): CheckOptions {
|
|
80
|
+
const options: MutableCheckOptions = {
|
|
81
|
+
host: "127.0.0.1",
|
|
82
|
+
port: 3768,
|
|
83
|
+
root: process.cwd(),
|
|
84
|
+
scope: "local",
|
|
85
|
+
service: false,
|
|
86
|
+
target: "codex",
|
|
87
|
+
transport: "stdio",
|
|
88
|
+
};
|
|
89
|
+
for (let index = 0; index < args.length; index += 1)
|
|
90
|
+
index = applyOption(options, args, index);
|
|
91
|
+
validateOptions(options);
|
|
92
|
+
return { ...options, url: endpointUrl(options.host, options.port) };
|
|
25
93
|
}
|
|
26
94
|
|
|
27
95
|
const instructionsBegin = "<!-- ast-mcp:begin -->";
|
|
@@ -114,37 +182,90 @@ async function hookCurrent(
|
|
|
114
182
|
return false;
|
|
115
183
|
}
|
|
116
184
|
|
|
185
|
+
type McpEntry = {
|
|
186
|
+
args?: unknown[];
|
|
187
|
+
command?: unknown;
|
|
188
|
+
env?: Record<string, unknown>;
|
|
189
|
+
tools?: unknown;
|
|
190
|
+
type?: unknown;
|
|
191
|
+
url?: unknown;
|
|
192
|
+
};
|
|
193
|
+
function httpJsonMcpCurrent(
|
|
194
|
+
entry: McpEntry | undefined,
|
|
195
|
+
type: "local" | "stdio" | undefined,
|
|
196
|
+
url: string | undefined,
|
|
197
|
+
) {
|
|
198
|
+
return (
|
|
199
|
+
entry?.type === "http" &&
|
|
200
|
+
entry.url === url &&
|
|
201
|
+
(type !== "local" || Array.isArray(entry.tools))
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
async function stdioCommandCurrent(entry: McpEntry | undefined) {
|
|
205
|
+
return (
|
|
206
|
+
entry?.command === "bun" &&
|
|
207
|
+
Array.isArray(entry.args) &&
|
|
208
|
+
entry.args[1] === "mcp" &&
|
|
209
|
+
(await astMcpEntry(entry.args[0]))
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function entryTypeCurrent(
|
|
214
|
+
entry: McpEntry,
|
|
215
|
+
type: "local" | "stdio" | undefined,
|
|
216
|
+
) {
|
|
217
|
+
if (!type) return true;
|
|
218
|
+
if (entry.type !== type) return false;
|
|
219
|
+
return type !== "local" || Array.isArray(entry.tools);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function entryRootCurrent(entry: McpEntry, root: string | undefined) {
|
|
223
|
+
return root
|
|
224
|
+
? entry.env?.AST_MCP_PROJECT_ROOT === root
|
|
225
|
+
: Object.keys(entry.env ?? {}).length === 0;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function stdioMetadataCurrent(
|
|
229
|
+
entry: McpEntry,
|
|
230
|
+
root: string | undefined,
|
|
231
|
+
type: "local" | "stdio" | undefined,
|
|
232
|
+
) {
|
|
233
|
+
return entryTypeCurrent(entry, type) && entryRootCurrent(entry, root);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function stdioJsonMcpCurrent(
|
|
237
|
+
entry: McpEntry | undefined,
|
|
238
|
+
root: string | undefined,
|
|
239
|
+
type: "local" | "stdio" | undefined,
|
|
240
|
+
) {
|
|
241
|
+
return (
|
|
242
|
+
(await stdioCommandCurrent(entry)) &&
|
|
243
|
+
stdioMetadataCurrent(entry as McpEntry, root, type)
|
|
244
|
+
);
|
|
245
|
+
}
|
|
117
246
|
async function jsonMcpCurrent(
|
|
118
247
|
file: string,
|
|
119
248
|
section: "mcpServers" | "servers",
|
|
120
249
|
root?: string,
|
|
121
250
|
type?: "local" | "stdio",
|
|
251
|
+
transport: Transport = "stdio",
|
|
252
|
+
url?: string,
|
|
122
253
|
) {
|
|
123
254
|
const value = JSON.parse(await readFile(file, "utf8").catch(() => "{}"));
|
|
124
|
-
const entry = value[section]?.["ast-mcp"];
|
|
125
|
-
|
|
126
|
-
entry
|
|
127
|
-
|
|
128
|
-
!(await astMcpEntry(entry.args[0])) ||
|
|
129
|
-
entry.args[1] !== "mcp"
|
|
130
|
-
)
|
|
131
|
-
return false;
|
|
132
|
-
if (type && entry.type !== type) return false;
|
|
133
|
-
if (
|
|
134
|
-
root &&
|
|
135
|
-
(entry.env?.AST_MCP_ROOTS !== root ||
|
|
136
|
-
entry.env?.AST_MCP_ALLOW_EXTERNAL_ROOTS !== "1")
|
|
137
|
-
)
|
|
138
|
-
return false;
|
|
139
|
-
if (!root && Object.keys(entry.env ?? {}).length !== 0) return false;
|
|
140
|
-
if (type === "local" && !Array.isArray(entry.tools)) return false;
|
|
141
|
-
return true;
|
|
255
|
+
const entry: McpEntry | undefined = value[section]?.["ast-mcp"];
|
|
256
|
+
return transport === "http"
|
|
257
|
+
? httpJsonMcpCurrent(entry, type, url)
|
|
258
|
+
: stdioJsonMcpCurrent(entry, root, type);
|
|
142
259
|
}
|
|
143
260
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
261
|
+
function codexHttpMcpCurrent(block: string, url: string | undefined) {
|
|
262
|
+
return (
|
|
263
|
+
block.includes("[mcp_servers.ast-mcp]") &&
|
|
264
|
+
block.includes(`url = ${JSON.stringify(url)}`) &&
|
|
265
|
+
!block.includes("command =")
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
async function codexStdioMcpCurrent(block: string, root: string | undefined) {
|
|
148
269
|
const args = block.match(/args = \[(".*"), "mcp"\]/);
|
|
149
270
|
if (
|
|
150
271
|
!block.includes("[mcp_servers.ast-mcp]") ||
|
|
@@ -154,130 +275,211 @@ async function codexMcpCurrent(file: string, root?: string) {
|
|
|
154
275
|
)
|
|
155
276
|
return false;
|
|
156
277
|
return root
|
|
157
|
-
? block.includes(`
|
|
158
|
-
|
|
159
|
-
: !block.includes("AST_MCP_ROOTS");
|
|
278
|
+
? block.includes(`AST_MCP_PROJECT_ROOT = ${JSON.stringify(root)}`)
|
|
279
|
+
: !block.includes("AST_MCP_PROJECT_ROOT");
|
|
160
280
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
281
|
+
async function codexMcpCurrent(
|
|
282
|
+
file: string,
|
|
283
|
+
root?: string,
|
|
284
|
+
transport: Transport = "stdio",
|
|
285
|
+
url?: string,
|
|
164
286
|
) {
|
|
165
|
-
const
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
287
|
+
const content = await readFile(file, "utf8").catch(() => "");
|
|
288
|
+
const block =
|
|
289
|
+
content.match(/# ast-mcp:begin\n([\s\S]*?)# ast-mcp:end/)?.[1] ?? "";
|
|
290
|
+
return transport === "http"
|
|
291
|
+
? codexHttpMcpCurrent(block, url)
|
|
292
|
+
: codexStdioMcpCurrent(block, root);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
type InstallChecks = Record<string, boolean>;
|
|
296
|
+
async function codexChecks(
|
|
297
|
+
options: CheckOptions,
|
|
298
|
+
home: string,
|
|
299
|
+
global: boolean,
|
|
300
|
+
): Promise<InstallChecks> {
|
|
301
|
+
const base = global
|
|
302
|
+
? path.join(home, ".codex")
|
|
303
|
+
: path.join(options.root, ".codex");
|
|
304
|
+
const [mcp, hook, skill, instructions] = await Promise.all([
|
|
305
|
+
codexMcpCurrent(
|
|
173
306
|
path.join(base, "config.toml"),
|
|
174
307
|
global ? undefined : options.root,
|
|
175
|
-
|
|
176
|
-
|
|
308
|
+
options.transport,
|
|
309
|
+
options.url,
|
|
310
|
+
),
|
|
311
|
+
hookCurrent(
|
|
177
312
|
path.join(base, "hooks.json"),
|
|
178
313
|
"PreToolUse",
|
|
179
314
|
path.join(base, "hooks/ast-mcp.ts"),
|
|
180
315
|
global ? path.join(base, "hooks/ast-mcp.ts") : ".codex/hooks/ast-mcp.ts",
|
|
181
|
-
)
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
);
|
|
185
|
-
checks.instructions = await instructionsCurrent(
|
|
316
|
+
),
|
|
317
|
+
skillCurrent(path.join(base, "skills/ast-mcp/SKILL.md")),
|
|
318
|
+
instructionsCurrent(
|
|
186
319
|
global
|
|
187
320
|
? path.join(base, "AGENTS.md")
|
|
188
321
|
: path.join(options.root, "AGENTS.md"),
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
322
|
+
),
|
|
323
|
+
]);
|
|
324
|
+
return { hook, instructions, mcp, skill };
|
|
325
|
+
}
|
|
326
|
+
async function claudeChecks(
|
|
327
|
+
options: CheckOptions,
|
|
328
|
+
home: string,
|
|
329
|
+
global: boolean,
|
|
330
|
+
): Promise<InstallChecks> {
|
|
331
|
+
const base = global
|
|
332
|
+
? path.join(home, ".claude")
|
|
333
|
+
: path.join(options.root, ".claude");
|
|
334
|
+
const [mcp, hook, skill, instructions] = await Promise.all([
|
|
335
|
+
jsonMcpCurrent(
|
|
195
336
|
global
|
|
196
337
|
? path.join(home, ".claude.json")
|
|
197
338
|
: path.join(options.root, ".mcp.json"),
|
|
198
339
|
"mcpServers",
|
|
199
340
|
global ? undefined : options.root,
|
|
200
|
-
|
|
201
|
-
|
|
341
|
+
undefined,
|
|
342
|
+
options.transport,
|
|
343
|
+
options.url,
|
|
344
|
+
),
|
|
345
|
+
hookCurrent(
|
|
202
346
|
path.join(base, "settings.json"),
|
|
203
347
|
"PreToolUse",
|
|
204
348
|
path.join(base, "hooks/ast-mcp.ts"),
|
|
205
349
|
global
|
|
206
350
|
? path.join(base, "hooks/ast-mcp.ts")
|
|
207
351
|
: `\${CLAUDE_PROJECT_DIR}/.claude/hooks/ast-mcp.ts`,
|
|
208
|
-
)
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
);
|
|
212
|
-
checks.instructions = await instructionsCurrent(
|
|
352
|
+
),
|
|
353
|
+
skillCurrent(path.join(base, "skills/ast-mcp/SKILL.md")),
|
|
354
|
+
instructionsCurrent(
|
|
213
355
|
global
|
|
214
356
|
? path.join(base, "CLAUDE.md")
|
|
215
357
|
: path.join(options.root, "AGENTS.md"),
|
|
216
|
-
)
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
358
|
+
),
|
|
359
|
+
]);
|
|
360
|
+
return { hook, instructions, mcp, skill };
|
|
361
|
+
}
|
|
362
|
+
async function copilotChecks(
|
|
363
|
+
options: CheckOptions,
|
|
364
|
+
home: string,
|
|
365
|
+
global: boolean,
|
|
366
|
+
): Promise<InstallChecks> {
|
|
367
|
+
const base = global
|
|
368
|
+
? path.join(home, ".copilot")
|
|
369
|
+
: path.join(options.root, ".github");
|
|
370
|
+
const [mcp, hook, skill, instructions] = await Promise.all([
|
|
371
|
+
jsonMcpCurrent(
|
|
222
372
|
global
|
|
223
373
|
? path.join(base, "mcp-config.json")
|
|
224
374
|
: path.join(options.root, ".github/mcp.json"),
|
|
225
375
|
"mcpServers",
|
|
226
376
|
global ? undefined : options.root,
|
|
227
377
|
"local",
|
|
228
|
-
|
|
229
|
-
|
|
378
|
+
options.transport,
|
|
379
|
+
options.url,
|
|
380
|
+
),
|
|
381
|
+
hookCurrent(
|
|
230
382
|
path.join(base, "hooks/ast-mcp.json"),
|
|
231
383
|
"preToolUse",
|
|
232
384
|
path.join(base, "hooks/ast-mcp.ts"),
|
|
233
385
|
global ? path.join(base, "hooks/ast-mcp.ts") : ".github/hooks/ast-mcp.ts",
|
|
234
|
-
)
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
);
|
|
238
|
-
checks.instructions = await instructionsCurrent(
|
|
386
|
+
),
|
|
387
|
+
skillCurrent(path.join(base, "skills/ast-mcp/SKILL.md")),
|
|
388
|
+
instructionsCurrent(
|
|
239
389
|
global
|
|
240
390
|
? path.join(base, "copilot-instructions.md")
|
|
241
391
|
: path.join(options.root, "AGENTS.md"),
|
|
392
|
+
),
|
|
393
|
+
]);
|
|
394
|
+
const checks: InstallChecks = { hook, instructions, mcp, skill };
|
|
395
|
+
if (!global)
|
|
396
|
+
checks.vscode = await jsonMcpCurrent(
|
|
397
|
+
path.join(options.root, ".vscode/mcp.json"),
|
|
398
|
+
"servers",
|
|
399
|
+
options.root,
|
|
400
|
+
"stdio",
|
|
401
|
+
options.transport,
|
|
402
|
+
options.url,
|
|
242
403
|
);
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
404
|
+
return checks;
|
|
405
|
+
}
|
|
406
|
+
function targetChecks(options: CheckOptions, home: string, global: boolean) {
|
|
407
|
+
if (options.target === "codex") return codexChecks(options, home, global);
|
|
408
|
+
if (options.target === "claude") return claudeChecks(options, home, global);
|
|
409
|
+
return copilotChecks(options, home, global);
|
|
410
|
+
}
|
|
411
|
+
function serviceFile(options: CheckOptions, home: string) {
|
|
412
|
+
const digest = new Bun.CryptoHasher("sha256")
|
|
413
|
+
.update(path.resolve(options.root))
|
|
414
|
+
.digest("hex")
|
|
415
|
+
.slice(0, 12);
|
|
416
|
+
const id = options.scope === "global" ? "ast-mcp" : `ast-mcp-${digest}`;
|
|
417
|
+
return process.platform === "darwin"
|
|
418
|
+
? path.join(home, "Library/LaunchAgents", `com.mwillbanks.${id}.plist`)
|
|
419
|
+
: path.join(home, ".config/systemd/user", `${id}.service`);
|
|
420
|
+
}
|
|
421
|
+
async function serviceCurrent(options: CheckOptions, home: string) {
|
|
422
|
+
if (process.platform !== "darwin" && process.platform !== "linux")
|
|
423
|
+
return false;
|
|
424
|
+
const content = await readFile(serviceFile(options, home), "utf8").catch(
|
|
425
|
+
() => "",
|
|
426
|
+
);
|
|
427
|
+
return (
|
|
428
|
+
content.includes("--transport") &&
|
|
429
|
+
content.includes("http") &&
|
|
430
|
+
content.includes(options.host) &&
|
|
431
|
+
content.includes(String(options.port)) &&
|
|
432
|
+
(options.scope === "global" || content.includes(path.resolve(options.root)))
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
function installOperation(checks: InstallChecks) {
|
|
436
|
+
if (Object.values(checks).every(Boolean)) return "none" as const;
|
|
437
|
+
return Object.values(checks).some(Boolean)
|
|
438
|
+
? ("update" as const)
|
|
439
|
+
: ("install" as const);
|
|
440
|
+
}
|
|
441
|
+
function commandSuffix(options: CheckOptions, global: boolean) {
|
|
442
|
+
return `--scope ${options.scope} --target ${options.target}${global ? "" : ` --root ${JSON.stringify(options.root)}`}${options.transport === "http" ? ` --transport http --host ${JSON.stringify(options.host)} --port ${options.port}` : ""}${options.service ? " --service" : ""}`;
|
|
443
|
+
}
|
|
444
|
+
function installCommands(options: CheckOptions, global: boolean) {
|
|
445
|
+
const suffix = commandSuffix(options, global);
|
|
446
|
+
return {
|
|
447
|
+
installCommand: global
|
|
448
|
+
? `bun add --global --trust @ast-bro/cli dprint @mwillbanks/ast-mcp && ast-mcp install ${suffix}`
|
|
449
|
+
: `bun add --dev @mwillbanks/ast-mcp && bun pm trust @ast-bro/cli dprint && ./node_modules/.bin/ast-mcp install ${suffix}`,
|
|
450
|
+
uninstallCommand: global
|
|
451
|
+
? `ast-mcp uninstall ${suffix}`
|
|
452
|
+
: `./node_modules/.bin/ast-mcp uninstall ${suffix}`,
|
|
453
|
+
updateCommand: global
|
|
454
|
+
? `ast-mcp update ${suffix}`
|
|
455
|
+
: `./node_modules/.bin/ast-mcp update ${suffix}`,
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
export async function checkInstall(
|
|
459
|
+
args = process.argv.slice(2),
|
|
460
|
+
home = os.homedir(),
|
|
461
|
+
) {
|
|
462
|
+
const options = parse(args);
|
|
463
|
+
const global = options.scope === "global";
|
|
464
|
+
const checks = await targetChecks(options, home, global);
|
|
465
|
+
if (options.service) checks.service = await serviceCurrent(options, home);
|
|
251
466
|
const installed = Object.values(checks).every(Boolean);
|
|
252
|
-
const operation =
|
|
253
|
-
|
|
254
|
-
: Object.values(checks).some(Boolean)
|
|
255
|
-
? "update"
|
|
256
|
-
: "install";
|
|
257
|
-
const suffix = `--scope ${options.scope} --target ${options.target}${global ? "" : ` --root ${JSON.stringify(options.root)}`}`;
|
|
258
|
-
const installCommand = global
|
|
259
|
-
? `bun add --global --trust @ast-bro/cli dprint @mwillbanks/ast-mcp && ast-mcp install ${suffix}`
|
|
260
|
-
: `bun add --dev @mwillbanks/ast-mcp && bun pm trust @ast-bro/cli dprint && ./node_modules/.bin/ast-mcp install ${suffix}`;
|
|
261
|
-
const updateCommand = global
|
|
262
|
-
? `ast-mcp update ${suffix}`
|
|
263
|
-
: `./node_modules/.bin/ast-mcp update ${suffix}`;
|
|
264
|
-
const uninstallCommand = global
|
|
265
|
-
? `ast-mcp uninstall ${suffix}`
|
|
266
|
-
: `./node_modules/.bin/ast-mcp uninstall ${suffix}`;
|
|
467
|
+
const operation = installOperation(checks);
|
|
468
|
+
const commands = installCommands(options, global);
|
|
267
469
|
return {
|
|
268
470
|
checks,
|
|
269
|
-
installCommand,
|
|
471
|
+
installCommand: commands.installCommand,
|
|
270
472
|
installed,
|
|
271
473
|
needsUpdate: operation === "update",
|
|
272
474
|
operation,
|
|
273
475
|
recommendedCommand:
|
|
274
476
|
operation === "update"
|
|
275
|
-
? updateCommand
|
|
477
|
+
? commands.updateCommand
|
|
276
478
|
: operation === "install"
|
|
277
|
-
? installCommand
|
|
479
|
+
? commands.installCommand
|
|
278
480
|
: undefined,
|
|
279
|
-
uninstallCommand,
|
|
280
|
-
updateCommand,
|
|
481
|
+
uninstallCommand: commands.uninstallCommand,
|
|
482
|
+
updateCommand: commands.updateCommand,
|
|
281
483
|
...options,
|
|
282
484
|
};
|
|
283
485
|
}
|