Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5c9573f
chore(porch): 1911 init pir
amrmelsayed Nov 20, 2026
b5865fe
[PIR #1911] Plan draft
amrmelsayed Nov 20, 2026
740657a
chore(porch): 1911 plan-approval gate-requested
amrmelsayed Nov 20, 2026
2060608
[PIR #1911] Plan revised: set NoDefaultCurrentDirectoryInExePath at e…
amrmelsayed Nov 20, 2026
57bcccc
chore(porch): 1911 plan-approval gate-approved
amrmelsayed Nov 20, 2026
a032c01
chore(porch): 1911 implement phase-transition
amrmelsayed Nov 20, 2026
7d4d41f
[PIR #1911] Set NoDefaultCurrentDirectoryInExePath first in every Cod…
amrmelsayed Nov 20, 2026
4d54ae8
[PIR #1911] VS Code: refuse a Codev CLI name that does not resolve on…
amrmelsayed Nov 20, 2026
1b16aee
[PIR #1911] Docs: native Windows is no longer a preview
amrmelsayed Nov 20, 2026
1cfb06b
[PIR #1911] Thread: implement notes
amrmelsayed Nov 20, 2026
3bef422
[PIR #1911] Rename to lib/process-bootstrap.ts; move the Windows step…
amrmelsayed Nov 22, 2026
f9d0c8b
[PIR #1911] Thread: Node 22 runs, waiting on #1946
amrmelsayed Nov 22, 2026
52307b0
Merge remote-tracking branch 'origin/main' into builder/pir-1911
amrmelsayed Nov 22, 2026
875a44b
chore(porch): 1911 dev-approval gate-requested
amrmelsayed Nov 22, 2026
663603e
[PIR #1911] Thread: checks pass, at dev-approval
amrmelsayed Nov 22, 2026
53a1f3c
[PIR #1911] Cover every Tower terminal: test it, correct the docs
amrmelsayed Nov 22, 2026
db8577b
[PIR #1911] Thread: checks pass, back at dev-approval
amrmelsayed Nov 22, 2026
e145f3c
[PIR #1911] Terminal coverage test: end every recorded session in tea…
amrmelsayed Nov 22, 2026
c6179e4
chore(porch): 1911 dev-approval gate-approved
amrmelsayed Nov 22, 2026
145a8b3
chore(porch): 1911 review phase-transition
amrmelsayed Nov 22, 2026
30d6666
[PIR #1911] Review + retrospective
amrmelsayed Nov 22, 2026
6fb70fb
chore(porch): 1911 record PR #1948
amrmelsayed Nov 22, 2026
50bd9f4
chore(porch): 1911 review build-complete
amrmelsayed Nov 22, 2026
70aee8d
chore(porch): 1911 pr gate-requested
amrmelsayed Nov 22, 2026
199c344
[PIR #1911] Consultation fixes: cover the fallback terminal, Spawn Bu…
amrmelsayed Nov 22, 2026
2b09e30
chore(porch): 1911 review build-complete
amrmelsayed Nov 22, 2026
57d2ec5
[PIR #1911] Review: final CI run and test counts
amrmelsayed Nov 22, 2026
600cfba
chore(porch): 1911 pr gate-approved
amrmelsayed Nov 22, 2026
016450d
chore(porch): 1911 protocol complete
amrmelsayed Nov 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ If Tower is running during an upgrade, restart it afterwards so it picks up the

On Linux and WSL, also install `build-essential` and `python3` (node-pty compiles from source).

**Windows:** two paths. **Native** (preview): Node.js 22 or 24 (x64 or ARM64), [Git for Windows](https://git-scm.com/download/win) and `jq`, no admin rights or Developer Mode needed. **WSL 2**: follow the Linux instructions inside your distribution. See [DEPENDENCIES.md](codev-skeleton/DEPENDENCIES.md#windows) for setup and limitations, including why native support is a preview (#1911).
**Windows:** two paths. **Native**: Node.js 22 or 24 (x64 or ARM64), [Git for Windows](https://git-scm.com/download/win) and `jq`, no admin rights or Developer Mode needed. **WSL 2**: follow the Linux instructions inside your distribution. See [DEPENDENCIES.md](codev-skeleton/DEPENDENCIES.md#windows) for setup and limitations.

**AI CLIs** (install all three for multi-model consultation):
- Claude Code: `npm install -g @anthropic-ai/claude-code`
Expand Down
46 changes: 44 additions & 2 deletions apps/vscode/src/__tests__/cli-process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,35 @@
* pass through unchanged.
*/

import { describe, it, expect, vi, beforeEach } from 'vitest';
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';

const childProcess = vi.hoisted(() => ({ spawn: vi.fn(() => ({ unref: vi.fn() })), execFile: vi.fn() }));
vi.mock('node:child_process', () => ({ spawn: childProcess.spawn, execFile: childProcess.execFile }));
vi.mock('node:child_process', async (importOriginal) => {
const actual = await importOriginal<typeof import('node:child_process')>();
return { ChildProcess: actual.ChildProcess, spawn: childProcess.spawn, execFile: childProcess.execFile };
});

const sdk = vi.hoisted(() => ({ resolveSpawnable: vi.fn() }));
vi.mock('@cluesmith/codev-sdk/node/executable', () => ({ resolveSpawnable: sdk.resolveSpawnable }));

import { spawnCodevCli, execCodevCli } from '../cli-process.js';

const realPlatform = process.platform;

function setPlatform(platform: NodeJS.Platform): void {
Object.defineProperty(process, 'platform', { value: platform, configurable: true });
}

beforeEach(() => {
childProcess.spawn.mockClear();
childProcess.execFile.mockReset();
sdk.resolveSpawnable.mockReset();
});

afterEach(() => {
setPlatform(realPlatform);
});

describe('spawnCodevCli', () => {
it('spawns the resolver output with its verbatim flag, hidden', () => {
sdk.resolveSpawnable.mockReturnValue({
Expand Down Expand Up @@ -57,6 +70,7 @@ describe('spawnCodevCli', () => {
});

it('execCodevCli rejects on a failing exit, carrying its output', async () => {
setPlatform('linux');
sdk.resolveSpawnable.mockImplementation((command: string, args: string[]) => ({ command, args, windowsVerbatimArguments: false }));
childProcess.execFile.mockImplementation((_file: string, _args: string[], _opts: unknown, cb: (e: Error | null, o: string, e2: string) => void) => {
cb(new Error('exit 1'), '', 'no such builder');
Expand All @@ -65,6 +79,7 @@ describe('spawnCodevCli', () => {
});

it('passes a POSIX command through unchanged', () => {
setPlatform('linux');
sdk.resolveSpawnable.mockImplementation((command: string, args: string[]) => ({ command, args, windowsVerbatimArguments: false }));
spawnCodevCli('codev', ['--version'], { cwd: '/repo' });
expect(childProcess.spawn).toHaveBeenCalledWith('codev', ['--version'], {
Expand All @@ -74,3 +89,30 @@ describe('spawnCodevCli', () => {
});
});
});

describe('a bare name not on PATH on Windows (#1911)', () => {
// The resolver hands an unresolved name back unchanged; spawning it would let
// Windows run a same-named program from the workspace folder instead.
beforeEach(() => {
setPlatform('win32');
sdk.resolveSpawnable.mockImplementation((command: string, args: string[]) => ({ command, args, windowsVerbatimArguments: false }));
});

it('spawnCodevCli never spawns it and emits ENOENT asynchronously', async () => {
const child = spawnCodevCli('afx', ['tower', 'start'], { cwd: 'C:\\ws' });
expect(childProcess.spawn).not.toHaveBeenCalled();
const error = await new Promise<NodeJS.ErrnoException>((resolve) => child.on('error', resolve));
expect(error).toMatchObject({ code: 'ENOENT', path: 'afx', syscall: 'spawn afx', spawnargs: ['tower', 'start'] });
});

it('execCodevCli never runs it and rejects with ENOENT', async () => {
await expect(execCodevCli('porch', ['approve', '42', 'pr'], { cwd: 'C:\\ws' })).rejects.toMatchObject({ code: 'ENOENT', path: 'porch' });
expect(childProcess.execFile).not.toHaveBeenCalled();
});

it('still spawns a name the resolver found', () => {
sdk.resolveSpawnable.mockReturnValue({ command: 'C:\\npm\\codev.exe', args: ['--version'], windowsVerbatimArguments: false });
spawnCodevCli('codev', ['--version'], {});
expect(childProcess.spawn).toHaveBeenCalledWith('C:\\npm\\codev.exe', ['--version'], { windowsHide: true, windowsVerbatimArguments: false });
});
});
53 changes: 53 additions & 0 deletions apps/vscode/src/__tests__/spawn-builder-not-found.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* #1911: when `afx` cannot be started (on Windows, `cli-process.ts` refuses a
* name that does not resolve on PATH and emits ENOENT), Spawn Builder shows a
* readable error instead of leaving an unhandled 'error' event.
*/

import { describe, it, expect, vi, beforeEach } from 'vitest';
import { EventEmitter } from 'node:events';

const vscodeMock = vi.hoisted(() => ({
window: {
showErrorMessage: vi.fn(),
showInformationMessage: vi.fn(),
showInputBox: vi.fn(),
showQuickPick: vi.fn(),
},
}));
vi.mock('vscode', () => vscodeMock);

const cli = vi.hoisted(() => ({ spawnCodevCli: vi.fn() }));
vi.mock('../cli-process.js', () => cli);

import { spawnBuilder } from '../commands/spawn.js';

function fakeChild(): EventEmitter & { unref: () => void } {
return Object.assign(new EventEmitter(), { unref: vi.fn() });
}

beforeEach(() => {
vi.clearAllMocks();
vscodeMock.window.showQuickPick.mockResolvedValue('pir');
});

describe('Spawn Builder when afx cannot start', () => {
it('says afx was not found on PATH for ENOENT', async () => {
const child = fakeChild();
cli.spawnCodevCli.mockReturnValue(child);
await spawnBuilder('42');
expect(cli.spawnCodevCli).toHaveBeenCalledWith('afx', ['spawn', '42', '--protocol', 'pir'], { detached: true, stdio: 'ignore' });

child.emit('error', Object.assign(new Error('spawn afx ENOENT'), { code: 'ENOENT' }));
expect(vscodeMock.window.showErrorMessage).toHaveBeenCalledWith(expect.stringContaining('afx was not found on PATH'));
});

it('shows the error message for any other failure', async () => {
const child = fakeChild();
cli.spawnCodevCli.mockReturnValue(child);
await spawnBuilder('42');

child.emit('error', Object.assign(new Error('spawn EACCES'), { code: 'EACCES' }));
expect(vscodeMock.window.showErrorMessage).toHaveBeenCalledWith('Codev: could not run afx: spawn EACCES');
});
});
36 changes: 34 additions & 2 deletions apps/vscode/src/cli-process.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
import { execFile, spawn, type ChildProcess, type ExecFileOptions, type SpawnOptions } from 'node:child_process';
import { resolveSpawnable } from '@cluesmith/codev-sdk/node/executable';
import { ChildProcess, execFile, spawn, type ExecFileOptions, type SpawnOptions } from 'node:child_process';
import { resolveSpawnable, type SpawnableCommand } from '@cluesmith/codev-sdk/node/executable';

/**
* Windows looks a bare name up in the current folder before `PATH` (#1911), so
* a `codev.exe` in the open workspace would run in place of Codev. The
* resolver searches `PATH` only and hands the name back unchanged when it is
* not there; that case must fail here rather than reach `spawn`. The extension
* host is shared with other extensions, so it does not set
* `NoDefaultCurrentDirectoryInExePath` process-wide as the Codev CLIs do.
*/
function unresolvedOnWindows(command: string, spawnable: SpawnableCommand): boolean {
return process.platform === 'win32' && spawnable.command === command && !/[\\/]/.test(command);
}

/** The ENOENT error `spawn` raises for a missing program. */
function notFoundError(command: string, args: string[]): NodeJS.ErrnoException {
return Object.assign(new Error(`spawn ${command} ENOENT (not found on PATH)`), {
code: 'ENOENT',
errno: -4058, // UV_ENOENT on Windows, the errno a real failed spawn carries
syscall: `spawn ${command}`,
path: command,
spawnargs: args,
});
}

/**
* Spawn a Codev CLI (`afx`, `codev`). On Windows each is an npm `.cmd` shim,
Expand All @@ -9,6 +32,12 @@ import { resolveSpawnable } from '@cluesmith/codev-sdk/node/executable';
*/
export function spawnCodevCli(command: string, args: string[], options: SpawnOptions): ChildProcess {
const spawnable = resolveSpawnable(command, args);
if (unresolvedOnWindows(command, spawnable)) {
// The async contract callers already handle: an 'error' event, never a throw.
const child = new ChildProcess();
process.nextTick(() => child.emit('error', notFoundError(command, args)));
return child;
}
return spawn(spawnable.command, spawnable.args, {
...options,
windowsHide: true,
Expand All @@ -28,6 +57,9 @@ export function execCodevCli(
options: ExecFileOptions,
): Promise<{ stdout: string; stderr: string }> {
const spawnable = resolveSpawnable(command, args);
if (unresolvedOnWindows(command, spawnable)) {
return Promise.reject(notFoundError(command, args));
}
return new Promise((resolve, reject) => {
execFile(spawnable.command, spawnable.args, {
...options,
Expand Down
4 changes: 4 additions & 0 deletions apps/vscode/src/commands/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export async function spawnBuilder(issueArg?: string): Promise<void> {

function runAfxCommand(args: string[]): void {
const child = spawnCodevCli('afx', args, { detached: true, stdio: 'ignore' });
child.on('error', (err: NodeJS.ErrnoException) => {
const reason = err.code === 'ENOENT' ? 'afx was not found on PATH (install @cluesmith/codev)' : err.message;
vscode.window.showErrorMessage(`Codev: could not run afx: ${reason}`);
});
child.unref();
vscode.window.showInformationMessage(`Codev: Running afx ${args.join(' ')}`);
}
18 changes: 11 additions & 7 deletions codev-skeleton/DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ sudo apt install nodejs npm git build-essential python3

### Windows

Codev supports two paths on Windows: native, with Git for Windows (a preview), and WSL 2.
Codev supports two paths on Windows: native, with Git for Windows, and WSL 2.

#### Native Windows (Git for Windows)

Expand Down Expand Up @@ -259,12 +259,16 @@ How it works and what to know:
- **PowerShell.** Tower uses the built-in `powershell.exe` (CIM) to list and stop the processes
each session starts. A machine policy that blocks it, or Constrained Language Mode, is not
supported; `codev doctor` and Tower's log report it.
- **Preview: only work in repositories you trust.** On Windows, a program started by bare name
(`git`, `gh`, `npm`, `node`) is looked up in the current folder before `PATH`, and Codev runs
many of those commands with a builder worktree or a cloned repository as the current folder.
A repository that contains, say, a `git.exe` would have that file run instead of Git. Codev's
own Windows tools (`powershell.exe`, `taskkill`, `cmd.exe`) already run by full system path;
the user tools follow (#1911), and native Windows support leaves preview with that fix.
- **Programs never run from the current folder.** Windows normally looks a program started by
bare name (`git`, `npm`) up in the current folder before `PATH`, so a `git.exe` inside a
repository could run in place of Git. Codev turns that lookup off (it sets
`NoDefaultCurrentDirectoryInExePath`) in its own processes, the commands they run, and every
terminal Tower opens: architect and builder sessions and shell tabs alike. In a `cmd.exe`
shell, a program in the current folder then runs only when you name its folder (`.\name`);
PowerShell already works this way. One known effect: a .NET 10 NativeAOT `dotnet publish` fails
inside a Codev terminal, because Visual Studio's `vcvarsall.bat` does not support the setting
(fixed in .NET 11; [dotnet/runtime#129340](https://github.com/dotnet/runtime/issues/129340)).
Codev runs its own Windows tools by full system path.
- **Known limitations.** Doctor cannot show Tower's environment on Windows (the process table does
not expose it). Building this repository from source on ARM64 fails in one bundler; installing
the published package on ARM64 works.
Expand Down
18 changes: 11 additions & 7 deletions codev/DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ sudo apt install nodejs npm git build-essential python3

### Windows

Codev supports two paths on Windows: native, with Git for Windows (a preview), and WSL 2.
Codev supports two paths on Windows: native, with Git for Windows, and WSL 2.

#### Native Windows (Git for Windows)

Expand Down Expand Up @@ -259,12 +259,16 @@ How it works and what to know:
- **PowerShell.** Tower uses the built-in `powershell.exe` (CIM) to list and stop the processes
each session starts. A machine policy that blocks it, or Constrained Language Mode, is not
supported; `codev doctor` and Tower's log report it.
- **Preview: only work in repositories you trust.** On Windows, a program started by bare name
(`git`, `gh`, `npm`, `node`) is looked up in the current folder before `PATH`, and Codev runs
many of those commands with a builder worktree or a cloned repository as the current folder.
A repository that contains, say, a `git.exe` would have that file run instead of Git. Codev's
own Windows tools (`powershell.exe`, `taskkill`, `cmd.exe`) already run by full system path;
the user tools follow (#1911), and native Windows support leaves preview with that fix.
- **Programs never run from the current folder.** Windows normally looks a program started by
bare name (`git`, `npm`) up in the current folder before `PATH`, so a `git.exe` inside a
repository could run in place of Git. Codev turns that lookup off (it sets
`NoDefaultCurrentDirectoryInExePath`) in its own processes, the commands they run, and every
terminal Tower opens: architect and builder sessions and shell tabs alike. In a `cmd.exe`
shell, a program in the current folder then runs only when you name its folder (`.\name`);
PowerShell already works this way. One known effect: a .NET 10 NativeAOT `dotnet publish` fails
inside a Codev terminal, because Visual Studio's `vcvarsall.bat` does not support the setting
(fixed in .NET 11; [dotnet/runtime#129340](https://github.com/dotnet/runtime/issues/129340)).
Codev runs its own Windows tools by full system path.
- **Known limitations.** Doctor cannot show Tower's environment on Windows (the process table does
not expose it). Building this repository from source on ARM64 fails in one bundler; installing
the published package on ARM64 works.
Expand Down
Loading
Loading