This guide explains how to customize CodeWhisper to fit your specific needs and workflow.
- Custom Templates
- Template Variables
- Customizing AI Models
- Extending CodeWhisper
- Performance Tuning
- Integrating with Other Tools
To create and use custom templates:
-
Export the built-in templates:
codewhisper export-templates -d ./my-templates
-
Edit or create new template files in the
./my-templates
directory. -
Use your custom template:
codewhisper generate --custom-template ./my-templates/my-custom-template.hbs
Let's create a template that focuses on code statistics:
Save this as code-stats.hbs
in your templates directory and use it with:
codewhisper generate --custom-template ./my-templates/code-stats.hbs --custom-data '{"projectName": "My Project"}'
Best Practice | Description |
---|---|
Clear variable names | Use descriptive names for variables to enhance readability |
Leverage helpers | Utilize Handlebars helpers for complex logic |
Include comments | Add comments to explain template structure and logic |
Modular design | Create reusable template components |
Thorough testing | Test templates with various inputs to ensure robustness |
CodeWhisper supports two types of special variable prefixes in templates to enable interactive prompting:
Prefix | Description | Example |
---|---|---|
var_ |
Single-line input prompts | {{var_projectName}} |
multiline_ |
Multi-line input prompts (opens in default text editor) | {{multiline_projectDescription}} |
Example usage in a template:
When using a template with these variables, CodeWhisper will automatically prompt the user for input if the values aren't provided via the --custom-data
option. This feature makes it easier to create dynamic, interactive templates that can be reused across different projects.
Note: Variable values are cached to speed up repeated use of templates. The cache can be cleared by using a different cache path with the
--cache-path
option.
You can also use computed values and conditional logic in your templates:
CodeWhisper allows you to specify which AI model to use for tasks. You can customize this in your commands:
codewhisper task -m claude-3-opus-20240229
To add support for new models:
- Modify the
MODEL_CONFIGS
object insrc/ai/model-config.ts
- Update the
generateAIResponse
function insrc/ai/generate-ai-response.ts
to handle the new model
// In src/ai/model-config.ts
export const MODEL_CONFIGS: ModelSpecs = {
// ... existing models ...
'new-model-name': {
contextWindow: 100000,
maxOutput: 4096,
modelName: 'New Model',
pricing: { inputCost: 1, outputCost: 2 },
},
};
// In src/ai/generate-ai-response.ts
// Update the generateAIResponse function to handle the new model
To add new features or modify existing ones:
- Fork the CodeWhisper repository
- Clone your fork and create a new branch
- Make your changes, following the existing code style
- Add tests for your new features
- Update the documentation to reflect your changes
- Submit a pull request with a clear description of your changes
To add a new command, e.g., analyze
:
-
Create a new file
src/commands/analyze.ts
:import { Command } from 'commander'; import { processFiles } from '../core/file-processor'; import { generateMarkdown } from '../core/markdown-generator'; export function registerAnalyzeCommand(program: Command) { program .command('analyze') .description('Analyze code and generate a report') .option('-p, --path <path>', 'Path to analyze', '.') .action(async (options) => { const files = await processFiles(options); const template = ` # Code Analysis Report {{#each files}} ## {{relativePath this.path}} {{fileInfo this}} {{/each}} `; const output = await generateMarkdown(files, template, options); console.log(output); }); }
-
Update
src/cli/index.ts
to include your new command:import { registerAnalyzeCommand } from '../commands/analyze'; // ... existing code ... registerAnalyzeCommand(program); // ... existing code ...
-
Add tests for your new command in
tests/commands/analyze.test.ts
-
Update the documentation to include information about the new
analyze
command
To optimize CodeWhisper's performance:
Technique | Description | Example |
---|---|---|
Specific file filters | Reduce the number of processed files | --filter "src/**/*.js" |
Consistent cache path | Leverage the caching mechanism | --cache-path /path/to/cache |
Example:
codewhisper generate --filter "src/**/*.js" --cache-path /path/to/cache
CodeWhisper can be easily integrated with other development tools:
Integration | Description | Example |
---|---|---|
Version Control | Use CodeWhisper in pre-commit hooks | Generate documentation or perform code analysis |
CI/CD | Incorporate CodeWhisper in your pipeline | Automated code reviews or documentation generation |
IDE Extensions | Create extensions using CodeWhisper's API | In-editor code analysis and AI assistance |
Example Git pre-commit hook:
#!/bin/sh
codewhisper analyze --path ./src --output ./docs/analysis.md
git add ./docs/analysis.md
By following these customization guidelines and leveraging the advanced features, you can tailor CodeWhisper to better suit your specific needs and workflows.