dsh-session-superagent 0.9.6 → 0.9.7
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 +23 -0
- package/README.md +1 -1
- package/client.js +1 -1
- package/lib/index.js +19 -3
- package/lib/watch.js +20 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
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.7] - 2026-11-02 —— 隔离区回收节流:没超额就不必每次唤醒都跑 git
|
|
6
|
+
|
|
7
|
+
### 学到的(知识库第 56 条)
|
|
8
|
+
常规清理按**时间**跑,越界清理**立刻**跑 —— 两者混在一起,最坏就是每次业务请求都跑一遍 gc。
|
|
9
|
+
|
|
10
|
+
### 问题
|
|
11
|
+
`cleanupWorktrees()` 每次唤醒都跑(间隔可短到 30 秒),里面是 `readdir` +
|
|
12
|
+
每个过期副本 `worktree remove` + `prune` + `branch -D`。本机实测单次 git 调用 0.19s ——
|
|
13
|
+
而绝大多数时候根本没有过期副本。
|
|
14
|
+
|
|
15
|
+
### 改法(两条线,别只用一条)
|
|
16
|
+
| 条件 | 动作 |
|
|
17
|
+
|---|---|
|
|
18
|
+
| `count > keepCount` 超额 | **立刻跑**(不跑就会堆,违反数量线) |
|
|
19
|
+
| 距上次 < 10 分钟 | 跳过 |
|
|
20
|
+
| 其它 | 跑(兜底) |
|
|
21
|
+
|
|
22
|
+
节流状态记在 `entry.lastCleanupAt`,**只在实际执行时更新** ——
|
|
23
|
+
"打算跑"不能算数(同 0.9.5 那条教训)。
|
|
24
|
+
|
|
25
|
+
### 测试
|
|
26
|
+
- 新增 1 例(5 种情况)。合计 **150 例**。
|
|
27
|
+
|
|
5
28
|
## [0.9.6] - 2026-11-02 —— 会话忙时不再白开隔离区
|
|
6
29
|
|
|
7
30
|
### 学到的(知识库第 55 条)
|
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.9.
|
|
17
|
+
const CLIENT_VERSION = '0.9.7'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
package/lib/index.js
CHANGED
|
@@ -26,15 +26,18 @@ import { decodeBody } from './body.js'
|
|
|
26
26
|
import {
|
|
27
27
|
advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, formatWatchText,
|
|
28
28
|
TRIAGE_SIGNALS, accessNote, buildCommentBatchQuery, classifyGhError, commentSummaryLine, parseCommentBatch, pickSuggestion, repoStructureNote, countReasons, filterReason, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
|
|
29
|
+
shouldRunCleanup,
|
|
29
30
|
mergeFilters, mergePollResult, mergeWakeTexts, msUntilActiveWindow, nextWaketimeAt, pruneSeen, sessionWakesLastHour, pruneWakeTimes, pushHistory, recordReported, staleWorktrees, worktreePlan,
|
|
30
31
|
} from './watch.js'
|
|
31
32
|
|
|
32
33
|
export const name = 'dsh-session-superagent'
|
|
33
34
|
/** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
|
|
34
|
-
export const SERVER_VERSION = '0.9.
|
|
35
|
+
export const SERVER_VERSION = '0.9.7'
|
|
35
36
|
export const inject = ['tools', 'agents', 'webServer']
|
|
36
37
|
/** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
|
|
37
38
|
const DEFAULT_SESSION_WAKES = 12
|
|
39
|
+
/** 隔离区回收的最小间隔:没有超额时不必每次唤醒都跑 git。 */
|
|
40
|
+
const CLEANUP_INTERVAL_MS = 10 * 60 * 1000
|
|
38
41
|
|
|
39
42
|
/** 仅供测试:读写状态文件(生产代码不要用)。 */
|
|
40
43
|
export const __test = { readState, writeState, hardenSecretsFile, wakeMerged }
|
|
@@ -334,13 +337,23 @@ function bumpFailure(entry, baseMs) {
|
|
|
334
337
|
* 回收过期的隔离区:每次唤醒都会开一个新 worktree,不回收就会一直涨。
|
|
335
338
|
* 只删 .dsh-zhuli/ 下超过 keepDays 天没动过的目录,删不掉就留着(不阻断唤醒)。
|
|
336
339
|
*/
|
|
337
|
-
async function cleanupWorktrees(workdir, keepDays = 3, keepCount = 5) {
|
|
340
|
+
async function cleanupWorktrees(workdir, keepDays = 3, keepCount = 5, options = {}) {
|
|
338
341
|
if (!workdir) return 0
|
|
339
342
|
const BS = String.fromCharCode(92)
|
|
340
343
|
const base = String(workdir).split(BS).join('/').replace(/\/+$/, '')
|
|
341
344
|
const root = base + '/.dsh-zhuli'
|
|
342
345
|
let names = []
|
|
343
346
|
try { names = readdirSync(root) } catch { return 0 }
|
|
347
|
+
|
|
348
|
+
// 节流:没有超额就不必每次都跑 git(remove / prune / branch -D 都是进程级开销)
|
|
349
|
+
const decision = shouldRunCleanup({
|
|
350
|
+
count: names.length,
|
|
351
|
+
keepCount,
|
|
352
|
+
lastRunAt: Number(options.lastRunAt) || 0,
|
|
353
|
+
intervalMs: CLEANUP_INTERVAL_MS,
|
|
354
|
+
})
|
|
355
|
+
if (!decision.run) return 0
|
|
356
|
+
if (typeof options.onRun === 'function') options.onRun(decision.reason)
|
|
344
357
|
const entries = []
|
|
345
358
|
for (const name of names) {
|
|
346
359
|
try { entries.push({ name, mtimeMs: statSync(root + '/' + name).mtimeMs }) } catch {}
|
|
@@ -376,7 +389,10 @@ async function prepareIsolation(entry) {
|
|
|
376
389
|
const plan = worktreePlan({ workdir: entry.workdir, repo: entry.repo, sessionTag: entry.sessionId })
|
|
377
390
|
try {
|
|
378
391
|
// 先回收过期隔离区,再开新的
|
|
379
|
-
await cleanupWorktrees(entry.workdir, Number(entry.isolateKeepDays) || 3, Number(entry.maxIsolated) || 5
|
|
392
|
+
await cleanupWorktrees(entry.workdir, Number(entry.isolateKeepDays) || 3, Number(entry.maxIsolated) || 5, {
|
|
393
|
+
lastRunAt: Number(entry.lastCleanupAt) || 0,
|
|
394
|
+
onRun: () => { entry.lastCleanupAt = Date.now() },
|
|
395
|
+
})
|
|
380
396
|
const res = await run('git', ['-C', entry.workdir, 'worktree', 'add', plan.dir, '-b', plan.branch], { timeoutMs: 45000 })
|
|
381
397
|
if (res.code !== 0) {
|
|
382
398
|
return { error: redact([res.stderr, res.stdout].filter(Boolean).join(' ')).slice(0, 200) }
|
package/lib/watch.js
CHANGED
|
@@ -601,3 +601,23 @@ export function mergeWakeTexts(parts) {
|
|
|
601
601
|
const body = trimmed.map((text, i) => String.fromCharCode(10, 10) + '—— 第 ' + (i + 1) + ' 处 ——' + String.fromCharCode(10) + text).join('')
|
|
602
602
|
return head + body
|
|
603
603
|
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* 该不该现在回收隔离区。
|
|
607
|
+
*
|
|
608
|
+
* 现状:每次唤醒都跑一遍回收 —— 里面是 `git worktree remove` / `branch -D` / `prune`
|
|
609
|
+
* (本机实测 `worktree add` 0.19s,remove 同级;5 个过期副本就是 1 秒级),
|
|
610
|
+
* 而绝大多数时候根本没有过期副本。
|
|
611
|
+
*
|
|
612
|
+
* 节流规则:
|
|
613
|
+
* - 数量**超上限**时必须立刻回收(不能等,否则会堆);
|
|
614
|
+
* - 没超额时,距上次回收不足 `intervalMs`(默认 10 分钟)就跳过。
|
|
615
|
+
*/
|
|
616
|
+
export function shouldRunCleanup({ count = 0, keepCount = 5, lastRunAt = 0, now = Date.now(), intervalMs = 10 * 60 * 1000 } = {}) {
|
|
617
|
+
const total = Number(count) || 0
|
|
618
|
+
const cap = Math.max(1, Number(keepCount) || 5)
|
|
619
|
+
if (total > cap) return { run: true, reason: 'over-cap' }
|
|
620
|
+
const last = Number(lastRunAt) || 0
|
|
621
|
+
if (last > 0 && now - last < Number(intervalMs)) return { run: false, reason: 'throttled' }
|
|
622
|
+
return { run: true, reason: 'interval' }
|
|
623
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.7",
|
|
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",
|