dsh-remote 0.8.91 → 0.8.92

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.
Files changed (139) hide show
  1. package/README.en.md +1 -0
  2. package/README.md +1 -0
  3. package/lib/client.js +161 -64
  4. package/lib/credential.js +7 -0
  5. package/lib/index.js +125 -31
  6. package/lib/openssh.js +60 -1
  7. package/lib/pool.js +127 -68
  8. package/lib/posix-shell.cjs +34 -0
  9. package/lib/remote-shell-child.cjs +8 -11
  10. package/lib/remote-skills.js +312 -0
  11. package/lib/routes-fs.js +6 -0
  12. package/lib/routes-misc.js +38 -1
  13. package/lib/web-attach.js +17 -7
  14. package/package.json +11 -8
  15. package/node_modules/buildcheck/.eslintrc.js +0 -5
  16. package/node_modules/buildcheck/.github/workflows/ci.yml +0 -88
  17. package/node_modules/buildcheck/.github/workflows/lint.yml +0 -27
  18. package/node_modules/buildcheck/.npmignore +0 -3
  19. package/node_modules/buildcheck/LICENSE +0 -19
  20. package/node_modules/buildcheck/README.md +0 -106
  21. package/node_modules/buildcheck/deps/Find-VisualStudio.cs +0 -250
  22. package/node_modules/buildcheck/lib/findvs.js +0 -361
  23. package/node_modules/buildcheck/lib/index.js +0 -738
  24. package/node_modules/buildcheck/package.json +0 -36
  25. package/node_modules/buildcheck/test/test.js +0 -8
  26. package/node_modules/cpu-features/.eslintrc.js +0 -5
  27. package/node_modules/cpu-features/.github/workflows/ci.yml +0 -74
  28. package/node_modules/cpu-features/.github/workflows/lint.yml +0 -27
  29. package/node_modules/cpu-features/LICENSE +0 -19
  30. package/node_modules/cpu-features/README.md +0 -59
  31. package/node_modules/cpu-features/binding.gyp +0 -16
  32. package/node_modules/cpu-features/buildcheck.js +0 -32
  33. package/node_modules/cpu-features/deps/cpu_features/.clang-format +0 -4
  34. package/node_modules/cpu-features/deps/cpu_features/.dockerignore +0 -31
  35. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/Dockerfile +0 -5
  36. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/aarch64_linux_cmake.yml +0 -30
  37. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_freebsd_cmake.yml +0 -22
  38. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_linux_bazel.yml +0 -26
  39. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_linux_cmake.yml +0 -31
  40. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_macos_cmake.yml +0 -43
  41. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_windows_cmake.yml +0 -25
  42. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/arm_linux_cmake.yml +0 -31
  43. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/clang_format.yml +0 -24
  44. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/mips_linux_cmake.yml +0 -30
  45. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/power_linux_cmake.yml +0 -29
  46. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/riscv_linux_cmake.yml +0 -28
  47. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/s390x_linux_cmake.yml +0 -27
  48. package/node_modules/cpu-features/deps/cpu_features/.grenrc.yml +0 -21
  49. package/node_modules/cpu-features/deps/cpu_features/BUILD.bazel +0 -329
  50. package/node_modules/cpu-features/deps/cpu_features/CMakeLists.txt +0 -261
  51. package/node_modules/cpu-features/deps/cpu_features/CONTRIBUTING.md +0 -23
  52. package/node_modules/cpu-features/deps/cpu_features/LICENSE +0 -230
  53. package/node_modules/cpu-features/deps/cpu_features/README.md +0 -272
  54. package/node_modules/cpu-features/deps/cpu_features/WORKSPACE +0 -19
  55. package/node_modules/cpu-features/deps/cpu_features/bazel/ci/README.md +0 -5
  56. package/node_modules/cpu-features/deps/cpu_features/bazel/platforms.bzl +0 -11
  57. package/node_modules/cpu-features/deps/cpu_features/cmake/CpuFeaturesConfig.cmake.in +0 -3
  58. package/node_modules/cpu-features/deps/cpu_features/cmake/CpuFeaturesNdkCompatConfig.cmake.in +0 -3
  59. package/node_modules/cpu-features/deps/cpu_features/cmake/README.md +0 -30
  60. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/Makefile +0 -252
  61. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/README.md +0 -40
  62. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/docker.dot +0 -64
  63. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/docker.svg +0 -312
  64. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/generate_image.sh +0 -7
  65. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/docker/amd64/Dockerfile +0 -48
  66. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/docker/toolchain/Dockerfile +0 -34
  67. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/sample/CMakeLists.txt +0 -22
  68. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/sample/main.cpp +0 -11
  69. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/vagrant/freebsd/Vagrantfile +0 -107
  70. package/node_modules/cpu-features/deps/cpu_features/cmake/googletest.CMakeLists.txt.in +0 -15
  71. package/node_modules/cpu-features/deps/cpu_features/cpu_features.gyp +0 -105
  72. package/node_modules/cpu-features/deps/cpu_features/include/cpu_features_cache_info.h +0 -54
  73. package/node_modules/cpu-features/deps/cpu_features/include/cpu_features_macros.h +0 -384
  74. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_aarch64.h +0 -259
  75. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_arm.h +0 -121
  76. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_mips.h +0 -74
  77. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_ppc.h +0 -149
  78. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_riscv.h +0 -72
  79. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_s390x.h +0 -108
  80. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_x86.h +0 -288
  81. package/node_modules/cpu-features/deps/cpu_features/include/internal/bit_utils.h +0 -40
  82. package/node_modules/cpu-features/deps/cpu_features/include/internal/cpuid_x86.h +0 -37
  83. package/node_modules/cpu-features/deps/cpu_features/include/internal/filesystem.h +0 -39
  84. package/node_modules/cpu-features/deps/cpu_features/include/internal/hwcaps.h +0 -240
  85. package/node_modules/cpu-features/deps/cpu_features/include/internal/stack_line_reader.h +0 -49
  86. package/node_modules/cpu-features/deps/cpu_features/include/internal/string_view.h +0 -110
  87. package/node_modules/cpu-features/deps/cpu_features/include/internal/windows_utils.h +0 -70
  88. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/CMakeLists.txt +0 -60
  89. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/README.md +0 -4
  90. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/cpu-features.c +0 -205
  91. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/cpu-features.h +0 -320
  92. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/ndk-compat-test.c +0 -12
  93. package/node_modules/cpu-features/deps/cpu_features/patches/0001-Add-Apple-Silicon-Support.patch +0 -456
  94. package/node_modules/cpu-features/deps/cpu_features/scripts/generate_badges.d +0 -165
  95. package/node_modules/cpu-features/deps/cpu_features/scripts/make_release.sh +0 -75
  96. package/node_modules/cpu-features/deps/cpu_features/scripts/run_integration.sh +0 -490
  97. package/node_modules/cpu-features/deps/cpu_features/scripts/test_integration.sh +0 -79
  98. package/node_modules/cpu-features/deps/cpu_features/src/copy.inl +0 -19
  99. package/node_modules/cpu-features/deps/cpu_features/src/define_introspection.inl +0 -86
  100. package/node_modules/cpu-features/deps/cpu_features/src/define_introspection_and_hwcaps.inl +0 -26
  101. package/node_modules/cpu-features/deps/cpu_features/src/equals.inl +0 -22
  102. package/node_modules/cpu-features/deps/cpu_features/src/filesystem.c +0 -62
  103. package/node_modules/cpu-features/deps/cpu_features/src/hwcaps.c +0 -169
  104. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64__base_implementation.inl +0 -88
  105. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_linux_or_android.c +0 -79
  106. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_macos_or_iphone.c +0 -82
  107. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_windows.c +0 -138
  108. package/node_modules/cpu-features/deps/cpu_features/src/impl_arm_linux_or_android.c +0 -212
  109. package/node_modules/cpu-features/deps/cpu_features/src/impl_mips_linux_or_android.c +0 -93
  110. package/node_modules/cpu-features/deps/cpu_features/src/impl_ppc_linux.c +0 -163
  111. package/node_modules/cpu-features/deps/cpu_features/src/impl_riscv_linux.c +0 -111
  112. package/node_modules/cpu-features/deps/cpu_features/src/impl_s390x_linux.c +0 -120
  113. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86__base_implementation.inl +0 -2055
  114. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_freebsd.c +0 -68
  115. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_linux_or_android.c +0 -58
  116. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_macos.c +0 -57
  117. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_windows.c +0 -58
  118. package/node_modules/cpu-features/deps/cpu_features/src/stack_line_reader.c +0 -132
  119. package/node_modules/cpu-features/deps/cpu_features/src/string_view.c +0 -192
  120. package/node_modules/cpu-features/deps/cpu_features/src/utils/list_cpu_features.c +0 -461
  121. package/node_modules/cpu-features/deps/cpu_features/test/CMakeLists.txt +0 -114
  122. package/node_modules/cpu-features/deps/cpu_features/test/bit_utils_test.cc +0 -53
  123. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_aarch64_test.cc +0 -396
  124. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_arm_test.cc +0 -384
  125. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_mips_test.cc +0 -176
  126. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_ppc_test.cc +0 -131
  127. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_riscv_test.cc +0 -180
  128. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_s390x_test.cc +0 -82
  129. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_x86_test.cc +0 -1729
  130. package/node_modules/cpu-features/deps/cpu_features/test/filesystem_for_testing.cc +0 -103
  131. package/node_modules/cpu-features/deps/cpu_features/test/filesystem_for_testing.h +0 -61
  132. package/node_modules/cpu-features/deps/cpu_features/test/hwcaps_for_testing.cc +0 -52
  133. package/node_modules/cpu-features/deps/cpu_features/test/hwcaps_for_testing.h +0 -31
  134. package/node_modules/cpu-features/deps/cpu_features/test/stack_line_reader_test.cc +0 -132
  135. package/node_modules/cpu-features/deps/cpu_features/test/string_view_test.cc +0 -202
  136. package/node_modules/cpu-features/lib/index.js +0 -5
  137. package/node_modules/cpu-features/package.json +0 -40
  138. package/node_modules/cpu-features/src/binding.cc +0 -151
  139. package/node_modules/cpu-features/test/test.js +0 -12
package/README.en.md CHANGED
@@ -61,6 +61,7 @@ The rest:
61
61
  - **Tell local and remote Sessions apart in the sidebar** (`0.8.43+`) — a remote Session row carries a **green dot** and its hover card names `user@host:port` plus the remote path; opening it also shows a host chip in the conversation header (a local Session shows neither). A Session counts as remote only when its cwd sits inside a `$DSH_HOME/remote-workspaces/…` mirror, so a machine that is merely saved never labels a local Session.
62
62
  - **A terminal in a remote Session opens on the remote host out of the box** (`0.8.75+`) — the shell menu's **remote ssh** entry routes by cwd (a mirror cwd → ssh into the remote workspace; anything else → transparent local-shell fallback), and it is the **default shell** whenever neither the host nor you picked one. Saved passwords are answered through the local credential bridge (`0.8.81+`, including OS-keychain ones) — no more `password:` prompt every time a terminal opens.
63
63
  - **Remote file previews have line numbers and syntax highlighting** (`0.8.86+`) — code files render through the host's own Shiki engine, and chat links carrying `file:line` (or `#L<n>`) land on that line with a flash.
64
+ - **Remote project skills need no prior sync** (issue #120) — `.dsh/skills` and `.agents/skills` on a remote workspace appear in the DSH skill catalog, including directory bundles and top-level Markdown files; full bodies load over SFTP on demand, and the remote candidate wins a same-named stale mirror copy. Resolve adjacent resources with `rw_list_dir` / `rw_read_file`. Writes, pushes and autoPush invalidate the catalog immediately; background/external edits are covered by a five-minute **invalidate-only** timer that performs no SFTP traffic of its own. Ordinary local Sessions keep the host's original skill discovery.
64
65
  - **Open a remote machine's DSH Web UI locally** (`0.8.36+`) — nothing has to be exposed on the remote: the plugin SSHes out, starts a `dsh web` there that binds **`127.0.0.1` only**, and tunnels its port back to a loopback port on this machine. The URL carries a one-time login token, consumed once by a redirect.
65
66
  - **The audit log opens locally** — preview recent entries in the panel, or use 「打开日志文件」/「在文件夹中显示」 to open the log with a local program (the log lives on the DSH host, so a browser cannot open it).
66
67
  - **Cross-platform remotes** — all file access is SFTP-protocol-level (no POSIX shell), so Linux/macOS/Windows remotes all work.
package/README.md CHANGED
@@ -50,6 +50,7 @@ DSH 的 Web 界面刻意只监听 `127.0.0.1`(CLI 为安全拒绝 `--host 0.0.
50
50
  - **会话列表里区分本地/远程**(`0.8.43+`)—— 远程会话的行首有一个**绿点**,悬停显示 `user@host:port` 与远端路径;打开该会话后,标题栏还会常显一个主机标签(本地会话两者都没有)。判定只看会话 cwd 是否落在 `$DSH_HOME/remote-workspaces/…` 镜像里,所以「保存过但没在用」的机器不会给本地会话打标。
51
51
  - **远程会话的终端开箱即在远端**(`0.8.75+`)—— 侧栏终端的 shell 菜单里有插件贡献的 **remote ssh**:按 cwd 智能路由(远程镜像 → `ssh` 进远端工作目录;本地会话 → 自动回落本地 shell),在没人占位时它还是**默认 shell**。已保存的密码由本机凭据桥自动应答(`0.8.81+`,含操作系统钥匙串里的),不会再每次开终端都问一遍 `password:`。
52
52
  - **远程文件预览带行号与语法高亮**(`0.8.86+`)—— 代码文件用宿主自家的 Shiki 引擎着色;AI 回答里的 `文件:行号`(或 `#L行号`)链接点开直接落到那一行并闪烁提示。
53
+ - **远程项目技能无需先同步**(issue #120)—— 远程工作区的 `.dsh/skills` 与 `.agents/skills` 会直接进入 DSH 技能目录,支持目录型 `SKILL.md` 和顶层 `.md`,完整正文按需经 SFTP 加载;同名时远端内容优先于本地镜像副本。技能里引用相邻资源时用 `rw_list_dir` / `rw_read_file` 读取。写入、推送、autoPush 会立即失效目录缓存;后台或外部进程的修改由每 5 分钟一次的**只失效、不联网**刷新兜底,不会制造定时 SFTP 流量。普通本地会话仍只使用宿主原有技能目录。
53
54
  - **把远端机器的 DSH 界面挂到本机**(`0.8.36+`)—— 不用在远端开任何端口:插件主动 SSH 连过去,在远端**只监听 `127.0.0.1`** 地起一个 `dsh web`,再把端口经隧道搬回本机的一个 loopback 端口。地址带一次性登录令牌,只在本机这次跳转里用一次。
54
55
  - **审计日志可以在本机直接打开** —— 面板里预览最近条目,另有「打开日志文件」「在文件夹中显示」直接调用本机程序打开那个日志(日志在运行 DSH 的机器上,浏览器打不开它)。
55
56
  - **远端跨平台** —— 文件访问走 SFTP 协议层(不依赖 POSIX shell),Linux/macOS/Windows 远端都能列/读/写/搜索/同步。
package/lib/client.js CHANGED
@@ -1360,15 +1360,21 @@ window.__ModuleLoader__.load({
1360
1360
  // Mirrors the host default (DEFAULT_UPDATE_MODE = 'auto') so the panel
1361
1361
  // does not flash "manual" before the first /update-check answers.
1362
1362
  const [updMode, setUpdMode] = React.useState('auto')
1363
- // Issue #78: initial value comes from localStorage, so a user's choice
1364
- // survives restarts (the bug was: the panel popped again every restart).
1363
+ // Render the local fallback immediately, then reconcile the shared host
1364
+ // value. The auto-open paths await the SAME promise, so a slow false never
1365
+ // arrives after an eager openTab.
1365
1366
  const [explorerAuto, setExplorerAuto] = React.useState(() => explorerAutoOpenEnabled())
1367
+ React.useEffect(() => {
1368
+ let cancelled = false
1369
+ explorerAutoOpenPreference().then((on) => { if (!cancelled) setExplorerAuto(on) })
1370
+ return () => { cancelled = true }
1371
+ }, [])
1366
1372
  // One applier per toggle, shared by the native-checkbox fallback (event
1367
1373
  // semantics) and the host Switch (bare-boolean callback), so both paths
1368
1374
  // behave identically.
1369
1375
  const applyExplorerAutoOpen = (on) => {
1370
1376
  setExplorerAuto(on)
1371
- try { window.localStorage.setItem(EXPLORER_AUTO_OPEN_KEY, on ? '1' : '0') } catch { /* private mode: choice lasts this session only */ }
1377
+ void updateExplorerAutoOpenPreference(on)
1372
1378
  }
1373
1379
  const checkUpdate = (quiet) => {
1374
1380
  if (updBusy) return
@@ -2986,17 +2992,62 @@ window.__ModuleLoader__.load({
2986
2992
  // resource type, never a better-sidebar card (see registerSidebarIntegration).
2987
2993
  const SIDEBAR_EXPLORER_ID = 'dsh-remote:explorer'
2988
2994
 
2989
- // Issue #78: durable opt-out for the sidebar auto-open. The in-memory
2990
- // autoOpenedFor set forgetting across restarts is by design; THIS key is
2991
- // the user's persistent "别再给我弹远程文件面板". Browser-local because the
2992
- // feature itself is browser-local. Default ON preserves the behaviour
2993
- // existing users know — only an explicit uncheck turns it off.
2995
+ // Issue #78 + #119: durable opt-out for BOTH sidebar worlds. localStorage
2996
+ // remains a fallback/migration source, but it is origin-scoped and tether can
2997
+ // give the same DSH_HOME a fresh origin. The host file is authoritative once
2998
+ // set; the first auto-open waits for this shared value instead of racing a
2999
+ // late `enabled:false` and popping the panel before it arrives.
2994
3000
  const EXPLORER_AUTO_OPEN_KEY = 'dsh-remote:explorerAutoOpen'
2995
- function explorerAutoOpenEnabled() {
3001
+ const EXPLORER_AUTO_OPEN_ROUTE = '/dsh-remote/explorer-auto-open'
3002
+ let explorerAutoEffective = true
3003
+ let explorerAutoPreferencePromise = null
3004
+ let explorerAutoPreferenceRevision = 0
3005
+ function localExplorerAutoOpenPreference() {
2996
3006
  try {
2997
- if (typeof window === 'undefined' || !window.localStorage) return true
2998
- return window.localStorage.getItem(EXPLORER_AUTO_OPEN_KEY) !== '0'
2999
- } catch { return true }
3007
+ if (typeof window === 'undefined' || !window.localStorage) return null
3008
+ const value = window.localStorage.getItem(EXPLORER_AUTO_OPEN_KEY)
3009
+ return value === '0' ? false : value === '1' ? true : null
3010
+ } catch { return null }
3011
+ }
3012
+ explorerAutoEffective = localExplorerAutoOpenPreference() ?? true
3013
+ function explorerAutoOpenEnabled() { return explorerAutoEffective }
3014
+ function explorerAutoOpenPreference() {
3015
+ if (explorerAutoPreferencePromise) return explorerAutoPreferencePromise
3016
+ const revision = explorerAutoPreferenceRevision
3017
+ const local = localExplorerAutoOpenPreference()
3018
+ if (local !== null) explorerAutoEffective = local
3019
+ explorerAutoPreferencePromise = api('GET', EXPLORER_AUTO_OPEN_ROUTE).then((r) => {
3020
+ // A user click after this request started always wins over its response.
3021
+ if (revision !== explorerAutoPreferenceRevision) return explorerAutoEffective
3022
+ if (r && typeof r.enabled === 'boolean') {
3023
+ if (r.persisted === true) {
3024
+ explorerAutoEffective = r.enabled
3025
+ } else if (local !== null) {
3026
+ // Upgrade path: the host has no explicit choice yet. Carry this
3027
+ // origin's old value into DSH_HOME; a failed migration still leaves
3028
+ // the local fallback in force for this run.
3029
+ explorerAutoEffective = local
3030
+ void api('POST', EXPLORER_AUTO_OPEN_ROUTE, { enabled: local }).catch(() => {})
3031
+ } else {
3032
+ explorerAutoEffective = r.enabled
3033
+ }
3034
+ } else if (local !== null) {
3035
+ explorerAutoEffective = local
3036
+ }
3037
+ return explorerAutoEffective
3038
+ }).catch(() => {
3039
+ // Host unreachable is not permission to ignore an explicit local OFF.
3040
+ if (revision === explorerAutoPreferenceRevision && local !== null) explorerAutoEffective = local
3041
+ return explorerAutoEffective
3042
+ })
3043
+ return explorerAutoPreferencePromise
3044
+ }
3045
+ function updateExplorerAutoOpenPreference(on) {
3046
+ explorerAutoPreferenceRevision++
3047
+ explorerAutoEffective = on
3048
+ try { window.localStorage.setItem(EXPLORER_AUTO_OPEN_KEY, on ? '1' : '0') } catch { /* session-only fallback */ }
3049
+ // Keep a working local fallback if the host is temporarily unreachable.
3050
+ return api('POST', EXPLORER_AUTO_OPEN_ROUTE, { enabled: on }).catch(() => null)
3000
3051
  }
3001
3052
 
3002
3053
  function fetchRemoteStatus(sessionId) {
@@ -3106,6 +3157,36 @@ window.__ModuleLoader__.load({
3106
3157
  }
3107
3158
  return best
3108
3159
  }
3160
+ // Server identity colors are independent of SSH health and workspace path.
3161
+ // Persist allocations per browser so adding a server never recolors old ones.
3162
+ const serverPalette = ['#5489d8', '#a579d5', '#d99a45', '#49a5ab', '#d8799c', '#858ed2', '#91a650', '#c5825c']
3163
+ const serverColorKey = 'dsh-remote.server-colors.v1'
3164
+ let serverColors = {}
3165
+ try {
3166
+ const saved = JSON.parse(localStorage.getItem(serverColorKey) || '{}')
3167
+ if (saved && typeof saved === 'object' && !Array.isArray(saved)) {
3168
+ for (const [key, value] of Object.entries(saved)) {
3169
+ if (/^#[0-9a-f]{6}$/i.test(value)) serverColors[key] = value
3170
+ }
3171
+ }
3172
+ } catch { /* storage may be unavailable */ }
3173
+ function mirrorColor(m) {
3174
+ // Ignore username: two accounts on the same endpoint are one server.
3175
+ const key = JSON.stringify([String(m.host || '').trim().toLowerCase(), Number(m.port) || 22])
3176
+ if (serverColors[key]) return serverColors[key]
3177
+ let hash = 2166136261
3178
+ for (let i = 0; i < key.length; i++) hash = Math.imul(hash ^ key.charCodeAt(i), 16777619) >>> 0
3179
+ const used = new Set(Object.values(serverColors))
3180
+ const start = hash % serverPalette.length
3181
+ let color = serverPalette[start]
3182
+ for (let i = 0; i < serverPalette.length; i++) {
3183
+ const candidate = serverPalette[(start + i) % serverPalette.length]
3184
+ if (!used.has(candidate)) { color = candidate; break }
3185
+ }
3186
+ serverColors[key] = color
3187
+ try { localStorage.setItem(serverColorKey, JSON.stringify(serverColors)) } catch { /* memory fallback */ }
3188
+ return color
3189
+ }
3109
3190
  /** `user@host:port` for a mirror record (port omitted when it is 22). */
3110
3191
  function mirrorTarget(m) {
3111
3192
  if (!m) return ''
@@ -3154,8 +3235,8 @@ window.__ModuleLoader__.load({
3154
3235
  return mirrorForCwd(cwd, MIRRORS.list)
3155
3236
  }
3156
3237
 
3157
- // Leading seat of a Session row: the 16px cell before the title. A green dot
3158
- // means "this session works on a remote host"; a local session renders
3238
+ // Leading seat of a Session row: the 16px cell before the title. A colored dot
3239
+ // identifies the remote server (not connection health); a local session renders
3159
3240
  // nothing at all, so the cell stays blank exactly as before. The owner only
3160
3241
  // mounts this seat while the row is idle (a running/pending row keeps its
3161
3242
  // own status dot there) — the hover card below therefore carries the host
@@ -3174,8 +3255,8 @@ window.__ModuleLoader__.load({
3174
3255
  'aria-hidden': 'true',
3175
3256
  style: {
3176
3257
  width: 8, height: 8, borderRadius: '50%',
3177
- background: 'var(--dsw-alias-state-success-primary, #4caf7d)',
3178
- boxShadow: '0 0 0 2px color-mix(in srgb, var(--dsw-alias-state-success-primary, #4caf7d) 22%, transparent)',
3258
+ background: mirrorColor(m),
3259
+ boxShadow: '0 0 0 2px color-mix(in srgb, ' + mirrorColor(m) + ' 22%, transparent)',
3179
3260
  },
3180
3261
  }))
3181
3262
  }
@@ -3190,7 +3271,7 @@ window.__ModuleLoader__.load({
3190
3271
  React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: 6 } },
3191
3272
  React.createElement('span', {
3192
3273
  'aria-hidden': 'true',
3193
- style: { width: 7, height: 7, borderRadius: '50%', flexShrink: 0, background: 'var(--dsw-alias-state-success-primary, #4caf7d)' },
3274
+ style: { width: 7, height: 7, borderRadius: '50%', flexShrink: 0, background: mirrorColor(m) },
3194
3275
  }),
3195
3276
  React.createElement('span', { style: { color: '#cfd3d6', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, mirrorLabel(m)),
3196
3277
  ),
@@ -3215,18 +3296,23 @@ window.__ModuleLoader__.load({
3215
3296
  // When better-sidebar is installed it owns the presentation (the
3216
3297
  // guide-card handshake arbitrates that); never open twice.
3217
3298
  React.useEffect(() => {
3218
- if (!m || !props.sessionId) return
3219
- if (!explorerAutoOpenEnabled()) return // the #78 opt-out covers both worlds
3220
- if (explorerOwnedByBs) return
3221
- if (autoOpenedNative.has(props.sessionId)) return
3299
+ if (!m || !props.sessionId) return undefined
3300
+ if (explorerOwnedByBs) return undefined
3301
+ if (autoOpenedNative.has(props.sessionId)) return undefined
3222
3302
  const right = SIDEBAR_RIGHT
3223
- if (!right || typeof right.openTab !== 'function') return
3224
- autoOpenedNative.add(props.sessionId)
3225
- try {
3226
- right.openTab(NATIVE_EXPLORER)
3227
- } catch {
3228
- autoOpenedNative.delete(props.sessionId) // unregistered kind, etc: retry next time
3229
- }
3303
+ if (!right || typeof right.openTab !== 'function') return undefined
3304
+ let cancelled = false
3305
+ const sessionId = props.sessionId
3306
+ void explorerAutoOpenPreference().then((enabled) => {
3307
+ if (cancelled || !enabled || explorerOwnedByBs || autoOpenedNative.has(sessionId)) return
3308
+ autoOpenedNative.add(sessionId)
3309
+ try {
3310
+ right.openTab(NATIVE_EXPLORER)
3311
+ } catch {
3312
+ autoOpenedNative.delete(sessionId) // unregistered kind, etc: retry next time
3313
+ }
3314
+ })
3315
+ return () => { cancelled = true }
3230
3316
  }, [m, props.sessionId])
3231
3317
  if (!m) return null
3232
3318
  const target = mirrorTarget(m)
@@ -3234,11 +3320,11 @@ window.__ModuleLoader__.load({
3234
3320
  'data-dsh-remote-chip': '',
3235
3321
  className: 'dsh-rw-pill is-ok',
3236
3322
  title: tr('session.remoteHover', { target }) + (m.remotePath ? '\n' + m.remotePath : ''),
3237
- style: { maxWidth: 220, overflow: 'hidden', textOverflow: 'ellipsis', display: 'inline-flex', alignItems: 'center', gap: 5 },
3323
+ style: { color: mirrorColor(m), borderColor: 'currentColor', maxWidth: 220, overflow: 'hidden', textOverflow: 'ellipsis', display: 'inline-flex', alignItems: 'center', gap: 5 },
3238
3324
  },
3239
3325
  React.createElement('span', {
3240
3326
  'aria-hidden': 'true',
3241
- style: { width: 7, height: 7, borderRadius: '50%', flexShrink: 0, background: 'var(--dsw-alias-state-success-primary, #4caf7d)' },
3327
+ style: { width: 7, height: 7, borderRadius: '50%', flexShrink: 0, background: mirrorColor(m) },
3242
3328
  }),
3243
3329
  React.createElement('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, target),
3244
3330
  )
@@ -3999,7 +4085,7 @@ window.__ModuleLoader__.load({
3999
4085
  .catch((e) => { if (!cancelled) { setErr(String((e && e.message) || e)); setLoading(false) } })
4000
4086
  return () => { cancelled = true }
4001
4087
  }
4002
- React.useEffect(load, [path])
4088
+ React.useEffect(load, [path, fileSessionId])
4003
4089
 
4004
4090
  const startEdit = () => {
4005
4091
  if (!data || data.binary || data.image) return
@@ -4134,24 +4220,26 @@ window.__ModuleLoader__.load({
4134
4220
  let autoOpenedFor = new Set()
4135
4221
  let disposeAuto = null
4136
4222
  const tryAutoOpen = () => {
4137
- if (!explorerAutoOpenEnabled()) return // issue #78: the user said no, persistently
4138
4223
  if (typeof bs.subscribeState !== 'function') return
4139
4224
  const snap = bs.getSnapshot && bs.getSnapshot()
4140
4225
  if (!snap || !snap.sessionId) return
4141
4226
  if (autoOpenedFor.has(snap.sessionId)) return
4142
4227
  const sessionId = snap.sessionId
4143
- // Issue #13: only auto-open the Remote Files tab for sessions that are
4144
- // genuinely remote (cwd inside a mirror). A plain local session must
4145
- // not get a remote tab popped open by a machine that happens to be
4146
- // saved as "current".
4147
- resolveSessionRemote(sessionId).then((remotePath) => {
4148
- if (!remotePath || autoOpenedFor.has(sessionId)) return
4149
- autoOpenedFor.add(sessionId)
4150
- try {
4151
- bs.openTab({ type: SIDEBAR_EXPLORER_ID, title: tr('explorer.tabTitle'), path: remotePath })
4152
- } catch (e2) {
4153
- console.warn('[dsh-remote] better-sidebar auto-open skipped:', e2)
4154
- }
4228
+ // Native and better-sidebar await the SAME effective preference. Only
4229
+ // after it resolves may we resolve the remote path and call openTab.
4230
+ void explorerAutoOpenPreference().then((enabled) => {
4231
+ if (!enabled || autoOpenedFor.has(sessionId)) return
4232
+ // Issue #13: only auto-open for a genuinely remote session. A plain
4233
+ // local session must never borrow the active machine's workspace.
4234
+ return resolveSessionRemote(sessionId).then((remotePath) => {
4235
+ if (!remotePath || autoOpenedFor.has(sessionId)) return
4236
+ autoOpenedFor.add(sessionId)
4237
+ try {
4238
+ bs.openTab({ type: SIDEBAR_EXPLORER_ID, title: tr('explorer.tabTitle'), path: remotePath })
4239
+ } catch (e2) {
4240
+ console.warn('[dsh-remote] better-sidebar auto-open skipped:', e2)
4241
+ }
4242
+ })
4155
4243
  })
4156
4244
  }
4157
4245
  tryAutoOpen()
@@ -4206,11 +4294,14 @@ window.__ModuleLoader__.load({
4206
4294
  const rest = url.pathname.replace(/^\/+/, '')
4207
4295
  const [scope, ...tail] = rest.split('/')
4208
4296
  if (scope !== 'session' || tail.length < 2) return null
4209
- const sessionId = decodeURIComponent(tail[0])
4297
+ let sessionId, decoded
4298
+ try {
4299
+ sessionId = decodeURIComponent(tail[0])
4300
+ decoded = decodeURIComponent(tail.slice(1).join('/'))
4301
+ } catch { return null } // A malformed link must not throw out of the host router.
4210
4302
  if (!sessionId) return null
4211
4303
  // Dropping the leading empty segment keeps a session-root address ('') a
4212
4304
  // legitimate empty path instead of turning it into '/'.
4213
- const decoded = decodeURIComponent(tail.slice(1).join('/'))
4214
4305
  // Issue #104 + #108: models cite lines as `path:42` / `path#L42`, and as
4215
4306
  // RANGES (`path:24-30`, `#L24-L30`) — the core's own prompt teaches the
4216
4307
  // range form. Range or not, the anchor is stripped from the path (no file
@@ -4305,21 +4396,20 @@ window.__ModuleLoader__.load({
4305
4396
  const address = info.tab.navigation.address
4306
4397
  const parsed = parseCoreFileAddress(address)
4307
4398
  const sessionId = (parsed && parsed.sessionId) || props.sessionId
4308
- const [remotePath, setRemotePath] = React.useState(() => {
4309
- const p = parsed || parseCoreFileAddress(address)
4310
- return p ? remotePathForCoreAddress(p, sessionCwdFor(sessionId)) : null
4311
- })
4399
+ // Resolve from the current navigation on every render. Keeping only an
4400
+ // initial path in state made same-tab navigation continue reading the old file.
4401
+ const [, invalidate] = React.useState(0)
4402
+ const remotePath = parsed ? remotePathForCoreAddress(parsed, sessionCwdFor(sessionId)) : null
4312
4403
  React.useEffect(() => {
4313
- if (remotePath || !parsed) return undefined
4314
- let cancelled = false
4315
- ensureMirrors().then(() => {
4316
- if (cancelled) return
4317
- const cwd = sessionCwdFor(sessionId)
4318
- const resolved = remotePathForCoreAddress(parsed, cwd)
4319
- if (resolved) setRemotePath(resolved)
4320
- })
4321
- return () => { cancelled = true }
4322
- }, [address, remotePath])
4404
+ const changed = () => invalidate((version) => version + 1)
4405
+ mirrorWatchers.add(changed)
4406
+ const unsubscribe = SESSIONS?.list?.subscribe?.(changed)
4407
+ ensureMirrors()
4408
+ return () => {
4409
+ mirrorWatchers.delete(changed)
4410
+ if (typeof unsubscribe === 'function') unsubscribe()
4411
+ }
4412
+ }, [sessionId])
4323
4413
  if (!remotePath) {
4324
4414
  return React.createElement('div', { style: { padding: 16, fontSize: 12, opacity: 0.7 } },
4325
4415
  tr('file.linkUnresolved'))
@@ -4330,15 +4420,20 @@ window.__ModuleLoader__.load({
4330
4420
  // grammar itself never carries one.
4331
4421
  const paramsLine = (() => {
4332
4422
  try {
4333
- const n = Number(info.tab && info.tab.navigation && info.tab.navigation.params && info.tab.navigation.params.line)
4334
- return Number.isInteger(n) && n >= 1 ? n : null
4423
+ const line = info.tab && info.tab.navigation && info.tab.navigation.params && info.tab.navigation.params.line
4424
+ // Host params are the current channel when the address has no
4425
+ // explicit anchor. Accept only actual positive integers: do not
4426
+ // coerce a string like "93" or let invalid params mask a legacy #L2.
4427
+ return Number.isSafeInteger(line) && line > 0 ? line : null
4335
4428
  } catch { return null }
4336
4429
  })()
4337
4430
  return React.createElement(RemoteFileTab, {
4338
4431
  key: remotePath,
4339
4432
  tab: { path: remotePath },
4340
4433
  scope: { sessionId },
4341
- jumpLine: (parsed && parsed.line) || paramsLine,
4434
+ // Current hosts pass line numbers as navigation params; retain support
4435
+ // for older address-carried anchors. Invalid params must not mask them.
4436
+ jumpLine: (parsed && parsed.line) || paramsLine || null,
4342
4437
  })
4343
4438
  }
4344
4439
  /** The local cwd of a session, from the client's own session store. */
@@ -4432,7 +4527,9 @@ window.__ModuleLoader__.load({
4432
4527
  // `extension` band, which by contract outranks every viewer the product
4433
4528
  // ships — including the built-in text preview that currently claims
4434
4529
  // `dsh-resource://file/**` in the `fallback` band and reads locally.
4435
- // `canOpen` is the whole safety story: it must return true ONLY for a
4530
+ // better-sidebar also registers an extension-band editor, so the more
4531
+ // specific session/** pattern below must win the pattern-length tie-break.
4532
+ // `canOpen` is the safety guard: it must return true ONLY for a
4436
4533
  // session whose cwd is PROVEN to be a remote mirror. Local sessions, and
4437
4534
  // a page load before the mirror registry has arrived, fall through to the
4438
4535
  // built-in preview and behave exactly as they did before.
package/lib/credential.js CHANGED
@@ -77,6 +77,13 @@ function run(bin, args, input) {
77
77
  })
78
78
  child.stdout.on('data', (d) => { out += d })
79
79
  child.stderr.on('data', (d) => { errOut += d })
80
+ // A helper may close its read end before stdin.end() flushes. EPIPE is an
81
+ // ASYNC Writable error, so the synchronous try/catch below cannot see it;
82
+ // without this listener it becomes an uncaughtException and kills the host.
83
+ child.stdin.on('error', (err) => {
84
+ try { child.kill('SIGTERM') } catch { /* already gone */ }
85
+ done(err)
86
+ })
80
87
  // Always end stdin: a helper that reads a secret from stdin needs EOF, and one
81
88
  // that does not must not inherit an open pipe.
82
89
  try { child.stdin.end(input == null ? '' : String(input)) } catch { /* closed early */ }
package/lib/index.js CHANGED
@@ -69,6 +69,7 @@ import { createUpdateRoutes } from './routes-update.js'
69
69
  import { createWebAttachRoutes } from './routes-web-attach.js'
70
70
  import { createWorkspaceRoutes } from './routes-workspace.js'
71
71
  import { listDirStructured, removeRemoteTree } from './remote-fs.js'
72
+ import { registerRemoteSkills } from './remote-skills.js'
72
73
 
73
74
  export const name = 'dsh-remote'
74
75
 
@@ -451,6 +452,8 @@ const machineId = _machineId
451
452
  // ── host-key registry (TOFU) ──────────────────────────────────────────────
452
453
  const KNOWN_HOSTS_FILE = 'known_hosts.json'
453
454
  const knownHostsFile = () => path.join(remoteWorkspacesRoot(), KNOWN_HOSTS_FILE)
455
+ // OpenSSH must append plain known_hosts lines, never the native JSON registry.
456
+ const opensshKnownHostsFile = () => path.join(remoteWorkspacesRoot(), 'known_hosts')
454
457
  const isHostKeyKnown = (host, port) => _isHostKeyKnown(knownHostsFile(), host, port)
455
458
 
456
459
  // ── encoding helpers ───────────────────────────────────────────────────────
@@ -469,7 +472,7 @@ function encodeText(s, enc) {
469
472
  export async function apply(ctx, config) {
470
473
  // The ACTIVE pool: a delegating facade, because `backend` is per machine and
471
474
  // the plugin must keep ONE long-lived object to hang its hooks on (issue #51).
472
- const pool = new ActivePool(config, { knownHostsFile })
475
+ const pool = new ActivePool(config, { knownHostsFile, opensshKnownHostsFile })
473
476
  ctx.effect(() => () => pool.close(), 'dsh-remote.close')
474
477
 
475
478
  migrateLegacyData()
@@ -986,7 +989,7 @@ export async function apply(ctx, config) {
986
989
  // session passes its own mirror-resolved remote path explicitly.
987
990
  workspace: '',
988
991
  })
989
- const created = new ActivePool(poolConfig, { knownHostsFile })
992
+ const created = new ActivePool(poolConfig, { knownHostsFile, opensshKnownHostsFile })
990
993
  // Keychain-backed passwords resolve against THIS pool's machine record.
991
994
  created.passwordResolver = async () => machinePassword(eff || { id: '', password: poolConfig.password })
992
995
  machinePools.set(key, created)
@@ -1269,6 +1272,7 @@ export async function apply(ctx, config) {
1269
1272
  }
1270
1273
  }
1271
1274
  saveSyncState(localDir, next)
1275
+ if (remoteSkills) remoteSkills.invalidate()
1272
1276
  }
1273
1277
  const startAutoPush = (localDir) => {
1274
1278
  if (!config.autoPush || autoPushWatchers.has(localDir)) return
@@ -1378,6 +1382,15 @@ export async function apply(ctx, config) {
1378
1382
  * session switching machines cannot redirect this session's commands. */
1379
1383
  const resolveMirrorForLocal = (local) => resolveMirror(local, remoteWorkspacesRoot())
1380
1384
 
1385
+ // Issue #120: project skills live on the REMOTE host, not only in the local
1386
+ // mirror. The optional provider supplements (never replaces) the core's local
1387
+ // filesystem provider and is inert on hosts without the skills service.
1388
+ const remoteSkills = registerRemoteSkills(ctx, {
1389
+ resolveBinding: resolveMirrorForLocal,
1390
+ poolForMachine,
1391
+ logger: typeof ctx.get === 'function' ? ctx.get('logger') : undefined,
1392
+ })
1393
+
1381
1394
  /**
1382
1395
  * The whole local-mirror registry with each mirror's recorded remote origin
1383
1396
  * (issue #49).
@@ -2423,20 +2436,26 @@ export async function apply(ctx, config) {
2423
2436
  throw new Error('sftp unavailable: ' + ((err && err.message) || err))
2424
2437
  }
2425
2438
  const state = loadSyncState(local)
2426
- const { stats, nextState } = await pushTree(sftp, local, p, { ...body, state, maxFileBytes: config.maxFileBytes })
2427
- if (!args.dryRun) saveSyncState(local, nextState)
2428
- let text = `${args.dryRun ? 'WOULD upload' : 'Uploaded'} ${stats.files} file(s) from ${local} → ${p}.`
2429
- if (stats.truncated || stats.files >= maxFiles) text += ` TRUNCATED (hit maxFiles=${maxFiles} cap; raise maxFiles and re-run).`
2430
- if (stats.skippedUnchanged) text += ` ${stats.skippedUnchanged} unchanged.`
2431
- if (stats.skippedLarge) text += ` ${stats.skippedLarge} too large (over ${config.maxFileBytes} bytes).`
2432
- if (stats.staleLocal) text += ` ${stats.staleLocal} local entries gone remotely (kept remotely; use rw_remove to mirror deletions).`
2433
- if (stats.conflicts.length) {
2434
- text += `\n⚠ ${stats.conflicts.length} conflict(s), NOT overwritten:`
2435
- for (const c of stats.conflicts.slice(0, 10)) text += `\n ${c.path} — ${c.reason}`
2436
- if (stats.conflicts.length > 10) text += `\n … and ${stats.conflicts.length - 10} more`
2437
- text += '\n(use force=true to override)'
2439
+ try {
2440
+ const { stats, nextState } = await pushTree(sftp, local, p, { ...body, state, maxFileBytes: config.maxFileBytes })
2441
+ if (!args.dryRun) saveSyncState(local, nextState)
2442
+ let text = `${args.dryRun ? 'WOULD upload' : 'Uploaded'} ${stats.files} file(s) from ${local} → ${p}.`
2443
+ if (stats.truncated || stats.files >= maxFiles) text += ` TRUNCATED (hit maxFiles=${maxFiles} cap; raise maxFiles and re-run).`
2444
+ if (stats.skippedUnchanged) text += ` ${stats.skippedUnchanged} unchanged.`
2445
+ if (stats.skippedLarge) text += ` ${stats.skippedLarge} too large (over ${config.maxFileBytes} bytes).`
2446
+ if (stats.staleLocal) text += ` ${stats.staleLocal} local entries gone remotely (kept remotely; use rw_remove to mirror deletions).`
2447
+ if (stats.conflicts.length) {
2448
+ text += `\n⚠ ${stats.conflicts.length} conflict(s), NOT overwritten:`
2449
+ for (const c of stats.conflicts.slice(0, 10)) text += `\n ${c.path} — ${c.reason}`
2450
+ if (stats.conflicts.length > 10) text += `\n … and ${stats.conflicts.length - 10} more`
2451
+ text += '\n(use force=true to override)'
2452
+ }
2453
+ return { text }
2454
+ } finally {
2455
+ // Sync AND async tasks share this body: invalidate only after the
2456
+ // actual push settles (partial uploads may have changed the remote).
2457
+ if (!args.dryRun && remoteSkills) remoteSkills.invalidate()
2438
2458
  }
2439
- return { text }
2440
2459
  }
2441
2460
  if (args.async) {
2442
2461
  const t = tasks.start('push', `push ${p}`, runPush)
@@ -3104,22 +3123,74 @@ export async function apply(ctx, config) {
3104
3123
  },
3105
3124
  })
3106
3125
 
3107
- // ── local-session tool visibility (issue #63) ────────────────────────────
3126
+ // ── local-session tool visibility (issues #63 / #117) ────────────────────
3108
3127
  // All rw_* tools register globally (at registration time there is no session
3109
- // to consult), but in a LOCAL session the operation tools can never succeed:
3110
- // bindingFor() refuses them with "this session is LOCAL". Exposing them
3111
- // anyway costs every local request a few thousand tokens of dead schema.
3112
- // The `system-prompt/assemble` waterfall is where the final per-request tool
3113
- // list passes with the calling agent attached, so the SAME cwd test the
3114
- // prompt section above already performs can trim the list there. A session
3115
- // whose cwd maps to a mirror keeps the full surface; anything else — a
3116
- // plain local directory, or a mirror whose meta is missing/unparsable
3117
- // (resolveMirror reports no binding; bindingFor refuses it as local too) —
3118
- // is reduced per config.localTools. An assembly without agent/cwd is left
3119
- // alone, matching bindingFor's "no caller context" semantics. `ctx.on` is
3120
- // cordis-core, but guard like the other
3121
- // optional surfaces: a minimal embedding (or a small test double) without
3122
- // event support simply keeps the legacy full surface.
3128
+ // to consult). A scoped restriction is the primary filter: DSH feeds the
3129
+ // SAME visible set to native schemas, the PTC SDK, run_code bindings and
3130
+ // dispatch. Filtering assembled.tools alone cannot touch the PTC SDK, which
3131
+ // is rendered from scope visibility before the assemble waterfall runs.
3132
+ //
3133
+ // Use deny, not an allowlist containing only the bootstrap tools: an allow
3134
+ // filter applies to every inherited tool and would hide unrelated Harness
3135
+ // capabilities too. Existing agents must be covered because this plugin
3136
+ // hot-reloads; created/disposed listeners cover the normal agent lifecycle.
3137
+ const localToolRestrictions = new Map()
3138
+ const localToolNames = tools.map((t) => t.name)
3139
+ const installLocalToolRestriction = (agent) => {
3140
+ if (localToolRestrictions.has(agent)) return
3141
+ const mode = normalizeLocalTools(config.localTools)
3142
+ if (mode === 'all') return
3143
+ const cwd = agent && agent.session && agent.session.header && agent.session.header.cwd
3144
+ if (!cwd) return // no caller context → not definitively local
3145
+ const { remotePath, machine } = resolveMirrorForLocal(String(cwd))
3146
+ if (remotePath && machine) return // remote session → full surface
3147
+ const agentCtx = agent && agent.ctx
3148
+ // Optional service lookup avoids Cordis's "without inject" property error
3149
+ // on custom/older agent contexts; get() still preserves the caller scope.
3150
+ const agentTools = agentCtx && (typeof agentCtx.get === 'function' ? agentCtx.get('tools') : agentCtx.tools)
3151
+ // Older DSH versions without scoped restriction keep the native waterfall
3152
+ // fallback below instead of failing agent creation.
3153
+ if (!agentTools || typeof agentTools.restrict !== 'function') return
3154
+ const deny = mode === 'none'
3155
+ ? localToolNames
3156
+ : localToolNames.filter((name) => !LOCAL_BOOTSTRAP_TOOLS.includes(name))
3157
+ if (deny.length === 0) return
3158
+ try {
3159
+ const dispose = agentTools.restrict({ deny })
3160
+ if (typeof dispose === 'function') localToolRestrictions.set(agent, dispose)
3161
+ } catch (error) {
3162
+ // A creation listener must not reject the whole agent for a presentation
3163
+ // compatibility problem. Native filtering remains active; surface the
3164
+ // degraded PTC behavior instead of silently pretending it was fixed.
3165
+ fileReferenceLog(`local tool restriction failed: ${(error && error.message) || error}`)
3166
+ }
3167
+ }
3168
+ const disposeLocalToolRestriction = (agent) => {
3169
+ const dispose = localToolRestrictions.get(agent)
3170
+ if (!dispose) return Promise.resolve()
3171
+ localToolRestrictions.delete(agent)
3172
+ return Promise.resolve()
3173
+ .then(() => dispose())
3174
+ .catch((error) => fileReferenceLog(`local tool restriction cleanup failed: ${(error && error.message) || error}`))
3175
+ }
3176
+ const agents = typeof ctx.get === 'function' ? ctx.get('agents') : undefined
3177
+ if (agents && typeof agents.list === 'function') {
3178
+ for (const agent of agents.list()) installLocalToolRestriction(agent)
3179
+ }
3180
+ if (typeof ctx.on === 'function') {
3181
+ ctx.on('agent/created', ({ agent }) => installLocalToolRestriction(agent))
3182
+ ctx.on('agent/disposed', ({ agent }) => { void disposeLocalToolRestriction(agent) })
3183
+ }
3184
+ ctx.effect(
3185
+ () => () => Promise.all([...localToolRestrictions.keys()].map((agent) => disposeLocalToolRestriction(agent))),
3186
+ 'dsh-remote.local-tool-visibility',
3187
+ )
3188
+
3189
+ // Native/legacy fallback: the final per-request wire list also passes through
3190
+ // this waterfall. PTC keeps only run_code here; its SDK is handled by the
3191
+ // scoped restriction above. An assembly without agent/cwd is left alone,
3192
+ // matching bindingFor's "no caller context" semantics. Minimal embeddings
3193
+ // without event support retain the legacy full surface.
3123
3194
  if (typeof ctx.on === 'function') {
3124
3195
  ctx.on('system-prompt/assemble', async (_assembly, assembleContext, next) => {
3125
3196
  const assembled = await next()
@@ -3206,6 +3277,28 @@ export async function apply(ctx, config) {
3206
3277
  })
3207
3278
  }
3208
3279
 
3280
+ // Remote skill catalogs are cached by cwd/revision. Invalidate after any
3281
+ // operation that MAY have changed the remote (a failed/partial write counts
3282
+ // too), but never after caller cancellation. rw_push has its own settlement
3283
+ // hook above; rw_sync only downloads and need not invalidate.
3284
+ if (remoteSkills && typeof ctx.on === 'function') {
3285
+ const SKILL_MUTATIONS = new Set([
3286
+ 'rw_write_file', 'rw_edit', 'rw_append', 'rw_remove', 'rw_move',
3287
+ 'rw_mkdir', 'rw_upload', 'rw_exec',
3288
+ // Rebinding a workspace/connection must not resurrect the old catalog.
3289
+ 'rw_connect', 'rw_pick_workspace', 'rw_disconnect',
3290
+ ])
3291
+ ctx.on('tools/result', (result, hookContext) => {
3292
+ try {
3293
+ const name = String((hookContext && hookContext.name) || (result && result.name) || '')
3294
+ if (!SKILL_MUTATIONS.has(name)) return
3295
+ const signal = (hookContext && hookContext.signal) || (result && result.signal)
3296
+ if (signal && signal.aborted) return
3297
+ remoteSkills.invalidate()
3298
+ } catch { /* cache invalidation is best-effort and never blocks the tool */ }
3299
+ })
3300
+ }
3301
+
3209
3302
  // ── slash commands ─────────────────────────────────────────────────────────
3210
3303
  const commands = ctx.get('commands')
3211
3304
  if (commands !== undefined) {
@@ -3766,7 +3859,7 @@ export async function apply(ctx, config) {
3766
3859
  proxy: (probeTarget && !probeIsOpenssh && probeTarget.proxy) ? probeTarget.proxy : cred.proxy,
3767
3860
  connectTimeoutMs: Math.min(Math.max(Number(body.connectTimeoutMs) || config.connectTimeoutMs, 2000), 30000),
3768
3861
  commandTimeoutMs: 10000,
3769
- }, { knownHostsFile })
3862
+ }, { knownHostsFile, opensshKnownHostsFile })
3770
3863
  // Same lazy resolution the active pool uses: if the merged password was
3771
3864
  // empty because the secret lives in the OS keychain, the pool asks again
3772
3865
  // at dial time instead of failing with "no credentials".
@@ -4172,6 +4265,7 @@ export async function apply(ctx, config) {
4172
4265
  }),
4173
4266
  ...createFsRoutes({
4174
4267
  sendJson, readBody, resolveRequestBinding, decodeBuf, encodeText, audit, config, mirrorDirFor,
4268
+ onRemoteMutation: () => { if (remoteSkills) remoteSkills.invalidate() },
4175
4269
  }),
4176
4270
 
4177
4271
  // Embedded terminal (P1): one host-owned PTY session per machine, polled.