The VS Code of video editing, built for agents.
TypeScript
feat: reopen session in new project folder and resume conversation
konstantin-paulusfb50341b0f1c
diff --git a/packages/agent-chat/src/host/host.ts b/packages/agent-chat/src/host/host.tsindex 4baa4af5..cf71de8a 100644--- a/packages/agent-chat/src/host/host.ts+++ b/packages/agent-chat/src/host/host.ts@@ -392,6 +392,16 @@ export class AgentHost {if (chat.idleTimer) clearTimeout(chat.idleTimer);chat.idleTimer = null;+ // The project's folder moved since the session opened — a draft that was+ // saved — and the session would go on working in the old one. Closed, it+ // opens again in the new folder and resumes the same conversation: both+ // harnesses find a session by its id, wherever it was started.+ if (chat.session && chat.meta.cwd !== cwd) {+ const session = chat.session;+ chat.session = null;+ await session.close().catch(() => {});+ }+const turnId = randomUUID();const user: Item = { id: `u-${turnId.slice(0, 12)}`, kind: "user", text, ...(attachments.length ? { attachments } : {}) };chat.meta = { ...chat.meta, cwd, model: model.model, status: "running", updatedAt: Date.now() };diff --git a/packages/agent-chat/test/e2e.test.ts b/packages/agent-chat/test/e2e.test.tsindex c9eb587a..4781bf92 100644--- a/packages/agent-chat/test/e2e.test.ts+++ b/packages/agent-chat/test/e2e.test.ts@@ -281,6 +281,24 @@ describe("agent chat end to end", () => {expect(client.state).toBe("open");});+ it("reopens the session in the project's new folder and resumes it", async () => {+ const client = await connect();+ const draft = { projectId: "moved", cwd: "/tmp/drafts/moved" };+ const { chatId } = await client.request("turn.send", { ...draft, text: "first", model: MODEL });+ const chat = follow(client, chatId);+ await chat.until(idle);+ const before = fake.sessions.at(-1)!;+ expect(before.opened.cwd).toBe(draft.cwd);++ await client.request("turn.send", { ...draft, cwd: "/tmp/saved/My Ad", chatId, text: "second", model: MODEL });+ await chat.until((t) => idle(t) && t.items.filter((item) => item.kind === "assistant").length === 2);++ const after = fake.sessions.at(-1)!;+ expect(after).not.toBe(before);+ expect(after.opened.cwd).toBe("/tmp/saved/My Ad");+ expect(after.opened.resume).toEqual(before.resume);+ });+it("deletes a chat and drops it from the list", async () => {const client = await connect();const { chatId } = await client.request("turn.send", { ...PROJECT, text: "bye", model: MODEL });