@dev-angsu/cli 1.0.1 → 1.0.3

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/index.js CHANGED
@@ -10,13 +10,15 @@ import chalk from "chalk";
10
10
  import ora from "ora";
11
11
  import fs from "fs";
12
12
 
13
+ import { run as review } from "../src/utils/engine.js";
14
+
13
15
  const program = new Command();
14
16
 
15
17
  // 1. Metadata
16
18
  program
17
19
  .name("cli")
18
20
  .description("A CLI to demonstrate industry")
19
- .version("1.0.0");
21
+ .version("1.0.1");
20
22
 
21
23
  // 2. Define a Command
22
24
  program
@@ -73,5 +75,14 @@ program
73
75
  }
74
76
  });
75
77
 
78
+ // 3. Review Command
79
+ program
80
+ .command("review")
81
+ .alias("r")
82
+ .description("Review staged changes using AI")
83
+ .action(async () => {
84
+ await review();
85
+ });
86
+
76
87
  // 6. Parse Arguments
77
88
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-angsu/cli",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { simpleGit } from "simple-git";
4
4
  import OpenAI from "openai";
5
+ import { fileURLToPath } from "url";
5
6
  import "dotenv/config"; // Loads .env file automatically
6
7
 
7
8
  import * as core from "@actions/core";
@@ -9,16 +10,6 @@ import * as github from "@actions/github";
9
10
 
10
11
  const git = simpleGit();
11
12
 
12
- if (!process.env.OPENAI_API_KEY) {
13
- console.error("❌ Error: OPENAI_API_KEY is missing in .env file.");
14
- process.exit(1);
15
- }
16
-
17
- const openai = new OpenAI({
18
- apiKey: process.env.OPENAI_API_KEY,
19
- baseURL: process.env.AI_BASE_URL || "https://api.z.ai/api/paas/v4/",
20
- });
21
-
22
13
  // async function getStagedDiff() {
23
14
  // const diff = await git.diff(["--staged"]);
24
15
  // return diff;
@@ -70,6 +61,15 @@ async function generateReview(diff) {
70
61
 
71
62
  console.log("🤔 Analyzing changes...");
72
63
 
64
+ if (!process.env.OPENAI_API_KEY) {
65
+ throw new Error("❌ Error: OPENAI_API_KEY is missing in .env file.");
66
+ }
67
+
68
+ const openai = new OpenAI({
69
+ apiKey: process.env.OPENAI_API_KEY,
70
+ baseURL: process.env.AI_BASE_URL || "https://api.z.ai/api/paas/v4/",
71
+ });
72
+
73
73
  const response = await openai.chat.completions.create({
74
74
  model: process.env.AI_MODEL || "glm-4.6v-flash",
75
75
  messages: [
@@ -97,7 +97,7 @@ async function generateReview(diff) {
97
97
  }
98
98
 
99
99
  // Main Execution
100
- async function run() {
100
+ export async function run() {
101
101
  try {
102
102
  // const diff = await getStagedDiff();
103
103
  // 1. SELECT STRATEGY
@@ -139,4 +139,11 @@ async function run() {
139
139
  }
140
140
  }
141
141
 
142
- run();
142
+ const currentFile = fileURLToPath(import.meta.url);
143
+ // Check if run directly (robust against symlinks/path variations in CI)
144
+ if (
145
+ process.argv[1] === currentFile ||
146
+ process.argv[1].endsWith("src/utils/engine.js")
147
+ ) {
148
+ run();
149
+ }