An open-source, faster Devin alternative
TypeScript
fix: generate working connection controls
Mohamed Habibe4365284bfb9
diff --git a/cli/src/project.test.ts b/cli/src/project.test.tsindex 1f363b49..0aacd444 100644--- a/cli/src/project.test.ts+++ b/cli/src/project.test.ts@@ -11,6 +11,7 @@ import {import { tmpdir } from "node:os";import { resolve } from "node:path";import test from "node:test";+import ts from "typescript";import type { ManagedAgentTemplate } from "./api.js";import {@@ -88,38 +89,44 @@ test("the compiler maps flat source into an OpenCode runtime", async () => {try {await initializeAgentProject(emailTemplate, root);const runtime = await prepareAgent(root);- assert.match(- await readFile(resolve(runtime, "AGENTS.md"), "utf8"),- /Email triage/,+ const runtimeInstructions = await readFile(+ resolve(runtime, "AGENTS.md"),+ "utf8",);+ assert.match(runtimeInstructions, /You are an OpenComputer agent/);+ assert.match(runtimeInstructions, /Never direct users to OpenCode/);+ assert.match(runtimeInstructions, /Email triage/);assert.equal((await stat(resolve(runtime, ".opencode", "tools", "gmail.ts"))).isFile(),true,);- assert.match(- await readFile(- resolve(- runtime,- ".opencode",- "tools",- "opencomputer-connections.ts",- ),- "utf8",- ),- /export const request = tool/,+ const connectionTool = await readFile(+ resolve(runtime, ".opencode", "tools", "opencomputer-connections.ts"),+ "utf8",+ );+ assert.match(connectionTool, /export const request = tool/);+ assert.match(connectionTool, /opencomputer\/fetch/);+ assert.match(connectionTool, /newAccount/);+ assert.equal(connectionTool.includes('base.replace(/\\\/$/, "")'), true);+ const transpiledConnectionTool = ts.transpileModule(connectionTool, {+ compilerOptions: { module: ts.ModuleKind.ESNext },+ reportDiagnostics: true,+ });+ assert.equal(+ transpiledConnectionTool.diagnostics?.length ?? 0,+ 0,+ transpiledConnectionTool.diagnostics+ ?.map((diagnostic) =>+ ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"),+ )+ .join("\n"),);assert.equal((await stat(resolve(runtime, "opencode.json"))).isFile(),true,);- assert.match(- await readFile(resolve(runtime, "AGENTS.md"), "utf8"),- /start with the `gmail_search` tool/,- );- assert.match(- await readFile(resolve(runtime, "AGENTS.md"), "utf8"),- /summary count exactly matches/,- );+ assert.match(runtimeInstructions, /start with the `gmail_search` tool/);+ assert.match(runtimeInstructions, /summary count exactly matches/);assert.equal((await stat(resolve(runtime, "README.md"))).isFile(),true,diff --git a/cli/src/project.ts b/cli/src/project.tsindex 2cc34e74..45075c1a 100644--- a/cli/src/project.ts+++ b/cli/src/project.ts@@ -398,20 +398,29 @@ async function connectionControl(if (!base || !token) {throw new Error("OpenComputer connections are unavailable");}- const response = await fetch(base, {- method,- headers: {- authorization: \`Bearer \${token}\`,- ...(body ? { "content-type": "application/json" } : {}),+ const response = await fetch(+ \`\${base.replace(/\\\/$/, "")}/opencomputer/fetch\`,+ {+ method: "POST",+ headers: {+ authorization: \`Bearer \${token}\`,+ "content-type": "application/json",+ },+ body: JSON.stringify({+ action: method === "GET" ? "list" : "request",+ ...(body && typeof body === "object" ? body : {}),+ }),},- body: body ? JSON.stringify(body) : undefined,- });+ );const result = await response.json() as {error?: { message?: string };+ message?: string;[key: string]: unknown;};if (!response.ok) {- throw new Error(result.error?.message ?? "Connection request failed");+ throw new Error(+ result.error?.message ?? result.message ?? "Connection request failed",+ );}return result;}@@ -427,10 +436,11 @@ export const list = tool({export const request = tool({description:- "Ask the current user to connect an additional account. In a messaging channel OpenComputer privately sends the authorization link to that user; otherwise the result includes the link.",+ "Ask the current user to connect an account. Set newAccount=true when the user asks for another account of the same service. In a messaging channel OpenComputer privately sends the authorization link to that user; otherwise the result includes the link.",args: {service: tool.schema.string(),label: tool.schema.string().optional(),+ newAccount: tool.schema.boolean().optional(),},async execute(args) {return JSON.stringify(await connectionControl("POST", args));@@ -775,7 +785,26 @@ export async function prepareAgent(root: string): Promise<string> {await mkdir(runtime, { recursive: true });await writeFile(resolve(runtime, "AGENTS.md"),- await readFile(resolve(root, "instructions.md"), "utf8"),+ `# OpenComputer runtime identity++You are an OpenComputer agent. OpenCode is an internal execution detail, not+the product or support surface presented to users.++- Identify yourself and your environment as OpenComputer.+- Never direct users to OpenCode commands, settings, websites, repositories,+ issue trackers, or support channels.+- Before saying an external account is unavailable, use the built-in+ OpenComputer connection tools to list or request the required connection.+- When the user asks for another account of the same service, request a new+ account instead of returning the existing default connection.+- If a connection request reports private-message delivery, tell the user to+ check their private messages. If it returns an authorization URL, show it.+- If a connection tool fails, report its exact error. Do not invent alternate+ controls or third-party support instructions.++# Agent instructions++${await readFile(resolve(root, "instructions.md"), "utf8")}`,);const openCodeConfig = resolve(root, "opencode.json");if (await exists(openCodeConfig)) {diff --git a/web/src/managed-agents/Home.tsx b/web/src/managed-agents/Home.tsxindex b67a11da..03e2a4a8 100644--- a/web/src/managed-agents/Home.tsx+++ b/web/src/managed-agents/Home.tsx@@ -119,7 +119,7 @@ Use the OpenComputer CLI and keep the agent as editable source code in this work5. Inspect and tailor the checked-in source: \`opencomputer.toml\`, \`instructions.md\`, \`agent.ts\`, \`tools/\`, \`connections/\`, \`skills/\`, \`workspace/\`, and \`evals/\`.6. Keep the stable \`id\` in \`opencomputer.toml\`; future deployments of this repository must create new versions of that same agent.7. Add and authorize only supported connections. For Gmail, use \`opencomputer tools add gmail\` and \`${cliCommand(origin, 'connect google')}\`. Connect Slack from the deployed agent's Channels tab after deployment.-8. Test the editable agent locally with OpenCode:+8. Test the editable agent locally with the OpenComputer CLI:\`opencomputer session "${firstPrompt.replace(/"/g, '\\"')}"\`9. Make any necessary source changes and test again.10. Commit the agent source, including \`opencomputer.toml\`, to Git.