@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
package/README.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@getchomp/mcp`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Model Context Protocol (`MCP`) architectural intelligence server for [Chomp](https://getchomp.dev).
|
|
4
|
+
|
|
5
|
+
Exposes live codebase map queries, pre-edit blast-radius analysis, structural diffs, boundary checks, redundancy detection, health audits, Bridges (`chomp_local_shims`), and Design System checks (`chomp_audit_design_system`, `chomp_diff_design_system`) to Cursor, Claude Code, Kiro, Windsurf, and Antigravity.
|
|
6
|
+
|
|
7
|
+
## Quick Start
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g @getchomp/cli
|
|
11
|
+
chomp init
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Documentation
|
|
15
|
+
|
|
16
|
+
See [https://getchomp.dev/docs](https://getchomp.dev/docs).
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/mcp/src/conventionsReference.ts
|
|
3
|
+
*
|
|
4
|
+
* Pure MCP Reference & Paved-Road Convention Discovery (`chomp_get_conventions`)
|
|
5
|
+
* Enforces [PAT-EXT-28], [PAT-MCP-08], [PAT-MCP-09].
|
|
6
|
+
*
|
|
7
|
+
* Exposes Chomp's built-in framework convention catalog (`CONVENTION_SETS`),
|
|
8
|
+
* active repository conventions (`chomp.config.json#conventions` + `validateConventionSet`),
|
|
9
|
+
* signal-to-matcher remediation playbooks (`UNRESOLVED_CALL`, `ORPHAN_CONTRACT`, `OPAQUE_BODY`, `DARK_FILE`),
|
|
10
|
+
* and the complete `NodeMatcher` / `EdgeMatcher` / `EmitTemplate` schema (`describeConventionSchema`).
|
|
11
|
+
*
|
|
12
|
+
* Note: Intentionally a pure MCP reference tool for coding agents — NOT a HUD plugin.
|
|
13
|
+
*/
|
|
14
|
+
import { type ConventionCatalogRow, type ConventionSchemaReference } from "@getchomp/core";
|
|
15
|
+
export type ConventionSignalKind = "UNRESOLVED_CALL" | "ORPHAN_CONTRACT" | "OPAQUE_BODY" | "DARK_FILE";
|
|
16
|
+
export interface GetConventionsReferenceOptions {
|
|
17
|
+
repoPath: string;
|
|
18
|
+
framework?: string;
|
|
19
|
+
entityType?: string;
|
|
20
|
+
signalKind?: ConventionSignalKind;
|
|
21
|
+
shapeKey?: string;
|
|
22
|
+
searchTerm?: string;
|
|
23
|
+
includeSchema?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface UserConventionSetStatus {
|
|
26
|
+
framework: string;
|
|
27
|
+
ruleCount: number;
|
|
28
|
+
edgeRuleCount: number;
|
|
29
|
+
fileRoleCount: number;
|
|
30
|
+
validationProblems: string[];
|
|
31
|
+
rules: ConventionCatalogRow[];
|
|
32
|
+
}
|
|
33
|
+
export interface BuiltInFrameworkCatalog {
|
|
34
|
+
framework: string;
|
|
35
|
+
installedInRepo: boolean;
|
|
36
|
+
totalRules: number;
|
|
37
|
+
rules: ConventionCatalogRow[];
|
|
38
|
+
}
|
|
39
|
+
export interface SignalRemediationPlaybookEntry {
|
|
40
|
+
signalKind: ConventionSignalKind;
|
|
41
|
+
meaning: string;
|
|
42
|
+
pavedRoadAdvice: string;
|
|
43
|
+
recommendedNodeMatchers: string[];
|
|
44
|
+
recommendedEdgeMatchers: string[];
|
|
45
|
+
whenToUseLocalShimsInstead: string;
|
|
46
|
+
}
|
|
47
|
+
export interface ShapeKeyRemediationAdvice {
|
|
48
|
+
shapeKey: string;
|
|
49
|
+
edgeKind: string | null;
|
|
50
|
+
receiverKind: string | null;
|
|
51
|
+
calleeSyntax: string | null;
|
|
52
|
+
recommendedApproach: "BUILT_IN_ALIGNMENT" | "CHOMP_CONFIG_CONVENTION" | "LOCAL_SHIM";
|
|
53
|
+
guidance: string;
|
|
54
|
+
suggestedMatchers: string[];
|
|
55
|
+
}
|
|
56
|
+
export interface ConventionsReferenceReport {
|
|
57
|
+
summary: {
|
|
58
|
+
builtInFrameworkCount: number;
|
|
59
|
+
builtInRuleCount: number;
|
|
60
|
+
matchedBuiltInRuleCount: number;
|
|
61
|
+
activeUserConventionSetCount: number;
|
|
62
|
+
activeUserRuleCount: number;
|
|
63
|
+
userValidationErrorCount: number;
|
|
64
|
+
hasChompConfig: boolean;
|
|
65
|
+
detectedFrameworks: string[];
|
|
66
|
+
};
|
|
67
|
+
decisionGuide: {
|
|
68
|
+
preferBuiltInConventions: string;
|
|
69
|
+
whenToAuthorChompConfigConventions: string;
|
|
70
|
+
whenToUseChompLocalShims: string;
|
|
71
|
+
verificationWorkflow: string[];
|
|
72
|
+
};
|
|
73
|
+
activeUserConventions: {
|
|
74
|
+
configPath: string;
|
|
75
|
+
exists: boolean;
|
|
76
|
+
parseError: string | null;
|
|
77
|
+
sets: UserConventionSetStatus[];
|
|
78
|
+
};
|
|
79
|
+
builtInConventions: BuiltInFrameworkCatalog[];
|
|
80
|
+
signalPlaybook: SignalRemediationPlaybookEntry[];
|
|
81
|
+
shapeKeyAdvice?: ShapeKeyRemediationAdvice;
|
|
82
|
+
schemaReference?: ConventionSchemaReference;
|
|
83
|
+
}
|
|
84
|
+
export declare function getConventionsReference(options: GetConventionsReferenceOptions): ConventionsReferenceReport;
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/mcp/src/conventionsReference.ts
|
|
3
|
+
*
|
|
4
|
+
* Pure MCP Reference & Paved-Road Convention Discovery (`chomp_get_conventions`)
|
|
5
|
+
* Enforces [PAT-EXT-28], [PAT-MCP-08], [PAT-MCP-09].
|
|
6
|
+
*
|
|
7
|
+
* Exposes Chomp's built-in framework convention catalog (`CONVENTION_SETS`),
|
|
8
|
+
* active repository conventions (`chomp.config.json#conventions` + `validateConventionSet`),
|
|
9
|
+
* signal-to-matcher remediation playbooks (`UNRESOLVED_CALL`, `ORPHAN_CONTRACT`, `OPAQUE_BODY`, `DARK_FILE`),
|
|
10
|
+
* and the complete `NodeMatcher` / `EdgeMatcher` / `EmitTemplate` schema (`describeConventionSchema`).
|
|
11
|
+
*
|
|
12
|
+
* Note: Intentionally a pure MCP reference tool for coding agents — NOT a HUD plugin.
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
15
|
+
import { join, resolve } from "node:path";
|
|
16
|
+
import { CONVENTION_SETS, describeConventionSchema, describeConventions, loadUserConventionSets, validateConventionSet, } from "@getchomp/core";
|
|
17
|
+
const FRAMEWORK_DEP_MAP = {
|
|
18
|
+
nextjs: ["next"],
|
|
19
|
+
react: ["react", "react-dom"],
|
|
20
|
+
express: ["express"],
|
|
21
|
+
mcp: ["@modelcontextprotocol/sdk"],
|
|
22
|
+
drizzle: ["drizzle-orm"],
|
|
23
|
+
payload: ["payload", "@payloadcms/next"],
|
|
24
|
+
};
|
|
25
|
+
const SIGNAL_PLAYBOOK = [
|
|
26
|
+
{
|
|
27
|
+
signalKind: "UNRESOLVED_CALL",
|
|
28
|
+
meaning: "A non-builtin call inside a contract or INIT_BLOCK has no resolved targetId (`? N unresolved`), leaving downstream side effects invisible on the map.",
|
|
29
|
+
pavedRoadAdvice: "Prefer direct imports or known client receivers for external calls. If your repo uses a consistent custom broker/SDK/HTTP wrapper (e.g. `eventBus.publish('topic')`, `rpcClient.invoke(...)`), add a `callToMember` or `callToIdentifier` -> `OPEN_CONNECTOR` rule in `chomp.config.json#conventions`.",
|
|
30
|
+
recommendedNodeMatchers: [
|
|
31
|
+
"callToMember",
|
|
32
|
+
"callToIdentifier",
|
|
33
|
+
"callToMemberChain",
|
|
34
|
+
"callChainRootedAt",
|
|
35
|
+
"newIdentifier",
|
|
36
|
+
],
|
|
37
|
+
recommendedEdgeMatchers: ["callRouteTargets", "callRegistrationTargets"],
|
|
38
|
+
whenToUseLocalShimsInstead: "Use `chomp_local_shims` (`.chomp/shims.json`) when the target depends on runtime DI tokens (`container.resolve(TOKEN)`), reflection, or dynamic lookup tables that have no static AST target.",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
signalKind: "ORPHAN_CONTRACT",
|
|
42
|
+
meaning: "An extracted contract has `inDegree === 0` (no incoming edge from any INGRESS route, component, CLI command, or INIT_BLOCK).",
|
|
43
|
+
pavedRoadAdvice: "If handlers are registered through a custom router, RPC builder, or plugin registry (`rpcRouter.query('/x', handler)`), add an `edgeRules` entry (`callRouteTargets` or `callRegistrationTargets`) in `chomp.config.json#conventions` to link the registration site to `importedComponent` / `sameFileExport`.",
|
|
44
|
+
recommendedNodeMatchers: [
|
|
45
|
+
"exportedWrappedFunction",
|
|
46
|
+
"callToMember",
|
|
47
|
+
"exportedConstObject",
|
|
48
|
+
],
|
|
49
|
+
recommendedEdgeMatchers: [
|
|
50
|
+
"callRouteTargets",
|
|
51
|
+
"callRegistrationTargets",
|
|
52
|
+
"jsxTag",
|
|
53
|
+
"jsxIdentifierAttribute",
|
|
54
|
+
],
|
|
55
|
+
whenToUseLocalShimsInstead: "Use `chomp_local_shims` when handlers are wired via config strings, reflection, or external framework bootstrap files outside TypeScript AST reach.",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
signalKind: "OPAQUE_BODY",
|
|
59
|
+
meaning: "A contract makes AST calls (`astCallCount > 0`) but produces `0` resolved outgoing edges (`resolvedOutDegree === 0`), acting as a silent black box in story flows.",
|
|
60
|
+
pavedRoadAdvice: "Inspect the helper or wrapper indirection inside the contract body. Either pass typed dependencies / standard client calls directly, declare custom client methods as `OPEN_CONNECTOR` conventions in `chomp.config.json#conventions`, or bridge dynamic dispatch via `chomp_local_shims`.",
|
|
61
|
+
recommendedNodeMatchers: ["callToMember", "callToIdentifier", "callToMemberChain"],
|
|
62
|
+
recommendedEdgeMatchers: ["callRouteTargets", "callRegistrationTargets"],
|
|
63
|
+
whenToUseLocalShimsInstead: "Use `chomp_local_shims` (`action: 'suggest'`) to inspect the exact unresolved call sites inside the opaque contract and wire runtime targets cleanly at Layer 1.",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
signalKind: "DARK_FILE",
|
|
67
|
+
meaning: "A TypeScript/JavaScript source file yielded `0` extracted Contracts and `0` INIT_BLOCK relationships — typically caused by an unrecognized HOF wrapper or custom file convention.",
|
|
68
|
+
pavedRoadAdvice: "Check how the file exports or registers its units. Declare `fileRoles` (if path-based) and `exportedWrappedFunction`, `exportedConstCall`, `defaultExportWrapped`, or `callToMember` -> `CONTRACT` rules in `chomp.config.json#conventions`.",
|
|
69
|
+
recommendedNodeMatchers: [
|
|
70
|
+
"exportedFunction",
|
|
71
|
+
"exportedWrappedFunction",
|
|
72
|
+
"exportedConstCall",
|
|
73
|
+
"exportedConstObject",
|
|
74
|
+
"defaultExportCall",
|
|
75
|
+
"defaultExportWrapped",
|
|
76
|
+
],
|
|
77
|
+
recommendedEdgeMatchers: ["callRouteTargets", "callRegistrationTargets"],
|
|
78
|
+
whenToUseLocalShimsInstead: "Dark files have `0` Layer 0 contracts to attach shims to — always solve `DARK_FILE` with paved-road exports or `chomp.config.json#conventions` `CONTRACT` rules first.",
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
function collectInstalledDepNames(repoPath) {
|
|
82
|
+
const deps = new Set();
|
|
83
|
+
const readPkgJson = (pkgJsonPath) => {
|
|
84
|
+
try {
|
|
85
|
+
if (!existsSync(pkgJsonPath))
|
|
86
|
+
return;
|
|
87
|
+
const raw = JSON.parse(readFileSync(pkgJsonPath, "utf8"));
|
|
88
|
+
for (const field of ["dependencies", "devDependencies", "peerDependencies"]) {
|
|
89
|
+
const sec = raw[field];
|
|
90
|
+
if (sec && typeof sec === "object") {
|
|
91
|
+
for (const k of Object.keys(sec)) {
|
|
92
|
+
deps.add(k);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// Ignore malformed package.json
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
readPkgJson(join(repoPath, "package.json"));
|
|
102
|
+
for (const subDir of ["packages", "apps"]) {
|
|
103
|
+
const absSub = join(repoPath, subDir);
|
|
104
|
+
try {
|
|
105
|
+
if (!existsSync(absSub))
|
|
106
|
+
continue;
|
|
107
|
+
for (const entry of readdirSync(absSub, { withFileTypes: true })) {
|
|
108
|
+
if (entry.isDirectory()) {
|
|
109
|
+
readPkgJson(join(absSub, entry.name, "package.json"));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// Ignore unreadable workspace directories
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return deps;
|
|
118
|
+
}
|
|
119
|
+
function matchesSignalFilter(row, signalKind) {
|
|
120
|
+
switch (signalKind) {
|
|
121
|
+
case "UNRESOLVED_CALL":
|
|
122
|
+
case "OPAQUE_BODY":
|
|
123
|
+
return row.produces.type === "OPEN_CONNECTOR" || row.produces.type === "RELATIONSHIP";
|
|
124
|
+
case "ORPHAN_CONTRACT":
|
|
125
|
+
return row.produces.type === "RELATIONSHIP" || row.produces.type === "CONTRACT";
|
|
126
|
+
case "DARK_FILE":
|
|
127
|
+
return row.produces.type === "CONTRACT";
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function buildShapeKeyAdvice(shapeKey) {
|
|
131
|
+
const trimmed = shapeKey.trim();
|
|
132
|
+
const parts = trimmed.split("/");
|
|
133
|
+
// Expected format: sk1/<EDGE_KIND>/<RECEIVER_CLASS>/<CALLEE_SYNTAX>...
|
|
134
|
+
const hasPrefix = parts[0] === "sk1";
|
|
135
|
+
const edgeKind = hasPrefix ? (parts[1] ?? null) : null;
|
|
136
|
+
const receiverKind = hasPrefix ? (parts[2] ?? null) : null;
|
|
137
|
+
const calleeSyntax = hasPrefix ? (parts.slice(3).join("/") || null) : null;
|
|
138
|
+
const lower = trimmed.toLowerCase();
|
|
139
|
+
if (lower.includes("elementaccess") ||
|
|
140
|
+
lower.includes("dynamic") ||
|
|
141
|
+
lower.includes("computed") ||
|
|
142
|
+
lower.includes("param")) {
|
|
143
|
+
return {
|
|
144
|
+
shapeKey: trimmed,
|
|
145
|
+
edgeKind,
|
|
146
|
+
receiverKind,
|
|
147
|
+
calleeSyntax,
|
|
148
|
+
recommendedApproach: "LOCAL_SHIM",
|
|
149
|
+
guidance: "This call shape dispatches through a parameter, computed property, or dynamic runtime value (`DYNAMIC_BOUNDARY`). Static AST rules should not guess runtime values — use `chomp_local_shims` (`action: 'suggest'` -> `action: 'upsert'`) to record an explicit `L1_SHIMS` bridge.",
|
|
150
|
+
suggestedMatchers: [],
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
if (calleeSyntax?.includes("PropertyAccessExpression")) {
|
|
154
|
+
return {
|
|
155
|
+
shapeKey: trimmed,
|
|
156
|
+
edgeKind,
|
|
157
|
+
receiverKind,
|
|
158
|
+
calleeSyntax,
|
|
159
|
+
recommendedApproach: "CHOMP_CONFIG_CONVENTION",
|
|
160
|
+
guidance: "Member-call syntax (`receiver.method(...)`). If this calls a consistent custom client/broker/router across the repo, add `callToMember` (for `OPEN_CONNECTOR` / `CONTRACT`) or `callRouteTargets` / `callRegistrationTargets` (for handler `edgeRules`) in `chomp.config.json#conventions`. If `receiver` is a runtime DI container (`container.resolve`), use `chomp_local_shims` instead.",
|
|
161
|
+
suggestedMatchers: [
|
|
162
|
+
"callToMember",
|
|
163
|
+
"callToMemberChain",
|
|
164
|
+
"callRouteTargets",
|
|
165
|
+
"callRegistrationTargets",
|
|
166
|
+
],
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
if (calleeSyntax?.includes("Identifier")) {
|
|
170
|
+
return {
|
|
171
|
+
shapeKey: trimmed,
|
|
172
|
+
edgeKind,
|
|
173
|
+
receiverKind,
|
|
174
|
+
calleeSyntax,
|
|
175
|
+
recommendedApproach: "CHOMP_CONFIG_CONVENTION",
|
|
176
|
+
guidance: "Direct identifier call (`fn(...)`). Verify the target is exported and imported via standard ES module paths (`BUILT_IN_ALIGNMENT`), or declare `callToIdentifier` / `exportedWrappedFunction` in `chomp.config.json#conventions` if `fn` is a custom DSL or external SDK helper.",
|
|
177
|
+
suggestedMatchers: ["callToIdentifier", "exportedWrappedFunction"],
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
shapeKey: trimmed,
|
|
182
|
+
edgeKind,
|
|
183
|
+
receiverKind,
|
|
184
|
+
calleeSyntax,
|
|
185
|
+
recommendedApproach: "BUILT_IN_ALIGNMENT",
|
|
186
|
+
guidance: "Inspect sample call sites via `chomp_audit_health` or `chomp_local_shims` (`action: 'suggest'`). Prefer aligning to built-in imports/exports first, `chomp.config.json#conventions` for repeatable AST idioms, or `chomp_local_shims` for one-off runtime/DI indirection.",
|
|
187
|
+
suggestedMatchers: ["callToMember", "callToIdentifier", "exportedWrappedFunction"],
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
export function getConventionsReference(options) {
|
|
191
|
+
const repoPath = resolve(options.repoPath);
|
|
192
|
+
const frameworkFilter = options.framework?.trim().toLowerCase();
|
|
193
|
+
const entityTypeFilter = options.entityType?.trim().toLowerCase();
|
|
194
|
+
const signalFilter = options.signalKind;
|
|
195
|
+
const searchFilter = options.searchTerm?.trim().toLowerCase();
|
|
196
|
+
const includeSchema = options.includeSchema ?? true;
|
|
197
|
+
const installedDeps = collectInstalledDepNames(repoPath);
|
|
198
|
+
const detectedFrameworks = ["core"];
|
|
199
|
+
for (const [fw, pkgNames] of Object.entries(FRAMEWORK_DEP_MAP)) {
|
|
200
|
+
if (pkgNames.some((pkg) => installedDeps.has(pkg))) {
|
|
201
|
+
detectedFrameworks.push(fw);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// Inspect repo's chomp.config.json#conventions
|
|
205
|
+
const configAbsPath = join(repoPath, "chomp.config.json");
|
|
206
|
+
const configExists = existsSync(configAbsPath);
|
|
207
|
+
let parseError = null;
|
|
208
|
+
if (configExists) {
|
|
209
|
+
try {
|
|
210
|
+
JSON.parse(readFileSync(configAbsPath, "utf8"));
|
|
211
|
+
}
|
|
212
|
+
catch (err) {
|
|
213
|
+
parseError = err instanceof Error ? err.message : String(err);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const loadedUserSets = parseError ? [] : loadUserConventionSets(repoPath);
|
|
217
|
+
const userSetStatuses = loadedUserSets.map((set) => ({
|
|
218
|
+
framework: set.framework,
|
|
219
|
+
ruleCount: set.rules.length,
|
|
220
|
+
edgeRuleCount: set.edgeRules?.length ?? 0,
|
|
221
|
+
fileRoleCount: set.fileRoles.length,
|
|
222
|
+
validationProblems: validateConventionSet(set),
|
|
223
|
+
rules: describeConventions(set),
|
|
224
|
+
}));
|
|
225
|
+
const activeUserRuleCount = userSetStatuses.reduce((sum, s) => sum + s.ruleCount + s.edgeRuleCount, 0);
|
|
226
|
+
const userValidationErrorCount = userSetStatuses.reduce((sum, s) => sum + s.validationProblems.length, 0);
|
|
227
|
+
const filterRow = (row) => {
|
|
228
|
+
if (frameworkFilter && row.framework.toLowerCase() !== frameworkFilter) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
if (entityTypeFilter &&
|
|
232
|
+
row.produces.entityType.toLowerCase() !== entityTypeFilter &&
|
|
233
|
+
row.produces.type.toLowerCase() !== entityTypeFilter) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
if (signalFilter && !matchesSignalFilter(row, signalFilter)) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
if (searchFilter) {
|
|
240
|
+
const haystack = [
|
|
241
|
+
row.id,
|
|
242
|
+
row.framework,
|
|
243
|
+
row.description,
|
|
244
|
+
row.produces.type,
|
|
245
|
+
row.produces.entityType,
|
|
246
|
+
row.produces.patternId,
|
|
247
|
+
row.specRef ?? "",
|
|
248
|
+
...(row.roles ?? []),
|
|
249
|
+
]
|
|
250
|
+
.join(" ")
|
|
251
|
+
.toLowerCase();
|
|
252
|
+
if (!haystack.includes(searchFilter)) {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return true;
|
|
257
|
+
};
|
|
258
|
+
let totalBuiltInRules = 0;
|
|
259
|
+
let matchedBuiltInRules = 0;
|
|
260
|
+
const builtInConventions = [];
|
|
261
|
+
for (const set of CONVENTION_SETS) {
|
|
262
|
+
const allRows = describeConventions(set);
|
|
263
|
+
totalBuiltInRules += allRows.length;
|
|
264
|
+
const filtered = allRows.filter(filterRow);
|
|
265
|
+
if (filtered.length === 0 && (frameworkFilter || entityTypeFilter || signalFilter || searchFilter)) {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
matchedBuiltInRules += filtered.length;
|
|
269
|
+
builtInConventions.push({
|
|
270
|
+
framework: set.framework,
|
|
271
|
+
installedInRepo: detectedFrameworks.includes(set.framework),
|
|
272
|
+
totalRules: allRows.length,
|
|
273
|
+
rules: filtered,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
const playbook = signalFilter
|
|
277
|
+
? SIGNAL_PLAYBOOK.filter((entry) => entry.signalKind === signalFilter)
|
|
278
|
+
: [...SIGNAL_PLAYBOOK];
|
|
279
|
+
return {
|
|
280
|
+
summary: {
|
|
281
|
+
builtInFrameworkCount: CONVENTION_SETS.length,
|
|
282
|
+
builtInRuleCount: totalBuiltInRules,
|
|
283
|
+
matchedBuiltInRuleCount: matchedBuiltInRules,
|
|
284
|
+
activeUserConventionSetCount: userSetStatuses.length,
|
|
285
|
+
activeUserRuleCount,
|
|
286
|
+
userValidationErrorCount,
|
|
287
|
+
hasChompConfig: configExists,
|
|
288
|
+
detectedFrameworks,
|
|
289
|
+
},
|
|
290
|
+
decisionGuide: {
|
|
291
|
+
preferBuiltInConventions: "When authoring new routes, components, handlers, or data access, align to the built-in Paved-Road conventions below so Chomp extracts 100% deterministic Layer 0 edges with zero configuration.",
|
|
292
|
+
whenToAuthorChompConfigConventions: "When a repository uses a repeatable syntactic convention (custom HOF wrapper, RPC router, internal SDK/event-bus client) across multiple files, declare a `ConventionSet` under `chomp.config.json#conventions` using `schemaReference` below, then re-run `chomp analyze` and verify via `chomp_get_diff`.",
|
|
293
|
+
whenToUseChompLocalShims: "When a call target is determined purely at runtime (DI container tokens, reflection, dynamic plugin registries) and cannot be derived from AST syntax, keep Layer 0 honest and invoke `chomp_local_shims` (`action: 'suggest'` / `'upsert'`) to bridge it as an explicit `L1_SHIMS` plugin overlay.",
|
|
294
|
+
verificationWorkflow: [
|
|
295
|
+
"1. Inspect conventions & matchers with `chomp_get_conventions`.",
|
|
296
|
+
"2. Edit code or update `chomp.config.json#conventions` (confirm `userValidationErrorCount === 0` by re-calling `chomp_get_conventions`).",
|
|
297
|
+
"3. Run `chomp_get_diff` to verify newly extracted deterministic contracts/edges before committing.",
|
|
298
|
+
],
|
|
299
|
+
},
|
|
300
|
+
activeUserConventions: {
|
|
301
|
+
configPath: "chomp.config.json",
|
|
302
|
+
exists: configExists,
|
|
303
|
+
parseError,
|
|
304
|
+
sets: userSetStatuses,
|
|
305
|
+
},
|
|
306
|
+
builtInConventions,
|
|
307
|
+
signalPlaybook: playbook,
|
|
308
|
+
...(options.shapeKey?.trim()
|
|
309
|
+
? { shapeKeyAdvice: buildShapeKeyAdvice(options.shapeKey) }
|
|
310
|
+
: {}),
|
|
311
|
+
...(includeSchema ? { schemaReference: describeConventionSchema() } : {}),
|
|
312
|
+
};
|
|
313
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/mcp/src/designSystem/astScanner.ts
|
|
3
|
+
*
|
|
4
|
+
* Single-pass TypeScript/TSX AST scanner for component styling conventions, Tailwind v4 utilities,
|
|
5
|
+
* magic spacing steps, intra-function className variable dataflow, JSX skeletons, prop contracts,
|
|
6
|
+
* ancestor-propagated Tailwind color pairs, nested interactive checks, stateful UI shapes, and
|
|
7
|
+
* canvas slot-recorder provenance (including local variable binding attribution).
|
|
8
|
+
*/
|
|
9
|
+
import { type AtomDefinition } from "./config.js";
|
|
10
|
+
import type { TailwindClassPairCandidate } from "./contrast.js";
|
|
11
|
+
import type { ArbitraryTailwindOccurrence, CanvasLiteralOccurrence, ComponentPropSignature, InlineStyleLiteralOccurrence, InvariantViolation, JsxCallSiteRecord, JsxSkeletonOccurrence, MagicSpacingOccurrence, NestedInteractiveFinding, PrimitiveScaleSkipOccurrence, RawDomPrimitiveOccurrence, StylingConvention, TokenReferenceOccurrence } from "./types.js";
|
|
12
|
+
import { type LiteralValueOccurrence } from "./valueClusters.js";
|
|
13
|
+
export declare function isTailwindUtilityToken(token: string): boolean;
|
|
14
|
+
export declare const ARBITRARY_TW_RE: RegExp;
|
|
15
|
+
export declare const TAILWIND_DEFAULT_PALETTES: Set<string>;
|
|
16
|
+
export interface ScanOptions {
|
|
17
|
+
/** Class names defined in the repo's own stylesheets (derived; replaces any hardcoded prefix). */
|
|
18
|
+
knownCssClasses?: ReadonlySet<string>;
|
|
19
|
+
/** Extra class-name prefixes that always count as stylesheet classes. */
|
|
20
|
+
cssClassPrefixes?: readonly string[];
|
|
21
|
+
/** Atom catalog used to detect raw DOM elements that should be shared atoms. */
|
|
22
|
+
atomDefinitions?: readonly AtomDefinition[];
|
|
23
|
+
/** Regex source: props matching it must not receive raw color literals. */
|
|
24
|
+
colorPropPattern?: string;
|
|
25
|
+
/** Factory function names that create a canvas slot recorder. Empty = no canvas-slot provenance. */
|
|
26
|
+
canvasSlotRecorderFactories?: readonly string[];
|
|
27
|
+
/** Helper names whose call result is a token-sourced canvas value (counted as "css" slots). */
|
|
28
|
+
canvasCssValueHelpers?: readonly string[];
|
|
29
|
+
/** Helper names whose first string-literal `--token` argument reads a CSS token onto canvas. */
|
|
30
|
+
canvasTokenReaderHelpers?: readonly string[];
|
|
31
|
+
/** Color utility slugs explicitly backed by repo CSS `@theme` / token declarations. */
|
|
32
|
+
knownThemeColorSlugs?: ReadonlySet<string>;
|
|
33
|
+
/** Typography size slugs defined as `@theme --text-<slug>` without color backing. */
|
|
34
|
+
nonColorThemeTextSlugs?: ReadonlySet<string>;
|
|
35
|
+
/** Spacing numeric steps explicitly defined as custom `--spacing-<N>` tokens. */
|
|
36
|
+
knownThemeSpacingSteps?: ReadonlySet<string>;
|
|
37
|
+
}
|
|
38
|
+
export interface ElementStyleSnapshot {
|
|
39
|
+
tag: string;
|
|
40
|
+
role?: string;
|
|
41
|
+
isRootElement: boolean;
|
|
42
|
+
classes: string[];
|
|
43
|
+
inlineStyle: Record<string, string>;
|
|
44
|
+
lineNumber: number;
|
|
45
|
+
snippet: string;
|
|
46
|
+
}
|
|
47
|
+
export interface TailwindTypographyUsageGroup {
|
|
48
|
+
classes: string[];
|
|
49
|
+
filePath: string;
|
|
50
|
+
lineNumber: number;
|
|
51
|
+
snippet: string;
|
|
52
|
+
}
|
|
53
|
+
export interface RawUiShapeCandidate {
|
|
54
|
+
shapeKind: "Tabs" | "SegmentedControl" | "BadgePill";
|
|
55
|
+
filePath: string;
|
|
56
|
+
lineNumber: number;
|
|
57
|
+
snippet: string;
|
|
58
|
+
/** File character start offsets of inner raw buttons absorbed into Tabs/SegmentedControl. */
|
|
59
|
+
absorbedButtonStarts: number[];
|
|
60
|
+
/** Variant count (number of explicit tabs/options, or undefined when `.map()`). */
|
|
61
|
+
variantCount?: number;
|
|
62
|
+
containerClasses: string[];
|
|
63
|
+
itemClasses: string[];
|
|
64
|
+
inlineStyle: Record<string, string>;
|
|
65
|
+
}
|
|
66
|
+
export interface ScannedComponentBucket {
|
|
67
|
+
name: string;
|
|
68
|
+
lineNumber: number;
|
|
69
|
+
endLineNumber: number;
|
|
70
|
+
isExported: boolean;
|
|
71
|
+
jsxDomElementCount: number;
|
|
72
|
+
jsxCustomComponentCount: number;
|
|
73
|
+
stateHookCount: number;
|
|
74
|
+
propContract: ComponentPropSignature[];
|
|
75
|
+
jsxCallSites: JsxCallSiteRecord[];
|
|
76
|
+
jsxSkeletons: JsxSkeletonOccurrence[];
|
|
77
|
+
stylingConventions: Set<StylingConvention>;
|
|
78
|
+
cssClassesUsed: Set<string>;
|
|
79
|
+
cssClassOccurrences: Array<{
|
|
80
|
+
className: string;
|
|
81
|
+
lineNumber: number;
|
|
82
|
+
snippet: string;
|
|
83
|
+
}>;
|
|
84
|
+
dynamicClassPrefixes: Set<string>;
|
|
85
|
+
tokensConsumed: Set<string>;
|
|
86
|
+
arbitraryTailwind: ArbitraryTailwindOccurrence[];
|
|
87
|
+
magicSpacingUtilities: MagicSpacingOccurrence[];
|
|
88
|
+
primitiveScaleSkips: PrimitiveScaleSkipOccurrence[];
|
|
89
|
+
inlineStyleLiterals: InlineStyleLiteralOccurrence[];
|
|
90
|
+
usesSlotRecorder: boolean;
|
|
91
|
+
canvasCssCount: number;
|
|
92
|
+
canvasTsConstCount: number;
|
|
93
|
+
canvasLiteralCount: number;
|
|
94
|
+
canvasLiterals: CanvasLiteralOccurrence[];
|
|
95
|
+
rawDomPrimitives: RawDomPrimitiveOccurrence[];
|
|
96
|
+
/** Parallel char offsets (`node.getStart(sf)`) aligned with `rawDomPrimitives`. */
|
|
97
|
+
rawDomOffsets: number[];
|
|
98
|
+
nestedInteractive: NestedInteractiveFinding[];
|
|
99
|
+
uiShapeCandidates: RawUiShapeCandidate[];
|
|
100
|
+
elementStyleSnapshots: ElementStyleSnapshot[];
|
|
101
|
+
tailwindTypographyGroups: TailwindTypographyUsageGroup[];
|
|
102
|
+
renderedComponents: Set<string>;
|
|
103
|
+
paletteClassCandidates: Array<{
|
|
104
|
+
className: string;
|
|
105
|
+
palette: string;
|
|
106
|
+
step: string;
|
|
107
|
+
filePath: string;
|
|
108
|
+
lineNumber: number;
|
|
109
|
+
snippet: string;
|
|
110
|
+
}>;
|
|
111
|
+
tsTokenRefs: TokenReferenceOccurrence[];
|
|
112
|
+
literalValues: LiteralValueOccurrence[];
|
|
113
|
+
domTags: Set<string>;
|
|
114
|
+
invariantViolations: InvariantViolation[];
|
|
115
|
+
tailwindUtilityCount: number;
|
|
116
|
+
tailwindClassesUsed: Array<{
|
|
117
|
+
className: string;
|
|
118
|
+
lineNumber: number;
|
|
119
|
+
snippet: string;
|
|
120
|
+
}>;
|
|
121
|
+
rootElement?: {
|
|
122
|
+
tag: string;
|
|
123
|
+
classes: string;
|
|
124
|
+
styleProps: Record<string, string>;
|
|
125
|
+
lineNumber: number;
|
|
126
|
+
snippet: string;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
export interface ScannedFileAstResult {
|
|
130
|
+
filePath: string;
|
|
131
|
+
definedFontVars: Array<{
|
|
132
|
+
name: string;
|
|
133
|
+
lineNumber: number;
|
|
134
|
+
scope?: "global" | "scoped";
|
|
135
|
+
fontFamily?: string;
|
|
136
|
+
}>;
|
|
137
|
+
tokenReferences: TokenReferenceOccurrence[];
|
|
138
|
+
cssImports: string[];
|
|
139
|
+
tailwindClassPairs: TailwindClassPairCandidate[];
|
|
140
|
+
importedModules: string[];
|
|
141
|
+
importedBindings: Map<string, {
|
|
142
|
+
specifier: string;
|
|
143
|
+
importedName: string;
|
|
144
|
+
}>;
|
|
145
|
+
reExports: Array<{
|
|
146
|
+
exportedName: string;
|
|
147
|
+
sourceName: string;
|
|
148
|
+
specifier: string;
|
|
149
|
+
}>;
|
|
150
|
+
variantAxes: Record<string, string[]>;
|
|
151
|
+
functionsAndClasses: Map<string, ScannedComponentBucket>;
|
|
152
|
+
}
|
|
153
|
+
export declare function scanTsxOrTsFile(filePath: string, sourceText: string, scanOptions?: ScanOptions): ScannedFileAstResult;
|