opencode-gbk-tools 0.1.4 → 0.1.6
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 +22 -0
- package/dist/agents/gbk-engine.md +13 -1
- package/dist/opencode-tools/gbk_edit.js +14 -8
- package/dist/opencode-tools/gbk_read.js +12 -4
- package/dist/opencode-tools/gbk_search.js +16462 -0
- package/dist/plugin/index.js +104 -13
- package/dist/release-manifest.json +10 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,6 +92,28 @@ opencode-gbk doctor
|
|
|
92
92
|
opencode-gbk doctor --project
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
+
## 卸载
|
|
96
|
+
|
|
97
|
+
如果你是通过 `setup` 或手动修改 `opencode.json` / `opencode.jsonc` 启用 npm plugin:
|
|
98
|
+
|
|
99
|
+
- 删除 `plugin` 数组中的 `"opencode-gbk-tools"`
|
|
100
|
+
- 如果不再需要 `gbk-engine`,再删除对应 agent 文件
|
|
101
|
+
- 项目级:`.opencode/agents/gbk-engine.md`
|
|
102
|
+
- 全局:`~/.config/opencode/agents/gbk-engine.md`
|
|
103
|
+
|
|
104
|
+
如果你是通过 CLI 安装 agent 或工具文件:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
opencode-gbk uninstall
|
|
108
|
+
opencode-gbk uninstall --project
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
说明:
|
|
112
|
+
|
|
113
|
+
- `opencode-gbk uninstall` 会卸载全局安装到 `~/.config/opencode` 下的文件
|
|
114
|
+
- `opencode-gbk uninstall --project` 会卸载当前项目 `.opencode/` 下的文件
|
|
115
|
+
- `uninstall` 只会删除通过本包 manifest 记录过的文件,不会自动改写你的 `opencode.json` / `opencode.jsonc` plugin 配置
|
|
116
|
+
|
|
95
117
|
## Agent
|
|
96
118
|
|
|
97
119
|
安装后会生成 `gbk-engine`。
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: 处理 GBK/GB18030 编码文件的专用代理,只使用 gbk_read、gbk_write、gbk_edit
|
|
2
|
+
description: 处理 GBK/GB18030 编码文件的专用代理,只使用 gbk_read、gbk_write、gbk_edit、gbk_search
|
|
3
3
|
mode: primary
|
|
4
4
|
permission:
|
|
5
5
|
read: deny
|
|
@@ -18,6 +18,7 @@ permission:
|
|
|
18
18
|
- 读取文件时优先使用 `gbk_read`
|
|
19
19
|
- 创建或覆盖文件时优先使用 `gbk_write`
|
|
20
20
|
- 修改已有文件时优先使用 `gbk_edit`
|
|
21
|
+
- 在大文件中搜索内容时使用 `gbk_search`
|
|
21
22
|
- 大文件读取优先使用 `gbk_read` 的分页或 `tail` 能力,避免一次读取过多内容
|
|
22
23
|
- 修改时优先缩小编辑范围:能用 `startLine/endLine` 或 `startAnchor/endAnchor` 就不要全文替换
|
|
23
24
|
- 文件发现可使用 `glob`,但文件内容读取必须使用 `gbk_read`
|
|
@@ -25,3 +26,14 @@ permission:
|
|
|
25
26
|
- `edit: deny` 同时覆盖内置 `write`、`patch`、`multiedit`
|
|
26
27
|
- 如果用户请求涉及 UTF-8 文件或二进制文件,先明确说明不适用
|
|
27
28
|
- 若目标文件编码不确定,先提醒用户确认是 `gbk` 还是 `gb18030`
|
|
29
|
+
|
|
30
|
+
## 大文件编辑工作流(必须遵守)
|
|
31
|
+
|
|
32
|
+
当 `gbk_read` 返回 `truncated: true` 时,说明文件超出了读取窗口。
|
|
33
|
+
此时若需要编辑文件,**必须按以下步骤操作,禁止直接猜测 oldString**:
|
|
34
|
+
|
|
35
|
+
1. `gbk_search(filePath, pattern)` — 找到目标内容的精确行号和上下文
|
|
36
|
+
2. `gbk_read(filePath, offset=<lineNumber>, limit=<N>)` — 读取目标行的精确内容
|
|
37
|
+
3. `gbk_edit(filePath, oldString=<精确内容>, newString=<新内容>)` — 用精确内容替换
|
|
38
|
+
|
|
39
|
+
**禁止**在未确认精确内容的情况下构造 `oldString`,否则 `gbk_edit` 必然报 `GBK_NO_MATCH`。
|
|
@@ -16720,17 +16720,23 @@ async function replaceGbkFileText(input) {
|
|
|
16720
16720
|
|
|
16721
16721
|
// src/tools/gbk_edit.ts
|
|
16722
16722
|
var gbk_edit_default = tool({
|
|
16723
|
-
description:
|
|
16723
|
+
description: `Edit GBK/GB18030 encoded text files with exact string replacement.
|
|
16724
|
+
|
|
16725
|
+
Reads the FULL file content regardless of file size \u2014 not limited by gbk_read's line window.
|
|
16726
|
+
Safe to use on files with more than 2000 lines.
|
|
16727
|
+
|
|
16728
|
+
For large files, use 'startLine'/'endLine' or 'startAnchor'/'endAnchor' to narrow the search scope
|
|
16729
|
+
and avoid false matches. Scoped edits also improve performance on very large files.`,
|
|
16724
16730
|
args: {
|
|
16725
16731
|
filePath: tool.schema.string().describe("Target file path"),
|
|
16726
|
-
oldString: tool.schema.string().describe("
|
|
16732
|
+
oldString: tool.schema.string().describe("Exact text to replace (must match file content, not gbk_read output with line numbers)"),
|
|
16727
16733
|
newString: tool.schema.string().describe("Replacement text"),
|
|
16728
|
-
replaceAll: tool.schema.boolean().optional().describe("Replace all occurrences"),
|
|
16729
|
-
startLine: tool.schema.union([tool.schema.number().int().positive(), tool.schema.literal(-1)]).optional().describe("Restrict edit to 1-based start line"),
|
|
16730
|
-
endLine: tool.schema.union([tool.schema.number().int().positive(), tool.schema.literal(-1)]).optional().describe("Restrict edit to 1-based end line"),
|
|
16731
|
-
startAnchor: tool.schema.string().optional().describe("Restrict edit to content after this anchor"),
|
|
16732
|
-
endAnchor: tool.schema.string().optional().describe("Restrict edit to content before this anchor"),
|
|
16733
|
-
encoding: tool.schema.enum(["gbk", "gb18030"]).optional().describe("Text encoding"),
|
|
16734
|
+
replaceAll: tool.schema.boolean().optional().describe("Replace all occurrences (default: false, requires unique match)"),
|
|
16735
|
+
startLine: tool.schema.union([tool.schema.number().int().positive(), tool.schema.literal(-1)]).optional().describe("Restrict edit scope to 1-based start line (inclusive)"),
|
|
16736
|
+
endLine: tool.schema.union([tool.schema.number().int().positive(), tool.schema.literal(-1)]).optional().describe("Restrict edit scope to 1-based end line (inclusive)"),
|
|
16737
|
+
startAnchor: tool.schema.string().optional().describe("Restrict edit to content after this anchor string"),
|
|
16738
|
+
endAnchor: tool.schema.string().optional().describe("Restrict edit to content before this anchor string"),
|
|
16739
|
+
encoding: tool.schema.enum(["gbk", "gb18030"]).optional().describe("Text encoding (default: gbk)"),
|
|
16734
16740
|
allowExternal: tool.schema.boolean().optional().describe("Allow paths outside workspace root")
|
|
16735
16741
|
},
|
|
16736
16742
|
async execute(args, context) {
|
|
@@ -16604,13 +16604,21 @@ async function readGbkFile(input) {
|
|
|
16604
16604
|
|
|
16605
16605
|
// src/tools/gbk_read.ts
|
|
16606
16606
|
var gbk_read_default = tool({
|
|
16607
|
-
description:
|
|
16607
|
+
description: `Read GBK/GB18030 encoded text files with line numbers.
|
|
16608
|
+
|
|
16609
|
+
Returns up to 'limit' lines (default 2000) starting from 'offset'.
|
|
16610
|
+
When the file has more lines than the window, 'truncated' is true and 'totalLines' shows the full count.
|
|
16611
|
+
|
|
16612
|
+
IMPORTANT: If 'truncated' is true, the returned content is incomplete.
|
|
16613
|
+
DO NOT use the returned content as 'oldString' for gbk_edit on a truncated file.
|
|
16614
|
+
To edit content beyond the visible window, use gbk_edit with 'startLine'/'endLine' to target the exact range,
|
|
16615
|
+
or read the specific range first with 'offset' set to the desired line number.`,
|
|
16608
16616
|
args: {
|
|
16609
16617
|
filePath: tool.schema.string().describe("Target file path"),
|
|
16610
|
-
offset: tool.schema.union([tool.schema.number().int().positive(), tool.schema.literal(-1)]).optional().describe("1-based start line"),
|
|
16611
|
-
limit: tool.schema.union([tool.schema.number().int().positive(), tool.schema.literal(-1)]).optional().describe("Number of lines to read"),
|
|
16618
|
+
offset: tool.schema.union([tool.schema.number().int().positive(), tool.schema.literal(-1)]).optional().describe("1-based start line (default: 1)"),
|
|
16619
|
+
limit: tool.schema.union([tool.schema.number().int().positive(), tool.schema.literal(-1)]).optional().describe("Number of lines to read (default: 2000). Use -1 to apply the default."),
|
|
16612
16620
|
tail: tool.schema.boolean().optional().describe("Read last N lines instead of offset-based window"),
|
|
16613
|
-
encoding: tool.schema.enum(["gbk", "gb18030"]).optional().describe("Text encoding"),
|
|
16621
|
+
encoding: tool.schema.enum(["gbk", "gb18030"]).optional().describe("Text encoding (default: gbk)"),
|
|
16614
16622
|
allowExternal: tool.schema.boolean().optional().describe("Allow paths outside workspace root")
|
|
16615
16623
|
},
|
|
16616
16624
|
async execute(args, context) {
|