10 // probeMessages is the length of the generated log for the live probe.
11 const probeMessages = 1000
14 probePeople = []string{"Mara", "Joel", "Ines", "Tomas", "Priya", "Lena"}
15 probeBreads = []string{"rye", "sourdough", "baguette", "brioche", "spelt", "seed loaf"}
16 probeDays = []string{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
17 probeThings = []string{"order form", "price list", "delivery route", "stock count", "invoice export", "oven schedule"}
18 probeProblems = []string{"shows the wrong total", "skips the last row", "is slow at noon", "loses the customer note", "rounds the tax down"}
19 probePlaces = []string{"the front page", "the weekly report", "the shared folder", "the admin menu"}
20 probeTasks = []string{"add a field for allergies", "send the invoices on Friday", "split the route in two", "print labels for the shelf"}
21 probeCauses = []string{"the date has no time zone", "the cache keeps old prices", "the loop stops one row early", "the form trims the note"}
22 probeChanges = []string{"the total to use cents", "the route to sort by street", "the export to add the tax line", "the form to keep the note"}
23 probePreferences = []string{"short answers", "a call before a change to prices", "invoices as PDF", "reports in the morning"}
24 probeFiles = []string{"orders/form.go", "prices/list.go", "routes/plan.go", "stock/count.go", "export/invoice.go", "ovens/schedule.go"}
25 probeModules = []string{"orders", "prices", "routes", "stock", "export", "ovens"}
28 // ProbeWriter writes readable made-up messages.
29 type ProbeWriter struct {
33 func (g *ProbeWriter) message() (string, string) {
34 roll := g.random.IntN(100)
37 return "user", g.fill(g.userLine, 10+g.random.IntN(200))
39 return "reply", g.fill(g.replyLine, 100+g.random.IntN(1500))
41 return "note", g.fill(g.noteLine, 50+g.random.IntN(600))
43 return "work", "[" + g.pick(probePeople) + "] report: " + g.fill(g.replyLine, 300+g.random.IntN(3000))
45 return "tool", g.toolCall(60 + g.random.IntN(400))
47 return "echo", g.fill(g.outputLine, 30000+g.random.IntN(30000))
49 return "echo", g.fill(g.outputLine, 20+g.random.IntN(4000))
53 // fill joins lines of write until the text has about size bytes.
54 func (g *ProbeWriter) fill(write func() string, size int) string {
55 var text strings.Builder
57 for text.Len() < size {
62 text.WriteString(write())
68 func (g *ProbeWriter) userLine() string {
69 return g.pick([]string{
70 fmt.Sprintf("Please check why the %s %s.", g.pick(probeThings), g.pick(probeProblems)),
71 fmt.Sprintf("Move the %s to %s before %s.", g.pick(probeThings), g.pick(probePlaces), g.pick(probeDays)),
72 fmt.Sprintf("Thanks, that works. Next, %s.", g.pick(probeTasks)),
73 fmt.Sprintf("No, keep the old %s. %s asked for it.", g.pick(probeThings), g.pick(probePeople)),
74 fmt.Sprintf("How many %s orders came in on %s?", g.pick(probeBreads), g.pick(probeDays)),
78 func (g *ProbeWriter) replyLine() string {
79 return g.pick([]string{
80 fmt.Sprintf("I looked at %s. The %s %s because %s.", g.pick(probeFiles), g.pick(probeThings), g.pick(probeProblems), g.pick(probeCauses)),
81 fmt.Sprintf("I changed %s, and the tests pass now.", g.pick(probeChanges)),
82 fmt.Sprintf("There were %d %s orders on %s, %d of them late.", 10+g.random.IntN(90), g.pick(probeBreads), g.pick(probeDays), g.random.IntN(10)),
83 fmt.Sprintf("Open question: should %s get %s?", g.pick(probePeople), g.pick(probeTasks)),
87 func (g *ProbeWriter) noteLine() string {
88 return g.pick([]string{
89 fmt.Sprintf("%s prefers %s.", g.pick(probePeople), g.pick(probePreferences)),
90 fmt.Sprintf("The bakery opens at %d and closes at %d on %s.", 5+g.random.IntN(3), 17+g.random.IntN(4), g.pick(probeDays)),
94 func (g *ProbeWriter) pick(words []string) string {
95 return words[g.random.IntN(len(words))]
98 // toolCall returns a tool name and its JSON input of about size bytes.
99 func (g *ProbeWriter) toolCall(size int) string {
100 name := g.pick([]string{"shell", "read", "write", "edit"})
102 var input map[string]string
106 input = map[string]string{"command": "grep -n '" + g.pick(probeThings) + "' " + g.pick(probeFiles)}
108 input = map[string]string{"path": g.pick(probeFiles)}
110 input = map[string]string{
111 "path": g.pick(probeFiles),
112 "text": g.fill(g.replyLine, max(0, size-80)),
116 data, err := json.Marshal(input)
121 return name + " " + string(data)
124 func (g *ProbeWriter) outputLine() string {
125 return g.pick([]string{
126 fmt.Sprintf("%02d:%02d order %d for %d %s, packed by %s.", 6+g.random.IntN(12), g.random.IntN(60), 1000+g.random.IntN(9000), 1+g.random.IntN(24), g.pick(probeBreads), g.pick(probePeople)),
127 fmt.Sprintf("%s:%d: %s %s.", g.pick(probeFiles), 1+g.random.IntN(400), g.pick(probeThings), g.pick(probeProblems)),
128 fmt.Sprintf("ok bakery/%s %d.%03ds", g.pick(probeModules), g.random.IntN(3), g.random.IntN(1000)),
132 // probeLog returns count messages of made-up work on a small bakery order
133 // system, with the mix of kinds and sizes of replayMessage. The same count
134 // always gives the same log.
135 func probeLog(count int) []DatedMessage {
137 random: rand.New(rand.NewPCG(7, 11)),
140 messages := make([]DatedMessage, count)
141 for id := range messages {
142 kind, text := g.message()
143 messages[id] = DatedMessage{