quackstack 1.0.0 ā 1.0.2
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/dist/commands/ingest.js +27 -23
- package/dist/commands/search.js +12 -6
- package/dist/lib/ai-provider.js +1 -1
- package/dist/repl.js +25 -21
- package/package.json +7 -6
package/dist/commands/ingest.js
CHANGED
|
@@ -11,31 +11,35 @@ export async function ingest(rootDir, projectName, silent = false) {
|
|
|
11
11
|
if (!silent)
|
|
12
12
|
console.log(`Found ${files.length} files to process`);
|
|
13
13
|
let processedCount = 0;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
embedding
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
14
|
+
const BATCH_SIZE = 10;
|
|
15
|
+
for (let i = 0; i < files.length; i += BATCH_SIZE) {
|
|
16
|
+
const batch = files.slice(i, i + BATCH_SIZE);
|
|
17
|
+
await Promise.all(batch.map(async (filePath) => {
|
|
18
|
+
try {
|
|
19
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
20
|
+
const chunks = chunkCode(content, filePath);
|
|
21
|
+
for (const chunk of chunks) {
|
|
22
|
+
const embedding = await aiClient.getEmbeddings(chunk.content);
|
|
23
|
+
await saveToDB({
|
|
24
|
+
content: chunk.content,
|
|
25
|
+
embedding,
|
|
26
|
+
filePath,
|
|
27
|
+
projectName,
|
|
28
|
+
language: path.extname(filePath),
|
|
29
|
+
functionName: chunk.functionName,
|
|
30
|
+
lineStart: chunk.lineStart,
|
|
31
|
+
lineEnd: chunk.lineEnd,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
processedCount++;
|
|
35
|
+
if (!silent && processedCount % 10 === 0) {
|
|
36
|
+
console.log(`Processed ${processedCount}/${files.length} files...`);
|
|
37
|
+
}
|
|
30
38
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
console.log(`Processed ${processedCount}/${files.length} files...`);
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error(`Error processing ${filePath}:`, error);
|
|
34
41
|
}
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
console.error(`Error processing ${filePath}:`, error);
|
|
38
|
-
}
|
|
42
|
+
}));
|
|
39
43
|
}
|
|
40
44
|
if (!silent)
|
|
41
45
|
console.log(`Done! Processed ${processedCount} files.`);
|
package/dist/commands/search.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { client } from "../lib/database.js";
|
|
3
2
|
import { aiClient } from "../lib/ai-provider.js";
|
|
3
|
+
import { client } from "../lib/database.js";
|
|
4
4
|
function cosineSim(a, b) {
|
|
5
5
|
let dot = 0, normA = 0, normB = 0;
|
|
6
6
|
for (let i = 0; i < a.length; i++) {
|
|
@@ -15,16 +15,22 @@ export async function search(query, projectName) {
|
|
|
15
15
|
const snippets = await client.codeSnippet.findMany({
|
|
16
16
|
where: { projectName },
|
|
17
17
|
});
|
|
18
|
-
const
|
|
19
|
-
.map(snippet => ({
|
|
18
|
+
const scored = snippets.map(snippet => ({
|
|
20
19
|
id: snippet.id,
|
|
21
20
|
content: snippet.content,
|
|
22
21
|
filePath: snippet.filePath,
|
|
23
22
|
functionName: snippet.functionName,
|
|
24
23
|
score: cosineSim(queryEmbedding, snippet.embedding),
|
|
25
|
-
}))
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
}));
|
|
25
|
+
scored.sort((a, b) => b.score - a.score);
|
|
26
|
+
const seenFiles = new Set();
|
|
27
|
+
const ranked = scored.filter(item => {
|
|
28
|
+
if (seenFiles.has(item.filePath)) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
seenFiles.add(item.filePath);
|
|
32
|
+
return true;
|
|
33
|
+
}).slice(0, 5);
|
|
28
34
|
const context = ranked
|
|
29
35
|
.map((r, i) => `[${i + 1}] ${r.filePath}${r.functionName ? ` (${r.functionName})` : ""}\n${r.content}`)
|
|
30
36
|
.join("\n\n---\n\n");
|
package/dist/lib/ai-provider.js
CHANGED
package/dist/repl.js
CHANGED
|
@@ -25,23 +25,24 @@ export async function startREPL(forceReindex = false) {
|
|
|
25
25
|
const rl = readline.createInterface({
|
|
26
26
|
input: process.stdin,
|
|
27
27
|
output: process.stdout,
|
|
28
|
-
|
|
28
|
+
terminal: true
|
|
29
29
|
});
|
|
30
30
|
console.log("š” Tip: Press Ctrl+C to exit\n");
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
const askQuestion = () => {
|
|
32
|
+
rl.question("š„ Quack! How can I help? > ", async (input) => {
|
|
33
|
+
const trimmed = input.trim();
|
|
34
|
+
if (!trimmed) {
|
|
35
|
+
askQuestion();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
rl.pause();
|
|
40
|
+
const { answer, sources } = await search(trimmed, PROJECT_NAME);
|
|
41
|
+
console.log(`\n${answer}\n`);
|
|
42
42
|
const detailRL = readline.createInterface({
|
|
43
43
|
input: process.stdin,
|
|
44
|
-
output: process.stdout
|
|
44
|
+
output: process.stdout,
|
|
45
|
+
terminal: true
|
|
45
46
|
});
|
|
46
47
|
detailRL.question("š” Want more details? (y/n) > ", (ans) => {
|
|
47
48
|
if (ans.toLowerCase() === "y") {
|
|
@@ -54,15 +55,18 @@ export async function startREPL(forceReindex = false) {
|
|
|
54
55
|
}
|
|
55
56
|
detailRL.close();
|
|
56
57
|
console.log();
|
|
57
|
-
|
|
58
|
+
rl.resume();
|
|
59
|
+
askQuestion();
|
|
58
60
|
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
console.error("ā Error:", error instanceof Error ? error.message : "Unknown error");
|
|
64
|
+
rl.resume();
|
|
65
|
+
askQuestion();
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
askQuestion();
|
|
66
70
|
rl.on("close", () => {
|
|
67
71
|
console.log("\nš Happy coding!");
|
|
68
72
|
process.exit(0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quackstack",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Your cracked unpaid intern for all things codebase related! AI-powered codebase search and Q&A.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/cli.cjs",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"dist",
|
|
12
12
|
"prisma",
|
|
13
13
|
"README.md",
|
|
14
|
-
"LICENSE"
|
|
14
|
+
"LICENSE",
|
|
15
|
+
".npmrc"
|
|
15
16
|
],
|
|
16
17
|
"publishConfig": {
|
|
17
18
|
"access": "public"
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
"build": "tsc -b",
|
|
21
22
|
"dev": "tsc -b && node dist/cli.cjs",
|
|
22
23
|
"prepare": "prisma generate",
|
|
23
|
-
"
|
|
24
|
+
"postinstall": "prisma generate"
|
|
24
25
|
},
|
|
25
26
|
"keywords": [
|
|
26
27
|
"cli",
|
|
@@ -57,13 +58,13 @@
|
|
|
57
58
|
"chalk-animation": "^2.0.3",
|
|
58
59
|
"commander": "^14.0.1",
|
|
59
60
|
"dotenv": "^17.2.3",
|
|
60
|
-
"openai": "^6.0.1"
|
|
61
|
+
"openai": "^6.0.1",
|
|
62
|
+
"prisma": "^6.16.3"
|
|
61
63
|
},
|
|
62
64
|
"devDependencies": {
|
|
63
65
|
"@types/babel__traverse": "^7.28.0",
|
|
64
66
|
"@types/chalk-animation": "^1.6.3",
|
|
65
67
|
"@types/node": "^20.0.0",
|
|
66
|
-
"prisma": "^6.16.3",
|
|
67
68
|
"typescript": "^5.9.3"
|
|
68
69
|
}
|
|
69
|
-
}
|
|
70
|
+
}
|