Skip to content

Commit 0bd3fa2

Browse files
committed
add suggested fixes to inline comments, add thread url to review, refine prompt. other logic/schema cleanup
1 parent 05dab8e commit 0bd3fa2

File tree

11 files changed

+49
-80
lines changed

11 files changed

+49
-80
lines changed

config.yml

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
github:
22
base_url: "https://api.github.com"
33
check_name: "Amp Code Review"
4-
development_mode: true
5-
bot_username: "amp-code-review-agent"
64

75
queue:
86
max_workers: 20
97
max_queue_size: 100
108
retry_after_seconds: 60
119

12-
# Diff splitting configuration
13-
diff_splitting:
14-
max_chunk_size: 500000 # 500k characters per chunk
15-
max_concurrent: 3
10+
1611

1712
server:
1813
port: "${PORT:-5053}"
1914
debug: "${DEBUG:-false}"
2015

2116
amp:
22-
timeout: "${AMP_TIMEOUT}"
2317
command: "npx --yes @sourcegraph/amp@latest"
2418
server_url: "${AMP_SERVER_URL}"
2519
settings:
@@ -56,39 +50,40 @@ amp:
5650
5751
Review the diff content to identify issues. If you find any issues, leave specific inline comments for each issue found.
5852
59-
Always leave actionable, specific comments with suggested fixes.
60-
61-
Suggestions are optional snippets of code that can directly replace the full line the indicated issue is on. If provided, the suggestion should be just code-- no thought process included.
62-
If there is no simple code suggestion you can provide to fix the issue succinctly, provide null as the suggestion value instead.
63-
Suggestions can only be left on "new" line_type issues, not on "old" issues. For "old" issues, the suggestion should be null.
53+
Suggested fixes are optional snippets of code that can directly replace the full line the indicated issue is on for an inline comment.
54+
If there is no simple code suggestion you can provide to fix the issue succinctly, do not provide a suggested fix.
6455
6556
Tools available to complete the code review process:
6657
__TOOL_CONTENT__
6758
68-
After you have completed the code review process:
59+
After you have completed the code review process, leave a single general comment.
60+
This comment should NOT reiterate the issues already identified in inline comments. Instead, include:
61+
* A brief summary of the diff's changes; include the goal of the changes and what they affect
62+
* A tour of the changes-- recommend the best tour order for reviewing the changes. Identify the best place to start the review-— the part that conveys the core and helps in understanding the rest.
63+
* (Optional) Any minor or vague considerations that were not obvious enough to be left as an inline comment-- don't repeat any inline comments.
6964
70-
Leave a general comment summarizing the review, including:
71-
* A brief summary of the changes reviewed
72-
* List out critical issues and blockers that need to be addressed
73-
* Any high-level feedback or suggestions
65+
Keep your tone professional and concise when commenting. No emojis.
7466
7567
tools:
7668
- name: leave_general_comment
77-
description: Leave general comments on pull requests
69+
description: Leave general review comments on pull requests
7870
instructions:
79-
- "Use this tool to leave general comments on the pull request"
80-
- "This will post your comment to the overall pull request discussion"
81-
- "Use for summary comments, overall feedback, or general observations"
71+
- "Use this tool to leave a general review comment on the pull request"
72+
- "This will post your comment as the top level comment on a review"
8273
- "Required: message, owner, repo, pr_number"
83-
- "Example: 'Overall the code looks good, just a few minor suggestions'"
74+
- "Example: 'The changes look good, but there are a few issues that need to be addressed'"
8475
- name: leave_inline_comment
8576
description: Leave inline comments on specific lines in pull requests
8677
instructions:
8778
- "Use this tool to leave comments on specific lines of code"
8879
- "This will post your comment directly on the line in the diff view via PR review"
8980
- "Required: message, owner, repo, pr_number, path, line"
90-
- "Optional: commit_sha (will be fetched from PR if not provided)"
81+
- "Optional: suggested_fix - provide exact replacement code for obvious/trivial fixes only"
82+
- "For suggested_fix: only include the raw code replacement, no markdown formatting or explanations"
83+
- "Use suggested_fix for simple fixes like typos, missing semicolons, variable name corrections, etc."
84+
- "Do NOT use suggested_fix for complex changes, architectural decisions, or anything requiring explanation"
9185
- "Example: Comment on line 25 of src/auth.js about missing error handling"
86+
- "Example with fix: Comment on typo with suggested_fix: 'const userName = req.body.username;'"
9287
- name: get_pr_comments
9388
description: Get all comments on a pull request
9489
instructions:

src/config.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,19 @@ const ConfigSchema = z.object({
1212
base_url: z.string(),
1313
token: z.string().optional(),
1414
check_name: z.string(),
15-
development_mode: z.boolean(),
16-
bot_username: z.string(),
1715
webhook_secret: z.string().optional(),
1816
}),
1917
queue: z.object({
2018
max_workers: z.coerce.number(),
2119
max_queue_size: z.coerce.number(),
2220
retry_after_seconds: z.coerce.number(),
2321
}),
24-
diff_splitting: z.object({
25-
max_chunk_size: z.coerce.number(),
26-
max_concurrent: z.coerce.number(),
27-
}),
22+
2823
server: z.object({
2924
port: z.string(),
3025
debug: z.string(),
3126
}),
3227
amp: z.object({
33-
timeout: z.string(),
3428
command: z.string(),
3529
server_url: z.string(),
3630
settings: z.object({

src/github/process-review.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,16 @@ export async function processReview(
8686
console.log(`📝 Collected ${inlineComments.length} inline comments and ${generalComments.length} general comments`);
8787

8888
// Create review summary from general comments
89-
const reviewSummary = generalComments.length > 0
89+
let reviewSummary = generalComments.length > 0
9090
? generalComments.map(c => c.message).join('\n\n')
9191
: 'Code review completed.';
9292

93+
// Append Amp thread URL if available
94+
if (reviewResult.threadId && config.amp.server_url) {
95+
const threadUrl = `${config.amp.server_url}/threads/${reviewResult.threadId}`;
96+
reviewSummary += `\n\n[View this review on Amp](${threadUrl})`;
97+
}
98+
9399
// Post aggregated review
94100
console.log('📋 Posting aggregated PR review...');
95101
await githubClient.createPRReview(
@@ -101,7 +107,9 @@ export async function processReview(
101107
inlineComments.map(comment => ({
102108
path: comment.path,
103109
line: comment.line,
104-
body: comment.message
110+
body: comment.suggested_fix
111+
? `${comment.message}\n\n\`\`\`suggestion\n${comment.suggested_fix}\n\`\`\``
112+
: comment.message
105113
}))
106114
);
107115
console.log('✅ PR review posted successfully');

src/mcp/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Leave inline comments on specific lines in pull requests.
2323
- `pr_number` (number, required): Pull request number
2424
- `path` (string, required): File path for the inline comment
2525
- `line` (number, required): Line number for the inline comment
26-
- `commit_sha` (string, optional): Commit SHA (will be fetched if not provided)
2726

2827
### 3. `get_pr_comments`
2928
Get all comments on a pull request.
@@ -108,7 +107,7 @@ The tools are designed to work together in a typical code review workflow:
108107
## Development
109108

110109
The tools are organized in the `/src/mcp/tools/` directory:
111-
- `leave_comment.ts` - General comment functionality
110+
- `leave_general_comment.ts` - General comment functionality
112111
- `leave_inline_comment.ts` - Inline comment functionality
113112
- `get_pr_comments.ts` - PR comments retrieval
114113

src/mcp/comment-collector.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface CommentData {
55
message: string;
66
path?: string; // Only for inline comments
77
line?: number; // Only for inline comments
8+
suggested_fix?: string; // Only for inline comments
89
}
910

1011
export class FileBasedCommentCollector {
@@ -16,12 +17,13 @@ export class FileBasedCommentCollector {
1617
writeFileSync(this.filePath, '', 'utf8');
1718
}
1819

19-
addInlineComment(path: string, line: number, message: string): void {
20+
addInlineComment(path: string, line: number, message: string, suggested_fix?: string): void {
2021
const comment: CommentData = {
2122
type: 'inline',
2223
message,
2324
path,
24-
line
25+
line,
26+
suggested_fix
2527
};
2628

2729
this.appendComment(comment);

src/mcp/server.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
McpError,
1212
} from '@modelcontextprotocol/sdk/types.js';
1313
import { getConfig, Config } from '../config.js';
14-
import { leaveGeneralComment } from './tools/leave_comment.js';
14+
import { leaveGeneralComment } from './tools/leave_general_comment.js';
1515
import { leaveInlineComment } from './tools/leave_inline_comment.js';
1616
import { getPRComments } from './tools/get_pr_comments.js';
1717
import {
@@ -78,13 +78,13 @@ class GitHubMCPServer {
7878
},
7979
{
8080
name: 'leave_inline_comment',
81-
description: 'Leave inline comments on specific lines in pull requests',
81+
description: 'Leave inline comments on specific lines in pull requests. Can optionally include suggested fixes for trivial changes.',
8282
inputSchema: {
8383
type: 'object',
8484
properties: {
8585
message: {
8686
type: 'string',
87-
description: 'The comment message',
87+
description: 'The comment message explaining the issue or feedback',
8888
},
8989
owner: {
9090
type: 'string',
@@ -106,9 +106,9 @@ class GitHubMCPServer {
106106
type: 'number',
107107
description: 'Line number for the inline comment',
108108
},
109-
commit_sha: {
109+
suggested_fix: {
110110
type: 'string',
111-
description: 'Commit SHA (optional - will be fetched if not provided)',
111+
description: 'Optional code suggestion to replace the current line(s). Only provide this for obvious/trivial fixes. The suggestion should be the exact replacement code without any markdown formatting.',
112112
},
113113
},
114114
required: ['message', 'owner', 'repo', 'pr_number', 'path', 'line'],

src/mcp/tools/leave_inline_comment.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ export interface LeaveInlineCommentArgs {
44
message: string;
55
path: string;
66
line: number;
7-
commit_sha?: string;
7+
suggested_fix?: string;
88
}
99

1010
export async function leaveInlineComment(
1111
args: LeaveInlineCommentArgs
1212
): Promise<{ success: boolean; error?: string }> {
1313
try {
14-
const { message, path, line } = args;
14+
const { message, path, line, suggested_fix } = args;
1515

16-
console.log('📝 Collecting inline comment for later review:', { path, line });
16+
console.log('📝 Collecting inline comment for later review:', { path, line, hasSuggestion: !!suggested_fix });
1717

1818
const collector = getCollector();
1919
if (collector) {
20-
collector.addInlineComment(path, line, message);
20+
collector.addInlineComment(path, line, message, suggested_fix);
2121
} else {
2222
console.log('⚠️ No collector available, comment will be skipped');
2323
}

src/mcp/validation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { z } from 'zod';
2-
import { LeaveGeneralCommentArgs } from './tools/leave_comment.js';
2+
import { LeaveGeneralCommentArgs } from './tools/leave_general_comment.js';
33
import { LeaveInlineCommentArgs } from './tools/leave_inline_comment.js';
44
import { GetPRCommentsArgs } from './tools/get_pr_comments.js';
55

@@ -19,7 +19,7 @@ const LeaveInlineCommentArgsSchema = z.object({
1919
message: z.string(),
2020
path: z.string(),
2121
line: z.number(),
22-
commit_sha: z.string().optional(),
22+
suggested_fix: z.string().optional(),
2323
});
2424

2525

src/review/reviewer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { newThread, execute } from "../amp.js";
88

99
export const reviewDiff = async (
1010
diffContent: string,
11-
mrDetailsContent: string,
11+
prDetailsContent: string,
1212
installationId: number
1313
) => {
1414

@@ -26,7 +26,7 @@ export const reviewDiff = async (
2626
const ampConfig = config.amp;
2727

2828
let promptContent = ampConfig.prompt_template
29-
.replace(/__PR_DETAILS_CONTENT__/g, mrDetailsContent)
29+
.replace(/__PR_DETAILS_CONTENT__/g, prDetailsContent)
3030
.replace(/__DIFF_CONTENT__/g, diffContent);
3131

3232
// Add tools content

0 commit comments

Comments
 (0)