codex-review-mcp 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mcp-server.js
CHANGED
@@ -6,7 +6,7 @@ import { performCodeReview } from './tools/performCodeReview.js';
|
|
6
6
|
const server = new McpServer({ name: 'codex-review-mcp', version: '0.1.0' });
|
7
7
|
server.registerTool('perform_code_review', {
|
8
8
|
title: 'Perform Code Review',
|
9
|
-
description: 'Review git diffs in the current repo and return actionable Markdown feedback.',
|
9
|
+
description: 'Review git diffs in the current repo and return actionable Markdown feedback. In auto mode (default), reviews uncommitted changes if present, otherwise reviews current branch vs default branch. No need to commit changes first - the tool reviews your working tree.',
|
10
10
|
inputSchema: {
|
11
11
|
target: z.enum(['auto', 'staged', 'head', 'range']).default('auto'),
|
12
12
|
baseRef: z.string().optional(),
|
@@ -54,8 +54,14 @@ export async function collectDiff(input, workspaceDir) {
|
|
54
54
|
// Branch doesn't exist, try next
|
55
55
|
}
|
56
56
|
}
|
57
|
-
// Last resort: use HEAD~1 as baseline
|
58
|
-
|
57
|
+
// Last resort: use HEAD~1 as baseline if it exists
|
58
|
+
try {
|
59
|
+
await exec('git', ['rev-parse', '--verify', 'HEAD~1'], { cwd: repoRoot });
|
60
|
+
return 'HEAD~1';
|
61
|
+
}
|
62
|
+
catch {
|
63
|
+
return null;
|
64
|
+
}
|
59
65
|
}
|
60
66
|
async function hasUncommittedChanges(repoRoot) {
|
61
67
|
try {
|
@@ -75,6 +81,15 @@ export async function collectDiff(input, workspaceDir) {
|
|
75
81
|
return null;
|
76
82
|
}
|
77
83
|
}
|
84
|
+
async function hasHeadCommit(repoRoot) {
|
85
|
+
try {
|
86
|
+
await exec('git', ['rev-parse', '--verify', 'HEAD'], { cwd: repoRoot });
|
87
|
+
return true;
|
88
|
+
}
|
89
|
+
catch {
|
90
|
+
return false;
|
91
|
+
}
|
92
|
+
}
|
78
93
|
// Priority order: explicit workspaceDir param > env vars > process.cwd()
|
79
94
|
const preferredStart = workspaceDir || process.env.CODEX_REPO_ROOT || process.env.WORKSPACE_ROOT || process.env.INIT_CWD || process.cwd();
|
80
95
|
const preferredRoot = await findRepoRoot(preferredStart);
|
@@ -88,13 +103,22 @@ export async function collectDiff(input, workspaceDir) {
|
|
88
103
|
// Auto mode: detect what to review
|
89
104
|
const hasChanges = await hasUncommittedChanges(repoRoot);
|
90
105
|
if (hasChanges) {
|
91
|
-
// Review uncommitted changes vs HEAD
|
92
|
-
|
106
|
+
// Review uncommitted changes vs HEAD (or staged if no commits yet)
|
107
|
+
if (await hasHeadCommit(repoRoot)) {
|
108
|
+
args.push('HEAD');
|
109
|
+
}
|
110
|
+
else {
|
111
|
+
args.splice(1, 0, '--staged');
|
112
|
+
}
|
93
113
|
}
|
94
114
|
else {
|
95
115
|
// No uncommitted changes, review branch vs default
|
96
116
|
const currentBranch = await getCurrentBranch(repoRoot);
|
97
117
|
const defaultBranch = await detectDefaultBranch(repoRoot);
|
118
|
+
if (!defaultBranch) {
|
119
|
+
// Can't determine default branch - nothing to review
|
120
|
+
return '';
|
121
|
+
}
|
98
122
|
if (currentBranch === defaultBranch) {
|
99
123
|
// On default branch with no changes - nothing to review
|
100
124
|
return '';
|
@@ -8,7 +8,7 @@ export async function performCodeReview(input, onProgress) {
|
|
8
8
|
await onProgress?.('Collecting diff…', 10, 100);
|
9
9
|
const diffText = await collectDiff(input, input.workspaceDir);
|
10
10
|
if (!diffText.trim()) {
|
11
|
-
throw new Error('No
|
11
|
+
throw new Error('No changes to review. You are on the default branch with a clean working tree.');
|
12
12
|
}
|
13
13
|
await onProgress?.('Gathering context…', 30, 100);
|
14
14
|
const context = await gatherContext();
|