Skip to content

Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.

feat(personas): starter prompts follow the selected persona (#117)

Durganshu3b80c41bfa8d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 87f420e..87e9d45 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -114,6 +114,11 @@ All notable changes to Gotcha are documented here.
what the agent is allowed to do — the mode restrictions remain the last word.
Where a role shadows a regulated profession its prompt says so: the Doctor
never presents itself as your doctor, and routes emergencies to real care.
+ Picking a persona also swaps the "Try" chips under it for the role's own
+ (#117) — the Doctor offers "Check a symptom" and "Is this urgent?", the Chef
+ "Cook from my fridge" — in place of the device-control ones, which come back
+ when the persona is cleared. Every role's starters are things to ask it, so
+ they all work in Monitor.
- **Search the settings.** Fifteen settings pages hold well over a hundred
controls between them, and finding one meant scrolling the list and guessing
which page owned it — "wake word" is under Assistive Ball, "API key" under AI
diff --git a/app/src/androidTest/java/com/gotcha/ChatRoundTripTest.kt b/app/src/androidTest/java/com/gotcha/ChatRoundTripTest.kt
index 3a272e4..407e4be 100644
--- a/app/src/androidTest/java/com/gotcha/ChatRoundTripTest.kt
+++ b/app/src/androidTest/java/com/gotcha/ChatRoundTripTest.kt
@@ -19,6 +19,8 @@ import com.gotcha.testutil.MOCK_REPLY_OK
import com.gotcha.testutil.MockLlm
import com.gotcha.testutil.TestSeed
import com.gotcha.ui.STARTER_PROMPTS
+import com.gotcha.ui.StarterPrompt
+import com.gotcha.ui.personaById
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
@@ -125,6 +127,40 @@ class ChatRoundTripTest {
)
}
+ @Test
+ fun starterPrompts_followTheSelectedPersona() {
+ mockLlm.start()
+ val context = ApplicationProvider.getApplicationContext<android.content.Context>()
+ TestSeed.seedConfigured(context, baseUrl = mockLlm.baseUrl, model = "test-model")
+
+ scenario = ActivityScenario.launch(MainActivity::class.java)
+ composeRule.waitForIdle()
+
+ fun shownFrom(pool: List<StarterPrompt>) = pool.filter { prompt ->
+ composeRule.onAllNodes(hasTestTag("starter_prompt_${prompt.label}"))
+ .fetchSemanticsNodes().isNotEmpty()
+ }
+ val doctor = requireNotNull(personaById("doctor")).starters
+ val chef = requireNotNull(personaById("chef")).starters
+
+ assertEquals("no persona: the default starters", 3, shownFrom(STARTER_PROMPTS).size)
+
+ composeRule.onNodeWithTag("persona_doctor").performClick()
+ composeRule.waitForIdle()
+ assertEquals("Doctor: its own starters", 3, shownFrom(doctor).size)
+ assertTrue("Doctor: none of the default ones", shownFrom(STARTER_PROMPTS).isEmpty())
+
+ composeRule.onNodeWithTag("persona_chef").performClick()
+ composeRule.waitForIdle()
+ assertEquals("Chef: its own starters", 3, shownFrom(chef).size)
+ assertTrue("Chef: none of Doctor's", shownFrom(doctor).isEmpty())
+
+ // Tapping the chosen persona clears it, and the default row comes back.
+ composeRule.onNodeWithTag("persona_chef").performClick()
+ composeRule.waitForIdle()
+ assertEquals("cleared: the default starters again", 3, shownFrom(STARTER_PROMPTS).size)
+ }
+
@Test
fun editMessage_truncatesHistoryAndRegenerates() {
mockLlm.start()
diff --git a/app/src/main/java/com/gotcha/ui/ChatScreen.kt b/app/src/main/java/com/gotcha/ui/ChatScreen.kt
index ec7a2e0..accf692 100644
--- a/app/src/main/java/com/gotcha/ui/ChatScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/ChatScreen.kt
@@ -364,13 +364,17 @@ fun ChatScreen(
// key means typing is disabled, and a run in another chat
// blocks sending from here.
if (state.isConfigured && !otherChatRunning) {
- // Re-drawn per session rather than per recomposition, so
- // the three on offer don't reshuffle under a rotation.
+ // Re-drawn per session and per persona rather than per
+ // recomposition: picking or switching a persona swaps the
+ // row for its own starters at once, while the three on
+ // offer still don't reshuffle under a rotation.
+ val starterPool = startersFor(personaById(state.activePersonaId))
val starters = rememberSaveable(
state.activeSessionId,
- saver = StarterPromptLabelsSaver
+ state.activePersonaId,
+ saver = starterPromptLabelsSaver(starterPool)
) {
- STARTER_PROMPTS.shuffled().take(STARTER_PROMPT_COUNT)
+ starterPool.shuffled().take(STARTER_PROMPT_COUNT)
}
if (starters.isNotEmpty()) {
Spacer(modifier = Modifier.height(24.dp))
diff --git a/app/src/main/java/com/gotcha/ui/Persona.kt b/app/src/main/java/com/gotcha/ui/Persona.kt
index c16ba9b..804868b 100644
--- a/app/src/main/java/com/gotcha/ui/Persona.kt
+++ b/app/src/main/java/com/gotcha/ui/Persona.kt
@@ -43,12 +43,18 @@ import com.gotcha.ui.theme.motionSpec
* [defaultAgent] is the mode applied when the persona is picked. It is a
* starting point, not a lock — the selector directly above the row stays live,
* so the user can take a persona into Operator if they want it acting.
+ *
+ * [starters] replace the default [STARTER_PROMPTS] on the empty chat while the
+ * persona is picked. Leave it empty to keep the default list; a list shorter
+ * than [STARTER_PROMPT_COUNT] can't fill a row, so it falls back the same way
+ * (see [startersFor]).
*/
data class Persona(
val id: String,
val label: String,
val defaultAgent: AgentMode,
- val systemPrompt: String
+ val systemPrompt: String,
+ val starters: List<StarterPrompt> = emptyList()
)
/**
@@ -63,6 +69,9 @@ data class Persona(
* Where a role maps onto a regulated profession the prompt carries its own
* disclaimer: these are not that professional, and the reply has to say so
* rather than leaving the persona's costume to imply otherwise.
+ *
+ * Their starters are things to *ask* the role, never things for the device to
+ * do: they have to work in Monitor, where every one of these starts.
*/
internal val PERSONAS = listOf(
Persona(
@@ -77,7 +86,29 @@ internal val PERSONAS = listOf(
"Tell the user to seek in-person care when the picture is unclear, when symptoms persist " +
"or worsen, and immediately — before anything else in your reply — when anything suggests " +
"an emergency (chest pain, trouble breathing, stroke signs, severe bleeding, suicidal " +
- "thoughts). Never give dosing instructions for prescription medication."
+ "thoughts). Never give dosing instructions for prescription medication.",
+ starters = listOf(
+ StarterPrompt(
+ label = "Check a symptom",
+ template = "I've had … for … days. What could be causing it?"
+ ),
+ StarterPrompt(
+ label = "Is this urgent?",
+ template = "I have … — should I see a doctor today, or can it wait?"
+ ),
+ StarterPrompt(
+ label = "Explain a result",
+ template = "Can you explain what this test result means: …"
+ ),
+ StarterPrompt(
+ label = "Sleep better",
+ template = "I keep waking up in the night. What usually helps?"
+ ),
+ StarterPrompt(
+ label = "Cold or flu?",
+ template = "I have a sore throat and a temperature. Is it a cold or the flu?"
+ )
+ )
),
Persona(
id = "chef",
@@ -87,7 +118,29 @@ internal val PERSONAS = listOf(
"and how much time they have, and give recipes as short numbered steps with real quantities " +
"and pan temperatures. Offer substitutions for anything hard to find, call out the step where " +
"a dish is usually ruined, and flag common allergens in what you suggest. Keep food safety " +
- "advice (cooking temperatures, storage times, reheating) accurate rather than relaxed."
+ "advice (cooking temperatures, storage times, reheating) accurate rather than relaxed.",
+ starters = listOf(
+ StarterPrompt(
+ label = "Cook from my fridge",
+ template = "I have … in the fridge. What can I make in 30 minutes?"
+ ),
+ StarterPrompt(
+ label = "Plan a dinner",
+ template = "Plan a dinner for … people, one of them vegetarian"
+ ),
+ StarterPrompt(
+ label = "Swap an ingredient",
+ template = "What can I use instead of … in …?"
+ ),
+ StarterPrompt(
+ label = "Quick breakfast",
+ template = "Give me three breakfasts I can make in under 10 minutes"
+ ),
+ StarterPrompt(
+ label = "Fix a dish",
+ template = "My … came out too … — what went wrong?"
+ )
+ )
),
Persona(
id = "fitness_coach",
@@ -97,7 +150,29 @@ internal val PERSONAS = listOf(
"any injuries before programming anything, then give concrete sessions — exercises, sets, " +
"reps, rest, and how to progress week to week. Cue form in a sentence or two per lift. " +
"You are not a doctor or a physiotherapist: say so when the user describes pain, and send " +
- "them to a professional for anything that hurts rather than working around it."
+ "them to a professional for anything that hurts rather than working around it.",
+ starters = listOf(
+ StarterPrompt(
+ label = "Plan my week",
+ template = "Plan three workouts a week for a beginner with no equipment"
+ ),
+ StarterPrompt(
+ label = "Start running",
+ template = "Give me a plan to run 5 km without stopping"
+ ),
+ StarterPrompt(
+ label = "Check my form",
+ template = "How do I squat with good form?"
+ ),
+ StarterPrompt(
+ label = "Stretch routine",
+ template = "Give me a 10-minute stretch for after sitting all day"
+ ),
+ StarterPrompt(
+ label = "Build strength",
+ template = "I can go to a gym twice a week. Build me a strength plan"
+ )
+ )
),
Persona(
id = "tutor",
@@ -108,7 +183,29 @@ internal val PERSONAS = listOf(
"next step themselves instead of finishing every problem for them, and when they are wrong " +
"point at the specific move that went wrong rather than restating the whole solution. " +
"If the work looks like homework being handed to you, help them solve it — do not just " +
- "produce an answer to copy."
+ "produce an answer to copy.",
+ starters = listOf(
+ StarterPrompt(
+ label = "Explain a topic",
+ template = "Explain … to me like I'm new to it"
+ ),
+ StarterPrompt(
+ label = "Quiz me",
+ template = "Quiz me on … one question at a time"
+ ),
+ StarterPrompt(
+ label = "Help with a problem",
+ template = "I'm stuck on this problem: …"
+ ),
+ StarterPrompt(
+ label = "Check my answer",
+ template = "Here's my working for …. Where did I go wrong?"
+ ),
+ StarterPrompt(
+ label = "Make a study plan",
+ template = "I have an exam on … in two weeks. Help me plan my revision"
+ )
+ )
),
Persona(
id = "travel_planner",
@@ -119,7 +216,29 @@ internal val PERSONAS = listOf(
"travel time between stops and the hours places actually keep. Name specific neighbourhoods " +
"and options rather than generic advice, and say when something needs booking ahead. " +
"Be explicit that prices, opening hours and entry requirements change, and that visas and " +
- "travel advisories must be checked against official sources."
+ "travel advisories must be checked against official sources.",
+ starters = listOf(
+ StarterPrompt(
+ label = "Plan a weekend",
+ template = "Plan a weekend in … for two on a mid-range budget"
+ ),
+ StarterPrompt(
+ label = "Build an itinerary",
+ template = "Build a 5-day itinerary for … in …"
+ ),
+ StarterPrompt(
+ label = "Packing list",
+ template = "What should I pack for a week in … in …?"
+ ),
+ StarterPrompt(
+ label = "Best time to go",
+ template = "When is the best time of year to visit …?"
+ ),
+ StarterPrompt(
+ label = "Trip on a budget",
+ template = "Where can I go for a week from … on a budget of …?"
+ )
+ )
),
Persona(
id = "handyman",
@@ -129,7 +248,29 @@ internal val PERSONAS = listOf(
"the thing actually is and what tools they own, then give ordered steps with the tools and " +
"parts named. Lead with the safety step — power off at the breaker, water off at the valve, " +
"eye protection — whenever one applies. Say plainly when a job belongs to a licensed " +
- "electrician, plumber or gas fitter, and do not talk the user through it anyway."
+ "electrician, plumber or gas fitter, and do not talk the user through it anyway.",
+ starters = listOf(
+ StarterPrompt(
+ label = "Fix a leaky tap",
+ template = "My tap keeps dripping. How do I fix it?"
+ ),
+ StarterPrompt(
+ label = "Hang a shelf",
+ template = "How do I hang a heavy shelf on a … wall?"
+ ),
+ StarterPrompt(
+ label = "Unblock a drain",
+ template = "My sink drains slowly. How do I clear it?"
+ ),
+ StarterPrompt(
+ label = "Patch a wall",
+ template = "How do I fill a hole in plasterboard?"
+ ),
+ StarterPrompt(
+ label = "Squeaky door",
+ template = "How do I stop a door from squeaking?"
+ )
+ )
)
)
diff --git a/app/src/main/java/com/gotcha/ui/StarterPrompt.kt b/app/src/main/java/com/gotcha/ui/StarterPrompt.kt
index a92451f..573db5c 100644
--- a/app/src/main/java/com/gotcha/ui/StarterPrompt.kt
+++ b/app/src/main/java/com/gotcha/ui/StarterPrompt.kt
@@ -30,11 +30,14 @@ import androidx.compose.ui.unit.dp
* a screen, while the template is a first draft of a real prompt. Tapping fills
* the composer and stops there: the user edits and sends, so a template may
* carry an unfilled `…` where a name or a message belongs.
+ *
+ * Public only because [Persona] carries its own list of them.
*/
-internal data class StarterPrompt(val label: String, val template: String)
+data class StarterPrompt(val label: String, val template: String)
/**
- * The starters offered on an empty chat. Between them they demo the three things
+ * The default starters, offered on an empty chat with no persona picked (or a
+ * persona with no starters of its own — see [startersFor]). Between them they demo the three things
* people most often don't realise Gotcha can do — drive the device, answer
* questions about what's on screen or on disk, and handle messages.
*
@@ -42,6 +45,10 @@ internal data class StarterPrompt(val label: String, val template: String)
* so they answer in Monitor as well as Operator. The two device actions need
* Operator; the chip does not switch mode on the user's behalf, the selector
* directly above it does.
+ *
+ * A persona's own starters replace this list outright, and are held to a
+ * stricter rule: every one must be answerable in Monitor, the mode every
+ * persona starts in, so none of them leads with a device action.
*/
internal val STARTER_PROMPTS = listOf(
StarterPrompt(
@@ -74,22 +81,32 @@ internal val STARTER_PROMPTS = listOf(
)
)
-/** How many of [STARTER_PROMPTS] a single home screen offers. */
+/** How many starters a single home screen offers. */
internal const val STARTER_PROMPT_COUNT = 3
/**
- * rememberSaveable saver for the drawn starters. Only the labels are stored —
- * they are unique, and the prompts themselves are a compile-time list, so a
- * restore is a lookup. A label that no longer exists (the list changed across an
- * app update, with saved state from the old one) drops out, and the row is
- * refilled from the current list so a stale save never shows fewer than
- * [STARTER_PROMPT_COUNT] chips.
+ * The pool the home screen draws its starters from: [persona]'s own when it
+ * has enough to fill a row, otherwise [STARTER_PROMPTS]. A persona's starters
+ * replace the default list rather than mixing with it — a Doctor chat offering
+ * "Turn on Wi-Fi" is exactly the "the persona changed nothing" feeling they
+ * exist to avoid.
+ */
+internal fun startersFor(persona: Persona?): List<StarterPrompt> =
+ persona?.starters?.takeIf { it.size >= STARTER_PROMPT_COUNT } ?: STARTER_PROMPTS
+
+/**
+ * rememberSaveable saver for the starters drawn from [pool]. Only the labels
+ * are stored — they are unique within a pool, and the prompts themselves are a
+ * compile-time list, so a restore is a lookup. A label that no longer exists
+ * (the list changed across an app update, with saved state from the old one)
+ * drops out, and the row is refilled from [pool] so a stale save never shows
+ * fewer than [STARTER_PROMPT_COUNT] chips.
*/
-internal val StarterPromptLabelsSaver = listSaver<List<StarterPrompt>, String>(
+internal fun starterPromptLabelsSaver(pool: List<StarterPrompt>) = listSaver<List<StarterPrompt>, String>(
save = { prompts -> prompts.map { it.label } },
restore = { labels ->
- val restored = labels.mapNotNull { label -> STARTER_PROMPTS.firstOrNull { it.label == label } }
- val fill = STARTER_PROMPTS.filter { it !in restored }.shuffled()
+ val restored = labels.mapNotNull { label -> pool.firstOrNull { it.label == label } }
+ val fill = pool.filter { it !in restored }.shuffled()
(restored + fill).take(STARTER_PROMPT_COUNT)
}
)
diff --git a/app/src/test/java/com/gotcha/ui/PersonasTest.kt b/app/src/test/java/com/gotcha/ui/PersonasTest.kt
index f310576..b388768 100644
--- a/app/src/test/java/com/gotcha/ui/PersonasTest.kt
+++ b/app/src/test/java/com/gotcha/ui/PersonasTest.kt
@@ -72,6 +72,19 @@ class PersonasTest {
)
}
+ @Test
+ fun `every seeded persona brings its own starters`() {
+ // The home screen falls back to the device-control starters for a
+ // persona without enough of its own, which is what made picking one
+ // look like it changed nothing (#117).
+ PERSONAS.forEach { persona ->
+ assertTrue(
+ "Persona '${persona.id}' needs at least $STARTER_PROMPT_COUNT starters to fill a row",
+ persona.starters.size >= STARTER_PROMPT_COUNT
+ )
+ }
+ }
+
@Test
fun `lookup resolves known ids and tolerates the rest`() {
assertNotNull(personaById(PERSONAS.first().id))
diff --git a/app/src/test/java/com/gotcha/ui/StarterPromptsTest.kt b/app/src/test/java/com/gotcha/ui/StarterPromptsTest.kt
index ddd3133..b923e44 100644
--- a/app/src/test/java/com/gotcha/ui/StarterPromptsTest.kt
+++ b/app/src/test/java/com/gotcha/ui/StarterPromptsTest.kt
@@ -2,51 +2,99 @@ package com.gotcha.ui
import androidx.compose.runtime.saveable.SaverScope
import org.junit.Assert.assertEquals
+import org.junit.Assert.assertSame
import org.junit.Assert.assertTrue
import org.junit.Test
/**
- * [STARTER_PROMPTS] is a hand-edited list that the home screen draws from
- * blindly. These are the invariants that drawing relies on.
+ * [STARTER_PROMPTS] and each persona's starters are hand-edited lists that the
+ * home screen draws from blindly. These are the invariants that drawing relies
+ * on, checked for every pool the screen can draw from.
*/
class StarterPromptsTest {
+ /** The default list plus every persona's own, by a name for failure messages. */
+ private val pools: Map<String, List<StarterPrompt>> =
+ mapOf("default" to STARTER_PROMPTS) +
+ PERSONAS.filter { it.starters.isNotEmpty() }.associate { it.id to it.starters }
+
@Test
fun `offers enough starters to draw from`() {
- assertTrue(
- "The home screen draws $STARTER_PROMPT_COUNT starters per session, " +
- "so the list must hold at least that many",
- STARTER_PROMPTS.size >= STARTER_PROMPT_COUNT
- )
+ pools.forEach { (name, pool) ->
+ assertTrue(
+ "The home screen draws $STARTER_PROMPT_COUNT starters per session, " +
+ "so the $name list must hold at least that many",
+ pool.size >= STARTER_PROMPT_COUNT
+ )
+ }
assertTrue("Expected a spread of starters to draw from", STARTER_PROMPTS.size >= 5)
}
@Test
fun `every starter has a label and a template`() {
- STARTER_PROMPTS.forEach { prompt ->
- assertTrue("Blank label in $prompt", prompt.label.isNotBlank())
- assertTrue("Blank template in $prompt", prompt.template.isNotBlank())
- // The chip has to sit three to a row on a phone.
- assertTrue(
- "Label too long to fit a chip: '${prompt.label}'",
- prompt.label.length <= 20
- )
+ pools.forEach { (name, pool) ->
+ pool.forEach { prompt ->
+ assertTrue("Blank label in $name: $prompt", prompt.label.isNotBlank())
+ assertTrue("Blank template in $name: $prompt", prompt.template.isNotBlank())
+ // The chip has to sit three to a row on a phone.
+ assertTrue(
+ "Label too long to fit a chip in $name: '${prompt.label}'",
+ prompt.label.length <= 20
+ )
+ }
}
}
@Test
- fun `labels are unique`() {
+ fun `labels are unique within a pool`() {
// The saver restores a drawn starter by its label, and the chips are
- // test-tagged by it, so duplicates would make both ambiguous.
- val labels = STARTER_PROMPTS.map { it.label }
- assertEquals(labels.size, labels.distinct().size)
+ // test-tagged by it, so duplicates would make both ambiguous. Only one
+ // pool is on screen at a time, so pools may share a label.
+ pools.forEach { (name, pool) ->
+ val labels = pool.map { it.label }
+ assertEquals("Duplicate label in $name", labels.size, labels.distinct().size)
+ }
}
@Test
- fun `saver round-trips a drawn set`() {
- val drawn = STARTER_PROMPTS.take(STARTER_PROMPT_COUNT)
+ fun `saver round-trips a drawn set from every pool`() {
val scope = SaverScope { true }
- val saved = requireNotNull(with(StarterPromptLabelsSaver) { scope.save(drawn) })
- assertEquals(drawn, StarterPromptLabelsSaver.restore(saved))
+ pools.forEach { (name, pool) ->
+ val saver = starterPromptLabelsSaver(pool)
+ val drawn = pool.take(STARTER_PROMPT_COUNT)
+ val saved = requireNotNull(with(saver) { scope.save(drawn) })
+ assertEquals(name, drawn, saver.restore(saved))
+ }
+ }
+
+ @Test
+ fun `saver refills a stale save from its own pool`() {
+ val pool = requireNotNull(personaById("doctor")).starters
+ val restored = requireNotNull(
+ starterPromptLabelsSaver(pool).restore(listOf(pool.first().label, "A starter since removed"))
+ )
+ assertEquals(STARTER_PROMPT_COUNT, restored.size)
+ assertEquals(pool.first(), restored.first())
+ assertTrue(restored.all { it in pool })
+ }
+
+ @Test
+ fun `no persona draws from the default list`() {
+ assertSame(STARTER_PROMPTS, startersFor(null))
+ }
+
+ @Test
+ fun `a persona with starters replaces the default list`() {
+ val doctor = requireNotNull(personaById("doctor"))
+ assertEquals(doctor.starters, startersFor(doctor))
+ assertTrue(startersFor(doctor).none { it in STARTER_PROMPTS })
+ }
+
+ @Test
+ fun `a persona without enough starters falls back to the default list`() {
+ val bare = PERSONAS.first().copy(starters = emptyList())
+ assertSame(STARTER_PROMPTS, startersFor(bare))
+ val short = PERSONAS.first().let { it.copy(starters = it.starters.take(STARTER_PROMPT_COUNT - 1)) }
+ assertSame(STARTER_PROMPTS, startersFor(short))
}
}