opencode-gbk-tools 0.1.15 → 0.1.16

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  为 OpenCode 提供一套自动识别编码的文本工具,以及面向 `GBK` / `GB18030` 的专用工具。
4
4
 
5
- 解决 OpenCode 内置工具难以稳定处理非 UTF-8 文本文件的问题,并让所有 agents 默认优先使用可保留原编码的 `text_*` 工具。
5
+ 解决 OpenCode 内置工具难以稳定处理非 UTF-8 文本文件的问题,并通过 plugin 让所有 agents 默认获得这些工具与规则,无需单独切换专属 GBK agent。
6
6
 
7
7
  ---
8
8
 
@@ -17,7 +17,7 @@
17
17
  | `gbk_write` | 写入或追加内容到 GBK 文件(`append=true` 支持追加) |
18
18
  | `gbk_edit` | 精确替换 GBK 文件中的指定文本块 |
19
19
  | `gbk_search` | 在 GBK 文件中搜索关键词,返回行号和上下文 |
20
- | 本地/全局 plugin 规则 | 给所有 agents 注入“优先使用 `text_*`”的系统提示 |
20
+ | 本地/全局 plugin 规则 | 给所有 agents 注入“优先使用 `text_*`”的系统提示,并统一开放 `gbk_*` 工具 |
21
21
 
22
22
  ---
23
23
 
@@ -27,7 +27,15 @@
27
27
  npx opencode-gbk-tools install
28
28
  ```
29
29
 
30
- 安装完成后**重启 OpenCode**,工具立即生效。
30
+ 安装完成后会注册 `opencode-gbk-tools` plugin,由该 plugin 统一向全部 agents 暴露 `text_*` / `gbk_*` 工具与规则。
31
+
32
+ 重启 OpenCode 后,**全部 agents** 都会默认获得:
33
+
34
+ - `text_read` / `text_write` / `text_edit`
35
+ - `gbk_read` / `gbk_write` / `gbk_edit` / `gbk_search`
36
+ - 对文本文件优先使用 `text_*` 的系统提示
37
+
38
+ 不再需要单独安装或切换专属 `gbk-engine` agent。
31
39
 
32
40
  ---
33
41
 
@@ -41,6 +49,8 @@ npx opencode-gbk-tools install
41
49
  npx opencode-gbk-tools uninstall
42
50
  ```
43
51
 
52
+ 卸载后会移除已安装的工具、plugin 与 manifest,所有 agents 恢复为未安装前的默认行为。
53
+
44
54
  ---
45
55
 
46
56
  ## 工具使用说明
@@ -181,7 +191,7 @@ A:重启 OpenCode。工具在 OpenCode 启动时加载,安装后需要重启
181
191
  A:请先安装 Node.js(https://nodejs.org/),版本需要 18 或以上。
182
192
 
183
193
  **Q:Windows 路径在哪?**
184
- A:全局安装目录为 `C:\Users\你的用户名\.config\opencode\tools\`
194
+ A:全局安装的 plugin 文件位于 `C:\Users\你的用户名\.config\opencode\plugins\opencode-gbk-tools.js`
185
195
 
186
196
  **Q:gbk_edit 提示"未找到需要替换的文本"?**
187
197
  A:检查 `oldString` 是否包含了行号前缀(如 `"3787: "`),去掉行号前缀后重试。若要在文件末尾追加内容,请使用 `gbk_write [append=true]`。
@@ -195,6 +205,7 @@ A:不要。现在优先用 `mode="insertAfter"` 或 `mode="insertBefore"`,
195
205
 
196
206
  | 版本 | 说明 |
197
207
  |------|------|
208
+ | 0.1.16 | 去掉专属 `gbk-engine` agent 安装链路,改为通过 plugin + tools 让全部 agents 统一支持 `text_*` / `gbk_*`;同步更新安装说明 |
198
209
  | 0.1.15 | 为 GBK 大文件统一引入行字节索引与流式读/搜/改路径,提升局部编辑、搜索与大块修改时的性能、稳定性与准确性 |
199
210
  | 0.1.14 | 重新发布当前稳定产物,核对 `npm pack --dry-run` 输出包含完整 `dist/`,为下一次公开发布提供一致的打包基线 |
200
211
  | 0.1.13 | `text_write` 在新文件 + `encoding=auto` 下改为显式报错,不再静默默认 `utf8`;同时优化 `text_read` 流式读取与 `text_edit` 预览生成,减少重复读取 |
package/dist/cli/index.js CHANGED
@@ -60,10 +60,19 @@ function resolveTargetBase(target, cwd) {
60
60
  // src/cli/install.ts
61
61
  async function installCommand(args) {
62
62
  const targetBase = resolveTargetBase(args.target, args.cwd);
63
- const allowedArtifacts = new Set(args.artifacts ?? ["tool", "agent", "plugin"]);
63
+ const allowedArtifacts = new Set(args.artifacts ?? ["plugin"]);
64
64
  const releaseManifest = JSON.parse(await fs3.readFile(path3.join(args.packageRoot, "dist", "release-manifest.json"), "utf8"));
65
65
  const selectedArtifacts = releaseManifest.artifacts.filter((artifact) => allowedArtifacts.has(artifact.kind));
66
66
  const existingManifest = await loadInstalledManifest(targetBase);
67
+ const selectedRelativePaths = new Set(selectedArtifacts.map((artifact) => artifact.relativePath));
68
+ if (existingManifest) {
69
+ for (const file of existingManifest.files) {
70
+ if (selectedRelativePaths.has(file.relativePath)) {
71
+ continue;
72
+ }
73
+ await fs3.rm(path3.join(targetBase, file.relativePath), { force: true });
74
+ }
75
+ }
67
76
  for (const artifact of selectedArtifacts) {
68
77
  const targetPath = path3.join(targetBase, artifact.relativePath);
69
78
  if (await pathExists(targetPath) && !existingManifest && !args.force) {
@@ -181,7 +190,7 @@ async function setupCommand(args) {
181
190
  await fs6.mkdir(configBase, { recursive: true });
182
191
  const configPath = await resolveConfigFile(configBase);
183
192
  await ensurePluginConfigured(configPath, pluginName);
184
- const installResult = await installCommand({ ...args, force: true, artifacts: ["agent", "plugin"] });
193
+ const installResult = await installCommand({ ...args, force: true, artifacts: ["plugin"] });
185
194
  return {
186
195
  configPath,
187
196
  targetBase: installResult.targetBase
@@ -18821,26 +18821,30 @@ var text_write_default = tool({
18821
18821
  });
18822
18822
 
18823
18823
  // src/plugin/index.ts
18824
+ function createOpencodeGbkHooks() {
18825
+ return {
18826
+ tool: {
18827
+ gbk_read: gbk_read_default,
18828
+ gbk_write: gbk_write_default,
18829
+ gbk_edit: gbk_edit_default,
18830
+ gbk_search: gbk_search_default,
18831
+ text_read: text_read_default,
18832
+ text_write: text_write_default,
18833
+ text_edit: text_edit_default
18834
+ },
18835
+ async "experimental.chat.system.transform"(_input, output) {
18836
+ appendTextToolSystemPrompt(output.system);
18837
+ }
18838
+ };
18839
+ }
18824
18840
  var pluginModule = {
18825
18841
  id: "opencode-gbk-tools",
18826
18842
  async server() {
18827
- return {
18828
- tool: {
18829
- gbk_read: gbk_read_default,
18830
- gbk_write: gbk_write_default,
18831
- gbk_edit: gbk_edit_default,
18832
- gbk_search: gbk_search_default,
18833
- text_read: text_read_default,
18834
- text_write: text_write_default,
18835
- text_edit: text_edit_default
18836
- },
18837
- async "experimental.chat.system.transform"(_input, output) {
18838
- appendTextToolSystemPrompt(output.system);
18839
- }
18840
- };
18843
+ return createOpencodeGbkHooks();
18841
18844
  }
18842
18845
  };
18843
18846
  var plugin_default = pluginModule;
18844
18847
  export {
18848
+ createOpencodeGbkHooks,
18845
18849
  plugin_default as default
18846
18850
  };