Progress (harness spec 3.4.0): one line for what a reply is doing
CI / check (push) Canceled after 0s
CI / check (push) Canceled after 0s
The `status` frame carries `progress` {phase, since, ...} beside its
text from spec 3.4.0 (progress.md). The app draws it as
`{{text}} · {{elapsed}}` -- the shared texts as string resources, the
elapsed time ticking each second, `retrying`'s `in` counted down, the
text alone for stopped and failed -- under the reply and in the
assistant's sheet, and falls back to the free `status` text for a server
that does not send it, a phase it does not know, or a required field
missing. Under inspection the clock stands still (65 s), so screenshots
are stable and nothing animates forever.
Coded to the spec while the server's frame is being added. ProgressTest
runs the spec's own conformance cases (conformance/progress.json, copied
from LLeMbas CLI 3.4.0 until the server vendors it) against the English
in res/values; fetch-contract.py pins the server's copy as
contract/harness_progress.json once it is there. gen-strings.py takes
the server's translations of the `{{field}}` texts (its catalogues key
them by the spec's English), numbering the fields and doubling a lone %.
Screenshots: 04-writing with a rate, 04-waiting-for-model at 360 dp and
1.5x type.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
23 files changed
+821
-15
No files matched your search
@@ -15,6 +15,8 @@ data class LiveReply(
|
||||
val tail: Tail = Tail(),
|
||||
val plan: Plan? = null,
|
||||
val status: String = "",
|
||||
/** The structured progress beside [status] (spec 3.4.0); null from an older server, or idle. */
|
||||
val progress: Progress? = null,
|
||||
val cards: List<Card> = emptyList(),
|
||||
val jobs: List<Job> = emptyList(),
|
||||
val metrics: Metrics? = null,
|
||||
@@ -45,7 +47,7 @@ data class LiveReply(
|
||||
|
||||
"plan" -> copy(plan = decodePlan(data))
|
||||
|
||||
"status" -> decode(StatusFrame.serializer(), data)?.let { copy(status = it.text) } ?: this
|
||||
"status" -> decode(StatusFrame.serializer(), data)?.let { copy(status = it.text, progress = it.progress) } ?: this
|
||||
|
||||
"ask" -> decode(AskFrame.serializer(), data)?.let { copy(cards = it.cards) } ?: this
|
||||
|
||||
@@ -54,7 +56,7 @@ data class LiveReply(
|
||||
"metrics" -> decode(Metrics.serializer(), data)?.let { copy(metrics = it) } ?: this
|
||||
|
||||
"done" -> decode(DoneFrame.serializer(), data)?.let {
|
||||
copy(finished = it.message, title = it.chat.title.ifEmpty { null }, next = it.next, cards = emptyList(), status = "")
|
||||
copy(finished = it.message, title = it.chat.title.ifEmpty { null }, next = it.next, cards = emptyList(), status = "", progress = null)
|
||||
} ?: this
|
||||
|
||||
"close" -> copy(closed = true)
|
||||
|
||||
@@ -477,8 +477,13 @@ data class StepsFrame(val steps: List<Step> = emptyList(), val tail: Tail = Tail
|
||||
@Serializable
|
||||
data class SteeredFrame(val ids: List<String> = emptyList())
|
||||
|
||||
/**
|
||||
* The `status` frame: the free [text] every server sends, and beside it from harness spec 3.4.0
|
||||
* the structured [progress] (`progress.md`) -- null when the session is doing nothing, or from
|
||||
* an older server. A client that reads [progress] draws it and ignores [text].
|
||||
*/
|
||||
@Serializable
|
||||
data class StatusFrame(val text: String = "")
|
||||
data class StatusFrame(val text: String = "", val progress: Progress? = null)
|
||||
|
||||
@Serializable
|
||||
data class AskFrame(val cards: List<Card> = emptyList())
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
package eu.llembas.android.api
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* What a session is doing (harness spec 3.4.0, `progress.md`): one of a fixed set of [phase]s,
|
||||
* since [since] (Unix milliseconds), with the phase's data. A field that is not known is left
|
||||
* out by the sender, so every one is optional here, and the text says less without it.
|
||||
*/
|
||||
@Serializable
|
||||
data class Progress(
|
||||
val phase: String,
|
||||
val since: Long = 0,
|
||||
/** queued: turns before it. */
|
||||
val ahead: Int? = null,
|
||||
/** waiting_for_model, loading_model: the model's display name. */
|
||||
val model: String? = null,
|
||||
/** waiting_for_model: busy | slots | group. stopped: person | steps | budget. retrying, failed: the error. */
|
||||
val reason: String? = null,
|
||||
/** reading_prompt: prompt tokens processed, of [total]. */
|
||||
val done: Int? = null,
|
||||
val total: Int? = null,
|
||||
/** writing: tokens a second. */
|
||||
val rate: Double? = null,
|
||||
/** running_tool: the tool's name; waiting_for_person (approval): the tool asked about. */
|
||||
val tool: String? = null,
|
||||
/** running_tool: the call's short title. waiting_for_person: approval | question | plan. */
|
||||
val what: String? = null,
|
||||
/** waiting_for_subagents: subagents working or waiting. */
|
||||
val running: Int? = null,
|
||||
/** retrying: seconds until the retry, counted down from [since]. */
|
||||
@SerialName("in") val inSeconds: Int? = null,
|
||||
val attempt: Int? = null,
|
||||
) {
|
||||
companion object {
|
||||
/** `loop.json` `progress.no_elapsed`: drawn as their text alone. */
|
||||
val NO_ELAPSED = setOf("stopped", "failed")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The shared texts (`loop.json` `progress.texts`, the i18n keys `progress.<phase>` …), as this
|
||||
* app holds them: [text] returns the template for a key with its arguments filled in, or null for
|
||||
* a key it does not have. The keys are the spec's with `.` as `_`: `queued_ahead`,
|
||||
* `reason_busy`, `what_approval_bare`, `stopped_reason_person`, `line`.
|
||||
*/
|
||||
fun interface ProgressWords {
|
||||
fun text(key: String, vararg args: String): String?
|
||||
}
|
||||
|
||||
/**
|
||||
* The phase's text, its fields filled (`progress.md` §2): numbers as integers, a rate with one
|
||||
* decimal in [locale]'s format, `retrying`'s `in` counted down to [now]. Null for a phase this
|
||||
* app does not know -- a newer server's -- so the caller falls back to the `status` text.
|
||||
*/
|
||||
fun progressText(progress: Progress, words: ProgressWords, now: Long, locale: Locale = Locale.getDefault()): String? {
|
||||
val p = progress
|
||||
return when (p.phase) {
|
||||
"queued" -> if (p.ahead != null) words.text("queued_ahead", "${p.ahead}") else words.text("queued")
|
||||
|
||||
"waiting_for_model" -> {
|
||||
val model = p.model ?: return null
|
||||
val why = p.reason?.let { words.text("reason_$it") ?: it } ?: return null
|
||||
words.text("waiting_for_model", model, why)
|
||||
}
|
||||
|
||||
"loading_model" -> p.model?.let { words.text("loading_model", it) }
|
||||
|
||||
"reading_prompt" -> {
|
||||
val done = p.done
|
||||
val total = p.total
|
||||
if (done != null && total != null && total > 0) {
|
||||
words.text("reading_prompt", "$done", "$total", "${done.toLong() * 100 / total}")
|
||||
} else {
|
||||
words.text("reading_prompt_bare")
|
||||
}
|
||||
}
|
||||
|
||||
"thinking" -> words.text("thinking")
|
||||
|
||||
"writing" -> p.rate?.let { words.text("writing", String.format(locale, "%.1f", it)) } ?: words.text("writing_bare")
|
||||
|
||||
"running_tool" -> {
|
||||
val tool = p.tool ?: return null
|
||||
if (!p.what.isNullOrBlank()) words.text("running_tool", tool, p.what.take(80)) else words.text("running_tool_bare", tool)
|
||||
}
|
||||
|
||||
"waiting_for_person" -> {
|
||||
val what = when (p.what) {
|
||||
"approval" -> if (!p.tool.isNullOrBlank()) words.text("what_approval", p.tool) else words.text("what_approval_bare")
|
||||
null -> null
|
||||
else -> words.text("what_${p.what}")
|
||||
} ?: return null
|
||||
words.text("waiting_for_person", what)
|
||||
}
|
||||
|
||||
"waiting_for_subagents" -> words.text("waiting_for_subagents", "${p.running ?: 0}")
|
||||
|
||||
"compacting" -> words.text("compacting")
|
||||
|
||||
"retrying" -> {
|
||||
val left = ((p.inSeconds ?: 0) - ((now - p.since).coerceAtLeast(0) / 1000)).coerceAtLeast(0)
|
||||
words.text("retrying", "$left", p.reason.orEmpty())
|
||||
}
|
||||
|
||||
"stopped" -> {
|
||||
val why = p.reason?.let { words.text("stopped_reason_$it") }
|
||||
if (why != null) words.text("stopped_reason", why) else words.text("stopped")
|
||||
}
|
||||
|
||||
"failed" -> words.text("failed", p.reason.orEmpty())
|
||||
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The line a client draws (`progress.md` §3): `{{text}} · {{elapsed}}`, or the text alone for
|
||||
* `stopped` and `failed`. Null when [progressText] is.
|
||||
*/
|
||||
fun progressLine(progress: Progress, words: ProgressWords, now: Long, locale: Locale = Locale.getDefault()): String? {
|
||||
val text = progressText(progress, words, now, locale) ?: return null
|
||||
if (progress.phase in Progress.NO_ELAPSED) return text
|
||||
return words.text("line", text, elapsed(now - progress.since)) ?: text
|
||||
}
|
||||
|
||||
/** Whole seconds as a ticking clock writes a duration: `5s`, `1m 05s`, `1h 02m`. Never negative. */
|
||||
fun elapsed(millis: Long): String {
|
||||
val seconds = millis.coerceAtLeast(0) / 1000
|
||||
return when {
|
||||
seconds < 60 -> "${seconds}s"
|
||||
seconds < 3600 -> "${seconds / 60}m ${"%02d".format(Locale.ROOT, seconds % 60)}s"
|
||||
else -> "${seconds / 3600}h ${"%02d".format(Locale.ROOT, (seconds % 3600) / 60)}m"
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,7 @@ import androidx.compose.ui.unit.dp
|
||||
import eu.llembas.android.R
|
||||
import eu.llembas.android.ui.ModelAvatar
|
||||
import eu.llembas.android.ui.chat.Steps
|
||||
import eu.llembas.android.ui.progressLineOf
|
||||
import eu.llembas.android.ui.theme.LocalPalette
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@@ -470,10 +471,11 @@ private fun Turn(turn: AssistTurn, last: Boolean, state: AssistUiState, actions:
|
||||
}
|
||||
if (turn.steps.isNotEmpty()) Steps(turn.steps)
|
||||
val reply = turn.reply
|
||||
val statusLine = progressLineOf(reply?.progress) ?: reply?.status.orEmpty()
|
||||
when {
|
||||
reply != null && reply.cards.isNotEmpty() -> TextButton(onClick = onOpenApp) { Text(stringResource(R.string.assist_answer_in_app)) }
|
||||
|
||||
turn.writing && reply?.status?.isNotBlank() == true -> Text(reply.status, style = MaterialTheme.typography.labelSmall, color = palette.inkFaint)
|
||||
turn.writing && statusLine.isNotBlank() -> Text(statusLine, style = MaterialTheme.typography.labelSmall, color = palette.inkFaint)
|
||||
|
||||
last && !turn.writing && turn.steps.isNotEmpty() -> Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
if (state.canSpeak) {
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package eu.llembas.android.ui
|
||||
|
||||
import android.content.res.Resources
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableLongStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalInspectionMode
|
||||
import eu.llembas.android.R
|
||||
import eu.llembas.android.api.Progress
|
||||
import eu.llembas.android.api.ProgressWords
|
||||
import eu.llembas.android.api.progressLine
|
||||
import eu.llembas.android.api.progressText
|
||||
import kotlinx.coroutines.delay
|
||||
|
||||
/** The progress texts' resources, by the spec's key (`progress.<key>` with `.` as `_`). */
|
||||
private val PROGRESS_STRINGS = mapOf(
|
||||
"queued" to R.string.progress_queued,
|
||||
"queued_ahead" to R.string.progress_queued_ahead,
|
||||
"waiting_for_model" to R.string.progress_waiting_for_model,
|
||||
"loading_model" to R.string.progress_loading_model,
|
||||
"reading_prompt" to R.string.progress_reading_prompt,
|
||||
"reading_prompt_bare" to R.string.progress_reading_prompt_bare,
|
||||
"thinking" to R.string.progress_thinking,
|
||||
"writing" to R.string.progress_writing,
|
||||
"writing_bare" to R.string.progress_writing_bare,
|
||||
"running_tool" to R.string.progress_running_tool,
|
||||
"running_tool_bare" to R.string.progress_running_tool_bare,
|
||||
"waiting_for_person" to R.string.progress_waiting_for_person,
|
||||
"waiting_for_subagents" to R.string.progress_waiting_for_subagents,
|
||||
"compacting" to R.string.progress_compacting,
|
||||
"retrying" to R.string.progress_retrying,
|
||||
"stopped" to R.string.progress_stopped,
|
||||
"stopped_reason" to R.string.progress_stopped_reason,
|
||||
"failed" to R.string.progress_failed,
|
||||
"reason_busy" to R.string.progress_reason_busy,
|
||||
"reason_slots" to R.string.progress_reason_slots,
|
||||
"reason_group" to R.string.progress_reason_group,
|
||||
"what_approval" to R.string.progress_what_approval,
|
||||
"what_approval_bare" to R.string.progress_what_approval_bare,
|
||||
"what_question" to R.string.progress_what_question,
|
||||
"what_plan" to R.string.progress_what_plan,
|
||||
"stopped_reason_person" to R.string.progress_stopped_person,
|
||||
"stopped_reason_steps" to R.string.progress_stopped_steps,
|
||||
"stopped_reason_budget" to R.string.progress_stopped_budget,
|
||||
"line" to R.string.progress_line,
|
||||
)
|
||||
|
||||
/** [ProgressWords] from the app's string resources, in the app's language. */
|
||||
fun progressWords(resources: Resources): ProgressWords = ProgressWords { key, args ->
|
||||
PROGRESS_STRINGS[key]?.let { id -> if (args.isEmpty()) resources.getString(id) else resources.getString(id, *args) }
|
||||
}
|
||||
|
||||
/** The clock a progress line ticks by: now, again on every whole second. */
|
||||
@Composable
|
||||
fun rememberTick(): Long {
|
||||
var now by remember { mutableLongStateOf(System.currentTimeMillis()) }
|
||||
LaunchedEffect(Unit) {
|
||||
while (true) {
|
||||
now = System.currentTimeMillis()
|
||||
delay(1000L - now % 1000L)
|
||||
}
|
||||
}
|
||||
return now
|
||||
}
|
||||
|
||||
/** In a preview or a screenshot the clock stands still, this long after the phase began. */
|
||||
private const val STILL_ELAPSED = 65_000L
|
||||
|
||||
/**
|
||||
* The progress line to draw for [progress] (`{{text}} · {{elapsed}}`), ticking once a second;
|
||||
* or the text alone with [withElapsed] false, where a line has no room (a list's row). Null
|
||||
* when there is no progress, or it is a phase this app does not know: draw `status` then.
|
||||
*/
|
||||
@Composable
|
||||
fun progressLineOf(progress: Progress?, withElapsed: Boolean = true): String? {
|
||||
progress ?: return null
|
||||
val resources = LocalContext.current.resources
|
||||
val locale = LocalConfiguration.current.locales[0]
|
||||
val words = remember(resources, locale) { progressWords(resources) }
|
||||
// Under inspection (previews, screenshots) nothing may animate forever, and a shot must be
|
||||
// the same every time.
|
||||
val now = if (LocalInspectionMode.current) progress.since + STILL_ELAPSED else rememberTick()
|
||||
return if (withElapsed) progressLine(progress, words, now, locale) else progressText(progress, words, now, locale)
|
||||
}
|
||||
@@ -92,6 +92,7 @@ import eu.llembas.android.R
|
||||
import eu.llembas.android.api.Message
|
||||
import eu.llembas.android.api.ShowCard
|
||||
import eu.llembas.android.ui.ModelAvatar
|
||||
import eu.llembas.android.ui.progressLineOf
|
||||
import eu.llembas.android.ui.theme.LocalPalette
|
||||
import eu.llembas.android.ui.viewer.FileViewer
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -286,9 +287,12 @@ fun ChatContent(
|
||||
}
|
||||
}
|
||||
}
|
||||
if (live != null && live.status.isNotBlank()) {
|
||||
// The 3.4.0 progress line, ticking; the free status text from an older server.
|
||||
val progressLine = progressLineOf(live?.progress)
|
||||
val statusLine = progressLine ?: live?.status.orEmpty()
|
||||
if (live != null && statusLine.isNotBlank()) {
|
||||
Text(
|
||||
live.status,
|
||||
statusLine,
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = palette.inkFaint,
|
||||
maxLines = 1,
|
||||
|
||||
Reference in new issue
Block a user