@mwillbanks/ast-mcp 0.1.2 → 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.
Files changed (58) hide show
  1. package/README.md +71 -22
  2. package/dist/ast-mcp.js +301 -101
  3. package/dist/ast-mcp.js.map +107 -27
  4. package/package.json +3 -1
  5. package/src/ast-bro/capability.ts +3 -8
  6. package/src/ast-bro/client.ts +18 -2
  7. package/src/ast-bro/result.ts +5 -12
  8. package/src/cli.ts +112 -13
  9. package/src/config-cli.ts +54 -0
  10. package/src/config.ts +886 -0
  11. package/src/helpers/aider.ts +252 -0
  12. package/src/helpers/ast-bro.ts +64 -0
  13. package/src/helpers/config.ts +149 -0
  14. package/src/helpers/hook.ts +60 -0
  15. package/src/helpers/installer.ts +249 -0
  16. package/src/helpers/json.ts +19 -0
  17. package/src/helpers/mcp-schema.ts +31 -0
  18. package/src/helpers/process.ts +31 -0
  19. package/src/helpers/string.ts +97 -0
  20. package/src/hook.ts +135 -40
  21. package/src/http-entry.ts +1 -1
  22. package/src/http.ts +118 -103
  23. package/src/installer-transport.ts +190 -0
  24. package/src/installer.ts +596 -235
  25. package/src/mcp-cli.ts +104 -0
  26. package/src/patch/aider.ts +6 -199
  27. package/src/patch/engine.ts +271 -197
  28. package/src/runtime/dependencies.ts +161 -8
  29. package/src/runtime/file-delete.ts +13 -9
  30. package/src/runtime/file-read.ts +91 -57
  31. package/src/runtime/file-rename.ts +158 -0
  32. package/src/runtime/format.ts +57 -34
  33. package/src/runtime/paths.ts +30 -16
  34. package/src/runtime/policy.ts +21 -0
  35. package/src/runtime/process-input.ts +14 -4
  36. package/src/service.ts +219 -0
  37. package/src/shell-policy.ts +331 -0
  38. package/src/stdio.ts +47 -35
  39. package/src/tools/ast-bro.ts +12 -6
  40. package/src/tools/configured.ts +28 -0
  41. package/src/tools/files.ts +24 -27
  42. package/src/tools/index.ts +5 -3
  43. package/src/tools/lifecycle.ts +69 -55
  44. package/templates/skills/ast-mcp/SKILL.md +7 -6
  45. package/templates/skills/ast-mcp/evals/batch.evals.json +48 -0
  46. package/templates/skills/ast-mcp/evals/evals.json +1 -0
  47. package/templates/skills/ast-mcp/evals/score.test.ts +175 -0
  48. package/templates/skills/ast-mcp/evals/score.ts +304 -267
  49. package/templates/skills/ast-mcp/evals/semantic.test.ts +322 -0
  50. package/templates/skills/ast-mcp/evals/semantic.ts +390 -135
  51. package/templates/skills/ast-mcp/evals/shell-policy.ts +252 -0
  52. package/templates/skills/ast-mcp/evals/source.test.ts +46 -0
  53. package/templates/skills/ast-mcp/evals/source.ts +164 -0
  54. package/templates/skills/ast-mcp/evals/trigger-queries.json +1 -1
  55. package/templates/skills/ast-mcp/references/installation.md +24 -11
  56. package/templates/skills/ast-mcp/references/patch-state-machine.md +5 -5
  57. package/templates/skills/ast-mcp/references/tool-catalog.md +4 -2
  58. package/templates/skills/ast-mcp/scripts/check-install.ts +312 -110
@@ -0,0 +1,175 @@
1
+ import { afterEach, expect, test } from "bun:test";
2
+ import { mkdtemp, rm, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { scoreTranscript } from "./score";
6
+
7
+ const directories: string[] = [];
8
+
9
+ afterEach(async () => {
10
+ await Promise.all(
11
+ directories
12
+ .splice(0)
13
+ .map((directory) => rm(directory, { force: true, recursive: true })),
14
+ );
15
+ });
16
+
17
+ async function transcript(lines: string[]) {
18
+ const directory = await mkdtemp(join(tmpdir(), "ast-mcp-score-"));
19
+ directories.push(directory);
20
+ const sessionPath = join(directory, "session.jsonl");
21
+ await writeFile(sessionPath, lines.join("\n"));
22
+ return { directory, sessionPath };
23
+ }
24
+
25
+ function record(type: string, payload: Record<string, unknown>) {
26
+ return JSON.stringify({ payload, type });
27
+ }
28
+
29
+ test("reports malformed and unmatched transcript records", async () => {
30
+ const { sessionPath } = await transcript([
31
+ "not-json",
32
+ record("response_item", {
33
+ call_id: "orphan",
34
+ output: "unmatched",
35
+ type: "custom_tool_call_output",
36
+ }),
37
+ ]);
38
+
39
+ const score = await scoreTranscript(sessionPath, true);
40
+ expect(score.passed).toBe(false);
41
+ expect(score.errors).toContain("line 1: invalid JSON");
42
+ expect(score.errors).toContain("unmatched output ID: orphan");
43
+ expect(score.errors).toContain(
44
+ "strict scoring requires at least one ast-mcp-eval marker",
45
+ );
46
+ });
47
+
48
+ test("binds direct calls to their marker and counts tool output", async () => {
49
+ const { sessionPath } = await transcript([
50
+ record("turn_context", {
51
+ cwd: process.cwd(),
52
+ workspace_roots: [process.cwd()],
53
+ }),
54
+ record("response_item", {
55
+ content: "ast-mcp-eval:999",
56
+ role: "user",
57
+ type: "message",
58
+ }),
59
+ record("response_item", {
60
+ call_id: "hash-call",
61
+ input: { filePaths: ["fixture.ts"] },
62
+ name: "mcp__ast_mcp__file_hash",
63
+ type: "custom_tool_call",
64
+ }),
65
+ record("response_item", {
66
+ call_id: "hash-call",
67
+ output: [{ text: "hash output", type: "input_text" }],
68
+ type: "custom_tool_call_output",
69
+ }),
70
+ ]);
71
+
72
+ const score = await scoreTranscript(sessionPath);
73
+ expect(score.execBatches).toBe(1);
74
+ expect(score.evaluatedCases).toBe(1);
75
+ expect(score.toolCalls.file_hash).toBe(1);
76
+ expect(score.astMcpOutputChars).toBe(11);
77
+ expect(score.errors).toContain("unknown eval ID: 999");
78
+ });
79
+
80
+ test("rejects nested exec evidence and duplicate identifiers", async () => {
81
+ const source = `// ast-mcp-eval:91\ntext(await tools.mcp__ast_mcp__file_rename({"a.ts":{"expectedSha256":"abc","destination":"b.ts"}}));`;
82
+ const { sessionPath } = await transcript([
83
+ record("response_item", {
84
+ call_id: "nested",
85
+ input: source,
86
+ name: "exec",
87
+ type: "custom_tool_call",
88
+ }),
89
+ record("response_item", {
90
+ call_id: "nested",
91
+ input: source,
92
+ name: "exec",
93
+ type: "custom_tool_call",
94
+ }),
95
+ record("response_item", {
96
+ call_id: "nested",
97
+ output: "renamed",
98
+ type: "custom_tool_call_output",
99
+ }),
100
+ record("response_item", {
101
+ call_id: "nested",
102
+ output: "duplicate",
103
+ type: "custom_tool_call_output",
104
+ }),
105
+ ]);
106
+
107
+ const score = await scoreTranscript(sessionPath);
108
+ expect(score.errors).toContain("duplicate call ID: nested");
109
+ expect(score.errors).toContain("duplicate output ID: nested");
110
+ expect(score.errors).toContain(
111
+ "eval 91 uses nested exec evidence that cannot be bound to individual MCP results",
112
+ );
113
+ });
114
+
115
+ test("evaluates successful and failed direct evidence", async () => {
116
+ const { sessionPath } = await transcript([
117
+ record("turn_context", {
118
+ cwd: process.cwd(),
119
+ workspace_roots: [process.cwd()],
120
+ }),
121
+ record("response_item", {
122
+ call_id: "valid-hash",
123
+ input: '// ast-mcp-eval:71\n{"filePaths":["src/server.ts"]}',
124
+ name: "mcp__ast_mcp__file_hash",
125
+ type: "custom_tool_call",
126
+ }),
127
+ record("response_item", {
128
+ call_id: "valid-hash",
129
+ output: [
130
+ { text: '{"filePath":"src/server.ts","sha256":"abc","size":1}' },
131
+ ],
132
+ type: "custom_tool_call_output",
133
+ }),
134
+ record("response_item", {
135
+ call_id: "failed-hash",
136
+ input: '// ast-mcp-eval:999\n{"filePaths":["src/server.ts"]}',
137
+ name: "mcp__ast_mcp__file_hash",
138
+ type: "custom_tool_call",
139
+ }),
140
+ record("response_item", {
141
+ call_id: "failed-hash",
142
+ isError: true,
143
+ output: "hash failed",
144
+ type: "custom_tool_call_output",
145
+ }),
146
+ ]);
147
+
148
+ const score = await scoreTranscript(sessionPath);
149
+ expect(score.passed).toBeFalse();
150
+ expect(score.evaluatedCases).toBe(2);
151
+ expect(score.verifiedAssertions).toBe(3);
152
+ expect(score.toolCalls.file_hash).toBe(2);
153
+ expect(score.errors).toContain("failed call ID: failed-hash");
154
+ expect(score.errors).toContain("unknown eval ID: 999");
155
+ });
156
+
157
+ test("accepts supported user message content shapes", async () => {
158
+ const { sessionPath } = await transcript(
159
+ [
160
+ "ast-mcp-eval:71",
161
+ {},
162
+ [null, {}, { text: null }, { text: "ast-mcp-eval:71" }],
163
+ ].map((content) =>
164
+ record("response_item", {
165
+ content,
166
+ role: "user",
167
+ type: "message",
168
+ }),
169
+ ),
170
+ );
171
+
172
+ const score = await scoreTranscript(sessionPath);
173
+ expect(score.passed).toBeTrue();
174
+ expect(score.evaluatedCases).toBe(0);
175
+ });