git-coco 0.14.0 → 0.14.1
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.d.ts +8 -2
- package/dist/index.esm.mjs +90 -26
- package/dist/index.js +90 -26
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as yargs from 'yargs';
|
|
2
2
|
import { Arguments } from 'yargs';
|
|
3
|
+
import { AnthropicInput, ChatAnthropic } from '@langchain/anthropic';
|
|
3
4
|
import { OllamaInput } from '@langchain/community/llms/ollama';
|
|
4
5
|
import { BaseLLMParams } from '@langchain/core/language_models/llms';
|
|
5
6
|
import * as _langchain_openai from '@langchain/openai';
|
|
6
7
|
import { TiktokenModel, OpenAIInput, ChatOpenAI } from '@langchain/openai';
|
|
7
8
|
import { SimpleGit } from 'simple-git';
|
|
8
|
-
import { ChatAnthropic } from '@langchain/anthropic';
|
|
9
9
|
import { ChatOllama } from '@langchain/ollama';
|
|
10
10
|
import { Color } from 'chalk';
|
|
11
11
|
import { TiktokenModel as TiktokenModel$1 } from 'tiktoken';
|
|
@@ -61,6 +61,7 @@ type Authentication = {
|
|
|
61
61
|
};
|
|
62
62
|
type OpenAIFields = Partial<OpenAIInput> & BaseLLMParams;
|
|
63
63
|
type OllamaFields = Partial<OllamaInput> & BaseLLMParams;
|
|
64
|
+
type AnthropicFields = Partial<AnthropicInput> & BaseLLMParams;
|
|
64
65
|
type OpenAILLMService = BaseLLMService & {
|
|
65
66
|
provider: 'openai';
|
|
66
67
|
model: TiktokenModel;
|
|
@@ -72,7 +73,12 @@ type OllamaLLMService = BaseLLMService & {
|
|
|
72
73
|
endpoint: string;
|
|
73
74
|
fields?: OllamaFields;
|
|
74
75
|
};
|
|
75
|
-
type
|
|
76
|
+
type AnthropicLLMService = BaseLLMService & {
|
|
77
|
+
provider: 'anthropic';
|
|
78
|
+
model: string;
|
|
79
|
+
fields?: AnthropicFields;
|
|
80
|
+
};
|
|
81
|
+
type LLMService = OpenAILLMService | OllamaLLMService | AnthropicLLMService;
|
|
76
82
|
|
|
77
83
|
type BaseConfig = {
|
|
78
84
|
/**
|
package/dist/index.esm.mjs
CHANGED
|
@@ -268,7 +268,7 @@ function getDefaultServiceConfigFromAlias(provider, model) {
|
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
-
const DEFAULT_IGNORED_FILES = ['package-lock.json'];
|
|
271
|
+
const DEFAULT_IGNORED_FILES = ['package-lock.json', 'yarn.lock', 'node_modules'];
|
|
272
272
|
const DEFAULT_IGNORED_EXTENSIONS = ['.map', '.lock'];
|
|
273
273
|
const COCO_CONFIG_START_COMMENT = '# -- start coco config --';
|
|
274
274
|
const COCO_CONFIG_END_COMMENT = '# -- end coco config --';
|
|
@@ -7108,6 +7108,46 @@ var recap = {
|
|
|
7108
7108
|
options: options$1,
|
|
7109
7109
|
};
|
|
7110
7110
|
|
|
7111
|
+
/**
|
|
7112
|
+
* Retrieves the diff between the current branch and a specified target branch.
|
|
7113
|
+
*
|
|
7114
|
+
* @param {Object} options - The options for retrieving the diff.
|
|
7115
|
+
* @param {SimpleGit} options.git - The SimpleGit instance.
|
|
7116
|
+
* @param {Logger} options.logger - The logger for logging messages.
|
|
7117
|
+
* @param {string} options.targetBranch - The target branch to compare against.
|
|
7118
|
+
* @param {string[]} options.ignoredFiles - Array of specific files to ignore.
|
|
7119
|
+
* @param {string[]} options.ignoredExtensions - Array of file extensions to ignore.
|
|
7120
|
+
* @returns {Promise<string>} The diff between the current branch and the target branch.
|
|
7121
|
+
*/
|
|
7122
|
+
async function getDiffForBranch({ git, logger, targetBranch, ignoredFiles = [], ignoredExtensions = [], }) {
|
|
7123
|
+
try {
|
|
7124
|
+
// Get the current branch name
|
|
7125
|
+
const currentBranch = await getCurrentBranchName({ git });
|
|
7126
|
+
// Prepare ignore patterns
|
|
7127
|
+
const ignorePatterns = [
|
|
7128
|
+
...ignoredFiles.map((file) => `:!${file}`),
|
|
7129
|
+
...ignoredExtensions.map((ext) => `:!*${ext}`),
|
|
7130
|
+
];
|
|
7131
|
+
// Construct the diff command
|
|
7132
|
+
const diffArgs = [`${targetBranch}..${currentBranch}`];
|
|
7133
|
+
if (ignorePatterns.length > 0) {
|
|
7134
|
+
diffArgs.push('--');
|
|
7135
|
+
diffArgs.push(...ignorePatterns);
|
|
7136
|
+
}
|
|
7137
|
+
// Get the diff
|
|
7138
|
+
const diff = await git.diff(diffArgs);
|
|
7139
|
+
logger?.verbose(`Generated diff between "${currentBranch}" and "${targetBranch}"`, {
|
|
7140
|
+
color: 'blue',
|
|
7141
|
+
});
|
|
7142
|
+
return diff;
|
|
7143
|
+
}
|
|
7144
|
+
catch (error) {
|
|
7145
|
+
console.error('Error in getDiffForBranch:', error);
|
|
7146
|
+
logger?.log('Encountered an error getting diff between branches', { color: 'red' });
|
|
7147
|
+
return '';
|
|
7148
|
+
}
|
|
7149
|
+
}
|
|
7150
|
+
|
|
7111
7151
|
function getDefaultExportFromCjs (x) {
|
|
7112
7152
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
7113
7153
|
}
|
|
@@ -28273,33 +28313,52 @@ const handler = async (argv, logger) => {
|
|
|
28273
28313
|
logger.log(LOGO);
|
|
28274
28314
|
}
|
|
28275
28315
|
async function factory() {
|
|
28276
|
-
|
|
28277
|
-
|
|
28278
|
-
|
|
28279
|
-
|
|
28316
|
+
if (argv.branch) {
|
|
28317
|
+
logger.verbose(`Generating diff for branch: ${argv.branch}`, { color: 'yellow' });
|
|
28318
|
+
const diff = await getDiffForBranch({
|
|
28319
|
+
git,
|
|
28320
|
+
logger,
|
|
28321
|
+
targetBranch: argv.branch,
|
|
28322
|
+
ignoredFiles: config.ignoredFiles || [],
|
|
28323
|
+
ignoredExtensions: config.ignoredExtensions || [],
|
|
28324
|
+
});
|
|
28325
|
+
return [diff];
|
|
28280
28326
|
}
|
|
28281
|
-
|
|
28282
|
-
|
|
28327
|
+
else {
|
|
28328
|
+
const { staged, unstaged, untracked } = await getChanges({
|
|
28329
|
+
git,
|
|
28330
|
+
options: {
|
|
28331
|
+
ignoredFiles: config.ignoredFiles || undefined,
|
|
28332
|
+
ignoredExtensions: config.ignoredExtensions || undefined,
|
|
28333
|
+
},
|
|
28334
|
+
});
|
|
28335
|
+
if (staged.length === 0 && unstaged?.length === 0 && untracked?.length === 0) {
|
|
28336
|
+
logger.log('No changes detected. Exiting...');
|
|
28337
|
+
process.exit(0);
|
|
28338
|
+
}
|
|
28339
|
+
if (INTERACTIVE) {
|
|
28340
|
+
logger.verbose(`Staged: ${staged.length}, Unstaged: ${unstaged?.length || 0}, Untracked: ${untracked?.length || 0}`);
|
|
28341
|
+
}
|
|
28342
|
+
const unstagedChanges = await fileChangeParser({
|
|
28343
|
+
changes: unstaged || [],
|
|
28344
|
+
commit: '--unstaged',
|
|
28345
|
+
options: { tokenizer, git, llm, logger },
|
|
28346
|
+
});
|
|
28347
|
+
const unstagedResponse = `Unstaged changes:\n${unstagedChanges}`;
|
|
28348
|
+
const untrackedChanges = await fileChangeParser({
|
|
28349
|
+
changes: untracked || [],
|
|
28350
|
+
commit: '--untracked',
|
|
28351
|
+
options: { tokenizer, git, llm, logger },
|
|
28352
|
+
});
|
|
28353
|
+
const untrackedResponse = `Untracked changes:\n${untrackedChanges}`;
|
|
28354
|
+
const stagedChanges = await fileChangeParser({
|
|
28355
|
+
changes: staged,
|
|
28356
|
+
commit: '--staged',
|
|
28357
|
+
options: { tokenizer, git, llm, logger },
|
|
28358
|
+
});
|
|
28359
|
+
const stagedResponse = `Staged changes:\n${stagedChanges}`;
|
|
28360
|
+
return [unstagedResponse, untrackedResponse, stagedResponse];
|
|
28283
28361
|
}
|
|
28284
|
-
const unstagedChanges = await fileChangeParser({
|
|
28285
|
-
changes: unstaged || [],
|
|
28286
|
-
commit: '--unstaged',
|
|
28287
|
-
options: { tokenizer, git, llm, logger },
|
|
28288
|
-
});
|
|
28289
|
-
const unstagedResponse = `Unstaged changes:\n${unstagedChanges}`;
|
|
28290
|
-
const untrackedChanges = await fileChangeParser({
|
|
28291
|
-
changes: untracked || [],
|
|
28292
|
-
commit: '--untracked',
|
|
28293
|
-
options: { tokenizer, git, llm, logger },
|
|
28294
|
-
});
|
|
28295
|
-
const untrackedResponse = `Untracked changes:\n${untrackedChanges}`;
|
|
28296
|
-
const stagedChanges = await fileChangeParser({
|
|
28297
|
-
changes: staged,
|
|
28298
|
-
commit: '--staged',
|
|
28299
|
-
options: { tokenizer, git, llm, logger },
|
|
28300
|
-
});
|
|
28301
|
-
const stagedResponse = `Staged changes:\n${stagedChanges}`;
|
|
28302
|
-
return [unstagedResponse, untrackedResponse, stagedResponse];
|
|
28303
28362
|
}
|
|
28304
28363
|
async function parser(changes) {
|
|
28305
28364
|
return changes.join('\n');
|
|
@@ -28372,6 +28431,11 @@ const options = {
|
|
|
28372
28431
|
alias: 'interactive',
|
|
28373
28432
|
description: 'Toggle interactive mode',
|
|
28374
28433
|
},
|
|
28434
|
+
'b': {
|
|
28435
|
+
type: 'string',
|
|
28436
|
+
alias: 'branch',
|
|
28437
|
+
description: 'Branch to review',
|
|
28438
|
+
},
|
|
28375
28439
|
};
|
|
28376
28440
|
const builder = (yargs) => {
|
|
28377
28441
|
return yargs.options(options).usage(getCommandUsageHeader(review.command));
|
package/dist/index.js
CHANGED
|
@@ -290,7 +290,7 @@ function getDefaultServiceConfigFromAlias(provider, model) {
|
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
-
const DEFAULT_IGNORED_FILES = ['package-lock.json'];
|
|
293
|
+
const DEFAULT_IGNORED_FILES = ['package-lock.json', 'yarn.lock', 'node_modules'];
|
|
294
294
|
const DEFAULT_IGNORED_EXTENSIONS = ['.map', '.lock'];
|
|
295
295
|
const COCO_CONFIG_START_COMMENT = '# -- start coco config --';
|
|
296
296
|
const COCO_CONFIG_END_COMMENT = '# -- end coco config --';
|
|
@@ -7130,6 +7130,46 @@ var recap = {
|
|
|
7130
7130
|
options: options$1,
|
|
7131
7131
|
};
|
|
7132
7132
|
|
|
7133
|
+
/**
|
|
7134
|
+
* Retrieves the diff between the current branch and a specified target branch.
|
|
7135
|
+
*
|
|
7136
|
+
* @param {Object} options - The options for retrieving the diff.
|
|
7137
|
+
* @param {SimpleGit} options.git - The SimpleGit instance.
|
|
7138
|
+
* @param {Logger} options.logger - The logger for logging messages.
|
|
7139
|
+
* @param {string} options.targetBranch - The target branch to compare against.
|
|
7140
|
+
* @param {string[]} options.ignoredFiles - Array of specific files to ignore.
|
|
7141
|
+
* @param {string[]} options.ignoredExtensions - Array of file extensions to ignore.
|
|
7142
|
+
* @returns {Promise<string>} The diff between the current branch and the target branch.
|
|
7143
|
+
*/
|
|
7144
|
+
async function getDiffForBranch({ git, logger, targetBranch, ignoredFiles = [], ignoredExtensions = [], }) {
|
|
7145
|
+
try {
|
|
7146
|
+
// Get the current branch name
|
|
7147
|
+
const currentBranch = await getCurrentBranchName({ git });
|
|
7148
|
+
// Prepare ignore patterns
|
|
7149
|
+
const ignorePatterns = [
|
|
7150
|
+
...ignoredFiles.map((file) => `:!${file}`),
|
|
7151
|
+
...ignoredExtensions.map((ext) => `:!*${ext}`),
|
|
7152
|
+
];
|
|
7153
|
+
// Construct the diff command
|
|
7154
|
+
const diffArgs = [`${targetBranch}..${currentBranch}`];
|
|
7155
|
+
if (ignorePatterns.length > 0) {
|
|
7156
|
+
diffArgs.push('--');
|
|
7157
|
+
diffArgs.push(...ignorePatterns);
|
|
7158
|
+
}
|
|
7159
|
+
// Get the diff
|
|
7160
|
+
const diff = await git.diff(diffArgs);
|
|
7161
|
+
logger?.verbose(`Generated diff between "${currentBranch}" and "${targetBranch}"`, {
|
|
7162
|
+
color: 'blue',
|
|
7163
|
+
});
|
|
7164
|
+
return diff;
|
|
7165
|
+
}
|
|
7166
|
+
catch (error) {
|
|
7167
|
+
console.error('Error in getDiffForBranch:', error);
|
|
7168
|
+
logger?.log('Encountered an error getting diff between branches', { color: 'red' });
|
|
7169
|
+
return '';
|
|
7170
|
+
}
|
|
7171
|
+
}
|
|
7172
|
+
|
|
7133
7173
|
function getDefaultExportFromCjs (x) {
|
|
7134
7174
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
7135
7175
|
}
|
|
@@ -28295,33 +28335,52 @@ const handler = async (argv, logger) => {
|
|
|
28295
28335
|
logger.log(LOGO);
|
|
28296
28336
|
}
|
|
28297
28337
|
async function factory() {
|
|
28298
|
-
|
|
28299
|
-
|
|
28300
|
-
|
|
28301
|
-
|
|
28338
|
+
if (argv.branch) {
|
|
28339
|
+
logger.verbose(`Generating diff for branch: ${argv.branch}`, { color: 'yellow' });
|
|
28340
|
+
const diff = await getDiffForBranch({
|
|
28341
|
+
git,
|
|
28342
|
+
logger,
|
|
28343
|
+
targetBranch: argv.branch,
|
|
28344
|
+
ignoredFiles: config.ignoredFiles || [],
|
|
28345
|
+
ignoredExtensions: config.ignoredExtensions || [],
|
|
28346
|
+
});
|
|
28347
|
+
return [diff];
|
|
28302
28348
|
}
|
|
28303
|
-
|
|
28304
|
-
|
|
28349
|
+
else {
|
|
28350
|
+
const { staged, unstaged, untracked } = await getChanges({
|
|
28351
|
+
git,
|
|
28352
|
+
options: {
|
|
28353
|
+
ignoredFiles: config.ignoredFiles || undefined,
|
|
28354
|
+
ignoredExtensions: config.ignoredExtensions || undefined,
|
|
28355
|
+
},
|
|
28356
|
+
});
|
|
28357
|
+
if (staged.length === 0 && unstaged?.length === 0 && untracked?.length === 0) {
|
|
28358
|
+
logger.log('No changes detected. Exiting...');
|
|
28359
|
+
process.exit(0);
|
|
28360
|
+
}
|
|
28361
|
+
if (INTERACTIVE) {
|
|
28362
|
+
logger.verbose(`Staged: ${staged.length}, Unstaged: ${unstaged?.length || 0}, Untracked: ${untracked?.length || 0}`);
|
|
28363
|
+
}
|
|
28364
|
+
const unstagedChanges = await fileChangeParser({
|
|
28365
|
+
changes: unstaged || [],
|
|
28366
|
+
commit: '--unstaged',
|
|
28367
|
+
options: { tokenizer, git, llm, logger },
|
|
28368
|
+
});
|
|
28369
|
+
const unstagedResponse = `Unstaged changes:\n${unstagedChanges}`;
|
|
28370
|
+
const untrackedChanges = await fileChangeParser({
|
|
28371
|
+
changes: untracked || [],
|
|
28372
|
+
commit: '--untracked',
|
|
28373
|
+
options: { tokenizer, git, llm, logger },
|
|
28374
|
+
});
|
|
28375
|
+
const untrackedResponse = `Untracked changes:\n${untrackedChanges}`;
|
|
28376
|
+
const stagedChanges = await fileChangeParser({
|
|
28377
|
+
changes: staged,
|
|
28378
|
+
commit: '--staged',
|
|
28379
|
+
options: { tokenizer, git, llm, logger },
|
|
28380
|
+
});
|
|
28381
|
+
const stagedResponse = `Staged changes:\n${stagedChanges}`;
|
|
28382
|
+
return [unstagedResponse, untrackedResponse, stagedResponse];
|
|
28305
28383
|
}
|
|
28306
|
-
const unstagedChanges = await fileChangeParser({
|
|
28307
|
-
changes: unstaged || [],
|
|
28308
|
-
commit: '--unstaged',
|
|
28309
|
-
options: { tokenizer, git, llm, logger },
|
|
28310
|
-
});
|
|
28311
|
-
const unstagedResponse = `Unstaged changes:\n${unstagedChanges}`;
|
|
28312
|
-
const untrackedChanges = await fileChangeParser({
|
|
28313
|
-
changes: untracked || [],
|
|
28314
|
-
commit: '--untracked',
|
|
28315
|
-
options: { tokenizer, git, llm, logger },
|
|
28316
|
-
});
|
|
28317
|
-
const untrackedResponse = `Untracked changes:\n${untrackedChanges}`;
|
|
28318
|
-
const stagedChanges = await fileChangeParser({
|
|
28319
|
-
changes: staged,
|
|
28320
|
-
commit: '--staged',
|
|
28321
|
-
options: { tokenizer, git, llm, logger },
|
|
28322
|
-
});
|
|
28323
|
-
const stagedResponse = `Staged changes:\n${stagedChanges}`;
|
|
28324
|
-
return [unstagedResponse, untrackedResponse, stagedResponse];
|
|
28325
28384
|
}
|
|
28326
28385
|
async function parser(changes) {
|
|
28327
28386
|
return changes.join('\n');
|
|
@@ -28394,6 +28453,11 @@ const options = {
|
|
|
28394
28453
|
alias: 'interactive',
|
|
28395
28454
|
description: 'Toggle interactive mode',
|
|
28396
28455
|
},
|
|
28456
|
+
'b': {
|
|
28457
|
+
type: 'string',
|
|
28458
|
+
alias: 'branch',
|
|
28459
|
+
description: 'Branch to review',
|
|
28460
|
+
},
|
|
28397
28461
|
};
|
|
28398
28462
|
const builder = (yargs) => {
|
|
28399
28463
|
return yargs.options(options).usage(getCommandUsageHeader(review.command));
|