Skip to content

fix(cli): wire SQUAD_TEAM_ROOT into squad resolution for subprocess compatibility (#734)#763

Merged
diberry merged 1 commit intobradygaster:devfrom
AmandaSilver:squad/734-nap-subprocess-cwd
Apr 4, 2026
Merged

fix(cli): wire SQUAD_TEAM_ROOT into squad resolution for subprocess compatibility (#734)#763
diberry merged 1 commit intobradygaster:devfrom
AmandaSilver:squad/734-nap-subprocess-cwd

Conversation

@AmandaSilver
Copy link
Copy Markdown
Contributor

What

Wires the --team-root\ / \SQUAD_TEAM_ROOT\ env var into the
esolveSquad()\ calls for the
ap, \status, and \cost\ commands. Previously the flag was parsed at CLI entry but never passed through to resolution.

Why

\squad nap\ (and other commands) fail when invoked as a subprocess where \process.cwd()\ differs from the interactive shell — e.g. Copilot CLI bang commands (!squad nap) on Windows (#734). The --team-root\ flag was already parsed and stored in \SQUAD_TEAM_ROOT, but no command ever read it.

How

  • Added \getSquadStartDir()\ helper: returns \SQUAD_TEAM_ROOT ?? process.cwd()\
  • Updated 3
    esolveSquad(process.cwd())\ calls to use
    esolveSquad(getSquadStartDir())\
  • Improved nap error message to show the searched directory and suggest --team-root\

Testing

  • 5 new tests in \ est/cli/nap-subprocess.test.ts\ (all pass)
  • 42 existing nap tests still pass
  • No functional change when \SQUAD_TEAM_ROOT\ is unset (falls back to \process.cwd())

Files Changed

  • \packages/squad-cli/src/cli-entry.ts\ — \getSquadStartDir()\ + 3 call-site updates
  • \ est/cli/nap-subprocess.test.ts\ — 5 new tests
  • .changeset/fix-nap-subprocess-cwd.md\ — patch changeset

Exports

N/A — no new public API

Breaking Changes

None — additive behavior only. Existing invocations are unchanged.

Waivers

None

Closes #734

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

@AmandaSilver AmandaSilver marked this pull request as ready for review April 2, 2026 22:59
Copilot AI review requested due to automatic review settings April 2, 2026 22:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a CLI wiring gap where --team-root / SQUAD_TEAM_ROOT was parsed but not used when resolving the active .squad/ directory, improving reliability when squad is invoked from subprocesses whose process.cwd() differs from the interactive shell (notably Copilot CLI bang commands on Windows).

Changes:

  • Added getSquadStartDir() in cli-entry.ts to prefer SQUAD_TEAM_ROOT over process.cwd().
  • Updated status, cost, and nap to resolve squads starting from getSquadStartDir().
  • Added a new test file and a patch changeset; improved nap “no squad found” error to include the searched directory and hint --team-root.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/squad-cli/src/cli-entry.ts Adds getSquadStartDir() and uses it to drive squad resolution for status, cost, and nap; improves the nap missing-squad error message.
test/cli/nap-subprocess.test.ts Adds tests intended to cover subprocess/--team-root scenarios for nap.
.changeset/fix-nap-subprocess-cwd.md Adds a patch changeset describing the CLI fix and its motivation.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

🟡 Impact Analysis — PR #763

Risk tier: 🟡 MEDIUM

📊 Summary

Metric Count
Files changed 3
Files added 2
Files modified 1
Files deleted 0
Modules touched 3

🎯 Risk Factors

  • 3 files changed (≤5 → LOW)
  • 3 modules touched (2-4 → MEDIUM)

📦 Modules Affected

root (1 file)
  • .changeset/fix-nap-subprocess-cwd.md
squad-cli (1 file)
  • packages/squad-cli/src/cli-entry.ts
tests (1 file)
  • test/cli/nap-subprocess.test.ts

This report is generated automatically for every PR. See #733 for details.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

🛫 PR Readiness Check

ℹ️ This comment updates on each push. Last checked: commit 17d780a

⚠️ 2 item(s) to address before review

Status Check Details
Single commit 1 commit — clean history
Not in draft Ready for review
Branch up to date Up to date with dev
Copilot review No Copilot review yet — it may still be processing
Changeset present Changeset file found
Scope clean No .squad/ or docs/proposals/ files
No merge conflicts No merge conflicts
Copilot threads resolved 0 active Copilot thread(s) resolved (2 outdated skipped)
CI passing 5 check(s) still running

This check runs automatically on every push. Fix any ❌ items and push again.
See CONTRIBUTING.md and PR Requirements for details.

* working directory differs from the interactive shell. (#734)
*/
function getSquadStartDir(): string {
return process.env['SQUAD_TEAM_ROOT'] || process.cwd();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@diberry
Copy link
Copy Markdown
Collaborator

diberry commented Apr 4, 2026

✅ APPROVE WITH FOLLOW-UP

This PR correctly fixes the subprocess invocation issue (#734) where \squad nap\ fails when \process.cwd()\ differs from the project root. The implementation is sound and safe.

Code Review

✅ Correctness: \getSquadStartDir()\ properly implements the fallback pattern:
\\ ypescript
return process.env['SQUAD_TEAM_ROOT'] || process.cwd();
\
Uses short-circuit OR for clean fallback to \process.cwd()\ when env var is unset.

✅ Completeness: All 3
esolveSquad()\ call sites are updated:


  • ap\ command (line 659)
  • \status\ command (line 571)
  • \cost\ command (line 609)

Verified against the diff — no call sites missed.

✅ Security: No path traversal risk. The env var is:

  1. Set by the CLI itself via the --team-root\ flag parsing (controlled input)
  2. Passed directly to
    esolveSquad()\ which already validates paths
  3. Only used as a starting point for upward directory traversal (looking for .squad/)

✅ Test Quality: The Copilot bot's review comments were valid when written but are now obsolete — commit 01ed21a (current HEAD) addressed both concerns:

  1. ✅ Test now uses \process.chdir(differentCwd)\ to simulate subprocess scenario
  2. ✅ Test validates the actual behavior, not just runNap internals

The 5 tests cover:

Existing review threads are correctly marked as resolved/outdated.

✅ Error Message Improvement: The updated nap error is helpful:
\
No squad found (searched from ). Run "squad init" first, or use --team-root to specify the project directory.
\\

Required Actions Before Merge

  1. *Rebase onto \dev* — PR is behind base (mergeable_state: "behind")
  2. Squash 4 commits to 1 — commits should be:
  3. Re-run CI — Squad CI checks not visible on current commit; need verification after rebase

Verdict

APPROVE WITH FOLLOW-UP — Code is production-ready. Merge blocked only by Git hygiene (rebase + squash), not code quality.

cc @AmandaSilver — please rebase onto latest \dev\ and squash to 1 commit, then CI should auto-run. Code review complete ✅

…ompatibility (bradygaster#734)

Adds getSquadStartDir() helper that reads SQUAD_TEAM_ROOT env var for nap, status, and cost commands. Previously the --team-root flag was parsed but never passed through to resolveSquad().

- Added getSquadStartDir(): returns SQUAD_TEAM_ROOT ?? process.cwd()
- Updated 3 resolveSquad(process.cwd()) calls to use resolveSquad(getSquadStartDir())
- Improved nap error message to show searched directory and suggest --team-root
- 5 new tests in test/cli/nap-subprocess.test.ts

Closes bradygaster#734

Co-authored-by: AmandaSilver <11282874+AmandaSilver@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@diberry
Copy link
Copy Markdown
Collaborator

diberry commented Apr 4, 2026

Follow-up Issues Created

Two follow-up issues filed to extend this fix:

These capture the remaining work to make subprocess invocation robust across all commands.

@diberry diberry merged commit 6f9d965 into bradygaster:dev Apr 4, 2026
17 checks passed
diberry added a commit that referenced this pull request Apr 4, 2026
Verifies getSquadStartDir() across all resolution scenarios:
env var set, unset, empty, invalid path.

Closes #836
Related: PR #763, #835

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
diberry added a commit that referenced this pull request Apr 4, 2026
All commands now respect SQUAD_TEAM_ROOT env var for subprocess compatibility.
Previously only nap, status, and cost used getSquadStartDir().

Closes #835
Related: PR #763, #734

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
diberry added a commit that referenced this pull request Apr 4, 2026
Verifies getSquadStartDir() across all resolution scenarios:
env var set, unset, empty, invalid path.

Closes #836
Related: PR #763, #835

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
tamirdresher added a commit that referenced this pull request Apr 5, 2026
Verifies getSquadStartDir() across all resolution scenarios:
env var set, unset, empty, invalid path.

Closes #836
Related: PR #763, #835

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Tamir Dresher <tamir.dresher@gmail.com>
tamirdresher added a commit that referenced this pull request Apr 5, 2026
All commands now respect SQUAD_TEAM_ROOT env var for subprocess compatibility.
Previously only nap, status, and cost used getSquadStartDir().

Closes #835
Related: PR #763, #734

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Tamir Dresher <tamir.dresher@gmail.com>
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.

bug: squad nap fails when invoked via bang command (!) in Windows PowerShell terminal

4 participants