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.
style(agent): satisfy detekt on the #143 review fixes
Durganshud40cf15a08d0
diff --git a/app/src/main/java/com/gotcha/tools/SubAgentSession.kt b/app/src/main/java/com/gotcha/tools/SubAgentSession.ktindex b222e62..081cdce 100644--- a/app/src/main/java/com/gotcha/tools/SubAgentSession.kt+++ b/app/src/main/java/com/gotcha/tools/SubAgentSession.kt@@ -9,6 +9,7 @@ import com.gotcha.connectors.ConnectorRegistryimport com.gotcha.data.Settingsimport com.gotcha.llm.ChatMessageimport com.gotcha.llm.LLMClient+import com.gotcha.llm.ToolCallimport com.gotcha.llm.withValidToolCallArgumentsimport com.gotcha.util.GotchaLogimport kotlinx.coroutines.CancellationException@@ -132,11 +133,7 @@ class SubAgentSession(for (call in toolCalls) {val toolName = call.function.nameblockedOn?.let { permission ->- val skipped = "Not run: an earlier call in this step needs $permission, " +- "which is not granted."- history.add(ChatMessage(role = "tool", content = JsonPrimitive(skipped), toolCallId = call.id))- collectedSteps.add("$toolName → skipped: needs $permission")- onStep(toolName, "completed", "skipped: needs $permission")+ skipCall(call, permission, history)continue}onStep(toolName, "running", "")@@ -181,14 +178,7 @@ class SubAgentSession())- // Report reasoning text that sometimes comes alongside tool calls- if (message.hasText && collectedSteps.none { it.startsWith("reasoning:") }) {- val thought = message.textContent.take(120)- if (thought.isNotBlank()) {- collectedSteps.add("reasoning: $thought")- onStep("reasoning", "completed", thought)- }- }+ reportReasoning(message)}if (activeTokenCount > settings.maxContextTokens * 0.8) {@@ -200,6 +190,25 @@ class SubAgentSession(return SubAgentOutput(msg, collectedSteps.toList())}+ /** Reports reasoning text that sometimes comes alongside tool calls, once per run. */+ private fun reportReasoning(message: ChatMessage) {+ if (!message.hasText || collectedSteps.any { it.startsWith("reasoning:") }) return+ val thought = message.textContent.take(120)+ if (thought.isNotBlank()) {+ collectedSteps.add("reasoning: $thought")+ onStep("reasoning", "completed", thought)+ }+ }++ /** Answers [call] without running it, as one planned after [permission] was refused. */+ private fun skipCall(call: ToolCall, permission: String, history: MutableList<ChatMessage>) {+ val toolName = call.function.name+ val skipped = "Not run: an earlier call in this step needs $permission, which is not granted."+ history.add(ChatMessage(role = "tool", content = JsonPrimitive(skipped), toolCallId = call.id))+ collectedSteps.add("$toolName → skipped: needs $permission")+ onStep(toolName, "completed", "skipped: needs $permission")+ }+/*** Puts a tool's missing permission in front of the user, the way the main* agent does, instead of leaving it as prose in this session's privatediff --git a/app/src/test/java/com/gotcha/agent/ChatViewModelPermissionGateTest.kt b/app/src/test/java/com/gotcha/agent/ChatViewModelPermissionGateTest.ktindex 06db061..007a049 100644--- a/app/src/test/java/com/gotcha/agent/ChatViewModelPermissionGateTest.kt+++ b/app/src/test/java/com/gotcha/agent/ChatViewModelPermissionGateTest.kt@@ -7,9 +7,9 @@ import com.gotcha.data.Settingsimport com.gotcha.data.SettingsRepositoryimport com.gotcha.testsupport.FakeAndroidKeyStoreimport kotlinx.coroutines.async-import kotlinx.coroutines.launchimport kotlinx.coroutines.jobimport kotlinx.coroutines.joinAll+import kotlinx.coroutines.launchimport kotlinx.coroutines.test.StandardTestDispatcherimport kotlinx.coroutines.test.advanceTimeByimport kotlinx.coroutines.test.resetMain@@ -134,28 +134,29 @@ class ChatViewModelPermissionGateTest {}@Test- fun `a special access raised behind another app opens its Settings screen once Gotcha is back`() = runTest(dispatcher) {- // App navigation stops on a missing access with another app in front.- // Settings can't be opened from there, so the ask waits for onStart- // instead of being dropped or blocked (issue #133).- val delivered = mutableListOf<String>()- val collector = launch { viewModel.permissionRequests.collect { delivered += it } }- runCurrent()- viewModel.setForeground(false)-- viewModel.runner.onPermissionRequest(com.gotcha.tools.ToolResult.ACCESSIBILITY_ACCESS)- runCurrent()- assertTrue("Settings was opened from behind another app: $delivered", delivered.isEmpty())-- viewModel.setForeground(true)- runCurrent()- assertEquals(listOf(com.gotcha.tools.ToolResult.ACCESSIBILITY_ACCESS), delivered)-- // Handed over once, not again on every return to the app.- viewModel.setForeground(false)- viewModel.setForeground(true)- runCurrent()- assertEquals(1, delivered.size)- collector.cancel()- }+ fun `a special access raised behind another app opens its Settings screen once Gotcha is back`() =+ runTest(dispatcher) {+ // App navigation stops on a missing access with another app in front.+ // Settings can't be opened from there, so the ask waits for onStart+ // instead of being dropped or blocked (issue #133).+ val delivered = mutableListOf<String>()+ val collector = launch { viewModel.permissionRequests.collect { delivered += it } }+ runCurrent()+ viewModel.setForeground(false)++ viewModel.runner.onPermissionRequest(com.gotcha.tools.ToolResult.ACCESSIBILITY_ACCESS)+ runCurrent()+ assertTrue("Settings was opened from behind another app: $delivered", delivered.isEmpty())++ viewModel.setForeground(true)+ runCurrent()+ assertEquals(listOf(com.gotcha.tools.ToolResult.ACCESSIBILITY_ACCESS), delivered)++ // Handed over once, not again on every return to the app.+ viewModel.setForeground(false)+ viewModel.setForeground(true)+ runCurrent()+ assertEquals(1, delivered.size)+ collector.cancel()+ }}