ai-cmg 0.0.5 → 0.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/dist/index.js +30 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -96,6 +96,15 @@ async function runConfigCommand(args) {
|
|
|
96
96
|
console.log('No changes made.');
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
+
function resolveRepoRoot() {
|
|
100
|
+
try {
|
|
101
|
+
const root = execSync('git rev-parse --show-toplevel').toString().trim();
|
|
102
|
+
return root || null;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
99
108
|
function parseMessageArgs(rawArgs) {
|
|
100
109
|
const hintParts = [];
|
|
101
110
|
let hint;
|
|
@@ -129,10 +138,10 @@ function parseMessageArgs(rawArgs) {
|
|
|
129
138
|
}
|
|
130
139
|
return { hint, prompt };
|
|
131
140
|
}
|
|
132
|
-
function getNameStatus() {
|
|
141
|
+
function getNameStatus(repoRoot) {
|
|
133
142
|
const map = new Map();
|
|
134
143
|
try {
|
|
135
|
-
const output = execSync('git diff --cached --name-status').toString();
|
|
144
|
+
const output = execSync('git diff --cached --name-status', { cwd: repoRoot }).toString();
|
|
136
145
|
output.split('\n').forEach((line) => {
|
|
137
146
|
if (!line.trim())
|
|
138
147
|
return;
|
|
@@ -147,9 +156,9 @@ function getNameStatus() {
|
|
|
147
156
|
}
|
|
148
157
|
return map;
|
|
149
158
|
}
|
|
150
|
-
function getChangedFiles() {
|
|
159
|
+
function getChangedFiles(repoRoot) {
|
|
151
160
|
try {
|
|
152
|
-
const output = execSync('git status --porcelain -z').toString();
|
|
161
|
+
const output = execSync('git status --porcelain -z', { cwd: repoRoot }).toString();
|
|
153
162
|
if (!output)
|
|
154
163
|
return [];
|
|
155
164
|
const parts = output.split('\0').filter(Boolean);
|
|
@@ -176,8 +185,8 @@ function getChangedFiles() {
|
|
|
176
185
|
return [];
|
|
177
186
|
}
|
|
178
187
|
}
|
|
179
|
-
async function promptStageFiles() {
|
|
180
|
-
const candidates = getChangedFiles();
|
|
188
|
+
async function promptStageFiles(repoRoot) {
|
|
189
|
+
const candidates = getChangedFiles(repoRoot);
|
|
181
190
|
if (candidates.length === 0) {
|
|
182
191
|
console.log('No local changes to stage.');
|
|
183
192
|
return false;
|
|
@@ -207,7 +216,7 @@ async function promptStageFiles() {
|
|
|
207
216
|
if (action === 'cancel')
|
|
208
217
|
return false;
|
|
209
218
|
if (action === 'all') {
|
|
210
|
-
spawnSync('git', ['add', '.'], { stdio: 'inherit' });
|
|
219
|
+
spawnSync('git', ['add', '.'], { stdio: 'inherit', cwd: repoRoot });
|
|
211
220
|
return true;
|
|
212
221
|
}
|
|
213
222
|
const fileChoices = candidates.map((entry) => ({
|
|
@@ -224,7 +233,7 @@ async function promptStageFiles() {
|
|
|
224
233
|
const files = picked.files;
|
|
225
234
|
if (!files || files.length === 0)
|
|
226
235
|
return false;
|
|
227
|
-
spawnSync('git', ['add', '--', ...files], { stdio: 'inherit' });
|
|
236
|
+
spawnSync('git', ['add', '--', ...files], { stdio: 'inherit', cwd: repoRoot });
|
|
228
237
|
return true;
|
|
229
238
|
}
|
|
230
239
|
function getExtension(filePath) {
|
|
@@ -250,8 +259,8 @@ function shouldOmitFile(path, block) {
|
|
|
250
259
|
}
|
|
251
260
|
return { omit: false };
|
|
252
261
|
}
|
|
253
|
-
function summarizeDiff(diff) {
|
|
254
|
-
const statusMap = getNameStatus();
|
|
262
|
+
function summarizeDiff(diff, repoRoot) {
|
|
263
|
+
const statusMap = getNameStatus(repoRoot);
|
|
255
264
|
const blocks = diff.split(/^diff --git /m);
|
|
256
265
|
const keptBlocks = [];
|
|
257
266
|
const omitted = [];
|
|
@@ -339,26 +348,31 @@ async function main() {
|
|
|
339
348
|
return;
|
|
340
349
|
console.log('Analyzing staged changes...');
|
|
341
350
|
try {
|
|
351
|
+
const repoRoot = resolveRepoRoot();
|
|
352
|
+
if (!repoRoot) {
|
|
353
|
+
console.log('Error: not a git repository.');
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
342
356
|
// 3. Git Diff 가져오기
|
|
343
357
|
let diff;
|
|
344
358
|
try {
|
|
345
|
-
diff = execSync('git diff --cached').toString();
|
|
359
|
+
diff = execSync('git diff --cached', { cwd: repoRoot }).toString();
|
|
346
360
|
}
|
|
347
361
|
catch (e) {
|
|
348
362
|
console.log('Error: not a git repository or git is unavailable.');
|
|
349
363
|
return;
|
|
350
364
|
}
|
|
351
365
|
if (!diff.trim()) {
|
|
352
|
-
const staged = await promptStageFiles();
|
|
366
|
+
const staged = await promptStageFiles(repoRoot);
|
|
353
367
|
if (!staged)
|
|
354
368
|
return;
|
|
355
|
-
diff = execSync('git diff --cached').toString();
|
|
369
|
+
diff = execSync('git diff --cached', { cwd: repoRoot }).toString();
|
|
356
370
|
if (!diff.trim()) {
|
|
357
371
|
console.log('No staged changes. Nothing to commit.');
|
|
358
372
|
return;
|
|
359
373
|
}
|
|
360
374
|
}
|
|
361
|
-
const summarizedDiff = summarizeDiff(diff);
|
|
375
|
+
const summarizedDiff = summarizeDiff(diff, repoRoot);
|
|
362
376
|
const { diff: filteredDiff, truncated } = limitDiffSize(summarizedDiff);
|
|
363
377
|
if (truncated) {
|
|
364
378
|
console.log(`Diff truncated to ${MAX_INPUT_CHARS} characters.`);
|
|
@@ -411,11 +425,11 @@ async function main() {
|
|
|
411
425
|
const action = actions[choice - 1].value;
|
|
412
426
|
switch (action) {
|
|
413
427
|
case 'commit':
|
|
414
|
-
spawnSync('git', ['commit', '-m', message], { stdio: 'inherit' });
|
|
428
|
+
spawnSync('git', ['commit', '-m', message], { stdio: 'inherit', cwd: repoRoot });
|
|
415
429
|
console.log('Commit complete.');
|
|
416
430
|
break;
|
|
417
431
|
case 'edit':
|
|
418
|
-
spawnSync('git', ['commit', '-e', '-m', message], { stdio: 'inherit' });
|
|
432
|
+
spawnSync('git', ['commit', '-e', '-m', message], { stdio: 'inherit', cwd: repoRoot });
|
|
419
433
|
console.log('Commit complete.');
|
|
420
434
|
break;
|
|
421
435
|
case 'copy':
|