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 review: adopt same-name examples, key history rows, check area hubs

Rishabh Bajpaibd2503348b51
diff --git a/app/src/main/java/com/gotcha/data/MemoryStore.kt b/app/src/main/java/com/gotcha/data/MemoryStore.kt
index d3ff748..0fc7afc 100644
--- a/app/src/main/java/com/gotcha/data/MemoryStore.kt
+++ b/app/src/main/java/com/gotcha/data/MemoryStore.kt
@@ -103,6 +103,17 @@ object MemoryStore {
fun isPristineMemoryIndex(content: String): Boolean =
content.trim() == defaultMemoryIndex().trim()
+ /**
+ * True while an area hub still holds only its generated heading and the one
+ * line under it. The frontmatter date changes every time a hub is created,
+ * so only the body is compared; a third non-blank line is something the
+ * user or agent added.
+ */
+ fun isPristineArea(content: String): Boolean {
+ val body = content.substringAfter("\n---\n", content)
+ return body.lines().count { it.isNotBlank() } <= 2
+ }
+
/** Rewrites user.md from Personal Info. Called on startup and on profile updates. */
fun syncUserFile(settings: Settings) {
runCatching {
diff --git a/app/src/main/java/com/gotcha/data/SecondBrainSummary.kt b/app/src/main/java/com/gotcha/data/SecondBrainSummary.kt
index 6bb780e..6d35924 100644
--- a/app/src/main/java/com/gotcha/data/SecondBrainSummary.kt
+++ b/app/src/main/java/com/gotcha/data/SecondBrainSummary.kt
@@ -25,5 +25,6 @@ fun MemoryStore.SecondBrainSnapshot.summary(): SecondBrainSummary = SecondBrainS
people.isEmpty() &&
raw.isEmpty() &&
(soul == null || MemoryStore.isPristineSoul(soul.content)) &&
- (memoryIndex == null || MemoryStore.isPristineMemoryIndex(memoryIndex.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 a461454..2bb3d33 100644
--- a/app/src/main/java/com/gotcha/scheduled/ScheduledTaskStore.kt
+++ b/app/src/main/java/com/gotcha/scheduled/ScheduledTaskStore.kt
@@ -86,26 +86,52 @@ class ScheduledTaskStore internal constructor(
val created = mutableListOf<ScheduledTask>()
for (preset in ScheduledPresets.all) {
if (tasks.any { it.presetId == preset.id }) continue
- // The briefing seeded before examples existed is tracked under its
- // own key, so it is adopted rather than duplicated once.
- val trackedId = prefs.getString(taskKey(preset.id), null) ?: legacyTaskId(preset.id)
- val tracked = trackedId?.let { id -> tasks.firstOrNull { it.id == id } }
- if (tracked != null) {
- tasks = tasks.map { if (it.id == tracked.id) it.copy(presetId = preset.id) else it }
- markSeeded(preset.id, tracked.id)
- continue
- }
- if (isSeeded(preset.id)) continue
- val task = ScheduledPresets.task(preset, memoryRoot, localNow)
- .copy(id = UUID.randomUUID().toString(), createdAt = now, presetId = preset.id)
- tasks = tasks + task
- created += task
- markSeeded(preset.id, task.id)
+ val seeded = seedOne(preset, tasks, memoryRoot, localNow, now)
+ tasks = seeded.tasks
+ seeded.created?.let { created += it }
}
if (created.isNotEmpty() || tasks != existing) write(tasks)
created
}
+ /**
+ * One preset's place in [tasks]: already tracked, already seen, a task the
+ * user made under the same name, or a new paused copy. Never returns a
+ * second copy of anything.
+ */
+ private fun seedOne(
+ preset: ScheduledPreset,
+ tasks: List<ScheduledTask>,
+ memoryRoot: String,
+ localNow: LocalDateTime,
+ now: Long
+ ): PresetSeed {
+ // The briefing seeded before examples existed is tracked under its
+ // own key, so it is adopted rather than duplicated once.
+ val trackedId = prefs.getString(taskKey(preset.id), null) ?: legacyTaskId(preset.id)
+ val tracked = trackedId?.let { id -> tasks.firstOrNull { it.id == id } }
+ if (tracked != null) {
+ markSeeded(preset.id, tracked.id)
+ return PresetSeed(tasks.map { if (it.id == tracked.id) it.copy(presetId = preset.id) else it })
+ }
+ if (isSeeded(preset.id)) return PresetSeed(tasks)
+ // A task the user already made with the example's name is theirs: adopt
+ // it as the example instead of adding a duplicate beside it. Only on the
+ // first seed, so promoting or deleting later stays put.
+ val sameName = tasks.firstOrNull { it.name == preset.name }
+ if (sameName != null) {
+ markSeeded(preset.id, sameName.id)
+ return PresetSeed(tasks.map { if (it.id == sameName.id) it.copy(presetId = preset.id) else it })
+ }
+ val task = ScheduledPresets.task(preset, memoryRoot, localNow)
+ .copy(id = UUID.randomUUID().toString(), createdAt = now, presetId = preset.id)
+ markSeeded(preset.id, task.id)
+ return PresetSeed(tasks + task, task)
+ }
+
+ /** The task list after seeding one preset, plus the task it created, if any. */
+ private data class PresetSeed(val tasks: List<ScheduledTask>, val created: ScheduledTask? = null)
+
/**
* Examples that are not in [tasks] at all: what the restore button would
* add back. A task carrying the example's name counts as present, since
diff --git a/app/src/main/java/com/gotcha/ui/ScheduledTasksScreen.kt b/app/src/main/java/com/gotcha/ui/ScheduledTasksScreen.kt
index e8f5b13..54bc1ac 100644
--- a/app/src/main/java/com/gotcha/ui/ScheduledTasksScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/ScheduledTasksScreen.kt
@@ -126,8 +126,10 @@ fun ScheduledTasksScreen(onBack: () -> Unit, onOpenChat: (String) -> Unit) {
}
// Examples stay above the user's own tasks until turned on or edited, at
// which point the task stops carrying a preset id and moves down.
- val examples = tasks.filter { it.presetId != null }
- val mine = tasks.filter { it.presetId == null }
+ val examples = tasks.filter { it.presetId != null && !it.enabled }
+ // An enabled task stays the user's own even if it was adopted as an example
+ // (a task they already had under the example's name).
+ val mine = tasks.filter { it.presetId == null || it.enabled }
val missingExamples = remember(tasks) { store.missingPresets() }
val canRunUnattended = remember(tick) { ScheduledTaskScheduler.canRunUnattended(context) }
@@ -418,7 +420,9 @@ private fun TaskRow(
onOpenChat: (String) -> Unit
) {
val context = LocalContext.current
- var showHistory by remember { mutableStateOf(false) }
+ // Keyed by task: promoting or deleting a row moves the others, and an
+ // unkeyed flag would open the wrong task's history.
+ var showHistory by remember(task.id) { mutableStateOf(false) }
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
Row(verticalAlignment = Alignment.CenterVertically) {
Column(modifier = Modifier.weight(1f)) {
diff --git a/app/src/test/java/com/gotcha/data/SecondBrainSummaryTest.kt b/app/src/test/java/com/gotcha/data/SecondBrainSummaryTest.kt
index 0f9b819..ce30c1a 100644
--- a/app/src/test/java/com/gotcha/data/SecondBrainSummaryTest.kt
+++ b/app/src/test/java/com/gotcha/data/SecondBrainSummaryTest.kt
@@ -56,6 +56,33 @@ class SecondBrainSummaryTest {
assertFalse(snapshot(memoryIndex = "# MEMORY\n\n- Gym: notes/gym.md").summary().empty)
}
+ @Test
+ fun `an edited area hub is not empty even without notes`() {
+ val withArea = MemoryStore.SecondBrainSnapshot(
+ available = true,
+ soul = null,
+ memoryIndex = null,
+ userCard = null,
+ areas = listOf(
+ MemoryStore.BrainFile(
+ "work.md",
+ "---\ntitle: Work\ntype: area\n---\n\n# Work\n\nProjects.\n\n- Alpha ships Friday",
+ false
+ )
+ ),
+ people = emptyList(),
+ notes = emptyList()
+ )
+
+ assertFalse(withArea.summary().empty)
+ }
+
+ @Test
+ fun `the generated area hub is pristine`() {
+ val generated = "---\ntitle: Work\ntype: area\n---\n\n# Work\n\nProjects and work threads."
+ assertTrue(MemoryStore.isPristineArea(generated))
+ }
+
@Test
fun `counts follow the snapshot`() {
val summary = snapshot(notes = 3, people = 2, areas = 4).summary()
diff --git a/app/src/test/java/com/gotcha/scheduled/ScheduledTaskStoreTest.kt b/app/src/test/java/com/gotcha/scheduled/ScheduledTaskStoreTest.kt
index a0e5c4d..657613b 100644
--- a/app/src/test/java/com/gotcha/scheduled/ScheduledTaskStoreTest.kt
+++ b/app/src/test/java/com/gotcha/scheduled/ScheduledTaskStoreTest.kt
@@ -133,6 +133,19 @@ class ScheduledTaskStoreTest {
assertEquals(1, store.all().count { it.name == MorningBriefing.TEMPLATE_NAME })
}
+ @Test
+ fun `a task the user already named like an example is adopted`() {
+ val zone = java.time.ZoneId.of("UTC")
+ val now = java.time.LocalDateTime.parse("2026-10-29T22:15").atZone(zone).toInstant().toEpochMilli()
+ store.put(task("u").copy(name = "Weekly review"))
+
+ val created = store.seedPresets("/mem", now, zone)
+
+ assertEquals(ScheduledPresets.all.size - 1, created.size)
+ assertEquals(ScheduledPresets.WEEKLY_REVIEW, store.get("u")!!.presetId)
+ assertEquals(1, store.all().count { it.name == "Weekly review" })
+ }
+
@Test
fun `a deleted example stays gone until examples are restored`() {
val zone = java.time.ZoneId.of("UTC")