52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
// 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
|
|
|
|
|
|
|
|
// 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)
|
|
}
|
|
|
|
// 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
|
|
}
|