An open-source, faster Devin alternative
TypeScript
Fix project binding to use canonical agent
Mohamed Habib42599097a4e6
diff --git a/cli/src/api.ts b/cli/src/api.tsindex db895f51..3bb506e2 100644--- a/cli/src/api.ts+++ b/cli/src/api.ts@@ -28,6 +28,8 @@ export interface ManagedProject {id: string;slug: string;name: string;+ /** The canonical cloud id of the project's primary agent. */+ agentId: string;/*** `single` projects have one current deployment and no environment choice;* `legacy` projects keep Development and Production. Servers that predatediff --git a/cli/src/binding.test.ts b/cli/src/binding.test.tsindex b5417151..79ddd9e9 100644--- a/cli/src/binding.test.ts+++ b/cli/src/binding.test.ts@@ -13,6 +13,7 @@ function project(): ManagedProject {id: "prj_existing",slug: "existing-project",name: "Existing project",+ agentId: "agent-cloud",environmentMode: "legacy",agents: [{ id: "agent-cloud", name: "Hello World" }],environments: [@@ -74,6 +75,37 @@ test("link persists the selected project and later commands reuse its binding",}});+test("project binding uses the canonical primary agent regardless of agent list order", async () => {+ const root = await mkdtemp(resolve(tmpdir(), "opencomputer-binding-"));+ try {+ const initialized = await initializeAgentProject(root);+ const reordered: ManagedProject = {+ ...project(),+ agents: [+ { id: "agent-cloud--summarizer", name: "Summarizer" },+ { id: "agent-cloud", name: "Primary" },+ ],+ };+ const selected = await ensureProjectBinding(+ {+ async projects() {+ return [reordered];+ },+ async createProject() {+ throw new Error("unexpected create");+ },+ },+ { apiUrl: "https://app.opencomputer.dev" },+ initialized.agentRoot,+ { project: reordered.id },+ );++ assert.equal(selected.agentId, "agent-cloud");+ } finally {+ await rm(root, { recursive: true, force: true });+ }+});+test("non-interactive commands direct an unlinked app to link", async () => {const root = await mkdtemp(resolve(tmpdir(), "opencomputer-binding-"));try {@@ -154,6 +186,7 @@ test("--project resolves a project for one command without rewriting the saved bid: "prj_other",slug: "other-project",name: "Other project",+ agentId: "other-agent",environmentMode: "single",agents: [{ id: "other-agent", name: "Other" }],};diff --git a/cli/src/binding.ts b/cli/src/binding.tsindex 1a04852a..e2fdd8ac 100644--- a/cli/src/binding.ts+++ b/cli/src/binding.ts@@ -152,14 +152,16 @@ function bindingFor(config: ResolvedConfig,project: ManagedProject,): ProjectBinding {- const agent = project.agents[0];- if (!agent) throw new Error(`Project ${project.name} has no agent to bind.`);+ const agentId = project.agentId?.trim();+ if (!agentId) {+ throw new Error(`Project ${project.name} has no primary agent to bind.`);+ }return {version: 1,apiUrl: config.apiUrl,projectId: project.id,projectName: project.name,- agentId: agent.id,+ agentId,};}