@mwillbanks/ast-mcp 0.6.5 → 0.7.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 +6 -0
- package/dist/ast-mcp.js +358 -337
- package/dist/ast-mcp.js.map +45 -32
- package/dist/workers/sql-postgres-worker.js +5 -0
- package/dist/workers/sql-postgres-worker.js.map +10 -0
- package/package.json +3 -2
- package/src/cli/doctor.ts +103 -0
- package/src/cli/index.ts +9 -1
- package/src/config/index.ts +61 -6
- package/src/config/registry.ts +209 -67
- package/src/config/v2-schema.ts +2 -0
- package/src/helpers/installer.ts +10 -1
- package/src/http/index.ts +12 -5
- package/src/installer/codex.ts +237 -0
- package/src/installer/diagnostics.ts +387 -0
- package/src/installer/directory-ancestry.ts +55 -0
- package/src/installer/index.ts +386 -119
- package/src/installer/ownership.ts +165 -0
- package/src/installer/service-state.ts +151 -0
- package/src/installer/service.ts +131 -7
- package/src/installer/transaction.ts +342 -0
- package/src/installer/transport.ts +22 -31
- package/src/intelligence/mutation/locks.ts +4 -1
- package/src/patch/engine.ts +157 -11
- package/src/runtime/approval.ts +427 -66
- package/src/runtime/config-write.ts +27 -1
- package/src/runtime/diagnostics.ts +115 -0
- package/src/runtime/file-capabilities.ts +2 -0
- package/src/runtime/hosts/codex.ts +16 -0
- package/src/runtime/path-policy.ts +2 -0
- package/src/runtime/release.ts +220 -0
- package/src/runtime/sql-assistance.ts +439 -0
- package/src/runtime/sql-options-schema.ts +31 -0
- package/src/runtime/sql-postgres-worker.ts +72 -0
- package/src/runtime/sql-postgres.ts +245 -0
- package/src/server/index.ts +35 -5
- package/src/server/lifecycle.ts +1 -1
- package/src/tools/configuration.ts +2 -0
- package/src/tools/diagnostics.ts +85 -0
- package/src/tools/files.ts +2 -0
- package/src/tools/index.ts +9 -0
- package/templates/skills/ast-mcp/SKILL.md +20 -1
- package/templates/skills/ast-mcp/evals/evals.json +274 -0
- package/templates/skills/ast-mcp/evals/semantic.ts +2 -0
- package/templates/skills/ast-mcp/evals/trigger-queries.json +4 -1
- package/templates/skills/ast-mcp/references/cli.md +97 -0
- package/templates/skills/ast-mcp/references/configuration.md +11 -3
- package/templates/skills/ast-mcp/references/diagnostics.md +106 -0
- package/templates/skills/ast-mcp/references/host-context.md +85 -0
- package/templates/skills/ast-mcp/references/installation.md +37 -0
- package/templates/skills/ast-mcp/references/issue-reporting.md +80 -0
- package/templates/skills/ast-mcp/references/patch-state-machine.md +10 -0
- package/templates/skills/ast-mcp/references/tool-catalog.md +120 -50
- package/templates/skills/ast-mcp/scripts/check-install.ts +223 -24
- package/templates/skills/ast-mcp/scripts/release.ts +220 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{parentPort as r}from"worker_threads";import{hasSqlDetails as l,parse as f}from"libpg-query";function a(t){return typeof t==="object"&&t!==null?t:void 0}function p(t){let e=a(t);return(Array.isArray(e?.stmts)?e.stmts:[]).some((o)=>{let n=a(a(o)?.stmt);return!n||n.DoStmt!==void 0||n.CreateFunctionStmt!==void 0})}function d(t,e){if(!l(e))return;let s=e.sqlDetails?.cursorPosition;if(!Number.isSafeInteger(s)||s<0)return;let o=0,n=0;for(let u of t){if(o++>=s)break;n+=u.length}let i=t.slice(0,n),c=i.split(`
|
|
3
|
+
`);return[{message:"SQL syntax rejected by the selected validator",line:c.length-1,column:Array.from(c.at(-1)??"").length,offset:Buffer.byteLength(i)}]}r?.once("message",async(t)=>{let e;try{let s=await f(t.source);e=p(s)?{status:"unsupported",complete:!1,scope:"sql"}:{status:"valid",complete:!0,scope:"sql"}}catch(s){e=l(s)?{status:"invalid",complete:!0,scope:"sql",diagnostics:d(t.source,s)}:{status:"unavailable",complete:!1,scope:"sql"}}r?.postMessage(e),r?.close()});
|
|
4
|
+
|
|
5
|
+
//# debugId=F02E5F6CFD88556C64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/runtime/sql-postgres-worker.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { parentPort } from \"node:worker_threads\";\n\nimport { hasSqlDetails, parse } from \"libpg-query\";\n\nimport type { SqlAdapterResult } from \"./sql-assistance\";\n\ntype ObjectValue = Record<string, unknown>;\nfunction object(value: unknown): ObjectValue | undefined {\n return typeof value === \"object\" && value !== null\n ? (value as ObjectValue)\n : undefined;\n}\n\nfunction hasUnsupportedBodies(value: unknown): boolean {\n const result = object(value);\n const statements = Array.isArray(result?.stmts) ? result.stmts : [];\n return statements.some((statement) => {\n const stmt = object(object(statement)?.stmt);\n return (\n !stmt ||\n stmt.DoStmt !== undefined ||\n stmt.CreateFunctionStmt !== undefined\n );\n });\n}\n\nfunction failureDiagnostic(\n source: string,\n error: unknown,\n): SqlAdapterResult[\"diagnostics\"] {\n if (!hasSqlDetails(error)) return undefined;\n const position = error.sqlDetails?.cursorPosition;\n if (!Number.isSafeInteger(position) || position! < 0) return undefined;\n // PostgreSQL reports zero-based Unicode character positions, not byte offsets.\n let characters = 0;\n let utf16Offset = 0;\n for (const character of source) {\n if (characters++ >= position!) break;\n utf16Offset += character.length;\n }\n const prefix = source.slice(0, utf16Offset);\n const lines = prefix.split(\"\\n\");\n return [\n {\n message: \"SQL syntax rejected by the selected validator\",\n line: lines.length - 1,\n column: Array.from(lines.at(-1) ?? \"\").length,\n offset: Buffer.byteLength(prefix),\n },\n ];\n}\n\nparentPort?.once(\"message\", async (request: { source: string }) => {\n let result: SqlAdapterResult;\n try {\n const parsed = await parse(request.source);\n result = hasUnsupportedBodies(parsed)\n ? { status: \"unsupported\", complete: false, scope: \"sql\" }\n : { status: \"valid\", complete: true, scope: \"sql\" };\n } catch (error) {\n result = hasSqlDetails(error)\n ? {\n status: \"invalid\",\n complete: true,\n scope: \"sql\",\n diagnostics: failureDiagnostic(request.source, error),\n }\n : { status: \"unavailable\", complete: false, scope: \"sql\" };\n }\n parentPort?.postMessage(result);\n parentPort?.close();\n});\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAAA,qBAAS,uBAET,wBAAS,WAAe,oBAKxB,SAAS,CAAM,CAAC,EAAyC,CACvD,OAAO,OAAO,IAAU,UAAY,IAAU,KACzC,EACD,OAGN,SAAS,CAAoB,CAAC,EAAyB,CACrD,IAAM,EAAS,EAAO,CAAK,EAE3B,OADmB,MAAM,QAAQ,GAAQ,KAAK,EAAI,EAAO,MAAQ,CAAC,GAChD,KAAK,CAAC,IAAc,CACpC,IAAM,EAAO,EAAO,EAAO,CAAS,GAAG,IAAI,EAC3C,MACE,CAAC,GACD,EAAK,SAAW,QAChB,EAAK,qBAAuB,OAE/B,EAGH,SAAS,CAAiB,CACxB,EACA,EACiC,CACjC,GAAI,CAAC,EAAc,CAAK,EAAG,OAC3B,IAAM,EAAW,EAAM,YAAY,eACnC,GAAI,CAAC,OAAO,cAAc,CAAQ,GAAK,EAAY,EAAG,OAEtD,IAAI,EAAa,EACb,EAAc,EAClB,QAAW,KAAa,EAAQ,CAC9B,GAAI,KAAgB,EAAW,MAC/B,GAAe,EAAU,OAE3B,IAAM,EAAS,EAAO,MAAM,EAAG,CAAW,EACpC,EAAQ,EAAO,MAAM;AAAA,CAAI,EAC/B,MAAO,CACL,CACE,QAAS,gDACT,KAAM,EAAM,OAAS,EACrB,OAAQ,MAAM,KAAK,EAAM,GAAG,EAAE,GAAK,EAAE,EAAE,OACvC,OAAQ,OAAO,WAAW,CAAM,CAClC,CACF,EAGF,GAAY,KAAK,UAAW,MAAO,IAAgC,CACjE,IAAI,EACJ,GAAI,CACF,IAAM,EAAS,MAAM,EAAM,EAAQ,MAAM,EACzC,EAAS,EAAqB,CAAM,EAChC,CAAE,OAAQ,cAAe,SAAU,GAAO,MAAO,KAAM,EACvD,CAAE,OAAQ,QAAS,SAAU,GAAM,MAAO,KAAM,EACpD,MAAO,EAAO,CACd,EAAS,EAAc,CAAK,EACxB,CACE,OAAQ,UACR,SAAU,GACV,MAAO,MACP,YAAa,EAAkB,EAAQ,OAAQ,CAAK,CACtD,EACA,CAAE,OAAQ,cAAe,SAAU,GAAO,MAAO,KAAM,EAE7D,GAAY,YAAY,CAAM,EAC9B,GAAY,MAAM,EACnB",
|
|
8
|
+
"debugId": "F02E5F6CFD88556C64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/package.json
CHANGED
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"@posthog/mcp": "0.23.0",
|
|
35
35
|
"apache-arrow": "21.2.0",
|
|
36
36
|
"diff-match-patch-ts": "^2.0.0",
|
|
37
|
+
"libpg-query": "18.2.2",
|
|
37
38
|
"onnxruntime-common": "1.30.0",
|
|
38
39
|
"parse5": "8.0.1",
|
|
39
40
|
"posthog-node": "5.56.4",
|
|
@@ -126,12 +127,12 @@
|
|
|
126
127
|
"templates:check": "bun run scripts/validation/check-template-drift.ts",
|
|
127
128
|
"templates:sync": "bun run scripts/validation/check-template-drift.ts --write",
|
|
128
129
|
"test": "bun test --dots --bail --max-concurrency=1 --timeout=30000",
|
|
129
|
-
"test:coverage": "bun test --coverage
|
|
130
|
+
"test:coverage": "bun run test --coverage",
|
|
130
131
|
"tools:check": "bun run scripts/validation/verify-tools.ts",
|
|
131
132
|
"typecheck": "bun check --no-script",
|
|
132
133
|
"boundaries:check": "bun run scripts/validation/check-runtime-imports.ts"
|
|
133
134
|
},
|
|
134
135
|
"sideEffects": false,
|
|
135
136
|
"type": "module",
|
|
136
|
-
"version": "0.
|
|
137
|
+
"version": "0.7.0"
|
|
137
138
|
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
import { resolveConfig } from "../config";
|
|
4
|
+
import { inspectHostConfiguration } from "../installer/diagnostics";
|
|
5
|
+
import { collectDiagnostics } from "../runtime/diagnostics";
|
|
6
|
+
import {
|
|
7
|
+
parseOutputArguments,
|
|
8
|
+
selectOutputFormat,
|
|
9
|
+
writeCliOutput,
|
|
10
|
+
type CliOutputContext,
|
|
11
|
+
} from "./output";
|
|
12
|
+
|
|
13
|
+
class DoctorUsageError extends Error {
|
|
14
|
+
constructor(message: string) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "DoctorUsageError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function parseDoctorArguments(args: string[], cwd = process.cwd()) {
|
|
21
|
+
const options: {
|
|
22
|
+
root: string;
|
|
23
|
+
scope: "local" | "global";
|
|
24
|
+
target: "auto" | "codex" | "claude" | "copilot";
|
|
25
|
+
profile?: string;
|
|
26
|
+
} = { root: cwd, scope: "local", target: "auto" };
|
|
27
|
+
const tokens = args.flatMap((token) => {
|
|
28
|
+
const match = /^(--(?:root|scope|target|profile))=(.*)$/.exec(token);
|
|
29
|
+
return match ? [match[1]!, match[2]!] : [token];
|
|
30
|
+
});
|
|
31
|
+
for (let index = 0; index < tokens.length; index++) {
|
|
32
|
+
const option = tokens[index]!;
|
|
33
|
+
if (!["--root", "--scope", "--target", "--profile"].includes(option))
|
|
34
|
+
throw new DoctorUsageError(`Unknown option: ${option}`);
|
|
35
|
+
const value = tokens[++index];
|
|
36
|
+
if (!value || value.startsWith("-"))
|
|
37
|
+
throw new DoctorUsageError(`Missing value for ${option}`);
|
|
38
|
+
if (option === "--root") options.root = path.resolve(value);
|
|
39
|
+
if (option === "--scope") {
|
|
40
|
+
if (value !== "local" && value !== "global")
|
|
41
|
+
throw new DoctorUsageError("Expected --scope local or global");
|
|
42
|
+
options.scope = value;
|
|
43
|
+
}
|
|
44
|
+
if (option === "--target") {
|
|
45
|
+
if (!["auto", "codex", "claude", "copilot"].includes(value))
|
|
46
|
+
throw new DoctorUsageError(
|
|
47
|
+
"Expected --target auto, codex, claude, or copilot",
|
|
48
|
+
);
|
|
49
|
+
options.target = value as typeof options.target;
|
|
50
|
+
}
|
|
51
|
+
if (option === "--profile") {
|
|
52
|
+
if (!/^[\w.-]{1,100}$/.test(value))
|
|
53
|
+
throw new DoctorUsageError(
|
|
54
|
+
"Expected a profile name containing letters, digits, dots, underscores, or hyphens",
|
|
55
|
+
);
|
|
56
|
+
options.profile = value;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (
|
|
60
|
+
options.profile &&
|
|
61
|
+
options.target !== "codex" &&
|
|
62
|
+
options.target !== "auto"
|
|
63
|
+
)
|
|
64
|
+
throw new DoctorUsageError("--profile requires --target codex or auto");
|
|
65
|
+
return options;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function runDoctorCli(
|
|
69
|
+
args = process.argv.slice(2),
|
|
70
|
+
context: CliOutputContext & {
|
|
71
|
+
fetch?: typeof fetch;
|
|
72
|
+
home?: string;
|
|
73
|
+
env?: NodeJS.ProcessEnv;
|
|
74
|
+
} = {},
|
|
75
|
+
): Promise<number> {
|
|
76
|
+
const parsed = parseOutputArguments(args);
|
|
77
|
+
const options = parseDoctorArguments(parsed.args);
|
|
78
|
+
const [diagnostics, host] = await Promise.all([
|
|
79
|
+
collectDiagnostics({ cwd: options.root, fetch: context.fetch }),
|
|
80
|
+
inspectHostConfiguration({
|
|
81
|
+
...options,
|
|
82
|
+
home: context.home,
|
|
83
|
+
env: context.env,
|
|
84
|
+
}),
|
|
85
|
+
]);
|
|
86
|
+
const config = await resolveConfig({ cwd: options.root }).catch(
|
|
87
|
+
() => undefined,
|
|
88
|
+
);
|
|
89
|
+
const output =
|
|
90
|
+
parsed.output ??
|
|
91
|
+
(config
|
|
92
|
+
? selectOutputFormat(config, undefined, context.isTTY)
|
|
93
|
+
: context.isTTY
|
|
94
|
+
? "human"
|
|
95
|
+
: "json");
|
|
96
|
+
writeCliOutput(
|
|
97
|
+
{ ...diagnostics, host },
|
|
98
|
+
output,
|
|
99
|
+
"AST-MCP diagnostics",
|
|
100
|
+
context.write,
|
|
101
|
+
);
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
package/src/cli/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { CliOutputUsageError, parseOutputArguments } from "./output";
|
|
|
2
2
|
|
|
3
3
|
export interface CliHandlers {
|
|
4
4
|
config(args: string[]): Promise<number | undefined> | Promise<void>;
|
|
5
|
+
doctor?(args: string[]): Promise<number | undefined> | Promise<void>;
|
|
5
6
|
hook(): Promise<number>;
|
|
6
7
|
skills?(args: string[]): Promise<void>;
|
|
7
8
|
installer(args: string[]): Promise<void>;
|
|
@@ -10,11 +11,12 @@ export interface CliHandlers {
|
|
|
10
11
|
stdout?(text: string): void;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
const rootHelp = `ast-mcp - AST-aware Model Context Protocol server\n\nUsage:\n ast-mcp <command> [options]\n\nCommands:\n config Validate, display, or migrate ast-mcp.toml configuration\n install Configure ast-mcp for one or more supported hosts\n update Refresh an existing ast-mcp configuration\n uninstall Remove ast-mcp-managed configuration\n mcp Start the stdio or Streamable HTTP MCP server\n skills Export or update manually installed skills\n hook Run the pre-tool-use filesystem guard\n help Display help for a command\n\nOptions:\n --output <format> Output: human, json, yaml, or toml\n -h, --help Display help\n\nRun "ast-mcp help <command>" for command-specific help.\n`;
|
|
14
|
+
const rootHelp = `ast-mcp - AST-aware Model Context Protocol server\n\nUsage:\n ast-mcp <command> [options]\n\nCommands:\n config Validate, display, or migrate ast-mcp.toml configuration\n doctor Diagnose host setup, approvals, and release currency\n install Configure ast-mcp for one or more supported hosts\n update Refresh an existing ast-mcp configuration\n uninstall Remove ast-mcp-managed configuration\n mcp Start the stdio or Streamable HTTP MCP server\n skills Export or update manually installed skills\n hook Run the pre-tool-use filesystem guard\n help Display help for a command\n\nOptions:\n --output <format> Output: human, json, yaml, or toml\n -h, --help Display help\n\nRun "ast-mcp help <command>" for command-specific help.\n`;
|
|
14
15
|
|
|
15
16
|
const installerOptions = `Options:\n -s, --scope <scope> Installation scope: local or global (default: local)\n -t, --target <target> Host: codex, claude, copilot, or all (default: all)\n -r, --root <path> Deprecated root override (default: current directory)\n --transport <mode> MCP transport: stdio or http (default: stdio)\n --host <address> HTTP bind host (default: layered configuration)\n --port <number> HTTP bind port (default: layered configuration)\n --service Install and start a managed user HTTP service\n --no-service Stop and remove a managed user HTTP service\n --output <format> Output: human, json, yaml, or toml\n -h, --help Display help\n`;
|
|
16
17
|
|
|
17
18
|
const commandHelp: Record<string, string> = {
|
|
19
|
+
doctor: `Usage:\n ast-mcp doctor [options]\n\nInspect local setup and check the latest stable release without changing configuration. Active host policy remains unknown unless the host supplies it.\n\nOptions:\n --scope <scope> Installation scope: local or global (default: local)\n --target <host> Host: auto, codex, claude, or copilot (default: auto)\n --root <path> Project directory (default: current directory)\n --profile <name> Inspect a Codex profile from disk\n --output <format> Output: human, json, yaml, or toml\n -h, --help Display help\n`,
|
|
18
20
|
skills: `Usage:\n ast-mcp skills <export|update> <destination> [--output <format>]\n\nExport preserves existing files. Update refreshes unchanged managed files and preserves customizations. Conflicts return a nonzero exit. Both commands track file hashes in .ast-mcp-export.json. MCP Skills clients load skills directly; installation does not write skills to disk.\n`,
|
|
19
21
|
config: `Usage:\n ast-mcp config <validate|show|migrate> [options]\n\nValidate, display, or migrate layered ast-mcp.toml configuration. Migration previews by default and never rewrites automatically.\n\nOptions:\n -r, --root <path> Deprecated root or migration target directory\n --file <path> Migrate an explicit configuration file\n --global Migrate the user-global configuration\n --to <version> Migration target version (currently 2)\n --check Exit 2 when migration is required\n --write Atomically write the migration\n --no-backup Do not create the default v1 backup\n --output <format> Output: human, json, yaml, or toml\n -h, --help Display help\n`,
|
|
20
22
|
hook: `Usage:\n ast-mcp hook\n\nRun the pre-tool-use filesystem guard. Hook input is read from stdin.\n\nOptions:\n -h, --help Display help\n`,
|
|
@@ -87,6 +89,7 @@ function isCliUsageError(error: unknown): error is Error {
|
|
|
87
89
|
return [
|
|
88
90
|
"InstallerUsageError",
|
|
89
91
|
"ConfigurationUsageError",
|
|
92
|
+
"DoctorUsageError",
|
|
90
93
|
"McpUsageError",
|
|
91
94
|
"SkillsUsageError",
|
|
92
95
|
"CliOutputUsageError",
|
|
@@ -99,6 +102,11 @@ async function runConfiguredCommand(
|
|
|
99
102
|
handlers: CliHandlers,
|
|
100
103
|
): Promise<number | undefined> {
|
|
101
104
|
try {
|
|
105
|
+
if (command === "doctor") {
|
|
106
|
+
if (!handlers.doctor) throw new Error("Doctor command is unavailable");
|
|
107
|
+
const result = await handlers.doctor(rest);
|
|
108
|
+
return typeof result === "number" ? result : undefined;
|
|
109
|
+
}
|
|
102
110
|
if (command === "skills") {
|
|
103
111
|
if (!handlers.skills) throw new Error("Skills command is unavailable");
|
|
104
112
|
await handlers.skills(rest);
|
package/src/config/index.ts
CHANGED
|
@@ -17,6 +17,10 @@ import {
|
|
|
17
17
|
canonicalizePathSync,
|
|
18
18
|
canonicalPathWithin,
|
|
19
19
|
} from "../runtime/path-utils";
|
|
20
|
+
import {
|
|
21
|
+
mergeSqlAssistanceDefaults,
|
|
22
|
+
type SqlAssistanceOptions,
|
|
23
|
+
} from "../runtime/sql-assistance";
|
|
20
24
|
import {
|
|
21
25
|
cliSchema,
|
|
22
26
|
type CliOutputFormat,
|
|
@@ -84,6 +88,7 @@ export interface ResolvedConfig {
|
|
|
84
88
|
"exact" | "whitespace" | "relative-indentation" | "diff-match-patch"
|
|
85
89
|
>;
|
|
86
90
|
strategies: Array<"ast" | "aider_block">;
|
|
91
|
+
sql?: SqlAssistanceOptions;
|
|
87
92
|
};
|
|
88
93
|
read: { modes: Array<"ast" | "text"> };
|
|
89
94
|
};
|
|
@@ -179,6 +184,8 @@ export interface ResolvedConfig {
|
|
|
179
184
|
export interface ResolveConfigOptions {
|
|
180
185
|
clientRoots?: string[];
|
|
181
186
|
cwd?: string;
|
|
187
|
+
/** Internal captured ambient cwd; preserves implicit host-root precedence. */
|
|
188
|
+
launchCwd?: string;
|
|
182
189
|
env?: NodeJS.ProcessEnv;
|
|
183
190
|
home?: string;
|
|
184
191
|
platform?: NodeJS.Platform;
|
|
@@ -208,6 +215,7 @@ interface InternalConfig {
|
|
|
208
215
|
"exact" | "whitespace" | "relative-indentation" | "diff-match-patch"
|
|
209
216
|
>;
|
|
210
217
|
strategies?: Array<"ast" | "aider_block">;
|
|
218
|
+
sql?: SqlAssistanceOptions;
|
|
211
219
|
};
|
|
212
220
|
read?: { modes?: Array<"ast" | "text"> };
|
|
213
221
|
};
|
|
@@ -677,6 +685,10 @@ const leaves = [
|
|
|
677
685
|
"files.read.modes",
|
|
678
686
|
"files.patch.strategies",
|
|
679
687
|
"files.patch.aider_matchers",
|
|
688
|
+
"files.patch.sql.dialect",
|
|
689
|
+
"files.patch.sql.policy",
|
|
690
|
+
"files.patch.sql.variant",
|
|
691
|
+
"files.patch.sql.version",
|
|
680
692
|
"formatting.dprint_config",
|
|
681
693
|
"formatting.enabled",
|
|
682
694
|
"formatting.fallback",
|
|
@@ -749,7 +761,14 @@ function mergeFileMethods(
|
|
|
749
761
|
): void {
|
|
750
762
|
if (!incoming) return;
|
|
751
763
|
result.files = {
|
|
752
|
-
patch: {
|
|
764
|
+
patch: {
|
|
765
|
+
...previous?.patch,
|
|
766
|
+
...incoming.patch,
|
|
767
|
+
sql: mergeSqlAssistanceDefaults(
|
|
768
|
+
incoming.patch?.sql,
|
|
769
|
+
previous?.patch?.sql,
|
|
770
|
+
),
|
|
771
|
+
},
|
|
753
772
|
read: { ...previous?.read, ...incoming.read },
|
|
754
773
|
};
|
|
755
774
|
}
|
|
@@ -843,9 +862,27 @@ function merge(...layers: InternalConfig[]): InternalConfig {
|
|
|
843
862
|
return result;
|
|
844
863
|
}
|
|
845
864
|
|
|
865
|
+
/** Prospective host selection must be tracked even before its directory exists. */
|
|
866
|
+
export function hostProjectRootCandidate(
|
|
867
|
+
options: ResolveConfigOptions,
|
|
868
|
+
): string | undefined {
|
|
869
|
+
const env = options.env ?? process.env;
|
|
870
|
+
if (
|
|
871
|
+
options.cwd !== undefined ||
|
|
872
|
+
options.clientRoots?.length ||
|
|
873
|
+
env.AST_MCP_PROJECT_ROOT ||
|
|
874
|
+
env.AST_MCP_ROOTS?.split(path.delimiter).filter(Boolean).length
|
|
875
|
+
)
|
|
876
|
+
return undefined;
|
|
877
|
+
const hostRoot = env.CLAUDE_PROJECT_DIR;
|
|
878
|
+
return hostRoot && path.isAbsolute(hostRoot)
|
|
879
|
+
? path.resolve(hostRoot)
|
|
880
|
+
: undefined;
|
|
881
|
+
}
|
|
882
|
+
|
|
846
883
|
async function projectRoots(options: ResolveConfigOptions) {
|
|
847
884
|
const env = options.env ?? process.env;
|
|
848
|
-
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
885
|
+
const cwd = path.resolve(options.cwd ?? options.launchCwd ?? process.cwd());
|
|
849
886
|
const withCanonical = async (roots: string[]) => [
|
|
850
887
|
...new Set([
|
|
851
888
|
...roots,
|
|
@@ -880,6 +917,18 @@ async function projectRoots(options: ResolveConfigOptions) {
|
|
|
880
917
|
};
|
|
881
918
|
}
|
|
882
919
|
|
|
920
|
+
// Claude Code supplies this launch context; it selects configuration, not approval.
|
|
921
|
+
const hostRoot = hostProjectRootCandidate(options);
|
|
922
|
+
if (hostRoot) {
|
|
923
|
+
const selected = hostRoot;
|
|
924
|
+
const metadata = await stat(selected).catch(() => undefined);
|
|
925
|
+
if (metadata?.isDirectory())
|
|
926
|
+
return {
|
|
927
|
+
candidates: [selected],
|
|
928
|
+
trustedRoots: await withCanonical([selected]),
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
|
|
883
932
|
return {
|
|
884
933
|
candidates: [cwd],
|
|
885
934
|
trustedRoots: await withCanonical([cwd]),
|
|
@@ -959,10 +1008,15 @@ type ConfigLayer = {
|
|
|
959
1008
|
|
|
960
1009
|
function configProvenance(layers: ConfigLayer[]) {
|
|
961
1010
|
const provenance: ResolvedConfig["provenance"] = {};
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
1011
|
+
let effective: InternalConfig = {};
|
|
1012
|
+
for (const layer of layers) {
|
|
1013
|
+
effective = merge(effective, layer.value);
|
|
1014
|
+
for (const dotted of leaves) {
|
|
1015
|
+
if (leaf(effective, dotted) === undefined) delete provenance[dotted];
|
|
1016
|
+
else if (leaf(layer.value, dotted) !== undefined)
|
|
965
1017
|
provenance[dotted] = layer.name;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
966
1020
|
return provenance;
|
|
967
1021
|
}
|
|
968
1022
|
|
|
@@ -999,6 +1053,7 @@ function resolvedFiles(value: InternalConfig): ResolvedConfig["files"] {
|
|
|
999
1053
|
"diff-match-patch",
|
|
1000
1054
|
],
|
|
1001
1055
|
strategies: value.files?.patch?.strategies ?? ["ast", "aider_block"],
|
|
1056
|
+
sql: { ...value.files?.patch?.sql },
|
|
1002
1057
|
},
|
|
1003
1058
|
read: { modes: value.files?.read?.modes ?? ["ast", "text"] },
|
|
1004
1059
|
};
|
|
@@ -1223,7 +1278,7 @@ function resolvedConfiguration(args: {
|
|
|
1223
1278
|
|
|
1224
1279
|
function resolutionRuntime(options: ResolveConfigOptions) {
|
|
1225
1280
|
return {
|
|
1226
|
-
cwd: path.resolve(options.cwd ?? process.cwd()),
|
|
1281
|
+
cwd: path.resolve(options.cwd ?? options.launchCwd ?? process.cwd()),
|
|
1227
1282
|
env: options.env ?? process.env,
|
|
1228
1283
|
};
|
|
1229
1284
|
}
|