scai 0.1.65 → 0.1.66
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/AskCmd.js
CHANGED
|
@@ -33,7 +33,7 @@ export async function runAskCommand(query) {
|
|
|
33
33
|
fallbackResults.forEach((file, i) => {
|
|
34
34
|
console.log(` ${i + 1}. 🔎 Fallback Match: ${file.path}`);
|
|
35
35
|
});
|
|
36
|
-
// 🟩 STEP 2: Merge results
|
|
36
|
+
// 🟩 STEP 2: Merge results
|
|
37
37
|
const seen = new Set();
|
|
38
38
|
const combinedResults = [];
|
|
39
39
|
for (const file of semanticResults) {
|
|
@@ -71,33 +71,39 @@ export async function runAskCommand(query) {
|
|
|
71
71
|
let code = '';
|
|
72
72
|
let topSummary = topFile.summary || '(No summary available)';
|
|
73
73
|
let topFunctions = [];
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
74
|
+
const fileFunctions = {};
|
|
75
|
+
// Truncate summary
|
|
76
|
+
topSummary = topSummary.split('\n').slice(0, MAX_SUMMARY_LINES).join('\n');
|
|
78
77
|
const allFileIds = combinedResults
|
|
79
78
|
.map(file => file.id)
|
|
80
79
|
.filter((id) => typeof id === 'number');
|
|
81
|
-
const allFunctionsMap = getFunctionsForFiles(allFileIds);
|
|
80
|
+
const allFunctionsMap = getFunctionsForFiles(allFileIds); // Record<number, Function[]>
|
|
82
81
|
try {
|
|
83
82
|
code = fs.readFileSync(filepath, 'utf-8');
|
|
84
83
|
const topFileId = topFile.id;
|
|
85
|
-
topFunctions = allFunctionsMap[topFileId]?.map(fn =>
|
|
84
|
+
topFunctions = allFunctionsMap[topFileId]?.map(fn => ({
|
|
85
|
+
name: fn.name,
|
|
86
|
+
content: fn.content
|
|
87
|
+
})) || [];
|
|
86
88
|
}
|
|
87
89
|
catch (err) {
|
|
88
90
|
console.warn(`⚠️ Failed to read or analyze top file (${filepath}):`, err);
|
|
89
91
|
}
|
|
90
|
-
// 🟩 STEP 5: Build relatedFiles with functions
|
|
92
|
+
// 🟩 STEP 5: Build relatedFiles with functions and fileFunctions
|
|
91
93
|
const relatedFiles = combinedResults.slice(0, RELATED_FILES_LIMIT).map(file => {
|
|
92
94
|
const fileId = file.id;
|
|
93
95
|
let summary = file.summary || '(No summary available)';
|
|
94
96
|
if (summary) {
|
|
95
97
|
summary = summary.split('\n').slice(0, MAX_SUMMARY_LINES).join('\n');
|
|
96
98
|
}
|
|
99
|
+
const functions = allFunctionsMap[fileId]?.map(fn => ({
|
|
100
|
+
name: fn.name,
|
|
101
|
+
content: fn.content || '(No content available)', // Assuming content is available
|
|
102
|
+
})) || [];
|
|
97
103
|
return {
|
|
98
104
|
path: file.path,
|
|
99
105
|
summary,
|
|
100
|
-
functions
|
|
106
|
+
functions,
|
|
101
107
|
};
|
|
102
108
|
});
|
|
103
109
|
// 🟩 STEP 6: Generate file tree
|
|
@@ -116,8 +122,9 @@ export async function runAskCommand(query) {
|
|
|
116
122
|
functions: topFunctions,
|
|
117
123
|
relatedFiles,
|
|
118
124
|
projectFileTree: fileTree || undefined,
|
|
125
|
+
fileFunctions,
|
|
119
126
|
});
|
|
120
|
-
// 🟩 STEP 8: Save prompt
|
|
127
|
+
// 🟩 STEP 8: Save prompt
|
|
121
128
|
try {
|
|
122
129
|
if (!fs.existsSync(SCAI_HOME))
|
|
123
130
|
fs.mkdirSync(SCAI_HOME, { recursive: true });
|
|
@@ -144,7 +151,7 @@ export async function runAskCommand(query) {
|
|
|
144
151
|
// 🟩 Helper: Prompt once
|
|
145
152
|
function promptOnce(promptText) {
|
|
146
153
|
return new Promise(resolve => {
|
|
147
|
-
console.log(promptText);
|
|
154
|
+
console.log(promptText);
|
|
148
155
|
const rl = readline.createInterface({
|
|
149
156
|
input: process.stdin,
|
|
150
157
|
output: process.stdout,
|
|
@@ -4,13 +4,26 @@ export function buildContextualPrompt({ baseInstruction, code, summary, function
|
|
|
4
4
|
parts.push(`📄 File Summary:\n${summary}`);
|
|
5
5
|
}
|
|
6
6
|
if (functions?.length) {
|
|
7
|
-
|
|
7
|
+
// Display each function's name and content
|
|
8
|
+
const formattedFunctions = functions
|
|
9
|
+
.map(fn => `• ${fn.name}:\n${fn.content}`)
|
|
10
|
+
.join('\n\n'); // Adds a line break between each function
|
|
11
|
+
parts.push(`🔧 Functions:\n${formattedFunctions}`);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
console.log(`🔧 No functions found `);
|
|
8
15
|
}
|
|
9
16
|
if (relatedFiles?.length) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
.
|
|
13
|
-
|
|
17
|
+
// Include functions from related files
|
|
18
|
+
const formattedRelatedFiles = relatedFiles
|
|
19
|
+
.map(f => {
|
|
20
|
+
const relatedFunctions = f.functions
|
|
21
|
+
.map(fn => ` • ${fn.name}:\n ${fn.content}`)
|
|
22
|
+
.join('\n\n'); // Adds a line break between related file functions
|
|
23
|
+
return `• ${f.path}: ${f.summary}\n${relatedFunctions}`;
|
|
24
|
+
})
|
|
25
|
+
.join('\n\n'); // Adds a line break between related files
|
|
26
|
+
parts.push(`📚 Related Files:\n${formattedRelatedFiles}`);
|
|
14
27
|
}
|
|
15
28
|
if (projectFileTree) {
|
|
16
29
|
parts.push(`📁 Project File Structure:\n\`\`\`\n${projectFileTree.trim()}\n\`\`\``);
|