Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions cmd/promptctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"log"
"os"
"path/filepath"
"regexp"
"slices"
"sort"
"strings"
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions cmd/promptctl/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
Loading