Which fence is a page is the server's to say; the build's missing constant
CI / check (push) Canceled after 0s
CI / check (push) Canceled after 0s
- A closed step and a report are drawn from the server's text, where a page is the one line "[page: Title]" (the card). An `html-view` fence the server does not list -- written while pages were not offered -- is the code block it is. Only the open step of a reply as it streams takes the fence for a page, so that a page being written is not source scrolling by. - The events' reports frame carries latest_created; a report its pages. - FEATURE_VOICE_RECOGNIZERS is not in the SDK for apps: the feature is asked for by its name (CI run 88 failed to compile on it). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
7 files changed
+57
-31
No files matched your search
@@ -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<StepPage> = emptyList(),
|
||||
val model: String? = null,
|
||||
val chat: JsonElement? = null,
|
||||
) {
|
||||
@@ -63,7 +65,7 @@ data class ReportList(val reports: List<Report> = 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
|
||||
|
||||
@@ -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<Segment> {
|
||||
fun splitFences(markdown: String, pages: Boolean = false): List<Segment> {
|
||||
val out = mutableListOf<Segment>()
|
||||
val prose = StringBuilder()
|
||||
val lines = markdown.split("\n")
|
||||
@@ -79,7 +83,7 @@ fun splitFences(markdown: String): List<Segment> {
|
||||
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<String>()
|
||||
i++
|
||||
|
||||
@@ -388,7 +388,9 @@ fun StepsCompact(steps: List<Step>, 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<Step>, 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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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<!doctype html>\n<html><script>alert(1)</script></html>\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", "<p>")), splitFences("```html\n<p>\n```"))
|
||||
assertEquals(listOf(Segment.Code("html-views", "<p>")), splitFences("```html-views\n<p>\n```"))
|
||||
// Tildes, no title, and one still being written.
|
||||
assertEquals(listOf(Segment.Page("")), splitFences("~~~html-view\n<html></html>\n~~~"))
|
||||
assertEquals(listOf(Segment.Page("Chart", closed = false)), splitFences("```html-view Chart\n<html>"))
|
||||
assertEquals(listOf(Segment.Code("html", "<p>")), splitFences("```html\n<p>\n```", pages = true))
|
||||
assertEquals(listOf(Segment.Code("html-views", "<p>")), splitFences("```html-views\n<p>\n```", pages = true))
|
||||
// Tildes, no title, and one not closed yet.
|
||||
assertEquals(listOf(Segment.Page("")), splitFences("~~~html-view\n<html></html>\n~~~", pages = true))
|
||||
assertEquals(listOf(Segment.Page("Chart", closed = false)), splitFences("```html-view Chart\n<html>", 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", "<p>x</p>")), splitFences("```html-view Cakes\n<p>x</p>\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\n<html>secret markup</html>\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<html></html>\n```", untitled = "Page"))
|
||||
val report = Report(id = "rep1", title = "Two tenders opened", body = "Bids are due.\n\n```html-view Chart\n<svg></svg>\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<svg></svg>\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("<svg>"))
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|<!doctype html><html><body><svg></svg></body></html>
|
||||
|```
|
||||
|[page: Storage tenders by month]
|
||||
|
|
||||
|```text
|
||||
|storage tender: 200 MW, deadline 2026-05-15
|
||||
|
||||
Reference in new issue
Block a user