Skip to content

An open-source, faster Devin alternative

TypeScript

Fix CLI managed GitHub App connection flow (#771)

Mohamed Habib1ed52b543b71
diff --git a/cli/package-lock.json b/cli/package-lock.json
index 05390149..0fb16ce6 100644
--- a/cli/package-lock.json
+++ b/cli/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@opencomputer/cli",
- "version": "0.7.9",
+ "version": "0.7.10",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@opencomputer/cli",
- "version": "0.7.9",
+ "version": "0.7.10",
"dependencies": {
"@opencode-ai/sdk": "1.18.4",
"ai": "^7.0.45",
diff --git a/cli/package.json b/cli/package.json
index 6d07f9e3..ca0ac6cb 100644
--- a/cli/package.json
+++ b/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@opencomputer/cli",
- "version": "0.7.9",
+ "version": "0.7.10",
"description": "Build, test, deploy, and share OpenComputer agents as code.",
"type": "module",
"bin": {
diff --git a/cli/src/api.test.ts b/cli/src/api.test.ts
index 86418fe0..a0b502d5 100644
--- a/cli/src/api.test.ts
+++ b/cli/src/api.test.ts
@@ -134,6 +134,63 @@ test("memory precondition failures surface the API's code", async (context) => {
);
});
+test("managed GitHub App requests use project-scoped status and connect routes", async (context) => {
+ const requests: Request[] = [];
+ context.mock.method(
+ globalThis,
+ "fetch",
+ async (input: string | URL | Request, init?: RequestInit) => {
+ const request = new Request(input, init);
+ requests.push(request);
+ if (request.method === "POST") {
+ return Response.json({
+ installUrl: "https://github.com/apps/opencomputer/installations/new",
+ authorizeUrl: "https://github.com/login/oauth/authorize",
+ });
+ }
+ return Response.json({ environments: [], connections: [], app: null });
+ },
+ );
+ const client = new OpenComputerClient({
+ apiUrl: "https://app.opencomputer.dev",
+ apiKey: "test",
+ });
+
+ await client.githubStatus("project/one");
+ await client.connectGitHub({
+ projectId: "project/one",
+ environments: ["development", "production"],
+ });
+ await client.attachGitHub({
+ projectId: "project/one",
+ environment: "production",
+ connectionId: "ghi_one",
+ });
+
+ assert.equal(
+ requests[0]?.url,
+ "https://app.opencomputer.dev/api/managed-agents/projects/project%2Fone/github",
+ );
+ assert.equal(requests[0]?.method, "GET");
+ assert.equal(
+ requests[1]?.url,
+ "https://app.opencomputer.dev/api/managed-agents/projects/project%2Fone/github/connect",
+ );
+ assert.equal(requests[1]?.method, "POST");
+ assert.deepEqual(await requests[1]?.json(), {
+ environments: ["development", "production"],
+ });
+ assert.equal(
+ requests[2]?.url,
+ "https://app.opencomputer.dev/api/managed-agents/projects/project%2Fone/github/attach",
+ );
+ assert.equal(requests[2]?.method, "POST");
+ assert.deepEqual(await requests[2]?.json(), {
+ environment: "production",
+ connectionId: "ghi_one",
+ });
+});
+
test("model connections and routes use write-only connection input and project route endpoints", async (context) => {
const requests: Request[] = [];
context.mock.method(
diff --git a/cli/src/api.ts b/cli/src/api.ts
index 60b3c42c..e4e6e1e4 100644
--- a/cli/src/api.ts
+++ b/cli/src/api.ts
@@ -72,21 +72,24 @@ export interface ManagedSecretMetadata {
updatedAt: string;
}
+export interface ManagedGitHubInstallation {
+ id: string;
+ githubInstallationId: number;
+ accountLogin: string;
+ accountType: string;
+ repositorySelection: "all" | "selected";
+ state: "active" | "suspended" | "deleted";
+ createdAt: string;
+ updatedAt: string;
+}
+
export interface ManagedGitHubStatus {
environments: Array<{
environment: "development" | "production";
state: "not_connected" | "active" | "suspended" | "deleted";
- installation?: {
- id: string;
- githubInstallationId: number;
- accountLogin: string;
- accountType: string;
- repositorySelection: "all" | "selected";
- state: "active" | "suspended" | "deleted";
- createdAt: string;
- updatedAt: string;
- };
+ installation?: ManagedGitHubInstallation;
}>;
+ connections: ManagedGitHubInstallation[];
app: { slug: string } | null;
}
@@ -581,6 +584,23 @@ export class OpenComputerClient {
);
}
+ attachGitHub(input: {
+ projectId: string;
+ environment: "development" | "production";
+ connectionId: string;
+ }) {
+ return this.request<{ attached: boolean }>(
+ `/api/managed-agents/projects/${encodeURIComponent(input.projectId)}/github/attach`,
+ {
+ method: "POST",
+ body: JSON.stringify({
+ environment: input.environment,
+ connectionId: input.connectionId,
+ }),
+ },
+ );
+ }
+
disconnectGitHub(input: {
projectId: string;
environment: "development" | "production";
diff --git a/cli/src/commands.test.ts b/cli/src/commands.test.ts
index f662b2cb..6142bbdc 100644
--- a/cli/src/commands.test.ts
+++ b/cli/src/commands.test.ts
@@ -3,8 +3,13 @@ import test from "node:test";
import {
deploymentAlias,
+ githubEnvironments,
+ githubEnvironmentsConnected,
nextAgentEventDeadline,
+ selectGitHubInstallation,
+ SERVICE_CONNECTIONS,
shouldBindModelAccessProject,
+ validateGitHubConnectionChoice,
} from "./commands.js";
test("agent event progress refreshes the inactivity deadline", () => {
@@ -26,3 +31,76 @@ test("model access binds the explicit or current linked project", () => {
);
assert.equal(shouldBindModelAccessProject(undefined, null), false);
});
+
+test("managed service connections exclude the dedicated GitHub App flow", () => {
+ assert.equal(SERVICE_CONNECTIONS.includes("linear"), true);
+ assert.equal(
+ (SERVICE_CONNECTIONS as readonly string[]).includes("github"),
+ false,
+ );
+});
+
+test("GitHub App connections target both environments unless one is explicit", () => {
+ assert.deepEqual(githubEnvironments(), ["development", "production"]);
+ assert.deepEqual(githubEnvironments("production"), ["production"]);
+ assert.throws(
+ () => githubEnvironments("staging"),
+ /development or production/,
+ );
+});
+
+test("GitHub App connection readiness requires every requested environment", () => {
+ const status = {
+ environments: [
+ { environment: "development" as const, state: "active" as const },
+ { environment: "production" as const, state: "not_connected" as const },
+ ],
+ connections: [],
+ app: { slug: "opencomputer" },
+ };
+ assert.equal(githubEnvironmentsConnected(status, ["development"]), true);
+ assert.equal(
+ githubEnvironmentsConnected(status, ["development", "production"]),
+ false,
+ );
+});
+
+test("GitHub App connection selection reuses one active account and disambiguates many", () => {
+ const installation = (id: string, accountLogin: string) => ({
+ id,
+ githubInstallationId: 1,
+ accountLogin,
+ accountType: "Organization",
+ repositorySelection: "selected" as const,
+ state: "active" as const,
+ createdAt: "2026-09-24T00:00:00.000Z",
+ updatedAt: "2026-09-24T00:00:00.000Z",
+ });
+ const digger = installation("ghi_digger", "diggerhq");
+ const personal = installation("ghi_personal", "mohamed");
+
+ assert.equal(selectGitHubInstallation([digger]), digger);
+ assert.equal(
+ selectGitHubInstallation([digger, personal], "diggerhq"),
+ digger,
+ );
+ assert.throws(
+ () => selectGitHubInstallation([digger, personal]),
+ /--connection/,
+ );
+ assert.equal(
+ selectGitHubInstallation([{ ...digger, state: "suspended" }]),
+ undefined,
+ );
+});
+
+test("a fresh GitHub App install cannot also select an existing connection", () => {
+ assert.doesNotThrow(() => validateGitHubConnectionChoice(true));
+ assert.doesNotThrow(() =>
+ validateGitHubConnectionChoice(false, "diggerhq"),
+ );
+ assert.throws(
+ () => validateGitHubConnectionChoice(true, "diggerhq"),
+ /either --new or --connection/,
+ );
+});
diff --git a/cli/src/commands.ts b/cli/src/commands.ts
index 47041ede..b4ea512b 100644
--- a/cli/src/commands.ts
+++ b/cli/src/commands.ts
@@ -2,6 +2,8 @@ import {
OpenComputerClient,
type ManagedAgentEvent,
type ManagedAgentLog,
+ type ManagedGitHubInstallation,
+ type ManagedGitHubStatus,
type ManagedSessionSnapshot,
type ManagedSessionSummary,
type MemoryBindings,
@@ -80,6 +82,72 @@ export function shouldBindModelAccessProject(
return Boolean(projectReference || currentAgentRoot);
}
+export const SERVICE_CONNECTIONS = [
+ "gmail",
+ "calendar",
+ "drive",
+ "sheets",
+ "linear",
+] as const;
+
+export function githubEnvironments(
+ value?: string,
+): Array<"development" | "production"> {
+ return value ? [environmentOption(value)] : ["development", "production"];
+}
+
+export function githubEnvironmentsConnected(
+ status: ManagedGitHubStatus,
+ environments: Array<"development" | "production">,
+): boolean {
+ return environments.every((environment) =>
+ status.environments.some(
+ (entry) => entry.environment === environment && entry.state === "active",
+ ),
+ );
+}
+
+export function selectGitHubInstallation(
+ connections: ManagedGitHubInstallation[],
+ selector?: string,
+): ManagedGitHubInstallation | undefined {
+ const active = connections.filter((connection) => connection.state === "active");
+ if (selector) {
+ const matches = active.filter(
+ (connection) =>
+ connection.id === selector || connection.accountLogin === selector,
+ );
+ if (matches.length === 1) return matches[0];
+ if (!matches.length) {
+ throw new Error(
+ `No active GitHub App connection matches ${JSON.stringify(selector)}.`,
+ );
+ }
+ throw new Error(
+ `More than one GitHub App connection belongs to @${selector}; use its connection id.`,
+ );
+ }
+ if (active.length === 1) return active[0];
+ if (active.length > 1) {
+ throw new Error(
+ "More than one GitHub App connection is available. Pass --connection <id|account>.\n" +
+ active
+ .map((connection) => ` ${connection.id} @${connection.accountLogin}`)
+ .join("\n"),
+ );
+ }
+ return undefined;
+}
+
+export function validateGitHubConnectionChoice(
+ forceNew: boolean,
+ connectionSelector?: string,
+): void {
+ if (forceNew && connectionSelector) {
+ throw new Error("Choose either --new or --connection, not both.");
+ }
+}
+
function printJSON(value: unknown): void {
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
}
@@ -1428,25 +1496,153 @@ export async function runCommand(
return "gmail";
}
+ if (command === "github") {
+ const action = args.shift();
+ const projectReference = option(args, "--project");
+ const project = await selectedProject(client, config, projectReference);
+
+ if (action === "status" || action === undefined) {
+ if (args.length) throw new Error(`Unexpected argument: ${args[0]}`);
+ const status = await client.githubStatus(project.projectId);
+ if (globals.json) {
+ printJSON(status);
+ return;
+ }
+ for (const entry of status.environments) {
+ const installation = entry.installation;
+ process.stdout.write(
+ `${entry.environment.padEnd(12)} ${entry.state.padEnd(14)}` +
+ (installation
+ ? ` @${installation.accountLogin} (${installation.repositorySelection} repositories)`
+ : "") +
+ "\n",
+ );
+ }
+ if (
+ status.environments.every((entry) => entry.state === "not_connected")
+ ) {
+ process.stdout.write(
+ "Connect the managed GitHub App with `opencomputer github connect`.\n",
+ );
+ }
+ return;
+ }
+
+ if (action === "connect") {
+ const environments = githubEnvironments(option(args, "--environment"));
+ const connectionSelector = option(args, "--connection");
+ const forceNew = flag(args, "--new");
+ const noWait = flag(args, "--no-wait");
+ if (args.length) throw new Error(`Unexpected argument: ${args[0]}`);
+ validateGitHubConnectionChoice(forceNew, connectionSelector);
+
+ const current = await client.githubStatus(project.projectId);
+ if (!forceNew && githubEnvironmentsConnected(current, environments)) {
+ if (globals.json) printJSON(current);
+ else {
+ process.stdout.write(
+ `The managed GitHub App is already connected for ${environments.join(" and ")}.\n`,
+ );
+ }
+ return;
+ }
+
+ const installation = forceNew
+ ? undefined
+ : selectGitHubInstallation(current.connections, connectionSelector);
+ if (installation) {
+ const missing = environments.filter(
+ (environment) =>
+ !current.environments.some(
+ (entry) =>
+ entry.environment === environment && entry.state === "active",
+ ),
+ );
+ for (const environment of missing) {
+ await client.attachGitHub({
+ projectId: project.projectId,
+ environment,
+ connectionId: installation.id,
+ });
+ }
+ const attached = await client.githubStatus(project.projectId);
+ if (globals.json) printJSON(attached);
+ else {
+ process.stdout.write(
+ `Attached @${installation.accountLogin} to ${missing.join(" and ")}.\n`,
+ );
+ }
+ return;
+ }
+
+ const result = await client.connectGitHub({
+ projectId: project.projectId,
+ environments,
+ });
+ if (globals.json) {
+ printJSON(result);
+ return;
+ }
+ process.stdout.write(
+ "Install or configure the managed OpenComputer GitHub App by opening:\n\n" +
+ ` ${result.installUrl}\n\n` +
+ `It will be attached to ${environments.join(" and ")} for this project.\n`,
+ );
+ if (noWait) {
+ process.stdout.write(
+ "Run `opencomputer github status` after completing the GitHub flow.\n",
+ );
+ return;
+ }
+
+ const deadline = Date.now() + 10 * 60_000;
+ process.stdout.write("Waiting for GitHub… (Ctrl-C to stop)\n");
+ while (Date.now() < deadline) {
+ await new Promise((resolve) => setTimeout(resolve, 2_000));
+ try {
+ const status = await client.githubStatus(project.projectId);
+ if (githubEnvironmentsConnected(status, environments)) {
+ process.stdout.write(
+ `Connected the managed GitHub App for ${environments.join(" and ")}.\n`,
+ );
+ return;
+ }
+ } catch {
+ // Keep waiting across transient status failures.
+ }
+ }
+ process.stdout.write(
+ "GitHub is not connected yet. Complete the browser flow, then run `opencomputer github status`.\n",
+ );
+ return;
+ }
+
+ throw new Error(
+ "Use `opencomputer github status` or `opencomputer github connect`.",
+ );
+ }
+
if (command === "connection" || command === "connections") {
// Accounts the platform holds an OAuth credential for. Nothing secret
// passes through here: `add` returns a link for the account's owner to
// open, and the token is minted and refreshed server-side.
- const SERVICES = [
- "gmail",
- "calendar",
- "drive",
- "sheets",
- "github",
- "linear",
- ];
const action = args.shift();
if (action === "add" || action === "connect") {
const service = args.shift();
- if (!service || !SERVICES.includes(service)) {
+ if (service === "github") {
+ throw new Error(
+ "GitHub agent access uses the managed GitHub App. Run `opencomputer github connect`.",
+ );
+ }
+ if (
+ !service ||
+ !SERVICE_CONNECTIONS.includes(
+ service as (typeof SERVICE_CONNECTIONS)[number],
+ )
+ ) {
throw new Error(
- `Use \`opencomputer connection add <${SERVICES.join("|")}>\``,
+ `Use \`opencomputer connection add <${SERVICE_CONNECTIONS.join("|")}>\``,
);
}
const label = option(args, "--alias") ?? option(args, "--label");
diff --git a/cli/src/index.ts b/cli/src/index.ts
index 2a7a44ea..8a87084d 100644
--- a/cli/src/index.ts
+++ b/cli/src/index.ts
@@ -75,9 +75,11 @@ Usage:
opencomputer env set <name> --value-stdin [--environment development|production] [--agent <agent>|current]
opencomputer env list [--environment development|production] [--agent <agent>|current]
opencomputer env remove <name> [--environment development|production] [--agent <agent>|current]
- opencomputer connection add <gmail|calendar|drive|sheets|github|linear> [--alias <name>] [--no-wait]
+ opencomputer connection add <gmail|calendar|drive|sheets|linear> [--alias <name>] [--no-wait]
opencomputer connection list
opencomputer connection remove <alias|connection-id> [--service <name>]
+ opencomputer github status [--project <id|slug>]
+ opencomputer github connect [--new | --connection <id|account>] [--environment development|production] [--project <id|slug>] [--no-wait]
opencomputer model-access connect codex [--project <id|slug>]
opencomputer model-access connect openrouter [--api-key-stdin] [--project <id|slug>]
opencomputer model-access connect openai-compatible --base-url <url> [--api-key-stdin] [--project <id|slug>]
diff --git a/create-start/package.json b/create-start/package.json
index 7ebc2ce4..ba0ed3c1 100644
--- a/create-start/package.json
+++ b/create-start/package.json
@@ -1,6 +1,6 @@
{
"name": "@opencomputer/create-start",
- "version": "0.7.9",
+ "version": "0.7.10",
"description": "Create a hello-world OpenComputer agent application.",
"type": "module",
"bin": {
@@ -18,7 +18,7 @@
"node": ">=22.0.0"
},
"dependencies": {
- "@opencomputer/cli": "0.7.9"
+ "@opencomputer/cli": "0.7.10"
},
"publishConfig": {
"access": "public"
diff --git a/docs/agents/github.mdx b/docs/agents/github.mdx
index 96879ecb..7ce8a2a6 100644
--- a/docs/agents/github.mdx
+++ b/docs/agents/github.mdx
@@ -53,11 +53,47 @@ Effective authority is therefore the intersection of:
## Install the App
-Deploy the agent, open its project in the OpenComputer dashboard, select the
-environment and open **Connections**. Install the managed OpenComputer GitHub
-App into a user or organization account. GitHub lets the installer select all
+Deploy the agent, then connect the managed App from the project directory:
+
+```bash
+opencomputer github connect
+```
+
+Open the printed URL and install the App into a user or organization account.
+The CLI waits until GitHub completes the flow and, by default, attaches the
+installation to both development and production. Pass
+`--environment development` or `--environment production` to attach only one
+environment, or `--no-wait` when using the command in a non-interactive script.
+Check the result at any time with:
+
+```bash
+opencomputer github status
+```
+
+If the OpenComputer account already has one active GitHub App installation,
+the command attaches it directly without opening GitHub again. When multiple
+installations are available, select one with `--connection <id|account>`; the
+ids and account names are shown by `opencomputer github status --json`.
+
+To install the App on another user or organization account, force a new GitHub
+flow and select the target account in GitHub:
+
+```bash
+opencomputer github connect --new
+```
+
+`--new` and `--connection` are mutually exclusive. Completing the new flow
+attaches that installation to the requested project environment or, when no
+environment is specified, to both environments.
+
+You can also install or attach the App from the project's **Connections** page
+in the OpenComputer dashboard. GitHub lets the installer select all
repositories or a specific set of repositories.
+GitHub App access is intentionally separate from managed service OAuth. Do not
+use `opencomputer connection add github`; the CLI directs that command to the
+GitHub App flow instead.
+
That GitHub installation selection is the complete repository boundary. There
is no second OpenComputer repository allowlist. If the installer selects all
repositories, the agent can access every repository available to that