The Open Framework for Building Agents
fix: polish multi-agent project setup (#2998)
OwenKephart1909295868ee
diff --git a/.changeset/polish-multi-agent-setup.md b/.changeset/polish-multi-agent-setup.mdnew file mode 100644index 000000000..fbf8b773b--- /dev/null+++ b/.changeset/polish-multi-agent-setup.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Fix multi-agent setup flows so `eve init --agents` asks which agent to run, while shared AI Gateway, integration, and deployment setup uses the project root.diff --git a/packages/eve/src/cli/commands/agent-instructions.test.ts b/packages/eve/src/cli/commands/agent-instructions.test.tsindex 64b588ad2..dd69cf5e5 100644--- a/packages/eve/src/cli/commands/agent-instructions.test.ts+++ b/packages/eve/src/cli/commands/agent-instructions.test.ts@@ -65,6 +65,12 @@ describe("initAgentReadySummary", () => {"✓ Model openai/gpt-5.5\n",);});++ it("reports the agents directory for a workspace", () => {+ expect(stripAnsi(initAgentReadySummary(undefined, "/app", { workspace: true }))).toBe(+ "✓ Model openai/gpt-5.6-luna-fast (eve default)\n✓ Agents /app/agents",+ );+ });});describe("initAgentDevHandoff", () => {diff --git a/packages/eve/src/cli/commands/agent-instructions.ts b/packages/eve/src/cli/commands/agent-instructions.tsindex c8a1577c5..f0db4a7bf 100644--- a/packages/eve/src/cli/commands/agent-instructions.ts+++ b/packages/eve/src/cli/commands/agent-instructions.ts@@ -61,13 +61,19 @@ export function initAgentInstructions(): string {}/** Concise scaffold facts printed only when a coding agent launched `eve init`. */-export function initAgentReadySummary(model: string | undefined, projectPath: string): string {+export function initAgentReadySummary(+ model: string | undefined,+ projectPath: string,+ options: { workspace?: boolean } = {},+): string {const selectedModel = model ?? DEFAULT_AGENT_MODEL_ID;const defaultLabel = model === undefined ? pc.dim(" (eve default)") : "";- return [- `${pc.green("✓")} Model ${pc.bold(selectedModel)}${defaultLabel}`,- `${pc.green("✓")} Instructions ${pc.bold(join(projectPath, "agent/instructions.md"))}`,- ].join("\n");+ const authoredFiles = options.workspace+ ? `${pc.green("✓")} Agents ${pc.bold(join(projectPath, "agents"))}`+ : `${pc.green("✓")} Instructions ${pc.bold(join(projectPath, "agent/instructions.md"))}`;+ return [`${pc.green("✓")} Model ${pc.bold(selectedModel)}${defaultLabel}`, authoredFiles].join(+ "\n",+ );}/** The post-scaffold handoff printed after a coding agent runs `eve init`. */diff --git a/packages/eve/src/cli/commands/init.integration.test.ts b/packages/eve/src/cli/commands/init.integration.test.tsindex 916d98f71..9dc158b83 100644--- a/packages/eve/src/cli/commands/init.integration.test.ts+++ b/packages/eve/src/cli/commands/init.integration.test.ts@@ -166,6 +166,13 @@ describe("runInitCommand", () => {await expect(readFile(join(projectRoot, "tsconfig.json"), "utf8")).resolves.toContain('"agents/**/*.ts"',);+ expect(deps.selectInitHandoff).toHaveBeenCalledWith({ agentName: "operations" });+ expect(deps.spawnPackageManager).toHaveBeenCalledWith("pnpm", projectRoot, [+ "exec",+ "eve",+ "dev",+ "--onboard",+ ]);});it("adds only agent files to an existing workspace", async () => {diff --git a/packages/eve/src/cli/commands/init.ts b/packages/eve/src/cli/commands/init.tsindex d29dec928..ec2da0eeb 100644--- a/packages/eve/src/cli/commands/init.ts+++ b/packages/eve/src/cli/commands/init.ts@@ -618,8 +618,9 @@ export async function runInitCommand(}}- const selectedAgentArguments = options.agents?.[0] ? ["--agent", options.agents[0]] : [];- const baseDevArguments = [...eveDevArguments(result.packageManager), ...selectedAgentArguments];+ // A workspace has no implicit primary agent. Let `eve dev` ask the person+ // which member to run, rather than silently selecting the first --agents value.+ const baseDevArguments = eveDevArguments(result.packageManager);const agentDevCommand = [result.packageManager, ...baseDevArguments].join(" ");const agentHandoff = initAgentDevHandoff({projectPath: result.projectPath,@@ -627,7 +628,11 @@ export async function runInitCommand(});if (result.agentLaunched) {- logger.log(initAgentReadySummary(options.model, result.projectPath));+ logger.log(+ initAgentReadySummary(options.model, result.projectPath, {+ workspace: options.agents !== undefined,+ }),+ );logger.log(agentHandoff);return;}@@ -667,11 +672,7 @@ export async function runInitCommand(// the command the way run-scripts do, so the handoff line is printed here.const freshScaffold = result.kind === "created";const devArguments = freshScaffold ? [...baseDevArguments, "--onboard"] : baseDevArguments;- logger.log(- pc.dim(- `$ eve dev${selectedAgentArguments.length > 0 ? ` --agent ${selectedAgentArguments[1]}` : ""}`,- ),- );+ logger.log(pc.dim("$ eve dev"));if (!resultSucceeded(await dependencies.spawnPackageManager(diff --git a/packages/eve/src/cli/commands/register-project-commands.ts b/packages/eve/src/cli/commands/register-project-commands.tsindex 33e89cf9e..6016bf0a4 100644--- a/packages/eve/src/cli/commands/register-project-commands.ts+++ b/packages/eve/src/cli/commands/register-project-commands.ts@@ -1,18 +1,32 @@import type { Command } from "#compiled/commander/index.js";-import { applicationCommand, type CliApplicationContext } from "#cli/application-command.js";+import type { CliApplicationContext } from "#cli/application-command.js";+import { findEveProjectContext } from "#internal/project-context.js";interface ProjectCommandLogger {error(message: string): void;log(message: string): void;}+/**+ * Resolves standalone projects without using application discovery, which+ * deliberately selects an individual agent and cannot represent a workspace+ * root. Workspace members remain unchanged so the command can explain that+ * deployment and linking belong at the workspace root.+ */+function projectCommand(command: Command, applicationContext: CliApplicationContext): Command {+ return command.hook("preAction", async () => {+ const context = await findEveProjectContext(applicationContext.root);+ if (context?.kind === "standalone") applicationContext.root = context.appRoot;+ });+}+/** Registers project-level Vercel commands without eagerly loading their flows. */export function registerProjectCommands(input: {program: Command;logger: ProjectCommandLogger;applicationContext: CliApplicationContext;}): void {- applicationCommand(input.program.command("link"), input.applicationContext)+ projectCommand(input.program.command("link"), input.applicationContext).description("Link this directory to a Vercel project and pull AI Gateway credentials.").option("--non-interactive", "Run without interactive prompts").option("--project <name-or-id>", "Vercel project name or ID")@@ -22,7 +36,7 @@ export function registerProjectCommands(input: {await runLinkCommand(input.logger, input.applicationContext.root, undefined, options);});- applicationCommand(input.program.command("deploy"), input.applicationContext)+ projectCommand(input.program.command("deploy"), input.applicationContext).description("Deploy the agent to Vercel production (links first if needed).").option("--non-interactive", "Run without interactive prompts").option("--project <name-or-id>", "Vercel project name or ID")diff --git a/packages/eve/src/cli/dev/run-interactive-ui.ts b/packages/eve/src/cli/dev/run-interactive-ui.tsindex 7fd943673..b1c92d15e 100644--- a/packages/eve/src/cli/dev/run-interactive-ui.ts+++ b/packages/eve/src/cli/dev/run-interactive-ui.ts@@ -1,6 +1,7 @@import { randomUUID } from "node:crypto";import { devBootPhase, type DevBootProgressReporter } from "#internal/dev-boot-progress.js";+import { findEveProjectContext } from "#internal/project-context.js";import {resumeDevelopmentRuntimeArtifacts,suspendDevelopmentRuntimeArtifacts,@@ -29,18 +30,15 @@ export async function runInteractiveDevelopmentUi(input: {async () => input.runDevelopmentTui ?? (await import("#cli/dev/tui/tui.js")).runDevelopmentTui,input.report,);+ const applicationRoot = input.server.appRoot ?? input.applicationRoot;+ const projectContext = await findEveProjectContext(applicationRoot);+ const workspaceRoot = projectContext?.environmentRoot ?? applicationRoot;+ const agentRoot =+ projectContext?.kind === "workspace-member" ? projectContext.member.appRoot : undefined;const target =input.remoteTarget === undefined || input.existingLocalServer- ? {- kind: "local" as const,- serverUrl: input.server.serverUrl,- workspaceRoot: input.server.appRoot ?? input.applicationRoot,- }- : {- kind: "remote" as const,- serverUrl: input.server.serverUrl,- workspaceRoot: input.applicationRoot,- };+ ? { kind: "local" as const, serverUrl: input.server.serverUrl, workspaceRoot, agentRoot }+ : { kind: "remote" as const, serverUrl: input.server.serverUrl, workspaceRoot, agentRoot };const display = resolveTuiDisplayOptions(input.options);const name = resolveTuiTitle({ name: input.options.name, target });if (name !== undefined) display.name = name;diff --git a/packages/eve/src/cli/dev/tui/prompt-command-handler.ts b/packages/eve/src/cli/dev/tui/prompt-command-handler.tsindex 0164fe01e..65298ddf3 100644--- a/packages/eve/src/cli/dev/tui/prompt-command-handler.ts+++ b/packages/eve/src/cli/dev/tui/prompt-command-handler.ts@@ -52,7 +52,7 @@ export function createPromptCommandHandler("/model needs eve dev running the local server (it is not available with --url).",};}- const appRoot = target.workspaceRoot;+ const appRoot = target.agentRoot ?? target.workspaceRoot;// Package-loading failures are command outcomes at this CLI boundary.try {const { modelChangeRefusalForUneditableModel } = await import("#setup/flows/model.js");@@ -120,6 +120,7 @@ export function createPromptCommandHandler(withExclusiveTerminal: context.withExclusiveTerminal,chatGptAccountLabel: context.chatGptAccountLabel,};+ if (target.agentRoot !== undefined) commandInput.agentRoot = target.agentRoot;if (context.initialModelStep !== undefined) {commandInput.initialModelStep = context.initialModelStep;}diff --git a/packages/eve/src/cli/dev/tui/setup-commands.test.ts b/packages/eve/src/cli/dev/tui/setup-commands.test.tsindex ac06434f4..b247fdcf3 100644--- a/packages/eve/src/cli/dev/tui/setup-commands.test.ts+++ b/packages/eve/src/cli/dev/tui/setup-commands.test.ts@@ -81,6 +81,7 @@ function run(input: {flows: TuiSetupFlows;renderer?: TuiSetupCommandRenderer;initialModelStep?: "provider";+ agentRoot?: string;useDefaultPrompter?: boolean;upgradeChoice?: "upgrade" | "later";withExclusiveTerminal?: TuiSetupCommandInput["withExclusiveTerminal"];@@ -95,6 +96,7 @@ function run(input: {renderer: input.renderer ?? fakePanelRenderer(),flows: input.flows,};+ if (input.agentRoot !== undefined) commandInput.agentRoot = input.agentRoot;if (input.useDefaultPrompter !== true) commandInput.createPrompter = () => fake.prompter;if (input.initialModelStep !== undefined) {commandInput.initialModelStep = input.initialModelStep;@@ -207,6 +209,23 @@ describe("runTuiSetupCommand", () => {);});+ it("edits the selected workspace agent while configuring project-level provider access", async () => {+ const flows = fakeFlows();++ await run({+ command: "model",+ flows,+ agentRoot: "/tmp/project/agents/researcher",+ });++ expect(flows.runModelFlow).toHaveBeenCalledWith(+ expect.objectContaining({+ appRoot: "/tmp/project/agents/researcher",+ environmentRoot: APP_ROOT,+ }),+ );+ });+it("does not rebuild model access after a rejected edit", async () => {const flows = fakeFlows({runModelFlow: vi.fn<TuiSetupFlows["runModelFlow"]>(async () => ({diff --git a/packages/eve/src/cli/dev/tui/setup-commands.ts b/packages/eve/src/cli/dev/tui/setup-commands.tsindex f680e9983..f46d48d1b 100644--- a/packages/eve/src/cli/dev/tui/setup-commands.ts+++ b/packages/eve/src/cli/dev/tui/setup-commands.ts@@ -53,8 +53,10 @@ type MuteableSetupRenderer = TuiPrompterRenderer &export interface TuiSetupCommandInput {command: TuiSetupCommand;- /** The local project the in-process dev server is running. */+ /** Project root for setup that changes shared dependencies, links, or environment files. */appRoot: string;+ /** Selected agent root whose authored settings are changed by `/model`. */+ agentRoot?: string;/** The renderer surface the TUI-native prompter drives. */renderer: TuiSetupCommandRenderer;/** Initial model-flow step authorized by the runner's boot evidence. */@@ -256,7 +258,8 @@ async function executeSetupCommand(case "model": {const pickProvider: ProviderPicker = (request) => renderer.readProviderPicker(request);const modelInput: Parameters<TuiSetupFlows["runModelFlow"]>[0] = {- appRoot,+ appRoot: input.agentRoot ?? appRoot,+ environmentRoot: appRoot,prompter,signal,chatGptAccountLabel: input.chatGptAccountLabel,diff --git a/packages/eve/src/cli/run.test.ts b/packages/eve/src/cli/run.test.tsindex c6ffbbbe2..33663ab91 100644--- a/packages/eve/src/cli/run.test.ts+++ b/packages/eve/src/cli/run.test.ts@@ -11,7 +11,8 @@ function resolvedProject(appRoot: string) {return { agentRoot: `${appRoot}/agent`, appRoot, layout: "nested" as const };}-const { runInitCommand, runSetCommand } = vi.hoisted(() => ({+const { runDeployCommand, runInitCommand, runSetCommand } = vi.hoisted(() => ({+ runDeployCommand: vi.fn(async () => {}),runInitCommand: vi.fn(async () => {}),runSetCommand: vi.fn(async () => {}),}));@@ -20,6 +21,7 @@ vi.mock("#cli/application-root.js", () => ({findCliApplicationRoot: vi.fn(async () => undefined),resolveCliApplicationProject: vi.fn(async (cwd: string) => resolvedProject(cwd)),}));+vi.mock("#cli/commands/deploy.js", () => ({ runDeployCommand }));vi.mock("#cli/commands/init.js", () => ({ runInitCommand }));vi.mock("#cli/commands/set.js", () => ({ runSetCommand }));vi.mock("#internal/project-context.js", () => ({@@ -93,6 +95,24 @@ describe("CLI command registration", () => {});});+ it("runs deploy from a workspace root without application discovery", async () => {+ const logger = { error: vi.fn(), log: vi.fn() };+ const resolveProject = vi.fn(async () => {+ throw new Error("application discovery must not run for a workspace root");+ });+ runDeployCommand.mockClear();++ await runCli(["deploy"], logger, { resolveApplicationProject: resolveProject });++ expect(resolveProject).not.toHaveBeenCalled();+ expect(runDeployCommand).toHaveBeenCalledWith(logger, resolve(process.cwd()), undefined, {+ nonInteractive: undefined,+ project: undefined,+ team: undefined,+ yes: undefined,+ });+ });+it("runs project commands with the resolved application root", async () => {const logger = { error: vi.fn(), log: vi.fn() };const resolveProject = vi.fn(async () => resolvedProject("/workspace/weather"));diff --git a/packages/eve/src/services/dev-client/target.ts b/packages/eve/src/services/dev-client/target.tsindex e57c81150..1a122ae80 100644--- a/packages/eve/src/services/dev-client/target.ts+++ b/packages/eve/src/services/dev-client/target.ts@@ -1,8 +1,10 @@/** Server target used by development clients. */interface DevelopmentTargetBase {readonly serverUrl: string;- /** Local workspace root for app files and the fallback Vercel project link. */+ /** Project root for shared dependencies, Vercel links, and environment files. */readonly workspaceRoot: string;+ /** The selected agent's root when it is a member of a multi-agent project. */+ readonly agentRoot?: string;}/** A development client backed by a local `eve dev` server. */diff --git a/packages/eve/src/setup/flows/model.ts b/packages/eve/src/setup/flows/model.tsindex 02881b859..689690ce2 100644--- a/packages/eve/src/setup/flows/model.ts+++ b/packages/eve/src/setup/flows/model.ts@@ -282,7 +282,10 @@ function modelMenuRows(* external-provider instructions return to the menu.*/export async function runModelFlow(input: {+ /** Selected agent root whose authored model settings are edited. */appRoot: string;+ /** Project root for shared provider configuration and Vercel credentials. */+ environmentRoot?: string;prompter: Prompter;/** Opens provider setup before the root menu when runtime evidence requires it. */initialStep?: "provider";@@ -294,6 +297,7 @@ export async function runModelFlow(input: {deps?: Partial<ModelFlowDeps>;}): Promise<ModelFlowResult> {const { appRoot, prompter, signal } = input;+ const environmentRoot = input.environmentRoot ?? appRoot;const deps: ModelFlowDeps = {readCurrentModel: readCurrentAgentModel,applySettings: changeAgentModelSettings,@@ -316,10 +320,10 @@ export async function runModelFlow(input: {Promise.all([deps.readCurrentModel(appRoot),deps.resolveAvailableProviders(- appRoot,+ environmentRoot,signal === undefined ? { env: process.env } : { signal, env: process.env },),- deps.readProviderSelection(appRoot),+ deps.readProviderSelection(environmentRoot),fetchCatalog(signal).catch((): GatewayCatalogModel[] | undefined => undefined),]),);@@ -457,7 +461,7 @@ export async function runModelFlow(input: {}const result = await deps.runProviderFlow({- appRoot,+ appRoot: environmentRoot,prompter,signal,availableProviders,@@ -506,7 +510,7 @@ export async function runModelFlow(input: {lastApply = await deps.applySettings({ appRoot, patch });}if (commitDraft && nextProviderSelection !== undefined && lastApply?.kind !== "rejected") {- await deps.writeProviderSelection(appRoot, nextProviderSelection);+ await deps.writeProviderSelection(environmentRoot, nextProviderSelection);committedProviderSelection = nextProviderSelection;}if (lastApply !== undefined && committedProviderSelection === undefined) {diff --git a/scripts/repro-multi-agent-init.mjs b/scripts/repro-multi-agent-init.mjsnew file mode 100644index 000000000..41fd73f0e--- /dev/null+++ b/scripts/repro-multi-agent-init.mjs@@ -0,0 +1,64 @@+#!/usr/bin/env node++import { spawn } from "node:child_process";+import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";+import { tmpdir } from "node:os";+import { dirname, join, resolve } from "node:path";+import { fileURLToPath } from "node:url";++const repositoryRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");+const evePackageRoot = join(repositoryRoot, "packages", "eve");+const projectName = process.argv[2] ?? "my-project";++if (process.argv.length > 3 || projectName.startsWith("-")) {+ console.error("Usage: node scripts/repro-multi-agent-init.mjs [project-name]");+ process.exitCode = 1;+} else {+ const packageJson = JSON.parse(await readFile(join(evePackageRoot, "package.json"), "utf8"));+ const packageVersion = packageJson.version;+ if (typeof packageVersion !== "string")+ throw new Error("packages/eve/package.json has no version.");++ const tempRoot = await mkdtemp(join(tmpdir(), "eve-multi-agent-init-"));+ const packDirectory = await mkdtemp(join(tmpdir(), "eve-multi-agent-pack-"));+ const homeDirectory = await mkdtemp(join(tmpdir(), "eve-multi-agent-home-"));+ const target = join(tempRoot, projectName);+ await writeFile(join(homeDirectory, ".npmrc"), "registry=https://registry.npmjs.org/\n");++ try {+ await run("pnpm", ["pack", "--pack-destination", packDirectory], { cwd: evePackageRoot });+ const environment = {+ ...process.env,+ EVE_INIT_PACKAGE_SPEC: `file:${join(packDirectory, `eve-${packageVersion}.tgz`)}`,+ HOME: homeDirectory,+ npm_config_globalconfig: "/dev/null",+ npm_config_registry: "https://registry.npmjs.org",+ npm_config_userconfig: join(homeDirectory, ".npmrc"),+ };+ await run(+ process.execPath,+ [join(evePackageRoot, "bin", "eve.js"), "init", target, "--agents", "researcher,bug-finder"],+ {+ cwd: tempRoot,+ env: environment,+ },+ );+ console.log(`\nCreated test workspace: ${target}`);+ } finally {+ await Promise.all([+ rm(packDirectory, { force: true, recursive: true }),+ rm(homeDirectory, { force: true, recursive: true }),+ ]);+ }+}++function run(command, args, options) {+ return new Promise((resolvePromise, reject) => {+ const child = spawn(command, args, { ...options, stdio: "inherit" });+ child.once("error", reject);+ child.once("exit", (code, signal) => {+ if (code === 0) return resolvePromise();+ reject(new Error(`${command} ${args.join(" ")} exited with ${signal ?? `code ${code}`}.`));+ });+ });+}