dsh-ris-ide 1.8.0 → 1.8.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/README.md CHANGED
@@ -33,7 +33,7 @@ DSH(DeepSeek Harness)Web GUI 右侧栏里的 **RIS-IDE 本地开发面板**
33
33
  - **预览**:`.md/.markdown/.html/.htm` 编辑/预览切换按钮**悬浮在编辑区右上角**(不占代码行高,预览含未保存修改);超过整读上限的大文本以**只读分页预览**打开(滚到近底取下一页、内存超限释放前文、滚动位置按文件记住),标题栏「编辑」可强制全量加载进编辑(上限 32MB)。
34
34
  - **JDWP 调试(仅 Java)**:点行号加断点、双击红点删除(空行/注释行忽略);断点/线程/调用栈/变量/单步/继续;对象与数组懒加载展开、继承字段与空值也列出;依赖 jar 自动取 `-sources.jar`,没有则 `javap` 反汇编,也可在调试面板 ⚙ 填反编译 jar(如 CFR),缓存按 jar 指纹失效并有 64MB/30 天上限回收;命中后自动切「参数」页签、打开源码并高亮当前行;前端程序只能启停/看日志。
35
35
  - **独立窗口**:聊天页右上角 **⧉ RIS-IDE**(或控制台标题栏 ⧉)打开,**填满屏幕**、**不加载 DSH 界面/不带会话历史**,与侧栏同一套 `/dsh-ris-ide/*` 路由与 cookie,没有新端口;窗口按**工作空间**单例,从程序目录调试也不会开出第二个。
36
- - **代理**:规则表是全机一份文件(`~/.dsh-ris-ide/proxy.json`),所以入口是 CLI/工具与 **risd 维护页**——`node <dsh-ris-ide>/lib/proxy.js rules` 看表、`… start` / `… stop` 管引擎,`yds proxy sync` 从 confcenter 自动生成该项目的规则(DB/Redis/gitlab/回调网段)。**插件面板不再内置代理配置界面**(1.8.0 起,D4):risd 维护页的「代理设置」页签(`http://127.0.0.1:11082/ui?tab=proxy`)不依赖 dsh,直接编辑全机规则表。系统层拦截需要的 **ProxyBridge 组件改为首次使用时下载**(不再随包内置 2.9 MB 二进制):risd 维护页「代理 → 组件」一点即下——内置 **Gitee 主地址、GitHub 备用**两个镜像(同一份发版附件,前一个失败自动换下一个),也可上传 `ris-proxy.4.0.tgz`,或设 `DSH_RIS_IDE_PROXYBRIDGE_URL` / `settings.json` 的 `proxybridgeUrl` 走内网镜像;装进 `~/.dsh-ris-ide/proxybridge/bundle/` 后复用,安装完成后面板只显示「已安装」。下载失败时面板给出两个下载地址与手动上传入口。许可文本(MIT + WinDivert LGPL-3.0)随包安装。组件包按**固定 sha256** 校验(下载与上传都验内容;`DSH_RIS_IDE_PROXYBRIDGE_SHA256` 或 `settings.json` 的 `proxybridgeSha256` 可覆盖,置空=首次信任;重发附件改了内容要同步更新常量并发版);已安装后在面板里可「重新下载」(强制刷新缓存副本)。未安装时会明确提示入口而不是静默失败;机器上已装的 ProxyBridge / `DSH_RIS_IDE_PROXYBRIDGE` 仍是回退。WSL 下先把 Windows 版复制到 `%LOCALAPPDATA%\dsh-ris-ide\proxybridge\windows` 再启动。**一个 启动/停止 管全部三层**——本地引擎(给本插件 spawn 的程序注入代理)、系统层拦截(ProxyBridge 按进程名在系统层改路,覆盖 Navicat、IDE 里的 java、终端 git)、git 配置(`git config --global http.https://<host>/.proxy = socks5h://…`,写完终端里的 `git` 与 dsh-git 都走隧道);`dsh` 退出时三层一起停,不留残留。**全机一份规则表**(`~/.dsh-ris-ide/proxy.json`,`DSH_RIS_IDE_PROXY_HOME` 可改位置),整机生效、不区分工作区与会话,行尾「来源」列只记是用户行还是 yds 注入(`yds·win` / `yds·wsl` 还会标出命中的一侧)。提权是正常流程:Windows 侧启动时弹 UAC,Linux 侧需要免密 sudo;提不到权时弹窗里给出可直接粘贴的命令。Windows 侧启动还有三个实测过的细节:GUI 安装的服务 `ProxyBridgeSvc` 与 CLI 互斥(都抢 WinDivert 句柄),所以先停服务再起 CLI(停过会记下来,停止时尝试恢复);手起或遗留的 `ProxyBridge_CLI.exe` 先结束再接管;CLI 没有日志开关,stdout 重定向到 `%TEMP%\dsh-ris-proxybridge.log`,起不来时日志尾部就是错误原因。两层兜底:ProxyBridge 没在跑时,支持代理的程序(java / git / node / curl)启动时注入**本机 CONNECT 代理** `http://127.0.0.1:11081`(`ALL_PROXY`/`HTTP(S)_PROXY` + JVM 的 `-Dhttp(s).proxyHost/Port`),每一条连接仍然要过规则里的 IP/端口白名单——注入不再等于「把上游 SOCKS 地址直接发给程序」。想让某个程序完全绕过白名单、直连上游 SOCKS,就在该行加 `"direct": true`(`proxy.json` 里的行级开关,界面暂无控件);不支持代理的客户端(Navicat / JDBC)自动映射 `127.0.0.1:同端口`——这些映射行是实现细节,不进界面。维护页「代理设置」页签上部填上游 SOCKS(host/port)与本地 CONNECT 端口,下部是规则表:`启用 · 程序 · IP 允许(1.1.1.* / 逗号)· 端口允许(1521 / 1000-1010,* 表示不限)· 状态 · 命中方式`。**全机一张表、改动直接覆盖**:没有「读取 / 保存」按钮,也没有按工作区区分——改动 700 ms 后自动校验并写表(缺程序/IP/端口或端口格式不对只提示、不写),写进去的就是整张表,未出现的行会被删掉(这也意味着 `yds stop` 能靠「不发那些行」把注入的规则撤干净);写盘后先停旧的系统层拦截再按新表重启,换拦截的两轮探测在后台跑,页面不会被它卡住。「状态」列直接回答这行现在生效没(未启用 / 缺… / 端口格式 / 待启动 / 生效)。引擎与拦截只用一个按钮管:运行中显示「停止」,停止后变「启动」(未运行/运行中的另一状态不再另设按钮);点下去到生效之间按钮显示「启动中…」/「停止中…」并暂时不可点(等提权或引擎拉起),不会看起来像没反应。`yds proxy sync` 注入的规则在 **Windows 与 WSL 两侧各一行**(`java.exe` / `java`、`git.exe` / `git`,「来源」列标 `yds·win` / `yds·wsl`)——ProxyBridge 按镜像名匹配,`java.exe` 匹配不到 WSL 里的 `java`,以前这里只注入 Windows 侧。ProxyBridge 组件安装好之后卡片只显示「已安装 · 文件 N 个」,不再给下载/上传按钮。程序列两种来源——**运行中的进程**(本侧 + Windows 侧,只列支持 SOCKS 的)或**固定程序**(文件浏览器选可执行文件,可在启动前配好;裸名按镜像名匹配,含路径则精确到那个可执行文件)。
36
+ - **代理**:规则表是全机一份文件(`~/.dsh-ris-ide/proxy.json`),所以入口是 CLI/工具与 **risd 维护页**——`node <dsh-ris-ide>/lib/proxy.js rules` 看表、`… start` / `… stop` 管引擎,`yds proxy sync` 从 confcenter 自动生成该项目的规则(DB/Redis/gitlab/回调网段)。**插件面板不再内置代理配置界面**(1.8.0 起,D4):risd 维护页的「代理设置」页签(`http://127.0.0.1:11082/ui?tab=proxy`)不依赖 dsh,直接编辑全机规则表。系统层拦截需要的 **ProxyBridge 组件改为首次使用时下载**(不再随包内置 2.9 MB 二进制):risd 维护页「代理 → 组件」一点即下——内置 **Gitee 主地址、GitHub 备用**两个镜像(同一份发版附件,前一个失败自动换下一个),也可上传 `ris-proxy.4.0.tgz`,或设 `DSH_RIS_IDE_PROXYBRIDGE_URL` / `settings.json` 的 `proxybridgeUrl` 走内网镜像;装进 `~/.dsh-ris-ide/proxybridge/bundle/` 后复用,安装完成后面板只显示「已安装」。下载失败时面板给出两个下载地址与手动上传入口。许可文本(MIT + WinDivert LGPL-3.0)随包安装。组件包按**固定 sha256** 校验(下载与上传都验内容;`DSH_RIS_IDE_PROXYBRIDGE_SHA256` 或 `settings.json` 的 `proxybridgeSha256` 可覆盖,置空=首次信任;重发附件改了内容要同步更新常量并发版);已安装后在面板里可「重新下载」(强制刷新缓存副本)。未安装时会明确提示入口而不是静默失败;机器上已装的 ProxyBridge / `DSH_RIS_IDE_PROXYBRIDGE` 仍是回退。WSL 下先把 Windows 版复制到 `%LOCALAPPDATA%\dsh-ris-ide\proxybridge\windows` 再启动。**一个 启动/停止 管全部三层**——本地引擎(给本插件 spawn 的程序注入代理)、系统层拦截(ProxyBridge 按进程名在系统层改路,覆盖 Navicat、IDE 里的 java、终端 git)、git 配置(`git config --global http.https://<host>/.proxy = socks5h://…`,写完终端里的 `git` 与 dsh-git 都走隧道);`dsh` 退出时三层一起停,不留残留。**全机一份规则表**(`~/.dsh-ris-ide/proxy.json`,`DSH_RIS_IDE_PROXY_HOME` 可改位置),整机生效、不区分工作区与会话,行尾「来源」列只记是用户行还是 yds 注入(`yds·win` / `yds·wsl` 还会标出命中的一侧)。提权是正常流程:Windows 侧启动时弹 UAC,Linux 侧需要免密 sudo;提不到权时弹窗里给出可直接粘贴的命令。Windows 侧启动还有三个实测过的细节:GUI 安装的服务 `ProxyBridgeSvc` 与 CLI 互斥(都抢 WinDivert 句柄),所以先停服务再起 CLI(停过会记下来,停止时尝试恢复);手起或遗留的 `ProxyBridge_CLI.exe` 先结束再接管;CLI 没有日志开关,stdout 重定向到 `%TEMP%\dsh-ris-proxybridge.log`,起不来时日志尾部就是错误原因。两层兜底:ProxyBridge 没在跑时,支持代理的程序(java / git / node / curl)启动时注入**本机 CONNECT 代理** `http://127.0.0.1:11081`(`ALL_PROXY`/`HTTP(S)_PROXY` + JVM 的 `-Dhttp(s).proxyHost/Port`),每一条连接仍然要过规则里的 IP/端口白名单——注入不再等于「把上游 SOCKS 地址直接发给程序」。想让某个程序完全绕过白名单、直连上游 SOCKS,就在该行加 `"direct": true`(`proxy.json` 里的行级开关,界面暂无控件);不支持代理的客户端(Navicat / JDBC)自动映射 `127.0.0.1:同端口`——这些映射行是实现细节,不进界面。维护页「代理设置」页签上部填上游 SOCKS(host/port)与本地 CONNECT 端口,下部是规则表:`启用 · 程序名称/路径 · 目标主机 · 端口 · 状态 · 来源`(程序列写裸名按镜像名匹配、写路径精确到那个可执行文件;目标主机可用 `172.20.*` 这类通配,端口可写 `1521`、`1000-1010` 或 `*`)。**全机一张表、改动直接覆盖**:没有「读取 / 保存」按钮,也没有按工作区区分——改动 700 ms 后自动校验并写表(缺程序/IP/端口或端口格式不对只提示、不写),写进去的就是整张表,未出现的行会被删掉(这也意味着 `yds stop` 能靠「不发那些行」把注入的规则撤干净);写盘后先停旧的系统层拦截再按新表重启,换拦截的两轮探测在后台跑,页面不会被它卡住。「状态」列直接回答这行现在生效没(未启用 / 缺… / 端口格式 / 待启动 / 生效)。引擎与拦截只用一个按钮管:运行中显示「停止」,停止后变「启动」——如果系统层拦截是 root 起的,停止会如实告诉你「请用 sudo stop」并给出命令;启动还在等提权时点停止则提示「另一个进程正在启动桥接,请稍后再试」(未运行/运行中的另一状态不再另设按钮);点下去到生效之间按钮显示「启动中…」/「停止中…」并暂时不可点(等提权或引擎拉起),不会看起来像没反应。`yds proxy sync` 注入的规则在 **Windows 与 WSL 两侧各一行**(`java.exe` / `java`、`git.exe` / `git`,「来源」列标 `yds·win` / `yds·wsl`)——ProxyBridge 按镜像名匹配,`java.exe` 匹配不到 WSL 里的 `java`,以前这里只注入 Windows 侧。ProxyBridge 该侧起不来(Linux 需要 root)时,同一行会给出可直接粘贴的 `sudo …/ProxyBridge --profile … --verbose 2`。卡片上的组件健康是**一行定时状态**(旁边还有「提权启动」:先试免密 `sudo`,做不到就**弹一个小窗口(居中)**让你在里面输密码,窗口开着的期间组件卡里会有一行提示、关掉就消失,密码输完窗口自动退出、拦截继续跑(日志在 `~/.dsh-ris-ide/proxybridge/elevate-<side>.log`);两者都不行时才只显示命令)(每 10 秒复查:`拦截运行中` / `拦截未启动` / `组件异常` / `代理引擎未启动` / `组件不应运行`),没有「重新检查」按钮,也不列每侧文件数;组件安装好之后卡片只显示「已安装 · 文件 N 个」,不再给下载/上传按钮。那一行状态只在**代理引擎运行时**才检查(引擎没跑时组件没被使用,不判红),检查只读、不启动也不提权;点它下面的「说明」可展开细节——本侧需要的 sudo 命令(直接粘贴到终端执行),以及**降级方案**:JVM 程序用 `-Dhttp.proxyHost/Port` 等参数、能读环境变量的程序用 `ALL_PROXY=http://127.0.0.1:<监听端口>`、git 已经由 daemon 写好 `http.<host>.proxy`(没写时说明里给出 `git config --global …` 命令);JDBC/Navicat 这类拿不到代理地址的程序只能靠系统层拦截。组件起得来就是系统层拦截、起不来自动走降级,不会把「提不到权」当成组件故障。一台机器只可能有一种「本侧」——原生 Linux 没有 Windows 侧、原生 Windows 没有 Linux 侧(只有 WSL 才两侧都有),所以卡片只列这台机器真有的侧,单侧环境不会因此报「组件异常」。**引擎与组件始终成对**(m12046/m12053/m12060):引擎启动后组件没起就自动拉起(需要 UAC/免密 sudo 时给出原因),引擎停了而拦截还在跑就自动停掉;daemon 启动、健康轮询、启停动作和 15 s 一次的监管都会把两者拉回一致,提权失败按分钟节流,不会反复弹窗。程序列两种来源——**运行中的进程**(本侧 + Windows 侧,只列支持 SOCKS 的)或**固定程序**(文件浏览器选可执行文件,可在启动前配好;裸名按镜像名匹配,含路径则精确到那个可执行文件)。
37
37
 
38
38
  - 弹窗**没有保存按钮**:改动在停手 700ms 后自动写盘;写的时候会过一遍校验——**新建但没填完整**的行不写入(底栏提示「N 条未填完整,未写入」),**已经在文件里**的行如果被改到一半,会连同新内容写成「停用」(提示「N 条改到一半,已置为停用」),不会留下旧内容假装生效,也不会让半截规则生效。写完本机引擎立刻生效、系统层拦截静默重启;「+ 添加规则」只追加一个空行,不会弹选择器盖住表格。
39
39
  - 「选…」打开的两页签选择器:**运行中的程序**(本侧 + Windows 侧进程,只列支持 SOCKS 的)、**选择文件**;文件页签下面是**树**——点文件夹原地展开(只读被展开的那一层),点文件即选中,不再一级一级「进入目录」;顶层入口只有**根路径 `/`** 与 **Windows C:/D:**(WSL 下 `/mnt` 就是 Windows 盘,所以只有一个文件页签;在那里选中的路径会写成 `D:\…`);**没有子项的文件夹**渲染成叶子(`·`、灰一点、点不动),不会出现按下去没反应的空展开。
@@ -75,6 +75,8 @@ DSH(DeepSeek Harness)Web GUI 右侧栏里的 **RIS-IDE 本地开发面板**
75
75
 
76
76
  已知边界:本侧(WSL/Linux root 起的)系统层拦截仍不支持热重载(要重启);规则表的 `shadow` 端口没有内置默认值,全部来自配置与 dsh-ris-yds 的写入。
77
77
 
78
+ - **开发环境的「工作区」状态互相独立**:打开的文件页签、当前文件、最近文件、检索结果缓存都按工作区(`cwd`)各存一份——切换工作区不会把上一个仓库的页签或 `git grep` 结果带过来。
79
+
78
80
  ## 安装
79
81
 
80
82
  需要 DSH `>= 0.2.0-rc.2`,且 Web GUI 带官方右侧栏服务(`sidebarRight` / `sidebarRightTabs` / `slots`)。
package/bin/risd.mjs CHANGED
@@ -24,8 +24,7 @@ import { readFileSync } from 'node:fs'
24
24
  import { DEFAULT_RISD_PORT, RISD_API_VERSION, risdHomeDir, risdStatePath, readRisdState, dropStaleSpawnLock } from '../lib/risd/state.js'
25
25
  import { pidAlive } from '../lib/proxy.js'
26
26
  import { createRisdLogger, risdLogPath } from '../lib/risd/log.js'
27
- import { startRisd } from '../lib/risd/server.js'
28
- import { probeRisdHealth } from '../lib/risd/server.js'
27
+ import { probeRisdHealth, startRisd, waitForPidExit } from '../lib/risd/server.js'
29
28
 
30
29
  const PACKAGE_VERSION = (() => {
31
30
  try {
@@ -46,6 +45,10 @@ function parseArgs(argv) {
46
45
  // m11421: successor started by POST /v1/restart — wait for the predecessor to
47
46
  // exit so the port is free and the handoff stamp is on disk.
48
47
  else if (arg === '--wait-pid') options.waitPid = Number(argv[++index])
48
+ // m13598: identity of that pid (Linux start time), so a reused pid is not waited
49
+ // on for the full 20 s (review A4-P2-5). Internal parameter: only the successor
50
+ // spawned by `POST /v1/restart` passes it, not the user-facing CLI.
51
+ else if (arg === '--wait-start') options.waitStart = String(argv[++index] ?? '')
49
52
  else if (arg === '--port' || arg === '-p') options.port = Number(argv[++index])
50
53
  else if (arg.startsWith('--port=')) options.port = Number(arg.slice('--port='.length))
51
54
  else if (arg.startsWith('-')) throw new Error(`unknown option: ${arg}`)
@@ -58,6 +61,9 @@ function parseArgs(argv) {
58
61
  if (options.waitPid !== undefined && (!Number.isInteger(options.waitPid) || options.waitPid <= 0)) {
59
62
  throw new Error(`invalid --wait-pid: ${options.waitPid}`)
60
63
  }
64
+ if (options.waitStart !== undefined && !/^\d+$/.test(options.waitStart)) {
65
+ throw new Error(`invalid --wait-start: ${options.waitStart}`)
66
+ }
61
67
  return options
62
68
  }
63
69
 
@@ -86,20 +92,6 @@ async function request(state, path, { method = 'GET', body = undefined, timeoutM
86
92
  return { status: response.status, payload }
87
93
  }
88
94
 
89
- /** Resolve once `pid` is gone (ESRCH) or the deadline passes; never throws. */
90
- function waitForPidExit(pid, timeoutMs) {
91
- const deadline = Date.now() + timeoutMs
92
- return new Promise((resolve) => {
93
- const tick = () => {
94
- let alive = true
95
- try { process.kill(pid, 0) } catch (error) { alive = error.code === 'EPERM' }
96
- if (!alive || Date.now() > deadline) { resolve(); return }
97
- setTimeout(tick, 100)
98
- }
99
- tick()
100
- })
101
- }
102
-
103
95
  async function serve(options) {
104
96
  // Never assign `undefined` to process.env: it becomes the string "undefined",
105
97
  // which then resolves every machine-level file (state, token, heartbeat) under
@@ -107,7 +99,12 @@ async function serve(options) {
107
99
  const home = risdHomeDir(options.home)
108
100
  // A successor spawned by POST /v1/restart must not treat the dying predecessor as
109
101
  // "already running": wait until its pid is gone, then serve (m11421).
110
- if (options.waitPid !== undefined) await waitForPidExit(options.waitPid, 20000)
102
+ if (options.waitPid !== undefined) {
103
+ const wait = await waitForPidExit(options.waitPid, 20000, options.waitStart ?? '')
104
+ // Not fatal: the predecessor may be stuck in teardown; bind anyway and let the
105
+ // already-running election decide (review A4-P2-5 / lead decision E).
106
+ if (wait.timedOut === true) process.stderr.write(`risd: predecessor ${options.waitPid} did not exit within 20s; continuing\n`)
107
+ }
111
108
  // Heartbeat, janitor state and the git-proxy entry all resolve through the
112
109
  // machine-level home; a daemon started for a test home must not touch the real
113
110
  // one, and the plugin always points at the same home it reads `risd.json` from.
package/lib/client.js CHANGED
@@ -1211,7 +1211,12 @@ window.__ModuleLoader__.load({
1211
1211
  }
1212
1212
  }
1213
1213
 
1214
- /** Storage key + default height of the compact panel's log pane. */
1214
+ /**
1215
+ * Storage key + default height of the compact panel's log pane.
1216
+ * Deliberately NOT workspace-scoped (unlike the IDE tabs/recent list): the
1217
+ * compact layout is a preference of this machine, and two panes of the same
1218
+ * page should agree on how tall the log is (评审 20261109-2326 客户端 P2).
1219
+ */
1215
1220
  var COMPACT_UI_KEY = 'dsh-ris-ide:ui:compact'
1216
1221
  var COMPACT_PANE_DEFAULT = 240
1217
1222
 
@@ -1227,7 +1232,10 @@ window.__ModuleLoader__.load({
1227
1232
  return Math.min(Math.max(120, value), 720)
1228
1233
  }
1229
1234
 
1230
- /** Storage key of the compact panel's maximized section ('' | 'console' | 'log'). */
1235
+ /**
1236
+ * Storage key of the compact panel's maximized section ('' | 'console' | 'log').
1237
+ * Machine-wide on purpose, same as COMPACT_UI_KEY above.
1238
+ */
1231
1239
  var COMPACT_MAX_KEY = 'dsh-ris-ide:ui:compact-max'
1232
1240
 
1233
1241
  /**
@@ -6664,34 +6672,65 @@ window.__ModuleLoader__.load({
6664
6672
  })))
6665
6673
  }
6666
6674
 
6675
+ /**
6676
+ * One stored IDE-tab blob, or null when it is absent/junk. Parsing is per key:
6677
+ * `dsh-ris-ide:ui:*` also holds non-JSON preferences (`…:compact-max` = 'log'),
6678
+ * and one of those used to abort the whole legacy scan (C review P2).
6679
+ * @param {string|null} raw - the localStorage value.
6680
+ * @returns {object|null} the parsed blob.
6681
+ */
6682
+ function parseSavedBlob(raw) {
6683
+ if (raw === null || raw === undefined) return null
6684
+ try {
6685
+ var blob = JSON.parse(raw)
6686
+ return blob !== null && typeof blob === 'object' ? blob : null
6687
+ } catch (error) {
6688
+ return null
6689
+ }
6690
+ }
6691
+
6667
6692
  /**
6668
6693
  * The saved layout of one IDE tab: `{ui:{maximized,section}, sizes, font,
6669
- * theme, files, file}`. Persisted per tab under `dsh-ris-ide:ui:<key>`.
6694
+ * theme, files, file}`. Persisted per tab + WORKSPACE under
6695
+ * `dsh-ris-ide:ui:<key>@<cwd>` (m13444).
6670
6696
  *
6671
- * The workspace tab used to be keyed per PROGRAM (the panel passed the first
6672
- * program's meta), so a user's maximised pane / colour scheme / font size could
6673
- * silently reset after that key became `…:workspace`. When the exact key has
6674
- * nothing saved, adopt the first other `dsh-ris-ide:ui:*` entry and let the
6675
- * normal persist effect copy it to the current key.
6697
+ * Pre-m13444 keys had no workspace suffix. Migration is one-shot: the tab's
6698
+ * own legacy key (`…:<key>` without `@…`) is adopted ONCE and deleted, so the
6699
+ * next workspace does not inherit the same open tabs again (C review P1-2).
6700
+ * Same-workspace tabs may still adopt each other (the old per-program key
6701
+ * behaviour); another workspace's blob is never adopted.
6676
6702
  * @param {string} storageKey - the current tab's key.
6703
+ * @param {string} [workspaceKey] - the workspace this tab belongs to.
6677
6704
  * @returns {object|null} the saved blob.
6678
6705
  */
6679
- function readSavedUi(storageKey) {
6706
+ function readSavedUi(storageKey, workspaceKey) {
6680
6707
  try {
6681
6708
  if (typeof localStorage === 'undefined') return null
6682
- var raw = localStorage.getItem(storageKey)
6683
- if (raw !== null) {
6684
- var own = JSON.parse(raw)
6685
- return own !== null && typeof own === 'object' ? own : null
6686
- }
6709
+ var own = parseSavedBlob(localStorage.getItem(storageKey))
6710
+ if (own !== null) return own
6687
6711
  if (typeof localStorage.key !== 'function') return null
6712
+ var scoped = typeof workspaceKey === 'string' && workspaceKey !== ''
6713
+ if (scoped === true) {
6714
+ var at = storageKey.lastIndexOf('@')
6715
+ var legacyKey = at > 0 ? storageKey.slice(0, at) : null
6716
+ if (legacyKey !== null) {
6717
+ var migrated = parseSavedBlob(localStorage.getItem(legacyKey))
6718
+ if (migrated !== null) {
6719
+ try { localStorage.removeItem(legacyKey) } catch (removeError) { /* private mode */ }
6720
+ return migrated
6721
+ }
6722
+ }
6723
+ }
6688
6724
  for (var index = 0; index < localStorage.length; index += 1) {
6689
6725
  var key = localStorage.key(index)
6690
6726
  if (typeof key !== 'string' || key.indexOf('dsh-ris-ide:ui:') !== 0 || key === storageKey) continue
6691
- var legacyRaw = localStorage.getItem(key)
6692
- if (legacyRaw === null) continue
6693
- var legacy = JSON.parse(legacyRaw)
6694
- if (legacy !== null && typeof legacy === 'object') return legacy
6727
+ // Only a tab of THIS workspace: split at the LAST `@`, so a cwd that
6728
+ // itself contains an `@` cannot match another workspace (C review P2).
6729
+ if (scoped !== true) continue
6730
+ var splitAt = key.lastIndexOf('@')
6731
+ if (splitAt <= 0 || key.slice(splitAt + 1) !== workspaceKey) continue
6732
+ var blob = parseSavedBlob(localStorage.getItem(key))
6733
+ if (blob !== null) return blob
6695
6734
  }
6696
6735
  return null
6697
6736
  } catch (error) {
@@ -7386,6 +7425,13 @@ window.__ModuleLoader__.load({
7386
7425
  var meta = tab !== null && tab !== undefined && tab.meta !== null && typeof tab.meta === 'object' ? tab.meta : {}
7387
7426
  var sessionId = scope ? scope.sessionId : undefined
7388
7427
  var cwd = scope ? scope.cwd : undefined
7428
+ /**
7429
+ * Everything that remembers a WORKSPACE (open file tabs, recent history,
7430
+ * layout, search results) is scoped by this key: two workspaces are two
7431
+ * different file trees, so a tab or a `git grep` hit from one must never
7432
+ * appear in the other (m13444).
7433
+ */
7434
+ var workspaceKey = typeof cwd === 'string' && cwd !== '' ? cwd : 'default'
7389
7435
  var programs = Array.isArray(props.programs) ? props.programs : []
7390
7436
  var metaKind = typeof meta.kind === 'string' ? meta.kind : 'spring'
7391
7437
  var metaLogPath = typeof meta.logPath === 'string' ? meta.logPath : ''
@@ -7413,8 +7459,12 @@ window.__ModuleLoader__.load({
7413
7459
  * across suspends, so reading `dbg` from its closure would be stale. */
7414
7460
  var dbgRef = useRef(dbg)
7415
7461
  dbgRef.current = dbg
7416
- var storageKey = 'dsh-ris-ide:ui:' + (programKey !== '' ? programKey : (metaLogPath !== '' ? metaLogPath : 'workspace'))
7417
- var savedUi = readSavedUi(storageKey)
7462
+ var storageKey = 'dsh-ris-ide:ui:' + (programKey !== '' ? programKey : (metaLogPath !== '' ? metaLogPath : 'workspace')) + '@' + workspaceKey
7463
+ // Read the saved blob ONCE per mount (it only seeds useState initializers
7464
+ // below). The read also runs the one-shot legacy migration — readSavedUi
7465
+ // removes the key it adopted — so calling it per render would re-probe
7466
+ // localStorage on every keystroke (评审 20261109-2326 客户端 P2).
7467
+ var [savedUi] = useState(function () { return readSavedUi(storageKey, workspaceKey) })
7418
7468
 
7419
7469
  var [consoleBusy, setConsoleBusy] = useState('')
7420
7470
  /** Which action that row mask is running (`start|stop|restart|debug`). */
@@ -7482,6 +7532,19 @@ var [ui, setUi] = useState(function () {
7482
7532
  * query (or the `git grep` output) away, so the same row can be reopened.
7483
7533
  */
7484
7534
  var searchCacheRef = useRef(new Map())
7535
+ /**
7536
+ * Search cache key: `kind:workspace\0query`. The workspace MUST be part of
7537
+ * it — `git grep` runs against one tree, so replaying another tree's hits
7538
+ * (or dropping the new tree's entry when invalidating) would cross
7539
+ * workspaces (m13444).
7540
+ */
7541
+ function searchKey(kind, text) {
7542
+ return kind + ':' + workspaceKey + '\u0000' + text
7543
+ }
7544
+ /** A workspace switch replaces the tree under every cached payload. */
7545
+ useEffect(function () {
7546
+ searchCacheRef.current.clear()
7547
+ }, [workspaceKey])
7485
7548
  /**
7486
7549
  * Bumped when the cached results for the CURRENT query must be thrown away
7487
7550
  * (Ctrl+R, or a save in this window). `searchCacheRef` is keyed by query text
@@ -9313,8 +9376,8 @@ var [ui, setUi] = useState(function () {
9313
9376
  var query = String(raw === undefined || raw === null ? '' : raw).trim()
9314
9377
  var dropped = false
9315
9378
  if (query !== '') {
9316
- dropped = searchCacheRef.current.delete('content:' + query) || dropped
9317
- dropped = searchCacheRef.current.delete('name:' + query) || dropped
9379
+ dropped = searchCacheRef.current.delete(searchKey('content', query)) || dropped
9380
+ dropped = searchCacheRef.current.delete(searchKey('name', query)) || dropped
9318
9381
  }
9319
9382
  // Nothing cached: whatever is on screen came from a run that is still
9320
9383
  // fresh (or is already in flight), so a second kick would only abort it.
@@ -9325,7 +9388,7 @@ var [ui, setUi] = useState(function () {
9325
9388
  useEffect(function () {
9326
9389
  var text = treeQuery.trim()
9327
9390
  if (text === '') { setSearchHits(null); setSearchBusy(false); return undefined }
9328
- var cached = searchCacheRef.current.get('name:' + text)
9391
+ var cached = searchCacheRef.current.get(searchKey('name', text))
9329
9392
  if (cached !== undefined && cached !== null) {
9330
9393
  setSearchHits(cached)
9331
9394
  setSearchBusy(false)
@@ -9348,7 +9411,7 @@ var [ui, setUi] = useState(function () {
9348
9411
  }, controller === null ? undefined : controller.signal).then(function () {
9349
9412
  if (cancelled) return
9350
9413
  var payload = searchHitPayload({ matches: matches.slice(), dirs: {} }, cwd)
9351
- rememberSearchEntry(searchCacheRef.current, 'name:' + text, payload)
9414
+ rememberSearchEntry(searchCacheRef.current, searchKey('name', text), payload)
9352
9415
  setSearchHits(payload)
9353
9416
  setSearchBusy(false)
9354
9417
  }).catch(function (problem) {
@@ -9373,7 +9436,7 @@ var [ui, setUi] = useState(function () {
9373
9436
  useEffect(function () {
9374
9437
  var text = treeQuery.trim()
9375
9438
  if (text.length < 2) { setContentHits([]); setContentBusy(false); return undefined }
9376
- var cached = searchCacheRef.current.get('content:' + text)
9439
+ var cached = searchCacheRef.current.get(searchKey('content', text))
9377
9440
  if (cached !== undefined && Array.isArray(cached)) {
9378
9441
  setContentHits(cached)
9379
9442
  setContentBusy(false)
@@ -9393,7 +9456,7 @@ var [ui, setUi] = useState(function () {
9393
9456
  }, controller === null ? undefined : controller.signal).then(function () {
9394
9457
  if (cancelled) return
9395
9458
  var payload = hits.slice()
9396
- rememberSearchEntry(searchCacheRef.current, 'content:' + text, payload)
9459
+ rememberSearchEntry(searchCacheRef.current, searchKey('content', text), payload)
9397
9460
  setContentHits(payload)
9398
9461
  setContentBusy(false)
9399
9462
  }).catch(function (problem) {
@@ -14520,7 +14583,12 @@ var [ui, setUi] = useState(function () {
14520
14583
 
14521
14584
  if (compact) return compactPanel()
14522
14585
 
14586
+ // key = workspaceKey: the tabs, recent list and layout of the workbench are
14587
+ // initialised from that workspace's own blob at mount, so a cwd change has to
14588
+ // remount instead of keeping the previous workspace's state (评审
14589
+ // 20261109-2326 客户端 P2).
14523
14590
  return h(ProgramWorkbench, {
14591
+ key: typeof cwd === 'string' && cwd !== '' ? cwd : 'default',
14524
14592
  scope: { sessionId: sessionId, cwd: cwd },
14525
14593
  visible: true,
14526
14594
  programs: state.programs,
@@ -44,7 +44,7 @@ export const MANIFEST_FILENAME = 'manifest.json'
44
44
 
45
45
  /**
46
46
  * Where the release asset lives. `ris-proxy.4.0.tgz` (ProxyBridge 4.0 bundle) is
47
- * attached to the 1.8.0
47
+ * attached to the 1.8.1
48
48
  * release on BOTH mirrors, so a blocked network on one side still installs:
49
49
  * Gitee is the primary repository (the GitHub repo is a mirror), and it is tried
50
50
  * first. Both URLs point at the same uploaded bytes.
@@ -0,0 +1,206 @@
1
+ /**
2
+ * Health check for the downloaded ProxyBridge component (m11828).
3
+ *
4
+ * The maintenance page can say "已安装 · 文件 8 个", but that only proves the files
5
+ * were written once. A component that matters is one that can still RUN: the binary
6
+ * may be missing a sibling DLL, an anti-virus may quarantine it, or the cached
7
+ * `.exe` may be an architecture mismatch. So this module asks both side's CLI for
8
+ * its version — the cheapest proof that the executable loads — and reports file
9
+ * completeness next to it.
10
+ *
11
+ * Deliberately separated from `lib/redirector.js`: that module owns the running
12
+ * bridge; this one answers "is the component itself healthy" without starting,
13
+ * elevating or killing anything. It never blocks the HTTP loop (`execFile`).
14
+ */
15
+
16
+ import { execFile } from 'node:child_process'
17
+ import { existsSync, statSync } from 'node:fs'
18
+ import { join } from 'node:path'
19
+ import { promisify } from 'node:util'
20
+
21
+ import { bundleLayout, installDir } from './proxybridge-bundle.js'
22
+
23
+ const execFileAsync = promisify(execFile)
24
+
25
+ /** Health results are cheap to compute but spawn processes: cache them. */
26
+ export const HEALTH_TTL_MS = 30000
27
+
28
+ /** Files each side's CLI needs before it can start (the licences are not required). */
29
+ export const SIDE_FILES = Object.freeze({
30
+ linux: Object.freeze(['linux/ProxyBridge', 'linux/libproxybridge.so']),
31
+ windows: Object.freeze([
32
+ 'windows/ProxyBridge_CLI.exe',
33
+ 'windows/ProxyBridgeCore.dll',
34
+ 'windows/WinDivert.dll',
35
+ 'windows/WinDivert64.sys',
36
+ ]),
37
+ })
38
+
39
+ /** Run a command and return its output; never throws (a broken CLI is a diagnosis). */
40
+ async function runCommand(command, args, timeoutMs) {
41
+ try {
42
+ const result = await execFileAsync(command, args, { encoding: 'utf8', timeout: timeoutMs, windowsHide: true, maxBuffer: 1024 * 1024 })
43
+ return `${result.stdout ?? ''}${result.stderr ?? ''}`
44
+ } catch (error) {
45
+ return `${error?.stdout ?? ''}${error?.stderr ?? ''}${error?.message ?? ''}`
46
+ }
47
+ }
48
+
49
+ function fileState(bundleDir, relative) {
50
+ const path = join(bundleDir, relative)
51
+ try {
52
+ const stat = statSync(path)
53
+ return { path: `bundle/${relative}`, ok: stat.isFile() && stat.size > 0, size: stat.size }
54
+ } catch {
55
+ return { path: `bundle/${relative}`, ok: false, size: 0 }
56
+ }
57
+ }
58
+
59
+ function parseVersion(output) {
60
+ const match = /(\d+\.\d+\.\d+)/.exec(String(output ?? ''))
61
+ return match === null ? '' : match[1]
62
+ }
63
+
64
+ /**
65
+ * Check one side of the component.
66
+ *
67
+ * @param {{bundleDir: string, side: 'linux'|'windows', run?: Function}} options - which side.
68
+ * @returns {Promise<{side: string, ok: boolean, files: object, version: string, error?: string, checks: object[]}>}
69
+ */
70
+ async function checkSide({ bundleDir, side, run, windowsExe = '', applicable = true, skippedNote = '' }) {
71
+ const files = SIDE_FILES[side].map((relative) => fileState(bundleDir, relative))
72
+ const missing = files.filter((file) => file.ok !== true).map((file) => file.path)
73
+ if (applicable !== true) {
74
+ // Single-sided hosts are normal, not broken: a native Linux box has no Windows
75
+ // bridge, a native Windows box has no Linux bridge. Skipping keeps the card green
76
+ // (m12019).
77
+ return {
78
+ side,
79
+ applicable: false,
80
+ skipped: true,
81
+ ok: true,
82
+ files: { ok: missing.length === 0, expected: files.length, missing, entries: files },
83
+ version: '',
84
+ note: skippedNote === '' ? '本机无此侧' : skippedNote,
85
+ checks: [],
86
+ }
87
+ }
88
+ const bundleExe = join(bundleDir, side === 'windows' ? 'windows/ProxyBridge_CLI.exe' : 'linux/ProxyBridge')
89
+ // Windows cannot launch an executable from the Linux filesystem: probe the copy
90
+ // materialised under %LOCALAPPDATA% (the one the bridge actually runs). Without it
91
+ // the check honestly says "not prepared yet" instead of "broken".
92
+ const exe = side === 'windows' ? windowsExe : bundleExe
93
+ let version = ''
94
+ let error = ''
95
+ if (skippedNote !== '') {
96
+ // Files are installed but the Windows copy has not been materialised yet: that
97
+ // happens before the first bridge start, so it is "not prepared", not "broken".
98
+ return {
99
+ side,
100
+ applicable: true,
101
+ skipped: true,
102
+ ok: true,
103
+ files: { ok: missing.length === 0, expected: files.length, missing, entries: files },
104
+ version: '',
105
+ note: skippedNote,
106
+ checks: [{ id: 'files', label: '文件完整', ok: missing.length === 0, detail: `${files.length - missing.length}/${files.length}` }],
107
+ }
108
+ }
109
+ if (side === 'windows' && exe === '') {
110
+ error = '尚未复制到 Windows 侧(首次启动拦截时准备)'
111
+ } else if (existsSync(side === 'windows' ? bundleExe : exe) === true || side === 'windows') {
112
+ const output = side === 'windows'
113
+ ? await run('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', `[Console]::OutputEncoding=[System.Text.Encoding]::UTF8; & '${exe}' --version`], 8000)
114
+ : await run(exe, ['--version'], 6000)
115
+ version = parseVersion(output)
116
+ if (version === '') error = String(output).trim().split(/\r?\n/).filter((line) => line !== '').slice(-1)[0]?.slice(0, 160) ?? ''
117
+ } else {
118
+ error = '可执行文件不存在'
119
+ }
120
+ const checks = [
121
+ { id: 'files', label: '文件完整', ok: missing.length === 0, detail: missing.length === 0 ? `${files.length}/${files.length}` : `缺 ${missing.join('、')}` },
122
+ { id: 'runs', label: '可启动', ok: version !== '', detail: version === '' ? (error === '' ? '版本探测无输出' : error) : `v${version}` },
123
+ ]
124
+ return {
125
+ side,
126
+ applicable: true,
127
+ skipped: false,
128
+ ok: checks.every((check) => check.ok === true),
129
+ files: { ok: missing.length === 0, expected: files.length, missing, entries: files },
130
+ version,
131
+ ...(error === '' ? {} : { error }),
132
+ checks,
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Full component health for both sides.
138
+ *
139
+ * `engineRunning` is reported, not judged: the component can be perfectly healthy
140
+ * while interception is off (the card shows「拦截:未启动」). The maintenance page
141
+ * only *asks* for this check while the proxy engine is running (m11838), because a
142
+ * stopped engine means the component is not in use at all.
143
+ *
144
+ * @param {{home: string, engineRunning?: boolean, run?: Function, timeoutMs?: number}} options - home + dependency seam.
145
+ * @returns {Promise<{at: string, engineRunning: boolean, ok: boolean, sides: object}>} health snapshot.
146
+ */
147
+ export async function collectProxyBridgeHealth(options = {}) {
148
+ const home = String(options.home ?? '')
149
+ const bundleDir = installDir(home)
150
+ const run = typeof options.run === 'function' ? options.run : runCommand
151
+ const expected = bundleLayout().length
152
+ const installed = existsSync(join(bundleDir, 'linux/ProxyBridge')) === true || existsSync(join(bundleDir, 'windows/ProxyBridge_CLI.exe')) === true
153
+ const windowsExe = typeof options.windowsExe === 'string' ? options.windowsExe : ''
154
+ // Applicability (m12019): a single-sided host must not report a red card. Linux is
155
+ // always a candidate; Windows only when the bridge can be materialised there
156
+ // (WSL with %LOCALAPPDATA% / native Windows).
157
+ const linuxApplicable = options.linuxApplicable !== undefined ? options.linuxApplicable === true : process.platform !== 'win32'
158
+ const windowsApplicable = options.windowsApplicable !== undefined ? options.windowsApplicable === true : windowsExe !== ''
159
+ const windowsPrepared = options.windowsPrepared !== false
160
+ const [linux, windows] = await Promise.all([
161
+ checkSide({ bundleDir, side: 'linux', run, applicable: linuxApplicable, skippedNote: linuxApplicable ? '' : '本机是 Windows,没有 Linux 侧' }),
162
+ checkSide({
163
+ bundleDir,
164
+ side: 'windows',
165
+ run,
166
+ windowsExe,
167
+ applicable: windowsApplicable,
168
+ skippedNote: windowsApplicable === true && windowsPrepared !== true ? '尚未复制到 Windows 侧(首次启动拦截时准备)' : (windowsApplicable === true ? '' : '本机不是 WSL,没有 Windows 侧'),
169
+ }),
170
+ ])
171
+ const applicable = [linux, windows].filter((side) => side.applicable === true)
172
+ return {
173
+ at: new Date().toISOString(),
174
+ engineRunning: options.engineRunning === true,
175
+ installed,
176
+ expectedFiles: expected,
177
+ // ok is judged only on sides this host can run; a skipped side is neutral.
178
+ ok: applicable.every((side) => side.ok === true),
179
+ sides: { linux, windows },
180
+ }
181
+ }
182
+
183
+ /**
184
+ * Cached wrapper: version probes cost a process spawn per side.
185
+ *
186
+ * `force:true` (the card's「重新检查」) must always re-probe; everything else can
187
+ * reuse a result younger than {@link HEALTH_TTL_MS}.
188
+ */
189
+ export function createHealthCache() {
190
+ let cached = { at: 0, key: '', value: null }
191
+ return {
192
+ async get({ home, engineRunning, force = false, run, windowsExe, windowsApplicable, windowsPrepared, linuxApplicable } = {}) {
193
+ const now = Date.now()
194
+ // The applicability inputs decide WHAT is probed (native Windows vs WSL vs
195
+ // Linux), so they belong in the key: a cached "both skipped" result must not
196
+ // be served to a host that now has a side to check (review A4-P1-1).
197
+ const key = [engineRunning === true, windowsApplicable, windowsPrepared, linuxApplicable, windowsExe].join('|')
198
+ if (force !== true && cached.value !== null && now - cached.at < HEALTH_TTL_MS && cached.key === key) {
199
+ return { ...cached.value, cached: true }
200
+ }
201
+ const value = await collectProxyBridgeHealth({ home, engineRunning, run, windowsExe, windowsApplicable, windowsPrepared, linuxApplicable })
202
+ cached = { at: now, key, value }
203
+ return { ...value, cached: false }
204
+ },
205
+ }
206
+ }