The Open Framework for Building Agents
fix(eve): preserve REPL sessions across HMR (#807)
Casey Gowrie90589623954f
diff --git a/.changeset/repl-hmr-session-continuity.md b/.changeset/repl-hmr-session-continuity.mdnew file mode 100644index 000000000..44ff99e2a--- /dev/null+++ b/.changeset/repl-hmr-session-continuity.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Keep an active `eve dev` REPL session across successful authored-source reloads, so its next turn continues the durable conversation on the latest generation.diff --git a/docs/reference/cli.md b/docs/reference/cli.mdindex be3670fb3..1e9bcbb3b 100644--- a/docs/reference/cli.md+++ b/docs/reference/cli.md@@ -158,7 +158,7 @@ For bearer tokens or custom schemes, pass explicit headers with `-H`.Local dev records the last ready URL per resolved app root in `.eve/dev-server-state.v1.json`. A second interactive `eve dev` reconnects only when that URL is loopback and healthy; each terminal UI creates a fresh client session while sharing the server process. A stale or malformed record is replaced when eve starts a new server. Passing `--host`, `--port`, or a `PORT` environment value skips reconnection and reports a healthy recorded server instead.-Local dev keeps immutable runtime source snapshots under `.eve/dev-runtime/snapshots/` so in-flight turns hold a consistent code revision while new turns pick up rebuilds. After a generation is superseded, `eve dev` retains it for at least 30 minutes and also retains the five most recently superseded generations, regardless of the configured Workflow World. The active generation is never pruned. Old runtime snapshots and local sandbox templates are pruned in the background. For manual cleanup, stop `eve dev` before deleting `.eve/dev-runtime/snapshots/` or `.eve/sandbox-cache/local/templates/`. A turn that remains unfinished beyond the automatic retention window can no longer resume after its generation is pruned.+Local dev keeps immutable runtime source snapshots under `.eve/dev-runtime/snapshots/` so in-flight turns hold a consistent code revision while new turns pick up rebuilds. The terminal REPL keeps its logical session across successful rebuilds, so the next turn continues the conversation on the latest generation; use `/new` to start a fresh session. After a generation is superseded, `eve dev` retains it for at least 30 minutes and also retains the five most recently superseded generations, regardless of the configured Workflow World. The active generation is never pruned. Old runtime snapshots and local sandbox templates are pruned in the background. For manual cleanup, stop `eve dev` before deleting `.eve/dev-runtime/snapshots/` or `.eve/sandbox-cache/local/templates/`. A turn that remains unfinished beyond the automatic retention window can no longer resume after its generation is pruned.## `eve link`diff --git a/packages/eve/src/cli/dev/tui/runner.test.ts b/packages/eve/src/cli/dev/tui/runner.test.tsindex f830e5fab..21e1f2622 100644--- a/packages/eve/src/cli/dev/tui/runner.test.ts+++ b/packages/eve/src/cli/dev/tui/runner.test.ts@@ -511,6 +511,112 @@ function sessionYieldingTurns(turns: ReadonlyArray<readonly unknown[]>): ClientSreturn session;}+describe("EveTUIRunner development session continuity", () => {+ it("keeps the REPL session when HMR publishes a new runtime revision", async () => {+ const requests: Array<{ readonly method: string; readonly url: URL }> = [];+ const revisions = ["revision-a", "revision-a", "revision-b", "revision-b"];+ const encoder = new TextEncoder();+ let nextRevision = 0;+ let nextSession = 0;+ vi.stubGlobal(+ "fetch",+ vi.fn(async (input: Parameters<typeof fetch>[0], init?: RequestInit) => {+ const url = new URL(+ typeof input === "string" ? input : input instanceof URL ? input : input.url,+ );+ const method = init?.method ?? "GET";+ requests.push({ method, url });++ if (url.pathname.startsWith("/eve/v1/dev/runtime-artifacts")) {+ const revision = revisions[Math.min(nextRevision, revisions.length - 1)] ?? "revision";+ nextRevision += 1;+ return Response.json({ revision });+ }++ if (method === "POST") {+ const sessionId =+ url.pathname === "/eve/v1/session"+ ? `session-${String(++nextSession)}`+ : (url.pathname.split("/").at(-1) ?? `session-${String(++nextSession)}`);+ return Response.json({+ continuationToken: `token-${sessionId}`,+ sessionId,+ });+ }++ return new Response(+ new ReadableStream<Uint8Array>({+ start(controller) {+ controller.enqueue(encoder.encode('{"type":"session.waiting"}\n'));+ controller.close();+ },+ }),+ );+ }),+ );++ const client = stubClient();+ vi.spyOn(client, "info").mockResolvedValue(AGENT_INFO);+ const session = client.session();+ const createSession = vi.spyOn(client, "session");+ const prompts: Array<string | undefined> = ["first", "second", undefined];+ const runner = new EveTUIRunner({+ client,+ name: "Weather Agent",+ renderer: {+ readPrompt: vi.fn(async () => prompts.shift()),+ renderStream: vi.fn(async (result) => {+ for await (const event of result.events as AsyncIterable<unknown>) {+ void event;+ }+ }),+ },+ serverUrl: "http://localhost:3000",+ session,+ });++ await runner.run();++ expect(createSession).not.toHaveBeenCalled();+ expect(session.state.sessionId).toBe("session-1");+ expect(+ requests+ .filter(+ (request) =>+ request.method === "POST" && request.url.pathname.startsWith("/eve/v1/session"),+ )+ .map((request) => request.url.pathname),+ ).toEqual(["/eve/v1/session", "/eve/v1/session/session-1"]);+ });++ it("starts a fresh session only after an explicit /new command", async () => {+ const initialSession = sessionYielding([{ type: "session.waiting" }]);+ const newSession = sessionYielding([{ type: "session.waiting" }]);+ const client = stubClient();+ const createSession = vi.spyOn(client, "session").mockReturnValue(newSession);+ const prompts: Array<string | undefined> = ["first", "/new", "second", undefined];+ const runner = new EveTUIRunner({+ client,+ name: "Weather Agent",+ renderer: {+ readPrompt: vi.fn(async () => prompts.shift()),+ renderStream: vi.fn(async (result) => {+ for await (const event of result.events as AsyncIterable<unknown>) {+ void event;+ }+ }),+ },+ session: initialSession,+ });++ await runner.run();++ expect(createSession).toHaveBeenCalledOnce();+ expect(initialSession.send).toHaveBeenCalledOnce();+ expect(newSession.send).toHaveBeenCalledOnce();+ });+});+describe("EveTUIRunner terminal-failure recovery", () => {it("starts a fresh session and posts a notice after session.failed", async () => {const notices: string[] = [];diff --git a/packages/eve/src/cli/dev/tui/runner.ts b/packages/eve/src/cli/dev/tui/runner.tsindex d905d7dff..aa1dd0ee9 100644--- a/packages/eve/src/cli/dev/tui/runner.ts+++ b/packages/eve/src/cli/dev/tui/runner.ts@@ -23,8 +23,8 @@ import {import { loadDevelopmentEnvironmentFiles } from "#cli/dev/environment.js";import { subscribeDevelopmentSandboxPrewarmLogs } from "#execution/sandbox/development-prewarm.js";import {- createDevelopmentRuntimeArtifactSessionRefresher,- type DevelopmentRuntimeArtifactSessionRefresher,+ createDevelopmentRuntimeArtifactRefresher,+ type DevelopmentRuntimeArtifactRefresher,} from "#services/dev-client.js";import { toErrorMessage } from "#shared/errors.js";import { devBootPhase, type DevBootProgressReporter } from "#internal/dev-boot-progress.js";@@ -352,8 +352,8 @@ export type EveTUIRunnerOptions = TuiDisplayOptions & {formatTransportError?: (error: unknown) => string;/*** Local `eve dev` server URL. When present, normal prompts refresh the- * active session after HMR so the next prompt uses the latest authored- * artifacts; input-response resumes keep the current session.+ * runtime artifacts after HMR so the next prompt uses the latest authored+ * artifacts while retaining its logical session.*/serverUrl?: string;/** Absolute local application root; omitted for remote `--url` sessions. */@@ -403,7 +403,7 @@ export class EveTUIRunner {readonly #assistantResponseStats: AssistantResponseStatsMode;readonly #contextSize?: number;readonly #formatTransportError: (error: unknown) => string;- readonly #runtimeArtifacts?: DevelopmentRuntimeArtifactSessionRefresher;+ readonly #runtimeArtifacts?: DevelopmentRuntimeArtifactRefresher;readonly #serverUrl?: string;readonly #appRoot?: string;/**@@ -542,7 +542,7 @@ export class EveTUIRunner {if (options.onBootProgress !== undefined) this.#onBootProgress = options.onBootProgress;if (options.serverUrl !== undefined) this.#serverUrl = options.serverUrl;if (options.serverUrl !== undefined && options.remote === undefined) {- this.#runtimeArtifacts = createDevelopmentRuntimeArtifactSessionRefresher({+ this.#runtimeArtifacts = createDevelopmentRuntimeArtifactRefresher({serverUrl: options.serverUrl,});}@@ -896,9 +896,8 @@ export class EveTUIRunner {}const prompt = this.#renderer.readPrompt(options);- const client = this.#client;const runtimeArtifacts = this.#runtimeArtifacts;- if (client === undefined || runtimeArtifacts === undefined) {+ if (runtimeArtifacts === undefined) {return await prompt;}@@ -912,10 +911,8 @@ export class EveTUIRunner {refreshing = true;try {- this.#session = await runtimeArtifacts.refreshIdle({- createSession: () => client.session(),+ await runtimeArtifacts.refreshIdle({onRuntimeArtifactsChanged: () => this.#handleRuntimeArtifactsChanged(),- session: this.#session,});} finally {refreshing = false;@@ -970,14 +967,11 @@ export class EveTUIRunner {let response: Awaited<ReturnType<ClientSession["send"]>>;try {- const client = this.#client;- if (client !== undefined && this.#runtimeArtifacts !== undefined) {- this.#session = await this.#runtimeArtifacts.refresh({- createSession: () => client.session(),+ if (this.#runtimeArtifacts !== undefined) {+ await this.#runtimeArtifacts.refresh({inputResponses: sendInput.inputResponses,message: sendInput.message,onRuntimeArtifactsChanged: () => this.#handleRuntimeArtifactsChanged(),- session: this.#session,});}@@ -1196,14 +1190,11 @@ export class EveTUIRunner {}async #refreshConnectionRuntime(): Promise<void> {- const client = this.#client;const runtimeArtifacts = this.#runtimeArtifacts;- if (client === undefined || runtimeArtifacts === undefined) return;+ if (runtimeArtifacts === undefined) return;- this.#session = await runtimeArtifacts.refreshAfterSourceChange({- createSession: () => client.session(),+ await runtimeArtifacts.refreshAfterSourceChange({onRuntimeArtifactsChanged: () => this.#handleRuntimeArtifactsChanged(),- session: this.#session,});}diff --git a/packages/eve/src/services/dev-client.test.ts b/packages/eve/src/services/dev-client.test.tsindex ecef7ca42..24da03ae0 100644--- a/packages/eve/src/services/dev-client.test.ts+++ b/packages/eve/src/services/dev-client.test.ts@@ -1,7 +1,7 @@import { afterEach, describe, expect, it, vi } from "vitest";import { Client } from "#client/index.js";-import { createDevelopmentRuntimeArtifactSessionRefresher } from "#services/dev-client.js";+import { createDevelopmentRuntimeArtifactRefresher } from "#services/dev-client.js";const encoder = new TextEncoder();@@ -9,8 +9,8 @@ afterEach(() => {vi.unstubAllGlobals();});-describe("runtime-artifact refresher session rotation", () => {- it("starts a fresh local session for normal prompts after the dev artifact revision changes", async () => {+describe("runtime-artifact refresher session continuity", () => {+ it("keeps the active local session for normal prompts after the dev artifact revision changes", async () => {const requests: Array<{ method: string; url: string }> = [];const fetchMock = createDevFetchMock({requests,@@ -18,35 +18,60 @@ describe("runtime-artifact refresher session rotation", () => {});vi.stubGlobal("fetch", fetchMock);const client = new Client({ host: "http://127.0.0.1:3000" });- const refresher = createDevelopmentRuntimeArtifactSessionRefresher({+ const refresher = createDevelopmentRuntimeArtifactRefresher({serverUrl: "http://127.0.0.1:3000",});- let session = client.session();+ const session = client.session();- session = await refresher.refresh({- createSession: () => client.session(),+ await refresher.refresh({message: "first",- session,});await (await session.send({ message: "first" })).result();- const before = session;- session = await refresher.refresh({- createSession: () => client.session(),+ const sessionId = session.state.sessionId;+ await refresher.refresh({message: "second",- session,});await (await session.send({ message: "second" })).result();- // The revision changed between turns, so the second prompt rotates onto a- // fresh session and POSTs /session instead of continuing the first.- expect(session).not.toBe(before);+ expect(session.state.sessionId).toBe(sessionId);const postUrls = requests.filter((request) => {const pathname = new URL(request.url).pathname;return request.method === "POST" && !pathname.startsWith("/eve/v1/dev/runtime-artifacts");}).map((request) => new URL(request.url).pathname);- expect(postUrls).toEqual(["/eve/v1/session", "/eve/v1/session"]);+ expect(postUrls).toEqual(["/eve/v1/session", "/eve/v1/session/session-1"]);+ });++ it("keeps the active session eligible when a candidate rebuild fails", async () => {+ const requests: Array<{ method: string; url: string }> = [];+ const fetchMock = createDevFetchMock({+ failedRebuilds: [false, true],+ requests,+ revisions: ["snapshot-a", "snapshot-a"],+ });+ vi.stubGlobal("fetch", fetchMock);+ const client = new Client({ host: "http://127.0.0.1:3000" });+ const refresher = createDevelopmentRuntimeArtifactRefresher({+ serverUrl: "http://127.0.0.1:3000",+ });+ const session = client.session();++ await refresher.refresh({ message: "first" });+ await (await session.send({ message: "first" })).result();+ const sessionId = session.state.sessionId;++ await refresher.refresh({ message: "second" });+ await (await session.send({ message: "second" })).result();++ expect(session.state.sessionId).toBe(sessionId);+ const postUrls = requests+ .filter((request) => {+ const pathname = new URL(request.url).pathname;+ return request.method === "POST" && !pathname.startsWith("/eve/v1/dev/runtime-artifacts");+ })+ .map((request) => new URL(request.url).pathname);+ expect(postUrls).toEqual(["/eve/v1/session", "/eve/v1/session/session-1"]);});it("keeps the active local session for input-response resumes after the dev artifact revision changes", async () => {@@ -57,27 +82,24 @@ describe("runtime-artifact refresher session rotation", () => {});vi.stubGlobal("fetch", fetchMock);const client = new Client({ host: "http://localhost:3000" });- const refresher = createDevelopmentRuntimeArtifactSessionRefresher({+ const refresher = createDevelopmentRuntimeArtifactRefresher({serverUrl: "http://localhost:3000",});const inputResponses = [{ optionId: "approve", requestId: "request-1" }];- let session = client.session();+ const session = client.session();- session = await refresher.refresh({- createSession: () => client.session(),+ await refresher.refresh({message: "approve a tool",- session,});await (await session.send({ message: "approve a tool" })).result();- const before = session;- session = await refresher.refresh({- createSession: () => client.session(),+ const sessionId = session.state.sessionId;+ await refresher.refresh({inputResponses,- session,});- expect(session).toBe(before);await (await session.send({ inputResponses })).result();+ expect(session.state.sessionId).toBe(sessionId);+const rebuilds = requests.filter((request) => new URL(request.url).pathname === "/eve/v1/dev/runtime-artifacts/rebuild",);@@ -92,8 +114,8 @@ describe("runtime-artifact refresher session rotation", () => {});});-describe("createDevelopmentRuntimeArtifactSessionRefresher", () => {- it("forces a rebuild and rotates an active session after a known source change", async () => {+describe("createDevelopmentRuntimeArtifactRefresher", () => {+ it("forces a rebuild without replacing an active session after a known source change", async () => {const requests: Array<{ method: string; url: string }> = [];const fetchMock = createDevFetchMock({requests,@@ -101,24 +123,18 @@ describe("createDevelopmentRuntimeArtifactSessionRefresher", () => {});vi.stubGlobal("fetch", fetchMock);const client = new Client({ host: "http://localhost:3000" });- const refresher = createDevelopmentRuntimeArtifactSessionRefresher({+ const refresher = createDevelopmentRuntimeArtifactRefresher({serverUrl: "http://localhost:3000",});- let session = client.session();+ const session = client.session();- session = await refresher.refreshIdle({- createSession: () => client.session(),- session,- });+ await refresher.refreshIdle({});await (await session.send({ message: "first" })).result();- const before = session;+ const sessionId = session.state.sessionId;- session = await refresher.refreshAfterSourceChange({- createSession: () => client.session(),- session,- });+ await refresher.refreshAfterSourceChange({});- expect(session).not.toBe(before);+ expect(session.state.sessionId).toBe(sessionId);expect(requests.some((request) => {const url = new URL(request.url);@@ -131,27 +147,24 @@ describe("createDevelopmentRuntimeArtifactSessionRefresher", () => {).toBe(true);});- it("rotates an active session after a known source change without a baseline revision", async () => {+ it("keeps an active session after a known source change without a baseline revision", async () => {const fetchMock = createDevFetchMock({requests: [],revisions: ["snapshot-b"],});vi.stubGlobal("fetch", fetchMock);const client = new Client({ host: "http://localhost:3000" });- const refresher = createDevelopmentRuntimeArtifactSessionRefresher({+ const refresher = createDevelopmentRuntimeArtifactRefresher({serverUrl: "http://localhost:3000",});- let session = client.session();+ const session = client.session();await (await session.send({ message: "first" })).result();- const before = session;+ const sessionId = session.state.sessionId;- session = await refresher.refreshAfterSourceChange({- createSession: () => client.session(),- session,- });+ await refresher.refreshAfterSourceChange({});- expect(session).not.toBe(before);+ expect(session.state.sessionId).toBe(sessionId);});it("reports local dev artifact revision changes for normal prompts", async () => {@@ -161,27 +174,21 @@ describe("createDevelopmentRuntimeArtifactSessionRefresher", () => {revisions: ["snapshot-a", "snapshot-b"],});vi.stubGlobal("fetch", fetchMock);- const refresher = createDevelopmentRuntimeArtifactSessionRefresher({+ const refresher = createDevelopmentRuntimeArtifactRefresher({serverUrl: "http://localhost:3000",});const changes: Array<{ previousRevision: string; revision: string }> = [];- const session = new Client({ host: "http://localhost:3000" }).session();-await refresher.refresh({- createSession: () => session,message: "first",onRuntimeArtifactsChanged: (change) => {changes.push(change);},- session,});await refresher.refresh({- createSession: () => session,message: "second",onRuntimeArtifactsChanged: (change) => {changes.push(change);},- session,});expect(changes).toEqual([@@ -209,25 +216,19 @@ describe("createDevelopmentRuntimeArtifactSessionRefresher", () => {revisions: ["snapshot-a", "snapshot-b"],});vi.stubGlobal("fetch", fetchMock);- const refresher = createDevelopmentRuntimeArtifactSessionRefresher({+ const refresher = createDevelopmentRuntimeArtifactRefresher({serverUrl: "http://localhost:3000",});const changes: Array<{ previousRevision: string; revision: string }> = [];- const session = new Client({ host: "http://localhost:3000" }).session();-await refresher.refreshIdle({- createSession: () => session,onRuntimeArtifactsChanged: (change) => {changes.push(change);},- session,});await refresher.refreshIdle({- createSession: () => session,onRuntimeArtifactsChanged: (change) => {changes.push(change);},- session,});expect(changes).toEqual([@@ -250,9 +251,11 @@ describe("createDevelopmentRuntimeArtifactSessionRefresher", () => {});function createDevFetchMock(input: {+ readonly failedRebuilds?: readonly boolean[];readonly requests: Array<{ method: string; url: string }>;readonly revisions: readonly string[];}) {+ let nextRebuildIndex = 0;let nextRevisionIndex = 0;let nextSessionIndex = 0;@@ -262,6 +265,14 @@ function createDevFetchMock(input: {input.requests.push({ method, url });const pathname = new URL(url).pathname;+ if (pathname === "/eve/v1/dev/runtime-artifacts/rebuild") {+ const rebuildFailed = input.failedRebuilds?.[nextRebuildIndex] === true;+ nextRebuildIndex += 1;+ if (rebuildFailed) {+ return new Response(null, { status: 500 });+ }+ }+if (pathname === "/eve/v1/dev/runtime-artifacts" ||pathname === "/eve/v1/dev/runtime-artifacts/rebuild"@@ -273,10 +284,13 @@ function createDevFetchMock(input: {}if (method === "POST") {- nextSessionIndex += 1;+ const sessionId =+ pathname === "/eve/v1/session"+ ? `session-${String(++nextSessionIndex)}`+ : (pathname.split("/").at(-1) ?? `session-${String(++nextSessionIndex)}`);return Response.json({- continuationToken: `token-${nextSessionIndex}`,- sessionId: `session-${nextSessionIndex}`,+ continuationToken: `token-${sessionId}`,+ sessionId,});}diff --git a/packages/eve/src/services/dev-client.ts b/packages/eve/src/services/dev-client.tsindex 94bc19253..5a4aa35e8 100644--- a/packages/eve/src/services/dev-client.ts+++ b/packages/eve/src/services/dev-client.ts@@ -1,5 +1,4 @@import type { UserContent } from "ai";-import type { ClientSession } from "#client/session.js";import type { InputResponse } from "#runtime/input/types.js";import { isLocalDevelopmentServerUrl } from "#services/dev-client/local-host.js";import {@@ -8,50 +7,43 @@ import {} from "#services/dev-client/runtime-artifacts.js";/**- * Tracks local dev runtime-artifact revisions and starts a fresh session for- * normal prompts after HMR, while preserving the current session for- * input-response resumes.+ * Tracks local dev runtime-artifact revisions so callers can refresh their+ * presentation before delivering the next turn.*/-export interface DevelopmentRuntimeArtifactSessionRefresher {+export interface DevelopmentRuntimeArtifactRefresher {/*** Clears the remembered runtime-artifact revision.*/clear(): void;/**- * Returns the session that should dispatch the next turn.+ * Refreshes the artifact revision before a normal turn.*/refresh(input: {- readonly createSession: () => ClientSession;readonly inputResponses?: readonly InputResponse[];readonly message?: string | UserContent;readonly onRuntimeArtifactsChanged?: (change: DevelopmentRuntimeArtifactChange,) => void | Promise<void>;- readonly session: ClientSession;- }): Promise<ClientSession>;+ }): Promise<void>;/*** Forces one rebuild after a local setup action wrote authored source.*/refreshAfterSourceChange(input: {- readonly createSession: () => ClientSession;readonly onRuntimeArtifactsChanged?: (change: DevelopmentRuntimeArtifactChange,) => void | Promise<void>;- readonly session: ClientSession;- }): Promise<ClientSession>;+ }): Promise<void>;/*** Checks for a runtime-artifact revision change while the UI is idle.*/refreshIdle(input: {- readonly createSession: () => ClientSession;readonly onRuntimeArtifactsChanged?: (change: DevelopmentRuntimeArtifactChange,) => void | Promise<void>;- readonly session: ClientSession;- }): Promise<ClientSession>;+ }): Promise<void>;}export interface DevelopmentRuntimeArtifactChange {@@ -59,7 +51,7 @@ export interface DevelopmentRuntimeArtifactChange {readonly revision: string;}-class LocalDevelopmentRuntimeArtifactSessionRefresher implements DevelopmentRuntimeArtifactSessionRefresher {+class LocalDevelopmentRuntimeArtifactRefresher implements DevelopmentRuntimeArtifactRefresher {readonly #isLocal: boolean;readonly #serverUrl: string;#artifactRevision: string | undefined;@@ -74,58 +66,48 @@ class LocalDevelopmentRuntimeArtifactSessionRefresher implements DevelopmentRunt}async refresh(input: {- readonly createSession: () => ClientSession;readonly inputResponses?: readonly InputResponse[];readonly message?: string | UserContent;readonly onRuntimeArtifactsChanged?: (change: DevelopmentRuntimeArtifactChange,) => void | Promise<void>;- readonly session: ClientSession;- }): Promise<ClientSession> {+ }): Promise<void> {if (!shouldRefreshRuntimeArtifactsForTurn(input)) {- return input.session;+ return;}- return await this.#refreshSession({ ...input, rebuild: true });+ await this.#refreshRuntimeArtifacts({ ...input, rebuild: true });}async refreshIdle(input: {- readonly createSession: () => ClientSession;readonly onRuntimeArtifactsChanged?: (change: DevelopmentRuntimeArtifactChange,) => void | Promise<void>;- readonly session: ClientSession;- }): Promise<ClientSession> {- return await this.#refreshSession({ ...input, rebuild: false });+ }): Promise<void> {+ await this.#refreshRuntimeArtifacts({ ...input, rebuild: false });}async refreshAfterSourceChange(input: {- readonly createSession: () => ClientSession;readonly onRuntimeArtifactsChanged?: (change: DevelopmentRuntimeArtifactChange,) => void | Promise<void>;- readonly session: ClientSession;- }): Promise<ClientSession> {- return await this.#refreshSession({+ }): Promise<void> {+ await this.#refreshRuntimeArtifacts({...input,force: true,rebuild: true,- resetActiveSession: true,});}- async #refreshSession(input: {- readonly createSession: () => ClientSession;+ async #refreshRuntimeArtifacts(input: {readonly onRuntimeArtifactsChanged?: (change: DevelopmentRuntimeArtifactChange,) => void | Promise<void>;readonly force?: boolean;readonly rebuild: boolean;- readonly resetActiveSession?: boolean;- readonly session: ClientSession;- }): Promise<ClientSession> {+ }): Promise<void> {if (!this.#isLocal) {- return input.session;+ return;}const revision =@@ -137,22 +119,15 @@ class LocalDevelopmentRuntimeArtifactSessionRefresher implements DevelopmentRunt: undefined) ??(await readDevelopmentRuntimeArtifactsRevision({ serverUrl: this.#serverUrl }));if (revision === undefined) {- return input.session;+ return;}- let session = input.session;const previousRevision = this.#artifactRevision;const revisionChanged = previousRevision !== undefined && previousRevision !== revision;- if (revisionChanged || input.resetActiveSession === true) {- if (session.state.continuationToken !== undefined) {- session = input.createSession();- }- }if (revisionChanged) {await input.onRuntimeArtifactsChanged?.({ previousRevision, revision });}this.#artifactRevision = revision;- return session;}}@@ -164,10 +139,10 @@ function shouldRefreshRuntimeArtifactsForTurn(input: {}/**- * Creates a revision-aware local dev session refresher.+ * Creates a revision-aware local dev runtime-artifact refresher.*/-export function createDevelopmentRuntimeArtifactSessionRefresher(input: {+export function createDevelopmentRuntimeArtifactRefresher(input: {readonly serverUrl: string;-}): DevelopmentRuntimeArtifactSessionRefresher {- return new LocalDevelopmentRuntimeArtifactSessionRefresher(input);+}): DevelopmentRuntimeArtifactRefresher {+ return new LocalDevelopmentRuntimeArtifactRefresher(input);}diff --git a/packages/eve/src/services/dev-client/runtime-artifacts.ts b/packages/eve/src/services/dev-client/runtime-artifacts.tsindex 88e453263..53c3c2e5e 100644--- a/packages/eve/src/services/dev-client/runtime-artifacts.ts+++ b/packages/eve/src/services/dev-client/runtime-artifacts.ts@@ -6,8 +6,8 @@ import {/*** Reads the dev server's runtime-artifacts revision — an opaque token that* changes whenever the authored-source watcher recompiles (HMR). Consumers- * compare successive values to detect "the agent changed under me": the dev- * client rotates an active session before the next turn or while idle.+ * compare successive values to detect "the agent changed under me" and+ * refresh the development UI before the next turn.** Never throws: any transport failure, non-2xx response, or malformed body* resolves to `undefined`, so callers treat "unknown" and "unreachable" thediff --git a/packages/eve/test/scenarios/dev-server.scenario.test.ts b/packages/eve/test/scenarios/dev-server.scenario.test.tsindex 5961074a7..47251fe32 100644--- a/packages/eve/test/scenarios/dev-server.scenario.test.ts+++ b/packages/eve/test/scenarios/dev-server.scenario.test.ts@@ -746,6 +746,42 @@ describe("eve dev server", () => {DEV_SERVER_SCENARIO_TIMEOUT_MS,);+ it(+ "makes a newly added tool available to the next turn in a continued session",+ async () => {+ const app = await scenarioApp(WORKFLOW_GENERATION_DESCRIPTOR);+ const server = await startEveDev(app.appRoot);++ try {+ const firstResult = await sendDevelopmentMessage({+ message: "Hello.",+ session: createDevelopmentSessionState(),+ serverUrl: server.url,+ });+ const firstSessionId = firstResult.session.sessionId;+ expect(firstSessionId).toBeDefined();++ await writeFile(+ join(app.appRoot, "agent", "tools", "get_added_marker.ts"),+ createGenerationMarkerToolSource("added-tool", false),+ );+ await forceDevelopmentRebuild(server.url);++ const secondResult = await sendDevelopmentMessage({+ message: "Use get_added_marker.",+ session: firstResult.session,+ serverUrl: server.url,+ });++ expect(secondResult.sessionId).toBe(firstSessionId);+ expect(readCompletedMessages(secondResult.events)).toContain("added-tool");+ } finally {+ await server.stop();+ }+ },+ DEV_SERVER_SCENARIO_TIMEOUT_MS,+ );+it("recovers a nonterminal child Workflow on its selected generation after restart",async () => {