用户在自己跑的 3080 实例上测完报回六条,逐条修:
1. 「已完成的聚合卡下方空荡荡」= 上一轮把计数收进徽标后那条只剩一个
chevron(我的取舍造成)。小条改为动作行:组图标 + 「展开」(新词条
tasksFoldExpandShort × 20 词典)+ 出错尾注 + 展开箭头。
2. 「展开后的子代理点不回去」= 真缺陷:expandedGroups 压过了 foldedIds,
展开组内卡片的 chevron 失效。改成手动折叠优先(手动 → 页级规则 →
组展开),补模型 + 组件两层判别性用例。
3. 「一次性一直显示」→ 模式词搬进徽标行成 chip(用户口径)。智能体卡不再
有 mono 元信息行,卡片高度预算拆成 GRAPH_AGENT_NODE_H / GRAPH_NODE_H
(只有 workflow run 卡保留元信息行),rowStrideFor(nodes) 按模型里有没有
run 选行距。
4. 动效:接入 @formkit/auto-animate(用户选定,~3KB、无依赖无安装脚本)+
useAutoAnimateRef 包装(WAAPI 守卫 → jsdom 空转、尊重 reduced-motion),
挂到画布卡片层 / 树视图 / 任务抽屉;详情卡另加 140ms 入场关键帧。核心
bundle +56KB(未压缩 CJS)。
5. 弹窗多两项:Token 用量(宿主 tokenUsage 四桶求和,悬停给明细)+ 耗时
(宿主 subagentTiming,按 3s 轮询刷新)。SidebarProjectionSnapshot 镜像
补两个键、模型新增 metrics 入参;**按存在性渲染**,没有测量就不显示这一
行(0 是投影初始态,与「没工作过」不可区分)。
6. 「查看转录」改为在原生右侧栏打开:宿主 ui-subagent 的 subagentchat tab
类型(宿主自己的子代理列表就是点行=主窗、点 chevron=侧栏)。插件照抄其
地址公式并调 openResource(..., { kind, preferNewPane: true }),三级降级回
主窗;页脚变「主按钮 + caret 菜单(在主窗口中打开)」。
测试 2238 passed / 17 skipped(191 文件)、tsc 0 错误、eslint 0 错误、构建
通过;新构建已装进 sidebar-test profile,:3080 上挂载正常、0 pageerror。
动效观感与真实数据的两行数值未在真机逐帧核验(右栏在无头上下文里被
transform 移出视口,合成点击不稳)——已如实记进设计文档的第二轮偏差段。
182 lines
7.8 KiB
TypeScript
182 lines
7.8 KiB
TypeScript
/**
|
|
* Unit tests for the layered graph layout: parent centering, depth rows, the
|
|
* sibling-band WRAP that keeps a narrow sidebar readable (and the row
|
|
* reservation that stops a wrapped band from landing on a sibling's
|
|
* children), the PER-SHAPE card height (the mode chip's badge row and the
|
|
* shared-task row a card renders are reserved, so a card never renders outside
|
|
* its box), and the width-aware solver.
|
|
*/
|
|
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
GRAPH_AGENT_NODE_H,
|
|
GRAPH_GAP_Y,
|
|
GRAPH_NODE_H,
|
|
GRAPH_NODE_W,
|
|
GRAPH_PAD,
|
|
GRAPH_ROW_STRIDE,
|
|
GRAPH_TASK_H,
|
|
bandColsFor,
|
|
layoutTasksGraph,
|
|
layoutTasksGraphForWidth,
|
|
rowStrideFor,
|
|
} from '../src/client/tasks-graph-layout.ts'
|
|
import type { TasksAgentNode, TasksNode, TasksNodeTask } from '../src/client/tasks-model.ts'
|
|
|
|
/** One shared task as the card's task line shows it. */
|
|
function task(id: string): TasksNodeTask {
|
|
return { id, subject: id, status: 'in_progress', ready: true }
|
|
}
|
|
|
|
/** An agent node. `live` gives it a text-only tail; `extra` shapes the card
|
|
* further (a settled state, a tool call, owned shared tasks). */
|
|
function agent(
|
|
id: string,
|
|
parentId?: string,
|
|
live = false,
|
|
extra: Partial<TasksAgentNode> = {},
|
|
): TasksAgentNode {
|
|
return {
|
|
kind: 'agent', id, ...(parentId === undefined ? {} : { parentId }),
|
|
depth: parentId === undefined ? 0 : 1,
|
|
label: id, state: 'running', activity: 'running', current: false,
|
|
...(live ? { live: { running: true, text: 'x' } } : {}),
|
|
...extra,
|
|
}
|
|
}
|
|
|
|
/** One running node's live view: a merged activity row (the bar's text). */
|
|
const ACTIVITY = {
|
|
running: true,
|
|
summary: { counts: [{ kind: 'read' as const, count: 1 }], running: 'read' as const, runningDetail: 'x' },
|
|
}
|
|
|
|
/**
|
|
* The row index of one laid-out node. The pitch is per MODEL now (a run card
|
|
* keeps its meta line, an agent card does not), so the helper asks the layout's
|
|
* own rule rather than the tallest constant.
|
|
*/
|
|
function layoutRow(
|
|
layout: ReturnType<typeof layoutTasksGraph>,
|
|
id: string,
|
|
nodes: readonly TasksNode[],
|
|
): number {
|
|
const box = layout.boxes.get(id)
|
|
if (box === undefined) throw new Error(`no box for ${id}`)
|
|
return (box.y - GRAPH_PAD) / rowStrideFor(nodes)
|
|
}
|
|
|
|
describe('layout: card heights', () => {
|
|
it('reserves the state bar for every node kind, and the task row only for team members', () => {
|
|
const nodes: TasksNode[] = [
|
|
agent('root'),
|
|
agent('busy', 'root', false, { live: ACTIVITY }),
|
|
agent('owner', 'root', false, { tasks: [task('t1')] }),
|
|
]
|
|
const layout = layoutTasksGraph(nodes)
|
|
// The merged activity lives in the bar, which every card renders: a
|
|
// running node and a settled one reserve exactly the same base height. The
|
|
// base is the AGENT card (badges + two title lines + the bar): the mode
|
|
// word moved into the badge row, so no card reserves a mono meta line —
|
|
// only a workflow RUN does (see the stride case below).
|
|
expect(layout.boxes.get('root')?.h).toBe(GRAPH_AGENT_NODE_H)
|
|
expect(layout.boxes.get('busy')?.h).toBe(GRAPH_AGENT_NODE_H)
|
|
expect(layout.boxes.get('owner')?.h).toBe(GRAPH_AGENT_NODE_H + GRAPH_TASK_H)
|
|
})
|
|
|
|
it('keeps every card shape inside one row stride', () => {
|
|
// The stride is the row pitch: a card taller than it would overlap the
|
|
// next row (and its phase frame).
|
|
const tallest = GRAPH_AGENT_NODE_H + GRAPH_TASK_H
|
|
expect(GRAPH_ROW_STRIDE).toBeGreaterThanOrEqual(tallest)
|
|
const nodes: TasksNode[] = [
|
|
agent('root'),
|
|
agent('busiest', 'root', false, { live: { ...ACTIVITY, text: 'y' }, tasks: [task('t1')] }),
|
|
]
|
|
const layout = layoutTasksGraph(nodes)
|
|
expect(layout.boxes.get('busiest')?.h).toBe(tallest)
|
|
// An agent-only model pitches its rows at the agent card; a model with a
|
|
// workflow run (the only card that keeps a meta line) pitches at the
|
|
// taller run card, so no card ever pokes into the row below.
|
|
const withRun: TasksNode[] = [
|
|
...nodes,
|
|
{
|
|
kind: 'workflow', id: 'run:r', parentId: 'root', depth: 1,
|
|
run: {
|
|
runId: 'r', name: 'audit', originSessionId: 'root', status: 'running',
|
|
phases: [], startedSeq: 1, startedAt: 0,
|
|
},
|
|
},
|
|
]
|
|
expect(rowStrideFor(nodes)).toBe(GRAPH_AGENT_NODE_H + GRAPH_GAP_Y)
|
|
expect(rowStrideFor(withRun)).toBe(GRAPH_NODE_H + GRAPH_GAP_Y)
|
|
// …and the run card itself is the card that needs the meta line.
|
|
expect(layoutTasksGraph(withRun).boxes.get('run:r')?.h).toBe(GRAPH_NODE_H)
|
|
})
|
|
|
|
it('gives every node a box even with a defensive orphan', () => {
|
|
const nodes: TasksNode[] = [agent('root'), agent('ghost', 'missing')]
|
|
const layout = layoutTasksGraph(nodes)
|
|
expect(layout.boxes.get('root')).toBeDefined()
|
|
expect(layout.boxes.get('ghost')).toBeDefined()
|
|
})
|
|
|
|
it('wraps a wide sibling band into rows of maxBandCols', () => {
|
|
const nodes: TasksNode[] = [agent('root')]
|
|
for (let index = 0; index < 5; index += 1) nodes.push(agent(`c${index}`, 'root'))
|
|
const layout = layoutTasksGraph(nodes, { maxBandCols: 2 })
|
|
// Three wrapped rows of 2/2/1, never five on one line.
|
|
expect([layoutRow(layout, 'c0', nodes), layoutRow(layout, 'c1', nodes)]).toEqual([1, 1])
|
|
expect([layoutRow(layout, 'c2', nodes), layoutRow(layout, 'c3', nodes)]).toEqual([2, 2])
|
|
expect(layoutRow(layout, 'c4', nodes)).toBe(3)
|
|
// The canvas stays as narrow as one wrapped band.
|
|
expect(layout.width).toBeLessThanOrEqual(2 * GRAPH_NODE_W + 28 + 2 * GRAPH_PAD)
|
|
})
|
|
|
|
it('never lets a wrapped band land on a sibling subtree row', () => {
|
|
// root → [a (with a child), b, c, d] wrapped at 2 columns: the second
|
|
// band must start BELOW a's child, not on the same row as it.
|
|
const nodes: TasksNode[] = [
|
|
agent('root'), agent('a', 'root'), agent('b', 'root'),
|
|
agent('c', 'root'), agent('d', 'root'), agent('a1', 'a'),
|
|
]
|
|
const layout = layoutTasksGraph(nodes, { maxBandCols: 2 })
|
|
expect(layoutRow(layout, 'c', nodes)).toBeGreaterThan(layoutRow(layout, 'a1', nodes))
|
|
expect(layoutRow(layout, 'd', nodes)).toBe(layoutRow(layout, 'c', nodes))
|
|
})
|
|
})
|
|
|
|
describe('bandColsFor / layoutTasksGraphForWidth', () => {
|
|
it('derives the column count from the container width', () => {
|
|
// The budget is measured at the READABILITY FLOOR, not at 1:1: the fit may
|
|
// scale the canvas down to 0.78 and stay readable, so a 360px panel keeps
|
|
// two 176px cards per row (scaled ~0.86) instead of collapsing into a
|
|
// one-card-per-row ladder. 720px fits four at the floor (the cap), and a
|
|
// panel too narrow for even two columns falls back to one.
|
|
expect(bandColsFor(360)).toBe(2)
|
|
expect(bandColsFor(720)).toBe(4)
|
|
expect(bandColsFor(120)).toBe(1)
|
|
})
|
|
|
|
it('prefers a flat band when the container is wide', () => {
|
|
const nodes: TasksNode[] = [agent('root')]
|
|
for (let index = 0; index < 4; index += 1) nodes.push(agent(`c${index}`, 'root'))
|
|
const wide = layoutTasksGraphForWidth(nodes, 720)
|
|
// Four 176px cards fit one band inside the floor budget at 720px, so the
|
|
// whole sibling set stays on one row.
|
|
expect(['c0', 'c1', 'c2', 'c3'].map(id => layoutRow(wide, id, nodes))).toEqual([1, 1, 1, 1])
|
|
expect(wide.width).toBeLessThanOrEqual(720 / 0.78)
|
|
})
|
|
|
|
it('wraps instead of overflowing wildly when the container is narrow', () => {
|
|
const nodes: TasksNode[] = [agent('root')]
|
|
for (let index = 0; index < 6; index += 1) nodes.push(agent(`c${index}`, 'root'))
|
|
// 360px (the narrowest native-sidebar panel) is where the anti-ladder
|
|
// rule matters most: two cards per band, scaled to fit.
|
|
const narrow = layoutTasksGraphForWidth(nodes, 360)
|
|
// Never wider than the tolerant budget (a small pan is allowed, a 3x
|
|
// overflow is not), and never a one-child-per-row ladder.
|
|
expect(narrow.width).toBeLessThanOrEqual(((360 - 24) / 0.78) * 1.2)
|
|
expect(layoutRow(narrow, 'c1', nodes)).toBe(layoutRow(narrow, 'c0', nodes))
|
|
})
|
|
})
|