opencode-rag-plugin 2.3.0 → 2.4.1
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 +73 -8
- package/dist/chunker/skeleton.js +1 -1
- package/dist/cli/commands/decide.d.ts +25 -0
- package/dist/cli/commands/decide.js +160 -0
- package/dist/cli/commands/eval.d.ts +23 -0
- package/dist/cli/commands/eval.js +331 -1
- package/dist/cli/commands/index-command.js +28 -10
- package/dist/cli/commands/index.d.ts +2 -1
- package/dist/cli/commands/index.js +2 -1
- package/dist/cli/commands/init-helpers.d.ts +20 -2
- package/dist/cli/commands/init-helpers.js +139 -22
- package/dist/cli/commands/init.js +42 -5
- package/dist/cli/commands/setup.js +43 -12
- package/dist/cli/commands/status.js +14 -8
- package/dist/cli/commands/update.d.ts +3 -2
- package/dist/cli/commands/update.js +7 -3
- package/dist/cli/format.d.ts +50 -0
- package/dist/cli/format.js +122 -0
- package/dist/cli/index.js +4 -1
- package/dist/cli/types.d.ts +2 -0
- package/dist/core/bootstrap.js +1 -0
- package/dist/core/config.d.ts +54 -2
- package/dist/core/config.js +36 -3
- package/dist/core/interfaces.d.ts +69 -0
- package/dist/core/package-manager.d.ts +69 -0
- package/dist/core/package-manager.js +250 -0
- package/dist/core/setup-runtime.d.ts +7 -4
- package/dist/core/setup-runtime.js +33 -31
- package/dist/core/version-check.d.ts +19 -11
- package/dist/core/version-check.js +30 -11
- package/dist/decision/factory.d.ts +17 -0
- package/dist/decision/factory.js +17 -0
- package/dist/decision/format.d.ts +14 -0
- package/dist/decision/format.js +53 -0
- package/dist/decision/systemone.d.ts +76 -0
- package/dist/decision/systemone.js +234 -0
- package/dist/decision/validate.d.ts +26 -0
- package/dist/decision/validate.js +74 -0
- package/dist/eval/decide-calibration.d.ts +112 -0
- package/dist/eval/decide-calibration.js +185 -0
- package/dist/eval/golden-gate.d.ts +65 -0
- package/dist/eval/golden-gate.js +61 -0
- package/dist/eval/golden-set.d.ts +81 -0
- package/dist/eval/golden-set.js +155 -0
- package/dist/eval/rerank-eval.js +10 -125
- package/dist/index.d.ts +6 -2
- package/dist/index.js +4 -0
- package/dist/indexer/pipeline.d.ts +0 -10
- package/dist/indexer/pipeline.js +1 -0
- package/dist/mcp/handlers.d.ts +17 -1
- package/dist/mcp/handlers.js +30 -0
- package/dist/mcp/server.d.ts +9 -1
- package/dist/mcp/server.js +47 -3
- package/dist/opencode/system-guidance.d.ts +11 -0
- package/dist/opencode/system-guidance.js +53 -0
- package/dist/opencode/tools.d.ts +24 -1
- package/dist/opencode/tools.js +101 -0
- package/dist/plugin.js +21 -3
- package/dist/quirks/quirk-store.d.ts +2 -0
- package/dist/quirks/quirk-store.js +33 -4
- package/dist/tui.js +21 -2
- package/dist/v2/v2-adapter.d.ts +20 -0
- package/dist/v2/v2-adapter.js +36 -8
- package/dist/vectorstore/lancedb.js +54 -5
- package/dist/watcher.d.ts +26 -1
- package/dist/watcher.js +71 -9
- package/dist/web/ui/assets/index-CWcp0jNf.css +2 -0
- package/dist/web/ui/index.html +2 -2
- package/package.json +5 -2
- package/dist/web/ui/assets/index-Dp009QCQ.css +0 -1
- /package/dist/web/ui/assets/{index-C0QXKA-b.js → index-DbXFrn53.js} +0 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Package-manager detection for the setup and self-update flows.
|
|
3
|
+
*
|
|
4
|
+
* OpenCodeRAG is usually installed globally with npm, but users also install it
|
|
5
|
+
* via pnpm, yarn, or bun. Earlier releases shelled out to `npm` directly and
|
|
6
|
+
* failed with "/bin/sh: 1: npm: not found" on machines where npm is not on
|
|
7
|
+
* PATH (GitHub issue #34). Every global-package operation now goes through
|
|
8
|
+
* this module: it finds the package manager that actually owns the global
|
|
9
|
+
* install and renders the equivalent commands for it
|
|
10
|
+
* (`npm root -g` / `pnpm root -g` / `yarn global dir` / bun's fixed layout).
|
|
11
|
+
*/
|
|
12
|
+
import os from "node:os";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
15
|
+
import { execSync } from "node:child_process";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
/** Default probe order when no signal identifies the owning package manager. */
|
|
18
|
+
const DEFAULT_ORDER = ["npm", "pnpm", "bun", "yarn"];
|
|
19
|
+
const EXEC_TIMEOUT_MS = 15_000;
|
|
20
|
+
/** Run a command and return trimmed stdout, or `null` on any failure. */
|
|
21
|
+
function tryRun(command, deps) {
|
|
22
|
+
try {
|
|
23
|
+
const out = deps.exec
|
|
24
|
+
? deps.exec(command, EXEC_TIMEOUT_MS)
|
|
25
|
+
: execSync(command, { encoding: "utf-8", timeout: EXEC_TIMEOUT_MS, stdio: ["ignore", "pipe", "ignore"] });
|
|
26
|
+
const trimmed = out.trim();
|
|
27
|
+
return trimmed || null;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const SPECS = {
|
|
34
|
+
npm: {
|
|
35
|
+
name: "npm",
|
|
36
|
+
globalRoot(deps) {
|
|
37
|
+
return tryRun("npm root -g", deps);
|
|
38
|
+
},
|
|
39
|
+
installCommand(pkg) {
|
|
40
|
+
return `npm install -g ${pkg} --no-fund --no-audit`;
|
|
41
|
+
},
|
|
42
|
+
uninstallCommand(pkg) {
|
|
43
|
+
return `npm uninstall -g ${pkg}`;
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
pnpm: {
|
|
47
|
+
name: "pnpm",
|
|
48
|
+
globalRoot(deps) {
|
|
49
|
+
// Returns e.g. `~/.local/share/pnpm/global/v10/node_modules` on Linux or
|
|
50
|
+
// `%LOCALAPPDATA%\pnpm\global\v10\node_modules` on Windows. Installed
|
|
51
|
+
// packages are symlinks/junctions inside it, so existence checks follow.
|
|
52
|
+
return tryRun("pnpm root -g", deps);
|
|
53
|
+
},
|
|
54
|
+
installCommand(pkg) {
|
|
55
|
+
return `pnpm add -g ${pkg}`;
|
|
56
|
+
},
|
|
57
|
+
uninstallCommand(pkg) {
|
|
58
|
+
return `pnpm remove -g ${pkg}`;
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
yarn: {
|
|
62
|
+
name: "yarn",
|
|
63
|
+
globalRoot(deps) {
|
|
64
|
+
// Yarn 1 ("classic") keeps globals in `<yarn global dir>/node_modules`.
|
|
65
|
+
// Yarn Berry has no global installs and errors on `global` — the null
|
|
66
|
+
// return makes callers skip it.
|
|
67
|
+
const dir = tryRun("yarn global dir", deps);
|
|
68
|
+
return dir ? path.join(dir, "node_modules") : null;
|
|
69
|
+
},
|
|
70
|
+
installCommand(pkg) {
|
|
71
|
+
return `yarn global add ${pkg}`;
|
|
72
|
+
},
|
|
73
|
+
uninstallCommand(pkg) {
|
|
74
|
+
return `yarn global remove ${pkg}`;
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
bun: {
|
|
78
|
+
name: "bun",
|
|
79
|
+
globalRoot(deps) {
|
|
80
|
+
// `bun pm` has no root query; the global layout is fixed at
|
|
81
|
+
// `$BUN_INSTALL/install/global/node_modules` (default `~/.bun`).
|
|
82
|
+
if (tryRun("bun --version", deps) === null)
|
|
83
|
+
return null;
|
|
84
|
+
const base = (deps.env ?? process.env).BUN_INSTALL || path.join(os.homedir(), ".bun");
|
|
85
|
+
return path.join(base, "install", "global", "node_modules");
|
|
86
|
+
},
|
|
87
|
+
installCommand(pkg) {
|
|
88
|
+
return `bun add -g ${pkg}`;
|
|
89
|
+
},
|
|
90
|
+
uninstallCommand(pkg) {
|
|
91
|
+
return `bun remove -g ${pkg}`;
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
/** Package manager that started this process, from `npm_config_user_agent` (set by all four). */
|
|
96
|
+
function preferredFromEnv(deps) {
|
|
97
|
+
const ua = (deps.env ?? process.env).npm_config_user_agent ?? "";
|
|
98
|
+
for (const name of DEFAULT_ORDER) {
|
|
99
|
+
if (ua.startsWith(`${name}/`))
|
|
100
|
+
return name;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Package manager implied by the running module's own path.
|
|
106
|
+
*
|
|
107
|
+
* A pnpm-global install lives under `…/pnpm/global/…/node_modules/.pnpm/…`,
|
|
108
|
+
* a bun-global one under `~/.bun/install/global/…`, a Yarn classic global one
|
|
109
|
+
* under `~/.config/yarn/global/…`. npm's global roots carry no such marker.
|
|
110
|
+
*/
|
|
111
|
+
function preferredFromSelfLocation(deps) {
|
|
112
|
+
let self;
|
|
113
|
+
try {
|
|
114
|
+
self = deps.selfPath ?? fileURLToPath(import.meta.url);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
const segments = self.toLowerCase().split(/[\\/]+/);
|
|
120
|
+
if (segments.includes(".pnpm"))
|
|
121
|
+
return "pnpm";
|
|
122
|
+
for (const segment of segments) {
|
|
123
|
+
if (segment === "pnpm")
|
|
124
|
+
return "pnpm";
|
|
125
|
+
if (segment === ".bun")
|
|
126
|
+
return "bun";
|
|
127
|
+
if (segment === "yarn")
|
|
128
|
+
return "yarn";
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Candidate package managers, best guess first.
|
|
134
|
+
*
|
|
135
|
+
* Detection order: the manager that launched this process (user-agent), then
|
|
136
|
+
* the manager implied by where this module is installed, then the default
|
|
137
|
+
* probe order (npm, pnpm, bun, yarn).
|
|
138
|
+
*/
|
|
139
|
+
export function candidatePackageManagerOrder(deps = {}) {
|
|
140
|
+
const preferred = preferredFromEnv(deps) ?? preferredFromSelfLocation(deps);
|
|
141
|
+
if (!preferred)
|
|
142
|
+
return [...DEFAULT_ORDER];
|
|
143
|
+
return [preferred, ...DEFAULT_ORDER.filter((name) => name !== preferred)];
|
|
144
|
+
}
|
|
145
|
+
/** The first package manager whose global root can be resolved (availability probe). */
|
|
146
|
+
export function bestAvailablePackageManager(deps = {}) {
|
|
147
|
+
for (const name of candidatePackageManagerOrder(deps)) {
|
|
148
|
+
if (SPECS[name].globalRoot(deps) !== null)
|
|
149
|
+
return name;
|
|
150
|
+
}
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
/** Shell command that globally installs `pkg` with the given manager. */
|
|
154
|
+
export function globalInstallCommand(pm, pkg) {
|
|
155
|
+
return SPECS[pm].installCommand(pkg);
|
|
156
|
+
}
|
|
157
|
+
/** Shell command that globally removes `pkg` with the given manager. */
|
|
158
|
+
export function globalUninstallCommand(pm, pkg) {
|
|
159
|
+
return SPECS[pm].uninstallCommand(pkg);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Human-friendly install hint using the most likely manager for this machine
|
|
163
|
+
* (falls back to npm when nothing can be detected, e.g. npm-less CI probes).
|
|
164
|
+
*/
|
|
165
|
+
export function installHint(pkg, deps = {}) {
|
|
166
|
+
const preferred = preferredFromEnv(deps) ?? preferredFromSelfLocation(deps) ?? bestAvailablePackageManager(deps);
|
|
167
|
+
return SPECS[preferred ?? "npm"].installCommand(pkg);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Locate the global install of `pluginName` and the package manager that owns it.
|
|
171
|
+
*
|
|
172
|
+
* Strategy: ask each candidate manager for its global root and check whether
|
|
173
|
+
* the package sits there. When no package-manager CLI works at all (the
|
|
174
|
+
* issue-#34 case: pnpm install, npm missing), fall back to deriving the
|
|
175
|
+
* location from this module's own resolved path — the running CLI *is* the
|
|
176
|
+
* installed package, so its real path identifies the install even without any
|
|
177
|
+
* package manager on PATH.
|
|
178
|
+
*
|
|
179
|
+
* @param pluginName - npm package name to look for (e.g. `opencode-rag-plugin`).
|
|
180
|
+
* @param deps - Test seams; leave empty in production.
|
|
181
|
+
* @returns The resolved install, or `null` when the package is not globally installed.
|
|
182
|
+
*/
|
|
183
|
+
export function resolveGlobalInstall(pluginName, deps = {}) {
|
|
184
|
+
for (const name of candidatePackageManagerOrder(deps)) {
|
|
185
|
+
const root = SPECS[name].globalRoot(deps);
|
|
186
|
+
if (!root)
|
|
187
|
+
continue;
|
|
188
|
+
const packageDir = path.join(root, pluginName);
|
|
189
|
+
if ((deps.exists ?? existsSync)(packageDir)) {
|
|
190
|
+
return { pm: name, globalRoot: root, packageDir };
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return deriveFromSelfLocation(pluginName, deps);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Derive `{ globalRoot, packageDir }` by walking up from this module's path to
|
|
197
|
+
* the package.json that names `pluginName`, then to the shallowest
|
|
198
|
+
* `node_modules` ancestor that still contains the package (for pnpm that is
|
|
199
|
+
* the outer global root, not the `.pnpm` store directory).
|
|
200
|
+
*/
|
|
201
|
+
function deriveFromSelfLocation(pluginName, deps) {
|
|
202
|
+
const exists = deps.exists ?? existsSync;
|
|
203
|
+
const readJson = deps.readJson ?? ((filePath) => JSON.parse(readFileSync(filePath, "utf-8")));
|
|
204
|
+
let self;
|
|
205
|
+
try {
|
|
206
|
+
self = deps.selfPath ?? fileURLToPath(import.meta.url);
|
|
207
|
+
// Resolve junctions/symlinks so a runtime-dir junction points at the real
|
|
208
|
+
// global install instead of back at `~/.opencode/node_modules`.
|
|
209
|
+
if (!deps.selfPath)
|
|
210
|
+
self = realpathSync(self);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
let dir = path.dirname(self);
|
|
216
|
+
for (let depth = 0; depth < 24; depth++) {
|
|
217
|
+
const pkgJson = path.join(dir, "package.json");
|
|
218
|
+
if (exists(pkgJson)) {
|
|
219
|
+
let name;
|
|
220
|
+
try {
|
|
221
|
+
name = readJson(pkgJson).name;
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
name = undefined;
|
|
225
|
+
}
|
|
226
|
+
if (name === pluginName) {
|
|
227
|
+
let globalRoot = null;
|
|
228
|
+
let probe = dir;
|
|
229
|
+
let parent = path.dirname(probe);
|
|
230
|
+
while (parent !== probe) {
|
|
231
|
+
if (path.basename(probe) === "node_modules" && exists(path.join(probe, pluginName))) {
|
|
232
|
+
globalRoot = probe;
|
|
233
|
+
}
|
|
234
|
+
probe = parent;
|
|
235
|
+
parent = path.dirname(probe);
|
|
236
|
+
}
|
|
237
|
+
if (globalRoot) {
|
|
238
|
+
return { pm: null, globalRoot, packageDir: dir };
|
|
239
|
+
}
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const parent = path.dirname(dir);
|
|
244
|
+
if (parent === dir)
|
|
245
|
+
break;
|
|
246
|
+
dir = parent;
|
|
247
|
+
}
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=package-manager.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { type GlobalInstall } from "./package-manager.js";
|
|
1
2
|
export interface SetupResult {
|
|
2
3
|
success: boolean;
|
|
3
4
|
errors: string[];
|
|
4
5
|
}
|
|
5
6
|
export declare function getRuntimeDir(): string;
|
|
6
|
-
export declare function getNpmGlobalRoot(): string;
|
|
7
7
|
export declare function getVersionFile(runtimeDir: string): string;
|
|
8
8
|
export declare function readVersionFile(versionFile: string): string | null;
|
|
9
9
|
/**
|
|
@@ -12,10 +12,13 @@ export declare function readVersionFile(versionFile: string): string | null;
|
|
|
12
12
|
* (e.g. Notepad++) instead of Node.js, the CLI opens the editor instead of
|
|
13
13
|
* running. This function patches the wrappers to call `node` explicitly.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* npm only: pnpm/bun/yarn shims already invoke `node` explicitly, and their
|
|
16
|
+
* global bin directories are not laid out relative to the global root the way
|
|
17
|
+
* npm's are (`<prefix>\node_modules` next to `<prefix>`). Runs only on
|
|
18
|
+
* Windows; safe to call on every setup — detects already-patched wrappers by
|
|
19
|
+
* checking for the `node` prefix.
|
|
17
20
|
*/
|
|
18
|
-
export declare function patchWindowsWrappers(
|
|
21
|
+
export declare function patchWindowsWrappers(install: GlobalInstall): void;
|
|
19
22
|
export declare function setupRuntime(options?: {
|
|
20
23
|
force?: boolean;
|
|
21
24
|
silent?: boolean;
|
|
@@ -2,16 +2,11 @@ import path from "node:path";
|
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import { existsSync, mkdirSync, rmSync, writeFileSync, readFileSync, symlinkSync, lstatSync, } from "node:fs";
|
|
4
4
|
import { execSync } from "node:child_process";
|
|
5
|
+
import { bestAvailablePackageManager, globalInstallCommand, installHint, resolveGlobalInstall, } from "./package-manager.js";
|
|
5
6
|
const PLUGIN_NAME = "opencode-rag-plugin";
|
|
6
7
|
export function getRuntimeDir() {
|
|
7
8
|
return path.join(os.homedir(), ".opencode");
|
|
8
9
|
}
|
|
9
|
-
export function getNpmGlobalRoot() {
|
|
10
|
-
return execSync("npm root -g", {
|
|
11
|
-
encoding: "utf-8",
|
|
12
|
-
timeout: 10_000,
|
|
13
|
-
}).trim();
|
|
14
|
-
}
|
|
15
10
|
function createJunction(targetPath, linkPath) {
|
|
16
11
|
const type = process.platform === "win32" ? "junction" : "dir";
|
|
17
12
|
symlinkSync(targetPath, linkPath, type);
|
|
@@ -33,8 +28,8 @@ export function readVersionFile(versionFile) {
|
|
|
33
28
|
}
|
|
34
29
|
}
|
|
35
30
|
/** Bin name npm generates for this package (without .cmd/.ps1). */
|
|
36
|
-
function getBinName() {
|
|
37
|
-
const pkgJson = path.join(
|
|
31
|
+
function getBinName(packageDir) {
|
|
32
|
+
const pkgJson = path.join(packageDir, "package.json");
|
|
38
33
|
try {
|
|
39
34
|
const pkg = JSON.parse(readFileSync(pkgJson, "utf-8"));
|
|
40
35
|
if (pkg.bin && typeof pkg.bin === "object") {
|
|
@@ -55,14 +50,19 @@ function getBinName() {
|
|
|
55
50
|
* (e.g. Notepad++) instead of Node.js, the CLI opens the editor instead of
|
|
56
51
|
* running. This function patches the wrappers to call `node` explicitly.
|
|
57
52
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
53
|
+
* npm only: pnpm/bun/yarn shims already invoke `node` explicitly, and their
|
|
54
|
+
* global bin directories are not laid out relative to the global root the way
|
|
55
|
+
* npm's are (`<prefix>\node_modules` next to `<prefix>`). Runs only on
|
|
56
|
+
* Windows; safe to call on every setup — detects already-patched wrappers by
|
|
57
|
+
* checking for the `node` prefix.
|
|
60
58
|
*/
|
|
61
|
-
export function patchWindowsWrappers(
|
|
59
|
+
export function patchWindowsWrappers(install) {
|
|
62
60
|
if (process.platform !== "win32")
|
|
63
61
|
return;
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
if (install.pm !== "npm")
|
|
63
|
+
return;
|
|
64
|
+
const binDir = path.resolve(install.globalRoot, "..");
|
|
65
|
+
const binName = getBinName(install.packageDir);
|
|
66
66
|
// ── .cmd wrapper ──────────────────────────────────────────────
|
|
67
67
|
const cmdFile = path.join(binDir, `${binName}.cmd`);
|
|
68
68
|
if (existsSync(cmdFile)) {
|
|
@@ -107,20 +107,16 @@ export async function setupRuntime(options) {
|
|
|
107
107
|
if (alreadyInstalled && installedVersion === pluginVersion && !options?.force) {
|
|
108
108
|
return { success: true, errors: [] };
|
|
109
109
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return { success: false, errors };
|
|
117
|
-
}
|
|
118
|
-
const globalPluginDir = path.join(npmGlobalRoot, PLUGIN_NAME);
|
|
119
|
-
const globalSdkPluginDir = path.join(npmGlobalRoot, "@opencode-ai", "plugin");
|
|
120
|
-
if (!existsSync(globalPluginDir)) {
|
|
121
|
-
errors.push(`Plugin not found at: ${globalPluginDir}`);
|
|
110
|
+
// Locate the global install with any package manager (issue #34: npm may be
|
|
111
|
+
// absent entirely — pnpm/yarn/bun installs must work too).
|
|
112
|
+
const install = resolveGlobalInstall(PLUGIN_NAME);
|
|
113
|
+
if (!install) {
|
|
114
|
+
errors.push(`Could not find a global ${PLUGIN_NAME} install (checked npm, pnpm, yarn, and bun). ` +
|
|
115
|
+
`Install it first: ${installHint(PLUGIN_NAME)}`);
|
|
122
116
|
return { success: false, errors };
|
|
123
117
|
}
|
|
118
|
+
const globalPluginDir = install.packageDir;
|
|
119
|
+
const globalSdkPluginDir = path.join(install.globalRoot, "@opencode-ai", "plugin");
|
|
124
120
|
if (!existsSync(path.join(globalPluginDir, "dist", "cli.js"))) {
|
|
125
121
|
errors.push(`Global install seems incomplete: dist/ not found in ${globalPluginDir}`);
|
|
126
122
|
return { success: false, errors };
|
|
@@ -161,18 +157,24 @@ export async function setupRuntime(options) {
|
|
|
161
157
|
cpSync(globalPluginDir, runtimePluginDir, { recursive: true });
|
|
162
158
|
}
|
|
163
159
|
// Ensure the @opencode-ai/plugin SDK is available globally.
|
|
164
|
-
// We must NOT run
|
|
165
|
-
// re-resolves all of node_modules/ and replaces the plugin
|
|
166
|
-
// with the published npm version (corrupting the local link).
|
|
160
|
+
// We must NOT run a package install inside the runtime dir because the
|
|
161
|
+
// package manager re-resolves all of node_modules/ and replaces the plugin
|
|
162
|
+
// junction with the published npm version (corrupting the local link).
|
|
167
163
|
if (!existsSync(globalSdkPluginDir)) {
|
|
164
|
+
const sdkPm = install.pm ?? bestAvailablePackageManager();
|
|
165
|
+
if (!sdkPm) {
|
|
166
|
+
errors.push("No package manager (npm/pnpm/yarn/bun) found on PATH — cannot install the @opencode-ai/plugin SDK globally.");
|
|
167
|
+
return { success: false, errors };
|
|
168
|
+
}
|
|
169
|
+
const sdkInstallCommand = globalInstallCommand(sdkPm, "@opencode-ai/plugin");
|
|
168
170
|
try {
|
|
169
|
-
execSync(
|
|
171
|
+
execSync(sdkInstallCommand, {
|
|
170
172
|
stdio: "pipe",
|
|
171
173
|
timeout: 60_000,
|
|
172
174
|
});
|
|
173
175
|
}
|
|
174
176
|
catch (cause) {
|
|
175
|
-
errors.push(`Failed to install @opencode-ai/plugin SDK globally: ${cause.message}`);
|
|
177
|
+
errors.push(`Failed to install @opencode-ai/plugin SDK globally (${sdkInstallCommand}): ${cause.message}`);
|
|
176
178
|
return { success: false, errors };
|
|
177
179
|
}
|
|
178
180
|
}
|
|
@@ -213,7 +215,7 @@ export async function setupRuntime(options) {
|
|
|
213
215
|
return { success: false, errors };
|
|
214
216
|
}
|
|
215
217
|
writeFileSync(versionFile, pluginVersion, "utf-8");
|
|
216
|
-
patchWindowsWrappers(
|
|
218
|
+
patchWindowsWrappers(install);
|
|
217
219
|
const cliEntry = path.join(runtimePluginDir, "dist", "cli.js");
|
|
218
220
|
const pluginEntry = path.join(runtimePluginDir, "dist", "plugin-entry.js");
|
|
219
221
|
const sdkPkg = path.join(runtimeSdkPluginDir, "package.json");
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Version check and self-update functionality. Checks GitHub
|
|
3
|
-
* releases for new versions and installs the newest version via
|
|
4
|
-
* re-syncs the
|
|
3
|
+
* releases for new versions and installs the newest version via the package
|
|
4
|
+
* manager that owns the global install (npm/pnpm/yarn/bun), then re-syncs the
|
|
5
|
+
* OpenCode runtime junctions.
|
|
5
6
|
*/
|
|
6
7
|
import { setupRuntime } from "./setup-runtime.js";
|
|
8
|
+
import { type PackageManagerName } from "./package-manager.js";
|
|
7
9
|
/** Information about an available update. */
|
|
8
10
|
export interface UpdateInfo {
|
|
9
11
|
/** The currently installed version string. */
|
|
@@ -28,7 +30,7 @@ export interface InstallUpdateResult {
|
|
|
28
30
|
/** Version after the update (undefined if the install failed). */
|
|
29
31
|
toVersion?: string;
|
|
30
32
|
}
|
|
31
|
-
/** Callable shape for the
|
|
33
|
+
/** Callable shape for the installer runner (a subset of execSync's signature). */
|
|
32
34
|
type NpmRunner = (command: string, options: {
|
|
33
35
|
stdio: "inherit" | "pipe";
|
|
34
36
|
timeout: number;
|
|
@@ -67,24 +69,30 @@ export declare function checkForUpdate(currentVersion: string): Promise<UpdateIn
|
|
|
67
69
|
/**
|
|
68
70
|
* Install the newest published version of OpenCodeRAG.
|
|
69
71
|
*
|
|
70
|
-
* Runs
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* the
|
|
72
|
+
* Runs the global install command of the package manager that owns the
|
|
73
|
+
* current install (`npm install -g` / `pnpm add -g` / `yarn global add` /
|
|
74
|
+
* `bun add -g` with `<package>@latest`) — the npm binary itself is not
|
|
75
|
+
* required when the package was installed with another manager (GitHub
|
|
76
|
+
* issue #34). Then calls {@link setupRuntime} with `force: true` to
|
|
77
|
+
* re-create the `~/.opencode/node_modules/` junctions so OpenCode picks up
|
|
78
|
+
* the new build on the next restart.
|
|
74
79
|
*
|
|
75
|
-
* @param options - Optional verbosity flag. When `verbose` is true,
|
|
76
|
-
* is streamed to the console; otherwise it is captured silently. The
|
|
77
|
-
* `_execSync` and `
|
|
80
|
+
* @param options - Optional verbosity flag. When `verbose` is true, installer
|
|
81
|
+
* output is streamed to the console; otherwise it is captured silently. The
|
|
82
|
+
* `_execSync`, `_setupRuntime`, `_getCurrentVersion`, and `_packageManager`
|
|
83
|
+
* seams are for testing only.
|
|
78
84
|
* @returns An {@link InstallUpdateResult} with success status, message, and the
|
|
79
85
|
* from/to versions.
|
|
80
86
|
*/
|
|
81
87
|
export declare function installLatestUpdate(options?: {
|
|
82
88
|
verbose?: boolean;
|
|
83
|
-
/** Test seam: override the
|
|
89
|
+
/** Test seam: override the installer runner. */
|
|
84
90
|
_execSync?: NpmRunner;
|
|
85
91
|
/** Test seam: override the runtime sync. */
|
|
86
92
|
_setupRuntime?: typeof setupRuntime;
|
|
87
93
|
/** Test seam: override the version reader for the "to" version. */
|
|
88
94
|
_getCurrentVersion?: typeof getCurrentVersion;
|
|
95
|
+
/** Test seam: pin the package manager (`null` = force "none found"). */
|
|
96
|
+
_packageManager?: PackageManagerName | null;
|
|
89
97
|
}): Promise<InstallUpdateResult>;
|
|
90
98
|
export {};
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Version check and self-update functionality. Checks GitHub
|
|
3
|
-
* releases for new versions and installs the newest version via
|
|
4
|
-
* re-syncs the
|
|
3
|
+
* releases for new versions and installs the newest version via the package
|
|
4
|
+
* manager that owns the global install (npm/pnpm/yarn/bun), then re-syncs the
|
|
5
|
+
* OpenCode runtime junctions.
|
|
5
6
|
*/
|
|
6
7
|
import { readFileSync } from "node:fs";
|
|
7
8
|
import path from "node:path";
|
|
8
9
|
import { fileURLToPath } from "node:url";
|
|
9
10
|
import { execSync } from "node:child_process";
|
|
10
11
|
import { setupRuntime } from "./setup-runtime.js";
|
|
12
|
+
import { bestAvailablePackageManager, globalInstallCommand, resolveGlobalInstall, } from "./package-manager.js";
|
|
11
13
|
/** npm package name (must match the `name` field in package.json). */
|
|
12
14
|
const PACKAGE_NAME = "opencode-rag-plugin";
|
|
13
15
|
/** GitHub repo used for release checks (owner/repo). */
|
|
@@ -107,14 +109,18 @@ export async function checkForUpdate(currentVersion) {
|
|
|
107
109
|
/**
|
|
108
110
|
* Install the newest published version of OpenCodeRAG.
|
|
109
111
|
*
|
|
110
|
-
* Runs
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* the
|
|
112
|
+
* Runs the global install command of the package manager that owns the
|
|
113
|
+
* current install (`npm install -g` / `pnpm add -g` / `yarn global add` /
|
|
114
|
+
* `bun add -g` with `<package>@latest`) — the npm binary itself is not
|
|
115
|
+
* required when the package was installed with another manager (GitHub
|
|
116
|
+
* issue #34). Then calls {@link setupRuntime} with `force: true` to
|
|
117
|
+
* re-create the `~/.opencode/node_modules/` junctions so OpenCode picks up
|
|
118
|
+
* the new build on the next restart.
|
|
114
119
|
*
|
|
115
|
-
* @param options - Optional verbosity flag. When `verbose` is true,
|
|
116
|
-
* is streamed to the console; otherwise it is captured silently. The
|
|
117
|
-
* `_execSync` and `
|
|
120
|
+
* @param options - Optional verbosity flag. When `verbose` is true, installer
|
|
121
|
+
* output is streamed to the console; otherwise it is captured silently. The
|
|
122
|
+
* `_execSync`, `_setupRuntime`, `_getCurrentVersion`, and `_packageManager`
|
|
123
|
+
* seams are for testing only.
|
|
118
124
|
* @returns An {@link InstallUpdateResult} with success status, message, and the
|
|
119
125
|
* from/to versions.
|
|
120
126
|
*/
|
|
@@ -125,8 +131,21 @@ export async function installLatestUpdate(options) {
|
|
|
125
131
|
const syncRuntime = options?._setupRuntime ?? setupRuntime;
|
|
126
132
|
const readVersion = options?._getCurrentVersion ?? getCurrentVersion;
|
|
127
133
|
const fromVersion = readVersion();
|
|
134
|
+
// Note: an explicit `null` pins "no package manager" (test seam), so this
|
|
135
|
+
// must not use ?? — null is a value here, not an absence.
|
|
136
|
+
const pm = options?._packageManager !== undefined
|
|
137
|
+
? options._packageManager
|
|
138
|
+
: resolveGlobalInstall(PACKAGE_NAME)?.pm ?? bestAvailablePackageManager();
|
|
139
|
+
if (!pm) {
|
|
140
|
+
return {
|
|
141
|
+
success: false,
|
|
142
|
+
message: `No package manager (npm/pnpm/yarn/bun) found on PATH. Update manually with ` +
|
|
143
|
+
`'npm install -g ${PACKAGE_NAME}@latest' or the equivalent for your package manager.`,
|
|
144
|
+
fromVersion,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
128
147
|
try {
|
|
129
|
-
run(
|
|
148
|
+
run(globalInstallCommand(pm, `${PACKAGE_NAME}@latest`), {
|
|
130
149
|
stdio,
|
|
131
150
|
timeout: 120_000,
|
|
132
151
|
});
|
|
@@ -134,7 +153,7 @@ export async function installLatestUpdate(options) {
|
|
|
134
153
|
catch (err) {
|
|
135
154
|
return {
|
|
136
155
|
success: false,
|
|
137
|
-
message:
|
|
156
|
+
message: `${pm} install failed: ${err.message}`,
|
|
138
157
|
fromVersion,
|
|
139
158
|
};
|
|
140
159
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Factory for decision-model providers.
|
|
3
|
+
*
|
|
4
|
+
* Only Ollama's `/v1/systemone` (tev1) is implemented for now; the factory
|
|
5
|
+
* keeps the provider name dispatch so future backends (e.g. TypeSafe/Jev
|
|
6
|
+
* hosted APIs) can be added without touching call sites.
|
|
7
|
+
*/
|
|
8
|
+
import type { DecisionProvider } from "../core/interfaces.js";
|
|
9
|
+
import type { DecisionConfig } from "../core/config.js";
|
|
10
|
+
/**
|
|
11
|
+
* Create a decision provider instance based on configuration.
|
|
12
|
+
*
|
|
13
|
+
* @param config - Decision configuration including provider, endpoint, and model.
|
|
14
|
+
* @returns An initialized {@link DecisionProvider} instance.
|
|
15
|
+
* @throws If `provider` is not `"ollama"` (not supported yet).
|
|
16
|
+
*/
|
|
17
|
+
export declare function createDecisionProvider(config: DecisionConfig): DecisionProvider;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { OllamaDecisionProvider } from "./systemone.js";
|
|
2
|
+
/**
|
|
3
|
+
* Create a decision provider instance based on configuration.
|
|
4
|
+
*
|
|
5
|
+
* @param config - Decision configuration including provider, endpoint, and model.
|
|
6
|
+
* @returns An initialized {@link DecisionProvider} instance.
|
|
7
|
+
* @throws If `provider` is not `"ollama"` (not supported yet).
|
|
8
|
+
*/
|
|
9
|
+
export function createDecisionProvider(config) {
|
|
10
|
+
const provider = (config.provider || "ollama").toLowerCase();
|
|
11
|
+
if (provider === "ollama") {
|
|
12
|
+
return new OllamaDecisionProvider(config);
|
|
13
|
+
}
|
|
14
|
+
throw new Error(`Decision provider "${config.provider}" is not supported yet — only "ollama" ` +
|
|
15
|
+
"(tev1 via /v1/systemone) is implemented.");
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Markdown formatting for decision answers, shared by the
|
|
3
|
+
* OpenCode plugin tool, the MCP handler, and the CLI command.
|
|
4
|
+
*/
|
|
5
|
+
import type { DecisionAnswer } from "../core/interfaces.js";
|
|
6
|
+
/** Optional provenance header fields. */
|
|
7
|
+
export interface DecisionFormatOptions {
|
|
8
|
+
/** Provider name (e.g. "ollama"). */
|
|
9
|
+
provider?: string;
|
|
10
|
+
/** Model name (e.g. "tev1:0.8b"). */
|
|
11
|
+
model?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Render an ordered list of decision answers as compact markdown. */
|
|
14
|
+
export declare function formatDecisionAnswers(answers: DecisionAnswer[], opts?: DecisionFormatOptions): string;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Render an ordered list of decision answers as compact markdown. */
|
|
2
|
+
export function formatDecisionAnswers(answers, opts = {}) {
|
|
3
|
+
const header = opts.provider && opts.model
|
|
4
|
+
? `**Decision** — ${opts.provider}/${opts.model}`
|
|
5
|
+
: "**Decision**";
|
|
6
|
+
const lines = [header, ""];
|
|
7
|
+
for (const answer of answers) {
|
|
8
|
+
lines.push(formatAnswer(answer));
|
|
9
|
+
}
|
|
10
|
+
return lines.join("\n");
|
|
11
|
+
}
|
|
12
|
+
function formatAnswer(answer) {
|
|
13
|
+
if (answer.type === "choice") {
|
|
14
|
+
const confidence = answer.confidence !== undefined ? ` (confidence ${answer.confidence.toFixed(2)})` : "";
|
|
15
|
+
const lines = [
|
|
16
|
+
`- **${answer.id}** = \`${answer.choice ?? "(no choice returned)"}\`${confidence}`,
|
|
17
|
+
];
|
|
18
|
+
const probabilities = formatProbabilities(answer.probabilities);
|
|
19
|
+
if (probabilities)
|
|
20
|
+
lines.push(` - probabilities: ${probabilities}`);
|
|
21
|
+
return lines.join("\n");
|
|
22
|
+
}
|
|
23
|
+
if (answer.type === "noul") {
|
|
24
|
+
if (answer.noul === undefined) {
|
|
25
|
+
return `- **${answer.id}** = (no probability returned)`;
|
|
26
|
+
}
|
|
27
|
+
const verdict = answer.noul >= 0.5 ? "true" : "false";
|
|
28
|
+
return `- **${answer.id}** = ${verdict} (p=${answer.noul.toFixed(2)})`;
|
|
29
|
+
}
|
|
30
|
+
const score = answer.score !== undefined ? answer.score.toFixed(2) : "(no score returned)";
|
|
31
|
+
const scale = answer.legend && answer.legend.length > 1 ? ` / ${answer.legend.length - 1}` : "";
|
|
32
|
+
const confidence = answer.confidence !== undefined ? ` (confidence ${answer.confidence.toFixed(2)})` : "";
|
|
33
|
+
const lines = [`- **${answer.id}** = ${score}${scale}${confidence}`];
|
|
34
|
+
if (answer.legend && answer.legend.length > 0) {
|
|
35
|
+
lines.push(` - legend: ${answer.legend.map((label, i) => `${i}=${label}`).join(", ")}`);
|
|
36
|
+
}
|
|
37
|
+
const probabilities = formatProbabilities(answer.probabilities);
|
|
38
|
+
if (probabilities)
|
|
39
|
+
lines.push(` - probabilities: ${probabilities}`);
|
|
40
|
+
return lines.join("\n");
|
|
41
|
+
}
|
|
42
|
+
function formatProbabilities(probabilities) {
|
|
43
|
+
if (!probabilities)
|
|
44
|
+
return undefined;
|
|
45
|
+
if (Array.isArray(probabilities)) {
|
|
46
|
+
return probabilities.map((p, i) => `${i}=${p.toFixed(2)}`).join(", ");
|
|
47
|
+
}
|
|
48
|
+
return Object.entries(probabilities)
|
|
49
|
+
.sort((a, b) => b[1] - a[1])
|
|
50
|
+
.map(([label, p]) => `${label}=${p.toFixed(2)}`)
|
|
51
|
+
.join(", ");
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=format.js.map
|