@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
|
@@ -10,8 +10,9 @@ import {
|
|
|
10
10
|
executableNames,
|
|
11
11
|
globalBinDirectories,
|
|
12
12
|
isExecutable,
|
|
13
|
+
npmNativeBinaries,
|
|
13
14
|
} from "./binary-resolution";
|
|
14
|
-
import { managedAstMcpHookEntry } from "./managed-hook";
|
|
15
|
+
import { isPackageHookEntry, managedAstMcpHookEntry } from "./managed-hook";
|
|
15
16
|
import {
|
|
16
17
|
checkLatestVersion,
|
|
17
18
|
compareVersions,
|
|
@@ -763,13 +764,18 @@ async function matchingSourceLaunch(
|
|
|
763
764
|
}
|
|
764
765
|
|
|
765
766
|
function* installedBinaryCandidates(root: string | undefined, home: string) {
|
|
766
|
-
const names =
|
|
767
|
+
const names = ["ast-mcp", "ast-mcp-bun"].flatMap((name) =>
|
|
768
|
+
executableNames(name, process.platform),
|
|
769
|
+
);
|
|
767
770
|
for (const discover of root ? [false] : [false, true]) {
|
|
768
771
|
const directories = root
|
|
769
772
|
? [path.join(root, "node_modules/.bin")]
|
|
770
773
|
: globalBinDirectories("ast-mcp", process.platform, home, discover);
|
|
771
|
-
for (const candidate of directoryBinaryCandidates(directories, names))
|
|
772
|
-
if (isExecutable(candidate, process.platform))
|
|
774
|
+
for (const candidate of directoryBinaryCandidates(directories, names)) {
|
|
775
|
+
if (!isExecutable(candidate, process.platform)) continue;
|
|
776
|
+
yield candidate;
|
|
777
|
+
yield* npmNativeBinaries(candidate);
|
|
778
|
+
}
|
|
773
779
|
}
|
|
774
780
|
}
|
|
775
781
|
|
|
@@ -849,26 +855,33 @@ async function hookCurrent(
|
|
|
849
855
|
const entries = Array.isArray(hostConfig.hooks?.[event])
|
|
850
856
|
? hostConfig.hooks[event]
|
|
851
857
|
: [];
|
|
852
|
-
|
|
858
|
+
type Hook = { command?: unknown; type?: unknown };
|
|
859
|
+
const hooks: Hook[] =
|
|
853
860
|
event === "preToolUse"
|
|
854
|
-
? entries
|
|
855
|
-
: entries.flatMap((item: { hooks?:
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
const
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
861
|
+
? entries
|
|
862
|
+
: entries.flatMap((item: { hooks?: Hook[] }) => item.hooks ?? []);
|
|
863
|
+
const managed: Array<{ command: string; entry: string; verified: boolean }> =
|
|
864
|
+
[];
|
|
865
|
+
for (const hook of hooks) {
|
|
866
|
+
const command = hook?.command;
|
|
867
|
+
const entry = managedAstMcpHookEntry(command);
|
|
868
|
+
if (typeof command !== "string" || entry === undefined) continue;
|
|
869
|
+
const packageHook = isPackageHookEntry(entry);
|
|
870
|
+
if (
|
|
871
|
+
packageHook &&
|
|
872
|
+
(hook.type !== "command" ||
|
|
873
|
+
command !== `${JSON.stringify(entry)} hook` ||
|
|
874
|
+
!(await astMcpEntry(entry, root, home)))
|
|
875
|
+
)
|
|
876
|
+
continue;
|
|
877
|
+
managed.push({ command, entry, verified: packageHook });
|
|
878
|
+
}
|
|
867
879
|
if (managed.length !== 1) return false;
|
|
868
|
-
const [{ command, entry }] = managed;
|
|
880
|
+
const [{ command, entry, verified }] = managed;
|
|
869
881
|
if (
|
|
870
|
-
|
|
871
|
-
(
|
|
882
|
+
verified ||
|
|
883
|
+
(command === `${JSON.stringify(entry)} hook` &&
|
|
884
|
+
(await astMcpEntry(entry, root, home)))
|
|
872
885
|
)
|
|
873
886
|
return true;
|
|
874
887
|
const receipt = await sourceLaunchReceipt(root, home);
|
|
@@ -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
|
);
|