dsh-session-superagent 0.8.58 → 0.8.60

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,48 @@
2
2
 
3
3
  格式参照 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
4
4
 
5
+ ## [0.8.60] - 2026-11-02 —— 保留天数可配;顺手修掉一个会写坏配置的真 bug
6
+
7
+ ### 学到的(知识库第 9 条)
8
+ GitHub Actions 的产物保留天数可按仓库配(默认 90 天,1–90 可选)——
9
+ 会长期增长的资源(日志/产物/缓存)应当**可调 + 有默认值 + 有上下限**。
10
+ <https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/removing-workflow-artifacts>
11
+
12
+ 我们的 `isolateKeepDays` 服务端早就支持(默认 3 天),**面板一直没有入口**。
13
+
14
+ ### 改了什么
15
+ 1. 编辑表单加「隔离区保留天数」(留空用默认 3),保存走 `/watch`;
16
+ 2. **修掉一个真 bug**:打开编辑态时只回填了 5 个字段(间隔/标签/时段/目标/已指派),
17
+ `observe / isolated / workdir / batchLimit / maxWakesPerHour` 都没填 ——
18
+ 打开一条"隔离执行"的守、不作修改直接「保存」,会把 `isolated` 写回 `false`。
19
+ 已补齐全部 10 个字段。
20
+
21
+ ### 为什么这条只能用源码级守门
22
+ 假 DOM 的 `setState` 是空实现,点标题触发 `setDraft` 后拿不到新渲染,
23
+ 所以行为测不出来。改成**静态检查**:编辑态初始化块必须包含全部 10 个字段名。
24
+
25
+ ### 测试
26
+ - 合计 **114 例**(新增源码级守门)。
27
+
28
+ ## [0.8.59] - 2026-11-02 —— 孤儿 worktree 删了目录还得 prune;占用看得见
29
+
30
+ ### 学到的(知识库第 8 条)
31
+ `git worktree remove` 会同时删目录和 `.git/worktrees/<id>/` 的管理记录;但**目录是被外部删掉**时,
32
+ 记录会留下 —— `git worktree list` 就一直显示一个不存在的路径。
33
+
34
+ 我们的清理有两条路径:`worktree remove --force` 成功走第一条(没问题),
35
+ 失败时走 `rmSync` 兜底删目录 —— **没人清记录**,长期运行会攒 ghost worktree。
36
+
37
+ ### 改了什么
38
+ 1. 孤儿分支删完目录后补一条 `git worktree prune`;
39
+ 2. `/state` 新增 `isolation`:每个 worktree 根下的**个数与总字节**,
40
+ 面板「设置 → 来源」显示「隔离占用 3 个 · 3.2 MB(合计 9.8 MB)」——客户能看见磁盘在涨。
41
+
42
+ ### 测试
43
+ - 新增 `test/worktree-prune.test.mjs`:用**真 git 仓库**复现现象(建 worktree → 手删目录 →
44
+ `list` 仍显示 → `prune` 后干净),不靠 mock。
45
+ - 合计 **113 例**。
46
+
5
47
  ## [0.8.58] - 2026-11-02 —— 完成标准从"一大句"改成可逐条核对的三条
6
48
 
7
49
  ### 学到的(知识库第 7 条)
package/MAINTENANCE.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## 二、当前状态(2026-11-01)
11
11
 
12
- - [x] 七个工具可用(github / repo_here / watch_start / watch_status / watch_stop / watch_ack / watch_doctor),`node --test` 112/112 通过
12
+ - [x] 七个工具可用(github / repo_here / watch_start / watch_status / watch_stop / watch_ack / watch_doctor),`node --test` 114/114 通过
13
13
  - [x] 自回声抑制(逐条水位)
14
14
  - [x] 仅空闲注入(避免草稿回放)
15
15
  - [x] 唤醒失败不推进水位
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <img src="assets/icon-180.png" width="88" height="88" alt="">
4
4
 
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
- [![Version](https://img.shields.io/badge/version-0.8.58-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.8.60-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
7
7
  [![npm](https://img.shields.io/npm/v/dsh-session-superagent.svg)](https://www.npmjs.com/package/dsh-session-superagent)
8
8
  [![dsh](https://img.shields.io/badge/DeepSeek%20Harness-plugin-orange.svg)](https://github.com/topics/dsh-plugin)
9
9
 
@@ -99,7 +99,7 @@ dsh plugin install /path/to/dsh-session-superagent
99
99
  ## 开发
100
100
 
101
101
  ```sh
102
- node --test # 112 项单测
102
+ node --test # 114 项单测
103
103
  ```
104
104
 
105
105
  版本与发布流程见 [UPDATING.md](UPDATING.md),交付门见 [CHECKLIST.md](CHECKLIST.md),接手台账见 [MAINTENANCE.md](MAINTENANCE.md)。
package/client.js CHANGED
@@ -14,7 +14,7 @@ window.__ModuleLoader__.load({
14
14
  const { useCallback, useEffect, useRef, useState } = React
15
15
 
16
16
  // 客户端版本探针:每次模块加载写一次,用来确认浏览器里跑的是哪一版
17
- const CLIENT_VERSION = '0.8.58'
17
+ const CLIENT_VERSION = '0.8.60'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
@@ -902,6 +902,7 @@ window.__ModuleLoader__.load({
902
902
  isolated: !!draft.isolated,
903
903
  workdir: draft.workdir || '',
904
904
  observe: !!draft.observe,
905
+ isolateKeepDays: Number(draft.isolateKeepDays) || undefined,
905
906
  batchLimit: Number(draft.batchLimit) || undefined,
906
907
  maxWakesPerHour: Number(draft.maxWakesPerHour) || undefined,
907
908
  }),
@@ -982,8 +983,15 @@ window.__ModuleLoader__.load({
982
983
  intervalSec: String(watcher.intervalSec ?? 60),
983
984
  labels: (watcher.filters && watcher.filters.labels ? watcher.filters.labels : []).join(','),
984
985
  activeHours: watcher.activeHours || '',
985
- goal: watcher.note || '',
986
+ goal: watcher.note || watcher.goal || '',
986
987
  onlyAssigned: !!(watcher.filters && watcher.filters.onlyAssigned),
988
+ // 下面这些以前没填 —— 打开一条隔离执行的守再直接保存,会把 isolated 写回 false
989
+ observe: !!watcher.observe,
990
+ isolated: !!watcher.isolated,
991
+ workdir: watcher.workdir || '',
992
+ batchLimit: watcher.batchLimit ? String(watcher.batchLimit) : '',
993
+ maxWakesPerHour: watcher.maxWakesPerHour ? String(watcher.maxWakesPerHour) : '',
994
+ isolateKeepDays: watcher.isolateKeepDays ? String(watcher.isolateKeepDays) : '',
987
995
  })
988
996
  },
989
997
  }, watcher.repo)),
@@ -1029,6 +1037,7 @@ window.__ModuleLoader__.load({
1029
1037
  h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: !!draft.observe, onChange: (v) => setDraft({ ...draft, observe: v }), label: '仅观察' }), '仅观察(只记录不唤醒)'),
1030
1038
  h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: !!draft.isolated, onChange: (v) => setDraft({ ...draft, isolated: v }), label: '隔离执行' }), '隔离执行(每次唤醒开一次性 worktree)'),
1031
1039
  draft.isolated ? field('隔离工作目录', h(Input, { value: draft.workdir || '', placeholder: '绝对路径,留空 = 当前工作目录', onChange: (e) => setDraft({ ...draft, workdir: e.target.value }) })) : null,
1040
+ draft.isolated ? field('隔离区保留天数', h(Input, { value: draft.isolateKeepDays || '', placeholder: '3(1-30)', onChange: (e) => setDraft({ ...draft, isolateKeepDays: e.target.value }) }), '每次唤醒前回收这个天数之前的一次性工作区;留空用默认 3 天') : null,
1032
1041
  h('div', { className: 'dt-actions' },
1033
1042
  h(Btn, { size: 'sm', variant: 'primary', onClick: () => saveEdit(watcher) }, '保存'),
1034
1043
  h(Btn, { size: 'sm', onClick: () => setEditing(null) }, '放弃')))
@@ -1164,6 +1173,10 @@ window.__ModuleLoader__.load({
1164
1173
  ['仓库', watchers.length === 0 ? '未绑定' : watchers.map((w) => w.repo).join(', ')],
1165
1174
  ['gh CLI', !body.gh ? '检测中…' : body.gh.ok ? '可用 · ' + (body.gh.version || '') : '不可用 · ' + (body.gh.error || '')],
1166
1175
  ['凭证', credentials.token === 'none' ? '回退到 gh CLI 登录态' : '使用面板配置的 token'],
1176
+ ['隔离占用', !body.isolation || (body.isolation.roots || []).length === 0
1177
+ ? '没有开隔离执行'
1178
+ : (body.isolation.roots || []).map((r) => r.count + ' 个 · ' + bytesText(r.bytes)).join(';')
1179
+ + '(合计 ' + bytesText(body.isolation.totalBytes) + ')'],
1167
1180
  ] })),
1168
1181
  h(Section, { key: 'creds', title: '凭证' },
1169
1182
  h(KeyValues, { rows: [['GitHub token', credentials.token === 'none' ? '未配置(回退到已登录的 gh CLI)' : '已配置'], ['SSH 私钥', credentials.sshKeyPath === 'none' ? '未配置(当前版本不使用)' : '已配置']] }),
@@ -1253,6 +1266,15 @@ window.__ModuleLoader__.load({
1253
1266
  return () => { alive = false }
1254
1267
  }, [])
1255
1268
 
1269
+ /** 人话字节数:客户看的是"3.2 MB",不是 3355443。 */
1270
+ function bytesText(n) {
1271
+ const value = Number(n) || 0
1272
+ if (value < 1024) return value + ' B'
1273
+ if (value < 1024 * 1024) return (value / 1024).toFixed(1) + ' KB'
1274
+ if (value < 1024 * 1024 * 1024) return (value / 1024 / 1024).toFixed(1) + ' MB'
1275
+ return (value / 1024 / 1024 / 1024).toFixed(2) + ' GB'
1276
+ }
1277
+
1256
1278
  // 官方 settings-kit.tsx 的 Field:label + hint(InfoTip) + 控件 + note(small)。
1257
1279
  // 我们之前只有 label,说明只能塞进 placeholder —— 用户看不到「这个字段到底什么意思」。
1258
1280
  function field(label, control, hint, note) {
package/lib/index.js CHANGED
@@ -30,7 +30,7 @@ import {
30
30
 
31
31
  export const name = 'dsh-session-superagent'
32
32
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
33
- export const SERVER_VERSION = '0.8.58'
33
+ export const SERVER_VERSION = '0.8.60'
34
34
  export const inject = ['tools', 'agents', 'webServer']
35
35
 
36
36
  /** 仅供测试:读写状态文件(生产代码不要用)。 */
@@ -308,6 +308,10 @@ async function cleanupWorktrees(workdir, keepDays = 3) {
308
308
  if (res.code !== 0) {
309
309
  // 已经不是工作树(孤儿目录):直接删目录,别让它永远留着
310
310
  try { rmSync(target, { recursive: true, force: true }) } catch {}
311
+ // 关键:目录删了,但 git 的 `worktrees/<id>/` 管理文件还在 —— 不 prune 的话
312
+ // `git worktree list` 会一直显示一个已经不存在的目录。
313
+ // 依据:git-worktree 文档里 `prune` 的职责正是「清掉那些目录已经不在了的管理记录」。
314
+ await run('git', ['-C', workdir, 'worktree', 'prune'], { timeoutMs: 20000 })
311
315
  } else {
312
316
  removed += 1
313
317
  }
@@ -436,6 +440,49 @@ function wake(ctx, sessionId, text) {
436
440
  }
437
441
  }
438
442
 
443
+
444
+ /** 隔离区占用:客户长期运行会攒下一堆一次性 worktree,面板上得看得见。 */
445
+ function isolationReport(entries) {
446
+ const roots = new Map()
447
+ for (const entry of entries) {
448
+ if (!entry || entry.isolated !== true || !entry.workdir) continue
449
+ roots.set(entry.workdir, true)
450
+ }
451
+ let totalBytes = 0
452
+ const list = []
453
+ for (const workdir of roots.keys()) {
454
+ const base = String(workdir).replace(/[\/]+$/, '') + '/.dsh-zhuli'
455
+ let count = 0
456
+ let bytes = 0
457
+ try {
458
+ for (const name of readdirSync(base)) {
459
+ const full = base + '/' + name
460
+ count += 1
461
+ bytes += dirSize(full, 2)
462
+ }
463
+ } catch { /* 目录还没有就是 0 */ }
464
+ totalBytes += bytes
465
+ list.push({ workdir, count, bytes })
466
+ }
467
+ return { roots: list, totalBytes }
468
+ }
469
+
470
+ /** 递归算目录大小(深度有上限,够用来判断"是不是涨到几百 MB 了")。 */
471
+ function dirSize(path, depth) {
472
+ if (depth <= 0) return 0
473
+ let total = 0
474
+ let items = []
475
+ try { items = readdirSync(path, { withFileTypes: true }) } catch { return 0 }
476
+ for (const item of items) {
477
+ const full = path + '/' + item.name
478
+ if (item.isDirectory()) total += dirSize(full, depth - 1)
479
+ else {
480
+ try { total += statSync(full).size } catch {}
481
+ }
482
+ }
483
+ return total
484
+ }
485
+
439
486
  async function pollOnce(ctx, entry, baseMs) {
440
487
  // 条件请求:带上上次的 ETag,没变化时 GitHub 回 304,且**不计入**速率限制
441
488
  const args = ['api', '--include', `repos/${entry.repo}/issues?state=all&sort=updated&direction=desc&per_page=20`]
@@ -791,6 +838,7 @@ export function apply(ctx) {
791
838
  updatedAt: new Date().toISOString(),
792
839
  credentials: secretsSummary(),
793
840
  sessionGoal: goalView(ctx, focusSession),
841
+ isolation: isolationReport(Object.values(state.watchers || {})),
794
842
  sessionTitle: sessionTitle(focusSession),
795
843
  watchers: watchers.map((w) => ({ ...w, goal: goalView(ctx, w.sessionId) })),
796
844
  }))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.8.58",
3
+ "version": "0.8.60",
4
4
  "description": "Session-level superagent for DeepSeek Harness: watch a GitHub repository and wake a session when something needs doing. Credentials never reach the model.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",