on main help sign in
fix(template): for coder so we handle memory files correctly
commitabb654e0c774fcff6bccd5926322625e7a4e17a9 authorkujtimiihoxha <kujtimii.h@gmail.com> dateWed 8 Oct 2025, 13:01 (1 year ago) parentb9249a3
3 files changed+30−24
internal/agent/prompt/prompt.go+28−18 internal/agent/templates/coder.md.tpl+2−5 internal/app/app.go−1
internal/agent/prompt/prompt.go+28−18
@@ -23,13 +23,14 @@ type Prompt struct {
2323}
2424
2525type PromptDat struct {
26− Provider string
27− Model string
28− Config config.Config
29− WorkingDir string
30− IsGitRepo bool
31− Platform string
32− Date string
26+ Provider string
27+ Model string
28+ Config config.Config
29+ WorkingDir string
30+ IsGitRepo bool
31+ Platform string
32+ Date string
33+ ContextFiles []ContextFile
3334}
3435
3536type ContextFile struct {
@@ -70,7 +71,7 @@ func NewPrompt(name, promptTemplate string, opts ...Option) (*Prompt, error) {
7071}
7172
7273func (p *Prompt) Build(provider, model string, cfg config.Config) (string, error) {
73− t, err := template.New(p.name).Funcs(p.funcMap(cfg)).Parse(p.template)
74+ t, err := template.New(p.name).Parse(p.template)
7475 if err != nil {
7576 return "", fmt.Errorf("parsing template: %w", err)
7677 }
@@ -82,15 +83,6 @@ func (p *Prompt) Build(provider, model string, cfg config.Config) (string, error
8283 return sb.String(), nil
8384}
8485
85−func (p *Prompt) funcMap(cfg config.Config) template.FuncMap {
86− return template.FuncMap{
87− "contextFiles": func(path string) []ContextFile {
88− path = expandPath(path, cfg)
89− return processContextPath(path, cfg)
90− },
91− }
92−}
93−
9486func processFile(filePath string) *ContextFile {
9587 content, err := os.ReadFile(filePath)
9688 if err != nil {
@@ -155,7 +147,20 @@ func (p *Prompt) promptData(provider, model string, cfg config.Config) PromptDat
155147 if p.platform != "" {
156148 platform = p.platform
157149 }
158− return PromptDat{
150+
151+ files := map[string][]ContextFile{}
152+
153+ for _, pth := range cfg.Options.ContextPaths {
154+ expanded := expandPath(pth, cfg)
155+ pathKey := strings.ToLower(expanded)
156+ if _, ok := files[pathKey]; ok {
157+ continue
158+ }
159+ content := processContextPath(expanded, cfg)
160+ files[pathKey] = content
161+ }
162+
163+ data := PromptDat{
159164 Provider: provider,
160165 Model: model,
161166 Config: cfg,
@@ -164,6 +169,11 @@ func (p *Prompt) promptData(provider, model string, cfg config.Config) PromptDat
164169 Platform: platform,
165170 Date: p.now().Format("1/2/2006"),
166171 }
172+
173+ for _, contextFiles := range files {
174+ data.ContextFiles = append(data.ContextFiles, contextFiles...)
175+ }
176+ return data
167177}
168178
169179func isGitRepo(dir string) bool {
internal/agent/templates/coder.md.tpl+2−5
@@ -124,14 +124,11 @@ Tools that support it will also include useful diagnostics such as linting and t
124124- Take necessary actions to fix the issues.
125125- You should ignore diagnostics of files that you did not change or are not related or caused by your changes unless the user explicitly asks you to fix them.
126126</lsp>
127−{{end}}{{if gt (len .Config.Options.ContextPaths) 0}}
128−<memory>
129−{{range .Config.Options.ContextPaths}}
130−{{range contextFiles .}}
127+{{end}}{{if .ContextFiles}}
128+<memory>{{range .ContextFiles}}
131129<file path="{{.Path}}">
132130{{.Content}}
133131</file>
134132{{end}}
135−{{end}}
136133</memory>
137134{{end}}
internal/app/app.go−1
@@ -33,7 +33,6 @@ type App struct {
3333 History history.Service
3434 Permissions permission.Service
3535
36− // TODO: (kujtim) remove this when fully implemented
3736 AgentCoordinator agent.Coordinator
3837
3938 LSPClients *csync.Map[string, *lsp.Client]