@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.
- package/package.json +1 -1
- package/src/core/auto-corrector.ts +220 -0
- package/src/core/auto-memory.ts +29 -0
- package/src/core/engine.ts +100 -1
- package/src/core/error-signature-db.ts +324 -0
- package/src/core/immune-memory-gc.ts +187 -0
- package/src/core/meta-rule-engine.ts +602 -0
- package/src/core/preflight-checker.ts +218 -0
- package/src/shared/types.ts +2 -0
- package/src/skills/fork-executor.ts +6 -2
- package/src/skills/loader.ts +37 -4
- package/src/skills/sanitizer.ts +214 -0
- package/src/tools/agent/skill.ts +6 -1
- package/src/tools/file/edit.ts +4 -0
- package/src/tools/file/read.ts +3 -0
- package/src/tools/file/write.ts +20 -3
- package/src/ui/commands.ts +268 -0
package/src/ui/commands.ts
CHANGED
|
@@ -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)',
|