@hncode/hncode 0.8.0 → 0.8.2

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.
@@ -53,8 +53,7 @@ Do NOT use it for what you can infer from context, or for trivial decisions —
53
53
 
54
54
  Usage:
55
55
  - Users always get an "Other" option; do not create one.
56
- + 'For an answer that cannot be enumerated (a name, a path, a description), set free_text: true and omit'
57
- + ' options — the user gets a focused field instead of a list.',
56
+ For an answer that cannot be enumerated (a name, a path, a description), set free_text: true and omit options — the user gets a focused field instead of a list.
58
57
  - 2-4 distinct options per question, labels 1-5 words, descriptions carry the trade-offs. Labels unique within a question, question texts unique across the call.
59
58
  - 1-4 questions at a time, related ones grouped. multi_select allows several answers.
60
59
  - Put a recommended option first and append "(Recommended)" to its label.
package/src/tools/bash.js CHANGED
@@ -5,9 +5,9 @@
5
5
 
6
6
  import fs from 'node:fs';
7
7
  import cp from 'node:child_process';
8
- import { resolvePath, truncateBuf } from './utils.js';
8
+ import { resolvePath, truncateBuf , similarFileHint } 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: {
@@ -146,7 +152,7 @@ export const spec = {
146
152
  const cwdRaw = args.cwd || ctx.workspace;
147
153
  let cwd;
148
154
  try { cwd = resolvePath(cwdRaw, ctx); } catch (e) { return e.message; }
149
- if (!fs.existsSync(cwd)) return `Error: cwd does not exist: ${cwdRaw}`;
155
+ if (!fs.existsSync(cwd)) return `Error: cwd does not exist: ${cwdRaw}${similarFileHint(cwd)}. Omit cwd to use the workspace root.`;
150
156
 
151
157
  if (args.run_in_background) return spawnBackground(args, cwd, ctx);
152
158
 
@@ -366,21 +372,27 @@ function spawnBackground(args, cwd, ctx) {
366
372
  // still read it. (In the TUI the parent rarely exits, but headless -p mode
367
373
  // does, and a background job should outlive the prompt.)
368
374
  //
369
- // AN INTERACTIVE RUN CANNOT BE DETACHED. Measured on Windows: `detached: true` with piped stdout
370
- // returns exit 0 and NO output, while the same command not detached returns its output normally — the
371
- // detached process gets no working pipe back to us. Interactive needs that pipe in both directions, so
372
- // it stays attached. The trade: it will not outlive the parent, which is the same lifetime its stdin
373
- // already has.
375
+ // AND NOT ON WINDOWS AT ALL. The note above says `detached: true` with piped stdout returns exit 0 and no output; the
376
+ // same is true for a NON-interactive background command, which is the ordinary Ctrl+B case. Measured with pwsh:
377
+ //
378
+ // detached=false "exit 3" -> exit 3, output intact
379
+ // detached=true "exit 3" -> exit 0, output EMPTY
380
+ // detached=true "echo hello" -> exit 0, output EMPTY
381
+ //
382
+ // So on Windows the process stays attached: its output and its exit code are the whole point of a background task, and
383
+ // a task that reports success whatever happened is worse than one that dies with its parent. Elsewhere the detach is
384
+ // what makes a job outlive headless `-p`, so it is kept.
385
+ const canDetach = process.platform !== 'win32' && !args.interactive;
374
386
  let shell;
375
387
  try { shell = shellSpawnArgs(command, { interactive: args.interactive }); } catch (e) { return `Error: ${e.message}`; }
376
388
  const child = cp.spawn(shell.bin, shell.args, {
377
- cwd, detached: !args.interactive, stdio: [args.interactive ? 'pipe' : 'ignore', 'pipe', 'pipe'], env: { ...process.env },
389
+ cwd, detached: canDetach, stdio: [args.interactive ? 'pipe' : 'ignore', 'pipe', 'pipe'], env: { ...process.env },
378
390
  });
379
391
  const task = createTask(ctx, 'process', {
380
392
  description: args.description || args.command,
381
393
  command: args.command,
382
394
  pid: child.pid,
383
- detached: !args.interactive,
395
+ detached: canDetach,
384
396
  });
385
397
  // The stdin pipe, when the caller asked for one. Kept on the TASK so `TaskInput` can reach it from a
386
398
  // task id alone — a tool receives an id, not a handle. Only `interactive` gets here, so a plain