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.

Address PR review: promoted examples, chip mode, dividers

Rishabh Bajpai96a44f4b6a46
diff --git a/app/src/main/java/com/gotcha/data/SecondBrainSummary.kt b/app/src/main/java/com/gotcha/data/SecondBrainSummary.kt
index 6d35924..4b0f8a6 100644
--- a/app/src/main/java/com/gotcha/data/SecondBrainSummary.kt
+++ b/app/src/main/java/com/gotcha/data/SecondBrainSummary.kt
@@ -24,6 +24,8 @@ fun MemoryStore.SecondBrainSnapshot.summary(): SecondBrainSummary = SecondBrainS
empty = notes.isEmpty() &&
people.isEmpty() &&
raw.isEmpty() &&
+ // The four seeded hubs are the skeleton; a fifth is something added.
+ areas.size <= 4 &&
(soul == null || MemoryStore.isPristineSoul(soul.content)) &&
(memoryIndex == null || MemoryStore.isPristineMemoryIndex(memoryIndex.content)) &&
areas.all { MemoryStore.isPristineArea(it.content) }
diff --git a/app/src/main/java/com/gotcha/scheduled/ScheduledTaskStore.kt b/app/src/main/java/com/gotcha/scheduled/ScheduledTaskStore.kt
index 2bb3d33..70040ca 100644
--- a/app/src/main/java/com/gotcha/scheduled/ScheduledTaskStore.kt
+++ b/app/src/main/java/com/gotcha/scheduled/ScheduledTaskStore.kt
@@ -85,7 +85,7 @@ class ScheduledTaskStore internal constructor(
var tasks = existing
val created = mutableListOf<ScheduledTask>()
for (preset in ScheduledPresets.all) {
- if (tasks.any { it.presetId == preset.id }) continue
+ if (tasks.any { it.presetId == preset.id } || isPromoted(preset.id)) continue
val seeded = seedOne(preset, tasks, memoryRoot, localNow, now)
tasks = seeded.tasks
seeded.created?.let { created += it }
@@ -140,7 +140,8 @@ class ScheduledTaskStore internal constructor(
fun missingPresets(): List<ScheduledPreset> = synchronized(LOCK) {
val tasks = read()
ScheduledPresets.all.filter { preset ->
- tasks.none { it.presetId == preset.id || it.name == preset.name }
+ !isPromoted(preset.id) &&
+ tasks.none { it.presetId == preset.id || it.name == preset.name }
}
}
@@ -154,7 +155,7 @@ class ScheduledTaskStore internal constructor(
var tasks = read()
var added = 0
for (preset in ScheduledPresets.all) {
- if (tasks.any { it.presetId == preset.id }) continue
+ if (tasks.any { it.presetId == preset.id } || isPromoted(preset.id)) continue
val sameName = tasks.firstOrNull { it.name == preset.name }
if (sameName != null) {
markSeeded(preset.id, sameName.id)
@@ -172,17 +173,21 @@ class ScheduledTaskStore internal constructor(
/**
* Stops treating [presetId] as an example: called when the user turns it on
- * or saves an edit. The example is theirs now, so neither seeding nor the
- * restore button may drag it back. The seeded marker stays, which is what
- * keeps a promoted example from being re-added as a duplicate.
+ * or saves an edit. A promoted example is theirs for good, so neither
+ * seeding nor restore may drag it back, even after they rename it. The
+ * seeded marker stays, which is what keeps it from being re-added.
*/
fun forgetPreset(presetId: String) = synchronized(LOCK) {
prefs.edit()
+ .putBoolean(promotedKey(presetId), true)
.remove(taskKey(presetId))
.apply { if (presetId == ScheduledPresets.MORNING_BRIEFING) remove(KEY_BRIEFING_TASK_ID) }
.apply()
}
+ /** True once the user has turned [presetId] into a task of their own. */
+ fun isPromoted(presetId: String): Boolean = prefs.getBoolean(promotedKey(presetId), false)
+
private fun isSeeded(presetId: String): Boolean =
prefs.getBoolean(seededKey(presetId), false) || legacySeeded(presetId)
@@ -206,6 +211,8 @@ class ScheduledTaskStore internal constructor(
private fun seededKey(presetId: String) = "preset_seeded_$presetId"
+ private fun promotedKey(presetId: String) = "preset_promoted_$presetId"
+
private fun taskKey(presetId: String) = "preset_task_$presetId"
fun delete(id: String) {
diff --git a/app/src/main/java/com/gotcha/ui/ChatScreen.kt b/app/src/main/java/com/gotcha/ui/ChatScreen.kt
index 234e058..5d12294 100644
--- a/app/src/main/java/com/gotcha/ui/ChatScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/ChatScreen.kt
@@ -428,12 +428,19 @@ fun ChatScreen(
showMemory = showMemoryIntro,
showSchedule = showScheduleIntro,
onMemory = {
+ // Both prompts need a write: memory saves a
+ // note, scheduling creates a task. Monitor
+ // would refuse them, so pick the mode the
+ // chip is asking for; the selector above
+ // shows the change.
+ onSetAgent(AgentMode.OPERATOR)
input = context.getString(R.string.starter_remember_this_template)
inputWasVoice = false
featureIntro.markSeen(FeatureIntroStore.MEMORY)
showMemoryIntro = false
},
onSchedule = {
+ onSetAgent(AgentMode.OPERATOR)
input = context.getString(R.string.starter_every_morning_template)
inputWasVoice = false
featureIntro.markSeen(FeatureIntroStore.SCHEDULE)
diff --git a/app/src/main/java/com/gotcha/ui/MessageBubble.kt b/app/src/main/java/com/gotcha/ui/MessageBubble.kt
index 8e9ca4f..0d625b6 100644
--- a/app/src/main/java/com/gotcha/ui/MessageBubble.kt
+++ b/app/src/main/java/com/gotcha/ui/MessageBubble.kt
@@ -248,11 +248,16 @@ fun MessageBubble(
// vault says so, once, under the tool row. Read from the
// ledger text, so it works on chats saved before it existed.
if (isTool) {
- val memoryWrite = remember(displayText) {
- secondBrainWriteOf(
- displayText,
+ // canonicalPath, because the file tools print the
+ // canonical target and a symlinked root would not
+ // prefix-match otherwise.
+ val memoryRoot = remember {
+ runCatching { GotchaStorage.memoryRoot().canonicalPath }.getOrElse {
runCatching { GotchaStorage.memoryRoot().absolutePath }.getOrDefault("")
- )
+ }
+ }
+ val memoryWrite = remember(displayText, memoryRoot) {
+ secondBrainWriteOf(displayText, memoryRoot)
}
if (memoryWrite != null) {
Row(
diff --git a/app/src/main/java/com/gotcha/ui/ScheduledTasksScreen.kt b/app/src/main/java/com/gotcha/ui/ScheduledTasksScreen.kt
index 54bc1ac..b7bf262 100644
--- a/app/src/main/java/com/gotcha/ui/ScheduledTasksScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/ScheduledTasksScreen.kt
@@ -234,7 +234,9 @@ fun ScheduledTasksScreen(onBack: () -> Unit, onOpenChat: (String) -> Unit) {
onOpenChat = onOpenChat
)
}
- HorizontalDivider()
+ // Only a boundary between the two groups; with no tasks below, the
+ // divider before the buttons already closes the list.
+ if (mine.isNotEmpty()) HorizontalDivider()
}
if (mine.isNotEmpty()) {
if (examples.isNotEmpty()) {
diff --git a/app/src/test/java/com/gotcha/data/SecondBrainSummaryTest.kt b/app/src/test/java/com/gotcha/data/SecondBrainSummaryTest.kt
index ce30c1a..8176832 100644
--- a/app/src/test/java/com/gotcha/data/SecondBrainSummaryTest.kt
+++ b/app/src/test/java/com/gotcha/data/SecondBrainSummaryTest.kt
@@ -41,6 +41,11 @@ class SecondBrainSummaryTest {
assertFalse(snapshot(notes = 1).summary().empty)
}
+ @Test
+ fun `a fifth area ends the empty state`() {
+ assertFalse(snapshot(areas = 5).summary().empty)
+ }
+
@Test
fun `a person ends the empty state too`() {
assertFalse(snapshot(people = 1).summary().empty)
diff --git a/app/src/test/java/com/gotcha/data/SecondBrainWriteTest.kt b/app/src/test/java/com/gotcha/data/SecondBrainWriteTest.kt
index ac2dad9..6740674 100644
--- a/app/src/test/java/com/gotcha/data/SecondBrainWriteTest.kt
+++ b/app/src/test/java/com/gotcha/data/SecondBrainWriteTest.kt
@@ -18,7 +18,8 @@ class SecondBrainWriteTest {
@Test
fun `an edit inside the vault says updated`() {
- val line = "edit: Replaced 1 occurrence in 'MEMORY.md' (resolved: $root/MEMORY.md)."
+ // EditTool prints the canonical target, not a resolved marker.
+ val line = "edit: Replaced 1 occurrence in '$root/MEMORY.md'.\n- old\n+ new"
assertEquals(SecondBrainWrite.UPDATED, secondBrainWriteOf(line, root))
}
diff --git a/app/src/test/java/com/gotcha/scheduled/ScheduledTaskStoreTest.kt b/app/src/test/java/com/gotcha/scheduled/ScheduledTaskStoreTest.kt
index 657613b..586b54b 100644
--- a/app/src/test/java/com/gotcha/scheduled/ScheduledTaskStoreTest.kt
+++ b/app/src/test/java/com/gotcha/scheduled/ScheduledTaskStoreTest.kt
@@ -173,11 +173,22 @@ class ScheduledTaskStoreTest {
store.update(evening.id) { it.copy(presetId = null, enabled = true) }
store.forgetPreset(ScheduledPresets.EVENING_WRAP_UP)
+ // Renaming is the main reason to customize an example; it must not
+ // make the example look missing again.
+ store.update(evening.id) { it.copy(name = "My evening") }
+ assertTrue(store.missingPresets().none { it.id == ScheduledPresets.EVENING_WRAP_UP })
assertTrue(store.seedPresets("/mem", now, zone).isEmpty())
assertEquals(0, store.restorePresets("/mem", now, zone))
- assertEquals(1, store.all().count { it.name == evening.name })
+ assertEquals(1, store.all().count { it.name == "My evening" })
+ assertEquals(0, store.all().count { it.name == evening.name })
assertEquals(null, store.get(evening.id)!!.presetId)
+
+ // Deleting a promoted example does not bring it back either: it stopped
+ // being an example when the user made it theirs.
+ store.delete(evening.id)
+ assertTrue(store.missingPresets().none { it.id == ScheduledPresets.EVENING_WRAP_UP })
+ assertEquals(0, store.restorePresets("/mem", now, zone))
}
@Test