Skip to content

Commit ad177ec

Browse files
will-osbornejszczypkbenfaerberjcheekhomanp
authored
Support global custom instructions from ~/.grok/GROK.md (#101)
* feat: add support for global custom instructions * Remove comments * Fix import syntax for fs-extra module (#112) * Fix import syntax for fs-extra module * Fix import syntax for fs-extra module * Fix import syntax for fs-extra module * Fix missing newline at end of morph-editor.ts * Add where to set the API key in the json file (#107) * Fix diff generation showing entire file as changed (fixes #83) (#98) The diff preview was showing the entire file as changed when only a few lines were actually modified. This was caused by a broken change detection algorithm that couldn't properly handle insertions and deletions. Replaced the naive line-matching algorithm with a proper LCS (Longest Common Subsequence) based diff algorithm using dynamic programming. This produces minimal, accurate diffs that match what git diff shows. Changes: - Added computeLCS(): Computes longest common subsequence between old/new lines - Added extractChanges(): Extracts actual change regions from LCS table - Updated generateDiff(): Uses LCS-based change detection instead of broken algorithm Impact: - Diff previews now show only actual changes (e.g., 4 lines instead of 260) - Drastically reduces context pollution in conversation history - Matches git diff output accuracy 🤖 Contributed by ZDS-AI (https://zds.group) * add model migration manager and new grok models (#124) * minor tweaks --------- Co-authored-by: jszczypk <janusz@fide.pl> Co-authored-by: Ben Faerber <benfaerber@protonmail.com> Co-authored-by: Joseph Cheek <jcheek@users.noreply.github.com> Co-authored-by: Ismail Pelaseyed <homanp@gmail.com>
1 parent 9d11b16 commit ad177ec

File tree

3 files changed

+50
-12
lines changed

3 files changed

+50
-12
lines changed

README.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,19 @@ Options:
296296

297297
### Custom Instructions
298298

299-
You can provide custom instructions to tailor Grok's behavior to your project by creating a `.grok/GROK.md` file in your project directory:
299+
You can provide custom instructions to tailor Grok's behavior to your project or globally. Grok CLI supports both project-level and global custom instructions.
300+
301+
#### Project-Level Instructions
302+
303+
Create a `.grok/GROK.md` file in your project directory to provide instructions specific to that project:
300304

301305
```bash
302306
mkdir .grok
303307
```
304308

305-
Create `.grok/GROK.md` with your custom instructions:
309+
Create `.grok/GROK.md` with your project-specific instructions:
306310
```markdown
307-
# Custom Instructions for Grok CLI
311+
# Custom Instructions for This Project
308312

309313
Always use TypeScript for any new code files.
310314
When creating React components, use functional components with hooks.
@@ -313,7 +317,33 @@ Always add JSDoc comments for public functions and interfaces.
313317
Follow the existing code style and patterns in this project.
314318
```
315319

316-
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.
320+
#### Global Instructions
321+
322+
For instructions that apply across all projects, create `~/.grok/GROK.md` in your home directory:
323+
324+
```bash
325+
mkdir -p ~/.grok
326+
```
327+
328+
Create `~/.grok/GROK.md` with your global instructions:
329+
```markdown
330+
# Global Custom Instructions for Grok CLI
331+
332+
Always prioritize code readability and maintainability.
333+
Use descriptive variable names and add comments for complex logic.
334+
Follow best practices for the programming language being used.
335+
When suggesting code changes, consider performance implications.
336+
```
337+
338+
#### Priority Order
339+
340+
Grok will load custom instructions in the following priority order:
341+
1. **Project-level** (`.grok/GROK.md` in current directory) - takes highest priority
342+
2. **Global** (`~/.grok/GROK.md` in home directory) - fallback if no project instructions exist
343+
344+
If both files exist, project instructions will be used. If neither exists, Grok operates with its default behavior.
345+
346+
The custom instructions are added to Grok's system prompt and influence its responses across all interactions in the respective context.
317347

318348
## Morph Fast Apply (Optional)
319349

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vibe-kit/grok-cli",
3-
"version": "0.0.33",
3+
"version": "0.0.34",
44
"description": "An open-source AI agent that brings the power of Grok directly into your terminal.",
55
"type": "module",
66
"main": "dist/index.js",

src/utils/custom-instructions.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
3+
import * as os from 'os';
34

45
export function loadCustomInstructions(workingDirectory: string = process.cwd()): string | null {
56
try {
6-
const instructionsPath = path.join(workingDirectory, '.grok', 'GROK.md');
7+
let instructionsPath = path.join(workingDirectory, '.grok', 'GROK.md');
78

8-
if (!fs.existsSync(instructionsPath)) {
9-
return null;
9+
if (fs.existsSync(instructionsPath)) {
10+
const customInstructions = fs.readFileSync(instructionsPath, 'utf-8');
11+
return customInstructions.trim();
1012
}
11-
12-
const customInstructions = fs.readFileSync(instructionsPath, 'utf-8');
13-
return customInstructions.trim();
13+
14+
instructionsPath = path.join(os.homedir(), '.grok', 'GROK.md');
15+
16+
if (fs.existsSync(instructionsPath)) {
17+
const customInstructions = fs.readFileSync(instructionsPath, 'utf-8');
18+
return customInstructions.trim();
19+
}
20+
21+
return null;
1422
} catch (error) {
1523
console.warn('Failed to load custom instructions:', error);
1624
return null;
1725
}
18-
}
26+
}

0 commit comments

Comments
 (0)