Skip to content

armgit / andee

Public Imported from GitHub
0

Andee lives on your phone or Mac and uses any app like you do—no integrations, no root, any model; memory and passwords never leave your device | Andee 住进你的手机或 Mac,像你一样操作任何 App——无需集成、无需 Root、支持任意模型,记忆和密码绝不离开设备。

fix(brain): reach the local brain on the two triggers that only spoke to the hub

booboosui9d3414fc3386
diff --git a/CLAUDE.md b/CLAUDE.md
index 73a6075..0d4b17f 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -49,6 +49,8 @@ Shared envelope shape: `{"type":"request","id":…,"method":…,"params":{…}}`
The device also talks unprompted, as `{"type":"event","kind":…,"device_id":…,"data":…}`, sent to the hub and broadcast to every server client. Three kinds exist: `asr.final` (the user said something), `task.stop` (they stopped it — triple-tap on the ball since the `■` button was removed, see "Startup self-check"), `notification` (relayed from the notification listener). Events are **never queued**: with the socket down they are dropped, because a stale "the user just said" is worse than silence. Unlike tools, event kinds are not in `ToolSchemas`, so **the brain side has to be taught each one separately** or it is silently discarded — which looks, from the tablet, exactly like the feature not working. That cost is why the meeting recorder asks for its minutes on `asr.final` instead of inventing a fourth kind.
+**An event is a hub mechanism, so anything that only emits one is invisible to the local brain — which is the default.** Events go out over `BodyWsClient`/`BodyWsServer`; the local brain has no socket in front of it, so it is reached by a direct call or not at all. Two paths were written as event-only and therefore did nothing on a stock device: a tap on 看看 on a notification signboard (`NotificationRelayService` forwarded to `BodyWsClient.current ?: return`), and `call.summary` (whose own KDoc claimed it worked "same as the meeting recorder" — the meeting twin calls `brain?.submit`, it did not). Both lit the ball first, so the visible result was a glow that stayed on until the 5-minute backstop with nothing behind it. Both now go through the service, which owns `hubClient` and `localBrain` both: `ScreenBodyService.notificationLookRequested` and the `call.summary` branch of `onExtensionEvent`. Note what was *not* broken and is a useful contrast — the scheduler never had this bug, because `wakeForTodo` was always a direct `localBrain.wake(...)` with no socket in it. **The rule: a device-originated trigger has to name both brains explicitly.** Reaching for `sendEvent` alone is the bug, and it is silent on the only configuration most devices run.
+
### The brain can also be this device (`brain/`)
`brain = local` in `voice_prefs` swaps the remote brain for an agent loop running on the tablet: `LocalBrain` calls DeepSeek over plain HTTP (`LlmClient`, OkHttp, non-streaming) and drives the same `CommandDispatcher`. The two are **mutually exclusive** — `ScreenBodyService.startBrain()` builds one or the other, because two brains answering the same `asr.final` is two voices talking over each other. The local brain is the **out-of-box default** (since 2026-09-29); anything other than the literal string `"hub"` reads as local, the same fail-closed rule `groundingEnabled` uses — the direction flipped with the default, and the settings picker's leftmost option (the fallback) flipped with it.
diff --git a/app/src/main/java/net/kuafuai/andee/ScreenBodyService.kt b/app/src/main/java/net/kuafuai/andee/ScreenBodyService.kt
index 2340b22..e469ad9 100644
--- a/app/src/main/java/net/kuafuai/andee/ScreenBodyService.kt
+++ b/app/src/main/java/net/kuafuai/andee/ScreenBodyService.kt
@@ -1478,6 +1478,7 @@ class ScreenBodyService : AccessibilityService() {
"call.summary" -> {
val summaryQuery = callSummaryQuery(data)
+ val brain = localBrain
// Display-only, same as the meeting twin above: the brain gets
// `callSummaryQuery`, the card gets this.
net.kuafuai.andee.ui.ChatHistory.addUser(
@@ -1494,11 +1495,19 @@ class ScreenBodyService : AccessibilityService() {
runCatching { client?.sendEvent("asr.final", event) }
runCatching { server?.broadcastEvent("asr.final", event) }
}.start()
- if (client != null || (server?.clientCount() ?: 0) > 0) {
+ if (client != null || brain != null || (server?.clientCount() ?: 0) > 0) {
ui.post {
acceptBrainOutput = true
dispatcher.beginTask()
window.setState(FloatingWindowUi.State.THINKING)
+ // The local brain was missing here while the KDoc above
+ // said this works the same way as the meeting recorder.
+ // It did not: the event goes to the hub, the local brain
+ // has no event channel, so on a local-brain device a
+ // call ended with the ball lit and the transcript going
+ // nowhere. After the gate opens, for the same reason the
+ // meeting twin says.
+ brain?.submit(summaryQuery)
}
}
}
@@ -1948,6 +1957,87 @@ class ScreenBodyService : AccessibilityService() {
fun dispatcherForNotification(): CommandDispatcher? =
if (::dispatcher.isInitialized) dispatcher else null
+ /**
+ * The user tapped 看看 on a notification signboard. Main thread only — the
+ * relay hops there before raising the card, and this touches [window].
+ *
+ * The routing lives here rather than in the relay for the same reason
+ * [dispatcherForNotification] does: the relay has no wiring of its own, and
+ * both halves of what this has to do are private to this class.
+ *
+ * It used to be the relay's own two lines and they reached the **hub only**
+ * — `BodyWsClient.current ?: return`. On a device running the local brain,
+ * which is the out-of-box default, a tap therefore lit the ball and then
+ * returned having told nothing, and the glow stayed on until the 5-minute
+ * backstop. That is the one outcome the signboard exists to prevent: the
+ * user is the spam filter here, so this is the notification they explicitly
+ * asked about.
+ *
+ * The two brains are reached differently, for the reason the meeting
+ * recorder reaches them differently. The hub keeps the `notification` event
+ * kind it was already taught. The local brain has no event plumbing to be
+ * taught *or* to go missing, so it takes the same facts as prose through
+ * `submit` — see [meetingMinutesQuery] for what that costs, and
+ * [notificationLookQuery] for the text written to be true when read that
+ * way.
+ *
+ * Lighting the ball moved in here with the routing and gained the guard it
+ * never had: nobody listening means nobody is thinking about it, exactly as
+ * in [onAsrFinal].
+ */
+ fun notificationLookRequested(n: JSONObject) {
+ val client = hubClient
+ val brain = localBrain
+ // Off the caller's thread, same as every other event: a WebSocket send
+ // blocks once the outbound buffer fills, and this one is on the main
+ // thread. Hub only, like `task.stop` and unlike `asr.final` — a 9008
+ // client is a passive observer by design and this is a request.
+ if (client != null) {
+ Thread { runCatching { client.sendEvent("notification", n) } }.start()
+ }
+ if (client == null && brain == null) {
+ // Nothing can answer. Say so here rather than lighting a glow that
+ // nothing will put out — which is what this method was written for.
+ android.util.Log.i("Body", "notification 看看 tapped, but no brain is listening")
+ return
+ }
+ // Display-only and in the interface language, same split as the meeting
+ // and call twins: the brain gets the query, the history card gets this.
+ net.kuafuai.andee.ui.ChatHistory.addUser(
+ AppLocale.str(this, R.string.svc_notification_look_line, n.optString("app"))
+ )
+ acceptBrainOutput = true
+ dispatcher.beginTask()
+ window.setState(FloatingWindowUi.State.THINKING)
+ // After the gate opens, not before — see the meeting twin: the local
+ // brain answers on its own thread, and a stop still pending from the
+ // turn before would otherwise swallow the answer.
+ brain?.submit(notificationLookQuery(n))
+ }
+
+ /**
+ * What the local brain is handed when the user taps 看看.
+ *
+ * Prompt, not a log line, and English with the rest of the model-facing set
+ * — see [notifyPageClosed]. It arrives as something the user said, so it is
+ * written as the user's own request: they looked at a signboard naming this
+ * app and chose to act on it, which is the one fact the raw notification
+ * JSON cannot carry.
+ */
+ private fun notificationLookQuery(n: JSONObject): String {
+ val count = n.optInt("count", 1)
+ val unread = if (count > 1) " ($count unread, the latest shown below)" else ""
+ return buildString {
+ append("A notification just came in from ${n.optString("app")}$unread ")
+ append("and I asked you to look at it.\n")
+ append("Title: ${n.optString("title")}\nMessage: ${n.optString("latest")}\n")
+ append("App package: ${n.optString("pkg")}\n\n")
+ append("Deal with it: if it needs a reply, open the app and reply; ")
+ append("if it only needs telling me about, say it in one sentence. ")
+ append("Ask me first before anything that cannot be undone.")
+ }
+ }
+
/**
* The ball's window, for CardUi — signboards anchor to where the ball
* actually is, and the relay (a separate service) has no other way to
diff --git a/app/src/main/java/net/kuafuai/andee/device/NotificationRelayService.kt b/app/src/main/java/net/kuafuai/andee/device/NotificationRelayService.kt
index 41f03dd..fdac831 100644
--- a/app/src/main/java/net/kuafuai/andee/device/NotificationRelayService.kt
+++ b/app/src/main/java/net/kuafuai/andee/device/NotificationRelayService.kt
@@ -21,9 +21,12 @@ import org.json.JSONObject
*
* Delivery is BOTH:
* - pull: `device.notifications` reads the ring (with since_ms increments)
- * - push: qualifying notifications are ALSO forwarded to the hub as
- * `notification` events — the same channel asr.final rides, so the brain
- * receives them as inbound messages. The hub side needs zero changes.
+ * - push: a qualifying notification the user taps 看看 on is ALSO handed to
+ * whichever brain is running, by `ScreenBodyService.notificationLookRequested`
+ * — as a `notification` event over the hub (the channel asr.final rides, so
+ * the hub side needs zero changes) and as prose to the local brain, which has
+ * no event channel to be taught. Routing it there rather than from here is
+ * what fixed a tap that lit the ball and reached nothing; see that method.
*
* Push FILTERING (the part that decides whether the brain gets interrupted):
* message apps (chat/SMS/mail) push immediately — a human is trying to reach
@@ -242,15 +245,16 @@ class NotificationRelayService : NotificationListenerService() {
// 5-minute leak-guard backstop applies too: if the brain
// never answers, the glow still goes out by itself.
//
- // Order matters: this runs inside CardUi's close, which
- // still has hideSignboard pending behind it. Lighting the
- // task first (perchedByTask=true) is what tells
- // hideSignboard "the ledge is wanted", so the shrink-then-
- // slide there happens as one motion instead of the ball
- // settling home first and hopping after.
- net.kuafuai.andee.ScreenBodyService.get()
- ?.dispatcherForNotification()?.beginTask()
- Pusher.forward(n)
+ // Lighting it is the service's job now, together with the
+ // routing — it used to be these two lines, and the second one
+ // reached the hub and nothing else, so on a local-brain device
+ // the first one lit a glow that nothing would put out. See
+ // `ScreenBodyService.notificationLookRequested`, which also
+ // keeps the ordering this comment used to explain: the task is
+ // lit before `CardUi`'s pending `hideSignboard` runs, which is
+ // what tells it "the ledge is wanted" so the shrink-then-slide
+ // happens as one motion.
+ net.kuafuai.andee.ScreenBodyService.get()?.notificationLookRequested(n)
}
}
}
@@ -277,14 +281,6 @@ class NotificationRelayService : NotificationListenerService() {
"com.gmail", "com.sina.weibo",
)
- /** Forwards to the hub over the shared WS client, if it's connected. */
- private object Pusher {
- fun forward(n: JSONObject) {
- val client = net.kuafuai.andee.net.BodyWsClient.current ?: return
- client.sendEvent("notification", n)
- }
- }
-
object Store {
private const val CAP = 50
private val lock = Any()
diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml
index 5179af2..ad1fbbe 100644
--- a/app/src/main/res/values-en/strings.xml
+++ b/app/src/main/res/values-en/strings.xml
@@ -248,6 +248,7 @@
<string name="svc_stopped">Stopped</string>
<string name="svc_meeting_ended_line">(Meeting recording ended — %1$d characters, drafting the minutes…)</string>
<string name="svc_call_ended_line">(Call ended — %1$d characters, summarising…)</string>
+ <string name="svc_notification_look_line">(%1$s has a message — I tapped "Take a look"…)</string>
<string name="svc_no_brain_hub">No brain is connected yet, so I can\'t speak.</string>
<string name="svc_no_brain_local">The local brain has no key yet, so I can\'t speak.</string>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 8614783..69c0328 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -251,6 +251,7 @@
-->
<string name="svc_meeting_ended_line">(会议记录结束,共 %1$d 字,正在整理纪要…)</string>
<string name="svc_call_ended_line">(通话结束,共 %1$d 字,正在整理…)</string>
+ <string name="svc_notification_look_line">(%1$s 来消息了,我点了「看看」…)</string>
<string name="svc_no_brain_hub">还没有接上大脑,我说不上话。</string>
<string name="svc_no_brain_local">本地大脑还没配 key,我说不上话。</string>