Download this file
| 1 | package fakeclaude |
| 2 | |
| 3 | import ( |
| 4 | "regexp" |
| 5 | "strconv" |
| 6 | "strings" |
| 7 | ) |
| 8 | |
| 9 | // StepMarkerText decodes quoted prompt values for fake CLI fixture markers. Decode |
| 10 | // those values without stripping literal quotes from an edit's replacement. |
| 11 | func StepMarkerText(prompt string) string { |
| 12 | for range 4 { |
| 13 | lines := strings.Split(prompt, "\n") |
| 14 | changed := false |
| 15 | for i, line := range lines { |
| 16 | at := strings.IndexByte(line, '"') |
| 17 | if at < 0 { |
| 18 | continue |
| 19 | } |
| 20 | prefix := strings.TrimSpace(line[:at]) |
| 21 | if prefix != "" && prefix != "-" && !strings.HasSuffix(prefix, ":") { |
| 22 | continue |
| 23 | } |
| 24 | if value, err := strconv.Unquote(strings.TrimSpace(line[at:])); err == nil { |
| 25 | lines[i], changed = line[:at]+value, true |
| 26 | } |
| 27 | } |
| 28 | prompt = strings.Join(lines, "\n") |
| 29 | if !changed { |
| 30 | break |
| 31 | } |
| 32 | } |
| 33 | return prompt |
| 34 | } |
| 35 | |
| 36 | // DistinctStepMarkers runs one fixture directive once even when the prompt |
| 37 | // carries it in both the person's original words and the coordinator's brief. |
| 38 | func DistinctStepMarkers(pattern *regexp.Regexp, prompt string) [][]string { |
| 39 | seen := map[string]bool{} |
| 40 | var out [][]string |
| 41 | for _, match := range pattern.FindAllStringSubmatch(prompt, -1) { |
| 42 | if !seen[match[0]] { |
| 43 | out = append(out, match) |
| 44 | seen[match[0]] = true |
| 45 | } |
| 46 | } |
| 47 | return out |
| 48 | } |
| 49 | |