@getchomp/mcp 0.0.0-stage → 0.2.42
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 +15 -2
- package/dist/conventionsReference.d.ts +84 -0
- package/dist/conventionsReference.js +313 -0
- package/dist/designSystem/astScanner.d.ts +153 -0
- package/dist/designSystem/astScanner.js +2014 -0
- package/dist/designSystem/baseline.d.ts +65 -0
- package/dist/designSystem/baseline.js +136 -0
- package/dist/designSystem/color.d.ts +35 -0
- package/dist/designSystem/color.js +265 -0
- package/dist/designSystem/config.d.ts +183 -0
- package/dist/designSystem/config.js +469 -0
- package/dist/designSystem/contrast.d.ts +55 -0
- package/dist/designSystem/contrast.js +377 -0
- package/dist/designSystem/cssParser.d.ts +63 -0
- package/dist/designSystem/cssParser.js +469 -0
- package/dist/designSystem/merges.d.ts +57 -0
- package/dist/designSystem/merges.js +94 -0
- package/dist/designSystem/preprocessors.d.ts +46 -0
- package/dist/designSystem/preprocessors.js +1108 -0
- package/dist/designSystem/presentation.d.ts +45 -0
- package/dist/designSystem/presentation.js +796 -0
- package/dist/designSystem/styleVectors.d.ts +27 -0
- package/dist/designSystem/styleVectors.js +484 -0
- package/dist/designSystem/tokens.d.ts +39 -0
- package/dist/designSystem/tokens.js +409 -0
- package/dist/designSystem/topology.d.ts +64 -0
- package/dist/designSystem/topology.js +254 -0
- package/dist/designSystem/types.d.ts +857 -0
- package/dist/designSystem/types.js +113 -0
- package/dist/designSystem/typography.d.ts +25 -0
- package/dist/designSystem/typography.js +244 -0
- package/dist/designSystem/uiShapes.d.ts +74 -0
- package/dist/designSystem/uiShapes.js +285 -0
- package/dist/designSystem/valueClusters.d.ts +76 -0
- package/dist/designSystem/valueClusters.js +281 -0
- package/dist/designSystemPlugin.d.ts +321 -0
- package/dist/designSystemPlugin.js +4730 -0
- package/dist/enrichNodesPlugin.d.ts +160 -0
- package/dist/enrichNodesPlugin.js +957 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +1298 -0
- package/dist/intelligence.d.ts +502 -0
- package/dist/intelligence.js +3058 -0
- package/dist/pluginRunner.d.ts +364 -0
- package/dist/pluginRunner.js +1096 -0
- package/dist/plugins/design-system/index.d.ts +14 -0
- package/dist/plugins/design-system/index.js +241 -0
- package/dist/plugins/enrich-nodes/index.d.ts +388 -0
- package/dist/plugins/enrich-nodes/index.js +697 -0
- package/dist/plugins/index.d.ts +15 -0
- package/dist/plugins/index.js +20 -0
- package/dist/plugins/local-shims/index.d.ts +121 -0
- package/dist/plugins/local-shims/index.js +237 -0
- package/dist/shimsPlugin.d.ts +134 -0
- package/dist/shimsPlugin.js +1392 -0
- package/package.json +38 -3
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/mcp/src/plugins/index.ts
|
|
3
|
+
*
|
|
4
|
+
* Zero-plumbing folder auto-discovery entry point for built-in Chomp plugins.
|
|
5
|
+
* Adding a new `<plugin-name>/index.ts` folder in this directory automatically:
|
|
6
|
+
* 1. Registers the plugin in the `ChompPlugin` runtime registry (`listChompPlugins`).
|
|
7
|
+
* 2. Provisions `.chomp/plugins/<plugin-name>/` state & settings (`settings.json`).
|
|
8
|
+
* 3. Exposes its `settingsSchema` in Explorer Settings -> Rules -> PLUGINS.
|
|
9
|
+
* 4. Registers its `mcpTools` on the `@getchomp/mcp` server and Settings -> Tools.
|
|
10
|
+
* 5. Wires its `projectGraph`, `isStructuralOverlay`, `PluginPresentation` v1 sections,
|
|
11
|
+
* Active View lenses (`ctx.setActiveView` & `summary.views`), and `formatCliSummary`.
|
|
12
|
+
*/
|
|
13
|
+
import { type ChompPlugin } from "../pluginRunner.js";
|
|
14
|
+
export declare const BUILTIN_PLUGINS_DIR: string;
|
|
15
|
+
export declare function discoverBuiltInPlugins(): Promise<ChompPlugin[]>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/mcp/src/plugins/index.ts
|
|
3
|
+
*
|
|
4
|
+
* Zero-plumbing folder auto-discovery entry point for built-in Chomp plugins.
|
|
5
|
+
* Adding a new `<plugin-name>/index.ts` folder in this directory automatically:
|
|
6
|
+
* 1. Registers the plugin in the `ChompPlugin` runtime registry (`listChompPlugins`).
|
|
7
|
+
* 2. Provisions `.chomp/plugins/<plugin-name>/` state & settings (`settings.json`).
|
|
8
|
+
* 3. Exposes its `settingsSchema` in Explorer Settings -> Rules -> PLUGINS.
|
|
9
|
+
* 4. Registers its `mcpTools` on the `@getchomp/mcp` server and Settings -> Tools.
|
|
10
|
+
* 5. Wires its `projectGraph`, `isStructuralOverlay`, `PluginPresentation` v1 sections,
|
|
11
|
+
* Active View lenses (`ctx.setActiveView` & `summary.views`), and `formatCliSummary`.
|
|
12
|
+
*/
|
|
13
|
+
import { dirname } from "node:path";
|
|
14
|
+
import { fileURLToPath } from "node:url";
|
|
15
|
+
import { discoverPluginsInDir } from "../pluginRunner.js";
|
|
16
|
+
export const BUILTIN_PLUGINS_DIR = dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
export async function discoverBuiltInPlugins() {
|
|
18
|
+
return discoverPluginsInDir(BUILTIN_PLUGINS_DIR);
|
|
19
|
+
}
|
|
20
|
+
await discoverBuiltInPlugins();
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/mcp/src/plugins/local-shims/index.ts
|
|
3
|
+
*
|
|
4
|
+
* Self-contained `local-shims` plugin module (`L1_SHIMS`).
|
|
5
|
+
* Auto-discovered from `packages/mcp/src/plugins/` with zero external plumbing:
|
|
6
|
+
* - State & settings folder: `.chomp/plugins/local-shims/` (`shims.json`, `settings.json`)
|
|
7
|
+
* - Declarative Settings UI (`settingsSchema`)
|
|
8
|
+
* - Structural Layer 1 graph projection (`projectGraph`, `isStructuralOverlay`)
|
|
9
|
+
* - Inspector & HUD Presentation (`PluginPresentation` v1)
|
|
10
|
+
* - Active View Spotlight (`ctx.setActiveView` + `summary.views`)
|
|
11
|
+
* - Owned MCP tool (`chomp_local_shims`)
|
|
12
|
+
* - Owned CLI summary formatter (`formatCliSummary`)
|
|
13
|
+
*/
|
|
14
|
+
import { z } from "zod";
|
|
15
|
+
export declare const localShimsPluginModule: {
|
|
16
|
+
defaultEnabled: true;
|
|
17
|
+
scanRepoFiles: false;
|
|
18
|
+
settingsSchema: {
|
|
19
|
+
key: string;
|
|
20
|
+
label: string;
|
|
21
|
+
description: string;
|
|
22
|
+
kind: "boolean";
|
|
23
|
+
defaultValue: true;
|
|
24
|
+
}[];
|
|
25
|
+
isStructuralOverlay: (ov: import("../../pluginRunner.js").ChompPluginProjectionOverlayLike) => boolean;
|
|
26
|
+
projectGraph: (ctx: import("../../pluginRunner.js").ChompPluginProjectionContext) => import("@getchomp/core").RepresentationGraph;
|
|
27
|
+
formatCliSummary: (res: import("../../pluginRunner.js").RunChompPluginResult, ansi: import("../../pluginRunner.js").ChompCliAnsiHelpers) => string[];
|
|
28
|
+
mcpTools: {
|
|
29
|
+
name: string;
|
|
30
|
+
description: string;
|
|
31
|
+
inputSchema: {
|
|
32
|
+
action: z.ZodOptional<z.ZodEnum<["status", "suggest", "validate", "upsert", "remove", "run"]>>;
|
|
33
|
+
shims: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
34
|
+
id: z.ZodOptional<z.ZodString>;
|
|
35
|
+
sourceId: z.ZodOptional<z.ZodString>;
|
|
36
|
+
sourceName: z.ZodOptional<z.ZodString>;
|
|
37
|
+
sourceFile: z.ZodOptional<z.ZodString>;
|
|
38
|
+
callName: z.ZodOptional<z.ZodString>;
|
|
39
|
+
shapeKey: z.ZodOptional<z.ZodString>;
|
|
40
|
+
targetId: z.ZodOptional<z.ZodString>;
|
|
41
|
+
targetName: z.ZodOptional<z.ZodString>;
|
|
42
|
+
targetFile: z.ZodOptional<z.ZodString>;
|
|
43
|
+
targetConnector: z.ZodOptional<z.ZodObject<{
|
|
44
|
+
name: z.ZodString;
|
|
45
|
+
entityType: z.ZodOptional<z.ZodString>;
|
|
46
|
+
}, "strip", z.ZodTypeAny, {
|
|
47
|
+
name: string;
|
|
48
|
+
entityType?: string | undefined;
|
|
49
|
+
}, {
|
|
50
|
+
name: string;
|
|
51
|
+
entityType?: string | undefined;
|
|
52
|
+
}>>;
|
|
53
|
+
entityType: z.ZodOptional<z.ZodString>;
|
|
54
|
+
edgeName: z.ZodOptional<z.ZodString>;
|
|
55
|
+
label: z.ZodOptional<z.ZodString>;
|
|
56
|
+
rationale: z.ZodOptional<z.ZodString>;
|
|
57
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
58
|
+
}, "strip", z.ZodTypeAny, {
|
|
59
|
+
id?: string | undefined;
|
|
60
|
+
entityType?: string | undefined;
|
|
61
|
+
shapeKey?: string | undefined;
|
|
62
|
+
label?: string | undefined;
|
|
63
|
+
rationale?: string | undefined;
|
|
64
|
+
sourceId?: string | undefined;
|
|
65
|
+
sourceName?: string | undefined;
|
|
66
|
+
sourceFile?: string | undefined;
|
|
67
|
+
callName?: string | undefined;
|
|
68
|
+
targetId?: string | undefined;
|
|
69
|
+
targetName?: string | undefined;
|
|
70
|
+
targetFile?: string | undefined;
|
|
71
|
+
targetConnector?: {
|
|
72
|
+
name: string;
|
|
73
|
+
entityType?: string | undefined;
|
|
74
|
+
} | undefined;
|
|
75
|
+
edgeName?: string | undefined;
|
|
76
|
+
enabled?: boolean | undefined;
|
|
77
|
+
}, {
|
|
78
|
+
id?: string | undefined;
|
|
79
|
+
entityType?: string | undefined;
|
|
80
|
+
shapeKey?: string | undefined;
|
|
81
|
+
label?: string | undefined;
|
|
82
|
+
rationale?: string | undefined;
|
|
83
|
+
sourceId?: string | undefined;
|
|
84
|
+
sourceName?: string | undefined;
|
|
85
|
+
sourceFile?: string | undefined;
|
|
86
|
+
callName?: string | undefined;
|
|
87
|
+
targetId?: string | undefined;
|
|
88
|
+
targetName?: string | undefined;
|
|
89
|
+
targetFile?: string | undefined;
|
|
90
|
+
targetConnector?: {
|
|
91
|
+
name: string;
|
|
92
|
+
entityType?: string | undefined;
|
|
93
|
+
} | undefined;
|
|
94
|
+
edgeName?: string | undefined;
|
|
95
|
+
enabled?: boolean | undefined;
|
|
96
|
+
}>, "many">>;
|
|
97
|
+
shim_ids: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
98
|
+
shimIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
99
|
+
clear_all: z.ZodOptional<z.ZodBoolean>;
|
|
100
|
+
clearAll: z.ZodOptional<z.ZodBoolean>;
|
|
101
|
+
packageName: z.ZodOptional<z.ZodString>;
|
|
102
|
+
package_name: z.ZodOptional<z.ZodString>;
|
|
103
|
+
include_dynamic: z.ZodOptional<z.ZodBoolean>;
|
|
104
|
+
includeDynamic: z.ZodOptional<z.ZodBoolean>;
|
|
105
|
+
create_view: z.ZodOptional<z.ZodBoolean>;
|
|
106
|
+
createView: z.ZodOptional<z.ZodBoolean>;
|
|
107
|
+
};
|
|
108
|
+
handler: (args: Record<string, any>, ctx: import("../../pluginRunner.js").ChompPluginToolContext) => Promise<Record<string, unknown>>;
|
|
109
|
+
}[];
|
|
110
|
+
name: string;
|
|
111
|
+
version: string;
|
|
112
|
+
layer: import("@getchomp/db").OverlayLayer;
|
|
113
|
+
displayName?: string;
|
|
114
|
+
description: string;
|
|
115
|
+
order?: number;
|
|
116
|
+
legacySources?: string[];
|
|
117
|
+
inspectorScopes?: import("@getchomp/core").PluginInspectorScope[];
|
|
118
|
+
accepts: (filePath: string) => boolean;
|
|
119
|
+
extract: (ctx: import("../../pluginRunner.js").ChompPluginContext) => Promise<import("../../pluginRunner.js").ChompPluginExtractResult | import("@getchomp/db").EntityOverlayInput[]> | import("../../pluginRunner.js").ChompPluginExtractResult | import("@getchomp/db").EntityOverlayInput[];
|
|
120
|
+
};
|
|
121
|
+
export default localShimsPluginModule;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/mcp/src/plugins/local-shims/index.ts
|
|
3
|
+
*
|
|
4
|
+
* Self-contained `local-shims` plugin module (`L1_SHIMS`).
|
|
5
|
+
* Auto-discovered from `packages/mcp/src/plugins/` with zero external plumbing:
|
|
6
|
+
* - State & settings folder: `.chomp/plugins/local-shims/` (`shims.json`, `settings.json`)
|
|
7
|
+
* - Declarative Settings UI (`settingsSchema`)
|
|
8
|
+
* - Structural Layer 1 graph projection (`projectGraph`, `isStructuralOverlay`)
|
|
9
|
+
* - Inspector & HUD Presentation (`PluginPresentation` v1)
|
|
10
|
+
* - Active View Spotlight (`ctx.setActiveView` + `summary.views`)
|
|
11
|
+
* - Owned MCP tool (`chomp_local_shims`)
|
|
12
|
+
* - Owned CLI summary formatter (`formatCliSummary`)
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync } from "node:fs";
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
import { SHIM_OVERLAY_LAYER, applyShimOverlaysToGraph } from "@getchomp/core";
|
|
17
|
+
import { LEGACY_LOCAL_SHIMS_FILE_REL, LOCAL_SHIMS_FILE_REL, evaluateShimsAgainstGraph, loadLocalShimsFromTexts, localShimsPlugin, manageLocalShims, } from "../../shimsPlugin.js";
|
|
18
|
+
import { defineChompPlugin } from "../../pluginRunner.js";
|
|
19
|
+
export const localShimsPluginModule = defineChompPlugin({
|
|
20
|
+
...localShimsPlugin,
|
|
21
|
+
defaultEnabled: true,
|
|
22
|
+
scanRepoFiles: false,
|
|
23
|
+
settingsSchema: [
|
|
24
|
+
{
|
|
25
|
+
key: "includeConfigShims",
|
|
26
|
+
label: "Include config bridges",
|
|
27
|
+
description: "Load shared bridges from chomp.config.json.",
|
|
28
|
+
kind: "boolean",
|
|
29
|
+
defaultValue: true,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
key: "showUnresolvedHotspotLens",
|
|
33
|
+
label: "Show unresolved patterns view",
|
|
34
|
+
description: "List unresolved patterns in the HUD and package inspector.",
|
|
35
|
+
kind: "boolean",
|
|
36
|
+
defaultValue: true,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
isStructuralOverlay: (ov) => ov.layer === SHIM_OVERLAY_LAYER &&
|
|
40
|
+
((Array.isArray(ov.payload?.shimmedEdges) && ov.payload.shimmedEdges.length > 0) ||
|
|
41
|
+
(Array.isArray(ov.payload?.syntheticConnectors) &&
|
|
42
|
+
ov.payload.syntheticConnectors.length > 0)),
|
|
43
|
+
projectGraph: (ctx) => {
|
|
44
|
+
const includeConfigShims = ctx.settings.includeConfigShims !== false;
|
|
45
|
+
const shimsText = ctx.readPluginFile("shims.json") ?? ctx.readRepoFile(LEGACY_LOCAL_SHIMS_FILE_REL);
|
|
46
|
+
const configText = includeConfigShims ? ctx.readRepoFile("chomp.config.json") : null;
|
|
47
|
+
const { shims } = loadLocalShimsFromTexts(shimsText, configText);
|
|
48
|
+
if (shimsText !== null || shims.length > 0) {
|
|
49
|
+
if (shims.length === 0)
|
|
50
|
+
return ctx.graph;
|
|
51
|
+
const { resolved } = evaluateShimsAgainstGraph(ctx.graph, shims);
|
|
52
|
+
if (resolved.length === 0)
|
|
53
|
+
return ctx.graph;
|
|
54
|
+
const provisionalOverlays = resolved.map((r) => ({
|
|
55
|
+
entityId: r.sourceNode.id,
|
|
56
|
+
layer: SHIM_OVERLAY_LAYER,
|
|
57
|
+
payload: {
|
|
58
|
+
shimmedEdges: [r.edgeEntry],
|
|
59
|
+
...(r.syntheticConnector ? { syntheticConnectors: [r.syntheticConnector] } : {}),
|
|
60
|
+
},
|
|
61
|
+
}));
|
|
62
|
+
return applyShimOverlaysToGraph(ctx.graph, provisionalOverlays, { enabled: true });
|
|
63
|
+
}
|
|
64
|
+
if (!ctx.repoPath && ctx.overlays.length > 0) {
|
|
65
|
+
return applyShimOverlaysToGraph(ctx.graph, ctx.overlays, { enabled: true });
|
|
66
|
+
}
|
|
67
|
+
return ctx.graph;
|
|
68
|
+
},
|
|
69
|
+
formatCliSummary: (res, ansi) => {
|
|
70
|
+
const s = res.summary ?? {};
|
|
71
|
+
if (typeof s.activeShims !== "number")
|
|
72
|
+
return [];
|
|
73
|
+
return [
|
|
74
|
+
`${ansi.dim("Bridges:")} ${ansi.bold(String(s.activeShims))} active / ${s.configuredShims ?? 0} configured · ${(s.unmatchedShims ?? 0) === 0
|
|
75
|
+
? ansi.green("0 unmatched")
|
|
76
|
+
: ansi.yellow(`${s.unmatchedShims} unmatched`)}`,
|
|
77
|
+
`${ansi.dim("Call Gaps:")} ${ansi.green(String(s.bridgedCallCount ?? 0))} bridged · ${(s.remainingUnresolvedCallCount ?? 0) === 0
|
|
78
|
+
? ansi.green("0 remaining")
|
|
79
|
+
: ansi.yellow(`${s.remainingUnresolvedCallCount} remaining`)}`,
|
|
80
|
+
];
|
|
81
|
+
},
|
|
82
|
+
mcpTools: [
|
|
83
|
+
{
|
|
84
|
+
name: "chomp_local_shims",
|
|
85
|
+
description: `BRIDGES PLUGIN: Inspects, suggests, validates, upserts, or removes local runtime/DI map bridges in \`${LOCAL_SHIMS_FILE_REL}\` (plus read-only \`chomp.config.json#shims\`) and refreshes the Bridges (\`local-shims\`) plugin overlays in \`.chomp/graph.db\` without mutating extracted AST nodes or edges. Use \`action: 'suggest'\` to list unresolved call hotspots (\`? N unresolved\`) with candidate targets, \`action: 'validate'\` to dry-run bridges, \`action: 'upsert'\` to persist bridges across story flows, health checks, blast radius, and \`chomp_get_diff\`, or \`action: 'remove'\` to delete bridges. For repeatable syntax conventions across files, prefer \`chomp_get_conventions\` + \`chomp.config.json#conventions\`.`,
|
|
86
|
+
inputSchema: {
|
|
87
|
+
action: z
|
|
88
|
+
.enum(["status", "suggest", "validate", "upsert", "remove", "run"])
|
|
89
|
+
.optional()
|
|
90
|
+
.describe(`Operation to perform: 'status' (default summary of active/unmatched shims & bridged gaps), 'suggest' (generate candidate shims from unresolved calls), 'validate' (dry-run shims against graph), 'upsert' (write shims to ${LOCAL_SHIMS_FILE_REL} & run local-shims plugin), 'remove' (remove shims by id or clearAll), or 'run' (re-evaluate ${LOCAL_SHIMS_FILE_REL} & chomp.config.json#shims into entity_overlays).`),
|
|
91
|
+
shims: z
|
|
92
|
+
.array(z.object({
|
|
93
|
+
id: z.string().optional().describe("Optional stable shim ID (auto-derived when omitted)"),
|
|
94
|
+
sourceId: z
|
|
95
|
+
.string()
|
|
96
|
+
.optional()
|
|
97
|
+
.describe("Exact source CONTRACT/CLASS/INIT_BLOCK node ID from chomp_get_nodes"),
|
|
98
|
+
sourceName: z
|
|
99
|
+
.string()
|
|
100
|
+
.optional()
|
|
101
|
+
.describe("Source contract name or stripped label (e.g., 'checkout' or 'Exported Function: checkout')"),
|
|
102
|
+
sourceFile: z
|
|
103
|
+
.string()
|
|
104
|
+
.optional()
|
|
105
|
+
.describe("Optional repo-relative file path disambiguating sourceName (e.g., 'src/checkout.ts')"),
|
|
106
|
+
callName: z
|
|
107
|
+
.string()
|
|
108
|
+
.optional()
|
|
109
|
+
.describe("Unresolved call expression name on source (e.g., 'container.resolve' or 'Call: container.resolve()')"),
|
|
110
|
+
shapeKey: z
|
|
111
|
+
.string()
|
|
112
|
+
.optional()
|
|
113
|
+
.describe("Optional unresolved call shapeKey filter (e.g., 'sk1/CALL/LocalVar/PropertyAccessExpression')"),
|
|
114
|
+
targetId: z.string().optional().describe("Exact target CONTRACT/CLASS/OPEN_CONNECTOR node ID"),
|
|
115
|
+
targetName: z
|
|
116
|
+
.string()
|
|
117
|
+
.optional()
|
|
118
|
+
.describe("Target contract or connector name (e.g., 'chargeCard' or 'Public Method: StripeGateway.charge')"),
|
|
119
|
+
targetFile: z
|
|
120
|
+
.string()
|
|
121
|
+
.optional()
|
|
122
|
+
.describe("Optional repo-relative file path disambiguating targetName"),
|
|
123
|
+
targetConnector: z
|
|
124
|
+
.object({
|
|
125
|
+
name: z
|
|
126
|
+
.string()
|
|
127
|
+
.describe("Display name of target OPEN_CONNECTOR (e.g., 'HTTP Call: POST /v1/charges' or 'Queue: billing-events')"),
|
|
128
|
+
entityType: z
|
|
129
|
+
.string()
|
|
130
|
+
.optional()
|
|
131
|
+
.describe("OPEN_CONNECTOR entityType (HTTP_FETCH, DB_QUERY, MESSAGE_PUBLISH, EXTERNAL_SDK_CALL, EXTERNAL_PACKAGE)"),
|
|
132
|
+
})
|
|
133
|
+
.optional()
|
|
134
|
+
.describe("Target external exit descriptor (reuses matching OPEN_CONNECTOR or creates an L1_SHIMS synthetic connector)"),
|
|
135
|
+
entityType: z.string().optional().describe("Relationship entityType (defaults to 'CALL')"),
|
|
136
|
+
edgeName: z.string().optional().describe("Optional custom display name for the shimmed relationship"),
|
|
137
|
+
label: z
|
|
138
|
+
.string()
|
|
139
|
+
.optional()
|
|
140
|
+
.describe("Optional short adapter name shown in the station card header (e.g., 'Billing OpenAPI')"),
|
|
141
|
+
rationale: z
|
|
142
|
+
.string()
|
|
143
|
+
.optional()
|
|
144
|
+
.describe("Human/agent explanation of why this runtime/DI connection exists"),
|
|
145
|
+
enabled: z.boolean().optional().describe("Defaults to true; set false to disable without deleting"),
|
|
146
|
+
}))
|
|
147
|
+
.optional()
|
|
148
|
+
.describe("Shim entries to dry-run ('validate') or write ('upsert')"),
|
|
149
|
+
shim_ids: z.array(z.string()).optional().describe("Shim IDs to delete when action is 'remove'"),
|
|
150
|
+
shimIds: z.array(z.string()).optional().describe("Alias for shim_ids (camelCase)"),
|
|
151
|
+
clear_all: z
|
|
152
|
+
.boolean()
|
|
153
|
+
.optional()
|
|
154
|
+
.describe(`When true with action 'remove', clears all entries in ${LOCAL_SHIMS_FILE_REL}`),
|
|
155
|
+
clearAll: z.boolean().optional().describe("Alias for clear_all (camelCase)"),
|
|
156
|
+
packageName: z.string().optional().describe("Optional package filter when action is 'suggest'"),
|
|
157
|
+
package_name: z.string().optional().describe("Alias for packageName (snake_case)"),
|
|
158
|
+
include_dynamic: z
|
|
159
|
+
.boolean()
|
|
160
|
+
.optional()
|
|
161
|
+
.describe("When true with action 'suggest', also includes runtime parameter/callback DYNAMIC_BOUNDARY calls. Leave false (default) to strictly target unhandled patterns and external specs."),
|
|
162
|
+
includeDynamic: z.boolean().optional().describe("Alias for include_dynamic (camelCase)"),
|
|
163
|
+
create_view: z
|
|
164
|
+
.boolean()
|
|
165
|
+
.optional()
|
|
166
|
+
.describe("When true, updates .chomp/current_view.json with L1_SHIMS Spotlight highlights. Leave false (default) during coding tasks; pass true only when answering user questions or walkthrough requests."),
|
|
167
|
+
createView: z.boolean().optional().describe("Alias for create_view (camelCase)"),
|
|
168
|
+
},
|
|
169
|
+
handler: async (args, ctx) => {
|
|
170
|
+
if (!existsSync(ctx.dbPath)) {
|
|
171
|
+
throw new Error(`Chomp database not found at ${ctx.dbPath}. Please run 'chomp analyze .' first.`);
|
|
172
|
+
}
|
|
173
|
+
const rawBaseGraph = await ctx.loadRawGraph();
|
|
174
|
+
if (!rawBaseGraph) {
|
|
175
|
+
throw new Error(`Graph data for repository '${ctx.repoId}' not found in the database. Please run 'chomp analyze .' first.`);
|
|
176
|
+
}
|
|
177
|
+
const action = args.action ?? "status";
|
|
178
|
+
const mutatesOverlays = action === "upsert" || action === "remove" || action === "run";
|
|
179
|
+
const pkgName = args.packageName ?? args.package_name;
|
|
180
|
+
const includeDynamic = args.include_dynamic ?? args.includeDynamic;
|
|
181
|
+
const result = mutatesOverlays
|
|
182
|
+
? await ctx.withStorage((storage) => manageLocalShims({
|
|
183
|
+
action,
|
|
184
|
+
repoPath: ctx.repoPath,
|
|
185
|
+
repoId: ctx.repoId,
|
|
186
|
+
repoName: ctx.repoName,
|
|
187
|
+
storage,
|
|
188
|
+
graph: rawBaseGraph,
|
|
189
|
+
shims: args.shims,
|
|
190
|
+
shimIds: args.shim_ids ?? args.shimIds,
|
|
191
|
+
clearAll: args.clear_all ?? args.clearAll,
|
|
192
|
+
packageName: pkgName,
|
|
193
|
+
includeDynamic,
|
|
194
|
+
}))
|
|
195
|
+
: await manageLocalShims({
|
|
196
|
+
action,
|
|
197
|
+
repoPath: ctx.repoPath,
|
|
198
|
+
repoId: ctx.repoId,
|
|
199
|
+
repoName: ctx.repoName,
|
|
200
|
+
graph: rawBaseGraph,
|
|
201
|
+
shims: args.shims,
|
|
202
|
+
shimIds: args.shim_ids ?? args.shimIds,
|
|
203
|
+
clearAll: args.clear_all ?? args.clearAll,
|
|
204
|
+
packageName: pkgName,
|
|
205
|
+
includeDynamic,
|
|
206
|
+
});
|
|
207
|
+
if (mutatesOverlays) {
|
|
208
|
+
ctx.invalidateCache();
|
|
209
|
+
}
|
|
210
|
+
if (args.create_view ?? args.createView) {
|
|
211
|
+
const projected = (await ctx.loadProjectedGraph()) ?? rawBaseGraph;
|
|
212
|
+
const statusActive = Array.isArray(result.activeShims)
|
|
213
|
+
? result.activeShims
|
|
214
|
+
: [];
|
|
215
|
+
const suggestedNodes = Array.isArray(result.suggestions)
|
|
216
|
+
? result.suggestions
|
|
217
|
+
: [];
|
|
218
|
+
const highlightIds = Array.from(new Set([
|
|
219
|
+
...statusActive.flatMap((s) => [s.sourceId, s.targetId]),
|
|
220
|
+
...suggestedNodes.map((s) => s.sourceNode.id),
|
|
221
|
+
])).slice(0, 40);
|
|
222
|
+
if (highlightIds.length > 0) {
|
|
223
|
+
ctx.setActiveView({
|
|
224
|
+
title: action === "suggest" ? "Unhandled patterns" : "Active adapters",
|
|
225
|
+
description: `Action: ${action} | Highlighted ${highlightIds.length} node(s)`,
|
|
226
|
+
highlightNodeIds: highlightIds,
|
|
227
|
+
...(pkgName ? { viewLevel: "package", packageName: pkgName } : {}),
|
|
228
|
+
graph: projected,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return result;
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
});
|
|
237
|
+
export default localShimsPluginModule;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/mcp/src/shimsPlugin.ts
|
|
3
|
+
*
|
|
4
|
+
* User-Defined Local Graph Shims Plugin (`L1_SHIMS` / `source: 'local-shims'`)
|
|
5
|
+
* Enforces [PAT-DB-03], [PAT-DB-05], [PAT-VIS-15], [PAT-VIS-36], [PAT-MCP-09], [PAT-MCP-10].
|
|
6
|
+
*
|
|
7
|
+
* Sits cleanly as a Layer 1 plugin on top of Chomp's deterministic Layer 0 AST graph:
|
|
8
|
+
* - Layer 0 (`nodes` / `edges` in SQLite) remains 100% pure AST-evidenced facts.
|
|
9
|
+
* - Local shims live in `.chomp/shims.json` (and optional `chomp.config.json#shims`) and are
|
|
10
|
+
* evaluated by `localShimsPlugin` into `L1_SHIMS` `entity_overlays` carrying:
|
|
11
|
+
* 1. Structured `shimmedEdges` + `syntheticConnectors` consumed by `applyShimOverlaysToGraph`
|
|
12
|
+
* when `overlayLayers.L1_SHIMS` is enabled (Eye icon in HUD).
|
|
13
|
+
* 2. Full `PluginPresentation` v1 (`summary`, `metrics`, `views`, `prompt`, `sections`)
|
|
14
|
+
* for the HUD card, Package Inspector, and Node Inspector.
|
|
15
|
+
*/
|
|
16
|
+
import { type RepresentationGraph, type ShimmedEdgeOverlayEntry, type StructuralNode } from "@getchomp/core";
|
|
17
|
+
import type { ChompStorage } from "@getchomp/db";
|
|
18
|
+
import { type ChompPlugin } from "./pluginRunner.js";
|
|
19
|
+
export declare const LOCAL_SHIMS_PLUGIN_NAME: "local-shims";
|
|
20
|
+
export declare const LOCAL_SHIMS_FILE_REL: ".chomp/plugins/local-shims/shims.json";
|
|
21
|
+
export declare const LEGACY_LOCAL_SHIMS_FILE_REL: ".chomp/shims.json";
|
|
22
|
+
export interface LocalTargetConnectorSpec {
|
|
23
|
+
/** Display name of the open connector (e.g. `HTTP Call: POST /v1/charges` or `Queue: billing-events`). */
|
|
24
|
+
name: string;
|
|
25
|
+
/** Open connector entityType (`HTTP_FETCH`, `DB_QUERY`, `MESSAGE_PUBLISH`, `EXTERNAL_SDK_CALL`, `EXTERNAL_PACKAGE`). */
|
|
26
|
+
entityType?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface LocalGraphShimInput {
|
|
29
|
+
/** Optional stable ID; auto-derived deterministically when omitted. */
|
|
30
|
+
id?: string;
|
|
31
|
+
/** Exact source entity ID (`nodes.id`). */
|
|
32
|
+
sourceId?: string;
|
|
33
|
+
/** Source node name or stripped label (e.g. `checkout` or `Exported Function: checkout`). */
|
|
34
|
+
sourceName?: string;
|
|
35
|
+
/** Optional repo-relative file path filter disambiguating `sourceName` (e.g. `src/checkout.ts`). */
|
|
36
|
+
sourceFile?: string;
|
|
37
|
+
/** Optional unresolved call name on the source contract (e.g. `container.resolve` or `Call: container.resolve()`). */
|
|
38
|
+
callName?: string;
|
|
39
|
+
/** Optional unresolved call shapeKey filter (e.g. `sk1/CALL/LocalVar/PropertyAccessExpression`). */
|
|
40
|
+
shapeKey?: string;
|
|
41
|
+
/** Exact target entity ID (`nodes.id`). */
|
|
42
|
+
targetId?: string;
|
|
43
|
+
/** Target node name or stripped label (e.g. `chargeCard` or `Public Method: StripeGateway.charge`). */
|
|
44
|
+
targetName?: string;
|
|
45
|
+
/** Optional repo-relative file path filter disambiguating `targetName`. */
|
|
46
|
+
targetFile?: string;
|
|
47
|
+
/** Target open connector descriptor (reuses matching OPEN_CONNECTOR or creates an `L1_SHIMS` synthetic connector). */
|
|
48
|
+
targetConnector?: LocalTargetConnectorSpec;
|
|
49
|
+
/** Relationship entityType (defaults to `CALL`). */
|
|
50
|
+
entityType?: string;
|
|
51
|
+
/** Optional custom relationship display name. */
|
|
52
|
+
edgeName?: string;
|
|
53
|
+
/** Short adapter label shown in the station card header strip (`[PAT-VIS-37]`, e.g. `Billing OpenAPI`). */
|
|
54
|
+
label?: string;
|
|
55
|
+
/** Human/agent rationale explaining why this runtime/dynamic link exists. */
|
|
56
|
+
rationale?: string;
|
|
57
|
+
/** Defaults to `true`. Set `false` to temporarily disable a shim without deleting it. */
|
|
58
|
+
enabled?: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface LocalGraphShim extends LocalGraphShimInput {
|
|
61
|
+
id: string;
|
|
62
|
+
origin?: "shims.json" | "chomp.config.json";
|
|
63
|
+
}
|
|
64
|
+
export interface LocalShimsManifest {
|
|
65
|
+
version: 1;
|
|
66
|
+
shims: LocalGraphShimInput[];
|
|
67
|
+
}
|
|
68
|
+
export interface ResolvedShimRecord {
|
|
69
|
+
shim: LocalGraphShim;
|
|
70
|
+
sourceNode: StructuralNode;
|
|
71
|
+
targetNode: StructuralNode;
|
|
72
|
+
syntheticConnector?: StructuralNode;
|
|
73
|
+
resolvedEdgeIds: string[];
|
|
74
|
+
edgeEntry: ShimmedEdgeOverlayEntry;
|
|
75
|
+
packageId: string | undefined;
|
|
76
|
+
}
|
|
77
|
+
export interface UnmatchedShimRecord {
|
|
78
|
+
shim: LocalGraphShim;
|
|
79
|
+
reason: string;
|
|
80
|
+
packageId?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface SuggestedShimCandidate {
|
|
83
|
+
suggestedShim: LocalGraphShimInput;
|
|
84
|
+
sourceNode: {
|
|
85
|
+
id: string;
|
|
86
|
+
name: string;
|
|
87
|
+
entityType: string;
|
|
88
|
+
packageName?: string;
|
|
89
|
+
filePath?: string;
|
|
90
|
+
lineNumber?: number;
|
|
91
|
+
};
|
|
92
|
+
unresolvedCall: {
|
|
93
|
+
name: string;
|
|
94
|
+
shapeKey?: string;
|
|
95
|
+
resolutionClass?: string;
|
|
96
|
+
reason: string;
|
|
97
|
+
snippet?: string;
|
|
98
|
+
};
|
|
99
|
+
candidateTargets: Array<{
|
|
100
|
+
id: string;
|
|
101
|
+
name: string;
|
|
102
|
+
entityType: string;
|
|
103
|
+
packageName?: string;
|
|
104
|
+
filePath?: string;
|
|
105
|
+
}>;
|
|
106
|
+
guidance: string;
|
|
107
|
+
}
|
|
108
|
+
export declare function deriveShimId(input: LocalGraphShimInput): string;
|
|
109
|
+
export declare function loadLocalShimsFromTexts(shimsJsonText: string | null, chompConfigText: string | null): {
|
|
110
|
+
shims: LocalGraphShim[];
|
|
111
|
+
parseErrors: string[];
|
|
112
|
+
};
|
|
113
|
+
export declare function evaluateShimsAgainstGraph(graph: RepresentationGraph, shims: readonly LocalGraphShim[]): {
|
|
114
|
+
resolved: ResolvedShimRecord[];
|
|
115
|
+
unmatched: UnmatchedShimRecord[];
|
|
116
|
+
owningDuByNodeId: Map<string, StructuralNode>;
|
|
117
|
+
};
|
|
118
|
+
export declare const localShimsPlugin: ChompPlugin;
|
|
119
|
+
export type LocalShimsAction = "status" | "suggest" | "validate" | "upsert" | "remove" | "run";
|
|
120
|
+
export interface ManageLocalShimsOptions {
|
|
121
|
+
action?: LocalShimsAction;
|
|
122
|
+
repoPath: string;
|
|
123
|
+
repoId?: string;
|
|
124
|
+
repoName?: string;
|
|
125
|
+
storage?: ChompStorage;
|
|
126
|
+
graph: RepresentationGraph;
|
|
127
|
+
shims?: LocalGraphShimInput[];
|
|
128
|
+
shimIds?: string[];
|
|
129
|
+
clearAll?: boolean;
|
|
130
|
+
packageName?: string;
|
|
131
|
+
/** Opt-in to inspect runtime parameter/local dynamic boundaries (`DYNAMIC_BOUNDARY`) in `suggest`. Default: `false`. */
|
|
132
|
+
includeDynamic?: boolean;
|
|
133
|
+
}
|
|
134
|
+
export declare function manageLocalShims(options: ManageLocalShimsOptions): Promise<Record<string, unknown>>;
|