openclaw/apps/macos/Sources/Clawdbot/ClawdbotPaths.swift

39 lines
1.2 KiB
Swift
Raw Permalink Normal View History

import Foundation
2026-01-04 14:32:47 +00:00
enum ClawdbotEnv {
static func path(_ key: String) -> String? {
2026-01-01 09:30:12 +01:00
// Normalize env overrides once so UI + file IO stay consistent.
guard let raw = getenv(key) else { return nil }
let value = String(cString: raw).trimmingCharacters(in: .whitespacesAndNewlines)
guard !value.isEmpty
else {
return nil
}
return value
}
}
2026-01-04 14:32:47 +00:00
enum ClawdbotPaths {
private static let configPathEnv = "CLAWDBOT_CONFIG_PATH"
private static let stateDirEnv = "CLAWDBOT_STATE_DIR"
static var stateDirURL: URL {
2026-01-04 14:32:47 +00:00
if let override = ClawdbotEnv.path(self.stateDirEnv) {
return URL(fileURLWithPath: override, isDirectory: true)
}
return FileManager.default.homeDirectoryForCurrentUser
2026-01-04 14:32:47 +00:00
.appendingPathComponent(".clawdbot", isDirectory: true)
}
static var configURL: URL {
2026-01-04 14:32:47 +00:00
if let override = ClawdbotEnv.path(self.configPathEnv) {
return URL(fileURLWithPath: override)
}
2026-01-04 14:32:47 +00:00
return self.stateDirURL.appendingPathComponent("clawdbot.json")
}
static var workspaceURL: URL {
self.stateDirURL.appendingPathComponent("workspace", isDirectory: true)
}
}