opencode-rag-plugin 2.4.4 → 2.5.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/dist/chunker/factory.d.ts +6 -0
- package/dist/chunker/factory.js +14 -0
- package/dist/chunker/skeleton.js +7 -1
- package/dist/cli/commands/init-helpers.d.ts +39 -3
- package/dist/cli/commands/init-helpers.js +53 -6
- package/dist/cli/commands/init.js +59 -25
- package/dist/cli/commands/setup.js +2 -0
- package/dist/cli/commands/ui.js +1 -1
- package/dist/core/package-manager.js +1 -1
- package/dist/core/runtime-overrides.d.ts +10 -0
- package/dist/core/runtime-overrides.js +14 -0
- package/dist/core/setup-runtime.js +1 -0
- package/dist/core/version-check.js +4 -1
- package/dist/eval/fast-index.js +7 -1
- package/dist/eval/run-branch-compare.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/indexer/git-diff.js +14 -6
- package/dist/indexer/metadata.d.ts +6 -1
- package/dist/indexer/metadata.js +8 -2
- package/dist/indexer/worker.js +3 -1
- package/dist/opencode/create-read-tool.d.ts +7 -0
- package/dist/opencode/create-read-tool.js +4 -1
- package/dist/opencode/tools.d.ts +6 -0
- package/dist/opencode/tools.js +2 -1
- package/dist/plugin.js +11 -1
- package/dist/tui.d.ts +16 -0
- package/dist/tui.js +38 -9
- package/dist/web/api.d.ts +11 -0
- package/dist/web/api.js +50 -2
- package/package.json +16 -2
|
@@ -62,6 +62,12 @@ export declare function getRegisteredLanguages(): string[];
|
|
|
62
62
|
* extension recipe when an override retargets an extension.
|
|
63
63
|
*/
|
|
64
64
|
export declare function getExtensionsForLanguage(language: string): string[];
|
|
65
|
+
/**
|
|
66
|
+
* The parser language registered for a file extension, or `undefined` when
|
|
67
|
+
* the extension has no registered parser. Used to detect a `chunking.parsers`
|
|
68
|
+
* override that does not actually change the parser.
|
|
69
|
+
*/
|
|
70
|
+
export declare function getLanguageForExtension(ext: string): string | undefined;
|
|
65
71
|
/**
|
|
66
72
|
* Validate a raw `chunking.parsers` map against the registered parsers.
|
|
67
73
|
*
|
package/dist/chunker/factory.js
CHANGED
|
@@ -167,6 +167,20 @@ export function getExtensionsForLanguage(language) {
|
|
|
167
167
|
}
|
|
168
168
|
return out;
|
|
169
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* The parser language registered for a file extension, or `undefined` when
|
|
172
|
+
* the extension has no registered parser. Used to detect a `chunking.parsers`
|
|
173
|
+
* override that does not actually change the parser.
|
|
174
|
+
*/
|
|
175
|
+
export function getLanguageForExtension(ext) {
|
|
176
|
+
const key = ext.toLowerCase();
|
|
177
|
+
const direct = extensionMap.get(key);
|
|
178
|
+
if (direct)
|
|
179
|
+
return direct.language;
|
|
180
|
+
// Basename-registered parsers (e.g. "dockerfile") are stored without a dot.
|
|
181
|
+
const base = key.startsWith(".") ? key.slice(1) : key;
|
|
182
|
+
return extensionMap.get(base)?.language;
|
|
183
|
+
}
|
|
170
184
|
/**
|
|
171
185
|
* Validate a raw `chunking.parsers` map against the registered parsers.
|
|
172
186
|
*
|
package/dist/chunker/skeleton.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { Parser } from "web-tree-sitter";
|
|
11
11
|
import { initParser, loadLanguage, walkTree } from "./grammar.js";
|
|
12
|
-
import { getExtensionsForLanguage, getRegisteredLanguages } from "./factory.js";
|
|
12
|
+
import { getExtensionsForLanguage, getLanguageForExtension, getRegisteredLanguages } from "./factory.js";
|
|
13
13
|
import { normalizeParserOverrides, } from "../core/parser-overrides.js";
|
|
14
14
|
/** Extension → tree-sitter grammar + node types for skeleton extraction. */
|
|
15
15
|
export const SKELETON_CONFIGS = {
|
|
@@ -86,6 +86,12 @@ function resolveSkeletonKey(ext, overrides) {
|
|
|
86
86
|
}
|
|
87
87
|
return ext;
|
|
88
88
|
}
|
|
89
|
+
// An override that names the extension's existing parser changes nothing
|
|
90
|
+
// for chunking — so keep the extension's own recipe, which can be more
|
|
91
|
+
// specific than the target language's first recipe (".tsx" also collects
|
|
92
|
+
// arrow functions, ".ts" does not).
|
|
93
|
+
if (getLanguageForExtension(ext) === target)
|
|
94
|
+
return ext;
|
|
89
95
|
const candidates = getExtensionsForLanguage(target);
|
|
90
96
|
const hit = candidates.find((c) => SKELETON_CONFIGS[c] || REGEX_SKELETON[c]);
|
|
91
97
|
// Known parser but no skeleton recipe for it (e.g. plain text, PDF): the
|
|
@@ -43,7 +43,27 @@ export declare function buildOpencodeConfig(existing: Record<string, unknown> |
|
|
|
43
43
|
*/
|
|
44
44
|
export declare function removeStaleGlobalPluginRegistrations(homeDir: string, pluginName: string): string[];
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
46
|
+
* Workspace plugin directory (`.opencode/plugins/opencode-rag/`).
|
|
47
|
+
*
|
|
48
|
+
* OpenCode 2 loads plugin *directories* under `.opencode/plugins/`: the
|
|
49
|
+
* `index.*` file is the server (business) entrypoint and `tui.*` beside it is
|
|
50
|
+
* the CLI entrypoint — the TUI only discovers directory targets, so a flat
|
|
51
|
+
* `rag-tui.js` is never registered with the terminal UI.
|
|
52
|
+
*/
|
|
53
|
+
export declare const WORKSPACE_PLUGIN_DIR = "opencode-rag";
|
|
54
|
+
/** Relative path (from the workspace root) of the generated server entrypoint. */
|
|
55
|
+
export declare const WORKSPACE_PLUGIN_ENTRY = ".opencode/plugins/opencode-rag/index.js";
|
|
56
|
+
/** Relative path (from the workspace root) of the generated TUI entrypoint. */
|
|
57
|
+
export declare const WORKSPACE_TUI_ENTRY = ".opencode/plugins/opencode-rag/tui.js";
|
|
58
|
+
/** V1-era flat plugin files, superseded by {@link WORKSPACE_PLUGIN_DIR}. */
|
|
59
|
+
export declare const LEGACY_PLUGIN_ENTRY = ".opencode/plugins/rag-plugin.js";
|
|
60
|
+
/** V1-era flat TUI plugin file, superseded by {@link WORKSPACE_TUI_ENTRY}. */
|
|
61
|
+
export declare const LEGACY_TUI_ENTRY = ".opencode/plugins/rag-tui.js";
|
|
62
|
+
/** V1-era TUI config file (OpenCode 2 reads CLI plugins from discovery, not this). */
|
|
63
|
+
export declare const LEGACY_TUI_CONFIG = ".opencode/tui.json";
|
|
64
|
+
/**
|
|
65
|
+
* Generate the content for the server entrypoint
|
|
66
|
+
* (`.opencode/plugins/opencode-rag/index.js`).
|
|
47
67
|
*
|
|
48
68
|
* This file re-exports the plugin from the workspace-local node_modules.
|
|
49
69
|
* The plugin entry default-exports the OpenCode V2 module shape
|
|
@@ -54,14 +74,30 @@ export declare function removeStaleGlobalPluginRegistrations(homeDir: string, pl
|
|
|
54
74
|
*/
|
|
55
75
|
export declare function generateWorkspacePluginFile(packageName: string): string;
|
|
56
76
|
/**
|
|
57
|
-
* Generate the content for
|
|
77
|
+
* Generate the content for the TUI entrypoint
|
|
78
|
+
* (`.opencode/plugins/opencode-rag/tui.js`).
|
|
58
79
|
*
|
|
59
|
-
*
|
|
80
|
+
* OpenCode resolves this file beside the server entrypoint in the same plugin
|
|
81
|
+
* directory; the TUI role loads it, the server role never touches it.
|
|
60
82
|
*
|
|
61
83
|
* @param packageName - The npm package name of the RAG plugin.
|
|
62
84
|
* @returns The JavaScript source code for the TUI plugin entry file.
|
|
63
85
|
*/
|
|
64
86
|
export declare function generateWorkspaceTuiPluginFile(packageName: string): string;
|
|
87
|
+
/**
|
|
88
|
+
* Content of the V1-era flat server entrypoint (`.opencode/plugins/rag-plugin.js`).
|
|
89
|
+
*
|
|
90
|
+
* Used to recognize — and safely migrate away from — files this command wrote
|
|
91
|
+
* before OpenCode 2 directory discovery. Recognized by exact content match, so
|
|
92
|
+
* hand-written files are never deleted.
|
|
93
|
+
*/
|
|
94
|
+
export declare function generateLegacyWorkspacePluginFile(packageName: string): string;
|
|
95
|
+
/** Content of the V1-era flat TUI entrypoint (`.opencode/plugins/rag-tui.js`). */
|
|
96
|
+
export declare function generateLegacyWorkspaceTuiPluginFile(packageName: string): string;
|
|
97
|
+
/** Content of the V1-era `.opencode/tui.json`. */
|
|
98
|
+
export declare function buildLegacyTuiConfig(): {
|
|
99
|
+
plugin: string[];
|
|
100
|
+
};
|
|
65
101
|
/**
|
|
66
102
|
* Generate the content for `.opencode/skills/opencode-rag/SKILL.md`.
|
|
67
103
|
*
|
|
@@ -63,7 +63,7 @@ export function buildOpencodeConfig(existing) {
|
|
|
63
63
|
if (typeof next.$schema !== "string") {
|
|
64
64
|
next.$schema = "https://opencode.ai/config.json";
|
|
65
65
|
}
|
|
66
|
-
// Plugin is loaded via
|
|
66
|
+
// Plugin is loaded via `.opencode/plugins/opencode-rag/` auto-discovery,
|
|
67
67
|
// not via npm package resolution. Stale "plugin" entries from older
|
|
68
68
|
// init versions would trigger npm install (which fails due to native
|
|
69
69
|
// dependencies like sharp) and produce "Plugin export is not a function".
|
|
@@ -134,7 +134,27 @@ export function removeStaleGlobalPluginRegistrations(homeDir, pluginName) {
|
|
|
134
134
|
return updatedPaths;
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
|
-
*
|
|
137
|
+
* Workspace plugin directory (`.opencode/plugins/opencode-rag/`).
|
|
138
|
+
*
|
|
139
|
+
* OpenCode 2 loads plugin *directories* under `.opencode/plugins/`: the
|
|
140
|
+
* `index.*` file is the server (business) entrypoint and `tui.*` beside it is
|
|
141
|
+
* the CLI entrypoint — the TUI only discovers directory targets, so a flat
|
|
142
|
+
* `rag-tui.js` is never registered with the terminal UI.
|
|
143
|
+
*/
|
|
144
|
+
export const WORKSPACE_PLUGIN_DIR = "opencode-rag";
|
|
145
|
+
/** Relative path (from the workspace root) of the generated server entrypoint. */
|
|
146
|
+
export const WORKSPACE_PLUGIN_ENTRY = `.opencode/plugins/${WORKSPACE_PLUGIN_DIR}/index.js`;
|
|
147
|
+
/** Relative path (from the workspace root) of the generated TUI entrypoint. */
|
|
148
|
+
export const WORKSPACE_TUI_ENTRY = `.opencode/plugins/${WORKSPACE_PLUGIN_DIR}/tui.js`;
|
|
149
|
+
/** V1-era flat plugin files, superseded by {@link WORKSPACE_PLUGIN_DIR}. */
|
|
150
|
+
export const LEGACY_PLUGIN_ENTRY = ".opencode/plugins/rag-plugin.js";
|
|
151
|
+
/** V1-era flat TUI plugin file, superseded by {@link WORKSPACE_TUI_ENTRY}. */
|
|
152
|
+
export const LEGACY_TUI_ENTRY = ".opencode/plugins/rag-tui.js";
|
|
153
|
+
/** V1-era TUI config file (OpenCode 2 reads CLI plugins from discovery, not this). */
|
|
154
|
+
export const LEGACY_TUI_CONFIG = ".opencode/tui.json";
|
|
155
|
+
/**
|
|
156
|
+
* Generate the content for the server entrypoint
|
|
157
|
+
* (`.opencode/plugins/opencode-rag/index.js`).
|
|
138
158
|
*
|
|
139
159
|
* This file re-exports the plugin from the workspace-local node_modules.
|
|
140
160
|
* The plugin entry default-exports the OpenCode V2 module shape
|
|
@@ -145,26 +165,46 @@ export function removeStaleGlobalPluginRegistrations(homeDir, pluginName) {
|
|
|
145
165
|
*/
|
|
146
166
|
export function generateWorkspacePluginFile(packageName) {
|
|
147
167
|
return [
|
|
148
|
-
`import plugin from "
|
|
168
|
+
`import plugin from "../../node_modules/${packageName}/dist/plugin-entry.js";`,
|
|
149
169
|
`export default plugin;`,
|
|
150
170
|
"",
|
|
151
171
|
].join("\n");
|
|
152
172
|
}
|
|
153
173
|
/**
|
|
154
|
-
* Generate the content for
|
|
174
|
+
* Generate the content for the TUI entrypoint
|
|
175
|
+
* (`.opencode/plugins/opencode-rag/tui.js`).
|
|
155
176
|
*
|
|
156
|
-
*
|
|
177
|
+
* OpenCode resolves this file beside the server entrypoint in the same plugin
|
|
178
|
+
* directory; the TUI role loads it, the server role never touches it.
|
|
157
179
|
*
|
|
158
180
|
* @param packageName - The npm package name of the RAG plugin.
|
|
159
181
|
* @returns The JavaScript source code for the TUI plugin entry file.
|
|
160
182
|
*/
|
|
161
183
|
export function generateWorkspaceTuiPluginFile(packageName) {
|
|
162
184
|
return [
|
|
163
|
-
`import plugin from "
|
|
185
|
+
`import plugin from "../../node_modules/${packageName}/dist/tui.js";`,
|
|
164
186
|
`export default plugin;`,
|
|
165
187
|
"",
|
|
166
188
|
].join("\n");
|
|
167
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Content of the V1-era flat server entrypoint (`.opencode/plugins/rag-plugin.js`).
|
|
192
|
+
*
|
|
193
|
+
* Used to recognize — and safely migrate away from — files this command wrote
|
|
194
|
+
* before OpenCode 2 directory discovery. Recognized by exact content match, so
|
|
195
|
+
* hand-written files are never deleted.
|
|
196
|
+
*/
|
|
197
|
+
export function generateLegacyWorkspacePluginFile(packageName) {
|
|
198
|
+
return [`import plugin from "../node_modules/${packageName}/dist/plugin-entry.js";`, `export default plugin;`, ""].join("\n");
|
|
199
|
+
}
|
|
200
|
+
/** Content of the V1-era flat TUI entrypoint (`.opencode/plugins/rag-tui.js`). */
|
|
201
|
+
export function generateLegacyWorkspaceTuiPluginFile(packageName) {
|
|
202
|
+
return [`import plugin from "../node_modules/${packageName}/dist/tui.js";`, `export default plugin;`, ""].join("\n");
|
|
203
|
+
}
|
|
204
|
+
/** Content of the V1-era `.opencode/tui.json`. */
|
|
205
|
+
export function buildLegacyTuiConfig() {
|
|
206
|
+
return { plugin: ["./plugins/rag-tui.js"] };
|
|
207
|
+
}
|
|
168
208
|
/**
|
|
169
209
|
* Generate the content for `.opencode/skills/opencode-rag/SKILL.md`.
|
|
170
210
|
*
|
|
@@ -570,6 +610,13 @@ export function generateDefaultConfigJson(tuning, existingConfigRaw) {
|
|
|
570
610
|
embedConcurrency: tuning?.embedConcurrency ?? DEFAULT_CONFIG.indexing.embedConcurrency ?? 3,
|
|
571
611
|
ollamaMaxBatchSize: tuning?.ollamaMaxBatchSize ?? DEFAULT_CONFIG.indexing.ollamaMaxBatchSize ?? 100,
|
|
572
612
|
},
|
|
613
|
+
chunking: {
|
|
614
|
+
// Emitted (empty) so the extension → parser mapping is discoverable
|
|
615
|
+
// in a freshly generated config. Fill in e.g. { ".c": "cpp", ".cu": "cpp" }
|
|
616
|
+
// to remap a file extension to another parser.
|
|
617
|
+
nodeTypes: {},
|
|
618
|
+
parsers: {},
|
|
619
|
+
},
|
|
573
620
|
vectorStore: {
|
|
574
621
|
path: DEFAULT_CONFIG.vectorStore.path,
|
|
575
622
|
},
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
* installation.
|
|
11
11
|
*/
|
|
12
12
|
import path from "node:path";
|
|
13
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync, copyFileSync } from "node:fs";
|
|
13
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync, copyFileSync } from "node:fs";
|
|
14
14
|
import { loadConfig, findConfigFile } 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";
|
|
18
18
|
import { getPackageMetadata, readJsonObject, writeJsonFile } from "../helpers.js";
|
|
19
|
-
import { buildOpencodeConfig, buildWorkspacePackageJson, generateDefaultConfigJson, generateSkillFile, generateDecisionSkillFile, generateWorkspacePluginFile, generateWorkspaceTuiPluginFile, installPluginFromGlobal, mergeAgentsMdContent, mergeGitignoreContent, } from "./init-helpers.js";
|
|
19
|
+
import { buildLegacyTuiConfig, buildOpencodeConfig, buildWorkspacePackageJson, generateDefaultConfigJson, generateSkillFile, generateDecisionSkillFile, generateLegacyWorkspacePluginFile, generateLegacyWorkspaceTuiPluginFile, generateWorkspacePluginFile, generateWorkspaceTuiPluginFile, installPluginFromGlobal, mergeAgentsMdContent, mergeGitignoreContent, LEGACY_PLUGIN_ENTRY, LEGACY_TUI_CONFIG, LEGACY_TUI_ENTRY, WORKSPACE_PLUGIN_DIR, WORKSPACE_PLUGIN_ENTRY, WORKSPACE_TUI_ENTRY, } from "./init-helpers.js";
|
|
20
20
|
import { detectOllamaBackend } from "./backend-detect.js";
|
|
21
21
|
/**
|
|
22
22
|
* Register the `init` command on the given Commander program.
|
|
@@ -65,9 +65,12 @@ export async function runWorkspaceInit(options = {}) {
|
|
|
65
65
|
const gitignorePath = path.join(opencodeDir, ".gitignore");
|
|
66
66
|
const opencodeConfigPath = path.join(opencodeDir, "opencode.json");
|
|
67
67
|
const pluginsDir = path.join(opencodeDir, "plugins");
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const
|
|
68
|
+
const workspacePluginDir = path.join(pluginsDir, WORKSPACE_PLUGIN_DIR);
|
|
69
|
+
const pluginEntryPath = path.join(workspacePluginDir, "index.js");
|
|
70
|
+
const tuiPluginEntryPath = path.join(workspacePluginDir, "tui.js");
|
|
71
|
+
const legacyPluginEntryPath = path.join(pluginsDir, "rag-plugin.js");
|
|
72
|
+
const legacyTuiPluginEntryPath = path.join(pluginsDir, "rag-tui.js");
|
|
73
|
+
const legacyTuiConfigPath = path.join(opencodeDir, "tui.json");
|
|
71
74
|
const opencodePackagePath = path.join(opencodeDir, "package.json");
|
|
72
75
|
console.log(`\n${c.heading("Initializing OpenCodeRAG in workspace...")}\n`);
|
|
73
76
|
if (!existsSync(opencodeDir)) {
|
|
@@ -111,44 +114,69 @@ export async function runWorkspaceInit(options = {}) {
|
|
|
111
114
|
else {
|
|
112
115
|
console.log(` ${c.exists("Exists:")} .opencode/opencode.json`);
|
|
113
116
|
}
|
|
117
|
+
// OpenCode 2 discovers plugin *directories* under `.opencode/plugins/`:
|
|
118
|
+
// `index.js` is the server (business) entrypoint and `tui.js` beside it
|
|
119
|
+
// is the CLI entrypoint. Flat `.js` files only reach the server role, so
|
|
120
|
+
// the terminal UI never saw the TUI plugin before this layout.
|
|
121
|
+
if (!existsSync(workspacePluginDir)) {
|
|
122
|
+
mkdirSync(workspacePluginDir, { recursive: true });
|
|
123
|
+
console.log(` ${c.created("Created:")} .opencode/plugins/${WORKSPACE_PLUGIN_DIR}/`);
|
|
124
|
+
}
|
|
114
125
|
const pluginEntryExists = existsSync(pluginEntryPath);
|
|
115
126
|
const pluginEntryContent = generateWorkspacePluginFile(packageMetadata.name);
|
|
116
127
|
if (!pluginEntryExists || options.force) {
|
|
117
128
|
writeFileSync(pluginEntryPath, pluginEntryContent, "utf-8");
|
|
118
|
-
console.log(` ${pluginEntryExists ? c.updated("Updated:") : c.created("Created:")}
|
|
129
|
+
console.log(` ${pluginEntryExists ? c.updated("Updated:") : c.created("Created:")} ${WORKSPACE_PLUGIN_ENTRY}`);
|
|
119
130
|
}
|
|
120
131
|
else if (readFileSync(pluginEntryPath, "utf-8") !== pluginEntryContent) {
|
|
121
132
|
writeFileSync(pluginEntryPath, pluginEntryContent, "utf-8");
|
|
122
|
-
console.log(` ${c.updated("Updated:")}
|
|
133
|
+
console.log(` ${c.updated("Updated:")} ${WORKSPACE_PLUGIN_ENTRY}`);
|
|
123
134
|
}
|
|
124
135
|
else {
|
|
125
|
-
console.log(` ${c.exists("Exists:")}
|
|
136
|
+
console.log(` ${c.exists("Exists:")} ${WORKSPACE_PLUGIN_ENTRY}`);
|
|
126
137
|
}
|
|
127
138
|
const tuiPluginEntryExists = existsSync(tuiPluginEntryPath);
|
|
128
139
|
const tuiPluginEntryContent = generateWorkspaceTuiPluginFile(packageMetadata.name);
|
|
129
140
|
if (!tuiPluginEntryExists || options.force) {
|
|
130
141
|
writeFileSync(tuiPluginEntryPath, tuiPluginEntryContent, "utf-8");
|
|
131
|
-
console.log(` ${tuiPluginEntryExists ? c.updated("Updated:") : c.created("Created:")}
|
|
142
|
+
console.log(` ${tuiPluginEntryExists ? c.updated("Updated:") : c.created("Created:")} ${WORKSPACE_TUI_ENTRY}`);
|
|
132
143
|
}
|
|
133
144
|
else if (readFileSync(tuiPluginEntryPath, "utf-8") !== tuiPluginEntryContent) {
|
|
134
145
|
writeFileSync(tuiPluginEntryPath, tuiPluginEntryContent, "utf-8");
|
|
135
|
-
console.log(` ${c.updated("Updated:")}
|
|
146
|
+
console.log(` ${c.updated("Updated:")} ${WORKSPACE_TUI_ENTRY}`);
|
|
136
147
|
}
|
|
137
148
|
else {
|
|
138
|
-
console.log(` ${c.exists("Exists:")}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
+
console.log(` ${c.exists("Exists:")} ${WORKSPACE_TUI_ENTRY}`);
|
|
150
|
+
}
|
|
151
|
+
// Migrate away from the V1-era flat entries: a leftover `rag-plugin.js`
|
|
152
|
+
// registers the server plugin a second time, and `rag-tui.js` is dead
|
|
153
|
+
// weight (the TUI never loads flat files). Only files whose content is
|
|
154
|
+
// exactly what an earlier `init` wrote are removed — hand-written files
|
|
155
|
+
// and custom `.opencode/tui.json` configs are left untouched.
|
|
156
|
+
const legacyEntries = [
|
|
157
|
+
[legacyPluginEntryPath, generateLegacyWorkspacePluginFile(packageMetadata.name), LEGACY_PLUGIN_ENTRY],
|
|
158
|
+
[legacyTuiPluginEntryPath, generateLegacyWorkspaceTuiPluginFile(packageMetadata.name), LEGACY_TUI_ENTRY],
|
|
159
|
+
];
|
|
160
|
+
for (const [legacyPath, legacyContent, legacyRel] of legacyEntries) {
|
|
161
|
+
if (!existsSync(legacyPath))
|
|
162
|
+
continue;
|
|
163
|
+
if (readFileSync(legacyPath, "utf-8") === legacyContent) {
|
|
164
|
+
unlinkSync(legacyPath);
|
|
165
|
+
console.log(` ${c.updated("Removed:")} ${legacyRel} (superseded by ${WORKSPACE_PLUGIN_DIR}/)`);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
console.log(` ${c.warn("Kept:")} ${legacyRel} (modified locally — no longer loaded by OpenCode 2)`);
|
|
169
|
+
}
|
|
149
170
|
}
|
|
150
|
-
|
|
151
|
-
|
|
171
|
+
if (existsSync(legacyTuiConfigPath)) {
|
|
172
|
+
const sameLegacyConfig = JSON.stringify(readJsonObject(legacyTuiConfigPath)) === JSON.stringify(buildLegacyTuiConfig());
|
|
173
|
+
if (sameLegacyConfig) {
|
|
174
|
+
unlinkSync(legacyTuiConfigPath);
|
|
175
|
+
console.log(` ${c.updated("Removed:")} ${LEGACY_TUI_CONFIG} (V1 config — OpenCode 2 discovers CLI plugins)`);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
console.log(` ${c.warn("Kept:")} ${LEGACY_TUI_CONFIG} (V1 config — ignored by OpenCode 2)`);
|
|
179
|
+
}
|
|
152
180
|
}
|
|
153
181
|
const skillsDir = path.join(opencodeDir, "skills");
|
|
154
182
|
const skillDir = path.join(skillsDir, "opencode-rag");
|
|
@@ -427,7 +455,13 @@ export function isLikelyProjectRoot(cwd) {
|
|
|
427
455
|
* @returns Whether the workspace looks initialized.
|
|
428
456
|
*/
|
|
429
457
|
export function isWorkspaceInitialized(cwd) {
|
|
430
|
-
|
|
431
|
-
|
|
458
|
+
// V2 layout: plugin directory with server + TUI entrypoints beside each other.
|
|
459
|
+
if (existsSync(path.join(cwd, ".opencode", "plugins", WORKSPACE_PLUGIN_DIR, "index.js")) &&
|
|
460
|
+
existsSync(path.join(cwd, ".opencode", "plugins", WORKSPACE_PLUGIN_DIR, "tui.js"))) {
|
|
461
|
+
return true;
|
|
462
|
+
}
|
|
463
|
+
// V1 layout (flat entries + .opencode/tui.json): treated as *not* initialized
|
|
464
|
+
// so `setup` re-runs `init` once and migrates the workspace.
|
|
465
|
+
return false;
|
|
432
466
|
}
|
|
433
467
|
//# sourceMappingURL=init.js.map
|
|
@@ -19,6 +19,7 @@ function checkOpenCodeRunning() {
|
|
|
19
19
|
execSync('tasklist /FI "IMAGENAME eq opencode.exe" 2>nul | find /I "opencode.exe" >nul', {
|
|
20
20
|
timeout: 3_000,
|
|
21
21
|
stdio: "ignore",
|
|
22
|
+
windowsHide: true,
|
|
22
23
|
});
|
|
23
24
|
console.log(`\n ${c.warn("OpenCode is currently running.")} Restart it to load the updated plugin.`);
|
|
24
25
|
}
|
|
@@ -26,6 +27,7 @@ function checkOpenCodeRunning() {
|
|
|
26
27
|
const pids = execSync("pgrep -x opencode 2>/dev/null", {
|
|
27
28
|
encoding: "utf-8",
|
|
28
29
|
timeout: 3_000,
|
|
30
|
+
windowsHide: true,
|
|
29
31
|
}).trim();
|
|
30
32
|
if (pids) {
|
|
31
33
|
console.log(`\n ${c.warn("OpenCode is currently running.")} Restart it to load the updated plugin.`);
|
package/dist/cli/commands/ui.js
CHANGED
|
@@ -46,7 +46,7 @@ export function registerUiCommand(program) {
|
|
|
46
46
|
const { spawn } = await import("node:child_process");
|
|
47
47
|
try {
|
|
48
48
|
if (process.platform === "win32") {
|
|
49
|
-
spawn("cmd.exe", ["/c", "start", url], { detached: true, stdio: "ignore" }).unref();
|
|
49
|
+
spawn("cmd.exe", ["/c", "start", url], { detached: true, stdio: "ignore", windowsHide: true }).unref();
|
|
50
50
|
}
|
|
51
51
|
else {
|
|
52
52
|
const cmd = process.platform === "darwin" ? "open" : "xdg-open";
|
|
@@ -22,7 +22,7 @@ function tryRun(command, deps) {
|
|
|
22
22
|
try {
|
|
23
23
|
const out = deps.exec
|
|
24
24
|
? deps.exec(command, EXEC_TIMEOUT_MS)
|
|
25
|
-
: execSync(command, { encoding: "utf-8", timeout: EXEC_TIMEOUT_MS, stdio: ["ignore", "pipe", "ignore"] });
|
|
25
|
+
: execSync(command, { encoding: "utf-8", timeout: EXEC_TIMEOUT_MS, stdio: ["ignore", "pipe", "ignore"], windowsHide: true });
|
|
26
26
|
const trimmed = out.trim();
|
|
27
27
|
return trimmed || null;
|
|
28
28
|
}
|
|
@@ -51,6 +51,16 @@ export interface RuntimeOverrides {
|
|
|
51
51
|
chunksKeybinding?: string;
|
|
52
52
|
settingsKeybinding?: string;
|
|
53
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* Chunking overrides. The TUI writes these live, so they must be applied
|
|
56
|
+
* here — otherwise the write to `runtime-overrides.json` is silently
|
|
57
|
+
* dropped and the edit only takes effect after an OpenCode restart (the
|
|
58
|
+
* plugin reads the on-disk config file once, at startup).
|
|
59
|
+
*/
|
|
60
|
+
chunking?: {
|
|
61
|
+
nodeTypes?: Record<string, string[]>;
|
|
62
|
+
parsers?: Record<string, string>;
|
|
63
|
+
};
|
|
54
64
|
}
|
|
55
65
|
/** Load runtime overrides from the store directory. Returns empty object if none exist. */
|
|
56
66
|
export declare function loadRuntimeOverrides(storePath: string): RuntimeOverrides;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { readFileSync, writeFileSync, existsSync, mkdirSync } from "node:fs";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
7
7
|
import { DEFAULT_CONFIG } from "./config.js";
|
|
8
|
+
import { normalizeParserOverrides } from "./parser-overrides.js";
|
|
8
9
|
/** Load runtime overrides from the store directory. Returns empty object if none exist. */
|
|
9
10
|
export function loadRuntimeOverrides(storePath) {
|
|
10
11
|
const overridePath = join(storePath, "runtime-overrides.json");
|
|
@@ -143,6 +144,19 @@ export function applyRuntimeOverrides(cfg, overrides) {
|
|
|
143
144
|
if (overrides.memory.autoInjectTopK !== undefined)
|
|
144
145
|
m.autoInjectTopK = overrides.memory.autoInjectTopK;
|
|
145
146
|
}
|
|
147
|
+
if (overrides.chunking) {
|
|
148
|
+
if (!merged.chunking)
|
|
149
|
+
merged.chunking = {};
|
|
150
|
+
if (overrides.chunking.nodeTypes !== undefined) {
|
|
151
|
+
merged.chunking.nodeTypes = overrides.chunking.nodeTypes;
|
|
152
|
+
}
|
|
153
|
+
if (overrides.chunking.parsers !== undefined) {
|
|
154
|
+
// Normalize exactly like the config loader does, so a hand-edited
|
|
155
|
+
// runtime-overrides.json gets the same "lowercase, leading dot"
|
|
156
|
+
// handling as the on-disk config.
|
|
157
|
+
merged.chunking.parsers = normalizeParserOverrides(overrides.chunking.parsers);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
146
160
|
if (overrides.tui) {
|
|
147
161
|
merged.tui = {
|
|
148
162
|
...DEFAULT_CONFIG.tui,
|
|
@@ -127,7 +127,10 @@ export async function checkForUpdate(currentVersion) {
|
|
|
127
127
|
export async function installLatestUpdate(options) {
|
|
128
128
|
const verbose = options?.verbose ?? false;
|
|
129
129
|
const stdio = verbose ? "inherit" : "pipe";
|
|
130
|
-
|
|
130
|
+
// Default runner hides the console window on Windows — the plugin runs in
|
|
131
|
+
// OpenCode's console-less service process, so any un-hidden spawn would
|
|
132
|
+
// flash a terminal window.
|
|
133
|
+
const run = options?._execSync ?? ((command, opts) => execSync(command, { ...opts, windowsHide: true }));
|
|
131
134
|
const syncRuntime = options?._setupRuntime ?? setupRuntime;
|
|
132
135
|
const readVersion = options?._getCurrentVersion ?? getCurrentVersion;
|
|
133
136
|
const fromVersion = readVersion();
|
package/dist/eval/fast-index.js
CHANGED
|
@@ -204,7 +204,13 @@ async function main() {
|
|
|
204
204
|
console.log(" empty");
|
|
205
205
|
continue;
|
|
206
206
|
}
|
|
207
|
-
|
|
207
|
+
// Mirror production chunking: the parser override map and the
|
|
208
|
+
// per-language node-type overrides decide the chunk boundaries, so
|
|
209
|
+
// dropping them here would make eval results incomparable to a
|
|
210
|
+
// real index pass.
|
|
211
|
+
const chunks = await chunkFile(absPath, content, cfg.chunking?.nodeTypes, {
|
|
212
|
+
languageByExtension: cfg.chunking?.parsers,
|
|
213
|
+
});
|
|
208
214
|
if (!chunks || chunks.length === 0) {
|
|
209
215
|
console.log(" no chunks");
|
|
210
216
|
continue;
|
|
@@ -59,9 +59,11 @@ function getGitInfo() {
|
|
|
59
59
|
try {
|
|
60
60
|
const branch = execSync("git rev-parse --abbrev-ref HEAD", {
|
|
61
61
|
encoding: "utf-8",
|
|
62
|
+
windowsHide: true,
|
|
62
63
|
}).trim();
|
|
63
64
|
const commit = execSync("git rev-parse --short HEAD", {
|
|
64
65
|
encoding: "utf-8",
|
|
66
|
+
windowsHide: true,
|
|
65
67
|
}).trim();
|
|
66
68
|
return { branch, commit };
|
|
67
69
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* low-level building blocks (chunkers, embedders, vector stores, retrieval),
|
|
4
4
|
* high-level convenience API (search, index, getContext), and plugin entry.
|
|
5
5
|
*/
|
|
6
|
-
export { chunkFile, getChunker, registerChunker, getRegisteredLanguages, getExtensionsForLanguage, validateParserOverrides } from "./chunker/factory.js";
|
|
6
|
+
export { chunkFile, getChunker, registerChunker, getRegisteredLanguages, getExtensionsForLanguage, getLanguageForExtension, validateParserOverrides } from "./chunker/factory.js";
|
|
7
7
|
export { extractSkeleton } from "./chunker/skeleton.js";
|
|
8
8
|
export { normalizeParserOverrides } from "./core/parser-overrides.js";
|
|
9
9
|
export type { ParserOverrides } from "./core/parser-overrides.js";
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* low-level building blocks (chunkers, embedders, vector stores, retrieval),
|
|
4
4
|
* high-level convenience API (search, index, getContext), and plugin entry.
|
|
5
5
|
*/
|
|
6
|
-
export { chunkFile, getChunker, registerChunker, getRegisteredLanguages, getExtensionsForLanguage, validateParserOverrides } from "./chunker/factory.js";
|
|
6
|
+
export { chunkFile, getChunker, registerChunker, getRegisteredLanguages, getExtensionsForLanguage, getLanguageForExtension, validateParserOverrides } from "./chunker/factory.js";
|
|
7
7
|
export { extractSkeleton } from "./chunker/skeleton.js";
|
|
8
8
|
export { normalizeParserOverrides } from "./core/parser-overrides.js";
|
|
9
9
|
export { createEmbedder, embedBatch } from "./embedder/factory.js";
|
package/dist/indexer/git-diff.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Uses git to detect changed, deleted, and untracked files for incremental indexing.
|
|
3
|
+
*
|
|
4
|
+
* Every git invocation sets `windowsHide: true`. The plugin runs inside
|
|
5
|
+
* OpenCode's console-less service process (`opencode serve --service`); without
|
|
6
|
+
* this option Windows allocates a new visible console (a Windows Terminal
|
|
7
|
+
* window/tab on systems where WT is the default terminal) for each spawn,
|
|
8
|
+
* which shows up as a flickering terminal window per index pass.
|
|
3
9
|
*/
|
|
4
10
|
import { execFileSync } from "node:child_process";
|
|
5
11
|
/**
|
|
@@ -15,6 +21,7 @@ export function getRepoRoot(cwd) {
|
|
|
15
21
|
encoding: "utf-8",
|
|
16
22
|
timeout: 5000,
|
|
17
23
|
stdio: ["ignore", "pipe", "ignore"],
|
|
24
|
+
windowsHide: true,
|
|
18
25
|
}).trim();
|
|
19
26
|
}
|
|
20
27
|
catch {
|
|
@@ -34,6 +41,7 @@ export function getCurrentCommit(cwd) {
|
|
|
34
41
|
encoding: "utf-8",
|
|
35
42
|
timeout: 5000,
|
|
36
43
|
stdio: ["ignore", "pipe", "ignore"],
|
|
44
|
+
windowsHide: true,
|
|
37
45
|
}).trim();
|
|
38
46
|
}
|
|
39
47
|
catch {
|
|
@@ -54,10 +62,10 @@ export function getChangedFilesSince(cwd, fromCommit) {
|
|
|
54
62
|
return null;
|
|
55
63
|
try {
|
|
56
64
|
const changedRaw = execFileSync("git", ["diff", "--name-only", "--diff-filter=ACMRT", fromCommit, "HEAD"], {
|
|
57
|
-
cwd, encoding: "utf-8", timeout: 10000, stdio: ["ignore", "pipe", "ignore"],
|
|
65
|
+
cwd, encoding: "utf-8", timeout: 10000, stdio: ["ignore", "pipe", "ignore"], windowsHide: true,
|
|
58
66
|
}).trim();
|
|
59
67
|
const deletedRaw = execFileSync("git", ["diff", "--name-only", "--diff-filter=D", fromCommit, "HEAD"], {
|
|
60
|
-
cwd, encoding: "utf-8", timeout: 10000, stdio: ["ignore", "pipe", "ignore"],
|
|
68
|
+
cwd, encoding: "utf-8", timeout: 10000, stdio: ["ignore", "pipe", "ignore"], windowsHide: true,
|
|
61
69
|
}).trim();
|
|
62
70
|
const changedFiles = changedRaw.length > 0 ? changedRaw.split("\n") : [];
|
|
63
71
|
const deletedFiles = deletedRaw.length > 0 ? deletedRaw.split("\n") : [];
|
|
@@ -79,7 +87,7 @@ export function getChangedFilesSince(cwd, fromCommit) {
|
|
|
79
87
|
export function getUntrackedFiles(cwd) {
|
|
80
88
|
try {
|
|
81
89
|
const raw = execFileSync("git", ["ls-files", "--others", "--exclude-standard"], {
|
|
82
|
-
cwd, encoding: "utf-8", timeout: 5000, stdio: ["ignore", "pipe", "ignore"],
|
|
90
|
+
cwd, encoding: "utf-8", timeout: 5000, stdio: ["ignore", "pipe", "ignore"], windowsHide: true,
|
|
83
91
|
}).trim();
|
|
84
92
|
return raw.length > 0 ? raw.split("\n") : [];
|
|
85
93
|
}
|
|
@@ -98,13 +106,13 @@ export function getUntrackedFiles(cwd) {
|
|
|
98
106
|
export function getWorkingTreeChanges(cwd) {
|
|
99
107
|
try {
|
|
100
108
|
const modifiedRaw = execFileSync("git", ["diff-index", "--name-only", "-M", "HEAD"], {
|
|
101
|
-
cwd, encoding: "utf-8", timeout: 10000, stdio: ["ignore", "pipe", "ignore"],
|
|
109
|
+
cwd, encoding: "utf-8", timeout: 10000, stdio: ["ignore", "pipe", "ignore"], windowsHide: true,
|
|
102
110
|
}).trim();
|
|
103
111
|
const deletedRaw = execFileSync("git", ["diff", "--name-only", "--diff-filter=D", "HEAD"], {
|
|
104
|
-
cwd, encoding: "utf-8", timeout: 10000, stdio: ["ignore", "pipe", "ignore"],
|
|
112
|
+
cwd, encoding: "utf-8", timeout: 10000, stdio: ["ignore", "pipe", "ignore"], windowsHide: true,
|
|
105
113
|
}).trim();
|
|
106
114
|
const untrackedRaw = execFileSync("git", ["ls-files", "--others", "--exclude-standard"], {
|
|
107
|
-
cwd, encoding: "utf-8", timeout: 5000, stdio: ["ignore", "pipe", "ignore"],
|
|
115
|
+
cwd, encoding: "utf-8", timeout: 5000, stdio: ["ignore", "pipe", "ignore"], windowsHide: true,
|
|
108
116
|
}).trim();
|
|
109
117
|
const changedFiles = modifiedRaw.length > 0 ? modifiedRaw.split("\n") : [];
|
|
110
118
|
const deletedFiles = deletedRaw.length > 0 ? deletedRaw.split("\n") : [];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ParserOverrides } from "../core/parser-overrides.js";
|
|
1
2
|
/**
|
|
2
3
|
* Build a metadata header string for embedding context that describes the
|
|
3
4
|
* file type, top-level directory, content classification, and document title.
|
|
@@ -5,6 +6,10 @@
|
|
|
5
6
|
* @param filePath - Absolute path to the file.
|
|
6
7
|
* @param cwd - Workspace root directory (used to compute relative path).
|
|
7
8
|
* @param content - File content used to extract a document title.
|
|
9
|
+
* @param languageByExtension - Optional `chunking.parsers` override map.
|
|
10
|
+
* When an extension is remapped to another parser, the header must name
|
|
11
|
+
* that parser — otherwise the embedded text says `[c]` while the chunk's
|
|
12
|
+
* `metadata.language` (and therefore the keyword filter) says `cpp`.
|
|
8
13
|
* @returns A space-delimited metadata string such as `"[typescript] [src] [source] MyComponent"`.
|
|
9
14
|
*/
|
|
10
|
-
export declare function buildFileMetadataHeader(filePath: string, cwd: string, content: string): string;
|
|
15
|
+
export declare function buildFileMetadataHeader(filePath: string, cwd: string, content: string, languageByExtension?: ParserOverrides): string;
|
package/dist/indexer/metadata.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* @fileoverview Builds metadata headers (file type, content type, document title) for embedding context.
|
|
3
3
|
*/
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import { normalizeParserOverrides, } from "../core/parser-overrides.js";
|
|
5
6
|
const FILE_TYPE_LABELS = {
|
|
6
7
|
".pdf": "pdf",
|
|
7
8
|
".docx": "docx",
|
|
@@ -86,12 +87,17 @@ function extractDocumentTitle(content, filePath) {
|
|
|
86
87
|
* @param filePath - Absolute path to the file.
|
|
87
88
|
* @param cwd - Workspace root directory (used to compute relative path).
|
|
88
89
|
* @param content - File content used to extract a document title.
|
|
90
|
+
* @param languageByExtension - Optional `chunking.parsers` override map.
|
|
91
|
+
* When an extension is remapped to another parser, the header must name
|
|
92
|
+
* that parser — otherwise the embedded text says `[c]` while the chunk's
|
|
93
|
+
* `metadata.language` (and therefore the keyword filter) says `cpp`.
|
|
89
94
|
* @returns A space-delimited metadata string such as `"[typescript] [src] [source] MyComponent"`.
|
|
90
95
|
*/
|
|
91
|
-
export function buildFileMetadataHeader(filePath, cwd, content) {
|
|
96
|
+
export function buildFileMetadataHeader(filePath, cwd, content, languageByExtension) {
|
|
92
97
|
const ext = path.extname(filePath).toLowerCase();
|
|
93
98
|
const relPath = path.relative(cwd, filePath).replace(/\\/g, "/");
|
|
94
|
-
const
|
|
99
|
+
const overrides = normalizeParserOverrides(languageByExtension);
|
|
100
|
+
const fileType = overrides[ext] ?? FILE_TYPE_LABELS[ext] ?? ext.slice(1);
|
|
95
101
|
const dirParts = relPath.split("/");
|
|
96
102
|
dirParts.pop();
|
|
97
103
|
const topDir = dirParts[0] ?? "";
|
package/dist/indexer/worker.js
CHANGED
|
@@ -171,7 +171,9 @@ export async function prepareFile(file, cwd, previous, config, keywordIndex, des
|
|
|
171
171
|
const docPrefix = config.embedding.documentPrefix ?? "";
|
|
172
172
|
const relPath = path.relative(cwd, file.filePath).replace(/\\/g, "/");
|
|
173
173
|
const isImage = isImageFile(file.filePath);
|
|
174
|
-
const metaHeader = isImage
|
|
174
|
+
const metaHeader = isImage
|
|
175
|
+
? ""
|
|
176
|
+
: buildFileMetadataHeader(file.filePath, cwd, file.content, config.chunking?.parsers);
|
|
175
177
|
if (deferDescriptions) {
|
|
176
178
|
for (const chunk of chunks) {
|
|
177
179
|
if (isImage) {
|
|
@@ -9,6 +9,13 @@ export interface RagReadToolOptions {
|
|
|
9
9
|
worktree: string;
|
|
10
10
|
/** Full RAG configuration. */
|
|
11
11
|
config: RagConfig;
|
|
12
|
+
/**
|
|
13
|
+
* Live configuration accessor. When provided, the read tool re-reads the
|
|
14
|
+
* config on every call, so runtime overrides (e.g. a TUI edit of
|
|
15
|
+
* `chunking.parsers`) reach the code-fence language label without
|
|
16
|
+
* restarting OpenCode. Falls back to the static `config` when omitted.
|
|
17
|
+
*/
|
|
18
|
+
getConfig?: () => RagConfig;
|
|
12
19
|
/** Embedding provider for retrieval. */
|
|
13
20
|
embedder: EmbeddingProvider;
|
|
14
21
|
/** Vector store for retrieval. */
|
|
@@ -105,6 +105,9 @@ export function createRagReadTool(options) {
|
|
|
105
105
|
// Retrieval failed — continue with just the file contents
|
|
106
106
|
}
|
|
107
107
|
// 5. Format output: full file + optional RAG context
|
|
108
|
+
// Resolve the config per call so a live `chunking.parsers` override
|
|
109
|
+
// (TUI edit) is reflected in the code-fence language label.
|
|
110
|
+
const liveConfig = options.getConfig?.() ?? config;
|
|
108
111
|
const output = formatHybridReadOutput({
|
|
109
112
|
filePath: resolvedPath,
|
|
110
113
|
fileContent,
|
|
@@ -113,7 +116,7 @@ export function createRagReadTool(options) {
|
|
|
113
116
|
ragChunks,
|
|
114
117
|
relatedFiles,
|
|
115
118
|
maxChars: maxReadOutputChars,
|
|
116
|
-
languageByExtension:
|
|
119
|
+
languageByExtension: liveConfig.chunking?.parsers,
|
|
117
120
|
});
|
|
118
121
|
// 6. Return
|
|
119
122
|
return {
|
package/dist/opencode/tools.d.ts
CHANGED
|
@@ -12,6 +12,12 @@ export interface FileSkeletonToolOptions {
|
|
|
12
12
|
worktree: string;
|
|
13
13
|
/** Extension → parser overrides from `chunking.parsers`. */
|
|
14
14
|
languageByExtension?: ParserOverrides;
|
|
15
|
+
/**
|
|
16
|
+
* Live accessor for the override map. When provided it is consulted on
|
|
17
|
+
* every call, so a runtime override (e.g. a TUI edit) is picked up without
|
|
18
|
+
* restarting OpenCode. Falls back to the static `languageByExtension`.
|
|
19
|
+
*/
|
|
20
|
+
getParserOverrides?: () => ParserOverrides | undefined;
|
|
15
21
|
}
|
|
16
22
|
/**
|
|
17
23
|
* Create the `get_file_skeleton` tool.
|
package/dist/opencode/tools.js
CHANGED
|
@@ -93,7 +93,8 @@ export function createFileSkeletonTool(options) {
|
|
|
93
93
|
const resolvedPath = resolveFilePath(args.filePath, worktree);
|
|
94
94
|
const content = readFileSync(resolvedPath, "utf-8");
|
|
95
95
|
const ext = getExtension(args.filePath);
|
|
96
|
-
const
|
|
96
|
+
const overrides = options.getParserOverrides?.() ?? languageByExtension;
|
|
97
|
+
const skeleton = await extractSkeleton(content, ext, { languageByExtension: overrides });
|
|
97
98
|
const declCounts = new Map();
|
|
98
99
|
for (const item of skeleton) {
|
|
99
100
|
const baseType = item.type.replace(/_declaration$|_definition$|_specifier$|_item$/, "");
|
package/dist/plugin.js
CHANGED
|
@@ -471,7 +471,11 @@ export function createRagHooks(options) {
|
|
|
471
471
|
// Runtime overrides for live config editing from TUI
|
|
472
472
|
let cachedOverrides = loadRuntimeOverrides(options.storePath);
|
|
473
473
|
let overridesLastCheck = 0;
|
|
474
|
-
|
|
474
|
+
// How often the override file is re-read from disk. The documented value
|
|
475
|
+
// was 5s; the code had drifted to 1h, which made every "live" TUI edit
|
|
476
|
+
// (including `chunking.parsers`) take up to an hour to take effect — the
|
|
477
|
+
// edit looked broken. Override with OPENCODE_RAG_OVERRIDES_TTL_MS.
|
|
478
|
+
const OVERRIDES_TTL_MS = Number(process.env.OPENCODE_RAG_OVERRIDES_TTL_MS) || 5000;
|
|
475
479
|
let lastEffectiveCfg = null;
|
|
476
480
|
let lastEffectiveCfgTime = 0;
|
|
477
481
|
function getEffectiveCfg() {
|
|
@@ -630,6 +634,9 @@ export function createRagHooks(options) {
|
|
|
630
634
|
const fileSkeletonTool = createFileSkeletonTool({
|
|
631
635
|
worktree: options.worktree,
|
|
632
636
|
languageByExtension: effectiveCfg.chunking?.parsers,
|
|
637
|
+
// Live accessor so a TUI edit of `chunking.parsers` is picked up
|
|
638
|
+
// without an OpenCode restart.
|
|
639
|
+
getParserOverrides: () => getEffectiveCfg().chunking?.parsers,
|
|
633
640
|
});
|
|
634
641
|
tools["get_file_skeleton"] = fileSkeletonTool;
|
|
635
642
|
}
|
|
@@ -761,6 +768,9 @@ export function createRagHooks(options) {
|
|
|
761
768
|
const readTool = createRagReadTool({
|
|
762
769
|
worktree: options.worktree,
|
|
763
770
|
config: options.cfg,
|
|
771
|
+
// Live config so a TUI edit of `chunking.parsers` reaches the
|
|
772
|
+
// code-fence language label without an OpenCode restart.
|
|
773
|
+
getConfig: getEffectiveCfg,
|
|
764
774
|
embedder,
|
|
765
775
|
store,
|
|
766
776
|
logFilePath: options.logFilePath,
|
package/dist/tui.d.ts
CHANGED
|
@@ -13,12 +13,28 @@ type V2TuiContext = {
|
|
|
13
13
|
location?: {
|
|
14
14
|
directory?: string;
|
|
15
15
|
} | undefined;
|
|
16
|
+
/** OpenCode's own version/channel — NOT the plugin version (use {@link getVersion}). */
|
|
16
17
|
app?: {
|
|
17
18
|
version?: string;
|
|
19
|
+
channel?: string;
|
|
18
20
|
} | undefined;
|
|
19
21
|
theme?: unknown;
|
|
20
22
|
renderer?: unknown;
|
|
21
23
|
data?: {
|
|
24
|
+
/** V2 data domain: `data.location.provider.list(location)`. */
|
|
25
|
+
location?: {
|
|
26
|
+
provider?: {
|
|
27
|
+
list?: (location?: {
|
|
28
|
+
directory?: string;
|
|
29
|
+
} | undefined) => readonly unknown[] | undefined;
|
|
30
|
+
};
|
|
31
|
+
model?: {
|
|
32
|
+
list?: (location?: {
|
|
33
|
+
directory?: string;
|
|
34
|
+
} | undefined) => readonly unknown[] | undefined;
|
|
35
|
+
};
|
|
36
|
+
} | undefined;
|
|
37
|
+
/** Pre-`location` context shapes; kept as a fallback. */
|
|
22
38
|
provider?: {
|
|
23
39
|
list?: () => readonly unknown[] | undefined;
|
|
24
40
|
};
|
package/dist/tui.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* @fileoverview OpenCode TUI (Terminal UI) plugin: renders a sidebar with RAG status,
|
|
3
3
|
* settings dialog for editing config values, and model selection picker.
|
|
4
4
|
*/
|
|
5
|
-
import { createElement, insert, setProp } from "@opentui/solid";
|
|
6
5
|
import { readFileSync, existsSync, writeFileSync, unlinkSync } from "node:fs";
|
|
7
6
|
import { createRequire } from "node:module";
|
|
8
7
|
import { dirname, join, resolve } from "node:path";
|
|
@@ -18,6 +17,24 @@ import { setPendingRagInjection } from "./core/rag-injection-flag.js";
|
|
|
18
17
|
* `src/eval/token-counter.ts`).
|
|
19
18
|
*/
|
|
20
19
|
const _require = createRequire(import.meta.url);
|
|
20
|
+
/** Loaded by {@link loadOpenTui}; `undefined` until the TUI role activates. */
|
|
21
|
+
let openTui;
|
|
22
|
+
/**
|
|
23
|
+
* Load `@opentui/solid` on demand.
|
|
24
|
+
*
|
|
25
|
+
* The package is only resolvable inside OpenCode's CLI (TUI) process, which
|
|
26
|
+
* rewrites the bare specifier to its own bundled copy: plain registry installs
|
|
27
|
+
* have no OpenTUI dependency (it lives in `peerDependencies`, optional) and
|
|
28
|
+
* the server role loads this module too. A static import here therefore breaks
|
|
29
|
+
* every non-TUI load ("Cannot find package '@opentui/solid'"), so it must stay
|
|
30
|
+
* a dynamic import reached only from the TUI branch of `setup()`.
|
|
31
|
+
*/
|
|
32
|
+
async function loadOpenTui() {
|
|
33
|
+
if (!openTui) {
|
|
34
|
+
openTui = (await import("@opentui/solid"));
|
|
35
|
+
}
|
|
36
|
+
return openTui;
|
|
37
|
+
}
|
|
21
38
|
/** Cached plugin version string from package.json. */
|
|
22
39
|
let _version;
|
|
23
40
|
/** Read the plugin version from package.json, caching the result. */
|
|
@@ -140,18 +157,22 @@ function formatKeybinding(key) {
|
|
|
140
157
|
const PLUGIN_NAME = "opencode-rag-plugin";
|
|
141
158
|
/**
|
|
142
159
|
* Create a TUI element node with the given tag, props, and children.
|
|
143
|
-
* Wraps the low-level @opentui/solid createElement/insert/setProp functions
|
|
160
|
+
* Wraps the low-level @opentui/solid createElement/insert/setProp functions
|
|
161
|
+
* (loaded lazily by {@link loadOpenTui} — see {@link setup}).
|
|
144
162
|
*/
|
|
145
163
|
function element(tag, props, children = []) {
|
|
146
|
-
const
|
|
164
|
+
const solid = openTui;
|
|
165
|
+
if (!solid)
|
|
166
|
+
throw new Error("@opentui/solid is not loaded (TUI setup has not run)");
|
|
167
|
+
const node = solid.createElement(tag);
|
|
147
168
|
for (const [key, value] of Object.entries(props)) {
|
|
148
169
|
if (value !== undefined)
|
|
149
|
-
setProp(node, key, value);
|
|
170
|
+
solid.setProp(node, key, value);
|
|
150
171
|
}
|
|
151
172
|
for (const child of children) {
|
|
152
173
|
if (child === null || child === undefined || child === false)
|
|
153
174
|
continue;
|
|
154
|
-
insert(node, child);
|
|
175
|
+
solid.insert(node, child);
|
|
155
176
|
}
|
|
156
177
|
return node;
|
|
157
178
|
}
|
|
@@ -688,8 +709,10 @@ function readTokenStats(worktree) {
|
|
|
688
709
|
/** Rebuild legacy sdk `Provider` shapes (model picker / base URL / API key) from V2 data domains. */
|
|
689
710
|
function v2LegacyProviders(context) {
|
|
690
711
|
try {
|
|
691
|
-
const
|
|
692
|
-
const
|
|
712
|
+
const location = context.location;
|
|
713
|
+
const data = context.data;
|
|
714
|
+
const providers = (data?.location?.provider?.list?.(location) ?? data?.provider?.list?.() ?? []);
|
|
715
|
+
const models = (data?.location?.model?.list?.(location) ?? data?.model?.list?.() ?? []);
|
|
693
716
|
return providers.map((p) => {
|
|
694
717
|
const id = String(p.id ?? "");
|
|
695
718
|
const modelMap = {};
|
|
@@ -704,7 +727,10 @@ function v2LegacyProviders(context) {
|
|
|
704
727
|
id,
|
|
705
728
|
name: p.name ?? id,
|
|
706
729
|
models: modelMap,
|
|
707
|
-
options: {
|
|
730
|
+
options: {
|
|
731
|
+
baseURL: p.settings?.baseURL ?? p.options?.baseURL,
|
|
732
|
+
apiKey: p.settings?.apiKey ?? p.options?.apiKey,
|
|
733
|
+
},
|
|
708
734
|
};
|
|
709
735
|
});
|
|
710
736
|
}
|
|
@@ -888,7 +914,10 @@ async function setup(context) {
|
|
|
888
914
|
const keymap = context.keymap;
|
|
889
915
|
if (!ui?.slot || !keymap)
|
|
890
916
|
return undefined; // server-role load: nothing to register
|
|
891
|
-
|
|
917
|
+
// TUI role confirmed — pull in the OpenTUI renderer primitives. This is the
|
|
918
|
+
// only place `@opentui/solid` may be imported (see {@link loadOpenTui}).
|
|
919
|
+
await loadOpenTui();
|
|
920
|
+
const version = getVersion();
|
|
892
921
|
const worktree = context.location?.directory;
|
|
893
922
|
let cachedStatus = DEFAULT_STATUS;
|
|
894
923
|
let lastRefresh = 0;
|
package/dist/web/api.d.ts
CHANGED
|
@@ -32,6 +32,17 @@ interface ApiResponse {
|
|
|
32
32
|
* @returns An async handler that returns `true` when a route matched or `false` otherwise.
|
|
33
33
|
*/
|
|
34
34
|
export declare function createApiHandler(store: LanceDbStore, keywordIndex: KeywordIndex, storePath: string, cwd?: string, cfg?: RagConfig, getEmbedder?: () => Promise<EmbeddingProvider>, token?: string, configPath?: string): (req: IncomingMessage, res: ServerResponse) => Promise<boolean>;
|
|
35
|
+
/**
|
|
36
|
+
* Apply a validated config patch (`{ indexing: { includeDirs: [...] } }`)
|
|
37
|
+
* to the on-disk config file and refresh the in-memory config used by
|
|
38
|
+
* subsequent API requests. Only known sections/keys with validated types
|
|
39
|
+
* are accepted; anything else is rejected with a 400.
|
|
40
|
+
*
|
|
41
|
+
* Exported for unit testing.
|
|
42
|
+
*/
|
|
43
|
+
export declare function handleConfigUpdate(configPath: string | undefined, configRef: {
|
|
44
|
+
current?: RagConfig;
|
|
45
|
+
}, body: unknown): ApiResponse;
|
|
35
46
|
/**
|
|
36
47
|
* Perform token-usage analysis for a single evaluation session.
|
|
37
48
|
*
|
package/dist/web/api.js
CHANGED
|
@@ -675,13 +675,27 @@ const INDEXING_STRING_ARRAY_KEYS = new Set([
|
|
|
675
675
|
"excludeFiles",
|
|
676
676
|
"includeDirs",
|
|
677
677
|
]);
|
|
678
|
+
/** True for a plain object whose every value is a string. */
|
|
679
|
+
function isStringMap(value) {
|
|
680
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
681
|
+
return false;
|
|
682
|
+
return Object.values(value).every((v) => typeof v === "string");
|
|
683
|
+
}
|
|
684
|
+
/** True for a plain object whose every value is an array of strings. */
|
|
685
|
+
function isStringArrayMap(value) {
|
|
686
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
687
|
+
return false;
|
|
688
|
+
return Object.values(value).every((v) => Array.isArray(v) && v.every((x) => typeof x === "string"));
|
|
689
|
+
}
|
|
678
690
|
/**
|
|
679
691
|
* Apply a validated config patch (`{ indexing: { includeDirs: [...] } }`)
|
|
680
692
|
* to the on-disk config file and refresh the in-memory config used by
|
|
681
693
|
* subsequent API requests. Only known sections/keys with validated types
|
|
682
694
|
* are accepted; anything else is rejected with a 400.
|
|
695
|
+
*
|
|
696
|
+
* Exported for unit testing.
|
|
683
697
|
*/
|
|
684
|
-
function handleConfigUpdate(configPath, configRef, body) {
|
|
698
|
+
export function handleConfigUpdate(configPath, configRef, body) {
|
|
685
699
|
if (!configPath) {
|
|
686
700
|
return {
|
|
687
701
|
status: 400,
|
|
@@ -692,7 +706,7 @@ function handleConfigUpdate(configPath, configRef, body) {
|
|
|
692
706
|
if (!patch || typeof patch !== "object" || Array.isArray(patch)) {
|
|
693
707
|
return { status: 400, body: { error: "Invalid config patch" } };
|
|
694
708
|
}
|
|
695
|
-
const otherSections = Object.keys(patch).filter((k) => k !== "indexing");
|
|
709
|
+
const otherSections = Object.keys(patch).filter((k) => k !== "indexing" && k !== "chunking");
|
|
696
710
|
if (otherSections.length > 0) {
|
|
697
711
|
return { status: 400, body: { error: `Unsupported config section(s): ${otherSections.join(", ")}` } };
|
|
698
712
|
}
|
|
@@ -710,6 +724,27 @@ function handleConfigUpdate(configPath, configRef, body) {
|
|
|
710
724
|
}
|
|
711
725
|
}
|
|
712
726
|
}
|
|
727
|
+
const chunkingPatch = patch.chunking;
|
|
728
|
+
if (chunkingPatch !== undefined) {
|
|
729
|
+
if (typeof chunkingPatch !== "object" || chunkingPatch === null || Array.isArray(chunkingPatch)) {
|
|
730
|
+
return { status: 400, body: { error: "Invalid 'chunking' section" } };
|
|
731
|
+
}
|
|
732
|
+
for (const [key, value] of Object.entries(chunkingPatch)) {
|
|
733
|
+
if (key === "parsers") {
|
|
734
|
+
if (!isStringMap(value)) {
|
|
735
|
+
return { status: 400, body: { error: "'chunking.parsers' must be an object mapping file extensions to parser names" } };
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
else if (key === "nodeTypes") {
|
|
739
|
+
if (!isStringArrayMap(value)) {
|
|
740
|
+
return { status: 400, body: { error: "'chunking.nodeTypes' must be an object mapping languages to arrays of node type names" } };
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
else {
|
|
744
|
+
return { status: 400, body: { error: `Unsupported chunking key '${key}'` } };
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
713
748
|
if (indexingPatch) {
|
|
714
749
|
for (const [key, value] of Object.entries(indexingPatch)) {
|
|
715
750
|
const ok = updateConfigValue(configPath, ["indexing", key], value);
|
|
@@ -723,6 +758,19 @@ function handleConfigUpdate(configPath, configRef, body) {
|
|
|
723
758
|
indexing: { ...current.indexing, ...indexingPatch },
|
|
724
759
|
};
|
|
725
760
|
}
|
|
761
|
+
if (chunkingPatch) {
|
|
762
|
+
for (const [key, value] of Object.entries(chunkingPatch)) {
|
|
763
|
+
const ok = updateConfigValue(configPath, ["chunking", key], value);
|
|
764
|
+
if (!ok) {
|
|
765
|
+
return { status: 500, body: { error: `Failed to write 'chunking.${key}' to ${configPath}` } };
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
const current = configRef.current ?? {};
|
|
769
|
+
configRef.current = {
|
|
770
|
+
...current,
|
|
771
|
+
chunking: { ...current.chunking, ...chunkingPatch },
|
|
772
|
+
};
|
|
773
|
+
}
|
|
726
774
|
const redacted = JSON.parse(JSON.stringify(configRef.current));
|
|
727
775
|
redactKeys(redacted);
|
|
728
776
|
return { status: 200, body: { config: redacted } };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-rag-plugin",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "OpenCode plugin for local-first RAG-based semantic code search",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/plugin-entry.js",
|
|
@@ -85,7 +85,21 @@
|
|
|
85
85
|
"homepage": "https://github.com/MrDoe/OpenCodeRAG#readme",
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"@opencode-ai/plugin": ">=1.18.0",
|
|
88
|
-
"@opencode/plugin": ">=2.0.0"
|
|
88
|
+
"@opencode/plugin": ">=2.0.0",
|
|
89
|
+
"@opentui/core": ">=0.5.10",
|
|
90
|
+
"@opentui/solid": ">=0.5.10",
|
|
91
|
+
"solid-js": ">=1.9.0"
|
|
92
|
+
},
|
|
93
|
+
"peerDependenciesMeta": {
|
|
94
|
+
"@opentui/core": {
|
|
95
|
+
"optional": true
|
|
96
|
+
},
|
|
97
|
+
"@opentui/solid": {
|
|
98
|
+
"optional": true
|
|
99
|
+
},
|
|
100
|
+
"solid-js": {
|
|
101
|
+
"optional": true
|
|
102
|
+
}
|
|
89
103
|
},
|
|
90
104
|
"dependencies": {
|
|
91
105
|
"@e965/xlsx": "^0.20.3",
|