MCPcopy Create free account
hub / github.com/github/gh-aw / buildCacheMemoryPromptSection

Function buildCacheMemoryPromptSection

pkg/workflow/cache.go:785–904  ·  view source on GitHub ↗

buildCacheMemoryPromptSection builds a PromptSection for cache memory instructions Returns a PromptSection that references a template file with substitutions, or nil if no cache is configured

(config *CacheMemoryConfig)

Source from the content-addressed store, hash-verified

783// buildCacheMemoryPromptSection builds a PromptSection for cache memory instructions
784// Returns a PromptSection that references a template file with substitutions, or nil if no cache is configured
785func buildCacheMemoryPromptSection(config *CacheMemoryConfig) *PromptSection {
786 if config == nil || len(config.Caches) == 0 {
787 return nil
788 }
789
790 // Check if there's only one cache with ID "default" to use singular template
791 if len(config.Caches) == 1 && config.Caches[0].ID == "default" {
792 cache := config.Caches[0]
793 // Trailing slash makes the path look like a directory in prompt context.
794 cacheDir := cacheMemoryDirFor(cache.ID) + "/"
795
796 // Build description text
797 descriptionText := ""
798 if cache.Description != "" {
799 descriptionText = cache.Description
800 }
801
802 // Build allowed extensions text.
803 // When non-empty, add a compact plain-text restriction line.
804 // When empty (all extensions allowed), the placeholder is replaced with nothing.
805 var allowedExtsText string
806 if len(cache.AllowedExtensions) > 0 {
807 allowedExtsText = "\nAllowed file extensions: " + strings.Join(cache.AllowedExtensions, ", ") + "."
808 }
809
810 cacheLog.Printf("Building cache memory prompt section with env vars: cache_dir=%s, description=%s, allowed_extensions=%v", cacheDir, descriptionText, cache.AllowedExtensions)
811
812 // Return prompt section with template file and environment variables for substitution
813 return &PromptSection{
814 Content: cacheMemoryPromptFile,
815 IsFile: true,
816 EnvVars: map[string]string{
817 "GH_AW_CACHE_DIR": cacheDir,
818 "GH_AW_CACHE_DESCRIPTION": descriptionText,
819 "GH_AW_ALLOWED_EXTENSIONS": allowedExtsText,
820 },
821 }
822 }
823
824 // Multiple caches or non-default single cache - use template file with substitutions
825 cacheLog.Print("Building cache memory prompt section for multiple caches using template")
826
827 // Build cache list
828 var cacheList strings.Builder
829 for _, cache := range config.Caches {
830 // Trailing slash makes the path look like a directory in prompt context.
831 cacheDir := cacheMemoryDirFor(cache.ID) + "/"
832 if cache.Description != "" {
833 fmt.Fprintf(&cacheList, "- **%s**: `%s` - %s\n", cache.ID, cacheDir, cache.Description)
834 } else {
835 fmt.Fprintf(&cacheList, "- **%s**: `%s`\n", cache.ID, cacheDir)
836 }
837 }
838
839 // Build allowed extensions text.
840 // Compute the union of all allowed extensions across all caches.
841 // When non-empty, add a compact plain-text restriction line.
842 // When empty (all extensions allowed for all caches), the placeholder is replaced with nothing.

Calls 4

cacheMemoryDirForFunction · 0.85
PrintMethod · 0.80
PrintfMethod · 0.45
StringMethod · 0.45