@xiaoqiong0v0/opencode-browser-tool 1.14.0 → 1.14.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/dist/index.js +14 -7
- package/dist/util/file-resolver.js +31 -0
- package/package.json +45 -45
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import { configureService, setAppDirectory, getAppDirectory, setServiceReadyHand
|
|
|
10
10
|
import { startNotifyServer } from "./notify-server.js";
|
|
11
11
|
import { startDownload, getBinaryStatus, describeBinaryStatus } from "./binary.js";
|
|
12
12
|
import { sanitizeForModel } from "./util/sanitize.js";
|
|
13
|
+
import { fileResolutionMode } from "./util/file-resolver.js";
|
|
13
14
|
import { EVAL_ITEM_MAX_BYTES, EVAL_TOTAL_MAX_BYTES, classifyEvalArgs, runEvalItems, } from "./util/eval-items.js";
|
|
14
15
|
import { INJECT_RULE_MAX_BYTES, buildInjectItems, formatInjectAdd, formatInjectList, formatInjectTest, injectAddIssue, injectRuleLimitIssue, normalizeInjectAction, } from "./util/inject-rules.js";
|
|
15
16
|
import { formatConsoleItems, formatNetworkItems, renderLogText, } from "./util/log-format.js";
|
|
@@ -1044,19 +1045,25 @@ export const opencodeBrowserTool = async ({ client, worktree, directory }) => {
|
|
|
1044
1045
|
for (const key of Object.keys(params)) {
|
|
1045
1046
|
const v = params[key];
|
|
1046
1047
|
if (typeof v === "string" && v.startsWith("@file:")) {
|
|
1047
|
-
//
|
|
1048
|
-
//
|
|
1049
|
-
|
|
1048
|
+
// 三类模式:own=命令自己解析(跳过本层)、workspace=允许工作区+插件 tmp、
|
|
1049
|
+
// tmp=只允许插件 tmp(默认,读完删全局 tmp 临时文件)。
|
|
1050
|
+
// 缺 workspace 会让 `evaluate --script @file:<工作区>/x.js` 永远被拒(1.14.0 缺陷)。
|
|
1051
|
+
const mode = fileResolutionMode(cmdName, key);
|
|
1052
|
+
if (mode === "own")
|
|
1050
1053
|
continue;
|
|
1054
|
+
const workspaceDir = getAppDirectory();
|
|
1055
|
+
const allowedDirs = mode === "workspace" && workspaceDir ? [...allowedTmpDirs, workspaceDir] : allowedTmpDirs;
|
|
1051
1056
|
const p = v.slice(6);
|
|
1052
|
-
const abs = resolve(p);
|
|
1053
|
-
if (!
|
|
1054
|
-
return _t("cli.err.file_outside_tmp", {
|
|
1057
|
+
const abs = workspaceDir && mode === "workspace" ? resolve(workspaceDir, p) : resolve(p);
|
|
1058
|
+
if (!allowedDirs.some((d) => isInsideDir(abs, d))) {
|
|
1059
|
+
return _t(mode === "workspace" ? "cli.err.eval_file_outside" : "cli.err.file_outside_tmp", {
|
|
1060
|
+
path: p,
|
|
1061
|
+
});
|
|
1055
1062
|
}
|
|
1056
1063
|
try {
|
|
1057
1064
|
params[key] = readFileSync(abs, "utf-8").replace(/\r?\n$/, "");
|
|
1058
1065
|
// 用完即删(仅限 lookup 生成的全局 tmp 临时密码文件;会话 tmp 内的截图等保留)
|
|
1059
|
-
if (isInsideDir(abs, globalTmpDir)) {
|
|
1066
|
+
if (mode !== "workspace" && isInsideDir(abs, globalTmpDir)) {
|
|
1060
1067
|
unlinkSync(abs);
|
|
1061
1068
|
}
|
|
1062
1069
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@file:` 通用层的解析模式判定(纯逻辑,便于单测)。
|
|
3
|
+
*
|
|
4
|
+
* 背景:`bt_cli` 的通用层对所有字符串参数先做一遍 `@file:` 处理。它原本只允许
|
|
5
|
+
* **插件 tmp**内的文件(读完还会删掉全局 tmp 里的文件),这对大多数命令是对的;
|
|
6
|
+
* 但有两类命令自带更宽的语义,需要区别对待:
|
|
7
|
+
*
|
|
8
|
+
* - `type --text`:命令自身解析(`resolveTypeText`),通用层必须整体跳过;
|
|
9
|
+
* - `evaluate --script`:脚本文件应当允许放在**工作区**(用户最常见用法),
|
|
10
|
+
* 但语义仍是"读出内容当脚本",所以不能跳过,要按 workspace 模式读且**不删文件**。
|
|
11
|
+
*
|
|
12
|
+
* 1.14.0 及更早:`evaluate --script @file:<工作区>/x.js` 会被 tmp-only 规则直接拒掉
|
|
13
|
+
* (报 file_outside_tmp),工作区里的脚本永远跑不起来。
|
|
14
|
+
*/
|
|
15
|
+
/** 命令名 → 参数键 → 模式(未列出的一律 `tmp`)。 */
|
|
16
|
+
const MODES = Object.freeze({
|
|
17
|
+
type: { text: "own" },
|
|
18
|
+
evaluate: { script: "workspace" },
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* 判断通用层该如何处理某命令的某个 `@file:` 参数。
|
|
22
|
+
*
|
|
23
|
+
* @param cmd 命令名(如 `evaluate` / `type`)
|
|
24
|
+
* @param key 参数键(如 `script` / `text`)
|
|
25
|
+
* @returns 解析模式(`own` / `workspace` / `tmp`)
|
|
26
|
+
*/
|
|
27
|
+
export function fileResolutionMode(cmd, key) {
|
|
28
|
+
const perCmd = MODES[cmd];
|
|
29
|
+
const mode = perCmd ? perCmd[key] : undefined;
|
|
30
|
+
return mode ?? "tmp";
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@xiaoqiong0v0/opencode-browser-tool",
|
|
3
|
-
"version": "1.14.
|
|
4
|
-
"description": "opencode 浏览器工具插件:WebView2 外壳渲染 + 零注入视觉元素选取面板",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "tsc",
|
|
8
|
-
"dev": "tsc --watch",
|
|
9
|
-
"test": "npm run build && node --test \"tests/unit/*.test.mjs\"",
|
|
10
|
-
"build:frontend": "cd frontend && npm install && npm run build"
|
|
11
|
-
},
|
|
12
|
-
"keywords": [
|
|
13
|
-
"opencode",
|
|
14
|
-
"browser",
|
|
15
|
-
"webview2",
|
|
16
|
-
"plugin"
|
|
17
|
-
],
|
|
18
|
-
"author": "",
|
|
19
|
-
"license": "ISC",
|
|
20
|
-
"type": "module",
|
|
21
|
-
"files": [
|
|
22
|
-
"dist"
|
|
23
|
-
],
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"@xiaoqiong0v0/opencode-plugin-logger": "^1.0.5",
|
|
26
|
-
"string-argv": "^0.3.2"
|
|
27
|
-
},
|
|
28
|
-
"peerDependencies": {
|
|
29
|
-
"@opencode-ai/plugin": "^1.18.4"
|
|
30
|
-
},
|
|
31
|
-
"devDependencies": {
|
|
32
|
-
"@types/node": "^26.1.1",
|
|
33
|
-
"typescript": "^7.0.2"
|
|
34
|
-
},
|
|
35
|
-
"publishConfig": {
|
|
36
|
-
"access": "public"
|
|
37
|
-
},
|
|
38
|
-
"repository": {
|
|
39
|
-
"type": "git",
|
|
40
|
-
"url": "git+https://github.com/xiaoqiong0v0/opencode-browser-tool.git"
|
|
41
|
-
},
|
|
42
|
-
"volta": {
|
|
43
|
-
"node": "24.16.0"
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@xiaoqiong0v0/opencode-browser-tool",
|
|
3
|
+
"version": "1.14.1",
|
|
4
|
+
"description": "opencode 浏览器工具插件:WebView2 外壳渲染 + 零注入视觉元素选取面板",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc",
|
|
8
|
+
"dev": "tsc --watch",
|
|
9
|
+
"test": "npm run build && node --test \"tests/unit/*.test.mjs\"",
|
|
10
|
+
"build:frontend": "cd frontend && npm install && npm run build"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"opencode",
|
|
14
|
+
"browser",
|
|
15
|
+
"webview2",
|
|
16
|
+
"plugin"
|
|
17
|
+
],
|
|
18
|
+
"author": "",
|
|
19
|
+
"license": "ISC",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@xiaoqiong0v0/opencode-plugin-logger": "^1.0.5",
|
|
26
|
+
"string-argv": "^0.3.2"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@opencode-ai/plugin": "^1.18.4"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^26.1.1",
|
|
33
|
+
"typescript": "^7.0.2"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/xiaoqiong0v0/opencode-browser-tool.git"
|
|
41
|
+
},
|
|
42
|
+
"volta": {
|
|
43
|
+
"node": "24.16.0"
|
|
44
|
+
}
|
|
45
|
+
}
|