cloving 0.1.18 → 0.1.19

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.
@@ -232,8 +232,20 @@ const code = async (options) => {
232
232
  const allSrcFiles = await (0, config_utils_1.getAllFiles)(options, false);
233
233
  let contextFiles = {};
234
234
  try {
235
- if (allSrcFiles) {
236
- for (const file of allSrcFiles) {
235
+ if (files) {
236
+ let expandedFiles = [];
237
+ for (const file of files) {
238
+ const filePath = path_1.default.resolve(file);
239
+ if (await fs_1.default.promises.stat(filePath).then(stat => stat.isDirectory()).catch(() => false)) {
240
+ const dirFiles = await (0, command_utils_1.getAllFilesInDirectory)(filePath);
241
+ expandedFiles = expandedFiles.concat(dirFiles.map(f => path_1.default.relative(process.cwd(), f)));
242
+ }
243
+ else {
244
+ expandedFiles.push(path_1.default.relative(process.cwd(), filePath));
245
+ }
246
+ }
247
+ files = expandedFiles;
248
+ for (const file of files) {
237
249
  const filePath = path_1.default.resolve(file);
238
250
  if (await fs_1.default.promises.stat(filePath).then(stat => stat.isFile()).catch(() => false)) {
239
251
  const content = await fs_1.default.promises.readFile(filePath, 'utf-8');
@@ -6,19 +6,57 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const cli_highlight_1 = __importDefault(require("cli-highlight"));
7
7
  const prompts_1 = require("@inquirer/prompts");
8
8
  const copy_paste_1 = __importDefault(require("copy-paste"));
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const path_1 = __importDefault(require("path"));
9
11
  const cloving_gpt_1 = __importDefault(require("../../cloving_gpt"));
10
12
  const git_utils_1 = require("../../utils/git_utils");
11
- const config_utils_1 = require("../../utils/config_utils");
12
13
  const string_utils_1 = require("../../utils/string_utils");
14
+ const command_utils_1 = require("../../utils/command_utils");
15
+ const config_utils_1 = require("../../utils/config_utils");
13
16
  const review = async (options) => {
17
+ let { prompt, files } = options;
14
18
  options.silent = (0, config_utils_1.getConfig)(options).globalSilent || false;
15
19
  const gpt = new cloving_gpt_1.default(options);
20
+ let promptText = '';
21
+ let contextFiles = {};
16
22
  try {
17
23
  // Define the prompt for analysis
18
- const gitDiff = await (0, git_utils_1.getGitDiff)();
19
- const promptText = `==== begin diff =====
24
+ if (files) {
25
+ let expandedFiles = [];
26
+ for (const file of files) {
27
+ const filePath = path_1.default.resolve(file);
28
+ if (await fs_1.default.promises.stat(filePath).then(stat => stat.isDirectory()).catch(() => false)) {
29
+ const dirFiles = await (0, command_utils_1.getAllFilesInDirectory)(filePath);
30
+ expandedFiles = expandedFiles.concat(dirFiles.map(f => path_1.default.relative(process.cwd(), f)));
31
+ }
32
+ else {
33
+ expandedFiles.push(path_1.default.relative(process.cwd(), filePath));
34
+ }
35
+ }
36
+ files = expandedFiles;
37
+ for (const file of files) {
38
+ const filePath = path_1.default.resolve(file);
39
+ if (await fs_1.default.promises.stat(filePath).then(stat => stat.isFile()).catch(() => false)) {
40
+ const content = await fs_1.default.promises.readFile(filePath, 'utf-8');
41
+ contextFiles[file] = content;
42
+ }
43
+ }
44
+ const contextFileContents = Object.keys(contextFiles).map((file) => `### Contents of ${file}\n\n${contextFiles[file]}\n\n`).join('\n');
45
+ promptText = `### Description of App
46
+
47
+ ${JSON.stringify((0, config_utils_1.getClovingConfig)(), null, 2)}
48
+
49
+ ${contextFileContents}
50
+
51
+ `;
52
+ }
53
+ else {
54
+ const gitDiff = await (0, git_utils_1.getGitDiff)();
55
+ promptText = `==== begin diff =====
20
56
  ${gitDiff}
21
- ==== end diff =====
57
+ ==== end diff =====`;
58
+ }
59
+ promptText += `
22
60
 
23
61
  ### Example of a well-structured response
24
62
 
@@ -76,6 +114,12 @@ Do not use any data from the example response structure, only use the structure.
76
114
  I would like you to explain why these change are being made and document a description of these changes.
77
115
  Also list any bugs in the new code as well as recommended fixes for those bugs with code examples.
78
116
  Format the output of this code review in Markdown format.`;
117
+ if (prompt) {
118
+ promptText += `
119
+
120
+ ### Additional Context
121
+ ${prompt}`;
122
+ }
79
123
  // get the analysis
80
124
  const analysis = await gpt.generateText({ prompt: promptText });
81
125
  // Print the analysis to the console
package/dist/index.js CHANGED
@@ -106,6 +106,8 @@ generate
106
106
  .alias('r')
107
107
  .description('Review the code for commited changes that differ from the main/master branch')
108
108
  .option('-s, --silent', 'Run the command without asking for confirmation of submitting prompts')
109
+ .option('-f, --files <filenames...>', 'Specify filenames for files you want to review')
110
+ .option('-p, --prompt <prompt>', 'Add a prompt to the review')
109
111
  .option('-m, --model <model>', 'Select the model to use (e.g., openai, claude, ollama, ollama:llama3, claude:claude-3-5-sonnet-20240620)')
110
112
  .option('-t, --temperature <temperature>', 'Temperature for the model (default 0.2)')
111
113
  .action(review_1.default);
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloving",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "packageManager": "yarn@1.22.22",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -3,7 +3,7 @@ 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
- exports.addFileOrDirectoryToContext = exports.readFileContent = exports.fetchModels = exports.runCommand = exports.generateFileList = exports.checkForSpecialFiles = exports.collectSpecialFileContents = exports.SPECIAL_FILES = void 0;
6
+ exports.addFileOrDirectoryToContext = exports.readFileContent = exports.fetchModels = exports.runCommand = exports.generateFileList = exports.getAllFilesInDirectory = exports.checkForSpecialFiles = exports.collectSpecialFileContents = exports.SPECIAL_FILES = void 0;
7
7
  const child_process_1 = require("child_process");
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const path_1 = __importDefault(require("path"));
@@ -33,6 +33,18 @@ const collectSpecialFileContents = () => {
33
33
  exports.collectSpecialFileContents = collectSpecialFileContents;
34
34
  const checkForSpecialFiles = () => exports.SPECIAL_FILES.some(file => fs_1.default.existsSync(file));
35
35
  exports.checkForSpecialFiles = checkForSpecialFiles;
36
+ const getAllFilesInDirectory = async (dir) => {
37
+ const subdirs = await fs_1.default.promises.readdir(dir);
38
+ const files = await Promise.all(subdirs.map(async (subdir) => {
39
+ const res = path_1.default.resolve(dir, subdir);
40
+ if (subdir === 'node_modules' || subdir === '.git') {
41
+ return [];
42
+ }
43
+ return (await fs_1.default.promises.stat(res)).isDirectory() ? (0, exports.getAllFilesInDirectory)(res) : res;
44
+ }));
45
+ return files.flat();
46
+ };
47
+ exports.getAllFilesInDirectory = getAllFilesInDirectory;
36
48
  const generateFileList = async () => {
37
49
  try {
38
50
  const lsOutput = await (0, exports.runCommand)('ls', []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloving",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "packageManager": "yarn@1.22.22",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",