From 1bd36ad629b6576ae71a893cd1f257209cd5661f Mon Sep 17 00:00:00 2001 From: Amolith Date: Mon, 15 Sep 2025 18:00:18 -0600 Subject: [PATCH] feat: load user CRUSH.md and AGENTS.md from config Issue: charmbracelet/crush#1050 --- README.md | 25 +++++++++++++++++++++++++ internal/config/config.go | 1 + internal/config/load.go | 9 +++++++++ schema.json | 11 +++++++++++ 4 files changed, 46 insertions(+) diff --git a/README.md b/README.md index f8028ed22b4e45080ac975282b29c8c11aa5cd97..0a759646556704ae0f9ac24042f76812f9044759 100644 --- a/README.md +++ b/README.md @@ -313,6 +313,31 @@ using `$(echo $VAR)` syntax. } ``` +### Memory files + +Crush automatically includes two files for cross-project instructions. + +- `~/.config/crush/CRUSH.md`: Crush-specific rules that would confuse other + agentic coding tools. If you only use Crush, this is the only one you need to + edit. +- `~/.config/AGENTS.md`: generic instructions that other coding tools might + read. Avoid referring to Crush-specific tools or workflows here. + +You can customize these paths using the `memory_paths` option in your +configuration: + +```jsonc +{ + "$schema": "https://charm.land/crush.json", + "options": { + "memory_paths": [ + "~/path/to/custom/memory/file.md", + "/full/path/to/folder/of/files/" // recursively load all .md files in folder + ] + } +} +``` + ### Ignoring Files Crush respects `.gitignore` files by default, but you can also create a diff --git a/internal/config/config.go b/internal/config/config.go index eb8394e11972de4c91017a4b92e59ccee804ef0c..8ab25c1732e69a00907b84dbf022279560733879 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -245,6 +245,7 @@ func (Attribution) JSONSchemaExtend(schema *jsonschema.Schema) { type Options struct { ContextPaths []string `json:"context_paths,omitempty" jsonschema:"description=Paths to files containing context information for the AI,example=.cursorrules,example=CRUSH.md"` + MemoryPaths []string `json:"memory_paths,omitempty" jsonschema:"description=Paths to files containing memory information for the AI,default=~/.config/crush/CRUSH.md,default=~/.config/AGENTS.md"` SkillsPaths []string `json:"skills_paths,omitempty" jsonschema:"description=Paths to directories containing Agent Skills (folders with SKILL.md files),example=~/.config/crush/skills,example=./skills"` TUI *TUIOptions `json:"tui,omitempty" jsonschema:"description=Terminal user interface options"` Debug bool `json:"debug,omitempty" jsonschema:"description=Enable debug logging,default=false"` diff --git a/internal/config/load.go b/internal/config/load.go index 25139cb5f4b2ba8013525bfde025f04cb267d1b8..bebc986e5e02fac8e43405226d46cd0f5e09880e 100644 --- a/internal/config/load.go +++ b/internal/config/load.go @@ -340,6 +340,14 @@ func (c *Config) setDefaults(workingDir, dataDir string) { if c.Options.ContextPaths == nil { c.Options.ContextPaths = []string{} } + if c.Options.MemoryPaths == nil { + crushConfigDir := filepath.Dir(GlobalConfig()) + c.Options.MemoryPaths = []string{ + filepath.Join(crushConfigDir, "CRUSH.md"), + filepath.Join(filepath.Dir(crushConfigDir), "AGENTS.md"), + } + } + c.Options.ContextPaths = append(c.Options.ContextPaths, c.Options.MemoryPaths...) if c.Options.SkillsPaths == nil { c.Options.SkillsPaths = []string{} } @@ -373,6 +381,7 @@ func (c *Config) setDefaults(workingDir, dataDir string) { // Add the default context paths if they are not already present c.Options.ContextPaths = append(defaultContextPaths, c.Options.ContextPaths...) + slices.Sort(c.Options.ContextPaths) c.Options.ContextPaths = slices.Compact(c.Options.ContextPaths) diff --git a/schema.json b/schema.json index 6eeaa40c1865ebb5e46f70964f4eba69cf47013e..9f43a7b05ec6469f82184011d8d79bbca8890f03 100644 --- a/schema.json +++ b/schema.json @@ -357,6 +357,17 @@ "type": "array", "description": "Paths to files containing context information for the AI" }, + "memory_paths": { + "items": { + "type": "string" + }, + "type": "array", + "description": "Paths to files containing memory information for the AI", + "default": [ + "~/.config/crush/CRUSH.md", + "~/.config/AGENTS.md" + ] + }, "skills_paths": { "items": { "type": "string",