opencode-rag-plugin 2.12.3 → 2.13.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 +20 -2
- package/dist/cli/browser.d.ts +20 -0
- package/dist/cli/browser.js +49 -0
- package/dist/cli/commands/setup.js +11 -0
- package/dist/cli/commands/ui.js +3 -11
- package/dist/cli/setup-ui.d.ts +38 -0
- package/dist/cli/setup-ui.js +133 -0
- package/dist/cli/types.d.ts +5 -0
- package/dist/core/config.d.ts +23 -7
- package/dist/core/config.js +8 -1
- package/dist/decision/systemone.d.ts +2 -1
- package/dist/decision/systemone.js +27 -4
- package/dist/safety/shell-guard.js +4 -1
- package/dist/web/api.d.ts +8 -1
- package/dist/web/api.js +28 -14
- package/dist/web/config-api.d.ts +60 -0
- package/dist/web/config-api.js +614 -0
- package/dist/web/config-schema.d.ts +88 -0
- package/dist/web/config-schema.js +821 -0
- package/dist/web/server.js +14 -4
- package/dist/web/ui/assets/{ScatterPlot3D-XjXIwavM.js → ScatterPlot3D-CJpVHNv-.js} +1 -1
- package/dist/web/ui/assets/index-BitHPGOk.css +2 -0
- package/dist/web/ui/assets/index-DDZPYJ4D.js +4 -0
- package/dist/web/ui/index.html +20 -3
- package/package.json +1 -1
- package/dist/web/ui/assets/index-B-RH6fko.css +0 -2
- package/dist/web/ui/assets/index-FFPRbgLx.js +0 -4
package/ReadMe.md
CHANGED
|
@@ -79,7 +79,8 @@ No GPU is required, although it is recommended when using code and image descrip
|
|
|
79
79
|
npm install -g opencode-rag-plugin
|
|
80
80
|
|
|
81
81
|
# 2. Set up the runtime, the workspace, and your models
|
|
82
|
-
# (a short interactive wizard guides you through the configuration
|
|
82
|
+
# (a short interactive wizard guides you through the configuration;
|
|
83
|
+
# the web UI then opens on the Configuration page)
|
|
83
84
|
cd /path/to/your/project
|
|
84
85
|
opencode-rag setup
|
|
85
86
|
|
|
@@ -114,6 +115,7 @@ It handles the whole onboarding in one command:
|
|
|
114
115
|
- installs or verifies the machine-level runtime in `~/.opencode/`
|
|
115
116
|
- scaffolds the current workspace (`.opencode/` config, plugin entries, skill files)
|
|
116
117
|
- on the first run, or with `--reconfigure`, starts a **model wizard** for the embedding, description, vision, and decision models
|
|
118
|
+
- an interactive run finishes by opening the **Web UI on its Configuration page**, so the generated settings can be reviewed and adjusted; the server stays up until you press `Ctrl+C` (`--no-ui` keeps setup headless)
|
|
117
119
|
|
|
118
120
|
A plain re-run only syncs the workspace files. The wizard is scriptable (`--yes`, `--provider`, `--base-url`, `--embedding-model`, `--description off`, and more), and `--skip-runtime` limits the run to the workspace. Use `opencode-rag update` to upgrade the runtime to a newer release.
|
|
119
121
|
|
|
@@ -308,6 +310,22 @@ Requires Ollama ≥ 0.35. **Disabled by default.** Opt in via `decision.enabled`
|
|
|
308
310
|
}
|
|
309
311
|
```
|
|
310
312
|
|
|
313
|
+
`decision.baseUrl` accepts a root URL, an `/api`-suffixed URL, or an `/v1`-suffixed URL - both suffixes are stripped, so requests always go to `<root>/v1/systemone`. Any server exposing that route works, for example **llama-swap**:
|
|
314
|
+
|
|
315
|
+
```json
|
|
316
|
+
{
|
|
317
|
+
"decision": {
|
|
318
|
+
"enabled": true,
|
|
319
|
+
"provider": "ollama",
|
|
320
|
+
"baseUrl": "http://127.0.0.1:11437",
|
|
321
|
+
"model": "Clef-Flash",
|
|
322
|
+
"apiKey": "sk-llama-local"
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
`decision.apiKey` is sent as `Authorization: Bearer <key>` and is required when the server protects its routes (llama-swap's `api_key`).
|
|
328
|
+
|
|
311
329
|
**Using it well**
|
|
312
330
|
|
|
313
331
|
- Always include a `none` / "cannot be determined" option.
|
|
@@ -387,7 +405,7 @@ Image files (PNG, JPEG, WebP, and others) are sent to a vision-capable LLM, and
|
|
|
387
405
|
|
|
388
406
|
### 7. Web UI, evaluation, and calibration
|
|
389
407
|
|
|
390
|
-
**Web UI.** A browser dashboard for exploring the vector database: browse, visualize, and inspect chunks, and evaluate OpenCode sessions by retrieved chunks and consumed tokens. Launch it with `opencode-rag ui
|
|
408
|
+
**Web UI.** A browser dashboard for exploring the vector database: browse, visualize, and inspect chunks side-by-side with a movable splitter, edit the global and project configuration layers, switch between dark, plasma, drama, and light themes, and evaluate OpenCode sessions by retrieved chunks and consumed tokens. Launch it with `opencode-rag ui` (or let `opencode-rag setup` open it on the Configuration page). See the [Web UI docs](doc/webui.md).
|
|
391
409
|
|
|
392
410
|
[](doc/assets/webui-3d.png)
|
|
393
411
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Cross-platform helper for opening a URL in the user's default browser.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Open a URL in the system default browser.
|
|
6
|
+
*
|
|
7
|
+
* Spawns the platform launcher detached so it outlives the CLI process:
|
|
8
|
+
* `cmd.exe /c start` on Windows, `open` on macOS and `xdg-open` elsewhere.
|
|
9
|
+
* Every spawn passes `windowsHide: true` — the plugin also runs inside
|
|
10
|
+
* OpenCode's console-less service, where an un-hidden spawn flashes a
|
|
11
|
+
* terminal window per call.
|
|
12
|
+
*
|
|
13
|
+
* The returned promise resolves once the launcher process either spawned or
|
|
14
|
+
* failed (a missing `xdg-open` emits an `error` event rather than throwing),
|
|
15
|
+
* so callers can tell "no browser available" from "browser opened".
|
|
16
|
+
*
|
|
17
|
+
* @param url - Absolute URL to open.
|
|
18
|
+
* @returns `true` when the launcher process was spawned, `false` otherwise.
|
|
19
|
+
*/
|
|
20
|
+
export declare function openInBrowser(url: string): Promise<boolean>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Cross-platform helper for opening a URL in the user's default browser.
|
|
3
|
+
*/
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
/**
|
|
6
|
+
* Open a URL in the system default browser.
|
|
7
|
+
*
|
|
8
|
+
* Spawns the platform launcher detached so it outlives the CLI process:
|
|
9
|
+
* `cmd.exe /c start` on Windows, `open` on macOS and `xdg-open` elsewhere.
|
|
10
|
+
* Every spawn passes `windowsHide: true` — the plugin also runs inside
|
|
11
|
+
* OpenCode's console-less service, where an un-hidden spawn flashes a
|
|
12
|
+
* terminal window per call.
|
|
13
|
+
*
|
|
14
|
+
* The returned promise resolves once the launcher process either spawned or
|
|
15
|
+
* failed (a missing `xdg-open` emits an `error` event rather than throwing),
|
|
16
|
+
* so callers can tell "no browser available" from "browser opened".
|
|
17
|
+
*
|
|
18
|
+
* @param url - Absolute URL to open.
|
|
19
|
+
* @returns `true` when the launcher process was spawned, `false` otherwise.
|
|
20
|
+
*/
|
|
21
|
+
export async function openInBrowser(url) {
|
|
22
|
+
try {
|
|
23
|
+
// The empty title argument keeps `start` from treating the URL as the
|
|
24
|
+
// window title on Windows.
|
|
25
|
+
const child = process.platform === "win32"
|
|
26
|
+
? spawn("cmd.exe", ["/c", "start", "", url], {
|
|
27
|
+
detached: true,
|
|
28
|
+
stdio: "ignore",
|
|
29
|
+
windowsHide: true,
|
|
30
|
+
})
|
|
31
|
+
: spawn(process.platform === "darwin" ? "open" : "xdg-open", [url], {
|
|
32
|
+
detached: true,
|
|
33
|
+
stdio: "ignore",
|
|
34
|
+
windowsHide: true,
|
|
35
|
+
});
|
|
36
|
+
const spawned = await new Promise((resolve) => {
|
|
37
|
+
child.once("spawn", () => resolve(true));
|
|
38
|
+
child.once("error", () => resolve(false));
|
|
39
|
+
});
|
|
40
|
+
child.unref();
|
|
41
|
+
return spawned;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// `spawn` throws synchronously only for invalid arguments — treat any
|
|
45
|
+
// throw as "could not open a browser".
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -15,6 +15,7 @@ import { generateDefaultConfigJson } from "./workspace-helpers.js";
|
|
|
15
15
|
import { detectOllamaBackend } from "./backend-detect.js";
|
|
16
16
|
import { isLikelyProjectRoot, runWorkspaceHealthCheck, scaffoldWorkspace, } from "../workspace.js";
|
|
17
17
|
import { destroyAllPooledConnections } from "../../embedder/http.js";
|
|
18
|
+
import { launchSetupConfigUi, shouldLaunchSetupUi } from "../setup-ui.js";
|
|
18
19
|
import { getGlobalPluginDir, installGlobalPlugin, isGlobalPluginInstalled, isWorkspacePluginInstalled, removeGlobalPlugin, } from "../../core/global-plugin.js";
|
|
19
20
|
const PLUGIN_NAME = "opencode-rag-plugin";
|
|
20
21
|
function removeIfExists(targetPath) {
|
|
@@ -72,6 +73,9 @@ export function registerSetupCommand(program) {
|
|
|
72
73
|
" Use --reconfigure to re-open the wizard, or pass flags for scripted setups.\n" +
|
|
73
74
|
" - Updating: use 'opencode-rag update' to install a newer release.\n" +
|
|
74
75
|
" - Troubleshooting: use --check to inspect the runtime, or --force to reinstall.\n" +
|
|
76
|
+
"\nAfter an interactive run the web UI opens on the Configuration page so the\n" +
|
|
77
|
+
"generated settings can be reviewed; press Ctrl+C there to finish. Use --no-ui\n" +
|
|
78
|
+
"to keep setup headless.\n" +
|
|
75
79
|
"\nProvider/model settings are written to the global config\n" +
|
|
76
80
|
"(~/.config/opencode/opencode-rag.json); feature toggles to the workspace\n" +
|
|
77
81
|
"config (.opencode/opencode-rag.json).\n")
|
|
@@ -104,6 +108,7 @@ export function registerSetupCommand(program) {
|
|
|
104
108
|
.option("--skip-runtime [on|off]", "skip the machine-level runtime install (workspace setup only)")
|
|
105
109
|
.option("--workspace-plugin", "install the plugin into this workspace instead of the global config")
|
|
106
110
|
.option("--no-index", "do not offer to build the search index after setup")
|
|
111
|
+
.option("--no-ui", "do not open the web UI Configuration page after setup")
|
|
107
112
|
.action(async (options) => {
|
|
108
113
|
await runSetup(options);
|
|
109
114
|
});
|
|
@@ -413,6 +418,12 @@ async function runSetup(rawOptions) {
|
|
|
413
418
|
console.log(` ${c.dim(" 1. Restart OpenCode if it is running")}`);
|
|
414
419
|
console.log(` ${c.dim(" 2. Run `opencode-rag index` to build the search index")}`);
|
|
415
420
|
checkOpenCodeRunning();
|
|
421
|
+
// Interactive runs hand off to the Configuration page so the generated
|
|
422
|
+
// settings can be reviewed immediately; the process stays alive until the
|
|
423
|
+
// user presses Ctrl+C. Never in scripted (`-y`) or failed runs.
|
|
424
|
+
if ((process.exitCode ?? 0) === 0 && shouldLaunchSetupUi(options)) {
|
|
425
|
+
await launchSetupConfigUi(process.cwd());
|
|
426
|
+
}
|
|
416
427
|
console.log();
|
|
417
428
|
}
|
|
418
429
|
/**
|
package/dist/cli/commands/ui.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { c, resolveCliContext, cleanupContext, logCliError, logCliInfo } from "../format.js";
|
|
9
|
+
import { openInBrowser } from "../browser.js";
|
|
9
10
|
/**
|
|
10
11
|
* Register the `ui` command on the given Commander program.
|
|
11
12
|
*
|
|
@@ -43,17 +44,8 @@ export function registerUiCommand(program) {
|
|
|
43
44
|
logCliInfo(logFilePath, "ui", ` ${c.dim("The token in the URL authenticates this session — keep it private.")}`);
|
|
44
45
|
logCliInfo(logFilePath, "ui", ` ${c.dim("Press Ctrl+C to stop")}\n`);
|
|
45
46
|
if (openBrowser) {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
if (process.platform === "win32") {
|
|
49
|
-
spawn("cmd.exe", ["/c", "start", url], { detached: true, stdio: "ignore", windowsHide: true }).unref();
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
const cmd = process.platform === "darwin" ? "open" : "xdg-open";
|
|
53
|
-
spawn(cmd, [url], { detached: true, stdio: "ignore" }).unref();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
47
|
+
const opened = await openInBrowser(url);
|
|
48
|
+
if (!opened) {
|
|
57
49
|
console.error(c.dim(`Could not open browser automatically. Open ${url} manually.`));
|
|
58
50
|
}
|
|
59
51
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Optional hand-off from `opencode-rag setup` to the web UI's
|
|
3
|
+
* Configuration view.
|
|
4
|
+
*
|
|
5
|
+
* Once the workspace is configured, an interactive setup opens the browser on
|
|
6
|
+
* the Configuration page and keeps the UI server alive until the user presses
|
|
7
|
+
* Ctrl+C. Scripted runs (`-y`), non-TTY runs and `--no-ui` never launch it.
|
|
8
|
+
*/
|
|
9
|
+
/** Setup options that decide whether the Configuration UI opens. */
|
|
10
|
+
export interface SetupUiLaunchOptions {
|
|
11
|
+
/** Set to `false` by `--no-ui`. */
|
|
12
|
+
ui?: boolean;
|
|
13
|
+
/** Set by `-y`/`--yes`: scripted runs never open a browser. */
|
|
14
|
+
yes?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Decide whether a finished setup should open the Configuration UI.
|
|
18
|
+
*
|
|
19
|
+
* Deliberately conservative: the setup process stays alive while the UI is
|
|
20
|
+
* open, so it must never trigger in a scripted (`-y`), non-interactive or
|
|
21
|
+
* `--no-ui` run — those would hang a CI job or an install pipeline.
|
|
22
|
+
*
|
|
23
|
+
* @param options - Parsed setup options.
|
|
24
|
+
* @param interactive - Whether stdin/stdout are a TTY (injectable for tests).
|
|
25
|
+
* @returns `true` when the UI should be launched.
|
|
26
|
+
*/
|
|
27
|
+
export declare function shouldLaunchSetupUi(options: SetupUiLaunchOptions, interactive?: boolean): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Open the web UI on the Configuration view and keep it running until the
|
|
30
|
+
* user stops it.
|
|
31
|
+
*
|
|
32
|
+
* Best-effort by design: setup has already completed, so a failure to start
|
|
33
|
+
* the server or open a browser only prints a hint and returns. The browser
|
|
34
|
+
* link carries the per-run auth token and the `#config` hash route.
|
|
35
|
+
*
|
|
36
|
+
* @param cwd - Workspace root (defaults to the current directory).
|
|
37
|
+
*/
|
|
38
|
+
export declare function launchSetupConfigUi(cwd?: string): Promise<void>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Optional hand-off from `opencode-rag setup` to the web UI's
|
|
3
|
+
* Configuration view.
|
|
4
|
+
*
|
|
5
|
+
* Once the workspace is configured, an interactive setup opens the browser on
|
|
6
|
+
* the Configuration page and keeps the UI server alive until the user presses
|
|
7
|
+
* Ctrl+C. Scripted runs (`-y`), non-TTY runs and `--no-ui` never launch it.
|
|
8
|
+
*/
|
|
9
|
+
import { c, cleanupContext } from "./format.js";
|
|
10
|
+
import { openInBrowser } from "./browser.js";
|
|
11
|
+
import { isInteractiveTerminal } from "./prompt.js";
|
|
12
|
+
import { findConfigFile, projectConfigPath } from "../core/config.js";
|
|
13
|
+
import { resolveRagContext } from "../core/bootstrap.js";
|
|
14
|
+
/**
|
|
15
|
+
* Decide whether a finished setup should open the Configuration UI.
|
|
16
|
+
*
|
|
17
|
+
* Deliberately conservative: the setup process stays alive while the UI is
|
|
18
|
+
* open, so it must never trigger in a scripted (`-y`), non-interactive or
|
|
19
|
+
* `--no-ui` run — those would hang a CI job or an install pipeline.
|
|
20
|
+
*
|
|
21
|
+
* @param options - Parsed setup options.
|
|
22
|
+
* @param interactive - Whether stdin/stdout are a TTY (injectable for tests).
|
|
23
|
+
* @returns `true` when the UI should be launched.
|
|
24
|
+
*/
|
|
25
|
+
export function shouldLaunchSetupUi(options, interactive = isInteractiveTerminal()) {
|
|
26
|
+
if (options.ui === false)
|
|
27
|
+
return false;
|
|
28
|
+
if (options.yes === true)
|
|
29
|
+
return false;
|
|
30
|
+
return interactive;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Open the web UI on the Configuration view and keep it running until the
|
|
34
|
+
* user stops it.
|
|
35
|
+
*
|
|
36
|
+
* Best-effort by design: setup has already completed, so a failure to start
|
|
37
|
+
* the server or open a browser only prints a hint and returns. The browser
|
|
38
|
+
* link carries the per-run auth token and the `#config` hash route.
|
|
39
|
+
*
|
|
40
|
+
* @param cwd - Workspace root (defaults to the current directory).
|
|
41
|
+
*/
|
|
42
|
+
export async function launchSetupConfigUi(cwd = process.cwd()) {
|
|
43
|
+
let ctx;
|
|
44
|
+
try {
|
|
45
|
+
// Read-only context: never probe the provider or reconcile quirks during
|
|
46
|
+
// setup — the Configuration page only needs the resolved config and paths.
|
|
47
|
+
ctx = await resolveRagContext({ cwd, skipProbe: true, skipKeywordIndex: true });
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
console.log(` ${c.warn("Configuration UI skipped:")} ${err.message}`);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (ctx.config.ui?.openBrowser === false) {
|
|
54
|
+
console.log(` ${c.dim("Configuration UI: browser launch disabled (ui.openBrowser = false).")} ` +
|
|
55
|
+
`Run ${c.file("opencode-rag ui")} to open the dashboard.`);
|
|
56
|
+
await cleanupContext(ctx);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const configPath = findConfigFile(cwd) ?? projectConfigPath(cwd);
|
|
60
|
+
const port = ctx.config.ui?.port ?? 3210;
|
|
61
|
+
let server;
|
|
62
|
+
try {
|
|
63
|
+
const { startWebUi } = await import("../web/server.js");
|
|
64
|
+
try {
|
|
65
|
+
server = await startWebUi(ctx.storePath, port, cwd, ctx.dimension, ctx.config, configPath);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
if (!isAddressInUse(err) || port === 0)
|
|
69
|
+
throw err;
|
|
70
|
+
console.log(` ${c.dim(`Port ${port} is in use — using a free port for the Configuration UI.`)}`);
|
|
71
|
+
server = await startWebUi(ctx.storePath, 0, cwd, ctx.dimension, ctx.config, configPath);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
console.log(` ${c.warn("Configuration UI could not start:")} ${err.message}`);
|
|
76
|
+
console.log(` ${c.dim("Run `opencode-rag ui` later to open the dashboard.")}`);
|
|
77
|
+
await cleanupContext(ctx);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const url = `http://127.0.0.1:${server.port}/?token=${server.token}#config`;
|
|
81
|
+
console.log(`\n${c.heading("Configuration UI")}`);
|
|
82
|
+
console.log(` ${c.label("URL:")} ${c.value(url)}`);
|
|
83
|
+
console.log(` ${c.dim("The token in the URL authenticates this session — keep it private.")}`);
|
|
84
|
+
console.log(` ${c.dim("Edit the global and project settings in the browser, then press Ctrl+C to stop.")}\n`);
|
|
85
|
+
if (!(await openInBrowser(url))) {
|
|
86
|
+
console.log(` ${c.warn("Could not open the browser automatically.")} Open the URL above manually,`);
|
|
87
|
+
console.log(` ${c.dim("or run `opencode-rag ui` later to open the dashboard.")}`);
|
|
88
|
+
// Nobody is looking at a page we could not open — stop instead of hanging.
|
|
89
|
+
await closeUi(server, ctx);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
let shuttingDown = false;
|
|
93
|
+
const shutdown = async () => {
|
|
94
|
+
if (shuttingDown) {
|
|
95
|
+
// Second Ctrl+C: do not wait for the graceful close.
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
shuttingDown = true;
|
|
99
|
+
await closeUi(server, ctx);
|
|
100
|
+
process.exit(0);
|
|
101
|
+
};
|
|
102
|
+
process.on("SIGINT", shutdown);
|
|
103
|
+
process.on("SIGTERM", shutdown);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Tear down the UI server and the bootstrap context it borrowed.
|
|
107
|
+
*
|
|
108
|
+
* @param server - Running web UI handle.
|
|
109
|
+
* @param ctx - Bootstrap context created for the launch.
|
|
110
|
+
*/
|
|
111
|
+
async function closeUi(server, ctx) {
|
|
112
|
+
try {
|
|
113
|
+
await server.close();
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// best-effort — setup is finishing anyway
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
await cleanupContext(ctx);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// best-effort cleanup
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/** Whether a `listen()` error is a port conflict. */
|
|
126
|
+
function isAddressInUse(err) {
|
|
127
|
+
if (typeof err !== "object" || err === null)
|
|
128
|
+
return false;
|
|
129
|
+
if (err.code === "EADDRINUSE")
|
|
130
|
+
return true;
|
|
131
|
+
return /EADDRINUSE/.test(err.message ?? "");
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=setup-ui.js.map
|
package/dist/cli/types.d.ts
CHANGED
|
@@ -59,6 +59,11 @@ export interface SetupOptions extends WizardFlags {
|
|
|
59
59
|
workspacePlugin?: boolean;
|
|
60
60
|
/** Set to `false` by `--no-index`: do not offer to build the index. */
|
|
61
61
|
index?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Set to `false` by `--no-ui`: do not open the web UI Configuration page
|
|
64
|
+
* when an interactive setup finishes.
|
|
65
|
+
*/
|
|
66
|
+
ui?: boolean;
|
|
62
67
|
}
|
|
63
68
|
/** Shape of the `package.json` metadata required by CLI helpers. */
|
|
64
69
|
export interface PackageMetadata {
|
package/dist/core/config.d.ts
CHANGED
|
@@ -235,14 +235,21 @@ export interface DecisionConfig {
|
|
|
235
235
|
/** Decision provider name. Only "ollama" is supported for now. */
|
|
236
236
|
provider: string;
|
|
237
237
|
/**
|
|
238
|
-
* Base URL of the
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
238
|
+
* Base URL of the decision server. Root URLs (`http://127.0.0.1:11434`),
|
|
239
|
+
* the `/api`-suffixed convention used by the other sections, and the
|
|
240
|
+
* `/v1`-suffixed convention used by OpenAI-compatible servers (e.g.
|
|
241
|
+
* llama-swap) are accepted - the suffixes are stripped because decision
|
|
242
|
+
* models are served at `/v1/systemone`.
|
|
242
243
|
*/
|
|
243
244
|
baseUrl: string;
|
|
244
245
|
/** Decision model name (`tev1`/`tev1:4b` or `tev1:0.8b`). */
|
|
245
246
|
model: string;
|
|
247
|
+
/**
|
|
248
|
+
* Optional bearer key for the decision endpoint. Some servers (e.g.
|
|
249
|
+
* llama-swap) protect every route with an API key; when set, requests
|
|
250
|
+
* carry `Authorization: Bearer <apiKey>`.
|
|
251
|
+
*/
|
|
252
|
+
apiKey?: string;
|
|
246
253
|
/** Request timeout in milliseconds. The first call may load the model. */
|
|
247
254
|
timeoutMs: number;
|
|
248
255
|
/** Ollama keep_alive value (e.g. "30m", "-1" for keep-in-memory). */
|
|
@@ -274,13 +281,13 @@ export interface DecisionConfig {
|
|
|
274
281
|
* `destructive` or `malicious` probability reaches `threshold` is escalated to
|
|
275
282
|
* OpenCode's permission prompt; a clean command executes unchanged.
|
|
276
283
|
*
|
|
277
|
-
* The guard reuses the `decision` backend unless `provider`/`baseUrl`/`model
|
|
278
|
-
* override it here. It is applied through OpenCode V2's permission
|
|
284
|
+
* The guard reuses the `decision` backend unless `provider`/`baseUrl`/`model`/
|
|
285
|
+
* `apiKey` override it here. It is applied through OpenCode V2's permission
|
|
279
286
|
* `evaluate` hook, so it needs no rule changes in `opencode.json`.
|
|
280
287
|
*/
|
|
281
288
|
export interface ShellGuardConfig {
|
|
282
289
|
/**
|
|
283
|
-
* Master gate. Default false
|
|
290
|
+
* Master gate. Default false - the guard is opt-in because every shell
|
|
284
291
|
* command then waits for the local decision model.
|
|
285
292
|
*/
|
|
286
293
|
enabled: boolean;
|
|
@@ -290,6 +297,8 @@ export interface ShellGuardConfig {
|
|
|
290
297
|
baseUrl?: string;
|
|
291
298
|
/** Model override (defaults to `decision.model`). */
|
|
292
299
|
model?: string;
|
|
300
|
+
/** API-key override (defaults to `decision.apiKey`). */
|
|
301
|
+
apiKey?: string;
|
|
293
302
|
/**
|
|
294
303
|
* Flag a command when `p(destructive)` or `p(malicious)` reaches this
|
|
295
304
|
* probability (0-1). Default 0.5. Lower = more prompts; tune against the
|
|
@@ -321,6 +330,13 @@ export interface UiConfig {
|
|
|
321
330
|
port: number;
|
|
322
331
|
/** Whether to automatically open the browser on startup. */
|
|
323
332
|
openBrowser: boolean;
|
|
333
|
+
/**
|
|
334
|
+
* Dashboard color theme: `dark`, `light`, `plasma` or `drama`.
|
|
335
|
+
* Machine-wide preference, so it lives in the global config; the web UI
|
|
336
|
+
* caches it in localStorage for first paint and treats this as the source
|
|
337
|
+
* of truth on snapshot load.
|
|
338
|
+
*/
|
|
339
|
+
theme: string;
|
|
324
340
|
}
|
|
325
341
|
/** Configuration for the automated documentation mode that adds JSDoc/TSDoc to source files. */
|
|
326
342
|
export interface DocumentationModeConfig {
|
package/dist/core/config.js
CHANGED
|
@@ -376,6 +376,7 @@ export const DEFAULT_CONFIG = {
|
|
|
376
376
|
ui: {
|
|
377
377
|
port: 3210,
|
|
378
378
|
openBrowser: true,
|
|
379
|
+
theme: "dark",
|
|
379
380
|
},
|
|
380
381
|
tui: {
|
|
381
382
|
fileListKeybinding: "ctrl+enter",
|
|
@@ -612,6 +613,9 @@ export function validateConfig(config) {
|
|
|
612
613
|
if (config.ui.port < 1 || config.ui.port > 65535) {
|
|
613
614
|
warnings.push("ui.port must be between 1 and 65535");
|
|
614
615
|
}
|
|
616
|
+
if (!["dark", "light", "plasma", "drama"].includes(config.ui.theme)) {
|
|
617
|
+
warnings.push(`ui.theme "${config.ui.theme}" — expected "dark", "light", "plasma" or "drama"`);
|
|
618
|
+
}
|
|
615
619
|
}
|
|
616
620
|
if (config.description) {
|
|
617
621
|
const KNOWN_DESCRIPTION_PROVIDERS = new Set(["ollama", "openai", "anthropic", "google"]);
|
|
@@ -647,6 +651,9 @@ export function validateConfig(config) {
|
|
|
647
651
|
if (config.decision.maxStateChars != null && config.decision.maxStateChars <= 0) {
|
|
648
652
|
warnings.push("decision.maxStateChars must be > 0");
|
|
649
653
|
}
|
|
654
|
+
if (config.decision.apiKey != null && typeof config.decision.apiKey !== "string") {
|
|
655
|
+
warnings.push("decision.apiKey must be a string when set");
|
|
656
|
+
}
|
|
650
657
|
try {
|
|
651
658
|
new URL(config.decision.baseUrl);
|
|
652
659
|
}
|
|
@@ -671,7 +678,7 @@ export function validateConfig(config) {
|
|
|
671
678
|
if (sg.maxCacheEntries != null && (typeof sg.maxCacheEntries !== "number" || !Number.isFinite(sg.maxCacheEntries) || sg.maxCacheEntries < 0)) {
|
|
672
679
|
warnings.push("shellGuard.maxCacheEntries must be >= 0");
|
|
673
680
|
}
|
|
674
|
-
for (const key of ["provider", "baseUrl", "model"]) {
|
|
681
|
+
for (const key of ["provider", "baseUrl", "model", "apiKey"]) {
|
|
675
682
|
if (sg[key] != null && typeof sg[key] !== "string") {
|
|
676
683
|
warnings.push(`shellGuard.${key} must be a string when set`);
|
|
677
684
|
}
|
|
@@ -42,13 +42,14 @@ export declare class OllamaDecisionProvider implements DecisionProvider {
|
|
|
42
42
|
readonly name = "ollama";
|
|
43
43
|
private readonly baseUrl;
|
|
44
44
|
private readonly model;
|
|
45
|
+
private readonly apiKey?;
|
|
45
46
|
private readonly timeoutMs;
|
|
46
47
|
private readonly keepAlive?;
|
|
47
48
|
private readonly proxy?;
|
|
48
49
|
private readonly retryMax;
|
|
49
50
|
private readonly retryBaseDelayMs;
|
|
50
51
|
/**
|
|
51
|
-
* @param config - Decision-model configuration (endpoint, model, timeout, proxy, retries).
|
|
52
|
+
* @param config - Decision-model configuration (endpoint, model, api key, timeout, proxy, retries).
|
|
52
53
|
*/
|
|
53
54
|
constructor(config: DecisionConfig);
|
|
54
55
|
/**
|
|
@@ -22,7 +22,21 @@ export const SYSTEMONE_MAX_OPTIONS = 24;
|
|
|
22
22
|
*/
|
|
23
23
|
export function resolveSystemOneUrl(baseUrl) {
|
|
24
24
|
const trimmed = baseUrl.replace(/\/+$/, "");
|
|
25
|
-
|
|
25
|
+
// Accept root, the `/api` suffix used by the embedding/description
|
|
26
|
+
// sections, and the `/v1` suffix used by OpenAI-compatible servers
|
|
27
|
+
// (e.g. llama-swap). Both suffixes are stripped because the decision
|
|
28
|
+
// route is `/v1/systemone`.
|
|
29
|
+
let root = trimmed;
|
|
30
|
+
let changed = true;
|
|
31
|
+
while (changed) {
|
|
32
|
+
changed = false;
|
|
33
|
+
for (const suffix of ["/api", "/v1"]) {
|
|
34
|
+
if (root.endsWith(suffix)) {
|
|
35
|
+
root = root.slice(0, -suffix.length).replace(/\/+$/, "");
|
|
36
|
+
changed = true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
26
40
|
return `${root}/v1/systemone`;
|
|
27
41
|
}
|
|
28
42
|
/** Coerce a number-or-numeric-string to a finite number, else undefined. */
|
|
@@ -117,17 +131,19 @@ export class OllamaDecisionProvider {
|
|
|
117
131
|
name = "ollama";
|
|
118
132
|
baseUrl;
|
|
119
133
|
model;
|
|
134
|
+
apiKey;
|
|
120
135
|
timeoutMs;
|
|
121
136
|
keepAlive;
|
|
122
137
|
proxy;
|
|
123
138
|
retryMax;
|
|
124
139
|
retryBaseDelayMs;
|
|
125
140
|
/**
|
|
126
|
-
* @param config - Decision-model configuration (endpoint, model, timeout, proxy, retries).
|
|
141
|
+
* @param config - Decision-model configuration (endpoint, model, api key, timeout, proxy, retries).
|
|
127
142
|
*/
|
|
128
143
|
constructor(config) {
|
|
129
144
|
this.baseUrl = config.baseUrl;
|
|
130
145
|
this.model = config.model;
|
|
146
|
+
this.apiKey = config.apiKey?.trim() || undefined;
|
|
131
147
|
this.timeoutMs = config.timeoutMs > 0 ? config.timeoutMs : 120000;
|
|
132
148
|
this.keepAlive = config.keepAlive;
|
|
133
149
|
this.proxy = config.proxy;
|
|
@@ -163,11 +179,14 @@ export class OllamaDecisionProvider {
|
|
|
163
179
|
`Shorten \`state\` or ask fewer questions.`);
|
|
164
180
|
}
|
|
165
181
|
const url = resolveSystemOneUrl(this.baseUrl);
|
|
182
|
+
const headers = this.apiKey
|
|
183
|
+
? { Authorization: `Bearer ${this.apiKey}` }
|
|
184
|
+
: {};
|
|
166
185
|
let lastError;
|
|
167
186
|
for (let attempt = 0; attempt <= this.retryMax; attempt++) {
|
|
168
187
|
let response;
|
|
169
188
|
try {
|
|
170
|
-
response = await postJson(url, body,
|
|
189
|
+
response = await postJson(url, body, headers, this.timeoutMs, this.proxy, abort);
|
|
171
190
|
}
|
|
172
191
|
catch (err) {
|
|
173
192
|
lastError = err instanceof Error ? err : new Error(String(err));
|
|
@@ -211,6 +230,10 @@ export class OllamaDecisionProvider {
|
|
|
211
230
|
*/
|
|
212
231
|
describeHttpError(status, text) {
|
|
213
232
|
const detail = truncate(text);
|
|
233
|
+
if (status === 401 || status === 403) {
|
|
234
|
+
return (`Decision endpoint unauthorized (${status}) - the server requires an API key. ` +
|
|
235
|
+
`Set \`decision.apiKey\` (e.g. llama-swap's "api_key"). ${detail}`);
|
|
236
|
+
}
|
|
214
237
|
if (status === 404) {
|
|
215
238
|
const lower = text.toLowerCase();
|
|
216
239
|
const modelLower = this.model.toLowerCase();
|
|
@@ -223,7 +246,7 @@ export class OllamaDecisionProvider {
|
|
|
223
246
|
return (`Decision request not found (404) — tev1 requires Ollama >= 0.35 and the model must be pulled ` +
|
|
224
247
|
`(\`ollama pull ${this.model}\`). ${detail}`);
|
|
225
248
|
}
|
|
226
|
-
return `
|
|
249
|
+
return `Decision request failed (${status}): ${detail}`;
|
|
227
250
|
}
|
|
228
251
|
/** Exponential backoff between retries. */
|
|
229
252
|
sleep(attempt) {
|
|
@@ -197,7 +197,9 @@ export class ShellGuard {
|
|
|
197
197
|
};
|
|
198
198
|
}
|
|
199
199
|
const { guard, decision, logging } = cfg;
|
|
200
|
-
|
|
200
|
+
// The API key participates in the signature so a key change rebuilds the
|
|
201
|
+
// provider (the key never leaves this in-memory cache/state).
|
|
202
|
+
const signature = `${decision.provider}|${decision.baseUrl}|${decision.model}|${decision.apiKey ?? ""}`;
|
|
201
203
|
const cacheKey = `${signature}\u0000${command}`;
|
|
202
204
|
const cacheTtlMs = guard.cacheTtlMs ?? 0;
|
|
203
205
|
if (cacheTtlMs > 0) {
|
|
@@ -360,6 +362,7 @@ export function resolveShellGuardRuntimeConfig(cfg, directory) {
|
|
|
360
362
|
provider: guard.provider?.trim() || base.provider,
|
|
361
363
|
baseUrl: guard.baseUrl?.trim() || base.baseUrl,
|
|
362
364
|
model: guard.model?.trim() || base.model,
|
|
365
|
+
apiKey: guard.apiKey?.trim() || base.apiKey,
|
|
363
366
|
};
|
|
364
367
|
const log = resolveLogConfig(cfg);
|
|
365
368
|
return {
|
package/dist/web/api.d.ts
CHANGED
|
@@ -28,9 +28,16 @@ interface ApiResponse {
|
|
|
28
28
|
* @param getEmbedder - Lazily-created embedder for /api/retrieve and reindex passes.
|
|
29
29
|
* @param token - Per-run auth token required on every request.
|
|
30
30
|
* @param configPath - Path to the opencode-rag.json config file, used by PUT /api/config.
|
|
31
|
+
* @param onConfigChanged - Called after a layered config write (reset embedder/caches).
|
|
31
32
|
* @returns An async handler that returns `true` when a route matched or `false` otherwise.
|
|
32
33
|
*/
|
|
33
|
-
export declare function createApiHandler(store: ChunkBrowseStore, keywordIndex: KeywordIndex, storePath: string, cwd?: string, cfg?: RagConfig, getEmbedder?: () => Promise<EmbeddingProvider>, token?: string, configPath?: string): (req: IncomingMessage, res: ServerResponse) => Promise<boolean>;
|
|
34
|
+
export declare function createApiHandler(store: ChunkBrowseStore, keywordIndex: KeywordIndex, storePath: string, cwd?: string, cfg?: RagConfig, getEmbedder?: () => Promise<EmbeddingProvider>, token?: string, configPath?: string, onConfigChanged?: (cfg: RagConfig, changedPaths: string[][]) => void): (req: IncomingMessage, res: ServerResponse) => Promise<boolean>;
|
|
35
|
+
/**
|
|
36
|
+
* Return the effective configuration with API keys redacted.
|
|
37
|
+
*
|
|
38
|
+
* Retained for the legacy `/api/config` contract used by embedded clients.
|
|
39
|
+
*/
|
|
40
|
+
export declare function handleConfig(cfg: RagConfig): ApiResponse;
|
|
34
41
|
/**
|
|
35
42
|
* Apply a validated config patch (`{ indexing: { includeDirs: [...] } }`)
|
|
36
43
|
* to the on-disk config file and refresh the in-memory config used by
|