@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
@@ -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
@@ -487,329 +489,269 @@ export class StatusVoice {
487
489
  .replaceAll('{n}', String(count));
488
490
  }
489
491
  }
490
- /** Murmur pacing: cooldown between whispers and output volume that earns one. */
492
+ /** Every whisper category key, in declaration order (voice-pack key allow-list). */
493
+ export const WHISPER_CATEGORIES = [
494
+ 'thinking', 'writing', 'reading', 'editing', 'running', 'searching',
495
+ 'git', 'delegating', 'browsing', 'generic',
496
+ ];
497
+ /** Every whisper outcome key, in declaration order (voice-pack key allow-list). */
498
+ export const WHISPER_RESULTS = ['pass', 'fail', 'done'];
499
+ /** Murmur pacing: the cooldown between category whispers. */
491
500
  export const WHISPER_COOLDOWN_MS = 9000;
492
- export const WHISPER_CHAR_BUDGET = 420;
501
+ /** Outcome whispers get their own shorter cooldown so a real moment still speaks. */
502
+ export const WHISPER_RESULT_COOLDOWN_MS = 5000;
493
503
  /** How long a whisper stays on screen (host-side expiry). */
494
504
  export const WHISPER_TTL_MS = 8000;
495
- /** Ambient inner-whisper pool (no keyword needed; earned by output volume). */
496
- export const WHISPER_GENERIC_POOL = [
497
- '哼哧哼哧,大脑转得飞快~',
498
- 'loading 99%……就差最后一步',
499
- '嗯……让我捋捋',
500
- '灵感来了,先记小本本上',
501
- '脑子在冒烟,但还能撑',
502
- '这个报错,我好像在哪见过',
503
- '专注模式 ON,请勿打扰',
504
- '思路通了,舒服了',
505
- '有点困……不行,还能肝',
506
- '让我嚼一嚼这个问题',
507
- '盘,都可以盘',
508
- '这波操作,我给自己点个赞',
509
- '别催别催,在想呢',
510
- '唔,这个细节差点漏掉',
511
- '脑子转太快,差点绕晕自己',
512
- '陪你干活,稳赚不亏',
513
- '深呼吸,马上就好',
514
- '诶,等等,好像发现了什么',
515
- '手速拉满,键盘冒火星',
516
- '摸鱼是不可能摸鱼的,就瞄一眼窗外',
517
- '今天也是稳扎稳打的一天',
518
- '把大问题拆成小饼干,一口一个',
519
- '这题有戏,我闻到了',
520
- '尾巴轻晃,心情有点小得意',
521
- '好结果是熬出来的,不慌',
522
- '啊,想岔了,重新来',
523
- '嗯嗯,思路对头,就这么干',
524
- '小本本记满了,都是干货',
525
- '打完这波,求摸摸奖励~',
526
- '这坑我记住了,下次绕道',
527
- '窗外云在飘,代码在跑,挺好',
528
- '嘘,正到关键处',
529
- '这个方案……让我再品品',
530
- '干活呢,别打扰我数数',
531
- '心里默默给你比了个耶',
532
- '思路像小鱼,逮住一条是一条',
533
- '嗯……有点东西,等我深挖',
534
- '收个尾就能喘口气了',
535
- '目标锁定,冲就完了',
536
- '嗯,这波配合不错',
537
- '困了……还能再战三回合',
538
- '思考.gif 加载中',
539
- '我本地能跑啊……哦,我就是干活的',
540
- '有点饿,小鱼干存货还够吗',
541
- '刚想通,一被打断又忘了,气',
542
- '缓冲中,请稍候',
543
- '这网速,比我思考还慢',
544
- '脑子在后台跑批',
545
- '内存不足,但热情够',
546
- '404:思路未找到,重试中',
547
- '这需求有点玄学,但能写',
548
- '诶,这 bug 还会闪现?',
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
- '妥',
576
- '得嘞',
577
- '你忙你的,我盯着呢',
578
- '放心,有我呢',
579
- '咱俩配合,无往不利',
580
- '你专注的样子,我默默记下了',
581
- ];
582
- /** Keyword-triggered whisper rules, most specific moods first. */
583
- export const WHISPER_RULES = [
584
- {
585
- keywords: ['测试通过', '测试全过', '全部通过', 'all tests pass', 'tests passed', 'test passed', '全绿'],
586
- pool: [
587
- '全绿!亮瞎我眼了',
588
- '测试全过,击掌~',
589
- '稳了稳了,这波稳得很',
590
- '绿灯一排排,看着就舒坦',
591
- '能跑!没报错!',
592
- '全绿,收工摸鱼去',
593
- '测试过了,尾巴翘上天',
594
- '漂亮,一次过',
595
- '测试过了,奖励自己一口小鱼干',
596
- '绿得发光,稳',
597
- '又双叒叕全绿',
598
- '这波测试,赢得干脆',
599
- ],
600
- },
601
- {
602
- keywords: ['错误', '失败', '报错', '异常', '崩溃', 'bug', 'error', 'failed', 'exception', 'traceback', '找不到', '不对了'],
603
- pool: [
604
- '哎呀,踩到小石子了',
605
- '翻车了……没事,扶起来继续',
606
- '错误是进步的脚印,我懂',
607
- '这报错我盯上它了',
608
- '我本地能跑啊?哦,我一直在跑',
609
- '别慌,深呼吸,先看报错',
610
- 'bug 你站住,我看见你了',
611
- '绷不住了……好,继续修',
612
- '报错这东西,见一个修一个',
613
- '又是它,老熟人了',
614
- '问题不大,就是有点问题',
615
- '先别慌,我看看到底咋回事',
616
- '这错报得,比我还委屈',
617
- '修好它,今天才不算白干',
618
- ],
619
- },
620
- {
621
- keywords: ['等等', '不对', '重新想', '再想想', '换个思路', '我搞错了', '纠正', '其实应该'],
622
- pool: [
623
- '嗯?让我再想想……',
624
- '推翻重来,也是种勇气',
625
- '发现岔路,及时掉头',
626
- '不对不对,重来重来',
627
- '自我纠错的瞬间,最帅了',
628
- '呃,刚说错了,收回',
629
- '哎,绕远了,拉回来',
630
- '回头一看,原来这么简单',
631
- '纠正完,思路清爽多了',
632
- '转弯不丢人,卡死才丢人',
633
- ],
634
- },
635
- {
636
- keywords: ['首先', '接下来', '第一步', '第二步', '计划', '步骤', 'todo', '任务拆解', '分工'],
637
- pool: [
638
- '排排坐,分果果',
639
- '计划通,执行开始',
640
- '一步一步来,不慌',
641
- '大任务切成小块块,好下口',
642
- '清单列好了,逐个击破',
643
- '谋定而后动,这节奏我熟',
644
- '先干这个,再干那个',
645
- '头绪理清了,开整',
646
- '步骤在手,心里不慌',
647
- '安排得明明白白',
648
- ],
649
- },
650
- {
651
- keywords: ['终于', '搞定', '完成了', '解决了', '成功了', '修复了', 'done', 'fixed', 'solved', '完成啦'],
652
- pool: [
653
- '太好了,又翻过一页',
654
- '搞定,收工~',
655
- '攻下一城,击掌!',
656
- '难题被拿下了,转个圈',
657
- '努力没白费,开心',
658
- '齐活,漂亮',
659
- '收工收工,今天圆满',
660
- '完成!心里踏实了',
661
- '这波,稳得一批',
662
- '任务清零,舒服',
663
- '搞定,可以伸个懒腰了',
664
- '又完成一件,成就感+1',
665
- ],
666
- },
667
- {
668
- keywords: ['谢谢', '感谢', 'thank'],
669
- pool: [
670
- '不客气呀,顺手的事',
671
- '被感谢了,心里甜甜的',
672
- '能帮上忙就好~',
673
- '你的谢意,我收进口袋啦',
674
- '这话我爱听',
675
- '客气啥,应该的',
676
- '收下这份心意,干劲+1',
677
- '你谢我,我谢你,扯平啦',
678
- ],
679
- },
680
- {
681
- keywords: ['复杂', '棘手', '困难', '难点', '坑', '头疼', 'tricky', 'complex'],
682
- pool: [
683
- '难不倒我们俩的',
684
- '越难啃的骨头越香',
685
- '硬骨头?我最喜欢了',
686
- '复杂问题拆开看,小事',
687
- '这坑我们一起填',
688
- '有点东西,但不多',
689
- '硬骨头,慢慢啃',
690
- '问题越难,赢的时候越爽',
691
- '绕是绕不过去的,正面刚',
692
- '再难的题,拆开都是小问号',
693
- ],
694
- },
695
- {
696
- keywords: ['检查', '审查', '确认一下', '核对', 'review', '仔细看看', '验证'],
697
- pool: [
698
- '火眼金睛,启动',
699
- '让我仔细瞧瞧',
700
- '细节魔鬼,一个都不放过',
701
- '认真检查的样子最迷人',
702
- '多核一遍,稳上加稳',
703
- '再看一眼,不亏',
704
- '确认键,点了才安心',
705
- '细节控上线',
706
- '查完这遍,稳了',
707
- ],
708
- },
709
- {
710
- keywords: ['搜索', '查一下', '资料', '文档', '搜一搜', '找找', '查询'],
711
- pool: [
712
- '去知识的海洋里捞一捞',
713
- '翻翻找找,线索快出来',
714
- '检索小雷达启动',
715
- '答案就藏在某个角落',
716
- '线索有点散,拼一下',
717
- '找东西,我最在行',
718
- '答案在网线那头等我',
719
- '翻箱倒柜中,稍等',
720
- ],
721
- },
722
- {
723
- keywords: ['写代码', '实现', '编码', '函数', '接口', '重构'],
724
- pool: [
725
- '指尖跳舞,代码开花',
726
- '把逻辑织成网',
727
- '一行一行,垒起小城堡',
728
- '这代码写得,我自己都佩服',
729
- '码着码着,天就亮了',
730
- '代码跑通了,比中奖还开心',
731
- '这行代码,写得有点帅',
732
- '写完再润润,讲究',
733
- ],
734
- },
735
- ];
736
- /** The built-in voice pack: the plugin's default copy, unchanged since v1. */
505
+ /** Map a tool family onto the whisper category it belongs to. */
506
+ export function whisperCategoryOf(tool) {
507
+ switch (tool) {
508
+ case 'read':
509
+ case 'grep':
510
+ case 'find':
511
+ case 'ls':
512
+ return 'reading';
513
+ case 'write':
514
+ case 'edit':
515
+ return 'editing';
516
+ case 'shell':
517
+ return 'running';
518
+ case 'webSearch':
519
+ case 'webFetch':
520
+ case 'memory':
521
+ case 'mcp':
522
+ return 'searching';
523
+ case 'git':
524
+ return 'git';
525
+ case 'subagent':
526
+ case 'todo':
527
+ return 'delegating';
528
+ case 'browser':
529
+ return 'browsing';
530
+ case 'ask':
531
+ case 'generic':
532
+ return 'generic';
533
+ }
534
+ }
535
+ /**
536
+ * Whether a tool invocation looks like a test run. The whisper engine never
537
+ * reads the model's prose (a discussion that merely mentions a keyword must
538
+ * not wake a mood); a test-outcome mood is wanted only when a test tool
539
+ * actually ran, so the projection marks the call at tool/call time and the
540
+ * pass mood fires from the paired tool/result.
541
+ */
542
+ export function looksLikeTestTool(name, argumentsText) {
543
+ const tool = name.toLowerCase();
544
+ if (/(^|[\/_.-])(test|tests|spec|vitest|jest|pytest|mocha|playwright|cypress|karma)([\/_.-]|$)/.test(tool)) {
545
+ return true;
546
+ }
547
+ if (argumentsText === undefined)
548
+ return false;
549
+ // Prefer the real command / code fields when the arguments parse; the raw
550
+ // JSON fallback still catches model-produced shapes the parser misses.
551
+ let haystack = argumentsText.toLowerCase();
552
+ try {
553
+ const parsed = JSON.parse(argumentsText);
554
+ if (typeof parsed === 'object' && parsed !== null) {
555
+ const record = parsed;
556
+ const command = record.command;
557
+ const code = record.code;
558
+ const picked = typeof command === 'string' && command !== ''
559
+ ? command
560
+ : typeof code === 'string' && code !== ''
561
+ ? code
562
+ : undefined;
563
+ if (picked !== undefined)
564
+ haystack = picked.toLowerCase();
565
+ }
566
+ }
567
+ catch {
568
+ // Keep the raw text below.
569
+ }
570
+ return /\b(pnpm|npm|yarn|npx|bun|python)\s+(run\s+)?(test|tests?)\b/.test(haystack)
571
+ || /\b(pytest|vitest|jest|mocha|cypress|playwright|go test|cargo test)\b/.test(haystack);
572
+ }
573
+ /** Category-level inner-whisper pools — the pet knows roughly what is going on. */
574
+ export const WHISPER_CATEGORY_POOLS = {
575
+ thinking: [
576
+ '先在脑子里搭个框架',
577
+ '它在心里打草稿,我垫着脚看',
578
+ '思路在一颗一颗冒泡',
579
+ '脑内开会中,都别抢话筒',
580
+ '先想清楚,再动手不迟',
581
+ '草稿纸已经画满了',
582
+ '让我听听它下一步打算',
583
+ '嗯,方案在成型了',
584
+ ],
585
+ writing: [
586
+ '落笔成文,我旁边听着',
587
+ '句子排着队往外走',
588
+ '把想法一句句摆整齐',
589
+ '它在组织语言,我打打气',
590
+ '写回复呢,不催',
591
+ '字斟句酌,快好了',
592
+ ],
593
+ reading: [
594
+ '翻资料呢,我保持安静',
595
+ '一行一行读,不跳页',
596
+ '在纸堆里找线索',
597
+ '眼珠子跟着字跑',
598
+ '边读边做记号',
599
+ '翻箱倒柜找重点',
600
+ ],
601
+ editing: [
602
+ '动手改起来了,手稳一点',
603
+ '这里补一笔,那边修一修',
604
+ '在改东西,听不到声音才怪',
605
+ '落笔小心,别有错别字',
606
+ '改写的节奏,我听得见',
607
+ '刷刷地改,一行都没跑',
608
+ ],
609
+ running: [
610
+ '跑起来了跑起来了',
611
+ '命令敲出去,等个回响',
612
+ '在跑什么呢,我踮脚看',
613
+ '输出开始冒烟了',
614
+ '它在跑活,我不吵',
615
+ '盯着输出,蹲一个结果',
616
+ '这波跑完就靠它了',
617
+ ],
618
+ searching: [
619
+ '去外面捞点信息',
620
+ '翻翻记忆库,等我一小会儿',
621
+ '顺着网线找线索',
622
+ '把老账翻出来对一对',
623
+ '情报在路上了',
624
+ '搜索引擎当跑腿',
625
+ ],
626
+ git: [
627
+ '版本在往前迈步',
628
+ '改动排队上车',
629
+ '提交历史在长个子',
630
+ '分支合并,神清气爽',
631
+ '记录都焊在时间线上',
632
+ ],
633
+ delegating: [
634
+ '派了活儿出去,等回话',
635
+ '清单列好,一件件来',
636
+ '任务拆开分了组',
637
+ '手下的伙计在远处跑着',
638
+ '分工完毕,各司其职',
639
+ ],
640
+ browsing: [
641
+ '它在看网页,我偷瞄两眼',
642
+ '页面一张张翻过去',
643
+ '网页里翻答案呢',
644
+ '这网速,我先歇会儿',
645
+ ],
646
+ generic: [
647
+ '这波活儿,我陪着',
648
+ '又开工了,我盯梢',
649
+ '它忙它的,我守着',
650
+ '不打扰,就安静待着',
651
+ '有活儿就有我',
652
+ ],
653
+ };
654
+ /** The pet's outcome reactions — woken by structured session results only. */
655
+ export const WHISPER_RESULT_POOLS = {
656
+ pass: [
657
+ '全绿!亮瞎我眼了',
658
+ '测试过了,击掌~',
659
+ '绿灯一排排,看着就舒坦',
660
+ '稳了稳了,这波稳得很',
661
+ '全绿,奖励自己一口小鱼干',
662
+ '这波测试,赢得干脆',
663
+ ],
664
+ fail: [
665
+ '哎呀,踩到小石子了',
666
+ '这报错我盯上它了',
667
+ '别慌,先看它在喊什么',
668
+ '修好它,今天才不算白干',
669
+ '又一次踩坑,老熟人了',
670
+ '问题不大,就是有点问题',
671
+ ],
672
+ done: [
673
+ '搞定,收工~',
674
+ '又翻过一页,踏实',
675
+ '努力没白费,开心',
676
+ '任务清零,舒服',
677
+ '攻下一城,转个圈',
678
+ '收工收工,今天圆满',
679
+ ],
680
+ };
681
+ /** The built-in voice pack: the plugin's default copy. */
737
682
  export const BUILTIN_VOICE_PACK = {
738
683
  status: STATUS_POOLS,
739
684
  tools: TOOL_POOLS,
740
685
  toolRemaining: TOOL_REMAINING_POOL,
741
- whispers: { generic: WHISPER_GENERIC_POOL, rules: WHISPER_RULES },
686
+ whispers: { categories: WHISPER_CATEGORY_POOLS, results: WHISPER_RESULT_POOLS },
742
687
  };
743
688
  /**
744
- * The murmur engine (碎碎念): watches the model's own output and lets the pet
745
- * whisper its inner voice. Two ways to earn a whisper:
746
- * - a keyword rule matches the fresh chunk text (themed whisper);
747
- * - enough output volume flowed by without one (ambient whisper).
748
- * A cooldown keeps whispers occasional; all picks are round-robin so tests
749
- * reproduce exact lines. The voice-pack provider (pet-center M4) swaps the
750
- * pools at draw time, so a pet switch re-voices live engines in place.
689
+ * The murmur engine (碎碎念): the pet's inner voice while sessions work.
690
+ * Category awareness: the projection feeds the current situation (thinking /
691
+ * writing / the running tool family), and the engine answers with a line from
692
+ * that category's pool so a whisper always roughly knows what is going on
693
+ * without ever quoting real content (no tool names, no paths, no model text).
694
+ * Outcome moments (test green, tool errors, turn completion) fire from the
695
+ * structured result events, never from output text, so a mood cannot mis-
696
+ * fire on a discussion that merely mentions a keyword. A cooldown keeps
697
+ * whispers occasional; all picks are round-robin so tests reproduce exact
698
+ * lines. The voice-pack provider (pet-center M4) swaps the pools at draw
699
+ * time, so a pet switch re-voices live engines in place.
751
700
  */
752
701
  export class WhisperEngine {
753
702
  pools;
754
- cooldownMs;
755
- charBudget;
756
- counters = new Map();
757
- genericCursor = 0;
703
+ categoryCooldownMs;
704
+ resultCooldownMs;
705
+ categoryCursor = new Map();
706
+ resultCursor = new Map();
758
707
  lastWhisperAt = Number.NEGATIVE_INFINITY;
759
- charsSinceWhisper = 0;
760
- constructor(pools = () => BUILTIN_VOICE_PACK, cooldownMs = WHISPER_COOLDOWN_MS, charBudget = WHISPER_CHAR_BUDGET) {
708
+ constructor(pools = () => BUILTIN_VOICE_PACK, categoryCooldownMs = WHISPER_COOLDOWN_MS, resultCooldownMs = WHISPER_RESULT_COOLDOWN_MS) {
761
709
  this.pools = pools;
762
- this.cooldownMs = cooldownMs;
763
- this.charBudget = charBudget;
710
+ this.categoryCooldownMs = categoryCooldownMs;
711
+ this.resultCooldownMs = resultCooldownMs;
764
712
  }
765
- /**
766
- * Effective keyword rules: an override replaces the built-in rules as a
767
- * whole; an explicit empty array disables keyword-triggered whispers.
768
- */
769
- rules() {
770
- const override = this.pools().whispers?.rules;
771
- return override === undefined ? WHISPER_RULES : override;
713
+ /** Effective category pool (an explicit empty override mutes the category). */
714
+ categoryPool(category) {
715
+ const override = this.pools().whispers?.categories?.[category];
716
+ return override === undefined ? WHISPER_CATEGORY_POOLS[category] : override;
772
717
  }
773
- /** Effective ambient pool (an explicit empty array mutes ambient whispers). */
774
- generic() {
775
- const override = this.pools().whispers?.generic;
776
- return override === undefined ? WHISPER_GENERIC_POOL : override;
718
+ /** Effective outcome pool (an explicit empty override mutes the outcome). */
719
+ resultPool(kind) {
720
+ const override = this.pools().whispers?.results?.[kind];
721
+ return override === undefined ? WHISPER_RESULT_POOLS[kind] : override;
777
722
  }
778
723
  /**
779
- * Feed one model-output chunk (reasoning or text). Returns the whisper to
780
- * show, or undefined when the moment stays quiet.
724
+ * Feed one situation while a session works. Returns the whisper to show,
725
+ * or undefined when the moment stays quiet (cooldown, or the category
726
+ * pool is muted).
781
727
  */
782
- feed(text, nowMs) {
783
- if (text.length === 0)
728
+ feed(category, nowMs) {
729
+ if (nowMs - this.lastWhisperAt < this.categoryCooldownMs)
784
730
  return undefined;
785
- const offCooldown = nowMs - this.lastWhisperAt >= this.cooldownMs;
786
- if (!offCooldown) {
787
- this.charsSinceWhisper += text.length;
731
+ const pool = this.categoryPool(category);
732
+ if (pool.length === 0)
788
733
  return undefined;
789
- }
790
- const haystack = text.toLowerCase();
791
- const rules = this.rules();
792
- for (let ruleIndex = 0; ruleIndex < rules.length; ruleIndex += 1) {
793
- const rule = rules[ruleIndex];
794
- if (!rule.keywords.some(keyword => haystack.includes(keyword)))
795
- continue;
796
- const index = (this.counters.get(ruleIndex) ?? 0) % rule.pool.length;
797
- this.counters.set(ruleIndex, index + 1);
798
- return this.speak(rule.pool[index], nowMs);
799
- }
800
- this.charsSinceWhisper += text.length;
801
- if (this.charsSinceWhisper < this.charBudget)
734
+ const index = (this.categoryCursor.get(category) ?? 0) % pool.length;
735
+ this.categoryCursor.set(category, index + 1);
736
+ return this.speak(pool[index], nowMs);
737
+ }
738
+ /**
739
+ * Feed one structured outcome (test green / tool failure / turn
740
+ * completion). Outcomes carry their own shorter cooldown so the emotional
741
+ * moment is heard unless another whisper just spoke.
742
+ */
743
+ result(kind, nowMs) {
744
+ if (nowMs - this.lastWhisperAt < this.resultCooldownMs)
802
745
  return undefined;
803
- const generic = this.generic();
804
- if (generic.length === 0)
746
+ const pool = this.resultPool(kind);
747
+ if (pool.length === 0)
805
748
  return undefined;
806
- const line = generic[this.genericCursor % generic.length];
807
- this.genericCursor += 1;
808
- return this.speak(line, nowMs);
749
+ const index = (this.resultCursor.get(kind) ?? 0) % pool.length;
750
+ this.resultCursor.set(kind, index + 1);
751
+ return this.speak(pool[index], nowMs);
809
752
  }
810
753
  speak(line, nowMs) {
811
754
  this.lastWhisperAt = nowMs;
812
- this.charsSinceWhisper = 0;
813
755
  return line;
814
756
  }
815
757
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PetSprite.d.ts","sourceRoot":"","sources":["../../../src/client/PetSprite.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK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