opencode-gbk-tools 0.1.17 → 0.1.19
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.
|
@@ -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,9 +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
|
});
|
|
17377
|
+
if (diffPreview) return diffPreview;
|
|
17343
17378
|
return JSON.stringify(result, null, 2);
|
|
17344
17379
|
}
|
|
17345
17380
|
});
|
|
@@ -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
|
-
|
|
16586
|
-
|
|
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(
|
|
16600
|
+
lines.push(`${ANSI_RED}-${before}${ANSI_RESET}`);
|
|
16597
16601
|
}
|
|
16598
16602
|
if (after !== void 0) {
|
|
16599
|
-
lines.push(
|
|
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,9 +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
|
|
17034
|
+
diffPreview
|
|
17030
17035
|
}
|
|
17031
17036
|
});
|
|
17037
|
+
if (diffPreview) return diffPreview;
|
|
17032
17038
|
return JSON.stringify(result, null, 2);
|
|
17033
17039
|
}
|
|
17034
17040
|
});
|
package/dist/plugin/index.js
CHANGED
|
@@ -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,9 +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
|
});
|
|
17673
|
+
if (diffPreview) return diffPreview;
|
|
17639
17674
|
return JSON.stringify(result, null, 2);
|
|
17640
17675
|
}
|
|
17641
17676
|
});
|
|
@@ -18017,13 +18052,17 @@ function assertInsertArguments2(input) {
|
|
|
18017
18052
|
throw createTextError("GBK_INVALID_ARGUMENT", "\u63D2\u5165\u6A21\u5F0F\u4E0D\u652F\u6301 startLine/endLine/startAnchor/endAnchor");
|
|
18018
18053
|
}
|
|
18019
18054
|
}
|
|
18055
|
+
var ANSI_RED2 = "\x1B[31m";
|
|
18056
|
+
var ANSI_GREEN2 = "\x1B[32m";
|
|
18057
|
+
var ANSI_DIM2 = "\x1B[2m";
|
|
18058
|
+
var ANSI_RESET2 = "\x1B[0m";
|
|
18020
18059
|
function buildLineDiffPreview(filePath, encoding, beforeText, afterText) {
|
|
18021
18060
|
const beforeLines = normalizeNewlines2(beforeText).split("\n");
|
|
18022
18061
|
const afterLines = normalizeNewlines2(afterText).split("\n");
|
|
18023
18062
|
const maxLines = Math.max(beforeLines.length, afterLines.length);
|
|
18024
18063
|
const lines = [
|
|
18025
|
-
|
|
18026
|
-
|
|
18064
|
+
`${ANSI_DIM2}--- ${path3.basename(filePath)} (${encoding})${ANSI_RESET2}`,
|
|
18065
|
+
`${ANSI_DIM2}+++ ${path3.basename(filePath)} (${encoding})${ANSI_RESET2}`
|
|
18027
18066
|
];
|
|
18028
18067
|
for (let index = 0; index < maxLines; index += 1) {
|
|
18029
18068
|
const before = beforeLines[index];
|
|
@@ -18033,10 +18072,10 @@ function buildLineDiffPreview(filePath, encoding, beforeText, afterText) {
|
|
|
18033
18072
|
continue;
|
|
18034
18073
|
}
|
|
18035
18074
|
if (before !== void 0) {
|
|
18036
|
-
lines.push(
|
|
18075
|
+
lines.push(`${ANSI_RED2}-${before}${ANSI_RESET2}`);
|
|
18037
18076
|
}
|
|
18038
18077
|
if (after !== void 0) {
|
|
18039
|
-
lines.push(
|
|
18078
|
+
lines.push(`${ANSI_GREEN2}+${after}${ANSI_RESET2}`);
|
|
18040
18079
|
}
|
|
18041
18080
|
}
|
|
18042
18081
|
return lines.join("\n");
|
|
@@ -18720,6 +18759,7 @@ var text_edit_default = tool({
|
|
|
18720
18759
|
async execute(args, context) {
|
|
18721
18760
|
const result = await replaceTextFileText({ ...args, context });
|
|
18722
18761
|
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}`;
|
|
18762
|
+
const diffPreview = result.diffPreview ?? "";
|
|
18723
18763
|
context.metadata({
|
|
18724
18764
|
title,
|
|
18725
18765
|
metadata: {
|
|
@@ -18737,9 +18777,10 @@ var text_edit_default = tool({
|
|
|
18737
18777
|
inserted: result.mode === "replace" ? void 0 : result.inserted,
|
|
18738
18778
|
skipped: result.mode === "replace" ? void 0 : result.skipped,
|
|
18739
18779
|
newlineStyle: result.newlineStyle,
|
|
18740
|
-
diffPreview
|
|
18780
|
+
diffPreview
|
|
18741
18781
|
}
|
|
18742
18782
|
});
|
|
18783
|
+
if (diffPreview) return diffPreview;
|
|
18743
18784
|
return JSON.stringify(result, null, 2);
|
|
18744
18785
|
}
|
|
18745
18786
|
});
|
|
@@ -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,9 +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
|
});
|
|
17673
|
+
if (diffPreview) return diffPreview;
|
|
17639
17674
|
return JSON.stringify(result, null, 2);
|
|
17640
17675
|
}
|
|
17641
17676
|
});
|
|
@@ -18017,13 +18052,17 @@ function assertInsertArguments2(input) {
|
|
|
18017
18052
|
throw createTextError("GBK_INVALID_ARGUMENT", "\u63D2\u5165\u6A21\u5F0F\u4E0D\u652F\u6301 startLine/endLine/startAnchor/endAnchor");
|
|
18018
18053
|
}
|
|
18019
18054
|
}
|
|
18055
|
+
var ANSI_RED2 = "\x1B[31m";
|
|
18056
|
+
var ANSI_GREEN2 = "\x1B[32m";
|
|
18057
|
+
var ANSI_DIM2 = "\x1B[2m";
|
|
18058
|
+
var ANSI_RESET2 = "\x1B[0m";
|
|
18020
18059
|
function buildLineDiffPreview(filePath, encoding, beforeText, afterText) {
|
|
18021
18060
|
const beforeLines = normalizeNewlines2(beforeText).split("\n");
|
|
18022
18061
|
const afterLines = normalizeNewlines2(afterText).split("\n");
|
|
18023
18062
|
const maxLines = Math.max(beforeLines.length, afterLines.length);
|
|
18024
18063
|
const lines = [
|
|
18025
|
-
|
|
18026
|
-
|
|
18064
|
+
`${ANSI_DIM2}--- ${path3.basename(filePath)} (${encoding})${ANSI_RESET2}`,
|
|
18065
|
+
`${ANSI_DIM2}+++ ${path3.basename(filePath)} (${encoding})${ANSI_RESET2}`
|
|
18027
18066
|
];
|
|
18028
18067
|
for (let index = 0; index < maxLines; index += 1) {
|
|
18029
18068
|
const before = beforeLines[index];
|
|
@@ -18033,10 +18072,10 @@ function buildLineDiffPreview(filePath, encoding, beforeText, afterText) {
|
|
|
18033
18072
|
continue;
|
|
18034
18073
|
}
|
|
18035
18074
|
if (before !== void 0) {
|
|
18036
|
-
lines.push(
|
|
18075
|
+
lines.push(`${ANSI_RED2}-${before}${ANSI_RESET2}`);
|
|
18037
18076
|
}
|
|
18038
18077
|
if (after !== void 0) {
|
|
18039
|
-
lines.push(
|
|
18078
|
+
lines.push(`${ANSI_GREEN2}+${after}${ANSI_RESET2}`);
|
|
18040
18079
|
}
|
|
18041
18080
|
}
|
|
18042
18081
|
return lines.join("\n");
|
|
@@ -18720,6 +18759,7 @@ var text_edit_default = tool({
|
|
|
18720
18759
|
async execute(args, context) {
|
|
18721
18760
|
const result = await replaceTextFileText({ ...args, context });
|
|
18722
18761
|
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}`;
|
|
18762
|
+
const diffPreview = result.diffPreview ?? "";
|
|
18723
18763
|
context.metadata({
|
|
18724
18764
|
title,
|
|
18725
18765
|
metadata: {
|
|
@@ -18737,9 +18777,10 @@ var text_edit_default = tool({
|
|
|
18737
18777
|
inserted: result.mode === "replace" ? void 0 : result.inserted,
|
|
18738
18778
|
skipped: result.mode === "replace" ? void 0 : result.skipped,
|
|
18739
18779
|
newlineStyle: result.newlineStyle,
|
|
18740
|
-
diffPreview
|
|
18780
|
+
diffPreview
|
|
18741
18781
|
}
|
|
18742
18782
|
});
|
|
18783
|
+
if (diffPreview) return diffPreview;
|
|
18743
18784
|
return JSON.stringify(result, null, 2);
|
|
18744
18785
|
}
|
|
18745
18786
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifestVersion": 1,
|
|
3
3
|
"packageName": "opencode-gbk-tools",
|
|
4
|
-
"packageVersion": "0.1.
|
|
4
|
+
"packageVersion": "0.1.18",
|
|
5
5
|
"artifacts": [
|
|
6
6
|
{
|
|
7
7
|
"relativePath": "plugins/opencode-gbk-tools.js",
|
|
8
8
|
"kind": "plugin",
|
|
9
|
-
"expectedHash": "
|
|
9
|
+
"expectedHash": "3b78d961fb39a3c81714097415279f5606eae1af169146d8446ecda3866a5527",
|
|
10
10
|
"hashAlgorithm": "sha256"
|
|
11
11
|
}
|
|
12
12
|
]
|