dsh-harness-toolbox 1.8.5 → 1.8.9

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
@@ -1,6 +1,33 @@
1
1
  # 变更记录
2
2
 
3
- > 版本号以 `package.json` 为准,每个发布版本对应一个 `vX.Y.Z` tag。安装方可以锁 `git+https://github.com/Homer4033/dsh-harness-toolbox.git#v1.8.5`。
3
+ > 版本号以 `package.json` 为准,每个发布版本对应一个 `vX.Y.Z` tag。安装方可以锁 `git+https://github.com/Homer4033/dsh-harness-toolbox.git#v1.8.9`。
4
+
5
+ ## 1.8.9 — 2026-11-24
6
+
7
+ - **插件说明重写**:插件页里那段说明原来是 1,343 字(英文 3,190 字符)的一大段流水账——GitHub CLI 讲了两遍、「组件管理」栏出现两次、还留着早已删掉的 1.4.x 仓库面板。现在按「五档压缩 / 四个工具 / 全局规则 / 组件管理 / 会话仓库 / 限制」分成六块,中文 669 字、英文 1,668 字符(各减一半),每块自带主语,浏览器把换行折叠掉也读得通。
8
+ - **显示名改为「压缩分档与工具箱」**(英文 `Compression tiers & toolbox`):功能早就超出「压缩分档」,包名也是 toolbox;加载器 id、状态目录、工具名都不变。
9
+ - `package.json` 的 `description` 从 470 字符压到 235,`keywords` 补 `toolbox` / `ffmpeg` / `github`,npm 搜索页不再是一长串。
10
+ - 说明里同步了这几版的新事实:掉线自动重试、已完成归档复用、安装替换失败回滚、会话标题下的仓库选择器。
11
+
12
+ ## 1.8.8 — 2026-11-21
13
+
14
+ - **修 `EPERM: rename 'staged-bin' -> 'bin'`**:包已经下完、二进制也自检通过,最后一步把暂存目录挪进安装位置时被 Windows 拒了——目录里还有文件被占用(杀毒在扫刚写出的 110 MB `ffmpeg.exe`,或者 `-version` 子进程还没退干净)时,`rename` 会报 `EPERM`。新增 `src/swap.js` 的 `moveIntoPlace()`:先按 200ms→400ms→…→6s 退避重试 7 次,锁还在就改用复制(读不锁、改名才锁),安装照样完成。`src/ffmpeg.js`、`src/components.js`(git / python)、`src/gh.js` 里所有到安装目录的移动都改走它,包括回滚路径。
15
+ - **重试不再白下**:下载完成的归档(`<root>/<id>/download/<file>`)现在会被复用——重试时先看它在不在,在就直接解压安装,不重新拉 110+ MB。这条对刚才那种「下完了、装的时候失败」的情况是最直接的救回。
16
+ - 测试 176 条(新增 `test/swap.test.js` 6 条:首试成功、锁重试后成功、锁不释放退化为复制、`ENOENT` 早退、跨卷 `EXDEV` 直接复制、错误分类)。
17
+
18
+ ## 1.8.7 — 2026-11-21
19
+
20
+ - **组件下载掉线自动重试**:以前只有「断点续传」——中断后 `.part` 留在磁盘上,但必须人再点一次「继续下载」。现在 `downloadWithResume` 自己在掉线时重试:默认 3 次(共 4 次尝试),退避 1.5s / 3s / 6s,**每次重试都从 `.part` 的字节偏移继续**(`Range: bytes=N-`),所以哪怕下到 100 MB 掉线也只补差额。gh / ffmpeg / git / python 四套组件共用这一段,一起生效。
21
+ - 不会重试的情况:`404` / `403` 这类再试也不会变的回答(`429` / `5xx` / `408` 会重试)、以及已经 `aborted` 的信号(20 分钟超时或人取消)——这两种立刻失败,省掉没有意义的十几秒等待。重试预算用尽后错误信息会带上「(gave up after N attempts)」,`.part` 依然保留,页面照旧给「继续下载」。
22
+ - 测试 170 条(新增 4 条:掉线重试并从 `.part` 续传、4xx 不重试、`aborted` 不重试且 `.part` 保留、预算用尽时报出尝试次数)。
23
+
24
+ ## 1.8.6 — 2026-11-21
25
+
26
+ - **会话头仓库胶囊挪到标题下面**:以前它被 `margin-left: auto` 甩到 View 标签行的最右端,和标题隔着上千像素的空白。现在紧跟标签之后,就在标题正下方、和「对话 / 轨迹」同一行;`margin-top: -4px` 让 24px 胶囊与标签文字基线对齐(由官方 `.tab` 的 -10px 外边距 + 10px 内边距推出,实测偏差 0px)。没有改官方 `titleRow` / `tabs` 的布局——header 高度是桌面窗口 chrome 几何的锚点。
27
+ - **胶囊更轻一点**:高度 26 → 24px,圆角胶囊、边距收紧;描边默认 `border-l2`、悬停升到 `border-l3`(深色主题里 l3 比 l2 明显);展开时箭头旋转 180° 并带 140ms 过渡;标题「仓库」降到 11px,仓库名加 500 字重;`max-width` 260 → 300px,`owner/name` 不再被截断(实测 30 字符名字自然宽度 266px)。
28
+ - **下拉菜单加了结构**:顶部一行标题「仓库」,`不使用仓库` 与仓库列表之间有分隔线;选项高度 30 → 32px,选中项名字加粗。仍然只有一份 portal、Esc / 外部点击 / resize 关闭。
29
+ - 测试 166 条(新增菜单标题 + 分隔线顺序、胶囊位置两条断言)。
30
+ - 渲染验证方式:把官方 `ConversationRoot` 的编译后 CSS 与插件样式表拼成一个静态页,用无头 Chromium 量出胶囊与标签文字中心线 `dy = 0.0px`、无文本截断,并截图核对(`output/capture/`)。真实 DSH 窗口内的最终观感仍需刷新页面确认。
4
31
 
5
32
  ## 1.8.5 — 2026-11-20
6
33
 
package/README.md CHANGED
@@ -18,13 +18,24 @@
18
18
 
19
19
  要求 Node.js ≥ 24.9;DSH 运行时 `0.2.2-rc.3` 到 `0.3.0` 之前(`engines.dsh` 声明)。
20
20
 
21
+ **从 npm 安装(推荐)**
22
+
23
+ 包名 `dsh-harness-toolbox`(已发布在 npmjs.com,版本见 `npm view dsh-harness-toolbox version`):
24
+
25
+ 1. DSH → **插件 → 添加插件**,输入包名 `dsh-harness-toolbox`(要锁版本就写 `dsh-harness-toolbox@1.8.5`);
26
+ 2. 安装完成后打开新会话 → **设置 → 上下文压缩**。
27
+
28
+ 也可以在会话里让智能体用 `plugin_manager` 安装这个包名。
29
+
30
+ **从本地目录安装**
31
+
21
32
  1. 把本仓库放到任意目录;
22
33
  2. DSH → **插件 → 添加插件**,选择这个目录;
23
34
  3. 打开新会话 → **设置 → 上下文压缩**。
24
35
 
25
- 也可以在会话里让智能体用 `plugin_manager` 的 `install_bundle` 安装。安装与启用都交给 DSH(不要手改 profile 的 `package.json` / `cordis.patch.yml`)。
36
+ 安装与启用都交给 DSH(不要手改 profile 的 `package.json` / `cordis.patch.yml`)。宿主包(`@deepseek-ai/dsh-home-paths`、`@deepseek-ai/dsh-tools`)由运行时提供,本包只声明为可选 `peerDependencies`,这样以「链接到外部目录」方式安装也能解析。
26
37
 
27
- 宿主包(`@deepseek-ai/dsh-home-paths`、`@deepseek-ai/dsh-tools`)由运行时提供,本包只声明为可选 `peerDependencies`,这样以「链接到外部目录」方式安装也能解析。
38
+ > 国内镜像(npmmirror)同步可能滞后:插件页装不到刚发布的版本时,先用上面的 `npm view` 确认线上版本,再等镜像同步或换 registry。
28
39
 
29
40
  ## 使用
30
41
 
package/client.js CHANGED
@@ -530,12 +530,18 @@ window.__ModuleLoader__.load({
530
530
  .ct-component-path {
531
531
  word-break: break-all;
532
532
  }
533
+ /* The pill lives in the tab strip, right after the tabs: that row is the only
534
+ chrome below the title that is not clipped (the title cluster itself is
535
+ overflow:clip with a mask fade), so the capsule reads as session meta instead
536
+ of being stranded at the far right edge. margin-top lines the 24px pill up
537
+ with the tab labels: a .tab starts -10px and pads 10px, so its label centre
538
+ sits 8px below the strip's content top, and 8 - 24/2 = -4. */
533
539
  .ct-repo-slot {
534
540
  display: flex;
535
541
  align-items: center;
542
+ align-self: flex-start;
536
543
  flex: none;
537
- margin-left: auto;
538
- margin-top: 2px;
544
+ margin-top: -4px;
539
545
  }
540
546
  .ct-repo-anchor-wrap {
541
547
  display: contents;
@@ -553,24 +559,25 @@ window.__ModuleLoader__.load({
553
559
  position: relative;
554
560
  display: inline-flex;
555
561
  align-items: center;
556
- gap: 5px;
562
+ gap: 6px;
557
563
  box-sizing: border-box;
558
- height: 26px;
559
- max-width: 260px;
564
+ height: 24px;
565
+ max-width: 300px;
560
566
  min-width: 0;
561
- padding: 0 8px;
567
+ padding: 0 9px 0 8px;
562
568
  border: 1px solid var(--dsw-alias-border-l2);
563
569
  border-radius: 999px;
564
570
  background: transparent;
565
571
  color: var(--dsw-alias-label-secondary);
566
572
  font-size: 12px;
567
- line-height: 16px;
573
+ line-height: 15px;
568
574
  white-space: nowrap;
569
- transition: background-color 120ms ease, border-color 120ms ease;
575
+ transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
570
576
  }
571
577
  @media (hover: hover) {
572
578
  .ct-repo-pill:hover {
573
579
  background: var(--dsw-alias-interactive-bg-hover);
580
+ border-color: var(--dsw-alias-border-l3);
574
581
  }
575
582
  }
576
583
  .ct-repo-pill:focus-within {
@@ -580,6 +587,7 @@ window.__ModuleLoader__.load({
580
587
  .ct-repo-pill[data-bound='true'] {
581
588
  border-color: var(--dsw-alias-border-selected);
582
589
  background: var(--dsw-alias-bg-module-platform);
590
+ color: var(--dsw-alias-label-primary);
583
591
  }
584
592
  .ct-repo-icon {
585
593
  flex: none;
@@ -593,6 +601,7 @@ window.__ModuleLoader__.load({
593
601
  .ct-repo-caption {
594
602
  flex: none;
595
603
  color: var(--dsw-alias-label-tertiary);
604
+ font-size: 11px;
596
605
  }
597
606
  .ct-repo-value {
598
607
  min-width: 0;
@@ -600,12 +609,21 @@ window.__ModuleLoader__.load({
600
609
  text-overflow: ellipsis;
601
610
  white-space: nowrap;
602
611
  color: var(--dsw-alias-label-primary);
612
+ font-weight: 500;
603
613
  }
604
614
  .ct-repo-chevron {
605
615
  flex: none;
606
616
  width: 12px;
607
617
  height: 12px;
608
618
  color: var(--dsw-alias-label-tertiary);
619
+ transition: transform 140ms ease;
620
+ }
621
+ .ct-repo-pill[aria-expanded='true'] .ct-repo-chevron {
622
+ transform: rotate(180deg);
623
+ }
624
+ .ct-repo-pill[aria-expanded='true'] {
625
+ border-color: var(--dsw-alias-border-l2);
626
+ background: var(--dsw-alias-interactive-bg-hover);
609
627
  }
610
628
  .ct-repo-pill {
611
629
  font-family: inherit;
@@ -633,12 +651,23 @@ window.__ModuleLoader__.load({
633
651
  font-size: 12px;
634
652
  line-height: 16px;
635
653
  }
654
+ .ct-repo-menu-head {
655
+ padding: 2px 8px 4px;
656
+ color: var(--dsw-alias-label-tertiary);
657
+ font-size: 11px;
658
+ line-height: 15px;
659
+ }
660
+ .ct-repo-sep {
661
+ height: 1px;
662
+ margin: 4px 8px;
663
+ background: var(--dsw-alias-border-l3);
664
+ }
636
665
  .ct-repo-option {
637
666
  display: flex;
638
667
  align-items: center;
639
668
  gap: 8px;
640
669
  width: 100%;
641
- min-height: 30px;
670
+ min-height: 32px;
642
671
  margin: 0;
643
672
  padding: 0 8px;
644
673
  border: 0;
@@ -661,6 +690,9 @@ window.__ModuleLoader__.load({
661
690
  .ct-repo-option-on {
662
691
  background: var(--dsw-alias-bg-module-platform);
663
692
  }
693
+ .ct-repo-option-on .ct-repo-option-name {
694
+ font-weight: 500;
695
+ }
664
696
  .ct-repo-check {
665
697
  flex: none;
666
698
  width: 12px;
@@ -975,6 +1007,24 @@ window.__ModuleLoader__.load({
975
1007
  }, h('path', { d: 'M4.5 6.25 8 9.75l3.5-3.5' })))
976
1008
 
977
1009
  const at = placement.current || { top: 0, left: 0, width: 240 }
1010
+ // Head line + separator keep "no repository" apart from the real list, so
1011
+ // the menu reads as a titled picker rather than a flat run of names.
1012
+ const menuChildren = [h('div', { key: '__head', className: 'ct-repo-menu-head', role: 'presentation' }, t('repoSelectLabel'))]
1013
+ items.forEach(function (item, index) {
1014
+ if (index === 1) menuChildren.push(h('div', { key: '__sep', className: 'ct-repo-sep', role: 'presentation' }))
1015
+ const selected = item.value === bound
1016
+ menuChildren.push(h('button', {
1017
+ key: item.value || '__none',
1018
+ type: 'button',
1019
+ role: 'option',
1020
+ 'aria-selected': selected ? 'true' : 'false',
1021
+ className: 'ct-repo-option' + (selected ? ' ct-repo-option-on' : ''),
1022
+ onClick: function () { chooseRepo(item.value) },
1023
+ },
1024
+ h('span', { className: 'ct-repo-check' }, selected ? '✓' : ''),
1025
+ h('span', { className: 'ct-repo-option-name' }, item.label),
1026
+ item.private ? h('span', { className: 'ct-repo-tag' }, t('repoPrivate')) : null))
1027
+ })
978
1028
  const menu = open && ReactDOM && typeof ReactDOM.createPortal === 'function'
979
1029
  ? ReactDOM.createPortal(h('div', {
980
1030
  ref: menuRef,
@@ -982,21 +1032,7 @@ window.__ModuleLoader__.load({
982
1032
  role: 'listbox',
983
1033
  'aria-label': t('repoSelectAria'),
984
1034
  style: { top: at.top + 'px', left: at.left + 'px', width: at.width + 'px' },
985
- },
986
- items.map(function (item) {
987
- const selected = item.value === bound
988
- return h('button', {
989
- key: item.value || '__none',
990
- type: 'button',
991
- role: 'option',
992
- 'aria-selected': selected ? 'true' : 'false',
993
- className: 'ct-repo-option' + (selected ? ' ct-repo-option-on' : ''),
994
- onClick: function () { chooseRepo(item.value) },
995
- },
996
- h('span', { className: 'ct-repo-check' }, selected ? '✓' : ''),
997
- h('span', { className: 'ct-repo-option-name' }, item.label),
998
- item.private ? h('span', { className: 'ct-repo-tag' }, t('repoPrivate')) : null)
999
- })), document.body)
1035
+ }, menuChildren), document.body)
1000
1036
  : null
1001
1037
 
1002
1038
  const group = h('span', { className: 'ct-repo-group' },
package/locale/en.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
- "title": "Context compression tiers",
4
- "description": "Adds a Context compression page under Settings with five automatic compaction tiers (gentle, light, standard, aggressive, max). Picking a tier pushes its thresholdRatio and retainRatio into every mounted agent preset compaction engine immediately, so no restart is needed, and stores the choice in <DSH home>/compression-tiers/settings.json. The plugin also adds four agent tools: compression_tiers reads or changes the tier and accepts optional per-route headroom overrides; compression_context reports live occupancy, the tier threshold and the room left; compression_compact queues a proactive compaction that runs after the turn and resumes the conversation by itself; github_push publishes the current work — the session working directory by default — after a network probe and a secret scan, with a 60-second push deadline and a failure family plus whatever is still local when it fails. A [context] line at the conversation tail reports the same occupancy. Every tier keeps automatic pressure compaction on, and /compact remains available to the human. The lower half of the page also edits the global rules: it reads and atomically writes the official instruction file <DSH home>/AGENTS.md (the official dsh-agent-instructions plugin injects it into later sessions), and the system prompt carries the newest 2,000-character clip; agents get no tool to rewrite that file, only a save on the page writes it. The page's Components panel manages GitHub CLI: it detects a gh on PATH and downloads a managed pinned gh 2.76.2 copy (resumable, atomic install, rollback on failure); a separate GitHub sign-in panel runs the gh auth login --web device flow for the official change-request panel, and the credential stays in gh's own store, which the plugin never reads. The Components panel keeps four managed components in one place: GitHub CLI 2.76.2, git 2.56.1 (MinGit), ffmpeg and ffprobe (the gyan.dev release build) and Python 3.11.18 (python-build-standalone). Each row detects the PATH copy and can download the managed build (unpacked into a staging directory, probed, then swapped in as a whole tree with rollback on failure); the managed copy wins and goes first on this process's PATH. All four share one configurable download root (default <DSH home>/compression-tiers) that the same panel can move as a whole. A repository selector beside the session title lists the account's repositories with gh repo list and binds one to the session; github_push then publishes to https://github.com/owner/name.git by default (it only changes the push target, never clones or edits the workspace), and the binding lives in sessionRepos in settings.json. Limitations: the tiers are designed for windows of at least 256k tokens (the official 65,536-token headroom caps smaller windows); the plugin updates preset-isolated engines and leaves the host-plane row alone; remove any other plugin that manages the same compaction engines or the two will fight over the policy; the 1.4.x sidebar repository panel is gone, and several repositories are published from each session through github_push; changing a tier updates the engines live, but a browser reload may be needed to see the page again.",
3
+ "title": "Compression tiers & toolbox",
4
+ "description": "Five automatic compaction tiers — gentle / light / standard / aggressive / max: picking one writes thresholdRatio and retainRatio into every mounted preset compacting engine, no restart needed; the choice lives in <DSH home>/compression-tiers/settings.json, every tier keeps automatic pressure compaction, and /compact still works by hand.\n\nFour agent tools: compression_tiers reads or changes the tier (optional per-route headroom overrides); compression_context reports live occupancy and the room left; compression_compact queues one proactive compaction that runs after the turn and resumes by itself; github_push publishes the current work (network probe, secret scan, 60-second deadline, a failure family plus whatever is still local).\n\nGlobal rules: the page edits <DSH home>/AGENTS.md atomically, the system prompt carries the newest 2,000-character clip, and no agent tool can rewrite that file.\n\nComponents: four managed builds — GitHub CLI 2.76.2, git 2.56.1, ffmpeg/ffprobe, Python 3.11.18. PATH detection, a managed download with resume (retries a dropped link, probes before swapping the tree in, rolls back on failure, reuses a finished archive), managed copies first on this process PATH, one migratable download root for all four, and gh device-code sign-in beside them.\n\nSession repository: a selector under the session title binds the session to one writable repository, and github_push targets it by default (it only changes the push target, never clones or edits the workspace).\n\nLimits: the tiers assume 256k-token windows or more, only preset-isolated engines are updated, and another plugin managing the same engines will fight over the policy.",
5
5
  "detail": "docs/DETAIL.md"
6
6
  }
7
7
  }
package/locale/zh.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
- "title": "上下文压缩分档",
4
- "description": "在「设置 → 上下文压缩」里提供五档自动压缩策略(极轻、轻量、标准、积极、最大)。选中档位后立即把 thresholdRatio / retainRatio 写入每个已挂载的 Agent 预设压缩引擎,无需重启;选择保存在 <DSH home>/compression-tiers/settings.json。插件还提供四个智能体工具:compression_tiers 读取或切换档位,并接受可选的按路由 headroom 覆盖;compression_context 返回实时占用、本档阈值与剩余空间;compression_compact 排队一次主动压缩,本轮结束后执行并自动继续;github_push 发布当前工作区——默认取本会话的工作目录,先做网络体检与密钥扫描,再带 60 秒超时推送,失败时给出分类与仍在本地的东西。对话尾部的 [context] 行会报告同样的占用信息。每档都保留自动压力压缩,人类仍可使用 /compact。设置页下半部分还能编辑全局规则:直接读写官方指令文件 <DSH home>/AGENTS.md(官方 dsh-agent-instructions 会在之后的会话里注入它),保存是原子写入,系统提示里另带最新 2000 字符的摘要;智能体没有改写该文件的工具,只有你在设置页保存才会写入。设置页的「组件管理」栏管理 GitHub CLI:识别系统 PATH、下载固定版本 gh 2.76.2 的托管副本(断点续传、原子安装、失败回滚);另有独立的 GitHub 登录栏,用 gh auth login --web 的设备码流程登录,供官方变更请求面板使用;凭据存在 gh 自己的存储里,插件不读取。设置页的「组件管理」栏把四套托管组件放在一起:GitHub CLI 2.76.2、git 2.56.1(MinGit)、ffmpeg / ffprobe(gyan.dev 的 release 构建)与 Python 3.11.18(python-build-standalone);逐个检测系统 PATH,并可断点续传下载托管版(解压到临时目录、先自检再原子替换整棵目录,失败回滚),托管版优先并插到本进程 PATH 最前;四套组件共用一个可配置的下载根目录(默认 <DSH home>/compression-tiers),可在同一栏整体迁移。会话标题旁有一个在线仓库选择器:用 gh repo list 列出账号可写仓库,为当前会话绑定一个;绑定后 github_push 默认推到 https://github.com/owner/name.git(只改推送目标,不克隆也不改工作区),绑定保存在 settings.json 的 sessionRepos 里。限制:五档按 ≥256k tokens 窗口设计(官方 65,536 输出余量会限制更小的窗口);插件只更新预设隔离域里的引擎,不改宿主平面上的那一行;如果同时安装其他管理同一批压缩引擎或同名职责的插件,两者会互相覆盖策略;1.4.x 的左侧栏仓库面板已删除,多仓库由各会话里的 github_push 负责;切换档位后引擎立即生效,但设置页可能需要刷新浏览器才能重新读取。",
3
+ "title": "压缩分档与工具箱",
4
+ "description": "五档自动压缩:极轻 / 轻量 / 标准 / 积极 / 最大,选中即写入所有已挂载预设的压缩引擎,无需重启;设置存在 <DSH home>/compression-tiers/settings.json,每档保留自动压力压缩,/compact 仍可手动触发。\n\n四个智能体工具:compression_tiers 读取或切换档位(可按路由覆盖 headroom);compression_context 报实时占用与剩余空间;compression_compact 排队一次主动压缩,本轮结束后执行并自动继续;github_push 发布当前工作区(网络体检、密钥扫描、60 秒超时,失败给出分类与仍在本地的东西)。\n\n全局规则:设置页原子编辑 <DSH home>/AGENTS.md,系统提示只带最新 2000 字符摘要,智能体没有改写它的工具。\n\n组件管理:四套托管组件 GitHub CLI 2.76.2、git 2.56.1、ffmpeg / ffprobe、Python 3.11.18。检测系统 PATH,可下载托管版(断点续传、掉线自动重试、自检后整树替换、失败回滚、复用已下载的归档),托管版优先并插到本进程 PATH 最前;四套共用一个可整体迁移的下载根目录,同栏有 gh 设备码登录。\n\n会话仓库:标题下的选择器把当前会话绑到一个可写仓库,github_push 默认推到它(只改推送目标,不克隆也不改工作区)。\n\n限制:档位按 ≥256k tokens 窗口设计;只更新预设隔离域里的引擎;与同类插件会互相覆盖策略。",
5
5
  "detail": "docs/DETAIL.zh.md"
6
6
  }
7
7
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "dsh-harness-toolbox",
3
- "version": "1.8.5",
3
+ "version": "1.8.9",
4
4
  "private": false,
5
5
  "type": "module",
6
- "description": "Five-tier context compression policy for official DeepSeek Harness plus a global rules editor and GitHub publishing: settings page, agent tools (compression_tiers, compression_context, compression_compact, github_push), live occupancy meter, proactive compaction, /AGENTS.md, a component manager that installs and PATH-prefixes the GitHub CLI, git, ffmpeg/ffprobe and Python below one configurable download root (whole-directory migration), GitHub device-code login, and a per-session online repository binding in the session header.",
6
+ "description": "Five-tier context compaction for DeepSeek Harness plus global rules editing, a managed component installer (gh, git, ffmpeg/ffprobe, Python) below one migratable download root, GitHub device login and per-session repository publishing.",
7
7
  "license": "MIT",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -15,7 +15,10 @@
15
15
  "dsh-plugin",
16
16
  "context",
17
17
  "compaction",
18
- "rules"
18
+ "rules",
19
+ "toolbox",
20
+ "ffmpeg",
21
+ "github"
19
22
  ],
20
23
  "repository": {
21
24
  "type": "git",
package/src/components.js CHANGED
@@ -2,6 +2,7 @@ import { chmodSync, cpSync, existsSync, mkdirSync, readdirSync, renameSync, rmSy
2
2
 
3
3
  import { join } from 'node:path'
4
4
  import { downloadWithResume, extractArchive, runCommand } from './gh.js'
5
+ import { moveIntoPlace } from './swap.js'
5
6
 
6
7
  /**
7
8
  * Managed components beyond `gh` and ffmpeg: git and Python.
@@ -259,14 +260,16 @@ function prune(root, id) {
259
260
  * Move the staged tree into place and probe the installed binary. The previous
260
261
  * install is kept until the probe passes, then dropped; on failure it is
261
262
  * restored, so an install either fully replaces the component or changes
262
- * nothing.
263
+ * nothing. Both renames go through `moveIntoPlace`: Windows reports a tree that
264
+ * is still being scanned (or whose probe process has not fully exited) as
265
+ * `EPERM`, so the swap retries and finally copies instead of failing.
263
266
  */
264
267
  async function swapTree(finalDir, stagedDir, spec, platform, run) {
265
268
  const backup = `${finalDir}.old-${process.pid}-${Date.now()}`
266
269
  let moved = false
267
270
  try {
268
- if (existsSync(finalDir)) renameSync(finalDir, backup)
269
- renameSync(stagedDir, finalDir)
271
+ if (existsSync(finalDir)) await moveIntoPlace(finalDir, backup)
272
+ await moveIntoPlace(stagedDir, finalDir)
270
273
  moved = true
271
274
  const binary = join(finalDir, spec.binary)
272
275
  const check = await run(binary, spec.args, { timeoutMs: VERIFY_TIMEOUT_MS })
@@ -289,7 +292,7 @@ async function swapTree(finalDir, stagedDir, spec, platform, run) {
289
292
  // Keep restoring the old tree even if the new one is locked.
290
293
  }
291
294
  try {
292
- if (existsSync(backup)) renameSync(backup, finalDir)
295
+ if (existsSync(backup)) await moveIntoPlace(backup, finalDir)
293
296
  } catch {
294
297
  // Best effort; the caller still reports the install error.
295
298
  }
@@ -323,17 +326,21 @@ export async function startComponentDownload(root, id, { platform = process.plat
323
326
  void (async () => {
324
327
  const downloadDir = join(dir, 'download')
325
328
  mkdirSync(downloadDir, { recursive: true })
326
- await downloadWithResume({
327
- url: asset.url,
328
- partPath: part,
329
- signal: controller.signal,
330
- onProgress: (progress) => {
331
- job.received = progress.received
332
- job.total = progress.total
333
- },
334
- })
335
329
  const archive = join(downloadDir, asset.file)
336
- renameSync(part, archive)
330
+ // A finished download is what puts the archive there, so a retry after a
331
+ // failed install reuses it instead of downloading the release again.
332
+ if (!existsSync(archive)) {
333
+ await downloadWithResume({
334
+ url: asset.url,
335
+ partPath: part,
336
+ signal: controller.signal,
337
+ onProgress: (progress) => {
338
+ job.received = progress.received
339
+ job.total = progress.total
340
+ },
341
+ })
342
+ await moveIntoPlace(part, archive)
343
+ }
337
344
  const staging = stagingRoot(root, id)
338
345
  rmSync(staging, { recursive: true, force: true })
339
346
  const unpacked = join(staging, 'unpacked')
@@ -360,7 +367,7 @@ export async function startComponentDownload(root, id, { platform = process.plat
360
367
  cpSync(tree, staged, { recursive: true })
361
368
  rmSync(unpacked, { recursive: true, force: true })
362
369
  } else {
363
- renameSync(unpacked, staged)
370
+ await moveIntoPlace(unpacked, staged)
364
371
  }
365
372
  await swapTree(dir, staged, spec, platform, run)
366
373
  prune(root, id)
package/src/ffmpeg.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { chmodSync, copyFileSync, existsSync, mkdirSync, renameSync, rmSync, statSync } from 'node:fs'
2
2
  import { join } from 'node:path'
3
3
  import { downloadWithResume, extractArchive, findBinary, runCommand } from './gh.js'
4
+ import { moveIntoPlace } from './swap.js'
4
5
 
5
6
  /**
6
7
  * Managed ffmpeg + ffprobe, next to the managed `gh`.
@@ -167,15 +168,17 @@ function prune(root) {
167
168
 
168
169
  /**
169
170
  * Move the staged `bin` directory into place. The previous directory is kept
170
- * until the new binaries answer `-version`, then removed.
171
+ * until the new binaries answer `-version`, then removed. Renames go through
172
+ * `moveIntoPlace` so a lingering lock (antivirus scanning the freshly probed
173
+ * binaries) retries and, if needed, copies instead of failing the install.
171
174
  */
172
175
  async function swapBinDir(root, stagedBin, platform) {
173
176
  const binDir = ffmpegBinDir(root)
174
177
  const backup = `${binDir}.old-${process.pid}-${Date.now()}`
175
178
  let moved = false
176
179
  try {
177
- if (existsSync(binDir)) renameSync(binDir, backup)
178
- renameSync(stagedBin, binDir)
180
+ if (existsSync(binDir)) await moveIntoPlace(binDir, backup)
181
+ await moveIntoPlace(stagedBin, binDir)
179
182
  moved = true
180
183
  const names = ffmpegSource(platform).binaries
181
184
  for (const name of Object.values(names)) {
@@ -192,7 +195,7 @@ async function swapBinDir(root, stagedBin, platform) {
192
195
  // Keep restoring the old directory even if the new one is locked.
193
196
  }
194
197
  try {
195
- if (existsSync(backup)) renameSync(backup, binDir)
198
+ if (existsSync(backup)) await moveIntoPlace(backup, binDir)
196
199
  } catch {
197
200
  // Best effort; the caller still reports the install error.
198
201
  }
@@ -230,17 +233,22 @@ export function startFfmpegDownload(root, { platform = process.platform, arch =
230
233
 
231
234
  void (async () => {
232
235
  mkdirSync(downloadDir, { recursive: true })
233
- await downloadWithResume({
234
- url: source.url,
235
- partPath: part,
236
- signal: controller.signal,
237
- onProgress: (progress) => {
238
- job.received = progress.received
239
- job.total = progress.total
240
- },
241
- })
242
236
  const archive = join(downloadDir, source.file)
243
- renameSync(part, archive)
237
+ // The archive only carries this name after a finished download, so a retry
238
+ // after a failed install (locked bin, probe failure) reuses it instead of
239
+ // pulling 110+ MB again.
240
+ if (!existsSync(archive)) {
241
+ await downloadWithResume({
242
+ url: source.url,
243
+ partPath: part,
244
+ signal: controller.signal,
245
+ onProgress: (progress) => {
246
+ job.received = progress.received
247
+ job.total = progress.total
248
+ },
249
+ })
250
+ await moveIntoPlace(part, archive)
251
+ }
244
252
  const staging = join(ffmpegRoot(root), 'src')
245
253
  await extractArchive(archive, staging, source.kind, platform)
246
254
  const stagedBin = join(ffmpegRoot(root), 'staged-bin')
package/src/gh.js CHANGED
@@ -4,6 +4,7 @@ import { pipeline } from 'node:stream/promises'
4
4
  import { basename, dirname, join } from 'node:path'
5
5
  import { spawn } from 'node:child_process'
6
6
  import { proxyEnv } from './publish.js'
7
+ import { moveIntoPlace } from './swap.js'
7
8
 
8
9
  /**
9
10
  * GitHub CLI (`gh`) management, merged in from `homerdsh-workbench`. The
@@ -165,12 +166,58 @@ async function fetchKeepingRange(url, headers, signal, fetchImpl, hops = 0) {
165
166
  return response
166
167
  }
167
168
 
169
+ /** Defaults for {@link downloadWithResume}'s automatic retries. */
170
+ const DOWNLOAD_RETRIES = 3
171
+ const DOWNLOAD_RETRY_DELAY_MS = 1500
172
+
173
+ /** HTTP statuses that are worth another attempt; other 4xx answers are final. */
174
+ const RETRYABLE_STATUS = new Set([408, 425, 429, 500, 502, 503, 504])
175
+
176
+ /** Socket / fetch error codes a retry can plausibly fix. */
177
+ const RETRYABLE_CODE = new Set([
178
+ 'ECONNRESET', 'ECONNREFUSED', 'ECONNABORTED', 'EPIPE', 'ETIMEDOUT', 'ENETUNREACH',
179
+ 'ENETDOWN', 'EHOSTUNREACH', 'ENOTFOUND', 'EAI_AGAIN', 'UND_ERR_SOCKET',
180
+ 'UND_ERR_CONNECT_TIMEOUT', 'UND_ERR_HEADERS_TIMEOUT', 'UND_ERR_BODY_TIMEOUT',
181
+ ])
182
+
168
183
  /**
169
- * Download with HTTP `Range` resume: an interrupted run keeps its `.part`
170
- * file and the next attempt continues from its byte offset. A `416` means the
171
- * partial file belongs to another version, so it is dropped and refetched.
184
+ * Whether the failure is a dropped connection rather than a real answer: a 404
185
+ * or an aborted signal will fail exactly the same way next time, so retrying it
186
+ * only delays the error the page has to show.
187
+ */
188
+ function isRetryableDownloadError(error, signal) {
189
+ if (!error || signal?.aborted) return false
190
+ if (error.name === 'AbortError') return false
191
+ if (typeof error.status === 'number') return RETRYABLE_STATUS.has(error.status)
192
+ if (RETRYABLE_CODE.has(String(error.code || ''))) return true
193
+ return /fetch failed|socket hang up|other side closed|premature|network|ECONNRESET|ETIMEDOUT|EAI_AGAIN/i.test(String(error.message || ''))
194
+ }
195
+
196
+ /** `setTimeout` that rejects as soon as the download is aborted. */
197
+ function waitForRetry(delayMs, signal) {
198
+ return new Promise((resolve, reject) => {
199
+ const abortError = () => (signal.reason instanceof Error ? signal.reason : new Error('download aborted'))
200
+ if (signal?.aborted) {
201
+ reject(abortError())
202
+ return
203
+ }
204
+ const timer = setTimeout(() => {
205
+ signal?.removeEventListener?.('abort', onAbort)
206
+ resolve()
207
+ }, delayMs)
208
+ function onAbort() {
209
+ clearTimeout(timer)
210
+ reject(abortError())
211
+ }
212
+ signal?.addEventListener?.('abort', onAbort, { once: true })
213
+ })
214
+ }
215
+
216
+ /**
217
+ * One download attempt. The `.part` file is the resume point, so a previous
218
+ * attempt's bytes are counted from disk every time this runs.
172
219
  */
173
- export async function downloadWithResume({ url, partPath: target, fetchImpl = fetch, onProgress, signal }) {
220
+ async function downloadAttempt({ url, partPath: target, fetchImpl, onProgress, signal }) {
174
221
  mkdirSync(dirname(target), { recursive: true })
175
222
  let existing = existsSync(target) ? statSync(target).size : 0
176
223
  const request = (resume) => fetchKeepingRange(
@@ -186,7 +233,9 @@ export async function downloadWithResume({ url, partPath: target, fetchImpl = fe
186
233
  response = await request(false)
187
234
  }
188
235
  if (response.status !== 200 && response.status !== 206) {
189
- throw new Error(`download failed HTTP ${response.status}`)
236
+ const error = new Error(`download failed HTTP ${response.status}`)
237
+ error.status = response.status
238
+ throw error
190
239
  }
191
240
  const restart = response.status === 200
192
241
  const contentRange = response.headers.get('content-range') || ''
@@ -209,6 +258,46 @@ export async function downloadWithResume({ url, partPath: target, fetchImpl = fe
209
258
  return { received, total, resumedFrom: restart ? 0 : existing }
210
259
  }
211
260
 
261
+ /**
262
+ * Download with HTTP `Range` resume: an interrupted run keeps its `.part`
263
+ * file and the next attempt continues from its byte offset. A `416` means the
264
+ * partial file belongs to another version, so it is dropped and refetched.
265
+ *
266
+ * A dropped connection is retried automatically (`retries` extra attempts with
267
+ * an exponential backoff) and every retry resumes from the `.part` file, so a
268
+ * flaky link costs seconds instead of the whole archive. Answers that will not
269
+ * change (404 and friends) and an aborted signal fail at once — the page then
270
+ * offers 「继续下载」 on the kept `.part` file.
271
+ */
272
+ export async function downloadWithResume({
273
+ url,
274
+ partPath: target,
275
+ fetchImpl = fetch,
276
+ onProgress,
277
+ onRetry,
278
+ signal,
279
+ retries = DOWNLOAD_RETRIES,
280
+ retryDelayMs = DOWNLOAD_RETRY_DELAY_MS,
281
+ }) {
282
+ let attempts = 0
283
+ for (;;) {
284
+ attempts += 1
285
+ try {
286
+ return await downloadAttempt({ url, partPath: target, fetchImpl, onProgress, signal })
287
+ } catch (error) {
288
+ if (attempts > retries || !isRetryableDownloadError(error, signal)) {
289
+ if (attempts > 1 && error instanceof Error) {
290
+ error.message = `${error.message} (gave up after ${attempts} attempts)`
291
+ }
292
+ throw error
293
+ }
294
+ const delayMs = retryDelayMs * 2 ** (attempts - 1)
295
+ onRetry?.({ attempt: attempts, retries, delayMs, error })
296
+ await waitForRetry(delayMs, signal)
297
+ }
298
+ }
299
+ }
300
+
212
301
  /** Run a command with a deadline, capturing both streams; shared with the ffmpeg manager. */
213
302
  export function runCommand(command, args, { timeoutMs = COMMAND_TIMEOUT_MS, env = process.env } = {}) {
214
303
  return new Promise((resolve) => {
@@ -331,9 +420,9 @@ async function installBinary(temp, final, platform) {
331
420
  }
332
421
  if (existsSync(final)) {
333
422
  backup = `${final}.old-${process.pid}-${Date.now()}`
334
- renameSync(final, backup)
423
+ await moveIntoPlace(final, backup)
335
424
  }
336
- renameSync(temp, final)
425
+ await moveIntoPlace(temp, final)
337
426
  installed = true
338
427
  const check = await runCommand(final, ['--version'], { timeoutMs: VERIFY_TIMEOUT_MS })
339
428
  if (check.code !== 0) {
@@ -354,7 +443,7 @@ async function installBinary(temp, final, platform) {
354
443
  // Keep restoring the older copy even if the new file is locked.
355
444
  }
356
445
  try {
357
- if (backup && existsSync(backup)) renameSync(backup, final)
446
+ if (backup && existsSync(backup)) await moveIntoPlace(backup, final)
358
447
  } catch {
359
448
  // Best effort; the caller still reports the install error.
360
449
  }
@@ -387,18 +476,23 @@ export function startGhDownload(root, { platform = process.platform, arch = proc
387
476
  controller.abort(new Error('download timed out after 10 minutes'))
388
477
  }, DOWNLOAD_TIMEOUT_MS)
389
478
  if (typeof timer.unref === 'function') timer.unref()
390
- downloadWithResume({
391
- url: asset.url,
392
- partPath: target,
393
- signal: controller.signal,
394
- onProgress: (progress) => {
395
- job.received = progress.received
396
- job.total = progress.total
397
- },
398
- }).then(async () => {
479
+ // A renamed archive only exists once a download finished, so retrying after a
480
+ // failed install (locked binary, probe failure) reuses it instead of pulling
481
+ // the whole release again.
482
+ const archivePath = join(downloadDir(root), asset.file)
483
+ const ready = existsSync(archivePath)
484
+ ? Promise.resolve()
485
+ : downloadWithResume({
486
+ url: asset.url,
487
+ partPath: target,
488
+ signal: controller.signal,
489
+ onProgress: (progress) => {
490
+ job.received = progress.received
491
+ job.total = progress.total
492
+ },
493
+ }).then(() => moveIntoPlace(target, archivePath))
494
+ ready.then(async () => {
399
495
  clearTimeout(timer)
400
- const archivePath = join(downloadDir(root), asset.file)
401
- renameSync(target, archivePath)
402
496
  const staging = join(ghRoot(root), 'src')
403
497
  await extractArchive(archivePath, staging, asset.kind, platform)
404
498
  const binaryName = ghBinaryName(platform)
package/src/swap.js ADDED
@@ -0,0 +1,77 @@
1
+ import { cpSync, renameSync, rmSync } from 'node:fs'
2
+
3
+ /**
4
+ * Atomic-ish replacement of an installed tree.
5
+ *
6
+ * Windows refuses `rename()` on a directory while any file inside it is still
7
+ * open — an antivirus halfway through scanning a freshly written 110 MB
8
+ * `ffmpeg.exe`, or the child process that just answered `-version`, is enough —
9
+ * and it reports that as `EPERM`. The lock is short-lived, so the first answer
10
+ * is to retry with a backoff. If the lock outlives the retries, renaming is
11
+ * hopeless but *reading* is not, so the tree is copied into the free path
12
+ * instead: the install still finishes, it just costs a copy.
13
+ *
14
+ * Renaming onto an existing non-empty directory also fails (`EPERM` /
15
+ * `ENOTEMPTY` on Windows, `ENOTEMPTY` on POSIX), so callers keep the contract
16
+ * that `to` must be free; the copy fallback clears it first anyway.
17
+ */
18
+
19
+ /** Locks that clear on their own: retry before giving up on the rename. */
20
+ const LOCKED = new Set(['EPERM', 'EACCES', 'EBUSY', 'ENOTEMPTY', 'EEXIST'])
21
+
22
+ /** Errors that will never survive a retry but are fine for a copy. */
23
+ const CROSS_DEVICE = new Set(['EXDEV'])
24
+
25
+ /** Whether a filesystem error is a transient lock rather than a real refusal. */
26
+ export function isLockedError(error) {
27
+ return Boolean(error) && LOCKED.has(String(error.code || ''))
28
+ }
29
+
30
+ /** Whether the destination lives on another volume, so only a copy can work. */
31
+ export function isCrossDeviceError(error) {
32
+ return Boolean(error) && CROSS_DEVICE.has(String(error.code || ''))
33
+ }
34
+
35
+ function sleep(ms) {
36
+ return new Promise((resolve) => setTimeout(resolve, ms))
37
+ }
38
+
39
+ /**
40
+ * Rename with a bounded exponential backoff for lock errors. Errors that a
41
+ * retry cannot fix (`ENOENT`, `ENOSPC`, `EXDEV`, …) are rethrown at once.
42
+ *
43
+ * @returns the attempt number that succeeded.
44
+ */
45
+ export async function renameWithRetry(from, to, { attempts = 7, delayMs = 200, rename = renameSync } = {}) {
46
+ let lastError = null
47
+ for (let attempt = 1; attempt <= attempts; attempt += 1) {
48
+ try {
49
+ rename(from, to)
50
+ return attempt
51
+ } catch (error) {
52
+ lastError = error
53
+ if (!isLockedError(error) || attempt === attempts) throw error
54
+ await sleep(delayMs * 2 ** (attempt - 1))
55
+ }
56
+ }
57
+ throw lastError
58
+ }
59
+
60
+ /**
61
+ * Put `from` at the free path `to`, renaming it there or — when the tree stays
62
+ * locked / lives on another volume — copying it there. The source is left in
63
+ * place on both paths; callers prune their own staging directories.
64
+ *
65
+ * @returns `{ how: 'rename' | 'copy', attempts }`.
66
+ */
67
+ export async function moveIntoPlace(from, to, { attempts, delayMs, rename = renameSync, copy = cpSync, remove = rmSync } = {}) {
68
+ try {
69
+ const how = await renameWithRetry(from, to, { attempts, delayMs, rename })
70
+ return { how: 'rename', attempts: how }
71
+ } catch (error) {
72
+ if (!isLockedError(error) && !isCrossDeviceError(error)) throw error
73
+ remove(to, { recursive: true, force: true })
74
+ copy(from, to, { recursive: true })
75
+ return { how: 'copy', attempts }
76
+ }
77
+ }