orcommit 1.0.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 +21 -0
- package/README.md +318 -0
- package/dist/cli.d.ts +70 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +391 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/api.d.ts +48 -0
- package/dist/modules/api.d.ts.map +1 -0
- package/dist/modules/api.js +286 -0
- package/dist/modules/api.js.map +1 -0
- package/dist/modules/cache.d.ts +74 -0
- package/dist/modules/cache.d.ts.map +1 -0
- package/dist/modules/cache.js +284 -0
- package/dist/modules/cache.js.map +1 -0
- package/dist/modules/config.d.ts +53 -0
- package/dist/modules/config.d.ts.map +1 -0
- package/dist/modules/config.js +180 -0
- package/dist/modules/config.js.map +1 -0
- package/dist/modules/core.d.ts +54 -0
- package/dist/modules/core.d.ts.map +1 -0
- package/dist/modules/core.js +474 -0
- package/dist/modules/core.js.map +1 -0
- package/dist/modules/diff-filter.d.ts +71 -0
- package/dist/modules/diff-filter.d.ts.map +1 -0
- package/dist/modules/diff-filter.js +332 -0
- package/dist/modules/diff-filter.js.map +1 -0
- package/dist/modules/git.d.ts +61 -0
- package/dist/modules/git.d.ts.map +1 -0
- package/dist/modules/git.js +362 -0
- package/dist/modules/git.js.map +1 -0
- package/dist/modules/logger.d.ts +67 -0
- package/dist/modules/logger.d.ts.map +1 -0
- package/dist/modules/logger.js +212 -0
- package/dist/modules/logger.js.map +1 -0
- package/dist/modules/tokenizer.d.ts +43 -0
- package/dist/modules/tokenizer.d.ts.map +1 -0
- package/dist/modules/tokenizer.js +200 -0
- package/dist/modules/tokenizer.js.map +1 -0
- package/dist/types/index.d.ts +141 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +70 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.d.ts +64 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +154 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
import { CHUNK_LIMITS, ConfigError, GitError, ApiError } from '../types/index.js';
|
|
2
|
+
import { configManager } from './config.js';
|
|
3
|
+
import { gitManager } from './git.js';
|
|
4
|
+
import { apiManager } from './api.js';
|
|
5
|
+
import { logger } from './logger.js';
|
|
6
|
+
import { tokenManager } from './tokenizer.js';
|
|
7
|
+
import { cacheManager } from './cache.js';
|
|
8
|
+
import { diffFilter } from './diff-filter.js';
|
|
9
|
+
import { confirm, isCancel } from '@clack/prompts';
|
|
10
|
+
import chalk from 'chalk';
|
|
11
|
+
export class CoreOrchestrator {
|
|
12
|
+
config;
|
|
13
|
+
/**
|
|
14
|
+
* Initialize the core orchestrator
|
|
15
|
+
*/
|
|
16
|
+
async initialize() {
|
|
17
|
+
try {
|
|
18
|
+
this.config = await configManager.load();
|
|
19
|
+
logger.debug('Configuration loaded successfully');
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
throw new ConfigError(`Failed to initialize: ${error instanceof Error ? error.message : 'Unknown error'}`, error instanceof Error ? error : undefined);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Main entry point for generating and creating commits
|
|
27
|
+
*/
|
|
28
|
+
async generateCommit(options) {
|
|
29
|
+
if (!this.config) {
|
|
30
|
+
throw new ConfigError('Core orchestrator not initialized');
|
|
31
|
+
}
|
|
32
|
+
// Set up logger based on options
|
|
33
|
+
const contextualLogger = logger.withOptions({
|
|
34
|
+
verbose: options.verbose || false,
|
|
35
|
+
silent: false
|
|
36
|
+
});
|
|
37
|
+
try {
|
|
38
|
+
// Validate environment
|
|
39
|
+
await this.validateEnvironment(options);
|
|
40
|
+
// Handle cache clearing if requested
|
|
41
|
+
if (options.clearCache) {
|
|
42
|
+
const cacheProgress = contextualLogger.startProgress('Clearing cache...');
|
|
43
|
+
await cacheManager.clear();
|
|
44
|
+
cacheProgress.succeed('Cache cleared');
|
|
45
|
+
}
|
|
46
|
+
// Phase 1: Get staged changes
|
|
47
|
+
console.log(chalk.blue('\nš Analyzing changes...'));
|
|
48
|
+
const analyzeProgress = contextualLogger.startProgress('Reading staged changes');
|
|
49
|
+
const rawDiff = await gitManager.getStagedDiff({
|
|
50
|
+
maxChunkSize: CHUNK_LIMITS.MAX_CHUNK_SIZE,
|
|
51
|
+
preserveContext: true,
|
|
52
|
+
maxConcurrency: CHUNK_LIMITS.MAX_CONCURRENT_REQUESTS,
|
|
53
|
+
});
|
|
54
|
+
if (rawDiff.files.length === 0) {
|
|
55
|
+
analyzeProgress.fail('No staged changes found');
|
|
56
|
+
contextualLogger.warn('Use `git add` to stage files first.');
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
analyzeProgress.succeed(`Found ${rawDiff.files.length} staged files`);
|
|
60
|
+
// Phase 2: Filter and process
|
|
61
|
+
const filterProgress = contextualLogger.startProgress('Processing and filtering changes');
|
|
62
|
+
let diff = diffFilter.filterDiff(rawDiff, {
|
|
63
|
+
ignoreGenerated: options.ignoreGenerated,
|
|
64
|
+
ignoreWhitespace: options.ignoreWhitespace,
|
|
65
|
+
maxFileSize: 1024 * 1024, // 1MB
|
|
66
|
+
relevancyThreshold: 0.1,
|
|
67
|
+
});
|
|
68
|
+
// Limit files if requested
|
|
69
|
+
if (options.maxFiles && diff.files.length > options.maxFiles) {
|
|
70
|
+
diff = {
|
|
71
|
+
...diff,
|
|
72
|
+
files: diff.files.slice(0, options.maxFiles)
|
|
73
|
+
};
|
|
74
|
+
contextualLogger.info(`Limited analysis to ${options.maxFiles} most relevant files`);
|
|
75
|
+
}
|
|
76
|
+
if (diff.files.length === 0) {
|
|
77
|
+
filterProgress.fail('No relevant changes found');
|
|
78
|
+
contextualLogger.warn('All changes were filtered out. Try adjusting filter settings.');
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const filterSummary = diffFilter.getFilteringSummary(rawDiff, diff);
|
|
82
|
+
filterProgress.succeed(`Ready to analyze ${diff.files.length} files`);
|
|
83
|
+
if (filterSummary.filesRemoved > 0) {
|
|
84
|
+
contextualLogger.debug(`Filtered out ${filterSummary.filesRemoved} irrelevant files`);
|
|
85
|
+
}
|
|
86
|
+
// Phase 3: Generate commit message
|
|
87
|
+
console.log(chalk.blue('\nš¤ Generating commit message...'));
|
|
88
|
+
const provider = options.provider || this.config.preferences.defaultProvider;
|
|
89
|
+
contextualLogger.debug(`Using ${provider} provider`);
|
|
90
|
+
// Initialize API client
|
|
91
|
+
apiManager.initializeProvider(provider, this.config);
|
|
92
|
+
// Generate commit message
|
|
93
|
+
const commitMessage = await this.generateCommitMessage(diff, options, provider);
|
|
94
|
+
if (options.dryRun) {
|
|
95
|
+
console.log(chalk.blue('\nš Generated commit message (dry run):'));
|
|
96
|
+
console.log(chalk.gray('āāāāāāāāāāāāāāāāāā'));
|
|
97
|
+
console.log(commitMessage);
|
|
98
|
+
console.log(chalk.gray('āāāāāāāāāāāāāāāāāā\n'));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
// Confirm or auto-commit
|
|
102
|
+
const shouldCommit = await this.confirmCommit(commitMessage, options);
|
|
103
|
+
if (shouldCommit) {
|
|
104
|
+
console.log(chalk.blue('\nš¾ Creating commit...'));
|
|
105
|
+
const commitProgress = contextualLogger.startProgress('Committing changes');
|
|
106
|
+
await gitManager.createCommit(commitMessage);
|
|
107
|
+
commitProgress.succeed('Commit created');
|
|
108
|
+
console.log(chalk.green('ā Commit: ') + chalk.white(commitMessage));
|
|
109
|
+
// Phase 4: Handle push
|
|
110
|
+
if (options.autoPush) {
|
|
111
|
+
console.log(chalk.blue('\nš Auto-pushing to remote...'));
|
|
112
|
+
await this.performPush(contextualLogger);
|
|
113
|
+
}
|
|
114
|
+
else if (options.push) {
|
|
115
|
+
console.log(chalk.blue('\nš Pushing to remote...'));
|
|
116
|
+
await this.performPush(contextualLogger);
|
|
117
|
+
}
|
|
118
|
+
else if (!options.yes && await gitManager.hasUnpushedCommits()) {
|
|
119
|
+
// Ask user if they want to push (only if not in auto mode)
|
|
120
|
+
try {
|
|
121
|
+
console.log(''); // Add some space
|
|
122
|
+
const shouldPush = await confirm({
|
|
123
|
+
message: 'Do you want to push to remote?'
|
|
124
|
+
});
|
|
125
|
+
if (isCancel(shouldPush)) {
|
|
126
|
+
console.log(chalk.yellow('ā¹ Push cancelled'));
|
|
127
|
+
}
|
|
128
|
+
else if (shouldPush) {
|
|
129
|
+
console.log(chalk.blue('\nš Pushing to remote...'));
|
|
130
|
+
await this.performPush(contextualLogger);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
console.log(chalk.gray('š” Tip: Use --push to automatically push changes in the future'));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
// If interactive prompts fail (e.g., in CI), skip push
|
|
138
|
+
console.log(chalk.gray('š” Tip: Use --push to automatically push changes'));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else if (await gitManager.hasUnpushedCommits()) {
|
|
142
|
+
// Just inform about unpushed commits
|
|
143
|
+
console.log(chalk.gray('š” Tip: Use --push to automatically push changes'));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
contextualLogger.info('Commit cancelled by user');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
if (error instanceof ConfigError || error instanceof GitError || error instanceof ApiError) {
|
|
152
|
+
contextualLogger.error(error.message, options.verbose ? error : undefined);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
contextualLogger.error(`Unexpected error: ${error instanceof Error ? error.message : 'Unknown error'}`, error instanceof Error ? error : undefined);
|
|
156
|
+
}
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Generate commit message from diff
|
|
162
|
+
*/
|
|
163
|
+
async generateCommitMessage(diff, options, provider) {
|
|
164
|
+
const progress = logger.startProgress('Generating commit message...');
|
|
165
|
+
try {
|
|
166
|
+
// Create system prompt
|
|
167
|
+
const systemPrompt = this.createSystemPrompt(options);
|
|
168
|
+
// Prepare diff content for processing
|
|
169
|
+
const diffContent = this.prepareDiffContent(diff);
|
|
170
|
+
const model = this.getModel(provider);
|
|
171
|
+
// Check cache first (unless disabled)
|
|
172
|
+
if (!options.noCache) {
|
|
173
|
+
const cachedMessage = await cacheManager.get(diffContent, model, provider, this.config.preferences.temperature);
|
|
174
|
+
if (cachedMessage) {
|
|
175
|
+
progress.succeed('Commit message retrieved from cache');
|
|
176
|
+
return cachedMessage;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// Get optimal chunk size for the model
|
|
180
|
+
const optimalChunkSize = tokenManager.getOptimalChunkSize(model);
|
|
181
|
+
const systemTokens = tokenManager.estimateSystemTokens(systemPrompt, model);
|
|
182
|
+
const availableTokens = optimalChunkSize - systemTokens;
|
|
183
|
+
// Check if we need to chunk the content based on tokens
|
|
184
|
+
const contentTokens = tokenManager.countTokens(diffContent, model);
|
|
185
|
+
if (contentTokens <= availableTokens) {
|
|
186
|
+
// Single request
|
|
187
|
+
const request = {
|
|
188
|
+
provider,
|
|
189
|
+
model: this.getModel(provider),
|
|
190
|
+
messages: [
|
|
191
|
+
{ role: 'system', content: systemPrompt },
|
|
192
|
+
{ role: 'user', content: diffContent },
|
|
193
|
+
],
|
|
194
|
+
maxTokens: this.config.preferences.maxTokens,
|
|
195
|
+
temperature: this.config.preferences.temperature,
|
|
196
|
+
};
|
|
197
|
+
const result = await apiManager.generateCommitMessage(request, provider);
|
|
198
|
+
if (!result.success || !result.data) {
|
|
199
|
+
throw new ApiError(result.error?.message || 'Failed to generate commit message');
|
|
200
|
+
}
|
|
201
|
+
// Cache the result
|
|
202
|
+
if (!options.noCache) {
|
|
203
|
+
await cacheManager.set(diffContent, model, provider, this.config.preferences.temperature, result.data);
|
|
204
|
+
}
|
|
205
|
+
progress.succeed('Commit message generated');
|
|
206
|
+
return result.data;
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
// Multiple chunks processing with token-based splitting
|
|
210
|
+
progress.update('Processing large diff in chunks...');
|
|
211
|
+
const chunks = tokenManager.splitIntoTokenChunks(diffContent, {
|
|
212
|
+
model,
|
|
213
|
+
maxTokens: optimalChunkSize,
|
|
214
|
+
reservedTokens: systemTokens,
|
|
215
|
+
});
|
|
216
|
+
logger.debug(`Split into ${chunks.length} token-based chunks`);
|
|
217
|
+
const baseRequest = {
|
|
218
|
+
provider,
|
|
219
|
+
model,
|
|
220
|
+
maxTokens: this.config.preferences.maxTokens,
|
|
221
|
+
temperature: this.config.preferences.temperature,
|
|
222
|
+
systemPrompt,
|
|
223
|
+
};
|
|
224
|
+
const result = await apiManager.processChunks(chunks, baseRequest, provider);
|
|
225
|
+
if (!result.success || !result.data) {
|
|
226
|
+
throw new ApiError(result.error?.message || 'Failed to process chunks');
|
|
227
|
+
}
|
|
228
|
+
// Combine chunk results into a single commit message
|
|
229
|
+
const finalMessage = this.combineChunkResults(result.data, options);
|
|
230
|
+
progress.succeed('Commit message generated from chunks');
|
|
231
|
+
return finalMessage;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
progress.fail('Failed to generate commit message');
|
|
236
|
+
throw error;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Create system prompt based on options and preferences
|
|
241
|
+
*/
|
|
242
|
+
createSystemPrompt(options) {
|
|
243
|
+
const format = this.config.preferences.commitFormat;
|
|
244
|
+
const language = this.config.preferences.language;
|
|
245
|
+
let prompt = `You are an expert Git commit message generator. Generate a concise, meaningful commit message based on the provided git diff.
|
|
246
|
+
|
|
247
|
+
Requirements:
|
|
248
|
+
- Write in ${language === 'en' ? 'English' : language}
|
|
249
|
+
- Use ${format === 'conventional' ? 'Conventional Commits format' : 'simple descriptive format'}
|
|
250
|
+
- Focus on the most significant changes
|
|
251
|
+
- Be specific and actionable
|
|
252
|
+
|
|
253
|
+
`;
|
|
254
|
+
// Formatting constraints
|
|
255
|
+
if (options.oneLine) {
|
|
256
|
+
prompt += `- Generate a single-line commit message only\n`;
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
prompt += `- Keep subject line under 72 characters\n- Add body if needed for complex changes\n`;
|
|
260
|
+
}
|
|
261
|
+
if (options.descriptionLength) {
|
|
262
|
+
prompt += `- Limit description to ${options.descriptionLength} characters\n`;
|
|
263
|
+
}
|
|
264
|
+
if (options.emoji) {
|
|
265
|
+
prompt += `- Include appropriate emoji at the start of the commit message\n`;
|
|
266
|
+
}
|
|
267
|
+
if (format === 'conventional') {
|
|
268
|
+
prompt += `\nConventional Commits format:
|
|
269
|
+
<type>[optional scope]: <description>
|
|
270
|
+
|
|
271
|
+
Types: feat, fix, docs, style, refactor, test, chore, perf, ci, build, revert
|
|
272
|
+
`;
|
|
273
|
+
if (options.emoji) {
|
|
274
|
+
prompt += `Emoji mapping:
|
|
275
|
+
- feat: āØ
|
|
276
|
+
- fix: š
|
|
277
|
+
- docs: š
|
|
278
|
+
- style: š
|
|
279
|
+
- refactor: ā»ļø
|
|
280
|
+
- test: ā
|
|
281
|
+
- chore: š§
|
|
282
|
+
- perf: ā”
|
|
283
|
+
- ci: š·
|
|
284
|
+
- build: š¦
|
|
285
|
+
- revert: āŖ
|
|
286
|
+
`;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (options.type) {
|
|
290
|
+
prompt += `\nRequired type: ${options.type}`;
|
|
291
|
+
}
|
|
292
|
+
if (options.scope) {
|
|
293
|
+
prompt += `\nRequired scope: ${options.scope}`;
|
|
294
|
+
}
|
|
295
|
+
if (options.breaking) {
|
|
296
|
+
prompt += `\nThis is a BREAKING CHANGE - include "BREAKING CHANGE:" in the commit message.`;
|
|
297
|
+
}
|
|
298
|
+
prompt += `\nGenerate only the commit message, no additional text or explanation.`;
|
|
299
|
+
return prompt;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Prepare diff content for API consumption
|
|
303
|
+
*/
|
|
304
|
+
prepareDiffContent(diff) {
|
|
305
|
+
const sections = [];
|
|
306
|
+
// Add summary
|
|
307
|
+
sections.push(`Summary: ${diff.files.length} files changed, ${diff.totalLines} lines modified\n`);
|
|
308
|
+
// Add file changes
|
|
309
|
+
for (const file of diff.files) {
|
|
310
|
+
if (file.isBinary) {
|
|
311
|
+
sections.push(`File: ${file.path} (${file.status}) - Binary file`);
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
sections.push(`File: ${file.path} (${file.status})`);
|
|
315
|
+
for (const chunk of file.chunks) {
|
|
316
|
+
if (chunk.context) {
|
|
317
|
+
sections.push(`Context: ${chunk.context}`);
|
|
318
|
+
}
|
|
319
|
+
const relevantLines = chunk.lines
|
|
320
|
+
.filter(line => line.type === 'added' || line.type === 'removed')
|
|
321
|
+
.slice(0, 20) // Limit lines per chunk
|
|
322
|
+
.map(line => `${line.type === 'added' ? '+' : '-'}${line.content}`)
|
|
323
|
+
.join('\n');
|
|
324
|
+
if (relevantLines) {
|
|
325
|
+
sections.push(relevantLines);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
sections.push(''); // Empty line between files
|
|
329
|
+
}
|
|
330
|
+
return sections.join('\n');
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Split large diff content into manageable chunks
|
|
334
|
+
*/
|
|
335
|
+
splitDiffIntoChunks(content) {
|
|
336
|
+
const chunks = [];
|
|
337
|
+
const lines = content.split('\n');
|
|
338
|
+
let currentChunk = [];
|
|
339
|
+
let currentSize = 0;
|
|
340
|
+
for (const line of lines) {
|
|
341
|
+
const lineSize = line.length + 1; // +1 for newline
|
|
342
|
+
if (currentSize + lineSize > CHUNK_LIMITS.MAX_CHUNK_SIZE && currentChunk.length > 0) {
|
|
343
|
+
chunks.push(currentChunk.join('\n'));
|
|
344
|
+
currentChunk = [];
|
|
345
|
+
currentSize = 0;
|
|
346
|
+
}
|
|
347
|
+
currentChunk.push(line);
|
|
348
|
+
currentSize += lineSize;
|
|
349
|
+
}
|
|
350
|
+
if (currentChunk.length > 0) {
|
|
351
|
+
chunks.push(currentChunk.join('\n'));
|
|
352
|
+
}
|
|
353
|
+
return chunks;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Combine results from multiple chunks into a single commit message
|
|
357
|
+
*/
|
|
358
|
+
combineChunkResults(results, options) {
|
|
359
|
+
if (results.length === 1) {
|
|
360
|
+
return results[0];
|
|
361
|
+
}
|
|
362
|
+
// Find the most comprehensive result or combine them intelligently
|
|
363
|
+
const longestResult = results.reduce((longest, current) => current.length > longest.length ? current : longest);
|
|
364
|
+
// If we have a type preference, ensure it's reflected
|
|
365
|
+
if (options.type && !longestResult.toLowerCase().includes(options.type)) {
|
|
366
|
+
const typePrefix = options.scope ? `${options.type}(${options.scope}):` : `${options.type}:`;
|
|
367
|
+
return `${typePrefix} ${longestResult.replace(/^[a-z]+(\([^)]+\))?\s*:\s*/i, '')}`;
|
|
368
|
+
}
|
|
369
|
+
return longestResult;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Get the appropriate model for the provider
|
|
373
|
+
*/
|
|
374
|
+
getModel(provider) {
|
|
375
|
+
const configuredModel = this.config.providers[provider].model;
|
|
376
|
+
if (configuredModel) {
|
|
377
|
+
return configuredModel;
|
|
378
|
+
}
|
|
379
|
+
// Default models
|
|
380
|
+
return provider === 'openrouter'
|
|
381
|
+
? 'anthropic/claude-3-haiku:beta'
|
|
382
|
+
: 'gpt-3.5-turbo';
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Confirm commit with user (unless auto-confirm is enabled)
|
|
386
|
+
*/
|
|
387
|
+
async confirmCommit(message, options) {
|
|
388
|
+
if (options.yes || this.config.preferences.autoConfirm) {
|
|
389
|
+
return true;
|
|
390
|
+
}
|
|
391
|
+
// For now, we'll implement a simple console confirmation
|
|
392
|
+
// In a full implementation, you might want to use a library like inquirer
|
|
393
|
+
console.log(`\nProposed commit message:\n${message}\n`);
|
|
394
|
+
// Simple readline implementation for confirmation
|
|
395
|
+
const readline = await import('readline');
|
|
396
|
+
const rl = readline.createInterface({
|
|
397
|
+
input: process.stdin,
|
|
398
|
+
output: process.stdout,
|
|
399
|
+
});
|
|
400
|
+
return new Promise((resolve) => {
|
|
401
|
+
rl.question('Create this commit? (y/N): ', (answer) => {
|
|
402
|
+
rl.close();
|
|
403
|
+
resolve(answer.toLowerCase().startsWith('y'));
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Validate environment before processing
|
|
409
|
+
*/
|
|
410
|
+
async validateEnvironment(options) {
|
|
411
|
+
// Check if in git repository
|
|
412
|
+
const isGitRepo = await gitManager.isGitRepository();
|
|
413
|
+
if (!isGitRepo) {
|
|
414
|
+
throw new GitError('Not in a git repository');
|
|
415
|
+
}
|
|
416
|
+
// Check if there are staged changes
|
|
417
|
+
const stagedFiles = await gitManager.getStagedFiles();
|
|
418
|
+
if (stagedFiles.length === 0) {
|
|
419
|
+
throw new GitError('No staged changes found. Use `git add` to stage files first.');
|
|
420
|
+
}
|
|
421
|
+
// Validate API configuration
|
|
422
|
+
const provider = options.provider || this.config.preferences.defaultProvider;
|
|
423
|
+
const isConfigValid = await configManager.validateConfig(provider);
|
|
424
|
+
if (!isConfigValid) {
|
|
425
|
+
throw new ConfigError(`API key not configured for ${provider}. Use 'orc config set ${provider} <api-key>' to set it.`);
|
|
426
|
+
}
|
|
427
|
+
logger.debug('Environment validation passed', {
|
|
428
|
+
provider,
|
|
429
|
+
stagedFiles: stagedFiles.length
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Perform push operation with proper messaging
|
|
434
|
+
*/
|
|
435
|
+
async performPush(contextualLogger) {
|
|
436
|
+
const hasUpstream = await gitManager.hasUpstream();
|
|
437
|
+
const currentBranch = await gitManager.getCurrentBranch();
|
|
438
|
+
const pushMessage = hasUpstream
|
|
439
|
+
? `Pushing to ${currentBranch}`
|
|
440
|
+
: `Setting upstream and pushing to ${currentBranch}`;
|
|
441
|
+
const pushProgress = contextualLogger.startProgress(pushMessage);
|
|
442
|
+
try {
|
|
443
|
+
await gitManager.pushToRemote(true); // Set upstream if needed
|
|
444
|
+
const successMessage = hasUpstream
|
|
445
|
+
? `Pushed to ${currentBranch}`
|
|
446
|
+
: `Upstream set and pushed to ${currentBranch}`;
|
|
447
|
+
pushProgress.succeed(successMessage);
|
|
448
|
+
console.log(chalk.green('ā Changes pushed successfully'));
|
|
449
|
+
}
|
|
450
|
+
catch (error) {
|
|
451
|
+
pushProgress.fail(`Push failed`);
|
|
452
|
+
console.log(chalk.red(`ā Error: ${error.message}`));
|
|
453
|
+
console.log(chalk.gray('š” You can try pushing manually: git push'));
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Determine if we should push changes
|
|
458
|
+
*/
|
|
459
|
+
async shouldPush(options) {
|
|
460
|
+
// If auto-push is enabled, always push
|
|
461
|
+
if (options.autoPush) {
|
|
462
|
+
return true;
|
|
463
|
+
}
|
|
464
|
+
// If push flag is set but not yes flag, we might want to ask
|
|
465
|
+
if (options.push && !options.yes) {
|
|
466
|
+
// For now, just return true. In future, could add interactive confirmation
|
|
467
|
+
return true;
|
|
468
|
+
}
|
|
469
|
+
return options.push || false;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
// Singleton instance
|
|
473
|
+
export const coreOrchestrator = new CoreOrchestrator();
|
|
474
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/modules/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,YAAY,EACZ,WA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AAa,CAAC,CAAC;YACjC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,YAAa,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAC/D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,2CAA2C,CAAC,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,UAAU,CAAC,OAAmB;QAC1C,uCAAuC;QACvC,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,6DAA6D;QAC7D,IAAI,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;YACjC,2EAA2E;YAC3E,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,OAAO,CAAC,IAAI,IAAI,KAAK,CAAC;IAC/B,CAAC;CACF;AAED,qBAAqB;AACrB,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { GitDiff } from '../types/index.js';
|
|
2
|
+
export interface FilterOptions {
|
|
3
|
+
ignoreWhitespace?: boolean;
|
|
4
|
+
ignoreGenerated?: boolean;
|
|
5
|
+
ignoreFormatterNoise?: boolean;
|
|
6
|
+
ignoreLockFiles?: boolean;
|
|
7
|
+
maxFileSize?: number;
|
|
8
|
+
relevancyThreshold?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface RelevancyScore {
|
|
11
|
+
file: string;
|
|
12
|
+
score: number;
|
|
13
|
+
reasons: string[];
|
|
14
|
+
}
|
|
15
|
+
export declare class DiffFilter {
|
|
16
|
+
private readonly defaultOptions;
|
|
17
|
+
private readonly generatedFilePatterns;
|
|
18
|
+
private readonly formatterPatterns;
|
|
19
|
+
private readonly highValuePatterns;
|
|
20
|
+
/**
|
|
21
|
+
* Filter diff based on relevancy and noise reduction
|
|
22
|
+
*/
|
|
23
|
+
filterDiff(diff: GitDiff, options?: Partial<FilterOptions>): GitDiff;
|
|
24
|
+
/**
|
|
25
|
+
* Filter individual file
|
|
26
|
+
*/
|
|
27
|
+
private filterFile;
|
|
28
|
+
/**
|
|
29
|
+
* Filter individual chunk
|
|
30
|
+
*/
|
|
31
|
+
private filterChunk;
|
|
32
|
+
/**
|
|
33
|
+
* Check if file is generated
|
|
34
|
+
*/
|
|
35
|
+
private isGeneratedFile;
|
|
36
|
+
/**
|
|
37
|
+
* Check if file is a lock file
|
|
38
|
+
*/
|
|
39
|
+
private isLockFile;
|
|
40
|
+
/**
|
|
41
|
+
* Check if line is whitespace-only change
|
|
42
|
+
*/
|
|
43
|
+
private isWhitespaceOnlyLine;
|
|
44
|
+
/**
|
|
45
|
+
* Check if line is formatter noise
|
|
46
|
+
*/
|
|
47
|
+
private isFormatterNoise;
|
|
48
|
+
/**
|
|
49
|
+
* Score files by relevancy
|
|
50
|
+
*/
|
|
51
|
+
private scoreFiles;
|
|
52
|
+
/**
|
|
53
|
+
* Get relevancy score based on file type
|
|
54
|
+
*/
|
|
55
|
+
private getFileTypeScore;
|
|
56
|
+
/**
|
|
57
|
+
* Generate context for filtered chunk
|
|
58
|
+
*/
|
|
59
|
+
private generateChunkContext;
|
|
60
|
+
/**
|
|
61
|
+
* Get summary of filtering actions
|
|
62
|
+
*/
|
|
63
|
+
getFilteringSummary(original: GitDiff, filtered: GitDiff): {
|
|
64
|
+
filesRemoved: number;
|
|
65
|
+
linesRemoved: number;
|
|
66
|
+
sizeReduction: string;
|
|
67
|
+
topRemovedReasons: string[];
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export declare const diffFilter: DiffFilter;
|
|
71
|
+
//# sourceMappingURL=diff-filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-filter.d.ts","sourceRoot":"","sources":["../../src/modules/diff-filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA8B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