Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

feat(extensions): support built-in extension mounts (#2938)

prha9d0df261fa17
diff --git a/.changeset/built-in-extension-mounts.md b/.changeset/built-in-extension-mounts.md
new file mode 100644
index 000000000..fca2779b8
--- /dev/null
+++ b/.changeset/built-in-extension-mounts.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Extension packages can expose built-in extension distributions from package export subpaths.
diff --git a/packages/eve/src/discover/extensions.test.ts b/packages/eve/src/discover/extensions.test.ts
index 03936a04f..81da8fc52 100644
--- a/packages/eve/src/discover/extensions.test.ts
+++ b/packages/eve/src/discover/extensions.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import {
+ locateExtensionMount,
locateExtensionMountPackage,
mountNamespace,
packageStateNamespace,
@@ -34,6 +35,42 @@ describe("packageStateNamespace", () => {
});
describe("locateExtensionMountPackage", () => {
+ it("resolves a package-local built-in extension without a compatibility manifest", async () => {
+ const appRoot = "/repo/apps/agent";
+ const agentRoot = `${appRoot}/agent`;
+ const packageRoot = `${appRoot}/node_modules/eve`;
+ const source = createMemoryProjectSource({
+ files: {
+ [`${agentRoot}/extensions/selfmod.ts`]:
+ 'export { default } from "eve/self-modification";\n',
+ [`${packageRoot}/package.json`]: JSON.stringify({
+ name: "eve",
+ eve: {
+ builtInExtensions: {
+ "./self-modification": { dist: "dist/src/self-modification/extension" },
+ },
+ },
+ }),
+ },
+ });
+
+ const result = await locateExtensionMount({
+ source,
+ agentRoot,
+ appRoot,
+ mount: createModuleSourceRef({ logicalPath: "extensions/selfmod.ts" }),
+ namespace: "selfmod",
+ });
+
+ expect(result.diagnostics).toEqual([]);
+ expect(result.location).toMatchObject({
+ packageName: "eve",
+ packageRoot,
+ sourceRoot: `${packageRoot}/dist/src/self-modification/extension`,
+ specifier: "eve/self-modification",
+ });
+ });
+
it("resolves source and dist roots before the distribution exists", async () => {
const appRoot = "/repo/apps/agent";
const agentRoot = `${appRoot}/agent`;
diff --git a/packages/eve/src/discover/extensions.ts b/packages/eve/src/discover/extensions.ts
index 912cfe711..5c1f90a76 100644
--- a/packages/eve/src/discover/extensions.ts
+++ b/packages/eve/src/discover/extensions.ts
@@ -10,7 +10,10 @@ import { parseExtensionMountSpecifier } from "#discover/extension-specifier.js";
import { SUPPORTED_AUTHORED_MODULE_FILE_EXTENSIONS } from "#discover/filesystem.js";
import type { ExtensionSourceRef } from "#discover/manifest.js";
import type { ProjectSource } from "#discover/project-source.js";
-import { parseExtensionPackageRoots } from "#shared/extension-package-contract.js";
+import {
+ parseBuiltInExtensionPackageRoots,
+ parseExtensionPackageRoots,
+} from "#shared/extension-package-contract.js";
/**
* Emitted when a mount file cannot be resolved to an extension package.
@@ -113,6 +116,8 @@ export interface ExtensionMountPackageLocation {
readonly authoredSourceRoot?: string;
/** Absolute path to the agent-shaped distribution root. */
readonly distRoot: string;
+ /** The distribution is shipped by the resolved eve package itself. */
+ readonly builtIn: boolean;
}
/**
@@ -180,6 +185,20 @@ export async function locateExtensionMount(input: {
}
const { location } = locatedPackage;
+ if (location.builtIn) {
+ return {
+ location: {
+ namespace: location.namespace,
+ specifier: location.specifier,
+ packageName: location.packageName,
+ packageRoot: location.packageRoot,
+ sourceRoot: location.distRoot,
+ externalDependencies: [],
+ },
+ diagnostics: [],
+ };
+ }
+
const compatibilityPath = join(location.distRoot, EXTENSION_COMPATIBILITY_MANIFEST_FILENAME);
let compatibility;
try {
@@ -291,7 +310,7 @@ export async function locateExtensionMountPackage(input: {
}
const manifestPath = join(packageRoot, "package.json");
- let pkg: { name?: unknown; eve?: { extension?: unknown } };
+ let pkg: { name?: unknown; eve?: { extension?: unknown; builtInExtensions?: unknown } };
try {
pkg = JSON.parse(await input.source.readTextFile(manifestPath)) as typeof pkg;
} catch {
@@ -306,7 +325,11 @@ export async function locateExtensionMountPackage(input: {
};
}
- const extension = parseExtensionPackageRoots(pkg.eve?.extension);
+ const builtInExtension = parseBuiltInExtensionPackageRoots(
+ pkg.eve?.builtInExtensions,
+ packageSpecifierSubpath(specifier),
+ );
+ const extension = builtInExtension ?? parseExtensionPackageRoots(pkg.eve?.extension);
if (extension === null) {
return {
diagnostics: [
@@ -330,6 +353,7 @@ export async function locateExtensionMountPackage(input: {
...(extension.source === undefined
? {}
: { authoredSourceRoot: resolve(packageRoot, extension.source) }),
+ builtIn: builtInExtension !== null,
distRoot: resolve(packageRoot, extension.dist),
},
diagnostics: [],
@@ -372,6 +396,12 @@ async function resolvePackageRoot(input: {
}
}
+/** Returns the export subpath of a bare package specifier. */
+function packageSpecifierSubpath(specifier: string): string {
+ const subpath = specifier.slice(bareSpecifierPackagePath(specifier).length);
+ return subpath.length === 0 ? "." : `.${subpath}`;
+}
+
/**
* Returns the package portion of a bare specifier, dropping any deep subpath.
* `@acme/crm/mount` → `@acme/crm`; `gizmo/mount` → `gizmo`.
diff --git a/packages/eve/src/shared/extension-package-contract.ts b/packages/eve/src/shared/extension-package-contract.ts
index a26bcd07e..547c6bc97 100644
--- a/packages/eve/src/shared/extension-package-contract.ts
+++ b/packages/eve/src/shared/extension-package-contract.ts
@@ -29,6 +29,15 @@ export function parseExtensionPackageRoots(value: unknown): ExtensionPackageRoot
: null;
}
+/** Parses package-local extension distributions keyed by their export subpath. */
+export function parseBuiltInExtensionPackageRoots(
+ value: unknown,
+ subpath: string,
+): ExtensionPackageRoots | null {
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
+ return parseExtensionPackageRoots((value as Record<string, unknown>)[subpath]);
+}
+
function parseExternalDependencies(value: unknown): readonly string[] | undefined | null {
if (value === undefined) return undefined;
if (!Array.isArray(value)) return null;