Skip to content

feat(tui): 为 dsh-remote 增加 dsh-tui 界面(设置页 / 工作区 provider / 工作区清理) - #92

Merged
flymysql merged 2 commits into
flymysql:mainfrom
baiseraku:feat/dsh-tui-integration
Nov 6, 2026
Merged

flymysql merged 2 commits into
flymysql:mainfrom
baiseraku:feat/dsh-tui-integration

Conversation

@baiseraku

@baiseraku baiseraku commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

概要

给 dsh-remote 增加一层 dsh-tui 适配层:在终端里也能用同一份机器清单、SSH 池和远程工作区,不修改 dsh-tui 本体(全部通过它的插件接缝注册)。

主要能力:

  • /dsh-remote 全屏设置页:机器列表 / 新增编辑表单 / 连接、探测、浏览远端目录 / 设为工作区
  • 工作区 provider(dshremote://):/workspace 选择器里直接列出远程项目;支持 /workspace open dshremote://<机器>/<远端路径> 与启动参数
  • 工作区清理页(/dsh-remote → 机器菜单 → m):
    • d 彻底删除工作区:对话 → 工作区登记 → 每台机器的「最近工作区 / 当前工作区」→ 本地镜像目录($DSH_HOME/remote-workspaces/<host>-<user>-<port>/<name>)
    • x 只删该工作区下的对话(保留镜像与登记)
    • r 只把远端路径移出最近列表(不删镜像)
    • 有会话仍在使用时 d 会被拒绝,并提示先停止(进程内 sessions 服务 + POSIX session.lock 的 flock 探测)
  • 删除路径会同时清 recentWorkspaces / machine.workspace,否则 provider 下次启动会按最近列表把镜像重建回来(这就是「删了又出现」的根因)

改动

  • lib/host-api.js:ctx.dshRemote(apiVersion 1)在原有方法上新增 listWorkspaceMirrors / deleteWorkspaceSessions / deleteRemoteWorkspace / forgetWorkspaceRecent,新错误码 WORKSPACE_BUSY
  • lib/workspace-cleanup.js:镜像安全校验(realpath、恰好两层、.dsh-remote-meta.json)+ DSH 会话目录编码(projectKey / encodeSegment,与 @deepseek-ai/dsh-session-persistence-jsonl 一致)+ 扫描/删除
  • lib/index.js:isSessionLive / forgetRemotePath 接线;TUI 层 lazy import,Web/Desktop profile 不受影响
  • lib/tui/:场景、provider、i18n(中/英)、格式化
  • docs/tui.md:契约、cwd 语义、清理安全边界、限制;README.md / README.en.md 增加 TUI 章节
  • 测试:test/tui-*.test.js、test/workspace-cleanup.test.js、test/host-api.test.js 新增 cleanup 覆盖

验证

  • npm test:997 例,988 通过 / 9 skip / 0 fail
  • node check.mjs:通过
  • 真实 TUI(PTY 驱动)跑通:/dsh-remote 打开、菜单 m、d/x/r 三条删除路径、占用中删除被拒绝并提示;Esc/←/→ 层级导航正常

兼容性 / 限制

  • 只删本地镜像与会话日志,不动远端目录(远端删除需要另一条带二次确认的 SSH 路径)
  • TUI 的 ctx.tuiWorkspaces 不在 dsh-tui 的「冻结接缝」列表里,属于实验面;provider 不可用时设置页仍可用
  • 占用探测在 Windows 上没有 lsof,只能依赖进程内检查(文档已注明)
  • apiVersion 仍为 1:新增方法属于向后兼容的扩展;如果希望升版本请指出

关于 PR 大小

按 CONTRIBUTING「一个 PR 一个逻辑改动 / 重大改动先开 issue」的建议:这个 PR 确实偏大(整个 TUI 适配层 + 清理功能一起)。如果更希望拆成「TUI 基础层」和「工作区清理」两个 PR,或先开 issue 讨论设计,我可以按你的偏好调整。已转为 Ready for review;CI 首次运行需要维护者批准 workflow 后才会执行。

@baiseraku
baiseraku marked this pull request as ready for review November 4, 2026 17:20
baiseraku and others added 2 commits November 6, 2026 16:23
Adds a terminal adaptation layer that registers through dsh-tui's plugin
seams (ctx.tuiScenes / ctx.tuiWorkspaces / ctx.tuiStatus / ctx.commands)
without patching dsh-tui itself:

- /dsh-remote full-screen scene: machine list, add/edit form, connect/probe/
  browse, use-as-workspace, and a workspace-cleanup page.
- workspace provider (dshremote://): lists existing mirrors, the current
  machine workspace and (optionally) each machine's recent projects; resolves
  URIs back into local mirror dirs; describe() stays local-only.
- in-process host API ctx.dshRemote (apiVersion 1) shaped as pure data with
  semantic error codes; secrets never leave the host.
- workspace cleanup: permanently delete a remote workspace (its chats, the
  workspace registration, the recent/current path so the provider cannot
  recreate it, and the local mirror) or only its chats; busy sessions are
  detected via the sessions service plus a POSIX flock probe and refused.
- docs/tui.md (contract + behaviour + limits), README zh/en sections, i18n
  zh/en, and tests for the host API, provider, scene rendering/keymaps and
  the cleanup path rules.

TUI files are untouched; lib/tui is lazy-loaded so a Web/Desktop profile
keeps working even if the directory is absent.
… stale version refs

Maintainer review pass on the rebase:

- provider.refresh() now ensures mirrors with register:false — merely opening
  the /workspace picker must not write the user's global workspace registry;
  registration happens in resolve()/resolvePath() when a target is actually
  picked. (Two refresh tests re-pinned accordingly.)
- new test/tui-flow.test.js drives runDialogFlow through scripted dialog
  answers: connect/Esc/decline/validation-error branches and the add-machine
  wizard for all three auth modes. lib/tui/flow.js 33% -> 100% lines, clearing
  the 60% per-file coverage gate the CI test leg enforced.
- check.mjs / sync.sh: the '0.8.73' reference predates the release numbering;
  0.8.73 shipped as the remote-shell fix, so the comment now just says 'the
  TUI integration'.
@flymysql
flymysql force-pushed the feat/dsh-tui-integration branch from 5252303 to 3f70e5d Compare November 6, 2026 12:34
@flymysql

flymysql commented Nov 6, 2026

Copy link
Copy Markdown
Owner

感谢这份高质量的 PR——契约文档、错误码设计、安全边界(realpath + 恰好两层 + meta 标记 + WORKSPACE_BUSY 占用拒绝)都做得很扎实。我已经把它推进到可合状态,几处需要你知悉:

前提核实:ctx.tuiScenes / tuiWorkspaces / tuiStatus / tuiDialogs 四个接缝我逐一验证过真实存在(目标是 @deepseek-harness-tui/dsh-tui,当前 latest 0.18.0;注意不要和同名的 dsh-tui 包混淆,后者没有这些接缝)。whenService 避开硬 inject 的做法也对——上游 update.js 里明确记着硬 inject tuiWorkspaces 会把 boot 死锁在 pending。

我直接推到本分支的修改(rebase 到最新 main + 三处评审修正,你的原始提交完整保留):

  1. 解冲突:main 在你分支后又合入了 fix(sshconfig): expand IdentityFile tokens, honor .pub agent identities and IdentityAgent #90(sshconfig 的 agentSocket/identitiesOnly),正好落在你抽取走的探测路由体里。解法:保留你的 probeMachineRecord 抽取,把那两行移植进抽取后的闭包。
  2. picker 副作用收窄(唯一的行为变更):provider.refresh() 原先对每个「最近工作区」都 ensureRemoteWorkspace({register:true})——用户只是打开 /workspace 选择器看一眼,就会把每台机器最多 5 条最近工作区写进全局工作区台账。现在 refresh 路径传 register:false,真正选中(resolve/resolvePath)才登记。两例测试相应改钉。如果你有意让「列出即登记」,我们可以再讨论,但我倾向窄一点。
  3. 覆盖率门槛:CI 的 test 腿挂在 lib/tui/flow.js 33% < 60% floor。补了 test/tui-flow.test.js(14 例:连接/取消/拒连/幽灵机器/异常收敛 + 三种认证的新建向导全流程 + 校验失败不落库),现在 flow.js 100% 行覆盖,两门(81.4% ≥ 70%、逐文件地板)本地全绿。
  4. 顺手把 check.mjs / sync.sh 注释里「自 0.8.73 起」的过期说法改掉(0.8.73 已经是另一个修复的版本号)。

关于拆 PR:不用拆了。TUI 基础层和工作区清理在同一个用户旅程里(清理页就从场景里进),拆开反而各自不完整;CONTRIBUTING 那条主要是防「顺手捎带无关改动」,你这个是一个逻辑改动。

遗留观察(不阻塞):

  • deleteRemoteWorkspace 是会话→登记→最近列表→镜像的顺序删除,中途失败会留下部分完成的现场(报告里如实反映)。可接受,但值得在 docs/tui.md 里点一句。
  • Windows 占用探测只有进程内检查(无 lsof),你已注明;后续可考虑读 session.lock 的存在性作弱信号。

CI 绿了就 squash 合入(保持你的作者归属)。

@flymysql
flymysql merged commit edf762c into flymysql:main Nov 6, 2026
3 checks passed
flymysql pushed a commit that referenced this pull request Nov 7, 2026
…sue #93)

The picker's position:fixed overlay rendered inline in the slot's React subtree,
where the 0.2.2 conversation container traps pointer events — the dialog painted
but every click fell through to the chat text in existing sessions (the hero
page has no such container, hence 'new session works'). The host's own Modal/Menu
portal to body; now the picker does ReactDOM.createPortal(overlay, document.body)
too, with the inline overlay kept as the fallback when react-dom is absent from
the shared module map. Our context menu already used this technique.

Also ships the dsh-tui adaptation layer from PR #92 (@baiseraku): /dsh-remote
scene, dshremote:// workspace provider, workspace cleanup page.

Tests: issue93 portal-vs-fallback pair (2), full suite 1028, check.mjs clean,
coverage gates green.
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