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.

fix: address Copilot review feedback on PR #50

Durganshu Mishra7b0d8c9bf1c4
diff --git a/RUNNING.md b/RUNNING.md
index f7c89e8..0cd05cb 100644
--- a/RUNNING.md
+++ b/RUNNING.md
@@ -79,7 +79,7 @@ All Gotcha-managed files on shared storage live under one root, `data/GotchaStor
/storage/emulated/0/Gotcha/
chats/<Slug_shortId>/ <- agent working dir (cwd for file tools)
Pictures/ <- camera captures
- Recordings/ <- audio captures
+ Recordings/ <- audio captures written via an explicit output_path
Screenshots/ <- agent read_screen_raw captures
.debug/ <- perception overlay dumps
calls/<sessionId>/ <- voice-call working dirs
@@ -88,6 +88,10 @@ All Gotcha-managed files on shared storage live under one root, `data/GotchaStor
Downloads/
```
+Audio recordings started without an explicit `output_path` are the one exception: they go to the
+device's public `Recordings/` folder (via MediaStore on API 29+) so they are findable like any
+other device recording, independent of which chat produced them.
+
Chat folders are named `slug(title)_<first 8 chars of the session UUID>` and renamed in place
when the title becomes known. Deleting a chat moves its working directory to `old_chats/` instead
of deleting it. See `STORAGE_PLAN.md` for the full rationale.
diff --git a/app/src/main/java/com/gotcha/agent/ChatViewModel.kt b/app/src/main/java/com/gotcha/agent/ChatViewModel.kt
index 3fa20dc..4c505f6 100644
--- a/app/src/main/java/com/gotcha/agent/ChatViewModel.kt
+++ b/app/src/main/java/com/gotcha/agent/ChatViewModel.kt
@@ -661,28 +661,37 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), A
/**
* One-time migration: rename any pre-existing UUID-named chat working dirs
- * to the readable "Slug_shortId" scheme. Guarded so it only ever runs once.
+ * to the readable "Slug_shortId" scheme. The "done" flag is only persisted
+ * once every session was handled, so a partial migration (a rename blocked by
+ * a missing storage grant, say) is retried on the next launch instead of
+ * leaving UUID-named dirs stranded forever.
*/
private suspend fun migrateChatDirsIfNeeded() {
val prefs = settingsRepository.prefs
if (prefs.getBoolean(MIGRATED_CHAT_DIRS_KEY, false)) return
val sessions = historyRepository.listSessions()
val chatsRoot = com.gotcha.data.GotchaStorage.chatsRoot()
+ var allMigrated = true
for (session in sessions) {
try {
val rawDir = java.io.File(chatsRoot, session.id)
- if (rawDir.exists() && rawDir.isDirectory) {
- val target = java.io.File(
- chatsRoot,
- com.gotcha.data.GotchaStorage.chatDirName(session.title, session.id)
- )
- rawDir.renameTo(target)
+ if (!rawDir.exists() || !rawDir.isDirectory) continue
+ val target = java.io.File(
+ chatsRoot,
+ com.gotcha.data.GotchaStorage.chatDirName(session.title, session.id)
+ )
+ // An already-migrated target is not a failure: keep the raw dir
+ // out of the way rather than clobbering the renamed one.
+ if (!rawDir.renameTo(target) && !target.isDirectory) {
+ allMigrated = false
+ android.util.Log.w("Gotcha", "migrateChatDirsIfNeeded: rename failed for ${session.id}")
}
} catch (e: Exception) {
+ allMigrated = false
android.util.Log.w("Gotcha", "migrateChatDirsIfNeeded: failed for ${session.id}", e)
}
}
- prefs.edit().putBoolean(MIGRATED_CHAT_DIRS_KEY, true).apply()
+ if (allMigrated) prefs.edit().putBoolean(MIGRATED_CHAT_DIRS_KEY, true).apply()
}
fun refreshSessions() {
diff --git a/app/src/main/java/com/gotcha/tools/FileResolver.kt b/app/src/main/java/com/gotcha/tools/FileResolver.kt
index 3f293c5..90dd12d 100644
--- a/app/src/main/java/com/gotcha/tools/FileResolver.kt
+++ b/app/src/main/java/com/gotcha/tools/FileResolver.kt
@@ -38,7 +38,18 @@ class FileResolver(private val context: Context) {
"This operation needs storage write permission. " +
"Go to Settings → Permissions → Storage Write and grant it, then ask again."
- var WORKING_DIR_BASE: String = com.gotcha.data.GotchaStorage.root().absolutePath
+ private var workingDirOverride: String? = null
+
+ /**
+ * Working directory for relative paths. Resolved lazily rather than at
+ * class-load time: touching [com.gotcha.data.GotchaStorage.root] pulls in
+ * `Environment.getExternalStorageDirectory()`, which throws under the
+ * android.jar stubs used by JVM unit tests, and would otherwise pin a
+ * value before [com.gotcha.agent.AgentEngine] sets the per-session dir.
+ */
+ var WORKING_DIR_BASE: String
+ get() = workingDirOverride ?: com.gotcha.data.GotchaStorage.root().absolutePath
+ set(value) { workingDirOverride = value }
fun formatSizeStatic(bytes: Long): String = when {
bytes >= 1024L * 1024 * 1024 -> "%.1f GB".format(bytes.toDouble() / (1024 * 1024 * 1024))