Skip to content

feat(agent): GitHub token bridge for refresh + codex compatibility#1976

Draft
ryans-posthog wants to merge 1 commit intomainfrom
ryan/add_env_propegation
Draft

feat(agent): GitHub token bridge for refresh + codex compatibility#1976
ryans-posthog wants to merge 1 commit intomainfrom
ryan/add_env_propegation

Conversation

@ryans-posthog
Copy link
Copy Markdown
Contributor

Summary

  • Adds POST /github-token (JWT-auth) on the agent server so the orchestrator can push a refreshed GitHub token mid-run, and GET /github-token (loopback + per-process secret) for the gh wrapper and a git credential helper to read it.
  • On start(), generates POSTHOG_GH_WRAPPER_URL + POSTHOG_GH_WRAPPER_SECRET into process.env before autoInitializeSession() so the codex-acp child inherits them, then installs a global credential.https://github.bokerqi.top.helper shim that fetches the latest token via the local endpoint.
  • Vitest now isolates GIT_CONFIG_GLOBAL with commit.gpgsign=false, fixing settings.test.ts failures on hosts with global signing on and preventing the credential-helper install from ever touching the dev's real ~/.gitconfig.

Why

The gh CLI and any git push in the sandbox both need a live GitHub token. The Claude adapter runs in-process, so mutating process.env.GH_TOKEN from POST /github-token reaches it. The codex-acp adapter is spawned as a child with env: { ...process.env } snapshotted at spawn time — env updates after that point are invisible. Routing both adapters through the loopback endpoint (via the gh wrapper and the git credential helper) gives a single source of truth that works for both.

Test plan

  • Existing agent tests still pass (308 total, including the previously red settings.test.ts).
  • New tests cover: JWT requirement on POST, body validation, env mutation, loopback enforcement on GET, missing-secret rejection, 404 when no token has been set, round-trip POST→GET.
  • Manual: in a sandbox, after the orchestrator POSTs a token, git push succeeds for both Claude and codex runs.
  • Manual: rotating the token via a second POST is reflected on the next git/gh call without restarting the agent.

🤖 Generated with Claude Code

The orchestrator can now POST a fresh GitHub token to the agent server
mid-run, and a per-process loopback endpoint hands that token to the
gh wrapper and a git credential helper. This decouples auth refresh from
the codex-acp child process, whose env is snapshotted at spawn time and
can't be mutated after the fact.

- POST /github-token (JWT-auth) stores the token, updates GH_TOKEN /
  GITHUB_TOKEN in process.env for the in-process Claude path
- GET /github-token (loopback + x-posthog-local-secret header) is what
  the gh wrapper and credential helper call
- On start(), generate a 32-byte secret + URL into env before any child
  spawns, then install a git credential helper at credential.https://
  github.com.helper that curls GET /github-token
- Vitest now isolates GIT_CONFIG_GLOBAL with gpgsign forced off so tests
  no longer fail on hosts with global commit signing enabled

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant