@esankhan3/anvil-knowledge-core 0.1.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 +194 -0
- package/dist/__tests__/chunker.test.d.ts +10 -0
- package/dist/__tests__/chunker.test.d.ts.map +1 -0
- package/dist/__tests__/chunker.test.js +161 -0
- package/dist/__tests__/chunker.test.js.map +1 -0
- package/dist/__tests__/query-classifier.test.d.ts +5 -0
- package/dist/__tests__/query-classifier.test.d.ts.map +1 -0
- package/dist/__tests__/query-classifier.test.js +158 -0
- package/dist/__tests__/query-classifier.test.js.map +1 -0
- package/dist/__tests__/retriever-defaults.test.d.ts +12 -0
- package/dist/__tests__/retriever-defaults.test.d.ts.map +1 -0
- package/dist/__tests__/retriever-defaults.test.js +37 -0
- package/dist/__tests__/retriever-defaults.test.js.map +1 -0
- package/dist/__tests__/structural-hasher.test.d.ts +5 -0
- package/dist/__tests__/structural-hasher.test.d.ts.map +1 -0
- package/dist/__tests__/structural-hasher.test.js +185 -0
- package/dist/__tests__/structural-hasher.test.js.map +1 -0
- package/dist/ast-graph-builder.d.ts +38 -0
- package/dist/ast-graph-builder.d.ts.map +1 -0
- package/dist/ast-graph-builder.js +1041 -0
- package/dist/ast-graph-builder.js.map +1 -0
- package/dist/chunker.d.ts +47 -0
- package/dist/chunker.d.ts.map +1 -0
- package/dist/chunker.js +428 -0
- package/dist/chunker.js.map +1 -0
- package/dist/claude-runner.d.ts +10 -0
- package/dist/claude-runner.d.ts.map +1 -0
- package/dist/claude-runner.js +10 -0
- package/dist/claude-runner.js.map +1 -0
- package/dist/config.d.ts +36 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +83 -0
- package/dist/config.js.map +1 -0
- package/dist/cross-repo-detector.d.ts +7 -0
- package/dist/cross-repo-detector.d.ts.map +1 -0
- package/dist/cross-repo-detector.js +990 -0
- package/dist/cross-repo-detector.js.map +1 -0
- package/dist/embedder.d.ts +84 -0
- package/dist/embedder.d.ts.map +1 -0
- package/dist/embedder.js +378 -0
- package/dist/embedder.js.map +1 -0
- package/dist/file-walker.d.ts +18 -0
- package/dist/file-walker.d.ts.map +1 -0
- package/dist/file-walker.js +221 -0
- package/dist/file-walker.js.map +1 -0
- package/dist/git-diff.d.ts +32 -0
- package/dist/git-diff.d.ts.map +1 -0
- package/dist/git-diff.js +145 -0
- package/dist/git-diff.js.map +1 -0
- package/dist/graph-metrics.d.ts +31 -0
- package/dist/graph-metrics.d.ts.map +1 -0
- package/dist/graph-metrics.js +277 -0
- package/dist/graph-metrics.js.map +1 -0
- package/dist/graph-query.d.ts +8 -0
- package/dist/graph-query.d.ts.map +1 -0
- package/dist/graph-query.js +79 -0
- package/dist/graph-query.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/indexer.d.ts +98 -0
- package/dist/indexer.d.ts.map +1 -0
- package/dist/indexer.js +635 -0
- package/dist/indexer.js.map +1 -0
- package/dist/project-graph-builder-core.d.ts +48 -0
- package/dist/project-graph-builder-core.d.ts.map +1 -0
- package/dist/project-graph-builder-core.js +213 -0
- package/dist/project-graph-builder-core.js.map +1 -0
- package/dist/project-graph-builder.d.ts +39 -0
- package/dist/project-graph-builder.d.ts.map +1 -0
- package/dist/project-graph-builder.js +640 -0
- package/dist/project-graph-builder.js.map +1 -0
- package/dist/query-classifier.d.ts +38 -0
- package/dist/query-classifier.d.ts.map +1 -0
- package/dist/query-classifier.js +199 -0
- package/dist/query-classifier.js.map +1 -0
- package/dist/query-router.d.ts +82 -0
- package/dist/query-router.d.ts.map +1 -0
- package/dist/query-router.js +278 -0
- package/dist/query-router.js.map +1 -0
- package/dist/rag-evaluator.d.ts +53 -0
- package/dist/rag-evaluator.d.ts.map +1 -0
- package/dist/rag-evaluator.js +217 -0
- package/dist/rag-evaluator.js.map +1 -0
- package/dist/repo-profiler.d.ts +62 -0
- package/dist/repo-profiler.d.ts.map +1 -0
- package/dist/repo-profiler.js +488 -0
- package/dist/repo-profiler.js.map +1 -0
- package/dist/reranker.d.ts +8 -0
- package/dist/reranker.d.ts.map +1 -0
- package/dist/reranker.js +250 -0
- package/dist/reranker.js.map +1 -0
- package/dist/retriever.d.ts +42 -0
- package/dist/retriever.d.ts.map +1 -0
- package/dist/retriever.js +320 -0
- package/dist/retriever.js.map +1 -0
- package/dist/semantic-edge-detector.d.ts +28 -0
- package/dist/semantic-edge-detector.d.ts.map +1 -0
- package/dist/semantic-edge-detector.js +191 -0
- package/dist/semantic-edge-detector.js.map +1 -0
- package/dist/service-mesh-inferrer.d.ts +57 -0
- package/dist/service-mesh-inferrer.d.ts.map +1 -0
- package/dist/service-mesh-inferrer.js +322 -0
- package/dist/service-mesh-inferrer.js.map +1 -0
- package/dist/structural-hasher.d.ts +57 -0
- package/dist/structural-hasher.d.ts.map +1 -0
- package/dist/structural-hasher.js +350 -0
- package/dist/structural-hasher.js.map +1 -0
- package/dist/tree-sitter-parser.d.ts +71 -0
- package/dist/tree-sitter-parser.d.ts.map +1 -0
- package/dist/tree-sitter-parser.js +633 -0
- package/dist/tree-sitter-parser.js.map +1 -0
- package/dist/types.d.ts +179 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/vector-store.d.ts +56 -0
- package/dist/vector-store.d.ts.map +1 -0
- package/dist/vector-store.js +299 -0
- package/dist/vector-store.js.map +1 -0
- package/dist/workspace-detector.d.ts +11 -0
- package/dist/workspace-detector.d.ts.map +1 -0
- package/dist/workspace-detector.js +587 -0
- package/dist/workspace-detector.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Autonomous Repo Profiler (WS-1)
|
|
3
|
+
*
|
|
4
|
+
* Given a list of repos with zero manual config, reads signal-dense
|
|
5
|
+
* "fingerprint" files and sends them to an LLM for structured profiling.
|
|
6
|
+
* Each repo gets a RepoProfile describing its role, domain, tech stack,
|
|
7
|
+
* exposed/consumed endpoints, and entry points.
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync } from 'node:fs';
|
|
10
|
+
import { join, basename } from 'node:path';
|
|
11
|
+
import { createHash } from 'node:crypto';
|
|
12
|
+
import { runLLM } from './claude-runner.js';
|
|
13
|
+
import { getKnowledgeBasePath } from '@esankhan3/anvil-knowledge-core';
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// Constants
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
const MAX_FINGERPRINT_CHARS = 6000;
|
|
18
|
+
const MAX_CONCURRENT = 3;
|
|
19
|
+
const PROFILE_FILENAME = 'profile.json';
|
|
20
|
+
const PROFILER_SYSTEM_PROMPT = `You are a senior software architect analyzing a repository to understand its role in a larger system.
|
|
21
|
+
|
|
22
|
+
Given the fingerprint files below, produce a structured JSON profile.
|
|
23
|
+
|
|
24
|
+
Rules:
|
|
25
|
+
- Infer the repo's role from its code, not just its name
|
|
26
|
+
- For "domain", group by business function (e.g., "email-delivery", "billing", "user-management", "infrastructure")
|
|
27
|
+
- For "exposes", list what this repo provides: HTTP endpoints, Kafka topics it produces, gRPC services, etc.
|
|
28
|
+
- For "consumes", list what this repo depends on: Kafka topics it subscribes to, HTTP services it calls, databases it reads
|
|
29
|
+
- Be specific with identifiers: use actual topic names, endpoint paths, table names from the code
|
|
30
|
+
- If you can't determine something, use "unknown" -- don't guess
|
|
31
|
+
|
|
32
|
+
Respond with ONLY valid JSON matching this schema (no markdown fences):
|
|
33
|
+
{
|
|
34
|
+
"name": "string",
|
|
35
|
+
"role": "service | library | cli | worker | gateway | ui | schema | config | monorepo | unknown",
|
|
36
|
+
"domain": "string",
|
|
37
|
+
"description": "string (1-2 sentences)",
|
|
38
|
+
"technologies": ["string"],
|
|
39
|
+
"exposes": [{ "type": "http | grpc | kafka-producer | kafka-consumer | database | redis | s3 | websocket | cron | other", "identifier": "string", "description": "string" }],
|
|
40
|
+
"consumes": [{ "type": "http | grpc | kafka-producer | kafka-consumer | database | redis | s3 | websocket | cron | other", "identifier": "string", "description": "string" }],
|
|
41
|
+
"entryPoints": ["string"]
|
|
42
|
+
}`;
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
// File reading helpers
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
/** Safely read a file, returning null if missing or unreadable */
|
|
47
|
+
function safeReadFile(path, maxChars) {
|
|
48
|
+
try {
|
|
49
|
+
if (!existsSync(path))
|
|
50
|
+
return null;
|
|
51
|
+
const content = readFileSync(path, 'utf-8');
|
|
52
|
+
return maxChars ? content.slice(0, maxChars) : content;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** Safely read first N lines of a file */
|
|
59
|
+
function safeReadLines(path, maxLines) {
|
|
60
|
+
try {
|
|
61
|
+
if (!existsSync(path))
|
|
62
|
+
return null;
|
|
63
|
+
const content = readFileSync(path, 'utf-8');
|
|
64
|
+
return content.split('\n').slice(0, maxLines).join('\n');
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Find the first existing file from a list of candidates */
|
|
71
|
+
function findFirst(repoPath, candidates) {
|
|
72
|
+
for (const c of candidates) {
|
|
73
|
+
const full = join(repoPath, c);
|
|
74
|
+
if (existsSync(full))
|
|
75
|
+
return c;
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
/** Find first matching glob-like pattern in a directory */
|
|
80
|
+
function findFirstGlob(repoPath, dir, ext) {
|
|
81
|
+
const dirPath = join(repoPath, dir);
|
|
82
|
+
try {
|
|
83
|
+
if (!existsSync(dirPath))
|
|
84
|
+
return null;
|
|
85
|
+
const entries = readdirSync(dirPath);
|
|
86
|
+
const match = entries.find((e) => e.endsWith(ext));
|
|
87
|
+
return match ? join(dir, match) : null;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** Strip version numbers from package.json dependencies, keeping only names */
|
|
94
|
+
function extractPackageJsonEssentials(raw) {
|
|
95
|
+
try {
|
|
96
|
+
const pkg = JSON.parse(raw);
|
|
97
|
+
const essentials = {};
|
|
98
|
+
for (const key of ['name', 'description', 'scripts', 'dependencies', 'devDependencies', 'peerDependencies']) {
|
|
99
|
+
if (!(key in pkg))
|
|
100
|
+
continue;
|
|
101
|
+
if (key === 'scripts') {
|
|
102
|
+
essentials[key] = pkg[key];
|
|
103
|
+
}
|
|
104
|
+
else if (typeof pkg[key] === 'object' && pkg[key] !== null && key !== 'name' && key !== 'description') {
|
|
105
|
+
// For dependency maps, keep only the keys (package names)
|
|
106
|
+
essentials[key] = Object.keys(pkg[key]);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
essentials[key] = pkg[key];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return JSON.stringify(essentials, null, 2);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return raw;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/** Extract module path + require block from go.mod */
|
|
119
|
+
function extractGoModEssentials(raw) {
|
|
120
|
+
const lines = raw.split('\n');
|
|
121
|
+
const result = [];
|
|
122
|
+
let inRequire = false;
|
|
123
|
+
for (const line of lines) {
|
|
124
|
+
if (line.startsWith('module ')) {
|
|
125
|
+
result.push(line);
|
|
126
|
+
}
|
|
127
|
+
else if (line.startsWith('require')) {
|
|
128
|
+
inRequire = true;
|
|
129
|
+
result.push(line);
|
|
130
|
+
}
|
|
131
|
+
else if (inRequire) {
|
|
132
|
+
result.push(line);
|
|
133
|
+
if (line.trim() === ')')
|
|
134
|
+
inRequire = false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return result.join('\n');
|
|
138
|
+
}
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
// Fingerprint extraction
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
/**
|
|
143
|
+
* Extract signal-dense "fingerprint" files from a repo.
|
|
144
|
+
* Reads only the files most useful for understanding what the repo does,
|
|
145
|
+
* capped to ~6000 chars total. Fast — just file reads, no LLM.
|
|
146
|
+
*/
|
|
147
|
+
export async function extractFingerprint(repoPath) {
|
|
148
|
+
const repoName = basename(repoPath);
|
|
149
|
+
const files = [];
|
|
150
|
+
let totalChars = 0;
|
|
151
|
+
function addFile(relativePath, content) {
|
|
152
|
+
if (totalChars + content.length > MAX_FINGERPRINT_CHARS) {
|
|
153
|
+
// Try to fit a truncated version
|
|
154
|
+
const remaining = MAX_FINGERPRINT_CHARS - totalChars;
|
|
155
|
+
if (remaining > 200) {
|
|
156
|
+
files.push({ relativePath, content: content.slice(0, remaining) });
|
|
157
|
+
totalChars += remaining;
|
|
158
|
+
}
|
|
159
|
+
return false; // budget exhausted
|
|
160
|
+
}
|
|
161
|
+
files.push({ relativePath, content });
|
|
162
|
+
totalChars += content.length;
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
// 1. README.md — first 2000 chars
|
|
166
|
+
const readme = safeReadFile(join(repoPath, 'README.md'), 2000);
|
|
167
|
+
if (readme)
|
|
168
|
+
addFile('README.md', readme);
|
|
169
|
+
// 2. Dockerfile or docker-compose.yml — first 1500 chars
|
|
170
|
+
const dockerFile = findFirst(repoPath, ['Dockerfile', 'docker-compose.yml', 'docker-compose.yaml']);
|
|
171
|
+
if (dockerFile) {
|
|
172
|
+
const content = safeReadFile(join(repoPath, dockerFile), 1500);
|
|
173
|
+
if (content)
|
|
174
|
+
addFile(dockerFile, content);
|
|
175
|
+
}
|
|
176
|
+
// 3. Main entry point detection — first 100 lines
|
|
177
|
+
const entryPointCandidates = [
|
|
178
|
+
'main.go',
|
|
179
|
+
'src/index.ts',
|
|
180
|
+
'src/main.ts',
|
|
181
|
+
'src/index.js',
|
|
182
|
+
'app.py',
|
|
183
|
+
'main.py',
|
|
184
|
+
'index.ts',
|
|
185
|
+
'index.js',
|
|
186
|
+
];
|
|
187
|
+
// Also check cmd/*/main.go
|
|
188
|
+
const cmdMainGo = findFirstGlob(repoPath, 'cmd', 'main.go');
|
|
189
|
+
if (cmdMainGo)
|
|
190
|
+
entryPointCandidates.unshift(cmdMainGo);
|
|
191
|
+
// Check src/main/java/**/Application.java — simplified to first level
|
|
192
|
+
const javaApp = findFirstGlob(repoPath, 'src/main/java', 'Application.java');
|
|
193
|
+
if (javaApp)
|
|
194
|
+
entryPointCandidates.push(javaApp);
|
|
195
|
+
const entryPoint = findFirst(repoPath, entryPointCandidates);
|
|
196
|
+
if (entryPoint && totalChars < MAX_FINGERPRINT_CHARS) {
|
|
197
|
+
const content = safeReadLines(join(repoPath, entryPoint), 100);
|
|
198
|
+
if (content)
|
|
199
|
+
addFile(entryPoint, content);
|
|
200
|
+
}
|
|
201
|
+
// 4. Package manifest
|
|
202
|
+
if (totalChars < MAX_FINGERPRINT_CHARS) {
|
|
203
|
+
const manifestFile = findFirst(repoPath, ['package.json', 'go.mod', 'pyproject.toml', 'Cargo.toml', 'pom.xml']);
|
|
204
|
+
if (manifestFile) {
|
|
205
|
+
const raw = safeReadFile(join(repoPath, manifestFile));
|
|
206
|
+
if (raw) {
|
|
207
|
+
let content = raw;
|
|
208
|
+
if (manifestFile === 'package.json') {
|
|
209
|
+
content = extractPackageJsonEssentials(raw);
|
|
210
|
+
}
|
|
211
|
+
else if (manifestFile === 'go.mod') {
|
|
212
|
+
content = extractGoModEssentials(raw);
|
|
213
|
+
}
|
|
214
|
+
addFile(manifestFile, content);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// 5. CI config — first workflow file, first 1000 chars
|
|
219
|
+
if (totalChars < MAX_FINGERPRINT_CHARS) {
|
|
220
|
+
const ciFile = findFirstGlob(repoPath, '.github/workflows', '.yml')
|
|
221
|
+
?? findFirstGlob(repoPath, '.github/workflows', '.yaml');
|
|
222
|
+
if (ciFile) {
|
|
223
|
+
const content = safeReadFile(join(repoPath, ciFile), 1000);
|
|
224
|
+
if (content)
|
|
225
|
+
addFile(ciFile, content);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
// 6. API schemas
|
|
229
|
+
if (totalChars < MAX_FINGERPRINT_CHARS) {
|
|
230
|
+
const apiSchema = findFirst(repoPath, ['openapi.yaml', 'openapi.json', 'asyncapi.yaml']);
|
|
231
|
+
if (apiSchema) {
|
|
232
|
+
const content = safeReadFile(join(repoPath, apiSchema), 1500);
|
|
233
|
+
if (content)
|
|
234
|
+
addFile(apiSchema, content);
|
|
235
|
+
}
|
|
236
|
+
// Also check for .proto files
|
|
237
|
+
if (!apiSchema) {
|
|
238
|
+
const protoFile = findFirstGlob(repoPath, 'proto', '.proto')
|
|
239
|
+
?? findFirstGlob(repoPath, '.', '.proto');
|
|
240
|
+
if (protoFile) {
|
|
241
|
+
const content = safeReadFile(join(repoPath, protoFile), 1500);
|
|
242
|
+
if (content)
|
|
243
|
+
addFile(protoFile, content);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// 7. Kubernetes / deploy manifests — first found, first 500 chars
|
|
248
|
+
if (totalChars < MAX_FINGERPRINT_CHARS) {
|
|
249
|
+
const k8sFile = findFirstGlob(repoPath, 'k8s', '.yaml')
|
|
250
|
+
?? findFirstGlob(repoPath, 'k8s', '.yml')
|
|
251
|
+
?? findFirstGlob(repoPath, 'deploy', '.yaml')
|
|
252
|
+
?? findFirstGlob(repoPath, 'deploy', '.yml');
|
|
253
|
+
if (k8sFile) {
|
|
254
|
+
const content = safeReadFile(join(repoPath, k8sFile), 500);
|
|
255
|
+
if (content)
|
|
256
|
+
addFile(k8sFile, content);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
// Compute fingerprint hash from concatenated content
|
|
260
|
+
const hash = createHash('sha256');
|
|
261
|
+
for (const f of files) {
|
|
262
|
+
hash.update(f.relativePath);
|
|
263
|
+
hash.update(f.content);
|
|
264
|
+
}
|
|
265
|
+
const fingerprintHash = hash.digest('hex');
|
|
266
|
+
return {
|
|
267
|
+
repoPath,
|
|
268
|
+
repoName,
|
|
269
|
+
files,
|
|
270
|
+
totalChars,
|
|
271
|
+
fingerprintHash,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
// ---------------------------------------------------------------------------
|
|
275
|
+
// LLM profiling
|
|
276
|
+
// ---------------------------------------------------------------------------
|
|
277
|
+
/** Build the user message from fingerprint files */
|
|
278
|
+
function buildFingerprintText(fingerprint) {
|
|
279
|
+
const sections = fingerprint.files.map((f) => `### ${f.relativePath}\n\n${f.content}`);
|
|
280
|
+
return `Repository: ${fingerprint.repoName}\n\n${sections.join('\n\n---\n\n')}`;
|
|
281
|
+
}
|
|
282
|
+
/** Parse LLM response, handling markdown fences and partial JSON */
|
|
283
|
+
function parseLLMJson(raw) {
|
|
284
|
+
let text = raw.trim();
|
|
285
|
+
// Strip markdown code fences if present
|
|
286
|
+
const fenceMatch = text.match(/```(?:json)?\s*\n?([\s\S]*?)```/);
|
|
287
|
+
if (fenceMatch) {
|
|
288
|
+
text = fenceMatch[1].trim();
|
|
289
|
+
}
|
|
290
|
+
// Try direct parse first
|
|
291
|
+
try {
|
|
292
|
+
return JSON.parse(text);
|
|
293
|
+
}
|
|
294
|
+
catch {
|
|
295
|
+
// Attempt to extract JSON object from surrounding text
|
|
296
|
+
const jsonStart = text.indexOf('{');
|
|
297
|
+
const jsonEnd = text.lastIndexOf('}');
|
|
298
|
+
if (jsonStart !== -1 && jsonEnd > jsonStart) {
|
|
299
|
+
try {
|
|
300
|
+
return JSON.parse(text.slice(jsonStart, jsonEnd + 1));
|
|
301
|
+
}
|
|
302
|
+
catch {
|
|
303
|
+
throw new Error(`Failed to parse LLM response as JSON: ${text.slice(0, 200)}...`);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
throw new Error(`No JSON object found in LLM response: ${text.slice(0, 200)}...`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Send a repo fingerprint to an LLM and get a structured RepoProfile back.
|
|
311
|
+
*/
|
|
312
|
+
export async function profileRepo(fingerprint, opts) {
|
|
313
|
+
const model = opts?.model ?? 'claude-sonnet-4-6';
|
|
314
|
+
const fingerprintText = buildFingerprintText(fingerprint);
|
|
315
|
+
const result = await runLLM(fingerprintText, PROFILER_SYSTEM_PROMPT, { model, provider: opts?.provider, timeoutMs: 600_000 });
|
|
316
|
+
const parsed = parseLLMJson(result.result);
|
|
317
|
+
// Build the full RepoProfile with metadata
|
|
318
|
+
const profile = {
|
|
319
|
+
name: parsed.name ?? fingerprint.repoName,
|
|
320
|
+
role: parsed.role ?? 'unknown',
|
|
321
|
+
domain: parsed.domain ?? 'unknown',
|
|
322
|
+
description: parsed.description ?? '',
|
|
323
|
+
technologies: parsed.technologies ?? [],
|
|
324
|
+
exposes: parsed.exposes ?? [],
|
|
325
|
+
consumes: parsed.consumes ?? [],
|
|
326
|
+
entryPoints: parsed.entryPoints ?? [],
|
|
327
|
+
profiledAt: new Date().toISOString(),
|
|
328
|
+
profiledBy: model,
|
|
329
|
+
fingerprintHash: fingerprint.fingerprintHash,
|
|
330
|
+
};
|
|
331
|
+
return profile;
|
|
332
|
+
}
|
|
333
|
+
// ---------------------------------------------------------------------------
|
|
334
|
+
// Batch profiling
|
|
335
|
+
// ---------------------------------------------------------------------------
|
|
336
|
+
/**
|
|
337
|
+
* Profile all repos in a project. Features:
|
|
338
|
+
* - Caching: skips repos whose fingerprint hash hasn't changed
|
|
339
|
+
* - Parallel: up to 3 concurrent profiling calls
|
|
340
|
+
* - Progress: reports via onProgress callback
|
|
341
|
+
* - Error handling: continues if one repo fails
|
|
342
|
+
* - Storage: saves each profile to {kbPath}/{repoName}/profile.json
|
|
343
|
+
*/
|
|
344
|
+
export async function profileProject(project, repos, opts) {
|
|
345
|
+
const progress = opts?.onProgress ?? (() => { });
|
|
346
|
+
const kbPath = getKnowledgeBasePath(project);
|
|
347
|
+
const profiles = [];
|
|
348
|
+
const errors = [];
|
|
349
|
+
progress(`Profiling ${repos.length} repos...`);
|
|
350
|
+
// Extract all fingerprints first (fast, no LLM)
|
|
351
|
+
const fingerprints = await Promise.all(repos.map(async (repo) => {
|
|
352
|
+
try {
|
|
353
|
+
const fp = await extractFingerprint(repo.path);
|
|
354
|
+
return { repo, fingerprint: fp };
|
|
355
|
+
}
|
|
356
|
+
catch (err) {
|
|
357
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
358
|
+
errors.push({ name: repo.name, error: msg });
|
|
359
|
+
progress(` [WARN] Failed to extract fingerprint for ${repo.name}: ${msg}`);
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
}));
|
|
363
|
+
const validFingerprints = fingerprints.filter((f) => f !== null);
|
|
364
|
+
// Check cache and filter repos that need profiling
|
|
365
|
+
const needsProfiling = [];
|
|
366
|
+
for (const item of validFingerprints) {
|
|
367
|
+
if (opts?.force) {
|
|
368
|
+
needsProfiling.push(item);
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
const cached = loadCachedProfile(kbPath, item.repo.name);
|
|
372
|
+
if (cached && cached.fingerprintHash === item.fingerprint.fingerprintHash) {
|
|
373
|
+
progress(` [CACHED] ${item.repo.name} (fingerprint unchanged)`);
|
|
374
|
+
profiles.push(cached);
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
needsProfiling.push(item);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (needsProfiling.length === 0) {
|
|
381
|
+
progress('All repos cached, no profiling needed.');
|
|
382
|
+
return profiles;
|
|
383
|
+
}
|
|
384
|
+
progress(`Profiling ${needsProfiling.length} repos (${validFingerprints.length - needsProfiling.length} cached)...`);
|
|
385
|
+
// Profile in batches of MAX_CONCURRENT
|
|
386
|
+
for (let i = 0; i < needsProfiling.length; i += MAX_CONCURRENT) {
|
|
387
|
+
const batch = needsProfiling.slice(i, i + MAX_CONCURRENT);
|
|
388
|
+
const batchResults = await Promise.allSettled(batch.map(async (item) => {
|
|
389
|
+
progress(` [PROFILING] ${item.repo.name} (${item.fingerprint.files.length} files, ${item.fingerprint.totalChars} chars)`);
|
|
390
|
+
const profile = await profileRepo(item.fingerprint, { model: opts?.model, provider: opts?.provider });
|
|
391
|
+
return { repo: item.repo, profile };
|
|
392
|
+
}));
|
|
393
|
+
for (const result of batchResults) {
|
|
394
|
+
if (result.status === 'fulfilled') {
|
|
395
|
+
const { repo, profile } = result.value;
|
|
396
|
+
profiles.push(profile);
|
|
397
|
+
// Persist to disk
|
|
398
|
+
saveProfileToDisk(kbPath, repo.name, profile);
|
|
399
|
+
progress(` [DONE] ${repo.name} -> ${profile.role} (${profile.domain})`);
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
const reason = result.reason instanceof Error ? result.reason.message : String(result.reason);
|
|
403
|
+
// Try to find which repo this was for
|
|
404
|
+
const batchIndex = batchResults.indexOf(result);
|
|
405
|
+
const repoName = batch[batchIndex]?.repo.name ?? 'unknown';
|
|
406
|
+
errors.push({ name: repoName, error: reason });
|
|
407
|
+
progress(` [WARN] Failed to profile ${repoName}: ${reason}`);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (errors.length > 0) {
|
|
412
|
+
progress(`Completed with ${errors.length} error(s): ${errors.map((e) => e.name).join(', ')}`);
|
|
413
|
+
}
|
|
414
|
+
return profiles;
|
|
415
|
+
}
|
|
416
|
+
// ---------------------------------------------------------------------------
|
|
417
|
+
// Cache / persistence
|
|
418
|
+
// ---------------------------------------------------------------------------
|
|
419
|
+
/** Load a cached profile from the KB directory */
|
|
420
|
+
function loadCachedProfile(kbPath, repoName) {
|
|
421
|
+
const profilePath = join(kbPath, repoName, PROFILE_FILENAME);
|
|
422
|
+
try {
|
|
423
|
+
if (!existsSync(profilePath))
|
|
424
|
+
return null;
|
|
425
|
+
const raw = readFileSync(profilePath, 'utf-8');
|
|
426
|
+
return JSON.parse(raw);
|
|
427
|
+
}
|
|
428
|
+
catch {
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
/** Save a profile to disk under {kbPath}/{repoName}/profile.json */
|
|
433
|
+
function saveProfileToDisk(kbPath, repoName, profile) {
|
|
434
|
+
const repoDir = join(kbPath, repoName);
|
|
435
|
+
mkdirSync(repoDir, { recursive: true });
|
|
436
|
+
const profilePath = join(repoDir, PROFILE_FILENAME);
|
|
437
|
+
writeFileSync(profilePath, JSON.stringify(profile, null, 2), 'utf-8');
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Load a cached profile for a single repo.
|
|
441
|
+
* Returns null if no cached profile exists.
|
|
442
|
+
*/
|
|
443
|
+
export function loadProfile(project, repoName) {
|
|
444
|
+
const kbPath = getKnowledgeBasePath(project);
|
|
445
|
+
const profilePath = join(kbPath, repoName, PROFILE_FILENAME);
|
|
446
|
+
try {
|
|
447
|
+
if (!existsSync(profilePath))
|
|
448
|
+
return null;
|
|
449
|
+
const raw = readFileSync(profilePath, 'utf-8');
|
|
450
|
+
return JSON.parse(raw);
|
|
451
|
+
}
|
|
452
|
+
catch {
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Load all cached profiles for a project.
|
|
458
|
+
* Scans the project's knowledge base directory for profile.json files.
|
|
459
|
+
*/
|
|
460
|
+
export function loadAllProfiles(project) {
|
|
461
|
+
const kbPath = getKnowledgeBasePath(project);
|
|
462
|
+
const profiles = [];
|
|
463
|
+
try {
|
|
464
|
+
if (!existsSync(kbPath))
|
|
465
|
+
return profiles;
|
|
466
|
+
const entries = readdirSync(kbPath, { withFileTypes: true });
|
|
467
|
+
for (const entry of entries) {
|
|
468
|
+
if (!entry.isDirectory())
|
|
469
|
+
continue;
|
|
470
|
+
const profilePath = join(kbPath, entry.name, PROFILE_FILENAME);
|
|
471
|
+
try {
|
|
472
|
+
if (!existsSync(profilePath))
|
|
473
|
+
continue;
|
|
474
|
+
const raw = readFileSync(profilePath, 'utf-8');
|
|
475
|
+
const profile = JSON.parse(raw);
|
|
476
|
+
profiles.push(profile);
|
|
477
|
+
}
|
|
478
|
+
catch {
|
|
479
|
+
// Skip malformed profile files
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
catch {
|
|
484
|
+
// KB directory doesn't exist or isn't readable
|
|
485
|
+
}
|
|
486
|
+
return profiles;
|
|
487
|
+
}
|
|
488
|
+
//# sourceMappingURL=repo-profiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repo-profiler.js","sourceRoot":"","sources":["../src/repo-profiler.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAmBvE,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,MAAM,qBAAqB,GAAG,IAAI,CAAC;AACnC,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAExC,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;;;;;;;;;;EAsB7B,CAAC;AAEH,8EAA8E;AAC9E,uBAAuB;AACvB,8EAA8E;AAE9E,kEAAkE;AAClE,SAAS,YAAY,CAAC,IAAY,EAAE,QAAiB;IACnD,IAAI,CAAC;QACH,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<Array<{
|
|
3
|
+
index: number;
|
|
4
|
+
score: number;
|
|
5
|
+
}>>;
|
|
6
|
+
}
|
|
7
|
+
export declare function createReranker(provider: string): Reranker | null;
|
|
8
|
+
//# sourceMappingURL=reranker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reranker.d.ts","sourceRoot":"","sources":["../src/reranker.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,QAAQ;IACvB,MAAM,CACJ,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EAAE,EACnB,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;CACrD;AA4RD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAoBhE"}
|