dsh-session-superagent 0.9.2 → 0.9.3
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 +29 -0
- package/README.md +1 -1
- package/client.js +1 -1
- package/lib/index.js +33 -4
- package/lib/watch.js +18 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,35 @@
|
|
|
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.3] - 2026-11-02 —— 同一会话的多条唤醒合并成一条
|
|
6
|
+
|
|
7
|
+
### 学到的(知识库第 52 条)
|
|
8
|
+
Google SRE《Handling Overload》:过载时要**减少工作**(coalesce/shed),不是更快失败。
|
|
9
|
+
<https://sre.google/sre-book/handling-overload/>
|
|
10
|
+
|
|
11
|
+
### 实测出来的形态
|
|
12
|
+
同会话 3 个守、间隔 60 秒:
|
|
13
|
+
```
|
|
14
|
+
首轮相位: 1184 / 2145 / 3106 ms
|
|
15
|
+
相邻两次唤醒间隔: 最小 0.96s / 中位 0.96s / 最大 0.96s
|
|
16
|
+
```
|
|
17
|
+
抖动是**一次性**的 —— 之后每个守按自己的 every 推进,相对相位几乎不变,
|
|
18
|
+
所以**每一轮**都会在约 1 秒内连着收到 3 条注入(5 个守就是 5 条)。
|
|
19
|
+
|
|
20
|
+
### 为什么不用"最小间隔"
|
|
21
|
+
先到的守会永远赢,后面的饿死 —— 和"固定窗口让突发者占名额"是同一类错。
|
|
22
|
+
|
|
23
|
+
### 改法:合并
|
|
24
|
+
同会话 **3 秒窗口**内的多条唤醒攒成一条:
|
|
25
|
+
```
|
|
26
|
+
【主理鱼】这一小段时间内有 3 处变化,合并成一条:
|
|
27
|
+
—— 第 1 处 —— … —— 第 2 处 —— …
|
|
28
|
+
```
|
|
29
|
+
单条不加包装;`decideWake`(是否 idle)在真正发送时再判,比原来更新鲜。
|
|
30
|
+
|
|
31
|
+
### 测试
|
|
32
|
+
- 新增 1 例。合计 **145 例**。
|
|
33
|
+
|
|
5
34
|
## [0.9.2] - 2026-11-02 —— 会话级唤醒上限:单守上限挡不住"多守叠加"
|
|
6
35
|
|
|
7
36
|
### 学到的(知识库第 51 条)
|
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.3'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
package/lib/index.js
CHANGED
|
@@ -26,12 +26,12 @@ 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
|
-
mergeFilters, mergePollResult, msUntilActiveWindow, nextWaketimeAt, pruneSeen, sessionWakesLastHour, pruneWakeTimes, pushHistory, recordReported, staleWorktrees, worktreePlan,
|
|
29
|
+
mergeFilters, mergePollResult, mergeWakeTexts, msUntilActiveWindow, nextWaketimeAt, pruneSeen, sessionWakesLastHour, pruneWakeTimes, pushHistory, recordReported, staleWorktrees, worktreePlan,
|
|
30
30
|
} from './watch.js'
|
|
31
31
|
|
|
32
32
|
export const name = 'dsh-session-superagent'
|
|
33
33
|
/** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
|
|
34
|
-
export const SERVER_VERSION = '0.9.
|
|
34
|
+
export const SERVER_VERSION = '0.9.3'
|
|
35
35
|
export const inject = ['tools', 'agents', 'webServer']
|
|
36
36
|
/** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
|
|
37
37
|
const DEFAULT_SESSION_WAKES = 12
|
|
@@ -452,6 +452,34 @@ function defineTool(options) {
|
|
|
452
452
|
* `Agent.followup()` queues an ordinary turn AND wakes the driver; the durable
|
|
453
453
|
* inbox alone only parks the message (the client shows it as a pending draft).
|
|
454
454
|
*/
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* 同会话几秒内的多条唤醒合并成一条再注入。
|
|
458
|
+
*
|
|
459
|
+
* 实测:同会话 3 个守、间隔 60 秒时,首轮抖动只把相位拉开 ≤5 秒 —— 之后每一轮都一样,
|
|
460
|
+
* 于是三次唤醒落在约 1 秒内,会话连着收到 3 条注入(5 个守就是 5 条)。
|
|
461
|
+
* 不做硬间隔,是因为"先到的守永远赢"会把后面的饿死;**合并**既不丢也不饿死。
|
|
462
|
+
*/
|
|
463
|
+
const WAKE_WINDOW_MS = 3000
|
|
464
|
+
const wakeBuffers = new Map()
|
|
465
|
+
|
|
466
|
+
function wakeMerged(ctx, sessionId, text) {
|
|
467
|
+
const now = Date.now()
|
|
468
|
+
const buf = wakeBuffers.get(sessionId) || { parts: [], timer: null, openedAt: now }
|
|
469
|
+
buf.parts.push(text)
|
|
470
|
+
if (buf.timer) return { ok: true, merged: true, pending: buf.parts.length }
|
|
471
|
+
buf.timer = setTimeout(() => {
|
|
472
|
+
wakeBuffers.delete(sessionId)
|
|
473
|
+
try {
|
|
474
|
+
const merged = mergeWakeTexts(buf.parts)
|
|
475
|
+
if (merged) wake(ctx, sessionId, merged)
|
|
476
|
+
} catch { /* 合并失败也不能让唤醒消失:下面这次单独发 */ }
|
|
477
|
+
}, WAKE_WINDOW_MS)
|
|
478
|
+
if (buf.timer && typeof buf.timer.unref === 'function') buf.timer.unref()
|
|
479
|
+
wakeBuffers.set(sessionId, buf)
|
|
480
|
+
return { ok: true, merged: true, pending: buf.parts.length }
|
|
481
|
+
}
|
|
482
|
+
|
|
455
483
|
function wake(ctx, sessionId, text) {
|
|
456
484
|
const agents = agentsService(ctx)
|
|
457
485
|
const agent = agents && typeof agents.get === 'function' ? agents.get(sessionId) : undefined
|
|
@@ -888,7 +916,7 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
888
916
|
if (isolation && isolation.dir) entry.lastWorktree = isolation.dir
|
|
889
917
|
// 批次前几条补「最后是谁在说话」(最多 3 条,失败静默)
|
|
890
918
|
await fetchLastComments(entry.repo, listed)
|
|
891
|
-
const
|
|
919
|
+
const wakeText = formatWatchText(entry.repo, listed, {
|
|
892
920
|
more: rest.length,
|
|
893
921
|
restNumbers: rest.map((item) => item.number),
|
|
894
922
|
isolation,
|
|
@@ -906,7 +934,8 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
906
934
|
changedTotal: fresh.length,
|
|
907
935
|
batchLimit: listed.length,
|
|
908
936
|
skippedReasons: entry.filterCounts || {},
|
|
909
|
-
})
|
|
937
|
+
})
|
|
938
|
+
const result = wakeMerged(ctx, entry.sessionId, wakeText)
|
|
910
939
|
entry.lastWake = result.ok ? new Date().toISOString() : `failed: ${result.reason}`
|
|
911
940
|
entry.lastWakeCount = fresh.length
|
|
912
941
|
entry.lastBatch = listed.map((item) => item.number)
|
package/lib/watch.js
CHANGED
|
@@ -560,3 +560,21 @@ export function sessionWakesLastHour(entries, sessionId, now = Date.now()) {
|
|
|
560
560
|
}
|
|
561
561
|
return total
|
|
562
562
|
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* 把同一会话在几秒内产生的多条唤醒合并成一条。
|
|
566
|
+
*
|
|
567
|
+
* 实测(本轮):同会话 3 个守、间隔都是 60 秒时,首轮抖动只把相位拉开 ≤5 秒,
|
|
568
|
+
* **之后每一轮都一样** —— 三次唤醒落在 ~1 秒内,会话会连着收到 3 条注入。
|
|
569
|
+
* 5 个守就是 5 条。这正是"上下文被瞬间打爆"的真实形态。
|
|
570
|
+
*
|
|
571
|
+
* 合并而不是"设个间隔挡掉":硬间隔会让先到的守永远赢,后面的守被饿死。
|
|
572
|
+
*/
|
|
573
|
+
export function mergeWakeTexts(parts) {
|
|
574
|
+
const list = (Array.isArray(parts) ? parts : []).filter((t) => typeof t === 'string' && t.trim())
|
|
575
|
+
if (list.length === 0) return ''
|
|
576
|
+
if (list.length === 1) return list[0]
|
|
577
|
+
const head = '【主理鱼】这一小段时间内有 ' + list.length + ' 处变化,合并成一条:'
|
|
578
|
+
const body = list.map((text, i) => String.fromCharCode(10, 10) + '—— 第 ' + (i + 1) + ' 处 ——' + String.fromCharCode(10) + text).join('')
|
|
579
|
+
return head + body
|
|
580
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
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",
|