@dimassetoid/septum-mcp 0.0.0-stage → 0.2.1
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/LICENSE +21 -0
- package/README.md +124 -2
- package/bin/septum.ts +4 -0
- package/package.json +70 -4
- package/scripts/postinstall.ts +25 -0
- package/src/cli/commands/check.ts +122 -0
- package/src/cli/commands/hook.ts +268 -0
- package/src/cli/commands/init.ts +553 -0
- package/src/cli/commands/serve.ts +5 -0
- package/src/cli/commands/sync.ts +41 -0
- package/src/cli/commands/topology.ts +161 -0
- package/src/cli/index.ts +167 -0
- package/src/cli/scaffold/harness-config.ts +621 -0
- package/src/cli/templates/hooks.ts +75 -0
- package/src/cli/templates/rules.ts +50 -0
- package/src/cli/templates/skill.ts +51 -0
- package/src/cli/ui/prompts.ts +122 -0
- package/src/core/boundary/evaluator.ts +442 -0
- package/src/core/boundary/staged-auditor.ts +58 -0
- package/src/core/config/loader.ts +122 -0
- package/src/core/config/schema.ts +69 -0
- package/src/core/database/client.ts +60 -0
- package/src/core/database/repositories/dependency.repository.ts +712 -0
- package/src/core/database/repositories/domain.repository.ts +330 -0
- package/src/core/database/repositories/environment.repository.ts +207 -0
- package/src/core/database/repositories/file.repository.ts +117 -0
- package/src/core/database/repositories/meta.repository.ts +33 -0
- package/src/core/database/repositories/symbol.repository.ts +508 -0
- package/src/core/database/repository.ts +303 -0
- package/src/core/database/schema.ts +154 -0
- package/src/core/discovery/topology-detector.ts +805 -0
- package/src/core/ingestion/hasher.ts +5 -0
- package/src/core/ingestion/pipeline.ts +623 -0
- package/src/core/parser/behavioral-analyzer.ts +119 -0
- package/src/core/parser/boundary-tracker.ts +443 -0
- package/src/core/parser/extractors/base.ts +67 -0
- package/src/core/parser/extractors/blade.ts +159 -0
- package/src/core/parser/extractors/csharp.ts +244 -0
- package/src/core/parser/extractors/django-semantic.ts +687 -0
- package/src/core/parser/extractors/elysia-semantic.ts +538 -0
- package/src/core/parser/extractors/express-semantic.ts +444 -0
- package/src/core/parser/extractors/fastapi-semantic.ts +736 -0
- package/src/core/parser/extractors/fastify-semantic.ts +774 -0
- package/src/core/parser/extractors/flask-semantic.ts +515 -0
- package/src/core/parser/extractors/frontend.ts +149 -0
- package/src/core/parser/extractors/go-semantic.ts +611 -0
- package/src/core/parser/extractors/go.ts +491 -0
- package/src/core/parser/extractors/hono-semantic.ts +567 -0
- package/src/core/parser/extractors/java.ts +225 -0
- package/src/core/parser/extractors/laravel-semantic.ts +1122 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +368 -0
- package/src/core/parser/extractors/nestjs-semantic.ts +543 -0
- package/src/core/parser/extractors/php.ts +569 -0
- package/src/core/parser/extractors/python.ts +498 -0
- package/src/core/parser/extractors/registry.ts +78 -0
- package/src/core/parser/extractors/ruby.ts +234 -0
- package/src/core/parser/extractors/rust.ts +286 -0
- package/src/core/parser/extractors/semantic-extractor.interface.ts +22 -0
- package/src/core/parser/extractors/symfony-semantic.ts +354 -0
- package/src/core/parser/extractors/typescript.ts +826 -0
- package/src/core/parser/language-capabilities.ts +71 -0
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +216 -0
- package/src/core/parser/schema/providers/prisma-schema-provider.ts +90 -0
- package/src/core/parser/schema/schema-provider-registry.ts +43 -0
- package/src/core/parser/schema/schema-provider.interface.ts +33 -0
- package/src/core/parser/tree-sitter.ts +63 -0
- package/src/core/parser/wasm-assets.ts +25 -0
- package/src/core/parser/wasm-loader.ts +274 -0
- package/src/core/resolver/call-graph-tracer.ts +724 -0
- package/src/core/resolver/import-resolver.ts +437 -0
- package/src/core/resolver/module-resolver.ts +482 -0
- package/src/core/resolver/path-resolver.ts +200 -0
- package/src/core/resolver/symbol-locator.ts +276 -0
- package/src/core/resolver/symbol-reference.ts +53 -0
- package/src/core/resolver/vertical-slice-tracer.ts +366 -0
- package/src/core/resources/ignore.ts +123 -0
- package/src/core/resources/limits.ts +14 -0
- package/src/core/resources/source-files.ts +62 -0
- package/src/core/resources/work-queue.ts +74 -0
- package/src/core/session/session-manager.ts +107 -0
- package/src/core/telemetry/telemetry.ts +97 -0
- package/src/core/topology/environment-detector.ts +973 -0
- package/src/core/topology/types.ts +83 -0
- package/src/index.ts +21 -0
- package/src/mcp/schemas.ts +1105 -0
- package/src/mcp/server.ts +774 -0
- package/src/mcp/tools/boundary.ts +17 -0
- package/src/mcp/tools/check-boundary.ts +387 -0
- package/src/mcp/tools/domain.ts +40 -0
- package/src/mcp/tools/feature.ts +67 -0
- package/src/mcp/tools/get-domain-catalog.ts +226 -0
- package/src/mcp/tools/get-environment-topology.ts +138 -0
- package/src/mcp/tools/get-feature-context.ts +224 -0
- package/src/mcp/tools/get-symbol-hotspots.ts +54 -0
- package/src/mcp/tools/get-symbol-impact.ts +64 -0
- package/src/mcp/tools/get-symbol.ts +175 -0
- package/src/mcp/tools/locate-symbol.ts +196 -0
- package/src/mcp/tools/register-domain.ts +75 -0
- package/src/mcp/tools/register-feature.ts +110 -0
- package/src/mcp/tools/slice.ts +16 -0
- package/src/mcp/tools/symbol.ts +93 -0
- package/src/mcp/tools/trace-vertical-slice.ts +80 -0
- package/src/mcp/workspace-manager.ts +159 -0
- package/src/mcp/workspace-watcher.ts +202 -0
- package/src/types/index.ts +456 -0
- package/src/types/wasm.d.ts +4 -0
- package/src/utils/version-check.ts +209 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import grammarPackage from "tree-sitter-wasms/package.json";
|
|
3
|
+
|
|
4
|
+
// Keep this revision aligned with ingestion invalidation; coverage is never implied by parse success.
|
|
5
|
+
export const PARSER_REVISION = "4";
|
|
6
|
+
|
|
7
|
+
type LanguageDefinition = {
|
|
8
|
+
id: string;
|
|
9
|
+
extensions: string[];
|
|
10
|
+
aliases: string[];
|
|
11
|
+
extractor: string | null;
|
|
12
|
+
method: "tree-sitter" | "template-scanner" | "embedded-script" | "unsupported";
|
|
13
|
+
grammar?: string;
|
|
14
|
+
grammarOverrides?: Record<string, string>;
|
|
15
|
+
limits: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const LANGUAGE_CAPABILITIES: readonly LanguageDefinition[] = [
|
|
19
|
+
{ id: "blade", extensions: [".blade.php"], aliases: [], extractor: "blade", method: "template-scanner", limits: "Literal directives/components only; no PHP or template syntax validation." },
|
|
20
|
+
{ id: "typescript", extensions: [".ts", ".tsx", ".mts", ".cts"], aliases: ["ts", "tsx"], extractor: "typescript", method: "tree-sitter", grammar: "typescript", grammarOverrides: { ".tsx": "tsx", tsx: "tsx" }, limits: "Selected declarations/imports; no type checking or complete module resolution." },
|
|
21
|
+
{ id: "javascript", extensions: [".js", ".jsx", ".mjs", ".cjs"], aliases: ["js", "jsx"], extractor: "typescript", method: "tree-sitter", grammar: "javascript", limits: "Selected declarations/imports; dynamic targets and module conditions are incomplete." },
|
|
22
|
+
{ id: "php", extensions: [".php"], aliases: [], extractor: "php", method: "tree-sitter", grammar: "php", limits: "Selected declarations/imports; partial PSR-4/domain resolution, no runtime reflection." },
|
|
23
|
+
{ id: "python", extensions: [".py"], aliases: ["py"], extractor: "python", method: "tree-sitter", grammar: "python", limits: "Selected declarations/imports; package resolution and dynamic attributes incomplete." },
|
|
24
|
+
{ id: "go", extensions: [".go"], aliases: ["golang"], extractor: "go", method: "tree-sitter", grammar: "go", limits: "Selected declarations/imports; no complete module/package or receiver resolution." },
|
|
25
|
+
{ id: "rust", extensions: [".rs"], aliases: ["rs"], extractor: "rust", method: "tree-sitter", grammar: "rust", limits: "Selected items/use declarations; no Cargo resolution, macro expansion or trait dispatch proof." },
|
|
26
|
+
{ id: "java", extensions: [".java"], aliases: [], extractor: "java", method: "tree-sitter", grammar: "java", limits: "Selected declarations; imports currently marked external, no JVM package resolution." },
|
|
27
|
+
{ id: "csharp", extensions: [".cs"], aliases: ["cs", "c_sharp"], extractor: "csharp", method: "tree-sitter", grammar: "c_sharp", limits: "Regression support for selected declarations; imports marked external, no assembly resolution." },
|
|
28
|
+
{ id: "ruby", extensions: [".rb"], aliases: ["rb"], extractor: "ruby", method: "tree-sitter", grammar: "ruby", limits: "Selected declarations/requires; no load-order or metaprogramming evaluation." },
|
|
29
|
+
{ id: "frontend", extensions: [".vue", ".astro", ".svelte"], aliases: [], extractor: "frontend", method: "embedded-script", limits: "Scans script/frontmatter as TypeScript; no whole-template AST validation." },
|
|
30
|
+
{ id: "kotlin", extensions: [".kt"], aliases: [], extractor: null, method: "unsupported", limits: "Recognized for unsupported-file diagnostics; no registered grammar or extractor." },
|
|
31
|
+
{ id: "scala", extensions: [".scala"], aliases: [], extractor: null, method: "unsupported", limits: "Recognized only; no registered grammar or extractor." },
|
|
32
|
+
{ id: "zig", extensions: [".zig"], aliases: [], extractor: null, method: "unsupported", limits: "Recognized only; no registered grammar or extractor." },
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
export function getLanguageCapability(filePath: string): LanguageDefinition | undefined {
|
|
36
|
+
const lower = filePath.toLowerCase();
|
|
37
|
+
return LANGUAGE_CAPABILITIES.find(language => language.extensions.some(ext => lower.endsWith(ext)));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function grammarFileForKey(keyOrPath: string): string | null {
|
|
41
|
+
const key = keyOrPath.trim().toLowerCase();
|
|
42
|
+
if (key.endsWith(".wasm")) return key;
|
|
43
|
+
const language = LANGUAGE_CAPABILITIES.find(l => l.id === key || l.aliases.includes(key))
|
|
44
|
+
?? getLanguageCapability(key);
|
|
45
|
+
if (!language?.grammar) return null;
|
|
46
|
+
const grammar = language.grammarOverrides?.[key] ?? language.grammarOverrides?.[path.extname(key)] ?? language.grammar;
|
|
47
|
+
return `tree-sitter-${grammar}.wasm`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function getParserCapabilities(full: boolean) {
|
|
51
|
+
const common = {
|
|
52
|
+
parser_revision: PARSER_REVISION,
|
|
53
|
+
grammar_package: `${grammarPackage.name}@${grammarPackage.version}`,
|
|
54
|
+
coverage: "partial",
|
|
55
|
+
status_contract: "parsed = parser/scanner completed; degraded = recovery/fallback; unsupported = no extractor. None implies complete extraction or runtime correctness.",
|
|
56
|
+
};
|
|
57
|
+
return full ? {
|
|
58
|
+
...common,
|
|
59
|
+
languages: LANGUAGE_CAPABILITIES.map(l => ({
|
|
60
|
+
id: l.id, extensions: l.extensions, extractor: l.extractor, method: l.method,
|
|
61
|
+
coverage: l.extractor ? "partial" : "none",
|
|
62
|
+
grammars: [...new Set(l.extensions.map(grammarFileForKey).filter(Boolean))],
|
|
63
|
+
limits: l.limits,
|
|
64
|
+
evidence: l.method === "tree-sitter" ? "tests/unit/language-capabilities.test.ts; tests/unit/parser-recovery.test.ts" : "tests/unit/language-capabilities.test.ts",
|
|
65
|
+
})),
|
|
66
|
+
} : {
|
|
67
|
+
...common,
|
|
68
|
+
languages: Object.fromEntries(LANGUAGE_CAPABILITIES.map(l => [l.id, l.method])),
|
|
69
|
+
detail_hint: "Use detail_level='full' for extensions, grammar assets and per-language limits.",
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { readOptionalSourceFile } from "../../../resources/source-files.ts";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import type {
|
|
5
|
+
SchemaFieldSummary,
|
|
6
|
+
SchemaMetadata,
|
|
7
|
+
StackSchemaProvider,
|
|
8
|
+
} from "../schema-provider.interface.ts";
|
|
9
|
+
|
|
10
|
+
export class LaravelMigrationSchemaProvider implements StackSchemaProvider {
|
|
11
|
+
public readonly id = "laravel-migration";
|
|
12
|
+
public readonly name = "Laravel Migration Schema Provider";
|
|
13
|
+
|
|
14
|
+
public canHandle(projectRoot: string): boolean {
|
|
15
|
+
const migrationsDir = path.join(projectRoot, "database", "migrations");
|
|
16
|
+
return fs.existsSync(migrationsDir) || fs.existsSync(path.join(projectRoot, "artisan"));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public resolveEntitySchema(
|
|
20
|
+
projectRoot: string,
|
|
21
|
+
entitySymbol: string,
|
|
22
|
+
entityFilePath?: string
|
|
23
|
+
): SchemaMetadata | null {
|
|
24
|
+
const migrationsDir = path.join(projectRoot, "database", "migrations");
|
|
25
|
+
if (!fs.existsSync(migrationsDir)) return null;
|
|
26
|
+
|
|
27
|
+
const tableName = this.resolveTableName(projectRoot, entitySymbol, entityFilePath);
|
|
28
|
+
if (!tableName) return null;
|
|
29
|
+
|
|
30
|
+
const migrationFiles = this.findMigrationFilesForTable(migrationsDir, tableName);
|
|
31
|
+
if (migrationFiles.length === 0) return null;
|
|
32
|
+
|
|
33
|
+
const fieldsMap = new Map<string, SchemaFieldSummary>();
|
|
34
|
+
let primarySourceFile = migrationFiles[0];
|
|
35
|
+
|
|
36
|
+
for (const migFile of migrationFiles) {
|
|
37
|
+
const fullPath = path.join(migrationsDir, migFile);
|
|
38
|
+
try {
|
|
39
|
+
const content = readOptionalSourceFile(fullPath, "utf-8");
|
|
40
|
+
this.extractColumnsFromMigration(content, tableName, fieldsMap);
|
|
41
|
+
} catch {
|
|
42
|
+
// Skip unreadable files
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (fieldsMap.size === 0) return null;
|
|
47
|
+
|
|
48
|
+
const relSourceFile = path.relative(projectRoot, path.join(migrationsDir, primarySourceFile));
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
entityName: entitySymbol,
|
|
52
|
+
tableName,
|
|
53
|
+
schemaSourceFile: relSourceFile,
|
|
54
|
+
fields: Array.from(fieldsMap.values()),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private resolveTableName(
|
|
59
|
+
projectRoot: string,
|
|
60
|
+
entitySymbol: string,
|
|
61
|
+
entityFilePath?: string
|
|
62
|
+
): string {
|
|
63
|
+
// 1. Check if model file defines explicit protected $table = '...';
|
|
64
|
+
if (entityFilePath) {
|
|
65
|
+
const fullEntityPath = path.isAbsolute(entityFilePath)
|
|
66
|
+
? entityFilePath
|
|
67
|
+
: path.join(projectRoot, entityFilePath);
|
|
68
|
+
if (fs.existsSync(fullEntityPath)) {
|
|
69
|
+
try {
|
|
70
|
+
const content = readOptionalSourceFile(fullEntityPath, "utf-8");
|
|
71
|
+
const tableMatch = /protected\s+\$table\s*=\s*['"]([^'"]+)['"]/.exec(content);
|
|
72
|
+
if (tableMatch) {
|
|
73
|
+
return tableMatch[1];
|
|
74
|
+
}
|
|
75
|
+
} catch {}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 2. Derive snake_case plural from entity name (e.g. OrderItem -> order_items)
|
|
80
|
+
return this.pluralize(this.toSnakeCase(entitySymbol));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private toSnakeCase(str: string): string {
|
|
84
|
+
return str
|
|
85
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
|
86
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2")
|
|
87
|
+
.toLowerCase();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private pluralize(snake: string): string {
|
|
91
|
+
if (snake.endsWith("y") && !/[aeiou]y$/i.test(snake)) {
|
|
92
|
+
return `${snake.slice(0, -1)}ies`;
|
|
93
|
+
}
|
|
94
|
+
if (/(?:s|x|z|ch|sh)$/i.test(snake)) {
|
|
95
|
+
return `${snake}es`;
|
|
96
|
+
}
|
|
97
|
+
return `${snake}s`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private findMigrationFilesForTable(migrationsDir: string, tableName: string): string[] {
|
|
101
|
+
const files = fs.readdirSync(migrationsDir).filter((f) => f.endsWith(".php")).sort();
|
|
102
|
+
const matched: string[] = [];
|
|
103
|
+
|
|
104
|
+
// Priority 1: *_create_${tableName}_table.php
|
|
105
|
+
const createTarget = `_create_${tableName}_table.php`;
|
|
106
|
+
for (const f of files) {
|
|
107
|
+
if (f.endsWith(createTarget)) {
|
|
108
|
+
matched.push(f);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Priority 2: Other migration files altering this table
|
|
113
|
+
for (const f of files) {
|
|
114
|
+
if (matched.includes(f)) continue;
|
|
115
|
+
if (f.includes(`_${tableName}_`)) {
|
|
116
|
+
matched.push(f);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// If still not found by filename, do a lightweight content search
|
|
121
|
+
if (matched.length === 0) {
|
|
122
|
+
for (const f of files) {
|
|
123
|
+
try {
|
|
124
|
+
const content = readOptionalSourceFile(path.join(migrationsDir, f), "utf-8");
|
|
125
|
+
if (
|
|
126
|
+
content.includes(`Schema::create('${tableName}'`) ||
|
|
127
|
+
content.includes(`Schema::create("${tableName}"`) ||
|
|
128
|
+
content.includes(`Schema::table('${tableName}'`) ||
|
|
129
|
+
content.includes(`Schema::table("${tableName}"`)
|
|
130
|
+
) {
|
|
131
|
+
matched.push(f);
|
|
132
|
+
}
|
|
133
|
+
} catch {}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return matched;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private extractColumnsFromMigration(
|
|
141
|
+
content: string,
|
|
142
|
+
tableName: string,
|
|
143
|
+
fieldsMap: Map<string, SchemaFieldSummary>
|
|
144
|
+
): void {
|
|
145
|
+
const lines = content.split("\n");
|
|
146
|
+
|
|
147
|
+
for (const rawLine of lines) {
|
|
148
|
+
const line = rawLine.trim();
|
|
149
|
+
if (!line.includes("$table->")) continue;
|
|
150
|
+
|
|
151
|
+
// Special shorthand: $table->id();
|
|
152
|
+
if (/\$table->id\s*\(\s*\)/.test(line)) {
|
|
153
|
+
fieldsMap.set("id", { name: "id", type: "id", isPrimary: true });
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Special shorthand: $table->id('custom_id');
|
|
158
|
+
const customIdMatch = /\$table->id\s*\(\s*['"]([^'"]+)['"]\s*\)/.exec(line);
|
|
159
|
+
if (customIdMatch) {
|
|
160
|
+
fieldsMap.set(customIdMatch[1], { name: customIdMatch[1], type: "id", isPrimary: true });
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Special shorthand: $table->timestamps();
|
|
165
|
+
if (/\$table->timestamps\s*\(/.test(line)) {
|
|
166
|
+
if (!fieldsMap.has("created_at")) {
|
|
167
|
+
fieldsMap.set("created_at", { name: "created_at", type: "timestamp", nullable: true });
|
|
168
|
+
}
|
|
169
|
+
if (!fieldsMap.has("updated_at")) {
|
|
170
|
+
fieldsMap.set("updated_at", { name: "updated_at", type: "timestamp", nullable: true });
|
|
171
|
+
}
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Special shorthand: $table->softDeletes();
|
|
176
|
+
if (/\$table->softDeletes\s*\(/.test(line)) {
|
|
177
|
+
if (!fieldsMap.has("deleted_at")) {
|
|
178
|
+
fieldsMap.set("deleted_at", { name: "deleted_at", type: "timestamp", nullable: true });
|
|
179
|
+
}
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Special shorthand: $table->rememberToken();
|
|
184
|
+
if (/\$table->rememberToken\s*\(/.test(line)) {
|
|
185
|
+
if (!fieldsMap.has("remember_token")) {
|
|
186
|
+
fieldsMap.set("remember_token", { name: "remember_token", type: "string", nullable: true });
|
|
187
|
+
}
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Standard column definitions: $table->type('column_name', ...)
|
|
192
|
+
const colMatch = /\$table->([a-zA-Z0-9_]+)\s*\(\s*['"]([^'"]+)['"]/.exec(line);
|
|
193
|
+
if (colMatch) {
|
|
194
|
+
const type = colMatch[1];
|
|
195
|
+
const name = colMatch[2];
|
|
196
|
+
|
|
197
|
+
// Skip non-column fluent methods like foreign, dropColumn, index, primary
|
|
198
|
+
if (["index", "unique", "primary", "foreign", "dropColumn", "dropForeign"].includes(type)) {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const nullable = line.includes("->nullable()");
|
|
203
|
+
const isPrimary = type === "increments" || type === "bigIncrements" || line.includes("->primary()");
|
|
204
|
+
const isForeign = type.startsWith("foreign") || name.endsWith("_id");
|
|
205
|
+
|
|
206
|
+
fieldsMap.set(name, {
|
|
207
|
+
name,
|
|
208
|
+
type,
|
|
209
|
+
nullable: nullable || undefined,
|
|
210
|
+
isPrimary: isPrimary || undefined,
|
|
211
|
+
isForeign: isForeign || undefined,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { readOptionalSourceFile } from "../../../resources/source-files.ts";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import type {
|
|
5
|
+
SchemaFieldSummary,
|
|
6
|
+
SchemaMetadata,
|
|
7
|
+
StackSchemaProvider,
|
|
8
|
+
} from "../schema-provider.interface.ts";
|
|
9
|
+
|
|
10
|
+
export class PrismaSchemaProvider implements StackSchemaProvider {
|
|
11
|
+
public readonly id = "prisma";
|
|
12
|
+
public readonly name = "Prisma Schema Provider";
|
|
13
|
+
|
|
14
|
+
public canHandle(projectRoot: string): boolean {
|
|
15
|
+
return (
|
|
16
|
+
fs.existsSync(path.join(projectRoot, "prisma", "schema.prisma")) ||
|
|
17
|
+
fs.existsSync(path.join(projectRoot, "schema.prisma"))
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public resolveEntitySchema(
|
|
22
|
+
projectRoot: string,
|
|
23
|
+
entitySymbol: string,
|
|
24
|
+
_entityFilePath?: string
|
|
25
|
+
): SchemaMetadata | null {
|
|
26
|
+
const candidatePaths = [
|
|
27
|
+
path.join(projectRoot, "prisma", "schema.prisma"),
|
|
28
|
+
path.join(projectRoot, "schema.prisma"),
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
let schemaPath: string | null = null;
|
|
32
|
+
for (const p of candidatePaths) {
|
|
33
|
+
if (fs.existsSync(p)) {
|
|
34
|
+
schemaPath = p;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!schemaPath) return null;
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const content = readOptionalSourceFile(schemaPath, "utf-8");
|
|
43
|
+
const modelRegex = new RegExp(`model\\s+${entitySymbol}\\s*\\{([^}]+)\\}`, "m");
|
|
44
|
+
const match = modelRegex.exec(content);
|
|
45
|
+
if (!match) return null;
|
|
46
|
+
|
|
47
|
+
const body = match[1];
|
|
48
|
+
const lines = body.split("\n");
|
|
49
|
+
const fields: SchemaFieldSummary[] = [];
|
|
50
|
+
|
|
51
|
+
for (const rawLine of lines) {
|
|
52
|
+
const line = rawLine.trim();
|
|
53
|
+
if (!line || line.startsWith("//") || line.startsWith("@@")) continue;
|
|
54
|
+
|
|
55
|
+
// Pattern: fieldName FieldType attributes...
|
|
56
|
+
const parts = line.split(/\s+/);
|
|
57
|
+
if (parts.length >= 2) {
|
|
58
|
+
const name = parts[0];
|
|
59
|
+
let type = parts[1];
|
|
60
|
+
const nullable = type.endsWith("?");
|
|
61
|
+
if (nullable) {
|
|
62
|
+
type = type.slice(0, -1);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const isPrimary = line.includes("@id");
|
|
66
|
+
const isForeign = line.includes("@relation");
|
|
67
|
+
|
|
68
|
+
fields.push({
|
|
69
|
+
name,
|
|
70
|
+
type,
|
|
71
|
+
nullable: nullable || undefined,
|
|
72
|
+
isPrimary: isPrimary || undefined,
|
|
73
|
+
isForeign: isForeign || undefined,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (fields.length === 0) return null;
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
entityName: entitySymbol,
|
|
82
|
+
tableName: entitySymbol.toLowerCase(),
|
|
83
|
+
schemaSourceFile: path.relative(projectRoot, schemaPath),
|
|
84
|
+
fields,
|
|
85
|
+
};
|
|
86
|
+
} catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SchemaMetadata,
|
|
3
|
+
StackSchemaProvider,
|
|
4
|
+
} from "./schema-provider.interface.ts";
|
|
5
|
+
import { LaravelMigrationSchemaProvider } from "./providers/laravel-migration-provider.ts";
|
|
6
|
+
import { PrismaSchemaProvider } from "./providers/prisma-schema-provider.ts";
|
|
7
|
+
|
|
8
|
+
export class SchemaProviderRegistry {
|
|
9
|
+
private static providers: StackSchemaProvider[] = [
|
|
10
|
+
new LaravelMigrationSchemaProvider(),
|
|
11
|
+
new PrismaSchemaProvider(),
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Registers a custom schema provider.
|
|
16
|
+
*/
|
|
17
|
+
public static register(provider: StackSchemaProvider): void {
|
|
18
|
+
this.providers.unshift(provider);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Resolves physical schema metadata across all registered providers.
|
|
23
|
+
*/
|
|
24
|
+
public static resolveSchema(
|
|
25
|
+
projectRoot: string,
|
|
26
|
+
entitySymbol: string,
|
|
27
|
+
entityFilePath?: string
|
|
28
|
+
): SchemaMetadata | null {
|
|
29
|
+
for (const provider of this.providers) {
|
|
30
|
+
if (provider.canHandle(projectRoot)) {
|
|
31
|
+
try {
|
|
32
|
+
const res = provider.resolveEntitySchema(projectRoot, entitySymbol, entityFilePath);
|
|
33
|
+
if (res && !(res instanceof Promise)) {
|
|
34
|
+
return res;
|
|
35
|
+
}
|
|
36
|
+
} catch {
|
|
37
|
+
// Graceful fallback
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface SchemaFieldSummary {
|
|
2
|
+
name: string;
|
|
3
|
+
type: string;
|
|
4
|
+
nullable?: boolean;
|
|
5
|
+
isPrimary?: boolean;
|
|
6
|
+
isForeign?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface SchemaMetadata {
|
|
10
|
+
entityName: string;
|
|
11
|
+
tableName: string;
|
|
12
|
+
schemaSourceFile: string;
|
|
13
|
+
fields: SchemaFieldSummary[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface StackSchemaProvider {
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly name: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Determines if this schema provider can handle the project.
|
|
22
|
+
*/
|
|
23
|
+
canHandle(projectRoot: string): boolean;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Resolves physical schema metadata (table name, source file, fields) for a given entity symbol.
|
|
27
|
+
*/
|
|
28
|
+
resolveEntitySchema(
|
|
29
|
+
projectRoot: string,
|
|
30
|
+
entitySymbol: string,
|
|
31
|
+
entityFilePath?: string
|
|
32
|
+
): Promise<SchemaMetadata | null> | SchemaMetadata | null;
|
|
33
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { ParsedFileAST } from "../../types/index.ts";
|
|
2
|
+
import type { CodeExtractor } from "./extractors/base.ts";
|
|
3
|
+
import { BladeExtractor } from "./extractors/blade.ts";
|
|
4
|
+
import { FrontendExtractor } from "./extractors/frontend.ts";
|
|
5
|
+
import { GoExtractor } from "./extractors/go.ts";
|
|
6
|
+
import { PHPExtractor } from "./extractors/php.ts";
|
|
7
|
+
import { PythonExtractor } from "./extractors/python.ts";
|
|
8
|
+
import { TypeScriptExtractor } from "./extractors/typescript.ts";
|
|
9
|
+
import { RustExtractor } from "./extractors/rust.ts";
|
|
10
|
+
import { JavaExtractor } from "./extractors/java.ts";
|
|
11
|
+
import { CSharpExtractor } from "./extractors/csharp.ts";
|
|
12
|
+
import { RubyExtractor } from "./extractors/ruby.ts";
|
|
13
|
+
|
|
14
|
+
import { getLanguageCapability } from "./language-capabilities.ts";
|
|
15
|
+
|
|
16
|
+
export class ASTParserEngine {
|
|
17
|
+
public static isSourceFile(filePath: string): boolean {
|
|
18
|
+
return getLanguageCapability(filePath) !== undefined;
|
|
19
|
+
}
|
|
20
|
+
private extractors: CodeExtractor[];
|
|
21
|
+
|
|
22
|
+
constructor() {
|
|
23
|
+
this.extractors = [
|
|
24
|
+
new BladeExtractor(),
|
|
25
|
+
new FrontendExtractor(),
|
|
26
|
+
new TypeScriptExtractor(),
|
|
27
|
+
new PHPExtractor(),
|
|
28
|
+
new PythonExtractor(),
|
|
29
|
+
new GoExtractor(),
|
|
30
|
+
new RustExtractor(),
|
|
31
|
+
new JavaExtractor(),
|
|
32
|
+
new CSharpExtractor(),
|
|
33
|
+
new RubyExtractor(),
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public async parseFile(filePath: string, content: string): Promise<ParsedFileAST> {
|
|
38
|
+
for (const extractor of this.extractors) {
|
|
39
|
+
if (extractor.canHandle(filePath)) {
|
|
40
|
+
const result = await extractor.extract(filePath, content);
|
|
41
|
+
const capability = getLanguageCapability(filePath);
|
|
42
|
+
return {
|
|
43
|
+
status: "parsed", ...result,
|
|
44
|
+
extraction: result.extraction ?? { method: capability?.method ?? "fallback", coverage: "partial" },
|
|
45
|
+
diagnostics: result.diagnostics ?? [],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Default fallback extractor for unknown file types
|
|
51
|
+
return {
|
|
52
|
+
status: "unsupported",
|
|
53
|
+
extraction: { method: "unsupported", coverage: "none" },
|
|
54
|
+
diagnostics: [{ code: "extractor_unavailable", message: `No extractor registered for '${filePath}'.` }],
|
|
55
|
+
symbols: [],
|
|
56
|
+
dependencies: [],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public registerExtractor(extractor: CodeExtractor): void {
|
|
61
|
+
this.extractors.unshift(extractor);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import runtime from "web-tree-sitter/tree-sitter.wasm" with { type: "file" };
|
|
2
|
+
import typescript from "tree-sitter-wasms/out/tree-sitter-typescript.wasm" with { type: "file" };
|
|
3
|
+
import tsx from "tree-sitter-wasms/out/tree-sitter-tsx.wasm" with { type: "file" };
|
|
4
|
+
import javascript from "tree-sitter-wasms/out/tree-sitter-javascript.wasm" with { type: "file" };
|
|
5
|
+
import php from "tree-sitter-wasms/out/tree-sitter-php.wasm" with { type: "file" };
|
|
6
|
+
import python from "tree-sitter-wasms/out/tree-sitter-python.wasm" with { type: "file" };
|
|
7
|
+
import go from "tree-sitter-wasms/out/tree-sitter-go.wasm" with { type: "file" };
|
|
8
|
+
import rust from "tree-sitter-wasms/out/tree-sitter-rust.wasm" with { type: "file" };
|
|
9
|
+
import java from "tree-sitter-wasms/out/tree-sitter-java.wasm" with { type: "file" };
|
|
10
|
+
import csharp from "tree-sitter-wasms/out/tree-sitter-c_sharp.wasm" with { type: "file" };
|
|
11
|
+
import ruby from "tree-sitter-wasms/out/tree-sitter-ruby.wasm" with { type: "file" };
|
|
12
|
+
|
|
13
|
+
export const WASM_ASSETS: Record<string, string> = {
|
|
14
|
+
"tree-sitter.wasm": runtime,
|
|
15
|
+
"tree-sitter-typescript.wasm": typescript,
|
|
16
|
+
"tree-sitter-tsx.wasm": tsx,
|
|
17
|
+
"tree-sitter-javascript.wasm": javascript,
|
|
18
|
+
"tree-sitter-php.wasm": php,
|
|
19
|
+
"tree-sitter-python.wasm": python,
|
|
20
|
+
"tree-sitter-go.wasm": go,
|
|
21
|
+
"tree-sitter-rust.wasm": rust,
|
|
22
|
+
"tree-sitter-java.wasm": java,
|
|
23
|
+
"tree-sitter-c_sharp.wasm": csharp,
|
|
24
|
+
"tree-sitter-ruby.wasm": ruby,
|
|
25
|
+
};
|