scai 0.1.109 → 0.1.111

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.
@@ -29,6 +29,7 @@ export async function extractFromJS(filePath, content, fileId) {
29
29
  locations: true,
30
30
  });
31
31
  const functions = [];
32
+ const classes = [];
32
33
  walkAncestor(ast, {
33
34
  FunctionDeclaration(node, ancestors) {
34
35
  const parent = ancestors[ancestors.length - 2];
@@ -60,31 +61,63 @@ export async function extractFromJS(filePath, content, fileId) {
60
61
  content: content.slice(node.start, node.end),
61
62
  });
62
63
  },
64
+ ClassDeclaration(node) {
65
+ const className = node.id?.name || `${path.basename(filePath)}:<anon-class>`;
66
+ classes.push({
67
+ name: className,
68
+ start_line: node.loc?.start.line ?? -1,
69
+ end_line: node.loc?.end.line ?? -1,
70
+ content: content.slice(node.start, node.end),
71
+ superClass: node.superClass?.name ?? null,
72
+ });
73
+ },
74
+ ClassExpression(node) {
75
+ const className = node.id?.name || `${path.basename(filePath)}:<anon-class>`;
76
+ classes.push({
77
+ name: className,
78
+ start_line: node.loc?.start.line ?? -1,
79
+ end_line: node.loc?.end.line ?? -1,
80
+ content: content.slice(node.start, node.end),
81
+ superClass: node.superClass?.name ?? null,
82
+ });
83
+ },
63
84
  });
64
- if (functions.length === 0) {
65
- log(`⚠️ No functions found in: ${filePath}`);
85
+ if (functions.length === 0 && classes.length === 0) {
86
+ log(`⚠️ No functions/classes found in: ${filePath}`);
66
87
  db.prepare(markFileAsSkippedTemplate).run({ id: fileId });
67
88
  return false;
68
89
  }
69
- log(`🔍 Found ${functions.length} functions in ${filePath}`);
90
+ log(`🔍 Found ${functions.length} functions and ${classes.length} classes in ${filePath}`);
91
+ // Insert functions
70
92
  for (const fn of functions) {
71
93
  const embedding = await generateEmbedding(fn.content);
72
- const result = db.prepare(`
94
+ const result = db
95
+ .prepare(`
73
96
  INSERT INTO functions (
74
97
  file_id, name, start_line, end_line, content, embedding, lang
75
98
  ) VALUES (
76
99
  @file_id, @name, @start_line, @end_line, @content, @embedding, @lang
77
100
  )
78
- `).run({
101
+ `)
102
+ .run({
79
103
  file_id: fileId,
80
104
  name: fn.name,
81
105
  start_line: fn.start_line,
82
106
  end_line: fn.end_line,
83
107
  content: fn.content,
84
108
  embedding: JSON.stringify(embedding),
85
- lang: 'js'
109
+ lang: 'js',
110
+ });
111
+ const functionId = result.lastInsertRowid;
112
+ // file → function edge
113
+ db.prepare(`INSERT INTO edges (source_type, source_id, target_type, target_id, relation)
114
+ VALUES (@source_type, @source_id, @target_type, @target_id, 'contains')`).run({
115
+ source_type: 'file',
116
+ source_id: fileId,
117
+ target_type: 'function',
118
+ target_id: functionId,
86
119
  });
87
- const callerId = result.lastInsertRowid;
120
+ // Walk inside function to find calls
88
121
  const fnAst = parse(fn.content, {
89
122
  ecmaVersion: 'latest',
90
123
  sourceType: 'module',
@@ -96,26 +129,73 @@ export async function extractFromJS(filePath, content, fileId) {
96
129
  if (node.callee?.type === 'Identifier' && node.callee.name) {
97
130
  calls.push({ calleeName: node.callee.name });
98
131
  }
99
- }
132
+ },
100
133
  });
101
134
  for (const call of calls) {
102
- db.prepare(`
103
- INSERT INTO function_calls (caller_id, callee_name)
104
- VALUES (@caller_id, @callee_name)
105
- `).run({
106
- caller_id: callerId,
107
- callee_name: call.calleeName
135
+ // Store name for later resolution
136
+ db.prepare(`INSERT INTO function_calls (caller_id, callee_name) VALUES (@caller_id, @callee_name)`).run({ caller_id: functionId, callee_name: call.calleeName });
137
+ // Optional unresolved edge
138
+ db.prepare(`INSERT INTO edges (source_type, source_id, target_type, target_id, relation)
139
+ VALUES (@source_type, @source_id, @target_type, @target_id, 'calls')`).run({
140
+ source_type: 'function',
141
+ source_id: functionId,
142
+ target_type: 'function',
143
+ target_id: 0, // unresolved callee
108
144
  });
109
145
  }
110
146
  log(`📌 Indexed function: ${fn.name} with ${calls.length} calls`);
111
147
  }
148
+ // Insert classes
149
+ for (const cls of classes) {
150
+ const embedding = await generateEmbedding(cls.content);
151
+ const result = db
152
+ .prepare(`
153
+ INSERT INTO classes (
154
+ file_id, name, start_line, end_line, content, embedding, lang
155
+ ) VALUES (
156
+ @file_id, @name, @start_line, @end_line, @content, @embedding, @lang
157
+ )
158
+ `)
159
+ .run({
160
+ file_id: fileId,
161
+ name: cls.name,
162
+ start_line: cls.start_line,
163
+ end_line: cls.end_line,
164
+ content: cls.content,
165
+ embedding: JSON.stringify(embedding),
166
+ lang: 'js',
167
+ });
168
+ const classId = result.lastInsertRowid;
169
+ // file → class edge
170
+ db.prepare(`INSERT INTO edges (source_type, source_id, target_type, target_id, relation)
171
+ VALUES (@source_type, @source_id, @target_type, @target_id, 'contains')`).run({
172
+ source_type: 'file',
173
+ source_id: fileId,
174
+ target_type: 'class',
175
+ target_id: classId,
176
+ });
177
+ // superclass → store unresolved reference
178
+ if (cls.superClass) {
179
+ db.prepare(`INSERT INTO edges (source_type, source_id, target_type, target_id, relation)
180
+ VALUES (@source_type, @source_id, @target_type, @target_id, 'inherits')`).run({
181
+ source_type: 'class',
182
+ source_id: classId,
183
+ target_type: 'class',
184
+ target_id: 0, // unresolved superclass
185
+ });
186
+ console.log(`🔗 Class ${cls.name} inherits ${cls.superClass} (edge stored for later resolution)`);
187
+ }
188
+ console.log(`🏷 Indexed class: ${cls.name} (id=${classId})`);
189
+ }
190
+ // Optional summary after extraction
191
+ console.log(`📊 Extraction summary for ${filePath}: ${functions.length} functions, ${classes.length} classes`);
112
192
  db.prepare(markFileAsExtractedTemplate).run({ id: fileId });
113
- log(`✅ Marked functions as extracted for ${filePath}`);
193
+ log(`✅ Marked functions/classes as extracted for ${filePath}`);
114
194
  return true;
115
195
  }
116
196
  catch (err) {
117
197
  log(`❌ Failed to extract from: ${filePath}`);
118
- log(` ↳ ${String(err.message)}`);
198
+ log(` ↳ ${err.message}`);
119
199
  db.prepare(markFileAsFailedTemplate).run({ id: fileId });
120
200
  return false;
121
201
  }
@@ -1,15 +1,16 @@
1
- import { Project, SyntaxKind } from 'ts-morph';
1
+ import { Project, SyntaxKind, } from 'ts-morph';
2
2
  import path from 'path';
3
3
  import { generateEmbedding } from '../../lib/generateEmbedding.js';
4
4
  import { log } from '../../utils/log.js';
5
5
  import { getDbForRepo } from '../client.js';
6
- import { markFileAsSkippedTemplate, markFileAsExtractedTemplate, markFileAsFailedTemplate } from '../sqlTemplates.js';
6
+ import { markFileAsSkippedTemplate, markFileAsExtractedTemplate, markFileAsFailedTemplate, } from '../sqlTemplates.js';
7
7
  export async function extractFromTS(filePath, content, fileId) {
8
8
  const db = getDbForRepo();
9
9
  try {
10
10
  const project = new Project({ useInMemoryFileSystem: true });
11
11
  const sourceFile = project.createSourceFile(filePath, content);
12
12
  const functions = [];
13
+ const classes = [];
13
14
  const allFuncs = [
14
15
  ...sourceFile.getDescendantsOfKind(SyntaxKind.FunctionDeclaration),
15
16
  ...sourceFile.getDescendantsOfKind(SyntaxKind.FunctionExpression),
@@ -22,45 +23,101 @@ export async function extractFromTS(filePath, content, fileId) {
22
23
  const code = fn.getText();
23
24
  functions.push({ name, start_line: start, end_line: end, content: code });
24
25
  }
25
- if (functions.length === 0) {
26
- log(`⚠️ No functions found in TS file: ${filePath}`);
26
+ const allClasses = [
27
+ ...sourceFile.getDescendantsOfKind(SyntaxKind.ClassDeclaration),
28
+ ...sourceFile.getDescendantsOfKind(SyntaxKind.ClassExpression),
29
+ ];
30
+ for (const cls of allClasses) {
31
+ const name = cls.getName() ?? `${path.basename(filePath)}:<anon-class>`;
32
+ const start = cls.getStartLineNumber();
33
+ const end = cls.getEndLineNumber();
34
+ const code = cls.getText();
35
+ const superClass = cls.getExtends()?.getText() ?? null;
36
+ classes.push({
37
+ name,
38
+ start_line: start,
39
+ end_line: end,
40
+ content: code,
41
+ superClass,
42
+ });
43
+ }
44
+ if (functions.length === 0 && classes.length === 0) {
45
+ log(`⚠️ No functions/classes found in TS file: ${filePath}`);
27
46
  db.prepare(markFileAsSkippedTemplate).run({ id: fileId });
28
47
  return false;
29
48
  }
30
- log(`🔍 Found ${functions.length} TypeScript functions in ${filePath}`);
49
+ log(`🔍 Found ${functions.length} functions and ${classes.length} classes in ${filePath}`);
50
+ // Insert functions
31
51
  for (const fn of functions) {
32
52
  const embedding = await generateEmbedding(fn.content);
33
- const result = db.prepare(`
53
+ const result = db
54
+ .prepare(`
34
55
  INSERT INTO functions (
35
56
  file_id, name, start_line, end_line, content, embedding, lang
36
57
  ) VALUES (
37
58
  @file_id, @name, @start_line, @end_line, @content, @embedding, @lang
38
59
  )
39
- `).run({
60
+ `)
61
+ .run({
40
62
  file_id: fileId,
41
63
  name: fn.name,
42
64
  start_line: fn.start_line,
43
65
  end_line: fn.end_line,
44
66
  content: fn.content,
45
67
  embedding: JSON.stringify(embedding),
46
- lang: 'ts'
68
+ lang: 'ts',
47
69
  });
48
- const callerId = result.lastInsertRowid;
49
- // Simplified call detection (no walking for now)
70
+ const functionId = result.lastInsertRowid;
71
+ // file function edge
72
+ db.prepare(`INSERT INTO edges (source_type, source_id, target_type, target_id, relation)
73
+ VALUES ('file', @source_id, 'function', @target_id, 'contains')`).run({ source_id: fileId, target_id: functionId });
74
+ // Simplified call detection (regex)
50
75
  const callMatches = fn.content.matchAll(/(\w+)\s*\(/g);
51
76
  for (const match of callMatches) {
52
- db.prepare(`
53
- INSERT INTO function_calls (caller_id, callee_name)
54
- VALUES (@caller_id, @callee_name)
55
- `).run({
56
- caller_id: callerId,
77
+ // Store call by name (resolution happens later)
78
+ db.prepare(`INSERT INTO function_calls (caller_id, callee_name)
79
+ VALUES (@caller_id, @callee_name)`).run({
80
+ caller_id: functionId,
57
81
  callee_name: match[1],
58
82
  });
59
83
  }
60
84
  log(`📌 Indexed TS function: ${fn.name}`);
61
85
  }
86
+ // Insert classes
87
+ for (const cls of classes) {
88
+ const embedding = await generateEmbedding(cls.content);
89
+ const result = db
90
+ .prepare(`
91
+ INSERT INTO classes (
92
+ file_id, name, start_line, end_line, content, embedding, lang
93
+ ) VALUES (
94
+ @file_id, @name, @start_line, @end_line, @content, @embedding, @lang
95
+ )
96
+ `)
97
+ .run({
98
+ file_id: fileId,
99
+ name: cls.name,
100
+ start_line: cls.start_line,
101
+ end_line: cls.end_line,
102
+ content: cls.content,
103
+ embedding: JSON.stringify(embedding),
104
+ lang: 'ts',
105
+ });
106
+ const classId = result.lastInsertRowid;
107
+ // file → class edge
108
+ db.prepare(`INSERT INTO edges (source_type, source_id, target_type, target_id, relation)
109
+ VALUES ('file', @source_id, 'class', @target_id, 'contains')`).run({ source_id: fileId, target_id: classId });
110
+ // superclass reference → store in helper table for later resolution
111
+ if (cls.superClass) {
112
+ db.prepare(`INSERT INTO class_inheritance (class_id, super_name)
113
+ VALUES (@class_id, @super_name)`).run({ class_id: classId, super_name: cls.superClass });
114
+ log(`🔗 Class ${cls.name} extends ${cls.superClass} (edge stored for later resolution)`);
115
+ }
116
+ log(`🏷 Indexed TS class: ${cls.name} (id=${classId})`);
117
+ }
118
+ log(`📊 Extraction summary for ${filePath}: ${functions.length} functions, ${classes.length} classes`);
62
119
  db.prepare(markFileAsExtractedTemplate).run({ id: fileId });
63
- log(`✅ Marked TS functions as extracted for ${filePath}`);
120
+ log(`✅ Marked TS functions/classes as extracted for ${filePath}`);
64
121
  return true;
65
122
  }
66
123
  catch (err) {
@@ -1,43 +1,44 @@
1
- import { log } from '../../utils/log.js';
2
- import { detectFileType } from '../../fileRules/detectFileType.js';
3
- import { extractFromJava } from './extractFromJava.js';
4
- import { extractFromJS } from './extractFromJs.js';
5
- import { extractFromXML } from './extractFromXML.js';
6
- import { getDbForRepo } from '../client.js';
7
- import { markFileAsFailedTemplate, markFileAsSkippedByPath } from '../sqlTemplates.js';
8
- import { extractFromTS } from './extractFromTs.js';
9
- /**
10
- * Detects file type and delegates to the appropriate extractor.
11
- */
1
+ import { getDbForRepo } from "../client.js";
2
+ import { markFileAsSkippedByPath, markFileAsFailedTemplate } from "../sqlTemplates.js";
3
+ import { extractFromJava } from "./extractFromJava.js";
4
+ import { extractFromJS } from "./extractFromJs.js";
5
+ import { extractFromTS } from "./extractFromTs.js";
6
+ import { extractFromXML } from "./extractFromXML.js";
7
+ import { detectFileType } from "../../fileRules/detectFileType.js";
8
+ import { log } from "../../utils/log.js";
12
9
  export async function extractFunctionsFromFile(filePath, content, fileId) {
13
10
  const type = detectFileType(filePath).trim().toLowerCase();
14
11
  const db = getDbForRepo();
15
12
  try {
16
- if (type === 'js' || type === 'javascript') {
17
- log(`✅ Attempting to extract JS functions from ${filePath}`);
18
- return await extractFromJS(filePath, content, fileId);
13
+ let success = false;
14
+ switch (type) {
15
+ case 'js':
16
+ case 'javascript':
17
+ log(`📄 Extracting JS code from ${filePath}`);
18
+ success = await extractFromJS(filePath, content, fileId);
19
+ break;
20
+ case 'ts':
21
+ case 'typescript':
22
+ log(`📘 Extracting TS code from ${filePath}`);
23
+ success = await extractFromTS(filePath, content, fileId);
24
+ break;
25
+ case 'java':
26
+ log(`⚠️ Java extraction not implemented for ${filePath}`);
27
+ await extractFromJava(filePath, content, fileId);
28
+ return false;
29
+ case 'xml':
30
+ log(`⚠️ XML extraction not implemented for ${filePath}`);
31
+ await extractFromXML(filePath, content, fileId);
32
+ return false;
33
+ default:
34
+ log(`⚠️ Unsupported file type: ${type}. Skipping ${filePath}`);
35
+ db.prepare(markFileAsSkippedByPath).run({ path: filePath });
36
+ return false;
19
37
  }
20
- if (type === 'ts' || type === 'typescript') {
21
- log(`📘 Extracting TS functions from ${filePath}`);
22
- return await extractFromTS(filePath, content, fileId);
23
- }
24
- if (type === 'java') {
25
- log(`❌ Nothing extracted for ${filePath} due to missing implementation`);
26
- await extractFromJava(filePath, content, fileId);
27
- return false;
28
- }
29
- if (type === 'xml') {
30
- log(`❌ Nothing extracted for ${filePath} due to missing implementation`);
31
- await extractFromXML(filePath, content, fileId);
32
- return false;
33
- }
34
- log(`⚠️ Unsupported file type: ${type} for function extraction. Skipping ${filePath}`);
35
- db.prepare(markFileAsSkippedByPath).run({ path: filePath });
36
- return false;
38
+ return success;
37
39
  }
38
40
  catch (error) {
39
- log(`❌ Failed to extract functions from ${filePath}: ${error instanceof Error ? error.message : error}`);
40
- // Use the sqlTemplate to mark the file as 'failed'
41
+ log(`❌ Failed to extract from ${filePath}: ${error instanceof Error ? error.message : error}`);
41
42
  db.prepare(markFileAsFailedTemplate).run({ id: fileId });
42
43
  return false;
43
44
  }
@@ -5,7 +5,7 @@ import { extractFunctionsFromFile } from './functionExtractors/index.js';
5
5
  * Extracts functions from file if language is supported.
6
6
  * Returns true if functions were extracted, false otherwise.
7
7
  */
8
- export async function indexFunctionsForFile(filePath, fileId) {
8
+ export async function indexCodeForFile(filePath, fileId) {
9
9
  const normalizedPath = path.normalize(filePath).replace(/\\/g, '/');
10
10
  const content = fs.readFileSync(filePath, 'utf-8');
11
11
  return await extractFunctionsFromFile(normalizedPath, content, fileId);
package/dist/db/schema.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { getDbForRepo } from "./client.js";
2
2
  export function initSchema() {
3
3
  const db = getDbForRepo();
4
+ // --- Existing tables ---
4
5
  db.exec(`
5
- -- Create the files table
6
6
  CREATE TABLE IF NOT EXISTS files (
7
7
  id INTEGER PRIMARY KEY AUTOINCREMENT,
8
8
  path TEXT UNIQUE,
@@ -16,12 +16,9 @@ export function initSchema() {
16
16
  functions_extracted_at TEXT
17
17
  );
18
18
 
19
- -- Create the full-text search table, auto-updated via content=files
20
19
  CREATE VIRTUAL TABLE IF NOT EXISTS files_fts
21
20
  USING fts5(filename, summary, path, content='files', content_rowid='id');
22
21
  `);
23
- console.log('✅ SQLite schema initialized with FTS5 auto-sync');
24
- // Create additional tables for functions and function_calls
25
22
  db.exec(`
26
23
  CREATE TABLE IF NOT EXISTS functions (
27
24
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -41,5 +38,54 @@ export function initSchema() {
41
38
  callee_name TEXT
42
39
  );
43
40
  `);
44
- console.log('✅ Schema for functions and function_calls initialized');
41
+ // --- KG-specific additions ---
42
+ // Classes table
43
+ db.exec(`
44
+ CREATE TABLE IF NOT EXISTS classes (
45
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
46
+ file_id INTEGER REFERENCES files(id),
47
+ name TEXT,
48
+ start_line INTEGER,
49
+ end_line INTEGER,
50
+ content TEXT,
51
+ embedding TEXT,
52
+ lang TEXT
53
+ );
54
+
55
+ CREATE INDEX IF NOT EXISTS idx_class_file_id ON classes(file_id);
56
+ `);
57
+ // Edges table (function/class/file relations)
58
+ db.exec(`
59
+ CREATE TABLE IF NOT EXISTS edges (
60
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
61
+ source_type TEXT NOT NULL, -- 'function' | 'class' | 'file'
62
+ source_id INTEGER NOT NULL,
63
+ target_type TEXT NOT NULL,
64
+ target_id INTEGER NOT NULL,
65
+ relation TEXT NOT NULL -- e.g., 'calls', 'inherits', 'contains'
66
+ );
67
+
68
+ CREATE INDEX IF NOT EXISTS idx_edges_source ON edges(source_type, source_id);
69
+ CREATE INDEX IF NOT EXISTS idx_edges_target ON edges(target_type, target_id);
70
+ `);
71
+ // --- Improved tags setup ---
72
+ // Master tag table
73
+ db.exec(`
74
+ CREATE TABLE IF NOT EXISTS tags_master (
75
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
76
+ name TEXT UNIQUE NOT NULL
77
+ );
78
+
79
+ CREATE TABLE IF NOT EXISTS entity_tags (
80
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
81
+ entity_type TEXT NOT NULL, -- 'function' | 'class' | 'file'
82
+ entity_id INTEGER NOT NULL,
83
+ tag_id INTEGER NOT NULL REFERENCES tags_master(id),
84
+ UNIQUE(entity_type, entity_id, tag_id)
85
+ );
86
+
87
+ CREATE INDEX IF NOT EXISTS idx_entity_tags_entity ON entity_tags(entity_type, entity_id);
88
+ CREATE INDEX IF NOT EXISTS idx_entity_tags_tag ON entity_tags(tag_id);
89
+ `);
90
+ console.log('✅ KG schema initialized (files, functions, classes, edges, tags)');
45
91
  }
package/dist/index.js CHANGED
@@ -193,9 +193,11 @@ const config = cmd.command('config').description('Manage SCAI configuration');
193
193
  config
194
194
  .command('set-model <model>')
195
195
  .description('Set the model to use')
196
- .action(async (model) => {
196
+ .option('-g, --global', 'Set the global default model instead of the active repo')
197
+ .action(async (model, options) => {
197
198
  await withContext(async () => {
198
- Config.setModel(model);
199
+ const scope = options.global ? 'global' : 'repo';
200
+ Config.setModel(model, scope);
199
201
  Config.show();
200
202
  });
201
203
  });
@@ -337,14 +339,8 @@ cmd.addHelpText('after', `
337
339
  💡 Use with caution and expect possible changes or instability.
338
340
  `);
339
341
  cmd.parse(process.argv);
340
- const opts = cmd.opts();
341
- if (opts.model)
342
- Config.setModel(opts.model);
343
- if (opts.lang)
344
- Config.setLanguage(opts.lang);
345
342
  async function withContext(action) {
346
343
  const ok = await updateContext();
347
- if (!ok)
348
- process.exit(1);
344
+ //if (!ok) process.exit(1);
349
345
  await action();
350
346
  }
@@ -1,8 +1,9 @@
1
1
  // File: lib/generate.ts
2
2
  import { Spinner } from './spinner.js';
3
- import { readConfig } from '../config.js';
3
+ import { Config, readConfig } from '../config.js';
4
4
  import { startModelProcess } from '../utils/checkModel.js';
5
- export async function generate(input, model) {
5
+ export async function generate(input) {
6
+ const model = Config.getModel();
6
7
  const contextLength = readConfig().contextLength ?? 8192;
7
8
  let prompt = input.content;
8
9
  if (prompt.length > contextLength) {
@@ -9,7 +9,7 @@ import { readConfig, writeConfig } from './config.js';
9
9
  import { CONFIG_PATH } from './constants.js';
10
10
  // Constants
11
11
  const MODEL_PORT = 11434;
12
- const REQUIRED_MODELS = ['llama3', 'mistral'];
12
+ const REQUIRED_MODELS = ['llama3:8b'];
13
13
  const OLLAMA_URL = 'https://ollama.com/download';
14
14
  const isYesMode = process.argv.includes('--yes') || process.env.SCAI_YES === '1';
15
15
  let ollamaChecked = false;
@@ -30,16 +30,16 @@ export async function autoInitIfNeeded() {
30
30
  }
31
31
  }
32
32
  }
33
- // 🗨 Prompt user with 10-second timeout
34
- function promptUser(question) {
33
+ // 🗨 Prompt user with configurable timeout
34
+ function promptUser(question, timeout = 20000) {
35
35
  if (isYesMode)
36
36
  return Promise.resolve('y');
37
37
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
38
38
  return new Promise((resolve) => {
39
39
  const timer = setTimeout(() => {
40
40
  rl.close();
41
- resolve('');
42
- }, 10000); // 10 second timeout
41
+ resolve(''); // treat empty as "continue"
42
+ }, timeout);
43
43
  rl.question(question, (answer) => {
44
44
  clearTimeout(timer);
45
45
  rl.close();
@@ -89,7 +89,7 @@ async function ensureOllamaRunning() {
89
89
  windowsHide: true,
90
90
  });
91
91
  child.unref();
92
- await new Promise((res) => setTimeout(res, 10000));
92
+ await new Promise((res) => setTimeout(res, 10000)); // give more time
93
93
  if (await isOllamaRunning()) {
94
94
  console.log(chalk.green('✅ Ollama started successfully.'));
95
95
  ollamaAvailable = true;
@@ -102,23 +102,21 @@ async function ensureOllamaRunning() {
102
102
  process.exit(1);
103
103
  }
104
104
  }
105
- // If we get here, Ollama likely isn't installed
105
+ // Ollama not detected; prompt user but allow continuing
106
106
  console.log(chalk.red('❌ Ollama is not installed or not in PATH.'));
107
107
  console.log(chalk.yellow(`📦 Ollama is required to run local AI models.`));
108
- const answer = await promptUser('🌐 Would you like to open the download page in your browser? (y/N): ');
108
+ const answer = await promptUser(`🌐 Recommended model: ${REQUIRED_MODELS.join(', ')}\nOpen download page in browser? (y/N): `);
109
109
  if (answer.toLowerCase() === 'y') {
110
110
  openBrowser(OLLAMA_URL);
111
111
  }
112
- console.log(chalk.yellow('⏳ Waiting for you to install Ollama and press Enter to continue...'));
113
- await promptUser('👉 Press Enter once Ollama is installed and ready: ');
114
- // Retry once
112
+ await promptUser('⏳ Press Enter once Ollama is installed or to continue without it: ');
115
113
  if (await isOllamaRunning()) {
116
114
  console.log(chalk.green('✅ Ollama detected. Continuing...'));
117
115
  ollamaAvailable = true;
118
116
  }
119
117
  else {
120
- console.log(chalk.red('Ollama still not detected. Please check your installation.'));
121
- process.exit(1);
118
+ console.log(chalk.yellow('⚠️ Ollama not running. Models will not be available until installed.'));
119
+ ollamaAvailable = false; // continue anyway
122
120
  }
123
121
  }
124
122
  // 🧰 List installed models
@@ -134,7 +132,7 @@ async function getInstalledModels() {
134
132
  return [];
135
133
  }
136
134
  }
137
- // 📥 Download missing models
135
+ // 📥 Suggest required models but don’t block
138
136
  async function ensureModelsDownloaded() {
139
137
  if (!ollamaAvailable)
140
138
  return;
@@ -144,11 +142,11 @@ async function ensureModelsDownloaded() {
144
142
  console.log(chalk.green('✅ All required models are installed.'));
145
143
  return;
146
144
  }
147
- console.log(chalk.yellow(`📦 Missing models: ${missing.join(', ')}`));
148
- const answer = await promptUser('⬇️ Do you want to download them now? (y/N): ');
145
+ console.log(chalk.yellow(`📦 Suggested models: ${missing.join(', ')}`));
146
+ const answer = await promptUser('⬇️ Download them now? (y/N, continue anyway): ');
149
147
  if (answer.toLowerCase() !== 'y') {
150
- console.log(chalk.red('🚫 Aborting due to missing models.'));
151
- process.exit(1);
148
+ console.log(chalk.yellow('⚠️ Continuing without installing models. You can install later via config.'));
149
+ return;
152
150
  }
153
151
  for (const model of missing) {
154
152
  try {
@@ -157,8 +155,7 @@ async function ensureModelsDownloaded() {
157
155
  console.log(chalk.green(`✅ Pulled ${model}`));
158
156
  }
159
157
  catch {
160
- console.log(chalk.red(`❌ Failed to pull ${model}.`));
161
- process.exit(1);
158
+ console.log(chalk.red(`❌ Failed to pull ${model}, continuing...`));
162
159
  }
163
160
  }
164
161
  }
@@ -18,7 +18,7 @@ If no meaningful changes are present, return the text: "NO UPDATE".
18
18
  ${input.content}
19
19
  --- DIFF END ---
20
20
  `.trim();
21
- const response = await generate({ content: prompt }, model);
21
+ const response = await generate({ content: prompt });
22
22
  // Check if we received a meaningful result or "NO UPDATE"
23
23
  const content = response?.content?.trim();
24
24
  if (content === 'NO UPDATE') {