From 77fffa7592fcdf5cf2a1bb14912a859f5515688c Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:42:17 -0500 Subject: [PATCH] Show recent photos in place of the keyboard when attaching to the agent (#3702) * Show recent photos in place of the keyboard in the agent composer The attach button opens a tray, at the keyboard's height, of the device's recent pictures; a tap attaches or detaches one. The tray also opens the system file picker and asks for photo access when the app has none. * Agent instructions: manifest needs an APK; the agent resumes after a Lab build restart * Skip the tray's back handler where the host has no back dispatcher * Offer the photo tray in windows that cannot open pickers, such as the floating pet * Fix the tray's permission request for windows without a registry * Move the game screenshot button into the photo tray * Name only the model in the agent's compact chip * Keep the session drawer open while the tray's picker or photo permission prompt is up * Address review: tray height on short screens, denied photo access, kept photo marks, tile labels, Lab build refusals * Keep tray photos being copied across the tray closing * Let a tray photo copy clear only its own in-progress marker * Review: one attachment file per copy, photo tile labels, superseded copies attach nothing * Drop tray photo copies still running when the message is sent --- app/src/main/AndroidManifest.xml | 2 + .../launcher/agent/AgentAttachments.kt | 19 +- .../com/droiddeck/launcher/ui/AgentPage.kt | 112 +++---- .../droiddeck/launcher/ui/AgentPhotoTray.kt | 280 ++++++++++++++++++ app/src/main/res/values-ar/strings.xml | 5 + app/src/main/res/values-b+es+419/strings.xml | 5 + app/src/main/res/values-bg/strings.xml | 5 + app/src/main/res/values-cs/strings.xml | 5 + app/src/main/res/values-da/strings.xml | 5 + app/src/main/res/values-de/strings.xml | 5 + app/src/main/res/values-el/strings.xml | 5 + app/src/main/res/values-es/strings.xml | 5 + app/src/main/res/values-fi/strings.xml | 5 + app/src/main/res/values-fr/strings.xml | 5 + app/src/main/res/values-hi/strings.xml | 5 + app/src/main/res/values-hu/strings.xml | 5 + app/src/main/res/values-in/strings.xml | 5 + app/src/main/res/values-it/strings.xml | 5 + app/src/main/res/values-ja/strings.xml | 5 + app/src/main/res/values-ko/strings.xml | 5 + app/src/main/res/values-ms/strings.xml | 5 + app/src/main/res/values-nb/strings.xml | 5 + app/src/main/res/values-nl/strings.xml | 5 + app/src/main/res/values-pl/strings.xml | 5 + app/src/main/res/values-pt-rPT/strings.xml | 5 + app/src/main/res/values-pt/strings.xml | 5 + app/src/main/res/values-ro/strings.xml | 5 + app/src/main/res/values-ru/strings.xml | 5 + app/src/main/res/values-sv/strings.xml | 5 + app/src/main/res/values-th/strings.xml | 5 + app/src/main/res/values-tr/strings.xml | 5 + app/src/main/res/values-uk/strings.xml | 5 + app/src/main/res/values-vi/strings.xml | 5 + app/src/main/res/values-zh-rCN/strings.xml | 5 + app/src/main/res/values-zh-rHK/strings.xml | 5 + app/src/main/res/values-zh-rTW/strings.xml | 5 + app/src/main/res/values/strings.xml | 5 + tools/agent/AGENTS.md | 9 +- 38 files changed, 526 insertions(+), 61 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/ui/AgentPhotoTray.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5db5b11509..4211f6bbc5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -40,6 +40,8 @@ + + diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentAttachments.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentAttachments.kt index 96ddf0057a..9c9dd5c150 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentAttachments.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentAttachments.kt @@ -22,6 +22,12 @@ object AgentAttachments { /** True while the file picker is open over a session: it answers the drawer's agent page, so the drawer must stay. */ @Volatile var picking = false + /** Launches a system screen that answers the agent page, keeping the drawer for it; the result callback clears [picking]. */ + fun pick(launch: () -> Unit) { + picking = true + if (runCatching(launch).isFailure) picking = false + } + private const val NEW = "new" private const val GUEST_DIR = "/root/.cache/droiddeck/attachments" private val IMAGE = setOf("png", "jpg", "jpeg", "webp", "gif", "bmp") @@ -38,14 +44,17 @@ object AgentAttachments { val folder = chat ?: NEW val dir = File(hostDir(app), folder).apply { mkdirs() } return uris.mapNotNull { uri -> + var target: File? = null runCatching { val name = displayName(app, uri).replace(Regex("[^A-Za-z0-9._-]"), "_").ifEmpty { "file" } - var target = File(dir, name) + var candidate = File(dir, name) var n = 1 - while (target.exists()) target = File(dir, "${name.substringBeforeLast('.')}-${n++}${name.substringAfterLast('.', "").let { if (it.isEmpty()) "" else ".$it" }}") - app.contentResolver.openInputStream(uri)!!.use { input -> target.outputStream().use { input.copyTo(it) } } - "$GUEST_DIR/$folder/${target.name}" - }.getOrNull() + // Created atomically, so copies running side by side never pick the same name. + while (!candidate.createNewFile()) candidate = File(dir, "${name.substringBeforeLast('.')}-${n++}${name.substringAfterLast('.', "").let { if (it.isEmpty()) "" else ".$it" }}") + target = candidate + app.contentResolver.openInputStream(uri)!!.use { input -> candidate.outputStream().use { input.copyTo(it) } } + "$GUEST_DIR/$folder/${candidate.name}" + }.onFailure { target?.delete() }.getOrNull() } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/AgentPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/AgentPage.kt index 44f4d4bc90..b2793e5ba1 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/AgentPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/AgentPage.kt @@ -5,7 +5,9 @@ import android.content.ContextWrapper import android.os.Build import android.view.KeyEvent import android.view.WindowManager +import androidx.activity.compose.BackHandler import androidx.activity.compose.LocalActivityResultRegistryOwner +import androidx.activity.compose.LocalOnBackPressedDispatcherOwner import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.animation.expandVertically @@ -50,12 +52,12 @@ import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.outlined.Send import androidx.compose.material.icons.outlined.Extension -import androidx.compose.material.icons.outlined.PhotoCamera import androidx.compose.material.icons.outlined.MicOff import androidx.compose.material.icons.outlined.Mic import androidx.compose.material.icons.outlined.Add import androidx.compose.material.icons.outlined.ArrowDownward import androidx.compose.material.icons.outlined.AttachFile +import androidx.compose.material.icons.outlined.Keyboard import androidx.compose.material.icons.outlined.Terminal import androidx.compose.material.icons.outlined.Build import androidx.compose.material.icons.outlined.Close @@ -79,6 +81,7 @@ import androidx.compose.runtime.MutableState import androidx.compose.runtime.Stable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.mutableStateMapOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope @@ -108,6 +111,7 @@ import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.platform.LocalView import androidx.compose.ui.platform.testTag @@ -301,7 +305,7 @@ private fun AgentPageContent( readingBack = false scope.launch { list.scrollToItem(maxOf(0, list.layoutInfo.totalItemsCount - 1), Int.MAX_VALUE / 2) } } - val hidden = !composer.focused && !composer.hasUnconsumedFocusRequest() && readingBack && AgentHost.entries.isNotEmpty() && + val hidden = !composer.focused && !composer.tray && !composer.hasUnconsumedFocusRequest() && readingBack && AgentHost.entries.isNotEmpty() && AgentHost.approvals.isEmpty() var listHeight by remember { mutableIntStateOf(0) } Box( @@ -319,6 +323,7 @@ private fun AgentPageContent( awaitEachGesture { awaitFirstDown(requireUnconsumed = false, pass = PointerEventPass.Initial) if (panel == AgentPanel.MODEL || panel == AgentPanel.USAGE) panel = AgentPanel.NONE + composer.tray = false // Forced: the unforced path walks the focus chain and throws ("ActiveParent with no focused child") when a tap lands while focus is moving. if (composer.focused) focusManager.clearFocus(force = true) } @@ -344,6 +349,12 @@ private fun AgentPageContent( @Stable private class ComposerState { var focused by mutableStateOf(false) + /** The photo tray stands in for the keyboard, at the height the keyboard last had. */ + var tray by mutableStateOf(false) + var keyboardHeight by mutableStateOf(0.dp) + /** Tray photos copied, or being copied, for this conversation, so reopening the tray keeps their marks and copies nothing twice. */ + val photoCopies = mutableStateMapOf() + val photosCopying = mutableStateMapOf() var focusRequests by mutableIntStateOf(0) private set private var consumedFocusRequests by mutableIntStateOf(0) @@ -390,7 +401,7 @@ private fun ModelChip(panel: AgentPanel, onPanel: (AgentPanel) -> Unit, firstCon .clickable { onPanel(AgentPanel.MODEL) }.padding(horizontal = 8.dp).testTag("agent-model"), ) { val mode = AgentHost.harness.permissions.drop(1).firstOrNull { it.id == AgentHost.permission }?.let { stringResource(it.label) } - val parts = if (compact) listOfNotNull(mode ?: model) + val parts = if (compact) listOf(model) else listOfNotNull( AgentHost.harness.name, model, AgentHost.effort, mode, stringResource(R.string.agent_plan_short).takeIf { AgentHost.plan && AgentHost.harness.plans }, @@ -748,6 +759,8 @@ private fun AgentComposer( if (text.isEmpty() && AgentAttachments.pending.isEmpty()) return@send AgentHost.send(context, text, AgentAttachments.pending.toList()) AgentAttachments.pending.clear() + composer.photosCopying.clear() + composer.tray = false onSent() } } @@ -813,7 +826,34 @@ private fun AgentEditor(composer: ComposerState, draftState: MutableState composer.keyboardHeight) composer.keyboardHeight = height + } + LaunchedEffect(hideAttach) { if (hideAttach) composer.tray = false } + LaunchedEffect(AgentHost.chat) { + composer.photoCopies.clear() + composer.photosCopying.clear() + } + // BackHandler throws where the host provides no back dispatcher: the front end and the floating pet. + if (LocalOnBackPressedDispatcherOwner.current != null) BackHandler(composer.tray) { composer.tray = false } + val focusManager = LocalFocusManager.current + val files = if (picks) rememberLauncherForActivityResult(ActivityResultContracts.OpenMultipleDocuments()) { + AgentAttachments.picking = false + attachUris(context, it) + } else null + val toggleTray = { + if (composer.tray) { + composer.tray = false + composer.open() + } else { + focusManager.clearFocus(force = true) + composer.tray = true + } + } BoxWithConstraints( Modifier.fillMaxWidth().padding(top = 8.dp).clip(Shape16).background(colors.surface) .border(if (focused) 2.dp else 1.dp, if (focused) pal.primary else pal.line, Shape16).padding(6.dp), @@ -841,6 +881,7 @@ private fun AgentEditor(composer: ComposerState, draftState: MutableState 0.dp) composer.keyboardHeight else 280.dp).coerceAtLeast(160.dp).coerceAtMost(most) + AgentPhotoTray(height, composer.photoCopies, composer.photosCopying, files?.let { { AgentAttachments.pick { it.launch(arrayOf("*/*")) } } }) + } } /** @@ -974,53 +1018,15 @@ private fun VoiceButton(voice: AgentVoice, onStart: () -> Unit, onSend: () -> Un } } -/** Attaches what the running game shows, taken from its own surface so nothing drawn over it is in the picture. */ +/** Opens the photo tray in place of the keyboard; while it is open, brings the keyboard back. */ @Composable -private fun GameFrameButton() { - val context = LocalContext.current +private fun AttachButton(trayOpen: Boolean, onClick: () -> Unit) { val pal = LocalPalette.current - RoundButton(Icons.Outlined.PhotoCamera, stringResource(R.string.agent_attach_game), pal.surfaceVariant, pal.onBackground, "agent-game-frame") { - val grab = AgentAttachments.gameFrame ?: return@RoundButton - val chat = AgentHost.chat - grab frame@{ frame -> - if (frame == null) { - android.widget.Toast.makeText(context, R.string.agent_attach_game_failed, android.widget.Toast.LENGTH_SHORT).show() - return@frame - } - Thread({ - val path = AgentAttachments.saveFrame(context, chat, frame) - frame.recycle() - android.os.Handler(android.os.Looper.getMainLooper()).post { - when { - path == null -> android.widget.Toast.makeText(context, R.string.agent_attach_game_failed, android.widget.Toast.LENGTH_SHORT).show() - AgentHost.chat == chat -> AgentAttachments.pending.add(path) - else -> AgentAttachments.discard(context, listOf(path)) - } - } - }, "agent-game-frame").start() - } - } -} - -@Composable -private fun AttachButton() { - val context = LocalContext.current - val pal = LocalPalette.current - val picker = rememberLauncherForActivityResult(ActivityResultContracts.OpenMultipleDocuments()) { uris -> - AgentAttachments.picking = false - if (uris.isEmpty()) return@rememberLauncherForActivityResult - val chat = AgentHost.chat - Thread({ - val paths = AgentAttachments.copy(context, chat, uris) - android.os.Handler(android.os.Looper.getMainLooper()).post { - if (AgentHost.chat == chat) AgentAttachments.pending.addAll(paths) else AgentAttachments.discard(context, paths) - } - }, "agent-attach").start() - } - RoundButton(Icons.Outlined.AttachFile, stringResource(R.string.agent_attach), pal.surfaceVariant, pal.onBackground, "agent-attach") { - AgentAttachments.picking = true - if (runCatching { picker.launch(arrayOf("*/*")) }.isFailure) AgentAttachments.picking = false - } + RoundButton( + if (trayOpen) Icons.Outlined.Keyboard else Icons.Outlined.AttachFile, + stringResource(if (trayOpen) R.string.agent_keyboard else R.string.agent_attach), + if (trayOpen) pal.primary else pal.surfaceVariant, if (trayOpen) pal.onPrimary else pal.onBackground, "agent-attach", onClick = onClick, + ) } @Composable diff --git a/app/src/main/java/com/droiddeck/launcher/ui/AgentPhotoTray.kt b/app/src/main/java/com/droiddeck/launcher/ui/AgentPhotoTray.kt new file mode 100644 index 0000000000..d6c5dabe68 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/ui/AgentPhotoTray.kt @@ -0,0 +1,280 @@ +package com.droiddeck.launcher.ui + +import android.Manifest +import android.content.ContentUris +import android.content.Context +import android.content.Intent +import android.content.pm.PackageManager +import android.net.Uri +import android.os.Build +import android.os.Environment +import android.provider.MediaStore +import android.provider.Settings +import android.widget.Toast +import androidx.activity.compose.LocalActivityResultRegistryOwner +import androidx.activity.compose.rememberLauncherForActivityResult +import androidx.activity.result.contract.ActivityResultContracts +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.lazy.grid.GridCells +import androidx.compose.foundation.lazy.grid.GridItemSpan +import androidx.compose.foundation.lazy.grid.LazyVerticalGrid +import androidx.compose.foundation.lazy.grid.items +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.Check +import androidx.compose.material.icons.outlined.FolderOpen +import androidx.compose.material.icons.outlined.PhotoCamera +import androidx.compose.material.icons.outlined.PhotoLibrary +import androidx.compose.material3.Icon +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.runtime.snapshots.SnapshotStateMap +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalLifecycleOwner +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.semantics.contentDescription +import androidx.compose.ui.semantics.selected +import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleEventObserver +import coil.compose.AsyncImage +import coil.request.ImageRequest +import com.droiddeck.launcher.R +import com.droiddeck.launcher.agent.AgentAttachments +import com.droiddeck.launcher.agent.AgentHost +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +/** The device's photos, newest first, as MediaStore lets the app see them. */ +internal object AgentPhotos { + enum class Access { NONE, SELECTED, ALL } + + /** Android stops showing the request after repeated denials and answers it at once, so a denied request sends later ones to Settings. */ + var refused = false + + fun permissions(sdk: Int = Build.VERSION.SDK_INT): Array = when { + sdk >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE -> arrayOf(Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED) + sdk >= Build.VERSION_CODES.TIRAMISU -> arrayOf(Manifest.permission.READ_MEDIA_IMAGES) + else -> arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE) + } + + fun access(context: Context): Access { + fun granted(permission: String) = context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED + val all = permissions().first() + return when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && Environment.isExternalStorageManager() -> Access.ALL + granted(all) -> Access.ALL + Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && granted(Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED) -> Access.SELECTED + else -> Access.NONE + } + } + + class Photo(val uri: Uri, val name: String) + + fun recent(context: Context, limit: Int = 300): List = runCatching { + val images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI + context.contentResolver.query( + images, arrayOf(MediaStore.Images.Media._ID, MediaStore.Images.Media.DISPLAY_NAME), null, null, "${MediaStore.Images.Media.DATE_ADDED} DESC", + )?.use { c -> + buildList { + while (size < limit && c.moveToNext()) add(Photo(ContentUris.withAppendedId(images, c.getLong(0)), c.getString(1).orEmpty())) + } + }.orEmpty() + }.getOrDefault(emptyList()) +} + +/** + * Copies [uris] into the conversation's attachments off the main thread, then hands [onCopied] what was attached: nothing if the + * conversation changed meanwhile or [current] says the copy was superseded. + */ +internal fun attachUris(context: Context, uris: List, current: () -> Boolean = { true }, onCopied: (List>) -> Unit = {}) { + if (uris.isEmpty()) return + val chat = AgentHost.chat + Thread({ + val copied = uris.mapNotNull { uri -> AgentAttachments.copy(context, chat, listOf(uri)).firstOrNull()?.let { uri to it } } + android.os.Handler(android.os.Looper.getMainLooper()).post { + val paths = copied.map { it.second } + if (AgentHost.chat == chat && current()) { + AgentAttachments.pending.addAll(paths) + onCopied(copied) + } else { + AgentAttachments.discard(context, paths) + onCopied(emptyList()) + } + } + }, "agent-attach").start() +} + +/** Attaches what the running game shows, taken from its own surface so nothing drawn over it is in the picture. */ +private fun attachGameFrame(context: Context) { + val grab = AgentAttachments.gameFrame ?: return + val chat = AgentHost.chat + grab frame@{ frame -> + if (frame == null) { + Toast.makeText(context, R.string.agent_attach_game_failed, Toast.LENGTH_SHORT).show() + return@frame + } + Thread({ + val path = AgentAttachments.saveFrame(context, chat, frame) + frame.recycle() + android.os.Handler(android.os.Looper.getMainLooper()).post { + when { + path == null -> Toast.makeText(context, R.string.agent_attach_game_failed, Toast.LENGTH_SHORT).show() + AgentHost.chat == chat -> AgentAttachments.pending.add(path) + else -> AgentAttachments.discard(context, listOf(path)) + } + } + }, "agent-game-frame").start() + } +} + +/** Shown in place of the keyboard: recent photos to tap onto the message, and the system picker for anything else. */ +@Composable +internal fun AgentPhotoTray(height: Dp, copies: SnapshotStateMap, copying: SnapshotStateMap, onFiles: (() -> Unit)?) { + val context = LocalContext.current + val pal = LocalPalette.current + var access by remember { mutableStateOf(AgentPhotos.access(context)) } + var photos by remember { mutableStateOf?>(null) } + var reloads by remember { mutableStateOf(0) } + // A window no activity owns (the floating pet's chat) cannot ask for a permission, so it sends the user to the app's settings. + val launcher = if (LocalActivityResultRegistryOwner.current != null) { + rememberLauncherForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { + AgentAttachments.picking = false + access = AgentPhotos.access(context) + if (access == AgentPhotos.Access.NONE) AgentPhotos.refused = true + reloads++ + } + } else null + val request = { + if (launcher != null && !AgentPhotos.refused) { + AgentAttachments.pick { launcher.launch(AgentPhotos.permissions()) } + } else { + val details = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + context.packageName)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + runCatching { context.startActivity(details) } + } + Unit + } + // Access can change in Settings, and new pictures arrive, while the app is in the background. + val lifecycle = LocalLifecycleOwner.current.lifecycle + DisposableEffect(lifecycle) { + val observer = LifecycleEventObserver { _, event -> + if (event == Lifecycle.Event.ON_RESUME) { + access = AgentPhotos.access(context) + reloads++ + } + } + lifecycle.addObserver(observer) + onDispose { lifecycle.removeObserver(observer) } + } + LaunchedEffect(access, reloads) { + photos = if (access == AgentPhotos.Access.NONE) emptyList() else withContext(Dispatchers.IO) { AgentPhotos.recent(context) } + } + LazyVerticalGrid( + GridCells.Adaptive(96.dp), + Modifier.fillMaxWidth().height(height).padding(top = 8.dp).testTag("agent-photo-tray"), + horizontalArrangement = Arrangement.spacedBy(4.dp), + verticalArrangement = Arrangement.spacedBy(4.dp), + ) { + if (AgentAttachments.gameFrame != null) item { + TrayTile(Icons.Outlined.PhotoCamera, stringResource(R.string.agent_attach_game), "agent-game-frame") { attachGameFrame(context) } + } + if (onFiles != null) item { TrayTile(Icons.Outlined.FolderOpen, stringResource(R.string.agent_attach_files), "agent-attach-files", onFiles) } + if (access != AgentPhotos.Access.ALL) item { + TrayTile( + Icons.Outlined.PhotoLibrary, + stringResource(if (access == AgentPhotos.Access.NONE) R.string.agent_photos_allow else R.string.agent_photos_more), + "agent-photos-allow", + onClick = request, + ) + } + val list = photos + if (list != null && list.isEmpty() && access != AgentPhotos.Access.NONE) item(span = { GridItemSpan(maxLineSpan) }) { + Text( + stringResource(R.string.agent_photos_empty), fontSize = 13.sp, color = pal.onSurfaceVariant, textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth().padding(16.dp), + ) + } + items(list.orEmpty(), key = { it.uri.toString() }) { photo -> + val uri = photo.uri + val path = copies[uri] + val selected = path != null && path in AgentAttachments.pending + Box( + Modifier.aspectRatio(1f).clip(Shape12).background(pal.surfaceVariant) + .then(if (selected) Modifier.border(3.dp, pal.primary, Shape12) else Modifier) + .clickable { + when { + selected -> AgentAttachments.pending.remove(path) + path != null && AgentAttachments.host(context, path).exists() -> AgentAttachments.pending.add(path) + uri in copying -> Unit + else -> { + // Leaving the conversation clears the markers, so a copy started before that is no longer current even back in it. + val copy = Any() + copying[uri] = copy + attachUris(context, listOf(uri), current = { copying[uri] === copy }) { copied -> + copied.forEach { (u, p) -> copies[u] = p } + if (copying[uri] === copy) copying.remove(uri) + } + } + } + }.semantics { + contentDescription = photo.name + this.selected = selected + }.testTag("agent-photo"), + ) { + AsyncImage( + model = ImageRequest.Builder(context).data(uri).size(320).build(), contentDescription = null, + contentScale = ContentScale.Crop, modifier = Modifier.fillMaxSize(), + ) + if (selected) Box( + contentAlignment = Alignment.Center, + modifier = Modifier.align(Alignment.TopEnd).padding(6.dp).size(22.dp).clip(CircleShape).background(pal.primary), + ) { + Icon(Icons.Outlined.Check, null, tint = pal.onPrimary, modifier = Modifier.size(16.dp)) + } + } + } + } +} + +@Composable +private fun TrayTile(icon: ImageVector, label: String, tag: String, onClick: () -> Unit) { + val pal = LocalPalette.current + Column( + horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center, + modifier = Modifier.aspectRatio(1f).clip(Shape12).background(pal.surfaceVariant).clickable(onClick = onClick).padding(8.dp).testTag(tag), + ) { + Icon(icon, null, tint = pal.onBackground, modifier = Modifier.size(26.dp)) + Text( + label, fontSize = 12.sp, color = pal.onBackground, textAlign = TextAlign.Center, maxLines = 3, overflow = TextOverflow.Ellipsis, + modifier = Modifier.padding(top = 6.dp), + ) + } +} diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index ea85ca5c12..0329c403c1 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -1180,6 +1180,11 @@ أدوات الوكيل غير مثبتة: %1$s لا تُرسل إرفاق + الملفات + السماح بالوصول إلى الصور + اختيار المزيد من الصور + لا توجد صور بعد + لوحة المفاتيح إزالة الافتراضي جهد الاستدلال diff --git a/app/src/main/res/values-b+es+419/strings.xml b/app/src/main/res/values-b+es+419/strings.xml index 12254b5715..ff0f9b4685 100644 --- a/app/src/main/res/values-b+es+419/strings.xml +++ b/app/src/main/res/values-b+es+419/strings.xml @@ -1198,6 +1198,11 @@ Herramientas del agente sin instalar: %1$s No enviar Adjuntar + Archivos + Permitir acceso a fotos + Elegir más fotos + Aún no hay fotos + Teclado Quitar Predeterminado Esfuerzo de razonamiento diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index bb4ff12581..70a66f3fe5 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -1168,6 +1168,11 @@ Инструментите на агента не са инсталирани: %1$s Не изпращай Прикачи + Файлове + Разрешаване на достъп до снимки + Избор на още снимки + Все още няма снимки + Клавиатура Премахни По подразбиране Усилие за разсъждение diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 02d5c6d00d..d8b5e9960c 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -1174,6 +1174,11 @@ Nástroje agenta nejsou nainstalované: %1$s Neposílat Přiložit + Soubory + Povolit přístup k fotkám + Vybrat další fotky + Zatím žádné fotky + Klávesnice Odebrat Výchozí Náročnost uvažování diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index f3383e6768..2dd816c23f 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -1168,6 +1168,11 @@ Agentens værktøjer er ikke installeret: %1$s Send ikke Vedhæft + Filer + Tillad adgang til billeder + Vælg flere billeder + Ingen billeder endnu + Tastatur Fjern Standard Ræsonneringsindsats diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index ce45ef01d4..ec19ca465a 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -1160,6 +1160,11 @@ Agent-Werkzeuge nicht installiert: %1$s Nicht senden Anhängen + Dateien + Zugriff auf Fotos erlauben + Weitere Fotos auswählen + Noch keine Fotos + Tastatur Entfernen Standard Denkaufwand diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 7205dd9940..b4d1e7552d 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -1168,6 +1168,11 @@ Τα εργαλεία του πράκτορα δεν εγκαταστάθηκαν: %1$s Να μην σταλεί Επισύναψη + Αρχεία + Να επιτρέπεται η πρόσβαση στις φωτογραφίες + Επιλογή περισσότερων φωτογραφιών + Δεν υπάρχουν φωτογραφίες ακόμα + Πληκτρολόγιο Αφαίρεση Προεπιλογή Προσπάθεια συλλογισμού diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 71e10bdab3..c07d195c68 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -1171,6 +1171,11 @@ Herramientas del agente sin instalar: %1$s No enviar Adjuntar + Archivos + Permitir acceso a las fotos + Elegir más fotos + Aún no hay fotos + Teclado Quitar Predeterminado Esfuerzo de razonamiento diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 464e2576be..2143c3416b 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -1168,6 +1168,11 @@ Agentin työkaluja ei ole asennettu: %1$s Älä lähetä Liitä + Tiedostot + Salli kuvien käyttö + Valitse lisää kuvia + Ei vielä kuvia + Näppäimistö Poista Oletus Päättelyteho diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 7c1c1ef44d..a667d3b351 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -1171,6 +1171,11 @@ Outils de l’agent non installés : %1$s Ne pas envoyer Joindre + Fichiers + Autoriser l\'accès aux photos + Choisir d\'autres photos + Aucune photo pour l\'instant + Clavier Supprimer Par défaut Effort de raisonnement diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index 281c5914d5..fee8602fce 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -1168,6 +1168,11 @@ एजेंट टूल इंस्टॉल नहीं हुए: %1$s न भेजें संलग्न करें + फ़ाइलें + फ़ोटो की अनुमति दें + और फ़ोटो चुनें + अभी कोई फ़ोटो नहीं + कीबोर्ड हटाएँ डिफ़ॉल्ट सोचने का स्तर diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index a74cef1df8..35f0ff99ef 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -1168,6 +1168,11 @@ Az ügynök eszközei nincsenek telepítve: %1$s Ne küldd el Csatolás + Fájlok + Fotókhoz való hozzáférés engedélyezése + További fotók kiválasztása + Még nincsenek fotók + Billentyűzet Eltávolítás Alapértelmezett Gondolkodási erőfeszítés diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 8bd5840655..22bff7e5ec 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -1165,6 +1165,11 @@ Alat agen tidak terpasang: %1$s Jangan kirim Lampirkan + File + Izinkan akses foto + Pilih foto lainnya + Belum ada foto + Keyboard Hapus Default Upaya penalaran diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 0d79a90921..a676758f72 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -1163,6 +1163,11 @@ Strumenti dell’agente non installati: %1$s Non inviare Allega + File + Consenti accesso alle foto + Scegli altre foto + Ancora nessuna foto + Tastiera Rimuovi Predefinito Livello di ragionamento diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index f66a14fc6e..0c181e7ab3 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -1165,6 +1165,11 @@ エージェントのツールが未インストール: %1$s 送信しない 添付 + ファイル + 写真へのアクセスを許可 + 写真をさらに選択 + まだ写真がありません + キーボード 削除 デフォルト 推論レベル diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index dbcf405e3f..5a6d979241 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -1165,6 +1165,11 @@ 에이전트 도구가 설치되지 않음: %1$s 보내지 않기 첨부 + 파일 + 사진 접근 허용 + 사진 더 선택 + 아직 사진이 없습니다 + 키보드 제거 기본 추론 수준 diff --git a/app/src/main/res/values-ms/strings.xml b/app/src/main/res/values-ms/strings.xml index 2dc5bcea1b..188ed04d5e 100644 --- a/app/src/main/res/values-ms/strings.xml +++ b/app/src/main/res/values-ms/strings.xml @@ -1165,6 +1165,11 @@ Alat ejen tidak dipasang: %1$s Jangan hantar Lampirkan + Fail + Benarkan akses foto + Pilih lebih banyak foto + Belum ada foto + Papan kekunci Alih keluar Lalai Usaha penaakulan diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index 70da47fde8..75a3415f2e 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -1168,6 +1168,11 @@ Agentverktøy er ikke installert: %1$s Ikke send Legg ved + Filer + Tillat tilgang til bilder + Velg flere bilder + Ingen bilder ennå + Tastatur Fjern Standard Resonneringsinnsats diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index aa95f349be..2df78a8419 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -1168,6 +1168,11 @@ Agenttools niet geïnstalleerd: %1$s Niet verzenden Bijvoegen + Bestanden + Toegang tot foto\'s toestaan + Meer foto\'s kiezen + Nog geen foto\'s + Toetsenbord Verwijderen Standaard Redeneerinspanning diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 350871461b..f8218ebfef 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -1174,6 +1174,11 @@ Narzędzia agenta nie są zainstalowane: %1$s Nie wysyłaj Załącz + Pliki + Zezwól na dostęp do zdjęć + Wybierz więcej zdjęć + Brak zdjęć + Klawiatura Usuń Domyślny Poziom rozumowania diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 58c25267da..4051e3fcb6 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -1163,6 +1163,11 @@ Ferramentas do agente não instaladas: %1$s Não enviar Anexar + Ficheiros + Permitir acesso às fotos + Escolher mais fotos + Ainda não há fotos + Teclado Remover Predefinido Esforço de raciocínio diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 08eb2c38de..bf322e180b 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -1170,6 +1170,11 @@ Ferramentas do agente não instaladas: %1$s Não enviar Anexar + Arquivos + Permitir acesso às fotos + Escolher mais fotos + Ainda não há fotos + Teclado Remover Padrão Esforço de raciocínio diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index bd89893d52..3325b9da12 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -1171,6 +1171,11 @@ Instrumentele agentului nu sunt instalate: %1$s Nu trimite Atașează + Fișiere + Permite accesul la fotografii + Alege mai multe fotografii + Încă nu există fotografii + Tastatură Elimină Implicit Efort de raționament diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index c75b0aa343..96694a0b2c 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -1174,6 +1174,11 @@ Инструменты агента не установлены: %1$s Не отправлять Прикрепить + Файлы + Разрешить доступ к фото + Выбрать ещё фото + Пока нет фото + Клавиатура Удалить По умолчанию Уровень рассуждений diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index f3819c7385..a0bbd67c37 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -1168,6 +1168,11 @@ Agentens verktyg är inte installerade: %1$s Skicka inte Bifoga + Filer + Tillåt åtkomst till bilder + Välj fler bilder + Inga bilder än + Tangentbord Ta bort Standard Resonemangsnivå diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index 21c96ecd2a..a4028f05ce 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -1165,6 +1165,11 @@ ยังไม่ได้ติดตั้งเครื่องมือของเอเจนต์: %1$s ไม่ต้องส่ง แนบ + ไฟล์ + อนุญาตให้เข้าถึงรูปภาพ + เลือกรูปภาพเพิ่ม + ยังไม่มีรูปภาพ + แป้นพิมพ์ นำออก ค่าเริ่มต้น ระดับการใช้เหตุผล diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index acc9089167..ef66a2f302 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -1160,6 +1160,11 @@ Ajan araçları yüklenmedi: %1$s Gönderme Ekle + Dosyalar + Fotoğraflara erişime izin ver + Daha fazla fotoğraf seç + Henüz fotoğraf yok + Klavye Kaldır Varsayılan Akıl yürütme çabası diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 6ca06df91c..890e3ea863 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -1174,6 +1174,11 @@ Інструменти агента не встановлено: %1$s Не надсилати Прикріпити + Файли + Дозволити доступ до фото + Вибрати ще фото + Поки немає фото + Клавіатура Видалити За замовчуванням Рівень міркувань diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 420c0c1bf5..ae806d0524 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -1165,6 +1165,11 @@ Chưa cài công cụ của tác tử: %1$s Không gửi Đính kèm + Tệp + Cho phép truy cập ảnh + Chọn thêm ảnh + Chưa có ảnh + Bàn phím Xóa Mặc định Mức độ lập luận diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index eb5407a271..9bc2afeaee 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -1248,6 +1248,11 @@ 智能体工具未安装:%1$s 不发送 添加附件 + 文件 + 允许访问照片 + 选择更多照片 + 还没有照片 + 键盘 移除 默认 推理强度 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 7f4bbd0233..7a79238501 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -1164,6 +1164,11 @@ 智能體工具未安裝:%1$s 不要傳送 附加 + 檔案 + 允許存取相片 + 選擇更多相片 + 尚未有相片 + 鍵盤 移除 預設 推理強度 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index e52193ca17..00e2bae533 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -1164,6 +1164,11 @@ 智慧代理工具未安裝:%1$s 不要傳送 附加 + 檔案 + 允許存取相片 + 選擇更多相片 + 還沒有相片 + 鍵盤 移除 預設 推理強度 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ed8b435d3f..9ab2d5584d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1330,6 +1330,11 @@ Agent tools not installed: %1$s Don\'t send Attach + Files + Allow photo access + Choose more photos + No photos yet + Keyboard Remove Default Reasoning effort diff --git a/tools/agent/AGENTS.md b/tools/agent/AGENTS.md index 709dcbf181..3b2ccd2c84 100644 --- a/tools/agent/AGENTS.md +++ b/tools/agent/AGENTS.md @@ -44,8 +44,10 @@ from what tripped agents up on real devices. running makes Steam show "Game already running" and `launch` time out. - Session scripts are APK assets, copied into the rootfs at every session start over any local edit. A Lab build (`dd-lab-build`, see `docs/lab-builds.md`) carries app code and resources only: - session scripts, native code and assets need a new APK, such as the pull request's CI test build - (DroidDeck > Updates > Test builds). + session scripts, native code, assets and `AndroidManifest.xml` need a new APK, such as the pull + request's CI test build (DroidDeck > Updates > Test builds). `dd-lab-build` refuses changes to the + manifest, native code, Gradle files and a few startup classes, but builds session script and asset + changes without them. To try the rest of a branch, build a copy without those changes. ## Changing DroidDeck @@ -56,7 +58,8 @@ The source is checked out at `/root/DroidDeck` once the Agent tab's build tools - `dd-lab-build` builds the checkout as a Lab build and restarts DroidDeck on it. DroidDeck runs the build in a process of its own and shows its progress; `dd-lab-build` follows its log. Run it in the background and keep checking, so the user can talk to you meanwhile. The restart ends your - process, and the conversation continues on the new build. + process; DroidDeck starts you again on the new build, in the same conversation, so tell the user + what you will check then instead of asking them to message you. - To try a change, commit it and go straight to `dd-lab-build`: it compiles the app, so a Gradle compile first only adds time. It refuses changes since the installed build (`apkCommit` in `droiddeckctl state`) that need a new APK. For a branch from a newer `origin/main`, cherry-pick