Cloving Generate Review Command Documentation

Learn how to use the cloving generate review command to review code changes.

Usage

cloving generate review [options]

Description

The cloving generate review command helps you review code changes by generating an analysis based on the git diff. It uses the ClovingGPT model to provide a structured review, including an overview of changes, reasons for changes, a detailed description, and potential bugs with recommended fixes.

Options

This command accepts the following options:

  • -s, --silent: Run the command without asking for confirmation of submitting prompts.
  • -m, --model <model>: Select the model to use (e.g., openai, claude, ollama, ollama:llama3, claude:claude-3-5-sonnet-20240620).

Interactive Prompts

The cloving generate review command uses the following interactive prompts:

  • Clipboard option: Prompt to select the content to copy to the clipboard (e.g., Changes Overview, Potential Bugs and Recommended Fixes, Everything, Done).

Example Process

Example Code Review Session

Here is an example of what a code review session might look like:

$ cloving generate review
Generating code review...

Generated code review:
```markdown
# Code Review: Enhanced Code Generation and File Handling

## Changes Overview

These changes primarily focus on improving the code generation process and adding more robust file handling capabilities. The main modifications include:

1. Enhancing the code generation prompt with a structured example response.
2. Implementing a new function to extract file names and contents from the generated code.
3. Adding a new option to save generated code directly to files.
4. Improving the copy-to-clipboard functionality to allow copying individual files.
5. Removing an unused import in the review.ts file.

## Reason for Changes

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.

## Detailed Description

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.
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.
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.
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.
5. **Removed Unused Import** - The unused import of \`execFileSync\` from 'child_process' has been removed from the review.ts file, improving code cleanliness.

## Potential Bugs and Recommended Fixes

### 1. Possible undefined access in \`extractFilesAndContent\`

```typescript
const contentMatch = regex.exec(rawCodeCommand)
if (contentMatch) {
files.push(fileName)
let content = contentMatch[1]
// ...
}
```

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:

```typescript
const contentMatch = regex.exec(rawCodeCommand)
if (contentMatch && contentMatch[1]) {
files.push(fileName)
let content = contentMatch[1]
// ...
}
```

What would you like to copy to the clipboard?
1. Copy only the Changes Overview
2. Copy only the Potential Bugs and Recommended Fixes
3. Copy everything
4. Done

If you choose to copy specific content to the clipboard, the process continues as follows:

$ cloving generate review
Generating code review...

Generated code review:
```markdown
# Code Review: Enhanced Code Generation and File Handling

## Changes Overview

These changes primarily focus on improving the code generation process and adding more robust file handling capabilities. The main modifications include:

1. Enhancing the code generation prompt with a structured example response.
2. Implementing a new function to extract file names and contents from the generated code.
3. Adding a new option to save generated code directly to files.
4. Improving the copy-to-clipboard functionality to allow copying individual files.
5. Removing an unused import in the review.ts file.
```

What would you like to copy to the clipboard?
1. Copy only the Changes Overview
2. Copy only the Potential Bugs and Recommended Fixes
3. Copy everything
4. Done
> 1
Selected content copied to clipboard