jstar-reviewer 2.3.0 → 2.4.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/bin/jstar.js CHANGED
@@ -29,7 +29,7 @@ function log(msg) {
29
29
 
30
30
  function printHelp() {
31
31
  log(`
32
- ${COLORS.bold}🌟 J-Star Reviewer v2.2.0${COLORS.reset}
32
+ ${COLORS.bold}🌟 J-Star Reviewer v2.4.0${COLORS.reset}
33
33
 
34
34
  ${COLORS.dim}AI-powered code review with local embeddings${COLORS.reset}
35
35
 
@@ -91,6 +91,32 @@ function chunkDiffByFile(diff) {
91
91
  function sleep(ms) {
92
92
  return new Promise(resolve => setTimeout(resolve, ms));
93
93
  }
94
+ async function getDefaultBranch() {
95
+ try {
96
+ // Method 1: Check remote HEAD (most reliable)
97
+ try {
98
+ const remote = await git.remote(['show', 'origin']);
99
+ if (typeof remote === 'string') {
100
+ const match = remote.match(/HEAD branch: (\S+)/);
101
+ if (match)
102
+ return match[1];
103
+ }
104
+ }
105
+ catch (e) {
106
+ // No remote or network issue, proceed to local check
107
+ }
108
+ // Method 2: Check which common branch exists locally
109
+ const branches = await git.branchLocal();
110
+ if (branches.all.includes('main'))
111
+ return 'main';
112
+ if (branches.all.includes('master'))
113
+ return 'master';
114
+ }
115
+ catch (e) {
116
+ // Fallback
117
+ }
118
+ return 'main';
119
+ }
94
120
  /**
95
121
  * Filter issues by confidence threshold and log what was removed
96
122
  */
@@ -207,12 +233,38 @@ async function main() {
207
233
  }
208
234
  else if (args.includes('--pr')) {
209
235
  const prIndex = args.indexOf('--pr');
210
- // Check if there is a next argument that doesn't start with --
211
- const potentialBase = args[prIndex + 1];
212
- const baseBranch = (potentialBase && !potentialBase.startsWith('--')) ? potentialBase : 'main';
236
+ // Check for --base flag first
237
+ let baseBranch = 'main';
238
+ if (args.includes('--base')) {
239
+ const baseIndex = args.indexOf('--base') + 1;
240
+ if (baseIndex < args.length) {
241
+ baseBranch = args[baseIndex];
242
+ }
243
+ else {
244
+ logger_1.Logger.error(chalk_1.default.red("❌ Missing branch name for --base"));
245
+ return;
246
+ }
247
+ }
248
+ else {
249
+ // Check positional argument (backward compatibility)
250
+ const potentialBase = args[prIndex + 1];
251
+ if (potentialBase && !potentialBase.startsWith('--')) {
252
+ baseBranch = potentialBase;
253
+ }
254
+ else {
255
+ // Auto-detect
256
+ baseBranch = await getDefaultBranch();
257
+ }
258
+ }
213
259
  reviewTarget = `PR (HEAD vs ${baseBranch})`;
214
260
  // Use triple-dot for merge-base difference (what a PR shows)
215
- diff = await git.diff([`${baseBranch}...HEAD`]);
261
+ try {
262
+ diff = await git.diff([`${baseBranch}...HEAD`]);
263
+ }
264
+ catch (e) {
265
+ logger_1.Logger.error(chalk_1.default.red(`❌ Failed to diff against ${baseBranch}. Does the branch exist?`));
266
+ return;
267
+ }
216
268
  }
217
269
  else {
218
270
  // Default: Staged changes
package/package.json CHANGED
@@ -1,19 +1,10 @@
1
1
  {
2
2
  "name": "jstar-reviewer",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "Local-First, Context-Aware AI Code Reviewer - Works with any language",
5
5
  "bin": {
6
6
  "jstar": "bin/jstar.js"
7
7
  },
8
- "scripts": {
9
- "build": "tsc",
10
- "index:init": "ts-node scripts/indexer.ts --init",
11
- "index:watch": "ts-node scripts/indexer.ts --watch",
12
- "review": "ts-node scripts/reviewer.ts",
13
- "chat": "ts-node scripts/chat.ts",
14
- "detect": "ts-node scripts/detective.ts",
15
- "prepare": "husky install"
16
- },
17
8
  "keywords": [
18
9
  "code-review",
19
10
  "ai",
@@ -65,5 +56,13 @@
65
56
  "type": "commonjs",
66
57
  "bugs": {
67
58
  "url": "https://github.com/JStaRFilms/jstar-code-review/issues"
59
+ },
60
+ "scripts": {
61
+ "build": "tsc",
62
+ "index:init": "ts-node scripts/indexer.ts --init",
63
+ "index:watch": "ts-node scripts/indexer.ts --watch",
64
+ "review": "ts-node scripts/reviewer.ts",
65
+ "chat": "ts-node scripts/chat.ts",
66
+ "detect": "ts-node scripts/detective.ts"
68
67
  }
69
- }
68
+ }
@@ -69,6 +69,30 @@ function sleep(ms: number): Promise<void> {
69
69
  return new Promise(resolve => setTimeout(resolve, ms));
70
70
  }
71
71
 
72
+ async function getDefaultBranch(): Promise<string> {
73
+ try {
74
+ // Method 1: Check remote HEAD (most reliable)
75
+ try {
76
+ const remote = await git.remote(['show', 'origin']);
77
+ if (typeof remote === 'string') {
78
+ const match = remote.match(/HEAD branch: (\S+)/);
79
+ if (match) return match[1];
80
+ }
81
+ } catch (e) {
82
+ // No remote or network issue, proceed to local check
83
+ }
84
+
85
+ // Method 2: Check which common branch exists locally
86
+ const branches = await git.branchLocal();
87
+ if (branches.all.includes('main')) return 'main';
88
+ if (branches.all.includes('master')) return 'master';
89
+
90
+ } catch (e) {
91
+ // Fallback
92
+ }
93
+ return 'main';
94
+ }
95
+
72
96
  /**
73
97
  * Filter issues by confidence threshold and log what was removed
74
98
  */
@@ -196,13 +220,36 @@ async function main() {
196
220
  }
197
221
  } else if (args.includes('--pr')) {
198
222
  const prIndex = args.indexOf('--pr');
199
- // Check if there is a next argument that doesn't start with --
200
- const potentialBase = args[prIndex + 1];
201
- const baseBranch = (potentialBase && !potentialBase.startsWith('--')) ? potentialBase : 'main';
223
+ // Check for --base flag first
224
+ let baseBranch = 'main';
225
+
226
+ if (args.includes('--base')) {
227
+ const baseIndex = args.indexOf('--base') + 1;
228
+ if (baseIndex < args.length) {
229
+ baseBranch = args[baseIndex];
230
+ } else {
231
+ Logger.error(chalk.red("❌ Missing branch name for --base"));
232
+ return;
233
+ }
234
+ } else {
235
+ // Check positional argument (backward compatibility)
236
+ const potentialBase = args[prIndex + 1];
237
+ if (potentialBase && !potentialBase.startsWith('--')) {
238
+ baseBranch = potentialBase;
239
+ } else {
240
+ // Auto-detect
241
+ baseBranch = await getDefaultBranch();
242
+ }
243
+ }
202
244
 
203
245
  reviewTarget = `PR (HEAD vs ${baseBranch})`;
204
246
  // Use triple-dot for merge-base difference (what a PR shows)
205
- diff = await git.diff([`${baseBranch}...HEAD`]);
247
+ try {
248
+ diff = await git.diff([`${baseBranch}...HEAD`]);
249
+ } catch (e) {
250
+ Logger.error(chalk.red(`❌ Failed to diff against ${baseBranch}. Does the branch exist?`));
251
+ return;
252
+ }
206
253
  } else {
207
254
  // Default: Staged changes
208
255
  diff = await git.diff(["--staged"]);