iubcli 4.2.17 → 4.2.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.
package/dist/index.js CHANGED
@@ -665,8 +665,11 @@ function undoLastChange() {
665
665
  return { success: false, message: "No file changes recorded in this session to undo." };
666
666
  }
667
667
  const lastChange = sessionFileHistory.pop();
668
- const rootDir = process.cwd();
669
- const targetFile = path2.resolve(rootDir, lastChange.filePath);
668
+ const resolved = resolveWorkspacePath(lastChange.filePath);
669
+ if (!resolved.ok) {
670
+ return { success: false, message: resolved.error };
671
+ }
672
+ const targetFile = resolved.path;
670
673
  try {
671
674
  if (lastChange.isNew) {
672
675
  if (fs2.existsSync(targetFile)) {
@@ -702,9 +705,54 @@ var IGNORED_DIRS = /* @__PURE__ */ new Set([
702
705
  ".vscode",
703
706
  ".idea"
704
707
  ]);
708
+ function resolveWorkspacePath(input) {
709
+ const rootDir = path2.resolve(process.cwd());
710
+ if (typeof input !== "string" || !input.trim() || input.includes("\0")) {
711
+ return { ok: false, error: 'Error: Missing, empty, or invalid "filePath" argument.' };
712
+ }
713
+ const absolute = path2.resolve(rootDir, input);
714
+ const outsideError = `Error: Path "${input}" is outside the workspace boundary. File tools are restricted to "${rootDir}".`;
715
+ if (!isPathWithin(rootDir, absolute)) {
716
+ return { ok: false, error: outsideError };
717
+ }
718
+ let probe = absolute;
719
+ const tail = [];
720
+ while (!fs2.existsSync(probe)) {
721
+ const parent = path2.dirname(probe);
722
+ if (parent === probe) break;
723
+ tail.unshift(path2.basename(probe));
724
+ probe = parent;
725
+ }
726
+ const realRoot = realPathOrSelf(rootDir);
727
+ const realProbe = realPathOrSelf(probe);
728
+ const realTarget = tail.length > 0 ? path2.join(realProbe, ...tail) : realProbe;
729
+ if (!isPathWithin(realRoot, realTarget)) {
730
+ return { ok: false, error: outsideError };
731
+ }
732
+ return { ok: true, path: absolute, root: rootDir };
733
+ }
734
+ function isPathWithin(rootDir, targetPath) {
735
+ const rel = path2.relative(rootDir, targetPath);
736
+ if (rel === "") return true;
737
+ if (path2.isAbsolute(rel)) return false;
738
+ return rel !== ".." && !rel.startsWith(".." + path2.sep);
739
+ }
740
+ function realPathOrSelf(targetPath) {
741
+ try {
742
+ return fs2.realpathSync.native(targetPath);
743
+ } catch {
744
+ try {
745
+ return fs2.realpathSync(targetPath);
746
+ } catch {
747
+ return targetPath;
748
+ }
749
+ }
750
+ }
705
751
  async function listFiles(dirPath = ".") {
706
- const rootDir = process.cwd();
707
- const targetDir = path2.resolve(rootDir, dirPath);
752
+ const resolved = resolveWorkspacePath(dirPath);
753
+ if (!resolved.ok) return resolved.error;
754
+ const rootDir = resolved.root;
755
+ const targetDir = resolved.path;
708
756
  if (!fs2.existsSync(targetDir)) {
709
757
  return `Error: Directory "${dirPath}" does not exist.`;
710
758
  }
@@ -741,8 +789,9 @@ async function readFile(filePath) {
741
789
  if (typeof filePath !== "string" || !filePath.trim()) {
742
790
  return 'Error: Missing or invalid "filePath" argument.';
743
791
  }
744
- const rootDir = process.cwd();
745
- const targetFile = path2.resolve(rootDir, filePath);
792
+ const resolved = resolveWorkspacePath(filePath);
793
+ if (!resolved.ok) return resolved.error;
794
+ const targetFile = resolved.path;
746
795
  if (!fs2.existsSync(targetFile)) {
747
796
  return `Error: File "${filePath}" does not exist.`;
748
797
  }
@@ -777,8 +826,10 @@ async function writeFile(filePath, content, signal) {
777
826
  if (typeof content !== "string") {
778
827
  return `Error: Missing or invalid "content" string for "${filePath}".`;
779
828
  }
780
- const rootDir = process.cwd();
781
- const targetFile = path2.resolve(rootDir, filePath);
829
+ const resolved = resolveWorkspacePath(filePath);
830
+ if (!resolved.ok) return resolved.error;
831
+ const rootDir = resolved.root;
832
+ const targetFile = resolved.path;
782
833
  const dirName = path2.dirname(targetFile);
783
834
  if (!safetySession.autoApproveAll) {
784
835
  const lineCount = content.split("\n").length;
@@ -827,8 +878,10 @@ async function editFile(filePath, target, replacement, signal) {
827
878
  if (target.length === 0) {
828
879
  return `Error: "target" cannot be empty. Provide exact lines to replace or use write_file.`;
829
880
  }
830
- const rootDir = process.cwd();
831
- const targetFile = path2.resolve(rootDir, filePath);
881
+ const resolved = resolveWorkspacePath(filePath);
882
+ if (!resolved.ok) return resolved.error;
883
+ const rootDir = resolved.root;
884
+ const targetFile = resolved.path;
832
885
  if (!fs2.existsSync(targetFile)) {
833
886
  return `Error: File "${filePath}" does not exist. Use write_file to create new files.`;
834
887
  }
@@ -2662,10 +2715,14 @@ async function interactiveSelect(config) {
2662
2715
  if (parsed === null) {
2663
2716
  escBuffer = rest;
2664
2717
  escTimeout = setTimeout(() => {
2665
- escBuffer = "";
2666
2718
  escTimeout = null;
2667
- cancel();
2668
- }, 60);
2719
+ if (escBuffer === "\x1B" || escBuffer === "\x1BO") {
2720
+ escBuffer = "";
2721
+ cancel();
2722
+ } else {
2723
+ escBuffer = "";
2724
+ }
2725
+ }, 250);
2669
2726
  break;
2670
2727
  }
2671
2728
  if (parsed.type === "ctrl_c") {
@@ -2948,6 +3005,9 @@ async function interactiveInput(config) {
2948
3005
  }
2949
3006
  return;
2950
3007
  }
3008
+ if (str === "\x1B[A" || str === "\x1BOA" || str === "\x1B[B" || str === "\x1BOB") {
3009
+ return;
3010
+ }
2951
3011
  if (str.startsWith("\x1B[")) return;
2952
3012
  const printable = str.replace(/[\x00-\x1f\x7f]/g, "");
2953
3013
  if (printable.length > 0) {
@@ -3376,10 +3436,14 @@ async function readInlinePrompt(options) {
3376
3436
  if (parsed === null) {
3377
3437
  escBuffer = rest;
3378
3438
  escTimeout = setTimeout(() => {
3379
- escBuffer = "";
3380
3439
  escTimeout = null;
3381
- cancel();
3382
- }, 60);
3440
+ if (escBuffer === "\x1B" || escBuffer === "\x1BO") {
3441
+ escBuffer = "";
3442
+ cancel();
3443
+ } else {
3444
+ escBuffer = "";
3445
+ }
3446
+ }, 250);
3383
3447
  return;
3384
3448
  }
3385
3449
  if (parsed.type === "ctrl_c") {