@mwillbanks/ast-mcp 0.8.0 → 0.9.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/CONTRIBUTING.md +5 -2
- package/README.md +3 -3
- package/dist/ast-mcp-launch.cjs +124 -0
- package/dist/ast-mcp.js +305 -302
- package/dist/ast-mcp.js.map +6 -6
- package/dist/npm-platforms.json +30 -0
- package/package.json +10 -3
- package/src/cli/index.ts +11 -1
- package/src/hooks/managed.ts +48 -13
- package/src/installer/index.ts +124 -14
- package/src/runtime/binary-resolution.ts +79 -1
- package/templates/skills/ast-mcp/SKILL.md +1 -1
- package/templates/skills/ast-mcp/references/cli.md +1 -0
- package/templates/skills/ast-mcp/references/configuration.md +8 -0
- package/templates/skills/ast-mcp/references/installation.md +4 -0
- package/templates/skills/ast-mcp/references/tool-catalog.md +3 -0
- package/templates/skills/ast-mcp/scripts/binary-resolution.ts +79 -1
- package/templates/skills/ast-mcp/scripts/check-install.ts +34 -21
- package/templates/skills/ast-mcp/scripts/managed-hook.ts +48 -13
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"darwin-arm64": {
|
|
3
|
+
"os": "darwin",
|
|
4
|
+
"cpu": "arm64"
|
|
5
|
+
},
|
|
6
|
+
"linux-arm64": {
|
|
7
|
+
"os": "linux",
|
|
8
|
+
"cpu": "arm64",
|
|
9
|
+
"libc": "glibc"
|
|
10
|
+
},
|
|
11
|
+
"linux-x64": {
|
|
12
|
+
"os": "linux",
|
|
13
|
+
"cpu": "x64",
|
|
14
|
+
"libc": "glibc"
|
|
15
|
+
},
|
|
16
|
+
"linux-arm64-musl": {
|
|
17
|
+
"os": "linux",
|
|
18
|
+
"cpu": "arm64",
|
|
19
|
+
"libc": "musl"
|
|
20
|
+
},
|
|
21
|
+
"linux-x64-musl": {
|
|
22
|
+
"os": "linux",
|
|
23
|
+
"cpu": "x64",
|
|
24
|
+
"libc": "musl"
|
|
25
|
+
},
|
|
26
|
+
"windows-x64": {
|
|
27
|
+
"os": "win32",
|
|
28
|
+
"cpu": "x64"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Mike Willbanks",
|
|
3
3
|
"bin": {
|
|
4
|
-
"ast-mcp": "dist/ast-mcp.
|
|
4
|
+
"ast-mcp": "dist/ast-mcp-launch.cjs",
|
|
5
|
+
"ast-mcp-bun": "dist/ast-mcp.js"
|
|
5
6
|
},
|
|
6
7
|
"bugs": {
|
|
7
8
|
"url": "https://github.com/mwillbanks/ast-mcp/issues"
|
|
@@ -85,7 +86,13 @@
|
|
|
85
86
|
"@lancedb/lancedb-linux-x64-gnu": "0.41.0",
|
|
86
87
|
"@lancedb/lancedb-linux-x64-musl": "0.41.0",
|
|
87
88
|
"@lancedb/lancedb-win32-arm64-msvc": "0.41.0",
|
|
88
|
-
"@lancedb/lancedb-win32-x64-msvc": "0.41.0"
|
|
89
|
+
"@lancedb/lancedb-win32-x64-msvc": "0.41.0",
|
|
90
|
+
"@mwillbanks/ast-mcp-darwin-arm64": "0.9.0",
|
|
91
|
+
"@mwillbanks/ast-mcp-linux-arm64": "0.9.0",
|
|
92
|
+
"@mwillbanks/ast-mcp-linux-x64": "0.9.0",
|
|
93
|
+
"@mwillbanks/ast-mcp-linux-arm64-musl": "0.9.0",
|
|
94
|
+
"@mwillbanks/ast-mcp-linux-x64-musl": "0.9.0",
|
|
95
|
+
"@mwillbanks/ast-mcp-windows-x64": "0.9.0"
|
|
89
96
|
},
|
|
90
97
|
"overrides": {
|
|
91
98
|
"sharp": "0.35.5"
|
|
@@ -136,5 +143,5 @@
|
|
|
136
143
|
},
|
|
137
144
|
"sideEffects": false,
|
|
138
145
|
"type": "module",
|
|
139
|
-
"version": "0.
|
|
146
|
+
"version": "0.9.0"
|
|
140
147
|
}
|
package/src/cli/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { version } from "../../package.json";
|
|
1
2
|
import { CliOutputUsageError, parseOutputArguments } from "./output";
|
|
2
3
|
|
|
3
4
|
export interface CliHandlers {
|
|
@@ -12,7 +13,9 @@ export interface CliHandlers {
|
|
|
12
13
|
stdout?(text: string): void;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
const rootHelp = `ast-mcp - AST-aware Model Context Protocol server\n\nUsage:\n ast-mcp <command> [options]\n\nCommands:\n config Validate, display, or migrate ast-mcp.toml configuration\n doctor Diagnose host setup, approvals, and release currency\n install Configure ast-mcp for one or more supported hosts\n update Refresh an existing ast-mcp configuration\n uninstall Remove ast-mcp-managed configuration\n mcp Start the stdio or Streamable HTTP MCP server\n pm List, install, or diagnose native language packs\n skills Export or update manually installed skills\n hook Run the pre-tool-use filesystem guard\n help Display help for a command\n\nOptions:\n --output <format> Output: human, json, yaml, or toml
|
|
16
|
+
const rootHelp = `ast-mcp - AST-aware Model Context Protocol server\n\nUsage:\n ast-mcp <command> [options]\n\nCommands:\n config Validate, display, or migrate ast-mcp.toml configuration\n doctor Diagnose host setup, approvals, and release currency\n install Configure ast-mcp for one or more supported hosts\n update Refresh an existing ast-mcp configuration\n uninstall Remove ast-mcp-managed configuration\n mcp Start the stdio or Streamable HTTP MCP server\n pm List, install, or diagnose native language packs\n skills Export or update manually installed skills\n hook Run the pre-tool-use filesystem guard\n help Display help for a command\n\nOptions:\n --output <format> Output: human, json, yaml, or toml
|
|
17
|
+
--version Display the installed AST-MCP version
|
|
18
|
+
-h, --help Display help\n\nRun "ast-mcp help <command>" for command-specific help.\n`;
|
|
16
19
|
|
|
17
20
|
const installerOptions = `Options:\n -s, --scope <scope> Installation scope: local or global (default: local)\n -t, --target <target> Host: codex, claude, copilot, or all (default: all)\n -r, --root <path> Deprecated root override (default: current directory)\n --transport <mode> MCP transport: stdio or http (default: stdio)\n --host <address> HTTP bind host (default: layered configuration)\n --port <number> HTTP bind port (default: layered configuration)\n --service Install and start a managed user HTTP service\n --no-service Stop and remove a managed user HTTP service\n --output <format> Output: human, json, yaml, or toml\n -h, --help Display help\n`;
|
|
18
21
|
|
|
@@ -155,6 +158,13 @@ export async function runCli(
|
|
|
155
158
|
writeHelp(handlers);
|
|
156
159
|
return 0;
|
|
157
160
|
}
|
|
161
|
+
if (command === "--version") {
|
|
162
|
+
if (rest.length || parsed.output !== undefined)
|
|
163
|
+
return usageError(handlers, "--version does not accept arguments");
|
|
164
|
+
if (handlers.stdout) handlers.stdout(`${version}\n`);
|
|
165
|
+
else process.stdout.write(`${version}\n`);
|
|
166
|
+
return 0;
|
|
167
|
+
}
|
|
158
168
|
if (command === "help") return runHelpCommand(rest, handlers);
|
|
159
169
|
if (!Object.hasOwn(commandHelp, command))
|
|
160
170
|
return usageError(handlers, `Unknown command: ${command}`);
|
package/src/hooks/managed.ts
CHANGED
|
@@ -2,6 +2,30 @@ import path from "node:path";
|
|
|
2
2
|
|
|
3
3
|
export type HookEvent = "PreToolUse" | "preToolUse";
|
|
4
4
|
|
|
5
|
+
const legacyHookNames = [
|
|
6
|
+
"ast-mcp",
|
|
7
|
+
"ast-mcp.bat",
|
|
8
|
+
"ast-mcp.cmd",
|
|
9
|
+
"ast-mcp.com",
|
|
10
|
+
"ast-mcp.exe",
|
|
11
|
+
"ast-mcp.js",
|
|
12
|
+
"ast-mcp.ts",
|
|
13
|
+
];
|
|
14
|
+
const packageHookNames = [
|
|
15
|
+
"ast-mcp-bun",
|
|
16
|
+
"ast-mcp-bun.cmd",
|
|
17
|
+
"ast-mcp-bytecode",
|
|
18
|
+
"ast-mcp-bytecode.exe",
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
function hookBasename(entry: string) {
|
|
22
|
+
return path.basename(entry.replaceAll("\\", "/")).toLowerCase();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isPackageHookEntry(entry: string) {
|
|
26
|
+
return packageHookNames.includes(hookBasename(entry));
|
|
27
|
+
}
|
|
28
|
+
|
|
5
29
|
export function managedAstMcpHookEntry(command: unknown) {
|
|
6
30
|
if (typeof command !== "string") return undefined;
|
|
7
31
|
const normalized = command.trim();
|
|
@@ -26,39 +50,50 @@ export function managedAstMcpHookEntry(command: unknown) {
|
|
|
26
50
|
invocation = JSON.parse(invocation);
|
|
27
51
|
} catch {}
|
|
28
52
|
if (typeof invocation !== "string") return undefined;
|
|
29
|
-
return
|
|
30
|
-
|
|
31
|
-
"ast-mcp.bat",
|
|
32
|
-
"ast-mcp.cmd",
|
|
33
|
-
"ast-mcp.com",
|
|
34
|
-
"ast-mcp.exe",
|
|
35
|
-
"ast-mcp.js",
|
|
36
|
-
"ast-mcp.ts",
|
|
37
|
-
].includes(path.basename(invocation.replaceAll("\\", "/")).toLowerCase())
|
|
53
|
+
return legacyHookNames.includes(hookBasename(invocation)) ||
|
|
54
|
+
isPackageHookEntry(invocation)
|
|
38
55
|
? invocation
|
|
39
56
|
: undefined;
|
|
40
57
|
}
|
|
41
58
|
|
|
42
|
-
function commandMatches(
|
|
43
|
-
|
|
59
|
+
function commandMatches(
|
|
60
|
+
actual: unknown,
|
|
61
|
+
expected: string,
|
|
62
|
+
ownsPackageHook?: (command: string) => boolean,
|
|
63
|
+
) {
|
|
64
|
+
if (actual === expected) return true;
|
|
65
|
+
const entry = managedAstMcpHookEntry(actual);
|
|
66
|
+
return (
|
|
67
|
+
entry !== undefined &&
|
|
68
|
+
(legacyHookNames.includes(hookBasename(entry)) ||
|
|
69
|
+
(typeof actual === "string" && ownsPackageHook?.(actual) === true))
|
|
70
|
+
);
|
|
44
71
|
}
|
|
45
72
|
|
|
46
73
|
export function isManagedHook(
|
|
47
74
|
item: unknown,
|
|
48
75
|
event: HookEvent,
|
|
49
76
|
command: string,
|
|
77
|
+
ownsPackageHook?: (command: string) => boolean,
|
|
50
78
|
): boolean {
|
|
51
79
|
if (!item || typeof item !== "object") return false;
|
|
52
80
|
const value = item as Record<string, unknown>;
|
|
53
81
|
if (event === "preToolUse")
|
|
54
|
-
return
|
|
82
|
+
return (
|
|
83
|
+
commandMatches(value.command, command, ownsPackageHook) &&
|
|
84
|
+
value.type === "command"
|
|
85
|
+
);
|
|
55
86
|
return (
|
|
56
87
|
Array.isArray(value.hooks) &&
|
|
57
88
|
value.hooks.some(
|
|
58
89
|
(child) =>
|
|
59
90
|
child &&
|
|
60
91
|
typeof child === "object" &&
|
|
61
|
-
commandMatches(
|
|
92
|
+
commandMatches(
|
|
93
|
+
(child as Record<string, unknown>).command,
|
|
94
|
+
command,
|
|
95
|
+
ownsPackageHook,
|
|
96
|
+
) &&
|
|
62
97
|
(child as Record<string, unknown>).type === "command",
|
|
63
98
|
)
|
|
64
99
|
);
|
package/src/installer/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
2
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
3
3
|
import { lstat, readdir } from "node:fs/promises";
|
|
4
4
|
import os from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
@@ -22,7 +22,17 @@ import {
|
|
|
22
22
|
jsonTransport,
|
|
23
23
|
parseInstallerArguments,
|
|
24
24
|
} from "../helpers/installer";
|
|
25
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
isManagedHook,
|
|
27
|
+
isPackageHookEntry,
|
|
28
|
+
managedAstMcpHookEntry,
|
|
29
|
+
} from "../hooks/managed";
|
|
30
|
+
import {
|
|
31
|
+
directoryBinaryCandidates,
|
|
32
|
+
executableNames,
|
|
33
|
+
isExecutable,
|
|
34
|
+
npmNativeBinaries,
|
|
35
|
+
} from "../runtime/binary-resolution";
|
|
26
36
|
import {
|
|
27
37
|
globalBinDirectories,
|
|
28
38
|
resolveGlobalBinaryAlias,
|
|
@@ -31,6 +41,7 @@ import {
|
|
|
31
41
|
import { withFencedFileLocks } from "../runtime/locks";
|
|
32
42
|
import { pathWithin } from "../runtime/path-utils";
|
|
33
43
|
import { commandForPlatform } from "../runtime/subprocess";
|
|
44
|
+
import { bundledSkillRoot } from "../skills";
|
|
34
45
|
import {
|
|
35
46
|
enableCodexElicitation,
|
|
36
47
|
parseCodexConfig,
|
|
@@ -77,6 +88,7 @@ const cliEntry = path.join(
|
|
|
77
88
|
);
|
|
78
89
|
const installerRuntime = new AsyncLocalStorage<{
|
|
79
90
|
cliEntry: string;
|
|
91
|
+
ownsPackageHook?: (command: string) => boolean;
|
|
80
92
|
platform: NodeJS.Platform;
|
|
81
93
|
}>();
|
|
82
94
|
function stableGlobalCliEntry(
|
|
@@ -109,15 +121,35 @@ function stableGlobalCliEntry(
|
|
|
109
121
|
});
|
|
110
122
|
}
|
|
111
123
|
|
|
124
|
+
function resolvedCliAlias(alias: string, platform: NodeJS.Platform): string {
|
|
125
|
+
if (!/^ast-mcp-bytecode(?:[.]exe)?$/iu.test(path.basename(process.execPath)))
|
|
126
|
+
return alias;
|
|
127
|
+
const executable = realpathSync(process.execPath);
|
|
128
|
+
return (
|
|
129
|
+
npmNativeBinaries(alias, platform).find((candidate) =>
|
|
130
|
+
platform === "win32"
|
|
131
|
+
? candidate.toLowerCase() === executable.toLowerCase()
|
|
132
|
+
: candidate === executable,
|
|
133
|
+
) ?? alias
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
112
137
|
function configuredCliEntry(
|
|
113
138
|
options: InstallOptions,
|
|
114
139
|
root: string,
|
|
115
140
|
home: string,
|
|
116
141
|
) {
|
|
117
142
|
const platform = options.platform ?? process.platform;
|
|
143
|
+
const bunOnly = !Bun.which("node");
|
|
118
144
|
if (options.scope === "local") {
|
|
145
|
+
const bunAlias =
|
|
146
|
+
bunOnly && resolveLocalBinaryAlias("ast-mcp-bun", root, platform);
|
|
119
147
|
const alias = resolveLocalBinaryAlias("ast-mcp", root, platform);
|
|
120
|
-
if (alias)
|
|
148
|
+
if (alias) {
|
|
149
|
+
const resolved = resolvedCliAlias(alias, platform);
|
|
150
|
+
return resolved === alias && bunAlias ? bunAlias : resolved;
|
|
151
|
+
}
|
|
152
|
+
if (bunAlias) return bunAlias;
|
|
121
153
|
if (existsSync(cliEntry)) return cliEntry;
|
|
122
154
|
throw new Error(
|
|
123
155
|
"No local ast-mcp executable or shipped CLI was found. Build or install ast-mcp, then rerun the installer.",
|
|
@@ -134,21 +166,39 @@ function configuredCliEntry(
|
|
|
134
166
|
directories,
|
|
135
167
|
platform,
|
|
136
168
|
);
|
|
137
|
-
if (preferred)
|
|
138
|
-
|
|
169
|
+
if (preferred) {
|
|
170
|
+
const resolved = resolvedCliAlias(preferred, platform);
|
|
171
|
+
if (resolved !== preferred || !bunOnly) return resolved;
|
|
172
|
+
}
|
|
173
|
+
if (
|
|
174
|
+
options.cliEntry &&
|
|
175
|
+
!preferred &&
|
|
176
|
+
!discover &&
|
|
177
|
+
!options.globalBinDirectories
|
|
178
|
+
)
|
|
139
179
|
continue;
|
|
140
180
|
const resolved = resolveGlobalBinaryAlias("ast-mcp", {
|
|
141
181
|
globalBinDirectories: directories,
|
|
142
182
|
platform,
|
|
143
183
|
});
|
|
184
|
+
if (resolved) {
|
|
185
|
+
const command = resolvedCliAlias(resolved, platform);
|
|
186
|
+
if (command !== resolved || !bunOnly) return command;
|
|
187
|
+
}
|
|
188
|
+
const bunAlias =
|
|
189
|
+
bunOnly &&
|
|
190
|
+
resolveGlobalBinaryAlias("ast-mcp-bun", {
|
|
191
|
+
globalBinDirectories: directories,
|
|
192
|
+
platform,
|
|
193
|
+
});
|
|
194
|
+
if (bunAlias) return bunAlias;
|
|
144
195
|
if (resolved) return resolved;
|
|
145
196
|
}
|
|
146
197
|
throw new Error(
|
|
147
198
|
"No executable global ast-mcp package-manager alias was found. Install @mwillbanks/ast-mcp globally with Bun, npm, pnpm, or Yarn, then rerun the installer.",
|
|
148
199
|
);
|
|
149
200
|
}
|
|
150
|
-
function
|
|
151
|
-
const entry = installerRuntime.getStore()?.cliEntry ?? cliEntry;
|
|
201
|
+
function scopedCliEntry(entry: string, root: string | undefined) {
|
|
152
202
|
if (!root || /\.[cm]?[jt]s$/u.test(entry)) return entry;
|
|
153
203
|
const relative = path.relative(root, entry);
|
|
154
204
|
if (relative && pathWithin(root, entry))
|
|
@@ -156,6 +206,57 @@ function cliEntryFor(root: string | undefined, _home: string) {
|
|
|
156
206
|
return entry;
|
|
157
207
|
}
|
|
158
208
|
|
|
209
|
+
function cliEntryFor(root: string | undefined, _home: string) {
|
|
210
|
+
return scopedCliEntry(
|
|
211
|
+
installerRuntime.getStore()?.cliEntry ?? cliEntry,
|
|
212
|
+
root,
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function installerHookOwnership(
|
|
217
|
+
options: InstallOptions,
|
|
218
|
+
root: string,
|
|
219
|
+
home: string,
|
|
220
|
+
) {
|
|
221
|
+
const platform = options.platform ?? process.platform;
|
|
222
|
+
const key = (entry: string) =>
|
|
223
|
+
platform === "win32" ? path.win32.normalize(entry).toLowerCase() : entry;
|
|
224
|
+
let entries: Set<string> | undefined;
|
|
225
|
+
return (command: string) => {
|
|
226
|
+
const entry = managedAstMcpHookEntry(command);
|
|
227
|
+
if (
|
|
228
|
+
entry === undefined ||
|
|
229
|
+
!isPackageHookEntry(entry) ||
|
|
230
|
+
command !== hookCommand(entry)
|
|
231
|
+
)
|
|
232
|
+
return false;
|
|
233
|
+
if (!entries) {
|
|
234
|
+
const local = options.scope === "local";
|
|
235
|
+
const directories = local
|
|
236
|
+
? [path.join(root, "node_modules/.bin")]
|
|
237
|
+
: (options.globalBinDirectories ??
|
|
238
|
+
globalBinDirectories("ast-mcp", platform, home));
|
|
239
|
+
const aliases = (name: string) =>
|
|
240
|
+
directoryBinaryCandidates(
|
|
241
|
+
directories,
|
|
242
|
+
executableNames(name, platform),
|
|
243
|
+
).filter((candidate) => isExecutable(candidate, platform));
|
|
244
|
+
const paths = [
|
|
245
|
+
...aliases("ast-mcp-bun"),
|
|
246
|
+
...aliases("ast-mcp").flatMap((alias) =>
|
|
247
|
+
npmNativeBinaries(alias, platform),
|
|
248
|
+
),
|
|
249
|
+
];
|
|
250
|
+
entries = new Set(
|
|
251
|
+
paths.map((entry) =>
|
|
252
|
+
key(scopedCliEntry(entry, local ? root : undefined)),
|
|
253
|
+
),
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
return entries.has(key(entry));
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
159
260
|
function cliInvocation(entry: string, args: string[]) {
|
|
160
261
|
return /\.[cm]?[jt]s$/u.test(entry)
|
|
161
262
|
? commandForPlatform(
|
|
@@ -453,12 +554,20 @@ function retainUnmanagedHooks(
|
|
|
453
554
|
commands: string[],
|
|
454
555
|
): unknown[] {
|
|
455
556
|
const factory = factoryHook(event, commands[0]!);
|
|
557
|
+
const ownsPackageHook = installerRuntime.getStore()?.ownsPackageHook;
|
|
558
|
+
const ownsCommand = (actual: unknown) =>
|
|
559
|
+
typeof actual === "string" &&
|
|
560
|
+
(commands.includes(actual) || ownsPackageHook?.(actual) === true);
|
|
456
561
|
return prior.flatMap((item) => {
|
|
457
|
-
if (
|
|
562
|
+
if (
|
|
563
|
+
!commands.some((command) =>
|
|
564
|
+
isManagedHook(item, event, command, ownsPackageHook),
|
|
565
|
+
)
|
|
566
|
+
)
|
|
458
567
|
return [item];
|
|
459
568
|
const group = item as Record<string, any>;
|
|
460
569
|
if (event === "preToolUse")
|
|
461
|
-
return
|
|
570
|
+
return ownsCommand(group.command) &&
|
|
462
571
|
isDeepStrictEqual({ ...group, command: commands[0] }, factory)
|
|
463
572
|
? []
|
|
464
573
|
: [item];
|
|
@@ -467,9 +576,7 @@ function retainUnmanagedHooks(
|
|
|
467
576
|
if (!isDeepStrictEqual(metadata, factoryMetadata)) return [item];
|
|
468
577
|
const retained = (hooks as unknown[]).filter(
|
|
469
578
|
(child) =>
|
|
470
|
-
!
|
|
471
|
-
(child as Record<string, unknown>)?.command as string,
|
|
472
|
-
) ||
|
|
579
|
+
!ownsCommand((child as Record<string, unknown>)?.command) ||
|
|
473
580
|
!isDeepStrictEqual(
|
|
474
581
|
{ ...(child as Record<string, unknown>), command: commands[0] },
|
|
475
582
|
factory.hooks[0],
|
|
@@ -484,9 +591,10 @@ function refreshManagedHooks(
|
|
|
484
591
|
command: string,
|
|
485
592
|
): unknown[] {
|
|
486
593
|
const factory = factoryHook(event, command);
|
|
594
|
+
const ownsPackageHook = installerRuntime.getStore()?.ownsPackageHook;
|
|
487
595
|
let found = false;
|
|
488
596
|
const refreshed = prior.map((item) => {
|
|
489
|
-
if (!isManagedHook(item, event, command)) return item;
|
|
597
|
+
if (!isManagedHook(item, event, command, ownsPackageHook)) return item;
|
|
490
598
|
const group = item as Record<string, any>;
|
|
491
599
|
if (event === "preToolUse") {
|
|
492
600
|
if (group.command === command) {
|
|
@@ -561,7 +669,7 @@ async function writeText(file: string, content: string) {
|
|
|
561
669
|
|
|
562
670
|
async function instructions(file: string) {
|
|
563
671
|
const block = (
|
|
564
|
-
await Bun.file(path.join(
|
|
672
|
+
await Bun.file(path.join(bundledSkillRoot, "../../AGENTS.md")).text()
|
|
565
673
|
).trim();
|
|
566
674
|
const old = await readInstallerText(file).catch((error) => {
|
|
567
675
|
if ((error as NodeJS.ErrnoException).code === "ENOENT") return "";
|
|
@@ -1224,6 +1332,7 @@ async function reconcile(
|
|
|
1224
1332
|
return installerRuntime.run(
|
|
1225
1333
|
{
|
|
1226
1334
|
cliEntry: configuredCliEntry(options, root, home),
|
|
1335
|
+
ownsPackageHook: installerHookOwnership(options, root, home),
|
|
1227
1336
|
platform: options.platform ?? process.platform,
|
|
1228
1337
|
},
|
|
1229
1338
|
async () => {
|
|
@@ -1386,6 +1495,7 @@ async function uninstallLocked(options: InstallOptions) {
|
|
|
1386
1495
|
return installerRuntime.run(
|
|
1387
1496
|
{
|
|
1388
1497
|
cliEntry: configuredCliEntry(options, root, home),
|
|
1498
|
+
ownsPackageHook: installerHookOwnership(options, root, home),
|
|
1389
1499
|
platform: options.platform ?? process.platform,
|
|
1390
1500
|
},
|
|
1391
1501
|
async () => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { statSync } from "node:fs";
|
|
1
|
+
import { realpathSync, statSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
2
3
|
import os from "node:os";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
|
|
@@ -71,6 +72,83 @@ export function isExecutable(
|
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
export function npmNativeBinaries(
|
|
76
|
+
alias: string,
|
|
77
|
+
platform: NodeJS.Platform = process.platform,
|
|
78
|
+
arch: string = process.arch,
|
|
79
|
+
): string[] {
|
|
80
|
+
const directory = path.dirname(alias);
|
|
81
|
+
const modules =
|
|
82
|
+
path.basename(directory) === ".bin"
|
|
83
|
+
? path.dirname(directory)
|
|
84
|
+
: path.join(directory, "node_modules");
|
|
85
|
+
const roots = new Set([path.join(modules, "@mwillbanks", "ast-mcp")]);
|
|
86
|
+
try {
|
|
87
|
+
const entry = realpathSync(alias);
|
|
88
|
+
if (path.basename(entry) === "ast-mcp-launch.cjs")
|
|
89
|
+
roots.add(path.dirname(path.dirname(entry)));
|
|
90
|
+
} catch {
|
|
91
|
+
// The npm shim can be absent while checking a previous installation.
|
|
92
|
+
}
|
|
93
|
+
const names =
|
|
94
|
+
platform === "win32"
|
|
95
|
+
? [`windows-${arch}`]
|
|
96
|
+
: [
|
|
97
|
+
`${platform}-${arch}`,
|
|
98
|
+
...(platform === "linux" ? [`linux-${arch}-musl`] : []),
|
|
99
|
+
];
|
|
100
|
+
const binaries = new Set<string>();
|
|
101
|
+
for (const root of roots) {
|
|
102
|
+
const packageManifest = path.join(root, "package.json");
|
|
103
|
+
try {
|
|
104
|
+
const requireInstalled = createRequire(packageManifest);
|
|
105
|
+
const installed = requireInstalled(packageManifest) as {
|
|
106
|
+
name?: string;
|
|
107
|
+
optionalDependencies?: Record<string, string>;
|
|
108
|
+
version?: string;
|
|
109
|
+
};
|
|
110
|
+
if (installed.name !== "@mwillbanks/ast-mcp") continue;
|
|
111
|
+
for (const target of names) {
|
|
112
|
+
const name = `@mwillbanks/ast-mcp-${target}`;
|
|
113
|
+
if (
|
|
114
|
+
!installed.version ||
|
|
115
|
+
installed.optionalDependencies?.[name] !== installed.version
|
|
116
|
+
)
|
|
117
|
+
continue;
|
|
118
|
+
try {
|
|
119
|
+
const manifest = realpathSync(
|
|
120
|
+
requireInstalled.resolve(`${name}/package.json`),
|
|
121
|
+
);
|
|
122
|
+
// Versioned pnpm or Yarn paths can change on every upgrade.
|
|
123
|
+
// Those managers retain their existing stable bin aliases.
|
|
124
|
+
if (
|
|
125
|
+
manifest
|
|
126
|
+
.split(path.sep)
|
|
127
|
+
.some((segment) => segment === ".pnpm" || segment === ".yarn")
|
|
128
|
+
)
|
|
129
|
+
continue;
|
|
130
|
+
const native = requireInstalled(manifest) as {
|
|
131
|
+
name?: string;
|
|
132
|
+
version?: string;
|
|
133
|
+
};
|
|
134
|
+
if (native.name !== name || native.version !== installed.version)
|
|
135
|
+
continue;
|
|
136
|
+
const executable = path.join(
|
|
137
|
+
path.dirname(manifest),
|
|
138
|
+
platform === "win32" ? "ast-mcp-bytecode.exe" : "ast-mcp-bytecode",
|
|
139
|
+
);
|
|
140
|
+
if (isExecutable(executable, platform)) binaries.add(executable);
|
|
141
|
+
} catch {
|
|
142
|
+
// An optional package for another libc need not be installed.
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} catch {
|
|
146
|
+
// Other managers can expose an alias without npm package metadata.
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return [...binaries];
|
|
150
|
+
}
|
|
151
|
+
|
|
74
152
|
function commandOutput(command: string, args: string[]) {
|
|
75
153
|
try {
|
|
76
154
|
const result = Bun.spawnSync([command, ...args], {
|
|
@@ -48,7 +48,7 @@ Keep Codex-specific recovery separate from Claude, Claude Desktop, Grok, Copilot
|
|
|
48
48
|
1. Start unfamiliar work with `digest`. Use `map` for file structure and `show` for symbols.
|
|
49
49
|
2. Use `search` or `find_related` for discovery, and `context` for nearby calls.
|
|
50
50
|
3. Use `impact` before shared API changes. Use callers, dependencies, and graph tools to check affected code.
|
|
51
|
-
4. Batch independent reads when schemas permit. Keep overlapping writes and dependent operations sequential.
|
|
51
|
+
4. Batch independent reads when schemas permit. Use `read_symbols` for several exact definitions and callers in one bounded request. Keep overlapping writes and dependent operations sequential.
|
|
52
52
|
5. Keep native intelligence requests within one project root. Use absolute paths for linked worktrees.
|
|
53
53
|
6. Use `file_read` with explicit `mode` when intent matters.
|
|
54
54
|
7. Use source `symbols`, structured-document `selectors`, or bounded text ranges.
|
|
@@ -23,6 +23,7 @@ Do not download an executable through an implicit package runner.
|
|
|
23
23
|
|
|
24
24
|
Run `ast-mcp help <command>` or `ast-mcp <command> --help` for executable-specific help.
|
|
25
25
|
Root `-h` and `--help` also display help.
|
|
26
|
+
Run `ast-mcp --version` to display the installed version.
|
|
26
27
|
Ordinary commands accept `--output human|json|yaml|toml`.
|
|
27
28
|
Protocol commands `mcp` and `hook` reject `--output`; stdout belongs to their protocol.
|
|
28
29
|
Usage errors return a nonzero exit.
|
|
@@ -36,6 +36,14 @@ Use the discovered schema for nested provider, embedding, storage, and formatter
|
|
|
36
36
|
Do not invent settings or transfer fields from tool requests into configuration.
|
|
37
37
|
Load [installation.md](installation.md) for migration and invalid-configuration recovery.
|
|
38
38
|
|
|
39
|
+
## Index freshness
|
|
40
|
+
|
|
41
|
+
The per-request `strictRead` option defaults to `false`.
|
|
42
|
+
Use it on supported index-backed tools to wait for the scheduled generation within the request budget.
|
|
43
|
+
Strict reads can be slower and can return `intelligence_refresh_pending`.
|
|
44
|
+
Guarded writes acknowledge durable source bytes before the coalesced refresh finishes.
|
|
45
|
+
LanceDB stores the index and SQLite records the write recovery journal.
|
|
46
|
+
|
|
39
47
|
## Native language packs
|
|
40
48
|
|
|
41
49
|
Version 2 accepts `[language_packs]` and `[language_packs.versions]`.
|
|
@@ -70,6 +70,10 @@ For a persistent global npm installation or upgrade:
|
|
|
70
70
|
`npm install --global @mwillbanks/ast-mcp@latest`
|
|
71
71
|
|
|
72
72
|
Use the discovered global `ast-mcp` executable for subsequent global commands.
|
|
73
|
+
On supported platforms, npm installs the matching compiled executable with Bun embedded and can install with scripts disabled.
|
|
74
|
+
The regular Bun bundle remains the fallback where a compiled package is unavailable.
|
|
75
|
+
The npm-installed `ast-mcp` command uses a Node launcher. Use `ast-mcp-bun` to run the bundle directly with an installed Bun runtime.
|
|
76
|
+
Alpine arm64 needs `gcompat` for the bundled Markdown parser.
|
|
73
77
|
Do not configure ephemeral package-runner paths or internal package files.
|
|
74
78
|
Yarn 2+ installations must use a project-local package.
|
|
75
79
|
|
|
@@ -155,6 +155,9 @@ Deletion count accepts 1–100,000; grace accepts 0–86,400 seconds.
|
|
|
155
155
|
|
|
156
156
|
Indexed reads can return a retained generation while a refresh is pending.
|
|
157
157
|
Set `strictRead: true` to wait for a current generation within the request deadline.
|
|
158
|
+
The default is `false` and marks retained results stale.
|
|
159
|
+
Waiting can raise latency or return `intelligence_refresh_pending` during sustained writes.
|
|
160
|
+
Use direct source inspection when the task needs the current bytes.
|
|
158
161
|
Optional filters are `deniedPaths`, `includedPaths`, `exactSymbols`, and `languages`.
|
|
159
162
|
Paths are repository-relative.
|
|
160
163
|
`intent` accepts `implementation`, `behavior`, or `documentation`.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { statSync } from "node:fs";
|
|
1
|
+
import { realpathSync, statSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
2
3
|
import os from "node:os";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
|
|
@@ -71,6 +72,83 @@ export function isExecutable(
|
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
export function npmNativeBinaries(
|
|
76
|
+
alias: string,
|
|
77
|
+
platform: NodeJS.Platform = process.platform,
|
|
78
|
+
arch: string = process.arch,
|
|
79
|
+
): string[] {
|
|
80
|
+
const directory = path.dirname(alias);
|
|
81
|
+
const modules =
|
|
82
|
+
path.basename(directory) === ".bin"
|
|
83
|
+
? path.dirname(directory)
|
|
84
|
+
: path.join(directory, "node_modules");
|
|
85
|
+
const roots = new Set([path.join(modules, "@mwillbanks", "ast-mcp")]);
|
|
86
|
+
try {
|
|
87
|
+
const entry = realpathSync(alias);
|
|
88
|
+
if (path.basename(entry) === "ast-mcp-launch.cjs")
|
|
89
|
+
roots.add(path.dirname(path.dirname(entry)));
|
|
90
|
+
} catch {
|
|
91
|
+
// The npm shim can be absent while checking a previous installation.
|
|
92
|
+
}
|
|
93
|
+
const names =
|
|
94
|
+
platform === "win32"
|
|
95
|
+
? [`windows-${arch}`]
|
|
96
|
+
: [
|
|
97
|
+
`${platform}-${arch}`,
|
|
98
|
+
...(platform === "linux" ? [`linux-${arch}-musl`] : []),
|
|
99
|
+
];
|
|
100
|
+
const binaries = new Set<string>();
|
|
101
|
+
for (const root of roots) {
|
|
102
|
+
const packageManifest = path.join(root, "package.json");
|
|
103
|
+
try {
|
|
104
|
+
const requireInstalled = createRequire(packageManifest);
|
|
105
|
+
const installed = requireInstalled(packageManifest) as {
|
|
106
|
+
name?: string;
|
|
107
|
+
optionalDependencies?: Record<string, string>;
|
|
108
|
+
version?: string;
|
|
109
|
+
};
|
|
110
|
+
if (installed.name !== "@mwillbanks/ast-mcp") continue;
|
|
111
|
+
for (const target of names) {
|
|
112
|
+
const name = `@mwillbanks/ast-mcp-${target}`;
|
|
113
|
+
if (
|
|
114
|
+
!installed.version ||
|
|
115
|
+
installed.optionalDependencies?.[name] !== installed.version
|
|
116
|
+
)
|
|
117
|
+
continue;
|
|
118
|
+
try {
|
|
119
|
+
const manifest = realpathSync(
|
|
120
|
+
requireInstalled.resolve(`${name}/package.json`),
|
|
121
|
+
);
|
|
122
|
+
// Versioned pnpm or Yarn paths can change on every upgrade.
|
|
123
|
+
// Those managers retain their existing stable bin aliases.
|
|
124
|
+
if (
|
|
125
|
+
manifest
|
|
126
|
+
.split(path.sep)
|
|
127
|
+
.some((segment) => segment === ".pnpm" || segment === ".yarn")
|
|
128
|
+
)
|
|
129
|
+
continue;
|
|
130
|
+
const native = requireInstalled(manifest) as {
|
|
131
|
+
name?: string;
|
|
132
|
+
version?: string;
|
|
133
|
+
};
|
|
134
|
+
if (native.name !== name || native.version !== installed.version)
|
|
135
|
+
continue;
|
|
136
|
+
const executable = path.join(
|
|
137
|
+
path.dirname(manifest),
|
|
138
|
+
platform === "win32" ? "ast-mcp-bytecode.exe" : "ast-mcp-bytecode",
|
|
139
|
+
);
|
|
140
|
+
if (isExecutable(executable, platform)) binaries.add(executable);
|
|
141
|
+
} catch {
|
|
142
|
+
// An optional package for another libc need not be installed.
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} catch {
|
|
146
|
+
// Other managers can expose an alias without npm package metadata.
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return [...binaries];
|
|
150
|
+
}
|
|
151
|
+
|
|
74
152
|
function commandOutput(command: string, args: string[]) {
|
|
75
153
|
try {
|
|
76
154
|
const result = Bun.spawnSync([command, ...args], {
|