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(settings): add a Personal Info page and feed it into the system prompt

Durganshu Mishra6083f842d08b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f35a3ba..da11618 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,36 @@ All notable changes to Gotcha are documented here.
## [Unreleased]
+### Added — Personal Info, fed into the system prompt
+
+The assistant knew what device it was running on and nothing about the person
+using it. Preferred language and currency were the only two facts it had, and
+they were filed under Proactive Assistance, where they only looked like settings
+for that feature.
+
+- **ui/PersonalInfoScreen.kt** (new, first row on the settings home list): name,
+ location, occupation, a free-text background, and a free-text reply style,
+ plus the preferred language (with its Test voice button) and currency moved
+ over from Proactive Assistance. Every field is optional and stays on the
+ device.
+- **AgentEngine**: the facts render as a `<user_profile>` block after `<env>` —
+ a block of its own because `<env>` describes the device and this describes the
+ person, and the model needs to keep the two apart. Blank fields are omitted
+ entirely; an untouched profile is two lines, not a list of "unknown"s the
+ model then tries to fill in by asking. Newlines inside a field are collapsed
+ so a multi-line background can't be read as the start of another fact.
+- The reply-style text is injected next to the language directive at the tail of
+ the message array instead, since it is an instruction about the reply being
+ written now rather than a fact to remember. It is explicitly subordinate to
+ safety constraints, the mode restrictions and tool-required formats.
+- **ui/ProactiveScreen.kt** is now only the proactive toggles, and no longer
+ needs `onTestVoice`.
+- **SettingsRepository**: `load()` reads strings through a new `string()` helper
+ (the sibling of the existing `stringSet()`). `getString` returns a nullable
+ even with a non-null default, so every field carried its own elvis; the new
+ Personal Info fields tipped the accumulated count past detekt's complexity
+ ceiling.
+
### Changed — Settings is now a list of pages, not one long scroll
Settings was a single scrolling screen with five accordions, one of which
diff --git a/app/src/androidTest/java/com/gotcha/SettingsFlowTest.kt b/app/src/androidTest/java/com/gotcha/SettingsFlowTest.kt
index 11e69ff..73ba5b4 100644
--- a/app/src/androidTest/java/com/gotcha/SettingsFlowTest.kt
+++ b/app/src/androidTest/java/com/gotcha/SettingsFlowTest.kt
@@ -62,6 +62,34 @@ class SettingsFlowTest {
composeRule.onNodeWithTag("chat_input").assertExists()
}
+ @Test
+ fun personalInfo_persistsAcrossRelaunch() {
+ val context = ApplicationProvider.getApplicationContext<android.content.Context>()
+ TestSeed.seedUnconfigured(context)
+
+ scenario = ActivityScenario.launch(MainActivity::class.java)
+ composeRule.waitForIdle()
+
+ // First run opens on AI Configuration; Back reaches the category list.
+ composeRule.onNodeWithText("← Back").performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithTag("settings_personal_info_row").performScrollTo().performClick()
+ composeRule.waitForIdle()
+
+ composeRule.onNodeWithTag("settings_user_name").performTextReplacement("Ada")
+ composeRule.onNodeWithTag("settings_user_response_style")
+ .performScrollTo()
+ .performTextReplacement("No bullet lists.")
+ composeRule.onNodeWithTag("settings_save_personal_info").performScrollTo().performClick()
+ composeRule.waitForIdle()
+
+ scenario?.close()
+
+ val persisted = SettingsRepository(context).load()
+ assertEquals("Ada", persisted.userName)
+ assertEquals("No bullet lists.", persisted.userResponseStyle)
+ }
+
@Test
fun settingsSubPage_opensFromTheListAndBackReturnsToIt() {
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
diff --git a/app/src/main/java/com/gotcha/agent/AgentEngine.kt b/app/src/main/java/com/gotcha/agent/AgentEngine.kt
index b30d4fb..a51cbbf 100644
--- a/app/src/main/java/com/gotcha/agent/AgentEngine.kt
+++ b/app/src/main/java/com/gotcha/agent/AgentEngine.kt
@@ -956,6 +956,18 @@ class AgentEngine(
"ALWAYS use English for tool names, tool arguments, file paths, package names, " +
"app names, search queries passed to tools, and shell commands — regardless of " +
"the language you are replying in."
+ // The user's own words about how they want to be answered (Settings ▸
+ // Personal Info). It rides with the language directive at the tail of
+ // the message array rather than in the <user_profile> block: it is an
+ // instruction about the reply being written now, not a fact to remember.
+ val styleDirective = settings.userResponseStyle.trim()
+ .takeIf { it.isNotEmpty() }
+ ?.let {
+ "\n\nThe user has described how they want replies written:\n$it\n" +
+ "Follow that unless it would conflict with a safety constraint, with the " +
+ "mode restrictions below, or with a format a tool requires."
+ }
+ .orEmpty()
val core = when (agent) {
AgentMode.MONITOR ->
"You are Monitor, a read-only AI assistant running on the user's Android phone. " +
@@ -1029,7 +1041,10 @@ class AgentEngine(
"</system-reminder>"
}
return listOf(
- ChatMessage(role = "system", content = JsonPrimitive(core + languageDirective + reminder))
+ ChatMessage(
+ role = "system",
+ content = JsonPrimitive(core + languageDirective + styleDirective + reminder)
+ )
)
}
@@ -1086,8 +1101,6 @@ class AgentEngine(
appendLine(" App version: $versionName")
appendLine(" Working directory: ${FileResolver.WORKING_DIR_BASE}")
appendLine(" (Relative paths in read_file/write_file/list_files resolve against the working directory.)")
- appendLine(" Preferred language: ${settings.preferredLanguage}")
- appendLine(" Preferred currency: ${settings.preferredCurrency}")
// Connector state, rebuilt every call. The active list is what lets the
// model notice a connector that appeared mid-conversation: its own
// earlier turns may say "no account is connected", and a tool quietly
@@ -1111,6 +1124,47 @@ class AgentEngine(
)
}
append("</env>")
+ append("\n\n")
+ append(buildUserProfileString())
+ }
+ }
+
+ /**
+ * What the user told us about themselves in Settings ▸ Personal Info.
+ *
+ * A block of its own rather than more `<env>` lines: `<env>` describes the
+ * device and the run, this describes the person asking, and the model needs
+ * to keep the two apart — a preference here is something to honour, not a
+ * capability to reason about. Blank fields are omitted entirely so an
+ * untouched profile costs a couple of lines rather than a list of "unknown"s
+ * the model may then try to fill in by asking.
+ *
+ * Language and currency always appear: they have real defaults, and the
+ * model is worse off guessing them than reading a default it can be
+ * corrected on.
+ */
+ private fun buildUserProfileString(): String {
+ val s = settings
+ val facts = buildList {
+ // One fact per line, so a multi-line Background can't be mistaken for
+ // the start of a new one.
+ fun fact(label: String, value: String) {
+ value.replace(Regex("\\s+"), " ").trim()
+ .takeIf { it.isNotEmpty() }
+ ?.let { add("$label: $it") }
+ }
+ fact("Name", s.userName)
+ fact("Location", s.userLocation)
+ fact("Occupation", s.userOccupation)
+ fact("Background", s.userBackground)
+ fact("Preferred language", s.preferredLanguage)
+ fact("Preferred currency", s.preferredCurrency)
+ }
+ return buildString {
+ appendLine("Here is what the user has told you about themselves:")
+ appendLine("<user_profile>")
+ facts.forEach { appendLine(" $it") }
+ append("</user_profile>")
}
}
diff --git a/app/src/main/java/com/gotcha/data/SettingsRepository.kt b/app/src/main/java/com/gotcha/data/SettingsRepository.kt
index 5ed2898..459ed99 100644
--- a/app/src/main/java/com/gotcha/data/SettingsRepository.kt
+++ b/app/src/main/java/com/gotcha/data/SettingsRepository.kt
@@ -76,6 +76,25 @@ data class Settings(
val proactiveOtpEnabled: Boolean = true,
val proactiveAutoCopyOtp: Boolean = true,
val proactiveAppBlacklist: Set<String> = emptySet(),
+ // ---- Personal info (Settings ▸ Personal Info) ----
+ // Everything the user chooses to tell the agent about themselves. All of it
+ // is optional, and all of it reaches the model's system prompt — see
+ // AgentEngine's <user_profile> block and the style directive.
+ /** What the user wants to be called. */
+ val userName: String = "",
+ /** Where the user is, in their own words ("Munich, Germany"). Grounds dates, units and prices. */
+ val userLocation: String = "",
+ /** What the user does — role, field, seniority. */
+ val userOccupation: String = "",
+ /** Free-text background: anything the agent should know about them by default. */
+ val userBackground: String = "",
+ /**
+ * Free-text output preferences ("no bullet lists", "always show the command
+ * you ran"). Kept apart from [userBackground] because it is an instruction
+ * about *how* to answer, not a fact, and is injected next to the language
+ * directive rather than into the profile block.
+ */
+ val userResponseStyle: String = "",
val preferredLanguage: String = "English",
val preferredCurrency: String = "USD",
val communitySkillHosts: Set<String> = setOf("samosa-ai.example", "samosa.ai")
@@ -192,16 +211,23 @@ class SettingsRepository(context: Context) {
private fun stringSet(key: String, default: Set<String> = emptySet()): Set<String> =
prefs.getStringSet(key, default) ?: default
+ /**
+ * `getString` is nullable even with a non-null default, so every field would
+ * otherwise carry its own elvis — enough of them to tip [load] over detekt's
+ * complexity ceiling on its own.
+ */
+ private fun string(key: String, default: String = ""): String =
+ prefs.getString(key, default) ?: default
+
fun load(): Settings = Settings(
provider = LlmProvider.fromName(prefs.getString(KEY_PROVIDER, null)),
- apiKey = prefs.getString(KEY_API_KEY, "") ?: "",
- baseUrl = prefs.getString(KEY_BASE_URL, Settings.DEFAULT_BASE_URL)
- ?: Settings.DEFAULT_BASE_URL,
- model = prefs.getString(KEY_MODEL, Settings.DEFAULT_MODEL) ?: Settings.DEFAULT_MODEL,
- samosaSessionToken = prefs.getString(KEY_SAMOSA_TOKEN, "") ?: "",
- samosaEmail = prefs.getString(KEY_SAMOSA_EMAIL, "") ?: "",
- subAgentModel = prefs.getString(KEY_SUB_AGENT_MODEL, "") ?: "",
- navigatorModel = prefs.getString(KEY_NAVIGATOR_MODEL, "") ?: "",
+ apiKey = string(KEY_API_KEY),
+ baseUrl = string(KEY_BASE_URL, Settings.DEFAULT_BASE_URL),
+ model = string(KEY_MODEL, Settings.DEFAULT_MODEL),
+ samosaSessionToken = string(KEY_SAMOSA_TOKEN),
+ samosaEmail = string(KEY_SAMOSA_EMAIL),
+ subAgentModel = string(KEY_SUB_AGENT_MODEL),
+ navigatorModel = string(KEY_NAVIGATOR_MODEL),
maxToolRounds = prefs.getInt(KEY_MAX_TOOL_ROUNDS, 300),
maxRepeatedToolCalls = prefs.getInt(KEY_MAX_REPEATED_TOOL_CALLS, 20),
maxNavigationToolCalls = prefs.getInt(KEY_MAX_NAVIGATION_TOOL_CALLS, 30),
@@ -209,25 +235,25 @@ class SettingsRepository(context: Context) {
maxContextTokens = prefs.getInt(KEY_MAX_CONTEXT_TOKENS, 70000),
apiTimeoutSeconds = prefs.getLong(KEY_API_TIMEOUT, 0L),
ttsProvider = runCatching {
- AudioProvider.valueOf(prefs.getString(KEY_TTS_PROVIDER, "ANDROID") ?: "ANDROID")
+ AudioProvider.valueOf(string(KEY_TTS_PROVIDER, "ANDROID"))
}.getOrDefault(AudioProvider.ANDROID),
- ttsApiBaseUrl = prefs.getString(KEY_TTS_API_URL, "") ?: "",
- ttsApiKey = prefs.getString(KEY_TTS_API_KEY, "") ?: "",
- ttsApiModel = prefs.getString(KEY_TTS_API_MODEL, "") ?: "",
- ttsVoice = prefs.getString(KEY_TTS_VOICE, "") ?: "",
+ ttsApiBaseUrl = string(KEY_TTS_API_URL),
+ ttsApiKey = string(KEY_TTS_API_KEY),
+ ttsApiModel = string(KEY_TTS_API_MODEL),
+ ttsVoice = string(KEY_TTS_VOICE),
sttProvider = runCatching {
- AudioProvider.valueOf(prefs.getString(KEY_STT_PROVIDER, "ANDROID") ?: "ANDROID")
+ AudioProvider.valueOf(string(KEY_STT_PROVIDER, "ANDROID"))
}.getOrDefault(AudioProvider.ANDROID),
- sttApiBaseUrl = prefs.getString(KEY_STT_API_URL, "") ?: "",
- sttApiKey = prefs.getString(KEY_STT_API_KEY, "") ?: "",
- sttApiModel = prefs.getString(KEY_STT_API_MODEL, "") ?: "",
- sttLanguage = prefs.getString(KEY_STT_LANGUAGE, "") ?: "",
+ sttApiBaseUrl = string(KEY_STT_API_URL),
+ sttApiKey = string(KEY_STT_API_KEY),
+ sttApiModel = string(KEY_STT_API_MODEL),
+ sttLanguage = string(KEY_STT_LANGUAGE),
autoReadReplies = prefs.getBoolean(KEY_AUTO_READ, false),
notifyVibrationEnabled = prefs.getBoolean(KEY_NOTIFY_VIBRATION, true),
notifyChimeEnabled = prefs.getBoolean(KEY_NOTIFY_CHIME, false),
assistiveBallEnabled = prefs.getBoolean(KEY_ASSISTIVE_BALL, false),
themeMode = runCatching {
- ThemeMode.valueOf(prefs.getString(KEY_THEME_MODE, "SYSTEM") ?: "SYSTEM")
+ ThemeMode.valueOf(string(KEY_THEME_MODE, "SYSTEM"))
}.getOrDefault(ThemeMode.SYSTEM),
disabledSkills = stringSet(KEY_DISABLED_SKILLS),
disabledConnectors = stringSet(KEY_DISABLED_CONNECTORS),
@@ -238,8 +264,13 @@ class SettingsRepository(context: Context) {
proactiveOtpEnabled = prefs.getBoolean(KEY_PROACTIVE_OTP_ENABLED, true),
proactiveAutoCopyOtp = prefs.getBoolean(KEY_PROACTIVE_AUTO_COPY_OTP, true),
proactiveAppBlacklist = stringSet(KEY_PROACTIVE_BLACKLIST),
- preferredLanguage = prefs.getString(KEY_PREFERRED_LANGUAGE, "English") ?: "English",
- preferredCurrency = prefs.getString(KEY_PREFERRED_CURRENCY, "USD") ?: "USD",
+ userName = string(KEY_USER_NAME),
+ userLocation = string(KEY_USER_LOCATION),
+ userOccupation = string(KEY_USER_OCCUPATION),
+ userBackground = string(KEY_USER_BACKGROUND),
+ userResponseStyle = string(KEY_USER_RESPONSE_STYLE),
+ preferredLanguage = string(KEY_PREFERRED_LANGUAGE, "English"),
+ preferredCurrency = string(KEY_PREFERRED_CURRENCY, "USD"),
communitySkillHosts = stringSet(KEY_COMMUNITY_SKILL_HOSTS, defaultCommunitySkillHosts)
)
@@ -283,6 +314,11 @@ class SettingsRepository(context: Context) {
.putBoolean(KEY_PROACTIVE_OTP_ENABLED, settings.proactiveOtpEnabled)
.putBoolean(KEY_PROACTIVE_AUTO_COPY_OTP, settings.proactiveAutoCopyOtp)
.putStringSet(KEY_PROACTIVE_BLACKLIST, settings.proactiveAppBlacklist)
+ .putString(KEY_USER_NAME, settings.userName)
+ .putString(KEY_USER_LOCATION, settings.userLocation)
+ .putString(KEY_USER_OCCUPATION, settings.userOccupation)
+ .putString(KEY_USER_BACKGROUND, settings.userBackground)
+ .putString(KEY_USER_RESPONSE_STYLE, settings.userResponseStyle)
.putString(KEY_PREFERRED_LANGUAGE, settings.preferredLanguage)
.putString(KEY_PREFERRED_CURRENCY, settings.preferredCurrency)
.putStringSet(KEY_COMMUNITY_SKILL_HOSTS, settings.communitySkillHosts)
@@ -344,6 +380,11 @@ class SettingsRepository(context: Context) {
const val KEY_PROACTIVE_OTP_ENABLED = "proactive_otp_enabled"
const val KEY_PROACTIVE_AUTO_COPY_OTP = "proactive_auto_copy_otp"
const val KEY_PROACTIVE_BLACKLIST = "proactive_blacklist"
+ const val KEY_USER_NAME = "user_name"
+ const val KEY_USER_LOCATION = "user_location"
+ const val KEY_USER_OCCUPATION = "user_occupation"
+ const val KEY_USER_BACKGROUND = "user_background"
+ const val KEY_USER_RESPONSE_STYLE = "user_response_style"
const val KEY_PREFERRED_LANGUAGE = "preferred_language"
const val KEY_PREFERRED_CURRENCY = "preferred_currency"
const val KEY_COMMUNITY_SKILL_HOSTS = "community_skill_hosts"
diff --git a/app/src/main/java/com/gotcha/ui/PersonalInfoScreen.kt b/app/src/main/java/com/gotcha/ui/PersonalInfoScreen.kt
new file mode 100644
index 0000000..62abc17
--- /dev/null
+++ b/app/src/main/java/com/gotcha/ui/PersonalInfoScreen.kt
@@ -0,0 +1,287 @@
+package com.gotcha.ui
+
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.material3.AlertDialog
+import androidx.compose.material3.Button
+import androidx.compose.material3.DropdownMenuItem
+import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.ExposedDropdownMenuBox
+import androidx.compose.material3.ExposedDropdownMenuDefaults
+import androidx.compose.material3.HorizontalDivider
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.OutlinedButton
+import androidx.compose.material3.OutlinedTextField
+import androidx.compose.material3.Text
+import androidx.compose.material3.TextButton
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.unit.dp
+import com.gotcha.data.Settings
+import com.gotcha.i18n.Language
+import kotlinx.coroutines.launch
+
+/** Currencies offered for [Settings.preferredCurrency]. */
+private val CURRENCIES = listOf("USD", "EUR", "GBP", "INR", "CAD", "AUD", "JPY", "CNY")
+
+/**
+ * The Personal Info page: who the user is and how they want to be answered.
+ *
+ * Every field here reaches the model's system prompt — the facts as a
+ * `<user_profile>` block, the reply-style text as a directive next to the
+ * language one (see `AgentEngine`). Nothing on this page changes what the agent
+ * is *allowed* to do; it only changes what it knows about the person asking.
+ *
+ * Language and currency live here rather than under Proactive Assistance, where
+ * they started: they describe the user, not whether the assistant volunteers
+ * help, and they apply to every reply whether proactive or not.
+ */
+@OptIn(ExperimentalMaterial3Api::class)
+@Composable
+fun PersonalInfoScreen(
+ load: () -> Settings,
+ onSave: ((Settings) -> Settings) -> Unit,
+ onBack: () -> Unit,
+ onTestVoice: suspend (Language) -> Boolean? = { null }
+) {
+ val initial = remember { load() }
+ var userName by remember { mutableStateOf(initial.userName) }
+ var userLocation by remember { mutableStateOf(initial.userLocation) }
+ var userOccupation by remember { mutableStateOf(initial.userOccupation) }
+ var userBackground by remember { mutableStateOf(initial.userBackground) }
+ var userResponseStyle by remember { mutableStateOf(initial.userResponseStyle) }
+ var preferredLanguage by remember { mutableStateOf(initial.preferredLanguage) }
+ var preferredCurrency by remember { mutableStateOf(initial.preferredCurrency) }
+
+ var languageExpanded by remember { mutableStateOf(false) }
+ var currencyExpanded by remember { mutableStateOf(false) }
+ var testingVoice by remember { mutableStateOf(false) }
+
+ /** Last [Language] whose voice data was reported missing, or null when not shown. */
+ var voiceDataMissing by remember { mutableStateOf<Language?>(null) }
+
+ val overlay = rememberSettingsOverlayState()
+ val scope = rememberCoroutineScope()
+ val localContext = LocalContext.current
+
+ /** This page's fields, copied onto [base]. */
+ fun applyPersonalInfo(base: Settings) = base.copy(
+ userName = userName.trim(),
+ userLocation = userLocation.trim(),
+ userOccupation = userOccupation.trim(),
+ userBackground = userBackground.trim(),
+ userResponseStyle = userResponseStyle.trim(),
+ preferredLanguage = preferredLanguage,
+ preferredCurrency = preferredCurrency
+ )
+
+ SettingsScaffold(title = SettingsPage.PERSONAL_INFO.title, onBack = onBack, overlay = overlay) {
+ Text(
+ "About you",
+ style = MaterialTheme.typography.titleMedium,
+ fontWeight = FontWeight.Bold
+ )
+ Text(
+ "Everything here is optional, stays on this device, and is given to the " +
+ "assistant at the start of every conversation so it doesn't have to ask.",
+ style = MaterialTheme.typography.bodySmall
+ )
+ OutlinedTextField(
+ value = userName,
+ onValueChange = { userName = it },
+ label = { Text("Name") },
+ placeholder = { Text("What the assistant should call you") },
+ singleLine = true,
+ modifier = Modifier
+ .fillMaxWidth()
+ .testTag("settings_user_name")
+ )
+ OutlinedTextField(
+ value = userLocation,
+ onValueChange = { userLocation = it },
+ label = { Text("Location") },
+ placeholder = { Text("e.g. Munich, Germany") },
+ singleLine = true,
+ modifier = Modifier
+ .fillMaxWidth()
+ .testTag("settings_user_location")
+ )
+ OutlinedTextField(
+ value = userOccupation,
+ onValueChange = { userOccupation = it },
+ label = { Text("Occupation") },
+ placeholder = { Text("e.g. Backend engineer") },
+ singleLine = true,
+ modifier = Modifier
+ .fillMaxWidth()
+ .testTag("settings_user_occupation")
+ )
+ OutlinedTextField(
+ value = userBackground,
+ onValueChange = { userBackground = it },
+ label = { Text("Background") },
+ placeholder = {
+ Text(
+ "Anything worth knowing by default — tools you use, who you " +
+ "work with, what you usually ask for"
+ )
+ },
+ minLines = 3,
+ modifier = Modifier
+ .fillMaxWidth()
+ .testTag("settings_user_background")
+ )
+
+ HorizontalDivider(thickness = 1.dp)
+
+ // ---- Output preferences ----
+ Text(
+ "How replies should be written",
+ style = MaterialTheme.typography.titleMedium,
+ fontWeight = FontWeight.Bold
+ )
+ OutlinedTextField(
+ value = userResponseStyle,
+ onValueChange = { userResponseStyle = it },
+ label = { Text("Reply style") },
+ placeholder = {
+ Text(
+ "e.g. Keep it to a few sentences, no bullet lists, show the " +
+ "command you ran"
+ )
+ },
+ minLines = 3,
+ modifier = Modifier
+ .fillMaxWidth()
+ .testTag("settings_user_response_style")
+ )
+
+ ExposedDropdownMenuBox(
+ expanded = languageExpanded,
+ onExpandedChange = { languageExpanded = it }
+ ) {
+ OutlinedTextField(
+ value = preferredLanguage,
+ onValueChange = {},
+ readOnly = true,
+ label = { Text("Preferred Language") },
+ trailingIcon = {
+ ExposedDropdownMenuDefaults.TrailingIcon(expanded = languageExpanded)
+ },
+ modifier = Modifier
+ .fillMaxWidth()
+ .menuAnchor()
+ )
+ ExposedDropdownMenu(
+ expanded = languageExpanded,
+ onDismissRequest = { languageExpanded = false }
+ ) {
+ Language.labels.forEach { lang ->
+ DropdownMenuItem(
+ text = { Text(lang) },
+ onClick = {
+ preferredLanguage = lang
+ languageExpanded = false
+ }
+ )
+ }
+ }
+ }
+ OutlinedButton(
+ onClick = {
+ testingVoice = true
+ scope.launch {
+ val lang = Language.fromLabel(preferredLanguage)
+ // Track which language triggered the missing-data state so
+ // rapid language-switch clicks don't surface a stale dialog.
+ val ok = onTestVoice(lang)
+ voiceDataMissing = if (ok == false) lang else null
+ testingVoice = false
+ }
+ },
+ enabled = !testingVoice,
+ modifier = Modifier.fillMaxWidth()
+ ) {
+ Text(if (testingVoice) "Playing…" else "Test voice")
+ }
+ voiceDataMissing?.let { missingLang ->
+ AlertDialog(
+ onDismissRequest = { voiceDataMissing = null },
+ title = { Text("Voice data not installed") },
+ text = {
+ Text(
+ "Your device doesn't have Android's built-in voice for " +
+ "${missingLang.label}. It was spoken in English instead. " +
+ "Install the voice data to fix pronunciation."
+ )
+ },
+ confirmButton = {
+ Button(
+ onClick = {
+ voiceDataMissing = null
+ try {
+ localContext.startActivity(
+ android.content.Intent(
+ android.speech.tts.TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA
+ ).addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)
+ )
+ } catch (_: Exception) { }
+ }
+ ) { Text("Install") }
+ },
+ dismissButton = {
+ TextButton(onClick = { voiceDataMissing = null }) { Text("Cancel") }
+ }
+ )
+ }
+
+ ExposedDropdownMenuBox(
+ expanded = currencyExpanded,
+ onExpandedChange = { currencyExpanded = it }
+ ) {
+ OutlinedTextField(
+ value = preferredCurrency,
+ onValueChange = {},
+ readOnly = true,
+ label = { Text("Preferred Currency") },
+ trailingIcon = {
+ ExposedDropdownMenuDefaults.TrailingIcon(expanded = currencyExpanded)
+ },
+ modifier = Modifier
+ .fillMaxWidth()
+ .menuAnchor()
+ )
+ ExposedDropdownMenu(
+ expanded = currencyExpanded,
+ onDismissRequest = { currencyExpanded = false }
+ ) {
+ CURRENCIES.forEach { curr ->
+ DropdownMenuItem(
+ text = { Text(curr) },
+ onClick = {
+ preferredCurrency = curr
+ currencyExpanded = false
+ }
+ )
+ }
+ }
+ }
+
+ Button(
+ onClick = {
+ onSave { applyPersonalInfo(it) }
+ overlay.show("Saved Personal Info.")
+ },
+ modifier = Modifier
+ .fillMaxWidth()
+ .testTag("settings_save_personal_info")
+ ) { Text("Save Personal Info") }
+ }
+}
diff --git a/app/src/main/java/com/gotcha/ui/ProactiveScreen.kt b/app/src/main/java/com/gotcha/ui/ProactiveScreen.kt
index 49e2060..abe2171 100644
--- a/app/src/main/java/com/gotcha/ui/ProactiveScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/ProactiveScreen.kt
@@ -1,39 +1,28 @@
package com.gotcha.ui
import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
-import androidx.compose.material3.DropdownMenuItem
-import androidx.compose.material3.ExperimentalMaterial3Api
-import androidx.compose.material3.ExposedDropdownMenuBox
-import androidx.compose.material3.ExposedDropdownMenuDefaults
-import androidx.compose.material3.OutlinedButton
-import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
-import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
-import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
-import androidx.compose.ui.platform.LocalContext
import com.gotcha.data.Settings
-import com.gotcha.i18n.Language
-import kotlinx.coroutines.launch
/**
- * The Proactive Assistance page: whether the assistant volunteers help, which
- * surfaces it may scan for context, and the language and currency it answers in.
+ * The Proactive Assistance page: whether the assistant volunteers help, and
+ * which surfaces it may scan for the context to do so.
+ *
+ * Language and currency used to live here; they moved to
+ * [PersonalInfoScreen] — they describe the user rather than this feature.
*/
-@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ProactiveScreen(
load: () -> Settings,
onSave: ((Settings) -> Settings) -> Unit,
- onBack: () -> Unit,
- onTestVoice: suspend (Language) -> Boolean? = { null }
+ onBack: () -> Unit
) {
val initial = remember { load() }
var proactiveEnabled by remember { mutableStateOf(initial.proactiveEnabled) }
@@ -42,18 +31,8 @@ fun ProactiveScreen(
var proactiveScanNotifications by remember { mutableStateOf(initial.proactiveScanNotifications) }
var proactiveOtpEnabled by remember { mutableStateOf(initial.proactiveOtpEnabled) }
var proactiveAutoCopyOtp by remember { mutableStateOf(initial.proactiveAutoCopyOtp) }
- var preferredLanguage by remember { mutableStateOf(initial.preferredLanguage) }
- var preferredCurrency by remember { mutableStateOf(initial.preferredCurrency) }
- var testingVoice by remember { mutableStateOf(false) }
-
- /** Last [Language] whose voice data was reported missing, or null when not shown. */
- var voiceDataMissing by remember { mutableStateOf<Language?>(null) }
- var languageExpanded by remember { mutableStateOf(false) }
- var currencyExpanded by remember { mutableStateOf(false) }
val overlay = rememberSettingsOverlayState()
- val scope = rememberCoroutineScope()
- val localContext = LocalContext.current
/** This page's fields, copied onto [base]. */
fun applyProactive(base: Settings) = base.copy(
@@ -62,9 +41,7 @@ fun ProactiveScreen(
proactiveScanClipboard = proactiveScanClipboard,
proactiveScanNotifications = proactiveScanNotifications,
proactiveOtpEnabled = proactiveOtpEnabled,
- proactiveAutoCopyOtp = proactiveAutoCopyOtp,
- preferredLanguage = preferredLanguage,
- preferredCurrency = preferredCurrency
+ proactiveAutoCopyOtp = proactiveAutoCopyOtp
)
SettingsScaffold(title = SettingsPage.PROACTIVE.title, onBack = onBack, overlay = overlay) {
@@ -100,119 +77,6 @@ fun ProactiveScreen(
checked = proactiveAutoCopyOtp,
onCheckedChange = { proactiveAutoCopyOtp = it }
)
-
- val languages = Language.labels
- ExposedDropdownMenuBox(
- expanded = languageExpanded,
- onExpandedChange = { languageExpanded = it }
- ) {
- OutlinedTextField(
- value = preferredLanguage,
- onValueChange = {},
- readOnly = true,
- label = { Text("Preferred Language") },
- trailingIcon = {
- ExposedDropdownMenuDefaults.TrailingIcon(expanded = languageExpanded)
- },
- modifier = Modifier
- .fillMaxWidth()
- .menuAnchor()
- )
- ExposedDropdownMenu(
- expanded = languageExpanded,
- onDismissRequest = { languageExpanded = false }
- ) {
- languages.forEach { lang ->
- DropdownMenuItem(
- text = { Text(lang) },
- onClick = {
- preferredLanguage = lang
- languageExpanded = false
- }
- )
- }
- }
- }
- OutlinedButton(
- onClick = {
- testingVoice = true
- scope.launch {
- val lang = Language.fromLabel(preferredLanguage)
- // Track which language triggered the missing-data state so
- // rapid language-switch clicks don't surface a stale dialog.
- val ok = onTestVoice(lang)
- voiceDataMissing = if (ok == false) lang else null
- testingVoice = false
- }
- },
- enabled = !testingVoice,
- modifier = Modifier.fillMaxWidth()
- ) {
- Text(if (testingVoice) "Playing…" else "Test voice")
- }
- voiceDataMissing?.let { missingLang ->
- AlertDialog(
- onDismissRequest = { voiceDataMissing = null },
- title = { Text("Voice data not installed") },
- text = {
- Text(
- "Your device doesn't have Android's built-in voice for " +
- "${missingLang.label}. It was spoken in English instead. " +
- "Install the voice data to fix pronunciation."
- )
- },
- confirmButton = {
- Button(
- onClick = {
- voiceDataMissing = null
- try {
- localContext.startActivity(
- android.content.Intent(
- android.speech.tts.TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA
- ).addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)
- )
- } catch (_: Exception) { }
- }
- ) { Text("Install") }
- },
- dismissButton = {
- TextButton(onClick = { voiceDataMissing = null }) { Text("Cancel") }
- }
- )
- }
-
- val currencies = listOf("USD", "EUR", "GBP", "INR", "CAD", "AUD", "JPY", "CNY")
- ExposedDropdownMenuBox(
- expanded = currencyExpanded,
- onExpandedChange = { currencyExpanded = it }
- ) {
- OutlinedTextField(
- value = preferredCurrency,
- onValueChange = {},
- readOnly = true,
- label = { Text("Preferred Currency") },
- trailingIcon = {
- ExposedDropdownMenuDefaults.TrailingIcon(expanded = currencyExpanded)
- },
- modifier = Modifier
- .fillMaxWidth()
- .menuAnchor()
- )
- ExposedDropdownMenu(
- expanded = currencyExpanded,
- onDismissRequest = { currencyExpanded = false }
- ) {
- currencies.forEach { curr ->
- DropdownMenuItem(
- text = { Text(curr) },
- onClick = {
- preferredCurrency = curr
- currencyExpanded = false
- }
- )
- }
- }
- }
}
Button(
onClick = {
diff --git a/app/src/main/java/com/gotcha/ui/SettingsCommon.kt b/app/src/main/java/com/gotcha/ui/SettingsCommon.kt
index 815ba58..034fc23 100644
--- a/app/src/main/java/com/gotcha/ui/SettingsCommon.kt
+++ b/app/src/main/java/com/gotcha/ui/SettingsCommon.kt
@@ -54,6 +54,11 @@ import kotlinx.coroutines.delay
* title, so the two can't drift apart.
*/
enum class SettingsPage(val title: String, val summary: String, val testTag: String) {
+ PERSONAL_INFO(
+ "Personal Info",
+ "Who you are, language, currency, reply style",
+ "settings_personal_info_row"
+ ),
AI_CONFIG(
"AI Configuration",
"Provider, models, agent limits",
@@ -76,7 +81,7 @@ enum class SettingsPage(val title: String, val summary: String, val testTag: Str
),
PROACTIVE(
"Proactive Assistance",
- "Offers, OTP detection, language",
+ "Offers, OTP detection, what may be scanned",
"settings_proactive_row"
)
}
diff --git a/app/src/main/java/com/gotcha/ui/SettingsScreen.kt b/app/src/main/java/com/gotcha/ui/SettingsScreen.kt
index 82fb890..5568af3 100644
--- a/app/src/main/java/com/gotcha/ui/SettingsScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/SettingsScreen.kt
@@ -91,6 +91,12 @@ fun SettingsScreen(
if (page != null) BackHandler(onBack = backToHome)
when (page) {
+ SettingsPage.PERSONAL_INFO -> PersonalInfoScreen(
+ load = load,
+ onSave = onSave,
+ onBack = backToHome,
+ onTestVoice = onTestVoice
+ )
SettingsPage.AI_CONFIG -> AiConfigScreen(
load = load,
onSave = onSave,
@@ -122,8 +128,7 @@ fun SettingsScreen(
SettingsPage.PROACTIVE -> ProactiveScreen(
load = load,
onSave = onSave,
- onBack = backToHome,
- onTestVoice = onTestVoice
+ onBack = backToHome
)
null -> SettingsHome(
load = load,
diff --git a/app/src/test/java/com/gotcha/agent/AgentPromptTest.kt b/app/src/test/java/com/gotcha/agent/AgentPromptTest.kt
index 7dda779..d2a50cb 100644
--- a/app/src/test/java/com/gotcha/agent/AgentPromptTest.kt
+++ b/app/src/test/java/com/gotcha/agent/AgentPromptTest.kt
@@ -13,6 +13,7 @@ import kotlinx.coroutines.test.runTest
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
+import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
@@ -25,6 +26,10 @@ import java.io.File
* Verifies the rendered system prompt carries the language directive and the
* English-tool-calls carve-out (issue #42 P0-5) — the highest-risk item in the
* multilingual change, since a translated tool argument fails silently.
+ *
+ * Also covers the Personal Info settings: the `<user_profile>` block and the
+ * reply-style directive are only useful if they actually reach the wire, and a
+ * field that silently fails to is indistinguishable from one the user never set.
*/
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], shadows = [ShadowExternalStorageManager::class])
@@ -56,19 +61,12 @@ class AgentPromptTest {
ShadowExternalStorageManager.resetGranted()
}
- private fun buildEngine(mode: AgentMode): AgentEngine {
+ private fun buildEngine(mode: AgentMode, settings: Settings = testSettings()): AgentEngine {
val engine = AgentEngine(
appContext = context,
events = RecordingAgentEvents(),
historyRepository = ChatHistoryRepository(context, "agent-prompt-test-chats"),
- settingsProvider = {
- Settings(
- apiKey = "test-key",
- baseUrl = server.url("/").toString(),
- preferredLanguage = "Hindi",
- maxToolRounds = 4
- )
- },
+ settingsProvider = { settings },
clientProvider = { LLMClient(apiKey = "test-key", baseUrl = server.url("/").toString()) },
workingDirRoot = workDir.absolutePath
)
@@ -77,11 +75,22 @@ class AgentPromptTest {
return engine
}
- private suspend fun requestBodyFor(mode: AgentMode): String {
+ private fun testSettings(personal: Settings.() -> Settings = { this }): Settings =
+ Settings(
+ apiKey = "test-key",
+ baseUrl = server.url("/").toString(),
+ preferredLanguage = "Hindi",
+ maxToolRounds = 4
+ ).personal()
+
+ private suspend fun requestBodyFor(
+ mode: AgentMode,
+ settings: Settings = testSettings()
+ ): String {
server.enqueue(
MockResponse().setBody("""{"choices":[{"message":{"role":"assistant","content":"ok"}}]}""")
)
- buildEngine(mode).run(mode)
+ buildEngine(mode, settings).run(mode)
return server.takeRequest().body.readUtf8()
}
@@ -100,9 +109,54 @@ class AgentPromptTest {
}
@Test
- fun `env block carries preferred language and currency facts`() = runTest {
+ fun `user profile block carries preferred language and currency facts`() = runTest {
val body = requestBodyFor(AgentMode.OPERATOR)
+ assertTrue(body.contains("<user_profile>"))
assertTrue(body.contains("Preferred language: Hindi"))
assertTrue(body.contains("Preferred currency:"))
}
+
+ @Test
+ fun `user profile block carries the personal info the user filled in`() = runTest {
+ val body = requestBodyFor(
+ AgentMode.OPERATOR,
+ testSettings {
+ copy(
+ userName = "Ada",
+ userLocation = "Munich, Germany",
+ userOccupation = "Backend engineer",
+ userBackground = "Works on\npayments infrastructure"
+ )
+ }
+ )
+ assertTrue(body.contains("Name: Ada"))
+ assertTrue(body.contains("Location: Munich, Germany"))
+ assertTrue(body.contains("Occupation: Backend engineer"))
+ // Newlines are collapsed so one fact can never span two lines of the block.
+ assertTrue(body.contains("Background: Works on payments infrastructure"))
+ }
+
+ @Test
+ fun `blank personal info fields are left out of the user profile block`() = runTest {
+ val body = requestBodyFor(AgentMode.OPERATOR, testSettings { copy(userName = " ") })
+ assertTrue(body.contains("<user_profile>"))
+ assertFalse(body.contains("Name:"))
+ assertFalse(body.contains("Occupation:"))
+ }
+
+ @Test
+ fun `reply style preference becomes a directive next to the language one`() = runTest {
+ val body = requestBodyFor(
+ AgentMode.OPERATOR,
+ testSettings { copy(userResponseStyle = "No bullet lists.") }
+ )
+ assertTrue(body.contains("how they want replies written"))
+ assertTrue(body.contains("No bullet lists."))
+ }
+
+ @Test
+ fun `no reply style preference adds no directive`() = runTest {
+ val body = requestBodyFor(AgentMode.OPERATOR)
+ assertFalse(body.contains("how they want replies written"))
+ }
}