Module: ClaudeSwarm::SessionPath
- Defined in:
- lib/claude_swarm/session_path.rb
Class Method Summary collapse
-
.ensure_directory(session_path) ⇒ Object
Ensure the session directory exists.
-
.from_env ⇒ Object
Get the session path from environment (required).
-
.generate(working_dir: Dir.pwd, session_id: SecureRandom.uuid) ⇒ Object
Generate a full session path for a given directory and session ID.
-
.project_folder_name(working_dir = Dir.pwd) ⇒ Object
Convert a directory path to a safe folder name using + as separator.
Class Method Details
.ensure_directory(session_path) ⇒ Object
Ensure the session directory exists
28 29 30 31 32 33 34 |
# File 'lib/claude_swarm/session_path.rb', line 28 def ensure_directory(session_path) FileUtils.mkdir_p(session_path) # Add .gitignore to swarm home if it doesn't exist gitignore_path = ClaudeSwarm.joined_home_dir(".gitignore") File.write(gitignore_path, "*\n") unless File.exist?(gitignore_path) end |
.from_env ⇒ Object
Get the session path from environment (required)
37 38 39 |
# File 'lib/claude_swarm/session_path.rb', line 37 def from_env ENV["CLAUDE_SWARM_SESSION_PATH"] or raise "CLAUDE_SWARM_SESSION_PATH not set" end |
.generate(working_dir: Dir.pwd, session_id: SecureRandom.uuid) ⇒ Object
Generate a full session path for a given directory and session ID
22 23 24 25 |
# File 'lib/claude_swarm/session_path.rb', line 22 def generate(working_dir: Dir.pwd, session_id: SecureRandom.uuid) project_name = project_folder_name(working_dir) ClaudeSwarm.joined_sessions_dir(project_name, session_id) end |
.project_folder_name(working_dir = Dir.pwd) ⇒ Object
Convert a directory path to a safe folder name using + as separator
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/claude_swarm/session_path.rb', line 7 def project_folder_name(working_dir = Dir.pwd) # Don't expand path if it's already expanded (avoids double expansion on Windows) path = working_dir.start_with?("/") || working_dir.match?(/^[A-Za-z]:/) ? working_dir : File.(working_dir) # Handle Windows drive letters (C:\ → C) path = path.gsub(/^([A-Za-z]):/, '\1') # Remove leading slash/backslash path = path.sub(%r{^[/\\]}, "") # Replace all path separators with + path.gsub(%r{[/\\]}, "+") end |