From 0dfe6292a887cba1b6ada50b7d47889c4579a3b2 Mon Sep 17 00:00:00 2001 From: Brendan Date: Thu, 17 Sep 2026 00:56:05 +0000 Subject: [PATCH] Expose GitHub installation metadata to agents --- README.md | 7 +++++++ packages/app/src/flow-service.ts | 1 + packages/app/src/protected-api.ts | 2 ++ packages/app/test/flow-service.test.ts | 13 +++++++++++++ 4 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 7eca1ebc..7afc77b7 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,13 @@ curl -X POST -H "Authorization: Bearer $FACTORIZE_ACCESS_TOKEN" \ https://app.factorize.sh/api/v1/runs/RUN_ID/stop ``` +Connected GitHub App installation metadata, including the installation IDs used by GitHub Job triggers, is available without exposing credentials: + +```bash +curl -H "Authorization: Bearer $FACTORIZE_ACCESS_TOKEN" \ + https://app.factorize.sh/api/v1/github-installations +``` + Job CRUD is available at `/jobs` and `/jobs/:id`; job metadata includes `currentRuns` and `maxConcurrency`. Run collections return `{ "items": [...], "nextCursor": "..." }`; pass `nextCursor` back as the `cursor` query parameter. Runs can be filtered by `jobId`, `state`, and `contextQuery`; context queries use case-insensitive literal substring matching and matching items contain a bounded `context_excerpt`, never the full context. `GET /runs/:runId` returns the complete structured trigger `context` and invocation metadata, including the firing `trigger_id`. The canonical Job prompt contract is documented in [docs/job-trigger-context.md](docs/job-trigger-context.md). Errors consistently use `{ "error": { "code": "...", "message": "..." } }`. ## MCP clients diff --git a/packages/app/src/flow-service.ts b/packages/app/src/flow-service.ts index d1922374..4536441e 100644 --- a/packages/app/src/flow-service.ts +++ b/packages/app/src/flow-service.ts @@ -44,6 +44,7 @@ export class ApiService { } listExeConnections() { return this.call("flows:read", "/connections/status").then((value: any) => value.exeConnections ?? []); } + listGitHubInstallations() { return this.call("flows:read", "/github/installations"); } listTailIntegrations() { return this.call("flows:read", "/connections/cloudflare-tail"); } listRuns(query: URLSearchParams) { return this.call("runs:read", `/v1/runs?${query}`); } getRun(runId: string) { return this.call("runs:read", `/v1/runs/${encodeURIComponent(runId)}`); } diff --git a/packages/app/src/protected-api.ts b/packages/app/src/protected-api.ts index 0191f290..1d629a8d 100644 --- a/packages/app/src/protected-api.ts +++ b/packages/app/src/protected-api.ts @@ -39,6 +39,7 @@ export async function protectedApiFetch(request: Request, env: Env, auth: OAuthP if (path === "/mcp") return mcp(request, service, env, ctx); if (!path.startsWith("/api/v1")) return Response.json({ error: { code: "not_found", message: "Not found" } }, { status: 404 }); if (request.method === "GET" && path === "/api/v1/exe-connections") return Response.json(await service.listExeConnections()); + if (request.method === "GET" && path === "/api/v1/github-installations") return Response.json(await service.listGitHubInstallations()); if (request.method === "GET" && path === "/api/v1/execution-targets") return Response.json(await service.listExecutionTargets()); if (request.method === "GET" && path === "/api/v1/job-trigger-availability") return Response.json(await service.listJobTriggerAvailability()); if (request.method === "POST" && path === "/api/v1/schedules/preview") return Response.json(await service.previewSchedule(await request.json())); @@ -72,6 +73,7 @@ async function mcp(request: Request, service: ApiService, env: Env, ctx: Executi catch (error) { const response = errorResponse(error), detail = await response.json() as any; throw new Error(`${detail.error?.code ?? "operation_failed"}: ${detail.error?.message ?? "Operation failed"}`); } }); tool("list_exe_connections", "List safe metadata for saved exe.dev connections. API tokens are never returned.", z.object({}), () => service.listExeConnections()); + tool("list_github_installations", "List connected GitHub App installations, including the installation IDs needed by GitHub Job triggers. Credentials are never returned.", z.object({}), () => service.listGitHubInstallations()); tool("list_runs", "List authoritative job runs by job ID, state, and an optional case-insensitive literal substring of triggered context. Automatic webhook, schedule, and lifecycle signals coalesce, so query runs and the provider API for authoritative work. Context matches include only a bounded excerpt.", listRunsSchema, (input: any) => service.listRuns(queryOf(input))); tool("get_run", "Get a run with its full triggered context, invocation metadata, execution metadata, output, and activity. For manual invocations, invocation.idempotency_key is the client-reusable value; invocation.claim_key is internal.", runIdSchema, ({ runId }: any) => service.getRun(runId)); tool("stop_run", "Stop an active run", runIdSchema, ({ runId }: any) => service.stopRun(runId)); diff --git a/packages/app/test/flow-service.test.ts b/packages/app/test/flow-service.test.ts index 8c640c2a..6847aa3e 100644 --- a/packages/app/test/flow-service.test.ts +++ b/packages/app/test/flow-service.test.ts @@ -28,6 +28,19 @@ describe("ApiService", () => { await service.invokeJob("job-1", { prompt: "go", idempotencyKey: "client-1" }); expect(requests).toEqual(["POST /v1/jobs", "POST /v1/jobs/job-1/invocations"]); }); + + it("lists safe GitHub installation metadata with the flow read scope", async () => { + const installations = [{ installationId: 123, accountLogin: "generation", accountType: "Organization", state: "active", updatedAt: "2026-09-17T00:00:00.000Z" }]; + const service = new ApiService(environment(request => { + const path = new URL(request.url).pathname; + if (path === "/members/owner-a") return Response.json({ role: "owner", session_version: 4 }); + if (path === "/github/installations") return Response.json(installations); + return new Response("Not found", { status: 404 }); + }), auth); + + await expect(service.listGitHubInstallations()).resolves.toEqual(installations); + expect(JSON.stringify(installations)).not.toMatch(/token|secret|credential/i); + }); }); describe("shared API schemas", () => {