opencode-rag-plugin 2.9.1 → 2.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ReadMe.md CHANGED
@@ -265,7 +265,7 @@ opencode-rag mcp
265
265
  | `search_semantic` | Vector + keyword hybrid search across the indexed codebase |
266
266
  | `get_file_skeleton` | AST-based file outline (functions, classes, methods) |
267
267
  | `find_usages` | Find all references to a symbol by name |
268
- | `describe_image` | Describe an image file with the configured vision model (`imageDescription.onDemand` overrides apply) |
268
+ | `describe_image` | Describe an image file with the configured vision model (`imageDescription.onDemand` overrides apply; paths outside the workspace are allowed) |
269
269
  | `make_decision` | Classify/route/score short text with the local tev1 decision model (only when `decision.enabled` is `true`) |
270
270
 
271
271
  Clients can configure the MCP server manually, or `opencode-rag init` auto-registers it.
@@ -7,6 +7,7 @@
7
7
  import path from "node:path";
8
8
  import { existsSync, readFileSync } from "node:fs";
9
9
  import { c, resolveCliContext, cleanupContext, logCliError, logCliInfo } from "../format.js";
10
+ import { resolveUserPath } from "../../core/paths.js";
10
11
  /**
11
12
  * Register the `describe-image` command on the given Commander program.
12
13
  *
@@ -30,7 +31,8 @@ export function registerDescribeImageCommand(program) {
30
31
  const ctx = await resolveCliContext(options, logFilePath);
31
32
  const { config } = ctx;
32
33
  logFilePath = ctx.logFilePath;
33
- const resolvedPath = path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
34
+ // Any readable image path is allowed — absolute, relative to cwd, or `~`-prefixed.
35
+ const resolvedPath = resolveUserPath(cwd, filePath);
34
36
  if (!existsSync(resolvedPath)) {
35
37
  logCliError(logFilePath, "describe-image", `\nFile not found: ${filePath}`, undefined);
36
38
  process.exit(1);
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @fileoverview Resolution helpers for user-supplied filesystem paths.
3
+ */
4
+ /**
5
+ * Expand a leading `~` to the current user's home directory.
6
+ *
7
+ * Only bare `~` and the `~/` / `~\` prefixes are expanded; `~otheruser` is
8
+ * returned unchanged (it has no portable meaning).
9
+ *
10
+ * @param inputPath - The path supplied by the user.
11
+ * @returns The path with `~` replaced by the home directory.
12
+ */
13
+ export declare function expandTilde(inputPath: string): string;
14
+ /**
15
+ * Resolve a user-supplied path against a base directory WITHOUT sandboxing it.
16
+ *
17
+ * Absolute paths (and `~`-prefixed paths) are used as-is; relative paths are
18
+ * resolved against `baseDir`. Use this for read-only tools that legitimately
19
+ * operate on files anywhere on disk (e.g. `describe_image` on a screenshot
20
+ * outside the workspace). Do NOT use it for the workspace-sandboxed `read`
21
+ * tool — that one must keep rejecting paths outside the workspace.
22
+ *
23
+ * @param baseDir - Directory used to resolve relative paths (usually the worktree).
24
+ * @param inputPath - The path supplied by the user.
25
+ * @returns An absolute path; no containment check is performed.
26
+ */
27
+ export declare function resolveUserPath(baseDir: string, inputPath: string): string;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @fileoverview Resolution helpers for user-supplied filesystem paths.
3
+ */
4
+ import path from "node:path";
5
+ import { homedir } from "node:os";
6
+ /**
7
+ * Expand a leading `~` to the current user's home directory.
8
+ *
9
+ * Only bare `~` and the `~/` / `~\` prefixes are expanded; `~otheruser` is
10
+ * returned unchanged (it has no portable meaning).
11
+ *
12
+ * @param inputPath - The path supplied by the user.
13
+ * @returns The path with `~` replaced by the home directory.
14
+ */
15
+ export function expandTilde(inputPath) {
16
+ if (inputPath === "~")
17
+ return homedir();
18
+ if (inputPath.startsWith("~/") || inputPath.startsWith("~\\")) {
19
+ return path.join(homedir(), inputPath.slice(2));
20
+ }
21
+ return inputPath;
22
+ }
23
+ /**
24
+ * Resolve a user-supplied path against a base directory WITHOUT sandboxing it.
25
+ *
26
+ * Absolute paths (and `~`-prefixed paths) are used as-is; relative paths are
27
+ * resolved against `baseDir`. Use this for read-only tools that legitimately
28
+ * operate on files anywhere on disk (e.g. `describe_image` on a screenshot
29
+ * outside the workspace). Do NOT use it for the workspace-sandboxed `read`
30
+ * tool — that one must keep rejecting paths outside the workspace.
31
+ *
32
+ * @param baseDir - Directory used to resolve relative paths (usually the worktree).
33
+ * @param inputPath - The path supplied by the user.
34
+ * @returns An absolute path; no containment check is performed.
35
+ */
36
+ export function resolveUserPath(baseDir, inputPath) {
37
+ const expanded = expandTilde(inputPath);
38
+ return path.isAbsolute(expanded)
39
+ ? path.resolve(expanded)
40
+ : path.resolve(baseDir, expanded);
41
+ }
42
+ //# sourceMappingURL=paths.js.map
@@ -98,7 +98,7 @@ export interface DescribeImageResult {
98
98
  /** Human-readable formatted output with metadata. */
99
99
  formatted: string;
100
100
  }
101
- /** Describe an image file using the configured vision provider (Ollama, OpenAI, Anthropic, Gemini, or OpenCode Zen). Honors `imageDescription.onDemand` overrides. */
101
+ /** Describe an image file using the configured vision provider (Ollama, OpenAI, Anthropic, Gemini, or OpenCode Zen). Honors `imageDescription.onDemand` overrides. The file may live anywhere on disk; relative paths resolve against `worktree`. */
102
102
  export declare function handleDescribeImage(params: DescribeImageParams, cfg: RagConfig, worktree: string, visionProvider?: ImageVisionProvider): Promise<DescribeImageResult>;
103
103
  /** Parameters for the make_decision MCP tool. */
104
104
  export interface MakeDecisionParams {
@@ -13,6 +13,7 @@ import { validateDecisionRequest } from "../decision/validate.js";
13
13
  import { formatDecisionAnswers } from "../decision/format.js";
14
14
  import { readFileSync } from "node:fs";
15
15
  import { resolve, isAbsolute, relative, sep as pathSep } from "node:path";
16
+ import { resolveUserPath } from "../core/paths.js";
16
17
  /**
17
18
  * Resolve a user-supplied file path against the worktree root, refusing to
18
19
  * escape the worktree. Absolute paths are accepted only if they already reside
@@ -136,11 +137,13 @@ export async function handleFileSkeleton(params, worktree, languageByExtension)
136
137
  const formatted = `${skeleton.length} structural elements (${summary || "—"})\n\n${formatSkeleton(skeleton)}`;
137
138
  return { elements: skeleton, formatted, summary };
138
139
  }
139
- /** Describe an image file using the configured vision provider (Ollama, OpenAI, Anthropic, Gemini, or OpenCode Zen). Honors `imageDescription.onDemand` overrides. */
140
+ /** Describe an image file using the configured vision provider (Ollama, OpenAI, Anthropic, Gemini, or OpenCode Zen). Honors `imageDescription.onDemand` overrides. The file may live anywhere on disk; relative paths resolve against `worktree`. */
140
141
  export async function handleDescribeImage(params, cfg, worktree, visionProvider) {
141
142
  const { existsSync, readFileSync } = await import("node:fs");
142
143
  const path = await import("node:path");
143
- const resolvedPath = resolveFilePath(params.filePath, worktree);
144
+ // Unlike the skeleton tools, image description is not sandboxed to the
145
+ // worktree: screenshots often live in the OS temp or home directory.
146
+ const resolvedPath = resolveUserPath(worktree, params.filePath);
144
147
  if (!existsSync(resolvedPath)) {
145
148
  throw new Error(`File not found: ${params.filePath}`);
146
149
  }
@@ -20,6 +20,7 @@ import { retrieve } from "../retriever/retriever.js";
20
20
  import { extractSkeleton, getExtension } from "../chunker/skeleton.js";
21
21
  import { readFileSync } from "node:fs";
22
22
  import { resolveWorkspacePath } from "./tool-args.js";
23
+ import { resolveUserPath } from "../core/paths.js";
23
24
  import { addQuirk, updateQuirk, removeQuirk, recallQuirks } from "../quirks/quirk-store.js";
24
25
  import { createDecisionProvider } from "../decision/factory.js";
25
26
  import { validateDecisionRequest } from "../decision/validate.js";
@@ -148,7 +149,9 @@ export function createDescribeImageTool(options) {
148
149
  "and returns a natural language description of what the image shows. " +
149
150
  "Optionally accepts a `systemPrompt` to steer the description toward specific features or details you care about " +
150
151
  "(e.g. colors, layout, accessibility, text content, specific UI elements). " +
151
- "Use when the user refers to a screenshot, diagram, mockup, or any image in the workspace.",
152
+ "The path may point anywhere on disk — outside the workspace too (e.g. a screenshot in the OS temp " +
153
+ "or home directory); relative paths resolve against the workspace root and `~` expands to the home directory. " +
154
+ "Use when the user refers to a screenshot, diagram, mockup, or any image.",
152
155
  args: {
153
156
  filePath: tool.schema.string().min(1, "An image file path is required."),
154
157
  systemPrompt: tool.schema.string().optional(),
@@ -157,7 +160,7 @@ export function createDescribeImageTool(options) {
157
160
  try {
158
161
  const { existsSync, readFileSync } = await import("node:fs");
159
162
  const path = await import("node:path");
160
- const resolvedPath = resolveWorkspacePath(worktree, args.filePath);
163
+ const resolvedPath = resolveUserPath(worktree, args.filePath);
161
164
  if (!existsSync(resolvedPath)) {
162
165
  return {
163
166
  title: "Describe image",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-rag-plugin",
3
- "version": "2.9.1",
3
+ "version": "2.9.2",
4
4
  "description": "OpenCode plugin for local-first RAG-based semantic code search",
5
5
  "type": "module",
6
6
  "main": "./dist/plugin-entry.js",