scai 0.1.66 → 0.1.67

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.
@@ -7,7 +7,8 @@ import { generate } from '../lib/generate.js';
7
7
  import { buildContextualPrompt } from '../utils/buildContextualPrompt.js';
8
8
  import { generateFocusedFileTree } from '../utils/fileTree.js';
9
9
  import { log } from '../utils/log.js';
10
- import { PROMPT_LOG_PATH, SCAI_HOME, RELATED_FILES_LIMIT, MAX_SUMMARY_LINES, getIndexDir } from '../constants.js';
10
+ import { PROMPT_LOG_PATH, SCAI_HOME, RELATED_FILES_LIMIT, MAX_SUMMARY_LINES, getIndexDir, MAX_FUNCTION_LINES } from '../constants.js';
11
+ import chalk from 'chalk';
11
12
  export async function runAskCommand(query) {
12
13
  if (!query) {
13
14
  query = await promptOnce('šŸ’¬ Ask your question:\n');
@@ -81,10 +82,15 @@ export async function runAskCommand(query) {
81
82
  try {
82
83
  code = fs.readFileSync(filepath, 'utf-8');
83
84
  const topFileId = topFile.id;
84
- topFunctions = allFunctionsMap[topFileId]?.map(fn => ({
85
- name: fn.name,
86
- content: fn.content
87
- })) || [];
85
+ topFunctions = allFunctionsMap[topFileId]?.map(fn => {
86
+ const content = fn.content
87
+ ? fn.content.split('\n').slice(0, MAX_FUNCTION_LINES).join('\n')
88
+ : '(No content available)';
89
+ return {
90
+ name: fn.name,
91
+ content,
92
+ };
93
+ }) || [];
88
94
  }
89
95
  catch (err) {
90
96
  console.warn(`āš ļø Failed to read or analyze top file (${filepath}):`, err);
@@ -96,10 +102,15 @@ export async function runAskCommand(query) {
96
102
  if (summary) {
97
103
  summary = summary.split('\n').slice(0, MAX_SUMMARY_LINES).join('\n');
98
104
  }
99
- const functions = allFunctionsMap[fileId]?.map(fn => ({
100
- name: fn.name,
101
- content: fn.content || '(No content available)', // Assuming content is available
102
- })) || [];
105
+ const functions = allFunctionsMap[fileId]?.map(fn => {
106
+ const content = fn.content
107
+ ? fn.content.split('\n').slice(0, MAX_FUNCTION_LINES).join('\n')
108
+ : '(No content available)';
109
+ return {
110
+ name: fn.name,
111
+ content,
112
+ };
113
+ }) || [];
103
114
  return {
104
115
  path: file.path,
105
116
  summary,
@@ -115,6 +126,8 @@ export async function runAskCommand(query) {
115
126
  console.warn('āš ļø Could not generate file tree:', e);
116
127
  }
117
128
  // 🟩 STEP 7: Build prompt
129
+ console.log(chalk.blueBright('\nšŸ“¦ Building contextual prompt...'));
130
+ console.log(chalk.gray(`[runAskCommand] Calling buildContextualPrompt()`));
118
131
  const promptContent = buildContextualPrompt({
119
132
  baseInstruction: query,
120
133
  code,
@@ -124,6 +137,8 @@ export async function runAskCommand(query) {
124
137
  projectFileTree: fileTree || undefined,
125
138
  fileFunctions,
126
139
  });
140
+ console.log(chalk.greenBright('āœ… Prompt built successfully.'));
141
+ console.log(chalk.cyan(`[runAskCommand] Prompt token estimate: ~${Math.round(promptContent.length / 4)} tokens`));
127
142
  // 🟩 STEP 8: Save prompt
128
143
  try {
129
144
  if (!fs.existsSync(SCAI_HOME))
package/dist/constants.js CHANGED
@@ -61,3 +61,7 @@ export const CANDIDATE_LIMIT = 100;
61
61
  * Limit number of summary lines
62
62
  */
63
63
  export const MAX_SUMMARY_LINES = 12;
64
+ /**
65
+ * Limit number of function content
66
+ */
67
+ export const MAX_FUNCTION_LINES = 12;
@@ -1,33 +1,56 @@
1
- export function buildContextualPrompt({ baseInstruction, code, summary, functions, relatedFiles, projectFileTree }) {
1
+ // File: src/utils/buildContextualPrompt.ts
2
+ import chalk from 'chalk';
3
+ function estimateTokenCount(text) {
4
+ return Math.round(text.length / 4); // simple heuristic approximation
5
+ }
6
+ export function buildContextualPrompt({ baseInstruction, code, summary, functions, relatedFiles, projectFileTree, }) {
2
7
  const parts = [baseInstruction];
3
8
  if (summary) {
4
9
  parts.push(`šŸ“„ File Summary:\n${summary}`);
5
10
  }
6
11
  if (functions?.length) {
7
- // Display each function's name and content
8
12
  const formattedFunctions = functions
9
13
  .map(fn => `• ${fn.name}:\n${fn.content}`)
10
- .join('\n\n'); // Adds a line break between each function
14
+ .join('\n\n');
11
15
  parts.push(`šŸ”§ Functions:\n${formattedFunctions}`);
12
16
  }
13
17
  else {
14
- console.log(`šŸ”§ No functions found `);
18
+ console.log(chalk.gray(`[buildContextualPrompt]`) +
19
+ chalk.yellow(` āš ļø No functions found in top file.`));
15
20
  }
16
21
  if (relatedFiles?.length) {
17
- // Include functions from related files
18
22
  const formattedRelatedFiles = relatedFiles
19
23
  .map(f => {
20
24
  const relatedFunctions = f.functions
21
25
  .map(fn => ` • ${fn.name}:\n ${fn.content}`)
22
- .join('\n\n'); // Adds a line break between related file functions
26
+ .join('\n\n');
23
27
  return `• ${f.path}: ${f.summary}\n${relatedFunctions}`;
24
28
  })
25
- .join('\n\n'); // Adds a line break between related files
29
+ .join('\n\n');
26
30
  parts.push(`šŸ“š Related Files:\n${formattedRelatedFiles}`);
27
31
  }
28
32
  if (projectFileTree) {
29
33
  parts.push(`šŸ“ Project File Structure:\n\`\`\`\n${projectFileTree.trim()}\n\`\`\``);
30
34
  }
31
35
  parts.push(`\n--- CODE START ---\n${code}\n--- CODE END ---`);
32
- return parts.join('\n\n');
36
+ const prompt = parts.join('\n\n');
37
+ const tokenEstimate = estimateTokenCount(prompt);
38
+ // šŸ”µ Colorized diagnostic output
39
+ const header = chalk.bgBlue.white.bold(' [SCAI] Prompt Overview ');
40
+ const labelColor = chalk.cyan;
41
+ const contentColor = chalk.gray;
42
+ console.log('\n' + header);
43
+ console.log(labelColor('šŸ”¢ Token Estimate:'), contentColor(`${tokenEstimate.toLocaleString()} tokens`));
44
+ console.log(labelColor('🧩 Prompt Sections:'));
45
+ console.log(contentColor([
46
+ summary ? 'šŸ“„ Summary' : null,
47
+ functions?.length ? 'šŸ”§ Functions' : null,
48
+ relatedFiles?.length ? 'šŸ“š Related Files' : null,
49
+ projectFileTree ? 'šŸ“ File Tree' : null,
50
+ 'šŸ“¦ Code',
51
+ ]
52
+ .filter(Boolean)
53
+ .join(', ')));
54
+ console.log(labelColor('šŸ” Key:'), contentColor('[buildContextualPrompt]\n'));
55
+ return prompt;
33
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scai",
3
- "version": "0.1.66",
3
+ "version": "0.1.67",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "scai": "./dist/index.js"