ai-cmg 0.0.5 → 0.0.7
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 +43 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -96,6 +96,22 @@ async function runConfigCommand(args) {
|
|
|
96
96
|
console.log('No changes made.');
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
+
function getGitEnv() {
|
|
100
|
+
const env = { ...process.env };
|
|
101
|
+
delete env.GIT_DIR;
|
|
102
|
+
delete env.GIT_WORK_TREE;
|
|
103
|
+
delete env.GIT_CEILING_DIRECTORIES;
|
|
104
|
+
return env;
|
|
105
|
+
}
|
|
106
|
+
function resolveRepoRoot() {
|
|
107
|
+
try {
|
|
108
|
+
const root = execSync('git rev-parse --show-toplevel', { env: getGitEnv() }).toString().trim();
|
|
109
|
+
return root || null;
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
99
115
|
function parseMessageArgs(rawArgs) {
|
|
100
116
|
const hintParts = [];
|
|
101
117
|
let hint;
|
|
@@ -129,10 +145,13 @@ function parseMessageArgs(rawArgs) {
|
|
|
129
145
|
}
|
|
130
146
|
return { hint, prompt };
|
|
131
147
|
}
|
|
132
|
-
function getNameStatus() {
|
|
148
|
+
function getNameStatus(repoRoot) {
|
|
133
149
|
const map = new Map();
|
|
134
150
|
try {
|
|
135
|
-
const output = execSync('git diff --cached --name-status'
|
|
151
|
+
const output = execSync('git diff --cached --name-status', {
|
|
152
|
+
cwd: repoRoot,
|
|
153
|
+
env: getGitEnv()
|
|
154
|
+
}).toString();
|
|
136
155
|
output.split('\n').forEach((line) => {
|
|
137
156
|
if (!line.trim())
|
|
138
157
|
return;
|
|
@@ -147,9 +166,12 @@ function getNameStatus() {
|
|
|
147
166
|
}
|
|
148
167
|
return map;
|
|
149
168
|
}
|
|
150
|
-
function getChangedFiles() {
|
|
169
|
+
function getChangedFiles(repoRoot) {
|
|
151
170
|
try {
|
|
152
|
-
const output = execSync('git status --porcelain -z'
|
|
171
|
+
const output = execSync('git status --porcelain -z', {
|
|
172
|
+
cwd: repoRoot,
|
|
173
|
+
env: getGitEnv()
|
|
174
|
+
}).toString();
|
|
153
175
|
if (!output)
|
|
154
176
|
return [];
|
|
155
177
|
const parts = output.split('\0').filter(Boolean);
|
|
@@ -176,8 +198,8 @@ function getChangedFiles() {
|
|
|
176
198
|
return [];
|
|
177
199
|
}
|
|
178
200
|
}
|
|
179
|
-
async function promptStageFiles() {
|
|
180
|
-
const candidates = getChangedFiles();
|
|
201
|
+
async function promptStageFiles(repoRoot) {
|
|
202
|
+
const candidates = getChangedFiles(repoRoot);
|
|
181
203
|
if (candidates.length === 0) {
|
|
182
204
|
console.log('No local changes to stage.');
|
|
183
205
|
return false;
|
|
@@ -207,7 +229,7 @@ async function promptStageFiles() {
|
|
|
207
229
|
if (action === 'cancel')
|
|
208
230
|
return false;
|
|
209
231
|
if (action === 'all') {
|
|
210
|
-
spawnSync('git', ['add', '.'], { stdio: 'inherit' });
|
|
232
|
+
spawnSync('git', ['add', '.'], { stdio: 'inherit', cwd: repoRoot, env: getGitEnv() });
|
|
211
233
|
return true;
|
|
212
234
|
}
|
|
213
235
|
const fileChoices = candidates.map((entry) => ({
|
|
@@ -224,7 +246,7 @@ async function promptStageFiles() {
|
|
|
224
246
|
const files = picked.files;
|
|
225
247
|
if (!files || files.length === 0)
|
|
226
248
|
return false;
|
|
227
|
-
spawnSync('git', ['add', '--', ...files], { stdio: 'inherit' });
|
|
249
|
+
spawnSync('git', ['add', '--', ...files], { stdio: 'inherit', cwd: repoRoot, env: getGitEnv() });
|
|
228
250
|
return true;
|
|
229
251
|
}
|
|
230
252
|
function getExtension(filePath) {
|
|
@@ -250,8 +272,8 @@ function shouldOmitFile(path, block) {
|
|
|
250
272
|
}
|
|
251
273
|
return { omit: false };
|
|
252
274
|
}
|
|
253
|
-
function summarizeDiff(diff) {
|
|
254
|
-
const statusMap = getNameStatus();
|
|
275
|
+
function summarizeDiff(diff, repoRoot) {
|
|
276
|
+
const statusMap = getNameStatus(repoRoot);
|
|
255
277
|
const blocks = diff.split(/^diff --git /m);
|
|
256
278
|
const keptBlocks = [];
|
|
257
279
|
const omitted = [];
|
|
@@ -339,26 +361,31 @@ async function main() {
|
|
|
339
361
|
return;
|
|
340
362
|
console.log('Analyzing staged changes...');
|
|
341
363
|
try {
|
|
364
|
+
const repoRoot = resolveRepoRoot();
|
|
365
|
+
if (!repoRoot) {
|
|
366
|
+
console.log('Error: not a git repository.');
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
342
369
|
// 3. Git Diff 가져오기
|
|
343
370
|
let diff;
|
|
344
371
|
try {
|
|
345
|
-
diff = execSync('git diff --cached').toString();
|
|
372
|
+
diff = execSync('git diff --cached', { cwd: repoRoot, env: getGitEnv() }).toString();
|
|
346
373
|
}
|
|
347
374
|
catch (e) {
|
|
348
375
|
console.log('Error: not a git repository or git is unavailable.');
|
|
349
376
|
return;
|
|
350
377
|
}
|
|
351
378
|
if (!diff.trim()) {
|
|
352
|
-
const staged = await promptStageFiles();
|
|
379
|
+
const staged = await promptStageFiles(repoRoot);
|
|
353
380
|
if (!staged)
|
|
354
381
|
return;
|
|
355
|
-
diff = execSync('git diff --cached').toString();
|
|
382
|
+
diff = execSync('git diff --cached', { cwd: repoRoot, env: getGitEnv() }).toString();
|
|
356
383
|
if (!diff.trim()) {
|
|
357
384
|
console.log('No staged changes. Nothing to commit.');
|
|
358
385
|
return;
|
|
359
386
|
}
|
|
360
387
|
}
|
|
361
|
-
const summarizedDiff = summarizeDiff(diff);
|
|
388
|
+
const summarizedDiff = summarizeDiff(diff, repoRoot);
|
|
362
389
|
const { diff: filteredDiff, truncated } = limitDiffSize(summarizedDiff);
|
|
363
390
|
if (truncated) {
|
|
364
391
|
console.log(`Diff truncated to ${MAX_INPUT_CHARS} characters.`);
|
|
@@ -411,11 +438,11 @@ async function main() {
|
|
|
411
438
|
const action = actions[choice - 1].value;
|
|
412
439
|
switch (action) {
|
|
413
440
|
case 'commit':
|
|
414
|
-
spawnSync('git', ['commit', '-m', message], { stdio: 'inherit' });
|
|
441
|
+
spawnSync('git', ['commit', '-m', message], { stdio: 'inherit', cwd: repoRoot, env: getGitEnv() });
|
|
415
442
|
console.log('Commit complete.');
|
|
416
443
|
break;
|
|
417
444
|
case 'edit':
|
|
418
|
-
spawnSync('git', ['commit', '-e', '-m', message], { stdio: 'inherit' });
|
|
445
|
+
spawnSync('git', ['commit', '-e', '-m', message], { stdio: 'inherit', cwd: repoRoot, env: getGitEnv() });
|
|
419
446
|
console.log('Commit complete.');
|
|
420
447
|
break;
|
|
421
448
|
case 'copy':
|