dsh-repo-watch 0.1.3 → 0.3.0

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/README.md CHANGED
@@ -68,9 +68,35 @@
68
68
  - [x] 占位发布(0.0.1)
69
69
  - [x] 轮询 + 水位 + 状态机(0.1.0)
70
70
  - [x] 通过飞书/微信通道推送
71
- - [x] 中文报数式推送 + 「看」展开明细(0.1.2)
72
- - [ ] `deep` 摘要(分类 + 优先级 + 相似历史)
73
- - [ ] 会话内快捷指令(`/watch done #646`)
71
+ - [x] 中文报数式推送 + 「查看」展开明细(0.1.2)
72
+ - [x] 「其他动静」也会留一份,供 `quiet` 摘要查看(0.2.0)
73
+ - [x] `snooze` 生效:标记「稍后再说」的条目在到期前不再提醒(0.2.0)
74
+ - [x] 插件图标与本地化文案(0.2.0)
75
+ - [x] `deep` 摘要:类别 + 优先级 + 相似 thread,全部可解释(0.3.0)
76
+ - [ ] 用 GitHub 上的标签/评论数补充优先级信号
77
+ - [ ] 多账号 / 组织仓库
78
+
79
+ ## 三种摘要
80
+
81
+ | 摘要 | 内容 | 怎么触发 |
82
+ |---|---|---|
83
+ | `waiting` | 需要你回复或处理的条目——报数推送里说的就是它 | 回「查看」 |
84
+ | `quiet` | **不需要你动手、但确实发生了**的事:别人在你订阅的 thread 里讨论、机器人提交等,留 30 天 | 让我「看看其他动静」 |
85
+ | `deep` | 在 `waiting` 基础上给出**判断**:类别(缺陷/功能请求/提问/文档)、优先级与理由、以及本仓库里相似的旧 thread(当时是 done 还是 pending) | 排查、决定先做哪个时用 |
86
+
87
+ ### `deep` 是怎么判断的
88
+
89
+ 全部是**可解释的规则**,不是让模型读一遍猜:
90
+
91
+ - **类别**:标签优先(`bug`/`regression`、`enhancement`/`feature`、`question`、`docs`),没有标签就看标题措辞;判断时会说明用了哪个信号;
92
+ - **优先级**(分数 → 高/中/低):
93
+ - `+3` 提到回归(以前可用)、涉及数据丢失、被请求 review;
94
+ - `+2` 崩溃/无法启动、@ 了你、你提的 thread 有人回复、**已提醒 3 次仍挂着**;
95
+ - `+1` 放置超过 7 天;
96
+ - `-1` 提问/文档类;`-2` 只有编号没有标题;
97
+ - **相似**:同仓库、标题共享 **≥2 个**有效词(英文单词 + 中文二元组,去掉“无法/问题/怎么”这类词),最多 3 条,并显示它们当时的状态。
98
+
99
+ 为什么要可解释:**“这条为什么算高优先级”必须有答案**,否则你没法反驳它,也就不会信任它。
74
100
 
75
101
  ## 许可
76
102
 
package/icon.svg ADDED
@@ -0,0 +1,19 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="Repository watchtower">
2
+ <defs>
3
+ <linearGradient id="tower" x1="0" y1="0" x2="1" y2="1">
4
+ <stop offset="0" stop-color="#2f6f4f"/>
5
+ <stop offset="1" stop-color="#1d4a34"/>
6
+ </linearGradient>
7
+ </defs>
8
+ <rect x="4" y="4" width="56" height="56" rx="14" fill="url(#tower)"/>
9
+ <!-- watchtower roof -->
10
+ <path d="M32 14 L44 24 H20 Z" fill="#e8f2ec"/>
11
+ <!-- tower body -->
12
+ <rect x="24" y="24" width="16" height="20" rx="2" fill="#e8f2ec"/>
13
+ <!-- watch window -->
14
+ <circle cx="32" cy="32" r="4.5" fill="#2f6f4f"/>
15
+ <!-- base -->
16
+ <rect x="18" y="44" width="28" height="5" rx="2.5" fill="#e8f2ec"/>
17
+ <!-- the one lit dot: someone is waiting -->
18
+ <circle cx="46" cy="18" r="4.5" fill="#f2b134"/>
19
+ </svg>
package/index.mjs CHANGED
@@ -20,6 +20,7 @@ import z from '@deepseek-ai/schemastery'
20
20
 
21
21
  import { excerptOf, lastHumanComment, listNotifications, listOwnRepos, listRepoIssues, resolveToken, whoami } from './lib/github.mjs'
22
22
  import { countsOf, loadState, pruneThreads, saveState, statePath, upsertThread } from './lib/state.mjs'
23
+ import { classify, priorityOf, similarTo } from './lib/insight.mjs'
23
24
  import { bucketHint, bucketOf, bucketText, judgeNotification, judgeRepoItem, reasonText, shouldNotify, threadOf } from './lib/triage.mjs'
24
25
 
25
26
  export const name = 'repo-watch'
@@ -169,6 +170,28 @@ function composeWaitingMessage(entries) {
169
170
  return lines.join('\n')
170
171
  }
171
172
 
173
+ /**
174
+ * Fold newly noticed activity into the stored list.
175
+ *
176
+ * One entry per thread (the newest wins), bounded, and pruned by age: this list
177
+ * exists so "what else moved" can be answered, not as an archive.
178
+ */
179
+ function mergeActivity(previous, noticed, now) {
180
+ const byKey = new Map()
181
+ for (const item of Array.isArray(previous) ? previous : []) {
182
+ if (item?.key) byKey.set(item.key, item)
183
+ }
184
+ for (const item of noticed) {
185
+ const existing = byKey.get(item.key)
186
+ if (!existing || Number(item.at ?? 0) >= Number(existing.at ?? 0)) byKey.set(item.key, item)
187
+ }
188
+ const keepMs = 30 * 24 * 60 * 60 * 1000
189
+ return [...byKey.values()]
190
+ .filter((item) => now - Number(item.at ?? 0) <= keepMs)
191
+ .sort((a, b) => Number(b.at ?? 0) - Number(a.at ?? 0))
192
+ .slice(0, 200)
193
+ }
194
+
172
195
  /**
173
196
  * One poll: notifications (someone acted toward me) + repo scan (someone opened
174
197
  * something of mine). Both paths feed the same judgement and the same state file.
@@ -243,14 +266,31 @@ async function pollOnce(ctx, config) {
243
266
  }
244
267
 
245
268
  const fresh = []
269
+ const noticed = []
246
270
  for (const candidate of candidates) {
247
- if (!candidate.verdict.pending) continue
271
+ if (!candidate.verdict.pending) {
272
+ // Activity that does not need an answer is still activity: it is what the
273
+ // "quiet" digest is for, and throwing it away would make that digest empty.
274
+ if (!/^(i-spoke-last|already-read|closed|mine)$/.test(candidate.verdict.reason)) {
275
+ noticed.push({
276
+ key: candidate.key,
277
+ title: candidate.title,
278
+ actor: candidate.actor,
279
+ text: candidate.snippet,
280
+ reason: candidate.verdict.reason,
281
+ at: candidate.lastActivityAt,
282
+ })
283
+ }
284
+ continue
285
+ }
248
286
  const previous = state.threads[candidate.key]
249
287
  const notify = shouldNotify({
250
288
  previous: previous?.state,
251
289
  pending: true,
252
290
  lastActivityAt: candidate.lastActivityAt,
253
291
  stateSince: Number(previous?.stateSince ?? 0),
292
+ snoozeUntil: Number(previous?.snoozeUntil ?? 0),
293
+ now,
254
294
  })
255
295
  upsertThread(state, candidate.key, {
256
296
  kind: candidate.thread.kind,
@@ -264,6 +304,7 @@ async function pollOnce(ctx, config) {
264
304
  if (notify) fresh.push({ ...candidate, reason: candidate.verdict.reason })
265
305
  }
266
306
 
307
+ state.activity = mergeActivity(state.activity, noticed, now)
267
308
  state.watermark = now
268
309
  pruneThreads(state, now)
269
310
  saveState(config ?? {}, state)
@@ -387,6 +428,22 @@ const digestTool = (config) => ({
387
428
  const limit = Math.max(1, Number(args?.limit ?? 20))
388
429
  const wanted = String(args?.kind ?? 'waiting')
389
430
  const bucket = String(args?.bucket ?? 'all')
431
+
432
+ // `quiet` answers "what else moved", which is activity, not threads: those
433
+ // entries did not become pending, so they are not in the state machine.
434
+ if (wanted === 'quiet') {
435
+ const items = (Array.isArray(state.activity) ? state.activity : []).slice(0, limit)
436
+ if (items.length === 0) return { ok: true, text: '最近没有其他动静。' }
437
+ const lines = [`最近 ${items.length} 条其他动静:`]
438
+ items.forEach((item, index) => {
439
+ lines.push('')
440
+ lines.push(`${index + 1}. ${item.key}${item.title ? ` ${item.title}` : ''}`)
441
+ lines.push(` ${reasonText(item.reason)}${item.actor ? ` · ${item.actor}` : ''}${item.at ? `(${shortDay(item.at)})` : ''}`)
442
+ if (item.text) lines.push(` ${item.text}`)
443
+ })
444
+ return { ok: true, text: lines.join('\n') }
445
+ }
446
+
390
447
  const rows = Object.entries(state.threads)
391
448
  .filter(([, thread]) => (wanted === 'waiting' ? thread.state === 'pending' : thread.state !== 'pending'))
392
449
  .filter(([, thread]) => bucket === 'all' || bucketOf(thread.reason) === bucket)
@@ -408,7 +465,23 @@ const digestTool = (config) => ({
408
465
  lines.push(` ${when}`)
409
466
  }
410
467
  if (thread.url) lines.push(` ${thread.url}`)
411
- if (wanted === 'deep' && thread.state) lines.push(` 状态:${thread.state} · 已提醒 ${Number(thread.notifyCount ?? 0)} 次`)
468
+ if (wanted === 'deep') {
469
+ const classification = classify({ title: thread.title })
470
+ const ageDays = thread.lastActivityAt ? (Date.now() - Number(thread.lastActivityAt)) / 86_400_000 : 0
471
+ const priority = priorityOf({
472
+ classification, title: thread.title, reason: thread.reason,
473
+ ageDays, notifyCount: Number(thread.notifyCount ?? 0),
474
+ })
475
+ lines.push(` 判断:${classification.label} · 优先级${priority.label}(${priority.score >= 0 ? '+' : ''}${priority.score})`)
476
+ if (priority.reasons.length) lines.push(` 理由:${priority.reasons.join(';')}`)
477
+ const similar = similarTo({ key, title: thread.title }, Object.entries(state.threads)
478
+ .filter(([other]) => other !== key)
479
+ .map(([other, entry]) => ({ key: other, ...entry })))
480
+ if (similar.length) {
481
+ lines.push(` 相似:${similar.map((item) => `${item.key}(${item.state})`).join('、')}`)
482
+ }
483
+ lines.push(` 状态:${thread.state} · 已提醒 ${Number(thread.notifyCount ?? 0)} 次`)
484
+ }
412
485
  })
413
486
  if (rows.length > shown.length) lines.push('', `……还有 ${rows.length - shown.length} 条,加大 limit 或收窄 bucket。`)
414
487
  return { ok: true, text: lines.join('\n') }
@@ -478,4 +551,4 @@ const checkTool = (ctx, config) => ({
478
551
  })
479
552
 
480
553
  /** Exposed for the smoke test: wiring a delay keeps timers testable. */
481
- export const _internals = { pollOnce, pushText, runtime, delay, composeWaitingMessage }
554
+ export const _internals = { pollOnce, pushText, runtime, delay, composeWaitingMessage, mergeActivity }
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Reading a thread: what kind of report is it, how urgent does it look, and what
3
+ * has happened to similar ones here before.
4
+ *
5
+ * Deliberately rule-based. The `deep` digest is asked for while triaging, and a
6
+ * model call there would be slow, non-reproducible, and impossible to explain —
7
+ * "why is this high priority" must have an answer the maintainer can check. Every
8
+ * judgement therefore returns the signals that produced it.
9
+ */
10
+
11
+ const KIND_RULES = [
12
+ {
13
+ kind: 'bug',
14
+ label: '缺陷',
15
+ labels: /^(bug|crash|regression|broken)/i,
16
+ text: /(报错|崩溃|异常|无法|失败|不工作|挂了|闪退|error|exception|crash|fail|broken|regression)/i,
17
+ },
18
+ {
19
+ kind: 'feature',
20
+ label: '功能请求',
21
+ labels: /^(enhancement|feature|request)/i,
22
+ text: /(希望|建议|能否|可不可以|支持一下|新增|feature request|would be nice|please add|support for)/i,
23
+ },
24
+ {
25
+ kind: 'question',
26
+ label: '提问',
27
+ labels: /^(question|help|how-?to)/i,
28
+ text: /(怎么|如何|为什么|请问|求教|是不是|能否问|how do|how to|why does|\?|?)/i,
29
+ },
30
+ {
31
+ kind: 'docs',
32
+ label: '文档',
33
+ labels: /^(docs?|documentation)/i,
34
+ text: /(文档|说明|readme|示例|example|typo|错别字)/i,
35
+ },
36
+ ]
37
+
38
+ /**
39
+ * What kind of report this is.
40
+ * @param {{ title?: string, labels?: string[] }} input
41
+ * @returns {{ kind: string, label: string, signals: string[] }}
42
+ */
43
+ export function classify({ title = '', labels = [] } = {}) {
44
+ const text = String(title ?? '')
45
+ const signals = []
46
+ for (const rule of KIND_RULES) {
47
+ const hitLabel = (Array.isArray(labels) ? labels : []).find((name) => rule.labels.test(String(name ?? '')))
48
+ if (hitLabel) signals.push(`标签 ${hitLabel}`)
49
+ const hitText = rule.text.test(text)
50
+ if (hitText) signals.push('标题措辞')
51
+ if (hitLabel || hitText) return { kind: rule.kind, label: rule.label, signals }
52
+ }
53
+ return { kind: 'other', label: '其他', signals: [] }
54
+ }
55
+
56
+ /** Score thresholds for the human-readable level. */
57
+ const LEVELS = [
58
+ { min: 5, level: 'high', label: '高' },
59
+ { min: 2, level: 'medium', label: '中' },
60
+ { min: -Infinity, level: 'low', label: '低' },
61
+ ]
62
+
63
+ /**
64
+ * How urgent a thread looks, with the reasons spelled out.
65
+ *
66
+ * Only signals the watchtower already stores are used, so this never costs a
67
+ * request and never changes between two identical calls.
68
+ *
69
+ * @param {object} input
70
+ * @param {{ kind: string }} input.classification
71
+ * @param {string} [input.title]
72
+ * @param {string} [input.reason] the pending reason
73
+ * @param {number} [input.ageDays] days since the last activity
74
+ * @param {number} [input.notifyCount] how often it has already been announced
75
+ * @returns {{ score: number, level: string, label: string, reasons: string[] }}
76
+ */
77
+ export function priorityOf({ classification, title = '', reason = '', ageDays = 0, notifyCount = 0 } = {}) {
78
+ const text = String(title ?? '')
79
+ const reasons = []
80
+ let score = 0
81
+ const add = (points, why) => { score += points; reasons.push(why) }
82
+
83
+ if (/regression|回归|以前可以|used to work/i.test(text)) add(3, '提到回归(以前可用)')
84
+ if (/数据丢失|丢数据|data loss|丢消息|丢失/i.test(text)) add(3, '涉及数据丢失')
85
+ if (/无法启动|启动不了|crash|崩溃|闪退/i.test(text)) add(2, '影响启动或直接崩溃')
86
+ if (reason === 'review-requested') add(3, '你被请求 review,阻塞别人')
87
+ if (reason === 'mentioned') add(2, '对方 @ 了你')
88
+ if (reason === 'someone-replied-to-my-thread') add(2, '你提的 thread 有人回复')
89
+ if (String(classification?.kind) === 'question' || String(classification?.kind) === 'docs') add(-1, '提问或文档类,通常不急')
90
+ if (String(classification?.kind) === 'other') add(-1, '无法归类,信息可能不足')
91
+ if (!text.trim()) add(-2, '只有编号没有标题')
92
+ if (Number(notifyCount) >= 3) add(2, `已提醒 ${notifyCount} 次仍挂着`)
93
+ if (Number(ageDays) >= 7) add(1, `已放置 ${Math.round(ageDays)} 天`)
94
+
95
+ const level = LEVELS.find((entry) => score >= entry.min)
96
+ return { score, level: level.level, label: level.label, reasons }
97
+ }
98
+
99
+ /** Words that carry no signal when comparing two titles. */
100
+ const STOP = new Set([
101
+ 'the', 'a', 'an', 'and', 'or', 'of', 'to', 'in', 'on', 'for', 'with', 'is', 'are', 'was',
102
+ 'bug', 'issue', 'error', 'problem', 'support', 'please', 'help', 'add', 'fix',
103
+ '无法', '不能', '问题', '报错', '异常', '怎么', '如何', '请问', '希望', '建议',
104
+ ])
105
+
106
+ /** Latin words plus CJK bigrams: no tokenizer, but enough to find siblings. */
107
+ export function tokensOf(text) {
108
+ const raw = String(text ?? '').toLowerCase()
109
+ const out = new Set()
110
+ for (const word of raw.match(/[a-z0-9][a-z0-9+._-]{1,}/g) ?? []) {
111
+ if (!STOP.has(word) && word.length >= 3) out.add(word)
112
+ }
113
+ const cjk = raw.match(/[\u4e00-\u9fa5]+/g) ?? []
114
+ for (const run of cjk) {
115
+ for (let i = 0; i + 2 <= run.length; i += 1) {
116
+ const bigram = run.slice(i, i + 2)
117
+ if (!STOP.has(bigram)) out.add(bigram)
118
+ }
119
+ }
120
+ return out
121
+ }
122
+
123
+ /**
124
+ * Threads that look like the same report.
125
+ *
126
+ * Same repository only: two projects sharing a word rarely share a cause, and a
127
+ * cross-repo match would read as noise. Ranked by shared tokens, then recency.
128
+ *
129
+ * @param {{ key: string, title?: string }} target
130
+ * @param {Array<{ key: string, title?: string, state?: string, lastActivityAt?: number }>} threads
131
+ * @param {{ limit?: number }} [options]
132
+ * @returns {Array<{ key: string, title: string, state: string, shared: number }>}
133
+ */
134
+ export function similarTo(target, threads, { limit = 3 } = {}) {
135
+ const repo = String(target?.key ?? '').split('#')[0]
136
+ const mine = tokensOf(target?.title)
137
+ if (!repo || mine.size === 0) return []
138
+ const scored = []
139
+ for (const thread of Array.isArray(threads) ? threads : []) {
140
+ if (!thread?.key || thread.key === target.key) continue
141
+ if (String(thread.key).split('#')[0] !== repo) continue
142
+ const theirs = tokensOf(thread.title)
143
+ let shared = 0
144
+ for (const token of mine) if (theirs.has(token)) shared += 1
145
+ // One shared word is usually the topic, not the same bug.
146
+ if (shared < 2) continue
147
+ scored.push({ key: thread.key, title: String(thread.title ?? ''), state: String(thread.state ?? ''), shared })
148
+ }
149
+ return scored
150
+ .sort((a, b) => b.shared - a.shared)
151
+ .slice(0, limit)
152
+ }
package/lib/state.mjs CHANGED
@@ -19,9 +19,9 @@ export const MAX_THREADS = 2000
19
19
  export const statePath = (config = {}) =>
20
20
  String(config.stateFile ?? '').trim() || join(dshHome(), 'repo-watch.json')
21
21
 
22
- /** @returns {{ version: number, watermark: number, threads: Record<string, object> }} */
22
+ /** @returns {{ version: number, watermark: number, threads: Record<string, object>, activity: object[] }} */
23
23
  export function emptyState() {
24
- return { version: STATE_VERSION, watermark: 0, threads: {} }
24
+ return { version: STATE_VERSION, watermark: 0, threads: {}, activity: [] }
25
25
  }
26
26
 
27
27
  export function loadState(config = {}) {
@@ -32,6 +32,7 @@ export function loadState(config = {}) {
32
32
  version: STATE_VERSION,
33
33
  watermark: Number(parsed.watermark ?? 0),
34
34
  threads: parsed.threads && typeof parsed.threads === 'object' ? parsed.threads : {},
35
+ activity: Array.isArray(parsed.activity) ? parsed.activity : [],
35
36
  }
36
37
  } catch {
37
38
  return emptyState()
package/lib/triage.mjs CHANGED
@@ -172,10 +172,14 @@ export function judgeRepoItem({ issue, me }) {
172
172
  * @param {boolean} input.pending the fresh judgement
173
173
  * @param {number} [input.lastActivityAt] activity that triggered this judgement
174
174
  * @param {number} [input.stateSince] when the stored state was entered
175
+ * @param {number} [input.snoozeUntil] silence this thread until then
176
+ * @param {number} [input.now] clock, so the snooze rule is testable
175
177
  * @returns {boolean}
176
178
  */
177
- export function shouldNotify({ previous, pending, lastActivityAt = 0, stateSince = 0 }) {
179
+ export function shouldNotify({ previous, pending, lastActivityAt = 0, stateSince = 0, snoozeUntil = 0, now = Date.now() }) {
178
180
  if (!pending) return false
181
+ // A snoozed thread stays pending — it still needs an answer, just not now.
182
+ if (Number(snoozeUntil) > Number(now)) return false
179
183
  if (previous === undefined) return true
180
184
  if (previous === 'done') return Number(lastActivityAt) > Number(stateSince)
181
185
  return false
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Repository watchtower",
4
+ "description": "Watches your GitHub repositories in the background and speaks up only when someone is actually waiting on you: replies to your threads, mentions, review requests, and issues opened in your repos."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "仓库守望",
4
+ "description": "在后台盯着你的 GitHub 仓库,只在真的有人等你时才说一句:你提的 issue/PR 有人回复、有人 @ 你、请你 review,或者有人给你的仓库开了 issue。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-repo-watch",
3
- "version": "0.1.3",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "description": "DSH repository watchtower: it watches your GitHub repos in the background and only speaks up when someone is actually waiting on you.",
6
6
  "license": "MIT",
@@ -11,12 +11,16 @@
11
11
  "main": "index.mjs",
12
12
  "exports": {
13
13
  ".": "./index.mjs",
14
+ "./locale/*.json": "./locale/*.json",
15
+ "./icon": "./icon.svg",
14
16
  "./package.json": "./package.json"
15
17
  },
16
18
  "files": [
17
19
  "index.mjs",
18
20
  "lib/*.mjs",
19
21
  "cordis.patch.yml",
22
+ "locale/*.json",
23
+ "icon.svg",
20
24
  "test/*.mjs",
21
25
  "README.md",
22
26
  "LICENSE"
@@ -32,6 +36,6 @@
32
36
  "node": ">=20.18.1"
33
37
  },
34
38
  "scripts": {
35
- "test": "node --test test/triage.test.mjs test/message.test.mjs"
39
+ "test": "node --test test/triage.test.mjs test/message.test.mjs test/insight.test.mjs"
36
40
  }
37
41
  }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * The `deep` digest's judgement: classification, priority, similar threads.
3
+ *
4
+ * These are rules, so they are pinned here: a priority that cannot be explained is
5
+ * worse than no priority at all.
6
+ */
7
+ import test from 'node:test'
8
+ import assert from 'node:assert/strict'
9
+
10
+ import { classify, priorityOf, similarTo, tokensOf } from '../lib/insight.mjs'
11
+
12
+ test('labels win over wording', () => {
13
+ assert.equal(classify({ title: '怎么用这个功能', labels: ['bug'] }).kind, 'bug')
14
+ assert.equal(classify({ title: '怎么用这个功能', labels: [] }).kind, 'question')
15
+ })
16
+
17
+ test('the four kinds are recognised from wording alone', () => {
18
+ assert.equal(classify({ title: '启动时崩溃,无法打开' }).kind, 'bug')
19
+ assert.equal(classify({ title: '希望支持批量导出' }).kind, 'feature')
20
+ assert.equal(classify({ title: '这个参数怎么设置?' }).kind, 'question')
21
+ assert.equal(classify({ title: 'README 里的示例有错别字' }).kind, 'docs')
22
+ assert.equal(classify({ title: 'dsh-repo-watch#42' }).kind, 'other')
23
+ })
24
+
25
+ test('classification names the signal it used', () => {
26
+ const byLabel = classify({ title: 'x', labels: ['regression'] })
27
+ assert.equal(byLabel.kind, 'bug')
28
+ assert.match(byLabel.signals.join(), /标签/)
29
+ const byText = classify({ title: '启动就崩溃' })
30
+ assert.match(byText.signals.join(), /标题措辞/)
31
+ })
32
+
33
+ test('priority is explainable and ordered', () => {
34
+ const regression = priorityOf({
35
+ classification: { kind: 'bug' },
36
+ title: '回归:以前可以启动,现在启动不了',
37
+ reason: 'someone-replied-to-my-thread',
38
+ })
39
+ const question = priorityOf({ classification: { kind: 'question' }, title: '怎么设置?' })
40
+ assert.ok(regression.score > question.score, '回归缺陷应当比提问更急')
41
+ assert.equal(regression.level, 'high')
42
+ assert.ok(regression.reasons.length >= 2)
43
+ for (const reason of regression.reasons) assert.match(reason, /[\u4e00-\u9fa5]/)
44
+ })
45
+
46
+ test('review requests and mentions raise the level', () => {
47
+ const review = priorityOf({ classification: { kind: 'other' }, title: 'x', reason: 'review-requested' })
48
+ const mention = priorityOf({ classification: { kind: 'other' }, title: 'x', reason: 'mentioned' })
49
+ assert.ok(review.score > mention.score)
50
+ assert.match(review.reasons.join(), /review/)
51
+ })
52
+
53
+ test('a thread announced three times is escalated, not ignored', () => {
54
+ const once = priorityOf({ classification: { kind: 'bug' }, title: '崩溃', notifyCount: 1 })
55
+ const many = priorityOf({ classification: { kind: 'bug' }, title: '崩溃', notifyCount: 4 })
56
+ assert.ok(many.score > once.score)
57
+ assert.match(many.reasons.join(), /已提醒/)
58
+ })
59
+
60
+ test('tokens drop filler words and keep CJK bigrams', () => {
61
+ const tokens = tokensOf('无法启动 the app after update 无法启动')
62
+ assert.ok(tokens.has('启动'))
63
+ assert.ok(tokens.has('app'))
64
+ assert.ok(tokens.has('update'))
65
+ assert.equal(tokens.has('the'), false)
66
+ assert.equal(tokens.has('无法'), false, 'stop word')
67
+ })
68
+
69
+ test('similar threads need two shared tokens and the same repository', () => {
70
+ const target = { key: 'o/r#1', title: '启动时崩溃 crash on startup' }
71
+ const threads = [
72
+ { key: 'o/r#2', title: '启动崩溃 crash after update', state: 'done' },
73
+ { key: 'o/r#3', title: '启动问题', state: 'pending' },
74
+ { key: 'other/repo#4', title: '启动崩溃 crash on startup', state: 'pending' },
75
+ { key: 'o/r#1', title: '启动崩溃', state: 'pending' },
76
+ ]
77
+ const similar = similarTo(target, threads)
78
+ assert.deepEqual(similar.map((item) => item.key), ['o/r#2'])
79
+ assert.equal(similar[0].state, 'done')
80
+ })
81
+
82
+ test('no tokens means no guesses', () => {
83
+ assert.deepEqual(similarTo({ key: 'o/r#1', title: '' }, [{ key: 'o/r#2', title: 'x' }]), [])
84
+ })
@@ -8,7 +8,7 @@ import assert from 'node:assert/strict'
8
8
 
9
9
  import { _internals } from '../index.mjs'
10
10
 
11
- const { composeWaitingMessage } = _internals
11
+ const { composeWaitingMessage, mergeActivity } = _internals
12
12
 
13
13
  const entry = (over = {}) => ({
14
14
  key: 'owner/repo#1',
@@ -68,3 +68,26 @@ test('the newest line is the most recent thread', () => {
68
68
  ])
69
69
  assert.match(text, /最近一条:owner\/repo#new/)
70
70
  })
71
+
72
+ test('quiet activity keeps one entry per thread, newest wins', () => {
73
+ const now = 10_000_000
74
+ const merged = mergeActivity(
75
+ [{ key: 'a#1', at: now - 100, title: 'old' }, { key: 'b#2', at: now - 200, title: 'b' }],
76
+ [{ key: 'a#1', at: now - 10, title: 'new' }, { key: 'c#3', at: now - 50, title: 'c' }],
77
+ now,
78
+ )
79
+ assert.equal(merged.length, 3)
80
+ assert.equal(merged[0].key, 'a#1', 'newest first')
81
+ assert.equal(merged[0].title, 'new', 'newest wins for the same thread')
82
+ assert.deepEqual(merged.map((item) => item.key), ['a#1', 'c#3', 'b#2'])
83
+ })
84
+
85
+ test('quiet activity forgets what is older than a month', () => {
86
+ const now = 10_000_000_000
87
+ const merged = mergeActivity(
88
+ [{ key: 'stale#1', at: now - 40 * 24 * 3600_000 }],
89
+ [{ key: 'fresh#2', at: now - 1000 }],
90
+ now,
91
+ )
92
+ assert.deepEqual(merged.map((item) => item.key), ['fresh#2'])
93
+ })
@@ -83,6 +83,23 @@ test('announce only when a thread enters pending or reopens after done', () => {
83
83
  assert.equal(shouldNotify({ previous: 'pending', pending: false }), false)
84
84
  })
85
85
 
86
+ test('a snoozed thread stays pending but stays quiet', () => {
87
+ const now = 1_000_000
88
+ // 首次出现也按 snooze 静默:snooze 的语义是"先别告诉我"
89
+ assert.equal(shouldNotify({ previous: undefined, pending: true, snoozeUntil: now + 60_000, now }), false)
90
+ assert.equal(shouldNotify({ previous: 'done', pending: true, lastActivityAt: 20, stateSince: 10, snoozeUntil: now + 60_000, now }), false)
91
+ // 到期后照常提醒
92
+ assert.equal(shouldNotify({ previous: undefined, pending: true, snoozeUntil: now - 1, now }), true)
93
+ })
94
+
95
+ test('a done thread still reopens when new activity arrives after snooze', () => {
96
+ const now = 1_000_000
97
+ assert.equal(
98
+ shouldNotify({ previous: 'done', pending: true, lastActivityAt: 90, stateSince: 10, snoozeUntil: now - 1, now }),
99
+ true,
100
+ )
101
+ })
102
+
86
103
  test('quiet hours wrap around midnight', () => {
87
104
  assert.equal(inQuietHours(23, '23-8'), true)
88
105
  assert.equal(inQuietHours(3, '23-8'), true)