dsh-transfer-dock 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 imnotRiv3r
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,510 @@
1
- # Temporary Holding Version
1
+ <p align="right"><b>English</b> · <a href="README.zh.md">中文</a></p>
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ <p align="center">
4
+ <img src="https://raw.githubusercontent.com/imnotRiv3r/dsh-download-dock/main/docs/banner.svg" width="100%" alt="dsh-download-dock — live download cards in the corner of the DeepSeek Harness UI">
5
+ </p>
6
+
7
+ <p align="center">
8
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-c4b5fd?style=flat-square" alt="License: MIT"></a>
9
+ <img src="https://img.shields.io/badge/node-%E2%89%A520-3c873a?style=flat-square&logo=nodedotjs&logoColor=white" alt="Node.js >= 20">
10
+ <img src="https://img.shields.io/badge/dsh-0.2.0--rc.1%2B-7c5cff?style=flat-square" alt="DeepSeek Harness >= 0.2.0-rc.1">
11
+ <img src="https://img.shields.io/badge/tests-smoke%20%C2%B7%20offline-22d3ee?style=flat-square" alt="Tests: offline smoke">
12
+ <img src="https://img.shields.io/badge/version-0.1.0-6d4aff?style=flat-square" alt="Version 0.1.0">
13
+ </p>
14
+
15
+ <p align="center">
16
+ <b>A background download shouldn't be one word: "Running".</b><br>
17
+ <sub>dsh-download-dock grows a live card in the bottom-right corner: file, progress, bytes, speed and ETA.</sub>
18
+ </p>
19
+
20
+ ---
21
+
22
+ <p align="center">
23
+ <img src="https://raw.githubusercontent.com/imnotRiv3r/dsh-download-dock/main/docs/card-fill.png" width="46%" alt="A card with a known total: 32% · curl">
24
+ <img src="https://raw.githubusercontent.com/imnotRiv3r/dsh-download-dock/main/docs/card-stripes.png" width="46%" alt="An indeterminate card: moving stripes, bytes written">
25
+ </p>
26
+
27
+ <p align="center">
28
+ <sub>Left: the total is known → a real percentage and an ETA. Right: no single total → moving stripes plus bytes written (a deliberate third state, not a failure).</sub>
29
+ </p>
30
+
31
+ > You start a 2 GB model download in Harness and it goes to the background. The corner of the UI says nothing; the job row says "Running".
32
+ > You can't tell whether it's downloading at full speed, stuck on DNS, or already dead.
33
+ >
34
+ > dsh-download-dock turns those forty seconds into one card: **file name, 32%, 4.14 MB / 12.9 MB, 148 KB/s, 59s left**.
35
+ > No second window, no wrapped commands, no takeover — it observes and draws the result where you are already looking.
36
+
37
+ ## Contents
38
+
39
+ <details>
40
+ <summary>Expand</summary>
41
+
42
+ - [The problem](#the-problem)
43
+ - [Anatomy of a card](#anatomy-of-a-card)
44
+ - [How it works](#how-it-works)
45
+ - [Three data sources](#three-data-sources)
46
+ - [Stripes are not a bug](#stripes-are-not-a-bug)
47
+ - [What it watches](#what-it-watches)
48
+ - [Install](#install)
49
+ - [Config](#config)
50
+ - [The state route](#the-state-route)
51
+ - [Troubleshooting](#troubleshooting)
52
+ - [Limitations](#limitations)
53
+ - [Development](#development)
54
+ - [License](#license)
55
+
56
+ </details>
57
+
58
+ ## The problem
59
+
60
+ Harness pushes download commands into background jobs (`run_in_background: true`) so they don't block the turn. The cost: the UI keeps a single status row, and the next real signal is a completion notice a dozen seconds later. Everything in between is invisible.
61
+
62
+ dsh-download-dock fills that gap, and it **only observes**:
63
+
64
+ | It does | It doesn't |
65
+ |---|---|
66
+ | Subscribe to job registry events and detect download commands | Consume the model's job cursor |
67
+ | Sample disk bytes, probe totals (Host) and parse job output (browser) | Change job state, send signals or kill processes |
68
+ | Expose a read-only JSON route to the browser half | Read or write the downloaded files |
69
+ | Render a card in the bottom-right corner | Pop dialogs, steal focus or block input |
70
+
71
+ It never asks you to wrap a command. `git clone`, `pip install`, `curl -o`, `npm install` and `winget install` work as they are; progress-friendly flags only make the card more precise (see [What it watches](#what-it-watches)).
72
+
73
+ ## Anatomy of a card
74
+
75
+ A card is 366 px wide (clamped to `100vw - 36px` on narrow screens), fixed 18 px from the bottom-right corner, with a blurred glass background that follows Harness' light and dark theme variables. Top to bottom:
76
+
77
+ | Part | Content | Notes |
78
+ |---|---|---|
79
+ | Tool badge | `git` / `py` / `npm` / `a2` / `c` / `w` / `web` / `app` / `rs` / `go` / `dk` | Derived from the detected tool |
80
+ | Title | File, repo or package name | e.g. `numpy-2.2.6-cp310-win_amd64.whl`, `dsh-download-dock`, `lodash`; falls back to the first 60 characters of the command |
81
+ | Subtitle | Byte progress or status text | `4.14 MB / 12.9 MB`, `12.4 MB written`, `Completed`, `Download failed`, `Cancelled`, `Stopping…` |
82
+ | Bar | Filled bar or moving stripes | Filled when the total is known; stripes otherwise (see [Stripes are not a bug](#stripes-are-not-a-bug)) |
83
+ | Bottom left | Percentage + tool | The tool alone means indeterminate |
84
+ | Bottom right | Speed · ETA · elapsed | Only elapsed once finished |
85
+ | Error line | Failure reason | `failed` only; first line of the job's `detail` |
86
+
87
+ Status maps directly onto the visuals:
88
+
89
+ | Status | Bar | Subtitle | Bottom right |
90
+ |---|---|---|---|
91
+ | `running` | filled or striped | bytes / status text | speed · ETA · elapsed |
92
+ | `stopping` | unchanged | `Stopping…` | speed no longer updates |
93
+ | `completed` | green, 100% | `Completed` | total elapsed |
94
+ | `failed` | red | `Download failed` + error line | total elapsed |
95
+ | `killed` | red | `Cancelled` | total elapsed |
96
+
97
+ The `✕` button only removes the card from the current page — **it never stops the job**. Reloading brings the card back if the job is still running.
98
+
99
+ ## How it works
100
+
101
+ The plugin is split into two halves that talk over a single read-only JSON route:
102
+
103
+ <p align="center">
104
+ <img src="https://raw.githubusercontent.com/imnotRiv3r/dsh-download-dock/main/docs/architecture.svg" width="100%" alt="dsh-download-dock data flow: download tools → Host sampling → JSON state → browser card">
105
+ </p>
106
+
107
+ | Half | Files | Runtime | Responsibility |
108
+ |---|---|---|---|
109
+ | Host | `index.js` + `lib/*` | Harness main process (Node.js) | Subscribe to job events, detect downloads, sample disk, probe totals, expose the state route, inject a prompt section |
110
+ | Browser | `client.js` | Web GUI (React) | Poll state, read job output, parse progress, merge into cards, portal into `document.body` |
111
+
112
+ ### Lifecycle of one download
113
+
114
+ ```mermaid
115
+ flowchart LR
116
+ A["Background job starts"] --> B{"detectDownload()<br/>is this a download?"}
117
+ B -- no --> X["No card"]
118
+ B -- yes --> C["Record baselines<br/>target dirs + %TEMP%"]
119
+ C --> D["HEAD probe for total<br/>single URL only"]
120
+ C --> E["Sample every 700 ms<br/>disk byte delta"]
121
+ D --> F["present() merge<br/>output first, disk as fallback"]
122
+ E --> F
123
+ F --> G["Browser polls every 600 ms<br/>renders the card"]
124
+ G --> H{"Job finished?"}
125
+ H -- no --> G
126
+ H -- yes --> I["completed / failed / killed<br/>fades out after 2.6 s"]
127
+ ```
128
+
129
+ 1. A command starts with `run_in_background: true` and the job registry emits an event.
130
+ 2. `detectDownload(label)` decides whether it is a download and resolves candidate output paths.
131
+ 3. The Host records baselines: current bytes of the target directories and of this tool's existing `%TEMP%` entries.
132
+ 4. If the command contains exactly one HTTP(S) URL, the Host sends a `HEAD` request and reads `content-length` as the total.
133
+ 5. Every 700 ms the Host samples only the **delta**, so pre-existing files never count as part of this download.
134
+ 6. After the job ends, the Host keeps returning it for 12 seconds (`settledTtlMs`) so the browser can render the final state.
135
+ 7. The browser fetches `/plugin/dsh-download-dock/state` every 600 ms and pauses while the page is hidden.
136
+ 8. The browser merges disk bytes with the downloader's own progress lines, renders the card, and fades finished cards out after 2.6 seconds.
137
+
138
+ ## Three data sources
139
+
140
+ ### A. Job output (most accurate)
141
+
142
+ The browser subscribes to the job's output and scans its last 16 KiB (up to 60 lines) for progress frames:
143
+
144
+ | Downloader | Sample output | Parsed fields |
145
+ |---|---|---|
146
+ | aria2c | `[#1a2b3c 12MiB/45MiB(26%) CN:1 DL:1.2MiB ETA:30s]` | percent, downloaded, total, speed, ETA |
147
+ | git clone | `Receiving objects: 45% (1234/2740), 1.20 MiB \| 2.30 MiB/s` | percent, downloaded, speed |
148
+ | docker pull | `45%\|████ \| 12.3MB/27MB` | percent, downloaded, total |
149
+ | pip | `12.9/12.9 MB 491.0 kB/s eta 0:00:00` | downloaded, total, speed, ETA |
150
+ | wget | `0K .......... .......... 45% 1.2M 3s` | percent, speed, ETA |
151
+ | curl `-#` | `################# 45.0%` | percent |
152
+ | generic | any line containing `45%` | percent |
153
+
154
+ A few details that matter:
155
+
156
+ - **pip's total comes from its first line.** `Downloading https://.../p.whl (9.7 MB)` is remembered separately; later progress frames only carry bytes downloaded, and the two together produce a percentage.
157
+ - **git only counts `Receiving objects`.** `Resolving deltas`, `Counting`, `Compressing`, `Writing`, `Updating` and `Enumerating` are local phases; treating their 100% as download progress makes the bar jump backwards.
158
+ - **Speed fallback.** When a line has no `MiB/s`, the parser also looks for a standalone `X MB/s` token in the same line.
159
+ - **Swallowed output is gone.** `curl -# ... | Select-Object` and friends eat stdout/stderr; that data source is unavailable and only disk sampling remains.
160
+
161
+ ### B. Disk sampling (covers everything that writes files)
162
+
163
+ The browser cannot read the filesystem, so the Host samples. Targets aren't guessed — they are parsed from the command text:
164
+
165
+ | Clue | Sampled target |
166
+ |---|---|
167
+ | A URL's file name | `<cwd>/<file>`, `<file>.part`, `<file>.tmp` |
168
+ | `-o` / `-O` / `--output` / `-OutFile` / `-Destination` / `--dir` and friends | The resolved real path |
169
+ | `git clone` | The target repo's `.git` (the working tree is never walked) |
170
+ | `npm` / `pnpm` / `yarn` / `uv` | `node_modules` and `.venv` under the working directory |
171
+ | `$dir="D:\dl"` in the command | Expanded before resolution; if a variable cannot be resolved the path is **skipped** rather than guessed |
172
+ | Everything | `%TEMP%` entries matching the downloader's prefix, plus `.part` / `.partial` / `.crdownload` / `.opdownload` staging files |
173
+
174
+ `%TEMP%` matching is scoped by downloader prefix (`pip-`, `uv-`, `npm-`, `pnpm`, `npx-`, `yarn-`, `git-`, `winget-`, `choco-`, `scoop-` …) because a Windows temp directory routinely holds hundreds of unrelated `.tmp` files.
175
+
176
+ Sampling has hard budgets so a huge directory can't stall the main process:
177
+
178
+ | Parameter | Value | Purpose |
179
+ |---|---|---|
180
+ | Per-round budget | `220 ms` (50–2000, configurable) | Stops walking as soon as the budget is spent |
181
+ | Target / temp split | 45% / 55% | Neither path can starve the other |
182
+ | Recursion depth | 3 levels | Avoids descending into nested `node_modules` |
183
+ | Entry cap per round | 4000 | Keeps giant trees from eating the whole budget |
184
+ | Sampling tick | 700 ms | Smooth enough, cheap enough |
185
+ | Speed window | 5 s | Byte delta between the window's first and last sample |
186
+ | Smoothing | 0.55 × old + 0.45 × new | Damps sampling jitter |
187
+
188
+ Every byte count is a **delta**: the Host records the target directory and `%TEMP%` baselines when the task opens, then counts only growth. Files that were already in the directory never count as this download.
189
+
190
+ ### C. HEAD probe (supplies the missing total)
191
+
192
+ For a **single-file URL** (exactly one HTTP(S) address in the command), the Host sends one `HEAD` request:
193
+
194
+ - 3 s timeout, at most 3 redirects;
195
+ - only a 2xx response's `content-length` counts (a 404 error page has a length too, and it would be wrong);
196
+ - failures, non-HTTP(S) URLs and servers that refuse HEAD are silently ignored, and the card falls back to stripes or to the output-derived total;
197
+ - multi-URL commands are **not** probed — batch downloads have no single total, so any probe would be wrong.
198
+
199
+ ### Merge rules
200
+
201
+ The browser merges the two paths like this:
202
+
203
+ | Field | How it merges |
204
+ |---|---|
205
+ | `downloaded` | `max(job output, disk delta)` — either can lead temporarily, and the max means progress never steps backwards to zero |
206
+ | `total` | job output (including pip's `(9.7 MB)`) → HEAD `content-length`; neither → stripes |
207
+ | `percent` | job output → `downloaded / total × 100`; neither → stripes |
208
+ | `speed` | job output → disk sampling speed; neither → hidden |
209
+ | `eta` | job output → `(total − downloaded) / speed`; neither → hidden |
210
+
211
+ > A real percentage appears only when the job output carries one, or when the output/HEAD supplies a total. Everything else degrades honestly.
212
+
213
+ ## Stripes are not a bug
214
+
215
+ Moving stripes mean the plugin is in its indeterminate state: it knows a download is running, how many bytes have landed and how fast, but **not the total**, so it honestly refuses to invent a percentage.
216
+
217
+ There are only three ways to end up without a total:
218
+
219
+ 1. The downloader doesn't report one (`curl -s`, `wget --quiet`, or output swallowed by a pipe);
220
+ 2. The command isn't a single HTTP(S) URL (many packages, many URLs) — there is nothing to HEAD;
221
+ 3. The server refuses HEAD, returns a non-2xx status, times out, or `probeTotals` is disabled.
222
+
223
+ This is not a fallback to failure but a deliberate third state: **don't fake certainty**. The card still shows `12.4 MB written` and a live speed, so the information isn't zero.
224
+
225
+ When you will always see a percentage:
226
+
227
+ | Scenario | Percentage | Total source |
228
+ |---|---|---|
229
+ | `curl -# -L -o file URL` | ✅ | Hash progress line |
230
+ | `curl -s -L -o file URL` | ✅ | HEAD probe |
231
+ | `git clone --progress` | ✅ | `Receiving objects` |
232
+ | `aria2c` | ✅ | Its own progress line |
233
+ | `docker pull` | ✅ | Its own progress line |
234
+ | `wget` | ✅ | Its own progress line |
235
+ | `pip install` / `python -m pip download` | ✅ | pip's `(9.7 MB)` + disk delta (when the output carries a total) |
236
+ | `npm install` / `pnpm add` | ❌ stripes | Dozens of packages, no single total |
237
+ | Multi-URL `curl` / `wget` | ❌ stripes | Same reason |
238
+ | Silent download from a server without HEAD | ❌ stripes | No source at all |
239
+
240
+ ## What it watches
241
+
242
+ Detection looks only at the command text (`job.label`) and takes the first matching rule, in a fixed order:
243
+
244
+ | Tool | Matching commands | Progress source | Badge |
245
+ |---|---|---|---|
246
+ | git | `git clone` / `fetch` / `pull` / `submodule update` / `lfs pull` | output lines + `.git` sampling | `git` |
247
+ | pip | `pip install` / `download` / `wheel`, including `python -m pip` | output lines + `%TEMP%` sampling | `py` |
248
+ | uv | `uv pip install` / `add` / `sync` / `lock` / `download` / `export` | disk sampling + `%TEMP%` | `py` |
249
+ | npm family | `npm` / `pnpm` / `yarn` / `bun` with `i`, `install`, `ci`, `add`, `dlx`, `create`, `update`, `fetch`, `rebuild` | disk sampling (`node_modules`) | `npm` |
250
+ | curl | Any `curl` call that has a URL or an output flag | `-#` output + target sampling | `c` |
251
+ | wget | Any `wget` call | output lines + target sampling | `w` |
252
+ | aria2 | `aria2c` | output lines + target sampling | `a2` |
253
+ | PowerShell | `Start-BitsTransfer`; `Invoke-WebRequest` / `iwr` / `Invoke-RestMethod` / `irm` **with `-OutFile`** | target sampling | `web` |
254
+ | Package managers | `winget install` / `download`, `choco install`, `scoop install` / `update`, `nuget install`, `dotnet tool install` / `add package` | `%TEMP%` sampling | `app` |
255
+ | Rust / Go | `cargo install` / `fetch` / `vendor` / `update`, `go get` / `mod download` | `%TEMP%` sampling | `rs` / `go` |
256
+ | Docker | `docker pull` / `load` / `save` / `build` | output lines | `dk` |
257
+
258
+ **Explicitly ignored** (no card, no sampling):
259
+
260
+ - `git status`, `git log`, `git commit` and other non-fetching commands;
261
+ - `curl --version`, `wget --help`, `aria2c -h` — version/help only, with neither a URL nor an output flag;
262
+ - `pip list`, `pip freeze` — no install/download action;
263
+ - `Invoke-WebRequest` without `-OutFile` (usually an API call read into memory, not a download);
264
+ - `npm run build`, `npm test` — `run` isn't a download verb;
265
+ - commands longer than 8000 characters (keeps pathological labels from slowing the parse).
266
+
267
+ ## Install
268
+
269
+ Prerequisites:
270
+
271
+ - DeepSeek Harness `>= 0.2.0-rc.1 < 0.3.0-0` (from `dsh.compatibility` in `package.json`);
272
+ - Node.js `>= 20`;
273
+ - a working Harness profile (examples below use `desktop`; substitute yours).
274
+
275
+ ### From the plugin market
276
+
277
+ The plugin is listed in the [awesome-dsh-plugin](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin) catalog, so the market inside DeepSeek Harness — [dsh-market](https://github.com/dsh-market/dsh-market), under UI Enhancements — lists it with a one-click **Install**. The market runs exactly the CLI command below, so either entry point ends in the same profile state.
278
+
279
+ ### From the CLI
280
+
281
+ ```powershell
282
+ dsh plugin --profile desktop add github:imnotRiv3r/dsh-download-dock
283
+ ```
284
+
285
+ That one command is the whole install: it adds the dependency to the profile's `package.json` and appends `dsh-download-dock` to `dsh.profile.bundles`. There is no npm package — the GitHub source is the only release channel. To pin a commit:
286
+
287
+ ```powershell
288
+ dsh plugin --profile desktop add github:imnotRiv3r/dsh-download-dock#b2404e2
289
+ ```
290
+
291
+ Uninstall is symmetric — it drops the dependency and the `bundles` row together:
292
+
293
+ ```powershell
294
+ dsh plugin --profile desktop remove dsh-download-dock
295
+ ```
296
+
297
+ The repo has no build step (no `prepare`/`install` script, and `exports` points straight at the source), so the first install does not raise pnpm's `allowBuilds` prompt.
298
+
299
+ ### Link a local checkout (development)
300
+
301
+ ```powershell
302
+ dsh plugin --profile desktop add 'link:E:\dshWorkspace\dsh-download-dock'
303
+ ```
304
+
305
+ The profile now points at your checkout, so edits are live: the Host half hot-reloads with the profile, the browser half needs one page refresh. pnpm warns that a `link:` dependency does not resolve `peerDependencies` from the target — the only one this package declares is `@deepseek-ai/schemastery`, which a DSH profile already provides through `@deepseek-ai/dsh-base`.
306
+
307
+ Prefer a frozen copy, where edits require re-running the command? Use `file:E:\dshWorkspace\dsh-download-dock` instead of `link:...`.
308
+
309
+ ### What reloads when
310
+
311
+ | Change | Takes effect |
312
+ |---|---|
313
+ | Host half (`index.js`, `lib/*`) | Hot reloads with profile changes |
314
+ | Browser half (`client.js`) | **One page refresh** |
315
+ | Config (`cordis.patch.yml`) | Hot reload; the browser half picks it up after a refresh |
316
+
317
+ ### Plugin page
318
+
319
+ `locale/en.json` and `locale/zh.json` carry `meta.title` and `meta.description`, and `icon.svg` is the plugin-page icon (through the `icon` field in `package.json` plus `./locale/*.json` and `./icon` in `exports`). After install, rename or update, refresh the page once and the plugin page shows "Download dock" / "下载坞" with its icon. If it still falls back to the package name or default artwork, the host has not re-read the package manifest yet — restart DSH.
320
+
321
+ ### Verify
322
+
323
+ ```powershell
324
+ # Is the Host half alive? `hits` grows once the browser half attaches (use your DSH Web port).
325
+ Invoke-RestMethod http://127.0.0.1:2482/plugin/dsh-download-dock/state
326
+ ```
327
+
328
+ A healthy response looks like:
329
+
330
+ ```json
331
+ { "version": 1, "now": 1731427200000, "tasks": [], "poll": { "hits": 412, "lastHitAt": 1731427200000, "build": "0.1.0" } }
332
+ ```
333
+
334
+ Now trigger a visible download (rate-limited to 300 KB/s so the card has time to appear):
335
+
336
+ ```powershell
337
+ curl.exe -L -# --limit-rate 300k -o "$env:TEMP\probe.bin" `
338
+ https://mirrors.aliyun.com/pypi/packages/a3/dd/4b822569d6b96c39d1215dbae0582fd99954dcbcf0c1a13c61783feaca3f/numpy-2.2.6-cp310-cp310-win_amd64.whl
339
+ ```
340
+
341
+ > **It must be a background job** (`run_in_background: true`, or a foreground command promoted to background on timeout). Foreground commands have no job row, so there is nothing to observe — that follows from Harness' job model.
342
+
343
+ ## Config
344
+
345
+ The row id is `download-dock`; edit it in the profile's `cordis.patch.yml`:
346
+
347
+ ```yaml
348
+ - id: download-dock
349
+ name: dsh-download-dock
350
+ config:
351
+ enabled: true
352
+ guidePrompt: true
353
+ settledTtlMs: 12000
354
+ maxTasks: 8
355
+ sampleBudgetMs: 220
356
+ probeTotals: true
357
+ workingDirectory: ''
358
+ ```
359
+
360
+ | Field | Type | Default | Range | Meaning |
361
+ |---|---|---:|---|---|
362
+ | `enabled` | boolean | `true` | — | Master switch: off means no detection, no sampling, no route |
363
+ | `guidePrompt` | boolean | `true` | — | Add the download guidance section to the system prompt |
364
+ | `settledTtlMs` | number | `12000` | 1000–120000 | How long the Host keeps returning a finished task |
365
+ | `maxTasks` | number | `8` | 1–32 | Maximum cards rendered at once |
366
+ | `sampleBudgetMs` | number | `220` | 50–2000 | Per-round disk sampling budget; lower it on huge directories |
367
+ | `probeTotals` | boolean | `true` | — | HEAD-probe single file URLs for a total; off means silent downloads stay indeterminate |
368
+ | `workingDirectory` | string | process cwd | — | Base for resolving relative paths; empty uses the Harness process cwd |
369
+
370
+ With `guidePrompt` on, the plugin injects a short system-prompt section: **for download commands prefer `run_in_background: true`, and add progress-friendly flags (`git clone --progress`, `curl -# -L`; wget and aria2c already report progress)**. That section is what determines how often cards actually appear — the model has to put downloads in the background before there is anything to observe.
371
+
372
+ > Config values are normalized on the Host side (numbers clamped to range and rounded, blank strings fall back to the process cwd), so a malformed value can't crash the plugin.
373
+
374
+ ## The state route
375
+
376
+ `GET /plugin/dsh-download-dock/state` returns a read-only JSON snapshot (`cache-control: no-store`):
377
+
378
+ ```json
379
+ {
380
+ "version": 1,
381
+ "now": 1731427200000,
382
+ "tasks": [
383
+ {
384
+ "id": "job_7f3a",
385
+ "sessionId": "sess_2b91",
386
+ "tool": "pip",
387
+ "fileName": "numpy-2.2.6-cp310-win_amd64.whl",
388
+ "label": "python -m pip download numpy --no-deps -d E:\\ws",
389
+ "status": "running",
390
+ "startedAt": 1731427188000,
391
+ "finishedAt": null,
392
+ "elapsedMs": 12000,
393
+ "bytes": 4140000,
394
+ "speed": 148000,
395
+ "total": 12900000,
396
+ "detail": null,
397
+ "source": "temp"
398
+ }
399
+ ],
400
+ "poll": { "hits": 412, "lastHitAt": 1731427200000, "build": "0.1.0" }
401
+ }
402
+ ```
403
+
404
+ | Field | Meaning |
405
+ |---|---|
406
+ | `version` | Snapshot format version, currently `1` |
407
+ | `now` | When the Host built the snapshot |
408
+ | `tasks[].id` | Harness job id |
409
+ | `tasks[].sessionId` | Owning session; `null` for ownerless jobs, which can only show bytes (their output stream is unavailable) |
410
+ | `tasks[].tool` | Detected tool (`git`, `pip`, `npm`, `curl` …) |
411
+ | `tasks[].fileName` | Card title (file / repo / package name) |
412
+ | `tasks[].label` | Full command text (shown as the card's hover title) |
413
+ | `tasks[].status` | `running` / `stopping` / `completed` / `failed` / `killed` |
414
+ | `tasks[].elapsedMs` | Milliseconds elapsed (total once finished) |
415
+ | `tasks[].bytes` | Monotonic disk delta in bytes |
416
+ | `tasks[].speed` | Smoothed bytes per second |
417
+ | `tasks[].total` | Total size; `null` when unknown |
418
+ | `tasks[].detail` | Failure reason (`null` on success) |
419
+ | `tasks[].source` | Whether bytes mainly came from `target` or `temp` |
420
+ | `poll.hits` | Requests to this route — direct evidence the browser half is mounted |
421
+ | `poll.build` | Build marker of the Host that answered |
422
+
423
+ For debugging, add `?diag=...` to the URL: the value is truncated to 4000 characters and echoed in `poll.diag`, so you can confirm which build the browser actually reached.
424
+
425
+ ## Troubleshooting
426
+
427
+ | Symptom | Likely cause | Fix |
428
+ |---|---|---|
429
+ | No card at all | Not a background job | Use `run_in_background: true`; foreground downloads never show a card |
430
+ | | Command doesn't look like a download | Check it against the list above; `npm run build` and `git status` don't count |
431
+ | | Browser half not loaded | Refresh the page; confirm `dsh-download-dock` is in `bundles` |
432
+ | | Plugin disabled | Check `enabled`; look for `disabled by config` in the Host log |
433
+ | | `webServer` not ready | The plugin retries every 500 ms, 20 times; after that you'll see `webServer never became available` |
434
+ | Card appears but bytes stay at 0 | Download doesn't hit disk, or lands somewhere unresolved | Use an explicit `-o` / `-OutFile`; make sure `$var` paths expand to real absolute paths |
435
+ | | Directory too deep / too many entries | Raise `sampleBudgetMs`, or download into a shallower directory |
436
+ | Card always shows stripes | No total available | HEAD only runs for a single HTTP(S) URL with `probeTotals: true`; multi-package / multi-URL downloads have no single total |
437
+ | Card flashes and disappears | Task was very short | Cards stay hidden for the first 500 ms of a run; finished cards still show for 2.6 s, so a quick fade-out is normal |
438
+ | Card only appears after a refresh | The browser half doesn't hot reload | Expected — `client.js` changes require a page refresh |
439
+ | Numbers freeze mid-download | The job itself is stuck (DNS, TLS, silent server) | The card truthfully shows the last byte count and a zero speed; it does not guess |
440
+ | Speed curve wobbles on huge directories | Sampling budget too small | Raise `sampleBudgetMs`, or accept the estimate (see [Limitations](#limitations)) |
441
+ | Two `pip` runs bleed into each other | `%TEMP%` is shared | Prefix filtering makes it rare, but concurrent runs of the same tool can still mix; run them serially |
442
+
443
+ Three-state diagnosis with `poll.hits`:
444
+
445
+ | `hits` | Meaning | Next step |
446
+ |---|---|---|
447
+ | Not growing | Browser half isn't loaded | Refresh; check profile `bundles`; check the browser console |
448
+ | Growing, no card | Mounting or data problem | Check whether `/state` returns non-empty `tasks`; verify the page renders outside `shell.overlay` |
449
+ | Growing, card present, numbers frozen | Sampling isn't matching | Inspect `tasks[].source` and `bytes`; check targets and permissions |
450
+
451
+ ## Limitations
452
+
453
+ - **Foreground downloads never get a card.** This follows from Harness' job model and cannot be worked around; `run_in_background` is the only entry point.
454
+ - **Stripes are not a bug.** Without a total there is no honest percentage. `npm install` and multi-URL batch downloads have no single total by design.
455
+ - **`pip` / `npm` print no live progress in a non-TTY pipe.** The percentage is `disk delta ÷ total`; pip's total comes from its own opening line, and npm has even less, so it usually stays indeterminate.
456
+ - **`%TEMP%` is shared.** Two concurrent `pip` downloads can bleed into each other's byte counts; prefix filtering only makes it rare, not impossible.
457
+ - **Disk sampling is an estimate, not accounting.** Depth 3, 4000 entries, 220 ms budget: very large trees are partially counted and the curve can wobble.
458
+ - **HEAD probing covers a single URL only.** Non-HTTP(S) addresses, multi-URL commands and servers that refuse HEAD get no total, and probe failures are silent.
459
+ - **Ownerless jobs show bytes only.** A job that doesn't belong to a session has no output stream to observe.
460
+ - **State lives in memory.** Restarting Harness clears everything; there is no history and no persistence. This is not a download manager.
461
+ - **Sampling is single-threaded and serial.** More concurrent downloads means slower rounds and duller speed curves; the ledger keeps at most `maxTasks × 2` tasks and the snapshot exports the first `maxTasks`.
462
+ - **It doesn't verify downloads.** Hashes, signatures, extraction and installation are out of scope; it only looks at bytes.
463
+ - **It doesn't throttle or schedule.** It watches downloads, it doesn't manage them.
464
+
465
+ ## Development
466
+
467
+ ```powershell
468
+ git clone https://github.com/imnotRiv3r/dsh-download-dock.git
469
+ cd dsh-download-dock
470
+
471
+ node test/smoke.mjs # detection, parsing, merging, browser-half registration — fully offline
472
+ npm run check # node --check on every source file
473
+ ```
474
+
475
+ Project layout:
476
+
477
+ | File | Responsibility |
478
+ |---|---|
479
+ | `index.js` | Host entry: config normalization, job subscription, state route, prompt injection |
480
+ | `lib/detect.js` | Command detection, URL / output-flag / variable expansion, target resolution |
481
+ | `lib/tracker.js` | Task ledger, 700 ms sampling tick, speed smoothing, snapshot export |
482
+ | `lib/sampler.js` | Budgeted directory byte counting, `%TEMP%` prefix filtering, baselines |
483
+ | `lib/probe.js` | HEAD `content-length` probe (timeouts, redirects, status validation) |
484
+ | `client.js` | Browser half: polling, output parsing, merging, card rendering and portal mounting |
485
+ | `test/smoke.mjs` | Offline smoke test built from excerpts of real command output |
486
+ | `docs/*.svg`, `docs/*.png` | README artwork and card renders |
487
+
488
+ The smoke test covers 10 commands that must be detected, 7 that must not, shell variable expansion, pip `-d` exclusion, invalid `probeContentLength` inputs, git / aria2 / wget / curl progress frames, `present()`'s percentage and ETA, and `client.js`'s module and slot registration. Fixtures are excerpts of real output, and nothing touches the network.
489
+
490
+ ### Design decisions
491
+
492
+ | Decision | Why |
493
+ |---|---|
494
+ | Mount with `ReactDOM.createPortal` into `document.body` | The `shell.overlay` container carries `transform` / `overflow`, so a `position: fixed` card inside it gets clipped or positioned against that ancestor — the component runs but nothing is visible |
495
+ | 700 ms sampling / 600 ms polling | Fast enough to look continuous, cheap enough to leave the main process and browser alone |
496
+ | `downloaded = max(output, disk)` | Either path can lead temporarily; taking the max avoids progress stepping backwards |
497
+ | Deltas, not absolute sizes | Download folders usually contain old files that must not count toward this download |
498
+ | HEAD for single URLs only | Multi-URL downloads have no single total, so any probe result would be wrong |
499
+ | Observe, never intervene | The plugin must not affect job lifecycle, completion notices or model context |
500
+ | No hot reload for `client.js` | Harness registers browser modules at page load; edits require a refresh |
501
+
502
+ ## License
503
+
504
+ [MIT](LICENSE) © imnotRiv3r
505
+
506
+ ---
507
+
508
+ <p align="center">
509
+ <sub>If this card saves you a few terminal stares, a ⭐ is enough.</sub>
510
+ </p>