@mwillbanks/ast-mcp 0.3.0 → 0.4.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/README.md +5 -5
- package/dist/ast-mcp.js +172 -156
- package/dist/ast-mcp.js.map +35 -31
- package/package.json +11 -11
- package/src/ast-bro/client.ts +12 -6
- package/src/ast-bro/result.ts +79 -0
- package/src/ast-bro/tools.json +7 -2
- package/src/config-edit.ts +236 -0
- package/src/config-migrate.ts +3 -20
- package/src/config-registry.ts +8 -0
- package/src/config-schema-common.ts +8 -1
- package/src/config-v2-schema.ts +12 -0
- package/src/config.ts +194 -39
- package/src/helpers/config.ts +9 -3
- package/src/installer.ts +61 -14
- package/src/patch/engine.ts +36 -17
- package/src/runtime/config-write.ts +327 -0
- package/src/runtime/dependencies.ts +14 -78
- package/src/runtime/file-read.ts +4 -13
- package/src/runtime/format.ts +27 -5
- package/src/runtime/git-worktrees.ts +179 -0
- package/src/runtime/path-policy.ts +131 -45
- package/src/runtime/path-utils.ts +40 -0
- package/src/runtime/paths.ts +29 -3
- package/src/tools/ast-bro.ts +106 -8
- package/src/tools/configuration.ts +218 -0
- package/src/tools/files.ts +1 -1
- package/templates/AGENTS.md +5 -1
- package/templates/skills/ast-mcp/SKILL.md +30 -1
- package/templates/skills/ast-mcp/evals/evals.json +98 -0
- package/templates/skills/ast-mcp/references/installation.md +2 -2
- package/templates/skills/ast-mcp/references/patch-state-machine.md +2 -2
- package/templates/skills/ast-mcp/references/tool-catalog.md +8 -4
- package/templates/skills/ast-mcp/scripts/binary-resolution.ts +112 -0
- package/templates/skills/ast-mcp/scripts/check-install.ts +162 -39
- package/templates/skills/ast-mcp/scripts/managed-hook.ts +34 -2
package/src/tools/ast-bro.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
astBroMatchFiles,
|
|
10
10
|
astBroRewrittenFiles,
|
|
11
11
|
parseAstBroJson,
|
|
12
|
+
parseAstBroShowV2,
|
|
12
13
|
} from "../ast-bro/result";
|
|
13
14
|
import metadata from "../ast-bro/tools.json";
|
|
14
15
|
import { currentConfig } from "../config";
|
|
@@ -22,9 +23,10 @@ import { inspectFileCapabilities } from "../runtime/file-capabilities";
|
|
|
22
23
|
import { assertFormattable, formatFileAtomically } from "../runtime/format";
|
|
23
24
|
import { withFileLocks } from "../runtime/locks";
|
|
24
25
|
import { assertReadableTree } from "../runtime/path-policy";
|
|
26
|
+
import { pathWithin } from "../runtime/path-utils";
|
|
25
27
|
import {
|
|
26
28
|
assertSingleProjectRoot,
|
|
27
|
-
|
|
29
|
+
intelligenceRoot,
|
|
28
30
|
resolveWorkspacePath,
|
|
29
31
|
resolveWritablePath,
|
|
30
32
|
} from "../runtime/paths";
|
|
@@ -63,6 +65,16 @@ async function boundedPath(
|
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
const pathArguments = ["file", "path", "root"] as const;
|
|
68
|
+
const globPattern = /[*?{}[\]]/;
|
|
69
|
+
|
|
70
|
+
async function existingLiteralPath(root: string, value: string) {
|
|
71
|
+
const resolved = await boundedPath(root, value);
|
|
72
|
+
const metadata = await lstat(resolved).catch((error) => {
|
|
73
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return undefined;
|
|
74
|
+
throw error;
|
|
75
|
+
});
|
|
76
|
+
return metadata !== undefined;
|
|
77
|
+
}
|
|
66
78
|
|
|
67
79
|
async function validateReadableScanPath(
|
|
68
80
|
root: string,
|
|
@@ -75,10 +87,76 @@ async function validateReadableScanPath(
|
|
|
75
87
|
return resolved;
|
|
76
88
|
}
|
|
77
89
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
)
|
|
90
|
+
function globBase(root: string, value: string) {
|
|
91
|
+
const globIndex = value.search(globPattern);
|
|
92
|
+
const prefix = value.slice(0, globIndex);
|
|
93
|
+
const separator = Math.max(prefix.lastIndexOf("/"), prefix.lastIndexOf("\\"));
|
|
94
|
+
const base = separator < 0 ? "." : prefix.slice(0, separator + 1);
|
|
95
|
+
return path.isAbsolute(value) ? base : path.resolve(root, base);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function scanGlob(root: string, value: string) {
|
|
99
|
+
const relativePattern = path.isAbsolute(value)
|
|
100
|
+
? path.relative(root, value)
|
|
101
|
+
: value;
|
|
102
|
+
const pattern = relativePattern.split(path.sep).join("/");
|
|
103
|
+
return [
|
|
104
|
+
...new Bun.Glob(pattern).scanSync({
|
|
105
|
+
absolute: true,
|
|
106
|
+
cwd: root,
|
|
107
|
+
dot: true,
|
|
108
|
+
followSymlinks: false,
|
|
109
|
+
onlyFiles: false,
|
|
110
|
+
}),
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function resolveGlobPaths(root: string, value: string) {
|
|
115
|
+
const base = await validateReadableScanPath(root, globBase(root, value));
|
|
116
|
+
if (!pathWithin(root, base))
|
|
117
|
+
throw new Error(`Glob path is outside configured workspace root: ${value}`);
|
|
118
|
+
const matches = scanGlob(root, value);
|
|
119
|
+
const resolved = await Promise.all(
|
|
120
|
+
matches.map((match) => validateReadableScanPath(root, match)),
|
|
121
|
+
);
|
|
122
|
+
return resolved.length > 0 ? resolved : [base];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function emptyShowResult(args: Record<string, unknown>, root: string) {
|
|
126
|
+
const target = args.path;
|
|
127
|
+
if (
|
|
128
|
+
typeof target !== "string" ||
|
|
129
|
+
!globPattern.test(target) ||
|
|
130
|
+
(await existingLiteralPath(root, target)) ||
|
|
131
|
+
scanGlob(root, target).length > 0
|
|
132
|
+
)
|
|
133
|
+
return undefined;
|
|
134
|
+
const symbols = Array.isArray(args.symbols)
|
|
135
|
+
? args.symbols.filter(
|
|
136
|
+
(symbol): symbol is string => typeof symbol === "string",
|
|
137
|
+
)
|
|
138
|
+
: [];
|
|
139
|
+
return {
|
|
140
|
+
content: [
|
|
141
|
+
{
|
|
142
|
+
text: JSON.stringify({
|
|
143
|
+
files: [],
|
|
144
|
+
files_matched: 0,
|
|
145
|
+
files_scanned: 0,
|
|
146
|
+
schema: "ast-bro.show.v2",
|
|
147
|
+
shown: 0,
|
|
148
|
+
symbols,
|
|
149
|
+
total: 0,
|
|
150
|
+
truncated: false,
|
|
151
|
+
unmatched: symbols,
|
|
152
|
+
}),
|
|
153
|
+
type: "text" as const,
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function astBroRequestPaths(args: Record<string, unknown>): string[] {
|
|
82
160
|
const candidates: string[] = [];
|
|
83
161
|
for (const name of pathArguments) {
|
|
84
162
|
const value = args[name];
|
|
@@ -90,10 +168,23 @@ async function resolveAstBroPaths(
|
|
|
90
168
|
(value): value is string => typeof value === "string",
|
|
91
169
|
),
|
|
92
170
|
);
|
|
171
|
+
return candidates;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function resolveAstBroPaths(
|
|
175
|
+
args: Record<string, unknown>,
|
|
176
|
+
root: string,
|
|
177
|
+
): Promise<string[]> {
|
|
178
|
+
const candidates = astBroRequestPaths(args);
|
|
93
179
|
if (candidates.length === 0) candidates.push(root);
|
|
94
|
-
|
|
95
|
-
candidates.map((value) =>
|
|
180
|
+
const resolved = await Promise.all(
|
|
181
|
+
candidates.map(async (value) => {
|
|
182
|
+
if (globPattern.test(value) && !(await existingLiteralPath(root, value)))
|
|
183
|
+
return resolveGlobPaths(root, value);
|
|
184
|
+
return [await validateReadableScanPath(root, value)];
|
|
185
|
+
}),
|
|
96
186
|
);
|
|
187
|
+
return resolved.flat();
|
|
97
188
|
}
|
|
98
189
|
|
|
99
190
|
async function validateRunPath(
|
|
@@ -279,8 +370,13 @@ export default function registerAstBroTools(
|
|
|
279
370
|
const result = await execute(
|
|
280
371
|
args,
|
|
281
372
|
async () => {
|
|
282
|
-
const root = await
|
|
373
|
+
const root = await intelligenceRoot(astBroRequestPaths(args));
|
|
283
374
|
await validateAstBroPaths(args, root, toolName);
|
|
375
|
+
const emptyShow =
|
|
376
|
+
toolName === "show" && args.json === true
|
|
377
|
+
? await emptyShowResult(args, root)
|
|
378
|
+
: undefined;
|
|
379
|
+
if (emptyShow) return emptyShow;
|
|
284
380
|
return toolName === "run"
|
|
285
381
|
? await callAstBroWithFormatting(args, root)
|
|
286
382
|
: await callAstBro(toolName, args, root);
|
|
@@ -289,6 +385,8 @@ export default function registerAstBroTools(
|
|
|
289
385
|
toolName,
|
|
290
386
|
);
|
|
291
387
|
|
|
388
|
+
if (toolName === "show" && args.json === true)
|
|
389
|
+
parseAstBroShowV2(result);
|
|
292
390
|
return structuredUpstreamToolResult(result, toolName);
|
|
293
391
|
} catch (error) {
|
|
294
392
|
return toolFailure(error);
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
toolOutputSchema,
|
|
11
11
|
toolSuccess,
|
|
12
12
|
} from "../helpers/mcp-schema";
|
|
13
|
+
import { applyConfigCore, applyConfigPaths } from "../runtime/config-write";
|
|
13
14
|
import {
|
|
14
15
|
parseStructuredDocument,
|
|
15
16
|
selectDocumentValue,
|
|
@@ -295,6 +296,7 @@ function statusPayload(
|
|
|
295
296
|
...base,
|
|
296
297
|
diagnostics,
|
|
297
298
|
formatting: formattingStatus(config),
|
|
299
|
+
mcp: config.mcp.configuration,
|
|
298
300
|
projectRoot: config.projectRoot,
|
|
299
301
|
provenance: config.provenance,
|
|
300
302
|
safety: config.safety,
|
|
@@ -447,4 +449,220 @@ export default function registerConfigurationTools(
|
|
|
447
449
|
}
|
|
448
450
|
},
|
|
449
451
|
);
|
|
452
|
+
|
|
453
|
+
const pathPolicy = z.enum(["allow", "deny", "request"]);
|
|
454
|
+
const configTarget = z.enum(["global", "project"]).optional();
|
|
455
|
+
const pathRulePatch = z
|
|
456
|
+
.object({
|
|
457
|
+
excludes: z.array(z.string().min(1)).max(256).optional(),
|
|
458
|
+
follow_symlinks: z.boolean().optional(),
|
|
459
|
+
includes: z.array(z.string().min(1)).max(256).optional(),
|
|
460
|
+
path: z.string().min(1).optional(),
|
|
461
|
+
policies: z
|
|
462
|
+
.object({
|
|
463
|
+
delete: pathPolicy.optional(),
|
|
464
|
+
read: pathPolicy.optional(),
|
|
465
|
+
write: pathPolicy.optional(),
|
|
466
|
+
})
|
|
467
|
+
.strict()
|
|
468
|
+
.optional(),
|
|
469
|
+
})
|
|
470
|
+
.strict();
|
|
471
|
+
|
|
472
|
+
server.registerTool(
|
|
473
|
+
"config_core",
|
|
474
|
+
{
|
|
475
|
+
annotations: {
|
|
476
|
+
destructiveHint: true,
|
|
477
|
+
idempotentHint: false,
|
|
478
|
+
openWorldHint: false,
|
|
479
|
+
readOnlyHint: false,
|
|
480
|
+
},
|
|
481
|
+
description:
|
|
482
|
+
"Updates grouped core ast-mcp.toml sections (workspace, safety, files, formatting, http, dependencies, mcp.configuration). Does not rewrite the whole file or change [[paths]]. Configuration changes require user approval by default.",
|
|
483
|
+
inputSchema: z
|
|
484
|
+
.object({
|
|
485
|
+
dependencies: z
|
|
486
|
+
.object({
|
|
487
|
+
ast_bro_binary: z.string().min(1).optional(),
|
|
488
|
+
dprint_binary: z.string().min(1).optional(),
|
|
489
|
+
})
|
|
490
|
+
.strict()
|
|
491
|
+
.optional(),
|
|
492
|
+
files: z
|
|
493
|
+
.object({
|
|
494
|
+
patch: z
|
|
495
|
+
.object({
|
|
496
|
+
aider_matchers: z
|
|
497
|
+
.array(
|
|
498
|
+
z.enum([
|
|
499
|
+
"exact",
|
|
500
|
+
"whitespace",
|
|
501
|
+
"relative-indentation",
|
|
502
|
+
"diff-match-patch",
|
|
503
|
+
]),
|
|
504
|
+
)
|
|
505
|
+
.max(4)
|
|
506
|
+
.optional(),
|
|
507
|
+
strategies: z
|
|
508
|
+
.array(z.enum(["ast", "aider_block"]))
|
|
509
|
+
.max(2)
|
|
510
|
+
.optional(),
|
|
511
|
+
})
|
|
512
|
+
.strict()
|
|
513
|
+
.optional(),
|
|
514
|
+
read: z
|
|
515
|
+
.object({
|
|
516
|
+
modes: z
|
|
517
|
+
.array(z.enum(["ast", "text"]))
|
|
518
|
+
.max(2)
|
|
519
|
+
.optional(),
|
|
520
|
+
})
|
|
521
|
+
.strict()
|
|
522
|
+
.optional(),
|
|
523
|
+
})
|
|
524
|
+
.strict()
|
|
525
|
+
.optional(),
|
|
526
|
+
formatting: z
|
|
527
|
+
.object({
|
|
528
|
+
dprint_config: z.string().min(1).optional(),
|
|
529
|
+
enabled: z.boolean().optional(),
|
|
530
|
+
fallback: z.enum(["preserve", "dprint", "reject"]).optional(),
|
|
531
|
+
})
|
|
532
|
+
.strict()
|
|
533
|
+
.optional(),
|
|
534
|
+
http: z
|
|
535
|
+
.object({
|
|
536
|
+
host: z.string().min(1).optional(),
|
|
537
|
+
port: z.number().int().min(1).max(65_535).optional(),
|
|
538
|
+
session_sweep_interval_ms: z.number().int().positive().optional(),
|
|
539
|
+
session_timeout_ms: z.number().int().positive().optional(),
|
|
540
|
+
})
|
|
541
|
+
.strict()
|
|
542
|
+
.optional(),
|
|
543
|
+
mcp: z
|
|
544
|
+
.object({
|
|
545
|
+
configuration: z
|
|
546
|
+
.object({
|
|
547
|
+
enabled: z.boolean().optional(),
|
|
548
|
+
require_approval: z.boolean().optional(),
|
|
549
|
+
})
|
|
550
|
+
.strict()
|
|
551
|
+
.optional(),
|
|
552
|
+
})
|
|
553
|
+
.strict()
|
|
554
|
+
.optional(),
|
|
555
|
+
safety: z
|
|
556
|
+
.object({
|
|
557
|
+
hook: z
|
|
558
|
+
.object({
|
|
559
|
+
allow_tools: z.array(z.string().min(1)).max(128).optional(),
|
|
560
|
+
block_tools: z.array(z.string().min(1)).max(128).optional(),
|
|
561
|
+
enabled: z.boolean().optional(),
|
|
562
|
+
})
|
|
563
|
+
.strict()
|
|
564
|
+
.optional(),
|
|
565
|
+
require_hash: z.boolean().optional(),
|
|
566
|
+
})
|
|
567
|
+
.strict()
|
|
568
|
+
.optional(),
|
|
569
|
+
target: configTarget,
|
|
570
|
+
workspace: z
|
|
571
|
+
.object({
|
|
572
|
+
roots: z.array(z.string().min(1)).min(1).optional(),
|
|
573
|
+
worktrees: z.enum(["include", "request", "ignore"]).optional(),
|
|
574
|
+
})
|
|
575
|
+
.strict()
|
|
576
|
+
.optional(),
|
|
577
|
+
})
|
|
578
|
+
.strict(),
|
|
579
|
+
outputSchema: toolOutputSchema,
|
|
580
|
+
title: "Update Core AST MCP Configuration",
|
|
581
|
+
},
|
|
582
|
+
async (args, context) => {
|
|
583
|
+
try {
|
|
584
|
+
return toolSuccess(
|
|
585
|
+
await execute(
|
|
586
|
+
args,
|
|
587
|
+
() => applyConfigCore(args),
|
|
588
|
+
context,
|
|
589
|
+
"config_core",
|
|
590
|
+
),
|
|
591
|
+
);
|
|
592
|
+
} catch (error) {
|
|
593
|
+
return toolFailure(error);
|
|
594
|
+
}
|
|
595
|
+
},
|
|
596
|
+
);
|
|
597
|
+
|
|
598
|
+
server.registerTool(
|
|
599
|
+
"config_paths",
|
|
600
|
+
{
|
|
601
|
+
annotations: {
|
|
602
|
+
destructiveHint: true,
|
|
603
|
+
idempotentHint: false,
|
|
604
|
+
openWorldHint: false,
|
|
605
|
+
readOnlyHint: false,
|
|
606
|
+
},
|
|
607
|
+
description:
|
|
608
|
+
"Adds, updates, or removes [[paths]] rules in ast-mcp.toml as a batch. Does not change core sections. Configuration changes require user approval by default.",
|
|
609
|
+
inputSchema: z
|
|
610
|
+
.object({
|
|
611
|
+
operations: z
|
|
612
|
+
.array(
|
|
613
|
+
z.union([
|
|
614
|
+
z
|
|
615
|
+
.object({
|
|
616
|
+
op: z.literal("add"),
|
|
617
|
+
rule: pathRulePatch.extend({
|
|
618
|
+
id: z.string().min(1).max(128),
|
|
619
|
+
path: z.string().min(1),
|
|
620
|
+
policies: z
|
|
621
|
+
.object({
|
|
622
|
+
delete: pathPolicy.optional(),
|
|
623
|
+
read: pathPolicy,
|
|
624
|
+
write: pathPolicy,
|
|
625
|
+
})
|
|
626
|
+
.strict(),
|
|
627
|
+
}),
|
|
628
|
+
})
|
|
629
|
+
.strict(),
|
|
630
|
+
z
|
|
631
|
+
.object({
|
|
632
|
+
id: z.string().min(1).max(128),
|
|
633
|
+
op: z.literal("update"),
|
|
634
|
+
rule: pathRulePatch,
|
|
635
|
+
})
|
|
636
|
+
.strict(),
|
|
637
|
+
z
|
|
638
|
+
.object({
|
|
639
|
+
id: z.string().min(1).max(128),
|
|
640
|
+
op: z.literal("remove"),
|
|
641
|
+
})
|
|
642
|
+
.strict(),
|
|
643
|
+
]),
|
|
644
|
+
)
|
|
645
|
+
.min(1)
|
|
646
|
+
.max(50),
|
|
647
|
+
target: configTarget,
|
|
648
|
+
})
|
|
649
|
+
.strict(),
|
|
650
|
+
outputSchema: toolOutputSchema,
|
|
651
|
+
title: "Update AST MCP Path Rules",
|
|
652
|
+
},
|
|
653
|
+
async (args, context) => {
|
|
654
|
+
try {
|
|
655
|
+
return toolSuccess(
|
|
656
|
+
await execute(
|
|
657
|
+
args,
|
|
658
|
+
() => applyConfigPaths(args),
|
|
659
|
+
context,
|
|
660
|
+
"config_paths",
|
|
661
|
+
),
|
|
662
|
+
);
|
|
663
|
+
} catch (error) {
|
|
664
|
+
return toolFailure(error);
|
|
665
|
+
}
|
|
666
|
+
},
|
|
667
|
+
);
|
|
450
668
|
}
|
package/src/tools/files.ts
CHANGED
|
@@ -215,7 +215,7 @@ export default function registerFileTools(
|
|
|
215
215
|
readOnlyHint: false,
|
|
216
216
|
},
|
|
217
217
|
description:
|
|
218
|
-
"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
|
|
218
|
+
"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 applies the strategy without formatting or committing; formatting runs only at commit, including previewReceipt commit.",
|
|
219
219
|
inputSchema: boundedFileBatch(
|
|
220
220
|
z
|
|
221
221
|
.object({
|
package/templates/AGENTS.md
CHANGED
|
@@ -16,6 +16,8 @@ CRITICAL INSTRUCTION: You are operating in an AST-isolated environment.
|
|
|
16
16
|
|
|
17
17
|
File boundary: `file_capabilities`, `file_hash`, `file_read`, `file_write`, `file_patch`, `file_chattr`, `file_delete`.
|
|
18
18
|
|
|
19
|
+
Configuration: `config_status`, `policy_check`, `document_query`, `config_core`, `config_paths`.
|
|
20
|
+
|
|
19
21
|
Code intelligence: `digest`, `map`, `show`, `search`, `find_related`, `surface`, `deps`, `reverse_deps`, `cycles`, `graph`, `callers`, `callees`, `trace`, `impact`, `context`, `implements`, `index`, `run`, `squeeze`.
|
|
20
22
|
|
|
21
23
|
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 preflight the complete batch before committing any entry. In version 2, access outside the host baseline—including the OS temporary directory—requires an explicit top-level `[[paths]]` rule; legacy `safety.allow_temp_directory` and `safety.allow_any_path` apply only to version 1 configuration. `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.
|
|
@@ -30,11 +32,13 @@ Shell commands are limited to read-only inspection that ast-mcp cannot provide a
|
|
|
30
32
|
|
|
31
33
|
Use ast-mcp intelligence tools as the primary repository search surface: `digest`, `map`, `show`, `search`, `find_related`, `callers`, `callees`, `trace`, `impact`, and bounded `run`. Do not invoke `ast-grep` directly; ast-mcp owns structural search and rewrites. `sed` is prohibited for repository reads and edits. `rg` is a fallback only for exact literals, identifiers, non-AST formats, or discovery that ast-mcp cannot provide; do not use it as the primary search route. External transcript/session analysis, Git metadata, repository-defined validation, and live runtime reproduction remain permitted exceptions.
|
|
32
34
|
|
|
35
|
+
Change `ast-mcp.toml` only through grouped `config_core` and batched `config_paths`. Never rewrite the whole file. Host approval is required by default; `[mcp.configuration]` changes always require approval. Successful writes reload the in-process snapshot immediately.
|
|
36
|
+
|
|
33
37
|
## Required write workflow
|
|
34
38
|
|
|
35
39
|
1. Explore with the smallest direct intelligence or `file_read` call; use `impact` before shared API changes and `file_capabilities` when method support is uncertain.
|
|
36
40
|
2. Select `file_read.mode` explicitly when intent matters. Select `file_patch.patchStrategy` per file: AST for structural edits, Aider for small exact text edits, subject to the reported effective capabilities.
|
|
37
|
-
3. Preview structural matches with `run({ pattern, paths, lang?, json: true })`, bounded to explicit paths. Use `file_patch` with `preview: true` for the full guarded
|
|
41
|
+
3. Preview structural matches with `run({ pattern, paths, lang?, json: true })`, bounded to explicit paths. Use `file_patch` with `preview: true` for the full guarded dry-run contract of either strategy. Preview does not format; commit, including `previewReceipt` commit, formats.
|
|
38
42
|
4. Call `file_hash({ filePaths })` immediately before a SHA-guarded patch.
|
|
39
43
|
5. Call one `file_patch({ files: { ... } })` batch with one fresh hash and matching ordered `astRules` or `aiderBlocks` per path. Each keyed path is locked and atomically committed once.
|
|
40
44
|
6. Use one `file_write({ files: { ... } })` batch for new files or permitted SHA-guarded whole-file replacement.
|
|
@@ -31,8 +31,10 @@ Read [tool-catalog.md](references/tool-catalog.md) for exact arguments and combi
|
|
|
31
31
|
- Batch paths, symbols, selectors, and keyed files into one call whenever the tool schema supports them. Prefer one bounded multi-target call over repeated single-target calls.
|
|
32
32
|
- Issue independent read-only calls in the same model turn or host executor, and return all parallel results together when the host protocol requires it.
|
|
33
33
|
- Keep each AST intelligence request within one project root. Split cross-root work into root-specific calls; independent read-only calls may run in parallel.
|
|
34
|
+
- Linked git worktrees of the config-bearing repository are authorized according to `workspace.worktrees` (`include` by default). Pass absolute paths into a worktree; if `PWD` is a linked worktree, relative paths resolve there. Do not treat a toml-less worktree as a different project root.
|
|
34
35
|
- Keep dependent and overlapping work sequential: inspect, preview, hash, then mutate. Never parallelize writes that can touch the same path, configuration generation, or dependency chain.
|
|
35
36
|
- Call `config_status` before the first mutation when formatter selection, path policy, configuration health, or generation is uncertain. Use `policy_check` to preflight read, write, and delete decisions without side effects.
|
|
37
|
+
- Change `ast-mcp.toml` only through grouped `config_core` and batched `config_paths`. Do not rewrite the whole file with `file_write` or `file_patch`. Host elicitation is required by default (`mcp.configuration.require_approval = true`). Changing `[mcp.configuration]` always requires approval, including disabling the surface. Successful writes invalidate the in-process registry so the new generation applies without restarting the MCP server.
|
|
36
38
|
- Use `document_query` for bounded JSON, JSONC, TOML, and YAML inspection instead of attempting whole-file reads of structured manifests.
|
|
37
39
|
|
|
38
40
|
## Mutate through declared file batches
|
|
@@ -40,7 +42,7 @@ Read [tool-catalog.md](references/tool-catalog.md) for exact arguments and combi
|
|
|
40
42
|
1. Inspect with `map`, `show`, `context`, a bounded `run`, or `file_read`. Call `file_capabilities` before choosing a read or patch method when intrinsic support or effective configuration is uncertain.
|
|
41
43
|
2. Select `file_read.mode` explicitly when intent matters. Use `ast` with `symbols` for source structure or with RFC 6901 `selectors` for structured documents; use `text` for a bounded exact slice. `auto` is suitable when AST-first behavior is desired.
|
|
42
44
|
3. Select `file_patch.patchStrategy` per file. Prefer `ast` for semantic, repeated, or structurally anchored changes; prefer `aider_block` for a small exact text replacement with unique context. Both remain selectable for parseable source whenever `file_capabilities` reports them, and configuration may narrow the effective choices.
|
|
43
|
-
4. 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 of either strategy, send the same `file_patch` file entry with `preview: true`.
|
|
45
|
+
4. 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 of either strategy, send the same `file_patch` file entry with `preview: true`. Preview returns the unformatted strategy candidate and does not run formatters; formatting occurs only at commit, including `previewReceipt` commit.
|
|
44
46
|
5. 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.
|
|
45
47
|
6. 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 with exactly one explicit strategy and its matching ordered operations. Each path runs under one lock; preview never commits and normal mode commits atomically.
|
|
46
48
|
7. Use one `file_write({ files: { ... } })` batch for new files or permitted SHA-guarded whole-file replacement. Supply the shared `chattr` object when chmod/chown metadata is required. The complete batch policy preflight finishes first; in-place formatter staging may transiently create, revalidate, and remove missing parents before the guarded commit recreates them, without writing the live target.
|
|
@@ -97,6 +99,33 @@ MCP transport requests may use a single JSON-RPC array containing requests and n
|
|
|
97
99
|
|
|
98
100
|
Read [patch-state-machine.md](references/patch-state-machine.md) for routing and rejection recovery.
|
|
99
101
|
|
|
102
|
+
## Update configuration through MCP
|
|
103
|
+
|
|
104
|
+
Use `config_core` for grouped core sections (`workspace`, `safety`, `files`, `formatting`, `http`, `dependencies`, `mcp.configuration`) and `config_paths` for batched `[[paths]]` add, update, or remove operations. Batch related keys in one group; do not send a whole-file rewrite or one call per individual key. `target` defaults to `project` and may be `global`. Version 1 files must be migrated first. When `mcp.configuration.enabled = false`, both tools fail closed.
|
|
105
|
+
|
|
106
|
+
```json
|
|
107
|
+
config_core({
|
|
108
|
+
"safety": { "require_hash": false },
|
|
109
|
+
"workspace": { "worktrees": "request" }
|
|
110
|
+
})
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
config_paths({
|
|
115
|
+
"operations": [
|
|
116
|
+
{
|
|
117
|
+
"op": "add",
|
|
118
|
+
"rule": {
|
|
119
|
+
"id": "docs",
|
|
120
|
+
"path": "./docs",
|
|
121
|
+
"policies": { "read": "allow", "write": "request" }
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
{ "op": "update", "id": "workspace", "rule": { "excludes": [".git/**"] } }
|
|
125
|
+
]
|
|
126
|
+
})
|
|
127
|
+
```
|
|
128
|
+
|
|
100
129
|
## Recover safely
|
|
101
130
|
|
|
102
131
|
- Stale SHA: refresh `file_hash`, re-inspect with the selected AST or text mode, and rebuild the patch.
|
|
@@ -1383,10 +1383,108 @@
|
|
|
1383
1383
|
"required_tools": ["file_hash"],
|
|
1384
1384
|
"surface": "file_read",
|
|
1385
1385
|
"variant": "hash-only-near-miss"
|
|
1386
|
+
},
|
|
1387
|
+
{
|
|
1388
|
+
"assertions": [
|
|
1389
|
+
"Uses config_core for a grouped core section instead of rewriting ast-mcp.toml.",
|
|
1390
|
+
"Does not call file_write or file_patch on the configuration file.",
|
|
1391
|
+
"Leaves [[paths]] unchanged."
|
|
1392
|
+
],
|
|
1393
|
+
"category": "positive",
|
|
1394
|
+
"expected_output": "Updates a core ast-mcp.toml section through config_core.",
|
|
1395
|
+
"files": [],
|
|
1396
|
+
"forbidden_tools": ["file_write", "file_patch"],
|
|
1397
|
+
"id": 184,
|
|
1398
|
+
"prompt": "Turn off require_hash in the project ast-mcp.toml without rewriting the whole file.",
|
|
1399
|
+
"required_tools": ["config_core"],
|
|
1400
|
+
"surface": "config_core",
|
|
1401
|
+
"variant": "primary"
|
|
1402
|
+
},
|
|
1403
|
+
{
|
|
1404
|
+
"assertions": [
|
|
1405
|
+
"Batches workspace and formatting keys in one config_core call.",
|
|
1406
|
+
"Does not send one call per individual key.",
|
|
1407
|
+
"Does not change [[paths]]."
|
|
1408
|
+
],
|
|
1409
|
+
"category": "variant",
|
|
1410
|
+
"expected_output": "Updates multiple core sections in one grouped config_core call.",
|
|
1411
|
+
"files": [],
|
|
1412
|
+
"forbidden_tools": ["config_paths"],
|
|
1413
|
+
"id": 185,
|
|
1414
|
+
"prompt": "Set workspace.worktrees to request and formatting.fallback to reject in one configuration change.",
|
|
1415
|
+
"required_tools": ["config_core"],
|
|
1416
|
+
"surface": "config_core",
|
|
1417
|
+
"variant": "grouped-sections"
|
|
1418
|
+
},
|
|
1419
|
+
{
|
|
1420
|
+
"assertions": [
|
|
1421
|
+
"Does not rewrite ast-mcp.toml through file_write.",
|
|
1422
|
+
"Selects config_core for a core section change.",
|
|
1423
|
+
"Avoids direct filesystem or shell mutation."
|
|
1424
|
+
],
|
|
1425
|
+
"category": "negative",
|
|
1426
|
+
"expected_output": "Does not route this near-miss to file_write; selects config_core.",
|
|
1427
|
+
"files": [],
|
|
1428
|
+
"forbidden_tools": ["file_write"],
|
|
1429
|
+
"id": 186,
|
|
1430
|
+
"prompt": "Replace the entire ast-mcp.toml contents to change only the HTTP port.",
|
|
1431
|
+
"required_tools": ["config_core"],
|
|
1432
|
+
"surface": "config_core",
|
|
1433
|
+
"variant": "whole-file-near-miss"
|
|
1434
|
+
},
|
|
1435
|
+
{
|
|
1436
|
+
"assertions": [
|
|
1437
|
+
"Uses config_paths to add a [[paths]] rule by id.",
|
|
1438
|
+
"Does not call config_core for path rules.",
|
|
1439
|
+
"Does not rewrite the whole configuration file."
|
|
1440
|
+
],
|
|
1441
|
+
"category": "positive",
|
|
1442
|
+
"expected_output": "Adds a path rule through config_paths.",
|
|
1443
|
+
"files": [],
|
|
1444
|
+
"forbidden_tools": ["config_core", "file_write"],
|
|
1445
|
+
"id": 187,
|
|
1446
|
+
"prompt": "Add a docs path rule that allows read and requests write.",
|
|
1447
|
+
"required_tools": ["config_paths"],
|
|
1448
|
+
"surface": "config_paths",
|
|
1449
|
+
"variant": "primary"
|
|
1450
|
+
},
|
|
1451
|
+
{
|
|
1452
|
+
"assertions": [
|
|
1453
|
+
"Batches add, update, and remove path operations in one config_paths call.",
|
|
1454
|
+
"Identifies existing rules by id.",
|
|
1455
|
+
"Does not change core sections."
|
|
1456
|
+
],
|
|
1457
|
+
"category": "variant",
|
|
1458
|
+
"expected_output": "Applies a batched config_paths operations list.",
|
|
1459
|
+
"files": [],
|
|
1460
|
+
"forbidden_tools": ["config_core"],
|
|
1461
|
+
"id": 188,
|
|
1462
|
+
"prompt": "In one call, add a vendor path rule, update the workspace rule excludes, and remove the unused temp rule.",
|
|
1463
|
+
"required_tools": ["config_paths"],
|
|
1464
|
+
"surface": "config_paths",
|
|
1465
|
+
"variant": "batched-operations"
|
|
1466
|
+
},
|
|
1467
|
+
{
|
|
1468
|
+
"assertions": [
|
|
1469
|
+
"Does not use config_core to change [[paths]].",
|
|
1470
|
+
"Selects config_paths for path rule mutation.",
|
|
1471
|
+
"Avoids a whole-file rewrite."
|
|
1472
|
+
],
|
|
1473
|
+
"category": "negative",
|
|
1474
|
+
"expected_output": "Does not route this near-miss to config_core; selects config_paths.",
|
|
1475
|
+
"files": [],
|
|
1476
|
+
"forbidden_tools": ["config_core"],
|
|
1477
|
+
"id": 189,
|
|
1478
|
+
"prompt": "Use config_core to add a new [[paths]] rule for ./vendor.",
|
|
1479
|
+
"required_tools": ["config_paths"],
|
|
1480
|
+
"surface": "config_paths",
|
|
1481
|
+
"variant": "core-near-miss"
|
|
1386
1482
|
}
|
|
1387
1483
|
],
|
|
1388
1484
|
"mcp_tools": [
|
|
1389
1485
|
"config_status",
|
|
1486
|
+
"config_core",
|
|
1487
|
+
"config_paths",
|
|
1390
1488
|
"document_query",
|
|
1391
1489
|
"file_capabilities",
|
|
1392
1490
|
"policy_check",
|
|
@@ -8,7 +8,7 @@ From the installed skill directory, run the read-only checker:
|
|
|
8
8
|
|
|
9
9
|
`bun run scripts/check-install.ts --scope local --target codex`
|
|
10
10
|
|
|
11
|
-
Replace `codex` with `claude` or `copilot`. Pass `--scope global` for a global installation. Pass the HTTP address and port for HTTP installations. The checker validates guidance, MCP definitions, hooks, skills, and
|
|
11
|
+
Replace `codex` with `claude` or `copilot`. Pass `--scope global` for a global installation. Pass the HTTP address and port for HTTP installations. The checker validates guidance, MCP definitions, hooks, skills, managed services, and exact ast-bro 4.2.0. It also detects stable package-manager aliases and duplicate handlers. It rejects package-internal or stale commands. It prints an exact install, update, or dependency-repair command.
|
|
12
12
|
|
|
13
13
|
## Install from this package checkout
|
|
14
14
|
|
|
@@ -46,7 +46,7 @@ npm install --global @mwillbanks/ast-mcp
|
|
|
46
46
|
|
|
47
47
|
Then run `ast-mcp install --scope global --target codex`. Use a project-local installation with Yarn 2+. Yarn 2+ does not provide the Yarn Classic global workflow. Bun blocks transitive lifecycle scripts by default. Trust `@ast-bro/cli` and `dprint` to run their pinned native installers. Approve those packages when another manager blocks dependency build scripts.
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
Local MCP, hook, service, and repair surfaces always use `./node_modules/.bin/ast-mcp`. Global surfaces use a discovered Bun, npm, pnpm, or Yarn global-bin alias and reject package-internal paths. The runtime checks package binaries, package metadata, global bins, and `PATH`. The installer uses the stable CLI and its `mcp` and `hook` subcommands. Run the local binary for local updates and removal. Run `ast-mcp update` or `ast-mcp uninstall` for global installations.
|
|
50
50
|
|
|
51
51
|
The pinned package provides a precompiled binary for macOS Apple Silicon. Install ast-bro with Cargo on Linux or macOS Intel. Set `AST_BRO_BINARY` to the installed path and persist the export. Use the Cargo executable path on Windows. Ensure GUI-launched hosts inherit the variable. The installer verifies the binary before changing host configuration. It returns setup commands when required.
|
|
52
52
|
|
|
@@ -7,7 +7,7 @@ The server distinguishes AST inspection from structural rewrite support. AST-cap
|
|
|
7
7
|
1. Call `file_capabilities` when the route is uncertain. It is the authoritative contract shared by `file_read`, `run`, and `file_patch`, and reports intrinsic support separately from configuration-filtered methods.
|
|
8
8
|
2. Choose `file_read.mode` explicitly when intent matters: `ast` returns a source map/requested symbols or RFC 6901-selected structured-document values, `text` returns a bounded slice, and `auto` prefers AST when available. Text remains selectable for AST-capable files.
|
|
9
9
|
3. Choose `file_patch.patchStrategy` per target. `ast` and `aider_block` are both valid for parseable source when reported by `file_capabilities`; prefer AST for semantic or repeated structural changes and Aider for a small, exact, uniquely anchored text replacement. Configuration may narrow either method but never silently changes the agent's selection.
|
|
10
|
-
4. Preview every ordered AST rule with `run`; for the full guarded
|
|
10
|
+
4. Preview every ordered AST rule with `run`; for the full guarded dry run, use the same keyed `file_patch` entry with `preview: true`. Preview does not format; commit, including `previewReceipt` commit, formats. Then obtain one fresh `file_hash` per keyed path immediately before mutation. Aider patches also support the guarded preview receipt workflow.
|
|
11
11
|
5. Use one `file_patch({ files: { ... } })` object for one or more files. Each path value declares exactly one `patchStrategy`, the corresponding ordered `astRules` or `aiderBlocks`, optional `preview`, and normally one fresh `expectedSha256`.
|
|
12
12
|
6. Use one `file_write({ files: { ... } })` object for new files or explicit whole-file replacement where permitted. Use the shared `chattr` object for chmod/chown metadata. The complete batch policy preflight finishes before filesystem preparation.
|
|
13
13
|
7. Use `file_rename`, `file_chattr`, and `file_delete` for their dedicated operations. Rename requires source `delete` and destination `write`; guarded mutations honor `safety.require_hash` and supplied hashes are always enforced.
|
|
@@ -22,7 +22,7 @@ MCP transport requests may contain a JSON-RPC array of requests and notification
|
|
|
22
22
|
- Use `$NODE` for one node and `$$NODES` for zero or more nodes.
|
|
23
23
|
- Preview with the same language, explicit paths, and optional glob.
|
|
24
24
|
- Inspect search matches, then use `file_patch` with `preview: true` for the full guarded diff; keep direct `run.write` for exceptional lower-level rewrites only.
|
|
25
|
-
- ast-bro 4.
|
|
25
|
+
- ast-bro 4.2.0 changes only the first match in each file; narrow ambiguous patterns rather than assuming replace-all behavior.
|
|
26
26
|
- Split declarations, calls, and type references into separate rules.
|
|
27
27
|
|
|
28
28
|
## Aider block discipline
|