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,
};
20 changes: 19 additions & 1 deletion src/agent/agent-task-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,12 @@ function spawnTaskProcess({ agent, ctPath, args, cwd, spawnEnv }) {
const SPAWN_TIMEOUT_MS = 30000; // 30 seconds to spawn task

return new Promise((resolve, reject) => {
const proc = spawn(ctPath, args, {
const spawnSpec = buildZeroshotSpawnSpec(ctPath, args);
const proc = spawn(spawnSpec.command, spawnSpec.args, {
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 Expand Up @@ -1256,6 +1258,21 @@ function followClaudeTaskLogs(agent, taskId) {
return createLogFollower({ agent, taskId, fsModule, ctPath, providerName });
}


function buildZeroshotSpawnSpec(ctPath, args) {
if (process.platform === 'win32') {
return {
command: process.execPath,
args: [path.join(__dirname, '../../cli/index.js'), ...args],
};
}

return {
command: ctPath,
args,
};
}

// Cache zeroshot path at module load time (when PATH is correct)
let _cachedZeroshotPath = null;
function _resolveZeroshotPath() {
Expand Down Expand Up @@ -1917,6 +1934,7 @@ module.exports = {
waitForTaskReady,
spawnClaudeTaskIsolated,
getClaudeTasksPath,
buildZeroshotSpawnSpec,
parseResultOutput,
killTask,
};
5 changes: 4 additions & 1 deletion src/claude-task-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const TaskRunner = require('./task-runner');
const { loadSettings } = require('../lib/settings');
const { normalizeProviderName } = require('../lib/provider-names');
const { getProvider } = require('./providers');
const { buildZeroshotSpawnSpec } = require('./agent/agent-task-executor');

class ClaudeTaskRunner extends TaskRunner {
/**
Expand Down Expand Up @@ -196,10 +197,12 @@ class ClaudeTaskRunner extends TaskRunner {
*/
_spawnAndGetTaskId(ctPath, args, cwd, spawnEnv, _agentId) {
return new Promise((resolve, reject) => {
const proc = spawn(ctPath, args, {
const spawnSpec = buildZeroshotSpawnSpec(ctPath, args);
const proc = spawn(spawnSpec.command, spawnSpec.args, {
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
46 changes: 46 additions & 0 deletions tests/providers/detection.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
const assert = require('assert');
const sinon = require('sinon');
const path = require('path');
const {
commandExists,
getCommandPath,
getHelpOutput,
getVersionOutput,
commandLookupCommand,
} = require('../../lib/provider-detection');

describe('Provider CLI detection', () => {
Expand All @@ -28,3 +31,46 @@ 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');
});
});

const { buildZeroshotSpawnSpec } = require('../../src/agent/agent-task-executor');

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

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

it('uses node + cli script on Windows', () => {
platformStub = sinon.stub(process, 'platform').value('win32');
const spec = buildZeroshotSpawnSpec('zeroshot', ['task', 'run']);
assert.strictEqual(spec.command, process.execPath);
assert.strictEqual(spec.args[0], path.resolve(process.cwd(), 'cli/index.js'));
assert.deepStrictEqual(spec.args.slice(1), ['task', 'run']);
});

it('uses the resolved zeroshot command on non-Windows platforms', () => {
platformStub = sinon.stub(process, 'platform').value('linux');
const spec = buildZeroshotSpawnSpec('/usr/local/bin/zeroshot', ['task', 'run']);
assert.strictEqual(spec.command, '/usr/local/bin/zeroshot');
assert.deepStrictEqual(spec.args, ['task', 'run']);
});
});