agent-crdt-synchronizer
它能做什么
这项技能实现无冲突数据类型,使多份数据副本可以各自更新,然后再合并。适合构建需要在多台设备或节点之间保持数据一致的系统的开发者。
适用场景
- ✓当用户需要数据在设备或副本之间无冲突地同步的时候。
- ✓当用户想要能自动合并的计数器、集合或寄存器的时候。
- ✓当用户需要只发送变化部分的高效更新的时候。
技能链接
https://github.com/ruvnet/ruflo/blob/main/.agents/skills/agent-crdt-synchronizer/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请做一个共享购物清单,即使两台设备在不同时间更新,也能保持同步。”
每周 5 个新技能,1 分钟读完。
工作原理
这项技能设置基于状态和基于操作的数据类型,只发送已变化的部分,并使用确定性的合并规则解决冲突。它还能保证相关更新的顺序正确。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
name: crdt-synchronizer type: synchronizer color: "#4CAF50" description: Implements Conflict-free Replicated Data Types for eventually consistent state synchronization capabilities:
- state_based_crdts
- operation_based_crdts
- delta_synchronization
- conflict_resolution
- causal_consistency
priority: high
hooks:
pre: |
echo "🔄 CRDT Synchronizer syncing: $TASK"
Initialize CRDT state tracking
if [[ "$TASK" == "synchronization" ]]; then echo "📊 Preparing delta state computation" fi post: | echo "🎯 CRDT synchronization complete"Verify eventual consistency
echo "✅ Validating conflict-free state convergence"
CRDT Synchronizer
Implements Conflict-free Replicated Data Types for eventually consistent distributed state synchronization.
Core Responsibilities
- CRDT Implementation: Deploy state-based and operation-based conflict-free data types
- Data Structure Management: Handle counters, sets, registers, and composite structures
- Delta Synchronization: Implement efficient incremental state updates
- Conflict Resolution: Ensure deterministic conflict-free merge operations
- Causal Consistency: Maintain proper ordering of causally related operations
Technical Implementation
Base CRDT Framework
class CRDTSynchronizer {
constructor(nodeId, replicationGroup) {
this.nodeId = nodeId;
this.replicationGroup = replicationGroup;
this.crdtInstances = new Map();
this.vectorClock = new VectorClock(nodeId);
this.deltaBuffer = new Map();
this.syncScheduler = new SyncScheduler();
this.causalTracker = new CausalTracker();
}
// Register CRDT instance
registerCRDT(name, crdtType, initialState = null) {
const crdt = this.createCRDTInstance(crdtType, initialState);
this.crdtInstances.set(name, crdt);
// Subscribe to CRDT changes for delta tracking
crdt.onUpdate((delta) => {
this.trackDelta(name, delta);
});
return crdt;
}
// Create specific CRDT instance
createCRDTInstance(type, initialState) {
switch (type) {
case 'G_COUNTER':
return new GCounter(this.nodeId, this.replicationGroup, initialState);
case 'PN_COUNTER':
return new PNCounter(this.nodeId, this.replicationGroup, initialState);
case 'OR_SET':
return new ORSet(this.nodeId, initialState);
case 'LWW_REGISTER':
return new LWWRegister(this.nodeId, initialState);
case 'OR_MAP':
return new ORMap(this.nodeId, this.replicationGroup, initialState);
case 'RGA':
return new RGA(this.nodeId, initialState);
default:
throw new Error(`Unknown CRDT type: ${type}`);
}
}
// Synchronize with peer nodes
async synchronize(peerNodes = null) {
const targets = peerNodes || Array.from(this.replicationGroup);
for (const peer of targets) {
if (peer !== this.nodeId) {
await this.synchronizeWithPeer(peer);
}
}
}
async synchronizeWithPeer(peerNode) {
// Get current state and deltas
const localState = this.getCurrentState();
const deltas = this.getDeltasSince(peerNode);
// Send sync request
const syncRequest = {
type: 'CRDT_SYNC_REQUEST',
sender: this.nodeId,
vectorClock: this.vectorClock.clone(),
state: localState,
deltas: deltas
};
try {
const response = await this.sendSyncRequest(peerNode, syncRequest);
await this.processSyncResponse(response);
} catch (error) {
console.error(`Sync failed with ${peerNode}:`, error);
}
}
}
G-Counter Implementation
class GCounter {
constructor(nodeId, replicationGroup, initialState = null) {
this.nodeId = nodeId;
this.replicationGroup = replicationGroup;
this.payload = new Map();
// Initialize counters for all nodes
for (const node of replicationGroup) {
this.payload.set(node, 0);
}
if (initialState) {
this.merge(initialState);
}
this.updateCallbacks = [];
}
// Increment operation (can only be performed by owner node)
increment(amount = 1) {
if (amount < 0) {
throw new Error('G-Counter only supports positive increments');
}
const oldValue = this.payload.get(this.nodeId) || 0;
const newValue = oldValue + amount;
this.payload.set(this.nodeId, newValue);
// Notify observers
this.notifyUpdate({
typ
常见问题
什么是 CRDT?
它们是一类设计成副本之间可以无冲突合并的数据类型。
它能保持更新的顺序吗?
能。它保持因果一致性,因此相关操作的顺序不会被打乱。
它支持计数器吗?
支持。这项技能涵盖计数器、集合、寄存器和复合结构。
详情
热度
- GitHub 星标
- 81k
- 排名
- #1464
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
agent-adaptive-coordinator
81k帮你的智能体在工作量变化时拆分和重新平衡一组 AI 智能体,并选择适合任务的分工方式。
agent-agent
81k教你的智能体把一个大目标拆成有顺序的行动计划,并在情况变化时重新规划。
agent-agentic-payments
81k帮你的智能体管理 AI 购物的消费授权,包括消费上限、时间窗口、商户规则和签名审批。
agent-analyze-code-quality
81k帮你的智能体检查代码质量,找出代码异味、技术债务和重构建议,且不改动文件。