agentic-flow 2.0.1-alpha.58 → 2.0.1-alpha.59

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.
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Agentic Flow Statusline for Claude Code
3
+ * Shows model, tokens, cost, swarm status, and memory usage
4
+ */
5
+
6
+ import { execSync } from 'child_process';
7
+
8
+ // Cache for expensive operations
9
+ let lastSwarmCheck = 0;
10
+ let cachedSwarmStatus = null;
11
+ const CACHE_TTL = 5000; // 5 seconds
12
+
13
+ /**
14
+ * Get swarm status (cached)
15
+ */
16
+ function getSwarmStatus() {
17
+ const now = Date.now();
18
+ if (cachedSwarmStatus && (now - lastSwarmCheck) < CACHE_TTL) {
19
+ return cachedSwarmStatus;
20
+ }
21
+
22
+ try {
23
+ const result = execSync('npx agentic-flow@alpha mcp status 2>/dev/null || echo "idle"', {
24
+ encoding: 'utf-8',
25
+ timeout: 2000
26
+ }).trim();
27
+
28
+ cachedSwarmStatus = result.includes('running') ? '🐝' : '⚡';
29
+ lastSwarmCheck = now;
30
+ return cachedSwarmStatus;
31
+ } catch {
32
+ cachedSwarmStatus = '⚡';
33
+ lastSwarmCheck = now;
34
+ return cachedSwarmStatus;
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Format token count
40
+ */
41
+ function formatTokens(tokens) {
42
+ if (tokens >= 1000000) {
43
+ return `${(tokens / 1000000).toFixed(1)}M`;
44
+ }
45
+ if (tokens >= 1000) {
46
+ return `${(tokens / 1000).toFixed(1)}K`;
47
+ }
48
+ return String(tokens);
49
+ }
50
+
51
+ /**
52
+ * Format cost
53
+ */
54
+ function formatCost(cost) {
55
+ if (cost >= 1) {
56
+ return `$${cost.toFixed(2)}`;
57
+ }
58
+ return `$${cost.toFixed(4)}`;
59
+ }
60
+
61
+ /**
62
+ * Main statusline export
63
+ */
64
+ export default function statusline(context) {
65
+ const parts = [];
66
+
67
+ // Agentic Flow indicator
68
+ parts.push('🤖');
69
+
70
+ // Model name (shortened)
71
+ if (context.model) {
72
+ const model = context.model
73
+ .replace('claude-', '')
74
+ .replace('-20250514', '')
75
+ .replace('sonnet-4', 'S4')
76
+ .replace('opus-4', 'O4')
77
+ .replace('haiku-3.5', 'H3.5');
78
+ parts.push(model);
79
+ }
80
+
81
+ // Token usage
82
+ if (context.inputTokens !== undefined || context.outputTokens !== undefined) {
83
+ const input = formatTokens(context.inputTokens || 0);
84
+ const output = formatTokens(context.outputTokens || 0);
85
+ parts.push(`↑${input} ↓${output}`);
86
+ }
87
+
88
+ // Cost
89
+ if (context.totalCost !== undefined && context.totalCost > 0) {
90
+ parts.push(formatCost(context.totalCost));
91
+ }
92
+
93
+ // Swarm/MCP status indicator
94
+ parts.push(getSwarmStatus());
95
+
96
+ // Session time
97
+ if (context.sessionStartTime) {
98
+ const elapsed = Math.floor((Date.now() - context.sessionStartTime) / 1000);
99
+ const mins = Math.floor(elapsed / 60);
100
+ const secs = elapsed % 60;
101
+ if (mins > 0) {
102
+ parts.push(`${mins}m${secs}s`);
103
+ } else {
104
+ parts.push(`${secs}s`);
105
+ }
106
+ }
107
+
108
+ return parts.join(' │ ');
109
+ }