Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

feat(eve): add local self-modification (#1632)

prha9a7964bbdd3b
diff --git a/.changeset/self-modification-source-editing-kit.md b/.changeset/self-modification-source-editing-kit.md
new file mode 100644
index 000000000..f3197eeae
--- /dev/null
+++ b/.changeset/self-modification-source-editing-kit.md
@@ -0,0 +1,6 @@
+---
+"eve": patch
+"@eve/self-modification": patch
+---
+
+Add a configurable, development-only `@eve/self-modification` source-editing subagent that mounts authored agent source read-write, exposes its instructions through an extension, and uses structured file tools to inspect and safely update source.
diff --git a/apps/docs/next-env.d.ts b/apps/docs/next-env.d.ts
index ce4e94a6b..a419cbe4e 100644
--- a/apps/docs/next-env.d.ts
+++ b/apps/docs/next-env.d.ts
@@ -1,7 +1,7 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
-import "./.next/types/routes.d.ts";
-import "./.next/types/root-params.d.ts";
+import "./.next/dev/types/routes.d.ts";
+import "./.next/dev/types/root-params.d.ts";
// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
diff --git a/apps/docs/package.json b/apps/docs/package.json
index 1b7cb1d48..3a17387bd 100644
--- a/apps/docs/package.json
+++ b/apps/docs/package.json
@@ -57,6 +57,7 @@
"@chat-adapter/state-memory": "4.34.0",
"@chat-adapter/whatsapp": "4.34.0",
"@chat-adapter/x": "4.34.0",
+ "@eve/self-modification": "workspace:*",
"@getdial/chat-sdk-adapter": "0.2.0",
"@github-tools/eve-extension": "^0.1.0",
"@jetty/eve": "^0.3.0",
diff --git a/packages/eve-self-modification/.gitignore b/packages/eve-self-modification/.gitignore
new file mode 100644
index 000000000..828bc4f17
--- /dev/null
+++ b/packages/eve-self-modification/.gitignore
@@ -0,0 +1,3 @@
+dist
+scaffold
+*.tsbuildinfo
diff --git a/packages/eve-self-modification/README.md b/packages/eve-self-modification/README.md
new file mode 100644
index 000000000..48c0a7447
--- /dev/null
+++ b/packages/eve-self-modification/README.md
@@ -0,0 +1,36 @@
+# @eve/self-modification
+
+A development-only source editing subagent for [eve](https://eve.dev).
+
+Install the package and scaffold a declared subagent from the eve registry:
+
+```sh
+eve add experimental/self-modification
+```
+
+The command creates independent filesystem entrypoints for the subagent, sandbox, and extension:
+
+```text
+agent/subagents/self-modification/
+├── agent.ts
+├── sandbox.ts
+└── extensions/
+ └── selfmod.ts
+```
+
+```ts
+// agent/subagents/self-modification/agent.ts
+import { defineSelfModificationAgent } from "@eve/self-modification/agent";
+
+export default defineSelfModificationAgent({
+ model: "anthropic/claude-sonnet-5",
+});
+
+// agent/subagents/self-modification/sandbox.ts
+export { default } from "@eve/self-modification/sandbox";
+
+// agent/subagents/self-modification/extensions/selfmod.ts
+export { default } from "@eve/self-modification";
+```
+
+Set `model` in the agent definition to choose the self-modification subagent's model; it defaults to `anthropic/claude-sonnet-5`. The sandbox mounts the application's authored `agent/` directory read-write at `/source` and the installed eve package's version-matched documentation read-only at `/eve-docs`. The extension contributes the official eve authoring skill, adapted to use that documentation mount, and `selfmod__edit_file` for one or more exact targeted edits to an existing file without rewriting it. Its instructions direct independent discovery calls to run concurrently and reserve `write_file` for new files or complete rewrites.
diff --git a/packages/eve-self-modification/extension/extension.ts b/packages/eve-self-modification/extension/extension.ts
new file mode 100644
index 000000000..eb45471fd
--- /dev/null
+++ b/packages/eve-self-modification/extension/extension.ts
@@ -0,0 +1,3 @@
+import { defineExtension } from "eve/extension";
+
+export default defineExtension();
diff --git a/packages/eve-self-modification/extension/instructions.ts b/packages/eve-self-modification/extension/instructions.ts
new file mode 100644
index 000000000..4fd45abe8
--- /dev/null
+++ b/packages/eve-self-modification/extension/instructions.ts
@@ -0,0 +1,17 @@
+import { defineInstructions } from "eve/instructions";
+
+export default defineInstructions({
+ markdown: `You are an expert coding assistant operating inside of an eve agent. You help users by reading files, editing code, and writing new files that shape the behavior of the agent itself.
+
+The source code of the eve agent is mounted read-write at /source. Use bash only for read-only discovery and available validation commands. Never modify source files with bash, sed, awk, redirection, or scripting. /source is the authored agent directory.
+
+Use selfmod__edit_file for precise changes to existing files; every edits[].oldText must match exactly. When changing multiple separate locations in one file, use one call with multiple entries in edits[]. Each oldText is matched against the original file, not after earlier edits are applied. Do not emit overlapping or nested edits; merge nearby changes into one edit. Keep oldText as small as possible while still being unique. Use write_file only for new files or complete rewrites.
+
+Group independent calls, including bash and reads, in one response.
+
+The eve framework documentation is mounted read-only at /eve-docs. Read the eve guide directly relevant to an unfamiliar public API. Prefer an existing local implementation pattern over broad documentation research.
+
+You cannot access application files outside the authored agent directory or run host binaries such as git, node, pnpm, or tsc.
+
+Treat a successful file-edit tool result as confirmation; do not reread a file solely to verify that the edit succeeded. Do not approximate unavailable build or test commands with broad source searches.`,
+});
diff --git a/packages/eve-self-modification/extension/tools/edit_file.ts b/packages/eve-self-modification/extension/tools/edit_file.ts
new file mode 100644
index 000000000..f0636991a
--- /dev/null
+++ b/packages/eve-self-modification/extension/tools/edit_file.ts
@@ -0,0 +1,139 @@
+import { defineTool } from "eve/tools";
+
+const replacementSchema = {
+ type: "object",
+ additionalProperties: false,
+ properties: {
+ oldText: {
+ type: "string",
+ minLength: 1,
+ description:
+ "Exact text for one targeted replacement. It must be unique in the original file and must not overlap with any other edits[].oldText in the same call.",
+ },
+ newText: {
+ type: "string",
+ description: "Replacement text for this targeted edit.",
+ },
+ },
+ required: ["oldText", "newText"],
+} as const;
+
+const inputSchema = {
+ type: "object",
+ additionalProperties: false,
+ properties: {
+ path: {
+ type: "string",
+ minLength: 1,
+ description: "Path to the file to edit (relative or absolute).",
+ },
+ edits: {
+ type: "array",
+ minItems: 1,
+ items: replacementSchema,
+ description:
+ "One or more targeted replacements. Each edit is matched against the original file, not incrementally. Do not include overlapping or nested edits. If two changes touch the same block or nearby lines, merge them into one edit instead.",
+ },
+ },
+ required: ["path", "edits"],
+} as const;
+
+const outputSchema = {
+ type: "object",
+ additionalProperties: false,
+ properties: {
+ path: { type: "string" },
+ replacements: { type: "integer", minimum: 1 },
+ },
+ required: ["path", "replacements"],
+} as const;
+
+interface ExactEdit {
+ readonly oldText: string;
+ readonly newText: string;
+}
+
+/** Applies unique, non-overlapping replacements matched against the original content. */
+export function applyExactEdits(content: string, edits: readonly ExactEdit[]): string {
+ if (edits.length === 0) {
+ throw new Error("edits must contain at least one replacement.");
+ }
+
+ const matches = edits.map((edit, index) => {
+ if (edit.oldText.length === 0) {
+ throw new Error(`edits[${index}].oldText must not be empty.`);
+ }
+
+ const start = content.indexOf(edit.oldText);
+ if (start === -1) {
+ throw new Error(
+ `edits[${index}].oldText was not found in the current file. Read the file and try again.`,
+ );
+ }
+ if (content.indexOf(edit.oldText, start + 1) !== -1) {
+ throw new Error(
+ `edits[${index}].oldText occurs more than once. Include more surrounding text to make it unique.`,
+ );
+ }
+
+ return { ...edit, end: start + edit.oldText.length, index, start };
+ });
+
+ const orderedMatches = [...matches].sort((left, right) => left.start - right.start);
+ for (let index = 1; index < orderedMatches.length; index += 1) {
+ const previous = orderedMatches[index - 1];
+ const current = orderedMatches[index];
+ if (previous !== undefined && current !== undefined && current.start < previous.end) {
+ throw new Error(
+ `edits[${previous.index}] and edits[${current.index}] overlap. Merge them into one edit.`,
+ );
+ }
+ }
+
+ return orderedMatches
+ .toReversed()
+ .reduce(
+ (result, edit) => result.slice(0, edit.start) + edit.newText + result.slice(edit.end),
+ content,
+ );
+}
+
+export default defineTool({
+ description:
+ "Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.",
+ inputSchema,
+ outputSchema,
+ async execute(input, ctx) {
+ const { edits, path } = input;
+ if (
+ typeof path !== "string" ||
+ !Array.isArray(edits) ||
+ edits.some(
+ (edit) =>
+ typeof edit !== "object" ||
+ edit === null ||
+ typeof edit.oldText !== "string" ||
+ typeof edit.newText !== "string",
+ )
+ ) {
+ throw new Error("path must be a string and edits must contain oldText and newText strings.");
+ }
+
+ const sandbox = await ctx.getSandbox();
+ const content = await sandbox.readTextFile({ path });
+
+ if (content === null) {
+ throw new Error(`File not found: ${path}.`);
+ }
+ if (content.includes("\0")) {
+ throw new Error(`File "${path}" contains NUL bytes and appears to be binary.`);
+ }
+
+ await sandbox.writeTextFile({
+ content: applyExactEdits(content, edits),
+ path,
+ });
+
+ return { path: sandbox.resolvePath(path), replacements: edits.length };
+ },
+});
diff --git a/packages/eve-self-modification/package.json b/packages/eve-self-modification/package.json
new file mode 100644
index 000000000..1254a9263
--- /dev/null
+++ b/packages/eve-self-modification/package.json
@@ -0,0 +1,86 @@
+{
+ "name": "@eve/self-modification",
+ "version": "0.0.0",
+ "description": "Development-only source editing subagent for eve applications.",
+ "keywords": [
+ "agents",
+ "eve",
+ "extension",
+ "self-modifying"
+ ],
+ "homepage": "https://github.com/vercel/eve#readme",
+ "bugs": {
+ "url": "https://github.com/vercel/eve/issues"
+ },
+ "license": "Apache-2.0",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/vercel/eve.git",
+ "directory": "packages/eve-self-modification"
+ },
+ "files": [
+ "dist",
+ "scaffold",
+ "README.md"
+ ],
+ "type": "module",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "default": "./dist/index.mjs"
+ },
+ "./agent": {
+ "eve-source": "./src/agent.ts",
+ "types": "./scaffold/agent.d.ts",
+ "import": "./scaffold/agent.js",
+ "default": "./scaffold/agent.js"
+ },
+ "./sandbox": {
+ "eve-source": "./src/sandbox.ts",
+ "types": "./scaffold/sandbox.d.ts",
+ "import": "./scaffold/sandbox.js",
+ "default": "./scaffold/sandbox.js"
+ },
+ "./extension": {
+ "types": "./dist/index.d.ts",
+ "default": "./dist/index.mjs"
+ },
+ "./tools": {
+ "types": "./dist/tools/index.d.ts",
+ "default": "./dist/tools/index.mjs"
+ }
+ },
+ "publishConfig": {
+ "access": "public"
+ },
+ "scripts": {
+ "build": "eve extension build && tsc -p tsconfig.scaffold.json",
+ "prepare": "pnpm run build",
+ "test:unit": "vitest run src",
+ "typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.scaffold.json --noEmit"
+ },
+ "dependencies": {
+ "just-bash": "3.1.0"
+ },
+ "devDependencies": {
+ "@types/node": "catalog:",
+ "eve": "workspace:*",
+ "typescript": "catalog:",
+ "vitest": "catalog:"
+ },
+ "peerDependencies": {
+ "eve": "workspace:*"
+ },
+ "engines": {
+ "node": ">=24"
+ },
+ "eve": {
+ "extension": {
+ "source": "./extension",
+ "dist": "./dist/extension",
+ "externalDependencies": [
+ "just-bash"
+ ]
+ }
+ }
+}
diff --git a/packages/eve-self-modification/src/agent.test.ts b/packages/eve-self-modification/src/agent.test.ts
new file mode 100644
index 000000000..d789b5e22
--- /dev/null
+++ b/packages/eve-self-modification/src/agent.test.ts
@@ -0,0 +1,33 @@
+import { afterEach, describe, expect, it } from "vitest";
+
+import { DEFAULT_SELF_MODIFICATION_MODEL, defineSelfModificationAgent } from "./agent.js";
+
+const originalEveDev = process.env.EVE_DEV;
+
+afterEach(() => {
+ if (originalEveDev === undefined) {
+ delete process.env.EVE_DEV;
+ } else {
+ process.env.EVE_DEV = originalEveDev;
+ }
+});
+
+describe("defineSelfModificationAgent", () => {
+ it("uses the default model", async () => {
+ process.env.EVE_DEV = "1";
+
+ const agent = defineSelfModificationAgent();
+ const definition = await agent.events["session.started"]?.({}, {} as never);
+
+ expect(definition).toMatchObject({ model: DEFAULT_SELF_MODIFICATION_MODEL });
+ });
+
+ it("configures the subagent model", async () => {
+ process.env.EVE_DEV = "1";
+
+ const agent = defineSelfModificationAgent({ model: "openai/gpt-5" });
+ const definition = await agent.events["session.started"]?.({}, {} as never);
+
+ expect(definition).toMatchObject({ model: "openai/gpt-5" });
+ });
+});
diff --git a/packages/eve-self-modification/src/agent.ts b/packages/eve-self-modification/src/agent.ts
new file mode 100644
index 000000000..8efb05b08
--- /dev/null
+++ b/packages/eve-self-modification/src/agent.ts
@@ -0,0 +1,41 @@
+import { defineAgent, defineDynamic, type AgentStaticModelDefinition } from "eve";
+
+/** Default model used by the self-modification subagent. */
+export const DEFAULT_SELF_MODIFICATION_MODEL = "anthropic/claude-sonnet-5";
+
+/** Configuration for the development-only self-modification subagent. */
+export interface SelfModificationAgentOptions {
+ /**
+ * Model used by the self-modification subagent.
+ *
+ * @default "anthropic/claude-sonnet-5"
+ */
+ readonly model?: AgentStaticModelDefinition;
+}
+
+/** Defines the development-only self-modification dynamic subagent. */
+export function defineSelfModificationAgent(options: SelfModificationAgentOptions = {}) {
+ const model = options.model ?? DEFAULT_SELF_MODIFICATION_MODEL;
+
+ return defineDynamic({
+ events: {
+ "session.started": () =>
+ process.env.EVE_DEV === "1"
+ ? defineAgent({
+ description:
+ "Delegate here when the developer asks to change this eve agent or its authored source. " +
+ "Describe the requested behavior change without guessing source paths or passing runtime skill paths under $HOME/.agents or /workspace/skills; the subagent discovers authored files under its /source mount. " +
+ "Treat requests for persistent changes to future behavior or capabilities as source-modification requests, even when the developer does not mention files or source code. " +
+ "Infer persistence from the request and conversation rather than waiting for phrases such as “modify your source.” " +
+ "For example, asking the agent to stop always doing something, add a capability, or change future responses calls for inspecting and editing the authored source instead of providing a one-turn workaround. " +
+ "Resolve short follow-ups such as “yes” or “do it” against the preceding conversation. " +
+ "Source edits do not affect the caller’s current turn. After this subagent reports changes, do not invoke edited tools or attempt runtime verification until a new user turn. " +
+ "If whether the requested change should persist is genuinely ambiguous, ask one concise clarifying question.",
+ model,
+ })
+ : null,
+ },
+ });
+}
+
+export default defineSelfModificationAgent();
diff --git a/packages/eve-self-modification/src/edit-file.test.ts b/packages/eve-self-modification/src/edit-file.test.ts
new file mode 100644
index 000000000..6b10b7f8f
--- /dev/null
+++ b/packages/eve-self-modification/src/edit-file.test.ts
@@ -0,0 +1,83 @@
+import { describe, expect, it } from "vitest";
+
+import editFile, { applyExactEdits } from "../extension/tools/edit_file.js";
+
+describe("applyExactEdits", () => {
+ it("replaces one exact match", () => {
+ expect(applyExactEdits("before old after", [{ oldText: "old", newText: "new" }])).toBe(
+ "before new after",
+ );
+ });
+
+ it("applies multiple disjoint edits against the original content", () => {
+ expect(
+ applyExactEdits("a b", [
+ { oldText: "a", newText: "b" },
+ { oldText: "b", newText: "c" },
+ ]),
+ ).toBe("b c");
+ });
+
+ it("supports deletion", () => {
+ expect(applyExactEdits("before old after", [{ oldText: "old ", newText: "" }])).toBe(
+ "before after",
+ );
+ });
+
+ it("rejects a missing match", () => {
+ expect(() => applyExactEdits("current", [{ oldText: "stale", newText: "new" }])).toThrow(
+ "oldText was not found in the current file",
+ );
+ });
+
+ it("rejects a non-unique match", () => {
+ expect(() => applyExactEdits("same same", [{ oldText: "same", newText: "new" }])).toThrow(
+ "oldText occurs more than once",
+ );
+ });
+
+ it("rejects overlapping edits", () => {
+ expect(() =>
+ applyExactEdits("before old after", [
+ { oldText: "old", newText: "new" },
+ { oldText: "before old", newText: "before new" },
+ ]),
+ ).toThrow("overlap");
+ });
+
+ it("rejects an empty edit list", () => {
+ expect(() => applyExactEdits("current", [])).toThrow(
+ "edits must contain at least one replacement",
+ );
+ });
+
+ it("rejects an empty match", () => {
+ expect(() => applyExactEdits("current", [{ oldText: "", newText: "new" }])).toThrow(
+ "oldText must not be empty",
+ );
+ });
+
+ it("edits the current sandbox file", async () => {
+ let content = "before old after";
+ const sandbox = {
+ readTextFile: async () => content,
+ resolvePath: (path: string) => path,
+ writeTextFile: async (input: { readonly content: string }) => {
+ content = input.content;
+ },
+ };
+
+ await expect(
+ editFile.execute(
+ {
+ edits: [{ newText: "new", oldText: "old" }],
+ path: "/source/file.ts",
+ },
+ {
+ getSandbox: async () => sandbox,
+ } as never,
+ ),
+ ).resolves.toEqual({ path: "/source/file.ts", replacements: 1 });
+ expect(content).toBe("before new after");
+ });
+});
diff --git a/packages/eve-self-modification/src/filesystem.ts b/packages/eve-self-modification/src/filesystem.ts
new file mode 100644
index 000000000..c5733a4f3
--- /dev/null
+++ b/packages/eve-self-modification/src/filesystem.ts
@@ -0,0 +1,33 @@
+import { resolve } from "node:path";
+
+import type { IFileSystem } from "just-bash";
+
+export async function createSelfModificationFilesystem(input: {
+ readonly appRoot: string;
+ readonly defaultFilesystem: IFileSystem;
+ readonly justBash: typeof import("just-bash");
+}): Promise<IFileSystem> {
+ const { MountableFs, OverlayFs, ReadWriteFs } = input.justBash;
+ await input.defaultFilesystem.mkdir("/source", { recursive: true });
+ return new MountableFs({
+ base: input.defaultFilesystem,
+ mounts: [
+ {
+ filesystem: new ReadWriteFs({
+ allowSymlinks: false,
+ maxFileReadSize: Number.MAX_SAFE_INTEGER,
+ root: resolve(input.appRoot, "agent"),
+ }),
+ mountPoint: "/source",
+ },
+ {
+ filesystem: new OverlayFs({
+ mountPoint: "/",
+ readOnly: true,
+ root: resolve(input.appRoot, "node_modules/eve/docs"),
+ }),
+ mountPoint: "/eve-docs",
+ },
+ ],
+ });
+}
diff --git a/packages/eve-self-modification/src/sandbox.test.ts b/packages/eve-self-modification/src/sandbox.test.ts
new file mode 100644
index 000000000..ddbc17a90
--- /dev/null
+++ b/packages/eve-self-modification/src/sandbox.test.ts
@@ -0,0 +1,46 @@
+import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+
+import * as justBash from "just-bash";
+import { afterEach, describe, expect, it } from "vitest";
+
+import { createSelfModificationFilesystem } from "./filesystem.js";
+
+const temporaryDirectories: string[] = [];
+
+afterEach(async () => {
+ await Promise.all(
+ temporaryDirectories
+ .splice(0)
+ .map((directory) => rm(directory, { force: true, recursive: true })),
+ );
+});
+
+async function createAppRoot(): Promise<string> {
+ const appRoot = await mkdtemp(join(tmpdir(), "eve-self-modification-sandbox-"));
+ temporaryDirectories.push(appRoot);
+ await mkdir(join(appRoot, "agent"), { recursive: true });
+ await mkdir(join(appRoot, "node_modules/eve/docs"), { recursive: true });
+ await writeFile(join(appRoot, "node_modules/eve/docs/README.md"), "installed eve docs\n");
+ return appRoot;
+}
+
+describe("self-modification filesystem", () => {
+ it("mounts authored source read-write and installed eve docs read-only", async () => {
+ const appRoot = await createAppRoot();
+ const filesystem = await createSelfModificationFilesystem({
+ appRoot,
+ defaultFilesystem: new justBash.InMemoryFs(),
+ justBash,
+ });
+
+ expect(await filesystem.readFile("/eve-docs/README.md")).toBe("installed eve docs\n");
+ await expect(filesystem.writeFile("/eve-docs/README.md", "changed\n")).rejects.toThrow(
+ /read-only file system/u,
+ );
+
+ await filesystem.writeFile("/source/instructions.md", "authored\n");
+ expect(await readFile(join(appRoot, "agent/instructions.md"), "utf8")).toBe("authored\n");
+ });
+});
diff --git a/packages/eve-self-modification/src/sandbox.ts b/packages/eve-self-modification/src/sandbox.ts
new file mode 100644
index 000000000..a1895c347
--- /dev/null
+++ b/packages/eve-self-modification/src/sandbox.ts
@@ -0,0 +1,8 @@
+import { defineSandbox } from "eve/sandbox";
+import { justbash } from "eve/sandbox/just-bash";
+
+import { createSelfModificationFilesystem } from "./filesystem.js";
+
+export default defineSandbox({
+ backend: justbash({ filesystem: createSelfModificationFilesystem }),
+});
diff --git a/packages/eve-self-modification/tsconfig.json b/packages/eve-self-modification/tsconfig.json
new file mode 100644
index 000000000..914d8f409
--- /dev/null
+++ b/packages/eve-self-modification/tsconfig.json
@@ -0,0 +1,9 @@
+{
+ "$schema": "https://json.schemastore.org/tsconfig",
+ "extends": "../../tsconfig.json",
+ "compilerOptions": {
+ "noEmit": true,
+ "rootDir": "."
+ },
+ "include": ["extension/**/*.ts", "src/**/*.ts"]
+}
diff --git a/packages/eve-self-modification/tsconfig.scaffold.json b/packages/eve-self-modification/tsconfig.scaffold.json
new file mode 100644
index 000000000..6a7377f81
--- /dev/null
+++ b/packages/eve-self-modification/tsconfig.scaffold.json
@@ -0,0 +1,13 @@
+{
+ "$schema": "https://json.schemastore.org/tsconfig",
+ "extends": "./tsconfig.json",
+ "compilerOptions": {
+ "declaration": true,
+ "declarationMap": true,
+ "noEmit": false,
+ "outDir": "./scaffold",
+ "rootDir": "./src"
+ },
+ "include": ["src/**/*.ts"],
+ "exclude": ["src/**/*.test.ts"]
+}
diff --git a/packages/eve/src/execution/sandbox/bindings/just-bash-runtime.ts b/packages/eve/src/execution/sandbox/bindings/just-bash-runtime.ts
index d861a50eb..72ee3c564 100644
--- a/packages/eve/src/execution/sandbox/bindings/just-bash-runtime.ts
+++ b/packages/eve/src/execution/sandbox/bindings/just-bash-runtime.ts
@@ -79,10 +79,11 @@ export async function createBashSandbox(input: {
readonly rootPath: string;
readonly sessionKey: string;
}): Promise<BashSandbox> {
- const { ReadWriteFs, Sandbox } = await loadJustBashModule({
+ const justBash = await loadJustBashModule({
appRoot: input.appRoot,
autoInstall: input.autoInstall,
});
+ const { ReadWriteFs, Sandbox } = justBash;
const filesystemRootPath = resolveLocalSandboxFilesystemRootPath(input.rootPath);
const metadataPath = resolveLocalSandboxMetadataPath(input.rootPath);
const metadata = await readLocalMetadata(metadataPath);
@@ -100,6 +101,7 @@ export async function createBashSandbox(input: {
filesystem = await input.filesystem({
appRoot: input.appRoot,
defaultFilesystem,
+ justBash,
});
} catch (error) {
throw new Error("Failed to create the custom just-bash filesystem.", { cause: error });
diff --git a/packages/eve/src/internal/authored-module-loader.scenario.test.ts b/packages/eve/src/internal/authored-module-loader.scenario.test.ts
index 3727b35da..1a26d80d0 100644
--- a/packages/eve/src/internal/authored-module-loader.scenario.test.ts
+++ b/packages/eve/src/internal/authored-module-loader.scenario.test.ts
@@ -316,7 +316,10 @@ describe("loadAuthoredModuleNamespace", () => {
JSON.stringify(
{
exports: {
- "./exa-linkedin": "./src/exa-linkedin.ts",
+ "./exa-linkedin": {
+ "eve-source": "./src/exa-linkedin.ts",
+ default: "./dist/exa-linkedin.js",
+ },
},
name: "@repo/enrichment",
type: "module",
@@ -507,6 +510,40 @@ describe("loadAuthoredModuleNamespace", () => {
}
});
+ it("loads a linked package tsconfig from its real workspace location", async () => {
+ const root = await mkdtemp(join(tmpdir(), "eve-linked-package-tsconfig-"));
+
+ try {
+ const workspaceRoot = join(root, "workspace");
+ const packageRoot = join(workspaceRoot, "packages", "extension");
+ const linkedPackageRoot = join(root, "app", "node_modules", "@repo", "extension");
+ await mkdir(join(packageRoot, "dist"), { recursive: true });
+ await mkdir(join(linkedPackageRoot, ".."), { recursive: true });
+ await writeFile(
+ join(workspaceRoot, "tsconfig.json"),
+ JSON.stringify({ compilerOptions: { target: "ES2024" } }),
+ );
+ await writeFile(
+ join(packageRoot, "tsconfig.json"),
+ JSON.stringify({ extends: "../../tsconfig.json" }),
+ );
+ await writeFile(
+ join(packageRoot, "package.json"),
+ JSON.stringify({ name: "@repo/extension", type: "module" }),
+ );
+ await writeFile(join(packageRoot, "dist", "entry.mjs"), 'export const result = "linked";\n');
+ await symlink(packageRoot, linkedPackageRoot, "junction");
+
+ const moduleNamespace = await loadAuthoredModuleNamespace(
+ join(linkedPackageRoot, "dist", "entry.mjs"),
+ );
+
+ expect(moduleNamespace.result).toBe("linked");
+ } finally {
+ await rm(root, { force: true, recursive: true });
+ }
+ });
+
it("keeps configured dependencies external when they are imported from workspace packages", async () => {
const app = await scenarioApp({
files: {
diff --git a/packages/eve/src/internal/authored-module-loader.ts b/packages/eve/src/internal/authored-module-loader.ts
index 5242c227a..76e71b01c 100644
--- a/packages/eve/src/internal/authored-module-loader.ts
+++ b/packages/eve/src/internal/authored-module-loader.ts
@@ -1,5 +1,5 @@
import { createHash } from "node:crypto";
-import { existsSync, mkdirSync, writeFileSync } from "node:fs";
+import { existsSync, mkdirSync, realpathSync, writeFileSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import type { CompiledAgentManifest } from "#compiler/manifest.js";
@@ -305,6 +305,7 @@ export async function bundleAuthoredModuleMapForGeneration(input: {
platform: "node",
plugins,
resolve: {
+ conditionNames: ["eve-source"],
extensions: [...RESOLVE_EXTENSIONS],
},
tsconfig: resolveAuthoredTsConfigPath(packageRoot),
@@ -418,6 +419,7 @@ async function buildAuthoredModuleBundle(
platform: "node",
plugins,
resolve: {
+ conditionNames: ["eve-source"],
extensions: [...RESOLVE_EXTENSIONS],
},
tsconfig: tsconfigPath,
@@ -513,7 +515,7 @@ function resolveAuthoredPackageRoot(modulePath: string): string {
while (true) {
if (existsSync(join(currentDirectory, "package.json"))) {
- return currentDirectory;
+ return realpathSync(currentDirectory);
}
const parentDirectory = dirname(currentDirectory);
diff --git a/packages/eve/src/public/sandbox/just-bash-sandbox.ts b/packages/eve/src/public/sandbox/just-bash-sandbox.ts
index 126e732ce..c3463eda8 100644
--- a/packages/eve/src/public/sandbox/just-bash-sandbox.ts
+++ b/packages/eve/src/public/sandbox/just-bash-sandbox.ts
@@ -8,6 +8,8 @@ export interface JustBashFilesystemContext {
readonly appRoot: string;
/** eve's durable, session-owned filesystem, including `/workspace`. */
readonly defaultFilesystem: IFileSystem;
+ /** The just-bash engine resolved by eve after its optional installation check. */
+ readonly justBash: typeof import("just-bash");
}
/**
diff --git a/packages/eve/src/runtime/resolve-dynamic-subagent.test.ts b/packages/eve/src/runtime/resolve-dynamic-subagent.test.ts
index f563b4987..8e6d454f1 100644
--- a/packages/eve/src/runtime/resolve-dynamic-subagent.test.ts
+++ b/packages/eve/src/runtime/resolve-dynamic-subagent.test.ts
@@ -13,7 +13,6 @@ describe("normalizeResolvedDynamicSubagentDefinition", () => {
sourceKind: "module",
},
{
- build: { externalDependencies: ["eve-selfmod"] },
events: { "session.started": handler },
kind: "eve:dynamic",
},
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index eac5dcfa0..6823ee1a3 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -268,6 +268,9 @@ importers:
'@chat-adapter/x':
specifier: 4.34.0
+ '@eve/self-modification':
+ specifier: workspace:*
+ version: link:../../packages/eve-self-modification
'@getdial/chat-sdk-adapter':
specifier: 0.2.0
@@ -1375,6 +1378,25 @@ importers:
specifier: 'catalog:'
+ packages/eve-self-modification:
+ dependencies:
+ just-bash:
+ specifier: 3.1.0
+ version: 3.1.0([email protected])
+ devDependencies:
+ '@types/node':
+ specifier: 'catalog:'
+ version: 25.9.1
+ eve:
+ specifier: workspace:*
+ version: link:../eve
+ typescript:
+ specifier: 'catalog:'
+ version: 7.0.2
+ vitest:
+ specifier: 'catalog:'
+
packages:
'@agent-browser/[email protected]':
diff --git a/scripts/assert-changeset-publish-packages.mjs b/scripts/assert-changeset-publish-packages.mjs
index 12005398d..3bda84d8b 100644
--- a/scripts/assert-changeset-publish-packages.mjs
+++ b/scripts/assert-changeset-publish-packages.mjs
@@ -1,7 +1,7 @@
import { access, readdir, readFile } from "node:fs/promises";
import { join } from "node:path";
-const allowedPublicPackages = new Set(["@eve/buzz-acp-adapter", "eve"]);
+const allowedPublicPackages = new Set(["@eve/buzz-acp-adapter", "eve", "@eve/self-modification"]);
const workspaceRoots = ["apps", "packages"];
async function readJson(path) {