dsh-session-superagent 0.8.97 → 0.8.98

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,31 @@
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.8.98] - 2026-11-02 —— 时段外不再空打 API(一夜能省 800+ 次)
6
+
7
+ ### 学到的(知识库第 47 条)
8
+ Renovate 的 `schedule`:**不在时间窗内就不去查更新**,而不是"查完再决定"。
9
+ 通用原则:把"不做"的判断尽量前移。
10
+ <https://docs.renovatebot.com/configuration-options/#schedule>
11
+
12
+ ### 抓到的浪费
13
+ `pollOnce` 里 `activeHours` 的判断原来在**拉完 API 之后**:
14
+ ```js
15
+ const res = await run('gh', ...) // 先打一次 GitHub
16
+ if (!inActiveHours(entry.activeHours)) return // 才决定不叫醒
17
+ ```
18
+ 客户设 `09:00-18:00`,**夜里 14 小时照样每 N 秒打一次**:60 秒间隔 ≈ **一夜 840 次**
19
+ (多数是 304 不计额度,但每次都要起 `gh` 进程 + 一次网络往返),且开门后还要等下一个周期。
20
+
21
+ ### 改了什么
22
+ 1. 时段判断**移到函数最前**(拉数据之前);
23
+ 2. 用 `msUntilActiveWindow()` 算出开门时间,把 `nextAt` 设到那一刻。
24
+
25
+ 用例锁死语义:23:30 → 9.5 小时;07:00 → 2 小时;跨夜 15:00 → 7 小时;非法/空 → 0;最小 1 秒。
26
+
27
+ ### 测试
28
+ - 新增 1 例(8 种情况)。合计 **141 例**。
29
+
5
30
  ## [0.8.97] - 2026-11-02 —— 错误提示要回答"我该做什么"
6
31
 
7
32
  ### 学到的(知识库第 46 条)
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.8.97-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.8.98-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.8.97'
17
+ const CLIENT_VERSION = '0.8.98'
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, pruneSeen, pruneWakeTimes, pushHistory, recordReported, staleWorktrees, worktreePlan,
29
+ mergeFilters, mergePollResult, msUntilActiveWindow, pruneSeen, 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.8.97'
34
+ export const SERVER_VERSION = '0.8.98'
35
35
  export const inject = ['tools', 'agents', 'webServer']
36
36
 
37
37
  /** 仅供测试:读写状态文件(生产代码不要用)。 */
@@ -728,6 +728,14 @@ async function fetchLastComments(repo, items, maxItems = 3) {
728
728
  }
729
729
 
730
730
  async function pollOnce(ctx, entry, baseMs) {
731
+ // 活跃时段要**在拉 API 之前**判断:以前放在后面,夜里照样每 N 秒打一次 GitHub,纯浪费。
732
+ // 不在时段内就把下一次轮询安排到"开门那一刻",攒着的条目不会多等一个周期。
733
+ if (entry.activeHours && !inActiveHours(entry.activeHours)) {
734
+ const wait = msUntilActiveWindow(entry.activeHours)
735
+ entry.nextAt = new Date(Date.now() + wait).toISOString()
736
+ entry.lastDeferred = `不在活跃时段(${entry.activeHours}),${Math.round(wait / 60000)} 分钟后开始`
737
+ return
738
+ }
731
739
  // 条件请求:带上上次的 ETag,没变化时 GitHub 回 304,且**不计入**速率限制
732
740
  const args = ['api', '--include', `repos/${entry.repo}/issues?state=all&sort=updated&direction=desc&per_page=20`]
733
741
  if (entry.etag) args.push('-H', 'If-None-Match: ' + entry.etag)
@@ -828,12 +836,6 @@ async function pollOnce(ctx, entry, baseMs) {
828
836
  return
829
837
  }
830
838
 
831
- // 活跃时段:夜里不叫醒,攒着(对标 Renovate 的 schedule)
832
- if (entry.activeHours && !inActiveHours(entry.activeHours)) {
833
- entry.lastDeferred = `不在活跃时段(${entry.activeHours}),已攒 ${fresh.length} 条`
834
- return
835
- }
836
-
837
839
  // 每小时唤醒上限:宁可攒着,也不要连续叫醒把上下文打爆
838
840
  const cap = Math.max(1, Number(entry.maxWakesPerHour) || 6)
839
841
  entry.wakeTimes = pruneWakeTimes(entry.wakeTimes)
package/lib/watch.js CHANGED
@@ -484,3 +484,24 @@ export {
484
484
  stateReasonNote,
485
485
  throttleDelayMs,
486
486
  } from './gh-format.js'
487
+
488
+ /**
489
+ * 距离「活跃时段开门」还有多久(毫秒);已在时段内返回 0。
490
+ *
491
+ * 为什么要它:以前 activeHours 的判断在**拉完 API 之后**才做 ——
492
+ * 夜里 8 小时照常每 N 秒打一次 GitHub,纯属白跑。现在提前到最前面,
493
+ * 并把下一次轮询安排在"开门那一刻",既不浪费请求,也不会让攒着的条目干等一个周期。
494
+ */
495
+ export function msUntilActiveWindow(spec, now = new Date()) {
496
+ if (!spec || typeof spec !== 'string') return 0
497
+ const m = spec.match(/^(\d{1,2}):(\d{2})\s*-\s*(\d{1,2}):(\d{2})$/)
498
+ if (!m) return 0
499
+ if (inActiveHours(spec, now)) return 0
500
+ const startMin = (Number(m[1]) * 60 + Number(m[2])) % (24 * 60)
501
+ const curMin = now.getHours() * 60 + now.getMinutes()
502
+ const curSec = now.getSeconds()
503
+ let diffMin = startMin - curMin
504
+ if (diffMin <= 0) diffMin += 24 * 60
505
+ // 精确到分钟的开头,再减掉当前秒数
506
+ return Math.max(1000, diffMin * 60 * 1000 - curSec * 1000)
507
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.8.97",
3
+ "version": "0.8.98",
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",