dsh-repo-watch 0.2.0 → 0.3.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/README.md CHANGED
@@ -72,7 +72,8 @@
72
72
  - [x] 「其他动静」也会留一份,供 `quiet` 摘要查看(0.2.0)
73
73
  - [x] `snooze` 生效:标记「稍后再说」的条目在到期前不再提醒(0.2.0)
74
74
  - [x] 插件图标与本地化文案(0.2.0)
75
- - [ ] `deep` 摘要(分类 + 优先级 + 相似历史)
75
+ - [x] `deep` 摘要:类别 + 优先级 + 相似 thread,全部可解释(0.3.0)
76
+ - [ ] 用 GitHub 上的标签/评论数补充优先级信号
76
77
  - [ ] 多账号 / 组织仓库
77
78
 
78
79
  ## 三种摘要
@@ -81,7 +82,21 @@
81
82
  |---|---|---|
82
83
  | `waiting` | 需要你回复或处理的条目——报数推送里说的就是它 | 回「查看」 |
83
84
  | `quiet` | **不需要你动手、但确实发生了**的事:别人在你订阅的 thread 里讨论、机器人提交等,留 30 天 | 让我「看看其他动静」 |
84
- | `deep` | 在 `waiting` 基础上带状态、提醒次数等内部字段 | 排查时用 |
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
+ 为什么要可解释:**“这条为什么算高优先级”必须有答案**,否则你没法反驳它,也就不会信任它。
85
100
 
86
101
  ## 许可
87
102
 
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'
@@ -464,7 +465,23 @@ const digestTool = (config) => ({
464
465
  lines.push(` ${when}`)
465
466
  }
466
467
  if (thread.url) lines.push(` ${thread.url}`)
467
- if (wanted === 'deep' && thread.state) lines.push(` 状态:${thread.state} · 已提醒 ${Number(thread.notifyCount ?? 0)} 次`)
468
+ if (wanted === 'deep') {
469
+ const classification = classify({ title: thread.title, kind: thread.kind })
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
+ }
468
485
  })
469
486
  if (rows.length > shown.length) lines.push('', `……还有 ${rows.length - shown.length} 条,加大 limit 或收窄 bucket。`)
470
487
  return { ok: true, text: lines.join('\n') }
@@ -0,0 +1,159 @@
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
+ // `bug` must be here as well as in the labels: maintainers write "[Bug] …" in the
17
+ // title far more often than they add the label, and the first version only
18
+ // matched labels, so every such report fell through to "其他".
19
+ text: /(报错|崩溃|异常|无法|失败|不工作|挂了|闪退|\bbug\b|\berror\b|exception|crash|fail|broken|regression)/i,
20
+ },
21
+ {
22
+ kind: 'feature',
23
+ label: '功能请求',
24
+ labels: /^(enhancement|feature|request)/i,
25
+ text: /(希望|建议|能否|可不可以|支持一下|新增|feature request|would be nice|please add|support for)/i,
26
+ },
27
+ {
28
+ kind: 'question',
29
+ label: '提问',
30
+ labels: /^(question|help|how-?to)/i,
31
+ text: /(怎么|如何|为什么|请问|求教|是不是|能否问|how do|how to|why does|\?|?)/i,
32
+ },
33
+ {
34
+ kind: 'docs',
35
+ label: '文档',
36
+ labels: /^(docs?|documentation)/i,
37
+ text: /(文档|说明|readme|示例|example|typo|错别字)/i,
38
+ },
39
+ ]
40
+
41
+ /**
42
+ * What kind of report this is.
43
+ * @param {{ title?: string, labels?: string[], kind?: 'issue' | 'pr' }} input
44
+ * @returns {{ kind: string, label: string, signals: string[] }}
45
+ */
46
+ export function classify({ title = '', labels = [], kind = 'issue' } = {}) {
47
+ const text = String(title ?? '')
48
+ const signals = []
49
+ for (const rule of KIND_RULES) {
50
+ const hitLabel = (Array.isArray(labels) ? labels : []).find((name) => rule.labels.test(String(name ?? '')))
51
+ if (hitLabel) signals.push(`标签 ${hitLabel}`)
52
+ const hitText = rule.text.test(text)
53
+ if (hitText) signals.push('标题措辞')
54
+ if (hitLabel || hitText) return { kind: rule.kind, label: rule.label, signals }
55
+ }
56
+ // A pull request is a different animal from an unclassified report: it is a
57
+ // contribution to review or merge, not a report that may be missing details.
58
+ if (kind === 'pr') return { kind: 'pr', label: '变更/PR', signals: ['类型为 PR'] }
59
+ return { kind: 'other', label: '其他', signals: [] }
60
+ }
61
+
62
+ /** Score thresholds for the human-readable level. */
63
+ const LEVELS = [
64
+ { min: 5, level: 'high', label: '高' },
65
+ { min: 2, level: 'medium', label: '中' },
66
+ { min: -Infinity, level: 'low', label: '低' },
67
+ ]
68
+
69
+ /**
70
+ * How urgent a thread looks, with the reasons spelled out.
71
+ *
72
+ * Only signals the watchtower already stores are used, so this never costs a
73
+ * request and never changes between two identical calls.
74
+ *
75
+ * @param {object} input
76
+ * @param {{ kind: string }} input.classification
77
+ * @param {string} [input.title]
78
+ * @param {string} [input.reason] the pending reason
79
+ * @param {number} [input.ageDays] days since the last activity
80
+ * @param {number} [input.notifyCount] how often it has already been announced
81
+ * @returns {{ score: number, level: string, label: string, reasons: string[] }}
82
+ */
83
+ export function priorityOf({ classification, title = '', reason = '', ageDays = 0, notifyCount = 0 } = {}) {
84
+ const text = String(title ?? '')
85
+ const reasons = []
86
+ let score = 0
87
+ const add = (points, why) => { score += points; reasons.push(why) }
88
+
89
+ if (/regression|回归|以前可以|used to work/i.test(text)) add(3, '提到回归(以前可用)')
90
+ if (/数据丢失|丢数据|data loss|丢消息|丢失/i.test(text)) add(3, '涉及数据丢失')
91
+ if (/无法启动|启动不了|crash|崩溃|闪退/i.test(text)) add(2, '影响启动或直接崩溃')
92
+ if (reason === 'review-requested') add(3, '你被请求 review,阻塞别人')
93
+ if (reason === 'mentioned') add(2, '对方 @ 了你')
94
+ if (reason === 'someone-replied-to-my-thread') add(2, '你提的 thread 有人回复')
95
+ if (String(classification?.kind) === 'question' || String(classification?.kind) === 'docs') add(-1, '提问或文档类,通常不急')
96
+ if (String(classification?.kind) === 'pr') add(0, '是一条 PR,等你审阅或合并')
97
+ if (String(classification?.kind) === 'other') add(-1, '无法归类,信息可能不足')
98
+ if (!text.trim()) add(-2, '只有编号没有标题')
99
+ if (Number(notifyCount) >= 3) add(2, `已提醒 ${notifyCount} 次仍挂着`)
100
+ if (Number(ageDays) >= 7) add(1, `已放置 ${Math.round(ageDays)} 天`)
101
+
102
+ const level = LEVELS.find((entry) => score >= entry.min)
103
+ return { score, level: level.level, label: level.label, reasons }
104
+ }
105
+
106
+ /** Words that carry no signal when comparing two titles. */
107
+ const STOP = new Set([
108
+ 'the', 'a', 'an', 'and', 'or', 'of', 'to', 'in', 'on', 'for', 'with', 'is', 'are', 'was',
109
+ 'bug', 'issue', 'error', 'problem', 'support', 'please', 'help', 'add', 'fix',
110
+ '无法', '不能', '问题', '报错', '异常', '怎么', '如何', '请问', '希望', '建议',
111
+ ])
112
+
113
+ /** Latin words plus CJK bigrams: no tokenizer, but enough to find siblings. */
114
+ export function tokensOf(text) {
115
+ const raw = String(text ?? '').toLowerCase()
116
+ const out = new Set()
117
+ for (const word of raw.match(/[a-z0-9][a-z0-9+._-]{1,}/g) ?? []) {
118
+ if (!STOP.has(word) && word.length >= 3) out.add(word)
119
+ }
120
+ const cjk = raw.match(/[\u4e00-\u9fa5]+/g) ?? []
121
+ for (const run of cjk) {
122
+ for (let i = 0; i + 2 <= run.length; i += 1) {
123
+ const bigram = run.slice(i, i + 2)
124
+ if (!STOP.has(bigram)) out.add(bigram)
125
+ }
126
+ }
127
+ return out
128
+ }
129
+
130
+ /**
131
+ * Threads that look like the same report.
132
+ *
133
+ * Same repository only: two projects sharing a word rarely share a cause, and a
134
+ * cross-repo match would read as noise. Ranked by shared tokens, then recency.
135
+ *
136
+ * @param {{ key: string, title?: string }} target
137
+ * @param {Array<{ key: string, title?: string, state?: string, lastActivityAt?: number }>} threads
138
+ * @param {{ limit?: number }} [options]
139
+ * @returns {Array<{ key: string, title: string, state: string, shared: number }>}
140
+ */
141
+ export function similarTo(target, threads, { limit = 3 } = {}) {
142
+ const repo = String(target?.key ?? '').split('#')[0]
143
+ const mine = tokensOf(target?.title)
144
+ if (!repo || mine.size === 0) return []
145
+ const scored = []
146
+ for (const thread of Array.isArray(threads) ? threads : []) {
147
+ if (!thread?.key || thread.key === target.key) continue
148
+ if (String(thread.key).split('#')[0] !== repo) continue
149
+ const theirs = tokensOf(thread.title)
150
+ let shared = 0
151
+ for (const token of mine) if (theirs.has(token)) shared += 1
152
+ // One shared word is usually the topic, not the same bug.
153
+ if (shared < 2) continue
154
+ scored.push({ key: thread.key, title: String(thread.title ?? ''), state: String(thread.state ?? ''), shared })
155
+ }
156
+ return scored
157
+ .sort((a, b) => b.shared - a.shared)
158
+ .slice(0, limit)
159
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-repo-watch",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
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",
@@ -36,6 +36,6 @@
36
36
  "node": ">=20.18.1"
37
37
  },
38
38
  "scripts": {
39
- "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"
40
40
  }
41
41
  }
@@ -0,0 +1,97 @@
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('[Bug] in the title is enough, without a label', () => {
26
+ // 维护者更常把 [Bug] 写在标题里,而不是加标签;首版只匹配标签,整类都掉进"其他"
27
+ assert.equal(classify({ title: '[Bug] 非 Anthropic 模型经桥接时推理文本混入正文' }).kind, 'bug')
28
+ })
29
+
30
+ test('a pull request is its own kind, not an unclassified report', () => {
31
+ const pr = classify({ title: 'Add: two IM channel plugins', kind: 'pr' })
32
+ assert.equal(pr.kind, 'pr')
33
+ assert.equal(pr.label, '变更/PR')
34
+ // 但 PR 标题里出现崩溃,仍然按缺陷处理——那说明这条 PR 在修 bug
35
+ assert.equal(classify({ title: 'Fix: 启动崩溃', kind: 'pr' }).kind, 'bug')
36
+ })
37
+
38
+ test('classification names the signal it used', () => {
39
+ const byLabel = classify({ title: 'x', labels: ['regression'] })
40
+ assert.equal(byLabel.kind, 'bug')
41
+ assert.match(byLabel.signals.join(), /标签/)
42
+ const byText = classify({ title: '启动就崩溃' })
43
+ assert.match(byText.signals.join(), /标题措辞/)
44
+ })
45
+
46
+ test('priority is explainable and ordered', () => {
47
+ const regression = priorityOf({
48
+ classification: { kind: 'bug' },
49
+ title: '回归:以前可以启动,现在启动不了',
50
+ reason: 'someone-replied-to-my-thread',
51
+ })
52
+ const question = priorityOf({ classification: { kind: 'question' }, title: '怎么设置?' })
53
+ assert.ok(regression.score > question.score, '回归缺陷应当比提问更急')
54
+ assert.equal(regression.level, 'high')
55
+ assert.ok(regression.reasons.length >= 2)
56
+ for (const reason of regression.reasons) assert.match(reason, /[\u4e00-\u9fa5]/)
57
+ })
58
+
59
+ test('review requests and mentions raise the level', () => {
60
+ const review = priorityOf({ classification: { kind: 'other' }, title: 'x', reason: 'review-requested' })
61
+ const mention = priorityOf({ classification: { kind: 'other' }, title: 'x', reason: 'mentioned' })
62
+ assert.ok(review.score > mention.score)
63
+ assert.match(review.reasons.join(), /review/)
64
+ })
65
+
66
+ test('a thread announced three times is escalated, not ignored', () => {
67
+ const once = priorityOf({ classification: { kind: 'bug' }, title: '崩溃', notifyCount: 1 })
68
+ const many = priorityOf({ classification: { kind: 'bug' }, title: '崩溃', notifyCount: 4 })
69
+ assert.ok(many.score > once.score)
70
+ assert.match(many.reasons.join(), /已提醒/)
71
+ })
72
+
73
+ test('tokens drop filler words and keep CJK bigrams', () => {
74
+ const tokens = tokensOf('无法启动 the app after update 无法启动')
75
+ assert.ok(tokens.has('启动'))
76
+ assert.ok(tokens.has('app'))
77
+ assert.ok(tokens.has('update'))
78
+ assert.equal(tokens.has('the'), false)
79
+ assert.equal(tokens.has('无法'), false, 'stop word')
80
+ })
81
+
82
+ test('similar threads need two shared tokens and the same repository', () => {
83
+ const target = { key: 'o/r#1', title: '启动时崩溃 crash on startup' }
84
+ const threads = [
85
+ { key: 'o/r#2', title: '启动崩溃 crash after update', state: 'done' },
86
+ { key: 'o/r#3', title: '启动问题', state: 'pending' },
87
+ { key: 'other/repo#4', title: '启动崩溃 crash on startup', state: 'pending' },
88
+ { key: 'o/r#1', title: '启动崩溃', state: 'pending' },
89
+ ]
90
+ const similar = similarTo(target, threads)
91
+ assert.deepEqual(similar.map((item) => item.key), ['o/r#2'])
92
+ assert.equal(similar[0].state, 'done')
93
+ })
94
+
95
+ test('no tokens means no guesses', () => {
96
+ assert.deepEqual(similarTo({ key: 'o/r#1', title: '' }, [{ key: 'o/r#2', title: 'x' }]), [])
97
+ })