Subagents (spec 3.4.0): the reduced list, coded to subagents.md §12
CI / check (push) Canceled after 0s

Android's share of the tree (§12): a row per agent -- name (id) and
position, the state word (loop.json team.read.states), the progress text
without the clock, context % (floor(used x 100 / window), as team_read
writes it) -- the main agent first, sub-managers' subagents indented under
them, the ended ones after, dimmed, and the open slots. A subagent's row
opens its conversation read-only through the agent route as a member, by
name; the main agent's is the chat.

The server has the tree (services/team.py tree_info, 98f053a) but no
/api/v2 shape for it yet: the app reads it as `tree` in the activity
(`Activity.tree`, null until the server sends it, and then the Tasks
section leaves the team members to the list). To be re-pinned and wired
to the real field when the server's fixture lands.

TreeTest (the §12 example), screenshot 26-subagents.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Opus 5.5 committed 2026-11-10 09:32:11 +00:00
1 parent 8972bcfcce
commit dff3aa67c0
19 files changed
+431 -1

No files matched your search

@@ -0,0 +1,83 @@
package eu.llembas.android
import eu.llembas.android.api.ActivityLogic
import eu.llembas.android.api.LembasJson
import eu.llembas.android.api.SubagentTree
import eu.llembas.android.api.TreeLogic
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
/** The subagent tree (harness spec 3.4.0, `subagents.md` §12) and the reduced list's rows. */
class TreeTest {
/** §12's own example, with a sub-manager and one under it added. */
private val tree = LembasJson.decodeFromString(
SubagentTree.serializer(),
"""
{ "min": 1, "max": 4, "size": 3, "open_slots": 1,
"agents": [
{ "id": "lead", "name": "lead", "position": "the main agent", "parent": null, "state": "working",
"model": "qwen-27b", "mode": "edit", "request": [], "manager": true,
"context": { "used": 41200, "window": 131072 }, "progress": { "phase": "thinking", "since": 1762790400000 } },
{ "id": "s1", "name": "parser", "position": "reviews the parser", "parent": "lead", "state": "working",
"model": "qwen-27b", "mode": "manual", "request": ["write"], "manager": true, "task": "…",
"context": { "used": 9100, "window": 131072 },
"progress": { "phase": "running_tool", "since": 1762790401000, "tool": "read", "what": "src/parse.ts" },
"findings": 2, "messages": 3 },
{ "id": "s3", "name": "lexer", "position": "the lexer's tests", "parent": "parser", "state": "paused",
"model": "qwen-27b", "mode": "manual", "request": [], "manager": false, "task": "…", "findings": 0, "messages": 0 }
],
"ended": [ { "id": "s0", "name": "scout", "position": "…", "parent": "lead", "state": "done", "ended": 1762790300000, "findings": 1 } ] }
""",
)
@Test
fun theTreeReads() {
assertEquals(1, tree.openSlots)
val parser = tree.agents[1]
assertEquals("s1", parser.id)
assertEquals("running_tool", parser.progress?.phase)
assertEquals(listOf("write"), parser.request)
assertTrue(tree.agents[0].isMain)
assertFalse(parser.isMain)
}
@Test
fun contextIsFlooredAndNeedsAWindow() {
assertEquals(31, tree.agents[0].contextPercent) // 41200 × 100 / 131072 = 31.43
assertEquals(6, tree.agents[1].contextPercent)
assertNull(tree.agents[2].contextPercent)
}
@Test
fun rowsInTreeOrderThenTheEnded() {
val rows = TreeLogic.rows(tree)
assertEquals(listOf("lead", "parser", "lexer", "scout"), rows.map { it.agent.name })
assertEquals(listOf(0, 1, 2, 1), rows.map { it.depth })
assertEquals(listOf(false, false, false, true), rows.map { it.ended })
}
@Test
fun aParentTheTreeDoesNotHoldIsTheMainAgents() {
val moved = tree.copy(agents = tree.agents.map { if (it.name == "lexer") it.copy(parent = "gone") else it })
assertEquals(1, TreeLogic.rows(moved).single { it.agent.name == "lexer" }.depth)
}
@Test
fun theMainAgentAloneIsNoList() {
assertFalse(TreeLogic.hasSubagents(null))
assertFalse(TreeLogic.hasSubagents(tree.copy(agents = tree.agents.take(1), ended = emptyList(), openSlots = 0)))
assertTrue(TreeLogic.hasSubagents(tree.copy(agents = tree.agents.take(1), ended = emptyList(), openSlots = 2)))
assertTrue(TreeLogic.hasSubagents(tree))
}
@Test
fun aSubagentOpensAsAMember() {
val agent = ActivityLogic.ofTreeAgent(tree.agents[1])
assertEquals("member", agent.kind)
assertEquals("parser", agent.id)
assertTrue(agent.transcript)
}
}
@@ -25,10 +25,13 @@ import eu.llembas.android.api.ScheduleRun
import eu.llembas.android.api.SchedulingModel
import eu.llembas.android.api.SchedulingModels
import eu.llembas.android.api.Step
import eu.llembas.android.api.SubagentTree
import eu.llembas.android.api.SubagentsOffer
import eu.llembas.android.api.Tail
import eu.llembas.android.api.ToolBlock
import eu.llembas.android.api.ToolCall
import eu.llembas.android.api.TreeAgent
import eu.llembas.android.api.TreeContext
import eu.llembas.android.assist.AssistTurn
import eu.llembas.android.assist.AssistUiState
import eu.llembas.android.assist.Connection
@@ -199,6 +202,46 @@ object Fakes {
live = writing.live!!.copy(progress = Progress(phase = "waiting_for_model", since = 1762790400000, model = "Qwen 27B", reason = "busy")),
)
/**
* The activity sheet of a chat with subagents (spec 3.4.0's tree): the main agent, a
* sub-manager with one under it paused, one waiting for a slot, an open slot and one ended.
*/
val activityTree = activity.copy(
tree = SubagentTree(
min = 2,
max = 5,
size = 4,
openSlots = 1,
agents = listOf(
TreeAgent(
id = "lead", name = "lead", position = "the main agent", state = "working", model = "qwen", mode = "edit", manager = true,
context = TreeContext(41_200, 131_072), progress = Progress(phase = "waiting_for_subagents", since = 1762790400000, running = 2),
),
TreeAgent(
id = "s1", name = "parser", position = "reviews the parser and everything that reads its output", parent = "lead",
state = "working", model = "qwen", mode = "edit", manager = true, context = TreeContext(9_100, 131_072),
progress = Progress(phase = "running_tool", since = 1762790401000, tool = "read", what = "src/parse.ts"),
),
TreeAgent(
id = "s3", name = "lexer", position = "the lexer's tests", parent = "parser", state = "paused",
model = "qwen", mode = "manual", context = TreeContext(112_000, 131_072), progress = Progress(phase = "thinking", since = 1762790402000),
),
TreeAgent(id = "s4", name = "docs", position = "writes the changelog", parent = "lead", state = "waiting", model = "qwen", mode = "edit"),
),
ended = listOf(
TreeAgent(
id = "s2",
name = "scout",
position = "finds the old parser",
parent = "lead",
state = "out_of_context",
ended = 1762790300000,
findings = 2,
),
),
),
)
/** A chat on a model with effort levels, a team and a plan: the tune sheet with everything. */
val tuned = transcript.copy(
chat = chat.copy(model = "gpt-oss", effort = "high", mode = "plan", agents = AgentsSetting(1, 4)),
@@ -174,6 +174,10 @@ class ScreenShots {
shoot("14-activity", Phone.Small, fontScale = 1.5f, content = sheet)
shoot("14-activity", Phone.Scroll, content = sheet)
shoot("15-activity-open", Phone.Scroll, content = open)
// Spec 3.4.0's subagents: the reduced list above the background tasks.
val tree: @Composable () -> Unit = { SheetOver { ActivityContent(Fakes.activityTree, readAt = 0, now = 0, actions = NoActivityActions) } }
shoot("26-subagents", Phone.Scroll, content = tree)
shoot("26-subagents", Phone.Small, fontScale = 1.5f, content = tree)
shoot("16-activity-new-chat") {
SheetOver { ActivityContent(eu.llembas.android.api.Activity(), readAt = 0, now = 0, actions = NoActivityActions, canCompact = false) }
}