@miphamai/cli 0.32.7 โ†’ 0.33.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -656,6 +656,257 @@ const crsiStatsCmd: CommandHandler = async (ctx) => {
656
656
  return { content: lines.join('\n') }
657
657
  }
658
658
 
659
+ const crsiHealthCmd: CommandHandler = async (ctx) => {
660
+ const engine = ctx.engine.getRuleEngine()
661
+ const tracker = ctx.engine.getEffectivenessTracker()
662
+ const db = ctx.engine.getErrorSignatureDB?.()
663
+ const patternAnalyzer = ctx.engine.getPatternAnalyzer?.()
664
+
665
+ const lines: string[] = ['## ๐Ÿฅ CRSI ็ณป็ปŸๅฅๅบทไปช่กจ็›˜', '']
666
+
667
+ // โ”€โ”€ CRSI Section โ”€โ”€
668
+ lines.push('### ๐Ÿง  CRSI ๅญฆไน ๅญ็ณป็ปŸ', '')
669
+ if (engine) {
670
+ const rules = engine.getActiveRules()
671
+ const builtin = rules.filter((r) => r.source === 'builtin').length
672
+ const auto = rules.filter((r) => r.source === 'pattern-analyzer').length
673
+ const manual = rules.filter((r) => r.source === 'manual').length
674
+
675
+ lines.push(`| ๆŒ‡ๆ ‡ | ๅ€ผ |`)
676
+ lines.push(`|------|----|`)
677
+ lines.push(`| ๆดป่ทƒ่ง„ๅˆ™ | ${rules.length} (ๅ†…็ฝฎ ${builtin} ยท ่‡ชๅŠจ ${auto} ยท ๆ‰‹ๅŠจ ${manual}) |`)
678
+
679
+ if (tracker) {
680
+ let interceptions = 0
681
+ let successes = 0
682
+ for (const r of rules) {
683
+ const eff = tracker.getEffectiveness(r.id)
684
+ if (eff) {
685
+ interceptions += eff.appliedCount
686
+ successes += eff.successAfterCount
687
+ }
688
+ }
689
+ const crsiRate = interceptions > 0 ? Math.round((successes / interceptions) * 100) : 100
690
+ lines.push(`| ๆ€ปๆ‹ฆๆˆชๆฌกๆ•ฐ | ${interceptions} |`)
691
+ lines.push(`| ๆ‹ฆๆˆชๆˆๅŠŸ็އ | ${crsiRate}% |`)
692
+ }
693
+
694
+ // Pattern analysis depth
695
+ if (patternAnalyzer) {
696
+ const patterns = patternAnalyzer.analyzeAllAgents()
697
+ lines.push(`| ๅทฒๆฃ€ๆต‹ๆจกๅผ | ${patterns.length} |`)
698
+ }
699
+
700
+ lines.push('')
701
+ lines.push('CRSI ๅ‘ฝไปค: `/crsi rules` `/crsi stats` `/crsi analyze`')
702
+ } else {
703
+ lines.push('CRSI ่ง„ๅˆ™ๅผ•ๆ“Žๆœชๅˆๅง‹ๅŒ–')
704
+ }
705
+
706
+ // โ”€โ”€ SIS Section โ”€โ”€
707
+ lines.push('', '### ๐Ÿ›ก๏ธ SIS ่‡ชๅ…็–ซๅญ็ณป็ปŸ', '')
708
+ if (db) {
709
+ const stats = db.getStats()
710
+ const healthEmoji =
711
+ stats.avgSuccessRate >= 0.8 ? '๐ŸŸข' : stats.avgSuccessRate >= 0.5 ? '๐ŸŸก' : '๐Ÿ”ด'
712
+
713
+ lines.push(`| ๆŒ‡ๆ ‡ | ๅ€ผ |`)
714
+ lines.push(`|------|----|`)
715
+ lines.push(
716
+ `| ๅ…็–ซ่ฎฐๅฟ† | ${stats.total} ๆก (๐ŸŸข${stats.active} ยท ๐ŸŸก${stats.degraded} ยท โšซ${stats.retired}) |`,
717
+ )
718
+ lines.push(`| ๅนณๅ‡ๆˆๅŠŸ็އ | ${Math.round(stats.avgSuccessRate * 100)}% |`)
719
+ lines.push(`| ๆ€ปๆ‹ฆๆˆช | ${stats.totalInterceptions} ๆฌก |`)
720
+
721
+ lines.push('')
722
+ lines.push('SIS ๅ‘ฝไปค: `/sis errors` `/sis stats` `/sis clear <id>`')
723
+ } else {
724
+ lines.push('SIS ่‡ชๅ…็–ซ็ณป็ปŸๆœชๅˆๅง‹ๅŒ–')
725
+ }
726
+
727
+ // โ”€โ”€ Overall Health Score โ”€โ”€
728
+ lines.push('', '### ๐Ÿ“Š ็ปผๅˆๅฅๅบท่ฏ„ๅˆ†', '')
729
+ const crsiScore = engine ? 50 : 0
730
+ const sisScore = db ? (db.getStats().avgSuccessRate >= 0.8 ? 50 : 25) : 0
731
+ const totalScore = crsiScore + sisScore
732
+
733
+ const grade =
734
+ totalScore >= 80
735
+ ? '๐ŸŸข A โ€” ไผ˜็ง€'
736
+ : totalScore >= 50
737
+ ? '๐ŸŸก B โ€” ่‰ฏๅฅฝ'
738
+ : totalScore >= 25
739
+ ? '๐ŸŸ  C โ€” ้œ€ๅ…ณๆณจ'
740
+ : '๐Ÿ”ด D โ€” ๅพ…ๅˆๅง‹ๅŒ–'
741
+
742
+ lines.push(`| ๅญ็ณป็ปŸ | ็Šถๆ€ | ๅพ—ๅˆ† |`)
743
+ lines.push(`|--------|------|------|`)
744
+ lines.push(`| CRSI ๅญฆไน  | ${engine ? 'โœ… ๅœจ็บฟ' : 'โŒ ็ฆป็บฟ'} | ${crsiScore}/50 |`)
745
+ lines.push(`| SIS ๅ…็–ซ | ${db ? 'โœ… ๅœจ็บฟ' : 'โŒ ็ฆป็บฟ'} | ${sisScore}/50 |`)
746
+ lines.push(`| **็ปผๅˆ** | **${grade}** | **${totalScore}/100** |`)
747
+
748
+ return { content: lines.join('\n') }
749
+ }
750
+
751
+ const crsiMetaCmd: CommandHandler = async (ctx) => {
752
+ const metaEngine = ctx.engine.getMetaRuleEngine?.()
753
+ if (!metaEngine) {
754
+ return { content: 'MetaRuleEngine ๆœชๅˆๅง‹ๅŒ–ใ€‚่ฏทๅ…ˆ่ฟ่กŒ `/crsi health` ๅˆๅง‹ๅŒ– CRSI ็ณป็ปŸใ€‚' }
755
+ }
756
+
757
+ const result = metaEngine.analyze()
758
+ const lines: string[] = ['## ๐Ÿ”ฎ CRSI ๅ…ƒ่ง„ๅˆ™ๅˆ†ๆž (RSI Level 3)', '']
759
+
760
+ // โ”€โ”€ System Health โ”€โ”€
761
+ lines.push('### ๐Ÿ“Š ็ณป็ปŸๅฅๅบท่ฏ„ๅˆ†', '')
762
+ const h = result.systemHealth
763
+ lines.push(`| ็ป„ไปถ | ๅพ—ๅˆ† |`)
764
+ lines.push(`|------|------|`)
765
+ lines.push(`| ้”™่ฏฏ็ญพๅ | ${h.components.errorSignatures}/100 |`)
766
+ lines.push(`| ้ข„้˜ฒๆ‹ฆๆˆช | ${h.components.preflightPrevention}/100 |`)
767
+ lines.push(`| ่‡ชๅŠจไฟฎๅค | ${h.components.autoCorrection}/100 |`)
768
+ lines.push(`| ๅ…็–ซ่ฎฐๅฟ† | ${h.components.immuneMemory}/100 |`)
769
+ lines.push(`| ่ง„ๅˆ™ๆœ‰ๆ•ˆๆ€ง | ${h.components.ruleEffectiveness}/100 |`)
770
+ lines.push(`| **็ปผๅˆ** | **${h.score}/100** |`)
771
+ lines.push('')
772
+ lines.push(h.assessment)
773
+ lines.push('')
774
+
775
+ // โ”€โ”€ Recommendations โ”€โ”€
776
+ lines.push('### ๐Ÿ’ก ไผ˜ๅŒ–ๅปบ่ฎฎ', '')
777
+ for (const rec of h.recommendations) {
778
+ lines.push(`- ${rec}`)
779
+ }
780
+ lines.push('')
781
+
782
+ // โ”€โ”€ Meta-Rules โ”€โ”€
783
+ if (result.metaRules.length > 0) {
784
+ lines.push(`### ๐Ÿงฌ ๅ‘็Žฐ ${result.metaRules.length} ๆกๅ…ƒ่ง„ๅˆ™`, '')
785
+
786
+ for (const mr of result.metaRules) {
787
+ const confIcon = mr.confidence === 'high' ? '๐Ÿ”ด' : mr.confidence === 'medium' ? '๐ŸŸก' : '๐ŸŸข'
788
+ const autoLabel = mr.autoApplicable ? ' [ๅฏ่‡ชๅŠจๅบ”็”จ]' : ''
789
+ lines.push(`#### ${confIcon} ${mr.title}${autoLabel}`)
790
+ lines.push('')
791
+ lines.push(mr.description)
792
+ lines.push('')
793
+ lines.push(`> **ๅปบ่ฎฎ**: ${mr.recommendation}`)
794
+ lines.push('')
795
+ lines.push(
796
+ `็ฝฎไฟกๅบฆ: ${mr.confidence} | ๆ ทๆœฌ้‡: ${mr.evidence.sampleSize} | ็”Ÿๆˆๆ—ถ้—ด: ${mr.generatedAt}`,
797
+ )
798
+ lines.push('')
799
+ }
800
+ } else {
801
+ lines.push('### ๐Ÿงฌ ๅ…ƒ่ง„ๅˆ™', '')
802
+ lines.push(
803
+ 'ๆš‚ๆ— ๅ…ƒ่ง„ๅˆ™็”Ÿๆˆใ€‚ๅฝ“็ณป็ปŸ็งฏ็ดฏ่ถณๅคŸ็š„้”™่ฏฏ็ญพๅๅ’Œ่ง„ๅˆ™ๆ•ฐๆฎๅŽ๏ผŒๅ…ƒ่ง„ๅˆ™ๅผ•ๆ“Žๅฐ†่‡ชๅŠจๅ‘็Žฐ่ทจ่ง„ๅˆ™ๆจกๅผใ€‚',
804
+ )
805
+ lines.push('')
806
+ }
807
+
808
+ // โ”€โ”€ Auto-applicable summary โ”€โ”€
809
+ const autoApplicable = metaEngine.getAutoApplicable(result.metaRules)
810
+ if (autoApplicable.length > 0) {
811
+ lines.push('### โšก ๅฏ่‡ชๅŠจๅบ”็”จ', '')
812
+ lines.push(`${autoApplicable.length} ๆกๅ…ƒ่ง„ๅˆ™ๅฏๅฎ‰ๅ…จ่‡ชๅŠจๅบ”็”จ๏ผš`)
813
+ for (const mr of autoApplicable) {
814
+ lines.push(`- \`${mr.id}\`: ${mr.recommendation}`)
815
+ }
816
+ lines.push('')
817
+ lines.push('ไฝฟ็”จ `/crsi meta --apply` ่‡ชๅŠจๅบ”็”จ้ซ˜็ฝฎไฟกๅบฆๅ…ƒ่ง„ๅˆ™ใ€‚')
818
+ }
819
+
820
+ return { content: lines.join('\n') }
821
+ }
822
+
823
+ // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
824
+ // SIS (Self-Immune System)
825
+ // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
826
+
827
+ const sisErrorsCmd: CommandHandler = (ctx) => {
828
+ const db = ctx.engine.getErrorSignatureDB?.()
829
+ if (!db) {
830
+ return { content: 'SIS ่‡ชๅ…็–ซ็ณป็ปŸๆœชๅˆๅง‹ๅŒ–ใ€‚' }
831
+ }
832
+ const sigs = db.getActive()
833
+ if (sigs.length === 0) {
834
+ return { content: '๐Ÿ›ก๏ธ SIS ๅ…็–ซ่ฎฐๅฟ†ไธบ็ฉบ โ€” ๅฐšๆœช่ฎฐๅฝ•ไปปไฝ•้”™่ฏฏ็ญพๅใ€‚' }
835
+ }
836
+ const lines: string[] = ['## ๐Ÿ›ก๏ธ SIS ๅ…็–ซ่ฎฐๅฟ†', '']
837
+ for (const sig of sigs) {
838
+ const statusIcon = sig.status === 'active' ? '๐ŸŸข' : '๐ŸŸก'
839
+ lines.push(`- ${statusIcon} \`${sig.id}\` [${sig.category}] ${sig.toolName}`)
840
+ lines.push(` ๆจกๅผ: \`${sig.pattern.slice(0, 80)}${sig.pattern.length > 80 ? '...' : ''}\``)
841
+ lines.push(
842
+ ` ไฟฎๅค: ${sig.fixStrategy} โ†’ ${sig.fixAction.slice(0, 60)} | ๅ‘็”Ÿ ${sig.occurrences} ๆฌก | ๆˆๅŠŸ็އ ${Math.round(sig.successRate * 100)}%`,
843
+ )
844
+ lines.push('')
845
+ }
846
+ lines.push(`ๅ…ฑ ${sigs.length} ๆกๆดป่ทƒๅ…็–ซ่ฎฐๅฟ†`)
847
+ lines.push('', 'ไฝฟ็”จ `/sis stats` ๆŸฅ็œ‹ๆฑ‡ๆ€ป็ปŸ่ฎก๏ผŒ`/sis clear <id>` ๆธ…้™คๆŒ‡ๅฎš็ญพๅ')
848
+ return { content: lines.join('\n') }
849
+ }
850
+
851
+ const sisStatsCmd: CommandHandler = (ctx) => {
852
+ const db = ctx.engine.getErrorSignatureDB?.()
853
+ if (!db) {
854
+ return { content: 'SIS ่‡ชๅ…็–ซ็ณป็ปŸๆœชๅˆๅง‹ๅŒ–ใ€‚' }
855
+ }
856
+ const stats = db.getStats()
857
+ const lines: string[] = ['## ๐Ÿ›ก๏ธ SIS ่‡ชๅ…็–ซ็ปŸ่ฎก', '']
858
+ lines.push(`ๆ€ป็ญพๅๆ•ฐ: ${stats.total}`)
859
+ lines.push(
860
+ `๐ŸŸข ๆดป่ทƒ: ${stats.active} | ๐ŸŸก ้™็บง: ${stats.degraded} | โšซ ๅทฒ้€€ๅฝน: ${stats.retired}`,
861
+ )
862
+ lines.push(`ๅนณๅ‡ๆˆๅŠŸ็އ: ${Math.round(stats.avgSuccessRate * 100)}%`)
863
+ lines.push(`ๆ€ปๆ‹ฆๆˆชๆฌกๆ•ฐ: ${stats.totalInterceptions}`)
864
+ return { content: lines.join('\n') }
865
+ }
866
+
867
+ const sisClearCmd: CommandHandler = (ctx, args) => {
868
+ const db = ctx.engine.getErrorSignatureDB?.()
869
+ if (!db) {
870
+ return { content: 'SIS ่‡ชๅ…็–ซ็ณป็ปŸๆœชๅˆๅง‹ๅŒ–ใ€‚' }
871
+ }
872
+ const sigId = args[0]?.trim()
873
+ if (!sigId) {
874
+ return { content: 'Usage: /sis clear <signature-id>\n\nไฝฟ็”จ `/sis errors` ๆŸฅ็œ‹ๆ‰€ๆœ‰็ญพๅ IDใ€‚' }
875
+ }
876
+ const sig = db.get(sigId)
877
+ if (!sig) {
878
+ return { content: `็ญพๅ \`${sigId}\` ๆœชๆ‰พๅˆฐใ€‚` }
879
+ }
880
+ db.retire(sigId)
881
+ return { content: `ๅทฒ้€€ๅฝน็ญพๅ \`${sigId}\` (${sig.pattern.slice(0, 50)}...)` }
882
+ }
883
+
884
+ const sisCleanupCmd: CommandHandler = async (ctx) => {
885
+ const db = ctx.engine.getErrorSignatureDB?.()
886
+ if (!db) {
887
+ return { content: 'SIS ่‡ชๅ…็–ซ็ณป็ปŸๆœชๅˆๅง‹ๅŒ–ใ€‚' }
888
+ }
889
+ // Use dynamic import for ESM compatibility
890
+ const { ImmuneMemoryGC } = await import('../../src/core/immune-memory-gc.js')
891
+ const gc = new ImmuneMemoryGC(db)
892
+ const report = gc.collect()
893
+ const lines: string[] = ['## ๐Ÿงน SIS ๅ…็–ซ่ฎฐๅฟ†ๆธ…็†ๅฎŒๆˆ', '']
894
+ lines.push(`ๆธ…็†ๅ‰: ${report.before} ๆก็ญพๅ`)
895
+ lines.push(`ๆธ…็†ๅŽ: ${report.after} ๆก็ญพๅ`)
896
+ lines.push('')
897
+ if (report.retiredRemoved > 0) lines.push(`๐Ÿ—‘๏ธ ็งป้™ค่ฟ‡ๆœŸ้€€ๅฝน: ${report.retiredRemoved} ๆก`)
898
+ if (report.zeroSuccessRetired > 0) lines.push(`โš ๏ธ ้€€ๅฝน้›ถๆˆๅŠŸ็އ: ${report.zeroSuccessRetired} ๆก`)
899
+ if (report.duplicatesMerged > 0) lines.push(`๐Ÿ”— ๅˆๅนถ้‡ๅค็ญพๅ: ${report.duplicatesMerged} ๆก`)
900
+ if (
901
+ report.retiredRemoved === 0 &&
902
+ report.zeroSuccessRetired === 0 &&
903
+ report.duplicatesMerged === 0
904
+ ) {
905
+ lines.push('โœ… ๅ…็–ซ่ฎฐๅฟ†ๅนฒๅ‡€๏ผŒๆ— ้œ€ๆธ…็†')
906
+ }
907
+ return { content: lines.join('\n') }
908
+ }
909
+
659
910
  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
660
911
  // Workflow
661
912
  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
@@ -3288,6 +3539,11 @@ const commandsListCmd: CommandHandler = () => {
3288
3539
  '/crsi analyze': 'Tools & Skills',
3289
3540
  '/crsi restore': 'Tools & Skills',
3290
3541
  '/crsi stats': 'Tools & Skills',
3542
+ '/crsi health': 'Tools & Skills',
3543
+ '/crsi meta': 'Tools & Skills',
3544
+ '/sis errors': 'Tools & Skills',
3545
+ '/sis stats': 'Tools & Skills',
3546
+ '/sis clear': 'Tools & Skills',
3291
3547
  '/plan': 'Workflow',
3292
3548
  '/no-plan': 'Workflow',
3293
3549
  '/tdd': 'Workflow',
@@ -3432,6 +3688,12 @@ registry.set('/crsi disable', crsiDisableCmd)
3432
3688
  registry.set('/crsi analyze', crsiAnalyzeCmd)
3433
3689
  registry.set('/crsi restore', crsiRestoreCmd)
3434
3690
  registry.set('/crsi stats', crsiStatsCmd)
3691
+ registry.set('/crsi health', crsiHealthCmd)
3692
+ registry.set('/crsi meta', crsiMetaCmd)
3693
+ registry.set('/sis errors', sisErrorsCmd)
3694
+ registry.set('/sis stats', sisStatsCmd)
3695
+ registry.set('/sis clear', sisClearCmd)
3696
+ registry.set('/sis cleanup', sisCleanupCmd)
3435
3697
 
3436
3698
  // Workflow
3437
3699
  registry.set('/plan', planCmd)
@@ -3588,6 +3850,12 @@ const COMMAND_DESCRIPTIONS: Record<string, string> = {
3588
3850
  '/crsi analyze': 'Manually trigger CRSI pattern analysis across all agents',
3589
3851
  '/crsi restore': 'Restore a disabled or degraded CRSI rule',
3590
3852
  '/crsi stats': 'Show CRSI overall effectiveness statistics',
3853
+ '/crsi health': 'CRSI + SIS unified health dashboard with scoring',
3854
+ '/crsi meta': 'RSI Level 3 meta-rule analysis โ€” rules that improve the rules',
3855
+ '/sis errors': 'List all active SIS immune memory signatures',
3856
+ '/sis stats': 'Show SIS self-immune system aggregate statistics',
3857
+ '/sis clear': 'Retire an immune memory signature by ID',
3858
+ '/sis cleanup': 'Run immune memory garbage collection (dedup + cleanup)',
3591
3859
  '/plan': 'Enter plan mode',
3592
3860
  '/no-plan': 'Exit plan mode',
3593
3861
  '/tdd': 'Test-Driven Development workflow (RED โ†’ GREEN โ†’ REFACTOR)',