A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
Team widget: the rule for which agents it shows, and the whole roster on the widget content
Clauded9c3da378a19
diff --git a/android/app/src/main/kotlin/com/coucou/android/core/TeamChoice.kt b/android/app/src/main/kotlin/com/coucou/android/core/TeamChoice.ktnew file mode 100644index 00000000..2eb749e1--- /dev/null+++ b/android/app/src/main/kotlin/com/coucou/android/core/TeamChoice.kt@@ -0,0 +1,70 @@+package com.coucou.android.core++import com.coucou.android.mochi.BotState++/**+ * The Team widget: the user picks which agents it shows (up to [MAX]), one choice per widget. This is the pure part: what can be picked, how+ * a choice is stored and read back (a short comma list that only ever holds ids of the catalog), and which rows the widget draws.+ *+ * An agent that is picked and not running is still shown, as "Not running", so the widget keeps its shape. With nothing picked (the widget was+ * added without opening the choice screen) it shows the busiest agents, like the List.+ */+object TeamChoice {+ /** The most agents one Team widget shows (two rows of two). */+ const val MAX = 4++ /** What can be picked: the agents and workspace tools of the catalog, never an AI provider or a service. */+ val candidates: List<PillDefinition> = Pills.catalog.filter { it.category == PillCategory.WORKSPACE || it.category == PillCategory.AGENT }++ private val ids: Set<String> = candidates.map { it.id }.toSet()++ /** The name the picker and the widget use for an agent that is not running (the Claude Code hook arrives on the VS Code pill). */+ fun nameOf(id: String): String =+ if (id == Pills.DEFAULT_MAIN_PILL) Texts.t("widget_sample_claude", "Claude Code") else Pills.byId(id)?.name ?: id++ /** The choice as it is stored: ids in the user's order, nothing else. */+ fun encode(chosen: List<String>): String = clean(chosen).joinToString(",")++ /** The choice read back. Anything that is not an id of [candidates] (a stale value, a hand-edited file) is dropped, and a repeat too. */+ fun decode(raw: String?): List<String> = clean(raw?.split(',').orEmpty())++ private fun clean(list: List<String>): List<String> = list.map { it.trim() }.filter { it in ids }.distinct().take(MAX)++ /** Adds [id] at the end if it is not picked and there is room; removes it if it is. */+ fun toggle(chosen: List<String>, id: String): List<String> = when {+ id !in ids -> clean(chosen)+ id in chosen -> clean(chosen).filter { it != id }+ else -> clean(chosen + id)+ }++ /** True when [id] can still be added (there is room), or is already picked and can be removed. */+ fun canToggle(chosen: List<String>, id: String): Boolean = id in ids && (id in chosen || clean(chosen).size < MAX)++ /**+ * The rows to draw. Not connected: none (the widget shows its empty state). Connected: the picked agents in the picked order, each as it runs+ * or as [notRunning]; with nothing picked, the first [MAX] of [roster] (already most urgent first).+ */+ fun rows(connected: Boolean, roster: List<WidgetTile>, chosen: List<String>, notRunning: String): List<WidgetTile> {+ if (!connected) return emptyList()+ val picked = clean(chosen)+ if (picked.isEmpty()) return roster.take(MAX)+ return picked.map { id ->+ roster.firstOrNull { it.pillId == id }+ ?: WidgetTile(id, nameOf(id), BotState.IDLE, notRunning, WidgetData.parse(Pills.byId(id)?.colorHex) ?: WidgetTone.IDLE.argb)+ }+ }++ /** The look of the whole widget: orange if any shown agent waits for you, else the most urgent shown tone, else the calm one. */+ fun look(connected: Boolean, rows: List<WidgetTile>): WidgetTone = when {+ !connected -> WidgetTone.MUTED+ rows.any { it.tone == WidgetTone.ATTENTION } -> WidgetTone.ATTENTION+ rows.any { it.tone == WidgetTone.TROUBLE } -> WidgetTone.TROUBLE+ rows.any { it.tone == WidgetTone.WORKING } -> WidgetTone.WORKING+ rows.any { it.tone == WidgetTone.DONE } -> WidgetTone.DONE+ else -> WidgetTone.IDLE+ }++ /** What TalkBack says for the whole card: each shown agent with its state, or the one clear line when there is none. */+ fun spoken(rows: List<WidgetTile>, emptyLine: String): String =+ if (rows.isEmpty()) emptyLine else rows.joinToString(". ") { WidgetSpoken.tile(it) }+}diff --git a/android/app/src/main/kotlin/com/coucou/android/core/WidgetData.kt b/android/app/src/main/kotlin/com/coucou/android/core/WidgetData.ktindex a16a6065..ac48d6d4 100644--- a/android/app/src/main/kotlin/com/coucou/android/core/WidgetData.kt+++ b/android/app/src/main/kotlin/com/coucou/android/core/WidgetData.kt@@ -164,6 +164,8 @@ data class WidgetContent(val today: Int = 0,/** Mochi Big's plan usage: Claude then Codex, each with its main window; empty when the computer sends none or is not connected. */val usageRows: List<UsageRing> = emptyList(),+ /** Every agent that runs, most urgent first (the [tiles] are its first few): the Team widget picks its own from it. */+ val roster: List<WidgetTile> = emptyList(),) {/** Which of the three things Mochi Big's right side shows. */val usageSide: UsageSide get() = when {@@ -258,13 +260,13 @@ object WidgetData {today: Int = 0,nowMs: Long = 0L,): WidgetContent {- val tiles = if (!glance.connected) emptyList() else sessions+ val roster = if (!glance.connected) emptyList() else sessions.sortedBy { GlanceBuilder.rank(it.state) }- .take(MAX_ROWS).map { WidgetTile(it.pillId, nameOf(it.pillId), it.state, GlanceBuilder.lineOf(it), colourOf(it)) }+ val tiles = roster.take(MAX_ROWS)val ring = if (glance.connected) ring(usage, nowMs) else nullval rows = if (glance.connected) usageRows(usage, nowMs) else emptyList()- return WidgetContent(glance.headline, glance.tone, glance.connected, glance.waiting, tiles, ring, today.coerceAtLeast(0), rows)+ return WidgetContent(glance.headline, glance.tone, glance.connected, glance.waiting, tiles, ring, today.coerceAtLeast(0), rows, roster)}/**diff --git a/android/app/src/test/kotlin/com/coucou/android/TeamChoiceTest.kt b/android/app/src/test/kotlin/com/coucou/android/TeamChoiceTest.ktnew file mode 100644index 00000000..4088bd69--- /dev/null+++ b/android/app/src/test/kotlin/com/coucou/android/TeamChoiceTest.kt@@ -0,0 +1,122 @@+package com.coucou.android++import com.coucou.android.core.GlanceBuilder+import com.coucou.android.core.TeamChoice+import com.coucou.android.core.WidgetData+import com.coucou.android.core.WidgetTile+import com.coucou.android.core.WidgetTone+import com.coucou.android.link.SessionInfo+import com.coucou.android.mochi.BotState+import org.junit.Assert.assertEquals+import org.junit.Assert.assertFalse+import org.junit.Assert.assertTrue+import org.junit.Test++class TeamChoiceTest {+ private fun tile(id: String, name: String, state: BotState, word: String = "word") = WidgetTile(id, name, state, word, 0xFF112233.toInt())+ private val running = listOf(+ tile("integration_claude", "Claude Code", BotState.APPROVAL, "Waiting for your approval"),+ tile("agent_codex", "Codex", BotState.WORKING, "Working"),+ tile("agent_gemini", "Gemini CLI", BotState.FINISHED, "Finished"),+ )++ @Test fun onlyAgentsAndWorkspaceToolsCanBePicked() {+ val ids = TeamChoice.candidates.map { it.id }+ assertTrue("agent_codex" in ids && "integration_claude" in ids && "agent_gemini" in ids)+ assertFalse("ai_openai" in ids)+ assertFalse("integration_stripe" in ids)+ assertEquals(ids.size, ids.toSet().size)+ }++ @Test fun aChoiceIsStoredAsACleanShortList() {+ assertEquals("agent_codex,agent_gemini", TeamChoice.encode(listOf("agent_codex", "agent_gemini")))+ assertEquals(listOf("agent_codex", "agent_gemini"), TeamChoice.decode("agent_codex,agent_gemini"))+ assertEquals(emptyList<String>(), TeamChoice.decode(null))+ assertEquals(emptyList<String>(), TeamChoice.decode(""))+ }++ @Test fun anythingThatIsNotACatalogAgentIsDroppedOnTheWayIn() {+ assertEquals(listOf("agent_codex"), TeamChoice.decode(" agent_codex , ai_openai,../x,,agent_codex,<b>"))+ assertEquals(emptyList<String>(), TeamChoice.decode("a".repeat(10_000)))+ assertEquals("agent_codex", TeamChoice.encode(listOf("agent_codex", "not-an-agent", "agent_codex")))+ }++ @Test fun nobodyHoldsMoreThanTheMaximum() {+ val six = TeamChoice.candidates.take(6).map { it.id }+ assertEquals(six.take(TeamChoice.MAX), TeamChoice.decode(six.joinToString(",")))+ assertEquals(TeamChoice.MAX, TeamChoice.encode(six).split(",").size)+ }++ @Test fun togglingAddsAtTheEndRemovesAndStopsAtTheMaximum() {+ var chosen = emptyList<String>()+ val ids = TeamChoice.candidates.map { it.id }+ for (id in ids.take(TeamChoice.MAX)) chosen = TeamChoice.toggle(chosen, id)+ assertEquals(ids.take(TeamChoice.MAX), chosen)+ // Full: another one is refused, the picked ones can still be removed.+ assertFalse(TeamChoice.canToggle(chosen, ids[TeamChoice.MAX]))+ assertEquals(chosen, TeamChoice.toggle(chosen, ids[TeamChoice.MAX]))+ assertTrue(TeamChoice.canToggle(chosen, ids[0]))+ assertEquals(ids.slice(1 until TeamChoice.MAX), TeamChoice.toggle(chosen, ids[0]))+ // Not a catalog id: nothing happens.+ assertEquals(chosen, TeamChoice.toggle(chosen, "ai_openai"))+ assertFalse(TeamChoice.canToggle(emptyList(), "ai_openai"))+ }++ @Test fun theRowsAreTheChosenAgentsInTheChosenOrder() {+ val rows = TeamChoice.rows(true, running, listOf("agent_gemini", "integration_claude"), "Not running")+ assertEquals(listOf("agent_gemini", "integration_claude"), rows.map { it.pillId })+ assertEquals(running[2], rows[0])+ }++ @Test fun aChosenAgentThatDoesNotRunIsShownAsNotRunning() {+ val rows = TeamChoice.rows(true, running, listOf("agent_codex", "agent_amp"), "Not running")+ assertEquals(listOf("Codex", "Amp"), rows.map { it.name })+ assertEquals("Not running", rows[1].stateWord)+ assertEquals(BotState.IDLE, rows[1].state)+ assertEquals(WidgetTone.IDLE, rows[1].tone)+ }++ @Test fun theClaudeCodeHookKeepsItsName() {+ assertEquals("Claude Code", TeamChoice.nameOf("integration_claude"))+ assertEquals("Codex", TeamChoice.nameOf("agent_codex"))+ assertEquals("Claude Code", TeamChoice.rows(true, emptyList(), listOf("integration_claude"), "Not running")[0].name)+ }++ @Test fun withNothingChosenItShowsTheBusiestAgents() {+ val many = (1..6).map { tile("agent_$it", "A$it", BotState.WORKING) }+ assertEquals(many.take(TeamChoice.MAX), TeamChoice.rows(true, many, emptyList(), "Not running"))+ assertEquals(emptyList<WidgetTile>(), TeamChoice.rows(true, emptyList(), emptyList(), "Not running"))+ }++ @Test fun whenTheComputerIsNotThereThereAreNoRows() {+ assertEquals(emptyList<WidgetTile>(), TeamChoice.rows(false, running, listOf("agent_codex"), "Not running"))+ }++ @Test fun anAgentBeyondTheListsFiveRowsStillShowsItsRealState() {+ // Seven agents run; the one picked is the least urgent. It must not be reported as "not running".+ val sessions = (1..7).map { SessionInfo("agent_$it", "Agent $it", if (it == 7) BotState.IDLE else BotState.WORKING, "", 0, 0, 0L) } ++ SessionInfo("agent_codex", "Codex", BotState.IDLE, "", 0, 0, 0L)+ val glance = GlanceBuilder.build(true, com.coucou.android.link.LinkState.CONNECTED, "PC", sessions, 0) { it }+ val content = WidgetData.build(glance, sessions, nameOf = { it })+ assertTrue(content.tiles.size <= WidgetData.MAX_ROWS)+ assertTrue(content.roster.any { it.pillId == "agent_codex" })+ val rows = TeamChoice.rows(true, content.roster, listOf("agent_codex"), "Not running")+ assertEquals(BotState.IDLE, rows.single().state)+ assertTrue(rows.single().stateWord != "Not running")+ }++ @Test fun theLookIsTheMostUrgentOfWhatIsShown() {+ assertEquals(WidgetTone.MUTED, TeamChoice.look(false, running))+ assertEquals(WidgetTone.ATTENTION, TeamChoice.look(true, running))+ assertEquals(WidgetTone.WORKING, TeamChoice.look(true, running.drop(1)))+ assertEquals(WidgetTone.DONE, TeamChoice.look(true, running.drop(2)))+ assertEquals(WidgetTone.IDLE, TeamChoice.look(true, emptyList()))+ assertEquals(WidgetTone.TROUBLE, TeamChoice.look(true, listOf(tile("a", "A", BotState.ERROR), tile("b", "B", BotState.WORKING))))+ }++ @Test fun theSpokenCardNamesEveryAgentOrSaysTheEmptyLine() {+ val said = TeamChoice.spoken(running, "Nothing")+ assertTrue(said.contains("Claude Code") && said.contains("Codex") && said.contains("Gemini CLI"))+ assertEquals("No agents running", TeamChoice.spoken(emptyList(), "No agents running"))+ }+}