dsh-progress-union 0.7.2 → 0.7.4
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/CHANGELOG.md +27 -0
- package/README.md +5 -1
- package/client.js +1 -1
- package/dsh.plugin.json +1 -1
- package/index.js +57 -10
- package/package.json +1 -1
- package/test/download-classify.test.mjs +85 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
本项目的所有值得记录的变更都写在这里。版本号遵循语义化版本。
|
|
4
4
|
|
|
5
|
+
## 0.7.4 (2026-12-04)
|
|
6
|
+
|
|
7
|
+
**fix(download):工具名本身就是解释器(实测 `pwsh`)时不再被 `isShell` 门拦下。**
|
|
8
|
+
|
|
9
|
+
真机回灌(沙箱宿主 0.2.2-rc.5 + dsh-progress-union 0.7.3):改发 `curl.exe -L -o dl073/echarts.tgz http://registry.npmmirror.com/…`,面板 88 帧探针仍 `basis=""` / `subbar=NO-SUBBAR`。但板面 `current` 供出了真因:`自动同步:pwsh · command=New-Item -ItemType Directory -Force -Path dl073 | Out-Null; curl.exe -` —— 这行里的 `pwsh` 是 `lastTool.name`,即宿主把跑命令的工具直接报成解释器名,而不是 `Bash`。0.7.3 只修了命令词表,而 `classifyDownload` 在 `isShell` 那道门上就 `return null`,后面的首词归一与引号体拆分根本轮不到。
|
|
10
|
+
|
|
11
|
+
- **新增 `SHELL_INTERPRETERS` + `isShellToolName()`**:除工具名白名单外,再认一批「解释器即工具名」的形状(`sh/bash/zsh/ksh/dash/fish/nu/xonsh/busybox/pwsh/powershell/powershell_ise/cmd/command.com`),判定前先取 basename 并剥 `.exe/.cmd/.bat/.ps1`,所以 `C:\Program Files\PowerShell\7\pwsh.exe` 也算 shell 通道。
|
|
12
|
+
- **两处消费面同时接入**:`classifyDownload` 的 `isShell` 门改为 `isShellToolName(toolKey)`;`describeToolStep` 的 shell 分支同样改用它 —— 否则 Windows 会话里「工序人话」依旧退回 `pwsh` 裸名而不是一句话。
|
|
13
|
+
- **白名单补齐**:`SHELL_TOOL_NAMES` 补 `shell_exec / shell_run / run_shell / terminal_run`(宿主侧另一类常见命法)。
|
|
14
|
+
- **不放宽误判面**:`read_file` / `mcp__tools__fetch` 这类不在词表里的工具名,即使参数里带了 `command` 也仍然返回 `null`;解释器名但拿不出命令文本同样 `null`(软感知纪律不变)。
|
|
15
|
+
- **测试**:`test/download-classify.test.mjs` +3 用例(共 22):pwsh/powershell 工具名命中真机命令串、非 shell 工具名不得被解释器名规则误放、`describeToolStep('pwsh', …)` 出人话。`npm test` **242 pass / 0 fail**(239 → +3),零回归。
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## 0.7.3 (2026-12-04)
|
|
19
|
+
|
|
20
|
+
**fix(download):Windows 宿主上 `curl.exe` / `Invoke-WebRequest` / `pwsh -Command "…"` 全漏识别,下载子条根本不出来。**
|
|
21
|
+
|
|
22
|
+
真机回灌(沙箱宿主 0.2.2-rc.5 + dsh-progress-union 0.7.2):让模型跑 `mkdir -p dl072 && curl -L -o dl072/node.tar.gz https://…`,整个回合里 `snapshot.download` 恒为 idle、`.pb-dock-dl` 一次都没渲染(DOM 探针 20+ 次全为 `NO-SUBBAR`,后台轮询 0 样本)。查下来不是网络问题(curl 因 SChannel `SEC_E_NO_CREDENTIALS` 零字节退出),而是 **分类器只认 POSIX 首词**:DSH 的 Bash 工具在 Windows 上实落 pwsh,命令名带 `.exe` 后缀与路径前缀,首词比对永远对不上。
|
|
23
|
+
|
|
24
|
+
- **首词归一**:新增 `normalizeHead()`——剥引号、取 basename(`\\` 与 `/` 都给)、去 `.exe/.cmd/.bat/.ps1` 后缀。`headWord()` 与三处 `findIndex(w => w.toLowerCase() === head)`(classifyDownload / glossCommand)统一改用它。于是 `C:\Windows\System32\curl.exe -O …`、`/mingw64/bin/git.exe clone …`、`WGET.EXE -q …` 均能识别。
|
|
25
|
+
- **shell 包层拆引号体**:新增 `wrapperSegments()`(`pwsh|powershell|sh|bash|zsh|dash|cmd|wsl` + `-Command|-c|/c|-file` 后的引号体再切一段,只拆一层不递归),并入 `classifyDownload` 的逐段循环。`pwsh -Command "curl.exe -L -o out.bin …"` 不再因为外层首词是 `pwsh` 而整条静默。
|
|
26
|
+
- **PowerShell 自有下载词入表**:`DOWNLOADERS` 补 `invoke-webrequest / iwr / invoke-restmethod / irm / start-bitstransfer`;`firstOperand` 的输出型 flag 扩到 `-OutFile / -FilePath / -Destination / -Uri` 等(`iwr URL -OutFile a.txt` 目标取 URL 末段,`iwr -Uri URL -OutFile big.iso` 目标取文件名)。
|
|
27
|
+
- **工序可解释同步**:`HEAD_GLOSS` 补 `invoke-webrequest/iwr → 下载文件`、`invoke-restmethod/irm → 发 HTTP 请求`、`start-bitstransfer → 传输文件`、`new-item → 建目录或文件`、`set-variable → 设环境变量`、`test-path → 查路径`,避免 Windows 会话里「最近动作」退回 `Bash×n`。
|
|
28
|
+
- **不误判**:新增反例用例 — `pwsh -Command "Get-Process | …"`、`git.exe status --short`、`New-Item -ItemType Directory out` 仍必须返回 `null`(软感知只认词表,不做语义猜)。POSIX 旧用例零修改全绿。
|
|
29
|
+
- **测试**:`test/download-classify.test.mjs` +5 用例(共 19),`npm test` **239 pass / 0 fail**(234 → +5),零回归。
|
|
30
|
+
|
|
31
|
+
|
|
5
32
|
## 0.7.2 (2026-12-04)
|
|
6
33
|
|
|
7
34
|
**feat(ops):侧边栏 LLM 任务操作面补上整块开关 `ops.enabled`,关掉后不枚举宿主、不发 token、面板整块收起。**
|
package/README.md
CHANGED
|
@@ -268,7 +268,7 @@ assistant:
|
|
|
268
268
|
## 开发与测试
|
|
269
269
|
|
|
270
270
|
```bash
|
|
271
|
-
npm test # node --test test/*.test.mjs(
|
|
271
|
+
npm test # node --test test/*.test.mjs(242 用例,纯 mock ctx,无需宿主进程)
|
|
272
272
|
```
|
|
273
273
|
|
|
274
274
|
## 冷启动接续(v0.6.2)
|
|
@@ -291,6 +291,10 @@ npm test # node --test test/*.test.mjs(234 用例,纯 mock ctx,无需宿
|
|
|
291
291
|
|
|
292
292
|
识别结果进两条出口:观察块多一行下载事实(动作 · 目标 · 已下字节 · 耗时 · 真值来源),以及 `snapshot.download`(供客户端子条)。配置 `download.enabled=false` 整条链路关闭,`snapshot` 少一个字段,UI 逐字退回 0.6.x。
|
|
293
293
|
|
|
294
|
+
**Windows 宿主形状(v0.7.3)**:DSH 的 Bash 工具在 Windows 上实落 pwsh,命令名常带 `.exe` 后缀与路径前缀,真下载还常被裹在 `pwsh -Command "…"` 的引号体里。分类器因此做三件事:首词先过 `normalizeHead`(剥引号 → 取 basename → 去 `.exe/.cmd/.bat/.ps1`),shell 包层的引号体额外再切一段(只拆一层),下载器词表补 PowerShell 自有的 `Invoke-WebRequest/iwr/Invoke-RestMethod/irm/Start-BitsTransfer`。反例仍然拦得住:`git.exe status`、`New-Item -ItemType Directory`、`pwsh -Command "Get-Process …"` 依旧返回 `null`。
|
|
295
|
+
|
|
296
|
+
**工具名即解释器(v0.7.4)**:上面那些只修到命令串,而真机上更靠外的一道门是工具名本身——宿主在 Windows 上报的是 `pwsh` 而不是 `Bash`,不在 shell 名单里时整条识别直接结束。现在 `isShellToolName()` 先取 basename 并剥 `.exe/.cmd/.bat/.ps1`,再比对解释器集(`pwsh/powershell/sh/bash/zsh/ksh/dash/fish/nu/xonsh/busybox/cmd`),`classifyDownload` 的 `isShell` 门与 `describeToolStep` 的 shell 分支共用它,所以子条与工序人话在 `pwsh` 会话里一起活过来。不在词表里的工具名(`read_file` 等)即使带 `command` 仍不算 shell 通道。
|
|
297
|
+
|
|
294
298
|
## 下载子进度条(v0.7.0)
|
|
295
299
|
|
|
296
300
|
输入框上方的迷你条在主条行之后渲染一行子条,真值全部来自本插件自解析 `tool/result`(`parseProgress` 覆盖 wget/curl 的 `45%` 与 `12.3MB/27.8MB`、pip/uv 单尾单位、git `Receiving objects: 62%`、pnpm `[3/12]`),**零跨插件依赖**。
|
package/client.js
CHANGED
|
@@ -24,7 +24,7 @@ window.__ModuleLoader__.load({
|
|
|
24
24
|
var REPO_URL = "https://github.com/drscrewdriver/dsh-progress-union";
|
|
25
25
|
var STAR_NS = "progress-union";
|
|
26
26
|
var STAR_GEN = "v4"; /* ladder:gen */
|
|
27
|
-
var STAR_VERSION = "0.7.
|
|
27
|
+
var STAR_VERSION = "0.7.4"; /* ladder:ver */
|
|
28
28
|
var LANGS = ["zh", "en", "ja", "ko", "fr", "de", "it", "ru", "es", "pt"];
|
|
29
29
|
|
|
30
30
|
// 三代共享:GitHub 单色 mark(octicon 轮廓,fill 随 currentColor)。
|
package/dsh.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "dsh-external/dsh-progress-union",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"description": "进度结合原型:board 槽位真相源(用户可编辑、diff+ack 增量同步、staleness nudge)× 鲸程时间引擎(step 计数、ETA 三档 board>todo>local>prior、悬浮迷你条),向压缩插件暴露只读三层进度锚点 progressAnchor(board 语义锚 + time 时间锚 + userEdits 未确认改动,service 与 HTTP 双平面),并在 0.6.0 起每回合落一版会话归档(handoff 规则摘要 + 重启注入一次)。",
|
|
6
6
|
"engines": {
|
package/index.js
CHANGED
|
@@ -173,11 +173,24 @@ export const inject = ['tools', 'systemPrompt', 'webServer', 'agents', 'commands
|
|
|
173
173
|
// ============================================================================
|
|
174
174
|
|
|
175
175
|
// 跑命令的工具名(跨宿主常见命名,大小写不敏感)。
|
|
176
|
-
const SHELL_TOOL_NAMES = new Set(['bash', 'shell', 'terminal', 'terminal_send', 'terminal_exec', 'exec', 'execute', 'run', 'run_command', 'command', 'cmd'])
|
|
176
|
+
const SHELL_TOOL_NAMES = new Set(['bash', 'shell', 'terminal', 'terminal_send', 'terminal_exec', 'exec', 'execute', 'run', 'run_command', 'command', 'cmd', 'shell_exec', 'shell_run', 'run_shell', 'terminal_run'])
|
|
177
177
|
// 本身就是「把东西拉到本地」语义的工具名(非 shell 通道)。
|
|
178
178
|
const FETCH_TOOL_NAMES = new Set(['download', 'download_file', 'fetch_file', 'git_clone'])
|
|
179
179
|
// 明确的后台执行器:走 shell 词表,但默认记为 background。
|
|
180
180
|
const BACKGROUND_TOOL_NAMES = new Set(['background_exec', 'exec_background', 'shell_background', 'run_in_background', 'terminal_spawn'])
|
|
181
|
+
// 0.7.4 真机回灌:宿主会把「跑命令」的工具名直接报成解释器本身——Windows 上实测是
|
|
182
|
+
// `pwsh`(不是 `Bash`)。只列 bash/shell/terminal 家族的话 isShell=false,下载识别
|
|
183
|
+
// 与工序人话在第一道门就整体失效,UI 永远看不到子进度条。
|
|
184
|
+
const SHELL_INTERPRETERS = new Set(['sh', 'bash', 'zsh', 'ksh', 'dash', 'fish', 'nu', 'xonsh', 'busybox', 'pwsh', 'powershell', 'powershell_ise', 'cmd', 'command.com'])
|
|
185
|
+
|
|
186
|
+
/** 这个工具名是不是「跑一条命令」的通道(含后台执行器与解释器名形态)。 */
|
|
187
|
+
function isShellToolName(raw) {
|
|
188
|
+
const key = String(raw || '').toLowerCase()
|
|
189
|
+
if (!key) return false
|
|
190
|
+
if (SHELL_TOOL_NAMES.has(key) || BACKGROUND_TOOL_NAMES.has(key)) return true
|
|
191
|
+
const name = key.split(/[\\/]/).pop().replace(/\.(?:exe|cmd|bat|ps1)$/, '')
|
|
192
|
+
return SHELL_INTERPRETERS.has(name)
|
|
193
|
+
}
|
|
181
194
|
|
|
182
195
|
// 包管理器 / 安装器的「动词」集合:只在这些动词后才是真正的下载/安装。
|
|
183
196
|
// 排除 test/list/status/run/show/freeze —— 它们不产生网络拉取(误判会把每次 npm test 当下载)。
|
|
@@ -200,7 +213,10 @@ const INSTALLERS = new Map([
|
|
|
200
213
|
])
|
|
201
214
|
|
|
202
215
|
// 单一下载器:命令首词即意图,无需第二个动词。
|
|
203
|
-
|
|
216
|
+
// 后五个是 Windows 宿主实测形状:Bash 工具落 pwsh 时,模型常写
|
|
217
|
+
// `curl.exe -L -o …` 或 `Invoke-WebRequest -Uri …`,只认 POSIX 名的话整条漏识别。
|
|
218
|
+
const DOWNLOADERS = new Set(['curl', 'wget', 'aria2c', 'axel', 'rsync', 'scp', 'aws', 'gcs', 'rclone',
|
|
219
|
+
'invoke-webrequest', 'iwr', 'invoke-restmethod', 'irm', 'start-bitstransfer'])
|
|
204
220
|
|
|
205
221
|
// 把 `act` 包装透传回内层工具(宿主侧 act 的入参形状就是 `{tool, input}`)。
|
|
206
222
|
// 只做一层,不递归展开嵌套 input:够用来避免「观察者把动作误记成 act」,不因此引入依赖。
|
|
@@ -226,20 +242,47 @@ function commandSegments(command) {
|
|
|
226
242
|
|
|
227
243
|
// 跳过 env/时间/权限等前缀词,拿到真正的命令名。
|
|
228
244
|
const COMMAND_PREFIX_WORDS = new Set(['sudo', 'env', 'time', 'nohup', 'doas', 'command', 'nice', 'setsid', 'noglob', 'cross-env', 'xargs'])
|
|
245
|
+
// 真下载藏在引号体里时的外层壳:`pwsh -Command "curl.exe …"` / `sh -c 'wget …'` / `cmd /c "…"`。
|
|
246
|
+
const SHELL_WRAPPERS = /(?:^|[\s;&(])(?:pwsh|powershell|sh|bash|zsh|dash|cmd|wsl)(?:\.exe)?[\s]+(?:-{0,2}(?:command|c|file|login|noexit|nologo)[\s]*|\/c[\s]+)("[^"]*"|'[^']*'|`[^`]*`)/gi
|
|
247
|
+
/**
|
|
248
|
+
* 首词归一(Windows 实测必修):剥引号、取 basename、去 `.exe/.cmd/.bat/.ps1` 后缀。
|
|
249
|
+
* 不这么做的话 `C:\Windows\System32\curl.exe`、`/mingw64/bin/git.exe` 全都认不出。
|
|
250
|
+
*/
|
|
251
|
+
function normalizeHead(word) {
|
|
252
|
+
let w = String(word || '').toLowerCase().replace(/^['"`]+/, '').replace(/['"`;)]+$/, '')
|
|
253
|
+
if (!w) return ''
|
|
254
|
+
w = w.split(/[\\/]/).pop()
|
|
255
|
+
return w.replace(/\.(?:exe|cmd|bat|ps1)$/, '')
|
|
256
|
+
}
|
|
229
257
|
function headWord(words) {
|
|
230
258
|
for (const w of words) {
|
|
231
|
-
const key = w
|
|
232
|
-
if (
|
|
259
|
+
const key = normalizeHead(w)
|
|
260
|
+
if (!key) continue
|
|
261
|
+
if (COMMAND_PREFIX_WORDS.has(key) || w.trim().startsWith('-')) continue
|
|
233
262
|
return key
|
|
234
263
|
}
|
|
235
264
|
return ''
|
|
236
265
|
}
|
|
237
266
|
|
|
267
|
+
// 把 shell 包层的引号体再切成段(只拆一层,不递归解嵌套引号——够用来补 Windows 漏识别)。
|
|
268
|
+
function wrapperSegments(command) {
|
|
269
|
+
const out = []
|
|
270
|
+
SHELL_WRAPPERS.lastIndex = 0
|
|
271
|
+
let m
|
|
272
|
+
while ((m = SHELL_WRAPPERS.exec(String(command || '')))) out.push(...commandSegments(m[1]))
|
|
273
|
+
return out
|
|
274
|
+
}
|
|
275
|
+
|
|
238
276
|
// 取第一个非 flag 词作为目标(包名 / 镜像 / URL)。
|
|
239
277
|
function firstOperand(words, from) {
|
|
240
278
|
for (let i = from; i < words.length; i++) {
|
|
241
279
|
const w = words[i]
|
|
242
|
-
if (
|
|
280
|
+
if (/^(?:-o|-O|--output|--target|-t|--?outfile|-out-file|--filepath|-file|-destination|--url)$/i.test(w)) {
|
|
281
|
+
const nxt = words[i + 1]
|
|
282
|
+
if (nxt && !nxt.startsWith('-')) return nxt
|
|
283
|
+
continue
|
|
284
|
+
}
|
|
285
|
+
if (w.startsWith('-')) continue
|
|
243
286
|
return w
|
|
244
287
|
}
|
|
245
288
|
return ''
|
|
@@ -272,18 +315,18 @@ function classifyDownload(name, argsRaw) {
|
|
|
272
315
|
return target ? { kind: 'download', target, background, command: '' } : null
|
|
273
316
|
}
|
|
274
317
|
// 后台执行器也是跑命令的通道,否则 `exec_background({command:'wget …'})` 会漏识别。
|
|
275
|
-
const isShell =
|
|
318
|
+
const isShell = isShellToolName(toolKey)
|
|
276
319
|
if (!isShell || !command) return null
|
|
277
320
|
|
|
278
321
|
// 后台线索:独立的一个 &(两侧不是另一个 &,且自成一词)、nohup、--detach、> log &
|
|
279
322
|
if (/(?:^|\s)&(?!&)(?:\s|$)/.test(command) || /\bnohup\b|--detach\b|\bdetached\b/i.test(command)) background = true
|
|
280
323
|
|
|
281
|
-
for (const words of commandSegments(command)) {
|
|
324
|
+
for (const words of commandSegments(command).concat(wrapperSegments(command))) {
|
|
282
325
|
// `--dry-run` 只试跑不拉取:逐段判,不让同一条命令里的另一段背锅。
|
|
283
326
|
if (/--dry-?run\b/i.test(words.join(' '))) continue
|
|
284
327
|
const head = headWord(words)
|
|
285
328
|
if (!head) continue
|
|
286
|
-
const headIdx = words.findIndex((w) => w
|
|
329
|
+
const headIdx = words.findIndex((w) => normalizeHead(w) === head)
|
|
287
330
|
|
|
288
331
|
if (head === 'git') {
|
|
289
332
|
const sub = String(words[headIdx + 1] || '').toLowerCase()
|
|
@@ -479,6 +522,10 @@ const HEAD_GLOSS = new Map([
|
|
|
479
522
|
['export', '设环境变量'], ['source', '载入脚本'], ['git', '跑 git'], ['gh', '操作 GitHub'],
|
|
480
523
|
['aws', '调 AWS'], ['brew', '装软件'], ['cargo', '跑 Rust 工程'], ['go', '跑 Go 工程'],
|
|
481
524
|
['dotnet', '跑 .NET'], ['mix', '跑 Elixir'], ['composer', '跑 PHP 依赖'],
|
|
525
|
+
// Windows 宿主的 Bash 实落 pwsh,不补这几条就只能退回 `Bash×n`。
|
|
526
|
+
['invoke-webrequest', '下载文件'], ['iwr', '下载文件'], ['invoke-restmethod', '发 HTTP 请求'],
|
|
527
|
+
['irm', '发 HTTP 请求'], ['start-bitstransfer', '传输文件'], ['new-item', '建目录或文件'],
|
|
528
|
+
['set-variable', '设环境变量'], ['test-path', '查路径'],
|
|
482
529
|
])
|
|
483
530
|
|
|
484
531
|
function argText(o, keys) {
|
|
@@ -521,7 +568,7 @@ function glossCommand(command) {
|
|
|
521
568
|
const words = segs[0]
|
|
522
569
|
const head = headWord(words)
|
|
523
570
|
if (!head) return ''
|
|
524
|
-
const at = words.findIndex((w) => w
|
|
571
|
+
const at = words.findIndex((w) => normalizeHead(w) === head)
|
|
525
572
|
const sub = String(words[at + 1] || '').toLowerCase().replace(/^-+/, '')
|
|
526
573
|
if (head === 'git') return GIT_SUB_GLOSS.get(sub) || ''
|
|
527
574
|
if (head === 'docker' || head === 'podman' || head === 'nerdctl') return CONTAINER_SUB_GLOSS.get(sub) || ''
|
|
@@ -550,7 +597,7 @@ function describeToolStep(name, argsRaw, maxLen) {
|
|
|
550
597
|
try { const v = JSON.parse(String(u.argsRaw || '')); if (isObject(v)) o = v } catch (_err) {}
|
|
551
598
|
const cap = Math.max(8, Number(maxLen) || 46)
|
|
552
599
|
let out = ''
|
|
553
|
-
if (
|
|
600
|
+
if (isShellToolName(key)) {
|
|
554
601
|
const cmd = argText(o, ['command', 'cmd', 'input', 'text']) || (typeof u.argsRaw === 'string' ? u.argsRaw : '')
|
|
555
602
|
out = glossCommand(cmd)
|
|
556
603
|
} else if (FETCH_TOOL_NAMES.has(key)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-progress-union",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "进度结合原型:dsh-progress-board 槽位真相源 × 鲸程 widget 时间/ETA 引擎;向压缩插件暴露只读三层进度锚点(service + HTTP 双平面);0.6.0 起每回合落一版会话归档(handoff + 重启注入一次)。基于 l3j3y3/dsh-progress-board (MIT) 与 uuhihj/task-progress-bar dsh-progress-widget (MIT)。",
|
|
6
6
|
"license": "MIT",
|
|
@@ -197,3 +197,88 @@ test('快照 items 追加 isDownload(老字段不动)', async () => {
|
|
|
197
197
|
assert.ok(Object.keys(snap.items[0]).includes(key), `老字段 ${key} 不得丢`)
|
|
198
198
|
}
|
|
199
199
|
})
|
|
200
|
+
|
|
201
|
+
// ── Windows 宿主实测形状(v0.7.3)───────────────────────────────────
|
|
202
|
+
// 真机回灌:DSH 0.2.2 沙箱的 Bash 工具实落 pwsh,命令名带 .exe / 路径前缀,
|
|
203
|
+
// 只认 POSIX 首词时 `curl.exe -L -o …` 整条漏识别(子条根本不出现)。
|
|
204
|
+
|
|
205
|
+
test('classifyDownload:Windows 形态的 .exe / 绝对路径首词照样识别', () => {
|
|
206
|
+
const a = classifyDownload(...sh('New-Item -ItemType Directory -Force -Path dl072; curl.exe -L -o dl072/node.tar.gz https://nodejs.org/dist/v22.12.0/node-v22.12.0.tar.gz'))
|
|
207
|
+
assert.equal(a?.kind, 'download', '复合命令里带 curl.exe 的那一段必须被抓到')
|
|
208
|
+
assert.equal(a.target, 'node.tar.gz')
|
|
209
|
+
assert.equal(classifyDownload(...sh('C:\\Windows\\System32\\curl.exe -O https://example.com/a.bin')).kind, 'download')
|
|
210
|
+
assert.equal(classifyDownload(...sh('/mingw64/bin/git.exe clone https://github.com/a/b')).kind, 'clone')
|
|
211
|
+
assert.equal(classifyDownload(...sh('WGET.EXE -q https://example.com/x')).kind, 'download')
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
test('classifyDownload:pwsh/cmd 包层的引号体不再漏识别', () => {
|
|
215
|
+
assert.equal(classifyDownload(...sh('pwsh -Command "curl.exe -L -o out.bin https://example.com/out.bin"')).kind, 'download')
|
|
216
|
+
assert.equal(classifyDownload(...sh('powershell -Command "Invoke-WebRequest -Uri https://example.com/f.zip -OutFile f.zip"')).kind, 'download')
|
|
217
|
+
assert.equal(classifyDownload(...sh('cmd /c "wget -qO- https://example.com/y"')).kind, 'download')
|
|
218
|
+
assert.equal(classifyDownload(...sh('sh -c \'npm install left-pad\'')).kind, 'install')
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
test('classifyDownload:PowerShell 自有下载 cmdlet 入表', () => {
|
|
222
|
+
assert.equal(classifyDownload(...sh('Invoke-WebRequest -Uri https://example.com/big.iso -OutFile big.iso')).kind, 'download')
|
|
223
|
+
assert.equal(classifyDownload(...sh('iwr https://example.com/a -OutFile a.txt')).target, 'a', 'URL 在前时目标取 URL 末段')
|
|
224
|
+
assert.equal(classifyDownload(...sh('iwr -Uri https://example.com/big.iso -OutFile big.iso')).target, 'big.iso', '-OutFile 显式给目标时用文件名')
|
|
225
|
+
assert.equal(classifyDownload(...sh('Start-BitsTransfer -Source https://example.com/b -Destination b.bin')).kind, 'download')
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
test('classifyDownload:Windows 形状不得误判(无拉取语义的 pwsh 命令仍返回 null)', () => {
|
|
229
|
+
for (const cmd of [
|
|
230
|
+
'pwsh -Command "Get-Process | Select-Object -First 5"',
|
|
231
|
+
'curl.exe -s -X POST https://example.com/api -d \'{}\'',
|
|
232
|
+
'Invoke-WebRequest -Uri https://example.com/page',
|
|
233
|
+
'git.exe status --short',
|
|
234
|
+
'New-Item -ItemType Directory out',
|
|
235
|
+
]) {
|
|
236
|
+
const r = classifyDownload(...sh(cmd))
|
|
237
|
+
if (cmd === 'curl.exe -s -X POST https://example.com/api -d \'{}\'' || cmd === 'Invoke-WebRequest -Uri https://example.com/page') {
|
|
238
|
+
// 拉取器就是单一动词,这两条允许命中(与 POSIX 口径一致),但不许是 install 型误判。
|
|
239
|
+
assert.ok(!r || r.kind !== 'install', cmd)
|
|
240
|
+
continue
|
|
241
|
+
}
|
|
242
|
+
assert.equal(r, null, `不该误判成下载:${cmd}`)
|
|
243
|
+
}
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
test('glossCommand:Windows 命令名给人话而不是退回 Bash×n', async () => {
|
|
247
|
+
const { glossCommand } = await import('../index.js')
|
|
248
|
+
assert.match(glossCommand('curl.exe -L -o a.bin https://x/a.bin'), /发 HTTP 请求|下载/)
|
|
249
|
+
assert.match(glossCommand('Invoke-WebRequest -Uri https://x -OutFile y'), /下载文件/)
|
|
250
|
+
assert.match(glossCommand('git.exe clone https://github.com/a/b'), /克隆|拉取/)
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
// ── v0.7.4:工具名本身是解释器(宿主实测报成 `pwsh` 而不是 `Bash`)──
|
|
254
|
+
// 0.7.3 只修了命令词表,但 isShell 这道门在上一行就把整条判成非 shell,
|
|
255
|
+
// 所以下面这些形状在 0.7.3 上依旧全漏——这两个用例就是那次的真机回灌。
|
|
256
|
+
test('classifyDownload:工具名为 pwsh/powershell 时不再被 isShell 门拦下', () => {
|
|
257
|
+
const pwsh = (command) => ['pwsh', JSON.stringify({ command })]
|
|
258
|
+
const real = 'New-Item -ItemType Directory -Force -Path dl073 | Out-Null; curl.exe -L -o dl073/echarts.tgz http://registry.npmmirror.com/echarts/-/echarts-5.5.0.tgz'
|
|
259
|
+
const hit = classifyDownload(...pwsh(real))
|
|
260
|
+
assert.equal(hit?.kind, 'download', 'pwsh 工具名 + 分号后的 curl.exe 必须命中')
|
|
261
|
+
assert.equal(hit.target, 'echarts.tgz')
|
|
262
|
+
|
|
263
|
+
assert.equal(classifyDownload(...pwsh('wget https://example.com/a.bin')).kind, 'download')
|
|
264
|
+
const p2 = ['powershell', JSON.stringify({ command: 'Invoke-WebRequest -Uri https://example.com/files/big.iso -OutFile big.iso' })]
|
|
265
|
+
assert.equal(classifyDownload(...p2).target, 'big.iso')
|
|
266
|
+
const p3 = ['C:\\Program Files\\PowerShell\\7\\pwsh.exe', JSON.stringify({ command: 'git.exe clone https://github.com/a/b' })]
|
|
267
|
+
assert.equal(classifyDownload(...p3).kind, 'clone')
|
|
268
|
+
assert.equal(classifyDownload(...pwsh('npm install lodash')).kind, 'install')
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
test('classifyDownload:解释器名不得把非 shell 工具变成 shell', () => {
|
|
272
|
+
// read/search 这类工具名不在词表里,带了 command 字段也不许当下载通道。
|
|
273
|
+
assert.equal(classifyDownload('read_file', JSON.stringify({ command: 'curl -O https://x/a.bin' })), null)
|
|
274
|
+
assert.equal(classifyDownload('mcp__tools__fetch', JSON.stringify({ command: 'wget https://x/a.bin' })), null)
|
|
275
|
+
// 解释器名但拿不出命令文本 → 仍然 null,不臆造。
|
|
276
|
+
assert.equal(classifyDownload('pwsh', JSON.stringify({})), null)
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
test('describeToolStep:pwsh 工具名走 shell 分支而不是退回空串', async () => {
|
|
280
|
+
const { describeToolStep } = await import('../index.js')
|
|
281
|
+
const step = describeToolStep('pwsh', JSON.stringify({ command: 'New-Item -ItemType Directory -Force -Path d1 | Out-Null; curl.exe -L -o a.bin http://x/a.bin' }), 46)
|
|
282
|
+
assert.ok(step, 'pwsh 形态必须有人话')
|
|
283
|
+
assert.match(step, /建目录或文件|发 HTTP 请求|下载/)
|
|
284
|
+
})
|