From 7398a309ba0ba07158912abcf70b8551f2dd2310 Mon Sep 17 00:00:00 2001 From: Tamir Dresher Date: Thu, 19 Nov 2026 19:10:52 +0200 Subject: [PATCH 1/3] fix: resolve Windows workspace launcher shims Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .changeset/fix-windows-workspace-shim.md | 6 +++ .../src/client/adapters/claude-plugin.ts | 5 ++- plugins/squad/scripts/squad.mjs | 5 ++- test/launcher-argv.test.ts | 42 ++++++++++++++++++- 4 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 .changeset/fix-windows-workspace-shim.md diff --git a/.changeset/fix-windows-workspace-shim.md b/.changeset/fix-windows-workspace-shim.md new file mode 100644 index 000000000..30f7fd090 --- /dev/null +++ b/.changeset/fix-windows-workspace-shim.md @@ -0,0 +1,6 @@ +--- +"@bradygaster/squad-cli": patch +"@bradygaster/squad-sdk": patch +--- + +Fix Windows launcher resolution for workspace-local Squad and npx shims. diff --git a/packages/squad-sdk/src/client/adapters/claude-plugin.ts b/packages/squad-sdk/src/client/adapters/claude-plugin.ts index a0cb7beec..fc5ec098d 100644 --- a/packages/squad-sdk/src/client/adapters/claude-plugin.ts +++ b/packages/squad-sdk/src/client/adapters/claude-plugin.ts @@ -300,9 +300,10 @@ function withoutShell(command, prefix) { if (!win || !/\\.(cmd|bat)$/i.test(command)) return [command, prefix]; const shim = path.isAbsolute(command) ? command : onPath(path.basename(command, path.extname(command))); const dir = shim ? path.dirname(shim) : path.dirname(process.execPath); + const modules = path.basename(dir).toLowerCase() === '.bin' ? path.dirname(dir) : path.join(dir, 'node_modules'); const candidates = path.basename(command).toLowerCase() === 'npx.cmd' - ? [path.join(dir, 'node_modules/npm/bin/npx-cli.js'), path.join(path.dirname(process.execPath), 'node_modules/npm/bin/npx-cli.js')] - : [path.join(dir, 'node_modules', ...PKG.split('/'), 'dist/cli-entry.js')]; + ? [path.join(modules, 'npm/bin/npx-cli.js'), path.join(path.dirname(process.execPath), 'node_modules/npm/bin/npx-cli.js')] + : [path.join(modules, ...PKG.split('/'), 'dist/cli-entry.js')]; const entry = candidates.find((candidate) => fs.existsSync(candidate)); if (!entry) throw new Error(\`Cannot resolve the JavaScript entry for \${command}; set SQUAD_CLI to cli-entry.js\`); return [process.execPath, [entry, ...prefix]]; diff --git a/plugins/squad/scripts/squad.mjs b/plugins/squad/scripts/squad.mjs index 8f2e9ceca..eaf6460b5 100755 --- a/plugins/squad/scripts/squad.mjs +++ b/plugins/squad/scripts/squad.mjs @@ -187,9 +187,10 @@ function withoutShell(command, prefix) { if (!win || !/\.(cmd|bat)$/i.test(command)) return [command, prefix]; const shim = path.isAbsolute(command) ? command : onPath(path.basename(command, path.extname(command))); const dir = shim ? path.dirname(shim) : path.dirname(process.execPath); + const modules = path.basename(dir).toLowerCase() === '.bin' ? path.dirname(dir) : path.join(dir, 'node_modules'); const candidates = path.basename(command).toLowerCase() === 'npx.cmd' - ? [path.join(dir, 'node_modules/npm/bin/npx-cli.js'), path.join(path.dirname(process.execPath), 'node_modules/npm/bin/npx-cli.js')] - : [path.join(dir, 'node_modules', ...PKG.split('/'), 'dist/cli-entry.js')]; + ? [path.join(modules, 'npm/bin/npx-cli.js'), path.join(path.dirname(process.execPath), 'node_modules/npm/bin/npx-cli.js')] + : [path.join(modules, ...PKG.split('/'), 'dist/cli-entry.js')]; const entry = candidates.find((candidate) => fs.existsSync(candidate)); if (!entry) throw new Error(`Cannot resolve the JavaScript entry for ${command}; set SQUAD_CLI to cli-entry.js`); return [process.execPath, [entry, ...prefix]]; diff --git a/test/launcher-argv.test.ts b/test/launcher-argv.test.ts index b18adb1c4..6a8d6d25a 100644 --- a/test/launcher-argv.test.ts +++ b/test/launcher-argv.test.ts @@ -62,8 +62,8 @@ function write(file: string, body: string, mode?: number): void { } /** A shim that must never run: under cmd.exe it prints SHELL-USED. */ -function cmdShim(name: string): void { - write(path.join(bin, `${name}.cmd`), '@echo SHELL-USED %*\r\n'); +function cmdShim(name: string, dir = bin): void { + write(path.join(dir, `${name}.cmd`), '@echo SHELL-USED %*\r\n'); } function run(args: string[], env: Record = {}) { @@ -102,6 +102,31 @@ describe('the launcher passes argv through unchanged', () => { expect(parsed(run(HOSTILE))).toEqual(HOSTILE); }); + it.runIf(win)('resolves a workspace .bin shim to its sibling package without a shell', () => { + const modules = path.join(root, 'workspace', 'node_modules'); + const workspaceBin = path.join(modules, '.bin'); + cmdShim('squad', workspaceBin); + const pkg = path.join(modules, ...PKG); + write(path.join(pkg, 'package.json'), JSON.stringify({ name: PKG.join('/'), version: '2.0.0' })); + write(path.join(pkg, 'dist', 'cli-entry.js'), ECHO); + expect(parsed(run(HOSTILE, { PATH: [workspaceBin, path.dirname(process.execPath)].join(path.delimiter) }))).toEqual(HOSTILE); + }); + + it.runIf(win)('skips an outdated workspace .bin shim in favor of a recorded CLI', () => { + const modules = path.join(root, 'workspace', 'node_modules'); + const workspaceBin = path.join(modules, '.bin'); + cmdShim('squad', workspaceBin); + const pkg = path.join(modules, ...PKG); + write(path.join(pkg, 'package.json'), JSON.stringify({ name: PKG.join('/'), version: '1.0.0' })); + write(path.join(pkg, 'dist', 'cli-entry.js'), "throw new Error('outdated CLI selected');\n"); + const recorded = path.join(root, 'recorded', 'node_modules', ...PKG); + const entry = path.join(recorded, 'dist', 'cli-entry.js'); + write(path.join(recorded, 'package.json'), JSON.stringify({ name: PKG.join('/'), version: '2.0.0' })); + write(entry, ECHO); + write(path.join(root, 'squad-home', 'cli.json'), JSON.stringify({ entry })); + expect(parsed(run(HOSTILE, { PATH: [workspaceBin, path.dirname(process.execPath)].join(path.delimiter) }))).toEqual(HOSTILE); + }); + it('to npx when SQUAD_ALLOW_NPX=1', () => { if (win) { cmdShim('npx'); @@ -112,6 +137,18 @@ describe('the launcher passes argv through unchanged', () => { expect(parsed(run(HOSTILE, { SQUAD_ALLOW_NPX: '1' }))).toEqual(['-y', `${PKG.join('/')}@2.0.0`, ...HOSTILE]); }); + it.runIf(win)('resolves a workspace npx .bin shim without a shell', () => { + const modules = path.join(root, 'workspace', 'node_modules'); + const workspaceBin = path.join(modules, '.bin'); + cmdShim('npx', workspaceBin); + write(path.join(modules, 'npm', 'bin', 'npx-cli.js'), ECHO); + const out = run(HOSTILE, { + PATH: [workspaceBin, path.dirname(process.execPath)].join(path.delimiter), + SQUAD_ALLOW_NPX: '1', + }); + expect(parsed(out)).toEqual(['-y', `${PKG.join('/')}@2.0.0`, ...HOSTILE]); + }); + it('to SQUAD_CLI given as a script', () => { const entry = path.join(root, 'cli dir', 'cli-entry.js'); write(entry, ECHO); @@ -127,6 +164,7 @@ describe('the launcher passes argv through unchanged', () => { it.runIf(win)('fails closed when a .cmd shim has no JavaScript entry beside it', () => { cmdShim('squad'); + write(path.join(bin, 'node_modules', ...PKG, 'package.json'), JSON.stringify({ name: PKG.join('/'), version: '2.0.0' })); const out = run(['state-mcp']); expect(out.status).toBe(1); expect(out.stdout).not.toContain('SHELL-USED'); From 42b77f197e3821829b47db319a5b7b44abb6691e Mon Sep 17 00:00:00 2001 From: Tamir Dresher Date: Thu, 19 Nov 2026 19:20:19 +0200 Subject: [PATCH 2/3] test: cover explicit Windows workspace shims Closes #2544 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- test/launcher-argv.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/launcher-argv.test.ts b/test/launcher-argv.test.ts index 6a8d6d25a..76683b537 100644 --- a/test/launcher-argv.test.ts +++ b/test/launcher-argv.test.ts @@ -112,6 +112,14 @@ describe('the launcher passes argv through unchanged', () => { expect(parsed(run(HOSTILE, { PATH: [workspaceBin, path.dirname(process.execPath)].join(path.delimiter) }))).toEqual(HOSTILE); }); + it.runIf(win)('resolves an explicitly configured workspace .bin shim', () => { + const modules = path.join(root, 'workspace', 'node_modules'); + const workspaceBin = path.join(modules, '.bin'); + cmdShim('squad', workspaceBin); + write(path.join(modules, ...PKG, 'dist', 'cli-entry.js'), ECHO); + expect(parsed(run(HOSTILE, { SQUAD_CLI: path.join(workspaceBin, 'squad.cmd') }))).toEqual(HOSTILE); + }); + it.runIf(win)('skips an outdated workspace .bin shim in favor of a recorded CLI', () => { const modules = path.join(root, 'workspace', 'node_modules'); const workspaceBin = path.join(modules, '.bin'); From 722626309598e9af4c3196a5290d2abdd6da02e9 Mon Sep 17 00:00:00 2001 From: Tamir Dresher Date: Thu, 19 Nov 2026 19:36:48 +0200 Subject: [PATCH 3/3] test: group Windows shim resolution cases Closes #2544 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- test/launcher-argv.test.ts | 86 +++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/test/launcher-argv.test.ts b/test/launcher-argv.test.ts index 76683b537..42e13cf71 100644 --- a/test/launcher-argv.test.ts +++ b/test/launcher-argv.test.ts @@ -102,39 +102,6 @@ describe('the launcher passes argv through unchanged', () => { expect(parsed(run(HOSTILE))).toEqual(HOSTILE); }); - it.runIf(win)('resolves a workspace .bin shim to its sibling package without a shell', () => { - const modules = path.join(root, 'workspace', 'node_modules'); - const workspaceBin = path.join(modules, '.bin'); - cmdShim('squad', workspaceBin); - const pkg = path.join(modules, ...PKG); - write(path.join(pkg, 'package.json'), JSON.stringify({ name: PKG.join('/'), version: '2.0.0' })); - write(path.join(pkg, 'dist', 'cli-entry.js'), ECHO); - expect(parsed(run(HOSTILE, { PATH: [workspaceBin, path.dirname(process.execPath)].join(path.delimiter) }))).toEqual(HOSTILE); - }); - - it.runIf(win)('resolves an explicitly configured workspace .bin shim', () => { - const modules = path.join(root, 'workspace', 'node_modules'); - const workspaceBin = path.join(modules, '.bin'); - cmdShim('squad', workspaceBin); - write(path.join(modules, ...PKG, 'dist', 'cli-entry.js'), ECHO); - expect(parsed(run(HOSTILE, { SQUAD_CLI: path.join(workspaceBin, 'squad.cmd') }))).toEqual(HOSTILE); - }); - - it.runIf(win)('skips an outdated workspace .bin shim in favor of a recorded CLI', () => { - const modules = path.join(root, 'workspace', 'node_modules'); - const workspaceBin = path.join(modules, '.bin'); - cmdShim('squad', workspaceBin); - const pkg = path.join(modules, ...PKG); - write(path.join(pkg, 'package.json'), JSON.stringify({ name: PKG.join('/'), version: '1.0.0' })); - write(path.join(pkg, 'dist', 'cli-entry.js'), "throw new Error('outdated CLI selected');\n"); - const recorded = path.join(root, 'recorded', 'node_modules', ...PKG); - const entry = path.join(recorded, 'dist', 'cli-entry.js'); - write(path.join(recorded, 'package.json'), JSON.stringify({ name: PKG.join('/'), version: '2.0.0' })); - write(entry, ECHO); - write(path.join(root, 'squad-home', 'cli.json'), JSON.stringify({ entry })); - expect(parsed(run(HOSTILE, { PATH: [workspaceBin, path.dirname(process.execPath)].join(path.delimiter) }))).toEqual(HOSTILE); - }); - it('to npx when SQUAD_ALLOW_NPX=1', () => { if (win) { cmdShim('npx'); @@ -145,16 +112,51 @@ describe('the launcher passes argv through unchanged', () => { expect(parsed(run(HOSTILE, { SQUAD_ALLOW_NPX: '1' }))).toEqual(['-y', `${PKG.join('/')}@2.0.0`, ...HOSTILE]); }); - it.runIf(win)('resolves a workspace npx .bin shim without a shell', () => { - const modules = path.join(root, 'workspace', 'node_modules'); - const workspaceBin = path.join(modules, '.bin'); - cmdShim('npx', workspaceBin); - write(path.join(modules, 'npm', 'bin', 'npx-cli.js'), ECHO); - const out = run(HOSTILE, { - PATH: [workspaceBin, path.dirname(process.execPath)].join(path.delimiter), - SQUAD_ALLOW_NPX: '1', + describe('when a .cmd shim has no JavaScript entry beside it', () => { + it.runIf(win)('resolves a workspace .bin shim to its sibling package without a shell', () => { + const modules = path.join(root, 'workspace', 'node_modules'); + const workspaceBin = path.join(modules, '.bin'); + cmdShim('squad', workspaceBin); + const pkg = path.join(modules, ...PKG); + write(path.join(pkg, 'package.json'), JSON.stringify({ name: PKG.join('/'), version: '2.0.0' })); + write(path.join(pkg, 'dist', 'cli-entry.js'), ECHO); + expect(parsed(run(HOSTILE, { PATH: [workspaceBin, path.dirname(process.execPath)].join(path.delimiter) }))).toEqual(HOSTILE); + }); + + it.runIf(win)('resolves an explicitly configured workspace .bin shim', () => { + const modules = path.join(root, 'workspace', 'node_modules'); + const workspaceBin = path.join(modules, '.bin'); + cmdShim('squad', workspaceBin); + write(path.join(modules, ...PKG, 'dist', 'cli-entry.js'), ECHO); + expect(parsed(run(HOSTILE, { SQUAD_CLI: path.join(workspaceBin, 'squad.cmd') }))).toEqual(HOSTILE); + }); + + it.runIf(win)('skips an outdated workspace .bin shim in favor of a recorded CLI', () => { + const modules = path.join(root, 'workspace', 'node_modules'); + const workspaceBin = path.join(modules, '.bin'); + cmdShim('squad', workspaceBin); + const pkg = path.join(modules, ...PKG); + write(path.join(pkg, 'package.json'), JSON.stringify({ name: PKG.join('/'), version: '1.0.0' })); + write(path.join(pkg, 'dist', 'cli-entry.js'), "throw new Error('outdated CLI selected');\n"); + const recorded = path.join(root, 'recorded', 'node_modules', ...PKG); + const entry = path.join(recorded, 'dist', 'cli-entry.js'); + write(path.join(recorded, 'package.json'), JSON.stringify({ name: PKG.join('/'), version: '2.0.0' })); + write(entry, ECHO); + write(path.join(root, 'squad-home', 'cli.json'), JSON.stringify({ entry })); + expect(parsed(run(HOSTILE, { PATH: [workspaceBin, path.dirname(process.execPath)].join(path.delimiter) }))).toEqual(HOSTILE); + }); + + it.runIf(win)('resolves a workspace npx .bin shim without a shell', () => { + const modules = path.join(root, 'workspace', 'node_modules'); + const workspaceBin = path.join(modules, '.bin'); + cmdShim('npx', workspaceBin); + write(path.join(modules, 'npm', 'bin', 'npx-cli.js'), ECHO); + const out = run(HOSTILE, { + PATH: [workspaceBin, path.dirname(process.execPath)].join(path.delimiter), + SQUAD_ALLOW_NPX: '1', + }); + expect(parsed(out)).toEqual(['-y', `${PKG.join('/')}@2.0.0`, ...HOSTILE]); }); - expect(parsed(out)).toEqual(['-y', `${PKG.join('/')}@2.0.0`, ...HOSTILE]); }); it('to SQUAD_CLI given as a script', () => {