81 lines
2.1 KiB
Go
81 lines
2.1 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
|
|
|
|
//go:embed session_9p.md
|
|
var Session9P string
|
|
|
|
//go:embed session_dbus.md
|
|
var SessionDBus string
|
|
|
|
//go:embed SYSTEM_PROMPT_QWEN.md
|
|
var QwenSystemPrompt 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 reads from overridePath if non-empty, otherwise returns
|
|
// the embedded default. If overridePath is a known key ("qwen", "devstral"),
|
|
// the corresponding embedded prompt is returned instead.
|
|
func ResolveSystemPrompt(overridePath string) string {
|
|
switch overridePath {
|
|
case "qwen":
|
|
return QwenSystemPrompt
|
|
}
|
|
if overridePath != "" {
|
|
data, err := os.ReadFile(overridePath)
|
|
if err == nil {
|
|
return strings.TrimRight(string(data), "\n")
|
|
}
|
|
// Fall through to embedded default if file can't be read.
|
|
fmt.Fprintf(os.Stderr, "system_prompt override %q: %v (using default)\n", overridePath, err)
|
|
}
|
|
return DefaultSystemPrompt
|
|
}
|