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] 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/