惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
V
Vulnerabilities – Threatpost
C
CERT Recently Published Vulnerability Notes
Google DeepMind News
Google DeepMind News
GbyAI
GbyAI
Y
Y Combinator Blog
T
Threatpost
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Project Zero
Project Zero
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
MyScale Blog
MyScale Blog
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
量子位
I
Intezer
Simon Willison's Weblog
Simon Willison's Weblog
C
Cybersecurity and Infrastructure Security Agency CISA
L
Lohrmann on Cybersecurity
L
LINUX DO - 最新话题
The Register - Security
The Register - Security
T
Tailwind CSS Blog
爱范儿
爱范儿
Google DeepMind News
Google DeepMind News
T
Troy Hunt's Blog
Stack Overflow Blog
Stack Overflow Blog
Cloudbric
Cloudbric
S
Secure Thoughts
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
L
LangChain Blog
Recorded Future
Recorded Future
小众软件
小众软件
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Tor Project blog
人人都是产品经理
人人都是产品经理
F
Full Disclosure
O
OpenAI News
Webroot Blog
Webroot Blog
A
Arctic Wolf
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog
Jina AI
Jina AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
雷峰网
雷峰网
Microsoft Security Blog
Microsoft Security Blog
H
Heimdal Security Blog
B
Blog RSS Feed
Vercel News
Vercel News

Chat SDK Documentation

Approvals | Chat SDK Vercel Connect | Chat SDK Teams Low-Level APIs | Chat SDK CLI | Chat SDK Platform Adapters | Chat SDK State Adapters | Chat SDK Cards | Chat SDK Getting Started | Chat SDK Introduction | Chat SDK Modals | Chat SDK Slack Low-Level APIs | Chat SDK Streaming | Chat SDK Testing | Chat SDK Overview | Chat SDK toAiMessages | Chat SDK Cards | Chat SDK Overview | Chat SDK Markdown | Chat SDK Modals | Chat SDK AI SDK Tools | Chat SDK Types | Chat SDK Message Subject | Chat SDK Conversation History | Chat SDK Transcripts | Chat SDK Slack bot with Next.js and Redis Actions | Chat SDK Direct Messages | Chat SDK Emoji | Chat SDK Error Handling | Chat SDK File Uploads | Chat SDK Handling Events | Chat SDK Posting Messages | Chat SDK Slash Commands | Chat SDK State Adapters | Chat SDK Threads, Messages, and Channels | Chat SDK Creating a Chat Instance | Chat SDK WhatsApp Business Cloud Channel | Chat SDK Chat | Chat SDK Platform Adapters | Chat SDK Overlapping Messages | Chat SDK Ephemeral Messages | Chat SDK Message | Chat SDK Thread | Chat SDK Building a community adapter | Chat SDK Documenting your adapter | Chat SDK Publishing your adapter | Chat SDK Testing adapters | Chat SDK Discord support bot with Nuxt and Redis Durable chat sessions with Next.js, Workflow, and Redis Schedule Slack posts with Next.js, Workflow, and Neon PostableMessage | Chat SDK
Code review GitHub bot with Hono and Redis
Vercel · 2026-04-06 · via Chat SDK Documentation

This guide walks through building a GitHub bot that reviews pull requests on demand. When a user @mentions the bot on a PR, Chat SDK picks up the mention, spins up a Vercel Sandbox with the repo cloned, and uses AI SDK to analyze the diff.

  • Node.js 18+
  • pnpm (or npm/yarn)
  • A GitHub repository where you have admin access
  • A Redis instance for state management
  • A Vercel account

Scaffold a new Hono project and install dependencies:

pnpm create hono my-review-bot
cd my-review-bot
pnpm add @octokit/rest @vercel/functions @vercel/sandbox ai bash-tool chat @chat-adapter/github @chat-adapter/state-redis

Select the vercel template when prompted by create-hono. This sets up the project for Vercel deployment with the correct entry point.

  1. Go to your repository Settings then Webhooks then Add webhook
  2. Set Payload URL to https://your-domain.com/api/webhooks/github
  3. Set Content type to application/json
  4. Set a Secret and save it — you'll need this as GITHUB_WEBHOOK_SECRET
  5. Under Which events would you like to trigger this webhook?, select Let me select individual events and check:
    • Issue comments (for @mention on the PR conversation tab)
    • Pull request review comments (for @mention on inline review threads)

Get credentials

  1. Go to Settings > Developer settings > Personal access tokens and create a token with repo scope — you'll need this as GITHUB_TOKEN
  2. Copy the Webhook secret you set above — you'll need this as GITHUB_WEBHOOK_SECRET

Create a .env file in your project root:

GITHUB_TOKEN=ghp_your_personal_access_token
GITHUB_WEBHOOK_SECRET=your_webhook_secret
REDIS_URL=redis://localhost:6379
BOT_USERNAME=my-review-bot

The model (anthropic/claude-sonnet-4.6) uses AI Gateway. Develop locally by linking to your Vercel project with vc link then pulling your OIDC token with vc pull --environment development.

Create the core review logic. This clones the repo into a Vercel Sandbox, then uses AI SDK with a bash tool to let Claude analyze the diff and read files directly.

import { Sandbox } from "@vercel/sandbox";
import { ToolLoopAgent, stepCountIs } from "ai";
import { createBashTool } from "bash-tool";

interface ReviewInput {
  owner: string;
  repo: string;
  prBranch: string;
  baseBranch: string;
}

export async function reviewPullRequest(input: ReviewInput): Promise<string> {
  const { owner, repo, prBranch, baseBranch } = input;

  const sandbox = await Sandbox.create({
    source: {
      type: "git",
      url: `https://github.com/${owner}/${repo}`,
      username: "x-access-token",
      password: process.env.GITHUB_TOKEN,
      depth: 50,
    },
    timeout: 5 * 60 * 1000,
  });

  try {
    await sandbox.runCommand("git", ["fetch", "origin", prBranch, baseBranch]);
    await sandbox.runCommand("git", ["checkout", prBranch]);

    const diffResult = await sandbox.runCommand("git", [
      "diff",
      `origin/${baseBranch}...HEAD`,
    ]);
    const diff = await diffResult.output("stdout");

    const { tools } = await createBashTool({ sandbox });

    const agent = new ToolLoopAgent({
      model: "anthropic/claude-sonnet-4.6",
      tools,
      stopWhen: stepCountIs(20),
    });

    const result = await agent.generate({
      prompt: `You are reviewing a pull request for bugs and issues.

Here is the diff for this PR:

\`\`\`diff
${diff}
\`\`\`

Use the bash and readFile tools to inspect any files you need more context on.

Look for bugs, security issues, performance problems, and missing error handling.
Organize findings by severity (critical, warning, suggestion).
If the code looks good, say so.`,
    });

    return result.text;
  } finally {
    await sandbox.stop();
  }
}

The createBashTool gives the agent bash, readFile, and writeFile tools — all scoped to the sandbox. The agent can run git diff, read source files, and explore the repo freely without any code escaping the sandbox.

The function returns the review text instead of posting it directly. This lets the Chat SDK handler post it as a threaded reply.

Create a Chat instance with the GitHub adapter. When someone @mentions the bot on a PR, it fetches the PR metadata, runs the review, and posts the result back to the thread.

import { Chat } from "chat";
import { createGitHubAdapter } from "@chat-adapter/github";
import { createRedisState } from "@chat-adapter/state-redis";
import { Octokit } from "@octokit/rest";
import { reviewPullRequest } from "./review";
import type { GitHubRawMessage } from "@chat-adapter/github";

const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });

export const bot = new Chat({
  userName: process.env.BOT_USERNAME!,
  adapters: {
    github: createGitHubAdapter(),
  },
  state: createRedisState(),
});

bot.onNewMention(async (thread, message) => {
  const raw = message.raw as GitHubRawMessage;
  const { owner, repo, prNumber } = {
    owner: raw.repository.owner.login,
    repo: raw.repository.name,
    prNumber: raw.prNumber,
  };

  // Fetch PR branch info
  const { data: pr } = await octokit.pulls.get({
    owner,
    repo,
    pull_number: prNumber,
  });

  await thread.post("Starting code review...");
  await thread.subscribe();

  const review = await reviewPullRequest({
    owner,
    repo,
    prBranch: pr.head.ref,
    baseBranch: pr.base.ref,
  });

  await thread.post(review);
});

bot.onSubscribedMessage(async (thread, message) => {
  await thread.post(
    "I've already reviewed this PR. @mention me on a new PR to start another review."
  );
});

onNewMention fires when a user @mentions the bot — for example, @codereview can you review this?. The handler extracts the PR details from the message's raw payload, runs the sandboxed review, and posts the result. Calling thread.subscribe() lets the bot respond to follow-up messages in the same thread.

Create the Hono app with a single webhook route that delegates to Chat SDK:

import { Hono } from "hono";
import { waitUntil } from "@vercel/functions";
import { bot } from "./bot";

const app = new Hono();

app.post("/api/webhooks/github", async (c) => {
  const handler = bot.webhooks.github;
  if (!handler) {
    return c.text("GitHub adapter not configured", 404);
  }

  return handler(c.req.raw, { waitUntil });
});

export default app;

Chat SDK's GitHub adapter handles signature verification, event parsing, and routing internally. The waitUntil option ensures the review completes after the HTTP response is sent — required on serverless platforms where the function would otherwise terminate before your handlers finish.

  1. Start your development server (pnpm dev)
  2. Expose it with a tunnel (e.g. ngrok http 3000)
  3. Update the webhook URL in your GitHub repository settings to your tunnel URL
  4. Open a pull request
  5. Comment @my-review-bot can you review this? — the bot should respond with "Starting code review..." followed by the full review

Deploy your bot to Vercel:

vercel deploy

After deployment, set your environment variables in the Vercel dashboard (GITHUB_TOKEN, GITHUB_WEBHOOK_SECRET, REDIS_URL, BOT_USERNAME). Update the webhook URL in your GitHub repository settings to your production URL.

  • GitHub adapter — Authentication options, thread model, and full configuration reference
  • State Adapters — Production state adapters (Redis, PostgreSQL, ioredis) for subscriptions and distributed locking