dsh-ris-ide 1.7.2 → 1.7.3

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
@@ -17,11 +17,15 @@ DSH(DeepSeek Harness)Web GUI 右侧栏里的 **RIS-IDE 本地开发面板**
17
17
 
18
18
  | 侧栏「RIS控制台」:控制台 + 实时日志|
19
19
  |---|
20
- | ![侧栏「RIS控制台」](https://gitee.com/riscloud/dsh-ris-ide/raw/master/docs/screenshots/ris-console.png) |
20
+ | ![侧栏「RIS控制台」](https://raw.githubusercontent.com/ris-cloud/dsh-ris-ide/master/docs/screenshots/ris-console.png) |
21
21
 
22
22
  | 独立窗口(打开即最大化、无会话历史;控制台标题栏有 📄/⚙)|
23
23
  |---|
24
- | ![独立窗口](https://gitee.com/riscloud/dsh-ris-ide/raw/master/docs/screenshots/ris-ide-window.png) |
24
+ | ![独立窗口](https://raw.githubusercontent.com/ris-cloud/dsh-ris-ide/master/docs/screenshots/ris-ide-window.png) |
25
+
26
+ | 代理面板(🌐):全机规则表,一次启停引擎 / 系统层转发 / git 代理 |
27
+ |---|
28
+ | ![代理面板](https://raw.githubusercontent.com/ris-cloud/dsh-ris-ide/master/docs/screenshots/ris-proxy.png) |
25
29
 
26
30
  ## 功能
27
31
 
@@ -33,9 +37,32 @@ DSH(DeepSeek Harness)Web GUI 右侧栏里的 **RIS-IDE 本地开发面板**
33
37
  - **预览**:`.md/.markdown/.html/.htm` 编辑/预览切换按钮**悬浮在编辑区右上角**(不占代码行高,预览含未保存修改);超过整读上限的大文本以**只读分页预览**打开(滚到近底取下一页、内存超限释放前文、滚动位置按文件记住),标题栏「编辑」可强制全量加载进编辑(上限 32MB)。
34
38
  - **JDWP 调试(仅 Java)**:点行号加断点、双击红点删除(空行/注释行忽略);断点/线程/调用栈/变量/单步/继续;对象与数组懒加载展开、继承字段与空值也列出;依赖 jar 自动取 `-sources.jar`,没有则 `javap` 反汇编,也可在调试面板 ⚙ 填反编译 jar(如 CFR),缓存按 jar 指纹失效并有 64MB/30 天上限回收;命中后自动切「参数」页签、打开源码并高亮当前行;前端程序只能启停/看日志。
35
39
  - **独立窗口**:聊天页右上角 **⧉ RIS-IDE**(或控制台标题栏 ⧉)打开,**填满屏幕**、**不加载 DSH 界面/不带会话历史**,与侧栏同一套 `/dsh-ris-ide/*` 路由与 cookie,没有新端口;窗口按**工作空间**单例,从程序目录调试也不会开出第二个。
40
+ - **代理**:规则表是全机一份文件(`~/.dsh-ris-ide/proxy.json`),所以日常入口是 CLI/工具,不是界面——`node <dsh-ris-ide>/lib/proxy.js rules` 看表、`… start` / `… stop` 管引擎,`yds proxy sync` 从 confcenter 自动生成该项目的规则(DB/Redis/gitlab/回调网段)。控制台里的 🌐 只是**查看/手改**用的辅助面板(dsh 侧栏的控制台与独立窗口各有一个)。**一个 启动/停止 管全部三层**——本地引擎(给本插件 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` 可改位置),整机生效、不区分工作区与会话,行尾「来源」只记是哪个工作区写的。提权是正常流程: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,* 表示不限)· 命中方式`。程序列两种来源——**运行中的进程**(本侧 + Windows 侧,只列支持 SOCKS 的)或**固定程序**(文件浏览器选可执行文件,可在启动前配好;裸名按镜像名匹配,含路径则精确到那个可执行文件)。
41
+
42
+ - 弹窗**没有保存按钮**:改动在停手 700ms 后自动写盘;写的时候会过一遍校验——**新建但没填完整**的行不写入(底栏提示「N 条未填完整,未写入」),**已经在文件里**的行如果被改到一半,会连同新内容写成「停用」(提示「N 条改到一半,已置为停用」),不会留下旧内容假装生效,也不会让半截规则生效。写完本机引擎立刻生效、系统层拦截静默重启;「+ 添加规则」只追加一个空行,不会弹选择器盖住表格。
43
+ - 「选…」打开的两页签选择器:**运行中的程序**(本侧 + Windows 侧进程,只列支持 SOCKS 的)、**选择文件**;文件页签下面是**树**——点文件夹原地展开(只读被展开的那一层),点文件即选中,不再一级一级「进入目录」;顶层入口只有**根路径 `/`** 与 **Windows C:/D:**(WSL 下 `/mnt` 就是 Windows 盘,所以只有一个文件页签;在那里选中的路径会写成 `D:\…`);**没有子项的文件夹**渲染成叶子(`·`、灰一点、点不动),不会出现按下去没反应的空展开。
44
+ - 初始只给 **java / git** 两行模板(node、curl 不再自动生成;要用就自己加一行)。
45
+
46
+ **规则什么时候真的生效**:一行必须同时满足 ①已启用 ②填了程序 ③填了 IP ④填了端口——四样都显式写出才算数,要「全匹配」就写 `*`(空白**不等于**全部,半成品行在表里会用红字标「不生效:缺 IP/缺端口」,也不会进 ProxyBridge profile 和本机允许列表)。
47
+
48
+ **这些路由的信任边界**:全部只应答 loopback 请求,`sessionId` 的作用是选工作区(日志/启动目录),**不是权限凭据**——能连本机 3080 的进程就能改这台机器的规则表(与 `ris_dev_*` 系列同一模型)。若以后要收紧,正确做法是把「会话登记过的 cwd」做成白名单,而不是相信客户端传来的 `sessionId`。
49
+ **改规则不用重启**:本机引擎(`127.0.0.1` 映射 / CONNECT 允许列表)监听 `proxy.json`,保存后原地换规则、不重启进程;系统层拦截(ProxyBridge)只在启动时读 profile,由已提权的看门狗静默重启它(约 2s、不弹 UAC、不动其它程序)。
36
50
  - **给 agent 用**:内置 `ris_dev_*` 工具(列程序/状态/启动/重启/停止/读日志/调试/安装 skill),与面板共用同一套宿主命令。
37
51
  - **跨平台**:Linux/macOS 用 bash 包装;Windows 自动选 Git Bash 或原生 PowerShell 包装,停止用 `taskkill /T` 杀整棵进程树。
38
52
 
53
+ ## 相关插件:dsh-ris-yds(可选)
54
+
55
+ 如果在做 **YonBIP / YMS** 相关开发,[`dsh-ris-yds`](https://gitee.com/riscloud/dsh-ris-yds) 与本插件互补,
56
+ 提供这些辅助开发能力:
57
+
58
+ - 在本地运行 YMS 运行时,不必连远端环境;
59
+ - 访问内网数据库、缓存与内网服务;
60
+ - 准备本地开发配置,并可在「代理 / 直连」两种方式之间切换;
61
+ - 生成调用平台 API 的凭据,辅助前端调试。
62
+
63
+ - 两个插件**互不依赖**:各自都能单独安装、单独工作;装在一起时不会重复启动隧道。
64
+ - 工作区出现 YMS/YonBIP 工程特征时,`ris_dev_programs` 的返回里会附一句安装建议——只是推荐,不会调用它。
65
+
39
66
  ## 安装
40
67
 
41
68
  需要 DSH `>= 0.2.0-rc.2`,且 Web GUI 带官方右侧栏服务(`sidebarRight` / `sidebarRightTabs` / `slots`)。
@@ -0,0 +1,247 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 上架自检:把 dsh-market(awesome-dsh-plugin 目录)与 dsh.so 的收录条件,变成能在本地跑的检查。
4
+ *
5
+ * npm run check:listing
6
+ * npm run check:listing -- --json
7
+ * npm run check:listing -- --strict # 警告也算失败
8
+ * npm run check:listing -- --net # 额外尝试联网确认仓库/包公开可达(内网环境会失败)
9
+ *
10
+ * 规则来源与逐条解释在**仓库外**的插件开发手册(`docs/dsh-plugin-listing-guide.md`)。这里是**静态**检查:license 选哪个、仓库要不要公开、
11
+ * npm 包名怎么定,这些决定项脚本只能标记出来,得人定。
12
+ */
13
+ import { readFile, readdir, stat } from 'node:fs/promises'
14
+ import { existsSync } from 'node:fs'
15
+ import { join, dirname, extname, relative } from 'node:path'
16
+ import { fileURLToPath } from 'node:url'
17
+
18
+ const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
19
+ const argv = process.argv.slice(2)
20
+ const AS_JSON = argv.includes('--json')
21
+ const STRICT = argv.includes('--strict')
22
+ const NET = argv.includes('--net')
23
+
24
+ const results = []
25
+ const ok = (id, detail) => results.push({ id, level: 'ok', detail })
26
+ const warn = (id, detail) => results.push({ id, level: 'warn', detail })
27
+ const fail = (id, detail) => results.push({ id, level: 'error', detail })
28
+
29
+ async function readJson(rel) {
30
+ return JSON.parse(await readFile(join(ROOT, rel), 'utf8'))
31
+ }
32
+
33
+ async function readText(rel) {
34
+ try {
35
+ return await readFile(join(ROOT, rel), 'utf8')
36
+ } catch {
37
+ return null
38
+ }
39
+ }
40
+
41
+ /** 递归列出目录下的文件(跳过 node_modules / .git / 构建产物) */
42
+ async function listFiles(dir, acc = []) {
43
+ let entries
44
+ try {
45
+ entries = await readdir(join(ROOT, dir), { withFileTypes: true })
46
+ } catch {
47
+ return acc
48
+ }
49
+ for (const entry of entries) {
50
+ if (entry.name === 'node_modules' || entry.name === '.git' || entry.name === 'dist') continue
51
+ const rel = dir === '.' ? entry.name : `${dir}/${entry.name}`
52
+ if (entry.isDirectory()) {
53
+ await listFiles(rel, acc)
54
+ } else {
55
+ acc.push(rel)
56
+ }
57
+ }
58
+ return acc
59
+ }
60
+
61
+ const SRC_EXT = new Set(['.js', '.mjs', '.cjs', '.ts', '.tsx', '.jsx', '.sh', '.ps1', '.vue'])
62
+ const PUBLIC_HOSTS = ['github.com', 'gitee.com', 'gitlab.com']
63
+
64
+ function short(text, max = 120) {
65
+ const line = String(text).replace(/\s+/g, ' ').trim()
66
+ return line.length > max ? `${line.slice(0, max - 1)}…` : line
67
+ }
68
+
69
+ async function main() {
70
+ const pkg = await readJson('package.json')
71
+ const readme = await readText('README.md')
72
+
73
+ // ── dsh.so:插件 id(slug) ───────────────────────────────────────────────
74
+ const bareName = String(pkg.name || '').replace(/^@[^/]+\//, '')
75
+ if (/^[a-z0-9]+(-[a-z0-9]+)*$/.test(bareName)) ok('插件 id(slug)', `"${pkg.name}" → ${bareName} 匹配 ^[a-z0-9]+(-[a-z0-9]+)*$`)
76
+ else fail('插件 id(slug)', `"${pkg.name}" 不匹配 ^[a-z0-9]+(-[a-z0-9]+)*$:改成小写 kebab-case(scoped 包只校验 scope 后的段)`)
77
+
78
+ // ── 版本:市场展示的是最新正式版 ─────────────────────────────────────────
79
+ if (/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(String(pkg.version || ''))) {
80
+ if (String(pkg.version).includes('-')) warn('版本号', `${pkg.version} 是预发布版;市场/dsh.so 展示 latest 语义时应发布 X.Y.Z 正式版(快照只用于本地)`)
81
+ else ok('版本号', `${pkg.version}(合法 semver,正式版)`)
82
+ } else {
83
+ fail('版本号', `"${pkg.version}" 不是合法 semver`)
84
+ }
85
+
86
+ // ── dsh.so:DSH 兼容信号(至少一个) ─────────────────────────────────────
87
+ const signals = []
88
+ if (pkg.dsh && typeof pkg.dsh === 'object') signals.push('package.json 的 dsh 字段')
89
+ if (pkg.dsh?.bundle?.patch) signals.push(`dsh.bundle.patch = ${pkg.dsh.bundle.patch}`)
90
+ if (pkg.dsh?.plugin) signals.push('dsh.plugin.* manifest')
91
+ if (pkg.engines?.dsh) signals.push(`engines.dsh = ${pkg.engines.dsh}`)
92
+ if (existsSync(join(ROOT, 'cordis.patch.yml'))) signals.push('cordis.patch.yml')
93
+ if (existsSync(join(ROOT, 'agent.cordis.yml'))) signals.push('agent.cordis manifest')
94
+ if (signals.length) ok('DSH 兼容信号', signals.join(';'))
95
+ else fail('DSH 兼容信号', '缺少全部信号(dsh 字段 / cordis manifest / dsh-plugin topic)')
96
+
97
+ // ── dsh.so:README 含安装说明 ────────────────────────────────────────────
98
+ if (!readme) fail('README 安装说明', '没有 README.md')
99
+ else {
100
+ const installLines = readme
101
+ .split('\n')
102
+ .filter((line) => /dsh plugin --profile \S+ add /.test(line))
103
+ // 「公开」口径:这条安装命令不依赖内网 registry,市场用户照抄就能装
104
+ const publicLine = installLines.find(
105
+ (line) => !/registry=|\.npmrc|repository\/npm-/.test(line) && !/@\d/.test(line),
106
+ )
107
+ if (installLines.length === 0) {
108
+ fail('README 安装说明', 'README 里找不到 `dsh plugin --profile <p> add …`')
109
+ } else if (publicLine) {
110
+ ok('README 安装说明', `含公开可直接抄的安装命令:${short(publicLine, 80)}${installLines.length > 1 ? `(另有 ${installLines.length - 1} 条内网/带版本号的备选)` : ''}`)
111
+ } else {
112
+ warn('README 安装说明', '安装命令都指向内部 registry 或写死了版本号;公开上架需要一条不依赖内网、不写死版本的 `dsh plugin --profile web add <包名>`')
113
+ }
114
+ }
115
+
116
+ // ── dsh.so:开源 license + SPDX ─────────────────────────────────────────
117
+ const licenseFiles = (await listFiles('.')).filter((f) => /^LICEN[CS]E(\..*)?$/i.test(f))
118
+ const spdx = typeof pkg.license === 'string' ? pkg.license.trim() : ''
119
+ const spdxOk = /^[A-Za-z0-9.+-]+$/.test(spdx) && !/^(UNLICENSED|SEE LICENSE IN .*|PROPRIETARY)$/i.test(spdx)
120
+ if (spdxOk && licenseFiles.length) ok('License(SPDX)', `${spdx},文件:${licenseFiles.join(', ')}`)
121
+ else if (!spdx && !licenseFiles.length) fail('License(SPDX)', '既没有 package.json 的 license 字段,也没有 LICENSE 文件;dsh.so 要求开源许可证 + 可识别 SPDX(UNLICENSED 不算)')
122
+ else if (!spdx) fail('License(SPDX)', `有 ${licenseFiles.join(', ')} 但 package.json 缺 license 字段(要写 SPDX id)`)
123
+ else fail('License(SPDX)', `license 字段是 "${spdx}",不是可识别的 SPDX 开源标识`)
124
+
125
+ // ── dsh.so:可扫描源码 ───────────────────────────────────────────────────
126
+ const sourceFiles = (await listFiles('.')).filter((f) => SRC_EXT.has(extname(f).toLowerCase()))
127
+ if (sourceFiles.length >= 3) ok('可扫描源码', `${sourceFiles.length} 个源码/脚本文件(如 ${sourceFiles.slice(0, 3).join(', ')}…)`)
128
+ else fail('可扫描源码', `只找到 ${sourceFiles.length} 个可扫描文件;docs-only / 空仓库不能提交`)
129
+
130
+ // ── dsh-market:安装来源(npm 包名) ─────────────────────────────────────
131
+ if (typeof pkg.name === 'string' && pkg.name) ok('npm 包名(目录 install 字段)', `${pkg.name}(目录里 npm/version 取自公开 registry)`)
132
+ else fail('npm 包名', 'package.json 缺 name')
133
+
134
+ // ── dsh.so:仓库地址(公开托管 + topic) ──────────────────────────────────
135
+ const repoUrl = typeof pkg.repository === 'string' ? pkg.repository : pkg.repository?.url
136
+ if (!repoUrl) {
137
+ fail('公开仓库地址', 'package.json 缺 repository(dsh.so 只收 GitHub / Gitee / GitLab,且用它同步星数/license/最后提交)')
138
+ } else {
139
+ const cleaned = String(repoUrl).replace(/^git\+/, '')
140
+ const host = (cleaned.match(/^https?:\/\/([^/]+)/) || [])[1] || ''
141
+ if (PUBLIC_HOSTS.some((h) => host === h || host.endsWith(`.${h}`))) ok('公开仓库地址', `${cleaned}(${host})`)
142
+ else fail('公开仓库地址', `${cleaned} 的 host 是 "${host || '未知'}";dsh.so 只认 GitHub/Gitee/GitLab`)
143
+ }
144
+ if (pkg.homepage || pkg.bugs?.url) ok('homepage / bugs', short(pkg.homepage || pkg.bugs.url))
145
+ else warn('homepage / bugs', '建议补 homepage / bugs(市场卡片与 issue 入口会用到)')
146
+
147
+ // ── dsh.so:topic(只能人工在仓库上加,本地无法验证) ────────────────────
148
+ const topics = Array.isArray(pkg.keywords) ? pkg.keywords.map((k) => String(k).toLowerCase()) : []
149
+ if (topics.includes('dsh-plugin') || topics.includes('dsh-pack')) ok('keywords 的 dsh-plugin', 'package.json keywords 含 dsh-plugin / dsh-pack')
150
+ else warn('keywords 的 dsh-plugin', 'package.json keywords 缺 dsh-plugin(同时记得在 GitHub 仓库加 topic `dsh-plugin`,dsh.so 靠它自动索引;这条只能人在仓库里加)')
151
+
152
+ // ── dsh-market:双语描述 ─────────────────────────────────────────────────
153
+ const desc = String(pkg.description || '')
154
+ // 目录条目需要 en/zh 两条描述;package.json 只有一个 description,至少要求它能当英文文案用
155
+ //(判定口径:连续 15 个 ASCII 字母/空格/标点,短串像 "Spring Boot" 不算一句英文)
156
+ if (!desc) fail('描述(en + zh)', 'package.json 缺 description')
157
+ else if (/[A-Za-z][A-Za-z ,.'’/()-]{15,}/.test(desc)) ok('描述(en + zh)', `package.json description 含英文句子:${short(desc, 80)}`)
158
+ else warn('描述(en + zh)', `description 只有中文/短英文(${short(desc, 60)});目录条目要自己写 en/zh 两条(市场按 UI 语言显示),建议把英文句也写进 README 首段`)
159
+
160
+ // ── dsh-market:README 截图(只从 GitHub 托管加载) ──────────────────────
161
+ const shots = readme ? (readme.match(/!\[[^\]]*\]\(([^)]+)\)/g) || []).length : 0
162
+ if (shots >= 2) ok('README 截图', `${shots} 张(市场卡片是轮播,仓库托管即可)`)
163
+ else warn('README 截图', `README 只有 ${shots} 张图;市场卡片需要 2–4 张(侧栏控制台 / 独立窗口 / 调试面板),且必须由 GitHub 托管`)
164
+
165
+ // ── 安全扫描启发式(dsh.so 阻断项:硬编码密钥 / 私钥) ───────────────────
166
+ const scanTargets = sourceFiles.filter((f) => !/client-codemirror\.js$/.test(f)).slice(0, 400)
167
+ const secretPatterns = [
168
+ { name: '私钥块', re: /-----BEGIN [A-Z ]*PRIVATE KEY-----/ },
169
+ { name: 'AWS Access Key', re: /\bAKIA[0-9A-Z]{16}\b/ },
170
+ { name: 'GitHub token', re: /\bghp_[A-Za-z0-9]{36}\b/ },
171
+ { name: 'OpenAI 风格 key', re: /\bsk-[A-Za-z0-9]{20,}\b/ },
172
+ { name: '疑似硬编码口令', re: /\b(?:password|passwd|secret|apiKey|api_key)\s*[:=]\s*['"][^'"\s]{6,}['"]/i },
173
+ ]
174
+ const hits = []
175
+ for (const rel of scanTargets) {
176
+ const text = await readText(rel)
177
+ if (!text) continue
178
+ for (const { name, re } of secretPatterns) {
179
+ if (re.test(text)) hits.push(`${rel} → ${name}`)
180
+ }
181
+ }
182
+ if (hits.length) warn('安全扫描(硬编码密钥)', `${hits.length} 处命中,提交前逐条确认是否误报:${hits.slice(0, 5).join(';')}`)
183
+ else ok('安全扫描(硬编码密钥)', `${scanTargets.length} 个文件扫描,无私钥/密钥字面量命中`)
184
+
185
+ // ── 能力声明(本插件一定会带的外围能力,提交时会被人工复核) ──────────────
186
+ ok(
187
+ '能力边界(人工复核项)',
188
+ '插件会:启动/停止进程(含杀进程组)、读写工作区文件、读环境变量、注册 agent 工具。dsh.so 扫描会标出 fs-write/env/process,README 需写清用途与围栏(loopback 校验、pidfile 校验、路径限制)',
189
+ )
190
+
191
+ // ── 可选联网核对 ─────────────────────────────────────────────────────────
192
+ if (NET) {
193
+ await checkNetwork(pkg, repoUrl)
194
+ } else {
195
+ warn('公开可达性(可选)', '跳过联网核对(--net 开启);内网环境通常不可达,可在有外网的机器上跑')
196
+ }
197
+
198
+ report()
199
+ }
200
+
201
+ async function head(url) {
202
+ try {
203
+ const res = await fetch(url, { method: 'HEAD', redirect: 'follow', signal: AbortSignal.timeout(8000) })
204
+ return res.ok || res.status === 405
205
+ } catch {
206
+ return false
207
+ }
208
+ }
209
+
210
+ async function checkNetwork(pkg, repoUrl) {
211
+ const npmUrl = `https://registry.npmjs.org/${encodeURIComponent(pkg.name).replace('%2F', '/')}`
212
+ const npmOk = await head(npmUrl)
213
+ if (npmOk) ok('公开 npm 可达', `${npmUrl} 200`)
214
+ else fail('公开 npm 可达', `${npmUrl} 不可达:需先发布到公开 npm(只发在内部 registry 的包,市场装不到)`)
215
+
216
+ if (repoUrl) {
217
+ const url = String(repoUrl).replace(/^git\+/, '').replace(/\.git$/, '')
218
+ const repoOk = await head(url)
219
+ if (repoOk) ok('公开仓库可达', `${url} 200`)
220
+ else fail('公开仓库可达', `${url} 不可达或需要登录:dsh.so/dsh-market 都要公开可拉取`)
221
+ }
222
+ }
223
+
224
+ function report() {
225
+ const errors = results.filter((r) => r.level === 'error')
226
+ const warns = results.filter((r) => r.level === 'warn')
227
+ const icon = { ok: '✅', warn: '⚠️ ', error: '❌' }
228
+ if (AS_JSON) {
229
+ console.log(JSON.stringify({ ok: errors.length === 0, errors: errors.length, warnings: warns.length, results }, null, 2))
230
+ } else {
231
+ console.log('\n上架条件自检(dsh-market / dsh.so)· 规则见仓库外插件开发手册\n')
232
+ for (const r of results) {
233
+ console.log(`${icon[r.level]} ${r.id}`)
234
+ if (r.detail) console.log(` ${r.detail}`)
235
+ }
236
+ console.log(`\n合计:${results.length} 项 · ❌ ${errors.length} · ⚠️ ${warns.length}`)
237
+ if (errors.length) {
238
+ console.log('\n必须先解决:')
239
+ for (const r of errors) console.log(` ❌ ${r.id} — ${r.detail}`)
240
+ }
241
+ if (!errors.length) console.log(warns.length && !STRICT ? '\n静态条件里没有阻断项;⚠️ 需要人确认。' : '\n全部通过。')
242
+ }
243
+ const failed = errors.length > 0 || (STRICT && warns.length > 0)
244
+ process.exitCode = failed ? 1 : 0
245
+ }
246
+
247
+ await main()
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Detached proxy janitor.
4
+ *
5
+ * Started by `armJanitor()` with the pid of the dsh process that owns the proxy
6
+ * layers. Polls that pid; when it disappears (graceful exit, crash, `kill -9`,
7
+ * closed terminal) it performs the same cleanup the exit hook does, then exits.
8
+ *
9
+ * Nothing here needs dsh: it runs in its own session, with only the state files
10
+ * (`proxy.pid`, `proxybridge.local.pid` / `proxybridge.windows.pid`,
11
+ * `proxybridge-service.json`, `git-proxy.json`) as input.
12
+ *
13
+ * A test run must never clean the real machine: janitor.js answers "no bridge" for
14
+ * the bridge probe when NODE_TEST_CONTEXT is set, and the layer seams keep the
15
+ * cleanup unit-testable without PowerShell.
16
+ *
17
+ * Usage: proxy-janitor.mjs --owner <pid> [--home <proxy home>] [--poll <ms>]
18
+ */
19
+ import { appendFileSync, mkdirSync, unlinkSync } from 'node:fs'
20
+ import { join } from 'node:path'
21
+
22
+ import { JANITOR_POLL_MS, cleanupSideEffects, janitorStatePath, pendingSideEffects } from '../lib/janitor.js'
23
+
24
+ /** Parse `--flag value` pairs without pulling in a dependency. */
25
+ function parse(argv) {
26
+ const out = {}
27
+ for (let i = 0; i < argv.length; i += 1) {
28
+ const token = argv[i]
29
+ if (token.startsWith('--')) {
30
+ out[token.slice(2)] = argv[i + 1]
31
+ i += 1
32
+ }
33
+ }
34
+ return out
35
+ }
36
+
37
+ const args = parse(process.argv.slice(2))
38
+ const owner = Number.parseInt(args.owner ?? '', 10)
39
+ const poll = Number.parseInt(args.poll ?? '', 10) || JANITOR_POLL_MS
40
+ const logPath = join(args.home ?? process.env.DSH_RIS_IDE_PROXY_HOME ?? '.', 'janitor.log')
41
+
42
+ function log(line) {
43
+ try {
44
+ mkdirSync(join(args.home ?? process.env.DSH_RIS_IDE_PROXY_HOME ?? '.'), { recursive: true })
45
+ appendFileSync(logPath, `${new Date().toISOString()} [${process.pid}] ${line}\n`)
46
+ } catch {
47
+ /* logging must never take the janitor down */
48
+ }
49
+ }
50
+
51
+ if (!Number.isInteger(owner) || owner <= 0) {
52
+ log('缺少 --owner <pid>,退出')
53
+ process.exit(2)
54
+ }
55
+
56
+ function alive(pid) {
57
+ try {
58
+ process.kill(pid, 0)
59
+ return true
60
+ } catch (error) {
61
+ return error?.code === 'EPERM'
62
+ }
63
+ }
64
+
65
+ log(`监视 dsh ${owner}(轮询 ${poll}ms,状态 ${janitorStatePath()})`)
66
+
67
+ const timer = setInterval(() => {
68
+ if (alive(owner)) return
69
+ clearInterval(timer)
70
+ const pending = pendingSideEffects()
71
+ log(`dsh ${owner} 已退出,开始清理: ${JSON.stringify(pending)}`)
72
+ try {
73
+ const done = cleanupSideEffects({ log })
74
+ log(`清理完成: ${JSON.stringify({ engine: done.engine, bridge: done.bridge, service: done.service, git: done.git })}`)
75
+ } catch (error) {
76
+ log(`清理异常: ${error?.message ?? error}`)
77
+ }
78
+ try {
79
+ // Our own state file is the last thing to go: while it exists, `yds proxy
80
+ // status` reports a watcher, and a fresh start re-arms instead of doubling.
81
+ unlinkSync(janitorStatePath())
82
+ } catch {
83
+ /* already gone */
84
+ }
85
+ process.exit(0)
86
+ // The interval must stay referenced: an unreferenced timer lets node exit
87
+ // immediately, which is the opposite of a watchdog.
88
+ })