@gloablehive/cache
v2.0.2
Published
Universal cache system for GloableHive - FTS5 search, chunk indexing, 4-layer compression, AI extraction, cloud sync
Maintainers
Readme
@gloablehive/cache
Shared WeChat cache system for GlobeHive channel plugins.
Features
- 4-Layer Compression: Micro → Auto → Full → Session compaction
- AI Extraction: LLM-powered conversation summary and user profile updates
- Cloud Sync: Incremental sync to remote database
- Offline Fallback: SAAS connector with message queue retry
- Per-Account Isolation: Account-scoped cache paths
- YAML Frontmatter: Aligned with Claude Code memory system
Installation
npm install @gloablehive/cacheUsage
import { createCacheManager, type WeChatMessage } from '@gloablehive/cache';
const cache = createCacheManager({
basePath: './cache',
accounts: [
{ accountId: 'acc1', wechatId: 'wx123', nickName: 'Account 1', wechatAccountId: 'wa1', enabled: true }
]
});
await cache.init();
// Handle incoming message
await cache.onMessage({
messageId: 'msg_123',
accountId: 'acc1',
conversationType: 'friend',
conversationId: 'wx_friend',
senderId: 'wx_friend',
content: 'Hello',
messageType: 1,
timestamp: Date.now(),
isSelf: false,
direction: 'inbound'
});Architecture
src/
├── types.ts # Core type definitions
├── manager.ts # CacheManager - main orchestration
├── writer.ts # File operations (read/write cache files)
├── indexer.ts # MEMORY.md index generation
├── extractor.ts # AI summary extraction
├── compactor.ts # 4-layer compression
├── syncer.ts # Cloud sync
├── saas-connector.ts # SAAS offline fallback
└── message-queue.ts # Offline message queueFor Plugin Developers
Message Format
Transform your protocol-specific message to this format before passing to cache:
const wechatMessage: WeChatMessage = {
messageId: 'protocol-specific-id',
accountId: 'your-account-id',
conversationType: 'friend' | 'chatroom',
conversationId: 'wxid_xxx or xxx@chatroom',
senderId: 'wxid_xxx',
content: 'message content',
messageType: 1, // 1=text, 3=image, etc.
timestamp: Date.now(),
isSelf: false,
direction: 'inbound' | 'outbound'
};Then call cache.onMessage(wechatMessage) - the cache system handles all storage, indexing, and sync.
