opencode-rag-plugin 2.11.2 → 2.12.0
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/ReadMe.md +305 -207
- package/dist/cli/commands/backend-detect.d.ts +1 -1
- package/dist/cli/commands/backend-detect.js +1 -1
- package/dist/cli/commands/index.d.ts +0 -1
- package/dist/cli/commands/index.js +0 -1
- package/dist/cli/commands/setup.js +271 -85
- package/dist/cli/commands/{init-helpers.d.ts → workspace-helpers.d.ts} +10 -7
- package/dist/cli/commands/{init-helpers.js → workspace-helpers.js} +12 -62
- package/dist/cli/index.js +1 -2
- package/dist/cli/prompt.d.ts +84 -0
- package/dist/cli/prompt.js +247 -0
- package/dist/cli/types.d.ts +16 -17
- package/dist/cli/wizard/apply.d.ts +58 -0
- package/dist/cli/wizard/apply.js +234 -0
- package/dist/cli/wizard/flow.d.ts +83 -0
- package/dist/cli/wizard/flow.js +759 -0
- package/dist/cli/wizard/model-catalog.d.ts +80 -0
- package/dist/cli/wizard/model-catalog.js +414 -0
- package/dist/cli/wizard/types.d.ts +94 -0
- package/dist/cli/wizard/types.js +5 -0
- package/dist/cli/workspace.d.ts +40 -0
- package/dist/cli/workspace.js +322 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +1 -1
- package/dist/core/config.d.ts +2 -2
- package/dist/core/config.js +2 -2
- package/dist/core/provider-defaults.d.ts +2 -0
- package/dist/core/provider-defaults.js +4 -0
- package/dist/eval/fast-index.js +1 -1
- package/dist/opencode/system-guidance.d.ts +1 -1
- package/dist/opencode/system-guidance.js +1 -1
- package/dist/tui.d.ts +11 -0
- package/dist/tui.js +12 -1
- package/package.json +1 -1
- package/dist/cli/commands/init.d.ts +0 -51
- package/dist/cli/commands/init.js +0 -508
|
@@ -0,0 +1,759 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Interactive `setup` wizard.
|
|
3
|
+
*
|
|
4
|
+
* The flow is deliberately linear and every question has a default taken from
|
|
5
|
+
* the effective configuration, so pressing Enter through the wizard keeps an
|
|
6
|
+
* existing setup intact. Any prompt resolving `undefined` (Ctrl+C / Ctrl+D)
|
|
7
|
+
* aborts the whole wizard: no configuration is written.
|
|
8
|
+
*/
|
|
9
|
+
import { DEFAULT_CONFIG } from "../../core/config.js";
|
|
10
|
+
import { getProviderDefault, supportsChat, supportsEmbedding } from "../../core/provider-defaults.js";
|
|
11
|
+
import { c } from "../format.js";
|
|
12
|
+
import { fetchModelCatalog, probeEmbeddingDimension, ollamaRoot, } from "./model-catalog.js";
|
|
13
|
+
const PROVIDERS = [
|
|
14
|
+
{
|
|
15
|
+
id: "ollama",
|
|
16
|
+
label: "Ollama",
|
|
17
|
+
description: "Local or remote — embeddings, chat, vision and the decision model",
|
|
18
|
+
embedding: true,
|
|
19
|
+
chat: true,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: "openai",
|
|
23
|
+
label: "OpenAI-compatible API",
|
|
24
|
+
description: "OpenAI, llama.cpp, LM Studio, vLLM, OpenRouter, …",
|
|
25
|
+
embedding: true,
|
|
26
|
+
chat: true,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: "cohere",
|
|
30
|
+
label: "Cohere",
|
|
31
|
+
description: "Embeddings only",
|
|
32
|
+
embedding: true,
|
|
33
|
+
chat: false,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: "anthropic",
|
|
37
|
+
label: "Anthropic",
|
|
38
|
+
description: "Chat and vision — no embedding API",
|
|
39
|
+
embedding: false,
|
|
40
|
+
chat: true,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: "google",
|
|
44
|
+
label: "Google Gemini",
|
|
45
|
+
description: "Chat and vision — no embedding API",
|
|
46
|
+
embedding: false,
|
|
47
|
+
chat: true,
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
/** Read a section of the raw config. */
|
|
51
|
+
function section(config, name) {
|
|
52
|
+
const value = config[name];
|
|
53
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
54
|
+
? value
|
|
55
|
+
: undefined;
|
|
56
|
+
}
|
|
57
|
+
/** Read a string from a raw config section. */
|
|
58
|
+
function readString(config, key) {
|
|
59
|
+
const value = config?.[key];
|
|
60
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
61
|
+
}
|
|
62
|
+
/** Read a boolean from a raw config section. */
|
|
63
|
+
function readBoolean(config, key) {
|
|
64
|
+
const value = config?.[key];
|
|
65
|
+
return typeof value === "boolean" ? value : undefined;
|
|
66
|
+
}
|
|
67
|
+
/** Default base URL for a provider. */
|
|
68
|
+
function defaultBaseUrl(provider) {
|
|
69
|
+
const defaults = getProviderDefault(provider);
|
|
70
|
+
if (defaults?.defaultBaseUrl)
|
|
71
|
+
return defaults.defaultBaseUrl;
|
|
72
|
+
if (provider === "ollama")
|
|
73
|
+
return "http://127.0.0.1:11434/api";
|
|
74
|
+
return "";
|
|
75
|
+
}
|
|
76
|
+
/** Render a catalog probe result as a status line. */
|
|
77
|
+
function printCatalogStatus(catalog) {
|
|
78
|
+
if (catalog.reachable) {
|
|
79
|
+
const count = catalog.models.length;
|
|
80
|
+
console.log(` ${c.success("✓")} ${c.value(catalog.baseUrl)} — ${count} model${count === 1 ? "" : "s"} found`);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
console.log(` ${c.error("✗")} ${c.value(catalog.baseUrl)} — ${catalog.error ?? "unreachable"}`);
|
|
84
|
+
}
|
|
85
|
+
/** Ask for a provider + base URL + optional API key, then probe its models. */
|
|
86
|
+
async function askHost(prompter, options) {
|
|
87
|
+
const { message, existing, flags } = options;
|
|
88
|
+
const previous = section(existing, "embedding");
|
|
89
|
+
const candidates = PROVIDERS.filter((entry) => (options.requireEmbedding ? entry.embedding : true) &&
|
|
90
|
+
(options.requireChat ? entry.chat : true));
|
|
91
|
+
const defaultProvider = (flags.provider && candidates.some((entry) => entry.id === flags.provider) ? flags.provider : undefined) ??
|
|
92
|
+
readString(previous, "provider") ??
|
|
93
|
+
DEFAULT_CONFIG.embedding.provider;
|
|
94
|
+
const defaultIndex = Math.max(0, candidates.findIndex((entry) => entry.id === defaultProvider));
|
|
95
|
+
const picked = await prompter.select({
|
|
96
|
+
message,
|
|
97
|
+
options: candidates.map((entry) => ({
|
|
98
|
+
label: entry.label,
|
|
99
|
+
value: entry.id,
|
|
100
|
+
description: entry.description,
|
|
101
|
+
})),
|
|
102
|
+
defaultIndex,
|
|
103
|
+
});
|
|
104
|
+
if (picked === undefined)
|
|
105
|
+
return undefined;
|
|
106
|
+
const entry = candidates.find((candidate) => candidate.id === picked);
|
|
107
|
+
if (!entry)
|
|
108
|
+
return undefined;
|
|
109
|
+
const baseUrlDefault = flags.baseUrl ??
|
|
110
|
+
readString(previous, "baseUrl") ??
|
|
111
|
+
(entry.id === "ollama" ? "http://127.0.0.1:11434/api" : defaultBaseUrl(entry.id));
|
|
112
|
+
const baseUrl = await prompter.text({
|
|
113
|
+
message: "Base URL",
|
|
114
|
+
defaultValue: baseUrlDefault,
|
|
115
|
+
hint: entry.id === "ollama"
|
|
116
|
+
? "Ollama accepts http://127.0.0.1:11434 or http://127.0.0.1:11434/api"
|
|
117
|
+
: entry.id === "openai"
|
|
118
|
+
? "OpenAI-compatible servers usually end in /v1 (llama.cpp, LM Studio, vLLM, …)"
|
|
119
|
+
: undefined,
|
|
120
|
+
validate: (value) => {
|
|
121
|
+
if (!value)
|
|
122
|
+
return "A base URL is required.";
|
|
123
|
+
try {
|
|
124
|
+
new URL(value);
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return "Enter a valid URL, e.g. http://127.0.0.1:11434/api";
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
if (baseUrl === undefined)
|
|
133
|
+
return undefined;
|
|
134
|
+
let apiKey;
|
|
135
|
+
const envVar = getProviderDefault(entry.id)?.apiKeyEnvVar;
|
|
136
|
+
const envValue = envVar ? process.env[envVar] : undefined;
|
|
137
|
+
const existingKey = readString(previous, "apiKey");
|
|
138
|
+
const flagKey = flags.apiKey && flags.apiKey.startsWith("env:")
|
|
139
|
+
? process.env[flags.apiKey.slice(4)]
|
|
140
|
+
: flags.apiKey;
|
|
141
|
+
if (flagKey) {
|
|
142
|
+
apiKey = flagKey;
|
|
143
|
+
}
|
|
144
|
+
else if (existingKey && !existingKey.startsWith("env:")) {
|
|
145
|
+
apiKey = existingKey;
|
|
146
|
+
console.log(` ${c.dim("Using the API key already stored in the config.")}`);
|
|
147
|
+
}
|
|
148
|
+
else if (envValue) {
|
|
149
|
+
console.log(` ${c.dim(`Using ${envVar} from the environment (not written to the config).`)}`);
|
|
150
|
+
}
|
|
151
|
+
else if (entry.id === "openai" || entry.id === "cohere" || entry.id === "anthropic" || entry.id === "google") {
|
|
152
|
+
console.log(` ${c.dim(envVar ? `No ${envVar} set. Paste a key or leave empty to add it later.` : "Paste an API key or leave empty to add it later.")}`);
|
|
153
|
+
const typed = await prompter.password("API key (Enter to skip)");
|
|
154
|
+
if (typed === undefined)
|
|
155
|
+
return undefined;
|
|
156
|
+
if (typed.trim().length > 0)
|
|
157
|
+
apiKey = typed.trim();
|
|
158
|
+
}
|
|
159
|
+
console.log(`\n ${c.dim(`Checking ${entry.id} at ${baseUrl}…`)}`);
|
|
160
|
+
const catalog = await fetchModelCatalog({
|
|
161
|
+
provider: entry.id,
|
|
162
|
+
baseUrl,
|
|
163
|
+
apiKey,
|
|
164
|
+
proxy: options.proxy,
|
|
165
|
+
});
|
|
166
|
+
printCatalogStatus(catalog);
|
|
167
|
+
return {
|
|
168
|
+
host: {
|
|
169
|
+
provider: entry.id,
|
|
170
|
+
baseUrl: entry.id === "ollama" ? catalog.baseUrl : baseUrl,
|
|
171
|
+
...(apiKey ? { apiKey } : {}),
|
|
172
|
+
},
|
|
173
|
+
catalog,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Pick a model from a probed catalog, falling back to free-text entry.
|
|
178
|
+
*
|
|
179
|
+
* `__custom__` is always offered so a model that the provider does not list
|
|
180
|
+
* (or a freshly pulled one) can still be typed.
|
|
181
|
+
*/
|
|
182
|
+
async function pickModel(prompter, options) {
|
|
183
|
+
const { catalog, capability } = options;
|
|
184
|
+
const candidates = catalog.models.filter((model) => model.capabilities.includes(capability));
|
|
185
|
+
// Keep the configured model selectable when the host lists models but did
|
|
186
|
+
// not advertise it. With no candidates at all, fall straight through to
|
|
187
|
+
// manual entry instead of showing a one-item menu.
|
|
188
|
+
if (candidates.length > 0 && options.defaultValue && !candidates.some((model) => model.id === options.defaultValue)) {
|
|
189
|
+
candidates.unshift({ id: options.defaultValue, capabilities: [capability] });
|
|
190
|
+
}
|
|
191
|
+
if (candidates.length === 0) {
|
|
192
|
+
if (catalog.reachable) {
|
|
193
|
+
console.log(` ${c.warn("No model with the required capability was advertised by the host.")}`);
|
|
194
|
+
}
|
|
195
|
+
return prompter.text({
|
|
196
|
+
message: options.message,
|
|
197
|
+
defaultValue: options.defaultValue ?? "",
|
|
198
|
+
hint: "Type the model name exactly as the provider expects it.",
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
const entries = candidates.map((model) => ({
|
|
202
|
+
label: model.id,
|
|
203
|
+
value: model.id,
|
|
204
|
+
description: model.detail,
|
|
205
|
+
}));
|
|
206
|
+
entries.push({ label: "Type a model name…", value: "__custom__" });
|
|
207
|
+
if (options.allowSkip) {
|
|
208
|
+
entries.push({ label: "Skip for now", value: "__skip__" });
|
|
209
|
+
}
|
|
210
|
+
const defaultIndex = Math.max(0, options.defaultValue ? candidates.findIndex((model) => model.id === options.defaultValue) : 0);
|
|
211
|
+
const picked = await prompter.select({
|
|
212
|
+
message: options.message,
|
|
213
|
+
options: entries,
|
|
214
|
+
defaultIndex,
|
|
215
|
+
});
|
|
216
|
+
if (picked === undefined)
|
|
217
|
+
return undefined;
|
|
218
|
+
if (picked === "__skip__")
|
|
219
|
+
return undefined;
|
|
220
|
+
if (picked === "__custom__") {
|
|
221
|
+
return prompter.text({
|
|
222
|
+
message: options.message,
|
|
223
|
+
defaultValue: options.defaultValue ?? "",
|
|
224
|
+
hint: "Type the model name exactly as the provider expects it.",
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
return picked;
|
|
228
|
+
}
|
|
229
|
+
/** Print a compact summary of the collected answers. */
|
|
230
|
+
function printSummary(answers) {
|
|
231
|
+
console.log(`\n${c.heading("Configuration summary")}\n`);
|
|
232
|
+
const host = (choice) => `${choice.provider} @ ${choice.baseUrl}${choice.apiKey ? " (API key set)" : ""}`;
|
|
233
|
+
console.log(` ${c.label("Embedding:")} ${c.value(answers.embedding.model)} — ${host(answers.embedding)}${answers.embedding.vectorDimension ? ` (${answers.embedding.vectorDimension} dims)` : ""}`);
|
|
234
|
+
console.log(` ${c.label("Description:")} ${answers.description ? `${c.value(answers.description.model)} — ${host(answers.description)}` : c.dim("disabled")}`);
|
|
235
|
+
console.log(` ${c.label("Vision:")} ${answers.imageDescription ? `${c.value(answers.imageDescription.model)} — ${host(answers.imageDescription)}` : c.dim("disabled")}`);
|
|
236
|
+
console.log(` ${c.label("Decision:")} ${answers.decision?.enabled ? `${c.value(answers.decision.model ?? "tev1")} — ${answers.decision.baseUrl ?? "ollama"}` : c.dim("disabled")}`);
|
|
237
|
+
console.log(` ${c.label("Reranking:")} ${answers.reranking?.enabled ? `${c.value(answers.reranking.model ?? "reranker")} — ${answers.reranking.baseUrl ?? ""}` : c.dim("disabled")}`);
|
|
238
|
+
console.log(` ${c.label("Shell guard:")} ${answers.shellGuard ? (answers.shellGuard.enabled ? c.value("enabled") : c.dim("disabled")) : c.dim("unchanged")}`);
|
|
239
|
+
console.log(` ${c.label("Memory:")} ${answers.memory ? (answers.memory.passiveCapture ? c.value("auto-capture on") : c.dim("auto-capture off")) : c.dim("unchanged")}`);
|
|
240
|
+
console.log(` ${c.label("Vector store:")} ${answers.vectorStore ? c.value(answers.vectorStore.provider) : c.dim("unchanged")}`);
|
|
241
|
+
console.log(`\n ${c.dim("Provider/model settings are written to the global config; toggles to .opencode/opencode-rag.json.")}`);
|
|
242
|
+
}
|
|
243
|
+
/** Ask the advanced questions (reranking, shell guard, memory, vector store). */
|
|
244
|
+
async function askAdvanced(prompter, existing, flags) {
|
|
245
|
+
const reranking = section(existing, "reranking");
|
|
246
|
+
const shellGuard = section(existing, "shellGuard");
|
|
247
|
+
const memory = section(existing, "memory");
|
|
248
|
+
const vectorStore = section(existing, "vectorStore");
|
|
249
|
+
const indexing = section(existing, "indexing");
|
|
250
|
+
const openCode = section(existing, "openCode");
|
|
251
|
+
const autoIndex = section(openCode ?? {}, "autoIndex");
|
|
252
|
+
const answers = {};
|
|
253
|
+
const wantRerank = flags.reranking ??
|
|
254
|
+
(await prompter.confirm({
|
|
255
|
+
message: "Enable reranking with a llama-server /v1/rerank endpoint?",
|
|
256
|
+
defaultValue: readBoolean(reranking, "enabled") ?? DEFAULT_CONFIG.reranking?.enabled ?? false,
|
|
257
|
+
}));
|
|
258
|
+
if (wantRerank === undefined)
|
|
259
|
+
return undefined;
|
|
260
|
+
if (wantRerank) {
|
|
261
|
+
const baseUrl = await prompter.text({
|
|
262
|
+
message: "Rerank base URL",
|
|
263
|
+
defaultValue: readString(reranking, "baseUrl") ?? DEFAULT_CONFIG.reranking?.baseUrl ?? "http://127.0.0.1:8080/v1",
|
|
264
|
+
});
|
|
265
|
+
if (baseUrl === undefined)
|
|
266
|
+
return undefined;
|
|
267
|
+
const model = await prompter.text({
|
|
268
|
+
message: "Rerank model",
|
|
269
|
+
defaultValue: readString(reranking, "model") ?? DEFAULT_CONFIG.reranking?.model ?? "qwen3-reranker-0.6b",
|
|
270
|
+
});
|
|
271
|
+
if (model === undefined)
|
|
272
|
+
return undefined;
|
|
273
|
+
answers.reranking = { enabled: true, baseUrl, model };
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
answers.reranking = { enabled: false };
|
|
277
|
+
}
|
|
278
|
+
const wantGuard = flags.shellGuard ??
|
|
279
|
+
(await prompter.confirm({
|
|
280
|
+
message: "Enable the shell-command guard (needs the decision model)?",
|
|
281
|
+
defaultValue: readBoolean(shellGuard, "enabled") ?? DEFAULT_CONFIG.shellGuard?.enabled ?? false,
|
|
282
|
+
}));
|
|
283
|
+
if (wantGuard === undefined)
|
|
284
|
+
return undefined;
|
|
285
|
+
answers.shellGuard = { enabled: wantGuard };
|
|
286
|
+
const wantCapture = flags.memoryCapture ??
|
|
287
|
+
(await prompter.confirm({
|
|
288
|
+
message: "Enable automatic quirk capture (passive + prompt enforcement + session end)?",
|
|
289
|
+
defaultValue: readBoolean(memory, "passiveCapture") ?? DEFAULT_CONFIG.memory?.passiveCapture ?? true,
|
|
290
|
+
}));
|
|
291
|
+
if (wantCapture === undefined)
|
|
292
|
+
return undefined;
|
|
293
|
+
answers.memory = {
|
|
294
|
+
passiveCapture: wantCapture,
|
|
295
|
+
promptEnforcement: wantCapture,
|
|
296
|
+
sessionEndExtraction: wantCapture,
|
|
297
|
+
};
|
|
298
|
+
const backendDefault = flags.vectorStore ?? readString(vectorStore, "provider") ?? "lancedb";
|
|
299
|
+
const backend = await prompter.select({
|
|
300
|
+
message: "Vector store backend",
|
|
301
|
+
options: [
|
|
302
|
+
{ label: "LanceDB (local, default)", value: "lancedb", description: "One index per workspace" },
|
|
303
|
+
{ label: "ClickHouse (central)", value: "clickhouse", description: "One shared index for many machines" },
|
|
304
|
+
],
|
|
305
|
+
defaultIndex: backendDefault === "clickhouse" ? 1 : 0,
|
|
306
|
+
});
|
|
307
|
+
if (backend === undefined)
|
|
308
|
+
return undefined;
|
|
309
|
+
if (backend === "clickhouse") {
|
|
310
|
+
const current = section(vectorStore ?? {}, "clickhouse");
|
|
311
|
+
const url = await prompter.text({
|
|
312
|
+
message: "ClickHouse URL",
|
|
313
|
+
defaultValue: flags.clickhouseUrl ?? readString(current, "url") ?? "http://localhost:8123",
|
|
314
|
+
});
|
|
315
|
+
if (url === undefined)
|
|
316
|
+
return undefined;
|
|
317
|
+
const database = await prompter.text({
|
|
318
|
+
message: "ClickHouse database",
|
|
319
|
+
defaultValue: flags.clickhouseDatabase ?? readString(current, "database") ?? "OpenCodeRAG",
|
|
320
|
+
});
|
|
321
|
+
if (database === undefined)
|
|
322
|
+
return undefined;
|
|
323
|
+
const username = await prompter.text({
|
|
324
|
+
message: "ClickHouse user",
|
|
325
|
+
defaultValue: flags.clickhouseUser ?? readString(current, "username") ?? "default",
|
|
326
|
+
});
|
|
327
|
+
if (username === undefined)
|
|
328
|
+
return undefined;
|
|
329
|
+
const passwordEnv = await prompter.text({
|
|
330
|
+
message: "Environment variable holding the ClickHouse password",
|
|
331
|
+
defaultValue: flags.clickhousePasswordEnv ?? readString(current, "passwordEnv") ?? "OPENCODERAG_CLICKHOUSE_PASSWORD",
|
|
332
|
+
});
|
|
333
|
+
if (passwordEnv === undefined)
|
|
334
|
+
return undefined;
|
|
335
|
+
const namespace = await prompter.text({
|
|
336
|
+
message: "Namespace (table suffix, optional)",
|
|
337
|
+
defaultValue: flags.clickhouseNamespace ?? readString(current, "namespace") ?? "",
|
|
338
|
+
});
|
|
339
|
+
if (namespace === undefined)
|
|
340
|
+
return undefined;
|
|
341
|
+
answers.vectorStore = {
|
|
342
|
+
provider: "clickhouse",
|
|
343
|
+
clickhouse: {
|
|
344
|
+
url,
|
|
345
|
+
database,
|
|
346
|
+
username,
|
|
347
|
+
passwordEnv,
|
|
348
|
+
...(namespace ? { namespace } : {}),
|
|
349
|
+
},
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
answers.vectorStore = { provider: "lancedb" };
|
|
354
|
+
}
|
|
355
|
+
const embedDescriptions = await prompter.confirm({
|
|
356
|
+
message: "Embed chunk descriptions as well as code? (turn off for code-specialized embedders)",
|
|
357
|
+
defaultValue: readBoolean(indexing, "embedDescriptions") ?? DEFAULT_CONFIG.indexing.embedDescriptions ?? true,
|
|
358
|
+
});
|
|
359
|
+
if (embedDescriptions === undefined)
|
|
360
|
+
return undefined;
|
|
361
|
+
answers.indexing = { embedDescriptions };
|
|
362
|
+
const wantWatcher = await prompter.confirm({
|
|
363
|
+
message: "Run the background indexer automatically?",
|
|
364
|
+
defaultValue: readBoolean(autoIndex, "enabled") ?? DEFAULT_CONFIG.openCode.autoIndex?.enabled ?? false,
|
|
365
|
+
});
|
|
366
|
+
if (wantWatcher === undefined)
|
|
367
|
+
return undefined;
|
|
368
|
+
answers.openCode = { autoIndex: wantWatcher };
|
|
369
|
+
return answers;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Whether the caller passed any flag that should override the stored config.
|
|
373
|
+
*
|
|
374
|
+
* `setup` only rewrites configuration when the wizard ran, when a flag was
|
|
375
|
+
* supplied, or when no config exists yet.
|
|
376
|
+
*/
|
|
377
|
+
export function hasExplicitSetupFlags(flags) {
|
|
378
|
+
const keys = [
|
|
379
|
+
"provider",
|
|
380
|
+
"baseUrl",
|
|
381
|
+
"apiKey",
|
|
382
|
+
"embeddingModel",
|
|
383
|
+
"descriptionModel",
|
|
384
|
+
"visionModel",
|
|
385
|
+
"decisionModel",
|
|
386
|
+
"description",
|
|
387
|
+
"vision",
|
|
388
|
+
"decision",
|
|
389
|
+
"reranking",
|
|
390
|
+
"shellGuard",
|
|
391
|
+
"memoryCapture",
|
|
392
|
+
"vectorStore",
|
|
393
|
+
];
|
|
394
|
+
return keys.some((key) => flags[key] !== undefined);
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Build answers from CLI flags plus the existing config, for non-interactive
|
|
398
|
+
* runs (`--yes`, CI, piped stdin).
|
|
399
|
+
*
|
|
400
|
+
* Only used when at least one explicit flag is present; otherwise `setup`
|
|
401
|
+
* leaves the stored configuration alone.
|
|
402
|
+
*/
|
|
403
|
+
export function answersFromFlags(flags, existing) {
|
|
404
|
+
const embeddingSection = section(existing, "embedding");
|
|
405
|
+
const provider = flags.provider ?? readString(embeddingSection, "provider") ?? DEFAULT_CONFIG.embedding.provider;
|
|
406
|
+
const baseUrl = flags.baseUrl ??
|
|
407
|
+
readString(embeddingSection, "baseUrl") ??
|
|
408
|
+
(provider === "ollama" ? "http://127.0.0.1:11434/api" : defaultBaseUrl(provider));
|
|
409
|
+
const apiKey = flags.apiKey?.startsWith("env:")
|
|
410
|
+
? process.env[flags.apiKey.slice(4)]
|
|
411
|
+
: flags.apiKey ?? readString(embeddingSection, "apiKey");
|
|
412
|
+
const vectorDimension = typeof embeddingSection?.vectorDimension === "number" ? embeddingSection.vectorDimension : undefined;
|
|
413
|
+
const embedding = {
|
|
414
|
+
provider,
|
|
415
|
+
baseUrl,
|
|
416
|
+
...(apiKey ? { apiKey } : {}),
|
|
417
|
+
model: flags.embeddingModel ?? readString(embeddingSection, "model") ?? DEFAULT_CONFIG.embedding.model,
|
|
418
|
+
...(vectorDimension ? { vectorDimension } : {}),
|
|
419
|
+
};
|
|
420
|
+
const descriptionSection = section(existing, "description");
|
|
421
|
+
const descriptionFlag = flags.description ?? (flags.descriptionModel ? true : undefined);
|
|
422
|
+
const chatAvailable = supportsChat(provider) || readString(descriptionSection, "provider") !== undefined;
|
|
423
|
+
// Only touch descriptions when asked, or when a fresh workspace gets a host
|
|
424
|
+
// that can actually serve chat completions.
|
|
425
|
+
const enableDescription = descriptionFlag === true ||
|
|
426
|
+
(descriptionFlag === undefined && descriptionSection === undefined && chatAvailable);
|
|
427
|
+
const description = enableDescription
|
|
428
|
+
? {
|
|
429
|
+
provider: readString(descriptionSection, "provider") ?? provider,
|
|
430
|
+
baseUrl: readString(descriptionSection, "baseUrl") ?? baseUrl,
|
|
431
|
+
...(readString(descriptionSection, "apiKey") ? { apiKey: readString(descriptionSection, "apiKey") } : {}),
|
|
432
|
+
model: flags.descriptionModel ??
|
|
433
|
+
readString(descriptionSection, "model") ??
|
|
434
|
+
DEFAULT_CONFIG.description?.model ??
|
|
435
|
+
"qwen2.5:3b",
|
|
436
|
+
}
|
|
437
|
+
: undefined;
|
|
438
|
+
const descriptionEnabled = descriptionFlag === false ? false : enableDescription ? true : undefined;
|
|
439
|
+
const visionSection = section(existing, "imageDescription");
|
|
440
|
+
const visionFlag = flags.vision ?? (flags.visionModel ? true : undefined);
|
|
441
|
+
const imageDescription = visionFlag === true && chatAvailable
|
|
442
|
+
? {
|
|
443
|
+
provider: readString(visionSection, "provider") ?? provider,
|
|
444
|
+
baseUrl: readString(visionSection, "baseUrl") ?? baseUrl,
|
|
445
|
+
...(readString(visionSection, "apiKey") ? { apiKey: readString(visionSection, "apiKey") } : {}),
|
|
446
|
+
model: flags.visionModel ??
|
|
447
|
+
readString(visionSection, "model") ??
|
|
448
|
+
DEFAULT_CONFIG.imageDescription?.model ??
|
|
449
|
+
"minicpm-v4.6:latest",
|
|
450
|
+
}
|
|
451
|
+
: undefined;
|
|
452
|
+
const imageDescriptionEnabled = visionFlag === false ? false : visionFlag === true ? true : undefined;
|
|
453
|
+
const decisionSection = section(existing, "decision");
|
|
454
|
+
const decisionFlag = flags.decision ?? (flags.decisionModel ? true : undefined);
|
|
455
|
+
let decision;
|
|
456
|
+
if (decisionFlag === true) {
|
|
457
|
+
decision = {
|
|
458
|
+
enabled: true,
|
|
459
|
+
baseUrl: readString(decisionSection, "baseUrl") ?? "http://127.0.0.1:11434/api",
|
|
460
|
+
model: flags.decisionModel ?? readString(decisionSection, "model") ?? DEFAULT_CONFIG.decision?.model ?? "tev1:4b",
|
|
461
|
+
routeBeforeAsking: readBoolean(decisionSection, "routeBeforeAsking") ?? false,
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
else if (decisionFlag === false) {
|
|
465
|
+
decision = { enabled: false };
|
|
466
|
+
}
|
|
467
|
+
const answers = {
|
|
468
|
+
embedding,
|
|
469
|
+
...(descriptionEnabled !== undefined ? { descriptionEnabled } : {}),
|
|
470
|
+
...(imageDescriptionEnabled !== undefined ? { imageDescriptionEnabled } : {}),
|
|
471
|
+
...(description ? { description } : {}),
|
|
472
|
+
...(imageDescription ? { imageDescription } : {}),
|
|
473
|
+
...(decision ? { decision } : {}),
|
|
474
|
+
};
|
|
475
|
+
if (flags.reranking !== undefined) {
|
|
476
|
+
const rerankSection = section(existing, "reranking");
|
|
477
|
+
answers.reranking = flags.reranking
|
|
478
|
+
? {
|
|
479
|
+
enabled: true,
|
|
480
|
+
baseUrl: readString(rerankSection, "baseUrl") ?? DEFAULT_CONFIG.reranking?.baseUrl ?? "http://127.0.0.1:8080/v1",
|
|
481
|
+
model: readString(rerankSection, "model") ?? DEFAULT_CONFIG.reranking?.model ?? "qwen3-reranker-0.6b",
|
|
482
|
+
}
|
|
483
|
+
: { enabled: false };
|
|
484
|
+
}
|
|
485
|
+
if (flags.shellGuard !== undefined) {
|
|
486
|
+
answers.shellGuard = { enabled: flags.shellGuard };
|
|
487
|
+
}
|
|
488
|
+
if (flags.memoryCapture !== undefined) {
|
|
489
|
+
answers.memory = {
|
|
490
|
+
passiveCapture: flags.memoryCapture,
|
|
491
|
+
promptEnforcement: flags.memoryCapture,
|
|
492
|
+
sessionEndExtraction: flags.memoryCapture,
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
if (flags.vectorStore) {
|
|
496
|
+
const clickhouseSection = section(section(existing, "vectorStore") ?? {}, "clickhouse");
|
|
497
|
+
answers.vectorStore =
|
|
498
|
+
flags.vectorStore === "clickhouse"
|
|
499
|
+
? {
|
|
500
|
+
provider: "clickhouse",
|
|
501
|
+
clickhouse: {
|
|
502
|
+
url: flags.clickhouseUrl ?? readString(clickhouseSection, "url") ?? "http://localhost:8123",
|
|
503
|
+
database: flags.clickhouseDatabase ?? readString(clickhouseSection, "database") ?? "OpenCodeRAG",
|
|
504
|
+
username: flags.clickhouseUser ?? readString(clickhouseSection, "username") ?? "default",
|
|
505
|
+
passwordEnv: flags.clickhousePasswordEnv ??
|
|
506
|
+
readString(clickhouseSection, "passwordEnv") ??
|
|
507
|
+
"OPENCODERAG_CLICKHOUSE_PASSWORD",
|
|
508
|
+
...(flags.clickhouseNamespace ?? readString(clickhouseSection, "namespace")
|
|
509
|
+
? { namespace: flags.clickhouseNamespace ?? readString(clickhouseSection, "namespace") }
|
|
510
|
+
: {}),
|
|
511
|
+
},
|
|
512
|
+
}
|
|
513
|
+
: { provider: "lancedb" };
|
|
514
|
+
}
|
|
515
|
+
return answers;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Run the interactive wizard.
|
|
519
|
+
*
|
|
520
|
+
* @returns The collected answers, or `undefined` when the user cancelled or
|
|
521
|
+
* declined to apply the configuration.
|
|
522
|
+
*/
|
|
523
|
+
export async function runSetupWizard(options) {
|
|
524
|
+
const { prompter, existing } = options;
|
|
525
|
+
const flags = options;
|
|
526
|
+
console.log(`\n${c.heading("OpenCodeRAG setup")}`);
|
|
527
|
+
console.log(`\n ${c.dim("Answer the questions below. Enter accepts the value in [brackets].")}\n`);
|
|
528
|
+
const primary = await askHost(prompter, {
|
|
529
|
+
message: "Which provider hosts your models?",
|
|
530
|
+
existing,
|
|
531
|
+
flags,
|
|
532
|
+
proxy: options.proxy,
|
|
533
|
+
requireEmbedding: false,
|
|
534
|
+
});
|
|
535
|
+
if (!primary)
|
|
536
|
+
return undefined;
|
|
537
|
+
let embeddingHost = primary;
|
|
538
|
+
if (!supportsEmbedding(primary.host.provider)) {
|
|
539
|
+
console.log(`\n ${c.warn(`${primary.host.provider} does not provide embeddings.`)} Choose a separate embedding host.`);
|
|
540
|
+
const separate = await askHost(prompter, {
|
|
541
|
+
message: "Embedding provider",
|
|
542
|
+
existing: {},
|
|
543
|
+
flags: { ...flags, provider: undefined, baseUrl: undefined, apiKey: undefined },
|
|
544
|
+
proxy: options.proxy,
|
|
545
|
+
requireEmbedding: true,
|
|
546
|
+
});
|
|
547
|
+
if (!separate)
|
|
548
|
+
return undefined;
|
|
549
|
+
embeddingHost = separate;
|
|
550
|
+
}
|
|
551
|
+
const embeddingModel = await pickModel(prompter, {
|
|
552
|
+
message: "Embedding model",
|
|
553
|
+
catalog: embeddingHost.catalog,
|
|
554
|
+
capability: "embedding",
|
|
555
|
+
defaultValue: flags.embeddingModel ??
|
|
556
|
+
readString(section(existing, "embedding"), "model") ??
|
|
557
|
+
DEFAULT_CONFIG.embedding.model,
|
|
558
|
+
});
|
|
559
|
+
if (embeddingModel === undefined)
|
|
560
|
+
return undefined;
|
|
561
|
+
let vectorDimension;
|
|
562
|
+
if (embeddingHost.catalog.reachable) {
|
|
563
|
+
const previousDimension = section(existing, "embedding")?.vectorDimension;
|
|
564
|
+
const previousModel = readString(section(existing, "embedding"), "model");
|
|
565
|
+
vectorDimension = await probeEmbeddingDimension({
|
|
566
|
+
provider: embeddingHost.host.provider,
|
|
567
|
+
baseUrl: embeddingHost.host.baseUrl,
|
|
568
|
+
model: embeddingModel,
|
|
569
|
+
apiKey: embeddingHost.host.apiKey,
|
|
570
|
+
proxy: options.proxy,
|
|
571
|
+
});
|
|
572
|
+
if (vectorDimension) {
|
|
573
|
+
console.log(` ${c.success("✓")} ${c.value(embeddingModel)} produces ${vectorDimension}-dimensional vectors`);
|
|
574
|
+
}
|
|
575
|
+
else if (typeof previousDimension === "number" && previousModel === embeddingModel) {
|
|
576
|
+
vectorDimension = previousDimension;
|
|
577
|
+
console.log(` ${c.dim(`Kept the configured vector dimension (${previousDimension}).`)}`);
|
|
578
|
+
}
|
|
579
|
+
else {
|
|
580
|
+
console.log(` ${c.warn("Could not probe the vector dimension.")} It will be detected on the first index run.`);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
const embedding = {
|
|
584
|
+
provider: embeddingHost.host.provider,
|
|
585
|
+
baseUrl: embeddingHost.host.baseUrl,
|
|
586
|
+
...(embeddingHost.host.apiKey ? { apiKey: embeddingHost.host.apiKey } : {}),
|
|
587
|
+
model: embeddingModel,
|
|
588
|
+
...(vectorDimension ? { vectorDimension } : {}),
|
|
589
|
+
};
|
|
590
|
+
// ── Chat host (shared by description and vision) ──
|
|
591
|
+
const descriptionDefault = flags.description ??
|
|
592
|
+
(flags.descriptionModel ? true : undefined) ??
|
|
593
|
+
readBoolean(section(existing, "description"), "enabled") ??
|
|
594
|
+
(supportsChat(primary.host.provider) ? (DEFAULT_CONFIG.description?.enabled ?? true) : false);
|
|
595
|
+
const wantDescription = await prompter.confirm({
|
|
596
|
+
message: "Generate LLM descriptions for indexed code chunks?",
|
|
597
|
+
defaultValue: descriptionDefault,
|
|
598
|
+
});
|
|
599
|
+
if (wantDescription === undefined)
|
|
600
|
+
return undefined;
|
|
601
|
+
const visionDefault = flags.vision ??
|
|
602
|
+
(flags.visionModel ? true : undefined) ??
|
|
603
|
+
readBoolean(section(existing, "imageDescription"), "enabled") ??
|
|
604
|
+
false;
|
|
605
|
+
const wantVision = await prompter.confirm({
|
|
606
|
+
message: "Describe images with a vision model?",
|
|
607
|
+
defaultValue: visionDefault,
|
|
608
|
+
});
|
|
609
|
+
if (wantVision === undefined)
|
|
610
|
+
return undefined;
|
|
611
|
+
let chatHost = primary;
|
|
612
|
+
if ((wantDescription || wantVision) && !supportsChat(primary.host.provider)) {
|
|
613
|
+
console.log(`\n ${c.warn(`${primary.host.provider} cannot serve chat completions.`)} Choose a chat/vision host.`);
|
|
614
|
+
const separate = await askHost(prompter, {
|
|
615
|
+
message: "Chat/vision provider",
|
|
616
|
+
existing: {},
|
|
617
|
+
flags: { ...flags, provider: undefined, baseUrl: undefined, apiKey: undefined },
|
|
618
|
+
proxy: options.proxy,
|
|
619
|
+
requireChat: true,
|
|
620
|
+
});
|
|
621
|
+
if (!separate)
|
|
622
|
+
return undefined;
|
|
623
|
+
chatHost = separate;
|
|
624
|
+
}
|
|
625
|
+
let description;
|
|
626
|
+
if (wantDescription) {
|
|
627
|
+
const model = await pickModel(prompter, {
|
|
628
|
+
message: "Description model",
|
|
629
|
+
catalog: chatHost.catalog,
|
|
630
|
+
capability: "chat",
|
|
631
|
+
defaultValue: flags.descriptionModel ??
|
|
632
|
+
readString(section(existing, "description"), "model") ??
|
|
633
|
+
DEFAULT_CONFIG.description?.model,
|
|
634
|
+
});
|
|
635
|
+
if (model === undefined)
|
|
636
|
+
return undefined;
|
|
637
|
+
description = {
|
|
638
|
+
provider: chatHost.host.provider,
|
|
639
|
+
baseUrl: chatHost.host.baseUrl,
|
|
640
|
+
...(chatHost.host.apiKey ? { apiKey: chatHost.host.apiKey } : {}),
|
|
641
|
+
model,
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
let imageDescription;
|
|
645
|
+
if (wantVision) {
|
|
646
|
+
const model = await pickModel(prompter, {
|
|
647
|
+
message: "Vision model",
|
|
648
|
+
catalog: chatHost.catalog,
|
|
649
|
+
capability: "vision",
|
|
650
|
+
defaultValue: flags.visionModel ??
|
|
651
|
+
readString(section(existing, "imageDescription"), "model") ??
|
|
652
|
+
DEFAULT_CONFIG.imageDescription?.model,
|
|
653
|
+
});
|
|
654
|
+
if (model === undefined)
|
|
655
|
+
return undefined;
|
|
656
|
+
imageDescription = {
|
|
657
|
+
provider: chatHost.host.provider,
|
|
658
|
+
baseUrl: chatHost.host.baseUrl,
|
|
659
|
+
...(chatHost.host.apiKey ? { apiKey: chatHost.host.apiKey } : {}),
|
|
660
|
+
model,
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
// ── Decision model (Ollama only) ──
|
|
664
|
+
const decisionSection = section(existing, "decision");
|
|
665
|
+
const decisionDefault = flags.decision ??
|
|
666
|
+
(flags.decisionModel ? true : undefined) ??
|
|
667
|
+
readBoolean(decisionSection, "enabled") ??
|
|
668
|
+
DEFAULT_CONFIG.decision?.enabled ??
|
|
669
|
+
false;
|
|
670
|
+
const wantDecision = await prompter.confirm({
|
|
671
|
+
message: "Enable the local decision model (make_decision, tev1)?",
|
|
672
|
+
defaultValue: decisionDefault,
|
|
673
|
+
});
|
|
674
|
+
if (wantDecision === undefined)
|
|
675
|
+
return undefined;
|
|
676
|
+
let decision;
|
|
677
|
+
if (wantDecision) {
|
|
678
|
+
const knownOllama = [primary, embeddingHost, chatHost].find((host) => host.host.provider === "ollama");
|
|
679
|
+
let decisionBaseUrl = readString(decisionSection, "baseUrl") ??
|
|
680
|
+
knownOllama?.host.baseUrl ??
|
|
681
|
+
"http://127.0.0.1:11434/api";
|
|
682
|
+
if (!knownOllama) {
|
|
683
|
+
const typed = await prompter.text({
|
|
684
|
+
message: "Ollama base URL for the decision model",
|
|
685
|
+
defaultValue: decisionBaseUrl,
|
|
686
|
+
hint: "tev1 requires Ollama >= 0.35 and `ollama pull tev1:0.8b`",
|
|
687
|
+
});
|
|
688
|
+
if (typed === undefined)
|
|
689
|
+
return undefined;
|
|
690
|
+
decisionBaseUrl = typed;
|
|
691
|
+
}
|
|
692
|
+
const decisionModel = await prompter.select({
|
|
693
|
+
message: "Decision model",
|
|
694
|
+
options: [
|
|
695
|
+
{ label: "tev1:0.8b", value: "tev1:0.8b", description: "Fastest, good default" },
|
|
696
|
+
{ label: "tev1:4b", value: "tev1:4b", description: "More accurate, slower" },
|
|
697
|
+
{ label: "tev1", value: "tev1", description: "Whichever tag is pulled" },
|
|
698
|
+
{ label: "Type a model name…", value: "__custom__" },
|
|
699
|
+
],
|
|
700
|
+
defaultIndex: 0,
|
|
701
|
+
});
|
|
702
|
+
if (decisionModel === undefined)
|
|
703
|
+
return undefined;
|
|
704
|
+
let resolvedDecisionModel = decisionModel;
|
|
705
|
+
if (decisionModel === "__custom__") {
|
|
706
|
+
const typed = await prompter.text({
|
|
707
|
+
message: "Decision model",
|
|
708
|
+
defaultValue: flags.decisionModel ?? readString(decisionSection, "model") ?? "tev1:0.8b",
|
|
709
|
+
});
|
|
710
|
+
if (typed === undefined)
|
|
711
|
+
return undefined;
|
|
712
|
+
resolvedDecisionModel = typed;
|
|
713
|
+
}
|
|
714
|
+
const routeBeforeAsking = await prompter.confirm({
|
|
715
|
+
message: "Let the agent route choices through make_decision before asking you?",
|
|
716
|
+
defaultValue: readBoolean(decisionSection, "routeBeforeAsking") ?? false,
|
|
717
|
+
});
|
|
718
|
+
if (routeBeforeAsking === undefined)
|
|
719
|
+
return undefined;
|
|
720
|
+
decision = {
|
|
721
|
+
enabled: true,
|
|
722
|
+
baseUrl: ollamaRoot(decisionBaseUrl) + "/api",
|
|
723
|
+
model: resolvedDecisionModel,
|
|
724
|
+
routeBeforeAsking,
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
else {
|
|
728
|
+
decision = { enabled: false };
|
|
729
|
+
}
|
|
730
|
+
// ── Advanced options ──
|
|
731
|
+
const advancedFlagsSet = flags.reranking !== undefined ||
|
|
732
|
+
flags.shellGuard !== undefined ||
|
|
733
|
+
flags.memoryCapture !== undefined ||
|
|
734
|
+
flags.vectorStore !== undefined;
|
|
735
|
+
const advanced = advancedFlagsSet || await prompter.confirm({
|
|
736
|
+
message: "Configure advanced options (reranking, shell guard, memory, vector store)?",
|
|
737
|
+
defaultValue: false,
|
|
738
|
+
});
|
|
739
|
+
if (advanced === undefined)
|
|
740
|
+
return undefined;
|
|
741
|
+
const advancedAnswers = advanced ? await askAdvanced(prompter, existing, flags) : undefined;
|
|
742
|
+
if (advancedAnswers === undefined && advanced)
|
|
743
|
+
return undefined;
|
|
744
|
+
const answers = {
|
|
745
|
+
embedding,
|
|
746
|
+
descriptionEnabled: wantDescription,
|
|
747
|
+
imageDescriptionEnabled: wantVision,
|
|
748
|
+
...(description ? { description } : {}),
|
|
749
|
+
...(imageDescription ? { imageDescription } : {}),
|
|
750
|
+
...(decision ? { decision } : {}),
|
|
751
|
+
...(advancedAnswers ?? {}),
|
|
752
|
+
};
|
|
753
|
+
printSummary(answers);
|
|
754
|
+
const apply = await prompter.confirm({ message: "Apply this configuration?", defaultValue: true });
|
|
755
|
+
if (apply === undefined)
|
|
756
|
+
return undefined;
|
|
757
|
+
return apply ? answers : undefined;
|
|
758
|
+
}
|
|
759
|
+
//# sourceMappingURL=flow.js.map
|