akbo-cli 0.0.0-stage → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +786 -2
- package/dist/catalog_store.d.ts +131 -0
- package/dist/catalog_store.js +506 -0
- package/dist/cleaner.d.ts +11 -0
- package/dist/cleaner.js +92 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1961 -0
- package/dist/dream_engine.d.ts +61 -0
- package/dist/dream_engine.js +330 -0
- package/dist/extractors/base.d.ts +35 -0
- package/dist/extractors/base.js +17 -0
- package/dist/extractors/custom_extractor.d.ts +55 -0
- package/dist/extractors/custom_extractor.js +198 -0
- package/dist/extractors/dotnet_extractor.d.ts +11 -0
- package/dist/extractors/dotnet_extractor.js +579 -0
- package/dist/extractors/golang_extractor.d.ts +11 -0
- package/dist/extractors/golang_extractor.js +73 -0
- package/dist/extractors/index.d.ts +14 -0
- package/dist/extractors/index.js +30 -0
- package/dist/extractors/jvm_extractor.d.ts +11 -0
- package/dist/extractors/jvm_extractor.js +319 -0
- package/dist/extractors/node_extractor.d.ts +11 -0
- package/dist/extractors/node_extractor.js +306 -0
- package/dist/extractors/proto_graphql_extractor.d.ts +11 -0
- package/dist/extractors/proto_graphql_extractor.js +125 -0
- package/dist/extractors/python_extractor.d.ts +11 -0
- package/dist/extractors/python_extractor.js +298 -0
- package/dist/extractors/rust_extractor.d.ts +11 -0
- package/dist/extractors/rust_extractor.js +66 -0
- package/dist/graph_builder.d.ts +87 -0
- package/dist/graph_builder.js +1516 -0
- package/dist/guard_service.d.ts +33 -0
- package/dist/guard_service.js +167 -0
- package/dist/harvester.d.ts +38 -0
- package/dist/harvester.js +461 -0
- package/dist/hook_generator.d.ts +34 -0
- package/dist/hook_generator.js +269 -0
- package/dist/importers/skill_importer.d.ts +43 -0
- package/dist/importers/skill_importer.js +470 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +20 -0
- package/dist/indexer.d.ts +19 -0
- package/dist/indexer.js +108 -0
- package/dist/init_service.d.ts +37 -0
- package/dist/init_service.js +246 -0
- package/dist/mcp_server.d.ts +10 -0
- package/dist/mcp_server.js +846 -0
- package/dist/pool_resolver.d.ts +40 -0
- package/dist/pool_resolver.js +84 -0
- package/dist/provider.d.ts +135 -0
- package/dist/provider.js +880 -0
- package/dist/query_service.d.ts +33 -0
- package/dist/query_service.js +161 -0
- package/dist/schema_generator.d.ts +236 -0
- package/dist/schema_generator.js +264 -0
- package/dist/standards_loader.d.ts +7 -0
- package/dist/standards_loader.js +33 -0
- package/dist/types.d.ts +323 -0
- package/dist/types.js +123 -0
- package/dist/unit_synthesizer.d.ts +22 -0
- package/dist/unit_synthesizer.js +196 -0
- package/dist/validator.d.ts +13 -0
- package/dist/validator.js +152 -0
- package/dist/version.d.ts +6 -0
- package/dist/version.js +16 -0
- package/dist/watcher.d.ts +38 -0
- package/dist/watcher.js +132 -0
- package/package.json +56 -6
- package/schemas/index-schema.json +98 -0
- package/schemas/knowledge-unit.json +154 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { cleanClientUrl } from './base.js';
|
|
3
|
+
export class PythonExtractor {
|
|
4
|
+
name = 'python';
|
|
5
|
+
canExtractManifest(filePath) {
|
|
6
|
+
const lower = path.basename(filePath).toLowerCase();
|
|
7
|
+
return (lower === 'pyproject.toml' ||
|
|
8
|
+
lower === 'requirements.txt' ||
|
|
9
|
+
lower === 'pipfile' ||
|
|
10
|
+
lower === 'setup.py');
|
|
11
|
+
}
|
|
12
|
+
extractManifest(filePath, content) {
|
|
13
|
+
const filename = path.basename(filePath);
|
|
14
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
15
|
+
if (filename === 'pyproject.toml') {
|
|
16
|
+
const deps = [];
|
|
17
|
+
const nameMatch = content.match(/name\s*=\s*["']([^"']+)["']/);
|
|
18
|
+
const versionMatch = content.match(/version\s*=\s*["']([^"']+)["']/);
|
|
19
|
+
let inDepsSection = false;
|
|
20
|
+
for (const line of content.split('\n')) {
|
|
21
|
+
const trimmed = line.trim();
|
|
22
|
+
if (trimmed.startsWith('[tool.poetry.dependencies]') ||
|
|
23
|
+
trimmed.startsWith('[project.dependencies]') ||
|
|
24
|
+
trimmed.startsWith('dependencies = [')) {
|
|
25
|
+
inDepsSection = true;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
else if (trimmed.startsWith('[') && !trimmed.includes('dependencies')) {
|
|
29
|
+
inDepsSection = false;
|
|
30
|
+
}
|
|
31
|
+
if (inDepsSection && trimmed && !trimmed.startsWith('#')) {
|
|
32
|
+
if (trimmed.startsWith('"') || trimmed.startsWith("'")) {
|
|
33
|
+
const match = trimmed.match(/^["']([A-Za-z0-9_.-]+)/);
|
|
34
|
+
if (match && match[1].toLowerCase() !== 'python')
|
|
35
|
+
deps.push(match[1]);
|
|
36
|
+
}
|
|
37
|
+
else if (trimmed.includes('=')) {
|
|
38
|
+
const key = trimmed.split('=')[0].trim();
|
|
39
|
+
if (key && key.toLowerCase() !== 'python')
|
|
40
|
+
deps.push(key);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (inDepsSection && trimmed === ']') {
|
|
44
|
+
inDepsSection = false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
path: normalized,
|
|
49
|
+
type: 'python',
|
|
50
|
+
contentSummary: {
|
|
51
|
+
name: nameMatch ? nameMatch[1] : undefined,
|
|
52
|
+
version: versionMatch ? versionMatch[1] : undefined,
|
|
53
|
+
dependencies: [...new Set(deps)]
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (filename === 'requirements.txt') {
|
|
58
|
+
const deps = content
|
|
59
|
+
.split('\n')
|
|
60
|
+
.map(l => l.trim())
|
|
61
|
+
.filter(l => l && !l.startsWith('#') && !l.startsWith('-'))
|
|
62
|
+
.map(l => l.split(/[=<>~;]/)[0].trim())
|
|
63
|
+
.filter(Boolean);
|
|
64
|
+
return {
|
|
65
|
+
path: normalized,
|
|
66
|
+
type: 'python',
|
|
67
|
+
contentSummary: { dependencies: deps }
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (filename === 'Pipfile') {
|
|
71
|
+
const deps = [];
|
|
72
|
+
let inPackages = false;
|
|
73
|
+
for (const line of content.split('\n')) {
|
|
74
|
+
const trimmed = line.trim();
|
|
75
|
+
if (trimmed === '[packages]' || trimmed === '[dev-packages]') {
|
|
76
|
+
inPackages = true;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
else if (trimmed.startsWith('[')) {
|
|
80
|
+
inPackages = false;
|
|
81
|
+
}
|
|
82
|
+
if (inPackages && trimmed && !trimmed.startsWith('#')) {
|
|
83
|
+
const pkg = trimmed.split('=')[0].trim();
|
|
84
|
+
if (pkg)
|
|
85
|
+
deps.push(pkg);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
path: normalized,
|
|
90
|
+
type: 'python',
|
|
91
|
+
contentSummary: { dependencies: deps }
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (filename === 'setup.py') {
|
|
95
|
+
return {
|
|
96
|
+
path: normalized,
|
|
97
|
+
type: 'python',
|
|
98
|
+
contentSummary: {
|
|
99
|
+
snippet: content.split('\n').slice(0, 20).join('\n')
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
canExtractSchema(filePath) {
|
|
106
|
+
return filePath.endsWith('.py');
|
|
107
|
+
}
|
|
108
|
+
extractSchemas(filePath, content) {
|
|
109
|
+
const schemas = [];
|
|
110
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
111
|
+
const isPyModel = content.includes('Base') ||
|
|
112
|
+
content.includes('Model') ||
|
|
113
|
+
content.includes('BaseModel') ||
|
|
114
|
+
content.includes('__tablename__') ||
|
|
115
|
+
content.includes('db_table') ||
|
|
116
|
+
normalized.includes('model') ||
|
|
117
|
+
normalized.includes('schema');
|
|
118
|
+
if (isPyModel) {
|
|
119
|
+
const classMatches = Array.from(content.matchAll(/class\s+([A-Za-z0-9_]+)\s*\((?:[^)]*(?:Base|models\.Model|Model|SQLModel|BaseModel|DeclarativeBase)[^)]*)\):/g)).map(m => m[1]);
|
|
120
|
+
const tableMatches = Array.from(content.matchAll(/(?:__tablename__|db_table)\s*=\s*['"`]([^'"`]+)['"`]/g)).map(m => m[1]);
|
|
121
|
+
const allModels = [...new Set([...classMatches, ...tableMatches])];
|
|
122
|
+
if (allModels.length > 0) {
|
|
123
|
+
const schemaType = content.includes('__tablename__') ||
|
|
124
|
+
content.includes('DeclarativeBase') ||
|
|
125
|
+
content.includes('mapped_column(')
|
|
126
|
+
? 'sqlalchemy'
|
|
127
|
+
: 'python_models';
|
|
128
|
+
schemas.push({
|
|
129
|
+
file: normalized,
|
|
130
|
+
type: schemaType,
|
|
131
|
+
tablesOrModels: allModels
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return schemas;
|
|
136
|
+
}
|
|
137
|
+
canExtractRoutes(filePath) {
|
|
138
|
+
return filePath.endsWith('.py');
|
|
139
|
+
}
|
|
140
|
+
extractRoutesAndCommands(filePath, content) {
|
|
141
|
+
const items = [];
|
|
142
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
143
|
+
// 1. FastAPI Routes (@app.get, @router.post, etc.)
|
|
144
|
+
let routerPrefix = '';
|
|
145
|
+
const prefixMatch = content.match(/APIRouter\s*\(\s*(?:.*?\bprefix\s*=\s*)?["']([^"']+)["']/);
|
|
146
|
+
if (prefixMatch) {
|
|
147
|
+
routerPrefix = `/${prefixMatch[1].replace(/^\//, '').replace(/\/$/, '')}`;
|
|
148
|
+
}
|
|
149
|
+
const fastApiRegex = /@(app|router|api_router)\.(get|post|put|delete|patch|options|head)\s*\(\s*["']([^"']*)["'](?:\s*,\s*[\s\S]*?)?\)\s*(?:async\s+)?def\s+([\p{L}\p{N}_]+)\s*\(([\s\S]*?)\):/gu;
|
|
150
|
+
for (const match of content.matchAll(fastApiRegex)) {
|
|
151
|
+
const verb = match[2].toUpperCase();
|
|
152
|
+
const rawSub = match[3] ?? '';
|
|
153
|
+
const subPath = rawSub ? `/${rawSub.replace(/^\//, '')}` : '';
|
|
154
|
+
const fullRoute = `${routerPrefix}${subPath}` || '/';
|
|
155
|
+
const funcName = match[4];
|
|
156
|
+
const params = match[5]?.trim() || '';
|
|
157
|
+
items.push({
|
|
158
|
+
file: normalized,
|
|
159
|
+
framework: 'FastAPI/Python',
|
|
160
|
+
method: verb,
|
|
161
|
+
identifier: funcName,
|
|
162
|
+
signature: `${verb} ${fullRoute} -> def ${funcName}(${params.replace(/\s+/g, ' ')})`
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
// 2. Flask Routes & Blueprints (@app.route, @bp.route)
|
|
166
|
+
let blueprintPrefix = '';
|
|
167
|
+
const bpMatch = content.match(/Blueprint\s*\(\s*['"][^'"]+['"],\s*__name__\s*,\s*url_prefix\s*=\s*['"]([^'"]+)['"]/);
|
|
168
|
+
if (bpMatch) {
|
|
169
|
+
blueprintPrefix = `/${bpMatch[1].replace(/^\//, '').replace(/\/$/, '')}`;
|
|
170
|
+
}
|
|
171
|
+
const flaskRouteRegex = /@(app|bp|api|blueprint|[A-Za-z0-9_]+_bp)\.route\s*\(\s*["']([^"']*)["'](?:\s*,\s*methods\s*=\s*\[([^\]]+)\])?(?:\s*,\s*[\s\S]*?)?\)\s*(?:async\s+)?def\s+([\p{L}\p{N}_]+)\s*\(([\s\S]*?)\):/gu;
|
|
172
|
+
for (const match of content.matchAll(flaskRouteRegex)) {
|
|
173
|
+
const rawSub = match[2] ?? '';
|
|
174
|
+
const methodsStr = match[3];
|
|
175
|
+
const subPath = rawSub ? `/${rawSub.replace(/^\//, '')}` : '';
|
|
176
|
+
const fullRoute = `${blueprintPrefix}${subPath}` || '/';
|
|
177
|
+
const funcName = match[4];
|
|
178
|
+
const params = match[5]?.trim() || '';
|
|
179
|
+
const verbs = methodsStr
|
|
180
|
+
? Array.from(methodsStr.matchAll(/["']([A-Za-z]+)["']/g)).map(m => m[1].toUpperCase())
|
|
181
|
+
: ['GET'];
|
|
182
|
+
for (const verb of verbs) {
|
|
183
|
+
items.push({
|
|
184
|
+
file: normalized,
|
|
185
|
+
framework: 'Flask',
|
|
186
|
+
method: verb,
|
|
187
|
+
identifier: funcName,
|
|
188
|
+
signature: `${verb} ${fullRoute} -> def ${funcName}(${params.replace(/\s+/g, ' ')})`
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// 3. Django URL patterns & ViewSets
|
|
193
|
+
if (content.includes('urlpatterns') || content.includes('path(') || content.includes('re_path(')) {
|
|
194
|
+
const djangoPathRegex = /(?:path|re_path)\s*\(\s*['"]([^'"]+)['"]\s*,\s*([A-Za-z0-9_.]+)(?:\.as_view\(\))?/g;
|
|
195
|
+
for (const match of content.matchAll(djangoPathRegex)) {
|
|
196
|
+
const rawPath = match[1];
|
|
197
|
+
const routePath = rawPath.startsWith('/') ? rawPath : `/${rawPath}`;
|
|
198
|
+
const viewTarget = match[2];
|
|
199
|
+
items.push({
|
|
200
|
+
file: normalized,
|
|
201
|
+
framework: 'Django',
|
|
202
|
+
method: 'ANY',
|
|
203
|
+
identifier: viewTarget,
|
|
204
|
+
signature: `Django ${routePath} -> ${viewTarget}`
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (content.includes('viewsets.') || content.includes('@action')) {
|
|
209
|
+
const viewSetMatch = content.match(/class\s+([\p{L}\p{N}_]+)\s*\([^)]*(?:viewsets|ModelViewSet|GenericViewSet)[^)]*\):/u);
|
|
210
|
+
const viewSetName = viewSetMatch ? viewSetMatch[1] : 'ViewSet';
|
|
211
|
+
const actionRegex = /@action\s*\((?:[^)]*methods\s*=\s*\[([^\]]+)\])?(?:[^)]*detail\s*=\s*(True|False))?[^)]*\)\s*(?:async\s+)?def\s+([\p{L}\p{N}_]+)\s*\(([\s\S]*?)\):/gu;
|
|
212
|
+
for (const match of content.matchAll(actionRegex)) {
|
|
213
|
+
const methodsStr = match[1];
|
|
214
|
+
const isDetail = match[2] === 'True';
|
|
215
|
+
const actionName = match[3];
|
|
216
|
+
const params = match[4]?.trim() || '';
|
|
217
|
+
const verbs = methodsStr
|
|
218
|
+
? Array.from(methodsStr.matchAll(/["']([A-Za-z]+)["']/g)).map(m => m[1].toUpperCase())
|
|
219
|
+
: ['POST'];
|
|
220
|
+
for (const verb of verbs) {
|
|
221
|
+
const routePattern = isDetail ? `/{pk}/${actionName}` : `/${actionName}`;
|
|
222
|
+
items.push({
|
|
223
|
+
file: normalized,
|
|
224
|
+
framework: 'Django',
|
|
225
|
+
method: verb,
|
|
226
|
+
identifier: `${viewSetName}.${actionName}`,
|
|
227
|
+
signature: `${verb} ${routePattern} -> ${viewSetName}.${actionName}(${params.replace(/\s+/g, ' ')})`
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// 4. Celery Background Tasks
|
|
233
|
+
if (content.includes('task') || content.includes('@shared_task')) {
|
|
234
|
+
const celeryRegex = /@(?:(?:[A-Za-z0-9_.]+\.)?task|shared_task)\s*(?:\((?:[^)]*name\s*=\s*['"`]([^'"`]+)['"`])?[^)]*\))?\s*(?:async\s+)?def\s+([\p{L}\p{N}_]+)\s*\(([\s\S]*?)\):/gu;
|
|
235
|
+
for (const match of content.matchAll(celeryRegex)) {
|
|
236
|
+
const customName = match[1];
|
|
237
|
+
const funcName = match[2];
|
|
238
|
+
const params = match[3]?.trim() || '';
|
|
239
|
+
const taskIdentifier = customName || funcName;
|
|
240
|
+
items.push({
|
|
241
|
+
file: normalized,
|
|
242
|
+
framework: 'Celery',
|
|
243
|
+
method: 'TASK',
|
|
244
|
+
identifier: taskIdentifier,
|
|
245
|
+
signature: `Celery task: ${taskIdentifier} -> def ${funcName}(${params.replace(/\s+/g, ' ')})`
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
// 5. Dramatiq Actors
|
|
250
|
+
if (content.includes('@dramatiq.actor') || content.includes('@actor')) {
|
|
251
|
+
const dramatiqRegex = /@(?:dramatiq\.)?actor\s*(?:\((?:[^)]*queue_name\s*=\s*['"`]([^'"`]+)['"`])?[^)]*\))?\s*(?:async\s+)?def\s+([\p{L}\p{N}_]+)\s*\(([\s\S]*?)\):/gu;
|
|
252
|
+
for (const match of content.matchAll(dramatiqRegex)) {
|
|
253
|
+
const queueName = match[1] || 'default';
|
|
254
|
+
const funcName = match[2];
|
|
255
|
+
const params = match[3]?.trim() || '';
|
|
256
|
+
items.push({
|
|
257
|
+
file: normalized,
|
|
258
|
+
framework: 'Dramatiq',
|
|
259
|
+
method: 'TASK',
|
|
260
|
+
identifier: funcName,
|
|
261
|
+
signature: `Dramatiq actor: ${queueName}:${funcName} -> def ${funcName}(${params.replace(/\s+/g, ' ')})`
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
// 6. Python HTTP Client calls: requests, httpx, aiohttp
|
|
266
|
+
const pyHttpRegex = /(?:\b(?:requests|httpx|client|session|aiohttp))\s*\.\s*(get|post|put|delete|patch)\s*\(\s*(?:url\s*=\s*)?["']([^"']+)["']/g;
|
|
267
|
+
for (const match of content.matchAll(pyHttpRegex)) {
|
|
268
|
+
const verb = match[1].toUpperCase();
|
|
269
|
+
const cleanPath = cleanClientUrl(match[2]);
|
|
270
|
+
if (cleanPath) {
|
|
271
|
+
items.push({
|
|
272
|
+
file: normalized,
|
|
273
|
+
framework: 'HttpClient',
|
|
274
|
+
method: verb,
|
|
275
|
+
identifier: cleanPath,
|
|
276
|
+
signature: `${verb} ${cleanPath} [HTTP Client]`
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// 7. Python gRPC Client calls
|
|
281
|
+
const pyGrpcRegex = /(?:\b(?:stub|grpc_client|client))\s*\.\s*([A-Za-z0-9_]+)\s*\(/g;
|
|
282
|
+
for (const match of content.matchAll(pyGrpcRegex)) {
|
|
283
|
+
const method = match[1];
|
|
284
|
+
if (!['get', 'post', 'put', 'delete', 'patch', 'request', 'close', 'send', 'connect', 'mount', 'build_request', 'print'].includes(method)) {
|
|
285
|
+
if (content.includes('grpc') || content.includes('pb2') || content.includes('stub') || /^[A-Z]/.test(method)) {
|
|
286
|
+
items.push({
|
|
287
|
+
file: normalized,
|
|
288
|
+
framework: 'GrpcClient',
|
|
289
|
+
method: 'RPC',
|
|
290
|
+
identifier: method,
|
|
291
|
+
signature: `rpc client: ${method}`
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return items;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CodebaseExtractor } from './base.js';
|
|
2
|
+
import type { ManifestSummary, SchemaSummary, RouteOrSignature } from '../types.js';
|
|
3
|
+
export declare class RustExtractor implements CodebaseExtractor {
|
|
4
|
+
readonly name = "rust";
|
|
5
|
+
canExtractManifest(filePath: string): boolean;
|
|
6
|
+
extractManifest(filePath: string, content: string): ManifestSummary | null;
|
|
7
|
+
canExtractSchema(filePath: string): boolean;
|
|
8
|
+
extractSchemas(filePath: string, content: string): SchemaSummary[];
|
|
9
|
+
canExtractRoutes(filePath: string): boolean;
|
|
10
|
+
extractRoutesAndCommands(filePath: string, content: string): RouteOrSignature[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
export class RustExtractor {
|
|
3
|
+
name = 'rust';
|
|
4
|
+
canExtractManifest(filePath) {
|
|
5
|
+
return path.basename(filePath).toLowerCase() === 'cargo.toml';
|
|
6
|
+
}
|
|
7
|
+
extractManifest(filePath, content) {
|
|
8
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
9
|
+
const deps = [];
|
|
10
|
+
const lines = content.split('\n');
|
|
11
|
+
let inDeps = false;
|
|
12
|
+
for (const line of lines) {
|
|
13
|
+
const trimmed = line.trim();
|
|
14
|
+
if (trimmed.startsWith('[dependencies]') || trimmed.startsWith('[workspace.dependencies]')) {
|
|
15
|
+
inDeps = true;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
else if (trimmed.startsWith('[')) {
|
|
19
|
+
inDeps = false;
|
|
20
|
+
}
|
|
21
|
+
if (inDeps && trimmed && !trimmed.startsWith('#')) {
|
|
22
|
+
const depName = trimmed.split('=')[0].trim();
|
|
23
|
+
if (depName)
|
|
24
|
+
deps.push(depName);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
path: normalized,
|
|
29
|
+
type: 'cargo',
|
|
30
|
+
contentSummary: { dependencies: deps }
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
canExtractSchema(filePath) {
|
|
34
|
+
const norm = filePath.replace(/\\/g, '/');
|
|
35
|
+
return norm.endsWith('database.rs') || norm.endsWith('db.rs') || (norm.endsWith('.rs') && norm.includes('models/'));
|
|
36
|
+
}
|
|
37
|
+
extractSchemas(filePath, content) {
|
|
38
|
+
const schemas = [];
|
|
39
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
40
|
+
const tables = Array.from(content.matchAll(/CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?([`"']?\w+[`"']?)/gi)).map(m => m[1].replace(/[`"']/g, ''));
|
|
41
|
+
const structs = Array.from(content.matchAll(/pub\s+struct\s+(\w+)/g)).map(m => m[1]);
|
|
42
|
+
schemas.push({
|
|
43
|
+
file: normalized,
|
|
44
|
+
type: 'rust_db',
|
|
45
|
+
tablesOrModels: [...new Set([...tables, ...structs.slice(0, 10)])]
|
|
46
|
+
});
|
|
47
|
+
return schemas;
|
|
48
|
+
}
|
|
49
|
+
canExtractRoutes(filePath) {
|
|
50
|
+
return filePath.endsWith('.rs');
|
|
51
|
+
}
|
|
52
|
+
extractRoutesAndCommands(filePath, content) {
|
|
53
|
+
const items = [];
|
|
54
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
55
|
+
const tauriMatches = Array.from(content.matchAll(/#\[tauri::command\]\s*(?:pub\s+)?(?:async\s+)?fn\s+(\w+)\s*\(([^)]*)\)/g));
|
|
56
|
+
for (const match of tauriMatches) {
|
|
57
|
+
items.push({
|
|
58
|
+
file: normalized,
|
|
59
|
+
framework: 'Tauri',
|
|
60
|
+
identifier: match[1],
|
|
61
|
+
signature: `fn ${match[1]}(${match[2].trim()})`
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return items;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type PoolConfig } from './pool_resolver.js';
|
|
2
|
+
import type { RepositorySkeleton, CodebaseKnowledgeGraph, GraphNode, GraphEdge, GraphNeighborhood, KnowledgeUnitContent } from './types.js';
|
|
3
|
+
export interface GraphCacheOptions {
|
|
4
|
+
useCache?: boolean;
|
|
5
|
+
cachePath?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class GraphBuilder {
|
|
8
|
+
private repoRoot;
|
|
9
|
+
poolConfig: PoolConfig;
|
|
10
|
+
repositoryRoot: string;
|
|
11
|
+
private static inMemoryCache;
|
|
12
|
+
private static knowledgeUnitsCache;
|
|
13
|
+
static clearCache(): void;
|
|
14
|
+
constructor(repoRoot: string, poolDir?: string);
|
|
15
|
+
private detectRepositoryRoot;
|
|
16
|
+
private getKnowledgeMaxMtime;
|
|
17
|
+
private getStandardsMtime;
|
|
18
|
+
/**
|
|
19
|
+
* Resolves a file path relative to repositoryRoot when scanning a narrow subproject,
|
|
20
|
+
* ensuring consistent top-level bounded context domain tagging across monorepos.
|
|
21
|
+
*/
|
|
22
|
+
resolveRelativePathAndDomain(filePath: string): {
|
|
23
|
+
relPath: string;
|
|
24
|
+
domain?: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Deterministically builds a Codebase Knowledge Graph (CKG) from the harvested
|
|
28
|
+
* skeleton and loaded Knowledge Units (0 LLM tokens).
|
|
29
|
+
*/
|
|
30
|
+
buildGraph(skeleton: RepositorySkeleton, customUnits?: KnowledgeUnitContent[], options?: GraphCacheOptions): Promise<CodebaseKnowledgeGraph>;
|
|
31
|
+
/**
|
|
32
|
+
* Traverses the graph and extracts the 1-hop and 2-hop topological neighborhood
|
|
33
|
+
* surrounding a target node, formatted as an LLM-ready prompt slice.
|
|
34
|
+
*/
|
|
35
|
+
extractNeighborhood(graph: CodebaseKnowledgeGraph, targetSearch: string, maxHops?: number): GraphNeighborhood | null;
|
|
36
|
+
/**
|
|
37
|
+
* Generates a valid GitHub-flavored Mermaid graph diagram from the graph.
|
|
38
|
+
* Supports domain/project subgraph clustering to provide high-level architectural structure.
|
|
39
|
+
*/
|
|
40
|
+
exportMermaid(graph: CodebaseKnowledgeGraph, filterNodesOrOptions?: GraphNode[] | {
|
|
41
|
+
clustered?: boolean;
|
|
42
|
+
maxNodes?: number;
|
|
43
|
+
nodeTypes?: string[] | string;
|
|
44
|
+
}, filterEdges?: GraphEdge[], options?: {
|
|
45
|
+
clustered?: boolean;
|
|
46
|
+
maxNodes?: number;
|
|
47
|
+
nodeTypes?: string[] | string;
|
|
48
|
+
}): string;
|
|
49
|
+
loadKnowledgeUnits(): KnowledgeUnitContent[];
|
|
50
|
+
/**
|
|
51
|
+
* Evaluates if a Knowledge Unit applies to a given file path using dual-path matching
|
|
52
|
+
* (both targetDir-relative and repositoryRoot-relative) with case-insensitive glob support.
|
|
53
|
+
*/
|
|
54
|
+
matchesAppliesTo(unit: KnowledgeUnitContent, filePath: string): boolean;
|
|
55
|
+
private extractEndpointRoute;
|
|
56
|
+
private normalizeRoutePath;
|
|
57
|
+
private routesMatch;
|
|
58
|
+
private canonicalEventName;
|
|
59
|
+
/**
|
|
60
|
+
* Fast 0-token symbol/node search across the graph.
|
|
61
|
+
*/
|
|
62
|
+
searchNodes(graph: CodebaseKnowledgeGraph, params: {
|
|
63
|
+
query: string;
|
|
64
|
+
type?: string;
|
|
65
|
+
domain?: string;
|
|
66
|
+
limit?: number;
|
|
67
|
+
}): Array<{
|
|
68
|
+
id: string;
|
|
69
|
+
label: string;
|
|
70
|
+
type: string;
|
|
71
|
+
file?: string;
|
|
72
|
+
signature?: string;
|
|
73
|
+
domain?: string;
|
|
74
|
+
}>;
|
|
75
|
+
/**
|
|
76
|
+
* Blast-radius and inbound dependent calculation.
|
|
77
|
+
*/
|
|
78
|
+
calculateInboundImpact(graph: CodebaseKnowledgeGraph, targetSearch: string, options?: {
|
|
79
|
+
maxDepth?: number;
|
|
80
|
+
}): {
|
|
81
|
+
targetNode: string;
|
|
82
|
+
directCallers: string[];
|
|
83
|
+
affectedEndpoints: string[];
|
|
84
|
+
topologicalProjects: string[];
|
|
85
|
+
invariants: string[];
|
|
86
|
+
};
|
|
87
|
+
}
|