dsh-session-superagent 0.8.99 → 0.9.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/CHANGELOG.md +22 -0
- package/README.md +1 -1
- package/client.js +4 -1
- package/lib/index.js +8 -4
- package/lib/watch.js +24 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
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.9.0] - 2026-11-02 —— 隔离区加"数量线":最坏 432 个副本 → 最多 5 个
|
|
6
|
+
|
|
7
|
+
### 学到的(知识库第 49 条)
|
|
8
|
+
`git worktree prune` 只清"目录已不在的管理记录",**不管副本数量**。
|
|
9
|
+
清理策略要 **时间线 + 数量线** 双保险,只靠一条会被极端情况绕过。
|
|
10
|
+
|
|
11
|
+
### 实测与推演
|
|
12
|
+
| 场景 | 数字 |
|
|
13
|
+
|---|---|
|
|
14
|
+
| 合成仓库(3 MB 文件) | 每个 worktree **2.9 MB**(≈ 工作树大小) |
|
|
15
|
+
| 6 次/小时 × 保留 3 天 | 最坏 **432 个副本** |
|
|
16
|
+
| 按 10 MB/副本估 | ≈ **4 GB** |
|
|
17
|
+
|
|
18
|
+
### 改了什么
|
|
19
|
+
`staleWorktrees` 加数量线:按 mtime 倒序只留最近 `keepCount`(默认 5)个,其余回收;
|
|
20
|
+
两条线结果去重,**最近 N 个无论多老都留着**(正在用的那个不能删)。
|
|
21
|
+
|
|
22
|
+
配置 `entry.maxIsolated`(1–50,默认 5),面板「隔离」区可改,`/state` 回传。
|
|
23
|
+
|
|
24
|
+
### 测试
|
|
25
|
+
- 新增 1 例(4 种情况)。合计 **143 例**。
|
|
26
|
+
|
|
5
27
|
## [0.8.99] - 2026-11-02 —— 被每小时上限挡住时,告诉你还要等多久
|
|
6
28
|
|
|
7
29
|
### 先模拟,再看要不要改(知识库第 48 条)
|
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)
|
|
6
|
-
[](https://github.com/MYCF711/dsh-session-superagent/releases)
|
|
7
7
|
[](https://www.npmjs.com/package/dsh-session-superagent)
|
|
8
8
|
[](https://github.com/topics/dsh-plugin)
|
|
9
9
|
|
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.
|
|
17
|
+
const CLIENT_VERSION = '0.9.0'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
|
@@ -919,6 +919,7 @@ window.__ModuleLoader__.load({
|
|
|
919
919
|
workdir: draft.workdir || '',
|
|
920
920
|
observe: !!draft.observe,
|
|
921
921
|
isolateKeepDays: Number(draft.isolateKeepDays) || undefined,
|
|
922
|
+
maxIsolated: Number(draft.maxIsolated) || undefined,
|
|
922
923
|
priority: {
|
|
923
924
|
reopened: draft.priorityReopened !== false,
|
|
924
925
|
comments: draft.priorityComments !== false,
|
|
@@ -1020,6 +1021,7 @@ window.__ModuleLoader__.load({
|
|
|
1020
1021
|
batchLimit: watcher.batchLimit ? String(watcher.batchLimit) : '',
|
|
1021
1022
|
maxWakesPerHour: watcher.maxWakesPerHour ? String(watcher.maxWakesPerHour) : '',
|
|
1022
1023
|
isolateKeepDays: watcher.isolateKeepDays ? String(watcher.isolateKeepDays) : '',
|
|
1024
|
+
maxIsolated: watcher.maxIsolated ? String(watcher.maxIsolated) : '',
|
|
1023
1025
|
priorityReopened: (watcher.priority && watcher.priority.reopened) !== false,
|
|
1024
1026
|
priorityComments: (watcher.priority && watcher.priority.comments) !== false,
|
|
1025
1027
|
priorityLabels: (watcher.priority && watcher.priority.labels) !== false,
|
|
@@ -1082,6 +1084,7 @@ window.__ModuleLoader__.load({
|
|
|
1082
1084
|
h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: !!draft.isolated, onChange: (v) => setDraft({ ...draft, isolated: v }), label: '隔离执行' }), '隔离执行(每次唤醒开一次性 worktree)'),
|
|
1083
1085
|
draft.isolated ? field('隔离工作目录', h(Input, { value: draft.workdir || '', placeholder: '绝对路径,留空 = 当前工作目录', onChange: (e) => setDraft({ ...draft, workdir: e.target.value }) })) : null,
|
|
1084
1086
|
draft.isolated ? field('隔离区保留天数', h(Input, { value: draft.isolateKeepDays || '', placeholder: '3(1-30)', onChange: (e) => setDraft({ ...draft, isolateKeepDays: e.target.value }) }), '每次唤醒前回收这个天数之前的一次性工作区;留空用默认 3 天') : null,
|
|
1087
|
+
draft.isolated ? field('最多保留几个隔离区', h(Input, { value: draft.maxIsolated || '', placeholder: '5(1-50)', onChange: (e) => setDraft({ ...draft, maxIsolated: e.target.value }) }), '天数之外的第二道线:超出就回收最旧的(不影响正在用的那个)') : null,
|
|
1085
1088
|
h('div', { className: 'dt-actions' },
|
|
1086
1089
|
h(Btn, { size: 'sm', variant: 'primary', onClick: () => saveEdit(watcher) }, '保存'),
|
|
1087
1090
|
h(Btn, { size: 'sm', onClick: () => setEditing(null) }, '放弃')))
|
package/lib/index.js
CHANGED
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
|
|
32
32
|
export const name = 'dsh-session-superagent'
|
|
33
33
|
/** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
|
|
34
|
-
export const SERVER_VERSION = '0.
|
|
34
|
+
export const SERVER_VERSION = '0.9.0'
|
|
35
35
|
export const inject = ['tools', 'agents', 'webServer']
|
|
36
36
|
|
|
37
37
|
/** 仅供测试:读写状态文件(生产代码不要用)。 */
|
|
@@ -332,7 +332,7 @@ function bumpFailure(entry, baseMs) {
|
|
|
332
332
|
* 回收过期的隔离区:每次唤醒都会开一个新 worktree,不回收就会一直涨。
|
|
333
333
|
* 只删 .dsh-zhuli/ 下超过 keepDays 天没动过的目录,删不掉就留着(不阻断唤醒)。
|
|
334
334
|
*/
|
|
335
|
-
async function cleanupWorktrees(workdir, keepDays = 3) {
|
|
335
|
+
async function cleanupWorktrees(workdir, keepDays = 3, keepCount = 5) {
|
|
336
336
|
if (!workdir) return 0
|
|
337
337
|
const BS = String.fromCharCode(92)
|
|
338
338
|
const base = String(workdir).split(BS).join('/').replace(/\/+$/, '')
|
|
@@ -343,7 +343,8 @@ async function cleanupWorktrees(workdir, keepDays = 3) {
|
|
|
343
343
|
for (const name of names) {
|
|
344
344
|
try { entries.push({ name, mtimeMs: statSync(root + '/' + name).mtimeMs }) } catch {}
|
|
345
345
|
}
|
|
346
|
-
|
|
346
|
+
// 数量线:最近 N 个留着(默认 5),其余回收 —— 年龄线管不住"堆"
|
|
347
|
+
const stale = staleWorktrees(entries, { keepMs: keepDays * 24 * 3600 * 1000, keepCount: Number(keepCount) || 5 })
|
|
347
348
|
let removed = 0
|
|
348
349
|
for (const item of stale) {
|
|
349
350
|
const target = root + '/' + item.name
|
|
@@ -373,7 +374,7 @@ async function prepareIsolation(entry) {
|
|
|
373
374
|
const plan = worktreePlan({ workdir: entry.workdir, repo: entry.repo, sessionTag: entry.sessionId })
|
|
374
375
|
try {
|
|
375
376
|
// 先回收过期隔离区,再开新的
|
|
376
|
-
await cleanupWorktrees(entry.workdir, Number(entry.isolateKeepDays) || 3)
|
|
377
|
+
await cleanupWorktrees(entry.workdir, Number(entry.isolateKeepDays) || 3, Number(entry.maxIsolated) || 5)
|
|
377
378
|
const res = await run('git', ['-C', entry.workdir, 'worktree', 'add', plan.dir, '-b', plan.branch], { timeoutMs: 45000 })
|
|
378
379
|
if (res.code !== 0) {
|
|
379
380
|
return { error: redact([res.stderr, res.stdout].filter(Boolean).join(' ')).slice(0, 200) }
|
|
@@ -1106,6 +1107,7 @@ export function apply(ctx) {
|
|
|
1106
1107
|
lastWorktree: w.lastWorktree ?? null,
|
|
1107
1108
|
activeHours: w.activeHours ?? null,
|
|
1108
1109
|
isolateKeepDays: w.isolateKeepDays ?? 3,
|
|
1110
|
+
maxIsolated: w.maxIsolated ?? 5,
|
|
1109
1111
|
history: (w.history ?? []).slice(-5),
|
|
1110
1112
|
note: w.goal ?? '',
|
|
1111
1113
|
title: sessionTitle(w.sessionId),
|
|
@@ -1271,6 +1273,8 @@ export function apply(ctx) {
|
|
|
1271
1273
|
entry.observe = body.observe === undefined ? entry.observe === true : body.observe === true
|
|
1272
1274
|
entry.isolated = body.isolated === undefined ? entry.isolated === true : body.isolated === true
|
|
1273
1275
|
if (body.isolateKeepDays != null) entry.isolateKeepDays = Math.max(1, Math.min(30, Number(body.isolateKeepDays) || 3))
|
|
1276
|
+
// 同时最多留几个隔离区(越界回收最旧的)—— 1~50
|
|
1277
|
+
if (body.maxIsolated != null) entry.maxIsolated = Math.max(1, Math.min(50, Number(body.maxIsolated) || 5))
|
|
1274
1278
|
if (typeof body.activeHours === 'string') entry.activeHours = body.activeHours.trim().slice(0, 20) || null
|
|
1275
1279
|
if (typeof body.workdir === 'string' && body.workdir.trim()) {
|
|
1276
1280
|
const workdir = body.workdir.trim()
|
package/lib/watch.js
CHANGED
|
@@ -377,13 +377,31 @@ export function worktreePlan({ workdir, repo, sessionTag, stamp = Date.now() } =
|
|
|
377
377
|
* 隔离区(worktree)会随每次唤醒累积。返回超过 keepMs 没动过的那些,交给调用方回收。
|
|
378
378
|
* 纯函数,单测覆盖。
|
|
379
379
|
*/
|
|
380
|
+
/**
|
|
381
|
+
* 该回收的隔离区:**按年龄** + **按数量** 两条线(原来只有年龄)。
|
|
382
|
+
*
|
|
383
|
+
* 为什么补数量:年龄线管不住"堆" —— 上限 6 次/小时 × 保留 3 天 = 最坏 432 个副本。
|
|
384
|
+
* 实测一个 worktree ≈ 该仓库工作树的大小(我们的仓库 1.3 MB,一个 3 MB 文件的测试仓库开出 2.9 MB),
|
|
385
|
+
* 按 10 MB 估就是 4 GB 级占用。
|
|
386
|
+
*
|
|
387
|
+
* `keepCount`:最近 N 个无论多老都留着(正在用的那个不能被删)。
|
|
388
|
+
*/
|
|
380
389
|
export function staleWorktrees(entries, options = {}) {
|
|
381
|
-
const { now = Date.now(), keepMs = 3 * 24 * 3600 * 1000 } = options
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
390
|
+
const { now = Date.now(), keepMs = 3 * 24 * 3600 * 1000, keepCount = 5 } = options
|
|
391
|
+
const list = (entries ?? []).filter((entry) => entry && entry.name && Number.isFinite(Number(entry.mtimeMs)))
|
|
392
|
+
const byAge = list.filter((entry) => now - Number(entry.mtimeMs) > keepMs)
|
|
393
|
+
const cap = Math.max(0, Number(keepCount) || 0)
|
|
394
|
+
const newest = list.slice().sort((a, b) => Number(b.mtimeMs) - Number(a.mtimeMs)).slice(0, cap)
|
|
395
|
+
const keep = new Set(newest.map((entry) => entry.name))
|
|
396
|
+
const byCount = list.filter((entry) => !keep.has(entry.name))
|
|
397
|
+
const out = []
|
|
398
|
+
const seen = new Set()
|
|
399
|
+
for (const entry of [...byAge, ...byCount]) {
|
|
400
|
+
if (seen.has(entry.name)) continue
|
|
401
|
+
seen.add(entry.name)
|
|
402
|
+
out.push(entry)
|
|
403
|
+
}
|
|
404
|
+
return out
|
|
387
405
|
}
|
|
388
406
|
|
|
389
407
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
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",
|