@mwillbanks/ast-mcp 0.2.1 → 0.3.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/CONTRIBUTING.md +13 -0
- package/README.md +18 -14
- package/dist/ast-mcp.js +183 -137
- package/dist/ast-mcp.js.map +58 -42
- package/package.json +17 -11
- package/src/ast-bro/capability.ts +20 -10
- package/src/ast-bro/tools.json +22 -2
- package/src/cli.ts +10 -7
- package/src/config-cli.ts +166 -19
- package/src/config-migrate.ts +223 -0
- package/src/config-registry.ts +321 -0
- package/src/config-schema-common.ts +81 -0
- package/src/config-v2-schema.ts +97 -0
- package/src/config.ts +375 -149
- package/src/helpers/ast-bro.ts +1 -7
- package/src/helpers/config.ts +12 -3
- package/src/helpers/installer.ts +8 -0
- package/src/helpers/mcp-schema.ts +105 -4
- package/src/host-smoke.ts +182 -0
- package/src/http.ts +8 -3
- package/src/installer-transport.ts +6 -4
- package/src/installer.ts +192 -51
- package/src/patch/engine.ts +555 -279
- package/src/patch/languages.ts +9 -0
- package/src/patch/strategy/aiderBlock.ts +110 -0
- package/src/patch/strategy/ast.ts +170 -0
- package/src/patch/strategy.ts +61 -0
- package/src/runtime/approval.ts +438 -0
- package/src/runtime/dependencies.ts +1 -1
- package/src/runtime/document-inspection.ts +78 -0
- package/src/runtime/file-capabilities.ts +250 -0
- package/src/runtime/file-delete.ts +122 -20
- package/src/runtime/file-read.ts +142 -14
- package/src/runtime/file-rename.ts +7 -6
- package/src/runtime/format.ts +65 -27
- package/src/runtime/path-policy.ts +557 -0
- package/src/runtime/path-utils.ts +40 -0
- package/src/runtime/paths.ts +204 -43
- package/src/server.ts +2 -1
- package/src/tools/ast-bro.ts +197 -76
- package/src/tools/configuration.ts +450 -0
- package/src/tools/configured.ts +49 -21
- package/src/tools/files.ts +177 -73
- package/src/tools/index.ts +2 -0
- package/src/tools/lifecycle.ts +89 -45
- package/templates/AGENTS.md +15 -17
- package/templates/skills/ast-mcp/SKILL.md +50 -34
- package/templates/skills/ast-mcp/evals/batch.evals.json +9 -9
- package/templates/skills/ast-mcp/evals/evals.json +221 -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 +87 -0
- package/templates/skills/ast-mcp/evals/semantic.test.ts +209 -28
- package/templates/skills/ast-mcp/evals/semantic.ts +151 -37
- package/templates/skills/ast-mcp/references/installation.md +12 -12
- package/templates/skills/ast-mcp/references/patch-state-machine.md +15 -14
- package/templates/skills/ast-mcp/references/tool-catalog.md +16 -10
- package/templates/skills/ast-mcp/scripts/check-install.ts +8 -17
- package/src/ast-bro/rewrite-capability.ts +0 -9
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { type FSWatcher, watch } from "node:fs";
|
|
2
|
+
import { stat } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import {
|
|
6
|
+
clearConfigCache,
|
|
7
|
+
globalConfigPath,
|
|
8
|
+
type ResolveConfigOptions,
|
|
9
|
+
type ResolvedConfig,
|
|
10
|
+
resolveConfig,
|
|
11
|
+
} from "./config";
|
|
12
|
+
import { setApprovalConfigInvalidator } from "./runtime/approval";
|
|
13
|
+
|
|
14
|
+
export interface ConfigSnapshot {
|
|
15
|
+
config?: Readonly<ResolvedConfig>;
|
|
16
|
+
error?: string;
|
|
17
|
+
fingerprints: Record<string, string>;
|
|
18
|
+
generation: number;
|
|
19
|
+
healthy: boolean;
|
|
20
|
+
key: string;
|
|
21
|
+
loadedAt: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface RegistryEntry {
|
|
25
|
+
options: ResolveConfigOptions;
|
|
26
|
+
promise?: Promise<Readonly<ConfigSnapshot>>;
|
|
27
|
+
reloadTimer?: ReturnType<typeof setTimeout>;
|
|
28
|
+
snapshot?: Readonly<ConfigSnapshot>;
|
|
29
|
+
watchers: FSWatcher[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function normalizedClientRoot(value: string): string {
|
|
33
|
+
return path.resolve(
|
|
34
|
+
value.startsWith("file:") ? fileURLToPath(new URL(value)) : value,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function within(root: string, target: string): boolean {
|
|
39
|
+
const relative = path.relative(root, target);
|
|
40
|
+
return (
|
|
41
|
+
relative === "" ||
|
|
42
|
+
(!relative.startsWith(`..${path.sep}`) &&
|
|
43
|
+
relative !== ".." &&
|
|
44
|
+
!path.isAbsolute(relative))
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function environmentFingerprint(environment: NodeJS.ProcessEnv) {
|
|
49
|
+
const fingerprint: Record<string, string> = {};
|
|
50
|
+
for (const name of [
|
|
51
|
+
"APPDATA",
|
|
52
|
+
"XDG_CONFIG_HOME",
|
|
53
|
+
"AST_MCP_PROJECT_ROOT",
|
|
54
|
+
"AST_MCP_ROOTS",
|
|
55
|
+
"AST_MCP_ALLOW_ANY_PATH",
|
|
56
|
+
"AST_MCP_ALLOW_EXTERNAL_ROOTS",
|
|
57
|
+
"AST_MCP_ALLOW_TEMP_DIRECTORY",
|
|
58
|
+
"AST_MCP_DPRINT_CONFIG",
|
|
59
|
+
"AST_BRO_BINARY",
|
|
60
|
+
"DPRINT_BINARY",
|
|
61
|
+
"AST_MCP_HTTP_HOST",
|
|
62
|
+
"PORT",
|
|
63
|
+
"AST_MCP_SESSION_TIMEOUT_MS",
|
|
64
|
+
"AST_MCP_SESSION_SWEEP_INTERVAL_MS",
|
|
65
|
+
]) {
|
|
66
|
+
const value = environment[name];
|
|
67
|
+
if (value !== undefined) fingerprint[name] = value;
|
|
68
|
+
}
|
|
69
|
+
return fingerprint;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function selectedRoots(
|
|
73
|
+
clientRoots: string[],
|
|
74
|
+
requestPaths: string[],
|
|
75
|
+
cwd: string,
|
|
76
|
+
): string[] {
|
|
77
|
+
const matched = clientRoots.filter((root) =>
|
|
78
|
+
requestPaths.some((requestPath) => within(root, requestPath)),
|
|
79
|
+
);
|
|
80
|
+
if (matched.length > 0) return matched;
|
|
81
|
+
return [clientRoots[0] ?? cwd];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function configuredSelectionRoots(
|
|
85
|
+
clientRoots: string[],
|
|
86
|
+
cwd: string,
|
|
87
|
+
env: NodeJS.ProcessEnv,
|
|
88
|
+
): string[] {
|
|
89
|
+
if (clientRoots.length) return clientRoots;
|
|
90
|
+
if (env.AST_MCP_PROJECT_ROOT)
|
|
91
|
+
return [path.resolve(cwd, env.AST_MCP_PROJECT_ROOT)];
|
|
92
|
+
return (env.AST_MCP_ROOTS?.split(path.delimiter).filter(Boolean) ?? []).map(
|
|
93
|
+
(root) => path.resolve(cwd, root),
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function keyFor(options: ResolveConfigOptions): string {
|
|
98
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
99
|
+
const env = options.env ?? process.env;
|
|
100
|
+
const clientRoots = (options.clientRoots ?? []).map(normalizedClientRoot);
|
|
101
|
+
const selectionRoots = configuredSelectionRoots(clientRoots, cwd, env);
|
|
102
|
+
const requestPaths = (options.requestPaths ?? [])
|
|
103
|
+
.filter((item) => path.isAbsolute(item))
|
|
104
|
+
.map((item) => path.resolve(item));
|
|
105
|
+
return JSON.stringify({
|
|
106
|
+
clientRoots,
|
|
107
|
+
cwd,
|
|
108
|
+
env: environmentFingerprint(env),
|
|
109
|
+
home: options.home,
|
|
110
|
+
platform: options.platform,
|
|
111
|
+
selectedRoots: selectedRoots(selectionRoots, requestPaths, cwd),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function fingerprint(filePath: string): Promise<string> {
|
|
116
|
+
const metadata = await stat(filePath).catch(() => undefined);
|
|
117
|
+
return metadata ? `${metadata.mtimeMs}:${metadata.size}` : "missing";
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function projectConfigCandidates(projectRoot: string): Promise<string[]> {
|
|
121
|
+
const candidates: string[] = [];
|
|
122
|
+
let current = path.resolve(projectRoot);
|
|
123
|
+
while (true) {
|
|
124
|
+
candidates.push(path.join(current, "ast-mcp.toml"));
|
|
125
|
+
const boundary = await stat(path.join(current, ".git")).then(
|
|
126
|
+
() => true,
|
|
127
|
+
() => false,
|
|
128
|
+
);
|
|
129
|
+
if (boundary) return candidates;
|
|
130
|
+
const parent = path.dirname(current);
|
|
131
|
+
if (parent === current) return candidates;
|
|
132
|
+
current = parent;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function fingerprints(
|
|
137
|
+
config: ResolvedConfig | undefined,
|
|
138
|
+
options: ResolveConfigOptions,
|
|
139
|
+
): Promise<Record<string, string>> {
|
|
140
|
+
const projectRoot = config?.projectRoot ?? options.cwd ?? process.cwd();
|
|
141
|
+
const sources = [
|
|
142
|
+
globalConfigPath(options),
|
|
143
|
+
...(await projectConfigCandidates(projectRoot)),
|
|
144
|
+
config?.sources.global,
|
|
145
|
+
config?.sources.project,
|
|
146
|
+
].filter(
|
|
147
|
+
(item, index, all): item is string =>
|
|
148
|
+
Boolean(item) && all.indexOf(item) === index,
|
|
149
|
+
);
|
|
150
|
+
return Object.fromEntries(
|
|
151
|
+
await Promise.all(
|
|
152
|
+
sources.map(async (source) => [source, await fingerprint(source)]),
|
|
153
|
+
),
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export class ConfigRegistry {
|
|
158
|
+
readonly #entries = new Map<string, RegistryEntry>();
|
|
159
|
+
readonly #reconcileTimer: ReturnType<typeof setInterval>;
|
|
160
|
+
constructor(
|
|
161
|
+
readonly debounceMs = 75,
|
|
162
|
+
readonly reconcileMs = 30_000,
|
|
163
|
+
readonly maxEntries = 128,
|
|
164
|
+
) {
|
|
165
|
+
this.#reconcileTimer = setInterval(
|
|
166
|
+
() => void this.reconcile(),
|
|
167
|
+
reconcileMs,
|
|
168
|
+
);
|
|
169
|
+
this.#reconcileTimer.unref?.();
|
|
170
|
+
}
|
|
171
|
+
async get(options: ResolveConfigOptions = {}): Promise<ResolvedConfig> {
|
|
172
|
+
const snapshot = await this.snapshot(options);
|
|
173
|
+
if (!snapshot.healthy || !snapshot.config)
|
|
174
|
+
throw new Error(
|
|
175
|
+
snapshot.error ??
|
|
176
|
+
"ast-mcp configuration is unavailable; run config_status",
|
|
177
|
+
);
|
|
178
|
+
return snapshot.config as ResolvedConfig;
|
|
179
|
+
}
|
|
180
|
+
#evictOldest(): void {
|
|
181
|
+
const oldestKey = this.#entries.keys().next().value;
|
|
182
|
+
if (oldestKey === undefined) return;
|
|
183
|
+
const oldest = this.#entries.get(oldestKey);
|
|
184
|
+
if (oldest?.reloadTimer) clearTimeout(oldest.reloadTimer);
|
|
185
|
+
for (const watcher of oldest?.watchers ?? []) watcher.close();
|
|
186
|
+
this.#entries.delete(oldestKey);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
#entry(key: string, options: ResolveConfigOptions): RegistryEntry {
|
|
190
|
+
const existing = this.#entries.get(key);
|
|
191
|
+
if (existing) {
|
|
192
|
+
this.#entries.delete(key);
|
|
193
|
+
this.#entries.set(key, existing);
|
|
194
|
+
return existing;
|
|
195
|
+
}
|
|
196
|
+
if (this.#entries.size >= this.maxEntries) this.#evictOldest();
|
|
197
|
+
const entry = { options: { ...options }, watchers: [] };
|
|
198
|
+
this.#entries.set(key, entry);
|
|
199
|
+
return entry;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
async snapshot(
|
|
203
|
+
options: ResolveConfigOptions = {},
|
|
204
|
+
): Promise<Readonly<ConfigSnapshot>> {
|
|
205
|
+
const key = keyFor(options);
|
|
206
|
+
const entry = this.#entry(key, options);
|
|
207
|
+
if (!entry.promise) entry.promise = this.#reload(key, entry);
|
|
208
|
+
return entry.promise;
|
|
209
|
+
}
|
|
210
|
+
invalidate(options: ResolveConfigOptions = {}): void {
|
|
211
|
+
const key = keyFor(options);
|
|
212
|
+
const entry = this.#entries.get(key);
|
|
213
|
+
if (Object.keys(options).length === 0) {
|
|
214
|
+
for (const [entryKey, entryValue] of this.#entries)
|
|
215
|
+
this.#queueReload(entryKey, entryValue);
|
|
216
|
+
} else if (entry) this.#schedule(key, entry);
|
|
217
|
+
}
|
|
218
|
+
async reconcile(): Promise<void> {
|
|
219
|
+
await Promise.all(
|
|
220
|
+
[...this.#entries.entries()].map(async ([key, entry]) => {
|
|
221
|
+
const snapshot = entry.snapshot;
|
|
222
|
+
if (!snapshot) return;
|
|
223
|
+
for (const [source, previous] of Object.entries(
|
|
224
|
+
snapshot.fingerprints,
|
|
225
|
+
)) {
|
|
226
|
+
if ((await fingerprint(source)) !== previous) {
|
|
227
|
+
this.#schedule(key, entry);
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}),
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
close(): void {
|
|
236
|
+
clearInterval(this.#reconcileTimer);
|
|
237
|
+
for (const entry of this.#entries.values()) {
|
|
238
|
+
if (entry.reloadTimer) clearTimeout(entry.reloadTimer);
|
|
239
|
+
for (const watcher of entry.watchers) watcher.close();
|
|
240
|
+
}
|
|
241
|
+
this.#entries.clear();
|
|
242
|
+
}
|
|
243
|
+
#queueReload(key: string, entry: RegistryEntry): void {
|
|
244
|
+
const previous = entry.promise;
|
|
245
|
+
const next = (
|
|
246
|
+
previous ? previous.catch(() => undefined) : Promise.resolve()
|
|
247
|
+
).then(() => this.#reload(key, entry));
|
|
248
|
+
entry.promise = next;
|
|
249
|
+
void next.catch(() => undefined);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
#schedule(key: string, entry: RegistryEntry): void {
|
|
253
|
+
if (entry.reloadTimer) clearTimeout(entry.reloadTimer);
|
|
254
|
+
entry.reloadTimer = setTimeout(() => {
|
|
255
|
+
this.#queueReload(key, entry);
|
|
256
|
+
}, this.debounceMs);
|
|
257
|
+
entry.reloadTimer.unref?.();
|
|
258
|
+
}
|
|
259
|
+
async #reload(
|
|
260
|
+
key: string,
|
|
261
|
+
entry: RegistryEntry,
|
|
262
|
+
): Promise<Readonly<ConfigSnapshot>> {
|
|
263
|
+
clearConfigCache();
|
|
264
|
+
const generation = (entry.snapshot?.generation ?? 0) + 1;
|
|
265
|
+
let snapshot: Readonly<ConfigSnapshot>;
|
|
266
|
+
try {
|
|
267
|
+
const resolved = await resolveConfig(entry.options);
|
|
268
|
+
const config = Object.freeze({ ...resolved, generation });
|
|
269
|
+
snapshot = Object.freeze({
|
|
270
|
+
config,
|
|
271
|
+
fingerprints: await fingerprints(resolved, entry.options),
|
|
272
|
+
generation,
|
|
273
|
+
healthy: true,
|
|
274
|
+
key,
|
|
275
|
+
loadedAt: new Date().toISOString(),
|
|
276
|
+
});
|
|
277
|
+
} catch (error) {
|
|
278
|
+
snapshot = Object.freeze({
|
|
279
|
+
config: entry.snapshot?.config,
|
|
280
|
+
error: error instanceof Error ? error.message : String(error),
|
|
281
|
+
fingerprints: await fingerprints(entry.snapshot?.config, entry.options),
|
|
282
|
+
generation,
|
|
283
|
+
healthy: false,
|
|
284
|
+
key,
|
|
285
|
+
loadedAt: new Date().toISOString(),
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
entry.snapshot = snapshot;
|
|
289
|
+
if (!entry.promise) entry.promise = Promise.resolve(snapshot);
|
|
290
|
+
if (this.#entries.get(key) === entry) this.#watch(key, entry, snapshot);
|
|
291
|
+
return snapshot;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
#watch(
|
|
295
|
+
key: string,
|
|
296
|
+
entry: RegistryEntry,
|
|
297
|
+
snapshot: Readonly<ConfigSnapshot>,
|
|
298
|
+
): void {
|
|
299
|
+
for (const watcher of entry.watchers) watcher.close();
|
|
300
|
+
entry.watchers = [];
|
|
301
|
+
const directories = new Set(
|
|
302
|
+
Object.keys(snapshot.fingerprints).map((source) => path.dirname(source)),
|
|
303
|
+
);
|
|
304
|
+
for (const directory of directories) {
|
|
305
|
+
try {
|
|
306
|
+
const watcher = watch(directory, (_event, filename) => {
|
|
307
|
+
if (this.#entries.get(key) !== entry) return;
|
|
308
|
+
if (!filename || filename.toString() === "ast-mcp.toml")
|
|
309
|
+
this.#schedule(key, entry);
|
|
310
|
+
});
|
|
311
|
+
watcher.unref?.();
|
|
312
|
+
entry.watchers.push(watcher);
|
|
313
|
+
} catch {
|
|
314
|
+
// Periodic fingerprint reconciliation remains authoritative.
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export const configRegistry = new ConfigRegistry();
|
|
321
|
+
setApprovalConfigInvalidator(() => configRegistry.invalidate());
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
const toolNameSchema = z
|
|
4
|
+
.string()
|
|
5
|
+
.min(1)
|
|
6
|
+
.max(200)
|
|
7
|
+
.regex(
|
|
8
|
+
/^[a-zA-Z0-9_.:-]+$/,
|
|
9
|
+
"tool names may contain letters, digits, _, ., :, and - only",
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export function createHookSchema(maxTools: number) {
|
|
13
|
+
return z
|
|
14
|
+
.object({
|
|
15
|
+
allow_tools: z.array(toolNameSchema).max(maxTools).optional(),
|
|
16
|
+
block_tools: z.array(toolNameSchema).max(maxTools).optional(),
|
|
17
|
+
enabled: z.boolean().optional(),
|
|
18
|
+
})
|
|
19
|
+
.strict()
|
|
20
|
+
.superRefine((value, context) => {
|
|
21
|
+
const allowed = new Set(
|
|
22
|
+
(value.allow_tools ?? []).map((tool) => tool.toLowerCase()),
|
|
23
|
+
);
|
|
24
|
+
for (const tool of value.block_tools ?? [])
|
|
25
|
+
if (allowed.has(tool.toLowerCase()))
|
|
26
|
+
context.addIssue({
|
|
27
|
+
code: "custom",
|
|
28
|
+
message: `hook tool "${tool}" cannot be both allowed and blocked`,
|
|
29
|
+
path: ["block_tools"],
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const positiveInteger = z.number().int().positive();
|
|
35
|
+
|
|
36
|
+
const formatterFields = {
|
|
37
|
+
args: z.array(z.string().max(4096)).max(64).optional(),
|
|
38
|
+
command: z.string().min(1).max(4096),
|
|
39
|
+
extensions: z
|
|
40
|
+
.array(z.string().regex(/^\.[^./\\]+$/, "extensions must begin with a dot"))
|
|
41
|
+
.max(64)
|
|
42
|
+
.optional(),
|
|
43
|
+
globs: z.array(z.string().min(1).max(4096)).max(64).optional(),
|
|
44
|
+
timeout_ms: positiveInteger.max(120_000).optional(),
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export function createFormatterSchema<T extends z.ZodRawShape>(extra: T) {
|
|
48
|
+
return z
|
|
49
|
+
.object({ ...formatterFields, ...extra })
|
|
50
|
+
.strict()
|
|
51
|
+
.refine((value) => {
|
|
52
|
+
const candidate = value as {
|
|
53
|
+
extensions?: string[];
|
|
54
|
+
globs?: string[];
|
|
55
|
+
};
|
|
56
|
+
return (
|
|
57
|
+
Boolean(candidate.extensions?.length) ||
|
|
58
|
+
Boolean(candidate.globs?.length)
|
|
59
|
+
);
|
|
60
|
+
}, "formatter requires at least one extension or glob");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const dependenciesSchema = z
|
|
64
|
+
.object({
|
|
65
|
+
ast_bro_binary: z.string().min(1).optional(),
|
|
66
|
+
dprint_binary: z.string().min(1).optional(),
|
|
67
|
+
})
|
|
68
|
+
.strict();
|
|
69
|
+
|
|
70
|
+
export const httpSchema = z
|
|
71
|
+
.object({
|
|
72
|
+
host: z.string().min(1).optional(),
|
|
73
|
+
port: z.number().int().min(1).max(65_535).optional(),
|
|
74
|
+
session_sweep_interval_ms: positiveInteger.optional(),
|
|
75
|
+
session_timeout_ms: positiveInteger.optional(),
|
|
76
|
+
})
|
|
77
|
+
.strict();
|
|
78
|
+
|
|
79
|
+
export const workspaceSchema = z
|
|
80
|
+
.object({ roots: z.array(z.string().min(1)).min(1).optional() })
|
|
81
|
+
.strict();
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
createFormatterSchema,
|
|
4
|
+
createHookSchema,
|
|
5
|
+
dependenciesSchema,
|
|
6
|
+
httpSchema,
|
|
7
|
+
workspaceSchema,
|
|
8
|
+
} from "./config-schema-common";
|
|
9
|
+
|
|
10
|
+
const schemaVersion = 2 as const;
|
|
11
|
+
const pathPolicy = z.enum(["allow", "request", "deny"]);
|
|
12
|
+
|
|
13
|
+
const formatterV2Schema = createFormatterSchema({
|
|
14
|
+
enabled: z.boolean().optional(),
|
|
15
|
+
id: z.string().min(1).max(128),
|
|
16
|
+
mode: z.enum(["stdout", "in_place"]).default("stdout"),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const pathRuleV2Schema = z
|
|
20
|
+
.object({
|
|
21
|
+
excludes: z.array(z.string().min(1).max(4096)).max(256).optional(),
|
|
22
|
+
follow_symlinks: z.boolean().optional(),
|
|
23
|
+
id: z.string().min(1).max(128),
|
|
24
|
+
includes: z.array(z.string().min(1).max(4096)).max(256).optional(),
|
|
25
|
+
path: z.string().min(1).max(4096),
|
|
26
|
+
policies: z
|
|
27
|
+
.object({
|
|
28
|
+
delete: pathPolicy.optional(),
|
|
29
|
+
read: pathPolicy,
|
|
30
|
+
write: pathPolicy,
|
|
31
|
+
})
|
|
32
|
+
.strict(),
|
|
33
|
+
})
|
|
34
|
+
.strict();
|
|
35
|
+
|
|
36
|
+
export const fileV2Schema = z
|
|
37
|
+
.object({
|
|
38
|
+
dependencies: dependenciesSchema.optional(),
|
|
39
|
+
files: z
|
|
40
|
+
.object({
|
|
41
|
+
patch: z
|
|
42
|
+
.object({
|
|
43
|
+
aider_matchers: z
|
|
44
|
+
.array(
|
|
45
|
+
z.enum([
|
|
46
|
+
"exact",
|
|
47
|
+
"whitespace",
|
|
48
|
+
"relative-indentation",
|
|
49
|
+
"diff-match-patch",
|
|
50
|
+
]),
|
|
51
|
+
)
|
|
52
|
+
.max(4)
|
|
53
|
+
.optional(),
|
|
54
|
+
strategies: z
|
|
55
|
+
.array(z.enum(["ast", "aider_block"]))
|
|
56
|
+
.max(2)
|
|
57
|
+
.optional(),
|
|
58
|
+
})
|
|
59
|
+
.strict()
|
|
60
|
+
.optional(),
|
|
61
|
+
read: z
|
|
62
|
+
.object({
|
|
63
|
+
modes: z
|
|
64
|
+
.array(z.enum(["ast", "text"]))
|
|
65
|
+
.max(2)
|
|
66
|
+
.optional(),
|
|
67
|
+
})
|
|
68
|
+
.strict()
|
|
69
|
+
.optional(),
|
|
70
|
+
})
|
|
71
|
+
.strict()
|
|
72
|
+
.optional(),
|
|
73
|
+
formatting: z
|
|
74
|
+
.object({
|
|
75
|
+
dprint_config: z.string().min(1).optional(),
|
|
76
|
+
enabled: z.boolean().optional(),
|
|
77
|
+
fallback: z.enum(["preserve", "dprint", "reject"]).optional(),
|
|
78
|
+
formatters: z.array(formatterV2Schema).max(64).optional(),
|
|
79
|
+
})
|
|
80
|
+
.strict()
|
|
81
|
+
.optional(),
|
|
82
|
+
http: httpSchema.optional(),
|
|
83
|
+
paths: z.array(pathRuleV2Schema).max(256).optional(),
|
|
84
|
+
safety: z
|
|
85
|
+
.object({
|
|
86
|
+
hook: createHookSchema(128).optional(),
|
|
87
|
+
require_hash: z.boolean().optional(),
|
|
88
|
+
})
|
|
89
|
+
.strict()
|
|
90
|
+
.optional(),
|
|
91
|
+
version: z.literal(schemaVersion),
|
|
92
|
+
workspace: workspaceSchema.optional(),
|
|
93
|
+
})
|
|
94
|
+
.strict();
|
|
95
|
+
|
|
96
|
+
export type PathPolicy = z.infer<typeof pathPolicy>;
|
|
97
|
+
export type PathRuleV2 = z.infer<typeof pathRuleV2Schema>;
|