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
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Repair flow for models that fail the post-setup health check.
|
|
3
|
+
*
|
|
4
|
+
* `setup` probes the configured providers after applying the configuration.
|
|
5
|
+
* When a model answers with an error (expired key, wrong URL, unreachable
|
|
6
|
+
* server) the run must not stop at "Some providers are not reachable": this
|
|
7
|
+
* module asks whether to fix the section, then collects provider, base URL,
|
|
8
|
+
* API key and model (the same questions as the wizard) and writes the result
|
|
9
|
+
* into the config layer that already owns the section.
|
|
10
|
+
*
|
|
11
|
+
* The health check resolves API keys the same way the runtime does
|
|
12
|
+
* (`resolveApiKey`), so a key stored in OpenCode's auth store is used instead
|
|
13
|
+
* of the indexing section's key — an expired Zen key then reports itself as
|
|
14
|
+
* expired rather than as a generic 401.
|
|
15
|
+
*/
|
|
16
|
+
import { loadWorkspaceConfig, configuredSections } from "../../core/config.js";
|
|
17
|
+
import { resolveApiKey } from "../../core/resolve-api-key.js";
|
|
18
|
+
import { resolveZenBaseUrl, isZenProvider } from "../../core/zen.js";
|
|
19
|
+
import { resolveOnDemandImageConfig } from "../../chunker/image.js";
|
|
20
|
+
import { checkProviderHealth } from "../../embedder/health.js";
|
|
21
|
+
import { c } from "../format.js";
|
|
22
|
+
import { readJsonObjectSafe, writeConfigPatch } from "./apply.js";
|
|
23
|
+
import { askHost, pickModel } from "./flow.js";
|
|
24
|
+
const TARGETS = {
|
|
25
|
+
embedding: {
|
|
26
|
+
section: "embedding",
|
|
27
|
+
label: "Embedding",
|
|
28
|
+
capability: "embedding",
|
|
29
|
+
requireEmbedding: true,
|
|
30
|
+
},
|
|
31
|
+
description: {
|
|
32
|
+
section: "description",
|
|
33
|
+
label: "Description",
|
|
34
|
+
capability: "chat",
|
|
35
|
+
requireChat: true,
|
|
36
|
+
},
|
|
37
|
+
image_description: {
|
|
38
|
+
section: "imageDescription",
|
|
39
|
+
label: "Image description",
|
|
40
|
+
capability: "vision",
|
|
41
|
+
requireChat: true,
|
|
42
|
+
},
|
|
43
|
+
image_description_on_demand: {
|
|
44
|
+
section: "imageDescription",
|
|
45
|
+
sub: "onDemand",
|
|
46
|
+
label: "Image description (on-demand)",
|
|
47
|
+
capability: "vision",
|
|
48
|
+
requireChat: true,
|
|
49
|
+
},
|
|
50
|
+
rerank: {
|
|
51
|
+
section: "reranking",
|
|
52
|
+
label: "Reranking",
|
|
53
|
+
capability: "chat",
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
/** Whether a config object has the given section (or nested override). */
|
|
57
|
+
function hasSection(raw, section, sub) {
|
|
58
|
+
const value = raw[section];
|
|
59
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
60
|
+
return false;
|
|
61
|
+
if (!sub)
|
|
62
|
+
return true;
|
|
63
|
+
const nested = value[sub];
|
|
64
|
+
return Boolean(nested) && typeof nested === "object";
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Pick the config file that owns a section.
|
|
68
|
+
*
|
|
69
|
+
* The section is repaired where the user already put it, so the write is
|
|
70
|
+
* visible immediately instead of being shadowed by another layer.
|
|
71
|
+
*/
|
|
72
|
+
export function resolveRepairLayer(workspaceConfigPath, globalConfigPath, section, sub) {
|
|
73
|
+
if (hasSection(readJsonObjectSafe(workspaceConfigPath), section, sub))
|
|
74
|
+
return workspaceConfigPath;
|
|
75
|
+
if (hasSection(readJsonObjectSafe(globalConfigPath), section, sub))
|
|
76
|
+
return globalConfigPath;
|
|
77
|
+
return sub ? globalConfigPath : workspaceConfigPath;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Build the sparse patch for a repaired section.
|
|
81
|
+
*
|
|
82
|
+
* `apiKey: null` deletes a stale key (so an environment variable or the
|
|
83
|
+
* OpenCode auth store can take over); `vectorDimension: null` does the same
|
|
84
|
+
* for an embedding model that may have a different dimension.
|
|
85
|
+
*/
|
|
86
|
+
export function buildRepairPatch(section, sub, choice) {
|
|
87
|
+
const values = { ...choice };
|
|
88
|
+
if (!values.apiKey)
|
|
89
|
+
values.apiKey = null;
|
|
90
|
+
if (sub === "onDemand")
|
|
91
|
+
return { imageDescription: { onDemand: values } };
|
|
92
|
+
if (section === "embedding")
|
|
93
|
+
return { embedding: { ...values, vectorDimension: null } };
|
|
94
|
+
return { [section]: values };
|
|
95
|
+
}
|
|
96
|
+
/** A provider entry for an id the wizard does not list (e.g. `opencode-go`). */
|
|
97
|
+
function extraProvider(id, target) {
|
|
98
|
+
if (id.length === 0)
|
|
99
|
+
return [];
|
|
100
|
+
return [
|
|
101
|
+
{
|
|
102
|
+
id,
|
|
103
|
+
label: `${id} (current)`,
|
|
104
|
+
description: "Provider already configured for this model",
|
|
105
|
+
embedding: target.capability === "embedding",
|
|
106
|
+
chat: target.capability !== "embedding",
|
|
107
|
+
},
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
/** Prompt for a reranker endpoint (no model catalog — llama-server style). */
|
|
111
|
+
async function repairReranker(prompter, current) {
|
|
112
|
+
const baseUrl = await prompter.text({
|
|
113
|
+
message: "Rerank endpoint base URL",
|
|
114
|
+
defaultValue: typeof current.baseUrl === "string" ? current.baseUrl : "http://127.0.0.1:8080/v1",
|
|
115
|
+
hint: "llama-server with --reranking serves /v1/rerank",
|
|
116
|
+
});
|
|
117
|
+
if (baseUrl === undefined)
|
|
118
|
+
return undefined;
|
|
119
|
+
const model = await prompter.text({
|
|
120
|
+
message: "Rerank model",
|
|
121
|
+
defaultValue: typeof current.model === "string" ? current.model : "qwen3-reranker-0.6b",
|
|
122
|
+
});
|
|
123
|
+
if (model === undefined)
|
|
124
|
+
return undefined;
|
|
125
|
+
const key = await prompter.password("API key (Enter keeps the current one)");
|
|
126
|
+
if (key === undefined)
|
|
127
|
+
return undefined;
|
|
128
|
+
const apiKey = key.trim().length > 0 ? key.trim() : undefined;
|
|
129
|
+
return { baseUrl, model, ...(apiKey ? { apiKey } : { apiKey: null }) };
|
|
130
|
+
}
|
|
131
|
+
/** Repair one failed model. Returns `true` when a patch was written. */
|
|
132
|
+
async function repairOne(options, failure) {
|
|
133
|
+
const target = TARGETS[failure.type];
|
|
134
|
+
if (!target)
|
|
135
|
+
return false;
|
|
136
|
+
const config = loadWorkspaceConfig(options.cwd);
|
|
137
|
+
const sectionValue = target.section === "reranking"
|
|
138
|
+
? config.reranking
|
|
139
|
+
: config[target.section];
|
|
140
|
+
const override = target.sub && sectionValue
|
|
141
|
+
? sectionValue[target.sub]
|
|
142
|
+
: undefined;
|
|
143
|
+
const effective = target.sub && config.imageDescription
|
|
144
|
+
? resolveOnDemandImageConfig(config.imageDescription)
|
|
145
|
+
: (sectionValue ?? {});
|
|
146
|
+
if (target.sub === "onDemand") {
|
|
147
|
+
const disable = await options.prompter.confirm({
|
|
148
|
+
message: "Remove the on-demand override and use the indexing vision model instead?",
|
|
149
|
+
defaultValue: false,
|
|
150
|
+
});
|
|
151
|
+
if (disable === undefined)
|
|
152
|
+
return false;
|
|
153
|
+
if (disable) {
|
|
154
|
+
const layer = resolveRepairLayer(options.workspaceConfigPath, options.globalConfigPath, "imageDescription", "onDemand");
|
|
155
|
+
writeConfigPatch(layer, { imageDescription: { onDemand: null } });
|
|
156
|
+
console.log(` ${c.updated("Removed:")} imageDescription.onDemand`);
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (target.section === "reranking") {
|
|
161
|
+
const patch = await repairReranker(options.prompter, effective);
|
|
162
|
+
if (!patch)
|
|
163
|
+
return false;
|
|
164
|
+
const layer = resolveRepairLayer(options.workspaceConfigPath, options.globalConfigPath, "reranking");
|
|
165
|
+
writeConfigPatch(layer, { reranking: patch });
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
// Defaults: the section's own values first, the effective (inherited) values
|
|
169
|
+
// second. For `onDemand` the inherited indexing base URL/key are deliberately
|
|
170
|
+
// not offered as the stored key — they are what just failed.
|
|
171
|
+
const provider = String(override?.provider ?? effective.provider ?? "ollama");
|
|
172
|
+
const defaultBaseUrl = typeof override?.baseUrl === "string"
|
|
173
|
+
? override.baseUrl
|
|
174
|
+
: isZenProvider(provider)
|
|
175
|
+
? resolveZenBaseUrl(typeof effective.baseUrl === "string" ? effective.baseUrl : undefined, provider)
|
|
176
|
+
: String(effective.baseUrl ?? "");
|
|
177
|
+
const defaultModel = String(override?.model ?? effective.model ?? "");
|
|
178
|
+
const defaults = {
|
|
179
|
+
provider,
|
|
180
|
+
baseUrl: defaultBaseUrl,
|
|
181
|
+
...(defaultModel ? { model: defaultModel } : {}),
|
|
182
|
+
...(typeof override?.apiKey === "string" ? { apiKey: override.apiKey } : {}),
|
|
183
|
+
};
|
|
184
|
+
console.log();
|
|
185
|
+
const host = await askHost(options.prompter, {
|
|
186
|
+
message: `${target.label} provider`,
|
|
187
|
+
existing: { embedding: defaults },
|
|
188
|
+
flags: {},
|
|
189
|
+
proxy: options.proxy,
|
|
190
|
+
...(target.requireEmbedding ? { requireEmbedding: true } : {}),
|
|
191
|
+
...(target.requireChat ? { requireChat: true } : {}),
|
|
192
|
+
extraProviders: extraProvider(provider, target),
|
|
193
|
+
forceKeyPrompt: true,
|
|
194
|
+
});
|
|
195
|
+
if (!host)
|
|
196
|
+
return false;
|
|
197
|
+
const model = await pickModel(options.prompter, {
|
|
198
|
+
message: `${target.label} model`,
|
|
199
|
+
catalog: host.catalog,
|
|
200
|
+
capability: target.capability,
|
|
201
|
+
defaultValue: defaultModel || undefined,
|
|
202
|
+
});
|
|
203
|
+
if (model === undefined)
|
|
204
|
+
return false;
|
|
205
|
+
const choice = {
|
|
206
|
+
provider: host.host.provider,
|
|
207
|
+
baseUrl: host.host.baseUrl,
|
|
208
|
+
model,
|
|
209
|
+
...(host.host.apiKey ? { apiKey: host.host.apiKey } : {}),
|
|
210
|
+
};
|
|
211
|
+
const patch = buildRepairPatch(target.section, target.sub, choice);
|
|
212
|
+
const layer = resolveRepairLayer(options.workspaceConfigPath, options.globalConfigPath, target.section, target.sub);
|
|
213
|
+
if (!writeConfigPatch(layer, patch)) {
|
|
214
|
+
console.log(` ${c.warn("Could not write the configuration.")} Check permissions for ${c.file(layer)}.`);
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
console.log(` ${c.updated("Updated:")} ${c.file(layer)} ${c.dim(`(${target.label.toLowerCase()})`)}`);
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Offer to repair every model that failed the connectivity check.
|
|
222
|
+
*
|
|
223
|
+
* Only runs for an interactive prompter: `--yes` / non-TTY runs keep the
|
|
224
|
+
* current report-and-continue behaviour. Returns the number of sections that
|
|
225
|
+
* were written.
|
|
226
|
+
*/
|
|
227
|
+
export async function offerHealthRepairs(options) {
|
|
228
|
+
const failures = options.results.filter((result) => result.status === "error");
|
|
229
|
+
if (failures.length === 0 || !options.prompter.interactive)
|
|
230
|
+
return 0;
|
|
231
|
+
console.log(`\n${c.heading("Fixing provider configuration")}`);
|
|
232
|
+
let repaired = 0;
|
|
233
|
+
for (const failure of failures) {
|
|
234
|
+
const target = TARGETS[failure.type];
|
|
235
|
+
if (!target)
|
|
236
|
+
continue;
|
|
237
|
+
const detail = failure.error ? ` (${failure.error})` : "";
|
|
238
|
+
const answer = await options.prompter.confirm({
|
|
239
|
+
message: `${target.label} model ${c.value(failure.model)} failed${detail}. Reconfigure it now?`,
|
|
240
|
+
defaultValue: true,
|
|
241
|
+
});
|
|
242
|
+
if (answer === undefined)
|
|
243
|
+
return repaired;
|
|
244
|
+
if (!answer)
|
|
245
|
+
continue;
|
|
246
|
+
if (await repairOne(options, failure)) {
|
|
247
|
+
repaired += 1;
|
|
248
|
+
// Verify against the runtime-resolved config, not the raw file.
|
|
249
|
+
const updated = loadWorkspaceConfig(options.cwd);
|
|
250
|
+
resolveApiKey(updated, options.cwd);
|
|
251
|
+
const after = (await checkProviderHealth(updated, configuredSections(options.cwd))).find((result) => result.type === failure.type);
|
|
252
|
+
if (!after) {
|
|
253
|
+
console.log(` ${c.success("✓")} ${c.value(failure.model)} is no longer checked.`);
|
|
254
|
+
}
|
|
255
|
+
else if (after.status === "ok") {
|
|
256
|
+
console.log(` ${c.success("✓")} ${c.value(after.model)} is reachable now.`);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
console.log(` ${c.error("✗")} ${c.value(after.model)} still fails: ${after.error ?? "unknown error"}`);
|
|
260
|
+
console.log(` ${c.dim("Run `opencode-rag setup --reconfigure` to change more settings.")}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return repaired;
|
|
265
|
+
}
|
|
266
|
+
//# sourceMappingURL=repair.js.map
|
package/dist/cli/workspace.d.ts
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
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
|
*/
|
|
16
|
+
import { type HealthCheckResult } from "../embedder/health.js";
|
|
10
17
|
import type { Prompter } from "./prompt.js";
|
|
11
18
|
/** Options for {@link scaffoldWorkspace}. */
|
|
12
19
|
export interface WorkspaceScaffoldOptions {
|
|
13
20
|
/** Rewrite generated files even when their content already matches. */
|
|
14
21
|
force?: boolean;
|
|
15
|
-
/** Skip linking the plugin from the global runtime cache. */
|
|
22
|
+
/** Skip linking the plugin from the global runtime cache (workspace mode). */
|
|
16
23
|
skipInstall?: boolean;
|
|
17
24
|
/** Config path used to render the AGENTS.md guidance. */
|
|
18
25
|
configPath?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Install the plugin into this workspace (legacy layout) instead of using
|
|
28
|
+
* the global plugin directory. Defaults to `false`.
|
|
29
|
+
*/
|
|
30
|
+
workspacePlugin?: boolean;
|
|
19
31
|
}
|
|
20
32
|
/**
|
|
21
33
|
* Best-effort check whether `cwd` looks like a project root (git repo or
|
|
@@ -36,5 +48,10 @@ export declare function scaffoldWorkspace(options?: WorkspaceScaffoldOptions): P
|
|
|
36
48
|
* Uses the effective config (global < workspace) so models chosen in the
|
|
37
49
|
* wizard are probed even though most provider settings live in the global
|
|
38
50
|
* file.
|
|
51
|
+
*
|
|
52
|
+
* @param options.autoPull Pull missing models without a second confirmation
|
|
53
|
+
* (used by the one-question recommended setup).
|
|
39
54
|
*/
|
|
40
|
-
export declare function runWorkspaceHealthCheck(cwd: string, prompter: Prompter
|
|
55
|
+
export declare function runWorkspaceHealthCheck(cwd: string, prompter: Prompter, options?: {
|
|
56
|
+
autoPull?: boolean;
|
|
57
|
+
}): Promise<HealthCheckResult[]>;
|