Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
feat: hot-reload workspaces on register via SIGHUP
Gener6778693e36f5
diff --git a/src/cli/commands/register.ts b/src/cli/commands/register.tsindex d8df7818f..e23bf3714 100644--- a/src/cli/commands/register.ts+++ b/src/cli/commands/register.ts@@ -4,6 +4,7 @@ import { hostname } from "os";import { APIClient } from "../lib/client.js";import { loadCLIConfigForProfile, saveCLIConfigForProfile } from "../lib/config.js";import { cmdPrefix } from "../lib/env.js";+import { readDaemonPid, isProcessAlive } from "../daemon/pidfile.js";interface MeResponse {id: string;@@ -176,10 +177,22 @@ export function registerCommand(): Command {console.log(`\nRegistered as ${me.email}`);console.log(`Workspace: ${ws.name} (${ws.id})`);console.log(`Runtimes: ${activateResp.runtimes.map((r) => r.provider).join(", ")}`);- console.log();- console.log(- `Run '${cmdPrefix()} daemon start --foreground' to start the daemon.`,- );++ // Notify running daemon to pick up the new workspace+ const daemonPid = readDaemonPid(profile);+ if (daemonPid && isProcessAlive(daemonPid)) {+ try {+ process.kill(daemonPid, "SIGHUP");+ console.log(`\nDaemon (pid ${daemonPid}) notified — workspace will be active shortly.`);+ } catch {+ console.log(`\nDaemon is running but could not be notified. Restart it to pick up the new workspace.`);+ }+ } else {+ console.log();+ console.log(+ `Run '${cmdPrefix()} daemon start --foreground' to start the daemon.`,+ );+ }});return cmd;diff --git a/src/cli/daemon/daemon.ts b/src/cli/daemon/daemon.tsindex c96a7a889..67c8eb1c1 100644--- a/src/cli/daemon/daemon.ts+++ b/src/cli/daemon/daemon.ts@@ -544,6 +544,59 @@ export async function startDaemon(};process.on("SIGTERM", shutdown);process.on("SIGINT", shutdown);++ // SIGHUP: reload config and register any new workspaces+ process.on("SIGHUP", async () => {+ if (shuttingDown) return;+ log.info("SIGHUP received — reloading config...");+ try {+ const freshConfig = loadCLIConfigForProfile(profile);+ const freshWorkspaces = freshConfig.watched_workspaces || [];+ const existingIds = new Set(workspaceStates.map((ws) => ws.workspaceId));++ const newWorkspaces = freshWorkspaces.filter(+ (ws) => ws.token && !existingIds.has(ws.id),+ );++ for (const ws of newWorkspaces) {+ const runtimes = providers.map((p) => ({ type: p.type, version: p.version }));+ log.info(`Registering new workspace ${ws.id} (${ws.name ?? "unnamed"})...`);+ try {+ const resp = await client.register(ws.token, {+ workspace_id: ws.id,+ daemon_id: config.daemonId,+ device_name: config.deviceName,+ cli_version: config.cliVersion,+ runtimes,+ });+ const runtimeIds = resp.runtimes.map((r: { id: string }) => r.id);+ workspaceStates.push({ workspaceId: ws.id, token: ws.token, runtimeIds });+ for (let i = 0; i < runtimeIds.length; i++) {+ runtimeIndex.set(runtimeIds[i], {+ id: runtimeIds[i],+ workspaceId: ws.id,+ provider: providers[i].type,+ });+ }+ log.info(`Workspace ${ws.id} added — ${runtimeIds.length} runtime(s)`);+ } catch (e) {+ log.error(`Failed to register new workspace ${ws.id}`, e);+ }+ }++ if (newWorkspaces.length > 0) {+ health.setRuntimeCount(+ workspaceStates.reduce((sum, w) => sum + w.runtimeIds.length, 0),+ );+ log.info(`Reload complete — now polling ${workspaceStates.length} workspace(s)`);+ } else {+ log.info("Reload complete — no new workspaces found");+ }+ } catch (e) {+ log.error("Failed to reload config", e);+ }+ });+await pollCycle();}