@ssamurias/dsh-fish 1.0.4 → 1.0.6

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.
Files changed (53) hide show
  1. package/AGENTS.md +31 -2
  2. package/CHANGELOG.md +4217 -4143
  3. package/README.md +95 -4
  4. package/RELEASE-NOTES-1.0.4.md +26 -0
  5. package/RELEASE-NOTES-1.0.5.md +79 -0
  6. package/RELEASE-NOTES-1.0.6.md +74 -0
  7. package/docs//346/217/222/344/273/266/347/272/246/345/256/232.md +1 -1
  8. package/lib/appoint.js +154 -25
  9. package/lib/ask.js +70 -7
  10. package/lib/at.js +34 -5
  11. package/lib/backup.js +16 -4
  12. package/lib/bili.js +80 -13
  13. package/lib/bridgeserve.js +195 -0
  14. package/lib/browse.js +136 -8
  15. package/lib/capture.js +54 -5
  16. package/lib/channels.js +20 -4
  17. package/lib/client.js +163 -21
  18. package/lib/comment.js +808 -716
  19. package/lib/compact.js +40 -3
  20. package/lib/configstamp.js +25 -0
  21. package/lib/derive.js +27 -1
  22. package/lib/doing.js +11 -2
  23. package/lib/handoff.js +28 -2
  24. package/lib/home.js +48 -19
  25. package/lib/identity.js +26 -12
  26. package/lib/import.js +4 -0
  27. package/lib/index.js +39 -9
  28. package/lib/log.js +57 -0
  29. package/lib/look.js +9 -2
  30. package/lib/move.js +14 -0
  31. package/lib/note.js +29 -5
  32. package/lib/observe.js +380 -87
  33. package/lib/persona.js +13 -4
  34. package/lib/proactive.js +2 -1
  35. package/lib/refuse.js +42 -0
  36. package/lib/restrict.js +75 -2
  37. package/lib/say.js +58 -13
  38. package/lib/scheduler.js +327 -45
  39. package/lib/selfcheck.js +9 -9
  40. package/lib/selfpronoun.js +7 -2
  41. package/lib/session-pressure.js +11 -3
  42. package/lib/sessionnote.js +11 -4
  43. package/lib/settings.js +23 -0
  44. package/lib/speak.js +15 -4
  45. package/lib/stance.js +257 -18
  46. package/lib/store.js +4 -0
  47. package/lib/turns.js +62 -5
  48. package/lib/use.js +2 -0
  49. package/lib/video.js +3 -0
  50. package/lib/watch.js +149 -3
  51. package/lib/wiki.js +183 -42
  52. package/media/principle-drive.svg +27 -23
  53. package/package.json +1 -1
package/lib/appoint.js CHANGED
@@ -9,6 +9,17 @@
9
9
  * 2. 到点只提一次(`notifiedAt`),不天天催。
10
10
  * 3. 他没来,也不替她圆——prompt 里明说「没来也别替他找理由」。
11
11
  * 4. 做没做到由她自己收:做到(done)、取消(cancel,要说为什么)、改期(move)。
12
+ *
13
+ * 2026-11-18 补「定到几点」(issue #149 / 用户 m01744、m01769、m01793):
14
+ * - 时刻**不是闹钟**,是「最早什么时候能提」——到那一刻她一定先看到这条,
15
+ * 做不做、怎么做由她自己定;催不催、说什么都不由这套代码替她决定。
16
+ * - 带时刻的约定不受作息窗口限制(约定优先);两条不同时刻各叫各的,不合并。
17
+ * - 到点那一刻正忙 / 刚叫过,宽限 5 分钟;超出宽限还忙就照叫——约定比闲聊优先。
18
+ * - 走到点这条链时 DSH 没开着,就晚一点叫,prompt 里写清「本来约的是 HH:MM,
19
+ * 那会儿我这边没开着」;不把「他不在」写进事件流(他可能就守在窗口旁)。
20
+ * - 双方都认下才作数:她可以用 ask_owner(kind='appoint') 问一句,答案在
21
+ * `answer` 事件里,这里是读答案那一端;没问过、问过没答、以后再说,各写各的。
22
+
12
23
  *
13
24
  * 三条硬约束(和 note.js 同一条线):
14
25
  * 1. **不审批**。约一件事不是改自己,不设关卡。
@@ -45,6 +56,25 @@ export const APPOINT_MAX_DAYS = 60
45
56
  /** list 一次最多列几条。 */
46
57
  export const APPOINT_SHOW_MAX = 5
47
58
 
59
+ /**
60
+ * 到点后宽限多久还算「准点」(2026-11-18,用户 m01744)。
61
+ * 5 分钟内叫她都算准时;超过就明说晚了多少。
62
+ */
63
+ export const APPT_GRACE_MS = 5 * 60_000
64
+
65
+ /**
66
+ * 两条到点的约定之间至少隔多久(2026-11-18)。
67
+ * 比作息唤醒的 45 分钟短:它不是「该醒了」,是「这件事到点了」。
68
+ */
69
+ export const APPT_MIN_GAP_MS = 10 * 60_000
70
+
71
+ /** 时刻写成 08:00 这样;24 小时制。 */
72
+ const HHMM = /^([01]\d|2[0-3]):[0-5]\d$/
73
+
74
+ export function isTime(v) {
75
+ return HHMM.test(String(v ?? '').trim())
76
+ }
77
+
48
78
  const STATUSES = ['open', 'done', 'cancelled', 'missed']
49
79
 
50
80
  export function appointPath(root = rootDir()) {
@@ -90,20 +120,50 @@ export function normalizeAppoint(raw) {
90
120
  const what = String(raw.what ?? '').replace(/\s+/g, ' ').trim()
91
121
  if (!what || !isDay(raw.due)) return null
92
122
  const status = STATUSES.includes(String(raw.status)) ? String(raw.status) : 'open'
123
+ const time = isTime(raw.time) ? String(raw.time).trim() : null
124
+ const late = Number(raw.lateMinutes)
93
125
  return {
94
126
  id: String(raw.id ?? '') || newAppointId(),
95
127
  due: String(raw.due),
128
+ // 2026-11-18:带时刻的约定。`null` 是老形状(只认日子)。
129
+ time,
96
130
  what: clipText(what, APPOINT_TEXT_MAX, ''),
97
131
  created: String(raw.created ?? '') || new Date().toISOString(),
98
132
  status,
99
133
  // 到点提过一次就写时间;改期会清回 null,让她在新日子再想起来一次
100
134
  notifiedAt: raw.notifiedAt == null ? null : String(raw.notifiedAt),
135
+ // 实际叫起来时晚了几分钟(超过宽限才写;没晚就是 null)
136
+ lateMinutes: Number.isFinite(late) && late > 0 ? Math.round(late) : null,
137
+ // 他答应过没有:true 答应、false 没问成或问过他还没答、null 还没问过(不猜)
138
+ agreed: raw.agreed === true ? true : raw.agreed === false ? false : null,
139
+ // 她为这条发的那张确认卡(ask 事件的 id),到点用来看他当时怎么答的
140
+ askId: raw.askId == null || String(raw.askId).trim() === '' ? null : String(raw.askId).trim(),
101
141
  closedAt: raw.closedAt == null ? null : String(raw.closedAt),
102
142
  outcome: ['done', 'cancelled', 'missed'].includes(String(raw.outcome)) ? String(raw.outcome) : null,
103
143
  reason: raw.reason == null ? null : clipText(raw.reason, 200, ''),
104
144
  }
105
145
  }
106
146
 
147
+ /**
148
+ * 这条约定「到点的那个瞬间」是哪一刻(毫秒)。没有时刻的返回 null。
149
+ * 用本地时间拼:她说的 08:00 是她那边的 08:00,不是 UTC 的。
150
+ */
151
+ export function momentOf(appt) {
152
+ if (!appt || !isDay(appt.due) || !isTime(appt.time)) return null
153
+ const [y, m, d] = String(appt.due).split('-').map(Number)
154
+ const [hh, mm] = String(appt.time).split(':').map(Number)
155
+ const t = new Date(y, m - 1, d, hh, mm, 0, 0).getTime()
156
+ return Number.isFinite(t) ? t : null
157
+ }
158
+
159
+ /** 到点后过去了几分钟(没到点或没时刻返回 null)。 */
160
+ export function lateMinutesOf(appt, now = Date.now()) {
161
+ const at = momentOf(appt)
162
+ if (at == null) return null
163
+ const late = Math.floor((Number(now) - at) / 60_000)
164
+ return late < 0 ? null : late
165
+ }
166
+
107
167
  /** 读全部预约。文件坏了/没有都只当空,永不抛。 */
108
168
  export async function readAppointments(root = rootDir()) {
109
169
  const raw = await readJson(appointPath(root), [])
@@ -118,20 +178,35 @@ export async function writeAppointments(root, list) {
118
178
  return rows
119
179
  }
120
180
 
121
- /** 未关掉的,按日子从近到远。 */
181
+ /** 未关掉的,按日子从近到远;同一天按时刻排。 */
122
182
  export function openAppointments(list, { now = Date.now() } = {}) {
123
183
  const today = dateKey(new Date(now))
124
184
  return (Array.isArray(list) ? list : [])
125
185
  .filter((a) => a?.status === 'open')
126
- .sort((a, b) => dayNumber(a.due) - dayNumber(b.due) || String(a.created).localeCompare(String(b.created)))
127
- .map((a) => ({ ...a, days: daysBetween(today, a.due) }))
186
+ .sort((a, b) =>
187
+ dayNumber(a.due) - dayNumber(b.due)
188
+ || String(a.time ?? '').localeCompare(String(b.time ?? ''))
189
+ || String(a.created).localeCompare(String(b.created)))
190
+ .map((a) => ({ ...a, days: daysBetween(today, a.due), at: momentOf(a) }))
191
+ }
192
+
193
+ /**
194
+ * 到点了、还没提过的约定(从早到晚)。
195
+ *
196
+ * 2026-11-18(issue #149):带时刻的按「那一刻」算,跟日子无关——
197
+ * 08:00 的约定不会等到晚上 20:00 的作息窗口。老形状(只写日子)
198
+ * 还是只看日子,到当天就算到点。
199
+ */
200
+ export async function dueAppointments(root = rootDir(), now = Date.now()) {
201
+ const rows = openAppointments(await readAppointments(root), { now })
202
+ .filter((a) => !a.notifiedAt)
203
+ .filter((a) => (a.at != null ? Number(now) >= a.at : a.days <= 0))
204
+ return rows
128
205
  }
129
206
 
130
207
  /** 到点、还没提过的那一条。过期了也返回——晚几天也是欠着,不替她抹掉。 */
131
208
  export async function dueAppointment(root = rootDir(), now = Date.now()) {
132
- const today = dateKey(new Date(now))
133
- const rows = openAppointments(await readAppointments(root), { now })
134
- .filter((a) => !a.notifiedAt && a.days <= 0)
209
+ const rows = await dueAppointments(root, now)
135
210
  return rows[0] ?? null
136
211
  }
137
212
 
@@ -148,12 +223,14 @@ export async function nextAppointment(root = rootDir(), now = Date.now()) {
148
223
  const mutateAppointments = (root, fn) => mutateJson(appointPath(root), fn)
149
224
 
150
225
  /** 记下「这一条到点提过了」,免得同一个 tick 反复叫。 */
151
- export async function markNotified(root, id, now = Date.now()) {
226
+ export async function markNotified(root, id, now = Date.now(), { lateMinutes = null } = {}) {
152
227
  return mutateAppointments(root, async () => {
153
228
  const rows = await readAppointments(root)
154
229
  const hit = rows.find((a) => a.id === id)
155
230
  if (!hit || hit.status !== 'open' || hit.notifiedAt) return false
156
231
  hit.notifiedAt = new Date(now).toISOString()
232
+ const late = Number(lateMinutes)
233
+ if (Number.isFinite(late) && late > 0) hit.lateMinutes = Math.round(late)
157
234
  await writeAppointments(root, rows)
158
235
  return true
159
236
  })
@@ -161,17 +238,25 @@ export async function markNotified(root, id, now = Date.now()) {
161
238
 
162
239
  /**
163
240
  * 定一条约定。返回 { ok, id, note, echo }。
164
- * `due` 只收 YYYY-MM-DD;日子与字数都在这里挡,不信入参。
241
+ * `due` 只收 YYYY-MM-DD;`time` 可给可不给(给了就是「到点」而不是「到日子」);
242
+ * 日子与字数都在这里挡,不信入参。
243
+ *
244
+ * 2026-11-18(issue #149 / 用户 m01769、m01793):
245
+ * 带时刻的约定要「一定让她看见」,所以它不进作息窗口,也不等今天抽的落点;
246
+ * 他答没答应只决定措辞(`askId` 对到那张确认卡),不决定叫不叫。
165
247
  */
166
- export async function makeAppointment(root = rootDir(), { what, due, now = Date.now() } = {}) {
248
+ export async function makeAppointment(root = rootDir(), { what, due, time, askId, now = Date.now() } = {}) {
167
249
  const text = String(what ?? '').replace(/\s+/g, ' ').trim()
168
250
  const day = String(due ?? '').trim()
251
+ const at = time == null || String(time).trim() === '' ? null : String(time).trim()
169
252
  const today = dateKey(new Date(now))
170
253
  if (text.length < 4) return { ok: false, id: '', note: '要做的那件事太短了,说清楚一点。' }
171
254
  if (text.length > APPOINT_TEXT_MAX) {
172
255
  return { ok: false, id: '', note: `太长,压到 ${APPOINT_TEXT_MAX} 字以内。` }
173
256
  }
174
257
  if (!isDay(day)) return { ok: false, id: '', note: '日子要写成 2026-11-11 这样。' }
258
+ if (at != null && !isTime(at)) return { ok: false, id: '', note: '时刻要写成 08:00 这样,24 小时制。' }
259
+ if (at != null && day === today) return { ok: false, id: '', note: '带时刻的约定最早只能约到明天。' }
175
260
  const gap = daysBetween(today, day)
176
261
  if (gap < APPOINT_MIN_DAYS) return { ok: false, id: '', note: '最早只能约到明天。' }
177
262
  if (gap > APPOINT_MAX_DAYS) return { ok: false, id: '', note: `最远只能约到 ${APPOINT_MAX_DAYS} 天后。` }
@@ -180,7 +265,7 @@ export async function makeAppointment(root = rootDir(), { what, due, now = Date.
180
265
  const rows = await readAppointments(root)
181
266
  if (rows.length >= APPOINT_MAX) return { ok: false, id: '', note: '预约簿满了,先关掉几条旧的。' }
182
267
  const open = openAppointments(rows, { now })
183
- const same = open.find((a) => a.due === day && a.what === text)
268
+ const same = open.find((a) => a.due === day && (a.time ?? null) === at && a.what === text)
184
269
  if (same) return { ok: true, id: same.id, note: '这件事之前就约好了。', echo: same.what }
185
270
  if (open.length >= APPOINT_OPEN_MAX) {
186
271
  return { ok: false, id: '', note: `手上已经有两件没做完的约定了,先把它们收掉。` }
@@ -188,9 +273,11 @@ export async function makeAppointment(root = rootDir(), { what, due, now = Date.
188
273
  const row = normalizeAppoint({
189
274
  id: newAppointId(now),
190
275
  due: day,
276
+ time: at,
191
277
  what: text,
192
278
  created: new Date(now).toISOString(),
193
279
  status: 'open',
280
+ askId: askId ?? null,
194
281
  })
195
282
  rows.push(row)
196
283
  await writeAppointments(root, rows)
@@ -263,7 +350,9 @@ export async function listAppointments(root = rootDir(), { limit = APPOINT_SHOW_
263
350
  if (!rows.length) return { ok: true, note: '这会儿没有约好的事。', text: '' }
264
351
  const lines = rows.map((a) => {
265
352
  const when = a.days === 0 ? '今天' : a.days > 0 ? `还有 ${a.days} 天` : `已经过了 ${-a.days} 天`
266
- return `- ${a.due}(${when}):「${a.what}」`
353
+ const at = a.time ? ` ${a.time}` : ''
354
+ const late = a.notifiedAt && a.lateMinutes ? `(晚 ${a.lateMinutes} 分钟叫的)` : ''
355
+ return `- ${a.due}${at}(${when}):「${a.what}」${late}`
267
356
  })
268
357
  return { ok: true, note: '预约簿', text: lines.join('\n') }
269
358
  } catch {
@@ -271,18 +360,50 @@ export async function listAppointments(root = rootDir(), { limit = APPOINT_SHOW_
271
360
  }
272
361
  }
273
362
 
363
+ /** 把毫秒换成她那边的时间 HH:MM。 */
364
+ function clockOf(ms) {
365
+ const t = new Date(Number(ms))
366
+ return `${String(t.getHours()).padStart(2, '0')}:${String(t.getMinutes()).padStart(2, '0')}`
367
+ }
368
+
274
369
  /**
275
- * 到点那天她醒来的第一段处境。
276
- * 只陈述她约了什么、日子到了;不替她判断他会不会来。
370
+ * 到点那一刻她看到的处境(2026-11-18 改写,用户 m01744 / m01769 / m01793)。
371
+ *
372
+ * 这里只陈述发生过什么:约的是哪天几点、现在几点、他当时怎么答的、这条问没问过。
373
+ * 不替她判断「他不在」——DSH 开着的时候,他可能就守在窗口旁等她先开口;
374
+ * 只有她根本没被叫起来(过点很久,超过半小时),才写清「那会儿没开着」。
375
+ * 最后一句一定是她自己的:做不做、怎么做,她自己定。
277
376
  */
278
- export function appointPrompt(appt, now = Date.now()) {
279
- const today = dateKey(new Date(now))
280
- const late = daysBetween(appt?.due, today)
281
- const when = late <= 0 ? '就是今天' : `已经过了 ${late} 天`
282
- return fillOwner(
283
- `你跟{T}约好的日子${when}(${appt?.due}),约的是:「${appt?.what}」。` +
284
- '现在先说这件事:你自己做到没有,{T}有没有来。没来也别替{T}找理由。',
285
- )
377
+ export function appointPrompt(appt, now = Date.now(), { answer = null } = {}) {
378
+ const due = String(appt?.due ?? '')
379
+ const time = isTime(appt?.time) ? String(appt.time) : ''
380
+ const late = lateMinutesOf(appt, now)
381
+ const hhmm = clockOf(now)
382
+ const head = time
383
+ ? `你和{T}约好的事在今天 ${time}(${due}):「${appt?.what}」。`
384
+ : `你跟{T}约好的日子${daysBetween(due, dateKey(new Date(now))) <= 0 ? '就是今天' : `已经过了 ${daysBetween(due, dateKey(new Date(now)))} 天`}(${due}),约的是:「${appt?.what}」。`
385
+
386
+ let whenLine = ''
387
+ if (time && late != null) {
388
+ if (late <= APPT_GRACE_MS / 60_000) whenLine = '到点了。'
389
+ else if (late < 30) whenLine = `到点了,这会儿已经 ${hhmm},晚了 ${late} 分钟。`
390
+ else whenLine = `到点了。本来约的是 ${time},那会儿我这边没开着,现在 ${hhmm}。`
391
+ }
392
+
393
+ const verdict = String(answer?.verdict ?? '')
394
+ let deal = ''
395
+ if (verdict === 'approve') deal = '他当时答应了这件事。'
396
+ else if (verdict === 'later') deal = '他当时说「以后再说」——不是答应,也不是拒绝。'
397
+ else if (verdict === 'reject') deal = '他当时说这次不行,这条本该作废;现在它还在。'
398
+ else if (verdict === 'unanswered') deal = '你问过他,一直没人答。'
399
+ else if (verdict === 'pending') deal = '你问过他,他还没答。'
400
+ else if (appt?.askId) deal = '你问过他,他还没答。'
401
+ else if (time) deal = '这条你还没跟{T}对过口——现在先问一句,别自己替他答应。'
402
+
403
+ const tail = time
404
+ ? '到点了不等于你要交作业:做不做、怎么做,你自己定。'
405
+ : '现在先说这件事:你自己做到没有,{T}有没有来。没来也别替{T}找理由。'
406
+ return fillOwner([head, whenLine, deal, tail].filter(Boolean).join(''))
286
407
  }
287
408
 
288
409
  /** 预约簿的一次操作。没写 action 的按「新约一条」走。 */
@@ -299,8 +420,11 @@ export function registerAppoint(ctx, deps = {}) {
299
420
  name: 'her_appoint',
300
421
  description:
301
422
  '跟{T}约一件具体的事:写清哪一天、要做什么。到那天你醒来会先想起它。' +
302
- '约的时候给 what 和 due(日子写成 2026-11-11);看预约簿给 action:"list";' +
303
- '改日子给 action:"move" 和 newDue;做到了给 action:"done";' +
423
+ '约的时候给 what 和 due(日子写成 2026-11-11);想定到几点就给 time(写成 08:00)——' +
424
+ '带时刻的约定不看作息时间,到点一定让你看见,晚几分钟也会写清晚了多久。' +
425
+ '想让这件事变成两个人都点过头的事,约好之后再用 ask_owner 问一句(kind 填 appoint,subject 写这条的编号);' +
426
+ '不问也会叫,只是到点会写「这条还没对过口」。' +
427
+ '看预约簿给 action:"list";改日子给 action:"move" 和 newDue;做到了给 action:"done";' +
304
428
  '不做了给 action:"cancel",并说一句 reason。',
305
429
  parameters: toJsonSchema({
306
430
  action: {
@@ -316,6 +440,10 @@ export function registerAppoint(ctx, deps = {}) {
316
440
  type: 'string',
317
441
  description: '哪一天,写成 2026-11-11。最早明天,最远 60 天后。',
318
442
  },
443
+ time: {
444
+ type: 'string',
445
+ description: '可选:几点,写成 08:00(24 小时制)。给了就按这一刻叫,不看作息时间;不给就只按日子。',
446
+ },
319
447
  id: { type: 'string', description: '预约的编号。手里没有就不用给,给 what 也行。' },
320
448
  newDue: { type: 'string', description: '改期时改成哪一天。' },
321
449
  reason: { type: 'string', description: '取消时为什么,必填。' },
@@ -341,7 +469,8 @@ export function registerAppoint(ctx, deps = {}) {
341
469
  if (act === 'done') return [{ type: 'text', text: out.ok ? '[记下了]' : `[没收掉:${out.note}]` }]
342
470
  if (act === 'cancel') return [{ type: 'text', text: out.ok ? '[取消了]' : `[没取消:${out.note}]` }]
343
471
  if (!out.ok) return [{ type: 'text', text: `[没约上:${out.note}]` }]
344
- return [{ type: 'text', text: `[约好了:${args?.due ?? ''} ${out.echo ?? ''}]` }]
472
+ const at = String(args?.time ?? '').trim()
473
+ return [{ type: 'text', text: `[约好了:${args?.due ?? ''}${at ? ` ${at}` : ''} ${out.echo ?? ''}]` }]
345
474
  },
346
475
  },
347
476
  async execute(args, exec) {
@@ -363,7 +492,7 @@ export function registerAppoint(ctx, deps = {}) {
363
492
  reason: args?.reason,
364
493
  })
365
494
  }
366
- return makeAppointment(root, { what: args?.what, due: args?.due })
495
+ return makeAppointment(root, { what: args?.what, due: args?.due, time: args?.time })
367
496
  },
368
497
  }),
369
498
  )
package/lib/ask.js CHANGED
@@ -39,14 +39,27 @@ import { askInChat, picked } from './askinchat.js'
39
39
  import { tsMs } from './schema.js'
40
40
  import { logLine } from './log.js'
41
41
  import { fillOwner } from './pronoun.js'
42
+ import { closeAppointment, openAppointments, readAppointments } from './appoint.js'
42
43
 
43
- /** 允许的用途。前三个不落实权限;time / rest 会真改东西。 */
44
- export const ASK_KINDS = Object.freeze(['need-file', 'need-tool', 'time', 'rest', 'other', 'rule'])
44
+ /**
45
+ * 允许的用途。need-file / need-tool / other / rule 不落实权限;
46
+ * time / rest 会真改东西;appoint 是「为某条约定问一句」(2026-11-18,issue #149)。
47
+ */
48
+ export const ASK_KINDS = Object.freeze(['need-file', 'need-tool', 'time', 'rest', 'other', 'rule', 'appoint'])
45
49
 
46
50
  /** 每天最多问几次、每周最多问几次(写死,不进配置)。 */
47
51
  export const ASK_PER_DAY = 1
48
52
  export const ASK_PER_WEEK = 3
49
53
 
54
+ /**
55
+ * 约定类的确认一天最多问几次(2026-11-18)。
56
+ *
57
+ * 为什么不占上面那 1/3:那是她「替自己争一件事」的额度,被约定挤掉就变成
58
+ * 他答应一个早安、她就少一次为自己说话的机会。这类只是把两个人已经说过的
59
+ * 事记成两个人都点过头,上限和同时能挂的约定数对齐(APPOINT_OPEN_MAX = 2)。
60
+ */
61
+ export const APPOINT_ASK_PER_DAY = 2
62
+
50
63
  /** kind=time 的时段,和 schema.js 存得下的一样。 */
51
64
  const HHMM = /^([01]\d|2[0-3]):[0-5]\d$/
52
65
 
@@ -77,6 +90,19 @@ export function answersByAsk(events = []) {
77
90
  return m
78
91
  }
79
92
 
93
+ /**
94
+ * 约定编号 → 为它问过的那张卡(ask 事件)。同一件事问过两次只认最后一次。
95
+ * 2026-11-18:约定到点时用这个看他当时到底怎么答的,不靠猜。
96
+ */
97
+ export function askForAppoint(events = []) {
98
+ const m = new Map()
99
+ for (const e of asksOf(events)) {
100
+ const id = String(e?.ask?.appointId ?? '')
101
+ if (id) m.set(id, e)
102
+ }
103
+ return m
104
+ }
105
+
80
106
  /** 还没答的请求(按时间从早到晚)。 */
81
107
  export function pendingAsks(events = [], now = Date.now()) {
82
108
  const done = answersByAsk(events)
@@ -86,9 +112,9 @@ export function pendingAsks(events = [], now = Date.now()) {
86
112
  .sort((a, b) => tsMs(a) - tsMs(b))
87
113
  }
88
114
 
89
- /** 配额:今天问过没有、最近七天问过几次。 */
115
+ /** 配额:今天问过没有、最近七天问过几次。约定类的确认不算在这里(见 APPOINT_ASK_PER_DAY)。 */
90
116
  export function quotaOf(events = [], { now = Date.now(), dk = dateKey() } = {}) {
91
- const asks = asksOf(events)
117
+ const asks = asksOf(events).filter((e) => String(e?.ask?.kind ?? '') !== 'appoint')
92
118
  // 真的事件上 day 是成长第几天(一个整数),不是日期,只能按时间算。
93
119
  const today = asks.filter((e) => dateKey(new Date(tsMs(e) || now)) === dk).length
94
120
  const week = asks.filter((e) => now - tsMs(e) < 7 * 24 * 3600 * 1000).length
@@ -102,6 +128,18 @@ export function quotaOf(events = [], { now = Date.now(), dk = dateKey() } = {})
102
128
  }
103
129
  }
104
130
 
131
+ /** 约定类确认的日配额(不复用上面那 1/3)。 */
132
+ export function appointAskQuotaOf(events = [], { now = Date.now(), dk = dateKey() } = {}) {
133
+ const asks = asksOf(events).filter((e) => String(e?.ask?.kind ?? '') === 'appoint')
134
+ const today = asks.filter((e) => dateKey(new Date(tsMs(e) || now)) === dk).length
135
+ return {
136
+ day: today,
137
+ perDay: APPOINT_ASK_PER_DAY,
138
+ ok: today < APPOINT_ASK_PER_DAY,
139
+ why: today >= APPOINT_ASK_PER_DAY ? `今天已经问过 ${APPOINT_ASK_PER_DAY} 次约定了` : '',
140
+ }
141
+ }
142
+
105
143
  /** 她今天请过假吗(rest 被同意后写一条 meta)。 */
106
144
  export function restedToday(events = [], dk = dateKey()) {
107
145
  return events.some((e) => e?.type === 'meta' && String(e.text ?? '').startsWith(`rest:${dk}`))
@@ -149,6 +187,12 @@ async function applyVerdict(root, askEv, verdict, { log = () => {} } = {}) {
149
187
  // 都不重提、不进提示词,只让观测台和后来的她查得到。
150
188
  const mark = verdict === 'later' ? 'ask-later' : 'ask-no'
151
189
  await appendEvent({ type: 'meta', text: `${mark}:${askEv.id}` }, ctx, root)
190
+ // 约定被驳回就地作废:到点不该再叫她(2026-11-18)。「以后再说」不作废——
191
+ // 他没答应,但这条还挂着,到点会写清「他说以后再说」。
192
+ if (kind === 'appoint' && verdict === 'reject') {
193
+ const id = String(askEv?.ask?.value?.appointId ?? askEv?.ask?.appointId ?? '')
194
+ if (id) await closeAppointment(root, { id, action: 'cancel', reason: '他没答应这件事' })
195
+ }
152
196
  return
153
197
  }
154
198
  if (kind === 'time') {
@@ -338,7 +382,9 @@ export function registerAsk(ctx, deps = {}) {
338
382
  name: 'ask_owner',
339
383
  description:
340
384
  '有事想问那个人同不同意的时候用。只问真的影响你自己的事:今天要不要歇、能不能换个作息、' +
341
- '能不能要一个文件或一个工具、你想给自己立一条什么规矩。一天最多问一次,一周最多三次。' +
385
+ '能不能要一个文件或一个工具、你想给自己立一条什么规矩。一天最多问一次,一周最多三次(约定确认另算,见下)。' +
386
+ '已经约好一件事、想把「两个人都点过头」记下来时,用 kind:"appoint"、subject 填约定编号——' +
387
+ '这一类不算在那三次里,到点会按他当时的答复写清是答应了、还没答,还是没问成。' +
342
388
  '不需要解释你在用哪个工具,也不用道谢。',
343
389
  parameters: toJsonSchema({
344
390
  question: {
@@ -350,7 +396,7 @@ export function registerAsk(ctx, deps = {}) {
350
396
  type: 'string',
351
397
  required: true,
352
398
  enum: ASK_KINDS,
353
- description: 'need-file / need-tool / time / rest / rule / other',
399
+ description: 'need-file / need-tool / time / rest / rule / other / appoint(为一条约定问一句)',
354
400
  },
355
401
  subject: {
356
402
  type: 'string',
@@ -420,7 +466,8 @@ export function registerAsk(ctx, deps = {}) {
420
466
  }
421
467
 
422
468
  const { events } = await readEvents(root)
423
- const quota = quotaOf(events)
469
+ // 约定类的确认不占「替自己争一件事」的额度:那是另一本账(2026-11-18)。
470
+ const quota = kind === 'appoint' ? { ok: true } : quotaOf(events)
424
471
  if (!quota.ok) return { ok: false, note: quota.why }
425
472
 
426
473
  const options = optionsOf(args?.options)
@@ -439,6 +486,22 @@ export function registerAsk(ctx, deps = {}) {
439
486
  }
440
487
  }
441
488
 
489
+ // 为一条约定问一句(2026-11-18,issue #149):subject 必须是还没关掉的约定编号。
490
+ let appointId = ''
491
+ if (kind === 'appoint') {
492
+ appointId = String(args?.subject ?? '').trim()
493
+ if (!appointId) {
494
+ return { ok: false, note: fillOwner('kind=appoint 要把约定编号写在 subject 里(her_appoint 约完会给)。') }
495
+ }
496
+ const open = openAppointments(await readAppointments(root))
497
+ if (!open.some((a) => a.id === appointId)) {
498
+ return { ok: false, note: '预约簿里没有这一条还没关掉的约定。' }
499
+ }
500
+ const aq = appointAskQuotaOf(events)
501
+ if (!aq.ok) return { ok: false, note: aq.why }
502
+ value.appointId = appointId
503
+ }
504
+
442
505
  const { config } = await loadConfig(root)
443
506
  const model = deriveSelf(events, { growthDays: config.growthDays })
444
507
  const ev = await appendEvent({
package/lib/at.js CHANGED
@@ -92,18 +92,43 @@ export function repliedToOthers(events) {
92
92
  /** B 站给的 uri 换成能点的链接;认不出来的就留空,不硬拼。 */
93
93
  export function mentionUrl(m = {}) {
94
94
  const uri = String(m.uri ?? '').trim()
95
- if (/^https?:\/\//i.test(uri)) return uri
95
+ const parent = Number(m.parentRpid) || 0
96
+ // 接口给的 uri 是整条视频的地址;补一个 #reply<rpid> 才落到被 @ 的那条评论上。
97
+ const anchor = parent > 0 && !uri.includes('#') ? `#reply${parent}` : ''
98
+ if (/^https?:\/\//i.test(uri)) return `${uri}${anchor}`
96
99
  const video = /^bilibili:\/\/video\/(\d+)/.exec(uri)
97
- if (video) return `https://www.bilibili.com/video/av${video[1]}`
100
+ if (video) return `https://www.bilibili.com/video/av${video[1]}${anchor}`
98
101
  const dynamic = /^bilibili:\/\/dynamic\/(\d+)/.exec(uri)
99
- if (dynamic) return `https://t.bilibili.com/${dynamic[1]}`
102
+ if (dynamic) return `https://t.bilibili.com/${dynamic[1]}${anchor}`
100
103
  return ''
101
104
  }
102
105
 
106
+ /**
107
+ * 告诉她「这条该用哪些参数回」。
108
+ *
109
+ * 2026-11-19:以前消息中心只给到视频链接,楼中楼的编号丢了,她想回也只能干瞪眼。
110
+ * 编号全是接口原样给的,不猜;缺一个就不给这句,省得她照着一半的参数去试。
111
+ *
112
+ * 2026-11-19 二修:楼根和被回那条是同一个(别人在顶层评论里 @ 她)时也要把楼根写出来。
113
+ * 那时看着多余——只要 parent 就够;但回的时候「她不认识这一楼」这条判断要靠楼根过闸,
114
+ * 少写这一句,她在没出现过的视频下就回不了。
115
+ */
116
+ export function mentionReplyHint(m = {}) {
117
+ const bvid = String(m.bvid ?? '').trim()
118
+ const parent = Number(m.parentRpid) || 0
119
+ const root = Number(m.rootRpid) || 0
120
+ if (!bvid || !parent) return ''
121
+ const bits = ['kind 填 reply', `bvid 填 ${bvid}`]
122
+ if (root) bits.push(`rootRpid 填 ${root}`)
123
+ bits.push(`parentRpid 填 ${parent}`)
124
+ return ` 要回这一条:bili_speak(${bits.join(',')})`
125
+ }
126
+
103
127
  /** 一条 @ 的正文(原话优先,没有正文就说清「递了个东西」) */
104
128
  function mentionText(m = {}) {
105
- const desc = String(m.desc ?? '').trim()
106
- if (desc) return desc
129
+ // 2026-11-19:正文现在只给在 source_content 里,desc 已经不发了。
130
+ const body = String(m.sourceContent ?? '').trim() || String(m.desc ?? '').trim()
131
+ if (body) return body
107
132
  const title = String(m.title ?? '').trim()
108
133
  return title ? `(在《${title}》里 @ 了你,没有写话)` : '(@ 了你,没有写话)'
109
134
  }
@@ -179,6 +204,8 @@ export function renderMentions(list) {
179
204
  const where = x.title ? `视频《${oneLine(x.title, 40)}》` : 'B 站'
180
205
  lines.push(`- ${who}(${where}):${oneLine(x.text, 200)}`)
181
206
  if (x.url) lines.push(` ${x.url}`)
207
+ const hint = mentionReplyHint(x)
208
+ if (hint) lines.push(hint)
182
209
  }
183
210
  }
184
211
 
@@ -196,6 +223,8 @@ export function renderMentions(list) {
196
223
  const where = x.title ? `视频《${oneLine(x.title, 40)}》` : 'B 站'
197
224
  lines.push(`- ${who}(${where}):${oneLine(x.text, 200)}`)
198
225
  if (x.url) lines.push(` ${x.url}`)
226
+ const hint = mentionReplyHint(x)
227
+ if (hint) lines.push(hint)
199
228
  }
200
229
  }
201
230
  return fillOwner(lines.join('\n'))
package/lib/backup.js CHANGED
@@ -41,6 +41,7 @@ import { promises as fs } from 'node:fs'
41
41
  import { dirname, extname, join, relative, resolve, sep } from 'node:path'
42
42
  import { rootDir, writeAtomic } from './store.js'
43
43
  import { EVENT_SCHEMA_VERSION } from './schema.js'
44
+ import { logLine } from './log.js'
44
45
 
45
46
  /** 备份文件里写的格式标记。改字段结构就换它。 */
46
47
  export const BACKUP_FORMAT = 'dsh-fish-backup/1'
@@ -335,7 +336,10 @@ export async function collectBackup(
335
336
  let names
336
337
  try {
337
338
  names = await fs.readdir(dir, { withFileTypes: true })
338
- } catch {
339
+ } catch (err) {
340
+ // 2026-11-20(用户 m03134):这里静默 return 意味着「整个目录的文件在备份里凭空消失」,
341
+ // 而回执上只会少几个文件,没有一行线索。收不到某一个子目录时至少要留痕。
342
+ logLine('warn', ['备份:这个目录读不进来,里面的文件这次不装', relative(root, dir).split(sep).join('/'), String(err?.message ?? err).slice(0, 120)], root)
339
343
  return
340
344
  }
341
345
  for (const e of names) {
@@ -378,7 +382,10 @@ export async function collectBackup(
378
382
  let st
379
383
  try {
380
384
  st = await fs.stat(full)
381
- } catch {
385
+ } catch (err) {
386
+ // 2026-11-20(用户 m03134):这一条以前只写进包里的 skipped 列表,日志里没有。
387
+ // 「备份里少了几个文件」是用户会专门来问的事,留一行够定位。
388
+ logLine('warn', ['备份:这个文件 stat 不到,按读不到处理', rel, String(err?.message ?? err).slice(0, 120)], root)
382
389
  out.push({ rel, why: '读不到' })
383
390
  continue
384
391
  }
@@ -443,7 +450,8 @@ export async function collectBackup(
443
450
  let entry
444
451
  try {
445
452
  entry = await read(f)
446
- } catch {
453
+ } catch (err) {
454
+ logLine('warn', ['备份:这个文件读不出来,这次不装', f.rel, String(err?.message ?? err).slice(0, 120)], root)
447
455
  out.push({ rel: f.rel, why: '读失败' })
448
456
  continue
449
457
  }
@@ -489,7 +497,8 @@ export async function collectBackup(
489
497
  let entry
490
498
  try {
491
499
  entry = await read(f)
492
- } catch {
500
+ } catch (err) {
501
+ logLine('warn', ['备份:这个文件读不出来,这次不装', f.rel, String(err?.message ?? err).slice(0, 120)], root)
493
502
  out.push({ rel: f.rel, why: '读失败' })
494
503
  continue
495
504
  }
@@ -707,6 +716,8 @@ export async function restoreBackup(bundle, root = rootDir(), { now = new Date()
707
716
  await fs.rename(root, quarantined)
708
717
  } catch (err) {
709
718
  // 跨盘 / 被占用:不部分搬走,直接如实报错
719
+ // 2026-11-20(用户 m03134):恢复失败是用户最慌的一类事,日志里必须留一行。
720
+ logLine('warn', ['恢复:旧档搬不动,这次恢复中止', root, '→', quarantined, String(err?.code ?? err)], root)
710
721
  return {
711
722
  ok: false,
712
723
  why: `旧档搬不动(${String(err?.code ?? err)}),这次恢复什么都没改`,
@@ -726,6 +737,7 @@ export async function restoreBackup(bundle, root = rootDir(), { now = new Date()
726
737
  }
727
738
  if (hadOld) await preservePressureObservations(quarantined, root)
728
739
  } catch (err) {
740
+ logLine('warn', ['恢复:写到一半失败,旧档还完好', '旧档', quarantined, '写不动的是', root, String(err?.message ?? err).slice(0, 160)], root)
729
741
  return {
730
742
  ok: false,
731
743
  why: `写到一半失败:${String(err?.message ?? err)}。旧档完好,在 ${quarantined}(如果它不是空的)`,