Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 9 additions & 3 deletions lib/provider-detection.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
const { execSync, spawnSync } = require('child_process');
const childProcess = require('child_process');
const { execSync, spawnSync } = childProcess;
const fs = require('fs');
const path = require('path');

function commandLookupCommand(command) {
return process.platform === 'win32' ? `where ${command}` : `command -v ${command}`;
}

function commandExists(command) {
if (!command) return false;
if (command.includes(path.sep)) {
return fs.existsSync(command);
}
try {
execSync(`command -v ${command}`, { stdio: 'pipe' });
execSync(commandLookupCommand(command), { stdio: 'pipe' });
return true;
} catch {
return false;
Expand All @@ -21,7 +26,7 @@ function getCommandPath(command) {
return fs.existsSync(command) ? command : null;
}
try {
const output = execSync(`command -v ${command}`, { encoding: 'utf8', stdio: 'pipe' });
const output = execSync(commandLookupCommand(command), { encoding: 'utf8', stdio: 'pipe' });
return output.trim() || null;
} catch {
return null;
Expand Down Expand Up @@ -56,4 +61,5 @@ module.exports = {
getCommandPath,
getHelpOutput,
getVersionOutput,
commandLookupCommand,
};
1 change: 1 addition & 0 deletions src/agent/agent-task-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ function spawnTaskProcess({ agent, ctPath, args, cwd, spawnEnv }) {
cwd,
stdio: ['ignore', 'pipe', 'pipe'],
env: spawnEnv,
windowsHide: true,
});

// NOTE: Don't emit PROCESS_SPAWNED here - proc.pid is a wrapper that exits immediately.
Expand Down
1 change: 1 addition & 0 deletions src/claude-task-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class ClaudeTaskRunner extends TaskRunner {
cwd,
stdio: ['ignore', 'pipe', 'pipe'],
env: spawnEnv,
windowsHide: true,
});

let stdout = '';
Expand Down
1 change: 1 addition & 0 deletions task-lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ function spawnWatcher({ watcherScript, id, cwd, logFile, finalArgs, watcherConfi
{
detached: true,
stdio: 'ignore',
windowsHide: true,
}
);

Expand Down
1 change: 1 addition & 0 deletions task-lib/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const child = spawn(command, finalArgs, {
cwd,
env,
stdio: ['ignore', 'pipe', 'pipe'],
windowsHide: true,
});

updateTask(taskId, { pid: child.pid });
Expand Down
20 changes: 20 additions & 0 deletions tests/providers/detection.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const assert = require('assert');
const sinon = require('sinon');
const {
commandExists,
getCommandPath,
getHelpOutput,
getVersionOutput,
commandLookupCommand,
} = require('../../lib/provider-detection');

describe('Provider CLI detection', () => {
Expand All @@ -28,3 +30,21 @@ describe('Provider CLI detection', () => {
assert.ok(version.length > 0);
});
});

describe('commandLookupCommand', () => {
let platformStub;

afterEach(() => {
if (platformStub) platformStub.restore();
});

it('uses where on Windows', () => {
platformStub = sinon.stub(process, 'platform').value('win32');
assert.strictEqual(commandLookupCommand('claude'), 'where claude');
});

it('uses command -v on non-Windows platforms', () => {
platformStub = sinon.stub(process, 'platform').value('linux');
assert.strictEqual(commandLookupCommand('claude'), 'command -v claude');
});
});