dsh-session-superagent 0.8.50 → 0.8.51

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.51] - 2026-11-02 —— 条件请求:没变化不计入速率限制
6
+
7
+ ### 学到了什么(新知识库 `docs/kb/` 的第一条)
8
+ GitHub 官方最佳实践原文:*"Make authenticated conditional requests, so that unchanged data does not
9
+ count against your primary rate limit."*
10
+ 出处:<https://docs.github.com/en/rest/using-the-rest-api/best-practices-for-using-the-rest-api>
11
+
12
+ 主理鱼每 N 秒拉一次 issue 列表,**大多数轮次其实什么都没变** —— 全量拉属于纯浪费,还占额度。
13
+
14
+ ### 改了什么
15
+ - 每条 watcher 记住 `etag`;下一轮带 `-H 'If-None-Match: <etag>'`;
16
+ - 收到 **304** 当「本轮无变化」:不解析、不记失败、**不动退避**(退避是给失败的,304 是成功);
17
+ - `gh api --include` 会输出「状态行 + 头 + 空行 + 正文」,新增纯函数 `parseGhInclude` 解析,
18
+ 用例覆盖 200 / 304 / 纯正文三种形态。
19
+
20
+ ### 效果
21
+ 没变化时:网络传输从「20 条 issue 的 JSON」降到「一个空响应」,且**不计入 rate limit**。
22
+
23
+ ### 附带
24
+ - 新建 `docs/kb/`(入口索引 + 按主题分组),本轮第一条 `github-conditional-requests.md`;
25
+ - 小时级定时任务改为「先学一条 → 再改一处 → 报三段」,作为保底。
26
+
27
+ ### 测试
28
+ - 合计 **104 例**;UI 体检 11/11。
29
+
5
30
  ## [0.8.50] - 2026-11-02 —— 双主题预览进「一键命令 + 门禁」
6
31
 
7
32
  以前 `render-preview.mjs` 是个内部脚本,没人知道它存在;现在:
package/MAINTENANCE.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## 二、当前状态(2026-11-01)
11
11
 
12
- - [x] 七个工具可用(github / repo_here / watch_start / watch_status / watch_stop / watch_ack / watch_doctor),`node --test` 103/103 通过
12
+ - [x] 七个工具可用(github / repo_here / watch_start / watch_status / watch_stop / watch_ack / watch_doctor),`node --test` 104/104 通过
13
13
  - [x] 自回声抑制(逐条水位)
14
14
  - [x] 仅空闲注入(避免草稿回放)
15
15
  - [x] 唤醒失败不推进水位
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.50-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.8.51-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
 
@@ -99,7 +99,7 @@ dsh plugin install /path/to/dsh-session-superagent
99
99
  ## 开发
100
100
 
101
101
  ```sh
102
- node --test # 103 项单测
102
+ node --test # 104 项单测
103
103
  ```
104
104
 
105
105
  版本与发布流程见 [UPDATING.md](UPDATING.md),交付门见 [CHECKLIST.md](CHECKLIST.md),接手台账见 [MAINTENANCE.md](MAINTENANCE.md)。
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.50'
17
+ const CLIENT_VERSION = '0.8.51'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
package/lib/index.js CHANGED
@@ -24,13 +24,13 @@ import { redact } from './redact.js'
24
24
  import { decodeBody } from './body.js'
25
25
  import {
26
26
  advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, formatWatchText,
27
- classifyGhError, filterReason, hasAckLabel, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
27
+ classifyGhError, filterReason, hasAckLabel, parseGhInclude, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
28
28
  mergeFilters, mergePollResult, pruneSeen, pruneWakeTimes, pushHistory, recordReported, staleWorktrees, worktreePlan,
29
29
  } from './watch.js'
30
30
 
31
31
  export const name = 'dsh-session-superagent'
32
32
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
33
- export const SERVER_VERSION = '0.8.50'
33
+ export const SERVER_VERSION = '0.8.51'
34
34
  export const inject = ['tools', 'agents', 'webServer']
35
35
 
36
36
  /** 仅供测试:读写状态文件(生产代码不要用)。 */
@@ -437,7 +437,10 @@ function wake(ctx, sessionId, text) {
437
437
  }
438
438
 
439
439
  async function pollOnce(ctx, entry, baseMs) {
440
- const res = await run('gh', ['api', `repos/${entry.repo}/issues?state=all&sort=updated&direction=desc&per_page=20`], { timeoutMs: 45000, env: ghEnv() })
440
+ // 条件请求:带上上次的 ETag,没变化时 GitHub 回 304,且**不计入**速率限制
441
+ const args = ['api', '--include', `repos/${entry.repo}/issues?state=all&sort=updated&direction=desc&per_page=20`]
442
+ if (entry.etag) args.push('-H', 'If-None-Match: ' + entry.etag)
443
+ const res = await run('gh', args, { timeoutMs: 45000, env: ghEnv() })
441
444
  entry.lastPoll = new Date().toISOString()
442
445
  if (res.code !== 0) {
443
446
  const detail = redact(res.stderr).slice(0, 240)
@@ -447,8 +450,18 @@ async function pollOnce(ctx, entry, baseMs) {
447
450
  bumpFailure(entry, baseMs)
448
451
  return
449
452
  }
453
+ const parsed = parseGhInclude(res.stdout)
454
+ if (parsed.status === 304) {
455
+ // 没变化:不解析、不算失败、不重置退避,只记一笔
456
+ entry.lastError = null
457
+ entry.consecutiveFailures = 0
458
+ entry.nextAt = null
459
+ entry.lastDeferred = '未变化(304,不计入速率限制)'
460
+ return
461
+ }
462
+ if (parsed.etag) entry.etag = parsed.etag
450
463
  let items
451
- try { items = JSON.parse(res.stdout) } catch { entry.lastError = 'bad json'; bumpFailure(entry, baseMs); return }
464
+ try { items = JSON.parse(parsed.body) } catch { entry.lastError = 'bad json'; bumpFailure(entry, baseMs); return }
452
465
  if (!Array.isArray(items)) { entry.lastError = 'unexpected payload'; bumpFailure(entry, baseMs); return }
453
466
 
454
467
  entry.lastError = null
package/lib/watch.js CHANGED
@@ -417,3 +417,31 @@ export function classifyGhError(detail) {
417
417
  }
418
418
  return { kind: 'other', short, hint: '' }
419
419
  }
420
+
421
+ /**
422
+ * 解析 `gh api --include` 的输出:状态行 / 响应头 / 空行 / 正文。
423
+ *
424
+ * 为什么用它而不是直接 `gh api`:GitHub 官方文档明确说
425
+ * 「Make authenticated conditional requests, so that unchanged data does not count against
426
+ * your primary rate limit」—— 带上 If-None-Match 后,没变化时拿 304,
427
+ * 304 **不计入**速率限制。对一个每 N 秒轮询的工具,这是最直接的省额度手段。
428
+ *
429
+ * 出处:https://docs.github.com/en/rest/using-the-rest-api/best-practices-for-using-the-rest-api
430
+ */
431
+ export function parseGhInclude(stdout) {
432
+ const text = String(stdout || '')
433
+ const LF = String.fromCharCode(10)
434
+ const blank = LF + LF
435
+ const idx = text.indexOf(blank)
436
+ const head = idx < 0 ? text : text.slice(0, idx)
437
+ const body = idx < 0 ? text.trim() : text.slice(idx + blank.length)
438
+ const lines = head.split(LF)
439
+ // 状态行形如 `HTTP/2.0 200 OK`
440
+ const statusParts = String(lines[0] || '').split(' ')
441
+ const status = Number(statusParts[1]) || 0
442
+ let etag = null
443
+ for (const line of lines) {
444
+ if (line.toLowerCase().startsWith('etag:')) etag = line.slice(5).trim()
445
+ }
446
+ return { status, etag, body }
447
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.8.50",
3
+ "version": "0.8.51",
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",