@fzed51/git-tool 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/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2026 Fabien Sanchez
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # Git Tool
2
+
3
+ Série d'outils pour Git incluant des fonctionnalités IA.
4
+
5
+ ## Description
6
+
7
+ Ce projet vise à créer un ensemble d'outils pour améliorer et automatiser certaines tâches Git en utilisant l'intelligence artificielle.
8
+
9
+ ## Outils
10
+
11
+ ### 1. Générateur de messages de commit
12
+
13
+ À partir des fichiers modifiés ajoutés au staging et des différences, génère automatiquement un message de commit pertinent et descriptif en utilisant l'IA Mistral.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ yarn install
19
+ yarn build
20
+ ```
21
+
22
+ ## Utilisation
23
+
24
+ ### Utilisation programmatique
25
+
26
+ ```typescript
27
+ import { generateCommitMessage, git } from "git-tool";
28
+
29
+ // Générer un message de commit
30
+ const message = await generateCommitMessage();
31
+ console.log(message);
32
+
33
+ // Utiliser le wrapper git
34
+ const stagedFiles = await git.getStagedFiles();
35
+ ```
36
+
37
+ ## Configuration
38
+
39
+ Créez un fichier `.env` à la racine du projet avec les variables d'environnement suivantes :
40
+
41
+ ```env
42
+ # Clé API pour le service d'IA (OpenAI, Anthropic, etc.)
43
+ MISTRAL_API_KEY=votre_cle_api_ici
44
+ ```
45
+
46
+ **Note:** Le fichier `.env` ne doit jamais être commité dans le dépôt. Assurez-vous qu'il est dans le `.gitignore`.
47
+
48
+ ## Développement
49
+
50
+ ```bash
51
+ # Compiler TypeScript
52
+ yarn build
53
+
54
+ # Mode watch
55
+ yarn dev
56
+
57
+ # Linter
58
+ yarn lint
59
+ yarn lint:fix
60
+
61
+ # Formatter
62
+ yarn format
63
+ ```
64
+
65
+ ## Technologies
66
+
67
+ - **TypeScript** - Langage principal (mode ESM)
68
+ - **Biome.js** - Linting et formatting
69
+ - **Node.js** - Environnement d'exécution
70
+
71
+ ## Licence
72
+
73
+ ISC
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CLI pour générer automatiquement des messages de commit avec IA
4
+ * Usage: git-commit
5
+ */
6
+ import "dotenv/config";
7
+ //# sourceMappingURL=git-commit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-commit.d.ts","sourceRoot":"","sources":["../src/git-commit.ts"],"names":[],"mappings":";AAEA;;;GAGG;AAEH,OAAO,eAAe,CAAC"}
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CLI pour générer automatiquement des messages de commit avec IA
4
+ * Usage: git-commit
5
+ */
6
+ import "dotenv/config";
7
+ import { stdin as input, stdout as output } from "node:process";
8
+ import * as readline from "node:readline/promises";
9
+ import { generateCommitMessage } from "./lib/git-commit.js";
10
+ import { GitWrapper } from "./lib/git-wrapper.js";
11
+ async function main() {
12
+ try {
13
+ console.log("🤖 Génération du message de commit...\n");
14
+ const message = await generateCommitMessage();
15
+ console.log("✅ Message de commit généré:\n");
16
+ console.log("─".repeat(50));
17
+ console.log(message);
18
+ console.log("─".repeat(50));
19
+ // Demander à l'utilisateur s'il veut exécuter le commit
20
+ const rl = readline.createInterface({ input, output });
21
+ const answer = await rl.question("\n❓ Voulez-vous exécuter ce commit maintenant ? (o/n) ");
22
+ rl.close();
23
+ if (answer.toLowerCase() === "o" || answer.toLowerCase() === "y") {
24
+ console.log("\n⏳ Exécution du commit...");
25
+ const git = new GitWrapper();
26
+ await git.commit(message);
27
+ console.log("✅ Commit effectué avec succès !");
28
+ }
29
+ else {
30
+ console.log("\n💡 Pour commiter avec ce message:");
31
+ console.log(` git commit -m "${message.split("\n")[0]}"`);
32
+ }
33
+ }
34
+ catch (error) {
35
+ console.error("❌ Erreur:", error instanceof Error ? error.message : error);
36
+ process.exit(1);
37
+ }
38
+ }
39
+ main();
40
+ //# sourceMappingURL=git-commit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-commit.js","sourceRoot":"","sources":["../src/git-commit.ts"],"names":[],"mappings":";AAEA;;;GAGG;AAEH,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,IAAI,KAAK,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,KAAK,UAAU,IAAI;IACjB,IAAI,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;QAEvD,MAAM,OAAO,GAAG,MAAM,qBAAqB,EAAE,CAAC;QAE9C,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;QAC7C,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QAC5B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACrB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QAE5B,wDAAwD;QACxD,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QACvD,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,QAAQ,CAC9B,wDAAwD,CACzD,CAAC;QACF,EAAE,CAAC,KAAK,EAAE,CAAC;QAEX,IAAI,MAAM,CAAC,WAAW,EAAE,KAAK,GAAG,IAAI,MAAM,CAAC,WAAW,EAAE,KAAK,GAAG,EAAE,CAAC;YACjE,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;YAC1C,MAAM,GAAG,GAAG,IAAI,UAAU,EAAE,CAAC;YAC7B,MAAM,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC1B,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;QACjD,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAC;YACnD,OAAO,CAAC,GAAG,CAAC,qBAAqB,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAC3E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Git Commit Message Generator
3
+ * Génère automatiquement un message de commit à partir des fichiers staged
4
+ */
5
+ import "dotenv/config";
6
+ export declare function generateCommitMessage(): Promise<string>;
7
+ //# sourceMappingURL=git-commit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-commit.d.ts","sourceRoot":"","sources":["../../src/lib/git-commit.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,eAAe,CAAC;AAQvB,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,MAAM,CAAC,CA+D7D"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Git Commit Message Generator
3
+ * Génère automatiquement un message de commit à partir des fichiers staged
4
+ */
5
+ import "dotenv/config";
6
+ import { Mistral } from "@mistralai/mistralai";
7
+ import { git } from "./git-wrapper.js";
8
+ const mistral = new Mistral({
9
+ apiKey: process.env.MISTRAL_API_KEY,
10
+ });
11
+ export async function generateCommitMessage() {
12
+ const stagedFiles = await git.getStagedFiles();
13
+ if (stagedFiles.length === 0) {
14
+ throw new Error("Aucun fichier staged. Utilisez 'git add' pour ajouter des fichiers.");
15
+ }
16
+ const diff = await git.getStagedDiff();
17
+ if (!diff.trim()) {
18
+ throw new Error("Aucune modification trouvée dans les fichiers staged.");
19
+ }
20
+ const prompt = `Analyse les changements git suivants et génère un message de commit concis et descriptif.
21
+
22
+ Fichiers modifiés:
23
+ ${stagedFiles.join("\n")}
24
+
25
+ Différences:
26
+ ${diff}
27
+
28
+ Génère un message de commit qui suit les conventions:
29
+ - Une ligne de résumé de 50 caractères maximum
30
+ - Si nécessaire, une ligne vide suivie d'une description plus détaillée
31
+ - Utilise l'impératif présent (ex: "feat", "fix", "test", "doc", "chore")
32
+ - Soit clair et précis sur ce qui a changé et pourquoi
33
+
34
+ Réponds uniquement avec le message de commit, sans explication supplémentaire.`;
35
+ const response = await mistral.chat.complete({
36
+ model: "devstral-medium-latest",
37
+ temperature: 0.2,
38
+ messages: [
39
+ {
40
+ role: "user",
41
+ content: prompt,
42
+ },
43
+ ],
44
+ });
45
+ // Log token usage
46
+ if (response.usage) {
47
+ console.info("\nTokens utilisés:");
48
+ console.info("─".repeat(30));
49
+ if (response.usage.promptTokens !== undefined)
50
+ console.info("promptTokens:", response.usage.promptTokens);
51
+ if (response.usage.completionTokens !== undefined)
52
+ console.info("completionTokens:", response.usage.completionTokens);
53
+ if (response.usage.totalTokens !== undefined)
54
+ console.info("totalTokens:", response.usage.totalTokens);
55
+ console.info("─".repeat(30) + "\n");
56
+ }
57
+ const content = response.choices?.[0]?.message?.content;
58
+ const commitMessage = typeof content === "string" ? content.trim() : "";
59
+ if (!commitMessage) {
60
+ throw new Error("Impossible de générer un message de commit.");
61
+ }
62
+ return commitMessage;
63
+ }
64
+ //# sourceMappingURL=git-commit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-commit.js","sourceRoot":"","sources":["../../src/lib/git-commit.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAEvC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC;IAC1B,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe;CACpC,CAAC,CAAC;AAEH,MAAM,CAAC,KAAK,UAAU,qBAAqB;IACzC,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,cAAc,EAAE,CAAC;IAE/C,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CACb,qEAAqE,CACtE,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,aAAa,EAAE,CAAC;IAEvC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,MAAM,GAAG;;;EAGf,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;;;EAGtB,IAAI;;;;;;;;+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,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Git Wrapper Module
3
+ * Centralise toutes les interactions avec Git via des commandes shell
4
+ */
5
+ /**
6
+ * Options pour l'exécution des commandes git
7
+ */
8
+ export interface GitExecOptions {
9
+ cwd?: string;
10
+ }
11
+ /**
12
+ * Classe wrapper pour les commandes Git
13
+ */
14
+ export declare class GitWrapper {
15
+ private options;
16
+ constructor(options?: GitExecOptions);
17
+ /**
18
+ * Exécute une commande git
19
+ */
20
+ private exec;
21
+ /**
22
+ * Récupère les fichiers staged (dans l'index)
23
+ */
24
+ getStagedFiles(): Promise<string[]>;
25
+ /**
26
+ * Récupère le diff des fichiers staged
27
+ */
28
+ getStagedDiff(): Promise<string>;
29
+ /**
30
+ * Récupère le statut du dépôt
31
+ */
32
+ getStatus(): Promise<string>;
33
+ /**
34
+ * Récupère la branche courante
35
+ */
36
+ getCurrentBranch(): Promise<string>;
37
+ /**
38
+ * Ajoute des fichiers à l'index
39
+ */
40
+ add(files: string[] | string): Promise<void>;
41
+ /**
42
+ * Effectue un commit
43
+ */
44
+ commit(message: string): Promise<void>;
45
+ /**
46
+ * Récupère l'historique des commits
47
+ */
48
+ getLog(options?: {
49
+ count?: number;
50
+ format?: string;
51
+ oneline?: boolean;
52
+ }): Promise<string>;
53
+ /**
54
+ * Récupère les fichiers modifiés non staged
55
+ */
56
+ getModifiedFiles(): Promise<string[]>;
57
+ /**
58
+ * Récupère les fichiers non trackés
59
+ */
60
+ getUntrackedFiles(): Promise<string[]>;
61
+ /**
62
+ * Vérifie si le répertoire est un dépôt git
63
+ */
64
+ isGitRepository(): Promise<boolean>;
65
+ /**
66
+ * Récupère le remote URL
67
+ */
68
+ getRemoteUrl(remote?: string): Promise<string>;
69
+ /**
70
+ * Récupère le dernier commit
71
+ */
72
+ getLastCommit(): Promise<{
73
+ hash: string;
74
+ message: string;
75
+ author: string;
76
+ date: string;
77
+ }>;
78
+ /**
79
+ * Reset des fichiers staged
80
+ */
81
+ reset(files?: string[] | string): Promise<void>;
82
+ /**
83
+ * Récupère le diff entre deux commits ou branches
84
+ */
85
+ getDiff(from?: string, to?: string): Promise<string>;
86
+ /**
87
+ * Vérifie s'il y a des changements non commités
88
+ */
89
+ hasUncommittedChanges(): Promise<boolean>;
90
+ }
91
+ /**
92
+ * Instance par défaut du wrapper git
93
+ */
94
+ export declare const git: GitWrapper;
95
+ //# sourceMappingURL=git-wrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-wrapper.d.ts","sourceRoot":"","sources":["../../src/lib/git-wrapper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAiB;gBAEpB,OAAO,GAAE,cAAmB;IAIxC;;OAEG;YACW,IAAI;IAclB;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAKzC;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAIlC;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIzC;;OAEG;IACG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlD;;OAEG;IACG,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM5C;;OAEG;IACG,MAAM,CACV,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAO,GACnE,OAAO,CAAC,MAAM,CAAC;IAgBlB;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAK3C;;OAEG;IACG,iBAAiB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAK5C;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IASzC;;OAEG;IACG,YAAY,CAAC,MAAM,SAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAItD;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC;QAC7B,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IASF;;OAEG;IACG,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASrD;;OAEG;IACG,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAW1D;;OAEG;IACG,qBAAqB,IAAI,OAAO,CAAC,OAAO,CAAC;CAIhD;AAED;;GAEG;AACH,eAAO,MAAM,GAAG,YAAmB,CAAC"}
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Git Wrapper Module
3
+ * Centralise toutes les interactions avec Git via des commandes shell
4
+ */
5
+ import { exec } from "node:child_process";
6
+ import { promisify } from "node:util";
7
+ const execAsync = promisify(exec);
8
+ /**
9
+ * Classe wrapper pour les commandes Git
10
+ */
11
+ export class GitWrapper {
12
+ options;
13
+ constructor(options = {}) {
14
+ this.options = options;
15
+ }
16
+ /**
17
+ * Exécute une commande git
18
+ */
19
+ async exec(command) {
20
+ try {
21
+ const { stdout } = await execAsync(`git ${command}`, {
22
+ cwd: this.options.cwd,
23
+ });
24
+ return stdout.trim();
25
+ }
26
+ catch (error) {
27
+ if (error instanceof Error) {
28
+ throw new Error(`Erreur git: ${error.message}`);
29
+ }
30
+ throw error;
31
+ }
32
+ }
33
+ /**
34
+ * Récupère les fichiers staged (dans l'index)
35
+ */
36
+ async getStagedFiles() {
37
+ const output = await this.exec("diff --cached --name-only");
38
+ return output.split("\n").filter((file) => file.length > 0);
39
+ }
40
+ /**
41
+ * Récupère le diff des fichiers staged
42
+ */
43
+ async getStagedDiff() {
44
+ return await this.exec("diff --cached");
45
+ }
46
+ /**
47
+ * Récupère le statut du dépôt
48
+ */
49
+ async getStatus() {
50
+ return await this.exec("status --porcelain");
51
+ }
52
+ /**
53
+ * Récupère la branche courante
54
+ */
55
+ async getCurrentBranch() {
56
+ return await this.exec("rev-parse --abbrev-ref HEAD");
57
+ }
58
+ /**
59
+ * Ajoute des fichiers à l'index
60
+ */
61
+ async add(files) {
62
+ const fileList = Array.isArray(files) ? files.join(" ") : files;
63
+ await this.exec(`add ${fileList}`);
64
+ }
65
+ /**
66
+ * Effectue un commit
67
+ */
68
+ async commit(message) {
69
+ // Échapper les guillemets dans le message
70
+ const escapedMessage = message.replace(/"/g, '\\"');
71
+ await this.exec(`commit -m "${escapedMessage}"`);
72
+ }
73
+ /**
74
+ * Récupère l'historique des commits
75
+ */
76
+ async getLog(options = {}) {
77
+ let command = "log";
78
+ if (options.count) {
79
+ command += ` -${options.count}`;
80
+ }
81
+ if (options.oneline) {
82
+ command += " --oneline";
83
+ }
84
+ else if (options.format) {
85
+ command += ` --format="${options.format}"`;
86
+ }
87
+ return await this.exec(command);
88
+ }
89
+ /**
90
+ * Récupère les fichiers modifiés non staged
91
+ */
92
+ async getModifiedFiles() {
93
+ const output = await this.exec("diff --name-only");
94
+ return output.split("\n").filter((file) => file.length > 0);
95
+ }
96
+ /**
97
+ * Récupère les fichiers non trackés
98
+ */
99
+ async getUntrackedFiles() {
100
+ const output = await this.exec("ls-files --others --exclude-standard");
101
+ return output.split("\n").filter((file) => file.length > 0);
102
+ }
103
+ /**
104
+ * Vérifie si le répertoire est un dépôt git
105
+ */
106
+ async isGitRepository() {
107
+ try {
108
+ await this.exec("rev-parse --git-dir");
109
+ return true;
110
+ }
111
+ catch {
112
+ return false;
113
+ }
114
+ }
115
+ /**
116
+ * Récupère le remote URL
117
+ */
118
+ async getRemoteUrl(remote = "origin") {
119
+ return await this.exec(`remote get-url ${remote}`);
120
+ }
121
+ /**
122
+ * Récupère le dernier commit
123
+ */
124
+ async getLastCommit() {
125
+ const hash = await this.exec("log -1 --format=%H");
126
+ const message = await this.exec("log -1 --format=%s");
127
+ const author = await this.exec("log -1 --format=%an");
128
+ const date = await this.exec("log -1 --format=%ad");
129
+ return { hash, message, author, date };
130
+ }
131
+ /**
132
+ * Reset des fichiers staged
133
+ */
134
+ async reset(files) {
135
+ if (files) {
136
+ const fileList = Array.isArray(files) ? files.join(" ") : files;
137
+ await this.exec(`reset ${fileList}`);
138
+ }
139
+ else {
140
+ await this.exec("reset");
141
+ }
142
+ }
143
+ /**
144
+ * Récupère le diff entre deux commits ou branches
145
+ */
146
+ async getDiff(from, to) {
147
+ let command = "diff";
148
+ if (from) {
149
+ command += ` ${from}`;
150
+ if (to) {
151
+ command += ` ${to}`;
152
+ }
153
+ }
154
+ return await this.exec(command);
155
+ }
156
+ /**
157
+ * Vérifie s'il y a des changements non commités
158
+ */
159
+ async hasUncommittedChanges() {
160
+ const status = await this.getStatus();
161
+ return status.length > 0;
162
+ }
163
+ }
164
+ /**
165
+ * Instance par défaut du wrapper git
166
+ */
167
+ export const git = new GitWrapper();
168
+ //# sourceMappingURL=git-wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-wrapper.js","sourceRoot":"","sources":["../../src/lib/git-wrapper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AASlC;;GAEG;AACH,MAAM,OAAO,UAAU;IACb,OA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QACvC,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,IAAa,EAAE,EAAW;QACtC,IAAI,OAAO,GAAG,MAAM,CAAC;QACrB,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,IAAI,IAAI,IAAI,EAAE,CAAC;YACtB,IAAI,EAAE,EAAE,CAAC;gBACP,OAAO,IAAI,IAAI,EAAE,EAAE,CAAC;YACtB,CAAC;QACH,CAAC;QACD,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,qBAAqB;QACzB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QACtC,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,UAAU,EAAE,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Git Tool - API publique
3
+ * Exporte les fonctionnalités principales du package
4
+ */
5
+ export { generateCommitMessage } from "./git-commit.js";
6
+ export { git, GitWrapper } from "./git-wrapper.js";
7
+ export type { GitExecOptions } from "./git-wrapper.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Git Tool - API publique
3
+ * Exporte les fonctionnalités principales du package
4
+ */
5
+ export { generateCommitMessage } from "./git-commit.js";
6
+ export { git, GitWrapper } from "./git-wrapper.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@fzed51/git-tool",
3
+ "version": "0.1.0",
4
+ "description": "A command-line tool for Git operations with AI-powered commit message generation",
5
+ "type": "module",
6
+ "main": "./dist/lib/index.js",
7
+ "types": "./dist/lib/index.d.ts",
8
+ "bin": {
9
+ "git-commit": "./dist/git-commit.js"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/lib/index.d.ts",
14
+ "import": "./dist/lib/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "engines": {
23
+ "node": ">=18.0.0"
24
+ },
25
+ "scripts": {
26
+ "build": "tsc",
27
+ "postbuild": "chmod +x dist/git-commit.js",
28
+ "prepublishOnly": "npm run build",
29
+ "dev": "tsc --watch",
30
+ "lint": "biome check .",
31
+ "lint:fix": "biome check --write ."
32
+ },
33
+ "keywords": [
34
+ "git",
35
+ "commit",
36
+ "cli",
37
+ "tool",
38
+ "command-line",
39
+ "version-control",
40
+ "IA",
41
+ "AI",
42
+ "mistral",
43
+ "commit-message",
44
+ "automation"
45
+ ],
46
+ "author": "Fabien Sanchez",
47
+ "license": "MIT",
48
+ "devDependencies": {
49
+ "@biomejs/biome": "^2.3.14",
50
+ "@types/node": "^22.10.2",
51
+ "tsx": "^4.21.0",
52
+ "typescript": "^5.7.2"
53
+ },
54
+ "dependencies": {
55
+ "@mistralai/mistralai": "^1.14.0",
56
+ "dotenv": "^17.2.4"
57
+ }
58
+ }