mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
feat: simplify to two modes (tag and agent) for v1.0
BREAKING CHANGES: - Remove review mode entirely - now handled via slash commands in agent mode - Remove all deprecated backward compatibility fields (mode, anthropic_model, override_prompt, direct_prompt) - Simplify mode detection: prompt overrides everything, then @claude mentions trigger tag mode, default is agent mode - Remove slash command resolution from GitHub Action - Claude Code handles natively - Remove variable substitution - prompts passed through as-is Architecture changes: - Only two modes now: tag (for @claude mentions) and agent (everything else) - Agent mode is the default for all events including PRs - Users configure behavior via prompts/slash commands (e.g. /review) - GitHub Action is now a thin wrapper that passes prompts to Claude Code - Mode names changed: 'experimental-review' → removed entirely This aligns with the philosophy that the GitHub Action should do minimal work and delegate to Claude Code for all intelligent behavior.
This commit is contained in:
@@ -48,13 +48,10 @@ export const agentMode: Mode = {
|
||||
await mkdir(`${process.env.RUNNER_TEMP}/claude-prompts`, {
|
||||
recursive: true,
|
||||
});
|
||||
// Write the prompt file - the base action requires a prompt_file parameter,
|
||||
// so we must create this file even though agent mode typically uses
|
||||
// override_prompt or direct_prompt. If neither is provided, we write
|
||||
// a minimal prompt with just the repository information.
|
||||
// Write the prompt file - the base action requires a prompt_file parameter.
|
||||
// Use the unified prompt field from v1.0.
|
||||
const promptContent =
|
||||
context.inputs.overridePrompt ||
|
||||
context.inputs.directPrompt ||
|
||||
context.inputs.prompt ||
|
||||
`Repository: ${context.repository.owner}/${context.repository.repo}`;
|
||||
await writeFile(
|
||||
`${process.env.RUNNER_TEMP}/claude-prompts/claude-prompt.txt`,
|
||||
@@ -117,13 +114,9 @@ export const agentMode: Mode = {
|
||||
},
|
||||
|
||||
generatePrompt(context: PreparedContext): string {
|
||||
// Agent mode uses override or direct prompt, no GitHub data needed
|
||||
if (context.overridePrompt) {
|
||||
return context.overridePrompt;
|
||||
}
|
||||
|
||||
if (context.directPrompt) {
|
||||
return context.directPrompt;
|
||||
// Agent mode uses prompt field
|
||||
if (context.prompt) {
|
||||
return context.prompt;
|
||||
}
|
||||
|
||||
// Minimal fallback - repository is a string in PreparedContext
|
||||
|
||||
@@ -1,24 +1,20 @@
|
||||
import type { GitHubContext } from "../github/context";
|
||||
import {
|
||||
isEntityContext,
|
||||
isAutomationContext,
|
||||
isPullRequestEvent,
|
||||
isIssueCommentEvent,
|
||||
isPullRequestReviewCommentEvent,
|
||||
} from "../github/context";
|
||||
import { checkContainsTrigger } from "../github/validation/trigger";
|
||||
|
||||
export type AutoDetectedMode = "review" | "tag" | "agent";
|
||||
export type AutoDetectedMode = "tag" | "agent";
|
||||
|
||||
export function detectMode(context: GitHubContext): AutoDetectedMode {
|
||||
if (isPullRequestEvent(context)) {
|
||||
const allowedActions = ["opened", "synchronize", "reopened"];
|
||||
const action = context.payload.action;
|
||||
if (allowedActions.includes(action)) {
|
||||
return "review";
|
||||
}
|
||||
// If prompt is provided, always use agent mode
|
||||
if (context.inputs?.prompt) {
|
||||
return "agent";
|
||||
}
|
||||
|
||||
// Check for @claude mentions (tag mode)
|
||||
if (isEntityContext(context)) {
|
||||
if (
|
||||
isIssueCommentEvent(context) ||
|
||||
@@ -36,21 +32,16 @@ export function detectMode(context: GitHubContext): AutoDetectedMode {
|
||||
}
|
||||
}
|
||||
|
||||
if (isAutomationContext(context)) {
|
||||
return "agent";
|
||||
}
|
||||
|
||||
// Default to agent mode for everything else
|
||||
return "agent";
|
||||
}
|
||||
|
||||
export function getModeDescription(mode: AutoDetectedMode): string {
|
||||
switch (mode) {
|
||||
case "review":
|
||||
return "Automated code review mode for pull requests";
|
||||
case "tag":
|
||||
return "Interactive mode triggered by @claude mentions";
|
||||
case "agent":
|
||||
return "Automation mode for scheduled tasks and workflows";
|
||||
return "General automation mode for all events";
|
||||
default:
|
||||
return "Unknown mode";
|
||||
}
|
||||
@@ -65,12 +56,10 @@ export function getDefaultPromptForMode(
|
||||
context: GitHubContext,
|
||||
): string | undefined {
|
||||
switch (mode) {
|
||||
case "review":
|
||||
return "/review";
|
||||
case "tag":
|
||||
return undefined;
|
||||
case "agent":
|
||||
return context.inputs?.directPrompt || context.inputs?.overridePrompt;
|
||||
return context.inputs?.prompt;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -8,11 +8,10 @@
|
||||
import type { Mode, ModeName } from "./types";
|
||||
import { tagMode } from "./tag";
|
||||
import { agentMode } from "./agent";
|
||||
import { reviewMode } from "./review";
|
||||
import type { GitHubContext } from "../github/context";
|
||||
import { detectMode, type AutoDetectedMode } from "./detector";
|
||||
|
||||
export const VALID_MODES = ["tag", "agent", "review"] as const;
|
||||
export const VALID_MODES = ["tag", "agent"] as const;
|
||||
|
||||
/**
|
||||
* All available modes in v1.0
|
||||
@@ -20,28 +19,19 @@ export const VALID_MODES = ["tag", "agent", "review"] as const;
|
||||
const modes = {
|
||||
tag: tagMode,
|
||||
agent: agentMode,
|
||||
review: reviewMode,
|
||||
} as const satisfies Record<AutoDetectedMode, Mode>;
|
||||
|
||||
/**
|
||||
* Automatically detects and retrieves the appropriate mode based on the GitHub context.
|
||||
* In v1.0, modes are auto-selected based on event type.
|
||||
* @param context The GitHub context
|
||||
* @param explicitMode Optional explicit mode override (for backward compatibility)
|
||||
* @returns The appropriate mode for the context
|
||||
*/
|
||||
export function getMode(context: GitHubContext, explicitMode?: string): Mode {
|
||||
let modeName: AutoDetectedMode;
|
||||
|
||||
if (explicitMode && isValidModeV1(explicitMode)) {
|
||||
console.log(`Using explicit mode: ${explicitMode}`);
|
||||
modeName = mapLegacyMode(explicitMode);
|
||||
} else {
|
||||
modeName = detectMode(context);
|
||||
console.log(
|
||||
`Auto-detected mode: ${modeName} for event: ${context.eventName}`,
|
||||
);
|
||||
}
|
||||
export function getMode(context: GitHubContext): Mode {
|
||||
const modeName = detectMode(context);
|
||||
console.log(
|
||||
`Auto-detected mode: ${modeName} for event: ${context.eventName}`,
|
||||
);
|
||||
|
||||
const mode = modes[modeName];
|
||||
if (!mode) {
|
||||
@@ -54,29 +44,11 @@ export function getMode(context: GitHubContext, explicitMode?: string): Mode {
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps legacy mode names to v1.0 mode names
|
||||
*/
|
||||
function mapLegacyMode(name: string): AutoDetectedMode {
|
||||
if (name === "experimental-review") {
|
||||
return "review";
|
||||
}
|
||||
return name as AutoDetectedMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard to check if a string is a valid v1.0 mode name.
|
||||
* Type guard to check if a string is a valid mode name.
|
||||
* @param name The string to check
|
||||
* @returns True if the name is a valid mode name
|
||||
*/
|
||||
export function isValidModeV1(name: string): boolean {
|
||||
const v1Modes = ["tag", "agent", "review", "experimental-review"];
|
||||
return v1Modes.includes(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy type guard for backward compatibility
|
||||
* @deprecated Use auto-detection instead
|
||||
*/
|
||||
export function isValidMode(name: string): name is ModeName {
|
||||
return isValidModeV1(name);
|
||||
const validModes = ["tag", "agent"];
|
||||
return validModes.includes(name);
|
||||
}
|
||||
|
||||
@@ -1,362 +0,0 @@
|
||||
import * as core from "@actions/core";
|
||||
import type { Mode, ModeOptions, ModeResult } from "../types";
|
||||
import { checkContainsTrigger } from "../../github/validation/trigger";
|
||||
import { prepareMcpConfig } from "../../mcp/install-mcp-server";
|
||||
import { fetchGitHubData } from "../../github/data/fetcher";
|
||||
import type { FetchDataResult } from "../../github/data/fetcher";
|
||||
import { createPrompt } from "../../create-prompt";
|
||||
import type { PreparedContext } from "../../create-prompt";
|
||||
import { isEntityContext, isPullRequestEvent } from "../../github/context";
|
||||
import {
|
||||
formatContext,
|
||||
formatBody,
|
||||
formatComments,
|
||||
formatReviewComments,
|
||||
formatChangedFilesWithSHA,
|
||||
} from "../../github/data/formatter";
|
||||
|
||||
/**
|
||||
* Review mode implementation.
|
||||
*
|
||||
* Code review mode that uses the default GitHub Action token
|
||||
* and focuses on providing inline comments and suggestions.
|
||||
* Automatically includes GitHub MCP tools for review operations.
|
||||
*/
|
||||
export const reviewMode: Mode = {
|
||||
name: "experimental-review",
|
||||
description:
|
||||
"Experimental code review mode for inline comments and suggestions",
|
||||
|
||||
shouldTrigger(context) {
|
||||
if (!isEntityContext(context)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Review mode only works on PRs
|
||||
if (!context.isPR) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// For pull_request events, only trigger on specific actions
|
||||
if (isPullRequestEvent(context)) {
|
||||
const allowedActions = ["opened", "synchronize", "reopened"];
|
||||
const action = context.payload.action;
|
||||
return allowedActions.includes(action);
|
||||
}
|
||||
|
||||
// For other events (comments), check for trigger phrase
|
||||
return checkContainsTrigger(context);
|
||||
},
|
||||
|
||||
prepareContext(context, data) {
|
||||
return {
|
||||
mode: "experimental-review",
|
||||
githubContext: context,
|
||||
commentId: data?.commentId,
|
||||
baseBranch: data?.baseBranch,
|
||||
claudeBranch: data?.claudeBranch,
|
||||
};
|
||||
},
|
||||
|
||||
getAllowedTools() {
|
||||
return [
|
||||
// Context tools - to know who the current user is
|
||||
"mcp__github__get_me",
|
||||
// Core review tools
|
||||
"mcp__github__create_pending_pull_request_review",
|
||||
"mcp__github__add_comment_to_pending_review",
|
||||
"mcp__github__submit_pending_pull_request_review",
|
||||
"mcp__github__delete_pending_pull_request_review",
|
||||
"mcp__github__create_and_submit_pull_request_review",
|
||||
// Comment tools
|
||||
"mcp__github__add_issue_comment",
|
||||
// PR information tools
|
||||
"mcp__github__get_pull_request",
|
||||
"mcp__github__get_pull_request_reviews",
|
||||
"mcp__github__get_pull_request_status",
|
||||
];
|
||||
},
|
||||
|
||||
getDisallowedTools() {
|
||||
return [];
|
||||
},
|
||||
|
||||
shouldCreateTrackingComment() {
|
||||
return false; // Review mode uses the review body instead of a tracking comment
|
||||
},
|
||||
|
||||
generatePrompt(
|
||||
context: PreparedContext,
|
||||
githubData: FetchDataResult,
|
||||
): string {
|
||||
// Support v1.0 unified prompt or legacy overridePrompt
|
||||
const userPrompt = context.prompt || context.overridePrompt;
|
||||
if (userPrompt) {
|
||||
return userPrompt;
|
||||
}
|
||||
|
||||
// Default to /review slash command content
|
||||
// This will be expanded by the slash command system
|
||||
|
||||
const {
|
||||
contextData,
|
||||
comments,
|
||||
changedFilesWithSHA,
|
||||
reviewData,
|
||||
imageUrlMap,
|
||||
} = githubData;
|
||||
const { eventData } = context;
|
||||
|
||||
const formattedContext = formatContext(contextData, true); // Reviews are always for PRs
|
||||
const formattedComments = formatComments(comments, imageUrlMap);
|
||||
const formattedReviewComments = formatReviewComments(
|
||||
reviewData,
|
||||
imageUrlMap,
|
||||
);
|
||||
const formattedChangedFiles =
|
||||
formatChangedFilesWithSHA(changedFilesWithSHA);
|
||||
const formattedBody = contextData?.body
|
||||
? formatBody(contextData.body, imageUrlMap)
|
||||
: "No description provided";
|
||||
|
||||
return `You are Claude, an AI assistant specialized in code reviews for GitHub pull requests. You are operating in REVIEW MODE, which means you should focus on providing thorough code review feedback using GitHub MCP tools for inline comments and suggestions.
|
||||
|
||||
<formatted_context>
|
||||
${formattedContext}
|
||||
</formatted_context>
|
||||
|
||||
<repository>${context.repository}</repository>
|
||||
${eventData.isPR && eventData.prNumber ? `<pr_number>${eventData.prNumber}</pr_number>` : ""}
|
||||
|
||||
<comments>
|
||||
${formattedComments || "No comments yet"}
|
||||
</comments>
|
||||
|
||||
<review_comments>
|
||||
${formattedReviewComments || "No review comments"}
|
||||
</review_comments>
|
||||
|
||||
<changed_files>
|
||||
${formattedChangedFiles}
|
||||
</changed_files>
|
||||
|
||||
<formatted_body>
|
||||
${formattedBody}
|
||||
</formatted_body>
|
||||
|
||||
${
|
||||
(eventData.eventName === "issue_comment" ||
|
||||
eventData.eventName === "pull_request_review_comment" ||
|
||||
eventData.eventName === "pull_request_review") &&
|
||||
eventData.commentBody
|
||||
? `<trigger_comment>
|
||||
User @${context.triggerUsername}: ${eventData.commentBody}
|
||||
</trigger_comment>`
|
||||
: ""
|
||||
}
|
||||
|
||||
${
|
||||
context.directPrompt
|
||||
? `<direct_prompt>
|
||||
${context.directPrompt}
|
||||
</direct_prompt>`
|
||||
: ""
|
||||
}
|
||||
|
||||
REVIEW MODE WORKFLOW:
|
||||
|
||||
1. First, understand the PR context:
|
||||
- You are reviewing PR #${eventData.isPR && eventData.prNumber ? eventData.prNumber : "[PR number]"} in ${context.repository}
|
||||
- Use mcp__github__get_pull_request to get PR metadata
|
||||
- Use the Read, Grep, and Glob tools to examine the modified files directly from disk
|
||||
- This provides the full context and latest state of the code
|
||||
- Look at the changed_files section above to see which files were modified
|
||||
|
||||
2. Create a pending review:
|
||||
- Use mcp__github__create_pending_pull_request_review to start your review
|
||||
- This allows you to batch comments before submitting
|
||||
|
||||
3. Add inline comments:
|
||||
- Use mcp__github__add_comment_to_pending_review for each issue or suggestion
|
||||
- Parameters:
|
||||
* path: The file path (e.g., "src/index.js")
|
||||
* line: Line number for single-line comments
|
||||
* startLine & line: For multi-line comments (startLine is the first line, line is the last)
|
||||
* side: "LEFT" (old code) or "RIGHT" (new code)
|
||||
* subjectType: "line" for line-level comments
|
||||
* body: Your comment text
|
||||
|
||||
- When to use multi-line comments:
|
||||
* When replacing multiple consecutive lines
|
||||
* When the fix requires changes across several lines
|
||||
* Example: To replace lines 19-20, use startLine: 19, line: 20
|
||||
|
||||
- For code suggestions, use this EXACT format in the body:
|
||||
\`\`\`suggestion
|
||||
corrected code here
|
||||
\`\`\`
|
||||
|
||||
CRITICAL: GitHub suggestion blocks must ONLY contain the replacement for the specific line(s) being commented on:
|
||||
- For single-line comments: Replace ONLY that line
|
||||
- For multi-line comments: Replace ONLY the lines in the range
|
||||
- Do NOT include surrounding context or function signatures
|
||||
- Do NOT suggest changes that span beyond the commented lines
|
||||
|
||||
Example for line 19 \`var name = user.name;\`:
|
||||
WRONG:
|
||||
\\\`\\\`\\\`suggestion
|
||||
function processUser(user) {
|
||||
if (!user) throw new Error('Invalid user');
|
||||
const name = user.name;
|
||||
\\\`\\\`\\\`
|
||||
|
||||
CORRECT:
|
||||
\\\`\\\`\\\`suggestion
|
||||
const name = user.name;
|
||||
\\\`\\\`\\\`
|
||||
|
||||
For validation suggestions, comment on the function declaration line or create separate comments for each concern.
|
||||
|
||||
4. Submit your review:
|
||||
- Use mcp__github__submit_pending_pull_request_review
|
||||
- Parameters:
|
||||
* event: "COMMENT" (general feedback), "REQUEST_CHANGES" (issues found), or "APPROVE" (if appropriate)
|
||||
* body: Write a comprehensive review summary that includes:
|
||||
- Overview of what was reviewed (files, scope, focus areas)
|
||||
- Summary of all issues found (with counts by severity if applicable)
|
||||
- Key recommendations and action items
|
||||
- Highlights of good practices observed
|
||||
- Overall assessment and recommendation
|
||||
- The body should be detailed and informative since it's the main review content
|
||||
- Structure the body with clear sections using markdown headers
|
||||
|
||||
REVIEW GUIDELINES:
|
||||
|
||||
- Focus on:
|
||||
* Security vulnerabilities
|
||||
* Bugs and logic errors
|
||||
* Performance issues
|
||||
* Code quality and maintainability
|
||||
* Best practices and standards
|
||||
* Edge cases and error handling
|
||||
|
||||
- Provide:
|
||||
* Specific, actionable feedback
|
||||
* Code suggestions when possible (following GitHub's format exactly)
|
||||
* Clear explanations of issues
|
||||
* Constructive criticism
|
||||
* Recognition of good practices
|
||||
* For complex changes that require multiple modifications:
|
||||
- Create separate comments for each logical change
|
||||
- Or explain the full solution in text without a suggestion block
|
||||
|
||||
- Communication:
|
||||
* All feedback goes through GitHub's review system
|
||||
* Be professional and respectful
|
||||
* Your review body is the main communication channel
|
||||
|
||||
Before starting, analyze the PR inside <analysis> tags:
|
||||
<analysis>
|
||||
- PR title and description
|
||||
- Number of files changed and scope
|
||||
- Type of changes (feature, bug fix, refactor, etc.)
|
||||
- Key areas to focus on
|
||||
- Review strategy
|
||||
</analysis>
|
||||
|
||||
Then proceed with the review workflow described above.
|
||||
|
||||
IMPORTANT: Your review body is the primary way users will understand your feedback. Make it comprehensive and well-structured with:
|
||||
- Executive summary at the top
|
||||
- Detailed findings organized by severity or category
|
||||
- Clear action items and recommendations
|
||||
- Recognition of good practices
|
||||
This ensures users get value from the review even before checking individual inline comments.`;
|
||||
},
|
||||
|
||||
async prepare({
|
||||
context,
|
||||
octokit,
|
||||
githubToken,
|
||||
}: ModeOptions): Promise<ModeResult> {
|
||||
if (!isEntityContext(context)) {
|
||||
throw new Error("Review mode requires entity context");
|
||||
}
|
||||
|
||||
// Review mode doesn't create a tracking comment
|
||||
const githubData = await fetchGitHubData({
|
||||
octokits: octokit,
|
||||
repository: `${context.repository.owner}/${context.repository.repo}`,
|
||||
prNumber: context.entityNumber.toString(),
|
||||
isPR: context.isPR,
|
||||
triggerUsername: context.actor,
|
||||
});
|
||||
|
||||
// Review mode doesn't need branch setup or git auth since it only creates comments
|
||||
// Using minimal branch info since review mode doesn't create or modify branches
|
||||
const branchInfo = {
|
||||
baseBranch: "main",
|
||||
currentBranch: "",
|
||||
claudeBranch: undefined, // Review mode doesn't create branches
|
||||
};
|
||||
|
||||
const modeContext = this.prepareContext(context, {
|
||||
baseBranch: branchInfo.baseBranch,
|
||||
claudeBranch: branchInfo.claudeBranch,
|
||||
});
|
||||
|
||||
await createPrompt(reviewMode, modeContext, githubData, context);
|
||||
|
||||
// Export tool environment variables for review mode
|
||||
const baseTools = [
|
||||
"Edit",
|
||||
"MultiEdit",
|
||||
"Glob",
|
||||
"Grep",
|
||||
"LS",
|
||||
"Read",
|
||||
"Write",
|
||||
];
|
||||
|
||||
// Add mode-specific and user-specified tools
|
||||
const allowedTools = [
|
||||
...baseTools,
|
||||
...this.getAllowedTools(),
|
||||
...context.inputs.allowedTools,
|
||||
];
|
||||
const disallowedTools = [
|
||||
"WebSearch",
|
||||
"WebFetch",
|
||||
...context.inputs.disallowedTools,
|
||||
];
|
||||
|
||||
// Export as INPUT_ prefixed variables for the base action
|
||||
core.exportVariable("INPUT_ALLOWED_TOOLS", allowedTools.join(","));
|
||||
core.exportVariable("INPUT_DISALLOWED_TOOLS", disallowedTools.join(","));
|
||||
|
||||
const additionalMcpConfig = process.env.MCP_CONFIG || "";
|
||||
const mcpConfig = await prepareMcpConfig({
|
||||
githubToken,
|
||||
owner: context.repository.owner,
|
||||
repo: context.repository.repo,
|
||||
branch: branchInfo.claudeBranch || branchInfo.currentBranch,
|
||||
baseBranch: branchInfo.baseBranch,
|
||||
additionalMcpConfig,
|
||||
allowedTools: [...this.getAllowedTools(), ...context.inputs.allowedTools],
|
||||
context,
|
||||
});
|
||||
|
||||
core.setOutput("mcp_config", mcpConfig);
|
||||
|
||||
return {
|
||||
branchInfo,
|
||||
mcpConfig,
|
||||
};
|
||||
},
|
||||
|
||||
getSystemPrompt() {
|
||||
// Review mode doesn't need additional system prompts
|
||||
// The review-specific instructions are included in the main prompt
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
@@ -3,7 +3,7 @@ import type { PreparedContext } from "../create-prompt/types";
|
||||
import type { FetchDataResult } from "../github/data/fetcher";
|
||||
import type { Octokits } from "../github/api/client";
|
||||
|
||||
export type ModeName = "tag" | "agent" | "experimental-review" | "review";
|
||||
export type ModeName = "tag" | "agent";
|
||||
|
||||
export type ModeContext = {
|
||||
mode: ModeName;
|
||||
@@ -25,8 +25,8 @@ export type ModeData = {
|
||||
* and tracking comment creation.
|
||||
*
|
||||
* Current modes include:
|
||||
* - 'tag': Traditional implementation triggered by mentions/assignments
|
||||
* - 'agent': For automation with no trigger checking
|
||||
* - 'tag': Interactive mode triggered by @claude mentions
|
||||
* - 'agent': General automation mode for all events (default)
|
||||
*/
|
||||
export type Mode = {
|
||||
name: ModeName;
|
||||
|
||||
Reference in New Issue
Block a user