feat(intelligence): complete Phase 2-3 migration to Rust

Phase 2 - Core Engines:
- Heartbeat Engine: Periodic proactive checks with quiet hours support
- Context Compactor: Token estimation and message summarization
  - CJK character handling (1.5 tokens per char)
  - Rule-based summary generation

Phase 3 - Advanced Features:
- Reflection Engine: Pattern analysis and improvement suggestions
- Agent Identity: SOUL.md/AGENTS.md/USER.md management
  - Proposal-based changes (requires user approval)
  - Snapshot history for rollback

All modules include:
- Tauri commands for frontend integration
- Unit tests
- Re-exported types via mod.rs

Reference: docs/plans/INTELLIGENCE-LAYER-MIGRATION.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
iven
2026-03-21 00:52:44 +08:00
parent 0db8a2822f
commit ef8f5cdb43
6 changed files with 2235 additions and 1 deletions

View File

@@ -0,0 +1,52 @@
//! Intelligence Layer - Migrated from frontend lib/
//!
//! This module contains the intelligence components that were previously
//! implemented in TypeScript/JavaScript in the frontend.
//!
//! ## Modules
//!
//! - `heartbeat` - Periodic proactive checks with quiet hours support
//! - `compactor` - Context compaction for infinite-length conversations
//! - `reflection` - Agent self-improvement through conversation analysis
//! - `identity` - Agent identity file management (SOUL.md, AGENTS.md, USER.md)
//!
//! ## Migration Status
//!
//! | Component | Status | Notes |
//! |-----------|--------|-------|
//! | Heartbeat Engine | ✅ Phase 2 | Complete |
//! | Context Compactor | ✅ Phase 2 | Complete |
//! | Reflection Engine | ✅ Phase 3 | Complete |
//! | Agent Identity | ✅ Phase 3 | Complete |
//! | Agent Swarm | 🚧 Phase 3 | TODO |
//! | Vector Memory | 📋 Phase 4 | Planned |
//!
//! Reference: docs/plans/INTELLIGENCE-LAYER-MIGRATION.md
pub mod heartbeat;
pub mod compactor;
pub mod reflection;
pub mod identity;
// Re-export main types for convenience
pub use heartbeat::{
HeartbeatConfig, HeartbeatEngine, HeartbeatEngineState,
HeartbeatAlert, HeartbeatResult, HeartbeatStatus,
Urgency, NotifyChannel, ProactivityLevel,
};
pub use compactor::{
CompactionConfig, ContextCompactor, CompactableMessage,
CompactionResult, CompactionCheck, CompactionUrgency,
estimate_tokens, estimate_messages_tokens,
};
pub use reflection::{
ReflectionConfig, ReflectionEngine, ReflectionEngineState,
ReflectionResult, ReflectionState, ReflectionResult as ReflectionOutput,
PatternObservation, ImprovementSuggestion, IdentityChangeProposal as ReflectionIdentityChangeProposal,
Sentiment, Priority, MemoryEntryForAnalysis,
};
pub use identity::{
AgentIdentityManager, IdentityManagerState,
IdentityFiles, IdentityChangeProposal, IdentitySnapshot,
IdentityFile, ProposalStatus,
};