xonecas.io
6119
My

mysis / commit 120cdf3

feat: add system prompt file flag

xonecas2026-02-10 120cdf3940e3fb6b33cf3a16ccb1dd97ba0c570e parent 59b7e89

2 files changed

internal/cli/cli.go+45−0
@@ -5,6 +5,7 @@ import (
55 "context"
66 "fmt"
77 "os"
8+ "path/filepath"
89 "strings"
910 "sync"
1011 "time"
@@ -171,6 +172,17 @@ func Run(version string) error {
171172 return err
172173 }
173174
175+ // Load system prompt from markdown file if provided
176+ if flags.SystemFile != "" {
177+ systemPrompt, err := loadSystemPromptFromFile(flags.SystemFile)
178+ if err != nil {
179+ return err
180+ }
181+ if !historyHasSystemPrompt(history, systemPrompt) {
182+ history = prependSystemPrompt(history, systemPrompt)
183+ }
184+ }
185+
174186 // Print welcome message
175187 printWelcome(selectedProvider, selectedModel, len(tools), sessionInfo)
176188
@@ -392,3 +404,36 @@ func initializeProviders(cfg *config.Config, creds *config.Credentials) *provide
392404
393405 return registry
394406 }
407+
408+func loadSystemPromptFromFile(path string) (string, error) {
409+ ext := strings.ToLower(filepath.Ext(path))
410+ if ext != ".md" && ext != ".markdown" {
411+ return "", fmt.Errorf("system prompt file must be markdown (.md or .markdown): %s", path)
412+ }
413+
414+ data, err := os.ReadFile(path)
415+ if err != nil {
416+ return "", fmt.Errorf("read system prompt file: %w", err)
417+ }
418+
419+ content := strings.TrimSpace(string(data))
420+ if content == "" {
421+ return "", fmt.Errorf("system prompt file is empty: %s", path)
422+ }
423+
424+ return content, nil
425+}
426+
427+func historyHasSystemPrompt(history []provider.Message, content string) bool {
428+ for _, msg := range history {
429+ if msg.Role == "system" && msg.Content == content {
430+ return true
431+ }
432+ }
433+ return false
434+}
435+
436+func prependSystemPrompt(history []provider.Message, content string) []provider.Message {
437+ systemMsg := provider.Message{Role: "system", Content: content}
438+ return append([]provider.Message{systemMsg}, history...)
439+}
internal/cli/flags.go+4−0
@@ -20,6 +20,7 @@ type Flags struct {
2020 ListSessions bool
2121 DeleteSession string
2222 Autoplay string
23+ SystemFile string
2324 }
2425
2526 // ParseFlags parses command-line flags and returns the result.
@@ -44,6 +45,8 @@ func ParseFlags(version string) *Flags {
4445 flag.StringVar(&f.DeleteSession, "D", "", "Delete a session by name (shorthand)")
4546 flag.StringVar(&f.Autoplay, "autoplay", "", "Start autoplay immediately with given message")
4647 flag.StringVar(&f.Autoplay, "a", "", "Start autoplay immediately (shorthand)")
48+ flag.StringVar(&f.SystemFile, "file", "", "Load system prompt from markdown file")
49+ flag.StringVar(&f.SystemFile, "f", "", "Load system prompt from markdown file (shorthand)")
4750
4851 flag.Usage = func() {
4952 printHelp(version)
@@ -95,6 +98,7 @@ func printHelp(version string) {
9598 fmt.Println(" " + styles.Secondary.Render("-p, --provider") + " NAME Provider name (overrides config default)")
9699 fmt.Println(" " + styles.Secondary.Render("-s, --session") + " NAME Session name (resume or create)")
97100 fmt.Println(" " + styles.Secondary.Render("-a, --autoplay") + " MSG Start autoplay immediately with message")
101+ fmt.Println(" " + styles.Secondary.Render("-f, --file") + " PATH Load system prompt from markdown file")
98102 fmt.Println(" " + styles.Secondary.Render("-l, --list-sessions") + " List recent sessions and exit")
99103 fmt.Println(" " + styles.Secondary.Render("-D, --delete-session") + " N Delete session by name and exit")
100104 fmt.Println()