feat: support multiple workspace roots (#584)

This commit is contained in:
junes
2026-05-07 08:30:52 +08:00
committed by GitHub
parent e17d7e5995
commit 0006d04f9e
16 changed files with 302 additions and 126 deletions
+7 -7
View File
@@ -22,10 +22,10 @@ import { startRunnerControlServer } from './controlServer';
import { createWorktree, removeWorktree, type WorktreeInfo } from './worktree';
import { join } from 'path';
import { buildMachineMetadata } from '@/agent/sessionFactory';
import { resolveWorkspaceRoot } from '@/utils/workspaceRoot';
import { resolveWorkspaceRoots } from '@/utils/workspaceRoot';
import { hashRunnerCliApiToken } from './runnerIdentity';
export async function startRunner(options: { workspaceRoot?: string } = {}): Promise<void> {
export async function startRunner(options: { workspaceRoots?: string[] } = {}): Promise<void> {
// We don't have cleanup function at the time of server construction
// Control flow is:
// 1. Create promise that will resolve when shutdown is requested
@@ -685,14 +685,14 @@ export async function startRunner(options: { workspaceRoot?: string } = {}): Pro
// Create API client
const api = await ApiClient.create();
const workspaceRoot = resolveWorkspaceRoot(options.workspaceRoot);
logger.debug(`[RUNNER RUN] Workspace root: ${workspaceRoot ?? '(not set)'}`);
const workspaceRoots = resolveWorkspaceRoots(options.workspaceRoots);
logger.debug(`[RUNNER RUN] Workspace roots: ${workspaceRoots?.join(', ') ?? '(not set)'}`);
// Get or create machine (with retry for transient connection errors)
const machine = await withRetry(
() => api.getOrCreateMachine({
machineId,
metadata: buildMachineMetadata({ workspaceRoot }),
metadata: buildMachineMetadata({ workspaceRoots }),
runnerState: initialRunnerState
}),
{
@@ -709,7 +709,7 @@ export async function startRunner(options: { workspaceRoot?: string } = {}): Pro
logger.debug(`[RUNNER RUN] Machine registered: ${machine.id}`);
// Create realtime machine session
const apiMachine = api.machineSyncClient(machine, { workspaceRoot });
const apiMachine = api.machineSyncClient(machine, { workspaceRoots });
// Set RPC handlers
apiMachine.setRPCHandlers({
@@ -725,7 +725,7 @@ export async function startRunner(options: { workspaceRoot?: string } = {}): Pro
// regardless of the verbose/quiet logger setting.
console.log('');
console.log('Hapi runner started.');
console.log(` Workspace root: ${workspaceRoot ?? '(not set — browse disabled; pass --workspace-root to enable)'}`);
console.log(` Workspace roots: ${workspaceRoots?.join(', ') ?? '(not set — browse disabled; pass --workspace-root to enable)'}`);
console.log(` Hub URL: ${configuration.apiUrl}`);
console.log(` Machine ID: ${machine.id}`);
console.log(` Control port: ${controlPort}`);