Branchwell

Glimmer / app · glimmertoday.ai / native / Glimmer / CoachPrompts.swift

1import Foundation
2
3/// The suggested questions on Coach's welcome screen. Coach shows three, each from a different category,
4/// and never repeats one from the set shown last time. Add prompts here; keep them short, warm and in the
5/// person's own voice.
6struct CoachPrompt: Hashable, Sendable {
7 enum Category: String, CaseIterable, Sendable {
8 case reflect, practice, read, focus, rest, stillness, kindness
9
10 /// Practice topics the rule-based guide prefers for this kind of question.
11 var topics: Set<String> {
12 switch self {
13 case .reflect: ["everyday_reflection"]
14 case .practice: []
15 case .read: ["learn_build"]
16 case .focus: ["protect_attention", "everyday_agency"]
17 case .rest: ["rest"]
18 case .stillness: ["stillness_spirit"]
19 case .kindness: ["rest", "everyday_reflection", "work_growth"]
20 }
21 }
22
23 /// Words in a typed question that point to this category, checked in `CoachPrompts.category(for:)`.
24 var keywords: Set<String> {
25 switch self {
26 case .reflect: ["week", "logged", "moments", "pattern", "patterns", "noticed", "notice", "stood", "reflect", "looking"]
27 case .practice: ["practice", "habit", "exercise", "small", "try", "something"]
28 case .read: ["read", "reading", "lesson", "learn", "learning", "study", "book"]
29 case .focus: ["focus", "plan", "planning", "priority", "priorities", "distracted", "scattered", "start", "first", "task", "tasks", "today's"]
30 case .rest: ["tired", "energy", "rest", "drained", "sleep", "exhausted", "break", "recharge", "restore", "worn"]
31 case .stillness: ["still", "stillness", "quiet", "silence", "pray", "prayer", "spirit", "spiritual", "meditate", "grateful", "gratitude", "peace", "calm", "sacred", "slow"]
32 case .kindness: ["stuck", "overwhelmed", "behind", "failing", "failed", "guilty", "guilt", "kind", "kinder", "myself", "shame", "messed", "hard", "harsh", "enough"]
33 }
34 }
35
36 /// The rule-based guide's opening line when no AI route is available.
37 var guideLead: String {
38 switch self {
39 case .reflect: "A pattern starts with one honest moment."
40 case .practice: "Here’s one small practice to try today. Keep it only if it helps."
41 case .read: "Here’s something to learn from today."
42 case .focus: "Pick the one thing that matters most today and give it your first clear half hour. This can help."
43 case .rest: "Rest counts as part of the work. Here’s a gentle way to choose it on purpose."
44 case .stillness: "A few quiet minutes are enough. Try this when you find a pause."
45 case .kindness: "Being stuck isn’t a verdict on you. Make the next step smaller, then try this."
46 }
47 }
48 }
49
50 let text: String
51 let category: Category
52}
53
54enum CoachPrompts {
55 /// The fixed set UI tests rely on, used whenever Glimmer runs against a test journal.
56 static let fixed = [
57 CoachPrompt(text: "What stood out this week?", category: .reflect),
58 CoachPrompt(text: "Help me choose one small practice", category: .practice),
59 CoachPrompt(text: "What should I read today?", category: .read),
60 ]
61
62 static let pool: [CoachPrompt] = [
63 // Reflection
64 .init(text: "What stood out this week?", category: .reflect),
65 .init(text: "What gave me energy lately?", category: .reflect),
66 .init(text: "What’s been draining me without my noticing?", category: .reflect),
67 .init(text: "What pattern do you see in my week?", category: .reflect),
68 .init(text: "What am I avoiding, and why?", category: .reflect),
69 .init(text: "What went better than I expected?", category: .reflect),
70 .init(text: "Help me look back on today", category: .reflect),
71 // Choosing a small practice
72 .init(text: "Help me choose one small practice", category: .practice),
73 .init(text: "Give me something small to try today", category: .practice),
74 .init(text: "What’s a five-minute practice for right now?", category: .practice),
75 .init(text: "Suggest a practice for a busy day", category: .practice),
76 .init(text: "What could I try instead of scrolling?", category: .practice),
77 .init(text: "Help me build one tiny habit", category: .practice),
78 .init(text: "What’s one small way to help someone today?", category: .practice),
79 // What to read or learn
80 .init(text: "What should I read today?", category: .read),
81 .init(text: "Give me one idea to think about today", category: .read),
82 .init(text: "What lesson fits where I am right now?", category: .read),
83 .init(text: "What’s worth learning this week?", category: .read),
84 .init(text: "Teach me something in five minutes", category: .read),
85 .init(text: "What should I study when my mind won’t settle?", category: .read),
86 .init(text: "Recommend something to read before bed", category: .read),
87 // Focus and planning today
88 .init(text: "Help me plan a gentle day", category: .focus),
89 .init(text: "What should I focus on first?", category: .focus),
90 .init(text: "My mind is scattered. Where do I start?", category: .focus),
91 .init(text: "Help me pick today’s one priority", category: .focus),
92 .init(text: "How do I start a task I keep putting off?", category: .focus),
93 .init(text: "Help me protect my focus this afternoon", category: .focus),
94 .init(text: "What can I let go of today?", category: .focus),
95 // Energy and rest
96 .init(text: "I’m tired. What would actually help?", category: .rest),
97 .init(text: "How can I rest without feeling guilty?", category: .rest),
98 .init(text: "What restores me versus what just passes time?", category: .rest),
99 .init(text: "Help me take a real break", category: .rest),
100 .init(text: "My energy is low. What’s a kind next step?", category: .rest),
101 .init(text: "How do I wind down tonight?", category: .rest),
102 .init(text: "What’s one way to recharge in ten minutes?", category: .rest),
103 // Stillness and spirit
104 .init(text: "Help me find a quiet moment today", category: .stillness),
105 .init(text: "Give me a short practice of stillness", category: .stillness),
106 .init(text: "What can I be grateful for right now?", category: .stillness),
107 .init(text: "Help me slow down and notice", category: .stillness),
108 .init(text: "What question could I carry through today?", category: .stillness),
109 .init(text: "How do I make room for silence?", category: .stillness),
110 .init(text: "Help me feel some peace today", category: .stillness),
111 // Self-kindness when stuck
112 .init(text: "I feel stuck. Can you help?", category: .kindness),
113 .init(text: "I’m behind on everything. Where do I begin?", category: .kindness),
114 .init(text: "Help me be kinder to myself today", category: .kindness),
115 .init(text: "I messed up. What now?", category: .kindness),
116 .init(text: "I feel overwhelmed. What’s one small step?", category: .kindness),
117 .init(text: "How do I stop being so hard on myself?", category: .kindness),
118 .init(text: "Remind me that today is enough", category: .kindness),
119 ]
120
121 /// Three prompts from three different categories, none of them in `previous`.
122 static func draw(excluding previous: Set<String>, using generator: inout some RandomNumberGenerator) -> [CoachPrompt] {
123 let categories = CoachPrompt.Category.allCases.shuffled(using: &generator)
124 var picked: [CoachPrompt] = []
125 for category in categories where picked.count < 3 {
126 let options = pool.filter { $0.category == category && !previous.contains($0.text) }
127 if let prompt = options.randomElement(using: &generator) { picked.append(prompt) }
128 }
129 return picked
130 }
131
132 static func draw(excluding previous: Set<String>) -> [CoachPrompt] {
133 var generator = SystemRandomNumberGenerator()
134 return draw(excluding: previous, using: &generator)
135 }
136
137 /// The category of a question: an exact pooled prompt, or the first category whose keywords it uses.
138 static func category(for question: String) -> CoachPrompt.Category? {
139 let trimmed = question.trimmingCharacters(in: .whitespacesAndNewlines)
140 if let match = pool.first(where: { $0.text.caseInsensitiveCompare(trimmed) == .orderedSame }) { return match.category }
141 let words = Set(trimmed.lowercased().replacingOccurrences(of: "’", with: "'")
142 .split { !$0.isLetter && $0 != "'" }.map(String.init))
143 let order: [CoachPrompt.Category] = [.read, .reflect, .kindness, .rest, .stillness, .focus, .practice]
144 return order.first { !words.isDisjoint(with: $0.keywords) }
145 }
146}