6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/claude_swarm/commands/ps.rb', line 6
def execute
run_dir = ClaudeSwarm.joined_run_dir
unless Dir.exist?(run_dir)
puts "No active sessions"
return
end
sessions = Dir.glob("#{run_dir}/*").filter_map do |symlink|
process_symlink(symlink)
end
if sessions.empty?
puts "No active sessions"
return
end
any_missing_main = sessions.any? { |s| !s[:main_has_cost] }
col_session = 15
col_swarm = 25
col_cost = 12
col_uptime = 10
= "#{
"SESSION_ID".ljust(col_session)
} #{
"SWARM_NAME".ljust(col_swarm)
} #{
"TOTAL_COST".ljust(col_cost)
} #{
"UPTIME".ljust(col_uptime)
} DIRECTORY"
if any_missing_main
puts "\n⚠️ \e[3mTotal cost does not include the cost of the main instance for some sessions\e[0m\n\n"
else
puts
end
puts
puts "-" * .length
sessions.sort_by { |s| s[:start_time] }.reverse.each do |session|
cost_str = format("$%.4f", session[:cost])
cost_str += "*" unless session[:main_has_cost]
puts "#{
session[:id].ljust(col_session)
} #{
truncate(session[:name], col_swarm).ljust(col_swarm)
} #{
cost_str.ljust(col_cost)
} #{
session[:uptime].ljust(col_uptime)
} #{session[:directory]}"
end
end
|