Contract at server dev 2fd3c03: the tree frame, and a subagent asking
CI / check (push) Canceled after 0s

The server's /api/v2 now carries the 3.4.0 subagents (2fd3c03):
- the stream's `tree` frame {tree} (event_tree.json): LiveReply keeps it,
  ChatState keeps the last one after the reply ends (cleared when another
  chat opens), and the activity sheet draws it as the reduced list. The
  provisional `Activity.tree` is gone -- the tree never came that way.
- an ask item's `subagent {id, name, position}` (event_ask.json card4): the
  approval names it with the page's sentence ("Subagent parser (s1),
  reviews the parser, asks:"), translated from the server's catalogue.
- an agent chat's `subagents.offered` is true where the instance allows
  them (chat_agent.json): the Subagents setting shows for an existing agent
  chat by the chat's own word.

ContractTest: the tree frame, the subagent's card; the agent chat offered.
Screenshot 24-approval-subagent; 26-subagents from the tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Opus 5.5 committed 2026-11-10 10:01:22 +00:00
1 parent 3e1c320b00
commit 415dc653c3
24 files changed
+239 -62

No files matched your search

@@ -19,6 +19,8 @@ data class LiveReply(
val progress: Progress? = null,
val cards: List<Card> = emptyList(),
val jobs: List<Job> = emptyList(),
/** The subagent tree (spec 3.4.0), from the `tree` frame; null until there is one. */
val tree: SubagentTree? = null,
val metrics: Metrics? = null,
val steered: Set<String> = emptySet(),
/** Set by `done`: the finished row, which replaces this in the transcript. */
@@ -53,6 +55,8 @@ data class LiveReply(
"jobs" -> decode(JobsFrame.serializer(), data)?.let { copy(jobs = it.jobs) } ?: this
"tree" -> decode(TreeFrame.serializer(), data)?.let { copy(tree = it.tree) } ?: this
"metrics" -> decode(Metrics.serializer(), data)?.let { copy(metrics = it) } ?: this
"done" -> decode(DoneFrame.serializer(), data)?.let {
@@ -419,8 +419,13 @@ data class CardItem(
val plan: JsonObject? = null,
@SerialName("mode_choice") val modeChoice: Boolean = false,
val job: String = "",
/** The tree subagent asking (spec 3.4.0), for a call nobody in the tree may allow; null otherwise. */
val subagent: CardSubagent? = null,
)
@Serializable
data class CardSubagent(val id: String = "", val name: String = "", val position: String = "")
@Serializable
data class Card(
val id: String,
@@ -485,6 +490,10 @@ data class SteeredFrame(val ids: List<String> = emptyList())
@Serializable
data class StatusFrame(val text: String = "", val progress: Progress? = null)
/** The `tree` frame (spec 3.4.0): the subagent tree, once there is one, whenever it changes. */
@Serializable
data class TreeFrame(val tree: SubagentTree? = null)
@Serializable
data class AskFrame(val cards: List<Card> = emptyList())
@@ -648,11 +657,6 @@ data class Activity(
val context: ContextUse? = null,
val outputs: List<Output> = emptyList(),
val plan: JsonObject? = null,
/**
* The subagent tree (harness spec 3.4.0, `subagents.md` §12), where the server sends it;
* null from an older one, which the Tasks section's team members stand for.
*/
val tree: SubagentTree? = null,
)
@Serializable
@@ -81,6 +81,7 @@ import eu.llembas.android.api.AgentDetail
import eu.llembas.android.api.ContextUse
import eu.llembas.android.api.Output
import eu.llembas.android.api.RoomMessage
import eu.llembas.android.api.SubagentTree
import eu.llembas.android.api.TreeLogic
import eu.llembas.android.lembas
import eu.llembas.android.ui.MarkdownText
@@ -254,6 +255,7 @@ fun ActivityPanel(chatId: String?, state: ChatState, model: ChatViewModel, canOp
canCompact = chatId != null && !state.running,
compacting = state.compacting,
canOpenFiles = canOpenFiles,
tree = state.tree,
onClose = close,
)
}
@@ -299,6 +301,7 @@ fun ActivityContent(
compacting: Boolean = false,
canOpenFiles: Boolean = true,
unfolded: Boolean = false,
tree: SubagentTree? = null,
onClose: () -> Unit = {},
) {
val palette = LocalPalette.current
@@ -332,15 +335,15 @@ fun ActivityContent(
}
// 3.4.0: the subagents as a reduced list, each opening its conversation read-only;
// the Tasks section then holds the background jobs, the members being in the list.
val tree = activity.tree?.takeIf { TreeLogic.hasSubagents(it) }
if (tree != null) {
val shownTree = tree?.takeIf { TreeLogic.hasSubagents(it) }
if (shownTree != null) {
item {
Section(stringResource(R.string.team_agents), count = tree.agents.count { !it.isMain }.takeIf { it > 0 }) {
SubagentList(tree) { agent -> actions.read(ActivityLogic.ofTreeAgent(agent)) }
Section(stringResource(R.string.team_agents), count = shownTree.agents.count { !it.isMain }.takeIf { it > 0 }) {
SubagentList(shownTree) { agent -> actions.read(ActivityLogic.ofTreeAgent(agent)) }
}
}
}
val tasks = if (tree != null) activity.copy(agents = activity.agents.filter { it.kind != "member" }, team = null) else activity
val tasks = if (shownTree != null) activity.copy(agents = activity.agents.filter { it.kind != "member" }, team = null) else activity
item { Section(stringResource(R.string.activity_tasks)) { TasksSection(tasks, readAt, now, actions, unfolded) } }
activity.team?.let { team ->
item { Section(stringResource(R.string.team_room), count = team.room.size.takeIf { it > 0 }) { RoomSection(team) } }
@@ -73,7 +73,14 @@ private fun Approval(card: Card, onAnswer: (CardAnswer) -> Unit) {
Text(stringResource(R.string.card_approval), style = MaterialTheme.typography.titleMedium)
card.items.forEach { item ->
// A subagent asks, not the chat's own turn: said first, as the page says it.
if (item.job.isNotBlank()) {
val subagent = item.subagent
if (subagent != null) {
Text(
stringResource(R.string.card_subagent_asks, subagent.name, subagent.id, subagent.position.ifBlank { "—" }),
style = MaterialTheme.typography.labelLarge,
color = palette.accent,
)
} else if (item.job.isNotBlank()) {
Text(stringResource(R.string.card_asker, item.job), style = MaterialTheme.typography.labelLarge, color = palette.accent)
}
// `title` is the heading ("Run a command"); `detail` is the thing itself, the command.
@@ -25,6 +25,7 @@ import eu.llembas.android.api.LiveReply
import eu.llembas.android.api.Message
import eu.llembas.android.api.ModelInfo
import eu.llembas.android.api.StreamClient
import eu.llembas.android.api.SubagentTree
import eu.llembas.android.api.Turn
import eu.llembas.android.lembas
import eu.llembas.android.ui.explain
@@ -73,6 +74,8 @@ data class ChatState(
val compacting: Boolean = false,
/** What a chat not made yet will be made with: chosen in the top bar and the tune sheet. */
val draft: Draft = Draft(),
/** The subagent tree (spec 3.4.0) from this chat's last `tree` frame; null until one came. */
val tree: SubagentTree? = null,
)
/**
@@ -190,7 +193,7 @@ class ChatViewModel(app: Application) :
viewModelScope.launch {
try {
val client = api()
_state.update { it.copy(loading = chatId != null || agent, error = null) }
_state.update { it.copy(loading = chatId != null || agent, error = null, tree = null) }
val list = runCatching { client.modelList(chatId) }.getOrNull()
val models = list?.models.orEmpty()
_state.update { it.copy(modelsCap = list?.subagentsCap) }
@@ -246,7 +249,11 @@ class ChatViewModel(app: Application) :
_state.update { it.copy(live = LiveReply(messageId)) }
try {
StreamClient(api()).follow(chat.id, messageId).collect { frame ->
_state.update { s -> s.copy(live = (s.live ?: LiveReply(messageId)).apply(frame.event, frame.data)) }
_state.update { s ->
val live = (s.live ?: LiveReply(messageId)).apply(frame.event, frame.data)
// The tree outlives the reply: kept for the activity sheet once it ends.
s.copy(live = live, tree = live.tree ?: s.tree)
}
}
} catch (e: CancellationException) {
throw e