diff --git a/README.md b/README.md index f99c153..2607511 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/package.json b/package.json index 76437d4..c5078b2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/github/events.ts b/src/github/events.ts index a976c91..0cf1f50 100644 --- a/src/github/events.ts +++ b/src/github/events.ts @@ -2,14 +2,16 @@ import type { AgentName, TriggerRequest, TriggerSource } from "../types.js"; type AnyPayload = Record; -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; diff --git a/src/github/manifest.ts b/src/github/manifest.ts index c93e9b8..d3ef8c1 100644 --- a/src/github/manifest.ts +++ b/src/github/manifest.ts @@ -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", diff --git a/src/runner/prompt.ts b/src/runner/prompt.ts index 3eaae01..fd41a4c 100644 --- a/src/runner/prompt.ts +++ b/src/runner/prompt.ts @@ -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(), diff --git a/test/events.test.ts b/test/events.test.ts index b9f8b47..373b73a 100644 --- a/test/events.test.ts +++ b/test/events.test.ts @@ -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(); }); }); @@ -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({ @@ -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(); diff --git a/test/job-store.test.ts b/test/job-store.test.ts index 6f00de1..2664bd8 100644 --- a/test/job-store.test.ts +++ b/test/job-store.test.ts @@ -67,7 +67,7 @@ function trigger(overrides: Partial = {}): 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, diff --git a/test/router.test.ts b/test/router.test.ts index 523022b..66d6888 100644 --- a/test/router.test.ts +++ b/test/router.test.ts @@ -68,7 +68,7 @@ function trigger(overrides: Partial = {}): 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, diff --git a/test/runner.test.ts b/test/runner.test.ts index 5274b92..a4871b9 100644 --- a/test/runner.test.ts +++ b/test/runner.test.ts @@ -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",