dsh-session-superagent 0.8.84 → 0.8.86
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 +41 -0
- package/MAINTENANCE.md +1 -1
- package/README.md +2 -2
- package/client.js +16 -2
- package/lib/index.js +23 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,47 @@
|
|
|
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.86] - 2026-11-02 —— SSE 可行性量完了:不改(并发现线上落后 47 个版本)
|
|
6
|
+
|
|
7
|
+
### 学到的(知识库第 35 条)
|
|
8
|
+
本机实测 `/state` 回环往返:
|
|
9
|
+
```
|
|
10
|
+
200: 0.002052s / 0.002166s / 0.002003s(空仓 1815 B)
|
|
11
|
+
```
|
|
12
|
+
720 次/小时 × 2 ms ≈ **1.44 秒/小时**;0.8.85 之后 ≥99% 已是 304。
|
|
13
|
+
|
|
14
|
+
改成 SSE 要付出:长连接生命周期、断线重连、与宿主重载的交互(我们被重载坑过两次)、流上鉴权、
|
|
15
|
+
多面板连接复用 —— 换来的是每小时 1.44 秒。**收益与复杂度严重不成比例,不做。**
|
|
16
|
+
|
|
17
|
+
(0.8.84 减字段 + 0.8.85 条件请求已经吃掉 95% 的空间。)
|
|
18
|
+
|
|
19
|
+
### 顺带发现(重要,已记进 HANDOFF)
|
|
20
|
+
线上 `/state` 的 `serverVersion` 是 **0.8.38**,仓库已到 0.8.86 ——
|
|
21
|
+
服务端改动只有重启宿主才生效,所以最近几十个版本的服务端改进**都还没在真机跑过**。
|
|
22
|
+
按本机铁律重启由用户执行,我只准备核对步骤。
|
|
23
|
+
|
|
24
|
+
## [0.8.85] - 2026-11-02 —— /state 接上 ETag/304:没变化就不重传
|
|
25
|
+
|
|
26
|
+
### 学到的(知识库第 34 条)
|
|
27
|
+
RFC 9110 §15.4.5:304 响应**不带正文**,客户端沿用本地缓存。
|
|
28
|
+
<https://www.rfc-editor.org/rfc/rfc9110.html#section-15.4.5>
|
|
29
|
+
|
|
30
|
+
面板每 5 秒拉一次 `/state`,而 99% 的轮询都是"没变化"。上一轮我们减了单次体积(3.8→2.2 KB),
|
|
31
|
+
这一轮把**没变化时整份重传**这件事也去掉 —— 照搬我们对 GitHub 用的那套,只是方向反过来。
|
|
32
|
+
|
|
33
|
+
### 改了什么
|
|
34
|
+
1. 服务端对响应体算 SHA-1 前 16 位作为 `ETag`;
|
|
35
|
+
2. 客户端把上次的 ETag 放进 `If-None-Match`;
|
|
36
|
+
3. 命中回 **304 空响应**,客户端保持现状(不 setState、不重渲染)。
|
|
37
|
+
|
|
38
|
+
### 踩到的坑
|
|
39
|
+
响应体里有 `updatedAt`(每次都变),直接算指纹的话 **ETag 永不命中**。
|
|
40
|
+
指纹改为基于 `JSON.stringify({ ...stateBody, updatedAt: undefined })`。
|
|
41
|
+
|
|
42
|
+
### 测试
|
|
43
|
+
- 新增 1 例:200 必须带 ETag、同内容回 304 且无正文、ETag 不匹配必须给完整内容。
|
|
44
|
+
- 测试基础设施(`makeReq` / `call`)补了 headers 支持。合计 **134 例**。
|
|
45
|
+
|
|
5
46
|
## [0.8.84] - 2026-11-02 —— 接口做减法:/state 少传 3 个没人读的字段
|
|
6
47
|
|
|
7
48
|
### 怎么找出来的(知识库第 33 条)
|
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`
|
|
12
|
+
- [x] 七个工具可用(github / repo_here / watch_start / watch_status / watch_stop / watch_ack / watch_doctor),`node --test` 134/134 通过
|
|
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)
|
|
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
|
|
|
@@ -99,7 +99,7 @@ dsh plugin install /path/to/dsh-session-superagent
|
|
|
99
99
|
## 开发
|
|
100
100
|
|
|
101
101
|
```sh
|
|
102
|
-
node --test #
|
|
102
|
+
node --test # 134 项单测
|
|
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.
|
|
17
|
+
const CLIENT_VERSION = '0.8.86'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
|
@@ -54,6 +54,9 @@ window.__ModuleLoader__.load({
|
|
|
54
54
|
|
|
55
55
|
const POLL_MS = 5000
|
|
56
56
|
|
|
57
|
+
// 上一次 /state 的 ETag:带上它,没变化时服务端回 304,省掉整份 JSON
|
|
58
|
+
let stateEtag = null
|
|
59
|
+
|
|
57
60
|
async function call(path, options, retried) {
|
|
58
61
|
const init = {
|
|
59
62
|
...(options || {}),
|
|
@@ -73,6 +76,14 @@ window.__ModuleLoader__.load({
|
|
|
73
76
|
await discoverBase()
|
|
74
77
|
return call(path, options, true)
|
|
75
78
|
}
|
|
79
|
+
// 304:内容没变(服务端带 ETag)。不是错误,也没有正文。
|
|
80
|
+
if (res.status === 304) {
|
|
81
|
+
const etag = res.headers && res.headers.get ? res.headers.get('etag') : null
|
|
82
|
+
if (etag) stateEtag = etag
|
|
83
|
+
return { notModified: true }
|
|
84
|
+
}
|
|
85
|
+
const freshEtag = res.headers && res.headers.get ? res.headers.get('etag') : null
|
|
86
|
+
if (freshEtag && path.startsWith('/state')) stateEtag = freshEtag
|
|
76
87
|
const text = await res.text()
|
|
77
88
|
let body = null
|
|
78
89
|
try { body = text ? JSON.parse(text) : null } catch { body = { raw: text } }
|
|
@@ -847,7 +858,10 @@ window.__ModuleLoader__.load({
|
|
|
847
858
|
|
|
848
859
|
const load = useCallback(async () => {
|
|
849
860
|
try {
|
|
850
|
-
const
|
|
861
|
+
const payload = await call('/state', stateEtag ? { headers: { 'if-none-match': stateEtag } } : undefined)
|
|
862
|
+
// 304:内容没变,别白白重渲染
|
|
863
|
+
if (payload && payload.notModified) return null
|
|
864
|
+
const body = payload
|
|
851
865
|
setSnap({ loading: false, error: null, body })
|
|
852
866
|
return body
|
|
853
867
|
} catch (error) {
|
package/lib/index.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* - advance the watermark only after a wake actually landed.
|
|
14
14
|
*/
|
|
15
15
|
import { execFileSync, spawn } from 'node:child_process'
|
|
16
|
-
import { randomUUID } from 'node:crypto'
|
|
16
|
+
import { createHash, randomUUID } from 'node:crypto'
|
|
17
17
|
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from 'node:fs'
|
|
18
18
|
import os, { homedir } from 'node:os'
|
|
19
19
|
import { isAbsolute, join } from 'node:path'
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
|
|
31
31
|
export const name = 'dsh-session-superagent'
|
|
32
32
|
/** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
|
|
33
|
-
export const SERVER_VERSION = '0.8.
|
|
33
|
+
export const SERVER_VERSION = '0.8.86'
|
|
34
34
|
export const inject = ['tools', 'agents', 'webServer']
|
|
35
35
|
|
|
36
36
|
/** 仅供测试:读写状态文件(生产代码不要用)。 */
|
|
@@ -1089,10 +1089,7 @@ export function apply(ctx) {
|
|
|
1089
1089
|
note: w.goal ?? '',
|
|
1090
1090
|
title: sessionTitle(w.sessionId),
|
|
1091
1091
|
}))
|
|
1092
|
-
|
|
1093
|
-
res.setHeader('content-type', 'application/json; charset=utf-8')
|
|
1094
|
-
res.setHeader('cache-control', 'no-store')
|
|
1095
|
-
res.end(JSON.stringify({
|
|
1092
|
+
const stateBody = {
|
|
1096
1093
|
gh,
|
|
1097
1094
|
routeBase: activeBase,
|
|
1098
1095
|
serverVersion: SERVER_VERSION,
|
|
@@ -1105,7 +1102,26 @@ export function apply(ctx) {
|
|
|
1105
1102
|
isolation: isolationReport(Object.values(state.watchers || {})),
|
|
1106
1103
|
sessionTitle: sessionTitle(focusSession),
|
|
1107
1104
|
watchers: watchers.map((w) => ({ ...w, goal: goalView(ctx, w.sessionId) })),
|
|
1108
|
-
}
|
|
1105
|
+
}
|
|
1106
|
+
// ETag/304:面板每 5 秒拉一次 /state,没变化时没必要重传整份 JSON ——
|
|
1107
|
+
// 和我们自己对 GitHub 做的事一样,只是方向反过来(这次我们是服务端)。
|
|
1108
|
+
// 依据:RFC 9110 §15.4.5 规定 304 不带正文,客户端沿用本地缓存。
|
|
1109
|
+
const payload = JSON.stringify(stateBody)
|
|
1110
|
+
// 注意:updatedAt 每次都变,把它排除在指纹之外,否则 ETag 永远不命中
|
|
1111
|
+
const stable = JSON.stringify({ ...stateBody, updatedAt: undefined })
|
|
1112
|
+
const etag = '"' + createHash('sha1').update(stable).digest('hex').slice(0, 16) + '"'
|
|
1113
|
+
res.setHeader('etag', etag)
|
|
1114
|
+
// 测试里的假 req 可能没有 headers,别因此崩
|
|
1115
|
+
const inm = String((req.headers && req.headers['if-none-match']) || '')
|
|
1116
|
+
if (inm && inm.split(',').map((v) => v.trim()).includes(etag)) {
|
|
1117
|
+
res.statusCode = 304
|
|
1118
|
+
res.end()
|
|
1119
|
+
return
|
|
1120
|
+
}
|
|
1121
|
+
res.statusCode = 200
|
|
1122
|
+
res.setHeader('content-type', 'application/json; charset=utf-8')
|
|
1123
|
+
res.setHeader('cache-control', 'no-store')
|
|
1124
|
+
res.end(payload)
|
|
1109
1125
|
},
|
|
1110
1126
|
})
|
|
1111
1127
|
addRoute({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.86",
|
|
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",
|