@linxin666/dsh-pet 0.3.4 → 0.3.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 (70) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +13 -10
  3. package/README.zh.md +13 -10
  4. package/contracts/voice-pack-v1.schema.json +53 -28
  5. package/cordis.patch.yml +1 -1
  6. package/lib/client.js +166 -30
  7. package/lib/client.js.map +1 -1
  8. package/lib/index.js +400 -478
  9. package/lib/invariant.js +1 -1
  10. package/lib/{state-DrMX22GL.js → state-NvDEoCln.js} +5 -2
  11. package/lib/types/access.d.ts +5 -4
  12. package/lib/types/access.d.ts.map +1 -1
  13. package/lib/types/access.js +2 -12
  14. package/lib/types/affinity.d.ts +2 -0
  15. package/lib/types/affinity.d.ts.map +1 -1
  16. package/lib/types/affinity.js +12 -0
  17. package/lib/types/chatter.d.ts +68 -46
  18. package/lib/types/chatter.d.ts.map +1 -1
  19. package/lib/types/chatter.js +243 -301
  20. package/lib/types/client/PetSprite.d.ts.map +1 -1
  21. package/lib/types/client/PetSprite.js +23 -18
  22. package/lib/types/client/index.d.ts.map +1 -1
  23. package/lib/types/client/index.js +26 -9
  24. package/lib/types/client/locales.d.ts +18 -0
  25. package/lib/types/client/locales.d.ts.map +1 -1
  26. package/lib/types/client/locales.js +18 -0
  27. package/lib/types/client/renderers/frames2d.d.ts +12 -0
  28. package/lib/types/client/renderers/frames2d.d.ts.map +1 -1
  29. package/lib/types/client/renderers/frames2d.js +143 -18
  30. package/lib/types/event-projection.d.ts +9 -4
  31. package/lib/types/event-projection.d.ts.map +1 -1
  32. package/lib/types/event-projection.js +46 -14
  33. package/lib/types/ledger.d.ts +4 -2
  34. package/lib/types/ledger.d.ts.map +1 -1
  35. package/lib/types/ledger.js +4 -4
  36. package/lib/types/pair-access.d.ts +35 -0
  37. package/lib/types/pair-access.d.ts.map +1 -0
  38. package/lib/types/pair-access.js +19 -0
  39. package/lib/types/remarks.d.ts +1 -1
  40. package/lib/types/remarks.d.ts.map +1 -1
  41. package/lib/types/remarks.js +11 -2
  42. package/lib/types/routes.d.ts.map +1 -1
  43. package/lib/types/routes.js +8 -3
  44. package/lib/types/service.d.ts +7 -11
  45. package/lib/types/service.d.ts.map +1 -1
  46. package/lib/types/service.js +31 -20
  47. package/lib/types/voice-pack.d.ts +11 -7
  48. package/lib/types/voice-pack.d.ts.map +1 -1
  49. package/lib/types/voice-pack.js +80 -49
  50. package/package.json +1 -1
  51. package/src/access.ts +7 -27
  52. package/src/affinity.ts +13 -0
  53. package/src/chatter.test.ts +68 -38
  54. package/src/chatter.ts +269 -316
  55. package/src/client/PetSprite.test.tsx +50 -15
  56. package/src/client/PetSprite.tsx +30 -25
  57. package/src/client/index.test.tsx +10 -1
  58. package/src/client/index.ts +29 -10
  59. package/src/client/locales.ts +18 -0
  60. package/src/client/renderers/frames2d.test.ts +101 -0
  61. package/src/client/renderers/frames2d.ts +138 -18
  62. package/src/event-projection.ts +57 -16
  63. package/src/ledger.ts +6 -4
  64. package/src/pair-access.ts +49 -0
  65. package/src/remarks.test.ts +10 -0
  66. package/src/remarks.ts +9 -2
  67. package/src/routes.ts +9 -4
  68. package/src/service.ts +36 -30
  69. package/src/voice-pack.test.ts +87 -25
  70. package/src/voice-pack.ts +87 -49
package/src/chatter.ts CHANGED
@@ -7,10 +7,12 @@
7
7
  * the working-activity plugin's status line. Lines rotate round-robin —
8
8
  * while a phase persists the copy advances every few seconds, so the pet
9
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.
10
+ * 2. The murmur engine (碎碎念): the pet's inner whispers category
11
+ * lines woken by the SITUATION (thinking / writing / the running tool
12
+ * family), plus outcome lines woken only by structured session results
13
+ * (test green, tool errors, turn completion). The model's own prose is
14
+ * never read, and no whisper ever quotes real content. Cooldowns keep
15
+ * whispers occasional.
14
16
  *
15
17
  * Pure and deterministic: round-robin everywhere (no Math.random), clocks are
16
18
  * injected. The first line of each status pool is the legacy fixed copy the
@@ -515,262 +517,214 @@ export class StatusVoice {
515
517
  }
516
518
  }
517
519
 
518
- /** One murmur trigger: keywords in the model output wake a themed pool. */
519
- export interface WhisperRule {
520
- /** Lowercase substrings that wake this pool (matched against chunk text). */
521
- keywords: readonly string[]
522
- /** Themed inner-whisper lines. */
523
- pool: readonly string[]
524
- }
520
+ /** The pet's outcome moments woken by structured session results only. */
521
+ export type WhisperResult = 'pass' | 'fail' | 'done'
522
+
523
+ /** The situations a whisper can comment on — the pet's category awareness. */
524
+ export type WhisperCategory =
525
+ | 'thinking'
526
+ | 'writing'
527
+ | 'reading'
528
+ | 'editing'
529
+ | 'running'
530
+ | 'searching'
531
+ | 'git'
532
+ | 'delegating'
533
+ | 'browsing'
534
+ | 'generic'
535
+
536
+ /** Every whisper category key, in declaration order (voice-pack key allow-list). */
537
+ export const WHISPER_CATEGORIES: readonly WhisperCategory[] = [
538
+ 'thinking', 'writing', 'reading', 'editing', 'running', 'searching',
539
+ 'git', 'delegating', 'browsing', 'generic',
540
+ ]
525
541
 
526
- /** Murmur pacing: cooldown between whispers and output volume that earns one. */
542
+ /** Every whisper outcome key, in declaration order (voice-pack key allow-list). */
543
+ export const WHISPER_RESULTS: readonly WhisperResult[] = ['pass', 'fail', 'done']
544
+
545
+ /** Murmur pacing: the cooldown between category whispers. */
527
546
  export const WHISPER_COOLDOWN_MS = 9000
528
- export const WHISPER_CHAR_BUDGET = 420
547
+ /** Outcome whispers get their own shorter cooldown so a real moment still speaks. */
548
+ export const WHISPER_RESULT_COOLDOWN_MS = 5000
529
549
  /** How long a whisper stays on screen (host-side expiry). */
530
550
  export const WHISPER_TTL_MS = 8000
531
551
 
532
- /** Ambient inner-whisper pool (no keyword needed; earned by output volume). */
533
- export const WHISPER_GENERIC_POOL: readonly string[] = [
534
- '哼哧哼哧,大脑转得飞快~',
535
- 'loading 99%……就差最后一步',
536
- '嗯……让我捋捋',
537
- '灵感来了,先记小本本上',
538
- '脑子在冒烟,但还能撑',
539
- '这个报错,我好像在哪见过',
540
- '专注模式 ON,请勿打扰',
541
- '思路通了,舒服了',
542
- '有点困……不行,还能肝',
543
- '让我嚼一嚼这个问题',
544
- '盘,都可以盘',
545
- '这波操作,我给自己点个赞',
546
- '别催别催,在想呢',
547
- '唔,这个细节差点漏掉',
548
- '脑子转太快,差点绕晕自己',
549
- '陪你干活,稳赚不亏',
550
- '深呼吸,马上就好',
551
- '诶,等等,好像发现了什么',
552
- '手速拉满,键盘冒火星',
553
- '摸鱼是不可能摸鱼的,就瞄一眼窗外',
554
- '今天也是稳扎稳打的一天',
555
- '把大问题拆成小饼干,一口一个',
556
- '这题有戏,我闻到了',
557
- '尾巴轻晃,心情有点小得意',
558
- '好结果是熬出来的,不慌',
559
- '啊,想岔了,重新来',
560
- '嗯嗯,思路对头,就这么干',
561
- '小本本记满了,都是干货',
562
- '打完这波,求摸摸奖励~',
563
- '这坑我记住了,下次绕道',
564
- '窗外云在飘,代码在跑,挺好',
565
- '嘘,正到关键处',
566
- '这个方案……让我再品品',
567
- '干活呢,别打扰我数数',
568
- '心里默默给你比了个耶',
569
- '思路像小鱼,逮住一条是一条',
570
- '嗯……有点东西,等我深挖',
571
- '收个尾就能喘口气了',
572
- '目标锁定,冲就完了',
573
- '嗯,这波配合不错',
574
- '困了……还能再战三回合',
575
- '思考.gif 加载中',
576
- '我本地能跑啊……哦,我就是干活的',
577
- '有点饿,小鱼干存货还够吗',
578
- '刚想通,一被打断又忘了,气',
579
- '缓冲中,请稍候',
580
- '这网速,比我思考还慢',
581
- '脑子在后台跑批',
582
- '内存不足,但热情够',
583
- '404:思路未找到,重试中',
584
- '这需求有点玄学,但能写',
585
- '诶,这 bug 还会闪现?',
586
- '刚说简单,结果打脸了',
587
- '自信满满,结果翻车',
588
- '这活不难,就是有点复杂',
589
- '我装的,其实心里没底',
590
- '别看我稳,我也慌',
591
- '假装很懂的样子,其实在查文档',
592
- '窗外鸟叫了两声,我听到了',
593
- '打了个哈欠,没人看见',
594
- '今天的状态:七分精神三分困',
595
- '刚想偷懒,又想起来你还在等',
596
- '数了数今天的产出,还行',
597
- '有点想伸懒腰',
598
- '饿意来袭,忍住',
599
- '灵感像猫一样,不追它自己来',
600
- '坐太久,尾巴麻了',
601
- '快了快了',
602
- '马上马上',
603
- '等下,我记得在哪见过',
604
- '呃,忘了,重新想',
605
- '诶,这个思路可以',
606
- '嗯?有意思',
607
- '行,就这么办',
608
- '好嘞',
609
- '收到收到',
610
- '冲了冲了',
611
- '稳',
612
- '妥',
613
- '得嘞',
614
- '你忙你的,我盯着呢',
615
- '放心,有我呢',
616
- '咱俩配合,无往不利',
617
- '你专注的样子,我默默记下了',
618
- ]
552
+ /** Map a tool family onto the whisper category it belongs to. */
553
+ export function whisperCategoryOf(tool: ToolCategory): WhisperCategory {
554
+ switch (tool) {
555
+ case 'read':
556
+ case 'grep':
557
+ case 'find':
558
+ case 'ls':
559
+ return 'reading'
560
+ case 'write':
561
+ case 'edit':
562
+ return 'editing'
563
+ case 'shell':
564
+ return 'running'
565
+ case 'webSearch':
566
+ case 'webFetch':
567
+ case 'memory':
568
+ case 'mcp':
569
+ return 'searching'
570
+ case 'git':
571
+ return 'git'
572
+ case 'subagent':
573
+ case 'todo':
574
+ return 'delegating'
575
+ case 'browser':
576
+ return 'browsing'
577
+ case 'ask':
578
+ case 'generic':
579
+ return 'generic'
580
+ }
581
+ }
619
582
 
620
- /** Keyword-triggered whisper rules, most specific moods first. */
621
- export const WHISPER_RULES: readonly WhisperRule[] = [
622
- {
623
- keywords: ['测试通过', '测试全过', '全部通过', 'all tests pass', 'tests passed', 'test passed', '全绿'],
624
- pool: [
625
- '全绿!亮瞎我眼了',
626
- '测试全过,击掌~',
627
- '稳了稳了,这波稳得很',
628
- '绿灯一排排,看着就舒坦',
629
- '能跑!没报错!',
630
- '全绿,收工摸鱼去',
631
- '测试过了,尾巴翘上天',
632
- '漂亮,一次过',
633
- '测试过了,奖励自己一口小鱼干',
634
- '绿得发光,稳',
635
- '又双叒叕全绿',
636
- '这波测试,赢得干脆',
637
- ],
638
- },
639
- {
640
- keywords: ['错误', '失败', '报错', '异常', '崩溃', 'bug', 'error', 'failed', 'exception', 'traceback', '找不到', '不对了'],
641
- pool: [
642
- '哎呀,踩到小石子了',
643
- '翻车了……没事,扶起来继续',
644
- '错误是进步的脚印,我懂',
645
- '这报错我盯上它了',
646
- '我本地能跑啊?哦,我一直在跑',
647
- '别慌,深呼吸,先看报错',
648
- 'bug 你站住,我看见你了',
649
- '绷不住了……好,继续修',
650
- '报错这东西,见一个修一个',
651
- '又是它,老熟人了',
652
- '问题不大,就是有点问题',
653
- '先别慌,我看看到底咋回事',
654
- '这错报得,比我还委屈',
655
- '修好它,今天才不算白干',
656
- ],
657
- },
658
- {
659
- keywords: ['等等', '不对', '重新想', '再想想', '换个思路', '我搞错了', '纠正', '其实应该'],
660
- pool: [
661
- '嗯?让我再想想……',
662
- '推翻重来,也是种勇气',
663
- '发现岔路,及时掉头',
664
- '不对不对,重来重来',
665
- '自我纠错的瞬间,最帅了',
666
- '呃,刚说错了,收回',
667
- '哎,绕远了,拉回来',
668
- '回头一看,原来这么简单',
669
- '纠正完,思路清爽多了',
670
- '转弯不丢人,卡死才丢人',
671
- ],
672
- },
673
- {
674
- keywords: ['首先', '接下来', '第一步', '第二步', '计划', '步骤', 'todo', '任务拆解', '分工'],
675
- pool: [
676
- '排排坐,分果果',
677
- '计划通,执行开始',
678
- '一步一步来,不慌',
679
- '大任务切成小块块,好下口',
680
- '清单列好了,逐个击破',
681
- '谋定而后动,这节奏我熟',
682
- '先干这个,再干那个',
683
- '头绪理清了,开整',
684
- '步骤在手,心里不慌',
685
- '安排得明明白白',
686
- ],
687
- },
688
- {
689
- keywords: ['终于', '搞定', '完成了', '解决了', '成功了', '修复了', 'done', 'fixed', 'solved', '完成啦'],
690
- pool: [
691
- '太好了,又翻过一页',
692
- '搞定,收工~',
693
- '攻下一城,击掌!',
694
- '难题被拿下了,转个圈',
695
- '努力没白费,开心',
696
- '齐活,漂亮',
697
- '收工收工,今天圆满',
698
- '完成!心里踏实了',
699
- '这波,稳得一批',
700
- '任务清零,舒服',
701
- '搞定,可以伸个懒腰了',
702
- '又完成一件,成就感+1',
703
- ],
704
- },
705
- {
706
- keywords: ['谢谢', '感谢', 'thank'],
707
- pool: [
708
- '不客气呀,顺手的事',
709
- '被感谢了,心里甜甜的',
710
- '能帮上忙就好~',
711
- '你的谢意,我收进口袋啦',
712
- '这话我爱听',
713
- '客气啥,应该的',
714
- '收下这份心意,干劲+1',
715
- '你谢我,我谢你,扯平啦',
716
- ],
717
- },
718
- {
719
- keywords: ['复杂', '棘手', '困难', '难点', '坑', '头疼', 'tricky', 'complex'],
720
- pool: [
721
- '难不倒我们俩的',
722
- '越难啃的骨头越香',
723
- '硬骨头?我最喜欢了',
724
- '复杂问题拆开看,小事',
725
- '这坑我们一起填',
726
- '有点东西,但不多',
727
- '硬骨头,慢慢啃',
728
- '问题越难,赢的时候越爽',
729
- '绕是绕不过去的,正面刚',
730
- '再难的题,拆开都是小问号',
731
- ],
732
- },
733
- {
734
- keywords: ['检查', '审查', '确认一下', '核对', 'review', '仔细看看', '验证'],
735
- pool: [
736
- '火眼金睛,启动',
737
- '让我仔细瞧瞧',
738
- '细节魔鬼,一个都不放过',
739
- '认真检查的样子最迷人',
740
- '多核一遍,稳上加稳',
741
- '再看一眼,不亏',
742
- '确认键,点了才安心',
743
- '细节控上线',
744
- '查完这遍,稳了',
745
- ],
746
- },
747
- {
748
- keywords: ['搜索', '查一下', '资料', '文档', '搜一搜', '找找', '查询'],
749
- pool: [
750
- '去知识的海洋里捞一捞',
751
- '翻翻找找,线索快出来',
752
- '检索小雷达启动',
753
- '答案就藏在某个角落',
754
- '线索有点散,拼一下',
755
- '找东西,我最在行',
756
- '答案在网线那头等我',
757
- '翻箱倒柜中,稍等',
758
- ],
759
- },
760
- {
761
- keywords: ['写代码', '实现', '编码', '函数', '接口', '重构'],
762
- pool: [
763
- '指尖跳舞,代码开花',
764
- '把逻辑织成网',
765
- '一行一行,垒起小城堡',
766
- '这代码写得,我自己都佩服',
767
- '码着码着,天就亮了',
768
- '代码跑通了,比中奖还开心',
769
- '这行代码,写得有点帅',
770
- '写完再润润,讲究',
771
- ],
772
- },
773
- ]
583
+ /**
584
+ * Whether a tool invocation looks like a test run. The whisper engine never
585
+ * reads the model's prose (a discussion that merely mentions a keyword must
586
+ * not wake a mood); a test-outcome mood is wanted only when a test tool
587
+ * actually ran, so the projection marks the call at tool/call time and the
588
+ * pass mood fires from the paired tool/result.
589
+ */
590
+ export function looksLikeTestTool(name: string, argumentsText: string | undefined): boolean {
591
+ const tool = name.toLowerCase()
592
+ if (/(^|[\/_.-])(test|tests|spec|vitest|jest|pytest|mocha|playwright|cypress|karma)([\/_.-]|$)/.test(tool)) {
593
+ return true
594
+ }
595
+ if (argumentsText === undefined) return false
596
+ // Prefer the real command / code fields when the arguments parse; the raw
597
+ // JSON fallback still catches model-produced shapes the parser misses.
598
+ let haystack = argumentsText.toLowerCase()
599
+ try {
600
+ const parsed = JSON.parse(argumentsText) as unknown
601
+ if (typeof parsed === 'object' && parsed !== null) {
602
+ const record = parsed as Record<string, unknown>
603
+ const command = record.command
604
+ const code = record.code
605
+ const picked = typeof command === 'string' && command !== ''
606
+ ? command
607
+ : typeof code === 'string' && code !== ''
608
+ ? code
609
+ : undefined
610
+ if (picked !== undefined) haystack = picked.toLowerCase()
611
+ }
612
+ } catch {
613
+ // Keep the raw text below.
614
+ }
615
+ return /\b(pnpm|npm|yarn|npx|bun|python)\s+(run\s+)?(test|tests?)\b/.test(haystack)
616
+ || /\b(pytest|vitest|jest|mocha|cypress|playwright|go test|cargo test)\b/.test(haystack)
617
+ }
618
+
619
+ /** Category-level inner-whisper pools — the pet knows roughly what is going on. */
620
+ export const WHISPER_CATEGORY_POOLS: Readonly<Record<WhisperCategory, readonly string[]>> = {
621
+ thinking: [
622
+ '先在脑子里搭个框架',
623
+ '它在心里打草稿,我垫着脚看',
624
+ '思路在一颗一颗冒泡',
625
+ '脑内开会中,都别抢话筒',
626
+ '先想清楚,再动手不迟',
627
+ '草稿纸已经画满了',
628
+ '让我听听它下一步打算',
629
+ '嗯,方案在成型了',
630
+ ],
631
+ writing: [
632
+ '落笔成文,我旁边听着',
633
+ '句子排着队往外走',
634
+ '把想法一句句摆整齐',
635
+ '它在组织语言,我打打气',
636
+ '写回复呢,不催',
637
+ '字斟句酌,快好了',
638
+ ],
639
+ reading: [
640
+ '翻资料呢,我保持安静',
641
+ '一行一行读,不跳页',
642
+ '在纸堆里找线索',
643
+ '眼珠子跟着字跑',
644
+ '边读边做记号',
645
+ '翻箱倒柜找重点',
646
+ ],
647
+ editing: [
648
+ '动手改起来了,手稳一点',
649
+ '这里补一笔,那边修一修',
650
+ '在改东西,听不到声音才怪',
651
+ '落笔小心,别有错别字',
652
+ '改写的节奏,我听得见',
653
+ '刷刷地改,一行都没跑',
654
+ ],
655
+ running: [
656
+ '跑起来了跑起来了',
657
+ '命令敲出去,等个回响',
658
+ '在跑什么呢,我踮脚看',
659
+ '输出开始冒烟了',
660
+ '它在跑活,我不吵',
661
+ '盯着输出,蹲一个结果',
662
+ '这波跑完就靠它了',
663
+ ],
664
+ searching: [
665
+ '去外面捞点信息',
666
+ '翻翻记忆库,等我一小会儿',
667
+ '顺着网线找线索',
668
+ '把老账翻出来对一对',
669
+ '情报在路上了',
670
+ '搜索引擎当跑腿',
671
+ ],
672
+ git: [
673
+ '版本在往前迈步',
674
+ '改动排队上车',
675
+ '提交历史在长个子',
676
+ '分支合并,神清气爽',
677
+ '记录都焊在时间线上',
678
+ ],
679
+ delegating: [
680
+ '派了活儿出去,等回话',
681
+ '清单列好,一件件来',
682
+ '任务拆开分了组',
683
+ '手下的伙计在远处跑着',
684
+ '分工完毕,各司其职',
685
+ ],
686
+ browsing: [
687
+ '它在看网页,我偷瞄两眼',
688
+ '页面一张张翻过去',
689
+ '网页里翻答案呢',
690
+ '这网速,我先歇会儿',
691
+ ],
692
+ generic: [
693
+ '这波活儿,我陪着',
694
+ '又开工了,我盯梢',
695
+ '它忙它的,我守着',
696
+ '不打扰,就安静待着',
697
+ '有活儿就有我',
698
+ ],
699
+ }
700
+
701
+ /** The pet's outcome reactions — woken by structured session results only. */
702
+ export const WHISPER_RESULT_POOLS: Readonly<Record<WhisperResult, readonly string[]>> = {
703
+ pass: [
704
+ '全绿!亮瞎我眼了',
705
+ '测试过了,击掌~',
706
+ '绿灯一排排,看着就舒坦',
707
+ '稳了稳了,这波稳得很',
708
+ '全绿,奖励自己一口小鱼干',
709
+ '这波测试,赢得干脆',
710
+ ],
711
+ fail: [
712
+ '哎呀,踩到小石子了',
713
+ '这报错我盯上它了',
714
+ '别慌,先看它在喊什么',
715
+ '修好它,今天才不算白干',
716
+ '又一次踩坑,老熟人了',
717
+ '问题不大,就是有点问题',
718
+ ],
719
+ done: [
720
+ '搞定,收工~',
721
+ '又翻过一页,踏实',
722
+ '努力没白费,开心',
723
+ '任务清零,舒服',
724
+ '攻下一城,转个圈',
725
+ '收工收工,今天圆满',
726
+ ],
727
+ }
774
728
 
775
729
  /**
776
730
  * Voice-pack overrides (pet-center M4, issue #677): the content a voice
@@ -783,8 +737,9 @@ export const WHISPER_RULES: readonly WhisperRule[] = [
783
737
  * - status/tools/toolRemaining: a non-empty override replaces the built-in
784
738
  * pool for that key; an empty override falls back to the built-in pool
785
739
  * (a scene line always renders, so it can never be blanked).
786
- * - whispers.generic / whispers.rules: the override REPLACES the built-in
787
- * section; an empty array mutes that channel (ambient or keyword).
740
+ * - whispers.categories / whispers.results: a key replaces that key's
741
+ * built-in pool; an explicit empty array mutes that channel (a whisper
742
+ * can always be silenced, unlike a scene line).
788
743
  */
789
744
  export interface VoicePackOverrides {
790
745
  /** Status copy pools by scene; each key replaces that scene's pool. */
@@ -793,101 +748,99 @@ export interface VoicePackOverrides {
793
748
  tools?: Partial<Record<ToolCategory, readonly string[]>>
794
749
  /** The parallel-tools count line pool ({n} interpolates the count). */
795
750
  toolRemaining?: readonly string[]
796
- /** Murmur pools; each section replaces the built-in one as a whole. */
751
+ /** Murmur pools; each key replaces the built-in pool as a whole. */
797
752
  whispers?: {
798
- /** Ambient inner-whisper pool (empty mutes ambient whispers). */
799
- generic?: readonly string[]
800
- /** Ordered keyword rules (empty disables keyword-triggered whispers). */
801
- rules?: readonly WhisperRule[]
753
+ /** Category pools; a key replaces that category's pool (empty mutes it). */
754
+ categories?: Partial<Record<WhisperCategory, readonly string[]>>
755
+ /** Outcome pools (test green / error / completion); empty mutes the outcome. */
756
+ results?: Partial<Record<WhisperResult, readonly string[]>>
802
757
  }
803
758
  }
804
759
 
805
760
  /** Read the current effective voice-pack overrides (draw-time resolution). */
806
761
  export type VoicePoolsProvider = () => VoicePackOverrides
807
762
 
808
- /** The built-in voice pack: the plugin's default copy, unchanged since v1. */
763
+ /** The built-in voice pack: the plugin's default copy. */
809
764
  export const BUILTIN_VOICE_PACK: VoicePackOverrides = {
810
765
  status: STATUS_POOLS,
811
766
  tools: TOOL_POOLS,
812
767
  toolRemaining: TOOL_REMAINING_POOL,
813
- whispers: { generic: WHISPER_GENERIC_POOL, rules: WHISPER_RULES },
768
+ whispers: { categories: WHISPER_CATEGORY_POOLS, results: WHISPER_RESULT_POOLS },
814
769
  }
815
770
 
816
771
  /**
817
- * The murmur engine (碎碎念): watches the model's own output and lets the pet
818
- * whisper its inner voice. Two ways to earn a whisper:
819
- * - a keyword rule matches the fresh chunk text (themed whisper);
820
- * - enough output volume flowed by without one (ambient whisper).
821
- * A cooldown keeps whispers occasional; all picks are round-robin so tests
822
- * reproduce exact lines. The voice-pack provider (pet-center M4) swaps the
823
- * pools at draw time, so a pet switch re-voices live engines in place.
772
+ * The murmur engine (碎碎念): the pet's inner voice while sessions work.
773
+ * Category awareness: the projection feeds the current situation (thinking /
774
+ * writing / the running tool family), and the engine answers with a line from
775
+ * that category's pool so a whisper always roughly knows what is going on
776
+ * without ever quoting real content (no tool names, no paths, no model text).
777
+ * Outcome moments (test green, tool errors, turn completion) fire from the
778
+ * structured result events, never from output text, so a mood cannot mis-
779
+ * fire on a discussion that merely mentions a keyword. A cooldown keeps
780
+ * whispers occasional; all picks are round-robin so tests reproduce exact
781
+ * lines. The voice-pack provider (pet-center M4) swaps the pools at draw
782
+ * time, so a pet switch re-voices live engines in place.
824
783
  */
825
784
  export class WhisperEngine {
826
785
  private readonly pools: VoicePoolsProvider
827
- private readonly cooldownMs: number
828
- private readonly charBudget: number
829
- private readonly counters = new Map<number, number>()
830
- private genericCursor = 0
786
+ private readonly categoryCooldownMs: number
787
+ private readonly resultCooldownMs: number
788
+ private readonly categoryCursor = new Map<WhisperCategory, number>()
789
+ private readonly resultCursor = new Map<WhisperResult, number>()
831
790
  private lastWhisperAt = Number.NEGATIVE_INFINITY
832
- private charsSinceWhisper = 0
833
791
 
834
792
  constructor(
835
793
  pools: VoicePoolsProvider = () => BUILTIN_VOICE_PACK,
836
- cooldownMs: number = WHISPER_COOLDOWN_MS,
837
- charBudget: number = WHISPER_CHAR_BUDGET,
794
+ categoryCooldownMs: number = WHISPER_COOLDOWN_MS,
795
+ resultCooldownMs: number = WHISPER_RESULT_COOLDOWN_MS,
838
796
  ) {
839
797
  this.pools = pools
840
- this.cooldownMs = cooldownMs
841
- this.charBudget = charBudget
798
+ this.categoryCooldownMs = categoryCooldownMs
799
+ this.resultCooldownMs = resultCooldownMs
842
800
  }
843
801
 
844
- /**
845
- * Effective keyword rules: an override replaces the built-in rules as a
846
- * whole; an explicit empty array disables keyword-triggered whispers.
847
- */
848
- private rules(): readonly WhisperRule[] {
849
- const override = this.pools().whispers?.rules
850
- return override === undefined ? WHISPER_RULES : override
802
+ /** Effective category pool (an explicit empty override mutes the category). */
803
+ private categoryPool(category: WhisperCategory): readonly string[] {
804
+ const override = this.pools().whispers?.categories?.[category]
805
+ return override === undefined ? WHISPER_CATEGORY_POOLS[category]! : override
851
806
  }
852
807
 
853
- /** Effective ambient pool (an explicit empty array mutes ambient whispers). */
854
- private generic(): readonly string[] {
855
- const override = this.pools().whispers?.generic
856
- return override === undefined ? WHISPER_GENERIC_POOL : override
808
+ /** Effective outcome pool (an explicit empty override mutes the outcome). */
809
+ private resultPool(kind: WhisperResult): readonly string[] {
810
+ const override = this.pools().whispers?.results?.[kind]
811
+ return override === undefined ? WHISPER_RESULT_POOLS[kind]! : override
857
812
  }
858
813
 
859
814
  /**
860
- * Feed one model-output chunk (reasoning or text). Returns the whisper to
861
- * show, or undefined when the moment stays quiet.
815
+ * Feed one situation while a session works. Returns the whisper to show,
816
+ * or undefined when the moment stays quiet (cooldown, or the category
817
+ * pool is muted).
862
818
  */
863
- feed(text: string, nowMs: number): string | undefined {
864
- if (text.length === 0) return undefined
865
- const offCooldown = nowMs - this.lastWhisperAt >= this.cooldownMs
866
- if (!offCooldown) {
867
- this.charsSinceWhisper += text.length
868
- return undefined
869
- }
870
- const haystack = text.toLowerCase()
871
- const rules = this.rules()
872
- for (let ruleIndex = 0; ruleIndex < rules.length; ruleIndex += 1) {
873
- const rule = rules[ruleIndex]!
874
- if (!rule.keywords.some(keyword => haystack.includes(keyword))) continue
875
- const index = (this.counters.get(ruleIndex) ?? 0) % rule.pool.length
876
- this.counters.set(ruleIndex, index + 1)
877
- return this.speak(rule.pool[index]!, nowMs)
878
- }
879
- this.charsSinceWhisper += text.length
880
- if (this.charsSinceWhisper < this.charBudget) return undefined
881
- const generic = this.generic()
882
- if (generic.length === 0) return undefined
883
- const line = generic[this.genericCursor % generic.length]!
884
- this.genericCursor += 1
885
- return this.speak(line, nowMs)
819
+ feed(category: WhisperCategory, nowMs: number): string | undefined {
820
+ if (nowMs - this.lastWhisperAt < this.categoryCooldownMs) return undefined
821
+ const pool = this.categoryPool(category)
822
+ if (pool.length === 0) return undefined
823
+ const index = (this.categoryCursor.get(category) ?? 0) % pool.length
824
+ this.categoryCursor.set(category, index + 1)
825
+ return this.speak(pool[index]!, nowMs)
826
+ }
827
+
828
+ /**
829
+ * Feed one structured outcome (test green / tool failure / turn
830
+ * completion). Outcomes carry their own shorter cooldown so the emotional
831
+ * moment is heard unless another whisper just spoke.
832
+ */
833
+ result(kind: WhisperResult, nowMs: number): string | undefined {
834
+ if (nowMs - this.lastWhisperAt < this.resultCooldownMs) return undefined
835
+ const pool = this.resultPool(kind)
836
+ if (pool.length === 0) return undefined
837
+ const index = (this.resultCursor.get(kind) ?? 0) % pool.length
838
+ this.resultCursor.set(kind, index + 1)
839
+ return this.speak(pool[index]!, nowMs)
886
840
  }
887
841
 
888
842
  private speak(line: string, nowMs: number): string {
889
843
  this.lastWhisperAt = nowMs
890
- this.charsSinceWhisper = 0
891
844
  return line
892
845
  }
893
846
  }