Add D&D spells prompt assets

This commit is contained in:
2026-07-03 23:34:10 +00:00
parent 382ca3fb6c
commit 404bfc8da5
7 changed files with 368 additions and 20 deletions

View File

@@ -0,0 +1,9 @@
You extract D&D spell-cast artifacts from source units.
{{ hardening }}
Extract only spell casts that are supported by the provided source text. Do not
infer spells from general D&D knowledge or from table chatter that does not
identify a spell being cast.
Source references must use the source-unit IDs exactly as provided.

View File

@@ -0,0 +1,21 @@
Source document ID: {{ .SourceID }}
{{ if .HasChunk }}
Chunk ID: {{ .ChunkID }}
Chunk index: {{ .ChunkIndex }}
{{ end }}
Source units:
{{ range .Units }}
- Unit ID: {{ .ID }}
Text: {{ .Text }}
{{ if .Metadata }}
Metadata:
{{ range .Metadata }}
- {{ .Key }}: {{ .Value }}
{{ end }}
{{ end }}
{{ end }}
Return only D&D spell-cast artifacts. For each spell cast, identify the in-world
caster, spell name, effect, narrative description, and source references using
source_id, start_unit_id, and end_unit_id.

View File

@@ -17,6 +17,7 @@ var embeddedAssets embed.FS
const (
SourceBuiltin = "builtin"
VersionV1 = "v1"
DNDSpellsPromptID = "dnd.spells"
TestGenericPromptID = "test.generic"
)
@@ -65,6 +66,13 @@ func init() {
}
defs := []definition{
{
id: DNDSpellsPromptID,
version: VersionV1,
embeddedDir: "assets/dnd/spells",
systemPath: "assets/dnd/spells/system.md",
userPath: "assets/dnd/spells/user.md",
},
{
id: TestGenericPromptID,
version: VersionV1,

View File

@@ -6,26 +6,38 @@ import (
"testing"
)
func TestLookupMetadataSucceedsForGenericPrompt(t *testing.T) {
metadata, ok := LookupMetadata(TestGenericPromptID)
if !ok {
t.Fatalf("expected metadata for %q", TestGenericPromptID)
func TestLookupMetadataSucceedsForRegisteredPrompts(t *testing.T) {
tests := []struct {
promptID string
embeddedPath string
}{
{promptID: DNDSpellsPromptID, embeddedPath: "assets/dnd/spells"},
{promptID: TestGenericPromptID, embeddedPath: "assets/test/generic"},
}
if metadata.PromptID != TestGenericPromptID {
t.Fatalf("unexpected prompt ID: %q", metadata.PromptID)
}
if metadata.PromptVersion != VersionV1 {
t.Fatalf("unexpected prompt version: %q", metadata.PromptVersion)
}
if metadata.PromptSource != SourceBuiltin {
t.Fatalf("unexpected prompt source: %q", metadata.PromptSource)
}
if metadata.EmbeddedPath != "assets/test/generic" {
t.Fatalf("unexpected embedded path: %q", metadata.EmbeddedPath)
}
if !strings.HasPrefix(metadata.SHA256, "sha256:") {
t.Fatalf("expected prefixed hash, got %q", metadata.SHA256)
for _, tc := range tests {
t.Run(tc.promptID, func(t *testing.T) {
metadata, ok := LookupMetadata(tc.promptID)
if !ok {
t.Fatalf("expected metadata for %q", tc.promptID)
}
if metadata.PromptID != tc.promptID {
t.Fatalf("unexpected prompt ID: %q", metadata.PromptID)
}
if metadata.PromptVersion != VersionV1 {
t.Fatalf("unexpected prompt version: %q", metadata.PromptVersion)
}
if metadata.PromptSource != SourceBuiltin {
t.Fatalf("unexpected prompt source: %q", metadata.PromptSource)
}
if metadata.EmbeddedPath != tc.embeddedPath {
t.Fatalf("unexpected embedded path: %q", metadata.EmbeddedPath)
}
if !strings.HasPrefix(metadata.SHA256, "sha256:") {
t.Fatalf("expected prefixed hash, got %q", metadata.SHA256)
}
})
}
}
@@ -47,17 +59,22 @@ func TestMustLookupMetadataPanicsForUnknownPromptID(t *testing.T) {
func TestRegisteredMetadataSortedByPromptID(t *testing.T) {
registered := RegisteredMetadata()
if len(registered) != 1 {
t.Fatalf("expected one registered prompt, got %d", len(registered))
if len(registered) != 2 {
t.Fatalf("expected two registered prompts, got %d", len(registered))
}
ids := make([]string, len(registered))
seen := make(map[string]bool, len(registered))
for i, metadata := range registered {
ids[i] = metadata.PromptID
seen[metadata.PromptID] = true
}
if !sort.StringsAreSorted(ids) {
t.Fatalf("expected sorted prompt IDs, got %v", ids)
}
if !seen[DNDSpellsPromptID] {
t.Fatalf("registered prompt IDs = %v, want %q", ids, DNDSpellsPromptID)
}
}
func TestHardeningTextAvailable(t *testing.T) {

View File

@@ -64,3 +64,47 @@ func TestRenderUserSystemIncludesHardeningText(t *testing.T) {
t.Fatalf("expected rendered system prompt to include hardening text: %q", system)
}
}
func TestRenderDNDSpellsPromptIncludesHardeningText(t *testing.T) {
system, user, metadata, err := RenderUserSystem(DNDSpellsPromptID, map[string]any{
"SourceID": "session-alpha",
"HasChunk": true,
"ChunkID": "session-alpha:chunk:0",
"ChunkIndex": 0,
"Units": []map[string]any{
{
"ID": "seg-001",
"Text": "Aria casts Cure Wounds.",
"Metadata": []map[string]string{
{"Key": "speaker", "Value": "Alice"},
},
},
},
})
if err != nil {
t.Fatalf("RenderUserSystem: %v", err)
}
hardening := strings.TrimSpace(HardeningText())
if hardening == "" {
t.Fatalf("expected hardening text")
}
if !strings.Contains(system, hardening) {
t.Fatalf("expected rendered system prompt to include hardening text: %q", system)
}
for _, want := range []string{"session-alpha", "session-alpha:chunk:0", "seg-001", "Aria casts Cure Wounds.", "speaker: Alice"} {
if !strings.Contains(user, want) {
t.Fatalf("rendered user prompt = %q, want substring %q", user, want)
}
}
if metadata.PromptID != DNDSpellsPromptID {
t.Fatalf("unexpected metadata: %+v", metadata)
}
}
func TestRenderDNDSpellsPromptMissingTemplateDataReturnsError(t *testing.T) {
_, _, _, err := RenderUserSystem(DNDSpellsPromptID, map[string]any{})
if err == nil || !strings.Contains(err.Error(), "SourceID") {
t.Fatalf("expected missing SourceID error, got %v", err)
}
}