Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

fix: update swarm-activity.json on agent spawn/stop

Hanan Basheer58c2c10e5317
diff --git a/v3/@claude-flow/cli/src/commands/agent.ts b/v3/@claude-flow/cli/src/commands/agent.ts
index d21f0ab42e..52347cf036 100644
--- a/v3/@claude-flow/cli/src/commands/agent.ts
+++ b/v3/@claude-flow/cli/src/commands/agent.ts
@@ -7,6 +7,44 @@ import type { Command, CommandContext, CommandResult } from '../types.js';
import { output } from '../output.js';
import { select, confirm, input } from '../prompt.js';
import { callMCPTool, MCPClientError } from '../mcp-client.js';
+import * as fs from 'fs';
+import * as path from 'path';
+
+/**
+ * Update swarm-activity.json metrics after agent count changes.
+ * The statusline reads this file to display the swarm agent count.
+ */
+function updateSwarmActivityMetrics(agentCountDelta: number): void {
+ try {
+ const metricsDir = path.join(process.cwd(), '.claude-flow', 'metrics');
+ const activityPath = path.join(metricsDir, 'swarm-activity.json');
+
+ let data: Record<string, unknown> = {
+ timestamp: new Date().toISOString(),
+ swarm: { active: false, agent_count: 0, coordination_active: false },
+ };
+
+ if (fs.existsSync(activityPath)) {
+ data = JSON.parse(fs.readFileSync(activityPath, 'utf-8'));
+ } else {
+ fs.mkdirSync(metricsDir, { recursive: true });
+ }
+
+ const swarm = (data.swarm as Record<string, unknown>) ?? {};
+ const currentCount = Math.max(0, (swarm.agent_count as number) || 0);
+ const newCount = Math.max(0, currentCount + agentCountDelta);
+
+ swarm.agent_count = newCount;
+ swarm.active = newCount > 0;
+ swarm.coordination_active = newCount > 0;
+ data.swarm = swarm;
+ data.timestamp = new Date().toISOString();
+
+ fs.writeFileSync(activityPath, JSON.stringify(data, null, 2));
+ } catch {
+ // Non-critical — don't fail the command if metrics update fails
+ }
+}
// Available agent types with descriptions
const AGENT_TYPES = [
@@ -147,6 +185,9 @@ const spawnCommand: Command = {
output.writeln();
output.printSuccess(`Agent ${agentName} spawned successfully`);
+ // Update swarm-activity.json so statusline reflects the new agent count
+ updateSwarmActivityMetrics(1);
+
if (ctx.flags.format === 'json') {
output.printJson(result);
}
@@ -418,6 +459,9 @@ const stopCommand: Command = {
output.printSuccess(`Agent ${agentId} stopped successfully`);
+ // Update swarm-activity.json so statusline reflects the reduced agent count
+ updateSwarmActivityMetrics(-1);
+
if (ctx.flags.format === 'json') {
output.printJson(result);
}