merge #1139: fix(tasks) read the team roster from subagentCatalog
# Conflicts: # CHANGELOG.md # CHANGELOG_EN.md
This commit is contained in:
commit
c67a8d1aa8
12 files changed
+300
-254
No files matched your search
@@ -14,6 +14,13 @@
|
||||
|
||||
- 🐞 **侧栏不再被钉死在已删除的 linked worktree 上**([#960](https://github.com/omdsh-dev/DSH-better-sidebar/issues/960)):worktree 被外部删除(`git worktree remove`、或直接删目录)后,进程级的路径/顶层缓存仍会把它当作活跃根目录返回,文件树报「文件夹不存在」、git 面板报「不是 git 仓库」,主仓库完好却只能重启恢复。现在缓存命中时会校验目标目录是否仍在(一次 `stat()`,相比它要避免的 ~7ms git 进程开销可忽略),已消失即失效并回落到会话 cwd 对应的仓库顶层。
|
||||
|
||||
- 🐞 **任务管理页在 DSH 0.2.2 线上不再整页崩在 `Cannot read properties of undefined (reading 'map')`**:0.2.2 的 `agentTeam` Session 投影不再携带 `members`(上游 Team 包迁移 `122dc3af42` 把名册移出投影,wire 只剩 `enabled` / `tasks` / `failure`),而本插件仍按 0.1.7 的形状读 `team.members.map(...)` —— `members` 是 `undefined` 时这里直接抛 `TypeError`,被面板级错误边界接住,于是「任务管理」整页只剩一行红字和一个永远无效的「重试」。
|
||||
- **影响面**:DSH **0.2.2** 线(凡带 Team 包迁移的宿主,含 0.2.2-rc.1 之后)上,只要该会话启用了 Team 模式(`agentTeam` 投影存在),打开「任务管理」即触发;与工作区、会话内容、插件配置无关。重试不会好 —— 投影的形状不会变。0.1.7 / 0.2.1 线不受影响,那些宿主的 `agentTeam` 仍然带 `members`。
|
||||
- **修复**:名册改由 **Lead 的 `subagentCatalog`** 重建。0.2.2 的成员真源就是它 —— 团队成员即 Lead 的直接 subagent,catalog 一行一个。实现为「Lead 行 + catalog 行」,名字取 `name ?? label ?? id`;投影新增 `enabled`:为 `false` 时不画团队板,**旧宿主没有该字段时视为启用**,因此这次改动对 0.1.7 / 0.2.1 线向后兼容。
|
||||
- **随之消失的两项**(上游已不再提供,不是本次取舍):roster 的 `phase`(`provisioning` / `failed`)与 per-member `error`。成员状态只剩「运行中 / 待命」;一次失败的 spawn 不会在 catalog 里留下行,名册上没有它的位置。
|
||||
- **另一个可观察变化**:团队模式下**所有**直接子 agent 都是成员,不再存在"部分成员",所以「已完成」折叠组只在**无团队**的树里出现(成员恒为待命),同一父节点下不会再有 done / idle 两个组并存。
|
||||
- 🧪 测试:`tests/team-projection.spec.ts` 重写为 catalog 驱动的名册(`enabled:false` 隐藏、旧宿主无 `enabled` 仍显示、Summary 的 run 位优先于 live 驻留);`tests/tasks-model.spec.ts` 与 `tests/tasks-page.spec.tsx` 改用 catalog 名构造成员,并把"同父下 done/idle 不再共存"写进用例注释。
|
||||
|
||||
### v0.30.1
|
||||
|
||||
- 🎯 **设置页「侧边卡片」的导航图标不再叠成两个**:插件此前按"宿主设置导航还没有图标通道"的老假设,用 CSS 把兜底齿轮藏起来、再画自己的图标;宿主早已提供按 section id 寻址的 `settings.section.icon` 插槽,而且图标的 DOM 外面多了一层 span,老选择器失效后兜底 SVG 露了出来,与插件图标并排显示。现在改为**走宿主插槽**提供图标,删掉标记 + CSS 遮罩那一套(顺带去掉了一个监听整个 document 的 MutationObserver)。
|
||||
|
||||
@@ -16,6 +16,13 @@
|
||||
|
||||
- 🐞 **The sidebar no longer pins itself to a deleted linked worktree** ([#960](https://github.com/omdsh-dev/DSH-better-sidebar/issues/960)): once a worktree was deleted externally (`git worktree remove`, or a plain folder delete), the process-wide path / top-level caches kept answering with it, so the file tree reported a missing folder and every git command reported "not a git repository" — with no recovery short of a restart. Cache hits now verify the directory still exists (one `stat()`, negligible next to the ~7ms git spawn these caches exist to avoid) and otherwise invalidate, falling back to the session cwd's repository.
|
||||
|
||||
- 🐞 **The Tasks page no longer dies on `Cannot read properties of undefined (reading 'map')` on the DSH 0.2.2 line**: 0.2.2's `agentTeam` Session projection no longer carries `members` (the upstream Team package migration `122dc3af42` moved the roster out; the wire value is `enabled` / `tasks` / `failure`), while the plugin still read `team.members.map(...)` in the 0.1.7 shape. `undefined.map` throws, the panel-level error boundary catches it, and the whole Tasks page degrades to one red line plus a Retry button that can never help.
|
||||
- **Reach**: on DSH **0.2.2** (any host carrying the Team package migration) and only for a session running Team mode (`agentTeam` present), opening Tasks crashes regardless of workspace, conversation, or plugin config. The 0.1.7 / 0.2.1 lines are unaffected — their `agentTeam` still carries `members`.
|
||||
- **Fix**: the roster is rebuilt from the **Lead's `subagentCatalog`**, which is 0.2.2's member source of truth (a team member IS a direct subagent of the Lead): a Lead row plus one row per catalog entry, named `name ?? label ?? id`. The projection gains `enabled` — `false` hides the board, and a host without the field reads as enabled, so this stays backward compatible with the 0.1.7 / 0.2.1 lines.
|
||||
- **Two capabilities are gone with the upstream field**: the roster's `phase` (`provisioning` / `failed`) and its per-member `error`. Members read as running / waiting only, and a spawn that never produced a catalog entry has no row to draw.
|
||||
- **One visible behaviour change**: under Team mode **every** direct child is a member, so partial membership no longer exists — the finished (`done`) fold group appears only in a team-less tree, and one parent never folds into both groups at once.
|
||||
- 🧪 `tests/team-projection.spec.ts` is rewritten for the catalog-driven roster (`enabled:false` hides, a host without `enabled` still shows, the summary run bit beats live residency); `tests/tasks-model.spec.ts` and `tests/tasks-page.spec.tsx` build members from catalog names and record that done/idle no longer coexist under one parent.
|
||||
|
||||
### v0.30.1
|
||||
|
||||
- 🎯 **The "Side card" settings row no longer shows two icons**: the plugin still assumed the settings navigation had no icon channel, so it hid the fallback gear with CSS and painted its own glyph. The shell has long since exposed a `settings.section.icon` slot addressed by section id, and it now wraps the nav icon in a span — the stale `> svg:first-child` rule stopped hiding the fallback, so both glyphs rendered side by side. The row now contributes its icon **through the slot**, and the marker + CSS-mask apparatus is gone (along with a document-wide MutationObserver).
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
# 2026-11-06 团队名册改读 subagentCatalog(`agentTeam.members` 移除适配)
|
||||
|
||||
> 目标:让「任务管理」在 `agentTeam` 投影去掉 `members` 之后继续可用——不是补一把空值兜底,而是把名册搬到它现在的真源上。
|
||||
|
||||
## 1. 结论
|
||||
|
||||
| 项 | 改动前 | 改动后 |
|
||||
| --- | --- | --- |
|
||||
| 名册来源 | `agentTeam.members`(0.1.7 形状) | **Lead 的 `subagentCatalog`**:Lead 行 + catalog 行 |
|
||||
| 成员名字 | 投影的 `name` | `name ?? label ?? id`(v3 载荷起 catalog 行带 `name`) |
|
||||
| 成员状态 | `running / idle / provisioning / failed` | **`running / idle`**(durable phase 随投影消失) |
|
||||
| 团队板显隐 | 投影存在即显示 | 投影存在且 `enabled !== false`(旧宿主没有该字段 → 仍显示) |
|
||||
| 每成员错误 | `member.error` → `diagnostics[]` | 无(只剩板级 `failure`) |
|
||||
| 任务归属匹配 | `member.name` | `member.name`,另加空串路径(Lead 自身的 agent path) |
|
||||
|
||||
## 2. 上游变化与证据
|
||||
|
||||
`agentTeam` 是 Session projection,浏览器从 `SessionListState.projectionsBySession[leadId].values.agentTeam`
|
||||
读它。它的 wire schema 决定这个插件能读到什么:
|
||||
|
||||
| 版本 | wire schema | 成员在哪 |
|
||||
| --- | --- | --- |
|
||||
| DSH 0.1.7 ~ 0.2.1 | `{ members, tasks, failure? }`(`experimental/agent-team`) | 投影自带 `members` |
|
||||
| DSH 0.2.2-rc.1(npm `latest` tag) | 同上 | 同上 |
|
||||
| master(Team 包迁移之后) | `{ enabled, tasks, failure? }`,`.strict()` | **不在投影里**,改由 `subagentCatalog` 提供 |
|
||||
|
||||
证据链:
|
||||
|
||||
- 迁移 commit `122dc3af42`(`refactor(team): isolate package group`)把 Team 从
|
||||
`packages/experimental/agent-team` 移到 `packages/team/agent-team`,同一批改掉了 wire schema:
|
||||
`teamProjectionSchema = z.object({ enabled, tasks, failure? }).strict()`。
|
||||
- 该 commit **不在任何 release tag 里**(`git tag --contains 122dc3af42` 为空),所以 0.2.2-rc.1 的
|
||||
发布产物仍是带 `members` 的旧形状——这就是为什么这个崩溃只在跑 master / 后续版本的宿主上出现。
|
||||
- 升级说明 `docs/upgrade-guide/v0.2.1-rc.2/agent-team-subagents/guide.md` 写下了同一结论:
|
||||
"The wire `agentTeam.members` field and `TeamMemberProjection` are removed",并指明成员浏览改由
|
||||
subagent 导航承担。
|
||||
- `TeamProjectionState`(fold 状态)也不再保留 roster:只剩 `id / enabled / tasks / nextTaskNumber / failure`,
|
||||
所以这不是"投影裁剪了字段",而是名册这个概念整体离开了 Team。
|
||||
|
||||
## 3. 修复
|
||||
|
||||
| 文件 | 改动 |
|
||||
| --- | --- |
|
||||
| [src/client/team-projection.ts](../src/client/team-projection.ts) | `teamMembersOf` 改为 `(team, rootId, entries, live, byId)`:Lead 行 + catalog 行;`teamProjectionOf` 增加 `enabled === false → undefined` |
|
||||
| [src/context-types.ts](../src/context-types.ts) | `SidebarTeamProjection` 去掉 `members`、加 `enabled?`;删掉 `SidebarTeamMemberProjection`;`SidebarSubagentCatalogEntry` 补 `name?` |
|
||||
| [src/client/SubagentView.tsx](../src/client/SubagentView.tsx) | 调用点把 Lead 的 catalog entries 传进名册(和拓扑用的是同一份 `catalogs[rootId]`) |
|
||||
| [src/client/tasks-model.ts](../src/client/tasks-model.ts) | 节点上的 `team` 去掉 `phase` / `diagnostics`;`teamState` 只剩两态;归属映射补空串路径 → Lead |
|
||||
| [src/client/tasks-shared.tsx](../src/client/tasks-shared.tsx) | 删掉 `provisioning` / `failed` 两个文案分支 |
|
||||
| [src/client/TeamBoard.tsx](../src/client/TeamBoard.tsx) | 状态点只剩 `ongoing` / `idle` |
|
||||
|
||||
关键是**不伪造字段**:`phase` 与 per-member `error` 的值域在 0.2.2 已不存在,
|
||||
保留一个恒为 `active` 的空壳只会让下一个人以为它在工作——这个仓库上一次就是这样被
|
||||
"字段漂移没人看见"坑到的(见 `team-projection.ts` 原注释里那句 warning)。
|
||||
|
||||
## 4. 影响面与降级
|
||||
|
||||
- **受影响**:DSH 0.2.2 线上带 Team 包迁移的宿主(master 及之后),且该会话启用 Team 模式。
|
||||
现象是「任务管理」面板整页被错误边界接住,只剩一行 `Cannot read properties of undefined (reading 'map')`。
|
||||
- **不受影响**:0.1.7 / 0.2.1 线。它们的 `agentTeam` 仍带 `members`,而新实现读 `subagentCatalog`
|
||||
(那些宿主同样有),`enabled` 缺失按启用处理。
|
||||
- **降级**(上游不再提供,无法恢复):名册上没有 `provisioning` / `failed` 状态;一次失败的 spawn
|
||||
不产生 catalog 行,因此没有行可画。
|
||||
- **行为变化**:团队模式下所有直接子 agent 都是成员,不再有"部分成员"。所以「已完成」折叠组
|
||||
只在无团队的树里出现,同一父节点下不会同时存在 done / idle 两个组。
|
||||
|
||||
## 5. 验证
|
||||
|
||||
- `pnpm typecheck`:通过。
|
||||
- `pnpm test`:全量 3042 例,3022 passed / 17 skipped;2 个失败是本地 pnpm 版本门禁
|
||||
(`packageManager: pnpm@11.8.0` vs 本机 11.28.5 的 corepack 检查),把版本临时对齐后 12/12 通过。
|
||||
- 真机:在 DSH master(`node --import tsx/esm apps/cli/src/bin.ts web`)+ 本插件构建上打开「任务管理」,
|
||||
面板正常渲染,团队板显示 Lead 与各子 agent,任务按 owner 落到对应节点。
|
||||
@@ -326,8 +326,16 @@ export function SubagentView(props: {
|
||||
[list.projectionsBySession, rootId],
|
||||
)
|
||||
const teamMembers = useMemo(
|
||||
() => teamMembersOf(team, live, byId),
|
||||
[team, live, byId],
|
||||
// A team member IS a direct subagent of the Lead, so the roster comes from
|
||||
// the same catalog rows the topology below already draws.
|
||||
() => teamMembersOf(
|
||||
team,
|
||||
rootId,
|
||||
rootId === undefined ? [] : catalogs[rootId]?.entries ?? [],
|
||||
live,
|
||||
byId,
|
||||
),
|
||||
[team, rootId, catalogs, live, byId],
|
||||
)
|
||||
|
||||
// The default view mode comes from the side card prefs (settings select);
|
||||
|
||||
@@ -33,15 +33,10 @@ import css from './tasks-graph.module.css'
|
||||
|
||||
/**
|
||||
* The status dot of one roster row: the member's derived status (see
|
||||
* ./team-projection.ts — durable phase first, live activity second).
|
||||
* ./team-projection.ts — the session's own run bit).
|
||||
*/
|
||||
function memberDotState(status: TeamMemberRow['status']): 'ongoing' | 'idle' | 'error' {
|
||||
switch (status) {
|
||||
case 'running': return 'ongoing'
|
||||
case 'provisioning': return 'ongoing'
|
||||
case 'failed': return 'error'
|
||||
case 'idle': return 'idle'
|
||||
}
|
||||
function memberDotState(status: TeamMemberRow['status']): 'ongoing' | 'idle' {
|
||||
return status === 'running' ? 'ongoing' : 'idle'
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,6 @@ import type {
|
||||
SidebarSessionSummary,
|
||||
SidebarSubagentAddress,
|
||||
SidebarSubagentCatalogEntry,
|
||||
SidebarTeamMemberProjection,
|
||||
SidebarTeamTaskView,
|
||||
} from '../context-types.ts'
|
||||
import type { SidebarChildLiveView } from '../context-types.ts'
|
||||
@@ -72,11 +71,8 @@ export interface TasksAgentNode {
|
||||
team?: {
|
||||
role: 'lead' | 'teammate'
|
||||
name: string
|
||||
/** Durable lifecycle of the roster row (`provisioning | active | failed`). */
|
||||
phase: SidebarTeamMemberProjection['phase']
|
||||
/** The member's derived display status (see ./team-projection.ts). */
|
||||
status: TeamMemberRow['status']
|
||||
diagnostics: string[]
|
||||
}
|
||||
/**
|
||||
* Tree depth (the root is 0). Drives the card's GROUP COLOUR: every node of
|
||||
@@ -281,16 +277,11 @@ function foldNode(
|
||||
|
||||
/**
|
||||
* Map a team member's derived status onto the node display state. The status
|
||||
* already folds in the durable phase (./team-projection.ts), so this is a
|
||||
* vocabulary translation and nothing more.
|
||||
* already folds in the session's own run bit (./team-projection.ts), so this
|
||||
* is a vocabulary translation and nothing more.
|
||||
*/
|
||||
function teamState(status: TeamMemberRow['status']): TasksNodeState {
|
||||
switch (status) {
|
||||
case 'running': return 'running'
|
||||
case 'provisioning': return 'running'
|
||||
case 'failed': return 'error'
|
||||
case 'idle': return 'idle'
|
||||
}
|
||||
return status === 'running' ? 'running' : 'idle'
|
||||
}
|
||||
|
||||
/** The workflow member's display state from its outcome (undefined = live). */
|
||||
@@ -320,6 +311,9 @@ export function buildTasksModel(input: TasksModelInput): TasksNode[] {
|
||||
/** Owner display name → node id (the board assigns by member name). */
|
||||
const nodeByOwner = new Map<string, string>()
|
||||
for (const member of teamMembers) nodeByOwner.set(member.name, member.id)
|
||||
// The Lead's own agent path is the EMPTY string, while its roster name is
|
||||
// `lead`; the board spells the same owner both ways.
|
||||
nodeByOwner.set('', rootId)
|
||||
const tasksByNode = new Map<string, TasksNodeTask[]>()
|
||||
for (const task of teamTasks) {
|
||||
if (task.status === 'deleted' || task.ownerName === undefined) continue
|
||||
@@ -343,7 +337,7 @@ export function buildTasksModel(input: TasksModelInput): TasksNode[] {
|
||||
const member = teamById.get(id)
|
||||
return member === undefined
|
||||
? undefined
|
||||
: { role: member.role, name: member.name, phase: member.phase, status: member.status, diagnostics: member.diagnostics }
|
||||
: { role: member.role, name: member.name, status: member.status }
|
||||
}
|
||||
|
||||
const out: (TasksAgentNode | TasksWorkflowNode)[] = []
|
||||
|
||||
@@ -207,17 +207,12 @@ export function agentChip(node: TasksAgentNode): string | undefined {
|
||||
if (node.parentId === undefined) return undefined
|
||||
const mode = modeLabel(node.mode)
|
||||
if (mode !== undefined) return mode
|
||||
if (node.team === undefined) return undefined
|
||||
if (node.team.phase === 'provisioning') return t('tasksStateProvisioning')
|
||||
if (node.team.phase === 'failed') return t('tasksStateError')
|
||||
return undefined
|
||||
}
|
||||
|
||||
/** The roster row's own identity word (the fallback for a modelless teammate). */
|
||||
function teamRoleLabel(team: NonNullable<TasksAgentNode['team']>): string | undefined {
|
||||
if (team.role === 'lead') return undefined
|
||||
if (team.phase === 'provisioning') return t('tasksStateProvisioning')
|
||||
if (team.phase === 'failed') return t('tasksStateError')
|
||||
return t('tasksKindTeammate')
|
||||
}
|
||||
|
||||
|
||||
@@ -1,72 +1,70 @@
|
||||
/**
|
||||
* The plugin's view of DSH 0.1.7's `agentTeam` Session projection — the Lead
|
||||
* Session's team board, read straight off the client snapshot.
|
||||
* The plugin's view of the host's `agentTeam` Session projection — the Lead
|
||||
* Session's shared task board — plus the roster the board draws beside it.
|
||||
*
|
||||
* 0.1.6 exposed the board through the experimental service's Remote vocabulary
|
||||
* (`agentTeams.remoteView`, reached over the wire) and the page had to poll it
|
||||
* every 5s. 0.1.7 deleted that trio and publishes the same state as a Session
|
||||
* projection instead: `SessionListState.projectionsBySession[leadId].values
|
||||
* .agentTeam`, loaded once per connection like every other projection. This
|
||||
* module is therefore a pure adapter — no request, no poller, no observer —
|
||||
* exactly like ./subagent-catalog.ts for the catalog.
|
||||
* DSH 0.2.2 reshaped that projection: the wire value is now
|
||||
* `{ enabled, tasks, failure? }` and no longer carries `members`
|
||||
* (upgrade-guide v0.2.1-rc.2 "agentTeam.members is removed"; the Team package
|
||||
* migration 122dc3af42 moved the roster out of the Team projection for good).
|
||||
* A team member IS a direct subagent of the Lead, so the roster this module
|
||||
* publishes is the Lead's `subagentCatalog` — the projection
|
||||
* ./subagent-catalog.ts already folds for the topology — with the Lead row
|
||||
* prepended.
|
||||
*
|
||||
* Two facts the durable projection does not carry are DERIVED, not invented:
|
||||
* Two facts the projection used to carry are genuinely gone, and this module
|
||||
* does not fake them:
|
||||
*
|
||||
* - TURN ACTIVITY. A projection row is `{ id, name, role, phase, error? }`
|
||||
* where `phase` is the durable lifecycle (`provisioning | active | failed`,
|
||||
* the Lead row always `active`). Whether a member is running right now comes
|
||||
* from the session's own status — upstream's own web UI "reads the shared
|
||||
* Session projections and overlays activity from Session status" — and this
|
||||
* plugin already has that overlay: `subagents.live` reports EVERY tree child
|
||||
* with an explicit `running` flag (see ./subagent-catalog.ts's `childLive`),
|
||||
* with the session list's own coarse `running` as the fallback for the Lead.
|
||||
* - `diagnostics`, the 0.1.6 view's array of provisioning notes, collapses to
|
||||
* the projection's single durable `error` string.
|
||||
* - there is no durable `phase`: `provisioning` / `failed` were the old roster
|
||||
* lifecycle, and a spawn that never produced a catalog entry has no row to
|
||||
* draw at all;
|
||||
* - there is no per-member `error`: the only failure left is the board-wide
|
||||
* `failure` string, which the board itself reports.
|
||||
*
|
||||
* What is genuinely gone is the member's `model` (and `description` /
|
||||
* `provider` / `context`): the wire view never carried them, so the node
|
||||
* detail no longer has a model row to show. See the design note
|
||||
* docs/plans/2026-09-27-agent-teams-dsh-0.1.7-adaptation.md.
|
||||
* Turn activity is derived, not invented: the session list's `running` bit is
|
||||
* authoritative, the live channel's flag is the catalog's RESIDENCY and only
|
||||
* stands in when the summaries do not carry the field (issue #800 — a retained
|
||||
* session reads `running` in the live map while no agent drives it).
|
||||
*/
|
||||
import type {
|
||||
SidebarChildLiveView,
|
||||
SidebarSessionList,
|
||||
SidebarSessionSummary,
|
||||
SidebarTeamMemberProjection,
|
||||
SidebarSubagentCatalogEntry,
|
||||
SidebarTeamProjection,
|
||||
} from '../context-types.ts'
|
||||
|
||||
/**
|
||||
* One roster row as this page consumes it: the projection's durable half plus
|
||||
* the derived runtime status. A THIRD type next to the host service's
|
||||
* `SidebarTeamMemberView` on purpose — that one is the 0.1.6 `listMembers`
|
||||
* shape (status/description/provider/model) this plugin no longer reads, and
|
||||
* conflating the two is exactly how the field drift that broke the board went
|
||||
* unnoticed.
|
||||
* The root agent's fixed name (the host's `ROOT_AGENT_NAME`). Named here
|
||||
* rather than imported: a client bundle may not value-import the host's
|
||||
* subagent package, and the Lead is the only row whose name is not a catalog
|
||||
* entry.
|
||||
*/
|
||||
const ROOT_AGENT_NAME = 'lead'
|
||||
|
||||
/** One roster row as this page consumes it: identity plus the derived runtime status. */
|
||||
export interface TeamMemberRow {
|
||||
/** The member's session id (the teammate's child session under the lead). */
|
||||
/** The member's session id (the Lead itself, or a direct child under it). */
|
||||
id: string
|
||||
/** The member's agent name: `lead` at the root, the catalog name below it. */
|
||||
name: string
|
||||
role: 'lead' | 'teammate'
|
||||
/** Durable lifecycle, as the projection publishes it. */
|
||||
phase: SidebarTeamMemberProjection['phase']
|
||||
/** Derived display status: durable phase wins, else the live activity flag. */
|
||||
status: 'running' | 'idle' | 'provisioning' | 'failed'
|
||||
/** The durable provisioning error as a one-item list (see the header). */
|
||||
diagnostics: string[]
|
||||
/** Derived display status: the session's own run bit, live flag as the fallback. */
|
||||
status: 'running' | 'idle'
|
||||
}
|
||||
|
||||
/**
|
||||
* The team board led by `rootId`, or undefined when that session leads none.
|
||||
*
|
||||
* ABSENT MEANS NO TEAM, and there are three ways to get there: the deployment
|
||||
* never mounted the experimental layer (no projection key at all), the root is
|
||||
* a teammate rather than the Lead, or the session simply has no team. All
|
||||
* three collapse into "the page draws no Teams block" — the same silent
|
||||
* degradation the 0.1.6 route expressed as `{available:false}` (layer absent)
|
||||
* and `{team:null}` (root leads none), with one lookup instead of two states
|
||||
* the page had to distinguish and never did.
|
||||
* never mounted the Team layer (no projection key at all), the session leads no
|
||||
* team (`enabled: false` — the durable mode selection), or the root is a
|
||||
* teammate rather than the Lead. All three collapse into "the page draws no
|
||||
* Teams block", which is the same silent degradation the 0.1.6 route expressed
|
||||
* as `{available:false}` and `{team:null}`.
|
||||
*
|
||||
* A host that still publishes the pre-0.2.2 value carries no `enabled` flag;
|
||||
* that reads as enabled, which keeps the board visible exactly where it used
|
||||
* to be.
|
||||
*
|
||||
* @param projections - `SessionListState.projectionsBySession`.
|
||||
* @param rootId - the tree's root session (the only session that can be Lead).
|
||||
@@ -76,52 +74,40 @@ export function teamProjectionOf(
|
||||
rootId: string | undefined,
|
||||
): SidebarTeamProjection | undefined {
|
||||
if (rootId === undefined) return undefined
|
||||
return projections?.[rootId]?.values.agentTeam
|
||||
const team = projections?.[rootId]?.values.agentTeam
|
||||
return team?.enabled === false ? undefined : team
|
||||
}
|
||||
|
||||
/**
|
||||
* Overlay runtime activity onto the durable roster.
|
||||
* Build the roster: the Lead, then the Lead's direct children from its catalog.
|
||||
*
|
||||
* Status precedence is deliberately narrow: the durable phase wins for the two
|
||||
* states it owns (`failed` never becomes "running" because a retry is in
|
||||
* flight, `provisioning` is not yet a turn), and only an `active` member asks
|
||||
* the live channel whether it is running right now. A member the channel does
|
||||
* not mention yet (the first poll of a freshly rooted tree) reads as `idle`,
|
||||
* which is the safe direction: it never claims work that is not happening.
|
||||
* The catalog is the ONLY roster source now (see the module header), so a child
|
||||
* that the catalog does not list is not a member — there is no second list to
|
||||
* disagree with, which is what kept the old `members` drift invisible.
|
||||
*
|
||||
* @param team - the Lead's projection ({@link teamProjectionOf}).
|
||||
* @param rootId - the tree's root session id.
|
||||
* @param entries - the Lead's `subagentCatalog` rows, in catalog order.
|
||||
* @param live - the `subagents.live` map (`session id → live view`).
|
||||
* @param byId - the session list by id (the Lead's own running flag lives here).
|
||||
*/
|
||||
export function teamMembersOf(
|
||||
team: SidebarTeamProjection | undefined,
|
||||
rootId: string | undefined,
|
||||
entries: readonly SidebarSubagentCatalogEntry[],
|
||||
live: Readonly<Record<string, SidebarChildLiveView | undefined>>,
|
||||
byId: Readonly<Record<string, SidebarSessionSummary | undefined>>,
|
||||
): TeamMemberRow[] {
|
||||
if (team === undefined) return []
|
||||
return team.members.map(member => ({
|
||||
id: member.id,
|
||||
name: member.name,
|
||||
role: member.role,
|
||||
phase: member.phase,
|
||||
status: memberStatus(member, live, byId),
|
||||
diagnostics: member.error === undefined ? [] : [member.error],
|
||||
}))
|
||||
}
|
||||
|
||||
/** One member's runtime status (see {@link teamMembersOf} for the rule). */
|
||||
function memberStatus(
|
||||
member: SidebarTeamMemberProjection,
|
||||
live: Readonly<Record<string, SidebarChildLiveView | undefined>>,
|
||||
byId: Readonly<Record<string, SidebarSessionSummary | undefined>>,
|
||||
): TeamMemberRow['status'] {
|
||||
if (member.phase === 'failed') return 'failed'
|
||||
if (member.phase === 'provisioning') return 'provisioning'
|
||||
// The summary's `running` is the authoritative run bit; the live channel's
|
||||
// flag is the catalog's RESIDENCY, which reads `running` for a retained
|
||||
// session that no agent is driving (a crash-restart — issue #800). Same rule
|
||||
// as the task tree: authoritative wins, the live flag only stands in when the
|
||||
// host's summaries do not carry the field.
|
||||
const running = byId[member.id]?.running ?? live[member.id]?.running
|
||||
return running === true ? 'running' : 'idle'
|
||||
if (team === undefined || rootId === undefined) return []
|
||||
const statusOf = (id: string): TeamMemberRow['status'] =>
|
||||
(byId[id]?.running ?? live[id]?.running) === true ? 'running' : 'idle'
|
||||
return [
|
||||
{ id: rootId, name: ROOT_AGENT_NAME, role: 'lead', status: statusOf(rootId) },
|
||||
...entries.map(entry => ({
|
||||
id: entry.id,
|
||||
name: entry.name ?? entry.label ?? entry.id,
|
||||
role: 'teammate' as const,
|
||||
status: statusOf(entry.id),
|
||||
})),
|
||||
]
|
||||
}
|
||||
+16
-20
@@ -417,28 +417,18 @@ export interface SidebarTeamMemberView {
|
||||
}
|
||||
|
||||
/**
|
||||
* One durable roster row of the Lead Session's `agentTeam` projection. Phase
|
||||
* is the DURABLE lifecycle (the Lead row is always `active`); turn activity is
|
||||
* overlaid from the session's own status (see ./client/team-projection.ts).
|
||||
*/
|
||||
export interface SidebarTeamMemberProjection {
|
||||
/** The member's session id (the teammate's child session under the lead). */
|
||||
id: string
|
||||
name: string
|
||||
role: 'lead' | 'teammate'
|
||||
phase: 'provisioning' | 'active' | 'failed'
|
||||
/** The provisioning failure, when the durable row records one. */
|
||||
error?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* The Lead Session's published team state: durable roster identities and
|
||||
* phases, member errors, the non-deleted task views (0.1.6's `TeamView` shape,
|
||||
* enriched per task exactly like the service's own views), and the first
|
||||
* rejected Team record when the board had to stop at its last valid state.
|
||||
* The Lead Session's published team state: the durable mode selection, the
|
||||
* non-deleted task views, and the first rejected Team record when the board had
|
||||
* to stop at its last valid state.
|
||||
*
|
||||
* The roster is NOT part of this value. Since the Team package migration the
|
||||
* wire value carries no `members`; a team member is a direct subagent of the
|
||||
* Lead and is read from the Lead's `subagentCatalog` instead (see
|
||||
* ./client/team-projection.ts).
|
||||
*/
|
||||
export interface SidebarTeamProjection {
|
||||
members: readonly SidebarTeamMemberProjection[]
|
||||
/** The durable Team-mode selection; `false` means this session runs no team. */
|
||||
enabled?: boolean
|
||||
tasks: readonly SidebarTeamTaskView[]
|
||||
failure?: string
|
||||
}
|
||||
@@ -606,6 +596,12 @@ export interface SidebarSubagentCatalogEntry {
|
||||
mode: 'one-shot' | 'continuable' | 'unknown'
|
||||
/** Mode-specific label; continuable children always carry one. */
|
||||
label?: string
|
||||
/**
|
||||
* The child's agent name, unique among its siblings (catalog payload v3).
|
||||
* Absent on entries recorded before names existed, and on modes that never
|
||||
* carried one.
|
||||
*/
|
||||
name?: string
|
||||
}
|
||||
|
||||
/** The client sessions service face (only the list feed is needed). */
|
||||
|
||||
+25
-37
@@ -55,7 +55,7 @@ function run(over: Partial<WorkflowRunView> = {}): WorkflowRunView {
|
||||
|
||||
/** A derived roster row (the shape ./team-projection.ts hands the model). */
|
||||
function member(over: Partial<TeamMemberRow> = {}): TeamMemberRow {
|
||||
return { id: 'x', name: 'n', role: 'teammate', phase: 'active', status: 'running', diagnostics: [], ...over }
|
||||
return { id: 'x', name: 'n', role: 'teammate', status: 'running', ...over }
|
||||
}
|
||||
|
||||
/** A base input; override per test. */
|
||||
@@ -141,21 +141,12 @@ describe('buildTasksModel', () => {
|
||||
byId: { root: summary('root'), w: summary('w') },
|
||||
teamMembers: [
|
||||
member({ id: 'root', name: 'lead', role: 'lead' }),
|
||||
member({ id: 'w', name: 'writer', phase: 'active', status: 'idle' }),
|
||||
member({ id: 'w', name: 'writer', status: 'idle' }),
|
||||
],
|
||||
}))
|
||||
expect(agents(model).find(node => node.id === 'root')?.team?.role).toBe('lead')
|
||||
const w = agents(model).find(node => node.id === 'w')
|
||||
expect(w?.team).toMatchObject({ role: 'teammate', name: 'writer', phase: 'active', status: 'idle' })
|
||||
})
|
||||
|
||||
it('gives a provisioning teammate the running node state', () => {
|
||||
const model = buildTasksModel(input({
|
||||
catalogs: { root: catalog([child('w')]) },
|
||||
byId: { root: summary('root'), w: summary('w') },
|
||||
teamMembers: [member({ id: 'w', phase: 'provisioning', status: 'provisioning' })],
|
||||
}))
|
||||
expect(agents(model).find(node => node.id === 'w')?.state).toBe('running')
|
||||
expect(w?.team).toMatchObject({ role: 'teammate', name: 'writer', status: 'idle' })
|
||||
})
|
||||
|
||||
it('folds a settled team member when the READER folds it by hand', () => {
|
||||
@@ -167,13 +158,13 @@ describe('buildTasksModel', () => {
|
||||
const model = buildTasksModel(input({
|
||||
catalogs: { root: catalog([child('mate'), child('sub')]), sub: catalog([]) },
|
||||
byId: { root: summary('root'), mate: summary('mate'), sub: summary('sub') },
|
||||
teamMembers: [member({ id: 'mate', phase: 'failed', status: 'failed' })],
|
||||
teamMembers: [member({ id: 'mate', status: 'idle' })],
|
||||
folded: false,
|
||||
foldedIds: new Set(['mate', 'sub']),
|
||||
}))
|
||||
expect(model.map(node => node.id)).toEqual(['root', 'fold:root'])
|
||||
expect(model.find(node => node.kind === 'fold')).toMatchObject({
|
||||
count: 2, memberIds: ['mate', 'sub'],
|
||||
expect(model.map(node => node.id)).toEqual(['root', 'fold:root', 'fold:root:idle'])
|
||||
expect(model.find(node => node.kind === 'fold' && node.foldKind === 'idle')).toMatchObject({
|
||||
count: 1, memberIds: ['mate'],
|
||||
})
|
||||
})
|
||||
|
||||
@@ -181,7 +172,7 @@ describe('buildTasksModel', () => {
|
||||
const model = buildTasksModel(input({
|
||||
catalogs: { root: catalog([child('mate'), child('sub')]), sub: catalog([]) },
|
||||
byId: { root: summary('root'), mate: summary('mate'), sub: summary('sub') },
|
||||
teamMembers: [member({ id: 'mate', phase: 'failed', status: 'failed' })],
|
||||
teamMembers: [member({ id: 'mate', status: 'idle' })],
|
||||
folded: true,
|
||||
}))
|
||||
expect(model.map(node => node.id)).toEqual(['root', 'mate', 'fold:root'])
|
||||
@@ -191,7 +182,7 @@ describe('buildTasksModel', () => {
|
||||
const model = buildTasksModel(input({
|
||||
catalogs: { root: catalog([child('mate')]) },
|
||||
byId: { root: summary('root'), mate: summary('mate') },
|
||||
teamMembers: [member({ id: 'mate', phase: 'active', status: 'running' })],
|
||||
teamMembers: [member({ id: 'mate', status: 'running' })],
|
||||
folded: false,
|
||||
foldedIds: new Set(['mate']),
|
||||
}))
|
||||
@@ -303,25 +294,24 @@ describe('buildTasksModel', () => {
|
||||
it('keeps the finished and the waiting members in SEPARATE rows', () => {
|
||||
const model = buildTasksModel(input({
|
||||
catalogs: {
|
||||
root: catalog([child('m1'), child('m2'), child('m3'), child('done-1'), child('failed-1')]),
|
||||
root: catalog([child('m1'), child('m2'), child('m3'), child('done-1')]),
|
||||
...Object.fromEntries(
|
||||
['m1', 'm2', 'm3', 'done-1', 'failed-1'].map(id => [id, catalog([])]),
|
||||
['m1', 'm2', 'm3', 'done-1'].map(id => [id, catalog([])]),
|
||||
),
|
||||
},
|
||||
byId: Object.fromEntries(
|
||||
[['root', summary('root')], ...['m1', 'm2', 'm3', 'done-1', 'failed-1'].map(id => [id, summary(id)])],
|
||||
[['root', summary('root')], ...['m1', 'm2', 'm3', 'done-1'].map(id => [id, summary(id)])],
|
||||
),
|
||||
teamMembers: [
|
||||
...['m1', 'm2', 'm3'].map(id => member({ id, name: id, status: 'idle' })),
|
||||
member({ id: 'failed-1', name: 'failed-1', phase: 'failed', status: 'failed' }),
|
||||
],
|
||||
}))
|
||||
const folders = model.filter(node => node.kind === 'fold')
|
||||
expect(folders.map(node => node.id)).toEqual(['fold:root', 'fold:root:idle'])
|
||||
// finished work + the failure, with the failure called out beside the ✓
|
||||
// finished work — a child that is NOT a roster member — in its own row
|
||||
expect(folders[0]).toMatchObject({
|
||||
foldKind: 'done', count: 2, doneCount: 1, idleCount: 0, errorCount: 1,
|
||||
memberIds: ['done-1', 'failed-1'],
|
||||
foldKind: 'done', count: 1, doneCount: 1, idleCount: 0, errorCount: 0,
|
||||
memberIds: ['done-1'],
|
||||
})
|
||||
// …and the waiting members in their own row, which claims no completion
|
||||
expect(folders[1]).toMatchObject({
|
||||
@@ -362,26 +352,26 @@ describe('buildTasksModel', () => {
|
||||
})
|
||||
|
||||
it('expands ONE group per reader click, leaving the sibling aggregate folded', () => {
|
||||
// Two groups of one parent at once: finished work (`done-1` / `failed-1`)
|
||||
// and three waiting teammates. Opening the finished group must reveal those
|
||||
// two nodes and NOTHING else — the page used to clear every fold it had.
|
||||
// Two groups of one parent at once: finished work (`done-1`, a child that
|
||||
// is NOT a roster member) and three waiting teammates. Opening the finished
|
||||
// group must reveal that node and NOTHING else — the page used to clear
|
||||
// every fold it had.
|
||||
const base = input({
|
||||
catalogs: {
|
||||
root: catalog([child('m1'), child('m2'), child('m3'), child('done-1'), child('failed-1')]),
|
||||
root: catalog([child('m1'), child('m2'), child('m3'), child('done-1')]),
|
||||
...Object.fromEntries(
|
||||
['m1', 'm2', 'm3', 'done-1', 'failed-1'].map(id => [id, catalog([])]),
|
||||
['m1', 'm2', 'm3', 'done-1'].map(id => [id, catalog([])]),
|
||||
),
|
||||
},
|
||||
byId: Object.fromEntries(
|
||||
[['root', summary('root')], ...['m1', 'm2', 'm3', 'done-1', 'failed-1'].map(id => [id, summary(id)])],
|
||||
[['root', summary('root')], ...['m1', 'm2', 'm3', 'done-1'].map(id => [id, summary(id)])],
|
||||
),
|
||||
teamMembers: [
|
||||
...['m1', 'm2', 'm3'].map(id => member({ id, name: id, status: 'idle' })),
|
||||
member({ id: 'failed-1', name: 'failed-1', phase: 'failed', status: 'failed' }),
|
||||
],
|
||||
})
|
||||
expect(buildTasksModel({ ...base, expandedGroups: new Set(['fold:root']) })
|
||||
.map(node => node.id)).toEqual(['root', 'done-1', 'failed-1', 'fold:root:idle'])
|
||||
.map(node => node.id)).toEqual(['root', 'done-1', 'fold:root:idle'])
|
||||
// …and the idle group's own opening leaves the finished one folded. Kept
|
||||
// children keep the catalog order; the aggregates trail whatever stays
|
||||
// folded (the model's one ordering rule).
|
||||
@@ -522,7 +512,7 @@ describe('buildTasksModel: settled branches', () => {
|
||||
expect(model.at(-1)).toMatchObject({ memberIds: ['a', 'b'], count: 2 })
|
||||
})
|
||||
|
||||
it.each(['running', 'current', 'unknown', 'error', 'idle', 'provisioning'])(
|
||||
it.each(['running', 'current', 'unknown', 'error', 'idle'])(
|
||||
'keeps a branch reachable with a %s descendant', (guard) => {
|
||||
const base = branch()
|
||||
if (guard === 'running') base.live = running('b')
|
||||
@@ -530,7 +520,6 @@ describe('buildTasksModel: settled branches', () => {
|
||||
if (guard === 'unknown') base.catalogs = { ...base.catalogs, b: undefined }
|
||||
if (guard === 'error') base.catalogs = { ...base.catalogs, b: { entries: [], state: 'error', error: { message: 'unavailable' } } }
|
||||
if (guard === 'idle') base.teamMembers = [member({ id: 'b', status: 'idle' })]
|
||||
if (guard === 'provisioning') base.teamMembers = [member({ id: 'b', phase: 'provisioning', status: 'provisioning' })]
|
||||
expect(buildTasksModel(base).map(node => node.id)).toEqual(['root', 'a', 'b'])
|
||||
},
|
||||
)
|
||||
@@ -646,7 +635,6 @@ describe('buildTasksModel: settled branches', () => {
|
||||
it('preserves workflow member subtrees, guards and hidden agent tallies', () => {
|
||||
const base = input({
|
||||
catalogs: { root: catalog([child('m')]), m: catalog([child('b')]), b: catalog([]) },
|
||||
teamMembers: [member({ id: 'b', phase: 'failed', status: 'failed' })],
|
||||
runs: [run({ status: 'completed', phases: [{ members: [
|
||||
{ seq: 1, label: 'm', childId: 'm', outcome: 'completed' },
|
||||
{ seq: 2, label: 'duplicate', childId: 'm', outcome: 'completed' },
|
||||
@@ -654,7 +642,7 @@ describe('buildTasksModel: settled branches', () => {
|
||||
})
|
||||
expect(buildTasksModel(base)).toMatchObject([
|
||||
{ id: 'root' }, { id: 'run:run-1' },
|
||||
{ id: 'fold:run:run-1', count: 2, doneCount: 1, errorCount: 1, memberIds: ['m', 'b'] },
|
||||
{ id: 'fold:run:run-1', count: 2, doneCount: 2, errorCount: 0, memberIds: ['m', 'b'] },
|
||||
])
|
||||
const opened = buildTasksModel({ ...base, folded: false })
|
||||
expect(opened.map(node => node.id)).toEqual(['root', 'run:run-1', 'm', 'b'])
|
||||
|
||||
+34
-42
@@ -27,7 +27,6 @@ import type {
|
||||
SidebarSessionSummary,
|
||||
SidebarSubagentAddress,
|
||||
SidebarSubagentCatalogEntry,
|
||||
SidebarTeamMemberProjection,
|
||||
SidebarTeamProjection,
|
||||
SidebarTeamTaskView,
|
||||
} from '../src/context-types.ts'
|
||||
@@ -175,6 +174,8 @@ function jsonError(status: number, code: string, message: string): Response {
|
||||
|
||||
/** The Lead Session's `agentTeam` projection the board reads (undefined = none). */
|
||||
let teamProjection: SidebarTeamProjection | undefined
|
||||
/** Agent names the current test's catalog rows carry (see {@link withTeam}). */
|
||||
let catalogNames: string[] = []
|
||||
const teamMutations: Array<{ method: string; body: Record<string, unknown> }> = []
|
||||
const fetchedMethods: string[] = []
|
||||
/** The `subagents.live` payload the stub answers with (session id → live view). */
|
||||
@@ -282,7 +283,10 @@ function snapshotWithChildren(count: number): SidebarSessionList {
|
||||
for (let index = 0; index < count; index += 1) {
|
||||
const id = `child-${index}`
|
||||
byId[id] = { id, displayTitle: id, origin: 'subagent', parentId: 'root', running: false }
|
||||
entries.push({ id, createdAt: 1_000 + index, mode: 'one-shot', label: `子代理 ${index}` })
|
||||
entries.push({
|
||||
id, createdAt: 1_000 + index, mode: 'one-shot', label: `子代理 ${index}`,
|
||||
name: catalogNames[index],
|
||||
})
|
||||
projectionsBySession[id] = { values: { subagentCatalog: [] }, state: 'ready', error: null }
|
||||
}
|
||||
projectionsBySession.root = {
|
||||
@@ -518,23 +522,25 @@ describe('Tasks page interactions', () => {
|
||||
})
|
||||
|
||||
/**
|
||||
* The Lead Session's projection for one test run: members + tasks, or absent
|
||||
* (`withTeam(null)`) when the tree leads no team. A task omitted from `tasks`
|
||||
* is not on the board at all.
|
||||
* The Lead Session's projection for one test run: the mode flag plus tasks, or
|
||||
* absent (`withTeam(null)`) when the tree leads no team. The roster is NOT part
|
||||
* of that value — members are the Lead's `subagentCatalog` rows — so a test
|
||||
* that needs NAMED members pins them with `names`, which the snapshots below
|
||||
* write onto those rows. A task omitted from `tasks` is not on the board at all.
|
||||
*/
|
||||
function withTeam(input: {
|
||||
members?: SidebarTeamMemberProjection[]
|
||||
enabled?: boolean
|
||||
tasks?: SidebarTeamTaskView[]
|
||||
names?: readonly string[]
|
||||
} | null = {}): void {
|
||||
if (input === null) {
|
||||
teamProjection = undefined
|
||||
catalogNames = []
|
||||
return
|
||||
}
|
||||
catalogNames = [...(input.names ?? [])]
|
||||
teamProjection = {
|
||||
members: input.members ?? [
|
||||
{ id: 'root', name: 'lead', role: 'lead', phase: 'active' },
|
||||
{ id: 'child-0', name: 'writer', role: 'teammate', phase: 'active' },
|
||||
],
|
||||
enabled: input.enabled ?? true,
|
||||
tasks: input.tasks ?? [],
|
||||
}
|
||||
}
|
||||
@@ -775,7 +781,7 @@ describe('Tasks page graph interactions and team board', () => {
|
||||
})
|
||||
|
||||
it('shows the team board without any click when the root leads a team', async () => {
|
||||
withTeam({ tasks: [teamTask()] })
|
||||
withTeam({ names: ['writer'], tasks: [teamTask()] })
|
||||
const store = makeStore(snapshotWithChildren(1))
|
||||
const { container, unmount } = renderRoot(
|
||||
createElement(SubagentView, { sessionId: 'root', active: true, ctx: makeCtx(store) }),
|
||||
@@ -807,6 +813,7 @@ describe('Tasks page: owned tasks, host-primitive controls, draggable output', (
|
||||
/** A board whose two tasks are both owned by the child agent. */
|
||||
function teamWithOwnedTask(): void {
|
||||
withTeam({
|
||||
names: ['writer'],
|
||||
tasks: [
|
||||
teamTask({ subject: '收窄卡片与图标化', ownerName: 'writer' }),
|
||||
teamTask({
|
||||
@@ -930,6 +937,7 @@ describe('Tasks page: owned tasks, host-primitive controls, draggable output', (
|
||||
describe('Tasks page: the shared task window', () => {
|
||||
it('opens from an agent node task line and saves a multi-line edit', async () => {
|
||||
withTeam({
|
||||
names: ['writer'],
|
||||
tasks: [teamTask({
|
||||
revision: 4, description: '第一行\n\n- 第二行', ownerName: 'writer',
|
||||
})],
|
||||
@@ -969,11 +977,7 @@ describe('Tasks page: the shared task window', () => {
|
||||
|
||||
it('reassigns the owner straight from the window (CAS on the current revision)', async () => {
|
||||
withTeam({
|
||||
members: [
|
||||
{ id: 'root', name: 'lead', role: 'lead', phase: 'active' },
|
||||
{ id: 'child-0', name: 'writer', role: 'teammate', phase: 'active' },
|
||||
{ id: 'child-1', name: 'reviewer', role: 'teammate', phase: 'active' },
|
||||
],
|
||||
names: ['writer', 'reviewer'],
|
||||
tasks: [teamTask({ revision: 7, description: '', status: 'pending', ownerName: 'writer' })],
|
||||
})
|
||||
const store = makeStore(snapshotWithChildren(2))
|
||||
@@ -1236,10 +1240,7 @@ describe('Tasks page: the shared task window', () => {
|
||||
// of their OWN: the finished work keeps its "✓ N 已完成" badge and the
|
||||
// waiting members count themselves on the badge, instead of hiding inside
|
||||
// a ✓ count.
|
||||
const mate = (index: number): SidebarTeamMemberProjection => ({
|
||||
id: `child-${index}`, name: `mate-${index}`, role: 'teammate', phase: 'active',
|
||||
})
|
||||
withTeam({ members: [{ id: 'root', name: 'lead', role: 'lead', phase: 'active' }, ...[0, 1, 2].map(mate)] })
|
||||
withTeam()
|
||||
const store = makeStore(snapshotWithChildren(3))
|
||||
const { container, unmount } = renderRoot(
|
||||
createElement(SubagentView, { sessionId: 'root', active: true, ctx: makeCtx(store) }),
|
||||
@@ -1260,10 +1261,7 @@ describe('Tasks page: the shared task window', () => {
|
||||
it('offers a WAITING card its own fold chevron (idle is foldable by hand)', async () => {
|
||||
// Below the idle head count nothing folds automatically; each waiting card
|
||||
// still carries the chevron, which is what "点击没反应" was about.
|
||||
const mate = (index: number): SidebarTeamMemberProjection => ({
|
||||
id: `child-${index}`, name: `mate-${index}`, role: 'teammate', phase: 'active',
|
||||
})
|
||||
withTeam({ members: [{ id: 'root', name: 'lead', role: 'lead', phase: 'active' }, ...[0, 1].map(mate)] })
|
||||
withTeam()
|
||||
const store = makeStore(snapshotWithChildren(2))
|
||||
const { container, unmount } = renderRoot(
|
||||
createElement(SubagentView, { sessionId: 'root', active: true, ctx: makeCtx(store) }),
|
||||
@@ -1551,33 +1549,28 @@ describe('Tasks page: the node status line and per-group expansion', () => {
|
||||
unmount()
|
||||
})
|
||||
|
||||
it('expands ONE aggregate group per click; the cluster still folds the page', async () => {
|
||||
// Two settled subagents (the `done` group) plus three waiting teammates
|
||||
// (the `idle` group): both aggregates exist at once, which is exactly what
|
||||
// makes "one click unfolded everything" observable.
|
||||
const mate = (index: number): SidebarTeamMemberProjection => ({
|
||||
id: `child-${index}`, name: `mate-${index}`, role: 'teammate', phase: 'active',
|
||||
})
|
||||
withTeam({
|
||||
members: [{ id: 'root', name: 'lead', role: 'lead', phase: 'active' }, ...[2, 3, 4].map(mate)],
|
||||
})
|
||||
it('expands the waiting aggregate by one click; the cluster still folds the page', async () => {
|
||||
// Every direct child of the Lead is a team member, and a member reads as
|
||||
// WAITING until its own turn runs — so this tree folds into exactly ONE
|
||||
// group. A `done` group needs finished children that are NOT members, which
|
||||
// the catalog-driven roster cannot express under a single parent; the
|
||||
// team-less tree is the surface that folds finished work.
|
||||
withTeam()
|
||||
const store = makeStore(snapshotWithChildren(5))
|
||||
const { container, unmount } = renderRoot(
|
||||
createElement(SubagentView, { sessionId: 'root', active: true, ctx: makeCtx(store) }),
|
||||
)
|
||||
await flushJobs()
|
||||
expect(container.querySelector('[data-graph-node="fold:root"]')).not.toBeNull()
|
||||
expect(container.querySelector('[data-graph-node="fold:root:idle"]')).not.toBeNull()
|
||||
expect(container.querySelector('[data-graph-node="fold:root"]')).toBeNull()
|
||||
|
||||
// One click on the finished group reveals ITS members only.
|
||||
// One click on the aggregate reveals the members it swallowed.
|
||||
await act(async () => {
|
||||
(container.querySelector('[data-graph-node="fold:root"]') as HTMLElement).click()
|
||||
(container.querySelector('[data-graph-node="fold:root:idle"]') as HTMLElement).click()
|
||||
})
|
||||
expect(container.querySelector('[data-graph-node="child-0"]')).not.toBeNull()
|
||||
expect(container.querySelector('[data-graph-node="child-1"]')).not.toBeNull()
|
||||
expect(container.querySelector('[data-graph-node="fold:root"]')).toBeNull()
|
||||
expect(container.querySelector('[data-graph-node="fold:root:idle"]')).not.toBeNull()
|
||||
expect(container.querySelector('[data-graph-node="child-2"]')).toBeNull()
|
||||
expect(container.querySelector('[data-graph-node="child-2"]')).not.toBeNull()
|
||||
expect(container.querySelector('[data-graph-node="fold:root:idle"]')).toBeNull()
|
||||
|
||||
// The cluster keeps the page-level switch: unfolding the page shows every
|
||||
// node, and collapsing it re-folds every group — including the one the
|
||||
@@ -1589,7 +1582,6 @@ describe('Tasks page: the node status line and per-group expansion', () => {
|
||||
await act(async () => {
|
||||
(container.querySelector('button[aria-label="折叠已完成的节点"]') as HTMLButtonElement).click()
|
||||
})
|
||||
expect(container.querySelector('[data-graph-node="fold:root"]')).not.toBeNull()
|
||||
expect(container.querySelector('[data-graph-node="fold:root:idle"]')).not.toBeNull()
|
||||
expect(container.querySelector('[data-graph-node="child-0"]')).toBeNull()
|
||||
unmount()
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
/**
|
||||
* Unit tests for the `agentTeam` projection adapter: reading the Lead
|
||||
* Session's board off the client snapshot, and overlaying runtime activity
|
||||
* onto the durable roster.
|
||||
* Session's board off the client snapshot, and building the roster from the
|
||||
* Lead's `subagentCatalog`.
|
||||
*
|
||||
* The shape under test is DSH 0.1.7's `TeamProjection` (see the experimental
|
||||
* package's `lib/types/types.d.ts`): `{ members: {id,name,role,phase,error?},
|
||||
* tasks: TeamTaskView[], failure? }`. There is no `available` flag and no
|
||||
* `model` field — a projection that is absent means "this session leads no
|
||||
* team" (or the deployment never mounted the layer), which is the same silent
|
||||
* The value under test is DSH 0.2.2's `TeamProjection`
|
||||
* (`{ enabled, tasks, failure? }`): the roster moved out of it, so a member is
|
||||
* a direct subagent read from the catalog. `enabled: false` — and an absent
|
||||
* projection — both mean "this session leads no team", the same silent
|
||||
* degradation either way.
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest'
|
||||
@@ -16,18 +15,13 @@ import type {
|
||||
SidebarChildLiveView,
|
||||
SidebarSessionList,
|
||||
SidebarSessionSummary,
|
||||
SidebarTeamMemberProjection,
|
||||
SidebarSubagentCatalogEntry,
|
||||
SidebarTeamProjection,
|
||||
} from '../src/context-types.ts'
|
||||
|
||||
/** One durable roster row. */
|
||||
function member(over: Partial<SidebarTeamMemberProjection> = {}): SidebarTeamMemberProjection {
|
||||
return { id: 'w', name: 'writer', role: 'teammate', phase: 'active', ...over }
|
||||
}
|
||||
|
||||
/** One Lead Session projection. */
|
||||
function team(over: Partial<SidebarTeamProjection> = {}): SidebarTeamProjection {
|
||||
return { members: [member()], tasks: [], ...over }
|
||||
return { enabled: true, tasks: [], ...over }
|
||||
}
|
||||
|
||||
/** The snapshot's projection map with one session's team installed. */
|
||||
@@ -38,6 +32,11 @@ function projections(
|
||||
return { [rootId]: { values: { agentTeam: teamValue }, state: 'ready', error: null } }
|
||||
}
|
||||
|
||||
/** One direct-child catalog row. */
|
||||
function entry(id: string, over: Partial<SidebarSubagentCatalogEntry> = {}): SidebarSubagentCatalogEntry {
|
||||
return { id, createdAt: 1, mode: 'one-shot', ...over }
|
||||
}
|
||||
|
||||
/** A summary row. */
|
||||
function summary(id: string, over: Partial<SidebarSessionSummary> = {}): SidebarSessionSummary {
|
||||
return { id, displayTitle: id, ...over }
|
||||
@@ -53,83 +52,90 @@ describe('teamProjectionOf', () => {
|
||||
expect(teamProjectionOf(projections('root', team()), undefined)).toBeUndefined()
|
||||
expect(teamProjectionOf(undefined, 'root')).toBeUndefined()
|
||||
// A session the projection store knows, but which leads no team (the
|
||||
// deployment without the experimental layer, or a plain subagent tree).
|
||||
// deployment without the Team layer, or a plain subagent tree).
|
||||
const other: SidebarSessionList['projectionsBySession'] = {
|
||||
root: { values: {}, state: 'ready', error: null },
|
||||
}
|
||||
expect(teamProjectionOf(other, 'root')).toBeUndefined()
|
||||
expect(teamProjectionOf(projections('root', team()), 'someone-else')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('hides a board whose durable mode selection is off', () => {
|
||||
expect(teamProjectionOf(projections('root', team({ enabled: false })), 'root')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('keeps a board from a host that publishes no mode flag', () => {
|
||||
const legacy: SidebarTeamProjection = { tasks: [] }
|
||||
expect(teamProjectionOf(projections('root', legacy), 'root')).toBe(legacy)
|
||||
})
|
||||
})
|
||||
|
||||
describe('teamMembersOf', () => {
|
||||
const noLive: Record<string, SidebarChildLiveView | undefined> = {}
|
||||
|
||||
it('answers an empty roster without a team', () => {
|
||||
expect(teamMembersOf(undefined, noLive, {})).toEqual([])
|
||||
it('answers an empty roster without a team or without a root', () => {
|
||||
expect(teamMembersOf(undefined, 'root', [entry('w')], noLive, {})).toEqual([])
|
||||
expect(teamMembersOf(team(), undefined, [entry('w')], noLive, {})).toEqual([])
|
||||
})
|
||||
|
||||
it('carries the durable phase and the member identity through', () => {
|
||||
it('puts the Lead first and takes its children from the catalog', () => {
|
||||
const rows = teamMembersOf(
|
||||
team({ members: [member({ id: 'lead', name: 'lead', role: 'lead' }), member({ id: 'w' })] }),
|
||||
team(),
|
||||
'root',
|
||||
[entry('w', { name: 'writer' }), entry('r', { name: 'reviewer' })],
|
||||
noLive,
|
||||
{},
|
||||
)
|
||||
expect(rows).toEqual([
|
||||
{ id: 'lead', name: 'lead', role: 'lead', phase: 'active', status: 'idle', diagnostics: [] },
|
||||
{ id: 'w', name: 'writer', role: 'teammate', phase: 'active', status: 'idle', diagnostics: [] },
|
||||
{ id: 'root', name: 'lead', role: 'lead', status: 'idle' },
|
||||
{ id: 'w', name: 'writer', role: 'teammate', status: 'idle' },
|
||||
{ id: 'r', name: 'reviewer', role: 'teammate', status: 'idle' },
|
||||
])
|
||||
})
|
||||
|
||||
it('falls back to the mode label and then the id for a row without a name', () => {
|
||||
const rows = teamMembersOf(
|
||||
team(),
|
||||
'root',
|
||||
[entry('w', { label: '子代理 0' }), entry('x')],
|
||||
noLive,
|
||||
{},
|
||||
)
|
||||
expect(rows.map(row => row.name)).toEqual(['lead', '子代理 0', 'x'])
|
||||
})
|
||||
|
||||
it('reads an active member activity from the live channel', () => {
|
||||
const live: Record<string, SidebarChildLiveView | undefined> = { w: { running: true } }
|
||||
expect(teamMembersOf(team(), live, {})[0]?.status).toBe('running')
|
||||
const rows = teamMembersOf(team(), 'root', [entry('w')], live, {})
|
||||
expect(rows[1]?.status).toBe('running')
|
||||
})
|
||||
|
||||
it('falls back to the session list running flag (the Lead is no live child)', () => {
|
||||
const byId = { lead: summary('lead', { running: true }) }
|
||||
const rows = teamMembersOf(
|
||||
team({ members: [member({ id: 'lead', name: 'lead', role: 'lead' })] }),
|
||||
noLive,
|
||||
byId,
|
||||
)
|
||||
const byId = { root: summary('root', { running: true }) }
|
||||
const rows = teamMembersOf(team(), 'root', [], noLive, byId)
|
||||
expect(rows[0]?.status).toBe('running')
|
||||
})
|
||||
|
||||
it('never claims a running turn while the durable phase disagrees', () => {
|
||||
const live: Record<string, SidebarChildLiveView | undefined> = { w: { running: true } }
|
||||
const provisioning = teamMembersOf(team({ members: [member({ phase: 'provisioning' })] }), live, {})
|
||||
expect(provisioning[0]?.status).toBe('provisioning')
|
||||
const failed = teamMembersOf(team({ members: [member({ phase: 'failed' })] }), live, {})
|
||||
expect(failed[0]?.status).toBe('failed')
|
||||
})
|
||||
|
||||
it('ignores the live channel residency when the summary says the agent is not running (issue #800)', () => {
|
||||
// The live flag is the catalog's SESSION RESIDENCY: a retained session
|
||||
// whose agent died in a crash-restart reads `running` there while the
|
||||
// authoritative summary stays false. The summary wins.
|
||||
const live: Record<string, SidebarChildLiveView | undefined> = { w: { running: true } }
|
||||
const byId = { w: summary('w', { running: false }) }
|
||||
expect(teamMembersOf(team(), live, byId)[0]?.status).toBe('idle')
|
||||
const rows = teamMembersOf(team(), 'root', [entry('w')], live, byId)
|
||||
expect(rows[1]?.status).toBe('idle')
|
||||
})
|
||||
|
||||
it('takes the Summary running bit even when the live channel says otherwise', () => {
|
||||
const live: Record<string, SidebarChildLiveView | undefined> = { w: { running: false } }
|
||||
const byId = { w: summary('w', { running: true }) }
|
||||
expect(teamMembersOf(team(), live, byId)[0]?.status).toBe('running')
|
||||
})
|
||||
|
||||
it('exposes the durable member error as the diagnostics list', () => {
|
||||
const rows = teamMembersOf(
|
||||
team({ members: [member({ phase: 'failed', error: 'spawn rejected' })] }),
|
||||
noLive,
|
||||
{},
|
||||
)
|
||||
expect(rows[0]?.diagnostics).toEqual(['spawn rejected'])
|
||||
const rows = teamMembersOf(team(), 'root', [entry('w')], live, byId)
|
||||
expect(rows[1]?.status).toBe('running')
|
||||
})
|
||||
|
||||
it('treats a member the live channel has not mentioned as idle', () => {
|
||||
const live: Record<string, SidebarChildLiveView | undefined> = { other: { running: true } }
|
||||
expect(teamMembersOf(team(), live, {})[0]?.status).toBe('idle')
|
||||
const rows = teamMembersOf(team(), 'root', [entry('w')], live, {})
|
||||
expect(rows[1]?.status).toBe('idle')
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user