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
Android Widgets: review fixes (demo does not count, Today resets at midnight, clock-time reset, version back to 0.1.0)
Claude379724f3cf35
diff --git a/android/README.md b/android/README.mdindex 7ed95932..c07209b9 100644--- a/android/README.md+++ b/android/README.md@@ -58,7 +58,7 @@ The desktop side is in `windows/src-tauri/src/phone_link`; the protocol is `docs- **Away from home Wi-Fi** (optional): through your own Cloudflare relay, end-to-end encrypted; the direct link is always tried first.- **Keeping the link alive with the screen off**: an alarm every few minutes checks that the computer still answers and reconnects if not (Doze allows nothing more); Home says when and why the link was lost; Settings > Computer > *Can't connect?* checks the network, address, discovery, certificate, pairing code and relay; a calm hint suggests the battery setting ("Unrestricted", with the Samsung steps) only if it would help. Details and limits: `docs/ANDROID_LINK.md`, "Keeping the link alive".- **Widget, quick-settings tile, ongoing notification**: agent names and state words only. Updated when something changes, never on a timer.-- **Widgets**: nine to pick from on the home screen, all on one card (24dp corners, a thin border, dark by default and light when the system is in day mode) with a gradient, a 1dp border and a glow in the colour of the state, the same palette for every Widget (`WidgetTone` in `core/WidgetData.kt`, `res/values/colors.xml`): green when an agent has finished, blue while it works, orange while something waits for you, soft grey when all is calm, and a muted grey with the "not connected" icon when the computer is not there. With several agents the most urgent one sets the colour (waiting, then working, then happy, then idle). Plan usage has a palette of its own so it never looks like a state: teal, yellow from 75% and red from 90% (`PlanUsageLook`); only from 90% is the percentage big and bold, with "Near limit" and when it resets. In the Widget picker each one shows a large, realistic preview with sample data (Android 12 and later; Android 11 shows a still picture of the card with Mochi), its name and a one-line description. The previews are static: vector Mochi faces in `res/drawable/preview_*`, layouts in `res/layout/widget_preview_*`.+- **Widgets**: nine to pick from on the home screen, all on one card (24dp corners, a thin border, dark by default and light when the system is in day mode) with a gradient, a 1dp border and a glow in the colour of the state, the same palette for every Widget (`WidgetTone` in `core/WidgetData.kt`, `res/values/colors.xml`): green when an agent has finished, blue while it works, orange while something waits for you, soft grey when all is calm, and a muted grey with the "not connected" icon when the computer is not there. With several agents the most urgent one sets the colour (waiting, then working, then happy, then idle). Plan usage has a palette of its own so it never looks like a state: teal, yellow from 75% and red from 90% (`PlanUsageLook`); only from 90% is the percentage big and bold, with "Near limit" and the clock time it resets at ("resets at 14:30"). In the Widget picker each one shows a large, realistic preview with sample data (Android 12 and later; Android 11 shows a still picture of the card with Mochi), its name and a one-line description. The previews are static: vector Mochi faces in `res/drawable/preview_*`, layouts in `res/layout/widget_preview_*`.- *Agents summary* (3x2, the first Widget, same receiver as before): its text and counts are unchanged, now on the shared card with a small Mochi in the state of your most urgent agent, a headline with a badge for what waits for you and up to three short lines with a state dot each. A tap anywhere opens the app; it has no buttons.- *Mochi at a glance* (Solo, 2x2): Mochi in the state of your most urgent agent, its name and a state word.- *All your agents* (List, 4x3): one row of at least 48dp per agent (Mochi's face, name, state word, dot), up to five, with a badge for what waits for you; with no agent, a centred empty state ("Waiting for your computer" / "No agents running").@@ -66,7 +66,7 @@ The desktop side is in `windows/src-tauri/src/phone_link`; the protocol is `docs- *One-line status* (Status Pill, 4x1): one slim line with a dot, the agent's name and its state word, and four round buttons that open Home, Chat, Settings and Recent decisions. Narrower, the state word goes first, then the name; the text never runs under the buttons.- *Approvals waiting* (Waiting Alert, 2x2): calm when nothing waits, a bright orange "N waiting" when something does. A tap opens the app and the sheet rises by itself.- *Plan usage* (Usage Ring, 2x2): a ring for your Claude or Codex plan usage; "Turn on plan usage in the app" when it is off.- - *Finished today* (Today, 2x2): agent tasks finished today, counted on this phone only and started again at local midnight.+ - *Finished today* (Today, 2x2): agent tasks finished today, counted on this phone only and started again at local midnight by one inexact alarm (no exact-alarm permission, no wake-ups).- *Mochi's mood* (Mood, 1x1): just his face.The buttons only open a screen of the app, from a closed list (`core/LaunchScreen.kt`) through the non-exported `LaunchActivity`; none approves, denies or sends anything, and `MainActivity` still reads no intent extra. A tap on Solo, Mochi Big, Status Pill, Mochi Mood or a List row opens that agent in the app. A request is still decided in the app, behind the fingerprint, never from a Widget. Widgets show agent names, state words and colours only, are redrawn when something changes (`updatePeriodMillis` stays 0) and a redraw that would look the same is skipped. On Android 12 and later they adapt to their size (small, medium, large). Code: `core/WidgetData.kt` (pure, tested), `app/WidgetHub.kt`, one class per Widget in `app/`, `app/MochiBitmap.kt`, `app/RingBitmap.kt`.diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.ktsindex 66271beb..aeea3775 100644--- a/android/app/build.gradle.kts+++ b/android/app/build.gradle.kts@@ -22,8 +22,8 @@ android {applicationId = "com.coucou.android"minSdk = 30targetSdk = 35- versionCode = 2- versionName = "0.2.0"+ versionCode = 1+ versionName = "0.1.0"// English only: libraries' other languages are left out of the app too.resourceConfigurations += listOf("en")}diff --git a/android/app/src/debug/kotlin/com/coucou/android/app/WidgetPreviewReceiver.kt b/android/app/src/debug/kotlin/com/coucou/android/app/WidgetPreviewReceiver.ktindex e8358464..51c28991 100644--- a/android/app/src/debug/kotlin/com/coucou/android/app/WidgetPreviewReceiver.kt+++ b/android/app/src/debug/kotlin/com/coucou/android/app/WidgetPreviewReceiver.kt@@ -19,8 +19,8 @@ import com.coucou.android.core.WidgetSample* adb shell am broadcast -n com.coucou.android/.app.WidgetPreviewReceiver -a com.coucou.android.debug.WIDGET_STATE --es state done* adb shell am broadcast -n com.coucou.android/.app.WidgetPreviewReceiver -a com.coucou.android.debug.WIDGET_STATE --es state live*- * Optional `--ei usage <percent>` sets Claude's plan usage on Mochi Big and the Usage Ring (reset in 2 h), to see the near-limit look- * (red from 90, large rate, "Near limit", reset time). Without `--es state` it uses `working`; ignored for `disconnected` and `live`:+ * Optional `--ei usage <percent>` sets Claude's plan usage on Mochi Big and the Usage Ring (it resets in 2 h, shown as a clock time), to see the near-limit look+ * (red from 90, large rate, "Near limit", "resets at 14:30"). Without `--es state` it uses `working`; ignored for `disconnected` and `live`:** adb shell am broadcast -n com.coucou.android/.app.WidgetPreviewReceiver -a com.coucou.android.debug.WIDGET_STATE --es state working --ei usage 92*diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xmlindex 43c9d157..fd2227d1 100644--- a/android/app/src/main/AndroidManifest.xml+++ b/android/app/src/main/AndroidManifest.xml@@ -116,8 +116,7 @@<receiver android:name=".app.TodayWidget" android:exported="true" android:label="@string/widget_today_label"><intent-filter><action android:name="android.appwidget.action.APPWIDGET_UPDATE" />- <!-- The day changed: the count starts again at zero. System broadcasts, no timer. -->- <action android:name="android.intent.action.DATE_CHANGED" />+ <!-- The clock or the time zone changed: the day may be another one. (Midnight itself is our own alarm: the system no longer tells manifest receivers that the date changed.) --><action android:name="android.intent.action.TIME_SET" /><action android:name="android.intent.action.TIMEZONE_CHANGED" /></intent-filter>diff --git a/android/app/src/main/kotlin/com/coucou/android/app/AppModel.kt b/android/app/src/main/kotlin/com/coucou/android/app/AppModel.ktindex 18ffdb87..f860fb13 100644--- a/android/app/src/main/kotlin/com/coucou/android/app/AppModel.kt+++ b/android/app/src/main/kotlin/com/coucou/android/app/AppModel.kt@@ -722,8 +722,8 @@ class AppModel(private val context: Context) : LinkListener {val minute = java.time.LocalTime.now().let { it.hour * 60 + it.minute }for (s in sessions) {val prev = lastState.put(s.pillId, s.state)- // A task just finished (not one already finished when the link came back).- if (prev != null && prev != BotState.FINISHED && s.state == BotState.FINISHED) todayCounter.increment()+ // A task just finished (not one already finished when the link came back), on a real computer: the demo loops and never counts.+ if (mode == Mode.PAIRED && prev != null && prev != BotState.FINISHED && s.state == BotState.FINISHED) todayCounter.increment()val name = agentName(s.pillId)val sound = com.coucou.android.mochi.MochiConst.STATE_SOUND[s.state]if (sound != null && StatusPolicy.stateSoundWanted(prev, s.state, settings)) sounds.play(sound)diff --git a/android/app/src/main/kotlin/com/coucou/android/app/TodayWidget.kt b/android/app/src/main/kotlin/com/coucou/android/app/TodayWidget.ktindex ed2c0d30..0a11d93e 100644--- a/android/app/src/main/kotlin/com/coucou/android/app/TodayWidget.kt+++ b/android/app/src/main/kotlin/com/coucou/android/app/TodayWidget.kt@@ -10,19 +10,27 @@ import com.coucou.android.core.WidgetContent/*** The Today widget: how many agent tasks finished today. The count is kept on this phone only ([TodayStore]) and starts- * again at local midnight: the system's "the date changed" broadcast redraws it, so nothing runs on a timer. A tap opens the app.+ * again at local midnight: one inexact alarm ([WidgetHub.scheduleMidnight]) redraws it, and so does a change of time or time zone. A tap opens the app.*/class TodayWidget : AppWidgetProvider() {- override fun onUpdate(context: Context, manager: AppWidgetManager, ids: IntArray) =+ override fun onUpdate(context: Context, manager: AppWidgetManager, ids: IntArray) {WidgetHub.refresh(context, manager, ids) { c, w -> views(c, w) }+ WidgetHub.scheduleMidnight(context)+ }++ override fun onDisabled(context: Context) = WidgetHub.cancelMidnight(context)override fun onReceive(context: Context, intent: Intent) {super.onReceive(context, intent)- if (intent.action in DAY_CHANGED) WidgetHub.refreshAll(context)+ if (intent.action in DAY_CHANGED) {+ WidgetHub.refreshAll(context)+ WidgetHub.scheduleMidnight(context)+ }}companion object {- private val DAY_CHANGED = setOf(Intent.ACTION_DATE_CHANGED, Intent.ACTION_TIME_CHANGED, Intent.ACTION_TIMEZONE_CHANGED)+ // Midnight (our alarm), and the clock or the time zone being changed: the day may be another one.+ private val DAY_CHANGED = setOf(WidgetHub.ACTION_MIDNIGHT, Intent.ACTION_TIME_CHANGED, Intent.ACTION_TIMEZONE_CHANGED)fun views(context: Context, c: WidgetContent): RemoteViews {val v = RemoteViews(context.packageName, R.layout.widget_today)diff --git a/android/app/src/main/kotlin/com/coucou/android/app/WidgetHub.kt b/android/app/src/main/kotlin/com/coucou/android/app/WidgetHub.ktindex 7b01c521..cac73c88 100644--- a/android/app/src/main/kotlin/com/coucou/android/app/WidgetHub.kt+++ b/android/app/src/main/kotlin/com/coucou/android/app/WidgetHub.kt@@ -1,5 +1,6 @@package com.coucou.android.app+import android.app.AlarmManagerimport android.app.PendingIntentimport android.appwidget.AppWidgetManagerimport android.appwidget.AppWidgetProvider@@ -12,6 +13,7 @@ import android.widget.RemoteViewsimport com.coucou.android.MainActivityimport com.coucou.android.Rimport com.coucou.android.core.LaunchScreen+import com.coucou.android.core.TodayMidnightimport com.coucou.android.core.UsageToneimport com.coucou.android.core.WidgetContentimport com.coucou.android.core.WidgetTone@@ -20,7 +22,8 @@ import kotlin.math.roundToInt/*** The one place that pushes the Widgets (Solo, List, Mochi Big, Status Pill, Waiting Alert, Usage Ring, Today and Mochi Mood). The app calls [update] on every change of sessions, requests and* link (from AppModel.pushGlance); a push whose content is the same as the last one is dropped, so a change that does not- * show on a widget costs nothing. There is no timer: a widget is drawn when something changes or when it is added.+ * show on a widget costs nothing. There is no timer: a widget is drawn when something changes or when it is added, and the Today+ * widget once at local midnight (one inexact alarm, see [scheduleMidnight]).*/object WidgetHub {private class Kind(val provider: Class<out AppWidgetProvider>, val views: (Context, WidgetContent) -> RemoteViews)@@ -144,6 +147,32 @@ object WidgetHub {update(context, current(context))}+ /** The one alarm of the Widgets: the Today widget's redraw at the next local midnight (see [scheduleMidnight]). */+ const val ACTION_MIDNIGHT = "com.coucou.android.action.WIDGET_MIDNIGHT"++ private fun midnightIntent(context: Context): PendingIntent =+ PendingIntent.getBroadcast(+ context, CODE_MIDNIGHT, Intent(ACTION_MIDNIGHT).setClass(context, TodayWidget::class.java),+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,+ )++ /**+ * Asks the system to redraw the Today widget once, at the next local midnight, so the count starts again at 0 even if nothing else+ * redraws it (Android no longer delivers "the date changed" to manifest receivers). One inexact alarm that does not wake the phone+ * and needs no permission; it replaces itself each time, and is set again when the alarm fires and whenever the Widget is updated.+ */+ fun scheduleMidnight(context: Context) {+ runCatching {+ val alarms = context.getSystemService(AlarmManager::class.java) ?: return+ alarms.set(AlarmManager.RTC, TodayMidnight.nextAfter(System.currentTimeMillis()), midnightIntent(context))+ }+ }++ /** No Today widget is left on the home screen: the alarm is not needed. */+ fun cancelMidnight(context: Context) {+ runCatching { context.getSystemService(AlarmManager::class.java)?.cancel(midnightIntent(context)) }+ }+/** Opens the app on Home. */fun openApp(context: Context, code: Int): PendingIntent {val open = Intent(context, MainActivity::class.java)@@ -192,4 +221,5 @@ object WidgetHub {/** Mochi Big's usage side: Settings when plan usage is off, the app otherwise. */const val CODE_BIG_USAGE_SETTINGS = 0x5D00const val CODE_BIG_USAGE_APP = 0x5E00+ const val CODE_MIDNIGHT = 0x5F00}diff --git a/android/app/src/main/kotlin/com/coucou/android/core/TodayCounter.kt b/android/app/src/main/kotlin/com/coucou/android/core/TodayCounter.ktindex 371b9a25..0b20bcb8 100644--- a/android/app/src/main/kotlin/com/coucou/android/core/TodayCounter.kt+++ b/android/app/src/main/kotlin/com/coucou/android/core/TodayCounter.kt@@ -1,6 +1,7 @@package com.coucou.android.coreimport java.time.LocalDate+import java.time.ZoneId/** Where the count of the day is kept: one day and one number. */interface TodayStorage {@@ -9,8 +10,8 @@ interface TodayStorage {}/**- * How many agent tasks finished today, counted on this phone only. A new local day starts at zero without any timer: the- * day is compared when the count is read or raised, so after midnight the first read says 0. [day] is injectable for tests.+ * How many agent tasks finished today, counted on this phone only. A new local day starts at zero: the day is compared when+ * the count is read or raised, so after midnight the first read says 0 (the Widget is redrawn then by [TodayMidnight]'s alarm). [day] is injectable for tests.*/class TodayCounter(private val storage: TodayStorage, private val day: () -> String = { LocalDate.now().toString() }) {@Synchronized@@ -27,3 +28,9 @@ class TodayCounter(private val storage: TodayStorage, private val day: () -> Strreturn n}}++/** When the next local day starts, for the one alarm that redraws the Today widget at midnight. */+object TodayMidnight {+ fun nextAfter(nowMs: Long, zone: ZoneId = ZoneId.systemDefault()): Long =+ java.time.Instant.ofEpochMilli(nowMs).atZone(zone).toLocalDate().plusDays(1).atStartOfDay(zone).toInstant().toEpochMilli()+}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 1cb030e7..14124afb 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@@ -8,6 +8,11 @@ import com.coucou.android.link.UsageSnapshotimport com.coucou.android.mochi.BotStateimport com.coucou.android.mochi.MochiConstimport com.coucou.android.mochi.Rgb+import java.time.Instant+import java.time.ZoneId+import java.time.format.TextStyle+import java.time.temporal.ChronoUnit+import java.util.Localeimport kotlin.math.roundToInt/**@@ -76,7 +81,7 @@ enum class UsageTone(val rgb: Rgb) {/*** How a plan-usage percentage looks, in one place: the colour of the ring and of the bar, and the "Near limit" line. Below the red line* the percentage is shown small and normal with no warning; from [LIMIT_FROM] it is shown big and bold with "Near limit" and, when the- * usage snapshot has one, when the window resets ("resets in 2 h"). Pure, so every boundary is a unit test.+ * usage snapshot has one, when the window resets ("resets at 14:30"). Pure, so every boundary is a unit test.*/object PlanUsageLook {/** From this percentage (included) the usage is "getting close": yellow. */@@ -97,21 +102,25 @@ object PlanUsageLook {/** True from the red line: the Widget then shows the rate prominently. */fun nearLimit(pct: Int): Boolean = clamp(pct) >= LIMIT_FROM- /** "resets in 2 h", "resets in 40 min", "resets in 3 d"; null when there is no reset time (0) or it has passed. */- fun resetLine(resetsAtMs: Long, nowMs: Long): String? {+ /**+ * When the window resets, as a clock time that stays true while nothing redraws the Widget: "resets at 14:30" today, "resets Fri 14:30"+ * within the next week, "resets Oct 21 14:30" later. Null when there is no reset time (0) or it has passed. [zone] is the phone's.+ */+ fun resetLine(resetsAtMs: Long, nowMs: Long, zone: ZoneId = ZoneId.systemDefault()): String? {if (resetsAtMs <= 0 || resetsAtMs <= nowMs) return null- val minutes = (resetsAtMs - nowMs) / 60_000- val hours = minutes / 60+ val at = Instant.ofEpochMilli(resetsAtMs).atZone(zone)+ val days = ChronoUnit.DAYS.between(Instant.ofEpochMilli(nowMs).atZone(zone).toLocalDate(), at.toLocalDate())+ val clock = "%02d:%02d".format(at.hour, at.minute)return when {- minutes < 60 -> "resets in ${maxOf(minutes, 1)} min"- hours < 48 -> "resets in $hours h"- else -> "resets in ${hours / 24} d"+ days == 0L -> "resets at $clock"+ days < 7 -> "resets ${at.dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.ENGLISH)} $clock"+ else -> "resets ${at.month.getDisplayName(TextStyle.SHORT, Locale.ENGLISH)} ${at.dayOfMonth} $clock"}}/** "Near limit" (with the reset time when known) from the red line; null below it, where there is no warning. */- fun note(pct: Int, resetsAtMs: Long, nowMs: Long): String? =- if (!nearLimit(pct)) null else listOfNotNull("Near limit", resetLine(resetsAtMs, nowMs)).joinToString(" · ")+ fun note(pct: Int, resetsAtMs: Long, nowMs: Long, zone: ZoneId = ZoneId.systemDefault()): String? =+ if (!nearLimit(pct)) null else listOfNotNull("Near limit", resetLine(resetsAtMs, nowMs, zone)).joinToString(" · ")}/** The plan usage a ring or a bar shows: which plan and window, how much of it is used, and the warning line when it is near the limit. */diff --git a/android/app/src/test/kotlin/com/coucou/android/PlanUsageLookTest.kt b/android/app/src/test/kotlin/com/coucou/android/PlanUsageLookTest.ktindex 7e05da9c..73d2542a 100644--- a/android/app/src/test/kotlin/com/coucou/android/PlanUsageLookTest.kt+++ b/android/app/src/test/kotlin/com/coucou/android/PlanUsageLookTest.kt@@ -13,6 +13,7 @@ import org.junit.Test/** One function decides how plan usage looks: its colour, whether it is shown prominently, and the "Near limit" line. */class PlanUsageLookTest {private val now = 10_000_000L+ private val utc = java.time.ZoneOffset.UTCprivate fun inMinutes(m: Long) = now + m * 60_000@Test fun theThresholdsAreNamedConstants() {@@ -58,14 +59,15 @@ class PlanUsageLookTest {}@Test fun belowTheRedLineThereIsNoWarningLine() {- for (p in listOf(0, 42, 74, 75, 89)) assertNull("$p%", PlanUsageLook.note(p, inMinutes(120), now))+ for (p in listOf(0, 42, 74, 75, 89)) assertNull("$p%", PlanUsageLook.note(p, inMinutes(120), now, utc))}@Test fun fromTheRedLineItSaysNearLimitAndWhenItResets() {- assertEquals("Near limit · resets in 2 h", PlanUsageLook.note(90, inMinutes(120), now))- assertEquals("Near limit · resets in 2 h", PlanUsageLook.note(100, inMinutes(125), now))- assertEquals("Near limit · resets in 40 min", PlanUsageLook.note(95, inMinutes(40), now))- assertEquals("Near limit · resets in 3 d", PlanUsageLook.note(93, inMinutes(3 * 24 * 60), now))+ // 10,000,000 ms after the epoch is 02:46 UTC.+ assertEquals("Near limit · resets at 04:46", PlanUsageLook.note(90, inMinutes(120), now, utc))+ assertEquals("Near limit · resets at 04:51", PlanUsageLook.note(100, inMinutes(125), now, utc))+ assertEquals("Near limit · resets at 03:26", PlanUsageLook.note(95, inMinutes(40), now, utc))+ assertEquals("Near limit · resets Sun 02:46", PlanUsageLook.note(93, inMinutes(3 * 24 * 60), now, utc))}@Test fun withoutAResetTimeItJustSaysNearLimit() {@@ -73,19 +75,30 @@ class PlanUsageLookTest {assertEquals("a reset time in the past is no reset time", "Near limit", PlanUsageLook.note(95, now - 1, now))}- @Test fun theResetLineReadsInTheRightUnit() {- assertEquals("resets in 1 min", PlanUsageLook.resetLine(now + 1_000, now))- assertEquals("resets in 59 min", PlanUsageLook.resetLine(inMinutes(59), now))- assertEquals("resets in 1 h", PlanUsageLook.resetLine(inMinutes(60), now))- assertEquals("resets in 47 h", PlanUsageLook.resetLine(inMinutes(47 * 60 + 59), now))- assertEquals("resets in 2 d", PlanUsageLook.resetLine(inMinutes(48 * 60), now))- assertNull(PlanUsageLook.resetLine(0L, now))- assertNull(PlanUsageLook.resetLine(now, now))+ @Test fun theResetLineIsAClockTimeThatStaysTrue() {+ assertEquals("resets at 02:47", PlanUsageLook.resetLine(inMinutes(1), now, utc))+ assertEquals("same day: just the time", "resets at 23:59", PlanUsageLook.resetLine(inMinutes(21 * 60 + 13), now, utc))+ assertEquals("next day: the day of the week", "resets Fri 00:00", PlanUsageLook.resetLine(inMinutes(21 * 60 + 14), now, utc))+ assertEquals("resets Wed 02:46", PlanUsageLook.resetLine(inMinutes(6 * 24 * 60), now, utc))+ assertEquals("a week or more: the date", "resets Jan 8 02:46", PlanUsageLook.resetLine(inMinutes(7 * 24 * 60), now, utc))+ assertNull(PlanUsageLook.resetLine(0L, now, utc))+ assertNull(PlanUsageLook.resetLine(now, now, utc))+ }++ @Test fun theClockTimeIsThePhonesOwn() {+ // The same moment reads differently in another time zone: 04:46 UTC is 10:16 in India.+ assertEquals("resets at 10:16", PlanUsageLook.resetLine(inMinutes(120), now, java.time.ZoneId.of("Asia/Kolkata")))+ }++ @Test fun theTextDoesNotChangeWhileTimePasses() {+ // Nothing redraws a Widget while the usage stays the same, so the line must not depend on "now".+ val at = inMinutes(120)+ assertEquals(PlanUsageLook.resetLine(at, now, utc), PlanUsageLook.resetLine(at, now + 60 * 60_000, utc))}@Test fun theRingAndTheTextComeFromTheSameFunction() {for (p in listOf(0, 74, 75, 89, 90, 100, 140)) {- val row = UsageRing("Claude", "5 h", p, PlanUsageLook.note(p, inMinutes(120), now))+ val row = UsageRing("Claude", "5 h", p, PlanUsageLook.note(p, inMinutes(120), now, utc))assertEquals(PlanUsageLook.tone(p), row.tone)assertEquals(PlanUsageLook.nearLimit(p), row.nearLimit)assertEquals("a note exactly when it is near the limit: $p%", row.nearLimit, row.note != null)diff --git a/android/app/src/test/kotlin/com/coucou/android/TodayCounterTest.kt b/android/app/src/test/kotlin/com/coucou/android/TodayCounterTest.ktindex b20591b0..c136c9d2 100644--- a/android/app/src/test/kotlin/com/coucou/android/TodayCounterTest.kt+++ b/android/app/src/test/kotlin/com/coucou/android/TodayCounterTest.kt@@ -1,6 +1,7 @@package com.coucou.androidimport com.coucou.android.core.TodayCounter+import com.coucou.android.core.TodayMidnightimport com.coucou.android.core.TodayStorageimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertTrue@@ -46,6 +47,30 @@ class TodayCounterTest {assertEquals("a day that is not today is not today", 0, counter.count())}+ @Test fun theMidnightAlarmIsSetForTheNextLocalMidnight() {+ val utc = java.time.ZoneOffset.UTC+ val noon = 12 * 3_600_000L // 12:00 on 1 January 1970+ assertEquals(24 * 3_600_000L, TodayMidnight.nextAfter(noon, utc))+ assertEquals("exactly at midnight, the next one", 48 * 3_600_000L, TodayMidnight.nextAfter(24 * 3_600_000L, utc))+ assertEquals(24 * 3_600_000L, TodayMidnight.nextAfter(24 * 3_600_000L - 1, utc))+ // Local time, not UTC: in Kolkata (UTC+5:30) 12:00 UTC is 17:30, and the next midnight is 18:30 UTC.+ assertEquals(18 * 3_600_000L + 30 * 60_000L, TodayMidnight.nextAfter(noon, java.time.ZoneId.of("Asia/Kolkata")))+ }++ @Test fun onlyAPairedComputerCountsNotTheDemo() {+ val model = File("src/main/kotlin/com/coucou/android/app/AppModel.kt").readText()+ val line = model.lines().first { it.contains("todayCounter.increment()") }+ assertTrue("the demo loops every 20 s and must not add to the day", line.contains("mode == Mode.PAIRED"))+ }++ @Test fun midnightIsOurOwnAlarmBecauseTheSystemNoLongerSendsDateChanged() {+ val manifest = File("src/main/AndroidManifest.xml").readText()+ assertTrue(!manifest.contains("DATE_CHANGED"))+ assertTrue(manifest.contains("android.intent.action.TIME_SET") && manifest.contains("android.intent.action.TIMEZONE_CHANGED"))+ val widget = File("src/main/kotlin/com/coucou/android/app/TodayWidget.kt").readText()+ assertTrue(widget.contains("WidgetHub.scheduleMidnight") && widget.contains("onDisabled") && widget.contains("ACTION_MIDNIGHT"))+ }+@Test fun itIsKeptOnThePhoneOnly() {val store = File("src/main/kotlin/com/coucou/android/app/TodayStore.kt")if (store.exists()) {diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetDataTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetDataTest.ktindex 4b4fbf75..f991d015 100644--- a/android/app/src/test/kotlin/com/coucou/android/WidgetDataTest.kt+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetDataTest.kt@@ -9,6 +9,7 @@ import com.coucou.android.link.PlanUsageimport com.coucou.android.link.PlanWindowimport com.coucou.android.link.SessionInfoimport com.coucou.android.link.UsageSnapshot+import com.coucou.android.core.PlanUsageLookimport com.coucou.android.core.UsageRingimport com.coucou.android.core.WidgetToneimport com.coucou.android.mochi.BotState@@ -138,7 +139,7 @@ class WidgetDataTest {@Test fun theRingPrefersClaudesFiveHoursThenItsWeekThenCodex() {assertEquals(UsageRing("Claude", "5 h", 42), built(usage(claude5 = 42, claudeWeek = 10, codex5 = 90)).ring)assertEquals(UsageRing("Claude", "week", 10), built(usage(claudeWeek = 10, codex5 = 90)).ring)- assertEquals(UsageRing("Codex", "5 h", 90, "Near limit · resets in 1 h"), built(usage(codex5 = 90)).ring)+ assertEquals(UsageRing("Codex", "5 h", 90, "Near limit · " + PlanUsageLook.resetLine(now + 3_600_000L, now)), built(usage(codex5 = 90)).ring)assertNull(built(usage()).ring)assertNull("the switch is off", built(null).ring)}diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetSampleTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetSampleTest.ktindex 84175c51..d677824b 100644--- a/android/app/src/test/kotlin/com/coucou/android/WidgetSampleTest.kt+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetSampleTest.kt@@ -1,6 +1,7 @@package com.coucou.androidimport com.coucou.android.core.UsageTone+import com.coucou.android.core.PlanUsageLookimport com.coucou.android.core.WidgetDataimport com.coucou.android.core.WidgetSampleimport com.coucou.android.core.WidgetTone@@ -56,7 +57,7 @@ class WidgetSampleTest {val c = WidgetData.sample(WidgetSample.WORKING, now, 92)assertEquals(92, c.ring?.pct)assertEquals(UsageTone.LIMIT, c.ring?.tone)- assertEquals("Near limit · resets in 2 h", c.ring?.note)+ assertEquals("Near limit · " + PlanUsageLook.resetLine(now + 2 * 3_600_000L, now), c.ring?.note)assertEquals(92, c.usageRows.first().pct)assertEquals("Claude", c.usageRows.first().plan)assertEquals(null, WidgetData.sample(WidgetSample.WORKING, now, 60).ring?.note)diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetSurfacesTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetSurfacesTest.ktindex 9720d7c4..95593a81 100644--- a/android/app/src/test/kotlin/com/coucou/android/WidgetSurfacesTest.kt+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetSurfacesTest.kt@@ -51,7 +51,16 @@ class WidgetSurfacesTest {@Test fun noTimerAndNoLibrary() {for ((name, src) in sources) {- for (word in listOf("AlarmManager", "WorkManager", "postDelayed", "Handler(", "Timer", "androidx.glance")) assertFalse("$name uses $word", src.contains(word))+ for (word in listOf("WorkManager", "postDelayed", "Handler(", "Timer", "androidx.glance")) assertFalse("$name uses $word", src.contains(word))+ if (name != "app/WidgetHub.kt") assertFalse("$name uses AlarmManager", src.contains("AlarmManager"))+ }+ // The one alarm: the Today widget at local midnight. Inexact and not waking the phone, so no exact-alarm permission and no wake-ups.+ val hub = sources.getValue("app/WidgetHub.kt")+ assertEquals(1, Regex("alarms\\.set\\(").findAll(hub).count())+ assertTrue(hub.contains("alarms.set(AlarmManager.RTC,"))+ for (word in listOf("RTC_WAKEUP", "setExact", "setAlarmClock", "setRepeating", "setInexactRepeating", "SCHEDULE_EXACT_ALARM", "USE_EXACT_ALARM")) {+ assertFalse(word, hub.contains(word))+ assertFalse("manifest asks for $word", manifest.contains(word))}assertFalse(read("build.gradle.kts").contains("androidx.glance"))}@@ -60,7 +69,10 @@ class WidgetSurfacesTest {val hub = sources.getValue("app/WidgetHub.kt")// Open the app, open a session, open a screen: three, all immutable, the last two through LaunchActivity.assertEquals(3, Regex("PendingIntent.getActivity").findAll(hub).count())- assertEquals(3, Regex("FLAG_IMMUTABLE").findAll(hub).count())+ // Plus the midnight alarm: one explicit, immutable broadcast to the Today widget.+ assertEquals(1, Regex("PendingIntent.getBroadcast").findAll(hub).count())+ assertTrue(hub.contains("Intent(ACTION_MIDNIGHT).setClass(context, TodayWidget::class.java)"))+ assertEquals(4, Regex("FLAG_IMMUTABLE").findAll(hub).count())assertEquals(2, Regex("Intent\\(context, LaunchActivity::class.java\\)").findAll(hub).count())assertTrue(hub.contains("Intent(context, MainActivity::class.java)"))for ((name, src) in sources) {@@ -73,7 +85,7 @@ class WidgetSurfacesTest {@Test fun everyRowAndEveryWidgetHasItsOwnRequestCode() {val hub = sources.getValue("app/WidgetHub.kt")val codes = Regex("""const val CODE_\w+ = (0x[0-9A-Fa-f]+)""").findAll(hub).map { it.groupValues[1] }.toList()- assertEquals(14, codes.size)+ assertEquals(15, codes.size)assertEquals(codes.size, codes.toSet().size)// The rows use CODE_LIST_ROW + index: the ranges must not run into the next code.val values = codes.map { it.removePrefix("0x").toInt(16) }.sorted()diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetUsageSideTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetUsageSideTest.ktindex 5ede875b..c3d63aef 100644--- a/android/app/src/test/kotlin/com/coucou/android/WidgetUsageSideTest.kt+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetUsageSideTest.kt@@ -116,7 +116,7 @@ class WidgetUsageSideTest {val waiting = WidgetData.sample(WidgetSample.WAITING, now)assertEquals(listOf(UsageTone.CLOSE, UsageTone.LIMIT), waiting.usageRows.map { it.tone })// The second row is at the limit: it says so, and when it resets.- assertEquals("Near limit · resets in 3 d", waiting.usageRows[1].note)+ assertEquals("Near limit · " + PlanUsageLook.resetLine(now + 3 * 24 * 3_600_000L, now), waiting.usageRows[1].note)assertEquals("no warning below the red line", null, waiting.usageRows[0].note)assertEquals(UsageSide.ROWS, WidgetData.sample(WidgetSample.DONE, now).usageSide)assertEquals(1, WidgetData.sample(WidgetSample.DONE, now).usageRows.size)diff --git a/docs/android.html b/docs/android.htmlindex 0cc16df1..f165c93e 100644--- a/docs/android.html+++ b/docs/android.html@@ -34,7 +34,7 @@<li><b>Allow or Deny</b> a permission from the notification or the app, even on a locked phone. A request wakes the screen; notifications show at most the tool and the program’s name, never the full command. Allow asks for your fingerprint or screen lock.</li><li><b>Answer Claude Code’s questions</b> and <b>chat</b> through your computer’s own AI keys, when you turn them on in the computer’s settings.</li><li><b>See your agents at a glance:</b> who is working, plan usage and your services.</li>-<li><b>Widgets</b> for your home screen: Solo, List, Mochi Big, Status Pill, Waiting Alert, Usage Ring, Today and Mochi Mood. They show your agents’ names and how they are doing, never a command or a file, and a request is always decided in the app.</li>+<li><b>Widgets</b> for your home screen: Solo, List, Mochi Big, Status Pill, Waiting Alert, Usage Ring, Today, Mochi Mood and the Agents summary. They show your agents’ names and how they are doing, never a command or a file, and a request is always decided in the app.</li><li><b>An island over other apps</b> (optional), a quick-settings tile, and a notification that keeps the link alive.</li><li><b>Mochi,</b> his outfits and his sounds, on your phone.</li></ul>