@hncode/hncode 0.7.8 → 0.8.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/src/text.js ADDED
@@ -0,0 +1,149 @@
1
+ // Text measurement, colouring and wrapping.
2
+ //
3
+ // These are the leaves of the renderer: they take a string and some numbers and return a string. Nothing here knows
4
+ // what a transcript is, so the same helpers serve a chat row, a popup and the composer.
5
+
6
+ import { C } from './colors.js';
7
+ import { visualWidth, expandTabs } from './term.js';
8
+
9
+ // The ESC byte, as its own string. Every escape scan starts by comparing against this rather than writing '\x1b',
10
+ // which keeps the regexes and the string walks recognisably the same test.
11
+ export const ESC = '\x1b';
12
+
13
+ export { expandTabs };
14
+
15
+ export function stripAnsi(s) {
16
+ return String(s)
17
+ .replace(/\x1b\[[0-9;?]*[a-zA-Z]/g, '')
18
+ .replace(/\x1b\[[0-9;?]* [a-zA-Z]/g, '')
19
+ .replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g, '');
20
+ }
21
+
22
+ // Make UNTRUSTED text safe to paint: file contents from Read, command output from Bash, diff bodies, tool arguments.
23
+ //
24
+ // The goal is to keep the content as ORIGINAL as possible while stopping the terminal from OBEYING it. Only the ESC
25
+ // byte is rewritten — every following byte (the `[31m`, the `[10;20H` parameters) is shown verbatim, so nothing is
26
+ // lost:
27
+ //
28
+ // file contains: ESC [ 3 1 m E R R O R ESC [ 0 m
29
+ // screen shows : ^[ [ 3 1 m E R R O R ^[ [ 0 m
30
+ //
31
+ // A terminal cannot act on a sequence whose ESC has been split into `^[`, so `ESC[31m` no longer recolours half the
32
+ // transcript, `ESC[0m` no longer resets the row mid-line, and `ESC[10;20H` no longer moves the cursor.
33
+ //
34
+ // `^[` is the convention `cat -v`, `less` and `bat` use for ESC, so it reads as "there is an escape here" rather
35
+ // than as content.
36
+ export function sanitizeText(s) {
37
+ return String(s == null ? '' : s)
38
+ .replace(/\x1b/g, '^[')
39
+ .replace(/\x07/g, '^G')
40
+ .replace(/\x08/g, '^H')
41
+ .replace(/[\x0b\x0c]/g, ' ')
42
+ .replace(/[\x00-\x06\x0e-\x1f\x7f]/g, '');
43
+ }
44
+
45
+ /**
46
+ * How much of a running command's output to KEEP, not just display.
47
+ *
48
+ * This string is mirrored into the hub row (and so into the SSE patch the browser applies on every frame), which
49
+ * means an unbounded buffer grows the terminal's row, the hub's row and the browser's copy at the same time. Only
50
+ * the tail is ever drawn, so only the tail is worth holding.
51
+ */
52
+ export const LIVE_OUTPUT_MAX_CHARS = 64 * 1024;
53
+
54
+ /** The last `max` CHARACTERS of `s`, cut on a line boundary so the tail never starts mid-line. */
55
+ export function tailChars(s, max) {
56
+ const str = String(s == null ? '' : s);
57
+ if (str.length <= max) return str;
58
+ const cut = str.slice(str.length - max);
59
+ const nl = cut.indexOf('\n');
60
+ return nl >= 0 ? cut.slice(nl + 1) : cut;
61
+ }
62
+
63
+ /** Visible width of a string that may carry ANSI escapes. */
64
+ export function visualCol(s) { return visualWidth(stripAnsi(String(s))); }
65
+
66
+ /** Wrap `text` in colour `c`, closing with a full reset. */
67
+ export function col(text, c) { return c + String(text) + C.reset; }
68
+
69
+ /**
70
+ * Pad or truncate to exactly `w` VISIBLE columns, carrying escapes through untouched.
71
+ *
72
+ * Padding is what makes a row's background reach the edge; truncation keeps a long line from wrapping and pushing
73
+ * the layout down a row.
74
+ */
75
+ export function fitAnsi(s, w) {
76
+ const str = String(s);
77
+ const v = visualCol(str);
78
+ if (v < w) return str + ' '.repeat(w - v);
79
+ if (v === w) return str;
80
+ let out = '';
81
+ let n = 0;
82
+ let i = 0;
83
+ while (i < str.length) {
84
+ if (str[i] === ESC) {
85
+ const m = /^\x1b\[[0-9;?]*[a-zA-Z]/.exec(str.slice(i))
86
+ || /^\x1b\[[0-9;?]* [a-zA-Z]/.exec(str.slice(i))
87
+ || /^\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/.exec(str.slice(i));
88
+ if (m) { out += m[0]; i += m[0].length; continue; }
89
+ }
90
+ const cp = str.codePointAt(i);
91
+ const ch = String.fromCodePoint(cp);
92
+ const cw = visualWidth(ch);
93
+ if (n + cw > w) break;
94
+ n += cw;
95
+ out += ch;
96
+ i += cp > 0xffff ? 2 : 1;
97
+ }
98
+ if (n < w) out += ' '.repeat(w - n);
99
+ return out;
100
+ }
101
+
102
+ /**
103
+ * Greedy word wrap to `width` VISIBLE columns.
104
+ *
105
+ * The running width is ACCUMULATED rather than re-measured. Recomputing `visualCol(line + ' ' + w)` per word is O(line)
106
+ * per word and therefore O(n²) per paragraph — a single long streamed paragraph cost ~46ms at 20KB and froze the UI on
107
+ * every markdown chunk. Widths are additive for the plain text this receives, because no ANSI is present until
108
+ * `inlineMarkdown` runs later.
109
+ *
110
+ * A word longer than the line is hard-split BY VISUAL COLUMNS, not by `.length`: CJK characters occupy two cells, so
111
+ * slicing by length emitted lines twice as wide as the box and let the terminal wrap them.
112
+ */
113
+ export function wrapWords(str, width) {
114
+ width = Math.max(1, width | 0);
115
+ const out = [];
116
+ let line = '';
117
+ let lineW = 0;
118
+ // Tabs are expanded first: `visualCol` counts '\t' as 0 columns while the terminal advances to the next stop, which
119
+ // made the row wider than computed and wrapped it onto the following line.
120
+ const words = expandTabs(str).split(' ');
121
+ for (const w of words) {
122
+ const wW = visualCol(w);
123
+ if (wW > width) {
124
+ if (line) { out.push(line); line = ''; lineW = 0; }
125
+ let chunk = '';
126
+ let cw = 0;
127
+ for (const ch of w) {
128
+ const chw = visualCol(ch);
129
+ if (cw + chw > width) { out.push(chunk); chunk = ''; cw = 0; }
130
+ chunk += ch; cw += chw;
131
+ }
132
+ if (chunk) { line = chunk; lineW = cw; }
133
+ continue;
134
+ }
135
+ const sep = line ? 1 : 0;
136
+ if (lineW + sep + wW <= width) {
137
+ line = line ? line + ' ' + w : w;
138
+ lineW += sep + wW;
139
+ } else {
140
+ if (line) out.push(line);
141
+ line = w;
142
+ lineW = wW;
143
+ }
144
+ }
145
+ if (line) out.push(line);
146
+ else if (out.length === 0) out.push('');
147
+ return out;
148
+ }
149
+
@@ -0,0 +1,193 @@
1
+ // The `Using Tool (arg)` row, and the colour a transcript row is drawn in.
2
+ //
3
+ // Both are pure: a message object in, an ANSI string out. Nothing here reads a session, which is what lets the tool
4
+ // line animate from a wall clock instead of from a render tick.
5
+
6
+ import { C } from './colors.js';
7
+ import { col, sanitizeText } from './text.js';
8
+ import { cycleMs, lightOrigin, shimmerText, TOOL_STEP_MS } from './animate.js';
9
+ import { fmtDuration } from './format.js';
10
+
11
+ /** The colour a transcript row is drawn in, by role. */
12
+ export function msgColorFor(role, text) {
13
+ // 'rich' output (e.g. /context, /usage panels) carries its OWN ANSI colours — do not wrap it in a single role colour,
14
+ // or the whole panel comes out one shade.
15
+ if (role === 'rich') return '';
16
+ if (role === 'system' && typeof text === 'string' && text.startsWith('[turn took')) return C.gray;
17
+ // System/status lines are NEUTRAL grey, not the brand teal: the deep teal showed up on every command result and
18
+ // one-line notice, and at that frequency it read as noise. Grey keeps them quiet; the accents stay for user, tool
19
+ // and working rows.
20
+ if (role === 'system') return C.gray;
21
+ if (role === 'user') return C.cyan;
22
+ if (role === 'bash') return C.shellMode; // ! shell-mode echo: violet
23
+ if (role === 'warn') return C.orange; // unfinished-turn warning
24
+ if (role === 'queued') return C.gray; // pending, not yet sent
25
+ if (role === 'steer') return C.yellow; // injected into the running turn
26
+ if (role === 'tool') return C.blue;
27
+ if (role === 'tool_result') return C.gray;
28
+ if (role === 'skill') return C.blue;
29
+ if (role === 'image') return C.gray; // the row names a file, it is not prose
30
+ return C.fg;
31
+ }
32
+
33
+ // Which argument best identifies a call, so a tool line reads `Using Read (src/tui.js)`.
34
+ const KEY_ARG = {
35
+ Bash: ['command'],
36
+ Read: ['path', 'file_path'],
37
+ Write: ['path', 'file_path'],
38
+ Edit: ['path', 'file_path'],
39
+ Grep: ['pattern'],
40
+ Glob: ['pattern'],
41
+ FileLines: ['path', 'file_path'],
42
+ FetchURL: ['url'],
43
+ WebSearch: ['query'],
44
+ Agent: ['description', 'prompt'],
45
+ TaskOutput: ['task_id'],
46
+ TaskStop: ['task_id'],
47
+ };
48
+
49
+ const MAX_ARG = 60;
50
+
51
+ /**
52
+ * The one argument worth showing next to a tool's name. `expanded` lifts the length cut.
53
+ *
54
+ * The cut exists so the single `● Used Bash (…)` row stays readable: a `node -e "…"` one-liner is routinely hundreds
55
+ * of characters, and printing it whole wrapped the row across the screen for every call. Ctrl+O is the escape hatch —
56
+ * whoever expands tool output to read it wants to see the command they are reading the output OF.
57
+ */
58
+ export function keyArgument(name, args, workspace, expanded = false) {
59
+ if (!args || typeof args !== 'object') return '';
60
+ const keys = KEY_ARG[name] || Object.keys(args);
61
+ // Expanded: the whole value, with newlines kept, so a multi-line script shows as the lines it was written as rather
62
+ // than being flattened to its first line.
63
+ if (expanded) {
64
+ for (const k of keys) {
65
+ const v = args[k];
66
+ if (typeof v !== 'string' || !v.length) continue;
67
+ const full = sanitizeText(v).replace(/\r\n/g, '\n');
68
+ return (k === 'path' || k === 'file_path') ? full.replace(/\\/g, '/') : full;
69
+ }
70
+ return '';
71
+ }
72
+ for (const k of keys) {
73
+ const v = args[k];
74
+ if (typeof v !== 'string' || !v.length) continue;
75
+ // Neutralise escapes BEFORE measuring: sanitizeText turns ESC into the two visible characters `^[`, so truncating
76
+ // first and sanitizing after made a long command come out wider than MAX_ARG — and a trailing ESC cut at the
77
+ // boundary left the row ending in a bare `^` instead of a proper `…`.
78
+ const valueLines = sanitizeText(v).replace(/\r\n/g, '\n').split('\n');
79
+ // A trailing blank line is not extra content: a command ending in a newline — how a heredoc is usually written —
80
+ // split into a final empty element, and counting it claimed `(+1 line)` for a command with no second line at all.
81
+ while (valueLines.length > 1 && valueLines[valueLines.length - 1].trim() === '') valueLines.pop();
82
+ let text = valueLines[0];
83
+ const rest = valueLines.length > 1 ? valueLines.length - 1 : 0;
84
+ if (text.length > MAX_ARG) {
85
+ text = (k === 'path' || k === 'file_path')
86
+ ? '…' + text.slice(text.length - (MAX_ARG - 1))
87
+ : text.slice(0, MAX_ARG - 1) + '…';
88
+ } else if (rest) {
89
+ // Make room for the marker before adding it, so the row never overflows: the count is dropped first because the
90
+ // ellipsis already carries the important half of the message.
91
+ const withCount = `… (+${rest} line${rest === 1 ? '' : 's'})`;
92
+ text += text.length + withCount.length <= MAX_ARG
93
+ ? withCount
94
+ : '…';
95
+ }
96
+ // Display paths with forward slashes (consistent across platforms).
97
+ if (k === 'path' || k === 'file_path') text = text.replace(/\\/g, '/');
98
+ return text;
99
+ }
100
+ return '';
101
+ }
102
+
103
+ /**
104
+ * The `● Using Name (arg)` row.
105
+ *
106
+ * A pending call's name carries a travelling light; a finished one is plain cyan. The light runs off a WALL CLOCK
107
+ * rather than the tick count: the spinner advances every 80ms while the render path redraws far more often, so a phase
108
+ * derived from the tick steps in 80ms jumps however often it is redrawn — which is the per-cell hopping this replaced.
109
+ */
110
+ export function formatToolLine(msg, workspace, spin, pulseStart, shimmerEdge, expanded = false, reducedMotion = false, width = 0) {
111
+ const name = msg.toolName || '';
112
+ const arg = keyArgument(name, msg.toolArgs, workspace, expanded);
113
+ const verb = msg.pending ? 'Using' : 'Used';
114
+ let nameDisplay;
115
+ if (msg.pending) {
116
+ // `??`, NOT `||`: tick 0 is a legitimate anchor at the START of a turn, and `0 || spin` would collapse the elapsed
117
+ // time to zero so the light never moved at all.
118
+ const anchorSpin = pulseStart ?? spin;
119
+ // THE KEY IS THE ROW'S OWN IDENTITY, and nothing else.
120
+ //
121
+ // It used to carry `anchorSpin` too, on the reasoning that the same message re-animated on a new tick should get a
122
+ // new origin. The opposite happened: when the caller passes no `pulseStart`, `anchorSpin` IS the tick counter, so
123
+ // every frame built a new key, `lightOrigin` created a fresh origin, and the elapsed time stayed at 0 — the light
124
+ // sat still except for the one frame after the row content changed.
125
+ //
126
+ // A row animates from the moment it appears until it stops being pending, and its id is stable across that life.
127
+ const rowKey = msg && (msg.id || msg.toolId) ? `tool:${msg.id || msg.toolId}` : `tool:${name}`;
128
+ const elapsedMs = Math.max(0, Date.now() - lightOrigin(rowKey, anchorSpin, spin));
129
+ const phaseMs = elapsedMs % cycleMs(name.length, TOOL_STEP_MS);
130
+
131
+ // The same restraint as the Working row's glint: the light is the base colour with a small lift in the SAME hue,
132
+ // not a jump to white. A pale white against cyan reads as a state change; a shade brighter reads as a sheen.
133
+ const BASE = [0, 215, 255]; // cyan: the name's resting colour
134
+ const GLINT = [110, 240, 255]; // the same hue, a shade brighter
135
+
136
+ // A pending tool's name is decoration, so reduced motion drops it rather than freezing it mid-sweep.
137
+ nameDisplay = reducedMotion
138
+ ? col(name, C.cyan)
139
+ : shimmerText(name, phaseMs, BASE, GLINT, shimmerEdge || 'cosine', TOOL_STEP_MS);
140
+ } else {
141
+ nameDisplay = col(name, C.cyan);
142
+ }
143
+ // Streamed size for a Write in flight.
144
+ let sizeStr = '';
145
+ if (name === 'Write' && typeof msg.streamContent === 'string' && msg.streamContent.length) {
146
+ const bytes = Buffer.byteLength(msg.streamContent, 'utf8');
147
+ sizeStr = bytes >= 1048576 ? ` ${(bytes / 1048576).toFixed(1)}MB`
148
+ : bytes >= 1024 ? ` ${(bytes / 1024).toFixed(1)}KB`
149
+ : ` ${bytes}B`;
150
+ }
151
+ // +xx -xx for a finished Edit. The diff itself is rendered under the `↳` receipt, so prefer the counts the
152
+ // tool_result handler copied over.
153
+ let diffStr = '';
154
+ const edDiff = (Array.isArray(msg.diff) && msg.diff.length) ? msg.diff : msg._diffCounts;
155
+ if (name === 'Edit' && !msg.pending && Array.isArray(edDiff) && edDiff.length) {
156
+ const adds = edDiff.filter((d) => d.type === 'add').length;
157
+ const deletes = edDiff.filter((d) => d.type === 'del').length;
158
+ if (adds || deletes) {
159
+ diffStr = ' ' + (adds ? col(`+${adds}`, C.green) : '') + ' ' + (deletes ? col(`-${deletes}`, C.red) : '');
160
+ }
161
+ }
162
+ // COLORED PER LINE, not around the whole string.
163
+ //
164
+ // `col(text)` writes one escape pair around everything, so a multi-line argument — exactly what Ctrl+O reveals, the
165
+ // body of a script — had its colour open on line 1 and none after the newline: the terminal's reset made every line
166
+ // below the first render in the DEFAULT foreground. Splitting on the newline and colouring each piece keeps the whole
167
+ // block the same grey. The parentheses still wrap the WHOLE value, so a multi-line script reads as one bracketed
168
+ // argument rather than as several.
169
+ let argText = '';
170
+ if (arg) {
171
+ const argLines = `${arg}`.split('\n');
172
+ const painted = argLines.map((l, i) => col(
173
+ (i === 0 ? '(' : '') + l + (i === argLines.length - 1 ? ')' : ''),
174
+ C.gray,
175
+ ));
176
+ argText = ' ' + painted.join('\n');
177
+ }
178
+ // HOW LONG IT TOOK, at the very end of the line.
179
+ //
180
+ // A running call counts up from its start, so a slow tool shows progress rather than looking frozen; a finished one
181
+ // shows the total. Same slot either way, so the line does not reflow when the call lands.
182
+ //
183
+ // Nothing is shown when the start is unknown — an older session, or a restored transcript — because a duration
184
+ // invented from "now" would be a lie that grows every frame.
185
+ let timeStr = '';
186
+ if (typeof msg.startAt === 'number' && msg.startAt > 0) {
187
+ const ended = typeof msg.endedAt === 'number' && msg.endedAt > 0
188
+ ? msg.endedAt
189
+ : (msg.pending ? Date.now() : 0);
190
+ if (ended >= msg.startAt) timeStr = ' ' + col(`(${fmtDuration(ended - msg.startAt)})`, C.gray);
191
+ }
192
+ return col(verb, C.white) + ' ' + nameDisplay + argText + col(sizeStr, C.gray) + diffStr + timeStr;
193
+ }
package/src/tools/bash.js CHANGED
@@ -7,7 +7,7 @@ import fs from 'node:fs';
7
7
  import cp from 'node:child_process';
8
8
  import { resolvePath, truncateBuf } from './utils.js';
9
9
  import { createTask, appendTaskOutput, settleTask } from '../agent-task.js';
10
- import { shellSpawnArgs } from './shell.js';
10
+ import { shellSpawnArgs, getShell } from './shell.js';
11
11
 
12
12
  // kimi-code's timeout policy (agent-core-v2/agent/tools/os/bash/bash.ts).
13
13
  export const DEFAULT_TIMEOUT_S = 60;
@@ -127,7 +127,13 @@ function killTree(child, opts = {}) {
127
127
 
128
128
  export const spec = {
129
129
  name: 'Bash',
130
- description: 'Run a shell command via pwsh. Returns combined stdout+stderr. timeout default 60s (max 300s); run_in_background detaches and returns a task id.',
130
+ // The shell is named at runtime, not baked in: the model is told which syntax it is writing against, and on a POSIX
131
+ // box "via pwsh" was both wrong and an invitation to emit PowerShell.
132
+ get description() {
133
+ const shell = getShell();
134
+ const which = shell ? (shell.edition === 'posix' ? 'the POSIX shell' : shell.name) : 'the system shell';
135
+ return `Run a shell command via ${which}. Returns combined stdout+stderr. timeout default 60s (max 300s); run_in_background detaches and returns a task id.`;
136
+ },
131
137
  parameters: {
132
138
  type: 'object',
133
139
  properties: {
@@ -155,15 +161,10 @@ export const spec = {
155
161
  const def = bg ? DEFAULT_BACKGROUND_TIMEOUT_S : DEFAULT_TIMEOUT_S;
156
162
  const timeoutMs = args.disable_timeout ? undefined : Math.min(args.timeout ?? def, cap) * 1000;
157
163
  const command = args.command;
158
- // stdin is 'ignore' by default (NUL / /dev/null): leaving it as an open pipe made any command that
159
- // reads stdin (`cat`, `npm init`, …) block until the timeout.
160
- //
161
- // `interactive` OPTS INTO A PIPE, and only for a background run: a foreground command has nobody to
162
- // type at it, while a background one can be fed through TaskInput. The pipe is closed by that tool
163
- // when it is done, which is what keeps `cat` and friends from hanging.
164
- if (args.interactive && !args.run_in_background) {
165
- return 'Error: `interactive` requires `run_in_background: true` — a foreground run has no way to receive input.';
166
- }
164
+ // STDIN IS A PIPE FOR EVERY RUN. The agent never types into it, but the USER can: a program that prompts
165
+ // (`npm init`, a REPL, a script reading a line) used to sit on /dev/null until the timeout killed it, with
166
+ // no way to answer. A background run is fed through TaskInput, a foreground one through the composer's
167
+ // Ctrl+G mode. When nobody writes, the command blocks exactly as it would in a terminal.
167
168
  let shell;
168
169
  try { shell = shellSpawnArgs(command); } catch (e) { return `Error: ${e.message}`; }
169
170
  // Check the turn's signal BEFORE spawning. The check below ran only after the
@@ -172,7 +173,7 @@ const command = args.command;
172
173
  // and Esc could not stop it.
173
174
  if (ctx.signal && ctx.signal.aborted) return 'Interrupted by user';
174
175
  const child = cp.spawn(shell.bin, shell.args, {
175
- cwd, stdio: [args.interactive ? 'pipe' : 'ignore', 'pipe', 'pipe'], env: { ...process.env },
176
+ cwd, stdio: ['pipe', 'pipe', 'pipe'], env: { ...process.env },
176
177
  });
177
178
 
178
179
  const chunks = [];
@@ -284,6 +285,12 @@ if (child.stdout) child.stdout.on('data', push);
284
285
  command: args.command,
285
286
  description: args.description || args.command,
286
287
  child, chunks,
288
+ // The TUI reaches this to answer a prompt the command is waiting on.
289
+ stdin: child.stdin,
290
+ write: (s) => {
291
+ if (settled || !child.stdin || child.stdin.destroyed || !child.stdin.writable) return false;
292
+ try { child.stdin.write(s); return true; } catch { return false; }
293
+ },
287
294
  detach: () => {
288
295
  if (settled) return null;
289
296
  settled = true;
@@ -69,6 +69,25 @@ function whichSync(name) {
69
69
  * cmd's, not PowerShell's.
70
70
  */
71
71
  export function detectShell() {
72
+ // POSIX FIRST, AND ON ITS OWN PATH.
73
+ //
74
+ // The PowerShell probe used to run on EVERY platform, so on Linux or macOS it looked for `pwsh`, then
75
+ // `powershell`, then `cmd.exe`, found none of them, and reported "install PowerShell 7+" — advice that is wrong on
76
+ // a machine whose shell has been there all along. A Unix box is never looking for PowerShell and a Windows box is
77
+ // never looking for bash, so the two branches do not overlap at all.
78
+ if (process.platform !== 'win32') {
79
+ // `$SHELL` is the user's own choice and is what a terminal would use. `/bin/sh` is the floor: it is on every
80
+ // POSIX system, so the tool survives a stripped PATH the same way `cmd.exe` does on Windows.
81
+ const fromEnv = process.env.SHELL ? whichSync(process.env.SHELL) : null;
82
+ if (fromEnv) return { path: fromEnv, name: fromEnv.split('/').pop(), edition: 'posix' };
83
+ for (const name of ['bash', 'zsh', 'sh']) {
84
+ const path = whichSync(name);
85
+ if (path) return { path, name, edition: 'posix' };
86
+ }
87
+ const sh = fs.existsSync('/bin/sh') ? '/bin/sh' : null;
88
+ return sh ? { path: sh, name: 'sh', edition: 'posix' } : null;
89
+ }
90
+
72
91
  for (const name of SHELL_CANDIDATES) {
73
92
  const path = whichSync(name);
74
93
  if (path) {
@@ -128,8 +147,9 @@ export function shellSpawnArgs(command, opts = {}) {
128
147
  const shell = getShell();
129
148
  if (!shell) {
130
149
  throw new Error(
131
- 'No shell found (tried pwsh, powershell, and cmd.exe). '
132
- + 'Install PowerShell 7+ or add it to PATH, then retry.',
150
+ process.platform === 'win32'
151
+ ? 'No shell found (tried pwsh, powershell, and cmd.exe). Install PowerShell 7+ or add it to PATH, then retry.'
152
+ : 'No shell found (tried $SHELL, bash, zsh and sh). Install a POSIX shell, then retry.',
133
153
  );
134
154
  }
135
155
  if (shell.edition === 'cmd') {
@@ -138,6 +158,12 @@ export function shellSpawnArgs(command, opts = {}) {
138
158
  // quoting and we do not wrap it ourselves.
139
159
  return { bin: shell.path, args: ['/d', '/s', '/c', command], shell };
140
160
  }
161
+ if (shell.edition === 'posix') {
162
+ // `-c` takes the command as one string, which is what every POSIX shell expects. There is no `-NoProfile`
163
+ // equivalent and none is wanted: a user's rc file is part of their environment, and the Windows flags exist to
164
+ // suppress a PowerShell banner that has no counterpart here.
165
+ return { bin: shell.path, args: ['-c', command], shell };
166
+ }
141
167
  const args = ['-NoProfile'];
142
168
  if (!opts.interactive) args.push('-NonInteractive');
143
169
  args.push('-Command', command);