dsh-session-superagent 2.0.0 → 2.0.1

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.md CHANGED
@@ -152,7 +152,7 @@ node scripts/render-preview.mjs preview.html
152
152
 
153
153
  ## 十、当前基线
154
154
 
155
- 2.0.0(独立实验仓候选);全量 **1420/1420**、房间边界 **20/20**、preflight **44 项**(贡献归属仅 PR CI 执行,本地 / main push 为 SKIP)、UI **11/11**。
155
+ 2.0.0(独立实验仓候选);全量 **1428/1428**、房间边界 **20/20**、preflight **44 项**(贡献归属仅 PR CI 执行,本地 / main push 为 SKIP)、UI **11/11**。
156
156
  无 `webServer` 的 headless 实例已完成 `watch_start`、重新 import/apply 与 interval 恢复验收;单守异常隔离及 `lastError` 落盘有独立测试。
157
157
  真实 Chromium:Issue #58 多段添加 / 编辑 / 删除 / 保存四项通过;Issue #60「只看新评论」新建、编辑保存与两次回读 **4/4** 通过。完整 harness 的 rc.2 Orbit/Modal 三项失败已由未改 main 复现(main 57/60,本分支含 #60 为 65/68),不记为本功能通过项。
158
158
  真实 `github` 工具 `POST /markdown` 请求体端到端验证通过(无仓库副作用)。
package/CHANGELOG.md CHANGED
@@ -2,8 +2,22 @@
2
2
 
3
3
  格式参照 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
4
4
 
5
+ ## [2.0.1] - 2026-11-26
6
+
7
+ 修正 2.0.0 发布后发现的右栏页签注册时序问题;本版由 @iJetLi 的 PR #71 修复,维护者独立复现并补齐真机验证。
8
+
5
9
  ## [Unreleased]
6
10
 
11
+ ### Fixed
12
+
13
+ - **点头部鲸鱼图标报 `sidebarRight: no tab type is registered as "sessionSuperagent"`**(2026-11-26 真机)。官方:宿主 `sidebarRight` / `sidebarRightTabs` 晚于插件 `apply` 就绪,`openTab(kind)` 只认宿主注册表里 inForce 的 definition。我们:2.0.0 的「服务晚就绪重挂」只补挂了会话头部,右栏 definition 与 `sidebar.right.pane.tab` / `.title` 仍只在 `apply` 的 `ctx.effect` 里注册一次 —— 服务晚到的实例上它们从未注册,而头部已按新服务启用,点下去就由宿主抛错。为什么以前没发现:单测夹具的 `openTab` 不校验 kind,桩比宿主干净。(@iJetLi,PR #71)
14
+ 修复分两层,审计(实现审计 + 对抗审计)各发现一半,均已修:
15
+ 1. **入口与注册一起补**:definition / body / title 改为可重入 mount,在 Cordis `ctx.inject` 回调里**先补注册、再重挂头部**;左栏 `main` / `sidebar.panellist` 同样改为可重入(`layout` 晚到的实例上它们以前也永久缺失)。
16
+ 2. **不再被无关服务绑死**:注入依赖按入口拆开 —— 右栏 definition 只依赖 `sidebarRightTabs`、头部只依赖 `sidebarRight`、全局页只依赖 `layout`;2.0.0 把三者与 `sessions` 绑在同一个 inject 上,`sessions` 缺失或晚到时右栏会永久不可用。
17
+ 3. **幂等判据改成宿主事实**:mount 的早退条件从「本地 cleanup 非空」改为「宿主注册表里 `get(kind).id` 仍是本插件的 id」,宿主 HMR 换掉 service 实例后会自动重新注册;同名 kind 被别的插件 shadow 时头部禁用并说明被谁占用,而不是点开别人的页签。
18
+ 4. **两个入口同一判定**:Dock/Orbit 与头部共用 `rightTabIssue()`,definition 没注册时直接降级并在弹层里说明原因(以前点下去把宿主内部错误塞进弹层,弹层没开时用户根本看不见);注册失败时 tooltip 显示最近一次真实错误。
19
+ 测试:导航夹具按宿主 registry 语义保真(`register`/`get`/`entries`、id/kind 冲突抛错、band shadow、inject 依赖就绪才触发、依赖重建可重放),新增「服务晚到必须补注册并真的能打开」「sessions 缺失不连累注册」「服务实例重建后重注册」「kind 被占用时禁用」「Dock 不把宿主错误当用户提示」「layout 晚到补挂左栏」等回归。当前全量 1428/1428、UI 11/11。
20
+
7
21
  ## [2.0.0] - 2026-11-23 —— 会话级导航与 session scope 隔离(实验候选)
8
22
 
9
23
  ### Added
package/MAINTENANCE.md CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
  | 资产 / 验证 | 当前结果 |
30
30
  |---|---|
31
- | 全量单测 | **1420/1420,exit 0**;隔离 preflight 41 PASS + 3 SKIP。新增 Cordis 未 inject admission 可选服务代理回归,修复重启后 watcher 首轮报错 |
31
+ | 全量单测 | **1428/1428,exit 0**;隔离 preflight 41 PASS + 3 SKIP。新增右栏入口「宿主服务晚到必须补注册 definition、注册失败头部禁用」两条回归(2.0.0 真机点击报 no tab type registered),以及 Cordis 未 inject admission 可选服务代理回归 |
32
32
  | 房间边界 | **20/20 PASS**;UI audit **11/11** |
33
33
  | Outbox | 同进程单飞、跨进程租约、热重载共享 flush、不同 Ticket 排队、attempts 栅栏均有回归 |
34
34
  | 生产接线 | worker/inline、bot/系统事件、ack 操作 ID、watcher 世代、marker 分页、执行模式切换已定向复验 |
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  </p>
11
11
 
12
12
  <p align="center">
13
- <a href="https://github.com/MYCF711/dsh-session-superagent/releases"><img src="https://img.shields.io/badge/version-2.0.0-green.svg" alt="version"></a>
13
+ <a href="https://github.com/MYCF711/dsh-session-superagent/releases"><img src="https://img.shields.io/badge/version-2.0.1-green.svg" alt="version"></a>
14
14
  <a href="https://www.npmjs.com/package/dsh-session-superagent"><img src="https://img.shields.io/npm/v/dsh-session-superagent?color=4D6BFE" alt="npm"></a>
15
15
  <img src="https://img.shields.io/badge/license-MIT-4D6BFE" alt="license">
16
16
  </p>
@@ -172,7 +172,7 @@ Gitee 没有 ETag,每轮会真读一次列表;私有仓库需要在面板里
172
172
 
173
173
  ## 验证
174
174
 
175
- 已通过 1420 项单测、20 房边界、11 项 UI 静态审计(2.0.0 实验仓候选)。隔离 preflight **exit 0:41 PASS + 3 个预期 SKIP**,profile 0 漂移;2.0.0 headless 实例启动、重挂 interval 与 12 工具通过。新导航真实 Chromium **18/18**:旧中栏缺席、会话隔离、全局目标会话新建、头部 pressed/toggle/Tooltip、键盘、双主题与 700px 完整矩阵通过。两组双盲均已签收:核心 25 请求与 10 类跨会话写保护零发现,UI 原四项复核全部 CLOSED。用户已确认整版 UI 并允许推实验仓;未打 tag、未发布,主仓库不改。
175
+ 已通过 1428 项单测、20 房边界、11 项 UI 静态审计(2.0.1)。隔离 preflight **exit 0:41 PASS + 3 个预期 SKIP**,profile 0 漂移;2.0.1 headless 实例启动、重挂 interval 与 12 工具通过。新导航真实 Chromium **18/18**:旧中栏缺席、会话隔离、全局目标会话新建、头部 pressed/toggle/Tooltip、键盘、双主题与 700px 完整矩阵通过。两组双盲均已签收:核心 25 请求与 10 类跨会话写保护零发现,UI 原四项复核全部 CLOSED。用户已确认整版 UI 并允许推实验仓;已合入主仓 main,tag / Release / npm 同批发。
176
176
 
177
177
  ### 贡献归属门禁
178
178
 
@@ -188,7 +188,7 @@ node scripts/check-pr-attribution.mjs --pr 49 --against 41 --repo MYCF711/dsh-se
188
188
 
189
189
  | 说法 | 来源 |
190
190
  |---|---|
191
- | 实验候选 `2.0.0` | [package.json](package.json);未发布 tag / Release / npm;分支仅用于独立实验仓 |
191
+ | 当前版本 `2.0.1` | [package.json](package.json);未发布 tag / Release / npm;分支仅用于独立实验仓 |
192
192
  | 项目起点 | [deepseek-ai/dsh-superagent-prototype](https://github.com/deepseek-ai/dsh-superagent-prototype) |
193
193
  | DSH 原生 UI | [deepseek-ai/deepseek-harness](https://github.com/deepseek-ai/deepseek-harness)、`$DSH_HOME/DSH-UI-official.md`、`docs/ui-decomp/` |
194
194
  | 图标 | [DSH-X/docs/icon-app.png](https://github.com/yyh-001/DSH-X/blob/Staging/docs/icon-app.png)(MIT) |
package/client.js CHANGED
@@ -440,7 +440,7 @@ window.__ModuleLoader__.load({
440
440
  }
441
441
 
442
442
  // 客户端版本探针:每次模块加载写一次,用来确认浏览器里跑的是哪一版
443
- const CLIENT_VERSION = '2.0.0'
443
+ const CLIENT_VERSION = '2.0.1'
444
444
 
445
445
  // 会话级导航使用官方 root/session slot。服务是可选的:老宿主没有它们时,
446
446
  // 全局页仍可用,头部入口明确禁用,Dock 保留旧操作列表;不能用猜来的路由代替真实服务。
@@ -449,6 +449,8 @@ window.__ModuleLoader__.load({
449
449
  const RIGHT_TAB_KIND = 'sessionSuperagent'
450
450
  const RIGHT_TAB_UNAVAILABLE = '宿主 sidebarRight.openTab 服务不存在'
451
451
  const RIGHT_TAB_DEFINITION_UNAVAILABLE = '宿主 sidebarRightTabs.register 服务不存在'
452
+ const RIGHT_TAB_DEFINITION_PENDING = '宿主 sidebarRightTabs 尚未注册本页签'
453
+ let rightRegistrationError = null
452
454
  const HEADER_UTILITY_ID = 'session-superagent-current'
453
455
  let hostLayout = null
454
456
  let hostSidebarRight = null
@@ -482,6 +484,44 @@ window.__ModuleLoader__.load({
482
484
  // 右栏 session slot 自带当前 sessionId;调用方只传 kind,不拼 sidebar:// 地址或伪造 params。
483
485
  return hostSidebarRight.openTab(RIGHT_TAB_KIND)
484
486
  }
487
+ // 宿主 openTab 在 kind 没有注册时直接抛 `sidebarRight: no tab type is registered as "…"`,
488
+ // 所以入口可用性必须以宿主注册表的真实内容为准:既要 kind 在,也要 inForce 的 definition
489
+ // 就是我们这一条(同 kind 被别的插件 shadow 时 get(kind) 返回的是别人,点开会是别人的页签)。
490
+ function rightTabOwnedByUs() {
491
+ if (!hostSidebarRightTabs) return false
492
+ try {
493
+ if (typeof hostSidebarRightTabs.get === 'function') {
494
+ const definition = hostSidebarRightTabs.get(RIGHT_TAB_KIND)
495
+ return Boolean(definition && definition.id === RIGHT_TAB_ID)
496
+ }
497
+ if (typeof hostSidebarRightTabs.entries === 'function') {
498
+ const entries = hostSidebarRightTabs.entries() || []
499
+ return entries.some((definition) => definition
500
+ && definition.kind === RIGHT_TAB_KIND && definition.id === RIGHT_TAB_ID)
501
+ }
502
+ } catch {
503
+ return false
504
+ }
505
+ // 宿主只暴露 register(老宿主/测试桩)时无法查询:按已注册处理,保持原有的 open-only 行为。
506
+ return true
507
+ }
508
+
509
+ // 会话头部与 Dock/Orbit 共用同一个判定:null 表示「现在点下去宿主一定按我们的 kind 打开」。
510
+ // 只看 register 方法是否存在会把「服务在、注册却没跑到」显示成可点 —— 真机上就是那条红字。
511
+ function rightTabIssue() {
512
+ if (!hostSidebarRight || typeof hostSidebarRight.openTab !== 'function') return RIGHT_TAB_UNAVAILABLE
513
+ if (!hostSidebarRightTabs || typeof hostSidebarRightTabs.register !== 'function') return RIGHT_TAB_DEFINITION_UNAVAILABLE
514
+ if (rightTabOwnedByUs()) return null
515
+ // kind 在、但不是我们的 definition:可能被别的插件 shadow(extension band 更高)。
516
+ try {
517
+ const held = typeof hostSidebarRightTabs.get === 'function'
518
+ ? hostSidebarRightTabs.get(RIGHT_TAB_KIND)
519
+ : null
520
+ if (held && held.id !== RIGHT_TAB_ID) return '主理鱼右栏页签已被 ' + String(held.id || '其它插件') + ' 占用'
521
+ } catch {}
522
+ if (rightRegistrationError) return '主理鱼右栏注册失败:' + rightRegistrationError
523
+ return RIGHT_TAB_DEFINITION_PENDING
524
+ }
485
525
  // SEMVER_COMPARATOR_SOURCE_START
486
526
  // This block is duplicated verbatim in client.js because the browser UMD cannot import ESM.
487
527
  // test/update-semver.test.mjs audits both copies and exercises their behavior.
@@ -2437,7 +2477,10 @@ window.__ModuleLoader__.load({
2437
2477
  }
2438
2478
  function StatusOrbit(props = {}) {
2439
2479
  // Dock 的 session slot 已提供当前 sessionId;右栏打开动作只传 kind。
2440
- const canOpenRight = Boolean(props.sessionId && hostSidebarRight && typeof hostSidebarRight.openTab === 'function')
2480
+ // 与头部共用 rightTabIssue():definition 没注册时要直接降级并说明原因 ——
2481
+ // 以前这里只看 openTab 存在,点击把宿主内部错误塞进弹层(弹层没开时用户根本看不见)。
2482
+ const rightIssue = rightTabIssue()
2483
+ const canOpenRight = Boolean(props.sessionId && !rightIssue)
2441
2484
  const [watchers, setWatchers] = useState(null)
2442
2485
  // 写操作的失败提示(M4):为空表示没有错误
2443
2486
  const [orbitError, setOrbitError] = useState(null)
@@ -2792,7 +2835,9 @@ window.__ModuleLoader__.load({
2792
2835
  !canOpenRight ? h('div', { className: 'sa-dock-foot', role: 'status' },
2793
2836
  !hostSidebarRight || typeof hostSidebarRight.openTab !== 'function'
2794
2837
  ? '宿主 sidebarRight 服务不存在;已保留旧操作列表。'
2795
- : '当前 Dock 没有 sessionId;已保留旧操作列表,未读取右栏。') : null,
2838
+ : !props.sessionId
2839
+ ? '当前 Dock 没有 sessionId;已保留旧操作列表,未读取右栏。'
2840
+ : (rightIssue || RIGHT_TAB_UNAVAILABLE) + ';已保留旧操作列表。') : null,
2796
2841
  list.length > 0
2797
2842
  ? h('div', { className: 'sa-dock-foot' }, '详细状态与凭证在「' + brandName + '」标签页')
2798
2843
  : null)
@@ -5489,11 +5534,7 @@ window.__ModuleLoader__.load({
5489
5534
  }, [props.sessionId])
5490
5535
  const unavailable = !props.sessionId
5491
5536
  ? '当前头部 slot 没有 sessionId'
5492
- : !hostSidebarRight || typeof hostSidebarRight.openTab !== 'function'
5493
- ? RIGHT_TAB_UNAVAILABLE
5494
- : !hostSidebarRightTabs || typeof hostSidebarRightTabs.register !== 'function'
5495
- ? RIGHT_TAB_DEFINITION_UNAVAILABLE
5496
- : null
5537
+ : rightTabIssue()
5497
5538
  const toggle = async () => {
5498
5539
  if (unavailable) return
5499
5540
  try {
@@ -5547,8 +5588,15 @@ window.__ModuleLoader__.load({
5547
5588
  // 品牌名同时驱动左栏、右栏 definition 与右栏标题。旧中栏删除后,
5548
5589
  // 改名订阅仍保留在这些存活入口上:先释放原注册,再按同 id/key/component 重注册。
5549
5590
  tabNameOverride = readTabNameOverride()
5550
- const mountBrandEntry = (mount, failureKey) => {
5591
+ const mountBrandEntry = (mount, failureKey, onFailure) => {
5551
5592
  let dispose = null
5593
+ const fail = (error) => {
5594
+ const message = String((error && error.message) || error)
5595
+ note(failureKey, message)
5596
+ if (typeof onFailure === 'function') {
5597
+ try { onFailure(message) } catch {}
5598
+ }
5599
+ }
5552
5600
  const unmount = () => {
5553
5601
  if (!dispose) return
5554
5602
  const current = dispose
@@ -5563,7 +5611,7 @@ window.__ModuleLoader__.load({
5563
5611
  remount()
5564
5612
  const stopWatching = subscribeTabName(() => {
5565
5613
  try { remount() } catch (error) {
5566
- note(failureKey, String((error && error.message) || error))
5614
+ fail(error)
5567
5615
  }
5568
5616
  })
5569
5617
  const cleanup = () => { stopWatching(); unmount() }
@@ -5572,7 +5620,7 @@ window.__ModuleLoader__.load({
5572
5620
  cleanup.remount = remount
5573
5621
  return cleanup
5574
5622
  } catch (error) {
5575
- note(failureKey, String((error && error.message) || error))
5623
+ fail(error)
5576
5624
  unmount()
5577
5625
  return undefined
5578
5626
  }
@@ -5590,64 +5638,138 @@ window.__ModuleLoader__.load({
5590
5638
  hostOpenSession = openSession
5591
5639
 
5592
5640
  // 左侧全局中枢:main 与 sidebar.panellist 使用同一个 panel id。
5593
- ctx.effect(() => {
5641
+ // layout 同样可能晚于 apply 就绪(与右栏同源问题):只挂一次会让左栏全局页永久缺失,
5642
+ // 所以也做成可重入 mount,由下方 ctx.inject(['layout']) 在服务到位后补挂。
5643
+ let globalEntriesCleanup = null
5644
+ let globalEntriesHost = null
5645
+ const unmountGlobalEntries = () => {
5646
+ if (globalEntriesCleanup) {
5647
+ try { globalEntriesCleanup() } catch {}
5648
+ }
5649
+ globalEntriesCleanup = null
5650
+ globalEntriesHost = null
5651
+ }
5652
+ const mountGlobalEntries = () => {
5594
5653
  if (!hostLayout || typeof hostLayout.selectPanel !== 'function') {
5595
5654
  noteOnce('layout-unavailable', 'layout.selectPanel 服务不存在;不注册无法选择的全局入口')
5596
- return undefined
5655
+ return
5597
5656
  }
5657
+ if (globalEntriesCleanup && globalEntriesHost === hostLayout) return
5658
+ unmountGlobalEntries()
5659
+ const disposers = []
5598
5660
  try {
5599
- return ctx.slots.inject('main', () => ctx.slots.register({
5661
+ const disposePanel = ctx.slots.inject('main', () => ctx.slots.register({
5600
5662
  name: 'main', key: GLOBAL_PANEL_ID,
5601
5663
  }, SuperagentGlobalPage))
5664
+ if (typeof disposePanel === 'function') disposers.push(disposePanel)
5602
5665
  } catch (error) {
5603
5666
  note('global-panel-fail', String((error && error.message) || error))
5604
- return undefined
5605
5667
  }
5606
- })
5607
- ctx.effect(() => {
5608
- if (!hostLayout || typeof hostLayout.selectPanel !== 'function') return undefined
5609
- return mountBrandEntry(() => ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
5668
+ const sidebarCleanup = mountBrandEntry(() => ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
5610
5669
  name: 'sidebar.panellist', id: GLOBAL_PANEL_ID, order: 20,
5611
5670
  label: () => tabNameLabel(),
5612
5671
  }, SuperagentNavIcon)), 'global-sidebar-fail')
5672
+ if (sidebarCleanup) disposers.push(sidebarCleanup)
5673
+ if (!disposers.length) return
5674
+ globalEntriesCleanup = () => {
5675
+ for (const dispose of disposers.reverse()) {
5676
+ try { dispose() } catch {}
5677
+ }
5678
+ }
5679
+ globalEntriesHost = hostLayout
5680
+ }
5681
+ ctx.effect(() => {
5682
+ mountGlobalEntries()
5683
+ return unmountGlobalEntries
5613
5684
  })
5614
5685
 
5615
5686
  // 右栏 page type:definition.id 用于 keyed body/title 分派,definition.kind 用于 openTab。
5616
- ctx.effect(() => {
5617
- if (!hostSidebarRightTabs || typeof hostSidebarRightTabs.register !== 'function') {
5687
+ // 这三件事都依赖宿主 sidebarRightTabs 就绪。真机上该服务晚于本插件 apply,而 ctx.effect
5688
+ // 只在 apply 跑一次 —— 只靠 ctx.effect 会出现「服务到位后头部被启用、definition 却没注册」,
5689
+ // 点下去宿主抛 `sidebarRight: no tab type is registered as "sessionSuperagent"`。
5690
+ // 所以拆成可重入的 mount 函数:apply 时试一次,服务到位/重建时(见下方 ctx.inject)再试。
5691
+ // 幂等判据必须看「宿主注册表里还有没有我们的 id」:宿主 HMR 换掉 service 实例后,
5692
+ // 本地 cleanup 还在,但新 registry 是空的 —— 只看本地 flag 会把右栏永久丢掉。
5693
+ const canRegisterRightTab = () => Boolean(hostSidebarRightTabs
5694
+ && typeof hostSidebarRightTabs.register === 'function')
5695
+ let rightDefinitionCleanup = null
5696
+ let rightDefinitionHost = null
5697
+ let rightPaneCleanup = null
5698
+ let rightPaneHost = null
5699
+ const unmountRightDefinition = () => {
5700
+ if (rightDefinitionCleanup) {
5701
+ try { rightDefinitionCleanup() } catch {}
5702
+ }
5703
+ rightDefinitionCleanup = null
5704
+ rightDefinitionHost = null
5705
+ }
5706
+ const mountRightDefinition = () => {
5707
+ if (!canRegisterRightTab()) {
5618
5708
  noteOnce('sidebar-right-tabs-unavailable', 'sidebarRightTabs.register 服务不存在;会话头部入口显示不可用原因')
5619
- return undefined
5709
+ return
5620
5710
  }
5621
- return mountBrandEntry(() => hostSidebarRightTabs.register({
5622
- id: RIGHT_TAB_ID,
5623
- kind: RIGHT_TAB_KIND,
5624
- priority: 'builtin',
5625
- title: () => tabNameLabel(),
5626
- guide: [{
5627
- id: 'session-superagent',
5628
- order: 20,
5711
+ if (rightDefinitionCleanup && rightDefinitionHost === hostSidebarRightTabs && rightTabOwnedByUs()) return
5712
+ unmountRightDefinition()
5713
+ const cleanup = mountBrandEntry(() => {
5714
+ const dispose = hostSidebarRightTabs.register({
5715
+ id: RIGHT_TAB_ID,
5716
+ kind: RIGHT_TAB_KIND,
5717
+ priority: 'builtin',
5629
5718
  title: () => tabNameLabel(),
5630
- description: () => '查看当前项目会话的 watcher、Ticket、执行、Outbox 与草稿',
5631
- icon: SuperagentNavIcon,
5632
- }],
5633
- }), 'right-definition-fail')
5634
- })
5635
- ctx.effect(() => {
5636
- if (!hostSidebarRightTabs || typeof hostSidebarRightTabs.register !== 'function') return undefined
5719
+ guide: [{
5720
+ id: 'session-superagent',
5721
+ order: 20,
5722
+ title: () => tabNameLabel(),
5723
+ description: () => '查看当前项目会话的 watcher、Ticket、执行、Outbox 与草稿',
5724
+ icon: SuperagentNavIcon,
5725
+ }],
5726
+ })
5727
+ rightRegistrationError = null
5728
+ return dispose
5729
+ }, 'right-definition-fail', (message) => { rightRegistrationError = message })
5730
+ if (!cleanup) return
5731
+ rightDefinitionCleanup = cleanup
5732
+ rightDefinitionHost = hostSidebarRightTabs
5733
+ }
5734
+ const unmountRightPane = () => {
5735
+ if (rightPaneCleanup) {
5736
+ try { rightPaneCleanup() } catch {}
5737
+ }
5738
+ rightPaneCleanup = null
5739
+ rightPaneHost = null
5740
+ }
5741
+ const mountRightPane = () => {
5742
+ if (!canRegisterRightTab()) return
5743
+ if (rightPaneCleanup && rightPaneHost === hostSidebarRightTabs) return
5744
+ unmountRightPane()
5745
+ const disposers = []
5637
5746
  try {
5638
- return ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register({
5747
+ const disposeBody = ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register({
5639
5748
  name: 'sidebar.right.pane.tab', key: RIGHT_TAB_ID,
5640
5749
  }, SuperagentSessionPage))
5750
+ if (typeof disposeBody === 'function') disposers.push(disposeBody)
5641
5751
  } catch (error) {
5642
5752
  note('right-tab-fail', String((error && error.message) || error))
5643
- return undefined
5644
5753
  }
5645
- })
5646
- ctx.effect(() => {
5647
- if (!hostSidebarRightTabs || typeof hostSidebarRightTabs.register !== 'function') return undefined
5648
- return mountBrandEntry(() => ctx.slots.inject('sidebar.right.pane.tab.title', () => ctx.slots.register({
5754
+ const titleCleanup = mountBrandEntry(() => ctx.slots.inject('sidebar.right.pane.tab.title', () => ctx.slots.register({
5649
5755
  name: 'sidebar.right.pane.tab.title', key: RIGHT_TAB_ID,
5650
5756
  }, SuperagentRightTabTitle)), 'right-title-fail')
5757
+ if (titleCleanup) disposers.push(titleCleanup)
5758
+ if (!disposers.length) return
5759
+ rightPaneCleanup = () => {
5760
+ for (const dispose of disposers.reverse()) {
5761
+ try { dispose() } catch {}
5762
+ }
5763
+ }
5764
+ rightPaneHost = hostSidebarRightTabs
5765
+ }
5766
+ ctx.effect(() => {
5767
+ mountRightDefinition()
5768
+ mountRightPane()
5769
+ return () => {
5770
+ unmountRightDefinition()
5771
+ unmountRightPane()
5772
+ }
5651
5773
  })
5652
5774
  let headerRemount = null
5653
5775
  let headerCleanup = null
@@ -5676,35 +5798,49 @@ window.__ModuleLoader__.load({
5676
5798
  }
5677
5799
  })
5678
5800
 
5679
- // 真机上 sidebarRight 等宿主服务可能在本插件 apply 之后才就绪:此时
5680
- // ctx.get('sidebarRight') 是 undefined,头部会被误判成「服务不存在」永久禁用
5681
- // (2026-11-24 真机截图)。用 Cordis 的 ctx.inject 等它们就绪后重取,
5682
- // 再重挂一次入口 —— 服务已到位就用新状态渲染,不到位仍然是原来的降级。
5801
+ // 真机上 sidebarRight 等宿主服务可能在本插件 apply 之后才就绪,也可能在宿主 HMR 时
5802
+ // 被换成新实例:Cordis 的 ctx.inject(deps, cb) 是子插件 fiber —— 依赖到位时跑一次,
5803
+ // 依赖重建再跑。各入口的依赖要拆开:右栏 definition 只依赖 sidebarRightTabs,
5804
+ // 头部只依赖 sidebarRight,全局页只依赖 layout。把它们绑在同一个 inject 上,
5805
+ // 任一服务缺失/晚到就会连累其余入口(2.0.0 真机:sessions 缺失 → definition 永不注册)。
5806
+ const refreshHostServices = (scoped) => {
5807
+ const host = scoped && typeof scoped.get === 'function' ? scoped : ctx
5808
+ const nextRight = optionalHostService(host, 'sidebarRight')
5809
+ const nextTabs = optionalHostService(host, 'sidebarRightTabs')
5810
+ const nextSessions = optionalHostService(host, 'sessions')
5811
+ const nextLayout = optionalHostService(host, 'layout')
5812
+ const changed = nextRight !== hostSidebarRight || nextTabs !== hostSidebarRightTabs
5813
+ || nextSessions !== hostSessions || nextLayout !== hostLayout
5814
+ hostSidebarRight = nextRight
5815
+ hostSidebarRightTabs = nextTabs
5816
+ hostSessions = nextSessions
5817
+ if (nextLayout) hostLayout = nextLayout
5818
+ return changed
5819
+ }
5820
+ const onHostServicesReady = (scoped) => {
5821
+ const changed = refreshHostServices(scoped)
5822
+ // 顺序不能反:先补注册右栏 definition 与 body/title、补挂左栏全局页,
5823
+ // 再重挂头部 —— 头部渲染时按宿主注册表的真实内容决定是否可用(见 rightTabIssue)。
5824
+ mountRightDefinition()
5825
+ mountRightPane()
5826
+ mountGlobalEntries()
5827
+ if (changed) note('host-services-ready', '收到宿主导航服务,补挂右栏与头部入口')
5828
+ if (headerCleanup) {
5829
+ if (headerRemount) {
5830
+ try { headerRemount() } catch {}
5831
+ }
5832
+ } else {
5833
+ // apply 时服务全缺,头部当时根本没注册 —— 这里补挂。
5834
+ mountHeaderEntry()
5835
+ }
5836
+ }
5683
5837
  if (typeof ctx.inject === 'function') {
5684
- try {
5685
- ctx.inject(['sidebarRight', 'sidebarRightTabs', 'sessions'], (scoped) => {
5686
- const host = scoped && typeof scoped.get === 'function' ? scoped : ctx
5687
- const nextRight = optionalHostService(host, 'sidebarRight')
5688
- const nextTabs = optionalHostService(host, 'sidebarRightTabs')
5689
- const nextSessions = optionalHostService(host, 'sessions')
5690
- const nextLayout = optionalHostService(host, 'layout')
5691
- const changed = nextRight !== hostSidebarRight || nextTabs !== hostSidebarRightTabs
5692
- || nextSessions !== hostSessions || nextLayout !== hostLayout
5693
- hostSidebarRight = nextRight
5694
- hostSidebarRightTabs = nextTabs
5695
- hostSessions = nextSessions
5696
- if (nextLayout) hostLayout = nextLayout
5697
- if (!changed) return
5698
- note('host-services-ready', '收到 sidebarRight/sessions 服务,重挂头部与右栏入口')
5699
- if (headerCleanup && headerRemount) {
5700
- try { headerRemount() } catch {}
5701
- } else {
5702
- // apply 时服务全缺,头部当时根本没注册 —— 这里补挂。
5703
- mountHeaderEntry()
5704
- }
5705
- })
5706
- } catch (error) {
5707
- note('host-services-inject-fail', String((error && error.message) || error))
5838
+ for (const deps of [['sidebarRightTabs'], ['sidebarRight'], ['layout']]) {
5839
+ try {
5840
+ ctx.inject(deps, onHostServicesReady)
5841
+ } catch (error) {
5842
+ note('host-services-inject-fail', String((error && error.message) || error))
5843
+ }
5708
5844
  }
5709
5845
  }
5710
5846
 
package/lib/index.js CHANGED
@@ -70,7 +70,7 @@ import {
70
70
 
71
71
  export const name = 'dsh-session-superagent'
72
72
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
73
- export const SERVER_VERSION = '2.0.0'
73
+ export const SERVER_VERSION = '2.0.1'
74
74
  export const inject = ['tools', 'agents', 'webServer']
75
75
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
76
76
  // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "workspaces": [
5
5
  "packages/*"
6
6
  ],