cloving 0.1.15 → 0.1.17
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/README.md +40 -32
- package/dist/cloving_gpt/adapters/claude.js +0 -2
- package/dist/cloving_gpt/adapters/openai.js +1 -0
- package/dist/cloving_gpt/index.js +12 -18
- package/dist/commands/config.js +54 -82
- package/dist/commands/generate/code.js +47 -91
- package/dist/commands/generate/context.js +8 -16
- package/dist/commands/generate/review.js +12 -16
- package/dist/commands/generate/shell.js +22 -35
- package/dist/commands/generate/unit_tests.js +156 -68
- package/dist/commands/init.js +9 -17
- package/dist/commands/project/build.js +11 -19
- package/dist/commands/project/init.js +4 -8
- package/dist/index.js +6 -0
- package/dist/package.json +16 -17
- package/dist/utils/config_utils.js +2 -1
- package/dist/utils/git_utils.js +3 -1
- package/dist/utils/string_utils.js +3 -1
- package/package.json +16 -17
package/README.md
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
|
-
# Cloving CLI
|
|
1
|
+
# Cloving - CLI Code Generation with AI
|
|
2
2
|
|
|
3
|
-
Cloving is
|
|
3
|
+
Cloving CLI is a command line utility which integrates AI into your development workflow. It provides AI-powered code generation, commit message generation, code reviews, unit test generation, and more.
|
|
4
|
+
|
|
5
|
+
What makes the Cloving CLI different from other AI tools is that it builds sophisticated context-aware prompts to generate code, commit messages, and more.
|
|
6
|
+
|
|
7
|
+
Cloving gets to know your specific projects, the frameworks you use, the coding style you prefer, and the patterns you follow, and does its best to generate code that fits your existing project so that it actually works.
|
|
8
|
+
|
|
9
|
+
It delivers usable code that you can save directly into your project instead of copying and pasting code snippets from chat interactions.
|
|
10
|
+
|
|
11
|
+
**Read the [introduction announcement](https://cloving.ai/tutorials/introducing-the-cloving-cli).**
|
|
12
|
+
|
|
13
|
+
> [!WARNING]
|
|
14
|
+
>
|
|
15
|
+
> This project is still in the early stages of development and is not yet stable.
|
|
16
|
+
> Please use it with caution and [report any issues](https://github.com/cloving-ai/cloving-cli/issues) you encounter
|
|
4
17
|
|
|
5
18
|
## Features
|
|
6
19
|
|
|
20
|
+
- **Context-aware AI code generation**
|
|
7
21
|
- **AI-powered Git commit message generation**
|
|
8
22
|
- **Automated code reviews with AI insights**
|
|
9
23
|
- **AI-assisted unit test generation**
|
|
10
|
-
- **Seamless integration with existing development workflows**
|
|
11
|
-
- **Customizable AI prompts for different tasks**
|
|
12
|
-
- **Project initialization, planning, and building with AI assistance**
|
|
13
24
|
- **Support for multiple AI models including OpenAI, Claude, and Ollama**
|
|
14
25
|
|
|
26
|
+
## Important
|
|
27
|
+
|
|
28
|
+
The cloving will ask you before submitting any prompt to the AI model. You can use the `-s` or `--silent` flag to run the command without asking for confirmation, but by default you will have the chance to review all prompts with all the context before submitting them. This is to ensure that you are aware of what is being sent to the AI model and can make any necessary changes before submitting the prompt.
|
|
29
|
+
|
|
15
30
|
## Prerequisites
|
|
16
31
|
|
|
17
32
|
- Node.js (version 20 or higher)
|
|
@@ -91,13 +106,6 @@ Options:
|
|
|
91
106
|
- `-s, --silent`: Run without asking for confirmation of submitting prompts
|
|
92
107
|
- `-m, --model <model>`: Select the model to use
|
|
93
108
|
|
|
94
|
-
### Listing Available Models
|
|
95
|
-
|
|
96
|
-
List the available AI models:
|
|
97
|
-
```bash
|
|
98
|
-
cloving models
|
|
99
|
-
```
|
|
100
|
-
|
|
101
109
|
### Generating Commit Messages
|
|
102
110
|
|
|
103
111
|
Generate an AI-powered commit message:
|
|
@@ -112,17 +120,6 @@ Options:
|
|
|
112
120
|
- `-s, --silent`: Run without asking for confirmation
|
|
113
121
|
- `-m, --model <model>`: Select the model to use
|
|
114
122
|
|
|
115
|
-
### Generating Unit Tests
|
|
116
|
-
|
|
117
|
-
Generate unit tests for changes or specific files:
|
|
118
|
-
```bash
|
|
119
|
-
cloving generate unit-tests
|
|
120
|
-
```
|
|
121
|
-
Options:
|
|
122
|
-
- `-s, --silent`: Run without asking for confirmation
|
|
123
|
-
- `-f, --files <filenames...>`: Specify filenames for the unit tests
|
|
124
|
-
- `-m, --model <model>`: Select the model to use
|
|
125
|
-
|
|
126
123
|
### Code Reviews
|
|
127
124
|
|
|
128
125
|
Get an AI-powered code review:
|
|
@@ -147,15 +144,6 @@ Options:
|
|
|
147
144
|
- `-p, --prompt <prompt>`: Specify the prompt to use
|
|
148
145
|
- `-f, --files <filenames...>`: Specify filenames of files with context to use for generating code
|
|
149
146
|
|
|
150
|
-
### Generating Context
|
|
151
|
-
|
|
152
|
-
Create a context string for generating prompts outside of the cloving cli:
|
|
153
|
-
```bash
|
|
154
|
-
cloving generate context
|
|
155
|
-
```
|
|
156
|
-
Options:
|
|
157
|
-
- `-f, --files <filenames...>`: Specify filenames of files with context
|
|
158
|
-
|
|
159
147
|
### Generating Shell Commands
|
|
160
148
|
|
|
161
149
|
Generate a shell command based on a prompt:
|
|
@@ -171,6 +159,26 @@ Options:
|
|
|
171
159
|
- `-m, --model <model>`: Select the model to use
|
|
172
160
|
- `-p, --prompt <prompt>`: Specify the prompt to use
|
|
173
161
|
|
|
162
|
+
### Generating Context
|
|
163
|
+
|
|
164
|
+
Create a context string for generating prompts outside of the cloving cli:
|
|
165
|
+
```bash
|
|
166
|
+
cloving generate context
|
|
167
|
+
```
|
|
168
|
+
Options:
|
|
169
|
+
- `-f, --files <filenames...>`: Specify filenames of files with context
|
|
170
|
+
|
|
171
|
+
### Generating Unit Tests
|
|
172
|
+
|
|
173
|
+
Generate unit tests for changes or specific files:
|
|
174
|
+
```bash
|
|
175
|
+
cloving generate unit-tests
|
|
176
|
+
```
|
|
177
|
+
Options:
|
|
178
|
+
- `-s, --silent`: Run without asking for confirmation
|
|
179
|
+
- `-f, --files <filenames...>`: Specify filenames for the unit tests
|
|
180
|
+
- `-m, --model <model>`: Select the model to use
|
|
181
|
+
|
|
174
182
|
### Project Commands
|
|
175
183
|
|
|
176
184
|
Cloving now includes commands for managing entire projects:
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
7
|
const child_process_1 = require("child_process");
|
|
8
8
|
const process_1 = __importDefault(require("process"));
|
|
9
|
-
const
|
|
9
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
10
10
|
const claude_1 = require("./adapters/claude");
|
|
11
11
|
const openai_1 = require("./adapters/openai");
|
|
12
12
|
const mistral_1 = require("./adapters/mistral");
|
|
@@ -14,7 +14,7 @@ const ollama_1 = require("./adapters/ollama");
|
|
|
14
14
|
const gemini_1 = require("./adapters/gemini");
|
|
15
15
|
const config_utils_1 = require("../utils/config_utils");
|
|
16
16
|
class ClovingGPT {
|
|
17
|
-
constructor(options
|
|
17
|
+
constructor(options) {
|
|
18
18
|
const { model: partialModel } = options;
|
|
19
19
|
const config = (0, config_utils_1.getConfig)(options);
|
|
20
20
|
if (!config || !config.models) {
|
|
@@ -28,6 +28,7 @@ class ClovingGPT {
|
|
|
28
28
|
}
|
|
29
29
|
const { provider, model, config: modelConfig } = primaryModel;
|
|
30
30
|
this.apiKey = modelConfig.apiKey;
|
|
31
|
+
this.temperature = options.temperature || modelConfig.temperature || 0.2;
|
|
31
32
|
this.silent = options.silent || modelConfig.silent;
|
|
32
33
|
switch (provider) {
|
|
33
34
|
case 'claude':
|
|
@@ -53,14 +54,10 @@ class ClovingGPT {
|
|
|
53
54
|
if (this.silent)
|
|
54
55
|
return;
|
|
55
56
|
const tokenCount = Math.ceil(prompt.length / 4).toLocaleString();
|
|
56
|
-
const
|
|
57
|
-
{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
message: `Do you want to review the ~${tokenCount} token prompt before sending it to ${endpoint}?`,
|
|
61
|
-
default: true
|
|
62
|
-
}
|
|
63
|
-
]);
|
|
57
|
+
const reviewPrompt = await (0, prompts_1.confirm)({
|
|
58
|
+
message: `Do you want to review the ~${tokenCount} token prompt before sending it to ${endpoint}?`,
|
|
59
|
+
default: true
|
|
60
|
+
});
|
|
64
61
|
if (reviewPrompt) {
|
|
65
62
|
const less = (0, child_process_1.spawn)('less', ['-R'], { stdio: ['pipe', process_1.default.stdout, process_1.default.stderr] });
|
|
66
63
|
less.stdin.write(prompt);
|
|
@@ -72,14 +69,10 @@ class ClovingGPT {
|
|
|
72
69
|
reject(new Error('Less command failed'));
|
|
73
70
|
return;
|
|
74
71
|
}
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
message: 'Do you want to continue?',
|
|
80
|
-
default: true
|
|
81
|
-
}
|
|
82
|
-
]);
|
|
72
|
+
const confirmContinue = await (0, prompts_1.confirm)({
|
|
73
|
+
message: 'Do you want to continue?',
|
|
74
|
+
default: true
|
|
75
|
+
});
|
|
83
76
|
if (!confirmContinue) {
|
|
84
77
|
console.error('Operation cancelled');
|
|
85
78
|
process_1.default.exit(1);
|
|
@@ -99,6 +92,7 @@ class ClovingGPT {
|
|
|
99
92
|
}
|
|
100
93
|
}
|
|
101
94
|
async generateText(request) {
|
|
95
|
+
request.temperature || (request.temperature = this.temperature);
|
|
102
96
|
const endpoint = this.adapter.getEndpoint();
|
|
103
97
|
const payload = this.adapter.getPayload(request);
|
|
104
98
|
const headers = this.adapter.getHeaders(this.apiKey);
|
package/dist/commands/config.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.config = void 0;
|
|
7
4
|
const config_utils_1 = require("../utils/config_utils");
|
|
8
5
|
const command_utils_1 = require("../utils/command_utils");
|
|
9
|
-
const
|
|
6
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
10
7
|
const config = async () => {
|
|
11
8
|
let currentConfig = (0, config_utils_1.getConfig)({});
|
|
12
9
|
// Ensure models are initialized properly
|
|
@@ -21,92 +18,71 @@ const config = async () => {
|
|
|
21
18
|
let continueConfig = true;
|
|
22
19
|
while (continueConfig) {
|
|
23
20
|
const providers = [...new Set(models.map(model => model.split(':')[0]))];
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
message: 'Select a provider:',
|
|
29
|
-
choices: providers.map(provider => ({ name: provider, value: provider })),
|
|
30
|
-
},
|
|
31
|
-
]);
|
|
21
|
+
const selectedProvider = await (0, prompts_1.select)({
|
|
22
|
+
message: 'Select a provider:',
|
|
23
|
+
choices: providers.map(provider => ({ name: provider, value: provider })),
|
|
24
|
+
});
|
|
32
25
|
const providerModels = models.filter(model => model.startsWith(selectedProvider));
|
|
33
26
|
const modelCategories = [...new Set(providerModels.map(model => model.split(':')[1]))];
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
message: 'Select a category:',
|
|
39
|
-
choices: modelCategories.map(category => ({ name: category, value: category })),
|
|
40
|
-
},
|
|
41
|
-
]);
|
|
27
|
+
const selectedCategory = await (0, prompts_1.select)({
|
|
28
|
+
message: 'Select a category:',
|
|
29
|
+
choices: modelCategories.map(category => ({ name: category, value: category })),
|
|
30
|
+
});
|
|
42
31
|
const specificModels = providerModels.filter(model => model.split(':')[1] === selectedCategory);
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
choices: specificModels.map((model, index) => ({ name: model, value: index })),
|
|
49
|
-
pageSize: specificModels.length,
|
|
50
|
-
},
|
|
51
|
-
]);
|
|
32
|
+
const modelIndex = await (0, prompts_1.select)({
|
|
33
|
+
message: 'Select an AI model you\'d like to use:',
|
|
34
|
+
choices: specificModels.map((model, index) => ({ name: model, value: index })),
|
|
35
|
+
pageSize: specificModels.length,
|
|
36
|
+
});
|
|
52
37
|
const selectedModel = specificModels[modelIndex];
|
|
53
|
-
const
|
|
54
|
-
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
message: `Enter your API key for ${selectedModel}: `,
|
|
58
|
-
},
|
|
59
|
-
]);
|
|
60
|
-
const [provider, ...modelParts] = selectedModel.split(':');
|
|
38
|
+
const apiKey = await (0, prompts_1.input)({
|
|
39
|
+
message: `Enter your API key for ${selectedModel}: `,
|
|
40
|
+
});
|
|
41
|
+
const [provider, ...modelParts] = selectedModel?.split(':') || [];
|
|
61
42
|
const model = modelParts.join(':');
|
|
62
43
|
if (!currentConfig.models[provider]) {
|
|
63
44
|
currentConfig.models[provider] = {};
|
|
64
45
|
}
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
default: primary ? '100' : '0',
|
|
79
|
-
validate: (input) => {
|
|
80
|
-
const num = parseInt(input, 10);
|
|
81
|
-
if (isNaN(num) || num < 0 || num > 100) {
|
|
82
|
-
return 'Please enter a valid number between 0 and 100.';
|
|
83
|
-
}
|
|
84
|
-
return true;
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
]);
|
|
88
|
-
const { review } = await inquirer_1.default.prompt([
|
|
89
|
-
{
|
|
90
|
-
type: 'confirm',
|
|
91
|
-
name: 'review',
|
|
92
|
-
message: `Do you want to review all prompts before they are sent to ${selectedModel}?`,
|
|
93
|
-
default: true,
|
|
46
|
+
const primary = await (0, prompts_1.confirm)({
|
|
47
|
+
message: 'Set this model as the primary? Primary models are used by default if your prompt fits within its context window. You can configure backup models for larger prompts.',
|
|
48
|
+
default: true,
|
|
49
|
+
});
|
|
50
|
+
const priority = await (0, prompts_1.input)({
|
|
51
|
+
message: 'Enter the priority for this model (0-100). Higher priority AI APIs are chosen as long as the prompt fits its context window:',
|
|
52
|
+
default: primary ? '100' : '0',
|
|
53
|
+
validate: (input) => {
|
|
54
|
+
const num = parseInt(input, 10);
|
|
55
|
+
if (isNaN(num) || num < 0 || num > 100) {
|
|
56
|
+
return 'Please enter a valid number between 0 and 100.';
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
94
59
|
},
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
{
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
60
|
+
});
|
|
61
|
+
const review = await (0, prompts_1.confirm)({
|
|
62
|
+
message: `Do you want to review all prompts before they are sent to ${selectedModel}?`,
|
|
63
|
+
default: true,
|
|
64
|
+
});
|
|
65
|
+
const trust = await (0, prompts_1.confirm)({
|
|
66
|
+
message: `Do you trust ${selectedModel} with sensitive information?`,
|
|
67
|
+
default: false,
|
|
68
|
+
});
|
|
69
|
+
const temperature = await (0, prompts_1.number)({
|
|
70
|
+
message: `Enter the temperature for ${selectedModel} (0.0 - 1.0): [0.2]`,
|
|
71
|
+
default: 0.2,
|
|
72
|
+
validate: (value) => {
|
|
73
|
+
if (value && (isNaN(value) || value < 0 || value > 1)) {
|
|
74
|
+
return 'Please enter a valid number between 0.0 and 1.0.';
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
102
77
|
},
|
|
103
|
-
|
|
78
|
+
}) || 0.2;
|
|
104
79
|
const modelConfig = {
|
|
105
80
|
apiKey,
|
|
106
81
|
primary,
|
|
107
82
|
priority: parseInt(priority, 10),
|
|
108
83
|
silent: !review,
|
|
109
84
|
trust,
|
|
85
|
+
temperature,
|
|
110
86
|
};
|
|
111
87
|
currentConfig.models[provider][model] = modelConfig;
|
|
112
88
|
if (primary) {
|
|
@@ -119,14 +95,10 @@ const config = async () => {
|
|
|
119
95
|
}
|
|
120
96
|
}
|
|
121
97
|
}
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
message: 'Do you want to configure another model?',
|
|
127
|
-
default: true,
|
|
128
|
-
},
|
|
129
|
-
]);
|
|
98
|
+
const anotherModel = await (0, prompts_1.confirm)({
|
|
99
|
+
message: 'Do you want to configure another model?',
|
|
100
|
+
default: true,
|
|
101
|
+
});
|
|
130
102
|
continueConfig = anotherModel;
|
|
131
103
|
}
|
|
132
104
|
(0, config_utils_1.saveConfig)(currentConfig);
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const copy_paste_1 = __importDefault(require("copy-paste"));
|
|
7
|
-
const
|
|
7
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
8
8
|
const cli_highlight_1 = __importDefault(require("cli-highlight"));
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
@@ -127,40 +127,28 @@ const handleUserAction = async (gpt, rawCodeCommand, prompt, allSrcFiles, contex
|
|
|
127
127
|
await updateContextFiles(contextFiles, files, fileContents);
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
name: '
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
{ name: 'Done', value: 'done' },
|
|
143
|
-
],
|
|
144
|
-
},
|
|
145
|
-
]);
|
|
130
|
+
const action = await (0, prompts_1.select)({
|
|
131
|
+
message: 'What would you like to do?',
|
|
132
|
+
choices: [
|
|
133
|
+
{ name: 'Revise', value: 'revise' },
|
|
134
|
+
{ name: 'Explain', value: 'explain' },
|
|
135
|
+
{ name: 'Save a Source Code File', value: 'save' },
|
|
136
|
+
{ name: 'Save All Source Code Files', value: 'saveAll' },
|
|
137
|
+
{ name: 'Copy Source Code to Clipboard', value: 'copySource' },
|
|
138
|
+
{ name: 'Copy Entire Response to Clipboard', value: 'copyAll' },
|
|
139
|
+
{ name: 'Done', value: 'done' },
|
|
140
|
+
],
|
|
141
|
+
});
|
|
146
142
|
switch (action) {
|
|
147
143
|
case 'revise':
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
name: 'newPrompt',
|
|
152
|
-
message: 'How would you like to modify the output:',
|
|
153
|
-
},
|
|
154
|
-
]);
|
|
144
|
+
const newPrompt = await (0, prompts_1.input)({
|
|
145
|
+
message: 'How would you like to modify the output:',
|
|
146
|
+
});
|
|
155
147
|
let includeMoreFiles = true;
|
|
156
148
|
while (includeMoreFiles) {
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
name: 'contextFile',
|
|
161
|
-
message: 'Enter the relative path of a file or directory you would like to include as context (or press enter to continue):',
|
|
162
|
-
},
|
|
163
|
-
]);
|
|
149
|
+
const contextFile = await (0, prompts_1.input)({
|
|
150
|
+
message: 'Enter the relative path of a file or directory you would like to include as context (or press enter to continue):',
|
|
151
|
+
});
|
|
164
152
|
if (contextFile) {
|
|
165
153
|
contextFiles = await (0, command_utils_1.addFileOrDirectoryToContext)(contextFile, contextFiles, options);
|
|
166
154
|
}
|
|
@@ -180,14 +168,10 @@ const handleUserAction = async (gpt, rawCodeCommand, prompt, allSrcFiles, contex
|
|
|
180
168
|
case 'copySource':
|
|
181
169
|
let copyAnother = true;
|
|
182
170
|
while (copyAnother) {
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
message: 'Which file do you want to copy to the clipboard?',
|
|
188
|
-
choices: files.map(file => ({ name: file, value: file })),
|
|
189
|
-
},
|
|
190
|
-
]);
|
|
171
|
+
const fileToCopy = await (0, prompts_1.select)({
|
|
172
|
+
message: 'Which file do you want to copy to the clipboard?',
|
|
173
|
+
choices: files.map(file => ({ name: file, value: file })),
|
|
174
|
+
});
|
|
191
175
|
if (fileContents[fileToCopy]) {
|
|
192
176
|
copy_paste_1.default.copy(fileContents[fileToCopy], () => {
|
|
193
177
|
console.log(`${fileToCopy} copied to clipboard`);
|
|
@@ -196,14 +180,10 @@ const handleUserAction = async (gpt, rawCodeCommand, prompt, allSrcFiles, contex
|
|
|
196
180
|
else {
|
|
197
181
|
console.log('File content not found.');
|
|
198
182
|
}
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
message: 'Do you want to copy another file?',
|
|
204
|
-
default: true,
|
|
205
|
-
},
|
|
206
|
-
]);
|
|
183
|
+
const copyMore = await (0, prompts_1.confirm)({
|
|
184
|
+
message: 'Do you want to copy another file?',
|
|
185
|
+
default: true,
|
|
186
|
+
});
|
|
207
187
|
copyAnother = copyMore;
|
|
208
188
|
}
|
|
209
189
|
break;
|
|
@@ -215,14 +195,10 @@ const handleUserAction = async (gpt, rawCodeCommand, prompt, allSrcFiles, contex
|
|
|
215
195
|
case 'save':
|
|
216
196
|
let saveAnother = true;
|
|
217
197
|
while (saveAnother) {
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
message: 'Which file do you want to save?',
|
|
223
|
-
choices: files.map(file => ({ name: file, value: file })),
|
|
224
|
-
},
|
|
225
|
-
]);
|
|
198
|
+
const fileToSave = await (0, prompts_1.select)({
|
|
199
|
+
message: 'Which file do you want to save?',
|
|
200
|
+
choices: files.map(file => ({ name: file, value: file })),
|
|
201
|
+
});
|
|
226
202
|
if (fileContents[fileToSave]) {
|
|
227
203
|
const filePath = path_1.default.resolve(fileToSave);
|
|
228
204
|
await fs_1.default.promises.mkdir(path_1.default.dirname(filePath), { recursive: true });
|
|
@@ -233,14 +209,10 @@ const handleUserAction = async (gpt, rawCodeCommand, prompt, allSrcFiles, contex
|
|
|
233
209
|
else {
|
|
234
210
|
console.log('File content not found.');
|
|
235
211
|
}
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
message: 'Do you want to save another file?',
|
|
241
|
-
default: true,
|
|
242
|
-
},
|
|
243
|
-
]);
|
|
212
|
+
const saveMore = await (0, prompts_1.confirm)({
|
|
213
|
+
message: 'Do you want to save another file?',
|
|
214
|
+
default: true,
|
|
215
|
+
});
|
|
244
216
|
saveAnother = saveMore;
|
|
245
217
|
}
|
|
246
218
|
break;
|
|
@@ -272,13 +244,9 @@ const code = async (options) => {
|
|
|
272
244
|
else {
|
|
273
245
|
let includeMoreFiles = true;
|
|
274
246
|
while (includeMoreFiles) {
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
name: 'contextFile',
|
|
279
|
-
message: `Enter the relative path of a file or directory you would like to include as context (or press enter to continue):`,
|
|
280
|
-
},
|
|
281
|
-
]);
|
|
247
|
+
const contextFile = await (0, prompts_1.input)({
|
|
248
|
+
message: `Enter the relative path of a file or directory you would like to include as context (or press enter to continue):`,
|
|
249
|
+
});
|
|
282
250
|
if (contextFile) {
|
|
283
251
|
contextFiles = await (0, command_utils_1.addFileOrDirectoryToContext)(contextFile, contextFiles, options);
|
|
284
252
|
}
|
|
@@ -288,13 +256,9 @@ const code = async (options) => {
|
|
|
288
256
|
}
|
|
289
257
|
}
|
|
290
258
|
if (!prompt) {
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
name: 'userPrompt',
|
|
295
|
-
message: 'What would you like the code to do:',
|
|
296
|
-
},
|
|
297
|
-
]);
|
|
259
|
+
const userPrompt = await (0, prompts_1.input)({
|
|
260
|
+
message: 'What would you like the code to do:',
|
|
261
|
+
});
|
|
298
262
|
prompt = userPrompt;
|
|
299
263
|
}
|
|
300
264
|
let rawCodeCommand = await generateCode(gpt, prompt, allSrcFiles, contextFiles);
|
|
@@ -310,26 +274,18 @@ const code = async (options) => {
|
|
|
310
274
|
if (options.interactive) {
|
|
311
275
|
let continueInteractive = true;
|
|
312
276
|
while (continueInteractive) {
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
name: 'newPrompt',
|
|
317
|
-
message: 'Revise the code (or press enter to finish):',
|
|
318
|
-
},
|
|
319
|
-
]);
|
|
277
|
+
const newPrompt = await (0, prompts_1.input)({
|
|
278
|
+
message: 'Revise the code (or press enter to finish):',
|
|
279
|
+
});
|
|
320
280
|
if (newPrompt.trim() === '') {
|
|
321
281
|
continueInteractive = false;
|
|
322
282
|
}
|
|
323
283
|
else {
|
|
324
284
|
let includeMoreFiles = true;
|
|
325
285
|
while (includeMoreFiles) {
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
name: 'contextFile',
|
|
330
|
-
message: 'Enter the relative path of a file or directory you would like to include as context (or press enter to continue):',
|
|
331
|
-
},
|
|
332
|
-
]);
|
|
286
|
+
const contextFile = await (0, prompts_1.input)({
|
|
287
|
+
message: 'Enter the relative path of a file or directory you would like to include as context (or press enter to continue):',
|
|
288
|
+
});
|
|
333
289
|
if (contextFile) {
|
|
334
290
|
contextFiles = await (0, command_utils_1.addFileOrDirectoryToContext)(contextFile, contextFiles, options);
|
|
335
291
|
}
|
|
@@ -3,11 +3,11 @@ 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 inquirer_1 = __importDefault(require("inquirer"));
|
|
7
6
|
const cli_highlight_1 = __importDefault(require("cli-highlight"));
|
|
8
7
|
const copy_paste_1 = __importDefault(require("copy-paste"));
|
|
9
8
|
const fs_1 = __importDefault(require("fs"));
|
|
10
9
|
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
11
11
|
const command_utils_1 = require("../../utils/command_utils");
|
|
12
12
|
const config_utils_1 = require("../../utils/config_utils");
|
|
13
13
|
const generateContextPrompt = (files, contextFiles) => {
|
|
@@ -44,13 +44,9 @@ const context = async (options) => {
|
|
|
44
44
|
else {
|
|
45
45
|
let includeMoreFiles = true;
|
|
46
46
|
while (includeMoreFiles) {
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
name: 'contextFile',
|
|
51
|
-
message: `Enter the relative path of a file or directory you would like to include as context (or press enter to continue):`,
|
|
52
|
-
},
|
|
53
|
-
]);
|
|
47
|
+
const contextFile = await (0, prompts_1.input)({
|
|
48
|
+
message: 'Enter the relative path of a file or directory you would like to include as context (or press enter to continue):',
|
|
49
|
+
});
|
|
54
50
|
if (contextFile) {
|
|
55
51
|
contextFiles = await (0, command_utils_1.addFileOrDirectoryToContext)(contextFile, contextFiles, options);
|
|
56
52
|
}
|
|
@@ -62,14 +58,10 @@ const context = async (options) => {
|
|
|
62
58
|
const contextPrompt = generateContextPrompt(allSrcFiles, contextFiles);
|
|
63
59
|
console.log('\nGenerated Context Prompt:');
|
|
64
60
|
console.log((0, cli_highlight_1.default)(contextPrompt, { language: 'markdown' }));
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
message: 'Do you want to copy the context prompt to your clipboard?',
|
|
70
|
-
default: true,
|
|
71
|
-
},
|
|
72
|
-
]);
|
|
61
|
+
const copyToClipboard = await (0, prompts_1.confirm)({
|
|
62
|
+
message: 'Do you want to copy the context prompt to your clipboard?',
|
|
63
|
+
default: true,
|
|
64
|
+
});
|
|
73
65
|
if (copyToClipboard) {
|
|
74
66
|
copy_paste_1.default.copy(contextPrompt, () => {
|
|
75
67
|
console.log('Context prompt copied to clipboard');
|