iubcli 4.2.18 → 5.0.0
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 +12 -0
- package/dist/index.js +66 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -333,6 +333,8 @@ iubcli/
|
|
|
333
333
|
|
|
334
334
|
## Development
|
|
335
335
|
|
|
336
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for the full development guide.
|
|
337
|
+
|
|
336
338
|
Clone the repository:
|
|
337
339
|
|
|
338
340
|
```bash
|
|
@@ -367,6 +369,16 @@ Package scripts:
|
|
|
367
369
|
|
|
368
370
|
---
|
|
369
371
|
|
|
372
|
+
## Documentation
|
|
373
|
+
|
|
374
|
+
- **[GET-STARTED.md](GET-STARTED.md)** — step-by-step guide for first-time users
|
|
375
|
+
- **[CONTRIBUTING.md](CONTRIBUTING.md)** — how to set up the dev environment and submit PRs
|
|
376
|
+
- **[CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md)** — community standards
|
|
377
|
+
- **[SECURITY.md](SECURITY.md)** — how to report vulnerabilities and security notes
|
|
378
|
+
- **[RELEASING.md](RELEASING.md)** — npm release process (maintainers)
|
|
379
|
+
|
|
380
|
+
---
|
|
381
|
+
|
|
370
382
|
## License
|
|
371
383
|
|
|
372
384
|
[MIT](license)
|
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
|
|
669
|
-
|
|
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
|
|
707
|
-
|
|
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
|
|
745
|
-
|
|
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
|
|
781
|
-
|
|
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
|
|
831
|
-
|
|
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
|
}
|
|
@@ -1147,6 +1200,9 @@ function runActualProcess(command, signal, cwd = process.cwd()) {
|
|
|
1147
1200
|
isTimedOut = true;
|
|
1148
1201
|
terminateChildTree(child);
|
|
1149
1202
|
}, timeoutMs);
|
|
1203
|
+
if (signal?.aborted) {
|
|
1204
|
+
onAbort();
|
|
1205
|
+
}
|
|
1150
1206
|
child.stdout.on("data", (data) => {
|
|
1151
1207
|
if (stdout.length < 20 * 1024 * 1024) {
|
|
1152
1208
|
stdout += data.toString();
|