The Open Framework for Building Agents
fix(eve): read repository-style Vercel links (#2010)
OwenKephart9a077549762c
diff --git a/.changeset/fix-repository-style-vercel-links.md b/.changeset/fix-repository-style-vercel-links.mdnew file mode 100644index 000000000..22e40da04--- /dev/null+++ b/.changeset/fix-repository-style-vercel-links.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Recognize repository-style Vercel link metadata during guided setup, so Vercel Connect integrations can continue after Vercel CLI links a repository-backed project.diff --git a/packages/eve/src/internal/vercel/project-link.test.ts b/packages/eve/src/internal/vercel/project-link.test.tsnew file mode 100644index 000000000..3ef3be3bf--- /dev/null+++ b/packages/eve/src/internal/vercel/project-link.test.ts@@ -0,0 +1,73 @@+import { readFile } from "node:fs/promises";++import { afterEach, describe, expect, it, vi } from "vitest";++import { readVercelProjectLink } from "./project-link.js";++vi.mock("node:fs/promises", () => ({ readFile: vi.fn() }));++const mockedReadFile = vi.mocked(readFile);++afterEach(() => {+ mockedReadFile.mockReset();+});++describe("readVercelProjectLink", () => {+ it("reads the matching repository-style link metadata", async () => {+ mockedReadFile+ .mockRejectedValueOnce(new Error("ENOENT"))+ .mockRejectedValueOnce(new Error("ENOENT"))+ .mockRejectedValueOnce(new Error("ENOENT"))+ .mockResolvedValueOnce(+ JSON.stringify({+ projects: [+ { directory: "apps/other", id: "prj_other", name: "other", orgId: "team_other" },+ { directory: "apps/agent", id: "prj_agent", name: "agent", orgId: "team_agent" },+ ],+ remoteName: "origin",+ }),+ );++ await expect(readVercelProjectLink("/repo/apps/agent")).resolves.toEqual({+ orgId: "team_agent",+ projectId: "prj_agent",+ projectName: "agent",+ });+ expect(mockedReadFile).toHaveBeenNthCalledWith(+ 1,+ "/repo/apps/agent/.vercel/project.json",+ "utf8",+ );+ expect(mockedReadFile).toHaveBeenNthCalledWith(2, "/repo/apps/agent/.vercel/repo.json", "utf8");+ expect(mockedReadFile).toHaveBeenNthCalledWith(3, "/repo/apps/.vercel/repo.json", "utf8");+ expect(mockedReadFile).toHaveBeenNthCalledWith(4, "/repo/.vercel/repo.json", "utf8");+ });++ it("uses a repo-level owner when the matching project has none", async () => {+ mockedReadFile.mockRejectedValueOnce(new Error("ENOENT")).mockResolvedValueOnce(+ JSON.stringify({+ orgId: "team_repo",+ projects: [{ directory: ".", id: "prj_agent", name: "agent" }],+ remoteName: "origin",+ }),+ );++ await expect(readVercelProjectLink("/agent")).resolves.toEqual({+ orgId: "team_repo",+ projectId: "prj_agent",+ projectName: "agent",+ });+ });++ it("keeps project metadata authoritative when both link formats exist", async () => {+ mockedReadFile.mockResolvedValueOnce(+ JSON.stringify({ orgId: "team_project", projectId: "prj_project" }),+ );++ await expect(readVercelProjectLink("/agent")).resolves.toEqual({+ orgId: "team_project",+ projectId: "prj_project",+ });+ expect(mockedReadFile).toHaveBeenCalledOnce();+ });+});diff --git a/packages/eve/src/internal/vercel/project-link.ts b/packages/eve/src/internal/vercel/project-link.tsindex da1ecd6e5..152ad3234 100644--- a/packages/eve/src/internal/vercel/project-link.ts+++ b/packages/eve/src/internal/vercel/project-link.ts@@ -1,5 +1,5 @@import { readFile } from "node:fs/promises";-import { join } from "node:path";+import { dirname, join, relative } from "node:path";import { z } from "#compiled/zod/index.js";@@ -9,13 +9,54 @@ export const VercelProjectLinkSchema = z.object({projectName: z.string().min(1).optional(),});-/** Validated Vercel owner and project identifiers from `.vercel/project.json`. */+/** Validated Vercel owner and project identifiers from Vercel link metadata. */export type VercelProjectLink = z.infer<typeof VercelProjectLinkSchema>;-/** Reads a validated Vercel project link without mutating local project state. */-export async function readVercelProjectLink(+const VercelRepoProjectSchema = z.object({+ directory: z.string().min(1),+ id: z.string().min(1),+ name: z.string().min(1),+ orgId: z.string().min(1).optional(),+});++const VercelRepoLinkSchema = z.object({+ orgId: z.string().min(1).optional(),+ projects: z.array(VercelRepoProjectSchema),+});++type VercelRepoLink = z.infer<typeof VercelRepoLinkSchema>;++function normalizeDirectory(directory: string): string {+ return directory === "." ? directory : directory.replaceAll("\\", "/").replace(/\/+$/, "");+}++function containsDirectory(directory: string, path: string): boolean {+ return directory === "." || path === directory || path.startsWith(`${directory}/`);+}++function resolveRepoProject(+ repo: VercelRepoLink,+ repoRoot: string,projectPath: string,-): Promise<VercelProjectLink | undefined> {+): VercelProjectLink | undefined {+ const path = normalizeDirectory(relative(repoRoot, projectPath));+ const matches = repo.projects.filter((project) =>+ containsDirectory(normalizeDirectory(project.directory), path),+ );+ const deepestDirectoryLength = Math.max(...matches.map((project) => project.directory.length));+ const deepestMatches = matches.filter(+ (project) => project.directory.length === deepestDirectoryLength,+ );+ const project = deepestMatches.length === 1 ? deepestMatches[0] : undefined;+ if (project === undefined) return undefined;++ const orgId = project.orgId ?? repo.orgId;+ return orgId === undefined+ ? undefined+ : { orgId, projectId: project.id, projectName: project.name };+}++async function readProjectFile(projectPath: string): Promise<VercelProjectLink | undefined> {try {const raw = await readFile(join(projectPath, ".vercel", "project.json"), "utf8");const parsed = VercelProjectLinkSchema.safeParse(JSON.parse(raw));@@ -24,3 +65,32 @@ export async function readVercelProjectLink(return undefined;}}++async function readRepoFile(repoRoot: string): Promise<VercelRepoLink | undefined> {+ try {+ const raw = await readFile(join(repoRoot, ".vercel", "repo.json"), "utf8");+ const parsed = VercelRepoLinkSchema.safeParse(JSON.parse(raw));+ return parsed.success ? parsed.data : undefined;+ } catch {+ return undefined;+ }+}++async function readRepoProjectLink(projectPath: string): Promise<VercelProjectLink | undefined> {+ let repoRoot = projectPath;+ while (true) {+ const repo = await readRepoFile(repoRoot);+ if (repo !== undefined) return resolveRepoProject(repo, repoRoot, projectPath);++ const parent = dirname(repoRoot);+ if (parent === repoRoot) return undefined;+ repoRoot = parent;+ }+}++/** Reads a validated Vercel project link without mutating local project state. */+export async function readVercelProjectLink(+ projectPath: string,+): Promise<VercelProjectLink | undefined> {+ return (await readProjectFile(projectPath)) ?? (await readRepoProjectLink(projectPath));+}diff --git a/packages/eve/src/setup/project-resolution.ts b/packages/eve/src/setup/project-resolution.tsindex fcfcfffd0..c668b9a5c 100644--- a/packages/eve/src/setup/project-resolution.ts+++ b/packages/eve/src/setup/project-resolution.ts@@ -166,7 +166,7 @@ async function fetchVercelName(/*** Resolves a linked project's human-readable name and team for the dashboard- * status bar, from local `.vercel/project.json` plus the Vercel API. A+ * status bar, from local Vercel link metadata plus the Vercel API. A* personal-account project (a non-`team_` org) carries no team, so `teamName`* is absent; the project name falls back to its id if the API call fails.*@@ -220,8 +220,8 @@ export function projectResolutionFromDeployment(deployment: DeploymentInfo): Pro}/**- * Side-effect-free fact gathering after a link: reads `.vercel/project.json`- * to resolve the project. The on-disk link is the single source of truth.+ * Side-effect-free fact gathering after a link: reads local Vercel link+ * metadata to resolve the project. The on-disk link is the single source of truth.*/export async function detectProjectResolution(projectRoot: string,diff --git a/packages/eve/src/setup/slack-connect-lifecycle.ts b/packages/eve/src/setup/slack-connect-lifecycle.tsindex a934969df..b150fa609 100644--- a/packages/eve/src/setup/slack-connect-lifecycle.ts+++ b/packages/eve/src/setup/slack-connect-lifecycle.ts@@ -1,6 +1,3 @@-import { readFile } from "node:fs/promises";-import { join } from "node:path";-import { SLACK_CHANNEL_DEFAULT_ROUTE } from "#setup/scaffold/index.js";import {CONNECT_MUTATION_TIMEOUT_MS,@@ -9,8 +6,6 @@ import {} from "#setup/connect-provisioning.js";import { createPromptCommandOutput, type ChannelSetupLog } from "#setup/cli/index.js";import { captureVercel, runVercel } from "#setup/primitives/run-vercel.js";-import { z } from "zod";-import {parseSlackConnectorDetails,parseSlackConnectors,@@ -23,11 +18,6 @@ import {export const CONNECT_LOOKUP_TIMEOUT_MS = 60_000;-const VercelProjectLinkSchema = z.object({- projectId: z.string().min(1),- orgId: z.string().min(1),-});-/** Connect subprocess operations needed to inventory and remove Slack connectors. */export interface SlackConnectLifecycleDeps {captureVercel: typeof captureVercel;@@ -82,20 +72,6 @@ export async function listSlackConnectors(}}-/** Project and team identifiers from a valid on-disk Vercel link. */-export type VercelProjectLink = z.infer<typeof VercelProjectLinkSchema>;--/** Reads the linked Vercel project and team ids from `.vercel/project.json`. */-export async function readProjectLink(projectRoot: string): Promise<VercelProjectLink | undefined> {- try {- const raw = await readFile(join(projectRoot, ".vercel", "project.json"), "utf8");- const parsed = VercelProjectLinkSchema.safeParse(JSON.parse(raw));- return parsed.success ? parsed.data : undefined;- } catch {- return undefined;- }-}-export type SlackConnectorLookup =| {state: "found";diff --git a/packages/eve/src/setup/slackbot.ts b/packages/eve/src/setup/slackbot.tsindex 296a0b418..0bc34db9f 100644--- a/packages/eve/src/setup/slackbot.ts+++ b/packages/eve/src/setup/slackbot.ts@@ -2,6 +2,7 @@ import { join } from "node:path";import { performance } from "node:perf_hooks";import { setTimeout as sleep } from "node:timers/promises";+import { readProjectLink } from "#setup/project-resolution.js";import { SLACK_CHANNEL_DEFAULT_ROUTE } from "#setup/scaffold/index.js";import {createPromptCommandOutput,@@ -21,7 +22,6 @@ import {CONNECT_LOOKUP_TIMEOUT_MS,fetchSlackWorkspace,findSlackConnector,- readProjectLink,listSlackConnectors,type SlackConnectLifecycleDeps,type SlackConnectorCleanupResult,