@mehmetsagir/git-ai 0.0.25 → 0.0.26
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/dist/add.d.ts +5 -0
- package/dist/add.d.ts.map +1 -0
- package/dist/add.js +98 -0
- package/dist/add.js.map +1 -0
- package/dist/commit.d.ts +1 -1
- package/dist/commit.d.ts.map +1 -1
- package/dist/commit.js +37 -4
- package/dist/commit.js.map +1 -1
- package/dist/config.d.ts +11 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +64 -0
- package/dist/config.js.map +1 -1
- package/dist/git.d.ts +8 -2
- package/dist/git.d.ts.map +1 -1
- package/dist/git.js +138 -2
- package/dist/git.js.map +1 -1
- package/dist/index.js +148 -62
- package/dist/index.js.map +1 -1
- package/dist/openai.d.ts +3 -0
- package/dist/openai.d.ts.map +1 -1
- package/dist/openai.js +18 -0
- package/dist/openai.js.map +1 -1
- package/dist/prompts.d.ts +2 -0
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +46 -0
- package/dist/prompts.js.map +1 -1
- package/dist/set-editor.d.ts +5 -0
- package/dist/set-editor.d.ts.map +1 -0
- package/dist/set-editor.js +59 -0
- package/dist/set-editor.js.map +1 -0
- package/dist/summary.d.ts +5 -0
- package/dist/summary.d.ts.map +1 -0
- package/dist/summary.js +175 -0
- package/dist/summary.js.map +1 -0
- package/dist/types.d.ts +24 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/update.d.ts +9 -0
- package/dist/update.d.ts.map +1 -0
- package/dist/update.js +68 -0
- package/dist/update.js.map +1 -0
- package/dist/user-management.d.ts +10 -0
- package/dist/user-management.d.ts.map +1 -0
- package/dist/user-management.js +175 -0
- package/dist/user-management.js.map +1 -0
- package/dist/users.d.ts +9 -0
- package/dist/users.d.ts.map +1 -0
- package/dist/users.js +129 -0
- package/dist/users.js.map +1 -0
- package/dist/utils/commit-file.d.ts +30 -0
- package/dist/utils/commit-file.d.ts.map +1 -0
- package/dist/utils/commit-file.js +192 -0
- package/dist/utils/commit-file.js.map +1 -0
- package/dist/utils/editor.d.ts +29 -0
- package/dist/utils/editor.d.ts.map +1 -0
- package/dist/utils/editor.js +245 -0
- package/dist/utils/editor.js.map +1 -0
- package/dist/utils/validation.d.ts +24 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +81 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.writeCommitFile = writeCommitFile;
|
|
37
|
+
exports.parseCommitFile = parseCommitFile;
|
|
38
|
+
exports.validateCommits = validateCommits;
|
|
39
|
+
exports.mergeEditedCommits = mergeEditedCommits;
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const SEPARATOR = "# ========";
|
|
42
|
+
const COMMENT_PREFIX = "#";
|
|
43
|
+
/**
|
|
44
|
+
* Write commit groups to a file for editing
|
|
45
|
+
*/
|
|
46
|
+
function writeCommitFile(filePath, groups) {
|
|
47
|
+
const lines = [];
|
|
48
|
+
// Header
|
|
49
|
+
lines.push("# Git-AI Commit Messages");
|
|
50
|
+
lines.push("# Edit the commit messages below. Lines starting with # are ignored.");
|
|
51
|
+
lines.push(`# Each commit is separated by: ${SEPARATOR}`);
|
|
52
|
+
lines.push("#");
|
|
53
|
+
lines.push("# Format: First line is the commit message (max 72 chars recommended)");
|
|
54
|
+
lines.push("# Followed by an empty line and detailed body (optional)");
|
|
55
|
+
lines.push("#");
|
|
56
|
+
lines.push("# TIP: You can delete a commit section entirely to skip that commit.");
|
|
57
|
+
lines.push("");
|
|
58
|
+
// Write each group
|
|
59
|
+
groups.forEach((group, index) => {
|
|
60
|
+
if (index > 0) {
|
|
61
|
+
lines.push("");
|
|
62
|
+
lines.push(SEPARATOR);
|
|
63
|
+
lines.push("");
|
|
64
|
+
}
|
|
65
|
+
// Group metadata as comments
|
|
66
|
+
lines.push(`# Group ${group.number}: ${group.description}`);
|
|
67
|
+
lines.push(`# Files: ${(group.files || []).join(", ")}`);
|
|
68
|
+
// Commit message
|
|
69
|
+
lines.push(group.commitMessage);
|
|
70
|
+
// Commit body (if exists)
|
|
71
|
+
if (group.commitBody && group.commitBody.trim()) {
|
|
72
|
+
lines.push("");
|
|
73
|
+
lines.push(group.commitBody);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
// Write to file
|
|
77
|
+
fs.writeFileSync(filePath, lines.join("\n"), "utf8");
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Parse edited commit file and extract commit messages
|
|
81
|
+
*/
|
|
82
|
+
function parseCommitFile(filePath) {
|
|
83
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
84
|
+
const lines = content.split("\n");
|
|
85
|
+
const commits = [];
|
|
86
|
+
let currentCommit = [];
|
|
87
|
+
let inCommit = false;
|
|
88
|
+
for (let i = 0; i < lines.length; i++) {
|
|
89
|
+
const line = lines[i];
|
|
90
|
+
// Skip comment lines
|
|
91
|
+
if (line.trim().startsWith(COMMENT_PREFIX)) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
// Check for separator
|
|
95
|
+
if (line.trim() === SEPARATOR.substring(2).trim()) {
|
|
96
|
+
// Save current commit if exists
|
|
97
|
+
if (currentCommit.length > 0) {
|
|
98
|
+
commits.push(parseCommitLines(currentCommit));
|
|
99
|
+
currentCommit = [];
|
|
100
|
+
inCommit = false;
|
|
101
|
+
}
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
// Collect commit lines
|
|
105
|
+
if (line.trim() || inCommit) {
|
|
106
|
+
currentCommit.push(line);
|
|
107
|
+
if (line.trim()) {
|
|
108
|
+
inCommit = true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Save last commit
|
|
113
|
+
if (currentCommit.length > 0) {
|
|
114
|
+
commits.push(parseCommitLines(currentCommit));
|
|
115
|
+
}
|
|
116
|
+
return commits;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Parse individual commit lines into message and body
|
|
120
|
+
*/
|
|
121
|
+
function parseCommitLines(lines) {
|
|
122
|
+
// Remove leading/trailing empty lines
|
|
123
|
+
while (lines.length > 0 && !lines[0].trim()) {
|
|
124
|
+
lines.shift();
|
|
125
|
+
}
|
|
126
|
+
while (lines.length > 0 && !lines[lines.length - 1].trim()) {
|
|
127
|
+
lines.pop();
|
|
128
|
+
}
|
|
129
|
+
if (lines.length === 0) {
|
|
130
|
+
return { message: "" };
|
|
131
|
+
}
|
|
132
|
+
// First non-empty line is the message
|
|
133
|
+
const message = lines[0].trim();
|
|
134
|
+
// Rest is the body (skip first empty line separator)
|
|
135
|
+
let bodyStartIndex = 1;
|
|
136
|
+
while (bodyStartIndex < lines.length && !lines[bodyStartIndex].trim()) {
|
|
137
|
+
bodyStartIndex++;
|
|
138
|
+
}
|
|
139
|
+
if (bodyStartIndex >= lines.length) {
|
|
140
|
+
return { message };
|
|
141
|
+
}
|
|
142
|
+
const bodyLines = lines.slice(bodyStartIndex);
|
|
143
|
+
const body = bodyLines.join("\n").trim();
|
|
144
|
+
return {
|
|
145
|
+
message,
|
|
146
|
+
body: body || undefined,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Validate parsed commits
|
|
151
|
+
*/
|
|
152
|
+
function validateCommits(commits) {
|
|
153
|
+
const errors = [];
|
|
154
|
+
if (commits.length === 0) {
|
|
155
|
+
errors.push("No commits found in file");
|
|
156
|
+
return { valid: false, errors };
|
|
157
|
+
}
|
|
158
|
+
commits.forEach((commit, index) => {
|
|
159
|
+
if (!commit.message || !commit.message.trim()) {
|
|
160
|
+
errors.push(`Commit ${index + 1}: Empty commit message`);
|
|
161
|
+
}
|
|
162
|
+
else if (commit.message.length > 100) {
|
|
163
|
+
errors.push(`Commit ${index + 1}: Message too long (${commit.message.length} chars, max 100 recommended)`);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
return {
|
|
167
|
+
valid: errors.length === 0,
|
|
168
|
+
errors,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Merge edited commits back into groups
|
|
173
|
+
*/
|
|
174
|
+
function mergeEditedCommits(originalGroups, editedCommits) {
|
|
175
|
+
const updatedGroups = [];
|
|
176
|
+
const minLength = Math.min(originalGroups.length, editedCommits.length);
|
|
177
|
+
for (let i = 0; i < minLength; i++) {
|
|
178
|
+
const group = originalGroups[i];
|
|
179
|
+
const edited = editedCommits[i];
|
|
180
|
+
// Skip empty commits (deleted by user)
|
|
181
|
+
if (!edited.message || !edited.message.trim()) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
updatedGroups.push({
|
|
185
|
+
...group,
|
|
186
|
+
commitMessage: edited.message,
|
|
187
|
+
commitBody: edited.body || group.commitBody,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return updatedGroups;
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=commit-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit-file.js","sourceRoot":"","sources":["../../src/utils/commit-file.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,0CA+CC;AAKD,0CA6CC;AA2CD,0CAwBC;AAKD,gDAyBC;AA3MD,uCAAyB;AAGzB,MAAM,SAAS,GAAG,YAAY,CAAC;AAC/B,MAAM,cAAc,GAAG,GAAG,CAAC;AAE3B;;GAEG;AACH,SAAgB,eAAe,CAC7B,QAAgB,EAChB,MAAqB;IAErB,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,SAAS;IACT,KAAK,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IACvC,KAAK,CAAC,IAAI,CACR,sEAAsE,CACvE,CAAC;IACF,KAAK,CAAC,IAAI,CAAC,kCAAkC,SAAS,EAAE,CAAC,CAAC;IAC1D,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChB,KAAK,CAAC,IAAI,CACR,uEAAuE,CACxE,CAAC;IACF,KAAK,CAAC,IAAI,CAAC,kEAAkE,CA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AC;YAC9C,SAAS;QACX,CAAC;QAED,aAAa,CAAC,IAAI,CAAC;YACjB,GAAG,KAAK;YACR,aAAa,EAAE,MAAM,CAAC,OAAO;YAC7B,UAAU,EAAE,MAAM,CAAC,IAAI,IAAI,KAAK,CAAC,UAAU;SAC5C,CAAC,CAAC;IACL,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect system editor from environment variables
|
|
3
|
+
*/
|
|
4
|
+
export declare function detectSystemEditor(): string | null;
|
|
5
|
+
/**
|
|
6
|
+
* Check if an editor command is available
|
|
7
|
+
*/
|
|
8
|
+
export declare function isEditorAvailable(editorCommand: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Prompt user to select an editor
|
|
11
|
+
*/
|
|
12
|
+
export declare function promptForEditor(): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Get or prompt for editor preference
|
|
15
|
+
*/
|
|
16
|
+
export declare function getOrPromptEditor(): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Open a file in the configured editor
|
|
19
|
+
*/
|
|
20
|
+
export declare function openEditor(filePath: string): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Create a temporary file for editing
|
|
23
|
+
*/
|
|
24
|
+
export declare function createTempFile(prefix?: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Clean up temporary file
|
|
27
|
+
*/
|
|
28
|
+
export declare function cleanupTempFile(filePath: string): void;
|
|
29
|
+
//# sourceMappingURL=editor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../src/utils/editor.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,GAAG,IAAI,CAoBlD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAahE;AAsBD;;GAEG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC,CAsEvD;AAED;;GAEG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,CAiBzD;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CA4BnE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,GAAE,MAAiB,GAAG,MAAM,CAMhE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAQtD"}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.detectSystemEditor = detectSystemEditor;
|
|
40
|
+
exports.isEditorAvailable = isEditorAvailable;
|
|
41
|
+
exports.promptForEditor = promptForEditor;
|
|
42
|
+
exports.getOrPromptEditor = getOrPromptEditor;
|
|
43
|
+
exports.openEditor = openEditor;
|
|
44
|
+
exports.createTempFile = createTempFile;
|
|
45
|
+
exports.cleanupTempFile = cleanupTempFile;
|
|
46
|
+
const childProcess = __importStar(require("child_process"));
|
|
47
|
+
const fs = __importStar(require("fs"));
|
|
48
|
+
const path = __importStar(require("path"));
|
|
49
|
+
const os = __importStar(require("os"));
|
|
50
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
51
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
52
|
+
const config = __importStar(require("../config"));
|
|
53
|
+
const errors_1 = require("./errors");
|
|
54
|
+
/**
|
|
55
|
+
* Detect system editor from environment variables
|
|
56
|
+
*/
|
|
57
|
+
function detectSystemEditor() {
|
|
58
|
+
// Check common editor environment variables
|
|
59
|
+
const editorVars = [
|
|
60
|
+
process.env.GIT_EDITOR,
|
|
61
|
+
process.env.EDITOR,
|
|
62
|
+
process.env.VISUAL,
|
|
63
|
+
];
|
|
64
|
+
for (const editor of editorVars) {
|
|
65
|
+
if (editor && editor.trim()) {
|
|
66
|
+
return editor.trim();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Platform-specific defaults
|
|
70
|
+
if (process.platform === "win32") {
|
|
71
|
+
return "notepad";
|
|
72
|
+
}
|
|
73
|
+
return "vi"; // Unix default
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Check if an editor command is available
|
|
77
|
+
*/
|
|
78
|
+
function isEditorAvailable(editorCommand) {
|
|
79
|
+
try {
|
|
80
|
+
const command = process.platform === "win32" ? "where" : "which";
|
|
81
|
+
const editorBinary = editorCommand.split(" ")[0];
|
|
82
|
+
childProcess.execSync(`${command} ${editorBinary}`, {
|
|
83
|
+
stdio: "ignore",
|
|
84
|
+
});
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get editor command with proper flags
|
|
93
|
+
*/
|
|
94
|
+
function getEditorCommand(editor) {
|
|
95
|
+
const normalizedEditor = editor.toLowerCase();
|
|
96
|
+
// Add wait flags for GUI editors
|
|
97
|
+
if (normalizedEditor.includes("code")) {
|
|
98
|
+
return `${editor} --wait`;
|
|
99
|
+
}
|
|
100
|
+
if (normalizedEditor.includes("subl")) {
|
|
101
|
+
return `${editor} --wait`;
|
|
102
|
+
}
|
|
103
|
+
if (normalizedEditor.includes("atom")) {
|
|
104
|
+
return `${editor} --wait`;
|
|
105
|
+
}
|
|
106
|
+
return editor;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Prompt user to select an editor
|
|
110
|
+
*/
|
|
111
|
+
async function promptForEditor() {
|
|
112
|
+
const systemEditor = detectSystemEditor();
|
|
113
|
+
const choices = [];
|
|
114
|
+
// Common editors to check
|
|
115
|
+
const commonEditors = [
|
|
116
|
+
{ name: "VS Code", command: "code" },
|
|
117
|
+
{ name: "Vim", command: "vim" },
|
|
118
|
+
{ name: "Nano", command: "nano" },
|
|
119
|
+
{ name: "Emacs", command: "emacs" },
|
|
120
|
+
{ name: "Sublime Text", command: "subl" },
|
|
121
|
+
{ name: "Atom", command: "atom" },
|
|
122
|
+
];
|
|
123
|
+
// Add available editors
|
|
124
|
+
for (const editor of commonEditors) {
|
|
125
|
+
if (isEditorAvailable(editor.command)) {
|
|
126
|
+
const displayName = editor.command === systemEditor
|
|
127
|
+
? `${editor.name} (System Default)`
|
|
128
|
+
: editor.name;
|
|
129
|
+
choices.push({
|
|
130
|
+
name: displayName,
|
|
131
|
+
value: editor.command,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// Add system editor if not in common list
|
|
136
|
+
if (systemEditor && !choices.find((c) => c.value === systemEditor)) {
|
|
137
|
+
choices.unshift({
|
|
138
|
+
name: `System Default (${systemEditor})`,
|
|
139
|
+
value: systemEditor,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
// Add custom option
|
|
143
|
+
choices.push({
|
|
144
|
+
name: "Other (enter custom command)",
|
|
145
|
+
value: "custom",
|
|
146
|
+
});
|
|
147
|
+
const { editorChoice } = await inquirer_1.default.prompt([
|
|
148
|
+
{
|
|
149
|
+
type: "list",
|
|
150
|
+
name: "editorChoice",
|
|
151
|
+
message: "Select your preferred editor for commit messages:",
|
|
152
|
+
choices,
|
|
153
|
+
default: systemEditor || "vim",
|
|
154
|
+
},
|
|
155
|
+
]);
|
|
156
|
+
if (editorChoice === "custom") {
|
|
157
|
+
const { customEditor } = await inquirer_1.default.prompt([
|
|
158
|
+
{
|
|
159
|
+
type: "input",
|
|
160
|
+
name: "customEditor",
|
|
161
|
+
message: "Enter editor command:",
|
|
162
|
+
validate: (input) => {
|
|
163
|
+
if (!input.trim()) {
|
|
164
|
+
return "Editor command cannot be empty";
|
|
165
|
+
}
|
|
166
|
+
return true;
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
]);
|
|
170
|
+
return customEditor.trim();
|
|
171
|
+
}
|
|
172
|
+
return editorChoice;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Get or prompt for editor preference
|
|
176
|
+
*/
|
|
177
|
+
async function getOrPromptEditor() {
|
|
178
|
+
// Check if editor is already configured
|
|
179
|
+
let editor = config.getEditor();
|
|
180
|
+
if (editor) {
|
|
181
|
+
return editor;
|
|
182
|
+
}
|
|
183
|
+
// Prompt user for editor preference
|
|
184
|
+
console.log(chalk_1.default.blue("\n⚙️ Editor preference not set.\n"));
|
|
185
|
+
editor = await promptForEditor();
|
|
186
|
+
// Save preference
|
|
187
|
+
config.setEditor(editor);
|
|
188
|
+
console.log(chalk_1.default.green(`\n✓ Editor preference saved: ${editor}\n`));
|
|
189
|
+
return editor;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Open a file in the configured editor
|
|
193
|
+
*/
|
|
194
|
+
async function openEditor(filePath) {
|
|
195
|
+
try {
|
|
196
|
+
const editor = await getOrPromptEditor();
|
|
197
|
+
const editorCommand = getEditorCommand(editor);
|
|
198
|
+
// Spawn editor process
|
|
199
|
+
const editorProcess = childProcess.spawn(editorCommand, [filePath], {
|
|
200
|
+
stdio: "inherit",
|
|
201
|
+
shell: true,
|
|
202
|
+
});
|
|
203
|
+
// Wait for editor to close
|
|
204
|
+
return new Promise((resolve, reject) => {
|
|
205
|
+
editorProcess.on("exit", (code) => {
|
|
206
|
+
if (code === 0) {
|
|
207
|
+
resolve(true);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
reject(new Error(`Editor exited with code ${code}`));
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
editorProcess.on("error", (error) => {
|
|
214
|
+
reject(error);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
throw new Error(`Failed to open editor: ${(0, errors_1.getErrorMessage)(error)}`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Create a temporary file for editing
|
|
224
|
+
*/
|
|
225
|
+
function createTempFile(prefix = "git-ai") {
|
|
226
|
+
const tmpDir = os.tmpdir();
|
|
227
|
+
const timestamp = Date.now();
|
|
228
|
+
const random = Math.random().toString(36).substring(2, 8);
|
|
229
|
+
const filename = `${prefix}-${timestamp}-${random}.txt`;
|
|
230
|
+
return path.join(tmpDir, filename);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Clean up temporary file
|
|
234
|
+
*/
|
|
235
|
+
function cleanupTempFile(filePath) {
|
|
236
|
+
try {
|
|
237
|
+
if (fs.existsSync(filePath)) {
|
|
238
|
+
fs.unlinkSync(filePath);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
// Silently ignore cleanup errors
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor.js","sourceRoot":"","sources":["../../src/utils/editor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,gDAoBC;AAKD,8CAaC;AAyBD,0CAsEC;AAKD,8CAiBC;AAKD,gCA4BC;AAKD,wCAMC;AAKD,0CAQC;AAhOD,4DAA8C;AAC9C,uCAAyB;AACzB,2CAA6B;AAC7B,uCAAyB;AACzB,wDAAgC;AAChC,kDAA0B;AAC1B,kDAAoC;AACpC,qCAA2C;AAE3C;;GAEG;AACH,SAAgB,kBAAkB;IAChC,4CAA4C;IAC5C,MAAM,UAAU,GAAG;QACjB,OAAO,CAAC,GAAG,CAAC,UAAU;QACtB,OAAO,CAAC,GAAG,CAAC,MAAM;QAClB,OAAO,CAAC,GAAG,CAAC,MAAM;KACnB,CAAC;IAEF,KAAK,MAAM,MAAM,IAAI,UAAU,EAAE,CAAC;QAChC,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;YAC5B,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;QACvB,CAAC;IACH,C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C,CAAC,CAAC;IAC1D,MAAM,QAAQ,GAAG,GAAG,MAAM,IAAI,SAAS,IAAI,MAAM,MAAM,CAAC;IACxD,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,QAAgB;IAC9C,IAAI,CAAC;QACH,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5B,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,iCAAiC;IACnC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation utilities for user input
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Validate OpenAI API key format
|
|
6
|
+
*/
|
|
7
|
+
export declare function validateOpenAIKey(input: string): string | true;
|
|
8
|
+
/**
|
|
9
|
+
* Validate git user name (allows "q" to cancel)
|
|
10
|
+
*/
|
|
11
|
+
export declare function validateUserName(input: string): string | true;
|
|
12
|
+
/**
|
|
13
|
+
* Validate git user email (allows "q" to cancel)
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateUserEmail(input: string, existingEmails?: string[]): string | true;
|
|
16
|
+
/**
|
|
17
|
+
* Validate shortcut key
|
|
18
|
+
*/
|
|
19
|
+
export declare function validateShortcut(input: string, usedShortcuts: Set<string>): string | true;
|
|
20
|
+
/**
|
|
21
|
+
* Check if input is cancellation ("q")
|
|
22
|
+
*/
|
|
23
|
+
export declare function isCancellation(input: string): boolean;
|
|
24
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAS9D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAS7D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,cAAc,GAAE,MAAM,EAAO,GAC5B,MAAM,GAAG,IAAI,CAef;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,GACzB,MAAM,GAAG,IAAI,CAef;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAErD"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Validation utilities for user input
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateOpenAIKey = validateOpenAIKey;
|
|
7
|
+
exports.validateUserName = validateUserName;
|
|
8
|
+
exports.validateUserEmail = validateUserEmail;
|
|
9
|
+
exports.validateShortcut = validateShortcut;
|
|
10
|
+
exports.isCancellation = isCancellation;
|
|
11
|
+
/**
|
|
12
|
+
* Validate OpenAI API key format
|
|
13
|
+
*/
|
|
14
|
+
function validateOpenAIKey(input) {
|
|
15
|
+
const trimmed = input.trim();
|
|
16
|
+
if (trimmed.length === 0) {
|
|
17
|
+
return "OpenAI API Key is required!";
|
|
18
|
+
}
|
|
19
|
+
if (!trimmed.startsWith("sk-")) {
|
|
20
|
+
return 'OpenAI API Key must start with "sk-"!';
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validate git user name (allows "q" to cancel)
|
|
26
|
+
*/
|
|
27
|
+
function validateUserName(input) {
|
|
28
|
+
const trimmed = input.trim();
|
|
29
|
+
if (trimmed.toLowerCase() === "q") {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
if (trimmed.length === 0) {
|
|
33
|
+
return "Name is required!";
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Validate git user email (allows "q" to cancel)
|
|
39
|
+
*/
|
|
40
|
+
function validateUserEmail(input, existingEmails = []) {
|
|
41
|
+
const trimmed = input.trim();
|
|
42
|
+
if (trimmed.toLowerCase() === "q") {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (trimmed.length === 0) {
|
|
46
|
+
return "Email is required!";
|
|
47
|
+
}
|
|
48
|
+
if (!trimmed.includes("@")) {
|
|
49
|
+
return "Please enter a valid email address!";
|
|
50
|
+
}
|
|
51
|
+
if (existingEmails.includes(trimmed)) {
|
|
52
|
+
return "This email is already added!";
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Validate shortcut key
|
|
58
|
+
*/
|
|
59
|
+
function validateShortcut(input, usedShortcuts) {
|
|
60
|
+
const key = input.trim().toLowerCase();
|
|
61
|
+
if (key === "q") {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
if (key.length === 0) {
|
|
65
|
+
return "Shortcut key is required!";
|
|
66
|
+
}
|
|
67
|
+
if (usedShortcuts.has(key)) {
|
|
68
|
+
return "This shortcut is already in use!";
|
|
69
|
+
}
|
|
70
|
+
if (key.includes(" ")) {
|
|
71
|
+
return "Shortcut cannot contain spaces!";
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Check if input is cancellation ("q")
|
|
77
|
+
*/
|
|
78
|
+
function isCancellation(input) {
|
|
79
|
+
return input.trim().toLowerCase() === "q";
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","s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