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 de45d4b51a..722c6e4029 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentHarness.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentHarness.kt @@ -27,6 +27,8 @@ interface AgentHarness { fun turn(message: String, conversation: String?, options: Options): List /** One line of the CLI's output, or null when it carries nothing to show. */ fun parse(line: String): AgentEvent? + /** Sets the CLI's own defaults in the userland before it runs; [rootfs] is the userland's root. */ + fun prepare(rootfs: File) {} data class Model(val id: String, val label: String) @@ -59,6 +61,28 @@ object ClaudeCode : AgentHarness { override val signIn = listOf(binary, "auth", "login", "--claudeai") override val plans = true + /** + * 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 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() + var changed = false + if (!settings.has("includeCoAuthoredBy")) { + settings.put("includeCoAuthoredBy", false) + changed = true + } + if (!settings.has("attribution")) { + settings.put("attribution", JSONObject().put("commit", "").put("pr", "")) + changed = true + } + if (changed) runCatching { + file.parentFile?.mkdirs() + file.writeText(settings.toString(2) + "\n") + } + } + override fun models(rootfs: File) = listOf( AgentHarness.Model("opus", "Opus"), AgentHarness.Model("sonnet", "Sonnet"), AgentHarness.Model("haiku", "Haiku"), ) 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 bbb99b744d..b1e939b088 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentHost.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentHost.kt @@ -55,7 +55,8 @@ object AgentHost { "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." + "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." val entries = mutableStateListOf() val queue = mutableStateListOf() @@ -250,6 +251,7 @@ object AgentHost { val command = current.turn(prompt, conversation, AgentHarness.Options(model, plan && current.plans, BRIEF)) val workdir = workspace(app) Thread({ + runCatching { current.prepare(LinuxRuntime.rootDir(app)) } val child = try { guest(app, command, workdir).start() } catch (e: Exception) { 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 47efab507d..b9971ced15 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentSetup.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentSetup.kt @@ -93,6 +93,7 @@ object AgentSetup { Thread({ val result = runCatching { installHelpers(app) + runCatching { harness.prepare(LinuxRuntime.rootDir(app)) } val child = AgentHost.guest(app, command).start() child.outputStream.close() child.inputStream.bufferedReader().forEachLine { line -> diff --git a/app/src/test/java/com/droiddeck/launcher/agent/AgentHostTest.kt b/app/src/test/java/com/droiddeck/launcher/agent/AgentHostTest.kt index 23a176c201..13e88edac4 100644 --- a/app/src/test/java/com/droiddeck/launcher/agent/AgentHostTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/agent/AgentHostTest.kt @@ -131,6 +131,27 @@ class AgentHostTest { assertEquals("ls", shellCommand("ls")) } + @Test fun claudeCodeDefaultsToNoAttributionAndKeepsTheUsersChoice() { + val root = Files.createTempDirectory("rootfs").toFile() + val settings = File(root, "root/.claude/settings.json") + ClaudeCode.prepare(root) + val written = org.json.JSONObject(settings.readText()) + assertEquals(false, written.getBoolean("includeCoAuthoredBy")) + assertEquals("", written.getJSONObject("attribution").getString("commit")) + assertEquals("", written.getJSONObject("attribution").getString("pr")) + + settings.writeText("""{"includeCoAuthoredBy":true,"model":"opus"}""") + ClaudeCode.prepare(root) + val kept = org.json.JSONObject(settings.readText()) + assertEquals(true, kept.getBoolean("includeCoAuthoredBy")) + assertEquals("opus", kept.getString("model")) + assertTrue(kept.has("attribution")) + + settings.writeText("not json") + ClaudeCode.prepare(root) + assertEquals("not json", settings.readText()) + } + @Test fun aTurnWithoutAnEndWasInterrupted() { assertTrue(AgentHost.interrupted(listOf(Entry.Asked("hi"), Entry.Used("1", "Bash", "dd-lab-build")))) assertEquals(false, AgentHost.interrupted(listOf(Entry.Asked("hi"), Entry.Finished(null))))