Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat: make todo column a draft staging area with agent picker and dispatch

Gusc5cf92e0a1f5
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 5ec8f95b0..608d638ec 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -19,7 +19,7 @@ importers:
version: 6.0.3
vitest:
specifier: ^4.1.5
wrangler:
specifier: ^4.87.0
version: 4.87.0(@cloudflare/[email protected])
@@ -50,7 +50,7 @@ importers:
version: 6.0.3
vitest:
specifier: ^4.1.5
src/email-worker:
dependencies:
@@ -78,7 +78,7 @@ importers:
version: 6.0.3
vitest:
specifier: ^4.1.5
wrangler:
specifier: ^4.87.0
version: 4.87.0(@cloudflare/[email protected])
@@ -109,7 +109,7 @@ importers:
version: 6.0.3
vitest:
specifier: ^4.1.5
src/web:
dependencies:
@@ -181,7 +181,7 @@ importers:
better-auth:
specifier: ^1.6.9
class-variance-authority:
specifier: ^0.7.1
version: 0.7.1
@@ -270,12 +270,15 @@ importers:
tailwindcss:
specifier: ^4
version: 4.2.4
+ tsx:
+ specifier: ^4.21.0
+ version: 4.21.0
typescript:
specifier: ^6.0.3
version: 6.0.3
vitest:
specifier: ^4.1.5
wrangler:
specifier: ^4.87.0
version: 4.87.0(@cloudflare/[email protected])
@@ -297,7 +300,7 @@ importers:
version: 6.0.3
vitest:
specifier: ^4.1.5
wrangler:
specifier: ^4.87.0
version: 4.87.0(@cloudflare/[email protected])
@@ -6474,6 +6477,11 @@ packages:
resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==}
+ resolution: {integrity: sha512-5C1sg4USs1lfG0GFb2RLXsdpXqBSEhAaA/0kPL01wxzpMqLILNxIxIOKiILz+cdg/pLnOUxFYOR5yhHU666wbw==}
+ engines: {node: '>=18.0.0'}
+ hasBin: true
+
resolution: {integrity: sha512-REEB2rVTVDTf4hav1gJ5dIsGylWZrNonvjXFtk1dCi8gND3PhZtnYkyry1bra/Fo+iP6ctTEZbg6vWfdfHq/1A==}
hasBin: true
@@ -9929,14 +9937,14 @@ snapshots:
chai: 6.2.2
tinyrainbow: 3.1.0
dependencies:
'@vitest/spy': 4.1.5
estree-walker: 3.0.3
magic-string: 0.30.21
optionalDependencies:
'@vitest/[email protected]':
dependencies:
@@ -10202,7 +10210,7 @@ snapshots:
dependencies:
@@ -10226,7 +10234,7 @@ snapshots:
react: 19.2.5
react-dom: 19.2.5([email protected])
transitivePeerDependencies:
- '@cloudflare/workers-types'
- '@opentelemetry/api'
@@ -11150,8 +11158,8 @@ snapshots:
'@next/eslint-plugin-next': 16.2.4
eslint: 9.39.4([email protected])
eslint-import-resolver-node: 0.3.10
+ eslint-import-resolver-typescript: 3.10.1([email protected])([email protected]([email protected]))
eslint-plugin-jsx-a11y: 6.10.2([email protected]([email protected]))
eslint-plugin-react: 7.37.5([email protected]([email protected]))
eslint-plugin-react-hooks: 7.1.1([email protected]([email protected]))
@@ -11173,7 +11181,7 @@ snapshots:
transitivePeerDependencies:
- supports-color
dependencies:
'@nolyfill/is-core-module': 1.0.39
debug: 4.4.3
@@ -11184,22 +11192,22 @@ snapshots:
tinyglobby: 0.2.16
unrs-resolver: 1.11.1
optionalDependencies:
transitivePeerDependencies:
- supports-color
dependencies:
debug: 3.2.7
optionalDependencies:
'@typescript-eslint/parser': 8.58.2([email protected]([email protected]))([email protected])
eslint: 9.39.4([email protected])
eslint-import-resolver-node: 0.3.10
+ eslint-import-resolver-typescript: 3.10.1([email protected])([email protected]([email protected]))
transitivePeerDependencies:
- supports-color
dependencies:
'@rtsao/scc': 1.1.0
array-includes: 3.1.9
@@ -11210,7 +11218,7 @@ snapshots:
doctrine: 2.1.0
eslint: 9.39.4([email protected])
eslint-import-resolver-node: 0.3.10
hasown: 2.0.3
is-core-module: 2.16.1
is-glob: 4.0.3
@@ -14279,6 +14287,13 @@ snapshots:
+ dependencies:
+ esbuild: 0.27.3
+ get-tsconfig: 4.14.0
+ optionalDependencies:
+ fsevents: 2.3.3
+
optionalDependencies:
'@turbo/darwin-64': 2.9.8
@@ -14494,7 +14509,7 @@ snapshots:
'@types/unist': 3.0.3
vfile-message: 4.0.3
dependencies:
lightningcss: 1.32.0
picomatch: 4.0.4
@@ -14507,12 +14522,13 @@ snapshots:
fsevents: 2.3.3
jiti: 2.6.1
terser: 5.16.9
+ tsx: 4.21.0
yaml: 2.8.4
dependencies:
'@vitest/expect': 4.1.5
'@vitest/pretty-format': 4.1.5
'@vitest/runner': 4.1.5
'@vitest/snapshot': 4.1.5
@@ -14529,7 +14545,7 @@ snapshots:
tinyexec: 1.1.1
tinyglobby: 0.2.16
tinyrainbow: 3.1.0
why-is-node-running: 2.3.0
optionalDependencies:
'@opentelemetry/api': 1.9.1
diff --git a/src/shared/src/api-types.ts b/src/shared/src/api-types.ts
index 0d189f324..a64436bcd 100644
--- a/src/shared/src/api-types.ts
+++ b/src/shared/src/api-types.ts
@@ -93,6 +93,7 @@ export interface UpdateIssueRequest {
title?: string;
description?: string;
status?: Issue["status"];
+ agent_id?: string;
}
export interface CreateIssueCommentRequest {
diff --git a/src/shared/src/db/queries/issue.ts b/src/shared/src/db/queries/issue.ts
index 97b99490f..f86cd2383 100644
--- a/src/shared/src/db/queries/issue.ts
+++ b/src/shared/src/db/queries/issue.ts
@@ -84,6 +84,8 @@ export async function updateIssue(
description?: string;
status?: IssueStatusType;
latestTaskId?: string | null;
+ agentId?: string;
+ conversationId?: string;
}
) {
const now = new Date().toISOString();
@@ -95,6 +97,8 @@ export async function updateIssue(
description?: string;
status?: IssueStatusType;
latestTaskId?: string | null;
+ agentId?: string;
+ conversationId?: string;
updatedAt: string;
completedAt?: string | null;
} = { updatedAt: now };
@@ -102,6 +106,8 @@ export async function updateIssue(
if (patch.description !== undefined) values.description = patch.description;
if (patch.status !== undefined) values.status = patch.status;
if (patch.latestTaskId !== undefined) values.latestTaskId = patch.latestTaskId;
+ if (patch.agentId !== undefined) values.agentId = patch.agentId;
+ if (patch.conversationId !== undefined) values.conversationId = patch.conversationId;
if (terminal !== undefined) values.completedAt = terminal ? now : null;
const rows = await db
.update(issue)
diff --git a/src/shared/src/schemas.ts b/src/shared/src/schemas.ts
index 2c31c390e..0157d2cc6 100644
--- a/src/shared/src/schemas.ts
+++ b/src/shared/src/schemas.ts
@@ -367,12 +367,14 @@ export const UpdateIssueRequestSchema = z
title: z.string().min(1).max(200).optional(),
description: z.string().max(20_000).optional(),
status: IssueStatusSchema.optional(),
+ agent_id: z.string().min(1).optional(),
})
.refine(
(v) =>
v.title !== undefined ||
v.description !== undefined ||
- v.status !== undefined,
+ v.status !== undefined ||
+ v.agent_id !== undefined,
{ message: "at least one field is required" }
);
export type UpdateIssueRequestInput = z.infer<typeof UpdateIssueRequestSchema>;
diff --git a/src/web/package.json b/src/web/package.json
index 98cf07997..86894efbb 100644
--- a/src/web/package.json
+++ b/src/web/package.json
@@ -72,6 +72,7 @@
"eslint": "^9",
"eslint-config-next": "16.2.4",
"tailwindcss": "^4",
+ "tsx": "^4.21.0",
"typescript": "^6.0.3",
"vitest": "^4.1.5",
"wrangler": "^4.87.0"
diff --git a/src/web/src/app/api/issues/[id]/route.ts b/src/web/src/app/api/issues/[id]/route.ts
index 3e7e2eea0..a4eaaf343 100644
--- a/src/web/src/app/api/issues/[id]/route.ts
+++ b/src/web/src/app/api/issues/[id]/route.ts
@@ -3,14 +3,17 @@ import { getCloudflareContext } from "@opennextjs/cloudflare";
import {
CreateIssueCommentBodySchema,
UpdateIssueRequestSchema,
+ TASK_TYPES,
queries,
} from "@alook/shared";
+import { nanoid } from "nanoid";
import { getDb } from "@/lib/db";
import { withAuth } from "@/lib/middleware/auth";
import { withWorkspaceMember } from "@/lib/middleware/workspace";
import { parseBody, writeError, writeJSON } from "@/lib/middleware/helpers";
-import { issueToResponse, messageToResponse } from "@/lib/api/responses";
+import { issueToResponse, messageToResponse, taskToResponse } from "@/lib/api/responses";
import { TaskService } from "@/lib/services/task";
+import { broadcastToUser } from "@/lib/broadcast";
import { log } from "@/lib/logger";
export const GET = withAuth(async (req: NextRequest, ctx) => {
@@ -63,6 +66,75 @@ export const PATCH = withAuth(async (req: NextRequest, ctx) => {
const [body, err] = await parseBody(req, UpdateIssueRequestSchema);
if (err) return err;
+ // Dispatch-on-assign: assigning an agent to a todo draft issue
+ if (body.agent_id) {
+ if (existing.status !== "todo") {
+ return writeError("Agent assignment is only allowed for todo (draft) issues", 400);
+ }
+
+ const agent = await queries.agent.getAgent(db, body.agent_id, ws.workspaceId, ctx.userId);
+ if (!agent) return writeError("agent not found in workspace", 404);
+ if (!agent.ownerId) return writeError("agent has no owner", 400);
+
+ const conversation = await queries.conversation.createConversation(db, {
+ workspaceId: ws.workspaceId,
+ agentId: body.agent_id,
+ userId: ctx.userId,
+ title: `[Issue] ${existing.title}`.slice(0, 120),
+ type: TASK_TYPES.ISSUE_EVENT,
+ });
+
+ const updated = await queries.issue.updateIssue(db, id, ws.workspaceId, {
+ agentId: body.agent_id,
+ conversationId: conversation.id,
+ status: "in_progress",
+ });
+ if (!updated) return writeError("issue not found", 404);
+
+ await queries.message.createMessage(db, {
+ conversationId: conversation.id,
+ role: "event",
+ content: `Issue created: ${existing.title}`,
+ metadata: JSON.stringify({ issueId: existing.id }),
+ });
+
+ const prompt = existing.description.trim()
+ ? `${existing.title}\n\n${existing.description}`
+ : existing.title;
+
+ const taskService = new TaskService(db);
+ try {
+ const task = await taskService.enqueueTask(
+ body.agent_id,
+ conversation.id,
+ ws.workspaceId,
+ prompt,
+ TASK_TYPES.ISSUE_EVENT,
+ {
+ contextKey: conversation.id,
+ context: { issue_id: existing.id },
+ traceId: "tr_" + nanoid(),
+ parentTaskId: null,
+ }
+ );
+ const issue = await queries.issue.setLatestTask(db, id, ws.workspaceId, task.id) ?? updated;
+ broadcastToUser(ctx.userId, { type: "task.updated", taskId: task.id, agentId: task.agentId, status: "queued" }).catch(() => {});
+ return writeJSON({
+ ...issueToResponse(issue),
+ task: taskToResponse(task),
+ });
+ } catch (taskErr) {
+ await queries.issue.updateIssue(db, id, ws.workspaceId, { status: "todo" });
+ await queries.message.createMessage(db, {
+ conversationId: conversation.id,
+ role: "event",
+ content: `Issue dispatch failed: ${taskErr instanceof Error ? taskErr.message : "unknown error"}`,
+ metadata: JSON.stringify({ issueId: existing.id }),
+ });
+ return writeError(taskErr instanceof Error ? taskErr.message : "failed to dispatch issue", 500);
+ }
+ }
+
const updated = await queries.issue.updateIssue(db, id, ws.workspaceId, {
title: body.title,
description: body.description,
diff --git a/src/web/src/components/issues/issue-sheet.tsx b/src/web/src/components/issues/issue-sheet.tsx
index 46e1905b4..9b23b7561 100644
--- a/src/web/src/components/issues/issue-sheet.tsx
+++ b/src/web/src/components/issues/issue-sheet.tsx
@@ -29,7 +29,9 @@ import { Streamdown } from "streamdown";
import type { Agent, Artifact, Issue, IssueComment, Message, TaskApi } from "@alook/shared";
import { isTerminalIssueStatus } from "@alook/shared";
import type { TraceTask } from "@/lib/api";
+import { updateIssue } from "@/lib/api";
import { AvatarRenderer, parseAvatarUrl } from "@/components/avatar";
+import { ConfirmDialog } from "@/components/ui/confirm-dialog";
// --- Constants ---
@@ -185,6 +187,7 @@ export interface IssueSheetProps {
onUpdate?: (issueId: string, patch: { title?: string; description?: string }) => void;
onStatusChange?: (issueId: string, status: string) => Promise<void>;
onCommented?: () => void;
+ onDispatched?: (issueId: string) => void;
}
export function IssueSheet({
@@ -208,6 +211,7 @@ export function IssueSheet({
onUpdate,
onStatusChange,
onCommented,
+ onDispatched,
}: IssueSheetProps) {
const mode = issue ? "detail" : "create";
@@ -218,6 +222,8 @@ export function IssueSheet({
const [assigneeOpen, setAssigneeOpen] = useState(false);
const [commentContent, setCommentContent] = useState("");
const [commentSubmitting, setCommentSubmitting] = useState(false);
+ const [confirmAgent, setConfirmAgent] = useState<Agent | null>(null);
+ const [dispatching, setDispatching] = useState(false);
const titleRef = useRef<HTMLTextAreaElement>(null);
const descriptionRef = useRef<HTMLDivElement>(null);
@@ -356,6 +362,8 @@ export function IssueSheet({
}
};
+ const isTodoDraft = mode === "detail" && issue?.status === "todo";
+
const selectedAgent = agents.find((a) => a.id === agentId) ?? null;
const detailAgent = issue?.agent_id ? agents.find((a) => a.id === issue.agent_id) ?? null : null;
@@ -443,7 +451,7 @@ export function IssueSheet({
</>
);
- const commentInput = mode === "detail" && issue && !isTaskActive && !isTerminalIssueStatus(issue.status) ? (
+ const commentInput = mode === "detail" && issue && !isTodoDraft && !isTaskActive && !isTerminalIssueStatus(issue.status) ? (
<div className="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">
<textarea
ref={commentRef}
@@ -493,13 +501,13 @@ export function IssueSheet({
<div className="shrink-0 space-y-1.5 px-2 sm:px-3 py-2">
{/* Agent row */}
<PropertyRow icon={<User className="size-3.5" />}>
- {mode === "create" ? (
+ {mode === "create" || isTodoDraft ? (
<Popover open={assigneeOpen} onOpenChange={setAssigneeOpen}>
<PopoverTrigger
render={
<button
type="button"
- disabled={submitting}
+ disabled={submitting || dispatching}
className={cn(GHOST_CONTROL, "flex items-center gap-1.5 rounded-md")}
/>
}
@@ -511,19 +519,28 @@ export function IssueSheet({
)}
</PopoverTrigger>
<PopoverContent align="start" className="max-h-64 w-72 overflow-y-auto thin-scrollbar p-1">
- <button
- type="button"
- onClick={() => { setAgentId(""); setAssigneeOpen(false); }}
- className="flex w-full items-center justify-between gap-2 rounded-md px-2 py-2 text-left text-sm transition-colors hover:bg-accent hover:text-accent-foreground"
- >
- <span className="text-muted-foreground">None (unassigned)</span>
- {!agentId ? <Check className="size-3.5 shrink-0" /> : null}
- </button>
+ {!isTodoDraft && (
+ <button
+ type="button"
+ onClick={() => { setAgentId(""); setAssigneeOpen(false); }}
+ className="flex w-full items-center justify-between gap-2 rounded-md px-2 py-2 text-left text-sm transition-colors hover:bg-accent hover:text-accent-foreground"
+ >
+ <span className="text-muted-foreground">None (unassigned)</span>
+ {!agentId ? <Check className="size-3.5 shrink-0" /> : null}
+ </button>
+ )}
{agents.map((agent) => (
<button
key={agent.id}
type="button"
- onClick={() => { setAgentId(agent.id); setAssigneeOpen(false); }}
+ onClick={() => {
+ if (isTodoDraft) {
+ setConfirmAgent(agent);
+ } else {
+ setAgentId(agent.id);
+ }
+ setAssigneeOpen(false);
+ }}
className="flex w-full items-center justify-between gap-2 rounded-md px-2 py-2 text-left text-sm transition-colors hover:bg-accent hover:text-accent-foreground"
>
<AgentIdentity agent={agent} size={18} />
@@ -547,7 +564,10 @@ export function IssueSheet({
onChange={(e) => handleStatusChange(e.target.value)}
className={GHOST_SELECT}
>
- {SELECTOR_STATUSES.map((s) => (
+ {(isTodoDraft
+ ? (["todo", "done"] as const)
+ : SELECTOR_STATUSES
+ ).map((s) => (
<option key={s} value={s}>{statusLabel(s)}</option>
))}
</select>
@@ -624,8 +644,8 @@ export function IssueSheet({
className="hidden sm:block absolute -left-px top-0 bottom-0 w-1.5 cursor-col-resize z-10 hover:bg-primary/20 active:bg-primary/30 transition-colors rounded-l-xl"
/>
- {/* Timeline floating panel — desktop only, detail mode only */}
- {mode === "detail" && (
+ {/* Timeline floating panel — desktop only, detail mode only, not for todo drafts */}
+ {mode === "detail" && !isTodoDraft && (
<div className="hidden lg:flex absolute right-full top-0 bottom-0 mr-2 w-[360px] flex-col rounded-xl border bg-background shadow-lg overflow-hidden">
<div className="shrink-0 flex items-center border-b px-4 py-2.5">
<span className="text-xs font-medium text-muted-foreground">Activity</span>
@@ -647,8 +667,8 @@ export function IssueSheet({
</SheetTitle>
<div className="flex flex-1 min-h-0 flex-col" onKeyDownCapture={onKeyDownCapture}>
- {/* Mobile tab switcher (detail mode only, below lg) */}
- {mode === "detail" && (
+ {/* Mobile tab switcher (detail mode only, below lg, not for todo drafts) */}
+ {mode === "detail" && !isTodoDraft && (
<div className="shrink-0 flex items-center gap-1 border-b px-2 py-1.5 lg:hidden">
<button
type="button"
@@ -683,7 +703,7 @@ export function IssueSheet({
</div>
{/* Mobile timeline view */}
- {mode === "detail" && mobileTab === "activity" && (
+ {mode === "detail" && !isTodoDraft && mobileTab === "activity" && (
<div className="flex flex-col flex-1 min-h-0 lg:hidden">
<div className="flex-1 min-h-0 overflow-y-auto thin-scrollbar px-3 py-4 space-y-3">
{timelineContent}
@@ -723,6 +743,32 @@ export function IssueSheet({
)}
</div>
</SheetContent>
+
+ {/* Dispatch confirmation dialog for todo draft issues */}
+ <ConfirmDialog
+ open={!!confirmAgent}
+ onOpenChange={(open) => { if (!open) setConfirmAgent(null); }}
+ title="Run issue?"
+ description={`This issue will be assigned to ${confirmAgent?.name ?? "the agent"} and start running immediately.`}
+ confirmLabel="Run"
+ loadingLabel="Running..."
+ confirmVariant="default"
+ loading={dispatching}
+ onConfirm={async () => {
+ if (!confirmAgent || !issue) return;
+ setDispatching(true);
+ try {
+ await updateIssue(workspaceId, issue.id, { agent_id: confirmAgent.id });
+ setConfirmAgent(null);
+ onDispatched?.(issue.id);
+ } catch (e) {
+ toast.error(e instanceof Error ? e.message : "Failed to dispatch issue");
+ setConfirmAgent(null);
+ } finally {
+ setDispatching(false);
+ }
+ }}
+ />
</Sheet>
);
}