jstar-reviewer 2.0.3 → 2.1.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/README.md +7 -4
- package/bin/jstar.js +63 -26
- package/dist/scripts/config.js +91 -0
- package/dist/scripts/dashboard.js +217 -0
- package/dist/scripts/detective.js +150 -0
- package/dist/scripts/gemini-embedding.js +95 -0
- package/dist/scripts/indexer.js +123 -0
- package/dist/scripts/local-embedding.js +49 -0
- package/dist/scripts/mock-llm.js +22 -0
- package/dist/scripts/reviewer.js +296 -0
- package/dist/scripts/types.js +14 -0
- package/package.json +9 -8
- package/scripts/config.ts +42 -2
- package/scripts/indexer.ts +9 -11
- package/scripts/reviewer.ts +12 -1
- package/setup.js +1 -1
package/scripts/config.ts
CHANGED
|
@@ -1,14 +1,53 @@
|
|
|
1
1
|
import dotenv from "dotenv";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as path from "path";
|
|
2
4
|
import { Severity } from "./types";
|
|
3
5
|
|
|
6
|
+
// --- Auto-Setup Logic ---
|
|
7
|
+
const REQUIRED_ENV_VARS = {
|
|
8
|
+
'GOOGLE_API_KEY': '# Required: Google API key for Gemini embeddings\nGOOGLE_API_KEY=your_google_api_key_here',
|
|
9
|
+
'GROQ_API_KEY': '# Required: Groq API key for LLM reviews\nGROQ_API_KEY=your_groq_api_key_here',
|
|
10
|
+
'REVIEW_MODEL_NAME': '# Optional: Override the default model\n# REVIEW_MODEL_NAME=moonshotai/kimi-k2-instruct-0905'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function ensureSetup() {
|
|
14
|
+
const cwd = process.cwd();
|
|
15
|
+
const jstarDir = path.join(cwd, ".jstar");
|
|
16
|
+
const envExamplePath = path.join(cwd, ".env.example");
|
|
17
|
+
|
|
18
|
+
// 1. Ensure .jstar exists
|
|
19
|
+
if (!fs.existsSync(jstarDir)) {
|
|
20
|
+
fs.mkdirSync(jstarDir, { recursive: true });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 2. Ensure .env.example is up to date
|
|
24
|
+
if (fs.existsSync(envExamplePath)) {
|
|
25
|
+
let content = fs.readFileSync(envExamplePath, 'utf-8');
|
|
26
|
+
let missing = false;
|
|
27
|
+
for (const [key, template] of Object.entries(REQUIRED_ENV_VARS)) {
|
|
28
|
+
if (!content.includes(key)) {
|
|
29
|
+
content += `\n${template}\n`;
|
|
30
|
+
missing = true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (missing) {
|
|
34
|
+
fs.writeFileSync(envExamplePath, content);
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
const initialEnv = "# J-Star Code Reviewer\n" + Object.values(REQUIRED_ENV_VARS).join("\n") + "\n";
|
|
38
|
+
fs.writeFileSync(envExamplePath, initialEnv);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Run setup check
|
|
43
|
+
ensureSetup();
|
|
44
|
+
|
|
4
45
|
// Load .env.local first, then .env
|
|
5
46
|
dotenv.config({ path: ".env.local" });
|
|
6
47
|
dotenv.config();
|
|
7
48
|
|
|
8
49
|
/**
|
|
9
50
|
* Default fallback values.
|
|
10
|
-
* These are intentional fallbacks when environment variables are not configured.
|
|
11
|
-
* Override via REVIEW_MODEL_NAME env var for production use.
|
|
12
51
|
*/
|
|
13
52
|
const DEFAULT_MODEL = "moonshotai/kimi-k2-instruct-0905";
|
|
14
53
|
|
|
@@ -19,3 +58,4 @@ export const Config = {
|
|
|
19
58
|
MEDIUM: 5
|
|
20
59
|
}
|
|
21
60
|
};
|
|
61
|
+
|
package/scripts/indexer.ts
CHANGED
|
@@ -9,28 +9,26 @@ import { MockLLM } from "./mock-llm";
|
|
|
9
9
|
import * as path from "path";
|
|
10
10
|
import * as fs from "fs";
|
|
11
11
|
import chalk from "chalk";
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
// Load .env.local first, then .env
|
|
15
|
-
dotenv.config({ path: ".env.local" });
|
|
16
|
-
dotenv.config();
|
|
12
|
+
import { Config } from "./config";
|
|
17
13
|
|
|
18
14
|
// Configuration
|
|
19
15
|
const STORAGE_DIR = path.join(process.cwd(), ".jstar", "storage");
|
|
20
16
|
const SOURCE_DIR = path.join(process.cwd(), "scripts"); // Changed from src/ to scripts/
|
|
21
17
|
|
|
22
|
-
// Ensure OpenAI Key exists (LlamaIndex default) or fallback if we configured something else
|
|
23
|
-
// (We are using local now, so this check is less critical, but good to have if we revert)
|
|
24
|
-
// if (!process.env.OPENAI_API_KEY) {
|
|
25
|
-
// console.warn(chalk.yellow("⚠️ OPENAI_API_KEY not found. Embeddings may fail unless you have configured a local model."));
|
|
26
|
-
// }
|
|
27
|
-
|
|
28
18
|
async function main() {
|
|
19
|
+
// 0. Environment Validation
|
|
20
|
+
if (!process.env.GOOGLE_API_KEY) {
|
|
21
|
+
console.error(chalk.red("❌ Missing GOOGLE_API_KEY!"));
|
|
22
|
+
console.log(chalk.yellow("\nPlease ensure you have a .env.local file. Check .env.example for a template.\n"));
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
29
26
|
const args = process.argv.slice(2);
|
|
30
27
|
const isWatch = args.includes("--watch");
|
|
31
28
|
|
|
32
29
|
console.log(chalk.blue("🧠 J-Star Indexer: Scanning codebase..."));
|
|
33
30
|
|
|
31
|
+
|
|
34
32
|
// 1. Load documents (Your Code)
|
|
35
33
|
if (!fs.existsSync(SOURCE_DIR)) {
|
|
36
34
|
console.error(chalk.red(`❌ Source directory not found: ${SOURCE_DIR}`));
|
package/scripts/reviewer.ts
CHANGED
|
@@ -109,8 +109,19 @@ function parseReviewResponse(text: string): LLMReviewResponse {
|
|
|
109
109
|
async function main() {
|
|
110
110
|
console.log(chalk.blue("🕵️ J-Star Reviewer: Analyzing your changes...\n"));
|
|
111
111
|
|
|
112
|
-
// 0.
|
|
112
|
+
// 0. Environment Validation
|
|
113
|
+
if (!process.env.GOOGLE_API_KEY || !process.env.GROQ_API_KEY) {
|
|
114
|
+
console.error(chalk.red("❌ Missing API Keys!"));
|
|
115
|
+
console.log(chalk.yellow("\nPlease ensure you have a .env.local file with:"));
|
|
116
|
+
console.log(chalk.white("- GOOGLE_API_KEY"));
|
|
117
|
+
console.log(chalk.white("- GROQ_API_KEY"));
|
|
118
|
+
console.log(chalk.white("\nCheck .env.example for a template.\n"));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 1. Detective
|
|
113
123
|
console.log(chalk.blue("🔎 Running Detective Engine..."));
|
|
124
|
+
|
|
114
125
|
const detective = new Detective(SOURCE_DIR);
|
|
115
126
|
await detective.scan();
|
|
116
127
|
detective.report();
|
package/setup.js
CHANGED
|
@@ -115,7 +115,7 @@ async function main() {
|
|
|
115
115
|
|
|
116
116
|
// HARDCODED: Tagged release URL - NOT configurable for security
|
|
117
117
|
// To update, modify this constant and publish a new version of setup.js
|
|
118
|
-
const BASE_URL = 'https://raw.githubusercontent.com/JStaRFilms/jstar-code-review/v2.
|
|
118
|
+
const BASE_URL = 'https://raw.githubusercontent.com/JStaRFilms/jstar-code-review/v2.1.0';
|
|
119
119
|
|
|
120
120
|
// Validate URL matches our exact expected pattern (defense in depth)
|
|
121
121
|
function isValidUrl(url) {
|