LLeMbas for Android 0.1.0 (alpha, unreleased): the first commit
CI / check (push) Canceled after 0s

A native client for a LLeMbas instance on the server's /api/v2, and the
phone's digital assistant.

- Sign in by device code; the token sealed in the Android Keystore; several
  instances.
- Chats and agent chats: the list, a chat with its reply streaming as JSON
  server-sent events (reconnecting, whole blocks), thinking, tool calls,
  steered messages, the plan, jobs, stop, edit, regenerate, continue, the
  model, effort and Plan mode, attachments and dictation.
- Cards in a sheet, answered as the page's form says it; first answer wins.
- Notifications through UnifiedPush, no Google services; an approval can be
  answered from its notification.
- The digital assistant: a VoiceInteractionService with its session (a sheet
  over the current app, "Include screen" off by default), a recognition
  service through the instance's speech-to-text, the lock-screen path that
  asks to unlock before sending, a Quick Settings tile and an Ask shortcut.
- Share to LLeMbas; Moria and Shire from the server's tokens; nine
  languages; a self-updater in the `full` flavour, none in `fdroid`.

Generated and pinned from the server, each checked in CI: the theme
(tokens.lock.json), the contract (contract/lock.json, server 2124ba9), the
strings and the icons. Built and tested only on GitHub Actions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Opus 5.5 committed 2026-10-21 13:44:30 +00:00
commit 4f09bc41bb
96 files changed
+7932

No files matched your search

@@ -0,0 +1,64 @@
package eu.llembas.android
import eu.llembas.android.api.ApiClient
import eu.llembas.android.api.ApiException
import eu.llembas.android.api.CardAnswer
import eu.llembas.android.api.normaliseBase
import kotlinx.coroutines.test.runTest
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.junit.Before
import org.junit.Test
class ClientTest {
private lateinit var server: MockWebServer
@Before
fun up() {
server = MockWebServer().apply { start() }
}
@After
fun down() = server.shutdown()
private fun client() = ApiClient(server.url("/").toString().trimEnd('/'), "lmb_test")
@Test
fun anAddressBecomesABase() {
assertEquals("https://llm.example.org", normaliseBase(" llm.example.org/ "))
assertEquals("http://10.1.2.3:8080", normaliseBase("http://10.1.2.3:8080"))
}
@Test
fun everyCallCarriesTheToken() = runTest {
server.enqueue(MockResponse().setBody("""{"api":1,"account":{"name":"Frodo","email":"f@shire.test"}}"""))
assertEquals("Frodo", client().me().account.name)
val request = server.takeRequest()
assertEquals("/api/v2/me", request.path)
assertEquals("Bearer lmb_test", request.getHeader("Authorization"))
}
@Test
fun aRefusalIsTheServersOwnSentence() = runTest {
server.enqueue(MockResponse().setResponseCode(409).setBody("""{"detail":"That question is no longer waiting for an answer."}"""))
try {
client().answer("c", "card", CardAnswer(verdict = "allow"))
fail("a 409 must throw")
} catch (e: ApiException) {
assertEquals(409, e.status)
assertEquals("That question is no longer waiting for an answer.", e.message)
}
}
@Test
fun aCardAnswerIsThePagesFormInJson() = runTest {
server.enqueue(MockResponse().setBody("""{"answered":true}"""))
client().answer("c1", "card1", CardAnswer(choices = mapOf("q0" to listOf("Tea"))))
val body = server.takeRequest().body.readUtf8()
assertTrue(body, body.contains(""""choices":{"q0":["Tea"]}"""))
}
}
@@ -0,0 +1,100 @@
package eu.llembas.android
import eu.llembas.android.api.AskFrame
import eu.llembas.android.api.Chat
import eu.llembas.android.api.DoneFrame
import eu.llembas.android.api.JobsFrame
import eu.llembas.android.api.LembasJson
import eu.llembas.android.api.LiveReply
import eu.llembas.android.api.Message
import eu.llembas.android.api.Metrics
import eu.llembas.android.api.Plan
import eu.llembas.android.api.StatusFrame
import eu.llembas.android.api.SteeredFrame
import eu.llembas.android.api.StepsFrame
import eu.llembas.android.api.Tail
import kotlinx.serialization.KSerializer
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
/**
* The server's contract, as pinned in `contract/` by `scripts/fetch-contract.py`: every shape
* the server's serialisers wrote must parse into this app's models, and say what it said.
*/
class ContractTest {
private fun text(name: String): String = requireNotNull(javaClass.classLoader!!.getResource("$name.json")) { "contract/$name.json is missing" }.readText()
private fun <T> read(name: String, serializer: KSerializer<T>): T = LembasJson.decodeFromString(serializer, text(name))
@Test
fun theVersionIsOneThisAppReads() {
val version = LembasJson.parseToJsonElement(text("version")).toString()
assertEquals("""{"app_api":1}""", version)
}
@Test
fun aChatAndAnAgentChat() {
val chat = read("chat", Chat.serializer())
assertEquals("Waybread", chat.title)
assertEquals("low", chat.effort)
assertTrue(chat.unread)
val agent = read("chat_agent", Chat.serializer())
assertTrue(agent.isAgent)
assertEquals("edit", agent.mode)
assertEquals("/home/dev/project", agent.device?.directory)
}
@Test
fun theMessages() {
val user = read("message_user", Message.serializer())
assertTrue(user.isUser)
assertEquals("How is lembas made?", user.text)
val reply = read("message_assistant", Message.serializer())
assertEquals(listOf("thinking", "text", "tools", "steer", "text"), reply.steps.map { it.kind })
assertTrue(reply.steps[1].markdown!!.startsWith("Here is how it is made"))
val call = reply.steps[2].calls.single()
assertEquals("shell", call.block.kind)
assertEquals("bake --slow", call.block.title)
assertEquals(listOf("exit 0"), call.block.chips)
assertEquals("and add honey", reply.steps[3].messages.single().text)
assertEquals(40, reply.metrics!!.completionTokens)
}
@Test
fun everyFrameParses() {
assertTrue(read("event_steps", StepsFrame.serializer()).steps.isNotEmpty())
assertNotNull(read("event_tail", Tail.serializer()).label)
assertEquals(listOf("msg9"), read("event_steered", SteeredFrame.serializer()).ids)
assertEquals("Bake lembas", read("event_plan", Plan.serializer()).title)
assertTrue(read("event_status", StatusFrame.serializer()).text.isNotEmpty())
val cards = read("event_ask", AskFrame.serializer()).cards
assertEquals(listOf("question", "approval", "plan"), cards.map { it.kind })
assertEquals(listOf("Honey", "Plain"), cards[0].items[0].options.map { it.label })
assertTrue(cards[1].items[0].editable)
assertNotNull(cards[2].items[0].plan)
assertTrue(read("event_ask_empty", AskFrame.serializer()).cards.isEmpty())
assertEquals("explore", read("event_jobs", JobsFrame.serializer()).jobs.single().agent)
assertEquals(2, read("event_metrics", Metrics.serializer()).percent)
assertEquals("Waybread", read("event_done", DoneFrame.serializer()).chat.title)
}
@Test
fun aWholeStreamBuildsAReply() {
var live = LiveReply("msg2")
for (event in listOf("steps", "tail", "steered", "plan", "status", "ask", "jobs", "metrics", "done", "close")) {
live = live.apply(event, text("event_$event"))
}
assertTrue(live.closed)
assertNotNull(live.finished)
assertEquals("Waybread", live.title)
assertNull(live.next)
// A finished reply asks nothing: `done` clears the cards.
assertTrue(live.cards.isEmpty())
assertEquals(setOf("msg9"), live.steered)
assertEquals("Bake lembas", live.plan?.title)
}
}
@@ -0,0 +1,48 @@
package eu.llembas.android
import eu.llembas.android.api.LiveReply
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class LiveReplyTest {
@Test
fun aFrameReplacesItsBlockNeverAppends() {
val once = LiveReply("m").apply("tail", """{"thinking":"","text":"Lem","label":""}""")
val twice = once.apply("tail", """{"thinking":"","text":"Lembas","label":""}""")
assertEquals("Lembas", twice.tail.text)
assertEquals(listOf("text"), twice.shown.map { it.kind })
}
@Test
fun theOpenTailFollowsTheClosedSteps() {
val live = LiveReply("m")
.apply("steps", """{"steps":[{"index":0,"kind":"text","markdown":"One."}],"tail":{"thinking":"hm","text":"Two","label":"3s"}}""")
assertEquals(listOf("text", "thinking", "text"), live.shown.map { it.kind })
assertEquals(listOf(0, 1, 1), live.shown.map { it.index })
assertTrue(live.shown.drop(1).all { it.open })
}
@Test
fun anEmptyAskFrameClearsTheCard() {
val asked = LiveReply("m").apply("ask", """{"cards":[{"id":"c","kind":"question","items":[{"key":"q0","kind":"question"}]}]}""")
assertEquals(1, asked.cards.size)
assertTrue(asked.apply("ask", """{"cards":[]}""").cards.isEmpty())
}
@Test
fun anUnknownOrBrokenFrameChangesNothing() {
val live = LiveReply("m").apply("status", """{"text":"Working"}""")
assertEquals(live, live.apply("something-newer", "{}"))
assertEquals(live, live.apply("status", "not json"))
}
@Test
fun aDrainedQueueNamesTheNextReply() {
val done = LiveReply("m").apply(
"done",
"""{"message":{"id":"m","role":"assistant"},"chat":{"id":"c","title":"T"},"next":"m2"}""",
)
assertEquals("m2", done.next)
}
}
@@ -0,0 +1,34 @@
package eu.llembas.android
import eu.llembas.android.assist.AssistController
import eu.llembas.android.assist.Recorder
import eu.llembas.android.update.Updater
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
class SmallThingsTest {
@Test
fun versionsCompareAsNumbers() {
assertTrue(Updater.newer("0.10.0", "0.9.9"))
assertTrue(Updater.newer("1.0.0", "0.99.0"))
assertFalse(Updater.newer("0.1.0", "0.1.0"))
assertFalse(Updater.newer("0.1.0", "0.2.0"))
}
@Test
fun aVoiceReadsNoMarkup() {
val said = AssistController.plain("**Bake** it.\n\n```sh\nbake\n```\nSee [the recipe](https://example.org).")
assertEquals("Bake it. See the recipe.", said)
}
@Test
fun aRecordingIsAValidWavFile() {
val wav = Recorder.wav(ByteArray(3200))
assertEquals(44 + 3200, wav.size)
assertEquals("RIFF", String(wav, 0, 4))
assertEquals("WAVE", String(wav, 8, 4))
assertEquals("data", String(wav, 36, 4))
}
}