Android 1.0 for server 2.0: the file viewer, and older servers refused
CI / check (push) Canceled after 0s

The show card. A tool call may now carry `show` (event["show"], harness spec 3.0.0): a file's
name, path, kind, line and which copy -- node and version in the chat's tree, or the copy a linked
device sent (shown_id). The transcript draws it as a card with Open; the viewer is a full-screen,
read-only dialog that fetches the text and opens at the named line. Markdown goes through the same
Markwon setup as a reply (rule 4); code, text and Markdown over 200 000 characters are numbered
lines in a lazy list, the number column measured from the file's longest number. HTML is never
rendered: no WebView exists in the app, so it is shown as source, and "Open in the browser" opens
the web UI's viewer, which renders it in its sealed frame. Copy takes the whole file.

The text comes from GET /api/v2/chats/{chat}/show?node=&version= (or ?shown=), plain text, at most
1 MB. That route is the app's half of a contract the server does not have yet: /api/v2 neither
publishes `show` on a tool call nor serves the file to a token. Until it does, the card does not
appear, and a viewer that meets a missing route says so and offers the browser.

Older servers are refused: the discovery document's device-link protocol must be 3 (LLeMbas 2.0),
at sign-in and, for an instance signed in to before, when the chat list opens. The protocol and
not the version string, because the server's dev still says 1.7.x before its first beta.

Also: gen-strings.py takes a server ref like the other two generators, so the strings come from
the same commit as the contract and the tokens rather than from a shared working tree; the
Reports notification channel goes (2.0 has no reports) and is deleted on first start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Opus 5.5 committed 2026-10-28 04:31:07 +00:00
1 parent 052d0a3894
commit fd1af60dbb
25 files changed
+754 -62

No files matched your search

@@ -0,0 +1,77 @@
package eu.llembas.android
import eu.llembas.android.api.Discovery
import eu.llembas.android.api.LembasJson
import eu.llembas.android.api.ServerFit
import eu.llembas.android.api.ToolCall
import eu.llembas.android.api.fit
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
/**
* The `show` card and the server gate. The card's shape is the server's own payload
* (`services/tools/files.py` `_run_show` for a tree file, `services/shown.py` `payload` for a
* device's) -- written out here because the server's contract fixtures do not carry a `show`
* call yet. When they do, this moves into `ContractTest`.
*/
class ShowAndServerTest {
private fun call(json: String) = LembasJson.decodeFromString(ToolCall.serializer(), json)
@Test
fun aTreeFileShowCard() {
val c = call(
"""
{"id": "call3", "name": "show", "status": "ok", "path": "/home/frodo/notes/road.md",
"show": {"path": "/home/frodo/notes/road.md", "name": "road.md", "kind": "markdown",
"language": "", "line": 12, "node_id": "n1", "version_id": "v7",
"sha": "ab12", "size": 2048, "mime": "text/markdown"},
"block": {"kind": "show", "title": "/home/frodo/notes/road.md"}}
""",
)
val show = c.show!!
assertEquals("road.md", show.name)
assertEquals("markdown", show.viewKind)
assertEquals(12, show.line)
assertEquals(listOf("node" to "n1", "version" to "v7"), show.query)
}
@Test
fun aDeviceFileShowCardNamesTheKeptCopy() {
val c = call(
"""
{"name": "show", "show": {"path": "src/main.rs", "name": "main.rs", "kind": "code",
"language": "rust", "line": 0, "node_id": "", "version_id": "", "sha": "cd34",
"size": 10, "mime": "text/plain", "source": "device", "shown_id": "s9",
"url": "/api/chats/chat1/shown/s9"}}
""",
)
assertEquals("device", c.show!!.source)
assertEquals(listOf("shown" to "s9"), c.show!!.query)
assertEquals("rust", c.show!!.language)
}
@Test
fun anUnknownKindIsPlainText() {
val c = call("""{"name": "show", "show": {"path": "x.svg", "kind": "svg"}}""")
assertEquals("text", c.show!!.viewKind)
assertNull(call("""{"name": "bash"}""").show)
}
private fun discovery(json: String) = LembasJson.decodeFromString(Discovery.serializer(), json)
@Test
fun onlyAServerOnTheTwoPointOhProtocolFits() {
val two = """{"service": "lembas", "version": "2.0.0-beta.1", "protocol": 3, "protocols": [3],
"app_api": 1, "scopes": ["app", "models"]}"""
assertEquals(ServerFit.FITS, fit(discovery(two)))
// 1.7: protocol 2, the app API already there -- and still refused.
val old = """{"service": "lembas", "version": "1.7.3", "protocol": 2, "protocols": [1, 2],
"app_api": 1, "scopes": ["app", "models"]}"""
assertEquals(ServerFit.TOO_OLD, fit(discovery(old)))
// A server with no protocol at all is older still.
assertEquals(ServerFit.TOO_OLD, fit(discovery("""{"service": "lembas", "app_api": 1, "scopes": ["app"]}""")))
assertEquals(ServerFit.TOO_NEW, fit(discovery(two.replace("\"app_api\": 1", "\"app_api\": 2"))))
assertEquals(ServerFit.NOT_LEMBAS, fit(discovery("""{"service": "other", "protocol": 3}""")))
}
}