@wrongstack/tools 0.82.6 → 0.84.1
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/bash.js +13 -3
- package/dist/bash.js.map +1 -1
- package/dist/builtin.js +44 -44
- package/dist/builtin.js.map +1 -1
- package/dist/exec.js +3 -3
- package/dist/exec.js.map +1 -1
- package/dist/fetch.js +18 -28
- package/dist/fetch.js.map +1 -1
- package/dist/index.js +44 -44
- package/dist/index.js.map +1 -1
- package/dist/pack.js +44 -44
- package/dist/pack.js.map +1 -1
- package/dist/search.js +4 -0
- package/dist/search.js.map +1 -1
- package/package.json +2 -2
package/dist/pack.js
CHANGED
|
@@ -702,7 +702,7 @@ function getProcessRegistry() {
|
|
|
702
702
|
|
|
703
703
|
// src/bash.ts
|
|
704
704
|
var MAX_OUTPUT = 32768;
|
|
705
|
-
var
|
|
705
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
706
706
|
var STREAM_FLUSH_INTERVAL_MS = 200;
|
|
707
707
|
var STREAM_FLUSH_BYTES = 4 * 1024;
|
|
708
708
|
var bashTool = {
|
|
@@ -765,9 +765,19 @@ var bashTool = {
|
|
|
765
765
|
};
|
|
766
766
|
return;
|
|
767
767
|
}
|
|
768
|
-
const timeoutMs = Math.max(1, Math.min(input.timeout_ms ??
|
|
768
|
+
const timeoutMs = Math.max(1, Math.min(input.timeout_ms ?? DEFAULT_TIMEOUT_MS, 6e5));
|
|
769
769
|
const isWin = os.platform() === "win32";
|
|
770
|
-
const shell =
|
|
770
|
+
const shell = (() => {
|
|
771
|
+
const explicit = process.env[isWin ? "WRONGSTACK_COMSPEC" : "WRONGSTACK_SHELL"];
|
|
772
|
+
if (explicit) return explicit;
|
|
773
|
+
if (isWin) return process.env["COMSPEC"] ?? "cmd.exe";
|
|
774
|
+
const fromEnv = process.env["SHELL"];
|
|
775
|
+
if (fromEnv) {
|
|
776
|
+
const name = fromEnv.split("/").pop() ?? "";
|
|
777
|
+
if (["bash", "zsh", "sh", "dash", "fish"].includes(name)) return fromEnv;
|
|
778
|
+
}
|
|
779
|
+
return "/bin/bash";
|
|
780
|
+
})();
|
|
771
781
|
const args = isWin ? ["/c", input.command] : ["-c", input.command];
|
|
772
782
|
const env = buildChildEnv(ctx.session?.id);
|
|
773
783
|
const detached = isWin ? !!input.background : true;
|
|
@@ -3717,7 +3727,7 @@ var ALLOWED_COMMANDS = {
|
|
|
3717
3727
|
};
|
|
3718
3728
|
var MAX_ARGS = 20;
|
|
3719
3729
|
var MAX_OUTPUT2 = 2e5;
|
|
3720
|
-
var
|
|
3730
|
+
var DEFAULT_TIMEOUT_MS2 = 3e4;
|
|
3721
3731
|
var BLOCKED_ARG_PATTERNS = {
|
|
3722
3732
|
// python -c/--command executes arbitrary code; python -m runs modules
|
|
3723
3733
|
python: [/-c$/, /^--command$/, /^-m$/, /^--module$/],
|
|
@@ -3780,7 +3790,7 @@ var execTool = {
|
|
|
3780
3790
|
permission: "confirm",
|
|
3781
3791
|
mutating: true,
|
|
3782
3792
|
riskTier: "standard",
|
|
3783
|
-
timeoutMs:
|
|
3793
|
+
timeoutMs: DEFAULT_TIMEOUT_MS2,
|
|
3784
3794
|
capabilities: ["shell.restricted"],
|
|
3785
3795
|
inputSchema: {
|
|
3786
3796
|
type: "object",
|
|
@@ -3841,7 +3851,7 @@ var execTool = {
|
|
|
3841
3851
|
};
|
|
3842
3852
|
}
|
|
3843
3853
|
const args = (input.args ?? []).slice(0, MAX_ARGS);
|
|
3844
|
-
const timeout = Math.max(1, Math.min(input.timeout ??
|
|
3854
|
+
const timeout = Math.max(1, Math.min(input.timeout ?? DEFAULT_TIMEOUT_MS2, DEFAULT_TIMEOUT_MS2));
|
|
3845
3855
|
const argError = validateArgs(cmd, args);
|
|
3846
3856
|
if (argError) {
|
|
3847
3857
|
return {
|
|
@@ -3934,8 +3944,21 @@ function runCommand(cmd, args, cwd, timeout, signal, sessionId) {
|
|
|
3934
3944
|
});
|
|
3935
3945
|
}
|
|
3936
3946
|
var MAX_BYTES = 131072;
|
|
3937
|
-
var
|
|
3947
|
+
var TIMEOUT_MS = 2e4;
|
|
3938
3948
|
var ALLOW_PRIVATE = process.env["WRONGSTACK_FETCH_ALLOW_PRIVATE"] === "1";
|
|
3949
|
+
function combineSignals(signals) {
|
|
3950
|
+
const anyFn = AbortSignal.any;
|
|
3951
|
+
if (typeof anyFn === "function") return anyFn(signals);
|
|
3952
|
+
const ctrl = new AbortController();
|
|
3953
|
+
for (const sig of signals) {
|
|
3954
|
+
if (sig.aborted) {
|
|
3955
|
+
ctrl.abort(sig.reason);
|
|
3956
|
+
return ctrl.signal;
|
|
3957
|
+
}
|
|
3958
|
+
sig.addEventListener("abort", () => ctrl.abort(sig.reason), { once: true });
|
|
3959
|
+
}
|
|
3960
|
+
return ctrl.signal;
|
|
3961
|
+
}
|
|
3939
3962
|
function guardedLookup(hostname, options, callback) {
|
|
3940
3963
|
dns.lookup(hostname, { all: true }).then((records) => {
|
|
3941
3964
|
const family = options?.family;
|
|
@@ -3978,6 +4001,10 @@ function getPinnedDispatcher() {
|
|
|
3978
4001
|
}
|
|
3979
4002
|
return pinnedAgent;
|
|
3980
4003
|
}
|
|
4004
|
+
process.on("beforeExit", () => {
|
|
4005
|
+
pinnedAgent?.destroy();
|
|
4006
|
+
pinnedAgent = void 0;
|
|
4007
|
+
});
|
|
3981
4008
|
async function guardedFetch(url, maxRedirects, signal, headers = {
|
|
3982
4009
|
"user-agent": "WrongStack/1.0 (+https://wrongstack.com)",
|
|
3983
4010
|
accept: "text/html,application/json;q=0.9,text/plain;q=0.8,*/*;q=0.1"
|
|
@@ -4027,7 +4054,7 @@ var fetchTool = {
|
|
|
4027
4054
|
// matching that pattern on any other tool that happens to have a `url`
|
|
4028
4055
|
// input field.
|
|
4029
4056
|
subjectKey: "url",
|
|
4030
|
-
timeoutMs:
|
|
4057
|
+
timeoutMs: TIMEOUT_MS,
|
|
4031
4058
|
maxOutputBytes: MAX_BYTES,
|
|
4032
4059
|
inputSchema: {
|
|
4033
4060
|
type: "object",
|
|
@@ -4066,8 +4093,8 @@ var fetchTool = {
|
|
|
4066
4093
|
await assertNotPrivate(u.hostname);
|
|
4067
4094
|
yield { type: "log", text: `GET ${input.url}` };
|
|
4068
4095
|
const ctrl = new AbortController();
|
|
4069
|
-
const timer = setTimeout(() => ctrl.abort(new Error("fetch timeout")),
|
|
4070
|
-
const combined = combineSignals(opts.signal, ctrl.signal);
|
|
4096
|
+
const timer = setTimeout(() => ctrl.abort(new Error("fetch timeout")), TIMEOUT_MS);
|
|
4097
|
+
const combined = combineSignals([opts.signal, ctrl.signal]);
|
|
4071
4098
|
try {
|
|
4072
4099
|
const res = await guardedFetch(input.url, 5, combined);
|
|
4073
4100
|
const ct = res.headers.get("content-type") ?? "application/octet-stream";
|
|
@@ -4215,33 +4242,6 @@ function expandIPv6(addr) {
|
|
|
4215
4242
|
if (fill < 0) return null;
|
|
4216
4243
|
return [...head, ...new Array(fill).fill(0), ...tail];
|
|
4217
4244
|
}
|
|
4218
|
-
function combineSignals(...sigs) {
|
|
4219
|
-
const anyFn = AbortSignal.any;
|
|
4220
|
-
if (typeof anyFn === "function") {
|
|
4221
|
-
return anyFn(sigs);
|
|
4222
|
-
}
|
|
4223
|
-
const ctrl = new AbortController();
|
|
4224
|
-
const cleanups = [];
|
|
4225
|
-
const detach = () => {
|
|
4226
|
-
for (const fn of cleanups) fn();
|
|
4227
|
-
cleanups.length = 0;
|
|
4228
|
-
};
|
|
4229
|
-
for (const s of sigs) {
|
|
4230
|
-
if (s.aborted) {
|
|
4231
|
-
detach();
|
|
4232
|
-
ctrl.abort(s.reason);
|
|
4233
|
-
return ctrl.signal;
|
|
4234
|
-
}
|
|
4235
|
-
const onAbort = () => {
|
|
4236
|
-
detach();
|
|
4237
|
-
ctrl.abort(s.reason);
|
|
4238
|
-
};
|
|
4239
|
-
s.addEventListener("abort", onAbort, { once: true });
|
|
4240
|
-
cleanups.push(() => s.removeEventListener("abort", onAbort));
|
|
4241
|
-
}
|
|
4242
|
-
ctrl.signal.addEventListener("abort", detach, { once: true });
|
|
4243
|
-
return ctrl.signal;
|
|
4244
|
-
}
|
|
4245
4245
|
function prettyJson(s) {
|
|
4246
4246
|
try {
|
|
4247
4247
|
return JSON.stringify(JSON.parse(s), null, 2);
|
|
@@ -4377,7 +4377,7 @@ async function detectFixer(cwd) {
|
|
|
4377
4377
|
}
|
|
4378
4378
|
}
|
|
4379
4379
|
}
|
|
4380
|
-
var
|
|
4380
|
+
var TIMEOUT_MS2 = 3e4;
|
|
4381
4381
|
var MAX_OUTPUT3 = 1e5;
|
|
4382
4382
|
var gitTool = {
|
|
4383
4383
|
name: "git",
|
|
@@ -4390,7 +4390,7 @@ var gitTool = {
|
|
|
4390
4390
|
// and `MUTATING_SUBCOMMANDS` is consulted at runtime for per-call checks.
|
|
4391
4391
|
mutating: true,
|
|
4392
4392
|
capabilities: ["fs.write", "shell.restricted"],
|
|
4393
|
-
timeoutMs:
|
|
4393
|
+
timeoutMs: TIMEOUT_MS2,
|
|
4394
4394
|
inputSchema: {
|
|
4395
4395
|
type: "object",
|
|
4396
4396
|
properties: {
|
|
@@ -6409,7 +6409,7 @@ function expectDefined12(value) {
|
|
|
6409
6409
|
}
|
|
6410
6410
|
var DEFAULT_NUM = 10;
|
|
6411
6411
|
var MAX_RESULTS = 50;
|
|
6412
|
-
var
|
|
6412
|
+
var TIMEOUT_MS3 = 15e3;
|
|
6413
6413
|
var searchTool = {
|
|
6414
6414
|
name: "search",
|
|
6415
6415
|
category: "Search",
|
|
@@ -6418,7 +6418,7 @@ var searchTool = {
|
|
|
6418
6418
|
permission: "confirm",
|
|
6419
6419
|
mutating: false,
|
|
6420
6420
|
capabilities: ["net.outbound"],
|
|
6421
|
-
timeoutMs:
|
|
6421
|
+
timeoutMs: TIMEOUT_MS3,
|
|
6422
6422
|
inputSchema: {
|
|
6423
6423
|
type: "object",
|
|
6424
6424
|
properties: {
|
|
@@ -6481,7 +6481,7 @@ var searchTool = {
|
|
|
6481
6481
|
async function duckduckgoSearch(query2, num, signal) {
|
|
6482
6482
|
const encoded = encodeURIComponent(query2);
|
|
6483
6483
|
const url = `https://lite.duckduckgo.com/lite/?q=${encoded}&kd=-1&kl=wt-wt`;
|
|
6484
|
-
const results = await fetchWithTimeout(url, signal,
|
|
6484
|
+
const results = await fetchWithTimeout(url, signal, TIMEOUT_MS3).then((r) => r.text()).then((html) => parseDuckDuckGo(html, num)).catch(() => [{ title: "Search unavailable", url: "", snippet: "Could not reach DuckDuckGo" }]);
|
|
6485
6485
|
return {
|
|
6486
6486
|
query: query2,
|
|
6487
6487
|
results,
|
|
@@ -6522,7 +6522,7 @@ function parseDuckDuckGo(html, num) {
|
|
|
6522
6522
|
async function googleSearch(query2, num, signal) {
|
|
6523
6523
|
const encoded = encodeURIComponent(query2);
|
|
6524
6524
|
const url = `https://www.google.com/search?q=${encoded}&hl=en`;
|
|
6525
|
-
const html = await fetchWithTimeout(url, signal,
|
|
6525
|
+
const html = await fetchWithTimeout(url, signal, TIMEOUT_MS3).then((r) => r.text()).catch(() => "");
|
|
6526
6526
|
const results = parseGoogleResults(html, num);
|
|
6527
6527
|
return {
|
|
6528
6528
|
query: query2,
|
|
@@ -6560,7 +6560,7 @@ function parseGoogleResults(html, num) {
|
|
|
6560
6560
|
async function bingSearch(query2, num, signal) {
|
|
6561
6561
|
const encoded = encodeURIComponent(query2);
|
|
6562
6562
|
const url = `https://www.bing.com/search?q=${encoded}`;
|
|
6563
|
-
const html = await fetchWithTimeout(url, signal,
|
|
6563
|
+
const html = await fetchWithTimeout(url, signal, TIMEOUT_MS3).then((r) => r.text()).catch(() => "");
|
|
6564
6564
|
const results = parseBingResults(html, num);
|
|
6565
6565
|
return {
|
|
6566
6566
|
query: query2,
|