dsh-progress-union 0.7.2 → 0.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/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  本项目的所有值得记录的变更都写在这里。版本号遵循语义化版本。
4
4
 
5
+ ## 0.7.3 (2026-12-04)
6
+
7
+ **fix(download):Windows 宿主上 `curl.exe` / `Invoke-WebRequest` / `pwsh -Command "…"` 全漏识别,下载子条根本不出来。**
8
+
9
+ 真机回灌(沙箱宿主 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` 后缀与路径前缀,首词比对永远对不上。
10
+
11
+ - **首词归一**:新增 `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 …` 均能识别。
12
+ - **shell 包层拆引号体**:新增 `wrapperSegments()`(`pwsh|powershell|sh|bash|zsh|dash|cmd|wsl` + `-Command|-c|/c|-file` 后的引号体再切一段,只拆一层不递归),并入 `classifyDownload` 的逐段循环。`pwsh -Command "curl.exe -L -o out.bin …"` 不再因为外层首词是 `pwsh` 而整条静默。
13
+ - **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` 目标取文件名)。
14
+ - **工序可解释同步**:`HEAD_GLOSS` 补 `invoke-webrequest/iwr → 下载文件`、`invoke-restmethod/irm → 发 HTTP 请求`、`start-bitstransfer → 传输文件`、`new-item → 建目录或文件`、`set-variable → 设环境变量`、`test-path → 查路径`,避免 Windows 会话里「最近动作」退回 `Bash×n`。
15
+ - **不误判**:新增反例用例 — `pwsh -Command "Get-Process | …"`、`git.exe status --short`、`New-Item -ItemType Directory out` 仍必须返回 `null`(软感知只认词表,不做语义猜)。POSIX 旧用例零修改全绿。
16
+ - **测试**:`test/download-classify.test.mjs` +5 用例(共 19),`npm test` **239 pass / 0 fail**(234 → +5),零回归。
17
+
18
+
5
19
  ## 0.7.2 (2026-12-04)
6
20
 
7
21
  **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(234 用例,纯 mock ctx,无需宿主进程)
271
+ npm test # node --test test/*.test.mjs(239 用例,纯 mock ctx,无需宿主进程)
272
272
  ```
273
273
 
274
274
  ## 冷启动接续(v0.6.2)
@@ -291,6 +291,8 @@ 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
+
294
296
  ## 下载子进度条(v0.7.0)
295
297
 
296
298
  输入框上方的迷你条在主条行之后渲染一行子条,真值全部来自本插件自解析 `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.2"; /* ladder:ver */
27
+ var STAR_VERSION = "0.7.3"; /* 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.2",
3
+ "version": "0.7.3",
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
@@ -200,7 +200,10 @@ const INSTALLERS = new Map([
200
200
  ])
201
201
 
202
202
  // 单一下载器:命令首词即意图,无需第二个动词。
203
- const DOWNLOADERS = new Set(['curl', 'wget', 'aria2c', 'axel', 'rsync', 'scp', 'aws', 'gcs', 'rclone'])
203
+ // 后五个是 Windows 宿主实测形状:Bash 工具落 pwsh 时,模型常写
204
+ // `curl.exe -L -o …` 或 `Invoke-WebRequest -Uri …`,只认 POSIX 名的话整条漏识别。
205
+ const DOWNLOADERS = new Set(['curl', 'wget', 'aria2c', 'axel', 'rsync', 'scp', 'aws', 'gcs', 'rclone',
206
+ 'invoke-webrequest', 'iwr', 'invoke-restmethod', 'irm', 'start-bitstransfer'])
204
207
 
205
208
  // 把 `act` 包装透传回内层工具(宿主侧 act 的入参形状就是 `{tool, input}`)。
206
209
  // 只做一层,不递归展开嵌套 input:够用来避免「观察者把动作误记成 act」,不因此引入依赖。
@@ -226,20 +229,47 @@ function commandSegments(command) {
226
229
 
227
230
  // 跳过 env/时间/权限等前缀词,拿到真正的命令名。
228
231
  const COMMAND_PREFIX_WORDS = new Set(['sudo', 'env', 'time', 'nohup', 'doas', 'command', 'nice', 'setsid', 'noglob', 'cross-env', 'xargs'])
232
+ // 真下载藏在引号体里时的外层壳:`pwsh -Command "curl.exe …"` / `sh -c 'wget …'` / `cmd /c "…"`。
233
+ 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
234
+ /**
235
+ * 首词归一(Windows 实测必修):剥引号、取 basename、去 `.exe/.cmd/.bat/.ps1` 后缀。
236
+ * 不这么做的话 `C:\Windows\System32\curl.exe`、`/mingw64/bin/git.exe` 全都认不出。
237
+ */
238
+ function normalizeHead(word) {
239
+ let w = String(word || '').toLowerCase().replace(/^['"`]+/, '').replace(/['"`;)]+$/, '')
240
+ if (!w) return ''
241
+ w = w.split(/[\\/]/).pop()
242
+ return w.replace(/\.(?:exe|cmd|bat|ps1)$/, '')
243
+ }
229
244
  function headWord(words) {
230
245
  for (const w of words) {
231
- const key = w.toLowerCase()
232
- if (COMMAND_PREFIX_WORDS.has(key) || key.startsWith('-')) continue
246
+ const key = normalizeHead(w)
247
+ if (!key) continue
248
+ if (COMMAND_PREFIX_WORDS.has(key) || w.trim().startsWith('-')) continue
233
249
  return key
234
250
  }
235
251
  return ''
236
252
  }
237
253
 
254
+ // 把 shell 包层的引号体再切成段(只拆一层,不递归解嵌套引号——够用来补 Windows 漏识别)。
255
+ function wrapperSegments(command) {
256
+ const out = []
257
+ SHELL_WRAPPERS.lastIndex = 0
258
+ let m
259
+ while ((m = SHELL_WRAPPERS.exec(String(command || '')))) out.push(...commandSegments(m[1]))
260
+ return out
261
+ }
262
+
238
263
  // 取第一个非 flag 词作为目标(包名 / 镜像 / URL)。
239
264
  function firstOperand(words, from) {
240
265
  for (let i = from; i < words.length; i++) {
241
266
  const w = words[i]
242
- if (w.startsWith('-')) { if (/^(?:-o|-O|--output|--target|-t)$/i.test(w)) { const nxt = words[i + 1]; if (nxt && !nxt.startsWith('-')) return nxt } continue }
267
+ if (/^(?:-o|-O|--output|--target|-t|--?outfile|-out-file|--filepath|-file|-destination|--url)$/i.test(w)) {
268
+ const nxt = words[i + 1]
269
+ if (nxt && !nxt.startsWith('-')) return nxt
270
+ continue
271
+ }
272
+ if (w.startsWith('-')) continue
243
273
  return w
244
274
  }
245
275
  return ''
@@ -278,12 +308,12 @@ function classifyDownload(name, argsRaw) {
278
308
  // 后台线索:独立的一个 &(两侧不是另一个 &,且自成一词)、nohup、--detach、> log &
279
309
  if (/(?:^|\s)&(?!&)(?:\s|$)/.test(command) || /\bnohup\b|--detach\b|\bdetached\b/i.test(command)) background = true
280
310
 
281
- for (const words of commandSegments(command)) {
311
+ for (const words of commandSegments(command).concat(wrapperSegments(command))) {
282
312
  // `--dry-run` 只试跑不拉取:逐段判,不让同一条命令里的另一段背锅。
283
313
  if (/--dry-?run\b/i.test(words.join(' '))) continue
284
314
  const head = headWord(words)
285
315
  if (!head) continue
286
- const headIdx = words.findIndex((w) => w.toLowerCase() === head)
316
+ const headIdx = words.findIndex((w) => normalizeHead(w) === head)
287
317
 
288
318
  if (head === 'git') {
289
319
  const sub = String(words[headIdx + 1] || '').toLowerCase()
@@ -479,6 +509,10 @@ const HEAD_GLOSS = new Map([
479
509
  ['export', '设环境变量'], ['source', '载入脚本'], ['git', '跑 git'], ['gh', '操作 GitHub'],
480
510
  ['aws', '调 AWS'], ['brew', '装软件'], ['cargo', '跑 Rust 工程'], ['go', '跑 Go 工程'],
481
511
  ['dotnet', '跑 .NET'], ['mix', '跑 Elixir'], ['composer', '跑 PHP 依赖'],
512
+ // Windows 宿主的 Bash 实落 pwsh,不补这几条就只能退回 `Bash×n`。
513
+ ['invoke-webrequest', '下载文件'], ['iwr', '下载文件'], ['invoke-restmethod', '发 HTTP 请求'],
514
+ ['irm', '发 HTTP 请求'], ['start-bitstransfer', '传输文件'], ['new-item', '建目录或文件'],
515
+ ['set-variable', '设环境变量'], ['test-path', '查路径'],
482
516
  ])
483
517
 
484
518
  function argText(o, keys) {
@@ -521,7 +555,7 @@ function glossCommand(command) {
521
555
  const words = segs[0]
522
556
  const head = headWord(words)
523
557
  if (!head) return ''
524
- const at = words.findIndex((w) => w.toLowerCase() === head)
558
+ const at = words.findIndex((w) => normalizeHead(w) === head)
525
559
  const sub = String(words[at + 1] || '').toLowerCase().replace(/^-+/, '')
526
560
  if (head === 'git') return GIT_SUB_GLOSS.get(sub) || ''
527
561
  if (head === 'docker' || head === 'podman' || head === 'nerdctl') return CONTAINER_SUB_GLOSS.get(sub) || ''
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-progress-union",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
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,55 @@ 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
+ })