@miphamai/cli 0.23.0 → 0.24.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/agent/agent-context.ts +20 -57
- package/src/agent/agent-experience.ts +8 -0
- package/src/agent/effectiveness-tracker.ts +149 -0
- package/src/agent/experience-rules.ts +188 -0
- package/src/agent/pattern-analyzer.ts +154 -0
- package/src/agent/sub-agent.ts +67 -0
- package/src/agent/types.ts +2 -0
- package/src/config/defaults.ts +6 -0
- package/src/core/engine.ts +70 -1
- package/src/core/rule-engine.ts +179 -0
- package/src/index.tsx +3 -1
- package/src/shared/types.ts +14 -0
- package/src/tools/agent/agent.ts +7 -1
- package/src/tools/file/edit.ts +78 -15
- package/src/ui/commands.ts +133 -0
package/src/ui/commands.ts
CHANGED
|
@@ -446,6 +446,124 @@ const skillsCmd: CommandHandler = (ctx) => {
|
|
|
446
446
|
return { content: lines.join('\n') }
|
|
447
447
|
}
|
|
448
448
|
|
|
449
|
+
// ═══════════════════════════════════════════════════════════════
|
|
450
|
+
// CRSI (Conversational Rule Self-Improvement)
|
|
451
|
+
// ═══════════════════════════════════════════════════════════════
|
|
452
|
+
|
|
453
|
+
const crsiRulesCmd: CommandHandler = (ctx) => {
|
|
454
|
+
const engine = ctx.engine.getRuleEngine()
|
|
455
|
+
if (!engine) {
|
|
456
|
+
return { content: 'CRSI rule engine is not available.' }
|
|
457
|
+
}
|
|
458
|
+
const rules = engine.getActiveRules()
|
|
459
|
+
if (rules.length === 0) {
|
|
460
|
+
return { content: 'No active CRSI rules.' }
|
|
461
|
+
}
|
|
462
|
+
const lines: string[] = ['## Active CRSI Rules', '']
|
|
463
|
+
for (const r of rules) {
|
|
464
|
+
const status = r.enabled ? '✅' : '⛔'
|
|
465
|
+
lines.push(`- \`${r.id}\` [${r.category}] ${r.toolName} — ${r.source} ${status}`)
|
|
466
|
+
}
|
|
467
|
+
lines.push('', `Total: ${rules.length} active rules`)
|
|
468
|
+
lines.push('', 'Use `/crsi disable <rule-id>` to disable a rule.')
|
|
469
|
+
return { content: lines.join('\n') }
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const crsiDisableCmd: CommandHandler = (ctx, args) => {
|
|
473
|
+
const engine = ctx.engine.getRuleEngine()
|
|
474
|
+
if (!engine) {
|
|
475
|
+
return { content: 'CRSI rule engine is not available.' }
|
|
476
|
+
}
|
|
477
|
+
const ruleId = args[0]?.trim()
|
|
478
|
+
if (!ruleId) {
|
|
479
|
+
return { content: 'Usage: /crsi disable <rule-id>' }
|
|
480
|
+
}
|
|
481
|
+
engine.setRuleEnabled(ruleId, false)
|
|
482
|
+
return {
|
|
483
|
+
content: `Rule \`${ruleId}\` has been disabled. Use \`/crsi restore ${ruleId}\` to re-enable.`,
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const crsiAnalyzeCmd: CommandHandler = async (ctx) => {
|
|
488
|
+
const analyzer = ctx.engine.getPatternAnalyzer()
|
|
489
|
+
const engine = ctx.engine.getRuleEngine()
|
|
490
|
+
if (!engine) {
|
|
491
|
+
return { content: 'CRSI system is not available.' }
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
const patterns = analyzer.analyzeAllAgents()
|
|
495
|
+
if (patterns.length === 0) {
|
|
496
|
+
return { content: 'No failure patterns found across agents.' }
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
let registered = 0
|
|
500
|
+
for (const pattern of patterns) {
|
|
501
|
+
const toolRule = analyzer.toToolRule(pattern)
|
|
502
|
+
engine.register(toolRule)
|
|
503
|
+
registered++
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
const lines: string[] = [
|
|
507
|
+
'## CRSI Analysis Complete',
|
|
508
|
+
'',
|
|
509
|
+
`Found ${patterns.length} patterns, ${registered} rules registered.`,
|
|
510
|
+
'',
|
|
511
|
+
]
|
|
512
|
+
for (const p of patterns) {
|
|
513
|
+
lines.push(
|
|
514
|
+
`- [${p.category}] \`${p.agentName}\` — ${p.frequency} failures (${p.confidence} confidence)`,
|
|
515
|
+
)
|
|
516
|
+
}
|
|
517
|
+
return { content: lines.join('\n') }
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
const crsiRestoreCmd: CommandHandler = (ctx, args) => {
|
|
521
|
+
const engine = ctx.engine.getRuleEngine()
|
|
522
|
+
if (!engine) {
|
|
523
|
+
return { content: 'CRSI rule engine is not available.' }
|
|
524
|
+
}
|
|
525
|
+
const ruleId = args.join(' ').trim()
|
|
526
|
+
if (!ruleId) {
|
|
527
|
+
return { content: 'Usage: /crsi restore <rule-id>' }
|
|
528
|
+
}
|
|
529
|
+
engine.setRuleEnabled(ruleId, true)
|
|
530
|
+
return { content: `Rule \`${ruleId}\` has been re-enabled.` }
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
const crsiStatsCmd: CommandHandler = async (ctx) => {
|
|
534
|
+
const engine = ctx.engine.getRuleEngine()
|
|
535
|
+
const tracker = ctx.engine.getEffectivenessTracker()
|
|
536
|
+
if (!engine) {
|
|
537
|
+
return { content: 'CRSI rule engine is not available.' }
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
const rules = engine.getActiveRules()
|
|
541
|
+
const lines: string[] = ['## CRSI Statistics', '']
|
|
542
|
+
lines.push(`Total active rules: ${rules.length}`)
|
|
543
|
+
lines.push(`Builtin: ${rules.filter((r) => r.source === 'builtin').length}`)
|
|
544
|
+
lines.push(`Auto-generated: ${rules.filter((r) => r.source === 'pattern-analyzer').length}`)
|
|
545
|
+
lines.push(`Manual: ${rules.filter((r) => r.source === 'manual').length}`)
|
|
546
|
+
|
|
547
|
+
if (tracker) {
|
|
548
|
+
let totalInterceptions = 0
|
|
549
|
+
let totalSuccesses = 0
|
|
550
|
+
for (const r of rules) {
|
|
551
|
+
const eff = tracker.getEffectiveness(r.id)
|
|
552
|
+
if (eff) {
|
|
553
|
+
totalInterceptions += eff.appliedCount
|
|
554
|
+
totalSuccesses += eff.successAfterCount
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
lines.push('')
|
|
558
|
+
lines.push(`Total interceptions: ${totalInterceptions}`)
|
|
559
|
+
lines.push(
|
|
560
|
+
`Success rate after rules: ${totalInterceptions > 0 ? Math.round((totalSuccesses / totalInterceptions) * 100) : 0}%`,
|
|
561
|
+
)
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
return { content: lines.join('\n') }
|
|
565
|
+
}
|
|
566
|
+
|
|
449
567
|
// ═══════════════════════════════════════════════════════════════
|
|
450
568
|
// Workflow
|
|
451
569
|
// ═══════════════════════════════════════════════════════════════
|
|
@@ -3072,6 +3190,11 @@ const commandsListCmd: CommandHandler = () => {
|
|
|
3072
3190
|
'/plugin-enable': 'Plugins',
|
|
3073
3191
|
'/plugin-disable': 'Plugins',
|
|
3074
3192
|
'/commands': 'Tools & Skills',
|
|
3193
|
+
'/crsi rules': 'Tools & Skills',
|
|
3194
|
+
'/crsi disable': 'Tools & Skills',
|
|
3195
|
+
'/crsi analyze': 'Tools & Skills',
|
|
3196
|
+
'/crsi restore': 'Tools & Skills',
|
|
3197
|
+
'/crsi stats': 'Tools & Skills',
|
|
3075
3198
|
'/plan': 'Workflow',
|
|
3076
3199
|
'/no-plan': 'Workflow',
|
|
3077
3200
|
'/tdd': 'Workflow',
|
|
@@ -3209,6 +3332,11 @@ registry.set('/remove-plugin', removePluginCmd)
|
|
|
3209
3332
|
registry.set('/plugin-enable', pluginEnableCmd)
|
|
3210
3333
|
registry.set('/plugin-disable', pluginDisableCmd)
|
|
3211
3334
|
registry.set('/commands', commandsListCmd)
|
|
3335
|
+
registry.set('/crsi rules', crsiRulesCmd)
|
|
3336
|
+
registry.set('/crsi disable', crsiDisableCmd)
|
|
3337
|
+
registry.set('/crsi analyze', crsiAnalyzeCmd)
|
|
3338
|
+
registry.set('/crsi restore', crsiRestoreCmd)
|
|
3339
|
+
registry.set('/crsi stats', crsiStatsCmd)
|
|
3212
3340
|
|
|
3213
3341
|
// Workflow
|
|
3214
3342
|
registry.set('/plan', planCmd)
|
|
@@ -3359,6 +3487,11 @@ const COMMAND_DESCRIPTIONS: Record<string, string> = {
|
|
|
3359
3487
|
'/remove-plugin': 'Remove an installed plugin',
|
|
3360
3488
|
'/plugin-enable': 'Enable a disabled plugin',
|
|
3361
3489
|
'/plugin-disable': 'Disable an enabled plugin',
|
|
3490
|
+
'/crsi rules': 'List all active CRSI rules with their status',
|
|
3491
|
+
'/crsi disable': 'Disable a CRSI rule by ID',
|
|
3492
|
+
'/crsi analyze': 'Manually trigger CRSI pattern analysis across all agents',
|
|
3493
|
+
'/crsi restore': 'Restore a disabled or degraded CRSI rule',
|
|
3494
|
+
'/crsi stats': 'Show CRSI overall effectiveness statistics',
|
|
3362
3495
|
'/plan': 'Enter plan mode',
|
|
3363
3496
|
'/no-plan': 'Exit plan mode',
|
|
3364
3497
|
'/tdd': 'Test-Driven Development workflow (RED → GREEN → REFACTOR)',
|