opencode-rag-plugin 2.5.1 → 2.5.3
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/cli/index.d.ts +5 -0
- package/dist/cli/index.js +75 -5
- package/dist/plugin.d.ts +41 -0
- package/dist/plugin.js +158 -14
- package/package.json +1 -1
package/dist/cli/index.d.ts
CHANGED
|
@@ -27,6 +27,11 @@ export declare function shouldAutoRunCli(moduleUrl: string, argv1?: string): boo
|
|
|
27
27
|
* This is the public API entry point for running the CLI from code
|
|
28
28
|
* (e.g. from tests or the library export).
|
|
29
29
|
*
|
|
30
|
+
* Never terminates the host process: Commander's exits are converted into
|
|
31
|
+
* errors. `--help` and `--version` resolve normally (their output was
|
|
32
|
+
* already printed); every other Commander error — a missing required
|
|
33
|
+
* argument, an unknown option — is rethrown so the caller can react.
|
|
34
|
+
*
|
|
30
35
|
* @param argv - The argument vector to parse (defaults to `process.argv`).
|
|
31
36
|
*/
|
|
32
37
|
export declare function runCli(argv?: string[]): Promise<void>;
|
package/dist/cli/index.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* referenced by the `bin` entry in `package.json`. The sibling file
|
|
11
11
|
* `dist/cli.js` is a backwards-compatibility re-export shim.
|
|
12
12
|
*/
|
|
13
|
-
import { Command } from "commander";
|
|
13
|
+
import { Command, CommanderError } from "commander";
|
|
14
14
|
import { realpathSync } from "node:fs";
|
|
15
15
|
import { basename, dirname } from "node:path";
|
|
16
16
|
import { fileURLToPath } from "node:url";
|
|
@@ -29,6 +29,15 @@ program
|
|
|
29
29
|
.name("opencode-rag")
|
|
30
30
|
.description(`Local-first RAG semantic code search v${pkg.version}`)
|
|
31
31
|
.version(pkg.version);
|
|
32
|
+
// Commander's default is to call `process.exit()` for `--help`, `--version`
|
|
33
|
+
// and argument-validation errors. That is fatal for `runCli()` — the
|
|
34
|
+
// programmatic API used by tests and library consumers: a `--help` would
|
|
35
|
+
// terminate the *host* process instead of returning. Override the exit so
|
|
36
|
+
// Commander throws a `CommanderError` that the caller can handle.
|
|
37
|
+
//
|
|
38
|
+
// This MUST be set before the sub-commands are registered: they inherit
|
|
39
|
+
// `_exitCallback` from the parent through `copyInheritedSettings()`.
|
|
40
|
+
program.exitOverride();
|
|
32
41
|
registerIndexCommand(program);
|
|
33
42
|
registerQueryCommand(program);
|
|
34
43
|
registerClearCommand(program);
|
|
@@ -73,8 +82,57 @@ export function shouldAutoRunCli(moduleUrl, argv1) {
|
|
|
73
82
|
return false;
|
|
74
83
|
}
|
|
75
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Commander error codes that mean "the requested output was printed, exit
|
|
87
|
+
* successfully". `--help` and `--version` are successful outcomes, not
|
|
88
|
+
* failures — they just ask Commander to exit with code 0.
|
|
89
|
+
*/
|
|
90
|
+
const DISPLAY_EXIT_CODES = new Set([
|
|
91
|
+
"commander.helpDisplayed",
|
|
92
|
+
"commander.help",
|
|
93
|
+
"commander.version",
|
|
94
|
+
]);
|
|
95
|
+
/**
|
|
96
|
+
* Check whether a thrown value is Commander's "output was displayed" exit.
|
|
97
|
+
*
|
|
98
|
+
* @param err - The value thrown by `program.parseAsync()`.
|
|
99
|
+
* @returns `true` for `--help` / `--version` style exits.
|
|
100
|
+
*/
|
|
101
|
+
function isDisplayExit(err) {
|
|
102
|
+
const code = err?.code;
|
|
103
|
+
return typeof code === "string" && DISPLAY_EXIT_CODES.has(code);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Run the CLI as a real command-line process.
|
|
107
|
+
*
|
|
108
|
+
* Commander already wrote the error message to stderr before throwing, so
|
|
109
|
+
* the only thing left to do is map the error to an exit code. Setting
|
|
110
|
+
* `process.exitCode` (instead of calling `process.exit()`) lets pending
|
|
111
|
+
* async work drain first and avoids tearing down live handles mid-flight.
|
|
112
|
+
*
|
|
113
|
+
* @param err - The value thrown by `program.parseAsync()`.
|
|
114
|
+
*/
|
|
115
|
+
function handleCliExit(err) {
|
|
116
|
+
if (isDisplayExit(err)) {
|
|
117
|
+
// Commander's own `help()` exits with `process.exitCode || 0` — respect
|
|
118
|
+
// an exit code a command may already have set.
|
|
119
|
+
process.exitCode = process.exitCode || 0;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (err instanceof CommanderError) {
|
|
123
|
+
process.exitCode = err.exitCode;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
// Not a Commander control-flow error — rethrow so Node reports it as an
|
|
127
|
+
// unhandled rejection with a visible stack trace, exactly as before.
|
|
128
|
+
throw err;
|
|
129
|
+
}
|
|
130
|
+
/** Parse `process.argv` as a real CLI invocation. */
|
|
131
|
+
function runAsCli() {
|
|
132
|
+
void program.parseAsync(process.argv).catch(handleCliExit);
|
|
133
|
+
}
|
|
76
134
|
if (shouldAutoRunCli(import.meta.url, process.argv[1])) {
|
|
77
|
-
|
|
135
|
+
runAsCli();
|
|
78
136
|
}
|
|
79
137
|
else {
|
|
80
138
|
// Fallback: auto-run only when the script being executed IS the CLI entry
|
|
@@ -85,7 +143,7 @@ else {
|
|
|
85
143
|
const cliScript = basename(modulePath);
|
|
86
144
|
const runningScript = basename(argvRaw);
|
|
87
145
|
if (cliScript === runningScript) {
|
|
88
|
-
|
|
146
|
+
runAsCli();
|
|
89
147
|
}
|
|
90
148
|
else {
|
|
91
149
|
// Backwards-compatibility: when a shim points to the sibling cli.js
|
|
@@ -94,7 +152,7 @@ else {
|
|
|
94
152
|
try {
|
|
95
153
|
const resolvedArgv = realpathSync(argvRaw);
|
|
96
154
|
if (dirname(resolvedArgv) === dirname(dirname(modulePath))) {
|
|
97
|
-
|
|
155
|
+
runAsCli();
|
|
98
156
|
}
|
|
99
157
|
}
|
|
100
158
|
catch {
|
|
@@ -108,9 +166,21 @@ else {
|
|
|
108
166
|
* This is the public API entry point for running the CLI from code
|
|
109
167
|
* (e.g. from tests or the library export).
|
|
110
168
|
*
|
|
169
|
+
* Never terminates the host process: Commander's exits are converted into
|
|
170
|
+
* errors. `--help` and `--version` resolve normally (their output was
|
|
171
|
+
* already printed); every other Commander error — a missing required
|
|
172
|
+
* argument, an unknown option — is rethrown so the caller can react.
|
|
173
|
+
*
|
|
111
174
|
* @param argv - The argument vector to parse (defaults to `process.argv`).
|
|
112
175
|
*/
|
|
113
176
|
export async function runCli(argv = process.argv) {
|
|
114
|
-
|
|
177
|
+
try {
|
|
178
|
+
await program.parseAsync(argv);
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
if (isDisplayExit(err))
|
|
182
|
+
return;
|
|
183
|
+
throw err;
|
|
184
|
+
}
|
|
115
185
|
}
|
|
116
186
|
//# sourceMappingURL=index.js.map
|
package/dist/plugin.d.ts
CHANGED
|
@@ -8,6 +8,47 @@ import { type EmbeddingProvider, type DescriptionProvider, type KeywordIndex, ty
|
|
|
8
8
|
import { type RagConfig } from "./core/config.js";
|
|
9
9
|
import { createEmbedder } from "./embedder/factory.js";
|
|
10
10
|
import { retrieve } from "./retriever/retriever.js";
|
|
11
|
+
/**
|
|
12
|
+
* Load the RAG configuration for a directory, searching in order:
|
|
13
|
+
* opencode-rag.json, .opencode/opencode-rag.json, .opencode/rag.json.
|
|
14
|
+
*
|
|
15
|
+
* The result is cached per directory and re-read whenever the config file
|
|
16
|
+
* changes on disk, so an edited API key or baseUrl does not require a restart.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getConfig(directory: string): Promise<RagConfig>;
|
|
19
|
+
/**
|
|
20
|
+
* Re-read a workspace's config file when it changed on disk.
|
|
21
|
+
*
|
|
22
|
+
* Only a config that this module loaded from a file is refreshed — the cache
|
|
23
|
+
* entry is the proof that the file is the source of truth for that workspace.
|
|
24
|
+
* A caller that supplies its own configuration (tests, embedders) keeps it.
|
|
25
|
+
*
|
|
26
|
+
* Synchronous on purpose: this runs on the hot path (every effective-config
|
|
27
|
+
* lookup) and `loadConfig` is synchronous. The pluggable-chunker side effect
|
|
28
|
+
* (`loadChunkersFromConfig`) mutates a global registry and is therefore
|
|
29
|
+
* re-applied asynchronously — it is not needed by the embedding path this
|
|
30
|
+
* refresh exists to fix.
|
|
31
|
+
*
|
|
32
|
+
* @param directory - Workspace directory whose config should be refreshed.
|
|
33
|
+
* @param fallback - Config to use when the workspace has no file-backed config.
|
|
34
|
+
* @returns The configuration currently in effect.
|
|
35
|
+
*/
|
|
36
|
+
export declare function refreshConfig(directory: string, fallback: RagConfig): RagConfig;
|
|
37
|
+
/**
|
|
38
|
+
* Wrap an embedding provider so it follows the live configuration.
|
|
39
|
+
*
|
|
40
|
+
* The provider is rebuilt whenever the embedding-relevant config changes on
|
|
41
|
+
* disk. Without this, the provider built at plugin setup kept using a stale
|
|
42
|
+
* API key / baseUrl until OpenCode was restarted — which surfaced as a 401
|
|
43
|
+
* that looked like an OpenAI auth error while the CLI worked fine against the
|
|
44
|
+
* very same config file.
|
|
45
|
+
*
|
|
46
|
+
* @param getConfig - Returns the configuration currently in effect.
|
|
47
|
+
* @param create - Factory that builds a provider for a configuration.
|
|
48
|
+
* @param initial - Provider to use until the configuration changes.
|
|
49
|
+
* @returns A provider that tracks the live configuration.
|
|
50
|
+
*/
|
|
51
|
+
export declare function createLiveEmbedder(getConfig: () => RagConfig, create: (cfg: RagConfig) => EmbeddingProvider, initial?: EmbeddingProvider): EmbeddingProvider;
|
|
11
52
|
/** Internal dependencies that can be overridden for testing. */
|
|
12
53
|
type RagPluginDependencies = {
|
|
13
54
|
createEmbedder: typeof createEmbedder;
|
package/dist/plugin.js
CHANGED
|
@@ -33,7 +33,7 @@ import { listQuirks, lintQuirks, recallQuirks, sharedWords, reconcileQuirks } fr
|
|
|
33
33
|
import { autoCaptureQuirks } from "./quirks/auto-capture.js";
|
|
34
34
|
import { createToolErrorInjectionState, selectToolErrorQuirks, formatToolErrorQuirkBlock, toToolErrorCaptureEntry, } from "./quirks/tool-error-recall.js";
|
|
35
35
|
import { buildSystemGuidanceLines } from "./opencode/system-guidance.js";
|
|
36
|
-
import { existsSync, readFileSync, readdirSync, unlinkSync } from "node:fs";
|
|
36
|
+
import { existsSync, readFileSync, readdirSync, statSync, unlinkSync } from "node:fs";
|
|
37
37
|
import path from "node:path";
|
|
38
38
|
/** Maximum entries per session map before oldest entries are evicted. */
|
|
39
39
|
const MAX_SESSION_MAP_SIZE = 50;
|
|
@@ -196,21 +196,46 @@ function indentMultiline(text, indent) {
|
|
|
196
196
|
.map((line) => `${prefix}${line}`)
|
|
197
197
|
.join("\n");
|
|
198
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* mtime of a config file in milliseconds, or -1 when it does not exist.
|
|
201
|
+
*/
|
|
202
|
+
function configFileMtime(configPath) {
|
|
203
|
+
if (!configPath)
|
|
204
|
+
return -1;
|
|
205
|
+
try {
|
|
206
|
+
return statSync(configPath).mtimeMs;
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
return -1;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
199
212
|
/**
|
|
200
213
|
* Load the RAG configuration for a directory, searching in order:
|
|
201
214
|
* opencode-rag.json, .opencode/opencode-rag.json, .opencode/rag.json.
|
|
202
|
-
*
|
|
215
|
+
*
|
|
216
|
+
* The result is cached per directory and re-read whenever the config file
|
|
217
|
+
* changes on disk, so an edited API key or baseUrl does not require a restart.
|
|
203
218
|
*/
|
|
204
|
-
async function getConfig(directory) {
|
|
205
|
-
const cached = configCache.get(directory);
|
|
206
|
-
if (cached)
|
|
207
|
-
return cached;
|
|
219
|
+
export async function getConfig(directory) {
|
|
208
220
|
const configPath = findConfigFile(directory);
|
|
221
|
+
const mtimeMs = configFileMtime(configPath);
|
|
222
|
+
const cached = configCache.get(directory);
|
|
223
|
+
if (cached && cached.configPath === configPath && cached.mtimeMs === mtimeMs) {
|
|
224
|
+
return cached.cfg;
|
|
225
|
+
}
|
|
209
226
|
if (configPath) {
|
|
210
227
|
try {
|
|
211
228
|
const cfg = loadConfig(configPath);
|
|
212
229
|
await loadChunkersFromConfig(cfg, path.dirname(configPath));
|
|
213
|
-
|
|
230
|
+
const hadKey = !!cfg.embedding.apiKey;
|
|
231
|
+
resolveApiKey(cfg, directory);
|
|
232
|
+
if (!hadKey && cfg.embedding.apiKey) {
|
|
233
|
+
appendDebugLog(path.resolve(directory, ".opencode", "opencode-rag.log"), {
|
|
234
|
+
scope: "config",
|
|
235
|
+
message: `Resolved embedding API key from ${process.env.OPENAI_API_KEY ? "OPENAI_API_KEY env var" : "OpenCode provider config"}`,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
configCache.set(directory, { cfg, configPath, mtimeMs });
|
|
214
239
|
return cfg;
|
|
215
240
|
}
|
|
216
241
|
catch (err) {
|
|
@@ -221,8 +246,109 @@ async function getConfig(directory) {
|
|
|
221
246
|
});
|
|
222
247
|
}
|
|
223
248
|
}
|
|
224
|
-
|
|
225
|
-
|
|
249
|
+
// Deep-clone so a later resolveApiKey() cannot mutate the shared
|
|
250
|
+
// DEFAULT_CONFIG singleton.
|
|
251
|
+
const cfg = structuredClone(DEFAULT_CONFIG);
|
|
252
|
+
configCache.set(directory, { cfg, configPath, mtimeMs });
|
|
253
|
+
return cfg;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Re-read a workspace's config file when it changed on disk.
|
|
257
|
+
*
|
|
258
|
+
* Only a config that this module loaded from a file is refreshed — the cache
|
|
259
|
+
* entry is the proof that the file is the source of truth for that workspace.
|
|
260
|
+
* A caller that supplies its own configuration (tests, embedders) keeps it.
|
|
261
|
+
*
|
|
262
|
+
* Synchronous on purpose: this runs on the hot path (every effective-config
|
|
263
|
+
* lookup) and `loadConfig` is synchronous. The pluggable-chunker side effect
|
|
264
|
+
* (`loadChunkersFromConfig`) mutates a global registry and is therefore
|
|
265
|
+
* re-applied asynchronously — it is not needed by the embedding path this
|
|
266
|
+
* refresh exists to fix.
|
|
267
|
+
*
|
|
268
|
+
* @param directory - Workspace directory whose config should be refreshed.
|
|
269
|
+
* @param fallback - Config to use when the workspace has no file-backed config.
|
|
270
|
+
* @returns The configuration currently in effect.
|
|
271
|
+
*/
|
|
272
|
+
export function refreshConfig(directory, fallback) {
|
|
273
|
+
const cached = configCache.get(directory);
|
|
274
|
+
if (!cached) {
|
|
275
|
+
// No file-backed config for this workspace — the caller's config stands.
|
|
276
|
+
return fallback;
|
|
277
|
+
}
|
|
278
|
+
const configPath = findConfigFile(directory);
|
|
279
|
+
const mtimeMs = configFileMtime(configPath);
|
|
280
|
+
if (cached.configPath === configPath && cached.mtimeMs === mtimeMs) {
|
|
281
|
+
return cached.cfg;
|
|
282
|
+
}
|
|
283
|
+
if (!configPath) {
|
|
284
|
+
// The config file was removed — keep serving the last known config.
|
|
285
|
+
return cached.cfg;
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
const cfg = loadConfig(configPath);
|
|
289
|
+
resolveApiKey(cfg, directory);
|
|
290
|
+
void loadChunkersFromConfig(cfg, path.dirname(configPath)).catch(() => { });
|
|
291
|
+
configCache.set(directory, { cfg, configPath, mtimeMs });
|
|
292
|
+
return cfg;
|
|
293
|
+
}
|
|
294
|
+
catch (err) {
|
|
295
|
+
appendDebugLog(path.resolve(directory, ".opencode", "opencode-rag.log"), {
|
|
296
|
+
scope: "config",
|
|
297
|
+
message: `Failed to reload config from ${configPath}`,
|
|
298
|
+
error: err,
|
|
299
|
+
});
|
|
300
|
+
return cached.cfg;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Identity of the embedding-relevant configuration. A change means the
|
|
305
|
+
* embedding provider has to be rebuilt (different key, baseUrl, model, …).
|
|
306
|
+
*/
|
|
307
|
+
function embeddingSignature(cfg) {
|
|
308
|
+
const e = cfg.embedding;
|
|
309
|
+
return [
|
|
310
|
+
e.provider,
|
|
311
|
+
e.baseUrl ?? "",
|
|
312
|
+
e.model,
|
|
313
|
+
e.apiKey ?? "",
|
|
314
|
+
e.timeoutMs ?? "",
|
|
315
|
+
JSON.stringify(e.proxy ?? null),
|
|
316
|
+
].join("\u0000");
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Wrap an embedding provider so it follows the live configuration.
|
|
320
|
+
*
|
|
321
|
+
* The provider is rebuilt whenever the embedding-relevant config changes on
|
|
322
|
+
* disk. Without this, the provider built at plugin setup kept using a stale
|
|
323
|
+
* API key / baseUrl until OpenCode was restarted — which surfaced as a 401
|
|
324
|
+
* that looked like an OpenAI auth error while the CLI worked fine against the
|
|
325
|
+
* very same config file.
|
|
326
|
+
*
|
|
327
|
+
* @param getConfig - Returns the configuration currently in effect.
|
|
328
|
+
* @param create - Factory that builds a provider for a configuration.
|
|
329
|
+
* @param initial - Provider to use until the configuration changes.
|
|
330
|
+
* @returns A provider that tracks the live configuration.
|
|
331
|
+
*/
|
|
332
|
+
export function createLiveEmbedder(getConfig, create, initial) {
|
|
333
|
+
let provider = initial ?? create(getConfig());
|
|
334
|
+
let signature = embeddingSignature(getConfig());
|
|
335
|
+
function current() {
|
|
336
|
+
const cfg = getConfig();
|
|
337
|
+
const sig = embeddingSignature(cfg);
|
|
338
|
+
if (sig !== signature) {
|
|
339
|
+
provider = create(cfg);
|
|
340
|
+
signature = sig;
|
|
341
|
+
}
|
|
342
|
+
return provider;
|
|
343
|
+
}
|
|
344
|
+
return {
|
|
345
|
+
get name() {
|
|
346
|
+
return current().name;
|
|
347
|
+
},
|
|
348
|
+
async embed(texts, purpose) {
|
|
349
|
+
return current().embed(texts, purpose);
|
|
350
|
+
},
|
|
351
|
+
};
|
|
226
352
|
}
|
|
227
353
|
/**
|
|
228
354
|
* Format retrieval results into a Markdown context block for LLM injection.
|
|
@@ -464,7 +590,6 @@ export function createRagHooks(options) {
|
|
|
464
590
|
...defaultDependencies,
|
|
465
591
|
...options.dependencies,
|
|
466
592
|
};
|
|
467
|
-
const embedder = options.embedder ?? dependencies.createEmbedder(options.cfg);
|
|
468
593
|
const configuredDimension = options.cfg.embedding.vectorDimension;
|
|
469
594
|
const store = options.store ?? dependencies.createStore(options.storePath, configuredDimension && configuredDimension > 0 ? configuredDimension : 384, options.cfg);
|
|
470
595
|
const keywordIndex = options.keywordIndex;
|
|
@@ -487,10 +612,20 @@ export function createRagHooks(options) {
|
|
|
487
612
|
if (lastEffectiveCfg && Date.now() - lastEffectiveCfgTime < 1000) {
|
|
488
613
|
return lastEffectiveCfg;
|
|
489
614
|
}
|
|
490
|
-
|
|
615
|
+
// Re-read the config file when it changed on disk, so an edited API key /
|
|
616
|
+
// baseUrl / model takes effect without restarting OpenCode.
|
|
617
|
+
lastEffectiveCfg = applyRuntimeOverrides(refreshConfig(options.worktree, options.cfg), cachedOverrides);
|
|
491
618
|
lastEffectiveCfgTime = Date.now();
|
|
492
619
|
return lastEffectiveCfg;
|
|
493
620
|
}
|
|
621
|
+
// The embedder follows the live configuration: when the config file changes
|
|
622
|
+
// (new API key, baseUrl or model) the provider is rebuilt instead of
|
|
623
|
+
// keeping the one built at plugin setup.
|
|
624
|
+
//
|
|
625
|
+
// Created *after* the override state above on purpose — the facade resolves
|
|
626
|
+
// the effective config eagerly, which would otherwise hit the temporal dead
|
|
627
|
+
// zone of those `let` bindings.
|
|
628
|
+
const embedder = options.embedder ?? createLiveEmbedder(() => getEffectiveCfg(), (cfg) => dependencies.createEmbedder(cfg));
|
|
494
629
|
// Session-level caches for lazy retrieval
|
|
495
630
|
const sessionLastMessage = new Map();
|
|
496
631
|
const sessionRetrievalCache = new Map();
|
|
@@ -1463,6 +1598,10 @@ async function loadKeywordIndex(storePath, logFilePath, logLevel) {
|
|
|
1463
1598
|
* @returns A complete set of OpenCode hooks for RAG functionality.
|
|
1464
1599
|
*/
|
|
1465
1600
|
export const ragPlugin = async (input, _options) => {
|
|
1601
|
+
// Drop the cached config before loading: a plugin reload must pick up a
|
|
1602
|
+
// changed config file, and the fresh cache entry is what enables the live
|
|
1603
|
+
// refresh (refreshConfig only refreshes file-backed configs).
|
|
1604
|
+
configCache.delete(input.directory);
|
|
1466
1605
|
const cfg = await getConfig(input.directory);
|
|
1467
1606
|
const logFilePath = path.resolve(input.directory, resolveLogConfig(cfg).logFilePath);
|
|
1468
1607
|
const logLevel = resolveLogConfig(cfg).level;
|
|
@@ -1537,6 +1676,11 @@ export const ragPlugin = async (input, _options) => {
|
|
|
1537
1676
|
// When the probe fails, prefer the existing store's schema over the 384
|
|
1538
1677
|
// default — a transient outage must not downgrade the store's dimension.
|
|
1539
1678
|
const embedder = createEmbedder(effectiveCfg);
|
|
1679
|
+
// The hooks and the background watcher share one embedder that follows the
|
|
1680
|
+
// live config: when the config file changes (new API key, baseUrl or model)
|
|
1681
|
+
// the provider is rebuilt instead of keeping the one built at startup. The
|
|
1682
|
+
// raw `embedder` above stays the probe target — it is used once.
|
|
1683
|
+
const liveEmbedder = createLiveEmbedder(() => refreshConfig(input.directory, effectiveCfg), (cfg) => createEmbedder(cfg), embedder);
|
|
1540
1684
|
let vectorDimension = effectiveCfg.embedding.vectorDimension;
|
|
1541
1685
|
if (vectorDimension && vectorDimension > 0) {
|
|
1542
1686
|
appendDebugLog(logFilePath, {
|
|
@@ -1592,7 +1736,7 @@ export const ragPlugin = async (input, _options) => {
|
|
|
1592
1736
|
// or keyword index (full rebuilds drop quirk chunks — see reconcileQuirks).
|
|
1593
1737
|
// Fire-and-forget: must never block plugin startup, and the embedder may be
|
|
1594
1738
|
// offline. The background watcher re-runs this at every pass end.
|
|
1595
|
-
void reconcileQuirks({ embedder, store, keywordIndex, cfg: effectiveCfg, storePath })
|
|
1739
|
+
void reconcileQuirks({ embedder: liveEmbedder, store, keywordIndex, cfg: effectiveCfg, storePath })
|
|
1596
1740
|
.then((r) => {
|
|
1597
1741
|
if (r.restoredToStore > 0 || r.addedToKeywordIndex > 0 || r.removedOrphans > 0) {
|
|
1598
1742
|
appendDebugLog(logFilePath, {
|
|
@@ -1619,7 +1763,7 @@ export const ragPlugin = async (input, _options) => {
|
|
|
1619
1763
|
logFilePath,
|
|
1620
1764
|
logLevel,
|
|
1621
1765
|
worktree: input.directory,
|
|
1622
|
-
embedder,
|
|
1766
|
+
embedder: liveEmbedder,
|
|
1623
1767
|
store,
|
|
1624
1768
|
keywordIndex,
|
|
1625
1769
|
descriptionProvider,
|
|
@@ -1632,7 +1776,7 @@ export const ragPlugin = async (input, _options) => {
|
|
|
1632
1776
|
storePath,
|
|
1633
1777
|
config: effectiveCfg,
|
|
1634
1778
|
store,
|
|
1635
|
-
embedder,
|
|
1779
|
+
embedder: liveEmbedder,
|
|
1636
1780
|
logFilePath,
|
|
1637
1781
|
logLevel,
|
|
1638
1782
|
keywordIndex,
|