@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/package.json
CHANGED
|
@@ -7,25 +7,25 @@
|
|
|
7
7
|
"url": "https://github.com/mwillbanks/ast-mcp/issues"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@ast-bro/cli": "4.
|
|
10
|
+
"@ast-bro/cli": "4.2.0",
|
|
11
11
|
"@modelcontextprotocol/client": "2.0.0",
|
|
12
12
|
"@modelcontextprotocol/server": "2.0.0",
|
|
13
13
|
"diff-match-patch-ts": "^2.0.0",
|
|
14
|
-
"dprint": "0.
|
|
15
|
-
"unbash": "^4.0.
|
|
14
|
+
"dprint": "0.56.1",
|
|
15
|
+
"unbash": "^4.0.10",
|
|
16
16
|
"zod": "^4.4.3"
|
|
17
17
|
},
|
|
18
18
|
"description": "Zero-trust MCP file writes, AST edits, ast-bro intelligence, hooks, and agent skills",
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@biomejs/biome": "^2.5.
|
|
21
|
-
"@modelcontextprotocol/inspector": "^2.
|
|
22
|
-
"@types/bun": "^1.
|
|
23
|
-
"@types/node": "^26.
|
|
24
|
-
"fallow": "^3.
|
|
20
|
+
"@biomejs/biome": "^2.5.10",
|
|
21
|
+
"@modelcontextprotocol/inspector": "^2.4.0",
|
|
22
|
+
"@types/bun": "^1.4.0",
|
|
23
|
+
"@types/node": "^26.3.0",
|
|
24
|
+
"fallow": "^3.19.0",
|
|
25
25
|
"typescript": "^7.0.2"
|
|
26
26
|
},
|
|
27
27
|
"engines": {
|
|
28
|
-
"bun": ">=1.
|
|
28
|
+
"bun": ">=1.4.0"
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
31
|
"dist",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
],
|
|
49
49
|
"license": "MIT",
|
|
50
50
|
"name": "@mwillbanks/ast-mcp",
|
|
51
|
-
"packageManager": "bun@1.
|
|
51
|
+
"packageManager": "bun@1.4.0",
|
|
52
52
|
"preferUnplugged": true,
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
"dprint"
|
|
93
93
|
],
|
|
94
94
|
"type": "module",
|
|
95
|
-
"version": "0.
|
|
95
|
+
"version": "0.4.0"
|
|
96
96
|
}
|
package/src/ast-bro/client.ts
CHANGED
|
@@ -2,7 +2,10 @@ import { Client } from "@modelcontextprotocol/client";
|
|
|
2
2
|
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
|
3
3
|
import { indexedAstBroCommand } from "../helpers/ast-bro";
|
|
4
4
|
import { captureProcess, successfulProcessOutput } from "../helpers/process";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
assertAstBroAvailable,
|
|
7
|
+
configuredAstBroBinary,
|
|
8
|
+
} from "../runtime/dependencies";
|
|
6
9
|
|
|
7
10
|
export { AST_BRO_BINARY } from "../runtime/dependencies";
|
|
8
11
|
export const AST_BRO_TOOLS = [
|
|
@@ -31,16 +34,19 @@ export async function callAstBro(
|
|
|
31
34
|
args: Record<string, unknown>,
|
|
32
35
|
root: string,
|
|
33
36
|
) {
|
|
37
|
+
const binary = await configuredAstBroBinary();
|
|
38
|
+
assertAstBroAvailable(binary);
|
|
34
39
|
if (
|
|
35
40
|
toolName === "search" ||
|
|
36
41
|
toolName === "find_related" ||
|
|
37
42
|
toolName === "index"
|
|
38
43
|
) {
|
|
39
44
|
const commandArgs = indexedAstBroCommand(toolName, args, root);
|
|
40
|
-
const processHandle = Bun.spawn(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
const processHandle = Bun.spawn([binary, ...commandArgs], {
|
|
46
|
+
cwd: root,
|
|
47
|
+
stderr: "pipe",
|
|
48
|
+
stdout: "pipe",
|
|
49
|
+
});
|
|
44
50
|
const result = await captureProcess(processHandle);
|
|
45
51
|
const stdout = successfulProcessOutput(`ast-bro ${commandArgs[0]}`, result);
|
|
46
52
|
return { content: [{ text: stdout, type: "text" as const }] };
|
|
@@ -48,7 +54,7 @@ export async function callAstBro(
|
|
|
48
54
|
const client = new Client({ name: "ast-mcp", version: "1.0.0" });
|
|
49
55
|
const transport = new StdioClientTransport({
|
|
50
56
|
args: ["mcp"],
|
|
51
|
-
command:
|
|
57
|
+
command: binary,
|
|
52
58
|
cwd: root,
|
|
53
59
|
});
|
|
54
60
|
try {
|
package/src/ast-bro/result.ts
CHANGED
|
@@ -11,6 +11,85 @@ export function parseAstBroJson(result: AstBroResult): AstBroJson {
|
|
|
11
11
|
return parseTextResultJson(result);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
export interface AstBroShowMatch {
|
|
15
|
+
end_line: number;
|
|
16
|
+
kind: string;
|
|
17
|
+
qualified_name: string;
|
|
18
|
+
source: string;
|
|
19
|
+
start_line: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface AstBroShowV2 {
|
|
23
|
+
files: Array<{
|
|
24
|
+
language: string;
|
|
25
|
+
matches: AstBroShowMatch[];
|
|
26
|
+
path: string;
|
|
27
|
+
}>;
|
|
28
|
+
files_matched: number;
|
|
29
|
+
files_scanned: number;
|
|
30
|
+
schema: "ast-bro.show.v2";
|
|
31
|
+
shown: number;
|
|
32
|
+
symbols: string[];
|
|
33
|
+
total: number;
|
|
34
|
+
truncated: boolean;
|
|
35
|
+
unmatched: string[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function nonnegativeInteger(value: unknown): value is number {
|
|
39
|
+
return Number.isInteger(value) && (value as number) >= 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function stringArray(value: unknown): value is string[] {
|
|
43
|
+
return (
|
|
44
|
+
Array.isArray(value) && value.every((item) => typeof item === "string")
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function showMatch(value: unknown): value is AstBroShowMatch {
|
|
49
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
50
|
+
const match = value as Record<string, unknown>;
|
|
51
|
+
return (
|
|
52
|
+
typeof match.qualified_name === "string" &&
|
|
53
|
+
typeof match.kind === "string" &&
|
|
54
|
+
nonnegativeInteger(match.start_line) &&
|
|
55
|
+
nonnegativeInteger(match.end_line) &&
|
|
56
|
+
match.end_line >= match.start_line &&
|
|
57
|
+
typeof match.source === "string"
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function parseAstBroShowV2(result: AstBroResult): AstBroShowV2 {
|
|
62
|
+
const payload = parseAstBroJson(result);
|
|
63
|
+
const files = payload.files;
|
|
64
|
+
const validFiles =
|
|
65
|
+
Array.isArray(files) &&
|
|
66
|
+
files.every(
|
|
67
|
+
(file) =>
|
|
68
|
+
file &&
|
|
69
|
+
typeof file === "object" &&
|
|
70
|
+
!Array.isArray(file) &&
|
|
71
|
+
typeof file.path === "string" &&
|
|
72
|
+
typeof file.language === "string" &&
|
|
73
|
+
Array.isArray(file.matches) &&
|
|
74
|
+
file.matches.every(showMatch),
|
|
75
|
+
);
|
|
76
|
+
if (
|
|
77
|
+
payload.schema !== "ast-bro.show.v2" ||
|
|
78
|
+
!stringArray(payload.symbols) ||
|
|
79
|
+
!stringArray(payload.unmatched) ||
|
|
80
|
+
!validFiles ||
|
|
81
|
+
!nonnegativeInteger(payload.files_scanned) ||
|
|
82
|
+
!nonnegativeInteger(payload.files_matched) ||
|
|
83
|
+
payload.files_matched > payload.files_scanned ||
|
|
84
|
+
!nonnegativeInteger(payload.total) ||
|
|
85
|
+
!nonnegativeInteger(payload.shown) ||
|
|
86
|
+
payload.shown > payload.total ||
|
|
87
|
+
typeof payload.truncated !== "boolean"
|
|
88
|
+
)
|
|
89
|
+
throw new Error("Invalid ast-bro.show.v2 response");
|
|
90
|
+
return payload as AstBroShowV2;
|
|
91
|
+
}
|
|
92
|
+
|
|
14
93
|
export function astBroMatchFiles(result: AstBroResult): string[] {
|
|
15
94
|
const payload = parseAstBroJson(result);
|
|
16
95
|
return [
|
package/src/ast-bro/tools.json
CHANGED
|
@@ -499,14 +499,19 @@
|
|
|
499
499
|
}
|
|
500
500
|
},
|
|
501
501
|
"show": {
|
|
502
|
-
"description": "Extract source of one or more symbols from a
|
|
502
|
+
"description": "Extract source of one or more symbols from a file, a directory, or a glob — pass a directory when you know the symbol but not the file. Suffix matching: `TakeDamage`, or `Player.TakeDamage` when ambiguous. For markdown the symbol is a heading or `frontmatter`. Returns text by default; set `json: true` for `ast-bro.show.v2`.",
|
|
503
503
|
"inputSchema": {
|
|
504
504
|
"properties": {
|
|
505
505
|
"json": {
|
|
506
506
|
"type": "boolean"
|
|
507
507
|
},
|
|
508
|
+
"limit": {
|
|
509
|
+
"description": "Cap on rendered bodies when the target is a directory or glob (default 20). The reported total is always exact.",
|
|
510
|
+
"minimum": 0,
|
|
511
|
+
"type": "integer"
|
|
512
|
+
},
|
|
508
513
|
"path": {
|
|
509
|
-
"description": "File to search.",
|
|
514
|
+
"description": "File, directory, or glob to search.",
|
|
510
515
|
"type": "string"
|
|
511
516
|
},
|
|
512
517
|
"symbols": {
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { lstat, readFile } from "node:fs/promises";
|
|
2
|
+
import { fileV2Schema } from "./config-v2-schema";
|
|
3
|
+
import { replaceFileAtomically } from "./runtime/atomic";
|
|
4
|
+
|
|
5
|
+
export type TomlValue =
|
|
6
|
+
| boolean
|
|
7
|
+
| number
|
|
8
|
+
| string
|
|
9
|
+
| TomlValue[]
|
|
10
|
+
| { [key: string]: TomlValue };
|
|
11
|
+
|
|
12
|
+
const pathIdPattern =
|
|
13
|
+
/(?:^|\n)[ \t]*id[ \t]*=[ \t]*("(?:[^"\\]|\\.)*"|'[^']*')/;
|
|
14
|
+
const policyPairPattern = () =>
|
|
15
|
+
/([A-Za-z_][A-Za-z0-9_]*)[ \t]*=[ \t]*("(?:[^"\\]|\\.)*"|'[^']*'|[A-Za-z0-9_-]+)/g;
|
|
16
|
+
|
|
17
|
+
function encodeTomlValue(value: TomlValue): string {
|
|
18
|
+
if (typeof value === "boolean" || typeof value === "number")
|
|
19
|
+
return String(value);
|
|
20
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
21
|
+
if (Array.isArray(value))
|
|
22
|
+
return `[${value.map((item) => encodeTomlValue(item)).join(", ")}]`;
|
|
23
|
+
const entries = Object.entries(value).map(
|
|
24
|
+
([key, item]) => `${key} = ${encodeTomlValue(item)}`,
|
|
25
|
+
);
|
|
26
|
+
return `{ ${entries.join(", ")} }`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function nextTableHeader(source: string, start: number): number {
|
|
30
|
+
const rest = source.slice(start);
|
|
31
|
+
const match = /\n\[/.exec(rest);
|
|
32
|
+
return match ? start + match.index + 1 : source.length;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function sectionRange(
|
|
36
|
+
source: string,
|
|
37
|
+
header: string,
|
|
38
|
+
): { bodyStart: number; end: number; start: number } | undefined {
|
|
39
|
+
const pattern = new RegExp(
|
|
40
|
+
`^[\\t ]*\\[${header.replaceAll(".", "\\.")}\\][\\t ]*(?:#.*)?$`,
|
|
41
|
+
"m",
|
|
42
|
+
);
|
|
43
|
+
const match = pattern.exec(source);
|
|
44
|
+
if (!match || match.index === undefined) return undefined;
|
|
45
|
+
const start = match.index;
|
|
46
|
+
const bodyStart = start + match[0].length;
|
|
47
|
+
return { bodyStart, end: nextTableHeader(source, bodyStart), start };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function ensureSection(source: string, header: string): string {
|
|
51
|
+
if (sectionRange(source, header)) return source;
|
|
52
|
+
return `${source.trimEnd()}\n\n[${header}]\n`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function replaceKeyInRange(
|
|
56
|
+
source: string,
|
|
57
|
+
rangeStart: number,
|
|
58
|
+
rangeEnd: number,
|
|
59
|
+
key: string,
|
|
60
|
+
encoded: string,
|
|
61
|
+
): string {
|
|
62
|
+
const body = source.slice(rangeStart, rangeEnd);
|
|
63
|
+
const keyPattern = new RegExp(`^[\\t ]*${key}[\\t ]*=.*$`, "m");
|
|
64
|
+
if (keyPattern.test(body)) {
|
|
65
|
+
const updated = body.replace(keyPattern, `${key} = ${encoded}`);
|
|
66
|
+
return `${source.slice(0, rangeStart)}${updated}${source.slice(rangeEnd)}`;
|
|
67
|
+
}
|
|
68
|
+
const insertion = body.endsWith("\n")
|
|
69
|
+
? `${body}${key} = ${encoded}\n`
|
|
70
|
+
: `${body}\n${key} = ${encoded}\n`;
|
|
71
|
+
return `${source.slice(0, rangeStart)}${insertion}${source.slice(rangeEnd)}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function setTomlSectionKey(
|
|
75
|
+
source: string,
|
|
76
|
+
header: string,
|
|
77
|
+
key: string,
|
|
78
|
+
value: TomlValue,
|
|
79
|
+
): string {
|
|
80
|
+
const withSection = ensureSection(source, header);
|
|
81
|
+
const range = sectionRange(withSection, header);
|
|
82
|
+
if (!range) return withSection;
|
|
83
|
+
return replaceKeyInRange(
|
|
84
|
+
withSection,
|
|
85
|
+
range.bodyStart,
|
|
86
|
+
range.end,
|
|
87
|
+
key,
|
|
88
|
+
encodeTomlValue(value),
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function pathBlocks(source: string): Array<{
|
|
93
|
+
end: number;
|
|
94
|
+
id?: string;
|
|
95
|
+
start: number;
|
|
96
|
+
}> {
|
|
97
|
+
const matches = [...source.matchAll(/^[ \t]*\[\[paths\]\][ \t]*(?:#.*)?$/gm)];
|
|
98
|
+
return matches.map((match, index) => {
|
|
99
|
+
const start = match.index ?? 0;
|
|
100
|
+
const nextStart = matches[index + 1]?.index;
|
|
101
|
+
const following = nextTableHeader(source, start + match[0].length);
|
|
102
|
+
const end =
|
|
103
|
+
nextStart === undefined ? following : Math.min(nextStart, following);
|
|
104
|
+
const body = source.slice(start, end);
|
|
105
|
+
const idMatch = pathIdPattern.exec(body);
|
|
106
|
+
const raw = idMatch?.[1];
|
|
107
|
+
const id = raw
|
|
108
|
+
? raw.startsWith("'")
|
|
109
|
+
? raw.slice(1, -1)
|
|
110
|
+
: (JSON.parse(raw) as string)
|
|
111
|
+
: undefined;
|
|
112
|
+
return { end, id, start };
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function encodePathRule(rule: Record<string, TomlValue>): string {
|
|
117
|
+
const lines = ["[[paths]]"];
|
|
118
|
+
for (const key of [
|
|
119
|
+
"id",
|
|
120
|
+
"path",
|
|
121
|
+
"policies",
|
|
122
|
+
"follow_symlinks",
|
|
123
|
+
"includes",
|
|
124
|
+
"excludes",
|
|
125
|
+
]) {
|
|
126
|
+
const value = rule[key];
|
|
127
|
+
if (value !== undefined) lines.push(`${key} = ${encodeTomlValue(value)}`);
|
|
128
|
+
}
|
|
129
|
+
return `${lines.join("\n")}\n`;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function addPathTable(
|
|
133
|
+
source: string,
|
|
134
|
+
rule: Record<string, TomlValue>,
|
|
135
|
+
): string {
|
|
136
|
+
return `${source.trimEnd()}\n\n${encodePathRule(rule)}`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function requirePathBlock(source: string, id: string) {
|
|
140
|
+
const block = pathBlocks(source).find((item) => item.id === id);
|
|
141
|
+
if (!block)
|
|
142
|
+
throw Object.assign(new Error(`No [[paths]] rule with id ${id}`), {
|
|
143
|
+
code: "configuration_path_missing",
|
|
144
|
+
retryable: true,
|
|
145
|
+
});
|
|
146
|
+
return block;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function removePathTable(source: string, id: string): string {
|
|
150
|
+
const block = requirePathBlock(source, id);
|
|
151
|
+
return `${source.slice(0, block.start)}${source.slice(block.end)}`.replace(
|
|
152
|
+
/\n{3,}/g,
|
|
153
|
+
"\n\n",
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function updatePathTable(
|
|
158
|
+
source: string,
|
|
159
|
+
id: string,
|
|
160
|
+
patch: Record<string, TomlValue>,
|
|
161
|
+
): string {
|
|
162
|
+
const block = requirePathBlock(source, id);
|
|
163
|
+
let body = source.slice(block.start, block.end);
|
|
164
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
165
|
+
const keyPattern = new RegExp(`^[\\t ]*${key}[\\t ]*=.*$`, "m");
|
|
166
|
+
const line = `${key} = ${encodeTomlValue(value)}`;
|
|
167
|
+
body = keyPattern.test(body)
|
|
168
|
+
? body.replace(keyPattern, line)
|
|
169
|
+
: `${body.trimEnd()}\n${line}\n`;
|
|
170
|
+
}
|
|
171
|
+
return `${source.slice(0, block.start)}${body}${source.slice(block.end)}`;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function pathTableIds(source: string): string[] {
|
|
175
|
+
return pathBlocks(source)
|
|
176
|
+
.map((block) => block.id)
|
|
177
|
+
.filter((id): id is string => Boolean(id));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function existingPathPolicies(
|
|
181
|
+
source: string,
|
|
182
|
+
id: string,
|
|
183
|
+
): Record<string, string> {
|
|
184
|
+
const block = pathBlocks(source).find((item) => item.id === id);
|
|
185
|
+
if (!block) return {};
|
|
186
|
+
const body = source.slice(block.start, block.end);
|
|
187
|
+
const match = /(?:^|\n)[ \t]*policies[ \t]*=[ \t]*\{([^}]*)\}/.exec(body);
|
|
188
|
+
if (!match?.[1]) return {};
|
|
189
|
+
const policies: Record<string, string> = {};
|
|
190
|
+
for (const item of match[1].matchAll(policyPairPattern()))
|
|
191
|
+
policies[item[1] ?? ""] = item[2]?.startsWith('"')
|
|
192
|
+
? (JSON.parse(item[2]) as string)
|
|
193
|
+
: item[2]?.startsWith("'")
|
|
194
|
+
? item[2].slice(1, -1)
|
|
195
|
+
: (item[2] ?? "");
|
|
196
|
+
return policies;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function validateConfigSource(source: string, filePath: string): void {
|
|
200
|
+
let parsed: unknown;
|
|
201
|
+
try {
|
|
202
|
+
parsed = Bun.TOML.parse(source);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
throw Object.assign(
|
|
205
|
+
new Error(
|
|
206
|
+
`${filePath}: invalid TOML: ${error instanceof Error ? error.message : String(error)}`,
|
|
207
|
+
),
|
|
208
|
+
{ code: "configuration_invalid", retryable: true },
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
const result = fileV2Schema.safeParse(parsed);
|
|
212
|
+
if (!result.success)
|
|
213
|
+
throw Object.assign(
|
|
214
|
+
new Error(
|
|
215
|
+
`${filePath}: invalid configuration: ${result.error.issues
|
|
216
|
+
.map(
|
|
217
|
+
(issue) => `${issue.path.join(".") || "<root>"}: ${issue.message}`,
|
|
218
|
+
)
|
|
219
|
+
.join("; ")}`,
|
|
220
|
+
),
|
|
221
|
+
{ code: "configuration_invalid", retryable: true },
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export async function writeConfigSource(
|
|
226
|
+
filePath: string,
|
|
227
|
+
source: string,
|
|
228
|
+
): Promise<void> {
|
|
229
|
+
validateConfigSource(source, filePath);
|
|
230
|
+
const metadata = await lstat(filePath);
|
|
231
|
+
await replaceFileAtomically(filePath, source, metadata.mode);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export async function readConfigSource(filePath: string): Promise<string> {
|
|
235
|
+
return readFile(filePath, "utf8");
|
|
236
|
+
}
|
package/src/config-migrate.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
chmod,
|
|
4
|
-
copyFile,
|
|
5
|
-
lstat,
|
|
6
|
-
rename,
|
|
7
|
-
unlink,
|
|
8
|
-
writeFile,
|
|
9
|
-
} from "node:fs/promises";
|
|
1
|
+
import { copyFile, lstat } from "node:fs/promises";
|
|
10
2
|
import os from "node:os";
|
|
11
3
|
import path from "node:path";
|
|
12
4
|
import { fileV2Schema } from "./config-v2-schema";
|
|
5
|
+
import { replaceFileAtomically } from "./runtime/atomic";
|
|
13
6
|
|
|
14
7
|
export interface MigrationPreview {
|
|
15
8
|
changed: boolean;
|
|
@@ -208,16 +201,6 @@ export async function writeMigratedConfig(
|
|
|
208
201
|
const metadata = await lstat(filePath);
|
|
209
202
|
const backupPath = backup ? `${filePath}.v1.bak` : undefined;
|
|
210
203
|
if (backupPath) await copyFile(filePath, backupPath);
|
|
211
|
-
|
|
212
|
-
path.dirname(filePath),
|
|
213
|
-
`.${path.basename(filePath)}.migrate-${randomUUID()}`,
|
|
214
|
-
);
|
|
215
|
-
try {
|
|
216
|
-
await writeFile(temporary, source, { flag: "wx", mode: metadata.mode });
|
|
217
|
-
await chmod(temporary, metadata.mode);
|
|
218
|
-
await rename(temporary, filePath);
|
|
219
|
-
} finally {
|
|
220
|
-
await unlink(temporary).catch(() => undefined);
|
|
221
|
-
}
|
|
204
|
+
await replaceFileAtomically(filePath, source, metadata.mode);
|
|
222
205
|
return backupPath;
|
|
223
206
|
}
|
package/src/config-registry.ts
CHANGED
|
@@ -215,6 +215,14 @@ export class ConfigRegistry {
|
|
|
215
215
|
this.#queueReload(entryKey, entryValue);
|
|
216
216
|
} else if (entry) this.#schedule(key, entry);
|
|
217
217
|
}
|
|
218
|
+
async reload(): Promise<Array<Readonly<ConfigSnapshot>>> {
|
|
219
|
+
this.invalidate();
|
|
220
|
+
return Promise.all(
|
|
221
|
+
[...this.#entries.values()].flatMap((entry) =>
|
|
222
|
+
entry.promise ? [entry.promise] : [],
|
|
223
|
+
),
|
|
224
|
+
);
|
|
225
|
+
}
|
|
218
226
|
async reconcile(): Promise<void> {
|
|
219
227
|
await Promise.all(
|
|
220
228
|
[...this.#entries.entries()].map(async ([key, entry]) => {
|
|
@@ -76,6 +76,13 @@ export const httpSchema = z
|
|
|
76
76
|
})
|
|
77
77
|
.strict();
|
|
78
78
|
|
|
79
|
+
const worktreesModeSchema = z.enum(["include", "request", "ignore"]);
|
|
80
|
+
|
|
79
81
|
export const workspaceSchema = z
|
|
80
|
-
.object({
|
|
82
|
+
.object({
|
|
83
|
+
roots: z.array(z.string().min(1)).min(1).optional(),
|
|
84
|
+
worktrees: worktreesModeSchema.optional(),
|
|
85
|
+
})
|
|
81
86
|
.strict();
|
|
87
|
+
|
|
88
|
+
export type WorktreesMode = z.infer<typeof worktreesModeSchema>;
|
package/src/config-v2-schema.ts
CHANGED
|
@@ -80,6 +80,18 @@ export const fileV2Schema = z
|
|
|
80
80
|
.strict()
|
|
81
81
|
.optional(),
|
|
82
82
|
http: httpSchema.optional(),
|
|
83
|
+
mcp: z
|
|
84
|
+
.object({
|
|
85
|
+
configuration: z
|
|
86
|
+
.object({
|
|
87
|
+
enabled: z.boolean().optional(),
|
|
88
|
+
require_approval: z.boolean().optional(),
|
|
89
|
+
})
|
|
90
|
+
.strict()
|
|
91
|
+
.optional(),
|
|
92
|
+
})
|
|
93
|
+
.strict()
|
|
94
|
+
.optional(),
|
|
83
95
|
paths: z.array(pathRuleV2Schema).max(256).optional(),
|
|
84
96
|
safety: z
|
|
85
97
|
.object({
|