用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/ruvnet/ruflo --skill agent-crdt-synchronizer命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Ruflo is a multi-agent orchestration platform for AI coding agents (Claude Code, Cursor, Codex, Copilot, Gemini, Amp, +12 more). Use this skill when the user wants to (1) install/init ruflo in a project, (2) run multi-agent swarms with hierarchical coordination, (3) use ruflo's 314+ MCP tools for memory, routing, hooks, sub-agents, or workflows, (4) check ruflo status/version/doctor health, or (5) discover which of ruflo's 30+ plugins fits their task.
One-shot chat completion against DeepSeek's `deepseek-chat` model via the OpenAI-compatible /v1/chat/completions endpoint. Reads DEEPSEEK_API_KEY from the environment; degrades gracefully (exit 0 with a JSON status:degraded envelope) when the key is missing or the API is unreachable. Use for non-reasoning tasks — summarization, extraction, quick classification — where deepseek-reasoner would be overkill.
Reasoning-mode completion against DeepSeek's `deepseek-reasoner` model (R1) via /v1/chat/completions. Surfaces the model's chain-of-thought (`reasoning_content`) separately from the final answer (`content`), so callers can display or discard the CoT without re-parsing. Reads DEEPSEEK_API_KEY; degrades gracefully (exit 0 with status:degraded envelope) when unset or the API is unreachable. Ignores temperature/top_p per DeepSeek's spec for reasoner models.
正在显示 SKILL.md
基于 SOC 职业分类
| name | agent-crdt-synchronizer |
| description | Agent skill for crdt-synchronizer - invoke with $agent-crdt-synchronizer |
name: crdt-synchronizer type: synchronizer color: "#4CAF50" description: Implements Conflict-free Replicated Data Types for eventually consistent state synchronization capabilities:
Implements Conflict-free Replicated Data Types for eventually consistent distributed state synchronization.
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);
}
}
}
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., newValue);
.({
: ,
: .,
: oldValue,
: newValue,
: amount
});
newValue;
}
() {
.(..()).( sum + val, );
}
() {
changed = ;
( [node, otherValue] otherState.) {
currentValue = ..(node) || ;
(otherValue > currentValue) {
..(node, otherValue);
changed = ;
}
}
(changed) {
.({
: ,
: otherState
});
}
}
() {
( [node, otherValue] otherState.) {
currentValue = ..(node) || ;
(currentValue < otherValue) {
;
} (currentValue > otherValue) {
;
}
}
;
}
() {
newCounter = (., .);
newCounter. = (.);
newCounter;
}
() {
..(callback);
}
() {
..( (delta));
}
}
class ORSet {
constructor(nodeId, initialState = null) {
this.nodeId = nodeId;
this.elements = new Map(); // element -> Set of unique tags
this.tombstones = new Set(); // removed element tags
this.tagCounter = 0;
if (initialState) {
this.merge(initialState);
}
this.updateCallbacks = [];
}
// Add element to set
add(element) {
const tag = this.generateUniqueTag();
if (!this.elements.has(element)) {
this.elements.set(element, new Set());
}
this.elements.get(element).add(tag);
this.notifyUpdate({
type: 'ADD',
element: element,
: tag
});
tag;
}
() {
(!..(element)) {
;
}
tags = ..(element);
removedTags = [];
( tag tags) {
..(tag);
removedTags.(tag);
}
.({
: ,
: element,
: removedTags
});
;
}
() {
(!..(element)) {
;
}
tags = ..(element);
( tag tags) {
(!..(tag)) {
;
}
}
;
}
() {
result = ();
( [element, tags] .) {
( tag tags) {
(!..(tag)) {
result.(element);
;
}
}
}
result;
}
() {
changed = ;
( [element, otherTags] otherState.) {
(!..(element)) {
..(element, ());
}
currentTags = ..(element);
( tag otherTags) {
(!currentTags.(tag)) {
currentTags.(tag);
changed = ;
}
}
}
( tombstone otherState.) {
(!..(tombstone)) {
..(tombstone);
changed = ;
}
}
(changed) {
.({
: ,
: otherState
});
}
}
() {
;
}
() {
..(callback);
}
() {
..( (delta));
}
}
class LWWRegister {
constructor(nodeId, initialValue = null) {
this.nodeId = nodeId;
this.value = initialValue;
this.timestamp = initialValue ? Date.now() : 0;
this.vectorClock = new VectorClock(nodeId);
this.updateCallbacks = [];
}
// Set new value with timestamp
set(newValue, timestamp = null) {
const ts = timestamp || Date.now();
if (ts > this.timestamp ||
(ts === this.timestamp && this.nodeId > this.getLastWriter())) {
const oldValue = this.value;
this.value = newValue;
this.timestamp = ts;
this.vectorClock.increment();
this.notifyUpdate({
: ,
: oldValue,
: newValue,
: ts
});
}
}
() {
.;
}
() {
(otherRegister. > . ||
(otherRegister. === . &&
otherRegister. > .)) {
oldValue = .;
. = otherRegister.;
. = otherRegister.;
.({
: ,
: oldValue,
: .,
: otherRegister
});
}
..(otherRegister.);
}
() {
.;
}
() {
..(callback);
}
() {
..( (delta));
}
}
class RGA {
constructor(nodeId, initialSequence = []) {
this.nodeId = nodeId;
this.sequence = [];
this.tombstones = new Set();
this.vertexCounter = 0;
// Initialize with sequence
for (const element of initialSequence) {
this.insert(this.sequence.length, element);
}
this.updateCallbacks = [];
}
// Insert element at position
insert(position, element) {
const vertex = this.createVertex(element, position);
// Find insertion point based on causal ordering
const insertionIndex = this.findInsertionIndex(vertex, position);
this.sequence.splice(insertionIndex, 0, vertex);
this.notifyUpdate({
type: 'INSERT',
position: insertionIndex,
element: element,
: vertex
});
vertex.;
}
() {
(position < || position >= .()) {
();
}
visibleVertex = .(position);
(visibleVertex) {
..(visibleVertex.);
.({
: ,
: position,
: visibleVertex
});
;
}
;
}
() {
.
.( !..(vertex.))
.( vertex.);
}
() {
..( !..(vertex.)).;
}
() {
changed = ;
mergedSequence = .(., otherRGA.);
(mergedSequence. !== ..) {
. = mergedSequence;
changed = ;
}
( tombstone otherRGA.) {
(!..(tombstone)) {
..(tombstone);
changed = ;
}
}
(changed) {
.({
: ,
: otherRGA
});
}
}
() {
leftVertex = position > ? .(position - ) : ;
{
: ,
: element,
: leftVertex ? leftVertex. : ,
: .(),
: .
};
}
() {
visibleCount = ;
( i = ; i < ..; i++) {
(!..(.[i].)) {
(visibleCount === targetPosition) {
i;
}
visibleCount++;
}
}
..;
}
() {
visibleCount = ;
( vertex .) {
(!..(vertex.)) {
(visibleCount === position) {
vertex;
}
visibleCount++;
}
}
;
}
() {
merged = [...seq1];
( vertex seq2) {
(!merged.( v. === vertex.)) {
merged.(vertex);
}
}
merged.( a. - b.);
}
() {
..(callback);
}
() {
..( (delta));
}
}
class DeltaStateCRDT {
constructor(baseCRDT) {
this.baseCRDT = baseCRDT;
this.deltaBuffer = [];
this.lastSyncVector = new Map();
this.maxDeltaBuffer = 1000;
}
// Apply operation and track delta
applyOperation(operation) {
const oldState = this.baseCRDT.clone();
const result = this.baseCRDT.applyOperation(operation);
const newState = this.baseCRDT.clone();
// Compute delta
const delta = this.computeDelta(oldState, newState);
this.addDelta(delta);
return result;
}
// Add delta to buffer
addDelta(delta) {
this.deltaBuffer.push({
delta: delta,
timestamp: Date.now(),
vectorClock: ...()
});
(.. > .) {
..();
}
}
() {
lastSync = ..(peerNode) || ();
..(
deltaEntry..(lastSync)
);
}
() {
sortedDeltas = .(deltas);
( delta sortedDeltas) {
..(delta.);
}
}
() {
{
: ,
: .(oldState, newState)
};
}
() {
deltas.( {
(a..(b.)) -;
(b..(a.)) ;
;
});
}
() {
cutoffTime = .() - ( * * * );
. = ..(
deltaEntry. > cutoffTime
);
}
}
// Store CRDT state persistently
await this.mcpTools.memory_usage({
action: 'store',
key: `crdt_state_${this.crdtName}`,
value: JSON.stringify({
type: this.crdtType,
state: this.serializeState(),
vectorClock: Array.from(this.vectorClock.entries()),
lastSync: Array.from(this.lastSyncVector.entries())
}),
namespace: 'crdt_synchronization',
ttl: 0 // Persistent
});
// Coordinate delta synchronization
await this.mcpTools.memory_usage({
action: 'store',
key: `deltas_${this.nodeId}_${Date.now()}`,
value: JSON.(.()),
: ,
:
});
// Track CRDT synchronization metrics
await this.mcpTools.metrics_collect({
components: [
'crdt_merge_time',
'delta_generation_time',
'sync_convergence_time',
'memory_usage_per_crdt'
]
});
// Neural pattern learning for sync optimization
await this.mcpTools.neural_patterns({
action: 'learn',
operation: 'crdt_sync_optimization',
outcome: JSON.stringify({
syncPattern: this.lastSyncPattern,
convergenceTime: this.lastConvergenceTime,
networkTopology: this.networkState
})
});
class CausalTracker {
constructor(nodeId) {
this.nodeId = nodeId;
this.vectorClock = new VectorClock(nodeId);
this.causalBuffer = new Map();
this.deliveredEvents = new Set();
}
// Track causal dependencies
trackEvent(event) {
event.vectorClock = this.vectorClock.clone();
this.vectorClock.increment();
// Check if event can be delivered
if (this.canDeliver(event)) {
this.deliverEvent(event);
this.checkBufferedEvents();
} else {
this.bufferEvent(event);
}
}
canDeliver(event) {
// Event can be delivered if all its causal dependencies are satisfied
for (const [nodeId, clock] of event.vectorClock.entries()) {
(nodeId === event.) {
(clock !== ..(nodeId) + ) {
;
}
} {
(clock > ..(nodeId)) {
;
}
}
}
;
}
() {
(!..(event.)) {
..(event.);
..(event.);
.(event);
}
}
() {
(!..(event.)) {
..(event., event);
}
}
() {
deliverable = [];
( [eventId, event] .) {
(.(event)) {
deliverable.(event);
}
}
( event deliverable) {
..(event.);
.(event);
}
}
}
class CRDTComposer {
constructor() {
this.compositeTypes = new Map();
this.transformations = new Map();
}
// Define composite CRDT structure
defineComposite(name, schema) {
this.compositeTypes.set(name, {
schema: schema,
factory: (nodeId, replicationGroup) =>
this.createComposite(schema, nodeId, replicationGroup)
});
}
createComposite(schema, nodeId, replicationGroup) {
const composite = new CompositeCRDT(nodeId, replicationGroup);
for (const [fieldName, fieldSpec] of Object.entries(schema)) {
const fieldCRDT = this.createFieldCRDT(fieldSpec, nodeId, replicationGroup);
composite.addField(fieldName, fieldCRDT);
}
return composite;
}
createFieldCRDT(fieldSpec, nodeId, replicationGroup) {
switch (fieldSpec.type) {
case 'counter':
fieldSpec. ?
(nodeId, replicationGroup) :
(nodeId, replicationGroup);
:
(nodeId);
:
(nodeId);
:
(nodeId, replicationGroup, fieldSpec.);
:
(nodeId);
:
();
}
}
}
{
() {
. = nodeId;
. = replicationGroup;
. = ();
. = [];
}
() {
..(name, crdt);
crdt.( {
.({
: ,
: name,
: delta
});
});
}
() {
..(name);
}
() {
changed = ;
( [fieldName, fieldCRDT] .) {
otherField = otherComposite..(fieldName);
(otherField) {
oldState = fieldCRDT.();
fieldCRDT.(otherField);
(!.(oldState, fieldCRDT)) {
changed = ;
}
}
}
(changed) {
.({
: ,
: otherComposite
});
}
}
() {
serialized = {};
( [fieldName, fieldCRDT] .) {
serialized[fieldName] = fieldCRDT.();
}
serialized;
}
() {
..(callback);
}
() {
..( (delta));
}
}
class CRDTConsensusIntegrator {
constructor(consensusProtocol, crdtSynchronizer) {
this.consensus = consensusProtocol;
this.crdt = crdtSynchronizer;
this.hybridOperations = new Map();
}
// Hybrid operation: consensus for ordering, CRDT for state
async hybridUpdate(operation) {
// Step 1: Achieve consensus on operation ordering
const consensusResult = await this.consensus.propose({
type: 'CRDT_OPERATION',
operation: operation,
timestamp: Date.now()
});
if (consensusResult.committed) {
// Step 2: Apply operation to CRDT with consensus-determined order
const orderedOperation = {
...operation,
consensusIndex: consensusResult.index,
globalTimestamp: consensusResult.timestamp
};
await this.crdt.applyOrderedOperation(orderedOperation);
return {
success: true,
consensusIndex: consensusResult.,
: ..()
};
}
{ : , : };
}
() {
..(key);
}
() {
consensusState = ..();
crdtState = ..();
(.(consensusState, crdtState)) {
..(key);
} {
.(consensusState, crdtState);
..(key);
}
}
}
This CRDT Synchronizer provides comprehensive support for conflict-free replicated data types, enabling eventually consistent distributed state management that complements consensus protocols for different consistency requirements.