iubcli 4.2.16 → 4.2.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 +372 -372
- package/dist/index.js +49 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -837,24 +837,37 @@ async function editFile(filePath, target, replacement, signal) {
|
|
|
837
837
|
return `Error: "${filePath}" is a directory, not a file.`;
|
|
838
838
|
}
|
|
839
839
|
const content = fs2.readFileSync(targetFile, "utf8");
|
|
840
|
-
const usesCRLF = content.includes("\r\n");
|
|
841
840
|
let effectiveTarget = target;
|
|
842
841
|
let effectiveReplacement = replacement;
|
|
843
|
-
let
|
|
844
|
-
let
|
|
845
|
-
|
|
842
|
+
let searchContent = content;
|
|
843
|
+
let matchStart = -1;
|
|
844
|
+
let matchEnd = -1;
|
|
845
|
+
if (content.includes(target)) {
|
|
846
|
+
matchStart = content.indexOf(target);
|
|
847
|
+
matchEnd = matchStart + target.length;
|
|
848
|
+
} else {
|
|
846
849
|
const contentLF = content.replace(/\r\n/g, "\n");
|
|
847
850
|
const targetLF = target.replace(/\r\n/g, "\n");
|
|
848
|
-
if (contentLF.includes(targetLF)) {
|
|
849
|
-
normalizedMode = true;
|
|
850
|
-
workingContent = contentLF;
|
|
851
|
-
effectiveTarget = targetLF;
|
|
852
|
-
effectiveReplacement = replacement.replace(/\r\n/g, "\n");
|
|
853
|
-
} else {
|
|
851
|
+
if (!contentLF.includes(targetLF)) {
|
|
854
852
|
return `Error: Target string not found in "${filePath}". Please use read_file first to verify the exact lines and whitespace before calling edit_file.`;
|
|
855
853
|
}
|
|
854
|
+
searchContent = contentLF;
|
|
855
|
+
effectiveTarget = targetLF;
|
|
856
|
+
const indexMap = [];
|
|
857
|
+
for (let i = 0; i < content.length; i++) {
|
|
858
|
+
if (content[i] === "\r" && content[i + 1] === "\n") {
|
|
859
|
+
indexMap.push(i);
|
|
860
|
+
i++;
|
|
861
|
+
} else {
|
|
862
|
+
indexMap.push(i);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
indexMap.push(content.length);
|
|
866
|
+
const normalizedMatch = contentLF.indexOf(targetLF);
|
|
867
|
+
matchStart = indexMap[normalizedMatch];
|
|
868
|
+
matchEnd = indexMap[normalizedMatch + targetLF.length];
|
|
856
869
|
}
|
|
857
|
-
const occurrences =
|
|
870
|
+
const occurrences = searchContent.split(effectiveTarget).length - 1;
|
|
858
871
|
if (occurrences > 1) {
|
|
859
872
|
return `Warning: Target string matches ${occurrences} times in "${filePath}". Please include more surrounding context lines in 'target' so it matches uniquely.`;
|
|
860
873
|
}
|
|
@@ -870,14 +883,15 @@ With: ${effectiveReplacement.split("\n").length} line(s) (${effectiveReplacement
|
|
|
870
883
|
console.log(chalk2.cyan("Auto-approve enabled for this session."));
|
|
871
884
|
}
|
|
872
885
|
}
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
const
|
|
877
|
-
|
|
878
|
-
if (
|
|
879
|
-
|
|
886
|
+
const crlfCount = (content.match(/\r\n/g) || []).length;
|
|
887
|
+
const loneLfCount = (content.match(/\n/g) || []).length - crlfCount;
|
|
888
|
+
const fileEol = crlfCount > loneLfCount ? "\r\n" : "\n";
|
|
889
|
+
const matchedRegion = content.slice(matchStart, matchEnd);
|
|
890
|
+
const regionEol = matchedRegion.includes("\r\n") ? "\r\n" : matchedRegion.includes("\n") ? "\n" : fileEol;
|
|
891
|
+
if (effectiveReplacement.includes("\n")) {
|
|
892
|
+
effectiveReplacement = effectiveReplacement.replace(/\r\n|\n/g, regionEol);
|
|
880
893
|
}
|
|
894
|
+
const updatedContent = content.slice(0, matchStart) + effectiveReplacement + content.slice(matchEnd);
|
|
881
895
|
sessionFileHistory.push({
|
|
882
896
|
filePath: path2.relative(rootDir, targetFile).replace(/\\/g, "/"),
|
|
883
897
|
isNew: false,
|
|
@@ -2648,10 +2662,14 @@ async function interactiveSelect(config) {
|
|
|
2648
2662
|
if (parsed === null) {
|
|
2649
2663
|
escBuffer = rest;
|
|
2650
2664
|
escTimeout = setTimeout(() => {
|
|
2651
|
-
escBuffer = "";
|
|
2652
2665
|
escTimeout = null;
|
|
2653
|
-
|
|
2654
|
-
|
|
2666
|
+
if (escBuffer === "\x1B" || escBuffer === "\x1BO") {
|
|
2667
|
+
escBuffer = "";
|
|
2668
|
+
cancel();
|
|
2669
|
+
} else {
|
|
2670
|
+
escBuffer = "";
|
|
2671
|
+
}
|
|
2672
|
+
}, 250);
|
|
2655
2673
|
break;
|
|
2656
2674
|
}
|
|
2657
2675
|
if (parsed.type === "ctrl_c") {
|
|
@@ -2934,6 +2952,9 @@ async function interactiveInput(config) {
|
|
|
2934
2952
|
}
|
|
2935
2953
|
return;
|
|
2936
2954
|
}
|
|
2955
|
+
if (str === "\x1B[A" || str === "\x1BOA" || str === "\x1B[B" || str === "\x1BOB") {
|
|
2956
|
+
return;
|
|
2957
|
+
}
|
|
2937
2958
|
if (str.startsWith("\x1B[")) return;
|
|
2938
2959
|
const printable = str.replace(/[\x00-\x1f\x7f]/g, "");
|
|
2939
2960
|
if (printable.length > 0) {
|
|
@@ -3362,10 +3383,14 @@ async function readInlinePrompt(options) {
|
|
|
3362
3383
|
if (parsed === null) {
|
|
3363
3384
|
escBuffer = rest;
|
|
3364
3385
|
escTimeout = setTimeout(() => {
|
|
3365
|
-
escBuffer = "";
|
|
3366
3386
|
escTimeout = null;
|
|
3367
|
-
|
|
3368
|
-
|
|
3387
|
+
if (escBuffer === "\x1B" || escBuffer === "\x1BO") {
|
|
3388
|
+
escBuffer = "";
|
|
3389
|
+
cancel();
|
|
3390
|
+
} else {
|
|
3391
|
+
escBuffer = "";
|
|
3392
|
+
}
|
|
3393
|
+
}, 250);
|
|
3369
3394
|
return;
|
|
3370
3395
|
}
|
|
3371
3396
|
if (parsed.type === "ctrl_c") {
|