package promptcontext import ( "encoding/json" "fmt" "strings" "gitea.maximumdirect.net/eric/audita/v4/internal/core/glossary" ) // GlossaryVariables contains the glossary inputs shared by a stage's proposals. type GlossaryVariables struct { ContextJSON string ProtectionJSON string InstructionsBlock string } type GlossaryInstruction struct { Collection string Text string } func GlossaryInstructionsBlock(instructions []GlossaryInstruction) string { var blocks []string for _, instruction := range instructions { if instruction.Text != "" { blocks = append(blocks, instruction.Collection+":\n"+instruction.Text) } } return strings.Join(blocks, "\n\n") } func PrepareGlossaryVariables(entries []glossary.Entry, terms []glossary.Term) (GlossaryVariables, error) { contextJSON, err := json.MarshalIndent(entries, "", " ") if err != nil { return GlossaryVariables{}, fmt.Errorf("marshal glossary prompt context: %w", err) } protected := make([]string, 0, len(terms)) for _, term := range terms { if !term.Exempt { protected = append(protected, term.Spelling) } } protectionJSON, err := json.Marshal(protected) if err != nil { return GlossaryVariables{}, fmt.Errorf("marshal protected spellings: %w", err) } return GlossaryVariables{ContextJSON: string(contextJSON), ProtectionJSON: string(protectionJSON)}, nil }