You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(cloud-agent-next): migrate to git-token-service RPC
Replace the in-worker GitHubTokenService and InstallationLookupService
with calls to the shared git-token-service Worker via a GIT_TOKEN_SERVICE
service binding, and drop the now-redundant token fetching in the web
app routers.
- Wire GIT_TOKEN_SERVICE binding in wrangler.jsonc; drop GITHUB_APP_ID,
GITHUB_LITE_APP_ID, and GITHUB_TOKEN_CACHE KV bindings. Restore the
HYPERDRIVE binding for an upcoming feature.
- Resolve GitHub tokens for repo + managed GitLab tokens through a new
shared helper (src/services/git-token-service-client.ts) used from
both session-prepare and async-preparation paths.
- Persist gitlabTokenManaged in session metadata so the DO can refresh
GitLab tokens on startExecutionV2 via refreshManagedGitLabToken.
Successful refreshes are persisted via updateGitToken so later
transient failures fall back to the last-known working token instead
of the stale prepare-time token. Treat gitlabTokenManaged ===
undefined as managed for backwards compatibility with pre-existing
sessions.
- Fail closed on GitLab access revocation: no_integration_found and
invalid_org_id reasons throw BAD_REQUEST at session prepare and
startExecutionV2 instead of falling back to the stored token, so the
session cannot keep using a managed token after the integration or
org access was removed. Transient failures retain the last-known
token fallback.
- Parameterize DurableObject<WorkerEnv> on the base class, removing 28
'as unknown as WorkerEnv' casts in CloudAgentSession and aligning
with the rest of the repo's DO pattern.
- Extract cloudflare-git-token-service into a standalone
'git-token-service' dev group shared by cloud-agent, app-builder, and
gastown. Switch its dev script to 'wrangler dev --env dev' so the
locally-running worker is named 'git-token-service-dev', matching
what cloud-agent-next and the security workers reference in their
dev service bindings.
- Web routers (personal + org) no longer fetch GitHub/GitLab tokens
for prepareSession/sendMessage — cloud-agent-next handles token
resolution and refresh centrally.
Copy file name to clipboardExpand all lines: services/cloud-agent-next/AGENTS.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ This file provides guidance to AI coding agents working in this repository.
4
4
5
5
## Project Overview
6
6
7
-
Cloudflare Worker that powers Kilocode Cloud Agents. It exposes a tRPC API for session preparation and execution, streams output over WebSockets, and runs the Kilocode CLI inside Cloudflare Sandbox containers. Durable Objects track sessions; Hyperdrive is used for Postgres lookups (for example, GitHub App installation IDs). The wrapper in `wrapper/` is a core component that brokers Kilocode CLI events into the worker’s `/ingest` WebSocket and handles job lifecycle.
7
+
Cloudflare Worker that powers Kilocode Cloud Agents. It exposes a tRPC API for session preparation and execution, streams output over WebSockets, and runs the Kilocode CLI inside Cloudflare Sandbox containers. Durable Objects track sessions; git tokens (GitHub App installation tokens, managed GitLab tokens) are resolved via the shared `git-token-service` Worker. The wrapper in `wrapper/` is a core component that brokers Kilocode CLI events into the worker’s `/ingest` WebSocket and handles job lifecycle.
8
8
9
9
## Development Commands
10
10
@@ -108,7 +108,7 @@ This pattern blocks API endpoints from running for external contributors who don
Copy file name to clipboardExpand all lines: services/cloud-agent-next/README.md
+7-14Lines changed: 7 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -832,28 +832,21 @@ This enables:
832
832
833
833
#### GitHub App Token Generation
834
834
835
-
For V2 routes (`sendMessageV2`, `initiateFromKilocodeSessionV2`), the cloud-agent generates GitHub App installation tokens on-demand.
835
+
For V2 routes (`sendMessageV2`, `initiateFromKilocodeSessionV2`), the cloud-agent resolves GitHub App installation tokens via the shared `git-token-service` Worker (`GIT_TOKEN_SERVICE` service binding).
836
836
837
837
**How it works:**
838
838
839
-
1.**Automatic installation lookup**: The worker automatically looks up the GitHub App installation ID from the database via Hyperdrive. The lookup verifies the user has access to the repository's organization.
840
-
2.**On-demand token generation**: When execution starts, `GitHubTokenService` generates a fresh token using `@octokit/auth-app`
841
-
3.**KV caching**: Tokens are cached in Cloudflare KV with 30-minute TTL (tokens valid for 1 hour)
1.**Delegated resolution**: The worker calls `git-token-service` RPC (see `src/services/git-token-service-client.ts`) to look up the installation ID for the repo and mint an installation access token. Token caching and GitHub App credentials live in `git-token-service`.
840
+
2.**Managed GitLab tokens**: The same client resolves and refreshes managed GitLab tokens; `gitlabTokenManaged` is persisted in session metadata so the session DO can refresh it on `startExecutionV2`.
843
841
844
842
**Configuration:**
845
843
846
-
The worker requires these environment variables:
847
-
848
-
-`GITHUB_APP_ID`: GitHub App ID (configured in `wrangler.jsonc`)
849
-
-`GITHUB_APP_PRIVATE_KEY`: RSA private key for the GitHub App (set via `wrangler secret put`)
850
-
-`GITHUB_TOKEN_CACHE`: KV namespace binding for token caching
851
-
-`HYPERDRIVE`: Hyperdrive binding for database access (installation ID lookup)
844
+
-`GIT_TOKEN_SERVICE`: service binding to the `git-token-service` Worker (prod) / `git-token-service-dev` (dev). Configured in `wrangler.jsonc`.
845
+
-`GITHUB_APP_SLUG` / `GITHUB_APP_BOT_USER_ID` (and the Lite equivalents): used only for git commit author attribution — not for token generation.
852
846
853
847
**Benefits:**
854
848
855
-
- No need to pass `githubInstallationId` — automatically resolved from database
856
-
-Tokens generated closer to where they're used (reduced latency)
849
+
- No need to pass `githubInstallationId` — resolved centrally by `git-token-service`
850
+
-GitHub App credentials and token cache kept in a single shared Worker
857
851
- Fresh tokens on-demand rather than at session start
0 commit comments