cloving 0.1.9 → 0.1.10
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/cloving_gpt/adapters/gemini.js +62 -0
- package/dist/cloving_gpt/adapters/mistral.js +46 -0
- package/dist/cloving_gpt/index.js +7 -3
- package/dist/commands/generate/code.js +134 -9
- package/dist/commands/generate/fizzbuzz.js +35 -0
- package/dist/commands/generate/review.js +103 -23
- package/dist/commands/generate/shell.js +9 -2
- package/dist/commands/models.js +5 -2
- package/dist/package.json +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GeminiAdapter = void 0;
|
|
4
|
+
class GeminiAdapter {
|
|
5
|
+
constructor(model) {
|
|
6
|
+
this.model = model;
|
|
7
|
+
}
|
|
8
|
+
static async listSupportedModels() {
|
|
9
|
+
GeminiAdapter.supportedModels.forEach(model => {
|
|
10
|
+
console.log(model);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
getEndpoint() {
|
|
14
|
+
return `https://generativelanguage.googleapis.com/v1beta/models/${this.model.replace(':', '-')}:generateContent`;
|
|
15
|
+
}
|
|
16
|
+
getHeaders(apiKey) {
|
|
17
|
+
return {
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
'x-goog-api-key': apiKey
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
getPayload(request) {
|
|
23
|
+
return {
|
|
24
|
+
contents: [
|
|
25
|
+
{
|
|
26
|
+
parts: [
|
|
27
|
+
{
|
|
28
|
+
text: request.prompt
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
generationConfig: {
|
|
34
|
+
temperature: 0.7,
|
|
35
|
+
topK: 40,
|
|
36
|
+
topP: 0.95,
|
|
37
|
+
maxOutputTokens: 1024
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
extractResponse(data) {
|
|
42
|
+
try {
|
|
43
|
+
if (data && data.candidates && data.candidates[0] && data.candidates[0].content && data.candidates[0].content.parts && data.candidates[0].content.parts[0]) {
|
|
44
|
+
return data.candidates[0].content.parts[0].text;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.error('Unexpected response structure:', data);
|
|
48
|
+
throw new Error('Invalid response structure');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
console.error('Error extracting response:', error);
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.GeminiAdapter = GeminiAdapter;
|
|
58
|
+
GeminiAdapter.supportedModels = [
|
|
59
|
+
'gemini:gemini-1.5:pro-latest',
|
|
60
|
+
'gemini:gemini-1.5:flash-latest',
|
|
61
|
+
'gemini:gemini-1.0:pro-latest',
|
|
62
|
+
];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MistralAdapter = void 0;
|
|
4
|
+
class MistralAdapter {
|
|
5
|
+
static listSupportedModels() {
|
|
6
|
+
MistralAdapter.supportedModels.forEach(model => {
|
|
7
|
+
console.log(model);
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
constructor(model) {
|
|
11
|
+
this.model = model;
|
|
12
|
+
}
|
|
13
|
+
getEndpoint() {
|
|
14
|
+
return 'https://api.mistral.ai/v1/chat/completions';
|
|
15
|
+
}
|
|
16
|
+
getHeaders(apiKey) {
|
|
17
|
+
return {
|
|
18
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
19
|
+
'Content-Type': 'application/json'
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
getPayload(request) {
|
|
23
|
+
return {
|
|
24
|
+
model: this.model.replace(':', '-'),
|
|
25
|
+
messages: [{ role: "user", content: request.prompt }],
|
|
26
|
+
max_tokens: request.maxTokens,
|
|
27
|
+
temperature: request.temperature || 0.7,
|
|
28
|
+
stream: false
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
extractResponse(data) {
|
|
32
|
+
return data.choices[0].message.content;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.MistralAdapter = MistralAdapter;
|
|
36
|
+
MistralAdapter.supportedModels = [
|
|
37
|
+
'mistral:mistral:embed',
|
|
38
|
+
'mistral:mistral:tiny-latest',
|
|
39
|
+
'mistral:mistral:small-latest',
|
|
40
|
+
'mistral:mistral:medium-latest',
|
|
41
|
+
'mistral:mistral:large-latest',
|
|
42
|
+
'mistral:open-mistral:7b',
|
|
43
|
+
'mistral:open-mixtral:8x7b',
|
|
44
|
+
'mistral:open-mixtral:8x22b',
|
|
45
|
+
'mistral:codestral:latest',
|
|
46
|
+
];
|
|
@@ -9,8 +9,9 @@ const process_1 = __importDefault(require("process"));
|
|
|
9
9
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
10
|
const claude_1 = require("./adapters/claude");
|
|
11
11
|
const openai_1 = require("./adapters/openai");
|
|
12
|
-
const
|
|
12
|
+
const mistral_1 = require("./adapters/mistral");
|
|
13
13
|
const ollama_1 = require("./adapters/ollama");
|
|
14
|
+
const gemini_1 = require("./adapters/gemini");
|
|
14
15
|
const config_utils_1 = require("../utils/config_utils");
|
|
15
16
|
class ClovingGPT {
|
|
16
17
|
constructor(options = { silent: false }) {
|
|
@@ -35,12 +36,15 @@ class ClovingGPT {
|
|
|
35
36
|
case 'openai':
|
|
36
37
|
this.adapter = new openai_1.OpenAIAdapter(model);
|
|
37
38
|
break;
|
|
38
|
-
case '
|
|
39
|
-
this.adapter = new
|
|
39
|
+
case 'mistral':
|
|
40
|
+
this.adapter = new mistral_1.MistralAdapter(model);
|
|
40
41
|
break;
|
|
41
42
|
case 'ollama':
|
|
42
43
|
this.adapter = new ollama_1.OllamaAdapter(model);
|
|
43
44
|
break;
|
|
45
|
+
case 'gemini':
|
|
46
|
+
this.adapter = new gemini_1.GeminiAdapter(model);
|
|
47
|
+
break;
|
|
44
48
|
default:
|
|
45
49
|
throw new Error(`Unsupported provider: ${provider}`);
|
|
46
50
|
}
|
|
@@ -36,11 +36,60 @@ ${previousCode}
|
|
|
36
36
|
|
|
37
37
|
`;
|
|
38
38
|
}
|
|
39
|
-
promptText += `###
|
|
39
|
+
promptText += `### Example of a well-structured response
|
|
40
|
+
|
|
41
|
+
Here are the files that I would like to generate:
|
|
42
|
+
|
|
43
|
+
1. **src/commands/generate/shell.ts**
|
|
44
|
+
|
|
45
|
+
\`\`\`typescript
|
|
46
|
+
import inquirer from 'inquirer'
|
|
47
|
+
import highlight from 'cli-highlight'
|
|
48
|
+
import { execSync } from 'child_process'
|
|
49
|
+
import ncp from 'copy-paste'
|
|
50
|
+
import { extractMarkdown } from '../../utils/string_utils'
|
|
51
|
+
import { getConfig } from '../../utils/config_utils'
|
|
52
|
+
import ClovingGPT from '../../cloving_gpt'
|
|
53
|
+
import type { ClovingGPTOptions } from '../../utils/types'
|
|
54
|
+
|
|
55
|
+
const generateShellPrompt = (prompt: string | undefined): string => {
|
|
56
|
+
const shell = execSync('echo $SHELL').toString().trim()
|
|
57
|
+
const os = execSync('echo $OSTYPE').toString().trim()
|
|
58
|
+
return \`Generate an executable \${shell} script that works on \${os}. Try to make it a single line if possible and as simple and straightforward as possible.
|
|
59
|
+
|
|
60
|
+
Do not add any commentary or context to the message other than the commit message itself.
|
|
61
|
+
|
|
62
|
+
An example of the output for this should look like the following:
|
|
63
|
+
\`\`\`
|
|
64
|
+
|
|
65
|
+
2. **src/commands/generate/code.ts**
|
|
66
|
+
|
|
67
|
+
\`\`\`typescript
|
|
68
|
+
import ncp from 'copy-paste'
|
|
69
|
+
import inquirer from 'inquirer'
|
|
70
|
+
import highlight from 'cli-highlight'
|
|
71
|
+
import { collectSpecialFileContents } from '../../utils/command_utils'
|
|
72
|
+
import { getConfig, getClovingConfig, getAllFiles } from '../../utils/config_utils'
|
|
73
|
+
import { parseMarkdownInstructions, extractMarkdown } from '../../utils/string_utils'
|
|
74
|
+
import ClovingGPT from '../../cloving_gpt'
|
|
75
|
+
import type { ClovingGPTOptions } from '../../utils/types'
|
|
76
|
+
import fs from 'fs'
|
|
77
|
+
import path from 'path'
|
|
78
|
+
|
|
79
|
+
const generateCodePrompt = (prompt: string | undefined, files: string[], contextFiles: Record<string, string>, previousCode?: string): string => {
|
|
80
|
+
const specialFileContents = collectSpecialFileContents()
|
|
81
|
+
const specialFiles = Object.keys(specialFileContents).map((file) => \`### Contents of \${file}\\n\\n\${JSON.stringify(specialFileContents[file], null, 2)}\\n\\n\`).join('\\n')
|
|
82
|
+
const contextFileContents = Object.keys(contextFiles).map((file) => \`### Contents of \${file}\\n\\n\${contextFiles[file]}\\n\\n\`).join('\\n')
|
|
83
|
+
|
|
84
|
+
return 'Here is a description of my app:'
|
|
85
|
+
}
|
|
86
|
+
\`\`\`
|
|
87
|
+
|
|
88
|
+
### Request
|
|
40
89
|
|
|
41
90
|
I would like to generate code that does the following: ${prompt}
|
|
42
91
|
|
|
43
|
-
Please generate the code and include filenames with paths to the code files mentioned and do not be lazy and ask me to keep the existing code or show things like previous code remains unchanged, always include existing code in the response.`;
|
|
92
|
+
Do not use any data from the example response structure, only use the structure. Please generate the code and include filenames with paths to the code files mentioned and do not be lazy and ask me to keep the existing code or show things like previous code remains unchanged, always include existing code in the response.`;
|
|
44
93
|
return promptText;
|
|
45
94
|
};
|
|
46
95
|
const generateExplainCodePrompt = (prompt) => {
|
|
@@ -66,7 +115,28 @@ const displayGeneratedCode = (rawCodeCommand) => {
|
|
|
66
115
|
}
|
|
67
116
|
});
|
|
68
117
|
};
|
|
118
|
+
const extractFilesAndContent = (rawCodeCommand) => {
|
|
119
|
+
const files = [];
|
|
120
|
+
const fileContents = {};
|
|
121
|
+
const matches = rawCodeCommand.match(/(\*{2})([^\*]+)(\*{2})/g);
|
|
122
|
+
if (!matches)
|
|
123
|
+
return [files, fileContents];
|
|
124
|
+
for (const match of matches) {
|
|
125
|
+
const fileName = match.replace(/\*{2}/g, '').trim();
|
|
126
|
+
const regex = new RegExp(`\\*\\*${fileName}\\*\\*\\n\\n\\\`{3}([\\s\\S]+?)\\\`{3}`, 'g');
|
|
127
|
+
const contentMatch = regex.exec(rawCodeCommand);
|
|
128
|
+
if (contentMatch) {
|
|
129
|
+
files.push(fileName);
|
|
130
|
+
let content = contentMatch[1];
|
|
131
|
+
// Remove the first word after the opening triple backticks
|
|
132
|
+
content = content.split('\n').map((line, idx) => idx === 0 ? line.replace(/^\w+\s*/, '') : line).join('\n');
|
|
133
|
+
fileContents[fileName] = content;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return [files, fileContents];
|
|
137
|
+
};
|
|
69
138
|
const handleUserAction = async (gpt, rawCodeCommand, prompt, allSrcFiles, contextFiles) => {
|
|
139
|
+
const [files, fileContents] = extractFilesAndContent(rawCodeCommand);
|
|
70
140
|
const { action } = await inquirer_1.default.prompt([
|
|
71
141
|
{
|
|
72
142
|
type: 'list',
|
|
@@ -75,9 +145,10 @@ const handleUserAction = async (gpt, rawCodeCommand, prompt, allSrcFiles, contex
|
|
|
75
145
|
choices: [
|
|
76
146
|
{ name: 'Revise', value: 'revise' },
|
|
77
147
|
{ name: 'Explain', value: 'explain' },
|
|
148
|
+
{ name: 'Save Source Code to Files', value: 'save' },
|
|
78
149
|
{ name: 'Copy Source Code to Clipboard', value: 'copySource' },
|
|
79
150
|
{ name: 'Copy Entire Response to Clipboard', value: 'copyAll' },
|
|
80
|
-
{ name: '
|
|
151
|
+
{ name: 'Done', value: 'done' },
|
|
81
152
|
],
|
|
82
153
|
},
|
|
83
154
|
]);
|
|
@@ -100,18 +171,72 @@ const handleUserAction = async (gpt, rawCodeCommand, prompt, allSrcFiles, contex
|
|
|
100
171
|
console.log((0, cli_highlight_1.default)(explainCodeCommand, { language: 'markdown' }));
|
|
101
172
|
break;
|
|
102
173
|
case 'copySource':
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
174
|
+
let copyAnother = true;
|
|
175
|
+
while (copyAnother) {
|
|
176
|
+
const { fileToCopy } = await inquirer_1.default.prompt([
|
|
177
|
+
{
|
|
178
|
+
type: 'list',
|
|
179
|
+
name: 'fileToCopy',
|
|
180
|
+
message: 'Which file do you want to copy to the clipboard?',
|
|
181
|
+
choices: files.map(file => ({ name: file, value: file })),
|
|
182
|
+
},
|
|
183
|
+
]);
|
|
184
|
+
if (fileContents[fileToCopy]) {
|
|
185
|
+
copy_paste_1.default.copy(fileContents[fileToCopy], () => {
|
|
186
|
+
console.log(`${fileToCopy} copied to clipboard`);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
console.log('File content not found.');
|
|
191
|
+
}
|
|
192
|
+
const { copyMore } = await inquirer_1.default.prompt([
|
|
193
|
+
{
|
|
194
|
+
type: 'confirm',
|
|
195
|
+
name: 'copyMore',
|
|
196
|
+
message: 'Do you want to copy another file?',
|
|
197
|
+
default: false,
|
|
198
|
+
},
|
|
199
|
+
]);
|
|
200
|
+
copyAnother = copyMore;
|
|
201
|
+
}
|
|
107
202
|
break;
|
|
108
203
|
case 'copyAll':
|
|
109
204
|
copy_paste_1.default.copy(rawCodeCommand, () => {
|
|
110
205
|
console.log('Entire response copied to clipboard');
|
|
111
206
|
});
|
|
112
207
|
break;
|
|
113
|
-
case '
|
|
114
|
-
|
|
208
|
+
case 'save':
|
|
209
|
+
let saveAnother = true;
|
|
210
|
+
while (saveAnother) {
|
|
211
|
+
const { fileToSave } = await inquirer_1.default.prompt([
|
|
212
|
+
{
|
|
213
|
+
type: 'list',
|
|
214
|
+
name: 'fileToSave',
|
|
215
|
+
message: 'Which file do you want to save?',
|
|
216
|
+
choices: files.map(file => ({ name: file, value: file })),
|
|
217
|
+
},
|
|
218
|
+
]);
|
|
219
|
+
if (fileContents[fileToSave]) {
|
|
220
|
+
const filePath = path_1.default.resolve(fileToSave);
|
|
221
|
+
fs_1.default.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
|
|
222
|
+
fs_1.default.writeFileSync(filePath, fileContents[fileToSave]);
|
|
223
|
+
console.log(`${fileToSave} has been saved.`);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
console.log('File content not found.');
|
|
227
|
+
}
|
|
228
|
+
const { saveMore } = await inquirer_1.default.prompt([
|
|
229
|
+
{
|
|
230
|
+
type: 'confirm',
|
|
231
|
+
name: 'saveMore',
|
|
232
|
+
message: 'Do you want to save another file?',
|
|
233
|
+
default: false,
|
|
234
|
+
},
|
|
235
|
+
]);
|
|
236
|
+
saveAnother = saveMore;
|
|
237
|
+
}
|
|
238
|
+
break;
|
|
239
|
+
case 'done':
|
|
115
240
|
break;
|
|
116
241
|
}
|
|
117
242
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fizzbuzzCommand = void 0;
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
9
|
+
const cli_highlight_1 = __importDefault(require("cli-highlight"));
|
|
10
|
+
const copy_paste_1 = __importDefault(require("copy-paste"));
|
|
11
|
+
const fizzbuzz_utils_1 = require("../../utils/fizzbuzz_utils");
|
|
12
|
+
exports.fizzbuzzCommand = new commander_1.Command('fizzbuzz')
|
|
13
|
+
.description('Generate FizzBuzz sequence')
|
|
14
|
+
.action(async () => {
|
|
15
|
+
const answers = await inquirer_1.default.prompt([
|
|
16
|
+
{
|
|
17
|
+
type: 'number',
|
|
18
|
+
name: 'start',
|
|
19
|
+
message: 'Enter the starting number:',
|
|
20
|
+
default: 1,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
type: 'number',
|
|
24
|
+
name: 'end',
|
|
25
|
+
message: 'Enter the ending number:',
|
|
26
|
+
default: 100,
|
|
27
|
+
},
|
|
28
|
+
]);
|
|
29
|
+
const fizzBuzzArray = (0, fizzbuzz_utils_1.generateFizzBuzzArray)(answers.start, answers.end);
|
|
30
|
+
const output = fizzBuzzArray.join('\n');
|
|
31
|
+
console.log((0, cli_highlight_1.default)(output, { language: 'plaintext', ignoreIllegals: true }));
|
|
32
|
+
copy_paste_1.default.copy(output, () => {
|
|
33
|
+
console.log('FizzBuzz sequence copied to clipboard!');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -3,30 +3,83 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const child_process_1 = require("child_process");
|
|
7
6
|
const cli_highlight_1 = __importDefault(require("cli-highlight"));
|
|
8
7
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
8
|
+
const copy_paste_1 = __importDefault(require("copy-paste"));
|
|
9
9
|
const cloving_gpt_1 = __importDefault(require("../../cloving_gpt"));
|
|
10
10
|
const git_utils_1 = require("../../utils/git_utils");
|
|
11
|
-
const string_utils_1 = require("../../utils/string_utils");
|
|
12
11
|
const config_utils_1 = require("../../utils/config_utils");
|
|
13
|
-
const
|
|
12
|
+
const string_utils_1 = require("../../utils/string_utils");
|
|
14
13
|
const review = async (options) => {
|
|
15
14
|
options.silent = (0, config_utils_1.getConfig)(options).globalSilent || false;
|
|
16
15
|
const gpt = new cloving_gpt_1.default(options);
|
|
17
16
|
try {
|
|
18
17
|
// Define the prompt for analysis
|
|
19
18
|
const gitDiff = await (0, git_utils_1.getGitDiff)();
|
|
20
|
-
const prompt =
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
const prompt = `==== begin diff =====
|
|
20
|
+
${gitDiff}
|
|
21
|
+
==== end diff =====
|
|
22
|
+
|
|
23
|
+
### Example of a well-structured response
|
|
24
|
+
|
|
25
|
+
# Code Review: Enhanced Code Generation and File Handling
|
|
26
|
+
|
|
27
|
+
## Changes Overview
|
|
28
|
+
|
|
29
|
+
These changes primarily focus on improving the code generation process and adding more robust file handling capabilities. The main modifications include:
|
|
30
|
+
|
|
31
|
+
1. Enhancing the code generation prompt with a structured example response.
|
|
32
|
+
2. Implementing a new function to extract file names and contents from the generated code.
|
|
33
|
+
3. Adding a new option to save generated code directly to files.
|
|
34
|
+
4. Improving the copy-to-clipboard functionality to allow copying individual files.
|
|
35
|
+
5. Removing an unused import in the review.ts file.
|
|
36
|
+
|
|
37
|
+
## Reason for Changes
|
|
38
|
+
|
|
39
|
+
The changes aim to enhance the usability and flexibility of the code generation tool by providing clearer prompts, better file management, and more control over the generated code.
|
|
40
|
+
|
|
41
|
+
## Detailed Description
|
|
23
42
|
|
|
24
|
-
|
|
43
|
+
1. **Enhanced Code Generation Prompt** - The \`generateCodePrompt\` function now includes a structured example of a well-formatted response. This helps guide the AI to produce more consistent and usable output, making it easier to parse and use the generated code.
|
|
44
|
+
2. **File Extraction Function** - A new function \`extractFilesAndContent\` has been added to parse the raw code command and extract individual file names and their contents. This enables more granular control over the generated code, allowing for file-specific operations.
|
|
45
|
+
3. **Save to File Option** - A new 'Save Source Code to Files' option has been added to the user action menu. This feature allows users to save generated code directly to files in the appropriate directory structure.
|
|
46
|
+
4. **Improved Copy to Clipboard** - The 'Copy Source Code to Clipboard' option has been enhanced to allow users to choose specific files to copy, rather than copying all generated code at once.
|
|
47
|
+
5. **Removed Unused Import** - The unused import of \`execFileSync\` from 'child_process' has been removed from the review.ts file, improving code cleanliness.
|
|
48
|
+
|
|
49
|
+
## Potential Bugs and Recommended Fixes
|
|
50
|
+
|
|
51
|
+
### 1. Possible undefined access in \`extractFilesAndContent\`
|
|
52
|
+
|
|
53
|
+
\`\`\`typescript
|
|
54
|
+
const contentMatch = regex.exec(rawCodeCommand)
|
|
55
|
+
if (contentMatch) {
|
|
56
|
+
files.push(fileName)
|
|
57
|
+
let content = contentMatch[1]
|
|
58
|
+
// ...
|
|
59
|
+
}
|
|
60
|
+
\`\`\`
|
|
61
|
+
|
|
62
|
+
There's a potential for \`contentMatch[1]\` to be undefined if the regex doesn't capture any groups. To fix this, add a null check:
|
|
63
|
+
|
|
64
|
+
\`\`\`typescript
|
|
65
|
+
const contentMatch = regex.exec(rawCodeCommand)
|
|
66
|
+
if (contentMatch && contentMatch[1]) {
|
|
67
|
+
files.push(fileName)
|
|
68
|
+
let content = contentMatch[1]
|
|
69
|
+
// ...
|
|
70
|
+
}
|
|
71
|
+
\`\`\`
|
|
72
|
+
|
|
73
|
+
### Request
|
|
74
|
+
|
|
75
|
+
Do not use any data from the example response structure, only use the structure.
|
|
76
|
+
I would like you to explain why these change are being made and document a description of these changes.
|
|
77
|
+
Also list any bugs in the new code as well as recommended fixes for those bugs with code examples.
|
|
78
|
+
Format the output of this code review in Markdown format.`;
|
|
25
79
|
// get the analysis
|
|
26
80
|
const analysis = await gpt.generateText({ prompt });
|
|
27
|
-
const markdown = (0, string_utils_1.extractMarkdown)(analysis);
|
|
28
81
|
// Print the analysis to the console
|
|
29
|
-
(0,
|
|
82
|
+
(0, string_utils_1.parseMarkdownInstructions)(analysis).map(code => {
|
|
30
83
|
if (code.trim().startsWith('```')) {
|
|
31
84
|
const lines = code.split('\n');
|
|
32
85
|
const language = code.match(/```(\w+)/)?.[1] || 'plaintext';
|
|
@@ -38,23 +91,50 @@ ${gitDiff}`;
|
|
|
38
91
|
console.log((0, cli_highlight_1.default)(code, { language: 'markdown' }));
|
|
39
92
|
}
|
|
40
93
|
});
|
|
41
|
-
//
|
|
42
|
-
const
|
|
94
|
+
// Modified Function to extract specific sections from the analysis
|
|
95
|
+
const extractSection = (section) => {
|
|
96
|
+
const regex = new RegExp(`## ${section}[\\s\\S]*?(?=\\n## Potential Bugs and Recommended Fixes|$)`, 'g');
|
|
97
|
+
const match = analysis.match(regex);
|
|
98
|
+
return match ? match[0].trim() : '';
|
|
99
|
+
};
|
|
100
|
+
// Prompt the user with options for copying to clipboard
|
|
101
|
+
const { clipboardOption } = await inquirer_1.default.prompt([
|
|
43
102
|
{
|
|
44
|
-
type: '
|
|
45
|
-
name: '
|
|
46
|
-
message: '
|
|
47
|
-
|
|
103
|
+
type: 'list',
|
|
104
|
+
name: 'clipboardOption',
|
|
105
|
+
message: 'What would you like to copy to the clipboard?',
|
|
106
|
+
choices: [
|
|
107
|
+
{ name: 'Copy only the Changes Overview', value: 'Changes Overview' },
|
|
108
|
+
{ name: 'Copy only the Potential Bugs and Recommended Fixes', value: 'Potential Bugs and Recommended Fixes' },
|
|
109
|
+
{ name: 'Copy everything', value: 'Everything' },
|
|
110
|
+
{ name: 'Done', value: 'Done' }
|
|
111
|
+
]
|
|
48
112
|
}
|
|
49
113
|
]);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
114
|
+
let contentToCopy = '';
|
|
115
|
+
switch (clipboardOption) {
|
|
116
|
+
case 'Changes Overview':
|
|
117
|
+
contentToCopy = extractSection('Changes Overview');
|
|
118
|
+
break;
|
|
119
|
+
case 'Potential Bugs and Recommended Fixes':
|
|
120
|
+
contentToCopy = extractSection('Potential Bugs and Recommended Fixes');
|
|
121
|
+
break;
|
|
122
|
+
case 'Everything':
|
|
123
|
+
contentToCopy = analysis;
|
|
124
|
+
break;
|
|
125
|
+
case 'Done':
|
|
126
|
+
console.log('No content copied to clipboard.');
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (contentToCopy) {
|
|
130
|
+
copy_paste_1.default.copy(contentToCopy, (err) => {
|
|
131
|
+
if (err) {
|
|
132
|
+
console.error('Error: Unable to copy to clipboard.', err);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
console.log('Selected content copied to clipboard');
|
|
136
|
+
}
|
|
137
|
+
});
|
|
58
138
|
}
|
|
59
139
|
}
|
|
60
140
|
catch (error) {
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
7
7
|
const cli_highlight_1 = __importDefault(require("cli-highlight"));
|
|
8
8
|
const child_process_1 = require("child_process");
|
|
9
|
+
const copy_paste_1 = __importDefault(require("copy-paste"));
|
|
9
10
|
const string_utils_1 = require("../../utils/string_utils");
|
|
10
11
|
const config_utils_1 = require("../../utils/config_utils");
|
|
11
12
|
const cloving_gpt_1 = __importDefault(require("../../cloving_gpt"));
|
|
@@ -86,8 +87,14 @@ const shell = async (options) => {
|
|
|
86
87
|
console.log((0, cli_highlight_1.default)(explainShellCommand, { language: 'markdown' }));
|
|
87
88
|
break;
|
|
88
89
|
case 'copy':
|
|
89
|
-
(
|
|
90
|
-
|
|
90
|
+
copy_paste_1.default.copy(generatedShellWithoutShebang, (err) => {
|
|
91
|
+
if (err) {
|
|
92
|
+
console.error('Error: Unable to copy to clipboard.', err);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
console.log('Script copied to clipboard.');
|
|
96
|
+
}
|
|
97
|
+
});
|
|
91
98
|
break;
|
|
92
99
|
case 'cancel':
|
|
93
100
|
console.log('Operation cancelled.');
|
package/dist/commands/models.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// models.ts
|
|
4
3
|
const claude_1 = require("../cloving_gpt/adapters/claude");
|
|
5
4
|
const openai_1 = require("../cloving_gpt/adapters/openai");
|
|
6
5
|
const ollama_1 = require("../cloving_gpt/adapters/ollama");
|
|
6
|
+
const gemini_1 = require("../cloving_gpt/adapters/gemini");
|
|
7
|
+
const mistral_1 = require("../cloving_gpt/adapters/mistral");
|
|
7
8
|
const listModels = async () => {
|
|
9
|
+
claude_1.ClaudeAdapter.listSupportedModels();
|
|
10
|
+
gemini_1.GeminiAdapter.listSupportedModels();
|
|
11
|
+
mistral_1.MistralAdapter.listSupportedModels();
|
|
8
12
|
try {
|
|
9
13
|
await ollama_1.OllamaAdapter.listSupportedModels();
|
|
10
14
|
}
|
|
11
15
|
catch (error) {
|
|
12
16
|
// do nothing, no ollama server running
|
|
13
17
|
}
|
|
14
|
-
claude_1.ClaudeAdapter.listSupportedModels();
|
|
15
18
|
openai_1.OpenAIAdapter.listSupportedModels();
|
|
16
19
|
};
|
|
17
20
|
exports.default = listModels;
|
package/dist/package.json
CHANGED
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"axios": "^1.7.2",
|
|
41
41
|
"cli-highlight": "^2.1.11",
|
|
42
|
-
"clipboard-copy": "^4.0.1",
|
|
43
42
|
"commander": "^12.1.0",
|
|
43
|
+
"copy-paste": "^1.5.3",
|
|
44
44
|
"eslint": "^9.6.0",
|
|
45
45
|
"eslint-config-prettier": "^9.1.0",
|
|
46
46
|
"eslint-config-raine": "^0.5.0",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"vite-node": "^2.0.1"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
+
"@types/copy-paste": "^1.1.33",
|
|
60
61
|
"@types/ini": "^4.1.1",
|
|
61
62
|
"@types/inquirer": "^9.0.7",
|
|
62
63
|
"@types/jest": "^29.5.12",
|