scenario.go
1162 bytes
1// Package scenario loads the plain-text brief that opens the game-loop LLM
2// context. A scenario file is one to three sentences describing place, time,
3// and vibe; the model invents everything else on the fly. The file name (base
4// without extension) is the scenario name.
5package scenario
6
7import (
8 "fmt"
9 "os"
10 "path/filepath"
11 "strings"
12)
13
14// Scenario is one brief: a display name plus the text that opens the
15// game-loop system prompt.
16type Scenario struct {
17 Name string
18 Brief string
19}
20
21// Load reads and validates a scenario from path. Name is the file's base name
22// without extension; Brief is the trimmed file content. Both must be non-empty.
23func Load(path string) (Scenario, error) {
24 data, err := os.ReadFile(path)
25 if err != nil {
26 return Scenario{}, fmt.Errorf("scenario: read %s: %w", path, err)
27 }
28 brief := strings.TrimSpace(string(data))
29 name := strings.TrimSuffix(filepath.Base(path), filepath.Ext(path))
30 if name == "" {
31 return Scenario{}, fmt.Errorf("scenario: name must not be empty")
32 }
33 if brief == "" {
34 return Scenario{}, fmt.Errorf("scenario: brief must not be empty")
35 }
36 return Scenario{Name: name, Brief: brief}, nil
37}