@mwillbanks/ast-mcp 0.2.1 → 0.2.2
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 +3 -1
- package/dist/ast-mcp.js +63 -63
- package/dist/ast-mcp.js.map +11 -11
- package/package.json +1 -1
- package/src/config.ts +32 -4
- package/src/helpers/config.ts +5 -3
- package/src/helpers/mcp-schema.ts +7 -0
- package/src/runtime/file-delete.ts +33 -4
- package/src/runtime/file-rename.ts +2 -4
- package/src/runtime/paths.ts +85 -22
- package/src/tools/ast-bro.ts +3 -3
- package/src/tools/files.ts +15 -18
- package/src/tools/lifecycle.ts +13 -13
- package/templates/AGENTS.md +5 -5
- package/templates/skills/ast-mcp/SKILL.md +31 -23
- package/templates/skills/ast-mcp/evals/batch.evals.json +9 -9
- package/templates/skills/ast-mcp/evals/measure.ts +27 -4
- package/templates/skills/ast-mcp/evals/score.test.ts +46 -3
- package/templates/skills/ast-mcp/evals/score.ts +7 -0
- package/templates/skills/ast-mcp/evals/semantic.test.ts +209 -28
- package/templates/skills/ast-mcp/evals/semantic.ts +148 -36
- package/templates/skills/ast-mcp/references/installation.md +1 -1
- package/templates/skills/ast-mcp/references/patch-state-machine.md +4 -4
- package/templates/skills/ast-mcp/references/tool-catalog.md +6 -6
|
@@ -26,32 +26,36 @@ Treat ast-mcp as the only code-intelligence and filesystem boundary. Do not call
|
|
|
26
26
|
|
|
27
27
|
Read [tool-catalog.md](references/tool-catalog.md) for exact arguments and combinations.
|
|
28
28
|
|
|
29
|
-
## Mutate through
|
|
29
|
+
## Mutate through declared file batches
|
|
30
30
|
|
|
31
31
|
1. Inspect AST-capable targets with `map`, `show`, `context`, or a bounded `run` search. For unsupported content, use one batched `file_read({ files: [...] })` call with narrow line ranges.
|
|
32
|
-
2. Preview every AST rule with `run({ pattern, paths: [filePath], lang?, json: true })`; inspect all matches and reject capped output before mutation. For a contract-level dry run, send the same
|
|
33
|
-
3. Call one batched `file_hash({ filePaths: [...] })` immediately before guarded edits. Keep one returned hash per
|
|
34
|
-
4.
|
|
32
|
+
2. Preview every AST rule with `run({ pattern, paths: [filePath], lang?, json: true })`; inspect all matches and reject capped output before mutation. For a contract-level dry run, send the same `file_patch` file entry with `preview: true`; it returns the formatted bounded diff and never commits.
|
|
33
|
+
3. Call one batched `file_hash({ filePaths: [...] })` immediately before guarded edits. Keep one returned hash per file. The runtime can make hashes optional through `safety.require_hash = false`, but the normal agent workflow should still supply them whenever current-state protection matters.
|
|
34
|
+
4. Mutation tools accept a declared `files` property whose value is a path-keyed object. Use one `file_patch({ files: { ... } })` call for one or more files:
|
|
35
35
|
- AST targets: `{ expectedSha256, patchStrategy: "ast", astRules: [{ pattern, fix, expectedMatches: 1 }], preview?: boolean }`
|
|
36
36
|
- Unsupported targets: `{ expectedSha256, patchStrategy: "aider_block", aiderBlocks: [{ search, replace }], preview?: boolean }`
|
|
37
37
|
Operations in each array run in order under one file lock; preview returns without committing and normal mode commits atomically.
|
|
38
|
-
5. Use one
|
|
39
|
-
6. Use one
|
|
40
|
-
7. Use `file_chattr` for metadata-only changes. Use hash-guarded `file_delete` for deletion; it preflights all targets and AST import references before any deletion, requires an explicit `forceReferences` override for referenced source, and removes empty ancestor directories after lock release.
|
|
38
|
+
5. Use one `file_write({ files: { ... } })` batch for new files or SHA-guarded replacement of existing non-structurally-rewritable files. Supply the shared `chattr` object when chmod/chown metadata is required; missing parents are created only after a guarded `ENOENT` write and path revalidation.
|
|
39
|
+
6. Use one `file_rename({ files: { ... } })` batch for hash-guarded moves; validate every source and destination, reject existing destinations, and use no-replace moves. Ordinary failures roll back completed entries when possible; the operation is not crash-atomic.
|
|
40
|
+
7. Use `file_chattr({ files: { ... } })` for metadata-only changes. Use hash-guarded `file_delete({ files: { ... } })` for deletion; it preflights all targets and AST import references before any deletion, requires an explicit `forceReferences` override for referenced source, and removes empty ancestor directories after lock release.
|
|
41
41
|
8. Use direct `run` with `rewrite` and `write: true` only for an intentionally bounded lower-level rewrite; it is not the normal agent patch route and still rewrites only the first match per file.
|
|
42
|
-
9. Verify
|
|
42
|
+
9. Verify results with `show`, `map`, `run`, or bounded `file_read` slices, then run repository validation.
|
|
43
|
+
|
|
44
|
+
The OS temporary directory is an allowed file-operation root by default. Set `safety.allow_temp_directory = false` to disable it. `safety.allow_any_path = true` is an explicit unrestricted mode for file tools; do not enable it merely to avoid configuring a workspace root.
|
|
43
45
|
|
|
44
46
|
Example batched AST patch:
|
|
45
47
|
|
|
46
48
|
```json
|
|
47
49
|
file_patch({
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
"files": {
|
|
51
|
+
"/repo/src/service.ts": {
|
|
52
|
+
"expectedSha256": "<from file_hash>",
|
|
53
|
+
"patchStrategy": "ast",
|
|
54
|
+
"astRules": [
|
|
55
|
+
{ "pattern": "oldName($$$ARGS)", "fix": "newName($$$ARGS)", "expectedMatches": 1 },
|
|
56
|
+
{ "pattern": "oldFlag", "fix": "newFlag", "expectedMatches": 1 }
|
|
57
|
+
]
|
|
58
|
+
}
|
|
55
59
|
}
|
|
56
60
|
})
|
|
57
61
|
```
|
|
@@ -60,10 +64,12 @@ Example batched Aider patch:
|
|
|
60
64
|
|
|
61
65
|
```json
|
|
62
66
|
file_patch({
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
"files": {
|
|
68
|
+
"/repo/notes.md": {
|
|
69
|
+
"expectedSha256": "<from file_hash>",
|
|
70
|
+
"patchStrategy": "aider_block",
|
|
71
|
+
"aiderBlocks": [{ "search": "old paragraph", "replace": "new paragraph" }]
|
|
72
|
+
}
|
|
67
73
|
}
|
|
68
74
|
})
|
|
69
75
|
```
|
|
@@ -72,8 +78,10 @@ Example batched file write:
|
|
|
72
78
|
|
|
73
79
|
```json
|
|
74
80
|
file_write({
|
|
75
|
-
"
|
|
76
|
-
|
|
81
|
+
"files": {
|
|
82
|
+
"/repo/new-a.txt": { "content": "alpha\\n" },
|
|
83
|
+
"/repo/existing.txt": { "content": "beta\\n", "expectedSha256": "<from file_hash>" }
|
|
84
|
+
}
|
|
77
85
|
})
|
|
78
86
|
```
|
|
79
87
|
|
|
@@ -84,7 +92,7 @@ Read [patch-state-machine.md](references/patch-state-machine.md) for routing and
|
|
|
84
92
|
## Recover safely
|
|
85
93
|
|
|
86
94
|
- Stale SHA: refresh `file_hash`, re-inspect through AST or a bounded unsupported-content slice, and rebuild the patch.
|
|
87
|
-
- Zero or excess matches: narrow each AST rule; every astRules item must match exactly one node because ast-bro rewrites the first match per file, while ordered arrays let one
|
|
95
|
+
- Zero or excess matches: narrow each AST rule; every astRules item must match exactly one node because ast-bro rewrites the first match per file, while ordered arrays let one declared `file_patch.files` entry apply multiple reviewed operations.
|
|
88
96
|
- Capped direct preview: narrow paths, glob, or pattern before writing.
|
|
89
97
|
- Aider ambiguity: request a larger bounded slice and expand the search block with unique surrounding context.
|
|
90
98
|
- Formatter preflight failure: inspect the active `[formatting]` policy. Do not write until the matching external formatter or dprint fallback succeeds; `enabled = false` deliberately skips formatting.
|
|
@@ -94,4 +102,4 @@ Read [patch-state-machine.md](references/patch-state-machine.md) for routing and
|
|
|
94
102
|
|
|
95
103
|
Confirm the old structure is absent through AST search, callers are correct, touched files were verified through their proper route, configured formatter-backed writes succeeded (or formatting is explicitly disabled), repository validation passes, and no direct-write or whole-file-read bypass was used.
|
|
96
104
|
|
|
97
|
-
Use `evals:check` for fixture-matrix integrity. `evals:measure` inventories direct MCP transcript records and statically visible `tools.mcp__ast_mcp__*` calls inside top-level Codex `exec` source. Put exactly one `ast-mcp-eval:<id>` marker in the user evaluation prompt, or in a direct record input supplied by an evaluation harness, to associate the following direct MCP records with that case. An outer `exec` result cannot prove each nested call, so marked nested calls and multi-marker evidence fail closed. Scoring validates schema-relevant inputs, transcript workspace roots, required order, expected output evidence, assertions, and successful per-call outputs. Use `evals:score --strict` only for a complete marked matrix; transcript scoring is matched task-execution evidence, not a blanket agent-quality claim.
|
|
105
|
+
Use `evals:check` for fixture-matrix integrity. `evals:measure` inventories direct MCP transcript records and statically visible `tools.mcp__ast_mcp__*` calls inside top-level Codex `exec` source. Put exactly one `ast-mcp-eval:<id>` marker in the user evaluation prompt, or in a direct record input supplied by an evaluation harness, to associate the following direct MCP records with that case. An outer `exec` result cannot prove each nested call, so marked nested calls and multi-marker evidence fail closed. Scoring validates schema-relevant inputs, transcript workspace roots, required order, expected output evidence, assertions, and successful per-call outputs. When the measured run used non-default file safety, pass the validated scorer options `--allow-any-path` and/or `--no-temp-directory`; the scorer does not infer layered project configuration from a transcript. Use `evals:score --strict` only for a complete marked matrix; transcript scoring is matched task-execution evidence, not a blanket agent-quality claim.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
[
|
|
2
2
|
{
|
|
3
3
|
"assertions": [
|
|
4
|
-
"Uses one
|
|
4
|
+
"Uses one declared files batch instead of one call per file.",
|
|
5
5
|
"Uses schema-valid content values keyed by file path.",
|
|
6
6
|
"Reports each created file for verification."
|
|
7
7
|
],
|
|
8
8
|
"category": "positive",
|
|
9
|
-
"expected_output": "Uses one
|
|
9
|
+
"expected_output": "Uses one file_write object with a declared files property whose path-keyed values contain content and reports every created file.",
|
|
10
10
|
"files": ["notes/one.txt", "notes/two.txt", "notes/three.txt"],
|
|
11
11
|
"forbidden_tools": ["file_patch"],
|
|
12
12
|
"id": 74,
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"Does not route either operation through file_patch."
|
|
23
23
|
],
|
|
24
24
|
"category": "variant",
|
|
25
|
-
"expected_output": "Uses one
|
|
25
|
+
"expected_output": "Uses one declared file_write.files batch and includes expectedSha256 only for the existing file.",
|
|
26
26
|
"files": [],
|
|
27
27
|
"forbidden_tools": ["file_patch"],
|
|
28
28
|
"id": 75,
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"Uses run only to preview or verify and sends the mutation through file_patch."
|
|
55
55
|
],
|
|
56
56
|
"category": "positive",
|
|
57
|
-
"expected_output": "Uses one
|
|
57
|
+
"expected_output": "Uses one file_patch object with a declared files property, ordered astRules arrays, and one expectedSha256 per file; run is used only for preview and verification.",
|
|
58
58
|
"files": [],
|
|
59
59
|
"forbidden_tools": ["file_write"],
|
|
60
60
|
"id": 77,
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"Preserves Aider ambiguity and atomic-commit safeguards."
|
|
71
71
|
],
|
|
72
72
|
"category": "variant",
|
|
73
|
-
"expected_output": "Uses one
|
|
73
|
+
"expected_output": "Uses one declared file_patch.files entry with patchStrategy aider_block and an ordered aiderBlocks array.",
|
|
74
74
|
"files": [],
|
|
75
75
|
"forbidden_tools": ["file_write"],
|
|
76
76
|
"id": 78,
|
|
@@ -99,10 +99,10 @@
|
|
|
99
99
|
"assertions": [
|
|
100
100
|
"Does not use run with write:true for a normal agent mutation.",
|
|
101
101
|
"Uses file_patch with patchStrategy ast for the reviewed edit.",
|
|
102
|
-
"Previews exact AST matches before the
|
|
102
|
+
"Previews exact AST matches before the declared file_patch.files mutation."
|
|
103
103
|
],
|
|
104
104
|
"category": "negative",
|
|
105
|
-
"expected_output": "Uses run only for preview or verification and routes the mutation through
|
|
105
|
+
"expected_output": "Uses run only for preview or verification and routes the mutation through declared file_patch.files entries with astRules.",
|
|
106
106
|
"files": [],
|
|
107
107
|
"forbidden_tools": ["file_write"],
|
|
108
108
|
"id": 81,
|
|
@@ -166,7 +166,7 @@
|
|
|
166
166
|
"Does not treat a preview result as a committed change."
|
|
167
167
|
],
|
|
168
168
|
"category": "variant",
|
|
169
|
-
"expected_output": "Uses the same
|
|
169
|
+
"expected_output": "Uses the same declared file_patch.files entry with preview true, a fresh hash, and the appropriate ordered astRules or aiderBlocks; it verifies the bounded diff and then sends the guarded mutation.",
|
|
170
170
|
"files": [],
|
|
171
171
|
"forbidden_tools": ["run"],
|
|
172
172
|
"id": 83,
|
|
@@ -273,7 +273,7 @@
|
|
|
273
273
|
},
|
|
274
274
|
{
|
|
275
275
|
"assertions": [
|
|
276
|
-
"Uses one
|
|
276
|
+
"Uses one declared file_rename.files batch.",
|
|
277
277
|
"Obtains a fresh source hash before renaming.",
|
|
278
278
|
"Reports each source and destination result."
|
|
279
279
|
],
|
|
@@ -1,18 +1,41 @@
|
|
|
1
1
|
import { scoreTranscript } from "./score";
|
|
2
2
|
|
|
3
3
|
const args = process.argv.slice(2);
|
|
4
|
-
const strict = args
|
|
5
|
-
const sessionPaths =
|
|
4
|
+
const strict = args.includes("--strict");
|
|
5
|
+
const sessionPaths = args.filter((argument) => !argument.startsWith("--"));
|
|
6
|
+
const knownOptions = new Set([
|
|
7
|
+
"--allow-any-path",
|
|
8
|
+
"--no-temp-directory",
|
|
9
|
+
"--strict",
|
|
10
|
+
]);
|
|
11
|
+
const requestedOptions = new Set(
|
|
12
|
+
args.filter((argument) => argument.startsWith("--")),
|
|
13
|
+
);
|
|
14
|
+
const unknownOption = [...requestedOptions].find(
|
|
15
|
+
(option) => !knownOptions.has(option),
|
|
16
|
+
);
|
|
17
|
+
if (unknownOption) {
|
|
18
|
+
console.error(`Unknown option: ${unknownOption}`);
|
|
19
|
+
process.exit(2);
|
|
20
|
+
}
|
|
21
|
+
const fileOperationPolicy = {
|
|
22
|
+
allowAnyPath: requestedOptions.has("--allow-any-path"),
|
|
23
|
+
allowTempDirectory: !requestedOptions.has("--no-temp-directory"),
|
|
24
|
+
};
|
|
6
25
|
|
|
7
26
|
if (sessionPaths.length === 0) {
|
|
8
27
|
console.error(
|
|
9
|
-
"Usage: bun run templates/skills/ast-mcp/evals/measure.ts <session.jsonl> [...session.jsonl]",
|
|
28
|
+
"Usage: bun run templates/skills/ast-mcp/evals/measure.ts [--strict] [--allow-any-path] [--no-temp-directory] <session.jsonl> [...session.jsonl]",
|
|
10
29
|
);
|
|
11
30
|
process.exit(2);
|
|
12
31
|
}
|
|
13
32
|
|
|
14
33
|
for (const sessionPath of sessionPaths) {
|
|
15
|
-
const result = await scoreTranscript(
|
|
34
|
+
const result = await scoreTranscript(
|
|
35
|
+
sessionPath,
|
|
36
|
+
strict,
|
|
37
|
+
fileOperationPolicy,
|
|
38
|
+
);
|
|
16
39
|
console.log(JSON.stringify(result));
|
|
17
40
|
if (!result.passed) process.exitCode = 1;
|
|
18
41
|
}
|
|
@@ -1,9 +1,52 @@
|
|
|
1
1
|
import { afterEach, expect, test } from "bun:test";
|
|
2
2
|
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
3
|
+
import os, { tmpdir } from "node:os";
|
|
4
|
+
import path, { join } from "node:path";
|
|
5
5
|
import { scoreTranscript } from "./score";
|
|
6
6
|
|
|
7
|
+
test("threads file-operation policy through transcript scoring", async () => {
|
|
8
|
+
const temporaryPath = path.join(os.tmpdir(), "ast-mcp-score-policy.ts");
|
|
9
|
+
const { sessionPath } = await transcript([
|
|
10
|
+
record("turn_context", {
|
|
11
|
+
cwd: "/workspace",
|
|
12
|
+
workspace_roots: ["/workspace"],
|
|
13
|
+
}),
|
|
14
|
+
record("response_item", {
|
|
15
|
+
call_id: "policy-hash",
|
|
16
|
+
input: `// ast-mcp-eval:71\n${JSON.stringify({ filePaths: [temporaryPath] })}`,
|
|
17
|
+
name: "mcp__ast_mcp__file_hash",
|
|
18
|
+
type: "custom_tool_call",
|
|
19
|
+
}),
|
|
20
|
+
record("response_item", {
|
|
21
|
+
call_id: "policy-hash",
|
|
22
|
+
output: [
|
|
23
|
+
{
|
|
24
|
+
text: JSON.stringify({
|
|
25
|
+
filePath: temporaryPath,
|
|
26
|
+
sha256: "abc",
|
|
27
|
+
size: 1,
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
type: "custom_tool_call_output",
|
|
32
|
+
}),
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
const protectedScore = await scoreTranscript(sessionPath, false, {
|
|
36
|
+
allowTempDirectory: false,
|
|
37
|
+
});
|
|
38
|
+
expect(protectedScore.errors).toContain(
|
|
39
|
+
`eval 71 file_hash input escapes transcript file-operation roots: ${temporaryPath}`,
|
|
40
|
+
);
|
|
41
|
+
const unrestrictedScore = await scoreTranscript(sessionPath, false, {
|
|
42
|
+
allowAnyPath: true,
|
|
43
|
+
allowTempDirectory: false,
|
|
44
|
+
});
|
|
45
|
+
expect(unrestrictedScore.errors).not.toContain(
|
|
46
|
+
`eval 71 file_hash input escapes transcript file-operation roots: ${temporaryPath}`,
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
|
|
7
50
|
const directories: string[] = [];
|
|
8
51
|
|
|
9
52
|
afterEach(async () => {
|
|
@@ -78,7 +121,7 @@ test("binds direct calls to their marker and counts tool output", async () => {
|
|
|
78
121
|
});
|
|
79
122
|
|
|
80
123
|
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"}}));`;
|
|
124
|
+
const source = `// ast-mcp-eval:91\ntext(await tools.mcp__ast_mcp__file_rename({files:{"a.ts":{"expectedSha256":"abc","destination":"b.ts"}}}));`;
|
|
82
125
|
const { sessionPath } = await transcript([
|
|
83
126
|
record("response_item", {
|
|
84
127
|
call_id: "nested",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import {
|
|
4
|
+
type FileOperationPolicy,
|
|
4
5
|
type Invocation,
|
|
5
6
|
type EvalCase as SemanticEvalCase,
|
|
6
7
|
verifyEvaluation,
|
|
@@ -341,6 +342,7 @@ function evaluateCase(
|
|
|
341
342
|
calls: TranscriptCall[],
|
|
342
343
|
evaluation: EvalCase | undefined,
|
|
343
344
|
roots: string[],
|
|
345
|
+
fileOperationPolicy: FileOperationPolicy,
|
|
344
346
|
errors: string[],
|
|
345
347
|
) {
|
|
346
348
|
if (!evaluation) {
|
|
@@ -363,6 +365,7 @@ function evaluateCase(
|
|
|
363
365
|
evaluationInvocations(calls),
|
|
364
366
|
evaluationText(calls),
|
|
365
367
|
roots,
|
|
368
|
+
fileOperationPolicy,
|
|
366
369
|
);
|
|
367
370
|
for (const error of semanticErrors) errors.push(`eval ${evalId} ${error}`);
|
|
368
371
|
return !executionFailed && semanticErrors.length === 0
|
|
@@ -374,6 +377,7 @@ function evaluateGroups(
|
|
|
374
377
|
grouped: GroupedEvaluations,
|
|
375
378
|
cases: Map<number, EvalCase>,
|
|
376
379
|
roots: string[],
|
|
380
|
+
fileOperationPolicy: FileOperationPolicy,
|
|
377
381
|
errors: string[],
|
|
378
382
|
): EvaluationResult {
|
|
379
383
|
let evaluatedCases = 0;
|
|
@@ -385,6 +389,7 @@ function evaluateGroups(
|
|
|
385
389
|
calls,
|
|
386
390
|
cases.get(evalId),
|
|
387
391
|
roots,
|
|
392
|
+
fileOperationPolicy,
|
|
388
393
|
errors,
|
|
389
394
|
);
|
|
390
395
|
}
|
|
@@ -414,6 +419,7 @@ function validateStrictMatrix(
|
|
|
414
419
|
export async function scoreTranscript(
|
|
415
420
|
sessionPath: string,
|
|
416
421
|
strict = false,
|
|
422
|
+
fileOperationPolicy: FileOperationPolicy = {},
|
|
417
423
|
): Promise<TranscriptScore> {
|
|
418
424
|
const collector = await collectTranscript(sessionPath);
|
|
419
425
|
const toolCalls: Record<string, number> = {};
|
|
@@ -426,6 +432,7 @@ export async function scoreTranscript(
|
|
|
426
432
|
grouped,
|
|
427
433
|
cases,
|
|
428
434
|
[...collector.roots],
|
|
435
|
+
fileOperationPolicy,
|
|
429
436
|
collector.errors,
|
|
430
437
|
);
|
|
431
438
|
validateStrictMatrix(
|
|
@@ -1,6 +1,170 @@
|
|
|
1
1
|
import { expect, test } from "bun:test";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
2
4
|
import { verifyEvaluation } from "./semantic";
|
|
3
5
|
|
|
6
|
+
test("semantic evaluator scopes declared batches and file-operation paths", () => {
|
|
7
|
+
const evaluation = {
|
|
8
|
+
assertions: ["Uses declared files property."],
|
|
9
|
+
expected_output: "verification output",
|
|
10
|
+
files: [],
|
|
11
|
+
forbidden_tools: [],
|
|
12
|
+
id: 97,
|
|
13
|
+
required_tools: ["file_write"],
|
|
14
|
+
};
|
|
15
|
+
const legacy = verifyEvaluation(
|
|
16
|
+
evaluation,
|
|
17
|
+
[
|
|
18
|
+
{
|
|
19
|
+
index: 0,
|
|
20
|
+
input: '{ files: {}, "/outside.ts": { content: "legacy" } }',
|
|
21
|
+
tool: "file_write",
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
"verification output",
|
|
25
|
+
["/workspace"],
|
|
26
|
+
);
|
|
27
|
+
expect(legacy).toContain("file_write has empty or schema-incomplete input");
|
|
28
|
+
const nested = verifyEvaluation(
|
|
29
|
+
evaluation,
|
|
30
|
+
[
|
|
31
|
+
{
|
|
32
|
+
index: 0,
|
|
33
|
+
input:
|
|
34
|
+
'{ wrapper: { files: { "/outside.ts": { content: "nested" } } } }',
|
|
35
|
+
tool: "file_write",
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
"verification output",
|
|
39
|
+
["/workspace"],
|
|
40
|
+
);
|
|
41
|
+
expect(nested).toContain("file_write has empty or schema-incomplete input");
|
|
42
|
+
|
|
43
|
+
for (const [tool, input] of [
|
|
44
|
+
[
|
|
45
|
+
"file_patch",
|
|
46
|
+
JSON.stringify({
|
|
47
|
+
files: {
|
|
48
|
+
"/workspace/file.ts": {
|
|
49
|
+
astRules: [{ fix: "new", pattern: "old" }],
|
|
50
|
+
expectedSha256: "a".repeat(64),
|
|
51
|
+
patchStrategy: "ast",
|
|
52
|
+
preview: true,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
],
|
|
57
|
+
[
|
|
58
|
+
"file_delete",
|
|
59
|
+
JSON.stringify({
|
|
60
|
+
files: {
|
|
61
|
+
"/workspace/file.ts": {
|
|
62
|
+
expectedSha256: "a".repeat(64),
|
|
63
|
+
forceReferences: true,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
67
|
+
],
|
|
68
|
+
] as const) {
|
|
69
|
+
const ordered = verifyEvaluation(
|
|
70
|
+
{ ...evaluation, required_tools: [tool] },
|
|
71
|
+
[{ index: 0, input, tool }],
|
|
72
|
+
"verification output",
|
|
73
|
+
["/workspace"],
|
|
74
|
+
);
|
|
75
|
+
expect(ordered).not.toContain(
|
|
76
|
+
`${tool} has empty or schema-incomplete input`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const forceFirstBatch = `{"files":{"/outside-one.ts":{"forceReferences":true,"expectedSha256":"${"a".repeat(64)}"},"/outside-two.ts":{"forceReferences":true,"expectedSha256":"${"b".repeat(64)}"}}}`;
|
|
81
|
+
const batchErrors = verifyEvaluation(
|
|
82
|
+
{
|
|
83
|
+
...evaluation,
|
|
84
|
+
assertions: ["Uses one keyed batch."],
|
|
85
|
+
required_tools: ["file_delete"],
|
|
86
|
+
},
|
|
87
|
+
[{ index: 0, input: forceFirstBatch, tool: "file_delete" }],
|
|
88
|
+
"verification output",
|
|
89
|
+
["/workspace"],
|
|
90
|
+
);
|
|
91
|
+
expect(batchErrors).toContain(
|
|
92
|
+
"file_delete input escapes transcript file-operation roots: /outside-one.ts",
|
|
93
|
+
);
|
|
94
|
+
expect(batchErrors).toContain(
|
|
95
|
+
"file_delete input escapes transcript file-operation roots: /outside-two.ts",
|
|
96
|
+
);
|
|
97
|
+
expect(batchErrors).not.toContain(
|
|
98
|
+
"assertion not proven: Uses one keyed batch.",
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const previewFirstErrors = verifyEvaluation(
|
|
102
|
+
{ ...evaluation, required_tools: ["file_patch"] },
|
|
103
|
+
[
|
|
104
|
+
{
|
|
105
|
+
index: 0,
|
|
106
|
+
input: `{"files":{"/outside-preview.ts":{"preview":true,"expectedSha256":"${"a".repeat(64)}","patchStrategy":"ast","astRules":[{"pattern":"old","fix":"new"}]}}}`,
|
|
107
|
+
tool: "file_patch",
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
"verification output",
|
|
111
|
+
["/workspace"],
|
|
112
|
+
);
|
|
113
|
+
expect(previewFirstErrors).toContain(
|
|
114
|
+
"file_patch input escapes transcript file-operation roots: /outside-preview.ts",
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const temporaryPath = path.join(os.tmpdir(), "ast-mcp-eval.ts");
|
|
118
|
+
expect(
|
|
119
|
+
verifyEvaluation(
|
|
120
|
+
evaluation,
|
|
121
|
+
[
|
|
122
|
+
{
|
|
123
|
+
index: 0,
|
|
124
|
+
input: JSON.stringify({
|
|
125
|
+
files: { [temporaryPath]: { content: "temporary" } },
|
|
126
|
+
}),
|
|
127
|
+
tool: "file_write",
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
"verification output",
|
|
131
|
+
["/workspace"],
|
|
132
|
+
),
|
|
133
|
+
).toEqual([]);
|
|
134
|
+
expect(
|
|
135
|
+
verifyEvaluation(
|
|
136
|
+
evaluation,
|
|
137
|
+
[
|
|
138
|
+
{
|
|
139
|
+
index: 0,
|
|
140
|
+
input: JSON.stringify({
|
|
141
|
+
files: { "/etc/ast-mcp-eval.ts": { content: "unrestricted" } },
|
|
142
|
+
}),
|
|
143
|
+
tool: "file_write",
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
"verification output",
|
|
147
|
+
["/workspace"],
|
|
148
|
+
{ allowAnyPath: true },
|
|
149
|
+
),
|
|
150
|
+
).toEqual([]);
|
|
151
|
+
|
|
152
|
+
const astErrors = verifyEvaluation(
|
|
153
|
+
{
|
|
154
|
+
...evaluation,
|
|
155
|
+
assertions: [],
|
|
156
|
+
required_tools: ["map"],
|
|
157
|
+
},
|
|
158
|
+
[{ index: 0, input: '{ paths: ["/etc"] }', tool: "map" }],
|
|
159
|
+
"verification output",
|
|
160
|
+
["/workspace"],
|
|
161
|
+
{ allowAnyPath: true },
|
|
162
|
+
);
|
|
163
|
+
expect(astErrors).toContain(
|
|
164
|
+
"map input escapes transcript workspace roots: /etc",
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
|
|
4
168
|
const evaluation = {
|
|
5
169
|
assertions: ["Reports each source and destination result."],
|
|
6
170
|
expected_output: "reports each source and destination result",
|
|
@@ -17,7 +181,12 @@ test("rename evaluator accepts root-relative runtime results", () => {
|
|
|
17
181
|
{
|
|
18
182
|
index: 0,
|
|
19
183
|
input: JSON.stringify({
|
|
20
|
-
|
|
184
|
+
files: {
|
|
185
|
+
"source.txt": {
|
|
186
|
+
destination: "renamed.txt",
|
|
187
|
+
expectedSha256: "hash",
|
|
188
|
+
},
|
|
189
|
+
},
|
|
21
190
|
}),
|
|
22
191
|
tool: "file_rename",
|
|
23
192
|
},
|
|
@@ -42,13 +211,15 @@ test("rename evaluator rejects incomplete per-file results", () => {
|
|
|
42
211
|
{
|
|
43
212
|
index: 0,
|
|
44
213
|
input: JSON.stringify({
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
214
|
+
files: {
|
|
215
|
+
"/tmp/ast-mcp-root/one.txt": {
|
|
216
|
+
destination: "/tmp/ast-mcp-root/one-new.txt",
|
|
217
|
+
expectedSha256: "hash",
|
|
218
|
+
},
|
|
219
|
+
"/tmp/ast-mcp-root/two.txt": {
|
|
220
|
+
destination: "/tmp/ast-mcp-root/two-new.txt",
|
|
221
|
+
expectedSha256: "hash",
|
|
222
|
+
},
|
|
52
223
|
},
|
|
53
224
|
}),
|
|
54
225
|
tool: "file_rename",
|
|
@@ -121,7 +292,7 @@ test("semantic evaluator proves every supported assertion shape", () => {
|
|
|
121
292
|
),
|
|
122
293
|
).toEqual([]);
|
|
123
294
|
};
|
|
124
|
-
const patch = `{ "src/file.ts": { expectedSha256: "${"a".repeat(64)}", patchStrategy: "ast", astRules: [{ pattern: "old", fix: "next", expectedMatches: 1 }], preview: true } }`;
|
|
295
|
+
const patch = `{ files: { "src/file.ts": { expectedSha256: "${"a".repeat(64)}", patchStrategy: "ast", astRules: [{ pattern: "old", fix: "next", expectedMatches: 1 }], preview: true } } }`;
|
|
125
296
|
|
|
126
297
|
verify(
|
|
127
298
|
"Does not overwrite an existing destination.",
|
|
@@ -129,9 +300,11 @@ test("semantic evaluator proves every supported assertion shape", () => {
|
|
|
129
300
|
invocation(
|
|
130
301
|
"file_rename",
|
|
131
302
|
JSON.stringify({
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
303
|
+
files: {
|
|
304
|
+
"source.txt": {
|
|
305
|
+
destination: "destination.txt",
|
|
306
|
+
expectedSha256: "a".repeat(64),
|
|
307
|
+
},
|
|
135
308
|
},
|
|
136
309
|
}),
|
|
137
310
|
),
|
|
@@ -176,34 +349,42 @@ test("semantic evaluator proves every supported assertion shape", () => {
|
|
|
176
349
|
[
|
|
177
350
|
"file_write",
|
|
178
351
|
JSON.stringify({
|
|
179
|
-
|
|
180
|
-
|
|
352
|
+
files: {
|
|
353
|
+
"src/a.ts": { content: "a" },
|
|
354
|
+
"src/b.ts": { content: "b" },
|
|
355
|
+
},
|
|
181
356
|
}),
|
|
182
357
|
],
|
|
183
358
|
[
|
|
184
359
|
"file_chattr",
|
|
185
360
|
JSON.stringify({
|
|
186
|
-
|
|
187
|
-
|
|
361
|
+
files: {
|
|
362
|
+
"src/a.ts": { chattr: { chmod: 384 } },
|
|
363
|
+
"src/b.ts": { chattr: { chmod: 384 } },
|
|
364
|
+
},
|
|
188
365
|
}),
|
|
189
366
|
],
|
|
190
367
|
[
|
|
191
368
|
"file_delete",
|
|
192
369
|
JSON.stringify({
|
|
193
|
-
|
|
194
|
-
|
|
370
|
+
files: {
|
|
371
|
+
"src/a.ts": { expectedSha256: "a".repeat(64) },
|
|
372
|
+
"src/b.ts": { expectedSha256: "b".repeat(64) },
|
|
373
|
+
},
|
|
195
374
|
}),
|
|
196
375
|
],
|
|
197
376
|
[
|
|
198
377
|
"file_rename",
|
|
199
378
|
JSON.stringify({
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
379
|
+
files: {
|
|
380
|
+
"src/a.ts": {
|
|
381
|
+
destination: "src/a-new.ts",
|
|
382
|
+
expectedSha256: "a".repeat(64),
|
|
383
|
+
},
|
|
384
|
+
"src/b.ts": {
|
|
385
|
+
destination: "src/b-new.ts",
|
|
386
|
+
expectedSha256: "b".repeat(64),
|
|
387
|
+
},
|
|
207
388
|
},
|
|
208
389
|
}),
|
|
209
390
|
],
|
|
@@ -214,7 +395,7 @@ test("semantic evaluator proves every supported assertion shape", () => {
|
|
|
214
395
|
invocation("file_hash", '{ filePaths: ["src/a.ts"] }', 0),
|
|
215
396
|
invocation(
|
|
216
397
|
"file_write",
|
|
217
|
-
JSON.stringify({ "src/a.ts": { content: "next" } }),
|
|
398
|
+
JSON.stringify({ files: { "src/a.ts": { content: "next" } } }),
|
|
218
399
|
1,
|
|
219
400
|
),
|
|
220
401
|
]);
|
|
@@ -230,7 +411,7 @@ test("semantic evaluator proves every supported assertion shape", () => {
|
|
|
230
411
|
verify("Uses an Aider block.", [
|
|
231
412
|
invocation(
|
|
232
413
|
"file_patch",
|
|
233
|
-
`{ "README.md": { expectedSha256: "${"a".repeat(64)}", patchStrategy: "aider_block", aiderBlocks: [{ search: "old", replace: "new" }] } }`,
|
|
414
|
+
`{ files: { "README.md": { expectedSha256: "${"a".repeat(64)}", patchStrategy: "aider_block", aiderBlocks: [{ search: "old", replace: "new" }] } } }`,
|
|
234
415
|
),
|
|
235
416
|
]);
|
|
236
417
|
verify("Reports verification output.", []);
|
|
@@ -275,7 +456,7 @@ test("semantic evaluator reports every validation failure class", () => {
|
|
|
275
456
|
"file_hash has empty or schema-incomplete input",
|
|
276
457
|
"required tool sequence is concurrent and cannot be proven",
|
|
277
458
|
"required tool sequence is not satisfied at: file_write",
|
|
278
|
-
"file_write input escapes transcript
|
|
459
|
+
"file_write input escapes transcript file-operation roots: /etc/out.txt",
|
|
279
460
|
"output does not prove file result: required.txt",
|
|
280
461
|
"expected output not proven: expected transport behavior",
|
|
281
462
|
"assertion not proven: Uses bounded lines.",
|