opencode-rag-plugin 2.10.0 → 2.11.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 +40 -28
- package/dist/api.js +1 -0
- package/dist/cli/commands/clickhouse.d.ts +61 -0
- package/dist/cli/commands/clickhouse.js +335 -0
- package/dist/cli/commands/eval-tuner.js +1 -1
- package/dist/cli/commands/eval.js +1 -1
- package/dist/cli/commands/index-command.js +2 -1
- package/dist/cli/commands/index.d.ts +1 -0
- package/dist/cli/commands/index.js +1 -0
- package/dist/cli/commands/init-helpers.js +2 -2
- package/dist/cli/commands/init.js +49 -11
- package/dist/cli/commands/quirk.js +6 -6
- package/dist/cli/commands/status.js +70 -6
- package/dist/cli/commands/ui.js +2 -2
- package/dist/cli/index.js +2 -1
- package/dist/cli/types.d.ts +14 -0
- package/dist/core/bootstrap.d.ts +7 -0
- package/dist/core/bootstrap.js +40 -9
- package/dist/core/config.d.ts +128 -5
- package/dist/core/config.js +205 -8
- package/dist/core/interfaces.d.ts +54 -0
- package/dist/core/runtime-overrides.d.ts +9 -0
- package/dist/core/runtime-overrides.js +44 -0
- package/dist/core/state-sync.d.ts +91 -0
- package/dist/core/state-sync.js +273 -0
- package/dist/eval/fast-index.js +2 -2
- package/dist/eval/rerank-eval.js +2 -2
- package/dist/eval/run-branch-compare.js +2 -2
- package/dist/eval/run-token-test.js +2 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +2 -1
- package/dist/indexer/pipeline.d.ts +32 -0
- package/dist/indexer/pipeline.js +230 -65
- package/dist/indexer/progress.d.ts +75 -0
- package/dist/indexer/progress.js +114 -0
- package/dist/indexer/stats.d.ts +14 -0
- package/dist/plugin.d.ts +6 -3
- package/dist/plugin.js +39 -20
- package/dist/quirks/quirk-store.d.ts +10 -0
- package/dist/quirks/quirk-store.js +110 -15
- package/dist/quirks/types.d.ts +7 -0
- package/dist/tui.js +134 -113
- package/dist/vectorstore/clickhouse.d.ts +150 -0
- package/dist/vectorstore/clickhouse.js +931 -0
- package/dist/vectorstore/dimension.d.ts +19 -0
- package/dist/vectorstore/dimension.js +36 -0
- package/dist/vectorstore/factory.d.ts +9 -3
- package/dist/vectorstore/factory.js +11 -2
- package/dist/vectorstore/lancedb.d.ts +27 -4
- package/dist/vectorstore/lancedb.js +180 -15
- package/dist/watcher.d.ts +29 -0
- package/dist/watcher.js +76 -2
- package/dist/web/api.d.ts +3 -4
- package/dist/web/api.js +18 -3
- package/dist/web/server.js +28 -2
- package/dist/web/ui/assets/index-B-RH6fko.css +2 -0
- package/dist/web/ui/index.html +2 -2
- package/package.json +2 -1
- package/dist/web/ui/assets/index-CWcp0jNf.css +0 -2
- /package/dist/web/ui/assets/{index-DbXFrn53.js → index-ChGi2bSp.js} +0 -0
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import path from "node:path";
|
|
13
13
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync, copyFileSync } from "node:fs";
|
|
14
|
-
import { loadConfig, findConfigFile, loadWorkspaceConfig, configuredSections } from "../../core/config.js";
|
|
14
|
+
import { loadConfig, findConfigFile, loadWorkspaceConfig, configuredSections, migrateLegacyProjectConfig, projectConfigPath } from "../../core/config.js";
|
|
15
15
|
import { checkProviderHealth, pullOllamaModels } from "../../embedder/health.js";
|
|
16
16
|
import { destroyAllPooledConnections } from "../../embedder/http.js";
|
|
17
17
|
import { c } from "../format.js";
|
|
@@ -41,6 +41,12 @@ export function registerInitCommand(program) {
|
|
|
41
41
|
.option("-f, --force", "overwrite existing files")
|
|
42
42
|
.option("--skip-install", "skip installing workspace-local plugin dependencies")
|
|
43
43
|
.option("--skip-health-check", "skip provider connectivity and model availability check")
|
|
44
|
+
.option("--vector-store <provider>", "vector store backend to write (lancedb | clickhouse)")
|
|
45
|
+
.option("--clickhouse-url <url>", "ClickHouse endpoint (default http://localhost:8123)")
|
|
46
|
+
.option("--clickhouse-database <name>", "ClickHouse database (default OpenCodeRAG)")
|
|
47
|
+
.option("--clickhouse-user <name>", "ClickHouse user (default default)")
|
|
48
|
+
.option("--clickhouse-password-env <name>", "env var holding the ClickHouse password")
|
|
49
|
+
.option("--clickhouse-namespace <name>", "project namespace / table suffix")
|
|
44
50
|
.action((options) => runWorkspaceInit(options));
|
|
45
51
|
}
|
|
46
52
|
/**
|
|
@@ -57,10 +63,13 @@ export async function runWorkspaceInit(options = {}) {
|
|
|
57
63
|
try {
|
|
58
64
|
const cwd = process.cwd();
|
|
59
65
|
const packageMetadata = getPackageMetadata();
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
|
|
66
|
+
// The workspace config now lives in `.opencode/`: move a legacy
|
|
67
|
+
// root-level opencode-rag.json there (only when the canonical file is
|
|
68
|
+
// absent), then respect whatever config exists — `.opencode/rag.json`
|
|
69
|
+
// included — instead of shadowing it with a new file.
|
|
70
|
+
const migratedConfigPath = migrateLegacyProjectConfig(cwd);
|
|
71
|
+
const configPath = findConfigFile(cwd) ?? projectConfigPath(cwd);
|
|
72
|
+
const configLabel = path.relative(cwd, configPath).replace(/\\/g, "/");
|
|
64
73
|
const opencodeDir = path.join(cwd, ".opencode");
|
|
65
74
|
const gitignorePath = path.join(opencodeDir, ".gitignore");
|
|
66
75
|
const opencodeConfigPath = path.join(opencodeDir, "opencode.json");
|
|
@@ -73,6 +82,9 @@ export async function runWorkspaceInit(options = {}) {
|
|
|
73
82
|
const legacyTuiConfigPath = path.join(opencodeDir, "tui.json");
|
|
74
83
|
const opencodePackagePath = path.join(opencodeDir, "package.json");
|
|
75
84
|
console.log(`\n${c.heading("Initializing OpenCodeRAG in workspace...")}\n`);
|
|
85
|
+
if (migratedConfigPath) {
|
|
86
|
+
console.log(` ${c.updated("Moved:")} opencode-rag.json → .opencode/opencode-rag.json\n`);
|
|
87
|
+
}
|
|
76
88
|
if (!existsSync(opencodeDir)) {
|
|
77
89
|
mkdirSync(opencodeDir, { recursive: true });
|
|
78
90
|
console.log(` ${c.created("Created:")} .opencode/`);
|
|
@@ -293,9 +305,11 @@ export async function runWorkspaceInit(options = {}) {
|
|
|
293
305
|
}
|
|
294
306
|
return generateDefaultConfigJson(detectedTuning, existingRaw);
|
|
295
307
|
};
|
|
308
|
+
let configWritten = false;
|
|
296
309
|
if (!configExists) {
|
|
297
310
|
writeFileSync(configPath, await configContent(), "utf-8");
|
|
298
|
-
|
|
311
|
+
configWritten = true;
|
|
312
|
+
console.log(` ${c.created("Created:")} ${configLabel}`);
|
|
299
313
|
}
|
|
300
314
|
else {
|
|
301
315
|
// NEVER overwrite existing config without interactive confirmation
|
|
@@ -304,24 +318,47 @@ export async function runWorkspaceInit(options = {}) {
|
|
|
304
318
|
const readline = await import("node:readline");
|
|
305
319
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
306
320
|
const answer = await new Promise((resolve) => {
|
|
307
|
-
rl.question(` ${c.warn(
|
|
321
|
+
rl.question(` ${c.warn(`${configLabel} already exists.`)} Overwrite with default config? A backup will be saved. (y/N) `, resolve);
|
|
308
322
|
});
|
|
309
323
|
rl.close();
|
|
310
324
|
overwrite = /^y(?:es)?$/i.test(answer.trim());
|
|
311
325
|
}
|
|
312
326
|
if (overwrite) {
|
|
313
327
|
copyFileSync(configPath, `${configPath}.bak`);
|
|
314
|
-
console.log(` ${c.dim("Backup:")}
|
|
328
|
+
console.log(` ${c.dim("Backup:")} ${configLabel}.bak`);
|
|
315
329
|
writeFileSync(configPath, await configContent(), "utf-8");
|
|
316
|
-
|
|
330
|
+
configWritten = true;
|
|
331
|
+
console.log(` ${c.updated("Updated:")} ${configLabel}`);
|
|
317
332
|
}
|
|
318
333
|
else {
|
|
319
|
-
console.log(` ${c.exists("Exists:")}
|
|
334
|
+
console.log(` ${c.exists("Exists:")} ${configLabel} (preserved)`);
|
|
320
335
|
if (!process.stdin.isTTY && options.force) {
|
|
321
|
-
console.log(` ${c.warn("Skipped overwrite:")} non-interactive shell. Edit
|
|
336
|
+
console.log(` ${c.warn("Skipped overwrite:")} non-interactive shell. Edit ${configLabel} manually or re-run in a TTY.`);
|
|
322
337
|
}
|
|
323
338
|
}
|
|
324
339
|
}
|
|
340
|
+
// ── Optional central ClickHouse backend ──
|
|
341
|
+
if (configWritten && options.vectorStore === "clickhouse") {
|
|
342
|
+
const raw = readJsonObject(configPath) ?? {};
|
|
343
|
+
const current = (raw.vectorStore ?? {});
|
|
344
|
+
const currentClickhouse = current.clickhouse && typeof current.clickhouse === "object"
|
|
345
|
+
? current.clickhouse
|
|
346
|
+
: {};
|
|
347
|
+
raw.vectorStore = {
|
|
348
|
+
...current,
|
|
349
|
+
provider: "clickhouse",
|
|
350
|
+
clickhouse: {
|
|
351
|
+
...currentClickhouse,
|
|
352
|
+
url: options.clickhouseUrl ?? "http://localhost:8123",
|
|
353
|
+
database: options.clickhouseDatabase ?? "OpenCodeRAG",
|
|
354
|
+
username: options.clickhouseUser ?? "default",
|
|
355
|
+
passwordEnv: options.clickhousePasswordEnv ?? "OPENCODERAG_CLICKHOUSE_PASSWORD",
|
|
356
|
+
...(options.clickhouseNamespace ? { namespace: options.clickhouseNamespace } : {}),
|
|
357
|
+
},
|
|
358
|
+
};
|
|
359
|
+
writeJsonFile(configPath, raw);
|
|
360
|
+
console.log(` ${c.created("Configured:")} clickhouse backend (${options.clickhouseUrl ?? "http://localhost:8123"})`);
|
|
361
|
+
}
|
|
325
362
|
// ── Provider health check + dependency install (parallel) ──
|
|
326
363
|
const healthPromise = options.skipHealthCheck
|
|
327
364
|
? null
|
|
@@ -447,6 +484,7 @@ export function isLikelyProjectRoot(cwd) {
|
|
|
447
484
|
"Cargo.toml",
|
|
448
485
|
"go.mod",
|
|
449
486
|
"opencode-rag.json",
|
|
487
|
+
".opencode/opencode-rag.json",
|
|
450
488
|
];
|
|
451
489
|
return markers.some((marker) => existsSync(path.join(cwd, marker)));
|
|
452
490
|
}
|
|
@@ -21,7 +21,7 @@ export function registerQuirkCommand(program) {
|
|
|
21
21
|
try {
|
|
22
22
|
const ctx = await resolveCliContext(options, resolveLogPath());
|
|
23
23
|
const { config, embedder, store, keywordIndex } = ctx;
|
|
24
|
-
const quirk = await addQuirk({ embedder, store, keywordIndex: keywordIndex, cfg: config, storePath: ctx.storePath }, {
|
|
24
|
+
const quirk = await addQuirk({ embedder, store, keywordIndex: keywordIndex, cfg: config, storePath: ctx.storePath, flushState: () => ctx.stateSync?.flush(["quirks"]) ?? Promise.resolve() }, {
|
|
25
25
|
content,
|
|
26
26
|
quirkType: options.type,
|
|
27
27
|
tags: options.tag ? (Array.isArray(options.tag) ? options.tag : [options.tag]) : undefined,
|
|
@@ -58,7 +58,7 @@ export function registerQuirkCommand(program) {
|
|
|
58
58
|
const ctx = await resolveCliContext(options, resolveLogPath());
|
|
59
59
|
const { config, embedder, store, keywordIndex } = ctx;
|
|
60
60
|
const tags = options.tag;
|
|
61
|
-
const quirk = await updateQuirk({ embedder, store, keywordIndex: keywordIndex, cfg: config, storePath: ctx.storePath }, id, {
|
|
61
|
+
const quirk = await updateQuirk({ embedder, store, keywordIndex: keywordIndex, cfg: config, storePath: ctx.storePath, flushState: () => ctx.stateSync?.flush(["quirks"]) ?? Promise.resolve() }, id, {
|
|
62
62
|
content: options.content,
|
|
63
63
|
quirkType: options.type,
|
|
64
64
|
tags: tags ? (Array.isArray(tags) ? tags : [tags]) : undefined,
|
|
@@ -85,7 +85,7 @@ export function registerQuirkCommand(program) {
|
|
|
85
85
|
try {
|
|
86
86
|
const ctx = await resolveCliContext(options, resolveLogPath());
|
|
87
87
|
const { config, embedder, store, keywordIndex } = ctx;
|
|
88
|
-
const quirks = await listQuirks({ embedder, store, keywordIndex: keywordIndex, cfg: config, storePath: ctx.storePath });
|
|
88
|
+
const quirks = await listQuirks({ embedder, store, keywordIndex: keywordIndex, cfg: config, storePath: ctx.storePath, flushState: () => ctx.stateSync?.flush(["quirks"]) ?? Promise.resolve() });
|
|
89
89
|
logCliInfo(ctx.logFilePath, "quirk list", `\n${c.num(quirks.length)} quirk(s):\n`);
|
|
90
90
|
for (const q of quirks) {
|
|
91
91
|
const badge = q.quirkType ? `[${q.quirkType}] ` : "";
|
|
@@ -109,7 +109,7 @@ export function registerQuirkCommand(program) {
|
|
|
109
109
|
try {
|
|
110
110
|
const ctx = await resolveCliContext(options, resolveLogPath());
|
|
111
111
|
const { config, embedder, store, keywordIndex } = ctx;
|
|
112
|
-
await removeQuirk({ embedder, store, keywordIndex: keywordIndex, cfg: config, storePath: ctx.storePath }, id);
|
|
112
|
+
await removeQuirk({ embedder, store, keywordIndex: keywordIndex, cfg: config, storePath: ctx.storePath, flushState: () => ctx.stateSync?.flush(["quirks"]) ?? Promise.resolve() }, id);
|
|
113
113
|
logCliInfo(ctx.logFilePath, "quirk rm", `\n${c.success("Quirk removed:")} ${id}`);
|
|
114
114
|
await cleanupContext(ctx);
|
|
115
115
|
}
|
|
@@ -126,7 +126,7 @@ export function registerQuirkCommand(program) {
|
|
|
126
126
|
try {
|
|
127
127
|
const ctx = await resolveCliContext(options, resolveLogPath());
|
|
128
128
|
const { config, embedder, store, keywordIndex } = ctx;
|
|
129
|
-
const issues = await lintQuirks({ embedder, store, keywordIndex: keywordIndex, cfg: config, storePath: ctx.storePath });
|
|
129
|
+
const issues = await lintQuirks({ embedder, store, keywordIndex: keywordIndex, cfg: config, storePath: ctx.storePath, flushState: () => ctx.stateSync?.flush(["quirks"]) ?? Promise.resolve() });
|
|
130
130
|
if (issues.length === 0) {
|
|
131
131
|
logCliInfo(ctx.logFilePath, "quirk lint", c.success("\nNo issues found. All quirks look healthy."));
|
|
132
132
|
}
|
|
@@ -152,7 +152,7 @@ export function registerQuirkCommand(program) {
|
|
|
152
152
|
try {
|
|
153
153
|
const ctx = await resolveCliContext(options, resolveLogPath());
|
|
154
154
|
const { config, embedder, store, keywordIndex } = ctx;
|
|
155
|
-
const results = await recallQuirks({ embedder, store, keywordIndex: keywordIndex, cfg: config, storePath: ctx.storePath }, content, { topK: 5 });
|
|
155
|
+
const results = await recallQuirks({ embedder, store, keywordIndex: keywordIndex, cfg: config, storePath: ctx.storePath, flushState: () => ctx.stateSync?.flush(["quirks"]) ?? Promise.resolve() }, content, { topK: 5 });
|
|
156
156
|
if (results.length > 0) {
|
|
157
157
|
logCliInfo(ctx.logFilePath, "quirk test", c.warn("\n✗ Similar quirk(s) already exist — quirk has NOT been appended:\n"));
|
|
158
158
|
for (const r of results) {
|
|
@@ -10,9 +10,10 @@ import fs from "node:fs";
|
|
|
10
10
|
import { c, resolveCliContext, logCliError, logCliInfo, formatTimestamp, formatRelativeAge } from "../format.js";
|
|
11
11
|
import { getIndexStatusSummary } from "../../indexer.js";
|
|
12
12
|
import { findKeywordIndexGaps } from "../../indexer/keyword-rehydration.js";
|
|
13
|
-
import { deriveWatcherHealth } from "../../watcher.js";
|
|
13
|
+
import { deriveWatcherHealth, discoverWatcherStates } from "../../watcher.js";
|
|
14
14
|
import { getPackageMetadata } from "../helpers.js";
|
|
15
15
|
import { checkForUpdate } from "../../core/version-check.js";
|
|
16
|
+
import { deriveNamespace, sanitizeNamespace } from "../../vectorstore/clickhouse.js";
|
|
16
17
|
/**
|
|
17
18
|
* Check for a stale index.lock file and clean it up if the owning process is dead.
|
|
18
19
|
*
|
|
@@ -63,6 +64,7 @@ export function registerStatusCommand(program) {
|
|
|
63
64
|
.command("status")
|
|
64
65
|
.description("Show indexing status")
|
|
65
66
|
.option("-c, --config <path>", "path to config file")
|
|
67
|
+
.option("--quick", "skip the workspace scan (Up-to-date/Pending files are then unknown, not zero)")
|
|
66
68
|
.action(async (options) => {
|
|
67
69
|
try {
|
|
68
70
|
const cwd = process.cwd();
|
|
@@ -72,9 +74,41 @@ export function registerStatusCommand(program) {
|
|
|
72
74
|
logFilePath = ctx.logFilePath;
|
|
73
75
|
checkStaleLock(storePath, logFilePath);
|
|
74
76
|
const count = await store.count();
|
|
75
|
-
|
|
77
|
+
// Scan by default: a skipped scan used to print "Up-to-date files: 0 /
|
|
78
|
+
// Pending files: 0" — two numbers that were never computed. With
|
|
79
|
+
// --quick the summary's `scanned` flag makes the display say so.
|
|
80
|
+
const summary = await getIndexStatusSummary(cwd, storePath, config, store, options.quick === true);
|
|
76
81
|
logCliInfo(logFilePath, "status", `\n${c.heading("Indexed chunks:")} ${c.num(count)}`);
|
|
77
|
-
|
|
82
|
+
const provider = config.vectorStore.provider ?? "lancedb";
|
|
83
|
+
if (provider === "clickhouse") {
|
|
84
|
+
const ch = config.vectorStore.clickhouse;
|
|
85
|
+
const namespace = ch?.namespace?.trim()
|
|
86
|
+
? sanitizeNamespace(ch.namespace)
|
|
87
|
+
: deriveNamespace(cwd);
|
|
88
|
+
const annMode = ch?.ann === "hnsw" ? "hnsw ANN" : "exact scans";
|
|
89
|
+
logCliInfo(logFilePath, "status", `${c.label("Vector store:")} ${c.value("clickhouse")} ${c.file(`${ch?.url ?? ""}/${ch?.database ?? ""}`)} ` +
|
|
90
|
+
`(namespace ${c.value(namespace)}, ${annMode})`);
|
|
91
|
+
if (ch?.ann === "hnsw") {
|
|
92
|
+
const hasIndex = store.hasVectorIndex;
|
|
93
|
+
if (hasIndex) {
|
|
94
|
+
const present = await hasIndex.call(store).catch(() => false);
|
|
95
|
+
logCliInfo(logFilePath, "status", `${c.label("ANN index:")} ${present ? c.success("present") : c.warn("missing")} (vector_similarity)`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
logCliInfo(logFilePath, "status", `${c.label("Local cache:")} ${c.file(storePath)} (disposable)`);
|
|
99
|
+
try {
|
|
100
|
+
const lease = await store.getLease?.("index");
|
|
101
|
+
if (lease) {
|
|
102
|
+
logCliInfo(logFilePath, "status", `${c.label("Index lease:")} ${c.value(lease.owner)} (expires ${formatTimestamp(lease.expiresAt)})`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// lease diagnostics are best effort
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
logCliInfo(logFilePath, "status", `${c.label("Store path:")} ${c.file(storePath)}`);
|
|
111
|
+
}
|
|
78
112
|
logCliInfo(logFilePath, "status", `${c.label("Embedding provider:")} ${c.value(config.embedding.provider)}`);
|
|
79
113
|
logCliInfo(logFilePath, "status", `${c.label("Embedding model:")} ${c.value(config.embedding.model)}`);
|
|
80
114
|
const storeDimension = await store.getVectorDimension?.();
|
|
@@ -98,15 +132,30 @@ export function registerStatusCommand(program) {
|
|
|
98
132
|
logCliInfo(logFilePath, "status", `${c.label("Manifest status:")} ${summary.manifestStatus}`);
|
|
99
133
|
logCliInfo(logFilePath, "status", `${c.label("Manifest entries:")} ${c.num(summary.manifestEntries)}`);
|
|
100
134
|
logCliInfo(logFilePath, "status", `${c.label("Last indexed:")} ${c.value(formatTimestamp(summary.lastIndexedAt))}`);
|
|
101
|
-
|
|
102
|
-
|
|
135
|
+
if (summary.scanned) {
|
|
136
|
+
logCliInfo(logFilePath, "status", `${c.label("Up-to-date files:")} ${c.num(summary.upToDateFiles)}`);
|
|
137
|
+
logCliInfo(logFilePath, "status", `${c.label("Pending files:")} ${c.num(summary.pendingFiles)}`);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
logCliInfo(logFilePath, "status", `${c.label("Up-to-date files:")} ${c.dim("n/a (not scanned)")}`);
|
|
141
|
+
logCliInfo(logFilePath, "status", `${c.label("Pending files:")} ${c.dim("n/a (not scanned — rerun without --quick)")}`);
|
|
142
|
+
}
|
|
103
143
|
logCliInfo(logFilePath, "status", `${c.label("Indexed chunks:")} ${c.num(summary.storeChunkCount)}`);
|
|
104
144
|
logCliInfo(logFilePath, "status", `${c.label("Expected chunks:")} ${c.num(summary.manifestExpectedChunks)}`);
|
|
105
145
|
logCliInfo(logFilePath, "status", `${c.label("Orphan chunks:")} ${c.num(summary.orphanChunks)}`);
|
|
146
|
+
if (summary.quirkChunks !== undefined) {
|
|
147
|
+
// Quirk rows are owned by quirks.jsonl — count them so
|
|
148
|
+
// Indexed = Expected + Orphan + Quirk reconciles and the reader can
|
|
149
|
+
// tell a sweepable orphan from a legitimately owned row.
|
|
150
|
+
logCliInfo(logFilePath, "status", `${c.label("Quirk chunks:")} ${c.num(summary.quirkChunks)} ${c.dim("(owned by quirks.jsonl)")}`);
|
|
151
|
+
}
|
|
106
152
|
if (summary.orphanChunks > 0) {
|
|
107
153
|
logCliInfo(logFilePath, "status", `${c.label("Unaccounted rows:")} ${c.warn("yes")} — stored chunks no manifest entry owns (files whose embedding never completed). Run 'opencode-rag index' to sweep them.`);
|
|
108
154
|
}
|
|
109
|
-
// Read watcher status from the background auto-indexer
|
|
155
|
+
// Read watcher status from the background auto-indexer. The watcher
|
|
156
|
+
// writes into ITS OWN store dir, so also discover watchers running in
|
|
157
|
+
// other store dirs (a plugin whose store was changed under it after
|
|
158
|
+
// load keeps watching elsewhere — this is where that shows up).
|
|
110
159
|
const watcherStatusPath = path.join(storePath, "watcher-status.json");
|
|
111
160
|
let watchModeDisplay;
|
|
112
161
|
let watcherWarning;
|
|
@@ -139,6 +188,21 @@ export function registerStatusCommand(program) {
|
|
|
139
188
|
if (watcherWarning) {
|
|
140
189
|
logCliInfo(logFilePath, "status", `${c.label("Watcher health:")} ${c.warn(`stale — ${watcherWarning}`)} ${c.dim("(run 'opencode-rag index' or check .opencode/opencode-rag.log)")}`);
|
|
141
190
|
}
|
|
191
|
+
try {
|
|
192
|
+
const others = discoverWatcherStates(storePath, cwd).filter((w) => path.resolve(w.storePath) !== path.resolve(storePath));
|
|
193
|
+
for (const w of others) {
|
|
194
|
+
if (w.alive && w.lock) {
|
|
195
|
+
logCliInfo(logFilePath, "status", `${c.label("Watcher elsewhere:")} ${c.warn("active")} pid ${w.lock.pid} in ${c.file(w.storePath)} ${c.dim("(the running OpenCode plugin indexes THAT store — restart OpenCode after a vectorStore/embedding config change)")}`);
|
|
196
|
+
}
|
|
197
|
+
else if (w.status?.lastRunAt || w.status?.lastSuccessAt) {
|
|
198
|
+
const last = w.status.lastSuccessAt ?? w.status.lastRunAt;
|
|
199
|
+
logCliInfo(logFilePath, "status", `${c.label("Watcher (old):")} ${c.dim(`stopped — last run ${formatRelativeAge(last)} in ${w.storePath}`)}`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
// watcher discovery is best effort
|
|
205
|
+
}
|
|
142
206
|
const kiCount = config.retrieval.hybridSearch?.enabled
|
|
143
207
|
? keywordIndex?.count() ?? 0
|
|
144
208
|
: 0;
|
package/dist/cli/commands/ui.js
CHANGED
|
@@ -32,10 +32,10 @@ export function registerUiCommand(program) {
|
|
|
32
32
|
const port = parseInt(options.port ?? String(config.ui?.port ?? 3210), 10);
|
|
33
33
|
const openBrowser = options.open !== false && (config.ui?.openBrowser ?? true);
|
|
34
34
|
const { startWebUi } = await import("../../web/server.js");
|
|
35
|
-
const { findConfigFile } = await import("../../core/config.js");
|
|
35
|
+
const { findConfigFile, projectConfigPath } = await import("../../core/config.js");
|
|
36
36
|
const configPath = options.config
|
|
37
37
|
? path.resolve(cwd, options.config)
|
|
38
|
-
: findConfigFile(cwd);
|
|
38
|
+
: findConfigFile(cwd) ?? projectConfigPath(cwd);
|
|
39
39
|
const server = await startWebUi(storePath, port, cwd, config.embedding.vectorDimension ?? 384, config, configPath);
|
|
40
40
|
const url = `http://127.0.0.1:${server.port}/?token=${server.token}`;
|
|
41
41
|
logCliInfo(logFilePath, "ui", `\n${c.heading("OpenCodeRAG Web UI")}`);
|
package/dist/cli/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { realpathSync } from "node:fs";
|
|
|
15
15
|
import { basename, dirname } from "node:path";
|
|
16
16
|
import { fileURLToPath } from "node:url";
|
|
17
17
|
import { getPackageMetadata } from "./helpers.js";
|
|
18
|
-
import { registerIndexCommand, registerQueryCommand, registerClearCommand, registerStatusCommand, registerListCommand, registerShowCommand, registerDumpCommand, registerInitCommand, registerUiCommand, registerMcpCommand, registerSetupCommand, registerUpdateCommand, registerEvalSessionsCommand, registerEvalAnalyzeCommand, registerEvalCompareCommand, registerEvalGateCommand, registerEvalDecideCommand, registerEvalTuneCommand, registerDescribeImageCommand, registerDecideCommand, registerQuirkCommand, } from "./commands/index.js";
|
|
18
|
+
import { registerIndexCommand, registerQueryCommand, registerClearCommand, registerStatusCommand, registerListCommand, registerShowCommand, registerDumpCommand, registerInitCommand, registerClickHouseCommand, registerUiCommand, registerMcpCommand, registerSetupCommand, registerUpdateCommand, registerEvalSessionsCommand, registerEvalAnalyzeCommand, registerEvalCompareCommand, registerEvalGateCommand, registerEvalDecideCommand, registerEvalTuneCommand, registerDescribeImageCommand, registerDecideCommand, registerQuirkCommand, } from "./commands/index.js";
|
|
19
19
|
/**
|
|
20
20
|
* The top-level Commander program instance that defines the `opencode-rag` CLI.
|
|
21
21
|
*
|
|
@@ -58,6 +58,7 @@ registerEvalGateCommand(program);
|
|
|
58
58
|
registerEvalDecideCommand(program);
|
|
59
59
|
registerEvalTuneCommand(program);
|
|
60
60
|
registerInitCommand(program);
|
|
61
|
+
registerClickHouseCommand(program);
|
|
61
62
|
registerQuirkCommand(program);
|
|
62
63
|
// ── Auto-run detection ──────────────────────────────────────────
|
|
63
64
|
/**
|
package/dist/cli/types.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export interface CliOptions {
|
|
|
22
22
|
yes?: boolean;
|
|
23
23
|
/** Print a machine-readable JSON summary as the last line of the `index` command. */
|
|
24
24
|
json?: boolean;
|
|
25
|
+
/** Skip the workspace scan in `status` (Up-to-date/Pending files then report unknown, not zero). */
|
|
26
|
+
quick?: boolean;
|
|
25
27
|
/** Optional system prompt to steer an image description toward specific features. */
|
|
26
28
|
systemPrompt?: string;
|
|
27
29
|
}
|
|
@@ -33,6 +35,18 @@ export interface InitOptions {
|
|
|
33
35
|
skipInstall?: boolean;
|
|
34
36
|
/** Skip provider connectivity and model availability check. */
|
|
35
37
|
skipHealthCheck?: boolean;
|
|
38
|
+
/** Vector-store backend to write into the config (`lancedb` or `clickhouse`). */
|
|
39
|
+
vectorStore?: string;
|
|
40
|
+
/** ClickHouse endpoint for `--vector-store clickhouse`. */
|
|
41
|
+
clickhouseUrl?: string;
|
|
42
|
+
/** ClickHouse database for `--vector-store clickhouse`. */
|
|
43
|
+
clickhouseDatabase?: string;
|
|
44
|
+
/** ClickHouse user for `--vector-store clickhouse`. */
|
|
45
|
+
clickhouseUser?: string;
|
|
46
|
+
/** ClickHouse password env var name for `--vector-store clickhouse`. */
|
|
47
|
+
clickhousePasswordEnv?: string;
|
|
48
|
+
/** ClickHouse project namespace (table suffix) for `--vector-store clickhouse`. */
|
|
49
|
+
clickhouseNamespace?: string;
|
|
36
50
|
}
|
|
37
51
|
/** Shape of the `package.json` metadata required by CLI helpers. */
|
|
38
52
|
export interface PackageMetadata {
|
package/dist/core/bootstrap.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* creates embedder, vector store, keyword index, and description provider.
|
|
4
4
|
*/
|
|
5
5
|
import { type RagConfig } from "./config.js";
|
|
6
|
+
import { StateSync } from "./state-sync.js";
|
|
6
7
|
import type { EmbeddingProvider, RerankProvider, VectorStore, KeywordIndex as IKeywordIndex, DescriptionProvider } from "./interfaces.js";
|
|
7
8
|
/** Options for bootstrapping the RAG pipeline context. */
|
|
8
9
|
export interface BootstrapOptions {
|
|
@@ -39,6 +40,12 @@ export interface RagContext {
|
|
|
39
40
|
logFilePath: string;
|
|
40
41
|
/** Resolved path to the config file, or undefined when built-in defaults are used. */
|
|
41
42
|
configPath?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Durable-state synchronizer. For ClickHouse this hydrates the local cache
|
|
45
|
+
* from `state_<namespace>` and flushes changes back; for LanceDB it is a
|
|
46
|
+
* no-op, so the local directory stays the source of truth.
|
|
47
|
+
*/
|
|
48
|
+
stateSync?: StateSync;
|
|
42
49
|
}
|
|
43
50
|
/** Bootstrap the full RAG pipeline context: load config, resolve API keys, create embedder, vector store, keyword index, and description provider. */
|
|
44
51
|
export declare function resolveRagContext(opts?: BootstrapOptions): Promise<RagContext>;
|
package/dist/core/bootstrap.js
CHANGED
|
@@ -10,7 +10,9 @@ import { createEmbedder, probeEmbeddingDimension } from "../embedder/factory.js"
|
|
|
10
10
|
import { createDescriptionProvider } from "../describer/factory.js";
|
|
11
11
|
import { createVectorStore } from "../vectorstore/factory.js";
|
|
12
12
|
import { getRerankerFor } from "../reranker/factory.js";
|
|
13
|
-
import {
|
|
13
|
+
import { readConfiguredStoreDimension } from "../vectorstore/dimension.js";
|
|
14
|
+
import { loadRuntimeOverrides, applyRuntimeOverrides } from "./runtime-overrides.js";
|
|
15
|
+
import { StateSync } from "./state-sync.js";
|
|
14
16
|
import { KeywordIndex } from "../retriever/keyword-index.js";
|
|
15
17
|
import { reconcileQuirks } from "../quirks/quirk-store.js";
|
|
16
18
|
/**
|
|
@@ -28,7 +30,7 @@ import { reconcileQuirks } from "../quirks/quirk-store.js";
|
|
|
28
30
|
* @param skipProbe - When true, never call the provider (read-only commands).
|
|
29
31
|
* @returns The resolved dimension.
|
|
30
32
|
*/
|
|
31
|
-
async function resolveDimension(embedder, storePath, skipProbe, configured) {
|
|
33
|
+
async function resolveDimension(embedder, storePath, skipProbe, configured, config, workspaceDir) {
|
|
32
34
|
if (configured && configured > 0) {
|
|
33
35
|
return configured;
|
|
34
36
|
}
|
|
@@ -37,7 +39,7 @@ async function resolveDimension(embedder, storePath, skipProbe, configured) {
|
|
|
37
39
|
if (probe.dimension !== undefined) {
|
|
38
40
|
return probe.dimension;
|
|
39
41
|
}
|
|
40
|
-
const storeDimension = await
|
|
42
|
+
const storeDimension = await readConfiguredStoreDimension(config, storePath, workspaceDir);
|
|
41
43
|
if (storeDimension !== undefined) {
|
|
42
44
|
console.warn(`[bootstrap] Could not probe embedding dimension (${probe.error?.message ?? "unknown error"}) — ` +
|
|
43
45
|
`using the existing store's dimension ${storeDimension}.`);
|
|
@@ -47,7 +49,7 @@ async function resolveDimension(embedder, storePath, skipProbe, configured) {
|
|
|
47
49
|
"falling back to 384. Set embedding.vectorDimension explicitly if the provider produces a different size.");
|
|
48
50
|
return 384;
|
|
49
51
|
}
|
|
50
|
-
return (await
|
|
52
|
+
return (await readConfiguredStoreDimension(config, storePath, workspaceDir)) ?? 384;
|
|
51
53
|
}
|
|
52
54
|
/** Load the keyword index from disk, or create a new empty one if loading fails. */
|
|
53
55
|
async function loadKeywordIndex(storePath) {
|
|
@@ -85,18 +87,46 @@ export async function resolveRagContext(opts = {}) {
|
|
|
85
87
|
await loadChunkersFromConfig(cfg, baseDir);
|
|
86
88
|
}
|
|
87
89
|
const logFilePath = path.resolve(workDir, resolveLogConfig(cfg).logFilePath);
|
|
88
|
-
|
|
90
|
+
// Apply runtime overrides (the store's runtime-overrides.json) BEFORE
|
|
91
|
+
// building the embedder/store, exactly like the plugin does at startup.
|
|
92
|
+
// Without this the CLI's effective config diverges from the plugin's:
|
|
93
|
+
// `status` printed "off" while a live watcher ran, and `query` searched
|
|
94
|
+
// with different retrieval settings than the agent's tools. vectorStore
|
|
95
|
+
// has no override keys, so storePath is safe to resolve first.
|
|
89
96
|
const storePath = path.resolve(workDir, cfg.vectorStore.path);
|
|
90
|
-
|
|
97
|
+
try {
|
|
98
|
+
const overrides = loadRuntimeOverrides(storePath);
|
|
99
|
+
if (Object.keys(overrides).length > 0) {
|
|
100
|
+
cfg = applyRuntimeOverrides(cfg, overrides);
|
|
101
|
+
// Overrides can change embedding.baseUrl/provider — re-run the key
|
|
102
|
+
// resolution in the same order the plugin uses (apply → resolve).
|
|
103
|
+
resolveApiKey(cfg, workDir);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// Overrides are best-effort; a corrupt file must not break the CLI.
|
|
108
|
+
}
|
|
109
|
+
const embedder = createEmbedder(cfg);
|
|
110
|
+
const dimension = await resolveDimension(embedder, storePath, opts.skipProbe ?? false, cfg.embedding.vectorDimension, cfg, workDir);
|
|
91
111
|
// Warn (but do not block) when the existing store schema disagrees with the
|
|
92
112
|
// resolved dimension: the next index pass rebuilds automatically, and search
|
|
93
|
-
// callers would otherwise see only cryptic
|
|
94
|
-
const storeDimension = await
|
|
113
|
+
// callers would otherwise see only cryptic backend errors.
|
|
114
|
+
const storeDimension = await readConfiguredStoreDimension(cfg, storePath, workDir);
|
|
95
115
|
if (storeDimension !== undefined && storeDimension !== dimension) {
|
|
96
116
|
console.warn(`[bootstrap] Store was built with vector dimension ${storeDimension} but the current embedder produces ${dimension} — ` +
|
|
97
117
|
"run 'opencode-rag index' to rebuild the index with the current model.");
|
|
98
118
|
}
|
|
99
|
-
const store = createVectorStore(cfg, storePath, dimension);
|
|
119
|
+
const store = createVectorStore(cfg, storePath, dimension, workDir);
|
|
120
|
+
// Durable-state sync: no-op for LanceDB (the local directory is the source
|
|
121
|
+
// of truth); for ClickHouse the local directory is a disposable cache that
|
|
122
|
+
// is hydrated from `state_<namespace>` before anything reads it.
|
|
123
|
+
const stateSync = new StateSync({ store, storePath, config: cfg });
|
|
124
|
+
try {
|
|
125
|
+
await stateSync.hydrate();
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
console.warn(`[bootstrap] State hydration failed: ${err.message}`);
|
|
129
|
+
}
|
|
100
130
|
const keywordIndex = opts.skipKeywordIndex
|
|
101
131
|
? new KeywordIndex(storePath)
|
|
102
132
|
: await loadKeywordIndex(storePath);
|
|
@@ -138,6 +168,7 @@ export async function resolveRagContext(opts = {}) {
|
|
|
138
168
|
dimension,
|
|
139
169
|
logFilePath,
|
|
140
170
|
configPath,
|
|
171
|
+
stateSync,
|
|
141
172
|
};
|
|
142
173
|
}
|
|
143
174
|
//# sourceMappingURL=bootstrap.js.map
|