Migrate item occurrences to native correction while preserving holder semantics

This commit is contained in:
2026-11-22 01:08:02 +00:00
parent 2c1d727232
commit 1fe231b6fb
14 changed files with 519 additions and 486 deletions

View File

@@ -0,0 +1,7 @@
Revise the previous item occurrence list using these findings:
{{ input "guidance" }}
Return the complete replacement list using the original transcript and registry
context. Preserve stated quantities and possession changes without inventing an
item or holder. Return only JSON matching the original response contract.

View File

@@ -20,7 +20,7 @@ prompts:
messages:
- role: system
content_file: ../../shared/prompts/common-dnd-system.md
- role: user
- role: system
content_file: ../../shared/prompts/common-dnd-identity.md
- role: user
content_file: ../../shared/prompts/common-dnd-references.md
@@ -30,11 +30,11 @@ prompts:
content_file: ../../shared/prompts/common-dnd-transcript-chunk.md
cache_control:
type: ephemeral
- role: user
- role: system
content_file: ../../shared/prompts/common-dnd-extraction-evidence.md
- role: user
content_file: ./item-registry.md
- role: user
- role: system
content_file: ./instructions.md
cache_control:
type: ephemeral
@@ -42,3 +42,17 @@ prompts:
format: json
validation_mode: json_schema
schema_path: dnd/item-occurrences/schemas/dnd_item_occurrences_llm.v1.json
- id: dnd.item_occurrences.repair
default_profile: notarius/dnd-extraction
inputs:
- name: guidance
required: true
content_type: text/plain
messages:
- role: user
content_file: ./correction.md
output:
format: json
validation_mode: json_schema
schema_path: dnd/item-occurrences/schemas/dnd_item_occurrences_llm.v1.json

View File

@@ -0,0 +1,79 @@
package assets_test
import (
"encoding/json"
"io/fs"
"testing"
"gitea.maximumdirect.net/eric/notarius/assets"
)
func TestItemOccurrenceSchemaIsStrictlyStructuralAndPrivate(t *testing.T) {
schema, err := fs.ReadFile(assets.FS(), "dnd/item-occurrences/schemas/dnd_item_occurrences_llm.v1.json")
if err != nil {
t.Fatal(err)
}
valid := map[string]any{"occurrences": []any{
map[string]any{
"name": "", "kind": "transferred", "quantity": 0, "from": "party", "to": "Party",
"source_refs": []any{map[string]any{"start_unit_id": 0, "end_unit_id": -1}},
},
map[string]any{
"name": "Hidden Cache", "kind": "discovered", "quantity": nil, "from": nil, "to": nil,
"source_refs": []any{map[string]any{"start_unit_id": 1, "end_unit_id": 1}},
},
}}
content, err := json.Marshal(valid)
if err != nil {
t.Fatal(err)
}
if err := validateJSONSchema(content, schema); err != nil {
t.Fatalf("private schema rejected validator-owned values: %v", err)
}
for _, test := range []struct {
name string
value map[string]any
}{
{"missing occurrences", map[string]any{}},
{"missing occurrence name", map[string]any{"occurrences": []any{itemOccurrenceWithoutField(itemOccurrenceRecord(), "name")}}},
{"missing nullable field", map[string]any{"occurrences": []any{itemOccurrenceWithoutField(itemOccurrenceRecord(), "quantity")}}},
{"missing from", map[string]any{"occurrences": []any{itemOccurrenceWithoutField(itemOccurrenceRecord(), "from")}}},
{"missing to", map[string]any{"occurrences": []any{itemOccurrenceWithoutField(itemOccurrenceRecord(), "to")}}},
{"noninteger quantity", map[string]any{"occurrences": []any{itemOccurrenceWithField(itemOccurrenceRecord(), "quantity", 1.5)}}},
{"unsupported kind", map[string]any{"occurrences": []any{itemOccurrenceWithField(itemOccurrenceRecord(), "kind", "unsupported")}}},
{"opaque item identifier", map[string]any{"occurrences": []any{itemOccurrenceWithField(itemOccurrenceRecord(), "item_id", "item:sha256:opaque")}}},
{"unknown occurrence field", map[string]any{"occurrences": []any{itemOccurrenceWithField(itemOccurrenceRecord(), "extra", true)}}},
{"segment-named range", map[string]any{"occurrences": []any{itemOccurrenceWithField(itemOccurrenceRecord(), "source_refs", []any{map[string]any{"start_segment": 1, "end_segment": 1}})}}},
{"opaque source identifier", map[string]any{"occurrences": []any{itemOccurrenceWithField(itemOccurrenceRecord(), "source_refs", []any{map[string]any{"start_unit_id": 1, "end_unit_id": 1, "source_id": "session-alpha"}})}}},
{"unknown reference field", map[string]any{"occurrences": []any{itemOccurrenceWithField(itemOccurrenceRecord(), "source_refs", []any{map[string]any{"start_unit_id": 1, "end_unit_id": 1, "extra": true}})}}},
{"noninteger range", map[string]any{"occurrences": []any{itemOccurrenceWithField(itemOccurrenceRecord(), "source_refs", []any{map[string]any{"start_unit_id": 1.5, "end_unit_id": 1}})}}},
} {
t.Run(test.name, func(t *testing.T) {
content, err := json.Marshal(test.value)
if err != nil {
t.Fatal(err)
}
if err := validateJSONSchema(content, schema); err == nil {
t.Fatal("private schema accepted invalid structure")
}
})
}
}
func itemOccurrenceRecord() map[string]any {
return map[string]any{
"name": "Ring", "kind": "acquired", "quantity": nil, "from": nil, "to": "party", "source_refs": []any{},
}
}
func itemOccurrenceWithoutField(value map[string]any, name string) map[string]any {
delete(value, name)
return value
}
func itemOccurrenceWithField(value map[string]any, name string, fieldValue any) map[string]any {
value[name] = fieldValue
return value
}

View File

@@ -18,6 +18,15 @@ func TestOccurrencePromptPairsPreserveRegistryAndTranscriptBoundaries(t *testing
family, registry string
rules []string
}{
{"item", `{"items":[{"name":"occurrence-registry-name"}]}`, []string{
"Return both `from` and `to` for every occurrence.",
"| `discovered` | `null` | `null` |",
"| `acquired` | `null` | `party` or the named party member gaining possession |",
"| `lost` | `party` or the named party member losing possession | `null` |",
"| `consumed` | `party` or the named party member consuming the item | `null` |",
"| `transferred` | one named party member | a different named party member |",
"payments are always `lost`, not `consumed`.",
}},
{"npc", `{"npcs":[{"name":"occurrence-registry-name"}]}`, []string{"Use the supplied canonical NPC", "noncombat_presence", "combat_opponent"}},
{"location", `{"locations":[{"name":"occurrence-registry-name","registry_refs":[{"start_unit_id":7,"end_unit_id":7}],"context":[{"unit_id":7,"text":"registry-context"}]}]}`,
[]string{"context supports that coreference", "must not create a registry location", "provenance must never replace current-chunk evidence", "complete ordered"}},