Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .changeset/eve-attribution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
'@github-tools/eve-extension': minor
'@github-tools/sdk': minor
---

Credit the GitHub App on pull requests and commits that run with a person's token.

With `actAs: 'user'`, or `'caller'` and a signed-in user, GitHub records the person as the author of what the agent writes. The extension now credits the App by default:

- `createPullRequest` ends the body with `Generated by [<app>](https://github.com/apps/<app>).`
- `createOrUpdateFile`, `editFiles`, `mergePullRequest` and `enablePullRequestAutoMerge` add the App's bot account to `coAuthors`, as `Co-authored-by: <app>[bot] <id+<app>[bot]@users.noreply.github.com>`.

The App is read from the person's token, so the connector must be backed by a GitHub App. Calls that run as the App add nothing. Turn it off or pick one credit with `attribution`:

```ts
export default githubExtension({
connector: 'github/my-connector',
actAs: 'caller',
attribution: false, // or { footer: true, coAuthor: false }
})
```

`@github-tools/sdk/eve-runtime` exports the pieces: `githubAppBot(token)` reads the App behind a user token, `githubAppBotIdentity(bot)` returns its commit identity, `withGithubAppFooter(body, bot)` adds the footer, and `GITHUB_COMMIT_TOOLS` lists the tools that take `coAuthors`. A user token that GitHub lists no installation to fails with `github_tools.APP_BOT_UNKNOWN`.
1 change: 1 addition & 0 deletions apps/docs/content/docs/3.core/7.errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Every code starts with `github_tools.`, as in `github_tools.NOT_FOUND`.
| --- | --- | --- |
| `GUARDRAIL_BLOCKED` | 403 | The call targets a repository or branch outside [`guardrails`](/approval#guardrails), or its input contains what looks like a credential. Checked before any request reaches GitHub, whoever approved the call. The message gives the reason |
| `CALLER_FORBIDDEN` | 403 | On the eve extension with [`actAs: 'caller'`](/integrations/eve#per-user-tokens), someone who commented on GitHub asked for a call their role on the target repository doesn't allow. Checked before the call reaches GitHub. The message names the role they have and the one the call needs |
| `APP_BOT_UNKNOWN` | 403 | On the eve extension with [`attribution`](/integrations/eve#credit-the-app), GitHub lists no installation of the App to the person's token, so the App's bot account can't be credited. The connector isn't backed by a GitHub App, or the person reaches no installation of it |

### GitHub API

Expand Down
20 changes: 20 additions & 0 deletions apps/docs/content/docs/4.integrations/2.eve.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,25 @@ Only the person who asked for a call can approve it, so a colleague in a shared

For a custom rule, pass `{ request, response }` for that tool in `requireApproval`, with an eve [`response` policy](https://eve.dev/docs/tools/human-in-the-loop#authorizing-approval-responses). It replaces both defaults, and the sign-in checks still apply to the people it allows.

### Credit the App

When a call runs with a person's token, GitHub records that person as its author. So the extension credits the App on what it wrote for them:

- `createPullRequest` ends the pull request body with `Generated by [<app>](https://github.com/apps/<app>).`
- `createOrUpdateFile`, `editFiles`, `mergePullRequest` and `enablePullRequestAutoMerge` add the App's bot account to `coAuthors`, so the commit message ends with `Co-authored-by: <app>[bot] <id+<app>[bot]@users.noreply.github.com>`. GitHub links that address to the bot account.

When you squash-merge a person's pull request, GitHub adds each commit author other than the pull request's author as `Co-authored-by`. Commits the App wrote, for example through eve's git extension, therefore credit it on the squash commit without this option.

The App is read from the person's token, once per process, so the connector must be backed by a GitHub App. Calls that run as the App add nothing, since GitHub already shows the App as their author. Turn both credits off, or pick one:

```ts [agent/extensions/github.ts]
export default githubExtension({
connector: 'github/my-connector',
actAs: 'caller',
attribution: { footer: true, coAuthor: false },
})
```

### Work across several installations

An App installed on several accounts needs no config. Each App token is minted for the installation that owns the call's `owner/repo`, after `context` defaults. Tools without a repository, such as `searchCode` and the gist tools, use the connector's default installation.
Expand Down Expand Up @@ -269,6 +288,7 @@ Pair it with `guardrails`, and try the schedule with `dryRun: true` first.
| `connector` | `string \| () => string \| Promise<string>` | Vercel Connect connector name, or a resolver that picks one per call. Wins over `token` |
| `actAs` | `'app' \| 'user' \| 'caller' \| { read, write }` | Whose GitHub access a call uses with a connector. Default `'app'`. See [Per-user tokens](#per-user-tokens) |
| `approvers` | `'requester' \| 'anyone'` | Who may answer an approval. Default `'requester'`. See [Who can approve](#who-can-approve) |
| `attribution` | `boolean \| { footer?, coAuthor? }` | Credit the App on pull requests and commits that run with a person's token. Default `true`. See [Credit the App](#credit-the-app) |
| `connect` | `object \| (ctx, call) => object` | Connect token params for App tokens, such as `installationId`, `repositories` or `scopes`. Can't be combined with `actAs: 'user'` |
| `preset` | preset name, array, or `'auto'` | Which tools the model sees. See [Presets](/presets) |
| `include` | tool names | Added to the preset, or the whole set without one |
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/7.reference/1.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,6 @@ import githubExtension from '@github-tools/eve-extension'
export default githubExtension({ connector: 'github/my-connector', preset: 'code-review' })
```

The default export mounts the tools in an eve agent from a file under `agent/extensions/`. The file name becomes the namespace, so `agent/extensions/github.ts` exposes `github__listPullRequests` and so on. It takes `token`, `connector`, `actAs`, `approvers`, `connect`, `preset` (including `'auto'`), `include`, `exclude`, `context`, `requireApproval` (adding `'once'` and predicates), `evaluation`, `overrides`, `author`, `committer`, `coAuthors`, `guardrails` and `dryRun`; [eve](/integrations/eve) documents each one. Needs Node 24 or later and `eve` as a peer.
The default export mounts the tools in an eve agent from a file under `agent/extensions/`. The file name becomes the namespace, so `agent/extensions/github.ts` exposes `github__listPullRequests` and so on. It takes `token`, `connector`, `actAs`, `approvers`, `attribution`, `connect`, `preset` (including `'auto'`), `include`, `exclude`, `context`, `requireApproval` (adding `'once'` and predicates), `evaluation`, `overrides`, `author`, `committer`, `coAuthors`, `guardrails` and `dryRun`; [eve](/integrations/eve) documents each one. Needs Node 24 or later and `eve` as a peer.

`@github-tools/eve-extension/channels` exports `githubChannel`, which is eve's `githubChannel` plus `respondTo` (`'anyone'`, `'triagers'`, `'writers'`, `'maintainers'` or `'admins'`), and the `GithubChannelConfig` and `GithubRespondTo` types. See [Choose who the agent answers](/integrations/eve#choose-who-the-agent-answers).
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Tools are exposed to the model as `<namespace>__<toolName>`: `agent/extensions/g

## Config schema

`token`, `connector`, `actAs`, `approvers`, `connect`, `preset`, `include`, `exclude`, `context`, `requireApproval`, `evaluation`, `guardrails`, `dryRun`, `overrides`, `author`/`committer`/`coAuthors`, see `/integrations/eve#config`. `guardrails: { repositories, branches }` deny any call outside the allowed repositories or branch patterns, whoever approves it, with the reason and without asking anyone. They cover the extension's tools only: eve's git extension runs `gh` through `git__gh` without approval, so limit it with its own `github.authorize` check. `dryRun: true` sends no write to GitHub and labels each one "Would create issue on owner/repo".
`token`, `connector`, `actAs`, `approvers`, `attribution`, `connect`, `preset`, `include`, `exclude`, `context`, `requireApproval`, `evaluation`, `guardrails`, `dryRun`, `overrides`, `author`/`committer`/`coAuthors`, see `/integrations/eve#config`. `guardrails: { repositories, branches }` deny any call outside the allowed repositories or branch patterns, whoever approves it, with the reason and without asking anyone. They cover the extension's tools only: eve's git extension runs `gh` through `git__gh` without approval, so limit it with its own `github.authorize` check. `dryRun: true` sends no write to GitHub and labels each one "Would create issue on owner/repo".

`token` is `string | (() => Promise<string>)` (`GithubTokenInput`). Pass an async provider for rotating GitHub App installation tokens. Falls back to `GITHUB_TOKEN` when omitted; `connector` takes priority.

Expand Down Expand Up @@ -95,6 +95,7 @@ export default githubExtension({
- GitHub allows a user-token call only when both the user and the App have access, so a maintainer can merge and a reader gets `403`.
- A user who has not authorized the App gets an eve `sign-in` interaction, and the call resumes after it; a `401` asks them to sign in again. A signed-in user never falls back to the App.
- `approvers: 'requester'` (default): only the requester can approve or deny, so a colleague in a shared thread cannot approve someone else's request. `'anyone'` (opt-in, for simple shared agents): any signed-in user can approve and anyone can deny; for `'user'`/`'caller'` tools the approved call runs with the approver's token, so GitHub checks and records the approver, and an approver who has not authorized the App signs in before the approval counts. For `'app'` tools the approval is a gate only.
- `attribution` (default `true`): a call that runs with a person's token is authored by them on GitHub, so `createPullRequest` ends the body with `Generated by [<app>](https://github.com/apps/<app>).` and `createOrUpdateFile`/`editFiles`/`mergePullRequest`/`enablePullRequestAutoMerge` add the App's bot as `Co-authored-by`. App-token calls add nothing. `false` turns both off; `{ footer, coAuthor }` picks. Don't also write a "generated by" line into the body yourself.
- `'user'`/`'caller'` need `connector`; `connect` configures App tokens and cannot be combined with `actAs: 'user'`.

One GitHub App installed on several accounts needs no configuration: each app token targets the installation owning the call's `owner/repo`, after `context` defaults. Tools without a repository target (search, gists, notifications) use the connector's default installation. Set `installationId`, `authorizationDetails` or `repositories` in `connect` to pin one installation; user subjects are left untouched. `connect` also accepts a custom `(ctx, call) => params` resolver, where `call` is `{ toolName, input, owner?, repo? }`. A missing installation surfaces as `CONNECT_INSTALLATION_REQUIRED` naming the account.
Expand Down
1 change: 1 addition & 0 deletions packages/github-tools-eve-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ channels/
| `token` | `string \| (() => Promise<string>)` (optional) | PAT string, or an async provider for rotating tokens (e.g. a GitHub App installation token) β€” the same `GithubTokenInput` the SDK accepts; falls back to `GITHUB_TOKEN` when omitted and `connector` is not set |
| `connector` | `string \| (() => string \| Promise<string>)` (optional) | Vercel Connect connector name, or a resolver to pick one dynamically (e.g. per environment/tenant); takes priority over `token` |
| `actAs` | `'app' \| 'user' \| 'caller' \| { read, write }` (optional) | Whose GitHub access the tools use when `connector` is set. `'app'` (default) uses the GitHub App installation. `'user'` runs each call with the signed-in eve user's own GitHub token, so the agent can do what that user can do on GitHub and nothing more; sessions without a signed-in user fail. `'caller'` uses the user when one drives the turn and the App otherwise (schedules, bots). Users who have not authorized the App get a sign-in prompt and never fall back to the App. Someone who comments on eve's GitHub channel can't sign in, so their call runs as the App once their own role on the target repository allows it (Read for a read, Write for a write), and fails with `CALLER_FORBIDDEN` otherwise. `{ read, write }` picks per tool kind, `overrides.<tool>.actAs` per tool. The default may change to `'caller'` in a future major version |
| `attribution` | `boolean \| { footer?, coAuthor? }` (optional) | Credit the GitHub App when a call runs with a person's token, since GitHub then records the person as the author. `createPullRequest` ends the body with `Generated by [<app>](https://github.com/apps/<app>).`, and the commit tools add the App's bot account to `coAuthors`. The App is read from the person's token, once per process. Calls that run as the App add nothing. Default `true`; `false` turns both off |
| `approvers` | `'requester' \| 'anyone'` (optional) | Who may answer an approval. `'requester'` (default) is only the person who asked, so a colleague cannot approve your request. `'anyone'` is an opt-in that lets any signed-in user approve and anyone deny; for `'user'` and `'caller'` tools the approved call runs with the approver's GitHub token, after they sign in |
| `connect` | `record \| ((ctx, call) => record)` (optional) | Passed through to `getToken` when `connector` is set. `connect.subject` defaults to `{ type: 'app' }` (the project's GitHub App installation); for per-user tokens, use `actAs`. App tokens target the installation owning each call's repository unless `installationId`, `authorizationDetails` or `repositories` pins one; pass a `(ctx, call) => record` resolver for other per-call rules |
| `preset` | preset name, array, or `'auto'` | `code-review`, `issue-triage`, `ci-ops`, `repo-explorer`, `security-audit`, `release-manager`, `discussion-moderator`, `notification-inbox`, `pr-author`, `maintainer`; `'auto'` lists the tools the session's first request needs and defers the rest |
Expand Down
24 changes: 24 additions & 0 deletions packages/github-tools-eve-extension/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ export type GithubExtensionActAs = GithubActAs | { read?: GithubActAs, write?: G
/** Who may answer an approval: only the requester, or any signed-in user. */
export type GithubExtensionApprovers = 'requester' | 'anyone'

/** Which credits `attribution` adds. Each defaults to `true`. */
export interface GithubExtensionAttribution {
/** End the body of a pull request with a line saying the App generated it. */
footer?: boolean
/** Add the App's bot account as `Co-authored-by` on commits. */
coAuthor?: boolean
}

/** Per-tool overrides, including the tool's own `actAs`. */
export type GithubExtensionToolOverrides = {
[K in GithubToolName]?: NonNullable<EveToolOverrides[K]> & { actAs?: GithubActAs }
Expand Down Expand Up @@ -142,6 +150,21 @@ export interface GithubExtensionConfig {
* `'caller'` in a future major version.
*/
actAs?: GithubExtensionActAs
/**
* Credit the GitHub App on what a person writes through it. When a call runs with a person's
* GitHub token (`actAs: 'user'`, or `'caller'` with a signed-in user), GitHub records that person
* as the author, so by default:
*
* - `createPullRequest` ends the body with `Generated by [<app>](https://github.com/apps/<app>).`
* - `createOrUpdateFile`, `editFiles`, `mergePullRequest` and `enablePullRequestAutoMerge` add the
* App's bot account to `coAuthors`, so the commit message carries
* `Co-authored-by: <app>[bot] <id+<app>[bot]@users.noreply.github.com>`.
*
* The App is read from the person's token, so the connector must be backed by a GitHub App.
* Calls that run as the App add nothing: the App is already their author. Pass `false` to turn
* both off, or `{ footer, coAuthor }` to pick.
*/
attribution?: boolean | GithubExtensionAttribution
/**
* Who may answer an approval.
*
Expand Down Expand Up @@ -244,6 +267,7 @@ const configSchema = z.object({
).optional(),
actAs: z.union([actAsSchema, z.object({ read: actAsSchema.optional(), write: actAsSchema.optional() })]).optional(),
approvers: z.enum(['requester', 'anyone']).optional(),
attribution: z.union([z.boolean(), z.object({ footer: z.boolean().optional(), coAuthor: z.boolean().optional() })]).optional(),
connect: z.union([
z.record(z.string(), z.unknown()),
z.custom<GithubExtensionConnectResolver>(value => typeof value === 'function'),
Expand Down
55 changes: 55 additions & 0 deletions packages/github-tools-eve-extension/extension/lib/attribution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { resolveGithubConnector } from '@github-tools/sdk/connect'
import {
GITHUB_COMMIT_TOOLS,
githubAppBot,
githubAppBotIdentity,
withGithubAppFooter,
type EveGithubToolsOptions,
type GithubAppBot,
type GithubToolName,
} from '@github-tools/sdk/eve-runtime'
import extension from '../extension'

// The App behind a connector never changes, so each process reads its bot once.
const bots = new Map<string, Promise<GithubAppBot>>()

async function appBot(token: string): Promise<GithubAppBot> {
const connector = await resolveGithubConnector(extension.config.connector!)
const cached = bots.get(connector)
if (cached) return cached
const bot = githubAppBot(token)
bots.set(connector, bot)
bot.catch(() => bots.delete(connector))
return bot
}

function credits() {
const { attribution = true } = extension.config
if (typeof attribution === 'boolean') return { footer: attribution, coAuthor: attribution }
return { footer: attribution.footer ?? true, coAuthor: attribution.coAuthor ?? true }
}

/**
* The input and options of a call that runs with a person's `token`, with the App credited as
* `attribution` asks: a footer on a new pull request, a co-author on a commit.
*/
export async function withAttribution(
name: GithubToolName,
args: Record<string, unknown>,
options: EveGithubToolsOptions,
token: string,
): Promise<{ args: Record<string, unknown>, options: EveGithubToolsOptions }> {
const { footer, coAuthor } = credits()
const addFooter = footer && name === 'createPullRequest'
const addCoAuthor = coAuthor && GITHUB_COMMIT_TOOLS.has(name)
if (!addFooter && !addCoAuthor) return { args, options: { ...options, token } }
const bot = await appBot(token)
return {
args: addFooter ? { ...args, body: withGithubAppFooter(args.body as string | undefined, bot) } : args,
options: {
...options,
token,
...(addCoAuthor && { coAuthors: [...options.coAuthors ?? [], githubAppBotIdentity(bot)] }),
},
}
}
11 changes: 9 additions & 2 deletions packages/github-tools-eve-extension/extension/tools/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
import type { ApprovalContext, ApprovalResponseContext, ApprovalResponseDecision, ApprovalResponsePolicy, ApprovalStatus } from 'eve/tools/approval'
import { defineDynamic, defineTool, type ToolContext, type ToolDefinition } from 'eve/tools'
import { z } from 'zod'
import { withAttribution } from '../lib/attribution'
import { githubCommenter } from '../lib/commenter'
import { sessionContext } from '../lib/context'
import extension, {
Expand Down Expand Up @@ -174,6 +175,12 @@ async function githubUserAuth() {
return connect(await resolveGithubConnector(extension.config.connector!))
}

// GitHub records the person whose token runs the call, so the App is credited on what it wrote for them.
async function runAsUser(name: GithubToolName, input: Record<string, unknown>, ctx: ToolContext, token: string) {
const { args, options } = await withAttribution(name, input, buildSessionOptions(ctx), token)
return executeGithubEveTool(name, args, options)
}

async function runGithubEveTool(name: GithubToolName, input: unknown, ctx: ToolContext) {
const args = input as Record<string, unknown>
if (extension.config.dryRun && writeToolName(name)) {
Expand All @@ -198,13 +205,13 @@ async function runGithubEveTool(name: GithubToolName, input: unknown, ctx: ToolC
const auth = await githubUserAuth()
if (approvedByOther) {
const { token } = await approver.getToken(auth)
return executeGithubEveTool(name, args, { ...buildSessionOptions(ctx), token })
return runAsUser(name, args, ctx, token)
}
if (actAs === 'caller' && !isUser(requester)) return executeGithubEveTool(name, args, buildSessionOptions(ctx))

const { token } = await ctx.getToken(auth)
try {
return await executeGithubEveTool(name, args, { ...buildSessionOptions(ctx), token })
return await runAsUser(name, args, ctx, token)
} catch (error) {
// A 401 means the user revoked the authorization: drop the token and ask them to sign in again.
if (isUnauthorized(error)) ctx.requireAuth(auth)
Expand Down
Loading
Loading