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
fix: restore short daemon commands
Gus1505aa7a4985
diff --git a/.env.example b/.env.exampleindex 8be7b87f5..3b4f5e412 100644--- a/.env.example+++ b/.env.example@@ -128,10 +128,10 @@# WebSocket Durable Object port (dev only, must match src/ws-do/wrangler.toml)# NEXT_PUBLIC_WS_DO_PORT=8789-# The community pair sheet's copyable `npm exec --yes-# --package=@alook/daemon@latest -- alook-daemon daemon start --server-url <...>-# --ws-url <...>` command derives both URLs from the-# browser's own location.origin (same pattern as use-user-ws.ts) — ws-do routes+# In production, the community pair sheet's copyable command relies on the+# daemon's default server URLs. Local development appends `--server-url` and+# `--ws-url` derived from the browser's own location.origin (same pattern as+# use-user-ws.ts) — ws-do routes# community-daemon connections by their `Authorization: Bearer cmk_...`# header, not by host, so there's no dedicated env var for it. See# NEXT_PUBLIC_WS_DO_PORT above for the local dev WS port it falls back to.diff --git a/src/daemon/README.md b/src/daemon/README.mdindex 5fdfec440..8ea7b8402 100644--- a/src/daemon/README.md+++ b/src/daemon/README.md@@ -27,25 +27,23 @@ is what's reusable — plug in whatever host you like.## Daemon lifecycle commands-The web Machines sheet generates the full command, including the correct HTTP-and WebSocket endpoints. Published-package commands use the package's explicit-binary so npm never guesses the wrong executable:+The web Machines sheet generates the full command. Production commands use the+built-in Alook endpoints; local development commands include explicit local URLs:```sh-npm exec --yes --package=@alook/daemon@latest -- alook-daemon daemon start \- --machine-key '<cmt_pair_token>' --server-url '<https_url>' --ws-url '<wss_url>'+npx --yes @alook/daemon@latest daemon start --machine-key '<cmt_pair_token>'```Restart a previously paired machine without rotating its credential:```sh-npm exec --yes --package=@alook/daemon@latest -- alook-daemon daemon start --id '<machine_id>'+npx --yes @alook/daemon@latest daemon start --id '<machine_id>'```Reconnect/rotate only with the command generated for that exact machine:```sh-npm exec --yes --package=@alook/daemon@latest -- alook-daemon daemon reconnect \+npx --yes @alook/daemon@latest daemon reconnect \--id '<machine_id>' --machine-key '<cmt_reconnect_token>'```diff --git a/src/daemon/src/cli/daemonStart.lifecycle.test.ts b/src/daemon/src/cli/daemonStart.lifecycle.test.tsindex d9ea0bb81..5e21a20e1 100644--- a/src/daemon/src/cli/daemonStart.lifecycle.test.ts+++ b/src/daemon/src/cli/daemonStart.lifecycle.test.ts@@ -41,6 +41,8 @@ describe("daemon lifecycle ownership cleanup", () => {afterEach(() => {delete process.env.ALOOK_DAEMON_TEST_FAIL_AFTER_ACTIVATE;+ delete process.env.ALOOK_SERVER_URL;+ delete process.env.ALOOK_SERVER_WS_URL;vi.useRealTimers();vi.restoreAllMocks();fs.rmSync(baseDir, { recursive: true, force: true });@@ -66,6 +68,74 @@ describe("daemon lifecycle ownership cleanup", () => {return { machineId, daemonDir };}+ it("uses production endpoints when first-pair URL overrides are absent", async () => {+ await expect(daemonStart({+ machineKey: "cmk_test",+ baseDir,+ foreground: true,+ })).rejects.toThrow("runner init failed");++ expect(globalThis.fetch).toHaveBeenCalledWith(+ "https://alook.ai/api/community/daemon/identity",+ expect.any(Object),+ );+ expect(mockRunPreparedDaemon).toHaveBeenCalledWith(+ expect.objectContaining({+ serverUrl: "https://alook.ai",+ wsUrl: "wss://alook.ai/api/ws/community-daemon",+ }),+ expect.any(Object),+ );+ });++ it("prefers endpoint environment variables over production defaults", async () => {+ process.env.ALOOK_SERVER_URL = "https://env.example";+ process.env.ALOOK_SERVER_WS_URL = "wss://env.example/control";++ await expect(daemonStart({+ machineKey: "cmk_test",+ baseDir,+ foreground: true,+ })).rejects.toThrow("runner init failed");++ expect(globalThis.fetch).toHaveBeenCalledWith(+ "https://env.example/api/community/daemon/identity",+ expect.any(Object),+ );+ expect(mockRunPreparedDaemon).toHaveBeenCalledWith(+ expect.objectContaining({+ serverUrl: "https://env.example",+ wsUrl: "wss://env.example/control",+ }),+ expect.any(Object),+ );+ });++ it("prefers explicit endpoint flags over environment variables", async () => {+ process.env.ALOOK_SERVER_URL = "https://env.example";+ process.env.ALOOK_SERVER_WS_URL = "wss://env.example/control";++ await expect(daemonStart({+ machineKey: "cmk_test",+ serverUrl: "https://flag.example",+ wsUrl: "wss://flag.example/control",+ baseDir,+ foreground: true,+ })).rejects.toThrow("runner init failed");++ expect(globalThis.fetch).toHaveBeenCalledWith(+ "https://flag.example/api/community/daemon/identity",+ expect.any(Object),+ );+ expect(mockRunPreparedDaemon).toHaveBeenCalledWith(+ expect.objectContaining({+ serverUrl: "https://flag.example",+ wsUrl: "wss://flag.example/control",+ }),+ expect.any(Object),+ );+ });+it("fails exact-machine ownership before activation when replacement is already owned", async () => {const { machineId, daemonDir } = writeReconnectState();fs.writeFileSync(path.join(daemonDir, "daemon.replace.lock"), JSON.stringify({diff --git a/src/daemon/src/cli/daemonStart.ts b/src/daemon/src/cli/daemonStart.tsindex 2ba041e53..3c356f74a 100644--- a/src/daemon/src/cli/daemonStart.ts+++ b/src/daemon/src/cli/daemonStart.ts@@ -37,6 +37,8 @@ const RUNNER_TERM_GRACE_MS = 2_000;const RUNNER_KILL_GRACE_MS = 2_000;const MACHINE_ID_PATTERN = /^cm_[A-Za-z0-9_-]{8,64}$/;const LEGACY_DAEMON_ID_PATTERN = /^[a-f0-9]{12}$/;+const DEFAULT_SERVER_URL = "https://alook.ai";+const DEFAULT_WS_URL = "wss://alook.ai/api/ws/community-daemon";function resolveDefaultBaseDir(): string {const root = process.env.ALOOK_PROJECT_ROOT || path.join(homedir(), ".alook");@@ -967,10 +969,8 @@ interface PreparedStart {}async function prepareDaemonStart(opts: DaemonStartOpts): Promise<PreparedStart> {- const serverUrl = opts.serverUrl || process.env.ALOOK_SERVER_URL;- const wsUrl = opts.wsUrl || process.env.ALOOK_SERVER_WS_URL;- if (!serverUrl) throw new Error("Server URL required — pass --server-url or set ALOOK_SERVER_URL");- if (!wsUrl) throw new Error("WebSocket URL required — pass --ws-url or set ALOOK_SERVER_WS_URL");+ const serverUrl = opts.serverUrl || process.env.ALOOK_SERVER_URL || DEFAULT_SERVER_URL;+ const wsUrl = opts.wsUrl || process.env.ALOOK_SERVER_WS_URL || DEFAULT_WS_URL;if (!opts.machineKey.startsWith("cmt_") && !opts.machineKey.startsWith("cmk_")) {throw new Error("invalid machine key format — expected `cmt_` or `cmk_`");}diff --git a/src/daemon/src/cli/index.ts b/src/daemon/src/cli/index.tsindex 9a3fea34b..071754574 100755--- a/src/daemon/src/cli/index.ts+++ b/src/daemon/src/cli/index.ts@@ -1032,8 +1032,8 @@ function buildProgram(stdin: CliInputStream): Command {.description("start the daemon (connects to server, manages agent lifecycles)").option("--machine-key <key>", "machine key for first-time pairing").option("--id <machineId>", "restart a previously paired machine by id")- .option("--server-url <url>", "server HTTP URL (or ALOOK_SERVER_URL env)")- .option("--ws-url <url>", "server WebSocket URL (or ALOOK_SERVER_WS_URL env)")+ .option("--server-url <url>", "server HTTP URL (or ALOOK_SERVER_URL; defaults to production)")+ .option("--ws-url <url>", "server WebSocket URL (or ALOOK_SERVER_WS_URL; defaults to production)").option("--base-dir <path>", "data directory for agent workspaces and pidfile (or ALOOK_DATA_DIR env)").option("--foreground", "run in the current process and tee daemon logs to the terminal").exitOverride()diff --git a/src/web/src/components/community/machines/pair-machine-sheet.test.ts b/src/web/src/components/community/machines/pair-machine-sheet.test.tsindex 0037368ea..ac73bb30b 100644--- a/src/web/src/components/community/machines/pair-machine-sheet.test.ts+++ b/src/web/src/components/community/machines/pair-machine-sheet.test.ts@@ -6,6 +6,7 @@ const mocks = vi.hoisted(() => ({apiFetch: vi.fn(),invoke: vi.fn(),isTauri: vi.fn(() => true),+ isLocalMode: vi.fn(() => false),toastSuccess: vi.fn(),toastError: vi.fn(),}))@@ -26,7 +27,7 @@ vi.mock("@/lib/api/client", () => ({}))vi.mock("@/lib/utils", () => ({- isLocalMode: () => false,+ isLocalMode: mocks.isLocalMode,WS_DO_PORT_DEFAULT: 8788,}))@@ -54,6 +55,7 @@ describe("PairMachineSheet desktop daemon integration", () => {vi.clearAllMocks()vi.stubGlobal("location", { origin: "https://alook.ai" })mocks.isTauri.mockReturnValue(true)+ mocks.isLocalMode.mockReturnValue(false)mocks.apiFetch.mockResolvedValue({ tokenId: "cmt_generated", expiresAt: "soon" })mocks.invoke.mockImplementation((command: string) => {if (command === "daemon_runtime_capability") {@@ -88,11 +90,15 @@ describe("PairMachineSheet desktop daemon integration", () => {expect(mocks.invoke.mock.calls.filter(([command]) => command === "daemon_pair")).toHaveLength(1)expect(mocks.toastSuccess).toHaveBeenCalledWith("This computer is connecting")expect(renderer.root.findByProps({ "data-testid": tid.machinePairDesktopConnect }).props.disabled).toBe(true)- expect(renderer.root.findByProps({ "data-testid": tid.machinePairCommand }).children.join(""))- .toContain("@alook/daemon")+ const command = renderer.root.findByProps({ "data-testid": tid.machinePairCommand }).children.join("")+ expect(command).toContain("npx --yes @alook/daemon@latest daemon start")+ expect(command).toContain("--machine-key cmt_desktop_token")+ expect(command).not.toContain("npm exec --yes --package=@alook/daemon@latest -- alook-daemon")+ expect(command).not.toContain("--server-url")+ expect(command).not.toContain("--ws-url")})- it("uses the explicit exact-machine reconnect command in terminal and native paths", async () => {+ it("uses the short exact-machine reconnect command in terminal and native paths", async () => {let renderer!: TestRenderer.ReactTestRendererawait act(async () => {renderer = TestRenderer.create(React.createElement(PairMachineSheet, {@@ -108,8 +114,10 @@ describe("PairMachineSheet desktop daemon integration", () => {const command = renderer.root.findByProps({ "data-testid": tid.machinePairCommand }).children.join("")- expect(command).toContain("npm exec --yes --package=@alook/daemon@latest -- alook-daemon daemon reconnect")+ expect(command).toContain("npx --yes @alook/daemon@latest daemon reconnect")expect(command).toContain("--id cm_abcdefgh --machine-key cmt_reconnect_token")+ expect(command).not.toContain("--server-url")+ expect(command).not.toContain("--ws-url")await act(async () => {await renderer.root.findByProps({ "data-testid": tid.machinePairDesktopConnect }).props.onClick()@@ -223,7 +231,7 @@ describe("PairMachineSheet desktop daemon integration", () => {let renderer!: TestRenderer.ReactTestRendereract(() => {renderer = TestRenderer.create(React.createElement(PairMachineSteps, {- command: "npm exec --yes --package=@alook/daemon@latest -- alook-daemon daemon start",+ command: "npx --yes @alook/daemon@latest daemon start",generating: false,onCopy: vi.fn(),connectedHostname: null,@@ -234,4 +242,25 @@ describe("PairMachineSheet desktop daemon integration", () => {.toContain("@alook/daemon")expect(renderer.root.findAllByProps({ "data-testid": tid.machinePairDesktopConnect })).toHaveLength(0)})++ it("keeps explicit endpoints only for local development", async () => {+ mocks.isLocalMode.mockReturnValue(true)+ vi.stubGlobal("location", { origin: "http://localhost:3000" })++ let renderer!: TestRenderer.ReactTestRenderer+ await act(async () => {+ renderer = TestRenderer.create(React.createElement(PairMachineSheet, {+ open: true,+ onOpenChange: vi.fn(),+ pendingTokenId: "cmt_local_token",+ setPendingTokenId: vi.fn(),+ connectedHostname: null,+ }))+ })++ const command = renderer.root.findByProps({ "data-testid": tid.machinePairCommand }).children.join("")+ expect(command).toContain("pnpm daemon start --machine-key cmt_local_token")+ expect(command).toContain("--server-url http://localhost:3000")+ expect(command).toContain("--ws-url ws://localhost:8788/api/ws/community-daemon")+ })})diff --git a/src/web/src/components/community/machines/pair-machine-sheet.tsx b/src/web/src/components/community/machines/pair-machine-sheet.tsxindex 6280fcc30..da651fb1d 100644--- a/src/web/src/components/community/machines/pair-machine-sheet.tsx+++ b/src/web/src/components/community/machines/pair-machine-sheet.tsx@@ -20,31 +20,26 @@ import { tid } from "@/lib/community/testids"import { isLocalMode, WS_DO_PORT_DEFAULT } from "@/lib/utils"import { websocketUrl } from "@/lib/websocket-url"-// Community daemon HTTP/WS endpoints live on the same worker + ws-do as the-// rest of the app — see use-user-ws.ts, which connects to the identical-// ws-do for the user's live WS channel. ws-do routes community-daemon-// connections by their `Authorization: Bearer cmk_...` header, not by host-// or path, so we reuse that exact local/origin split instead of introducing-// a separate URL concept (or env vars) just for this sheet.-const isLocal = isLocalMode()-+// Production daemons use their built-in endpoints. Local development appends+// the browser origin and local ws-do address so the command stays on the dev stack.// Only ever called once `pendingTokenId` is set, which happens from a-// client-only effect — safe to touch `location` here (never runs during SSR).+// client-only effect — safe to touch `location` in the local branch.function buildPairCommand(machineKey: string, machineId?: string): string {- const { serverUrl, wsUrl } = pairEndpoints()+ const isLocal = isLocalMode()const bin = isLocal? "pnpm daemon"- : "npm exec --yes --package=@alook/daemon@latest -- alook-daemon daemon"+ : "npx --yes @alook/daemon@latest daemon"const action = machineId? `reconnect --id ${machineId} --machine-key ${machineKey}`: `start --machine-key ${machineKey}`- return `${bin} ${action} --server-url ${serverUrl} --ws-url ${wsUrl}`+ const command = `${bin} ${action}`+ if (!isLocal) return command+ const { serverUrl, wsUrl } = pairEndpoints()+ return `${command} --server-url ${serverUrl} --ws-url ${wsUrl}`}function pairEndpoints(): { serverUrl: string; wsUrl: string } {- const wsUrl = isLocal- ? websocketUrl("community-daemon", { local: true, port: WS_DO_PORT_DEFAULT })- : websocketUrl("community-daemon", { local: false, origin: location.origin })+ const wsUrl = websocketUrl("community-daemon", { local: true, port: WS_DO_PORT_DEFAULT })return { serverUrl: location.origin, wsUrl }}diff --git a/src/web/src/components/home/landing-content.test.ts b/src/web/src/components/home/landing-content.test.tsindex 2be6340b9..7d57b5a6b 100644--- a/src/web/src/components/home/landing-content.test.ts+++ b/src/web/src/components/home/landing-content.test.ts@@ -134,9 +134,11 @@ describe("landing content contract", () => {expect(shellSource).not.toMatch(/<h[1-6]\b/)expect(shellSource).toContain(- "npm exec --yes --package=@alook/daemon@latest -- alook-daemon daemon start",+ "npx --yes @alook/daemon@latest daemon start",)- expect(shellSource).not.toMatch(/npx(?: --yes)? @alook\/daemon/)+ expect(shellSource).not.toContain("npm exec --yes --package=@alook/daemon@latest -- alook-daemon")+ expect(shellSource).not.toContain("--server-url https://alook.ai")+ expect(shellSource).not.toContain("--ws-url wss://alook.ai")expect(shellSource.match(/<DmHeader dm=\{DMS\[0\]\} titleAs="div" \/>/g)).toHaveLength(2)expect(shellSource).toContain('headingAs="div"')expect(dmHeaderSource).toContain('titleAs: Title = "h1"')diff --git a/src/web/src/components/home/landing-shell-motion.tsx b/src/web/src/components/home/landing-shell-motion.tsxindex b6e943d25..f6a895210 100644--- a/src/web/src/components/home/landing-shell-motion.tsx+++ b/src/web/src/components/home/landing-shell-motion.tsx@@ -507,7 +507,7 @@ const BOT_AVATAR_DRAFT: AvatarDraft = {}const PAIR_COMMAND =- "npm exec --yes --package=@alook/daemon@latest -- alook-daemon daemon start --machine-key cmk_demo --server-url https://alook.ai --ws-url wss://alook.ai/api/ws/community-daemon"+ "npx --yes @alook/daemon@latest daemon start --machine-key cmk_demo"function useReducedMotion() {const [reduced, setReduced] = useState(false)