From 143f7d9143af0efc44ee809e493e3a94249aa806 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 15 Nov 2026 11:07:42 +0530 Subject: [PATCH] fix: derive slots with validate.Slots so {{ and }} are literal braces proto v0.7.3 lets templates write literal braces as {{ and }}, exactly as in Python's str.format. deriveSlots used its own \{(\w+)\} regexp, which reads "{{name}}" as slot "name"; validate then rejected the publish with "declared slots never used". Require proto v0.7.3 and derive slots with validate.Slots, the same rules the server validates against. --- cmd/promptctl/main.go | 19 ++++++------------- cmd/promptctl/main_test.go | 5 +++++ go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/cmd/promptctl/main.go b/cmd/promptctl/main.go index c7a3e64..e635708 100644 --- a/cmd/promptctl/main.go +++ b/cmd/promptctl/main.go @@ -22,7 +22,6 @@ import ( "log" "os" "path/filepath" - "regexp" "slices" "sort" "strings" @@ -530,21 +529,15 @@ func reportSync(verb string, err error) { // --- prompt files ---------------------------------------------------------- -var slotRe = regexp.MustCompile(`\{(\w+)\}`) - -// deriveSlots reads declared slots straight from the template's {placeholders}. +// deriveSlots reads declared slots straight from the template's {placeholders}, +// with the same rules the server validates against: {{ and }} are literal +// braces, so "{{name}}" is text, not a slot. A malformed template yields no +// slots; validate.Prompt then reports the actual brace error. // ponytail: derived, so the slot set always matches — add front-matter slot // declarations if you want to catch typos against an intended set. func deriveSlots(template string) []string { - seen := map[string]bool{} - var out []string - for _, m := range slotRe.FindAllStringSubmatch(template, -1) { - if !seen[m[1]] { - seen[m[1]] = true - out = append(out, m[1]) - } - } - return out + slots, _ := validate.Slots(template) + return slots } // pathToURI maps a repo-relative prompt path to its priompt:// URI. diff --git a/cmd/promptctl/main_test.go b/cmd/promptctl/main_test.go index f8fda00..3261adf 100644 --- a/cmd/promptctl/main_test.go +++ b/cmd/promptctl/main_test.go @@ -20,4 +20,9 @@ func TestDeriveSlots(t *testing.T) { if s := deriveSlots("no slots here"); len(s) != 0 { t.Errorf("deriveSlots on plain text = %v, want empty", s) } + // {{ and }} are literal braces (str.format), so a JSON example is not a slot. + got = deriveSlots(`Answer {question}. Reply as JSON: {{"answer": "{{name}}"}}`) + if want := []string{"question"}; !reflect.DeepEqual(got, want) { + t.Errorf("deriveSlots with escaped braces = %v, want %v", got, want) + } } diff --git a/go.mod b/go.mod index f03c072..0a1816c 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/kevinburke/ssh_config v1.2.0 // indirect github.com/klauspost/cpuid/v2 v2.3.0 // indirect github.com/pjbgf/sha1cd v0.6.0 // indirect - github.com/priompt/proto v0.7.1 + github.com/priompt/proto v0.7.3 github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect github.com/skeema/knownhosts v1.3.1 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect diff --git a/go.sum b/go.sum index 89f0c25..5d2082f 100644 --- a/go.sum +++ b/go.sum @@ -65,8 +65,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/priompt/proto v0.7.1 h1:RdoEcJ8pi5RZMrs11UJhGGoP8jmnZq8h59WmO7YbnpY= -github.com/priompt/proto v0.7.1/go.mod h1:vwz0jk/O+rIf7LYwd20dtLzBtLvnKIbYsL9SFMf6gaY= +github.com/priompt/proto v0.7.3 h1:9/L3Gkciv8qJcnVB1+DkAPLoZnkdh/6ITJs/S8p/SbM= +github.com/priompt/proto v0.7.3/go.mod h1:vwz0jk/O+rIf7LYwd20dtLzBtLvnKIbYsL9SFMf6gaY= github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=