@ssamurias/dsh-fish 1.0.0 → 1.0.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/doing.js ADDED
@@ -0,0 +1,316 @@
1
+ /**
2
+ * doing.js —— 主动做事(2026-11-14,用户 m01237 定案)
3
+ *
4
+ * 她可以不只是开口,也可以自己动手做一件事。这里只做三件事:
5
+ * 1. 判断「这一轮算不算动手回合」(scheduler 在投递前打标记);
6
+ * 2. 在动手回合里给消耗类工具上闸:一轮一件、一天一件、同一件隔三天、
7
+ * 连着三次同类歇一周;
8
+ * 3. 把真的做成的事记成 `did:`(只认工具真的返回了,不认她嘴上说做了)。
9
+ *
10
+ * 三条边界:
11
+ * - 分类不靠工具名猜。自家工具写死;外面的工具默认 effect(不拦、也不自动
12
+ * 当消耗类摆上桌),用户可以在设置里改。宿主只把工具名给插件,看不到
13
+ * 工具定义,所以没有「按声明自动识别」这回事——说清楚比猜一个强。
14
+ * - 只在动手回合生效。他自己找她说话、定时叫醒,都不经过这里。
15
+ * - 数字只在插件内部用,不进她的身份文档,也不回显给她。
16
+ */
17
+
18
+ import { tsMs } from './schema.js'
19
+ import { appendEvent, readEvents } from './store.js'
20
+ import { loadConfig } from './settings.js'
21
+
22
+ export const DOING_DEFAULTS = Object.freeze({
23
+ enabled: false,
24
+ consumePerDay: 1,
25
+ itemCooldownDays: 3,
26
+ bingeLimit: 3,
27
+ bingeRestDays: 7,
28
+ })
29
+
30
+ export const DOING_CLASSES = Object.freeze(['produce', 'consume', 'effect', 'self'])
31
+
32
+ /** 自家工具的分类。read_image 也算「看」,按消耗类算。 */
33
+ export const OWN_CLASS = Object.freeze({
34
+ bili_look: 'consume',
35
+ bili_watch: 'consume',
36
+ bili_sub: 'consume',
37
+ read_image: 'consume',
38
+ her_diary: 'produce',
39
+ bili_speak: 'effect',
40
+ her_leave: 'effect',
41
+ bring_back: 'effect',
42
+ growth_commit: 'self',
43
+ her_recall: 'self',
44
+ her_note: 'self',
45
+ her_appoint: 'self',
46
+ her_dream: 'self',
47
+ her_say: 'self',
48
+ ask_owner: 'self',
49
+ ask_pronoun: 'self',
50
+ })
51
+
52
+ const MARK_MS = 2 * 3600_000
53
+ const DID = 'did:'
54
+
55
+ /** 动手回合的标记只存在进程里;按会话分开,重启后没有标记也就不会误拦。 */
56
+ const turns = new Map()
57
+
58
+ function prune(now) {
59
+ for (const [sid, t] of turns) if (now - t.at > MARK_MS) turns.delete(sid)
60
+ }
61
+
62
+ function num(v, fallback, lo, hi) {
63
+ const n = Number(v)
64
+ if (!Number.isFinite(n)) return fallback
65
+ return Math.max(lo, Math.min(hi, Math.round(n)))
66
+ }
67
+
68
+ /** 读设置。键都在 config.proactive 下,和「主动搭话」共用一张卡。 */
69
+ export function doingConfig(config = {}) {
70
+ const raw = config && typeof config.proactive === 'object' && config.proactive ? config.proactive : {}
71
+ return {
72
+ enabled: raw.allowDoing === true,
73
+ consumePerDay: num(raw.consumePerDay, DOING_DEFAULTS.consumePerDay, 0, 6),
74
+ itemCooldownDays: num(raw.itemCooldownDays, DOING_DEFAULTS.itemCooldownDays, 0, 30),
75
+ bingeLimit: num(raw.bingeLimit, DOING_DEFAULTS.bingeLimit, 2, 10),
76
+ bingeRestDays: num(raw.bingeRestDays, DOING_DEFAULTS.bingeRestDays, 1, 60),
77
+ }
78
+ }
79
+
80
+ /** 工具分类:设置里的覆盖优先,其次自家表,最后按 effect(不拦、不自动摆上桌)。 */
81
+ export function classOf(name, config = {}) {
82
+ const n = String(name ?? '').trim()
83
+ if (!n) return 'effect'
84
+ const over = config?.proactive?.toolClasses
85
+ if (over && typeof over === 'object' && DOING_CLASSES.includes(over[n])) return over[n]
86
+ return OWN_CLASS[n] ?? 'effect'
87
+ }
88
+
89
+ /** 同一件事的键:优先 bvid/id/path,其次 query,最后退回工具名。 */
90
+ export function itemKey(name, args) {
91
+ const tool = String(name ?? '').trim() || 'tool'
92
+ let a = args
93
+ if (typeof a === 'string') {
94
+ try { a = JSON.parse(a) } catch { a = null }
95
+ }
96
+ if (!a || typeof a !== 'object') return tool
97
+ for (const k of ['bvid', 'id', 'path', 'file', 'query', 'keyword', 'title', 'name']) {
98
+ const v = a[k]
99
+ if (typeof v === 'string' && v.trim()) return `${tool}:${v.trim().slice(0, 60)}`
100
+ }
101
+ return tool
102
+ }
103
+
104
+ export function didText({ cls, tool, ok, key }) {
105
+ return `${DID}${cls}:${tool}:${ok ? 'ok' : 'fail'}:${key}`
106
+ }
107
+
108
+ /** `did:<cls>:<tool>:ok|fail:<key>`;key 放最后,路径里的冒号不会被切开。 */
109
+ export function parseDid(text) {
110
+ const s = String(text ?? '')
111
+ if (!s.startsWith(DID)) return null
112
+ const rest = s.slice(DID.length).split(':')
113
+ if (rest.length < 4) return null
114
+ const [cls, tool, flag, ...key] = rest
115
+ if (!DOING_CLASSES.includes(cls)) return null
116
+ return { cls, tool, ok: flag === 'ok', key: key.join(':') }
117
+ }
118
+
119
+ function didOf(events = []) {
120
+ const out = []
121
+ for (const e of events) {
122
+ if (e?.type !== 'meta') continue
123
+ const d = parseDid(e.text)
124
+ if (!d) continue
125
+ out.push({ ...d, ts: tsMs(e) || 0 })
126
+ }
127
+ return out.sort((a, b) => a.ts - b.ts)
128
+ }
129
+
130
+ function localDay(ms) {
131
+ const d = new Date(ms)
132
+ return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
133
+ }
134
+
135
+ function startOfLocalDay(ms) {
136
+ const d = new Date(ms)
137
+ d.setHours(0, 0, 0, 0)
138
+ return d.getTime()
139
+ }
140
+
141
+ /**
142
+ * 今天/最近做过什么。只数真的成功了的(ok)。
143
+ * @returns {{consumeToday:number, byClass:Object, last:Array, lastAt:number}}
144
+ */
145
+ export function doingUsage(events = [], now = Date.now()) {
146
+ const all = didOf(events).filter((d) => d.ok)
147
+ const consumeToday = all.filter((d) => d.cls === 'consume' && d.ts >= startOfLocalDay(now)).length
148
+ const byClass = { produce: 0, consume: 0, effect: 0, self: 0 }
149
+ for (const d of all) byClass[d.cls] = (byClass[d.cls] ?? 0) + 1
150
+ return { consumeToday, byClass, last: all.slice(-6), lastAt: all.length ? all[all.length - 1].ts : 0 }
151
+ }
152
+
153
+ /**
154
+ * 消耗类调用能不能放行。只看消耗类;产出/外效/自己的事不设日限。
155
+ * @returns {{ok:true, cls:string, key:string} | {ok:false, reason:string, code:string}}
156
+ */
157
+ export function checkDoing({ name, args, events = [], now = Date.now(), config = {} } = {}) {
158
+ const cfg = doingConfig(config)
159
+ const cls = classOf(name, config)
160
+ const key = itemKey(name, args)
161
+ const all = didOf(events).filter((d) => d.ok)
162
+
163
+ if (cfg.consumePerDay <= 0) {
164
+ return { ok: false, code: 'off', reason: '今天不做这样的事了。' }
165
+ }
166
+ const today = all.filter((d) => d.cls === 'consume' && d.ts >= startOfLocalDay(now)).length
167
+ if (today >= cfg.consumePerDay) {
168
+ return { ok: false, code: 'daily', reason: '今天已经做过这样的事了,明天再说。' }
169
+ }
170
+ const same = all.filter((d) => d.key === key && now - d.ts < cfg.itemCooldownDays * 86400_000)
171
+ if (same.length) {
172
+ return { ok: false, code: 'item', reason: '这件事前几天刚做过,过几天再说。' }
173
+ }
174
+ const tail = all.slice(-cfg.bingeLimit)
175
+ if (tail.length >= cfg.bingeLimit && tail.every((d) => d.cls === 'consume')) {
176
+ const last = tail[tail.length - 1].ts
177
+ if (now - last < cfg.bingeRestDays * 86400_000) {
178
+ return { ok: false, code: 'binge', reason: '连着做了几次,先歇几天。' }
179
+ }
180
+ }
181
+ return { ok: true, cls, key }
182
+ }
183
+
184
+ /** 这一轮是不是动手回合。会话对不上或超过两小时就当没有。 */
185
+ export function doingTurnOf(sessionId, now = Date.now()) {
186
+ const sid = String(sessionId ?? '')
187
+ if (!sid) return null
188
+ prune(now)
189
+ return turns.get(sid) ?? null
190
+ }
191
+
192
+ export function markDoingTurn(sessionId, now = Date.now()) {
193
+ if (!sessionId) return null
194
+ prune(now)
195
+ const t = { sessionId: String(sessionId), at: now, consumeUsed: false, calls: new Map() }
196
+ turns.set(t.sessionId, t)
197
+ return t
198
+ }
199
+
200
+ export function clearDoingTurn(sessionId) {
201
+ if (sessionId) turns.delete(String(sessionId))
202
+ else turns.clear()
203
+ }
204
+
205
+ /**
206
+ * 她自己的记录里点到过哪件手边的工具。
207
+ *
208
+ * 只认「记录原文里出现了工具名」的;不列全量工具清单——那是菜单,会把
209
+ * 处境变成派活。没点到就一个都不提。
210
+ */
211
+ export function mentionedTools(records = [], tools = []) {
212
+ const names = (Array.isArray(tools) ? tools : []).map((t) => String(t ?? '').trim()).filter(Boolean)
213
+ const said = (Array.isArray(records) ? records : []).map((m) => String(m?.text ?? '')).join('\n').toLowerCase()
214
+ if (!names.length || !said) return []
215
+ return names.filter((n) => {
216
+ const esc = n.toLowerCase().replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
217
+ return new RegExp(`(^|[^a-z0-9_])${esc}($|[^a-z0-9_])`).test(said)
218
+ }).slice(0, 3)
219
+ }
220
+
221
+ /** 给处境用的那一句。只给许可和边界,不写「你应该做点什么」。 */
222
+ export function doingSection({ material = [], loose = [], tools = [], notes = [] } = {}) {
223
+ const hinted = mentionedTools([...material, ...loose], tools)
224
+ const lead = hinted.length ? `你之前提过 ${hinted.join('、')},它们就在手边。` : ''
225
+ // 便条只作她自己的材料:不写「到期」「该做了」,最多两张,不列清单。
226
+ const own = (Array.isArray(notes) ? notes : [])
227
+ .map((n) => String(n?.text ?? '').trim())
228
+ .filter(Boolean)
229
+ .slice(0, 2)
230
+ .map((t) => (t.length > 40 ? `${t.slice(0, 40)}…` : t))
231
+ const mine = own.length ? `你自己记下的:${own.join(';')}。` : ''
232
+ return `${lead}${mine}这一轮是动手的:想做的那件事,如果手边有工具能做,就直接做,不用先把这件事说出来。手边有什么、各自能做什么,这一轮你看得到;没有对得上的,就照旧。做一件就收,不用接着做第二件;没有能做的,就什么都不做,也不用写解释。`
233
+ }
234
+
235
+ function sessionOf(exec) {
236
+ const s = exec?.agent?.session
237
+ if (typeof s === 'string') return s
238
+ return String(s?.id ?? exec?.agent?.sessionId ?? exec?.session?.id ?? exec?.sessionId ?? '')
239
+ }
240
+
241
+ function argsOf(exec) {
242
+ const a = exec?.args ?? exec?.arguments ?? exec?.call?.arguments ?? null
243
+ if (typeof a === 'string') {
244
+ try { return JSON.parse(a) } catch { return null }
245
+ }
246
+ return a
247
+ }
248
+
249
+ /**
250
+ * 注册两个观察点。pre-execute 负责拦,result 负责记账。
251
+ * 拿不到会话、不是动手回合、开关关着,一律 `next()` 放行——这里不是权限层。
252
+ */
253
+ export function registerDoingHooks(ctx, { root, log = () => {} } = {}) {
254
+ if (!ctx?.on) return () => {}
255
+ const offs = []
256
+
257
+ offs.push(ctx.on('tools/pre-execute', async (exec, next) => {
258
+ try {
259
+ const t = doingTurnOf(sessionOf(exec))
260
+ if (!t) return next()
261
+ const { config } = await loadConfig(root)
262
+ if (!doingConfig(config).enabled) return next()
263
+ const cls = classOf(exec?.name, config)
264
+ const key = itemKey(exec?.name, argsOf(exec))
265
+ const ref = String(exec?.callId ?? exec?.token ?? `${exec?.name}:${Date.now()}`)
266
+ // 消耗类之外也记一笔,好让 result 知道该写 did;但不拦。
267
+ if (cls === 'self') return next()
268
+ if (cls !== 'consume') {
269
+ t.calls.set(ref, { cls, tool: String(exec?.name ?? ''), key })
270
+ return next()
271
+ }
272
+ if (t.consumeUsed) {
273
+ return { kind: 'deny', reason: '这一轮已经做过一件了,做完就收。', info: { name: 'DoingLimit', code: 'DOING_TURN' } }
274
+ }
275
+ const { events } = await readEvents(root)
276
+ const verdict = checkDoing({ name: exec?.name, args: argsOf(exec), events, now: Date.now(), config })
277
+ if (!verdict.ok) {
278
+ log('doing', `拦下一次 ${exec?.name}:${verdict.code}`)
279
+ return { kind: 'deny', reason: verdict.reason, info: { name: 'DoingLimit', code: verdict.code.toUpperCase() } }
280
+ }
281
+ t.consumeUsed = true
282
+ t.calls.set(ref, { cls, tool: String(exec?.name ?? ''), key })
283
+ return next()
284
+ } catch {
285
+ return next()
286
+ }
287
+ }))
288
+
289
+ offs.push(ctx.on('tools/result', async (exec, result) => {
290
+ try {
291
+ const t = doingTurnOf(sessionOf(exec))
292
+ if (!t) return
293
+ const ref = String(exec?.callId ?? exec?.token ?? '')
294
+ let call = t.calls.get(ref)
295
+ if (!call && t.calls.size === 1) call = [...t.calls.values()][0]
296
+ if (!call) return
297
+ t.calls.delete(ref)
298
+ const ok = !(result?.isError === true || result?.ok === false)
299
+ await appendEvent(
300
+ { type: 'meta', text: didText({ cls: call.cls, tool: call.tool, ok, key: call.key }) },
301
+ { day: 0, stage: 1, source: 'system' },
302
+ root,
303
+ ).catch(() => {})
304
+ log('doing', `记下 ${call.tool} ${ok ? '做成' : '没做成'}`)
305
+ } catch { /* 观察点不改变调用结果 */ }
306
+ }))
307
+
308
+ return () => {
309
+ for (const off of offs) {
310
+ try {
311
+ if (typeof off === 'function') off()
312
+ else off?.off?.()
313
+ } catch { /* ignore */ }
314
+ }
315
+ }
316
+ }
package/lib/events.js CHANGED
@@ -97,7 +97,9 @@ export const CATALOG = [
97
97
  ? `${noHit} 站不住就改,并指出是哪一句话让你改的;站得住就说清它今天又赢了什么。`
98
98
  : `${noHit} 你原来那句还站得住吗?站不住就改,站得住就说清为什么。`
99
99
  // 2026-10-27(issue #4):同理,不保证「今天有素材」——只说可能碰到。
100
- return `你之前说过:「${b.text}」。今天你碰上了一点可能说明你错了一点点的事——也可能什么都没碰上。不管怎样,自己判断:${tail}`
100
+ // 2026-11-14(用户 m00704):把旧句子的 id 一起摆出来。她 70 条认领里只有 9 条带 refs,
101
+ // her_recall 一次没调用过——不是不想指,是手里没有可指的编号(dreamtable 早就这么做了)。
102
+ return `你之前说过:「${b.text}」(${b.id})。今天你碰上了一点可能说明你错了一点点的事——也可能什么都没碰上。不管怎样,自己判断:${tail}`
101
103
  },
102
104
  },
103
105
  {
@@ -556,7 +558,8 @@ export const CATALOG = [
556
558
  },
557
559
  prompt: (m, ctx) => {
558
560
  const line = String(ctx?.lastAfter?.('plan_make') || '').slice(0, 120)
559
- return `你跟{T}约好的那件事,到今天该有结果了。${line ? `你当时说的是:「${line}」。` : ''}先说你自己做到没有、做到哪一步;{T}那件,{T}愿意说就说,不追。{T}没做到,也别替{T}圆。`
561
+ const prog = progressLine(ctx)
562
+ return `你跟{T}约好的那件事,到今天该有结果了。${line ? `你当时说的是:「${line}」。` : ''}${prog}先说你自己做到没有、做到哪一步;{T}那件,{T}愿意说就说,不追。{T}没做到,也别替{T}圆。`
560
563
  },
561
564
  },
562
565
  {
@@ -575,7 +578,8 @@ export const CATALOG = [
575
578
  },
576
579
  prompt: (m, ctx) => {
577
580
  const line = String(ctx?.lastAfter?.('arc_try_start') || '').slice(0, 120)
578
- return `上次你说要试的那件事,现在到哪一步了?${line ? `你当时说的是:「${line}」。` : ''}只说实际发生的:做了什么、卡在哪一步、有没有停下来。`
581
+ const prog = progressLine(ctx)
582
+ return `上次你说要试的那件事,现在到哪一步了?${line ? `你当时说的是:「${line}」。` : ''}${prog}只说实际发生的:做了什么、卡在哪一步、有没有停下来。`
579
583
  },
580
584
  },
581
585
  {
@@ -587,7 +591,8 @@ export const CATALOG = [
587
591
  },
588
592
  prompt: (m, ctx) => {
589
593
  const line = String(ctx?.lastAfter?.('arc_try_mid') || '').slice(0, 120)
590
- return `这件事到今天该有个说法了:做成了,还是放弃了?${line ? `你当时说的是:「${line}」。` : ''}做成,说清是哪一步起了作用;放弃,也说清是哪一步让你停下的——别说「没时间」。`
594
+ const prog = progressLine(ctx)
595
+ return `这件事到今天该有个说法了:做成了,还是放弃了?${line ? `你当时说的是:「${line}」。` : ''}${prog}做成,说清是哪一步起了作用;放弃,也说清是哪一步让你停下的——别说「没时间」。`
591
596
  },
592
597
  },
593
598
  ]
@@ -598,6 +603,19 @@ function filledPrompt(t) {
598
603
  return { ...t, prompt: (...args) => fillOwner(t.prompt(...args)) }
599
604
  }
600
605
 
606
+ /**
607
+ * 便条上最近记的那一笔(2026-11-14,用户 m00209)。
608
+ *
609
+ * 约定到期、弧的中段与收尾都该看得见这件事**现在做到哪儿**,而不是只剩她当时那句表态。
610
+ * 有就只说一句;没有就一个字都不加(她没记过进展时,句子跟原来一模一样)。
611
+ */
612
+ function progressLine(ctx) {
613
+ const p = ctx?.inProgress
614
+ if (!p?.progress) return ''
615
+ const what = String(p.text ?? '').slice(0, 60)
616
+ return `你便条上那张「${what}」最近记的一笔是:「${String(p.progress).slice(0, 100)}」。`
617
+ }
618
+
601
619
  export function availableFor(m) {
602
620
  return CATALOG.filter((t) => t.stage <= m.stage).map(filledPrompt)
603
621
  }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * firstwake.js —— 「你刚醒」(2026-11-14,用户 m00704)
3
+ *
4
+ * 为什么要有这个:
5
+ * 梦一直是 0 条。材料早就在桌上(lib/dreamtable.js 的旧句子),缺的是
6
+ * 「睡过一觉」这个事实——唤醒只会给她时间和处境,从来没告诉过她刚醒。
7
+ * 但她一天会醒好几次(12:00–02:00 的窗口),不能每次都说「你刚醒」。
8
+ *
9
+ * 判据(三条同时成立):
10
+ * 1. 现在本地时间 ≥ 4 点。凌晨 0–4 点的醒是她还没睡下,不是醒来;
11
+ * 0:30 醒过一次、9:00 再醒,仍然算 9:00 这次是当天第一次「早上醒来」。
12
+ * 2. 当天 4 点以后没有醒过。有,就说明这一觉已经结束了。
13
+ * 3. 距上一次醒来或她/他说话 ≥ 4 小时。这一条挡的是「刚被叫醒又醒一次」
14
+ * 和「他刚说完话,她接着醒」——那时候她不是刚睡醒。
15
+ *
16
+ * 不写 `sleep:`:那是夜间 think 的槽位标记,不是「睡过一觉」。
17
+ * 没有基线(事件流里一条活动都没有)时不猜,返回 false。
18
+ */
19
+
20
+ import { tsMs } from './schema.js'
21
+
22
+ /** 早于这个整点醒来,不算「早上那一次」。 */
23
+ export const FIRST_WAKE_HOUR = 4
24
+ /** 距上一次醒来/活动至少这么久,才算睡过一觉。 */
25
+ export const FIRST_WAKE_GAP_HOURS = 4
26
+
27
+ const HOUR_MS = 3_600_000
28
+
29
+ function sameLocalDay(a, b) {
30
+ return (
31
+ a.getFullYear() === b.getFullYear() &&
32
+ a.getMonth() === b.getMonth() &&
33
+ a.getDate() === b.getDate()
34
+ )
35
+ }
36
+
37
+ /**
38
+ * 这一次醒来是不是当天「睡醒」的那一次。
39
+ *
40
+ * @param {object[]} events 全量事件(真事件,含 meta)
41
+ * @param {number|Date} [now]
42
+ * @returns {boolean}
43
+ */
44
+ export function firstWakeOfDay(events = [], now = Date.now()) {
45
+ const at = now instanceof Date ? now.getTime() : Number(now)
46
+ if (!Number.isFinite(at) || at <= 0) return false
47
+
48
+ const d = new Date(at)
49
+ if (d.getHours() < FIRST_WAKE_HOUR) return false
50
+
51
+ let lastAt = 0
52
+ let wokeAfterFour = false
53
+
54
+ for (const e of events) {
55
+ const t = tsMs(e)
56
+ if (!(t > 0)) continue
57
+
58
+ const isWake = e?.type === 'meta' && String(e.text ?? '').startsWith('wake:')
59
+ if (isWake) {
60
+ const w = new Date(t)
61
+ if (w.getHours() >= FIRST_WAKE_HOUR && sameLocalDay(w, d)) wokeAfterFour = true
62
+ }
63
+
64
+ // 活动 = 醒来,或任何不是 meta 的事件(她写下的话、他说的、听到的)。
65
+ // meta 里的 seen:/quiet:/sleep: 都是记账,不代表她那时醒着。
66
+ if (isWake || e?.type !== 'meta') {
67
+ if (t > lastAt) lastAt = t
68
+ }
69
+ }
70
+
71
+ if (wokeAfterFour) return false
72
+ if (!lastAt) return false
73
+ return at - lastAt >= FIRST_WAKE_GAP_HOURS * HOUR_MS
74
+ }
package/lib/generator.js CHANGED
@@ -29,7 +29,7 @@ export function pick(model, cfg, today, events = [], opts = {}) {
29
29
  const daily = cfg.daily ?? {}
30
30
  const maxQuestions = Number(daily.questions ?? 1)
31
31
  const questionsLeft = Math.max(0, maxQuestions - Number(today.questions ?? 0))
32
- const ctx = cardContext(model, events, now)
32
+ const ctx = cardContext(model, events, now, opts.notes)
33
33
 
34
34
  const pool = availableFor(model).filter((t) => {
35
35
  if (isSpent(t, fired, { now, growthDays: model.growthDays, squeeze: opts.squeeze })) return false
@@ -87,10 +87,21 @@ export function pick(model, cfg, today, events = [], opts = {}) {
87
87
  * 2. dream 不进 interest / curiosity 的原料:两者都吃 HER_TYPES,会把梦算进去。
88
88
  * 3. hisLine 只认他本人的话(scene !== 'group');群里的原话不算「他最近说过」。
89
89
  * 4. fired / lastAfter 只读已落盘的事件:约定到期、事件弧的下一集,都靠它算,不另建存储。
90
- * 5. 纯函数,每轮可能被几十张卡各看一遍;任何一处出错只让那一项为 null,不拖垮 pick。
90
+ * 5. notes 只读它们自己那份文件(notes.json),**不回写**:卡片只借来看「这件事走到哪儿」。
91
+ * 6. 纯函数,每轮可能被几十张卡各看一遍;任何一处出错只让那一项为 null,不拖垮 pick。
92
+ *
93
+ * @param {object} model deriveSelf 的结果
94
+ * @param {object[]} events 全量事件
95
+ * @param {number} now
96
+ * @param {object[]} notes readNotes() 的结果(可选;不给就是「便条里没东西」)
91
97
  */
92
- export function cardContext(model, events = [], now = Date.now()) {
93
- const out = { now, dream: null, interest: null, question: null, hisLine: null, fired: new Map(), lastAfter: () => '' }
98
+ export function cardContext(model, events = [], now = Date.now(), notes = []) {
99
+ const out = {
100
+ now, dream: null, interest: null, question: null, hisLine: null, fired: new Map(), lastAfter: () => '',
101
+ // 便条里那件正在做的事(2026-11-14,用户 m00209):约定到期、事件弧的中段与收尾
102
+ // 都该看见「她那天记下的进展」,而不是只回放她当时的原话。
103
+ inProgress: null,
104
+ }
94
105
  const all = Array.isArray(events) ? events : []
95
106
  const evs = all.filter((e) => e?.type !== 'dream')
96
107
  try {
@@ -150,6 +161,26 @@ export function cardContext(model, events = [], now = Date.now()) {
150
161
  }
151
162
  return ''
152
163
  }
164
+ // 便条里那件「做着、还没做完、最近记过一笔」的事(2026-11-14,用户 m00209)。
165
+ //
166
+ // 为什么要它:约定到期、事件弧的中段与收尾这三张卡原来只能端回她当时那句原话,
167
+ // 十天里她写过什么、卡在哪儿,卡片一个字都不知道。她于是只能凭记忆重讲一遍,
168
+ // 讲到第三集就难免自圆其说。
169
+ // 只挑**最近动过的一张**:一句进展说明「现在在哪」,两张以上就变成汇报工作。
170
+ try {
171
+ const open = (Array.isArray(notes) ? notes : []).filter((n) => n && n.status === 'open')
172
+ let best = null
173
+ for (const n of open) {
174
+ const list = Array.isArray(n.progress) ? n.progress : []
175
+ if (!list.length) continue
176
+ const last = list[list.length - 1]
177
+ const at = Date.parse(String(last?.at ?? n.revisedAt ?? '')) || 0
178
+ if (!best || at > best.at) best = { text: String(n.text ?? ''), progress: String(last.text ?? ''), at }
179
+ }
180
+ if (best?.progress) out.inProgress = best
181
+ } catch {
182
+ out.inProgress = null
183
+ }
153
184
  return out
154
185
  }
155
186