opencode-gbk-tools 0.1.3 → 0.1.4
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.
|
@@ -16315,6 +16315,13 @@ function assertPositiveInteger(value, name) {
|
|
|
16315
16315
|
throw createGbkError("GBK_INVALID_ARGUMENT", `${name} \u5FC5\u987B\u662F\u6B63\u6574\u6570`);
|
|
16316
16316
|
}
|
|
16317
16317
|
}
|
|
16318
|
+
function normalizeOptionalPositiveInteger(value, name) {
|
|
16319
|
+
if (value === void 0 || value === -1) {
|
|
16320
|
+
return void 0;
|
|
16321
|
+
}
|
|
16322
|
+
assertPositiveInteger(value, name);
|
|
16323
|
+
return Number(value);
|
|
16324
|
+
}
|
|
16318
16325
|
function assertNotBinary(buffer) {
|
|
16319
16326
|
if (buffer.includes(0)) {
|
|
16320
16327
|
throw createGbkError("GBK_BINARY_FILE", "\u7591\u4F3C\u4E8C\u8FDB\u5236\u6587\u4EF6\uFF0C\u65E0\u6CD5\u6309 GBK \u6587\u672C\u5904\u7406");
|
|
@@ -16650,12 +16657,17 @@ async function replaceLargeGbkFileText(input) {
|
|
|
16650
16657
|
}
|
|
16651
16658
|
}
|
|
16652
16659
|
async function replaceGbkFileText(input) {
|
|
16660
|
+
const normalizedInput = {
|
|
16661
|
+
...input,
|
|
16662
|
+
startLine: normalizeOptionalPositiveInteger(input.startLine, "startLine"),
|
|
16663
|
+
endLine: normalizeOptionalPositiveInteger(input.endLine, "endLine")
|
|
16664
|
+
};
|
|
16653
16665
|
if (input.oldString.length === 0) {
|
|
16654
16666
|
throw createGbkError("GBK_EMPTY_OLD_STRING", "oldString \u4E0D\u80FD\u4E3A\u7A7A");
|
|
16655
16667
|
}
|
|
16656
|
-
const replaceAll =
|
|
16657
|
-
const resolved = await resolveReadableGbkFile(
|
|
16658
|
-
const hasScopedRange =
|
|
16668
|
+
const replaceAll = normalizedInput.replaceAll ?? false;
|
|
16669
|
+
const resolved = await resolveReadableGbkFile(normalizedInput);
|
|
16670
|
+
const hasScopedRange = normalizedInput.startLine !== void 0 || normalizedInput.endLine !== void 0 || normalizedInput.startAnchor !== void 0 || normalizedInput.endAnchor !== void 0;
|
|
16659
16671
|
if (resolved.stat.size >= STREAMING_FILE_SIZE_THRESHOLD_BYTES && !hasScopedRange) {
|
|
16660
16672
|
return await replaceLargeGbkFileText({
|
|
16661
16673
|
...resolved,
|
|
@@ -16665,10 +16677,10 @@ async function replaceGbkFileText(input) {
|
|
|
16665
16677
|
});
|
|
16666
16678
|
}
|
|
16667
16679
|
const current = await readWholeGbkTextFile(resolved);
|
|
16668
|
-
const scope = resolveEditScope(current.content,
|
|
16669
|
-
const occurrencesBefore = countOccurrences(scope.selectedText,
|
|
16680
|
+
const scope = resolveEditScope(current.content, normalizedInput);
|
|
16681
|
+
const occurrencesBefore = countOccurrences(scope.selectedText, normalizedInput.oldString);
|
|
16670
16682
|
if (!replaceAll && occurrencesBefore === 0) {
|
|
16671
|
-
const loose = tryLooseBlockReplace(scope.selectedText,
|
|
16683
|
+
const loose = tryLooseBlockReplace(scope.selectedText, normalizedInput.oldString, normalizedInput.newString);
|
|
16672
16684
|
if (loose !== null) {
|
|
16673
16685
|
const outputText2 = `${current.content.slice(0, scope.rangeStart)}${loose.content}${current.content.slice(scope.rangeEnd)}`;
|
|
16674
16686
|
const buffer2 = import_iconv_lite.default.encode(outputText2, current.encoding);
|
|
@@ -16685,14 +16697,14 @@ async function replaceGbkFileText(input) {
|
|
|
16685
16697
|
}
|
|
16686
16698
|
if (replaceAll) {
|
|
16687
16699
|
if (occurrencesBefore === 0) {
|
|
16688
|
-
throw createGbkError("GBK_NO_MATCH", buildNoMatchMessage(scope.selectedText,
|
|
16700
|
+
throw createGbkError("GBK_NO_MATCH", buildNoMatchMessage(scope.selectedText, normalizedInput.oldString));
|
|
16689
16701
|
}
|
|
16690
16702
|
} else if (occurrencesBefore === 0) {
|
|
16691
|
-
throw createGbkError("GBK_NO_MATCH", buildNoMatchMessage(scope.selectedText,
|
|
16703
|
+
throw createGbkError("GBK_NO_MATCH", buildNoMatchMessage(scope.selectedText, normalizedInput.oldString));
|
|
16692
16704
|
} else if (occurrencesBefore > 1) {
|
|
16693
|
-
throw createGbkError("GBK_MULTIPLE_MATCHES", `\u627E\u5230\u591A\u4E2A\u5339\u914D\u9879: ${
|
|
16705
|
+
throw createGbkError("GBK_MULTIPLE_MATCHES", `\u627E\u5230\u591A\u4E2A\u5339\u914D\u9879: ${normalizedInput.oldString}`);
|
|
16694
16706
|
}
|
|
16695
|
-
const replaced = replaceAll ? scope.selectedText.split(
|
|
16707
|
+
const replaced = replaceAll ? scope.selectedText.split(normalizedInput.oldString).join(normalizedInput.newString) : scope.selectedText.replace(normalizedInput.oldString, normalizedInput.newString);
|
|
16696
16708
|
const outputText = `${current.content.slice(0, scope.rangeStart)}${replaced}${current.content.slice(scope.rangeEnd)}`;
|
|
16697
16709
|
const buffer = import_iconv_lite.default.encode(outputText, current.encoding);
|
|
16698
16710
|
await fs2.writeFile(current.filePath, buffer);
|
|
@@ -16714,8 +16726,8 @@ var gbk_edit_default = tool({
|
|
|
16714
16726
|
oldString: tool.schema.string().describe("Text to replace"),
|
|
16715
16727
|
newString: tool.schema.string().describe("Replacement text"),
|
|
16716
16728
|
replaceAll: tool.schema.boolean().optional().describe("Replace all occurrences"),
|
|
16717
|
-
startLine: tool.schema.number().int().positive().optional().describe("Restrict edit to 1-based start line"),
|
|
16718
|
-
endLine: tool.schema.number().int().positive().optional().describe("Restrict edit to 1-based end line"),
|
|
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"),
|
|
16719
16731
|
startAnchor: tool.schema.string().optional().describe("Restrict edit to content after this anchor"),
|
|
16720
16732
|
endAnchor: tool.schema.string().optional().describe("Restrict edit to content before this anchor"),
|
|
16721
16733
|
encoding: tool.schema.enum(["gbk", "gb18030"]).optional().describe("Text encoding"),
|
|
@@ -16315,6 +16315,13 @@ function assertPositiveInteger(value, name) {
|
|
|
16315
16315
|
throw createGbkError("GBK_INVALID_ARGUMENT", `${name} \u5FC5\u987B\u662F\u6B63\u6574\u6570`);
|
|
16316
16316
|
}
|
|
16317
16317
|
}
|
|
16318
|
+
function normalizeOptionalPositiveInteger(value, name) {
|
|
16319
|
+
if (value === void 0 || value === -1) {
|
|
16320
|
+
return void 0;
|
|
16321
|
+
}
|
|
16322
|
+
assertPositiveInteger(value, name);
|
|
16323
|
+
return Number(value);
|
|
16324
|
+
}
|
|
16318
16325
|
function assertNotBinary(buffer) {
|
|
16319
16326
|
if (buffer.includes(0)) {
|
|
16320
16327
|
throw createGbkError("GBK_BINARY_FILE", "\u7591\u4F3C\u4E8C\u8FDB\u5236\u6587\u4EF6\uFF0C\u65E0\u6CD5\u6309 GBK \u6587\u672C\u5904\u7406");
|
|
@@ -16556,8 +16563,8 @@ function createTailCollector(limit) {
|
|
|
16556
16563
|
};
|
|
16557
16564
|
}
|
|
16558
16565
|
async function readGbkFile(input) {
|
|
16559
|
-
const offset = input.offset ?? 1;
|
|
16560
|
-
const limit = input.limit ?? 2e3;
|
|
16566
|
+
const offset = normalizeOptionalPositiveInteger(input.offset, "offset") ?? 1;
|
|
16567
|
+
const limit = normalizeOptionalPositiveInteger(input.limit, "limit") ?? 2e3;
|
|
16561
16568
|
const tail = input.tail ?? false;
|
|
16562
16569
|
const resolved = await resolveReadableGbkFile(input);
|
|
16563
16570
|
if (resolved.stat.size < STREAMING_FILE_SIZE_THRESHOLD_BYTES) {
|
|
@@ -16600,8 +16607,8 @@ var gbk_read_default = tool({
|
|
|
16600
16607
|
description: "Read GBK encoded text files",
|
|
16601
16608
|
args: {
|
|
16602
16609
|
filePath: tool.schema.string().describe("Target file path"),
|
|
16603
|
-
offset: tool.schema.number().int().positive().optional().describe("1-based start line"),
|
|
16604
|
-
limit: tool.schema.number().int().positive().optional().describe("Number of lines to read"),
|
|
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"),
|
|
16605
16612
|
tail: tool.schema.boolean().optional().describe("Read last N lines instead of offset-based window"),
|
|
16606
16613
|
encoding: tool.schema.enum(["gbk", "gb18030"]).optional().describe("Text encoding"),
|
|
16607
16614
|
allowExternal: tool.schema.boolean().optional().describe("Allow paths outside workspace root")
|
package/dist/plugin/index.js
CHANGED
|
@@ -16315,6 +16315,13 @@ function assertPositiveInteger(value, name) {
|
|
|
16315
16315
|
throw createGbkError("GBK_INVALID_ARGUMENT", `${name} \u5FC5\u987B\u662F\u6B63\u6574\u6570`);
|
|
16316
16316
|
}
|
|
16317
16317
|
}
|
|
16318
|
+
function normalizeOptionalPositiveInteger(value, name) {
|
|
16319
|
+
if (value === void 0 || value === -1) {
|
|
16320
|
+
return void 0;
|
|
16321
|
+
}
|
|
16322
|
+
assertPositiveInteger(value, name);
|
|
16323
|
+
return Number(value);
|
|
16324
|
+
}
|
|
16318
16325
|
function assertNotBinary(buffer) {
|
|
16319
16326
|
if (buffer.includes(0)) {
|
|
16320
16327
|
throw createGbkError("GBK_BINARY_FILE", "\u7591\u4F3C\u4E8C\u8FDB\u5236\u6587\u4EF6\uFF0C\u65E0\u6CD5\u6309 GBK \u6587\u672C\u5904\u7406");
|
|
@@ -16805,8 +16812,8 @@ async function replaceLargeGbkFileText(input) {
|
|
|
16805
16812
|
}
|
|
16806
16813
|
}
|
|
16807
16814
|
async function readGbkFile(input) {
|
|
16808
|
-
const offset = input.offset ?? 1;
|
|
16809
|
-
const limit = input.limit ?? 2e3;
|
|
16815
|
+
const offset = normalizeOptionalPositiveInteger(input.offset, "offset") ?? 1;
|
|
16816
|
+
const limit = normalizeOptionalPositiveInteger(input.limit, "limit") ?? 2e3;
|
|
16810
16817
|
const tail = input.tail ?? false;
|
|
16811
16818
|
const resolved = await resolveReadableGbkFile(input);
|
|
16812
16819
|
if (resolved.stat.size < STREAMING_FILE_SIZE_THRESHOLD_BYTES) {
|
|
@@ -16844,12 +16851,17 @@ async function readGbkFile(input) {
|
|
|
16844
16851
|
};
|
|
16845
16852
|
}
|
|
16846
16853
|
async function replaceGbkFileText(input) {
|
|
16854
|
+
const normalizedInput = {
|
|
16855
|
+
...input,
|
|
16856
|
+
startLine: normalizeOptionalPositiveInteger(input.startLine, "startLine"),
|
|
16857
|
+
endLine: normalizeOptionalPositiveInteger(input.endLine, "endLine")
|
|
16858
|
+
};
|
|
16847
16859
|
if (input.oldString.length === 0) {
|
|
16848
16860
|
throw createGbkError("GBK_EMPTY_OLD_STRING", "oldString \u4E0D\u80FD\u4E3A\u7A7A");
|
|
16849
16861
|
}
|
|
16850
|
-
const replaceAll =
|
|
16851
|
-
const resolved = await resolveReadableGbkFile(
|
|
16852
|
-
const hasScopedRange =
|
|
16862
|
+
const replaceAll = normalizedInput.replaceAll ?? false;
|
|
16863
|
+
const resolved = await resolveReadableGbkFile(normalizedInput);
|
|
16864
|
+
const hasScopedRange = normalizedInput.startLine !== void 0 || normalizedInput.endLine !== void 0 || normalizedInput.startAnchor !== void 0 || normalizedInput.endAnchor !== void 0;
|
|
16853
16865
|
if (resolved.stat.size >= STREAMING_FILE_SIZE_THRESHOLD_BYTES && !hasScopedRange) {
|
|
16854
16866
|
return await replaceLargeGbkFileText({
|
|
16855
16867
|
...resolved,
|
|
@@ -16859,10 +16871,10 @@ async function replaceGbkFileText(input) {
|
|
|
16859
16871
|
});
|
|
16860
16872
|
}
|
|
16861
16873
|
const current = await readWholeGbkTextFile(resolved);
|
|
16862
|
-
const scope = resolveEditScope(current.content,
|
|
16863
|
-
const occurrencesBefore = countOccurrences(scope.selectedText,
|
|
16874
|
+
const scope = resolveEditScope(current.content, normalizedInput);
|
|
16875
|
+
const occurrencesBefore = countOccurrences(scope.selectedText, normalizedInput.oldString);
|
|
16864
16876
|
if (!replaceAll && occurrencesBefore === 0) {
|
|
16865
|
-
const loose = tryLooseBlockReplace(scope.selectedText,
|
|
16877
|
+
const loose = tryLooseBlockReplace(scope.selectedText, normalizedInput.oldString, normalizedInput.newString);
|
|
16866
16878
|
if (loose !== null) {
|
|
16867
16879
|
const outputText2 = `${current.content.slice(0, scope.rangeStart)}${loose.content}${current.content.slice(scope.rangeEnd)}`;
|
|
16868
16880
|
const buffer2 = import_iconv_lite.default.encode(outputText2, current.encoding);
|
|
@@ -16879,14 +16891,14 @@ async function replaceGbkFileText(input) {
|
|
|
16879
16891
|
}
|
|
16880
16892
|
if (replaceAll) {
|
|
16881
16893
|
if (occurrencesBefore === 0) {
|
|
16882
|
-
throw createGbkError("GBK_NO_MATCH", buildNoMatchMessage(scope.selectedText,
|
|
16894
|
+
throw createGbkError("GBK_NO_MATCH", buildNoMatchMessage(scope.selectedText, normalizedInput.oldString));
|
|
16883
16895
|
}
|
|
16884
16896
|
} else if (occurrencesBefore === 0) {
|
|
16885
|
-
throw createGbkError("GBK_NO_MATCH", buildNoMatchMessage(scope.selectedText,
|
|
16897
|
+
throw createGbkError("GBK_NO_MATCH", buildNoMatchMessage(scope.selectedText, normalizedInput.oldString));
|
|
16886
16898
|
} else if (occurrencesBefore > 1) {
|
|
16887
|
-
throw createGbkError("GBK_MULTIPLE_MATCHES", `\u627E\u5230\u591A\u4E2A\u5339\u914D\u9879: ${
|
|
16899
|
+
throw createGbkError("GBK_MULTIPLE_MATCHES", `\u627E\u5230\u591A\u4E2A\u5339\u914D\u9879: ${normalizedInput.oldString}`);
|
|
16888
16900
|
}
|
|
16889
|
-
const replaced = replaceAll ? scope.selectedText.split(
|
|
16901
|
+
const replaced = replaceAll ? scope.selectedText.split(normalizedInput.oldString).join(normalizedInput.newString) : scope.selectedText.replace(normalizedInput.oldString, normalizedInput.newString);
|
|
16890
16902
|
const outputText = `${current.content.slice(0, scope.rangeStart)}${replaced}${current.content.slice(scope.rangeEnd)}`;
|
|
16891
16903
|
const buffer = import_iconv_lite.default.encode(outputText, current.encoding);
|
|
16892
16904
|
await fs2.writeFile(current.filePath, buffer);
|
|
@@ -16965,8 +16977,8 @@ var gbk_edit_default = tool({
|
|
|
16965
16977
|
oldString: tool.schema.string().describe("Text to replace"),
|
|
16966
16978
|
newString: tool.schema.string().describe("Replacement text"),
|
|
16967
16979
|
replaceAll: tool.schema.boolean().optional().describe("Replace all occurrences"),
|
|
16968
|
-
startLine: tool.schema.number().int().positive().optional().describe("Restrict edit to 1-based start line"),
|
|
16969
|
-
endLine: tool.schema.number().int().positive().optional().describe("Restrict edit to 1-based end line"),
|
|
16980
|
+
startLine: tool.schema.union([tool.schema.number().int().positive(), tool.schema.literal(-1)]).optional().describe("Restrict edit to 1-based start line"),
|
|
16981
|
+
endLine: tool.schema.union([tool.schema.number().int().positive(), tool.schema.literal(-1)]).optional().describe("Restrict edit to 1-based end line"),
|
|
16970
16982
|
startAnchor: tool.schema.string().optional().describe("Restrict edit to content after this anchor"),
|
|
16971
16983
|
endAnchor: tool.schema.string().optional().describe("Restrict edit to content before this anchor"),
|
|
16972
16984
|
encoding: tool.schema.enum(["gbk", "gb18030"]).optional().describe("Text encoding"),
|
|
@@ -16983,8 +16995,8 @@ var gbk_read_default = tool({
|
|
|
16983
16995
|
description: "Read GBK encoded text files",
|
|
16984
16996
|
args: {
|
|
16985
16997
|
filePath: tool.schema.string().describe("Target file path"),
|
|
16986
|
-
offset: tool.schema.number().int().positive().optional().describe("1-based start line"),
|
|
16987
|
-
limit: tool.schema.number().int().positive().optional().describe("Number of lines to read"),
|
|
16998
|
+
offset: tool.schema.union([tool.schema.number().int().positive(), tool.schema.literal(-1)]).optional().describe("1-based start line"),
|
|
16999
|
+
limit: tool.schema.union([tool.schema.number().int().positive(), tool.schema.literal(-1)]).optional().describe("Number of lines to read"),
|
|
16988
17000
|
tail: tool.schema.boolean().optional().describe("Read last N lines instead of offset-based window"),
|
|
16989
17001
|
encoding: tool.schema.enum(["gbk", "gb18030"]).optional().describe("Text encoding"),
|
|
16990
17002
|
allowExternal: tool.schema.boolean().optional().describe("Allow paths outside workspace root")
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifestVersion": 1,
|
|
3
3
|
"packageName": "opencode-gbk-tools",
|
|
4
|
-
"packageVersion": "0.1.
|
|
4
|
+
"packageVersion": "0.1.4",
|
|
5
5
|
"artifacts": [
|
|
6
6
|
{
|
|
7
7
|
"relativePath": "tools/gbk_edit.js",
|
|
8
8
|
"kind": "tool",
|
|
9
|
-
"expectedHash": "
|
|
9
|
+
"expectedHash": "6a8a26850a21e47a9ececc2b8606452491a654d5fc79ef908cfbcea9e6c5b7e3",
|
|
10
10
|
"hashAlgorithm": "sha256"
|
|
11
11
|
},
|
|
12
12
|
{
|
|
13
13
|
"relativePath": "tools/gbk_read.js",
|
|
14
14
|
"kind": "tool",
|
|
15
|
-
"expectedHash": "
|
|
15
|
+
"expectedHash": "c61e5ee95e05e96965c76e5dc2f18b3943bc3c2a76567b415839442358024d46",
|
|
16
16
|
"hashAlgorithm": "sha256"
|
|
17
17
|
},
|
|
18
18
|
{
|