@wrongstack/tools 0.109.1 → 0.141.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/dist/pack.js CHANGED
@@ -1,6 +1,6 @@
1
+ import { spawn, execFileSync, spawnSync } from 'node:child_process';
1
2
  import * as Core from '@wrongstack/core';
2
3
  import { buildChildEnv, expectDefined, detectNewlineStyle, normalizeToLf, toStyle, atomicWrite, unifiedDiff, compileGlob, loadPlan, emptyPlan, clearPlan, savePlan, getPlanTemplate, addPlanItem, deriveTodosFromPlanItem, removePlanItem, setPlanItemStatus, formatPlan, loadTasks, emptyTaskFile, saveTasks, computeTaskItemProgress, formatTaskList, resolveWstackPaths } from '@wrongstack/core';
3
- import { spawn, execFileSync, spawnSync } from 'node:child_process';
4
4
  import * as fs12 from 'node:fs/promises';
5
5
  import * as path from 'node:path';
6
6
  import { resolve, sep, dirname } from 'node:path';
@@ -65,7 +65,7 @@ async function* spawnStream(opts) {
65
65
  waiter = resolve7;
66
66
  });
67
67
  }
68
- const chunk = expectDefined(queue.shift());
68
+ const chunk = queue.shift();
69
69
  if (chunk.kind === "close") {
70
70
  if (!spawnFailed) exitCode = chunk.code ?? 0;
71
71
  break;
@@ -181,9 +181,9 @@ function collapseConsecutiveDuplicates(text, minRun = REPEAT_RUN_THRESHOLD) {
181
181
  while (j < lines.length && lines[j] === lines[i]) j++;
182
182
  const run = j - i;
183
183
  if (run >= minRun) {
184
- out.push(expectDefined(lines[i]), `\u2026 \u27E8repeated ${run}\xD7\u27E9`);
184
+ out.push(lines[i], `\u2026 \u27E8repeated ${run}\xD7\u27E9`);
185
185
  } else {
186
- for (let k = i; k < j; k++) out.push(expectDefined(lines[k]));
186
+ for (let k = i; k < j; k++) out.push(lines[k]);
187
187
  }
188
188
  i = j;
189
189
  }
@@ -838,44 +838,46 @@ var bashTool = {
838
838
  let pending = "";
839
839
  let timedOut = false;
840
840
  const timers = [];
841
- const timer = setTimeout(() => {
842
- timedOut = true;
841
+ function killWithTimeout(child2, timeoutMs2) {
843
842
  if (isWin) {
844
843
  try {
845
- child.kill();
844
+ child2.kill();
846
845
  } catch {
847
846
  }
848
- } else {
847
+ return;
848
+ }
849
+ try {
850
+ if (typeof child2.pid === "number") {
851
+ try {
852
+ process.kill(-child2.pid, "SIGTERM");
853
+ } catch {
854
+ child2.kill("SIGTERM");
855
+ }
856
+ } else {
857
+ child2.kill("SIGTERM");
858
+ }
859
+ } catch {
860
+ }
861
+ const killTimer = setTimeout(() => {
849
862
  try {
850
- if (typeof child.pid === "number") {
863
+ if (typeof child2.pid === "number") {
851
864
  try {
852
- process.kill(-child.pid, "SIGTERM");
865
+ process.kill(-child2.pid, "SIGKILL");
853
866
  } catch {
854
- child.kill("SIGTERM");
867
+ child2.kill("SIGKILL");
855
868
  }
856
869
  } else {
857
- child.kill("SIGTERM");
870
+ child2.kill("SIGKILL");
858
871
  }
859
- const killTimer = setTimeout(() => {
860
- try {
861
- if (typeof child.pid === "number") {
862
- try {
863
- process.kill(-child.pid, "SIGKILL");
864
- } catch {
865
- child.kill("SIGKILL");
866
- }
867
- } else {
868
- child.kill("SIGKILL");
869
- }
870
- } catch {
871
- } finally {
872
- killTimer.unref?.();
873
- }
874
- }, 2e3);
875
- timers.push(killTimer);
876
872
  } catch {
877
873
  }
878
- }
874
+ }, timeoutMs2);
875
+ timers.push(killTimer);
876
+ killTimer.unref?.();
877
+ }
878
+ const timer = setTimeout(() => {
879
+ timedOut = true;
880
+ killWithTimeout(child, 2e3);
879
881
  }, timeoutMs);
880
882
  timers.push(timer);
881
883
  timer.unref?.();
@@ -3886,19 +3888,12 @@ function runCommand(cmd, args, cwd, timeout, signal, sessionId) {
3886
3888
  var MAX_BYTES = 131072;
3887
3889
  var TIMEOUT_MS = 2e4;
3888
3890
  var ALLOW_PRIVATE = process.env["WRONGSTACK_FETCH_ALLOW_PRIVATE"] === "1";
3889
- function combineSignals(signals) {
3890
- const anyFn = AbortSignal.any;
3891
- if (typeof anyFn === "function") return anyFn(signals);
3892
- const ctrl = new AbortController();
3893
- for (const sig of signals) {
3894
- if (sig.aborted) {
3895
- ctrl.abort(sig.reason);
3896
- return ctrl.signal;
3897
- }
3898
- sig.addEventListener("abort", () => ctrl.abort(sig.reason), { once: true });
3899
- }
3900
- return ctrl.signal;
3891
+ if (ALLOW_PRIVATE && !process.env["CI"]) {
3892
+ console.warn(
3893
+ "[WrongStack] WARNING: WRONGSTACK_FETCH_ALLOW_PRIVATE=1 is active \u2014\n fetch tool can now access private IPs (10.x, 192.168.x, 169.254.x),\n cloud metadata endpoints, and plaintext HTTP. Use only on isolated networks."
3894
+ );
3901
3895
  }
3896
+ var combineSignals = (signals) => AbortSignal.any(signals);
3902
3897
  function guardedLookup(hostname, options, callback) {
3903
3898
  dns.lookup(hostname, { all: true }).then((records) => {
3904
3899
  const family = options?.family;
@@ -3941,10 +3936,14 @@ function getPinnedDispatcher() {
3941
3936
  }
3942
3937
  return pinnedAgent;
3943
3938
  }
3944
- process.on("beforeExit", () => {
3945
- pinnedAgent?.destroy();
3946
- pinnedAgent = void 0;
3947
- });
3939
+ var _beforeExitRegistered = false;
3940
+ if (!_beforeExitRegistered) {
3941
+ _beforeExitRegistered = true;
3942
+ process.on("beforeExit", () => {
3943
+ pinnedAgent?.destroy();
3944
+ pinnedAgent = void 0;
3945
+ });
3946
+ }
3948
3947
  async function guardedFetch(url, maxRedirects, signal, headers = {
3949
3948
  "user-agent": "WrongStack/1.0 (+https://wrongstack.com)",
3950
3949
  accept: "text/html,application/json;q=0.9,text/plain;q=0.8,*/*;q=0.1"
@@ -6108,7 +6107,11 @@ function checkRg() {
6108
6107
  }
6109
6108
  function spawnRgFind(pattern, base) {
6110
6109
  const args = ["--files", "--glob", pattern, base];
6111
- const child = spawn("rg", args, { env: buildChildEnv(), stdio: ["ignore", "pipe", "pipe"] });
6110
+ const child = spawn("rg", args, {
6111
+ signal: AbortSignal.timeout(3e4),
6112
+ env: buildChildEnv(),
6113
+ stdio: ["ignore", "pipe", "pipe"]
6114
+ });
6112
6115
  let buf = "";
6113
6116
  child.stdout?.on("data", (chunk) => {
6114
6117
  buf += chunk.toString();
@@ -6625,7 +6628,7 @@ var taskTool = {
6625
6628
  return { ok: false, message: "Task storage path not configured.", count: 0, completed: 0, inProgress: 0 };
6626
6629
  }
6627
6630
  const sessionId = ctx.session?.id ?? "unknown";
6628
- let file = await loadTasks(taskPath) ?? emptyTaskFile(sessionId);
6631
+ const file = await loadTasks(taskPath) ?? emptyTaskFile(sessionId);
6629
6632
  switch (input.action) {
6630
6633
  case "show":
6631
6634
  break;