opencode-rag-plugin 2.12.0 → 2.12.2
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 +282 -216
- package/dist/cli/commands/quirk.js +1 -0
- package/dist/cli/commands/setup.js +83 -10
- package/dist/cli/commands/workspace-helpers.js +3 -0
- package/dist/cli/ollama.d.ts +12 -0
- package/dist/cli/ollama.js +26 -0
- package/dist/cli/prompt.d.ts +37 -0
- package/dist/cli/prompt.js +83 -21
- package/dist/cli/types.d.ts +19 -6
- package/dist/cli/wizard/apply.d.ts +4 -2
- package/dist/cli/wizard/apply.js +12 -3
- package/dist/cli/wizard/flow.d.ts +39 -1
- package/dist/cli/wizard/flow.js +155 -10
- package/dist/cli/wizard/presets.d.ts +55 -0
- package/dist/cli/wizard/presets.js +70 -0
- package/dist/cli/wizard/repair.d.ts +54 -0
- package/dist/cli/wizard/repair.js +266 -0
- package/dist/cli/wizard/types.d.ts +5 -0
- package/dist/cli/workspace.d.ts +24 -7
- package/dist/cli/workspace.js +168 -83
- package/dist/core/auto-scaffold.d.ts +21 -0
- package/dist/core/auto-scaffold.js +80 -0
- package/dist/core/config.d.ts +11 -0
- package/dist/core/config.js +11 -1
- package/dist/core/global-plugin.d.ts +48 -0
- package/dist/core/global-plugin.js +114 -0
- package/dist/core/setup-runtime.js +40 -26
- package/dist/embedder/health.js +44 -2
- package/dist/opencode/tools.js +4 -2
- package/dist/v2/v2-adapter.js +9 -0
- package/package.json +3 -2
- package/scripts/postinstall-setup.js +16 -0
package/dist/cli/workspace.js
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Workspace scaffolding shared by `opencode-rag setup`.
|
|
3
3
|
*
|
|
4
|
-
* Creates/updates the `.opencode/` tree, plugin entrypoints
|
|
5
|
-
* `AGENTS.md` guidance and the workspace `package.json`. Configuration
|
|
6
|
-
* written separately (see `src/cli/wizard/apply.ts`) so the wizard can
|
|
7
|
-
* what goes into the workspace file before `AGENTS.md` is rendered from
|
|
8
|
-
* effective `decision`/`memory` flags.
|
|
4
|
+
* Creates/updates the `.opencode/` tree, plugin entrypoints (workspace mode),
|
|
5
|
+
* skills, `AGENTS.md` guidance and the workspace `package.json`. Configuration
|
|
6
|
+
* is written separately (see `src/cli/wizard/apply.ts`) so the wizard can
|
|
7
|
+
* decide what goes into the workspace file before `AGENTS.md` is rendered from
|
|
8
|
+
* the effective `decision`/`memory` flags.
|
|
9
|
+
*
|
|
10
|
+
* By default the plugin is installed ONCE in OpenCode's global plugin
|
|
11
|
+
* directory (`~/.config/opencode/plugins/opencode-rag/`), so a workspace only
|
|
12
|
+
* receives the config, skills, `AGENTS.md` and the `.gitignore` that protects
|
|
13
|
+
* its local LanceDB store. `workspacePlugin: true` restores the legacy
|
|
14
|
+
* per-repository plugin layout.
|
|
9
15
|
*/
|
|
10
16
|
import path from "node:path";
|
|
11
|
-
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, rmSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
12
18
|
import { loadConfig, loadWorkspaceConfig, configuredSections, findConfigFile, projectConfigPath } from "../core/config.js";
|
|
19
|
+
import { resolveApiKey } from "../core/resolve-api-key.js";
|
|
13
20
|
import { checkProviderHealth, pullOllamaModels } from "../embedder/health.js";
|
|
14
21
|
import { c } from "./format.js";
|
|
15
22
|
import { getPackageMetadata, readJsonObject, writeJsonFile } from "./helpers.js";
|
|
23
|
+
import { isOllamaConnectionError, ollamaInstallHint } from "./ollama.js";
|
|
16
24
|
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
25
|
/**
|
|
18
26
|
* Best-effort check whether `cwd` looks like a project root (git repo or
|
|
@@ -35,6 +43,47 @@ export function isLikelyProjectRoot(cwd) {
|
|
|
35
43
|
];
|
|
36
44
|
return markers.some((marker) => existsSync(path.join(cwd, marker)));
|
|
37
45
|
}
|
|
46
|
+
/** Remove a file only when its content matches exactly what setup generates. */
|
|
47
|
+
function removeGeneratedFile(filePath, expected, label) {
|
|
48
|
+
if (!existsSync(filePath))
|
|
49
|
+
return false;
|
|
50
|
+
try {
|
|
51
|
+
if (readFileSync(filePath, "utf-8") !== expected) {
|
|
52
|
+
console.log(` ${c.warn("Kept:")} ${label} (modified locally)`);
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
unlinkSync(filePath);
|
|
56
|
+
console.log(` ${c.updated("Removed:")} ${label} (superseded by the global plugin)`);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** Remove a junction created by a previous workspace-mode install. */
|
|
64
|
+
function removeJunction(linkPath, label) {
|
|
65
|
+
if (!existsSync(linkPath))
|
|
66
|
+
return;
|
|
67
|
+
try {
|
|
68
|
+
if (!lstatSync(linkPath).isSymbolicLink())
|
|
69
|
+
return;
|
|
70
|
+
rmSync(linkPath, { recursive: true, force: true });
|
|
71
|
+
console.log(` ${c.updated("Removed:")} ${label} (global plugin mode)`);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// Leave it; a stale link is harmless next to the global plugin.
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** Remove a directory when it is empty. */
|
|
78
|
+
function removeIfEmpty(dirPath) {
|
|
79
|
+
try {
|
|
80
|
+
if (existsSync(dirPath) && readdirSync(dirPath).length === 0)
|
|
81
|
+
rmSync(dirPath, { recursive: true });
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// ignore
|
|
85
|
+
}
|
|
86
|
+
}
|
|
38
87
|
/**
|
|
39
88
|
* Create or refresh the workspace files.
|
|
40
89
|
*
|
|
@@ -45,6 +94,7 @@ export async function scaffoldWorkspace(options = {}) {
|
|
|
45
94
|
const cwd = process.cwd();
|
|
46
95
|
const packageMetadata = getPackageMetadata();
|
|
47
96
|
const configPath = options.configPath ?? findConfigFile(cwd) ?? projectConfigPath(cwd);
|
|
97
|
+
const workspacePlugin = options.workspacePlugin ?? false;
|
|
48
98
|
const opencodeDir = path.join(cwd, ".opencode");
|
|
49
99
|
const gitignorePath = path.join(opencodeDir, ".gitignore");
|
|
50
100
|
const opencodeConfigPath = path.join(opencodeDir, "opencode.json");
|
|
@@ -56,6 +106,8 @@ export async function scaffoldWorkspace(options = {}) {
|
|
|
56
106
|
const legacyTuiPluginEntryPath = path.join(pluginsDir, "rag-tui.js");
|
|
57
107
|
const legacyTuiConfigPath = path.join(opencodeDir, "tui.json");
|
|
58
108
|
const opencodePackagePath = path.join(opencodeDir, "package.json");
|
|
109
|
+
const runtimePluginLink = path.join(opencodeDir, "node_modules", packageMetadata.name);
|
|
110
|
+
const runtimeSdkLink = path.join(opencodeDir, "node_modules", "@opencode-ai", "plugin");
|
|
59
111
|
console.log(`\n${c.heading("Workspace files")}\n`);
|
|
60
112
|
if (!existsSync(opencodeDir)) {
|
|
61
113
|
mkdirSync(opencodeDir, { recursive: true });
|
|
@@ -69,13 +121,6 @@ export async function scaffoldWorkspace(options = {}) {
|
|
|
69
121
|
if (existsSync(wikiDir)) {
|
|
70
122
|
console.log(` ${c.exists("Preserved:")} .opencode/wiki/ (never modified by setup)`);
|
|
71
123
|
}
|
|
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
124
|
const gitignoreExists = existsSync(gitignorePath);
|
|
80
125
|
const nextGitignoreContent = mergeGitignoreContent(gitignoreExists ? readFileSync(gitignorePath, "utf-8") : undefined);
|
|
81
126
|
if (!gitignoreExists || options.force || readFileSync(gitignorePath, "utf-8") !== nextGitignoreContent) {
|
|
@@ -85,51 +130,75 @@ export async function scaffoldWorkspace(options = {}) {
|
|
|
85
130
|
else {
|
|
86
131
|
console.log(` ${c.exists("Exists:")} .opencode/.gitignore`);
|
|
87
132
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
133
|
+
if (workspacePlugin) {
|
|
134
|
+
// ── Legacy per-repository plugin layout ──────────────────────────────
|
|
135
|
+
if (!existsSync(pluginsDir)) {
|
|
136
|
+
mkdirSync(pluginsDir, { recursive: true });
|
|
137
|
+
console.log(` ${c.created("Created:")} .opencode/plugins/`);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
console.log(` ${c.exists("Exists:")} .opencode/plugins/`);
|
|
141
|
+
}
|
|
142
|
+
const opencodeConfigExists = existsSync(opencodeConfigPath);
|
|
143
|
+
const nextOpencodeConfig = buildOpencodeConfig(readJsonObject(opencodeConfigPath));
|
|
144
|
+
if (!opencodeConfigExists || options.force) {
|
|
145
|
+
writeJsonFile(opencodeConfigPath, nextOpencodeConfig);
|
|
146
|
+
console.log(` ${opencodeConfigExists ? c.updated("Updated:") : c.created("Created:")} .opencode/opencode.json`);
|
|
147
|
+
}
|
|
148
|
+
else if (JSON.stringify(readJsonObject(opencodeConfigPath)) !== JSON.stringify(nextOpencodeConfig)) {
|
|
149
|
+
writeJsonFile(opencodeConfigPath, nextOpencodeConfig);
|
|
150
|
+
console.log(` ${c.updated("Updated:")} .opencode/opencode.json`);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
console.log(` ${c.exists("Exists:")} .opencode/opencode.json`);
|
|
154
|
+
}
|
|
155
|
+
// OpenCode 2 discovers plugin *directories* under `.opencode/plugins/`:
|
|
156
|
+
// `index.js` is the server entrypoint and `tui.js` beside it is the CLI
|
|
157
|
+
// entrypoint. Flat `.js` files only reach the server role.
|
|
158
|
+
if (!existsSync(workspacePluginDir)) {
|
|
159
|
+
mkdirSync(workspacePluginDir, { recursive: true });
|
|
160
|
+
console.log(` ${c.created("Created:")} .opencode/plugins/${WORKSPACE_PLUGIN_DIR}/`);
|
|
161
|
+
}
|
|
162
|
+
const pluginEntryExists = existsSync(pluginEntryPath);
|
|
163
|
+
const pluginEntryContent = generateWorkspacePluginFile(packageMetadata.name);
|
|
164
|
+
if (!pluginEntryExists || options.force) {
|
|
165
|
+
writeFileSync(pluginEntryPath, pluginEntryContent, "utf-8");
|
|
166
|
+
console.log(` ${pluginEntryExists ? c.updated("Updated:") : c.created("Created:")} ${WORKSPACE_PLUGIN_ENTRY}`);
|
|
167
|
+
}
|
|
168
|
+
else if (readFileSync(pluginEntryPath, "utf-8") !== pluginEntryContent) {
|
|
169
|
+
writeFileSync(pluginEntryPath, pluginEntryContent, "utf-8");
|
|
170
|
+
console.log(` ${c.updated("Updated:")} ${WORKSPACE_PLUGIN_ENTRY}`);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
console.log(` ${c.exists("Exists:")} ${WORKSPACE_PLUGIN_ENTRY}`);
|
|
174
|
+
}
|
|
175
|
+
const tuiPluginEntryExists = existsSync(tuiPluginEntryPath);
|
|
176
|
+
const tuiPluginEntryContent = generateWorkspaceTuiPluginFile(packageMetadata.name);
|
|
177
|
+
if (!tuiPluginEntryExists || options.force) {
|
|
178
|
+
writeFileSync(tuiPluginEntryPath, tuiPluginEntryContent, "utf-8");
|
|
179
|
+
console.log(` ${tuiPluginEntryExists ? c.updated("Updated:") : c.created("Created:")} ${WORKSPACE_TUI_ENTRY}`);
|
|
180
|
+
}
|
|
181
|
+
else if (readFileSync(tuiPluginEntryPath, "utf-8") !== tuiPluginEntryContent) {
|
|
182
|
+
writeFileSync(tuiPluginEntryPath, tuiPluginEntryContent, "utf-8");
|
|
183
|
+
console.log(` ${c.updated("Updated:")} ${WORKSPACE_TUI_ENTRY}`);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
console.log(` ${c.exists("Exists:")} ${WORKSPACE_TUI_ENTRY}`);
|
|
187
|
+
}
|
|
130
188
|
}
|
|
131
189
|
else {
|
|
132
|
-
|
|
190
|
+
// ── Global plugin layout (default) ────────────────────────────────────
|
|
191
|
+
// Remove the entries an older workspace-mode setup generated. Only exact
|
|
192
|
+
// matches are removed; hand-written files are kept.
|
|
193
|
+
removeGeneratedFile(pluginEntryPath, generateWorkspacePluginFile(packageMetadata.name), WORKSPACE_PLUGIN_ENTRY);
|
|
194
|
+
removeGeneratedFile(tuiPluginEntryPath, generateWorkspaceTuiPluginFile(packageMetadata.name), WORKSPACE_TUI_ENTRY);
|
|
195
|
+
removeIfEmpty(workspacePluginDir);
|
|
196
|
+
removeIfEmpty(pluginsDir);
|
|
197
|
+
removeJunction(runtimePluginLink, `.opencode/node_modules/${packageMetadata.name}`);
|
|
198
|
+
removeJunction(runtimeSdkLink, ".opencode/node_modules/@opencode-ai/plugin");
|
|
199
|
+
removeIfEmpty(path.join(opencodeDir, "node_modules", "@opencode-ai"));
|
|
200
|
+
removeIfEmpty(path.join(opencodeDir, "node_modules"));
|
|
201
|
+
console.log(` ${c.success("Plugin:")} global (~/.config/opencode/plugins/opencode-rag/)`);
|
|
133
202
|
}
|
|
134
203
|
// Remove only the V1-era flat entries that an older `init` wrote verbatim;
|
|
135
204
|
// modified files are kept (they are no longer loaded by OpenCode 2).
|
|
@@ -225,27 +294,29 @@ export async function scaffoldWorkspace(options = {}) {
|
|
|
225
294
|
else {
|
|
226
295
|
console.log(` ${c.exists("Exists:")} AGENTS.md`);
|
|
227
296
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
297
|
+
if (workspacePlugin) {
|
|
298
|
+
const workspacePackageExists = existsSync(opencodePackagePath);
|
|
299
|
+
const nextWorkspacePackage = buildWorkspacePackageJson(readJsonObject(opencodePackagePath), packageMetadata);
|
|
300
|
+
if (!workspacePackageExists || options.force) {
|
|
301
|
+
writeJsonFile(opencodePackagePath, nextWorkspacePackage);
|
|
302
|
+
console.log(` ${workspacePackageExists ? c.updated("Updated:") : c.created("Created:")} .opencode/package.json`);
|
|
303
|
+
}
|
|
304
|
+
else if (JSON.stringify(readJsonObject(opencodePackagePath)) !== JSON.stringify(nextWorkspacePackage)) {
|
|
305
|
+
writeJsonFile(opencodePackagePath, nextWorkspacePackage);
|
|
306
|
+
console.log(` ${c.updated("Updated:")} .opencode/package.json`);
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
console.log(` ${c.exists("Exists:")} .opencode/package.json`);
|
|
310
|
+
}
|
|
311
|
+
if (options.skipInstall) {
|
|
312
|
+
console.log(`\n ${c.exists("Skipped:")} plugin installation (--skip-install)`);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
console.log(`\n${c.heading("Installing workspace-local plugin...")}\n`);
|
|
316
|
+
await installPluginFromGlobal(opencodeDir, packageMetadata.name, false);
|
|
317
|
+
console.log(`\n ${c.success("Installed:")} .opencode/node_modules/`);
|
|
318
|
+
console.log(` ${c.dim("Plugin is linked to the global runtime cache; no npm install was required.")}`);
|
|
244
319
|
}
|
|
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
320
|
}
|
|
250
321
|
/**
|
|
251
322
|
* Check provider connectivity and offer to pull missing Ollama models.
|
|
@@ -253,10 +324,17 @@ export async function scaffoldWorkspace(options = {}) {
|
|
|
253
324
|
* Uses the effective config (global < workspace) so models chosen in the
|
|
254
325
|
* wizard are probed even though most provider settings live in the global
|
|
255
326
|
* file.
|
|
327
|
+
*
|
|
328
|
+
* @param options.autoPull Pull missing models without a second confirmation
|
|
329
|
+
* (used by the one-question recommended setup).
|
|
256
330
|
*/
|
|
257
|
-
export async function runWorkspaceHealthCheck(cwd, prompter) {
|
|
331
|
+
export async function runWorkspaceHealthCheck(cwd, prompter, options = {}) {
|
|
258
332
|
console.log(`\n${c.heading("Checking provider connectivity...")}\n`);
|
|
259
333
|
const ragConfig = loadWorkspaceConfig(cwd);
|
|
334
|
+
// Resolve keys the way the runtime does (env vars, OpenCode provider config,
|
|
335
|
+
// auth store). Without this an on-demand override with no own key inherits
|
|
336
|
+
// the indexing section's key and reports a misleading 401.
|
|
337
|
+
resolveApiKey(ragConfig, cwd);
|
|
260
338
|
const results = await checkProviderHealth(ragConfig, configuredSections(cwd));
|
|
261
339
|
for (const result of results) {
|
|
262
340
|
const icon = result.status === "ok" ? c.success("✓") : result.status === "missing" ? c.warn("○") : c.error("✗");
|
|
@@ -269,6 +347,10 @@ export async function runWorkspaceHealthCheck(cwd, prompter) {
|
|
|
269
347
|
if (result.error)
|
|
270
348
|
console.log(` ${c.dim(result.error)}`);
|
|
271
349
|
}
|
|
350
|
+
if (results.some((result) => result.provider === "ollama" && result.status === "error" && isOllamaConnectionError(result.error))) {
|
|
351
|
+
console.log(`\n ${c.warn("Ollama is not reachable.")} ${c.dim(ollamaInstallHint())}`);
|
|
352
|
+
console.log(` ${c.dim("Start it with: ollama serve")}`);
|
|
353
|
+
}
|
|
272
354
|
const missingOllama = results.filter((result) => result.status === "missing" && result.provider === "ollama");
|
|
273
355
|
if (missingOllama.length > 0) {
|
|
274
356
|
const pullEntries = missingOllama.map((result) => {
|
|
@@ -292,12 +374,14 @@ export async function runWorkspaceHealthCheck(cwd, prompter) {
|
|
|
292
374
|
return { model: result.model, baseUrl: ragConfig.embedding.baseUrl, proxy: ragConfig.embedding.proxy };
|
|
293
375
|
});
|
|
294
376
|
console.log(`\n ${c.warn("Models not found:")} ${pullEntries.map((entry) => entry.model).join(", ")}`);
|
|
295
|
-
const pull =
|
|
296
|
-
?
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
377
|
+
const pull = options.autoPull
|
|
378
|
+
? true
|
|
379
|
+
: prompter.interactive
|
|
380
|
+
? await prompter.confirm({
|
|
381
|
+
message: `Pull ${pullEntries.length === 1 ? "this model" : "these models"} now?`,
|
|
382
|
+
defaultValue: missingOllama.some((result) => result.type === "embedding"),
|
|
383
|
+
})
|
|
384
|
+
: false;
|
|
301
385
|
if (pull) {
|
|
302
386
|
console.log();
|
|
303
387
|
try {
|
|
@@ -318,5 +402,6 @@ export async function runWorkspaceHealthCheck(cwd, prompter) {
|
|
|
318
402
|
if (results.some((result) => result.status === "error")) {
|
|
319
403
|
console.log(`\n ${c.warn("Some providers are not reachable.")} Check configuration and network, then run ${c.file("'opencode-rag index'")}.`);
|
|
320
404
|
}
|
|
405
|
+
return results;
|
|
321
406
|
}
|
|
322
407
|
//# sourceMappingURL=workspace.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Create-only workspace scaffolding for the OpenCode plugin.
|
|
3
|
+
*
|
|
4
|
+
* With the plugin installed globally, a repository does not need a CLI run
|
|
5
|
+
* before it works: on first load the plugin creates the missing workspace
|
|
6
|
+
* files itself (config, skills, `AGENTS.md`, `.gitignore`). Existing files are
|
|
7
|
+
* never overwritten, and `setup.autoScaffold: false` disables the behaviour.
|
|
8
|
+
*/
|
|
9
|
+
/** Result of {@link autoScaffoldWorkspace}. */
|
|
10
|
+
export interface AutoScaffoldResult {
|
|
11
|
+
/** Workspace-relative paths created during this call. */
|
|
12
|
+
created: string[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create the missing workspace files for `directory`.
|
|
16
|
+
*
|
|
17
|
+
* Only runs when no workspace config exists yet *or* the effective config
|
|
18
|
+
* still has `setup.autoScaffold` enabled. The function never overwrites an
|
|
19
|
+
* existing file and never throws (plugin load must not break).
|
|
20
|
+
*/
|
|
21
|
+
export declare function autoScaffoldWorkspace(directory: string): AutoScaffoldResult;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Create-only workspace scaffolding for the OpenCode plugin.
|
|
3
|
+
*
|
|
4
|
+
* With the plugin installed globally, a repository does not need a CLI run
|
|
5
|
+
* before it works: on first load the plugin creates the missing workspace
|
|
6
|
+
* files itself (config, skills, `AGENTS.md`, `.gitignore`). Existing files are
|
|
7
|
+
* never overwritten, and `setup.autoScaffold: false` disables the behaviour.
|
|
8
|
+
*/
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { findConfigFile, loadWorkspaceConfig, projectConfigPath } from "./config.js";
|
|
12
|
+
import { appendDebugLog } from "./fileLogger.js";
|
|
13
|
+
import { generateDecisionSkillFile, generateDefaultConfigJson, generateSkillFile, mergeAgentsMdContent, mergeGitignoreContent, } from "../cli/commands/workspace-helpers.js";
|
|
14
|
+
/** Write a file when it does not exist yet. */
|
|
15
|
+
function createIfMissing(filePath, content, created, relativeTo) {
|
|
16
|
+
if (existsSync(filePath))
|
|
17
|
+
return;
|
|
18
|
+
mkdirSync(path.dirname(filePath), { recursive: true });
|
|
19
|
+
writeFileSync(filePath, content, "utf-8");
|
|
20
|
+
created.push(path.relative(relativeTo, filePath).replace(/\\/g, "/"));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create the missing workspace files for `directory`.
|
|
24
|
+
*
|
|
25
|
+
* Only runs when no workspace config exists yet *or* the effective config
|
|
26
|
+
* still has `setup.autoScaffold` enabled. The function never overwrites an
|
|
27
|
+
* existing file and never throws (plugin load must not break).
|
|
28
|
+
*/
|
|
29
|
+
export function autoScaffoldWorkspace(directory) {
|
|
30
|
+
const created = [];
|
|
31
|
+
try {
|
|
32
|
+
const existingConfig = findConfigFile(directory);
|
|
33
|
+
if (existingConfig) {
|
|
34
|
+
try {
|
|
35
|
+
const cfg = loadWorkspaceConfig(directory, false);
|
|
36
|
+
if (cfg.setup?.autoScaffold === false)
|
|
37
|
+
return { created };
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// Malformed config: still fill in the missing files.
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const opencodeDir = path.join(directory, ".opencode");
|
|
44
|
+
const configPath = projectConfigPath(directory);
|
|
45
|
+
mkdirSync(opencodeDir, { recursive: true });
|
|
46
|
+
if (!existingConfig) {
|
|
47
|
+
createIfMissing(configPath, generateDefaultConfigJson(), created, directory);
|
|
48
|
+
}
|
|
49
|
+
createIfMissing(path.join(opencodeDir, ".gitignore"), mergeGitignoreContent(undefined), created, directory);
|
|
50
|
+
createIfMissing(path.join(opencodeDir, "skills", "opencode-rag", "SKILL.md"), generateSkillFile(), created, directory);
|
|
51
|
+
createIfMissing(path.join(opencodeDir, "skills", "make-decision", "SKILL.md"), generateDecisionSkillFile(), created, directory);
|
|
52
|
+
const agentsPath = path.join(directory, "AGENTS.md");
|
|
53
|
+
if (!existsSync(agentsPath)) {
|
|
54
|
+
let promptEnforcement = true;
|
|
55
|
+
let decisionEnabled = false;
|
|
56
|
+
let routeBeforeAsking = false;
|
|
57
|
+
try {
|
|
58
|
+
const cfg = loadWorkspaceConfig(directory, false);
|
|
59
|
+
promptEnforcement = cfg.memory?.promptEnforcement ?? true;
|
|
60
|
+
decisionEnabled = cfg.decision?.enabled ?? false;
|
|
61
|
+
routeBeforeAsking = cfg.decision?.routeBeforeAsking ?? false;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// Defaults.
|
|
65
|
+
}
|
|
66
|
+
createIfMissing(agentsPath, mergeAgentsMdContent(undefined, { promptEnforcement, decisionEnabled, routeBeforeAsking }), created, directory);
|
|
67
|
+
}
|
|
68
|
+
if (created.length > 0) {
|
|
69
|
+
appendDebugLog(path.join(opencodeDir, "opencode-rag.log"), {
|
|
70
|
+
scope: "setup",
|
|
71
|
+
message: `auto-scaffolded workspace files: ${created.join(", ")}`,
|
|
72
|
+
}, "info");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Never break plugin load because a workspace could not be scaffolded.
|
|
77
|
+
}
|
|
78
|
+
return { created };
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=auto-scaffold.js.map
|
package/dist/core/config.d.ts
CHANGED
|
@@ -479,6 +479,15 @@ export interface McpConfig {
|
|
|
479
479
|
/** Whether to auto-start the MCP server on plugin load. Default false — agent tools run in-process regardless. Set true only when an external MCP client needs to connect via `opencode-rag mcp`. */
|
|
480
480
|
enabled: boolean;
|
|
481
481
|
}
|
|
482
|
+
/** Configuration for workspace setup behaviour. */
|
|
483
|
+
export interface SetupConfig {
|
|
484
|
+
/**
|
|
485
|
+
* Create missing workspace files (config, skills, AGENTS.md) when the plugin
|
|
486
|
+
* loads in a repository that has not been set up yet. Create-only: existing
|
|
487
|
+
* files are never overwritten. Default true.
|
|
488
|
+
*/
|
|
489
|
+
autoScaffold: boolean;
|
|
490
|
+
}
|
|
482
491
|
/** Configuration for automatic self-updates. */
|
|
483
492
|
export interface AutoUpdateConfig {
|
|
484
493
|
/** Whether update checking is enabled (defaults to true). */
|
|
@@ -778,6 +787,8 @@ export interface RagConfig {
|
|
|
778
787
|
wikiMode?: WikiModeConfig;
|
|
779
788
|
/** MCP server integration config. */
|
|
780
789
|
mcp?: McpConfig;
|
|
790
|
+
/** Workspace setup behaviour (auto-scaffold). */
|
|
791
|
+
setup?: SetupConfig;
|
|
781
792
|
/** Auto-update checking config. */
|
|
782
793
|
autoUpdate?: AutoUpdateConfig;
|
|
783
794
|
/** Quirk memory config for experiential agent memory. */
|
package/dist/core/config.js
CHANGED
|
@@ -328,6 +328,9 @@ export const DEFAULT_CONFIG = {
|
|
|
328
328
|
mcp: {
|
|
329
329
|
enabled: false,
|
|
330
330
|
},
|
|
331
|
+
setup: {
|
|
332
|
+
autoScaffold: true,
|
|
333
|
+
},
|
|
331
334
|
autoUpdate: {
|
|
332
335
|
enabled: true,
|
|
333
336
|
autoInstall: false,
|
|
@@ -397,7 +400,7 @@ export function validateConfig(config) {
|
|
|
397
400
|
const KNOWN_TOP_KEYS = new Set([
|
|
398
401
|
"embedding", "indexing", "vectorStore", "retrieval", "reranking",
|
|
399
402
|
"openCode", "chunkers", "chunking", "description",
|
|
400
|
-
"imageDescription", "decision", "shellGuard", "documentationMode", "wikiMode", "mcp", "autoUpdate", "memory", "ui", "tui", "logging",
|
|
403
|
+
"imageDescription", "decision", "shellGuard", "documentationMode", "wikiMode", "mcp", "autoUpdate", "memory", "ui", "tui", "logging", "setup",
|
|
401
404
|
]);
|
|
402
405
|
const topKeys = new Set(Object.keys(config));
|
|
403
406
|
for (const key of topKeys) {
|
|
@@ -682,6 +685,9 @@ export function validateConfig(config) {
|
|
|
682
685
|
}
|
|
683
686
|
}
|
|
684
687
|
}
|
|
688
|
+
if (config.setup && typeof config.setup.autoScaffold !== "boolean") {
|
|
689
|
+
warnings.push("setup.autoScaffold must be a boolean");
|
|
690
|
+
}
|
|
685
691
|
if (config.reranking?.enabled) {
|
|
686
692
|
const rr = config.reranking;
|
|
687
693
|
if (!rr.baseUrl)
|
|
@@ -1068,6 +1074,10 @@ function buildConfig(parsed, validate) {
|
|
|
1068
1074
|
...DEFAULT_CONFIG.mcp,
|
|
1069
1075
|
...(safeObj(parsed.mcp) ?? {}),
|
|
1070
1076
|
},
|
|
1077
|
+
setup: {
|
|
1078
|
+
...DEFAULT_CONFIG.setup,
|
|
1079
|
+
...(safeObj(parsed.setup) ?? {}),
|
|
1080
|
+
},
|
|
1071
1081
|
autoUpdate: {
|
|
1072
1082
|
...DEFAULT_CONFIG.autoUpdate,
|
|
1073
1083
|
...(safeObj(parsed.autoUpdate) ?? {}),
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Global OpenCode plugin installation.
|
|
3
|
+
*
|
|
4
|
+
* OpenCode 2 loads plugins from `~/.config/opencode/plugins/` as well as from
|
|
5
|
+
* a workspace's `.opencode/plugins/`. Installing the RAG plugin once in the
|
|
6
|
+
* global directory removes the per-repository plugin entries, the
|
|
7
|
+
* `.opencode/node_modules` junction and the workspace `package.json`:
|
|
8
|
+
*
|
|
9
|
+
* ```
|
|
10
|
+
* ~/.config/opencode/plugins/opencode-rag/index.js (server role)
|
|
11
|
+
* ~/.config/opencode/plugins/opencode-rag/tui.js (TUI role)
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Both files re-export the plugin from the global runtime
|
|
15
|
+
* (`~/.opencode/node_modules/opencode-rag-plugin/dist/…`) via a relative
|
|
16
|
+
* path, so the install keeps working when the home directory moves. The
|
|
17
|
+
* vector store is NOT affected: `vectorStore.path` is resolved against the
|
|
18
|
+
* workspace, so every repository keeps its own local LanceDB.
|
|
19
|
+
*/
|
|
20
|
+
/** OpenCode's global plugin directory (`<config>/plugins`). */
|
|
21
|
+
export declare function getGlobalPluginsRoot(): string;
|
|
22
|
+
/** Our directory inside OpenCode's global plugin directory. */
|
|
23
|
+
export declare function getGlobalPluginDir(): string;
|
|
24
|
+
/** Dist directory of the plugin inside the runtime cache. */
|
|
25
|
+
export declare function getRuntimePluginDist(): string;
|
|
26
|
+
/** Result of {@link installGlobalPlugin}. */
|
|
27
|
+
export interface GlobalPluginResult {
|
|
28
|
+
/** Directory that holds the entrypoints. */
|
|
29
|
+
dir: string;
|
|
30
|
+
/** Files written during this call (empty when already up to date). */
|
|
31
|
+
written: string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Install (or refresh) the global plugin entrypoints.
|
|
35
|
+
*
|
|
36
|
+
* @throws When the runtime plugin dist is missing (run the runtime step first).
|
|
37
|
+
*/
|
|
38
|
+
export declare function installGlobalPlugin(options?: {
|
|
39
|
+
force?: boolean;
|
|
40
|
+
}): GlobalPluginResult;
|
|
41
|
+
/** Whether both global entrypoints exist. */
|
|
42
|
+
export declare function isGlobalPluginInstalled(): boolean;
|
|
43
|
+
/** Remove the global plugin entrypoints. Returns `true` when something was removed. */
|
|
44
|
+
export declare function removeGlobalPlugin(): boolean;
|
|
45
|
+
/** Workspace-local plugin directory (legacy/per-repo mode). */
|
|
46
|
+
export declare function getWorkspacePluginDir(workspaceDir: string): string;
|
|
47
|
+
/** Whether a workspace still uses the per-repository plugin entries. */
|
|
48
|
+
export declare function isWorkspacePluginInstalled(workspaceDir: string): boolean;
|