@wrongstack/tools 0.310.0 → 0.313.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/_shell-pick.d.ts +5 -10
- package/dist/bash.js +184 -208
- package/dist/builtin.d.ts +17 -14
- package/dist/builtin.js +157 -174
- package/dist/index.js +157 -174
- package/dist/pack.js +157 -174
- package/dist/tool-tier.js +157 -174
- package/package.json +5 -5
package/dist/tool-tier.js
CHANGED
|
@@ -9207,8 +9207,128 @@ import { buildChildEnv as buildChildEnv2 } from "@wrongstack/core/utils";
|
|
|
9207
9207
|
|
|
9208
9208
|
// src/bash.ts
|
|
9209
9209
|
init_output_spool();
|
|
9210
|
+
|
|
9211
|
+
// src/_shell-pick.ts
|
|
9212
|
+
var POSIX_DEFAULT = "cmd";
|
|
9213
|
+
function pickShell(platform6, command, env) {
|
|
9214
|
+
if (platform6 !== "win32") return POSIX_DEFAULT;
|
|
9215
|
+
const override = env.get("WRONGSTACK_SHELL")?.trim().toLowerCase();
|
|
9216
|
+
if (override === "cmd" || override === "cmd.exe") return "cmd";
|
|
9217
|
+
if (override === "powershell" || override === "powershell.exe") return "powershell";
|
|
9218
|
+
if (override === "pwsh" || override === "pwsh.exe") return "pwsh";
|
|
9219
|
+
if (looksLikePowerShell(command)) return "pwsh";
|
|
9220
|
+
return "cmd";
|
|
9221
|
+
}
|
|
9222
|
+
function looksLikePowerShell(command) {
|
|
9223
|
+
if (!command) return false;
|
|
9224
|
+
const trimmed = command.trimStart();
|
|
9225
|
+
if (/\.ps1\b/i.test(trimmed)) return true;
|
|
9226
|
+
if (/^\s*#requires\s/i.test(trimmed)) return true;
|
|
9227
|
+
if (/^\s*param\s*\(/i.test(trimmed)) return true;
|
|
9228
|
+
if (/\$[\w:{]/i.test(trimmed)) return true;
|
|
9229
|
+
if (/\$\(/.test(trimmed)) return true;
|
|
9230
|
+
if (/@\s*['"]/.test(trimmed)) return true;
|
|
9231
|
+
if (/&\s+\$/.test(trimmed)) return true;
|
|
9232
|
+
if (/(^|\s)@\s*\(/.test(trimmed)) return true;
|
|
9233
|
+
if (/(^|\s)@\{/.test(trimmed)) return true;
|
|
9234
|
+
if (/(?:^|[\s[({,;])(?:-eq|-ne|-lt|-gt|-le|-ge|-like|-notlike|-match|-notmatch|-contains|-notcontains|-in|-notin|-and|-or|-not|-band|-bor|-bxor|-replace|-isplit|-csplit|-osplit|-join|-is|-as|-f)(?:$|[\s\])},;])/i.test(
|
|
9235
|
+
trimmed
|
|
9236
|
+
)) {
|
|
9237
|
+
return true;
|
|
9238
|
+
}
|
|
9239
|
+
if (PS_VERB_RE.test(trimmed)) return true;
|
|
9240
|
+
if (/(?:^|[\s;&|])(gci|gi|gp|gcm|gps)\b/i.test(trimmed)) {
|
|
9241
|
+
return true;
|
|
9242
|
+
}
|
|
9243
|
+
if (looksLikePowerShellExtended(command)) return true;
|
|
9244
|
+
return false;
|
|
9245
|
+
}
|
|
9246
|
+
function looksLikePowerShellExtended(command) {
|
|
9247
|
+
if (!command) return false;
|
|
9248
|
+
const trimmed = command.trimStart();
|
|
9249
|
+
if (/(?:^|\s)[-/](?:WhatIf|Confirm|ErrorAction)(?::[^\s]+|\s|=|$)/i.test(trimmed)) {
|
|
9250
|
+
return true;
|
|
9251
|
+
}
|
|
9252
|
+
if (/(?:^|[\s;&|])(Where-Object|ForEach-Object|Select-Object|Sort-Object|Group-Object|Measure-Object|Compare-Object|Tee-Object)(?:\s|$)/i.test(
|
|
9253
|
+
trimmed
|
|
9254
|
+
)) {
|
|
9255
|
+
return true;
|
|
9256
|
+
}
|
|
9257
|
+
if (/\bWrite-(?:Host|Output|Error|Warning|Verbose|Debug|Information)(?:\s|$)/i.test(trimmed)) {
|
|
9258
|
+
return true;
|
|
9259
|
+
}
|
|
9260
|
+
if (/HK(?:LM|CU|CR|U|CC|DD|PD):\\/i.test(trimmed)) return true;
|
|
9261
|
+
if (/\[(?:string|int|bool|xml|double|float|decimal|char|byte|long|System\.)/i.test(trimmed)) {
|
|
9262
|
+
return true;
|
|
9263
|
+
}
|
|
9264
|
+
if (/^\s*<#|#>\s*$/m.test(trimmed)) return true;
|
|
9265
|
+
if (/(?:^|\s)[-//](?:AsPlainText|PipelineVariable|pv|FilterHashtable|OutVariable|ov)(?:\s|=|$)/i.test(
|
|
9266
|
+
trimmed
|
|
9267
|
+
)) {
|
|
9268
|
+
return true;
|
|
9269
|
+
}
|
|
9270
|
+
return false;
|
|
9271
|
+
}
|
|
9272
|
+
function wrapPowerShellScript(command) {
|
|
9273
|
+
const bootstrap = "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8;$ConfirmPreference='None';$WhatIfPreference=$false";
|
|
9274
|
+
return bootstrap + "\n$ErrorActionPreference='Stop'\n" + command + "\nif ($LASTEXITCODE -is [int]) { exit $LASTEXITCODE }";
|
|
9275
|
+
}
|
|
9276
|
+
var PS_VERB_RE = new RegExp(
|
|
9277
|
+
// Boundaries: start-of-string, whitespace, `;`, `&`, `|`, `(`, `{`, `,`.
|
|
9278
|
+
"(?:^|[\\s;&|\\(\\{,])(?:Get|Set|New|Remove|Add|Clear|Copy|Move|Rename|Test|Update|Write|Read|Push|Pop|Invoke|Start|Stop|Wait|Out|Format|Group|Measure|Compare|Resolve|ConvertTo|ConvertFrom|Convert|Import|Export|Select|Where|ForEach|Sort|Tee|Split|Join|Limit|Skip|Step|Trace|Debug|Register|Unregister|Enable|Disable|Restart|Suspend|Resume|Save|Open|Close|Lock|Unlock|Mount|Dismount|Enter|Exit|Use|Show|Hide|Find|Search|Watch|Initialize|Optimize|Compress|Expand|Merge|Checkpoint|Undo|Redo|Approve|Deny|Block|Grant|Revoke|Assert|Confirm|Receive|Send|Connect|Disconnect|Reset|Backup|Restore|Publish|Unpublish|Install|Uninstall|Build|Rebuild|Deploy|Submit|Process|Complete|Approve|Revoke|Pay|Refund|Decline|Receive|Send)-[A-Za-z][A-Za-z0-9]+(?:[\\-\\+][A-Za-z][A-Za-z0-9]+)*(?:$|[\\s\\-\\;\\&\\|\\(\\)\\{\\},])",
|
|
9279
|
+
"i"
|
|
9280
|
+
);
|
|
9281
|
+
function shellArgs(shell) {
|
|
9282
|
+
if (shell === "powershell" || shell === "pwsh") {
|
|
9283
|
+
return ["-NoLogo", "-NoProfile", "-NonInteractive", "-EncodedCommand"];
|
|
9284
|
+
}
|
|
9285
|
+
return ["/c"];
|
|
9286
|
+
}
|
|
9287
|
+
function diagnoseBashism(command, shell) {
|
|
9288
|
+
if (!command) return void 0;
|
|
9289
|
+
const isCmd = shell === "cmd";
|
|
9290
|
+
const hints = [];
|
|
9291
|
+
const add = (h) => {
|
|
9292
|
+
if (!hints.includes(h)) hints.push(h);
|
|
9293
|
+
};
|
|
9294
|
+
if (/\/dev\/null/.test(command)) {
|
|
9295
|
+
add(
|
|
9296
|
+
isCmd ? "use `nul` instead of `/dev/null` (e.g. `2>nul`)" : "use `$null` instead of `/dev/null` (e.g. `2>$null`)"
|
|
9297
|
+
);
|
|
9298
|
+
}
|
|
9299
|
+
if (/(^|[;&|]\s*)export\s+[A-Za-z_]\w*=/.test(command)) {
|
|
9300
|
+
add(
|
|
9301
|
+
isCmd ? "set env vars with `set NAME=value`, not `export`" : "set env vars with `$env:NAME = 'value'`, not `export`"
|
|
9302
|
+
);
|
|
9303
|
+
}
|
|
9304
|
+
if (/<<-?\s*['"]?[A-Za-z_]\w*/.test(command)) {
|
|
9305
|
+
add(
|
|
9306
|
+
isCmd ? "cmd has no heredocs \u2014 write the content to a file or use multiple `echo` lines" : "PowerShell has no heredocs \u2014 use a single-quoted here-string `@'\u2026'@` (closing `'@` at column 0)"
|
|
9307
|
+
);
|
|
9308
|
+
}
|
|
9309
|
+
if (shell === "powershell" && /(&&|\|\|)/.test(command)) {
|
|
9310
|
+
add(
|
|
9311
|
+
"Windows PowerShell 5.1 has no `&&`/`||` \u2014 separate commands with `;` (check `$LASTEXITCODE`)"
|
|
9312
|
+
);
|
|
9313
|
+
}
|
|
9314
|
+
if (/\brm\s+-[A-Za-z]*[rf]/.test(command)) {
|
|
9315
|
+
add(
|
|
9316
|
+
isCmd ? "`rm` is not a cmd builtin \u2014 use `del` (files) or `rmdir /s /q` (dirs)" : "use `Remove-Item -Recurse -Force` \u2014 the `rm -rf` bash flags don't exist in PowerShell"
|
|
9317
|
+
);
|
|
9318
|
+
}
|
|
9319
|
+
if (/\bwhich\s+\S/.test(command)) {
|
|
9320
|
+
add(
|
|
9321
|
+
isCmd ? "use `where <cmd>` instead of `which`" : "use `Get-Command <cmd>` instead of `which`"
|
|
9322
|
+
);
|
|
9323
|
+
}
|
|
9324
|
+
if (hints.length === 0) return void 0;
|
|
9325
|
+
const label = isCmd ? "cmd.exe" : shell === "pwsh" ? "PowerShell 7" : "Windows PowerShell";
|
|
9326
|
+
return `[wrongstack] This command failed and contains bash/POSIX syntax that ${label} does not accept \u2014 ${hints.join("; ")}. Rewrite it in ${isCmd ? "cmd" : "PowerShell"} syntax and retry.`;
|
|
9327
|
+
}
|
|
9328
|
+
|
|
9329
|
+
// src/bash.ts
|
|
9210
9330
|
init_util();
|
|
9211
|
-
|
|
9331
|
+
init_win32_resolve();
|
|
9212
9332
|
|
|
9213
9333
|
// src/bash-kill-guard.ts
|
|
9214
9334
|
import * as os3 from "node:os";
|
|
@@ -10049,126 +10169,8 @@ async function checkAndBlockKillCommand(command) {
|
|
|
10049
10169
|
return { blocked: false };
|
|
10050
10170
|
}
|
|
10051
10171
|
|
|
10052
|
-
// src/_shell-pick.ts
|
|
10053
|
-
var POSIX_DEFAULT = "cmd";
|
|
10054
|
-
function pickShell(platform6, command, env) {
|
|
10055
|
-
if (platform6 !== "win32") return POSIX_DEFAULT;
|
|
10056
|
-
const override = env.get("WRONGSTACK_SHELL")?.trim().toLowerCase();
|
|
10057
|
-
if (override === "cmd" || override === "cmd.exe") return "cmd";
|
|
10058
|
-
if (override === "powershell" || override === "powershell.exe") return "powershell";
|
|
10059
|
-
if (override === "pwsh" || override === "pwsh.exe") return "pwsh";
|
|
10060
|
-
if (looksLikePowerShell(command)) return "pwsh";
|
|
10061
|
-
return "cmd";
|
|
10062
|
-
}
|
|
10063
|
-
function looksLikePowerShell(command) {
|
|
10064
|
-
if (!command) return false;
|
|
10065
|
-
const trimmed = command.trimStart();
|
|
10066
|
-
if (/\.ps1\b/i.test(trimmed)) return true;
|
|
10067
|
-
if (/^\s*#requires\s/i.test(trimmed)) return true;
|
|
10068
|
-
if (/^\s*param\s*\(/i.test(trimmed)) return true;
|
|
10069
|
-
if (/\$[\w:{]/i.test(trimmed)) return true;
|
|
10070
|
-
if (/\$\(/.test(trimmed)) return true;
|
|
10071
|
-
if (/@\s*['"]/.test(trimmed)) return true;
|
|
10072
|
-
if (/&\s+\$/.test(trimmed)) return true;
|
|
10073
|
-
if (/(^|\s)@\s*\(/.test(trimmed)) return true;
|
|
10074
|
-
if (/(^|\s)@\{/.test(trimmed)) return true;
|
|
10075
|
-
if (/(?:^|[\s[({,;])(?:-eq|-ne|-lt|-gt|-le|-ge|-like|-notlike|-match|-notmatch|-contains|-notcontains|-in|-notin|-and|-or|-not|-band|-bor|-bxor|-replace|-isplit|-csplit|-osplit|-join|-is|-as|-f)(?:$|[\s\])},;])/i.test(
|
|
10076
|
-
trimmed
|
|
10077
|
-
)) {
|
|
10078
|
-
return true;
|
|
10079
|
-
}
|
|
10080
|
-
if (PS_VERB_RE.test(trimmed)) return true;
|
|
10081
|
-
if (/(?:^|[\s;&|])(gci|gi|gp|gcm|gps)\b/i.test(trimmed)) {
|
|
10082
|
-
return true;
|
|
10083
|
-
}
|
|
10084
|
-
if (looksLikePowerShellExtended(command)) return true;
|
|
10085
|
-
return false;
|
|
10086
|
-
}
|
|
10087
|
-
function looksLikePowerShellExtended(command) {
|
|
10088
|
-
if (!command) return false;
|
|
10089
|
-
const trimmed = command.trimStart();
|
|
10090
|
-
if (/(?:^|\s)[-/](?:WhatIf|Confirm|ErrorAction)(?::[^\s]+|\s|=|$)/i.test(trimmed)) {
|
|
10091
|
-
return true;
|
|
10092
|
-
}
|
|
10093
|
-
if (/(?:^|[\s;&|])(Where-Object|ForEach-Object|Select-Object|Sort-Object|Group-Object|Measure-Object|Compare-Object|Tee-Object)(?:\s|$)/i.test(
|
|
10094
|
-
trimmed
|
|
10095
|
-
)) {
|
|
10096
|
-
return true;
|
|
10097
|
-
}
|
|
10098
|
-
if (/\bWrite-(?:Host|Output|Error|Warning|Verbose|Debug|Information)(?:\s|$)/i.test(trimmed)) {
|
|
10099
|
-
return true;
|
|
10100
|
-
}
|
|
10101
|
-
if (/HK(?:LM|CU|CR|U|CC|DD|PD):\\/i.test(trimmed)) return true;
|
|
10102
|
-
if (/\[(?:string|int|bool|xml|double|float|decimal|char|byte|long|System\.)/i.test(trimmed)) {
|
|
10103
|
-
return true;
|
|
10104
|
-
}
|
|
10105
|
-
if (/^\s*<#|#>\s*$/m.test(trimmed)) return true;
|
|
10106
|
-
if (/(?:^|\s)[-//](?:AsPlainText|PipelineVariable|pv|FilterHashtable|OutVariable|ov)(?:\s|=|$)/i.test(
|
|
10107
|
-
trimmed
|
|
10108
|
-
)) {
|
|
10109
|
-
return true;
|
|
10110
|
-
}
|
|
10111
|
-
return false;
|
|
10112
|
-
}
|
|
10113
|
-
function wrapPowerShellScript(command) {
|
|
10114
|
-
const bootstrap = "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8;$ConfirmPreference='None';$WhatIfPreference=$false";
|
|
10115
|
-
return bootstrap + "\n$ErrorActionPreference='Stop'\n" + command + "\nif ($LASTEXITCODE -is [int]) { exit $LASTEXITCODE }";
|
|
10116
|
-
}
|
|
10117
|
-
var PS_VERB_RE = new RegExp(
|
|
10118
|
-
// Boundaries: start-of-string, whitespace, `;`, `&`, `|`, `(`, `{`, `,`.
|
|
10119
|
-
"(?:^|[\\s;&|\\(\\{,])(?:Get|Set|New|Remove|Add|Clear|Copy|Move|Rename|Test|Update|Write|Read|Push|Pop|Invoke|Start|Stop|Wait|Out|Format|Group|Measure|Compare|Resolve|ConvertTo|ConvertFrom|Convert|Import|Export|Select|Where|ForEach|Sort|Tee|Split|Join|Limit|Skip|Step|Trace|Debug|Register|Unregister|Enable|Disable|Restart|Suspend|Resume|Save|Open|Close|Lock|Unlock|Mount|Dismount|Enter|Exit|Use|Show|Hide|Find|Search|Watch|Initialize|Optimize|Compress|Expand|Merge|Checkpoint|Undo|Redo|Approve|Deny|Block|Grant|Revoke|Assert|Confirm|Receive|Send|Connect|Disconnect|Reset|Backup|Restore|Publish|Unpublish|Install|Uninstall|Build|Rebuild|Deploy|Submit|Process|Complete|Approve|Revoke|Pay|Refund|Decline|Receive|Send)-[A-Za-z][A-Za-z0-9]+(?:[\\-\\+][A-Za-z][A-Za-z0-9]+)*(?:$|[\\s\\-\\;\\&\\|\\(\\)\\{\\},])",
|
|
10120
|
-
"i"
|
|
10121
|
-
);
|
|
10122
|
-
function shellArgs(shell) {
|
|
10123
|
-
if (shell === "powershell" || shell === "pwsh") {
|
|
10124
|
-
return ["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", "-"];
|
|
10125
|
-
}
|
|
10126
|
-
return ["/c"];
|
|
10127
|
-
}
|
|
10128
|
-
function diagnoseBashism(command, shell) {
|
|
10129
|
-
if (!command) return void 0;
|
|
10130
|
-
const isCmd = shell === "cmd";
|
|
10131
|
-
const hints = [];
|
|
10132
|
-
const add = (h) => {
|
|
10133
|
-
if (!hints.includes(h)) hints.push(h);
|
|
10134
|
-
};
|
|
10135
|
-
if (/\/dev\/null/.test(command)) {
|
|
10136
|
-
add(
|
|
10137
|
-
isCmd ? "use `nul` instead of `/dev/null` (e.g. `2>nul`)" : "use `$null` instead of `/dev/null` (e.g. `2>$null`)"
|
|
10138
|
-
);
|
|
10139
|
-
}
|
|
10140
|
-
if (/(^|[;&|]\s*)export\s+[A-Za-z_]\w*=/.test(command)) {
|
|
10141
|
-
add(
|
|
10142
|
-
isCmd ? "set env vars with `set NAME=value`, not `export`" : "set env vars with `$env:NAME = 'value'`, not `export`"
|
|
10143
|
-
);
|
|
10144
|
-
}
|
|
10145
|
-
if (/<<-?\s*['"]?[A-Za-z_]\w*/.test(command)) {
|
|
10146
|
-
add(
|
|
10147
|
-
isCmd ? "cmd has no heredocs \u2014 write the content to a file or use multiple `echo` lines" : "PowerShell has no heredocs \u2014 use a single-quoted here-string `@'\u2026'@` (closing `'@` at column 0)"
|
|
10148
|
-
);
|
|
10149
|
-
}
|
|
10150
|
-
if (shell === "powershell" && /(&&|\|\|)/.test(command)) {
|
|
10151
|
-
add(
|
|
10152
|
-
"Windows PowerShell 5.1 has no `&&`/`||` \u2014 separate commands with `;` (check `$LASTEXITCODE`)"
|
|
10153
|
-
);
|
|
10154
|
-
}
|
|
10155
|
-
if (/\brm\s+-[A-Za-z]*[rf]/.test(command)) {
|
|
10156
|
-
add(
|
|
10157
|
-
isCmd ? "`rm` is not a cmd builtin \u2014 use `del` (files) or `rmdir /s /q` (dirs)" : "use `Remove-Item -Recurse -Force` \u2014 the `rm -rf` bash flags don't exist in PowerShell"
|
|
10158
|
-
);
|
|
10159
|
-
}
|
|
10160
|
-
if (/\bwhich\s+\S/.test(command)) {
|
|
10161
|
-
add(
|
|
10162
|
-
isCmd ? "use `where <cmd>` instead of `which`" : "use `Get-Command <cmd>` instead of `which`"
|
|
10163
|
-
);
|
|
10164
|
-
}
|
|
10165
|
-
if (hints.length === 0) return void 0;
|
|
10166
|
-
const label = isCmd ? "cmd.exe" : shell === "pwsh" ? "PowerShell 7" : "Windows PowerShell";
|
|
10167
|
-
return `[wrongstack] This command failed and contains bash/POSIX syntax that ${label} does not accept \u2014 ${hints.join("; ")}. Rewrite it in ${isCmd ? "cmd" : "PowerShell"} syntax and retry.`;
|
|
10168
|
-
}
|
|
10169
|
-
|
|
10170
10172
|
// src/bash.ts
|
|
10171
|
-
|
|
10173
|
+
init_process_registry();
|
|
10172
10174
|
var MAX_OUTPUT = 32768;
|
|
10173
10175
|
var DEFAULT_TIMEOUT_MS2 = 3e5;
|
|
10174
10176
|
var STREAM_FLUSH_INTERVAL_MS = 200;
|
|
@@ -10276,8 +10278,7 @@ var bashTool = {
|
|
|
10276
10278
|
plan = {
|
|
10277
10279
|
bin,
|
|
10278
10280
|
argv: shellArgs(shell2),
|
|
10279
|
-
|
|
10280
|
-
stdinBody: shell2 === "powershell" || shell2 === "pwsh" ? wrapPowerShellScript(input.command) : void 0
|
|
10281
|
+
commandArg: shell2 === "powershell" || shell2 === "pwsh" ? Buffer.from(wrapPowerShellScript(input.command), "utf16le").toString("base64") : input.command
|
|
10281
10282
|
};
|
|
10282
10283
|
} else {
|
|
10283
10284
|
const explicit = process.env["WRONGSTACK_SHELL"];
|
|
@@ -10291,10 +10292,10 @@ var bashTool = {
|
|
|
10291
10292
|
else bin = "/bin/bash";
|
|
10292
10293
|
} else bin = "/bin/bash";
|
|
10293
10294
|
}
|
|
10294
|
-
plan = { bin, argv: ["-c"],
|
|
10295
|
+
plan = { bin, argv: ["-c"], commandArg: input.command };
|
|
10295
10296
|
}
|
|
10296
10297
|
const shell = plan.bin;
|
|
10297
|
-
const args =
|
|
10298
|
+
const args = [...plan.argv, plan.commandArg];
|
|
10298
10299
|
const env = buildChildEnv2(ctx.session?.id);
|
|
10299
10300
|
const spawnCwd = ctx.workingDir ?? ctx.projectRoot;
|
|
10300
10301
|
const detached = !isWin5;
|
|
@@ -10303,26 +10304,10 @@ var bashTool = {
|
|
|
10303
10304
|
const child2 = spawn3(shell, args, {
|
|
10304
10305
|
cwd: spawnCwd,
|
|
10305
10306
|
env,
|
|
10306
|
-
|
|
10307
|
-
// and POSIX shells ignore stdin when given the command inline.
|
|
10308
|
-
stdio: [plan.useStdin ? "pipe" : "ignore", "ignore", "ignore"],
|
|
10309
|
-
// win32: CreateProcess IGNORES CREATE_NO_WINDOW (windowsHide) when
|
|
10310
|
-
// DETACHED_PROCESS (detached: true) is set, so the console-less
|
|
10311
|
-
// cmd.exe's grandchildren (node, dev servers) each allocate a fresh
|
|
10312
|
-
// VISIBLE console window. detached: false lets CREATE_NO_WINDOW
|
|
10313
|
-
// apply: the child gets a hidden console that grandchildren inherit.
|
|
10314
|
-
// Windows children survive parent exit either way. POSIX keeps
|
|
10315
|
-
// detached for the process-group kill semantics.
|
|
10307
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
10316
10308
|
detached: !isWin5,
|
|
10317
10309
|
windowsHide: true
|
|
10318
10310
|
});
|
|
10319
|
-
if (plan.useStdin) {
|
|
10320
|
-
try {
|
|
10321
|
-
child2.stdin?.write(plan.stdinBody ?? input.command);
|
|
10322
|
-
child2.stdin?.end();
|
|
10323
|
-
} catch {
|
|
10324
|
-
}
|
|
10325
|
-
}
|
|
10326
10311
|
const pid2 = child2.pid;
|
|
10327
10312
|
const stdoutBytes2 = 0;
|
|
10328
10313
|
const stderrBytes2 = 0;
|
|
@@ -10397,20 +10382,11 @@ var bashTool = {
|
|
|
10397
10382
|
const child = spawn3(shell, args, {
|
|
10398
10383
|
cwd: spawnCwd,
|
|
10399
10384
|
env,
|
|
10400
|
-
|
|
10401
|
-
// and POSIX shells ignore stdin when given the command inline.
|
|
10402
|
-
stdio: [plan.useStdin ? "pipe" : "ignore", "pipe", "pipe"],
|
|
10385
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
10403
10386
|
detached,
|
|
10404
10387
|
windowsHide: true,
|
|
10405
10388
|
...isWin5 ? {} : { signal: opts.signal }
|
|
10406
10389
|
});
|
|
10407
|
-
if (plan.useStdin) {
|
|
10408
|
-
try {
|
|
10409
|
-
child.stdin?.write(plan.stdinBody ?? input.command);
|
|
10410
|
-
child.stdin?.end();
|
|
10411
|
-
} catch {
|
|
10412
|
-
}
|
|
10413
|
-
}
|
|
10414
10390
|
const pid = child.pid;
|
|
10415
10391
|
let stdoutBytes = 0;
|
|
10416
10392
|
let stderrBytes = 0;
|
|
@@ -30417,8 +30393,8 @@ import {
|
|
|
30417
30393
|
} from "@wrongstack/core/observability";
|
|
30418
30394
|
init_output_spool();
|
|
30419
30395
|
init_util();
|
|
30420
|
-
init_process_registry();
|
|
30421
30396
|
init_win32_resolve();
|
|
30397
|
+
init_process_registry();
|
|
30422
30398
|
var MAX_OUTPUT4 = 32768;
|
|
30423
30399
|
var DEFAULT_TIMEOUT_MS4 = 3e5;
|
|
30424
30400
|
var STREAM_FLUSH_INTERVAL_MS2 = 200;
|
|
@@ -30528,15 +30504,14 @@ var pwshTool = {
|
|
|
30528
30504
|
}
|
|
30529
30505
|
const isWin5 = os11.platform() === "win32";
|
|
30530
30506
|
const bin = isWin5 ? resolvePowerShell("pwsh.exe") : "pwsh";
|
|
30531
|
-
const
|
|
30532
|
-
|
|
30507
|
+
const encodedCommand = Buffer.from(wrapPwshCommand(input.command), "utf16le").toString(
|
|
30508
|
+
"base64"
|
|
30509
|
+
);
|
|
30510
|
+
const args = [...shellArgs("pwsh"), encodedCommand];
|
|
30533
30511
|
const env = buildChildEnv2(ctx.session?.id);
|
|
30534
30512
|
let targetCwd;
|
|
30535
30513
|
try {
|
|
30536
|
-
targetCwd = await safeResolveReal(
|
|
30537
|
-
input.workdir ?? ctx.workingDir ?? ctx.projectRoot,
|
|
30538
|
-
ctx
|
|
30539
|
-
);
|
|
30514
|
+
targetCwd = await safeResolveReal(input.workdir ?? ctx.workingDir ?? ctx.projectRoot, ctx);
|
|
30540
30515
|
} catch (err) {
|
|
30541
30516
|
yield {
|
|
30542
30517
|
type: "final",
|
|
@@ -30557,13 +30532,9 @@ var pwshTool = {
|
|
|
30557
30532
|
cwd: targetCwd,
|
|
30558
30533
|
env,
|
|
30559
30534
|
detached,
|
|
30560
|
-
stdio: ["
|
|
30535
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
30561
30536
|
windowsHide: true
|
|
30562
30537
|
});
|
|
30563
|
-
if (child2.stdin) {
|
|
30564
|
-
child2.stdin.write(stdinBody);
|
|
30565
|
-
child2.stdin.end();
|
|
30566
|
-
}
|
|
30567
30538
|
const pid2 = child2.pid;
|
|
30568
30539
|
if (typeof pid2 === "number") {
|
|
30569
30540
|
registry.register({
|
|
@@ -30621,7 +30592,7 @@ Working directory: ${targetCwd}`,
|
|
|
30621
30592
|
cwd: targetCwd,
|
|
30622
30593
|
env,
|
|
30623
30594
|
detached,
|
|
30624
|
-
stdio: ["
|
|
30595
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
30625
30596
|
windowsHide: true
|
|
30626
30597
|
});
|
|
30627
30598
|
const pid = child.pid;
|
|
@@ -30662,14 +30633,7 @@ Working directory: ${targetCwd}`,
|
|
|
30662
30633
|
processGroupLeader: detached && child.pid === pid
|
|
30663
30634
|
});
|
|
30664
30635
|
}
|
|
30665
|
-
|
|
30666
|
-
child.stdin.write(stdinBody);
|
|
30667
|
-
child.stdin.end();
|
|
30668
|
-
}
|
|
30669
|
-
const timeoutMs = Math.min(
|
|
30670
|
-
Math.max(1e3, input.timeout_ms ?? DEFAULT_TIMEOUT_MS4),
|
|
30671
|
-
6e5
|
|
30672
|
-
);
|
|
30636
|
+
const timeoutMs = Math.min(Math.max(1e3, input.timeout_ms ?? DEFAULT_TIMEOUT_MS4), 6e5);
|
|
30673
30637
|
let timedOut = false;
|
|
30674
30638
|
const timers = [];
|
|
30675
30639
|
const killWithTimeout = (timeout) => {
|
|
@@ -30679,7 +30643,17 @@ Working directory: ${targetCwd}`,
|
|
|
30679
30643
|
if (!attempted) {
|
|
30680
30644
|
try {
|
|
30681
30645
|
child.kill();
|
|
30682
|
-
} catch {
|
|
30646
|
+
} catch (err) {
|
|
30647
|
+
console.log(
|
|
30648
|
+
JSON.stringify({
|
|
30649
|
+
level: "warn",
|
|
30650
|
+
event: "pwsh.kill_fallback_failed",
|
|
30651
|
+
pid: child.pid,
|
|
30652
|
+
platform: process.platform,
|
|
30653
|
+
error: err instanceof Error ? err.message : String(err),
|
|
30654
|
+
message: "pwsh child.kill() raised after the registry kill failed; process may be leaked"
|
|
30655
|
+
})
|
|
30656
|
+
);
|
|
30683
30657
|
}
|
|
30684
30658
|
}
|
|
30685
30659
|
}
|
|
@@ -30690,7 +30664,16 @@ Working directory: ${targetCwd}`,
|
|
|
30690
30664
|
} else {
|
|
30691
30665
|
try {
|
|
30692
30666
|
child.kill("SIGTERM");
|
|
30693
|
-
} catch {
|
|
30667
|
+
} catch (err) {
|
|
30668
|
+
console.log(
|
|
30669
|
+
JSON.stringify({
|
|
30670
|
+
level: "warn",
|
|
30671
|
+
event: "pwsh.sigterm_failed",
|
|
30672
|
+
platform: process.platform,
|
|
30673
|
+
error: err instanceof Error ? err.message : String(err),
|
|
30674
|
+
message: 'pwsh child.kill("SIGTERM") raised on POSIX fallback; process may be leaked'
|
|
30675
|
+
})
|
|
30676
|
+
);
|
|
30694
30677
|
}
|
|
30695
30678
|
}
|
|
30696
30679
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wrongstack/tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.313.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "WrongStack built-in tools: read/write/edit, bash/exec, grep/glob, git, fetch, test, lint, and more.",
|
|
6
6
|
"repository": {
|
|
@@ -253,10 +253,10 @@
|
|
|
253
253
|
"turndown": "^7.2.4",
|
|
254
254
|
"undici": "^8.10.0",
|
|
255
255
|
"web-tree-sitter": "0.26.12",
|
|
256
|
-
"@wrongstack/
|
|
257
|
-
"@wrongstack/
|
|
258
|
-
"@wrongstack/primitives": "0.
|
|
259
|
-
"@wrongstack/persistence": "0.
|
|
256
|
+
"@wrongstack/kanban": "0.313.0",
|
|
257
|
+
"@wrongstack/core": "0.313.0",
|
|
258
|
+
"@wrongstack/primitives": "0.313.0",
|
|
259
|
+
"@wrongstack/persistence": "0.313.0"
|
|
260
260
|
},
|
|
261
261
|
"devDependencies": {
|
|
262
262
|
"@types/node": "^26.2.0",
|