singularity-forge/packages
Jeremy McSpadden a3ff25c668 fix(bash): rewrite background commands to prevent pipe-open hang
Root cause: when the LLM runs `cmd &`, bash forks the process and
exits immediately. The forked process inherits Node's piped stdout/
stderr FDs. Node.js waits for all holders of those FDs to close before
firing the 'close' event — so the tool hangs until the background
process exits (which for a server is never).

Fix: add rewriteBackgroundCommand() in bash.ts. Before exec, detect
commands with a trailing & background operator and inject
>/dev/null 2>&1 before the & when stdout is not already redirected.
This severs the pipe inheritance so Node gets 'close' immediately
when the shell exits.

Guards:
- Commands already redirecting stdout (>, >>, &>, |) are not rewritten
- && (logical AND) is not affected
- & inside single-quoted strings is not affected
- A brief onUpdate advisory is surfaced when rewrite happens so the
  LLM knows to prefer nohup/setsid for robust detachment

Export rewriteBackgroundCommand from pi-coding-agent for testability.

Tests: bash-background.test.ts — 12 cases covering no-op paths,
rewrite paths, compound commands, and already-safe nohup patterns.
Closes #733
2026-03-16 18:03:01 -05:00
..
native perf: optimize discovery and interactive hot paths 2026-03-14 16:03:44 -05:00
pi-agent-core fix(agent-core): await event queue in tool hooks for safe parallel execution (#439) 2026-03-14 21:16:17 -06:00
pi-ai Merge pull request #690 from trek-e/fix/688-thinking-minimal-gpt5 2026-03-16 14:17:51 -06:00
pi-coding-agent fix(bash): rewrite background commands to prevent pipe-open hang 2026-03-16 18:03:01 -05:00
pi-tui Merge pull request #680 from trek-e/fix/658-warp-cursor-visibility 2026-03-16 13:20:37 -06:00