@mwillbanks/ast-mcp 0.2.0 → 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 +76 -76
- package/dist/ast-mcp.js.map +13 -13
- 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/installer.ts +37 -17
- 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/service.ts +2 -4
- 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
- package/templates/skills/ast-mcp/scripts/check-install.ts +15 -25
package/src/tools/files.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { McpServer } from "@modelcontextprotocol/server";
|
|
2
2
|
import * as z from "zod/v4";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
boundedFileBatch,
|
|
5
|
+
chattrSchema,
|
|
6
|
+
toolFailure,
|
|
7
|
+
} from "../helpers/mcp-schema";
|
|
4
8
|
import { patchFiles, writeFilesSafely } from "../patch/engine";
|
|
5
9
|
import {
|
|
6
10
|
FILE_READ_MAX_BATCH,
|
|
@@ -39,15 +43,6 @@ export default function registerFileTools(
|
|
|
39
43
|
content: z.string(),
|
|
40
44
|
expectedSha256: z.string().length(64).optional(),
|
|
41
45
|
});
|
|
42
|
-
const boundedBatch = <T extends z.ZodType>(schema: T, label: string) =>
|
|
43
|
-
z
|
|
44
|
-
.record(z.string().min(1), schema)
|
|
45
|
-
.refine(
|
|
46
|
-
(value) =>
|
|
47
|
-
Object.keys(value).length > 0 &&
|
|
48
|
-
Object.keys(value).length <= FILE_READ_MAX_BATCH,
|
|
49
|
-
label,
|
|
50
|
-
);
|
|
51
46
|
|
|
52
47
|
server.registerTool(
|
|
53
48
|
"file_read",
|
|
@@ -109,20 +104,20 @@ export default function registerFileTools(
|
|
|
109
104
|
"file_write",
|
|
110
105
|
{
|
|
111
106
|
description:
|
|
112
|
-
"Creates or replaces multiple files in one
|
|
113
|
-
inputSchema:
|
|
107
|
+
"Creates or replaces multiple files in one declared files batch. Existing files require a fresh expectedSha256 by default; safety.require_hash=false makes it optional, but any supplied hash is still verified.",
|
|
108
|
+
inputSchema: boundedFileBatch(
|
|
114
109
|
writeTarget,
|
|
115
110
|
"file_write requires between 1 and 50 files",
|
|
116
111
|
),
|
|
117
112
|
title: "Write Files Safely",
|
|
118
113
|
},
|
|
119
|
-
async (
|
|
114
|
+
async ({ files }) => {
|
|
120
115
|
try {
|
|
121
116
|
return {
|
|
122
117
|
content: [
|
|
123
118
|
{
|
|
124
119
|
text: JSON.stringify(
|
|
125
|
-
await execute(
|
|
120
|
+
await execute({ files }, () => writeFilesSafely(files)),
|
|
126
121
|
),
|
|
127
122
|
type: "text",
|
|
128
123
|
},
|
|
@@ -138,8 +133,8 @@ export default function registerFileTools(
|
|
|
138
133
|
"file_patch",
|
|
139
134
|
{
|
|
140
135
|
description:
|
|
141
|
-
"Patches multiple files in one
|
|
142
|
-
inputSchema:
|
|
136
|
+
"Patches multiple files in one declared files batch. Each value contains a patchStrategy, ordered aiderBlocks or astRules, and optional preview mode. A fresh expectedSha256 is required by default; safety.require_hash=false makes it optional, but supplied hashes remain enforced. Preview runs the complete formatted operation without committing.",
|
|
137
|
+
inputSchema: boundedFileBatch(
|
|
143
138
|
z.object({
|
|
144
139
|
aiderBlocks: z.array(aiderBlock).max(FILE_READ_MAX_BATCH).optional(),
|
|
145
140
|
astRules: z.array(astRule).max(FILE_READ_MAX_BATCH).optional(),
|
|
@@ -152,12 +147,14 @@ export default function registerFileTools(
|
|
|
152
147
|
),
|
|
153
148
|
title: "Patch Files Through the Enforced State Machine",
|
|
154
149
|
},
|
|
155
|
-
async (
|
|
150
|
+
async ({ files }) => {
|
|
156
151
|
try {
|
|
157
152
|
return {
|
|
158
153
|
content: [
|
|
159
154
|
{
|
|
160
|
-
text: JSON.stringify(
|
|
155
|
+
text: JSON.stringify(
|
|
156
|
+
await execute({ files }, () => patchFiles(files)),
|
|
157
|
+
),
|
|
161
158
|
type: "text",
|
|
162
159
|
},
|
|
163
160
|
],
|
package/src/tools/lifecycle.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { McpServer } from "@modelcontextprotocol/server";
|
|
2
2
|
import * as z from "zod/v4";
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
boundedFileBatch,
|
|
5
5
|
chattrSchema,
|
|
6
6
|
toolFailure,
|
|
7
7
|
} from "../helpers/mcp-schema";
|
|
@@ -25,8 +25,8 @@ export default function registerLifecycleTools(
|
|
|
25
25
|
"file_chattr",
|
|
26
26
|
{
|
|
27
27
|
description:
|
|
28
|
-
"Applies the shared chattr contract to multiple
|
|
29
|
-
inputSchema:
|
|
28
|
+
"Applies the shared chattr contract to multiple files in one declared files batch under deterministic locks.",
|
|
29
|
+
inputSchema: boundedFileBatch(
|
|
30
30
|
z.object({
|
|
31
31
|
chattr,
|
|
32
32
|
expectedSha256: z.string().length(64).optional(),
|
|
@@ -35,9 +35,9 @@ export default function registerLifecycleTools(
|
|
|
35
35
|
),
|
|
36
36
|
title: "Change File Attributes Safely",
|
|
37
37
|
},
|
|
38
|
-
async (requests) => {
|
|
38
|
+
async ({ files: requests }) => {
|
|
39
39
|
try {
|
|
40
|
-
const entries = await execute(requests, () =>
|
|
40
|
+
const entries = await execute({ files: requests }, () =>
|
|
41
41
|
Promise.all(
|
|
42
42
|
Object.entries(requests).map(async ([inputPath, request]) => ({
|
|
43
43
|
filePath: await resolveWritablePath(inputPath),
|
|
@@ -77,8 +77,8 @@ export default function registerLifecycleTools(
|
|
|
77
77
|
"file_delete",
|
|
78
78
|
{
|
|
79
79
|
description:
|
|
80
|
-
"Deletes files in one
|
|
81
|
-
inputSchema:
|
|
80
|
+
"Deletes files in one declared files batch after reference preflight and removes empty ancestor directories. A fresh expectedSha256 is required by default; safety.require_hash=false makes it optional, but supplied hashes remain enforced.",
|
|
81
|
+
inputSchema: boundedFileBatch(
|
|
82
82
|
z.object({
|
|
83
83
|
expectedSha256: z.string().length(64).optional(),
|
|
84
84
|
forceReferences: z.boolean().optional(),
|
|
@@ -87,13 +87,13 @@ export default function registerLifecycleTools(
|
|
|
87
87
|
),
|
|
88
88
|
title: "Delete Files Safely",
|
|
89
89
|
},
|
|
90
|
-
async (
|
|
90
|
+
async ({ files }) => {
|
|
91
91
|
try {
|
|
92
92
|
return {
|
|
93
93
|
content: [
|
|
94
94
|
{
|
|
95
95
|
text: JSON.stringify(
|
|
96
|
-
await execute(
|
|
96
|
+
await execute({ files }, () => deleteFilesSafely(files)),
|
|
97
97
|
),
|
|
98
98
|
type: "text",
|
|
99
99
|
},
|
|
@@ -108,8 +108,8 @@ export default function registerLifecycleTools(
|
|
|
108
108
|
"file_rename",
|
|
109
109
|
{
|
|
110
110
|
description:
|
|
111
|
-
"Renames files in one
|
|
112
|
-
inputSchema:
|
|
111
|
+
"Renames files in one declared files batch without overwriting destinations. A fresh expectedSha256 is required by default; safety.require_hash=false makes it optional, but supplied hashes remain enforced.",
|
|
112
|
+
inputSchema: boundedFileBatch(
|
|
113
113
|
z.object({
|
|
114
114
|
destination: z.string().min(1),
|
|
115
115
|
expectedSha256: z.string().length(64).optional(),
|
|
@@ -118,13 +118,13 @@ export default function registerLifecycleTools(
|
|
|
118
118
|
),
|
|
119
119
|
title: "Rename Files Safely",
|
|
120
120
|
},
|
|
121
|
-
async (
|
|
121
|
+
async ({ files }) => {
|
|
122
122
|
try {
|
|
123
123
|
return {
|
|
124
124
|
content: [
|
|
125
125
|
{
|
|
126
126
|
text: JSON.stringify(
|
|
127
|
-
await execute(
|
|
127
|
+
await execute({ files }, () => renameFilesSafely(files)),
|
|
128
128
|
),
|
|
129
129
|
type: "text",
|
|
130
130
|
},
|
package/templates/AGENTS.md
CHANGED
|
@@ -9,7 +9,7 @@ CRITICAL INSTRUCTION: You are operating in an AST-isolated environment.
|
|
|
9
9
|
- Use `file_read` only for bounded slices of non-AST content, and batch multiple files in one call.
|
|
10
10
|
- Use `file_hash` for fresh whole-file SHA-256 values without retrieving content.
|
|
11
11
|
- For new files, use only `file_write`.
|
|
12
|
-
- For existing files, call `file_hash` immediately before a guarded `file_patch`;
|
|
12
|
+
- For existing files, call `file_hash` immediately before a guarded `file_patch`; mutation tools declare a `files` property containing the path-keyed batch.
|
|
13
13
|
- Parseable rewrite-supported files use `file_patch` with `patchStrategy: "ast"` and ordered `astRules`; unsupported, unparseable, or inspection-only formats use `patchStrategy: "aider_block"` and ordered `aiderBlocks`.
|
|
14
14
|
|
|
15
15
|
## Available ast-mcp tools
|
|
@@ -18,7 +18,7 @@ File boundary: `file_hash`, `file_read`, `file_write`, `file_patch`, `file_chatt
|
|
|
18
18
|
|
|
19
19
|
Code intelligence: `digest`, `map`, `show`, `search`, `find_related`, `surface`, `deps`, `reverse_deps`, `cycles`, `graph`, `callers`, `callees`, `trace`, `impact`, `context`, `implements`, `index`, `run`, `squeeze`.
|
|
20
20
|
|
|
21
|
-
Call every intelligence tool directly by name. There is no proxy tool. Use `run` for bounded AST searches and previews. Direct `run` rewrites with `write: true` are a lower-level escape hatch for intentionally bounded cases; they remain first-match-per-file and are not the normal agent patch route. All
|
|
21
|
+
Call every intelligence tool directly by name. There is no proxy tool. Use `run` for bounded AST searches and previews. Direct `run` rewrites with `write: true` are a lower-level escape hatch for intentionally bounded cases; they remain first-match-per-file and are not the normal agent patch route. All mutation tools accept a declared `files` object, are file-operation-root bounded, SHA-guarded where required, and atomically committed per keyed path. The OS temporary directory is allowed by default; `safety.allow_temp_directory = false` disables it, while `safety.allow_any_path = true` explicitly enables unrestricted file paths. `file_write` and `file_patch` share the `file_chattr` contract rather than independent chmod/chown keys; `file_delete` is the only directory cleanup capability and only removes empty ancestors after a successful file deletion.
|
|
22
22
|
|
|
23
23
|
## Forbidden mutation paths
|
|
24
24
|
|
|
@@ -35,11 +35,11 @@ Use ast-mcp intelligence tools as the primary repository search surface: `digest
|
|
|
35
35
|
1. Explore AST-capable content with the smallest direct intelligence call; use `impact` before shared API changes. Use batched, bounded `file_read` slices only for non-AST content.
|
|
36
36
|
2. Preview structural matches with `run({ pattern, paths, lang?, json: true })`, bounded to explicit paths. Use `file_patch` with `preview: true` when you need the full guarded and formatted dry-run contract.
|
|
37
37
|
3. Call `file_hash({ filePaths })` immediately before a SHA-guarded patch.
|
|
38
|
-
4. Call one
|
|
38
|
+
4. Call one `file_patch({ files: { ... } })` batch with one fresh hash and ordered operations per path:
|
|
39
39
|
- AST targets: `{ expectedSha256, patchStrategy: "ast", astRules: [...] }`
|
|
40
40
|
- Unsupported targets: `{ expectedSha256, patchStrategy: "aider_block", aiderBlocks: [...] }`
|
|
41
41
|
Each keyed path is locked and atomically committed once; preview every AST rule before the batch.
|
|
42
|
-
5. Use one
|
|
42
|
+
5. Use one `file_write({ files: { ... } })` batch for new files or SHA-guarded replacement of existing non-structurally-rewritable files.
|
|
43
43
|
6. Use direct `run` with `rewrite` and `write: true` only when an intentionally bounded lower-level rewrite is required; do not use it instead of `file_patch` for normal agent edits.
|
|
44
44
|
7. Verify keyed results with `show`, `map`, `run`, or bounded `file_read` slices, then run repository validation and review the final diff without mutating through Git.
|
|
45
45
|
|
|
@@ -49,7 +49,7 @@ A stale hash, ambiguous Aider block, unexpected match count, capped run preview,
|
|
|
49
49
|
|
|
50
50
|
A JSON-RPC transport batch may contain requests and notifications. Stdio emits one framed response per request; live streamable HTTP uses SSE by default and emits one event per request. Notifications never receive responses. Preserve every request ID and do not assume the live HTTP response is a JSON array unless `enableJsonResponse` is configured.
|
|
51
51
|
|
|
52
|
-
`evals:measure` inventories direct MCP 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 following direct MCP records with that case. Marked nested `exec` evidence and multi-marker evidence fail closed because an outer result cannot prove each nested call. Scoring requires schema-relevant inputs, workspace-root compliance from transcript context, required sequencing, expected output evidence, fixture assertions, and a successful output bound to each direct call.
|
|
52
|
+
`evals:measure` inventories direct MCP 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 following direct MCP records with that case. Marked nested `exec` evidence and multi-marker evidence fail closed because an outer result cannot prove each nested call. Scoring requires schema-relevant inputs, workspace-root compliance from transcript context, required sequencing, expected output evidence, fixture assertions, and a successful output bound to each direct call. Pass `--allow-any-path` and/or `--no-temp-directory` when the measured run used non-default file safety; scorer options are validated rather than inferred from layered project configuration.
|
|
53
53
|
|
|
54
54
|
## Missing MCP
|
|
55
55
|
|
|
@@ -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(
|