Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat: update task streaming

Gus527cd40400ca
diff --git a/AGENTS.md b/AGENTS.md
index ef5c71120..dc12aef95 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -9,6 +9,10 @@ Alook's main purpose is to make the cli agent always on, and give it a email add
- `src/email-worker`: inbound email Cloudflare Worker
- `src/ws-do`: WebSocket Durable Object worker
+## MUST
+- run `pnpm typecheck`, `pnpm test`, `pnpm test:e2e` and `pnpm build` as the final check when you think the code is ready.
+
+
## Plan-driven Development
- You must make a markdown plan at `plans/` before you implement any my request, otherwise I will reject your implementation.
- The `plans/` directory is gitignored — plans are kept locally and do not need to be committed or included in PRs.
diff --git a/src/shared/schemas.test.ts b/src/shared/schemas.test.ts
index e3faedbf4..98f65c60c 100644
--- a/src/shared/schemas.test.ts
+++ b/src/shared/schemas.test.ts
@@ -49,7 +49,6 @@ function validRow() {
result: null,
context: { foo: "bar" },
sessionId: "sess-1",
- workDir: "/tmp/work",
createdAt: "2024-01-01T00:00:00Z",
dispatchedAt: "2024-01-01T00:01:00Z",
startedAt: null,
@@ -65,7 +64,6 @@ describe("ClaimedTaskRowSchema", () => {
expect(parsed.id).toBe("t1");
expect(parsed.context).toEqual({ foo: "bar" });
expect(parsed.sessionId).toBe("sess-1");
- expect(parsed.workDir).toBe("/tmp/work");
});
it("coerces string timestamps to Date objects", () => {
@@ -128,17 +126,15 @@ describe("TaskApiBaseSchema", () => {
// ---------------------------------------------------------------------------
describe("TaskApiSchema", () => {
- it("accepts optional agent, prior_session_id, prior_work_dir", () => {
+ it("accepts optional agent and prior_session_id", () => {
const input = {
...validTaskApiBase(),
agent: { instructions: "be helpful", name: "bot", runtime_config: {} },
prior_session_id: "sess-0",
- prior_work_dir: "/tmp/old",
};
const parsed = TaskApiSchema.parse(input);
expect(parsed.agent?.name).toBe("bot");
expect(parsed.prior_session_id).toBe("sess-0");
- expect(parsed.prior_work_dir).toBe("/tmp/old");
});
});
diff --git a/src/shared/schemas.ts b/src/shared/schemas.ts
index e048f4dee..3115facaf 100644
--- a/src/shared/schemas.ts
+++ b/src/shared/schemas.ts
@@ -29,7 +29,6 @@ export const ClaimedTaskRowSchema = z.object({
result: z.unknown().nullable(),
context: z.unknown().nullable(),
sessionId: z.string().nullable(),
- workDir: z.string().nullable(),
createdAt: z.coerce.date(),
dispatchedAt: z.coerce.date().nullable(),
startedAt: z.coerce.date().nullable(),
@@ -78,7 +77,6 @@ export type TaskApiBase = z.infer<typeof TaskApiBaseSchema>;
export const TaskApiSchema = TaskApiBaseSchema.extend({
agent: TaskAgentDataApiSchema.nullable().optional(),
prior_session_id: z.string().nullable().optional(),
- prior_work_dir: z.string().nullable().optional(),
});
export type TaskApi = z.infer<typeof TaskApiSchema>;
@@ -137,7 +135,6 @@ export type HeartbeatRequest = z.infer<typeof HeartbeatRequestSchema>;
export const CompleteTaskRequestSchema = z.object({
output: z.string().optional(),
session_id: z.string().optional(),
- work_dir: z.string().optional(),
branch_name: z.string().optional(),
});
export type CompleteTaskRequest = z.infer<typeof CompleteTaskRequestSchema>;
diff --git a/src/shared/src/db/queries/task-message.ts b/src/shared/src/db/queries/task-message.ts
index a32169955..85daf3345 100644
--- a/src/shared/src/db/queries/task-message.ts
+++ b/src/shared/src/db/queries/task-message.ts
@@ -9,6 +9,7 @@ export async function createTaskMessage(
seq: number;
type: string;
tool: string;
+ callId?: string;
content: string;
input?: unknown;
output: string;
@@ -21,6 +22,7 @@ export async function createTaskMessage(
seq: data.seq,
type: data.type,
tool: data.tool,
+ callId: data.callId || "",
content: data.content,
input: data.input ?? null,
output: data.output,
diff --git a/src/shared/src/db/queries/task.ts b/src/shared/src/db/queries/task.ts
index 835031161..9333660c1 100644
--- a/src/shared/src/db/queries/task.ts
+++ b/src/shared/src/db/queries/task.ts
@@ -108,7 +108,7 @@ export async function startTask(db: Database, id: string) {
export async function completeTask(
db: Database,
id: string,
- data: { result: unknown; sessionId: string | null; workDir: string | null }
+ data: { result: unknown; sessionId: string | null }
) {
const rows = await db
.update(agentTaskQueue)
@@ -117,7 +117,6 @@ export async function completeTask(
completedAt: new Date().toISOString(),
result: data.result,
sessionId: data.sessionId,
- workDir: data.workDir,
})
.where(
and(eq(agentTaskQueue.id, id), eq(agentTaskQueue.status, "running"))
@@ -152,7 +151,6 @@ export async function getLastTaskSession(
const rows = await db
.select({
sessionId: agentTaskQueue.sessionId,
- workDir: agentTaskQueue.workDir,
})
.from(agentTaskQueue)
.where(
diff --git a/src/shared/src/db/schema.ts b/src/shared/src/db/schema.ts
index 1b830f0e8..2e8a989aa 100644
--- a/src/shared/src/db/schema.ts
+++ b/src/shared/src/db/schema.ts
@@ -203,7 +203,6 @@ export const agentTaskQueue = sqliteTable(
result: text("result", { mode: "json" }),
context: text("context", { mode: "json" }),
sessionId: text("session_id"),
- workDir: text("work_dir"),
createdAt: text("created_at").notNull().$defaultFn(() => new Date().toISOString()),
dispatchedAt: text("dispatched_at"),
startedAt: text("started_at"),
@@ -231,6 +230,7 @@ export const taskMessage = sqliteTable(
type: text("type").notNull().default(""),
tool: text("tool").notNull().default(""),
content: text("content").notNull().default(""),
+ callId: text("call_id").notNull().default(""),
input: text("input", { mode: "json" }),
output: text("output").notNull().default(""),
createdAt: text("created_at").notNull().$defaultFn(() => new Date().toISOString()),
diff --git a/src/shared/src/schemas.ts b/src/shared/src/schemas.ts
index b1276d184..c63c76879 100644
--- a/src/shared/src/schemas.ts
+++ b/src/shared/src/schemas.ts
@@ -29,7 +29,6 @@ export const ClaimedTaskRowSchema = z.object({
result: z.unknown().nullable(),
context: z.unknown().nullable(),
sessionId: z.string().nullable(),
- workDir: z.string().nullable(),
createdAt: z.coerce.date(),
dispatchedAt: z.coerce.date().nullable(),
startedAt: z.coerce.date().nullable(),
@@ -78,7 +77,6 @@ export type TaskApiBase = z.infer<typeof TaskApiBaseSchema>;
export const TaskApiSchema = TaskApiBaseSchema.extend({
agent: TaskAgentDataApiSchema.nullable().optional(),
prior_session_id: z.string().nullable().optional(),
- prior_work_dir: z.string().nullable().optional(),
});
export type TaskApi = z.infer<typeof TaskApiSchema>;
@@ -150,7 +148,6 @@ export type HeartbeatRequest = z.infer<typeof HeartbeatRequestSchema>;
export const CompleteTaskRequestSchema = z.object({
output: z.string().optional(),
session_id: z.string().optional(),
- work_dir: z.string().optional(),
branch_name: z.string().optional(),
});
export type CompleteTaskRequest = z.infer<typeof CompleteTaskRequestSchema>;
@@ -164,6 +161,7 @@ export const MessageItemSchema = z.object({
seq: z.number(),
type: z.string(),
tool: z.string().optional(),
+ call_id: z.string().optional(),
content: z.string().optional(),
input: z.record(z.unknown()).optional(),
output: z.string().optional(),
diff --git a/src/shared/src/types.ts b/src/shared/src/types.ts
index fa338b522..700c5b112 100644
--- a/src/shared/src/types.ts
+++ b/src/shared/src/types.ts
@@ -81,7 +81,6 @@ export interface AgentTask {
agent?: TaskAgentData;
created_at: string;
prior_session_id?: string;
- prior_work_dir?: string;
}
export interface TaskAgentData {
@@ -96,6 +95,7 @@ export interface TaskMessage {
seq: number;
type: string;
tool: string;
+ call_id: string;
content: string;
input?: Record<string, unknown>;
output: string;
diff --git a/src/shared/types.ts b/src/shared/types.ts
index a23c16ae7..2985bb36d 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -80,7 +80,6 @@ export interface AgentTask {
agent?: TaskAgentData;
created_at: string;
prior_session_id?: string;
- prior_work_dir?: string;
}
export interface TaskAgentData {
diff --git a/src/web/migrations/0002_drop_work_dir.sql b/src/web/migrations/0002_drop_work_dir.sql
new file mode 100644
index 000000000..4250756ec
--- /dev/null
+++ b/src/web/migrations/0002_drop_work_dir.sql
@@ -0,0 +1,4 @@
+-- Drop the unused work_dir column from agent_task_queue.
+-- Deploy code changes first (server/CLI no longer read/write this column),
+-- then run this migration.
+ALTER TABLE agent_task_queue DROP COLUMN work_dir;
diff --git a/src/web/migrations/0003_add_call_id.sql b/src/web/migrations/0003_add_call_id.sql
new file mode 100644
index 000000000..6ec2aea59
--- /dev/null
+++ b/src/web/migrations/0003_add_call_id.sql
@@ -0,0 +1,2 @@
+-- Add call_id column to task_message for pairing tool-use with tool-result.
+ALTER TABLE task_message ADD COLUMN call_id TEXT NOT NULL DEFAULT '';
diff --git a/src/web/next.config.ts b/src/web/next.config.ts
index 9352f4e33..418e01721 100644
--- a/src/web/next.config.ts
+++ b/src/web/next.config.ts
@@ -1,7 +1,10 @@
import type { NextConfig } from "next";
+import path from "node:path";
const nextConfig: NextConfig = {
- /* config options here */
+ turbopack: {
+ root: path.resolve(__dirname, "../.."),
+ },
};
export default nextConfig;
diff --git a/src/web/src/app/(app)/w/[slug]/agents/[id]/chat/[convId]/page.tsx b/src/web/src/app/(app)/w/[slug]/agents/[id]/chat/[convId]/page.tsx
index c0a318da5..89d5cf849 100644
--- a/src/web/src/app/(app)/w/[slug]/agents/[id]/chat/[convId]/page.tsx
+++ b/src/web/src/app/(app)/w/[slug]/agents/[id]/chat/[convId]/page.tsx
@@ -1,10 +1,10 @@
"use client";
-import { useEffect, useState, useRef, useCallback } from "react";
+import React, { useEffect, useState, useRef, useCallback } from "react";
import { useParams } from "next/navigation";
import { useWorkspace } from "@/contexts/workspace-context";
import { Button } from "@/components/ui/button";
-import { Badge } from "@/components/ui/badge";
+import { TaskStream } from "@/components/task-stream";
import {
getConversation,
listMessages,
@@ -105,8 +105,7 @@ export default function AgentChatDetailPage() {
} catch {
toast.error("Failed to refresh messages");
}
- setActiveTask(null);
- setTaskMessages([]);
+ setActiveTask(task);
}
} catch {
pollFailures.current += 1;
@@ -192,7 +191,16 @@ export default function AgentChatDetailPage() {
return (
<>
{/* Messages */}
- <div className="flex-1 overflow-y-auto px-5" ref={scrollRef}>
+ <div
+ className="flex-1 overflow-y-auto px-5 thin-scrollbar"
+ ref={scrollRef}
+ onClick={(e) => {
+ const btn = (e.target as HTMLElement).closest(
+ '[data-streamdown="code-block-actions"] button'
+ );
+ if (btn) toast.success("Copied to clipboard");
+ }}
+ >
<div className="mx-auto max-w-2xl py-6 space-y-4">
{messages.length === 0 && !activeTask && (
<p className="text-center text-muted-foreground py-20 text-sm">
@@ -201,73 +209,39 @@ export default function AgentChatDetailPage() {
)}
{messages.map((msg) => (
- <div
- key={msg.id}
- className={`flex ${msg.role === "user" ? "justify-end" : "justify-start"}`}
- >
- {msg.role === "user" ? (
- <div className="max-w-[80%] rounded-lg px-4 py-2 bg-primary text-primary-foreground whitespace-pre-wrap">
- {msg.content}
- </div>
- ) : (
- <div className="markdown max-w-full px-1 py-1 text-base text-foreground">
- <Streamdown>{msg.content}</Streamdown>
- </div>
+ <React.Fragment key={msg.id}>
+ {/* Show trace before the assistant message it produced */}
+ {activeTask && msg.role === "assistant" && msg.task_id === activeTask.id && taskMessages.length > 0 && (
+ <TaskStream
+ task={activeTask}
+ messages={taskMessages}
+ connectionLost={connectionLost}
+ hideText
+ />
)}
- </div>
+ <div
+ className={`flex ${msg.role === "user" ? "justify-end" : "justify-start"}`}
+ >
+ {msg.role === "user" ? (
+ <div className="max-w-[80%] rounded-lg px-4 py-2 bg-primary text-primary-foreground whitespace-pre-wrap">
+ {msg.content}
+ </div>
+ ) : (
+ <div className="markdown max-w-full px-1 py-1 text-base text-foreground">
+ <Streamdown controls={{ code: { copy: true, download: false } }}>{msg.content}</Streamdown>
+ </div>
+ )}
+ </div>
+ </React.Fragment>
))}
- {activeTask && (
- <div className="rounded-lg border bg-muted/50 p-4 space-y-2">
- <div className="flex items-center gap-2">
- <Badge variant="secondary">
- {activeTask.status === "running"
- ? "Agent working..."
- : activeTask.status}
- </Badge>
- </div>
- {taskMessages.length > 0 && (
- <div className="mt-2 max-h-60 overflow-y-auto rounded-lg bg-muted/30 p-3 font-mono text-xs space-y-1">
- {taskMessages.map((tm) => (
- <div key={tm.id} className="text-muted-foreground">
- {tm.type === "tool-use" && (
- <span className="text-primary">
- [tool] {tm.tool}
- </span>
- )}
- {tm.type === "tool-result" && (
- <span className="text-accent-foreground">
- [result] {tm.output || tm.content}
- </span>
- )}
- {tm.type === "text" && <span>{tm.content}</span>}
- {tm.type === "thinking" && (
- <span className="italic opacity-60">
- {tm.content}
- </span>
- )}
- {!["tool-use", "tool-result", "text", "thinking"].includes(
- tm.type
- ) && (
- <span>
- [{tm.type}] {tm.content}
- </span>
- )}
- </div>
- ))}
- </div>
- )}
- {activeTask.status === "failed" && activeTask.error && (
- <p className="text-sm text-destructive">
- {activeTask.error}
- </p>
- )}
- {connectionLost && (
- <p className="text-xs text-muted-foreground animate-pulse">
- Connection lost — retrying...
- </p>
- )}
- </div>
+ {/* Show trace while task is in progress (no assistant message yet) */}
+ {activeTask && activeTask.status !== "completed" && activeTask.status !== "failed" && (
+ <TaskStream
+ task={activeTask}
+ messages={taskMessages}
+ connectionLost={connectionLost}
+ />
)}
</div>
</div>
@@ -279,7 +253,7 @@ export default function AgentChatDetailPage() {
className={cn(
"relative flex flex-col rounded-xl border bg-background/60 transition-colors duration-200",
"focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50",
- (sending || !!activeTask) && "opacity-50"
+ (sending || (!!activeTask && activeTask.status !== "completed" && activeTask.status !== "failed")) && "opacity-50"
)}
>
<textarea
@@ -288,7 +262,7 @@ export default function AgentChatDetailPage() {
onKeyDown={handleKeyDown}
placeholder="Type a message..."
rows={1}
- disabled={sending || !!activeTask}
+ disabled={sending || (!!activeTask && activeTask.status !== "completed" && activeTask.status !== "failed")}
className={cn(
"field-sizing-content w-full resize-none bg-transparent px-3.5 pt-2.5 text-base outline-none",
"placeholder:text-muted-foreground disabled:cursor-not-allowed",
@@ -299,7 +273,7 @@ export default function AgentChatDetailPage() {
<Button
size="icon-sm"
onClick={handleSend}
- disabled={!input.trim() || sending || !!activeTask}
+ disabled={!input.trim() || sending || (!!activeTask && activeTask.status !== "completed" && activeTask.status !== "failed")}
className={cn(
"rounded-lg transition-opacity duration-200",
!input.trim() && "opacity-40"
diff --git a/src/web/src/app/(app)/w/[slug]/runtimes/page.tsx b/src/web/src/app/(app)/w/[slug]/runtimes/page.tsx
index 0209bb925..e3e9c98b2 100644
--- a/src/web/src/app/(app)/w/[slug]/runtimes/page.tsx
+++ b/src/web/src/app/(app)/w/[slug]/runtimes/page.tsx
@@ -45,7 +45,7 @@ function ConnectMachineSteps({
const copyToClipboard = (text: string) => {
navigator.clipboard.writeText(text);
- toast("Copied to clipboard");
+ toast.success("Copied to clipboard");
};
return (
@@ -89,7 +89,7 @@ function ConnectMachineSteps({
navigator.clipboard.writeText(
`${CLI_CMD} register --token ${generatedToken}`
);
- toast("Copied to clipboard");
+ toast.success("Copied to clipboard");
}}
className="w-full"
>
diff --git a/src/web/src/app/api/daemon/runtimes/[runtimeId]/tasks/claim/route.test.ts b/src/web/src/app/api/daemon/runtimes/[runtimeId]/tasks/claim/route.test.ts
index 9a9677784..8b822eabd 100644
--- a/src/web/src/app/api/daemon/runtimes/[runtimeId]/tasks/claim/route.test.ts
+++ b/src/web/src/app/api/daemon/runtimes/[runtimeId]/tasks/claim/route.test.ts
@@ -88,7 +88,7 @@ describe("POST /api/daemon/runtimes/[runtimeId]/tasks/claim", () => {
instructions: "be helpful",
runtimeConfig: { model: "gpt-4" },
};
- const fakeSession = { sessionId: "sess1", workDir: "/tmp/work" };
+ const fakeSession = { sessionId: "sess1" };
mockClaimTaskForRuntime.mockResolvedValue(fakeTask);
mockGetAgent.mockResolvedValue(fakeAgent);
@@ -126,7 +126,6 @@ describe("POST /api/daemon/runtimes/[runtimeId]/tasks/claim", () => {
runtime_config: { model: "gpt-4" },
});
expect(body.task.prior_session_id).toBe("sess1");
- expect(body.task.prior_work_dir).toBe("/tmp/work");
expect(mockGetAgent).toHaveBeenCalledWith({}, "a1");
expect(mockGetLastTaskSession).toHaveBeenCalledWith({}, "a1", "conv1");
});
diff --git a/src/web/src/app/api/daemon/runtimes/[runtimeId]/tasks/claim/route.ts b/src/web/src/app/api/daemon/runtimes/[runtimeId]/tasks/claim/route.ts
index 17ef20751..3e4c9c71c 100644
--- a/src/web/src/app/api/daemon/runtimes/[runtimeId]/tasks/claim/route.ts
+++ b/src/web/src/app/api/daemon/runtimes/[runtimeId]/tasks/claim/route.ts
@@ -39,7 +39,6 @@ export const POST = withAuth(async (_req, ctx) => {
}
: null,
prior_session_id: priorSession?.sessionId ?? null,
- prior_work_dir: priorSession?.workDir ?? null,
},
});
});
diff --git a/src/web/src/app/api/daemon/tasks/[taskId]/complete/route.ts b/src/web/src/app/api/daemon/tasks/[taskId]/complete/route.ts
index de68cd985..f88942422 100644
--- a/src/web/src/app/api/daemon/tasks/[taskId]/complete/route.ts
+++ b/src/web/src/app/api/daemon/tasks/[taskId]/complete/route.ts
@@ -22,15 +22,13 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
const result = JSON.stringify(body);
const sessionId = body.session_id || "";
- const workDir = body.work_dir || "";
const taskService = new TaskService(db);
try {
const task = await taskService.completeTask(
taskId,
result,
- sessionId,
- workDir
+ sessionId
);
broadcastToUser(ctx.userId, { type: "task.updated", taskId, status: "completed" }).catch(() => {});
return writeJSON(taskToResponse(task));
diff --git a/src/web/src/app/api/daemon/tasks/[taskId]/messages/route.ts b/src/web/src/app/api/daemon/tasks/[taskId]/messages/route.ts
index 1b521bdef..3b60a5b4c 100644
--- a/src/web/src/app/api/daemon/tasks/[taskId]/messages/route.ts
+++ b/src/web/src/app/api/daemon/tasks/[taskId]/messages/route.ts
@@ -42,6 +42,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
seq: m.seq,
type: m.type,
tool: m.tool || "",
+ callId: m.call_id || "",
content: m.content || "",
input: m.input,
output: m.output || "",
diff --git a/src/web/src/app/globals.css b/src/web/src/app/globals.css
index 1f8d7a601..d0f901113 100644
--- a/src/web/src/app/globals.css
+++ b/src/web/src/app/globals.css
@@ -269,6 +269,26 @@
-ms-overflow-style: none;
scrollbar-width: none;
}
+
+/* ── Utility: thin scrollbar ── */
+.thin-scrollbar {
+ scrollbar-width: thin;
+ scrollbar-color: var(--border) transparent;
+}
+.thin-scrollbar::-webkit-scrollbar {
+ width: 4px;
+ height: 4px;
+}
+.thin-scrollbar::-webkit-scrollbar-track {
+ background: transparent;
+}
+.thin-scrollbar::-webkit-scrollbar-thumb {
+ background: var(--border);
+ border-radius: 2px;
+}
+.thin-scrollbar::-webkit-scrollbar-thumb:hover {
+ background: var(--muted-foreground);
+}
.scrollbar-none::-webkit-scrollbar {
display: none;
}
@@ -359,6 +379,7 @@
overflow-x: auto;
font-size: 0.85em;
line-height: 1.55;
+ width: 100%;
}
.markdown pre:not(:has(> code)) {
padding: 0.75em 1em;
@@ -404,3 +425,100 @@
}
.markdown strong { font-weight: 600; }
.markdown em { font-style: italic; }
+
+/* ── Thin scrollbar (code blocks, tool panels, chat scroll) ── */
+.markdown pre,
+[data-streamdown] pre,
+.task-stream-pre {
+ scrollbar-width: thin;
+ scrollbar-color: var(--border) transparent;
+}
+.markdown pre::-webkit-scrollbar,
+[data-streamdown] pre::-webkit-scrollbar,
+.task-stream-pre::-webkit-scrollbar {
+ height: 4px;
+ width: 4px;
+}
+.markdown pre::-webkit-scrollbar-track,
+[data-streamdown] pre::-webkit-scrollbar-track,
+.task-stream-pre::-webkit-scrollbar-track {
+ background: transparent;
+}
+.markdown pre::-webkit-scrollbar-thumb,
+[data-streamdown] pre::-webkit-scrollbar-thumb,
+.task-stream-pre::-webkit-scrollbar-thumb {
+ background: var(--border);
+ border-radius: 2px;
+}
+.markdown pre::-webkit-scrollbar-thumb:hover,
+[data-streamdown] pre::-webkit-scrollbar-thumb:hover,
+.task-stream-pre::-webkit-scrollbar-thumb:hover {
+ background: var(--muted-foreground);
+}
+
+/* ── Streamdown code block: everything inside the dark area ── */
+
+/* Outer container: no padding, no border, no gap — code body IS the block */
+[data-streamdown="code-block"] {
+ position: relative !important;
+ padding: 0 !important;
+ margin-top: 0.5em !important;
+ margin-bottom: 0.5em !important;
+ gap: 0 !important;
+ border: none !important;
+ background: transparent !important;
+}
+
+/* Header (language label): hidden, shows on hover inside the code body */
+[data-streamdown="code-block-header"] {
+ position: absolute !important;
+ top: 0.375rem;
+ left: 0.625rem;
+ z-index: 5;
+ height: auto !important;
+ padding: 0 !important;
+ background: transparent !important;
+ font-size: 0.7rem;
+ opacity: 0;
+ pointer-events: none;
+ transition: opacity 150ms ease;
+}
+[data-streamdown="code-block"]:hover [data-streamdown="code-block-header"] {
+ opacity: 0.5;
+}
+
+/* Code body: the only visible element, owns the rounded corners */
+[data-streamdown="code-block-body"] {
+ padding: 0.5rem 0.75rem !important;
+ border-radius: 0.5rem !important;
+}
+
+/* Actions wrapper: anchor inside top-right of code body */
+[data-streamdown="code-block"] > div:has([data-streamdown="code-block-actions"]) {
+ position: absolute !important;
+ top: 0.375rem;
+ right: 0.375rem;
+ z-index: 10;
+ margin-top: 0 !important;
+ height: auto !important;
+ pointer-events: none !important;
+}
+[data-streamdown="code-block"]:hover > div:has([data-streamdown="code-block-actions"]) {
+ pointer-events: auto !important;
+}
+
+/* ── Streamdown code block actions: show on hover ── */
+[data-streamdown="code-block-actions"] {
+ opacity: 0;
+ pointer-events: none;
+ transition: opacity 150ms ease;
+ background: oklch(0.25 0.01 60) !important;
+ border-color: oklch(1 0.005 80 / 12%) !important;
+}
+.dark [data-streamdown="code-block-actions"] {
+ background: oklch(0.22 0.008 60) !important;
+}
+[data-streamdown="code-block"]:hover [data-streamdown="code-block-actions"] {
+ opacity: 1;
+ pointer-events: auto;
+}
diff --git a/src/web/src/app/layout.tsx b/src/web/src/app/layout.tsx
index 16fbed89f..548f45524 100644
--- a/src/web/src/app/layout.tsx
+++ b/src/web/src/app/layout.tsx
@@ -13,13 +13,13 @@ const dmSans = DM_Sans({
const dmMono = DM_Mono({
variable: "--font-dm-mono",
subsets: ["latin"],
- weight: ["400", "500"],
+ weight: ["400"],
});
const caveat = Caveat({
variable: "--font-caveat",
subsets: ["latin"],
- weight: ["400", "500", "600", "700"],
+ weight: ["700"],
});
diff --git a/src/web/src/components/agent-edit-form.tsx b/src/web/src/components/agent-edit-form.tsx
index e979d1dc0..3e08bc4f9 100644
--- a/src/web/src/components/agent-edit-form.tsx
+++ b/src/web/src/components/agent-edit-form.tsx
@@ -133,11 +133,25 @@ export function AgentEditForm({
<div className="space-y-1.5">
<Label htmlFor="agent-runtime">Runtime</Label>
- <RuntimeSelect
- value={runtimeId}
- onValueChange={setRuntimeId}
- runtimes={runtimes}
- />
+ {agent ? (
+ <p className="text-sm text-muted-foreground">
+ {(() => {
+ const rt = runtimes.find((r) => r.id === agent.runtime_id);
+ if (!rt) return "Unknown runtime";
+ const machine =
+ (typeof rt.device_info === "string" ? rt.device_info : "") ||
+ rt.name ||
+ "";
+ return machine ? `${rt.provider} (${machine})` : rt.provider;
+ })()}
+ </p>
+ ) : (
+ <RuntimeSelect
+ value={runtimeId}
+ onValueChange={setRuntimeId}
+ runtimes={runtimes}
+ />
+ )}
</div>
<div className="flex items-center gap-2 pt-2">
diff --git a/src/web/src/components/dashboard-navbar.tsx b/src/web/src/components/dashboard-navbar.tsx
index eb91ed8f9..6318bca92 100644
--- a/src/web/src/components/dashboard-navbar.tsx
+++ b/src/web/src/components/dashboard-navbar.tsx
@@ -44,7 +44,7 @@ function OnboardingSteps({
const copyToClipboard = (text: string) => {
navigator.clipboard.writeText(text);
- toast("Copied to clipboard");
+ toast.success("Copied to clipboard");
};
return (
@@ -98,7 +98,7 @@ function OnboardingSteps({
navigator.clipboard.writeText(
`${CLI_CMD} register --token ${generatedToken}`
);
- toast("Copied to clipboard");
+ toast.success("Copied to clipboard");
}}
className="w-full"
>
@@ -208,7 +208,7 @@ export function DashboardNavbar() {
const handleCopyToken = async () => {
await navigator.clipboard.writeText(generatedToken);
setTokenCopied(true);
- toast("Copied to clipboard");
+ toast.success("Copied to clipboard");
};
return (
diff --git a/src/web/src/components/nav-user.tsx b/src/web/src/components/nav-user.tsx
index 5e8ccd08c..1c38ab686 100644
--- a/src/web/src/components/nav-user.tsx
+++ b/src/web/src/components/nav-user.tsx
@@ -1,5 +1,6 @@
"use client";
+import { useState, useEffect } from "react";
import { useRouter } from "next/navigation";
import { useSession, signOut } from "@/lib/auth-client";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
@@ -17,9 +18,14 @@ import { LogOut } from "lucide-react";
export function NavUser() {
const { data: session } = useSession();
const router = useRouter();
+ const [mounted, setMounted] = useState(false);
+
+ useEffect(() => {
+ setMounted(true);
+ }, []);
const user = session?.user;
- if (!user) return null;
+ if (!mounted || !user) return null;
const initials = (user.name ?? user.email ?? "?")
.split(/[\s@]/)
diff --git a/src/web/src/components/task-stream.tsx b/src/web/src/components/task-stream.tsx
new file mode 100644
index 000000000..9447fade6
--- /dev/null
+++ b/src/web/src/components/task-stream.tsx
@@ -0,0 +1,289 @@
+"use client";
+
+import { useMemo } from "react";
+import { Badge } from "@/components/ui/badge";
+import { cn } from "@/lib/utils";
+import type { TaskMessage } from "@alook/shared";
+import type { Task } from "@/lib/api";
+import {
+ Terminal,
+ FileText,
+ Search,
+ Pencil,
+ Play,
+ ChevronRight,
+ Brain,
+ AlertCircle,
+} from "lucide-react";
+import { Streamdown } from "streamdown";
+
+/* ── Tool icon mapping ── */
+
+const TOOL_ICONS: Record<string, React.ElementType> = {
+ read_file: FileText,
+ write_file: Pencil,
+ edit_file: Pencil,
+ search: Search,
+ grep: Search,
+ find: Search,
+ bash: Terminal,
+ execute: Terminal,
+ run: Play,
+};
+
+function getToolIcon(tool: string): React.ElementType {
+ const lower = tool.toLowerCase();
+ for (const [key, icon] of Object.entries(TOOL_ICONS)) {
+ if (lower.includes(key)) return icon;
+ }
+ return Terminal;
+}
+
+function formatToolName(tool: string): string {
+ return tool
+ .replace(/_/g, " ")
+ .replace(/\b\w/g, (c) => c.toUpperCase());
+}
+
+/* ── Grouped stream items ── */
+
+interface ToolCallGroup {
+ kind: "tool-call";
+ id: string;
+ tool: string;
+ input?: Record<string, unknown>;
+ output?: string;
+}
+
+interface TextItem {
+ kind: "text";
+ id: string;
+ content: string;
+}
+
+interface ThinkingItem {
+ kind: "thinking";
+ id: string;
+ content: string;
+}
+
+interface StatusItem {
+ kind: "status";
+ id: string;
+ content: string;
+ type: string;
+}
+
+type StreamItem = ToolCallGroup | TextItem | ThinkingItem | StatusItem;
+
+/** Types that are agent-internal lifecycle events, never user-facing. */
+const HIDDEN_TYPES = new Set(["status", "log"]);
+
+function groupMessages(messages: TaskMessage[]): StreamItem[] {
+ const items: StreamItem[] = [];
+ const toolCalls = new Map<string, ToolCallGroup>();
+
+ for (const msg of messages) {
+ if (HIDDEN_TYPES.has(msg.type)) continue;
+ switch (msg.type) {
+ case "tool-use": {
+ const callId = msg.call_id;
+ const group: ToolCallGroup = {
+ kind: "tool-call",
+ id: msg.id,
+ tool: msg.tool,
+ input: msg.input,
+ };
+ if (callId) toolCalls.set(callId, group);
+ items.push(group);
+ break;
+ }
+ case "tool-result": {
+ const callId = msg.call_id;
+ const existing = callId ? toolCalls.get(callId) : undefined;
+ if (existing) {
+ existing.output = msg.output || msg.content;
+ } else {
+ // Standalone result — attach to most recent tool-call without output
+ const lastTool = [...items]
+ .reverse()
+ .find((i): i is ToolCallGroup => i.kind === "tool-call" && !i.output);
+ if (lastTool) {
+ lastTool.output = msg.output || msg.content;
+ } else {
+ items.push({
+ kind: "status",
+ id: msg.id,
+ content: msg.output || msg.content,
+ type: "tool-result",
+ });
+ }
+ }
+ break;
+ }
+ case "text":
+ items.push({ kind: "text", id: msg.id, content: msg.content });
+ break;
+ case "thinking":
+ items.push({ kind: "thinking", id: msg.id, content: msg.content });
+ break;
+ case "error":
+ items.push({
+ kind: "status",
+ id: msg.id,
+ content: msg.content || msg.output,
+ type: "error",
+ });
+ break;
+ default:
+ // Unknown types (e.g. future agent lifecycle events) — skip silently
+ break;
+ }
+ }
+
+ return items;
+}
+
+/* ── ToolCallBlock ── */
+
+function ToolCallBlock({ item, isRunning }: { item: ToolCallGroup; isRunning: boolean }) {
+ const Icon = getToolIcon(item.tool);
+ const hasDetails = item.input || item.output;
+
+ const inputStr = useMemo(() => {
+ if (!item.input) return null;
+ try {
+ return JSON.stringify(item.input, null, 2);
+ } catch {
+ return String(item.input);
+ }
+ }, [item.input]);
+
+ return (
+ <details className="group/tool animate-[fade-up_200ms_ease-out_both]">
+ <summary
+ className={cn(
+ "flex items-center gap-2 py-1.5 px-2 -mx-2 rounded-md cursor-pointer select-none",
+ "text-sm text-muted-foreground transition-colors duration-150",
+ "hover:bg-muted/60 hover:text-foreground",
+ "[&::-webkit-details-marker]:hidden [&::marker]:hidden"
+ )}
+ >
+ {hasDetails && (
+ <ChevronRight className="size-3 shrink-0 text-muted-foreground/60 transition-transform duration-150 group-open/tool:rotate-90" />
+ )}
+ <Icon className="size-3.5 shrink-0" />
+ <span className="font-medium text-foreground/80">
+ {formatToolName(item.tool)}
+ </span>
+ {!item.output && isRunning && (
+ <span className="ml-auto size-1.5 rounded-full bg-primary/60 animate-pulse" />
+ )}
+ </summary>
+
+ {hasDetails && (
+ <div className="mt-1 mb-2 space-y-2">
+ {inputStr && (
+ <pre className="task-stream-pre overflow-x-auto rounded-md bg-muted/40 p-2.5 font-mono text-xs leading-relaxed text-muted-foreground max-h-48 overflow-y-auto">
+ {inputStr}
+ </pre>
+ )}
+ {item.output && (
+ <pre className="task-stream-pre overflow-x-auto rounded-md bg-muted/30 border border-border/50 p-2.5 font-mono text-xs leading-relaxed text-foreground/70 max-h-48 overflow-y-auto">
+ {item.output}
+ </pre>
+ )}
+ </div>
+ )}
+ </details>
+ );
+}
+
+/* ── TaskStream ── */
+
+export function TaskStream({
+ task,
+ messages,
+ connectionLost,
+ hideText,
+}: {
+ task: Task;
+ messages: TaskMessage[];
+ connectionLost?: boolean;
+ /** Hide text items (final answer is rendered separately as the assistant message). */
+ hideText?: boolean;
+}) {
+ const allItems = useMemo(() => groupMessages(messages), [messages]);
+ const items = hideText ? allItems.filter((i) => i.kind !== "text") : allItems;
+ const isRunning = task.status !== "completed" && task.status !== "failed";
+
+ return (
+ <div className="space-y-1">
+ <div className="flex items-center gap-2 mb-1">
+ {task.status === "running" ? (
+ <Badge variant="secondary" className="gap-1.5">
+ <span className="size-1.5 rounded-full bg-primary animate-pulse" />
+ Working
+ </Badge>
+ ) : (
+ <Badge variant="secondary">{task.status}</Badge>
+ )}
+ </div>
+
+ {items.length > 0 && (
+ <div className="space-y-0.5">
+ {items.map((item) => {
+ switch (item.kind) {
+ case "tool-call":
+ return <ToolCallBlock key={item.id} item={item} isRunning={isRunning} />;
+ case "text":
+ return (
+ <div
+ key={item.id}
+ className="markdown text-sm px-1 animate-[fade-up_200ms_ease-out_both]"
+ >
+ <Streamdown controls={{ code: { copy: true, download: false } }}>{item.content}</Streamdown>
+ </div>
+ );
+ case "thinking":
+ return (
+ <p
+ key={item.id}
+ className="text-sm italic text-muted-foreground/60 px-1 animate-[fade-up_200ms_ease-out_both]"
+ >
+ <Brain className="inline size-3 mr-1 -mt-0.5" />
+ {item.content}
+ </p>
+ );
+ case "status":
+ return (
+ <p
+ key={item.id}
+ className="text-xs text-muted-foreground px-1 animate-[fade-up_200ms_ease-out_both]"
+ >
+ {item.type === "error" && (
+ <AlertCircle className="inline size-3 mr-1 -mt-0.5 text-destructive" />
+ )}
+ {item.content}
+ </p>
+ );
+ }
+ })}
+ </div>
+ )}
+
+ {task.status === "failed" && task.error && (
+ <p className="text-sm text-destructive flex items-center gap-1.5 mt-2">
+ <AlertCircle className="size-3.5 shrink-0" />
+ {task.error}
+ </p>
+ )}
+
+ {connectionLost && (
+ <p className="text-xs text-muted-foreground animate-pulse mt-1">
+ Connection lost — retrying...
+ </p>
+ )}
+ </div>
+ );
+}
diff --git a/src/web/src/lib/api/responses.ts b/src/web/src/lib/api/responses.ts
index efb70145e..40012da3b 100644
--- a/src/web/src/lib/api/responses.ts
+++ b/src/web/src/lib/api/responses.ts
@@ -126,6 +126,7 @@ export function taskMessageToResponse(m: any) {
seq: m.seq,
type: m.type,
tool: m.tool,
+ call_id: m.callId || "",
content: m.content,
output: m.output,
};
diff --git a/src/web/src/lib/services/task.ts b/src/web/src/lib/services/task.ts
index c9c04b0c4..4d5541775 100644
--- a/src/web/src/lib/services/task.ts
+++ b/src/web/src/lib/services/task.ts
@@ -86,8 +86,7 @@ export class TaskService {
async completeTask(
taskId: string,
result: string,
- sessionId: string,
- workDir: string
+ sessionId: string
) {
let parsed: unknown;
try {
@@ -99,7 +98,6 @@ export class TaskService {
const task = await taskQueries.completeTask(this.db, taskId, {
result: parsed,
sessionId: sessionId || null,
- workDir: workDir || null,
});
if (!task) {
diff --git a/src/web/src/test/e2e/task-lifecycle.test.ts b/src/web/src/test/e2e/task-lifecycle.test.ts
index d555520ac..e30cfb18e 100644
--- a/src/web/src/test/e2e/task-lifecycle.test.ts
+++ b/src/web/src/test/e2e/task-lifecycle.test.ts
@@ -120,7 +120,6 @@ describe("task lifecycle", () => {
body: JSON.stringify({
output: "All tests passed",
session_id: "sess_test_123",
- work_dir: "/tmp/e2e",
}),
},
)