Skip to content

fix(tui): 底栏机器名只在远程工作区会话中显示(含悬停详情) - #98

Merged
flymysql merged 1 commit into
flymysql:mainfrom
baiseraku:fix/tui-status-remote-only
Nov 8, 2026
Merged

flymysql merged 1 commit into
flymysql:mainfrom
baiseraku:fix/tui-status-remote-only

Conversation

@baiseraku

Copy link
Copy Markdown
Contributor

问题

在本地目录使用 dsh-tui 时,底栏一直显示远程机器名(例如 group/gpt-auto · 缓存 99.5% · shpc-116139-instance-… · DSH),让人以为当前会话是远程的。

原因:lib/tui/index.js 的底栏字段只读 machines.json 的 currentId,把「保存成 current 的机器」当成「正在用的机器」。

第一版修复尝试按 api.status().connected 判断,但插件启动时会 auto-restore 当前机器并 echo 探活(lib/index.js 的 auto-restore 块),connected 实际恒为 true,等于没改。

方案

底栏改为跟随当前 TUI 会话的 cwd:只有它的 cwd 解析到 $DSH_HOME/remote-workspaces/<host>-<user>-<port>/<name> 下的镜像时,才显示该镜像所属机器;本地会话清空字段。

「当前会话」的判定顺序(TUI 一个进程可同时挂载多个会话):

  1. 宿主每次切换会话后传给 provider.describe() 的 cwd —— 只采信确实属于某个 live 会话的那个(session/* 事件覆盖不到“切到已挂载会话”);
  2. 最近进入 store / 最近发过 user/message 的会话;
  3. store 里最后进入的会话。

header.origin === 'subagent' 的子代理会话一律排除(子代理也会进 store、也会发 user/message,且可带独立 cwd)。session/created / session/disposed / user/message / 终端 resize 触发 500ms 合并刷新。

悬停详情(与其它底栏字段同一效果):完整机器名 · user@host:port · 远端路径。宿主只按 160 cells 截断 detail、再按可用宽度 wrap(不 truncate),所以插件自己按 process.stdout.columns - 18 裁成单行(状态行内宽 columns-2,再给右侧 MiniWake/activity 预留),CJK / emoji 记 2 格,超宽以 … 结尾,并在 resize 后重裁。

改动

  • lib/tui/index.js:会话判定 / 事件订阅 / 字段写入 / 宽度裁剪 / 卸载与竞态保护
  • lib/tui/provider.js:describe() 回传当前 cwd;导出 matchMachineForMirror() 供底栏与 provider 共用(含 ssh-config 别名机)
  • lib/tui/format.js:displayWidth() / clipCells()
  • lib/tui/i18n.js:悬停详情中英文案
  • test/tui-install.test.js / test/tui-format.test.js:本地 / 远程 / 切换 / 子代理 / describe 提示 / 别名机 / 降级 / 去重 / 宽度用例
  • docs/tui.md:状态行规则、悬停与宽度预算

验证

  • npm test:1052 例 / 1043 通过 / 9 skip / 0 fail
  • node check.mjs:OK
  • 真实 dsh-tui(PTY 驱动):本地目录无机器名;远程镜像目录显示机器名;160 列悬停详情完整单行,80 列自动 … 截断

兼容性 / 限制

  • 只改插件,不改 dsh-tui 本体。
  • 宿主没有 sessions 服务(旧组合)时退回旧行为;有服务但读失败时隐藏,不显示过期机器名。
  • “切到已挂载会话”的实时性依赖宿主在切换时调用 provider.describe(cwd)(当前 dsh-tui 实现会调);没有这个调用的宿主上,退化为事件/输入驱动的近似判定。
  • 只影响底栏展示,不改变连接、工作区解析或清理逻辑。
  • 未包含版本号与 CHANGELOG 条目(与 feat(tui): 为 dsh-remote 增加 dsh-tui 界面(设置页 / 工作区 provider / 工作区清理) #92 一致,由发布流程统一写)。

The footer field used to show whichever machine was persisted as current, so
a local session still displayed the remote server name. The first attempt
gated on `status().connected`, but the plugin auto-restores that machine at
boot and probes it (lib/index.js), so `connected` is effectively always true.

The field now follows the session's cwd: it is written only while the session
the user is looking at resolves to a mirror under
`$DSH_HOME/remote-workspaces`, and cleared for local sessions. The active
session is the cwd the host hands to `provider.describe()` on every session
switch (validated against live sessions), with session events as fallback;
subagent sessions (`header.origin === 'subagent'`) are skipped. Hovering the
field shows the full machine name, `user@host:port` and the remote path,
clipped to one line for the current terminal width (CJK/emoji measured as two
cells) and re-clipped on resize.

The provider and the footer now share one mirror->machine matcher, including
ssh-config aliases. A missing sessions service keeps the legacy behaviour; a
failing one hides the field instead of reviving the stale name.
@baiseraku
baiseraku force-pushed the fix/tui-status-remote-only branch from 1589054 to 8f6a879 Compare November 8, 2026 06:59
@baiseraku

Copy link
Copy Markdown
Contributor Author

第一次 run 的 test-windows 挂在 test/sshconfig-agent-identity.test.js(getPublicSSH is not a function),与本次改动无关;上游 main 的 run 42450461190 在同一个文件上以同样方式失败过,属于既有 flake。无 admin 权限无法 rerun,已用空 amend 重新触发 CI,现在三条腿全绿:test 1m54s / test-macos 53s / test-windows 2m31s。

@flymysql
flymysql merged commit 199fb4d into flymysql:main Nov 8, 2026
3 checks passed
flymysql pushed a commit that referenced this pull request Nov 8, 2026
@flymysql

flymysql commented Nov 8, 2026

Copy link
Copy Markdown
Owner

评审通过并已合入发布(v0.8.80)。几处做得特别好的点:cwd 三级采信 + describe 提示交叉校验、「读不到就隐藏而不是留旧名」的失败方向、500ms 合并刷新、CJK 宽度裁切、相同值不重写字段。一个非阻塞观察记下即可:session/event 的 (session, event) 形状依赖 dsh-tui 当前事件分类法,将来上游若改名,最坏结果是底栏退化到近似判定,不致出错——docs/tui.md 里已经写清了依赖面,够了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants