Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat: add reset button for dm

Gusab61cc1f7728
diff --git a/src/cli/daemon/execenv/__tests__/timeline.test.ts b/src/cli/daemon/execenv/__tests__/timeline.test.ts
index 666fa4dbc..e7742f60a 100644
--- a/src/cli/daemon/execenv/__tests__/timeline.test.ts
+++ b/src/cli/daemon/execenv/__tests__/timeline.test.ts
@@ -253,6 +253,7 @@ describe("timeline", () => {
function makeEntry(overrides: Partial<ContextTimelineEntry>): ContextTimelineEntry {
return {
task_id: "t_1",
+ conversation_id: null,
session_id: null,
pid: null,
status: "running",
@@ -487,5 +488,71 @@ describe("timeline", () => {
expect(findResumableSessionId(dir, "user_dm_message", "claude")).toBe("sess_claude");
expect(findResumableSessionId(dir, "user_dm_message", "codex")).toBe("sess_codex");
});
+
+ it("createTimelineEntry includes conversation_id when provided", () => {
+ const entry = createTimelineEntry("t_c1", "test", "user_dm_message", "sess_1", 1234, "claude", "conv_abc");
+ expect(entry.conversation_id).toBe("conv_abc");
+ });
+
+ it("createTimelineEntry sets conversation_id to null when not provided", () => {
+ const entry = createTimelineEntry("t_c2", "test", "user_dm_message");
+ expect(entry.conversation_id).toBeNull();
+ });
+
+ it("filters by conversationId when provided", () => {
+ writeEntry(_todayFilename(), makeEntry({
+ task_id: "t_conv1",
+ status: "completed",
+ session_id: "sess_conv1",
+ conversation_id: "conv_1",
+ datetime: new Date().toISOString(),
+ }));
+ writeEntry(_todayFilename(), makeEntry({
+ task_id: "t_conv2",
+ status: "completed",
+ session_id: "sess_conv2",
+ conversation_id: "conv_2",
+ datetime: new Date().toISOString(),
+ }));
+
+ expect(findResumableSessionId(dir, "user_dm_message", "claude", undefined, "conv_1")).toBe("sess_conv1");
+ expect(findResumableSessionId(dir, "user_dm_message", "claude", undefined, "conv_2")).toBe("sess_conv2");
+ });
+
+ it("returns null when conversationId doesn't match any entry", () => {
+ writeEntry(_todayFilename(), makeEntry({
+ task_id: "t_conv1",
+ status: "completed",
+ session_id: "sess_conv1",
+ conversation_id: "conv_1",
+ datetime: new Date().toISOString(),
+ }));
+
+ expect(findResumableSessionId(dir, "user_dm_message", "claude", undefined, "conv_other")).toBeNull();
+ });
+
+ it("ignores conversationId filter when not provided (backward compat)", () => {
+ writeEntry(_todayFilename(), makeEntry({
+ task_id: "t_conv1",
+ status: "completed",
+ session_id: "sess_conv1",
+ conversation_id: "conv_1",
+ datetime: new Date().toISOString(),
+ }));
+
+ expect(findResumableSessionId(dir, "user_dm_message", "claude")).toBe("sess_conv1");
+ });
+
+ it("matches entries with null conversation_id when conversationId filter not provided", () => {
+ writeEntry(_todayFilename(), makeEntry({
+ task_id: "t_old",
+ status: "completed",
+ session_id: "sess_old",
+ conversation_id: null,
+ datetime: new Date().toISOString(),
+ }));
+
+ expect(findResumableSessionId(dir, "user_dm_message", "claude")).toBe("sess_old");
+ });
});
});
diff --git a/src/cli/daemon/execenv/timeline.ts b/src/cli/daemon/execenv/timeline.ts
index 0d1e2d009..e2156e1e4 100644
--- a/src/cli/daemon/execenv/timeline.ts
+++ b/src/cli/daemon/execenv/timeline.ts
@@ -22,6 +22,7 @@ function readJsonl(filePath: string): ContextTimelineEntry[] {
export interface ContextTimelineEntry {
task_id: string;
+ conversation_id: string | null;
session_id: string | null;
pid: number | null;
status: "running" | "completed" | "failed" | "killed";
@@ -195,9 +196,11 @@ export function createTimelineEntry(
sessionId?: string,
pid?: number,
provider?: string,
+ conversationId?: string,
): ContextTimelineEntry {
return {
task_id: taskId,
+ conversation_id: conversationId || null,
session_id: sessionId || null,
pid: pid ?? null,
status: "running",
@@ -217,6 +220,7 @@ export function findResumableSessionId(
type: string,
provider: string,
maxAgeMs: number = DEFAULT_RESUME_MAX_AGE_MS,
+ conversationId?: string,
): string | null {
const now = new Date();
const cutoff = new Date(now.getTime() - maxAgeMs);
@@ -236,7 +240,8 @@ export function findResumableSessionId(
entry.type === type &&
entry.provider === provider &&
entry.session_id &&
- new Date(entry.datetime) >= cutoff
+ new Date(entry.datetime) >= cutoff &&
+ (!conversationId || entry.conversation_id === conversationId)
) {
return entry.session_id;
}
diff --git a/src/cli/daemon/session-runner.test.ts b/src/cli/daemon/session-runner.test.ts
index a4850d81e..266bf292c 100644
--- a/src/cli/daemon/session-runner.test.ts
+++ b/src/cli/daemon/session-runner.test.ts
@@ -38,8 +38,10 @@ const mockCreateTimelineEntry = vi.fn(
sessionId?: string,
pid?: number,
provider?: string,
+ conversationId?: string,
) => ({
task_id: taskId,
+ conversation_id: conversationId || null,
session_id: sessionId || null,
pid: pid ?? null,
status: "running",
@@ -213,6 +215,7 @@ describe("session-runner runSession", () => {
"sess-1",
process.pid,
"claude",
+ "c1",
);
expect(mockInitEntryAsync).toHaveBeenCalledWith(
"/tmp/ws/ws1/agent1/workdir/.context_timeline",
@@ -340,6 +343,8 @@ describe("session-runner runSession", () => {
"/tmp/ws/ws1/agent1/workdir/.context_timeline",
"user_dm_message",
"claude",
+ undefined,
+ "c1",
);
expect(mockBackendExecute).toHaveBeenCalledWith(
expect.any(String),
@@ -576,6 +581,7 @@ describe("session-runner runSession", () => {
"sess-1",
process.pid,
"codex",
+ "c1",
);
});
@@ -594,6 +600,8 @@ describe("session-runner runSession", () => {
"/tmp/ws/ws1/agent1/workdir/.context_timeline",
"user_dm_message",
"codex",
+ undefined,
+ "c1",
);
});
@@ -633,6 +641,8 @@ describe("session-runner runSession", () => {
"/tmp/ws/ws1/agent1/workdir/.context_timeline",
"user_dm_message",
"opencode",
+ undefined,
+ "c1",
);
expect(mockBackendExecute).toHaveBeenCalledWith(
expect.any(String),
diff --git a/src/cli/daemon/session-runner.ts b/src/cli/daemon/session-runner.ts
index 49ec51bc7..2fb341c2c 100644
--- a/src/cli/daemon/session-runner.ts
+++ b/src/cli/daemon/session-runner.ts
@@ -36,7 +36,7 @@ export async function runSession(input: SessionRunnerInput): Promise<void> {
const resumeSessionId =
task.type === TASK_TYPES.USER_DM_MESSAGE
- ? findResumableSessionId(timelineDir, task.type, provider) ?? undefined
+ ? findResumableSessionId(timelineDir, task.type, provider, undefined, task.conversationId) ?? undefined
: undefined;
if (resumeSessionId) {
log.info(`Task ${task.id} resuming session ${resumeSessionId}`);
@@ -57,7 +57,7 @@ export async function runSession(input: SessionRunnerInput): Promise<void> {
const earlySessionId = await session.sessionId;
await initEntryAsync(
timelineDir,
- createTimelineEntry(task.id, task.prompt, task.type, earlySessionId, process.pid, provider),
+ createTimelineEntry(task.id, task.prompt, task.type, earlySessionId, process.pid, provider, task.conversationId),
);
// Message batching
diff --git a/src/web/src/components/agent-chat/agent-chat-view.tsx b/src/web/src/components/agent-chat/agent-chat-view.tsx
index 066c04c12..f10fc7138 100644
--- a/src/web/src/components/agent-chat/agent-chat-view.tsx
+++ b/src/web/src/components/agent-chat/agent-chat-view.tsx
@@ -12,13 +12,22 @@ import {
getTask,
getTaskMessages,
getActiveTask,
+ deleteConversation,
} from "@/lib/api";
import type { Conversation, Message, TaskApi as Task, TaskMessage, WsMessage } from "@alook/shared";
import { useAgentContext } from "@/contexts/agent-context";
import { toast } from "sonner";
import { cn } from "@/lib/utils";
import { Skeleton } from "@/components/ui/skeleton";
-import { ArrowUp, Loader2 } from "lucide-react";
+import { ArrowUp, Loader2, RotateCcw } from "lucide-react";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "@/components/ui/dialog";
import { Streamdown } from "streamdown";
const MESSAGE_LIMIT = 20;
@@ -331,6 +340,49 @@ export function AgentChatView() {
}
};
+ const [resetConfirmOpen, setResetConfirmOpen] = useState(false);
+ const [resetting, setResetting] = useState(false);
+ const [resetDontAsk, setResetDontAsk] = useState(false);
+
+ const RESET_SKIP_KEY = "chat-reset-skip-confirm";
+
+ const executeReset = async () => {
+ if (!conversation) return;
+ setResetting(true);
+ try {
+ if (pollRef.current) {
+ clearInterval(pollRef.current);
+ pollRef.current = null;
+ }
+ await deleteConversation(conversation.id, workspaceId);
+ const newConv = await getOrCreateAgentConversation(agentId, workspaceId);
+ setConversation(newConv);
+ setMessages([]);
+ setActiveTask(null);
+ setTaskMessages([]);
+ lastSeqRef.current = 0;
+ setConnectionLost(false);
+ setHasMore(false);
+ initialScrollDone.current = false;
+ } catch {
+ toast.error("Failed to reset conversation");
+ } finally {
+ setResetting(false);
+ setResetConfirmOpen(false);
+ }
+ };
+
+ const handleReset = () => {
+ if (!conversation || messages.length === 0) return;
+ const skip = typeof window !== "undefined" && localStorage.getItem(RESET_SKIP_KEY) === "true";
+ if (skip) {
+ executeReset();
+ } else {
+ setResetDontAsk(false);
+ setResetConfirmOpen(true);
+ }
+ };
+
const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.key === "Enter" && !e.shiftKey) {
e.preventDefault();
@@ -481,7 +533,21 @@ export function AgentChatView() {
"min-h-[38px] max-h-[200px] thin-scrollbar"
)}
/>
- <div className="flex items-center justify-end px-2 pb-2 pt-0.5">
+ <div className="flex items-center justify-between px-2 pb-2 pt-0.5">
+ <Button
+ variant="ghost"
+ size="icon-sm"
+ onClick={handleReset}
+ disabled={resetting || !conversation || messages.length === 0}
+ className="rounded-lg text-muted-foreground/60 hover:text-foreground transition-colors duration-200"
+ title="New conversation"
+ >
+ {resetting ? (
+ <Loader2 className="size-3.5 animate-spin" />
+ ) : (
+ <RotateCcw className="size-3.5" />
+ )}
+ </Button>
<Button
size="icon-sm"
onClick={handleSend}
@@ -501,6 +567,48 @@ export function AgentChatView() {
</div>
</div>
</div>
+
+ <Dialog open={resetConfirmOpen} onOpenChange={setResetConfirmOpen}>
+ <DialogContent showCloseButton={false}>
+ <DialogHeader>
+ <DialogTitle>Start new conversation?</DialogTitle>
+ <DialogDescription>
+ This will clear the current conversation and start fresh. The agent won&apos;t remember context from this chat.
+ </DialogDescription>
+ </DialogHeader>
+ <label className="flex items-center gap-2 text-sm text-muted-foreground cursor-pointer select-none">
+ <input
+ type="checkbox"
+ checked={resetDontAsk}
+ onChange={(e) => setResetDontAsk(e.target.checked)}
+ className="rounded"
+ />
+ Don&apos;t ask me next time
+ </label>
+ <DialogFooter>
+ <Button
+ variant="outline"
+ size="sm"
+ onClick={() => setResetConfirmOpen(false)}
+ disabled={resetting}
+ >
+ Cancel
+ </Button>
+ <Button
+ size="sm"
+ onClick={() => {
+ if (resetDontAsk) {
+ localStorage.setItem(RESET_SKIP_KEY, "true");
+ }
+ executeReset();
+ }}
+ disabled={resetting}
+ >
+ {resetting ? "Resetting..." : "Reset"}
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
</>
);
}
diff --git a/src/web/src/components/task-stream.tsx b/src/web/src/components/task-stream.tsx
index 87fa5d14a..fc25d4c8c 100644
--- a/src/web/src/components/task-stream.tsx
+++ b/src/web/src/components/task-stream.tsx
@@ -359,15 +359,8 @@ export function TaskStream({
{/* Text output zone */}
{textItems.length > 0 && (
- <div className="space-y-3">
- {textItems.map((item) => (
- <div
- key={item.id}
- className="markdown max-w-full min-w-0 px-1 py-1 text-base text-foreground"
- >
- <Streamdown controls={{ code: { copy: true, download: false }, table: { copy: true, download: false, fullscreen: true } }} linkSafety={{ enabled: false }}>{item.content}</Streamdown>
- </div>
- ))}
+ <div className="markdown max-w-full min-w-0 px-1 py-1 text-base text-foreground">
+ <Streamdown controls={{ code: { copy: true, download: false }, table: { copy: true, download: false, fullscreen: true } }} linkSafety={{ enabled: false }}>{textItems.map((item) => item.content).join("\n\n")}</Streamdown>
</div>
)}