cloving 0.1.22 → 0.1.23

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.
@@ -13,7 +13,7 @@ const cloving_gpt_1 = __importDefault(require("../cloving_gpt"));
13
13
  const git_utils_1 = require("../utils/git_utils");
14
14
  const string_utils_1 = require("../utils/string_utils");
15
15
  const command_utils_1 = require("../utils/command_utils");
16
- const PREAMBLE = `Don't apologize and when generating code, always include filenames in bold 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.`;
16
+ const PREAMBLE = `When generating code, don't apologize and wherever possible include filenames in bold 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.`;
17
17
  class ChatManager {
18
18
  constructor(options) {
19
19
  this.options = options;
@@ -24,6 +24,7 @@ class ChatManager {
24
24
  this.isMultilineMode = false;
25
25
  this.contextFiles = {};
26
26
  this.prompt = '';
27
+ this.isProcessing = false;
27
28
  options.stream = true;
28
29
  options.silent = true;
29
30
  this.gpt = new cloving_gpt_1.default(options);
@@ -69,6 +70,9 @@ class ChatManager {
69
70
  }
70
71
  }
71
72
  async handleLine(line) {
73
+ if (this.isProcessing) {
74
+ return;
75
+ }
72
76
  if (this.isMultilineMode) {
73
77
  if (line.trim() === '```') {
74
78
  this.isMultilineMode = false;
@@ -84,17 +88,17 @@ class ChatManager {
84
88
  else if (line.trim() === '```') {
85
89
  this.isMultilineMode = true;
86
90
  this.multilineInput = '';
87
- console.log('Entering multiline mode. Type ``` on a new line to end.');
91
+ console.log('Entering multiline mode. Type ``` on a new line to end.\n');
88
92
  this.rl.prompt();
89
93
  return;
90
94
  }
91
- const trimmedLine = line.trim().toLowerCase();
95
+ const trimmedLine = line.trim();
92
96
  if (trimmedLine === '') {
93
97
  this.rl.prompt();
94
98
  return;
95
99
  }
96
100
  this.updateCommandHistory(trimmedLine);
97
- if (trimmedLine === 'exit') {
101
+ if (trimmedLine.toLowerCase() === 'exit') {
98
102
  this.rl.close();
99
103
  return;
100
104
  }
@@ -192,6 +196,12 @@ class ChatManager {
192
196
  }
193
197
  }
194
198
  async processUserInput(input) {
199
+ if (this.isProcessing) {
200
+ console.log('Please wait for the current request to complete.');
201
+ return;
202
+ }
203
+ this.isProcessing = true;
204
+ this.chunkManager = new ChunkManager_1.default();
195
205
  try {
196
206
  this.chatHistory.push({ role: 'user', content: input });
197
207
  this.prompt = this.generatePrompt(input);
@@ -214,10 +224,14 @@ class ChatManager {
214
224
  });
215
225
  responseStream.data.on('end', () => {
216
226
  this.chatHistory.push({ role: 'assistant', content: accumulatedContent.trim() });
227
+ this.isProcessing = false;
228
+ process.stdout.write('\n');
217
229
  this.rl.prompt();
218
230
  });
219
231
  responseStream.data.on('error', (error) => {
220
232
  console.error('Error streaming response:', error);
233
+ this.isProcessing = false;
234
+ process.stdout.write('\n');
221
235
  this.rl.prompt();
222
236
  });
223
237
  }
@@ -242,7 +256,8 @@ class ChatManager {
242
256
  }
243
257
  // get token estimate for prompt
244
258
  const promptTokens = Math.ceil(this.prompt.length / 4).toLocaleString();
245
- console.error(`Error processing a ${promptTokens} token prompt:`, errorMessage, `(${errorNumber})`);
259
+ console.error(`Error processing a ${promptTokens} token prompt:`, errorMessage, `(${errorNumber})\n`);
260
+ this.isProcessing = false;
246
261
  this.rl.prompt();
247
262
  }
248
263
  }
@@ -250,13 +265,23 @@ class ChatManager {
250
265
  const contextFileContents = Object.keys(this.contextFiles)
251
266
  .map((file) => `### Contents of ${file}\n\n${this.contextFiles[file]}\n\n`)
252
267
  .join('\n');
253
- return `${contextFileContents}
268
+ const allButLast = this.chatHistory.slice(0, -1).map(msg => `${msg.role.toUpperCase()}: ${msg.content}`).join('\n\n');
269
+ const lastUserMessage = this.chatHistory.slice(-1).map(msg => msg.content).join('\n\n');
270
+ return `### Request
271
+
272
+ ${lastUserMessage}
273
+
274
+ ${contextFileContents}
275
+
276
+ ### Full Chat History Context
277
+
278
+ ${allButLast}
254
279
 
255
- ### Task
280
+ ### Current Request
256
281
 
257
282
  ${PREAMBLE}
258
283
 
259
- ${this.chatHistory.map(msg => `${msg.role.toUpperCase()}: ${msg.content}`).join('\n\n')}`;
284
+ ${lastUserMessage}`;
260
285
  }
261
286
  handleClose() {
262
287
  console.log('Goodbye!');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloving",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "packageManager": "yarn@1.22.22",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",