dsh-session-superagent 0.9.0 → 0.9.2

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,49 @@
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.2] - 2026-11-02 —— 会话级唤醒上限:单守上限挡不住"多守叠加"
6
+
7
+ ### 学到的(知识库第 51 条)
8
+ K8s `ResourceQuota`:**单个 Pod 的 limits 不能防止 namespace 被打满**,要在上一层再加配额。
9
+ <https://kubernetes.io/docs/concepts/policy/resource-quotas/>
10
+
11
+ ### 代码里核实出来的漏洞
12
+ `maxWakesPerHour` 记在**每条守**身上(`entry.wakeTimes`):
13
+ ```
14
+ 1 条会话守 5 个仓库 → 实际上限 5 × 6 = 30 次/小时;每次 5 条 → 最多 150 条/小时注进同一会话
15
+ ```
16
+ 而设这个上限的原因正是"别把上下文打爆" —— 多守叠加后它完全没起作用。
17
+
18
+ ### 改了什么
19
+ 新增**会话级上限 `sessionMaxWakes`(默认 12/小时,跨所有守累计)**:
20
+ > 这条会话一小时内已被唤醒 8 次(上限 12),已攒 3 条待处理
21
+
22
+ 三层限额:单次批量 5 / 单守 6 / **会话总量 12**。面板可改,`/state` 回传。
23
+
24
+ ### 测试
25
+ - 新增 1 例(跨守累加、过期不计、多会话隔离、对象/数组入参、坏数据不崩)。合计 **144 例**。
26
+
27
+ ## [0.9.1] - 2026-11-02 —— 修正「已知限制」:一条是错的,三条缺
28
+
29
+ ### 核对出来的(知识库第 50 条)
30
+ 把 README 的限制逐条对照代码:
31
+
32
+ | README 原文 | 实际 |
33
+ |---|---|
34
+ | 「单会话单仓库」 | **错** —— 守的 id 是 `repo#sessionId`,同一会话可多条 |
35
+ | 「`node --test # 136 项单测`」 | 过时(143),且每版都变 |
36
+ | 未写「服务端改动要重启」 | **缺**(本机踩得最多的一条) |
37
+ | 未写「每小时上限是滑动窗口」 | **缺**(客户会以为整点重置) |
38
+ | 未写「隔离区最多 5 个」 | **缺**(这轮才有的行为) |
39
+
40
+ ### 两条做法
41
+ 1. **限制要写"客户会误判什么"**,不是写"我们实现了什么";
42
+ 2. **易变数字(单测条数)不要写进 README** —— 忘改就是谎话,放 CHANGELOG/MAINTENANCE 更合适。
43
+
44
+ ### 顺带
45
+ `docs/whats-new-0.9.md` 从"预告"改成"已发布",补上 0.9 的四项新行为(时段前移、等待可见、
46
+ 隔离区数量线、错误人话)。文档体检 71 篇 / 68 链接全 PASS。
47
+
5
48
  ## [0.9.0] - 2026-11-02 —— 隔离区加"数量线":最坏 432 个副本 → 最多 5 个
6
49
 
7
50
  ### 学到的(知识库第 49 条)
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.0-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.2-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
 
@@ -98,8 +98,15 @@ dsh plugin install /path/to/dsh-session-superagent
98
98
 
99
99
  - 依赖 `gh` CLI 已登录;需要 GitHub 账号权限。
100
100
  - 轮询而非 webhook:延迟等于轮询间隔。
101
- - 单会话单仓库;多仓库请每仓库一个会话,各自 `watch_start`。
101
+ - 一条会话可以守多个仓库(每条守独立配置间隔/过滤/时段),但**同一会话同一时刻只处理一批**:
102
+ 多仓库同时有动静时按每小时上限排队。
102
103
  - 宿主重启后 watcher 从状态文件恢复;会话不在则不注入(会记 `lastError`)。
104
+ - **服务端改动要重启宿主才生效**(客户端热重载会生效,别被"界面上有新功能"骗了;
105
+ 面板顶部会在版本不一致时直接提示)。
106
+ - 每小时唤醒上限是**滑动窗口**:6 次若集中在开头几分钟,下一次要等约 1 小时
107
+ (面板会写「约 X 分钟后可再唤醒」)。
108
+ - 隔离执行会在仓库下留 `.dsh-zhuli/` 副本:默认**最多 5 个**、超 3 天回收;
109
+ 副本体积≈该仓库工作树大小。
103
110
 
104
111
  ## 开发
105
112
 
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.0'
17
+ const CLIENT_VERSION = '0.9.2'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
@@ -929,6 +929,7 @@ window.__ModuleLoader__.load({
929
929
  },
930
930
  batchLimit: Number(draft.batchLimit) || undefined,
931
931
  maxWakesPerHour: Number(draft.maxWakesPerHour) || undefined,
932
+ sessionMaxWakes: Number(draft.sessionMaxWakes) || undefined,
932
933
  }),
933
934
  })
934
935
  setEditing(null)
@@ -1020,6 +1021,7 @@ window.__ModuleLoader__.load({
1020
1021
  workdir: watcher.workdir || '',
1021
1022
  batchLimit: watcher.batchLimit ? String(watcher.batchLimit) : '',
1022
1023
  maxWakesPerHour: watcher.maxWakesPerHour ? String(watcher.maxWakesPerHour) : '',
1024
+ sessionMaxWakes: watcher.sessionMaxWakes ? String(watcher.sessionMaxWakes) : '',
1023
1025
  isolateKeepDays: watcher.isolateKeepDays ? String(watcher.isolateKeepDays) : '',
1024
1026
  maxIsolated: watcher.maxIsolated ? String(watcher.maxIsolated) : '',
1025
1027
  priorityReopened: (watcher.priority && watcher.priority.reopened) !== false,
@@ -1074,6 +1076,7 @@ window.__ModuleLoader__.load({
1074
1076
  h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: !!draft.onlyAssigned, onChange: (v) => setDraft({ ...draft, onlyAssigned: v }), label: '只看已指派' }), '只处理已指派给人的条目'),
1075
1077
  field('单次最多唤醒条数', h(Input, { value: draft.batchLimit || '', placeholder: '5(1-20)', onChange: (e) => setDraft({ ...draft, batchLimit: e.target.value }) })),
1076
1078
  field('每小时最多唤醒次数', h(Input, { value: draft.maxWakesPerHour || '', placeholder: '6(1-60)', onChange: (e) => setDraft({ ...draft, maxWakesPerHour: e.target.value }) })),
1079
+ field('这条会话每小时最多被唤醒', h(Input, { value: draft.sessionMaxWakes || '', placeholder: '12(1-60)', onChange: (e) => setDraft({ ...draft, sessionMaxWakes: e.target.value }) }), '跨所有守累计:守 5 个仓库时,光有单守上限挡不住叠加'),
1077
1080
  field('优先级(一次只处理 N 条时先挑谁)', h('div', { className: 'dt-actions' },
1078
1081
  h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityReopened !== false, onChange: (v) => setDraft({ ...draft, priorityReopened: v }), label: '重开优先' }), '被重开的排最前'),
1079
1082
  h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityComments !== false, onChange: (v) => setDraft({ ...draft, priorityComments: v }), label: '评论优先' }), '有人在等回应的靠前'),
package/lib/index.js CHANGED
@@ -26,13 +26,15 @@ 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, pruneWakeTimes, pushHistory, recordReported, staleWorktrees, worktreePlan,
29
+ mergeFilters, mergePollResult, 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.0'
34
+ export const SERVER_VERSION = '0.9.2'
35
35
  export const inject = ['tools', 'agents', 'webServer']
36
+ /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
37
+ const DEFAULT_SESSION_WAKES = 12
36
38
 
37
39
  /** 仅供测试:读写状态文件(生产代码不要用)。 */
38
40
  export const __test = { readState, writeState, hardenSecretsFile }
@@ -837,6 +839,14 @@ async function pollOnce(ctx, entry, baseMs) {
837
839
  return
838
840
  }
839
841
 
842
+ // 会话级上限(跨守累计):单守上限 × 守数量 = 实际频率,光有单守上限挡不住
843
+ const sessionCap = Math.max(1, Number(entry.sessionMaxWakes) || DEFAULT_SESSION_WAKES)
844
+ const sessionUsed = sessionWakesLastHour(Object.values(readState().watchers || {}), entry.sessionId)
845
+ if (sessionUsed >= sessionCap) {
846
+ entry.lastDeferred = '这条会话一小时内已被唤醒 ' + sessionUsed + ' 次(上限 ' + sessionCap + '),已攒 ' + fresh.length + ' 条待处理'
847
+ return
848
+ }
849
+
840
850
  // 每小时唤醒上限:宁可攒着,也不要连续叫醒把上下文打爆
841
851
  const cap = Math.max(1, Number(entry.maxWakesPerHour) || 6)
842
852
  entry.wakeTimes = pruneWakeTimes(entry.wakeTimes)
@@ -1093,6 +1103,7 @@ export function apply(ctx) {
1093
1103
  filters: w.filters ?? null,
1094
1104
  batchLimit: w.batchLimit ?? 5,
1095
1105
  maxWakesPerHour: w.maxWakesPerHour ?? 6,
1106
+ sessionMaxWakes: w.sessionMaxWakes ?? 12,
1096
1107
  consecutiveFailures: w.consecutiveFailures ?? 0,
1097
1108
  nextAt: w.nextAt ?? null,
1098
1109
  lastDeferred: w.lastDeferred ?? null,
@@ -1257,6 +1268,7 @@ export function apply(ctx) {
1257
1268
  entry.filters = mergeFilters(entry.filters, body.filters)
1258
1269
  entry.batchLimit = Math.max(1, Math.min(20, Number(body.batchLimit) || entry.batchLimit || 5))
1259
1270
  entry.maxWakesPerHour = Math.max(1, Math.min(60, Number(body.maxWakesPerHour) || entry.maxWakesPerHour || 6))
1271
+ if (body.sessionMaxWakes != null) entry.sessionMaxWakes = Math.max(1, Math.min(60, Number(body.sessionMaxWakes) || DEFAULT_SESSION_WAKES))
1260
1272
  if (typeof body.ackLabel === 'string' && body.ackLabel.trim()) entry.ackLabel = body.ackLabel.trim().slice(0, 60)
1261
1273
  // 优先级开关:客户可以关掉某几类"加权",只按 updated 顺序处理
1262
1274
  if (body.priority && typeof body.priority === 'object') {
package/lib/watch.js CHANGED
@@ -539,3 +539,24 @@ export function nextWaketimeAt(wakeTimes, cap, now = Date.now()) {
539
539
  const freeing = times[times.length - n]
540
540
  return freeing + 60 * 60 * 1000
541
541
  }
542
+
543
+ /**
544
+ * 同一条会话在过去一小时被唤醒了几次(跨所有守)。
545
+ *
546
+ * 为什么需要:`maxWakesPerHour` 是**按守**算的。一条会话守 5 个仓库时,
547
+ * 上限实际是 5 × 6 = 30 次/小时 —— 这根本没保护到"别把会话的上下文打爆",
548
+ * 而那正是当初设这个上限的原因。
549
+ *
550
+ * 类比:只给单个 Pod 设 CPU limit,并不能防止整个 namespace 被打满,所以还要 ResourceQuota。
551
+ * 出处:https://kubernetes.io/docs/concepts/policy/resource-quotas/
552
+ */
553
+ export function sessionWakesLastHour(entries, sessionId, now = Date.now()) {
554
+ if (!sessionId) return 0
555
+ const list = Array.isArray(entries) ? entries : Object.values(entries || {})
556
+ let total = 0
557
+ for (const entry of list) {
558
+ if (!entry || entry.sessionId !== sessionId) continue
559
+ total += pruneWakeTimes(entry.wakeTimes, now).length
560
+ }
561
+ return total
562
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
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",