Separate glossary context from prompt protection

This commit is contained in:
2026-11-10 20:18:47 +00:00
parent a8eb5aea4d
commit 45e5b381f5
10 changed files with 46 additions and 16 deletions

View File

@@ -2,6 +2,7 @@ package proposal_generation
import (
"context"
"encoding/json"
"fmt"
"strings"
@@ -47,6 +48,16 @@ func ExecuteModuleProposal(ctx context.Context, req ModuleProposalRequest) (cont
return contracts.ProposalResult{}, err
}
protected := make([]string, 0, len(req.ProposalRequest.ProtectedTerms))
for _, term := range req.ProposalRequest.ProtectedTerms {
protected = append(protected, term.Spelling)
}
payload, err := json.Marshal(protected)
if err != nil {
return contracts.ProposalResult{}, fmt.Errorf("marshal protected spellings: %w", err)
}
variables["ProtectedTermsJSON"] = string(payload)
promptMetadata, ok := prompts.LookupMetadata(req.PromptID)
if !ok {
return contracts.ProposalResult{}, fmt.Errorf("unknown prompt ID %q", req.PromptID)

View File

@@ -40,6 +40,7 @@ func TestExecuteModuleProposalBuildsMessagesFromSectionAndDescription(t *testing
Settings: cfg,
WorkingTranscript: transcript,
Glossary: glossary,
ProtectedTerms: []domain.Term{{Spelling: "Separate protection"}},
Section: &section,
},
RunSpec: contracts.ModuleRunSpec{
@@ -76,6 +77,9 @@ func TestExecuteModuleProposalBuildsMessagesFromSectionAndDescription(t *testing
if len(client.calls) != 1 || client.calls[0].PromptID != prompts.PromptIDModuleGrammarProposal || client.calls[0].Context.SectionIndex == nil || *client.calls[0].Context.SectionIndex != 7 {
t.Fatalf("unexpected stage name calls: %+v", client.calls)
}
if got := client.calls[0].Variables["ProtectedTermsJSON"]; got != `["Separate protection"]` {
t.Fatalf("protected spellings = %s", got)
}
if len(out.Proposals) != 1 || out.Proposals[0].CorrectedText != "the" {
t.Fatalf("unexpected proposals: %+v", out)
}