@linxin666/dsh-pet 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.i18n.yaml +2 -2
- package/README.md +13 -10
- package/README.zh.md +13 -10
- package/contracts/voice-pack-v1.schema.json +23 -28
- package/lib/client.js +23 -15
- package/lib/client.js.map +1 -1
- package/lib/index.js +344 -461
- package/lib/types/chatter.d.ts +68 -46
- package/lib/types/chatter.d.ts.map +1 -1
- package/lib/types/chatter.js +243 -301
- package/lib/types/client/PetSprite.d.ts.map +1 -1
- package/lib/types/client/PetSprite.js +16 -17
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/index.js +26 -9
- package/lib/types/event-projection.d.ts +9 -4
- package/lib/types/event-projection.d.ts.map +1 -1
- package/lib/types/event-projection.js +46 -14
- package/lib/types/routes.d.ts.map +1 -1
- package/lib/types/routes.js +8 -3
- package/lib/types/service.d.ts +7 -11
- package/lib/types/service.d.ts.map +1 -1
- package/lib/types/service.js +27 -19
- package/lib/types/voice-pack.d.ts +6 -7
- package/lib/types/voice-pack.d.ts.map +1 -1
- package/lib/types/voice-pack.js +44 -47
- package/package.json +1 -1
- package/src/chatter.test.ts +68 -38
- package/src/chatter.ts +269 -316
- package/src/client/PetSprite.test.tsx +32 -15
- package/src/client/PetSprite.tsx +21 -24
- package/src/client/index.test.tsx +10 -1
- package/src/client/index.ts +29 -10
- package/src/event-projection.ts +57 -16
- package/src/routes.ts +9 -4
- package/src/service.ts +32 -29
- package/src/voice-pack.test.ts +48 -25
- package/src/voice-pack.ts +50 -47
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
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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
|
-
/**
|
|
519
|
-
export
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
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
|
-
/**
|
|
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
|
-
|
|
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
|
-
/**
|
|
533
|
-
export
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
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
|
-
/**
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
'
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
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.
|
|
787
|
-
*
|
|
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
|
|
751
|
+
/** Murmur pools; each key replaces the built-in pool as a whole. */
|
|
797
752
|
whispers?: {
|
|
798
|
-
/**
|
|
799
|
-
|
|
800
|
-
/**
|
|
801
|
-
|
|
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
|
|
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: {
|
|
768
|
+
whispers: { categories: WHISPER_CATEGORY_POOLS, results: WHISPER_RESULT_POOLS },
|
|
814
769
|
}
|
|
815
770
|
|
|
816
771
|
/**
|
|
817
|
-
* The murmur engine (碎碎念):
|
|
818
|
-
*
|
|
819
|
-
*
|
|
820
|
-
*
|
|
821
|
-
*
|
|
822
|
-
*
|
|
823
|
-
*
|
|
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
|
|
828
|
-
private readonly
|
|
829
|
-
private readonly
|
|
830
|
-
private
|
|
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
|
-
|
|
837
|
-
|
|
794
|
+
categoryCooldownMs: number = WHISPER_COOLDOWN_MS,
|
|
795
|
+
resultCooldownMs: number = WHISPER_RESULT_COOLDOWN_MS,
|
|
838
796
|
) {
|
|
839
797
|
this.pools = pools
|
|
840
|
-
this.
|
|
841
|
-
this.
|
|
798
|
+
this.categoryCooldownMs = categoryCooldownMs
|
|
799
|
+
this.resultCooldownMs = resultCooldownMs
|
|
842
800
|
}
|
|
843
801
|
|
|
844
|
-
/**
|
|
845
|
-
|
|
846
|
-
|
|
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
|
|
854
|
-
private
|
|
855
|
-
const override = this.pools().whispers?.
|
|
856
|
-
return override === undefined ?
|
|
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
|
|
861
|
-
*
|
|
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(
|
|
864
|
-
if (
|
|
865
|
-
const
|
|
866
|
-
if (
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
if (
|
|
881
|
-
const
|
|
882
|
-
|
|
883
|
-
|
|
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
|
}
|