dsh-leader-agent 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/e2e-scenarios/SKILL.md +3 -2
- package/.agents/skills/init-leader-agent/SKILL.md +2 -1
- package/.agents/skills/init-leader-agent/references/SLOTS.md +6 -1
- package/.agents/skills/leader-mode/SKILL.md +3 -2
- package/.agents/skills/leader-mode/playbooks/implementation.md +1 -1
- package/.agents/skills/leader-mode/playbooks/program.md +3 -2
- package/.agents/skills/leader-mode/playbooks/testing.md +46 -0
- package/README.md +21 -16
- package/README_ZH.md +21 -16
- package/lib/client.js +1943 -550
- package/locale/de.json +21 -1
- package/locale/en.json +21 -1
- package/locale/es.json +21 -1
- package/locale/fr.json +21 -1
- package/locale/ja.json +21 -1
- package/locale/pt.json +21 -1
- package/locale/ru.json +21 -1
- package/locale/zh.json +21 -1
- package/package.json +2 -1
- package/src/client/agent-bubble-styles.js +4 -7
- package/src/client/board-card.js +99 -28
- package/src/client/board-mode.js +74 -0
- package/src/client/board-rail-plan.js +159 -0
- package/src/client/board-rail.js +254 -0
- package/src/client/board-settings.js +433 -0
- package/src/client/board-styles.js +490 -20
- package/src/client/board.js +188 -13
- package/src/client/index.js +11 -1
- package/src/client/leader-changes.js +3 -7
- package/src/client/locales.generated.js +168 -8
- package/src/client/modal-shell.js +5 -9
- package/src/client/motion-preference.js +59 -0
- package/src/client/project-panel-logic.js +3 -2
- package/src/client/project-panel.js +37 -4
- package/src/client/project-remote.js +22 -3
- package/src/client/project-section.js +9 -8
- package/src/client/session-tabs.js +16 -12
- package/src/client/style-sheet.js +32 -0
- package/src/client/toast-view.js +3 -7
- package/src/client/worker-task-styles.js +4 -7
- package/src/client/workspace-exclusion.js +4 -7
- package/src/host/dispatch.js +367 -86
- package/src/host/index.js +70 -12
- package/src/host/leader-context.js +7 -4
- package/src/host/message.js +6 -2
- package/src/host/projects/remote.js +45 -3
- package/src/host/projects/service.js +19 -1
- package/src/host/projects/session-index.js +20 -0
- package/src/host/settings-store.js +231 -0
- package/src/host/slots/slot-templates.js +71 -16
- package/src/host/tools/gate.js +2 -1
- package/src/host/tools/list-worker-models.js +204 -0
- package/src/host/tools/read-worker.js +15 -3
- package/src/host/tools/spawn-worker.js +46 -3
- package/src/host/worker-model.js +274 -0
- package/src/host/worker-sessions.js +42 -11
- package/src/host/worker-transcript.js +49 -52
- package/src/shared/projects.js +8 -2
- package/src/shared/settings.js +81 -0
- package/src/shared/truncate.js +49 -0
- package/src/shared/turn-failure.js +25 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 看板显示模式:`work`(纯列表,默认)与 `cinema`(线路图)。
|
|
3
|
+
*
|
|
4
|
+
* 这是**显示偏好**,但自 2026-11-25 起和自动续行上限一样存在宿主侧
|
|
5
|
+
* `settings.json` 里,不再写浏览器 localStorage:同一个 dsh 实例下的所有窗口
|
|
6
|
+
* 与项目看到同一份选择,换浏览器或清缓存不会把模式打回默认。
|
|
7
|
+
*
|
|
8
|
+
* 客户端保留一份模块级内存快照:设置页保存成功后广播,看板不必重新异步取数;
|
|
9
|
+
* 其它窗口通过看板 `focus` 时重读宿主设置同步。取不到宿主配置时按默认模式走,
|
|
10
|
+
* 不阻塞渲染。
|
|
11
|
+
*
|
|
12
|
+
* @module dsh-leader-agent/client/board-mode
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
BOARD_MODE_CINEMA,
|
|
17
|
+
BOARD_MODE_DEFAULT,
|
|
18
|
+
BOARD_MODE_WORK,
|
|
19
|
+
BOARD_MODES,
|
|
20
|
+
normalizeBoardMode,
|
|
21
|
+
} from '../shared/settings.js'
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
BOARD_MODE_CINEMA,
|
|
25
|
+
BOARD_MODE_DEFAULT,
|
|
26
|
+
BOARD_MODE_WORK,
|
|
27
|
+
BOARD_MODES,
|
|
28
|
+
normalizeBoardMode,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 当前运行时看到的模式;先按默认值起步,挂载后由宿主设置回填。 */
|
|
32
|
+
let current = BOARD_MODE_DEFAULT
|
|
33
|
+
|
|
34
|
+
/** 同一运行时内的订阅者。设置页写、看板读,都在这张表上。 */
|
|
35
|
+
const listeners = new Set()
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 取当前运行时快照。
|
|
39
|
+
*
|
|
40
|
+
* @returns {string} `work` 或 `cinema`
|
|
41
|
+
*/
|
|
42
|
+
export function getBoardMode() {
|
|
43
|
+
return current
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 订阅模式变化。
|
|
48
|
+
*
|
|
49
|
+
* @param {(mode: string) => void} listener - 变化回调
|
|
50
|
+
* @returns {() => void} 取消订阅
|
|
51
|
+
*/
|
|
52
|
+
export function subscribeBoardMode(listener) {
|
|
53
|
+
listeners.add(listener)
|
|
54
|
+
return () => {
|
|
55
|
+
listeners.delete(listener)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 更新运行时快照并广播。
|
|
61
|
+
*
|
|
62
|
+
* 宿主保存成功后调用;同值不广播,避免设置页与看板的回填互相触发。
|
|
63
|
+
*
|
|
64
|
+
* @param {unknown} mode - 新模式
|
|
65
|
+
* @returns {string} 生效的合法模式
|
|
66
|
+
*/
|
|
67
|
+
export function setBoardMode(mode) {
|
|
68
|
+
const next = normalizeBoardMode(mode)
|
|
69
|
+
if (next === current) return next
|
|
70
|
+
current = next
|
|
71
|
+
// 先取快照:回调里退订会改动 Set,边迭代边删会漏掉后面的订阅者
|
|
72
|
+
for (const listener of Array.from(listeners)) listener(next)
|
|
73
|
+
return next
|
|
74
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 线路图的几何规划(纯函数)。
|
|
3
|
+
*
|
|
4
|
+
* 只做「量好之后的坐标 → 路径字符串」这一段,不碰 DOM:卡面位置由
|
|
5
|
+
* `board-rail.js` 量出来后传进来,这里负责把一张卡片拆成「主干上的 tick + 通往
|
|
6
|
+
* 每个执行者的支线」。拆出来是为了能直接断言形状——SVG 画错比逻辑错更难看出来。
|
|
7
|
+
*
|
|
8
|
+
* 坐标一律是相对看板内容区(`.dsh-leader-agent-board-stage`)的 CSS 像素。
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-leader-agent/client/board-rail-plan
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** 主线在跑:金色。 */
|
|
14
|
+
export const RAIL_LANE_HOT = 'hot'
|
|
15
|
+
|
|
16
|
+
/** 需要人介入:红色,不流动(只看呼吸提示,不加光流)。 */
|
|
17
|
+
export const RAIL_LANE_WARN = 'warn'
|
|
18
|
+
|
|
19
|
+
/** 静态绑定:灰色。 */
|
|
20
|
+
export const RAIL_LANE_MUTED = 'muted'
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 卡片信号 → 线的语义。
|
|
24
|
+
*
|
|
25
|
+
* 只有「执行中」和「需注意」值得用颜色区分;空闲、未读、未派工都只是静态绑定,
|
|
26
|
+
* 用同一种灰线——线太多颜色时,金色就不再表示「有数据在流动」。
|
|
27
|
+
*
|
|
28
|
+
* @param {string} status - 卡面信号(`cardSignal` 的结果)
|
|
29
|
+
* @returns {string} `hot` / `warn` / `muted`
|
|
30
|
+
*/
|
|
31
|
+
export function railLaneKind(status) {
|
|
32
|
+
if (status === 'running') return RAIL_LANE_HOT
|
|
33
|
+
if (status === 'attention') return RAIL_LANE_WARN
|
|
34
|
+
return RAIL_LANE_MUTED
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 卡片信号 → 主干节点的状态类。
|
|
39
|
+
*
|
|
40
|
+
* @param {string} status - 卡面信号
|
|
41
|
+
* @returns {string} `running` / `attention` / `idle`
|
|
42
|
+
*/
|
|
43
|
+
export function railNodeState(status) {
|
|
44
|
+
if (status === 'running') return 'running'
|
|
45
|
+
if (status === 'attention') return 'attention'
|
|
46
|
+
return 'idle'
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 坐标取一位小数:够准,且路径字符串稳定,不会被浮点尾巴搅得每次重建。
|
|
51
|
+
*
|
|
52
|
+
* @param {number} value - 原始坐标
|
|
53
|
+
* @returns {number} 取整后的坐标
|
|
54
|
+
*/
|
|
55
|
+
function px(value) {
|
|
56
|
+
return Math.round(value * 10) / 10
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 主干到卡片的一段:先沿主干下行,再横着拐进卡面左缘。
|
|
61
|
+
*
|
|
62
|
+
* @param {object} input - 几何
|
|
63
|
+
* @param {number} input.trunkX - 主干 x
|
|
64
|
+
* @param {number} input.fromY - 上一段终点 y(首段是 leader 节点)
|
|
65
|
+
* @param {number} input.cy - 这张卡的中心 y
|
|
66
|
+
* @param {number} input.cardX - 卡面左缘 x
|
|
67
|
+
* @returns {string} SVG path
|
|
68
|
+
*/
|
|
69
|
+
export function railTickPath({ trunkX, fromY, cy, cardX }) {
|
|
70
|
+
return `M${px(trunkX)},${px(fromY)} L${px(trunkX)},${px(cy)} L${px(cardX)},${px(cy)}`
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 卡面右缘到执行者圆点的一段曲线。
|
|
75
|
+
*
|
|
76
|
+
* 控制点分别从两端出发,形成一条两端水平的 S 弯;间距小于 20px 时也保留一点
|
|
77
|
+
* 弯度,否则短支线会退化成直线,和 tick 分不开。
|
|
78
|
+
*
|
|
79
|
+
* @param {object} input - 几何
|
|
80
|
+
* @param {number} input.cardRight - 卡面右缘 x
|
|
81
|
+
* @param {number} input.cy - 卡面中心 y
|
|
82
|
+
* @param {number} input.slotX - 执行者圆点中心 x
|
|
83
|
+
* @param {number} input.slotY - 执行者圆点中心 y
|
|
84
|
+
* @returns {string} SVG path
|
|
85
|
+
*/
|
|
86
|
+
export function railBranchPath({ cardRight, cy, slotX, slotY }) {
|
|
87
|
+
const bend = Math.max(10, (slotX - cardRight) / 2)
|
|
88
|
+
return `M${px(cardRight)},${px(cy)} C${px(cardRight + bend)},${px(cy)} ${px(slotX - bend)},${px(slotY)} ${px(slotX)},${px(slotY)}`
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 正交走线:先向右出线,再竖直,再向右进圆点;拐角用 5px 圆角。
|
|
93
|
+
*
|
|
94
|
+
* 直角比 S 弯更像电路图,也让「出线点 → 竖槽」的距离一眼可读。竖槽很窄时
|
|
95
|
+
* 退化成一条直线,避免拐点跑到圆点右边去。
|
|
96
|
+
*
|
|
97
|
+
* @param {object} input - 几何
|
|
98
|
+
* @param {number} input.cardRight - 卡面右缘 x
|
|
99
|
+
* @param {number} input.cy - 卡面中心 y
|
|
100
|
+
* @param {number} input.slotX - 执行者圆点左缘 x
|
|
101
|
+
* @param {number} input.slotY - 执行者圆点中心 y
|
|
102
|
+
* @returns {string} SVG path
|
|
103
|
+
*/
|
|
104
|
+
export function railOrthoBranchPath({ cardRight, cy, slotX, slotY }) {
|
|
105
|
+
const elbow = Math.min(cardRight + 16, slotX - 6)
|
|
106
|
+
const radius = 5
|
|
107
|
+
const dy = slotY - cy
|
|
108
|
+
if (Math.abs(dy) < radius * 2 || elbow <= cardRight) {
|
|
109
|
+
return `M${px(cardRight)},${px(cy)} L${px(slotX)},${px(slotY)}`
|
|
110
|
+
}
|
|
111
|
+
const dir = dy > 0 ? 1 : -1
|
|
112
|
+
return [
|
|
113
|
+
`M${px(cardRight)},${px(cy)}`,
|
|
114
|
+
`L${px(elbow - radius)},${px(cy)}`,
|
|
115
|
+
`Q${px(elbow)},${px(cy)} ${px(elbow)},${px(cy + dir * radius)}`,
|
|
116
|
+
`L${px(elbow)},${px(slotY - dir * radius)}`,
|
|
117
|
+
`Q${px(elbow)},${px(slotY)} ${px(elbow + radius)},${px(slotY)}`,
|
|
118
|
+
`L${px(slotX)},${px(slotY)}`,
|
|
119
|
+
].join(' ')
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 把量好的行几何拆成线。
|
|
124
|
+
*
|
|
125
|
+
* 每行产出一条 tick 与若干支线;支线数量等于该行实际渲染的执行者圆点数。没有
|
|
126
|
+
* 绑定会话的卡不产支线——空线不画,画面上没有支线本身就是「这张卡还没派人」。
|
|
127
|
+
*
|
|
128
|
+
* @param {object} input - 几何
|
|
129
|
+
* @param {number} input.trunkX - 主干 x
|
|
130
|
+
* @param {number} input.leaderY - leader 节点中心 y
|
|
131
|
+
* @param {Array<{ status: string, cardX: number, cardRight: number, cy: number, slots?: Array<{ x: number, y: number, status?: string }> }>} input.rows
|
|
132
|
+
* 自上而下的行几何;槽位自带的 `status` 优先于卡片级状态
|
|
133
|
+
* @param {boolean} [input.orthogonal] - 支线走直角(浅色皮的电路感)
|
|
134
|
+
* @returns {Array<{ id: string, kind: string, d: string }>} 线路列表
|
|
135
|
+
*/
|
|
136
|
+
export function planRailLanes({ trunkX, leaderY, rows, orthogonal }) {
|
|
137
|
+
const lanes = []
|
|
138
|
+
let fromY = leaderY
|
|
139
|
+
rows.forEach((row, index) => {
|
|
140
|
+
lanes.push({
|
|
141
|
+
id: `tick:${index}`,
|
|
142
|
+
kind: railLaneKind(row.status),
|
|
143
|
+
d: railTickPath({ trunkX, fromY, cy: row.cy, cardX: row.cardX }),
|
|
144
|
+
})
|
|
145
|
+
const slots = Array.isArray(row.slots) ? row.slots : []
|
|
146
|
+
slots.forEach((slot, slotIndex) => {
|
|
147
|
+
// 支线按执行者自己的状态上色:同一张卡上,只有正在跑的那个 worker 才有传输
|
|
148
|
+
lanes.push({
|
|
149
|
+
id: `branch:${index}:${slotIndex}`,
|
|
150
|
+
kind: railLaneKind(slot.status ?? row.status),
|
|
151
|
+
d: orthogonal
|
|
152
|
+
? railOrthoBranchPath({ cardRight: row.cardRight, cy: row.cy, slotX: slot.x, slotY: slot.y })
|
|
153
|
+
: railBranchPath({ cardRight: row.cardRight, cy: row.cy, slotX: slot.x, slotY: slot.y }),
|
|
154
|
+
})
|
|
155
|
+
})
|
|
156
|
+
fromY = row.cy
|
|
157
|
+
})
|
|
158
|
+
return lanes
|
|
159
|
+
}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 线路图覆盖层:在卡片列表下面垫一层 SVG,画出主干、节点与支线。
|
|
3
|
+
*
|
|
4
|
+
* 它不改列表的 DOM 语义——卡片、链接、会话入口都还是原来的元素,这一层只负责
|
|
5
|
+
* 「看得见连线」。所有几何都在渲染后实测:卡面高度随标题换行变,语言一换就变,
|
|
6
|
+
* 写死坐标的图在别的语言下必然错位。
|
|
7
|
+
*
|
|
8
|
+
* 动画只给「执行中」的线:金色光点沿路径跑,来源是槽位会话快照的 running 跳变,
|
|
9
|
+
* 不是随机装饰。`prefers-reduced-motion` 下只留静态线,不跑光点。
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-leader-agent/client/board-rail
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { createElement, useEffect, useLayoutEffect, useRef, useState } from 'react'
|
|
15
|
+
import { planRailLanes, railNodeState, RAIL_LANE_HOT, RAIL_LANE_WARN } from './board-rail-plan.js'
|
|
16
|
+
import { prefersReducedMotion, watchReducedMotion } from './motion-preference.js'
|
|
17
|
+
|
|
18
|
+
const SVG_NS = 'http://www.w3.org/2000/svg'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 同时跑光点的上限。
|
|
22
|
+
*
|
|
23
|
+
* 二十张卡一起亮不是「工作流」,是圣诞树;超过这个数只保留静态金色,不再跑头。
|
|
24
|
+
*/
|
|
25
|
+
const MAX_ANIMATED_LANES = 6
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 造一个 SVG 元素。
|
|
29
|
+
*
|
|
30
|
+
* @param {string} tag - 标签名
|
|
31
|
+
* @param {Record<string, unknown>} [attrs] - 属性
|
|
32
|
+
* @returns {object} SVG 元素
|
|
33
|
+
*/
|
|
34
|
+
function svgNode(tag, attrs = {}) {
|
|
35
|
+
const node = document.createElementNS(SVG_NS, tag)
|
|
36
|
+
for (const [key, value] of Object.entries(attrs)) node.setAttribute(key, String(value))
|
|
37
|
+
return node
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 造一条路径。
|
|
42
|
+
*
|
|
43
|
+
* @param {string} d - path 数据
|
|
44
|
+
* @param {string} className - 类名
|
|
45
|
+
* @returns {object} SVG path
|
|
46
|
+
*/
|
|
47
|
+
function pathNode(d, className) {
|
|
48
|
+
return svgNode('path', { d, class: className })
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 跟随系统的「减少动态效果」偏好。
|
|
53
|
+
*
|
|
54
|
+
* SMIL 光点不受 CSS 媒体查询管:偏好如果在看板打开后才切到 reduce,已经挂上的
|
|
55
|
+
* comet 会继续跑。订阅变化后重画,绘制层才能把光点摘掉。
|
|
56
|
+
*
|
|
57
|
+
* @returns {boolean} 当前是否要求减少动态效果
|
|
58
|
+
*/
|
|
59
|
+
function usePrefersReducedMotion() {
|
|
60
|
+
const [reduced, setReduced] = useState(prefersReducedMotion)
|
|
61
|
+
useEffect(() => watchReducedMotion(globalThis, setReduced), [])
|
|
62
|
+
return reduced
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 让一段金色高亮沿路径流动。
|
|
67
|
+
*
|
|
68
|
+
* dash 长度按路径实测长度给:短支线整条亮,长主干留一段跑动的光。用 CSS 变量把
|
|
69
|
+
* 起止偏移带到 keyframes 里,避免为每条线写一份样式。
|
|
70
|
+
*
|
|
71
|
+
* @param {object} path - SVG path
|
|
72
|
+
* @param {number} phase - 相位,错开同时起跑的光点
|
|
73
|
+
* @returns {void}
|
|
74
|
+
*/
|
|
75
|
+
function primeFlow(path, phase) {
|
|
76
|
+
let length = 200
|
|
77
|
+
try {
|
|
78
|
+
length = path.getTotalLength()
|
|
79
|
+
} catch {
|
|
80
|
+
// 路径退化(零长度)时按默认长度算,最多是一段不动的线
|
|
81
|
+
}
|
|
82
|
+
const dash = Math.min(120, Math.max(44, length * 0.55))
|
|
83
|
+
path.style.strokeDasharray = `${dash} ${length + dash * 2}`
|
|
84
|
+
path.style.setProperty('--dla-from', `${dash}px`)
|
|
85
|
+
path.style.setProperty('--dla-to', `${-(length + dash * 2)}px`)
|
|
86
|
+
path.style.animationDelay = `${-(phase % 7) * 0.31}s`
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 量一个元素相对内容区的矩形。
|
|
91
|
+
*
|
|
92
|
+
* @param {object} element - DOM 元素
|
|
93
|
+
* @param {DOMRect} base - 内容区矩形
|
|
94
|
+
* @returns {{x: number, y: number, cx: number, cy: number, right: number}} 相对坐标
|
|
95
|
+
*/
|
|
96
|
+
function measure(element, base) {
|
|
97
|
+
const rect = element.getBoundingClientRect()
|
|
98
|
+
return {
|
|
99
|
+
x: rect.left - base.left,
|
|
100
|
+
y: rect.top - base.top,
|
|
101
|
+
cx: rect.left - base.left + rect.width / 2,
|
|
102
|
+
cy: rect.top - base.top + rect.height / 2,
|
|
103
|
+
right: rect.right - base.left,
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 重画整张线路图。
|
|
109
|
+
*
|
|
110
|
+
* @param {object} svg - 覆盖层
|
|
111
|
+
* @param {{ orthogonal?: boolean, theme?: string, reduced?: boolean }} options - 走线方式、主题与动效偏好
|
|
112
|
+
* @returns {void}
|
|
113
|
+
*/
|
|
114
|
+
function drawRail(svg, options = {}) {
|
|
115
|
+
const stage = svg.parentElement
|
|
116
|
+
if (stage === null) return
|
|
117
|
+
svg.replaceChildren()
|
|
118
|
+
|
|
119
|
+
const rowElements = [...stage.querySelectorAll('[data-rail-row]')]
|
|
120
|
+
if (rowElements.length === 0) return
|
|
121
|
+
|
|
122
|
+
const base = stage.getBoundingClientRect()
|
|
123
|
+
const dot = stage.querySelector('[data-rail-leader-dot]')
|
|
124
|
+
const leader = dot === null ? { cx: 20, cy: 0 } : measure(dot, base)
|
|
125
|
+
|
|
126
|
+
const rows = []
|
|
127
|
+
for (const row of rowElements) {
|
|
128
|
+
const cardElement = row.querySelector('.dsh-leader-agent-board-card')
|
|
129
|
+
if (cardElement === null) continue
|
|
130
|
+
const card = measure(cardElement, base)
|
|
131
|
+
const slots = [...row.querySelectorAll('[data-rail-slot]')]
|
|
132
|
+
.map((slot) => {
|
|
133
|
+
const rect = measure(slot, base)
|
|
134
|
+
// 支线停在圆点左缘外 2px:画到圆心上会从首字上穿过去
|
|
135
|
+
return { x: rect.cx - 12, y: rect.cy, status: slot.dataset.railState }
|
|
136
|
+
})
|
|
137
|
+
rows.push({
|
|
138
|
+
status: row.dataset.railStatus ?? 'none',
|
|
139
|
+
cardX: card.x,
|
|
140
|
+
cardRight: card.right,
|
|
141
|
+
cy: card.cy,
|
|
142
|
+
slots,
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
if (rows.length === 0) return
|
|
146
|
+
|
|
147
|
+
const trunkX = leader.cx
|
|
148
|
+
const lastY = rows[rows.length - 1].cy
|
|
149
|
+
svg.appendChild(pathNode(`M${trunkX},${leader.cy} L${trunkX},${lastY}`, 'dsh-leader-agent-board-rail-trunk'))
|
|
150
|
+
|
|
151
|
+
rows.forEach((row) => {
|
|
152
|
+
const nodeClass = `dsh-leader-agent-board-rail-node dsh-leader-agent-board-rail-node-${railNodeState(row.status)}`
|
|
153
|
+
svg.appendChild(options.orthogonal === true
|
|
154
|
+
? svgNode('rect', { x: trunkX - 3.2, y: row.cy - 3.2, width: 6.4, height: 6.4, rx: 1.2, class: nodeClass })
|
|
155
|
+
: svgNode('circle', { cx: trunkX, cy: row.cy, r: 3.4, class: nodeClass }))
|
|
156
|
+
// 浅色皮的节点是方块,再加扩散圆环会变成「光晕」,那正是浅色最忌讳的材质
|
|
157
|
+
if (row.status === 'running' && options.theme !== 'light') {
|
|
158
|
+
svg.appendChild(svgNode('circle', {
|
|
159
|
+
cx: trunkX,
|
|
160
|
+
cy: row.cy,
|
|
161
|
+
r: 9,
|
|
162
|
+
class: 'dsh-leader-agent-board-rail-halo',
|
|
163
|
+
}))
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
const reduced = options.reduced === true
|
|
168
|
+
let animated = 0
|
|
169
|
+
planRailLanes({ trunkX, leaderY: leader.cy, rows, orthogonal: options.orthogonal }).forEach((lane, index) => {
|
|
170
|
+
if (lane.kind === RAIL_LANE_HOT) {
|
|
171
|
+
svg.appendChild(pathNode(lane.d, 'dsh-leader-agent-board-rail-hot'))
|
|
172
|
+
if (reduced || animated >= MAX_ANIMATED_LANES) return
|
|
173
|
+
animated += 1
|
|
174
|
+
const trail = pathNode(lane.d, 'dsh-leader-agent-board-rail-trail')
|
|
175
|
+
svg.appendChild(trail)
|
|
176
|
+
primeFlow(trail, index)
|
|
177
|
+
const comet = svgNode('circle', { r: 3, class: 'dsh-leader-agent-board-rail-comet' })
|
|
178
|
+
comet.appendChild(svgNode('animateMotion', {
|
|
179
|
+
dur: '2400ms',
|
|
180
|
+
begin: `${(index % 7) * 0.28}s`,
|
|
181
|
+
repeatCount: 'indefinite',
|
|
182
|
+
path: lane.d,
|
|
183
|
+
}))
|
|
184
|
+
svg.appendChild(comet)
|
|
185
|
+
return
|
|
186
|
+
}
|
|
187
|
+
if (lane.kind === RAIL_LANE_WARN) {
|
|
188
|
+
svg.appendChild(pathNode(lane.d, 'dsh-leader-agent-board-rail-warn'))
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
svg.appendChild(pathNode(lane.d, 'dsh-leader-agent-board-rail-edge'))
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 线路图覆盖层。
|
|
197
|
+
*
|
|
198
|
+
* `railKey` 是行身份与状态的签名:卡片轮询每 2 秒会换一个新数组,但签名不变时
|
|
199
|
+
* 不必重画——重画会让光点从头再跑一遍。stage 宽高另并入绘制签名。
|
|
200
|
+
*
|
|
201
|
+
* @param {object} props - 组件属性
|
|
202
|
+
* @param {string} props.railKey - 行与状态的签名
|
|
203
|
+
* @returns {object} React 元素
|
|
204
|
+
*/
|
|
205
|
+
export function BoardRail({ railKey, orthogonal, theme }) {
|
|
206
|
+
const ref = useRef(null)
|
|
207
|
+
const reduced = usePrefersReducedMotion()
|
|
208
|
+
// 最近一次真正画上去的完整签名(内容 + 几何)。隐藏/显示只改可见性,不改
|
|
209
|
+
// 内容与几何;用它把「右栏重新可见」的 0 → N 尺寸变化挡在重画之外——重画会
|
|
210
|
+
// 重建 SVG,SMIL 光点跟着从头起跑。
|
|
211
|
+
const drawnKey = useRef('')
|
|
212
|
+
|
|
213
|
+
useLayoutEffect(() => {
|
|
214
|
+
const svg = ref.current
|
|
215
|
+
if (svg === null) return undefined
|
|
216
|
+
const stage = svg.parentElement
|
|
217
|
+
if (stage === null) return undefined
|
|
218
|
+
let timer = 0
|
|
219
|
+
const draw = () => {
|
|
220
|
+
// 宿主用 display:none 隐藏非当前会话的右栏:尺寸归零不是布局变化
|
|
221
|
+
if (stage.clientWidth === 0 || stage.clientHeight === 0) return
|
|
222
|
+
// 卡面标题固定单行后,行中心只随行高变化;宽度决定换行,高度覆盖 locale/
|
|
223
|
+
// 字体与链接行导致的整卡高度变化,两者合起来就够,不必逐行量几何。
|
|
224
|
+
const key = `${railKey}|${orthogonal}|${theme}|${reduced}|${stage.clientWidth}x${stage.clientHeight}`
|
|
225
|
+
if (key === drawnKey.current) return
|
|
226
|
+
drawnKey.current = key
|
|
227
|
+
drawRail(svg, { orthogonal, theme, reduced })
|
|
228
|
+
}
|
|
229
|
+
draw()
|
|
230
|
+
if (typeof ResizeObserver === 'undefined') return undefined
|
|
231
|
+
const observer = new ResizeObserver(() => {
|
|
232
|
+
// 尾防抖:连续拖拽期间每次回调都重置计时,整个拖拽过程中线路图停在旧宽度上
|
|
233
|
+
// (错位),停手 80ms 后只画最后一次。换来的是不逐帧重建 SMIL 节点。
|
|
234
|
+
clearTimeout(timer)
|
|
235
|
+
timer = setTimeout(() => {
|
|
236
|
+
draw()
|
|
237
|
+
// 防抖真正跑完的信号:e2e 等它递增后再断言,不用睡固定时间——重画即使
|
|
238
|
+
// 发生也已经在 draw() 里做完了。
|
|
239
|
+
svg.dataset.railSettled = String(Number(svg.dataset.railSettled ?? '0') + 1)
|
|
240
|
+
}, 80)
|
|
241
|
+
})
|
|
242
|
+
observer.observe(stage)
|
|
243
|
+
return () => {
|
|
244
|
+
clearTimeout(timer)
|
|
245
|
+
observer.disconnect()
|
|
246
|
+
}
|
|
247
|
+
}, [railKey, orthogonal, theme, reduced])
|
|
248
|
+
|
|
249
|
+
return createElement('svg', {
|
|
250
|
+
ref,
|
|
251
|
+
className: 'dsh-leader-agent-board-rail',
|
|
252
|
+
'aria-hidden': 'true',
|
|
253
|
+
})
|
|
254
|
+
}
|