import Foundation public enum ClawdisNodeStorage { public static func appSupportDir() throws -> URL { let base = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first guard let base else { throw NSError(domain: "ClawdisNodeStorage", code: 1, userInfo: [ NSLocalizedDescriptionKey: "Application Support directory unavailable", ]) } return base.appendingPathComponent("Clawdis", isDirectory: true) } public static func canvasRoot(sessionKey: String) throws -> URL { let root = try appSupportDir().appendingPathComponent("canvas", isDirectory: true) let safe = sessionKey.trimmingCharacters(in: .whitespacesAndNewlines) let session = safe.isEmpty ? "main" : safe return root.appendingPathComponent(session, isDirectory: true) } public static func cachesDir() throws -> URL { let base = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first guard let base else { throw NSError(domain: "ClawdisNodeStorage", code: 2, userInfo: [ NSLocalizedDescriptionKey: "Caches directory unavailable", ]) } return base.appendingPathComponent("Clawdis", isDirectory: true) } public static func canvasSnapshotsRoot(sessionKey: String) throws -> URL { let root = try cachesDir().appendingPathComponent("canvas-snapshots", isDirectory: true) let safe = sessionKey.trimmingCharacters(in: .whitespacesAndNewlines) let session = safe.isEmpty ? "main" : safe return root.appendingPathComponent(session, isDirectory: true) } }