dsh-session-superagent 0.9.2 → 0.9.4
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 +52 -0
- package/README.md +1 -1
- package/client.js +1 -1
- package/lib/index.js +33 -4
- package/lib/watch.js +41 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,58 @@
|
|
|
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.4] - 2026-11-02 —— 合并之后去重:三条唤醒从 1065 字砍到 575 字
|
|
6
|
+
|
|
7
|
+
### 学到的(知识库第 53 条)
|
|
8
|
+
合并只是第一步,**去重是第二步**:合并减少了"消息条数",但重复的样板文字仍占上下文。
|
|
9
|
+
(同源:SRE《Handling Overload》的 coalesce 思路。)
|
|
10
|
+
|
|
11
|
+
### 实测
|
|
12
|
+
三条唤醒直接拼接:
|
|
13
|
+
```
|
|
14
|
+
长度 1065 字符;【完成标准】3 次;goal 行 3 次
|
|
15
|
+
```
|
|
16
|
+
样板段落每条都一样 —— 合并后纯属噪音,占了近一半长度。
|
|
17
|
+
|
|
18
|
+
### 改法
|
|
19
|
+
`mergeWakeTexts` 拼接前先过一遍:
|
|
20
|
+
1. 【完成标准】块内容**完全相同**才只留第一份,不同则各自保留;
|
|
21
|
+
2. `本条目主理目标:`行同理。
|
|
22
|
+
|
|
23
|
+
效果:**1066 → 575 字符(-46%)**,【完成标准】3→1、goal 3→1。
|
|
24
|
+
|
|
25
|
+
### 测试
|
|
26
|
+
- 新增 1 例(相同只留一份 / 不同都要留 / 两仓库内容都在 / 明显短于简单拼接)。合计 **146 例**。
|
|
27
|
+
|
|
28
|
+
## [0.9.3] - 2026-11-02 —— 同一会话的多条唤醒合并成一条
|
|
29
|
+
|
|
30
|
+
### 学到的(知识库第 52 条)
|
|
31
|
+
Google SRE《Handling Overload》:过载时要**减少工作**(coalesce/shed),不是更快失败。
|
|
32
|
+
<https://sre.google/sre-book/handling-overload/>
|
|
33
|
+
|
|
34
|
+
### 实测出来的形态
|
|
35
|
+
同会话 3 个守、间隔 60 秒:
|
|
36
|
+
```
|
|
37
|
+
首轮相位: 1184 / 2145 / 3106 ms
|
|
38
|
+
相邻两次唤醒间隔: 最小 0.96s / 中位 0.96s / 最大 0.96s
|
|
39
|
+
```
|
|
40
|
+
抖动是**一次性**的 —— 之后每个守按自己的 every 推进,相对相位几乎不变,
|
|
41
|
+
所以**每一轮**都会在约 1 秒内连着收到 3 条注入(5 个守就是 5 条)。
|
|
42
|
+
|
|
43
|
+
### 为什么不用"最小间隔"
|
|
44
|
+
先到的守会永远赢,后面的饿死 —— 和"固定窗口让突发者占名额"是同一类错。
|
|
45
|
+
|
|
46
|
+
### 改法:合并
|
|
47
|
+
同会话 **3 秒窗口**内的多条唤醒攒成一条:
|
|
48
|
+
```
|
|
49
|
+
【主理鱼】这一小段时间内有 3 处变化,合并成一条:
|
|
50
|
+
—— 第 1 处 —— … —— 第 2 处 —— …
|
|
51
|
+
```
|
|
52
|
+
单条不加包装;`decideWake`(是否 idle)在真正发送时再判,比原来更新鲜。
|
|
53
|
+
|
|
54
|
+
### 测试
|
|
55
|
+
- 新增 1 例。合计 **145 例**。
|
|
56
|
+
|
|
5
57
|
## [0.9.2] - 2026-11-02 —— 会话级唤醒上限:单守上限挡不住"多守叠加"
|
|
6
58
|
|
|
7
59
|
### 学到的(知识库第 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.4'
|
|
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.4'
|
|
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,44 @@ 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
|
+
// 每条唤醒都带着同一段【完成标准】和目标行 —— 合并后重复 3 遍纯属噪音(实测占约 40% 长度)。
|
|
578
|
+
// 只保留第一份;内容不同的(不同仓库的完成标准确实不同)则各自保留。
|
|
579
|
+
const seenCriteria = new Set()
|
|
580
|
+
const seenGoal = new Set()
|
|
581
|
+
const trimmed = list.map((text) => {
|
|
582
|
+
let out = text
|
|
583
|
+
const criteriaAt = out.indexOf('【完成标准】')
|
|
584
|
+
if (criteriaAt >= 0) {
|
|
585
|
+
const block = out.slice(criteriaAt)
|
|
586
|
+
if (seenCriteria.has(block)) out = out.slice(0, criteriaAt).replace(/[\s]+$/, '')
|
|
587
|
+
else seenCriteria.add(block)
|
|
588
|
+
}
|
|
589
|
+
out = out
|
|
590
|
+
.split(String.fromCharCode(10))
|
|
591
|
+
.filter((line) => {
|
|
592
|
+
if (!line.startsWith('本条目主理目标:')) return true
|
|
593
|
+
if (seenGoal.has(line)) return false
|
|
594
|
+
seenGoal.add(line)
|
|
595
|
+
return true
|
|
596
|
+
})
|
|
597
|
+
.join(String.fromCharCode(10))
|
|
598
|
+
return out
|
|
599
|
+
})
|
|
600
|
+
const head = '【主理鱼】这一小段时间内有 ' + list.length + ' 处变化,合并成一条:'
|
|
601
|
+
const body = trimmed.map((text, i) => String.fromCharCode(10, 10) + '—— 第 ' + (i + 1) + ' 处 ——' + String.fromCharCode(10) + text).join('')
|
|
602
|
+
return head + body
|
|
603
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
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",
|