@claude-flow/cli 3.32.33 → 3.32.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/helpers/helpers.manifest.json +2 -2
- package/catalog-manifest.json +4 -4
- package/dist/src/commands/agent.js +49 -1
- package/dist/src/commands/hooks.js +24 -0
- package/dist/src/commands/metaharness.js +4 -0
- package/dist/src/commands/swarm.js +61 -5
- package/dist/src/config-adapter.js +1 -0
- package/dist/src/index.js +3 -2
- package/dist/src/mcp-tools/agent-tools.js +10 -0
- package/dist/src/mcp-tools/hooks-tools.js +86 -52
- package/dist/src/mcp-tools/memory-tools.js +14 -2
- package/dist/src/mcp-tools/metaharness-tools.js +7 -0
- package/dist/src/mcp-tools/swarm-tools.d.ts +16 -0
- package/dist/src/mcp-tools/swarm-tools.js +172 -7
- package/dist/src/memory/memory-bridge.d.ts +42 -0
- package/dist/src/memory/memory-bridge.js +144 -40
- package/dist/src/memory/memory-initializer.d.ts +9 -1
- package/dist/src/memory/memory-initializer.js +95 -31
- package/dist/src/services/daemon-autostart.js +7 -4
- package/dist/src/services/flywheel-receipt.d.ts +3 -0
- package/dist/src/services/flywheel-receipt.js +1 -0
- package/dist/src/services/harness-flywheel-runtime.d.ts +6 -0
- package/dist/src/services/harness-flywheel-runtime.js +19 -19
- package/dist/src/services/harness-flywheel.d.ts +2 -0
- package/dist/src/services/harness-flywheel.js +1 -0
- package/dist/src/services/harness-project-anchor.d.ts +23 -0
- package/dist/src/services/harness-project-anchor.js +129 -0
- package/dist/src/services/learned-routing.d.ts +34 -0
- package/dist/src/services/learned-routing.js +85 -0
- package/dist/src/services/pheromone-adaptive.d.ts +71 -0
- package/dist/src/services/pheromone-adaptive.js +214 -0
- package/dist/src/services/worker-daemon.js +4 -1
- package/package.json +1 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ADR-330 — Adaptive Pheromone Swarm Consensus.
|
|
3
|
+
*
|
|
4
|
+
* This is a scheduling eligibility layer, not an agent terminator. It learns a
|
|
5
|
+
* bounded EMA signal per agent, compares agents against role-local baselines,
|
|
6
|
+
* and may suspend them from future dispatch. Coordinators and other protected
|
|
7
|
+
* roles remain eligible, quorum is never crossed, pruning per round is capped,
|
|
8
|
+
* and exploration periodically reactivates a suspended agent.
|
|
9
|
+
*/
|
|
10
|
+
export declare const APSC_SCHEMA = "ruflo.apsc-state/v1";
|
|
11
|
+
export interface ApscConfig {
|
|
12
|
+
alpha: number;
|
|
13
|
+
beta: number;
|
|
14
|
+
gamma: number;
|
|
15
|
+
emaDecay: number;
|
|
16
|
+
pruningFactor: number;
|
|
17
|
+
reactivationThreshold: number;
|
|
18
|
+
minActiveAgents: number;
|
|
19
|
+
minSamples: number;
|
|
20
|
+
maxSuspendFraction: number;
|
|
21
|
+
explorationRate: number;
|
|
22
|
+
dryRun: boolean;
|
|
23
|
+
protectedRoles: string[];
|
|
24
|
+
}
|
|
25
|
+
export interface ApscAgentState {
|
|
26
|
+
agentId: string;
|
|
27
|
+
role: string;
|
|
28
|
+
status: 'active' | 'suspended';
|
|
29
|
+
samples: number;
|
|
30
|
+
rawScore: number;
|
|
31
|
+
normalizedScore: number;
|
|
32
|
+
emaScore: number;
|
|
33
|
+
lastUpdatedAt: string;
|
|
34
|
+
lastDecision?: 'keep' | 'would-suspend' | 'suspend' | 'reactivate' | 'explore';
|
|
35
|
+
}
|
|
36
|
+
export interface ApscState {
|
|
37
|
+
schemaVersion: typeof APSC_SCHEMA;
|
|
38
|
+
config: ApscConfig;
|
|
39
|
+
round: number;
|
|
40
|
+
threshold: number;
|
|
41
|
+
roleBaselines: Record<string, number>;
|
|
42
|
+
agents: Record<string, ApscAgentState>;
|
|
43
|
+
}
|
|
44
|
+
export interface ApscSignal {
|
|
45
|
+
agentId: string;
|
|
46
|
+
role: string;
|
|
47
|
+
taskSuccess: number;
|
|
48
|
+
normalizedLatency: number;
|
|
49
|
+
consensusAlignment: number;
|
|
50
|
+
}
|
|
51
|
+
export interface ApscDecision {
|
|
52
|
+
agentId: string;
|
|
53
|
+
score: number;
|
|
54
|
+
normalizedScore: number;
|
|
55
|
+
emaScore: number;
|
|
56
|
+
threshold: number;
|
|
57
|
+
action: 'keep' | 'would-suspend' | 'suspend' | 'reactivate' | 'explore';
|
|
58
|
+
applied: boolean;
|
|
59
|
+
reason: string;
|
|
60
|
+
activeAgents: number;
|
|
61
|
+
suspendedAgents: number;
|
|
62
|
+
}
|
|
63
|
+
export declare const DEFAULT_APSC_CONFIG: ApscConfig;
|
|
64
|
+
export declare function normalizeApscConfig(input?: Partial<ApscConfig>): ApscConfig;
|
|
65
|
+
export declare function createApscState(config?: Partial<ApscConfig>): ApscState;
|
|
66
|
+
export declare function recordApscSignal(current: ApscState, signal: ApscSignal, now?: number): {
|
|
67
|
+
state: ApscState;
|
|
68
|
+
decision: ApscDecision;
|
|
69
|
+
};
|
|
70
|
+
export declare function isApscAgentEligible(state: ApscState | undefined, agentId: string): boolean;
|
|
71
|
+
//# sourceMappingURL=pheromone-adaptive.d.ts.map
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ADR-330 — Adaptive Pheromone Swarm Consensus.
|
|
3
|
+
*
|
|
4
|
+
* This is a scheduling eligibility layer, not an agent terminator. It learns a
|
|
5
|
+
* bounded EMA signal per agent, compares agents against role-local baselines,
|
|
6
|
+
* and may suspend them from future dispatch. Coordinators and other protected
|
|
7
|
+
* roles remain eligible, quorum is never crossed, pruning per round is capped,
|
|
8
|
+
* and exploration periodically reactivates a suspended agent.
|
|
9
|
+
*/
|
|
10
|
+
export const APSC_SCHEMA = 'ruflo.apsc-state/v1';
|
|
11
|
+
export const DEFAULT_APSC_CONFIG = {
|
|
12
|
+
alpha: 0.5,
|
|
13
|
+
beta: 0.2,
|
|
14
|
+
gamma: 0.3,
|
|
15
|
+
emaDecay: 0.85,
|
|
16
|
+
pruningFactor: 0.6,
|
|
17
|
+
reactivationThreshold: 0.75,
|
|
18
|
+
minActiveAgents: 3,
|
|
19
|
+
minSamples: 3,
|
|
20
|
+
maxSuspendFraction: 0.25,
|
|
21
|
+
explorationRate: 0.1,
|
|
22
|
+
dryRun: true,
|
|
23
|
+
protectedRoles: ['coordinator', 'queen', 'security-architect', 'security-auditor'],
|
|
24
|
+
};
|
|
25
|
+
const unit = (value, field) => {
|
|
26
|
+
if (!Number.isFinite(value) || value < 0 || value > 1) {
|
|
27
|
+
throw new Error(`${field} must be a finite number in [0,1]`);
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
};
|
|
31
|
+
export function normalizeApscConfig(input = {}) {
|
|
32
|
+
const alpha = unit(input.alpha ?? DEFAULT_APSC_CONFIG.alpha, 'alpha');
|
|
33
|
+
const beta = unit(input.beta ?? DEFAULT_APSC_CONFIG.beta, 'beta');
|
|
34
|
+
const gamma = unit(input.gamma ?? DEFAULT_APSC_CONFIG.gamma, 'gamma');
|
|
35
|
+
const weight = alpha + beta + gamma;
|
|
36
|
+
if (weight <= 0)
|
|
37
|
+
throw new Error('at least one APSC score weight must be positive');
|
|
38
|
+
const minActiveAgents = input.minActiveAgents ?? DEFAULT_APSC_CONFIG.minActiveAgents;
|
|
39
|
+
const minSamples = input.minSamples ?? DEFAULT_APSC_CONFIG.minSamples;
|
|
40
|
+
if (!Number.isInteger(minActiveAgents) || minActiveAgents < 1 || minActiveAgents > 50) {
|
|
41
|
+
throw new Error('minActiveAgents must be an integer in [1,50]');
|
|
42
|
+
}
|
|
43
|
+
if (!Number.isInteger(minSamples) || minSamples < 1 || minSamples > 1000) {
|
|
44
|
+
throw new Error('minSamples must be an integer in [1,1000]');
|
|
45
|
+
}
|
|
46
|
+
const protectedRoles = [...new Set((input.protectedRoles ?? DEFAULT_APSC_CONFIG.protectedRoles)
|
|
47
|
+
.map((role) => role.trim().toLowerCase())
|
|
48
|
+
.filter(Boolean))].sort();
|
|
49
|
+
return {
|
|
50
|
+
alpha: alpha / weight,
|
|
51
|
+
beta: beta / weight,
|
|
52
|
+
gamma: gamma / weight,
|
|
53
|
+
emaDecay: unit(input.emaDecay ?? DEFAULT_APSC_CONFIG.emaDecay, 'emaDecay'),
|
|
54
|
+
pruningFactor: unit(input.pruningFactor ?? DEFAULT_APSC_CONFIG.pruningFactor, 'pruningFactor'),
|
|
55
|
+
reactivationThreshold: unit(input.reactivationThreshold ?? DEFAULT_APSC_CONFIG.reactivationThreshold, 'reactivationThreshold'),
|
|
56
|
+
minActiveAgents,
|
|
57
|
+
minSamples,
|
|
58
|
+
maxSuspendFraction: unit(input.maxSuspendFraction ?? DEFAULT_APSC_CONFIG.maxSuspendFraction, 'maxSuspendFraction'),
|
|
59
|
+
explorationRate: unit(input.explorationRate ?? DEFAULT_APSC_CONFIG.explorationRate, 'explorationRate'),
|
|
60
|
+
dryRun: input.dryRun ?? DEFAULT_APSC_CONFIG.dryRun,
|
|
61
|
+
protectedRoles,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export function createApscState(config = {}) {
|
|
65
|
+
return {
|
|
66
|
+
schemaVersion: APSC_SCHEMA,
|
|
67
|
+
config: normalizeApscConfig(config),
|
|
68
|
+
round: 0,
|
|
69
|
+
threshold: 0.5,
|
|
70
|
+
roleBaselines: {},
|
|
71
|
+
agents: {},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function counts(state) {
|
|
75
|
+
const values = Object.values(state.agents);
|
|
76
|
+
return {
|
|
77
|
+
activeAgents: values.filter((agent) => agent.status === 'active').length,
|
|
78
|
+
suspendedAgents: values.filter((agent) => agent.status === 'suspended').length,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function protectedRole(state, role) {
|
|
82
|
+
return state.config.protectedRoles.includes(role.toLowerCase());
|
|
83
|
+
}
|
|
84
|
+
export function recordApscSignal(current, signal, now = Date.now()) {
|
|
85
|
+
if (!/^[A-Za-z0-9._:-]{1,160}$/.test(signal.agentId))
|
|
86
|
+
throw new Error('invalid APSC agentId');
|
|
87
|
+
if (!/^[A-Za-z0-9._:-]{1,100}$/.test(signal.role))
|
|
88
|
+
throw new Error('invalid APSC role');
|
|
89
|
+
const config = normalizeApscConfig(current.config);
|
|
90
|
+
const state = {
|
|
91
|
+
...current,
|
|
92
|
+
config,
|
|
93
|
+
round: current.round + 1,
|
|
94
|
+
roleBaselines: { ...current.roleBaselines },
|
|
95
|
+
agents: Object.fromEntries(Object.entries(current.agents).map(([id, agent]) => [id, { ...agent }])),
|
|
96
|
+
};
|
|
97
|
+
const success = unit(signal.taskSuccess, 'taskSuccess');
|
|
98
|
+
const latency = unit(signal.normalizedLatency, 'normalizedLatency');
|
|
99
|
+
const alignment = unit(signal.consensusAlignment, 'consensusAlignment');
|
|
100
|
+
const rawScore = config.alpha * success + config.beta * (1 - latency) + config.gamma * alignment;
|
|
101
|
+
const role = signal.role.toLowerCase();
|
|
102
|
+
// Compare against peers in the same role, excluding the current agent.
|
|
103
|
+
// Letting an agent update its own baseline before normalization caused a
|
|
104
|
+
// persistently weak agent to redefine "normal" downward and reactivate
|
|
105
|
+
// without any recovery.
|
|
106
|
+
const rolePeers = Object.values(state.agents)
|
|
107
|
+
.filter((item) => item.agentId !== signal.agentId && item.role === role && item.samples > 0);
|
|
108
|
+
const peerMean = rolePeers.length
|
|
109
|
+
? rolePeers.reduce((sum, item) => sum + item.rawScore, 0) / rolePeers.length
|
|
110
|
+
: undefined;
|
|
111
|
+
const priorRoleBaseline = peerMean ?? state.roleBaselines[role] ?? rawScore;
|
|
112
|
+
// A common absolute scale unfairly prunes coordinators/specialists whose
|
|
113
|
+
// observable task signal differs by role. Center each score on its role EMA.
|
|
114
|
+
const normalizedScore = Math.max(0, Math.min(1, 0.5 + rawScore - priorRoleBaseline));
|
|
115
|
+
const previous = state.agents[signal.agentId];
|
|
116
|
+
const agent = {
|
|
117
|
+
agentId: signal.agentId,
|
|
118
|
+
role,
|
|
119
|
+
status: previous?.status ?? 'active',
|
|
120
|
+
samples: (previous?.samples ?? 0) + 1,
|
|
121
|
+
rawScore,
|
|
122
|
+
normalizedScore,
|
|
123
|
+
emaScore: previous
|
|
124
|
+
? config.emaDecay * previous.emaScore + (1 - config.emaDecay) * normalizedScore
|
|
125
|
+
: normalizedScore,
|
|
126
|
+
lastUpdatedAt: new Date(now).toISOString(),
|
|
127
|
+
lastDecision: 'keep',
|
|
128
|
+
};
|
|
129
|
+
state.agents[signal.agentId] = agent;
|
|
130
|
+
const allRoleAgents = Object.values(state.agents).filter((item) => item.role === role);
|
|
131
|
+
const observedRoleMean = allRoleAgents.reduce((sum, item) => sum + item.rawScore, 0) / allRoleAgents.length;
|
|
132
|
+
state.roleBaselines[role] = config.emaDecay * priorRoleBaseline + (1 - config.emaDecay) * observedRoleMean;
|
|
133
|
+
const mature = Object.values(state.agents).filter((item) => item.samples >= config.minSamples);
|
|
134
|
+
const observedMean = mature.length
|
|
135
|
+
? mature.reduce((sum, item) => sum + item.emaScore, 0) / mature.length
|
|
136
|
+
: state.threshold;
|
|
137
|
+
state.threshold = config.emaDecay * state.threshold + (1 - config.emaDecay) * observedMean;
|
|
138
|
+
let action = 'keep';
|
|
139
|
+
let applied = false;
|
|
140
|
+
let reason = agent.samples < config.minSamples
|
|
141
|
+
? `warm-up ${agent.samples}/${config.minSamples}`
|
|
142
|
+
: 'within adaptive envelope';
|
|
143
|
+
if (agent.status === 'suspended' && agent.emaScore >= state.threshold * config.reactivationThreshold) {
|
|
144
|
+
action = 'reactivate';
|
|
145
|
+
reason = 'score recovered above reactivation threshold';
|
|
146
|
+
if (!config.dryRun) {
|
|
147
|
+
agent.status = 'active';
|
|
148
|
+
applied = true;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else if (agent.status === 'active'
|
|
152
|
+
&& agent.samples >= config.minSamples
|
|
153
|
+
&& !protectedRole(state, agent.role)
|
|
154
|
+
&& agent.emaScore < state.threshold * config.pruningFactor) {
|
|
155
|
+
const before = counts(state);
|
|
156
|
+
const maxThisRound = Math.floor(before.activeAgents * config.maxSuspendFraction);
|
|
157
|
+
const quorumCapacity = Math.max(0, before.activeAgents - config.minActiveAgents);
|
|
158
|
+
if (maxThisRound < 1 || quorumCapacity < 1) {
|
|
159
|
+
reason = 'safety floor prevents suspension';
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
action = config.dryRun ? 'would-suspend' : 'suspend';
|
|
163
|
+
reason = 'score below adaptive pruning threshold';
|
|
164
|
+
if (!config.dryRun) {
|
|
165
|
+
agent.status = 'suspended';
|
|
166
|
+
applied = true;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else if (protectedRole(state, agent.role)) {
|
|
171
|
+
reason = 'protected role remains eligible';
|
|
172
|
+
}
|
|
173
|
+
// Deterministic exploration: at a bounded cadence, reactivate the stalest
|
|
174
|
+
// suspended agent so a transient failure cannot permanently exclude it.
|
|
175
|
+
if (!config.dryRun && config.explorationRate > 0) {
|
|
176
|
+
const cadence = Math.max(1, Math.round(1 / config.explorationRate));
|
|
177
|
+
if (state.round % cadence === 0) {
|
|
178
|
+
const explorer = Object.values(state.agents)
|
|
179
|
+
.filter((item) => item.status === 'suspended')
|
|
180
|
+
.sort((a, b) => a.lastUpdatedAt.localeCompare(b.lastUpdatedAt) || a.agentId.localeCompare(b.agentId))[0];
|
|
181
|
+
if (explorer) {
|
|
182
|
+
explorer.status = 'active';
|
|
183
|
+
explorer.lastDecision = 'explore';
|
|
184
|
+
if (explorer.agentId === agent.agentId) {
|
|
185
|
+
action = 'explore';
|
|
186
|
+
applied = true;
|
|
187
|
+
reason = 'bounded exploration reactivation';
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
agent.lastDecision = action;
|
|
193
|
+
const after = counts(state);
|
|
194
|
+
return {
|
|
195
|
+
state,
|
|
196
|
+
decision: {
|
|
197
|
+
agentId: agent.agentId,
|
|
198
|
+
score: rawScore,
|
|
199
|
+
normalizedScore,
|
|
200
|
+
emaScore: agent.emaScore,
|
|
201
|
+
threshold: state.threshold,
|
|
202
|
+
action,
|
|
203
|
+
applied,
|
|
204
|
+
reason,
|
|
205
|
+
...after,
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
export function isApscAgentEligible(state, agentId) {
|
|
210
|
+
if (!state || state.config.dryRun)
|
|
211
|
+
return true;
|
|
212
|
+
return state.agents[agentId]?.status !== 'suspended';
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=pheromone-adaptive.js.map
|
|
@@ -70,7 +70,10 @@ const NO_DISTILL_ENV = 'RUFLO_DAEMON_NO_DISTILL';
|
|
|
70
70
|
// half a day; set RUFLO_DAEMON_TTL_SECS=0 (or `--ttl 0`) to opt out. Idle
|
|
71
71
|
// shutdown is opt-in (0 = disabled) since a legitimately quiet daemon is not a leak.
|
|
72
72
|
const DEFAULT_DAEMON_TTL_MS = 12 * 60 * 60 * 1000;
|
|
73
|
-
|
|
73
|
+
// #2834 — an auto-started daemon must not remain alive for the full 12h TTL
|
|
74
|
+
// after its workspace goes idle. Explicit 0 via config/env still disables the
|
|
75
|
+
// idle cap for operators who intentionally want a resident daemon.
|
|
76
|
+
const DEFAULT_DAEMON_IDLE_SHUTDOWN_MS = 30 * 60 * 1000;
|
|
74
77
|
/**
|
|
75
78
|
* Read a non-negative seconds value from an env var and return it as ms.
|
|
76
79
|
* Unlike the `parseInt(x) || default` idiom used elsewhere, an explicit `0`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@claude-flow/cli",
|
|
3
|
-
"version": "3.32.
|
|
3
|
+
"version": "3.32.35",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Ruflo CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
|
|
6
6
|
"main": "dist/src/index.js",
|