From c7ff93ec1977f1338120da0a14c385220b896f4b Mon Sep 17 00:00:00 2001 From: LunaDL <91587464+EnzoDLofi@users.noreply.github.com> Date: Sun, 15 Nov 2026 15:51:24 -0400 Subject: [PATCH 01/52] Feat: adds a interger scalling (another option) (#2620) * Add integer scaling mode * Add Fit and Auto options for integer scaling * Update vk_present.c ( removed comentarios) * Fix integer scaling view-space input bounds * Fix integer scaling view coordinate ratios * Fix glasses touch and effective Cardboard alignment * Translate integer scaling settings * Fix glasses picture bounds scaling --- app/src/main/cpp/waylandcomp/src/vk_present.c | 3 +- .../droiddeck/launcher/FrontEndActivity.kt | 4 ++ .../com/droiddeck/launcher/SessionActivity.kt | 42 +++++++++---------- .../launcher/session/SessionPrefs.kt | 7 ++++ .../launcher/session/SettingsReset.kt | 2 +- .../launcher/ui/ModeSettingsDialog.kt | 14 +++++++ app/src/main/res/values-ar/strings.xml | 3 ++ app/src/main/res/values-b+es+419/strings.xml | 3 ++ app/src/main/res/values-bg/strings.xml | 3 ++ app/src/main/res/values-cs/strings.xml | 3 ++ app/src/main/res/values-da/strings.xml | 3 ++ app/src/main/res/values-de/strings.xml | 3 ++ app/src/main/res/values-el/strings.xml | 3 ++ app/src/main/res/values-es/strings.xml | 3 ++ app/src/main/res/values-fi/strings.xml | 3 ++ app/src/main/res/values-fr/strings.xml | 3 ++ app/src/main/res/values-hi/strings.xml | 3 ++ app/src/main/res/values-hu/strings.xml | 3 ++ app/src/main/res/values-in/strings.xml | 3 ++ app/src/main/res/values-it/strings.xml | 3 ++ app/src/main/res/values-ja/strings.xml | 3 ++ app/src/main/res/values-ko/strings.xml | 3 ++ app/src/main/res/values-ms/strings.xml | 3 ++ app/src/main/res/values-nb/strings.xml | 3 ++ app/src/main/res/values-nl/strings.xml | 3 ++ app/src/main/res/values-pl/strings.xml | 3 ++ app/src/main/res/values-pt-rPT/strings.xml | 3 ++ app/src/main/res/values-pt/strings.xml | 3 ++ app/src/main/res/values-ro/strings.xml | 3 ++ app/src/main/res/values-ru/strings.xml | 3 ++ app/src/main/res/values-sv/strings.xml | 3 ++ app/src/main/res/values-th/strings.xml | 3 ++ app/src/main/res/values-tr/strings.xml | 3 ++ app/src/main/res/values-uk/strings.xml | 3 ++ app/src/main/res/values-vi/strings.xml | 3 ++ app/src/main/res/values-zh-rCN/strings.xml | 3 ++ app/src/main/res/values-zh-rHK/strings.xml | 3 ++ app/src/main/res/values-zh-rTW/strings.xml | 3 ++ app/src/main/res/values/strings.xml | 4 ++ 39 files changed, 147 insertions(+), 25 deletions(-) diff --git a/app/src/main/cpp/waylandcomp/src/vk_present.c b/app/src/main/cpp/waylandcomp/src/vk_present.c index aa63253b67..e0e494cb87 100644 --- a/app/src/main/cpp/waylandcomp/src/vk_present.c +++ b/app/src/main/cpp/waylandcomp/src/vk_present.c @@ -416,8 +416,7 @@ static void update_map(int scene_w, int scene_h) { if (mode == VKP_MODE_FILL) aspect = sx > sy ? sx : sy; else if (mode == VKP_MODE_INTEGER) { float m = sx < sy ? sx : sy; - aspect = (float)(int)m; - if (aspect < 1.0f) aspect = 1.0f; + aspect = m >= 1.0f ? (float)(int)m : m; } else aspect = sx < sy ? sx : sy; g_map.kx = g_map.ky = aspect; g_map.off_x = (float)(g_map.rx + (int)((g_map.rw - scene_w * aspect) * 0.5f)); diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index c79f757531..4e774e76b6 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -195,6 +195,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet private var showPhantomGate by mutableStateOf(false) private var directAudio by mutableStateOf(false) private var picturePosition by mutableStateOf("center") + private var integerScaling by mutableStateOf(false) private var stretch16x9 by mutableStateOf(false) private var orientation by mutableStateOf(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) private var launcherOrientation by mutableStateOf(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER) @@ -2551,6 +2552,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet backActionsInverted = backActionsInverted, directAudio = if (mode == SessionService.MODE_STEAM) directAudio else null, picturePosition = if (mode == SessionService.MODE_STEAM) picturePosition else null, + integerScaling = if (mode == SessionService.MODE_STEAM) integerScaling else null, stretch16x9 = if (mode == SessionService.MODE_STEAM) stretch16x9 else null, mic = if (mode == SessionService.MODE_STEAM) mic else null, gameStorage = if (mode == SessionService.MODE_STEAM) gameStorage else null, @@ -2612,6 +2614,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet }, onDirectAudio = { on -> SessionPrefs.setDirectAudio(this, on); directAudio = on }, onPicturePosition = { value -> SessionPrefs.setPicturePosition(this, value); picturePosition = value }, + onIntegerScaling = { on -> SessionPrefs.setIntegerScaling(this, on); integerScaling = on }, onStretch16x9 = { on -> SessionPrefs.setStretch16x9(this, on); stretch16x9 = on }, onMic = { on -> SessionPrefs.setMicEnabled(this, on) @@ -2949,6 +2952,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet backActionsInverted = SessionPrefs.backActionsInverted(this) directAudio = SessionPrefs.directAudio(this) picturePosition = SessionPrefs.picturePosition(this) + integerScaling = SessionPrefs.integerScaling(this) stretch16x9 = SessionPrefs.stretch16x9(this) mic = SessionPrefs.micEnabled(this) refreshWifiDiscovery() diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 8032723834..6aed0ecf48 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -173,11 +173,12 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private var adaptiveSticks by mutableStateOf(null) private var quickButtons by mutableStateOf>(emptyMap()) private var picturePosition by mutableStateOf("center") + private var integerScaling by mutableStateOf(false) private fun applyGameAlignment() { if (!CompositorHost.isStarted) return val active = SessionState.mode == SessionService.MODE_STEAM && - !pipUi && !isInPictureInPictureMode && !cardboard.enabled + !pipUi && !isInPictureInPictureMode && !activeCardboard.enabled val alignment = if (!active) ALIGN_CENTER else when (picturePosition) { "top" -> ALIGN_PICTURE_TOP "bottom" -> ALIGN_PICTURE_BOTTOM @@ -185,7 +186,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde "right" -> ALIGN_PICTURE_RIGHT else -> ALIGN_CENTER } - WaylandCompositor.nativeSetScaleMode(SCALE_FIT, alignment) + WaylandCompositor.nativeSetScaleMode(if (active && integerScaling) SCALE_INTEGER else SCALE_FIT, alignment) } private var unfoldedPanel by mutableStateOf(null) private var unfoldedColumn: android.widget.LinearLayout? = null @@ -1085,7 +1086,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde secondScreenPresentation?.closeFieldKeyboard() } } - androidx.compose.runtime.LaunchedEffect(picturePosition, SessionState.running, pipUi, cardboard.enabled) { applyGameAlignment() } + androidx.compose.runtime.LaunchedEffect(picturePosition, integerScaling, SessionState.running, pipUi, cardboard.enabled) { applyGameAlignment() } DroidDeckTheme { if (pipUi) { if (SessionState.suspended) androidx.compose.foundation.layout.Box( @@ -2399,6 +2400,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde unfoldedControls = SessionPrefs.unfoldedControls(this) unfoldedControlsWithController = SessionPrefs.unfoldedControlsWithController(this) picturePosition = SessionPrefs.picturePosition(this) + integerScaling = SessionPrefs.integerScaling(this) hudOn = SessionPrefs.hudEnabled(this) hudConfig = DroidDeckHudConfig.load(this) hudColor = SessionPrefs.hudColor(this) @@ -2654,7 +2656,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde runCatching { GameEnvironmentStore.publish(this) } .onFailure { Log.e(TAG, "Could not update game environment", it) } }, "game-env-publish").start() - WaylandCompositor.nativeSetScaleMode(SCALE_FIT, ALIGN_CENTER) + applyGameAlignment() val activeProfileId = currentScreenEffectsProfileId() val activeUpscaler = SessionPrefs.screenEffectsUpscaler(this, activeProfileId) val activeEffects = SessionPrefs.screenEffects(this, activeProfileId) @@ -4636,25 +4638,18 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde gamePictureBounds[2], gamePictureBounds[3] ) + val nativeWidth: Int + val nativeHeight: Int if (glassesOutputActive) { val mode = glassesScreen?.display?.mode ?: return null - val outputWidth = mode.physicalWidth.takeIf { it > 0 } ?: return null - val outputHeight = mode.physicalHeight.takeIf { it > 0 } ?: return null - val scaleX = width.toFloat() / outputWidth - val scaleY = height.toFloat() / outputHeight - - return android.graphics.RectF( - rect.left * scaleX, - rect.top * scaleY, - rect.right * scaleX, - rect.bottom * scaleY - ) + nativeWidth = mode.physicalWidth.takeIf { it > 0 } ?: return null + nativeHeight = mode.physicalHeight.takeIf { it > 0 } ?: return null + } else { + val nativeSize = IntArray(2) + if (!WaylandCompositor.nativeOutputSize(nativeSize)) return null + nativeWidth = nativeSize[0].takeIf { it > 0 } ?: return null + nativeHeight = nativeSize[1].takeIf { it > 0 } ?: return null } - - val nativeSize = IntArray(2) - if (!WaylandCompositor.nativeOutputSize(nativeSize)) return null - val nativeWidth = nativeSize[0].takeIf { it > 0 } ?: return null - val nativeHeight = nativeSize[1].takeIf { it > 0 } ?: return null val scaleX = width.toFloat() / nativeWidth val scaleY = height.toFloat() / nativeHeight @@ -4863,7 +4858,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private fun dispatchDirectTouch(event: MotionEvent): Boolean { val rect = drawnRect() ?: return false if (event.actionMasked == MotionEvent.ACTION_DOWN) - ignoreGameTouch = topPictureMapped && !rect.contains(event.x, event.y) + ignoreGameTouch = topPictureMapped && !glassesOutputActive && + !rect.contains(event.x, event.y) if (ignoreGameTouch) { if (event.actionMasked == MotionEvent.ACTION_DOWN) { directTouchHold.cancel() @@ -5389,7 +5385,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde listOf(PointerGestures.BTN_LEFT, PointerGestures.BTN_RIGHT, PointerGestures.BTN_MIDDLE).forEach { heldButtons.set(1, it, false) } - WaylandCompositor.nativeSetScaleMode(SCALE_FIT, ALIGN_CENTER) + applyGameAlignment() } } else if (!isFinishing && !isDestroyed) { window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) @@ -5750,6 +5746,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde cardboard = c val e = effectiveCardboard(c) activeCardboard = e + applyGameAlignment() if (CompositorHost.isStarted) pushCardboard(e) if (e.enabled && !was.enabled) headTracker?.recenter() updateHeadTracker() @@ -6369,6 +6366,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private val steamVrWorker = java.util.concurrent.ThreadPoolExecutor(0, 1, 30, java.util.concurrent.TimeUnit.SECONDS, java.util.concurrent.LinkedBlockingQueue()) { Thread(it, "steamvr") } private const val SCALE_FIT = 1 + private const val SCALE_INTEGER = 4 private const val ALIGN_CENTER = 0 private const val ALIGN_PICTURE_TOP = 3 private const val ALIGN_PICTURE_BOTTOM = 4 diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt index 035c237bd0..aae250583a 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -641,6 +641,13 @@ object SessionPrefs { position.takeIf { it in listOf("top", "bottom", "left", "right", "center") } ?: "center").apply() } + fun integerScaling(context: Context): Boolean = + prefs(context).getBoolean("integerScaling", false) + + fun setIntegerScaling(context: Context, enabled: Boolean) { + prefs(context).edit().putBoolean("integerScaling", enabled).apply() + } + fun returnAfterGame(context: Context): Boolean = prefs(context).getBoolean("returnAfterGame", true) fun setReturnAfterGame(context: Context, on: Boolean) { diff --git a/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt b/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt index cc7779322e..92ec84c13a 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt @@ -18,7 +18,7 @@ object SettingsReset { "storesInstallLanguage", "hud", "hudDeck", "hudFps", "hudBattery", "hudGraph", "hudColor", "hudOpacity", "__KEEP_droidDeckHud__", "__KEEP_droidDeckHudPos__", "backHold", "backActionsInverted", "backDoubleTapMs", "touch", "pen", "penButton", "osc", "shape", "steamController", "gamepadLeft", "gamepadRight", "pipAutoEnter", "unfoldedControls", "unfoldedControlsWithController", - "stretch16x9", "picturePosition", "railLabels", "agentTab", "navTabOrder", "navTabShelved", "navTabHidden", "pcKeyboardSize", "pcKeyboardOpacity", "pcKeyboardHiddenKeys", + "stretch16x9", "picturePosition", "integerScaling", "railLabels", "agentTab", "navTabOrder", "navTabShelved", "navTabHidden", "pcKeyboardSize", "pcKeyboardOpacity", "pcKeyboardHiddenKeys", "gpuDriverMode", "androidDriver", "linuxDriver", "linuxDriver.steam", "linuxDriver.desktop", "tuSysmem", "glThread", "noGlError", "zinkLazy", "mangoapp", "gpuClockPin", "gamescopeRealtime", "paceCores", "ramCapMb", "vramCapMb", "zramClient", "zramIdle", "directAudio", "mic", "wifiDiscovery", "clientCpusOverride", "clientCpus", "gameCpus", diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt b/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt index 4c882ab1e9..d25cd1ffa3 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt @@ -83,6 +83,7 @@ class ModeSettings( val forceSsbs: Boolean = false, val syncBackend: String? = null, val picturePosition: String? = null, + val integerScaling: Boolean? = null, val stretch16x9: Boolean? = null, val steamClientArch: String? = null, val returnAfterGame: Boolean? = null, @@ -139,6 +140,7 @@ class ModeSettingsActions( val onForceSsbs: (Boolean) -> Unit = {}, val onSyncBackend: (String) -> Unit = {}, val onPicturePosition: (String) -> Unit = {}, + val onIntegerScaling: (Boolean) -> Unit = {}, val onStretch16x9: (Boolean) -> Unit = {}, val onSteamRepair: () -> Unit = {}, val onSteamClientArch: (String) -> Unit = {}, @@ -242,6 +244,18 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras: } } SettingsGroup(stringResource(R.string.display_image_scaling)) { + s.integerScaling?.let { enabled -> + ChoiceRow( + host, "integer-scaling", + stringResource(R.string.display_integer_scaling), + stringResource(R.string.display_integer_scaling_hint), + listOf( + false to stringResource(R.string.display_scaling_fit), + true to stringResource(R.string.display_scaling_auto), + ), + enabled, onPick = a.onIntegerScaling, + ) + } ChoiceRow( host, "upscaler", stringResource(R.string.display_filter), null, SessionPrefs.upscalerChoices(LocalContext.current), s.upscaler, diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 26f1db7bb4..095fb1995e 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -4266,4 +4266,7 @@ المعروض %1$d من %2$d اضغط زر الرجوع مرة أخرى للخروج + + تحجيم صحيح بالأعداد الصحيحة + يستخدم أكبر معامل تحجيم صحيح يناسب الشاشة. إذا كان المصدر كبيرًا جدًا، يتم تصغير الصورة كاملة لتجنب الاقتصاص. يتم ضبط الدقة بشكل منفصل. 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 006974f736..2e050014fd 100644 --- a/app/src/main/res/values-b+es+419/strings.xml +++ b/app/src/main/res/values-b+es+419/strings.xml @@ -4117,4 +4117,7 @@ Mostrados %1$d de %2$d Presiona atrás una vez más para salir + + Escalado de píxeles enteros + Usa el mayor factor de escala entero que quepa. Si la imagen de origen es demasiado grande, ajusta la imagen completa para evitar recortes. La resolución se configura por separado. diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 8f877c02d1..82393e0483 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -4106,4 +4106,7 @@ Показани %1$d от %2$d Натиснете отново „Назад“, за да излезете + + Целочислено мащабиране + Използва най-големия цял коефициент на мащабиране, който се побира. Ако източникът е твърде голям, побира цялото изображение, за да избегне изрязване. Разделителната способност се настройва отделно. diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 6c66acabfd..be4c2e1b25 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -4186,4 +4186,7 @@ Zobrazeno %1$d z %2$d Stiskněte znovu zpět pro ukončení + + Celočíselné škálování + Použije největší celočíselný násobek měřítka, který se vejde. Pokud je zdroj příliš velký, přizpůsobí celý obraz, aby nedošlo k oříznutí. Rozlišení se nastavuje samostatně. diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index d2f31b011e..5dce74fc53 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -4106,4 +4106,7 @@ Vist %1$d af %2$d Tryk tilbage igen for at afslutte + + Heltalsskalering + Bruger den største hele skaleringsfaktor, der kan være der. Hvis kilden er for stor, tilpasses hele billedet for at undgå beskæring. Opløsningen indstilles separat. diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 47dce20b4a..10bb9f7c16 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -4106,4 +4106,7 @@ Angezeigt %1$d von %2$d Noch einmal zurück drücken zum Beenden + + Ganzzahlige Skalierung + Verwendet den größten ganzzahligen Skalierungsfaktor, der passt. Ist die Quelle zu groß, wird das gesamte Bild eingepasst, um Beschneidung zu vermeiden. Die Auflösung wird separat eingestellt. diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 5870bfa94c..037a7da150 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -4106,4 +4106,7 @@ Εμφανίζονται %1$d από %2$d Πατήστε ξανά πίσω για έξοδο + + Ακέραια κλιμάκωση + Χρησιμοποιεί τον μεγαλύτερο ακέραιο συντελεστή κλιμάκωσης που χωράει. Αν η πηγή είναι πολύ μεγάλη, προσαρμόζει ολόκληρη την εικόνα ώστε να αποφευχθεί η περικοπή. Η ανάλυση ρυθμίζεται ξεχωριστά. diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 454585bcbb..73f08e89a4 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -4146,4 +4146,7 @@ Mostrados %1$d de %2$d Pulsa atrás una vez más para salir + + Escalado de píxeles enteros + Usa el mayor factor de escala entero que quepa. Si la imagen de origen es demasiado grande, ajusta la imagen completa para evitar recortes. La resolución se configura por separado. diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 3faed1bd20..a27e6228bc 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -4106,4 +4106,7 @@ Näkyvissä %1$d / %2$d Paina takaisin vielä kerran poistuaksesi + + Kokonaislukuskaalaus + Käyttää suurinta mahtuvaa kokonaislukukerrointa. Jos lähdekuva on liian suuri, koko kuva sovitetaan rajauksen välttämiseksi. Tarkkuus määritetään erikseen. diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index dca037ff9b..80765a1c86 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -4145,4 +4145,7 @@ Affichés %1$d sur %2$d Appuyez à nouveau sur retour pour quitter + + Mise à l’échelle entière + Utilise le plus grand facteur d’échelle entier possible. Si la source est trop grande, l’image entière est ajustée pour éviter le recadrage. La résolution se règle séparément. diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index 9acd2d7783..3acc513034 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -4106,4 +4106,7 @@ दिखाए गए %2$d में से %1$d बाहर निकलने के लिए फिर से बैक दबाएँ + + पूर्णांक स्केलिंग + फिट होने वाले सबसे बड़े पूर्णांक स्केल का उपयोग करता है। स्रोत बहुत बड़ा होने पर काटने से बचाने के लिए पूरी छवि को फिट करता है। रिज़ॉल्यूशन अलग से सेट किया जाता है। diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index bf6abc003c..cc87c4de8e 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -4106,4 +4106,7 @@ Megjelenítve %1$d / %2$d Nyomd meg még egyszer a visszát a kilépéshez + + Egész számú méretezés + A legnagyobb elférő egész számú méretezési tényezőt használja. Ha a forrás túl nagy, a teljes képet hozzáigazítja a levágás elkerüléséhez. A felbontás külön állítható. diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index bfefdf12c7..5ebb1a34f9 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -4076,4 +4076,7 @@ Ditampilkan %1$d dari %2$d Tekan kembali sekali lagi untuk keluar + + Penskalaan bilangan bulat + Menggunakan faktor skala bilangan bulat terbesar yang muat. Jika sumber terlalu besar, seluruh gambar disesuaikan agar tidak terpotong. Resolusi diatur secara terpisah. diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 51a2ae045e..e7817522bd 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -4145,4 +4145,7 @@ Mostrati %1$d di %2$d Premi di nuovo indietro per uscire + + Ridimensionamento intero + Usa il più grande fattore di scala intero che entra nello schermo. Se la sorgente è troppo grande, adatta l’intera immagine per evitare ritagli. La risoluzione si configura separatamente. diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index ace99b72c0..c2a67cc84d 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -4076,4 +4076,7 @@ 表示中 %2$d 中 %1$d もう一度戻るを押すと終了します + + 整数スケーリング + 収まる最大の整数倍率を使用します。元の画像が大きすぎる場合は、切り抜きを避けるため画像全体を収めます。解像度は別途設定します。 diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 11fbb0f3ec..dd65900c76 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -4076,4 +4076,7 @@ 표시됨 %2$d 중 %1$d 한 번 더 뒤로를 누르면 종료됩니다 + + 정수 배율 조정 + 화면에 맞는 가장 큰 정수 배율을 사용합니다. 원본이 너무 크면 잘림을 방지하기 위해 전체 이미지를 맞춥니다. 해상도는 별도로 설정합니다. diff --git a/app/src/main/res/values-ms/strings.xml b/app/src/main/res/values-ms/strings.xml index b781198eb9..9701ed1542 100644 --- a/app/src/main/res/values-ms/strings.xml +++ b/app/src/main/res/values-ms/strings.xml @@ -4076,4 +4076,7 @@ Dipaparkan %1$d daripada %2$d Tekan kembali sekali lagi untuk keluar + + Penskalaan integer + Menggunakan faktor skala integer terbesar yang muat. Jika sumber terlalu besar, keseluruhan imej disesuaikan untuk mengelakkan pemotongan. Resolusi ditetapkan secara berasingan. diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index ff8ee92cac..19c503f02d 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -4106,4 +4106,7 @@ Vist %1$d av %2$d Trykk tilbake én gang til for å avslutte + + Heltallsskalering + Bruker den største hele skaleringsfaktoren som får plass. Hvis kilden er for stor, tilpasses hele bildet for å unngå beskjæring. Oppløsningen stilles inn separat. diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index e95fd9a735..4bb4d3223b 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -4106,4 +4106,7 @@ Getoond %1$d van %2$d Druk nog één keer op terug om af te sluiten + + Gehele-getallenschaal + Gebruikt de grootste gehele schaalfactor die past. Als de bron te groot is, wordt de volledige afbeelding passend gemaakt om bijsnijden te voorkomen. De resolutie wordt apart ingesteld. diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index b5537449ab..f8620690ac 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -4186,4 +4186,7 @@ Pokazane %1$d z %2$d Naciśnij wstecz jeszcze raz, aby wyjść + + Skalowanie całkowite + Używa największego całkowitego współczynnika skalowania, który się mieści. Jeśli źródło jest zbyt duże, dopasowuje cały obraz, aby uniknąć przycinania. Rozdzielczość ustawia się osobno. diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index b07045dcbd..09831c53f2 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -4145,4 +4145,7 @@ Mostrados %1$d de %2$d Prima novamente o botão Voltar para sair + + Escala por números inteiros + Utiliza o maior fator de escala inteiro que couber. Se a imagem de origem for demasiado grande, ajusta a imagem completa para evitar cortes. A resolução é configurada separadamente. diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 988e258cbe..42248a4fb5 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -4153,4 +4153,7 @@ Exibidos %1$d de %2$d Pressione o botão Voltar novamente para sair + + Escala por números inteiros + Usa o maior fator de escala inteiro que couber. Se a imagem de origem for grande demais, ajusta a imagem completa para evitar cortes. A resolução é configurada separadamente. diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index 032e628dde..c00b97f0e9 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -4146,4 +4146,7 @@ Afișate %1$d din %2$d Apasă din nou înapoi pentru a ieși + + Scalare cu numere întregi + Folosește cel mai mare factor întreg de scalare care încape. Dacă sursa este prea mare, adaptează întreaga imagine pentru a evita decuparea. Rezoluția se configurează separat. diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 476efea4e9..f373bcf903 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -4186,4 +4186,7 @@ Показано %1$d из %2$d Нажмите «Назад» ещё раз, чтобы выйти + + Целочисленное масштабирование + Использует наибольший целочисленный коэффициент масштабирования, который помещается. Если исходное изображение слишком велико, оно уменьшается целиком, чтобы избежать обрезки. Разрешение настраивается отдельно. diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 0c9addcde5..bdfb11dd91 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -4106,4 +4106,7 @@ Visade %1$d av %2$d Tryck tillbaka igen för att avsluta + + Heltalsskalning + Använder den största hela skalningsfaktorn som får plats. Om källbilden är för stor anpassas hela bilden för att undvika beskärning. Upplösningen ställs in separat. diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index 9c936f699b..2a74e0f185 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -4076,4 +4076,7 @@ ที่แสดง %1$d จาก %2$d กดกลับอีกครั้งเพื่อออก + + การปรับขนาดจำนวนเต็ม + ใช้ตัวคูณการปรับขนาดจำนวนเต็มที่ใหญ่ที่สุดที่พอดี หากภาพต้นฉบับใหญ่เกินไป จะปรับภาพทั้งหมดให้พอดีเพื่อหลีกเลี่ยงการตัดภาพ โดยตั้งค่าความละเอียดแยกต่างหาก diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 1ba6ea683d..8a72d0a584 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -4106,4 +4106,7 @@ Gösterilen %1$d / %2$d Çıkmak için bir kez daha geri basın + + Tam sayı ölçeklendirme + Sığan en büyük tam sayı ölçekleme katsayısını kullanır. Kaynak çok büyükse kırpmayı önlemek için görüntünün tamamını sığdırır. Çözünürlük ayrı ayarlanır. diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 699d176341..a09c1234f6 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -4186,4 +4186,7 @@ Показано %1$d з %2$d Натисніть «Назад» ще раз, щоб вийти + + Цілочисельне масштабування + Використовує найбільший цілий коефіцієнт масштабування, який поміщається. Якщо вихідне зображення завелике, воно вміщується повністю без обрізання. Роздільна здатність налаштовується окремо. diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 284e5c94a1..e0ae6e7e6e 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -4076,4 +4076,7 @@ Đang hiển thị %1$d trên %2$d Nhấn lại để thoát + + Tỷ lệ nguyên + Sử dụng hệ số tỷ lệ nguyên lớn nhất có thể vừa màn hình. Nếu nguồn quá lớn, toàn bộ hình ảnh sẽ được thu vừa để tránh bị cắt. Độ phân giải được thiết lập riêng. diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index e2f20e1e19..d95be01abc 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -4076,4 +4076,7 @@ 已显示 %1$d / %2$d 再按一次返回键退出 + + 整数缩放 + 使用能够容纳的最大整数缩放倍数。如果源图像过大,则缩放整张图像以避免裁切。分辨率单独设置。 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 978f3efc83..50d5590f72 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -4076,4 +4076,7 @@ 已顯示 %1$d / %2$d 再按一次返回鍵退出 + + 整數縮放 + 使用可容納的最大整數縮放倍數。如果來源圖像太大,便縮放整張圖像以避免裁切。解像度會另外設定。 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 8c733aa7d8..431ff323a0 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -4076,4 +4076,7 @@ 已顯示 %1$d / %2$d 再按一次返回鍵退出 + + 整數縮放 + 使用可容納的最大整數縮放倍數。如果來源影像太大,會縮放整張影像以避免裁切。解析度會另外設定。 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e1df2af429..36bf2d60de 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2659,6 +2659,10 @@ Keep proportions Stretch to display Image scaling + Integer scaling + Uses the largest whole-number scale that fits. If the source is too large, fits the full image to avoid cropping. Resolution is configured separately. + Fit + Auto Scaling filter Shared by Steam and Desktop. Applies live. Shared by Steam and Desktop. From b6391ed8c00810ac5d4c9faf5f87ab4aad3a2731 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Sun, 15 Nov 2026 16:40:45 -0500 Subject: [PATCH 02/52] feat(agent): shipped rules and skills for every harness, with a user layer and tool health (#2682) --- app/build.gradle | 4 +- app/src/main/assets/agent/droiddeck-scenario | 2 + .../droiddeck/launcher/agent/AgentHarness.kt | 8 ++ .../com/droiddeck/launcher/agent/AgentHost.kt | 12 +- .../droiddeck/launcher/agent/AgentSetup.kt | 116 ++++++++++++++++- .../com/droiddeck/launcher/ui/AgentPage.kt | 8 +- app/src/main/res/values-ar/strings.xml | 1 + app/src/main/res/values-b+es+419/strings.xml | 1 + app/src/main/res/values-bg/strings.xml | 1 + app/src/main/res/values-cs/strings.xml | 1 + app/src/main/res/values-da/strings.xml | 1 + app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-el/strings.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-fi/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-hi/strings.xml | 1 + app/src/main/res/values-hu/strings.xml | 1 + app/src/main/res/values-in/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-ko/strings.xml | 1 + app/src/main/res/values-ms/strings.xml | 1 + app/src/main/res/values-nb/strings.xml | 1 + app/src/main/res/values-nl/strings.xml | 1 + app/src/main/res/values-pl/strings.xml | 1 + app/src/main/res/values-pt-rPT/strings.xml | 1 + app/src/main/res/values-pt/strings.xml | 1 + app/src/main/res/values-ro/strings.xml | 1 + app/src/main/res/values-ru/strings.xml | 1 + app/src/main/res/values-sv/strings.xml | 1 + app/src/main/res/values-th/strings.xml | 1 + app/src/main/res/values-tr/strings.xml | 1 + app/src/main/res/values-uk/strings.xml | 1 + app/src/main/res/values-vi/strings.xml | 1 + app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + .../launcher/agent/AgentHelpersTest.kt | 117 ++++++++++++++++++ docs/agent-control.md | 12 ++ tools/agent/AGENTS.md | 74 +++++++++++ tools/agent/dd-lab-build | 3 + tools/agent/skills/diagnose-game/SKILL.md | 41 ++++++ .../skills/reproduce-with-input/SKILL.md | 41 ++++++ tools/tests/test_dd_lab_build.py | 24 ++++ 46 files changed, 478 insertions(+), 17 deletions(-) create mode 100755 app/src/main/assets/agent/droiddeck-scenario create mode 100644 app/src/test/java/com/droiddeck/launcher/agent/AgentHelpersTest.kt create mode 100644 tools/agent/AGENTS.md create mode 100644 tools/agent/skills/diagnose-game/SKILL.md create mode 100644 tools/agent/skills/reproduce-with-input/SKILL.md diff --git a/app/build.gradle b/app/build.gradle index 825792f20f..4ca98a45db 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -278,8 +278,10 @@ def stageRuntimeAssets = tasks.register('stageRuntimeAssets', Sync) { dependsOn(stageSessionScripts) from(layout.projectDirectory.dir('src/main/assets')) { exclude 'pulseaudio.tzst' } from(rootProject.file('tools/linuxfs/innoextract')) - from(rootProject.file('tools')) { include 'droiddeckctl', 'adb_device.py', 'proot_profile.py'; into('agent/ctl') } + from(rootProject.file('tools')) { include 'droiddeckctl', 'droiddeck-scenario', 'adb_device.py', 'proot_profile.py'; into('agent/ctl') } + from(rootProject.file('tools/agent/AGENTS.md')) { into('agent/ctl') } from(rootProject.file('docs/agent-control.md')) { into('agent/ctl') } + from(rootProject.file('tools/agent/skills')) { into('agent/skills') } from(layout.buildDirectory.dir('prepared-assets')) into(runtimeAssetsDir) } diff --git a/app/src/main/assets/agent/droiddeck-scenario b/app/src/main/assets/agent/droiddeck-scenario new file mode 100755 index 0000000000..8d04eabbf6 --- /dev/null +++ b/app/src/main/assets/agent/droiddeck-scenario @@ -0,0 +1,2 @@ +#!/bin/sh +exec python3 /root/.local/share/droiddeck/ctl/droiddeck-scenario "$@" diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentHarness.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentHarness.kt index ca1c51c59e..149adf6456 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentHarness.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentHarness.kt @@ -35,6 +35,10 @@ interface AgentHarness { fun input(message: String): String? = null /** One line of the CLI's output, or null when it carries nothing to show. */ fun parse(line: String): AgentEvent? + /** The folder, under the userland's root, where the CLI loads user skills (`/SKILL.md`). */ + val skills: String + /** The CLI's global instructions file under the userland's root, where DroidDeck keeps its rules in a marked block. */ + val instructions: String /** Sets the CLI's own defaults in the userland before it runs; [rootfs] is the userland's root. */ fun prepare(rootfs: File) {} /** Context and plan limits the CLI keeps on disk rather than printing, read once a turn of [conversation] is done. */ @@ -83,6 +87,8 @@ object ClaudeCode : AgentHarness { * Commits and pull requests the agent makes carry no Claude Code credit or co-author line by * default. Only keys the user has not set are written, so their own choice stays. */ + override val skills = "root/.claude/skills" + override val instructions = "root/.claude/CLAUDE.md" override fun prepare(rootfs: File) { val file = File(rootfs, "root/.claude/settings.json") val settings = if (file.exists()) runCatching { JSONObject(file.readText()) }.getOrNull() ?: return else JSONObject() @@ -254,6 +260,8 @@ object Codex : AgentHarness { override val id = "codex" override val name = "Codex" override val binary = "/root/.local/bin/codex" + override val skills = "root/.codex/skills" + override val instructions = "root/.codex/AGENTS.md" // Code mode runs in a helper that each release ships as its own download. private const val HOST = "/root/.local/bin/codex-code-mode-host" override val files get() = listOf(binary, HOST) diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentHost.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentHost.kt index d4cf0035b9..de00d5ce73 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentHost.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentHost.kt @@ -68,18 +68,10 @@ object AgentHost { @VisibleForTesting internal const val BRIEF = "You run inside DroidDeck on the user's handheld, in its Linux userland (Ubuntu under proot, aarch64), " + "and the user talks to you from DroidDeck's Agent tab, often on a small screen, so keep replies short. " + - "droiddeckctl inspects and drives the app over loopback adb (\$ADB_SERIAL); its guide is ${AgentSetup.CTL}/agent-control.md. " + - "Steam, the desktop and games run in DroidDeck's session, a separate guest from yours: a program you start here is not in it and has no screen. " + - "Reach the session through droiddeckctl: state, start steam, stop, launch, quit, focus, screenshot, logs, and guest to run a command inside it. " + - "Starting, stopping or restarting a session leaves you running. " + + "DroidDeck's rules for working here are in your global instructions file (~/.claude/CLAUDE.md or ~/.codex/AGENTS.md); " + + "if they are not loaded, read ${AgentSetup.CTL}/AGENTS.md before acting on the device. " + "Never kill by a command-line pattern (pkill -f, pgrep -f piped to kill): your own command line holds the user's message, so the pattern matches you. " + - "End a game with droiddeckctl quit, the session with droiddeckctl stop, anything else by its pid. " + - "dd-lab-build builds the checkout as a Lab build and restarts DroidDeck on it (docs/lab-builds.md). DroidDeck runs the build in a " + - "process of its own and shows the user its progress and time left; dd-lab-build follows that build's log until it is done. " + - "Run it with run_in_background and keep checking its output, so the user can talk to you meanwhile. " + - "The restart ends this process, and this conversation continues on the new build. " + "Files the user attaches are listed at the end of their message, under /root/.cache/droiddeck/attachments. " + - "Commits and pull requests you make are the user's own: add no co-author line, AI credit or generated-by note. " + "To have the user pick between options, end your reply with a fenced code block whose language is choices, one short option per line, " + "and end your turn: DroidDeck shows them as buttons and sends the one picked as the next message." diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentSetup.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentSetup.kt index 1ff5475b6e..d8d57abd24 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentSetup.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentSetup.kt @@ -4,6 +4,7 @@ import android.content.Context import android.os.Handler import android.os.Looper import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateMapOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue @@ -40,7 +41,9 @@ object AgentSetup { private val main = Handler(Looper.getMainLooper()) private const val REPO = "https://github.com/Droid-Deck/DroidDeck.git" private const val CHECKOUT = "/root/DroidDeck" - private val HELPERS = listOf("android-open", "dd-gh-login", "droiddeckctl") + private val HELPERS = listOf("android-open", "dd-gh-login", "droiddeckctl", "droiddeck-scenario") + /** DroidDeck's own skills (tools/agent/skills), given to every harness. */ + private const val SKILLS = "agent/skills" internal const val CTL = "/root/.local/share/droiddeck/ctl" private const val PROBE_TIMEOUT_S = 60L @@ -187,11 +190,98 @@ object AgentSetup { /** Written before every step, so the helpers a step relies on are there and match this DroidDeck version. */ internal fun installHelpers(app: Context) { val root = LinuxRuntime.rootDir(app) + val failed = mutableListOf() + fun attempt(what: String, block: () -> Unit) = runCatching(block).onFailure { + android.util.Log.w("AgentSetup", "could not install $what", it) + failed += what + } val bin = File(root, "root/.local/bin").apply { mkdirs() } - for (name in HELPERS) copyAsset(app, "agent/$name", File(bin, name)) + for (name in HELPERS) attempt(name) { copyAsset(app, "agent/$name", File(bin, name)) } val ctl = File(root, CTL.removePrefix("/")).apply { mkdirs() } - for (name in app.assets.list("agent/ctl").orEmpty()) copyAsset(app, "agent/ctl/$name", File(ctl, name)) + for (name in app.assets.list("agent/ctl").orEmpty()) attempt("ctl/$name") { copyAsset(app, "agent/ctl/$name", File(ctl, name)) } + val skills = app.assets.list(SKILLS).orEmpty().associateWith { app.assets.list("$SKILLS/$it").orEmpty().toList() } + failed += installSkills(root, skills) { app.assets.open("$SKILLS/$it") } + attempt("AGENTS.md") { + val rules = app.assets.open("agent/ctl/AGENTS.md").use { it.readBytes().decodeToString() } + failed += installInstructions(root, rules) + } unpinAdbSerial(File(root, "root/.bashrc")) + main.post { problems.clear(); problems.addAll(failed.distinct()) } + } + + /** What [installHelpers] could not install last time, shown in the Agent tab; empty when all is in place. */ + val problems = mutableStateListOf() + + /** + * Writes each of DroidDeck's [skills] (name to its files) into every harness's skills folder, so + * Claude Code, Codex and any later harness load the same ones, as of this DroidDeck version. + * Skills the user added there are left alone. Returns the skills that could not be written. + */ + internal fun installSkills(root: File, skills: Map>, open: (String) -> java.io.InputStream): List { + val failed = mutableListOf() + for (harness in AgentHarness.all) for ((name, files) in skills) runCatching { + val dir = File(root, "${harness.skills}/$name") + // A folder of that name without DroidDeck's mark is the user's own skill: keep it. + if (dir.exists() && !File(dir, SKILL_MARK).exists()) return@runCatching + dir.mkdirs() + // Marked before copying, so a copy that fails part way is retried next turn, not taken for the user's. + File(dir, SKILL_MARK).writeText("Installed by DroidDeck and replaced on every turn. Delete this file to keep your own edits.\n") + for (file in files) open("$name/$file").use { replaceFile(it, File(dir, file), executable = false) } + }.onFailure { + android.util.Log.w("AgentSetup", "could not install skill $name for ${harness.name}", it) + failed += "skill $name" + } + return failed + } + + /** Marks a skill folder as DroidDeck's, so it may be replaced; one without it belongs to the user. */ + internal const val SKILL_MARK = ".droiddeck" + + /** + * Where [file] really is when it is a symlink, as the guest sees it: an absolute target is a + * userland path, so it is looked up under [root]. A dotfiles link keeps working that way. + */ + internal fun guestTarget(root: File, file: File): File { + var current = file + repeat(8) { + val path = current.toPath() + if (!java.nio.file.Files.isSymbolicLink(path)) return current + val target = java.nio.file.Files.readSymbolicLink(path).toString() + current = if (target.startsWith("/")) File(root, target.removePrefix("/")) else File(current.parentFile, target) + } + return current + } + + internal const val BLOCK_BEGIN = "" + internal const val BLOCK_END = "" + + /** + * Puts DroidDeck's [rules] in a marked block of every harness's global instructions file, + * keeping whatever the user wrote around it. Returns the files that could not be written. + */ + internal fun installInstructions(root: File, rules: String): List { + val failed = mutableListOf() + for (harness in AgentHarness.all) runCatching { + val file = guestTarget(root, File(root, harness.instructions)).apply { parentFile?.mkdirs() } + val existing = if (file.exists()) file.readText() else null + val merged = withBlock(existing, rules) + if (merged != existing) replaceFile(merged.byteInputStream(), file, executable = false) + }.onFailure { + android.util.Log.w("AgentSetup", "could not write ${harness.instructions}", it) + failed += harness.instructions.substringAfterLast("root/") + } + return failed + } + + /** [existing] with DroidDeck's block set to [rules]: replaced in place, or put first when there is none yet. */ + internal fun withBlock(existing: String?, rules: String): String { + val block = "$BLOCK_BEGIN\n${rules.trim()}\n$BLOCK_END\n" + if (existing.isNullOrBlank()) return block + val start = existing.indexOf(BLOCK_BEGIN) + val end = existing.indexOf(BLOCK_END, start.coerceAtLeast(0)) + if (start < 0 || end < 0) return "$block\n$existing" + val after = existing.substring(end + BLOCK_END.length).removePrefix("\n") + return existing.substring(0, start) + block + after } /** Older tools/agent/setup pinned the adb port in .bashrc, which overrides the live port DroidDeck passes. */ @@ -201,8 +291,24 @@ object AgentSetup { if (fixed != text) runCatching { bashrc.writeText(fixed) } } + /** + * Written beside [target] and renamed over it, so a symlink left there by a hand-made setup is + * replaced rather than followed: its absolute target is a userland path the app cannot reach, + * and the failed write stopped every helper after it, the droiddeckctl guide included. + */ private fun copyAsset(app: Context, asset: String, target: File) { - app.assets.open(asset).use { input -> target.outputStream().use { input.copyTo(it) } } - target.setExecutable(true, false) + app.assets.open(asset).use { replaceFile(it, target) } + } + + /** Replaces [target], or the symlink at it, with [input]. */ + internal fun replaceFile(input: java.io.InputStream, target: File, executable: Boolean = true) { + // A unique name, since an agent turn and a setup step can install at the same time. + val staged = File.createTempFile(".${target.name}.", ".part", target.parentFile) + staged.outputStream().use { input.copyTo(it) } + if (executable) staged.setExecutable(true, false) + if (!staged.renameTo(target)) { + staged.delete() + throw java.io.IOException("could not replace $target") + } } } 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 30e7e9e01b..ae1826bbde 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/AgentPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/AgentPage.kt @@ -567,7 +567,8 @@ private fun labStage(lab: com.droiddeck.launcher.agent.LabProgress) = when (lab. else -> stringResource(R.string.agent_lab_stage_starting) } -private fun hasActivity() = AgentHost.lab != null || AgentHost.queue.isNotEmpty() || currentTodo() != null +private fun hasActivity() = AgentHost.lab != null || AgentHost.queue.isNotEmpty() || currentTodo() != null || + com.droiddeck.launcher.agent.AgentSetup.problems.isNotEmpty() /** The todo item in progress and how many are done, while the agent works through a list. */ private fun currentTodo(): String? { @@ -594,6 +595,11 @@ private fun AgentActivity(labOpen: Boolean, onLab: () -> Unit) { Text(todo, fontSize = 12.5.sp, color = pal.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.widthIn(max = 220.dp)) } } + val problems = com.droiddeck.launcher.agent.AgentSetup.problems + if (problems.isNotEmpty()) AgentChip(warn = true, tag = "agent-tools-missing") { + Text(stringResource(R.string.agent_tools_missing, problems.joinToString(", ")), fontSize = 12.5.sp, color = AttentionAmber, + maxLines = 2, overflow = TextOverflow.Ellipsis, modifier = Modifier.widthIn(max = 260.dp)) + } for (queued in AgentHost.queue) AgentChip(warn = true) { Text(stringResource(R.string.agent_queued, queued.text), fontSize = 12.5.sp, color = AttentionAmber, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.widthIn(max = 180.dp)) diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 095fb1995e..1f05b663c9 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -1195,6 +1195,7 @@ اكتب لإضافة الرسالة التالية إلى الانتظار إضافة إلى الانتظار التالي: %1$s + أدوات الوكيل غير مثبتة: %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 2e050014fd..17d84ace22 100644 --- a/app/src/main/res/values-b+es+419/strings.xml +++ b/app/src/main/res/values-b+es+419/strings.xml @@ -1213,6 +1213,7 @@ Escribe para encolar el siguiente mensaje Encolar Siguiente: %1$s + Herramientas del agente sin instalar: %1$s No enviar Adjuntar Quitar diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 82393e0483..db5d6f35fd 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -1183,6 +1183,7 @@ Въведете, за да наредите следващото съобщение В опашката Следващо: %1$s + Инструментите на агента не са инсталирани: %1$s Не изпращай Прикачи Премахни diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index be4c2e1b25..f640a9b2d4 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -1189,6 +1189,7 @@ Psaním zařadíte další zprávu do fronty Zařadit do fronty Další: %1$s + Nástroje agenta nejsou nainstalované: %1$s Neposílat Přiložit Odebrat diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index 5dce74fc53..f24bc117e4 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -1183,6 +1183,7 @@ Skriv for at sætte den næste besked i kø Sæt i kø Næste: %1$s + Agentens værktøjer er ikke installeret: %1$s Send ikke Vedhæft Fjern diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 10bb9f7c16..3836e1672d 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -1175,6 +1175,7 @@ Tippen, um die nächste Nachricht einzureihen Einreihen Als Nächstes: %1$s + Agent-Werkzeuge nicht installiert: %1$s Nicht senden Anhängen Entfernen diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 037a7da150..8aab95076f 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -1183,6 +1183,7 @@ Γράψτε για να προσθέσετε το επόμενο μήνυμα στην ουρά Στην ουρά Επόμενο: %1$s + Τα εργαλεία του πράκτορα δεν εγκαταστάθηκαν: %1$s Να μην σταλεί Επισύναψη Αφαίρεση diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 73f08e89a4..ab614c3ce7 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -1186,6 +1186,7 @@ Escribe para encolar el siguiente mensaje Encolar Siguiente: %1$s + Herramientas del agente sin instalar: %1$s No enviar Adjuntar Quitar diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index a27e6228bc..856a984fbd 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -1183,6 +1183,7 @@ Kirjoita lisätäksesi seuraavan viestin jonoon Jono Seuraava: %1$s + Agentin työkaluja ei ole asennettu: %1$s Älä lähetä Liitä Poista diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 80765a1c86..e2a1c927fa 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -1186,6 +1186,7 @@ Tapez pour mettre le prochain message en attente Mettre en attente Suivant : %1$s + Outils de l’agent non installés : %1$s Ne pas envoyer Joindre Supprimer diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index 3acc513034..7c32f0bcbe 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -1183,6 +1183,7 @@ अगला संदेश कतार में जोड़ने के लिए टाइप करें कतार में जोड़ें अगला: %1$s + एजेंट टूल इंस्टॉल नहीं हुए: %1$s न भेजें संलग्न करें हटाएँ diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index cc87c4de8e..2c8e9de881 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -1183,6 +1183,7 @@ Gépelj a következő üzenet sorba állításához Sorba állítás Következő: %1$s + Az ügynök eszközei nincsenek telepítve: %1$s Ne küldd el Csatolás Eltávolítás diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 5ebb1a34f9..06b1ad1b79 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -1180,6 +1180,7 @@ Ketik untuk mengantrekan pesan berikutnya Antrekan Berikutnya: %1$s + Alat agen tidak terpasang: %1$s Jangan kirim Lampirkan Hapus diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index e7817522bd..8ee4cf0869 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -1178,6 +1178,7 @@ Digita per mettere in coda il messaggio successivo Metti in coda Prossimo: %1$s + Strumenti dell’agente non installati: %1$s Non inviare Allega Rimuovi diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index c2a67cc84d..dda237f330 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -1180,6 +1180,7 @@ 入力すると次のメッセージをキューに追加できます キューに追加 次: %1$s + エージェントのツールが未インストール: %1$s 送信しない 添付 削除 diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index dd65900c76..5516555fb4 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -1180,6 +1180,7 @@ 입력하면 다음 메시지가 대기열에 추가됩니다 대기열에 추가 다음: %1$s + 에이전트 도구가 설치되지 않음: %1$s 보내지 않기 첨부 제거 diff --git a/app/src/main/res/values-ms/strings.xml b/app/src/main/res/values-ms/strings.xml index 9701ed1542..2630036f56 100644 --- a/app/src/main/res/values-ms/strings.xml +++ b/app/src/main/res/values-ms/strings.xml @@ -1180,6 +1180,7 @@ Taip untuk membariskan mesej seterusnya Baris gilir Seterusnya: %1$s + Alat ejen tidak dipasang: %1$s Jangan hantar Lampirkan Alih keluar diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index 19c503f02d..8f3ee6a6aa 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -1183,6 +1183,7 @@ Skriv for å legge neste melding i kø Legg i kø Neste: %1$s + Agentverktøy er ikke installert: %1$s Ikke send Legg ved Fjern diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 4bb4d3223b..1cd50ef96e 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -1183,6 +1183,7 @@ Typ om het volgende bericht in de wachtrij te zetten In wachtrij Volgende: %1$s + Agenttools niet geïnstalleerd: %1$s Niet verzenden Bijvoegen Verwijderen diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index f8620690ac..3ed82432cd 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -1189,6 +1189,7 @@ Wpisz, aby zakolejkować następną wiadomość Zakolejkuj Następna: %1$s + Narzędzia agenta nie są zainstalowane: %1$s Nie wysyłaj Załącz Usuń diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 09831c53f2..3ba244fb02 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -1178,6 +1178,7 @@ Escreva para pôr a mensagem seguinte na fila Pôr na fila Seguinte: %1$s + Ferramentas do agente não instaladas: %1$s Não enviar Anexar Remover diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 42248a4fb5..2f4344522e 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -1185,6 +1185,7 @@ Digite para enfileirar a próxima mensagem Enfileirar Próxima: %1$s + Ferramentas do agente não instaladas: %1$s Não enviar Anexar Remover diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index c00b97f0e9..41224c92f0 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -1186,6 +1186,7 @@ Scrie pentru a pune următorul mesaj în coadă Pune în coadă Următorul: %1$s + Instrumentele agentului nu sunt instalate: %1$s Nu trimite Atașează Elimină diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index f373bcf903..99a4421e20 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -1189,6 +1189,7 @@ Введите текст, чтобы поставить следующее сообщение в очередь В очередь Далее: %1$s + Инструменты агента не установлены: %1$s Не отправлять Прикрепить Удалить diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index bdfb11dd91..a2f94dc88c 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -1183,6 +1183,7 @@ Skriv för att köa nästa meddelande Köa Nästa: %1$s + Agentens verktyg är inte installerade: %1$s Skicka inte Bifoga Ta bort diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index 2a74e0f185..fa5a17e016 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -1180,6 +1180,7 @@ พิมพ์เพื่อเข้าคิวข้อความถัดไป เข้าคิว ถัดไป: %1$s + ยังไม่ได้ติดตั้งเครื่องมือของเอเจนต์: %1$s ไม่ต้องส่ง แนบ นำออก diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 8a72d0a584..cf874e3756 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -1175,6 +1175,7 @@ Sonraki mesajı sıraya almak için yazın Sıraya ekle Sıradaki: %1$s + Ajan araçları yüklenmedi: %1$s Gönderme Ekle Kaldır diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index a09c1234f6..94dba311b6 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -1189,6 +1189,7 @@ Введіть текст, щоб поставити наступне повідомлення в чергу Поставити в чергу Далі: %1$s + Інструменти агента не встановлено: %1$s Не надсилати Прикріпити Видалити diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index e0ae6e7e6e..78043b8bc6 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -1180,6 +1180,7 @@ Nhập để xếp tin nhắn tiếp theo vào hàng đợi Xếp hàng Tiếp theo: %1$s + Chưa cài công cụ của tác tử: %1$s Không gửi Đính kèm Xóa diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index d95be01abc..f2dc1017d5 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -1263,6 +1263,7 @@ 输入以排队下一条消息 排队 下一条:%1$s + 智能体工具未安装:%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 50d5590f72..3bf2efdd85 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -1179,6 +1179,7 @@ 輸入即可排入下一則訊息 排入 下一則:%1$s + 智能體工具未安裝:%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 431ff323a0..219bf2d709 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -1179,6 +1179,7 @@ 輸入以排入下一則訊息 排入佇列 下一則:%1$s + 智慧代理工具未安裝:%1$s 不要傳送 附加 移除 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 36bf2d60de..30875a9553 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1284,6 +1284,7 @@ Type to queue the next message Queue Next: %1$s + Agent tools not installed: %1$s Don\'t send Attach Remove diff --git a/app/src/test/java/com/droiddeck/launcher/agent/AgentHelpersTest.kt b/app/src/test/java/com/droiddeck/launcher/agent/AgentHelpersTest.kt new file mode 100644 index 0000000000..8de7a2d008 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/agent/AgentHelpersTest.kt @@ -0,0 +1,117 @@ +package com.droiddeck.launcher.agent + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder +import java.io.File +import java.nio.file.Files + +class AgentHelpersTest { + @get:Rule val tmp = TemporaryFolder() + + @Test fun aSymlinkLeftByAHandMadeSetupIsReplacedNotFollowed() { + val bin = tmp.newFolder("bin") + val old = tmp.newFile("old-droiddeckctl").apply { writeText("old") } + val target = File(bin, "droiddeckctl") + Files.createSymbolicLink(target.toPath(), old.toPath()) + + AgentSetup.replaceFile("new".byteInputStream(), target) + + assertFalse(Files.isSymbolicLink(target.toPath())) + assertEquals("new", target.readText()) + assertEquals("old", old.readText()) + assertTrue(target.canExecute()) + } + + @Test fun aDanglingSymlinkIsReplaced() { + val bin = tmp.newFolder("bin") + val target = File(bin, "droiddeckctl") + Files.createSymbolicLink(target.toPath(), File("/no/such/userland/path").toPath()) + + AgentSetup.replaceFile("new".byteInputStream(), target) + + assertEquals("new", target.readText()) + assertEquals(listOf("droiddeckctl"), bin.list()!!.toList()) + } + + @Test fun skillsGoToEveryHarnessAndLeaveTheUsersOwnAlone() { + val root = tmp.newFolder("rootfs") + val mine = File(root, "root/.claude/skills/my-skill/SKILL.md").apply { parentFile!!.mkdirs(); writeText("mine") } + val stale = File(root, "root/.codex/skills/diagnose-game/SKILL.md").apply { parentFile!!.mkdirs(); writeText("old") } + File(stale.parentFile, AgentSetup.SKILL_MARK).writeText("") + + val failed = AgentSetup.installSkills(root, mapOf("diagnose-game" to listOf("SKILL.md"))) { "new $it".byteInputStream() } + + assertEquals(emptyList(), failed) + for (harness in AgentHarness.all) { + assertEquals("new diagnose-game/SKILL.md", File(root, "${harness.skills}/diagnose-game/SKILL.md").readText()) + } + assertEquals("mine", mine.readText()) + assertFalse(File(root, "${ClaudeCode.skills}/diagnose-game/SKILL.md").canExecute()) + } + + @Test fun aSkillTheUserMadeWithTheSameNameIsKept() { + val root = tmp.newFolder("rootfs3") + val own = File(root, "${ClaudeCode.skills}/diagnose-game/SKILL.md").apply { parentFile!!.mkdirs(); writeText("my version") } + + AgentSetup.installSkills(root, mapOf("diagnose-game" to listOf("SKILL.md"))) { "new".byteInputStream() } + + assertEquals("my version", own.readText()) + assertFalse(File(own.parentFile, AgentSetup.SKILL_MARK).exists()) + assertEquals("new", File(root, "${Codex.skills}/diagnose-game/SKILL.md").readText()) + } + + @Test fun aSkillThatFailedPartWayIsRetriedNextTurn() { + val root = tmp.newFolder("rootfs5") + val skills = mapOf("diagnose-game" to listOf("SKILL.md")) + + val failed = AgentSetup.installSkills(root, skills) { throw java.io.IOException("asset unreadable") } + assertEquals(AgentHarness.all.size, failed.size) + + assertEquals(emptyList(), AgentSetup.installSkills(root, skills) { "new".byteInputStream() }) + for (harness in AgentHarness.all) assertEquals("new", File(root, "${harness.skills}/diagnose-game/SKILL.md").readText()) + } + + @Test fun instructionsBehindAGuestSymlinkAreWrittenWhereItPoints() { + val root = tmp.newFolder("rootfs4") + val dotfile = File(root, "root/dotfiles/CLAUDE.md").apply { parentFile!!.mkdirs(); writeText("my rule\n") } + val link = File(root, ClaudeCode.instructions).apply { parentFile!!.mkdirs() } + Files.createSymbolicLink(link.toPath(), File("/root/dotfiles/CLAUDE.md").toPath()) + + AgentSetup.installInstructions(root, "rules") + + assertTrue(Files.isSymbolicLink(link.toPath())) + assertTrue(dotfile.readText().contains("rules")) + assertTrue(dotfile.readText().endsWith("\nmy rule\n")) + } + + @Test fun theRulesGoFirstInAFileThatHasNoBlockYetAndKeepTheUsersOwn() { + val text = AgentSetup.withBlock("# Mine\nAlways answer in French.\n", "rules v1") + assertEquals("${AgentSetup.BLOCK_BEGIN}\nrules v1\n${AgentSetup.BLOCK_END}\n\n# Mine\nAlways answer in French.\n", text) + } + + @Test fun onlyTheBlockIsReplacedOnTheNextTurn() { + val first = AgentSetup.withBlock("before\n", "rules v1") + "after\n" + val second = AgentSetup.withBlock(first, "rules v2") + assertEquals(first.replace("rules v1", "rules v2"), second) + assertEquals(second, AgentSetup.withBlock(second, "rules v2")) + } + + @Test fun anEmptyOrMissingFileGetsJustTheBlock() { + assertEquals("${AgentSetup.BLOCK_BEGIN}\nrules\n${AgentSetup.BLOCK_END}\n", AgentSetup.withBlock(null, "rules\n")) + assertEquals(AgentSetup.withBlock(null, "rules"), AgentSetup.withBlock(" \n", "rules")) + } + + @Test fun everyHarnessGetsTheRules() { + val root = tmp.newFolder("rootfs2") + val claude = File(root, ClaudeCode.instructions).apply { parentFile!!.mkdirs(); writeText("my rule\n") } + + assertEquals(emptyList(), AgentSetup.installInstructions(root, "rules")) + + for (harness in AgentHarness.all) assertTrue(File(root, harness.instructions).readText().contains("rules")) + assertTrue(claude.readText().endsWith("\nmy rule\n")) + } +} diff --git a/docs/agent-control.md b/docs/agent-control.md index dc9ced7e60..171f0960c7 100644 --- a/docs/agent-control.md +++ b/docs/agent-control.md @@ -22,6 +22,18 @@ and reports every run. works on every display and window. UI Automator, by contrast, dumps whichever window has focus, which on a dual-screen device is often another app's. +## On the device + +The agent in DroidDeck's Agent tab gets its working rules from `tools/agent/AGENTS.md` and its +skills from `tools/agent/skills`. Both ship in the APK; before every turn the app writes the rules +as a marked block into each harness's global instructions (`~/.claude/CLAUDE.md`, +`~/.codex/AGENTS.md`) and the skills into its skills folder (`~/.claude/skills`, `~/.codex/skills`). +Only DroidDeck's own block and skills (folders holding a `.droiddeck` file) are replaced: rules +the user writes outside the block, and skills they add, stay. A symlinked instructions file is +followed, so the block lands in the file it points to. `droiddeckctl`, `droiddeck-scenario` and this guide are installed in +`~/.local/share/droiddeck/ctl` (with `droiddeckctl` and `droiddeck-scenario` on PATH). If any of +these cannot be installed, the Agent tab shows which. + ## Access Player controls and observations work over authorized ADB on any build: `state`, `start`, `stop`, diff --git a/tools/agent/AGENTS.md b/tools/agent/AGENTS.md new file mode 100644 index 0000000000..20b1736bd7 --- /dev/null +++ b/tools/agent/AGENTS.md @@ -0,0 +1,74 @@ +# DroidDeck on-device agent + +You run in DroidDeck's Agent tab, on the user's handheld, in DroidDeck's Linux userland (Ubuntu +under proot, aarch64). The user is often on a small screen: keep replies short. These notes come +from what tripped agents up on real devices. + +## Where you run + +- Steam, the desktop and games run in DroidDeck's session, a separate guest from yours: a program + you start here is not in it and has no screen. Reach it with `droiddeckctl` (guide: + `/root/.local/share/droiddeck/ctl/agent-control.md`): `state`, `start steam`, `stop`, `launch`, + `quit`, `focus`, `screenshot`, `logs`, `pacing`, `thermal`, and `guest` to run a command in it. +- `droiddeckctl stop`, `start steam` and `resume` end or restart only the session. You keep + running, so restart it yourself when a change needs a new session. +- The session shares your filesystem. Steam is in `/root/.local/share/Steam` (its logs in + `logs/`), and the session's live logs are in the folder `state` gives as `session.logDir`. + `logs latest` makes a redacted, partial copy: read the live folder yourself. X properties, + gamescope and the session's processes are only reachable through `guest`. + +## Commands + +- `guest` runs one program, not a shell line: `droiddeckctl guest -- sh -c '...'` for pipes, + `$(...)` or `DISPLAY=:0 xprop ...`. Its answer is JSON; the output is in `stdout.text`. +- `screenshot` takes the path as an argument (`screenshot /tmp/top.png --display 0`); on a + dual-screen device see `droiddeckctl displays`. `prefs get` takes a file (`prefs get session`). +- `input` drives a game session that has drawn a frame. For the launcher's own screens use + `adb -s $ADB_SERIAL shell input keyevent KEYCODE_BACK` and similar. +- `droiddeck-scenario` replays a scripted test through `droiddeckctl` (`--help` for the format). +- Never kill by a command-line pattern (`pkill -f`, `pgrep -f` piped to `kill`): your own command + line holds the user's message, so the pattern matches you. End a game with `droiddeckctl quit`, + the session with `droiddeckctl stop`, anything else by its pid after checking what it is + (`ps -o pid,args -p `): a pid near a game can be the Steam client. +- `DEVICE_RESOLUTION_FAILED`: run `adb devices` and use the serial it lists. +- Do not chain `sleep` before a check. Start long work in the background. In Claude Code, its end + starts you again; other harnesses are not woken, so check it before ending your turn or tell the + user it is still running. + +## What applies when + +- Many session settings (black frame insertion, environment, Proton) are read when a session or + game starts. After changing one, restart the game or the session before judging it. +- With "Return after game" on (the default), quitting a game DroidDeck launched ends the whole + session; `start steam --wait --reuse` before the next launch. Launching a game that is already + 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). + +## Changing DroidDeck + +The source is checked out at `/root/DroidDeck` once the Agent tab's build tools are set up. + +- It often holds the user's uncommitted work and a stale local `main`. Branch from `origin/main` + in a worktree (`git worktree add -b ../ origin/main`). +- `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. +- Python tests run from the repository root: `python3 -m unittest tools.tests.test_x`. Some fail on + the device on `origin/main` too; run them on a worktree of `origin/main` before blaming a change. +- Gradle unit tests rarely run on the device. Leave them to CI and say so rather than retrying. +- If `git push` asks for credentials, run `gh auth setup-git` once. +- Commits and pull requests you make are the user's own: no co-author line, AI credit or + generated-by note. + +## This file + +DroidDeck writes this block into your global instructions (`~/.claude/CLAUDE.md`, +`~/.codex/AGENTS.md`) before every turn, and its skills into `~/.claude/skills` and +`~/.codex/skills`. It replaces only its own block and its own skills (folders holding a `.droiddeck` file): the +user's rules go outside the block, and their skills stay, even one with the same name. Deleting a +skill's `.droiddeck` file keeps local edits to it. To change DroidDeck's, edit `tools/agent/AGENTS.md` and +`tools/agent/skills` in the source. diff --git a/tools/agent/dd-lab-build b/tools/agent/dd-lab-build index 4f5671dc04..33fa47d99f 100755 --- a/tools/agent/dd-lab-build +++ b/tools/agent/dd-lab-build @@ -19,6 +19,9 @@ for arg in "$@"; do --no-restart) mode=no-restart ;; --prepare) mode=prepare ;; --explain) explain=(--info -Pkotlin.build.report.output=file) ;; + # Anything else used to start a full build and restart the app, --help included. + -h|--help) sed -n '2,6s/^# \{0,1\}//p' "$0"; exit 0 ;; + *) echo "dd-lab-build: unknown option $arg (see --help)" >&2; exit 2 ;; esac done started=$(date +%s) diff --git a/tools/agent/skills/diagnose-game/SKILL.md b/tools/agent/skills/diagnose-game/SKILL.md new file mode 100644 index 0000000000..cfb06f72c4 --- /dev/null +++ b/tools/agent/skills/diagnose-game/SKILL.md @@ -0,0 +1,41 @@ +--- +name: diagnose-game +description: Find why a game crashed, hung or ran badly in DroidDeck, from session state and logs +--- + +1. `droiddeckctl state`: `session.phase`, `session.failure`, `session.focus.focusedApp` (769 is + Steam's own UI) and `session.logDir`. +2. Read that log folder directly; it is on your filesystem. Earlier sessions are its siblings: + `ls -t "$(dirname )"`; the crash may be in the one before a restart. `logs latest` + makes a redacted, partial copy with renamed files: use it only to hand logs to someone. + - `games/