@linxin666/dsh-pet 0.1.20 → 0.2.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.
Files changed (85) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +18 -11
  3. package/README.zh.md +18 -11
  4. package/assets/whale/pet.json +9 -0
  5. package/lib/client.js +394 -58
  6. package/lib/client.js.map +1 -1
  7. package/lib/index.js +1007 -43
  8. package/lib/invariant.js +1 -1
  9. package/lib/{state-Diiq8vjk.js → state-DrMX22GL.js} +86 -28
  10. package/lib/types/affinity.d.ts +4 -0
  11. package/lib/types/affinity.d.ts.map +1 -1
  12. package/lib/types/affinity.js +32 -6
  13. package/lib/types/chatter.d.ts +111 -0
  14. package/lib/types/chatter.d.ts.map +1 -0
  15. package/lib/types/chatter.js +756 -0
  16. package/lib/types/client/PetDockEntry.d.ts.map +1 -1
  17. package/lib/types/client/PetDockEntry.js +1 -1
  18. package/lib/types/client/PetSprite.d.ts.map +1 -1
  19. package/lib/types/client/PetSprite.js +133 -16
  20. package/lib/types/client/PluginSettingsCard.d.ts +28 -0
  21. package/lib/types/client/PluginSettingsCard.d.ts.map +1 -1
  22. package/lib/types/client/PluginSettingsCard.js +147 -6
  23. package/lib/types/client/index.d.ts.map +1 -1
  24. package/lib/types/client/index.js +1 -0
  25. package/lib/types/client/locales.d.ts +4 -0
  26. package/lib/types/client/locales.d.ts.map +1 -1
  27. package/lib/types/client/locales.js +4 -0
  28. package/lib/types/client/sequences.d.ts +10 -0
  29. package/lib/types/client/sequences.d.ts.map +1 -0
  30. package/lib/types/client/sequences.js +20 -0
  31. package/lib/types/event-projection.d.ts +14 -1
  32. package/lib/types/event-projection.d.ts.map +1 -1
  33. package/lib/types/event-projection.js +38 -17
  34. package/lib/types/ledger.d.ts.map +1 -1
  35. package/lib/types/ledger.js +15 -7
  36. package/lib/types/loopback.d.ts +25 -0
  37. package/lib/types/loopback.d.ts.map +1 -0
  38. package/lib/types/loopback.js +68 -0
  39. package/lib/types/persist.d.ts.map +1 -1
  40. package/lib/types/persist.js +3 -1
  41. package/lib/types/registry.d.ts +7 -1
  42. package/lib/types/registry.d.ts.map +1 -1
  43. package/lib/types/registry.js +47 -3
  44. package/lib/types/remarks.d.ts +2 -0
  45. package/lib/types/remarks.d.ts.map +1 -1
  46. package/lib/types/remarks.js +35 -0
  47. package/lib/types/routes.d.ts.map +1 -1
  48. package/lib/types/routes.js +14 -0
  49. package/lib/types/service.d.ts +6 -0
  50. package/lib/types/service.d.ts.map +1 -1
  51. package/lib/types/service.js +15 -2
  52. package/lib/types/state.d.ts +7 -4
  53. package/lib/types/state.d.ts.map +1 -1
  54. package/lib/types/state.js +20 -20
  55. package/package.json +9 -9
  56. package/src/affinity.test.ts +4 -2
  57. package/src/affinity.ts +37 -6
  58. package/src/chatter.test.ts +154 -0
  59. package/src/chatter.ts +787 -0
  60. package/src/client/PetDockEntry.test.tsx +93 -0
  61. package/src/client/PetDockEntry.tsx +1 -0
  62. package/src/client/PetSprite.test.tsx +253 -3
  63. package/src/client/PetSprite.tsx +192 -37
  64. package/src/client/PluginSettingsCard.tsx +229 -18
  65. package/src/client/index.test.tsx +95 -0
  66. package/src/client/index.ts +1 -0
  67. package/src/client/locales.ts +4 -0
  68. package/src/client/pet-css.test.ts +54 -0
  69. package/src/client/pet.module.css +215 -57
  70. package/src/client/sequences.test.ts +33 -0
  71. package/src/client/sequences.ts +33 -0
  72. package/src/client/settings-card.module.css +90 -1
  73. package/src/event-projection.ts +49 -16
  74. package/src/ledger.test.ts +42 -1
  75. package/src/ledger.ts +15 -7
  76. package/src/loopback.ts +63 -0
  77. package/src/persist.test.ts +18 -1
  78. package/src/persist.ts +3 -1
  79. package/src/registry.test.ts +79 -4
  80. package/src/registry.ts +58 -6
  81. package/src/remarks.ts +36 -0
  82. package/src/routes.ts +11 -0
  83. package/src/service.ts +27 -2
  84. package/src/state.test.ts +13 -0
  85. package/src/state.ts +24 -18
@@ -0,0 +1,756 @@
1
+ /**
2
+ * Pet chatter — the pet's voice while sessions work. Two speakers live here:
3
+ *
4
+ * 1. The status voice (session bubbles): big per-scene copy pools instead of
5
+ * one fixed line per phase, a fine-grained tool-name → copy-family map,
6
+ * and a compact real-argument hint ('跑跑 npm test'), in the spirit of
7
+ * the working-activity plugin's status line. Lines rotate round-robin —
8
+ * while a phase persists the copy advances every few seconds, so the pet
9
+ * feels alive without flickering per streamed chunk.
10
+ * 2. The murmur engine (碎碎念): the pet's inner whispers, woken by the
11
+ * model's own output — keyword moods (errors, test greens, plans,
12
+ * self-corrections, victories...) plus an ambient pool earned by output
13
+ * volume. A cooldown keeps whispers occasional.
14
+ *
15
+ * Pure and deterministic: round-robin everywhere (no Math.random), clocks are
16
+ * injected. The first line of each status pool is the legacy fixed copy the
17
+ * plugin has always shown, so existing installs keep their wording until the
18
+ * scene cycles. No emoji anywhere (repository rule); ~ is the whale-girl's
19
+ * signature.
20
+ * @module @linxin666/dsh-pet/chatter
21
+ */
22
+ /** While a scene persists, its copy advances on this cadence (ms). */
23
+ export const STATUS_ROTATE_MS = 4000;
24
+ /** Fixed-copy pools per status scene (first line = legacy wording). */
25
+ export const STATUS_POOLS = {
26
+ prepare: [
27
+ '准备开始',
28
+ '撸起袖子开工啦',
29
+ '新一轮,出发~',
30
+ '打起精神,开干!',
31
+ '整理一下桌面,开始吧',
32
+ '氧气充满,下潜开始~',
33
+ '热身完毕,跃跃欲试',
34
+ '开工仪式感已就位',
35
+ ],
36
+ waiting: [
37
+ '等待模型响应',
38
+ '呼叫大脑中,请稍等',
39
+ '信号发射中,等一个回音',
40
+ '灵感正在路上~',
41
+ '竖起耳朵等回复',
42
+ '大脑在咕噜咕噜加载',
43
+ '等它伸个懒腰再开口',
44
+ '模型:来了来了',
45
+ '等一个灵感砸中我',
46
+ '滴——等待连线中',
47
+ '它在组织语言,别催',
48
+ '等它热身完毕',
49
+ '灵感快递派送中',
50
+ '屏住呼吸等回复',
51
+ ],
52
+ thinking: [
53
+ '正在思考',
54
+ '嗯……让我想一想',
55
+ '脑内风暴进行中',
56
+ '思绪咕噜咕噜冒泡',
57
+ '灵光集结中~',
58
+ '眉头一皱,认真分析',
59
+ '左脑右脑一起开会',
60
+ '答案正在浮出水面',
61
+ '盘一下,盘一下逻辑',
62
+ '让子弹再飞一会儿',
63
+ '别催别催,在想呢',
64
+ '大脑转起来了',
65
+ '让我把线索捋一捋',
66
+ '脑内跑火车中',
67
+ '小脑瓜高速运转',
68
+ '让我琢磨琢磨',
69
+ '翻翻脑子里的藏书',
70
+ '让我嚼一嚼这个问题',
71
+ '脑子在煮咖啡,马上好',
72
+ '思考的鱼游来了',
73
+ '让我康康这里面的门道',
74
+ '正在盘逻辑链',
75
+ '思绪整理收纳中',
76
+ '嗯?有点意思……',
77
+ '让思路沉淀一下',
78
+ '脑内弹幕飞速滚动',
79
+ ],
80
+ review: [
81
+ '整理回复中',
82
+ '把想法写下来',
83
+ '组织语言中~',
84
+ '落笔成文,请稍候',
85
+ '字斟句酌中',
86
+ '把答案装进信封里',
87
+ '遣词造句打磨中',
88
+ '把思绪码成整整齐齐的字',
89
+ '奋笔疾书中',
90
+ '把最好的表达挑出来',
91
+ '文字排版美容师上线',
92
+ '收尾润色一下下',
93
+ ],
94
+ toolResult: [
95
+ '处理工具结果',
96
+ '看看带回了什么',
97
+ '消化一下刚到的结果',
98
+ '结果解读中~',
99
+ '验收工具的成果',
100
+ '把线索拼接起来',
101
+ '战利品清点中',
102
+ '这份结果有点东西',
103
+ '把新情报归档',
104
+ '结果到手,继续前进',
105
+ ],
106
+ done: [
107
+ '完成啦',
108
+ '搞定收工~',
109
+ '任务达成,耶!',
110
+ '这一轮圆满完成',
111
+ '顺利抵达终点',
112
+ '收工!求摸摸奖励',
113
+ '交差!下一位',
114
+ '齐活,漂亮收官',
115
+ '拿下!击掌~',
116
+ '稳了,满分交卷',
117
+ '搞定,去喝口水',
118
+ '完工咯,转个圈圈',
119
+ '这一轮,我们配合满分',
120
+ '妥了妥了,收工收工',
121
+ ],
122
+ failed: [
123
+ '执行失败',
124
+ '哎呀,中途卡住了',
125
+ '这一步没能走完',
126
+ '被小石头绊倒了',
127
+ '半路翻车了,揉揉膝盖',
128
+ '出了点岔子,缓缓再来',
129
+ ],
130
+ toolFailed: [
131
+ '工具执行失败',
132
+ '工具闹脾气了,哄哄它',
133
+ '哎呀,工具掉链子了',
134
+ '这个工具今天不太听话',
135
+ '工具翻车了,扶起来继续',
136
+ '没跑通,再来一次',
137
+ '工具:我罢工三秒钟',
138
+ '这一步摔了一跤,没事',
139
+ ],
140
+ maxTokens: [
141
+ '达到输出上限',
142
+ '话说到一半被截断了',
143
+ '字数用完了,喘口气',
144
+ '一口气说太满,缓缓',
145
+ ],
146
+ interrupted: [
147
+ '执行意外中断',
148
+ '哎呀,被意外打断了',
149
+ '半路踩了急刹车',
150
+ '被迫停下,意犹未尽',
151
+ ],
152
+ blocked: [
153
+ '等待继续',
154
+ '在这里等你发令',
155
+ '暂停待命,随时出发',
156
+ '蹲一个继续的指令',
157
+ ],
158
+ };
159
+ /** Map a raw tool name onto its copy family (working-activity style regexes). */
160
+ export function toolCategory(toolName) {
161
+ const name = toolName.toLowerCase();
162
+ if (/mem0|recall|memory/.test(name))
163
+ return 'memory';
164
+ if (/subagent|workflow|ralph|agent|task/.test(name))
165
+ return 'subagent';
166
+ if (/web_search|websearch|search_web|exa|brave|tavily/.test(name))
167
+ return 'webSearch';
168
+ if (/fetch|browser|playwright|chrome/.test(name))
169
+ return 'webFetch';
170
+ if (/grep|search|rg/.test(name))
171
+ return 'grep';
172
+ if (/glob|find/.test(name))
173
+ return 'find';
174
+ if (/^ls$|list_dir|list/.test(name))
175
+ return 'ls';
176
+ if (/ask_user|ask/.test(name))
177
+ return 'ask';
178
+ if (/todo|plan/.test(name))
179
+ return 'todo';
180
+ if (/git/.test(name))
181
+ return 'git';
182
+ if (/mcp__|mcp/.test(name))
183
+ return 'mcp';
184
+ if (/read|open|load|describe|inspect/.test(name))
185
+ return 'read';
186
+ if (/edit|patch|replace|rename/.test(name))
187
+ return 'edit';
188
+ if (/write|create|save/.test(name))
189
+ return 'write';
190
+ if (/run_code|bash|shell|terminal|exec|command|ssh/.test(name))
191
+ return 'shell';
192
+ return 'generic';
193
+ }
194
+ /**
195
+ * Per-family tool status pools. '{tool}' interpolates the compact tool name,
196
+ * '{hint}' the compact real-argument hint (both optional per line); the first
197
+ * entry of every pool is the legacy '正在使用 {tool}' wording.
198
+ */
199
+ export const TOOL_POOLS = {
200
+ read: [
201
+ '正在使用 {tool}',
202
+ '翻翻 {hint}',
203
+ '读一下 {hint}',
204
+ '让我康康这个文件',
205
+ '逐行品味 {hint}',
206
+ '翻阅资料中~',
207
+ '瞄一眼 {hint}',
208
+ '把文件摊开看一看',
209
+ '认真研读 {hint}',
210
+ ],
211
+ write: [
212
+ '正在使用 {tool}',
213
+ '写写写,写 {hint}',
214
+ '下笔中~',
215
+ '码字呢,别催',
216
+ '写下 {hint}',
217
+ '落笔成章',
218
+ '把想法存进 {hint}',
219
+ '开写开写',
220
+ '存个文件压压惊',
221
+ ],
222
+ edit: [
223
+ '正在使用 {tool}',
224
+ '改改 {hint}',
225
+ '修修补补中',
226
+ '润色一下 {hint}',
227
+ '改两行,就两行',
228
+ '补一刀 {hint}',
229
+ '动动手指改一改',
230
+ '精雕细琢 {hint}',
231
+ '微调一下下',
232
+ ],
233
+ shell: [
234
+ '正在使用 {tool}',
235
+ '跑跑 {hint}',
236
+ '敲几行命令试试',
237
+ '命令行走起:{hint}',
238
+ '使唤终端跑个腿',
239
+ '终端全速运转中',
240
+ '敲回车!{hint}',
241
+ '让命令飞一会儿',
242
+ '去终端里探个究竟',
243
+ ],
244
+ grep: [
245
+ '正在使用 {tool}',
246
+ '搜搜 {hint}',
247
+ '找找匹配:{hint}',
248
+ '关键词走你',
249
+ '在代码里挖一挖',
250
+ '检索小雷达启动',
251
+ '顺着 {hint} 追下去',
252
+ '掘地三尺找一找',
253
+ '过滤筛选中~',
254
+ ],
255
+ find: [
256
+ '正在使用 {tool}',
257
+ '找找文件 {hint}',
258
+ '寻宝中~',
259
+ '文件在哪里呀',
260
+ '找啊找啊找文件',
261
+ '把 {hint} 揪出来',
262
+ '查找模式中',
263
+ ],
264
+ ls: [
265
+ '正在使用 {tool}',
266
+ '列个清单看看',
267
+ '看看目录里有啥',
268
+ '目录走起~',
269
+ '瞟一眼文件夹',
270
+ '数数这里有几个文件',
271
+ ],
272
+ webSearch: [
273
+ '正在使用 {tool}',
274
+ '网上搜搜 {hint}',
275
+ '网络冲浪中',
276
+ '帮你问问互联网',
277
+ '搜一圈 {hint}',
278
+ '去外面的世界打听打听',
279
+ '查找资料中~',
280
+ '情报收集模式开启',
281
+ ],
282
+ webFetch: [
283
+ '正在使用 {tool}',
284
+ '抓个页面看看',
285
+ '拉取 {hint}',
286
+ '扒拉一下网页',
287
+ '取点内容回来',
288
+ '打开 {hint} 瞅瞅',
289
+ ],
290
+ mcp: [
291
+ '正在使用 {tool}',
292
+ '连一下外部服务',
293
+ '喊个外援来',
294
+ '接个工具用用',
295
+ '问问插件小助手',
296
+ '外部力量接入中',
297
+ ],
298
+ memory: [
299
+ '正在使用 {tool}',
300
+ '翻翻小本本',
301
+ '回想一下之前的事',
302
+ '在记忆里挖一挖',
303
+ '提取记忆碎片~',
304
+ '我们之前的约定是……',
305
+ ],
306
+ subagent: [
307
+ '正在使用 {tool}',
308
+ '派个小弟去跑腿',
309
+ '小助手出动!',
310
+ '交给分身去办',
311
+ '多线作战,分身出击',
312
+ '召唤队友支援',
313
+ '集思广益中~',
314
+ ],
315
+ todo: [
316
+ '正在使用 {tool}',
317
+ '列个待办清单',
318
+ '写个小计划',
319
+ '待办安排得明明白白',
320
+ '打个勾,继续',
321
+ '把任务排排坐',
322
+ ],
323
+ browser: [
324
+ '正在使用 {tool}',
325
+ '开个浏览器看看',
326
+ '网页操作小能手',
327
+ '替你点点页面',
328
+ '浏览器跑腿中',
329
+ ],
330
+ git: [
331
+ '正在使用 {tool}',
332
+ '提交一下代码',
333
+ '版本控制走起',
334
+ '管管仓库',
335
+ '给改动安个家',
336
+ ],
337
+ ask: [
338
+ '正在使用 {tool}',
339
+ '问你个事儿',
340
+ '请教一下下',
341
+ '等等,我需要确认',
342
+ '这个问题得你拍板',
343
+ ],
344
+ generic: [
345
+ '正在使用 {tool}',
346
+ '召唤 {tool} 出击',
347
+ '{tool} 工作中',
348
+ '借助 {tool} 的力量',
349
+ '拜托 {tool} 一下',
350
+ '{tool},启动!',
351
+ ],
352
+ };
353
+ /** Pools for the parallel-tools line; '{n}' interpolates the running count. */
354
+ export const TOOL_REMAINING_POOL = [
355
+ '还有 {n} 个工具运行中',
356
+ '{n} 路并进,分身们还在忙',
357
+ '还有 {n} 位小助手在加班',
358
+ '{n} 条战线同时推进中',
359
+ '另 {n} 个工具在后台跑',
360
+ ];
361
+ /**
362
+ * A compact, human-readable hint of what a tool call actually touches —
363
+ * the command, the path, the pattern, the query. Best-effort parse of the
364
+ * raw arguments JSON; unknown shapes stay hintless. Capped short so the
365
+ * bubble stays compact.
366
+ */
367
+ export function toolArgHint(toolName, argumentsJson) {
368
+ let args;
369
+ try {
370
+ args = JSON.parse(argumentsJson);
371
+ }
372
+ catch {
373
+ return undefined;
374
+ }
375
+ if (typeof args !== 'object' || args === null || Array.isArray(args))
376
+ return undefined;
377
+ const record = args;
378
+ const category = toolCategory(toolName);
379
+ const candidateKeys = (() => {
380
+ switch (category) {
381
+ case 'shell': return ['command', 'code', 'cmd'];
382
+ case 'grep': return ['pattern', 'query', 'path'];
383
+ case 'find': return ['pattern', 'path', 'glob'];
384
+ case 'read':
385
+ case 'write':
386
+ case 'edit': return ['file_path', 'path', 'filePath', 'file'];
387
+ case 'webSearch': return ['query', 'q', 'keyword'];
388
+ case 'webFetch':
389
+ case 'browser': return ['url', 'uri'];
390
+ case 'subagent': return ['description', 'label', 'prompt'];
391
+ case 'ls': return ['path', 'dir', 'directory'];
392
+ case 'git': return ['command', 'message'];
393
+ default: return ['command', 'query', 'path', 'file_path', 'description', 'title', 'name'];
394
+ }
395
+ })();
396
+ for (const key of candidateKeys) {
397
+ const value = record[key];
398
+ if (typeof value !== 'string')
399
+ continue;
400
+ const compact = value.replace(/\s+/g, ' ').trim();
401
+ if (compact === '')
402
+ continue;
403
+ const base = compact.split('/').pop() ?? compact;
404
+ const shown = (category === 'read' || category === 'write' || category === 'edit') && base !== '' ? base : compact;
405
+ return shown.length <= 28 ? shown : shown.slice(0, 25) + '...';
406
+ }
407
+ return undefined;
408
+ }
409
+ /**
410
+ * Round-robin voice for status copy. Scene-keyed picks stay STABLE while the
411
+ * same scene repeats (streaming chunks re-emit the same phase many times per
412
+ * second, and rotating per chunk would make the bubble flicker), but advance
413
+ * once the scene has persisted past the rotation cadence, so a long thinking
414
+ * stretch keeps changing its wording.
415
+ */
416
+ export class StatusVoice {
417
+ rotateMs;
418
+ counters = new Map();
419
+ lastScene = '';
420
+ lastLine = '';
421
+ lastLineAt = Number.NEGATIVE_INFINITY;
422
+ constructor(rotateMs = STATUS_ROTATE_MS) {
423
+ this.rotateMs = rotateMs;
424
+ }
425
+ /** Draw the next line of one pool, advancing its round-robin cursor. */
426
+ draw(poolKey, pool) {
427
+ const index = (this.counters.get(poolKey) ?? 0) % pool.length;
428
+ this.counters.set(poolKey, index + 1);
429
+ return pool[index];
430
+ }
431
+ /** Reuse the stable line or advance when the cadence elapsed. */
432
+ voice(scene, poolKey, pool, nowMs) {
433
+ if (scene === this.lastScene && nowMs - this.lastLineAt < this.rotateMs)
434
+ return this.lastLine;
435
+ this.lastScene = scene;
436
+ this.lastLine = this.draw(poolKey, pool);
437
+ this.lastLineAt = nowMs;
438
+ return this.lastLine;
439
+ }
440
+ /** Status line for a phase scene. */
441
+ scene(scene, nowMs) {
442
+ return this.voice('scene:' + scene, 'pool:' + scene, STATUS_POOLS[scene], nowMs);
443
+ }
444
+ /** Status line for a tool call, with the real-argument hint when known. */
445
+ tool(toolName, displayName, hint, nowMs) {
446
+ const category = toolCategory(toolName);
447
+ const line = this.voice('tool:' + category, 'tool:' + category, TOOL_POOLS[category], nowMs);
448
+ return line
449
+ .replace('{tool}', displayName)
450
+ .replace('{hint}', hint ?? displayName);
451
+ }
452
+ /** Status line while sibling tools still run (always reflects the count). */
453
+ toolRemaining(count, nowMs) {
454
+ return this.voice('toolRemaining', 'toolRemaining', TOOL_REMAINING_POOL, nowMs)
455
+ .replace('{n}', String(count));
456
+ }
457
+ }
458
+ /** Murmur pacing: cooldown between whispers and output volume that earns one. */
459
+ export const WHISPER_COOLDOWN_MS = 9000;
460
+ export const WHISPER_CHAR_BUDGET = 420;
461
+ /** How long a whisper stays on screen (host-side expiry). */
462
+ export const WHISPER_TTL_MS = 8000;
463
+ /** Ambient inner-whisper pool (no keyword needed; earned by output volume). */
464
+ export const WHISPER_GENERIC_POOL = [
465
+ '哼哧哼哧,大脑转得飞快~',
466
+ 'loading 99%……就差最后一步',
467
+ '嗯……让我捋捋',
468
+ '灵感来了,先记小本本上',
469
+ '脑子在冒烟,但还能撑',
470
+ '这个报错,我好像在哪见过',
471
+ '专注模式 ON,请勿打扰',
472
+ '思路通了,舒服了',
473
+ '有点困……不行,还能肝',
474
+ '让我嚼一嚼这个问题',
475
+ '盘,都可以盘',
476
+ '这波操作,我给自己点个赞',
477
+ '别催别催,在想呢',
478
+ '唔,这个细节差点漏掉',
479
+ '脑子转太快,差点绕晕自己',
480
+ '陪你干活,稳赚不亏',
481
+ '深呼吸,马上就好',
482
+ '诶,等等,好像发现了什么',
483
+ '手速拉满,键盘冒火星',
484
+ '摸鱼是不可能摸鱼的,就瞄一眼窗外',
485
+ '今天也是稳扎稳打的一天',
486
+ '把大问题拆成小饼干,一口一个',
487
+ '这题有戏,我闻到了',
488
+ '尾巴轻晃,心情有点小得意',
489
+ '好结果是熬出来的,不慌',
490
+ '啊,想岔了,重新来',
491
+ '嗯嗯,思路对头,就这么干',
492
+ '小本本记满了,都是干货',
493
+ '打完这波,求摸摸奖励~',
494
+ '这坑我记住了,下次绕道',
495
+ '窗外云在飘,代码在跑,挺好',
496
+ '嘘,正到关键处',
497
+ '这个方案……让我再品品',
498
+ '干活呢,别打扰我数数',
499
+ '心里默默给你比了个耶',
500
+ '思路像小鱼,逮住一条是一条',
501
+ '嗯……有点东西,等我深挖',
502
+ '收个尾就能喘口气了',
503
+ '目标锁定,冲就完了',
504
+ '嗯,这波配合不错',
505
+ '困了……还能再战三回合',
506
+ '思考.gif 加载中',
507
+ '我本地能跑啊……哦,我就是干活的',
508
+ '有点饿,小鱼干存货还够吗',
509
+ '刚想通,一被打断又忘了,气',
510
+ '缓冲中,请稍候',
511
+ '这网速,比我思考还慢',
512
+ '脑子在后台跑批',
513
+ '内存不足,但热情够',
514
+ '404:思路未找到,重试中',
515
+ '这需求有点玄学,但能写',
516
+ '诶,这 bug 还会闪现?',
517
+ '刚说简单,结果打脸了',
518
+ '自信满满,结果翻车',
519
+ '这活不难,就是有点复杂',
520
+ '我装的,其实心里没底',
521
+ '别看我稳,我也慌',
522
+ '假装很懂的样子,其实在查文档',
523
+ '窗外鸟叫了两声,我听到了',
524
+ '打了个哈欠,没人看见',
525
+ '今天的状态:七分精神三分困',
526
+ '刚想偷懒,又想起来你还在等',
527
+ '数了数今天的产出,还行',
528
+ '有点想伸懒腰',
529
+ '饿意来袭,忍住',
530
+ '灵感像猫一样,不追它自己来',
531
+ '坐太久,尾巴麻了',
532
+ '快了快了',
533
+ '马上马上',
534
+ '等下,我记得在哪见过',
535
+ '呃,忘了,重新想',
536
+ '诶,这个思路可以',
537
+ '嗯?有意思',
538
+ '行,就这么办',
539
+ '好嘞',
540
+ '收到收到',
541
+ '冲了冲了',
542
+ '稳',
543
+ '妥',
544
+ '得嘞',
545
+ '你忙你的,我盯着呢',
546
+ '放心,有我呢',
547
+ '咱俩配合,无往不利',
548
+ '你专注的样子,我默默记下了',
549
+ ];
550
+ /** Keyword-triggered whisper rules, most specific moods first. */
551
+ export const WHISPER_RULES = [
552
+ {
553
+ keywords: ['测试通过', '测试全过', '全部通过', 'all tests pass', 'tests passed', 'test passed', '全绿'],
554
+ pool: [
555
+ '全绿!亮瞎我眼了',
556
+ '测试全过,击掌~',
557
+ '稳了稳了,这波稳得很',
558
+ '绿灯一排排,看着就舒坦',
559
+ '能跑!没报错!',
560
+ '全绿,收工摸鱼去',
561
+ '测试过了,尾巴翘上天',
562
+ '漂亮,一次过',
563
+ '测试过了,奖励自己一口小鱼干',
564
+ '绿得发光,稳',
565
+ '又双叒叕全绿',
566
+ '这波测试,赢得干脆',
567
+ ],
568
+ },
569
+ {
570
+ keywords: ['错误', '失败', '报错', '异常', '崩溃', 'bug', 'error', 'failed', 'exception', 'traceback', '找不到', '不对了'],
571
+ pool: [
572
+ '哎呀,踩到小石子了',
573
+ '翻车了……没事,扶起来继续',
574
+ '错误是进步的脚印,我懂',
575
+ '这报错我盯上它了',
576
+ '我本地能跑啊?哦,我一直在跑',
577
+ '别慌,深呼吸,先看报错',
578
+ 'bug 你站住,我看见你了',
579
+ '绷不住了……好,继续修',
580
+ '报错这东西,见一个修一个',
581
+ '又是它,老熟人了',
582
+ '问题不大,就是有点问题',
583
+ '先别慌,我看看到底咋回事',
584
+ '这错报得,比我还委屈',
585
+ '修好它,今天才不算白干',
586
+ ],
587
+ },
588
+ {
589
+ keywords: ['等等', '不对', '重新想', '再想想', '换个思路', '我搞错了', '纠正', '其实应该'],
590
+ pool: [
591
+ '嗯?让我再想想……',
592
+ '推翻重来,也是种勇气',
593
+ '发现岔路,及时掉头',
594
+ '不对不对,重来重来',
595
+ '自我纠错的瞬间,最帅了',
596
+ '呃,刚说错了,收回',
597
+ '哎,绕远了,拉回来',
598
+ '回头一看,原来这么简单',
599
+ '纠正完,思路清爽多了',
600
+ '转弯不丢人,卡死才丢人',
601
+ ],
602
+ },
603
+ {
604
+ keywords: ['首先', '接下来', '第一步', '第二步', '计划', '步骤', 'todo', '任务拆解', '分工'],
605
+ pool: [
606
+ '排排坐,分果果',
607
+ '计划通,执行开始',
608
+ '一步一步来,不慌',
609
+ '大任务切成小块块,好下口',
610
+ '清单列好了,逐个击破',
611
+ '谋定而后动,这节奏我熟',
612
+ '先干这个,再干那个',
613
+ '头绪理清了,开整',
614
+ '步骤在手,心里不慌',
615
+ '安排得明明白白',
616
+ ],
617
+ },
618
+ {
619
+ keywords: ['终于', '搞定', '完成了', '解决了', '成功了', '修复了', 'done', 'fixed', 'solved', '完成啦'],
620
+ pool: [
621
+ '太好了,又翻过一页',
622
+ '搞定,收工~',
623
+ '攻下一城,击掌!',
624
+ '难题被拿下了,转个圈',
625
+ '努力没白费,开心',
626
+ '齐活,漂亮',
627
+ '收工收工,今天圆满',
628
+ '完成!心里踏实了',
629
+ '这波,稳得一批',
630
+ '任务清零,舒服',
631
+ '搞定,可以伸个懒腰了',
632
+ '又完成一件,成就感+1',
633
+ ],
634
+ },
635
+ {
636
+ keywords: ['谢谢', '感谢', 'thank'],
637
+ pool: [
638
+ '不客气呀,顺手的事',
639
+ '被感谢了,心里甜甜的',
640
+ '能帮上忙就好~',
641
+ '你的谢意,我收进口袋啦',
642
+ '这话我爱听',
643
+ '客气啥,应该的',
644
+ '收下这份心意,干劲+1',
645
+ '你谢我,我谢你,扯平啦',
646
+ ],
647
+ },
648
+ {
649
+ keywords: ['复杂', '棘手', '困难', '难点', '坑', '头疼', 'tricky', 'complex'],
650
+ pool: [
651
+ '难不倒我们俩的',
652
+ '越难啃的骨头越香',
653
+ '硬骨头?我最喜欢了',
654
+ '复杂问题拆开看,小事',
655
+ '这坑我们一起填',
656
+ '有点东西,但不多',
657
+ '硬骨头,慢慢啃',
658
+ '问题越难,赢的时候越爽',
659
+ '绕是绕不过去的,正面刚',
660
+ '再难的题,拆开都是小问号',
661
+ ],
662
+ },
663
+ {
664
+ keywords: ['检查', '审查', '确认一下', '核对', 'review', '仔细看看', '验证'],
665
+ pool: [
666
+ '火眼金睛,启动',
667
+ '让我仔细瞧瞧',
668
+ '细节魔鬼,一个都不放过',
669
+ '认真检查的样子最迷人',
670
+ '多核一遍,稳上加稳',
671
+ '再看一眼,不亏',
672
+ '确认键,点了才安心',
673
+ '细节控上线',
674
+ '查完这遍,稳了',
675
+ ],
676
+ },
677
+ {
678
+ keywords: ['搜索', '查一下', '资料', '文档', '搜一搜', '找找', '查询'],
679
+ pool: [
680
+ '去知识的海洋里捞一捞',
681
+ '翻翻找找,线索快出来',
682
+ '检索小雷达启动',
683
+ '答案就藏在某个角落',
684
+ '线索有点散,拼一下',
685
+ '找东西,我最在行',
686
+ '答案在网线那头等我',
687
+ '翻箱倒柜中,稍等',
688
+ ],
689
+ },
690
+ {
691
+ keywords: ['写代码', '实现', '编码', '函数', '接口', '重构'],
692
+ pool: [
693
+ '指尖跳舞,代码开花',
694
+ '把逻辑织成网',
695
+ '一行一行,垒起小城堡',
696
+ '这代码写得,我自己都佩服',
697
+ '码着码着,天就亮了',
698
+ '代码跑通了,比中奖还开心',
699
+ '这行代码,写得有点帅',
700
+ '写完再润润,讲究',
701
+ ],
702
+ },
703
+ ];
704
+ /**
705
+ * The murmur engine (碎碎念): watches the model's own output and lets the pet
706
+ * whisper its inner voice. Two ways to earn a whisper:
707
+ * - a keyword rule matches the fresh chunk text (themed whisper);
708
+ * - enough output volume flowed by without one (ambient whisper).
709
+ * A cooldown keeps whispers occasional; all picks are round-robin so tests
710
+ * reproduce exact lines.
711
+ */
712
+ export class WhisperEngine {
713
+ cooldownMs;
714
+ charBudget;
715
+ counters = new Map();
716
+ genericCursor = 0;
717
+ lastWhisperAt = Number.NEGATIVE_INFINITY;
718
+ charsSinceWhisper = 0;
719
+ constructor(cooldownMs = WHISPER_COOLDOWN_MS, charBudget = WHISPER_CHAR_BUDGET) {
720
+ this.cooldownMs = cooldownMs;
721
+ this.charBudget = charBudget;
722
+ }
723
+ /**
724
+ * Feed one model-output chunk (reasoning or text). Returns the whisper to
725
+ * show, or undefined when the moment stays quiet.
726
+ */
727
+ feed(text, nowMs) {
728
+ if (text.length === 0)
729
+ return undefined;
730
+ const offCooldown = nowMs - this.lastWhisperAt >= this.cooldownMs;
731
+ if (!offCooldown) {
732
+ this.charsSinceWhisper += text.length;
733
+ return undefined;
734
+ }
735
+ const haystack = text.toLowerCase();
736
+ for (let ruleIndex = 0; ruleIndex < WHISPER_RULES.length; ruleIndex += 1) {
737
+ const rule = WHISPER_RULES[ruleIndex];
738
+ if (!rule.keywords.some(keyword => haystack.includes(keyword)))
739
+ continue;
740
+ const index = (this.counters.get(ruleIndex) ?? 0) % rule.pool.length;
741
+ this.counters.set(ruleIndex, index + 1);
742
+ return this.speak(rule.pool[index], nowMs);
743
+ }
744
+ this.charsSinceWhisper += text.length;
745
+ if (this.charsSinceWhisper < this.charBudget)
746
+ return undefined;
747
+ const line = WHISPER_GENERIC_POOL[this.genericCursor % WHISPER_GENERIC_POOL.length];
748
+ this.genericCursor += 1;
749
+ return this.speak(line, nowMs);
750
+ }
751
+ speak(line, nowMs) {
752
+ this.lastWhisperAt = nowMs;
753
+ this.charsSinceWhisper = 0;
754
+ return line;
755
+ }
756
+ }