perf(agents): lazy-load delivery runtime

This commit is contained in:
Vincent Koc
2026-04-13 21:05:30 +01:00
parent f126088761
commit dd27aa945e
3 changed files with 11 additions and 2 deletions

View File

@@ -30,7 +30,7 @@ vi.mock("./command/attempt-execution.runtime.js", () => ({
sessionFileHasContent: vi.fn(async () => false),
}));
vi.mock("./command/delivery.js", () => ({
vi.mock("./command/delivery.runtime.js", () => ({
deliverAgentCommandResult: (...args: unknown[]) => state.deliverAgentCommandResultMock(...args),
}));

View File

@@ -50,7 +50,6 @@ import {
persistSessionEntry as persistSessionEntryBase,
prependInternalEventContext,
} from "./command/attempt-execution.shared.js";
import { deliverAgentCommandResult } from "./command/delivery.js";
import { resolveAgentRunContext } from "./command/run-context.js";
import { updateSessionStoreAfterAgentRun } from "./command/session-store.js";
import { resolveSession } from "./command/session.js";
@@ -79,9 +78,11 @@ import { ensureAgentWorkspace } from "./workspace.js";
const log = createSubsystemLogger("agents/agent-command");
type AttemptExecutionRuntime = typeof import("./command/attempt-execution.runtime.js");
type DeliveryRuntime = typeof import("./command/delivery.runtime.js");
type TranscriptResolveRuntime = typeof import("../config/sessions/transcript-resolve.runtime.js");
let attemptExecutionRuntimePromise: Promise<AttemptExecutionRuntime> | undefined;
let deliveryRuntimePromise: Promise<DeliveryRuntime> | undefined;
let transcriptResolveRuntimePromise: Promise<TranscriptResolveRuntime> | undefined;
function loadAttemptExecutionRuntime(): Promise<AttemptExecutionRuntime> {
@@ -89,6 +90,11 @@ function loadAttemptExecutionRuntime(): Promise<AttemptExecutionRuntime> {
return attemptExecutionRuntimePromise;
}
function loadDeliveryRuntime(): Promise<DeliveryRuntime> {
deliveryRuntimePromise ??= import("./command/delivery.runtime.js");
return deliveryRuntimePromise;
}
function loadTranscriptResolveRuntime(): Promise<TranscriptResolveRuntime> {
transcriptResolveRuntimePromise ??= import("../config/sessions/transcript-resolve.runtime.js");
return transcriptResolveRuntimePromise;
@@ -557,6 +563,7 @@ async function agentCommandInternal(
abortSignal: opts.abortSignal,
});
const payloads = result.payloads;
const { deliverAgentCommandResult } = await loadDeliveryRuntime();
return await deliverAgentCommandResult({
cfg,
@@ -1031,6 +1038,7 @@ async function agentCommandInternal(
}
const payloads = result.payloads ?? [];
const { deliverAgentCommandResult } = await loadDeliveryRuntime();
return await deliverAgentCommandResult({
cfg,
deps,

View File

@@ -0,0 +1 @@
export { deliverAgentCommandResult } from "./delivery.js";