diff --git a/app/src/main/java/eu/llembas/android/api/Reports.kt b/app/src/main/java/eu/llembas/android/api/Reports.kt index ca6a814..313f468 100644 --- a/app/src/main/java/eu/llembas/android/api/Reports.kt +++ b/app/src/main/java/eu/llembas/android/api/Reports.kt @@ -41,8 +41,10 @@ data class Report( @JsonNames("created_at") val created: String? = null, val unread: Boolean = false, val body: String? = null, - /** The body as text: every page in it replaced by its one line, `[page: Title]`. */ + /** The body as text: every page in it replaced by its one line, `[page: Title]`; the body itself where it has none. */ val text: String? = null, + /** The pages the body has: only these are pages -- an `html-view` fence the server does not list is a code block. */ + val pages: List = emptyList(), val model: String? = null, val chat: JsonElement? = null, ) { @@ -63,7 +65,7 @@ data class ReportList(val reports: List = emptyList(), val unread: Int? /** `GET /events`, frame `reports`: the count of the unread, and the newest report. */ @Serializable -data class ReportsFrame(val unread: Int = 0, val newest: Report? = null) +data class ReportsFrame(val unread: Int = 0, val newest: Report? = null, @SerialName("latest_created") val latestCreated: String? = null) /** `POST /reports/{id}/reply`: the chat the conversation about the report is in. */ @Serializable diff --git a/app/src/main/java/eu/llembas/android/ui/MarkdownSplit.kt b/app/src/main/java/eu/llembas/android/ui/MarkdownSplit.kt index cbbf88b..d3f5363 100644 --- a/app/src/main/java/eu/llembas/android/ui/MarkdownSplit.kt +++ b/app/src/main/java/eu/llembas/android/ui/MarkdownSplit.kt @@ -10,9 +10,13 @@ package eu.llembas.android.ui * is in the middle of is already a code block, not markdown that changes shape when it closes. * * **A page** (harness spec 3.8.0, `pages.md`: a whole HTML document in an `html-view` fence) is - * not drawn on a phone and its source is never shown: the fence becomes [Segment.Page] with its - * title, and so does the line the server puts in a page's place where a reply is read as text, - * `[page: Title]`. One still being written is a page already ([Segment.Page.closed] false). + * not drawn on a phone and its source is never shown as the answer. Which fence is a page is the + * server's to say: a block is one only in a reply written while pages were offered, and the + * server then puts the one line `[page: Title]` in its place in the text it gives a client that + * draws no pages. That line is what becomes [Segment.Page]. A fence is taken for a page here + * only where the caller says pages are being written ([splitFences]' `pages`: the open step of + * a reply as it streams, which the server has not turned into text yet); anywhere else an + * `html-view` fence is the code block it is. */ sealed interface Segment { data class Prose(val markdown: String) : Segment @@ -41,7 +45,7 @@ private fun pageTitle(raw: String?): String = raw.orEmpty().trim().replace(Regex * Share and read-aloud take, so a page's source never leaves as "the answer". [untitled] names * a page without a title. */ -fun pageProjection(markdown: String, untitled: String): String = splitFences(markdown).joinToString("\n\n") { segment -> +fun pageProjection(markdown: String, untitled: String, pages: Boolean = false): String = splitFences(markdown, pages).joinToString("\n\n") { segment -> when (segment) { is Segment.Prose -> segment.markdown is Segment.Code -> "```${segment.language}\n${segment.code}\n```" @@ -51,7 +55,7 @@ fun pageProjection(markdown: String, untitled: String): String = splitFences(mar private val OPENING = Regex("^ {0,3}(`{3,}|~{3,})\\s*([^`\\s]*).*$") -fun splitFences(markdown: String): List { +fun splitFences(markdown: String, pages: Boolean = false): List { val out = mutableListOf() val prose = StringBuilder() val lines = markdown.split("\n") @@ -79,7 +83,7 @@ fun splitFences(markdown: String): List { flushProse() val fence = open.groupValues[1] val language = open.groupValues[2] - val page = PAGE_OPENING.matchEntire(lines[i]) + val page = if (pages) PAGE_OPENING.matchEntire(lines[i]) else null val closing = Regex("^ {0,3}${Regex.escape(fence.substring(0, 1))}{${fence.length},}\\s*$") val code = mutableListOf() i++ diff --git a/app/src/main/java/eu/llembas/android/ui/chat/Transcript.kt b/app/src/main/java/eu/llembas/android/ui/chat/Transcript.kt index 2169bfa..dfb27b5 100644 --- a/app/src/main/java/eu/llembas/android/ui/chat/Transcript.kt +++ b/app/src/main/java/eu/llembas/android/ui/chat/Transcript.kt @@ -388,7 +388,9 @@ fun StepsCompact(steps: List, modifier: Modifier = Modifier, onShow: ((Sho when (step.kind) { "thinking" -> ThinkingChip(step) - "text" -> RichMarkdown(step.shownMarkdown, onLongPress = onLongPress) + // A closed step's pages are the server's to name (its `text`); in the step still + // being written a page's fence is a page already, not source scrolling by. + "text" -> RichMarkdown(step.shownMarkdown, onLongPress = onLongPress, pages = step.open) // A page the server took out of the text as a step of its own: the same card. "page" -> PageCard(step.title.orEmpty()) @@ -403,8 +405,8 @@ fun StepsCompact(steps: List, modifier: Modifier = Modifier, onShow: ((Sho /** Markdown with its fenced code taken out into [CodeBlock]s, each with its own Copy. */ @Composable -fun RichMarkdown(markdown: String, modifier: Modifier = Modifier, onLongPress: (() -> Unit)? = null) { - val segments = remember(markdown) { splitFences(markdown) } +fun RichMarkdown(markdown: String, modifier: Modifier = Modifier, onLongPress: (() -> Unit)? = null, pages: Boolean = false) { + val segments = remember(markdown, pages) { splitFences(markdown, pages) } Column(modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(12.dp)) { segments.forEach { segment -> when (segment) { diff --git a/app/src/main/java/eu/llembas/android/wake/WakeWordService.kt b/app/src/main/java/eu/llembas/android/wake/WakeWordService.kt index c6eaa8b..89976a1 100644 --- a/app/src/main/java/eu/llembas/android/wake/WakeWordService.kt +++ b/app/src/main/java/eu/llembas/android/wake/WakeWordService.kt @@ -277,6 +277,9 @@ class WakeWordService : LifecycleService() { const val HEARD_ID = 7002 private const val SHEET_GRACE_MS = 3_000L + /** `PackageManager.FEATURE_VOICE_RECOGNIZERS`, which the SDK does not name for apps: without it Android runs no voice-interaction service. */ + private const val FEATURE_VOICE_RECOGNIZERS = "android.software.voice_recognizers" + /** The app's own scope: a wake and its record outlive the listening loop, and the service too. */ private val wakeScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate) @@ -285,7 +288,7 @@ class WakeWordService : LifecycleService() { connected = LembasAssistService.current != null, active = LembasAssistService.isActive(context), role = LembasAssistService.holdsRole(context), - recognizers = context.packageManager.hasSystemFeature(PackageManager.FEATURE_VOICE_RECOGNIZERS), + recognizers = context.packageManager.hasSystemFeature(FEATURE_VOICE_RECOGNIZERS), screenOn = context.getSystemService(PowerManager::class.java).isInteractive, locked = context.getSystemService(KeyguardManager::class.java).isKeyguardLocked, visible = AppVisibility.visible, diff --git a/app/src/test/java/eu/llembas/android/ReportsContractTest.kt b/app/src/test/java/eu/llembas/android/ReportsContractTest.kt index 5bbcc7f..9961f15 100644 --- a/app/src/test/java/eu/llembas/android/ReportsContractTest.kt +++ b/app/src/test/java/eu/llembas/android/ReportsContractTest.kt @@ -49,6 +49,7 @@ class ReportsContractTest { val frame = read("event_reports", ReportsFrame.serializer()) assertEquals(1, frame.unread) assertEquals("rep1", frame.newest?.id) + assertEquals("2026-01-02T03:04:05+00:00", frame.latestCreated) } @Test @@ -57,8 +58,10 @@ class ReportsContractTest { val report = LembasJson.decodeFromJsonElement(Report.serializer(), LembasJson.parseToJsonElement(text("report")).jsonObject.getValue("report")) assertEquals("chat9", report.chatId) assertEquals("gpt-oss", report.model) - // The body carries the page's source; the phone draws a card in its place, never the source. - val drawn = splitFences(report.body!!) + // The body carries the page's source; the phone draws the server's text, where the page + // is its one line and becomes a card -- never the source. + assertEquals("Cakes", report.pages.single().title) + val drawn = splitFences(report.text!!) assertEquals(Segment.Page("Cakes"), drawn.last()) assertFalse(drawn.any { it is Segment.Code }) // Share takes the server's own text, where the page is its one line. diff --git a/app/src/test/java/eu/llembas/android/ReportsTest.kt b/app/src/test/java/eu/llembas/android/ReportsTest.kt index aba69ec..33fbd3a 100644 --- a/app/src/test/java/eu/llembas/android/ReportsTest.kt +++ b/app/src/test/java/eu/llembas/android/ReportsTest.kt @@ -199,19 +199,27 @@ class ReportsTest { } @Test - fun aPageInAnAnswerIsNeverItsSource() { + fun aPageBeingWrittenIsNeverItsSource() { + // The open step of a reply as it streams, in a chat where pages are written: the fence is a page already. val reply = "Sales by month:\n\n```html-view Monthly sales\n\n\n```\n\nThat is all." - val split = splitFences(reply) + val split = splitFences(reply, pages = true) assertEquals(listOf(Segment.Prose("Sales by month:"), Segment.Page("Monthly sales"), Segment.Prose("That is all.")), split) // The word is exact: these are ordinary code blocks. - assertEquals(listOf(Segment.Code("html", "

")), splitFences("```html\n

\n```")) - assertEquals(listOf(Segment.Code("html-views", "

")), splitFences("```html-views\n

\n```")) - // Tildes, no title, and one still being written. - assertEquals(listOf(Segment.Page("")), splitFences("~~~html-view\n\n~~~")) - assertEquals(listOf(Segment.Page("Chart", closed = false)), splitFences("```html-view Chart\n")) + assertEquals(listOf(Segment.Code("html", "

")), splitFences("```html\n

\n```", pages = true)) + assertEquals(listOf(Segment.Code("html-views", "

")), splitFences("```html-views\n

\n```", pages = true)) + // Tildes, no title, and one not closed yet. + assertEquals(listOf(Segment.Page("")), splitFences("~~~html-view\n\n~~~", pages = true)) + assertEquals(listOf(Segment.Page("Chart", closed = false)), splitFences("```html-view Chart\n", pages = true)) // Backticks inside a page do not end it unless a line is the closing fence. - assertEquals(listOf(Segment.Page("T")), splitFences("````html-view T\nconst a = `x`\n```\nstill the page\n````")) - // The server's own line in a page's place. + assertEquals(listOf(Segment.Page("T")), splitFences("````html-view T\nconst a = `x`\n```\nstill the page\n````", pages = true)) + } + + @Test + fun whichFenceIsAPageIsTheServersToSay() { + // Anywhere else -- a finished step, a report -- a fence is a page only if the server + // said so, and then it sent the one line in its place. A fence it did not list (written + // while pages were not offered) is the code block it is. + assertEquals(listOf(Segment.Code("html-view", "

x

")), splitFences("```html-view Cakes\n

x

\n```")) assertEquals( listOf(Segment.Prose("Before."), Segment.Page("Monthly sales"), Segment.Prose("After.")), splitFences("Before.\n\n[page: Monthly sales]\n\nAfter."), @@ -221,12 +229,18 @@ class ReportsTest { @Test fun whatIsCopiedOrSharedSaysThereIsAPage() { - val reply = "Sales:\n\n```html-view Monthly sales\nsecret markup\n```\n\n```sh\nmake\n```" - val text = pageProjection(reply, untitled = "Page") + val text = pageProjection("Sales:\n\n[page: Monthly sales]\n\n```sh\nmake\n```", untitled = "Page") assertEquals("Sales:\n\n[page: Monthly sales]\n\n```sh\nmake\n```", text) - assertFalse(text.contains("secret markup")) - assertEquals("[page: Page]", pageProjection("```html-view\n\n```", untitled = "Page")) - val report = Report(id = "rep1", title = "Two tenders opened", body = "Bids are due.\n\n```html-view Chart\n\n```") + assertEquals("[page: Page]", pageProjection("[page: ]", untitled = "Page")) + // A report is shared by the server's text of it, where each page is its one line. + val report = + Report( + id = "rep1", + title = "Two tenders opened", + body = "Bids are due.\n\n```html-view Chart\n\n```", + text = "Bids are due.\n\n[page: Chart]\n", + ) assertEquals("Two tenders opened\n\nBids are due.\n\n[page: Chart]", shareText(report)) + assertFalse(shareText(report).contains("")) } } diff --git a/app/src/test/java/eu/llembas/android/shots/Fakes.kt b/app/src/test/java/eu/llembas/android/shots/Fakes.kt index b18f050..69c0009 100644 --- a/app/src/test/java/eu/llembas/android/shots/Fakes.kt +++ b/app/src/test/java/eu/llembas/android/shots/Fakes.kt @@ -710,9 +710,7 @@ object Fakes { |1. **Austria**: 200 MW, bids due on 15 May. |2. **A smaller one** closes on Friday; see the [notice](https://example.org/notice). | - |```html-view Storage tenders by month - | - |``` + |[page: Storage tenders by month] | |```text |storage tender: 200 MW, deadline 2026-05-15