The Open Framework for Building Agents
fix(eve): mount workspace dependency packages in place for dev snapshots (#1685)
Chad Hietalab7a2a14771bc
diff --git a/.changeset/mount-workspace-deps-in-dev-snapshots.md b/.changeset/mount-workspace-deps-in-dev-snapshots.mdnew file mode 100644index 000000000..4ffdb3f2d--- /dev/null+++ b/.changeset/mount-workspace-deps-in-dev-snapshots.md@@ -0,0 +1,12 @@+---+"eve": patch+---++Dev runtime snapshots now mount workspace dependency packages in place+instead of copying them. Only roots that host runtime-hydrated authored+source — the app root, extension mount roots, and tsconfig path-alias+targets — are still copied, matching how installed dependencies already+resolved. In monorepos this removes the largest per-generation copy: a+workspace-linked framework package (hundreds of files and tens of+megabytes per rebuild) no longer lands under+`.eve/dev-runtime/snapshots/`.diff --git a/packages/eve/src/internal/nitro/dev-runtime-artifacts.integration.test.ts b/packages/eve/src/internal/nitro/dev-runtime-artifacts.integration.test.tsindex df6276e52..01c7ab5a1 100644--- a/packages/eve/src/internal/nitro/dev-runtime-artifacts.integration.test.ts+++ b/packages/eve/src/internal/nitro/dev-runtime-artifacts.integration.test.ts@@ -875,21 +875,16 @@ describe("development runtime artifact snapshots", () => {expect(moduleNamespace.answer).toBe(42);});- it("freezes local workspace packages resolved through app node_modules symlinks", async () => {+ it("mounts local workspace packages resolved through app node_modules symlinks in place", async () => {const workspaceRoot = await createScratchDirectory("eve-dev-runtime-linked-package-");const appRoot = join(workspaceRoot, "apps", "agent-app");const agentRoot = join(appRoot, "agent");const packageRoot = join(workspaceRoot, "packages", "message");- const externalPackageRoot = join(workspaceRoot, "node_modules", "external-message");const compileDirectoryPath = join(appRoot, ".eve", "compile");const manifestPath = join(compileDirectoryPath, "compiled-agent-manifest.json");await mkdir(agentRoot, { recursive: true });- await mkdir(join(packageRoot, "src"), { recursive: true });- await mkdir(join(packageRoot, "build"), { recursive: true });await mkdir(join(packageRoot, "dist"), { recursive: true });- await mkdir(join(packageRoot, "node_modules"), { recursive: true });- await mkdir(externalPackageRoot, { recursive: true });await mkdir(join(workspaceRoot, "packages", "unused"), { recursive: true });await mkdir(join(appRoot, "node_modules", "@repo"), { recursive: true });await mkdir(compileDirectoryPath, { recursive: true });@@ -920,9 +915,6 @@ describe("development runtime artifact snapshots", () => {join(packageRoot, "package.json"),JSON.stringify({- dependencies: {- "external-message": "1.0.0",- },exports: "./dist/index.js",name: "@repo/message",type: "module",@@ -932,45 +924,189 @@ describe("development runtime artifact snapshots", () => {),);await writeFile(- join(externalPackageRoot, "package.json"),+ join(packageRoot, "dist", "index.js"),+ 'export const message = "snapshotted";\n',+ );+ await writeFile(+ join(workspaceRoot, "packages", "unused", "package.json"),+ '{"name":"unused"}\n',+ );+ await symlink(packageRoot, join(appRoot, "node_modules", "@repo", "message"), "junction");+ await writeFile(+ join(agentRoot, "agent.ts"),+ 'import { message } from "@repo/message";\nexport const result = message;\n',+ );+ await writeFile(manifestPath, `${JSON.stringify({ agentRoot, appRoot }, null, 2)}\n`);++ const snapshot = await stageDevelopmentRuntimeArtifactsSnapshot({+ paths: { compileDirectoryPath },+ project: { appRoot },+ } as CompileAgentResult);++ await writeFile(join(packageRoot, "dist", "index.js"), 'export const message = "live";\n');++ // Workspace dependency packages are mounted in place like installed+ // dependencies instead of being copied into the snapshot.+ expect(existsSync(join(snapshot.snapshotSourceRoot, "packages"))).toBe(false);+ const snapshotMountPath = join(snapshot.runtimeAppRoot, "node_modules", "@repo", "message");+ await expect(lstat(snapshotMountPath).then((stats) => stats.isSymbolicLink())).resolves.toBe(+ true,+ );+ await expect(realpath(snapshotMountPath)).resolves.toBe(await realpath(packageRoot));++ const moduleNamespace = await loadAuthoredModuleNamespace(+ join(snapshot.runtimeAppRoot, "agent", "agent.ts"),+ );++ expect(moduleNamespace.result).toBe("live");+ });++ it("freezes workspace packages that host extension mount roots", async () => {+ const workspaceRoot = await createScratchDirectory("eve-dev-runtime-extension-package-");+ const appRoot = join(workspaceRoot, "apps", "agent-app");+ const agentRoot = join(appRoot, "agent");+ const packageRoot = join(workspaceRoot, "packages", "acme-extension");+ const extensionRoot = join(packageRoot, "extension");+ const compileDirectoryPath = join(appRoot, ".eve", "compile");+ const manifestPath = join(compileDirectoryPath, "compiled-agent-manifest.json");++ await mkdir(agentRoot, { recursive: true });+ await mkdir(join(extensionRoot, "tools"), { recursive: true });+ await mkdir(join(appRoot, "node_modules", "@acme"), { recursive: true });+ await mkdir(compileDirectoryPath, { recursive: true });+ await writeFile(+ join(workspaceRoot, "pnpm-workspace.yaml"),+ "packages:\n - apps/*\n - packages/*\n",+ );+ await writeFile(+ join(appRoot, "package.json"),JSON.stringify({- exports: "./index.js",- name: "external-message",+ dependencies: {+ "@acme/extension": "workspace:*",+ },+ name: "agent-app",type: "module",- version: "1.0.0",},null,2,),);await writeFile(- join(externalPackageRoot, "index.js"),- 'export const externalMessage = "external";\n',+ join(packageRoot, "package.json"),+ JSON.stringify(+ {+ exports: "./extension/extension.mjs",+ name: "@acme/extension",+ type: "module",+ },+ null,+ 2,+ ),);+ await writeFile(join(extensionRoot, "extension.mjs"), "export default {};\n");await writeFile(- join(packageRoot, "src", "index.ts"),- 'export const sourceMessage = "snapshotted-source";\n',+ join(extensionRoot, "tools", "read_label.mjs"),+ 'export default { execute: () => "original" };\n',);- await writeFile(join(packageRoot, "build", "artifact.js"), "build output\n");+ await symlink(packageRoot, join(appRoot, "node_modules", "@acme", "extension"), "junction");+ await writeFile(join(agentRoot, "agent.ts"), "export const answer = 42;\n");+ await writeFile(manifestPath, `${JSON.stringify({ agentRoot, appRoot }, null, 2)}\n`);++ const snapshot = await stageDevelopmentRuntimeArtifactsSnapshot({+ manifest: {+ agentRoot,+ appRoot,+ extensionMounts: [{ sourceRoot: extensionRoot }],+ },+ paths: { compileDirectoryPath },+ project: { appRoot },+ } as CompileAgentResult);+await writeFile(- join(packageRoot, "dist", "index.js"),- 'import { externalMessage } from "external-message";\nexport const message = `snapshotted:${externalMessage}`;\n',+ join(extensionRoot, "tools", "read_label.mjs"),+ 'export default { execute: () => "live" };\n',);++ // Extension mount roots host runtime-hydrated authored source, so the+ // package stays a real copy and the mount links into the snapshot.+ expect(existsSync(join(snapshot.snapshotSourceRoot, "packages", "acme-extension"))).toBe(true);+ await expect(+ readFile(+ join(+ snapshot.snapshotSourceRoot,+ "packages",+ "acme-extension",+ "extension",+ "tools",+ "read_label.mjs",+ ),+ "utf8",+ ),+ ).resolves.toContain("original");+ const snapshotMountPath = join(snapshot.runtimeAppRoot, "node_modules", "@acme", "extension");+ const canonicalSnapshotSourceRoot = await realpath(snapshot.snapshotSourceRoot);+ await expect(realpath(snapshotMountPath)).resolves.toBe(+ join(canonicalSnapshotSourceRoot, "packages", "acme-extension"),+ );+ });++ it("mounts dependencies of workspace packages nested inside the app root", async () => {+ const appRoot = await createScratchDirectory("eve-dev-runtime-nested-workspace-");+ const agentRoot = join(appRoot, "agent");+ const packageRoot = join(appRoot, "packages", "nested");+ const installedPackageRoot = join(packageRoot, "node_modules", "external-value");+ const compileDirectoryPath = join(appRoot, ".eve", "compile");+ const manifestPath = join(compileDirectoryPath, "compiled-agent-manifest.json");++ await mkdir(agentRoot, { recursive: true });+ await mkdir(join(packageRoot, "dist"), { recursive: true });+ await mkdir(installedPackageRoot, { recursive: true });+ await mkdir(join(appRoot, "node_modules", "@repo"), { recursive: true });+ await mkdir(compileDirectoryPath, { recursive: true });+ // The app root is also the workspace root, so workspace packages live+ // inside the copied app tree.+ await writeFile(join(appRoot, "pnpm-workspace.yaml"), "packages:\n - packages/*\n");await writeFile(- join(workspaceRoot, "packages", "unused", "package.json"),- '{"name":"unused"}\n',+ join(appRoot, "package.json"),+ JSON.stringify(+ {+ dependencies: {+ "@repo/nested": "workspace:*",+ },+ name: "agent-app",+ type: "module",+ },+ null,+ 2,+ ),);- await symlink(packageRoot, join(appRoot, "node_modules", "@repo", "message"), "junction");- await symlink(- externalPackageRoot,- join(packageRoot, "node_modules", "external-message"),- "junction",+ await writeFile(+ join(packageRoot, "package.json"),+ JSON.stringify(+ {+ dependencies: {+ "external-value": "1.0.0",+ },+ exports: "./dist/index.js",+ name: "@repo/nested",+ type: "module",+ },+ null,+ 2,+ ),);await writeFile(- join(agentRoot, "agent.ts"),- 'import { message } from "@repo/message";\nexport const result = message;\n',+ join(installedPackageRoot, "package.json"),+ '{"name":"external-value","version":"1.0.0","type":"module","exports":"./index.js"}\n',+ );+ await writeFile(join(installedPackageRoot, "index.js"), 'export const value = "nested";\n');+ await writeFile(+ join(packageRoot, "dist", "index.js"),+ 'import { value } from "external-value";\nexport const message = value;\n',);+ await symlink(packageRoot, join(appRoot, "node_modules", "@repo", "nested"), "junction");+ await writeFile(join(agentRoot, "agent.ts"), "export const answer = 42;\n");await writeFile(manifestPath, `${JSON.stringify({ agentRoot, appRoot }, null, 2)}\n`);const snapshot = await stageDevelopmentRuntimeArtifactsSnapshot({@@ -978,30 +1114,29 @@ describe("development runtime artifact snapshots", () => {project: { appRoot },} as CompileAgentResult);- await writeFile(join(packageRoot, "dist", "index.js"), 'export const message = "live";\n');-- expect(existsSync(join(snapshot.snapshotSourceRoot, "packages", "message"))).toBe(true);- expect(existsSync(join(snapshot.snapshotSourceRoot, "packages", "message", "build"))).toBe(- true,+ // A copied workspace package keeps the dependency mounts its snapshot+ // copy resolves through.+ expect(+ existsSync(join(snapshot.snapshotSourceRoot, "packages", "nested", "dist", "index.js")),+ ).toBe(true);+ const nestedDependencyMount = join(+ snapshot.snapshotSourceRoot,+ "packages",+ "nested",+ "node_modules",+ "external-value",);- expect(existsSync(join(snapshot.snapshotSourceRoot, "packages", "message", "dist"))).toBe(true);- expect(existsSync(join(snapshot.snapshotSourceRoot, "packages", "unused"))).toBe(false);await expect(- lstat(- join(- snapshot.snapshotSourceRoot,- "packages",- "message",- "node_modules",- "external-message",- ),- ).then((stats) => stats.isSymbolicLink()),+ lstat(nestedDependencyMount).then((stats) => stats.isSymbolicLink()),).resolves.toBe(true);+ await expect(realpath(nestedDependencyMount)).resolves.toBe(+ await realpath(installedPackageRoot),+ );const moduleNamespace = await loadAuthoredModuleNamespace(- join(snapshot.runtimeAppRoot, "agent", "agent.ts"),+ join(snapshot.snapshotSourceRoot, "packages", "nested", "dist", "index.js"),);- expect(moduleNamespace.result).toBe("snapshotted:external");+ expect(moduleNamespace.message).toBe("nested");});});diff --git a/packages/eve/src/internal/nitro/dev-runtime-artifacts.ts b/packages/eve/src/internal/nitro/dev-runtime-artifacts.tsindex 50ac85e80..899cb184a 100644--- a/packages/eve/src/internal/nitro/dev-runtime-artifacts.ts+++ b/packages/eve/src/internal/nitro/dev-runtime-artifacts.ts@@ -4,6 +4,7 @@ import { existsSync, readFileSync } from "node:fs";import { dirname, join, relative, resolve, sep } from "node:path";import type { CompileAgentResult } from "#compiler/compile-agent.js";+import type { CompiledAgentManifest } from "#compiler/manifest.js";import { copyDevelopmentSourceSnapshot } from "#internal/nitro/dev-runtime-source-snapshot-copy.js";import {createDevelopmentSourceSnapshotPlan,@@ -86,6 +87,7 @@ export async function stageDevelopmentRuntimeArtifactsSnapshot();const sourceSnapshotPlan = await createDevelopmentSourceSnapshotPlan({appRoot: compileResult.project.appRoot,+ authoredSourceRoots: collectExtensionMountSourceRoots(compileResult.manifest),snapshotRoot,});@@ -279,6 +281,21 @@ export async function pruneDevelopmentRuntimeArtifactsSnapshots(input: {});}+/**+ * Collects the workspace roots that host extension-authored source. Extension+ * modules hydrate from disk at runtime through snapshot paths, so their+ * packages stay real copies while other workspace dependencies are mounted.+ */+function collectExtensionMountSourceRoots(manifest?: CompiledAgentManifest): string[] {+ if (manifest === undefined) {+ return [];+ }++ return [manifest, ...(manifest.subagents ?? []).map((subagent) => subagent.agent)].flatMap(+ (node) => (node.extensionMounts ?? []).map((mount) => mount.sourceRoot),+ );+}+function readDevelopmentRuntimeArtifactsPointer(pointerPath: string | undefined,): DevelopmentRuntimeArtifactsPointerV1 | DevelopmentRuntimeArtifactsPointerV2 | undefined {diff --git a/packages/eve/src/internal/nitro/dev-runtime-source-snapshot-copy.ts b/packages/eve/src/internal/nitro/dev-runtime-source-snapshot-copy.tsindex a183df9cb..64f65ec43 100644--- a/packages/eve/src/internal/nitro/dev-runtime-source-snapshot-copy.ts+++ b/packages/eve/src/internal/nitro/dev-runtime-source-snapshot-copy.ts@@ -297,14 +297,12 @@ function rewriteTsConfigExtendsSpecifier(input: {async function createSnapshotDependencyMounts(plan: DevelopmentSourceSnapshotPlan): Promise<void> {for (const dependencyMount of plan.dependencyMounts) {const snapshotMountPath = toSnapshotPathForPlan(plan, dependencyMount.mountPath);- const sourcePath =- dependencyMount.sourceKind === "workspace"- ? toSnapshotPathForPlan(plan, dependencyMount.sourcePath)- : dependencyMount.sourcePath;- const mountTarget =- dependencyMount.sourceKind === "workspace"- ? relative(dirname(snapshotMountPath), sourcePath) || "."- : sourcePath;+ const sourcePath = dependencyMount.copied+ ? toSnapshotPathForPlan(plan, dependencyMount.sourcePath)+ : dependencyMount.sourcePath;+ const mountTarget = dependencyMount.copied+ ? relative(dirname(snapshotMountPath), sourcePath) || "."+ : sourcePath;await mkdir(dirname(snapshotMountPath), { recursive: true });await symlink(mountTarget, snapshotMountPath, "junction");diff --git a/packages/eve/src/internal/nitro/dev-runtime-source-snapshot-local-roots.ts b/packages/eve/src/internal/nitro/dev-runtime-source-snapshot-local-roots.tsnew file mode 100644index 000000000..96a4720dc--- /dev/null+++ b/packages/eve/src/internal/nitro/dev-runtime-source-snapshot-local-roots.ts@@ -0,0 +1,188 @@+import { existsSync } from "node:fs";+import { lstat } from "node:fs/promises";+import { dirname, join, relative, resolve, sep } from "node:path";++import {+ parseTsConfigObject,+ readTextFileIfExists,+} from "#internal/application/tsconfig-dependencies.js";++/**+ * Resolves the local roots that a tsconfig's path aliases can resolve to.+ * Each alias target that lands on authored workspace source contributes the+ * owning package root (or the target directory itself when no package owns+ * it), so snapshot planning can copy the aliased source.+ */+export async function resolveLocalTsConfigPathTargetRoots(input: {+ readonly configPath: string;+ readonly sourceRoot: string;+}): Promise<string[]> {+ const source = await readTextFileIfExists(input.configPath);++ if (source === undefined) {+ return [];+ }++ const parsedConfig = parseTsConfigObject(source);+ const compilerOptions = isObjectRecord(parsedConfig?.compilerOptions)+ ? parsedConfig.compilerOptions+ : undefined;+ const paths = isObjectRecord(compilerOptions?.paths) ? compilerOptions.paths : undefined;++ if (compilerOptions === undefined || paths === undefined) {+ return [];+ }++ const baseDirectory =+ typeof compilerOptions.baseUrl === "string"+ ? resolve(dirname(input.configPath), compilerOptions.baseUrl)+ : dirname(input.configPath);+ const localRoots = new Set<string>();++ for (const targets of Object.values(paths)) {+ if (!Array.isArray(targets)) {+ continue;+ }++ for (const target of targets) {+ if (typeof target !== "string" || target.length === 0) {+ continue;+ }++ const localRoot = await resolveLocalTsConfigPathTargetRoot({+ baseDirectory,+ sourceRoot: input.sourceRoot,+ target,+ });++ if (localRoot !== undefined) {+ localRoots.add(localRoot);+ }+ }+ }++ return [...localRoots].sort((left, right) => left.localeCompare(right));+}++/** Resolves the nearest ancestor directory (bounded by the source root) that owns a package.json. */+export async function resolveNearestPackageRoot(+ path: string,+ sourceRoot: string,+): Promise<string | undefined> {+ let currentDirectory = resolve(path);++ try {+ const stats = await lstat(currentDirectory);++ if (!stats.isDirectory()) {+ currentDirectory = dirname(currentDirectory);+ }+ } catch {+ currentDirectory = dirname(currentDirectory);+ }++ while (isAuthoredSourcePath(currentDirectory, sourceRoot)) {+ if (existsSync(join(currentDirectory, "package.json"))) {+ return currentDirectory;+ }++ const parentDirectory = dirname(currentDirectory);++ if (parentDirectory === currentDirectory) {+ return undefined;+ }++ currentDirectory = parentDirectory;+ }++ return undefined;+}++/** Returns whether a path is authored workspace source rather than installed dependency data. */+export function isAuthoredSourcePath(path: string, sourceRoot: string): boolean {+ if (!isPathInsideOrEqual(path, sourceRoot)) {+ return false;+ }++ const relativePath = relative(sourceRoot, path);++ return !relativePath.split(/[\\/]/).includes("node_modules");+}++export function isPathInsideOrEqual(path: string, directory: string): boolean {+ const resolvedPath = resolve(path);+ const resolvedDirectory = resolve(directory);++ return (+ resolvedPath === resolvedDirectory || resolvedPath.startsWith(`${resolvedDirectory}${sep}`)+ );+}++async function resolveLocalTsConfigPathTargetRoot(input: {+ readonly baseDirectory: string;+ readonly sourceRoot: string;+ readonly target: string;+}): Promise<string | undefined> {+ const hasWildcard = input.target.includes("*");+ const targetPrefix = hasWildcard+ ? input.target.slice(0, input.target.indexOf("*"))+ : input.target;++ if (targetPrefix.length === 0 || targetPrefix === "." || targetPrefix === "./") {+ return undefined;+ }++ const resolvedTarget = resolve(input.baseDirectory, targetPrefix);++ if (!isAuthoredSourcePath(resolvedTarget, input.sourceRoot)) {+ return undefined;+ }++ const existingTarget = await resolveExistingPathOrAncestor({+ path: resolvedTarget,+ stopDirectory: input.sourceRoot,+ });++ if (existingTarget === undefined) {+ return undefined;+ }++ const packageRoot = await resolveNearestPackageRoot(existingTarget, input.sourceRoot);++ if (packageRoot !== undefined && packageRoot !== input.sourceRoot) {+ return packageRoot;+ }++ if (hasWildcard) {+ return undefined;+ }++ return existingTarget === input.sourceRoot ? undefined : existingTarget;+}++async function resolveExistingPathOrAncestor(input: {+ readonly path: string;+ readonly stopDirectory: string;+}): Promise<string | undefined> {+ let currentPath = resolve(input.path);++ while (isAuthoredSourcePath(currentPath, input.stopDirectory)) {+ if (existsSync(currentPath)) {+ return currentPath;+ }++ const parentPath = dirname(currentPath);++ if (parentPath === currentPath) {+ return undefined;+ }++ currentPath = parentPath;+ }++ return undefined;+}++function isObjectRecord(value: unknown): value is Record<string, unknown> {+ return value !== null && typeof value === "object" && !Array.isArray(value);+}diff --git a/packages/eve/src/internal/nitro/dev-runtime-source-snapshot.ts b/packages/eve/src/internal/nitro/dev-runtime-source-snapshot.tsindex 2421563fb..7ae3944c9 100644--- a/packages/eve/src/internal/nitro/dev-runtime-source-snapshot.ts+++ b/packages/eve/src/internal/nitro/dev-runtime-source-snapshot.ts@@ -1,12 +1,19 @@import { existsSync, readFileSync } from "node:fs";import { lstat, readlink, realpath } from "node:fs/promises";-import { dirname, join, relative, resolve, sep } from "node:path";+import { dirname, join, relative, resolve } from "node:path";import {- parseTsConfigObject,readTextFileIfExists,resolveTsConfigDependencyPaths,} from "#internal/application/tsconfig-dependencies.js";+import {+ isAuthoredSourcePath,+ isPathInsideOrEqual,+ resolveLocalTsConfigPathTargetRoots,+ resolveNearestPackageRoot,+} from "#internal/nitro/dev-runtime-source-snapshot-local-roots.js";++export { isAuthoredSourcePath } from "#internal/nitro/dev-runtime-source-snapshot-local-roots.js";export const DEV_RUNTIME_SOURCE_DIRECTORY = "source";@@ -49,6 +56,12 @@ export interface DevelopmentSourceSnapshotPlan {}export interface DevelopmentSourceSnapshotDependencyMount {+ /**+ * Whether the mount target is copied into the snapshot. Copied mounts link+ * to the in-snapshot copy; all other mounts link to the real source path so+ * installed and workspace dependency code resolves in place.+ */+ readonly copied: boolean;readonly mountPath: string;readonly sourceKind: "installed" | "workspace";readonly sourcePath: string;@@ -56,9 +69,12 @@ export interface DevelopmentSourceSnapshotDependencyMount {interface SnapshotPlanState {readonly appRoot: string;+ readonly authoredLocalRoots: Set<string>;readonly copyFiles: Set<string>;- readonly copyRoots: Set<string>;- readonly dependencyMountsByPath: Map<string, DevelopmentSourceSnapshotDependencyMount>;+ readonly dependencyMountsByPath: Map<+ string,+ Omit<DevelopmentSourceSnapshotDependencyMount, "copied">+ >;readonly localRootsToProcess: string[];readonly processedLocalRoots: Set<string>;readonly snapshotRoot: string;@@ -69,6 +85,13 @@ interface SnapshotPlanState {export async function createDevelopmentSourceSnapshotPlan(input: {readonly appRoot: string;+ /**+ * Workspace roots that host runtime-hydrated authored source (extension+ * mount roots from the compiled manifest). They are copied into the+ * snapshot like the app root; every other workspace dependency package is+ * mounted in place instead of copied.+ */+ readonly authoredSourceRoots?: readonly string[];readonly snapshotRoot: string;}): Promise<DevelopmentSourceSnapshotPlan> {const appRoot = resolve(input.appRoot);@@ -77,8 +100,8 @@ export async function createDevelopmentSourceSnapshotPlan(input: {const snapshotSourceRoot = join(snapshotRoot, DEV_RUNTIME_SOURCE_DIRECTORY);const state: SnapshotPlanState = {appRoot,+ authoredLocalRoots: new Set([appRoot]),copyFiles: new Set(),- copyRoots: new Set(),dependencyMountsByPath: new Map(),localRootsToProcess: [appRoot],processedLocalRoots: new Set(),@@ -89,6 +112,7 @@ export async function createDevelopmentSourceSnapshotPlan(input: {};addWorkspaceMetadataFiles(state);+ await addAuthoredSourceRoots(state, input.authoredSourceRoots ?? []);while (state.localRootsToProcess.length > 0) {const localRoot = state.localRootsToProcess.shift();@@ -107,22 +131,31 @@ export async function createDevelopmentSourceSnapshotPlan(input: {}state.processedLocalRoots.add(resolvedLocalRoot);- state.copyRoots.add(resolvedLocalRoot);await addTsConfigDependenciesForRoot(state, resolvedLocalRoot);await addDependencyMountsForRoot(state, resolvedLocalRoot);}- const copyRoots = normalizeCopyRoots([...state.copyRoots]);+ // Discovery walks every reachable root so the dependency-mount topology and+ // tsconfig collection match a full copy; only the directory copies are+ // narrowed to roots that host runtime-hydrated authored source.+ const copyRoots = normalizeCopyRoots(+ [...state.processedLocalRoots].filter((root) => state.authoredLocalRoots.has(root)),+ );const copyFiles = [...state.copyFiles].filter((path) => isPathInsideOrEqual(path, sourceRoot)).sort((left, right) => left.localeCompare(right));const tsconfigPaths = [...state.tsconfigPaths].filter((path) => isPathInsideOrEqual(path, sourceRoot)).sort((left, right) => left.localeCompare(right));- const dependencyMounts = [...state.dependencyMountsByPath.values()].sort((left, right) =>- left.mountPath.localeCompare(right.mountPath),- );+ const dependencyMounts = [...state.dependencyMountsByPath.values()]+ .map((mount) => ({+ ...mount,+ copied:+ mount.sourceKind === "workspace" &&+ [...state.authoredLocalRoots].some((root) => isPathInsideOrEqual(mount.sourcePath, root)),+ }))+ .sort((left, right) => left.mountPath.localeCompare(right.mountPath));const watchPaths = createWatchPaths({appRoot,copyFiles,@@ -200,6 +233,25 @@ function addWorkspaceMetadataFiles(state: SnapshotPlanState): void {}}+async function addAuthoredSourceRoots(+ state: SnapshotPlanState,+ authoredSourceRoots: readonly string[],+): Promise<void> {+ for (const authoredSourceRoot of authoredSourceRoots) {+ const resolvedRoot = resolve(authoredSourceRoot);++ if (!isAuthoredSourcePath(resolvedRoot, state.sourceRoot)) {+ continue;+ }++ const localRoot =+ (await resolveNearestPackageRoot(resolvedRoot, state.sourceRoot)) ?? resolvedRoot;++ state.authoredLocalRoots.add(localRoot);+ enqueueLocalRoot(state, localRoot);+ }+}+async function addTsConfigDependenciesForRoot(state: SnapshotPlanState,packageRoot: string,@@ -218,6 +270,9 @@ async function addTsConfigDependenciesForRoot(configPath: tsconfigPath,sourceRoot: state.sourceRoot,})) {+ // Path-alias targets host authored source that runtime hydration can+ // read back from the snapshot, so they stay copies.+ state.authoredLocalRoots.add(localRoot);enqueueLocalRoot(state, localRoot);}}@@ -359,6 +414,14 @@ async function addDependencyMount(state: SnapshotPlanState, mountPath: string):});}+/**+ * Workspace dependency packages are mounted in place rather than copied: the+ * dev runtime resolves their contents through the real tree, the same way+ * installed dependencies already resolve (vercel/eve#652). Their dependency+ * closure is still discovered — packages nested inside a copied root keep+ * their mounts — but only roots that host runtime-hydrated authored source+ * (the app, extension mounts, tsconfig path-alias targets) stay copies.+ */async function addWorkspaceDependencyMount(input: {readonly mountPath: string;readonly state: SnapshotPlanState;@@ -450,155 +513,6 @@ async function readPackageDependencyNames(packageRoot: string): Promise<string[]return [...dependencyNames].sort((left, right) => left.localeCompare(right));}-async function resolveLocalTsConfigPathTargetRoots(input: {- readonly configPath: string;- readonly sourceRoot: string;-}): Promise<string[]> {- const source = await readTextFileIfExists(input.configPath);-- if (source === undefined) {- return [];- }-- const parsedConfig = parseTsConfigObject(source);- const compilerOptions = isObjectRecord(parsedConfig?.compilerOptions)- ? parsedConfig.compilerOptions- : undefined;- const paths = isObjectRecord(compilerOptions?.paths) ? compilerOptions.paths : undefined;-- if (compilerOptions === undefined || paths === undefined) {- return [];- }-- const baseDirectory =- typeof compilerOptions.baseUrl === "string"- ? resolve(dirname(input.configPath), compilerOptions.baseUrl)- : dirname(input.configPath);- const localRoots = new Set<string>();-- for (const targets of Object.values(paths)) {- if (!Array.isArray(targets)) {- continue;- }-- for (const target of targets) {- if (typeof target !== "string" || target.length === 0) {- continue;- }-- const localRoot = await resolveLocalTsConfigPathTargetRoot({- baseDirectory,- sourceRoot: input.sourceRoot,- target,- });-- if (localRoot !== undefined) {- localRoots.add(localRoot);- }- }- }-- return [...localRoots].sort((left, right) => left.localeCompare(right));-}--async function resolveLocalTsConfigPathTargetRoot(input: {- readonly baseDirectory: string;- readonly sourceRoot: string;- readonly target: string;-}): Promise<string | undefined> {- const hasWildcard = input.target.includes("*");- const targetPrefix = hasWildcard- ? input.target.slice(0, input.target.indexOf("*"))- : input.target;-- if (targetPrefix.length === 0 || targetPrefix === "." || targetPrefix === "./") {- return undefined;- }-- const resolvedTarget = resolve(input.baseDirectory, targetPrefix);-- if (!isAuthoredSourcePath(resolvedTarget, input.sourceRoot)) {- return undefined;- }-- const existingTarget = await resolveExistingPathOrAncestor({- path: resolvedTarget,- stopDirectory: input.sourceRoot,- });-- if (existingTarget === undefined) {- return undefined;- }-- const packageRoot = await resolveNearestPackageRoot(existingTarget, input.sourceRoot);-- if (packageRoot !== undefined && packageRoot !== input.sourceRoot) {- return packageRoot;- }-- if (hasWildcard) {- return undefined;- }-- return existingTarget === input.sourceRoot ? undefined : existingTarget;-}--async function resolveExistingPathOrAncestor(input: {- readonly path: string;- readonly stopDirectory: string;-}): Promise<string | undefined> {- let currentPath = resolve(input.path);-- while (isAuthoredSourcePath(currentPath, input.stopDirectory)) {- if (existsSync(currentPath)) {- return currentPath;- }-- const parentPath = dirname(currentPath);-- if (parentPath === currentPath) {- return undefined;- }-- currentPath = parentPath;- }-- return undefined;-}--async function resolveNearestPackageRoot(- path: string,- sourceRoot: string,-): Promise<string | undefined> {- let currentDirectory = resolve(path);-- try {- const stats = await lstat(currentDirectory);-- if (!stats.isDirectory()) {- currentDirectory = dirname(currentDirectory);- }- } catch {- currentDirectory = dirname(currentDirectory);- }-- while (isAuthoredSourcePath(currentDirectory, sourceRoot)) {- if (existsSync(join(currentDirectory, "package.json"))) {- return currentDirectory;- }-- const parentDirectory = dirname(currentDirectory);-- if (parentDirectory === currentDirectory) {- return undefined;- }-- currentDirectory = parentDirectory;- }-- return undefined;-}-function normalizeCopyRoots(copyRoots: readonly string[]): string[] {const sortedRoots = [...new Set(copyRoots.map((path) => resolve(path)))].sort((left, right) => {const lengthDifference = left.length - right.length;@@ -674,26 +588,6 @@ function toSnapshotPath(input: {return join(input.snapshotSourceRoot, relative(input.sourceRoot, input.sourcePath));}-function isPathInsideOrEqual(path: string, directory: string): boolean {- const resolvedPath = resolve(path);- const resolvedDirectory = resolve(directory);-- return (- resolvedPath === resolvedDirectory || resolvedPath.startsWith(`${resolvedDirectory}${sep}`)- );-}--/** Returns whether a path is authored workspace source rather than installed dependency data. */-export function isAuthoredSourcePath(path: string, sourceRoot: string): boolean {- if (!isPathInsideOrEqual(path, sourceRoot)) {- return false;- }-- const relativePath = relative(sourceRoot, path);-- return !relativePath.split(/[\\/]/).includes("node_modules");-}-function isObjectRecord(value: unknown): value is Record<string, unknown> {return value !== null && typeof value === "object" && !Array.isArray(value);}