parallel-code icon indicating copy to clipboard operation
parallel-code copied to clipboard

feat: setup/teardown commands and configurable symlink dirs in project settings

Open linniksa opened this issue 8 months ago • 4 comments

Add per-project setup and teardown commands that run automatically when worktrees are created or removed. This lets users configure things
like npm install, environment setup, or cleanup scripts that execute in the context of each task's worktree.

Setup/teardown commands:

  • Configurable in Edit Project dialog via a reusable CommandListEditor component
  • $PROJECT_ROOT and $WORKTREE variable substitution in commands
  • Setup runs after worktree creation, before the agent starts; teardown runs before worktree removal
  • Live output displayed in a SetupBanner above the terminal with retry/skip on failure
  • Initial prompt is stashed during setup to prevent the agent from acting before setup completes

Configurable symlink directories:

  • Replace hardcoded symlink candidate list with per-project defaultSymlinkDirs setting
  • New PathSelector component with autocomplete backed by ListProjectEntries IPC (Tab to navigate into subdirectories, supports nested
    paths)
  • New-task dialog pre-fills symlink dirs from project defaults instead of scanning gitignored entries

linniksa avatar Mar 16 '26 22:03 linniksa

Security: shell metacharacter injection via $PROJECT_ROOT/$WORKTREE substitution

setup.ts substitutes projectRoot and worktreePath into the command string, then passes the result to spawn(cmd, { shell: true }). If either path contains shell metacharacters (spaces, $, backticks, semicolons, etc.), the shell will interpret them. Example: a project path of /home/user/my project; echo pwned would result in two shell commands being executed.

// setup.ts – the substituted string is passed directly to a shell
const cmd = expandVars(raw);   // e.g. "npm install --prefix /home/user/my project; echo pwned"
spawn(cmd, { shell: true, ... });

Fix options:

  1. Shell-quote the substituted values when inserting them (e.g. wrap in single-quotes, escaping any single-quote inside with '\'').
  2. Pass commands as an argument array to spawn and handle variable substitution at the array level (though this prevents users from using pipes/redirects in their commands, which may be intentional).

The simplest safe fix is to quote the values:

const shellQuote = (s: string) => `'${s.replace(/'/g, "'\\''")}'`;
const expandVars = (cmd: string): string =>
  cmd
    .replace(/\$\{PROJECT_ROOT\}|\$PROJECT_ROOT\b/g, () => shellQuote(projectRoot))
    .replace(/\$\{WORKTREE\}|\$WORKTREE\b/g, () => shellQuote(worktreePath));

In practice, project roots set by the user on their own machine make this low-severity, but it's worth closing if paths can ever contain spaces (common on macOS).

This is a new finding not covered by the existing review — all other items I checked were already thoroughly addressed by @johannesjo.

johannesjo avatar Apr 13 '26 17:04 johannesjo

Thank you very much! <3

johannesjo avatar Apr 13 '26 17:04 johannesjo

@linniksa Thank you very much for this! Sorry for the delay. I took the liberty to make some adjustments. Could you maybe have a look if the updated version fits your vision?

johannesjo avatar Apr 19 '26 20:04 johannesjo

@linniksa thank you for submitting this. I haven't seen any further updates from you so I'll close this out in the next few days if you are not available to move this forward. Of course you are welcome to re-open this or submit a new PR anytime.

brooksc avatar Jun 16 '26 16:06 brooksc