@mwillbanks/ast-mcp 0.6.6 → 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
package/src/patch/engine.ts
CHANGED
|
@@ -54,6 +54,13 @@ import {
|
|
|
54
54
|
FileSnapshotCollection,
|
|
55
55
|
stageFileSnapshot,
|
|
56
56
|
} from "../runtime/snapshot-blob";
|
|
57
|
+
import {
|
|
58
|
+
evaluateSqlCandidate,
|
|
59
|
+
resolveSqlAssistanceOptions,
|
|
60
|
+
type ResolvedSqlAssistanceOptions,
|
|
61
|
+
type SqlAssistanceOptions,
|
|
62
|
+
type SqlPatchDecision,
|
|
63
|
+
} from "../runtime/sql-assistance";
|
|
57
64
|
import {
|
|
58
65
|
type AiderBlock,
|
|
59
66
|
type AstRule,
|
|
@@ -85,6 +92,7 @@ export interface PatchRequest {
|
|
|
85
92
|
filePath: string;
|
|
86
93
|
patchStrategy: "ast" | "aider_block";
|
|
87
94
|
preview?: boolean;
|
|
95
|
+
sql?: SqlAssistanceOptions;
|
|
88
96
|
}
|
|
89
97
|
|
|
90
98
|
export interface PatchBatchRequest {
|
|
@@ -95,6 +103,7 @@ export interface PatchBatchRequest {
|
|
|
95
103
|
patchStrategy?: "ast" | "aider_block";
|
|
96
104
|
preview?: boolean;
|
|
97
105
|
previewReceipt?: string;
|
|
106
|
+
sql?: SqlAssistanceOptions;
|
|
98
107
|
}
|
|
99
108
|
|
|
100
109
|
export type PatchBatch = Record<string, PatchBatchRequest>;
|
|
@@ -252,10 +261,17 @@ function previewDiff(filePath: string, before: string, after: string): string {
|
|
|
252
261
|
: lines.join("\n");
|
|
253
262
|
}
|
|
254
263
|
|
|
264
|
+
interface PatchSqlBinding {
|
|
265
|
+
options?: Readonly<SqlAssistanceOptions>;
|
|
266
|
+
defaults: Readonly<SqlAssistanceOptions>;
|
|
267
|
+
resolved: Readonly<ResolvedSqlAssistanceOptions>;
|
|
268
|
+
}
|
|
269
|
+
|
|
255
270
|
interface PatchContext extends PatchStrategyContext {
|
|
256
271
|
actual: string;
|
|
257
272
|
capabilities: FileCapabilities;
|
|
258
273
|
request: PatchBatchRequest;
|
|
274
|
+
sqlBinding?: PatchSqlBinding;
|
|
259
275
|
}
|
|
260
276
|
|
|
261
277
|
type PreviewMetadata = PatchStrategyMetadata;
|
|
@@ -272,8 +288,10 @@ interface PreviewReceipt {
|
|
|
272
288
|
metadata: PreviewMetadata;
|
|
273
289
|
normalizedOperations: Pick<
|
|
274
290
|
PatchBatchRequest,
|
|
275
|
-
"aiderBlocks" | "astRules" | "chattr" | "patchStrategy"
|
|
291
|
+
"aiderBlocks" | "astRules" | "chattr" | "patchStrategy" | "sql"
|
|
276
292
|
>;
|
|
293
|
+
sqlBinding?: PatchSqlBinding;
|
|
294
|
+
sqlDecision?: SqlPatchDecision;
|
|
277
295
|
payloadBytes: number;
|
|
278
296
|
sessionId: string;
|
|
279
297
|
sourceSha256: string;
|
|
@@ -294,6 +312,7 @@ const previewConfigurationIdentity = (
|
|
|
294
312
|
JSON.stringify({
|
|
295
313
|
dependencies: config.dependencies,
|
|
296
314
|
formatting: config.formatting,
|
|
315
|
+
patch: config.files.patch,
|
|
297
316
|
projectRoot: config.projectRoot,
|
|
298
317
|
safety: config.safety,
|
|
299
318
|
sources: config.sources,
|
|
@@ -483,17 +502,92 @@ async function validatePreviewReceipt(filePath: string, token: string) {
|
|
|
483
502
|
return receipt;
|
|
484
503
|
}
|
|
485
504
|
|
|
505
|
+
function createSqlBinding(
|
|
506
|
+
capabilities: FileCapabilities,
|
|
507
|
+
options: Readonly<SqlAssistanceOptions> | undefined,
|
|
508
|
+
defaults: SqlAssistanceOptions,
|
|
509
|
+
): PatchSqlBinding | undefined {
|
|
510
|
+
if (capabilities.language !== "sql") {
|
|
511
|
+
if (options !== undefined)
|
|
512
|
+
throw Object.assign(
|
|
513
|
+
new Error("SQL assistance applies only to SQL files"),
|
|
514
|
+
{
|
|
515
|
+
code: "sql_assistance_not_applicable",
|
|
516
|
+
retryable: true,
|
|
517
|
+
},
|
|
518
|
+
);
|
|
519
|
+
return undefined;
|
|
520
|
+
}
|
|
521
|
+
const snapshot = Object.freeze({ ...defaults });
|
|
522
|
+
return {
|
|
523
|
+
options,
|
|
524
|
+
defaults: snapshot,
|
|
525
|
+
resolved: resolveSqlAssistanceOptions(options, snapshot),
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
async function evaluatePatchSql(
|
|
530
|
+
source: string,
|
|
531
|
+
binding?: PatchSqlBinding,
|
|
532
|
+
): Promise<SqlPatchDecision | undefined> {
|
|
533
|
+
if (!binding) return undefined;
|
|
534
|
+
const decision = await evaluateSqlCandidate({
|
|
535
|
+
source,
|
|
536
|
+
options: binding.options,
|
|
537
|
+
defaults: binding.defaults,
|
|
538
|
+
signal: patchSignals.getStore(),
|
|
539
|
+
});
|
|
540
|
+
if (!decision.allowed)
|
|
541
|
+
throw Object.assign(
|
|
542
|
+
new Error(
|
|
543
|
+
"SQL validation rejected this candidate under the required policy",
|
|
544
|
+
),
|
|
545
|
+
{
|
|
546
|
+
code: "sql_validation_rejected",
|
|
547
|
+
details: { sql: decision },
|
|
548
|
+
retryable: true,
|
|
549
|
+
suggestedNextCall:
|
|
550
|
+
"Review SQL diagnostics or preview a guarded patch with sql.policy='skip'",
|
|
551
|
+
},
|
|
552
|
+
);
|
|
553
|
+
return decision;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
function verifyReceiptSql(receipt: PreviewReceipt, request: PatchBatchRequest) {
|
|
557
|
+
if (request.sql === undefined) return;
|
|
558
|
+
const supplied = resolveSqlAssistanceOptions(
|
|
559
|
+
request.sql,
|
|
560
|
+
receipt.sqlBinding?.defaults,
|
|
561
|
+
);
|
|
562
|
+
if (
|
|
563
|
+
!receipt.sqlBinding ||
|
|
564
|
+
JSON.stringify(supplied) !== JSON.stringify(receipt.sqlBinding.resolved)
|
|
565
|
+
)
|
|
566
|
+
throw receiptError(
|
|
567
|
+
"preview_receipt_sql_changed",
|
|
568
|
+
"SQL assistance policy or variant changed; preview the patch again",
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
|
|
486
572
|
async function createPatchContext(
|
|
487
573
|
filePath: string,
|
|
488
574
|
request: PatchBatchRequest,
|
|
489
575
|
): Promise<PatchContext> {
|
|
576
|
+
const sqlOptions =
|
|
577
|
+
request.sql === undefined ? undefined : Object.freeze({ ...request.sql });
|
|
490
578
|
const original = await readText(filePath);
|
|
491
579
|
const actual = sha256(original);
|
|
492
580
|
await requireExpectedHash(request.expectedSha256, "file_patch");
|
|
493
581
|
verifyExpectedHash(request.expectedSha256, actual);
|
|
494
582
|
const capabilities = await inspectFileCapabilities(filePath);
|
|
583
|
+
const sqlBinding = createSqlBinding(
|
|
584
|
+
capabilities,
|
|
585
|
+
sqlOptions,
|
|
586
|
+
(await currentConfig()).files.patch.sql ?? {},
|
|
587
|
+
);
|
|
495
588
|
return {
|
|
496
589
|
actual,
|
|
590
|
+
sqlBinding,
|
|
497
591
|
aiderBlocks: request.aiderBlocks ?? [],
|
|
498
592
|
astRules: request.astRules ?? [],
|
|
499
593
|
capabilities,
|
|
@@ -510,17 +604,19 @@ async function patchPreview(
|
|
|
510
604
|
context: PatchContext,
|
|
511
605
|
candidate: string,
|
|
512
606
|
metadata: PreviewMetadata,
|
|
607
|
+
sqlDecision?: SqlPatchDecision,
|
|
513
608
|
) {
|
|
514
609
|
const config = await currentConfig();
|
|
515
610
|
const receipt = randomUUID();
|
|
516
611
|
const expiresAt = Date.now() + PREVIEW_RECEIPT_TTL_MS;
|
|
517
612
|
const sessionId = approvalSessionId();
|
|
518
|
-
const normalizedOperations = {
|
|
613
|
+
const normalizedOperations = structuredClone({
|
|
519
614
|
aiderBlocks: context.request.aiderBlocks,
|
|
520
615
|
astRules: context.request.astRules,
|
|
521
616
|
chattr: context.request.chattr,
|
|
522
617
|
patchStrategy: context.request.patchStrategy,
|
|
523
|
-
|
|
618
|
+
sql: context.sqlBinding?.options,
|
|
619
|
+
});
|
|
524
620
|
const payloadBytes = previewPayloadBytes(
|
|
525
621
|
sessionId,
|
|
526
622
|
candidate,
|
|
@@ -534,8 +630,10 @@ async function patchPreview(
|
|
|
534
630
|
previewReceipts.set(receipt, {
|
|
535
631
|
candidate,
|
|
536
632
|
candidateSha256: sha256(candidate),
|
|
537
|
-
chattr:
|
|
633
|
+
chattr: normalizedOperations.chattr,
|
|
538
634
|
configurationIdentity: previewConfigurationIdentity(config),
|
|
635
|
+
sqlBinding: context.sqlBinding,
|
|
636
|
+
sqlDecision: sqlDecision ? structuredClone(sqlDecision) : undefined,
|
|
539
637
|
expiresAt,
|
|
540
638
|
expiryTimer,
|
|
541
639
|
filePath: context.filePath,
|
|
@@ -567,6 +665,7 @@ async function patchPreview(
|
|
|
567
665
|
receiptExpiresAt: new Date(expiresAt).toISOString(),
|
|
568
666
|
sha256: sha256(candidate),
|
|
569
667
|
strategy: metadata.strategy,
|
|
668
|
+
...(sqlDecision ? { sql: structuredClone(sqlDecision) } : {}),
|
|
570
669
|
};
|
|
571
670
|
}
|
|
572
671
|
|
|
@@ -575,17 +674,27 @@ async function prepareStrategyPatch(context: PatchContext) {
|
|
|
575
674
|
context.request.patchStrategy,
|
|
576
675
|
).prepare(context);
|
|
577
676
|
await validateStructuredCandidate(context.capabilities, prepared.candidate);
|
|
578
|
-
return {
|
|
677
|
+
return {
|
|
678
|
+
candidate: prepared.candidate,
|
|
679
|
+
metadata: prepared.metadata,
|
|
680
|
+
sql: await evaluatePatchSql(prepared.candidate, context.sqlBinding),
|
|
681
|
+
};
|
|
579
682
|
}
|
|
580
683
|
|
|
581
684
|
async function formatCandidate(
|
|
582
685
|
filePath: string,
|
|
583
686
|
candidate: string,
|
|
584
687
|
capabilities: FileCapabilities,
|
|
688
|
+
binding?: PatchSqlBinding,
|
|
689
|
+
previousSql?: SqlPatchDecision,
|
|
585
690
|
) {
|
|
586
691
|
const formatted = await formatContent(filePath, candidate);
|
|
587
692
|
await validateStructuredCandidate(capabilities, formatted);
|
|
588
|
-
|
|
693
|
+
const sql =
|
|
694
|
+
formatted === candidate && previousSql
|
|
695
|
+
? previousSql
|
|
696
|
+
: await evaluatePatchSql(formatted, binding);
|
|
697
|
+
return { candidate: formatted, sql };
|
|
589
698
|
}
|
|
590
699
|
|
|
591
700
|
async function applyLockedPatch(
|
|
@@ -602,12 +711,20 @@ async function applyLockedPatch(
|
|
|
602
711
|
const context = await createPatchContext(filePath, request);
|
|
603
712
|
const prepared = await prepareStrategyPatch(context);
|
|
604
713
|
if (request.preview)
|
|
605
|
-
return patchPreview(
|
|
606
|
-
|
|
714
|
+
return patchPreview(
|
|
715
|
+
context,
|
|
716
|
+
prepared.candidate,
|
|
717
|
+
prepared.metadata,
|
|
718
|
+
prepared.sql,
|
|
719
|
+
);
|
|
720
|
+
const formatted = await formatCandidate(
|
|
607
721
|
filePath,
|
|
608
722
|
prepared.candidate,
|
|
609
723
|
context.capabilities,
|
|
724
|
+
context.sqlBinding,
|
|
725
|
+
prepared.sql,
|
|
610
726
|
);
|
|
727
|
+
const candidate = formatted.candidate;
|
|
611
728
|
await commit(
|
|
612
729
|
filePath,
|
|
613
730
|
candidate,
|
|
@@ -622,6 +739,7 @@ async function applyLockedPatch(
|
|
|
622
739
|
filePath,
|
|
623
740
|
preview: false,
|
|
624
741
|
sha256: sha256(candidate),
|
|
742
|
+
...(formatted.sql ? { sql: formatted.sql } : {}),
|
|
625
743
|
};
|
|
626
744
|
}
|
|
627
745
|
|
|
@@ -637,12 +755,14 @@ async function applyPatchBatch(
|
|
|
637
755
|
export async function patchFile(
|
|
638
756
|
request: PatchRequest,
|
|
639
757
|
): Promise<Record<string, unknown>> {
|
|
758
|
+
request = structuredClone(request);
|
|
640
759
|
return applyPatchBatch(await resolveWritablePath(request.filePath), {
|
|
641
760
|
aiderBlocks: request.aiderBlock ? [request.aiderBlock] : undefined,
|
|
642
761
|
astRules: request.astRule ? [request.astRule] : undefined,
|
|
643
762
|
expectedSha256: request.expectedSha256,
|
|
644
763
|
patchStrategy: request.patchStrategy,
|
|
645
764
|
preview: request.preview,
|
|
765
|
+
sql: request.sql,
|
|
646
766
|
});
|
|
647
767
|
}
|
|
648
768
|
|
|
@@ -654,6 +774,8 @@ interface PreparedPatch {
|
|
|
654
774
|
receiptToken?: string;
|
|
655
775
|
result?: Record<string, unknown>;
|
|
656
776
|
sourceSha256?: string;
|
|
777
|
+
sqlBinding?: PatchSqlBinding;
|
|
778
|
+
sqlDecision?: SqlPatchDecision;
|
|
657
779
|
}
|
|
658
780
|
|
|
659
781
|
async function preflightPatchBatch(
|
|
@@ -667,6 +789,7 @@ async function preflightPatchBatch(
|
|
|
667
789
|
filePath,
|
|
668
790
|
request.previewReceipt,
|
|
669
791
|
);
|
|
792
|
+
verifyReceiptSql(receipt, request);
|
|
670
793
|
await requireExpectedHash(request.expectedSha256, "file_patch");
|
|
671
794
|
verifyExpectedHash(request.expectedSha256, receipt.sourceSha256);
|
|
672
795
|
return {
|
|
@@ -674,6 +797,10 @@ async function preflightPatchBatch(
|
|
|
674
797
|
chattr: receipt.chattr,
|
|
675
798
|
mode: (await lstat(filePath)).mode,
|
|
676
799
|
receiptToken: request.previewReceipt,
|
|
800
|
+
sqlBinding: receipt.sqlBinding,
|
|
801
|
+
sqlDecision: receipt.sqlDecision
|
|
802
|
+
? structuredClone(receipt.sqlDecision)
|
|
803
|
+
: undefined,
|
|
677
804
|
result: {
|
|
678
805
|
filePath,
|
|
679
806
|
matches: receipt.metadata.matches,
|
|
@@ -694,6 +821,8 @@ async function preflightPatchBatch(
|
|
|
694
821
|
candidate: prepared.candidate,
|
|
695
822
|
chattr: request.chattr,
|
|
696
823
|
mode: context.mode,
|
|
824
|
+
sqlBinding: context.sqlBinding,
|
|
825
|
+
sqlDecision: prepared.sql,
|
|
697
826
|
result: {
|
|
698
827
|
...prepared.metadata,
|
|
699
828
|
filePath,
|
|
@@ -718,11 +847,24 @@ async function applyPreparedPatch(
|
|
|
718
847
|
prepared.sourceSha256 === undefined
|
|
719
848
|
)
|
|
720
849
|
throw new Error("Patch batch preflight did not produce a commit candidate");
|
|
721
|
-
const
|
|
850
|
+
const formatted = await formatCandidate(
|
|
722
851
|
filePath,
|
|
723
852
|
prepared.candidate,
|
|
724
853
|
await inspectFileCapabilities(filePath),
|
|
854
|
+
prepared.sqlBinding,
|
|
855
|
+
// A receipt crosses operations and must recheck the current validator.
|
|
856
|
+
prepared.receiptToken ? undefined : prepared.sqlDecision,
|
|
725
857
|
);
|
|
858
|
+
const candidate = formatted.candidate;
|
|
859
|
+
if (
|
|
860
|
+
prepared.receiptToken &&
|
|
861
|
+
JSON.stringify(formatted.sql?.validation.validator) !==
|
|
862
|
+
JSON.stringify(prepared.sqlDecision?.validation.validator)
|
|
863
|
+
)
|
|
864
|
+
throw receiptError(
|
|
865
|
+
"preview_receipt_sql_changed",
|
|
866
|
+
"SQL validator identity changed; preview the patch again",
|
|
867
|
+
);
|
|
726
868
|
if (prepared.receiptToken)
|
|
727
869
|
await validatePreviewReceipt(filePath, prepared.receiptToken);
|
|
728
870
|
await commit(
|
|
@@ -734,7 +876,11 @@ async function applyPreparedPatch(
|
|
|
734
876
|
true,
|
|
735
877
|
beforeReplace,
|
|
736
878
|
);
|
|
737
|
-
return {
|
|
879
|
+
return {
|
|
880
|
+
...prepared.result,
|
|
881
|
+
sha256: sha256(candidate),
|
|
882
|
+
...(formatted.sql ? { sql: structuredClone(formatted.sql) } : {}),
|
|
883
|
+
};
|
|
738
884
|
}
|
|
739
885
|
|
|
740
886
|
interface PreparedWrite {
|
|
@@ -1082,7 +1228,7 @@ async function processFileBatch<T, Prepared>(
|
|
|
1082
1228
|
options: FileLockOptions = {},
|
|
1083
1229
|
): Promise<Record<string, unknown>> {
|
|
1084
1230
|
options.signal?.throwIfAborted();
|
|
1085
|
-
const entries = Object.entries(requests);
|
|
1231
|
+
const entries = Object.entries(structuredClone(requests));
|
|
1086
1232
|
if (entries.length < 1 || entries.length > FILE_READ_MAX_BATCH)
|
|
1087
1233
|
throw new Error(
|
|
1088
1234
|
`${tool} requires between 1 and ${FILE_READ_MAX_BATCH} files`,
|