// Package prompts provides embedded prompt templates for the layered preamble. package prompts import ( _ "embed" "fmt" "os" "strings" "time" ) //go:embed system_prompt.md var DefaultSystemPrompt string //go:embed session_9p.md var Session9P string //go:embed session_dbus.md var SessionDBus string // Environment renders the environment context block with live values. func Environment(cwd, platform string, isGitRepo bool, sandbox string) string { date := time.Now().Format("2006-01-02") gitStr := "false" if isGitRepo { gitStr = "true" } return fmt.Sprintf(`# Environment - Working directory: %s - Platform: %s - Current date: %s - Is git repo: %s - Sandbox: %s Tools run in a sandbox with restricted filesystem access. Unexpected permission denied errors are usually caused by sandbox restrictions. Use `+"`elevated: true`"+` to bypass.`, cwd, platform, date, gitStr, sandbox) } // OperationalModel returns the appropriate operational model text based on flags. func OperationalModel(enable9P, enableDBus bool, envVars map[string]string) string { expand := func(s string) string { return os.Expand(s, func(key string) string { if v, ok := envVars[key]; ok { return v } return os.Getenv(key) }) } var parts []string if enable9P { parts = append(parts, expand(Session9P)) } if enableDBus { parts = append(parts, expand(SessionDBus)) } return strings.Join(parts, "\n") } // ResolveSystemPrompt expands env vars in overridePath, then tries to read the // file from the filesystem. If the file doesn't exist, the embedded default is // returned. func ResolveSystemPrompt(overridePath string) string { if overridePath == "" { return DefaultSystemPrompt } expanded := os.Expand(overridePath, os.Getenv) data, err := os.ReadFile(expanded) if err == nil { return strings.TrimRight(string(data), "\n") } // Fall through to embedded default. fmt.Fprintf(os.Stderr, "system_prompt %q: %v (using default)\n", expanded, err) return DefaultSystemPrompt }