- Simplified README.md by moving detailed command docs, workflows, and development info to dedicated user-guide/ and developer-guide/ directories. - Created index.md files for both guides to improve navigation. - Extracted individual command guides (e.g., chat.md, edit.md) into user-guide/ for focused, maintainable documentation. - Moved architecture, configuration, and troubleshooting to developer-guide/. - Updated README links to point to the new docs structure.
54 lines
2.3 KiB
Markdown
54 lines
2.3 KiB
Markdown
# ✏️ Edit Guide
|
|
|
|
The `edit` command allows you to modify an existing file in-place using natural language instructions. It's a quick and efficient way to refactor code, fix bugs, or add features without manually editing the file.
|
|
|
|
### Why use Edit?
|
|
|
|
- **Natural Language**: Just tell Grok what you want to change (e.g., "Add a new parameter to the `NewClient` function").
|
|
- **Interactive Preview**: See the proposed changes in a unified diff format before they are applied.
|
|
- **Refactoring made easy**: Effortlessly refactor large functions or rewrite entire blocks of code.
|
|
- **Cleanup**: `edit` automatically removes unnecessary comments, last modified timestamps, and ownership headers for a cleaner codebase.
|
|
|
|
### Basic Usage
|
|
|
|
```bash
|
|
# Basic usage
|
|
grokkit edit main.go "add error handling to all functions"
|
|
|
|
# Complex refactoring
|
|
grokkit edit server.go "convert this to use context for cancellation"
|
|
|
|
# Add features
|
|
grokkit edit api.go "add rate limiting middleware"
|
|
|
|
# Documentation
|
|
grokkit edit utils.go "add detailed docstrings to all exported functions"
|
|
```
|
|
|
|
### Safety Features
|
|
|
|
- **Diff-style Preview**: Shows exactly what will change.
|
|
- **Confirmation Required**: Nothing is written without your `y/N`.
|
|
- **Silent Streaming**: No console spam while waiting.
|
|
|
|
### Options
|
|
|
|
| Flag | Description |
|
|
|------|-------------|
|
|
| `--model`, `-m` | Override the default model (e.g., `grok-4`) |
|
|
|
|
### How it Works
|
|
|
|
1. **File Retrieval**: Grokkit reads the content of the target file.
|
|
2. **Contextual Analysis**: It prepares a prompt for Grok with the original file content and your instructions.
|
|
3. **AI Generation**: Grok processes the request and returns the updated file content.
|
|
4. **Interactive Preview**: Grokkit shows you a preview of the changes in a unified diff format.
|
|
5. **Confirmation**: You review the changes and confirm before the file is overwritten.
|
|
|
|
### Best Practices
|
|
|
|
- **Specific Instructions**: The more specific you are, the better the result. Instead of "Fix the bug", try "Fix the race condition in the `UpdateState` method".
|
|
- **Review carefully**: Always review the diff before applying changes, especially for complex refactors.
|
|
- **Git workflow**: Commit your changes before using `edit` so you can easily revert if you're not happy with the result.
|
|
- **Combine with Lint**: After editing, run `grokkit lint` to ensure the new code meets your project's standards.
|