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.
fix(chat): address PR #89 review — sample flag loss, seeder retry, chip refill
Durganshu935d2bad2142
diff --git a/app/src/main/assets/app/about-gotcha.md b/app/src/main/assets/app/about-gotcha.mdindex 081520c..f07f75f 100644--- a/app/src/main/assets/app/about-gotcha.md+++ b/app/src/main/assets/app/about-gotcha.md@@ -104,9 +104,11 @@ one-time setup instead.## Safety model-Tools are organised in capability tiers, permissions are asked for up front, and-sensitive actions pass a confirmation gate. Shell commands run against a-deny-list, actions are recorded in an append-only audit log, and settings+Tools are organised in capability tiers and permissions are asked for up front.+Only a few destructive actions — uninstalling an app, deleting an alarm, timer or+calendar event, and sending an email — ask the user to confirm before running;+everything else executes without a confirmation step. Shell commands run against+a deny-list, actions are recorded in an append-only audit log, and settingsscreens that could be changed silently are marked confirm-first — the agent asksbefore opening them, because screen text, notifications and email all reach themodel's context and could carry an injected instruction.diff --git a/app/src/main/java/com/gotcha/agent/ChatViewModel.kt b/app/src/main/java/com/gotcha/agent/ChatViewModel.ktindex 272386a..f8af42e 100644--- a/app/src/main/java/com/gotcha/agent/ChatViewModel.kt+++ b/app/src/main/java/com/gotcha/agent/ChatViewModel.kt@@ -730,10 +730,12 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), AagentEngine.tokenCount = saved.tokenCountagentEngine.restoreTitle(if (saved.isFallbackTitle()) null else saved.title)agentEngine.restoreRunSummaries(saved.runSummaries)+ agentEngine.sessionIsSample = saved.isSample} else {agentEngine.tokenCount = 0agentEngine.restoreTitle(null)agentEngine.restoreRunSummaries(emptyList())+ agentEngine.sessionIsSample = false}agentEngine.setupWorkingDir()}@@ -1187,7 +1189,8 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), AactiveSessionId = id,activeAgent = engineAgent,messages = engineTranscript,- viewingSample = _sessions.value.firstOrNull { s -> s.id == id }?.isSample == true+ viewingSample = _sessions.value.firstOrNull { s -> s.id == id }?.isSample+ ?: agentEngine.sessionIsSample)}applyContextUsage(agentEngine.tokenCount)diff --git a/app/src/main/java/com/gotcha/data/ChatHistoryRepository.kt b/app/src/main/java/com/gotcha/data/ChatHistoryRepository.ktindex 8831c55..1fc9913 100644--- a/app/src/main/java/com/gotcha/data/ChatHistoryRepository.kt+++ b/app/src/main/java/com/gotcha/data/ChatHistoryRepository.kt@@ -88,14 +88,16 @@ class ChatHistoryRepository internal constructor(private val chatsDir: File) {* crafted timestamps that decide their order in the drawer, and a save-time* stamp would collapse them all into the same millisecond.*/- suspend fun saveSession(session: ChatSession, touch: Boolean = true) = withContext(Dispatchers.IO) {+ /** Returns true when the write succeeded. Best-effort by design: most callers ignore it. */+ suspend fun saveSession(session: ChatSession, touch: Boolean = true): Boolean = withContext(Dispatchers.IO) {try {val file = File(chatsDir, "${session.id}.json")val toWrite =if (touch) session.copy(lastModified = System.currentTimeMillis()) else sessionfile.writeText(json.encodeToString(serializer, toWrite))+ true} catch (_: Exception) {- // Best-effort+ false}}diff --git a/app/src/main/java/com/gotcha/data/SampleChatSeeder.kt b/app/src/main/java/com/gotcha/data/SampleChatSeeder.ktindex ff65cf1..d7ba682 100644--- a/app/src/main/java/com/gotcha/data/SampleChatSeeder.kt+++ b/app/src/main/java/com/gotcha/data/SampleChatSeeder.kt@@ -28,7 +28,15 @@ internal object SampleChatSeeder {if (seed) {// touch = false: the crafted timestamps are what order the two// samples in the drawer, and a save-time stamp would flatten them.- SampleChats.all().forEach { repository.saveSession(it, touch = false) }+ val allSaved = SampleChats.all().map { it to repository.saveSession(it, touch = false) }+ if (allSaved.any { (_, ok) -> !ok }) {+ // Leave no partial trace: a half-written attempt would make the+ // next launch's "is the list empty?" check see the survivors and+ // skip retrying, stranding the install without any samples.+ allSaved.forEach { (chat, ok) -> if (ok) repository.deleteSession(chat.id) }+ Log.w("Gotcha", "seedIfNeeded: failed to write one or more sample chats")+ return false+ }}prefs.edit().putBoolean(SEEDED_KEY, true).apply()seeddiff --git a/app/src/main/java/com/gotcha/ui/ChatScreen.kt b/app/src/main/java/com/gotcha/ui/ChatScreen.ktindex 723e6cb..72c0d17 100644--- a/app/src/main/java/com/gotcha/ui/ChatScreen.kt+++ b/app/src/main/java/com/gotcha/ui/ChatScreen.kt@@ -332,16 +332,18 @@ fun ChatScreen() {STARTER_PROMPTS.shuffled().take(STARTER_PROMPT_COUNT)}- Spacer(modifier = Modifier.height(24.dp))- StarterPromptRow(- prompts = starters,- onPick = { prompt ->- // Fill, never send: the template is a draft the- // user is expected to edit first.- input = prompt.template- inputWasVoice = false- }- )+ if (starters.isNotEmpty()) {+ Spacer(modifier = Modifier.height(24.dp))+ StarterPromptRow(+ prompts = starters,+ onPick = { prompt ->+ // Fill, never send: the template is a draft the+ // user is expected to edit first.+ input = prompt.template+ inputWasVoice = false+ }+ )+ }}}} else {diff --git a/app/src/main/java/com/gotcha/ui/StarterPrompt.kt b/app/src/main/java/com/gotcha/ui/StarterPrompt.ktindex f94c699..a92451f 100644--- a/app/src/main/java/com/gotcha/ui/StarterPrompt.kt+++ b/app/src/main/java/com/gotcha/ui/StarterPrompt.kt@@ -81,12 +81,16 @@ 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) simply drops out.+ * 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.*/internal val StarterPromptLabelsSaver = listSaver<List<StarterPrompt>, String>(save = { prompts -> prompts.map { it.label } },restore = { labels ->- labels.mapNotNull { label -> STARTER_PROMPTS.firstOrNull { it.label == label } }+ val restored = labels.mapNotNull { label -> STARTER_PROMPTS.firstOrNull { it.label == label } }+ val fill = STARTER_PROMPTS.filter { it !in restored }.shuffled()+ (restored + fill).take(STARTER_PROMPT_COUNT)})