Skip to content

feat: add pi-bash-bg package#29

Merged
mgabor3141 merged 4 commits intomainfrom
pi-bash-bg
Apr 3, 2026
Merged

feat: add pi-bash-bg package#29
mgabor3141 merged 4 commits intomainfrom
pi-bash-bg

Conversation

@mgabor3141
Copy link
Copy Markdown
Owner

Makes command & work in pi's bash tool by intercepting bash tool calls, detecting background processes via AST parsing, and rewriting commands to detach them from pipes.

How it works

  • Parses commands with @aliou/sh to find background: true statements
  • Simple commands: redirects stdout/stderr to temp log files
  • Compound commands (&&, ||, pipelines): wraps in { ...; } so the redirect applies to the entire background subshell
  • Adds disown to detach from job control (skipped if already present)
  • Appends echo reporting PID, label, and log path
  • Replaces the system prompt's "command & doesn't work" guidance

What the agent sees

[bg] pid=12345 label=npm run dev log=/tmp/pi-bg-abc-0.log

72 tests covering detection, rewriting, and integration (verifying rewritten commands actually return without hanging).

mgabor3141 and others added 4 commits April 3, 2026 17:40
Intercepts bash tool calls, detects background processes via AST parsing
(@aliou/sh), and rewrites commands to redirect output to temp log files
and disown. Compound commands (&&, ||, pipelines) are wrapped in braces
so the redirect applies to the entire background subshell.

The agent sees PID, label, and log path in the tool output, and can use
cat/kill to monitor or stop background processes.
- Compound commands now ALWAYS wrap in braces, even when inner commands
  have redirects. Inner redirects only affect individual commands, not the
  background subshell that holds the pipe fds open.
- State machine now tracks backtick nesting to avoid finding & inside
  command substitutions.
- Fully-redirected simple commands no longer report a nonexistent log file
  in the echo output.
- Removed dead echoes variable in rewriteCommand.
- Added tests for isCompound detection, compound+redirect wrapping,
  echo output with/without log paths, backtick handling.
@mgabor3141 mgabor3141 merged commit ce02a93 into main Apr 3, 2026
1 check passed
@mgabor3141 mgabor3141 deleted the pi-bash-bg branch April 3, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant