opencode-rag-plugin 2.11.1 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReadMe.md +305 -207
- package/dist/cli/commands/backend-detect.d.ts +1 -1
- package/dist/cli/commands/backend-detect.js +1 -1
- package/dist/cli/commands/index.d.ts +0 -1
- package/dist/cli/commands/index.js +0 -1
- package/dist/cli/commands/setup.js +271 -85
- package/dist/cli/commands/{init-helpers.d.ts → workspace-helpers.d.ts} +10 -7
- package/dist/cli/commands/{init-helpers.js → workspace-helpers.js} +12 -62
- package/dist/cli/index.js +1 -2
- package/dist/cli/prompt.d.ts +84 -0
- package/dist/cli/prompt.js +247 -0
- package/dist/cli/types.d.ts +16 -17
- package/dist/cli/wizard/apply.d.ts +58 -0
- package/dist/cli/wizard/apply.js +234 -0
- package/dist/cli/wizard/flow.d.ts +83 -0
- package/dist/cli/wizard/flow.js +759 -0
- package/dist/cli/wizard/model-catalog.d.ts +80 -0
- package/dist/cli/wizard/model-catalog.js +414 -0
- package/dist/cli/wizard/types.d.ts +94 -0
- package/dist/cli/wizard/types.js +5 -0
- package/dist/cli/workspace.d.ts +40 -0
- package/dist/cli/workspace.js +322 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +1 -1
- package/dist/core/config.d.ts +2 -2
- package/dist/core/config.js +2 -2
- package/dist/core/provider-defaults.d.ts +2 -0
- package/dist/core/provider-defaults.js +4 -0
- package/dist/eval/fast-index.js +1 -1
- package/dist/opencode/system-guidance.d.ts +1 -1
- package/dist/opencode/system-guidance.js +1 -1
- package/dist/plugin.d.ts +13 -0
- package/dist/plugin.js +77 -8
- package/dist/tui.d.ts +11 -0
- package/dist/tui.js +12 -1
- package/package.json +1 -1
- package/dist/cli/commands/init.d.ts +0 -51
- package/dist/cli/commands/init.js +0 -508
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Workspace scaffolding shared by `opencode-rag setup`.
|
|
3
|
+
*
|
|
4
|
+
* Creates/updates the `.opencode/` tree, plugin entrypoints, skills,
|
|
5
|
+
* `AGENTS.md` guidance and the workspace `package.json`. Configuration is
|
|
6
|
+
* written separately (see `src/cli/wizard/apply.ts`) so the wizard can decide
|
|
7
|
+
* what goes into the workspace file before `AGENTS.md` is rendered from the
|
|
8
|
+
* effective `decision`/`memory` flags.
|
|
9
|
+
*/
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { loadConfig, loadWorkspaceConfig, configuredSections, findConfigFile, projectConfigPath } from "../core/config.js";
|
|
13
|
+
import { checkProviderHealth, pullOllamaModels } from "../embedder/health.js";
|
|
14
|
+
import { c } from "./format.js";
|
|
15
|
+
import { getPackageMetadata, readJsonObject, writeJsonFile } from "./helpers.js";
|
|
16
|
+
import { buildLegacyTuiConfig, buildOpencodeConfig, buildWorkspacePackageJson, generateDecisionSkillFile, generateLegacyWorkspacePluginFile, generateLegacyWorkspaceTuiPluginFile, generateSkillFile, generateWorkspacePluginFile, generateWorkspaceTuiPluginFile, installPluginFromGlobal, mergeAgentsMdContent, mergeGitignoreContent, LEGACY_PLUGIN_ENTRY, LEGACY_TUI_CONFIG, LEGACY_TUI_ENTRY, WORKSPACE_PLUGIN_DIR, WORKSPACE_PLUGIN_ENTRY, WORKSPACE_TUI_ENTRY, } from "./commands/workspace-helpers.js";
|
|
17
|
+
/**
|
|
18
|
+
* Best-effort check whether `cwd` looks like a project root (git repo or
|
|
19
|
+
* common project manifest files). `setup` uses this to warn before creating
|
|
20
|
+
* `.opencode/` in an unrelated directory.
|
|
21
|
+
*/
|
|
22
|
+
export function isLikelyProjectRoot(cwd) {
|
|
23
|
+
if (existsSync(path.join(cwd, ".git"))) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
const markers = [
|
|
27
|
+
"package.json",
|
|
28
|
+
"AGENTS.md",
|
|
29
|
+
"README.md",
|
|
30
|
+
"pyproject.toml",
|
|
31
|
+
"Cargo.toml",
|
|
32
|
+
"go.mod",
|
|
33
|
+
"opencode-rag.json",
|
|
34
|
+
".opencode/opencode-rag.json",
|
|
35
|
+
];
|
|
36
|
+
return markers.some((marker) => existsSync(path.join(cwd, marker)));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create or refresh the workspace files.
|
|
40
|
+
*
|
|
41
|
+
* Idempotent: unchanged generated files are reported as existing and not
|
|
42
|
+
* rewritten. The workspace config is never modified here.
|
|
43
|
+
*/
|
|
44
|
+
export async function scaffoldWorkspace(options = {}) {
|
|
45
|
+
const cwd = process.cwd();
|
|
46
|
+
const packageMetadata = getPackageMetadata();
|
|
47
|
+
const configPath = options.configPath ?? findConfigFile(cwd) ?? projectConfigPath(cwd);
|
|
48
|
+
const opencodeDir = path.join(cwd, ".opencode");
|
|
49
|
+
const gitignorePath = path.join(opencodeDir, ".gitignore");
|
|
50
|
+
const opencodeConfigPath = path.join(opencodeDir, "opencode.json");
|
|
51
|
+
const pluginsDir = path.join(opencodeDir, "plugins");
|
|
52
|
+
const workspacePluginDir = path.join(pluginsDir, WORKSPACE_PLUGIN_DIR);
|
|
53
|
+
const pluginEntryPath = path.join(workspacePluginDir, "index.js");
|
|
54
|
+
const tuiPluginEntryPath = path.join(workspacePluginDir, "tui.js");
|
|
55
|
+
const legacyPluginEntryPath = path.join(pluginsDir, "rag-plugin.js");
|
|
56
|
+
const legacyTuiPluginEntryPath = path.join(pluginsDir, "rag-tui.js");
|
|
57
|
+
const legacyTuiConfigPath = path.join(opencodeDir, "tui.json");
|
|
58
|
+
const opencodePackagePath = path.join(opencodeDir, "package.json");
|
|
59
|
+
console.log(`\n${c.heading("Workspace files")}\n`);
|
|
60
|
+
if (!existsSync(opencodeDir)) {
|
|
61
|
+
mkdirSync(opencodeDir, { recursive: true });
|
|
62
|
+
console.log(` ${c.created("Created:")} .opencode/`);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
console.log(` ${c.exists("Exists:")} .opencode/`);
|
|
66
|
+
}
|
|
67
|
+
// The wiki is user-authored; setup never touches it.
|
|
68
|
+
const wikiDir = path.join(opencodeDir, "wiki");
|
|
69
|
+
if (existsSync(wikiDir)) {
|
|
70
|
+
console.log(` ${c.exists("Preserved:")} .opencode/wiki/ (never modified by setup)`);
|
|
71
|
+
}
|
|
72
|
+
if (!existsSync(pluginsDir)) {
|
|
73
|
+
mkdirSync(pluginsDir, { recursive: true });
|
|
74
|
+
console.log(` ${c.created("Created:")} .opencode/plugins/`);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
console.log(` ${c.exists("Exists:")} .opencode/plugins/`);
|
|
78
|
+
}
|
|
79
|
+
const gitignoreExists = existsSync(gitignorePath);
|
|
80
|
+
const nextGitignoreContent = mergeGitignoreContent(gitignoreExists ? readFileSync(gitignorePath, "utf-8") : undefined);
|
|
81
|
+
if (!gitignoreExists || options.force || readFileSync(gitignorePath, "utf-8") !== nextGitignoreContent) {
|
|
82
|
+
writeFileSync(gitignorePath, nextGitignoreContent, "utf-8");
|
|
83
|
+
console.log(` ${gitignoreExists ? c.updated("Updated:") : c.created("Created:")} .opencode/.gitignore`);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
console.log(` ${c.exists("Exists:")} .opencode/.gitignore`);
|
|
87
|
+
}
|
|
88
|
+
const opencodeConfigExists = existsSync(opencodeConfigPath);
|
|
89
|
+
const nextOpencodeConfig = buildOpencodeConfig(readJsonObject(opencodeConfigPath));
|
|
90
|
+
if (!opencodeConfigExists || options.force) {
|
|
91
|
+
writeJsonFile(opencodeConfigPath, nextOpencodeConfig);
|
|
92
|
+
console.log(` ${opencodeConfigExists ? c.updated("Updated:") : c.created("Created:")} .opencode/opencode.json`);
|
|
93
|
+
}
|
|
94
|
+
else if (JSON.stringify(readJsonObject(opencodeConfigPath)) !== JSON.stringify(nextOpencodeConfig)) {
|
|
95
|
+
writeJsonFile(opencodeConfigPath, nextOpencodeConfig);
|
|
96
|
+
console.log(` ${c.updated("Updated:")} .opencode/opencode.json`);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
console.log(` ${c.exists("Exists:")} .opencode/opencode.json`);
|
|
100
|
+
}
|
|
101
|
+
// OpenCode 2 discovers plugin *directories* under `.opencode/plugins/`:
|
|
102
|
+
// `index.js` is the server entrypoint and `tui.js` beside it is the CLI
|
|
103
|
+
// entrypoint. Flat `.js` files only reach the server role.
|
|
104
|
+
if (!existsSync(workspacePluginDir)) {
|
|
105
|
+
mkdirSync(workspacePluginDir, { recursive: true });
|
|
106
|
+
console.log(` ${c.created("Created:")} .opencode/plugins/${WORKSPACE_PLUGIN_DIR}/`);
|
|
107
|
+
}
|
|
108
|
+
const pluginEntryExists = existsSync(pluginEntryPath);
|
|
109
|
+
const pluginEntryContent = generateWorkspacePluginFile(packageMetadata.name);
|
|
110
|
+
if (!pluginEntryExists || options.force) {
|
|
111
|
+
writeFileSync(pluginEntryPath, pluginEntryContent, "utf-8");
|
|
112
|
+
console.log(` ${pluginEntryExists ? c.updated("Updated:") : c.created("Created:")} ${WORKSPACE_PLUGIN_ENTRY}`);
|
|
113
|
+
}
|
|
114
|
+
else if (readFileSync(pluginEntryPath, "utf-8") !== pluginEntryContent) {
|
|
115
|
+
writeFileSync(pluginEntryPath, pluginEntryContent, "utf-8");
|
|
116
|
+
console.log(` ${c.updated("Updated:")} ${WORKSPACE_PLUGIN_ENTRY}`);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
console.log(` ${c.exists("Exists:")} ${WORKSPACE_PLUGIN_ENTRY}`);
|
|
120
|
+
}
|
|
121
|
+
const tuiPluginEntryExists = existsSync(tuiPluginEntryPath);
|
|
122
|
+
const tuiPluginEntryContent = generateWorkspaceTuiPluginFile(packageMetadata.name);
|
|
123
|
+
if (!tuiPluginEntryExists || options.force) {
|
|
124
|
+
writeFileSync(tuiPluginEntryPath, tuiPluginEntryContent, "utf-8");
|
|
125
|
+
console.log(` ${tuiPluginEntryExists ? c.updated("Updated:") : c.created("Created:")} ${WORKSPACE_TUI_ENTRY}`);
|
|
126
|
+
}
|
|
127
|
+
else if (readFileSync(tuiPluginEntryPath, "utf-8") !== tuiPluginEntryContent) {
|
|
128
|
+
writeFileSync(tuiPluginEntryPath, tuiPluginEntryContent, "utf-8");
|
|
129
|
+
console.log(` ${c.updated("Updated:")} ${WORKSPACE_TUI_ENTRY}`);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
console.log(` ${c.exists("Exists:")} ${WORKSPACE_TUI_ENTRY}`);
|
|
133
|
+
}
|
|
134
|
+
// Remove only the V1-era flat entries that an older `init` wrote verbatim;
|
|
135
|
+
// modified files are kept (they are no longer loaded by OpenCode 2).
|
|
136
|
+
const legacyEntries = [
|
|
137
|
+
[legacyPluginEntryPath, generateLegacyWorkspacePluginFile(packageMetadata.name), LEGACY_PLUGIN_ENTRY],
|
|
138
|
+
[legacyTuiPluginEntryPath, generateLegacyWorkspaceTuiPluginFile(packageMetadata.name), LEGACY_TUI_ENTRY],
|
|
139
|
+
];
|
|
140
|
+
for (const [legacyPath, legacyContent, legacyRel] of legacyEntries) {
|
|
141
|
+
if (!existsSync(legacyPath))
|
|
142
|
+
continue;
|
|
143
|
+
if (readFileSync(legacyPath, "utf-8") === legacyContent) {
|
|
144
|
+
unlinkSync(legacyPath);
|
|
145
|
+
console.log(` ${c.updated("Removed:")} ${legacyRel} (superseded by ${WORKSPACE_PLUGIN_DIR}/)`);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
console.log(` ${c.warn("Kept:")} ${legacyRel} (modified locally — no longer loaded by OpenCode 2)`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (existsSync(legacyTuiConfigPath)) {
|
|
152
|
+
const sameLegacyConfig = JSON.stringify(readJsonObject(legacyTuiConfigPath)) === JSON.stringify(buildLegacyTuiConfig());
|
|
153
|
+
if (sameLegacyConfig) {
|
|
154
|
+
unlinkSync(legacyTuiConfigPath);
|
|
155
|
+
console.log(` ${c.updated("Removed:")} ${LEGACY_TUI_CONFIG} (V1 config — OpenCode 2 discovers CLI plugins)`);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
console.log(` ${c.warn("Kept:")} ${LEGACY_TUI_CONFIG} (V1 config — ignored by OpenCode 2)`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const skillsDir = path.join(opencodeDir, "skills");
|
|
162
|
+
const skillDir = path.join(skillsDir, "opencode-rag");
|
|
163
|
+
const skillPath = path.join(skillDir, "SKILL.md");
|
|
164
|
+
if (!existsSync(skillDir)) {
|
|
165
|
+
mkdirSync(skillDir, { recursive: true });
|
|
166
|
+
console.log(` ${c.created("Created:")} .opencode/skills/opencode-rag/`);
|
|
167
|
+
}
|
|
168
|
+
const skillContent = generateSkillFile();
|
|
169
|
+
const skillExists = existsSync(skillPath);
|
|
170
|
+
if (!skillExists || options.force) {
|
|
171
|
+
writeFileSync(skillPath, skillContent, "utf-8");
|
|
172
|
+
console.log(` ${skillExists ? c.updated("Updated:") : c.created("Created:")} .opencode/skills/opencode-rag/SKILL.md`);
|
|
173
|
+
}
|
|
174
|
+
else if (readFileSync(skillPath, "utf-8") !== skillContent) {
|
|
175
|
+
writeFileSync(skillPath, skillContent, "utf-8");
|
|
176
|
+
console.log(` ${c.updated("Updated:")} .opencode/skills/opencode-rag/SKILL.md`);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
console.log(` ${c.exists("Exists:")} .opencode/skills/opencode-rag/SKILL.md`);
|
|
180
|
+
}
|
|
181
|
+
const decisionSkillDir = path.join(skillsDir, "make-decision");
|
|
182
|
+
const decisionSkillPath = path.join(decisionSkillDir, "SKILL.md");
|
|
183
|
+
if (!existsSync(decisionSkillDir)) {
|
|
184
|
+
mkdirSync(decisionSkillDir, { recursive: true });
|
|
185
|
+
console.log(` ${c.created("Created:")} .opencode/skills/make-decision/`);
|
|
186
|
+
}
|
|
187
|
+
const decisionSkillContent = generateDecisionSkillFile();
|
|
188
|
+
const decisionSkillExists = existsSync(decisionSkillPath);
|
|
189
|
+
if (!decisionSkillExists || options.force) {
|
|
190
|
+
writeFileSync(decisionSkillPath, decisionSkillContent, "utf-8");
|
|
191
|
+
console.log(` ${decisionSkillExists ? c.updated("Updated:") : c.created("Created:")} .opencode/skills/make-decision/SKILL.md`);
|
|
192
|
+
}
|
|
193
|
+
else if (readFileSync(decisionSkillPath, "utf-8") !== decisionSkillContent) {
|
|
194
|
+
writeFileSync(decisionSkillPath, decisionSkillContent, "utf-8");
|
|
195
|
+
console.log(` ${c.updated("Updated:")} .opencode/skills/make-decision/SKILL.md`);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
console.log(` ${c.exists("Exists:")} .opencode/skills/make-decision/SKILL.md`);
|
|
199
|
+
}
|
|
200
|
+
const agentsMdPath = path.join(cwd, "AGENTS.md");
|
|
201
|
+
const agentsMdExists = existsSync(agentsMdPath);
|
|
202
|
+
let promptEnforcement = true;
|
|
203
|
+
let decisionEnabled = false;
|
|
204
|
+
let routeBeforeAsking = false;
|
|
205
|
+
try {
|
|
206
|
+
if (existsSync(configPath)) {
|
|
207
|
+
const existingCfg = loadConfig(configPath, false);
|
|
208
|
+
promptEnforcement = existingCfg.memory?.promptEnforcement ?? true;
|
|
209
|
+
decisionEnabled = existingCfg.decision?.enabled ?? false;
|
|
210
|
+
routeBeforeAsking = existingCfg.decision?.routeBeforeAsking ?? false;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
// Malformed or missing config — use defaults.
|
|
215
|
+
}
|
|
216
|
+
const nextAgentsMd = mergeAgentsMdContent(agentsMdExists ? readFileSync(agentsMdPath, "utf-8") : undefined, { promptEnforcement, decisionEnabled, routeBeforeAsking });
|
|
217
|
+
if (!agentsMdExists || options.force) {
|
|
218
|
+
writeFileSync(agentsMdPath, nextAgentsMd, "utf-8");
|
|
219
|
+
console.log(` ${agentsMdExists ? c.updated("Updated:") : c.created("Created:")} AGENTS.md`);
|
|
220
|
+
}
|
|
221
|
+
else if (readFileSync(agentsMdPath, "utf-8") !== nextAgentsMd) {
|
|
222
|
+
writeFileSync(agentsMdPath, nextAgentsMd, "utf-8");
|
|
223
|
+
console.log(` ${c.updated("Updated:")} AGENTS.md`);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
console.log(` ${c.exists("Exists:")} AGENTS.md`);
|
|
227
|
+
}
|
|
228
|
+
const workspacePackageExists = existsSync(opencodePackagePath);
|
|
229
|
+
const nextWorkspacePackage = buildWorkspacePackageJson(readJsonObject(opencodePackagePath), packageMetadata);
|
|
230
|
+
if (!workspacePackageExists || options.force) {
|
|
231
|
+
writeJsonFile(opencodePackagePath, nextWorkspacePackage);
|
|
232
|
+
console.log(` ${workspacePackageExists ? c.updated("Updated:") : c.created("Created:")} .opencode/package.json`);
|
|
233
|
+
}
|
|
234
|
+
else if (JSON.stringify(readJsonObject(opencodePackagePath)) !== JSON.stringify(nextWorkspacePackage)) {
|
|
235
|
+
writeJsonFile(opencodePackagePath, nextWorkspacePackage);
|
|
236
|
+
console.log(` ${c.updated("Updated:")} .opencode/package.json`);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
console.log(` ${c.exists("Exists:")} .opencode/package.json`);
|
|
240
|
+
}
|
|
241
|
+
if (options.skipInstall) {
|
|
242
|
+
console.log(`\n ${c.exists("Skipped:")} plugin installation (--skip-install)`);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
console.log(`\n${c.heading("Installing workspace-local plugin...")}\n`);
|
|
246
|
+
await installPluginFromGlobal(opencodeDir, packageMetadata.name, false);
|
|
247
|
+
console.log(`\n ${c.success("Installed:")} .opencode/node_modules/`);
|
|
248
|
+
console.log(` ${c.dim("Plugin is linked to the global runtime cache; no npm install was required.")}`);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Check provider connectivity and offer to pull missing Ollama models.
|
|
252
|
+
*
|
|
253
|
+
* Uses the effective config (global < workspace) so models chosen in the
|
|
254
|
+
* wizard are probed even though most provider settings live in the global
|
|
255
|
+
* file.
|
|
256
|
+
*/
|
|
257
|
+
export async function runWorkspaceHealthCheck(cwd, prompter) {
|
|
258
|
+
console.log(`\n${c.heading("Checking provider connectivity...")}\n`);
|
|
259
|
+
const ragConfig = loadWorkspaceConfig(cwd);
|
|
260
|
+
const results = await checkProviderHealth(ragConfig, configuredSections(cwd));
|
|
261
|
+
for (const result of results) {
|
|
262
|
+
const icon = result.status === "ok" ? c.success("✓") : result.status === "missing" ? c.warn("○") : c.error("✗");
|
|
263
|
+
const typeLabel = result.type === "image_description"
|
|
264
|
+
? "image description"
|
|
265
|
+
: result.type === "image_description_on_demand"
|
|
266
|
+
? "image description (on-demand)"
|
|
267
|
+
: result.type;
|
|
268
|
+
console.log(` ${icon} ${c.value(result.model)} (${result.provider}) — ${typeLabel} model: ${result.status}`);
|
|
269
|
+
if (result.error)
|
|
270
|
+
console.log(` ${c.dim(result.error)}`);
|
|
271
|
+
}
|
|
272
|
+
const missingOllama = results.filter((result) => result.status === "missing" && result.provider === "ollama");
|
|
273
|
+
if (missingOllama.length > 0) {
|
|
274
|
+
const pullEntries = missingOllama.map((result) => {
|
|
275
|
+
if (result.type === "embedding") {
|
|
276
|
+
return { model: result.model, baseUrl: ragConfig.embedding.baseUrl, proxy: ragConfig.embedding.proxy };
|
|
277
|
+
}
|
|
278
|
+
if (result.type === "description" && ragConfig.description) {
|
|
279
|
+
return { model: result.model, baseUrl: ragConfig.description.baseUrl, proxy: ragConfig.description.proxy };
|
|
280
|
+
}
|
|
281
|
+
if (result.type === "image_description" && ragConfig.imageDescription) {
|
|
282
|
+
return { model: result.model, baseUrl: ragConfig.imageDescription.baseUrl, proxy: ragConfig.imageDescription.proxy };
|
|
283
|
+
}
|
|
284
|
+
if (result.type === "image_description_on_demand" && ragConfig.imageDescription) {
|
|
285
|
+
const onDemand = ragConfig.imageDescription.onDemand;
|
|
286
|
+
return {
|
|
287
|
+
model: result.model,
|
|
288
|
+
baseUrl: onDemand?.baseUrl ?? ragConfig.imageDescription.baseUrl,
|
|
289
|
+
proxy: onDemand?.proxy ?? ragConfig.imageDescription.proxy,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
return { model: result.model, baseUrl: ragConfig.embedding.baseUrl, proxy: ragConfig.embedding.proxy };
|
|
293
|
+
});
|
|
294
|
+
console.log(`\n ${c.warn("Models not found:")} ${pullEntries.map((entry) => entry.model).join(", ")}`);
|
|
295
|
+
const pull = prompter.interactive
|
|
296
|
+
? await prompter.confirm({
|
|
297
|
+
message: `Pull ${pullEntries.length === 1 ? "this model" : "these models"} now?`,
|
|
298
|
+
defaultValue: false,
|
|
299
|
+
})
|
|
300
|
+
: false;
|
|
301
|
+
if (pull) {
|
|
302
|
+
console.log();
|
|
303
|
+
try {
|
|
304
|
+
await pullOllamaModels(pullEntries, (model, line) => {
|
|
305
|
+
console.log(` ${c.value(model)}: ${line}`);
|
|
306
|
+
});
|
|
307
|
+
console.log(`\n ${c.success("Models pulled successfully.")}`);
|
|
308
|
+
}
|
|
309
|
+
catch (err) {
|
|
310
|
+
console.error(`\n ${c.error("Pull failed:")} ${err.message}`);
|
|
311
|
+
console.log(` ${c.dim("Pull manually with: ollama pull <model>")}`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
console.log(` ${c.dim("Skipped. Pull manually with: ollama pull <model>")}`);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (results.some((result) => result.status === "error")) {
|
|
319
|
+
console.log(`\n ${c.warn("Some providers are not reachable.")} Check configuration and network, then run ${c.file("'opencode-rag index'")}.`);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
//# sourceMappingURL=workspace.js.map
|
package/dist/cli.d.ts
CHANGED
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
/** Main CLI runner and auto-launch detection. */
|
|
6
6
|
export { runCli, shouldAutoRunCli } from "./cli/index.js";
|
|
7
7
|
/** Cleanup helper that removes stale global plugin registration symlinks. */
|
|
8
|
-
export { removeStaleGlobalPluginRegistrations } from "./cli/commands/
|
|
8
|
+
export { removeStaleGlobalPluginRegistrations } from "./cli/commands/workspace-helpers.js";
|
package/dist/cli.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
/** Main CLI runner and auto-launch detection. */
|
|
6
6
|
export { runCli, shouldAutoRunCli } from "./cli/index.js";
|
|
7
7
|
/** Cleanup helper that removes stale global plugin registration symlinks. */
|
|
8
|
-
export { removeStaleGlobalPluginRegistrations } from "./cli/commands/
|
|
8
|
+
export { removeStaleGlobalPluginRegistrations } from "./cli/commands/workspace-helpers.js";
|
|
9
9
|
//# sourceMappingURL=cli.js.map
|
package/dist/core/config.d.ts
CHANGED
|
@@ -825,9 +825,9 @@ export declare function validateConfig(config: RagConfig): ConfigValidationResul
|
|
|
825
825
|
* Config file locations to search, in order of precedence.
|
|
826
826
|
*
|
|
827
827
|
* `.opencode/opencode-rag.json` is the canonical workspace location — every
|
|
828
|
-
* writer (TUI, `
|
|
828
|
+
* writer (TUI, `setup`, `clickhouse setup`, the Web UI) creates and updates it
|
|
829
829
|
* there. The root-level `opencode-rag.json` is the legacy location, still read
|
|
830
|
-
* for compatibility (and migrated into `.opencode/` by `opencode-rag
|
|
830
|
+
* for compatibility (and migrated into `.opencode/` by `opencode-rag setup`);
|
|
831
831
|
* `.opencode/rag.json` is a legacy alias inside `.opencode/`.
|
|
832
832
|
*/
|
|
833
833
|
export declare const CONFIG_FILE_CANDIDATES: string[];
|
package/dist/core/config.js
CHANGED
|
@@ -707,9 +707,9 @@ export function validateConfig(config) {
|
|
|
707
707
|
* Config file locations to search, in order of precedence.
|
|
708
708
|
*
|
|
709
709
|
* `.opencode/opencode-rag.json` is the canonical workspace location — every
|
|
710
|
-
* writer (TUI, `
|
|
710
|
+
* writer (TUI, `setup`, `clickhouse setup`, the Web UI) creates and updates it
|
|
711
711
|
* there. The root-level `opencode-rag.json` is the legacy location, still read
|
|
712
|
-
* for compatibility (and migrated into `.opencode/` by `opencode-rag
|
|
712
|
+
* for compatibility (and migrated into `.opencode/` by `opencode-rag setup`);
|
|
713
713
|
* `.opencode/rag.json` is a legacy alias inside `.opencode/`.
|
|
714
714
|
*/
|
|
715
715
|
export const CONFIG_FILE_CANDIDATES = [
|
|
@@ -21,3 +21,5 @@ export declare function getProviderDefault(provider: string): ProviderDefaults |
|
|
|
21
21
|
export declare function isOpenAiCompatible(provider: string): boolean;
|
|
22
22
|
/** Whether the given provider can produce embeddings. */
|
|
23
23
|
export declare function supportsEmbedding(provider: string): boolean;
|
|
24
|
+
/** Whether the given provider can serve chat/completion requests. */
|
|
25
|
+
export declare function supportsChat(provider: string): boolean;
|
|
@@ -103,4 +103,8 @@ export function isOpenAiCompatible(provider) {
|
|
|
103
103
|
export function supportsEmbedding(provider) {
|
|
104
104
|
return PROVIDER_DEFAULTS[provider]?.supportsEmbedding ?? false;
|
|
105
105
|
}
|
|
106
|
+
/** Whether the given provider can serve chat/completion requests. */
|
|
107
|
+
export function supportsChat(provider) {
|
|
108
|
+
return PROVIDER_DEFAULTS[provider]?.supportsChat ?? false;
|
|
109
|
+
}
|
|
106
110
|
//# sourceMappingURL=provider-defaults.js.map
|
package/dist/eval/fast-index.js
CHANGED
|
@@ -43,7 +43,7 @@ const INCLUDE_EXTS = new Set([".ts", ".tsx"]);
|
|
|
43
43
|
const CHANGED_FILES = new Set([
|
|
44
44
|
"src/api.ts",
|
|
45
45
|
"src/chunker/pdf.ts",
|
|
46
|
-
"src/cli/commands/
|
|
46
|
+
"src/cli/commands/workspace-helpers.ts",
|
|
47
47
|
"src/core/config.ts",
|
|
48
48
|
"src/core/interfaces.ts",
|
|
49
49
|
"src/core/manifest.ts",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Single source of truth for the mandatory OpenCodeRAG tool-usage guidance
|
|
3
3
|
* that is injected into both the runtime system prompt (via plugin.ts) and the AGENTS.md
|
|
4
|
-
* directive (via
|
|
4
|
+
* directive (via workspace-helpers.ts).
|
|
5
5
|
*/
|
|
6
6
|
import type { OpenCodeShellConfig } from "../core/config.js";
|
|
7
7
|
/** Sentinel marker that opens the managed section. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Single source of truth for the mandatory OpenCodeRAG tool-usage guidance
|
|
3
3
|
* that is injected into both the runtime system prompt (via plugin.ts) and the AGENTS.md
|
|
4
|
-
* directive (via
|
|
4
|
+
* directive (via workspace-helpers.ts).
|
|
5
5
|
*/
|
|
6
6
|
/** Sentinel marker that opens the managed section. */
|
|
7
7
|
export const BEGIN_MARKER = "<!-- BEGIN opencode-rag -->";
|
package/dist/plugin.d.ts
CHANGED
|
@@ -9,6 +9,19 @@ import { type RagConfig } from "./core/config.js";
|
|
|
9
9
|
import { createEmbedder } from "./embedder/factory.js";
|
|
10
10
|
import { StateSync } from "./core/state-sync.js";
|
|
11
11
|
import { retrieve } from "./retriever/retriever.js";
|
|
12
|
+
/**
|
|
13
|
+
* Describe where a workspace's effective config is read from.
|
|
14
|
+
*
|
|
15
|
+
* Slash-command gates (`/doc`, `/wiki`, `/quirk`) report "not enabled" from a
|
|
16
|
+
* config object, and without provenance the report is not actionable: a
|
|
17
|
+
* higher-precedence layer (`.opencode/opencode-rag.json`) silently shadows the
|
|
18
|
+
* root file, and a plugin that booted before an edit keeps serving its startup
|
|
19
|
+
* snapshot. Printed in the command's response and in the plugin log.
|
|
20
|
+
*
|
|
21
|
+
* @param directory - Workspace directory the plugin was loaded for.
|
|
22
|
+
* @returns One line naming the directory and both config layers (`none` when absent).
|
|
23
|
+
*/
|
|
24
|
+
export declare function describeConfigSource(directory: string): string;
|
|
12
25
|
/**
|
|
13
26
|
* Load the RAG configuration for a directory: DEFAULT_CONFIG, then the global
|
|
14
27
|
* layer (`~/.config/opencode/opencode-rag.json`), then the first workspace
|
package/dist/plugin.js
CHANGED
|
@@ -242,6 +242,22 @@ function configStamp(paths) {
|
|
|
242
242
|
paths.workspace ? `${paths.workspace}:${configFileMtime(paths.workspace)}` : "",
|
|
243
243
|
].join("|");
|
|
244
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Describe where a workspace's effective config is read from.
|
|
247
|
+
*
|
|
248
|
+
* Slash-command gates (`/doc`, `/wiki`, `/quirk`) report "not enabled" from a
|
|
249
|
+
* config object, and without provenance the report is not actionable: a
|
|
250
|
+
* higher-precedence layer (`.opencode/opencode-rag.json`) silently shadows the
|
|
251
|
+
* root file, and a plugin that booted before an edit keeps serving its startup
|
|
252
|
+
* snapshot. Printed in the command's response and in the plugin log.
|
|
253
|
+
*
|
|
254
|
+
* @param directory - Workspace directory the plugin was loaded for.
|
|
255
|
+
* @returns One line naming the directory and both config layers (`none` when absent).
|
|
256
|
+
*/
|
|
257
|
+
export function describeConfigSource(directory) {
|
|
258
|
+
const paths = resolveConfigPaths(directory);
|
|
259
|
+
return `directory: ${directory}; workspace: ${paths.workspace ?? "none"}; global: ${paths.global ?? "none"}`;
|
|
260
|
+
}
|
|
245
261
|
/**
|
|
246
262
|
* Load the RAG configuration for a directory: DEFAULT_CONFIG, then the global
|
|
247
263
|
* layer (`~/.config/opencode/opencode-rag.json`), then the first workspace
|
|
@@ -670,6 +686,31 @@ export function createRagHooks(options) {
|
|
|
670
686
|
lastEffectiveCfgTime = Date.now();
|
|
671
687
|
return lastEffectiveCfg;
|
|
672
688
|
}
|
|
689
|
+
/**
|
|
690
|
+
* Config used by the slash-command gates (`/doc`, `/wiki`, `/quirk`).
|
|
691
|
+
*
|
|
692
|
+
* These are cold paths, so read the workspace config straight from disk
|
|
693
|
+
* instead of trusting the cached startup snapshot: the gate must agree with
|
|
694
|
+
* the file the user just edited, even when the plugin started before that
|
|
695
|
+
* edit. This matters because OpenCode V2 runs plugins inside a shared
|
|
696
|
+
* background service that survives TUI restarts, so "restart OpenCode" does
|
|
697
|
+
* not necessarily reload the plugin.
|
|
698
|
+
*
|
|
699
|
+
* Falls back to the effective config when the workspace has no config file
|
|
700
|
+
* or the file cannot be parsed (the last known config keeps serving).
|
|
701
|
+
*/
|
|
702
|
+
function slashCommandConfig() {
|
|
703
|
+
try {
|
|
704
|
+
const paths = resolveConfigPaths(options.worktree);
|
|
705
|
+
if (paths.workspace || paths.global) {
|
|
706
|
+
return applyRuntimeOverrides(loadWorkspaceConfig(options.worktree, false), cachedOverrides);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
catch {
|
|
710
|
+
// Unreadable/malformed config — fall through to the last known config.
|
|
711
|
+
}
|
|
712
|
+
return getEffectiveCfg();
|
|
713
|
+
}
|
|
673
714
|
// The embedder follows the live configuration: when the config file changes
|
|
674
715
|
// (new API key, baseUrl or model) the provider is rebuilt instead of
|
|
675
716
|
// keeping the one built at plugin setup.
|
|
@@ -1592,13 +1633,26 @@ export function createRagHooks(options) {
|
|
|
1592
1633
|
boundedSet(sessionLastMessage, input.sessionID, text, MAX_SESSION_MAP_SIZE);
|
|
1593
1634
|
// Handle /doc slash command
|
|
1594
1635
|
if (text.startsWith("/doc")) {
|
|
1595
|
-
|
|
1636
|
+
// Read the config from disk (cold path): the gate must agree with the
|
|
1637
|
+
// file the user just edited, not with a startup snapshot.
|
|
1638
|
+
const docMode = slashCommandConfig().documentationMode;
|
|
1596
1639
|
if (!docMode?.enabled) {
|
|
1640
|
+
const configSource = describeConfigSource(options.worktree);
|
|
1641
|
+
const configHint = resolveConfigPaths(options.worktree).workspace
|
|
1642
|
+
?? path.join(options.worktree, ".opencode", "opencode-rag.json");
|
|
1643
|
+
appendDebugLog(options.logFilePath, {
|
|
1644
|
+
scope: "chat.message",
|
|
1645
|
+
message: `Slash command /doc blocked: documentationMode.enabled is not true — ${configSource}`,
|
|
1646
|
+
}, options.logLevel);
|
|
1597
1647
|
const parts = output?.parts ?? output?.message?.parts;
|
|
1598
1648
|
if (Array.isArray(parts) && parts.length > 0) {
|
|
1599
1649
|
const first = parts[0];
|
|
1600
1650
|
if (typeof first.text === "string") {
|
|
1601
|
-
parts[0] = { ...first, text: "Documentation mode is not enabled
|
|
1651
|
+
parts[0] = { ...first, text: "Documentation mode is not enabled.\n\n" +
|
|
1652
|
+
`Set \`documentationMode.enabled\` to \`true\` in \`${configHint}\`.\n\n` +
|
|
1653
|
+
`Config resolution — ${configSource}.\n\n` +
|
|
1654
|
+
"If the file already says `true`, the running plugin is using a stale config — " +
|
|
1655
|
+
"restart the OpenCode service (`opencode service restart`) so the plugin reloads." };
|
|
1602
1656
|
}
|
|
1603
1657
|
}
|
|
1604
1658
|
return;
|
|
@@ -1676,13 +1730,13 @@ export function createRagHooks(options) {
|
|
|
1676
1730
|
}
|
|
1677
1731
|
// Handle /wiki slash command
|
|
1678
1732
|
if (text.startsWith("/wiki")) {
|
|
1679
|
-
const wikiMode =
|
|
1733
|
+
const wikiMode = slashCommandConfig().wikiMode;
|
|
1680
1734
|
if (!wikiMode?.enabled) {
|
|
1681
1735
|
const parts = output?.parts ?? output?.message?.parts;
|
|
1682
1736
|
if (Array.isArray(parts) && parts.length > 0) {
|
|
1683
1737
|
const first = parts[0];
|
|
1684
1738
|
if (typeof first.text === "string") {
|
|
1685
|
-
parts[0] = { ...first, text:
|
|
1739
|
+
parts[0] = { ...first, text: `Wiki mode is not enabled. Set \`wikiMode.enabled\` to \`true\` in opencode-rag.json. Config resolution — ${describeConfigSource(options.worktree)}.` };
|
|
1686
1740
|
}
|
|
1687
1741
|
}
|
|
1688
1742
|
return;
|
|
@@ -1734,13 +1788,13 @@ export function createRagHooks(options) {
|
|
|
1734
1788
|
}
|
|
1735
1789
|
// Handle /quirk slash command
|
|
1736
1790
|
if (text.startsWith("/quirk")) {
|
|
1737
|
-
const memoryCfg =
|
|
1791
|
+
const memoryCfg = slashCommandConfig().memory;
|
|
1738
1792
|
if (!memoryCfg?.enabled) {
|
|
1739
1793
|
const parts = output?.parts ?? output?.message?.parts;
|
|
1740
1794
|
if (Array.isArray(parts) && parts.length > 0) {
|
|
1741
1795
|
const first = parts[0];
|
|
1742
1796
|
if (typeof first.text === "string") {
|
|
1743
|
-
parts[0] = { ...first, text:
|
|
1797
|
+
parts[0] = { ...first, text: `Quirk memory is not enabled. Set \`memory.enabled\` to \`true\` in opencode-rag.json. Config resolution — ${describeConfigSource(options.worktree)}.` };
|
|
1744
1798
|
}
|
|
1745
1799
|
}
|
|
1746
1800
|
return;
|
|
@@ -1996,6 +2050,16 @@ export const ragPlugin = async (input, _options) => {
|
|
|
1996
2050
|
if (!cfg.openCode.enabled) {
|
|
1997
2051
|
return {};
|
|
1998
2052
|
}
|
|
2053
|
+
// Record WHICH config file produced this instance. Without it, a report like
|
|
2054
|
+
// "the config says documentationMode.enabled = true but /doc says it is off"
|
|
2055
|
+
// cannot be diagnosed from the log: the answer is either a different file
|
|
2056
|
+
// (layer shadowing) or a stale snapshot (plugin never reloaded).
|
|
2057
|
+
appendDebugLog(logFilePath, {
|
|
2058
|
+
scope: "config",
|
|
2059
|
+
message: `Config: ${describeConfigSource(input.directory)}; ` +
|
|
2060
|
+
`documentationMode.enabled=${cfg.documentationMode?.enabled === true}; ` +
|
|
2061
|
+
`wikiMode.enabled=${cfg.wikiMode?.enabled === true}`,
|
|
2062
|
+
}, logLevel);
|
|
1999
2063
|
const storePath = path.resolve(input.directory, cfg.vectorStore.path);
|
|
2000
2064
|
// Apply runtime overrides before creating services
|
|
2001
2065
|
const overrides = loadRuntimeOverrides(storePath);
|
|
@@ -2048,8 +2112,13 @@ export const ragPlugin = async (input, _options) => {
|
|
|
2048
2112
|
}
|
|
2049
2113
|
ragStores.delete(input.directory);
|
|
2050
2114
|
}
|
|
2051
|
-
// Clean up
|
|
2052
|
-
|
|
2115
|
+
// Clean up pending update info for this directory.
|
|
2116
|
+
//
|
|
2117
|
+
// Do NOT drop the config cache entry here: `getConfig` above just stored it,
|
|
2118
|
+
// and that entry is what makes `refreshConfig` re-read the file on every
|
|
2119
|
+
// later mtime change. Deleting it pinned the whole plugin to its startup
|
|
2120
|
+
// snapshot for the lifetime of the (long-lived, shared) OpenCode service —
|
|
2121
|
+
// a config edit was then never picked up, not even by `getEffectiveCfg()`.
|
|
2053
2122
|
pendingUpdateInfo.delete(input.directory);
|
|
2054
2123
|
pendingRestartNotice.delete(input.directory);
|
|
2055
2124
|
notifiedUpdateDirs.delete(input.directory);
|
package/dist/tui.d.ts
CHANGED
|
@@ -82,6 +82,17 @@ type V2TuiContext = {
|
|
|
82
82
|
id: string;
|
|
83
83
|
title?: string;
|
|
84
84
|
bind?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Adds the command to prompt slash completion (`KeymapCommand.slash`
|
|
87
|
+
* in `@opencode/plugin/tui`). The name has no leading slash; a command
|
|
88
|
+
* needs a stable `id` to be slash-addressable.
|
|
89
|
+
*/
|
|
90
|
+
slash?: {
|
|
91
|
+
name: string;
|
|
92
|
+
aliases?: string[];
|
|
93
|
+
/** Keeps the slash command in the prompt and passes its raw input to run. */
|
|
94
|
+
arguments?: true;
|
|
95
|
+
};
|
|
85
96
|
run: (input?: string) => void;
|
|
86
97
|
}[];
|
|
87
98
|
bindings: readonly string[];
|
package/dist/tui.js
CHANGED
|
@@ -162,6 +162,15 @@ function formatKeybinding(key) {
|
|
|
162
162
|
* Kitty keyboard protocol is negotiated. Exactly one chord is bound.
|
|
163
163
|
*/
|
|
164
164
|
const DEFAULT_SETTINGS_KEYBINDING = "alt+s";
|
|
165
|
+
/**
|
|
166
|
+
* Prompt slash name for the settings dialog (no leading slash — the host adds
|
|
167
|
+
* it). A slash path matters because key delivery is terminal-dependent: VTE
|
|
168
|
+
* collapses `ctrl+shift+<letter>` to the plain control byte and VS Code's
|
|
169
|
+
* xterm sends nothing until the Kitty keyboard protocol is negotiated, while
|
|
170
|
+
* text input works everywhere. `tui.settingsKeybinding` stays the shortcut;
|
|
171
|
+
* this is the fallback that is also discoverable from `/` completion.
|
|
172
|
+
*/
|
|
173
|
+
const SETTINGS_SLASH_NAME = "rag-settings";
|
|
165
174
|
const PLUGIN_NAME = "opencode-rag-plugin";
|
|
166
175
|
/**
|
|
167
176
|
* Create a TUI element node with the given tag, props, and children.
|
|
@@ -243,7 +252,7 @@ function renderSidebar(theme, version, status, tuiConfig, tokenStats) {
|
|
|
243
252
|
text({ fg: theme.textMuted }, [timeLine]),
|
|
244
253
|
text({ fg: watcher.running ? theme.accent : watcherStale ? theme.text : theme.textMuted }, [watcherLine]),
|
|
245
254
|
...(watcherDetail ? [text({ fg: theme.textMuted }, [watcherDetail])] : []),
|
|
246
|
-
text({ fg: theme.textMuted }, [`${formatKeybinding(settingsKey)} → Settings`]),
|
|
255
|
+
text({ fg: theme.textMuted }, [`${formatKeybinding(settingsKey)} / /${SETTINGS_SLASH_NAME} → Settings`]),
|
|
247
256
|
text({ fg: theme.textMuted }, [`${formatKeybinding(fileListKey)} → Add File List`]),
|
|
248
257
|
text({ fg: theme.textMuted }, [`${formatKeybinding(chunksKey)} → Add Chunks`]),
|
|
249
258
|
...(tokenStats && tokenStats.queries > 0 ? [
|
|
@@ -1000,6 +1009,8 @@ async function setup(context) {
|
|
|
1000
1009
|
id: "opencode-rag:settings",
|
|
1001
1010
|
title: "OpenCodeRAG Settings",
|
|
1002
1011
|
bind: v2Bind(settingsKey),
|
|
1012
|
+
// Also in prompt slash completion: `/rag-settings` (alias `/rag`).
|
|
1013
|
+
slash: { name: SETTINGS_SLASH_NAME, aliases: ["rag"] },
|
|
1003
1014
|
run: () => {
|
|
1004
1015
|
if (worktree) {
|
|
1005
1016
|
void openSettingsDialogV2(context, worktree, v2LegacyProviders(context), () => refreshStatus());
|