dsh-repo-watch 0.1.3 → 0.2.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,20 @@
68
68
  - [x] 占位发布(0.0.1)
69
69
  - [x] 轮询 + 水位 + 状态机(0.1.0)
70
70
  - [x] 通过飞书/微信通道推送
71
- - [x] 中文报数式推送 + 「看」展开明细(0.1.2)
71
+ - [x] 中文报数式推送 + 「查看」展开明细(0.1.2)
72
+ - [x] 「其他动静」也会留一份,供 `quiet` 摘要查看(0.2.0)
73
+ - [x] `snooze` 生效:标记「稍后再说」的条目在到期前不再提醒(0.2.0)
74
+ - [x] 插件图标与本地化文案(0.2.0)
72
75
  - [ ] `deep` 摘要(分类 + 优先级 + 相似历史)
73
- - [ ] 会话内快捷指令(`/watch done #646`)
76
+ - [ ] 多账号 / 组织仓库
77
+
78
+ ## 三种摘要
79
+
80
+ | 摘要 | 内容 | 怎么触发 |
81
+ |---|---|---|
82
+ | `waiting` | 需要你回复或处理的条目——报数推送里说的就是它 | 回「查看」 |
83
+ | `quiet` | **不需要你动手、但确实发生了**的事:别人在你订阅的 thread 里讨论、机器人提交等,留 30 天 | 让我「看看其他动静」 |
84
+ | `deep` | 在 `waiting` 基础上带状态、提醒次数等内部字段 | 排查时用 |
74
85
 
75
86
  ## 许可
76
87
 
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
@@ -169,6 +169,28 @@ function composeWaitingMessage(entries) {
169
169
  return lines.join('\n')
170
170
  }
171
171
 
172
+ /**
173
+ * Fold newly noticed activity into the stored list.
174
+ *
175
+ * One entry per thread (the newest wins), bounded, and pruned by age: this list
176
+ * exists so "what else moved" can be answered, not as an archive.
177
+ */
178
+ function mergeActivity(previous, noticed, now) {
179
+ const byKey = new Map()
180
+ for (const item of Array.isArray(previous) ? previous : []) {
181
+ if (item?.key) byKey.set(item.key, item)
182
+ }
183
+ for (const item of noticed) {
184
+ const existing = byKey.get(item.key)
185
+ if (!existing || Number(item.at ?? 0) >= Number(existing.at ?? 0)) byKey.set(item.key, item)
186
+ }
187
+ const keepMs = 30 * 24 * 60 * 60 * 1000
188
+ return [...byKey.values()]
189
+ .filter((item) => now - Number(item.at ?? 0) <= keepMs)
190
+ .sort((a, b) => Number(b.at ?? 0) - Number(a.at ?? 0))
191
+ .slice(0, 200)
192
+ }
193
+
172
194
  /**
173
195
  * One poll: notifications (someone acted toward me) + repo scan (someone opened
174
196
  * something of mine). Both paths feed the same judgement and the same state file.
@@ -243,14 +265,31 @@ async function pollOnce(ctx, config) {
243
265
  }
244
266
 
245
267
  const fresh = []
268
+ const noticed = []
246
269
  for (const candidate of candidates) {
247
- if (!candidate.verdict.pending) continue
270
+ if (!candidate.verdict.pending) {
271
+ // Activity that does not need an answer is still activity: it is what the
272
+ // "quiet" digest is for, and throwing it away would make that digest empty.
273
+ if (!/^(i-spoke-last|already-read|closed|mine)$/.test(candidate.verdict.reason)) {
274
+ noticed.push({
275
+ key: candidate.key,
276
+ title: candidate.title,
277
+ actor: candidate.actor,
278
+ text: candidate.snippet,
279
+ reason: candidate.verdict.reason,
280
+ at: candidate.lastActivityAt,
281
+ })
282
+ }
283
+ continue
284
+ }
248
285
  const previous = state.threads[candidate.key]
249
286
  const notify = shouldNotify({
250
287
  previous: previous?.state,
251
288
  pending: true,
252
289
  lastActivityAt: candidate.lastActivityAt,
253
290
  stateSince: Number(previous?.stateSince ?? 0),
291
+ snoozeUntil: Number(previous?.snoozeUntil ?? 0),
292
+ now,
254
293
  })
255
294
  upsertThread(state, candidate.key, {
256
295
  kind: candidate.thread.kind,
@@ -264,6 +303,7 @@ async function pollOnce(ctx, config) {
264
303
  if (notify) fresh.push({ ...candidate, reason: candidate.verdict.reason })
265
304
  }
266
305
 
306
+ state.activity = mergeActivity(state.activity, noticed, now)
267
307
  state.watermark = now
268
308
  pruneThreads(state, now)
269
309
  saveState(config ?? {}, state)
@@ -387,6 +427,22 @@ const digestTool = (config) => ({
387
427
  const limit = Math.max(1, Number(args?.limit ?? 20))
388
428
  const wanted = String(args?.kind ?? 'waiting')
389
429
  const bucket = String(args?.bucket ?? 'all')
430
+
431
+ // `quiet` answers "what else moved", which is activity, not threads: those
432
+ // entries did not become pending, so they are not in the state machine.
433
+ if (wanted === 'quiet') {
434
+ const items = (Array.isArray(state.activity) ? state.activity : []).slice(0, limit)
435
+ if (items.length === 0) return { ok: true, text: '最近没有其他动静。' }
436
+ const lines = [`最近 ${items.length} 条其他动静:`]
437
+ items.forEach((item, index) => {
438
+ lines.push('')
439
+ lines.push(`${index + 1}. ${item.key}${item.title ? ` ${item.title}` : ''}`)
440
+ lines.push(` ${reasonText(item.reason)}${item.actor ? ` · ${item.actor}` : ''}${item.at ? `(${shortDay(item.at)})` : ''}`)
441
+ if (item.text) lines.push(` ${item.text}`)
442
+ })
443
+ return { ok: true, text: lines.join('\n') }
444
+ }
445
+
390
446
  const rows = Object.entries(state.threads)
391
447
  .filter(([, thread]) => (wanted === 'waiting' ? thread.state === 'pending' : thread.state !== 'pending'))
392
448
  .filter(([, thread]) => bucket === 'all' || bucketOf(thread.reason) === bucket)
@@ -478,4 +534,4 @@ const checkTool = (ctx, config) => ({
478
534
  })
479
535
 
480
536
  /** Exposed for the smoke test: wiring a delay keeps timers testable. */
481
- export const _internals = { pollOnce, pushText, runtime, delay, composeWaitingMessage }
537
+ export const _internals = { pollOnce, pushText, runtime, delay, composeWaitingMessage, mergeActivity }
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.2.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"
@@ -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)