feat(agent-env): add default GH_TOKEN, GITHUB_TOKEN, and git identity overrides#179
feat(agent-env): add default GH_TOKEN, GITHUB_TOKEN, and git identity overrides#179
Conversation
… overrides
Inject sensible defaults into the agent environment so that Claude Code
agents automatically get GitHub auth and bot git identity without
requiring explicit `env:` in WORKFLOW.md.
- Add `BotIdentity` interface and optional `botIdentity()` to `TokenProvider`
- `resolveAgentEnv` now injects `GH_TOKEN` / `GITHUB_TOKEN` defaults
(resolved via `${INSTALLATION_ACCESS_TOKEN}`) when tokenProvider is present
- `buildTokenProvider` queries `GET /users/{bot_username}[bot]` to resolve
the bot user ID for noreply email format
- User-defined env in WORKFLOW.md always takes precedence over defaults
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the agent environment resolution by introducing automatic injection of default GitHub tokens and git identity information. Agents can now seamlessly authenticate with GitHub and attribute their commits correctly without explicit configuration, while still allowing users to override these defaults when needed. This streamlines agent development and improves the integrity of automated git operations. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable feature for automatically injecting default GitHub authentication tokens and git author identity into the agent's environment. The implementation is well-executed, including good test coverage, caching for the bot identity, and proper handling of user overrides. I have a couple of suggestions to enhance the code's clarity and long-term maintainability.
There was a problem hiding this comment.
1 issue found across 5 files
Confidence score: 4/5
- This PR is likely safe to merge, but there is a moderate reliability risk: bot startup can hang if identity fetch never returns, which can block agent initialization.
- The main issue is in
packages/core/src/orchestrator.ts: adding a timeout around the GitHub bot identity call would prevent indefinite waits on slow or unresponsive endpoints. - Pay close attention to
packages/core/src/orchestrator.ts- startup flow depends on this fetch path, so lack of timeout can cause stalled launches.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/core/src/orchestrator.ts">
<violation number="1" location="packages/core/src/orchestrator.ts:1050">
P2: Add a timeout to bot identity fetch so agent startup cannot hang on a slow/unresponsive GitHub endpoint.</violation>
</file>
Architecture diagram
sequenceDiagram
participant Runner as Agent Runner
participant Env as Env Resolver
participant TP as Token Provider
participant GH as GitHub API
Note over Runner,GH: NEW: Default Auth & Identity Injection Flow
Runner->>Env: resolveAgentEnv(config, tokenProvider)
rect rgb(240, 240, 240)
Note over Env,TP: Build Defaults
Env->>Env: NEW: Check for missing GH_TOKEN / GITHUB_TOKEN
opt If missing
Env->>Env: NEW: Add ${INSTALLATION_ACCESS_TOKEN} to defaults
end
Env->>Env: NEW: Check for missing GIT_AUTHOR/COMMITTER keys
opt If git keys missing AND botIdentity exists
Env->>TP: botIdentity()
alt Cache miss
TP->>GH: NEW: GET /users/{bot_username}[bot]
GH-->>TP: 200 OK (id, login)
TP->>TP: Construct noreply email using ID
end
TP-->>Env: BotIdentity (name, email)
Env->>Env: NEW: Add git identity to defaults
end
end
Env->>Env: Merge (User Env overrides Defaults)
loop For each [key, value] in merged env
alt value is "${INSTALLATION_ACCESS_TOKEN}"
alt Token not yet cached
Env->>TP: installationAccessToken()
TP-->>Env: ghs_token
end
Env->>Env: Replace placeholder with token
else value matches other ${VAR}
Env->>Env: Resolve from process.env
end
end
Env-->>Runner: Final Agent Environment
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
- Separate JSON parse error from network error in fetchBotIdentity for clearer debugging - Guard git identity injection with hasTokenEnv check to avoid setting bot identity when no GitHub credentials are available
- Replace key.includes('NAME') with explicit switch statement
- Import BotIdentity type at top of orchestrator.ts
- Add AbortSignal.timeout(30s) to fetchBotIdentity fetch call
|



Summary
GH_TOKEN/GITHUB_TOKEN(via${INSTALLATION_ACCESS_TOKEN}) into agent env when tokenProvider is available, so Claude Code agents get GitHub auth without explicitenv:in WORKFLOW.mdBotIdentityinterface and optionalbotIdentity()toTokenProvider— queriesGET /users/{bot_username}[bot]to resolve bot user ID for noreply emailGIT_AUTHOR_*,GIT_COMMITTER_*) is injected from bot identity, ensuring correct attribution ongit commitTest plan
bun test packages/core/src/agent-env.test.ts— 7 new tests for default override behaviorbun run test)bun run check)Summary by cubic
Automatically injects GitHub auth and a bot git identity into agent environments when a GitHub token provider is configured. Adds safeguards, identity caching, clearer logging, and a 30s timeout for bot identity lookup.
New Features
GH_TOKENandGITHUB_TOKENset to${INSTALLATION_ACCESS_TOKEN}when a token provider exists; user-defined env always wins.BotIdentityand optionalbotIdentity()toTokenProvider; orchestrator queriesGET /users/{bot_username}[bot]and caches the result to build the noreply email.resolveAgentEnvsetsGIT_AUTHOR_*andGIT_COMMITTER_*from the bot identity when missing.Bug Fixes
fetchBotIdentity; add a 30s fetch timeout to avoid hangs.Written for commit 94e8b8c. Summary will update on new commits.