dsh-session-superagent 0.9.286 → 0.10.1

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/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.9.286'
55
+ export const SERVER_VERSION = '0.10.1'
53
56
  export const inject = ['tools', 'agents', 'webServer']
54
57
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
55
58
  // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
@@ -110,11 +113,64 @@ function toolError(args, message) {
110
113
  }
111
114
  /** 全局上限:每条守一个定时器,无限建等于自造 DoS(审核 T19)。 */
112
115
  const MAX_WATCHERS_TOTAL = 200
116
+
117
+ /**
118
+ * 插件配置(issue #11):品牌名 + 两家默认 ack 标签。
119
+ *
120
+ * 为什么用官方 schemastery:DSH 的 loader 会在 `apply()` 之前按这份 schema 校验并补默认值,
121
+ * 设置页也直接吃它的 `default` / `description`。手写一遍校验等于把同一套规则维护两次。
122
+ *
123
+ * 三个字段各自独立:`brandName` 只影响抬头与面板标题;两个 ack 标签按 provider 分开,
124
+ * 因为 Gitee 的标签名不允许半角冒号(真机 2026-11-05 实测),默认值本来就不一样。
125
+ */
126
+ export const Config = Schema.object({
127
+ brandName: Schema.string().default(DEFAULT_BRAND_NAME)
128
+ .description('唤醒抬头与面板标题里的品牌名(默认「' + DEFAULT_BRAND_NAME + '」)'),
129
+ defaultAckLabel: Schema.string().default(DEFAULT_ACK_LABEL)
130
+ .description('新建 GitHub 守的默认已处理标签(默认「' + DEFAULT_ACK_LABEL + '」)'),
131
+ defaultAckLabelGitee: Schema.string().default(DEFAULT_ACK_LABEL_GITEE)
132
+ .description('新建 Gitee 守的默认已处理标签;只能用 Gitee 允许的字符,不能带半角冒号(默认「' + DEFAULT_ACK_LABEL_GITEE + '」)'),
133
+ })
134
+
135
+ /**
136
+ * ack 标签归一化:trim、空值回落、Gitee 校验非法字符。
137
+ *
138
+ * Gitee 的规则比 GitHub 严(见 lib/gitee.js 的 `isValidGiteeLabel`)——
139
+ * 配一个带半角冒号的值如果不校验,每次 `watch_ack` 都会 404,而错误信息还指向仓库。
140
+ * 宁可回落默认,也不要让整条守废掉。
141
+ */
142
+ export function normalizeDefaultAckLabel(value, provider, fallback) {
143
+ const text = String(value ?? '').trim()
144
+ if (provider === 'gitee') {
145
+ if (!text || !isValidGiteeLabel(text)) return fallback || DEFAULT_ACK_LABEL_GITEE
146
+ return text
147
+ }
148
+ if (!text) return fallback || DEFAULT_ACK_LABEL
149
+ // 与手工填写的上限一致(watch_start / 面板保存都截 60)
150
+ return text.slice(0, 60)
151
+ }
152
+
153
+ /**
154
+ * 把 `apply()` 的 options 归一成运行时品牌配置。
155
+ *
156
+ * 正常情况下 options 是 cordis 用 `Config` 校验后的对象(默认值已补齐);
157
+ * 单测/直接调用会传 `{}` 或只传更新 runner —— 这里必须自己兜住默认值。
158
+ */
159
+ export function resolveBrandConfig(options = {}) {
160
+ const source = options && typeof options === 'object' ? options : {}
161
+ return Object.freeze({
162
+ brandName: normalizeBrandName(source.brandName),
163
+ defaultAckLabels: Object.freeze({
164
+ github: normalizeDefaultAckLabel(source.defaultAckLabel, 'github', DEFAULT_ACK_LABEL),
165
+ gitee: normalizeDefaultAckLabel(source.defaultAckLabelGitee, 'gitee', DEFAULT_ACK_LABEL_GITEE),
166
+ }),
167
+ })
168
+ }
113
169
  /** 隔离区回收的最小间隔:没有超额时不必每次唤醒都跑 git。 */
114
170
  const CLEANUP_INTERVAL_MS = 10 * 60 * 1000
115
171
 
116
172
  /** 仅供测试:读写状态文件(生产代码不要用)。 */
117
- export const __test = { readState, writeState, hardenSecretsFile, wakeMerged, flushWakeQueue, wakeQueueCount, clearWakeQueues, setAuthStatusCache: (text) => { authStatusCache = { at: text ? Date.now() : 0, text } } }
173
+ export const __test = { readState, writeState, hardenSecretsFile, wakeMerged, flushWakeQueue, wakeQueueCount, clearWakeQueues, pollWithItems, setAuthStatusCache: (text) => { authStatusCache = { at: text ? Date.now() : 0, text } } }
118
174
 
119
175
  // 审核 T30:这四个路径以前在**模块加载那一刻**定死 ——
120
176
  // 测试里改 `process.env.DSH_SUPERAGENT_STATE` 之后,已经加载的实例仍然指着老目录,
@@ -217,6 +273,10 @@ function readState() {
217
273
  // 读取时归一,写盘时自然带走(同 normalizePaused 的思路)。
218
274
  function normalizeAckLabel(entry) {
219
275
  if (!entry || entry.provider !== 'gitee') return entry
276
+ // issue #11:**没有** ackLabel 的历史守不能在这里补默认值 —— 补了就会把插件配置的
277
+ // `defaultAckLabelGitee` 短路掉(`entry.ackLabel ||` 永远先命中旧默认)。
278
+ // 这里只修「存了一个 Gitee 建不出来的旧标签」,空值留给调用方按配置派生。
279
+ if (typeof entry.ackLabel !== 'string' || !entry.ackLabel.trim()) return entry
220
280
  if (!isValidGiteeLabel(entry.ackLabel)) entry.ackLabel = suggestGiteeLabel(entry.ackLabel)
221
281
  return entry
222
282
  }
@@ -713,9 +773,12 @@ function run(file, args, options = {}) {
713
773
  })
714
774
  }
715
775
 
716
- /** 默认 ack 标签按 provider 走:Gitee 的标签名不允许半角冒号(真机实测拒建)。 */
717
- function defaultAckLabel(provider) {
718
- return provider === 'gitee' ? DEFAULT_ACK_LABEL_GITEE : DEFAULT_ACK_LABEL
776
+ /**
777
+ * 默认 ack 标签按 provider 走:Gitee 的标签名不允许半角冒号(真机实测拒建)。
778
+ * `labels` 来自插件配置(见 resolveBrandConfig);不传时保持 0.10.0 的默认。
779
+ */
780
+ function defaultAckLabel(provider, labels) {
781
+ return defaultAckLabelFor(provider, labels)
719
782
  }
720
783
 
721
784
  function defineTool(options) {
@@ -829,7 +892,7 @@ function clearWakeQueues(ctx) {
829
892
  }
830
893
  }
831
894
 
832
- function wakeMerged(ctx, sessionId, text, onSettled, queueKey = '') {
895
+ function wakeMerged(ctx, sessionId, text, onSettled, queueKey = '', brandName = DEFAULT_BRAND_NAME) {
833
896
  // 同一事件已在队列里时不重复入队;先尝试 flush,空闲时会立即把旧队列送完。
834
897
  flushWakeQueue(ctx, sessionId)
835
898
  if (hasQueuedWake(sessionId, queueKey, ctx)) {
@@ -846,7 +909,7 @@ function wakeMerged(ctx, sessionId, text, onSettled, queueKey = '') {
846
909
  wakeBuffers.delete(sessionId)
847
910
  let result = { ok: false, reason: '合并后没有内容可发(这几条都已被处理过)—— 不用管,下一轮会重新判断' }
848
911
  try {
849
- const merged = mergeWakeTexts(buf.parts)
912
+ const merged = mergeWakeTexts(buf.parts, { brandName })
850
913
  if (merged) {
851
914
  result = wake(ctx, sessionId, merged)
852
915
  if (isBusyWakeResult(result)) result = enqueueWake(ctx, sessionId, merged, buf.settled, queueKey)
@@ -1197,7 +1260,7 @@ async function fetchLastComments(repo, items, maxItems = 3, options = {}) {
1197
1260
  }))
1198
1261
  }
1199
1262
 
1200
- async function pollOnce(ctx, entry, baseMs) {
1263
+ async function pollOnce(ctx, entry, baseMs, brand = null) {
1201
1264
  // 活跃时段要**在拉 API 之前**判断:以前放在后面,夜里照样每 N 秒打一次 GitHub,纯浪费。
1202
1265
  // 不在时段内就把下一次轮询安排到"开门那一刻",攒着的条目不会多等一个周期。
1203
1266
  if (entry.activeHours && !inActiveHours(entry.activeHours)) {
@@ -1270,7 +1333,7 @@ async function pollOnce(ctx, entry, baseMs) {
1270
1333
  return
1271
1334
  }
1272
1335
  // 归一后的条目直接交给共用判定:形状已和 GitHub 一致,后面不该再分两家
1273
- return pollWithItems(ctx, entry, baseMs, { status: 200, etag: null, body: JSON.stringify(items) })
1336
+ return pollWithItems(ctx, entry, baseMs, { status: 200, etag: null, body: JSON.stringify(items) }, brand)
1274
1337
  }
1275
1338
 
1276
1339
  const args = ['api', '--include', `repos/${entry.repo}/issues?state=all&sort=updated&direction=desc&per_page=20`]
@@ -1363,7 +1426,7 @@ async function pollOnce(ctx, entry, baseMs) {
1363
1426
  // 原因:下面有多个提前 return 的分支(会话正忙 / 会话上限 / 每小时上限 / 本轮被暂停 / 会话已不在)。
1364
1427
  // 它们刻意不动 seen/cursor(注释也写了「否则攒着等于丢掉」),但 ETag 若已前移,
1365
1428
  // 下一轮条件请求就会拿到 304 并在上面直接 return,fresh 永远不再重算 —— 效果同样是「攒着=丢掉」。
1366
- return pollWithItems(ctx, entry, baseMs, parsed)
1429
+ return pollWithItems(ctx, entry, baseMs, parsed, brand)
1367
1430
  }
1368
1431
 
1369
1432
  /**
@@ -1372,7 +1435,7 @@ async function pollOnce(ctx, entry, baseMs) {
1372
1435
  * 抽出来是为了让 GitHub 与 Gitee 共用同一套判定 —— 两家只有「怎么拿数据」不同,
1373
1436
  * 「要不要叫醒、叫醒说什么、水位怎么走」必须完全一致,否则同一条 bug 要修两遍。
1374
1437
  */
1375
- async function pollWithItems(ctx, entry, baseMs, parsed) {
1438
+ async function pollWithItems(ctx, entry, baseMs, parsed, brand = null) {
1376
1439
  const pendingEtag = parsed.etag
1377
1440
  const commitEtag = () => { if (pendingEtag) entry.etag = pendingEtag }
1378
1441
  let items
@@ -1403,7 +1466,7 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
1403
1466
  // 触发要有许可:过滤器不通过的条目根本不进候选集,也不写 seen 水位
1404
1467
  // 记忆要有遗忘:seen 只增不减会问成几 MB 的字典
1405
1468
  entry.seen = pruneSeen(entry.seen)
1406
- const ackLabel = entry.ackLabel || defaultAckLabel(entry.provider)
1469
+ const ackLabel = entry.ackLabel || defaultAckLabel(entry.provider, brand && brand.defaultAckLabels)
1407
1470
  // 幂等痕迹留在 GitHub 上:带 ack 标签的条目直接跳过(换机器、删状态都不会重报)
1408
1471
  const considered = []
1409
1472
  // 每轮重置:这行要被读成「本轮跳过多少」,累计值会越滚越大、误导客户
@@ -1567,6 +1630,8 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
1567
1630
  // 此时"有动态"其实是"仓库里本来就有这些待处理",说成新动态会让人以为刚刚发生。
1568
1631
  const firstSync = !entry.cursor
1569
1632
  const wakeText = formatWatchText(entry.repo, listed, {
1633
+ // 品牌名(issue #11):抬头【…】与面板/诊断共用同一份配置
1634
+ brandName: brand ? brand.brandName : undefined,
1570
1635
  more: rest.length,
1571
1636
  firstSync,
1572
1637
  restNumbers: rest.map((item) => item.number),
@@ -1643,10 +1708,13 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
1643
1708
  if (settled.lastDeferred) entry.lastDeferred = settled.lastDeferred
1644
1709
  if (settled.bumpBackoff) bumpFailure(entry, baseMs)
1645
1710
  } persistEntry(entry)
1646
- }, wakeQueueKey)
1711
+ }, wakeQueueKey, brand ? brand.brandName : undefined)
1647
1712
  }
1648
1713
 
1649
1714
  export function apply(ctx, options = {}) {
1715
+ // 品牌配置(issue #11):options 是 cordis 按 Config 校验后的对象;
1716
+ // 直接调用(单测 / 老宿主)时由 resolveBrandConfig 兜住默认值。
1717
+ const brand = resolveBrandConfig(options)
1650
1718
  // 更新 runner 可注入:路由测试绝不发起真实安装;生产默认走 shell:false 的 CLI runner。
1651
1719
  const updateRunner = options.updateRunner || spawnPluginUpdate
1652
1720
  const updateTimeoutMs = options.updateTimeoutMs
@@ -1716,7 +1784,7 @@ export function apply(ctx, options = {}) {
1716
1784
  if (inFlight.has(entry.id)) return
1717
1785
  inFlight.add(entry.id)
1718
1786
  try {
1719
- await pollOnce(ctx, entry, every)
1787
+ await pollOnce(ctx, entry, every, brand)
1720
1788
  // GitHub 要求的间隔比我们的长:把下一轮推到它之后(成功路径也生效)
1721
1789
  const floor = (Number(entry.minIntervalSec) || 0) * 1000
1722
1790
  if (floor > every) entry.nextAt = new Date(Date.now() + floor).toISOString()
@@ -1892,7 +1960,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
1892
1960
  repo: w.repo,
1893
1961
  // 面板要能一眼分出 GitHub / Gitee:否则行内只能靠 id 前缀猜
1894
1962
  provider: w.provider === 'gitee' ? 'gitee' : 'github',
1895
- ackLabel: w.ackLabel || defaultAckLabel(w.provider),
1963
+ ackLabel: w.ackLabel || defaultAckLabel(w.provider, brand.defaultAckLabels),
1896
1964
  // 会话忙时真正排在 FIFO 里的条数;0 表示没有排队,不靠猜 lastDeferred。
1897
1965
  queuedWakes: wakeQueueCount(w.sessionId, ctx),
1898
1966
  sessionId: w.sessionId,
@@ -1968,6 +2036,10 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
1968
2036
  sessionTitle: sessionTitle(focusSession),
1969
2037
  retryPolicy: { budgetAttempts: RETRY_BUDGET_ATTEMPTS, slowCapMinutes: RETRY_SLOW_CAP_MINUTES },
1970
2038
  defaults: { sessionMaxWakes: DEFAULT_SESSION_WAKES, maxWakesPerHour: DEFAULT_WAKES_PER_HOUR, isolateKeepDays: DEFAULT_ISOLATE_KEEP_DAYS, batchLimit: DEFAULT_BATCH_LIMIT },
2039
+ // issue #11:品牌与两家默认 ack 标签由服务端下发 —— 客户端不再各自写死「主理鱼」。
2040
+ // 放在 stateBody 里就自动进了 ETag 的稳定字段:配置变了,下一次轮询一定不是 304。
2041
+ brandName: brand.brandName,
2042
+ defaultAckLabels: brand.defaultAckLabels,
1971
2043
  watchers: watchers.map((w) => ({ ...w, goal: goalView(ctx, w.sessionId) })),
1972
2044
  }
1973
2045
  // ETag/304:面板每 5 秒拉一次 /state,没变化时没必要重传整份 JSON ——
@@ -2108,7 +2180,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2108
2180
  if (inFlight.has(id)) return json(res, 409, { error: '上一轮轮询还没结束(网络慢或 GitHub 慢)—— 等十几秒再看', code: 'in_flight', id })
2109
2181
  const every = Math.max(30, Number(entry.intervalSec) || 60) * 1000
2110
2182
  inFlight.add(id)
2111
- pollOnce(ctx, entry, every)
2183
+ pollOnce(ctx, entry, every, brand)
2112
2184
  .catch(() => {})
2113
2185
  .finally(() => { inFlight.delete(id); persistEntry(entry) })
2114
2186
  return json(res, 202, { ok: true, action, id, polling: true })
@@ -2169,7 +2241,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2169
2241
  id, repo, provider, sessionId, cursor: null, seen: {}, lastReported: {},
2170
2242
  cooldownMs: 180000, createdAt: new Date().toISOString(),
2171
2243
  filters: normalizeFilters(), batchLimit: 5, maxWakesPerHour: 6,
2172
- wakeTimes: [], consecutiveFailures: 0, ackLabel: defaultAckLabel(provider),
2244
+ wakeTimes: [], consecutiveFailures: 0, ackLabel: defaultAckLabel(provider, brand.defaultAckLabels),
2173
2245
  isolated: false, workdir: null,
2174
2246
  }
2175
2247
  entry.provider = provider
@@ -2574,13 +2646,14 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2574
2646
  ctx.tools.register(defineTool({
2575
2647
  name: 'watch_ack',
2576
2648
  description:
2577
- 'Mark an issue/PR as handled: adds the ack label on GitHub (主理鱼:已处理 by default) and advances the local watermark, so the same item will never wake this session again — even after a restart or on another machine.',
2649
+ 'Mark an issue/PR as handled: adds the ack label (' + brand.defaultAckLabels.github + ' by default on GitHub, '
2650
+ + 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
2651
  parameters: {
2579
2652
  repo: { type: 'string', description: 'owner/name; defaults to the only watched repo' },
2580
2653
  // 审核 T32 M4:实现里这两个必填其一(缺了直接报错),schema 却没标。
2581
2654
  number: { type: ['number', 'string'], description: 'issue or PR number(Gitee 的编号是字符串,如 IKSQJH)' },
2582
2655
  numbers: { type: 'string', description: '逗号分隔的多个编号,如 "12,13,14"(number 与 numbers 至少填一个)' },
2583
- label: { type: 'string', description: 'ack label, default 主理鱼:已处理' },
2656
+ label: { type: 'string', description: 'ack label, default ' + brand.defaultAckLabels.github + ' on GitHub / ' + brand.defaultAckLabels.gitee + ' on Gitee' },
2584
2657
  note: { type: 'string', description: '可选:一句话记下这条最后怎么处理的(如「已修,见 #57」「不修,上游已修」)。下次这条再被叫醒时会带回来,省得会话重新判一遍。' },
2585
2658
  comment: { type: 'boolean', description: '把 note 作为评论回写到原 issue/PR(默认 false)。必须同时给 note;这是显式写操作。' },
2586
2659
  kind: { type: 'string', description: "Gitee 评论回写时的条目类型:'issue'(默认)或 'pull';GitHub 不需要。" },
@@ -2606,7 +2679,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2606
2679
  ? watchers.find((w) => w && w.repo === String(args.repo))
2607
2680
  : watchers.find((w) => w && w.enabled)
2608
2681
  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))
2682
+ const label = String(args.label || entry.ackLabel || defaultAckLabel(entry.provider, brand.defaultAckLabels))
2610
2683
  const note = typeof args.note === 'string' ? args.note.trim().slice(0, 200) : ''
2611
2684
  if (args.comment === true && !note) return toolError(args, 'comment:true 需要同时提供 note —— 不会发一条空评论')
2612
2685
  // GitHub 不会因为加标签而自动建标签:不存在时返回 422。先幂等建一次(已存在也返回 422,忽略)。
@@ -2876,7 +2949,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2876
2949
  }
2877
2950
  }
2878
2951
  // 3. ack 标签是否存在(两家都要看:Gitee 不会自动建标签,更要说清楚)
2879
- const label = entry.ackLabel || defaultAckLabel(entry.provider)
2952
+ const label = entry.ackLabel || defaultAckLabel(entry.provider, brand.defaultAckLabels)
2880
2953
  if (isGitee) {
2881
2954
  // Gitee 的标签必须先存在(watch_ack 会先查再建,但建不出来时要能看出是哪一步)——
2882
2955
  // 以前这里只写一句规则,等于没检查。现在真的去查一次。
@@ -3017,7 +3090,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
3017
3090
  isolateKeepDays: { type: 'number', description: 'With isolated: remove isolation worktrees older than this many days (1-30, default 3).' },
3018
3091
  maxIsolated: { type: 'number', description: 'With isolated: keep at most this many worktrees, oldest removed first (1-50, default 5).' },
3019
3092
  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 主理鱼:已处理). Two sessions watching the same repo share it unless each sets its own.' },
3093
+ 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
3094
  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
3095
  },
3023
3096
  async execute(args) {
@@ -3052,7 +3125,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
3052
3125
  id, repo, provider, sessionId,
3053
3126
  intervalSec: 60,
3054
3127
  cooldownMs: DEFAULT_COOLDOWN_MS,
3055
- ackLabel: defaultAckLabel(provider),
3128
+ ackLabel: defaultAckLabel(provider, brand.defaultAckLabels),
3056
3129
  priority: { ...DEFAULT_TOOL_PRIORITY },
3057
3130
  cursor: null,
3058
3131
  seen: {},
@@ -3210,7 +3283,11 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
3210
3283
  const wsAgent = wsAgents && typeof wsAgents.currentInitiator === 'function' ? wsAgents.currentInitiator() : undefined
3211
3284
  const wsSessionId = (wsAgent && wsAgent.id) || undefined
3212
3285
  // 同一份数据:结构化视图 -> 文本只是它的一种渲染,两边永远对得上
3213
- const view = statusView(list, wsSessionId ? { sessionId: wsSessionId } : {})
3286
+ const view = statusView(list, {
3287
+ ...(wsSessionId ? { sessionId: wsSessionId } : {}),
3288
+ // 状态视图里的默认 ack 与 /state 同源(issue #11)
3289
+ defaultAckLabels: brand.defaultAckLabels,
3290
+ })
3214
3291
  if (args && args.format === 'json') return JSON.stringify(view, null, 2)
3215
3292
  // 默认只写「这条守是什么」;只有当它需要你注意时才追加原因。
3216
3293
  // 以前每行都带 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
- ? `【主理鱼】${repo} 首次同步:仓库里现有 ${lines.length} 条待处理(接上之前就在的,不是刚刚发生):`
266
- : `【主理鱼】${repo} 有 ${lines.length} 条新动态:`
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 命令
@@ -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 head = '【主理鱼】这一小段时间内有 ' + list.length + ' 处变化,合并成一条:'
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 ?? DEFAULT_ACK_LABEL,
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.9.286",
3
+ "version": "0.10.1",
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",
@@ -100,5 +100,8 @@
100
100
  },
101
101
  "devDependencies": {
102
102
  "semver": "7.8.6"
103
+ },
104
+ "dependencies": {
105
+ "@deepseek-ai/schemastery": "3.18.5"
103
106
  }
104
107
  }