diff --git a/apps/x/packages/core/src/agents/registry.ts b/apps/x/packages/core/src/agents/registry.ts index 9508ea7f..f09a5034 100644 --- a/apps/x/packages/core/src/agents/registry.ts +++ b/apps/x/packages/core/src/agents/registry.ts @@ -10,6 +10,7 @@ import { getRaw as getLabelingAgentRaw } from "../knowledge/labeling_agent.js"; import { getRaw as getNoteTaggingAgentRaw } from "../knowledge/note_tagging_agent.js"; import { getRaw as getInlineTaskAgentRaw } from "../knowledge/inline_task_agent.js"; import { getRaw as getAgentNotesAgentRaw } from "../knowledge/agent_notes_agent.js"; +import { lazyResolve } from "../di/lazy-resolve.js"; import type { IAgentsRepo } from "./repo.js"; // The registry of built-in agents: one table instead of the historical @@ -89,9 +90,7 @@ export async function loadAgent(id: string): Promise> { if (builtin) { return builtin.build(); } - // User-defined agents. The container is imported lazily so this module - // adds no static edge into the DI graph (mirrors spawn-agent). - const { default: container } = await import("../di/container.js"); - const repo = container.resolve("agentsRepo"); + // User-defined agents (lazyResolve: no static DI edge from this module). + const repo = await lazyResolve("agentsRepo"); return repo.fetch(id); } diff --git a/apps/x/packages/core/src/agents/spawn-agent.ts b/apps/x/packages/core/src/agents/spawn-agent.ts index 432edaab..72cbf26c 100644 --- a/apps/x/packages/core/src/agents/spawn-agent.ts +++ b/apps/x/packages/core/src/agents/spawn-agent.ts @@ -219,13 +219,13 @@ export async function runSpawnedAgent( async function resolveServices(): Promise< NonNullable > { - const { default: container } = await import("../di/container.js"); + const { lazyResolve } = await import("../di/lazy-resolve.js"); return { turnRuntime: - container.resolve( + await lazyResolve( "turnRuntime", ), - headlessRunner: container.resolve< + headlessRunner: await lazyResolve< import("./headless.js").IHeadlessAgentRunner >("headlessAgentRunner"), }; diff --git a/apps/x/packages/core/src/application/notification/notifier.ts b/apps/x/packages/core/src/application/notification/notifier.ts index a1cacc76..050279d3 100644 --- a/apps/x/packages/core/src/application/notification/notifier.ts +++ b/apps/x/packages/core/src/application/notification/notifier.ts @@ -19,8 +19,8 @@ export async function notifyIfEnabled( ): Promise { try { if (!isNotificationCategoryEnabled(category)) return; - const { default: container } = await import('../../di/container.js'); - const service = container.resolve('notificationService'); + const { lazyResolve } = await import('../../di/lazy-resolve.js'); + const service = await lazyResolve('notificationService'); if (!service.isSupported()) return; service.notify(input); } catch (err) { diff --git a/apps/x/packages/core/src/background-tasks/runner.ts b/apps/x/packages/core/src/background-tasks/runner.ts index 810b9aac..1463d27b 100644 --- a/apps/x/packages/core/src/background-tasks/runner.ts +++ b/apps/x/packages/core/src/background-tasks/runner.ts @@ -128,8 +128,8 @@ export async function runBackgroundTask( let codeProject: { id: string; path: string; name: string } | undefined; if (task.projectId) { try { - const { default: container } = await import('../di/container.js'); - const projectsRepo = container.resolve('codeProjectsRepo'); + const { lazyResolve } = await import('../di/lazy-resolve.js'); + const projectsRepo = await lazyResolve('codeProjectsRepo'); const project = await projectsRepo.get(task.projectId); if (project) codeProject = { id: project.id, path: project.path, name: project.name }; } catch (err) {