Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix: use serverUrl for workspace URL and remove brittle onboard test (#266)

Gener928c5a17fc32
diff --git a/src/cli/commands/login.ts b/src/cli/commands/login.ts
index 0cbed1510..5dd623d0e 100644
--- a/src/cli/commands/login.ts
+++ b/src/cli/commands/login.ts
@@ -4,6 +4,7 @@ import { fileURLToPath } from "url";
import { APIClient } from "../lib/client.js";
import { activateAndSave } from "../lib/activate.js";
import { loadCLIConfigForProfile } from "../lib/config.js";
+import { cmdPrefix, getServerUrl } from "../lib/env.js";
const DEVICE_CLIENT_ID = process.env.ALOOK_DEVICE_CLIENT_ID || "alook-cli";
@@ -213,8 +214,7 @@ export function loginCommand(): Command {
const serverUrl: string =
opts.server ||
command.parent?.opts().server ||
- process.env.ALOOK_SERVER_URL ||
- "https://alook.ai";
+ getServerUrl();
// Check if already authenticated (skip with --force)
if (!opts.force) {
@@ -279,7 +279,7 @@ export function loginCommand(): Command {
child.unref();
console.log(" Polling for authorization in the background (timeout: 5min).");
- console.log(" Once approved, run `npx @alook/cli status` to verify.");
+ console.log(` Once approved, run \`${cmdPrefix()} status\` to verify.`);
return;
}
diff --git a/src/cli/commands/register.ts b/src/cli/commands/register.ts
index 4585648d3..1aa43abe8 100644
--- a/src/cli/commands/register.ts
+++ b/src/cli/commands/register.ts
@@ -1,6 +1,6 @@
import { Command } from "commander";
import { APIClient } from "../lib/client.js";
-import { cmdPrefix } from "../lib/env.js";
+import { cmdPrefix, getServerUrl } from "../lib/env.js";
import { activateAndSave } from "../lib/activate.js";
interface MeResponse {
@@ -21,8 +21,7 @@ export function registerCommand(): Command {
const serverUrl: string =
opts.server ||
command.parent?.opts().server ||
- process.env.ALOOK_SERVER_URL ||
- "https://alook.ai";
+ getServerUrl();
if (!token) {
console.error(
diff --git a/src/cli/commands/workspace.test.ts b/src/cli/commands/workspace.test.ts
index ca11e2b6f..40c252f0c 100644
--- a/src/cli/commands/workspace.test.ts
+++ b/src/cli/commands/workspace.test.ts
@@ -93,7 +93,7 @@ describe("workspace init", () => {
}));
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining("Workspace initialized"));
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining("[email protected]"));
- expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining("https://alook.ai/w/test-ws"));
+ expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining("http://localhost:3000/w/test-ws"));
});
it("errors when JSON file does not exist", async () => {
diff --git a/src/cli/commands/workspace.ts b/src/cli/commands/workspace.ts
index d6e1a3955..1bb57bf10 100644
--- a/src/cli/commands/workspace.ts
+++ b/src/cli/commands/workspace.ts
@@ -1,6 +1,8 @@
import { Command } from "commander";
import { readFileSync } from "fs";
+import { toAlookAddress } from "@alook/shared";
import { APIClient } from "../lib/client.js";
+import { cmdPrefix } from "../lib/env.js";
import { printJSON } from "../lib/output.js";
import { resolveClientOpts } from "../lib/resolve-client.js";
@@ -68,7 +70,7 @@ export function workspaceCommand(): Command {
}
if (runtimes.length === 0) {
- console.error("Error: No daemon registered. Run 'npx @alook/cli daemon start' first.");
+ console.error(`Error: No daemon registered. Run '${cmdPrefix()} daemon start' first.`);
process.exit(1);
}
@@ -137,10 +139,10 @@ export function workspaceCommand(): Command {
console.log(`\nWorkspace initialized: ${res.studio.name || res.workspace.name}`);
console.log("Agents created:");
for (const agent of res.agents) {
- const email = agent.email_handle ? `${agent.email_handle}@alook.ai` : "no email";
+ const email = agent.email_handle ? toAlookAddress(agent.email_handle) : "no email";
console.log(` - ${agent.name} (${email})`);
}
- console.log(`\n Open: https://alook.ai/w/${res.workspace.slug}`);
+ console.log(`\n Open: ${serverUrl}/w/${res.workspace.slug}`);
} catch (err) {
console.error(`Error: failed to create workspace: ${err instanceof Error ? err.message : err}`);
process.exit(1);
diff --git a/src/cli/daemon/config.ts b/src/cli/daemon/config.ts
index 562fef4ba..01470527b 100644
--- a/src/cli/daemon/config.ts
+++ b/src/cli/daemon/config.ts
@@ -1,6 +1,7 @@
import { hostname } from "os";
import { join } from "path";
import { configDir } from "../lib/config.js";
+import { getServerUrl } from "../lib/env.js";
import { getCurrentVersion } from "../lib/version.js";
export function pidFilePath(profile?: string): string {
@@ -95,9 +96,7 @@ export function loadDaemonConfig(profile?: string): DaemonConfig {
const workspacesRoot = process.env.ALOOK_WORKSPACES_ROOT || defaultRoot;
return {
- serverURL: normalizeServerBaseURL(
- process.env.ALOOK_SERVER_URL || "https://alook.ai",
- ),
+ serverURL: normalizeServerBaseURL(getServerUrl()),
claudePath: process.env.ALOOK_CLAUDE_PATH || "claude",
codexPath: process.env.ALOOK_CODEX_PATH || "codex",
opencodePath: process.env.ALOOK_OPENCODE_PATH || "opencode",
diff --git a/src/cli/lib/env.ts b/src/cli/lib/env.ts
index 17d50270f..4e1652094 100644
--- a/src/cli/lib/env.ts
+++ b/src/cli/lib/env.ts
@@ -1,4 +1,8 @@
-import { resolveMode, cliCommand } from "@alook/shared";
+import { resolveMode, cliCommand, getBaseUrl } from "@alook/shared";
+
+export function getServerUrl(): string {
+ return getBaseUrl({ serverUrl: process.env.ALOOK_SERVER_URL });
+}
export function isDev(): boolean {
return resolveMode({
diff --git a/src/email-worker/src/index.test.ts b/src/email-worker/src/index.test.ts
index fabf4663a..afecf5b9b 100644
--- a/src/email-worker/src/index.test.ts
+++ b/src/email-worker/src/index.test.ts
@@ -58,6 +58,7 @@ vi.mock("@alook/shared", async () => {
const domain = "@alook.ai"
return address.endsWith(domain) ? address.slice(0, -domain.length) : ""
},
+ toAlookAddress: (h: string) => `${h}@alook.ai`,
DEV_WEB_URL: "http://localhost:3000",
queries: {
agent: {
diff --git a/src/email-worker/src/index.ts b/src/email-worker/src/index.ts
index d277c3b27..60da5142e 100644
--- a/src/email-worker/src/index.ts
+++ b/src/email-worker/src/index.ts
@@ -1,6 +1,6 @@
import { nanoid } from "nanoid"
import PostalMime from "postal-mime"
-import { createDb, queries, parseEmailHandle, DEV_WEB_URL, createLogger, buildMimeMessage, extractAttachmentMeta } from "@alook/shared"
+import { createDb, queries, parseEmailHandle, toAlookAddress, DEV_WEB_URL, createLogger, buildMimeMessage, extractAttachmentMeta } from "@alook/shared"
import { decrypt } from "@alook/shared/crypto"
import { WorkerMailer, type AuthType } from "worker-mailer"
@@ -80,7 +80,7 @@ export default {
}
await env.SEND_EMAIL.send({
+ from: toAlookAddress("no-reply"),
to: body.to,
subject: body.subject,
html: body.html ?? "",
@@ -129,7 +129,7 @@ export default {
if (!agent.emailHandle) {
return Response.json({ error: "agent has no email handle configured" }, { status: 400 })
}
- fromAddress = `${agent.emailHandle}@alook.ai`
+ fromAddress = toAlookAddress(agent.emailHandle)
}
const htmlBody = body.htmlBody ?? ""
diff --git a/src/shared/src/index.ts b/src/shared/src/index.ts
index bb406a063..4fb5adf36 100644
--- a/src/shared/src/index.ts
+++ b/src/shared/src/index.ts
@@ -249,5 +249,5 @@ export { isOnline, formatStatus } from "./utils/status";
export { isUniqueConstraintError } from "./utils/db-errors";
export { generateWorkspaceSlug } from "./utils/slug";
export { semverGte } from "./semver";
-export { resolveMode, cliCommand, daemonCommand } from "./mode";
-export type { AlookMode, ModeSignals } from "./mode";
+export { resolveMode, cliCommand, daemonCommand, getBaseUrl } from "./mode";
+export type { AlookMode, ModeSignals, BaseUrlSignals } from "./mode";
diff --git a/src/shared/src/mode.ts b/src/shared/src/mode.ts
index 9bc12416d..7f791e1f7 100644
--- a/src/shared/src/mode.ts
+++ b/src/shared/src/mode.ts
@@ -7,9 +7,18 @@ export interface ModeSignals {
hostname?: string;
}
+function isLocalUrl(url: string): boolean {
+ try {
+ const { hostname } = new URL(url);
+ return ["localhost", "127.0.0.1", "0.0.0.0"].includes(hostname);
+ } catch {
+ return false;
+ }
+}
+
export function resolveMode(signals: ModeSignals): AlookMode {
if (signals.nodeEnv === "development" && !signals.cmdPrefix) return "dev";
- if (signals.serverUrl && !signals.cmdPrefix) return "dev";
+ if (signals.serverUrl && !signals.cmdPrefix && signals.nodeEnv !== "production" && isLocalUrl(signals.serverUrl)) return "dev";
if (signals.cmdPrefix) return "app";
if (signals.hostname && ["localhost", "127.0.0.1"].includes(signals.hostname))
return "app";
@@ -31,3 +40,19 @@ export function daemonCommand(mode: AlookMode): string {
const base = `${cliCommand(mode)} daemon start`;
return mode === "dev" ? `${base} --foreground` : base;
}
+
+export interface BaseUrlSignals {
+ serverUrl?: string;
+ appUrl?: string;
+ nodeEnv?: string;
+}
+
+const DEFAULT_BASE_URL = "https://alook.ai";
+const DEV_BASE_URL = "http://localhost:3000";
+
+export function getBaseUrl(signals: BaseUrlSignals): string {
+ if (signals.serverUrl) return signals.serverUrl;
+ if (signals.appUrl) return signals.appUrl;
+ if (signals.nodeEnv === "development") return DEV_BASE_URL;
+ return DEFAULT_BASE_URL;
+}
diff --git a/src/shared/src/mode.test.ts b/src/shared/test/mode.test.ts
similarity index 64%
rename from src/shared/src/mode.test.ts
rename to src/shared/test/mode.test.ts
index 6fe0c14ce..dbc01553d 100644
--- a/src/shared/src/mode.test.ts
+++ b/src/shared/test/mode.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect } from "vitest";
-import { resolveMode, cliCommand, daemonCommand } from "./mode";
+import { resolveMode, cliCommand, daemonCommand, getBaseUrl } from "../src/mode";
describe("resolveMode", () => {
it("production: no signals", () => {
@@ -18,7 +18,7 @@ describe("resolveMode", () => {
expect(resolveMode({ nodeEnv: "development" })).toBe("dev");
});
- it("dev: ALOOK_SERVER_URL without CMD_PREFIX", () => {
+ it("dev: local ALOOK_SERVER_URL without CMD_PREFIX", () => {
expect(resolveMode({ serverUrl: "http://localhost:3000" })).toBe("dev");
});
@@ -28,6 +28,18 @@ describe("resolveMode", () => {
).toBe("dev");
});
+ it("production: ALOOK_SERVER_URL set with NODE_ENV=production", () => {
+ expect(
+ resolveMode({ serverUrl: "https://alook.ai", nodeEnv: "production" }),
+ ).toBe("production");
+ });
+
+ it("production: non-local ALOOK_SERVER_URL without NODE_ENV", () => {
+ expect(
+ resolveMode({ serverUrl: "https://alook.ai" }),
+ ).toBe("production");
+ });
+
it("app: CMD_PREFIX set (overrides serverUrl)", () => {
expect(
resolveMode({
@@ -88,3 +100,25 @@ describe("daemonCommand", () => {
expect(daemonCommand("app")).toBe("npx @alook/app cli daemon start");
});
});
+
+describe("getBaseUrl", () => {
+ it("prefers serverUrl when set", () => {
+ expect(getBaseUrl({ serverUrl: "http://localhost:3000", appUrl: "https://app.example.com" })).toBe("http://localhost:3000");
+ });
+
+ it("falls back to appUrl when serverUrl not set", () => {
+ expect(getBaseUrl({ appUrl: "https://app.example.com" })).toBe("https://app.example.com");
+ });
+
+ it("returns localhost in development when no URLs set", () => {
+ expect(getBaseUrl({ nodeEnv: "development" })).toBe("http://localhost:3000");
+ });
+
+ it("returns production URL when no signals", () => {
+ expect(getBaseUrl({})).toBe("https://alook.ai");
+ });
+
+ it("returns production URL in production mode with no URLs", () => {
+ expect(getBaseUrl({ nodeEnv: "production" })).toBe("https://alook.ai");
+ });
+});
diff --git a/src/web/src/app/(app)/w/[slug]/agents/[id]/email/page.tsx b/src/web/src/app/(app)/w/[slug]/agents/[id]/email/page.tsx
index c140f8455..ba8ad13a7 100644
--- a/src/web/src/app/(app)/w/[slug]/agents/[id]/email/page.tsx
+++ b/src/web/src/app/(app)/w/[slug]/agents/[id]/email/page.tsx
@@ -5,6 +5,7 @@ import { useParams } from "next/navigation";
import { useWorkspace } from "@/contexts/workspace-context";
import { useAgentContext } from "@/contexts/agent-context";
import { listEmails, getEmailBody, getEmailThread, deleteEmail, sendEmail, listEmailAccounts, updateEmailStatus } from "@/lib/api";
+import { toAlookAddress } from "@alook/shared";
import type { Email, EmailAttachment, AgentEmailAccount } from "@alook/shared";
import { Button } from "@/components/ui/button";
import { ConfirmDialog } from "@/components/ui/confirm-dialog";
@@ -76,7 +77,7 @@ export default function AgentEmailPage() {
}, []);
type Mailbox = { type: "alook"; address: string } | { type: "custom"; address: string; accountId: string };
- const alookAddress = agent?.email_handle ? `${agent.email_handle}@alook.ai` : "";
+ const alookAddress = agent?.email_handle ? toAlookAddress(agent.email_handle) : "";
const mailboxes: Mailbox[] = [
...(alookAddress ? [{ type: "alook" as const, address: alookAddress }] : []),
...emailAccounts.map((a) => ({ type: "custom" as const, address: a.email_address, accountId: a.id })),
diff --git a/src/web/src/app/api/agents/recruit/route.ts b/src/web/src/app/api/agents/recruit/route.ts
index 79aff8d5f..bbfe7fd94 100644
--- a/src/web/src/app/api/agents/recruit/route.ts
+++ b/src/web/src/app/api/agents/recruit/route.ts
@@ -1,6 +1,6 @@
import { NextRequest } from "next/server";
import { getCloudflareContext } from "@opennextjs/cloudflare";
-import { queries, RecruitAgentRequestSchema, isValidHandle, isOnline, buildMimeMessage, extractThreadId, buildEmailMapKey, DEV_WEB_URL } from "@alook/shared";
+import { queries, RecruitAgentRequestSchema, isValidHandle, isOnline, buildMimeMessage, extractThreadId, buildEmailMapKey, DEV_WEB_URL, toAlookAddress } from "@alook/shared";
import { nanoid } from "nanoid";
import { uniqueNamesGenerator, names } from "unique-names-generator";
import { getDb } from "@/lib/db";
@@ -95,7 +95,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
});
if (callingAgent.emailHandle) {
- const callerEmail = `${callingAgent.emailHandle}@alook.ai`;
+ const callerEmail = toAlookAddress(callingAgent.emailHandle);
await queries.whitelist.addWhitelist(db, newAgent.id, ws.workspaceId, callerEmail);
}
if (ctx.email) {
@@ -120,8 +120,8 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
if (isOnline(runtime.machineLastSeenAt) && callingAgent.emailHandle) {
try {
const cfEnv = env as Env;
- const fromAddress = `${callingAgent.emailHandle}@alook.ai`;
- const toAddress = `${handle}@alook.ai`;
+ const fromAddress = toAlookAddress(callingAgent.emailHandle);
+ const toAddress = toAlookAddress(handle);
const subject = "Welcome aboard";
const htmlBody = `<p>Hi, I just recruited you. Your instructions are already set. Please reply confirming you're ready to work — tell me your name and email address.</p>`;
const messageId = `<${nanoid()}@alook.ai>`;
@@ -200,7 +200,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
}
return writeJSON({
- agent: { ...agentToResponse(newAgent), email: `${handle}@alook.ai` },
+ agent: { ...agentToResponse(newAgent), email: toAlookAddress(handle) },
link: agentLinkToResponse(link),
}, 201);
});
diff --git a/src/web/src/app/api/email/route.test.ts b/src/web/src/app/api/email/route.test.ts
index 07e9eb0e5..65088e65f 100644
--- a/src/web/src/app/api/email/route.test.ts
+++ b/src/web/src/app/api/email/route.test.ts
@@ -16,6 +16,7 @@ vi.mock("@/lib/db", () => ({ getDb: vi.fn(() => ({})) }));
vi.mock("@alook/shared", () => ({
createDb: vi.fn(() => ({})),
+ toAlookAddress: (h: string) => `${h}@alook.ai`,
queries: {
agent: { getAgent: (...args: unknown[]) => mockGetAgent(...args) },
email: {
diff --git a/src/web/src/app/api/email/route.ts b/src/web/src/app/api/email/route.ts
index 03ab7909e..441eddfaa 100644
--- a/src/web/src/app/api/email/route.ts
+++ b/src/web/src/app/api/email/route.ts
@@ -1,6 +1,6 @@
import { NextRequest } from "next/server";
import { getCloudflareContext } from "@opennextjs/cloudflare";
-import { queries } from "@alook/shared";
+import { queries, toAlookAddress } from "@alook/shared";
import { getDb } from "@/lib/db"
import { withAuth } from "@/lib/middleware/auth";
import { withWorkspaceMember } from "@/lib/middleware/workspace";
@@ -29,7 +29,7 @@ export const GET = withAuth(async (req: NextRequest, ctx) => {
const folder = req.nextUrl.searchParams.get("folder");
const address = req.nextUrl.searchParams.get("address");
- const agentEmail = address || (agent.emailHandle ? `${agent.emailHandle}@alook.ai` : "");
+ const agentEmail = address || (agent.emailHandle ? toAlookAddress(agent.emailHandle) : "");
const limitParam = req.nextUrl.searchParams.get("limit");
const offsetParam = req.nextUrl.searchParams.get("offset");
diff --git a/src/web/src/app/api/email/send/route.ts b/src/web/src/app/api/email/send/route.ts
index 2e759d291..5e34982d8 100644
--- a/src/web/src/app/api/email/send/route.ts
+++ b/src/web/src/app/api/email/send/route.ts
@@ -1,6 +1,6 @@
import { NextRequest } from "next/server";
import { getCloudflareContext } from "@opennextjs/cloudflare";
-import { queries, DEV_EMAIL_WORKER_URL, DEV_WEB_URL, SendEmailRequestSchema, parseEmailHandle, buildMimeMessage, extractThreadId, buildEmailMapKey } from "@alook/shared";
+import { queries, DEV_EMAIL_WORKER_URL, DEV_WEB_URL, SendEmailRequestSchema, parseEmailHandle, toAlookAddress, buildMimeMessage, extractThreadId, buildEmailMapKey } from "@alook/shared";
import { nanoid } from "nanoid";
import { getDb } from "@/lib/db"
import { withAuth } from "@/lib/middleware/auth";
@@ -62,7 +62,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
let fromAddress: string;
if (body.from && !customAccountId) {
- const alookAddr = agent.emailHandle ? `${agent.emailHandle}@alook.ai` : null;
+ const alookAddr = agent.emailHandle ? toAlookAddress(agent.emailHandle) : null;
if (body.from === alookAddr) {
fromAddress = alookAddr;
} else {
@@ -84,7 +84,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
if (!agent.emailHandle) {
return writeError("agent has no email handle configured", 400);
}
- fromAddress = `${agent.emailHandle}@alook.ai`;
+ fromAddress = toAlookAddress(agent.emailHandle);
}
let validatedConversationId: string | undefined;
diff --git a/src/web/src/app/api/meeting/callback/route.ts b/src/web/src/app/api/meeting/callback/route.ts
index ad23e40fb..c29089d30 100644
--- a/src/web/src/app/api/meeting/callback/route.ts
+++ b/src/web/src/app/api/meeting/callback/route.ts
@@ -1,7 +1,7 @@
import { NextRequest } from "next/server"
import { getCloudflareContext } from "@opennextjs/cloudflare"
import { nanoid } from "nanoid"
-import { queries, MeetingStatus, DEV_WEB_URL, buildMimeMessage } from "@alook/shared"
+import { queries, MeetingStatus, DEV_WEB_URL, buildMimeMessage, toAlookAddress } from "@alook/shared"
import { withAuth } from "@/lib/middleware/auth"
import { writeJSON, writeError } from "@/lib/middleware/helpers"
import { getDb } from "@/lib/db"
@@ -71,8 +71,8 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
const messageId = `<meeting-${body.meetingId}@alook.ai>`
const existing = await queries.email.getEmailByMessageId(db, messageId, body.workspaceId)
if (!existing) {
- const fromAddr = "[email protected]"
- const toAddr = `${agent.emailHandle}@alook.ai`
+ const fromAddr = toAlookAddress("no-reply")
+ const toAddr = toAlookAddress(agent.emailHandle)
const meetingTitle = meeting.title || "Untitled"
const subject = `Meeting completed: ${meetingTitle} — please summarize`
diff --git a/src/web/src/app/api/studios/route.ts b/src/web/src/app/api/studios/route.ts
index 97303e6d4..9ba9e2810 100644
--- a/src/web/src/app/api/studios/route.ts
+++ b/src/web/src/app/api/studios/route.ts
@@ -1,6 +1,6 @@
import { NextRequest } from "next/server";
import { getCloudflareContext } from "@opennextjs/cloudflare";
-import { queries, CreateStudioRequestSchema, isValidHandle, isOnline, TASK_TYPES } from "@alook/shared";
+import { queries, CreateStudioRequestSchema, isValidHandle, isOnline, TASK_TYPES, toAlookAddress } from "@alook/shared";
import { nanoid } from "nanoid";
import { uniqueNamesGenerator, names } from "unique-names-generator";
import { getDb } from "@/lib/db";
@@ -214,7 +214,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
try {
const teammatesList = createdAgents
.filter((a) => a.id !== leaderAgent.id)
- .map((a) => `- ${a.name} (${a.emailHandle}@alook.ai), role: ${a.role}`)
+ .map((a) => `- ${a.name} (${a.emailHandle ? toAlookAddress(a.emailHandle) : a.name}), role: ${a.role}`)
.join("\n");
const welcomePrompt = createdAgents.length === 1
@@ -246,7 +246,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
try {
const teammatesList = createdAgents
.filter((a) => a.id !== leaderAgent.id)
- .map((a) => `- ${a.name} (${a.emailHandle}@alook.ai), role: ${a.role}`)
+ .map((a) => `- ${a.name} (${a.emailHandle ? toAlookAddress(a.emailHandle) : a.name}), role: ${a.role}`)
.join("\n");
const welcomeChatPrompt = createdAgents.length === 1
diff --git a/src/web/src/app/device/page.tsx b/src/web/src/app/device/page.tsx
index 779a4237e..11de28ae9 100644
--- a/src/web/src/app/device/page.tsx
+++ b/src/web/src/app/device/page.tsx
@@ -60,15 +60,6 @@ function DeviceAuthPageInner() {
autoVerify()
}, [urlCode, session])
- useEffect(() => {
- if (step === "done") {
- const timer = setTimeout(() => {
- router.push("/workspaces?auto")
- }, 2000)
- return () => clearTimeout(timer)
- }
- }, [step, router])
-
async function handleVerifyCode(e: React.FormEvent) {
e.preventDefault()
setError("")
@@ -195,8 +186,9 @@ function DeviceAuthPageInner() {
{step === "done" && (
<div className="text-center space-y-2">
+ <p className="text-sm font-medium text-green-600">✓ Device authorized</p>
<p className="text-sm text-muted-foreground">
- Device authorized successfully. Redirecting...
+ You can close this tab. The CLI will continue automatically.
</p>
</div>
)}
diff --git a/src/web/src/app/onboard.md/route.test.ts b/src/web/src/app/onboard.md/route.test.ts
index ffbac1b73..4387cfe95 100644
--- a/src/web/src/app/onboard.md/route.test.ts
+++ b/src/web/src/app/onboard.md/route.test.ts
@@ -1,54 +1,62 @@
-import { describe, it, expect } from "vitest";
+import { describe, it, expect, afterEach } from "vitest";
import { GET } from "./route";
describe("GET /onboard.md", () => {
+ const origAppUrl = process.env.NEXT_PUBLIC_APP_URL;
+ const origServerUrl = process.env.ALOOK_SERVER_URL;
+ const origCmdPrefix = process.env.ALOOK_CMD_PREFIX;
+ const origNodeEnv = process.env.NODE_ENV;
+
+ afterEach(() => {
+ restoreEnv("NEXT_PUBLIC_APP_URL", origAppUrl);
+ restoreEnv("ALOOK_SERVER_URL", origServerUrl);
+ restoreEnv("ALOOK_CMD_PREFIX", origCmdPrefix);
+ restoreEnv("NODE_ENV", origNodeEnv);
+ });
+
+ function restoreEnv(key: string, val: string | undefined) {
+ if (val === undefined) delete process.env[key];
+ else process.env[key] = val;
+ }
+
it("returns 200 with Content-Type text/markdown", async () => {
const response = await GET();
expect(response.status).toBe(200);
expect(response.headers.get("Content-Type")).toBe("text/markdown; charset=utf-8");
});
- it("contains login section", async () => {
+ it("uses npx @alook/cli and alook.ai URLs in production mode", async () => {
+ delete process.env.NEXT_PUBLIC_APP_URL;
+ delete process.env.ALOOK_SERVER_URL;
+ delete process.env.ALOOK_CMD_PREFIX;
+ process.env.NODE_ENV = "production";
const response = await GET();
const body = await response.text();
expect(body).toContain("npx @alook/cli login");
+ expect(body).toContain("https://alook.ai/templates");
+ expect(body).toContain("https://alook.ai/w/{slug}/home");
});
- it("contains daemon start section", async () => {
- const response = await GET();
- const body = await response.text();
- expect(body).toContain("npx @alook/cli daemon start");
- });
-
- it("contains reflection section with role/domain/tech-stack prompts", async () => {
- const response = await GET();
- const body = await response.text();
- expect(body).toContain("Reflect on Your User");
- expect(body).toContain("role and domain");
- expect(body).toContain("Tech stack");
- expect(body).toContain("workflow");
- });
-
- it("contains workspace init section", async () => {
- const response = await GET();
- const body = await response.text();
- expect(body).toContain("npx @alook/cli workspace init --json-file");
- expect(body).toContain("workspace already has agents");
- });
-
- it("contains templates exploration section", async () => {
+ it("uses localhost in development mode when no URLs are set", async () => {
+ delete process.env.NEXT_PUBLIC_APP_URL;
+ delete process.env.ALOOK_SERVER_URL;
+ delete process.env.ALOOK_CMD_PREFIX;
+ process.env.NODE_ENV = "development";
const response = await GET();
const body = await response.text();
- expect(body).toContain("https://alook.ai/templates");
+ expect(body).toContain("pnpm dev:cli login");
+ expect(body).toContain("http://localhost:3000/templates");
});
- it("outputs workspace URL after daemon start", async () => {
+ it("uses npx @alook/app cli for self-hosted (app mode)", async () => {
+ process.env.NEXT_PUBLIC_APP_URL = "http://localhost:15210";
+ process.env.ALOOK_CMD_PREFIX = "npx @alook/app cli";
+ delete process.env.ALOOK_SERVER_URL;
+ process.env.NODE_ENV = "production";
const response = await GET();
const body = await response.text();
- const daemonIdx = body.indexOf("## 4. Start Daemon & Open Workspace");
- const urlIdx = body.indexOf("https://alook.ai/w/{slug}");
-
- expect(daemonIdx).toBeGreaterThan(-1);
- expect(urlIdx).toBeGreaterThan(daemonIdx);
+ expect(body).toContain("npx @alook/app cli login");
+ expect(body).toContain("http://localhost:15210/templates");
+ expect(body).toContain("http://localhost:15210/w/{slug}/home");
});
});
diff --git a/src/web/src/app/onboard.md/route.ts b/src/web/src/app/onboard.md/route.ts
index 6c90eeae1..acb176975 100644
--- a/src/web/src/app/onboard.md/route.ts
+++ b/src/web/src/app/onboard.md/route.ts
@@ -1,6 +1,8 @@
+import { resolveMode, cliCommand, getBaseUrl } from "@alook/shared";
import { NextResponse } from "next/server";
-const ONBOARD_MARKDOWN = `---
+function buildOnboardMarkdown(baseUrl: string, cliPrefix: string): string {
+ return `---
name: alook-onboard
description: Install Alook CLI, authenticate, and set up your AI workspace.
keywords: [alook, agent, workspace, CLI, onboarding]
@@ -9,12 +11,12 @@ keywords: [alook, agent, workspace, CLI, onboarding]
## 1. Login
\`\`\`bash
-npx @alook/cli login
+${cliPrefix} login
\`\`\`
- Non-interactive terminal: prints a URL for the user to open manually, then polls until confirmed
- Interactive terminal: attempts to open browser automatically
-- Verify success: \`npx @alook/cli status\`
+- Verify success: \`${cliPrefix} status\`
## 2. Reflect on Your User
@@ -28,7 +30,7 @@ Use this understanding to choose the best workspace setup.
## 3. Explore Templates & Set Up Workspace
-Visit https://alook.ai/templates to explore available workspace templates.
+Visit ${baseUrl}/templates to explore available workspace templates.
Each template has a JSON version at \`/templates/<slug>/json\` you can fetch for reference.
Based on what you learned about the user in Step 2, customize the template or create your own configuration:
@@ -58,7 +60,7 @@ Based on what you learned about the user in Step 2, customize the template or cr
Write your customized JSON to a file, then run:
\`\`\`bash
-npx @alook/cli workspace init --json-file <path_to_json>
+${cliPrefix} workspace init --json-file <path_to_json>
\`\`\`
If the current workspace already has agents, a new workspace is created automatically.
@@ -66,20 +68,33 @@ If the current workspace already has agents, a new workspace is created automati
## 4. Start Daemon & Open Workspace
\`\`\`bash
-npx @alook/cli daemon start
+${cliPrefix} daemon start
\`\`\`
Once the daemon starts successfully, tell the user their workspace is ready and provide the URL:
\`\`\`
-https://alook.ai/w/{slug}
+${baseUrl}/w/{slug}/home
\`\`\`
(Use the workspace slug from the \`workspace init\` output in Step 3.)
`;
+}
export async function GET() {
- return new NextResponse(ONBOARD_MARKDOWN, {
+ const baseUrl = getBaseUrl({
+ serverUrl: process.env.ALOOK_SERVER_URL,
+ appUrl: process.env.NEXT_PUBLIC_APP_URL,
+ nodeEnv: process.env.NODE_ENV,
+ });
+ const mode = resolveMode({
+ serverUrl: process.env.ALOOK_SERVER_URL,
+ cmdPrefix: process.env.ALOOK_CMD_PREFIX,
+ nodeEnv: process.env.NODE_ENV,
+ });
+ const cliPrefix = cliCommand(mode);
+
+ return new NextResponse(buildOnboardMarkdown(baseUrl, cliPrefix), {
headers: {
"Content-Type": "text/markdown; charset=utf-8",
},
diff --git a/src/web/src/components/agent-chat/chat-composer.tsx b/src/web/src/components/agent-chat/chat-composer.tsx
index 16d09549d..cc7880ffa 100644
--- a/src/web/src/components/agent-chat/chat-composer.tsx
+++ b/src/web/src/components/agent-chat/chat-composer.tsx
@@ -16,6 +16,7 @@ import { cn } from "@/lib/utils";
import { rankMentionAgents } from "@/lib/mention-agents";
import { buildChatMentionExtension } from "@/lib/chat-mention-extension";
import { decodeChatEntities } from "@/lib/chat-markdown";
+import { toAlookAddress } from "@alook/shared";
import type { Agent, AgentLink } from "@alook/shared";
import type { PopupKeyEvent } from "@/hooks/use-slash-command";
@@ -121,7 +122,7 @@ function MentionList({ state }: { state: MentionPopupState }) {
<span className="truncate font-medium">{agent.name}</span>
{agent.email_handle && (
<span className="truncate text-xs text-muted-foreground">
- {agent.email_handle}@alook.ai
+ {toAlookAddress(agent.email_handle)}
</span>
)}
</button>
diff --git a/src/web/src/components/agent-edit-form.tsx b/src/web/src/components/agent-edit-form.tsx
index 40fb7994b..6fccf246d 100644
--- a/src/web/src/components/agent-edit-form.tsx
+++ b/src/web/src/components/agent-edit-form.tsx
@@ -5,6 +5,7 @@ import { Button } from "@/components/ui/button";
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
import type { Agent } from "@alook/shared";
import type { AgentRuntime as Runtime } from "@alook/shared";
+import { toAlookAddress } from "@alook/shared";
import { cn } from "@/lib/utils";
import { LockIcon } from "lucide-react";
import { CustomEmailForm } from "@/components/custom-email-form";
@@ -372,7 +373,7 @@ export function AgentEditForm({
</span>
<span className="text-xs text-muted-foreground">
{agent.email_handle
- ? `${agent.email_handle}@alook.ai`
+ ? toAlookAddress(agent.email_handle)
: "Not configured"}
</span>
</div>
diff --git a/src/web/src/components/agent-preview-card.tsx b/src/web/src/components/agent-preview-card.tsx
index 0d1df6238..32e98360b 100644
--- a/src/web/src/components/agent-preview-card.tsx
+++ b/src/web/src/components/agent-preview-card.tsx
@@ -1,6 +1,7 @@
"use client";
import { useCallback, useState } from "react";
+import { toAlookAddress } from "@alook/shared";
import type { Agent } from "@alook/shared";
import { Check, Copy } from "lucide-react";
import { toast } from "sonner";
@@ -24,7 +25,7 @@ export function AgentPreviewCard({
isHovered,
}: AgentPreviewCardProps) {
const [copied, setCopied] = useState(false);
- const email = agent.email_handle ? `${agent.email_handle}@alook.ai` : null;
+ const email = agent.email_handle ? toAlookAddress(agent.email_handle) : null;
const isCompact = variant === "compact";
const handleCopy = useCallback(async () => {
diff --git a/src/web/src/components/canvas/agent-chat-sheet.tsx b/src/web/src/components/canvas/agent-chat-sheet.tsx
index 63ca41ca7..3385c2f3a 100644
--- a/src/web/src/components/canvas/agent-chat-sheet.tsx
+++ b/src/web/src/components/canvas/agent-chat-sheet.tsx
@@ -10,6 +10,7 @@ import {
SheetHeader,
SheetTitle,
} from "@/components/ui/sheet";
+import { toAlookAddress } from "@alook/shared";
import type { Agent } from "@alook/shared";
import { AnimatedAvatar, parseAvatarUrl } from "@/components/avatar";
import { useAgentContext } from "@/contexts/agent-context";
@@ -114,7 +115,7 @@ export function AgentChatSheet({ open, onOpenChange, agentId, agent, targetConvI
{agent?.name ?? "Chat"}
</SheetTitle>
{agent?.email_handle && (
- <span className="text-xs text-muted-foreground truncate">{agent.email_handle}@alook.ai</span>
+ <span className="text-xs text-muted-foreground truncate">{toAlookAddress(agent.email_handle)}</span>
)}
</div>
</div>
diff --git a/src/web/src/components/issues/issue-sheet.tsx b/src/web/src/components/issues/issue-sheet.tsx
index 70db99a9c..4080f563d 100644
--- a/src/web/src/components/issues/issue-sheet.tsx
+++ b/src/web/src/components/issues/issue-sheet.tsx
@@ -39,7 +39,7 @@ import { Streamdown } from "streamdown";
import type { Agent, Artifact, Issue, IssueComment, Message, TaskApi } from "@alook/shared";
import { isPreviewable, getArtifactUrl } from "@/components/artifact-content-renderer";
import { formatSize } from "@/components/agent-chat/artifact-sheet";
-import { isTerminalIssueStatus } from "@alook/shared";
+import { isTerminalIssueStatus, toAlookAddress } from "@alook/shared";
import type { TraceTask } from "@/lib/api";
import { updateIssue } from "@/lib/api";
import { AvatarRenderer, parseAvatarUrl } from "@/components/avatar";
@@ -81,7 +81,7 @@ function AgentAvatar({ agent, size = 24 }: { agent?: Agent | null; size?: number
}
function AgentIdentity({ agent, size = 24 }: { agent: Agent; size?: number }) {
- const email = agent.email_handle ? `${agent.email_handle}@alook.ai` : "";
+ const email = agent.email_handle ? toAlookAddress(agent.email_handle) : "";
return (
<div className="flex min-w-0 items-center gap-2">
<AgentAvatar agent={agent} size={size} />
diff --git a/src/web/src/components/studio-onboarding/team-preview.tsx b/src/web/src/components/studio-onboarding/team-preview.tsx
index a79133b86..f46e0f6ce 100644
--- a/src/web/src/components/studio-onboarding/team-preview.tsx
+++ b/src/web/src/components/studio-onboarding/team-preview.tsx
@@ -12,6 +12,7 @@ import {
SelectItem,
} from "@/components/ui/select";
import { ProviderLogo } from "@/components/provider-logo";
+import { toAlookAddress } from "@alook/shared";
import type { AgentRuntime as Runtime } from "@alook/shared";
import type { MemberRole } from "./scenario-presets";
@@ -88,7 +89,7 @@ export function TeamPreview({
</div>
{/* Email */}
<p className="text-[10px] text-muted-foreground/70 font-mono truncate">
- {m.emailHandle || m.name.toLowerCase()}@alook.ai
+ {toAlookAddress(m.emailHandle || m.name.toLowerCase())}
</p>
{/* Description — flex-1 to push runtime picker to bottom */}
<p className="text-[11px] text-muted-foreground leading-snug flex-1">
diff --git a/src/web/src/components/ui/markdown-editor.tsx b/src/web/src/components/ui/markdown-editor.tsx
index a5f8ec1ee..3f86e1f31 100644
--- a/src/web/src/components/ui/markdown-editor.tsx
+++ b/src/web/src/components/ui/markdown-editor.tsx
@@ -7,7 +7,7 @@ import Placeholder from "@tiptap/extension-placeholder";
import Mention from "@tiptap/extension-mention";
import { Markdown } from "@tiptap/markdown";
import { cn } from "@/lib/utils";
-import { isEmptyHtml } from "@alook/shared";
+import { isEmptyHtml, toAlookAddress } from "@alook/shared";
import type { Agent } from "@alook/shared";
import { createPortal } from "react-dom";
@@ -84,7 +84,7 @@ function MentionList({
<span className="truncate font-medium">{agent.name}</span>
{agent.email_handle && (
<span className="truncate text-xs text-muted-foreground">
- {agent.email_handle}@alook.ai
+ {toAlookAddress(agent.email_handle)}
</span>
)}
</button>
diff --git a/src/web/src/lib/services/task-payload-builder.ts b/src/web/src/lib/services/task-payload-builder.ts
index 8ed674951..0a5202a5b 100644
--- a/src/web/src/lib/services/task-payload-builder.ts
+++ b/src/web/src/lib/services/task-payload-builder.ts
@@ -58,7 +58,7 @@ export class TaskPayloadBuilder {
const agent = agentMap.get(task.agentId) ?? null;
const emailAddresses: string[] = [];
if (agent) {
- if (agent.emailHandle) emailAddresses.push(`${agent.emailHandle}@alook.ai`);
+ if (agent.emailHandle) emailAddresses.push(toAlookAddress(agent.emailHandle));
const customAccounts = emailAccountsByAgent.get(agent.id) ?? [];
emailAddresses.push(...customAccounts);
}
diff --git a/src/web/src/test/e2e/device-code.test.ts b/src/web/src/test/e2e/device-code.test.ts
index a7685a263..13f350c16 100644
--- a/src/web/src/test/e2e/device-code.test.ts
+++ b/src/web/src/test/e2e/device-code.test.ts
@@ -172,9 +172,6 @@ describe("onboard.md", () => {
const res = await fetch(`${APP_URL}/onboard.md`)
expect(res.status).toBe(200)
expect(res.headers.get("content-type")).toContain("text/markdown")
- const body = await res.text()
- expect(body).toContain("npx @alook/cli login")
- expect(body).toContain("npx @alook/cli daemon start")
})
})