bit-cli-ai 1.0.4 → 1.0.6
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/package.json +1 -1
- package/src/index.js +79 -59
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,99 +1,119 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { Command } from
|
|
4
|
-
import { execSync } from
|
|
5
|
-
import chalk from
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { execSync } from "child_process";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
import { readFileSync } from "fs";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import { fileURLToPath } from "url";
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import { mergePreview } from './commands/merge.js';
|
|
11
|
-
import { checkHotZones } from './commands/hotzone.js';
|
|
12
|
-
import { analyzeSymbols } from './commands/analyze.js';
|
|
10
|
+
// ===== Resolve __dirname (ESM-safe) =====
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = path.dirname(__filename);
|
|
13
13
|
|
|
14
|
+
// ===== Read version from package.json =====
|
|
15
|
+
const pkg = JSON.parse(
|
|
16
|
+
readFileSync(path.join(__dirname, "../package.json"), "utf-8")
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
// ===== Import Bit commands =====
|
|
20
|
+
import { smartInit } from "./commands/init.js";
|
|
21
|
+
import { aiCommit } from "./commands/commit.js";
|
|
22
|
+
import { ghostBranch, checkoutGhost } from "./commands/branch.js";
|
|
23
|
+
import { mergePreview } from "./commands/merge.js";
|
|
24
|
+
import { checkHotZones } from "./commands/hotzone.js";
|
|
25
|
+
import { analyzeSymbols } from "./commands/analyze.js";
|
|
26
|
+
|
|
27
|
+
// ===== Setup CLI =====
|
|
14
28
|
const program = new Command();
|
|
15
29
|
|
|
16
30
|
program
|
|
17
|
-
.name(
|
|
18
|
-
.description(chalk.cyan(
|
|
19
|
-
.version(
|
|
31
|
+
.name("bit")
|
|
32
|
+
.description(chalk.cyan("Bit — Git with a brain"))
|
|
33
|
+
.version(pkg.version);
|
|
20
34
|
|
|
21
|
-
//
|
|
35
|
+
// ================= INIT =================
|
|
22
36
|
program
|
|
23
|
-
.command(
|
|
24
|
-
.description(
|
|
37
|
+
.command("init")
|
|
38
|
+
.description("Initialize repo with smart .gitignore and .bit directory")
|
|
25
39
|
.action(smartInit);
|
|
26
40
|
|
|
27
|
-
//
|
|
41
|
+
// ================= COMMIT =================
|
|
28
42
|
program
|
|
29
|
-
.command(
|
|
30
|
-
.description(
|
|
31
|
-
.option(
|
|
43
|
+
.command("commit")
|
|
44
|
+
.description("AI-powered commit message generation")
|
|
45
|
+
.option("-m, --message <msg>", "Manual commit message (skip AI)")
|
|
32
46
|
.action(aiCommit);
|
|
33
47
|
|
|
34
|
-
//
|
|
48
|
+
// ================= BRANCH =================
|
|
35
49
|
program
|
|
36
|
-
.command(
|
|
37
|
-
.description(
|
|
38
|
-
.option(
|
|
39
|
-
.option(
|
|
50
|
+
.command("branch")
|
|
51
|
+
.description("List all branches including ghost branches")
|
|
52
|
+
.option("--ghost <name>", "Create a ghost branch")
|
|
53
|
+
.option("--list-ghost", "List only ghost branches")
|
|
40
54
|
.action(ghostBranch);
|
|
41
55
|
|
|
56
|
+
// ================= CHECKOUT =================
|
|
42
57
|
program
|
|
43
|
-
.command(
|
|
44
|
-
.description(
|
|
45
|
-
.argument(
|
|
46
|
-
.option(
|
|
58
|
+
.command("checkout")
|
|
59
|
+
.description("Checkout a branch")
|
|
60
|
+
.argument("<branch>", "Branch name to checkout")
|
|
61
|
+
.option("--ghost", "Checkout a ghost branch")
|
|
47
62
|
.action(checkoutGhost);
|
|
48
63
|
|
|
49
|
-
//
|
|
64
|
+
// ================= MERGE =================
|
|
50
65
|
program
|
|
51
|
-
.command(
|
|
52
|
-
.description(
|
|
53
|
-
.argument(
|
|
54
|
-
.option(
|
|
66
|
+
.command("merge")
|
|
67
|
+
.description("Merge branches with optional preview")
|
|
68
|
+
.argument("<branch>", "Branch to merge")
|
|
69
|
+
.option("--preview", "Preview merge conflicts without merging")
|
|
55
70
|
.action(mergePreview);
|
|
56
71
|
|
|
57
|
-
//
|
|
72
|
+
// ================= HOTZONE =================
|
|
58
73
|
program
|
|
59
|
-
.command(
|
|
60
|
-
.description(
|
|
74
|
+
.command("hotzone")
|
|
75
|
+
.description("Detect overlapping work with other developers")
|
|
61
76
|
.action(checkHotZones);
|
|
62
77
|
|
|
63
|
-
//
|
|
78
|
+
// ================= ANALYZE =================
|
|
64
79
|
program
|
|
65
|
-
.command(
|
|
66
|
-
.description(
|
|
80
|
+
.command("analyze")
|
|
81
|
+
.description("Analyze code changes at function/symbol level")
|
|
67
82
|
.action(analyzeSymbols);
|
|
68
83
|
|
|
69
|
-
//
|
|
84
|
+
// ================= STATUS =================
|
|
70
85
|
program
|
|
71
|
-
.command(
|
|
72
|
-
.description(
|
|
86
|
+
.command("status")
|
|
87
|
+
.description("Enhanced git status with Bit intelligence")
|
|
73
88
|
.action(() => {
|
|
74
89
|
try {
|
|
75
|
-
console.log(chalk.cyan(
|
|
76
|
-
execSync(
|
|
90
|
+
console.log(chalk.cyan("\n--- Bit Status ---\n"));
|
|
91
|
+
execSync("git status", { stdio: "inherit" });
|
|
77
92
|
checkHotZones(true); // silent mode
|
|
78
93
|
} catch {
|
|
79
|
-
console.error(chalk.red(
|
|
94
|
+
console.error(chalk.red("Not a git repository"));
|
|
95
|
+
process.exit(1);
|
|
80
96
|
}
|
|
81
97
|
});
|
|
82
98
|
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
.action((command, args) => {
|
|
87
|
-
if (!command) {
|
|
88
|
-
program.outputHelp();
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
99
|
+
// ================= GIT PASSTHROUGH =================
|
|
100
|
+
// Forward ANY unknown command directly to git
|
|
101
|
+
program.allowUnknownOption(true);
|
|
91
102
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
103
|
+
program.action(() => {
|
|
104
|
+
const args = process.argv.slice(2);
|
|
105
|
+
|
|
106
|
+
if (args.length === 0) {
|
|
107
|
+
program.outputHelp();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
execSync(`git ${args.join(" ")}`, { stdio: "inherit" });
|
|
113
|
+
} catch {
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
98
117
|
|
|
118
|
+
// ================= RUN =================
|
|
99
119
|
program.parse(process.argv);
|