opencode-gbk-tools 0.1.16 → 0.1.18

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
@@ -205,6 +205,7 @@ A:不要。现在优先用 `mode="insertAfter"` 或 `mode="insertBefore"`,
205
205
 
206
206
  | 版本 | 说明 |
207
207
  |------|------|
208
+ | 0.1.17 | 修复 OpenCode 以 npm plugin 方式加载包时缺少 `./server` 导出导致的插件加载失败问题;补充 `main` 与 `./server` 入口兼容性 |
208
209
  | 0.1.16 | 去掉专属 `gbk-engine` agent 安装链路,改为通过 plugin + tools 让全部 agents 统一支持 `text_*` / `gbk_*`;同步更新安装说明 |
209
210
  | 0.1.15 | 为 GBK 大文件统一引入行字节索引与流式读/搜/改路径,提升局部编辑、搜索与大块修改时的性能、稳定性与准确性 |
210
211
  | 0.1.14 | 重新发布当前稳定产物,核对 `npm pack --dry-run` 输出包含完整 `dist/`,为下一次公开发布提供一致的打包基线 |
@@ -16307,6 +16307,34 @@ async function assertPathAllowed(filePath, context, allowExternal = false) {
16307
16307
  var STREAMING_FILE_SIZE_THRESHOLD_BYTES = 1024 * 1024;
16308
16308
  var STREAM_READ_CHUNK_SIZE_BYTES = 1024 * 1024;
16309
16309
  var gbkLineIndexCache = /* @__PURE__ */ new Map();
16310
+ var ANSI_RED = "\x1B[31m";
16311
+ var ANSI_GREEN = "\x1B[32m";
16312
+ var ANSI_DIM = "\x1B[2m";
16313
+ var ANSI_RESET = "\x1B[0m";
16314
+ function buildGbkLineDiffPreview(filePath, encoding, beforeText, afterText) {
16315
+ const beforeLines = normalizeNewlines(beforeText).split("\n");
16316
+ const afterLines = normalizeNewlines(afterText).split("\n");
16317
+ const maxLines = Math.max(beforeLines.length, afterLines.length);
16318
+ const lines = [
16319
+ `${ANSI_DIM}--- ${path2.basename(filePath)} (${encoding})${ANSI_RESET}`,
16320
+ `${ANSI_DIM}+++ ${path2.basename(filePath)} (${encoding})${ANSI_RESET}`
16321
+ ];
16322
+ for (let index = 0; index < maxLines; index += 1) {
16323
+ const before = beforeLines[index];
16324
+ const after = afterLines[index];
16325
+ if (before !== void 0 && after !== void 0 && before === after) {
16326
+ lines.push(` ${before}`);
16327
+ continue;
16328
+ }
16329
+ if (before !== void 0) {
16330
+ lines.push(`${ANSI_RED}-${before}${ANSI_RESET}`);
16331
+ }
16332
+ if (after !== void 0) {
16333
+ lines.push(`${ANSI_GREEN}+${after}${ANSI_RESET}`);
16334
+ }
16335
+ }
16336
+ return lines.join("\n");
16337
+ }
16310
16338
  function toSafeNumber(value) {
16311
16339
  return typeof value === "bigint" ? Number(value) : value;
16312
16340
  }
@@ -17169,7 +17197,8 @@ async function replaceGbkFileText(input) {
17169
17197
  inserted: false,
17170
17198
  skipped: true,
17171
17199
  bytesRead: current2.bytesRead,
17172
- bytesWritten: 0
17200
+ bytesWritten: 0,
17201
+ diffPreview: buildGbkLineDiffPreview(current2.filePath, current2.encoding, input.anchor ?? "", input.content ?? "")
17173
17202
  };
17174
17203
  }
17175
17204
  const buffer2 = import_iconv_lite.default.encode(insertResult.outputText, current2.encoding);
@@ -17184,7 +17213,8 @@ async function replaceGbkFileText(input) {
17184
17213
  inserted: true,
17185
17214
  skipped: false,
17186
17215
  bytesRead: current2.bytesRead,
17187
- bytesWritten: buffer2.byteLength
17216
+ bytesWritten: buffer2.byteLength,
17217
+ diffPreview: buildGbkLineDiffPreview(current2.filePath, current2.encoding, input.anchor ?? "", input.content ?? "")
17188
17218
  };
17189
17219
  }
17190
17220
  assertReplaceArguments(input);
@@ -17241,7 +17271,8 @@ async function replaceGbkFileText(input) {
17241
17271
  replacements: 1,
17242
17272
  occurrencesBefore: loose.occurrencesBefore,
17243
17273
  bytesRead: current.bytesRead,
17244
- bytesWritten: buffer2.byteLength
17274
+ bytesWritten: buffer2.byteLength,
17275
+ diffPreview: buildGbkLineDiffPreview(current.filePath, current.encoding, effectiveOldString, input.newString ?? "")
17245
17276
  };
17246
17277
  }
17247
17278
  }
@@ -17268,7 +17299,8 @@ async function replaceGbkFileText(input) {
17268
17299
  replacements: replaceAll ? occurrencesBefore : 1,
17269
17300
  occurrencesBefore,
17270
17301
  bytesRead: current.bytesRead,
17271
- bytesWritten: buffer.byteLength
17302
+ bytesWritten: buffer.byteLength,
17303
+ diffPreview: buildGbkLineDiffPreview(current.filePath, current.encoding, effectiveOldString, alignedNewString)
17272
17304
  };
17273
17305
  }
17274
17306
 
@@ -17323,6 +17355,7 @@ Insert mode:
17323
17355
  const result = await replaceGbkFileText({ ...args, context });
17324
17356
  const isReplace = "replacements" in result;
17325
17357
  const title = isReplace ? `GBK \u7F16\u8F91 ${result.encoding.toUpperCase()} x${result.replacements}` : result.inserted ? `GBK \u63D2\u5165 ${result.encoding.toUpperCase()} #${result.occurrence}` : `GBK \u8DF3\u8FC7 ${result.encoding.toUpperCase()} #${result.occurrence}`;
17358
+ const diffPreview = result.diffPreview ?? "";
17326
17359
  context.metadata({
17327
17360
  title,
17328
17361
  metadata: {
@@ -17337,10 +17370,11 @@ Insert mode:
17337
17370
  inserted: isReplace ? void 0 : result.inserted,
17338
17371
  skipped: isReplace ? void 0 : result.skipped,
17339
17372
  bytesRead: result.bytesRead,
17340
- bytesWritten: result.bytesWritten
17373
+ bytesWritten: result.bytesWritten,
17374
+ diffPreview
17341
17375
  }
17342
17376
  });
17343
- return JSON.stringify(result, null, 2);
17377
+ return JSON.stringify({ ...result, diffPreview: diffPreview || void 0 }, null, 2);
17344
17378
  }
17345
17379
  });
17346
17380
  export {
@@ -16577,13 +16577,17 @@ function assertInsertArguments(input) {
16577
16577
  throw createTextError("GBK_INVALID_ARGUMENT", "\u63D2\u5165\u6A21\u5F0F\u4E0D\u652F\u6301 startLine/endLine/startAnchor/endAnchor");
16578
16578
  }
16579
16579
  }
16580
+ var ANSI_RED = "\x1B[31m";
16581
+ var ANSI_GREEN = "\x1B[32m";
16582
+ var ANSI_DIM = "\x1B[2m";
16583
+ var ANSI_RESET = "\x1B[0m";
16580
16584
  function buildLineDiffPreview(filePath, encoding, beforeText, afterText) {
16581
16585
  const beforeLines = normalizeNewlines(beforeText).split("\n");
16582
16586
  const afterLines = normalizeNewlines(afterText).split("\n");
16583
16587
  const maxLines = Math.max(beforeLines.length, afterLines.length);
16584
16588
  const lines = [
16585
- `--- ${path3.basename(filePath)} (${encoding})`,
16586
- `+++ ${path3.basename(filePath)} (${encoding})`
16589
+ `${ANSI_DIM}--- ${path3.basename(filePath)} (${encoding})${ANSI_RESET}`,
16590
+ `${ANSI_DIM}+++ ${path3.basename(filePath)} (${encoding})${ANSI_RESET}`
16587
16591
  ];
16588
16592
  for (let index = 0; index < maxLines; index += 1) {
16589
16593
  const before = beforeLines[index];
@@ -16593,10 +16597,10 @@ function buildLineDiffPreview(filePath, encoding, beforeText, afterText) {
16593
16597
  continue;
16594
16598
  }
16595
16599
  if (before !== void 0) {
16596
- lines.push(`-${before}`);
16600
+ lines.push(`${ANSI_RED}-${before}${ANSI_RESET}`);
16597
16601
  }
16598
16602
  if (after !== void 0) {
16599
- lines.push(`+${after}`);
16603
+ lines.push(`${ANSI_GREEN}+${after}${ANSI_RESET}`);
16600
16604
  }
16601
16605
  }
16602
16606
  return lines.join("\n");
@@ -17009,6 +17013,7 @@ var text_edit_default = tool({
17009
17013
  async execute(args, context) {
17010
17014
  const result = await replaceTextFileText({ ...args, context });
17011
17015
  const title = result.mode === "replace" ? `\u6587\u672C\u7F16\u8F91 ${result.encoding.toUpperCase()} x${result.replacements}` : result.inserted ? `\u6587\u672C\u63D2\u5165 ${result.encoding.toUpperCase()} #${result.occurrence}` : `\u6587\u672C\u8DF3\u8FC7 ${result.encoding.toUpperCase()} #${result.occurrence}`;
17016
+ const diffPreview = result.diffPreview ?? "";
17012
17017
  context.metadata({
17013
17018
  title,
17014
17019
  metadata: {
@@ -17026,10 +17031,10 @@ var text_edit_default = tool({
17026
17031
  inserted: result.mode === "replace" ? void 0 : result.inserted,
17027
17032
  skipped: result.mode === "replace" ? void 0 : result.skipped,
17028
17033
  newlineStyle: result.newlineStyle,
17029
- diffPreview: result.diffPreview ?? ""
17034
+ diffPreview
17030
17035
  }
17031
17036
  });
17032
- return JSON.stringify(result, null, 2);
17037
+ return JSON.stringify({ ...result, diffPreview: diffPreview || void 0 }, null, 2);
17033
17038
  }
17034
17039
  });
17035
17040
  export {
@@ -16308,6 +16308,34 @@ async function assertPathAllowed(filePath, context, allowExternal = false) {
16308
16308
  var STREAMING_FILE_SIZE_THRESHOLD_BYTES = 1024 * 1024;
16309
16309
  var STREAM_READ_CHUNK_SIZE_BYTES = 1024 * 1024;
16310
16310
  var gbkLineIndexCache = /* @__PURE__ */ new Map();
16311
+ var ANSI_RED = "\x1B[31m";
16312
+ var ANSI_GREEN = "\x1B[32m";
16313
+ var ANSI_DIM = "\x1B[2m";
16314
+ var ANSI_RESET = "\x1B[0m";
16315
+ function buildGbkLineDiffPreview(filePath, encoding, beforeText, afterText) {
16316
+ const beforeLines = normalizeNewlines(beforeText).split("\n");
16317
+ const afterLines = normalizeNewlines(afterText).split("\n");
16318
+ const maxLines = Math.max(beforeLines.length, afterLines.length);
16319
+ const lines = [
16320
+ `${ANSI_DIM}--- ${path2.basename(filePath)} (${encoding})${ANSI_RESET}`,
16321
+ `${ANSI_DIM}+++ ${path2.basename(filePath)} (${encoding})${ANSI_RESET}`
16322
+ ];
16323
+ for (let index = 0; index < maxLines; index += 1) {
16324
+ const before = beforeLines[index];
16325
+ const after = afterLines[index];
16326
+ if (before !== void 0 && after !== void 0 && before === after) {
16327
+ lines.push(` ${before}`);
16328
+ continue;
16329
+ }
16330
+ if (before !== void 0) {
16331
+ lines.push(`${ANSI_RED}-${before}${ANSI_RESET}`);
16332
+ }
16333
+ if (after !== void 0) {
16334
+ lines.push(`${ANSI_GREEN}+${after}${ANSI_RESET}`);
16335
+ }
16336
+ }
16337
+ return lines.join("\n");
16338
+ }
16311
16339
  function toSafeNumber(value) {
16312
16340
  return typeof value === "bigint" ? Number(value) : value;
16313
16341
  }
@@ -17304,7 +17332,8 @@ async function replaceGbkFileText(input) {
17304
17332
  inserted: false,
17305
17333
  skipped: true,
17306
17334
  bytesRead: current2.bytesRead,
17307
- bytesWritten: 0
17335
+ bytesWritten: 0,
17336
+ diffPreview: buildGbkLineDiffPreview(current2.filePath, current2.encoding, input.anchor ?? "", input.content ?? "")
17308
17337
  };
17309
17338
  }
17310
17339
  const buffer2 = import_iconv_lite.default.encode(insertResult.outputText, current2.encoding);
@@ -17319,7 +17348,8 @@ async function replaceGbkFileText(input) {
17319
17348
  inserted: true,
17320
17349
  skipped: false,
17321
17350
  bytesRead: current2.bytesRead,
17322
- bytesWritten: buffer2.byteLength
17351
+ bytesWritten: buffer2.byteLength,
17352
+ diffPreview: buildGbkLineDiffPreview(current2.filePath, current2.encoding, input.anchor ?? "", input.content ?? "")
17323
17353
  };
17324
17354
  }
17325
17355
  assertReplaceArguments(input);
@@ -17376,7 +17406,8 @@ async function replaceGbkFileText(input) {
17376
17406
  replacements: 1,
17377
17407
  occurrencesBefore: loose.occurrencesBefore,
17378
17408
  bytesRead: current.bytesRead,
17379
- bytesWritten: buffer2.byteLength
17409
+ bytesWritten: buffer2.byteLength,
17410
+ diffPreview: buildGbkLineDiffPreview(current.filePath, current.encoding, effectiveOldString, input.newString ?? "")
17380
17411
  };
17381
17412
  }
17382
17413
  }
@@ -17403,7 +17434,8 @@ async function replaceGbkFileText(input) {
17403
17434
  replacements: replaceAll ? occurrencesBefore : 1,
17404
17435
  occurrencesBefore,
17405
17436
  bytesRead: current.bytesRead,
17406
- bytesWritten: buffer.byteLength
17437
+ bytesWritten: buffer.byteLength,
17438
+ diffPreview: buildGbkLineDiffPreview(current.filePath, current.encoding, effectiveOldString, alignedNewString)
17407
17439
  };
17408
17440
  }
17409
17441
  async function searchGbkFile(input) {
@@ -17619,6 +17651,7 @@ Insert mode:
17619
17651
  const result = await replaceGbkFileText({ ...args, context });
17620
17652
  const isReplace = "replacements" in result;
17621
17653
  const title = isReplace ? `GBK \u7F16\u8F91 ${result.encoding.toUpperCase()} x${result.replacements}` : result.inserted ? `GBK \u63D2\u5165 ${result.encoding.toUpperCase()} #${result.occurrence}` : `GBK \u8DF3\u8FC7 ${result.encoding.toUpperCase()} #${result.occurrence}`;
17654
+ const diffPreview = result.diffPreview ?? "";
17622
17655
  context.metadata({
17623
17656
  title,
17624
17657
  metadata: {
@@ -17633,10 +17666,11 @@ Insert mode:
17633
17666
  inserted: isReplace ? void 0 : result.inserted,
17634
17667
  skipped: isReplace ? void 0 : result.skipped,
17635
17668
  bytesRead: result.bytesRead,
17636
- bytesWritten: result.bytesWritten
17669
+ bytesWritten: result.bytesWritten,
17670
+ diffPreview
17637
17671
  }
17638
17672
  });
17639
- return JSON.stringify(result, null, 2);
17673
+ return JSON.stringify({ ...result, diffPreview: diffPreview || void 0 }, null, 2);
17640
17674
  }
17641
17675
  });
17642
17676
 
@@ -18017,13 +18051,17 @@ function assertInsertArguments2(input) {
18017
18051
  throw createTextError("GBK_INVALID_ARGUMENT", "\u63D2\u5165\u6A21\u5F0F\u4E0D\u652F\u6301 startLine/endLine/startAnchor/endAnchor");
18018
18052
  }
18019
18053
  }
18054
+ var ANSI_RED2 = "\x1B[31m";
18055
+ var ANSI_GREEN2 = "\x1B[32m";
18056
+ var ANSI_DIM2 = "\x1B[2m";
18057
+ var ANSI_RESET2 = "\x1B[0m";
18020
18058
  function buildLineDiffPreview(filePath, encoding, beforeText, afterText) {
18021
18059
  const beforeLines = normalizeNewlines2(beforeText).split("\n");
18022
18060
  const afterLines = normalizeNewlines2(afterText).split("\n");
18023
18061
  const maxLines = Math.max(beforeLines.length, afterLines.length);
18024
18062
  const lines = [
18025
- `--- ${path3.basename(filePath)} (${encoding})`,
18026
- `+++ ${path3.basename(filePath)} (${encoding})`
18063
+ `${ANSI_DIM2}--- ${path3.basename(filePath)} (${encoding})${ANSI_RESET2}`,
18064
+ `${ANSI_DIM2}+++ ${path3.basename(filePath)} (${encoding})${ANSI_RESET2}`
18027
18065
  ];
18028
18066
  for (let index = 0; index < maxLines; index += 1) {
18029
18067
  const before = beforeLines[index];
@@ -18033,10 +18071,10 @@ function buildLineDiffPreview(filePath, encoding, beforeText, afterText) {
18033
18071
  continue;
18034
18072
  }
18035
18073
  if (before !== void 0) {
18036
- lines.push(`-${before}`);
18074
+ lines.push(`${ANSI_RED2}-${before}${ANSI_RESET2}`);
18037
18075
  }
18038
18076
  if (after !== void 0) {
18039
- lines.push(`+${after}`);
18077
+ lines.push(`${ANSI_GREEN2}+${after}${ANSI_RESET2}`);
18040
18078
  }
18041
18079
  }
18042
18080
  return lines.join("\n");
@@ -18720,6 +18758,7 @@ var text_edit_default = tool({
18720
18758
  async execute(args, context) {
18721
18759
  const result = await replaceTextFileText({ ...args, context });
18722
18760
  const title = result.mode === "replace" ? `\u6587\u672C\u7F16\u8F91 ${result.encoding.toUpperCase()} x${result.replacements}` : result.inserted ? `\u6587\u672C\u63D2\u5165 ${result.encoding.toUpperCase()} #${result.occurrence}` : `\u6587\u672C\u8DF3\u8FC7 ${result.encoding.toUpperCase()} #${result.occurrence}`;
18761
+ const diffPreview = result.diffPreview ?? "";
18723
18762
  context.metadata({
18724
18763
  title,
18725
18764
  metadata: {
@@ -18737,10 +18776,10 @@ var text_edit_default = tool({
18737
18776
  inserted: result.mode === "replace" ? void 0 : result.inserted,
18738
18777
  skipped: result.mode === "replace" ? void 0 : result.skipped,
18739
18778
  newlineStyle: result.newlineStyle,
18740
- diffPreview: result.diffPreview ?? ""
18779
+ diffPreview
18741
18780
  }
18742
18781
  });
18743
- return JSON.stringify(result, null, 2);
18782
+ return JSON.stringify({ ...result, diffPreview: diffPreview || void 0 }, null, 2);
18744
18783
  }
18745
18784
  });
18746
18785
 
@@ -16308,6 +16308,34 @@ async function assertPathAllowed(filePath, context, allowExternal = false) {
16308
16308
  var STREAMING_FILE_SIZE_THRESHOLD_BYTES = 1024 * 1024;
16309
16309
  var STREAM_READ_CHUNK_SIZE_BYTES = 1024 * 1024;
16310
16310
  var gbkLineIndexCache = /* @__PURE__ */ new Map();
16311
+ var ANSI_RED = "\x1B[31m";
16312
+ var ANSI_GREEN = "\x1B[32m";
16313
+ var ANSI_DIM = "\x1B[2m";
16314
+ var ANSI_RESET = "\x1B[0m";
16315
+ function buildGbkLineDiffPreview(filePath, encoding, beforeText, afterText) {
16316
+ const beforeLines = normalizeNewlines(beforeText).split("\n");
16317
+ const afterLines = normalizeNewlines(afterText).split("\n");
16318
+ const maxLines = Math.max(beforeLines.length, afterLines.length);
16319
+ const lines = [
16320
+ `${ANSI_DIM}--- ${path2.basename(filePath)} (${encoding})${ANSI_RESET}`,
16321
+ `${ANSI_DIM}+++ ${path2.basename(filePath)} (${encoding})${ANSI_RESET}`
16322
+ ];
16323
+ for (let index = 0; index < maxLines; index += 1) {
16324
+ const before = beforeLines[index];
16325
+ const after = afterLines[index];
16326
+ if (before !== void 0 && after !== void 0 && before === after) {
16327
+ lines.push(` ${before}`);
16328
+ continue;
16329
+ }
16330
+ if (before !== void 0) {
16331
+ lines.push(`${ANSI_RED}-${before}${ANSI_RESET}`);
16332
+ }
16333
+ if (after !== void 0) {
16334
+ lines.push(`${ANSI_GREEN}+${after}${ANSI_RESET}`);
16335
+ }
16336
+ }
16337
+ return lines.join("\n");
16338
+ }
16311
16339
  function toSafeNumber(value) {
16312
16340
  return typeof value === "bigint" ? Number(value) : value;
16313
16341
  }
@@ -17304,7 +17332,8 @@ async function replaceGbkFileText(input) {
17304
17332
  inserted: false,
17305
17333
  skipped: true,
17306
17334
  bytesRead: current2.bytesRead,
17307
- bytesWritten: 0
17335
+ bytesWritten: 0,
17336
+ diffPreview: buildGbkLineDiffPreview(current2.filePath, current2.encoding, input.anchor ?? "", input.content ?? "")
17308
17337
  };
17309
17338
  }
17310
17339
  const buffer2 = import_iconv_lite.default.encode(insertResult.outputText, current2.encoding);
@@ -17319,7 +17348,8 @@ async function replaceGbkFileText(input) {
17319
17348
  inserted: true,
17320
17349
  skipped: false,
17321
17350
  bytesRead: current2.bytesRead,
17322
- bytesWritten: buffer2.byteLength
17351
+ bytesWritten: buffer2.byteLength,
17352
+ diffPreview: buildGbkLineDiffPreview(current2.filePath, current2.encoding, input.anchor ?? "", input.content ?? "")
17323
17353
  };
17324
17354
  }
17325
17355
  assertReplaceArguments(input);
@@ -17376,7 +17406,8 @@ async function replaceGbkFileText(input) {
17376
17406
  replacements: 1,
17377
17407
  occurrencesBefore: loose.occurrencesBefore,
17378
17408
  bytesRead: current.bytesRead,
17379
- bytesWritten: buffer2.byteLength
17409
+ bytesWritten: buffer2.byteLength,
17410
+ diffPreview: buildGbkLineDiffPreview(current.filePath, current.encoding, effectiveOldString, input.newString ?? "")
17380
17411
  };
17381
17412
  }
17382
17413
  }
@@ -17403,7 +17434,8 @@ async function replaceGbkFileText(input) {
17403
17434
  replacements: replaceAll ? occurrencesBefore : 1,
17404
17435
  occurrencesBefore,
17405
17436
  bytesRead: current.bytesRead,
17406
- bytesWritten: buffer.byteLength
17437
+ bytesWritten: buffer.byteLength,
17438
+ diffPreview: buildGbkLineDiffPreview(current.filePath, current.encoding, effectiveOldString, alignedNewString)
17407
17439
  };
17408
17440
  }
17409
17441
  async function searchGbkFile(input) {
@@ -17619,6 +17651,7 @@ Insert mode:
17619
17651
  const result = await replaceGbkFileText({ ...args, context });
17620
17652
  const isReplace = "replacements" in result;
17621
17653
  const title = isReplace ? `GBK \u7F16\u8F91 ${result.encoding.toUpperCase()} x${result.replacements}` : result.inserted ? `GBK \u63D2\u5165 ${result.encoding.toUpperCase()} #${result.occurrence}` : `GBK \u8DF3\u8FC7 ${result.encoding.toUpperCase()} #${result.occurrence}`;
17654
+ const diffPreview = result.diffPreview ?? "";
17622
17655
  context.metadata({
17623
17656
  title,
17624
17657
  metadata: {
@@ -17633,10 +17666,11 @@ Insert mode:
17633
17666
  inserted: isReplace ? void 0 : result.inserted,
17634
17667
  skipped: isReplace ? void 0 : result.skipped,
17635
17668
  bytesRead: result.bytesRead,
17636
- bytesWritten: result.bytesWritten
17669
+ bytesWritten: result.bytesWritten,
17670
+ diffPreview
17637
17671
  }
17638
17672
  });
17639
- return JSON.stringify(result, null, 2);
17673
+ return JSON.stringify({ ...result, diffPreview: diffPreview || void 0 }, null, 2);
17640
17674
  }
17641
17675
  });
17642
17676
 
@@ -18017,13 +18051,17 @@ function assertInsertArguments2(input) {
18017
18051
  throw createTextError("GBK_INVALID_ARGUMENT", "\u63D2\u5165\u6A21\u5F0F\u4E0D\u652F\u6301 startLine/endLine/startAnchor/endAnchor");
18018
18052
  }
18019
18053
  }
18054
+ var ANSI_RED2 = "\x1B[31m";
18055
+ var ANSI_GREEN2 = "\x1B[32m";
18056
+ var ANSI_DIM2 = "\x1B[2m";
18057
+ var ANSI_RESET2 = "\x1B[0m";
18020
18058
  function buildLineDiffPreview(filePath, encoding, beforeText, afterText) {
18021
18059
  const beforeLines = normalizeNewlines2(beforeText).split("\n");
18022
18060
  const afterLines = normalizeNewlines2(afterText).split("\n");
18023
18061
  const maxLines = Math.max(beforeLines.length, afterLines.length);
18024
18062
  const lines = [
18025
- `--- ${path3.basename(filePath)} (${encoding})`,
18026
- `+++ ${path3.basename(filePath)} (${encoding})`
18063
+ `${ANSI_DIM2}--- ${path3.basename(filePath)} (${encoding})${ANSI_RESET2}`,
18064
+ `${ANSI_DIM2}+++ ${path3.basename(filePath)} (${encoding})${ANSI_RESET2}`
18027
18065
  ];
18028
18066
  for (let index = 0; index < maxLines; index += 1) {
18029
18067
  const before = beforeLines[index];
@@ -18033,10 +18071,10 @@ function buildLineDiffPreview(filePath, encoding, beforeText, afterText) {
18033
18071
  continue;
18034
18072
  }
18035
18073
  if (before !== void 0) {
18036
- lines.push(`-${before}`);
18074
+ lines.push(`${ANSI_RED2}-${before}${ANSI_RESET2}`);
18037
18075
  }
18038
18076
  if (after !== void 0) {
18039
- lines.push(`+${after}`);
18077
+ lines.push(`${ANSI_GREEN2}+${after}${ANSI_RESET2}`);
18040
18078
  }
18041
18079
  }
18042
18080
  return lines.join("\n");
@@ -18720,6 +18758,7 @@ var text_edit_default = tool({
18720
18758
  async execute(args, context) {
18721
18759
  const result = await replaceTextFileText({ ...args, context });
18722
18760
  const title = result.mode === "replace" ? `\u6587\u672C\u7F16\u8F91 ${result.encoding.toUpperCase()} x${result.replacements}` : result.inserted ? `\u6587\u672C\u63D2\u5165 ${result.encoding.toUpperCase()} #${result.occurrence}` : `\u6587\u672C\u8DF3\u8FC7 ${result.encoding.toUpperCase()} #${result.occurrence}`;
18761
+ const diffPreview = result.diffPreview ?? "";
18723
18762
  context.metadata({
18724
18763
  title,
18725
18764
  metadata: {
@@ -18737,10 +18776,10 @@ var text_edit_default = tool({
18737
18776
  inserted: result.mode === "replace" ? void 0 : result.inserted,
18738
18777
  skipped: result.mode === "replace" ? void 0 : result.skipped,
18739
18778
  newlineStyle: result.newlineStyle,
18740
- diffPreview: result.diffPreview ?? ""
18779
+ diffPreview
18741
18780
  }
18742
18781
  });
18743
- return JSON.stringify(result, null, 2);
18782
+ return JSON.stringify({ ...result, diffPreview: diffPreview || void 0 }, null, 2);
18744
18783
  }
18745
18784
  });
18746
18785
 
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "manifestVersion": 1,
3
3
  "packageName": "opencode-gbk-tools",
4
- "packageVersion": "0.1.16",
4
+ "packageVersion": "0.1.18",
5
5
  "artifacts": [
6
6
  {
7
7
  "relativePath": "plugins/opencode-gbk-tools.js",
8
8
  "kind": "plugin",
9
- "expectedHash": "8dcda75f5d58a57a70accc76b6e6fe922e9b490b70c9351ba4ca2d420f2903cb",
9
+ "expectedHash": "c03ae5d53eef0adc0eb6791908c5a9c776af47f8e9e6f8191acb3a43736fa770",
10
10
  "hashAlgorithm": "sha256"
11
11
  }
12
12
  ]
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "opencode-gbk-tools",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "Auto-encoding text tools plus GBK/GB18030 tools for OpenCode",
5
5
  "type": "module",
6
+ "main": "./dist/plugin/index.js",
6
7
  "license": "MIT",
7
8
  "exports": {
8
9
  ".": "./dist/plugin/index.js",
10
+ "./server": "./dist/plugin/index.js",
9
11
  "./cli": "./dist/cli/index.js"
10
12
  },
11
13
  "bin": {