dsh-session-superagent 0.10.0 → 0.10.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/AGENTS.md +133 -0
- package/CHANGELOG.md +15 -0
- package/README.md +105 -237
- package/SETUP.md +1 -1
- package/UPDATING.md +2 -0
- package/assets/icon-180.png +0 -0
- package/assets/icon-app.png +0 -0
- package/client.js +41 -27
- package/docs//347/234/237/346/234/272/351/252/214/350/257/201/346/270/205/345/215/225.md +65 -0
- package/lib/index.js +124 -26
- package/lib/watch.js +45 -6
- package/package.json +7 -1
package/lib/index.js
CHANGED
|
@@ -21,6 +21,8 @@ import { fileURLToPath } from 'node:url'
|
|
|
21
21
|
|
|
22
22
|
import { zstdDecompressSync } from 'node:zlib'
|
|
23
23
|
|
|
24
|
+
import Schema from '@deepseek-ai/schemastery'
|
|
25
|
+
|
|
24
26
|
import { redact } from './redact.js'
|
|
25
27
|
import { decodeBody, truncateUtf8 } from './body.js'
|
|
26
28
|
import { quotaDeferText, isOfflineMode } from './gh-format.js'
|
|
@@ -29,7 +31,8 @@ import { migrateState, CURRENT_STATE_SCHEMA } from './state-migration.js'
|
|
|
29
31
|
import { runExclusiveUpdate, spawnPluginUpdate, validateUpdateBody } from './update.js'
|
|
30
32
|
import { compareSemver, isStrictSemver } from './semver.js'
|
|
31
33
|
import {
|
|
32
|
-
effectiveIntervalMs, planWakeSettlement, advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, DEFAULT_PRIORITY, formatWatchText,
|
|
34
|
+
effectiveIntervalMs, planWakeSettlement, advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, DEFAULT_BRAND_NAME, DEFAULT_PRIORITY, formatWatchText,
|
|
35
|
+
defaultAckLabelFor, normalizeBrandName,
|
|
33
36
|
recordPendingWake, clearPending, pendingRetry,
|
|
34
37
|
wakeQuality,
|
|
35
38
|
parseRepoSpec, markGiteeReopened,
|
|
@@ -49,7 +52,7 @@ import {
|
|
|
49
52
|
|
|
50
53
|
export const name = 'dsh-session-superagent'
|
|
51
54
|
/** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
|
|
52
|
-
export const SERVER_VERSION = '0.10.
|
|
55
|
+
export const SERVER_VERSION = '0.10.2'
|
|
53
56
|
export const inject = ['tools', 'agents', 'webServer']
|
|
54
57
|
/** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
|
|
55
58
|
// 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
|
|
@@ -61,6 +64,10 @@ function setEntryError(entry, text) {
|
|
|
61
64
|
entry.lastErrorAt = new Date().toISOString()
|
|
62
65
|
}
|
|
63
66
|
const UNCHANGED_TEXT = '未变化(304,不计入速率限制)'
|
|
67
|
+
// GitHub 的 issues 列表 ETag 偶尔不会因为「新增评论」而变化(真机 #11:
|
|
68
|
+
// 18:21 的评论已经改了 updated_at,18:31 带旧 ETag 仍回 304)。
|
|
69
|
+
// 304 不能无限信任:超过这个时长强制一次全量,宁可多花一次请求。
|
|
70
|
+
const ETAG_MAX_AGE_MS = 10 * 60 * 1000
|
|
64
71
|
// Gitee 没有 ETag/304:说「304」会让客户以为在省额度,其实每轮都真读
|
|
65
72
|
const UNCHANGED_TEXT_GITEE = '未变化(Gitee 无 ETag:这一轮是真空读的)'
|
|
66
73
|
// 追溯找不到任何痕迹时的那句话:两个入口(工具 / HTTP)必须一模一样
|
|
@@ -110,11 +117,64 @@ function toolError(args, message) {
|
|
|
110
117
|
}
|
|
111
118
|
/** 全局上限:每条守一个定时器,无限建等于自造 DoS(审核 T19)。 */
|
|
112
119
|
const MAX_WATCHERS_TOTAL = 200
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 插件配置(issue #11):品牌名 + 两家默认 ack 标签。
|
|
123
|
+
*
|
|
124
|
+
* 为什么用官方 schemastery:DSH 的 loader 会在 `apply()` 之前按这份 schema 校验并补默认值,
|
|
125
|
+
* 设置页也直接吃它的 `default` / `description`。手写一遍校验等于把同一套规则维护两次。
|
|
126
|
+
*
|
|
127
|
+
* 三个字段各自独立:`brandName` 只影响抬头与面板标题;两个 ack 标签按 provider 分开,
|
|
128
|
+
* 因为 Gitee 的标签名不允许半角冒号(真机 2026-11-05 实测),默认值本来就不一样。
|
|
129
|
+
*/
|
|
130
|
+
export const Config = Schema.object({
|
|
131
|
+
brandName: Schema.string().default(DEFAULT_BRAND_NAME)
|
|
132
|
+
.description('唤醒抬头与面板标题里的品牌名(默认「' + DEFAULT_BRAND_NAME + '」)'),
|
|
133
|
+
defaultAckLabel: Schema.string().default(DEFAULT_ACK_LABEL)
|
|
134
|
+
.description('新建 GitHub 守的默认已处理标签(默认「' + DEFAULT_ACK_LABEL + '」)'),
|
|
135
|
+
defaultAckLabelGitee: Schema.string().default(DEFAULT_ACK_LABEL_GITEE)
|
|
136
|
+
.description('新建 Gitee 守的默认已处理标签;只能用 Gitee 允许的字符,不能带半角冒号(默认「' + DEFAULT_ACK_LABEL_GITEE + '」)'),
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* ack 标签归一化:trim、空值回落、Gitee 校验非法字符。
|
|
141
|
+
*
|
|
142
|
+
* Gitee 的规则比 GitHub 严(见 lib/gitee.js 的 `isValidGiteeLabel`)——
|
|
143
|
+
* 配一个带半角冒号的值如果不校验,每次 `watch_ack` 都会 404,而错误信息还指向仓库。
|
|
144
|
+
* 宁可回落默认,也不要让整条守废掉。
|
|
145
|
+
*/
|
|
146
|
+
export function normalizeDefaultAckLabel(value, provider, fallback) {
|
|
147
|
+
const text = String(value ?? '').trim()
|
|
148
|
+
if (provider === 'gitee') {
|
|
149
|
+
if (!text || !isValidGiteeLabel(text)) return fallback || DEFAULT_ACK_LABEL_GITEE
|
|
150
|
+
return text
|
|
151
|
+
}
|
|
152
|
+
if (!text) return fallback || DEFAULT_ACK_LABEL
|
|
153
|
+
// 与手工填写的上限一致(watch_start / 面板保存都截 60)
|
|
154
|
+
return text.slice(0, 60)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 把 `apply()` 的 options 归一成运行时品牌配置。
|
|
159
|
+
*
|
|
160
|
+
* 正常情况下 options 是 cordis 用 `Config` 校验后的对象(默认值已补齐);
|
|
161
|
+
* 单测/直接调用会传 `{}` 或只传更新 runner —— 这里必须自己兜住默认值。
|
|
162
|
+
*/
|
|
163
|
+
export function resolveBrandConfig(options = {}) {
|
|
164
|
+
const source = options && typeof options === 'object' ? options : {}
|
|
165
|
+
return Object.freeze({
|
|
166
|
+
brandName: normalizeBrandName(source.brandName),
|
|
167
|
+
defaultAckLabels: Object.freeze({
|
|
168
|
+
github: normalizeDefaultAckLabel(source.defaultAckLabel, 'github', DEFAULT_ACK_LABEL),
|
|
169
|
+
gitee: normalizeDefaultAckLabel(source.defaultAckLabelGitee, 'gitee', DEFAULT_ACK_LABEL_GITEE),
|
|
170
|
+
}),
|
|
171
|
+
})
|
|
172
|
+
}
|
|
113
173
|
/** 隔离区回收的最小间隔:没有超额时不必每次唤醒都跑 git。 */
|
|
114
174
|
const CLEANUP_INTERVAL_MS = 10 * 60 * 1000
|
|
115
175
|
|
|
116
176
|
/** 仅供测试:读写状态文件(生产代码不要用)。 */
|
|
117
|
-
export const __test = { readState, writeState, hardenSecretsFile, wakeMerged, flushWakeQueue, wakeQueueCount, clearWakeQueues, setAuthStatusCache: (text) => { authStatusCache = { at: text ? Date.now() : 0, text } } }
|
|
177
|
+
export const __test = { readState, writeState, hardenSecretsFile, wakeMerged, flushWakeQueue, wakeQueueCount, clearWakeQueues, pollWithItems, setAuthStatusCache: (text) => { authStatusCache = { at: text ? Date.now() : 0, text } } }
|
|
118
178
|
|
|
119
179
|
// 审核 T30:这四个路径以前在**模块加载那一刻**定死 ——
|
|
120
180
|
// 测试里改 `process.env.DSH_SUPERAGENT_STATE` 之后,已经加载的实例仍然指着老目录,
|
|
@@ -217,6 +277,10 @@ function readState() {
|
|
|
217
277
|
// 读取时归一,写盘时自然带走(同 normalizePaused 的思路)。
|
|
218
278
|
function normalizeAckLabel(entry) {
|
|
219
279
|
if (!entry || entry.provider !== 'gitee') return entry
|
|
280
|
+
// issue #11:**没有** ackLabel 的历史守不能在这里补默认值 —— 补了就会把插件配置的
|
|
281
|
+
// `defaultAckLabelGitee` 短路掉(`entry.ackLabel ||` 永远先命中旧默认)。
|
|
282
|
+
// 这里只修「存了一个 Gitee 建不出来的旧标签」,空值留给调用方按配置派生。
|
|
283
|
+
if (typeof entry.ackLabel !== 'string' || !entry.ackLabel.trim()) return entry
|
|
220
284
|
if (!isValidGiteeLabel(entry.ackLabel)) entry.ackLabel = suggestGiteeLabel(entry.ackLabel)
|
|
221
285
|
return entry
|
|
222
286
|
}
|
|
@@ -713,9 +777,12 @@ function run(file, args, options = {}) {
|
|
|
713
777
|
})
|
|
714
778
|
}
|
|
715
779
|
|
|
716
|
-
/**
|
|
717
|
-
|
|
718
|
-
|
|
780
|
+
/**
|
|
781
|
+
* 默认 ack 标签按 provider 走:Gitee 的标签名不允许半角冒号(真机实测拒建)。
|
|
782
|
+
* `labels` 来自插件配置(见 resolveBrandConfig);不传时保持 0.10.0 的默认。
|
|
783
|
+
*/
|
|
784
|
+
function defaultAckLabel(provider, labels) {
|
|
785
|
+
return defaultAckLabelFor(provider, labels)
|
|
719
786
|
}
|
|
720
787
|
|
|
721
788
|
function defineTool(options) {
|
|
@@ -829,7 +896,7 @@ function clearWakeQueues(ctx) {
|
|
|
829
896
|
}
|
|
830
897
|
}
|
|
831
898
|
|
|
832
|
-
function wakeMerged(ctx, sessionId, text, onSettled, queueKey = '') {
|
|
899
|
+
function wakeMerged(ctx, sessionId, text, onSettled, queueKey = '', brandName = DEFAULT_BRAND_NAME) {
|
|
833
900
|
// 同一事件已在队列里时不重复入队;先尝试 flush,空闲时会立即把旧队列送完。
|
|
834
901
|
flushWakeQueue(ctx, sessionId)
|
|
835
902
|
if (hasQueuedWake(sessionId, queueKey, ctx)) {
|
|
@@ -846,7 +913,7 @@ function wakeMerged(ctx, sessionId, text, onSettled, queueKey = '') {
|
|
|
846
913
|
wakeBuffers.delete(sessionId)
|
|
847
914
|
let result = { ok: false, reason: '合并后没有内容可发(这几条都已被处理过)—— 不用管,下一轮会重新判断' }
|
|
848
915
|
try {
|
|
849
|
-
const merged = mergeWakeTexts(buf.parts)
|
|
916
|
+
const merged = mergeWakeTexts(buf.parts, { brandName })
|
|
850
917
|
if (merged) {
|
|
851
918
|
result = wake(ctx, sessionId, merged)
|
|
852
919
|
if (isBusyWakeResult(result)) result = enqueueWake(ctx, sessionId, merged, buf.settled, queueKey)
|
|
@@ -1197,7 +1264,7 @@ async function fetchLastComments(repo, items, maxItems = 3, options = {}) {
|
|
|
1197
1264
|
}))
|
|
1198
1265
|
}
|
|
1199
1266
|
|
|
1200
|
-
async function pollOnce(ctx, entry, baseMs) {
|
|
1267
|
+
async function pollOnce(ctx, entry, baseMs, brand = null) {
|
|
1201
1268
|
// 活跃时段要**在拉 API 之前**判断:以前放在后面,夜里照样每 N 秒打一次 GitHub,纯浪费。
|
|
1202
1269
|
// 不在时段内就把下一次轮询安排到"开门那一刻",攒着的条目不会多等一个周期。
|
|
1203
1270
|
if (entry.activeHours && !inActiveHours(entry.activeHours)) {
|
|
@@ -1270,7 +1337,7 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
1270
1337
|
return
|
|
1271
1338
|
}
|
|
1272
1339
|
// 归一后的条目直接交给共用判定:形状已和 GitHub 一致,后面不该再分两家
|
|
1273
|
-
return pollWithItems(ctx, entry, baseMs, { status: 200, etag: null, body: JSON.stringify(items) })
|
|
1340
|
+
return pollWithItems(ctx, entry, baseMs, { status: 200, etag: null, body: JSON.stringify(items) }, brand)
|
|
1274
1341
|
}
|
|
1275
1342
|
|
|
1276
1343
|
const args = ['api', '--include', `repos/${entry.repo}/issues?state=all&sort=updated&direction=desc&per_page=20`]
|
|
@@ -1349,7 +1416,22 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
1349
1416
|
return
|
|
1350
1417
|
}
|
|
1351
1418
|
if (parsed.status === 304) {
|
|
1352
|
-
//
|
|
1419
|
+
// 没变化:不解析、不算失败、不重置退避,只记一笔。
|
|
1420
|
+
// 但 304 不能无限信任:GitHub 的 issues 列表 ETag 偶尔不因新增评论而变化
|
|
1421
|
+
//(真机 #11:18:21 的评论改了 updated_at,18:31 带旧 ETag 仍 304)。
|
|
1422
|
+
// 超过 10 分钟没全量刷新,就主动丢掉 ETag,下一轮重取。
|
|
1423
|
+
const freshAt = Date.parse(entry.lastFreshAt || '')
|
|
1424
|
+
if (!Number.isFinite(freshAt) || Date.now() - freshAt > ETAG_MAX_AGE_MS) {
|
|
1425
|
+
delete entry.etag
|
|
1426
|
+
entry.lastError = null
|
|
1427
|
+
entry.needsReauth = false
|
|
1428
|
+
entry.consecutiveFailures = 0
|
|
1429
|
+
entry.nextAt = null
|
|
1430
|
+
entry.lastDeferred = 'ETag 可能过期(超过 10 分钟没全量刷新):下一轮强制全量'
|
|
1431
|
+
entry.deferReason = 'etag-stale'
|
|
1432
|
+
noteEvent(entry, 'unchanged', entry.lastDeferred)
|
|
1433
|
+
return
|
|
1434
|
+
}
|
|
1353
1435
|
entry.lastError = null
|
|
1354
1436
|
entry.needsReauth = false
|
|
1355
1437
|
entry.consecutiveFailures = 0
|
|
@@ -1359,11 +1441,13 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
1359
1441
|
noteEvent(entry, 'unchanged', entry.lastDeferred)
|
|
1360
1442
|
return
|
|
1361
1443
|
}
|
|
1444
|
+
// 记下「最后一次真正拿到 200 正文」的时刻:304 超过 10 分钟就不再信任 ETag。
|
|
1445
|
+
entry.lastFreshAt = new Date().toISOString()
|
|
1362
1446
|
// ETag 先存到 pending,确认这一轮真的被消费(或被正当记账)后才前移。
|
|
1363
1447
|
// 原因:下面有多个提前 return 的分支(会话正忙 / 会话上限 / 每小时上限 / 本轮被暂停 / 会话已不在)。
|
|
1364
1448
|
// 它们刻意不动 seen/cursor(注释也写了「否则攒着等于丢掉」),但 ETag 若已前移,
|
|
1365
1449
|
// 下一轮条件请求就会拿到 304 并在上面直接 return,fresh 永远不再重算 —— 效果同样是「攒着=丢掉」。
|
|
1366
|
-
return pollWithItems(ctx, entry, baseMs, parsed)
|
|
1450
|
+
return pollWithItems(ctx, entry, baseMs, parsed, brand)
|
|
1367
1451
|
}
|
|
1368
1452
|
|
|
1369
1453
|
/**
|
|
@@ -1372,7 +1456,7 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
1372
1456
|
* 抽出来是为了让 GitHub 与 Gitee 共用同一套判定 —— 两家只有「怎么拿数据」不同,
|
|
1373
1457
|
* 「要不要叫醒、叫醒说什么、水位怎么走」必须完全一致,否则同一条 bug 要修两遍。
|
|
1374
1458
|
*/
|
|
1375
|
-
async function pollWithItems(ctx, entry, baseMs, parsed) {
|
|
1459
|
+
async function pollWithItems(ctx, entry, baseMs, parsed, brand = null) {
|
|
1376
1460
|
const pendingEtag = parsed.etag
|
|
1377
1461
|
const commitEtag = () => { if (pendingEtag) entry.etag = pendingEtag }
|
|
1378
1462
|
let items
|
|
@@ -1403,7 +1487,7 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
|
|
|
1403
1487
|
// 触发要有许可:过滤器不通过的条目根本不进候选集,也不写 seen 水位
|
|
1404
1488
|
// 记忆要有遗忘:seen 只增不减会问成几 MB 的字典
|
|
1405
1489
|
entry.seen = pruneSeen(entry.seen)
|
|
1406
|
-
const ackLabel = entry.ackLabel || defaultAckLabel(entry.provider)
|
|
1490
|
+
const ackLabel = entry.ackLabel || defaultAckLabel(entry.provider, brand && brand.defaultAckLabels)
|
|
1407
1491
|
// 幂等痕迹留在 GitHub 上:带 ack 标签的条目直接跳过(换机器、删状态都不会重报)
|
|
1408
1492
|
const considered = []
|
|
1409
1493
|
// 每轮重置:这行要被读成「本轮跳过多少」,累计值会越滚越大、误导客户
|
|
@@ -1567,6 +1651,8 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
|
|
|
1567
1651
|
// 此时"有动态"其实是"仓库里本来就有这些待处理",说成新动态会让人以为刚刚发生。
|
|
1568
1652
|
const firstSync = !entry.cursor
|
|
1569
1653
|
const wakeText = formatWatchText(entry.repo, listed, {
|
|
1654
|
+
// 品牌名(issue #11):抬头【…】与面板/诊断共用同一份配置
|
|
1655
|
+
brandName: brand ? brand.brandName : undefined,
|
|
1570
1656
|
more: rest.length,
|
|
1571
1657
|
firstSync,
|
|
1572
1658
|
restNumbers: rest.map((item) => item.number),
|
|
@@ -1643,10 +1729,13 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
|
|
|
1643
1729
|
if (settled.lastDeferred) entry.lastDeferred = settled.lastDeferred
|
|
1644
1730
|
if (settled.bumpBackoff) bumpFailure(entry, baseMs)
|
|
1645
1731
|
} persistEntry(entry)
|
|
1646
|
-
}, wakeQueueKey)
|
|
1732
|
+
}, wakeQueueKey, brand ? brand.brandName : undefined)
|
|
1647
1733
|
}
|
|
1648
1734
|
|
|
1649
1735
|
export function apply(ctx, options = {}) {
|
|
1736
|
+
// 品牌配置(issue #11):options 是 cordis 按 Config 校验后的对象;
|
|
1737
|
+
// 直接调用(单测 / 老宿主)时由 resolveBrandConfig 兜住默认值。
|
|
1738
|
+
const brand = resolveBrandConfig(options)
|
|
1650
1739
|
// 更新 runner 可注入:路由测试绝不发起真实安装;生产默认走 shell:false 的 CLI runner。
|
|
1651
1740
|
const updateRunner = options.updateRunner || spawnPluginUpdate
|
|
1652
1741
|
const updateTimeoutMs = options.updateTimeoutMs
|
|
@@ -1716,7 +1805,7 @@ export function apply(ctx, options = {}) {
|
|
|
1716
1805
|
if (inFlight.has(entry.id)) return
|
|
1717
1806
|
inFlight.add(entry.id)
|
|
1718
1807
|
try {
|
|
1719
|
-
await pollOnce(ctx, entry, every)
|
|
1808
|
+
await pollOnce(ctx, entry, every, brand)
|
|
1720
1809
|
// GitHub 要求的间隔比我们的长:把下一轮推到它之后(成功路径也生效)
|
|
1721
1810
|
const floor = (Number(entry.minIntervalSec) || 0) * 1000
|
|
1722
1811
|
if (floor > every) entry.nextAt = new Date(Date.now() + floor).toISOString()
|
|
@@ -1892,7 +1981,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1892
1981
|
repo: w.repo,
|
|
1893
1982
|
// 面板要能一眼分出 GitHub / Gitee:否则行内只能靠 id 前缀猜
|
|
1894
1983
|
provider: w.provider === 'gitee' ? 'gitee' : 'github',
|
|
1895
|
-
ackLabel: w.ackLabel || defaultAckLabel(w.provider),
|
|
1984
|
+
ackLabel: w.ackLabel || defaultAckLabel(w.provider, brand.defaultAckLabels),
|
|
1896
1985
|
// 会话忙时真正排在 FIFO 里的条数;0 表示没有排队,不靠猜 lastDeferred。
|
|
1897
1986
|
queuedWakes: wakeQueueCount(w.sessionId, ctx),
|
|
1898
1987
|
sessionId: w.sessionId,
|
|
@@ -1968,6 +2057,10 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1968
2057
|
sessionTitle: sessionTitle(focusSession),
|
|
1969
2058
|
retryPolicy: { budgetAttempts: RETRY_BUDGET_ATTEMPTS, slowCapMinutes: RETRY_SLOW_CAP_MINUTES },
|
|
1970
2059
|
defaults: { sessionMaxWakes: DEFAULT_SESSION_WAKES, maxWakesPerHour: DEFAULT_WAKES_PER_HOUR, isolateKeepDays: DEFAULT_ISOLATE_KEEP_DAYS, batchLimit: DEFAULT_BATCH_LIMIT },
|
|
2060
|
+
// issue #11:品牌与两家默认 ack 标签由服务端下发 —— 客户端不再各自写死「主理鱼」。
|
|
2061
|
+
// 放在 stateBody 里就自动进了 ETag 的稳定字段:配置变了,下一次轮询一定不是 304。
|
|
2062
|
+
brandName: brand.brandName,
|
|
2063
|
+
defaultAckLabels: brand.defaultAckLabels,
|
|
1971
2064
|
watchers: watchers.map((w) => ({ ...w, goal: goalView(ctx, w.sessionId) })),
|
|
1972
2065
|
}
|
|
1973
2066
|
// ETag/304:面板每 5 秒拉一次 /state,没变化时没必要重传整份 JSON ——
|
|
@@ -2108,7 +2201,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2108
2201
|
if (inFlight.has(id)) return json(res, 409, { error: '上一轮轮询还没结束(网络慢或 GitHub 慢)—— 等十几秒再看', code: 'in_flight', id })
|
|
2109
2202
|
const every = Math.max(30, Number(entry.intervalSec) || 60) * 1000
|
|
2110
2203
|
inFlight.add(id)
|
|
2111
|
-
pollOnce(ctx, entry, every)
|
|
2204
|
+
pollOnce(ctx, entry, every, brand)
|
|
2112
2205
|
.catch(() => {})
|
|
2113
2206
|
.finally(() => { inFlight.delete(id); persistEntry(entry) })
|
|
2114
2207
|
return json(res, 202, { ok: true, action, id, polling: true })
|
|
@@ -2169,7 +2262,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2169
2262
|
id, repo, provider, sessionId, cursor: null, seen: {}, lastReported: {},
|
|
2170
2263
|
cooldownMs: 180000, createdAt: new Date().toISOString(),
|
|
2171
2264
|
filters: normalizeFilters(), batchLimit: 5, maxWakesPerHour: 6,
|
|
2172
|
-
wakeTimes: [], consecutiveFailures: 0, ackLabel: defaultAckLabel(provider),
|
|
2265
|
+
wakeTimes: [], consecutiveFailures: 0, ackLabel: defaultAckLabel(provider, brand.defaultAckLabels),
|
|
2173
2266
|
isolated: false, workdir: null,
|
|
2174
2267
|
}
|
|
2175
2268
|
entry.provider = provider
|
|
@@ -2574,13 +2667,14 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2574
2667
|
ctx.tools.register(defineTool({
|
|
2575
2668
|
name: 'watch_ack',
|
|
2576
2669
|
description:
|
|
2577
|
-
'Mark an issue/PR as handled: adds the ack label
|
|
2670
|
+
'Mark an issue/PR as handled: adds the ack label (' + brand.defaultAckLabels.github + ' by default on GitHub, '
|
|
2671
|
+
+ brand.defaultAckLabels.gitee + ' on Gitee) and advances the local watermark, so the same item will never wake this session again — even after a restart or on another machine.',
|
|
2578
2672
|
parameters: {
|
|
2579
2673
|
repo: { type: 'string', description: 'owner/name; defaults to the only watched repo' },
|
|
2580
2674
|
// 审核 T32 M4:实现里这两个必填其一(缺了直接报错),schema 却没标。
|
|
2581
2675
|
number: { type: ['number', 'string'], description: 'issue or PR number(Gitee 的编号是字符串,如 IKSQJH)' },
|
|
2582
2676
|
numbers: { type: 'string', description: '逗号分隔的多个编号,如 "12,13,14"(number 与 numbers 至少填一个)' },
|
|
2583
|
-
label: { type: 'string', description: 'ack label, default
|
|
2677
|
+
label: { type: 'string', description: 'ack label, default ' + brand.defaultAckLabels.github + ' on GitHub / ' + brand.defaultAckLabels.gitee + ' on Gitee' },
|
|
2584
2678
|
note: { type: 'string', description: '可选:一句话记下这条最后怎么处理的(如「已修,见 #57」「不修,上游已修」)。下次这条再被叫醒时会带回来,省得会话重新判一遍。' },
|
|
2585
2679
|
comment: { type: 'boolean', description: '把 note 作为评论回写到原 issue/PR(默认 false)。必须同时给 note;这是显式写操作。' },
|
|
2586
2680
|
kind: { type: 'string', description: "Gitee 评论回写时的条目类型:'issue'(默认)或 'pull';GitHub 不需要。" },
|
|
@@ -2606,7 +2700,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2606
2700
|
? watchers.find((w) => w && w.repo === String(args.repo))
|
|
2607
2701
|
: watchers.find((w) => w && w.enabled)
|
|
2608
2702
|
if (!entry) return toolError(args, 'no watcher for that repo — start one with watch_start first')
|
|
2609
|
-
const label = String(args.label || entry.ackLabel || defaultAckLabel(entry.provider))
|
|
2703
|
+
const label = String(args.label || entry.ackLabel || defaultAckLabel(entry.provider, brand.defaultAckLabels))
|
|
2610
2704
|
const note = typeof args.note === 'string' ? args.note.trim().slice(0, 200) : ''
|
|
2611
2705
|
if (args.comment === true && !note) return toolError(args, 'comment:true 需要同时提供 note —— 不会发一条空评论')
|
|
2612
2706
|
// GitHub 不会因为加标签而自动建标签:不存在时返回 422。先幂等建一次(已存在也返回 422,忽略)。
|
|
@@ -2876,7 +2970,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2876
2970
|
}
|
|
2877
2971
|
}
|
|
2878
2972
|
// 3. ack 标签是否存在(两家都要看:Gitee 不会自动建标签,更要说清楚)
|
|
2879
|
-
const label = entry.ackLabel || defaultAckLabel(entry.provider)
|
|
2973
|
+
const label = entry.ackLabel || defaultAckLabel(entry.provider, brand.defaultAckLabels)
|
|
2880
2974
|
if (isGitee) {
|
|
2881
2975
|
// Gitee 的标签必须先存在(watch_ack 会先查再建,但建不出来时要能看出是哪一步)——
|
|
2882
2976
|
// 以前这里只写一句规则,等于没检查。现在真的去查一次。
|
|
@@ -3017,7 +3111,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
3017
3111
|
isolateKeepDays: { type: 'number', description: 'With isolated: remove isolation worktrees older than this many days (1-30, default 3).' },
|
|
3018
3112
|
maxIsolated: { type: 'number', description: 'With isolated: keep at most this many worktrees, oldest removed first (1-50, default 5).' },
|
|
3019
3113
|
goal: { type: 'string', description: 'Optional per-watcher goal appended to the wake message.' },
|
|
3020
|
-
ackLabel: { type: 'string', description: 'Label used as the handled marker (default
|
|
3114
|
+
ackLabel: { type: 'string', description: 'Label used as the handled marker (default ' + brand.defaultAckLabels.github + ' on GitHub / ' + brand.defaultAckLabels.gitee + ' on Gitee). Two sessions watching the same repo share it unless each sets its own.' },
|
|
3021
3115
|
priority: { type: 'object', description: 'Priority switches; only explicitly supplied keys are changed. Boolean keys: reopened, comments, labels, unassigned, stale. Defaults: reopened/comments/labels=true; unassigned/stale=false. additionalProperties are unrestricted.' },
|
|
3022
3116
|
},
|
|
3023
3117
|
async execute(args) {
|
|
@@ -3052,7 +3146,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
3052
3146
|
id, repo, provider, sessionId,
|
|
3053
3147
|
intervalSec: 60,
|
|
3054
3148
|
cooldownMs: DEFAULT_COOLDOWN_MS,
|
|
3055
|
-
ackLabel: defaultAckLabel(provider),
|
|
3149
|
+
ackLabel: defaultAckLabel(provider, brand.defaultAckLabels),
|
|
3056
3150
|
priority: { ...DEFAULT_TOOL_PRIORITY },
|
|
3057
3151
|
cursor: null,
|
|
3058
3152
|
seen: {},
|
|
@@ -3210,7 +3304,11 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
3210
3304
|
const wsAgent = wsAgents && typeof wsAgents.currentInitiator === 'function' ? wsAgents.currentInitiator() : undefined
|
|
3211
3305
|
const wsSessionId = (wsAgent && wsAgent.id) || undefined
|
|
3212
3306
|
// 同一份数据:结构化视图 -> 文本只是它的一种渲染,两边永远对得上
|
|
3213
|
-
const view = statusView(list,
|
|
3307
|
+
const view = statusView(list, {
|
|
3308
|
+
...(wsSessionId ? { sessionId: wsSessionId } : {}),
|
|
3309
|
+
// 状态视图里的默认 ack 与 /state 同源(issue #11)
|
|
3310
|
+
defaultAckLabels: brand.defaultAckLabels,
|
|
3311
|
+
})
|
|
3214
3312
|
if (args && args.format === 'json') return JSON.stringify(view, null, 2)
|
|
3215
3313
|
// 默认只写「这条守是什么」;只有当它需要你注意时才追加原因。
|
|
3216
3314
|
// 以前每行都带 lastPoll/lastWake/err=-,十条守就是十行长日志。
|
package/lib/watch.js
CHANGED
|
@@ -5,6 +5,30 @@
|
|
|
5
5
|
* is allowed, what the wake text says) is unit-testable without a DSH host.
|
|
6
6
|
*/
|
|
7
7
|
import { repoBadges, classifyGhError } from './gh-format.js'
|
|
8
|
+
// Gitee 的标签名不允许半角冒号,它的默认 ack 与 GitHub 不同。
|
|
9
|
+
// 这里只取常量,不碰网络:gitee.js 的顶层没有任何副作用。
|
|
10
|
+
import { DEFAULT_ACK_LABEL_GITEE } from './gitee.js'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 品牌名的唯一默认值(issue #11)。
|
|
14
|
+
*
|
|
15
|
+
* 它出现在两处**结构性**文本里:唤醒抬头的「【品牌】…」和合并抬头的「【品牌】这一小段时间内…」。
|
|
16
|
+
* 这两处是会话解析消息的依据,所以默认值必须与 0.10.0 完全一致;
|
|
17
|
+
* 只有插件 Config 明确改了 `brandName` 时才换。
|
|
18
|
+
*/
|
|
19
|
+
export const DEFAULT_BRAND_NAME = '主理鱼'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 归一化品牌名:trim、压平换行、空值回落默认。
|
|
23
|
+
*
|
|
24
|
+
* 抬头是**单行**结构(`【品牌】<repo> 有 N 条新动态:`)。品牌名里夹一个换行,
|
|
25
|
+
* 整段就会变成两行,看起来像第二条消息 —— 外部可配的文本必须先压平再进结构。
|
|
26
|
+
*/
|
|
27
|
+
export function normalizeBrandName(value, fallback = DEFAULT_BRAND_NAME) {
|
|
28
|
+
const text = String(value ?? '').trim()
|
|
29
|
+
if (!text) return fallback
|
|
30
|
+
return text.replace(/[\r\n]+/g, ' ')
|
|
31
|
+
}
|
|
8
32
|
|
|
9
33
|
/**
|
|
10
34
|
* Split items into "report now" and "absorb silently".
|
|
@@ -139,6 +163,7 @@ export function wakeCriteria({ isolation } = {}) {
|
|
|
139
163
|
*/
|
|
140
164
|
export function buildWakeSections(repo, items, options = {}) {
|
|
141
165
|
const list = items ?? []
|
|
166
|
+
const brandName = normalizeBrandName(options.brandName)
|
|
142
167
|
const more = Number(options.more) || 0
|
|
143
168
|
const lines = list.map((item) => {
|
|
144
169
|
const kind = item.pull_request ? 'PR' : 'issue'
|
|
@@ -262,8 +287,8 @@ export function buildWakeSections(repo, items, options = {}) {
|
|
|
262
287
|
? ['【完成标准】', ...criteria.map((line, i) => (i + 1) + '. ' + line)]
|
|
263
288
|
: []
|
|
264
289
|
const headerLine = options.firstSync
|
|
265
|
-
?
|
|
266
|
-
:
|
|
290
|
+
? `【${brandName}】${repo} 首次同步:仓库里现有 ${lines.length} 条待处理(接上之前就在的,不是刚刚发生):`
|
|
291
|
+
: `【${brandName}】${repo} 有 ${lines.length} 条新动态:`
|
|
267
292
|
const nextLine = '接下来:先读仓库 AGENTS.md 定「修 / 回 / 待定」;没有测试结果不算完成;'
|
|
268
293
|
+ (options.provider === 'gitee'
|
|
269
294
|
// Gitee 没有 gh CLI:回写走网页/API,别让会话去跑 gh 命令
|
|
@@ -668,7 +693,7 @@ export const POLL_RESULT_FIELDS = [
|
|
|
668
693
|
// 最关键的是 etag —— 丢了它,条件请求永远带不上,每轮都在全量拉;
|
|
669
694
|
// 其次是 needsReauth / lastErrorAt —— doctor 的「凭证失效」分支永远不会触发。
|
|
670
695
|
// 教训:白名单是**手维护的**,新增字段时必须同时加进来,否则「算出来了但没存」。
|
|
671
|
-
'etag', 'needsReauth', 'lastErrorAt', 'deferReason', 'silentWakes', 'prevWakeAt',
|
|
696
|
+
'etag', 'lastFreshAt', 'needsReauth', 'lastErrorAt', 'deferReason', 'silentWakes', 'prevWakeAt',
|
|
672
697
|
'dailyWakes', 'absorbedLog', 'filterCounts', 'repoAccess', 'sessionMissingSince',
|
|
673
698
|
'minIntervalSec', 'lastCleanupAt',
|
|
674
699
|
// 「叫醒之后」的两块记录:漏了它们,ack 留的话和「提过没回执」都会在写盘时被静默丢掉
|
|
@@ -832,7 +857,7 @@ export function sessionWakesLastHour(entries, sessionId, now = Date.now()) {
|
|
|
832
857
|
*
|
|
833
858
|
* 合并而不是"设个间隔挡掉":硬间隔会让先到的守永远赢,后面的守被饿死。
|
|
834
859
|
*/
|
|
835
|
-
export function mergeWakeTexts(parts) {
|
|
860
|
+
export function mergeWakeTexts(parts, options = {}) {
|
|
836
861
|
const list = (Array.isArray(parts) ? parts : []).filter((t) => typeof t === 'string' && t.trim())
|
|
837
862
|
if (list.length === 0) return ''
|
|
838
863
|
if (list.length === 1) return list[0]
|
|
@@ -878,7 +903,8 @@ export function mergeWakeTexts(parts) {
|
|
|
878
903
|
return at < 0 ? text : text.slice(0, at).replace(/[\s]+$/, '')
|
|
879
904
|
})
|
|
880
905
|
|
|
881
|
-
const
|
|
906
|
+
const brandName = normalizeBrandName(options && options.brandName)
|
|
907
|
+
const head = '【' + brandName + '】这一小段时间内有 ' + list.length + ' 处变化,合并成一条:'
|
|
882
908
|
const body = stripped.map((text, i) => String.fromCharCode(10, 10) + '—— 第 ' + (i + 1) + ' 处 ——' + String.fromCharCode(10) + text).join('')
|
|
883
909
|
return head + body + (tailBlock ? String.fromCharCode(10, 10) + tailBlock : '')
|
|
884
910
|
}
|
|
@@ -1132,6 +1158,19 @@ export function busierThanUsual(summary, { factor = 2, minDays = 3 } = {}) {
|
|
|
1132
1158
|
return today >= avg * Math.max(1.5, Number(factor) || 2)
|
|
1133
1159
|
}
|
|
1134
1160
|
|
|
1161
|
+
/**
|
|
1162
|
+
* 默认 ack 标签(issue #11):GitHub 用 `主理鱼:已处理`,Gitee 因为标签名不允许半角冒号用
|
|
1163
|
+
* `主理鱼-已处理`。品牌配置可以从 `labels` 传进来;不传时保持 0.10.0 的默认。
|
|
1164
|
+
*
|
|
1165
|
+
* @param {'github'|'gitee'|undefined} provider
|
|
1166
|
+
* @param {{github?: string, gitee?: string}} [labels]
|
|
1167
|
+
*/
|
|
1168
|
+
export function defaultAckLabelFor(provider, labels) {
|
|
1169
|
+
const map = labels && typeof labels === 'object' ? labels : null
|
|
1170
|
+
if (provider === 'gitee') return (map && map.gitee) || DEFAULT_ACK_LABEL_GITEE
|
|
1171
|
+
return (map && map.github) || DEFAULT_ACK_LABEL
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1135
1174
|
/**
|
|
1136
1175
|
* `watch_status` 的结构化视图:同一份数据,既能渲染成人读的文本,也能给 agent 解析。
|
|
1137
1176
|
*
|
|
@@ -1172,7 +1211,7 @@ export function statusView(entries, options = {}) {
|
|
|
1172
1211
|
sessionMaxWakes: w.sessionMaxWakes ?? 12,
|
|
1173
1212
|
isolateKeepDays: w.isolateKeepDays ?? 3,
|
|
1174
1213
|
maxIsolated: w.maxIsolated ?? 5,
|
|
1175
|
-
ackLabel: w.ackLabel ??
|
|
1214
|
+
ackLabel: w.ackLabel ?? defaultAckLabelFor(w.provider, options.defaultAckLabels),
|
|
1176
1215
|
workdir: w.workdir ?? null,
|
|
1177
1216
|
// 补齐缺省开关,同时保留面板写入的 stale 等扩展项;拷贝对象避免共享引用。
|
|
1178
1217
|
priority: { ...DEFAULT_PRIORITY, ...((w.priority && typeof w.priority === 'object' && !Array.isArray(w.priority)) ? w.priority : {}) },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.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",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"lib/semver.js",
|
|
26
26
|
"cordis.patch.yml",
|
|
27
27
|
"README.md",
|
|
28
|
+
"AGENTS.md",
|
|
28
29
|
"SETUP.md",
|
|
29
30
|
"CHANGELOG.md",
|
|
30
31
|
"LICENSE",
|
|
@@ -33,8 +34,10 @@
|
|
|
33
34
|
"ui-orbit-popover.js",
|
|
34
35
|
"bin/check.mjs",
|
|
35
36
|
"assets/icon-180.png",
|
|
37
|
+
"assets/icon-app.png",
|
|
36
38
|
"docs/whats-new-0.9.md",
|
|
37
39
|
"docs/json-契约.md",
|
|
40
|
+
"docs/真机验证清单.md",
|
|
38
41
|
"UPDATING.md",
|
|
39
42
|
"CHECKLIST.md",
|
|
40
43
|
"MAINTENANCE.md"
|
|
@@ -100,5 +103,8 @@
|
|
|
100
103
|
},
|
|
101
104
|
"devDependencies": {
|
|
102
105
|
"semver": "7.8.6"
|
|
106
|
+
},
|
|
107
|
+
"dependencies": {
|
|
108
|
+
"@deepseek-ai/schemastery": "3.18.5"
|
|
103
109
|
}
|
|
104
110
|
}
|