@hpreet/gitpilot 0.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/.editorconfig +22 -0
- package/README.md +0 -0
- package/bin/gitpilot.js +25 -0
- package/package.json +31 -0
- package/src/commands/commit.js +35 -0
- package/src/commands/config.js +14 -0
- package/src/commands/setup.js +28 -0
- package/src/gitWrapper.js +15 -0
- package/src/providers/geminiProvider.js +13 -0
- package/src/providers/index.js +16 -0
- package/src/providers/localProvider.js +9 -0
- package/src/providers/openaiProvider.js +16 -0
- package/src/utils/diff.js +7 -0
- package/src/utils/prompt.js +3 -0
package/.editorconfig
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# top-most EditorConfig file
|
|
2
|
+
root = true
|
|
3
|
+
|
|
4
|
+
[*]
|
|
5
|
+
# Use spaces instead of tabs
|
|
6
|
+
indent_style = space
|
|
7
|
+
# 2 spaces per indent
|
|
8
|
+
indent_size = 2
|
|
9
|
+
# Trim trailing whitespace on save
|
|
10
|
+
trim_trailing_whitespace = true
|
|
11
|
+
# Insert final newline at end of file
|
|
12
|
+
insert_final_newline = true
|
|
13
|
+
# File encoding
|
|
14
|
+
charset = utf-8
|
|
15
|
+
|
|
16
|
+
[*.md]
|
|
17
|
+
# Markdown files usually need trailing whitespace (for line breaks)
|
|
18
|
+
trim_trailing_whitespace = false
|
|
19
|
+
|
|
20
|
+
[*.json]
|
|
21
|
+
# JSON files usually 2-space indentation
|
|
22
|
+
indent_size = 2
|
package/README.md
ADDED
|
File without changes
|
package/bin/gitpilot.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { commitCommand } from "../src/commands/commit.js";
|
|
4
|
+
import { setupCommand } from "../src/commands/setup.js";
|
|
5
|
+
|
|
6
|
+
const program = new Command();
|
|
7
|
+
|
|
8
|
+
program
|
|
9
|
+
.name("gitpilot")
|
|
10
|
+
.description("Your AI copilot for git commits")
|
|
11
|
+
.version("0.1.0");
|
|
12
|
+
|
|
13
|
+
program
|
|
14
|
+
.command("commit")
|
|
15
|
+
.description("Generate a commit message with AI")
|
|
16
|
+
.option("-m, --message <message>", "Provide your own commit message")
|
|
17
|
+
.option("--interactive", "Approve/edit message before committing")
|
|
18
|
+
.action(commitCommand);
|
|
19
|
+
|
|
20
|
+
program
|
|
21
|
+
.command("setup")
|
|
22
|
+
.description("Configure your API provider and keys")
|
|
23
|
+
.action(setupCommand);
|
|
24
|
+
|
|
25
|
+
program.parse(process.argv);
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hpreet/gitpilot",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "AI-powered Git commit assistant — generates commit messages intelligently and fits seamlessly into your workflow.",
|
|
5
|
+
"main": "bin/gitpilot.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"gitpilot": "./bin/gitpilot.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"start": "node bin/gitpilot.js",
|
|
12
|
+
"test": "echo \"No tests yet\" && exit 0"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"git",
|
|
16
|
+
"AI",
|
|
17
|
+
"commit",
|
|
18
|
+
"CLI",
|
|
19
|
+
"automation",
|
|
20
|
+
"developer-tools"
|
|
21
|
+
],
|
|
22
|
+
"author": "Harpreet Singh <thesinghharpreet@gmail.com>",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@google/generative-ai": "^0.24.1",
|
|
26
|
+
"commander": "^14.0.2",
|
|
27
|
+
"inquirer": "^12.11.1",
|
|
28
|
+
"openai": "^6.9.0",
|
|
29
|
+
"simple-git": "^3.30.0"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getProvider } from "../providers/index.js";
|
|
2
|
+
import { getStagedDiff } from "../utils/diff.js";
|
|
3
|
+
import { promptTemplate } from "../utils/prompt.js";
|
|
4
|
+
import simpleGit from "simple-git";
|
|
5
|
+
import inquirer from "inquirer";
|
|
6
|
+
import { loadConfig } from "./config.js";
|
|
7
|
+
|
|
8
|
+
const git = simpleGit();
|
|
9
|
+
|
|
10
|
+
export async function commitCommand(options) {
|
|
11
|
+
const diff = await getStagedDiff();
|
|
12
|
+
if (!diff) {
|
|
13
|
+
console.log("No staged changes.");
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const config = loadConfig();
|
|
18
|
+
const provider = getProvider(config.provider || "openai", config);
|
|
19
|
+
|
|
20
|
+
let message = options.message || await provider.generateCommitMessage(promptTemplate(diff));
|
|
21
|
+
|
|
22
|
+
if (options.interactive) {
|
|
23
|
+
const { approvedMessage } = await inquirer.prompt([{
|
|
24
|
+
type: "editor",
|
|
25
|
+
name: "approvedMessage",
|
|
26
|
+
message: "Edit or approve commit message:",
|
|
27
|
+
default: message
|
|
28
|
+
}]);
|
|
29
|
+
message = approvedMessage;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
await git.commit(message);
|
|
33
|
+
console.log("\n✅ Commit created:");
|
|
34
|
+
console.log(message);
|
|
35
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
const configPath = path.join(process.env.HOME || process.env.USERPROFILE, ".gitpilotrc");
|
|
5
|
+
|
|
6
|
+
export function saveConfig(config) {
|
|
7
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function loadConfig() {
|
|
11
|
+
if (!fs.existsSync(configPath)) return {};
|
|
12
|
+
const raw = fs.readFileSync(configPath, "utf-8");
|
|
13
|
+
return JSON.parse(raw);
|
|
14
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
import { saveConfig } from "./config.js";
|
|
3
|
+
|
|
4
|
+
export async function setupCommand() {
|
|
5
|
+
const answers = await inquirer.prompt([
|
|
6
|
+
{
|
|
7
|
+
type: "list",
|
|
8
|
+
name: "provider",
|
|
9
|
+
message: "Choose your AI provider:",
|
|
10
|
+
choices: ["openai", "local", "gemini"]
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
type: "input",
|
|
14
|
+
name: "apiKey",
|
|
15
|
+
message: "Enter your OpenAI/Gemini API key (leave blank for local models):",
|
|
16
|
+
when: (answers) => answers.provider === "openai" || answers.provider === "gemini"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
type: "list",
|
|
20
|
+
name: "defaultCommitStyle",
|
|
21
|
+
message: "Choose your default commit message style:",
|
|
22
|
+
choices: ["concise", "detailed", "custom"]
|
|
23
|
+
}
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
saveConfig(answers);
|
|
27
|
+
console.log(`\n✅ Configuration saved!`);
|
|
28
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
import process from "process";
|
|
4
|
+
|
|
5
|
+
const args = process.argv.slice(2);
|
|
6
|
+
const hasAIFlag = args.includes("-ai");
|
|
7
|
+
|
|
8
|
+
if (hasAIFlag) {
|
|
9
|
+
const filteredArgs = args.filter(arg => arg !== "-ai");
|
|
10
|
+
const child = spawn("gitpilot", ["commit", "--interactive", ...filteredArgs], { stdio: "inherit" });
|
|
11
|
+
child.on("exit", process.exit);
|
|
12
|
+
} else {
|
|
13
|
+
const child = spawn("git", args, { stdio: "inherit" });
|
|
14
|
+
child.on("exit", process.exit);
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GoogleGenerativeAI } from "@google/generative-ai";
|
|
2
|
+
|
|
3
|
+
export class GeminiProvider {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
this.client = new GoogleGenerativeAI(config.apiKey);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async generateCommitMessage(prompt) {
|
|
9
|
+
const model = this.client.getGenerativeModel({ model: "gemini-2.5-flash" });
|
|
10
|
+
const result = await model.generateContent(prompt);
|
|
11
|
+
return result.response.text();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { OpenAIProvider } from "./openaiProvider.js";
|
|
2
|
+
import { LocalProvider } from "./localProvider.js";
|
|
3
|
+
import { GeminiProvider } from "./geminiProvider.js";
|
|
4
|
+
|
|
5
|
+
export function getProvider(name, config) {
|
|
6
|
+
switch (name) {
|
|
7
|
+
case "openai":
|
|
8
|
+
return new OpenAIProvider(config);
|
|
9
|
+
case "gemini":
|
|
10
|
+
return new GeminiProvider(config);
|
|
11
|
+
case "local":
|
|
12
|
+
return new LocalProvider(config);
|
|
13
|
+
default:
|
|
14
|
+
throw new Error(`Unknown provider: ${name}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
|
|
3
|
+
export class OpenAIProvider {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
this.client = new OpenAI({ apiKey: config.apiKey });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async generateCommitMessage(prompt) {
|
|
9
|
+
const completion = await this.client.chat.completions.create({
|
|
10
|
+
model: "gpt-4",
|
|
11
|
+
messages: [{ role: "user", content: prompt }],
|
|
12
|
+
temperature: 0
|
|
13
|
+
});
|
|
14
|
+
return completion.choices[0].message.content.trim();
|
|
15
|
+
}
|
|
16
|
+
}
|