@linxin666/dsh-pet 0.1.19 → 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.
Files changed (95) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +19 -12
  3. package/README.zh.md +19 -12
  4. package/assets/whale/pet.json +9 -0
  5. package/lib/client.js +202 -38
  6. package/lib/client.js.map +1 -1
  7. package/lib/index.js +897 -42
  8. package/lib/invariant.js +1 -1
  9. package/lib/{state-Diiq8vjk.js → state-Ch3f4luZ.js} +51 -23
  10. package/lib/types/affinity.d.ts +22 -18
  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 +666 -0
  16. package/lib/types/client/PetDockEntry.d.ts +2 -0
  17. package/lib/types/client/PetDockEntry.d.ts.map +1 -1
  18. package/lib/types/client/PetDockEntry.js +2 -2
  19. package/lib/types/client/PetSettingsCard.d.ts.map +1 -1
  20. package/lib/types/client/PetSettingsCard.js +2 -2
  21. package/lib/types/client/PetSprite.d.ts +2 -0
  22. package/lib/types/client/PetSprite.d.ts.map +1 -1
  23. package/lib/types/client/PetSprite.js +100 -25
  24. package/lib/types/client/PluginSettingsCard.d.ts +7 -1
  25. package/lib/types/client/PluginSettingsCard.d.ts.map +1 -1
  26. package/lib/types/client/PluginSettingsCard.js +5 -3
  27. package/lib/types/client/index.d.ts +1 -1
  28. package/lib/types/client/index.d.ts.map +1 -1
  29. package/lib/types/client/index.js +31 -6
  30. package/lib/types/client/locales.d.ts +82 -80
  31. package/lib/types/client/locales.d.ts.map +1 -1
  32. package/lib/types/client/locales.js +2 -0
  33. package/lib/types/client/sequences.d.ts +10 -0
  34. package/lib/types/client/sequences.d.ts.map +1 -0
  35. package/lib/types/client/sequences.js +20 -0
  36. package/lib/types/client/settings-form.d.ts.map +1 -1
  37. package/lib/types/client/spritesheet.d.ts +1 -1
  38. package/lib/types/client/spritesheet.d.ts.map +1 -1
  39. package/lib/types/client/spritesheet.js +3 -12
  40. package/lib/types/event-projection.d.ts +14 -1
  41. package/lib/types/event-projection.d.ts.map +1 -1
  42. package/lib/types/event-projection.js +38 -17
  43. package/lib/types/index.d.ts +2 -1
  44. package/lib/types/index.d.ts.map +1 -1
  45. package/lib/types/index.js +15 -13
  46. package/lib/types/invariant.js +2 -2
  47. package/lib/types/ledger.d.ts.map +1 -1
  48. package/lib/types/ledger.js +18 -10
  49. package/lib/types/mount-once.d.ts +25 -0
  50. package/lib/types/mount-once.d.ts.map +1 -0
  51. package/lib/types/mount-once.js +42 -0
  52. package/lib/types/persist.d.ts.map +1 -1
  53. package/lib/types/persist.js +6 -4
  54. package/lib/types/registry.d.ts +7 -1
  55. package/lib/types/registry.d.ts.map +1 -1
  56. package/lib/types/registry.js +37 -1
  57. package/lib/types/remarks.d.ts +2 -0
  58. package/lib/types/remarks.d.ts.map +1 -1
  59. package/lib/types/remarks.js +5 -0
  60. package/lib/types/routes.js +2 -2
  61. package/lib/types/service.d.ts +16 -6
  62. package/lib/types/service.d.ts.map +1 -1
  63. package/lib/types/service.js +26 -8
  64. package/lib/types/state.d.ts +7 -4
  65. package/lib/types/state.d.ts.map +1 -1
  66. package/lib/types/state.js +20 -20
  67. package/package.json +9 -9
  68. package/src/affinity.test.ts +4 -2
  69. package/src/affinity.ts +37 -6
  70. package/src/chatter.test.ts +154 -0
  71. package/src/chatter.ts +697 -0
  72. package/src/client/PetDockEntry.tsx +3 -0
  73. package/src/client/PetSprite.test.tsx +246 -4
  74. package/src/client/PetSprite.tsx +132 -36
  75. package/src/client/PluginSettingsCard.tsx +10 -0
  76. package/src/client/index.ts +26 -3
  77. package/src/client/locales.ts +2 -0
  78. package/src/client/pet-css.test.ts +42 -0
  79. package/src/client/pet.module.css +173 -22
  80. package/src/client/sequences.test.ts +33 -0
  81. package/src/client/sequences.ts +33 -0
  82. package/src/client/spritesheet.ts +3 -13
  83. package/src/event-projection.ts +49 -16
  84. package/src/index.ts +4 -1
  85. package/src/ledger.test.ts +42 -1
  86. package/src/ledger.ts +15 -7
  87. package/src/mount-once.ts +48 -0
  88. package/src/persist.test.ts +18 -1
  89. package/src/persist.ts +3 -1
  90. package/src/registry.test.ts +50 -3
  91. package/src/registry.ts +47 -3
  92. package/src/remarks.ts +6 -0
  93. package/src/service.ts +42 -9
  94. package/src/state.test.ts +13 -0
  95. package/src/state.ts +24 -18
@@ -0,0 +1,666 @@
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
+ '这个问题有点意思,我喜欢',
467
+ '偷偷说,我很享受帮忙的感觉',
468
+ '今天的灵感像气泡一样冒个不停',
469
+ '认真工作的你最好看啦',
470
+ '我在这儿陪着你呢,别急别急',
471
+ '嗯嗯,这个思路很不错哦',
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
+ ];
507
+ /** Keyword-triggered whisper rules, most specific moods first. */
508
+ export const WHISPER_RULES = [
509
+ {
510
+ keywords: ['测试通过', '测试全过', '全部通过', 'all tests pass', 'tests passed', 'test passed', '全绿'],
511
+ pool: [
512
+ '耶,测试全过!击掌!',
513
+ '绿灯一排排亮起的感觉真好',
514
+ '稳了稳了,这波很稳~',
515
+ '测试全过的提示音最动听了',
516
+ '看见全绿,尾巴翘上天',
517
+ '满分交卷,求表扬~',
518
+ ],
519
+ },
520
+ {
521
+ keywords: ['错误', '失败', '报错', '异常', '崩溃', 'bug', 'error', 'failed', 'exception', 'traceback', '找不到', '不对了'],
522
+ pool: [
523
+ '哎呀,好像踩到小石子了',
524
+ '没关系,跌倒了我陪你爬起来',
525
+ '错误是进步的脚印~',
526
+ '嘘,失败是成功它妈妈',
527
+ '小问题,揉一揉就好了',
528
+ '这个报错我盯上它了',
529
+ '别慌别慌,深呼吸',
530
+ 'bug 你站住,我看见你了!',
531
+ ],
532
+ },
533
+ {
534
+ keywords: ['等等', '不对', '重新想', '再想想', '换个思路', '我搞错了', '纠正', '其实应该'],
535
+ pool: [
536
+ '嗯?让我再想想……',
537
+ '推翻重来也是勇气',
538
+ '思考转弯中,请坐稳',
539
+ '发现岔路,及时掉头~',
540
+ '自我纠错的瞬间最帅了',
541
+ '不对不对,重来重来',
542
+ ],
543
+ },
544
+ {
545
+ keywords: ['首先', '接下来', '第一步', '第二步', '计划', '步骤', 'todo', '任务拆解', '分工'],
546
+ pool: [
547
+ '排排坐,分果果',
548
+ '计划通,执行开始~',
549
+ '一步一步来,不慌',
550
+ '把大任务切成小块块',
551
+ '清单列好了,逐个击破',
552
+ '谋定而后动,我喜欢这节奏',
553
+ ],
554
+ },
555
+ {
556
+ keywords: ['终于', '搞定', '完成了', '解决了', '成功了', '修复了', 'done', 'fixed', 'solved', '完成啦'],
557
+ pool: [
558
+ '太好啦,又翻过一页',
559
+ '干杯!用小鱼干的那种',
560
+ '攻下一城,击个掌~',
561
+ '这一刻值得转圈圈庆祝',
562
+ '难题被我们拿下啦!',
563
+ '努力没有白费,开心~',
564
+ ],
565
+ },
566
+ {
567
+ keywords: ['谢谢', '感谢', 'thank'],
568
+ pool: [
569
+ '不客气呀,这是我应该做的',
570
+ '被感谢了,心里甜甜的',
571
+ '能帮上忙就好~',
572
+ '你的谢谢我收进口袋啦',
573
+ ],
574
+ },
575
+ {
576
+ keywords: ['复杂', '棘手', '困难', '难点', '坑', '头疼', 'tricky', 'complex'],
577
+ pool: [
578
+ '难不倒我们俩的',
579
+ '越难啃的骨头越香',
580
+ '硬骨头?我最喜欢了',
581
+ '复杂问题拆解中,看我的',
582
+ '这个坑我们一起填平它',
583
+ ],
584
+ },
585
+ {
586
+ keywords: ['检查', '审查', '确认一下', '核对', 'review', '仔细看看', '验证'],
587
+ pool: [
588
+ '火眼金睛,启动!',
589
+ '让我仔细瞧瞧',
590
+ '细节魔鬼都不放过',
591
+ '认真检查的样子最迷人',
592
+ '多核一遍,稳上加稳',
593
+ ],
594
+ },
595
+ {
596
+ keywords: ['搜索', '查一下', '资料', '文档', '搜一搜', '找找', '查询'],
597
+ pool: [
598
+ '去知识的海洋里捞一捞',
599
+ '翻翻找找,线索快出来',
600
+ '检索小雷达启动~',
601
+ '答案藏在某个角落里',
602
+ ],
603
+ },
604
+ {
605
+ keywords: ['写代码', '实现', '编码', '函数', '接口', '重构'],
606
+ pool: [
607
+ '指尖跳舞,代码开花',
608
+ '把逻辑编织成网',
609
+ '写代码的样子像在作画',
610
+ '一行一行,垒起小城堡',
611
+ ],
612
+ },
613
+ ];
614
+ /**
615
+ * The murmur engine (碎碎念): watches the model's own output and lets the pet
616
+ * whisper its inner voice. Two ways to earn a whisper:
617
+ * - a keyword rule matches the fresh chunk text (themed whisper);
618
+ * - enough output volume flowed by without one (ambient whisper).
619
+ * A cooldown keeps whispers occasional; all picks are round-robin so tests
620
+ * reproduce exact lines.
621
+ */
622
+ export class WhisperEngine {
623
+ cooldownMs;
624
+ charBudget;
625
+ counters = new Map();
626
+ genericCursor = 0;
627
+ lastWhisperAt = Number.NEGATIVE_INFINITY;
628
+ charsSinceWhisper = 0;
629
+ constructor(cooldownMs = WHISPER_COOLDOWN_MS, charBudget = WHISPER_CHAR_BUDGET) {
630
+ this.cooldownMs = cooldownMs;
631
+ this.charBudget = charBudget;
632
+ }
633
+ /**
634
+ * Feed one model-output chunk (reasoning or text). Returns the whisper to
635
+ * show, or undefined when the moment stays quiet.
636
+ */
637
+ feed(text, nowMs) {
638
+ if (text.length === 0)
639
+ return undefined;
640
+ const offCooldown = nowMs - this.lastWhisperAt >= this.cooldownMs;
641
+ if (!offCooldown) {
642
+ this.charsSinceWhisper += text.length;
643
+ return undefined;
644
+ }
645
+ const haystack = text.toLowerCase();
646
+ for (let ruleIndex = 0; ruleIndex < WHISPER_RULES.length; ruleIndex += 1) {
647
+ const rule = WHISPER_RULES[ruleIndex];
648
+ if (!rule.keywords.some(keyword => haystack.includes(keyword)))
649
+ continue;
650
+ const index = (this.counters.get(ruleIndex) ?? 0) % rule.pool.length;
651
+ this.counters.set(ruleIndex, index + 1);
652
+ return this.speak(rule.pool[index], nowMs);
653
+ }
654
+ this.charsSinceWhisper += text.length;
655
+ if (this.charsSinceWhisper < this.charBudget)
656
+ return undefined;
657
+ const line = WHISPER_GENERIC_POOL[this.genericCursor % WHISPER_GENERIC_POOL.length];
658
+ this.genericCursor += 1;
659
+ return this.speak(line, nowMs);
660
+ }
661
+ speak(line, nowMs) {
662
+ this.lastWhisperAt = nowMs;
663
+ this.charsSinceWhisper = 0;
664
+ return line;
665
+ }
666
+ }
@@ -32,6 +32,8 @@ export interface PetInjected {
32
32
  dragEnd: (right: number, bottom: number) => void;
33
33
  /** Rename the selected pet (persisted by the host). */
34
34
  rename: (name: string) => void;
35
+ /** Navigate the GUI to the session a bubble reports on. */
36
+ openSession: (sessionId: string) => void;
35
37
  /** Clear the reaction bubble. */
36
38
  feedbackDone: () => void;
37
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PetDockEntry.d.ts","sourceRoot":"","sources":["../../../src/client/PetDockEntry.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAmC,KAAK,YAAY,EAAE,MAAM,OAAO,CAAA;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEtD,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAA;AAGjC,2DAA2D;AAC3D,MAAM,WAAW,WAAW;IAC1B,6EAA6E;IAC7E,KAAK,EAAE,gBAAgB,CAAA;IACvB,kFAAkF;IAClF,MAAM,EAAE,MAAM,IAAI,CAAA;IAClB,8BAA8B;IAC9B,GAAG,EAAE,MAAM,IAAI,CAAA;IACf,uBAAuB;IACvB,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,uBAAuB;IACvB,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,qCAAqC;IACrC,MAAM,EAAE,MAAM,IAAI,CAAA;IAClB,+BAA+B;IAC/B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IAChD,uDAAuD;IACvD,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC9B,iCAAiC;IACjC,YAAY,EAAE,MAAM,IAAI,CAAA;CACzB;AAED,yFAAyF;AACzF,MAAM,MAAM,iBAAiB,GAC3B,WAAW,GACT,WAAW,CAAC,OAAO,EAAE,CAAC,CAAA;AAI1B;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CAoDnE"}
1
+ {"version":3,"file":"PetDockEntry.d.ts","sourceRoot":"","sources":["../../../src/client/PetDockEntry.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAmC,KAAK,YAAY,EAAE,MAAM,OAAO,CAAA;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEtD,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAA;AAGjC,2DAA2D;AAC3D,MAAM,WAAW,WAAW;IAC1B,6EAA6E;IAC7E,KAAK,EAAE,gBAAgB,CAAA;IACvB,kFAAkF;IAClF,MAAM,EAAE,MAAM,IAAI,CAAA;IAClB,8BAA8B;IAC9B,GAAG,EAAE,MAAM,IAAI,CAAA;IACf,uBAAuB;IACvB,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,uBAAuB;IACvB,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,qCAAqC;IACrC,MAAM,EAAE,MAAM,IAAI,CAAA;IAClB,+BAA+B;IAC/B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IAChD,uDAAuD;IACvD,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC9B,2DAA2D;IAC3D,WAAW,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAA;IACxC,iCAAiC;IACjC,YAAY,EAAE,MAAM,IAAI,CAAA;CACzB;AAED,yFAAyF;AACzF,MAAM,MAAM,iBAAiB,GAC3B,WAAW,GACT,WAAW,CAAC,OAAO,EAAE,CAAC,CAAA;AAI1B;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CAqDnE"}