dsh-session-superagent 0.9.19 → 0.9.21
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 +45 -0
- package/README.md +1 -1
- package/client.js +11 -1
- package/lib/index.js +20 -1
- package/lib/watch.js +13 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,51 @@
|
|
|
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.21] - 2026-11-02 —— 用原因码替代"匹配提示文案"
|
|
6
|
+
|
|
7
|
+
### 学到的(知识库第 70 条)
|
|
8
|
+
把展示层当数据层是反模式。OTel 的 log record 带结构化 attributes,文案只负责给人看。
|
|
9
|
+
一旦拿文案当判据,任何一次文案优化都会**静默改变统计数据**。
|
|
10
|
+
|
|
11
|
+
### 修的是什么
|
|
12
|
+
0.9.20 统计"几条守被上限挡住"用的是 `lastDeferred.includes('上限')`:
|
|
13
|
+
- 文案一改统计归零;
|
|
14
|
+
- "额度紧张(剩余 …)"这类含"上限"但不是频率上限的提示会被误算。
|
|
15
|
+
|
|
16
|
+
### 改法
|
|
17
|
+
服务端在各暂停分支写 `entry.deferReason`(`active-hours` / `ratelimit` / `quota` /
|
|
18
|
+
`unchanged` / `observe` / `cap-session` / `cap-watcher` / `busy`),
|
|
19
|
+
统计改用 `countCapped()` 只认两种 cap 码;`/state` 也回传 `deferReason`。
|
|
20
|
+
|
|
21
|
+
### 用例锁住的误判
|
|
22
|
+
```js
|
|
23
|
+
countCapped([{ lastDeferred: '每小时最多唤醒 6 次' }]) === 0 // 文案有"上限"也不算
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 测试
|
|
27
|
+
- 新增 2 例(计数语义 + `/state` 契约)。合计 **166 例**。
|
|
28
|
+
|
|
29
|
+
## [0.9.20] - 2026-11-02 —— 面板显示"还能用几次"(会话唤醒用量)
|
|
30
|
+
|
|
31
|
+
### 学到的(知识库第 69 条)
|
|
32
|
+
Google SRE 四个黄金指标里的 **saturation**:错误和延迟都是事后,**饱和是唯一能提前预警的**。
|
|
33
|
+
<https://sre.google/sre-book/monitoring-distributed-systems/#:~:text=Saturation>
|
|
34
|
+
|
|
35
|
+
### 上一轮模拟给的证据
|
|
36
|
+
离线跑一小时:**实际上报 12 / 共 30 条,被会话上限挡住 241 次** ——
|
|
37
|
+
默认参数下一半条目在排队,而界面上看不出来。
|
|
38
|
+
|
|
39
|
+
### 改法
|
|
40
|
+
`/state` 新增 `sessionUsage: { used, cap, capped }`(复用 `sessionWakesLastHour`,**零新增请求**)。
|
|
41
|
+
面板在「按仓库」旁显示:
|
|
42
|
+
- 常态 `本会话近一小时唤醒 3/12`;
|
|
43
|
+
- 到顶 `已到上限:新条目会攒到下一小时,可以把「这条会话每小时最多被唤醒」调大` + `2 条守正因上限暂停`。
|
|
44
|
+
|
|
45
|
+
只写"已到上限"等于把问题丢回客户;带上"把某个字段调大"才是可执行动作。
|
|
46
|
+
|
|
47
|
+
### 测试
|
|
48
|
+
- 新增 2 例(路由契约三字段;面板:没用满不报警 / 用满给建议 / 说清几条被挡)。合计 **164 例**。
|
|
49
|
+
|
|
5
50
|
## [0.9.19] - 2026-11-02 —— 离线跑一小时:限流/合并/去重没有互相打架
|
|
6
51
|
|
|
7
52
|
### 学到的(知识库第 68 条)
|
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.21'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
|
@@ -1272,6 +1272,16 @@ window.__ModuleLoader__.load({
|
|
|
1272
1272
|
h('div', { className: 'dt-row-meta' },
|
|
1273
1273
|
h(Pill, { active: problemsOnly, onClick: () => setProblemsOnly(!problemsOnly) }, '只看有问题的' + (problemCount > 0 ? ' (' + problemCount + ')' : '')),
|
|
1274
1274
|
problemsOnly ? h(Pill, { onClick: () => setProblemsOnly(false) }, '全部') : null),
|
|
1275
|
+
body.sessionUsage
|
|
1276
|
+
? h('div', { className: 'dt-row-meta' },
|
|
1277
|
+
h('span', null, '本会话近一小时唤醒 ' + body.sessionUsage.used + '/' + body.sessionUsage.cap),
|
|
1278
|
+
body.sessionUsage.used >= body.sessionUsage.cap
|
|
1279
|
+
? h('span', { className: 'dt-error-text' }, '已到上限:新条目会攒到下一小时,可以把「这条会话每小时最多被唤醒」调大')
|
|
1280
|
+
: null,
|
|
1281
|
+
body.sessionUsage.capped > 0
|
|
1282
|
+
? h('span', { className: 'dt-error-text' }, body.sessionUsage.capped + ' 条守正因上限暂停')
|
|
1283
|
+
: null)
|
|
1284
|
+
: null,
|
|
1275
1285
|
visible.length === 0 ? h(Hint, null, '没有符合条件的主理鱼。点上面「全部」看所有守。') : null,
|
|
1276
1286
|
h('div', { className: 'dt-rows' }, ...summarizeByRepo(visible).map((group) => h('div', { key: 'repo-' + group.repo, className: 'dt-row' },
|
|
1277
1287
|
h('div', { className: 'dt-row-main' },
|
package/lib/index.js
CHANGED
|
@@ -27,12 +27,13 @@ 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
29
|
shouldRunCleanup,
|
|
30
|
+
countCapped,
|
|
30
31
|
mergeFilters, mergePollResult, mergeWakeTexts, pushEvent, silentStreak, msUntilActiveWindow, nextWaketimeAt, pruneSeen, sessionWakesLastHour, pruneWakeTimes, pushHistory, recordReported, staleWorktrees, worktreePlan,
|
|
31
32
|
} from './watch.js'
|
|
32
33
|
|
|
33
34
|
export const name = 'dsh-session-superagent'
|
|
34
35
|
/** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
|
|
35
|
-
export const SERVER_VERSION = '0.9.
|
|
36
|
+
export const SERVER_VERSION = '0.9.21'
|
|
36
37
|
export const inject = ['tools', 'agents', 'webServer']
|
|
37
38
|
/** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
|
|
38
39
|
const DEFAULT_SESSION_WAKES = 12
|
|
@@ -800,6 +801,7 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
800
801
|
const wait = msUntilActiveWindow(entry.activeHours)
|
|
801
802
|
entry.nextAt = new Date(Date.now() + wait).toISOString()
|
|
802
803
|
entry.lastDeferred = `不在活跃时段(${entry.activeHours}),${Math.round(wait / 60000)} 分钟后开始`
|
|
804
|
+
entry.deferReason = 'active-hours'
|
|
803
805
|
noteEvent(entry, 'defer', entry.lastDeferred)
|
|
804
806
|
return
|
|
805
807
|
}
|
|
@@ -815,6 +817,7 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
815
817
|
if (wait > 0) {
|
|
816
818
|
entry.nextAt = new Date(Date.now() + wait).toISOString()
|
|
817
819
|
entry.lastDeferred = '被 GitHub 限流,按 Retry-After 等 ' + Math.round(wait / 1000) + ' 秒'
|
|
820
|
+
entry.deferReason = 'ratelimit'
|
|
818
821
|
noteEvent(entry, 'ratelimit', entry.lastDeferred)
|
|
819
822
|
entry.lastError = null
|
|
820
823
|
return
|
|
@@ -832,6 +835,7 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
832
835
|
if (throttle > 0) {
|
|
833
836
|
entry.nextAt = new Date(Date.now() + throttle).toISOString()
|
|
834
837
|
entry.lastDeferred = '额度紧张(剩余 ' + parsed.remaining + '),已推迟到 '
|
|
838
|
+
entry.deferReason = 'quota'
|
|
835
839
|
+ new Date(Date.now() + throttle).toISOString().slice(11, 16) + 'Z'
|
|
836
840
|
entry.lastError = null
|
|
837
841
|
return
|
|
@@ -842,6 +846,7 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
842
846
|
entry.consecutiveFailures = 0
|
|
843
847
|
entry.nextAt = null
|
|
844
848
|
entry.lastDeferred = '未变化(304,不计入速率限制)'
|
|
849
|
+
entry.deferReason = 'unchanged'
|
|
845
850
|
noteEvent(entry, 'unchanged', entry.lastDeferred)
|
|
846
851
|
return
|
|
847
852
|
}
|
|
@@ -894,6 +899,7 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
894
899
|
// 仅观察模式(对标官方 observe):照常判定,但只记录「本会唤醒哪几条」,不真唤醒
|
|
895
900
|
if (entry.observe === true) {
|
|
896
901
|
entry.lastDeferred = '仅观察:本轮本会唤醒 ' + fresh.length + ' 条(' + fresh.slice(0, 5).map((i) => '#' + i.number).join(' ') + ')'
|
|
902
|
+
entry.deferReason = 'observe'
|
|
897
903
|
noteEvent(entry, 'observe', entry.lastDeferred)
|
|
898
904
|
entry.history = pushHistory(entry.history, {
|
|
899
905
|
at: new Date().toISOString(),
|
|
@@ -911,6 +917,7 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
911
917
|
const sessionUsed = sessionWakesLastHour(Object.values(readState().watchers || {}), entry.sessionId)
|
|
912
918
|
if (sessionUsed >= sessionCap) {
|
|
913
919
|
entry.lastDeferred = '这条会话一小时内已被唤醒 ' + sessionUsed + ' 次(上限 ' + sessionCap + '),已攒 ' + fresh.length + ' 条待处理'
|
|
920
|
+
entry.deferReason = 'cap-session'
|
|
914
921
|
noteEvent(entry, 'cap-session', entry.lastDeferred)
|
|
915
922
|
return
|
|
916
923
|
}
|
|
@@ -923,6 +930,7 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
923
930
|
const freeAt = nextWaketimeAt(entry.wakeTimes, cap)
|
|
924
931
|
const waitMin = Math.max(1, Math.round((freeAt - Date.now()) / 60000))
|
|
925
932
|
entry.lastDeferred = `每小时最多唤醒 ${cap} 次,已攒 ${fresh.length} 条待处理(约 ${waitMin} 分钟后可再唤醒)`
|
|
933
|
+
entry.deferReason = 'cap-watcher'
|
|
926
934
|
noteEvent(entry, 'cap-watcher', entry.lastDeferred)
|
|
927
935
|
return
|
|
928
936
|
}
|
|
@@ -1011,6 +1019,7 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
1011
1019
|
entry.prevWakeAt = new Date().toISOString()
|
|
1012
1020
|
entry.wakeTimes.push(Date.now())
|
|
1013
1021
|
entry.lastDeferred = null
|
|
1022
|
+
entry.deferReason = null
|
|
1014
1023
|
noteEvent(entry, 'wake', '唤醒了 ' + (entry.lastBatch || []).length + ' 条:' + (entry.lastBatch || []).map((n) => '#' + n).join(' '))
|
|
1015
1024
|
entry.seen = advanceSeen(entry.seen, fresh)
|
|
1016
1025
|
entry.lastReported = recordReported(entry, fresh)
|
|
@@ -1020,6 +1029,7 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
1020
1029
|
entry.lastError = 'wake failed: ' + String(result.reason || '')
|
|
1021
1030
|
noteEvent(entry, 'wake-failed', entry.lastError)
|
|
1022
1031
|
// 会话正忙是暂时的:下一轮直接重试;退避反而会越拖越久
|
|
1032
|
+
entry.deferReason = 'busy'
|
|
1023
1033
|
if (/busy|running|idle/i.test(String(result.reason || ''))) {
|
|
1024
1034
|
entry.lastDeferred = '会话正忙,下一轮重试'
|
|
1025
1035
|
} else {
|
|
@@ -1217,6 +1227,7 @@ export function apply(ctx) {
|
|
|
1217
1227
|
maxIsolated: w.maxIsolated ?? 5,
|
|
1218
1228
|
history: (w.history ?? []).slice(-5),
|
|
1219
1229
|
events: (w.events ?? []).slice(-20),
|
|
1230
|
+
deferReason: w.deferReason ?? null,
|
|
1220
1231
|
silentWakes: w.silentWakes ?? 0,
|
|
1221
1232
|
note: w.goal ?? '',
|
|
1222
1233
|
title: sessionTitle(w.sessionId),
|
|
@@ -1229,6 +1240,14 @@ export function apply(ctx) {
|
|
|
1229
1240
|
credentials: secretsSummary(),
|
|
1230
1241
|
sessionGoal: goalView(ctx, focusSession),
|
|
1231
1242
|
stateSource,
|
|
1243
|
+
// 会话级用量:上限够不够,客户应该一眼看到(数据都在状态里,零新增请求)
|
|
1244
|
+
sessionUsage: (() => {
|
|
1245
|
+
const list = Object.values(state.watchers || {})
|
|
1246
|
+
const usage = list.length === 0 ? null : sessionWakesLastHour(list, focusSession)
|
|
1247
|
+
const cap = list.length === 0 ? null : (Number(list[0].sessionMaxWakes) || 12)
|
|
1248
|
+
const capped = countCapped(list)
|
|
1249
|
+
return usage === null ? null : { used: usage, cap, capped }
|
|
1250
|
+
})(),
|
|
1232
1251
|
// 版本漂移:文件换了但宿主还在跑老模块(客户端热重载会掩盖这件事)
|
|
1233
1252
|
installedVersion: installedVersion(),
|
|
1234
1253
|
runningVersion: SERVER_VERSION,
|
package/lib/watch.js
CHANGED
|
@@ -723,3 +723,16 @@ export function summarizeByRepo(watchers) {
|
|
|
723
723
|
const weight = (g) => (g.errors > 0 ? 0 : g.silentWakes >= 2 ? 1 : 2)
|
|
724
724
|
return [...groups.values()].sort((a, b) => (weight(a) - weight(b)) || a.repo.localeCompare(b.repo))
|
|
725
725
|
}
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* 有几条守正被"频率上限"挡着。
|
|
729
|
+
*
|
|
730
|
+
* 之前是面板去匹配提示文案(`lastDeferred.includes('上限')`)—— 文案一改统计就废。
|
|
731
|
+
* 现在服务端在暂停时写一个明确的 `deferReason`,这里只按字段统计。
|
|
732
|
+
*/
|
|
733
|
+
export const CAP_REASONS = ['cap-session', 'cap-watcher']
|
|
734
|
+
|
|
735
|
+
export function countCapped(watchers) {
|
|
736
|
+
const list = Array.isArray(watchers) ? watchers : Object.values(watchers || {})
|
|
737
|
+
return list.filter((w) => w && CAP_REASONS.includes(w.deferReason)).length
|
|
738
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.21",
|
|
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",
|