opencode-gbk-tools 0.1.25 → 0.1.27

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
@@ -64,7 +64,8 @@ npx opencode-gbk-tools uninstall
64
64
  - 原编码
65
65
  - BOM
66
66
  - 换行风格
67
- - 新文件在 `encoding=auto` 下不会自动默认成 `utf8`,需要显式指定 `encoding`
67
+ - 新建 `.txt` 文件在 `encoding=auto` 下默认使用 `gbk`
68
+ - 其他新文件在 `encoding=auto` 下不会自动默认成 `utf8`,仍需要显式指定 `encoding`
68
69
  - 当前支持:
69
70
  - `utf8`
70
71
  - `utf8-bom`
@@ -207,6 +208,8 @@ A:不要。现在优先用 `mode="insertAfter"` 或 `mode="insertBefore"`,
207
208
 
208
209
  | 版本 | 说明 |
209
210
  |------|------|
211
+ | 0.1.27 | 重新发布当前稳定内容,包含:新建 `.txt` 文件在 `encoding=auto` 下默认使用 `gbk`;保留已有文件的原编码检测与保持逻辑;修复 plugin 追加 system 规则时可能触发部分 Jinja/chat template 的“System message must be at the beginning”异常;同步更新工具提示、README 与测试覆盖 |
212
+ | 0.1.26 | 仅提升发布版本号,用于重新发布当时的稳定内容 |
210
213
  | 0.1.25 | 恢复并正式发布专属 `gbk-engine` agent;通过 agent 白名单禁用内置 `read` / `write` / `edit` / `apply_patch`,只保留 `text_*` / `gbk_*` 自定义工具,并把 agent 纳入构建、安装与 release manifest |
211
214
  | 0.1.17 | 修复 OpenCode 以 npm plugin 方式加载包时缺少 `./server` 导出导致的插件加载失败问题;补充 `main` 与 `./server` 入口兼容性 |
212
215
  | 0.1.16 | 去掉专属 `gbk-engine` agent 安装链路,改为通过 plugin + tools 让全部 agents 统一支持 `text_*` / `gbk_*`;同步更新安装说明 |
@@ -16340,6 +16340,9 @@ function resolveExplicitTextEncoding(value, fallback) {
16340
16340
  const requested = value ?? "auto";
16341
16341
  return requested === "auto" ? fallback : requested;
16342
16342
  }
16343
+ function shouldDefaultNewTextFileToGbk(filePath) {
16344
+ return path3.extname(filePath).toLowerCase() === ".txt";
16345
+ }
16343
16346
  function getBomPrefix(encoding, hasBom) {
16344
16347
  if (!hasBom) {
16345
16348
  return Buffer.alloc(0);
@@ -16626,10 +16629,11 @@ async function writeTextFile(input) {
16626
16629
  if (existing && !append && !overwrite) {
16627
16630
  throw createTextError("GBK_FILE_EXISTS", `\u76EE\u6807\u6587\u4EF6\u5DF2\u5B58\u5728: ${candidatePath}`);
16628
16631
  }
16629
- if (!existing && requestedEncoding === "auto") {
16630
- throw createTextError("TEXT_UNKNOWN_ENCODING", "\u65B0\u6587\u4EF6\u5728 encoding=auto \u4E0B\u65E0\u6CD5\u786E\u5B9A\u7F16\u7801\uFF0C\u8BF7\u663E\u5F0F\u6307\u5B9A encoding");
16632
+ const newFileDefaultEncoding = !existing && requestedEncoding === "auto" && shouldDefaultNewTextFileToGbk(candidatePath) ? "gbk" : null;
16633
+ if (!existing && requestedEncoding === "auto" && !newFileDefaultEncoding) {
16634
+ throw createTextError("TEXT_UNKNOWN_ENCODING", "\u65B0\u6587\u4EF6\u5728 encoding=auto \u4E0B\u65E0\u6CD5\u786E\u5B9A\u7F16\u7801\uFF1B.txt \u65B0\u6587\u4EF6\u4F1A\u9ED8\u8BA4\u4F7F\u7528 GBK\uFF0C\u5176\u4ED6\u6587\u4EF6\u8BF7\u663E\u5F0F\u6307\u5B9A encoding");
16631
16635
  }
16632
- const targetEncoding = existing && preserveEncoding ? existing.encoding : resolveExplicitTextEncoding(requestedEncoding, existing?.encoding ?? "utf8");
16636
+ const targetEncoding = existing && preserveEncoding ? existing.encoding : requestedEncoding === "auto" && newFileDefaultEncoding ? newFileDefaultEncoding : resolveExplicitTextEncoding(requestedEncoding, existing?.encoding ?? "utf8");
16633
16637
  const targetHasBom = targetEncoding === "utf8-bom" ? true : existing && preserveEncoding ? existing.hasBom : targetEncoding === "utf16le" || targetEncoding === "utf16be" ? true : false;
16634
16638
  const baseContent = append ? existing?.content ?? "" : "";
16635
16639
  const rawContent = `${baseContent}${input.content}`;
@@ -16657,7 +16661,8 @@ var text_write_default = tool({
16657
16661
  description: `Write text files while preserving detected encoding and newline style by default.
16658
16662
 
16659
16663
  - Existing files keep their original encoding when encoding=auto.
16660
- - New files require explicit encoding when encoding=auto.
16664
+ - New .txt files default to GBK when encoding=auto.
16665
+ - Other new files still require explicit encoding when encoding=auto.
16661
16666
  - Supports append and overwrite modes.`,
16662
16667
  args: {
16663
16668
  filePath: tool.schema.string().describe("Target file path"),
@@ -18036,7 +18036,7 @@ var TEXT_TOOL_SYSTEM_PROMPT = [
18036
18036
  "\u6587\u672C\u6587\u4EF6\u5904\u7406\u89C4\u5219\uFF1A",
18037
18037
  "- \u5904\u7406\u6587\u672C\u6587\u4EF6\u65F6\uFF0C\u4F18\u5148\u4F7F\u7528 text_read\u3001text_write\u3001text_edit\u3002",
18038
18038
  "- text_* \u9ED8\u8BA4\u4F1A\u81EA\u52A8\u8BC6\u522B\u73B0\u6709\u6587\u4EF6\u7F16\u7801\uFF0C\u5E76\u5728\u4FEE\u6539\u65F6\u5C3D\u91CF\u4FDD\u6301\u539F\u7F16\u7801\u3001BOM \u548C\u6362\u884C\u98CE\u683C\u3002",
18039
- "- \u65B0\u6587\u4EF6\u5728 encoding=auto \u4E0B\u4E0D\u4F1A\u9759\u9ED8\u9ED8\u8BA4\u6210 utf8\uFF1B\u8BF7\u663E\u5F0F\u6307\u5B9A encoding\u3002",
18039
+ "- \u65B0\u5EFA .txt \u6587\u4EF6\u5728 encoding=auto \u4E0B\u9ED8\u8BA4\u4F7F\u7528 GBK\uFF1B\u5176\u4ED6\u65B0\u6587\u4EF6\u8BF7\u663E\u5F0F\u6307\u5B9A encoding\u3002",
18040
18040
  "- \u5982\u679C\u610F\u56FE\u662F\u2018\u5728\u67D0\u6807\u7B7E\u524D\u540E\u63D2\u5165\u5185\u5BB9\u2019\uFF0C\u4F18\u5148\u4F7F\u7528 mode=insertAfter \u6216 mode=insertBefore\uFF0C\u5E76\u4F20 anchor/content\u3002",
18041
18041
  "- \u53EA\u6709\u5728\u660E\u786E\u505A\u7CBE\u786E\u66FF\u6362\u65F6\uFF0C\u624D\u4F7F\u7528 oldString/newString\u3002",
18042
18042
  "- \u82E5\u68C0\u6D4B\u7F6E\u4FE1\u5EA6\u4E0D\u8DB3\u6216\u51FA\u73B0 TEXT_UNKNOWN_ENCODING\uFF0C\u8BF7\u663E\u5F0F\u6307\u5B9A encoding \u540E\u91CD\u8BD5\u3002",
@@ -18046,7 +18046,13 @@ function appendTextToolSystemPrompt(system) {
18046
18046
  if (system.some((item) => item.includes(TEXT_TOOL_SYSTEM_MARKER))) {
18047
18047
  return;
18048
18048
  }
18049
- system.push(TEXT_TOOL_SYSTEM_PROMPT);
18049
+ if (system.length === 0) {
18050
+ system.push(TEXT_TOOL_SYSTEM_PROMPT);
18051
+ return;
18052
+ }
18053
+ system[0] = `${system[0]}
18054
+
18055
+ ${TEXT_TOOL_SYSTEM_PROMPT}`;
18050
18056
  }
18051
18057
 
18052
18058
  // src/lib/text-file.ts
@@ -18089,6 +18095,9 @@ function resolveExplicitTextEncoding(value, fallback) {
18089
18095
  const requested = value ?? "auto";
18090
18096
  return requested === "auto" ? fallback : requested;
18091
18097
  }
18098
+ function shouldDefaultNewTextFileToGbk(filePath) {
18099
+ return path3.extname(filePath).toLowerCase() === ".txt";
18100
+ }
18092
18101
  function getBomPrefix(encoding, hasBom) {
18093
18102
  if (!hasBom) {
18094
18103
  return Buffer.alloc(0);
@@ -18817,10 +18826,11 @@ async function writeTextFile(input) {
18817
18826
  if (existing && !append && !overwrite) {
18818
18827
  throw createTextError("GBK_FILE_EXISTS", `\u76EE\u6807\u6587\u4EF6\u5DF2\u5B58\u5728: ${candidatePath}`);
18819
18828
  }
18820
- if (!existing && requestedEncoding === "auto") {
18821
- throw createTextError("TEXT_UNKNOWN_ENCODING", "\u65B0\u6587\u4EF6\u5728 encoding=auto \u4E0B\u65E0\u6CD5\u786E\u5B9A\u7F16\u7801\uFF0C\u8BF7\u663E\u5F0F\u6307\u5B9A encoding");
18829
+ const newFileDefaultEncoding = !existing && requestedEncoding === "auto" && shouldDefaultNewTextFileToGbk(candidatePath) ? "gbk" : null;
18830
+ if (!existing && requestedEncoding === "auto" && !newFileDefaultEncoding) {
18831
+ throw createTextError("TEXT_UNKNOWN_ENCODING", "\u65B0\u6587\u4EF6\u5728 encoding=auto \u4E0B\u65E0\u6CD5\u786E\u5B9A\u7F16\u7801\uFF1B.txt \u65B0\u6587\u4EF6\u4F1A\u9ED8\u8BA4\u4F7F\u7528 GBK\uFF0C\u5176\u4ED6\u6587\u4EF6\u8BF7\u663E\u5F0F\u6307\u5B9A encoding");
18822
18832
  }
18823
- const targetEncoding = existing && preserveEncoding ? existing.encoding : resolveExplicitTextEncoding(requestedEncoding, existing?.encoding ?? "utf8");
18833
+ const targetEncoding = existing && preserveEncoding ? existing.encoding : requestedEncoding === "auto" && newFileDefaultEncoding ? newFileDefaultEncoding : resolveExplicitTextEncoding(requestedEncoding, existing?.encoding ?? "utf8");
18824
18834
  const targetHasBom = targetEncoding === "utf8-bom" ? true : existing && preserveEncoding ? existing.hasBom : targetEncoding === "utf16le" || targetEncoding === "utf16be" ? true : false;
18825
18835
  const baseContent = append ? existing?.content ?? "" : "";
18826
18836
  const rawContent = `${baseContent}${input.content}`;
@@ -19063,7 +19073,8 @@ var text_write_default = tool({
19063
19073
  description: `Write text files while preserving detected encoding and newline style by default.
19064
19074
 
19065
19075
  - Existing files keep their original encoding when encoding=auto.
19066
- - New files require explicit encoding when encoding=auto.
19076
+ - New .txt files default to GBK when encoding=auto.
19077
+ - Other new files still require explicit encoding when encoding=auto.
19067
19078
  - Supports append and overwrite modes.`,
19068
19079
  args: {
19069
19080
  filePath: tool.schema.string().describe("Target file path"),
@@ -18036,7 +18036,7 @@ var TEXT_TOOL_SYSTEM_PROMPT = [
18036
18036
  "\u6587\u672C\u6587\u4EF6\u5904\u7406\u89C4\u5219\uFF1A",
18037
18037
  "- \u5904\u7406\u6587\u672C\u6587\u4EF6\u65F6\uFF0C\u4F18\u5148\u4F7F\u7528 text_read\u3001text_write\u3001text_edit\u3002",
18038
18038
  "- text_* \u9ED8\u8BA4\u4F1A\u81EA\u52A8\u8BC6\u522B\u73B0\u6709\u6587\u4EF6\u7F16\u7801\uFF0C\u5E76\u5728\u4FEE\u6539\u65F6\u5C3D\u91CF\u4FDD\u6301\u539F\u7F16\u7801\u3001BOM \u548C\u6362\u884C\u98CE\u683C\u3002",
18039
- "- \u65B0\u6587\u4EF6\u5728 encoding=auto \u4E0B\u4E0D\u4F1A\u9759\u9ED8\u9ED8\u8BA4\u6210 utf8\uFF1B\u8BF7\u663E\u5F0F\u6307\u5B9A encoding\u3002",
18039
+ "- \u65B0\u5EFA .txt \u6587\u4EF6\u5728 encoding=auto \u4E0B\u9ED8\u8BA4\u4F7F\u7528 GBK\uFF1B\u5176\u4ED6\u65B0\u6587\u4EF6\u8BF7\u663E\u5F0F\u6307\u5B9A encoding\u3002",
18040
18040
  "- \u5982\u679C\u610F\u56FE\u662F\u2018\u5728\u67D0\u6807\u7B7E\u524D\u540E\u63D2\u5165\u5185\u5BB9\u2019\uFF0C\u4F18\u5148\u4F7F\u7528 mode=insertAfter \u6216 mode=insertBefore\uFF0C\u5E76\u4F20 anchor/content\u3002",
18041
18041
  "- \u53EA\u6709\u5728\u660E\u786E\u505A\u7CBE\u786E\u66FF\u6362\u65F6\uFF0C\u624D\u4F7F\u7528 oldString/newString\u3002",
18042
18042
  "- \u82E5\u68C0\u6D4B\u7F6E\u4FE1\u5EA6\u4E0D\u8DB3\u6216\u51FA\u73B0 TEXT_UNKNOWN_ENCODING\uFF0C\u8BF7\u663E\u5F0F\u6307\u5B9A encoding \u540E\u91CD\u8BD5\u3002",
@@ -18046,7 +18046,13 @@ function appendTextToolSystemPrompt(system) {
18046
18046
  if (system.some((item) => item.includes(TEXT_TOOL_SYSTEM_MARKER))) {
18047
18047
  return;
18048
18048
  }
18049
- system.push(TEXT_TOOL_SYSTEM_PROMPT);
18049
+ if (system.length === 0) {
18050
+ system.push(TEXT_TOOL_SYSTEM_PROMPT);
18051
+ return;
18052
+ }
18053
+ system[0] = `${system[0]}
18054
+
18055
+ ${TEXT_TOOL_SYSTEM_PROMPT}`;
18050
18056
  }
18051
18057
 
18052
18058
  // src/lib/text-file.ts
@@ -18089,6 +18095,9 @@ function resolveExplicitTextEncoding(value, fallback) {
18089
18095
  const requested = value ?? "auto";
18090
18096
  return requested === "auto" ? fallback : requested;
18091
18097
  }
18098
+ function shouldDefaultNewTextFileToGbk(filePath) {
18099
+ return path3.extname(filePath).toLowerCase() === ".txt";
18100
+ }
18092
18101
  function getBomPrefix(encoding, hasBom) {
18093
18102
  if (!hasBom) {
18094
18103
  return Buffer.alloc(0);
@@ -18817,10 +18826,11 @@ async function writeTextFile(input) {
18817
18826
  if (existing && !append && !overwrite) {
18818
18827
  throw createTextError("GBK_FILE_EXISTS", `\u76EE\u6807\u6587\u4EF6\u5DF2\u5B58\u5728: ${candidatePath}`);
18819
18828
  }
18820
- if (!existing && requestedEncoding === "auto") {
18821
- throw createTextError("TEXT_UNKNOWN_ENCODING", "\u65B0\u6587\u4EF6\u5728 encoding=auto \u4E0B\u65E0\u6CD5\u786E\u5B9A\u7F16\u7801\uFF0C\u8BF7\u663E\u5F0F\u6307\u5B9A encoding");
18829
+ const newFileDefaultEncoding = !existing && requestedEncoding === "auto" && shouldDefaultNewTextFileToGbk(candidatePath) ? "gbk" : null;
18830
+ if (!existing && requestedEncoding === "auto" && !newFileDefaultEncoding) {
18831
+ throw createTextError("TEXT_UNKNOWN_ENCODING", "\u65B0\u6587\u4EF6\u5728 encoding=auto \u4E0B\u65E0\u6CD5\u786E\u5B9A\u7F16\u7801\uFF1B.txt \u65B0\u6587\u4EF6\u4F1A\u9ED8\u8BA4\u4F7F\u7528 GBK\uFF0C\u5176\u4ED6\u6587\u4EF6\u8BF7\u663E\u5F0F\u6307\u5B9A encoding");
18822
18832
  }
18823
- const targetEncoding = existing && preserveEncoding ? existing.encoding : resolveExplicitTextEncoding(requestedEncoding, existing?.encoding ?? "utf8");
18833
+ const targetEncoding = existing && preserveEncoding ? existing.encoding : requestedEncoding === "auto" && newFileDefaultEncoding ? newFileDefaultEncoding : resolveExplicitTextEncoding(requestedEncoding, existing?.encoding ?? "utf8");
18824
18834
  const targetHasBom = targetEncoding === "utf8-bom" ? true : existing && preserveEncoding ? existing.hasBom : targetEncoding === "utf16le" || targetEncoding === "utf16be" ? true : false;
18825
18835
  const baseContent = append ? existing?.content ?? "" : "";
18826
18836
  const rawContent = `${baseContent}${input.content}`;
@@ -19063,7 +19073,8 @@ var text_write_default = tool({
19063
19073
  description: `Write text files while preserving detected encoding and newline style by default.
19064
19074
 
19065
19075
  - Existing files keep their original encoding when encoding=auto.
19066
- - New files require explicit encoding when encoding=auto.
19076
+ - New .txt files default to GBK when encoding=auto.
19077
+ - Other new files still require explicit encoding when encoding=auto.
19067
19078
  - Supports append and overwrite modes.`,
19068
19079
  args: {
19069
19080
  filePath: tool.schema.string().describe("Target file path"),
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "manifestVersion": 1,
3
3
  "packageName": "opencode-gbk-tools",
4
- "packageVersion": "0.1.25",
4
+ "packageVersion": "0.1.27",
5
5
  "artifacts": [
6
6
  {
7
7
  "relativePath": "plugins/opencode-gbk-tools.js",
8
8
  "kind": "plugin",
9
- "expectedHash": "55f2eae379bf3bd5a9129fbc413f255a4ffd9186d90a4fe26ecb3cc75b5a4c68",
9
+ "expectedHash": "7d7c0b0f3c801e9017e167b21a098ae2992b36e0d95deebb13a85d4f163db84f",
10
10
  "hashAlgorithm": "sha256"
11
11
  },
12
12
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-gbk-tools",
3
- "version": "0.1.25",
3
+ "version": "0.1.27",
4
4
  "description": "Auto-encoding text tools plus GBK/GB18030 tools for OpenCode",
5
5
  "type": "module",
6
6
  "main": "./dist/plugin/index.js",