dsh-mcp-status 0.2.0 → 0.3.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/README.md CHANGED
@@ -12,18 +12,20 @@ An MCP server panel for the DeepSeek Harness Web GUI: it lists every `@deepseek-
12
12
  | 连上了没有? | 三份证据:loader fiber 的 state(已停用 / 加载失败 / 启动中 / 运行中)、工具注册表里 `mcp__<server>__*` 的条数、以及 streamable-http 行每次刷新时的 TCP 端口探活。连不上时 `mcp-client` 不抛错(`failOnStartupError` 默认 false),fiber 照样 active——而**工具条数只证明「曾经连上过」**:服务器后来死掉时工具不会注销,所以端口探活和最近一次「测试连接」的结论会推翻那个绿点 |
13
13
  | 为什么没连上? | 「测试连接」用宿主同一份配置真做一次 JSON-RPC 握手(stdio 起进程 / http 打请求),把 `ECONNREFUSED`、`HTTP 401`、超时原文贴回行内 |
14
14
 
15
- ## 两个座位
15
+ ## 三个座位
16
16
 
17
- - **侧边栏行**:`sidebar.panellist`,id `mcp`,order 40;
17
+ - **侧边栏行**:`sidebar.panellist`,id `mcp`,order 40;图标右上角挂一个状态点(见下节);
18
+ - **侧栏收起态**:`sidebar.toggle.badge`,只在有服务器要处理时出现;
18
19
  - **中央面板**:`main` keyed 槽,key 也是 `mcp`。
19
20
 
20
- 宿主维护一份状态缓存:后台每 `refreshMs`(默认 10 s)刷新,喂给 system prompt 与调用闸门;面板拉取时**当场重采**(探活有 2 s 缓存,其余全是内存读取),所以面板的新鲜度与以前一样。数据来自四条同源路由:
21
+ 宿主维护一份状态缓存:后台每 `refreshMs`(默认 10 s)刷新,喂给 system prompt 与调用闸门;面板拉取时**当场重采**(探活有 2 s 缓存,其余全是内存读取),所以面板的新鲜度与以前一样。数据来自五条同源路由:
21
22
 
22
23
  | 路由 | 作用 |
23
24
  | --- | --- |
24
25
  | `GET /api/dsh-mcp-status/servers` | 快照:每行的状态、工具数、传输与地址、来源补丁文件、超时与重连策略 |
26
+ | `GET /api/dsh-mcp-status/summary` | 侧栏角标用的聚合摘要(`worst` / `counts` / `names` / `signature`);**读缓存、不强制重采、不探活** |
25
27
  | `POST /api/dsh-mcp-status/toggle` | `{ id, enabled }`:改补丁行 → 等热重载 → 返回新状态(超时后主动重排一次) |
26
- | `POST /api/dsh-mcp-status/retry` | `{ id }`:重新挂载这一行(= 重新连接) |
28
+ | `POST /api/dsh-mcp-status/retry` | `{ id }`:真正重新挂载这一行(`dispose` 旧 fiber + `init` 冷启动,重连预算清零),不是等 HMR 碰运气 |
27
29
  | `POST /api/dsh-mcp-status/test` | `{ id }`:真握手,返回协议版本 / serverInfo / 工具数 / 失败原因 |
28
30
 
29
31
  写操作要求同源证明,且所有路由都只接受回环来源。
@@ -40,21 +42,28 @@ An MCP server panel for the DeepSeek Harness Web GUI: it lists every `@deepseek-
40
42
 
41
43
  ## 状态判定表(每条结论都带依据)
42
44
 
43
- 状态由 `lib/status.js` 的 `resolveStatus()` 纯函数推导,优先级从上到下:
45
+ 状态由 `lib/status.js` 的 `resolveStatus()` 纯函数推导。**第一优先是宿主自己的连接状态**
46
+ (`@deepseek-ai/dsh-mcp-client` 导出的 `connectionStatusOf(fiber)`,从 loader 条目的
47
+ `moduleNamespace` 取),探活和工具数只在宿主说「已连接」时做旁证:
44
48
 
45
49
  | 顺序 | 条件 | 状态 | reason |
46
50
  | --- | --- | --- | --- |
47
51
  | 1 | 行被停用 | 已停用 | `disabled`(用户选择,不是故障) |
48
52
  | 2 | loader fiber 失败 | 加载失败 | `fiber-failed` |
49
- | 3 | fiber 未就绪 | 启动中 | `pending` |
50
- | 4 | 最近一次测试失败,且端口不通或结论在 `probeAssertMs` 内 | 不可达 | `probe-failed` |
51
- | 5 | streamable-http 端口拒绝连接 / 超时 | 不可达 | `tcp-refused` |
52
- | 6 | 最近一次测试成功 | 已连接 | `connected` |
53
- | 7 | 工具表读不到 | 已连接 | `unknown-tools`(不下结论) |
54
- | 8 | 有工具 / 没有工具 | 已连接 / 未连接 | `connected` / `no-tools` |
53
+ | 3 | 宿主客户端正在首次连接 | 启动中 | `client-connecting` |
54
+ | 4 | 宿主客户端正在重连(第 n/N 次) | 重连中 | `client-reconnecting`(依据里带 n/N) |
55
+ | 5 | 宿主客户端已放弃(连续 10 次失败后工具被注销) | 未连接 | `gave-up` |
56
+ | 6 | 等凭证 / 连接已关闭 / 其它客户端失败 | 未连接 | `waiting-credentials` / `client-closed` / `client-failed` |
57
+ | 7 | 宿主说已连接,但端口拒绝连接,或窗口内刚测失败 | 不可达 | `tcp-refused` / `probe-failed` |
58
+ | 8 | 宿主说已连接,但工具数为 0 | 未连接 | `no-tools` |
59
+ | 9 | 宿主说已连接,且有工具 | 已连接 | `connected` |
60
+ | 10 | 读不到宿主状态(老版本 / 非 mcp-client 行) | 退回观测推导 | `unknown-tools` / `pending` … |
61
+
62
+ 第 4、5 条是 0.2.1 的关键修正:以前「重连中」和「已放弃」都被当成绿色——测试连接一成功还会把
63
+ 「已连接 + 0 工具」显示成已连接。现在客户端状态优先,成功握手不会压过它。
55
64
 
56
65
  第 8 条的 `no-tools`(界面显示「未连接」)刻意与 `unreachable` 分开:工具数为 0 可能只是这行挂在
57
- per-agent 作用域、全局注册表看不见,把它当断线会误报也会误拦。
66
+ per-agent 作用域、全局注册表看不见,把它当断线会误报也会误拦——但它也不再被算作「已连接」。
58
67
 
59
68
  每行 DTO 带 `reason` 与 `evidence`(fiber / tools / tcp / probe 四个信号,带各自时间戳),
60
69
  展开区把依据压成一行——「凭什么绿/红」不再靠猜。
@@ -67,8 +76,8 @@ per-agent 作用域、全局注册表看不见,把它当断线会误报也会
67
76
  `- unityMCP (http://127.0.0.1:8080/mcp): unreachable — connect ECONNREFUSED, checked 8s ago.`
68
77
  全部恢复后 section 会被注销——健康时 prompt 里不多一个空行。
69
78
  - **调用闸门**(`ctx.tools.guard`):`mcp__<server>__*` 的调用在派发前被判为不可用就拒绝,返回可读原因
70
- (含「去 MCP 面板重试」)。只有**证据够新**才会拦:快照超过 `2 × refreshMs` 视为过期,`pending`、
71
- `no-tools`、`disabled` 一律放行——`idle` 不等于断线。
79
+ (含「去 MCP 面板重试」)。拦 `unreachable` / `failed` / `reconnecting`,且只有**证据够新**才会拦:
80
+ 快照超过 `2 × refreshMs` 视为过期,`pending`、`no-tools`、`disabled` 一律放行——`idle` 不等于断线。
72
81
 
73
82
  两个消费方都能关:`promptHealth: false` / `guardUnreachable: false`(见下)。
74
83
 
@@ -86,12 +95,29 @@ per-agent 作用域、全局注册表看不见,把它当断线会误报也会
86
95
  guardUnreachable: true # 是否拦截发往不可用服务器的工具调用
87
96
  ```
88
97
 
98
+ ## 侧栏状态点
99
+
100
+ 面板是商品,侧栏那一行是产品:要先在门口看见,才有人点进门。
101
+
102
+ - **形状**:图标不变,右上角加一个 6 px 的点。红=有服务器不可用(`unreachable` / `failed`),黄=正在重连(`reconnecting`);
103
+ **全好时没有点**——没有消息就是好消息,比一个常年发绿的点更可信。悬停给出明细(`已连接 2/5 · 1 台要处理:unityMCP`)。
104
+ - **变化才闪**:状态变差时点脉冲一次(0.9 s);`prefers-reduced-motion` 下不播动画。恢复健康不庆祝。
105
+ - **收起态**:侧栏折叠时,顶部的展开按钮上出现同色小点(`sidebar.toggle.badge`);全好时该槽不渲染任何东西。
106
+ - **在哪个视图都在**:点的样式挂在宿主 `<head>`,不跟面板走。面板切到会话或别的插件时会被卸载,
107
+ 侧栏那一行却还在——样式若跟着面板走,那时点就只剩一个没有尺寸的空 span,等于消失。
108
+ - **5 s 一次**`GET /summary`:只读宿主缓存,不探活、不强制重采;页面不可见时暂停轮询,切回前台立即拉一次。
109
+ 面板的 `/servers` 仍然每次当场重采——角标不该为一个 6 px 的点打风暴。
110
+ - **红线**:判定仍然只来自 `resolveStatus`,`summarizeServers` 只做聚合。`idle`(没有工具)与 `disabled`
111
+ 不会让点变红,和调用闸门的放行规则一致(A3)。
112
+
89
113
  ## 显示约定
90
114
 
91
115
  - 样式只用 `--dsw-alias-*` 主题令牌,跟随宿主明暗主题;文案走 `ctx.locale`(zh / en)。
92
- - 状态色:绿=已连接;红=未连接/不可达/加载失败;黄(呼吸)=启动中;灰=已停用。
116
+ - 状态色:绿=已连接;红=未连接/不可达/加载失败;黄(呼吸)=启动中/重连中;灰=已停用。侧栏点只用红/黄两档,见上节。
117
+ - 顶栏副标题显示的是「状态变化 Ns 前」:面板每 4 s 轮询,但快照里的 `checkedAt` 每次拉取都会刷新,
118
+ 所以它不表示新鲜度,只在某一行状态真的变了时计时。
93
119
  - 「不可达」= 端口连不上,或最近一次测试失败:徽标立即变红,展开区给出原因;若工具还挂在注册表里,会单独说明那是上一次连接的残留。
94
- - 行的展开区给出传输、命令/地址、env/header **名字**(不显示值)、重连策略、调用超时、来源补丁
120
+ - 行的展开区给出传输、命令/地址、env/header **名字**(不显示值)、连接状态、重连策略、调用超时、来源补丁
95
121
  文件、条目 id、判定与依据,以及失败原因。
96
122
 
97
123
  ## 兼容与依赖
@@ -125,11 +151,13 @@ node lib/probe.test.mjs # 5 个用例:stdio/http 成功、命令不存在、
125
151
 
126
152
  - 停用/启用会改写**当前 profile 的补丁文件**里那一行的 `disabled`;如果该行由其它工具生成(例如同步 MCP 配置的第三方工具),那个工具下次整表重写时可能覆盖本次开关的结果。
127
153
  - 面板只读配置、不做新增/编辑;新增与编辑仍在「设置 → 插件 → MCP 服务器配置」。
128
- - **stdio 行没有端口可探**:它们的存活只能靠工具数 + 用户点过「测试连接」的结论;`no-tools` 不会被当成断线。
129
- - **闸门可能误拦**:只有「快照新鲜 + 端口确实拒绝连接 / 刚测过失败」才拒绝,窗口过期一律放行;不放心就
154
+ - **stdio 行没有端口可探**:它们的存活只能靠宿主连接状态 + 工具数;`no-tools` 不算断线,也不会被当成已连接。
155
+ - **闸门可能误拦**:只有「快照新鲜 + 确实不可达 / 正在重连」才拒绝,窗口过期一律放行;不放心就
130
156
  `guardUnreachable: false`,退回纯看板行为。
131
- - **状态是推导的,不是客户端自报的**:DSH 的 `dsh-mcp-client` 目前不暴露连接状态,所以这里只能组合
132
- fiber / 工具注册表 / TCP / 测试结论四份证据。真要让状态像 opencode 那样由客户端层拥有,需要上游提供接口。
157
+ - **重试会短暂摘掉这一行的工具**:`dispose` + `init` 是冷启动,重连成功前 `mcp__<server>__*` 不在工具表里,
158
+ 这是宿主 mcp-client 自己给出的唯一自救路径(它放弃重连时的提示就是「reload the plugin or restart the Host」)。
159
+ - **宿主不暴露连接状态时退回推导**:0.2.1 起优先读 `connectionStatusOf(fiber)`;拿不到(老版本宿主、非
160
+ mcp-client 行)就退回 fiber / 工具注册表 / TCP / 测试结论四份证据,此时「重连中」无法区分。
133
161
 
134
162
  ## License
135
163
 
package/client.js CHANGED
@@ -21,6 +21,8 @@ window.__ModuleLoader__.load({
21
21
  const PANEL_ORDER = 40;
22
22
  const API = '/api/dsh-mcp-status';
23
23
  const POLL_MS = 4000;
24
+ /** 侧栏角标的轮询周期:比面板慢一档,读的是 /summary(不探活、不强制重采)。 */
25
+ const DOCK_POLL_MS = 5000;
24
26
 
25
27
  /* ------------------------------------------------------------------ *
26
28
  * 文案
@@ -33,6 +35,7 @@ window.__ModuleLoader__.load({
33
35
  'panel.emptyHint': '在 设置 → 插件 → MCP 服务器配置 里添加,或把 mcp-client 行写进 profile 补丁。',
34
36
  'state.connected': '已连接',
35
37
  'state.connecting': '连接中',
38
+ 'state.reconnecting': '重连中',
36
39
  'state.idle': '未连接',
37
40
  'state.unreachable': '未连接(不可达)',
38
41
  'state.failed': '加载失败',
@@ -51,6 +54,7 @@ window.__ModuleLoader__.load({
51
54
  'action.showConfig': '配置',
52
55
  'action.hideConfig': '收起',
53
56
  'field.transport': '传输',
57
+ 'field.client': '连接状态',
54
58
  'field.command': '命令',
55
59
  'field.url': '地址',
56
60
  'field.env': '环境变量',
@@ -59,15 +63,27 @@ window.__ModuleLoader__.load({
59
63
  'field.entry': '条目',
60
64
  'field.reason': '判定',
61
65
  'field.evidence': '依据',
62
- 'panel.updated': '已更新 {n}s 前',
66
+ 'panel.changed': '状态变化 {n}s 前',
63
67
  'reason.disabled': '已停用(用户选择,不是故障)',
64
68
  'reason.fiber-failed': 'MCP 客户端加载失败',
65
69
  'reason.pending': '客户端正在启动',
70
+ 'reason.client-connecting': '客户端正在建立连接',
71
+ 'reason.client-reconnecting': '客户端正在自动重连',
72
+ 'reason.gave-up': '自动重连已放弃(连续失败达到上限,工具已卸载)',
73
+ 'reason.client-failed': '客户端连接失败',
74
+ 'reason.client-closed': '客户端已关闭',
75
+ 'reason.waiting-credentials': '等待凭据',
66
76
  'reason.probe-failed': '最近一次连接测试失败',
67
77
  'reason.tcp-refused': '端口拒绝连接',
68
78
  'reason.no-tools': '没有注册任何工具',
69
79
  'reason.connected': '已连接',
70
80
  'reason.unknown-tools': '工具表读不到,不下结论',
81
+ 'evidence.client': '客户端',
82
+ 'evidence.connecting': '连接中',
83
+ 'evidence.connected': '已连接',
84
+ 'evidence.reconnecting': '重连中',
85
+ 'evidence.closed': '已关闭',
86
+ 'evidence.waiting-credentials': '等待凭据',
71
87
  'evidence.fiber': 'fiber',
72
88
  'evidence.tools': '工具',
73
89
  'evidence.tcp': 'TCP',
@@ -84,6 +100,9 @@ window.__ModuleLoader__.load({
84
100
  'hint.notToggleable': '该服务器由插件包提供,不能在面板里开关',
85
101
  'hint.idle': 'MCP 客户端已加载,但没有注册任何工具——通常意味着连接失败。点「测试连接」看原因。',
86
102
  'hint.unreachable': '最近一次连接检测失败:下面的错误就是原因。修好后点「重试」重新挂载这一行。',
103
+ 'hint.reconnecting': '客户端正在自动重连,工具暂时不可用;连上后面板会自动变绿。',
104
+ 'hint.reconnectingN': '客户端正在自动重连(第 {n}/{max} 次),工具暂时不可用;连上后面板会自动变绿。',
105
+ 'hint.gaveUp': '自动重连已放弃,工具已卸载——「重试」会重新挂载这一行,重连预算从头算。',
87
106
  'hint.staleTools': '工具仍然注册着({n} 个),那是上一次连接成功留下的,不代表现在连着——连接已失效。',
88
107
  'hint.failed': '这一行加载失败,展开可看错误信息;「重试」会重新挂载它。',
89
108
  'hint.disabled': '已停用:不会连接,也不占工具表。',
@@ -96,6 +115,14 @@ window.__ModuleLoader__.load({
96
115
  'toggle.disabled': '已停用',
97
116
  'test.ok': '连接成功:{n} 个工具,耗时 {ms} ms',
98
117
  'test.fail': '连接失败',
118
+ 'dock.loading': '读取 MCP 状态…',
119
+ 'dock.empty': '还没有配置 MCP 服务器',
120
+ 'dock.connectedOf': '已连接 {n}/{total}',
121
+ 'dock.attention': '{n} 台要处理:{names}',
122
+ 'dock.more': '等 {n} 台',
123
+ 'dock.pending': '{n} 台正在连接',
124
+ 'dock.idle': '{n} 台没有工具',
125
+ 'dock.disabled': '{n} 台已停用',
99
126
  };
100
127
 
101
128
  const EN = {
@@ -105,6 +132,7 @@ window.__ModuleLoader__.load({
105
132
  'panel.emptyHint': 'Add one under Settings → Plugins → MCP server configuration, or write an mcp-client row into the profile patch.',
106
133
  'state.connected': 'Connected',
107
134
  'state.connecting': 'Connecting',
135
+ 'state.reconnecting': 'Reconnecting',
108
136
  'state.idle': 'Not connected',
109
137
  'state.unreachable': 'Unreachable',
110
138
  'state.failed': 'Failed',
@@ -123,6 +151,7 @@ window.__ModuleLoader__.load({
123
151
  'action.showConfig': 'Config',
124
152
  'action.hideConfig': 'Hide',
125
153
  'field.transport': 'Transport',
154
+ 'field.client': 'Connection',
126
155
  'field.command': 'Command',
127
156
  'field.url': 'URL',
128
157
  'field.env': 'Environment',
@@ -131,15 +160,27 @@ window.__ModuleLoader__.load({
131
160
  'field.entry': 'Entry',
132
161
  'field.reason': 'Verdict',
133
162
  'field.evidence': 'Evidence',
134
- 'panel.updated': 'updated {n}s ago',
163
+ 'panel.changed': 'changed {n}s ago',
135
164
  'reason.disabled': 'disabled by choice — not a fault',
136
165
  'reason.fiber-failed': 'the MCP client failed to load',
137
166
  'reason.pending': 'the MCP client is starting',
167
+ 'reason.client-connecting': 'the MCP client is connecting',
168
+ 'reason.client-reconnecting': 'the MCP client is retrying the connection',
169
+ 'reason.gave-up': 'reconnect gave up (attempt limit reached, tools unregistered)',
170
+ 'reason.client-failed': 'the MCP connection failed',
171
+ 'reason.client-closed': 'the MCP client is closed',
172
+ 'reason.waiting-credentials': 'waiting for credentials',
138
173
  'reason.probe-failed': 'the last connection test failed',
139
174
  'reason.tcp-refused': 'the port refuses connections',
140
175
  'reason.no-tools': 'no tools registered',
141
176
  'reason.connected': 'connected',
142
177
  'reason.unknown-tools': 'tool registry unreadable — no verdict',
178
+ 'evidence.client': 'client',
179
+ 'evidence.connecting': 'connecting',
180
+ 'evidence.connected': 'connected',
181
+ 'evidence.reconnecting': 'reconnecting',
182
+ 'evidence.closed': 'closed',
183
+ 'evidence.waiting-credentials': 'waiting credentials',
143
184
  'evidence.fiber': 'fiber',
144
185
  'evidence.tools': 'tools',
145
186
  'evidence.tcp': 'TCP',
@@ -156,6 +197,9 @@ window.__ModuleLoader__.load({
156
197
  'hint.notToggleable': 'Provided by a plugin package; it cannot be switched here',
157
198
  'hint.idle': 'The MCP client is loaded but registered no tools — usually a failed connection. Test it to see why.',
158
199
  'hint.unreachable': 'The latest connection check failed; the error below says why. Fix it, then use Reconnect to remount the row.',
200
+ 'hint.reconnecting': 'The MCP client is retrying the connection; tools are unavailable meanwhile. The dot turns green once it reconnects.',
201
+ 'hint.reconnectingN': 'The MCP client is retrying the connection (attempt {n} of {max}); tools are unavailable meanwhile.',
202
+ 'hint.gaveUp': 'Reconnecting gave up and the tools were unregistered — Reconnect remounts just this row with a fresh attempt budget.',
159
203
  'hint.staleTools': '{n} tools are still registered from an earlier successful connection — that no longer means the server is reachable.',
160
204
  'hint.failed': 'This row failed to load. Expand it for the error; Reconnect remounts it.',
161
205
  'hint.disabled': 'Disabled: no connection is attempted and no tools are registered.',
@@ -168,6 +212,14 @@ window.__ModuleLoader__.load({
168
212
  'toggle.timeout': 'Still connecting; the list refreshes automatically',
169
213
  'test.ok': 'Connected: {n} tools in {ms} ms',
170
214
  'test.fail': 'Connection failed',
215
+ 'dock.loading': 'Reading MCP state…',
216
+ 'dock.empty': 'No MCP server configured',
217
+ 'dock.connectedOf': '{n}/{total} connected',
218
+ 'dock.attention': '{n} need attention: {names}',
219
+ 'dock.more': '+{n} more',
220
+ 'dock.pending': '{n} connecting',
221
+ 'dock.idle': '{n} with no tools',
222
+ 'dock.disabled': '{n} disabled',
171
223
  };
172
224
 
173
225
  /* ------------------------------------------------------------------ *
@@ -200,7 +252,7 @@ window.__ModuleLoader__.load({
200
252
  .mcpPanel-dot[data-state=connected]{background:var(--dsw-alias-state-success-primary)}
201
253
  .mcpPanel-dot[data-state=idle],.mcpPanel-dot[data-state=unreachable]{background:var(--dsw-alias-state-error-primary)}
202
254
  .mcpPanel-dot[data-state=failed]{background:var(--dsw-alias-state-error-primary)}
203
- .mcpPanel-dot[data-state=connecting]{background:var(--dsw-alias-state-warn-primary);animation:mcpPanel-pulse 1.2s ease-in-out infinite}
255
+ .mcpPanel-dot[data-state=connecting],.mcpPanel-dot[data-state=reconnecting]{background:var(--dsw-alias-state-warn-primary);animation:mcpPanel-pulse 1.2s ease-in-out infinite}
204
256
  @keyframes mcpPanel-pulse{0%,100%{opacity:1}50%{opacity:.35}}
205
257
  .mcpPanel-id{display:flex;flex-direction:column;gap:2px;min-width:0;flex:1}
206
258
  .mcpPanel-nameLine{display:flex;align-items:baseline;gap:8px;min-width:0}
@@ -208,6 +260,7 @@ window.__ModuleLoader__.load({
208
260
  .mcpPanel-state{font-size:11.5px;color:var(--dsw-alias-label-secondary);white-space:nowrap}
209
261
  .mcpPanel-state[data-state=connected]{color:var(--dsw-alias-state-success-primary)}
210
262
  .mcpPanel-state[data-state=idle],.mcpPanel-state[data-state=failed],.mcpPanel-state[data-state=unreachable]{color:var(--dsw-alias-state-error-primary)}
263
+ .mcpPanel-state[data-state=reconnecting]{color:var(--dsw-alias-state-warn-primary)}
211
264
  .mcpPanel-target{font-size:11.5px;line-height:16px;color:var(--dsw-alias-label-secondary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-family:var(--dsw-font-family-code,ui-monospace,SFMono-Regular,Menlo,monospace)}
212
265
  .mcpPanel-tools{font-size:11px;color:var(--dsw-alias-label-secondary);border:.5px solid var(--dsw-alias-border-l1);border-radius:6px;padding:1px 6px;white-space:nowrap;font-variant-numeric:tabular-nums}
213
266
  .mcpPanel-link{appearance:none;border:0;background:0 0;padding:0 2px;font:inherit;font-size:11.5px;color:var(--dsw-alias-brand-primary);cursor:pointer;white-space:nowrap}
@@ -227,6 +280,22 @@ window.__ModuleLoader__.load({
227
280
  .mcpPanel-note[data-tone=ok]{color:var(--dsw-alias-state-success-primary)}
228
281
  .mcpPanel-empty{border:.5px dashed var(--dsw-alias-border-l2);border-radius:10px;padding:26px 20px;text-align:center;display:flex;flex-direction:column;gap:6px;color:var(--dsw-alias-label-secondary);font-size:12.5px}
229
282
  .mcpPanel-emptyTitle{color:var(--dsw-alias-label-primary);font-size:13.5px;font-weight:600}
283
+ `;
284
+
285
+ /**
286
+ * 侧栏角标的样式挂在宿主 <head> 上,不跟面板走。
287
+ *
288
+ * 面板切到别的视图时会被卸载,侧栏那一行却还在;样式若跟着面板走,那时 DOM 里
289
+ * 只剩一个没有宽度和颜色的空 span —— 点等于消失(用户看到的就是「只有打开面板才有红点」)。
290
+ */
291
+ const DOCK_CSS = `
292
+ .mcpDock{position:relative;display:inline-flex;align-items:center;justify-content:center;color:inherit}
293
+ .mcpDock-dot{position:absolute;top:-1px;right:-3px;width:6px;height:6px;border-radius:50%;background:var(--dsw-alias-state-warn-primary);box-shadow:0 0 0 1.5px var(--dsw-alias-bg-base);animation:mcpDockPulse .9s ease-out 1}
294
+ .mcpDock[data-tone=bad] .mcpDock-dot{background:var(--dsw-alias-state-error-primary)}
295
+ .mcpDock-rail{width:6px;height:6px;border-radius:50%;flex:none;background:var(--dsw-alias-state-warn-primary);margin:-14px 0 0 -6px}
296
+ .mcpDock-rail[data-tone=bad]{background:var(--dsw-alias-state-error-primary)}
297
+ @keyframes mcpDockPulse{0%{transform:scale(1)}35%{transform:scale(1.9)}100%{transform:scale(1)}}
298
+ @media (prefers-reduced-motion: reduce){.mcpDock-dot{animation:none}}
230
299
  `;
231
300
 
232
301
  /* ------------------------------------------------------------------ *
@@ -265,6 +334,157 @@ window.__ModuleLoader__.load({
265
334
  return payload;
266
335
  }
267
336
 
337
+ /* ------------------------------------------------------------------ *
338
+ * 侧栏角标
339
+ *
340
+ * 侧栏行的文字由宿主按 locale 派生,不随数据变化,所以状态只能画在 16px 的图标上;
341
+ * 图标是组件(宿主经 renderSlot('sidebar.panellist') 渲染),因此它能自己订阅、自己重渲染。
342
+ * 数据走 /summary:读缓存、不探活,5 s 一次,页面隐藏时暂停。
343
+ * ------------------------------------------------------------------ */
344
+
345
+ /** 音调排序,只用于「这次比上次更糟吗」——状态本身仍由宿主判定(A1)。 */
346
+ function dockSeverity(tone) {
347
+ if (tone === 'bad') return 3;
348
+ if (tone === 'warn') return 2;
349
+ if (tone === 'idle') return 1;
350
+ return 0;
351
+ }
352
+
353
+ /** 一句话把摘要讲完:16px 里放不下的东西全放进 hover 提示。 */
354
+ function dockTitle(t, summary) {
355
+ if (summary === null || summary === undefined) return t('dock.loading');
356
+ const counts = summary.counts ?? {};
357
+ if ((counts.total ?? 0) === 0) return t('dock.empty');
358
+
359
+ const parts = [t('dock.connectedOf', { n: counts.connected ?? 0, total: counts.total })];
360
+ const retrying = counts.reconnecting ?? 0;
361
+ const unhealthy = counts.unhealthy ?? 0;
362
+ if (retrying + unhealthy > 0) {
363
+ const names = (summary.names ?? []).join(', ');
364
+ const more = summary.more ?? 0;
365
+ parts.push(t('dock.attention', {
366
+ n: retrying + unhealthy,
367
+ names: more > 0 ? names + ' ' + t('dock.more', { n: more }) : names,
368
+ }));
369
+ }
370
+ if ((counts.pending ?? 0) > 0) parts.push(t('dock.pending', { n: counts.pending }));
371
+ if ((counts.idle ?? 0) > 0) parts.push(t('dock.idle', { n: counts.idle }));
372
+ if ((counts.disabled ?? 0) > 0) parts.push(t('dock.disabled', { n: counts.disabled }));
373
+ return parts.join(' · ');
374
+ }
375
+
376
+ function createSummaryStore() {
377
+ const listeners = new Set();
378
+ let snapshot = { loading: true, summary: null, error: null, pulseAt: 0 };
379
+ let timer;
380
+ let inflight;
381
+ let lastSeverity = null;
382
+
383
+ const publish = (patch) => {
384
+ snapshot = { ...snapshot, ...patch };
385
+ for (const listener of listeners) {
386
+ try {
387
+ listener();
388
+ } catch {
389
+ /* 一个订阅者坏掉不该拖垮另一个 */
390
+ }
391
+ }
392
+ };
393
+
394
+ const load = () => {
395
+ if (inflight !== undefined) return inflight;
396
+ inflight = requestJson('/summary', { method: 'GET' })
397
+ .then((payload) => {
398
+ const severity = dockSeverity(payload?.worst);
399
+ // 只在变差时脉冲;恢复健康不在侧栏里放礼花。
400
+ const worsened = lastSeverity !== null && severity > lastSeverity;
401
+ lastSeverity = severity;
402
+ publish({
403
+ loading: false,
404
+ error: null,
405
+ summary: payload,
406
+ pulseAt: worsened ? Date.now() : snapshot.pulseAt,
407
+ });
408
+ })
409
+ .catch((error) => {
410
+ // 拿不到摘要就保留上一份:宁可显示略旧的真话,也不要因为一次 500 把点抹掉。
411
+ publish({ loading: false, error: error?.message ?? String(error) });
412
+ })
413
+ .finally(() => {
414
+ inflight = undefined;
415
+ });
416
+ return inflight;
417
+ };
418
+
419
+ const onVisibility = () => {
420
+ if (document.visibilityState === 'visible') load();
421
+ };
422
+
423
+ const start = () => {
424
+ load();
425
+ document.addEventListener('visibilitychange', onVisibility);
426
+ timer = setInterval(() => {
427
+ if (document.visibilityState === 'visible') load();
428
+ }, DOCK_POLL_MS);
429
+ };
430
+
431
+ const stop = () => {
432
+ if (timer !== undefined) clearInterval(timer);
433
+ timer = undefined;
434
+ document.removeEventListener('visibilitychange', onVisibility);
435
+ };
436
+
437
+ return {
438
+ getSnapshot: () => snapshot,
439
+ subscribe(listener) {
440
+ listeners.add(listener);
441
+ // 侧栏收起时这一行仍在树上(只是变窄),所以按订阅者数量、不按可见性决定轮询开关。
442
+ if (listeners.size === 1) start();
443
+ return () => {
444
+ listeners.delete(listener);
445
+ if (listeners.size === 0) stop();
446
+ };
447
+ },
448
+ };
449
+ }
450
+
451
+ const summaryStore = createSummaryStore();
452
+
453
+ function useSummary() {
454
+ const [state, setState] = useState(summaryStore.getSnapshot);
455
+ useEffect(() => summaryStore.subscribe(() => setState(summaryStore.getSnapshot())), []);
456
+ return state;
457
+ }
458
+
459
+ /** 侧栏那一行的图标:本体不变,右上角长出状态点。 */
460
+ function StatusGlyph({ size = 18, t }) {
461
+ const state = useSummary();
462
+ const summary = state.summary;
463
+ const tone = summary?.worst ?? 'empty';
464
+ const attention = tone === 'bad' || tone === 'warn';
465
+ return h(
466
+ 'span',
467
+ { className: 'mcpDock', 'data-tone': tone, title: dockTitle(t, summary) },
468
+ h(Glyph, { size }),
469
+ // key 换成新的 pulseAt 会让节点重建一次,CSS 动画因此只播一次。
470
+ attention ? h('span', { key: String(state.pulseAt), className: 'mcpDock-dot', 'aria-hidden': true }) : null,
471
+ );
472
+ }
473
+
474
+ /** 收起态:展开按钮上的点。只提示,不改变按钮行为。 */
475
+ function ToggleBadge({ t }) {
476
+ const state = useSummary();
477
+ const summary = state.summary;
478
+ const tone = summary?.worst ?? 'empty';
479
+ if (tone !== 'bad' && tone !== 'warn') return null;
480
+ return h('span', {
481
+ className: 'mcpDock-rail',
482
+ 'data-tone': tone,
483
+ title: dockTitle(t, summary),
484
+ 'aria-hidden': true,
485
+ });
486
+ }
487
+
268
488
  /* ------------------------------------------------------------------ *
269
489
  * 图标
270
490
  * ------------------------------------------------------------------ */
@@ -349,25 +569,40 @@ window.__ModuleLoader__.load({
349
569
  return text === key ? (server.reason ?? '') : text;
350
570
  }
351
571
 
572
+ /** 一条 evidence 的取值文案:code → 本地化,未知 code 原样显示(宿主新增状态不会变成空白)。 */
573
+ function evidenceValue(t, item) {
574
+ if (item.signal === 'tools') {
575
+ return item.value === null || item.value === undefined ? '?' : String(item.value);
576
+ }
577
+ if (item.signal === 'probe') {
578
+ return item.value === 'ok' ? t('evidence.ok') : (item.detail ?? t('evidence.failed'));
579
+ }
580
+ const key = `evidence.${item.value}`;
581
+ const text = t(key);
582
+ const base = text === key ? String(item.value) : text;
583
+ return item.detail ? `${base} ${item.detail}` : base;
584
+ }
585
+
352
586
  /** 依据摘要:把 resolver 的 evidence 压成一行,带时间戳的项标注多久以前。 */
353
587
  function describeEvidence(t, server) {
354
588
  const now = Date.now();
355
- const parts = [];
356
- for (const item of server.evidence ?? []) {
589
+ return (server.evidence ?? []).map((item) => {
357
590
  const label = t(`evidence.${item.signal}`);
358
- if (item.signal === 'tools') {
359
- parts.push(`${label} ${item.value === null || item.value === undefined ? '?' : item.value}`);
360
- continue;
361
- }
362
- const value = item.signal === 'fiber'
363
- ? t(`evidence.${item.value}`)
364
- : item.signal === 'tcp'
365
- ? t(`evidence.${item.value}`)
366
- : item.value === 'ok' ? t('evidence.ok') : (item.detail ?? t('evidence.failed'));
367
591
  const age = typeof item.at === 'number' ? ` (${Math.max(0, Math.round((now - item.at) / 1000))}s)` : '';
368
- parts.push(`${label} ${value}${age}`);
592
+ return `${label} ${evidenceValue(t, item)}${age}`;
593
+ }).join(' · ');
594
+ }
595
+
596
+ /** 宿主连接状态的一句话(重连带次数,失败带 reason code)。 */
597
+ function connectionLabel(t, connection) {
598
+ const key = `evidence.${connection.state}`;
599
+ const text = t(key);
600
+ const base = text === key ? String(connection.state) : text;
601
+ if (connection.state === 'reconnecting' && typeof connection.attempt === 'number') {
602
+ return `${base} ${connection.attempt}/${connection.maxAttempts ?? '?'}`;
369
603
  }
370
- return parts.join(' · ');
604
+ if (connection.state === 'failed' && connection.reason) return `${base}(${connection.reason})`;
605
+ return base;
371
606
  }
372
607
 
373
608
  function ServerCard({ server, t, busy, onToggle, onTest, onRetry, expanded, onExpand }) {
@@ -378,21 +613,29 @@ window.__ModuleLoader__.load({
378
613
  const testBusy = busy?.kind === 'test';
379
614
  const retryBusy = busy?.kind === 'retry';
380
615
  const testResult = busy?.result;
616
+ const connection = server.connection ?? undefined;
381
617
 
382
618
  const hint = state === 'idle' ? t('hint.idle')
383
- : state === 'unreachable' ? t('hint.unreachable')
384
- : state === 'failed' ? t('hint.failed')
385
- : state === 'disabled' ? t('hint.disabled')
386
- : state === 'connecting' ? t('hint.pending')
387
- : null;
388
- // 连接已不可达、但工具还留在注册表里:那是上一次连接成功留下的残留,必须说清楚。
389
- const staleTools = state === 'unreachable' && (server.toolCount ?? 0) > 0
619
+ : state === 'reconnecting'
620
+ ? (typeof connection?.attempt === 'number'
621
+ ? t('hint.reconnectingN', { n: connection.attempt, max: connection.maxAttempts ?? '?' })
622
+ : t('hint.reconnecting'))
623
+ : state === 'unreachable' ? t('hint.unreachable')
624
+ : state === 'failed' && server.reason === 'gave-up' ? t('hint.gaveUp')
625
+ : state === 'failed' ? t('hint.failed')
626
+ : state === 'disabled' ? t('hint.disabled')
627
+ : state === 'connecting' ? t('hint.pending')
628
+ : null;
629
+ // 连接已不可用、但工具还留在注册表里:那是上一次连接成功留下的残留,必须说清楚。
630
+ const staleTools = (state === 'unreachable' || state === 'reconnecting' || state === 'failed')
631
+ && (server.toolCount ?? 0) > 0
390
632
  ? t('hint.staleTools', { n: server.toolCount })
391
633
  : null;
392
634
 
393
635
  const fields = [
394
636
  [t('field.transport'), transportLabel(server.transport) || '—'],
395
637
  ];
638
+ if (connection) fields.push([t('field.client'), connectionLabel(t, connection)]);
396
639
  if (server.transport === 'stdio') {
397
640
  fields.push([t('field.command'), server.detail.command ?? '—']);
398
641
  if (server.detail.args?.length) fields.push(['args', server.detail.args.join(' ')]);
@@ -461,7 +704,7 @@ window.__ModuleLoader__.load({
461
704
  { className: 'mcpPanel-nameLine' },
462
705
  h('span', { className: 'mcpPanel-name', title: server.serverName }, server.serverName),
463
706
  h('span', { className: 'mcpPanel-state', 'data-state': state }, stateLabel(t, state)),
464
- state === 'connected' || state === 'idle' || state === 'unreachable'
707
+ state === 'connected' || state === 'idle' || state === 'unreachable' || state === 'reconnecting'
465
708
  ? h(
466
709
  'span',
467
710
  { className: 'mcpPanel-tools' },
@@ -529,13 +772,23 @@ window.__ModuleLoader__.load({
529
772
  const [busy, setBusy] = useState({});
530
773
  const [expanded, setExpanded] = useState({});
531
774
  const [refreshing, setRefreshing] = useState(false);
775
+ const [changedAt, setChangedAt] = useState(null);
776
+ const signatureRef = useRef('');
532
777
  const mounted = useRef(true);
533
778
 
534
779
  const load = useCallback(async () => {
535
780
  try {
536
781
  const payload = await requestJson('/servers', { method: 'GET' });
537
782
  if (!mounted.current) return;
538
- setSnapshot({ loading: false, servers: payload.servers ?? [], error: null, checkedAt: payload.checkedAt });
783
+ const servers = payload.servers ?? [];
784
+ // 顶栏计时的是「上次状态变化」:只有某行的 state/reason 真的变了才重新计时。
785
+ // 用采快照的时间会是个自指量(每次请求都刚采过,永远是 0s),没有信息量。
786
+ const signature = servers
787
+ .map((server) => `${server.id}:${server.state}:${server.reason}`)
788
+ .join('|');
789
+ if (signatureRef.current !== '' && signatureRef.current !== signature) setChangedAt(Date.now());
790
+ signatureRef.current = signature;
791
+ setSnapshot({ loading: false, servers, error: null, checkedAt: payload.checkedAt });
539
792
  } catch (error) {
540
793
  if (!mounted.current) return;
541
794
  setSnapshot((previous) => ({ ...previous, loading: false, error: error?.message ?? String(error) }));
@@ -658,11 +911,9 @@ window.__ModuleLoader__.load({
658
911
  h('div', { className: 'mcpPanel-title' }, t('panel.title')),
659
912
  h('div', { className: 'mcpPanel-sub' }, snapshot.loading
660
913
  ? '…'
661
- : `${snapshot.servers.length} MCP · ${t('panel.updated', {
662
- n: snapshot.checkedAt === undefined
663
- ? 0
664
- : Math.max(0, Math.round((Date.now() - snapshot.checkedAt) / 1000)),
665
- })}`),
914
+ : `${snapshot.servers.length} MCP${changedAt === null ? '' : ` · ${t('panel.changed', {
915
+ n: Math.max(0, Math.round((Date.now() - changedAt) / 1000)),
916
+ })}`}`),
666
917
  ),
667
918
  h(
668
919
  'div',
@@ -732,13 +983,29 @@ window.__ModuleLoader__.load({
732
983
  ctx.effect(() => ctx.locale.register(NS, { zh: ZH, en: EN }), 'dsh-mcp-status: dictionaries');
733
984
  const t = ctx.locale.bind(NS);
734
985
 
986
+ // 角标样式必须挂在 <head>:面板切走后会被卸载,侧栏那一行还在,样式一没点就画不出来。
987
+ ctx.effect(() => {
988
+ const style = document.createElement('style');
989
+ style.setAttribute('data-dsh-plugin', `${NS}-dock`);
990
+ style.textContent = DOCK_CSS;
991
+ document.head.appendChild(style);
992
+ return () => style.remove();
993
+ }, 'dsh-mcp-status: dock styles');
994
+
735
995
  ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
736
996
  name: 'sidebar.panellist',
737
997
  id: PANEL_ID,
738
998
  order: PANEL_ORDER,
739
999
  label: () => t('panel.title'),
740
1000
  locale: NS,
741
- }, ({ size = 18 }) => h(Glyph, { size })));
1001
+ }, ({ size = 18 }) => h(StatusGlyph, { size, t })));
1002
+
1003
+ // 侧栏收起时,顶部展开按钮上的状态点(宿主声明为可选、不可交互)。
1004
+ // 全好时不注册任何东西:没有点就是没有坏事,比一个常年发绿的点更可信。
1005
+ ctx.slots.inject('sidebar.toggle.badge', () => ctx.slots.register({
1006
+ name: 'sidebar.toggle.badge',
1007
+ locale: NS,
1008
+ }, () => h(ToggleBadge, { t })));
742
1009
 
743
1010
  ctx.slots.inject('main', () => ctx.slots.register({
744
1011
  name: 'main',