claude-flow-novice
Version:
Claude Flow Novice - Advanced orchestration platform for multi-agent AI workflows with CFN Loop architecture Includes Local RuVector Accelerator and all CFN skills for complete functionality.
144 lines (143 loc) • 4.29 kB
JavaScript
/**
* Iteration Tracker - Loop 2 and Loop 3 iteration management
* Migrated from legacy/v1 CFN Loop orchestrator inline implementation
*/ import { Logger } from '../core/logger.js';
/**
* Tracks Loop 2 and Loop 3 iterations for CFN Loop orchestration
*/ export class IterationTracker {
logger;
config;
loop2Counter = 0;
loop3Counter = 0;
constructor(config){
this.config = config;
const loggerConfig = process.env.CLAUDE_FLOW_ENV === 'test' ? {
level: 'error',
format: 'json',
destination: 'console'
} : {
level: 'info',
format: 'json',
destination: 'console'
};
this.logger = new Logger(loggerConfig, {
component: 'IterationTracker'
});
}
/**
* Initialize iteration tracker (load from memory if available)
*/ async initialize() {
this.loop2Counter = 0;
this.loop3Counter = 0;
this.logger.info('Iteration tracker initialized', {
phaseId: this.config.phaseId,
swarmId: this.config.swarmId,
limits: {
loop2: this.config.loop2Max,
loop3: this.config.loop3Max
}
});
}
/**
* Increment Loop 2 counter (consensus loop)
*/ async incrementLoop2() {
this.loop2Counter++;
const remaining = this.config.loop2Max - this.loop2Counter;
const escalate = this.loop2Counter >= this.config.loop2Max;
const status = escalate ? 'max_reached' : 'active';
this.logger.info('Loop 2 iteration incremented', {
counter: this.loop2Counter,
max: this.config.loop2Max,
remaining,
escalate,
status
});
return {
counter: this.loop2Counter,
max: this.config.loop2Max,
remaining,
escalate,
status
};
}
/**
* Increment Loop 3 counter (implementation loop)
*/ async incrementLoop3() {
this.loop3Counter++;
const remaining = this.config.loop3Max - this.loop3Counter;
const escalate = this.loop3Counter >= this.config.loop3Max;
const status = escalate ? 'max_reached' : 'active';
this.logger.info('Loop 3 iteration incremented', {
counter: this.loop3Counter,
max: this.config.loop3Max,
remaining,
escalate,
status
});
return {
counter: this.loop3Counter,
max: this.config.loop3Max,
remaining,
escalate,
status
};
}
/**
* Reset Loop 3 counter (when consensus fails and we retry)
*/ async resetLoop3(reason) {
this.logger.info('Resetting Loop 3 counter', {
previousCounter: this.loop3Counter,
reason
});
this.loop3Counter = 0;
}
/**
* Get current iteration state
*/ async getState() {
return {
counters: {
loop2: this.loop2Counter,
loop3: this.loop3Counter
},
limits: {
loop2: this.config.loop2Max,
loop3: this.config.loop3Max
}
};
}
/**
* Get statistics
*/ getStatistics() {
return {
current: {
loop2: this.loop2Counter,
loop3: this.loop3Counter
},
totals: {
loop2: this.config.loop2Max,
loop3: this.config.loop3Max
}
};
}
/**
* Check if Loop 2 has exceeded max iterations
*/ isLoop2Exhausted() {
return this.loop2Counter >= this.config.loop2Max;
}
/**
* Check if Loop 3 has exceeded max iterations
*/ isLoop3Exhausted() {
return this.loop3Counter >= this.config.loop3Max;
}
/**
* Get remaining iterations for Loop 2
*/ getRemainingLoop2() {
return Math.max(0, this.config.loop2Max - this.loop2Counter);
}
/**
* Get remaining iterations for Loop 3
*/ getRemainingLoop3() {
return Math.max(0, this.config.loop3Max - this.loop3Counter);
}
}
//# sourceMappingURL=iteration-tracker.js.map