opencode-rag-plugin 2.4.3 → 2.4.5

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.
@@ -43,7 +43,27 @@ export declare function buildOpencodeConfig(existing: Record<string, unknown> |
43
43
  */
44
44
  export declare function removeStaleGlobalPluginRegistrations(homeDir: string, pluginName: string): string[];
45
45
  /**
46
- * Generate the content for `.opencode/plugins/rag-plugin.js`.
46
+ * Workspace plugin directory (`.opencode/plugins/opencode-rag/`).
47
+ *
48
+ * OpenCode 2 loads plugin *directories* under `.opencode/plugins/`: the
49
+ * `index.*` file is the server (business) entrypoint and `tui.*` beside it is
50
+ * the CLI entrypoint — the TUI only discovers directory targets, so a flat
51
+ * `rag-tui.js` is never registered with the terminal UI.
52
+ */
53
+ export declare const WORKSPACE_PLUGIN_DIR = "opencode-rag";
54
+ /** Relative path (from the workspace root) of the generated server entrypoint. */
55
+ export declare const WORKSPACE_PLUGIN_ENTRY = ".opencode/plugins/opencode-rag/index.js";
56
+ /** Relative path (from the workspace root) of the generated TUI entrypoint. */
57
+ export declare const WORKSPACE_TUI_ENTRY = ".opencode/plugins/opencode-rag/tui.js";
58
+ /** V1-era flat plugin files, superseded by {@link WORKSPACE_PLUGIN_DIR}. */
59
+ export declare const LEGACY_PLUGIN_ENTRY = ".opencode/plugins/rag-plugin.js";
60
+ /** V1-era flat TUI plugin file, superseded by {@link WORKSPACE_TUI_ENTRY}. */
61
+ export declare const LEGACY_TUI_ENTRY = ".opencode/plugins/rag-tui.js";
62
+ /** V1-era TUI config file (OpenCode 2 reads CLI plugins from discovery, not this). */
63
+ export declare const LEGACY_TUI_CONFIG = ".opencode/tui.json";
64
+ /**
65
+ * Generate the content for the server entrypoint
66
+ * (`.opencode/plugins/opencode-rag/index.js`).
47
67
  *
48
68
  * This file re-exports the plugin from the workspace-local node_modules.
49
69
  * The plugin entry default-exports the OpenCode V2 module shape
@@ -54,14 +74,30 @@ export declare function removeStaleGlobalPluginRegistrations(homeDir: string, pl
54
74
  */
55
75
  export declare function generateWorkspacePluginFile(packageName: string): string;
56
76
  /**
57
- * Generate the content for `.opencode/plugins/rag-tui.js`.
77
+ * Generate the content for the TUI entrypoint
78
+ * (`.opencode/plugins/opencode-rag/tui.js`).
58
79
  *
59
- * This file re-exports the TUI plugin from the workspace-local node_modules.
80
+ * OpenCode resolves this file beside the server entrypoint in the same plugin
81
+ * directory; the TUI role loads it, the server role never touches it.
60
82
  *
61
83
  * @param packageName - The npm package name of the RAG plugin.
62
84
  * @returns The JavaScript source code for the TUI plugin entry file.
63
85
  */
64
86
  export declare function generateWorkspaceTuiPluginFile(packageName: string): string;
87
+ /**
88
+ * Content of the V1-era flat server entrypoint (`.opencode/plugins/rag-plugin.js`).
89
+ *
90
+ * Used to recognize — and safely migrate away from — files this command wrote
91
+ * before OpenCode 2 directory discovery. Recognized by exact content match, so
92
+ * hand-written files are never deleted.
93
+ */
94
+ export declare function generateLegacyWorkspacePluginFile(packageName: string): string;
95
+ /** Content of the V1-era flat TUI entrypoint (`.opencode/plugins/rag-tui.js`). */
96
+ export declare function generateLegacyWorkspaceTuiPluginFile(packageName: string): string;
97
+ /** Content of the V1-era `.opencode/tui.json`. */
98
+ export declare function buildLegacyTuiConfig(): {
99
+ plugin: string[];
100
+ };
65
101
  /**
66
102
  * Generate the content for `.opencode/skills/opencode-rag/SKILL.md`.
67
103
  *
@@ -63,7 +63,7 @@ export function buildOpencodeConfig(existing) {
63
63
  if (typeof next.$schema !== "string") {
64
64
  next.$schema = "https://opencode.ai/config.json";
65
65
  }
66
- // Plugin is loaded via .opencode/plugins/rag-plugin.js auto-discovery,
66
+ // Plugin is loaded via `.opencode/plugins/opencode-rag/` auto-discovery,
67
67
  // not via npm package resolution. Stale "plugin" entries from older
68
68
  // init versions would trigger npm install (which fails due to native
69
69
  // dependencies like sharp) and produce "Plugin export is not a function".
@@ -134,7 +134,27 @@ export function removeStaleGlobalPluginRegistrations(homeDir, pluginName) {
134
134
  return updatedPaths;
135
135
  }
136
136
  /**
137
- * Generate the content for `.opencode/plugins/rag-plugin.js`.
137
+ * Workspace plugin directory (`.opencode/plugins/opencode-rag/`).
138
+ *
139
+ * OpenCode 2 loads plugin *directories* under `.opencode/plugins/`: the
140
+ * `index.*` file is the server (business) entrypoint and `tui.*` beside it is
141
+ * the CLI entrypoint — the TUI only discovers directory targets, so a flat
142
+ * `rag-tui.js` is never registered with the terminal UI.
143
+ */
144
+ export const WORKSPACE_PLUGIN_DIR = "opencode-rag";
145
+ /** Relative path (from the workspace root) of the generated server entrypoint. */
146
+ export const WORKSPACE_PLUGIN_ENTRY = `.opencode/plugins/${WORKSPACE_PLUGIN_DIR}/index.js`;
147
+ /** Relative path (from the workspace root) of the generated TUI entrypoint. */
148
+ export const WORKSPACE_TUI_ENTRY = `.opencode/plugins/${WORKSPACE_PLUGIN_DIR}/tui.js`;
149
+ /** V1-era flat plugin files, superseded by {@link WORKSPACE_PLUGIN_DIR}. */
150
+ export const LEGACY_PLUGIN_ENTRY = ".opencode/plugins/rag-plugin.js";
151
+ /** V1-era flat TUI plugin file, superseded by {@link WORKSPACE_TUI_ENTRY}. */
152
+ export const LEGACY_TUI_ENTRY = ".opencode/plugins/rag-tui.js";
153
+ /** V1-era TUI config file (OpenCode 2 reads CLI plugins from discovery, not this). */
154
+ export const LEGACY_TUI_CONFIG = ".opencode/tui.json";
155
+ /**
156
+ * Generate the content for the server entrypoint
157
+ * (`.opencode/plugins/opencode-rag/index.js`).
138
158
  *
139
159
  * This file re-exports the plugin from the workspace-local node_modules.
140
160
  * The plugin entry default-exports the OpenCode V2 module shape
@@ -145,26 +165,46 @@ export function removeStaleGlobalPluginRegistrations(homeDir, pluginName) {
145
165
  */
146
166
  export function generateWorkspacePluginFile(packageName) {
147
167
  return [
148
- `import plugin from "../node_modules/${packageName}/dist/plugin-entry.js";`,
168
+ `import plugin from "../../node_modules/${packageName}/dist/plugin-entry.js";`,
149
169
  `export default plugin;`,
150
170
  "",
151
171
  ].join("\n");
152
172
  }
153
173
  /**
154
- * Generate the content for `.opencode/plugins/rag-tui.js`.
174
+ * Generate the content for the TUI entrypoint
175
+ * (`.opencode/plugins/opencode-rag/tui.js`).
155
176
  *
156
- * This file re-exports the TUI plugin from the workspace-local node_modules.
177
+ * OpenCode resolves this file beside the server entrypoint in the same plugin
178
+ * directory; the TUI role loads it, the server role never touches it.
157
179
  *
158
180
  * @param packageName - The npm package name of the RAG plugin.
159
181
  * @returns The JavaScript source code for the TUI plugin entry file.
160
182
  */
161
183
  export function generateWorkspaceTuiPluginFile(packageName) {
162
184
  return [
163
- `import plugin from "../node_modules/${packageName}/dist/tui.js";`,
185
+ `import plugin from "../../node_modules/${packageName}/dist/tui.js";`,
164
186
  `export default plugin;`,
165
187
  "",
166
188
  ].join("\n");
167
189
  }
190
+ /**
191
+ * Content of the V1-era flat server entrypoint (`.opencode/plugins/rag-plugin.js`).
192
+ *
193
+ * Used to recognize — and safely migrate away from — files this command wrote
194
+ * before OpenCode 2 directory discovery. Recognized by exact content match, so
195
+ * hand-written files are never deleted.
196
+ */
197
+ export function generateLegacyWorkspacePluginFile(packageName) {
198
+ return [`import plugin from "../node_modules/${packageName}/dist/plugin-entry.js";`, `export default plugin;`, ""].join("\n");
199
+ }
200
+ /** Content of the V1-era flat TUI entrypoint (`.opencode/plugins/rag-tui.js`). */
201
+ export function generateLegacyWorkspaceTuiPluginFile(packageName) {
202
+ return [`import plugin from "../node_modules/${packageName}/dist/tui.js";`, `export default plugin;`, ""].join("\n");
203
+ }
204
+ /** Content of the V1-era `.opencode/tui.json`. */
205
+ export function buildLegacyTuiConfig() {
206
+ return { plugin: ["./plugins/rag-tui.js"] };
207
+ }
168
208
  /**
169
209
  * Generate the content for `.opencode/skills/opencode-rag/SKILL.md`.
170
210
  *
@@ -10,13 +10,13 @@
10
10
  * installation.
11
11
  */
12
12
  import path from "node:path";
13
- import { existsSync, mkdirSync, readFileSync, writeFileSync, copyFileSync } from "node:fs";
13
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync, copyFileSync } from "node:fs";
14
14
  import { loadConfig, findConfigFile } from "../../core/config.js";
15
15
  import { checkProviderHealth, pullOllamaModels } from "../../embedder/health.js";
16
16
  import { destroyAllPooledConnections } from "../../embedder/http.js";
17
17
  import { c } from "../format.js";
18
18
  import { getPackageMetadata, readJsonObject, writeJsonFile } from "../helpers.js";
19
- import { buildOpencodeConfig, buildWorkspacePackageJson, generateDefaultConfigJson, generateSkillFile, generateDecisionSkillFile, generateWorkspacePluginFile, generateWorkspaceTuiPluginFile, installPluginFromGlobal, mergeAgentsMdContent, mergeGitignoreContent, } from "./init-helpers.js";
19
+ import { buildLegacyTuiConfig, buildOpencodeConfig, buildWorkspacePackageJson, generateDefaultConfigJson, generateSkillFile, generateDecisionSkillFile, generateLegacyWorkspacePluginFile, generateLegacyWorkspaceTuiPluginFile, generateWorkspacePluginFile, generateWorkspaceTuiPluginFile, installPluginFromGlobal, mergeAgentsMdContent, mergeGitignoreContent, LEGACY_PLUGIN_ENTRY, LEGACY_TUI_CONFIG, LEGACY_TUI_ENTRY, WORKSPACE_PLUGIN_DIR, WORKSPACE_PLUGIN_ENTRY, WORKSPACE_TUI_ENTRY, } from "./init-helpers.js";
20
20
  import { detectOllamaBackend } from "./backend-detect.js";
21
21
  /**
22
22
  * Register the `init` command on the given Commander program.
@@ -65,9 +65,12 @@ export async function runWorkspaceInit(options = {}) {
65
65
  const gitignorePath = path.join(opencodeDir, ".gitignore");
66
66
  const opencodeConfigPath = path.join(opencodeDir, "opencode.json");
67
67
  const pluginsDir = path.join(opencodeDir, "plugins");
68
- const pluginEntryPath = path.join(pluginsDir, "rag-plugin.js");
69
- const tuiPluginEntryPath = path.join(pluginsDir, "rag-tui.js");
70
- const tuiConfigPath = path.join(opencodeDir, "tui.json");
68
+ const workspacePluginDir = path.join(pluginsDir, WORKSPACE_PLUGIN_DIR);
69
+ const pluginEntryPath = path.join(workspacePluginDir, "index.js");
70
+ const tuiPluginEntryPath = path.join(workspacePluginDir, "tui.js");
71
+ const legacyPluginEntryPath = path.join(pluginsDir, "rag-plugin.js");
72
+ const legacyTuiPluginEntryPath = path.join(pluginsDir, "rag-tui.js");
73
+ const legacyTuiConfigPath = path.join(opencodeDir, "tui.json");
71
74
  const opencodePackagePath = path.join(opencodeDir, "package.json");
72
75
  console.log(`\n${c.heading("Initializing OpenCodeRAG in workspace...")}\n`);
73
76
  if (!existsSync(opencodeDir)) {
@@ -111,44 +114,69 @@ export async function runWorkspaceInit(options = {}) {
111
114
  else {
112
115
  console.log(` ${c.exists("Exists:")} .opencode/opencode.json`);
113
116
  }
117
+ // OpenCode 2 discovers plugin *directories* under `.opencode/plugins/`:
118
+ // `index.js` is the server (business) entrypoint and `tui.js` beside it
119
+ // is the CLI entrypoint. Flat `.js` files only reach the server role, so
120
+ // the terminal UI never saw the TUI plugin before this layout.
121
+ if (!existsSync(workspacePluginDir)) {
122
+ mkdirSync(workspacePluginDir, { recursive: true });
123
+ console.log(` ${c.created("Created:")} .opencode/plugins/${WORKSPACE_PLUGIN_DIR}/`);
124
+ }
114
125
  const pluginEntryExists = existsSync(pluginEntryPath);
115
126
  const pluginEntryContent = generateWorkspacePluginFile(packageMetadata.name);
116
127
  if (!pluginEntryExists || options.force) {
117
128
  writeFileSync(pluginEntryPath, pluginEntryContent, "utf-8");
118
- console.log(` ${pluginEntryExists ? c.updated("Updated:") : c.created("Created:")} .opencode/plugins/rag-plugin.js`);
129
+ console.log(` ${pluginEntryExists ? c.updated("Updated:") : c.created("Created:")} ${WORKSPACE_PLUGIN_ENTRY}`);
119
130
  }
120
131
  else if (readFileSync(pluginEntryPath, "utf-8") !== pluginEntryContent) {
121
132
  writeFileSync(pluginEntryPath, pluginEntryContent, "utf-8");
122
- console.log(` ${c.updated("Updated:")} .opencode/plugins/rag-plugin.js`);
133
+ console.log(` ${c.updated("Updated:")} ${WORKSPACE_PLUGIN_ENTRY}`);
123
134
  }
124
135
  else {
125
- console.log(` ${c.exists("Exists:")} .opencode/plugins/rag-plugin.js`);
136
+ console.log(` ${c.exists("Exists:")} ${WORKSPACE_PLUGIN_ENTRY}`);
126
137
  }
127
138
  const tuiPluginEntryExists = existsSync(tuiPluginEntryPath);
128
139
  const tuiPluginEntryContent = generateWorkspaceTuiPluginFile(packageMetadata.name);
129
140
  if (!tuiPluginEntryExists || options.force) {
130
141
  writeFileSync(tuiPluginEntryPath, tuiPluginEntryContent, "utf-8");
131
- console.log(` ${tuiPluginEntryExists ? c.updated("Updated:") : c.created("Created:")} .opencode/plugins/rag-tui.js`);
142
+ console.log(` ${tuiPluginEntryExists ? c.updated("Updated:") : c.created("Created:")} ${WORKSPACE_TUI_ENTRY}`);
132
143
  }
133
144
  else if (readFileSync(tuiPluginEntryPath, "utf-8") !== tuiPluginEntryContent) {
134
145
  writeFileSync(tuiPluginEntryPath, tuiPluginEntryContent, "utf-8");
135
- console.log(` ${c.updated("Updated:")} .opencode/plugins/rag-tui.js`);
146
+ console.log(` ${c.updated("Updated:")} ${WORKSPACE_TUI_ENTRY}`);
136
147
  }
137
148
  else {
138
- console.log(` ${c.exists("Exists:")} .opencode/plugins/rag-tui.js`);
139
- }
140
- const tuiConfigExists = existsSync(tuiConfigPath);
141
- const nextTuiConfig = { plugin: ["./plugins/rag-tui.js"] };
142
- if (!tuiConfigExists || options.force) {
143
- writeJsonFile(tuiConfigPath, nextTuiConfig);
144
- console.log(` ${tuiConfigExists ? c.updated("Updated:") : c.created("Created:")} .opencode/tui.json`);
145
- }
146
- else if (JSON.stringify(readJsonObject(tuiConfigPath)) !== JSON.stringify(nextTuiConfig)) {
147
- writeJsonFile(tuiConfigPath, nextTuiConfig);
148
- console.log(` ${c.updated("Updated:")} .opencode/tui.json`);
149
+ console.log(` ${c.exists("Exists:")} ${WORKSPACE_TUI_ENTRY}`);
150
+ }
151
+ // Migrate away from the V1-era flat entries: a leftover `rag-plugin.js`
152
+ // registers the server plugin a second time, and `rag-tui.js` is dead
153
+ // weight (the TUI never loads flat files). Only files whose content is
154
+ // exactly what an earlier `init` wrote are removed — hand-written files
155
+ // and custom `.opencode/tui.json` configs are left untouched.
156
+ const legacyEntries = [
157
+ [legacyPluginEntryPath, generateLegacyWorkspacePluginFile(packageMetadata.name), LEGACY_PLUGIN_ENTRY],
158
+ [legacyTuiPluginEntryPath, generateLegacyWorkspaceTuiPluginFile(packageMetadata.name), LEGACY_TUI_ENTRY],
159
+ ];
160
+ for (const [legacyPath, legacyContent, legacyRel] of legacyEntries) {
161
+ if (!existsSync(legacyPath))
162
+ continue;
163
+ if (readFileSync(legacyPath, "utf-8") === legacyContent) {
164
+ unlinkSync(legacyPath);
165
+ console.log(` ${c.updated("Removed:")} ${legacyRel} (superseded by ${WORKSPACE_PLUGIN_DIR}/)`);
166
+ }
167
+ else {
168
+ console.log(` ${c.warn("Kept:")} ${legacyRel} (modified locally — no longer loaded by OpenCode 2)`);
169
+ }
149
170
  }
150
- else {
151
- console.log(` ${c.exists("Exists:")} .opencode/tui.json`);
171
+ if (existsSync(legacyTuiConfigPath)) {
172
+ const sameLegacyConfig = JSON.stringify(readJsonObject(legacyTuiConfigPath)) === JSON.stringify(buildLegacyTuiConfig());
173
+ if (sameLegacyConfig) {
174
+ unlinkSync(legacyTuiConfigPath);
175
+ console.log(` ${c.updated("Removed:")} ${LEGACY_TUI_CONFIG} (V1 config — OpenCode 2 discovers CLI plugins)`);
176
+ }
177
+ else {
178
+ console.log(` ${c.warn("Kept:")} ${LEGACY_TUI_CONFIG} (V1 config — ignored by OpenCode 2)`);
179
+ }
152
180
  }
153
181
  const skillsDir = path.join(opencodeDir, "skills");
154
182
  const skillDir = path.join(skillsDir, "opencode-rag");
@@ -427,7 +455,13 @@ export function isLikelyProjectRoot(cwd) {
427
455
  * @returns Whether the workspace looks initialized.
428
456
  */
429
457
  export function isWorkspaceInitialized(cwd) {
430
- return (existsSync(path.join(cwd, ".opencode", "plugins", "rag-plugin.js")) &&
431
- existsSync(path.join(cwd, ".opencode", "tui.json")));
458
+ // V2 layout: plugin directory with server + TUI entrypoints beside each other.
459
+ if (existsSync(path.join(cwd, ".opencode", "plugins", WORKSPACE_PLUGIN_DIR, "index.js")) &&
460
+ existsSync(path.join(cwd, ".opencode", "plugins", WORKSPACE_PLUGIN_DIR, "tui.js"))) {
461
+ return true;
462
+ }
463
+ // V1 layout (flat entries + .opencode/tui.json): treated as *not* initialized
464
+ // so `setup` re-runs `init` once and migrates the workspace.
465
+ return false;
432
466
  }
433
467
  //# sourceMappingURL=init.js.map
@@ -19,6 +19,7 @@ function checkOpenCodeRunning() {
19
19
  execSync('tasklist /FI "IMAGENAME eq opencode.exe" 2>nul | find /I "opencode.exe" >nul', {
20
20
  timeout: 3_000,
21
21
  stdio: "ignore",
22
+ windowsHide: true,
22
23
  });
23
24
  console.log(`\n ${c.warn("OpenCode is currently running.")} Restart it to load the updated plugin.`);
24
25
  }
@@ -26,6 +27,7 @@ function checkOpenCodeRunning() {
26
27
  const pids = execSync("pgrep -x opencode 2>/dev/null", {
27
28
  encoding: "utf-8",
28
29
  timeout: 3_000,
30
+ windowsHide: true,
29
31
  }).trim();
30
32
  if (pids) {
31
33
  console.log(`\n ${c.warn("OpenCode is currently running.")} Restart it to load the updated plugin.`);
@@ -46,7 +46,7 @@ export function registerUiCommand(program) {
46
46
  const { spawn } = await import("node:child_process");
47
47
  try {
48
48
  if (process.platform === "win32") {
49
- spawn("cmd.exe", ["/c", "start", url], { detached: true, stdio: "ignore" }).unref();
49
+ spawn("cmd.exe", ["/c", "start", url], { detached: true, stdio: "ignore", windowsHide: true }).unref();
50
50
  }
51
51
  else {
52
52
  const cmd = process.platform === "darwin" ? "open" : "xdg-open";
@@ -533,8 +533,10 @@ export interface RagConfig {
533
533
  readNoResultsBehavior?: ReadNoResultsBehavior;
534
534
  /** Maximum related files shown when read results are empty. */
535
535
  readRelatedFilesMax?: number;
536
- /** Whether to inject RAG tool guidance into system prompts (default true). */
536
+ /** Whether to inject RAG tool guidance into system prompts when the session's tool catalog exposes the RAG tools (default true). */
537
537
  injectSystemPrompt?: boolean;
538
+ /** Whether to grant the read-only RAG tools to the built-in `explore` agent (default true). */
539
+ exploreAgentTools?: boolean;
538
540
  };
539
541
  /** Custom chunker module registrations. */
540
542
  chunkers?: ChunkerConfig[];
@@ -164,6 +164,7 @@ export const DEFAULT_CONFIG = {
164
164
  maxContextChunks: 10,
165
165
  readOverride: true,
166
166
  injectSystemPrompt: true,
167
+ exploreAgentTools: true,
167
168
  autoIndex: {
168
169
  enabled: false,
169
170
  debounceMs: 2000,
@@ -22,7 +22,7 @@ function tryRun(command, deps) {
22
22
  try {
23
23
  const out = deps.exec
24
24
  ? deps.exec(command, EXEC_TIMEOUT_MS)
25
- : execSync(command, { encoding: "utf-8", timeout: EXEC_TIMEOUT_MS, stdio: ["ignore", "pipe", "ignore"] });
25
+ : execSync(command, { encoding: "utf-8", timeout: EXEC_TIMEOUT_MS, stdio: ["ignore", "pipe", "ignore"], windowsHide: true });
26
26
  const trimmed = out.trim();
27
27
  return trimmed || null;
28
28
  }
@@ -171,6 +171,7 @@ export async function setupRuntime(options) {
171
171
  execSync(sdkInstallCommand, {
172
172
  stdio: "pipe",
173
173
  timeout: 60_000,
174
+ windowsHide: true,
174
175
  });
175
176
  }
176
177
  catch (cause) {
@@ -127,7 +127,10 @@ export async function checkForUpdate(currentVersion) {
127
127
  export async function installLatestUpdate(options) {
128
128
  const verbose = options?.verbose ?? false;
129
129
  const stdio = verbose ? "inherit" : "pipe";
130
- const run = options?._execSync ?? execSync;
130
+ // Default runner hides the console window on Windows — the plugin runs in
131
+ // OpenCode's console-less service process, so any un-hidden spawn would
132
+ // flash a terminal window.
133
+ const run = options?._execSync ?? ((command, opts) => execSync(command, { ...opts, windowsHide: true }));
131
134
  const syncRuntime = options?._setupRuntime ?? setupRuntime;
132
135
  const readVersion = options?._getCurrentVersion ?? getCurrentVersion;
133
136
  const fromVersion = readVersion();
@@ -59,9 +59,11 @@ function getGitInfo() {
59
59
  try {
60
60
  const branch = execSync("git rev-parse --abbrev-ref HEAD", {
61
61
  encoding: "utf-8",
62
+ windowsHide: true,
62
63
  }).trim();
63
64
  const commit = execSync("git rev-parse --short HEAD", {
64
65
  encoding: "utf-8",
66
+ windowsHide: true,
65
67
  }).trim();
66
68
  return { branch, commit };
67
69
  }
@@ -1,5 +1,11 @@
1
1
  /**
2
2
  * @fileoverview Uses git to detect changed, deleted, and untracked files for incremental indexing.
3
+ *
4
+ * Every git invocation sets `windowsHide: true`. The plugin runs inside
5
+ * OpenCode's console-less service process (`opencode serve --service`); without
6
+ * this option Windows allocates a new visible console (a Windows Terminal
7
+ * window/tab on systems where WT is the default terminal) for each spawn,
8
+ * which shows up as a flickering terminal window per index pass.
3
9
  */
4
10
  import { execFileSync } from "node:child_process";
5
11
  /**
@@ -15,6 +21,7 @@ export function getRepoRoot(cwd) {
15
21
  encoding: "utf-8",
16
22
  timeout: 5000,
17
23
  stdio: ["ignore", "pipe", "ignore"],
24
+ windowsHide: true,
18
25
  }).trim();
19
26
  }
20
27
  catch {
@@ -34,6 +41,7 @@ export function getCurrentCommit(cwd) {
34
41
  encoding: "utf-8",
35
42
  timeout: 5000,
36
43
  stdio: ["ignore", "pipe", "ignore"],
44
+ windowsHide: true,
37
45
  }).trim();
38
46
  }
39
47
  catch {
@@ -54,10 +62,10 @@ export function getChangedFilesSince(cwd, fromCommit) {
54
62
  return null;
55
63
  try {
56
64
  const changedRaw = execFileSync("git", ["diff", "--name-only", "--diff-filter=ACMRT", fromCommit, "HEAD"], {
57
- cwd, encoding: "utf-8", timeout: 10000, stdio: ["ignore", "pipe", "ignore"],
65
+ cwd, encoding: "utf-8", timeout: 10000, stdio: ["ignore", "pipe", "ignore"], windowsHide: true,
58
66
  }).trim();
59
67
  const deletedRaw = execFileSync("git", ["diff", "--name-only", "--diff-filter=D", fromCommit, "HEAD"], {
60
- cwd, encoding: "utf-8", timeout: 10000, stdio: ["ignore", "pipe", "ignore"],
68
+ cwd, encoding: "utf-8", timeout: 10000, stdio: ["ignore", "pipe", "ignore"], windowsHide: true,
61
69
  }).trim();
62
70
  const changedFiles = changedRaw.length > 0 ? changedRaw.split("\n") : [];
63
71
  const deletedFiles = deletedRaw.length > 0 ? deletedRaw.split("\n") : [];
@@ -79,7 +87,7 @@ export function getChangedFilesSince(cwd, fromCommit) {
79
87
  export function getUntrackedFiles(cwd) {
80
88
  try {
81
89
  const raw = execFileSync("git", ["ls-files", "--others", "--exclude-standard"], {
82
- cwd, encoding: "utf-8", timeout: 5000, stdio: ["ignore", "pipe", "ignore"],
90
+ cwd, encoding: "utf-8", timeout: 5000, stdio: ["ignore", "pipe", "ignore"], windowsHide: true,
83
91
  }).trim();
84
92
  return raw.length > 0 ? raw.split("\n") : [];
85
93
  }
@@ -98,13 +106,13 @@ export function getUntrackedFiles(cwd) {
98
106
  export function getWorkingTreeChanges(cwd) {
99
107
  try {
100
108
  const modifiedRaw = execFileSync("git", ["diff-index", "--name-only", "-M", "HEAD"], {
101
- cwd, encoding: "utf-8", timeout: 10000, stdio: ["ignore", "pipe", "ignore"],
109
+ cwd, encoding: "utf-8", timeout: 10000, stdio: ["ignore", "pipe", "ignore"], windowsHide: true,
102
110
  }).trim();
103
111
  const deletedRaw = execFileSync("git", ["diff", "--name-only", "--diff-filter=D", "HEAD"], {
104
- cwd, encoding: "utf-8", timeout: 10000, stdio: ["ignore", "pipe", "ignore"],
112
+ cwd, encoding: "utf-8", timeout: 10000, stdio: ["ignore", "pipe", "ignore"], windowsHide: true,
105
113
  }).trim();
106
114
  const untrackedRaw = execFileSync("git", ["ls-files", "--others", "--exclude-standard"], {
107
- cwd, encoding: "utf-8", timeout: 5000, stdio: ["ignore", "pipe", "ignore"],
115
+ cwd, encoding: "utf-8", timeout: 5000, stdio: ["ignore", "pipe", "ignore"], windowsHide: true,
108
116
  }).trim();
109
117
  const changedFiles = modifiedRaw.length > 0 ? modifiedRaw.split("\n") : [];
110
118
  const deletedFiles = deletedRaw.length > 0 ? deletedRaw.split("\n") : [];
package/dist/plugin.d.ts CHANGED
@@ -37,6 +37,12 @@ type CreateRagHooksOptions = {
37
37
  /** Pre-created description provider for chunk descriptions. */
38
38
  descriptionProvider?: DescriptionProvider;
39
39
  };
40
+ /**
41
+ * Plugin tool names advertised by the mandatory guidance and granted to the
42
+ * built-in `explore` agent. `read` is deliberately absent — the read override
43
+ * shadows a built-in tool name and is ambiguous.
44
+ */
45
+ export declare const RAG_TOOL_NAMES: readonly ["search_semantic", "get_file_skeleton", "find_usages", "describe_image", "make_decision", "recall_quirks", "add_quirk", "update_quirk", "delete_quirk"];
40
46
  /**
41
47
  * Create the RAG plugin hook implementations for an OpenCode workspace.
42
48
  *
package/dist/plugin.js CHANGED
@@ -333,6 +333,47 @@ const defaultDependencies = {
333
333
  createStore: (storePath, dimension, config) => createVectorStore(config, storePath, dimension),
334
334
  retrieve,
335
335
  };
336
+ /**
337
+ * Plugin tool names advertised by the mandatory guidance and granted to the
338
+ * built-in `explore` agent. `read` is deliberately absent — the read override
339
+ * shadows a built-in tool name and is ambiguous.
340
+ */
341
+ export const RAG_TOOL_NAMES = [
342
+ "search_semantic",
343
+ "get_file_skeleton",
344
+ "find_usages",
345
+ "describe_image",
346
+ "make_decision",
347
+ "recall_quirks",
348
+ "add_quirk",
349
+ "update_quirk",
350
+ "delete_quirk",
351
+ ];
352
+ /**
353
+ * Built-in agents that ship with a permission policy denying every RAG tool
354
+ * (e.g. `explore`: deny all except read/glob/grep and the web tools). When the
355
+ * host sends no tool catalog, the guidance gate assumes they lack the tools —
356
+ * unless the explore tool grant (openCode.exploreAgentTools) is active.
357
+ */
358
+ const TOOLLESS_BUILTIN_AGENTS = new Set(["explore"]);
359
+ /**
360
+ * Decide whether the mandatory RAG guidance should be injected into the
361
+ * session's system prompt. OpenCode V2 passes the session's tool catalog to
362
+ * the context hook: advertise the tools only when at least one RAG tool is
363
+ * actually exposed. Restricted agents (`explore`) and custom permission
364
+ * overrides would otherwise receive an inert mandate referencing tools they
365
+ * cannot call. Hosts that do not send a catalog assume the legacy state —
366
+ * tool-less built-in agents stay skipped unless the explore tool grant is on.
367
+ */
368
+ function shouldInjectSystemGuidance(tools, agent, exploreToolsGranted) {
369
+ if (tools) {
370
+ return RAG_TOOL_NAMES.some((name) => name in tools);
371
+ }
372
+ if (agent !== undefined && TOOLLESS_BUILTIN_AGENTS.has(agent)) {
373
+ return exploreToolsGranted;
374
+ }
375
+ return true;
376
+ }
336
377
  /**
337
378
  * Format a list of relevant files (aggregated from chunks) for display.
338
379
  * Groups chunks by file path and sorts by maximum relevance score.
@@ -845,13 +886,18 @@ export function createRagHooks(options) {
845
886
  // Non-critical — must never throw
846
887
  }
847
888
  },
848
- async "experimental.chat.system.transform"(_input, output) {
889
+ async "experimental.chat.system.transform"(input, output) {
890
+ const cfg = getEffectiveCfg();
891
+ const guidanceEnabled = cfg.openCode.injectSystemPrompt !== false;
892
+ const exploreToolsGranted = cfg.openCode.exploreAgentTools !== false;
893
+ const injectGuidance = guidanceEnabled && shouldInjectSystemGuidance(input?.tools, input?.agent, exploreToolsGranted);
849
894
  appendDebugLog(options.logFilePath, {
850
895
  scope: "experimental.chat.system.transform",
851
- message: "system guidance injected",
896
+ message: injectGuidance
897
+ ? "system guidance injected"
898
+ : `system guidance skipped (${guidanceEnabled ? `no RAG tools in session; agent=${input?.agent ?? "unknown"}` : "injectSystemPrompt=false"})`,
852
899
  });
853
- const cfg = getEffectiveCfg();
854
- if (cfg.openCode.injectSystemPrompt !== false) {
900
+ if (injectGuidance) {
855
901
  const guidance = buildSystemGuidanceLines({ promptEnforcement: !!cfg.memory?.promptEnforcement, decisionEnabled: !!cfg.decision?.enabled, routeBeforeAsking: !!cfg.decision?.routeBeforeAsking });
856
902
  output.system.unshift(guidance.join("\n"));
857
903
  }
@@ -888,7 +934,7 @@ export function createRagHooks(options) {
888
934
  }
889
935
  // Inject relevant quirks into system prompt when memory.autoInject is enabled
890
936
  try {
891
- const sessionId = _input?.sessionID;
937
+ const sessionId = input?.sessionID;
892
938
  if (sessionId) {
893
939
  const memCfg = getEffectiveCfg().memory;
894
940
  if (memCfg?.enabled && memCfg?.autoInject) {
@@ -936,7 +982,7 @@ export function createRagHooks(options) {
936
982
  // Tool-error quirks: flush the pending block captured in tool.execute.after.
937
983
  // Freshness-bounded — a stale error must not leak into a later turn.
938
984
  try {
939
- const sessionId = _input?.sessionID;
985
+ const sessionId = input?.sessionID;
940
986
  if (sessionId) {
941
987
  const pending = sessionPendingToolErrorQuirk.get(sessionId);
942
988
  if (pending) {
package/dist/tui.d.ts CHANGED
@@ -13,12 +13,28 @@ type V2TuiContext = {
13
13
  location?: {
14
14
  directory?: string;
15
15
  } | undefined;
16
+ /** OpenCode's own version/channel — NOT the plugin version (use {@link getVersion}). */
16
17
  app?: {
17
18
  version?: string;
19
+ channel?: string;
18
20
  } | undefined;
19
21
  theme?: unknown;
20
22
  renderer?: unknown;
21
23
  data?: {
24
+ /** V2 data domain: `data.location.provider.list(location)`. */
25
+ location?: {
26
+ provider?: {
27
+ list?: (location?: {
28
+ directory?: string;
29
+ } | undefined) => readonly unknown[] | undefined;
30
+ };
31
+ model?: {
32
+ list?: (location?: {
33
+ directory?: string;
34
+ } | undefined) => readonly unknown[] | undefined;
35
+ };
36
+ } | undefined;
37
+ /** Pre-`location` context shapes; kept as a fallback. */
22
38
  provider?: {
23
39
  list?: () => readonly unknown[] | undefined;
24
40
  };
package/dist/tui.js CHANGED
@@ -2,7 +2,6 @@
2
2
  * @fileoverview OpenCode TUI (Terminal UI) plugin: renders a sidebar with RAG status,
3
3
  * settings dialog for editing config values, and model selection picker.
4
4
  */
5
- import { createElement, insert, setProp } from "@opentui/solid";
6
5
  import { readFileSync, existsSync, writeFileSync, unlinkSync } from "node:fs";
7
6
  import { createRequire } from "node:module";
8
7
  import { dirname, join, resolve } from "node:path";
@@ -18,6 +17,24 @@ import { setPendingRagInjection } from "./core/rag-injection-flag.js";
18
17
  * `src/eval/token-counter.ts`).
19
18
  */
20
19
  const _require = createRequire(import.meta.url);
20
+ /** Loaded by {@link loadOpenTui}; `undefined` until the TUI role activates. */
21
+ let openTui;
22
+ /**
23
+ * Load `@opentui/solid` on demand.
24
+ *
25
+ * The package is only resolvable inside OpenCode's CLI (TUI) process, which
26
+ * rewrites the bare specifier to its own bundled copy: plain registry installs
27
+ * have no OpenTUI dependency (it lives in `peerDependencies`, optional) and
28
+ * the server role loads this module too. A static import here therefore breaks
29
+ * every non-TUI load ("Cannot find package '@opentui/solid'"), so it must stay
30
+ * a dynamic import reached only from the TUI branch of `setup()`.
31
+ */
32
+ async function loadOpenTui() {
33
+ if (!openTui) {
34
+ openTui = (await import("@opentui/solid"));
35
+ }
36
+ return openTui;
37
+ }
21
38
  /** Cached plugin version string from package.json. */
22
39
  let _version;
23
40
  /** Read the plugin version from package.json, caching the result. */
@@ -140,18 +157,22 @@ function formatKeybinding(key) {
140
157
  const PLUGIN_NAME = "opencode-rag-plugin";
141
158
  /**
142
159
  * Create a TUI element node with the given tag, props, and children.
143
- * Wraps the low-level @opentui/solid createElement/insert/setProp functions.
160
+ * Wraps the low-level @opentui/solid createElement/insert/setProp functions
161
+ * (loaded lazily by {@link loadOpenTui} — see {@link setup}).
144
162
  */
145
163
  function element(tag, props, children = []) {
146
- const node = createElement(tag);
164
+ const solid = openTui;
165
+ if (!solid)
166
+ throw new Error("@opentui/solid is not loaded (TUI setup has not run)");
167
+ const node = solid.createElement(tag);
147
168
  for (const [key, value] of Object.entries(props)) {
148
169
  if (value !== undefined)
149
- setProp(node, key, value);
170
+ solid.setProp(node, key, value);
150
171
  }
151
172
  for (const child of children) {
152
173
  if (child === null || child === undefined || child === false)
153
174
  continue;
154
- insert(node, child);
175
+ solid.insert(node, child);
155
176
  }
156
177
  return node;
157
178
  }
@@ -688,8 +709,10 @@ function readTokenStats(worktree) {
688
709
  /** Rebuild legacy sdk `Provider` shapes (model picker / base URL / API key) from V2 data domains. */
689
710
  function v2LegacyProviders(context) {
690
711
  try {
691
- const providers = (context.data?.provider?.list?.() ?? []);
692
- const models = (context.data?.model?.list?.() ?? []);
712
+ const location = context.location;
713
+ const data = context.data;
714
+ const providers = (data?.location?.provider?.list?.(location) ?? data?.provider?.list?.() ?? []);
715
+ const models = (data?.location?.model?.list?.(location) ?? data?.model?.list?.() ?? []);
693
716
  return providers.map((p) => {
694
717
  const id = String(p.id ?? "");
695
718
  const modelMap = {};
@@ -704,7 +727,10 @@ function v2LegacyProviders(context) {
704
727
  id,
705
728
  name: p.name ?? id,
706
729
  models: modelMap,
707
- options: { baseURL: p.settings?.baseURL ?? p.options?.baseURL, apiKey: p.options?.apiKey },
730
+ options: {
731
+ baseURL: p.settings?.baseURL ?? p.options?.baseURL,
732
+ apiKey: p.settings?.apiKey ?? p.options?.apiKey,
733
+ },
708
734
  };
709
735
  });
710
736
  }
@@ -888,7 +914,10 @@ async function setup(context) {
888
914
  const keymap = context.keymap;
889
915
  if (!ui?.slot || !keymap)
890
916
  return undefined; // server-role load: nothing to register
891
- const version = context.app?.version ?? getVersion();
917
+ // TUI role confirmed — pull in the OpenTUI renderer primitives. This is the
918
+ // only place `@opentui/solid` may be imported (see {@link loadOpenTui}).
919
+ await loadOpenTui();
920
+ const version = getVersion();
892
921
  const worktree = context.location?.directory;
893
922
  let cachedStatus = DEFAULT_STATUS;
894
923
  let lastRefresh = 0;
@@ -47,7 +47,14 @@ declare module "@opencode-ai/plugin" {
47
47
  output: { messages: { info: Message; parts: Part[] }[] }
48
48
  ) => Promise<void>;
49
49
  "experimental.chat.system.transform"?: (
50
- input: { sessionID?: string; model: Model },
50
+ input: {
51
+ sessionID?: string;
52
+ model: Model;
53
+ /** Session agent ID (OpenCode V2); absent when the host does not send it. */
54
+ agent?: string;
55
+ /** Tool catalog exposed to the session (OpenCode V2); absent when the host does not send it. */
56
+ tools?: Record<string, { description?: string; input?: unknown }>;
57
+ },
51
58
  output: { system: string[] }
52
59
  ) => Promise<void>;
53
60
  }
@@ -16,6 +16,10 @@
16
16
  * | `tool.execute.after` | `ctx.tool.hook("execute.after", ...)` |
17
17
  * | `event` | `ctx.event.subscribe({ signal })` |
18
18
  *
19
+ * Additional V2-only registration (no V1 equivalent): the read-only RAG tools
20
+ * are granted to the built-in `explore` agent via `ctx.agent.transform`
21
+ * (config `openCode.exploreAgentTools`, default on).
22
+ *
19
23
  * The V2 prompt hook exposes the user's text as a mutable `event.prompt.text`
20
24
  * instead of V1's parts-mutation contract; the adapter shims a V1-shaped
21
25
  * `output.parts` view around it and writes the mutated text back.
@@ -45,6 +49,24 @@ type V2EventDomain = {
45
49
  signal: AbortSignal;
46
50
  }): AsyncIterable<unknown>;
47
51
  };
52
+ /** Permission rule shape inside an agent definition (OpenCode V2 schema). */
53
+ type V2PermissionRule = {
54
+ action: string;
55
+ resource: string;
56
+ effect: "allow" | "deny" | "ask";
57
+ };
58
+ /** Mutable agent definition subset used by the explore tool grant. */
59
+ type V2AgentInfo = {
60
+ permissions?: V2PermissionRule[];
61
+ };
62
+ type V2AgentEditor = {
63
+ get(id: string): V2AgentInfo | undefined;
64
+ update(id: string, update: (agent: V2AgentInfo) => void): void;
65
+ };
66
+ type V2AgentDomain = {
67
+ transform(callback: (editor: V2AgentEditor) => void): Promise<V2Registration>;
68
+ reload(): Promise<void>;
69
+ };
48
70
  /** Structural subset of the OpenCode V2 plugin context. */
49
71
  export type V2Context = {
50
72
  location: {
@@ -54,6 +76,7 @@ export type V2Context = {
54
76
  tool: V2ToolDomain;
55
77
  session: V2SessionDomain;
56
78
  event: V2EventDomain;
79
+ agent?: V2AgentDomain;
57
80
  };
58
81
  /** A registered V2 tool definition (structural subset of Tool.Info). */
59
82
  type V2Tool = {
@@ -104,9 +127,19 @@ type V2PromptHookEvent = {
104
127
  text: string;
105
128
  };
106
129
  };
107
- /** V2 `context` hook event. */
130
+ /**
131
+ * V2 `context` hook event. `agent` and `tools` mirror the host's
132
+ * `SessionContext` (session agent ID and the tool catalog actually exposed to
133
+ * it); both stay optional so hosts that don't send them keep the legacy
134
+ * unconditional guidance injection.
135
+ */
108
136
  type V2ContextHookEvent = {
109
137
  sessionID: string;
138
+ agent?: string;
139
+ tools?: Record<string, {
140
+ description?: string;
141
+ input?: unknown;
142
+ }>;
110
143
  system: Array<{
111
144
  type: "text";
112
145
  text: string;
@@ -119,6 +152,14 @@ type V2ContextHookEvent = {
119
152
  export declare function zodArgToJsonSchema(schema: unknown): Record<string, unknown>;
120
153
  /** Convert a V1 `args` record (zod raw shape) to a JSON schema object. Exported for tests. */
121
154
  export declare function zodShapeToJsonSchema(shape: Record<string, unknown>): Record<string, unknown>;
155
+ /**
156
+ * Grant the read-only RAG tools to the built-in `explore` agent. Appends an
157
+ * `allow` rule per tool action AFTER the shipped deny-all policy (OpenCode
158
+ * resolves permissions with "last matching rule wins"); an existing explicit
159
+ * rule for a tool action — user-configured allow, ask, or deny — is respected
160
+ * and left untouched. No-op when the agent is absent. Exported for tests.
161
+ */
162
+ export declare function grantExploreToolPermissions(editor: V2AgentEditor): void;
122
163
  /**
123
164
  * Run the V1 `ragPlugin` factory for the V2 context's location and register
124
165
  * all returned hooks as V2 transforms/hooks. Returns a cleanup function that
@@ -16,6 +16,10 @@
16
16
  * | `tool.execute.after` | `ctx.tool.hook("execute.after", ...)` |
17
17
  * | `event` | `ctx.event.subscribe({ signal })` |
18
18
  *
19
+ * Additional V2-only registration (no V1 equivalent): the read-only RAG tools
20
+ * are granted to the built-in `explore` agent via `ctx.agent.transform`
21
+ * (config `openCode.exploreAgentTools`, default on).
22
+ *
19
23
  * The V2 prompt hook exposes the user's text as a mutable `event.prompt.text`
20
24
  * instead of V1's parts-mutation contract; the adapter shims a V1-shaped
21
25
  * `output.parts` view around it and writes the mutated text back.
@@ -26,7 +30,8 @@
26
30
  * queries and session-end extraction fall back gracefully.
27
31
  * - The read-tool override keeps its V1 execute contract (args + sessionID).
28
32
  */
29
- import { ragPlugin } from "../plugin.js";
33
+ import { findConfigFile, loadConfig } from "../core/config.js";
34
+ import { ragPlugin, RAG_TOOL_NAMES } from "../plugin.js";
30
35
  /**
31
36
  * Extract a human-readable error string from a V2 `execute.after` error event.
32
37
  * The exact error payload differs across OpenCode versions; probe the known
@@ -160,6 +165,25 @@ function v1ToolToV2(name, def, codemode) {
160
165
  // ────────────────────────────────────────────────────────────────────────────
161
166
  // Registration entry point
162
167
  // ────────────────────────────────────────────────────────────────────────────
168
+ /**
169
+ * Grant the read-only RAG tools to the built-in `explore` agent. Appends an
170
+ * `allow` rule per tool action AFTER the shipped deny-all policy (OpenCode
171
+ * resolves permissions with "last matching rule wins"); an existing explicit
172
+ * rule for a tool action — user-configured allow, ask, or deny — is respected
173
+ * and left untouched. No-op when the agent is absent. Exported for tests.
174
+ */
175
+ export function grantExploreToolPermissions(editor) {
176
+ if (!editor.get("explore"))
177
+ return;
178
+ editor.update("explore", (agent) => {
179
+ const rules = (agent.permissions ??= []);
180
+ for (const name of RAG_TOOL_NAMES) {
181
+ if (rules.some((rule) => rule.action === name))
182
+ continue;
183
+ rules.push({ action: name, resource: "*", effect: "allow" });
184
+ }
185
+ });
186
+ }
163
187
  /**
164
188
  * Run the V1 `ragPlugin` factory for the V2 context's location and register
165
189
  * all returned hooks as V2 transforms/hooks. Returns a cleanup function that
@@ -176,6 +200,18 @@ export async function registerRagPluginV2(ctx) {
176
200
  // to force the previous code-mode-only behavior.
177
201
  const codemode = typeof ctx.options?.codemode === "boolean" ? ctx.options.codemode : false;
178
202
  const registrations = [];
203
+ // Explore keeps its RAG tool grant across reloads; opt out via
204
+ // `openCode.exploreAgentTools: false` in opencode-rag.json.
205
+ let exploreToolsEnabled = true;
206
+ try {
207
+ const cfgPath = findConfigFile(ctx.location.directory);
208
+ if (cfgPath) {
209
+ exploreToolsEnabled = loadConfig(cfgPath, false).openCode.exploreAgentTools !== false;
210
+ }
211
+ }
212
+ catch {
213
+ // Malformed config — the V1 factory reports it; fall back to the default
214
+ }
179
215
  // ── Tools ────────────────────────────────────────────────────────────────
180
216
  const toolDefs = (hooks.tool ?? {});
181
217
  const toolEntries = Object.entries(toolDefs);
@@ -187,6 +223,20 @@ export async function registerRagPluginV2(ctx) {
187
223
  });
188
224
  registrations.push(registration);
189
225
  }
226
+ // Explore agent tool grant: hand the read-only RAG tools to the built-in
227
+ // search agent. The grant appends allow rules after the shipped deny-all
228
+ // policy (last matching rule wins) and respects explicit user rules.
229
+ if (ctx.agent && exploreToolsEnabled) {
230
+ try {
231
+ const registration = await ctx.agent.transform((editor) => {
232
+ grantExploreToolPermissions(editor);
233
+ });
234
+ registrations.push(registration);
235
+ }
236
+ catch {
237
+ // Non-critical — the guidance gate falls back on the tool catalog
238
+ }
239
+ }
190
240
  // ── prompt hook (V1 `chat.message`) ─────────────────────────────────────
191
241
  // Shims a V1-shaped output (parts array) around the mutable prompt text,
192
242
  // runs the V1 handler, and writes the (possibly replaced) text back.
@@ -218,7 +268,7 @@ export async function registerRagPluginV2(ctx) {
218
268
  const registration = await ctx.session.hook("context", async (event) => {
219
269
  const output = { system: [] };
220
270
  try {
221
- await systemTransformHook({ sessionID: event.sessionID }, output);
271
+ await systemTransformHook({ sessionID: event.sessionID, agent: event.agent, tools: event.tools }, output);
222
272
  }
223
273
  catch {
224
274
  // Non-critical — must never throw
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-rag-plugin",
3
- "version": "2.4.3",
3
+ "version": "2.4.5",
4
4
  "description": "OpenCode plugin for local-first RAG-based semantic code search",
5
5
  "type": "module",
6
6
  "main": "./dist/plugin-entry.js",
@@ -85,7 +85,21 @@
85
85
  "homepage": "https://github.com/MrDoe/OpenCodeRAG#readme",
86
86
  "peerDependencies": {
87
87
  "@opencode-ai/plugin": ">=1.18.0",
88
- "@opencode/plugin": ">=2.0.0"
88
+ "@opencode/plugin": ">=2.0.0",
89
+ "@opentui/core": ">=0.5.10",
90
+ "@opentui/solid": ">=0.5.10",
91
+ "solid-js": ">=1.9.0"
92
+ },
93
+ "peerDependenciesMeta": {
94
+ "@opentui/core": {
95
+ "optional": true
96
+ },
97
+ "@opentui/solid": {
98
+ "optional": true
99
+ },
100
+ "solid-js": {
101
+ "optional": true
102
+ }
89
103
  },
90
104
  "dependencies": {
91
105
  "@e965/xlsx": "^0.20.3",