Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): portable extension subagent resource paths and follow-up cleanup (#3849)

Andrew Barba01cb6b47bbd1
diff --git a/.changeset/windows-extension-subagent-resources.md b/.changeset/windows-extension-subagent-resources.md
new file mode 100644
index 000000000..d35099311
--- /dev/null
+++ b/.changeset/windows-extension-subagent-resources.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Fix compiling agents on Windows when a mounted extension contributes a subagent. Each subagent's workspace resources now live in one URL-encoded directory under `.eve/compile/workspace-resources/`, so ids that contain `:` no longer produce invalid Windows paths.
diff --git a/.oxfmtrc.json b/.oxfmtrc.json
index a07e5e4a3..cc447abb6 100644
--- a/.oxfmtrc.json
+++ b/.oxfmtrc.json
@@ -1,4 +1,8 @@
{
"$schema": "./node_modules/oxfmt/configuration_schema.json",
- "ignorePatterns": ["packages/eve/CHANGELOG.md"]
+ "ignorePatterns": [
+ "packages/eve/CHANGELOG.md",
+ "apps/docs/registry.json",
+ "packages/eve/src/setup/scaffold/create/web-template.ts"
+ ]
}
diff --git a/packages/eve/src/compiler/mounted-extension.integration.test.ts b/packages/eve/src/compiler/mounted-extension.integration.test.ts
index 400389d5c..bc79a6d3a 100644
--- a/packages/eve/src/compiler/mounted-extension.integration.test.ts
+++ b/packages/eve/src/compiler/mounted-extension.integration.test.ts
@@ -1,3 +1,6 @@
+import { stat } from "node:fs/promises";
+import { join } from "node:path";
+
import { describe, expect, it } from "vitest";
import { compileAgent } from "#compiler/compile-agent.js";
@@ -356,3 +359,51 @@ describe("mounted extension via directory form with override", () => {
]);
});
});
+
+describe("mounted extension subagent resources", () => {
+ it("materializes extension subagent resources under a Windows-safe directory", async () => {
+ const app = await createAppRoot("eve-mounted-extension-subagent-resources-", {
+ files: {
+ "agent/agent.mjs": 'export default { model: "openai/gpt-5.4" };\n',
+ "agent/instructions.md": "You are a precise assistant.\n",
+ "agent/extensions/crm.mjs": 'export { default } from "@acme/crm";\n',
+ "node_modules/@acme/crm/package.json": `${JSON.stringify({
+ name: "@acme/crm",
+ type: "module",
+ eve: { extension: { source: "source", dist: "extension" } },
+ exports: { ".": "./extension/extension.mjs" },
+ })}\n`,
+ "node_modules/@acme/crm/extension/_manifest.json": compatibilityManifest({
+ extension: 1,
+ subagent: 6,
+ }),
+ "node_modules/@acme/crm/extension/extension.mjs": [
+ 'import { defineExtension } from "eve/extension";',
+ "export default defineExtension();",
+ "",
+ ].join("\n"),
+ "node_modules/@acme/crm/extension/subagents/reviewer/agent.mjs": [
+ "export default {",
+ ' model: "openai/gpt-5.4",',
+ ' description: "Review CRM notes.",',
+ "};",
+ "",
+ ].join("\n"),
+ },
+ });
+
+ const { paths } = await compileAgent({ startPath: app.appRoot });
+ const manifest = await loadCompiledManifest({
+ compiledArtifactsSource: createDiskRuntimeCompiledArtifactsSource(app.appRoot),
+ });
+
+ const [subagent] = manifest.subagents;
+ expect(subagent?.nodeId).toContain(":");
+ const logicalPath = subagent?.agent.workspaceResourceRoot.logicalPath ?? "";
+ const [resourcesDirectory, nodeDirectory, ...nested] = logicalPath.split("/");
+ expect(resourcesDirectory).toBe("workspace-resources");
+ expect(nested).toEqual([]);
+ expect(nodeDirectory).toMatch(/^[^<>:"/\\|?*]+$/);
+ await expect(stat(join(paths.compileDirectoryPath, logicalPath))).resolves.toMatchObject({});
+ });
+});
diff --git a/packages/eve/src/compiler/workspace-resources.ts b/packages/eve/src/compiler/workspace-resources.ts
index 83ed04f1c..678de2666 100644
--- a/packages/eve/src/compiler/workspace-resources.ts
+++ b/packages/eve/src/compiler/workspace-resources.ts
@@ -70,6 +70,13 @@ export async function materializeWorkspaceResources(input: {
};
}
+// Node ids contain `:` and `/` (e.g. `manager::ext:crm:subagents/reviewer`).
+// Encoding keeps each node in one reversible, collision-free path segment
+// that Windows accepts.
+function resourceDirectoryName(nodeId: string): string {
+ return encodeURIComponent(nodeId);
+}
+
function createResourceRoot(
manifest: CompiledAgentResources,
nodeId: string,
@@ -77,7 +84,7 @@ function createResourceRoot(
): CompiledWorkspaceResourceRoot {
return {
contentHash,
- logicalPath: normalizeLogicalPath(join(RESOURCES_DIRECTORY, nodeId)),
+ logicalPath: normalizeLogicalPath(join(RESOURCES_DIRECTORY, resourceDirectoryName(nodeId))),
rootEntries: deriveResourceRootEntries({
sandboxWorkspaces: manifest.sandboxWorkspaces,
skills: manifest.skills,
@@ -90,7 +97,7 @@ async function materializeNode<TManifest extends CompiledAgentResources>(input:
readonly nodeId: string;
readonly resourcesRoot: string;
}): Promise<TManifest> {
- const nodeRoot = join(input.resourcesRoot, input.nodeId);
+ const nodeRoot = join(input.resourcesRoot, resourceDirectoryName(input.nodeId));
await mkdir(nodeRoot, { recursive: true });
const workspaceRoot = join(nodeRoot, RESOURCE_WORKSPACE_DIRECTORY);
diff --git a/packages/eve/src/internal/authored-module-loader.integration.test.ts b/packages/eve/src/internal/authored-module-loader.integration.test.ts
index dfd11883d..ace37547a 100644
--- a/packages/eve/src/internal/authored-module-loader.integration.test.ts
+++ b/packages/eve/src/internal/authored-module-loader.integration.test.ts
@@ -1,4 +1,4 @@
-import { mkdir, mkdtemp, realpath, rm, symlink, writeFile } from "node:fs/promises";
+import { mkdir, mkdtemp, rm, symlink, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { basename, join } from "node:path";
@@ -223,51 +223,6 @@ export default defineWorkflowTool({ description: "Probe", inputSchema: { type: "
expect(code).toContain("eve:durable-dynamic-callback");
});
- it("preserves cached channel identity for relative channel imports", async () => {
- const app = await createApp({
- files: {
- "agent/channels/support.ts": [
- 'export default { marker: "source-channel-instance" };',
- "",
- ].join("\n"),
- "agent/tools/use_support_channel.ts": [
- 'import supportChannel from "../channels/support";',
- "",
- "export const result = supportChannel.marker;",
- "",
- ].join("\n"),
- },
- name: "cached-relative-channel-import",
- });
- const cache = new Map<string, unknown>();
- const cacheKey = "__eveChannelModuleCache__";
- const globals = globalThis as Record<string, unknown>;
- const previousCache = globals[cacheKey];
-
- try {
- // Native realpath resolves symlinks (macOS /var) and Windows 8.3 short
- // names (RUNNER~1); loading from the same canonical root keeps the
- // bundler's resolved channel path equal to the cache key.
- const appRoot = await realpath(app.appRoot);
- cache.set(join(appRoot, "agent", "channels", "support.ts"), {
- marker: "cached-channel-instance",
- });
- globals[cacheKey] = cache;
-
- const moduleNamespace = await loadAuthoredModuleNamespace(
- join(appRoot, "agent", "tools", "use_support_channel.ts"),
- );
-
- expect(moduleNamespace.result).toBe("cached-channel-instance");
- } finally {
- if (previousCache === undefined) {
- delete globals[cacheKey];
- } else {
- globals[cacheKey] = previousCache;
- }
- }
- });
-
it("explains when an installed package contains Node-incompatible extensionless ESM", async () => {
const app = await createApp({
files: {
diff --git a/packages/eve/src/internal/authored-module-loader.ts b/packages/eve/src/internal/authored-module-loader.ts
index 28d40dc24..09394fc70 100644
--- a/packages/eve/src/internal/authored-module-loader.ts
+++ b/packages/eve/src/internal/authored-module-loader.ts
@@ -15,14 +15,12 @@ import {
createFixedNamespaceScopePlugin,
} from "#internal/bundler/extension-scope-plugin.js";
import {
- CACHED_CHANNEL_PREFIX,
RESOLVE_EXTENSIONS,
createDistributionPackageBoundaryPlugin,
createGenerationPackageBoundaryPlugin,
createRuntimeLoaderPackageBoundaryPlugin,
isNodeModulesPath,
normalizeExternalDependencies,
- type RolldownResolveContext,
} from "#internal/authored-package-boundary.js";
import { expectObjectRecord } from "#internal/authored-module.js";
import { normalizeEsmImportSpecifier } from "#internal/application/import-specifier.js";
@@ -48,7 +46,6 @@ const AUTHORED_MODULE_BUNDLE_DIRECTORY_PATH = join(
"eve",
"authored-modules",
);
-const CHANNEL_MODULE_CACHE_KEY = "__eveChannelModuleCache__";
export interface AuthoredModuleLoadOptions {
readonly externalDependencies?: readonly string[];
@@ -60,12 +57,6 @@ export interface AuthoredModuleLoadOptions {
readonly extensionScopeNamespace?: string;
}
-function getChannelModuleCache(): Map<string, unknown> | undefined {
- return (globalThis as Record<string, unknown>)[CHANNEL_MODULE_CACHE_KEY] as
- | Map<string, unknown>
- | undefined;
-}
-
/**
* In-flight load deduplication map keyed by the absolute module path.
*
@@ -157,7 +148,6 @@ export async function bundleAuthoredModuleCode(
): Promise<string> {
const packageRoot = resolveAuthoredPackageRoot(modulePath);
return await buildAuthoredModuleBundle(modulePath, options, {
- channelIdentity: true,
packageBoundaryPlugin: createRuntimeLoaderPackageBoundaryPlugin({
externalDependencies: normalizeExternalDependencies(options.externalDependencies),
packageRoot,
@@ -178,10 +168,6 @@ export async function bundleAuthoredModuleForGeneration(
options: AuthoredModuleLoadOptions = {},
): Promise<string> {
const code = await buildAuthoredModuleBundle(modulePath, options, {
- // Generation bundles must not reference process state: the channel
- // identity plugin emits reads of a process-global cache keyed by live
- // source paths, which an immutable retained artifact cannot depend on.
- channelIdentity: false,
packageBoundaryPlugin: createGenerationPackageBoundaryPlugin({
externalDependencies: normalizeExternalDependencies(options.externalDependencies),
packageRoot: resolveAuthoredPackageRoot(modulePath),
@@ -480,64 +466,14 @@ async function buildAuthoredModuleBundle(
modulePath: string,
options: AuthoredModuleLoadOptions,
configuration: {
- readonly channelIdentity: boolean;
readonly packageBoundaryPlugin: Record<string, unknown>;
readonly plugins: readonly Record<string, unknown>[];
readonly sourcemap: false | "inline";
},
): Promise<string> {
- const channelCache = configuration.channelIdentity ? getChannelModuleCache() : undefined;
const packageRoot = resolveAuthoredPackageRoot(modulePath);
const tsconfigPath = resolveAuthoredTsConfigPath(packageRoot);
- const channelIdentityPlugin =
- channelCache && channelCache.size > 0
- ? {
- name: "eve-channel-identity",
- async resolveId(
- this: RolldownResolveContext,
- source: string,
- importer: string | undefined,
- options: { kind: string },
- ) {
- if (!/channels[/\\]/.test(source) || options.kind !== "import-statement") {
- return undefined;
- }
-
- const resolved = await this.resolve(source, importer, {
- kind: options.kind,
- skipSelf: true,
- });
-
- if (resolved === null || typeof resolved.id !== "string") {
- return undefined;
- }
-
- const resolvedPath = resolve(resolved.id);
-
- if (!channelCache.has(resolvedPath)) {
- return undefined;
- }
-
- return { id: `${CACHED_CHANNEL_PREFIX}${resolvedPath}` };
- },
- load(id: string) {
- if (!id.startsWith(CACHED_CHANNEL_PREFIX)) {
- return undefined;
- }
-
- const cachedPath = id.slice(CACHED_CHANNEL_PREFIX.length);
- return {
- code: [
- `const cache = globalThis["${CHANNEL_MODULE_CACHE_KEY}"];`,
- `export default cache.get(${JSON.stringify(cachedPath)});`,
- ].join("\n"),
- moduleType: "js" as const,
- };
- },
- }
- : null;
const plugins = [
- channelIdentityPlugin,
...configuration.plugins,
options.extensionScopeNamespace === undefined
? null
diff --git a/packages/eve/src/internal/authored-package-boundary.ts b/packages/eve/src/internal/authored-package-boundary.ts
index 09e4408cc..daf1afe0d 100644
--- a/packages/eve/src/internal/authored-package-boundary.ts
+++ b/packages/eve/src/internal/authored-package-boundary.ts
@@ -8,8 +8,6 @@ import {
resolveWorkflowModulePath,
} from "#internal/application/package.js";
-export const CACHED_CHANNEL_PREFIX = "eve-cached-channel:";
-
export const RESOLVE_EXTENSIONS = [
".ts",
".tsx",
@@ -138,11 +136,7 @@ export function createRuntimeLoaderPackageBoundaryPlugin(input: {
}
const importerPath =
- importer === undefined ||
- importer.startsWith("\0") ||
- importer.startsWith(CACHED_CHANNEL_PREFIX)
- ? undefined
- : resolve(importer);
+ importer === undefined || importer.startsWith("\0") ? undefined : resolve(importer);
// Keep package imports authored directly by the app external by
// default, but let symlinked/file workspace packages compile as
@@ -385,11 +379,7 @@ function isPackageImport(source: string): boolean {
return false;
}
- if (source.startsWith("@/")) {
- return false;
- }
-
- return !source.startsWith(CACHED_CHANNEL_PREFIX);
+ return !source.startsWith("@/");
}
export function isPathImport(source: string): boolean {
diff --git a/packages/eve/src/internal/authored-relative-extension-resolver.ts b/packages/eve/src/internal/authored-relative-extension-resolver.ts
index 9930ae59d..ec1384bf9 100644
--- a/packages/eve/src/internal/authored-relative-extension-resolver.ts
+++ b/packages/eve/src/internal/authored-relative-extension-resolver.ts
@@ -1,11 +1,7 @@
import { realpathSync, statSync } from "node:fs";
import { dirname, isAbsolute, join, resolve } from "node:path";
-import {
- CACHED_CHANNEL_PREFIX,
- isNodeModulesPath,
- isPathImport,
-} from "#internal/authored-package-boundary.js";
+import { isNodeModulesPath, isPathImport } from "#internal/authored-package-boundary.js";
const PATH_IMPORT_FILTER = /^(?:\.|\/|[A-Za-z]:[\\/])/;
@@ -24,12 +20,7 @@ export function createAuthoredRelativeExtensionResolverPlugin(input: {
id: PATH_IMPORT_FILTER,
},
handler(source: string, importer: string | undefined) {
- if (
- importer === undefined ||
- importer.startsWith("\0") ||
- importer.startsWith(CACHED_CHANNEL_PREFIX) ||
- !isPathImport(source)
- ) {
+ if (importer === undefined || importer.startsWith("\0") || !isPathImport(source)) {
return undefined;
}