scai 0.1.68 → 0.1.69

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.
@@ -127,7 +127,6 @@ export async function runAskCommand(query) {
127
127
  }
128
128
  // 🟩 STEP 7: Build prompt
129
129
  console.log(chalk.blueBright('\nšŸ“¦ Building contextual prompt...'));
130
- console.log(chalk.gray(`[runAskCommand] Calling buildContextualPrompt()`));
131
130
  const promptContent = buildContextualPrompt({
132
131
  baseInstruction: query,
133
132
  code,
@@ -3,26 +3,26 @@ import * as readline from 'readline';
3
3
  import * as fs from 'fs';
4
4
  import * as path from 'path';
5
5
  import chalk from 'chalk';
6
- import { getDbForRepo } from './db/client.js'; // Ensure this function works correctly
6
+ import { getDbForRepo } from './db/client.js';
7
7
  import { readConfig, writeConfig } from './config.js';
8
8
  import { CONFIG_PATH } from './constants.js';
9
9
  // Constants
10
10
  const MODEL_PORT = 11434;
11
- const REQUIRED_MODELS = ['llama3', 'mistral']; // Expand as needed
11
+ const REQUIRED_MODELS = ['llama3', 'mistral'];
12
12
  const isYesMode = process.argv.includes('--yes') || process.env.SCAI_YES === '1';
13
13
  // 🧠 Auto init config/db if missing
14
14
  export async function autoInitIfNeeded() {
15
15
  const cfg = readConfig();
16
16
  if (!fs.existsSync(CONFIG_PATH)) {
17
17
  console.log(chalk.green('šŸ› ļø Config not found. Initializing...'));
18
- writeConfig({}); // This will create config.json with defaults
18
+ writeConfig({});
19
19
  }
20
20
  const activeRepo = cfg.activeRepo && cfg.repos[cfg.activeRepo];
21
21
  if (activeRepo) {
22
22
  const dbPath = path.join(activeRepo.indexDir, 'scai.db');
23
23
  if (!fs.existsSync(dbPath)) {
24
24
  console.log(chalk.green('šŸ“¦ DB not found. Initializing...'));
25
- getDbForRepo(); // This creates the DB
25
+ getDbForRepo();
26
26
  }
27
27
  }
28
28
  }
@@ -31,14 +31,15 @@ async function ensureOllamaRunning() {
31
31
  try {
32
32
  const res = await fetch(`http://localhost:${MODEL_PORT}`);
33
33
  if (res.ok) {
34
- console.log('āœ… Ollama is already running.');
34
+ console.log(chalk.green('āœ… Result:') + ` Ollama is already running on port ${MODEL_PORT}.`);
35
35
  return;
36
36
  }
37
37
  }
38
- catch {
39
- // Continue to spawn below
38
+ catch (err) {
39
+ console.log(chalk.yellow('āš™ļø Challenge:') + ' Ollama is not running. Attempting to start it...');
40
40
  }
41
- console.log(chalk.yellow('āš™ļø Ollama is not running. Starting it in the background...'));
41
+ console.log(chalk.yellow('āš™ļø Challenge:') + ` Ollama does not appear to be running on port ${MODEL_PORT}.\n` +
42
+ chalk.yellow('šŸš€ Action:') + ' Attempting to start Ollama in the background...');
42
43
  try {
43
44
  const child = spawn('ollama', ['serve'], {
44
45
  detached: true,
@@ -47,10 +48,10 @@ async function ensureOllamaRunning() {
47
48
  });
48
49
  child.unref();
49
50
  await new Promise((res) => setTimeout(res, 3000));
50
- console.log('āœ… Ollama started.');
51
+ console.log(chalk.green('āœ… Result:') + ' Ollama started successfully.');
51
52
  }
52
53
  catch (err) {
53
- console.error('āŒ Failed to start Ollama:', err);
54
+ console.error(chalk.red('āŒ Failed:') + ' Could not start Ollama process.', err);
54
55
  process.exit(1);
55
56
  }
56
57
  }
@@ -64,7 +65,7 @@ async function getInstalledModels() {
64
65
  .filter((model) => REQUIRED_MODELS.includes(model));
65
66
  }
66
67
  catch (err) {
67
- console.error('āŒ Could not fetch installed models:', err);
68
+ console.error(chalk.red('āŒ Could not fetch installed models:'), err);
68
69
  return [];
69
70
  }
70
71
  }
@@ -83,13 +84,13 @@ async function ensureModelsDownloaded() {
83
84
  const installed = await getInstalledModels();
84
85
  const missing = REQUIRED_MODELS.filter((m) => !installed.includes(m));
85
86
  if (!missing.length) {
86
- console.log('āœ… All required models are installed.');
87
+ console.log(chalk.green('āœ… All required models are installed.'));
87
88
  return;
88
89
  }
89
90
  console.log(chalk.yellow(`šŸ“¦ Missing models: ${missing.join(', ')}`));
90
91
  const answer = await promptUser('ā¬‡ļø Do you want to download them now? (y/N): ');
91
92
  if (answer.toLowerCase() !== 'y') {
92
- console.log('🚫 Aborting due to missing models.');
93
+ console.log(chalk.red('🚫 Aborting due to missing models.'));
93
94
  process.exit(1);
94
95
  }
95
96
  for (const model of missing) {
@@ -99,7 +100,7 @@ async function ensureModelsDownloaded() {
99
100
  console.log(chalk.green(`āœ… Pulled ${model}`));
100
101
  }
101
102
  catch (err) {
102
- console.error(`āŒ Failed to pull ${model}:`, err);
103
+ console.error(chalk.red(`āŒ Failed to pull ${model}:`), err);
103
104
  process.exit(1);
104
105
  }
105
106
  }
@@ -16,8 +16,7 @@ export function buildContextualPrompt({ baseInstruction, code, summary, function
16
16
  parts.push(`šŸ”§ Functions:\n${formattedFunctions}`);
17
17
  }
18
18
  else {
19
- console.log(chalk.gray(`[buildContextualPrompt]`) +
20
- chalk.yellow(` āš ļø No functions found in top file.`));
19
+ console.log(chalk.yellow(` āš ļø No functions found in top rated file.`));
21
20
  }
22
21
  if (relatedFiles?.length) {
23
22
  const formattedRelatedFiles = relatedFiles
@@ -1,10 +1,16 @@
1
- import { wrapText } from "./textWrapper.js";
2
- // src/utils/summarizer.ts
1
+ import columnify from 'columnify';
3
2
  export function summarizeCode(summaryText) {
4
- // Get the terminal width (default to 80 if not available)
5
3
  const terminalWidth = process.stdout.columns || 80;
6
- // Use two-thirds of the terminal width for the wrapping
7
- const twoThirdsTerminalWidth = Math.floor((terminalWidth * 2) / 3);
8
- // Wrap the summary output to fit within two-thirds of the terminal width
9
- return wrapText(summaryText, twoThirdsTerminalWidth);
4
+ // You can control wrapping here
5
+ const formatted = columnify([{ Summary: summaryText }], {
6
+ columnSplitter: ' ',
7
+ maxLineWidth: terminalWidth,
8
+ config: {
9
+ Summary: {
10
+ maxWidth: Math.floor((terminalWidth * 2) / 3), // Use 2/3 width like before
11
+ align: "left",
12
+ },
13
+ },
14
+ });
15
+ return formatted;
10
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scai",
3
- "version": "0.1.68",
3
+ "version": "0.1.69",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "scai": "./dist/index.js"
@@ -41,6 +41,7 @@
41
41
  "acorn-walk": "^8.3.2",
42
42
  "better-sqlite3": "^12.1.1",
43
43
  "chalk": "^5.4.1",
44
+ "columnify": "^1.6.0",
44
45
  "commander": "^11.0.0",
45
46
  "fast-glob": "^3.3.3",
46
47
  "proper-lockfile": "^4.1.2",
@@ -49,6 +50,7 @@
49
50
  },
50
51
  "devDependencies": {
51
52
  "@types/better-sqlite3": "^7.6.13",
53
+ "@types/columnify": "^1.5.4",
52
54
  "@types/jest": "^30.0.0",
53
55
  "@types/node": "^24.1.0",
54
56
  "@types/proper-lockfile": "^4.1.4",
@@ -1,26 +0,0 @@
1
- export function wrapText(text, maxWidth) {
2
- const words = text.split(' ');
3
- let wrappedText = '';
4
- let currentLine = '';
5
- words.forEach(word => {
6
- // If the word is longer than the maxWidth, break it up into multiple lines
7
- if (word.length > maxWidth) {
8
- // Break the word into smaller chunks
9
- while (word.length > maxWidth) {
10
- wrappedText += word.slice(0, maxWidth) + '\n';
11
- word = word.slice(maxWidth);
12
- }
13
- }
14
- // Check if adding the word would exceed the max width
15
- if ((currentLine + word).length > maxWidth) {
16
- wrappedText += currentLine + '\n'; // Add the current line and start a new one
17
- currentLine = word + ' '; // Start the new line with the current word
18
- }
19
- else {
20
- currentLine += word + ' '; // Add the word to the current line
21
- }
22
- });
23
- // Append the last line if any
24
- wrappedText += currentLine.trim(); // trim() to remove the extra space at the end
25
- return wrappedText;
26
- }