@oxecli/oxe 1.0.76 → 1.0.77
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/engine.js +1 -1
- package/dist/tools.js +23 -16
- package/package.json +1 -1
package/dist/engine.js
CHANGED
|
@@ -103,7 +103,7 @@ export class InferenceEngine {
|
|
|
103
103
|
result = await toolBash(args.command, args.timeout, args.cwd);
|
|
104
104
|
break;
|
|
105
105
|
case "glob":
|
|
106
|
-
result = toolGlob(args.pattern, args.path, args.limit);
|
|
106
|
+
result = toolGlob(args.pattern, args.path, args.limit, args.depth);
|
|
107
107
|
break;
|
|
108
108
|
case "grep":
|
|
109
109
|
result = toolGrep(args.pattern, args.path, args.glob, args.limit);
|
package/dist/tools.js
CHANGED
|
@@ -122,26 +122,26 @@ function displayDiff(pathName, oldContent, newContent) {
|
|
|
122
122
|
maxNum = Math.max(maxNum, v.newNum);
|
|
123
123
|
}
|
|
124
124
|
const numW = String(maxNum).length;
|
|
125
|
-
const
|
|
126
|
-
const bodyMax = Math.max(termW - plainLen(indent) - numW - 4, 20);
|
|
125
|
+
const bodyMax = Math.max(termW - numW - 4, 20);
|
|
127
126
|
const gap = " ".repeat(numW);
|
|
128
127
|
for (const v of visible) {
|
|
129
128
|
if (v.kind === "~") {
|
|
130
129
|
const body = truncateStyled(v.body, bodyMax);
|
|
131
|
-
pendingDiffOutput.push(`\x1b[90m${
|
|
130
|
+
pendingDiffOutput.push(`\x1b[90m${gap} ${body}\x1b[0m`);
|
|
132
131
|
continue;
|
|
133
132
|
}
|
|
134
133
|
const num = v.kind === "+" ? v.newNum : v.oldNum;
|
|
135
134
|
const numStr = num ? String(num).padStart(numW, " ") : gap;
|
|
136
135
|
if (v.kind === "+" || v.kind === "-") {
|
|
137
|
-
const
|
|
136
|
+
const bg = v.kind === "+" ? "\x1b[42m" : "\x1b[41m";
|
|
138
137
|
const sign = v.kind === "+" ? "+" : "-";
|
|
139
138
|
const body = truncateStyled(v.body, bodyMax);
|
|
140
|
-
|
|
139
|
+
const fill = Math.max(0, termW - numW - 4 - plainLen(body));
|
|
140
|
+
pendingDiffOutput.push(`${bg}\x1b[97m${numStr} ${sign} ${body}${" ".repeat(fill)}\x1b[0m`);
|
|
141
141
|
}
|
|
142
142
|
else {
|
|
143
143
|
const body = truncateStyled(v.kind === "\\" ? v.body : highlightCodeLine(v.body), bodyMax);
|
|
144
|
-
pendingDiffOutput.push(`\x1b[90m${
|
|
144
|
+
pendingDiffOutput.push(`\x1b[90m${numStr} ${body}\x1b[0m`);
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
return { added, removed };
|
|
@@ -629,7 +629,7 @@ function globMatch(name, pattern) {
|
|
|
629
629
|
.replace(/\?/g, ".");
|
|
630
630
|
return new RegExp(`^${regex}$`, "i").test(name);
|
|
631
631
|
}
|
|
632
|
-
function walkFiles(root, current, rel, parts, out) {
|
|
632
|
+
function walkFiles(root, current, rel, parts, out, depthLeft) {
|
|
633
633
|
let entries;
|
|
634
634
|
try {
|
|
635
635
|
entries = fs.readdirSync(current, { withFileTypes: true });
|
|
@@ -643,8 +643,10 @@ function walkFiles(root, current, rel, parts, out) {
|
|
|
643
643
|
if (entry.isDirectory()) {
|
|
644
644
|
if (ignoredDirs.has(name))
|
|
645
645
|
continue;
|
|
646
|
+
if (depthLeft <= 0)
|
|
647
|
+
continue;
|
|
646
648
|
rel.push(name);
|
|
647
|
-
walkFiles(root, path.join(current, name), rel, parts, out);
|
|
649
|
+
walkFiles(root, path.join(current, name), rel, parts, out, depthLeft - 1);
|
|
648
650
|
rel.pop();
|
|
649
651
|
}
|
|
650
652
|
else if (entry.isFile()) {
|
|
@@ -661,13 +663,13 @@ function walkFiles(root, current, rel, parts, out) {
|
|
|
661
663
|
}
|
|
662
664
|
}
|
|
663
665
|
}
|
|
664
|
-
function rglobPruned(base, pattern) {
|
|
666
|
+
function rglobPruned(base, pattern, depth = 12) {
|
|
665
667
|
const norm = pattern.replace(/\\/g, "/");
|
|
666
668
|
const parts = norm.split("/").filter((p) => p !== "" && p !== ".");
|
|
667
669
|
const hasDotDot = parts.includes("..");
|
|
668
670
|
if (hasDotDot) {
|
|
669
671
|
const out = [];
|
|
670
|
-
const walk = (dir) => {
|
|
672
|
+
const walk = (dir, depthLeft) => {
|
|
671
673
|
let entries;
|
|
672
674
|
try {
|
|
673
675
|
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
@@ -678,8 +680,8 @@ function rglobPruned(base, pattern) {
|
|
|
678
680
|
for (const e of entries) {
|
|
679
681
|
const full = path.join(dir, e.name);
|
|
680
682
|
if (e.isDirectory()) {
|
|
681
|
-
if (!ignoredDirs.has(e.name))
|
|
682
|
-
walk(full);
|
|
683
|
+
if (!ignoredDirs.has(e.name) && depthLeft > 0)
|
|
684
|
+
walk(full, depthLeft - 1);
|
|
683
685
|
}
|
|
684
686
|
else if (e.isFile()) {
|
|
685
687
|
out.push([full, fs.statSync(full).size]);
|
|
@@ -690,7 +692,7 @@ function rglobPruned(base, pattern) {
|
|
|
690
692
|
out.push([base, fs.statSync(base).size]);
|
|
691
693
|
}
|
|
692
694
|
else {
|
|
693
|
-
walk(base);
|
|
695
|
+
walk(base, depth);
|
|
694
696
|
}
|
|
695
697
|
return out;
|
|
696
698
|
}
|
|
@@ -702,17 +704,18 @@ function rglobPruned(base, pattern) {
|
|
|
702
704
|
if (!parts.length)
|
|
703
705
|
return [];
|
|
704
706
|
const out = [];
|
|
705
|
-
walkFiles(base, base, [], ["**", ...parts], out);
|
|
707
|
+
walkFiles(base, base, [], ["**", ...parts], out, depth);
|
|
706
708
|
return out;
|
|
707
709
|
}
|
|
708
|
-
export function toolGlob(pattern, pathName = ".", limit = 200) {
|
|
710
|
+
export function toolGlob(pattern, pathName = ".", limit = 200, depth = 12) {
|
|
709
711
|
const base = sanitizePath(pathName) || ".";
|
|
710
712
|
if (!fs.existsSync(base))
|
|
711
713
|
return `Error: path not found: ${pathName}`;
|
|
712
714
|
const lim = typeof limit === "number" ? limit : parseInt(String(limit), 10) || 200;
|
|
715
|
+
const dep = Math.max(0, typeof depth === "number" ? depth : parseInt(String(depth), 10) || 12);
|
|
713
716
|
let matches;
|
|
714
717
|
try {
|
|
715
|
-
matches = rglobPruned(base, pattern);
|
|
718
|
+
matches = rglobPruned(base, pattern, dep);
|
|
716
719
|
}
|
|
717
720
|
catch {
|
|
718
721
|
return `Error: path not found: ${pathName}`;
|
|
@@ -891,6 +894,10 @@ export const RESPONSES_TOOLS = [
|
|
|
891
894
|
type: "integer",
|
|
892
895
|
description: "Max number of matches to return (default 200)",
|
|
893
896
|
},
|
|
897
|
+
depth: {
|
|
898
|
+
type: "integer",
|
|
899
|
+
description: "Max directory depth to descend (default 12)",
|
|
900
|
+
},
|
|
894
901
|
},
|
|
895
902
|
required: ["pattern"],
|
|
896
903
|
},
|