add support for GROK.md custom instructions
This commit is contained in:
1 parent
d41a31cf36
commit
694258c620
3 files changed
+47
-1
No files matched your search
@@ -65,6 +65,27 @@ Or specify a working directory:
|
||||
grok -d /path/to/project
|
||||
```
|
||||
|
||||
### Custom Instructions
|
||||
|
||||
You can provide custom instructions to tailor Grok's behavior to your project by creating a `.grok/GROK.md` file in your project directory:
|
||||
|
||||
```bash
|
||||
mkdir .grok
|
||||
```
|
||||
|
||||
Create `.grok/GROK.md` with your custom instructions:
|
||||
```markdown
|
||||
# Custom Instructions for Grok CLI
|
||||
|
||||
Always use TypeScript for any new code files.
|
||||
When creating React components, use functional components with hooks.
|
||||
Prefer const assertions and explicit typing over inference where it improves clarity.
|
||||
Always add JSDoc comments for public functions and interfaces.
|
||||
Follow the existing code style and patterns in this project.
|
||||
```
|
||||
|
||||
Grok will automatically load and follow these instructions when working in your project directory. The custom instructions are added to Grok's system prompt and take priority over default behavior.
|
||||
|
||||
## Example Conversations
|
||||
|
||||
Instead of typing commands, just tell Grok what you want to do:
|
||||
|
||||
@@ -4,6 +4,7 @@ import { TextEditorTool, BashTool, TodoTool, ConfirmationTool } from '../tools';
|
||||
import { ToolResult } from '../types';
|
||||
import { EventEmitter } from 'events';
|
||||
import { createTokenCounter, TokenCounter } from '../utils/token-counter';
|
||||
import { loadCustomInstructions } from '../utils/custom-instructions';
|
||||
|
||||
export interface ChatEntry {
|
||||
type: 'user' | 'assistant' | 'tool_result';
|
||||
@@ -43,10 +44,16 @@ export class GrokAgent extends EventEmitter {
|
||||
this.confirmationTool = new ConfirmationTool();
|
||||
this.tokenCounter = createTokenCounter('grok-4-latest');
|
||||
|
||||
// Load custom instructions
|
||||
const customInstructions = loadCustomInstructions();
|
||||
const customInstructionsSection = customInstructions
|
||||
? `\n\nCUSTOM INSTRUCTIONS:\n${customInstructions}\n\nThe above custom instructions should be followed alongside the standard instructions below.`
|
||||
: '';
|
||||
|
||||
// Initialize with system message
|
||||
this.messages.push({
|
||||
role: 'system',
|
||||
content: `You are Grok CLI, an AI assistant that helps with file editing, coding tasks, and system operations.
|
||||
content: `You are Grok CLI, an AI assistant that helps with file editing, coding tasks, and system operations.${customInstructionsSection}
|
||||
|
||||
You have access to these tools:
|
||||
- view_file: View file contents or directory listings
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
export function loadCustomInstructions(workingDirectory: string = process.cwd()): string | null {
|
||||
try {
|
||||
const instructionsPath = path.join(workingDirectory, '.grok', 'GROK.md');
|
||||
|
||||
if (!fs.existsSync(instructionsPath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const customInstructions = fs.readFileSync(instructionsPath, 'utf-8');
|
||||
return customInstructions.trim();
|
||||
} catch (error) {
|
||||
console.warn('Failed to load custom instructions:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user