The open-source app everyone uses to manage agents at work
TypeScript acpxagent-orchestrationagent-skillsagentic-aiai-agentsai-engineeringai-governanceai-toolsautonomous-agentsclaudeclaude-codeclaude-skillscodexhermesllmmcpmulti-agentopenclawproject-managementworkflow-automation
fix(runner): preserve managed GitHub access in OpenCode (#16488)
Dotta8843887c240b
diff --git a/doc/execution-github-identity.md b/doc/execution-github-identity.mdindex 85699e141f..662f20ef11 100644--- a/doc/execution-github-identity.md+++ b/doc/execution-github-identity.md@@ -41,6 +41,11 @@ Server-side Git operations and GitHub gateway calls follow the same selection ruManaged commands disable ambient Git credential helpers, Git global/system configuration, host GitHub CLI configuration, and host SSH identity access. Per-operation GitHub CLI configuration is isolated in a writable configuration directory beneath the managed launcher directory. Missing credentials clear previous author and token values; no teammate, standing delegation, host token, or company-default user's account is substituted. Anonymous/local operations remain available where supported.+OpenCode retains the controller-projected GitHub broker environment through+runner startup and provider startup. Shell operations acquire credentials for+the active run through that broker. They do not require a persistent GitHub CLI+login or inherit an ambient host broker capability.+Without a managed identity, local commits can use an explicitly configuredrepository identity or `git -c user.name=... -c user.email=...`. The launcherleaves author/committer environment variables unset and requires configureddiff --git a/packages/paperclip-runner/src/configured-environment.test.ts b/packages/paperclip-runner/src/configured-environment.test.tsindex 9431301079..2281becd0a 100644--- a/packages/paperclip-runner/src/configured-environment.test.ts+++ b/packages/paperclip-runner/src/configured-environment.test.ts@@ -96,4 +96,21 @@ describe("configured environment authority", () => {expect(createSanitizedAcpxSpawnInput(source, "codex").env).toMatchObject(pages);expect(createCapabilityRunnerdProviderEnvironment({ provider: "opencode", options: { environment: source }, identity, codexHome: "/isolated/home", runtimeContextPath: "/isolated/context", hasRuntimeContext: false })).toMatchObject(pages);});++ it("does not inherit an ambient GitHub broker into OpenCode", () => {+ vi.stubEnv("PAPERCLIP_GITHUB_BROKER_TOKEN", "ambient-capability");+ vi.stubEnv("PAPERCLIP_GITHUB_BROKER_URL", "http://ambient.invalid");+ vi.stubEnv("GH_TOKEN", "ambient-github-token");+ try {+ for (const environment of [undefined, {}]) {+ const prepared = createCapabilityRunnerdProviderEnvironment({+ provider: "opencode", options: { environment }, identity,+ codexHome: "/isolated/home", runtimeContextPath: "/isolated/context", hasRuntimeContext: false,+ });+ expect(prepared.PAPERCLIP_GITHUB_BROKER_TOKEN).toBeUndefined();+ expect(prepared.PAPERCLIP_GITHUB_BROKER_URL).toBeUndefined();+ expect(prepared.GH_TOKEN).toBeUndefined();+ }+ } finally { vi.unstubAllEnvs(); }+ });});diff --git a/packages/paperclip-runner/src/drivers/opencode/opencode-server-driver.ts b/packages/paperclip-runner/src/drivers/opencode/opencode-server-driver.tsindex 489ed50a52..f500867030 100644--- a/packages/paperclip-runner/src/drivers/opencode/opencode-server-driver.ts+++ b/packages/paperclip-runner/src/drivers/opencode/opencode-server-driver.ts@@ -21,6 +21,7 @@ import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";import { parseOpenCodeReasoningMode, type OpenCodeReasoningMode } from "./reasoning-mode.js";import { annotateOmittedProviderText, parseOpenCodeSseFrames } from "./sse-frames.js";+import { githubCredentialEnvironment } from "../../github-credential-environment.js";import {CODEX_SKILLLESS_BASE_INSTRUCTIONS,@@ -2385,7 +2386,7 @@ async function startRuntime(input: {{ mode: 0o600 },);const environment = sanitizedEnvironment(- input.options.environment ?? process.env,+ input.options.environment,{HOME: isolatedHome,XDG_CONFIG_HOME: configHome,@@ -2874,7 +2875,7 @@ async function* parseSse(}function sanitizedEnvironment(- source: NodeJS.ProcessEnv,+ source: NodeJS.ProcessEnv | undefined,overrides: Record<string, string>,): NodeJS.ProcessEnv {const allowed = [@@ -2893,9 +2894,10 @@ function sanitizedEnvironment("OPENROUTER_API_KEY",];const result: NodeJS.ProcessEnv = {};+ const candidate = source ?? process.env;for (const key of allowed)- if (source[key] !== undefined) result[key] = source[key];- return { ...result, ...overrides };+ if (candidate[key] !== undefined) result[key] = candidate[key];+ return { ...result, ...githubCredentialEnvironment(source ?? {}), ...overrides };}function sanitizedEnvironmentKeys(): string[] {diff --git a/packages/paperclip-runner/src/live/runnerd-codex-transport.ts b/packages/paperclip-runner/src/live/runnerd-codex-transport.tsindex 2fd55d73dd..3bf2ebda3c 100644--- a/packages/paperclip-runner/src/live/runnerd-codex-transport.ts+++ b/packages/paperclip-runner/src/live/runnerd-codex-transport.ts@@ -3,6 +3,7 @@ import { resolvePinnedOpenCodeCommand } from "../drivers/opencode/opencode-serveimport { ACPX_CAPABILITY_PROFILES } from "../drivers/acpx/capability-profiles.js";import { admittedPiThinkingLevel, resolvePiThinkingLevel } from "../drivers/acpx/pi-thinking.js";import { configuredEnvironment } from "../configured-environment.js";+import { githubCredentialEnvironment } from "../github-credential-environment.js";import { resolveAcpxProviderMode } from "../drivers/acpx/provider-mode.js";import { isAcpxCanonicalInputMethod } from "../drivers/acpx/profile-extensions.js";import { RunnerdTraceFrameIndex } from "./runnerd-trace-frame-index.js";@@ -3393,7 +3394,7 @@ function createSanitizedOpenCodeRunnerEnvironment(delete candidate[key];if (source?.[key] !== undefined) candidate[key] = source[key];}- return { ...configuredEnvironment(source), ...Object.fromEntries(+ return { ...configuredEnvironment(source), ...githubCredentialEnvironment(source ?? {}), ...Object.fromEntries(Object.entries(candidate).filter(([key, value]) =>typeof value === "string" &&diff --git a/packages/paperclip-runner/test/fixtures/fake-opencode-server.mjs b/packages/paperclip-runner/test/fixtures/fake-opencode-server.mjsindex 692fd9c2eb..99f5a921d4 100644--- a/packages/paperclip-runner/test/fixtures/fake-opencode-server.mjs+++ b/packages/paperclip-runner/test/fixtures/fake-opencode-server.mjs@@ -1,5 +1,6 @@#!/usr/bin/env nodeimport { createServer } from "node:http";+import { execFile } from "node:child_process";import { appendFile, mkdir, readFile, writeFile } from "node:fs/promises";import { join } from "node:path";@@ -101,6 +102,7 @@ await writeFile(projectConfigDisabled: process.env.OPENCODE_DISABLE_PROJECT_CONFIG,modelsFetchDisabled: process.env.OPENCODE_DISABLE_MODELS_FETCH,defaultPluginsDisabled: process.env.OPENCODE_DISABLE_DEFAULT_PLUGINS,+ githubTokenPresent: Boolean(process.env.GH_TOKEN || process.env.GITHUB_TOKEN),}),);@@ -443,6 +445,14 @@ const server = createServer(async (request, response) => {setTimeout(async () => {await callFirstPaperclipTool();const parsedPrompt = parsedPromptText(promptPayload);+ if (String(parsedPrompt.message ?? "").includes("managed-github-operation")) {+ const result = await new Promise(resolve => {+ execFile("gh", ["api", "user"], { timeout: 5000 }, (error, stdout, stderr) => {+ resolve({ stdout, stderr, error: error?.message ?? null });+ });+ });+ await writeFile(join(process.env.XDG_DATA_HOME, "fake-github-operation.json"), JSON.stringify(result));+ }if (String(parsedPrompt.message ?? "").includes("incremental-stream")) {const messageID = `stream-message-${promptTurnSeq}`;const part = { id: `stream-part-${promptTurnSeq}`, messageID, sessionID: session.id, type: "text", text: "" };diff --git a/server/src/services/native-runtime/native-github-access.test.ts b/server/src/services/native-runtime/native-github-access.test.tsindex b472beaf34..444715a1b1 100644--- a/server/src/services/native-runtime/native-github-access.test.ts+++ b/server/src/services/native-runtime/native-github-access.test.ts@@ -8,6 +8,8 @@ import { tmpdir } from "node:os";import path from "node:path";import { createInterface } from "node:readline";import { createNativeGitHubAccess, type NativeGitHubAccess } from "./native-github-access.js";+import { OpenCodeServerDriver } from "@paperclipai/paperclip-runner";+import { createCapabilityRunnerdProviderEnvironment } from "@paperclipai/paperclip-runner/live";const scope = { companyId: "company-a", agentId: "agent-a", issueId: "task-a" };const run = (runId: string) => ({ ...scope, runId });const cleanups: (() => Promise<unknown>)[] = [];@@ -80,6 +82,45 @@ function request(broker: NativeGitHubAccess, extra: RequestInit = {}, endpoint =method: "POST", body: "{}", headers: { authorization: `Bearer ${broker.env.PAPERCLIP_GITHUB_BRIDGE_TOKEN}`, "content-type": "application/json" }, ...extra,});}+it.each([false, true])("resolves managed GitHub credentials from OpenCode shell operations (runner projection: %s)", async throughRunner => {+ const b = await broker();+ const command = path.join(b.root, "fake-opencode-server.mjs");+ const fixture = new URL("../../../../packages/paperclip-runner/test/fixtures/fake-opencode-server.mjs", import.meta.url);+ await writeFile(command, await readFile(fixture), { mode: 0o700 });+ const source = { ...b.env, OPENROUTER_API_KEY: "fixture-provider-key", PAPERCLIP_API_KEY: "controller-must-not-cross" };+ const environment = throughRunner ? createCapabilityRunnerdProviderEnvironment({+ provider: "opencode",+ options: { environment: source, stateDirectory: b.root },+ identity: { runnerInstanceId: "runner-a", environmentLeaseId: "lease-a", runId: "a", normalizedSessionId: "github", turnId: "turn-a", itemId: "item-a" },+ codexHome: path.join(b.root, "codex-home"),+ runtimeContextPath: path.join(b.root, "context.json"),+ hasRuntimeContext: false,+ }) : source;+ const driver = new OpenCodeServerDriver({+ model: "openrouter/z-ai/glm-5.3", runtimeDirectory: b.root, command, environment,+ });+ const session = await driver.openSession({ runId: "a", normalizedSessionId: "github", workingDirectory: b.root });+ cleanups.push(() => session.close({ reason: "test complete" }));+ const operate = async () => {+ await session.startTurn({ message: { role: "user", text: "managed-github-operation" } });+ for await (const event of session.events()) {+ if (event.eventType === "turn.completed") break;+ if (event.eventType === "turn.failed") throw new Error("OpenCode fixture turn failed");+ }+ return JSON.parse(await readFile(path.join(b.root, "github", "data", "fake-github-operation.json"), "utf8"));+ };+ const releaseA = b.activate(run("a"));+ expect(await operate()).toMatchObject({ stdout: "fixture-a", error: null });+ releaseA();+ const releaseB = b.activate(run("b"));+ expect(await operate()).toMatchObject({ stdout: "fixture-b", error: null });+ releaseB();+ expect(await operate()).toMatchObject({ stdout: "anonymous", error: null });+ expect(b.resolveCredentials.mock.calls.map(([binding]) => binding.runId)).toEqual(["a", "b"]);+ const childEnvironment = JSON.parse(await readFile(path.join(b.root, "github", "data", "fake-environment.json"), "utf8"));+ expect(childEnvironment.keys).not.toContain("PAPERCLIP_API_KEY");+ expect(childEnvironment.githubTokenPresent).toBe(false);+}, 30000);it("uses the selected duplex transport across credential rotation without file polling", async () => {const b = await broker(undefined, true, false, undefined, { enabled: true, capability: true });expect(b.bridgeModes).toEqual(["http2_v1"]);