Skip to content

Commit

Permalink
feat: add diff-based code modifications (#63)
Browse files Browse the repository at this point in the history
* feat: add diff-based code modifications

* chore: update lockfile

* chore: fix type

* chore: add a shortcut for the diff command

* test: add more test coverage

* fix: improve diff-parser

* feat: add context flag

* test: improve test coverage

* docs: document new flag

* fix: should probably actually load the correct prompt template

* docs: note that diff mode is experimental
  • Loading branch information
gmickel authored Aug 2, 2024
1 parent 5649448 commit e1cc33a
Show file tree
Hide file tree
Showing 18 changed files with 1,056 additions and 245 deletions.
6 changes: 4 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ async function performAITask() {
await runAIAssistedTask({
path: '/path/to/project',
task: 'Implement user authentication',
description: 'Add user login and registration functionality using JWT',
description: 'Add user login and registration functionality using JWT', // detailed task description
instructions: 'Use bcrypt for password hashing...', // additional instructions, pass an empty string to skip
context: ['src/api/auth.js', 'src/utils/auth.js'], // specify files or directories to include in the task context
model: 'claude-3-5-sonnet-20240620',
dryRun: true,
dryRun: true, // Set to false to actually apply changes
});
console.log('AI-assisted task completed successfully!');
} catch (error) {
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ While CodeWhisper excels at performing individual coding tasks and even large fe

* 🧠 AI-powered task planning and code generation
* 🔄 Full git integration for version control of AI-generated changes
* 🔄 Support for diff-based code modifications to handle larger edits within output token limits
* 🌍 Support for various models and LLM providers, such as Anthropic, OpenAI, and Groq
* 🔐 Support for local models via Ollama
* 🚀 Blazingly fast code processing with concurrent workers
Expand Down Expand Up @@ -160,6 +161,8 @@ codewhisper list-models
# CodeWhisper will prompt you to select a model from the list of available models
codewhisper task

# To use the new experimental diff-based code modifications, you can use the following command:
codewhisper task --diff

# You can also specify a model directly
# Claude-3.5 Sonnet
Expand Down Expand Up @@ -192,6 +195,7 @@ While CodeWhisper supports a variety of providers and models, my current recomme
3. **GPT-4o-mini (OpenAI)**
- Strong performance
- Generates good quality plans and results
- Has a long max output length of 16384 tokens which can be used for complex tasks

#### Experimental Support

Expand Down
22 changes: 17 additions & 5 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,18 @@ codewhisper task [options]
Options:
* `-p, --path <path>`: Path to the codebase (default: current directory)
* `-m, --model <modelId>`: Specify the AI model to use (if not specified, CodeWhisper will prompt you to select a model from the list of available models)
* `-t, --task <task>`: Short task title
* `-d, --description <description>`: Detailed task description
* `-i, --instructions <instructions>`: Additional instructions for the task
* `-c, --context <paths...>`: Specify files or directories to include in the task context. Can be file paths, directory paths, or glob patterns. Multiple entries should be space-separated.
* `-df, --diff`: Use diff format for file updates instead of full file content
* `-g, --gitignore <path>`: Path to .gitignore file (default: .gitignore)
* `-f, --filter <patterns...>`: File patterns to include (use glob patterns, e.g., "src/**/*.js")
* `-e, --exclude <patterns...>`: File patterns to exclude (use glob patterns, e.g., "**/*.test.js")
* `-s, --suppress-comments`: Strip comments from the code
* `-l, --line-numbers`: Add line numbers to code blocks
* `-cw, --context-window <number>`: Specify the context window for the AI model. Only applicable for Ollama models.
* `-mt, --max-tokens <number>`: Specify the max output tokens for the AI model. Only applicable for Ollama models.
* `--case-sensitive`: Use case-sensitive pattern matching
* `--custom-ignores <patterns...>`: Additional patterns to ignore
* `--cache-path <path>`: Custom path for the cache file
Expand All @@ -50,9 +57,6 @@ Options:
* `--log-ai-interactions`: Enable logging of AI prompts, responses, and parsing results to a file (default: false)
* `-max, --max-cost-threshold <number>`: Set a maximum cost threshold for AI operations in USD (e.g., 0.5 for $0.50)
* `--auto-commit`: Automatically commit changes
* `-t, --task <task>`: Short task title
* `-d, --description <description>`: Detailed task description
* `-i, --instructions <instructions>`: Additional instructions for the task

#### Model Selection

Expand Down Expand Up @@ -319,10 +323,18 @@ codewhisper generate --model ollama:llama3.1:70b --context-window 131072 --max-t
22. Run an AI-assisted task with detailed logging:

```bash
codewhisper task -m claude-3-5-sonnet-20240620 --log-ai-interactions -t "Implement error handling" -d "Add comprehensive error handling to all API endpoints"
# This will generate a log file (codewhisper-`<date>`.log) in the current directory, containing all AI prompts, responses, and parsing results.

codewhisper task -m claude-3-5-sonnet-20240620 --log-ai-interactions -t "Implement error handling" -d "Add comprehensive error handling to all API endpoints" -i "some instructions"
```

This will generate a log file (codewhisper-`<date>`.log) in the current directory, containing all AI prompts, responses, and parsing results.
23. Run an AI-assisted task using diff-based updates:

```bash
# This command will use diff-based updates for modified files, which can help handle larger edits within token limits.

codewhisper task --diff -m claude-3-5-sonnet-20240620 -t "Refactor authentication logic" -d "Update the user authentication system to use JWT tokens" -i "some instructions"
```

## CI/CD Integration

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@
"@anthropic-ai/sdk": "0.25.0",
"@inquirer/prompts": "5.3.6",
"@octokit/rest": "21.0.1",
"ai": "3.2.42",
"@types/diff": "5.2.1",
"ai": "3.2.45",
"chalk": "5.3.0",
"commander": "12.1.0",
"diff": "5.2.0",
"dotenv": "16.4.5",
"fast-glob": "3.3.2",
"fs-extra": "11.2.0",
Expand Down
75 changes: 46 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e1cc33a

Please sign in to comment.