From c40720e1cd76a29ae554657b8c1706abc4867e70 Mon Sep 17 00:00:00 2001 From: Amolith Date: Wed, 17 Sep 2025 20:11:15 -0600 Subject: [PATCH] feat(prompt): distinguish user/project context Separate user-defined memory paths from project-specific context paths. Previously, memory paths were appended to context paths. Now, they are passed distinctly to the prompt generator. The CoderPrompt now formats project context within tags and user memory within tags, each with a specific explanatory header for the LLM. This allows for clearer separation and potential prioritization by the model. Issue: charmbracelet/crush#1050 --- internal/agent/prompt/prompt.go | 25 ++++++++++++++++++++----- internal/agent/templates/coder.md.tpl | 18 ++++++++++++++++-- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/internal/agent/prompt/prompt.go b/internal/agent/prompt/prompt.go index d68c7c132116c49cd004bee52169be7487133efa..ee7f8095b45dff241636b9d66d0e759289384ee5 100644 --- a/internal/agent/prompt/prompt.go +++ b/internal/agent/prompt/prompt.go @@ -36,6 +36,7 @@ type PromptDat struct { Date string GitStatus string ContextFiles []ContextFile + MemoryFiles []ContextFile AvailSkillXML string } @@ -152,16 +153,27 @@ func (p *Prompt) promptData(ctx context.Context, provider, model string, cfg con workingDir := cmp.Or(p.workingDir, cfg.WorkingDir()) platform := cmp.Or(p.platform, runtime.GOOS) - files := map[string][]ContextFile{} + contextFiles := map[string][]ContextFile{} + memoryFiles := map[string][]ContextFile{} for _, pth := range cfg.Options.ContextPaths { expanded := expandPath(pth, cfg) pathKey := strings.ToLower(expanded) - if _, ok := files[pathKey]; ok { + if _, ok := contextFiles[pathKey]; ok { continue } content := processContextPath(expanded, cfg) - files[pathKey] = content + contextFiles[pathKey] = content + } + + for _, pth := range cfg.Options.MemoryPaths { + expanded := expandPath(pth, cfg) + pathKey := strings.ToLower(expanded) + if _, ok := memoryFiles[pathKey]; ok { + continue + } + content := processContextPath(expanded, cfg) + memoryFiles[pathKey] = content } // Discover and load skills metadata. @@ -195,8 +207,11 @@ func (p *Prompt) promptData(ctx context.Context, provider, model string, cfg con } } - for _, contextFiles := range files { - data.ContextFiles = append(data.ContextFiles, contextFiles...) + for _, files := range contextFiles { + data.ContextFiles = append(data.ContextFiles, files...) + } + for _, files := range memoryFiles { + data.MemoryFiles = append(data.MemoryFiles, files...) } return data, nil } diff --git a/internal/agent/templates/coder.md.tpl b/internal/agent/templates/coder.md.tpl index e0bbe34b92003a691a158a40d330db55b4b9c9b8..b6177ba30804463dfb5b44391ec21efb2f4b3437 100644 --- a/internal/agent/templates/coder.md.tpl +++ b/internal/agent/templates/coder.md.tpl @@ -382,11 +382,25 @@ If a skill mentions scripts, references, or assets, they are placed in the same {{end}} {{if .ContextFiles}} - +# Project-Specific Context +Make sure to follow the instructions in the context below. + {{range .ContextFiles}} {{.Content}} {{end}} - + +{{end}} + +{{if .MemoryFiles}} +# User context +The following is personal content added by the user that they'd like you to follow no matter what project you're working in. + +{{range .MemoryFiles}} + +{{.Content}} + +{{end}} + {{end}}