@wrongstack/tools 0.310.1 → 0.313.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.
Files changed (135) hide show
  1. package/dist/_shell-pick.d.ts +5 -10
  2. package/dist/audit.js +10 -4055
  3. package/dist/bash.js +9 -2332
  4. package/dist/batch-tool-use.js +2 -187
  5. package/dist/browser/index.js +25 -1339
  6. package/dist/builtin.js +69 -33985
  7. package/dist/chunk-2CTB3UK5.js +197 -0
  8. package/dist/chunk-2ME7ZWDD.js +1272 -0
  9. package/dist/chunk-2TFQDEPU.js +113 -0
  10. package/dist/chunk-2ZCJNKFE.js +315 -0
  11. package/dist/chunk-3PVYQFRQ.js +472 -0
  12. package/dist/chunk-3QMQBO5Z.js +89 -0
  13. package/dist/chunk-42AKKX7O.js +385 -0
  14. package/dist/chunk-42SKEETB.js +113 -0
  15. package/dist/chunk-4BHUSMNL.js +104 -0
  16. package/dist/chunk-4I4LWFOO.js +431 -0
  17. package/dist/chunk-553IQUMO.js +478 -0
  18. package/dist/chunk-55KF77OK.js +1944 -0
  19. package/dist/chunk-6HLZK37X.js +359 -0
  20. package/dist/chunk-6RNIFLG4.js +305 -0
  21. package/dist/chunk-A6BRWIXN.js +317 -0
  22. package/dist/chunk-AHHDWNXC.js +200 -0
  23. package/dist/chunk-B2CIOKWP.js +899 -0
  24. package/dist/chunk-BTSFTGIL.js +7 -0
  25. package/dist/chunk-D33S4RQG.js +222 -0
  26. package/dist/chunk-DIJKHSUO.js +134 -0
  27. package/dist/chunk-DPL47QGS.js +3515 -0
  28. package/dist/chunk-EMRGN4KM.js +170 -0
  29. package/dist/chunk-FGOABE4Z.js +955 -0
  30. package/dist/chunk-FW65TP4G.js +520 -0
  31. package/dist/chunk-GOIZNNOA.js +221 -0
  32. package/dist/chunk-H5MJUAA6.js +295 -0
  33. package/dist/chunk-H5OHH6F4.js +223 -0
  34. package/dist/chunk-HC5RM4WY.js +199 -0
  35. package/dist/chunk-HEQFMLZ7.js +190 -0
  36. package/dist/chunk-HFXSNKCV.js +196 -0
  37. package/dist/chunk-HXSBQ2SE.js +1723 -0
  38. package/dist/chunk-ILESNGNM.js +163 -0
  39. package/dist/chunk-INF5CGAO.js +137 -0
  40. package/dist/chunk-IWDFZ6XR.js +337 -0
  41. package/dist/chunk-IXMNTNW5.js +238 -0
  42. package/dist/chunk-J4SRJKBW.js +428 -0
  43. package/dist/chunk-J5SKD6LN.js +235 -0
  44. package/dist/chunk-JRJJX3L5.js +424 -0
  45. package/dist/chunk-KXNDHMUB.js +366 -0
  46. package/dist/chunk-LIJQMYYX.js +59 -0
  47. package/dist/chunk-MAN26PZ5.js +260 -0
  48. package/dist/chunk-MKRQMLZA.js +474 -0
  49. package/dist/chunk-NBDZMMG2.js +169 -0
  50. package/dist/chunk-NHA6BEIH.js +101 -0
  51. package/dist/chunk-OA6YJIWL.js +4412 -0
  52. package/dist/chunk-OZC255IC.js +2830 -0
  53. package/dist/chunk-PUR6WU2B.js +154 -0
  54. package/dist/chunk-Q5JPPCZC.js +12 -0
  55. package/dist/chunk-QBV725YG.js +128 -0
  56. package/dist/chunk-QHVW4AAM.js +892 -0
  57. package/dist/chunk-QNJ7AQ4B.js +1000 -0
  58. package/dist/chunk-RGISBZBD.js +231 -0
  59. package/dist/chunk-RJZQWEMS.js +84 -0
  60. package/dist/chunk-RP2ZA47V.js +15 -0
  61. package/dist/chunk-RXISBFR5.js +315 -0
  62. package/dist/chunk-S5CCLZL3.js +99 -0
  63. package/dist/chunk-TVTCSBJF.js +122 -0
  64. package/dist/chunk-U4D5S3VQ.js +21 -0
  65. package/dist/chunk-U4VAATKP.js +193 -0
  66. package/dist/chunk-UKU2ZX4C.js +203 -0
  67. package/dist/chunk-UNSKG6DC.js +159 -0
  68. package/dist/chunk-URFKEIHM.js +1091 -0
  69. package/dist/chunk-UTV7YAW7.js +178 -0
  70. package/dist/chunk-V43EQ6VR.js +68 -0
  71. package/dist/chunk-VB3MJGCV.js +610 -0
  72. package/dist/chunk-WHIIIREL.js +223 -0
  73. package/dist/chunk-XMIFYKUT.js +1371 -0
  74. package/dist/chunk-YF2RSV34.js +54 -0
  75. package/dist/chunk-Z6DAKQ3U.js +1 -0
  76. package/dist/chunk-ZIGAZFWE.js +522 -0
  77. package/dist/circuit-breaker.js +3 -191
  78. package/dist/codebase-index/index.js +84 -13688
  79. package/dist/codebase-index/parser-worker-script.js +8 -3995
  80. package/dist/codebase-index/project-server.js +60 -8548
  81. package/dist/codebase-index/worker.js +20 -8416
  82. package/dist/design.js +2 -299
  83. package/dist/diff.js +4 -256
  84. package/dist/document.js +4 -222
  85. package/dist/e2e.js +5 -476
  86. package/dist/edit.js +14 -10200
  87. package/dist/exec.js +16 -3131
  88. package/dist/fetch.js +8 -398
  89. package/dist/format.js +10 -3750
  90. package/dist/generic-parser-VUXDIAOZ.js +13 -0
  91. package/dist/git.js +4 -380
  92. package/dist/glob.js +6 -280
  93. package/dist/go-parser-6CA77WZ4.js +469 -0
  94. package/dist/grep.js +7 -604
  95. package/dist/index.js +318 -35423
  96. package/dist/install.js +10 -4091
  97. package/dist/json-parser-7YMDJSBJ.js +213 -0
  98. package/dist/json.js +4 -665
  99. package/dist/kanban.js +3 -2096
  100. package/dist/languages/index.js +23 -4664
  101. package/dist/legacy-bridge-7UKZT46G.js +18 -0
  102. package/dist/lint.js +10 -3706
  103. package/dist/logs.js +4 -287
  104. package/dist/memory.js +6 -215
  105. package/dist/mode.js +3 -99
  106. package/dist/outdated.js +4 -5170
  107. package/dist/pack.js +65 -33933
  108. package/dist/parser-dispatch-VPOFDO2U.js +14 -0
  109. package/dist/patch.js +13 -9935
  110. package/dist/plan.js +5 -3286
  111. package/dist/process-registry.js +8 -651
  112. package/dist/ps-slash.js +12 -1439
  113. package/dist/py-parser-GPM5VYRG.js +16 -0
  114. package/dist/read.js +13 -9816
  115. package/dist/replace.js +15 -10014
  116. package/dist/rs-parser-WVQ4KYCX.js +81 -0
  117. package/dist/scaffold.js +4 -253
  118. package/dist/search.js +5 -585
  119. package/dist/session-kanban.js +30 -972
  120. package/dist/skill.js +2 -215
  121. package/dist/task.js +5 -3410
  122. package/dist/test.js +10 -3773
  123. package/dist/todo.js +4 -2891
  124. package/dist/tool-help.js +3 -123
  125. package/dist/tool-search.js +3 -79
  126. package/dist/tool-tier.js +68 -34020
  127. package/dist/tool-use.js +2 -93
  128. package/dist/tree-sitter-parser-YCILHGZD.js +17 -0
  129. package/dist/tree.js +4 -288
  130. package/dist/ts-parser-YH4ZMWMH.js +232 -0
  131. package/dist/typecheck.js +10 -3753
  132. package/dist/win32.js +6 -60
  133. package/dist/write.js +14 -9882
  134. package/dist/yaml-parser-GFAOKV53.js +157 -0
  135. package/package.json +5 -5
@@ -0,0 +1,1723 @@
1
+ import {
2
+ buildChildEnv
3
+ } from "./chunk-BTSFTGIL.js";
4
+ import {
5
+ getPersistentProcessRegistry
6
+ } from "./chunk-ZIGAZFWE.js";
7
+ import {
8
+ createOutputSpool,
9
+ spoolNote
10
+ } from "./chunk-2TFQDEPU.js";
11
+ import {
12
+ getProcessRegistry,
13
+ redactCommand
14
+ } from "./chunk-3PVYQFRQ.js";
15
+ import {
16
+ buildWin32CmdShimInvocation,
17
+ resolveWin32Command
18
+ } from "./chunk-V43EQ6VR.js";
19
+ import {
20
+ COMMAND_OUTPUT_MAX_BYTES,
21
+ normalizeCommandOutput,
22
+ safeResolveReal
23
+ } from "./chunk-D33S4RQG.js";
24
+
25
+ // src/exec.ts
26
+ import { spawn } from "node:child_process";
27
+ import {
28
+ emitProcessCompleted,
29
+ emitProcessOutput,
30
+ emitProcessStarted
31
+ } from "@wrongstack/core/observability";
32
+ import { toErrorMessage } from "@wrongstack/core/utils/error";
33
+
34
+ // src/_danger-detect.ts
35
+ var argHas = (args, value) => args.includes(value);
36
+ var argMatches = (args, re) => args.some((a) => re.test(a));
37
+ var hasShortFlags = (args, letters) => {
38
+ const seen = /* @__PURE__ */ new Set();
39
+ for (const a of args) {
40
+ if (!/^-[a-zA-Z]+$/.test(a)) continue;
41
+ for (const ch of a.slice(1)) seen.add(ch);
42
+ }
43
+ return letters.split("").every((l) => seen.has(l));
44
+ };
45
+ var RULES = [
46
+ // ----- rm / rmdir: recursive force delete (any path) -----
47
+ // Note: BLOCKED_ARG_PATTERNS already hard-denies root/home/glob paths,
48
+ // but `rm -rf ./build` is a normal dev workflow that the user might
49
+ // want to do intentionally. We downgrade it to 'destructive' so the
50
+ // confirm prompt can approve.
51
+ {
52
+ id: "rm-recursive",
53
+ level: "destructive",
54
+ test: (cmd, args) => (cmd === "rm" || cmd === "rmdir") && hasShortFlags(args, "rf"),
55
+ reason: "recursive force-delete"
56
+ },
57
+ // ----- Windows PowerShell Remove-Item: -Recurse -Force -----
58
+ {
59
+ id: "powershell-remove-item-recursive-force",
60
+ level: "destructive",
61
+ test: (cmd, args) => {
62
+ if (cmd !== "powershell" && cmd !== "pwsh") return false;
63
+ const hasRecurse = argMatches(args, /^-(?:R|Recurse|Recurse\s)/);
64
+ const hasForce = argHas(args, "-Force") || argHas(args, "-F");
65
+ if (argHas(args, "-WhatIf")) return false;
66
+ return hasRecurse && hasForce;
67
+ },
68
+ reason: "Remove-Item with -Recurse -Force"
69
+ },
70
+ // ----- Windows PowerShell Disk & Volume destruction -----
71
+ {
72
+ id: "powershell-disk-volume-destroy",
73
+ level: "destructive",
74
+ test: (cmd, args) => {
75
+ if (cmd !== "powershell" && cmd !== "pwsh") return false;
76
+ return args.some(
77
+ (a) => /^(?:Format-Volume|Clear-Disk|Initialize-Disk|Remove-Partition|Clear-Volume)(?:\s|$)/i.test(a)
78
+ );
79
+ },
80
+ reason: "PowerShell disk/volume partition destruction"
81
+ },
82
+ // ----- Windows PowerShell System Restart / Shutdown -----
83
+ {
84
+ id: "powershell-stop-restart-computer",
85
+ level: "destructive",
86
+ test: (cmd, args) => {
87
+ if (cmd !== "powershell" && cmd !== "pwsh") return false;
88
+ return args.some((a) => /^(?:Stop-Computer|Restart-Computer)(?:\s|$)/i.test(a));
89
+ },
90
+ reason: "PowerShell system shutdown or restart"
91
+ },
92
+ // ----- Windows PowerShell ExecutionPolicy / Payload evasion -----
93
+ {
94
+ id: "powershell-execution-policy-bypass",
95
+ level: "caution",
96
+ test: (cmd, args) => {
97
+ if (cmd !== "powershell" && cmd !== "pwsh") return false;
98
+ return args.some(
99
+ (a) => /Set-ExecutionPolicy\s+(?:Bypass|Unrestricted)|-(?:EncodedCommand|enc)\b/i.test(a)
100
+ );
101
+ },
102
+ reason: "PowerShell execution policy bypass or encoded command"
103
+ },
104
+ // ----- find -exec / -ok / -execdir -----
105
+ {
106
+ id: "find-exec",
107
+ level: "destructive",
108
+ test: (cmd, args) => {
109
+ if (cmd !== "find") return false;
110
+ return args.some(
111
+ (a) => a === "-exec" || a === "-exec;" || a === "-ok" || a === "-ok;" || a === "-execdir" || a === "-execdir;" || a.startsWith("-exec=") || a.startsWith("-ok=") || a.startsWith("-execdir=")
112
+ );
113
+ },
114
+ reason: "find with -exec/-ok (executes arbitrary command on matches)"
115
+ },
116
+ // ----- git --exec= / --upload-pack= / --receive-pack= -----
117
+ // These run arbitrary commands via the git transport layer.
118
+ {
119
+ id: "git-exec",
120
+ level: "destructive",
121
+ test: (cmd, args) => cmd === "git" && args.some(
122
+ (a) => a.startsWith("--exec=") || a.startsWith("--upload-pack=") || a.startsWith("--receive-pack=") || a === "--exec" || a === "--upload-pack" || a === "--receive-pack"
123
+ ),
124
+ reason: "git with --exec/--upload-pack/--receive-pack (runs arbitrary code)"
125
+ },
126
+ // ----- Windows: format / diskpart / bcdedit -----
127
+ {
128
+ id: "win32-format",
129
+ level: "destructive",
130
+ test: (cmd) => cmd === "format" || cmd === "format.exe",
131
+ reason: "format (Windows disk format)"
132
+ },
133
+ {
134
+ id: "win32-diskpart",
135
+ level: "destructive",
136
+ test: (cmd) => cmd === "diskpart" || cmd === "diskpart.exe",
137
+ reason: "diskpart (Windows partition editor)"
138
+ },
139
+ {
140
+ id: "win32-bcdedit",
141
+ level: "destructive",
142
+ test: (cmd) => cmd === "bcdedit" || cmd === "bcdedit.exe",
143
+ reason: "bcdedit (Windows boot config editor)"
144
+ },
145
+ // ----- mkfs family -----
146
+ {
147
+ id: "mkfs",
148
+ level: "destructive",
149
+ test: (cmd) => /^mkfs(\.[a-z0-9]+)?$/.test(cmd) || cmd === "mkswap",
150
+ reason: "mkfs (filesystem creation \u2014 destroys existing data)"
151
+ },
152
+ // ----- dd writing to a block device -----
153
+ {
154
+ id: "dd-to-block-device",
155
+ level: "destructive",
156
+ test: (cmd, args) => {
157
+ if (cmd !== "dd") return false;
158
+ return args.some((a) => /of=\/dev\/(sd|hd|nvme|vd|mmcblk|xvd|loop|disk)/.test(a));
159
+ },
160
+ reason: "dd writing to a block device"
161
+ },
162
+ // ----- Secure-erase tools -----
163
+ {
164
+ id: "shred",
165
+ level: "destructive",
166
+ test: (cmd) => cmd === "shred" || cmd === "shred.exe",
167
+ reason: "shred (secure file delete)"
168
+ },
169
+ {
170
+ id: "wipefs",
171
+ level: "destructive",
172
+ test: (cmd) => cmd === "wipefs" || cmd === "wipefs.exe",
173
+ reason: "wipefs (signature wipe \u2014 destroys filesystem headers)"
174
+ },
175
+ {
176
+ id: "sdelete",
177
+ level: "destructive",
178
+ test: (cmd) => cmd === "sdelete" || cmd === "sdelete.exe",
179
+ reason: "sdelete (Sysinternals secure delete)"
180
+ },
181
+ // ----- VCS history rewrite (destructive) -----
182
+ // `git push --force` / `-f` rewrites remote history. `--force-with-lease`
183
+ // is the safer variant (checks remote hasn't moved) but still rewrites.
184
+ {
185
+ id: "git-push-force",
186
+ level: "destructive",
187
+ test: (cmd, args) => {
188
+ if (cmd !== "git") return false;
189
+ const pushIdx = args.indexOf("push");
190
+ if (pushIdx < 0) return false;
191
+ for (let i = pushIdx + 1; i < args.length; i++) {
192
+ const a = args[i];
193
+ if (a === "--force" || a === "-f" || a === "--force-with-lease") return true;
194
+ if (!a.startsWith("-") && !a.includes("=")) continue;
195
+ if (a.startsWith("--force")) return true;
196
+ }
197
+ return false;
198
+ },
199
+ reason: "git push with --force / -f (rewrites remote history)"
200
+ },
201
+ // ----- git reset --hard (destructive) -----
202
+ {
203
+ id: "git-reset-hard",
204
+ level: "destructive",
205
+ test: (cmd, args) => cmd === "git" && args.some((a) => a === "--hard" || a.startsWith("--hard=")),
206
+ reason: "git reset --hard (discards working tree + index)"
207
+ },
208
+ // ----- git clean -f / -fd (destructive) -----
209
+ {
210
+ id: "git-clean-force",
211
+ level: "destructive",
212
+ test: (cmd, args) => {
213
+ if (cmd !== "git") return false;
214
+ const cleanIdx = args.indexOf("clean");
215
+ if (cleanIdx < 0) return false;
216
+ return args.slice(cleanIdx + 1).some(
217
+ (a) => a === "-f" || a === "--force" || a.startsWith("-f") || a.startsWith("--force=")
218
+ );
219
+ },
220
+ reason: "git clean -f (deletes untracked files)"
221
+ },
222
+ // ----- package publish (destructive — public, irreversible) -----
223
+ {
224
+ id: "npm-publish",
225
+ level: "destructive",
226
+ test: (cmd, args) => {
227
+ if (!["npm", "pnpm", "yarn", "bun", "cargo"].includes(cmd)) return false;
228
+ return args.includes("publish") || cmd === "cargo" && args.includes("yank");
229
+ },
230
+ reason: "publishing to a public package registry (hard to reverse)"
231
+ },
232
+ // ----- k8s cluster-wide destructive ops (destructive) -----
233
+ {
234
+ id: "kubectl-delete-namespace",
235
+ level: "destructive",
236
+ test: (cmd, args) => {
237
+ if (cmd !== "kubectl") return false;
238
+ const delIdx = args.indexOf("delete");
239
+ if (delIdx < 0) return false;
240
+ const after = args.slice(delIdx + 1);
241
+ return after[0] === "namespace" || after[0] === "ns";
242
+ },
243
+ reason: "kubectl delete namespace (deletes all resources in the namespace)"
244
+ },
245
+ {
246
+ id: "kubectl-drain",
247
+ level: "destructive",
248
+ test: (cmd, args) => cmd === "kubectl" && args.includes("drain"),
249
+ reason: "kubectl drain (evicts pods, marks node unschedulable)"
250
+ },
251
+ // ----- inline code evaluation (caution — high false-positive) -----
252
+ // Common in scripts: `python -c "..."`, `node -e "..."`, `bash -c "..."`.
253
+ // We tag 'caution' rather than 'destructive' because these are used in
254
+ // many legitimate one-liners (e.g. `python -c "print(1)"`).
255
+ {
256
+ id: "inline-eval",
257
+ level: "caution",
258
+ test: (cmd, args) => {
259
+ if (![
260
+ "python",
261
+ "python3",
262
+ "python2",
263
+ "node",
264
+ "bash",
265
+ "sh",
266
+ "zsh",
267
+ "ruby",
268
+ "perl",
269
+ "lua"
270
+ ].includes(cmd)) {
271
+ return false;
272
+ }
273
+ return args.some(
274
+ (a) => a === "-c" || a === "-e" || a === "--eval" || a === "-eval" || a === "-E"
275
+ );
276
+ },
277
+ reason: "inline script evaluation (-c / -e / --eval)"
278
+ },
279
+ // ----- pipe-to-shell (destructive — download-and-run pattern) -----
280
+ // The classic `curl https://... | sh` download-and-run vector. Detected by
281
+ // looking for a known fetcher piped into a shell or expression evaluator.
282
+ // A shell command passed through `bash -c` / `pwsh -Command` arrives as one
283
+ // argv string, so scan the reconstructed argv text rather than individual
284
+ // tokens only.
285
+ {
286
+ id: "pipe-to-shell",
287
+ level: "destructive",
288
+ test: (cmd, args) => /\b(?:curl|wget|fetch|httpie|http|irm|iwr|Invoke-WebRequest|Invoke-RestMethod)\b[\s\S]{0,300}\|\s*(?:sudo\s+)?(?:sh|bash|zsh|fish|pwsh|powershell|iex|Invoke-Expression)\b/i.test(
289
+ [cmd, ...args].join(" ")
290
+ ),
291
+ reason: "network fetch piped to a shell (download-and-run pattern)"
292
+ },
293
+ // ----- privilege escalation (caution) -----
294
+ {
295
+ id: "sudo",
296
+ level: "caution",
297
+ test: (cmd) => cmd === "sudo" || cmd === "doas",
298
+ reason: "privilege escalation (sudo / doas)"
299
+ },
300
+ {
301
+ id: "runas",
302
+ level: "caution",
303
+ test: (cmd) => cmd === "runas" || cmd === "runas.exe",
304
+ reason: "Windows runas (run as different user)"
305
+ },
306
+ // ----- world-writable permissions (caution) -----
307
+ // `chmod 777` is rarely correct. `chmod -R 777` is almost always wrong.
308
+ // We only flag octal modes; symbolic modes like `chmod o+w` are
309
+ // left to the operator's discretion.
310
+ {
311
+ id: "chmod-world-writable",
312
+ level: "caution",
313
+ test: (cmd, args) => {
314
+ if (cmd !== "chmod") return false;
315
+ return args.some((a) => /^[0-7]{3,4}$/.test(a) && /7/.test(a));
316
+ },
317
+ reason: "chmod with world-writable octal mode (e.g. 777)"
318
+ },
319
+ // ----- network recon / offensive scanners (caution) -----
320
+ // These tools are purpose-built for network reconnaissance and offensive
321
+ // security. They have legitimate uses in dev (security testing, infra
322
+ // debugging) but their presence in an agent's command stream is worth a
323
+ // caution banner so the user can notice an unexpected scan.
324
+ {
325
+ id: "network-scanner",
326
+ level: "caution",
327
+ test: (cmd) => cmd === "nmap" || cmd === "masscan" || cmd === "zmap" || cmd === "nuclei" || cmd === "hping3" || cmd === "naabu" || cmd === "katana" || cmd === "amass" || cmd === "subfinder" || cmd === "httpx" || cmd === "rustscan" || cmd === "zgrab",
328
+ reason: "network scanner / offensive reconnaissance tool"
329
+ },
330
+ // ----- process termination (caution) -----
331
+ // kill/killall/pkill terminate processes. The exec kill guard
332
+ // (exec-kill-guard.ts) hard-blocks attempts on protected WrongStack
333
+ // processes; this rule adds a caution banner for generic process
334
+ // termination so the user sees a warning even for non-protected targets.
335
+ {
336
+ id: "process-kill",
337
+ level: "caution",
338
+ test: (cmd) => cmd === "kill" || cmd === "killall" || cmd === "pkill",
339
+ reason: "process termination command"
340
+ },
341
+ // ----- shell/interpreter launchers (caution) -----
342
+ // `env bash -c '…'`, `timeout sh`, `nohup perl -e '…'` etc. wrap a child
343
+ // binary that bypasses the allowlist name-gate entirely (the wrapper
344
+ // resolves the child from PATH, not from the allowlist). We flag caution
345
+ // when a known launcher has a shell/interpreter as its target program.
346
+ {
347
+ id: "shell-launcher",
348
+ level: "caution",
349
+ test: (cmd, args) => {
350
+ const launchers = [
351
+ "env",
352
+ "timeout",
353
+ "nohup",
354
+ "nice",
355
+ "script",
356
+ "expect",
357
+ "tmux",
358
+ "screen",
359
+ "byobu",
360
+ "dtach"
361
+ ];
362
+ if (!launchers.includes(cmd)) return false;
363
+ const shells = [
364
+ "sh",
365
+ "bash",
366
+ "zsh",
367
+ "fish",
368
+ "python",
369
+ "python3",
370
+ "perl",
371
+ "ruby",
372
+ "node",
373
+ "pwsh",
374
+ "powershell",
375
+ "cmd"
376
+ ];
377
+ if (cmd === "env") {
378
+ const prog = args.find((a) => !a.includes("=") && !a.startsWith("-"));
379
+ return prog !== void 0 && shells.includes(prog);
380
+ }
381
+ return args.some((a) => shells.includes(a));
382
+ },
383
+ reason: "launcher wrapping a shell/interpreter (bypasses allowlist name-gate)"
384
+ }
385
+ ];
386
+ function detectDanger(cmd, args, bypass) {
387
+ const reasons = [];
388
+ let level = "safe";
389
+ let matchedRule;
390
+ for (const rule of RULES) {
391
+ if (bypass?.has(rule.id)) continue;
392
+ if (!rule.test(cmd, args)) continue;
393
+ reasons.push(rule.reason);
394
+ if (matchedRule === void 0 || levelRank(rule.level) >= levelRank(level)) {
395
+ matchedRule = rule.id;
396
+ }
397
+ if (levelRank(rule.level) > levelRank(level)) {
398
+ level = rule.level;
399
+ }
400
+ }
401
+ if (level === "safe") return { level: "safe", reasons: [] };
402
+ const result = { level, reasons };
403
+ if (matchedRule !== void 0) result.matchedRule = matchedRule;
404
+ return result;
405
+ }
406
+ function levelRank(level) {
407
+ switch (level) {
408
+ case "safe":
409
+ return 0;
410
+ case "caution":
411
+ return 1;
412
+ case "destructive":
413
+ return 2;
414
+ }
415
+ }
416
+
417
+ // src/exec-kill-guard.ts
418
+ import * as os from "node:os";
419
+ import * as path from "node:path";
420
+ var isWin = os.platform() === "win32";
421
+ async function checkExecKillCommand(cmd, args) {
422
+ if (!cmd) return { blocked: false };
423
+ const cmdLower = cmd.toLowerCase().trim();
424
+ const fullCommand = [cmdLower, ...args].join(" ").replace(/\s+/g, " ").trim();
425
+ if (isWin) {
426
+ if (cmdLower === "taskkill" || cmdLower === "taskkill.exe") {
427
+ const hasForce = args.some((a) => a.toUpperCase() === "/F" || a.toUpperCase() === "-F");
428
+ const signal = hasForce ? "FORCE" : "TERM";
429
+ for (let i = 0; i < args.length; i++) {
430
+ const a = args[i];
431
+ if (a.toUpperCase() === "/IM" || a.toUpperCase() === "-IM") {
432
+ const nameArg = args[i + 1];
433
+ if (nameArg) {
434
+ const result = await checkKillTarget({ name: nameArg, signal, cmd: fullCommand });
435
+ if (result.blocked) return result;
436
+ }
437
+ }
438
+ }
439
+ for (let i = 0; i < args.length; i++) {
440
+ const a = args[i];
441
+ if (a.toUpperCase() === "/PID" || a.toUpperCase() === "-PID") {
442
+ const pidArg = args[i + 1];
443
+ if (pidArg && /^\d+$/.test(pidArg)) {
444
+ const result = await checkKillTarget({
445
+ pid: parseInt(pidArg, 10),
446
+ signal,
447
+ cmd: fullCommand
448
+ });
449
+ if (result.blocked) return result;
450
+ }
451
+ }
452
+ }
453
+ for (let i = 0; i < args.length; i++) {
454
+ const a = args[i];
455
+ if (a.toUpperCase() === "/FI" || a.toUpperCase() === "-FI") {
456
+ const filterArg = args[i + 1];
457
+ if (filterArg) {
458
+ const nameMatch = filterArg.match(/IMAGENAME\s+eq\s+"?([^"\s]+)/i);
459
+ if (nameMatch?.[1]) {
460
+ const result = await checkKillTarget({
461
+ name: nameMatch[1],
462
+ signal,
463
+ cmd: fullCommand
464
+ });
465
+ if (result.blocked) return result;
466
+ }
467
+ }
468
+ }
469
+ }
470
+ return { blocked: false };
471
+ }
472
+ if (cmdLower === "powershell" || cmdLower === "powershell.exe" || cmdLower === "pwsh" || cmdLower === "pwsh.exe" || cmdLower === "cmd" || cmdLower === "cmd.exe") {
473
+ const shellFlagIndex = args.findIndex((arg) => {
474
+ const lower = arg.toLowerCase();
475
+ return lower === "-c" || lower === "-command" || lower === "/c";
476
+ });
477
+ if (shellFlagIndex >= 0) {
478
+ const innerTokens = tokenizeShellCommand(args.slice(shellFlagIndex + 1).join(" "));
479
+ const innerCommand = innerTokens[0];
480
+ if (innerCommand) {
481
+ const result = await checkExecKillCommand(innerCommand, innerTokens.slice(1));
482
+ if (result.blocked) return result;
483
+ }
484
+ }
485
+ }
486
+ if (cmdLower === "stop-process" || cmdLower === "kill") {
487
+ for (let i = 0; i < args.length; i++) {
488
+ const a = args[i];
489
+ if (a === "-Name" || a === "-n") {
490
+ const nameArg = args[i + 1]?.replace(/^['"]|['"]$/g, "");
491
+ if (nameArg) {
492
+ const result = await checkKillTarget({
493
+ name: nameArg,
494
+ signal: "FORCE",
495
+ cmd: fullCommand
496
+ });
497
+ if (result.blocked) return result;
498
+ }
499
+ }
500
+ if (a === "-Id" || a === "-PID" || a === "-pid") {
501
+ const pidArg = args[i + 1];
502
+ if (pidArg && /^\d+$/.test(pidArg)) {
503
+ const result = await checkKillTarget({
504
+ pid: parseInt(pidArg, 10),
505
+ signal: "FORCE",
506
+ cmd: fullCommand
507
+ });
508
+ if (result.blocked) return result;
509
+ }
510
+ }
511
+ }
512
+ const firstNonFlag = args.find((a) => !a.startsWith("-"));
513
+ if (firstNonFlag) {
514
+ const name = firstNonFlag.replace(/^['"]|['"]$/g, "");
515
+ const result = await checkKillTarget({ name, signal: "TERM", cmd: fullCommand });
516
+ if (result.blocked) return result;
517
+ }
518
+ }
519
+ if (cmdLower === "wmic" || cmdLower === "wmic.exe") {
520
+ const joined = args.join(" ").toLowerCase();
521
+ if (/\bprocess\b/.test(joined) && /\bdelete\b/.test(joined)) {
522
+ const nameMatch = joined.match(/name\s*=\s*['"]?([^'"]+)/);
523
+ if (nameMatch?.[1]) {
524
+ const result = await checkKillTarget({
525
+ name: nameMatch[1].trim(),
526
+ signal: "FORCE",
527
+ cmd: fullCommand
528
+ });
529
+ if (result.blocked) return result;
530
+ }
531
+ return {
532
+ blocked: true,
533
+ reason: "Blocked: wmic process delete targets all matched processes \u2014 would include protected WrongStack processes."
534
+ };
535
+ }
536
+ }
537
+ if (cmdLower === "node" || cmdLower === "node.exe") {
538
+ if (args.includes("-e") || args.includes("--eval")) {
539
+ const evalIdx = args.indexOf("-e") !== -1 ? args.indexOf("-e") : args.indexOf("--eval");
540
+ const evalCode = args[evalIdx + 1] ?? "";
541
+ if (/\bprocess\.kill\s*\(/.test(evalCode)) {
542
+ const pidMatch = evalCode.match(/process\.kill\s*\(\s*(\d+)/);
543
+ if (pidMatch?.[1]) {
544
+ const pid = parseInt(pidMatch[1], 10);
545
+ const result = await checkKillTarget({ pid, signal: "SIGTERM", cmd: fullCommand });
546
+ if (result.blocked) return result;
547
+ }
548
+ return {
549
+ blocked: true,
550
+ reason: "Blocked: node -e with process.kill() \u2014 would target protected WrongStack process(es)."
551
+ };
552
+ }
553
+ }
554
+ }
555
+ } else {
556
+ if (cmdLower === "kill") {
557
+ for (const a of args) {
558
+ const num = a.replace(/^-/, "");
559
+ if (/^\d+$/.test(num)) {
560
+ const pid = parseInt(num, 10);
561
+ const result = await checkKillTarget({ pid, signal: "SIGTERM", cmd: fullCommand });
562
+ if (result.blocked) return result;
563
+ }
564
+ }
565
+ }
566
+ if (cmdLower === "pkill" || cmdLower === "killall") {
567
+ const firstNonFlag = args.find((a) => !a.startsWith("-"));
568
+ if (firstNonFlag) {
569
+ const result = await checkKillTarget({
570
+ name: firstNonFlag,
571
+ signal: "SIGTERM",
572
+ cmd: fullCommand
573
+ });
574
+ if (result.blocked) return result;
575
+ }
576
+ }
577
+ }
578
+ return { blocked: false };
579
+ }
580
+ function tokenizeShellCommand(command) {
581
+ const tokens = [];
582
+ let current = "";
583
+ let quote = null;
584
+ for (const char of command.trim()) {
585
+ if (quote) {
586
+ if (char === quote) quote = null;
587
+ else current += char;
588
+ continue;
589
+ }
590
+ if (char === '"' || char === "'") {
591
+ quote = char;
592
+ } else if (/\s/.test(char)) {
593
+ if (current) {
594
+ tokens.push(current);
595
+ current = "";
596
+ }
597
+ } else {
598
+ current += char;
599
+ }
600
+ }
601
+ if (current) tokens.push(current);
602
+ return tokens;
603
+ }
604
+ async function checkKillTarget(target) {
605
+ const registry = getPersistentProcessRegistry();
606
+ if (target.pid !== void 0) {
607
+ const blocked = await registry.shouldBlockKill(target.pid);
608
+ if (blocked) {
609
+ return {
610
+ blocked: true,
611
+ reason: `Blocked: kill ${target.signal} PID ${target.pid} targets a protected WrongStack process (${target.cmd.slice(0, 80)}).`
612
+ };
613
+ }
614
+ if (target.pid === process.pid) {
615
+ return {
616
+ blocked: true,
617
+ reason: "Blocked: cannot kill the current WrongStack process."
618
+ };
619
+ }
620
+ if (target.pid === process.ppid) {
621
+ return {
622
+ blocked: true,
623
+ reason: "Blocked: cannot kill the parent terminal hosting WrongStack."
624
+ };
625
+ }
626
+ return { blocked: false };
627
+ }
628
+ if (target.name) {
629
+ const nameLower = target.name.toLowerCase().replace(/\.exe$/, "");
630
+ if (nameLower.includes("wrongstack")) {
631
+ return {
632
+ blocked: true,
633
+ reason: `Blocked: kill ${target.signal} '${target.name}' targets a WrongStack process name.`
634
+ };
635
+ }
636
+ const currentImage = path.basename(process.execPath).toLowerCase().replace(/\.exe$/, "");
637
+ const targetsNodeRuntime = nameLower === "node" || nameLower.startsWith("node");
638
+ if (targetsNodeRuntime && currentImage === "node") {
639
+ return {
640
+ blocked: true,
641
+ reason: `Blocked: kill ${target.signal} '${target.name}' would kill the active WrongStack node.exe runtime.`
642
+ };
643
+ }
644
+ const protectedPids = await registry.getAllProtectedPids();
645
+ if (protectedPids.length > 0 && targetsNodeRuntime) {
646
+ return {
647
+ blocked: true,
648
+ reason: `Blocked: kill ${target.signal} '${target.name}' would kill all node.exe processes including active WrongStack instance(s).`
649
+ };
650
+ }
651
+ return { blocked: false };
652
+ }
653
+ return { blocked: false };
654
+ }
655
+
656
+ // src/exec-allowlist.ts
657
+ var DEFAULT_ALLOWED_COMMANDS = /* @__PURE__ */ new Set([
658
+ // JS / TS toolchain
659
+ "node",
660
+ "npm",
661
+ "pnpm",
662
+ "yarn",
663
+ "npx",
664
+ "bun",
665
+ "deno",
666
+ "corepack",
667
+ "tsc",
668
+ "tsx",
669
+ "ts-node",
670
+ "vite",
671
+ "vitest",
672
+ "jest",
673
+ "biome",
674
+ "eslint",
675
+ "prettier",
676
+ "turbo",
677
+ "nx",
678
+ "webpack",
679
+ "rollup",
680
+ "parcel",
681
+ "next",
682
+ "astro",
683
+ "playwright",
684
+ "cypress",
685
+ // version control
686
+ "git",
687
+ // Rust
688
+ "cargo",
689
+ "rustc",
690
+ // Go
691
+ "go",
692
+ // Python
693
+ "python",
694
+ "python3",
695
+ "pip",
696
+ "pip3",
697
+ "pytest",
698
+ "ruff",
699
+ "mypy",
700
+ "uv",
701
+ "uvx",
702
+ "poetry",
703
+ "hatch",
704
+ "tox",
705
+ // Ruby
706
+ "ruby",
707
+ "gem",
708
+ "bundle",
709
+ // PHP
710
+ "php",
711
+ "composer",
712
+ "phpunit",
713
+ // JVM
714
+ "java",
715
+ "javac",
716
+ "mvn",
717
+ "gradle",
718
+ "gradlew",
719
+ // .NET
720
+ "dotnet",
721
+ // C / C++ / native build
722
+ "make",
723
+ "cmake",
724
+ "ninja",
725
+ "clang",
726
+ "clang-cl",
727
+ "gcc",
728
+ "g++",
729
+ "link",
730
+ "msbuild",
731
+ // containers / orchestration
732
+ "docker",
733
+ "podman",
734
+ "kubectl",
735
+ // network fetch tools. Per-arg safety is NOT enforced by BLOCKED_ARG_PATTERNS
736
+ // (no curl/wget entries) — the real boundary is the per-call `confirm`
737
+ // permission gate (exec.ts permission:'confirm', subjectKey:'command'),
738
+ // the `pipe-to-shell` danger rule, and the kill guard. The allowlist is a
739
+ // guidance layer, not a security boundary on its own.
740
+ "curl",
741
+ "wget",
742
+ // common POSIX file/text utilities
743
+ "pwd",
744
+ "ls",
745
+ "cat",
746
+ "head",
747
+ "tail",
748
+ "wc",
749
+ "grep",
750
+ "rg",
751
+ "find",
752
+ "echo",
753
+ "sort",
754
+ "uniq",
755
+ "sed",
756
+ "awk",
757
+ "mkdir",
758
+ "cp",
759
+ "mv",
760
+ "rm",
761
+ "touch",
762
+ "tar",
763
+ // Windows-native tooling (win32). All non-destructive binaries; per-arg
764
+ // safety is still enforced by BLOCKED_ARG_PATTERNS + the destructive-ops
765
+ // gate in bash-kill-guard.ts. `gh` is included even though it lives at
766
+ // "C:\Program Files\GitHub CLI\gh.exe" — resolveWin32Command handles the
767
+ // space in the path.
768
+ "gh",
769
+ "where",
770
+ "tasklist",
771
+ "systeminfo",
772
+ "wmic",
773
+ "sc",
774
+ "netstat",
775
+ "ipconfig",
776
+ "nslookup",
777
+ "tracert",
778
+ "pathping",
779
+ // Windows shell interpreters. Without these, `exec` cannot run cmd builtins
780
+ // (`dir`, `type`, `copy`, …) or any PowerShell cmdlet on Windows — a major
781
+ // gap since those are the platform's primary shells. Arbitrary execution
782
+ // through `cmd /c …` / `powershell -c …` is NOT a new hole: the permission
783
+ // policy reconstructs the full command line (shellCommandLineFromInput) and
784
+ // still runs it through the YOLO destructive classifier, so a genuinely
785
+ // destructive `cmd /c del /s /q C:\…` continues to require confirmation.
786
+ "cmd",
787
+ "cmd.exe",
788
+ "powershell",
789
+ "powershell.exe",
790
+ "pwsh",
791
+ "pwsh.exe",
792
+ // [core] Extended default allowlist (added 4b3d18d1 + this commit). Broadly
793
+ // used dev binaries — NOT all non-destructive: this section contains
794
+ // process/system tools (kill, chown, mount, userdel), network scanners
795
+ // (nmap, masscan, zmap, nuclei), and launchers (env, perl, timeout, tmux).
796
+ // The real safety boundary for these is the per-call `confirm` permission
797
+ // gate (exec.ts permission:'confirm', subjectKey:'command' renders the full
798
+ // invocation) plus the danger rules in _danger-detect.ts. Per-arg hard-deny
799
+ // is still enforced by BLOCKED_ARG_PATTERNS + bash-kill-guard.ts, but only
800
+ // for the commands that have entries there (git, find, rm).
801
+ // --- Archives & compression ---
802
+ "7z",
803
+ "7za",
804
+ "bzip2",
805
+ "gzip",
806
+ "xz",
807
+ "unzip",
808
+ "zip",
809
+ "gtar",
810
+ "bsdtar",
811
+ "star",
812
+ "pax",
813
+ "cpio",
814
+ // --- Android / mobile dev ---
815
+ "adb",
816
+ "fastboot",
817
+ "sdkmanager",
818
+ // --- DevOps / config mgmt ---
819
+ "ansible",
820
+ "ansible-playbook",
821
+ "ansible-vault",
822
+ "ansible-lint",
823
+ "ansible-galaxy",
824
+ "molecule",
825
+ // --- Cloud CLIs ---
826
+ "aws",
827
+ "aws-vault",
828
+ "awslocal",
829
+ "az",
830
+ "azcopy",
831
+ "gcloud",
832
+ "gsutil",
833
+ "doctl",
834
+ "linode-cli",
835
+ // --- Native / C / C++ / linker tools ---
836
+ "clang++",
837
+ "clang-format",
838
+ "clang-tidy",
839
+ "clangd",
840
+ "lld",
841
+ "lldb",
842
+ "ctest",
843
+ "gmake",
844
+ "meson",
845
+ "conan",
846
+ "vcpkg",
847
+ "cl",
848
+ "rc",
849
+ "mt",
850
+ "dumpbin",
851
+ "dotnet-format",
852
+ // --- Image / media / binary tools ---
853
+ "convert",
854
+ "ffmpeg",
855
+ "ffprobe",
856
+ "magick",
857
+ "gs",
858
+ "exiftool",
859
+ // --- HTTP / fetch ---
860
+ "wget2",
861
+ "aria2c",
862
+ "axel",
863
+ "httpie",
864
+ "hey",
865
+ "ab",
866
+ "wrk",
867
+ "http",
868
+ // --- Diff / patch / merge ---
869
+ "diff",
870
+ "diff3",
871
+ "patch",
872
+ "meld",
873
+ "kdiff3",
874
+ "kompare",
875
+ // --- Encoding / file inspection ---
876
+ "dos2unix",
877
+ "unix2dos",
878
+ "iconv",
879
+ "file",
880
+ "stat",
881
+ "xxd",
882
+ "hexdump",
883
+ "od",
884
+ "base64",
885
+ // --- SSH / crypto / signing ---
886
+ "ssh",
887
+ "ssh-add",
888
+ "ssh-keygen",
889
+ "ssh-keyscan",
890
+ "scp",
891
+ "sftp",
892
+ "rsync",
893
+ "gpg",
894
+ "gpg2",
895
+ "gpg-agent",
896
+ "openssl",
897
+ "step",
898
+ "keytool",
899
+ // --- Search ---
900
+ "egrep",
901
+ "fgrep",
902
+ "ag",
903
+ "ack",
904
+ "sift",
905
+ "ugrep",
906
+ "fd",
907
+ "fdfind",
908
+ "jq",
909
+ "yq",
910
+ "xq",
911
+ "fx",
912
+ "gron",
913
+ // --- K8s / container ecosystem ---
914
+ "kubectl.exe",
915
+ "kubeadm",
916
+ "kubelet",
917
+ "helm",
918
+ "k9s",
919
+ "kustomize",
920
+ "skaffold",
921
+ "tilt",
922
+ "minikube",
923
+ "kind",
924
+ "k3d",
925
+ "k3s",
926
+ "docker-compose",
927
+ "buildah",
928
+ "skopeo",
929
+ "nerdctl",
930
+ "ctr",
931
+ "ctr.exe",
932
+ // --- Databases ---
933
+ "sqlite3",
934
+ "sqlite",
935
+ "psql",
936
+ "pg_dump",
937
+ "pg_restore",
938
+ "mysql",
939
+ "mysqladmin",
940
+ "mysqldump",
941
+ "mariadb",
942
+ "mariadb-dump",
943
+ "redis-cli",
944
+ "redis-server",
945
+ "memcached",
946
+ "etcdctl",
947
+ "consul",
948
+ "vault",
949
+ "nomad",
950
+ "mongosh",
951
+ "mongo",
952
+ "mongoexport",
953
+ "mongoimport",
954
+ "mongodump",
955
+ "mongorestore",
956
+ // --- Windows extended (read-mostly ops) ---
957
+ "taskkill",
958
+ "gpupdate",
959
+ "gpresult",
960
+ "hostname",
961
+ "whoami",
962
+ "who",
963
+ "net",
964
+ "net1",
965
+ // --- VCS ecosystem ---
966
+ "glab",
967
+ "hub",
968
+ "tea",
969
+ "git-lfs",
970
+ "tig",
971
+ "lazygit",
972
+ // --- POSIX text utilities (extended) ---
973
+ "gawk",
974
+ "tr",
975
+ "cut",
976
+ "paste",
977
+ "join",
978
+ "comm",
979
+ "expand",
980
+ "unexpand",
981
+ "fold",
982
+ "fmt",
983
+ "nl",
984
+ "pr",
985
+ "column",
986
+ "tsort",
987
+ "tty",
988
+ "ul",
989
+ "units",
990
+ "factor",
991
+ "seq",
992
+ "shuf",
993
+ "look",
994
+ "yes",
995
+ "true",
996
+ "false",
997
+ "test",
998
+ "[",
999
+ "printf",
1000
+ "env",
1001
+ "tree",
1002
+ "locate",
1003
+ "which",
1004
+ "whereis",
1005
+ // NOTE: shell builtins with no standalone binary (type, hash, pushd,
1006
+ // popd, dirs, history, fc, jobs, bg, fg, wait, ulimit, umask, trap,
1007
+ // exit, return, source, ., alias, unalias, set, unset, export, readonly,
1008
+ // typeset, declare, local, eval, exec) are intentionally excluded —
1009
+ // spawn() would fail with ENOENT on every platform because they only
1010
+ // exist inside a shell process. Use the `bash` tool for builtins.
1011
+ "nice",
1012
+ "nohup",
1013
+ "timeout",
1014
+ "time",
1015
+ // --- Process / system inspection ---
1016
+ "htop",
1017
+ "top",
1018
+ "atop",
1019
+ "glances",
1020
+ "iotop",
1021
+ "nethogs",
1022
+ "iftop",
1023
+ "lsof",
1024
+ "strace",
1025
+ "ltrace",
1026
+ "sysstat",
1027
+ "vmstat",
1028
+ "iostat",
1029
+ "mpstat",
1030
+ "sar",
1031
+ "free",
1032
+ "df",
1033
+ "du",
1034
+ "mount",
1035
+ "umount",
1036
+ "lsblk",
1037
+ "blkid",
1038
+ "kill",
1039
+ "killall",
1040
+ "pkill",
1041
+ "pgrep",
1042
+ "pidof",
1043
+ "ps",
1044
+ "ps.exe",
1045
+ // --- Network inspection ---
1046
+ "ip",
1047
+ "ss",
1048
+ "route",
1049
+ "arp",
1050
+ "arping",
1051
+ "ping",
1052
+ "ping6",
1053
+ "hping3",
1054
+ "mtr",
1055
+ "tracepath",
1056
+ "tcpdump",
1057
+ "nmap",
1058
+ "netcat",
1059
+ "nc",
1060
+ "ncat",
1061
+ "socat",
1062
+ // --- Sync / backup ---
1063
+ "rclone",
1064
+ "restic",
1065
+ "borg",
1066
+ "duplicati",
1067
+ "duplicacy",
1068
+ "syncthing",
1069
+ "syncthing-cli",
1070
+ // --- Permissions / users / ACLs (POSIX) ---
1071
+ "useradd",
1072
+ "userdel",
1073
+ "usermod",
1074
+ "groupadd",
1075
+ "groupdel",
1076
+ "groupmod",
1077
+ "chown",
1078
+ "chmod",
1079
+ "chgrp",
1080
+ "getfacl",
1081
+ "setfacl",
1082
+ "setcap",
1083
+ "getcap",
1084
+ // --- Crypto / cert mgmt (extended) ---
1085
+ "certbot",
1086
+ "mkcert",
1087
+ "jarsigner",
1088
+ // --- Editors ---
1089
+ "subl",
1090
+ "code",
1091
+ "code-insiders",
1092
+ "cursor",
1093
+ "atom",
1094
+ "nano",
1095
+ "vim",
1096
+ "nvim",
1097
+ "vi",
1098
+ "emacs",
1099
+ "helix",
1100
+ "hx",
1101
+ "micro",
1102
+ "jed",
1103
+ "ed",
1104
+ "ex",
1105
+ "mg",
1106
+ // --- Terminal multiplexers ---
1107
+ "asciinema",
1108
+ "script",
1109
+ "scriptreplay",
1110
+ "expect",
1111
+ "screen",
1112
+ "tmux",
1113
+ "byobu",
1114
+ "dtach",
1115
+ "abduco",
1116
+ // --- Calculators / REPLs / scientific ---
1117
+ "bc",
1118
+ "dc",
1119
+ "calc",
1120
+ "qalc",
1121
+ "genius",
1122
+ "octave",
1123
+ "R",
1124
+ "Rscript",
1125
+ "julia",
1126
+ "irb",
1127
+ "pry",
1128
+ "ghci",
1129
+ "stack",
1130
+ "cabal",
1131
+ "ghc",
1132
+ // --- PHP / Lua / Perl / Ruby ecosystem (extended) ---
1133
+ "php8",
1134
+ "php7",
1135
+ "phpcs",
1136
+ "phpcbf",
1137
+ "phpmd",
1138
+ "phpstan",
1139
+ "psalm",
1140
+ "lua",
1141
+ "lua5.1",
1142
+ "lua5.2",
1143
+ "lua5.3",
1144
+ "lua5.4",
1145
+ "luarocks",
1146
+ "perl",
1147
+ "cpan",
1148
+ "prove",
1149
+ "plackup",
1150
+ "rake",
1151
+ "rspec",
1152
+ "jekyll",
1153
+ "node-gyp",
1154
+ "node-pre-gyp",
1155
+ // --- JS / TS toolchain (extended) ---
1156
+ "electron",
1157
+ "electron-builder",
1158
+ "electron-forge",
1159
+ "vite-preview",
1160
+ "swc",
1161
+ "swc-cli",
1162
+ "swcpack",
1163
+ "mocha",
1164
+ "chai",
1165
+ "jasmine",
1166
+ "puppeteer",
1167
+ "lighthouse",
1168
+ // --- Linters / formatters (extended) ---
1169
+ "tslint",
1170
+ "stylelint",
1171
+ "htmlhint",
1172
+ "jshint",
1173
+ "jslint",
1174
+ "jscs",
1175
+ // --- Document conversion ---
1176
+ "pandoc",
1177
+ "weasyprint",
1178
+ "wkhtmltopdf",
1179
+ "wkhtmltoimage",
1180
+ "prince",
1181
+ "mdp",
1182
+ "markdown",
1183
+ "multimarkdown",
1184
+ "cmark",
1185
+ "cmark-gfm",
1186
+ // --- Office / spreadsheet ---
1187
+ "soffice",
1188
+ "libreoffice",
1189
+ "unoconv",
1190
+ "abiword",
1191
+ "gnumeric",
1192
+ // --- Spell / grammar ---
1193
+ "aspell",
1194
+ "hunspell",
1195
+ "enchant",
1196
+ "languagetool",
1197
+ // --- Source-highlight / diff tools ---
1198
+ "delta",
1199
+ "bat",
1200
+ "ccat",
1201
+ "hl",
1202
+ "highlight",
1203
+ "source-highlight",
1204
+ "ansifilter",
1205
+ // --- Job schedulers ---
1206
+ "pueue",
1207
+ "task-spooler",
1208
+ "ts",
1209
+ "at",
1210
+ "atd",
1211
+ "anacron",
1212
+ "fcron",
1213
+ "cronie",
1214
+ "systemd-run",
1215
+ "systemd-cat",
1216
+ // --- Plotting / visualization ---
1217
+ "gnuplot",
1218
+ "gnuplot-nox",
1219
+ "veusz",
1220
+ "scidavis",
1221
+ "grace",
1222
+ "xmgrace",
1223
+ "labplot",
1224
+ // --- Security / recon (network + web) ---
1225
+ "masscan",
1226
+ "zmap",
1227
+ "rustscan",
1228
+ "amass",
1229
+ "subfinder",
1230
+ "httpx",
1231
+ "nuclei",
1232
+ "naabu",
1233
+ "katana",
1234
+ "dnsx",
1235
+ "assetfinder",
1236
+ "findomain",
1237
+ "gau",
1238
+ "waybackurls",
1239
+ "httprobe",
1240
+ "meg",
1241
+ "subjack",
1242
+ "sublert",
1243
+ "chaos"
1244
+ ]);
1245
+
1246
+ // src/exec.ts
1247
+ var isWin2 = process.platform === "win32";
1248
+ var allowedCommands = new Set(DEFAULT_ALLOWED_COMMANDS);
1249
+ var normalizeCmd = (c) => c.trim();
1250
+ function configureExecPolicy(opts = {}) {
1251
+ const next = new Set(DEFAULT_ALLOWED_COMMANDS);
1252
+ for (const c of opts.allow ?? []) {
1253
+ const n = normalizeCmd(c);
1254
+ if (n) next.add(n);
1255
+ }
1256
+ for (const c of opts.deny ?? []) next.delete(normalizeCmd(c));
1257
+ allowedCommands = next;
1258
+ }
1259
+ function resetExecPolicy() {
1260
+ allowedCommands = new Set(DEFAULT_ALLOWED_COMMANDS);
1261
+ }
1262
+ var dangerBypass = /* @__PURE__ */ new Set();
1263
+ function configureDangerBypass(opts = {}) {
1264
+ const next = /* @__PURE__ */ new Set();
1265
+ for (const id of opts.bypass ?? []) {
1266
+ const trimmed = id.trim();
1267
+ if (trimmed) next.add(trimmed);
1268
+ }
1269
+ dangerBypass = next;
1270
+ }
1271
+ function resetDangerBypass() {
1272
+ dangerBypass = /* @__PURE__ */ new Set();
1273
+ }
1274
+ function getDangerBypass() {
1275
+ return dangerBypass;
1276
+ }
1277
+ function isExecCommandAllowed(cmd) {
1278
+ return allowedCommands.has(normalizeCmd(cmd));
1279
+ }
1280
+ function getExecAllowlist() {
1281
+ return [...allowedCommands].sort();
1282
+ }
1283
+ var MAX_ARGS = 20;
1284
+ var MAX_OUTPUT = 2e5;
1285
+ var DEFAULT_TIMEOUT_MS = 3e4;
1286
+ var MAX_TIMEOUT_MS = 6e5;
1287
+ var BLOCKED_ARG_PATTERNS = {
1288
+ python: [],
1289
+ // git --exec=<cmd> runs arbitrary commands via upload-pack/receive-pack;
1290
+ // -C <dir> changes working directory, bypassing cwd sandbox;
1291
+ // -c/--config <k>=<v> injects config that runs commands
1292
+ // (e.g. core.sshCommand, core.pager, http.proxy, alias.x=!cmd).
1293
+ git: [
1294
+ /^--exec=/,
1295
+ /^--upload-pack=/,
1296
+ /^--receive-pack=/,
1297
+ /^-C$/,
1298
+ /^-c$/,
1299
+ /^--config$/,
1300
+ /^-c=/,
1301
+ /^--config=/,
1302
+ /^--config-env=/
1303
+ ],
1304
+ node: [],
1305
+ go: [],
1306
+ bun: [],
1307
+ docker: [],
1308
+ // find -exec/-ok/-execdir execute arbitrary commands
1309
+ find: [
1310
+ /^-exec$/,
1311
+ /^-exec;$/,
1312
+ /^-ok$/,
1313
+ /^-ok;$/,
1314
+ /^-execdir$/,
1315
+ /^-execdir;$/,
1316
+ /^-exec=/,
1317
+ /^-ok=/,
1318
+ /^-execdir=/
1319
+ ],
1320
+ // rm -rf / is catastrophic — block absolute paths, home, dot-dirs,
1321
+ // and glob patterns that could expand to dangerous targets.
1322
+ // `rm -rf ./src/*` expands to project files; `rm -rf ../../` escapes upward;
1323
+ // `rm -rf /*` targets the filesystem root. All are blocked.
1324
+ rm: [/^\//, /^[A-Za-z]:[\\/]/, /^~\//, /^~$/, /^\.$/, /^\.\.$/, /\*$/, /\/$/, /\/\*$/, /\.\//],
1325
+ // npm/pnpm subcommands are checked separately below. Matching every arg here
1326
+ // over-blocked normal dev flows such as `pnpm vitest run ...`.
1327
+ npm: [],
1328
+ pnpm: [],
1329
+ npx: []
1330
+ };
1331
+ var BLOCKED_OPTION_NAMES = {
1332
+ git: /* @__PURE__ */ new Set([
1333
+ "--exec",
1334
+ "--upload-pack",
1335
+ "--receive-pack",
1336
+ "--exec-path",
1337
+ "--git-dir",
1338
+ "--work-tree",
1339
+ "--namespace",
1340
+ "-c",
1341
+ "--config",
1342
+ "--config-env",
1343
+ "-C"
1344
+ ]),
1345
+ find: /* @__PURE__ */ new Set(["-exec", "-ok", "-execdir"])
1346
+ };
1347
+ function optionName(arg) {
1348
+ const eq = arg.indexOf("=");
1349
+ return eq > 0 ? arg.slice(0, eq) : arg;
1350
+ }
1351
+ var BLOCKED_SUBCOMMANDS = {
1352
+ docker: /* @__PURE__ */ new Set(["push"]),
1353
+ podman: /* @__PURE__ */ new Set(["push"]),
1354
+ npm: /* @__PURE__ */ new Set(["publish", "deploy"]),
1355
+ pnpm: /* @__PURE__ */ new Set(["publish", "deploy"]),
1356
+ yarn: /* @__PURE__ */ new Set(["publish"])
1357
+ };
1358
+ var BLOCKED_SUBCOMMAND_SEQUENCES = {
1359
+ yarn: [["npm", "publish"]]
1360
+ };
1361
+ function firstSubcommand(args) {
1362
+ for (const arg of args) {
1363
+ if (arg === "--") return null;
1364
+ if (!arg.startsWith("-")) return arg;
1365
+ }
1366
+ return null;
1367
+ }
1368
+ function subcommandArgs(args) {
1369
+ const out = [];
1370
+ for (const arg of args) {
1371
+ if (arg === "--") break;
1372
+ if (!arg.startsWith("-")) out.push(arg);
1373
+ }
1374
+ return out;
1375
+ }
1376
+ function validateArgs(cmd, args) {
1377
+ const blockedSubcommands = BLOCKED_SUBCOMMANDS[cmd];
1378
+ const subcommand = firstSubcommand(args);
1379
+ if (blockedSubcommands && subcommand && blockedSubcommands.has(subcommand)) {
1380
+ return `Blocked subcommand "${subcommand}" for command "${cmd}"`;
1381
+ }
1382
+ const blockedSequences = BLOCKED_SUBCOMMAND_SEQUENCES[cmd];
1383
+ if (blockedSequences) {
1384
+ const actual = subcommandArgs(args);
1385
+ const blocked2 = blockedSequences.find((seq) => seq.every((part, idx) => actual[idx] === part));
1386
+ if (blocked2) return `Blocked subcommand "${blocked2.join(" ")}" for command "${cmd}"`;
1387
+ }
1388
+ const blockedOptions = BLOCKED_OPTION_NAMES[cmd];
1389
+ if (blockedOptions) {
1390
+ for (const arg of args) {
1391
+ if (arg === "--") break;
1392
+ if (blockedOptions.has(optionName(arg))) {
1393
+ return `Blocked option "${optionName(arg)}" for command "${cmd}"`;
1394
+ }
1395
+ }
1396
+ }
1397
+ const blocked = BLOCKED_ARG_PATTERNS[cmd];
1398
+ if (!blocked) return null;
1399
+ for (const arg of args) {
1400
+ for (const pattern of blocked) {
1401
+ if (pattern.test(arg)) {
1402
+ return `Blocked argument "${arg}" for command "${cmd}" (matches security pattern ${pattern})`;
1403
+ }
1404
+ }
1405
+ }
1406
+ return null;
1407
+ }
1408
+ var SAFE_DANGER = { level: "safe", reasons: [] };
1409
+ var execTool = {
1410
+ name: "exec",
1411
+ category: "Shell",
1412
+ description: "Execute a command from a **curated command roster** with argument validation and confirm gating. This is the **preferred** alternative to the `bash` tool for running development tools (node, npm, pnpm, tsc, git, tests, linters, etc.). It is NOT a sandbox \u2014 several rostered commands (node, python, powershell, \u2026) can run arbitrary code \u2014 so prefer least-privilege commands.",
1413
+ usageHint: "PREFERRED SHELL TOOL for most cases.\n\nUse this instead of `bash` whenever possible.\n- `command` must be in the allowlist. Defaults cover JS (node/npm/pnpm/yarn/bun/deno/tsc/vitest/eslint/biome), Go (`go build`/`go test`), Rust (cargo), Python (python/pip), Ruby (gem/bundle), JVM (java/mvn/gradle), .NET (dotnet), native (make/cmake), and git. Users can extend it via `tools.exec.allow` in config.\n- Arguments are passed as a clean array (no shell interpretation).\n- `cwd` is validated to stay inside the project.\n- If a command is not allowlisted, the error explains how to add it; for one-off arbitrary commands, fall back to `bash` (with strong justification).\nThe curated roster + confirm gating narrows the surface compared to full shell access, but this is not a sandbox \u2014 prefer least-privilege commands.",
1414
+ selection: {
1415
+ doNotUseWhen: "the operation requires pipes, redirection, shell expansion, or a non-allowlisted command.",
1416
+ useInstead: ["bash"]
1417
+ },
1418
+ permission: "confirm",
1419
+ // WS-046: without this, every exec call collapsed onto the bare tool name.
1420
+ // Three consequences followed: "always allow" stored a rule that could never
1421
+ // match, pressing "no" once blocked ALL exec for the session, and the
1422
+ // permission cache keyed one decision for every command. `subjectKey:
1423
+ // 'command'` renders the FULL invocation (`command` + `args`) — using the
1424
+ // program alone would make `exec git status` and `exec git push --force` the
1425
+ // same subject, so trusting one would silently authorize the other.
1426
+ subjectKey: "command",
1427
+ mutating: true,
1428
+ riskTier: "standard",
1429
+ // Executor-level abort ceiling. Must sit ABOVE the per-call timeout ceiling
1430
+ // (MAX_TIMEOUT_MS): the tool's own timer resolves with exit 124 + registry
1431
+ // tree-kill; the executor's AbortSignal.timeout is a blunt abort that would
1432
+ // otherwise fire first and discard the structured timeout result. The 10s
1433
+ // margin covers the kill/teardown window. (The executor additionally clamps
1434
+ // to config `tools.maxToolTimeoutMs`.)
1435
+ timeoutMs: MAX_TIMEOUT_MS + 1e4,
1436
+ capabilities: ["shell.restricted"],
1437
+ icon: "terminal",
1438
+ inputSchema: {
1439
+ type: "object",
1440
+ properties: {
1441
+ command: {
1442
+ type: "string",
1443
+ description: 'The base command to run. Must be in the internal allowlist (e.g. "node", "pnpm", "git", "tsc").'
1444
+ },
1445
+ args: {
1446
+ type: "array",
1447
+ items: { type: "string" },
1448
+ description: "Arguments passed to the command. Passed as an array (no shell parsing)."
1449
+ },
1450
+ cwd: {
1451
+ type: "string",
1452
+ description: "Optional working directory. Must resolve inside the project root."
1453
+ },
1454
+ timeout: {
1455
+ type: "integer",
1456
+ description: "Per-command timeout in milliseconds (default 30000, max 600000)."
1457
+ }
1458
+ },
1459
+ required: ["command"]
1460
+ },
1461
+ async execute(input, ctx, opts) {
1462
+ const registry = getProcessRegistry();
1463
+ if (!registry.canProceed) {
1464
+ return {
1465
+ command: input.command,
1466
+ args: input.args ?? [],
1467
+ stdout: "",
1468
+ stderr: "Circuit breaker is open \u2014 too many consecutive failures. Use /kill reset to recover.",
1469
+ exitCode: 1,
1470
+ truncated: false,
1471
+ allowed: false,
1472
+ danger: SAFE_DANGER
1473
+ };
1474
+ }
1475
+ const cmd = input.command.trim();
1476
+ if (!cmd)
1477
+ return {
1478
+ command: cmd,
1479
+ args: [],
1480
+ stdout: "",
1481
+ stderr: "Empty command",
1482
+ exitCode: 1,
1483
+ truncated: false,
1484
+ allowed: false,
1485
+ danger: SAFE_DANGER
1486
+ };
1487
+ if (!isExecCommandAllowed(cmd)) {
1488
+ return {
1489
+ command: cmd,
1490
+ args: input.args ?? [],
1491
+ stdout: "",
1492
+ stderr: `Command "${cmd}" not in allowlist. Add it to your active profile config (~/.wrongstack/profiles/<name>/config.json) under "tools": { "exec": { "allow": ["${cmd}"] } }, or use the bash tool for one-off arbitrary commands.`,
1493
+ exitCode: 1,
1494
+ truncated: false,
1495
+ allowed: false,
1496
+ danger: SAFE_DANGER
1497
+ };
1498
+ }
1499
+ const args = (input.args ?? []).slice(0, MAX_ARGS);
1500
+ const timeout = Math.max(1, Math.min(input.timeout ?? DEFAULT_TIMEOUT_MS, MAX_TIMEOUT_MS));
1501
+ const danger = detectDanger(cmd, args, dangerBypass);
1502
+ const killCheck = await checkExecKillCommand(cmd, args);
1503
+ if (killCheck.blocked) {
1504
+ return {
1505
+ command: cmd,
1506
+ args,
1507
+ stdout: "",
1508
+ stderr: killCheck.reason ?? "Kill command blocked: targets a protected WrongStack process.",
1509
+ exitCode: 1,
1510
+ truncated: false,
1511
+ allowed: false,
1512
+ danger
1513
+ };
1514
+ }
1515
+ const argError = validateArgs(cmd, args);
1516
+ if (argError) {
1517
+ return {
1518
+ command: cmd,
1519
+ args,
1520
+ stdout: "",
1521
+ stderr: argError,
1522
+ exitCode: 1,
1523
+ truncated: false,
1524
+ allowed: false,
1525
+ danger
1526
+ };
1527
+ }
1528
+ const defaultCwd = ctx.workingDir ?? ctx.cwd;
1529
+ let cwd;
1530
+ try {
1531
+ cwd = input.cwd ? await safeResolveReal(input.cwd, ctx) : await safeResolveReal(defaultCwd, ctx);
1532
+ } catch {
1533
+ return {
1534
+ command: cmd,
1535
+ args,
1536
+ stdout: "",
1537
+ stderr: `cwd "${input.cwd ?? defaultCwd}" resolves outside project root`,
1538
+ exitCode: 1,
1539
+ truncated: false,
1540
+ allowed: false,
1541
+ danger
1542
+ };
1543
+ }
1544
+ const signal = opts.signal;
1545
+ return runCommand(cmd, args, cwd, timeout, signal, ctx.session?.id, danger);
1546
+ }
1547
+ };
1548
+ function runCommand(cmd, args, cwd, timeout, signal, sessionId, danger) {
1549
+ return new Promise((resolve) => {
1550
+ let stdout = "";
1551
+ let stderr = "";
1552
+ let killed = false;
1553
+ const resolvedOnce = { value: false };
1554
+ const finish = (result) => {
1555
+ if (resolvedOnce.value) return;
1556
+ resolvedOnce.value = true;
1557
+ resolve(result);
1558
+ };
1559
+ const startedAt = Date.now();
1560
+ let stdoutBytes = 0;
1561
+ let stderrBytes = 0;
1562
+ let telemetryCompleted = false;
1563
+ let timedOut = false;
1564
+ const spool = createOutputSpool({ tool: `exec-${cmd}`, thresholdBytes: MAX_OUTPUT });
1565
+ const resolved = resolveWin32Command(cmd);
1566
+ const needsShell = isWin2 && (resolved.endsWith(".cmd") || resolved.endsWith(".bat"));
1567
+ const shim = needsShell ? buildWin32CmdShimInvocation(resolved, args) : null;
1568
+ const spawnCmd = shim?.command ?? resolved;
1569
+ const spawnArgs = shim?.args ?? args;
1570
+ const emitCompletedOnce = (exitCode, pid2, signal2) => {
1571
+ if (telemetryCompleted) return;
1572
+ telemetryCompleted = true;
1573
+ emitProcessCompleted({
1574
+ ...pid2 !== void 0 ? { pid: pid2 } : {},
1575
+ exitCode,
1576
+ ...signal2 ? { signal: signal2 } : {},
1577
+ durationMs: Date.now() - startedAt,
1578
+ stdoutBytes,
1579
+ stderrBytes,
1580
+ timedOut,
1581
+ endedAt: (/* @__PURE__ */ new Date()).toISOString()
1582
+ });
1583
+ };
1584
+ let child;
1585
+ try {
1586
+ child = spawn(spawnCmd, spawnArgs, {
1587
+ cwd,
1588
+ env: buildChildEnv(sessionId),
1589
+ stdio: ["ignore", "pipe", "pipe"],
1590
+ windowsHide: true,
1591
+ ...isWin2 ? {} : { signal },
1592
+ ...shim ? { windowsVerbatimArguments: shim.windowsVerbatimArguments } : {}
1593
+ });
1594
+ } catch (err) {
1595
+ spool.finalize();
1596
+ emitProcessStarted({
1597
+ parentPid: process.pid,
1598
+ command: redactCommand(`${cmd} ${args.join(" ")}`),
1599
+ args: redactCommand(args.join(" ")).split(" ").filter(Boolean),
1600
+ cwd,
1601
+ background: false,
1602
+ startedAt: new Date(startedAt).toISOString()
1603
+ });
1604
+ emitCompletedOnce(1, void 0);
1605
+ finish({
1606
+ command: cmd,
1607
+ args,
1608
+ stdout: "",
1609
+ stderr: `spawn failed: ${toErrorMessage(err)}`,
1610
+ exitCode: 1,
1611
+ truncated: false,
1612
+ allowed: true,
1613
+ danger
1614
+ });
1615
+ return;
1616
+ }
1617
+ emitProcessStarted({
1618
+ ...child.pid !== void 0 ? { pid: child.pid } : {},
1619
+ parentPid: process.pid,
1620
+ command: redactCommand(`${cmd} ${args.join(" ")}`),
1621
+ args: redactCommand(args.join(" ")).split(" ").filter(Boolean),
1622
+ cwd,
1623
+ background: false,
1624
+ startedAt: new Date(startedAt).toISOString()
1625
+ });
1626
+ child.on("error", (err) => {
1627
+ const isAbort = err && err.code === "ABORT_ERR";
1628
+ const stderrText = isAbort ? `Aborted: ${err.message}` : err.message;
1629
+ clearTimeout(timer);
1630
+ if (isWin2) signal.removeEventListener("abort", onAbort);
1631
+ if (typeof pid === "number") registry.unregister(pid);
1632
+ registry.afterCall(Date.now() - startedAt, true);
1633
+ spool.finalize();
1634
+ emitCompletedOnce(isAbort ? 124 : 1, child.pid, isAbort ? "ABORT" : void 0);
1635
+ finish({
1636
+ command: cmd,
1637
+ args,
1638
+ stdout: normalizeCommandOutput(stdout),
1639
+ stderr: stderrText,
1640
+ exitCode: isAbort ? 124 : 1,
1641
+ truncated: Buffer.byteLength(stdout, "utf8") > COMMAND_OUTPUT_MAX_BYTES,
1642
+ allowed: true,
1643
+ danger
1644
+ });
1645
+ });
1646
+ const registry = getProcessRegistry();
1647
+ const pid = child.pid;
1648
+ if (typeof pid === "number") {
1649
+ const fullCommand = `${cmd} ${args.join(" ")}`;
1650
+ registry.register({
1651
+ pid,
1652
+ name: "exec",
1653
+ command: redactCommand(fullCommand),
1654
+ startedAt: Date.now(),
1655
+ sessionId,
1656
+ child
1657
+ });
1658
+ }
1659
+ const timer = setTimeout(() => {
1660
+ killed = true;
1661
+ timedOut = true;
1662
+ if (typeof pid === "number") registry.kill(pid);
1663
+ else child.kill("SIGTERM");
1664
+ }, timeout);
1665
+ const onAbort = () => {
1666
+ killed = true;
1667
+ if (typeof pid === "number") registry.kill(pid, { force: true });
1668
+ else child.kill("SIGTERM");
1669
+ };
1670
+ if (isWin2) {
1671
+ if (signal.aborted) onAbort();
1672
+ else signal.addEventListener("abort", onAbort, { once: true });
1673
+ }
1674
+ child.stdout?.on("data", (chunk) => {
1675
+ const text = chunk.toString();
1676
+ stdoutBytes += chunk.byteLength;
1677
+ emitProcessOutput({ pid, stream: "stdout", chunk });
1678
+ if (stdout.length < MAX_OUTPUT) stdout += text;
1679
+ spool.write(text);
1680
+ });
1681
+ child.stderr?.on("data", (chunk) => {
1682
+ const text = chunk.toString();
1683
+ stderrBytes += chunk.byteLength;
1684
+ emitProcessOutput({ pid, stream: "stderr", chunk });
1685
+ if (stderr.length < MAX_OUTPUT) stderr += text;
1686
+ spool.write(text);
1687
+ });
1688
+ child.on("close", (code) => {
1689
+ clearTimeout(timer);
1690
+ if (isWin2) signal.removeEventListener("abort", onAbort);
1691
+ if (typeof pid === "number") registry.unregister(pid);
1692
+ const durationMs = Date.now() - startedAt;
1693
+ const exitCode = killed ? 124 : code ?? 1;
1694
+ emitCompletedOnce(exitCode, pid);
1695
+ registry.afterCall(durationMs, exitCode !== 0);
1696
+ const spooled = spool.finalize();
1697
+ finish({
1698
+ command: cmd,
1699
+ args,
1700
+ stdout: normalizeCommandOutput(stdout) + (spooled ? spoolNote(spooled) : ""),
1701
+ stderr: normalizeCommandOutput(stderr),
1702
+ exitCode,
1703
+ truncated: Buffer.byteLength(stdout, "utf8") > COMMAND_OUTPUT_MAX_BYTES || Buffer.byteLength(stderr, "utf8") > COMMAND_OUTPUT_MAX_BYTES,
1704
+ allowed: true,
1705
+ danger
1706
+ });
1707
+ });
1708
+ });
1709
+ }
1710
+
1711
+ export {
1712
+ detectDanger,
1713
+ checkExecKillCommand,
1714
+ configureExecPolicy,
1715
+ resetExecPolicy,
1716
+ configureDangerBypass,
1717
+ resetDangerBypass,
1718
+ getDangerBypass,
1719
+ isExecCommandAllowed,
1720
+ getExecAllowlist,
1721
+ execTool
1722
+ };
1723
+ //# sourceMappingURL=chunk-HXSBQ2SE.js.map