Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.
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: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# AgentRouter

AgentRouter is a GitHub App router for explicit agent mentions across personal and organization repositories. It lets one installed app listen across selected repos and queue work only when someone deliberately calls an agent.
AgentRouter is a GitHub App router for explicit SummonAgent commands across personal and organization repositories. It lets one installed app listen across selected repos and queue work only when someone deliberately calls an agent lane.

It listens for GitHub comments and reviews, validates that the sender is allowed to dispatch work, and creates jobs for:
It listens for GitHub comments and reviews, validates that the sender is allowed to dispatch work, and creates jobs from commands like:

- `@codex`
- `@claude`
- `@huma`
- `@SummonAgent codex fix this`
- `@SummonAgent claude review this`
- `@SummonAgent huma handle this`

The first version is intentionally conservative: it stores jobs locally, exposes a small runner API, and only dispatches when an exact mention is present. No ambient code review, no surprise bot activity, no repo-by-repo workflow file required.
The first version is intentionally conservative: it stores jobs locally, exposes a small runner API, and only dispatches when `@SummonAgent` is mentioned with a supported lane name. No ambient code review, no surprise bot activity, no repo-by-repo workflow file required.

## Quick Start

Expand Down Expand Up @@ -98,19 +98,20 @@ The runner resolves jobs to fixed local worktrees from `workspaceRoot` and `repo
}
```

For a `@codex` PR job on `fschrhunt/AgentRouter`, that maps to `/Volumes/Thorium/Projects/AgentRouter/codex` and requires the branch to already be `codex/workspace`.
For a `@SummonAgent codex` PR job on `fschrhunt/AgentRouter`, that maps to `/Volumes/Thorium/Projects/AgentRouter/codex` and requires the branch to already be `codex/workspace`.

## Safety Rules

- No agent runs unless a comment or review contains `@codex`, `@claude`, or `@huma`.
- No agent runs unless a comment or review contains `@SummonAgent` plus `codex`, `claude`, or `huma`.
- Raw `@codex`, `@claude`, and `@huma` mentions are ignored.
- Bot users are ignored.
- Senders must have `write`, `maintain`, or `admin` repository permission.
- Repositories can be allowlisted in `agent-router.config.json`.
- The runner claims jobs over an authenticated local API.
- PR fix jobs only run on fixed lane branches:
- `@codex` -> `codex/workspace`
- `@claude` -> `claude/workspace`
- `@huma` -> `huma/workspace`
- `@SummonAgent codex` -> `codex/workspace`
- `@SummonAgent claude` -> `claude/workspace`
- `@SummonAgent huma` -> `huma/workspace`
- AgentRouter blocks fork PRs and unexpected PR branches instead of creating new branches.

## Webhook Events
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"type": "module",
"description": "GitHub App router for @codex, @claude, and @huma agent mentions.",
"description": "GitHub App router for @SummonAgent codex, claude, and huma commands.",
"scripts": {
"dev": "tsx src/server/main.ts",
"runner": "tsx src/runner/main.ts",
Expand Down
12 changes: 7 additions & 5 deletions src/github/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import type { AgentName, TriggerRequest, TriggerSource } from "../types.js";

type AnyPayload = Record<string, any>;

const mentionPatterns: Array<[AgentName, RegExp]> = [
["codex", /\B@codex\b/i],
["claude", /\B@claude\b/i],
["huma", /\B@huma\b/i],
const summonMention = /\B@summonagent\b/i;
const commandPatterns: Array<[AgentName, RegExp]> = [
["codex", /\bcodex\b/i],
["claude", /\bclaude\b/i],
["huma", /\bhuma\b/i],
];

export function detectAgentMention(body: string): AgentName | null {
for (const [agent, pattern] of mentionPatterns) {
if (!summonMention.test(body)) return null;
for (const [agent, pattern] of commandPatterns) {
if (pattern.test(body)) return agent;
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/github/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function buildManifest(config: AppConfig, params: ManifestParams): Record
redirect_url: `${config.publicUrl}/setup/callback`,
callback_urls: [`${config.publicUrl}/setup/callback`],
setup_url: `${config.publicUrl}/setup/done`,
description: "Routes explicit @codex, @claude, and @huma GitHub mentions to local agent lanes.",
description: "Routes explicit @SummonAgent codex/claude/huma commands to local agent lanes.",
public: false,
default_permissions: {
contents: "read",
Expand Down
2 changes: 1 addition & 1 deletion src/runner/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface RunnerContext {
export function buildAgentPrompt(job: AgentJob, target: WorktreeTarget, context: RunnerContext): string {
const prUrl = `https://github.com/${job.repository}/pull/${job.targetNumber}`;
return [
`You were summoned from GitHub by @${job.agent}.`,
`You were summoned from GitHub by @SummonAgent ${job.agent}.`,
"",
"Task:",
job.body.trim(),
Expand Down
25 changes: 16 additions & 9 deletions test/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ import { describe, expect, it } from "vitest";
import { detectAgentMention, normalizeGitHubEvent } from "../src/github/events.js";

describe("detectAgentMention", () => {
it("detects exact supported mentions", () => {
expect(detectAgentMention("please @codex fix this")).toBe("codex");
expect(detectAgentMention("@claude review this")).toBe("claude");
expect(detectAgentMention("route to @huma")).toBe("huma");
it("detects supported agent commands after SummonAgent is mentioned", () => {
expect(detectAgentMention("@SummonAgent codex fix this")).toBe("codex");
expect(detectAgentMention("@summonagent claude review this")).toBe("claude");
expect(detectAgentMention("route to @SummonAgent huma")).toBe("huma");
});

it("ignores partial words", () => {
expect(detectAgentMention("email@codexample.com")).toBeNull();
expect(detectAgentMention("@codexify")).toBeNull();
it("does not trigger on raw agent mentions", () => {
expect(detectAgentMention("please @codex fix this")).toBeNull();
expect(detectAgentMention("@claude review this")).toBeNull();
expect(detectAgentMention("route to @huma")).toBeNull();
});

it("ignores partial words and missing lane commands", () => {
expect(detectAgentMention("email@summonagentx codex")).toBeNull();
expect(detectAgentMention("@SummonAgent codexify")).toBeNull();
expect(detectAgentMention("@SummonAgent please fix this")).toBeNull();
});
});

Expand All @@ -21,7 +28,7 @@ describe("normalizeGitHubEvent", () => {
installation: { id: 123 },
repository: { full_name: "fschrhunt/AgentRouter" },
issue: { number: 7, html_url: "https://github.com/fschrhunt/AgentRouter/issues/7" },
comment: { body: "@codex make it so", html_url: "https://github.com/comment" },
comment: { body: "@SummonAgent codex make it so", html_url: "https://github.com/comment" },
});

expect(trigger).toMatchObject({
Expand All @@ -40,7 +47,7 @@ describe("normalizeGitHubEvent", () => {
installation: { id: 123 },
repository: { full_name: "fschrhunt/AgentRouter" },
issue: { number: 7 },
comment: { body: "@codex make it so" },
comment: { body: "@SummonAgent codex make it so" },
});

expect(trigger).toBeNull();
Expand Down
2 changes: 1 addition & 1 deletion test/job-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function trigger(overrides: Partial<TriggerRequest> = {}): TriggerRequest {
actor: "fschrhunt",
targetNumber: 1,
isPullRequest: false,
body: "@codex hello",
body: "@SummonAgent codex hello",
htmlUrl: "https://github.com/fschrhunt/AgentRouter/issues/1#issuecomment-1",
installationId: 123,
...overrides,
Expand Down
2 changes: 1 addition & 1 deletion test/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function trigger(overrides: Partial<TriggerRequest> = {}): TriggerRequest {
actor: "fschrhunt",
targetNumber: 1,
isPullRequest: true,
body: "@codex fix this",
body: "@SummonAgent codex fix this",
htmlUrl: "https://github.com/fschrhunt/AgentRouter/pull/1#issuecomment-1",
installationId: 123,
...overrides,
Expand Down
2 changes: 1 addition & 1 deletion test/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function job(): AgentJob {
actor: "fschrhunt",
targetNumber: 5,
isPullRequest: true,
body: "@codex fix the failing check",
body: "@SummonAgent codex fix the failing check",
htmlUrl: "https://github.com/fschrhunt/AgentRouter/pull/5#issuecomment-1",
installationId: 123,
pullRequestHeadBranch: "codex/workspace",
Expand Down
Loading