dsh-session-superagent 0.9.33 → 0.9.35

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 CHANGED
@@ -2,6 +2,50 @@
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.35] - 2026-11-02 —— 「今天明显比平时忙」:阈值故意定高
6
+
7
+ ### 学到的(知识库第 83 条)
8
+ 用历史影响判断时,阈值要故意定高 —— 告警疲劳的代价远大于少提示一次。
9
+
10
+ ### 规则(`busierThanUsual`)
11
+ | 条件 | 结论 |
12
+ |---|---|
13
+ | 历史不足 3 天 / 日均 0 | 不提示(没有基线) |
14
+ | 今天 < 日均 × 2 | 不提示 |
15
+ | 今天 ≥ 日均 × 2 | 「今天明显比平时忙 —— 上限可能不够用」 |
16
+
17
+ 阈值下限写死 1.5 倍(调用方传更小也不会更低)。
18
+
19
+ ### 判断放在服务端
20
+ `/state` 回传 `busy: true/false`,面板只显示 —— 与 0.9.21 一致:**面板不再实现第二份判断逻辑**。
21
+
22
+ ### 为什么宁可不提示
23
+ 真积压已有更硬的信号(`sessionUsage.capped > 0`);历史基线是用来**发现异常**,不是制造焦虑。
24
+
25
+ ### 测试
26
+ - 新增 2 例(阈值 6 种情况;面板 busy=false 不提示 / true 提示且给原因)。合计 **175 例**。
27
+
28
+ ## [0.9.34] - 2026-11-02 —— 留一份「每天一个数」的极小历史
29
+
30
+ ### 学到的(知识库第 82 条)
31
+ 只看瞬时值会放大偶发尖峰;基线要按天聚合,但**不必**是完整日志。
32
+
33
+ ### 改法
34
+ `bumpDailyWakes(daily, atIso, keepDays = 7)`:key 是 `YYYY-MM-DD`,同日累加,只留最近 7 天(**几十字节**)。
35
+ `dailySummary()` → `{ days, total, avg }`,面板显示:
36
+ > 过去 3 天:共 9 次(日均 3)
37
+
38
+ ### 为什么不做更细
39
+ 每小时 × 7 天 = 168 个数字,收益低;`events`(最近 20 条)已经回答"刚才发生了什么",
40
+ `daily` 只回答"最近忙不忙",两者职责不同。
41
+
42
+ ### 诚实说明
43
+ **建议逻辑仍只看当前一小时** —— 历史目前只用于展示。用它改建议需要更多真实数据验证,
44
+ 现在改了反而可能误导。
45
+
46
+ ### 测试
47
+ - 新增 2 例(同日累加 / 只留 7 天 / 坏日期 / summary;面板显示历史)。合计 **173 例**。
48
+
5
49
  ## [0.9.33] - 2026-11-02 —— 到上限时给出具体数字,而不是"把上限调大"
6
50
 
7
51
  ### 学到的(知识库第 81 条)
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: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
- [![Version](https://img.shields.io/badge/version-0.9.33-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.35-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
7
7
  [![npm](https://img.shields.io/npm/v/dsh-session-superagent.svg)](https://www.npmjs.com/package/dsh-session-superagent)
8
8
  [![dsh](https://img.shields.io/badge/DeepSeek%20Harness-plugin-orange.svg)](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.33'
17
+ const CLIENT_VERSION = '0.9.35'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
@@ -1337,7 +1337,20 @@ window.__ModuleLoader__.load({
1337
1337
  : null,
1338
1338
  body.sessionUsage.capped > 0
1339
1339
  ? h('span', { className: 'dt-error-text' }, body.sessionUsage.capped + ' 条守正因上限暂停')
1340
- : null)
1340
+ : null,
1341
+ (() => {
1342
+ // 过去几天累计(数据来自每条守的 daily,几十字节)
1343
+ const days = watchers.reduce((n, w) => n + (Number(w.daily && w.daily.days) || 0), 0)
1344
+ const total = watchers.reduce((n, w) => n + (Number(w.daily && w.daily.total) || 0), 0)
1345
+ if (total === 0) return null
1346
+ const span = Math.max(...watchers.map((w) => Number(w.daily && w.daily.days) || 0))
1347
+ return [
1348
+ h('span', { key: 'hist', className: 'dt-row-meta' }, '过去 ' + span + ' 天:共 ' + total + ' 次(日均 ' + (Math.round((total / Math.max(1, span)) * 10) / 10) + ')'),
1349
+ watchers.some((w) => w.busy)
1350
+ ? h('span', { key: 'busy', className: 'dt-error-text' }, '今天明显比平时忙 —— 上限可能不够用')
1351
+ : null,
1352
+ ]
1353
+ })())
1341
1354
  : null,
1342
1355
  visible.length === 0 ? h(Hint, null, '没有符合条件的主理鱼。点上面「全部」看所有守。') : null,
1343
1356
  h('div', { className: 'dt-rows' }, ...summarizeByRepo(visible).map((group) => h('div', { key: 'repo-' + group.repo, className: 'dt-row' },
package/lib/index.js CHANGED
@@ -27,7 +27,10 @@ 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
+ bumpDailyWakes,
31
+ busierThanUsual,
30
32
  countCapped,
33
+ dailySummary,
31
34
  suggestSessionCap,
32
35
  itemTrace,
33
36
  splitBatch,
@@ -36,7 +39,7 @@ import {
36
39
 
37
40
  export const name = 'dsh-session-superagent'
38
41
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
39
- export const SERVER_VERSION = '0.9.33'
42
+ export const SERVER_VERSION = '0.9.35'
40
43
  export const inject = ['tools', 'agents', 'webServer']
41
44
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
42
45
  const DEFAULT_SESSION_WAKES = 12
@@ -1045,6 +1048,7 @@ async function pollOnce(ctx, entry, baseMs) {
1045
1048
  if (entry.silentWakes === 0 && entry.prevWakeAt) noteEvent(entry, 'acked', '上一次唤醒有回音(ack 出现过了)')
1046
1049
  entry.prevWakeAt = new Date().toISOString()
1047
1050
  entry.wakeTimes.push(Date.now())
1051
+ entry.dailyWakes = bumpDailyWakes(entry.dailyWakes)
1048
1052
  entry.lastDeferred = null
1049
1053
  entry.deferReason = null
1050
1054
  noteEvent(entry, 'wake', '唤醒了 ' + (entry.lastBatch || []).length + ' 条:' + (entry.lastBatch || []).map((n) => '#' + n).join(' '))
@@ -1255,6 +1259,8 @@ export function apply(ctx) {
1255
1259
  history: (w.history ?? []).slice(-5),
1256
1260
  events: (w.events ?? []).slice(-20),
1257
1261
  deferReason: w.deferReason ?? null,
1262
+ daily: dailySummary(w.dailyWakes),
1263
+ busy: busierThanUsual(dailySummary(w.dailyWakes)),
1258
1264
  silentWakes: w.silentWakes ?? 0,
1259
1265
  note: w.goal ?? '',
1260
1266
  title: sessionTitle(w.sessionId),
package/lib/watch.js CHANGED
@@ -799,3 +799,51 @@ export function suggestSessionCap({ used = 0, cap = 12, capped = 0, max = 60 } =
799
799
  const wanted = blocked > 0 ? doubled : c + Math.ceil(c / 2)
800
800
  return Math.min(Math.max(1, Number(max) || 60), wanted)
801
801
  }
802
+
803
+ /**
804
+ * 按天累计唤醒次数,只保留最近 N 天(默认 7)。
805
+ *
806
+ * 为什么需要:上限建议目前只看"当前这一小时",是瞬时值 ——
807
+ * 偶尔一次积压就建议翻倍,客户可能被误导。留一份极小的历史(每天一个数,几十字节),
808
+ * 面板就能显示"过去 7 天共 N 次",让判断有上下文。
809
+ * 用 map 而不是数组:同一天多次唤醒只加同一条,天然去重。
810
+ */
811
+ export function bumpDailyWakes(daily, atIso = new Date().toISOString(), keepDays = 7) {
812
+ const day = String(atIso).slice(0, 10)
813
+ const map = (daily && typeof daily === 'object' && !Array.isArray(daily)) ? { ...daily } : {}
814
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(day)) return map
815
+ map[day] = (Number(map[day]) || 0) + 1
816
+ const days = Object.keys(map).sort().slice(-Math.max(1, Number(keepDays) || 7))
817
+ const out = {}
818
+ for (const key of days) out[key] = map[key]
819
+ return out
820
+ }
821
+
822
+ /** 最近几天的总量与日均(给面板显示用;没有数据就返回 null)。 */
823
+ export function dailySummary(daily, todayIso = new Date().toISOString()) {
824
+ const map = (daily && typeof daily === 'object' && !Array.isArray(daily)) ? daily : {}
825
+ const values = Object.values(map).map(Number).filter((n) => Number.isFinite(n) && n >= 0)
826
+ if (values.length === 0) return null
827
+ const total = values.reduce((a, b) => a + b, 0)
828
+ const day = String(todayIso).slice(0, 10)
829
+ return {
830
+ days: values.length,
831
+ total,
832
+ avg: Math.round((total / values.length) * 10) / 10,
833
+ today: Number(map[day]) || 0,
834
+ }
835
+ }
836
+
837
+ /**
838
+ * 「今天明显比平时忙」:只在有足够历史、且高出很多倍时才提示。
839
+ *
840
+ * 阈值故意保守(默认 2 倍 + 至少 3 天数据)——
841
+ * 拿历史去影响判断,最怕的是频繁误报;宁可少提示,也不要制造噪音。
842
+ */
843
+ export function busierThanUsual(summary, { factor = 2, minDays = 3 } = {}) {
844
+ if (!summary || !Number.isFinite(Number(summary.days)) || summary.days < minDays) return false
845
+ const avg = Number(summary.avg) || 0
846
+ const today = Number(summary.today) || 0
847
+ if (avg <= 0) return false // 历史为 0 时没有可比基线
848
+ return today >= avg * Math.max(1.5, Number(factor) || 2)
849
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.33",
3
+ "version": "0.9.35",
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",